stablekit.ts 0.2.0

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.js ADDED
@@ -0,0 +1,816 @@
1
+ // src/components/layout-group.tsx
2
+ import {
3
+ forwardRef,
4
+ createContext,
5
+ useEffect,
6
+ useInsertionEffect,
7
+ useMemo,
8
+ useRef
9
+ } from "react";
10
+
11
+ // src/styles.css
12
+ var styles_default = `/* stablekit \u2014 layout stability toolkit for React
13
+ *
14
+ * CSS class prefix: sk-
15
+ * All animations use CSS custom properties for themability.
16
+ * Styles are auto-injected at import time (opt-out via meta tag).
17
+ */
18
+
19
+ /* \u2500\u2500 LayoutGroup / LayoutView \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
20
+
21
+ /* All children overlap in the same grid cell.
22
+ Grid auto-sizes to the largest child.
23
+ Block-level groups use flex-column so content stretches to fill
24
+ the reserved width. Inline groups (data-inline) skip this \u2014 their
25
+ children are inline content that shouldn't be forced vertical. */
26
+ .sk-layout-group {
27
+ display: grid;
28
+ }
29
+ .sk-layout-group[data-inline] {
30
+ display: inline-grid;
31
+ }
32
+ .sk-layout-group > * {
33
+ grid-area: 1 / 1;
34
+ }
35
+ .sk-layout-group:not([data-inline]) > * {
36
+ display: flex;
37
+ flex-direction: column;
38
+ }
39
+ /* Inline groups: children inherit the parent's inline flow.
40
+ Without this, grid items default to block and stack content. */
41
+ .sk-layout-group[data-inline] > * {
42
+ display: inline;
43
+ }
44
+
45
+ /* Inactive LayoutView hiding \u2014 CSS-driven via data-state attribute.
46
+ LayoutView sets data-state="active"|"inactive" so consumers can
47
+ override transitions on .sk-layout-view without specificity fights.
48
+ [inert] handles accessibility (non-focusable, non-interactive). */
49
+ .sk-layout-view[data-state="inactive"] {
50
+ opacity: 0;
51
+ visibility: hidden;
52
+ }
53
+
54
+ /* \u2500\u2500 SizeRatchet \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
55
+
56
+ /* contain isolates internal reflow from ancestors. */
57
+ .sk-size-ratchet {
58
+ contain: layout style;
59
+ }
60
+
61
+ /* \u2500\u2500 Shimmer / Skeleton \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
62
+
63
+ .sk-skeleton-grid {
64
+ display: grid;
65
+ gap: var(--sk-skeleton-gap, 0.75rem);
66
+ contain: layout style;
67
+ }
68
+
69
+ .sk-skeleton-bone {
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: var(--sk-skeleton-bone-gap, 0.125rem);
73
+ padding: var(--sk-skeleton-bone-padding, 0.375rem 0.5rem);
74
+ }
75
+
76
+ .sk-shimmer-line {
77
+ height: 1lh;
78
+ border-radius: var(--sk-shimmer-radius, 0.125rem);
79
+ background: linear-gradient(
80
+ 90deg,
81
+ var(--sk-shimmer-color, #e5e7eb) 25%,
82
+ var(--sk-shimmer-highlight, #f3f4f6) 50%,
83
+ var(--sk-shimmer-color, #e5e7eb) 75%
84
+ );
85
+ background-size: 200% 100%;
86
+ animation: sk-shimmer var(--sk-shimmer-duration, 1.5s) ease-in-out infinite;
87
+ }
88
+
89
+ /* Inert ghost inside a shimmer-line \u2014 sizes the shimmer to match
90
+ content width exactly. Invisible and non-interactive via [inert]. */
91
+ .sk-shimmer-line > [inert] {
92
+ visibility: hidden;
93
+ }
94
+
95
+ @keyframes sk-shimmer {
96
+ 0% { background-position: 200% 0; }
97
+ 100% { background-position: -200% 0; }
98
+ }
99
+
100
+ /* \u2500\u2500 MediaSkeleton \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
101
+
102
+ /* Loading-aware media container.
103
+ Reserves space via aspect-ratio (set inline by the component).
104
+ Child constraints enforced via React.cloneElement inline styles. */
105
+ .sk-media {
106
+ overflow: hidden;
107
+ }
108
+ .sk-media-shimmer {
109
+ position: absolute;
110
+ inset: 0;
111
+ border-radius: var(--sk-shimmer-radius, 0.125rem);
112
+ background: linear-gradient(
113
+ 90deg,
114
+ var(--sk-shimmer-color, #e5e7eb) 25%,
115
+ var(--sk-shimmer-highlight, #f3f4f6) 50%,
116
+ var(--sk-shimmer-color, #e5e7eb) 75%
117
+ );
118
+ background-size: 200% 100%;
119
+ animation: sk-shimmer var(--sk-shimmer-duration, 1.5s) ease-in-out infinite;
120
+ transition: opacity var(--sk-loading-exit-duration, 400ms) var(--sk-ease-decelerate);
121
+ }
122
+
123
+ /* \u2500\u2500 Shared easing \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
124
+
125
+ /* Decelerate: fast start, gentle finish \u2014 for elements entering view. */
126
+ /* Standard: balanced ease \u2014 for general-purpose transitions. */
127
+ /* Accelerate: gentle start, fast finish \u2014 for elements leaving view. */
128
+ :root {
129
+ --sk-ease-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1.0);
130
+ --sk-ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
131
+ --sk-ease-accelerate: cubic-bezier(0.4, 0, 1, 1);
132
+ }
133
+
134
+ /* \u2500\u2500 FadeTransition \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
135
+
136
+ .sk-fade {
137
+ --sk-fade-duration: 400ms;
138
+ }
139
+
140
+ .sk-fade-entering {
141
+ animation: sk-emerge var(--sk-fade-duration) var(--sk-ease-decelerate) forwards;
142
+ }
143
+
144
+ .sk-fade-exiting {
145
+ animation: sk-collapse var(--sk-fade-duration) var(--sk-ease-accelerate) forwards;
146
+ }
147
+
148
+ @keyframes sk-emerge {
149
+ from {
150
+ opacity: 0;
151
+ transform: translateY(var(--sk-fade-offset-y, -12px)) scale(var(--sk-fade-offset-scale, 0.98));
152
+ }
153
+ to {
154
+ opacity: 1;
155
+ transform: translateY(0) scale(1);
156
+ }
157
+ }
158
+
159
+ @keyframes sk-collapse {
160
+ from { opacity: 1; transform: scaleY(1); transform-origin: top; }
161
+ to { opacity: 0; transform: scaleY(0); transform-origin: top; }
162
+ }
163
+
164
+ /* \u2500\u2500 Loading layers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
165
+
166
+ /* Shared by shimmer and content layers inside skeleton components.
167
+ Both layers permanently occupy the same grid cell; only opacity
168
+ and interactivity change. CSS transitions handle the crossfade. */
169
+ .sk-loading-layer {
170
+ grid-area: 1 / 1;
171
+ transition: opacity var(--sk-loading-exit-duration, 400ms) var(--sk-ease-decelerate);
172
+ }
173
+
174
+ /* \u2500\u2500 Reduced motion \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
175
+
176
+ /* Disables all animations \u2014 shimmer, fade, and loading exit.
177
+ Layout changes still happen instantly so functionality is preserved. */
178
+ @media (prefers-reduced-motion: reduce) {
179
+ .sk-fade-entering,
180
+ .sk-fade-exiting,
181
+ .sk-shimmer-line,
182
+ .sk-media-shimmer {
183
+ animation-duration: 0s !important;
184
+ }
185
+ .sk-loading-layer,
186
+ .sk-media-shimmer {
187
+ transition-duration: 0s !important;
188
+ }
189
+ }
190
+ `;
191
+
192
+ // src/internal/inject-styles.ts
193
+ var injected = false;
194
+ function injectStyles() {
195
+ if (injected || typeof document === "undefined") return;
196
+ if (document.querySelector('meta[name="stablekit-disable-injection"]')) {
197
+ injected = true;
198
+ return;
199
+ }
200
+ if (document.querySelector("style[data-stablekit]")) {
201
+ injected = true;
202
+ return;
203
+ }
204
+ const style = document.createElement("style");
205
+ style.setAttribute("data-stablekit", "");
206
+ const nonceMeta = document.querySelector('meta[name="stablekit-nonce"]');
207
+ if (nonceMeta) {
208
+ const nonce = nonceMeta.getAttribute("content");
209
+ if (nonce) style.setAttribute("nonce", nonce);
210
+ }
211
+ style.textContent = styles_default;
212
+ document.head.appendChild(style);
213
+ injected = true;
214
+ }
215
+ injectStyles();
216
+
217
+ // src/internal/merge-refs.ts
218
+ function mergeRefs(...refs) {
219
+ return (value) => {
220
+ for (const ref of refs) {
221
+ if (typeof ref === "function") {
222
+ ref(value);
223
+ } else if (ref != null) {
224
+ ref.current = value;
225
+ }
226
+ }
227
+ };
228
+ }
229
+
230
+ // src/internal/invariant.ts
231
+ function invariant(condition, message) {
232
+ if (condition) return;
233
+ if (process.env.NODE_ENV !== "production") {
234
+ throw new Error(`StableKit: ${message}`);
235
+ }
236
+ }
237
+ function warning(condition, message) {
238
+ if (condition) return;
239
+ if (process.env.NODE_ENV !== "production") {
240
+ console.warn(`StableKit Warning: ${message}`);
241
+ }
242
+ }
243
+
244
+ // src/components/layout-group.tsx
245
+ import { jsx } from "react/jsx-runtime";
246
+ var AxisContext = createContext("both");
247
+ var NO_PROVIDER = /* @__PURE__ */ Symbol("sk-no-layout-group");
248
+ var ActiveValueContext = createContext(NO_PROVIDER);
249
+ var FocusHandoffContext = createContext(null);
250
+ var LayoutGroup = forwardRef(
251
+ function LayoutGroup2({ axis = "both", value, as: Tag = "div", className, style, children, ...props }, ref) {
252
+ useInsertionEffect(injectStyles, []);
253
+ warning(
254
+ value !== void 0,
255
+ "<LayoutGroup> rendered without a 'value' prop. All named <LayoutView> children will default to active, which may cause overlapping layouts."
256
+ );
257
+ const internalRef = useRef(null);
258
+ const hadFocusRef = useRef(false);
259
+ useEffect(() => {
260
+ const el = internalRef.current;
261
+ if (!el) return;
262
+ const onFocusIn = () => {
263
+ hadFocusRef.current = true;
264
+ };
265
+ const onFocusOut = (e) => {
266
+ const target = e.relatedTarget;
267
+ if (target && !el.contains(target)) {
268
+ hadFocusRef.current = false;
269
+ }
270
+ };
271
+ el.addEventListener("focusin", onFocusIn);
272
+ el.addEventListener("focusout", onFocusOut);
273
+ return () => {
274
+ el.removeEventListener("focusin", onFocusIn);
275
+ el.removeEventListener("focusout", onFocusOut);
276
+ };
277
+ }, []);
278
+ const focusCtx = useMemo(() => ({ hadFocusRef }), []);
279
+ const merged = className ? `sk-layout-group ${className}` : "sk-layout-group";
280
+ return /* @__PURE__ */ jsx(AxisContext.Provider, { value: axis, children: /* @__PURE__ */ jsx(ActiveValueContext.Provider, { value, children: /* @__PURE__ */ jsx(FocusHandoffContext.Provider, { value: focusCtx, children: /* @__PURE__ */ jsx(Tag, { ref: mergeRefs(ref, internalRef), className: merged, style, ...props, children }) }) }) });
281
+ }
282
+ );
283
+
284
+ // src/components/layout-view.tsx
285
+ import {
286
+ forwardRef as forwardRef2,
287
+ useContext,
288
+ useInsertionEffect as useInsertionEffect2,
289
+ useLayoutEffect,
290
+ useRef as useRef2
291
+ } from "react";
292
+ import { jsx as jsx2 } from "react/jsx-runtime";
293
+ var LayoutView = forwardRef2(
294
+ function LayoutView2({ active, name, as: Tag = "div", style, className, children, ...props }, ref) {
295
+ useInsertionEffect2(injectStyles, []);
296
+ useContext(AxisContext);
297
+ const rawActiveValue = useContext(ActiveValueContext);
298
+ const focusCtx = useContext(FocusHandoffContext);
299
+ invariant(
300
+ !(name != null && typeof rawActiveValue === "symbol"),
301
+ "<LayoutView> with a 'name' prop must be rendered inside a <LayoutGroup> or <LayoutMap>."
302
+ );
303
+ const activeValue = typeof rawActiveValue === "symbol" ? void 0 : rawActiveValue;
304
+ const isActive = active ?? (name != null ? name === activeValue : true);
305
+ const internalRef = useRef2(null);
306
+ const prevActiveRef = useRef2(isActive);
307
+ useLayoutEffect(() => {
308
+ const wasActive = prevActiveRef.current;
309
+ prevActiveRef.current = isActive;
310
+ if (!isActive || wasActive) return;
311
+ if (!focusCtx?.hadFocusRef.current) return;
312
+ const current = document.activeElement;
313
+ if (current && current !== document.body && !current.closest?.("[inert]")) return;
314
+ internalRef.current?.focus({ preventScroll: true });
315
+ });
316
+ const viewClass = className ? `sk-layout-view ${className}` : "sk-layout-view";
317
+ return /* @__PURE__ */ jsx2(
318
+ Tag,
319
+ {
320
+ ref: mergeRefs(ref, internalRef),
321
+ className: viewClass,
322
+ "data-state": isActive ? "active" : "inactive",
323
+ tabIndex: isActive ? -1 : void 0,
324
+ inert: !isActive || void 0,
325
+ style,
326
+ ...props,
327
+ children
328
+ }
329
+ );
330
+ }
331
+ );
332
+
333
+ // src/components/state-swap.tsx
334
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
335
+ function StateSwap({
336
+ state,
337
+ true: onTrue,
338
+ false: onFalse,
339
+ as: Tag = "span",
340
+ ...props
341
+ }) {
342
+ return /* @__PURE__ */ jsxs(LayoutGroup, { as: Tag, value: state ? "true" : "false", axis: "both", "data-inline": true, ...props, children: [
343
+ /* @__PURE__ */ jsx3(LayoutView, { as: "span", name: "true", children: onTrue }),
344
+ /* @__PURE__ */ jsx3(LayoutView, { as: "span", name: "false", children: onFalse })
345
+ ] });
346
+ }
347
+
348
+ // src/components/layout-map.tsx
349
+ import { jsx as jsx4 } from "react/jsx-runtime";
350
+ function LayoutMap({ value, map, ...props }) {
351
+ return /* @__PURE__ */ jsx4(LayoutGroup, { value, ...props, children: Object.entries(map).map(([key, node]) => /* @__PURE__ */ jsx4(LayoutView, { name: key, children: node }, key)) });
352
+ }
353
+
354
+ // src/components/size-ratchet.tsx
355
+ import { forwardRef as forwardRef3, useInsertionEffect as useInsertionEffect3 } from "react";
356
+
357
+ // src/primitives/use-stable-slot.ts
358
+ import { useState, useCallback, useEffect as useEffect2, useRef as useRef3 } from "react";
359
+ var RATCHET_FLOOR = -Infinity;
360
+ function useStableSlot(options = {}) {
361
+ const { axis = "both", resetKey } = options;
362
+ const [style, setStyle] = useState({});
363
+ const maxRef = useRef3({ w: RATCHET_FLOOR, h: RATCHET_FLOOR });
364
+ const observerRef = useRef3(null);
365
+ const prevResetKeyRef = useRef3(resetKey);
366
+ useEffect2(() => {
367
+ if (prevResetKeyRef.current !== resetKey) {
368
+ prevResetKeyRef.current = resetKey;
369
+ maxRef.current = { w: RATCHET_FLOOR, h: RATCHET_FLOOR };
370
+ setStyle({});
371
+ }
372
+ }, [resetKey]);
373
+ const ref = useCallback(
374
+ (el) => {
375
+ if (observerRef.current) {
376
+ observerRef.current.disconnect();
377
+ observerRef.current = null;
378
+ }
379
+ if (!el || typeof ResizeObserver === "undefined") return;
380
+ const observer = new ResizeObserver((entries) => {
381
+ for (const entry of entries) {
382
+ let w;
383
+ let h;
384
+ if (entry.borderBoxSize?.length) {
385
+ const box = entry.borderBoxSize[0];
386
+ w = box.inlineSize;
387
+ h = box.blockSize;
388
+ } else {
389
+ const rect = entry.target.getBoundingClientRect();
390
+ w = rect.width;
391
+ h = rect.height;
392
+ }
393
+ const max = maxRef.current;
394
+ let grew = false;
395
+ if ((axis === "width" || axis === "both") && w > max.w) {
396
+ max.w = w;
397
+ grew = true;
398
+ }
399
+ if ((axis === "height" || axis === "both") && h > max.h) {
400
+ max.h = h;
401
+ grew = true;
402
+ }
403
+ if (grew) {
404
+ const next = {};
405
+ if (axis === "width" || axis === "both") next.minWidth = max.w;
406
+ if (axis === "height" || axis === "both") next.minHeight = max.h;
407
+ setStyle(next);
408
+ }
409
+ }
410
+ });
411
+ observer.observe(el, { box: "border-box" });
412
+ observerRef.current = observer;
413
+ },
414
+ [axis]
415
+ );
416
+ return { ref, style };
417
+ }
418
+
419
+ // src/components/size-ratchet.tsx
420
+ import { jsx as jsx5 } from "react/jsx-runtime";
421
+ var SizeRatchet = forwardRef3(
422
+ function SizeRatchet2({ axis = "height", resetKey, as: Tag = "div", className, style, children, ...props }, fwdRef) {
423
+ useInsertionEffect3(injectStyles, []);
424
+ const { ref: ratchetRef, style: ratchetStyle } = useStableSlot({ axis, resetKey });
425
+ const merged = className ? `sk-size-ratchet ${className}` : "sk-size-ratchet";
426
+ return /* @__PURE__ */ jsx5(
427
+ Tag,
428
+ {
429
+ ref: mergeRefs(ratchetRef, fwdRef),
430
+ className: merged,
431
+ style: { ...ratchetStyle, ...style },
432
+ ...props,
433
+ children
434
+ }
435
+ );
436
+ }
437
+ );
438
+
439
+ // src/components/stable-counter.tsx
440
+ import { forwardRef as forwardRef4 } from "react";
441
+ import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
442
+ var GHOST_STYLE = {
443
+ visibility: "hidden",
444
+ gridArea: "1 / 1",
445
+ pointerEvents: "none"
446
+ };
447
+ var VALUE_STYLE = {
448
+ gridArea: "1 / 1"
449
+ };
450
+ var StableCounter = forwardRef4(
451
+ function StableCounter2({ value, reserve, as: Tag = "span", style, className, ...props }, ref) {
452
+ return /* @__PURE__ */ jsxs2(
453
+ Tag,
454
+ {
455
+ ref,
456
+ className,
457
+ style: { ...style, display: "inline-grid" },
458
+ ...props,
459
+ children: [
460
+ /* @__PURE__ */ jsx6("span", { "aria-hidden": "true", style: GHOST_STYLE, children: reserve }),
461
+ /* @__PURE__ */ jsx6("span", { style: VALUE_STYLE, children: value })
462
+ ]
463
+ }
464
+ );
465
+ }
466
+ );
467
+
468
+ // src/components/stable-field.tsx
469
+ import { forwardRef as forwardRef5 } from "react";
470
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
471
+ var GHOST_STYLE2 = {
472
+ visibility: "hidden",
473
+ gridArea: "1 / 1",
474
+ pointerEvents: "none"
475
+ };
476
+ var ERROR_STYLE = {
477
+ gridArea: "1 / 1"
478
+ };
479
+ var ERROR_HIDDEN_STYLE = {
480
+ gridArea: "1 / 1",
481
+ visibility: "hidden"
482
+ };
483
+ var StableField = forwardRef5(
484
+ function StableField2({ error, reserve, children, style, className, ...props }, ref) {
485
+ const hasError = error != null && error !== false && error !== "";
486
+ return /* @__PURE__ */ jsxs3("div", { ref, className, style, ...props, children: [
487
+ children,
488
+ /* @__PURE__ */ jsxs3("div", { style: { display: "grid" }, children: [
489
+ /* @__PURE__ */ jsx7("span", { "aria-hidden": "true", style: GHOST_STYLE2, children: reserve }),
490
+ /* @__PURE__ */ jsx7(
491
+ "span",
492
+ {
493
+ role: hasError ? "alert" : void 0,
494
+ style: hasError ? ERROR_STYLE : ERROR_HIDDEN_STYLE,
495
+ children: hasError ? error : null
496
+ }
497
+ )
498
+ ] })
499
+ ] });
500
+ }
501
+ );
502
+
503
+ // src/components/loading-boundary.tsx
504
+ import {
505
+ forwardRef as forwardRef6,
506
+ useInsertionEffect as useInsertionEffect4
507
+ } from "react";
508
+
509
+ // src/components/loading-context.tsx
510
+ import { createContext as createContext2, useContext as useContext2 } from "react";
511
+ import { jsx as jsx8 } from "react/jsx-runtime";
512
+ var LoadingStateContext = createContext2(false);
513
+ function useLoadingState() {
514
+ return useContext2(LoadingStateContext);
515
+ }
516
+ function LoadingContext({ loading, children }) {
517
+ return /* @__PURE__ */ jsx8(LoadingStateContext.Provider, { value: loading, children });
518
+ }
519
+
520
+ // src/components/loading-boundary.tsx
521
+ import { jsx as jsx9 } from "react/jsx-runtime";
522
+ var LoadingBoundary = forwardRef6(
523
+ function LoadingBoundary2({ loading, exitDuration, as: Tag = "div", className, style, children, ...props }, ref) {
524
+ useInsertionEffect4(injectStyles, []);
525
+ const merged = {
526
+ ...style,
527
+ "--sk-loading-exit-duration": `${exitDuration}ms`
528
+ };
529
+ return /* @__PURE__ */ jsx9(SizeRatchet, { ref, axis: "height", as: Tag, className, style: merged, ...props, children: /* @__PURE__ */ jsx9(LoadingContext, { loading, children }) });
530
+ }
531
+ );
532
+
533
+ // src/components/text-skeleton.tsx
534
+ import { useInsertionEffect as useInsertionEffect5 } from "react";
535
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
536
+ function TextSkeleton({ loading, as: Tag = "span", className, style, children, ...props }) {
537
+ useInsertionEffect5(injectStyles, []);
538
+ const contextLoading = useLoadingState();
539
+ const isLoading = loading ?? contextLoading;
540
+ return /* @__PURE__ */ jsxs4(Tag, { className, style: { ...style, display: "inline-grid" }, ...props, children: [
541
+ /* @__PURE__ */ jsx10(
542
+ "span",
543
+ {
544
+ className: "sk-shimmer-line sk-loading-layer",
545
+ "aria-hidden": "true",
546
+ style: { opacity: isLoading ? 1 : 0 },
547
+ children: /* @__PURE__ */ jsx10("span", { inert: true, children })
548
+ }
549
+ ),
550
+ /* @__PURE__ */ jsx10(
551
+ "span",
552
+ {
553
+ className: "sk-loading-layer",
554
+ style: { opacity: isLoading ? 0 : 1 },
555
+ inert: isLoading || void 0,
556
+ children
557
+ }
558
+ )
559
+ ] });
560
+ }
561
+
562
+ // src/components/stable-text.tsx
563
+ import { jsx as jsx11 } from "react/jsx-runtime";
564
+ function StableText({
565
+ as: Tag = "p",
566
+ loading,
567
+ children,
568
+ ...props
569
+ }) {
570
+ return /* @__PURE__ */ jsx11(Tag, { ...props, children: /* @__PURE__ */ jsx11(TextSkeleton, { loading, children }) });
571
+ }
572
+
573
+ // src/components/media-skeleton.tsx
574
+ import {
575
+ Children,
576
+ cloneElement,
577
+ isValidElement,
578
+ useCallback as useCallback2,
579
+ useEffect as useEffect3,
580
+ useInsertionEffect as useInsertionEffect6,
581
+ useRef as useRef4,
582
+ useState as useState2
583
+ } from "react";
584
+ import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
585
+ var CHILD_STYLE = {
586
+ position: "absolute",
587
+ inset: 0,
588
+ width: "100%",
589
+ height: "100%",
590
+ objectFit: "cover"
591
+ };
592
+ function MediaSkeleton({
593
+ aspectRatio,
594
+ loading,
595
+ className,
596
+ style,
597
+ children,
598
+ ...props
599
+ }) {
600
+ useInsertionEffect6(injectStyles, []);
601
+ const contextLoading = useLoadingState();
602
+ const isLoading = loading ?? contextLoading;
603
+ const [mediaReady, setMediaReady] = useState2(false);
604
+ const childRef = useRef4(null);
605
+ useEffect3(() => {
606
+ if (isLoading) setMediaReady(false);
607
+ }, [isLoading]);
608
+ useEffect3(() => {
609
+ const el = childRef.current;
610
+ if (el instanceof HTMLImageElement && el.complete && el.naturalWidth > 0) {
611
+ setMediaReady(true);
612
+ }
613
+ });
614
+ const handleLoad = useCallback2(() => setMediaReady(true), []);
615
+ const showShimmer = isLoading || !mediaReady;
616
+ const containerStyle = {
617
+ position: "relative",
618
+ overflow: "hidden",
619
+ aspectRatio,
620
+ ...style
621
+ };
622
+ const containerClass = showShimmer ? className ? `sk-media sk-media-loading ${className}` : "sk-media sk-media-loading" : className ? `sk-media ${className}` : "sk-media";
623
+ const child = Children.only(children);
624
+ const existingOnLoad = child.props.onLoad;
625
+ const clonedChild = isValidElement(child) ? cloneElement(child, {
626
+ ref: childRef,
627
+ onLoad: (e) => {
628
+ handleLoad();
629
+ existingOnLoad?.(e);
630
+ },
631
+ style: {
632
+ ...CHILD_STYLE,
633
+ opacity: showShimmer ? 0 : 1,
634
+ transition: "opacity var(--sk-loading-exit-duration, 400ms) var(--sk-ease-decelerate)",
635
+ ...child.props.style
636
+ }
637
+ }) : child;
638
+ return /* @__PURE__ */ jsxs5("div", { className: containerClass, style: containerStyle, ...props, children: [
639
+ /* @__PURE__ */ jsx12(
640
+ "div",
641
+ {
642
+ className: "sk-media-shimmer",
643
+ "aria-hidden": "true",
644
+ style: { opacity: showShimmer ? 1 : 0 }
645
+ }
646
+ ),
647
+ clonedChild
648
+ ] });
649
+ }
650
+
651
+ // src/components/collection-skeleton.tsx
652
+ import {
653
+ forwardRef as forwardRef8,
654
+ useInsertionEffect as useInsertionEffect8
655
+ } from "react";
656
+
657
+ // src/components/skeleton-grid.tsx
658
+ import { forwardRef as forwardRef7, useInsertionEffect as useInsertionEffect7 } from "react";
659
+ import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
660
+ var SkeletonGrid = forwardRef7(
661
+ function SkeletonGrid2({ rows, columns, as: Tag = "div", className, children, ...props }, ref) {
662
+ useInsertionEffect7(injectStyles, []);
663
+ const merged = className ? `sk-skeleton-grid ${className}` : "sk-skeleton-grid";
664
+ const count = columns ? rows * columns : rows;
665
+ const cells = Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsxs6("div", { className: "sk-skeleton-bone", children: [
666
+ /* @__PURE__ */ jsx13("div", { className: "sk-shimmer-line" }),
667
+ /* @__PURE__ */ jsx13("div", { className: "sk-shimmer-line" })
668
+ ] }, i));
669
+ const gridStyle = columns ? { gridTemplateColumns: `repeat(${columns}, auto)` } : void 0;
670
+ return /* @__PURE__ */ jsx13(
671
+ Tag,
672
+ {
673
+ ref,
674
+ className: merged,
675
+ style: gridStyle,
676
+ ...props,
677
+ children: cells
678
+ }
679
+ );
680
+ }
681
+ );
682
+
683
+ // src/components/collection-skeleton.tsx
684
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
685
+ function CollectionSkeletonInner({
686
+ items,
687
+ loading,
688
+ renderItem,
689
+ stubCount,
690
+ exitDuration,
691
+ as: Tag = "div",
692
+ className,
693
+ style,
694
+ ...props
695
+ }, ref) {
696
+ useInsertionEffect8(injectStyles, []);
697
+ const merged = {
698
+ ...style,
699
+ display: "grid",
700
+ "--sk-loading-exit-duration": `${exitDuration}ms`
701
+ };
702
+ return /* @__PURE__ */ jsxs7(SizeRatchet, { ref, axis: "height", as: Tag, className, style: merged, ...props, children: [
703
+ /* @__PURE__ */ jsx14(
704
+ "div",
705
+ {
706
+ className: "sk-loading-layer",
707
+ "aria-hidden": "true",
708
+ style: { opacity: loading ? 1 : 0 },
709
+ children: /* @__PURE__ */ jsx14(SkeletonGrid, { rows: stubCount })
710
+ }
711
+ ),
712
+ /* @__PURE__ */ jsx14(
713
+ "div",
714
+ {
715
+ className: "sk-loading-layer",
716
+ style: { opacity: loading ? 0 : 1 },
717
+ inert: loading || void 0,
718
+ children: items.map(renderItem)
719
+ }
720
+ )
721
+ ] });
722
+ }
723
+ var CollectionSkeleton = forwardRef8(CollectionSkeletonInner);
724
+
725
+ // src/components/fade-transition.tsx
726
+ import {
727
+ forwardRef as forwardRef9,
728
+ useInsertionEffect as useInsertionEffect9
729
+ } from "react";
730
+
731
+ // src/primitives/use-presence.ts
732
+ import {
733
+ useState as useState3,
734
+ useEffect as useEffect4,
735
+ useCallback as useCallback3
736
+ } from "react";
737
+ function usePresence(show) {
738
+ const [mounted, setMounted] = useState3(show);
739
+ const [phase, setPhase] = useState3(show ? "entered" : "exiting");
740
+ useEffect4(() => {
741
+ if (show) {
742
+ setMounted(true);
743
+ setPhase("entering");
744
+ } else if (mounted) {
745
+ setPhase("exiting");
746
+ }
747
+ }, [show]);
748
+ const onAnimationEnd = useCallback3(
749
+ (e) => {
750
+ if (e.target !== e.currentTarget) return;
751
+ if (phase === "entering") setPhase("entered");
752
+ if (phase === "exiting") setMounted(false);
753
+ },
754
+ [phase]
755
+ );
756
+ return { mounted, phase, onAnimationEnd };
757
+ }
758
+
759
+ // src/components/fade-transition.tsx
760
+ import { jsx as jsx15 } from "react/jsx-runtime";
761
+ var FadeTransition = forwardRef9(
762
+ function FadeTransition2({ show, as: Tag = "div", className, style, children, ...props }, fwdRef) {
763
+ useInsertionEffect9(injectStyles, []);
764
+ const { mounted, phase, onAnimationEnd } = usePresence(show);
765
+ if (!mounted) return null;
766
+ const phaseClass = phase === "entering" ? "sk-fade-entering" : phase === "exiting" ? "sk-fade-exiting" : "";
767
+ const merged = ["sk-fade", phaseClass, className].filter(Boolean).join(" ");
768
+ return /* @__PURE__ */ jsx15(
769
+ Tag,
770
+ {
771
+ ref: fwdRef,
772
+ className: merged,
773
+ style,
774
+ onAnimationEnd,
775
+ ...props,
776
+ children
777
+ }
778
+ );
779
+ }
780
+ );
781
+
782
+ // src/create-primitive.tsx
783
+ import { createElement } from "react";
784
+ function createPrimitive(tag, baseClass, variants) {
785
+ const variantKeys = new Set(variants ? Object.keys(variants) : []);
786
+ function Primitive(props) {
787
+ const htmlProps = { className: baseClass };
788
+ for (const [key, value] of Object.entries(props)) {
789
+ if (variantKeys.has(key)) {
790
+ htmlProps[`data-${key}`] = value;
791
+ } else {
792
+ htmlProps[key] = value;
793
+ }
794
+ }
795
+ return createElement(tag, htmlProps);
796
+ }
797
+ return Primitive;
798
+ }
799
+ export {
800
+ CollectionSkeleton,
801
+ FadeTransition,
802
+ LayoutGroup,
803
+ LayoutMap,
804
+ LayoutView,
805
+ LoadingBoundary,
806
+ LoadingContext,
807
+ MediaSkeleton,
808
+ SizeRatchet,
809
+ StableCounter,
810
+ StableField,
811
+ StableText,
812
+ StateSwap,
813
+ TextSkeleton,
814
+ createPrimitive,
815
+ useLoadingState
816
+ };