@radix-ui/rect 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,yBAAkB;IAAE,qBAAqB,IAAI,UAAU,CAAA;CAAE,CAAC;AAE1D;A;A;A;GAIG;AACH;AACE,wCAAwC;AACxC,gBAAgB,EAAE,UAAU;AAC5B,8DAA8D;AAC9D,QAAQ,EAAE,UAAU,
|
|
1
|
+
{"mappings":"AAAA,yBAAkB;IAAE,qBAAqB,IAAI,UAAU,CAAA;CAAE,CAAC;AAE1D;A;A;A;GAIG;AACH;AACE,wCAAwC;AACxC,gBAAgB,EAAE,UAAU;AAC5B,8DAA8D;AAC9D,QAAQ,EAAE,UAAU,cAwCrB;AAKD,kBAAkB,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC","sources":["./packages/core/rect/src/packages/core/rect/src/observeElementRect.ts","./packages/core/rect/src/packages/core/rect/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
let t;exports.observeElementRect=function(n,o){const
|
|
1
|
+
let t;exports.observeElementRect=function(n,o){const i=e.get(n);return void 0===i?(e.set(n,{rect:{},callbacks:[o]}),1===e.size&&(t=requestAnimationFrame(c))):(i.callbacks.push(o),o(n.getBoundingClientRect())),()=>{const c=e.get(n);if(void 0===c)return;const i=c.callbacks.indexOf(o);i>-1&&c.callbacks.splice(i,1),0===c.callbacks.length&&(e.delete(n),0===e.size&&cancelAnimationFrame(t))}};const e=new Map;function c(){const n=[];e.forEach(((t,e)=>{const c=e.getBoundingClientRect();var o,i;o=t.rect,i=c,(o.width!==i.width||o.height!==i.height||o.top!==i.top||o.right!==i.right||o.bottom!==i.bottom||o.left!==i.left)&&(t.rect=c,n.push(t))})),n.forEach((t=>{t.callbacks.forEach((e=>e(t.rect)))})),t=requestAnimationFrame(c)}
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AA+DA,IAAIA,6BAxDJ,SAEEC,EAEAC,GAEA,MAAMC,EAAeC,EAAiBC,IAAIJ,GAiB1C,YAfqBK,IAAjBH,GAGFC,EAAiBG,IAAIN,EAAkB,CAAEO,KAAM,GAAkBC,UAAW,CAACP,KAE/C,IAA1BE,EAAiBM,OAEnBV,EAAQW,sBAAsBC,MAIhCT,EAAaM,UAAUI,KAAKX,GAC5BA,EAASD,EAAiBa,0BAGrB,KACL,MAAMX,EAAeC,EAAiBC,IAAIJ,GAC1C,QAAqBK,IAAjBH,EAA4B,OAGhC,MAAMY,EAAQZ,EAAaM,UAAUO,QAAQd,GACzCa,GAAS,GACXZ,EAAaM,UAAUQ,OAAOF,EAAO,GAGD,IAAlCZ,EAAaM,UAAUS,SAGzBd,EAAiBe,OAAOlB,GAEM,IAA1BG,EAAiBM,MAEnBU,qBAAqBpB,MAiB7B,MAAMI,EAAkD,IAAIiB,IAE5D,SAAST,IACP,MAAMU,EAAwC,GAG9ClB,EAAiBmB,SAAQ,CAACC,EAAMC,KAC9B,MAAMC,EAAUD,EAAQX,wBAsB5B,IAAoBa,EAAmBC,EAAnBD,EAnBAH,EAAKhB,KAmBcoB,EAnBRF,GAqB3BC,EAAME,QAAUD,EAAMC,OACtBF,EAAMG,SAAWF,EAAME,QACvBH,EAAMI,MAAQH,EAAMG,KACpBJ,EAAMK,QAAUJ,EAAMI,OACtBL,EAAMM,SAAWL,EAAMK,QACvBN,EAAMO,OAASN,EAAMM,QAzBnBV,EAAKhB,KAAOkB,EACZJ,EAAiBT,KAAKW,OAM1BF,EAAiBC,SAASC,IACxBA,EAAKf,UAAUc,SAASrB,GAAaA,EAASsB,EAAKhB,WAGrDR,EAAQW,sBAAsBC","sources":["./packages/core/rect/src/observeElementRect.ts"],"sourcesContent":["type Measurable = { getBoundingClientRect(): ClientRect };\n\n/**\n * Observes an element's rectangle on screen (getBoundingClientRect)\n * This is useful to track elements on the screen and attach other elements\n * that might be in different layers, etc.\n */\nfunction observeElementRect(\n /** The element whose rect to observe */\n elementToObserve: Measurable,\n /** The callback which will be called when the rect changes */\n callback: CallbackFn\n) {\n const observedData = observedElements.get(elementToObserve);\n\n if (observedData === undefined) {\n // add the element to the map of observed elements with its first callback\n // because this is the first time this element is observed\n observedElements.set(elementToObserve, { rect: {} as ClientRect, callbacks: [callback] });\n\n if (observedElements.size === 1) {\n // start the internal loop once at least 1 element is observed\n rafId = requestAnimationFrame(runLoop);\n }\n } else {\n // only add a callback for this element as it's already observed\n observedData.callbacks.push(callback);\n callback(elementToObserve.getBoundingClientRect());\n }\n\n return () => {\n const observedData = observedElements.get(elementToObserve);\n if (observedData === undefined) return;\n\n // start by removing the callback\n const index = observedData.callbacks.indexOf(callback);\n if (index > -1) {\n observedData.callbacks.splice(index, 1);\n }\n\n if (observedData.callbacks.length === 0) {\n // stop observing this element because there are no\n // callbacks registered for it anymore\n observedElements.delete(elementToObserve);\n\n if (observedElements.size === 0) {\n // stop the internal loop once no elements are observed anymore\n cancelAnimationFrame(rafId);\n }\n }\n };\n}\n\n// ========================================================================\n// module internals\n\ntype CallbackFn = (rect: ClientRect) => void;\n\ntype ObservedData = {\n rect: ClientRect;\n callbacks: Array<CallbackFn>;\n};\n\nlet rafId: number;\nconst observedElements: Map<Measurable, ObservedData> = new Map();\n\nfunction runLoop() {\n const changedRectsData: Array<ObservedData> = [];\n\n // process all DOM reads first (getBoundingClientRect)\n observedElements.forEach((data, element) => {\n const newRect = element.getBoundingClientRect();\n\n // gather all the data for elements whose rects have changed\n if (!rectEquals(data.rect, newRect)) {\n data.rect = newRect;\n changedRectsData.push(data);\n }\n });\n\n // group DOM writes here after the DOM reads (getBoundingClientRect)\n // as DOM writes will most likely happen with the callbacks\n changedRectsData.forEach((data) => {\n data.callbacks.forEach((callback) => callback(data.rect));\n });\n\n rafId = requestAnimationFrame(runLoop);\n}\n// ========================================================================\n\n/**\n * Returns whether 2 rects are equal in values\n */\nfunction rectEquals(rect1: ClientRect, rect2: ClientRect) {\n return (\n rect1.width === rect2.width &&\n rect1.height === rect2.height &&\n rect1.top === rect2.top &&\n rect1.right === rect2.right &&\n rect1.bottom === rect2.bottom &&\n rect1.left === rect2.left\n );\n}\n\nexport { observeElementRect };\nexport type { Measurable };\n"],"names":["rafId","elementToObserve","callback","observedData","observedElements","get","undefined","set","rect","callbacks","size","requestAnimationFrame","runLoop","push","getBoundingClientRect","index","indexOf","splice","length","delete","cancelAnimationFrame","Map","changedRectsData","forEach","data","element","newRect","rect1","rect2","width","height","top","right","bottom","left"],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function observeElementRect(n,o){const
|
|
1
|
+
export function observeElementRect(n,o){const i=e.get(n);return void 0===i?(e.set(n,{rect:{},callbacks:[o]}),1===e.size&&(t=requestAnimationFrame(c))):(i.callbacks.push(o),o(n.getBoundingClientRect())),()=>{const c=e.get(n);if(void 0===c)return;const i=c.callbacks.indexOf(o);i>-1&&c.callbacks.splice(i,1),0===c.callbacks.length&&(e.delete(n),0===e.size&&cancelAnimationFrame(t))}}let t;const e=new Map;function c(){const n=[];e.forEach(((t,e)=>{const c=e.getBoundingClientRect();var o,i;o=t.rect,i=c,(o.width!==i.width||o.height!==i.height||o.top!==i.top||o.right!==i.right||o.bottom!==i.bottom||o.left!==i.left)&&(t.rect=c,n.push(t))})),n.forEach((t=>{t.callbacks.forEach((e=>e(t.rect)))})),t=requestAnimationFrame(c)}
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
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observeElementRect.ts"],"sourcesContent":["type Measurable = { getBoundingClientRect(): ClientRect };\n\n/**\n * Observes an element's rectangle on screen (getBoundingClientRect)\n * This is useful to track elements on the screen and attach other elements\n * that might be in different layers, etc.\n */\nfunction observeElementRect(\n /** The element whose rect to observe */\n elementToObserve: Measurable,\n /** The callback which will be called when the rect changes */\n callback: CallbackFn\n) {\n const observedData = observedElements.get(elementToObserve);\n\n if (observedData === undefined) {\n // add the element to the map of observed elements with its first callback\n // because this is the first time this element is observed\n observedElements.set(elementToObserve, { rect: {} as ClientRect, callbacks: [callback] });\n\n if (observedElements.size === 1) {\n // start the internal loop once at least 1 element is observed\n rafId = requestAnimationFrame(runLoop);\n }\n } else {\n // only add a callback for this element as it's already observed\n observedData.callbacks.push(callback);\n callback(elementToObserve.getBoundingClientRect());\n }\n\n return () => {\n const observedData = observedElements.get(elementToObserve);\n if (observedData === undefined) return;\n\n // start by removing the callback\n const index = observedData.callbacks.indexOf(callback);\n if (index > -1) {\n observedData.callbacks.splice(index, 1);\n }\n\n if (observedData.callbacks.length === 0) {\n // stop observing this element because there are no\n // callbacks registered for it anymore\n observedElements.delete(elementToObserve);\n\n if (observedElements.size === 0) {\n // stop the internal loop once no elements are observed anymore\n cancelAnimationFrame(rafId);\n }\n }\n };\n}\n\n// ========================================================================\n// module internals\n\ntype CallbackFn = (rect: ClientRect) => void;\n\ntype ObservedData = {\n rect: ClientRect;\n callbacks: Array<CallbackFn>;\n};\n\nlet rafId: number;\nconst observedElements: Map<Measurable, ObservedData> = new Map();\n\nfunction runLoop() {\n const changedRectsData: Array<ObservedData> = [];\n\n // process all DOM reads first (getBoundingClientRect)\n observedElements.forEach((data, element) => {\n const newRect = element.getBoundingClientRect();\n\n // gather all the data for elements whose rects have changed\n if (!rectEquals(data.rect, newRect)) {\n data.rect = newRect;\n changedRectsData.push(data);\n }\n });\n\n // group DOM writes here after the DOM reads (getBoundingClientRect)\n // as DOM writes will most likely happen with the callbacks\n changedRectsData.forEach((data) => {\n data.callbacks.forEach((callback) => callback(data.rect));\n });\n\n rafId = requestAnimationFrame(runLoop);\n}\n// ========================================================================\n\n/**\n * Returns whether 2 rects are equal in values\n */\nfunction rectEquals(rect1: ClientRect, rect2: ClientRect) {\n return (\n rect1.width === rect2.width &&\n rect1.height === rect2.height &&\n rect1.top === rect2.top &&\n rect1.right === rect2.right &&\n rect1.bottom === rect2.bottom &&\n rect1.left === rect2.left\n );\n}\n\nexport { observeElementRect };\nexport type { Measurable };\n"],"names":["observeElementRect","elementToObserve","callback","observedData","observedElements","get","undefined","set","rect","callbacks","size","rafId","requestAnimationFrame","runLoop","push","getBoundingClientRect","index","indexOf","splice","length","delete","cancelAnimationFrame","Map","changedRectsData","forEach","data","element","newRect","rect1","rect2","width","height","top","right","bottom","left"],"version":3,"file":"index.module.js.map"}
|