PromoCursed/node_modules/.cache/babel-loader/c113dff59ca3fb82354f0a69b450671a498d3cfb3e5f13f932ec1e1bde2f8905.json
2024-08-20 23:25:37 +04:00

1 line
7.4 KiB
JSON

{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nfunction parseColWidth(totalWidth) {\n var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n if (typeof width === 'number') {\n return width;\n }\n if (width.endsWith('%')) {\n return totalWidth * parseFloat(width) / 100;\n }\n return null;\n}\n\n/**\n * Fill all column with width\n */\nexport default function useWidthColumns(flattenColumns, scrollWidth, clientWidth) {\n return React.useMemo(function () {\n // Fill width if needed\n if (scrollWidth && scrollWidth > 0) {\n var totalWidth = 0;\n var missWidthCount = 0;\n\n // collect not given width column\n flattenColumns.forEach(function (col) {\n var colWidth = parseColWidth(scrollWidth, col.width);\n if (colWidth) {\n totalWidth += colWidth;\n } else {\n missWidthCount += 1;\n }\n });\n\n // Fill width\n var maxFitWidth = Math.max(scrollWidth, clientWidth);\n var restWidth = Math.max(maxFitWidth - totalWidth, missWidthCount);\n var restCount = missWidthCount;\n var avgWidth = restWidth / missWidthCount;\n var realTotal = 0;\n var filledColumns = flattenColumns.map(function (col) {\n var clone = _objectSpread({}, col);\n var colWidth = parseColWidth(scrollWidth, clone.width);\n if (colWidth) {\n clone.width = colWidth;\n } else {\n var colAvgWidth = Math.floor(avgWidth);\n clone.width = restCount === 1 ? restWidth : colAvgWidth;\n restWidth -= colAvgWidth;\n restCount -= 1;\n }\n realTotal += clone.width;\n return clone;\n });\n\n // If realTotal is less than clientWidth,\n // We need extend column width\n if (realTotal < maxFitWidth) {\n var scale = maxFitWidth / realTotal;\n restWidth = maxFitWidth;\n filledColumns.forEach(function (col, index) {\n var colWidth = Math.floor(col.width * scale);\n col.width = index === filledColumns.length - 1 ? restWidth : colWidth;\n restWidth -= colWidth;\n });\n }\n return [filledColumns, Math.max(realTotal, maxFitWidth)];\n }\n return [flattenColumns, scrollWidth];\n }, [flattenColumns, scrollWidth, clientWidth]);\n}","map":{"version":3,"names":["_objectSpread","React","parseColWidth","totalWidth","width","arguments","length","undefined","endsWith","parseFloat","useWidthColumns","flattenColumns","scrollWidth","clientWidth","useMemo","missWidthCount","forEach","col","colWidth","maxFitWidth","Math","max","restWidth","restCount","avgWidth","realTotal","filledColumns","map","clone","colAvgWidth","floor","scale","index"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.js"],"sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport * as React from 'react';\nfunction parseColWidth(totalWidth) {\n var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';\n if (typeof width === 'number') {\n return width;\n }\n if (width.endsWith('%')) {\n return totalWidth * parseFloat(width) / 100;\n }\n return null;\n}\n\n/**\n * Fill all column with width\n */\nexport default function useWidthColumns(flattenColumns, scrollWidth, clientWidth) {\n return React.useMemo(function () {\n // Fill width if needed\n if (scrollWidth && scrollWidth > 0) {\n var totalWidth = 0;\n var missWidthCount = 0;\n\n // collect not given width column\n flattenColumns.forEach(function (col) {\n var colWidth = parseColWidth(scrollWidth, col.width);\n if (colWidth) {\n totalWidth += colWidth;\n } else {\n missWidthCount += 1;\n }\n });\n\n // Fill width\n var maxFitWidth = Math.max(scrollWidth, clientWidth);\n var restWidth = Math.max(maxFitWidth - totalWidth, missWidthCount);\n var restCount = missWidthCount;\n var avgWidth = restWidth / missWidthCount;\n var realTotal = 0;\n var filledColumns = flattenColumns.map(function (col) {\n var clone = _objectSpread({}, col);\n var colWidth = parseColWidth(scrollWidth, clone.width);\n if (colWidth) {\n clone.width = colWidth;\n } else {\n var colAvgWidth = Math.floor(avgWidth);\n clone.width = restCount === 1 ? restWidth : colAvgWidth;\n restWidth -= colAvgWidth;\n restCount -= 1;\n }\n realTotal += clone.width;\n return clone;\n });\n\n // If realTotal is less than clientWidth,\n // We need extend column width\n if (realTotal < maxFitWidth) {\n var scale = maxFitWidth / realTotal;\n restWidth = maxFitWidth;\n filledColumns.forEach(function (col, index) {\n var colWidth = Math.floor(col.width * scale);\n col.width = index === filledColumns.length - 1 ? restWidth : colWidth;\n restWidth -= colWidth;\n });\n }\n return [filledColumns, Math.max(realTotal, maxFitWidth)];\n }\n return [flattenColumns, scrollWidth];\n }, [flattenColumns, scrollWidth, clientWidth]);\n}"],"mappings":"AAAA,OAAOA,aAAa,MAAM,0CAA0C;AACpE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,aAAaA,CAACC,UAAU,EAAE;EACjC,IAAIC,KAAK,GAAGC,SAAS,CAACC,MAAM,GAAG,CAAC,IAAID,SAAS,CAAC,CAAC,CAAC,KAAKE,SAAS,GAAGF,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE;EAClF,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAOA,KAAK;EACd;EACA,IAAIA,KAAK,CAACI,QAAQ,CAAC,GAAG,CAAC,EAAE;IACvB,OAAOL,UAAU,GAAGM,UAAU,CAACL,KAAK,CAAC,GAAG,GAAG;EAC7C;EACA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA,eAAe,SAASM,eAAeA,CAACC,cAAc,EAAEC,WAAW,EAAEC,WAAW,EAAE;EAChF,OAAOZ,KAAK,CAACa,OAAO,CAAC,YAAY;IAC/B;IACA,IAAIF,WAAW,IAAIA,WAAW,GAAG,CAAC,EAAE;MAClC,IAAIT,UAAU,GAAG,CAAC;MAClB,IAAIY,cAAc,GAAG,CAAC;;MAEtB;MACAJ,cAAc,CAACK,OAAO,CAAC,UAAUC,GAAG,EAAE;QACpC,IAAIC,QAAQ,GAAGhB,aAAa,CAACU,WAAW,EAAEK,GAAG,CAACb,KAAK,CAAC;QACpD,IAAIc,QAAQ,EAAE;UACZf,UAAU,IAAIe,QAAQ;QACxB,CAAC,MAAM;UACLH,cAAc,IAAI,CAAC;QACrB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