first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+3
View File
@@ -0,0 +1,3 @@
# `rect`
This is an internal utility, not intended for public usage.
+16
View File
@@ -0,0 +1,16 @@
type Measurable = {
getBoundingClientRect(): DOMRect;
};
/**
* Observes an element's rectangle on screen (getBoundingClientRect)
* This is useful to track elements on the screen and attach other elements
* that might be in different layers, etc.
*/
declare function observeElementRect(
/** The element whose rect to observe */
elementToObserve: Measurable,
/** The callback which will be called when the rect changes */
callback: CallbackFn): () => void;
type CallbackFn = (rect: DOMRect) => void;
export { type Measurable, observeElementRect };
+16
View File
@@ -0,0 +1,16 @@
type Measurable = {
getBoundingClientRect(): DOMRect;
};
/**
* Observes an element's rectangle on screen (getBoundingClientRect)
* This is useful to track elements on the screen and attach other elements
* that might be in different layers, etc.
*/
declare function observeElementRect(
/** The element whose rect to observe */
elementToObserve: Measurable,
/** The callback which will be called when the rect changes */
callback: CallbackFn): () => void;
type CallbackFn = (rect: DOMRect) => void;
export { type Measurable, observeElementRect };
+73
View File
@@ -0,0 +1,73 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
observeElementRect: () => observeElementRect
});
module.exports = __toCommonJS(index_exports);
// src/observe-element-rect.ts
function observeElementRect(elementToObserve, callback) {
const observedData = observedElements.get(elementToObserve);
if (observedData === void 0) {
observedElements.set(elementToObserve, { rect: {}, callbacks: [callback] });
if (observedElements.size === 1) {
rafId = requestAnimationFrame(runLoop);
}
} else {
observedData.callbacks.push(callback);
callback(elementToObserve.getBoundingClientRect());
}
return () => {
const observedData2 = observedElements.get(elementToObserve);
if (observedData2 === void 0) return;
const index = observedData2.callbacks.indexOf(callback);
if (index > -1) {
observedData2.callbacks.splice(index, 1);
}
if (observedData2.callbacks.length === 0) {
observedElements.delete(elementToObserve);
if (observedElements.size === 0) {
cancelAnimationFrame(rafId);
}
}
};
}
var rafId;
var observedElements = /* @__PURE__ */ new Map();
function runLoop() {
const changedRectsData = [];
observedElements.forEach((data, element) => {
const newRect = element.getBoundingClientRect();
if (!rectEquals(data.rect, newRect)) {
data.rect = newRect;
changedRectsData.push(data);
}
});
changedRectsData.forEach((data) => {
data.callbacks.forEach((callback) => callback(data.rect));
});
rafId = requestAnimationFrame(runLoop);
}
function rectEquals(rect1, rect2) {
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
}
//# sourceMappingURL=index.js.map
+7
View File
@@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/index.ts", "../src/observe-element-rect.ts"],
"sourcesContent": ["export { observeElementRect } from './observe-element-rect';\nexport type { Measurable } from './observe-element-rect';\n", "// Adapted from https://github.com/reach/observe-rect/tree\n// MIT license, React Training\n\ntype Measurable = { getBoundingClientRect(): DOMRect };\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 DOMRect, 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: DOMRect) => void;\n\ntype ObservedData = {\n rect: DOMRect;\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: DOMRect, rect2: DOMRect) {\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"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,SAAS,mBAEP,kBAEA,UACA;AACA,QAAM,eAAe,iBAAiB,IAAI,gBAAgB;AAE1D,MAAI,iBAAiB,QAAW;AAG9B,qBAAiB,IAAI,kBAAkB,EAAE,MAAM,CAAC,GAAc,WAAW,CAAC,QAAQ,EAAE,CAAC;AAErF,QAAI,iBAAiB,SAAS,GAAG;AAE/B,cAAQ,sBAAsB,OAAO;AAAA,IACvC;AAAA,EACF,OAAO;AAEL,iBAAa,UAAU,KAAK,QAAQ;AACpC,aAAS,iBAAiB,sBAAsB,CAAC;AAAA,EACnD;AAEA,SAAO,MAAM;AACX,UAAMA,gBAAe,iBAAiB,IAAI,gBAAgB;AAC1D,QAAIA,kBAAiB,OAAW;AAGhC,UAAM,QAAQA,cAAa,UAAU,QAAQ,QAAQ;AACrD,QAAI,QAAQ,IAAI;AACd,MAAAA,cAAa,UAAU,OAAO,OAAO,CAAC;AAAA,IACxC;AAEA,QAAIA,cAAa,UAAU,WAAW,GAAG;AAGvC,uBAAiB,OAAO,gBAAgB;AAExC,UAAI,iBAAiB,SAAS,GAAG;AAE/B,6BAAqB,KAAK;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;AAYA,IAAI;AACJ,IAAM,mBAAkD,oBAAI,IAAI;AAEhE,SAAS,UAAU;AACjB,QAAM,mBAAwC,CAAC;AAG/C,mBAAiB,QAAQ,CAAC,MAAM,YAAY;AAC1C,UAAM,UAAU,QAAQ,sBAAsB;AAG9C,QAAI,CAAC,WAAW,KAAK,MAAM,OAAO,GAAG;AACnC,WAAK,OAAO;AACZ,uBAAiB,KAAK,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AAID,mBAAiB,QAAQ,CAAC,SAAS;AACjC,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,KAAK,IAAI,CAAC;AAAA,EAC1D,CAAC;AAED,UAAQ,sBAAsB,OAAO;AACvC;AAMA,SAAS,WAAW,OAAgB,OAAgB;AAClD,SACE,MAAM,UAAU,MAAM,SACtB,MAAM,WAAW,MAAM,UACvB,MAAM,QAAQ,MAAM,OACpB,MAAM,UAAU,MAAM,SACtB,MAAM,WAAW,MAAM,UACvB,MAAM,SAAS,MAAM;AAEzB;",
"names": ["observedData"]
}
+50
View File
@@ -0,0 +1,50 @@
// src/observe-element-rect.ts
function observeElementRect(elementToObserve, callback) {
const observedData = observedElements.get(elementToObserve);
if (observedData === void 0) {
observedElements.set(elementToObserve, { rect: {}, callbacks: [callback] });
if (observedElements.size === 1) {
rafId = requestAnimationFrame(runLoop);
}
} else {
observedData.callbacks.push(callback);
callback(elementToObserve.getBoundingClientRect());
}
return () => {
const observedData2 = observedElements.get(elementToObserve);
if (observedData2 === void 0) return;
const index = observedData2.callbacks.indexOf(callback);
if (index > -1) {
observedData2.callbacks.splice(index, 1);
}
if (observedData2.callbacks.length === 0) {
observedElements.delete(elementToObserve);
if (observedElements.size === 0) {
cancelAnimationFrame(rafId);
}
}
};
}
var rafId;
var observedElements = /* @__PURE__ */ new Map();
function runLoop() {
const changedRectsData = [];
observedElements.forEach((data, element) => {
const newRect = element.getBoundingClientRect();
if (!rectEquals(data.rect, newRect)) {
data.rect = newRect;
changedRectsData.push(data);
}
});
changedRectsData.forEach((data) => {
data.callbacks.forEach((callback) => callback(data.rect));
});
rafId = requestAnimationFrame(runLoop);
}
function rectEquals(rect1, rect2) {
return rect1.width === rect2.width && rect1.height === rect2.height && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom && rect1.left === rect2.left;
}
export {
observeElementRect
};
//# sourceMappingURL=index.mjs.map
+7
View File
@@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/observe-element-rect.ts"],
"sourcesContent": ["// Adapted from https://github.com/reach/observe-rect/tree\n// MIT license, React Training\n\ntype Measurable = { getBoundingClientRect(): DOMRect };\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 DOMRect, 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: DOMRect) => void;\n\ntype ObservedData = {\n rect: DOMRect;\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: DOMRect, rect2: DOMRect) {\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"],
"mappings": ";AAUA,SAAS,mBAEP,kBAEA,UACA;AACA,QAAM,eAAe,iBAAiB,IAAI,gBAAgB;AAE1D,MAAI,iBAAiB,QAAW;AAG9B,qBAAiB,IAAI,kBAAkB,EAAE,MAAM,CAAC,GAAc,WAAW,CAAC,QAAQ,EAAE,CAAC;AAErF,QAAI,iBAAiB,SAAS,GAAG;AAE/B,cAAQ,sBAAsB,OAAO;AAAA,IACvC;AAAA,EACF,OAAO;AAEL,iBAAa,UAAU,KAAK,QAAQ;AACpC,aAAS,iBAAiB,sBAAsB,CAAC;AAAA,EACnD;AAEA,SAAO,MAAM;AACX,UAAMA,gBAAe,iBAAiB,IAAI,gBAAgB;AAC1D,QAAIA,kBAAiB,OAAW;AAGhC,UAAM,QAAQA,cAAa,UAAU,QAAQ,QAAQ;AACrD,QAAI,QAAQ,IAAI;AACd,MAAAA,cAAa,UAAU,OAAO,OAAO,CAAC;AAAA,IACxC;AAEA,QAAIA,cAAa,UAAU,WAAW,GAAG;AAGvC,uBAAiB,OAAO,gBAAgB;AAExC,UAAI,iBAAiB,SAAS,GAAG;AAE/B,6BAAqB,KAAK;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;AAYA,IAAI;AACJ,IAAM,mBAAkD,oBAAI,IAAI;AAEhE,SAAS,UAAU;AACjB,QAAM,mBAAwC,CAAC;AAG/C,mBAAiB,QAAQ,CAAC,MAAM,YAAY;AAC1C,UAAM,UAAU,QAAQ,sBAAsB;AAG9C,QAAI,CAAC,WAAW,KAAK,MAAM,OAAO,GAAG;AACnC,WAAK,OAAO;AACZ,uBAAiB,KAAK,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AAID,mBAAiB,QAAQ,CAAC,SAAS;AACjC,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,KAAK,IAAI,CAAC;AAAA,EAC1D,CAAC;AAED,UAAQ,sBAAsB,OAAO;AACvC;AAMA,SAAS,WAAW,OAAgB,OAAgB;AAClD,SACE,MAAM,UAAU,MAAM,SACtB,MAAM,WAAW,MAAM,UACvB,MAAM,QAAQ,MAAM,OACpB,MAAM,UAAU,MAAM,SACtB,MAAM,WAAW,MAAM,UACvB,MAAM,SAAS,MAAM;AAEzB;",
"names": ["observedData"]
}
+47
View File
@@ -0,0 +1,47 @@
{
"name": "@radix-ui/rect",
"version": "1.1.2",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"devDependencies": {
"typescript": "^5.9.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0"
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git",
"directory": "packages/core/rect"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "oxlint --max-warnings 0 src",
"clean": "rm -rf dist",
"reset": "rm -rf dist node_modules",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}