@lynx-js/luna-stage 0.0.0-oidc-bootstrap.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/LICENSE +1 -1
- package/README.md +415 -5
- package/dist/components/context/create-context.d.ts +55 -0
- package/dist/components/context/create-context.d.ts.map +1 -0
- package/dist/components/context/create-context.js +32 -0
- package/dist/components/context/create-context.js.map +1 -0
- package/dist/components/context/index.d.ts +2 -0
- package/dist/components/context/index.d.ts.map +1 -0
- package/dist/components/context/index.js +1 -0
- package/dist/components/stage/index.d.ts +2 -0
- package/dist/components/stage/index.d.ts.map +1 -0
- package/dist/components/stage/index.js +1 -0
- package/dist/components/stage/stage.d.ts +10 -0
- package/dist/components/stage/stage.d.ts.map +1 -0
- package/dist/components/stage/stage.js +185 -0
- package/dist/components/stage/stage.js.map +1 -0
- package/dist/constants/stage.d.ts +4 -0
- package/dist/constants/stage.d.ts.map +1 -0
- package/dist/constants/stage.js +6 -0
- package/dist/constants/stage.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/use-container-resize.d.ts +30 -0
- package/dist/hooks/use-container-resize.d.ts.map +1 -0
- package/dist/hooks/use-container-resize.js +63 -0
- package/dist/hooks/use-container-resize.js.map +1 -0
- package/dist/hooks/use-event-callback.d.ts +36 -0
- package/dist/hooks/use-event-callback.d.ts.map +1 -0
- package/dist/hooks/use-event-callback.js +18 -0
- package/dist/hooks/use-event-callback.js.map +1 -0
- package/dist/hooks/use-is-client.d.ts +2 -0
- package/dist/hooks/use-is-client.d.ts.map +1 -0
- package/dist/hooks/use-is-client.js +16 -0
- package/dist/hooks/use-is-client.js.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +4 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +6 -0
- package/dist/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/hooks/use-merged-refs.d.ts +5 -0
- package/dist/hooks/use-merged-refs.d.ts.map +1 -0
- package/dist/hooks/use-merged-refs.js +18 -0
- package/dist/hooks/use-merged-refs.js.map +1 -0
- package/dist/hooks/use-raf-clock.d.ts +17 -0
- package/dist/hooks/use-raf-clock.d.ts.map +1 -0
- package/dist/hooks/use-raf-clock.js +22 -0
- package/dist/hooks/use-raf-clock.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/lynx/index.d.ts +7 -0
- package/dist/lynx/index.d.ts.map +1 -0
- package/dist/lynx/index.js +3 -0
- package/dist/lynx/luna-lynx-stage.d.ts +32 -0
- package/dist/lynx/luna-lynx-stage.d.ts.map +1 -0
- package/dist/lynx/luna-lynx-stage.js +45 -0
- package/dist/lynx/luna-lynx-stage.js.map +1 -0
- package/dist/lynx/lynx-stage-constants.d.ts +8 -0
- package/dist/lynx/lynx-stage-constants.d.ts.map +1 -0
- package/dist/lynx/lynx-stage-constants.js +26 -0
- package/dist/lynx/lynx-stage-constants.js.map +1 -0
- package/dist/lynx/lynx-stage.d.ts +25 -0
- package/dist/lynx/lynx-stage.d.ts.map +1 -0
- package/dist/lynx/lynx-stage.js +33 -0
- package/dist/lynx/lynx-stage.js.map +1 -0
- package/dist/lynx/types.d.ts +77 -0
- package/dist/lynx/types.d.ts.map +1 -0
- package/dist/lynx/types.js +0 -0
- package/dist/lynx/use-lynx-stage.d.ts +5 -0
- package/dist/lynx/use-lynx-stage.d.ts.map +1 -0
- package/dist/lynx/use-lynx-stage.js +130 -0
- package/dist/lynx/use-lynx-stage.js.map +1 -0
- package/dist/motion/context/index.d.ts +6 -0
- package/dist/motion/context/index.d.ts.map +1 -0
- package/dist/motion/context/index.js +3 -0
- package/dist/motion/context/use-visual-size.d.ts +8 -0
- package/dist/motion/context/use-visual-size.d.ts.map +1 -0
- package/dist/motion/context/use-visual-size.js +8 -0
- package/dist/motion/context/use-visual-size.js.map +1 -0
- package/dist/motion/context/visual-size-context.d.ts +10 -0
- package/dist/motion/context/visual-size-context.d.ts.map +1 -0
- package/dist/motion/context/visual-size-context.js +5 -0
- package/dist/motion/context/visual-size-context.js.map +1 -0
- package/dist/motion/context/visual-size-provider.d.ts +9 -0
- package/dist/motion/context/visual-size-provider.d.ts.map +1 -0
- package/dist/motion/context/visual-size-provider.js +19 -0
- package/dist/motion/context/visual-size-provider.js.map +1 -0
- package/dist/motion/index.d.ts +5 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +2 -0
- package/dist/motion/stage/container-motion.d.ts +25 -0
- package/dist/motion/stage/container-motion.d.ts.map +1 -0
- package/dist/motion/stage/container-motion.js +111 -0
- package/dist/motion/stage/container-motion.js.map +1 -0
- package/dist/motion/stage/index.d.ts +5 -0
- package/dist/motion/stage/index.d.ts.map +1 -0
- package/dist/motion/stage/index.js +3 -0
- package/dist/motion/stage/presentation-motion.d.ts +17 -0
- package/dist/motion/stage/presentation-motion.d.ts.map +1 -0
- package/dist/motion/stage/presentation-motion.js +33 -0
- package/dist/motion/stage/presentation-motion.js.map +1 -0
- package/dist/motion/stage/stage-motion.d.ts +5 -0
- package/dist/motion/stage/stage-motion.d.ts.map +1 -0
- package/dist/motion/stage/stage-motion.js +184 -0
- package/dist/motion/stage/stage-motion.js.map +1 -0
- package/dist/motion/stage/transform-utils.d.ts +9 -0
- package/dist/motion/stage/transform-utils.d.ts.map +1 -0
- package/dist/motion/stage/transform-utils.js +20 -0
- package/dist/motion/stage/transform-utils.js.map +1 -0
- package/dist/motion/stage/types.d.ts +85 -0
- package/dist/motion/stage/types.d.ts.map +1 -0
- package/dist/motion/stage/types.js +0 -0
- package/dist/motion/stage/use-container-resize-mv.d.ts +13 -0
- package/dist/motion/stage/use-container-resize-mv.d.ts.map +1 -0
- package/dist/motion/stage/use-container-resize-mv.js +64 -0
- package/dist/motion/stage/use-container-resize-mv.js.map +1 -0
- package/dist/types/align.d.ts +3 -0
- package/dist/types/align.d.ts.map +1 -0
- package/dist/types/align.js +0 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +0 -0
- package/dist/types/lynx-view.d.ts +18 -0
- package/dist/types/lynx-view.d.ts.map +1 -0
- package/dist/types/lynx-view.js +0 -0
- package/dist/types/stage-props.d.ts +94 -0
- package/dist/types/stage-props.d.ts.map +1 -0
- package/dist/types/stage-props.js +0 -0
- package/dist/utils/align.d.ts +3 -0
- package/dist/utils/align.d.ts.map +1 -0
- package/dist/utils/align.js +15 -0
- package/dist/utils/align.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/transform.d.ts +121 -0
- package/dist/utils/transform.d.ts.map +1 -0
- package/dist/utils/transform.js +37 -0
- package/dist/utils/transform.js.map +1 -0
- package/package.json +73 -5
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useMemo, useRef } from "react";
|
|
3
|
+
import { OUTLINE_WEIGHT, SMOOTHING_OUTLINE_PATH, SMOOTHING_PATH } from "../../constants/stage.js";
|
|
4
|
+
import { useContainerResize } from "../../hooks/use-container-resize.js";
|
|
5
|
+
import { useMergedRefs } from "../../hooks/use-merged-refs.js";
|
|
6
|
+
import { computeFrameOffset, computeScaleRange, lerpFitScale, toAlignFactor } from "../../utils/index.js";
|
|
7
|
+
import { createContextWithProvider } from "../context/index.js";
|
|
8
|
+
const [StageSizeProvider, useOptionalStageSize] = createContextWithProvider('Stage', void 0, {
|
|
9
|
+
throwIfMissing: false
|
|
10
|
+
});
|
|
11
|
+
const DEVICE_CLIP_PATH = `path("${SMOOTHING_PATH}")`;
|
|
12
|
+
const DEVICE_OUTLINE_CLIP_PATH = `path("${SMOOTHING_OUTLINE_PATH}")`;
|
|
13
|
+
const VIEWPORT_LOCKED_STYLE = {
|
|
14
|
+
position: 'relative',
|
|
15
|
+
overflow: 'visible',
|
|
16
|
+
pointerEvents: 'none'
|
|
17
|
+
};
|
|
18
|
+
const VIEWPORT_FILL_STYLE = {
|
|
19
|
+
...VIEWPORT_LOCKED_STYLE,
|
|
20
|
+
width: '100%',
|
|
21
|
+
height: '100%'
|
|
22
|
+
};
|
|
23
|
+
const STAGE_ANCHOR_STYLE = {
|
|
24
|
+
width: 0,
|
|
25
|
+
height: 0,
|
|
26
|
+
transform: 'none',
|
|
27
|
+
filter: 'none',
|
|
28
|
+
perspective: 'none',
|
|
29
|
+
backdropFilter: 'none',
|
|
30
|
+
willChange: 'auto',
|
|
31
|
+
contain: 'none',
|
|
32
|
+
overflow: 'visible',
|
|
33
|
+
pointerEvents: 'none'
|
|
34
|
+
};
|
|
35
|
+
const ANCHOR_LOCKED_STYLE = {
|
|
36
|
+
...STAGE_ANCHOR_STYLE,
|
|
37
|
+
position: 'absolute'
|
|
38
|
+
};
|
|
39
|
+
const ANCHOR_CENTER_STYLE = {
|
|
40
|
+
...ANCHOR_LOCKED_STYLE,
|
|
41
|
+
left: '50%',
|
|
42
|
+
top: '50%'
|
|
43
|
+
};
|
|
44
|
+
const DEVICE_OUTLINE_LOCKED_STYLE = {
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
top: 0,
|
|
47
|
+
left: 0,
|
|
48
|
+
transformOrigin: 'top left',
|
|
49
|
+
pointerEvents: 'none',
|
|
50
|
+
clipPath: DEVICE_OUTLINE_CLIP_PATH
|
|
51
|
+
};
|
|
52
|
+
const DEVICE_FRAME_LOCKED_STYLE = {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
transformOrigin: 'top left',
|
|
57
|
+
overflow: 'hidden',
|
|
58
|
+
cursor: 'pointer',
|
|
59
|
+
pointerEvents: 'none',
|
|
60
|
+
clipPath: DEVICE_CLIP_PATH
|
|
61
|
+
};
|
|
62
|
+
function Stage({ className, style, width: widthProp, height: heightProp, fit = 'contain', alignX = 'center', alignY = 'center', placeX, placeY, children, baseWidth = 375, baseHeight = 812, zoom = 1, panX = 0, panY = 0 }) {
|
|
63
|
+
const ctx = useOptionalStageSize();
|
|
64
|
+
const containerWidth = widthProp ?? ctx?.width ?? baseWidth;
|
|
65
|
+
const containerHeight = heightProp ?? ctx?.height ?? baseHeight;
|
|
66
|
+
const scaleInfo = useMemo(()=>{
|
|
67
|
+
const scaleRange = computeScaleRange({
|
|
68
|
+
containerWidth,
|
|
69
|
+
containerHeight,
|
|
70
|
+
baseWidth,
|
|
71
|
+
baseHeight
|
|
72
|
+
});
|
|
73
|
+
const scale = lerpFitScale(scaleRange, 'cover' === fit ? 1 : 0) * zoom;
|
|
74
|
+
const ax = toAlignFactor(alignX);
|
|
75
|
+
const ay = toAlignFactor(alignY);
|
|
76
|
+
const { offsetX, offsetY } = computeFrameOffset({
|
|
77
|
+
ax,
|
|
78
|
+
ay,
|
|
79
|
+
scale,
|
|
80
|
+
baseWidth,
|
|
81
|
+
baseHeight
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
scale,
|
|
85
|
+
offsetX: offsetX + panX,
|
|
86
|
+
offsetY: offsetY + panY
|
|
87
|
+
};
|
|
88
|
+
}, [
|
|
89
|
+
containerWidth,
|
|
90
|
+
containerHeight,
|
|
91
|
+
baseWidth,
|
|
92
|
+
baseHeight,
|
|
93
|
+
fit,
|
|
94
|
+
alignX,
|
|
95
|
+
alignY,
|
|
96
|
+
zoom,
|
|
97
|
+
panX,
|
|
98
|
+
panY
|
|
99
|
+
]);
|
|
100
|
+
const resolvedPlaceX = placeX ?? alignX;
|
|
101
|
+
const resolvedPlaceY = placeY ?? alignY;
|
|
102
|
+
const hasMeasuredCtx = void 0 !== ctx;
|
|
103
|
+
const viewportStyle = useMemo(()=>{
|
|
104
|
+
if (void 0 === widthProp && void 0 === heightProp) {
|
|
105
|
+
if (hasMeasuredCtx) return VIEWPORT_FILL_STYLE;
|
|
106
|
+
return {
|
|
107
|
+
...VIEWPORT_LOCKED_STYLE,
|
|
108
|
+
width: containerWidth,
|
|
109
|
+
height: containerHeight
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
...VIEWPORT_LOCKED_STYLE,
|
|
114
|
+
width: widthProp ?? containerWidth,
|
|
115
|
+
height: heightProp ?? containerHeight
|
|
116
|
+
};
|
|
117
|
+
}, [
|
|
118
|
+
widthProp,
|
|
119
|
+
heightProp,
|
|
120
|
+
hasMeasuredCtx,
|
|
121
|
+
containerWidth,
|
|
122
|
+
containerHeight
|
|
123
|
+
]);
|
|
124
|
+
const anchorStyle = useMemo(()=>{
|
|
125
|
+
if ('center' === resolvedPlaceX && 'center' === resolvedPlaceY) return ANCHOR_CENTER_STYLE;
|
|
126
|
+
const ax = toAlignFactor(resolvedPlaceX);
|
|
127
|
+
const ay = toAlignFactor(resolvedPlaceY);
|
|
128
|
+
return {
|
|
129
|
+
...ANCHOR_LOCKED_STYLE,
|
|
130
|
+
left: `${100 * ax}%`,
|
|
131
|
+
top: `${100 * ay}%`
|
|
132
|
+
};
|
|
133
|
+
}, [
|
|
134
|
+
resolvedPlaceX,
|
|
135
|
+
resolvedPlaceY
|
|
136
|
+
]);
|
|
137
|
+
return /*#__PURE__*/ jsx("div", {
|
|
138
|
+
style: viewportStyle,
|
|
139
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
140
|
+
style: anchorStyle,
|
|
141
|
+
children: [
|
|
142
|
+
/*#__PURE__*/ jsx("div", {
|
|
143
|
+
className: className,
|
|
144
|
+
style: {
|
|
145
|
+
...style,
|
|
146
|
+
...DEVICE_OUTLINE_LOCKED_STYLE,
|
|
147
|
+
width: baseWidth + 2 * OUTLINE_WEIGHT,
|
|
148
|
+
height: baseHeight + 2 * OUTLINE_WEIGHT,
|
|
149
|
+
transform: `translate(${scaleInfo.offsetX - OUTLINE_WEIGHT * scaleInfo.scale}px, ${scaleInfo.offsetY - OUTLINE_WEIGHT * scaleInfo.scale}px) scale(${scaleInfo.scale})`
|
|
150
|
+
}
|
|
151
|
+
}),
|
|
152
|
+
/*#__PURE__*/ jsx("div", {
|
|
153
|
+
style: {
|
|
154
|
+
...DEVICE_FRAME_LOCKED_STYLE,
|
|
155
|
+
width: baseWidth,
|
|
156
|
+
height: baseHeight,
|
|
157
|
+
transform: `translate(${scaleInfo.offsetX}px, ${scaleInfo.offsetY}px) scale(${scaleInfo.scale})`
|
|
158
|
+
},
|
|
159
|
+
children: children
|
|
160
|
+
})
|
|
161
|
+
]
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function StageContainerImpl(props, ref) {
|
|
166
|
+
const { fallbackWidth = 0, fallbackHeight = 0, children, ...restProps } = props;
|
|
167
|
+
const containerRef = useRef(null);
|
|
168
|
+
const { width = fallbackWidth, height = fallbackHeight } = useContainerResize({
|
|
169
|
+
ref: containerRef
|
|
170
|
+
});
|
|
171
|
+
const mergedRef = useMergedRefs(containerRef, ref);
|
|
172
|
+
return /*#__PURE__*/ jsx(StageSizeProvider, {
|
|
173
|
+
width: width,
|
|
174
|
+
height: height,
|
|
175
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
176
|
+
ref: mergedRef,
|
|
177
|
+
...restProps,
|
|
178
|
+
children: children
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const StageContainer = /*#__PURE__*/ forwardRef(StageContainerImpl);
|
|
183
|
+
export { Stage, StageContainer };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=stage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components/stage/stage.js","sources":["../../../src/components/stage/stage.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { forwardRef, useMemo, useRef } from 'react'\nimport type {\n CSSProperties,\n ComponentPropsWithoutRef,\n DetailedHTMLProps,\n ForwardRefExoticComponent,\n ForwardedRef,\n HTMLAttributes,\n RefAttributes,\n} from 'react'\nimport type { JSX } from 'react/jsx-runtime'\n\nimport {\n OUTLINE_WEIGHT,\n SMOOTHING_OUTLINE_PATH,\n SMOOTHING_PATH,\n} from '../../constants/stage'\nimport { useContainerResize } from '../../hooks/use-container-resize'\nimport { useMergedRefs } from '../../hooks/use-merged-refs'\nimport type { StageProps } from '../../types'\nimport {\n computeFrameOffset,\n computeScaleRange,\n lerpFitScale,\n toAlignFactor,\n} from '../../utils'\nimport { createContextWithProvider } from '../context'\n\nconst [StageSizeProvider, useOptionalStageSize] = createContextWithProvider<\n { width: number, height: number }\n>('Stage', undefined, { throwIfMissing: false })\n\nconst DEVICE_CLIP_PATH = `path(\"${SMOOTHING_PATH}\")`\nconst DEVICE_OUTLINE_CLIP_PATH = `path(\"${SMOOTHING_OUTLINE_PATH}\")`\n\nconst VIEWPORT_LOCKED_STYLE: CSSProperties = {\n position: 'relative',\n overflow: 'visible',\n pointerEvents: 'none',\n}\n\nconst VIEWPORT_FILL_STYLE: CSSProperties = {\n ...VIEWPORT_LOCKED_STYLE,\n width: '100%',\n height: '100%',\n}\n\nconst STAGE_ANCHOR_STYLE: CSSProperties = {\n width: 0,\n height: 0,\n transform: 'none',\n filter: 'none',\n perspective: 'none',\n backdropFilter: 'none',\n willChange: 'auto',\n contain: 'none',\n overflow: 'visible',\n pointerEvents: 'none',\n}\n\nconst ANCHOR_LOCKED_STYLE: CSSProperties = {\n ...STAGE_ANCHOR_STYLE,\n position: 'absolute',\n}\n\nconst ANCHOR_CENTER_STYLE: CSSProperties = {\n ...ANCHOR_LOCKED_STYLE,\n left: '50%',\n top: '50%',\n}\n\nconst DEVICE_OUTLINE_LOCKED_STYLE: CSSProperties = {\n position: 'absolute',\n top: 0,\n left: 0,\n transformOrigin: 'top left',\n pointerEvents: 'none',\n clipPath: DEVICE_OUTLINE_CLIP_PATH,\n}\n\nconst DEVICE_FRAME_LOCKED_STYLE: CSSProperties = {\n position: 'absolute',\n top: 0,\n left: 0,\n transformOrigin: 'top left',\n overflow: 'hidden',\n cursor: 'pointer',\n pointerEvents: 'none',\n clipPath: DEVICE_CLIP_PATH,\n}\n\nfunction Stage({\n className,\n style,\n width: widthProp,\n height: heightProp,\n fit = 'contain',\n alignX = 'center',\n alignY = 'center',\n placeX,\n placeY,\n children,\n baseWidth = 375,\n baseHeight = 812,\n zoom = 1,\n panX = 0,\n panY = 0,\n}: StageProps): JSX.Element {\n const ctx = useOptionalStageSize()\n\n const containerWidth = widthProp\n ?? ctx?.width ?? baseWidth\n\n const containerHeight = heightProp\n ?? ctx?.height ?? baseHeight\n\n const scaleInfo = useMemo(() => {\n const scaleRange = computeScaleRange({\n containerWidth,\n containerHeight,\n baseWidth,\n baseHeight,\n })\n const scale = lerpFitScale(scaleRange, fit === 'cover' ? 1 : 0) * zoom\n\n const ax = toAlignFactor(alignX)\n const ay = toAlignFactor(alignY)\n\n const { offsetX, offsetY } = computeFrameOffset({\n ax,\n ay,\n scale,\n baseWidth,\n baseHeight,\n })\n\n return { scale, offsetX: offsetX + panX, offsetY: offsetY + panY }\n }, [\n containerWidth,\n containerHeight,\n baseWidth,\n baseHeight,\n fit,\n alignX,\n alignY,\n zoom,\n panX,\n panY,\n ])\n\n const resolvedPlaceX = placeX ?? alignX\n const resolvedPlaceY = placeY ?? alignY\n\n const hasMeasuredCtx = ctx !== undefined\n\n const viewportStyle = useMemo<CSSProperties>(() => {\n if (widthProp === undefined && heightProp === undefined) {\n if (hasMeasuredCtx) {\n return VIEWPORT_FILL_STYLE\n }\n return {\n ...VIEWPORT_LOCKED_STYLE,\n width: containerWidth,\n height: containerHeight,\n }\n }\n return {\n ...VIEWPORT_LOCKED_STYLE,\n width: widthProp ?? containerWidth,\n height: heightProp ?? containerHeight,\n }\n }, [\n widthProp,\n heightProp,\n hasMeasuredCtx,\n containerWidth,\n containerHeight,\n ])\n\n const anchorStyle = useMemo<CSSProperties>(() => {\n if (resolvedPlaceX === 'center' && resolvedPlaceY === 'center') {\n return ANCHOR_CENTER_STYLE\n }\n const ax = toAlignFactor(resolvedPlaceX)\n const ay = toAlignFactor(resolvedPlaceY)\n return {\n ...ANCHOR_LOCKED_STYLE,\n left: `${ax * 100}%`,\n top: `${ay * 100}%`,\n }\n }, [resolvedPlaceX, resolvedPlaceY])\n\n return (\n <div\n style={viewportStyle}\n >\n {/* Anchor & coordinate system element, no size */}\n <div\n style={anchorStyle}\n >\n {/* Device outline */}\n <div\n className={className}\n style={{\n ...style,\n ...DEVICE_OUTLINE_LOCKED_STYLE,\n width: baseWidth + 2 * OUTLINE_WEIGHT,\n height: baseHeight + 2 * OUTLINE_WEIGHT,\n transform: `translate(${\n scaleInfo.offsetX - OUTLINE_WEIGHT * scaleInfo.scale\n }px, ${\n scaleInfo.offsetY - OUTLINE_WEIGHT * scaleInfo.scale\n }px) scale(${scaleInfo.scale})`,\n }}\n />\n\n {/* Device frame */}\n <div\n style={{\n ...DEVICE_FRAME_LOCKED_STYLE,\n width: baseWidth,\n height: baseHeight,\n transform:\n `translate(${scaleInfo.offsetX}px, ${scaleInfo.offsetY}px) scale(${scaleInfo.scale})`,\n }}\n >\n {children}\n </div>\n </div>\n </div>\n )\n}\n\ntype StageContainerProps = ComponentPropsWithoutRef<'div'> & {\n fallbackWidth?: number\n fallbackHeight?: number\n}\n\nfunction StageContainerImpl(\n props: StageContainerProps,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const { fallbackWidth = 0, fallbackHeight = 0, children, ...restProps } =\n props\n\n const containerRef = useRef<HTMLDivElement | null>(null)\n const { width = fallbackWidth, height = fallbackHeight } = useContainerResize(\n {\n ref: containerRef,\n },\n )\n\n const mergedRef = useMergedRefs(containerRef, ref)\n\n return (\n <StageSizeProvider\n width={width}\n height={height}\n >\n <div ref={mergedRef} {...restProps}>\n {children}\n </div>\n </StageSizeProvider>\n )\n}\n\nconst StageContainer: ForwardRefExoticComponent<\n & Omit<\n DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>,\n 'ref'\n >\n & {\n fallbackWidth?: number\n fallbackHeight?: number\n }\n & RefAttributes<HTMLDivElement>\n> = forwardRef(StageContainerImpl)\n\nexport { Stage, StageContainer }\n"],"names":["StageSizeProvider","useOptionalStageSize","createContextWithProvider","undefined","DEVICE_CLIP_PATH","SMOOTHING_PATH","DEVICE_OUTLINE_CLIP_PATH","SMOOTHING_OUTLINE_PATH","VIEWPORT_LOCKED_STYLE","VIEWPORT_FILL_STYLE","STAGE_ANCHOR_STYLE","ANCHOR_LOCKED_STYLE","ANCHOR_CENTER_STYLE","DEVICE_OUTLINE_LOCKED_STYLE","DEVICE_FRAME_LOCKED_STYLE","Stage","className","style","widthProp","heightProp","fit","alignX","alignY","placeX","placeY","children","baseWidth","baseHeight","zoom","panX","panY","ctx","containerWidth","containerHeight","scaleInfo","useMemo","scaleRange","computeScaleRange","scale","lerpFitScale","ax","toAlignFactor","ay","offsetX","offsetY","computeFrameOffset","resolvedPlaceX","resolvedPlaceY","hasMeasuredCtx","viewportStyle","anchorStyle","OUTLINE_WEIGHT","StageContainerImpl","props","ref","fallbackWidth","fallbackHeight","restProps","containerRef","useRef","width","height","useContainerResize","mergedRef","useMergedRefs","StageContainer","forwardRef"],"mappings":"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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const OUTLINE_WEIGHT = 6;
|
|
2
|
+
export declare const SMOOTHING_OUTLINE_PATH = "M0 96C0 62.3968 0 45.5953 6.53961 32.7606C12.292 21.4708 21.4708 12.292 32.7606 6.53961C45.5953 0 62.3969 0 96 0H291C324.603 0 341.405 0 354.239 6.53961C365.529 12.292 374.708 21.4708 380.46 32.7606C387 45.5953 387 62.3968 387 96V728C387 761.603 387 778.405 380.46 791.239C374.708 802.529 365.529 811.708 354.239 817.46C341.405 824 324.603 824 291 824H96C62.3969 824 45.5953 824 32.7606 817.46C21.4708 811.708 12.292 802.529 6.53961 791.239C0 778.405 0 761.603 0 728V96Z";
|
|
3
|
+
export declare const SMOOTHING_PATH = "M0 86.4C0 56.1572 0 41.0357 5.88565 29.4845C11.0628 19.3238 19.3238 11.0628 29.4845 5.88565C41.0357 0 56.1572 0 86.4 0H288.6C318.843 0 333.964 0 345.516 5.88565C355.676 11.0628 363.937 19.3238 369.114 29.4845C375 41.0357 375 56.1572 375 86.4V725.6C375 755.843 375 770.964 369.114 782.516C363.937 792.676 355.676 800.937 345.516 806.114C333.964 812 318.843 812 288.6 812H86.4C56.1572 812 41.0357 812 29.4845 806.114C19.3238 800.937 11.0628 792.676 5.88565 782.516C0 770.964 0 755.843 0 725.6V86.4Z";
|
|
4
|
+
//# sourceMappingURL=stage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage.d.ts","sourceRoot":"","sources":["../../src/constants/stage.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B,eAAO,MAAM,sBAAsB,2dACub,CAAA;AAE1d,eAAO,MAAM,cAAc,qfACyd,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const OUTLINE_WEIGHT = 6;
|
|
2
|
+
const SMOOTHING_OUTLINE_PATH = "M0 96C0 62.3968 0 45.5953 6.53961 32.7606C12.292 21.4708 21.4708 12.292 32.7606 6.53961C45.5953 0 62.3969 0 96 0H291C324.603 0 341.405 0 354.239 6.53961C365.529 12.292 374.708 21.4708 380.46 32.7606C387 45.5953 387 62.3968 387 96V728C387 761.603 387 778.405 380.46 791.239C374.708 802.529 365.529 811.708 354.239 817.46C341.405 824 324.603 824 291 824H96C62.3969 824 45.5953 824 32.7606 817.46C21.4708 811.708 12.292 802.529 6.53961 791.239C0 778.405 0 761.603 0 728V96Z";
|
|
3
|
+
const SMOOTHING_PATH = "M0 86.4C0 56.1572 0 41.0357 5.88565 29.4845C11.0628 19.3238 19.3238 11.0628 29.4845 5.88565C41.0357 0 56.1572 0 86.4 0H288.6C318.843 0 333.964 0 345.516 5.88565C355.676 11.0628 363.937 19.3238 369.114 29.4845C375 41.0357 375 56.1572 375 86.4V725.6C375 755.843 375 770.964 369.114 782.516C363.937 792.676 355.676 800.937 345.516 806.114C333.964 812 318.843 812 288.6 812H86.4C56.1572 812 41.0357 812 29.4845 806.114C19.3238 800.937 11.0628 792.676 5.88565 782.516C0 770.964 0 755.843 0 725.6V86.4Z";
|
|
4
|
+
export { OUTLINE_WEIGHT, SMOOTHING_OUTLINE_PATH, SMOOTHING_PATH };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=stage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants/stage.js","sources":["../../src/constants/stage.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nexport const OUTLINE_WEIGHT = 6\n\nexport const SMOOTHING_OUTLINE_PATH =\n `M0 96C0 62.3968 0 45.5953 6.53961 32.7606C12.292 21.4708 21.4708 12.292 32.7606 6.53961C45.5953 0 62.3969 0 96 0H291C324.603 0 341.405 0 354.239 6.53961C365.529 12.292 374.708 21.4708 380.46 32.7606C387 45.5953 387 62.3968 387 96V728C387 761.603 387 778.405 380.46 791.239C374.708 802.529 365.529 811.708 354.239 817.46C341.405 824 324.603 824 291 824H96C62.3969 824 45.5953 824 32.7606 817.46C21.4708 811.708 12.292 802.529 6.53961 791.239C0 778.405 0 761.603 0 728V96Z`\n\nexport const SMOOTHING_PATH =\n `M0 86.4C0 56.1572 0 41.0357 5.88565 29.4845C11.0628 19.3238 19.3238 11.0628 29.4845 5.88565C41.0357 0 56.1572 0 86.4 0H288.6C318.843 0 333.964 0 345.516 5.88565C355.676 11.0628 363.937 19.3238 369.114 29.4845C375 41.0357 375 56.1572 375 86.4V725.6C375 755.843 375 770.964 369.114 782.516C363.937 792.676 355.676 800.937 345.516 806.114C333.964 812 318.843 812 288.6 812H86.4C56.1572 812 41.0357 812 29.4845 806.114C19.3238 800.937 11.0628 792.676 5.88565 782.516C0 770.964 0 755.843 0 725.6V86.4Z`\n"],"names":["OUTLINE_WEIGHT","SMOOTHING_OUTLINE_PATH","SMOOTHING_PATH"],"mappings":"AAIO,MAAMA,iBAAiB;AAEvB,MAAMC,yBACX;AAEK,MAAMC,iBACX"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useContainerResize } from './use-container-resize';
|
|
2
|
+
export { useEventCallback } from './use-event-callback';
|
|
3
|
+
export { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect';
|
|
4
|
+
export { useMergedRefs } from './use-merged-refs';
|
|
5
|
+
export { useIsClient } from './use-is-client';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useContainerResize } from "./use-container-resize.js";
|
|
2
|
+
export { useEventCallback } from "./use-event-callback.js";
|
|
3
|
+
export { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
4
|
+
export { useMergedRefs } from "./use-merged-refs.js";
|
|
5
|
+
export { useIsClient } from "./use-is-client.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
interface Size {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
}
|
|
6
|
+
/** Constructor type for ResizeObserver */
|
|
7
|
+
type ResizeObserverCtor = new (callback: ResizeObserverCallback) => ResizeObserver;
|
|
8
|
+
interface UseContainerResizeOptions<T> {
|
|
9
|
+
/** The ref of the element to observe. */
|
|
10
|
+
ref: RefObject<T | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Optional: inject a polyfill constructor (e.g. `resize-observer-polyfill`)
|
|
13
|
+
*/
|
|
14
|
+
ResizeObserverImpl?: ResizeObserverCtor;
|
|
15
|
+
/**
|
|
16
|
+
* Optional: callback mode — if provided, the hook will not re-render,
|
|
17
|
+
* it will just call `onResize` when size changes.
|
|
18
|
+
*/
|
|
19
|
+
onResize?: (size: Size) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A lightweight version of the `useResizeObserver` hook (https://usehooks-ts.com/react-hook/use-resize-observer).
|
|
23
|
+
*
|
|
24
|
+
* Differences from the original:
|
|
25
|
+
* - Only supports the default `'content-box'` model
|
|
26
|
+
* - Optional polyfill injection (`ResizeObserverImpl`)
|
|
27
|
+
*/
|
|
28
|
+
declare function useContainerResize<T extends HTMLElement = HTMLElement>({ ref, ResizeObserverImpl, onResize: onResizeProp, }: UseContainerResizeOptions<T>): Size;
|
|
29
|
+
export { useContainerResize };
|
|
30
|
+
//# sourceMappingURL=use-container-resize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-container-resize.d.ts","sourceRoot":"","sources":["../../src/hooks/use-container-resize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,UAAU,IAAI;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,0CAA0C;AAC1C,KAAK,kBAAkB,GAAG,KACxB,QAAQ,EAAE,sBAAsB,KAC7B,cAAc,CAAA;AAEnB,UAAU,yBAAyB,CAAC,CAAC;IACnC,yCAAyC;IACzC,GAAG,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IACxB;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;CAChC;AACD;;;;;;GAMG;AACH,iBAAS,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,EAC/D,GAAG,EACH,kBAAkB,EAClB,QAAQ,EAAE,YAAY,GACvB,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,IAAI,CAwErC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import { useEventCallback } from "./use-event-callback.js";
|
|
3
|
+
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
4
|
+
function useContainerResize({ ref, ResizeObserverImpl, onResize: onResizeProp }) {
|
|
5
|
+
const [size, setSize] = useState({});
|
|
6
|
+
const prev = useRef({});
|
|
7
|
+
const onResize = useEventCallback(onResizeProp);
|
|
8
|
+
const hasOnResize = void 0 !== onResizeProp;
|
|
9
|
+
useIsomorphicLayoutEffect(()=>{
|
|
10
|
+
const element = ref.current;
|
|
11
|
+
if (!element) return;
|
|
12
|
+
const updateSize = (width, height)=>{
|
|
13
|
+
const changed = width !== prev.current.width || height !== prev.current.height;
|
|
14
|
+
if (!changed) return;
|
|
15
|
+
const next = {
|
|
16
|
+
width,
|
|
17
|
+
height
|
|
18
|
+
};
|
|
19
|
+
prev.current = next;
|
|
20
|
+
if (hasOnResize) onResize(next);
|
|
21
|
+
else setSize(next);
|
|
22
|
+
};
|
|
23
|
+
const rect = element.getBoundingClientRect();
|
|
24
|
+
updateSize(rect.width, rect.height);
|
|
25
|
+
const RO = ResizeObserverImpl ?? ("u" > typeof window && 'ResizeObserver' in window ? window.ResizeObserver : void 0);
|
|
26
|
+
if (!RO) return;
|
|
27
|
+
const observer = new RO((entries)=>{
|
|
28
|
+
const entry = entries[0];
|
|
29
|
+
if (!entry) return;
|
|
30
|
+
let width = 0;
|
|
31
|
+
let height = 0;
|
|
32
|
+
const cbsUnknown = entry.contentBoxSize;
|
|
33
|
+
if (Array.isArray(cbsUnknown)) {
|
|
34
|
+
const first = entry.contentBoxSize[0];
|
|
35
|
+
if (first) {
|
|
36
|
+
width = first.inlineSize;
|
|
37
|
+
height = first.blockSize;
|
|
38
|
+
}
|
|
39
|
+
} else if (isContentBoxSizeSingleItem(cbsUnknown)) {
|
|
40
|
+
width = cbsUnknown.inlineSize;
|
|
41
|
+
height = cbsUnknown.blockSize;
|
|
42
|
+
} else {
|
|
43
|
+
width = entry.contentRect.width;
|
|
44
|
+
height = entry.contentRect.height;
|
|
45
|
+
}
|
|
46
|
+
updateSize(width, height);
|
|
47
|
+
});
|
|
48
|
+
observer.observe(element);
|
|
49
|
+
return ()=>observer.disconnect();
|
|
50
|
+
}, [
|
|
51
|
+
ref,
|
|
52
|
+
ResizeObserverImpl,
|
|
53
|
+
hasOnResize,
|
|
54
|
+
onResize
|
|
55
|
+
]);
|
|
56
|
+
return size;
|
|
57
|
+
}
|
|
58
|
+
function isContentBoxSizeSingleItem(v) {
|
|
59
|
+
return 'object' == typeof v && null !== v && 'number' == typeof v.inlineSize && 'number' == typeof v.blockSize;
|
|
60
|
+
}
|
|
61
|
+
export { useContainerResize };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=use-container-resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-container-resize.js","sources":["../../src/hooks/use-container-resize.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useRef, useState } from 'react'\nimport type { RefObject } from 'react'\n\nimport { useEventCallback } from './use-event-callback'\nimport { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'\n\ninterface Size {\n width?: number\n height?: number\n}\n\n/** Constructor type for ResizeObserver */\ntype ResizeObserverCtor = new(\n callback: ResizeObserverCallback,\n) => ResizeObserver\n\ninterface UseContainerResizeOptions<T> {\n /** The ref of the element to observe. */\n ref: RefObject<T | null>\n /**\n * Optional: inject a polyfill constructor (e.g. `resize-observer-polyfill`)\n */\n ResizeObserverImpl?: ResizeObserverCtor\n /**\n * Optional: callback mode — if provided, the hook will not re-render,\n * it will just call `onResize` when size changes.\n */\n onResize?: (size: Size) => void\n}\n/**\n * A lightweight version of the `useResizeObserver` hook (https://usehooks-ts.com/react-hook/use-resize-observer).\n *\n * Differences from the original:\n * - Only supports the default `'content-box'` model\n * - Optional polyfill injection (`ResizeObserverImpl`)\n */\nfunction useContainerResize<T extends HTMLElement = HTMLElement>({\n ref,\n ResizeObserverImpl,\n onResize: onResizeProp,\n}: UseContainerResizeOptions<T>): Size {\n const [size, setSize] = useState<Size>({})\n const prev = useRef<Size>({})\n const onResize = useEventCallback(onResizeProp)\n const hasOnResize = onResizeProp !== undefined\n\n useIsomorphicLayoutEffect(() => {\n const element = ref.current\n if (!element) return\n\n const updateSize = (width: number, height: number) => {\n const changed = width !== prev.current.width\n || height !== prev.current.height\n\n if (!changed) return\n\n const next: Size = { width, height }\n prev.current = next\n if (hasOnResize) {\n onResize(next)\n } else {\n setSize(next)\n }\n }\n\n const rect = element.getBoundingClientRect()\n updateSize(rect.width, rect.height)\n\n // SSR & Polyfill\n // Prefer injected ctor; otherwise read from the environment in a typed way.\n const RO: ResizeObserverCtor | undefined = ResizeObserverImpl\n ?? ((typeof window !== 'undefined' && 'ResizeObserver' in window)\n ? window.ResizeObserver\n : undefined)\n\n if (!RO) return\n\n const observer: ResizeObserver = new RO(\n (entries) => {\n const entry = entries[0]\n if (!entry) return\n let width = 0\n let height = 0\n\n const cbsUnknown = entry.contentBoxSize as unknown\n\n if (Array.isArray(cbsUnknown)) {\n // The standard makes contentBoxSize an array...\n const first = entry.contentBoxSize[0]\n if (first) {\n width = first.inlineSize\n height = first.blockSize\n }\n } else if (isContentBoxSizeSingleItem(cbsUnknown)) {\n // ... but old versions of Firefox treat it as a single item\n width = cbsUnknown.inlineSize\n height = cbsUnknown.blockSize\n } else {\n // fallback to legacy API\n width = entry.contentRect.width\n height = entry.contentRect.height\n }\n\n updateSize(width, height)\n },\n )\n\n observer.observe(element)\n return () => observer.disconnect()\n }, [ref, ResizeObserverImpl, hasOnResize, onResize])\n\n return size\n}\n\nexport { useContainerResize }\n\nfunction isContentBoxSizeSingleItem(\n v: unknown,\n): v is { inlineSize: number, blockSize: number } {\n return (\n typeof v === 'object'\n && v !== null\n && typeof (v as { inlineSize?: unknown }).inlineSize === 'number'\n && typeof (v as { blockSize?: unknown }).blockSize === 'number'\n )\n}\n"],"names":["useContainerResize","ref","ResizeObserverImpl","onResizeProp","size","setSize","useState","prev","useRef","onResize","useEventCallback","hasOnResize","undefined","useIsomorphicLayoutEffect","element","updateSize","width","height","changed","next","rect","RO","window","observer","entries","entry","cbsUnknown","Array","first","isContentBoxSizeSingleItem","v"],"mappings":";;;AAwCA,SAASA,mBAAwD,EAC/DC,GAAG,EACHC,kBAAkB,EAClB,UAAUC,YAAY,EACO;IAC7B,MAAM,CAACC,MAAMC,QAAQ,GAAGC,SAAe,CAAC;IACxC,MAAMC,OAAOC,OAAa,CAAC;IAC3B,MAAMC,WAAWC,iBAAiBP;IAClC,MAAMQ,cAAcR,AAAiBS,WAAjBT;IAEpBU,0BAA0B;QACxB,MAAMC,UAAUb,IAAI,OAAO;QAC3B,IAAI,CAACa,SAAS;QAEd,MAAMC,aAAa,CAACC,OAAeC;YACjC,MAAMC,UAAUF,UAAUT,KAAK,OAAO,CAAC,KAAK,IACvCU,WAAWV,KAAK,OAAO,CAAC,MAAM;YAEnC,IAAI,CAACW,SAAS;YAEd,MAAMC,OAAa;gBAAEH;gBAAOC;YAAO;YACnCV,KAAK,OAAO,GAAGY;YACf,IAAIR,aACFF,SAASU;iBAETd,QAAQc;QAEZ;QAEA,MAAMC,OAAON,QAAQ,qBAAqB;QAC1CC,WAAWK,KAAK,KAAK,EAAEA,KAAK,MAAM;QAIlC,MAAMC,KAAqCnB,sBACpC,CAAkB,MAAlB,OAAOoB,UAA0B,oBAAoBA,SACtDA,OAAO,cAAc,GACrBV,MAAQ;QAEd,IAAI,CAACS,IAAI;QAET,MAAME,WAA2B,IAAIF,GACnC,CAACG;YACC,MAAMC,QAAQD,OAAO,CAAC,EAAE;YACxB,IAAI,CAACC,OAAO;YACZ,IAAIT,QAAQ;YACZ,IAAIC,SAAS;YAEb,MAAMS,aAAaD,MAAM,cAAc;YAEvC,IAAIE,MAAM,OAAO,CAACD,aAAa;gBAE7B,MAAME,QAAQH,MAAM,cAAc,CAAC,EAAE;gBACrC,IAAIG,OAAO;oBACTZ,QAAQY,MAAM,UAAU;oBACxBX,SAASW,MAAM,SAAS;gBAC1B;YACF,OAAO,IAAIC,2BAA2BH,aAAa;gBAEjDV,QAAQU,WAAW,UAAU;gBAC7BT,SAASS,WAAW,SAAS;YAC/B,OAAO;gBAELV,QAAQS,MAAM,WAAW,CAAC,KAAK;gBAC/BR,SAASQ,MAAM,WAAW,CAAC,MAAM;YACnC;YAEAV,WAAWC,OAAOC;QACpB;QAGFM,SAAS,OAAO,CAACT;QACjB,OAAO,IAAMS,SAAS,UAAU;IAClC,GAAG;QAACtB;QAAKC;QAAoBS;QAAaF;KAAS;IAEnD,OAAOL;AACT;AAIA,SAASyB,2BACPC,CAAU;IAEV,OACE,AAAa,YAAb,OAAOA,KACJA,AAAM,SAANA,KACA,AAAsD,YAAtD,OAAQA,EAA+B,UAAU,IACjD,AAAoD,YAApD,OAAQA,EAA8B,SAAS;AAEtD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEventCallback
|
|
3
|
+
*
|
|
4
|
+
* Returns a stable callback whose identity never changes across renders, but
|
|
5
|
+
* which always invokes the latest `fn` from props/state. Useful for passing
|
|
6
|
+
* callbacks to child components, event handlers, or external systems without
|
|
7
|
+
* re-binding on every render and without stale-closure bugs.
|
|
8
|
+
*
|
|
9
|
+
* Unlike React's experimental `useEffectEvent`, this hook returns a stable
|
|
10
|
+
* proxy that can be passed around anywhere — including during render, in
|
|
11
|
+
* effects, event handlers, and async callbacks. However, the proxy itself
|
|
12
|
+
* must not be called during render. This is the pattern commonly known as
|
|
13
|
+
* `useEvent` (React RFC #1825) or `useEventCallback` (Material UI, react-use).
|
|
14
|
+
*
|
|
15
|
+
* - Internally stores the latest `fn` in a ref, synced via
|
|
16
|
+
* `useIsomorphicLayoutEffect` so the ref is fresh by the time any
|
|
17
|
+
* post-commit layout-phase code (or anything that follows) reads it.
|
|
18
|
+
* - Returns a memoized proxy that delegates to `ref.current`.
|
|
19
|
+
* - When `fn` is `undefined`, the proxy returns `fallbackResult` (or
|
|
20
|
+
* `undefined` if no fallback is provided — the proxy's return type then
|
|
21
|
+
* widens to include `undefined`).
|
|
22
|
+
*
|
|
23
|
+
* Caveat: calling the proxy during render still returns the *previous*
|
|
24
|
+
* render's `fn`, because the ref is synced after commit. This matches React's
|
|
25
|
+
* own rule that `useEffectEvent` must not be called during render.
|
|
26
|
+
*
|
|
27
|
+
* @param fn The callback function to be stabilized. May be `undefined`.
|
|
28
|
+
* @param fallbackResult Value returned when `fn` is `undefined`. Defaults to
|
|
29
|
+
* `undefined`, in which case the return type widens accordingly.
|
|
30
|
+
* @returns A stable function that always calls the latest `fn`.
|
|
31
|
+
*/
|
|
32
|
+
declare function useEventCallback<TArgs extends unknown[]>(fn: ((...args: TArgs) => void) | undefined): (...args: TArgs) => void;
|
|
33
|
+
declare function useEventCallback<TArgs extends unknown[], TResult>(fn: ((...args: TArgs) => TResult) | undefined, fallbackResult: TResult): (...args: TArgs) => TResult;
|
|
34
|
+
declare function useEventCallback<TArgs extends unknown[], TResult>(fn: ((...args: TArgs) => TResult) | undefined): (...args: TArgs) => TResult | undefined;
|
|
35
|
+
export { useEventCallback };
|
|
36
|
+
//# sourceMappingURL=use-event-callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-event-callback.d.ts","sourceRoot":"","sources":["../../src/hooks/use-event-callback.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,gBAAgB,CAAC,KAAK,SAAS,OAAO,EAAE,EAC/C,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,SAAS,GACzC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;AAE3B,iBAAS,gBAAgB,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACxD,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG,SAAS,EAC7C,cAAc,EAAE,OAAO,GACtB,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAA;AAE9B,iBAAS,gBAAgB,CAAC,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EACxD,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG,SAAS,GAC5C,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAAG,SAAS,CAAA;AA8B1C,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
3
|
+
function useEventCallback(fn, fallbackResult) {
|
|
4
|
+
const fnRef = useRef(fn);
|
|
5
|
+
const fallbackRef = useRef(fallbackResult);
|
|
6
|
+
useIsomorphicLayoutEffect(()=>{
|
|
7
|
+
fnRef.current = fn;
|
|
8
|
+
fallbackRef.current = fallbackResult;
|
|
9
|
+
});
|
|
10
|
+
return useMemo(()=>(...args)=>{
|
|
11
|
+
const f = fnRef.current;
|
|
12
|
+
if (f) return f(...args);
|
|
13
|
+
return fallbackRef.current;
|
|
14
|
+
}, []);
|
|
15
|
+
}
|
|
16
|
+
export { useEventCallback };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=use-event-callback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-event-callback.js","sources":["../../src/hooks/use-event-callback.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo, useRef } from 'react'\n\nimport { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'\n\n/**\n * useEventCallback\n *\n * Returns a stable callback whose identity never changes across renders, but\n * which always invokes the latest `fn` from props/state. Useful for passing\n * callbacks to child components, event handlers, or external systems without\n * re-binding on every render and without stale-closure bugs.\n *\n * Unlike React's experimental `useEffectEvent`, this hook returns a stable\n * proxy that can be passed around anywhere — including during render, in\n * effects, event handlers, and async callbacks. However, the proxy itself\n * must not be called during render. This is the pattern commonly known as\n * `useEvent` (React RFC #1825) or `useEventCallback` (Material UI, react-use).\n *\n * - Internally stores the latest `fn` in a ref, synced via\n * `useIsomorphicLayoutEffect` so the ref is fresh by the time any\n * post-commit layout-phase code (or anything that follows) reads it.\n * - Returns a memoized proxy that delegates to `ref.current`.\n * - When `fn` is `undefined`, the proxy returns `fallbackResult` (or\n * `undefined` if no fallback is provided — the proxy's return type then\n * widens to include `undefined`).\n *\n * Caveat: calling the proxy during render still returns the *previous*\n * render's `fn`, because the ref is synced after commit. This matches React's\n * own rule that `useEffectEvent` must not be called during render.\n *\n * @param fn The callback function to be stabilized. May be `undefined`.\n * @param fallbackResult Value returned when `fn` is `undefined`. Defaults to\n * `undefined`, in which case the return type widens accordingly.\n * @returns A stable function that always calls the latest `fn`.\n */\nfunction useEventCallback<TArgs extends unknown[]>(\n fn: ((...args: TArgs) => void) | undefined,\n): (...args: TArgs) => void\n\nfunction useEventCallback<TArgs extends unknown[], TResult>(\n fn: ((...args: TArgs) => TResult) | undefined,\n fallbackResult: TResult,\n): (...args: TArgs) => TResult\n\nfunction useEventCallback<TArgs extends unknown[], TResult>(\n fn: ((...args: TArgs) => TResult) | undefined,\n): (...args: TArgs) => TResult | undefined\n\nfunction useEventCallback<TArgs extends unknown[], TResult>(\n fn: ((...args: TArgs) => TResult) | undefined,\n fallbackResult?: TResult,\n): (...args: TArgs) => TResult | undefined {\n const fnRef = useRef(fn)\n const fallbackRef = useRef(fallbackResult)\n\n // Layout effect, not passive effect: ensures the ref is up-to-date before\n // any subsequent useLayoutEffect / useEffect in the tree reads it. The\n // proxy is therefore safe to call from any effect phase.\n useIsomorphicLayoutEffect(() => {\n fnRef.current = fn\n fallbackRef.current = fallbackResult\n })\n\n // Stable proxy that delegates to the latest ref. Empty deps — identity is\n // truly stable across the component's lifetime.\n return useMemo(() => {\n return (...args: TArgs) => {\n const f = fnRef.current\n if (f) {\n return f(...args)\n }\n return fallbackRef.current\n }\n }, [])\n}\n\nexport { useEventCallback }\n"],"names":["useEventCallback","fn","fallbackResult","fnRef","useRef","fallbackRef","useIsomorphicLayoutEffect","useMemo","args","f"],"mappings":";;AAoDA,SAASA,iBACPC,EAA6C,EAC7CC,cAAwB;IAExB,MAAMC,QAAQC,OAAOH;IACrB,MAAMI,cAAcD,OAAOF;IAK3BI,0BAA0B;QACxBH,MAAM,OAAO,GAAGF;QAChBI,YAAY,OAAO,GAAGH;IACxB;IAIA,OAAOK,QAAQ,IACN,CAAC,GAAGC;YACT,MAAMC,IAAIN,MAAM,OAAO;YACvB,IAAIM,GACF,OAAOA,KAAKD;YAEd,OAAOH,YAAY,OAAO;QAC5B,GACC,EAAE;AACP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-is-client.d.ts","sourceRoot":"","sources":["../../src/hooks/use-is-client.ts"],"names":[],"mappings":"AAoBA,wBAAgB,WAAW,IAAI,OAAO,CAMrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
function subscribe() {
|
|
3
|
+
return ()=>{};
|
|
4
|
+
}
|
|
5
|
+
function getClientSnapshot() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
function getServerSnapshot() {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
function useIsClient() {
|
|
12
|
+
return useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
|
|
13
|
+
}
|
|
14
|
+
export { useIsClient };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=use-is-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-is-client.js","sources":["../../src/hooks/use-is-client.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useSyncExternalStore } from 'react'\n\nfunction subscribe(): () => void {\n return () => {\n // No-op for static snapshot\n }\n}\n\nfunction getClientSnapshot(): boolean {\n return true\n}\n\nfunction getServerSnapshot(): boolean {\n return false\n}\n\nexport function useIsClient(): boolean {\n return useSyncExternalStore(\n subscribe,\n getClientSnapshot,\n getServerSnapshot,\n )\n}\n"],"names":["subscribe","getClientSnapshot","getServerSnapshot","useIsClient","useSyncExternalStore"],"mappings":";AAMA,SAASA;IACP,OAAO,KAEP;AACF;AAEA,SAASC;IACP,OAAO;AACT;AAEA,SAASC;IACP,OAAO;AACT;AAEO,SAASC;IACd,OAAOC,qBACLJ,WACAC,mBACAC;AAEJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../src/hooks/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAmB,MAAM,OAAO,CAAA;AAOlD,QAAA,MAAM,yBAAyB,EAAE,OAAO,SAErB,CAAA;AAEnB,OAAO,EAAE,yBAAyB,EAAE,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
|
+
const isServer = "u" < typeof window || "u" < typeof document;
|
|
3
|
+
const useIsomorphicLayoutEffect = isServer ? useEffect : useLayoutEffect;
|
|
4
|
+
export { useIsomorphicLayoutEffect };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=use-isomorphic-layout-effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-isomorphic-layout-effect.js","sources":["../../src/hooks/use-isomorphic-layout-effect.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useEffect, useLayoutEffect } from 'react'\n\nconst isServer = typeof window === 'undefined'\n || typeof document === 'undefined'\n\n// Fix: server → useEffect (no-op, avoids SSR warning);\n// client → useLayoutEffect (synchronous layout measurements).\nconst useIsomorphicLayoutEffect: typeof useEffect = isServer\n ? useEffect\n : useLayoutEffect\n\nexport { useIsomorphicLayoutEffect }\n"],"names":["isServer","window","document","useIsomorphicLayoutEffect","useEffect","useLayoutEffect"],"mappings":";AAMA,MAAMA,WAAW,AAAkB,MAAlB,OAAOC,UACnB,AAAoB,MAApB,OAAOC;AAIZ,MAAMC,4BAA8CH,WAChDI,YACAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-merged-refs.d.ts","sourceRoot":"","sources":["../../src/hooks/use-merged-refs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEhC,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AA2BxC,wBAAgB,aAAa,CAAC,CAAC,EAC7B,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GACxB,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAG1B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
function setRef(ref, value) {
|
|
3
|
+
if ('function' == typeof ref) ref(value);
|
|
4
|
+
else if (null != ref && 'object' == typeof ref && 'current' in ref) ref.current = value;
|
|
5
|
+
}
|
|
6
|
+
function mergeRefs(...refs) {
|
|
7
|
+
return (node)=>{
|
|
8
|
+
refs.forEach((ref)=>{
|
|
9
|
+
setRef(ref, node);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function useMergedRefs(...refs) {
|
|
14
|
+
return useMemo(()=>mergeRefs(...refs), refs);
|
|
15
|
+
}
|
|
16
|
+
export { useMergedRefs };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=use-merged-refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-merged-refs.js","sources":["../../src/hooks/use-merged-refs.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMemo } from 'react'\nimport type { Ref } from 'react'\n\ntype PossibleRef<T> = Ref<T> | undefined\ninterface WritableRefObject<T> {\n current: T | null\n}\n\nfunction setRef<T>(\n ref: PossibleRef<T>,\n value: T | null,\n): void {\n if (typeof ref === 'function') {\n ref(value)\n } else if (\n ref !== undefined && ref !== null && typeof ref === 'object'\n && 'current' in ref\n ) {\n ;(ref as WritableRefObject<T>).current = value\n }\n}\n\nfunction mergeRefs<T>(...refs: PossibleRef<T>[]) {\n return (node: T | null) => {\n refs.forEach(ref => {\n setRef(ref, node)\n })\n }\n}\n\nexport function useMergedRefs<T>(\n ...refs: PossibleRef<T>[]\n): (node: T | null) => void {\n // biome-ignore lint/correctness/useExhaustiveDependencies: refs is the dependency list for the merged ref callback.\n return useMemo(() => mergeRefs(...refs), refs)\n}\n"],"names":["setRef","ref","value","mergeRefs","refs","node","useMergedRefs","useMemo"],"mappings":";AAYA,SAASA,OACPC,GAAmB,EACnBC,KAAe;IAEf,IAAI,AAAe,cAAf,OAAOD,KACTA,IAAIC;SACC,IACLD,QAAAA,OAAqC,AAAe,YAAf,OAAOA,OACzC,aAAaA,KAEdA,IAA6B,OAAO,GAAGC;AAE7C;AAEA,SAASC,UAAa,GAAGC,IAAsB;IAC7C,OAAO,CAACC;QACND,KAAK,OAAO,CAACH,CAAAA;YACXD,OAAOC,KAAKI;QACd;IACF;AACF;AAEO,SAASC,cACd,GAAGF,IAAsB;IAGzB,OAAOG,QAAQ,IAAMJ,aAAaC,OAAOA;AAC3C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* useRafClock
|
|
4
|
+
*
|
|
5
|
+
* Provides a monotonically increasing frame counter (`frameIdRef`)
|
|
6
|
+
* and the last rAF timestamp (`tsRef`), updated once per animation frame.
|
|
7
|
+
*
|
|
8
|
+
* Useful for tagging logs or values to check if multiple updates
|
|
9
|
+
* occurred within the same rendered frame.
|
|
10
|
+
*
|
|
11
|
+
* @internal — not exported from the package's public API.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useRafClock(): {
|
|
14
|
+
frameIdRef: MutableRefObject<number>;
|
|
15
|
+
tsRef: MutableRefObject<number>;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=use-raf-clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-raf-clock.d.ts","sourceRoot":"","sources":["../../src/hooks/use-raf-clock.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE7C;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,IAAI;IAC7B,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACpC,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;CAChC,CAgBA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
function useRafClock() {
|
|
3
|
+
const frameIdRef = useRef(0);
|
|
4
|
+
const tsRef = useRef(0);
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
let raf = 0;
|
|
7
|
+
const tick = (ts)=>{
|
|
8
|
+
frameIdRef.current += 1;
|
|
9
|
+
tsRef.current = ts;
|
|
10
|
+
raf = requestAnimationFrame(tick);
|
|
11
|
+
};
|
|
12
|
+
raf = requestAnimationFrame(tick);
|
|
13
|
+
return ()=>cancelAnimationFrame(raf);
|
|
14
|
+
}, []);
|
|
15
|
+
return {
|
|
16
|
+
frameIdRef,
|
|
17
|
+
tsRef
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export { useRafClock };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=use-raf-clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/use-raf-clock.js","sources":["../../src/hooks/use-raf-clock.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useEffect, useRef } from 'react'\nimport type { MutableRefObject } from 'react'\n\n/**\n * useRafClock\n *\n * Provides a monotonically increasing frame counter (`frameIdRef`)\n * and the last rAF timestamp (`tsRef`), updated once per animation frame.\n *\n * Useful for tagging logs or values to check if multiple updates\n * occurred within the same rendered frame.\n *\n * @internal — not exported from the package's public API.\n */\nexport function useRafClock(): {\n frameIdRef: MutableRefObject<number>\n tsRef: MutableRefObject<number>\n} {\n const frameIdRef = useRef(0)\n const tsRef = useRef(0)\n\n useEffect(() => {\n let raf = 0\n const tick = (ts: number) => {\n frameIdRef.current += 1\n tsRef.current = ts\n raf = requestAnimationFrame(tick)\n }\n raf = requestAnimationFrame(tick)\n return () => cancelAnimationFrame(raf)\n }, [])\n\n return { frameIdRef, tsRef }\n}\n"],"names":["useRafClock","frameIdRef","useRef","tsRef","useEffect","raf","tick","ts","requestAnimationFrame","cancelAnimationFrame"],"mappings":";AAkBO,SAASA;IAId,MAAMC,aAAaC,OAAO;IAC1B,MAAMC,QAAQD,OAAO;IAErBE,UAAU;QACR,IAAIC,MAAM;QACV,MAAMC,OAAO,CAACC;YACZN,WAAW,OAAO,IAAI;YACtBE,MAAM,OAAO,GAAGI;YAChBF,MAAMG,sBAAsBF;QAC9B;QACAD,MAAMG,sBAAsBF;QAC5B,OAAO,IAAMG,qBAAqBJ;IACpC,GAAG,EAAE;IAEL,OAAO;QAAEJ;QAAYE;IAAM;AAC7B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { useContainerResize, useEventCallback, useIsomorphicLayoutEffect, useMergedRefs, useIsClient, } from './hooks';
|
|
2
|
+
export { Stage, StageContainer } from './components/stage';
|
|
3
|
+
export type { StageProps, StageBaseProps } from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,aAAa,EACb,WAAW,GACZ,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { LynxStage } from './lynx-stage';
|
|
2
|
+
export { LunaLynxStage } from './luna-lynx-stage';
|
|
3
|
+
export { useLynxStage } from './use-lynx-stage';
|
|
4
|
+
export type { LynxStageProps } from './lynx-stage';
|
|
5
|
+
export type { LunaLynxStageProps } from './luna-lynx-stage';
|
|
6
|
+
export type { ResolveBundleSrc, UseLynxStageOptions, UseLynxStageResult, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lynx/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,SAAS,CAAA"}
|