{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useEffect } from 'react';\nimport findDOMNode from \"rc-util/es/Dom/findDOMNode\";\nimport raf from \"rc-util/es/raf\";\nimport CacheMap from \"../utils/CacheMap\";\nexport default function useHeights(getKey, onItemAdd, onItemRemove) {\n var _React$useState = React.useState(0),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n updatedMark = _React$useState2[0],\n setUpdatedMark = _React$useState2[1];\n var instanceRef = useRef(new Map());\n var heightsRef = useRef(new CacheMap());\n var collectRafRef = useRef();\n function cancelRaf() {\n raf.cancel(collectRafRef.current);\n }\n function collectHeight() {\n var sync = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n cancelRaf();\n var doCollect = function doCollect() {\n instanceRef.current.forEach(function (element, key) {\n if (element && element.offsetParent) {\n var htmlElement = findDOMNode(element);\n var offsetHeight = htmlElement.offsetHeight;\n if (heightsRef.current.get(key) !== offsetHeight) {\n heightsRef.current.set(key, htmlElement.offsetHeight);\n }\n }\n });\n\n // Always trigger update mark to tell parent that should re-calculate heights when resized\n setUpdatedMark(function (c) {\n return c + 1;\n });\n };\n if (sync) {\n doCollect();\n } else {\n collectRafRef.current = raf(doCollect);\n }\n }\n function setInstanceRef(item, instance) {\n var key = getKey(item);\n var origin = instanceRef.current.get(key);\n if (instance) {\n instanceRef.current.set(key, instance);\n collectHeight();\n } else {\n instanceRef.current.delete(key);\n }\n\n // Instance changed\n if (!origin !== !instance) {\n if (instance) {\n onItemAdd === null || onItemAdd === void 0 || onItemAdd(item);\n } else {\n onItemRemove === null || onItemRemove === void 0 || onItemRemove(item);\n }\n }\n }\n useEffect(function () {\n return cancelRaf;\n }, []);\n return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];\n}","map":{"version":3,"names":["_slicedToArray","React","useRef","useEffect","findDOMNode","raf","CacheMap","useHeights","getKey","onItemAdd","onItemRemove","_React$useState","useState","_React$useState2","updatedMark","setUpdatedMark","instanceRef","Map","heightsRef","collectRafRef","cancelRaf","cancel","current","collectHeight","sync","arguments","length","undefined","doCollect","forEach","element","key","offsetParent","htmlElement","offsetHeight","get","set","c","setInstanceRef","item","instance","origin","delete"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-virtual-list/es/hooks/useHeights.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useEffect } from 'react';\nimport findDOMNode from \"rc-util/es/Dom/findDOMNode\";\nimport raf from \"rc-util/es/raf\";\nimport CacheMap from \"../utils/CacheMap\";\nexport default function useHeights(getKey, onItemAdd, onItemRemove) {\n var _React$useState = React.useState(0),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n updatedMark = _React$useState2[0],\n setUpdatedMark = _React$useState2[1];\n var instanceRef = useRef(new Map());\n var heightsRef = useRef(new CacheMap());\n var collectRafRef = useRef();\n function cancelRaf() {\n raf.cancel(collectRafRef.current);\n }\n function collectHeight() {\n var sync = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n cancelRaf();\n var doCollect = function doCollect() {\n instanceRef.current.forEach(function (element, key) {\n if (element && element.offsetParent) {\n var htmlElement = findDOMNode(element);\n var offsetHeight = htmlElement.offsetHeight;\n if (heightsRef.current.get(key) !== offsetHeight) {\n heightsRef.current.set(key, htmlElement.offsetHeight);\n }\n }\n });\n\n // Always trigger update mark to tell parent that should re-calculate heights when resized\n setUpdatedMark(function (c) {\n return c + 1;\n });\n };\n if (sync) {\n doCollect();\n } else {\n collectRafRef.current = raf(doCollect);\n }\n }\n function setInstanceRef(item, instance) {\n var key = getKey(item);\n var origin = instanceRef.current.get(key);\n if (instance) {\n instanceRef.current.set(key, instance);\n collectHeight();\n } else {\n instanceRef.current.delete(key);\n }\n\n // Instance changed\n if (!origin !== !instance) {\n if (instance) {\n onItemAdd === null || onItemAdd === void 0 || onItemAdd(item);\n } else {\n onItemRemove === null || onItemRemove === void 0 || onItemRemove(item);\n }\n }\n }\n useEffect(function () {\n return cancelRaf;\n }, []);\n return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];\n}"],"mappings":"AAAA,OAAOA,cAAc,MAAM,0CAA0C;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,EAAEC,SAAS,QAAQ,OAAO;AACzC,OAAOC,WAAW,MAAM,4BAA4B;AACpD,OAAOC,GAAG,MAAM,gBAAgB;AAChC,OAAOC,QAAQ,MAAM,mBAAmB;AACxC,eAAe,SAASC,UAAUA,CAACC,MAAM,EAAEC,SAAS,EAAEC,YAAY,EAAE;EAClE,IAAIC,eAAe,GAAGV,KAAK,CAACW,QAAQ,CAAC,CAAC,CAAC;IACrCC,gBAAgB,GAAGb,cAAc,CAACW,eAAe,EAAE,CAAC,CAAC;IACrDG,WAAW,GAAGD,gBAAgB,CAAC,CAAC,CAAC;IACjCE,cAAc,GAAGF,gBAAgB,CAAC,CAAC,CAAC;EACtC,IAAIG,WAAW,GAAGd,MAAM,CAAC,IAAIe,GAAG,CAAC,CAAC,CAAC;EACnC,IAAIC,UAAU,GAAGhB,MAAM,CAAC,IAAII,QAAQ,CAAC,CAAC,CAAC;EACvC,IAAIa,aAAa,GAAGjB,MAAM,CAAC,CAAC;EAC5B,SAASkB,SAASA,CAAA,EAAG;IACnBf,GAAG,CAACgB,MAAM,CAACF,aAAa,CAACG,OAAO,CAAC;EACnC;EACA,SAASC,aAAaA,CAAA,EAAG;IACvB,IAAIC,IAAI,GAAGC,SAAS,CAACC,MAAM,GAAG,CAAC,IAAID,SAAS,CAAC,CAAC,CAAC,KAAKE,SAAS,GAAGF,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK;IACpFL,SAAS,CAAC,CAAC;IACX,IAAIQ,SAAS,GAAG,SAASA,SAASA,CAAA,EAAG;MACnCZ,WAAW,CAACM,OAAO,CAACO,OAAO,CAAC,UAAUC,OAAO,EAAEC,GAAG,EAAE;QAClD,IAAID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