@tahoangphuc111/liquid-glass 0.3.0 → 0.4.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/chunk-GMQXHUV5.js +744 -0
- package/dist/chunk-GMQXHUV5.js.map +1 -0
- package/dist/chunk-NWYZW4VI.cjs +14199 -0
- package/dist/chunk-NWYZW4VI.cjs.map +1 -0
- package/dist/chunk-UAXX5I2K.js +14119 -0
- package/dist/chunk-UAXX5I2K.js.map +1 -0
- package/dist/chunk-UYZIMLYS.cjs +752 -0
- package/dist/chunk-UYZIMLYS.cjs.map +1 -0
- package/dist/index.cjs +400 -517
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -16
- package/dist/index.d.ts +182 -16
- package/dist/index.js +218 -471
- package/dist/index.js.map +1 -1
- package/dist/next/index.cjs +146 -27
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +3 -3
- package/dist/next/index.d.ts +3 -3
- package/dist/next/index.js +133 -22
- package/dist/next/index.js.map +1 -1
- package/dist/react/index.cjs +50 -8
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +23 -4
- package/dist/react/index.d.ts +23 -4
- package/dist/react/index.js +37 -3
- package/dist/react/index.js.map +1 -1
- package/dist/styles.css +336 -67
- package/dist/types-ByMuri6x.d.cts +146 -0
- package/dist/types-ByMuri6x.d.ts +146 -0
- package/dist/vue/index.cjs +529 -27
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +625 -10
- package/dist/vue/index.d.ts +625 -10
- package/dist/vue/index.js +524 -24
- package/dist/vue/index.js.map +1 -1
- package/package.json +33 -13
- package/dist/chunk-FB6QOH33.js +0 -7532
- package/dist/chunk-FB6QOH33.js.map +0 -1
- package/dist/chunk-KKMJIY4M.cjs +0 -360
- package/dist/chunk-KKMJIY4M.cjs.map +0 -1
- package/dist/chunk-RMWCG5MB.js +0 -354
- package/dist/chunk-RMWCG5MB.js.map +0 -1
- package/dist/chunk-ZECDS4SL.cjs +0 -7578
- package/dist/chunk-ZECDS4SL.cjs.map +0 -1
- package/dist/types-BqXPylfU.d.cts +0 -90
- package/dist/types-BqXPylfU.d.ts +0 -90
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
import { mergeGlassOptions, createLiquidGlass, computeMergedOptionPatch, serializeLightTiltKey, createGlassSlider, canUseWebglRefraction, canUseSvgGlass, acquireSharedSceneCapture, getMediaQueries, isWasmReady, onWasmReady, subscribeBatteryChanges, createGlassSwitch } from './chunk-UAXX5I2K.js';
|
|
2
|
+
import { createContext, forwardRef, useRef, useImperativeHandle, useEffect, useState, useCallback, useContext, useLayoutEffect, useMemo } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
var LiquidGlassContext = createContext(null);
|
|
6
|
+
var EMPTY_DEFAULTS = {};
|
|
7
|
+
function shallowDefaultsEqual(prev, next) {
|
|
8
|
+
if (prev === next) return true;
|
|
9
|
+
const prevKeys = Object.keys(prev);
|
|
10
|
+
const nextKeys = Object.keys(next);
|
|
11
|
+
if (prevKeys.length !== nextKeys.length) return false;
|
|
12
|
+
for (const key of prevKeys) {
|
|
13
|
+
const aVal = prev[key];
|
|
14
|
+
const bVal = next[key];
|
|
15
|
+
if (Object.is(aVal, bVal)) continue;
|
|
16
|
+
if (key === "lightTilt" && aVal && bVal && typeof aVal === "object" && typeof bVal === "object") {
|
|
17
|
+
const tiltA = aVal;
|
|
18
|
+
const tiltB = bVal;
|
|
19
|
+
if (Object.is(tiltA.horizontal, tiltB.horizontal) && Object.is(tiltA.vertical, tiltB.vertical)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
function LiquidGlassProvider({
|
|
28
|
+
children,
|
|
29
|
+
sceneRef,
|
|
30
|
+
captureScene = "auto",
|
|
31
|
+
defaults = EMPTY_DEFAULTS,
|
|
32
|
+
className
|
|
33
|
+
}) {
|
|
34
|
+
const wrapperRef = useRef(null);
|
|
35
|
+
const controllerRef = useRef(null);
|
|
36
|
+
const stabilizedDefaultsRef = useRef(defaults);
|
|
37
|
+
if (!shallowDefaultsEqual(stabilizedDefaultsRef.current, defaults)) {
|
|
38
|
+
stabilizedDefaultsRef.current = defaults;
|
|
39
|
+
}
|
|
40
|
+
const stableDefaults = stabilizedDefaultsRef.current;
|
|
41
|
+
const defaultsRef = useRef(stableDefaults);
|
|
42
|
+
defaultsRef.current = stableDefaults;
|
|
43
|
+
const [sceneCanvas, setSceneCanvas] = useState(null);
|
|
44
|
+
const [sceneElement, setSceneElement] = useState(null);
|
|
45
|
+
const [forcedCapture, setForcedCapture] = useState(false);
|
|
46
|
+
const shouldCaptureNow = useCallback(() => {
|
|
47
|
+
if (captureScene === "never") return false;
|
|
48
|
+
if (captureScene === "always") return true;
|
|
49
|
+
return canUseWebglRefraction() && (forcedCapture || !canUseSvgGlass());
|
|
50
|
+
}, [captureScene, forcedCapture]);
|
|
51
|
+
const syncCapture = useCallback(() => {
|
|
52
|
+
const target = sceneRef?.current ?? wrapperRef.current;
|
|
53
|
+
if (!target || !shouldCaptureNow()) {
|
|
54
|
+
controllerRef.current?.destroy();
|
|
55
|
+
controllerRef.current = null;
|
|
56
|
+
setSceneCanvas(null);
|
|
57
|
+
setSceneElement(target ?? null);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (controllerRef.current && controllerRef.current.source === target) {
|
|
61
|
+
setSceneElement(target);
|
|
62
|
+
controllerRef.current.scheduleCapture();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
controllerRef.current?.destroy();
|
|
66
|
+
setSceneCanvas(null);
|
|
67
|
+
const controller = acquireSharedSceneCapture(target, () => ({
|
|
68
|
+
pixelRatio: defaultsRef.current.pixelRatio,
|
|
69
|
+
radius: defaultsRef.current.pill ? 9999 : defaultsRef.current.radius
|
|
70
|
+
}));
|
|
71
|
+
controllerRef.current = controller;
|
|
72
|
+
setSceneElement(target);
|
|
73
|
+
controller.subscribe((canvas, sourceEl) => {
|
|
74
|
+
setSceneCanvas(canvas);
|
|
75
|
+
setSceneElement(sourceEl);
|
|
76
|
+
});
|
|
77
|
+
}, [sceneRef, shouldCaptureNow]);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
syncCapture();
|
|
80
|
+
const {
|
|
81
|
+
reducedMotionQuery,
|
|
82
|
+
mobileOrTouchQuery,
|
|
83
|
+
reducedTransparencyQuery,
|
|
84
|
+
highContrastQuery
|
|
85
|
+
} = getMediaQueries();
|
|
86
|
+
reducedMotionQuery?.addEventListener?.("change", syncCapture);
|
|
87
|
+
mobileOrTouchQuery?.addEventListener?.("change", syncCapture);
|
|
88
|
+
reducedTransparencyQuery?.addEventListener?.("change", syncCapture);
|
|
89
|
+
highContrastQuery?.addEventListener?.("change", syncCapture);
|
|
90
|
+
const unsubWasm = isWasmReady() ? null : onWasmReady(syncCapture);
|
|
91
|
+
const unsubscribeBattery = captureScene === "auto" ? subscribeBatteryChanges(syncCapture) : null;
|
|
92
|
+
return () => {
|
|
93
|
+
unsubWasm?.();
|
|
94
|
+
unsubscribeBattery?.();
|
|
95
|
+
reducedMotionQuery?.removeEventListener?.("change", syncCapture);
|
|
96
|
+
mobileOrTouchQuery?.removeEventListener?.("change", syncCapture);
|
|
97
|
+
reducedTransparencyQuery?.removeEventListener?.("change", syncCapture);
|
|
98
|
+
highContrastQuery?.removeEventListener?.("change", syncCapture);
|
|
99
|
+
controllerRef.current?.destroy();
|
|
100
|
+
controllerRef.current = null;
|
|
101
|
+
};
|
|
102
|
+
}, [captureScene, syncCapture]);
|
|
103
|
+
const requestSceneCapture = useCallback(() => {
|
|
104
|
+
setForcedCapture(true);
|
|
105
|
+
}, []);
|
|
106
|
+
const refreshCapture = useCallback(() => {
|
|
107
|
+
controllerRef.current?.scheduleCapture();
|
|
108
|
+
}, []);
|
|
109
|
+
const contextValue = useMemo(
|
|
110
|
+
() => ({
|
|
111
|
+
sceneCanvas,
|
|
112
|
+
sceneElement,
|
|
113
|
+
defaults: stableDefaults,
|
|
114
|
+
requestSceneCapture,
|
|
115
|
+
refreshCapture
|
|
116
|
+
}),
|
|
117
|
+
[sceneCanvas, sceneElement, stableDefaults, requestSceneCapture, refreshCapture]
|
|
118
|
+
);
|
|
119
|
+
return /* @__PURE__ */ jsx(LiquidGlassContext.Provider, { value: contextValue, children: sceneRef ? children : /* @__PURE__ */ jsx("div", { ref: wrapperRef, className, style: { position: "relative" }, children }) });
|
|
120
|
+
}
|
|
121
|
+
function useLiquidGlassContext() {
|
|
122
|
+
return useContext(LiquidGlassContext);
|
|
123
|
+
}
|
|
124
|
+
function serializeDragBoundsKey(bounds) {
|
|
125
|
+
if (!bounds || typeof bounds === "string") return bounds;
|
|
126
|
+
if ("nodeType" in bounds) return bounds;
|
|
127
|
+
return `${bounds.minX ?? ""}|${bounds.maxX ?? ""}|${bounds.minY ?? ""}|${bounds.maxY ?? ""}`;
|
|
128
|
+
}
|
|
129
|
+
function useLiquidGlass(targetRef, options = {}) {
|
|
130
|
+
const context = useLiquidGlassContext();
|
|
131
|
+
const instanceRef = useRef(null);
|
|
132
|
+
const prevMergedOptionsRef = useRef(null);
|
|
133
|
+
const [engine, setEngine] = useState("css");
|
|
134
|
+
const sceneElement = options.sceneElement ?? context?.sceneElement ?? null;
|
|
135
|
+
const sceneCanvas = options.sceneCanvas ?? (sceneElement ? null : context?.sceneCanvas) ?? null;
|
|
136
|
+
const onEngineChangeRef = useRef(options.onEngineChange);
|
|
137
|
+
onEngineChangeRef.current = options.onEngineChange;
|
|
138
|
+
const onDragChangeRef = useRef(options.onDragChange);
|
|
139
|
+
onDragChangeRef.current = options.onDragChange;
|
|
140
|
+
const latestMergedOptionsRef = useRef({});
|
|
141
|
+
latestMergedOptionsRef.current = {
|
|
142
|
+
...mergeGlassOptions(context?.defaults, options),
|
|
143
|
+
sceneCanvas,
|
|
144
|
+
sceneElement,
|
|
145
|
+
onDragChange: (offsetX, offsetY, isDragging) => {
|
|
146
|
+
onDragChangeRef.current?.(offsetX, offsetY, isDragging);
|
|
147
|
+
},
|
|
148
|
+
onEngineChange: (nextEngine) => {
|
|
149
|
+
setEngine(nextEngine);
|
|
150
|
+
onEngineChangeRef.current?.(nextEngine);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const syncTargetElement = useCallback(() => {
|
|
154
|
+
const element = targetRef.current;
|
|
155
|
+
if (!element) {
|
|
156
|
+
instanceRef.current?.destroy();
|
|
157
|
+
instanceRef.current = null;
|
|
158
|
+
prevMergedOptionsRef.current = null;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const mergedOptions = latestMergedOptionsRef.current;
|
|
162
|
+
if (!instanceRef.current || instanceRef.current.element !== element) {
|
|
163
|
+
instanceRef.current?.destroy();
|
|
164
|
+
const instance = createLiquidGlass(element, mergedOptions);
|
|
165
|
+
instanceRef.current = instance;
|
|
166
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
167
|
+
setEngine(instance.engine);
|
|
168
|
+
} else {
|
|
169
|
+
const patch = computeMergedOptionPatch(prevMergedOptionsRef.current, mergedOptions);
|
|
170
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
171
|
+
instanceRef.current.update(patch);
|
|
172
|
+
setEngine(instanceRef.current.engine);
|
|
173
|
+
}
|
|
174
|
+
}, [targetRef]);
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if ((options.engine ?? context?.defaults?.engine) === "webgl" && context && !context.sceneCanvas) {
|
|
177
|
+
context.requestSceneCapture();
|
|
178
|
+
}
|
|
179
|
+
}, [options.engine, context]);
|
|
180
|
+
const tiltKey = serializeLightTiltKey(options.lightTilt);
|
|
181
|
+
const dragBoundsKey = serializeDragBoundsKey(options.dragBounds);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
syncTargetElement();
|
|
184
|
+
}, [
|
|
185
|
+
syncTargetElement,
|
|
186
|
+
context?.defaults,
|
|
187
|
+
options.preset,
|
|
188
|
+
options.theme,
|
|
189
|
+
options.surface,
|
|
190
|
+
options.engine,
|
|
191
|
+
options.thickness,
|
|
192
|
+
options.bezel,
|
|
193
|
+
options.adaptiveRefraction,
|
|
194
|
+
options.refractionDirection,
|
|
195
|
+
options.refractionEdgeFade,
|
|
196
|
+
options.maxRefractionPx,
|
|
197
|
+
options.scaleRatio,
|
|
198
|
+
options.maxScaleMultiplier,
|
|
199
|
+
options.blur,
|
|
200
|
+
options.ior,
|
|
201
|
+
options.radius,
|
|
202
|
+
options.cornerStyle,
|
|
203
|
+
options.pill,
|
|
204
|
+
options.hollow,
|
|
205
|
+
options.alwaysOn,
|
|
206
|
+
options.coreFilter,
|
|
207
|
+
options.tintColor,
|
|
208
|
+
options.tintOpacity,
|
|
209
|
+
options.highlight,
|
|
210
|
+
tiltKey,
|
|
211
|
+
options.pixelRatio,
|
|
212
|
+
options.saturation,
|
|
213
|
+
options.chromaticAberration,
|
|
214
|
+
options.abbeNumber,
|
|
215
|
+
options.interactive,
|
|
216
|
+
options.draggable,
|
|
217
|
+
dragBoundsKey,
|
|
218
|
+
options.coalesce,
|
|
219
|
+
sceneCanvas,
|
|
220
|
+
sceneElement
|
|
221
|
+
]);
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
const currentEl = targetRef.current;
|
|
224
|
+
const boundEl = instanceRef.current?.element ?? null;
|
|
225
|
+
if (currentEl !== boundEl) {
|
|
226
|
+
syncTargetElement();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
return () => {
|
|
231
|
+
instanceRef.current?.destroy();
|
|
232
|
+
instanceRef.current = null;
|
|
233
|
+
prevMergedOptionsRef.current = null;
|
|
234
|
+
};
|
|
235
|
+
}, []);
|
|
236
|
+
const refresh = useCallback(() => {
|
|
237
|
+
instanceRef.current?.refresh();
|
|
238
|
+
}, []);
|
|
239
|
+
const setLightTilt = useCallback((horizontal, vertical) => {
|
|
240
|
+
instanceRef.current?.setLightTilt?.(horizontal, vertical);
|
|
241
|
+
}, []);
|
|
242
|
+
const setDragOffset = useCallback((offsetX, offsetY, animate = true) => {
|
|
243
|
+
instanceRef.current?.setDragOffset?.(offsetX, offsetY, animate);
|
|
244
|
+
}, []);
|
|
245
|
+
return { engine, refresh, setLightTilt, setDragOffset };
|
|
246
|
+
}
|
|
247
|
+
var LiquidGlassImpl = forwardRef(
|
|
248
|
+
function LiquidGlass({
|
|
249
|
+
as,
|
|
250
|
+
children,
|
|
251
|
+
className,
|
|
252
|
+
preset,
|
|
253
|
+
theme,
|
|
254
|
+
surface,
|
|
255
|
+
engine,
|
|
256
|
+
thickness,
|
|
257
|
+
bezel,
|
|
258
|
+
adaptiveRefraction,
|
|
259
|
+
refractionDirection,
|
|
260
|
+
refractionEdgeFade,
|
|
261
|
+
maxRefractionPx,
|
|
262
|
+
scaleRatio,
|
|
263
|
+
maxScaleMultiplier,
|
|
264
|
+
blur,
|
|
265
|
+
ior,
|
|
266
|
+
radius,
|
|
267
|
+
cornerStyle,
|
|
268
|
+
pill,
|
|
269
|
+
hollow,
|
|
270
|
+
alwaysOn,
|
|
271
|
+
coreFilter,
|
|
272
|
+
tintColor,
|
|
273
|
+
tintOpacity,
|
|
274
|
+
highlight,
|
|
275
|
+
lightTilt,
|
|
276
|
+
pixelRatio,
|
|
277
|
+
saturation,
|
|
278
|
+
chromaticAberration,
|
|
279
|
+
abbeNumber,
|
|
280
|
+
interactive,
|
|
281
|
+
draggable,
|
|
282
|
+
dragBounds,
|
|
283
|
+
onDragChange,
|
|
284
|
+
coalesce,
|
|
285
|
+
sceneElement,
|
|
286
|
+
sceneCanvas,
|
|
287
|
+
onEngineChange,
|
|
288
|
+
...restProps
|
|
289
|
+
}, ref) {
|
|
290
|
+
const elRef = useRef(null);
|
|
291
|
+
useImperativeHandle(ref, () => elRef.current);
|
|
292
|
+
useLiquidGlass(elRef, {
|
|
293
|
+
preset,
|
|
294
|
+
theme,
|
|
295
|
+
surface,
|
|
296
|
+
engine,
|
|
297
|
+
thickness,
|
|
298
|
+
bezel,
|
|
299
|
+
adaptiveRefraction,
|
|
300
|
+
refractionDirection,
|
|
301
|
+
refractionEdgeFade,
|
|
302
|
+
maxRefractionPx,
|
|
303
|
+
scaleRatio,
|
|
304
|
+
maxScaleMultiplier,
|
|
305
|
+
blur,
|
|
306
|
+
ior,
|
|
307
|
+
radius,
|
|
308
|
+
cornerStyle,
|
|
309
|
+
pill,
|
|
310
|
+
hollow,
|
|
311
|
+
alwaysOn,
|
|
312
|
+
coreFilter,
|
|
313
|
+
tintColor,
|
|
314
|
+
tintOpacity,
|
|
315
|
+
highlight,
|
|
316
|
+
lightTilt,
|
|
317
|
+
pixelRatio,
|
|
318
|
+
saturation,
|
|
319
|
+
chromaticAberration,
|
|
320
|
+
abbeNumber,
|
|
321
|
+
interactive,
|
|
322
|
+
draggable,
|
|
323
|
+
dragBounds,
|
|
324
|
+
onDragChange,
|
|
325
|
+
coalesce,
|
|
326
|
+
sceneElement,
|
|
327
|
+
sceneCanvas,
|
|
328
|
+
onEngineChange
|
|
329
|
+
});
|
|
330
|
+
const Component = as ?? "div";
|
|
331
|
+
const classes = className ? `lg-surface ${className}` : "lg-surface";
|
|
332
|
+
return /* @__PURE__ */ jsx(Component, { ref: elRef, className: classes, ...restProps, children });
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
var LiquidGlass2 = LiquidGlassImpl;
|
|
336
|
+
function useGlassSwitch(targetRef, options = {}) {
|
|
337
|
+
const context = useLiquidGlassContext();
|
|
338
|
+
const instanceRef = useRef(null);
|
|
339
|
+
const prevMergedOptionsRef = useRef(null);
|
|
340
|
+
const [engine, setEngine] = useState("css");
|
|
341
|
+
const [value, setValueState] = useState(
|
|
342
|
+
options.value ?? options.defaultValue ?? ""
|
|
343
|
+
);
|
|
344
|
+
const [activeIndex, setActiveIndexState] = useState(0);
|
|
345
|
+
const sceneElement = options.sceneElement ?? context?.sceneElement ?? null;
|
|
346
|
+
const sceneCanvas = options.sceneCanvas ?? (sceneElement ? null : context?.sceneCanvas) ?? null;
|
|
347
|
+
const onChangeRef = useRef(options.onChange);
|
|
348
|
+
onChangeRef.current = options.onChange;
|
|
349
|
+
const onEngineChangeRef = useRef(options.onEngineChange);
|
|
350
|
+
onEngineChangeRef.current = options.onEngineChange;
|
|
351
|
+
const latestMergedOptionsRef = useRef({});
|
|
352
|
+
latestMergedOptionsRef.current = {
|
|
353
|
+
...mergeGlassOptions(context?.defaults, options),
|
|
354
|
+
sceneCanvas,
|
|
355
|
+
sceneElement,
|
|
356
|
+
onChange: (nextValue, nextIndex, itemElement) => {
|
|
357
|
+
setValueState(nextValue);
|
|
358
|
+
setActiveIndexState(nextIndex);
|
|
359
|
+
onChangeRef.current?.(nextValue, nextIndex, itemElement);
|
|
360
|
+
},
|
|
361
|
+
onEngineChange: (nextEngine) => {
|
|
362
|
+
setEngine(nextEngine);
|
|
363
|
+
onEngineChangeRef.current?.(nextEngine);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const syncTargetElement = useCallback(() => {
|
|
367
|
+
const element = targetRef.current;
|
|
368
|
+
if (!element) {
|
|
369
|
+
instanceRef.current?.destroy();
|
|
370
|
+
instanceRef.current = null;
|
|
371
|
+
prevMergedOptionsRef.current = null;
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const mergedOptions = latestMergedOptionsRef.current;
|
|
375
|
+
if (!instanceRef.current || instanceRef.current.element !== element) {
|
|
376
|
+
instanceRef.current?.destroy();
|
|
377
|
+
const instance = createGlassSwitch(element, mergedOptions);
|
|
378
|
+
instanceRef.current = instance;
|
|
379
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
380
|
+
setEngine(instance.engine);
|
|
381
|
+
setValueState(instance.value);
|
|
382
|
+
setActiveIndexState(instance.activeIndex);
|
|
383
|
+
} else {
|
|
384
|
+
const patch = computeMergedOptionPatch(prevMergedOptionsRef.current, mergedOptions);
|
|
385
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
386
|
+
instanceRef.current.update(patch);
|
|
387
|
+
setEngine(instanceRef.current.engine);
|
|
388
|
+
setValueState(instanceRef.current.value);
|
|
389
|
+
setActiveIndexState(instanceRef.current.activeIndex);
|
|
390
|
+
}
|
|
391
|
+
}, [targetRef]);
|
|
392
|
+
useEffect(() => {
|
|
393
|
+
if ((options.engine ?? context?.defaults?.engine) === "webgl" && context && !context.sceneCanvas) {
|
|
394
|
+
context.requestSceneCapture();
|
|
395
|
+
}
|
|
396
|
+
}, [options.engine, context]);
|
|
397
|
+
const tiltKey = serializeLightTiltKey(options.lightTilt);
|
|
398
|
+
useEffect(() => {
|
|
399
|
+
syncTargetElement();
|
|
400
|
+
}, [
|
|
401
|
+
syncTargetElement,
|
|
402
|
+
context?.defaults,
|
|
403
|
+
options.value,
|
|
404
|
+
options.defaultValue,
|
|
405
|
+
options.orientation,
|
|
406
|
+
options.itemSelector,
|
|
407
|
+
options.gliderElement,
|
|
408
|
+
options.trackOptions,
|
|
409
|
+
options.gliderOptions,
|
|
410
|
+
options.preset,
|
|
411
|
+
options.theme,
|
|
412
|
+
options.surface,
|
|
413
|
+
options.engine,
|
|
414
|
+
options.thickness,
|
|
415
|
+
options.bezel,
|
|
416
|
+
options.adaptiveRefraction,
|
|
417
|
+
options.refractionDirection,
|
|
418
|
+
options.refractionEdgeFade,
|
|
419
|
+
options.maxRefractionPx,
|
|
420
|
+
options.scaleRatio,
|
|
421
|
+
options.maxScaleMultiplier,
|
|
422
|
+
options.blur,
|
|
423
|
+
options.ior,
|
|
424
|
+
options.radius,
|
|
425
|
+
options.cornerStyle,
|
|
426
|
+
options.pill,
|
|
427
|
+
options.hollow,
|
|
428
|
+
options.alwaysOn,
|
|
429
|
+
options.coreFilter,
|
|
430
|
+
options.tintColor,
|
|
431
|
+
options.tintOpacity,
|
|
432
|
+
options.highlight,
|
|
433
|
+
tiltKey,
|
|
434
|
+
options.pixelRatio,
|
|
435
|
+
options.saturation,
|
|
436
|
+
options.chromaticAberration,
|
|
437
|
+
options.abbeNumber,
|
|
438
|
+
options.interactive,
|
|
439
|
+
options.draggable,
|
|
440
|
+
options.coalesce,
|
|
441
|
+
sceneCanvas,
|
|
442
|
+
sceneElement
|
|
443
|
+
]);
|
|
444
|
+
useEffect(() => {
|
|
445
|
+
const currentEl = targetRef.current;
|
|
446
|
+
const boundEl = instanceRef.current?.element ?? null;
|
|
447
|
+
if (currentEl !== boundEl) {
|
|
448
|
+
syncTargetElement();
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
useEffect(() => {
|
|
452
|
+
return () => {
|
|
453
|
+
instanceRef.current?.destroy();
|
|
454
|
+
instanceRef.current = null;
|
|
455
|
+
prevMergedOptionsRef.current = null;
|
|
456
|
+
};
|
|
457
|
+
}, []);
|
|
458
|
+
const setValue = useCallback((nextValue, animate = true) => {
|
|
459
|
+
const instance = instanceRef.current;
|
|
460
|
+
if (!instance) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
instance.setValue(nextValue, animate);
|
|
464
|
+
setValueState(instance.value);
|
|
465
|
+
setActiveIndexState(instance.activeIndex);
|
|
466
|
+
}, []);
|
|
467
|
+
const setActiveIndex = useCallback((nextIndex, animate = true) => {
|
|
468
|
+
const instance = instanceRef.current;
|
|
469
|
+
if (!instance) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
instance.setActiveIndex(nextIndex, animate);
|
|
473
|
+
setValueState(instance.value);
|
|
474
|
+
setActiveIndexState(instance.activeIndex);
|
|
475
|
+
}, []);
|
|
476
|
+
const refresh = useCallback(() => {
|
|
477
|
+
instanceRef.current?.refresh();
|
|
478
|
+
}, []);
|
|
479
|
+
const setLightTilt = useCallback((horizontal, vertical) => {
|
|
480
|
+
instanceRef.current?.setLightTilt?.(horizontal, vertical);
|
|
481
|
+
}, []);
|
|
482
|
+
return {
|
|
483
|
+
engine,
|
|
484
|
+
value,
|
|
485
|
+
activeIndex,
|
|
486
|
+
setValue,
|
|
487
|
+
setActiveIndex,
|
|
488
|
+
refresh,
|
|
489
|
+
setLightTilt
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
493
|
+
function useGlassSlider(inputRef, options = {}) {
|
|
494
|
+
const context = useLiquidGlassContext();
|
|
495
|
+
const instanceRef = useRef(null);
|
|
496
|
+
const prevMergedOptionsRef = useRef(null);
|
|
497
|
+
const [engine, setEngine] = useState("css");
|
|
498
|
+
const [value, setValueState] = useState(0);
|
|
499
|
+
const sceneElement = options.sceneElement ?? context?.sceneElement ?? null;
|
|
500
|
+
const sceneCanvas = options.sceneCanvas ?? (sceneElement ? null : context?.sceneCanvas) ?? null;
|
|
501
|
+
const onChangeRef = useRef(options.onChange);
|
|
502
|
+
onChangeRef.current = options.onChange;
|
|
503
|
+
const onEngineChangeRef = useRef(options.onEngineChange);
|
|
504
|
+
onEngineChangeRef.current = options.onEngineChange;
|
|
505
|
+
const latestMergedOptionsRef = useRef({});
|
|
506
|
+
latestMergedOptionsRef.current = {
|
|
507
|
+
...mergeGlassOptions(context?.defaults, options),
|
|
508
|
+
sceneCanvas,
|
|
509
|
+
sceneElement,
|
|
510
|
+
onChange: (nextValue, inputEl) => {
|
|
511
|
+
setValueState(nextValue);
|
|
512
|
+
onChangeRef.current?.(nextValue, inputEl);
|
|
513
|
+
},
|
|
514
|
+
onEngineChange: (nextEngine) => {
|
|
515
|
+
setEngine(nextEngine);
|
|
516
|
+
onEngineChangeRef.current?.(nextEngine);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
const syncTargetElement = useCallback(() => {
|
|
520
|
+
const element = inputRef.current;
|
|
521
|
+
if (!element) {
|
|
522
|
+
instanceRef.current?.destroy();
|
|
523
|
+
instanceRef.current = null;
|
|
524
|
+
prevMergedOptionsRef.current = null;
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const mergedOptions = latestMergedOptionsRef.current;
|
|
528
|
+
if (!instanceRef.current || instanceRef.current.element !== element) {
|
|
529
|
+
instanceRef.current?.destroy();
|
|
530
|
+
const instance = createGlassSlider(element, mergedOptions);
|
|
531
|
+
instanceRef.current = instance;
|
|
532
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
533
|
+
setEngine(instance.engine);
|
|
534
|
+
setValueState(instance.value);
|
|
535
|
+
} else {
|
|
536
|
+
const patch = computeMergedOptionPatch(prevMergedOptionsRef.current, mergedOptions);
|
|
537
|
+
prevMergedOptionsRef.current = mergedOptions;
|
|
538
|
+
instanceRef.current.update(patch);
|
|
539
|
+
setEngine(instanceRef.current.engine);
|
|
540
|
+
setValueState(instanceRef.current.value);
|
|
541
|
+
}
|
|
542
|
+
}, [inputRef]);
|
|
543
|
+
useEffect(() => {
|
|
544
|
+
if ((options.engine ?? context?.defaults?.engine) === "webgl" && context && !context.sceneCanvas) {
|
|
545
|
+
context.requestSceneCapture();
|
|
546
|
+
}
|
|
547
|
+
}, [options.engine, context]);
|
|
548
|
+
const tiltKey = serializeLightTiltKey(options.lightTilt);
|
|
549
|
+
useEffect(() => {
|
|
550
|
+
syncTargetElement();
|
|
551
|
+
}, [
|
|
552
|
+
syncTargetElement,
|
|
553
|
+
context?.defaults,
|
|
554
|
+
options.orientation,
|
|
555
|
+
options.preset,
|
|
556
|
+
options.theme,
|
|
557
|
+
options.surface,
|
|
558
|
+
options.engine,
|
|
559
|
+
options.thickness,
|
|
560
|
+
options.bezel,
|
|
561
|
+
options.adaptiveRefraction,
|
|
562
|
+
options.refractionDirection,
|
|
563
|
+
options.refractionEdgeFade,
|
|
564
|
+
options.maxRefractionPx,
|
|
565
|
+
options.scaleRatio,
|
|
566
|
+
options.maxScaleMultiplier,
|
|
567
|
+
options.blur,
|
|
568
|
+
options.ior,
|
|
569
|
+
options.radius,
|
|
570
|
+
options.cornerStyle,
|
|
571
|
+
options.pill,
|
|
572
|
+
options.hollow,
|
|
573
|
+
options.alwaysOn,
|
|
574
|
+
options.coreFilter,
|
|
575
|
+
options.tintColor,
|
|
576
|
+
options.tintOpacity,
|
|
577
|
+
options.highlight,
|
|
578
|
+
tiltKey,
|
|
579
|
+
options.pixelRatio,
|
|
580
|
+
options.saturation,
|
|
581
|
+
options.chromaticAberration,
|
|
582
|
+
options.abbeNumber,
|
|
583
|
+
options.interactive,
|
|
584
|
+
options.draggable,
|
|
585
|
+
options.coalesce,
|
|
586
|
+
sceneCanvas,
|
|
587
|
+
sceneElement
|
|
588
|
+
]);
|
|
589
|
+
useEffect(() => {
|
|
590
|
+
const currentEl = inputRef.current;
|
|
591
|
+
const boundEl = instanceRef.current?.element ?? null;
|
|
592
|
+
if (currentEl !== boundEl) {
|
|
593
|
+
syncTargetElement();
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
useIsomorphicLayoutEffect(() => {
|
|
597
|
+
return () => {
|
|
598
|
+
instanceRef.current?.destroy();
|
|
599
|
+
instanceRef.current = null;
|
|
600
|
+
prevMergedOptionsRef.current = null;
|
|
601
|
+
};
|
|
602
|
+
}, []);
|
|
603
|
+
const setValue = useCallback((nextValue, animate = true) => {
|
|
604
|
+
const instance = instanceRef.current;
|
|
605
|
+
if (!instance) return;
|
|
606
|
+
instance.setValue(nextValue, animate);
|
|
607
|
+
setValueState(instance.value);
|
|
608
|
+
}, []);
|
|
609
|
+
const refresh = useCallback(() => {
|
|
610
|
+
instanceRef.current?.refresh();
|
|
611
|
+
}, []);
|
|
612
|
+
const setLightTilt = useCallback((horizontal, vertical) => {
|
|
613
|
+
instanceRef.current?.setLightTilt?.(horizontal, vertical);
|
|
614
|
+
}, []);
|
|
615
|
+
return {
|
|
616
|
+
engine,
|
|
617
|
+
value,
|
|
618
|
+
setValue,
|
|
619
|
+
refresh,
|
|
620
|
+
setLightTilt
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
var LiquidGlassSlider = forwardRef(
|
|
624
|
+
function LiquidGlassSlider2({
|
|
625
|
+
orientation,
|
|
626
|
+
onChange,
|
|
627
|
+
onValueChange,
|
|
628
|
+
preset,
|
|
629
|
+
theme,
|
|
630
|
+
surface,
|
|
631
|
+
engine,
|
|
632
|
+
thickness,
|
|
633
|
+
bezel,
|
|
634
|
+
adaptiveRefraction,
|
|
635
|
+
refractionDirection,
|
|
636
|
+
refractionEdgeFade,
|
|
637
|
+
maxRefractionPx,
|
|
638
|
+
scaleRatio,
|
|
639
|
+
maxScaleMultiplier,
|
|
640
|
+
blur,
|
|
641
|
+
ior,
|
|
642
|
+
radius,
|
|
643
|
+
cornerStyle,
|
|
644
|
+
pill,
|
|
645
|
+
hollow,
|
|
646
|
+
alwaysOn,
|
|
647
|
+
coreFilter,
|
|
648
|
+
tintColor,
|
|
649
|
+
tintOpacity,
|
|
650
|
+
highlight,
|
|
651
|
+
lightTilt,
|
|
652
|
+
pixelRatio,
|
|
653
|
+
saturation,
|
|
654
|
+
chromaticAberration,
|
|
655
|
+
abbeNumber,
|
|
656
|
+
interactive,
|
|
657
|
+
draggable,
|
|
658
|
+
dragBounds,
|
|
659
|
+
onDragChange,
|
|
660
|
+
coalesce,
|
|
661
|
+
sceneElement,
|
|
662
|
+
sceneCanvas,
|
|
663
|
+
onEngineChange,
|
|
664
|
+
value,
|
|
665
|
+
disabled,
|
|
666
|
+
min,
|
|
667
|
+
max,
|
|
668
|
+
step,
|
|
669
|
+
...restProps
|
|
670
|
+
}, ref) {
|
|
671
|
+
const inputRef = useRef(null);
|
|
672
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
673
|
+
const { refresh } = useGlassSlider(inputRef, {
|
|
674
|
+
orientation,
|
|
675
|
+
onChange: (nextVal, inputEl) => {
|
|
676
|
+
onChange?.(nextVal, inputEl);
|
|
677
|
+
onValueChange?.(nextVal, inputEl);
|
|
678
|
+
},
|
|
679
|
+
preset,
|
|
680
|
+
theme,
|
|
681
|
+
surface,
|
|
682
|
+
engine,
|
|
683
|
+
thickness,
|
|
684
|
+
bezel,
|
|
685
|
+
adaptiveRefraction,
|
|
686
|
+
refractionDirection,
|
|
687
|
+
refractionEdgeFade,
|
|
688
|
+
maxRefractionPx,
|
|
689
|
+
scaleRatio,
|
|
690
|
+
maxScaleMultiplier,
|
|
691
|
+
blur,
|
|
692
|
+
ior,
|
|
693
|
+
radius,
|
|
694
|
+
cornerStyle,
|
|
695
|
+
pill,
|
|
696
|
+
hollow,
|
|
697
|
+
alwaysOn,
|
|
698
|
+
coreFilter,
|
|
699
|
+
tintColor,
|
|
700
|
+
tintOpacity,
|
|
701
|
+
highlight,
|
|
702
|
+
lightTilt,
|
|
703
|
+
pixelRatio,
|
|
704
|
+
saturation,
|
|
705
|
+
chromaticAberration,
|
|
706
|
+
abbeNumber,
|
|
707
|
+
interactive,
|
|
708
|
+
draggable,
|
|
709
|
+
dragBounds,
|
|
710
|
+
onDragChange,
|
|
711
|
+
coalesce,
|
|
712
|
+
sceneElement,
|
|
713
|
+
sceneCanvas,
|
|
714
|
+
onEngineChange
|
|
715
|
+
});
|
|
716
|
+
const didMountRef = useRef(false);
|
|
717
|
+
useEffect(() => {
|
|
718
|
+
if (!didMountRef.current) {
|
|
719
|
+
didMountRef.current = true;
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
refresh();
|
|
723
|
+
}, [value, min, max, step, disabled, refresh]);
|
|
724
|
+
return /* @__PURE__ */ jsx("span", { className: "lg-slider-host", style: { display: "contents" }, children: /* @__PURE__ */ jsx(
|
|
725
|
+
"input",
|
|
726
|
+
{
|
|
727
|
+
ref: inputRef,
|
|
728
|
+
type: "range",
|
|
729
|
+
value,
|
|
730
|
+
onChange: value !== void 0 ? () => {
|
|
731
|
+
} : void 0,
|
|
732
|
+
disabled,
|
|
733
|
+
min,
|
|
734
|
+
max,
|
|
735
|
+
step,
|
|
736
|
+
...restProps
|
|
737
|
+
}
|
|
738
|
+
) });
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
|
|
742
|
+
export { LiquidGlass2 as LiquidGlass, LiquidGlassProvider, LiquidGlassSlider, useGlassSlider, useGlassSwitch, useLiquidGlass, useLiquidGlassContext };
|
|
743
|
+
//# sourceMappingURL=chunk-GMQXHUV5.js.map
|
|
744
|
+
//# sourceMappingURL=chunk-GMQXHUV5.js.map
|