0e9a471ca17ea557fe31f1a38ecb8e43.json
22.3 KB
{"ast":null,"code":"import { render, unmountComponentAtNode } from 'react-dom';\nimport * as React from 'react';\nimport toArray from \"rc-util/es/Children/toArray\"; // We only handle element & text node.\n\nvar ELEMENT_NODE = 1;\nvar TEXT_NODE = 3;\nvar COMMENT_NODE = 8;\nvar ellipsisContainer;\nvar wrapperStyle = {\n padding: 0,\n margin: 0,\n display: 'inline',\n lineHeight: 'inherit'\n};\n\nfunction pxToNumber(value) {\n if (!value) return 0;\n var match = value.match(/^\\d*(\\.\\d*)?/);\n return match ? Number(match[0]) : 0;\n}\n\nfunction styleToString(style) {\n // There are some different behavior between Firefox & Chrome.\n // We have to handle this ourself.\n var styleNames = Array.prototype.slice.apply(style);\n return styleNames.map(function (name) {\n return \"\".concat(name, \": \").concat(style.getPropertyValue(name), \";\");\n }).join('');\n}\n\nfunction mergeChildren(children) {\n var childList = [];\n children.forEach(function (child) {\n var prevChild = childList[childList.length - 1];\n\n if (typeof child === 'string' && typeof prevChild === 'string') {\n childList[childList.length - 1] += child;\n } else {\n childList.push(child);\n }\n });\n return childList;\n}\n\nexport default (function (originEle, option, content, fixedContent, ellipsisStr) {\n if (!ellipsisContainer) {\n ellipsisContainer = document.createElement('div');\n ellipsisContainer.setAttribute('aria-hidden', 'true');\n document.body.appendChild(ellipsisContainer);\n }\n\n var rows = option.rows,\n _option$suffix = option.suffix,\n suffix = _option$suffix === void 0 ? '' : _option$suffix; // Get origin style\n\n var originStyle = window.getComputedStyle(originEle);\n var originCSS = styleToString(originStyle);\n var lineHeight = pxToNumber(originStyle.lineHeight);\n var maxHeight = Math.round(lineHeight * (rows + 1) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom)); // Set shadow\n\n ellipsisContainer.setAttribute('style', originCSS);\n ellipsisContainer.style.position = 'fixed';\n ellipsisContainer.style.left = '0';\n ellipsisContainer.style.height = 'auto';\n ellipsisContainer.style.minHeight = 'auto';\n ellipsisContainer.style.maxHeight = 'auto';\n ellipsisContainer.style.top = '-999999px';\n ellipsisContainer.style.zIndex = '-1000'; // clean up css overflow\n\n ellipsisContainer.style.textOverflow = 'clip';\n ellipsisContainer.style.whiteSpace = 'normal';\n ellipsisContainer.style.webkitLineClamp = 'none'; // Render in the fake container\n\n var contentList = mergeChildren(toArray(content));\n render( /*#__PURE__*/React.createElement(\"div\", {\n style: wrapperStyle\n }, /*#__PURE__*/React.createElement(\"span\", {\n style: wrapperStyle\n }, contentList, suffix), /*#__PURE__*/React.createElement(\"span\", {\n style: wrapperStyle\n }, fixedContent)), ellipsisContainer); // wrap in an div for old version react\n // Check if ellipsis in measure div is height enough for content\n\n function inRange() {\n return ellipsisContainer.offsetHeight < maxHeight;\n } // Skip ellipsis if already match\n\n\n if (inRange()) {\n unmountComponentAtNode(ellipsisContainer);\n return {\n content: content,\n text: ellipsisContainer.innerHTML,\n ellipsis: false\n };\n } // We should clone the childNode since they're controlled by React and we can't reuse it without warning\n\n\n var childNodes = Array.prototype.slice.apply(ellipsisContainer.childNodes[0].childNodes[0].cloneNode(true).childNodes).filter(function (_ref) {\n var nodeType = _ref.nodeType;\n return nodeType !== COMMENT_NODE;\n });\n var fixedNodes = Array.prototype.slice.apply(ellipsisContainer.childNodes[0].childNodes[1].cloneNode(true).childNodes);\n unmountComponentAtNode(ellipsisContainer); // ========================= Find match ellipsis content =========================\n\n var ellipsisChildren = [];\n ellipsisContainer.innerHTML = ''; // Create origin content holder\n\n var ellipsisContentHolder = document.createElement('span');\n ellipsisContainer.appendChild(ellipsisContentHolder);\n var ellipsisTextNode = document.createTextNode(ellipsisStr + suffix);\n ellipsisContentHolder.appendChild(ellipsisTextNode);\n fixedNodes.forEach(function (childNode) {\n ellipsisContainer.appendChild(childNode);\n }); // Append before fixed nodes\n\n function appendChildNode(node) {\n ellipsisContentHolder.insertBefore(node, ellipsisTextNode);\n } // Get maximum text\n\n\n function measureText(textNode, fullText) {\n var startLoc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;\n var endLoc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : fullText.length;\n var lastSuccessLoc = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;\n var midLoc = Math.floor((startLoc + endLoc) / 2);\n var currentText = fullText.slice(0, midLoc);\n textNode.textContent = currentText;\n\n if (startLoc >= endLoc - 1) {\n // Loop when step is small\n for (var step = endLoc; step >= startLoc; step -= 1) {\n var currentStepText = fullText.slice(0, step);\n textNode.textContent = currentStepText;\n\n if (inRange() || !currentStepText) {\n return step === fullText.length ? {\n finished: false,\n reactNode: fullText\n } : {\n finished: true,\n reactNode: currentStepText\n };\n }\n }\n }\n\n if (inRange()) {\n return measureText(textNode, fullText, midLoc, endLoc, midLoc);\n }\n\n return measureText(textNode, fullText, startLoc, midLoc, lastSuccessLoc);\n }\n\n function measureNode(childNode, index) {\n var type = childNode.nodeType;\n\n if (type === ELEMENT_NODE) {\n // We don't split element, it will keep if whole element can be displayed.\n appendChildNode(childNode);\n\n if (inRange()) {\n return {\n finished: false,\n reactNode: contentList[index]\n };\n } // Clean up if can not pull in\n\n\n ellipsisContentHolder.removeChild(childNode);\n return {\n finished: true,\n reactNode: null\n };\n }\n\n if (type === TEXT_NODE) {\n var fullText = childNode.textContent || '';\n var textNode = document.createTextNode(fullText);\n appendChildNode(textNode);\n return measureText(textNode, fullText);\n } // Not handle other type of content\n // PS: This code should not be attached after react 16\n\n /* istanbul ignore next */\n\n\n return {\n finished: false,\n reactNode: null\n };\n }\n\n childNodes.some(function (childNode, index) {\n var _measureNode = measureNode(childNode, index),\n finished = _measureNode.finished,\n reactNode = _measureNode.reactNode;\n\n if (reactNode) {\n ellipsisChildren.push(reactNode);\n }\n\n return finished;\n });\n return {\n content: ellipsisChildren,\n text: ellipsisContainer.innerHTML,\n ellipsis: true\n };\n});","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/antd/es/typography/util.js"],"names":["render","unmountComponentAtNode","React","toArray","ELEMENT_NODE","TEXT_NODE","COMMENT_NODE","ellipsisContainer","wrapperStyle","padding","margin","display","lineHeight","pxToNumber","value","match","Number","styleToString","style","styleNames","Array","prototype","slice","apply","map","name","concat","getPropertyValue","join","mergeChildren","children","childList","forEach","child","prevChild","length","push","originEle","option","content","fixedContent","ellipsisStr","document","createElement","setAttribute","body","appendChild","rows","_option$suffix","suffix","originStyle","window","getComputedStyle","originCSS","maxHeight","Math","round","paddingTop","paddingBottom","position","left","height","minHeight","top","zIndex","textOverflow","whiteSpace","webkitLineClamp","contentList","inRange","offsetHeight","text","innerHTML","ellipsis","childNodes","cloneNode","filter","_ref","nodeType","fixedNodes","ellipsisChildren","ellipsisContentHolder","ellipsisTextNode","createTextNode","childNode","appendChildNode","node","insertBefore","measureText","textNode","fullText","startLoc","arguments","undefined","endLoc","lastSuccessLoc","midLoc","floor","currentText","textContent","step","currentStepText","finished","reactNode","measureNode","index","type","removeChild","some","_measureNode"],"mappings":"AAAA,SAASA,MAAT,EAAiBC,sBAAjB,QAA+C,WAA/C;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,6BAApB,C,CAAmD;;AAEnD,IAAIC,YAAY,GAAG,CAAnB;AACA,IAAIC,SAAS,GAAG,CAAhB;AACA,IAAIC,YAAY,GAAG,CAAnB;AACA,IAAIC,iBAAJ;AACA,IAAIC,YAAY,GAAG;AACjBC,EAAAA,OAAO,EAAE,CADQ;AAEjBC,EAAAA,MAAM,EAAE,CAFS;AAGjBC,EAAAA,OAAO,EAAE,QAHQ;AAIjBC,EAAAA,UAAU,EAAE;AAJK,CAAnB;;AAOA,SAASC,UAAT,CAAoBC,KAApB,EAA2B;AACzB,MAAI,CAACA,KAAL,EAAY,OAAO,CAAP;AACZ,MAAIC,KAAK,GAAGD,KAAK,CAACC,KAAN,CAAY,cAAZ,CAAZ;AACA,SAAOA,KAAK,GAAGC,MAAM,CAACD,KAAK,CAAC,CAAD,CAAN,CAAT,GAAs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;AACbvB,MAAAA,gBAAgB,CAAC5C,IAAjB,CAAsBmE,SAAtB;AACD;;AAED,WAAOD,QAAP;AACD,GAVD;AAWA,SAAO;AACL/D,IAAAA,OAAO,EAAEyC,gBADJ;AAELT,IAAAA,IAAI,EAAEhE,iBAAiB,CAACiE,SAFnB;AAGLC,IAAAA,QAAQ,EAAE;AAHL,GAAP;AAKD,CArKD","sourcesContent":["import { render, unmountComponentAtNode } from 'react-dom';\nimport * as React from 'react';\nimport toArray from \"rc-util/es/Children/toArray\"; // We only handle element & text node.\n\nvar ELEMENT_NODE = 1;\nvar TEXT_NODE = 3;\nvar COMMENT_NODE = 8;\nvar ellipsisContainer;\nvar wrapperStyle = {\n padding: 0,\n margin: 0,\n display: 'inline',\n lineHeight: 'inherit'\n};\n\nfunction pxToNumber(value) {\n if (!value) return 0;\n var match = value.match(/^\\d*(\\.\\d*)?/);\n return match ? Number(match[0]) : 0;\n}\n\nfunction styleToString(style) {\n // There are some different behavior between Firefox & Chrome.\n // We have to handle this ourself.\n var styleNames = Array.prototype.slice.apply(style);\n return styleNames.map(function (name) {\n return \"\".concat(name, \": \").concat(style.getPropertyValue(name), \";\");\n }).join('');\n}\n\nfunction mergeChildren(children) {\n var childList = [];\n children.forEach(function (child) {\n var prevChild = childList[childList.length - 1];\n\n if (typeof child === 'string' && typeof prevChild === 'string') {\n childList[childList.length - 1] += child;\n } else {\n childList.push(child);\n }\n });\n return childList;\n}\n\nexport default (function (originEle, option, content, fixedContent, ellipsisStr) {\n if (!ellipsisContainer) {\n ellipsisContainer = document.createElement('div');\n ellipsisContainer.setAttribute('aria-hidden', 'true');\n document.body.appendChild(ellipsisContainer);\n }\n\n var rows = option.rows,\n _option$suffix = option.suffix,\n suffix = _option$suffix === void 0 ? '' : _option$suffix; // Get origin style\n\n var originStyle = window.getComputedStyle(originEle);\n var originCSS = styleToString(originStyle);\n var lineHeight = pxToNumber(originStyle.lineHeight);\n var maxHeight = Math.round(lineHeight * (rows + 1) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom)); // Set shadow\n\n ellipsisContainer.setAttribute('style', originCSS);\n ellipsisContainer.style.position = 'fixed';\n ellipsisContainer.style.left = '0';\n ellipsisContainer.style.height = 'auto';\n ellipsisContainer.style.minHeight = 'auto';\n ellipsisContainer.style.maxHeight = 'auto';\n ellipsisContainer.style.top = '-999999px';\n ellipsisContainer.style.zIndex = '-1000'; // clean up css overflow\n\n ellipsisContainer.style.textOverflow = 'clip';\n ellipsisContainer.style.whiteSpace = 'normal';\n ellipsisContainer.style.webkitLineClamp = 'none'; // Render in the fake container\n\n var contentList = mergeChildren(toArray(content));\n render( /*#__PURE__*/React.createElement(\"div\", {\n style: wrapperStyle\n }, /*#__PURE__*/React.createElement(\"span\", {\n style: wrapperStyle\n }, contentList, suffix), /*#__PURE__*/React.createElement(\"span\", {\n style: wrapperStyle\n }, fixedContent)), ellipsisContainer); // wrap in an div for old version react\n // Check if ellipsis in measure div is height enough for content\n\n function inRange() {\n return ellipsisContainer.offsetHeight < maxHeight;\n } // Skip ellipsis if already match\n\n\n if (inRange()) {\n unmountComponentAtNode(ellipsisContainer);\n return {\n content: content,\n text: ellipsisContainer.innerHTML,\n ellipsis: false\n };\n } // We should clone the childNode since they're controlled by React and we can't reuse it without warning\n\n\n var childNodes = Array.prototype.slice.apply(ellipsisContainer.childNodes[0].childNodes[0].cloneNode(true).childNodes).filter(function (_ref) {\n var nodeType = _ref.nodeType;\n return nodeType !== COMMENT_NODE;\n });\n var fixedNodes = Array.prototype.slice.apply(ellipsisContainer.childNodes[0].childNodes[1].cloneNode(true).childNodes);\n unmountComponentAtNode(ellipsisContainer); // ========================= Find match ellipsis content =========================\n\n var ellipsisChildren = [];\n ellipsisContainer.innerHTML = ''; // Create origin content holder\n\n var ellipsisContentHolder = document.createElement('span');\n ellipsisContainer.appendChild(ellipsisContentHolder);\n var ellipsisTextNode = document.createTextNode(ellipsisStr + suffix);\n ellipsisContentHolder.appendChild(ellipsisTextNode);\n fixedNodes.forEach(function (childNode) {\n ellipsisContainer.appendChild(childNode);\n }); // Append before fixed nodes\n\n function appendChildNode(node) {\n ellipsisContentHolder.insertBefore(node, ellipsisTextNode);\n } // Get maximum text\n\n\n function measureText(textNode, fullText) {\n var startLoc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;\n var endLoc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : fullText.length;\n var lastSuccessLoc = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;\n var midLoc = Math.floor((startLoc + endLoc) / 2);\n var currentText = fullText.slice(0, midLoc);\n textNode.textContent = currentText;\n\n if (startLoc >= endLoc - 1) {\n // Loop when step is small\n for (var step = endLoc; step >= startLoc; step -= 1) {\n var currentStepText = fullText.slice(0, step);\n textNode.textContent = currentStepText;\n\n if (inRange() || !currentStepText) {\n return step === fullText.length ? {\n finished: false,\n reactNode: fullText\n } : {\n finished: true,\n reactNode: currentStepText\n };\n }\n }\n }\n\n if (inRange()) {\n return measureText(textNode, fullText, midLoc, endLoc, midLoc);\n }\n\n return measureText(textNode, fullText, startLoc, midLoc, lastSuccessLoc);\n }\n\n function measureNode(childNode, index) {\n var type = childNode.nodeType;\n\n if (type === ELEMENT_NODE) {\n // We don't split element, it will keep if whole element can be displayed.\n appendChildNode(childNode);\n\n if (inRange()) {\n return {\n finished: false,\n reactNode: contentList[index]\n };\n } // Clean up if can not pull in\n\n\n ellipsisContentHolder.removeChild(childNode);\n return {\n finished: true,\n reactNode: null\n };\n }\n\n if (type === TEXT_NODE) {\n var fullText = childNode.textContent || '';\n var textNode = document.createTextNode(fullText);\n appendChildNode(textNode);\n return measureText(textNode, fullText);\n } // Not handle other type of content\n // PS: This code should not be attached after react 16\n\n /* istanbul ignore next */\n\n\n return {\n finished: false,\n reactNode: null\n };\n }\n\n childNodes.some(function (childNode, index) {\n var _measureNode = measureNode(childNode, index),\n finished = _measureNode.finished,\n reactNode = _measureNode.reactNode;\n\n if (reactNode) {\n ellipsisChildren.push(reactNode);\n }\n\n return finished;\n });\n return {\n content: ellipsisChildren,\n text: ellipsisContainer.innerHTML,\n ellipsis: true\n };\n});"]},"metadata":{},"sourceType":"module"}