@pixerate/editor-react 0.95.0 → 0.96.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/README.md +2 -0
- package/dist/animation-editor/index.cjs +1240 -195
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1418 -373
- package/dist/canvas/index.js +4 -2
- package/dist/chunk-3I7FOSLF.js +988 -0
- package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
- package/dist/{chunk-5R67YSSD.js → chunk-GLSOQNQR.js} +1 -1
- package/dist/{chunk-6YRSQW2V.js → chunk-IY6YOY5B.js} +1 -1
- package/dist/chunk-KIRIU53A.js +72 -0
- package/dist/color/ColorPicker.d.cts +30 -0
- package/dist/color/ColorPicker.d.ts +30 -0
- package/dist/color/DualColorPicker.d.cts +29 -0
- package/dist/color/DualColorPicker.d.ts +29 -0
- package/dist/color/index.cjs +1067 -0
- package/dist/color/index.d.cts +7 -0
- package/dist/color/index.d.ts +7 -0
- package/dist/color/index.js +14 -0
- package/dist/color/useColorScheme.d.cts +16 -0
- package/dist/color/useColorScheme.d.ts +16 -0
- package/dist/effects/index.cjs +1169 -124
- package/dist/effects/index.js +4 -2
- package/dist/gradient/FillPicker.d.cts +27 -0
- package/dist/gradient/FillPicker.d.ts +27 -0
- package/dist/gradient/GradientEditor.d.cts +21 -0
- package/dist/gradient/GradientEditor.d.ts +21 -0
- package/dist/gradient/index.cjs +1601 -0
- package/dist/gradient/index.d.cts +6 -0
- package/dist/gradient/index.d.ts +6 -0
- package/dist/gradient/index.js +617 -0
- package/dist/gradient/useGradientController.d.cts +10 -0
- package/dist/gradient/useGradientController.d.ts +10 -0
- package/dist/image-editor/index.cjs +1742 -697
- package/dist/image-editor/index.js +5 -3
- package/dist/index.cjs +2160 -1115
- package/dist/index.js +5 -3
- package/dist/paint-editor/index.cjs +1233 -188
- package/dist/paint-editor/index.js +4 -2
- package/dist/parameters/fields.d.cts +1 -1
- package/dist/parameters/fields.d.ts +1 -1
- package/dist/parameters/index.cjs +1218 -173
- package/dist/parameters/index.js +3 -1
- package/dist/vector/index.cjs +1219 -174
- package/dist/vector/index.js +4 -2
- package/dist/video-editor/index.cjs +1230 -185
- package/dist/video-editor/index.js +4 -2
- package/package.json +29 -3
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
21
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
22
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
23
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -102,9 +103,1050 @@ function useParameterCommands(registry, controller, options = {}) {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
// src/parameters/fields.tsx
|
|
105
|
-
var
|
|
106
|
+
var import_react5 = require("react");
|
|
106
107
|
var import_parameters2 = require("@pixerate/editor/parameters");
|
|
108
|
+
|
|
109
|
+
// src/color/index.ts
|
|
110
|
+
var color_exports = {};
|
|
111
|
+
__export(color_exports, {
|
|
112
|
+
ColorPicker: () => ColorPicker,
|
|
113
|
+
DualColorPicker: () => DualColorPicker,
|
|
114
|
+
useColorScheme: () => useColorScheme,
|
|
115
|
+
useResolvedColor: () => useResolvedColor
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/color/ColorPicker.tsx
|
|
119
|
+
var import_react2 = require("react");
|
|
120
|
+
var import_color = require("@pixerate/editor/color");
|
|
107
121
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
122
|
+
var LOCAL_STORAGE_KEY = "pixerate:color:recent";
|
|
123
|
+
function readLocalRecents() {
|
|
124
|
+
try {
|
|
125
|
+
if (typeof localStorage === "undefined") return [];
|
|
126
|
+
const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
127
|
+
if (!raw) return [];
|
|
128
|
+
const parsed = JSON.parse(raw);
|
|
129
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
130
|
+
} catch {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function writeLocalRecents(list) {
|
|
135
|
+
try {
|
|
136
|
+
if (typeof localStorage !== "undefined") {
|
|
137
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
|
|
138
|
+
}
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
|
|
143
|
+
var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
|
|
144
|
+
var ColorPicker = ({
|
|
145
|
+
value,
|
|
146
|
+
onChange,
|
|
147
|
+
onGestureStart,
|
|
148
|
+
onGestureEnd,
|
|
149
|
+
alpha = false,
|
|
150
|
+
swatches,
|
|
151
|
+
recent: controlledRecent,
|
|
152
|
+
onRecentChange,
|
|
153
|
+
contrastAgainst,
|
|
154
|
+
disabled = false,
|
|
155
|
+
className,
|
|
156
|
+
id,
|
|
157
|
+
"aria-label": ariaLabel = "Color picker"
|
|
158
|
+
}) => {
|
|
159
|
+
const generatedId = (0, import_react2.useId)();
|
|
160
|
+
const pickerId = id || generatedId;
|
|
161
|
+
const [pickerState, setPickerState] = (0, import_react2.useState)(
|
|
162
|
+
() => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
|
|
163
|
+
);
|
|
164
|
+
const stateRef = (0, import_react2.useRef)(pickerState);
|
|
165
|
+
stateRef.current = pickerState;
|
|
166
|
+
(0, import_react2.useEffect)(() => {
|
|
167
|
+
const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
|
|
168
|
+
if (next) {
|
|
169
|
+
setPickerState(next);
|
|
170
|
+
}
|
|
171
|
+
}, [value]);
|
|
172
|
+
const [internalRecent, setInternalRecent] = (0, import_react2.useState)(
|
|
173
|
+
() => controlledRecent ? [] : readLocalRecents()
|
|
174
|
+
);
|
|
175
|
+
const activeRecent = controlledRecent ?? internalRecent;
|
|
176
|
+
const recordRecent = (0, import_react2.useCallback)(
|
|
177
|
+
(color) => {
|
|
178
|
+
const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
|
|
179
|
+
if (!controlledRecent) {
|
|
180
|
+
setInternalRecent(updated);
|
|
181
|
+
writeLocalRecents(updated);
|
|
182
|
+
}
|
|
183
|
+
onRecentChange?.(updated);
|
|
184
|
+
},
|
|
185
|
+
[activeRecent, controlledRecent, onRecentChange]
|
|
186
|
+
);
|
|
187
|
+
const [textDraft, setTextDraft] = (0, import_react2.useState)(value);
|
|
188
|
+
const [isInvalid, setIsInvalid] = (0, import_react2.useState)(false);
|
|
189
|
+
const [isClipped, setIsClipped] = (0, import_react2.useState)(false);
|
|
190
|
+
const isTypingRef = (0, import_react2.useRef)(false);
|
|
191
|
+
(0, import_react2.useEffect)(() => {
|
|
192
|
+
if (!isTypingRef.current) {
|
|
193
|
+
setTextDraft(value);
|
|
194
|
+
setIsInvalid(false);
|
|
195
|
+
const parsed = (0, import_color.parseColor)(value);
|
|
196
|
+
setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
|
|
197
|
+
}
|
|
198
|
+
}, [value]);
|
|
199
|
+
const [hasEyeDropper, setHasEyeDropper] = (0, import_react2.useState)(false);
|
|
200
|
+
(0, import_react2.useEffect)(() => {
|
|
201
|
+
setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
|
|
202
|
+
}, []);
|
|
203
|
+
const emitColorChange = (0, import_react2.useCallback)(
|
|
204
|
+
(nextState) => {
|
|
205
|
+
setPickerState(nextState);
|
|
206
|
+
const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
|
|
207
|
+
onChange(hex);
|
|
208
|
+
},
|
|
209
|
+
[alpha, onChange]
|
|
210
|
+
);
|
|
211
|
+
const latest = (0, import_react2.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
|
|
212
|
+
latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
|
|
213
|
+
const endDragRef = (0, import_react2.useRef)(null);
|
|
214
|
+
(0, import_react2.useEffect)(() => () => endDragRef.current?.(), []);
|
|
215
|
+
const startDrag = (e, next) => {
|
|
216
|
+
if (disabled) return;
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
endDragRef.current?.();
|
|
219
|
+
onGestureStart?.();
|
|
220
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
221
|
+
const update = (clientX, clientY) => {
|
|
222
|
+
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
223
|
+
const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
|
|
224
|
+
latest.current.emitColorChange(next(stateRef.current, x, y));
|
|
225
|
+
};
|
|
226
|
+
update(e.clientX, e.clientY);
|
|
227
|
+
const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
|
|
228
|
+
const end = () => {
|
|
229
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
230
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
231
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
232
|
+
endDragRef.current = null;
|
|
233
|
+
latest.current.onGestureEnd?.();
|
|
234
|
+
};
|
|
235
|
+
const onPointerUp = () => {
|
|
236
|
+
end();
|
|
237
|
+
latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
|
|
238
|
+
};
|
|
239
|
+
endDragRef.current = end;
|
|
240
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
241
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
242
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
243
|
+
};
|
|
244
|
+
const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
|
|
245
|
+
const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
|
|
246
|
+
const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
|
|
247
|
+
const handleAreaKeyDown = (e) => {
|
|
248
|
+
if (disabled) return;
|
|
249
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
|
|
250
|
+
if (next) {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
emitColorChange(next);
|
|
253
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const handleHueKeyDown = (e) => {
|
|
257
|
+
if (disabled) return;
|
|
258
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
|
|
259
|
+
if (next) {
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
emitColorChange(next);
|
|
262
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const handleAlphaKeyDown = (e) => {
|
|
266
|
+
if (disabled) return;
|
|
267
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
|
|
268
|
+
if (next) {
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
emitColorChange(next);
|
|
271
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const commitTextInput = (inputElement) => {
|
|
275
|
+
isTypingRef.current = false;
|
|
276
|
+
const parsed = (0, import_color.parseColor)(textDraft);
|
|
277
|
+
if (parsed) {
|
|
278
|
+
setIsInvalid(false);
|
|
279
|
+
setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
|
|
280
|
+
const formatted = (0, import_color.formatHex)(parsed);
|
|
281
|
+
onChange(formatted);
|
|
282
|
+
recordRecent(formatted);
|
|
283
|
+
} else {
|
|
284
|
+
setIsInvalid(true);
|
|
285
|
+
setTextDraft(value);
|
|
286
|
+
if (inputElement) {
|
|
287
|
+
inputElement.value = value;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const handleTextKeyDown = (e) => {
|
|
292
|
+
if (e.key === "Enter") {
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
commitTextInput(e.currentTarget);
|
|
295
|
+
} else if (e.key === "Escape") {
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
isTypingRef.current = false;
|
|
298
|
+
setIsInvalid(false);
|
|
299
|
+
setTextDraft(value);
|
|
300
|
+
e.currentTarget.value = value;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const handleEyeDropper = async () => {
|
|
304
|
+
if (disabled || !hasEyeDropper) return;
|
|
305
|
+
try {
|
|
306
|
+
const EyeDropperClass = window.EyeDropper;
|
|
307
|
+
const eyeDropper = new EyeDropperClass();
|
|
308
|
+
const res = await eyeDropper.open();
|
|
309
|
+
if (res?.sRGBHex) {
|
|
310
|
+
onChange(res.sRGBHex);
|
|
311
|
+
recordRecent(res.sRGBHex);
|
|
312
|
+
}
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const contrastResult = (0, import_react2.useMemo)(() => {
|
|
317
|
+
if (!contrastAgainst) return null;
|
|
318
|
+
const fg = (0, import_color.parseColor)(value);
|
|
319
|
+
const bg = (0, import_color.parseColor)(contrastAgainst);
|
|
320
|
+
if (!fg || !bg) return null;
|
|
321
|
+
const ratio = (0, import_color.contrastRatio)(fg, bg);
|
|
322
|
+
const aa = ratio >= 4.5;
|
|
323
|
+
const aaa = ratio >= 7;
|
|
324
|
+
return { ratio, aa, aaa };
|
|
325
|
+
}, [value, contrastAgainst]);
|
|
326
|
+
const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
|
|
327
|
+
const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
|
|
328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
329
|
+
"div",
|
|
330
|
+
{
|
|
331
|
+
id: pickerId,
|
|
332
|
+
role: "group",
|
|
333
|
+
"aria-label": ariaLabel,
|
|
334
|
+
className,
|
|
335
|
+
style: {
|
|
336
|
+
boxSizing: "border-box",
|
|
337
|
+
width: "var(--pixerate-color-picker-width, 240px)",
|
|
338
|
+
borderRadius: "var(--pixerate-color-picker-radius, 8px)",
|
|
339
|
+
background: "var(--pixerate-color-picker-bg, #1f2430)",
|
|
340
|
+
color: "var(--pixerate-color-picker-fg, #f0f2f5)",
|
|
341
|
+
padding: "12px",
|
|
342
|
+
display: "flex",
|
|
343
|
+
flexDirection: "column",
|
|
344
|
+
gap: "10px",
|
|
345
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
346
|
+
fontSize: "12px",
|
|
347
|
+
userSelect: "none",
|
|
348
|
+
opacity: disabled ? 0.6 : 1,
|
|
349
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
350
|
+
},
|
|
351
|
+
children: [
|
|
352
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
353
|
+
"span",
|
|
354
|
+
{
|
|
355
|
+
role: "status",
|
|
356
|
+
"aria-live": "polite",
|
|
357
|
+
style: {
|
|
358
|
+
position: "absolute",
|
|
359
|
+
width: "1px",
|
|
360
|
+
height: "1px",
|
|
361
|
+
padding: 0,
|
|
362
|
+
margin: "-1px",
|
|
363
|
+
overflow: "hidden",
|
|
364
|
+
clip: "rect(0, 0, 0, 0)",
|
|
365
|
+
whiteSpace: "nowrap",
|
|
366
|
+
border: 0
|
|
367
|
+
},
|
|
368
|
+
children: liveDescription
|
|
369
|
+
}
|
|
370
|
+
),
|
|
371
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
372
|
+
"div",
|
|
373
|
+
{
|
|
374
|
+
role: "slider",
|
|
375
|
+
tabIndex: disabled ? -1 : 0,
|
|
376
|
+
"aria-label": "Saturation and brightness",
|
|
377
|
+
"aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
|
|
378
|
+
pickerState.v * 100
|
|
379
|
+
)}%`,
|
|
380
|
+
"aria-disabled": disabled,
|
|
381
|
+
onPointerDown: handleAreaPointerDown,
|
|
382
|
+
onKeyDown: handleAreaKeyDown,
|
|
383
|
+
style: {
|
|
384
|
+
position: "relative",
|
|
385
|
+
width: "100%",
|
|
386
|
+
height: "150px",
|
|
387
|
+
borderRadius: "6px",
|
|
388
|
+
background: (0, import_color.pickerAreaBackground)(pickerState),
|
|
389
|
+
cursor: disabled ? "default" : "crosshair",
|
|
390
|
+
touchAction: "none",
|
|
391
|
+
outline: "none"
|
|
392
|
+
},
|
|
393
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
394
|
+
"div",
|
|
395
|
+
{
|
|
396
|
+
style: {
|
|
397
|
+
position: "absolute",
|
|
398
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
399
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
400
|
+
borderRadius: "50%",
|
|
401
|
+
transform: "translate(-50%, -50%)",
|
|
402
|
+
left: `${pickerState.s * 100}%`,
|
|
403
|
+
top: `${(1 - pickerState.v) * 100}%`,
|
|
404
|
+
border: "2px solid #ffffff",
|
|
405
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
406
|
+
pointerEvents: "none",
|
|
407
|
+
backgroundColor: currentHex
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
414
|
+
"div",
|
|
415
|
+
{
|
|
416
|
+
role: "slider",
|
|
417
|
+
tabIndex: disabled ? -1 : 0,
|
|
418
|
+
"aria-label": "Hue",
|
|
419
|
+
"aria-valuenow": Math.round(pickerState.h),
|
|
420
|
+
"aria-valuemin": 0,
|
|
421
|
+
"aria-valuemax": 360,
|
|
422
|
+
"aria-valuetext": `${Math.round(pickerState.h)} degrees`,
|
|
423
|
+
"aria-disabled": disabled,
|
|
424
|
+
onPointerDown: handleHuePointerDown,
|
|
425
|
+
onKeyDown: handleHueKeyDown,
|
|
426
|
+
style: {
|
|
427
|
+
position: "relative",
|
|
428
|
+
width: "100%",
|
|
429
|
+
height: "12px",
|
|
430
|
+
borderRadius: "6px",
|
|
431
|
+
background: import_color.PICKER_HUE_BACKGROUND,
|
|
432
|
+
cursor: disabled ? "default" : "pointer",
|
|
433
|
+
touchAction: "none",
|
|
434
|
+
outline: "none"
|
|
435
|
+
},
|
|
436
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
437
|
+
"div",
|
|
438
|
+
{
|
|
439
|
+
style: {
|
|
440
|
+
position: "absolute",
|
|
441
|
+
top: "50%",
|
|
442
|
+
transform: "translate(-50%, -50%)",
|
|
443
|
+
left: `${pickerState.h / 360 * 100}%`,
|
|
444
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
445
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
446
|
+
borderRadius: "50%",
|
|
447
|
+
border: "2px solid #ffffff",
|
|
448
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
449
|
+
pointerEvents: "none",
|
|
450
|
+
backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
alpha && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
457
|
+
"div",
|
|
458
|
+
{
|
|
459
|
+
role: "slider",
|
|
460
|
+
tabIndex: disabled ? -1 : 0,
|
|
461
|
+
"aria-label": "Alpha",
|
|
462
|
+
"aria-valuenow": Math.round(pickerState.alpha * 100),
|
|
463
|
+
"aria-valuemin": 0,
|
|
464
|
+
"aria-valuemax": 100,
|
|
465
|
+
"aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
|
|
466
|
+
"aria-disabled": disabled,
|
|
467
|
+
onPointerDown: handleAlphaPointerDown,
|
|
468
|
+
onKeyDown: handleAlphaKeyDown,
|
|
469
|
+
style: {
|
|
470
|
+
position: "relative",
|
|
471
|
+
width: "100%",
|
|
472
|
+
height: "12px",
|
|
473
|
+
borderRadius: "6px",
|
|
474
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
475
|
+
backgroundSize: "8px 8px",
|
|
476
|
+
cursor: disabled ? "default" : "pointer",
|
|
477
|
+
touchAction: "none",
|
|
478
|
+
outline: "none",
|
|
479
|
+
overflow: "hidden"
|
|
480
|
+
},
|
|
481
|
+
children: [
|
|
482
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
483
|
+
"div",
|
|
484
|
+
{
|
|
485
|
+
style: {
|
|
486
|
+
position: "absolute",
|
|
487
|
+
inset: 0,
|
|
488
|
+
background: (0, import_color.pickerAlphaBackground)(pickerState)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
),
|
|
492
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
493
|
+
"div",
|
|
494
|
+
{
|
|
495
|
+
style: {
|
|
496
|
+
position: "absolute",
|
|
497
|
+
top: "50%",
|
|
498
|
+
transform: "translate(-50%, -50%)",
|
|
499
|
+
left: `${pickerState.alpha * 100}%`,
|
|
500
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
501
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
502
|
+
borderRadius: "50%",
|
|
503
|
+
border: "2px solid #ffffff",
|
|
504
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
505
|
+
pointerEvents: "none",
|
|
506
|
+
backgroundColor: currentHex
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
)
|
|
510
|
+
]
|
|
511
|
+
}
|
|
512
|
+
),
|
|
513
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
|
|
514
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
515
|
+
"div",
|
|
516
|
+
{
|
|
517
|
+
style: {
|
|
518
|
+
position: "relative",
|
|
519
|
+
width: "28px",
|
|
520
|
+
height: "28px",
|
|
521
|
+
borderRadius: "4px",
|
|
522
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
523
|
+
backgroundSize: "8px 8px",
|
|
524
|
+
overflow: "hidden",
|
|
525
|
+
flexShrink: 0,
|
|
526
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
527
|
+
},
|
|
528
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
529
|
+
"div",
|
|
530
|
+
{
|
|
531
|
+
style: {
|
|
532
|
+
width: "100%",
|
|
533
|
+
height: "100%",
|
|
534
|
+
backgroundColor: currentHex
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
),
|
|
540
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
541
|
+
"input",
|
|
542
|
+
{
|
|
543
|
+
type: "text",
|
|
544
|
+
value: textDraft,
|
|
545
|
+
disabled,
|
|
546
|
+
"aria-label": "Color hex or CSS string",
|
|
547
|
+
"aria-invalid": isInvalid ? "true" : void 0,
|
|
548
|
+
onChange: (e) => {
|
|
549
|
+
isTypingRef.current = true;
|
|
550
|
+
setTextDraft(e.target.value);
|
|
551
|
+
setIsInvalid(false);
|
|
552
|
+
},
|
|
553
|
+
onKeyDown: handleTextKeyDown,
|
|
554
|
+
onBlur: (e) => commitTextInput(e.currentTarget),
|
|
555
|
+
style: {
|
|
556
|
+
flex: 1,
|
|
557
|
+
minWidth: 0,
|
|
558
|
+
height: "28px",
|
|
559
|
+
padding: "0 8px",
|
|
560
|
+
fontSize: "12px",
|
|
561
|
+
fontFamily: "monospace",
|
|
562
|
+
borderRadius: "4px",
|
|
563
|
+
border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
|
|
564
|
+
background: "rgba(0,0,0,0.2)",
|
|
565
|
+
color: "inherit",
|
|
566
|
+
outline: "none"
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
),
|
|
570
|
+
hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
571
|
+
"button",
|
|
572
|
+
{
|
|
573
|
+
type: "button",
|
|
574
|
+
disabled,
|
|
575
|
+
"aria-label": "Pick color from screen",
|
|
576
|
+
title: "Pick color from screen",
|
|
577
|
+
onClick: handleEyeDropper,
|
|
578
|
+
style: {
|
|
579
|
+
display: "inline-flex",
|
|
580
|
+
alignItems: "center",
|
|
581
|
+
justifyContent: "center",
|
|
582
|
+
width: "28px",
|
|
583
|
+
height: "28px",
|
|
584
|
+
borderRadius: "4px",
|
|
585
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
586
|
+
background: "transparent",
|
|
587
|
+
color: "inherit",
|
|
588
|
+
cursor: disabled ? "default" : "pointer"
|
|
589
|
+
},
|
|
590
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
591
|
+
"svg",
|
|
592
|
+
{
|
|
593
|
+
width: "14",
|
|
594
|
+
height: "14",
|
|
595
|
+
viewBox: "0 0 24 24",
|
|
596
|
+
fill: "none",
|
|
597
|
+
stroke: "currentColor",
|
|
598
|
+
strokeWidth: "2",
|
|
599
|
+
strokeLinecap: "round",
|
|
600
|
+
strokeLinejoin: "round",
|
|
601
|
+
children: [
|
|
602
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m19 11-8-8-8.5 8.5a2.12 2.12 0 0 0 0 3l2.5 2.5 1.5-1.5" }),
|
|
603
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
|
|
604
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m14 6 4 4" })
|
|
605
|
+
]
|
|
606
|
+
}
|
|
607
|
+
)
|
|
608
|
+
}
|
|
609
|
+
)
|
|
610
|
+
] }),
|
|
611
|
+
isClipped && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
612
|
+
"div",
|
|
613
|
+
{
|
|
614
|
+
role: "note",
|
|
615
|
+
title: "This colour was outside standard sRGB and clipped.",
|
|
616
|
+
style: {
|
|
617
|
+
display: "inline-flex",
|
|
618
|
+
alignItems: "center",
|
|
619
|
+
gap: "4px",
|
|
620
|
+
fontSize: "10px",
|
|
621
|
+
color: "#f59e0b",
|
|
622
|
+
background: "rgba(245, 158, 11, 0.1)",
|
|
623
|
+
padding: "2px 6px",
|
|
624
|
+
borderRadius: "4px",
|
|
625
|
+
alignSelf: "flex-start"
|
|
626
|
+
},
|
|
627
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
|
|
628
|
+
}
|
|
629
|
+
),
|
|
630
|
+
contrastResult && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
631
|
+
"div",
|
|
632
|
+
{
|
|
633
|
+
style: {
|
|
634
|
+
display: "flex",
|
|
635
|
+
alignItems: "center",
|
|
636
|
+
justifyContent: "space-between",
|
|
637
|
+
fontSize: "11px",
|
|
638
|
+
padding: "4px 8px",
|
|
639
|
+
borderRadius: "4px",
|
|
640
|
+
background: "rgba(255,255,255,0.05)",
|
|
641
|
+
border: "1px solid rgba(255,255,255,0.1)"
|
|
642
|
+
},
|
|
643
|
+
children: [
|
|
644
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
645
|
+
"Contrast: ",
|
|
646
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("strong", { children: [
|
|
647
|
+
contrastResult.ratio.toFixed(2),
|
|
648
|
+
":1"
|
|
649
|
+
] })
|
|
650
|
+
] }),
|
|
651
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
652
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
653
|
+
"span",
|
|
654
|
+
{
|
|
655
|
+
style: {
|
|
656
|
+
color: contrastResult.aa ? "#10b981" : "#ef4444",
|
|
657
|
+
fontWeight: 600
|
|
658
|
+
},
|
|
659
|
+
children: [
|
|
660
|
+
"AA ",
|
|
661
|
+
contrastResult.aa ? "\u2713" : "\u2717"
|
|
662
|
+
]
|
|
663
|
+
}
|
|
664
|
+
),
|
|
665
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
666
|
+
"span",
|
|
667
|
+
{
|
|
668
|
+
style: {
|
|
669
|
+
color: contrastResult.aaa ? "#10b981" : "#ef4444",
|
|
670
|
+
fontWeight: 600
|
|
671
|
+
},
|
|
672
|
+
children: [
|
|
673
|
+
"AAA ",
|
|
674
|
+
contrastResult.aaa ? "\u2713" : "\u2717"
|
|
675
|
+
]
|
|
676
|
+
}
|
|
677
|
+
)
|
|
678
|
+
] })
|
|
679
|
+
]
|
|
680
|
+
}
|
|
681
|
+
),
|
|
682
|
+
swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
|
|
684
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
685
|
+
"button",
|
|
686
|
+
{
|
|
687
|
+
type: "button",
|
|
688
|
+
"data-testid": "color-picker-swatch",
|
|
689
|
+
title: color,
|
|
690
|
+
disabled,
|
|
691
|
+
"aria-label": `Color ${color}`,
|
|
692
|
+
onClick: () => {
|
|
693
|
+
onChange(color);
|
|
694
|
+
recordRecent(color);
|
|
695
|
+
},
|
|
696
|
+
style: {
|
|
697
|
+
width: "18px",
|
|
698
|
+
height: "18px",
|
|
699
|
+
borderRadius: "3px",
|
|
700
|
+
backgroundColor: color,
|
|
701
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
702
|
+
cursor: disabled ? "default" : "pointer",
|
|
703
|
+
padding: 0,
|
|
704
|
+
outline: "none"
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
`${color}-${idx}`
|
|
708
|
+
)) })
|
|
709
|
+
] }),
|
|
710
|
+
activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
711
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
|
|
712
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
713
|
+
"button",
|
|
714
|
+
{
|
|
715
|
+
type: "button",
|
|
716
|
+
"data-testid": "color-picker-recent",
|
|
717
|
+
disabled,
|
|
718
|
+
"aria-label": `Color ${color}`,
|
|
719
|
+
onClick: () => {
|
|
720
|
+
onChange(color);
|
|
721
|
+
recordRecent(color);
|
|
722
|
+
},
|
|
723
|
+
style: {
|
|
724
|
+
width: "18px",
|
|
725
|
+
height: "18px",
|
|
726
|
+
borderRadius: "3px",
|
|
727
|
+
backgroundColor: color,
|
|
728
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
729
|
+
cursor: disabled ? "default" : "pointer",
|
|
730
|
+
padding: 0,
|
|
731
|
+
outline: "none"
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
`recent-${color}-${idx}`
|
|
735
|
+
)) })
|
|
736
|
+
] })
|
|
737
|
+
]
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// src/color/DualColorPicker.tsx
|
|
743
|
+
var import_react3 = require("react");
|
|
744
|
+
var import_color2 = require("@pixerate/editor/color");
|
|
745
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
746
|
+
function DualColorPicker({
|
|
747
|
+
value,
|
|
748
|
+
onChange,
|
|
749
|
+
onGestureStart,
|
|
750
|
+
onGestureEnd,
|
|
751
|
+
scheme: controlledScheme,
|
|
752
|
+
onSchemeChange,
|
|
753
|
+
surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
|
|
754
|
+
contrastAgainst,
|
|
755
|
+
alpha = false,
|
|
756
|
+
swatches,
|
|
757
|
+
disabled = false,
|
|
758
|
+
className = ""
|
|
759
|
+
}) {
|
|
760
|
+
const sameId = (0, import_react3.useId)();
|
|
761
|
+
const [internalScheme, setInternalScheme] = (0, import_react3.useState)("light");
|
|
762
|
+
const activeScheme = controlledScheme ?? internalScheme;
|
|
763
|
+
const handleSchemeSelect = (nextScheme) => {
|
|
764
|
+
if (onSchemeChange) {
|
|
765
|
+
onSchemeChange(nextScheme);
|
|
766
|
+
} else {
|
|
767
|
+
setInternalScheme(nextScheme);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
|
|
771
|
+
const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
|
|
772
|
+
const [sameInBoth, setSameInBoth] = (0, import_react3.useState)(isSame);
|
|
773
|
+
const handleSameToggle = (e) => {
|
|
774
|
+
const nextSame = e.target.checked;
|
|
775
|
+
setSameInBoth(nextSame);
|
|
776
|
+
if (nextSame) {
|
|
777
|
+
const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
|
|
778
|
+
onChange({ light: activeVal, dark: activeVal });
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
const handleDerive = () => {
|
|
782
|
+
if (disabled) return;
|
|
783
|
+
onGestureStart?.();
|
|
784
|
+
const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
|
|
785
|
+
const derived = (0, import_color2.deriveDualColor)(currentActive, {
|
|
786
|
+
from: activeScheme,
|
|
787
|
+
// An unreadable surfaces prop falls back to the defaults rather than throwing.
|
|
788
|
+
surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
|
|
789
|
+
});
|
|
790
|
+
onChange(derived);
|
|
791
|
+
onGestureEnd?.();
|
|
792
|
+
};
|
|
793
|
+
const handleInnerChange = (hex) => {
|
|
794
|
+
if (sameInBoth) {
|
|
795
|
+
onChange({ light: hex, dark: hex });
|
|
796
|
+
} else {
|
|
797
|
+
const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
|
|
798
|
+
onChange(updated);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
|
|
802
|
+
const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
|
|
803
|
+
const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
|
|
804
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
805
|
+
"div",
|
|
806
|
+
{
|
|
807
|
+
className: `pixerate-dual-color-picker ${className}`,
|
|
808
|
+
style: {
|
|
809
|
+
display: "flex",
|
|
810
|
+
flexDirection: "column",
|
|
811
|
+
gap: "12px",
|
|
812
|
+
padding: "12px",
|
|
813
|
+
background: "#1a1d24",
|
|
814
|
+
color: "#e2e8f0",
|
|
815
|
+
borderRadius: "10px",
|
|
816
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
817
|
+
width: "260px",
|
|
818
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
819
|
+
fontSize: "13px",
|
|
820
|
+
boxSizing: "border-box"
|
|
821
|
+
},
|
|
822
|
+
children: [
|
|
823
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
824
|
+
"div",
|
|
825
|
+
{
|
|
826
|
+
role: "tablist",
|
|
827
|
+
"aria-label": "Color scheme mode",
|
|
828
|
+
style: {
|
|
829
|
+
display: "flex",
|
|
830
|
+
background: "#111318",
|
|
831
|
+
borderRadius: "6px",
|
|
832
|
+
padding: "2px",
|
|
833
|
+
gap: "2px"
|
|
834
|
+
},
|
|
835
|
+
children: [
|
|
836
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
837
|
+
"button",
|
|
838
|
+
{
|
|
839
|
+
type: "button",
|
|
840
|
+
role: "tab",
|
|
841
|
+
"aria-selected": activeScheme === "light",
|
|
842
|
+
onClick: () => handleSchemeSelect("light"),
|
|
843
|
+
disabled,
|
|
844
|
+
style: {
|
|
845
|
+
flex: 1,
|
|
846
|
+
padding: "6px 8px",
|
|
847
|
+
border: "none",
|
|
848
|
+
borderRadius: "4px",
|
|
849
|
+
background: activeScheme === "light" ? "#2d3342" : "transparent",
|
|
850
|
+
color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
|
|
851
|
+
fontWeight: activeScheme === "light" ? 600 : 400,
|
|
852
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
853
|
+
fontSize: "12px",
|
|
854
|
+
transition: "all 0.15s ease"
|
|
855
|
+
},
|
|
856
|
+
children: "Light"
|
|
857
|
+
}
|
|
858
|
+
),
|
|
859
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
860
|
+
"button",
|
|
861
|
+
{
|
|
862
|
+
type: "button",
|
|
863
|
+
role: "tab",
|
|
864
|
+
"aria-selected": activeScheme === "dark",
|
|
865
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
866
|
+
disabled,
|
|
867
|
+
style: {
|
|
868
|
+
flex: 1,
|
|
869
|
+
padding: "6px 8px",
|
|
870
|
+
border: "none",
|
|
871
|
+
borderRadius: "4px",
|
|
872
|
+
background: activeScheme === "dark" ? "#2d3342" : "transparent",
|
|
873
|
+
color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
|
|
874
|
+
fontWeight: activeScheme === "dark" ? 600 : 400,
|
|
875
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
876
|
+
fontSize: "12px",
|
|
877
|
+
transition: "all 0.15s ease"
|
|
878
|
+
},
|
|
879
|
+
children: "Dark"
|
|
880
|
+
}
|
|
881
|
+
)
|
|
882
|
+
]
|
|
883
|
+
}
|
|
884
|
+
),
|
|
885
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
886
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
887
|
+
"button",
|
|
888
|
+
{
|
|
889
|
+
type: "button",
|
|
890
|
+
onClick: () => handleSchemeSelect("light"),
|
|
891
|
+
disabled,
|
|
892
|
+
title: "Edit light mode colour",
|
|
893
|
+
style: {
|
|
894
|
+
flex: 1,
|
|
895
|
+
display: "flex",
|
|
896
|
+
flexDirection: "column",
|
|
897
|
+
alignItems: "center",
|
|
898
|
+
gap: "6px",
|
|
899
|
+
padding: "8px",
|
|
900
|
+
background: surfaces.light,
|
|
901
|
+
color: "#000000",
|
|
902
|
+
border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
903
|
+
borderRadius: "6px",
|
|
904
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
905
|
+
outline: "none"
|
|
906
|
+
},
|
|
907
|
+
children: [
|
|
908
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
909
|
+
"span",
|
|
910
|
+
{
|
|
911
|
+
style: {
|
|
912
|
+
width: "100%",
|
|
913
|
+
height: "24px",
|
|
914
|
+
borderRadius: "4px",
|
|
915
|
+
background: dual.light,
|
|
916
|
+
border: "1px solid rgba(0,0,0,0.15)"
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
),
|
|
920
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
|
|
921
|
+
]
|
|
922
|
+
}
|
|
923
|
+
),
|
|
924
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
925
|
+
"button",
|
|
926
|
+
{
|
|
927
|
+
type: "button",
|
|
928
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
929
|
+
disabled,
|
|
930
|
+
title: "Edit dark mode colour",
|
|
931
|
+
style: {
|
|
932
|
+
flex: 1,
|
|
933
|
+
display: "flex",
|
|
934
|
+
flexDirection: "column",
|
|
935
|
+
alignItems: "center",
|
|
936
|
+
gap: "6px",
|
|
937
|
+
padding: "8px",
|
|
938
|
+
background: surfaces.dark,
|
|
939
|
+
color: "#ffffff",
|
|
940
|
+
border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
941
|
+
borderRadius: "6px",
|
|
942
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
943
|
+
outline: "none"
|
|
944
|
+
},
|
|
945
|
+
children: [
|
|
946
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
947
|
+
"span",
|
|
948
|
+
{
|
|
949
|
+
style: {
|
|
950
|
+
width: "100%",
|
|
951
|
+
height: "24px",
|
|
952
|
+
borderRadius: "4px",
|
|
953
|
+
background: dual.dark,
|
|
954
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
),
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
|
|
959
|
+
]
|
|
960
|
+
}
|
|
961
|
+
)
|
|
962
|
+
] }),
|
|
963
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
964
|
+
"div",
|
|
965
|
+
{
|
|
966
|
+
style: {
|
|
967
|
+
display: "flex",
|
|
968
|
+
alignItems: "center",
|
|
969
|
+
justifyContent: "space-between",
|
|
970
|
+
gap: "8px",
|
|
971
|
+
padding: "2px 0"
|
|
972
|
+
},
|
|
973
|
+
children: [
|
|
974
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
975
|
+
"label",
|
|
976
|
+
{
|
|
977
|
+
htmlFor: sameId,
|
|
978
|
+
style: {
|
|
979
|
+
display: "flex",
|
|
980
|
+
alignItems: "center",
|
|
981
|
+
gap: "6px",
|
|
982
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
983
|
+
userSelect: "none",
|
|
984
|
+
fontSize: "12px",
|
|
985
|
+
color: "#c4cad4"
|
|
986
|
+
},
|
|
987
|
+
children: [
|
|
988
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
989
|
+
"input",
|
|
990
|
+
{
|
|
991
|
+
id: sameId,
|
|
992
|
+
type: "checkbox",
|
|
993
|
+
checked: sameInBoth,
|
|
994
|
+
onChange: handleSameToggle,
|
|
995
|
+
disabled,
|
|
996
|
+
style: { cursor: disabled ? "not-allowed" : "pointer" }
|
|
997
|
+
}
|
|
998
|
+
),
|
|
999
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Same in both" })
|
|
1000
|
+
]
|
|
1001
|
+
}
|
|
1002
|
+
),
|
|
1003
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1004
|
+
"button",
|
|
1005
|
+
{
|
|
1006
|
+
type: "button",
|
|
1007
|
+
onClick: handleDerive,
|
|
1008
|
+
disabled,
|
|
1009
|
+
style: {
|
|
1010
|
+
padding: "4px 10px",
|
|
1011
|
+
background: "#2d3342",
|
|
1012
|
+
color: "#e2e8f0",
|
|
1013
|
+
border: "1px solid #3b4252",
|
|
1014
|
+
borderRadius: "4px",
|
|
1015
|
+
fontSize: "11px",
|
|
1016
|
+
fontWeight: 500,
|
|
1017
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
1018
|
+
},
|
|
1019
|
+
children: "Derive"
|
|
1020
|
+
}
|
|
1021
|
+
)
|
|
1022
|
+
]
|
|
1023
|
+
}
|
|
1024
|
+
),
|
|
1025
|
+
dualContrast && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1026
|
+
"div",
|
|
1027
|
+
{
|
|
1028
|
+
"data-testid": "dual-contrast-summary",
|
|
1029
|
+
style: {
|
|
1030
|
+
display: "flex",
|
|
1031
|
+
justifyContent: "space-between",
|
|
1032
|
+
background: "#111318",
|
|
1033
|
+
padding: "6px 8px",
|
|
1034
|
+
borderRadius: "6px",
|
|
1035
|
+
fontSize: "11px",
|
|
1036
|
+
color: "#8c95a6"
|
|
1037
|
+
},
|
|
1038
|
+
children: [
|
|
1039
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
1040
|
+
"Light:",
|
|
1041
|
+
" ",
|
|
1042
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
1043
|
+
dualContrast.light.ratio.toFixed(2),
|
|
1044
|
+
" (",
|
|
1045
|
+
dualContrast.light.level,
|
|
1046
|
+
")"
|
|
1047
|
+
] })
|
|
1048
|
+
] }),
|
|
1049
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
|
|
1050
|
+
"Dark:",
|
|
1051
|
+
" ",
|
|
1052
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
1053
|
+
dualContrast.dark.ratio.toFixed(2),
|
|
1054
|
+
" (",
|
|
1055
|
+
dualContrast.dark.level,
|
|
1056
|
+
")"
|
|
1057
|
+
] })
|
|
1058
|
+
] })
|
|
1059
|
+
]
|
|
1060
|
+
}
|
|
1061
|
+
),
|
|
1062
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1063
|
+
ColorPicker,
|
|
1064
|
+
{
|
|
1065
|
+
value: activeColor,
|
|
1066
|
+
onChange: handleInnerChange,
|
|
1067
|
+
onGestureStart,
|
|
1068
|
+
onGestureEnd,
|
|
1069
|
+
contrastAgainst: activeContrastTarget,
|
|
1070
|
+
alpha,
|
|
1071
|
+
swatches,
|
|
1072
|
+
disabled
|
|
1073
|
+
}
|
|
1074
|
+
)
|
|
1075
|
+
]
|
|
1076
|
+
}
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// src/color/useColorScheme.ts
|
|
1081
|
+
var import_react4 = require("react");
|
|
1082
|
+
var import_color3 = require("@pixerate/editor/color");
|
|
1083
|
+
function getSnapshot(attribute) {
|
|
1084
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1085
|
+
return "light";
|
|
1086
|
+
}
|
|
1087
|
+
if (attribute) {
|
|
1088
|
+
const el = document.documentElement;
|
|
1089
|
+
if (attribute === "class") {
|
|
1090
|
+
return el.classList.contains("dark") ? "dark" : "light";
|
|
1091
|
+
}
|
|
1092
|
+
const val = el.getAttribute(attribute);
|
|
1093
|
+
return val === "dark" ? "dark" : "light";
|
|
1094
|
+
}
|
|
1095
|
+
if (typeof window.matchMedia === "function") {
|
|
1096
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1097
|
+
}
|
|
1098
|
+
return "light";
|
|
1099
|
+
}
|
|
1100
|
+
function getServerSnapshot() {
|
|
1101
|
+
return "light";
|
|
1102
|
+
}
|
|
1103
|
+
function useColorScheme(options) {
|
|
1104
|
+
const override = options?.override;
|
|
1105
|
+
const attribute = options?.attribute;
|
|
1106
|
+
const subscribe = (0, import_react4.useMemo)(() => {
|
|
1107
|
+
return (callback) => {
|
|
1108
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
1109
|
+
return () => {
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
if (attribute) {
|
|
1113
|
+
const observer = new MutationObserver(() => {
|
|
1114
|
+
callback();
|
|
1115
|
+
});
|
|
1116
|
+
observer.observe(document.documentElement, {
|
|
1117
|
+
attributes: true,
|
|
1118
|
+
attributeFilter: [attribute]
|
|
1119
|
+
});
|
|
1120
|
+
return () => observer.disconnect();
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof window.matchMedia === "function") {
|
|
1123
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1124
|
+
const handler = () => callback();
|
|
1125
|
+
mql.addEventListener("change", handler);
|
|
1126
|
+
return () => mql.removeEventListener("change", handler);
|
|
1127
|
+
}
|
|
1128
|
+
return () => {
|
|
1129
|
+
};
|
|
1130
|
+
};
|
|
1131
|
+
}, [attribute]);
|
|
1132
|
+
const detected = (0, import_react4.useSyncExternalStore)(
|
|
1133
|
+
subscribe,
|
|
1134
|
+
() => getSnapshot(attribute),
|
|
1135
|
+
getServerSnapshot
|
|
1136
|
+
);
|
|
1137
|
+
return override ?? detected;
|
|
1138
|
+
}
|
|
1139
|
+
function useResolvedColor(value, scheme) {
|
|
1140
|
+
const detectedScheme = useColorScheme();
|
|
1141
|
+
const activeScheme = scheme ?? detectedScheme;
|
|
1142
|
+
return (0, import_color3.resolveColor)(value, activeScheme);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/color/index.ts
|
|
1146
|
+
__reExport(color_exports, require("@pixerate/editor/color"));
|
|
1147
|
+
|
|
1148
|
+
// src/parameters/fields.tsx
|
|
1149
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
108
1150
|
var parameterInputClass = "h-7 w-full min-w-0 rounded-md border border-input bg-background px-2 text-xs text-foreground tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
109
1151
|
var parameterButtonClass = "inline-flex h-7 items-center justify-center gap-1 rounded-md border border-input bg-background px-2 text-xs text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";
|
|
110
1152
|
var rangeClass = "h-4 w-full min-w-0 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
@@ -128,7 +1170,7 @@ function ParameterCommitInput({ value, onCommit, multiline, className, onKeyDown
|
|
|
128
1170
|
onKeyDown: keyDown,
|
|
129
1171
|
...rest
|
|
130
1172
|
};
|
|
131
|
-
return multiline ? /* @__PURE__ */ (0,
|
|
1173
|
+
return multiline ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "text", ...props }, value);
|
|
132
1174
|
}
|
|
133
1175
|
var plainNumber = (field, value) => (0, import_parameters2.formatParameterNumber)({ ...field, unit: void 0 }, value);
|
|
134
1176
|
function ParameterNumberInput({
|
|
@@ -139,8 +1181,8 @@ function ParameterNumberInput({
|
|
|
139
1181
|
id,
|
|
140
1182
|
"aria-label": ariaLabel
|
|
141
1183
|
}) {
|
|
142
|
-
return /* @__PURE__ */ (0,
|
|
143
|
-
/* @__PURE__ */ (0,
|
|
1184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
144
1186
|
ParameterCommitInput,
|
|
145
1187
|
{
|
|
146
1188
|
id,
|
|
@@ -162,21 +1204,21 @@ function ParameterNumberInput({
|
|
|
162
1204
|
}
|
|
163
1205
|
}
|
|
164
1206
|
),
|
|
165
|
-
field.unit && /* @__PURE__ */ (0,
|
|
1207
|
+
field.unit && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
|
|
166
1208
|
] });
|
|
167
1209
|
}
|
|
168
1210
|
function ParameterSlider(props) {
|
|
169
1211
|
const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
|
|
170
|
-
const dragging = (0,
|
|
1212
|
+
const dragging = (0, import_react5.useRef)(false);
|
|
171
1213
|
const end = () => {
|
|
172
1214
|
if (!dragging.current) return;
|
|
173
1215
|
dragging.current = false;
|
|
174
1216
|
onGestureEnd?.();
|
|
175
1217
|
};
|
|
176
|
-
if (!(0, import_parameters2.isSliderField)(field)) return /* @__PURE__ */ (0,
|
|
1218
|
+
if (!(0, import_parameters2.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterNumberInput, { ...props });
|
|
177
1219
|
const step = (0, import_parameters2.parameterStep)(field);
|
|
178
|
-
return /* @__PURE__ */ (0,
|
|
179
|
-
/* @__PURE__ */ (0,
|
|
1220
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
1221
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
180
1222
|
"input",
|
|
181
1223
|
{
|
|
182
1224
|
type: "range",
|
|
@@ -199,11 +1241,11 @@ function ParameterSlider(props) {
|
|
|
199
1241
|
onChange: (e) => onChange((0, import_parameters2.clampParameterNumber)(field, Number(e.target.value)))
|
|
200
1242
|
}
|
|
201
1243
|
),
|
|
202
|
-
/* @__PURE__ */ (0,
|
|
1244
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters2.parameterLabel)(field)} value` }) })
|
|
203
1245
|
] });
|
|
204
1246
|
}
|
|
205
1247
|
function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
206
|
-
return /* @__PURE__ */ (0,
|
|
1248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
207
1249
|
"button",
|
|
208
1250
|
{
|
|
209
1251
|
type: "button",
|
|
@@ -214,7 +1256,7 @@ function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
|
214
1256
|
disabled: disabled || field.readOnly,
|
|
215
1257
|
onClick: () => onChange(!value),
|
|
216
1258
|
className: `relative inline-flex h-5 w-9 shrink-0 items-center rounded-full border border-transparent transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:opacity-50 ${value ? "bg-primary" : "bg-muted"}`,
|
|
217
|
-
children: /* @__PURE__ */ (0,
|
|
1259
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
218
1260
|
"span",
|
|
219
1261
|
{
|
|
220
1262
|
className: `pointer-events-none block h-4 w-4 rounded-full bg-background shadow transition-transform ${value ? "translate-x-4" : "translate-x-0.5"}`
|
|
@@ -227,7 +1269,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
227
1269
|
const options = (0, import_parameters2.getChoiceOptions)(field);
|
|
228
1270
|
const off = disabled || field.readOnly;
|
|
229
1271
|
if (field.control === "segmented") {
|
|
230
|
-
return /* @__PURE__ */ (0,
|
|
1272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { role: "radiogroup", "aria-label": (0, import_parameters2.parameterLabel)(field), className: "inline-flex flex-wrap rounded-md border border-input bg-muted p-0.5", children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
231
1273
|
"button",
|
|
232
1274
|
{
|
|
233
1275
|
type: "button",
|
|
@@ -243,7 +1285,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
243
1285
|
)) });
|
|
244
1286
|
}
|
|
245
1287
|
const index = options.findIndex((o) => o.value === value);
|
|
246
|
-
return /* @__PURE__ */ (0,
|
|
1288
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
247
1289
|
"select",
|
|
248
1290
|
{
|
|
249
1291
|
id,
|
|
@@ -255,53 +1297,64 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
255
1297
|
if (option) onChange(option.value);
|
|
256
1298
|
},
|
|
257
1299
|
className: parameterInputClass,
|
|
258
|
-
children: options.map((o, i) => /* @__PURE__ */ (0,
|
|
1300
|
+
children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters2.choiceOptionLabel)(o) }, String(o.value)))
|
|
259
1301
|
}
|
|
260
1302
|
);
|
|
261
1303
|
}
|
|
262
1304
|
function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
|
|
263
|
-
const
|
|
1305
|
+
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
1306
|
+
const containerRef = (0, import_react5.useRef)(null);
|
|
1307
|
+
const buttonRef = (0, import_react5.useRef)(null);
|
|
1308
|
+
const popoverRef = (0, import_react5.useRef)(null);
|
|
264
1309
|
const alpha = !!field.alpha;
|
|
265
1310
|
const hex = (0, import_parameters2.normalizeHexColor)(value, true) ?? "#000000ff";
|
|
266
1311
|
const rgb = hex.slice(0, 7);
|
|
267
|
-
const
|
|
1312
|
+
const shown = alpha ? hex : rgb;
|
|
268
1313
|
const off = disabled || field.readOnly;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
1314
|
+
const name = (0, import_parameters2.parameterLabel)(field);
|
|
1315
|
+
(0, import_react5.useEffect)(() => {
|
|
1316
|
+
if (!open) return;
|
|
1317
|
+
const onPointerDown = (e) => {
|
|
1318
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
1319
|
+
setOpen(false);
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
const onKeyDown = (e) => {
|
|
1323
|
+
if (e.key === "Escape") {
|
|
1324
|
+
e.stopPropagation();
|
|
1325
|
+
setOpen(false);
|
|
1326
|
+
buttonRef.current?.focus();
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
window.addEventListener("pointerdown", onPointerDown, true);
|
|
1330
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
1331
|
+
return () => {
|
|
1332
|
+
window.removeEventListener("pointerdown", onPointerDown, true);
|
|
1333
|
+
window.removeEventListener("keydown", onKeyDown, true);
|
|
1334
|
+
};
|
|
1335
|
+
}, [open]);
|
|
1336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { ref: containerRef, className: "relative space-y-1.5", children: [
|
|
1337
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
1338
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1339
|
+
"button",
|
|
1340
|
+
{
|
|
1341
|
+
ref: buttonRef,
|
|
1342
|
+
type: "button",
|
|
1343
|
+
"aria-label": name,
|
|
1344
|
+
"aria-expanded": open,
|
|
1345
|
+
"aria-haspopup": "dialog",
|
|
1346
|
+
disabled: off,
|
|
1347
|
+
onClick: () => setOpen((prev) => !prev),
|
|
1348
|
+
className: "relative h-7 w-9 shrink-0 overflow-hidden rounded-md border border-input bg-[repeating-conic-gradient(#d4d4d8_0_25%,#fff_0_50%)] bg-[length:8px_8px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50",
|
|
1349
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "absolute inset-0", style: { background: shown } })
|
|
1350
|
+
}
|
|
1351
|
+
),
|
|
1352
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
300
1353
|
ParameterCommitInput,
|
|
301
1354
|
{
|
|
302
1355
|
id,
|
|
303
|
-
"aria-label": `${
|
|
304
|
-
value:
|
|
1356
|
+
"aria-label": `${name} hex`,
|
|
1357
|
+
value: shown,
|
|
305
1358
|
disabled: off,
|
|
306
1359
|
spellCheck: false,
|
|
307
1360
|
className: `${parameterInputClass} font-mono`,
|
|
@@ -312,51 +1365,43 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
|
|
|
312
1365
|
}
|
|
313
1366
|
)
|
|
314
1367
|
] }),
|
|
315
|
-
|
|
316
|
-
"
|
|
1368
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1369
|
+
"div",
|
|
317
1370
|
{
|
|
318
|
-
|
|
319
|
-
"
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
onPointerDown: start,
|
|
327
|
-
onPointerUp: end,
|
|
328
|
-
onPointerCancel: end,
|
|
329
|
-
onBlur: end,
|
|
330
|
-
onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
|
|
331
|
-
}
|
|
332
|
-
),
|
|
333
|
-
field.swatches && field.swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
|
|
334
|
-
const swatch = (0, import_parameters2.normalizeHexColor)(s, alpha);
|
|
335
|
-
if (!swatch) return null;
|
|
336
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
337
|
-
"button",
|
|
338
|
-
{
|
|
339
|
-
type: "button",
|
|
340
|
-
title: swatch,
|
|
341
|
-
"aria-label": `${(0, import_parameters2.parameterLabel)(field)} ${swatch}`,
|
|
342
|
-
"aria-pressed": swatch === (alpha ? hex : rgb),
|
|
343
|
-
disabled: off,
|
|
344
|
-
onClick: () => onChange(swatch),
|
|
345
|
-
className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
|
|
346
|
-
style: { background: swatch }
|
|
1371
|
+
ref: popoverRef,
|
|
1372
|
+
role: "dialog",
|
|
1373
|
+
"aria-label": name,
|
|
1374
|
+
tabIndex: -1,
|
|
1375
|
+
onBlur: (e) => {
|
|
1376
|
+
if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
|
|
1377
|
+
setOpen(false);
|
|
1378
|
+
}
|
|
347
1379
|
},
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
1380
|
+
className: "absolute left-0 top-full z-50 mt-1 w-64 rounded-lg border border-border bg-popover p-2 text-popover-foreground shadow-xl",
|
|
1381
|
+
style: { background: "var(--popover, var(--background, #fff))" },
|
|
1382
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1383
|
+
ColorPicker,
|
|
1384
|
+
{
|
|
1385
|
+
value: shown,
|
|
1386
|
+
alpha,
|
|
1387
|
+
swatches: field.swatches,
|
|
1388
|
+
disabled: off,
|
|
1389
|
+
onChange,
|
|
1390
|
+
onGestureStart,
|
|
1391
|
+
onGestureEnd
|
|
1392
|
+
}
|
|
1393
|
+
)
|
|
1394
|
+
}
|
|
1395
|
+
)
|
|
351
1396
|
] });
|
|
352
1397
|
}
|
|
353
1398
|
function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
354
1399
|
const size = (0, import_parameters2.vectorSize)(field);
|
|
355
|
-
return /* @__PURE__ */ (0,
|
|
1400
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
|
|
356
1401
|
const component = (0, import_parameters2.vectorComponentField)(field, i);
|
|
357
|
-
return /* @__PURE__ */ (0,
|
|
358
|
-
/* @__PURE__ */ (0,
|
|
359
|
-
/* @__PURE__ */ (0,
|
|
1402
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
|
|
1403
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
|
|
1404
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
360
1405
|
ParameterNumberInput,
|
|
361
1406
|
{
|
|
362
1407
|
field: component,
|
|
@@ -373,11 +1418,11 @@ function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
|
373
1418
|
function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
374
1419
|
const off = disabled || field.readOnly;
|
|
375
1420
|
const name = (0, import_parameters2.parameterLabel)(field);
|
|
376
|
-
return /* @__PURE__ */ (0,
|
|
377
|
-
/* @__PURE__ */ (0,
|
|
378
|
-
/* @__PURE__ */ (0,
|
|
379
|
-
/* @__PURE__ */ (0,
|
|
380
|
-
/* @__PURE__ */ (0,
|
|
1421
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-1.5", children: [
|
|
1422
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
1423
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex h-12 w-16 shrink-0 items-center justify-center overflow-hidden rounded-md border border-input bg-muted", children: value ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
|
|
1424
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
1425
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
381
1426
|
ParameterCommitInput,
|
|
382
1427
|
{
|
|
383
1428
|
id,
|
|
@@ -388,10 +1433,10 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
388
1433
|
onCommit: (text) => onChange(text.trim())
|
|
389
1434
|
}
|
|
390
1435
|
),
|
|
391
|
-
/* @__PURE__ */ (0,
|
|
392
|
-
resolveFile && /* @__PURE__ */ (0,
|
|
1436
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex gap-1", children: [
|
|
1437
|
+
resolveFile && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
|
|
393
1438
|
"Choose file\u2026",
|
|
394
|
-
/* @__PURE__ */ (0,
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
395
1440
|
"input",
|
|
396
1441
|
{
|
|
397
1442
|
type: "file",
|
|
@@ -407,11 +1452,11 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
407
1452
|
}
|
|
408
1453
|
)
|
|
409
1454
|
] }),
|
|
410
|
-
value && /* @__PURE__ */ (0,
|
|
1455
|
+
value && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
|
|
411
1456
|
] })
|
|
412
1457
|
] })
|
|
413
1458
|
] }),
|
|
414
|
-
field.options && field.options.length > 0 && /* @__PURE__ */ (0,
|
|
1459
|
+
field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
415
1460
|
"button",
|
|
416
1461
|
{
|
|
417
1462
|
type: "button",
|
|
@@ -421,14 +1466,14 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
421
1466
|
disabled: off,
|
|
422
1467
|
onClick: () => onChange(o.url),
|
|
423
1468
|
className: "h-9 w-12 overflow-hidden rounded border border-input aria-pressed:ring-2 aria-pressed:ring-primary",
|
|
424
|
-
children: /* @__PURE__ */ (0,
|
|
1469
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
|
|
425
1470
|
},
|
|
426
1471
|
o.url
|
|
427
1472
|
)) })
|
|
428
1473
|
] });
|
|
429
1474
|
}
|
|
430
1475
|
function ParameterText({ field, value, onChange, disabled, id }) {
|
|
431
|
-
return /* @__PURE__ */ (0,
|
|
1476
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
432
1477
|
ParameterCommitInput,
|
|
433
1478
|
{
|
|
434
1479
|
id,
|
|
@@ -444,7 +1489,7 @@ function ParameterText({ field, value, onChange, disabled, id }) {
|
|
|
444
1489
|
}
|
|
445
1490
|
function KeyframeDiamond({ state, onToggle, label, disabled, className = "" }) {
|
|
446
1491
|
const keyed = state === "keyed";
|
|
447
|
-
return /* @__PURE__ */ (0,
|
|
1492
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
448
1493
|
"button",
|
|
449
1494
|
{
|
|
450
1495
|
type: "button",
|
|
@@ -455,7 +1500,7 @@ function KeyframeDiamond({ state, onToggle, label, disabled, className = "" }) {
|
|
|
455
1500
|
disabled,
|
|
456
1501
|
onClick: onToggle,
|
|
457
1502
|
className: `inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:opacity-40 ${state === "none" ? "text-muted-foreground hover:text-foreground" : "text-amber-500"} ${className}`,
|
|
458
|
-
children: /* @__PURE__ */ (0,
|
|
1503
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { viewBox: "0 0 10 10", className: "h-2.5 w-2.5", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
459
1504
|
"path",
|
|
460
1505
|
{
|
|
461
1506
|
d: "M5 0.8 9.2 5 5 9.2 0.8 5Z",
|
|
@@ -473,47 +1518,47 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
|
|
|
473
1518
|
switch (field.type) {
|
|
474
1519
|
case "number":
|
|
475
1520
|
case "int":
|
|
476
|
-
return /* @__PURE__ */ (0,
|
|
1521
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
|
|
477
1522
|
case "boolean":
|
|
478
|
-
return /* @__PURE__ */ (0,
|
|
1523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
|
|
479
1524
|
case "choice":
|
|
480
|
-
return /* @__PURE__ */ (0,
|
|
1525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
|
|
481
1526
|
case "color":
|
|
482
|
-
return /* @__PURE__ */ (0,
|
|
1527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
|
|
483
1528
|
case "vector":
|
|
484
|
-
return /* @__PURE__ */ (0,
|
|
1529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
|
|
485
1530
|
case "image":
|
|
486
|
-
return /* @__PURE__ */ (0,
|
|
1531
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
|
|
487
1532
|
case "text":
|
|
488
|
-
return /* @__PURE__ */ (0,
|
|
1533
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterText, { field, value, onChange: set, ...rest });
|
|
489
1534
|
}
|
|
490
1535
|
}
|
|
491
1536
|
|
|
492
1537
|
// src/parameters/ParametersPanel.tsx
|
|
493
|
-
var
|
|
1538
|
+
var import_react10 = require("react");
|
|
494
1539
|
|
|
495
1540
|
// src/playback/AgentPlaybackContext.tsx
|
|
496
|
-
var
|
|
497
|
-
var
|
|
498
|
-
var AgentPlaybackContext = (0,
|
|
1541
|
+
var import_react6 = require("react");
|
|
1542
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1543
|
+
var AgentPlaybackContext = (0, import_react6.createContext)(null);
|
|
499
1544
|
function useAgentPlayback() {
|
|
500
|
-
return (0,
|
|
1545
|
+
return (0, import_react6.useContext)(AgentPlaybackContext);
|
|
501
1546
|
}
|
|
502
1547
|
|
|
503
1548
|
// src/playback/useElementPlaybackSurface.ts
|
|
504
|
-
var
|
|
1549
|
+
var import_react8 = require("react");
|
|
505
1550
|
|
|
506
1551
|
// src/playback/usePlaybackSurface.ts
|
|
507
|
-
var
|
|
1552
|
+
var import_react7 = require("react");
|
|
508
1553
|
var import_tools = require("@pixerate/editor/tools");
|
|
509
1554
|
function usePlaybackSurface(playback, id, options = {}, sharedPresence) {
|
|
510
1555
|
const ambient = useAgentPlayback();
|
|
511
1556
|
const target = playback === void 0 ? ambient : playback;
|
|
512
|
-
const [ownPresence] = (0,
|
|
1557
|
+
const [ownPresence] = (0, import_react7.useState)(() => new import_tools.PresenceStore());
|
|
513
1558
|
const presence = sharedPresence ?? ownPresence;
|
|
514
|
-
const latest = (0,
|
|
1559
|
+
const latest = (0, import_react7.useRef)(options);
|
|
515
1560
|
latest.current = options;
|
|
516
|
-
(0,
|
|
1561
|
+
(0, import_react7.useEffect)(() => {
|
|
517
1562
|
if (!target || !id) return;
|
|
518
1563
|
const o = () => latest.current;
|
|
519
1564
|
const surface = {
|
|
@@ -542,7 +1587,7 @@ function usePlaybackSurface(playback, id, options = {}, sharedPresence) {
|
|
|
542
1587
|
|
|
543
1588
|
// src/playback/useElementPlaybackSurface.ts
|
|
544
1589
|
function useElementPlaybackSurface(playback, id, element, options) {
|
|
545
|
-
const latest = (0,
|
|
1590
|
+
const latest = (0, import_react8.useRef)(options);
|
|
546
1591
|
latest.current = options;
|
|
547
1592
|
const box = () => element.current?.getBoundingClientRect() ?? null;
|
|
548
1593
|
return usePlaybackSurface(playback, id, {
|
|
@@ -576,13 +1621,13 @@ function useElementPlaybackSurface(playback, id, element, options) {
|
|
|
576
1621
|
}
|
|
577
1622
|
|
|
578
1623
|
// src/playback/PresenceLayer.tsx
|
|
579
|
-
var
|
|
580
|
-
var
|
|
1624
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
1625
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
581
1626
|
function PresenceLayer({ presence, viewport, className = "" }) {
|
|
582
|
-
const { actors } = (0,
|
|
1627
|
+
const { actors } = (0, import_react9.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
583
1628
|
if (!actors.length) return null;
|
|
584
1629
|
const map = typeof viewport === "function" ? viewport : viewport ? (p) => ({ x: p.x * viewport.zoom + viewport.x, y: p.y * viewport.zoom + viewport.y }) : (p) => p;
|
|
585
|
-
return /* @__PURE__ */ (0,
|
|
1630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
586
1631
|
"div",
|
|
587
1632
|
{
|
|
588
1633
|
className: `pixerate-presence ${className}`.trim(),
|
|
@@ -596,19 +1641,19 @@ function PresenceLayer({ presence, viewport, className = "" }) {
|
|
|
596
1641
|
const br = map({ x: a.focus.x + a.focus.width, y: a.focus.y + a.focus.height });
|
|
597
1642
|
return { left: tl.x - 4, top: tl.y - 4, width: br.x - tl.x + 8, height: br.y - tl.y + 8 };
|
|
598
1643
|
})();
|
|
599
|
-
return /* @__PURE__ */ (0,
|
|
600
|
-
ring && /* @__PURE__ */ (0,
|
|
1644
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react9.default.Fragment, { children: [
|
|
1645
|
+
ring && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
601
1646
|
"div",
|
|
602
1647
|
{
|
|
603
1648
|
"data-actor-focus": a.id,
|
|
604
1649
|
style: { position: "absolute", ...ring, borderRadius: 8, border: `2px solid ${a.color}`, background: `${a.color}14`, transition: "all 160ms ease-out" }
|
|
605
1650
|
}
|
|
606
1651
|
),
|
|
607
|
-
/* @__PURE__ */ (0,
|
|
608
|
-
/* @__PURE__ */ (0,
|
|
609
|
-
/* @__PURE__ */ (0,
|
|
610
|
-
/* @__PURE__ */ (0,
|
|
611
|
-
a.message && /* @__PURE__ */ (0,
|
|
1652
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-actor": a.id, style: { position: "absolute", left: 0, top: 0, transform: `translate(${at.x}px, ${at.y}px)` }, children: [
|
|
1653
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { width: "18", height: "20", viewBox: "0 0 12 18", style: { display: "block", transform: a.pressed ? "scale(0.85)" : void 0, transformOrigin: "0 0", filter: "drop-shadow(0 1px 2px rgba(0,0,0,.35))" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 } }) }),
|
|
1654
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { position: "absolute", left: 14, top: 16, display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 4 }, children: [
|
|
1655
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { whiteSpace: "nowrap", borderRadius: 999, padding: "1px 7px", fontSize: 11, fontWeight: 600, color: "#ffffff", background: a.color }, children: a.name }),
|
|
1656
|
+
a.message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-actor-message": a.id, style: { width: "max-content", maxWidth: 240, borderRadius: 8, borderTopLeftRadius: 0, padding: "4px 8px", fontSize: 12, color: "#1e293b", background: "#ffffff", boxShadow: "0 4px 12px rgba(15,23,42,.18)" }, children: a.message })
|
|
612
1657
|
] })
|
|
613
1658
|
] })
|
|
614
1659
|
] }, a.id);
|
|
@@ -619,7 +1664,7 @@ function PresenceLayer({ presence, viewport, className = "" }) {
|
|
|
619
1664
|
|
|
620
1665
|
// src/parameters/ParametersPanel.tsx
|
|
621
1666
|
var import_parameters3 = require("@pixerate/editor/parameters");
|
|
622
|
-
var
|
|
1667
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
623
1668
|
function FieldRow({
|
|
624
1669
|
controller,
|
|
625
1670
|
state,
|
|
@@ -634,11 +1679,11 @@ function FieldRow({
|
|
|
634
1679
|
const value = state.values[field.id];
|
|
635
1680
|
const error = state.errors[field.id];
|
|
636
1681
|
const changed = !(0, import_parameters3.parameterValuesEqual)(value, state.defaults[field.id]);
|
|
637
|
-
return /* @__PURE__ */ (0,
|
|
638
|
-
/* @__PURE__ */ (0,
|
|
639
|
-
showKeyframes && /* @__PURE__ */ (0,
|
|
640
|
-
/* @__PURE__ */ (0,
|
|
641
|
-
showFieldReset && changed && !field.readOnly && /* @__PURE__ */ (0,
|
|
1682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { "data-parameter-id": field.id, "data-parameter-type": field.type, className: "space-y-1", children: [
|
|
1683
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex min-h-[1.25rem] items-center gap-1.5", children: [
|
|
1684
|
+
showKeyframes && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(KeyframeDiamond, { state: state.keys[field.id] ?? "none", label, onToggle: () => controller.toggleKeyframe(field.id) }),
|
|
1685
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium text-foreground", title: field.description, children: label }),
|
|
1686
|
+
showFieldReset && changed && !field.readOnly && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
642
1687
|
"button",
|
|
643
1688
|
{
|
|
644
1689
|
type: "button",
|
|
@@ -650,8 +1695,8 @@ function FieldRow({
|
|
|
650
1695
|
}
|
|
651
1696
|
)
|
|
652
1697
|
] }),
|
|
653
|
-
field.description && /* @__PURE__ */ (0,
|
|
654
|
-
/* @__PURE__ */ (0,
|
|
1698
|
+
field.description && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-[11px] leading-snug text-muted-foreground", children: field.description }),
|
|
1699
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
655
1700
|
ParameterFieldControl,
|
|
656
1701
|
{
|
|
657
1702
|
field,
|
|
@@ -663,13 +1708,13 @@ function FieldRow({
|
|
|
663
1708
|
onGestureEnd: () => controller.endGesture()
|
|
664
1709
|
}
|
|
665
1710
|
),
|
|
666
|
-
error && /* @__PURE__ */ (0,
|
|
1711
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: error })
|
|
667
1712
|
] });
|
|
668
1713
|
}
|
|
669
1714
|
function PresetBar({ controller, state }) {
|
|
670
|
-
const [saving, setSaving] = (0,
|
|
671
|
-
const [name, setName] = (0,
|
|
672
|
-
const [message, setMessage] = (0,
|
|
1715
|
+
const [saving, setSaving] = (0, import_react10.useState)(false);
|
|
1716
|
+
const [name, setName] = (0, import_react10.useState)("");
|
|
1717
|
+
const [message, setMessage] = (0, import_react10.useState)(null);
|
|
673
1718
|
const active = state.presets.find((p) => p.name === state.activePreset);
|
|
674
1719
|
const save = (e) => {
|
|
675
1720
|
e.preventDefault();
|
|
@@ -680,9 +1725,9 @@ function PresetBar({ controller, state }) {
|
|
|
680
1725
|
setMessage(null);
|
|
681
1726
|
} else setMessage(result.message);
|
|
682
1727
|
};
|
|
683
|
-
return /* @__PURE__ */ (0,
|
|
684
|
-
/* @__PURE__ */ (0,
|
|
685
|
-
/* @__PURE__ */ (0,
|
|
1728
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1.5", "data-parameter-presets": "", children: [
|
|
1729
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-1.5", children: [
|
|
1730
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
686
1731
|
"select",
|
|
687
1732
|
{
|
|
688
1733
|
"aria-label": "Preset",
|
|
@@ -690,16 +1735,16 @@ function PresetBar({ controller, state }) {
|
|
|
690
1735
|
value: state.activePreset ?? "",
|
|
691
1736
|
onChange: (e) => e.target.value && controller.applyPreset(e.target.value),
|
|
692
1737
|
children: [
|
|
693
|
-
/* @__PURE__ */ (0,
|
|
694
|
-
state.presets.map((p) => /* @__PURE__ */ (0,
|
|
1738
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "", children: state.presets.length ? "Presets\u2026" : "No presets" }),
|
|
1739
|
+
state.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: p.name, title: p.description, children: p.name }, p.name))
|
|
695
1740
|
]
|
|
696
1741
|
}
|
|
697
1742
|
),
|
|
698
|
-
/* @__PURE__ */ (0,
|
|
699
|
-
active && !active.builtIn && /* @__PURE__ */ (0,
|
|
1743
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: parameterButtonClass, onClick: () => setSaving((s) => !s), "aria-expanded": saving, children: "Save\u2026" }),
|
|
1744
|
+
active && !active.builtIn && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: parameterButtonClass, "aria-label": `Delete preset ${active.name}`, onClick: () => controller.deletePreset(active.name), children: "Delete" })
|
|
700
1745
|
] }),
|
|
701
|
-
saving && /* @__PURE__ */ (0,
|
|
702
|
-
/* @__PURE__ */ (0,
|
|
1746
|
+
saving && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { className: "flex items-center gap-1.5", onSubmit: save, children: [
|
|
1747
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
703
1748
|
"input",
|
|
704
1749
|
{
|
|
705
1750
|
autoFocus: true,
|
|
@@ -710,9 +1755,9 @@ function PresetBar({ controller, state }) {
|
|
|
710
1755
|
onChange: (e) => setName(e.target.value)
|
|
711
1756
|
}
|
|
712
1757
|
),
|
|
713
|
-
/* @__PURE__ */ (0,
|
|
1758
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "submit", className: parameterButtonClass, children: "Save" })
|
|
714
1759
|
] }),
|
|
715
|
-
message && /* @__PURE__ */ (0,
|
|
1760
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
716
1761
|
] });
|
|
717
1762
|
}
|
|
718
1763
|
function ParametersPanel({
|
|
@@ -730,7 +1775,7 @@ function ParametersPanel({
|
|
|
730
1775
|
onPlaybackReveal
|
|
731
1776
|
}) {
|
|
732
1777
|
const state = useParametersState(controller);
|
|
733
|
-
const rootRef = (0,
|
|
1778
|
+
const rootRef = (0, import_react10.useRef)(null);
|
|
734
1779
|
const ambientPlayback = useAgentPlayback();
|
|
735
1780
|
const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
|
|
736
1781
|
const agentPresence = useElementPlaybackSurface(playing, playbackId, rootRef, {
|
|
@@ -738,13 +1783,13 @@ function ParametersPanel({
|
|
|
738
1783
|
selectors: { parameter: (id) => `[data-parameter-id="${CSS.escape(id)}"]` },
|
|
739
1784
|
reveal: onPlaybackReveal
|
|
740
1785
|
});
|
|
741
|
-
const idBase = (0,
|
|
1786
|
+
const idBase = (0, import_react10.useId)();
|
|
742
1787
|
const keys = showKeyframes ?? state.keyframesEnabled;
|
|
743
1788
|
const heading = title === void 0 ? state.schema.title : title;
|
|
744
1789
|
const renderItems = (items) => items.map((item) => {
|
|
745
1790
|
if (state.visible[item.id] === false) return null;
|
|
746
1791
|
if ((0, import_parameters3.isParameterGroup)(item)) return renderGroup(item);
|
|
747
|
-
return /* @__PURE__ */ (0,
|
|
1792
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
748
1793
|
FieldRow,
|
|
749
1794
|
{
|
|
750
1795
|
controller,
|
|
@@ -761,8 +1806,8 @@ function ParametersPanel({
|
|
|
761
1806
|
const renderGroup = (group) => {
|
|
762
1807
|
const collapsed = !!state.collapsed[group.id];
|
|
763
1808
|
const bodyId = `${idBase}-group-${group.id}`;
|
|
764
|
-
return /* @__PURE__ */ (0,
|
|
765
|
-
/* @__PURE__ */ (0,
|
|
1809
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { "data-parameter-group": group.id, className: "rounded-md border border-border", children: [
|
|
1810
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
766
1811
|
"button",
|
|
767
1812
|
{
|
|
768
1813
|
type: "button",
|
|
@@ -771,22 +1816,22 @@ function ParametersPanel({
|
|
|
771
1816
|
onClick: () => controller.toggleCollapsed(group.id),
|
|
772
1817
|
className: "flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs font-semibold text-foreground hover:bg-muted",
|
|
773
1818
|
children: [
|
|
774
|
-
/* @__PURE__ */ (0,
|
|
1819
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", className: `inline-block text-[10px] text-muted-foreground transition-transform ${collapsed ? "" : "rotate-90"}`, children: "\u25B6" }),
|
|
775
1820
|
(0, import_parameters3.parameterLabel)(group)
|
|
776
1821
|
]
|
|
777
1822
|
}
|
|
778
1823
|
),
|
|
779
|
-
!collapsed && /* @__PURE__ */ (0,
|
|
780
|
-
group.description && /* @__PURE__ */ (0,
|
|
1824
|
+
!collapsed && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { id: bodyId, className: "space-y-3 border-t border-border px-2 py-2", children: [
|
|
1825
|
+
group.description && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-[11px] text-muted-foreground", children: group.description }),
|
|
781
1826
|
renderItems(group.fields)
|
|
782
1827
|
] })
|
|
783
1828
|
] }, group.id);
|
|
784
1829
|
};
|
|
785
|
-
return /* @__PURE__ */ (0,
|
|
786
|
-
(heading || showToolbar) && /* @__PURE__ */ (0,
|
|
787
|
-
heading && /* @__PURE__ */ (0,
|
|
788
|
-
showToolbar && /* @__PURE__ */ (0,
|
|
789
|
-
/* @__PURE__ */ (0,
|
|
1830
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { ref: rootRef, className: `relative space-y-3 text-foreground ${className}`, "data-parameters-panel": "", children: [
|
|
1831
|
+
(heading || showToolbar) && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
1832
|
+
heading && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { className: "mr-auto text-sm font-semibold", children: heading }),
|
|
1833
|
+
showToolbar && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex flex-wrap gap-1", role: "toolbar", "aria-label": "Parameter actions", children: [
|
|
1834
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
790
1835
|
"button",
|
|
791
1836
|
{
|
|
792
1837
|
type: "button",
|
|
@@ -797,7 +1842,7 @@ function ParametersPanel({
|
|
|
797
1842
|
children: "Undo"
|
|
798
1843
|
}
|
|
799
1844
|
),
|
|
800
|
-
/* @__PURE__ */ (0,
|
|
1845
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
801
1846
|
"button",
|
|
802
1847
|
{
|
|
803
1848
|
type: "button",
|
|
@@ -808,13 +1853,13 @@ function ParametersPanel({
|
|
|
808
1853
|
children: "Redo"
|
|
809
1854
|
}
|
|
810
1855
|
),
|
|
811
|
-
/* @__PURE__ */ (0,
|
|
812
|
-
/* @__PURE__ */ (0,
|
|
1856
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: parameterButtonClass, disabled: !state.modified, onClick: () => controller.reset(), children: "Reset" }),
|
|
1857
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: parameterButtonClass, onClick: () => controller.randomize(), children: "Randomize" })
|
|
813
1858
|
] })
|
|
814
1859
|
] }),
|
|
815
|
-
showPresets && /* @__PURE__ */ (0,
|
|
816
|
-
state.fields.length === 0 ? /* @__PURE__ */ (0,
|
|
817
|
-
playing && /* @__PURE__ */ (0,
|
|
1860
|
+
showPresets && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PresetBar, { controller, state }),
|
|
1861
|
+
state.fields.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-xs text-muted-foreground", children: emptyMessage }) : renderItems(state.schema.fields),
|
|
1862
|
+
playing && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PresenceLayer, { presence: agentPresence })
|
|
818
1863
|
] });
|
|
819
1864
|
}
|
|
820
1865
|
// Annotate the CommonJS export names for ESM import in node:
|