@pixerate/editor-react 0.95.0 → 0.97.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 +1261 -198
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1439 -376
- 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-KIRIU53A.js +72 -0
- package/dist/{chunk-6YRSQW2V.js → chunk-NC4RLZTK.js} +1 -1
- package/dist/chunk-Q7LAFHGP.js +655 -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/EffectAuthoringEditor.d.cts +22 -0
- package/dist/effects/EffectAuthoringEditor.d.ts +22 -0
- package/dist/effects/EffectParameters.d.cts +5 -1
- package/dist/effects/EffectParameters.d.ts +5 -1
- package/dist/effects/index.cjs +1624 -127
- package/dist/effects/index.d.cts +2 -0
- package/dist/effects/index.d.ts +2 -0
- package/dist/effects/index.js +8 -2
- package/dist/effects/useEffectAuthoring.d.cts +6 -0
- package/dist/effects/useEffectAuthoring.d.ts +6 -0
- 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 +1763 -700
- package/dist/image-editor/index.js +5 -3
- package/dist/index.cjs +2181 -1118
- package/dist/index.js +5 -3
- package/dist/paint-editor/index.cjs +1254 -191
- 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 +1240 -177
- package/dist/vector/index.js +4 -2
- package/dist/video-editor/index.cjs +1251 -188
- package/dist/video-editor/index.js +4 -2
- package/package.json +29 -3
- package/dist/chunk-5R67YSSD.js +0 -205
package/dist/vector/index.cjs
CHANGED
|
@@ -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-
|
|
@@ -3241,14 +3242,1055 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
3241
3242
|
}
|
|
3242
3243
|
|
|
3243
3244
|
// src/effects/EffectParameters.tsx
|
|
3244
|
-
var
|
|
3245
|
+
var import_react22 = __toESM(require("react"), 1);
|
|
3245
3246
|
var import_effects3 = require("@pixerate/editor/effects");
|
|
3246
3247
|
var import_parameters2 = require("@pixerate/editor/parameters");
|
|
3247
3248
|
|
|
3248
3249
|
// src/parameters/fields.tsx
|
|
3249
|
-
var
|
|
3250
|
+
var import_react21 = require("react");
|
|
3250
3251
|
var import_parameters = require("@pixerate/editor/parameters");
|
|
3252
|
+
|
|
3253
|
+
// src/color/index.ts
|
|
3254
|
+
var color_exports = {};
|
|
3255
|
+
__export(color_exports, {
|
|
3256
|
+
ColorPicker: () => ColorPicker,
|
|
3257
|
+
DualColorPicker: () => DualColorPicker,
|
|
3258
|
+
useColorScheme: () => useColorScheme,
|
|
3259
|
+
useResolvedColor: () => useResolvedColor
|
|
3260
|
+
});
|
|
3261
|
+
|
|
3262
|
+
// src/color/ColorPicker.tsx
|
|
3263
|
+
var import_react18 = require("react");
|
|
3264
|
+
var import_color = require("@pixerate/editor/color");
|
|
3251
3265
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
3266
|
+
var LOCAL_STORAGE_KEY = "pixerate:color:recent";
|
|
3267
|
+
function readLocalRecents() {
|
|
3268
|
+
try {
|
|
3269
|
+
if (typeof localStorage === "undefined") return [];
|
|
3270
|
+
const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
3271
|
+
if (!raw) return [];
|
|
3272
|
+
const parsed = JSON.parse(raw);
|
|
3273
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
3274
|
+
} catch {
|
|
3275
|
+
return [];
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
function writeLocalRecents(list) {
|
|
3279
|
+
try {
|
|
3280
|
+
if (typeof localStorage !== "undefined") {
|
|
3281
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
|
|
3282
|
+
}
|
|
3283
|
+
} catch {
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
|
|
3287
|
+
var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
|
|
3288
|
+
var ColorPicker = ({
|
|
3289
|
+
value,
|
|
3290
|
+
onChange,
|
|
3291
|
+
onGestureStart,
|
|
3292
|
+
onGestureEnd,
|
|
3293
|
+
alpha = false,
|
|
3294
|
+
swatches,
|
|
3295
|
+
recent: controlledRecent,
|
|
3296
|
+
onRecentChange,
|
|
3297
|
+
contrastAgainst,
|
|
3298
|
+
disabled = false,
|
|
3299
|
+
className,
|
|
3300
|
+
id,
|
|
3301
|
+
"aria-label": ariaLabel = "Color picker"
|
|
3302
|
+
}) => {
|
|
3303
|
+
const generatedId = (0, import_react18.useId)();
|
|
3304
|
+
const pickerId = id || generatedId;
|
|
3305
|
+
const [pickerState, setPickerState] = (0, import_react18.useState)(
|
|
3306
|
+
() => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
|
|
3307
|
+
);
|
|
3308
|
+
const stateRef = (0, import_react18.useRef)(pickerState);
|
|
3309
|
+
stateRef.current = pickerState;
|
|
3310
|
+
(0, import_react18.useEffect)(() => {
|
|
3311
|
+
const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
|
|
3312
|
+
if (next) {
|
|
3313
|
+
setPickerState(next);
|
|
3314
|
+
}
|
|
3315
|
+
}, [value]);
|
|
3316
|
+
const [internalRecent, setInternalRecent] = (0, import_react18.useState)(
|
|
3317
|
+
() => controlledRecent ? [] : readLocalRecents()
|
|
3318
|
+
);
|
|
3319
|
+
const activeRecent = controlledRecent ?? internalRecent;
|
|
3320
|
+
const recordRecent = (0, import_react18.useCallback)(
|
|
3321
|
+
(color) => {
|
|
3322
|
+
const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
|
|
3323
|
+
if (!controlledRecent) {
|
|
3324
|
+
setInternalRecent(updated);
|
|
3325
|
+
writeLocalRecents(updated);
|
|
3326
|
+
}
|
|
3327
|
+
onRecentChange?.(updated);
|
|
3328
|
+
},
|
|
3329
|
+
[activeRecent, controlledRecent, onRecentChange]
|
|
3330
|
+
);
|
|
3331
|
+
const [textDraft, setTextDraft] = (0, import_react18.useState)(value);
|
|
3332
|
+
const [isInvalid, setIsInvalid] = (0, import_react18.useState)(false);
|
|
3333
|
+
const [isClipped, setIsClipped] = (0, import_react18.useState)(false);
|
|
3334
|
+
const isTypingRef = (0, import_react18.useRef)(false);
|
|
3335
|
+
(0, import_react18.useEffect)(() => {
|
|
3336
|
+
if (!isTypingRef.current) {
|
|
3337
|
+
setTextDraft(value);
|
|
3338
|
+
setIsInvalid(false);
|
|
3339
|
+
const parsed = (0, import_color.parseColor)(value);
|
|
3340
|
+
setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
|
|
3341
|
+
}
|
|
3342
|
+
}, [value]);
|
|
3343
|
+
const [hasEyeDropper, setHasEyeDropper] = (0, import_react18.useState)(false);
|
|
3344
|
+
(0, import_react18.useEffect)(() => {
|
|
3345
|
+
setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
|
|
3346
|
+
}, []);
|
|
3347
|
+
const emitColorChange = (0, import_react18.useCallback)(
|
|
3348
|
+
(nextState) => {
|
|
3349
|
+
setPickerState(nextState);
|
|
3350
|
+
const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
|
|
3351
|
+
onChange(hex);
|
|
3352
|
+
},
|
|
3353
|
+
[alpha, onChange]
|
|
3354
|
+
);
|
|
3355
|
+
const latest = (0, import_react18.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
|
|
3356
|
+
latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
|
|
3357
|
+
const endDragRef = (0, import_react18.useRef)(null);
|
|
3358
|
+
(0, import_react18.useEffect)(() => () => endDragRef.current?.(), []);
|
|
3359
|
+
const startDrag = (e, next) => {
|
|
3360
|
+
if (disabled) return;
|
|
3361
|
+
e.preventDefault();
|
|
3362
|
+
endDragRef.current?.();
|
|
3363
|
+
onGestureStart?.();
|
|
3364
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
3365
|
+
const update = (clientX, clientY) => {
|
|
3366
|
+
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
3367
|
+
const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
|
|
3368
|
+
latest.current.emitColorChange(next(stateRef.current, x, y));
|
|
3369
|
+
};
|
|
3370
|
+
update(e.clientX, e.clientY);
|
|
3371
|
+
const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
|
|
3372
|
+
const end = () => {
|
|
3373
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
3374
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
3375
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
3376
|
+
endDragRef.current = null;
|
|
3377
|
+
latest.current.onGestureEnd?.();
|
|
3378
|
+
};
|
|
3379
|
+
const onPointerUp = () => {
|
|
3380
|
+
end();
|
|
3381
|
+
latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
|
|
3382
|
+
};
|
|
3383
|
+
endDragRef.current = end;
|
|
3384
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
3385
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
3386
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
3387
|
+
};
|
|
3388
|
+
const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
|
|
3389
|
+
const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
|
|
3390
|
+
const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
|
|
3391
|
+
const handleAreaKeyDown = (e) => {
|
|
3392
|
+
if (disabled) return;
|
|
3393
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
|
|
3394
|
+
if (next) {
|
|
3395
|
+
e.preventDefault();
|
|
3396
|
+
emitColorChange(next);
|
|
3397
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
3398
|
+
}
|
|
3399
|
+
};
|
|
3400
|
+
const handleHueKeyDown = (e) => {
|
|
3401
|
+
if (disabled) return;
|
|
3402
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
|
|
3403
|
+
if (next) {
|
|
3404
|
+
e.preventDefault();
|
|
3405
|
+
emitColorChange(next);
|
|
3406
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
3407
|
+
}
|
|
3408
|
+
};
|
|
3409
|
+
const handleAlphaKeyDown = (e) => {
|
|
3410
|
+
if (disabled) return;
|
|
3411
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
|
|
3412
|
+
if (next) {
|
|
3413
|
+
e.preventDefault();
|
|
3414
|
+
emitColorChange(next);
|
|
3415
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
3416
|
+
}
|
|
3417
|
+
};
|
|
3418
|
+
const commitTextInput = (inputElement) => {
|
|
3419
|
+
isTypingRef.current = false;
|
|
3420
|
+
const parsed = (0, import_color.parseColor)(textDraft);
|
|
3421
|
+
if (parsed) {
|
|
3422
|
+
setIsInvalid(false);
|
|
3423
|
+
setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
|
|
3424
|
+
const formatted = (0, import_color.formatHex)(parsed);
|
|
3425
|
+
onChange(formatted);
|
|
3426
|
+
recordRecent(formatted);
|
|
3427
|
+
} else {
|
|
3428
|
+
setIsInvalid(true);
|
|
3429
|
+
setTextDraft(value);
|
|
3430
|
+
if (inputElement) {
|
|
3431
|
+
inputElement.value = value;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
const handleTextKeyDown = (e) => {
|
|
3436
|
+
if (e.key === "Enter") {
|
|
3437
|
+
e.preventDefault();
|
|
3438
|
+
commitTextInput(e.currentTarget);
|
|
3439
|
+
} else if (e.key === "Escape") {
|
|
3440
|
+
e.preventDefault();
|
|
3441
|
+
isTypingRef.current = false;
|
|
3442
|
+
setIsInvalid(false);
|
|
3443
|
+
setTextDraft(value);
|
|
3444
|
+
e.currentTarget.value = value;
|
|
3445
|
+
}
|
|
3446
|
+
};
|
|
3447
|
+
const handleEyeDropper = async () => {
|
|
3448
|
+
if (disabled || !hasEyeDropper) return;
|
|
3449
|
+
try {
|
|
3450
|
+
const EyeDropperClass = window.EyeDropper;
|
|
3451
|
+
const eyeDropper = new EyeDropperClass();
|
|
3452
|
+
const res = await eyeDropper.open();
|
|
3453
|
+
if (res?.sRGBHex) {
|
|
3454
|
+
onChange(res.sRGBHex);
|
|
3455
|
+
recordRecent(res.sRGBHex);
|
|
3456
|
+
}
|
|
3457
|
+
} catch {
|
|
3458
|
+
}
|
|
3459
|
+
};
|
|
3460
|
+
const contrastResult = (0, import_react18.useMemo)(() => {
|
|
3461
|
+
if (!contrastAgainst) return null;
|
|
3462
|
+
const fg = (0, import_color.parseColor)(value);
|
|
3463
|
+
const bg = (0, import_color.parseColor)(contrastAgainst);
|
|
3464
|
+
if (!fg || !bg) return null;
|
|
3465
|
+
const ratio = (0, import_color.contrastRatio)(fg, bg);
|
|
3466
|
+
const aa = ratio >= 4.5;
|
|
3467
|
+
const aaa = ratio >= 7;
|
|
3468
|
+
return { ratio, aa, aaa };
|
|
3469
|
+
}, [value, contrastAgainst]);
|
|
3470
|
+
const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
|
|
3471
|
+
const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
|
|
3472
|
+
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3473
|
+
"div",
|
|
3474
|
+
{
|
|
3475
|
+
id: pickerId,
|
|
3476
|
+
role: "group",
|
|
3477
|
+
"aria-label": ariaLabel,
|
|
3478
|
+
className,
|
|
3479
|
+
style: {
|
|
3480
|
+
boxSizing: "border-box",
|
|
3481
|
+
width: "var(--pixerate-color-picker-width, 240px)",
|
|
3482
|
+
borderRadius: "var(--pixerate-color-picker-radius, 8px)",
|
|
3483
|
+
background: "var(--pixerate-color-picker-bg, #1f2430)",
|
|
3484
|
+
color: "var(--pixerate-color-picker-fg, #f0f2f5)",
|
|
3485
|
+
padding: "12px",
|
|
3486
|
+
display: "flex",
|
|
3487
|
+
flexDirection: "column",
|
|
3488
|
+
gap: "10px",
|
|
3489
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
3490
|
+
fontSize: "12px",
|
|
3491
|
+
userSelect: "none",
|
|
3492
|
+
opacity: disabled ? 0.6 : 1,
|
|
3493
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
3494
|
+
},
|
|
3495
|
+
children: [
|
|
3496
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3497
|
+
"span",
|
|
3498
|
+
{
|
|
3499
|
+
role: "status",
|
|
3500
|
+
"aria-live": "polite",
|
|
3501
|
+
style: {
|
|
3502
|
+
position: "absolute",
|
|
3503
|
+
width: "1px",
|
|
3504
|
+
height: "1px",
|
|
3505
|
+
padding: 0,
|
|
3506
|
+
margin: "-1px",
|
|
3507
|
+
overflow: "hidden",
|
|
3508
|
+
clip: "rect(0, 0, 0, 0)",
|
|
3509
|
+
whiteSpace: "nowrap",
|
|
3510
|
+
border: 0
|
|
3511
|
+
},
|
|
3512
|
+
children: liveDescription
|
|
3513
|
+
}
|
|
3514
|
+
),
|
|
3515
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3516
|
+
"div",
|
|
3517
|
+
{
|
|
3518
|
+
role: "slider",
|
|
3519
|
+
tabIndex: disabled ? -1 : 0,
|
|
3520
|
+
"aria-label": "Saturation and brightness",
|
|
3521
|
+
"aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
|
|
3522
|
+
pickerState.v * 100
|
|
3523
|
+
)}%`,
|
|
3524
|
+
"aria-disabled": disabled,
|
|
3525
|
+
onPointerDown: handleAreaPointerDown,
|
|
3526
|
+
onKeyDown: handleAreaKeyDown,
|
|
3527
|
+
style: {
|
|
3528
|
+
position: "relative",
|
|
3529
|
+
width: "100%",
|
|
3530
|
+
height: "150px",
|
|
3531
|
+
borderRadius: "6px",
|
|
3532
|
+
background: (0, import_color.pickerAreaBackground)(pickerState),
|
|
3533
|
+
cursor: disabled ? "default" : "crosshair",
|
|
3534
|
+
touchAction: "none",
|
|
3535
|
+
outline: "none"
|
|
3536
|
+
},
|
|
3537
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3538
|
+
"div",
|
|
3539
|
+
{
|
|
3540
|
+
style: {
|
|
3541
|
+
position: "absolute",
|
|
3542
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3543
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3544
|
+
borderRadius: "50%",
|
|
3545
|
+
transform: "translate(-50%, -50%)",
|
|
3546
|
+
left: `${pickerState.s * 100}%`,
|
|
3547
|
+
top: `${(1 - pickerState.v) * 100}%`,
|
|
3548
|
+
border: "2px solid #ffffff",
|
|
3549
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
3550
|
+
pointerEvents: "none",
|
|
3551
|
+
backgroundColor: currentHex
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
)
|
|
3555
|
+
}
|
|
3556
|
+
),
|
|
3557
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3558
|
+
"div",
|
|
3559
|
+
{
|
|
3560
|
+
role: "slider",
|
|
3561
|
+
tabIndex: disabled ? -1 : 0,
|
|
3562
|
+
"aria-label": "Hue",
|
|
3563
|
+
"aria-valuenow": Math.round(pickerState.h),
|
|
3564
|
+
"aria-valuemin": 0,
|
|
3565
|
+
"aria-valuemax": 360,
|
|
3566
|
+
"aria-valuetext": `${Math.round(pickerState.h)} degrees`,
|
|
3567
|
+
"aria-disabled": disabled,
|
|
3568
|
+
onPointerDown: handleHuePointerDown,
|
|
3569
|
+
onKeyDown: handleHueKeyDown,
|
|
3570
|
+
style: {
|
|
3571
|
+
position: "relative",
|
|
3572
|
+
width: "100%",
|
|
3573
|
+
height: "12px",
|
|
3574
|
+
borderRadius: "6px",
|
|
3575
|
+
background: import_color.PICKER_HUE_BACKGROUND,
|
|
3576
|
+
cursor: disabled ? "default" : "pointer",
|
|
3577
|
+
touchAction: "none",
|
|
3578
|
+
outline: "none"
|
|
3579
|
+
},
|
|
3580
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3581
|
+
"div",
|
|
3582
|
+
{
|
|
3583
|
+
style: {
|
|
3584
|
+
position: "absolute",
|
|
3585
|
+
top: "50%",
|
|
3586
|
+
transform: "translate(-50%, -50%)",
|
|
3587
|
+
left: `${pickerState.h / 360 * 100}%`,
|
|
3588
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3589
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3590
|
+
borderRadius: "50%",
|
|
3591
|
+
border: "2px solid #ffffff",
|
|
3592
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
3593
|
+
pointerEvents: "none",
|
|
3594
|
+
backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
)
|
|
3598
|
+
}
|
|
3599
|
+
),
|
|
3600
|
+
alpha && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3601
|
+
"div",
|
|
3602
|
+
{
|
|
3603
|
+
role: "slider",
|
|
3604
|
+
tabIndex: disabled ? -1 : 0,
|
|
3605
|
+
"aria-label": "Alpha",
|
|
3606
|
+
"aria-valuenow": Math.round(pickerState.alpha * 100),
|
|
3607
|
+
"aria-valuemin": 0,
|
|
3608
|
+
"aria-valuemax": 100,
|
|
3609
|
+
"aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
|
|
3610
|
+
"aria-disabled": disabled,
|
|
3611
|
+
onPointerDown: handleAlphaPointerDown,
|
|
3612
|
+
onKeyDown: handleAlphaKeyDown,
|
|
3613
|
+
style: {
|
|
3614
|
+
position: "relative",
|
|
3615
|
+
width: "100%",
|
|
3616
|
+
height: "12px",
|
|
3617
|
+
borderRadius: "6px",
|
|
3618
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
3619
|
+
backgroundSize: "8px 8px",
|
|
3620
|
+
cursor: disabled ? "default" : "pointer",
|
|
3621
|
+
touchAction: "none",
|
|
3622
|
+
outline: "none",
|
|
3623
|
+
overflow: "hidden"
|
|
3624
|
+
},
|
|
3625
|
+
children: [
|
|
3626
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3627
|
+
"div",
|
|
3628
|
+
{
|
|
3629
|
+
style: {
|
|
3630
|
+
position: "absolute",
|
|
3631
|
+
inset: 0,
|
|
3632
|
+
background: (0, import_color.pickerAlphaBackground)(pickerState)
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
),
|
|
3636
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3637
|
+
"div",
|
|
3638
|
+
{
|
|
3639
|
+
style: {
|
|
3640
|
+
position: "absolute",
|
|
3641
|
+
top: "50%",
|
|
3642
|
+
transform: "translate(-50%, -50%)",
|
|
3643
|
+
left: `${pickerState.alpha * 100}%`,
|
|
3644
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3645
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
3646
|
+
borderRadius: "50%",
|
|
3647
|
+
border: "2px solid #ffffff",
|
|
3648
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
3649
|
+
pointerEvents: "none",
|
|
3650
|
+
backgroundColor: currentHex
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
)
|
|
3654
|
+
]
|
|
3655
|
+
}
|
|
3656
|
+
),
|
|
3657
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
|
|
3658
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3659
|
+
"div",
|
|
3660
|
+
{
|
|
3661
|
+
style: {
|
|
3662
|
+
position: "relative",
|
|
3663
|
+
width: "28px",
|
|
3664
|
+
height: "28px",
|
|
3665
|
+
borderRadius: "4px",
|
|
3666
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
3667
|
+
backgroundSize: "8px 8px",
|
|
3668
|
+
overflow: "hidden",
|
|
3669
|
+
flexShrink: 0,
|
|
3670
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
3671
|
+
},
|
|
3672
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3673
|
+
"div",
|
|
3674
|
+
{
|
|
3675
|
+
style: {
|
|
3676
|
+
width: "100%",
|
|
3677
|
+
height: "100%",
|
|
3678
|
+
backgroundColor: currentHex
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
)
|
|
3682
|
+
}
|
|
3683
|
+
),
|
|
3684
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3685
|
+
"input",
|
|
3686
|
+
{
|
|
3687
|
+
type: "text",
|
|
3688
|
+
value: textDraft,
|
|
3689
|
+
disabled,
|
|
3690
|
+
"aria-label": "Color hex or CSS string",
|
|
3691
|
+
"aria-invalid": isInvalid ? "true" : void 0,
|
|
3692
|
+
onChange: (e) => {
|
|
3693
|
+
isTypingRef.current = true;
|
|
3694
|
+
setTextDraft(e.target.value);
|
|
3695
|
+
setIsInvalid(false);
|
|
3696
|
+
},
|
|
3697
|
+
onKeyDown: handleTextKeyDown,
|
|
3698
|
+
onBlur: (e) => commitTextInput(e.currentTarget),
|
|
3699
|
+
style: {
|
|
3700
|
+
flex: 1,
|
|
3701
|
+
minWidth: 0,
|
|
3702
|
+
height: "28px",
|
|
3703
|
+
padding: "0 8px",
|
|
3704
|
+
fontSize: "12px",
|
|
3705
|
+
fontFamily: "monospace",
|
|
3706
|
+
borderRadius: "4px",
|
|
3707
|
+
border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
|
|
3708
|
+
background: "rgba(0,0,0,0.2)",
|
|
3709
|
+
color: "inherit",
|
|
3710
|
+
outline: "none"
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
),
|
|
3714
|
+
hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3715
|
+
"button",
|
|
3716
|
+
{
|
|
3717
|
+
type: "button",
|
|
3718
|
+
disabled,
|
|
3719
|
+
"aria-label": "Pick color from screen",
|
|
3720
|
+
title: "Pick color from screen",
|
|
3721
|
+
onClick: handleEyeDropper,
|
|
3722
|
+
style: {
|
|
3723
|
+
display: "inline-flex",
|
|
3724
|
+
alignItems: "center",
|
|
3725
|
+
justifyContent: "center",
|
|
3726
|
+
width: "28px",
|
|
3727
|
+
height: "28px",
|
|
3728
|
+
borderRadius: "4px",
|
|
3729
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
3730
|
+
background: "transparent",
|
|
3731
|
+
color: "inherit",
|
|
3732
|
+
cursor: disabled ? "default" : "pointer"
|
|
3733
|
+
},
|
|
3734
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3735
|
+
"svg",
|
|
3736
|
+
{
|
|
3737
|
+
width: "14",
|
|
3738
|
+
height: "14",
|
|
3739
|
+
viewBox: "0 0 24 24",
|
|
3740
|
+
fill: "none",
|
|
3741
|
+
stroke: "currentColor",
|
|
3742
|
+
strokeWidth: "2",
|
|
3743
|
+
strokeLinecap: "round",
|
|
3744
|
+
strokeLinejoin: "round",
|
|
3745
|
+
children: [
|
|
3746
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.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" }),
|
|
3747
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
|
|
3748
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("path", { d: "m14 6 4 4" })
|
|
3749
|
+
]
|
|
3750
|
+
}
|
|
3751
|
+
)
|
|
3752
|
+
}
|
|
3753
|
+
)
|
|
3754
|
+
] }),
|
|
3755
|
+
isClipped && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3756
|
+
"div",
|
|
3757
|
+
{
|
|
3758
|
+
role: "note",
|
|
3759
|
+
title: "This colour was outside standard sRGB and clipped.",
|
|
3760
|
+
style: {
|
|
3761
|
+
display: "inline-flex",
|
|
3762
|
+
alignItems: "center",
|
|
3763
|
+
gap: "4px",
|
|
3764
|
+
fontSize: "10px",
|
|
3765
|
+
color: "#f59e0b",
|
|
3766
|
+
background: "rgba(245, 158, 11, 0.1)",
|
|
3767
|
+
padding: "2px 6px",
|
|
3768
|
+
borderRadius: "4px",
|
|
3769
|
+
alignSelf: "flex-start"
|
|
3770
|
+
},
|
|
3771
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
|
|
3772
|
+
}
|
|
3773
|
+
),
|
|
3774
|
+
contrastResult && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3775
|
+
"div",
|
|
3776
|
+
{
|
|
3777
|
+
style: {
|
|
3778
|
+
display: "flex",
|
|
3779
|
+
alignItems: "center",
|
|
3780
|
+
justifyContent: "space-between",
|
|
3781
|
+
fontSize: "11px",
|
|
3782
|
+
padding: "4px 8px",
|
|
3783
|
+
borderRadius: "4px",
|
|
3784
|
+
background: "rgba(255,255,255,0.05)",
|
|
3785
|
+
border: "1px solid rgba(255,255,255,0.1)"
|
|
3786
|
+
},
|
|
3787
|
+
children: [
|
|
3788
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("span", { children: [
|
|
3789
|
+
"Contrast: ",
|
|
3790
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("strong", { children: [
|
|
3791
|
+
contrastResult.ratio.toFixed(2),
|
|
3792
|
+
":1"
|
|
3793
|
+
] })
|
|
3794
|
+
] }),
|
|
3795
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
3796
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3797
|
+
"span",
|
|
3798
|
+
{
|
|
3799
|
+
style: {
|
|
3800
|
+
color: contrastResult.aa ? "#10b981" : "#ef4444",
|
|
3801
|
+
fontWeight: 600
|
|
3802
|
+
},
|
|
3803
|
+
children: [
|
|
3804
|
+
"AA ",
|
|
3805
|
+
contrastResult.aa ? "\u2713" : "\u2717"
|
|
3806
|
+
]
|
|
3807
|
+
}
|
|
3808
|
+
),
|
|
3809
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
3810
|
+
"span",
|
|
3811
|
+
{
|
|
3812
|
+
style: {
|
|
3813
|
+
color: contrastResult.aaa ? "#10b981" : "#ef4444",
|
|
3814
|
+
fontWeight: 600
|
|
3815
|
+
},
|
|
3816
|
+
children: [
|
|
3817
|
+
"AAA ",
|
|
3818
|
+
contrastResult.aaa ? "\u2713" : "\u2717"
|
|
3819
|
+
]
|
|
3820
|
+
}
|
|
3821
|
+
)
|
|
3822
|
+
] })
|
|
3823
|
+
]
|
|
3824
|
+
}
|
|
3825
|
+
),
|
|
3826
|
+
swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
3827
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
|
|
3828
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3829
|
+
"button",
|
|
3830
|
+
{
|
|
3831
|
+
type: "button",
|
|
3832
|
+
"data-testid": "color-picker-swatch",
|
|
3833
|
+
title: color,
|
|
3834
|
+
disabled,
|
|
3835
|
+
"aria-label": `Color ${color}`,
|
|
3836
|
+
onClick: () => {
|
|
3837
|
+
onChange(color);
|
|
3838
|
+
recordRecent(color);
|
|
3839
|
+
},
|
|
3840
|
+
style: {
|
|
3841
|
+
width: "18px",
|
|
3842
|
+
height: "18px",
|
|
3843
|
+
borderRadius: "3px",
|
|
3844
|
+
backgroundColor: color,
|
|
3845
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
3846
|
+
cursor: disabled ? "default" : "pointer",
|
|
3847
|
+
padding: 0,
|
|
3848
|
+
outline: "none"
|
|
3849
|
+
}
|
|
3850
|
+
},
|
|
3851
|
+
`${color}-${idx}`
|
|
3852
|
+
)) })
|
|
3853
|
+
] }),
|
|
3854
|
+
activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
3855
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
|
|
3856
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3857
|
+
"button",
|
|
3858
|
+
{
|
|
3859
|
+
type: "button",
|
|
3860
|
+
"data-testid": "color-picker-recent",
|
|
3861
|
+
disabled,
|
|
3862
|
+
"aria-label": `Color ${color}`,
|
|
3863
|
+
onClick: () => {
|
|
3864
|
+
onChange(color);
|
|
3865
|
+
recordRecent(color);
|
|
3866
|
+
},
|
|
3867
|
+
style: {
|
|
3868
|
+
width: "18px",
|
|
3869
|
+
height: "18px",
|
|
3870
|
+
borderRadius: "3px",
|
|
3871
|
+
backgroundColor: color,
|
|
3872
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
3873
|
+
cursor: disabled ? "default" : "pointer",
|
|
3874
|
+
padding: 0,
|
|
3875
|
+
outline: "none"
|
|
3876
|
+
}
|
|
3877
|
+
},
|
|
3878
|
+
`recent-${color}-${idx}`
|
|
3879
|
+
)) })
|
|
3880
|
+
] })
|
|
3881
|
+
]
|
|
3882
|
+
}
|
|
3883
|
+
);
|
|
3884
|
+
};
|
|
3885
|
+
|
|
3886
|
+
// src/color/DualColorPicker.tsx
|
|
3887
|
+
var import_react19 = require("react");
|
|
3888
|
+
var import_color2 = require("@pixerate/editor/color");
|
|
3889
|
+
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
3890
|
+
function DualColorPicker({
|
|
3891
|
+
value,
|
|
3892
|
+
onChange,
|
|
3893
|
+
onGestureStart,
|
|
3894
|
+
onGestureEnd,
|
|
3895
|
+
scheme: controlledScheme,
|
|
3896
|
+
onSchemeChange,
|
|
3897
|
+
surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
|
|
3898
|
+
contrastAgainst,
|
|
3899
|
+
alpha = false,
|
|
3900
|
+
swatches,
|
|
3901
|
+
disabled = false,
|
|
3902
|
+
className = ""
|
|
3903
|
+
}) {
|
|
3904
|
+
const sameId = (0, import_react19.useId)();
|
|
3905
|
+
const [internalScheme, setInternalScheme] = (0, import_react19.useState)("light");
|
|
3906
|
+
const activeScheme = controlledScheme ?? internalScheme;
|
|
3907
|
+
const handleSchemeSelect = (nextScheme) => {
|
|
3908
|
+
if (onSchemeChange) {
|
|
3909
|
+
onSchemeChange(nextScheme);
|
|
3910
|
+
} else {
|
|
3911
|
+
setInternalScheme(nextScheme);
|
|
3912
|
+
}
|
|
3913
|
+
};
|
|
3914
|
+
const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
|
|
3915
|
+
const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
|
|
3916
|
+
const [sameInBoth, setSameInBoth] = (0, import_react19.useState)(isSame);
|
|
3917
|
+
const handleSameToggle = (e) => {
|
|
3918
|
+
const nextSame = e.target.checked;
|
|
3919
|
+
setSameInBoth(nextSame);
|
|
3920
|
+
if (nextSame) {
|
|
3921
|
+
const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
|
|
3922
|
+
onChange({ light: activeVal, dark: activeVal });
|
|
3923
|
+
}
|
|
3924
|
+
};
|
|
3925
|
+
const handleDerive = () => {
|
|
3926
|
+
if (disabled) return;
|
|
3927
|
+
onGestureStart?.();
|
|
3928
|
+
const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
|
|
3929
|
+
const derived = (0, import_color2.deriveDualColor)(currentActive, {
|
|
3930
|
+
from: activeScheme,
|
|
3931
|
+
// An unreadable surfaces prop falls back to the defaults rather than throwing.
|
|
3932
|
+
surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
|
|
3933
|
+
});
|
|
3934
|
+
onChange(derived);
|
|
3935
|
+
onGestureEnd?.();
|
|
3936
|
+
};
|
|
3937
|
+
const handleInnerChange = (hex) => {
|
|
3938
|
+
if (sameInBoth) {
|
|
3939
|
+
onChange({ light: hex, dark: hex });
|
|
3940
|
+
} else {
|
|
3941
|
+
const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
|
|
3942
|
+
onChange(updated);
|
|
3943
|
+
}
|
|
3944
|
+
};
|
|
3945
|
+
const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
|
|
3946
|
+
const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
|
|
3947
|
+
const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
|
|
3948
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
3949
|
+
"div",
|
|
3950
|
+
{
|
|
3951
|
+
className: `pixerate-dual-color-picker ${className}`,
|
|
3952
|
+
style: {
|
|
3953
|
+
display: "flex",
|
|
3954
|
+
flexDirection: "column",
|
|
3955
|
+
gap: "12px",
|
|
3956
|
+
padding: "12px",
|
|
3957
|
+
background: "#1a1d24",
|
|
3958
|
+
color: "#e2e8f0",
|
|
3959
|
+
borderRadius: "10px",
|
|
3960
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
3961
|
+
width: "260px",
|
|
3962
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
3963
|
+
fontSize: "13px",
|
|
3964
|
+
boxSizing: "border-box"
|
|
3965
|
+
},
|
|
3966
|
+
children: [
|
|
3967
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
3968
|
+
"div",
|
|
3969
|
+
{
|
|
3970
|
+
role: "tablist",
|
|
3971
|
+
"aria-label": "Color scheme mode",
|
|
3972
|
+
style: {
|
|
3973
|
+
display: "flex",
|
|
3974
|
+
background: "#111318",
|
|
3975
|
+
borderRadius: "6px",
|
|
3976
|
+
padding: "2px",
|
|
3977
|
+
gap: "2px"
|
|
3978
|
+
},
|
|
3979
|
+
children: [
|
|
3980
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
3981
|
+
"button",
|
|
3982
|
+
{
|
|
3983
|
+
type: "button",
|
|
3984
|
+
role: "tab",
|
|
3985
|
+
"aria-selected": activeScheme === "light",
|
|
3986
|
+
onClick: () => handleSchemeSelect("light"),
|
|
3987
|
+
disabled,
|
|
3988
|
+
style: {
|
|
3989
|
+
flex: 1,
|
|
3990
|
+
padding: "6px 8px",
|
|
3991
|
+
border: "none",
|
|
3992
|
+
borderRadius: "4px",
|
|
3993
|
+
background: activeScheme === "light" ? "#2d3342" : "transparent",
|
|
3994
|
+
color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
|
|
3995
|
+
fontWeight: activeScheme === "light" ? 600 : 400,
|
|
3996
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
3997
|
+
fontSize: "12px",
|
|
3998
|
+
transition: "all 0.15s ease"
|
|
3999
|
+
},
|
|
4000
|
+
children: "Light"
|
|
4001
|
+
}
|
|
4002
|
+
),
|
|
4003
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4004
|
+
"button",
|
|
4005
|
+
{
|
|
4006
|
+
type: "button",
|
|
4007
|
+
role: "tab",
|
|
4008
|
+
"aria-selected": activeScheme === "dark",
|
|
4009
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
4010
|
+
disabled,
|
|
4011
|
+
style: {
|
|
4012
|
+
flex: 1,
|
|
4013
|
+
padding: "6px 8px",
|
|
4014
|
+
border: "none",
|
|
4015
|
+
borderRadius: "4px",
|
|
4016
|
+
background: activeScheme === "dark" ? "#2d3342" : "transparent",
|
|
4017
|
+
color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
|
|
4018
|
+
fontWeight: activeScheme === "dark" ? 600 : 400,
|
|
4019
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
4020
|
+
fontSize: "12px",
|
|
4021
|
+
transition: "all 0.15s ease"
|
|
4022
|
+
},
|
|
4023
|
+
children: "Dark"
|
|
4024
|
+
}
|
|
4025
|
+
)
|
|
4026
|
+
]
|
|
4027
|
+
}
|
|
4028
|
+
),
|
|
4029
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
4030
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4031
|
+
"button",
|
|
4032
|
+
{
|
|
4033
|
+
type: "button",
|
|
4034
|
+
onClick: () => handleSchemeSelect("light"),
|
|
4035
|
+
disabled,
|
|
4036
|
+
title: "Edit light mode colour",
|
|
4037
|
+
style: {
|
|
4038
|
+
flex: 1,
|
|
4039
|
+
display: "flex",
|
|
4040
|
+
flexDirection: "column",
|
|
4041
|
+
alignItems: "center",
|
|
4042
|
+
gap: "6px",
|
|
4043
|
+
padding: "8px",
|
|
4044
|
+
background: surfaces.light,
|
|
4045
|
+
color: "#000000",
|
|
4046
|
+
border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
4047
|
+
borderRadius: "6px",
|
|
4048
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
4049
|
+
outline: "none"
|
|
4050
|
+
},
|
|
4051
|
+
children: [
|
|
4052
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4053
|
+
"span",
|
|
4054
|
+
{
|
|
4055
|
+
style: {
|
|
4056
|
+
width: "100%",
|
|
4057
|
+
height: "24px",
|
|
4058
|
+
borderRadius: "4px",
|
|
4059
|
+
background: dual.light,
|
|
4060
|
+
border: "1px solid rgba(0,0,0,0.15)"
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
),
|
|
4064
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
|
|
4065
|
+
]
|
|
4066
|
+
}
|
|
4067
|
+
),
|
|
4068
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4069
|
+
"button",
|
|
4070
|
+
{
|
|
4071
|
+
type: "button",
|
|
4072
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
4073
|
+
disabled,
|
|
4074
|
+
title: "Edit dark mode colour",
|
|
4075
|
+
style: {
|
|
4076
|
+
flex: 1,
|
|
4077
|
+
display: "flex",
|
|
4078
|
+
flexDirection: "column",
|
|
4079
|
+
alignItems: "center",
|
|
4080
|
+
gap: "6px",
|
|
4081
|
+
padding: "8px",
|
|
4082
|
+
background: surfaces.dark,
|
|
4083
|
+
color: "#ffffff",
|
|
4084
|
+
border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
4085
|
+
borderRadius: "6px",
|
|
4086
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
4087
|
+
outline: "none"
|
|
4088
|
+
},
|
|
4089
|
+
children: [
|
|
4090
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4091
|
+
"span",
|
|
4092
|
+
{
|
|
4093
|
+
style: {
|
|
4094
|
+
width: "100%",
|
|
4095
|
+
height: "24px",
|
|
4096
|
+
borderRadius: "4px",
|
|
4097
|
+
background: dual.dark,
|
|
4098
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
),
|
|
4102
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
|
|
4103
|
+
]
|
|
4104
|
+
}
|
|
4105
|
+
)
|
|
4106
|
+
] }),
|
|
4107
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4108
|
+
"div",
|
|
4109
|
+
{
|
|
4110
|
+
style: {
|
|
4111
|
+
display: "flex",
|
|
4112
|
+
alignItems: "center",
|
|
4113
|
+
justifyContent: "space-between",
|
|
4114
|
+
gap: "8px",
|
|
4115
|
+
padding: "2px 0"
|
|
4116
|
+
},
|
|
4117
|
+
children: [
|
|
4118
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4119
|
+
"label",
|
|
4120
|
+
{
|
|
4121
|
+
htmlFor: sameId,
|
|
4122
|
+
style: {
|
|
4123
|
+
display: "flex",
|
|
4124
|
+
alignItems: "center",
|
|
4125
|
+
gap: "6px",
|
|
4126
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
4127
|
+
userSelect: "none",
|
|
4128
|
+
fontSize: "12px",
|
|
4129
|
+
color: "#c4cad4"
|
|
4130
|
+
},
|
|
4131
|
+
children: [
|
|
4132
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4133
|
+
"input",
|
|
4134
|
+
{
|
|
4135
|
+
id: sameId,
|
|
4136
|
+
type: "checkbox",
|
|
4137
|
+
checked: sameInBoth,
|
|
4138
|
+
onChange: handleSameToggle,
|
|
4139
|
+
disabled,
|
|
4140
|
+
style: { cursor: disabled ? "not-allowed" : "pointer" }
|
|
4141
|
+
}
|
|
4142
|
+
),
|
|
4143
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { children: "Same in both" })
|
|
4144
|
+
]
|
|
4145
|
+
}
|
|
4146
|
+
),
|
|
4147
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4148
|
+
"button",
|
|
4149
|
+
{
|
|
4150
|
+
type: "button",
|
|
4151
|
+
onClick: handleDerive,
|
|
4152
|
+
disabled,
|
|
4153
|
+
style: {
|
|
4154
|
+
padding: "4px 10px",
|
|
4155
|
+
background: "#2d3342",
|
|
4156
|
+
color: "#e2e8f0",
|
|
4157
|
+
border: "1px solid #3b4252",
|
|
4158
|
+
borderRadius: "4px",
|
|
4159
|
+
fontSize: "11px",
|
|
4160
|
+
fontWeight: 500,
|
|
4161
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
4162
|
+
},
|
|
4163
|
+
children: "Derive"
|
|
4164
|
+
}
|
|
4165
|
+
)
|
|
4166
|
+
]
|
|
4167
|
+
}
|
|
4168
|
+
),
|
|
4169
|
+
dualContrast && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
|
|
4170
|
+
"div",
|
|
4171
|
+
{
|
|
4172
|
+
"data-testid": "dual-contrast-summary",
|
|
4173
|
+
style: {
|
|
4174
|
+
display: "flex",
|
|
4175
|
+
justifyContent: "space-between",
|
|
4176
|
+
background: "#111318",
|
|
4177
|
+
padding: "6px 8px",
|
|
4178
|
+
borderRadius: "6px",
|
|
4179
|
+
fontSize: "11px",
|
|
4180
|
+
color: "#8c95a6"
|
|
4181
|
+
},
|
|
4182
|
+
children: [
|
|
4183
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { children: [
|
|
4184
|
+
"Light:",
|
|
4185
|
+
" ",
|
|
4186
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
4187
|
+
dualContrast.light.ratio.toFixed(2),
|
|
4188
|
+
" (",
|
|
4189
|
+
dualContrast.light.level,
|
|
4190
|
+
")"
|
|
4191
|
+
] })
|
|
4192
|
+
] }),
|
|
4193
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("span", { children: [
|
|
4194
|
+
"Dark:",
|
|
4195
|
+
" ",
|
|
4196
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
4197
|
+
dualContrast.dark.ratio.toFixed(2),
|
|
4198
|
+
" (",
|
|
4199
|
+
dualContrast.dark.level,
|
|
4200
|
+
")"
|
|
4201
|
+
] })
|
|
4202
|
+
] })
|
|
4203
|
+
]
|
|
4204
|
+
}
|
|
4205
|
+
),
|
|
4206
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
4207
|
+
ColorPicker,
|
|
4208
|
+
{
|
|
4209
|
+
value: activeColor,
|
|
4210
|
+
onChange: handleInnerChange,
|
|
4211
|
+
onGestureStart,
|
|
4212
|
+
onGestureEnd,
|
|
4213
|
+
contrastAgainst: activeContrastTarget,
|
|
4214
|
+
alpha,
|
|
4215
|
+
swatches,
|
|
4216
|
+
disabled
|
|
4217
|
+
}
|
|
4218
|
+
)
|
|
4219
|
+
]
|
|
4220
|
+
}
|
|
4221
|
+
);
|
|
4222
|
+
}
|
|
4223
|
+
|
|
4224
|
+
// src/color/useColorScheme.ts
|
|
4225
|
+
var import_react20 = require("react");
|
|
4226
|
+
var import_color3 = require("@pixerate/editor/color");
|
|
4227
|
+
function getSnapshot(attribute) {
|
|
4228
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
4229
|
+
return "light";
|
|
4230
|
+
}
|
|
4231
|
+
if (attribute) {
|
|
4232
|
+
const el = document.documentElement;
|
|
4233
|
+
if (attribute === "class") {
|
|
4234
|
+
return el.classList.contains("dark") ? "dark" : "light";
|
|
4235
|
+
}
|
|
4236
|
+
const val = el.getAttribute(attribute);
|
|
4237
|
+
return val === "dark" ? "dark" : "light";
|
|
4238
|
+
}
|
|
4239
|
+
if (typeof window.matchMedia === "function") {
|
|
4240
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
4241
|
+
}
|
|
4242
|
+
return "light";
|
|
4243
|
+
}
|
|
4244
|
+
function getServerSnapshot() {
|
|
4245
|
+
return "light";
|
|
4246
|
+
}
|
|
4247
|
+
function useColorScheme(options) {
|
|
4248
|
+
const override = options?.override;
|
|
4249
|
+
const attribute = options?.attribute;
|
|
4250
|
+
const subscribe = (0, import_react20.useMemo)(() => {
|
|
4251
|
+
return (callback) => {
|
|
4252
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
4253
|
+
return () => {
|
|
4254
|
+
};
|
|
4255
|
+
}
|
|
4256
|
+
if (attribute) {
|
|
4257
|
+
const observer = new MutationObserver(() => {
|
|
4258
|
+
callback();
|
|
4259
|
+
});
|
|
4260
|
+
observer.observe(document.documentElement, {
|
|
4261
|
+
attributes: true,
|
|
4262
|
+
attributeFilter: [attribute]
|
|
4263
|
+
});
|
|
4264
|
+
return () => observer.disconnect();
|
|
4265
|
+
}
|
|
4266
|
+
if (typeof window.matchMedia === "function") {
|
|
4267
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
4268
|
+
const handler = () => callback();
|
|
4269
|
+
mql.addEventListener("change", handler);
|
|
4270
|
+
return () => mql.removeEventListener("change", handler);
|
|
4271
|
+
}
|
|
4272
|
+
return () => {
|
|
4273
|
+
};
|
|
4274
|
+
};
|
|
4275
|
+
}, [attribute]);
|
|
4276
|
+
const detected = (0, import_react20.useSyncExternalStore)(
|
|
4277
|
+
subscribe,
|
|
4278
|
+
() => getSnapshot(attribute),
|
|
4279
|
+
getServerSnapshot
|
|
4280
|
+
);
|
|
4281
|
+
return override ?? detected;
|
|
4282
|
+
}
|
|
4283
|
+
function useResolvedColor(value, scheme) {
|
|
4284
|
+
const detectedScheme = useColorScheme();
|
|
4285
|
+
const activeScheme = scheme ?? detectedScheme;
|
|
4286
|
+
return (0, import_color3.resolveColor)(value, activeScheme);
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
// src/color/index.ts
|
|
4290
|
+
__reExport(color_exports, require("@pixerate/editor/color"));
|
|
4291
|
+
|
|
4292
|
+
// src/parameters/fields.tsx
|
|
4293
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
3252
4294
|
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";
|
|
3253
4295
|
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";
|
|
3254
4296
|
var rangeClass = "h-4 w-full min-w-0 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
@@ -3272,7 +4314,7 @@ function ParameterCommitInput({ value, onCommit, multiline, className, onKeyDown
|
|
|
3272
4314
|
onKeyDown: keyDown,
|
|
3273
4315
|
...rest
|
|
3274
4316
|
};
|
|
3275
|
-
return multiline ? /* @__PURE__ */ (0,
|
|
4317
|
+
return multiline ? /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("input", { type: "text", ...props }, value);
|
|
3276
4318
|
}
|
|
3277
4319
|
var plainNumber = (field, value) => (0, import_parameters.formatParameterNumber)({ ...field, unit: void 0 }, value);
|
|
3278
4320
|
function ParameterNumberInput({
|
|
@@ -3283,8 +4325,8 @@ function ParameterNumberInput({
|
|
|
3283
4325
|
id,
|
|
3284
4326
|
"aria-label": ariaLabel
|
|
3285
4327
|
}) {
|
|
3286
|
-
return /* @__PURE__ */ (0,
|
|
3287
|
-
/* @__PURE__ */ (0,
|
|
4328
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
|
|
4329
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3288
4330
|
ParameterCommitInput,
|
|
3289
4331
|
{
|
|
3290
4332
|
id,
|
|
@@ -3306,21 +4348,21 @@ function ParameterNumberInput({
|
|
|
3306
4348
|
}
|
|
3307
4349
|
}
|
|
3308
4350
|
),
|
|
3309
|
-
field.unit && /* @__PURE__ */ (0,
|
|
4351
|
+
field.unit && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
|
|
3310
4352
|
] });
|
|
3311
4353
|
}
|
|
3312
4354
|
function ParameterSlider(props) {
|
|
3313
4355
|
const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
|
|
3314
|
-
const dragging = (0,
|
|
4356
|
+
const dragging = (0, import_react21.useRef)(false);
|
|
3315
4357
|
const end = () => {
|
|
3316
4358
|
if (!dragging.current) return;
|
|
3317
4359
|
dragging.current = false;
|
|
3318
4360
|
onGestureEnd?.();
|
|
3319
4361
|
};
|
|
3320
|
-
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0,
|
|
4362
|
+
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterNumberInput, { ...props });
|
|
3321
4363
|
const step = (0, import_parameters.parameterStep)(field);
|
|
3322
|
-
return /* @__PURE__ */ (0,
|
|
3323
|
-
/* @__PURE__ */ (0,
|
|
4364
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
4365
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3324
4366
|
"input",
|
|
3325
4367
|
{
|
|
3326
4368
|
type: "range",
|
|
@@ -3343,11 +4385,11 @@ function ParameterSlider(props) {
|
|
|
3343
4385
|
onChange: (e) => onChange((0, import_parameters.clampParameterNumber)(field, Number(e.target.value)))
|
|
3344
4386
|
}
|
|
3345
4387
|
),
|
|
3346
|
-
/* @__PURE__ */ (0,
|
|
4388
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters.parameterLabel)(field)} value` }) })
|
|
3347
4389
|
] });
|
|
3348
4390
|
}
|
|
3349
4391
|
function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
3350
|
-
return /* @__PURE__ */ (0,
|
|
4392
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3351
4393
|
"button",
|
|
3352
4394
|
{
|
|
3353
4395
|
type: "button",
|
|
@@ -3358,7 +4400,7 @@ function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
|
3358
4400
|
disabled: disabled || field.readOnly,
|
|
3359
4401
|
onClick: () => onChange(!value),
|
|
3360
4402
|
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"}`,
|
|
3361
|
-
children: /* @__PURE__ */ (0,
|
|
4403
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3362
4404
|
"span",
|
|
3363
4405
|
{
|
|
3364
4406
|
className: `pointer-events-none block h-4 w-4 rounded-full bg-background shadow transition-transform ${value ? "translate-x-4" : "translate-x-0.5"}`
|
|
@@ -3371,7 +4413,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
3371
4413
|
const options = (0, import_parameters.getChoiceOptions)(field);
|
|
3372
4414
|
const off = disabled || field.readOnly;
|
|
3373
4415
|
if (field.control === "segmented") {
|
|
3374
|
-
return /* @__PURE__ */ (0,
|
|
4416
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { role: "radiogroup", "aria-label": (0, import_parameters.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_runtime26.jsx)(
|
|
3375
4417
|
"button",
|
|
3376
4418
|
{
|
|
3377
4419
|
type: "button",
|
|
@@ -3387,7 +4429,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
3387
4429
|
)) });
|
|
3388
4430
|
}
|
|
3389
4431
|
const index = options.findIndex((o) => o.value === value);
|
|
3390
|
-
return /* @__PURE__ */ (0,
|
|
4432
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3391
4433
|
"select",
|
|
3392
4434
|
{
|
|
3393
4435
|
id,
|
|
@@ -3399,53 +4441,64 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
3399
4441
|
if (option) onChange(option.value);
|
|
3400
4442
|
},
|
|
3401
4443
|
className: parameterInputClass,
|
|
3402
|
-
children: options.map((o, i) => /* @__PURE__ */ (0,
|
|
4444
|
+
children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters.choiceOptionLabel)(o) }, String(o.value)))
|
|
3403
4445
|
}
|
|
3404
4446
|
);
|
|
3405
4447
|
}
|
|
3406
4448
|
function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
|
|
3407
|
-
const
|
|
4449
|
+
const [open, setOpen] = (0, import_react21.useState)(false);
|
|
4450
|
+
const containerRef = (0, import_react21.useRef)(null);
|
|
4451
|
+
const buttonRef = (0, import_react21.useRef)(null);
|
|
4452
|
+
const popoverRef = (0, import_react21.useRef)(null);
|
|
3408
4453
|
const alpha = !!field.alpha;
|
|
3409
4454
|
const hex = (0, import_parameters.normalizeHexColor)(value, true) ?? "#000000ff";
|
|
3410
4455
|
const rgb = hex.slice(0, 7);
|
|
3411
|
-
const
|
|
4456
|
+
const shown = alpha ? hex : rgb;
|
|
3412
4457
|
const off = disabled || field.readOnly;
|
|
3413
|
-
const
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
4458
|
+
const name = (0, import_parameters.parameterLabel)(field);
|
|
4459
|
+
(0, import_react21.useEffect)(() => {
|
|
4460
|
+
if (!open) return;
|
|
4461
|
+
const onPointerDown = (e) => {
|
|
4462
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
4463
|
+
setOpen(false);
|
|
4464
|
+
}
|
|
4465
|
+
};
|
|
4466
|
+
const onKeyDown = (e) => {
|
|
4467
|
+
if (e.key === "Escape") {
|
|
4468
|
+
e.stopPropagation();
|
|
4469
|
+
setOpen(false);
|
|
4470
|
+
buttonRef.current?.focus();
|
|
4471
|
+
}
|
|
4472
|
+
};
|
|
4473
|
+
window.addEventListener("pointerdown", onPointerDown, true);
|
|
4474
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
4475
|
+
return () => {
|
|
4476
|
+
window.removeEventListener("pointerdown", onPointerDown, true);
|
|
4477
|
+
window.removeEventListener("keydown", onKeyDown, true);
|
|
4478
|
+
};
|
|
4479
|
+
}, [open]);
|
|
4480
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { ref: containerRef, className: "relative space-y-1.5", children: [
|
|
4481
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
4482
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
4483
|
+
"button",
|
|
4484
|
+
{
|
|
4485
|
+
ref: buttonRef,
|
|
4486
|
+
type: "button",
|
|
4487
|
+
"aria-label": name,
|
|
4488
|
+
"aria-expanded": open,
|
|
4489
|
+
"aria-haspopup": "dialog",
|
|
4490
|
+
disabled: off,
|
|
4491
|
+
onClick: () => setOpen((prev) => !prev),
|
|
4492
|
+
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",
|
|
4493
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "absolute inset-0", style: { background: shown } })
|
|
4494
|
+
}
|
|
4495
|
+
),
|
|
4496
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3444
4497
|
ParameterCommitInput,
|
|
3445
4498
|
{
|
|
3446
4499
|
id,
|
|
3447
|
-
"aria-label": `${
|
|
3448
|
-
value:
|
|
4500
|
+
"aria-label": `${name} hex`,
|
|
4501
|
+
value: shown,
|
|
3449
4502
|
disabled: off,
|
|
3450
4503
|
spellCheck: false,
|
|
3451
4504
|
className: `${parameterInputClass} font-mono`,
|
|
@@ -3456,51 +4509,43 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
|
|
|
3456
4509
|
}
|
|
3457
4510
|
)
|
|
3458
4511
|
] }),
|
|
3459
|
-
|
|
3460
|
-
"
|
|
4512
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
4513
|
+
"div",
|
|
3461
4514
|
{
|
|
3462
|
-
|
|
3463
|
-
"
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
onPointerDown: start,
|
|
3471
|
-
onPointerUp: end,
|
|
3472
|
-
onPointerCancel: end,
|
|
3473
|
-
onBlur: end,
|
|
3474
|
-
onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
|
|
3475
|
-
}
|
|
3476
|
-
),
|
|
3477
|
-
field.swatches && field.swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
|
|
3478
|
-
const swatch = (0, import_parameters.normalizeHexColor)(s, alpha);
|
|
3479
|
-
if (!swatch) return null;
|
|
3480
|
-
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
|
3481
|
-
"button",
|
|
3482
|
-
{
|
|
3483
|
-
type: "button",
|
|
3484
|
-
title: swatch,
|
|
3485
|
-
"aria-label": `${(0, import_parameters.parameterLabel)(field)} ${swatch}`,
|
|
3486
|
-
"aria-pressed": swatch === (alpha ? hex : rgb),
|
|
3487
|
-
disabled: off,
|
|
3488
|
-
onClick: () => onChange(swatch),
|
|
3489
|
-
className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
|
|
3490
|
-
style: { background: swatch }
|
|
4515
|
+
ref: popoverRef,
|
|
4516
|
+
role: "dialog",
|
|
4517
|
+
"aria-label": name,
|
|
4518
|
+
tabIndex: -1,
|
|
4519
|
+
onBlur: (e) => {
|
|
4520
|
+
if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
|
|
4521
|
+
setOpen(false);
|
|
4522
|
+
}
|
|
3491
4523
|
},
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
4524
|
+
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",
|
|
4525
|
+
style: { background: "var(--popover, var(--background, #fff))" },
|
|
4526
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
4527
|
+
ColorPicker,
|
|
4528
|
+
{
|
|
4529
|
+
value: shown,
|
|
4530
|
+
alpha,
|
|
4531
|
+
swatches: field.swatches,
|
|
4532
|
+
disabled: off,
|
|
4533
|
+
onChange,
|
|
4534
|
+
onGestureStart,
|
|
4535
|
+
onGestureEnd
|
|
4536
|
+
}
|
|
4537
|
+
)
|
|
4538
|
+
}
|
|
4539
|
+
)
|
|
3495
4540
|
] });
|
|
3496
4541
|
}
|
|
3497
4542
|
function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
3498
4543
|
const size = (0, import_parameters.vectorSize)(field);
|
|
3499
|
-
return /* @__PURE__ */ (0,
|
|
4544
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
|
|
3500
4545
|
const component = (0, import_parameters.vectorComponentField)(field, i);
|
|
3501
|
-
return /* @__PURE__ */ (0,
|
|
3502
|
-
/* @__PURE__ */ (0,
|
|
3503
|
-
/* @__PURE__ */ (0,
|
|
4546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
|
|
4547
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
|
|
4548
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3504
4549
|
ParameterNumberInput,
|
|
3505
4550
|
{
|
|
3506
4551
|
field: component,
|
|
@@ -3517,11 +4562,11 @@ function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
|
3517
4562
|
function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
3518
4563
|
const off = disabled || field.readOnly;
|
|
3519
4564
|
const name = (0, import_parameters.parameterLabel)(field);
|
|
3520
|
-
return /* @__PURE__ */ (0,
|
|
3521
|
-
/* @__PURE__ */ (0,
|
|
3522
|
-
/* @__PURE__ */ (0,
|
|
3523
|
-
/* @__PURE__ */ (0,
|
|
3524
|
-
/* @__PURE__ */ (0,
|
|
4565
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "space-y-1.5", children: [
|
|
4566
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
4567
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.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_runtime26.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
|
|
4568
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
4569
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3525
4570
|
ParameterCommitInput,
|
|
3526
4571
|
{
|
|
3527
4572
|
id,
|
|
@@ -3532,10 +4577,10 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
3532
4577
|
onCommit: (text) => onChange(text.trim())
|
|
3533
4578
|
}
|
|
3534
4579
|
),
|
|
3535
|
-
/* @__PURE__ */ (0,
|
|
3536
|
-
resolveFile && /* @__PURE__ */ (0,
|
|
4580
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "flex gap-1", children: [
|
|
4581
|
+
resolveFile && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
|
|
3537
4582
|
"Choose file\u2026",
|
|
3538
|
-
/* @__PURE__ */ (0,
|
|
4583
|
+
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3539
4584
|
"input",
|
|
3540
4585
|
{
|
|
3541
4586
|
type: "file",
|
|
@@ -3551,11 +4596,11 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
3551
4596
|
}
|
|
3552
4597
|
)
|
|
3553
4598
|
] }),
|
|
3554
|
-
value && /* @__PURE__ */ (0,
|
|
4599
|
+
value && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
|
|
3555
4600
|
] })
|
|
3556
4601
|
] })
|
|
3557
4602
|
] }),
|
|
3558
|
-
field.options && field.options.length > 0 && /* @__PURE__ */ (0,
|
|
4603
|
+
field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3559
4604
|
"button",
|
|
3560
4605
|
{
|
|
3561
4606
|
type: "button",
|
|
@@ -3565,14 +4610,14 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
3565
4610
|
disabled: off,
|
|
3566
4611
|
onClick: () => onChange(o.url),
|
|
3567
4612
|
className: "h-9 w-12 overflow-hidden rounded border border-input aria-pressed:ring-2 aria-pressed:ring-primary",
|
|
3568
|
-
children: /* @__PURE__ */ (0,
|
|
4613
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
|
|
3569
4614
|
},
|
|
3570
4615
|
o.url
|
|
3571
4616
|
)) })
|
|
3572
4617
|
] });
|
|
3573
4618
|
}
|
|
3574
4619
|
function ParameterText({ field, value, onChange, disabled, id }) {
|
|
3575
|
-
return /* @__PURE__ */ (0,
|
|
4620
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
3576
4621
|
ParameterCommitInput,
|
|
3577
4622
|
{
|
|
3578
4623
|
id,
|
|
@@ -3591,31 +4636,42 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
|
|
|
3591
4636
|
switch (field.type) {
|
|
3592
4637
|
case "number":
|
|
3593
4638
|
case "int":
|
|
3594
|
-
return /* @__PURE__ */ (0,
|
|
4639
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
|
|
3595
4640
|
case "boolean":
|
|
3596
|
-
return /* @__PURE__ */ (0,
|
|
4641
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
|
|
3597
4642
|
case "choice":
|
|
3598
|
-
return /* @__PURE__ */ (0,
|
|
4643
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
|
|
3599
4644
|
case "color":
|
|
3600
|
-
return /* @__PURE__ */ (0,
|
|
4645
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
|
|
3601
4646
|
case "vector":
|
|
3602
|
-
return /* @__PURE__ */ (0,
|
|
4647
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
|
|
3603
4648
|
case "image":
|
|
3604
|
-
return /* @__PURE__ */ (0,
|
|
4649
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
|
|
3605
4650
|
case "text":
|
|
3606
|
-
return /* @__PURE__ */ (0,
|
|
4651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ParameterText, { field, value, onChange: set, ...rest });
|
|
3607
4652
|
}
|
|
3608
4653
|
}
|
|
3609
4654
|
|
|
3610
4655
|
// src/effects/EffectParameters.tsx
|
|
3611
|
-
var
|
|
3612
|
-
function EffectParameters({
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
4656
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
4657
|
+
function EffectParameters({
|
|
4658
|
+
description,
|
|
4659
|
+
values,
|
|
4660
|
+
onChange,
|
|
4661
|
+
onReset,
|
|
4662
|
+
keyframed,
|
|
4663
|
+
onPreset,
|
|
4664
|
+
onPresetName,
|
|
4665
|
+
renderControlAddon,
|
|
4666
|
+
disabled = false,
|
|
4667
|
+
className = ""
|
|
4668
|
+
}) {
|
|
4669
|
+
const fields = (0, import_react22.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
|
|
4670
|
+
const idBase = (0, import_react22.useId)();
|
|
4671
|
+
const gesture = import_react22.default.useRef(null);
|
|
4672
|
+
const count = import_react22.default.useRef(0);
|
|
4673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
|
|
4674
|
+
(onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
3619
4675
|
"select",
|
|
3620
4676
|
{
|
|
3621
4677
|
className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
|
|
@@ -3623,12 +4679,18 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
3623
4679
|
value: "",
|
|
3624
4680
|
disabled,
|
|
3625
4681
|
onChange: (e) => {
|
|
3626
|
-
const
|
|
3627
|
-
if (
|
|
4682
|
+
const name = e.currentTarget.value;
|
|
4683
|
+
if (!name) return;
|
|
4684
|
+
if (onPresetName) {
|
|
4685
|
+
onPresetName(name);
|
|
4686
|
+
} else if (onPreset) {
|
|
4687
|
+
const preset = description.presets.find((p) => p.name === name);
|
|
4688
|
+
if (preset) onPreset({ ...description.defaults, ...preset.values });
|
|
4689
|
+
}
|
|
3628
4690
|
},
|
|
3629
4691
|
children: [
|
|
3630
|
-
/* @__PURE__ */ (0,
|
|
3631
|
-
description.presets.map((p) => /* @__PURE__ */ (0,
|
|
4692
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("option", { value: "", children: "Presets\u2026" }),
|
|
4693
|
+
description.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("option", { value: p.name, children: p.name }, p.name))
|
|
3632
4694
|
]
|
|
3633
4695
|
}
|
|
3634
4696
|
),
|
|
@@ -3638,13 +4700,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
3638
4700
|
const keyed = keyframed?.has(field.id) ?? false;
|
|
3639
4701
|
const value = (0, import_effects3.effectFieldValue)(field, values[field.id]);
|
|
3640
4702
|
const changed = !keyed && !(0, import_parameters2.parameterValuesEqual)(value, field.default);
|
|
3641
|
-
return /* @__PURE__ */ (0,
|
|
3642
|
-
/* @__PURE__ */ (0,
|
|
3643
|
-
/* @__PURE__ */ (0,
|
|
3644
|
-
keyed && /* @__PURE__ */ (0,
|
|
3645
|
-
|
|
4703
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "space-y-1", "data-effect-control": field.id, children: [
|
|
4704
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex items-center gap-1.5", children: [
|
|
4705
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
|
|
4706
|
+
keyed && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
|
|
4707
|
+
renderControlAddon?.(field.id),
|
|
4708
|
+
onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("button", { type: "button", className: "rounded px-1 text-[11px] text-muted-foreground hover:text-foreground", "aria-label": `Reset ${label}`, onClick: () => onReset(field.id), children: "\u21BA" })
|
|
3646
4709
|
] }),
|
|
3647
|
-
/* @__PURE__ */ (0,
|
|
4710
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
3648
4711
|
ParameterFieldControl,
|
|
3649
4712
|
{
|
|
3650
4713
|
field,
|
|
@@ -3658,25 +4721,25 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
3658
4721
|
)
|
|
3659
4722
|
] }, field.id);
|
|
3660
4723
|
}),
|
|
3661
|
-
!fields.length && /* @__PURE__ */ (0,
|
|
4724
|
+
!fields.length && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
|
|
3662
4725
|
] });
|
|
3663
4726
|
}
|
|
3664
4727
|
|
|
3665
4728
|
// src/vector/VectorProviderEffectsPanel.tsx
|
|
3666
|
-
var
|
|
3667
|
-
var
|
|
4729
|
+
var import_react23 = require("react");
|
|
4730
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
3668
4731
|
var btn = "rounded border border-border px-1.5 py-0.5 text-[11px] disabled:opacity-40";
|
|
3669
4732
|
function Controls({ controller, group }) {
|
|
3670
4733
|
const provider = controller.effectsProvider;
|
|
3671
4734
|
const tag = group.providerEffect;
|
|
3672
4735
|
const { description, error } = useEffectDescription(provider, tag.effect);
|
|
3673
|
-
const [message, setMessage] = (0,
|
|
4736
|
+
const [message, setMessage] = (0, import_react23.useState)(null);
|
|
3674
4737
|
const run = (work) => void work.then(() => setMessage(null), (e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
3675
|
-
if (!provider) return /* @__PURE__ */ (0,
|
|
3676
|
-
if (error) return /* @__PURE__ */ (0,
|
|
3677
|
-
if (!description) return /* @__PURE__ */ (0,
|
|
3678
|
-
return /* @__PURE__ */ (0,
|
|
3679
|
-
/* @__PURE__ */ (0,
|
|
4738
|
+
if (!provider) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider: the shapes are kept as they are." });
|
|
4739
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "text-[11px] text-amber-500", children: error });
|
|
4740
|
+
if (!description) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Loading\u2026" });
|
|
4741
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
4742
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
3680
4743
|
EffectParameters,
|
|
3681
4744
|
{
|
|
3682
4745
|
description,
|
|
@@ -3686,18 +4749,18 @@ function Controls({ controller, group }) {
|
|
|
3686
4749
|
onPreset: (v) => run(controller.updateVectorEffect(group.id, v))
|
|
3687
4750
|
}
|
|
3688
4751
|
),
|
|
3689
|
-
message && /* @__PURE__ */ (0,
|
|
4752
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
3690
4753
|
] });
|
|
3691
4754
|
}
|
|
3692
4755
|
function VectorProviderEffectsPanel({ controller, className = "" }) {
|
|
3693
4756
|
const state = useVectorEditorState(controller);
|
|
3694
|
-
const provider = (0,
|
|
4757
|
+
const provider = (0, import_react23.useSyncExternalStore)(
|
|
3695
4758
|
(cb) => controller.effects.subscribe(cb),
|
|
3696
4759
|
() => controller.effects.provider,
|
|
3697
4760
|
() => controller.effects.provider
|
|
3698
4761
|
);
|
|
3699
|
-
const [browse, setBrowse] = (0,
|
|
3700
|
-
const [message, setMessage] = (0,
|
|
4762
|
+
const [browse, setBrowse] = (0, import_react23.useState)(false);
|
|
4763
|
+
const [message, setMessage] = (0, import_react23.useState)(null);
|
|
3701
4764
|
void state;
|
|
3702
4765
|
const groups = controller.vectorEffectGroups();
|
|
3703
4766
|
const selected = groups.filter((g) => state.selection.includes(g.id));
|
|
@@ -3705,60 +4768,60 @@ function VectorProviderEffectsPanel({ controller, className = "" }) {
|
|
|
3705
4768
|
setMessage(null);
|
|
3706
4769
|
Promise.resolve().then(work).catch((e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
3707
4770
|
};
|
|
3708
|
-
return /* @__PURE__ */ (0,
|
|
3709
|
-
/* @__PURE__ */ (0,
|
|
3710
|
-
/* @__PURE__ */ (0,
|
|
3711
|
-
/* @__PURE__ */ (0,
|
|
4771
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("section", { className: `flex flex-col gap-2 text-xs ${className}`, "aria-label": "Vector effects", "data-vector-provider-effects": "", children: [
|
|
4772
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4773
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "flex-1 font-semibold", children: "Effects" }),
|
|
4774
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("button", { type: "button", className: btn, disabled: !provider, "aria-pressed": browse, onClick: () => setBrowse(!browse), children: "Add effect\u2026" })
|
|
3712
4775
|
] }),
|
|
3713
|
-
!provider && /* @__PURE__ */ (0,
|
|
3714
|
-
browse && /* @__PURE__ */ (0,
|
|
3715
|
-
selected.map((g) => /* @__PURE__ */ (0,
|
|
3716
|
-
/* @__PURE__ */ (0,
|
|
3717
|
-
/* @__PURE__ */ (0,
|
|
3718
|
-
/* @__PURE__ */ (0,
|
|
4776
|
+
!provider && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider is registered. Effect groups are kept as shapes." }),
|
|
4777
|
+
browse && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(EffectsBrowser, { provider, kinds: ["vector"], title: "Vector effects", onPick: (e) => (setBrowse(false), run(() => controller.addVectorEffect(e.id))) }),
|
|
4778
|
+
selected.map((g) => /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "space-y-1 rounded border border-border p-1", "data-vector-effect-group": g.id, children: [
|
|
4779
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4780
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "min-w-0 flex-1 truncate font-medium", children: g.providerEffect.name ?? g.providerEffect.effect }),
|
|
4781
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("button", { type: "button", className: btn, title: "Keep the shapes as a plain group", onClick: () => run(() => controller.detachVectorEffect(g.id)), children: "Detach" })
|
|
3719
4782
|
] }),
|
|
3720
|
-
/* @__PURE__ */ (0,
|
|
4783
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Controls, { controller, group: g })
|
|
3721
4784
|
] }, g.id)),
|
|
3722
|
-
groups.length > 0 && !selected.length && /* @__PURE__ */ (0,
|
|
4785
|
+
groups.length > 0 && !selected.length && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("p", { className: "text-[11px] text-muted-foreground", children: [
|
|
3723
4786
|
"Select an effect group (",
|
|
3724
4787
|
groups.length,
|
|
3725
4788
|
" in the drawing) to change it."
|
|
3726
4789
|
] }),
|
|
3727
|
-
message && /* @__PURE__ */ (0,
|
|
4790
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
3728
4791
|
] });
|
|
3729
4792
|
}
|
|
3730
4793
|
|
|
3731
4794
|
// src/vector/VectorEditor.tsx
|
|
3732
|
-
var
|
|
4795
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
3733
4796
|
function VectorEditor({ controller, tools, showStylePanel = true, height = 520, canvasProps, effects, className }) {
|
|
3734
4797
|
useEffects(controller, effects);
|
|
3735
4798
|
const effectsShown = !!effects || controller.vectorEffectGroups().length > 0;
|
|
3736
|
-
return /* @__PURE__ */ (0,
|
|
3737
|
-
/* @__PURE__ */ (0,
|
|
3738
|
-
/* @__PURE__ */ (0,
|
|
3739
|
-
/* @__PURE__ */ (0,
|
|
3740
|
-
showStylePanel && /* @__PURE__ */ (0,
|
|
3741
|
-
/* @__PURE__ */ (0,
|
|
3742
|
-
effectsShown && /* @__PURE__ */ (0,
|
|
4799
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: `flex flex-col gap-2 ${className ?? ""}`, "data-vector-editor": "", children: [
|
|
4800
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(VectorToolbar, { controller, tools }),
|
|
4801
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-h-0 flex-col gap-2 md:flex-row", children: [
|
|
4802
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: "relative min-h-[320px] flex-1 overflow-hidden rounded-md border border-border bg-muted/40", style: { height }, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(VectorCanvas, { controller, ...canvasProps }) }),
|
|
4803
|
+
showStylePanel && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex w-full shrink-0 flex-col gap-2 md:w-56", children: [
|
|
4804
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(VectorStylePanel, { controller, className: "rounded-md border border-border p-3" }),
|
|
4805
|
+
effectsShown && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(VectorProviderEffectsPanel, { controller, className: "rounded-md border border-border p-3" })
|
|
3743
4806
|
] })
|
|
3744
4807
|
] })
|
|
3745
4808
|
] });
|
|
3746
4809
|
}
|
|
3747
4810
|
|
|
3748
4811
|
// src/vector/VectorGeneratePanel.tsx
|
|
3749
|
-
var
|
|
4812
|
+
var import_react24 = require("react");
|
|
3750
4813
|
var import_vector21 = require("@pixerate/editor/vector");
|
|
3751
|
-
var
|
|
4814
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
3752
4815
|
var buttonClass17 = "inline-flex h-7 min-w-7 items-center justify-center rounded-md border border-border bg-background px-1.5 text-xs font-medium text-foreground hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40";
|
|
3753
4816
|
var selectClass15 = "h-7 min-w-0 flex-1 rounded border border-border bg-background px-1 text-xs";
|
|
3754
4817
|
var AS_LABELS = { color: "Traced in colour", threshold: "Traced in one colour", mosaic: "Mosaic", halftone: "Halftone", lowPoly: "Low poly", hatch: "Engraving" };
|
|
3755
4818
|
function VectorGeneratePanel({ controller, models, generate, className }) {
|
|
3756
4819
|
const usable = (0, import_vector21.vectorArtModels)(models);
|
|
3757
|
-
const [prompt, setPrompt] = (0,
|
|
3758
|
-
const [model, setModel] = (0,
|
|
3759
|
-
const [as, setAs] = (0,
|
|
3760
|
-
const [busy, setBusy] = (0,
|
|
3761
|
-
const [message, setMessage] = (0,
|
|
4820
|
+
const [prompt, setPrompt] = (0, import_react24.useState)("");
|
|
4821
|
+
const [model, setModel] = (0, import_react24.useState)("");
|
|
4822
|
+
const [as, setAs] = (0, import_react24.useState)("color");
|
|
4823
|
+
const [busy, setBusy] = (0, import_react24.useState)(false);
|
|
4824
|
+
const [message, setMessage] = (0, import_react24.useState)(null);
|
|
3762
4825
|
const chosen = usable.find((m) => m.id === model) ?? usable[0];
|
|
3763
4826
|
if (!usable.length) return null;
|
|
3764
4827
|
const run = async () => {
|
|
@@ -3768,18 +4831,18 @@ function VectorGeneratePanel({ controller, models, generate, className }) {
|
|
|
3768
4831
|
setBusy(false);
|
|
3769
4832
|
setMessage(r.ok ? null : r.message ?? "Generation failed.");
|
|
3770
4833
|
};
|
|
3771
|
-
return /* @__PURE__ */ (0,
|
|
3772
|
-
/* @__PURE__ */ (0,
|
|
3773
|
-
/* @__PURE__ */ (0,
|
|
3774
|
-
/* @__PURE__ */ (0,
|
|
3775
|
-
chosen.media === "image" && /* @__PURE__ */ (0,
|
|
4834
|
+
return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: `space-y-1 ${className ?? ""}`, "data-vector-generate-panel": "", "aria-label": "Generate", children: [
|
|
4835
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4836
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "w-16 text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: "Generate" }),
|
|
4837
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("select", { "aria-label": "Generation model", className: selectClass15, value: chosen.id, onChange: (e) => setModel(e.target.value), children: usable.map((m) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("option", { value: m.id, children: m.name ?? m.id }, m.id)) }),
|
|
4838
|
+
chosen.media === "image" && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("select", { "aria-label": "Image to vectors", className: selectClass15, value: as, onChange: (e) => setAs(e.target.value), children: import_vector21.VECTOR_GENERATED_IMAGE_AS.map((a) => /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("option", { value: a, children: AS_LABELS[a] }, a)) })
|
|
3776
4839
|
] }),
|
|
3777
|
-
/* @__PURE__ */ (0,
|
|
3778
|
-
/* @__PURE__ */ (0,
|
|
3779
|
-
/* @__PURE__ */ (0,
|
|
3780
|
-
/* @__PURE__ */ (0,
|
|
4840
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4841
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "w-16" }),
|
|
4842
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("input", { type: "text", "aria-label": "Prompt", placeholder: "Describe the art\u2026", className: "h-7 min-w-0 flex-1 rounded border border-border bg-background px-1.5 text-xs", value: prompt, onChange: (e) => setPrompt(e.target.value), onKeyDown: (e) => e.key === "Enter" && prompt.trim() && !busy && void run() }),
|
|
4843
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)("button", { type: "button", className: buttonClass17, "data-vector-generate-action": "", disabled: !prompt.trim() || busy, onClick: () => void run(), children: busy ? "Generating\u2026" : "Generate" })
|
|
3781
4844
|
] }),
|
|
3782
|
-
message && /* @__PURE__ */ (0,
|
|
4845
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("p", { className: "text-[11px] text-red-600", children: message })
|
|
3783
4846
|
] });
|
|
3784
4847
|
}
|
|
3785
4848
|
// Annotate the CommonJS export names for ESM import in node:
|