@pixerate/editor-react 0.94.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 +3 -1
- package/dist/animation-editor/index.cjs +1240 -195
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1419 -372
- package/dist/canvas/index.js +9 -4
- package/dist/canvas/useMermaidDiagram.d.cts +7 -1
- package/dist/canvas/useMermaidDiagram.d.ts +7 -1
- 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/{chunk-NNM633RN.js → chunk-R7MEGRPV.js} +23 -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 +2181 -1115
- package/dist/index.js +9 -5
- 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/persistence/index.cjs +25 -4
- package/dist/persistence/index.d.cts +1 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +5 -3
- package/dist/persistence/useEditorAutosave.d.cts +17 -0
- package/dist/persistence/useEditorAutosave.d.ts +17 -0
- 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-
|
|
@@ -1334,7 +1335,7 @@ var StickerPanel = ({ controller, className }) => {
|
|
|
1334
1335
|
};
|
|
1335
1336
|
|
|
1336
1337
|
// src/paint-editor/PaintEditor.tsx
|
|
1337
|
-
var
|
|
1338
|
+
var import_react23 = require("react");
|
|
1338
1339
|
var import_paint_editor14 = require("@pixerate/editor/paint-editor");
|
|
1339
1340
|
|
|
1340
1341
|
// src/playback/AgentPlaybackContext.tsx
|
|
@@ -1425,7 +1426,7 @@ function PresenceLayer({ presence, viewport, className = "" }) {
|
|
|
1425
1426
|
}
|
|
1426
1427
|
|
|
1427
1428
|
// src/paint-editor/PaintEffectsPanel.tsx
|
|
1428
|
-
var
|
|
1429
|
+
var import_react22 = require("react");
|
|
1429
1430
|
var import_paint_editor13 = require("@pixerate/editor/paint-editor");
|
|
1430
1431
|
|
|
1431
1432
|
// src/effects/useEffects.ts
|
|
@@ -1559,14 +1560,1055 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
1559
1560
|
}
|
|
1560
1561
|
|
|
1561
1562
|
// src/effects/EffectParameters.tsx
|
|
1562
|
-
var
|
|
1563
|
+
var import_react21 = __toESM(require("react"), 1);
|
|
1563
1564
|
var import_effects3 = require("@pixerate/editor/effects");
|
|
1564
1565
|
var import_parameters2 = require("@pixerate/editor/parameters");
|
|
1565
1566
|
|
|
1566
1567
|
// src/parameters/fields.tsx
|
|
1567
|
-
var
|
|
1568
|
+
var import_react20 = require("react");
|
|
1568
1569
|
var import_parameters = require("@pixerate/editor/parameters");
|
|
1570
|
+
|
|
1571
|
+
// src/color/index.ts
|
|
1572
|
+
var color_exports = {};
|
|
1573
|
+
__export(color_exports, {
|
|
1574
|
+
ColorPicker: () => ColorPicker,
|
|
1575
|
+
DualColorPicker: () => DualColorPicker,
|
|
1576
|
+
useColorScheme: () => useColorScheme,
|
|
1577
|
+
useResolvedColor: () => useResolvedColor
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1580
|
+
// src/color/ColorPicker.tsx
|
|
1581
|
+
var import_react17 = require("react");
|
|
1582
|
+
var import_color = require("@pixerate/editor/color");
|
|
1569
1583
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1584
|
+
var LOCAL_STORAGE_KEY = "pixerate:color:recent";
|
|
1585
|
+
function readLocalRecents() {
|
|
1586
|
+
try {
|
|
1587
|
+
if (typeof localStorage === "undefined") return [];
|
|
1588
|
+
const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
1589
|
+
if (!raw) return [];
|
|
1590
|
+
const parsed = JSON.parse(raw);
|
|
1591
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
1592
|
+
} catch {
|
|
1593
|
+
return [];
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function writeLocalRecents(list) {
|
|
1597
|
+
try {
|
|
1598
|
+
if (typeof localStorage !== "undefined") {
|
|
1599
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
|
|
1600
|
+
}
|
|
1601
|
+
} catch {
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
|
|
1605
|
+
var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
|
|
1606
|
+
var ColorPicker = ({
|
|
1607
|
+
value,
|
|
1608
|
+
onChange,
|
|
1609
|
+
onGestureStart,
|
|
1610
|
+
onGestureEnd,
|
|
1611
|
+
alpha = false,
|
|
1612
|
+
swatches,
|
|
1613
|
+
recent: controlledRecent,
|
|
1614
|
+
onRecentChange,
|
|
1615
|
+
contrastAgainst,
|
|
1616
|
+
disabled = false,
|
|
1617
|
+
className,
|
|
1618
|
+
id,
|
|
1619
|
+
"aria-label": ariaLabel = "Color picker"
|
|
1620
|
+
}) => {
|
|
1621
|
+
const generatedId = (0, import_react17.useId)();
|
|
1622
|
+
const pickerId = id || generatedId;
|
|
1623
|
+
const [pickerState, setPickerState] = (0, import_react17.useState)(
|
|
1624
|
+
() => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
|
|
1625
|
+
);
|
|
1626
|
+
const stateRef = (0, import_react17.useRef)(pickerState);
|
|
1627
|
+
stateRef.current = pickerState;
|
|
1628
|
+
(0, import_react17.useEffect)(() => {
|
|
1629
|
+
const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
|
|
1630
|
+
if (next) {
|
|
1631
|
+
setPickerState(next);
|
|
1632
|
+
}
|
|
1633
|
+
}, [value]);
|
|
1634
|
+
const [internalRecent, setInternalRecent] = (0, import_react17.useState)(
|
|
1635
|
+
() => controlledRecent ? [] : readLocalRecents()
|
|
1636
|
+
);
|
|
1637
|
+
const activeRecent = controlledRecent ?? internalRecent;
|
|
1638
|
+
const recordRecent = (0, import_react17.useCallback)(
|
|
1639
|
+
(color) => {
|
|
1640
|
+
const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
|
|
1641
|
+
if (!controlledRecent) {
|
|
1642
|
+
setInternalRecent(updated);
|
|
1643
|
+
writeLocalRecents(updated);
|
|
1644
|
+
}
|
|
1645
|
+
onRecentChange?.(updated);
|
|
1646
|
+
},
|
|
1647
|
+
[activeRecent, controlledRecent, onRecentChange]
|
|
1648
|
+
);
|
|
1649
|
+
const [textDraft, setTextDraft] = (0, import_react17.useState)(value);
|
|
1650
|
+
const [isInvalid, setIsInvalid] = (0, import_react17.useState)(false);
|
|
1651
|
+
const [isClipped, setIsClipped] = (0, import_react17.useState)(false);
|
|
1652
|
+
const isTypingRef = (0, import_react17.useRef)(false);
|
|
1653
|
+
(0, import_react17.useEffect)(() => {
|
|
1654
|
+
if (!isTypingRef.current) {
|
|
1655
|
+
setTextDraft(value);
|
|
1656
|
+
setIsInvalid(false);
|
|
1657
|
+
const parsed = (0, import_color.parseColor)(value);
|
|
1658
|
+
setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
|
|
1659
|
+
}
|
|
1660
|
+
}, [value]);
|
|
1661
|
+
const [hasEyeDropper, setHasEyeDropper] = (0, import_react17.useState)(false);
|
|
1662
|
+
(0, import_react17.useEffect)(() => {
|
|
1663
|
+
setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
|
|
1664
|
+
}, []);
|
|
1665
|
+
const emitColorChange = (0, import_react17.useCallback)(
|
|
1666
|
+
(nextState) => {
|
|
1667
|
+
setPickerState(nextState);
|
|
1668
|
+
const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
|
|
1669
|
+
onChange(hex);
|
|
1670
|
+
},
|
|
1671
|
+
[alpha, onChange]
|
|
1672
|
+
);
|
|
1673
|
+
const latest = (0, import_react17.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
|
|
1674
|
+
latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
|
|
1675
|
+
const endDragRef = (0, import_react17.useRef)(null);
|
|
1676
|
+
(0, import_react17.useEffect)(() => () => endDragRef.current?.(), []);
|
|
1677
|
+
const startDrag = (e, next) => {
|
|
1678
|
+
if (disabled) return;
|
|
1679
|
+
e.preventDefault();
|
|
1680
|
+
endDragRef.current?.();
|
|
1681
|
+
onGestureStart?.();
|
|
1682
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
1683
|
+
const update = (clientX, clientY) => {
|
|
1684
|
+
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
1685
|
+
const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
|
|
1686
|
+
latest.current.emitColorChange(next(stateRef.current, x, y));
|
|
1687
|
+
};
|
|
1688
|
+
update(e.clientX, e.clientY);
|
|
1689
|
+
const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
|
|
1690
|
+
const end = () => {
|
|
1691
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
1692
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
1693
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
1694
|
+
endDragRef.current = null;
|
|
1695
|
+
latest.current.onGestureEnd?.();
|
|
1696
|
+
};
|
|
1697
|
+
const onPointerUp = () => {
|
|
1698
|
+
end();
|
|
1699
|
+
latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
|
|
1700
|
+
};
|
|
1701
|
+
endDragRef.current = end;
|
|
1702
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
1703
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
1704
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
1705
|
+
};
|
|
1706
|
+
const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
|
|
1707
|
+
const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
|
|
1708
|
+
const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
|
|
1709
|
+
const handleAreaKeyDown = (e) => {
|
|
1710
|
+
if (disabled) return;
|
|
1711
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
|
|
1712
|
+
if (next) {
|
|
1713
|
+
e.preventDefault();
|
|
1714
|
+
emitColorChange(next);
|
|
1715
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
const handleHueKeyDown = (e) => {
|
|
1719
|
+
if (disabled) return;
|
|
1720
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
|
|
1721
|
+
if (next) {
|
|
1722
|
+
e.preventDefault();
|
|
1723
|
+
emitColorChange(next);
|
|
1724
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
const handleAlphaKeyDown = (e) => {
|
|
1728
|
+
if (disabled) return;
|
|
1729
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
|
|
1730
|
+
if (next) {
|
|
1731
|
+
e.preventDefault();
|
|
1732
|
+
emitColorChange(next);
|
|
1733
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
const commitTextInput = (inputElement) => {
|
|
1737
|
+
isTypingRef.current = false;
|
|
1738
|
+
const parsed = (0, import_color.parseColor)(textDraft);
|
|
1739
|
+
if (parsed) {
|
|
1740
|
+
setIsInvalid(false);
|
|
1741
|
+
setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
|
|
1742
|
+
const formatted = (0, import_color.formatHex)(parsed);
|
|
1743
|
+
onChange(formatted);
|
|
1744
|
+
recordRecent(formatted);
|
|
1745
|
+
} else {
|
|
1746
|
+
setIsInvalid(true);
|
|
1747
|
+
setTextDraft(value);
|
|
1748
|
+
if (inputElement) {
|
|
1749
|
+
inputElement.value = value;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
const handleTextKeyDown = (e) => {
|
|
1754
|
+
if (e.key === "Enter") {
|
|
1755
|
+
e.preventDefault();
|
|
1756
|
+
commitTextInput(e.currentTarget);
|
|
1757
|
+
} else if (e.key === "Escape") {
|
|
1758
|
+
e.preventDefault();
|
|
1759
|
+
isTypingRef.current = false;
|
|
1760
|
+
setIsInvalid(false);
|
|
1761
|
+
setTextDraft(value);
|
|
1762
|
+
e.currentTarget.value = value;
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
const handleEyeDropper = async () => {
|
|
1766
|
+
if (disabled || !hasEyeDropper) return;
|
|
1767
|
+
try {
|
|
1768
|
+
const EyeDropperClass = window.EyeDropper;
|
|
1769
|
+
const eyeDropper = new EyeDropperClass();
|
|
1770
|
+
const res = await eyeDropper.open();
|
|
1771
|
+
if (res?.sRGBHex) {
|
|
1772
|
+
onChange(res.sRGBHex);
|
|
1773
|
+
recordRecent(res.sRGBHex);
|
|
1774
|
+
}
|
|
1775
|
+
} catch {
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
const contrastResult = (0, import_react17.useMemo)(() => {
|
|
1779
|
+
if (!contrastAgainst) return null;
|
|
1780
|
+
const fg = (0, import_color.parseColor)(value);
|
|
1781
|
+
const bg = (0, import_color.parseColor)(contrastAgainst);
|
|
1782
|
+
if (!fg || !bg) return null;
|
|
1783
|
+
const ratio = (0, import_color.contrastRatio)(fg, bg);
|
|
1784
|
+
const aa = ratio >= 4.5;
|
|
1785
|
+
const aaa = ratio >= 7;
|
|
1786
|
+
return { ratio, aa, aaa };
|
|
1787
|
+
}, [value, contrastAgainst]);
|
|
1788
|
+
const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
|
|
1789
|
+
const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
|
|
1790
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1791
|
+
"div",
|
|
1792
|
+
{
|
|
1793
|
+
id: pickerId,
|
|
1794
|
+
role: "group",
|
|
1795
|
+
"aria-label": ariaLabel,
|
|
1796
|
+
className,
|
|
1797
|
+
style: {
|
|
1798
|
+
boxSizing: "border-box",
|
|
1799
|
+
width: "var(--pixerate-color-picker-width, 240px)",
|
|
1800
|
+
borderRadius: "var(--pixerate-color-picker-radius, 8px)",
|
|
1801
|
+
background: "var(--pixerate-color-picker-bg, #1f2430)",
|
|
1802
|
+
color: "var(--pixerate-color-picker-fg, #f0f2f5)",
|
|
1803
|
+
padding: "12px",
|
|
1804
|
+
display: "flex",
|
|
1805
|
+
flexDirection: "column",
|
|
1806
|
+
gap: "10px",
|
|
1807
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
1808
|
+
fontSize: "12px",
|
|
1809
|
+
userSelect: "none",
|
|
1810
|
+
opacity: disabled ? 0.6 : 1,
|
|
1811
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
1812
|
+
},
|
|
1813
|
+
children: [
|
|
1814
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1815
|
+
"span",
|
|
1816
|
+
{
|
|
1817
|
+
role: "status",
|
|
1818
|
+
"aria-live": "polite",
|
|
1819
|
+
style: {
|
|
1820
|
+
position: "absolute",
|
|
1821
|
+
width: "1px",
|
|
1822
|
+
height: "1px",
|
|
1823
|
+
padding: 0,
|
|
1824
|
+
margin: "-1px",
|
|
1825
|
+
overflow: "hidden",
|
|
1826
|
+
clip: "rect(0, 0, 0, 0)",
|
|
1827
|
+
whiteSpace: "nowrap",
|
|
1828
|
+
border: 0
|
|
1829
|
+
},
|
|
1830
|
+
children: liveDescription
|
|
1831
|
+
}
|
|
1832
|
+
),
|
|
1833
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1834
|
+
"div",
|
|
1835
|
+
{
|
|
1836
|
+
role: "slider",
|
|
1837
|
+
tabIndex: disabled ? -1 : 0,
|
|
1838
|
+
"aria-label": "Saturation and brightness",
|
|
1839
|
+
"aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
|
|
1840
|
+
pickerState.v * 100
|
|
1841
|
+
)}%`,
|
|
1842
|
+
"aria-disabled": disabled,
|
|
1843
|
+
onPointerDown: handleAreaPointerDown,
|
|
1844
|
+
onKeyDown: handleAreaKeyDown,
|
|
1845
|
+
style: {
|
|
1846
|
+
position: "relative",
|
|
1847
|
+
width: "100%",
|
|
1848
|
+
height: "150px",
|
|
1849
|
+
borderRadius: "6px",
|
|
1850
|
+
background: (0, import_color.pickerAreaBackground)(pickerState),
|
|
1851
|
+
cursor: disabled ? "default" : "crosshair",
|
|
1852
|
+
touchAction: "none",
|
|
1853
|
+
outline: "none"
|
|
1854
|
+
},
|
|
1855
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1856
|
+
"div",
|
|
1857
|
+
{
|
|
1858
|
+
style: {
|
|
1859
|
+
position: "absolute",
|
|
1860
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1861
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1862
|
+
borderRadius: "50%",
|
|
1863
|
+
transform: "translate(-50%, -50%)",
|
|
1864
|
+
left: `${pickerState.s * 100}%`,
|
|
1865
|
+
top: `${(1 - pickerState.v) * 100}%`,
|
|
1866
|
+
border: "2px solid #ffffff",
|
|
1867
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
1868
|
+
pointerEvents: "none",
|
|
1869
|
+
backgroundColor: currentHex
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
)
|
|
1873
|
+
}
|
|
1874
|
+
),
|
|
1875
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1876
|
+
"div",
|
|
1877
|
+
{
|
|
1878
|
+
role: "slider",
|
|
1879
|
+
tabIndex: disabled ? -1 : 0,
|
|
1880
|
+
"aria-label": "Hue",
|
|
1881
|
+
"aria-valuenow": Math.round(pickerState.h),
|
|
1882
|
+
"aria-valuemin": 0,
|
|
1883
|
+
"aria-valuemax": 360,
|
|
1884
|
+
"aria-valuetext": `${Math.round(pickerState.h)} degrees`,
|
|
1885
|
+
"aria-disabled": disabled,
|
|
1886
|
+
onPointerDown: handleHuePointerDown,
|
|
1887
|
+
onKeyDown: handleHueKeyDown,
|
|
1888
|
+
style: {
|
|
1889
|
+
position: "relative",
|
|
1890
|
+
width: "100%",
|
|
1891
|
+
height: "12px",
|
|
1892
|
+
borderRadius: "6px",
|
|
1893
|
+
background: import_color.PICKER_HUE_BACKGROUND,
|
|
1894
|
+
cursor: disabled ? "default" : "pointer",
|
|
1895
|
+
touchAction: "none",
|
|
1896
|
+
outline: "none"
|
|
1897
|
+
},
|
|
1898
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1899
|
+
"div",
|
|
1900
|
+
{
|
|
1901
|
+
style: {
|
|
1902
|
+
position: "absolute",
|
|
1903
|
+
top: "50%",
|
|
1904
|
+
transform: "translate(-50%, -50%)",
|
|
1905
|
+
left: `${pickerState.h / 360 * 100}%`,
|
|
1906
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1907
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1908
|
+
borderRadius: "50%",
|
|
1909
|
+
border: "2px solid #ffffff",
|
|
1910
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
1911
|
+
pointerEvents: "none",
|
|
1912
|
+
backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
)
|
|
1916
|
+
}
|
|
1917
|
+
),
|
|
1918
|
+
alpha && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1919
|
+
"div",
|
|
1920
|
+
{
|
|
1921
|
+
role: "slider",
|
|
1922
|
+
tabIndex: disabled ? -1 : 0,
|
|
1923
|
+
"aria-label": "Alpha",
|
|
1924
|
+
"aria-valuenow": Math.round(pickerState.alpha * 100),
|
|
1925
|
+
"aria-valuemin": 0,
|
|
1926
|
+
"aria-valuemax": 100,
|
|
1927
|
+
"aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
|
|
1928
|
+
"aria-disabled": disabled,
|
|
1929
|
+
onPointerDown: handleAlphaPointerDown,
|
|
1930
|
+
onKeyDown: handleAlphaKeyDown,
|
|
1931
|
+
style: {
|
|
1932
|
+
position: "relative",
|
|
1933
|
+
width: "100%",
|
|
1934
|
+
height: "12px",
|
|
1935
|
+
borderRadius: "6px",
|
|
1936
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
1937
|
+
backgroundSize: "8px 8px",
|
|
1938
|
+
cursor: disabled ? "default" : "pointer",
|
|
1939
|
+
touchAction: "none",
|
|
1940
|
+
outline: "none",
|
|
1941
|
+
overflow: "hidden"
|
|
1942
|
+
},
|
|
1943
|
+
children: [
|
|
1944
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1945
|
+
"div",
|
|
1946
|
+
{
|
|
1947
|
+
style: {
|
|
1948
|
+
position: "absolute",
|
|
1949
|
+
inset: 0,
|
|
1950
|
+
background: (0, import_color.pickerAlphaBackground)(pickerState)
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
),
|
|
1954
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1955
|
+
"div",
|
|
1956
|
+
{
|
|
1957
|
+
style: {
|
|
1958
|
+
position: "absolute",
|
|
1959
|
+
top: "50%",
|
|
1960
|
+
transform: "translate(-50%, -50%)",
|
|
1961
|
+
left: `${pickerState.alpha * 100}%`,
|
|
1962
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1963
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
1964
|
+
borderRadius: "50%",
|
|
1965
|
+
border: "2px solid #ffffff",
|
|
1966
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
1967
|
+
pointerEvents: "none",
|
|
1968
|
+
backgroundColor: currentHex
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
)
|
|
1972
|
+
]
|
|
1973
|
+
}
|
|
1974
|
+
),
|
|
1975
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
|
|
1976
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1977
|
+
"div",
|
|
1978
|
+
{
|
|
1979
|
+
style: {
|
|
1980
|
+
position: "relative",
|
|
1981
|
+
width: "28px",
|
|
1982
|
+
height: "28px",
|
|
1983
|
+
borderRadius: "4px",
|
|
1984
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
1985
|
+
backgroundSize: "8px 8px",
|
|
1986
|
+
overflow: "hidden",
|
|
1987
|
+
flexShrink: 0,
|
|
1988
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
1989
|
+
},
|
|
1990
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1991
|
+
"div",
|
|
1992
|
+
{
|
|
1993
|
+
style: {
|
|
1994
|
+
width: "100%",
|
|
1995
|
+
height: "100%",
|
|
1996
|
+
backgroundColor: currentHex
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
)
|
|
2000
|
+
}
|
|
2001
|
+
),
|
|
2002
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2003
|
+
"input",
|
|
2004
|
+
{
|
|
2005
|
+
type: "text",
|
|
2006
|
+
value: textDraft,
|
|
2007
|
+
disabled,
|
|
2008
|
+
"aria-label": "Color hex or CSS string",
|
|
2009
|
+
"aria-invalid": isInvalid ? "true" : void 0,
|
|
2010
|
+
onChange: (e) => {
|
|
2011
|
+
isTypingRef.current = true;
|
|
2012
|
+
setTextDraft(e.target.value);
|
|
2013
|
+
setIsInvalid(false);
|
|
2014
|
+
},
|
|
2015
|
+
onKeyDown: handleTextKeyDown,
|
|
2016
|
+
onBlur: (e) => commitTextInput(e.currentTarget),
|
|
2017
|
+
style: {
|
|
2018
|
+
flex: 1,
|
|
2019
|
+
minWidth: 0,
|
|
2020
|
+
height: "28px",
|
|
2021
|
+
padding: "0 8px",
|
|
2022
|
+
fontSize: "12px",
|
|
2023
|
+
fontFamily: "monospace",
|
|
2024
|
+
borderRadius: "4px",
|
|
2025
|
+
border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
|
|
2026
|
+
background: "rgba(0,0,0,0.2)",
|
|
2027
|
+
color: "inherit",
|
|
2028
|
+
outline: "none"
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
),
|
|
2032
|
+
hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2033
|
+
"button",
|
|
2034
|
+
{
|
|
2035
|
+
type: "button",
|
|
2036
|
+
disabled,
|
|
2037
|
+
"aria-label": "Pick color from screen",
|
|
2038
|
+
title: "Pick color from screen",
|
|
2039
|
+
onClick: handleEyeDropper,
|
|
2040
|
+
style: {
|
|
2041
|
+
display: "inline-flex",
|
|
2042
|
+
alignItems: "center",
|
|
2043
|
+
justifyContent: "center",
|
|
2044
|
+
width: "28px",
|
|
2045
|
+
height: "28px",
|
|
2046
|
+
borderRadius: "4px",
|
|
2047
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
2048
|
+
background: "transparent",
|
|
2049
|
+
color: "inherit",
|
|
2050
|
+
cursor: disabled ? "default" : "pointer"
|
|
2051
|
+
},
|
|
2052
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
2053
|
+
"svg",
|
|
2054
|
+
{
|
|
2055
|
+
width: "14",
|
|
2056
|
+
height: "14",
|
|
2057
|
+
viewBox: "0 0 24 24",
|
|
2058
|
+
fill: "none",
|
|
2059
|
+
stroke: "currentColor",
|
|
2060
|
+
strokeWidth: "2",
|
|
2061
|
+
strokeLinecap: "round",
|
|
2062
|
+
strokeLinejoin: "round",
|
|
2063
|
+
children: [
|
|
2064
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.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" }),
|
|
2065
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
|
|
2066
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("path", { d: "m14 6 4 4" })
|
|
2067
|
+
]
|
|
2068
|
+
}
|
|
2069
|
+
)
|
|
2070
|
+
}
|
|
2071
|
+
)
|
|
2072
|
+
] }),
|
|
2073
|
+
isClipped && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2074
|
+
"div",
|
|
2075
|
+
{
|
|
2076
|
+
role: "note",
|
|
2077
|
+
title: "This colour was outside standard sRGB and clipped.",
|
|
2078
|
+
style: {
|
|
2079
|
+
display: "inline-flex",
|
|
2080
|
+
alignItems: "center",
|
|
2081
|
+
gap: "4px",
|
|
2082
|
+
fontSize: "10px",
|
|
2083
|
+
color: "#f59e0b",
|
|
2084
|
+
background: "rgba(245, 158, 11, 0.1)",
|
|
2085
|
+
padding: "2px 6px",
|
|
2086
|
+
borderRadius: "4px",
|
|
2087
|
+
alignSelf: "flex-start"
|
|
2088
|
+
},
|
|
2089
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
|
|
2090
|
+
}
|
|
2091
|
+
),
|
|
2092
|
+
contrastResult && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
2093
|
+
"div",
|
|
2094
|
+
{
|
|
2095
|
+
style: {
|
|
2096
|
+
display: "flex",
|
|
2097
|
+
alignItems: "center",
|
|
2098
|
+
justifyContent: "space-between",
|
|
2099
|
+
fontSize: "11px",
|
|
2100
|
+
padding: "4px 8px",
|
|
2101
|
+
borderRadius: "4px",
|
|
2102
|
+
background: "rgba(255,255,255,0.05)",
|
|
2103
|
+
border: "1px solid rgba(255,255,255,0.1)"
|
|
2104
|
+
},
|
|
2105
|
+
children: [
|
|
2106
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { children: [
|
|
2107
|
+
"Contrast: ",
|
|
2108
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("strong", { children: [
|
|
2109
|
+
contrastResult.ratio.toFixed(2),
|
|
2110
|
+
":1"
|
|
2111
|
+
] })
|
|
2112
|
+
] }),
|
|
2113
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
2114
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
2115
|
+
"span",
|
|
2116
|
+
{
|
|
2117
|
+
style: {
|
|
2118
|
+
color: contrastResult.aa ? "#10b981" : "#ef4444",
|
|
2119
|
+
fontWeight: 600
|
|
2120
|
+
},
|
|
2121
|
+
children: [
|
|
2122
|
+
"AA ",
|
|
2123
|
+
contrastResult.aa ? "\u2713" : "\u2717"
|
|
2124
|
+
]
|
|
2125
|
+
}
|
|
2126
|
+
),
|
|
2127
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
2128
|
+
"span",
|
|
2129
|
+
{
|
|
2130
|
+
style: {
|
|
2131
|
+
color: contrastResult.aaa ? "#10b981" : "#ef4444",
|
|
2132
|
+
fontWeight: 600
|
|
2133
|
+
},
|
|
2134
|
+
children: [
|
|
2135
|
+
"AAA ",
|
|
2136
|
+
contrastResult.aaa ? "\u2713" : "\u2717"
|
|
2137
|
+
]
|
|
2138
|
+
}
|
|
2139
|
+
)
|
|
2140
|
+
] })
|
|
2141
|
+
]
|
|
2142
|
+
}
|
|
2143
|
+
),
|
|
2144
|
+
swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
2145
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
|
|
2146
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2147
|
+
"button",
|
|
2148
|
+
{
|
|
2149
|
+
type: "button",
|
|
2150
|
+
"data-testid": "color-picker-swatch",
|
|
2151
|
+
title: color,
|
|
2152
|
+
disabled,
|
|
2153
|
+
"aria-label": `Color ${color}`,
|
|
2154
|
+
onClick: () => {
|
|
2155
|
+
onChange(color);
|
|
2156
|
+
recordRecent(color);
|
|
2157
|
+
},
|
|
2158
|
+
style: {
|
|
2159
|
+
width: "18px",
|
|
2160
|
+
height: "18px",
|
|
2161
|
+
borderRadius: "3px",
|
|
2162
|
+
backgroundColor: color,
|
|
2163
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
2164
|
+
cursor: disabled ? "default" : "pointer",
|
|
2165
|
+
padding: 0,
|
|
2166
|
+
outline: "none"
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
`${color}-${idx}`
|
|
2170
|
+
)) })
|
|
2171
|
+
] }),
|
|
2172
|
+
activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
2173
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
|
|
2174
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2175
|
+
"button",
|
|
2176
|
+
{
|
|
2177
|
+
type: "button",
|
|
2178
|
+
"data-testid": "color-picker-recent",
|
|
2179
|
+
disabled,
|
|
2180
|
+
"aria-label": `Color ${color}`,
|
|
2181
|
+
onClick: () => {
|
|
2182
|
+
onChange(color);
|
|
2183
|
+
recordRecent(color);
|
|
2184
|
+
},
|
|
2185
|
+
style: {
|
|
2186
|
+
width: "18px",
|
|
2187
|
+
height: "18px",
|
|
2188
|
+
borderRadius: "3px",
|
|
2189
|
+
backgroundColor: color,
|
|
2190
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
2191
|
+
cursor: disabled ? "default" : "pointer",
|
|
2192
|
+
padding: 0,
|
|
2193
|
+
outline: "none"
|
|
2194
|
+
}
|
|
2195
|
+
},
|
|
2196
|
+
`recent-${color}-${idx}`
|
|
2197
|
+
)) })
|
|
2198
|
+
] })
|
|
2199
|
+
]
|
|
2200
|
+
}
|
|
2201
|
+
);
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2204
|
+
// src/color/DualColorPicker.tsx
|
|
2205
|
+
var import_react18 = require("react");
|
|
2206
|
+
var import_color2 = require("@pixerate/editor/color");
|
|
2207
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2208
|
+
function DualColorPicker({
|
|
2209
|
+
value,
|
|
2210
|
+
onChange,
|
|
2211
|
+
onGestureStart,
|
|
2212
|
+
onGestureEnd,
|
|
2213
|
+
scheme: controlledScheme,
|
|
2214
|
+
onSchemeChange,
|
|
2215
|
+
surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
|
|
2216
|
+
contrastAgainst,
|
|
2217
|
+
alpha = false,
|
|
2218
|
+
swatches,
|
|
2219
|
+
disabled = false,
|
|
2220
|
+
className = ""
|
|
2221
|
+
}) {
|
|
2222
|
+
const sameId = (0, import_react18.useId)();
|
|
2223
|
+
const [internalScheme, setInternalScheme] = (0, import_react18.useState)("light");
|
|
2224
|
+
const activeScheme = controlledScheme ?? internalScheme;
|
|
2225
|
+
const handleSchemeSelect = (nextScheme) => {
|
|
2226
|
+
if (onSchemeChange) {
|
|
2227
|
+
onSchemeChange(nextScheme);
|
|
2228
|
+
} else {
|
|
2229
|
+
setInternalScheme(nextScheme);
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
|
|
2233
|
+
const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
|
|
2234
|
+
const [sameInBoth, setSameInBoth] = (0, import_react18.useState)(isSame);
|
|
2235
|
+
const handleSameToggle = (e) => {
|
|
2236
|
+
const nextSame = e.target.checked;
|
|
2237
|
+
setSameInBoth(nextSame);
|
|
2238
|
+
if (nextSame) {
|
|
2239
|
+
const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2240
|
+
onChange({ light: activeVal, dark: activeVal });
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
const handleDerive = () => {
|
|
2244
|
+
if (disabled) return;
|
|
2245
|
+
onGestureStart?.();
|
|
2246
|
+
const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2247
|
+
const derived = (0, import_color2.deriveDualColor)(currentActive, {
|
|
2248
|
+
from: activeScheme,
|
|
2249
|
+
// An unreadable surfaces prop falls back to the defaults rather than throwing.
|
|
2250
|
+
surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
|
|
2251
|
+
});
|
|
2252
|
+
onChange(derived);
|
|
2253
|
+
onGestureEnd?.();
|
|
2254
|
+
};
|
|
2255
|
+
const handleInnerChange = (hex) => {
|
|
2256
|
+
if (sameInBoth) {
|
|
2257
|
+
onChange({ light: hex, dark: hex });
|
|
2258
|
+
} else {
|
|
2259
|
+
const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
|
|
2260
|
+
onChange(updated);
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2264
|
+
const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
|
|
2265
|
+
const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
|
|
2266
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2267
|
+
"div",
|
|
2268
|
+
{
|
|
2269
|
+
className: `pixerate-dual-color-picker ${className}`,
|
|
2270
|
+
style: {
|
|
2271
|
+
display: "flex",
|
|
2272
|
+
flexDirection: "column",
|
|
2273
|
+
gap: "12px",
|
|
2274
|
+
padding: "12px",
|
|
2275
|
+
background: "#1a1d24",
|
|
2276
|
+
color: "#e2e8f0",
|
|
2277
|
+
borderRadius: "10px",
|
|
2278
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
2279
|
+
width: "260px",
|
|
2280
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
2281
|
+
fontSize: "13px",
|
|
2282
|
+
boxSizing: "border-box"
|
|
2283
|
+
},
|
|
2284
|
+
children: [
|
|
2285
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2286
|
+
"div",
|
|
2287
|
+
{
|
|
2288
|
+
role: "tablist",
|
|
2289
|
+
"aria-label": "Color scheme mode",
|
|
2290
|
+
style: {
|
|
2291
|
+
display: "flex",
|
|
2292
|
+
background: "#111318",
|
|
2293
|
+
borderRadius: "6px",
|
|
2294
|
+
padding: "2px",
|
|
2295
|
+
gap: "2px"
|
|
2296
|
+
},
|
|
2297
|
+
children: [
|
|
2298
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2299
|
+
"button",
|
|
2300
|
+
{
|
|
2301
|
+
type: "button",
|
|
2302
|
+
role: "tab",
|
|
2303
|
+
"aria-selected": activeScheme === "light",
|
|
2304
|
+
onClick: () => handleSchemeSelect("light"),
|
|
2305
|
+
disabled,
|
|
2306
|
+
style: {
|
|
2307
|
+
flex: 1,
|
|
2308
|
+
padding: "6px 8px",
|
|
2309
|
+
border: "none",
|
|
2310
|
+
borderRadius: "4px",
|
|
2311
|
+
background: activeScheme === "light" ? "#2d3342" : "transparent",
|
|
2312
|
+
color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
|
|
2313
|
+
fontWeight: activeScheme === "light" ? 600 : 400,
|
|
2314
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2315
|
+
fontSize: "12px",
|
|
2316
|
+
transition: "all 0.15s ease"
|
|
2317
|
+
},
|
|
2318
|
+
children: "Light"
|
|
2319
|
+
}
|
|
2320
|
+
),
|
|
2321
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2322
|
+
"button",
|
|
2323
|
+
{
|
|
2324
|
+
type: "button",
|
|
2325
|
+
role: "tab",
|
|
2326
|
+
"aria-selected": activeScheme === "dark",
|
|
2327
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
2328
|
+
disabled,
|
|
2329
|
+
style: {
|
|
2330
|
+
flex: 1,
|
|
2331
|
+
padding: "6px 8px",
|
|
2332
|
+
border: "none",
|
|
2333
|
+
borderRadius: "4px",
|
|
2334
|
+
background: activeScheme === "dark" ? "#2d3342" : "transparent",
|
|
2335
|
+
color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
|
|
2336
|
+
fontWeight: activeScheme === "dark" ? 600 : 400,
|
|
2337
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2338
|
+
fontSize: "12px",
|
|
2339
|
+
transition: "all 0.15s ease"
|
|
2340
|
+
},
|
|
2341
|
+
children: "Dark"
|
|
2342
|
+
}
|
|
2343
|
+
)
|
|
2344
|
+
]
|
|
2345
|
+
}
|
|
2346
|
+
),
|
|
2347
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
2348
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2349
|
+
"button",
|
|
2350
|
+
{
|
|
2351
|
+
type: "button",
|
|
2352
|
+
onClick: () => handleSchemeSelect("light"),
|
|
2353
|
+
disabled,
|
|
2354
|
+
title: "Edit light mode colour",
|
|
2355
|
+
style: {
|
|
2356
|
+
flex: 1,
|
|
2357
|
+
display: "flex",
|
|
2358
|
+
flexDirection: "column",
|
|
2359
|
+
alignItems: "center",
|
|
2360
|
+
gap: "6px",
|
|
2361
|
+
padding: "8px",
|
|
2362
|
+
background: surfaces.light,
|
|
2363
|
+
color: "#000000",
|
|
2364
|
+
border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
2365
|
+
borderRadius: "6px",
|
|
2366
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2367
|
+
outline: "none"
|
|
2368
|
+
},
|
|
2369
|
+
children: [
|
|
2370
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2371
|
+
"span",
|
|
2372
|
+
{
|
|
2373
|
+
style: {
|
|
2374
|
+
width: "100%",
|
|
2375
|
+
height: "24px",
|
|
2376
|
+
borderRadius: "4px",
|
|
2377
|
+
background: dual.light,
|
|
2378
|
+
border: "1px solid rgba(0,0,0,0.15)"
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
),
|
|
2382
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
|
|
2383
|
+
]
|
|
2384
|
+
}
|
|
2385
|
+
),
|
|
2386
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2387
|
+
"button",
|
|
2388
|
+
{
|
|
2389
|
+
type: "button",
|
|
2390
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
2391
|
+
disabled,
|
|
2392
|
+
title: "Edit dark mode colour",
|
|
2393
|
+
style: {
|
|
2394
|
+
flex: 1,
|
|
2395
|
+
display: "flex",
|
|
2396
|
+
flexDirection: "column",
|
|
2397
|
+
alignItems: "center",
|
|
2398
|
+
gap: "6px",
|
|
2399
|
+
padding: "8px",
|
|
2400
|
+
background: surfaces.dark,
|
|
2401
|
+
color: "#ffffff",
|
|
2402
|
+
border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
2403
|
+
borderRadius: "6px",
|
|
2404
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2405
|
+
outline: "none"
|
|
2406
|
+
},
|
|
2407
|
+
children: [
|
|
2408
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2409
|
+
"span",
|
|
2410
|
+
{
|
|
2411
|
+
style: {
|
|
2412
|
+
width: "100%",
|
|
2413
|
+
height: "24px",
|
|
2414
|
+
borderRadius: "4px",
|
|
2415
|
+
background: dual.dark,
|
|
2416
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
),
|
|
2420
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
|
|
2421
|
+
]
|
|
2422
|
+
}
|
|
2423
|
+
)
|
|
2424
|
+
] }),
|
|
2425
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2426
|
+
"div",
|
|
2427
|
+
{
|
|
2428
|
+
style: {
|
|
2429
|
+
display: "flex",
|
|
2430
|
+
alignItems: "center",
|
|
2431
|
+
justifyContent: "space-between",
|
|
2432
|
+
gap: "8px",
|
|
2433
|
+
padding: "2px 0"
|
|
2434
|
+
},
|
|
2435
|
+
children: [
|
|
2436
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2437
|
+
"label",
|
|
2438
|
+
{
|
|
2439
|
+
htmlFor: sameId,
|
|
2440
|
+
style: {
|
|
2441
|
+
display: "flex",
|
|
2442
|
+
alignItems: "center",
|
|
2443
|
+
gap: "6px",
|
|
2444
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2445
|
+
userSelect: "none",
|
|
2446
|
+
fontSize: "12px",
|
|
2447
|
+
color: "#c4cad4"
|
|
2448
|
+
},
|
|
2449
|
+
children: [
|
|
2450
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2451
|
+
"input",
|
|
2452
|
+
{
|
|
2453
|
+
id: sameId,
|
|
2454
|
+
type: "checkbox",
|
|
2455
|
+
checked: sameInBoth,
|
|
2456
|
+
onChange: handleSameToggle,
|
|
2457
|
+
disabled,
|
|
2458
|
+
style: { cursor: disabled ? "not-allowed" : "pointer" }
|
|
2459
|
+
}
|
|
2460
|
+
),
|
|
2461
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: "Same in both" })
|
|
2462
|
+
]
|
|
2463
|
+
}
|
|
2464
|
+
),
|
|
2465
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2466
|
+
"button",
|
|
2467
|
+
{
|
|
2468
|
+
type: "button",
|
|
2469
|
+
onClick: handleDerive,
|
|
2470
|
+
disabled,
|
|
2471
|
+
style: {
|
|
2472
|
+
padding: "4px 10px",
|
|
2473
|
+
background: "#2d3342",
|
|
2474
|
+
color: "#e2e8f0",
|
|
2475
|
+
border: "1px solid #3b4252",
|
|
2476
|
+
borderRadius: "4px",
|
|
2477
|
+
fontSize: "11px",
|
|
2478
|
+
fontWeight: 500,
|
|
2479
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
2480
|
+
},
|
|
2481
|
+
children: "Derive"
|
|
2482
|
+
}
|
|
2483
|
+
)
|
|
2484
|
+
]
|
|
2485
|
+
}
|
|
2486
|
+
),
|
|
2487
|
+
dualContrast && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
2488
|
+
"div",
|
|
2489
|
+
{
|
|
2490
|
+
"data-testid": "dual-contrast-summary",
|
|
2491
|
+
style: {
|
|
2492
|
+
display: "flex",
|
|
2493
|
+
justifyContent: "space-between",
|
|
2494
|
+
background: "#111318",
|
|
2495
|
+
padding: "6px 8px",
|
|
2496
|
+
borderRadius: "6px",
|
|
2497
|
+
fontSize: "11px",
|
|
2498
|
+
color: "#8c95a6"
|
|
2499
|
+
},
|
|
2500
|
+
children: [
|
|
2501
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { children: [
|
|
2502
|
+
"Light:",
|
|
2503
|
+
" ",
|
|
2504
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
2505
|
+
dualContrast.light.ratio.toFixed(2),
|
|
2506
|
+
" (",
|
|
2507
|
+
dualContrast.light.level,
|
|
2508
|
+
")"
|
|
2509
|
+
] })
|
|
2510
|
+
] }),
|
|
2511
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { children: [
|
|
2512
|
+
"Dark:",
|
|
2513
|
+
" ",
|
|
2514
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
2515
|
+
dualContrast.dark.ratio.toFixed(2),
|
|
2516
|
+
" (",
|
|
2517
|
+
dualContrast.dark.level,
|
|
2518
|
+
")"
|
|
2519
|
+
] })
|
|
2520
|
+
] })
|
|
2521
|
+
]
|
|
2522
|
+
}
|
|
2523
|
+
),
|
|
2524
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
2525
|
+
ColorPicker,
|
|
2526
|
+
{
|
|
2527
|
+
value: activeColor,
|
|
2528
|
+
onChange: handleInnerChange,
|
|
2529
|
+
onGestureStart,
|
|
2530
|
+
onGestureEnd,
|
|
2531
|
+
contrastAgainst: activeContrastTarget,
|
|
2532
|
+
alpha,
|
|
2533
|
+
swatches,
|
|
2534
|
+
disabled
|
|
2535
|
+
}
|
|
2536
|
+
)
|
|
2537
|
+
]
|
|
2538
|
+
}
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// src/color/useColorScheme.ts
|
|
2543
|
+
var import_react19 = require("react");
|
|
2544
|
+
var import_color3 = require("@pixerate/editor/color");
|
|
2545
|
+
function getSnapshot(attribute) {
|
|
2546
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2547
|
+
return "light";
|
|
2548
|
+
}
|
|
2549
|
+
if (attribute) {
|
|
2550
|
+
const el = document.documentElement;
|
|
2551
|
+
if (attribute === "class") {
|
|
2552
|
+
return el.classList.contains("dark") ? "dark" : "light";
|
|
2553
|
+
}
|
|
2554
|
+
const val = el.getAttribute(attribute);
|
|
2555
|
+
return val === "dark" ? "dark" : "light";
|
|
2556
|
+
}
|
|
2557
|
+
if (typeof window.matchMedia === "function") {
|
|
2558
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
2559
|
+
}
|
|
2560
|
+
return "light";
|
|
2561
|
+
}
|
|
2562
|
+
function getServerSnapshot() {
|
|
2563
|
+
return "light";
|
|
2564
|
+
}
|
|
2565
|
+
function useColorScheme(options) {
|
|
2566
|
+
const override = options?.override;
|
|
2567
|
+
const attribute = options?.attribute;
|
|
2568
|
+
const subscribe = (0, import_react19.useMemo)(() => {
|
|
2569
|
+
return (callback) => {
|
|
2570
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2571
|
+
return () => {
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
if (attribute) {
|
|
2575
|
+
const observer = new MutationObserver(() => {
|
|
2576
|
+
callback();
|
|
2577
|
+
});
|
|
2578
|
+
observer.observe(document.documentElement, {
|
|
2579
|
+
attributes: true,
|
|
2580
|
+
attributeFilter: [attribute]
|
|
2581
|
+
});
|
|
2582
|
+
return () => observer.disconnect();
|
|
2583
|
+
}
|
|
2584
|
+
if (typeof window.matchMedia === "function") {
|
|
2585
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
2586
|
+
const handler = () => callback();
|
|
2587
|
+
mql.addEventListener("change", handler);
|
|
2588
|
+
return () => mql.removeEventListener("change", handler);
|
|
2589
|
+
}
|
|
2590
|
+
return () => {
|
|
2591
|
+
};
|
|
2592
|
+
};
|
|
2593
|
+
}, [attribute]);
|
|
2594
|
+
const detected = (0, import_react19.useSyncExternalStore)(
|
|
2595
|
+
subscribe,
|
|
2596
|
+
() => getSnapshot(attribute),
|
|
2597
|
+
getServerSnapshot
|
|
2598
|
+
);
|
|
2599
|
+
return override ?? detected;
|
|
2600
|
+
}
|
|
2601
|
+
function useResolvedColor(value, scheme) {
|
|
2602
|
+
const detectedScheme = useColorScheme();
|
|
2603
|
+
const activeScheme = scheme ?? detectedScheme;
|
|
2604
|
+
return (0, import_color3.resolveColor)(value, activeScheme);
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
// src/color/index.ts
|
|
2608
|
+
__reExport(color_exports, require("@pixerate/editor/color"));
|
|
2609
|
+
|
|
2610
|
+
// src/parameters/fields.tsx
|
|
2611
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1570
2612
|
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";
|
|
1571
2613
|
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";
|
|
1572
2614
|
var rangeClass = "h-4 w-full min-w-0 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
@@ -1590,7 +2632,7 @@ function ParameterCommitInput({ value, onCommit, multiline, className, onKeyDown
|
|
|
1590
2632
|
onKeyDown: keyDown,
|
|
1591
2633
|
...rest
|
|
1592
2634
|
};
|
|
1593
|
-
return multiline ? /* @__PURE__ */ (0,
|
|
2635
|
+
return multiline ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("input", { type: "text", ...props }, value);
|
|
1594
2636
|
}
|
|
1595
2637
|
var plainNumber = (field, value) => (0, import_parameters.formatParameterNumber)({ ...field, unit: void 0 }, value);
|
|
1596
2638
|
function ParameterNumberInput({
|
|
@@ -1601,8 +2643,8 @@ function ParameterNumberInput({
|
|
|
1601
2643
|
id,
|
|
1602
2644
|
"aria-label": ariaLabel
|
|
1603
2645
|
}) {
|
|
1604
|
-
return /* @__PURE__ */ (0,
|
|
1605
|
-
/* @__PURE__ */ (0,
|
|
2646
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
|
|
2647
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1606
2648
|
ParameterCommitInput,
|
|
1607
2649
|
{
|
|
1608
2650
|
id,
|
|
@@ -1624,21 +2666,21 @@ function ParameterNumberInput({
|
|
|
1624
2666
|
}
|
|
1625
2667
|
}
|
|
1626
2668
|
),
|
|
1627
|
-
field.unit && /* @__PURE__ */ (0,
|
|
2669
|
+
field.unit && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
|
|
1628
2670
|
] });
|
|
1629
2671
|
}
|
|
1630
2672
|
function ParameterSlider(props) {
|
|
1631
2673
|
const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
|
|
1632
|
-
const dragging = (0,
|
|
2674
|
+
const dragging = (0, import_react20.useRef)(false);
|
|
1633
2675
|
const end = () => {
|
|
1634
2676
|
if (!dragging.current) return;
|
|
1635
2677
|
dragging.current = false;
|
|
1636
2678
|
onGestureEnd?.();
|
|
1637
2679
|
};
|
|
1638
|
-
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0,
|
|
2680
|
+
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterNumberInput, { ...props });
|
|
1639
2681
|
const step = (0, import_parameters.parameterStep)(field);
|
|
1640
|
-
return /* @__PURE__ */ (0,
|
|
1641
|
-
/* @__PURE__ */ (0,
|
|
2682
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
2683
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1642
2684
|
"input",
|
|
1643
2685
|
{
|
|
1644
2686
|
type: "range",
|
|
@@ -1661,11 +2703,11 @@ function ParameterSlider(props) {
|
|
|
1661
2703
|
onChange: (e) => onChange((0, import_parameters.clampParameterNumber)(field, Number(e.target.value)))
|
|
1662
2704
|
}
|
|
1663
2705
|
),
|
|
1664
|
-
/* @__PURE__ */ (0,
|
|
2706
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters.parameterLabel)(field)} value` }) })
|
|
1665
2707
|
] });
|
|
1666
2708
|
}
|
|
1667
2709
|
function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
1668
|
-
return /* @__PURE__ */ (0,
|
|
2710
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1669
2711
|
"button",
|
|
1670
2712
|
{
|
|
1671
2713
|
type: "button",
|
|
@@ -1676,7 +2718,7 @@ function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
|
1676
2718
|
disabled: disabled || field.readOnly,
|
|
1677
2719
|
onClick: () => onChange(!value),
|
|
1678
2720
|
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"}`,
|
|
1679
|
-
children: /* @__PURE__ */ (0,
|
|
2721
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1680
2722
|
"span",
|
|
1681
2723
|
{
|
|
1682
2724
|
className: `pointer-events-none block h-4 w-4 rounded-full bg-background shadow transition-transform ${value ? "translate-x-4" : "translate-x-0.5"}`
|
|
@@ -1689,7 +2731,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
1689
2731
|
const options = (0, import_parameters.getChoiceOptions)(field);
|
|
1690
2732
|
const off = disabled || field.readOnly;
|
|
1691
2733
|
if (field.control === "segmented") {
|
|
1692
|
-
return /* @__PURE__ */ (0,
|
|
2734
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.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_runtime18.jsx)(
|
|
1693
2735
|
"button",
|
|
1694
2736
|
{
|
|
1695
2737
|
type: "button",
|
|
@@ -1705,7 +2747,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
1705
2747
|
)) });
|
|
1706
2748
|
}
|
|
1707
2749
|
const index = options.findIndex((o) => o.value === value);
|
|
1708
|
-
return /* @__PURE__ */ (0,
|
|
2750
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1709
2751
|
"select",
|
|
1710
2752
|
{
|
|
1711
2753
|
id,
|
|
@@ -1717,53 +2759,64 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
1717
2759
|
if (option) onChange(option.value);
|
|
1718
2760
|
},
|
|
1719
2761
|
className: parameterInputClass,
|
|
1720
|
-
children: options.map((o, i) => /* @__PURE__ */ (0,
|
|
2762
|
+
children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters.choiceOptionLabel)(o) }, String(o.value)))
|
|
1721
2763
|
}
|
|
1722
2764
|
);
|
|
1723
2765
|
}
|
|
1724
2766
|
function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
|
|
1725
|
-
const
|
|
2767
|
+
const [open, setOpen] = (0, import_react20.useState)(false);
|
|
2768
|
+
const containerRef = (0, import_react20.useRef)(null);
|
|
2769
|
+
const buttonRef = (0, import_react20.useRef)(null);
|
|
2770
|
+
const popoverRef = (0, import_react20.useRef)(null);
|
|
1726
2771
|
const alpha = !!field.alpha;
|
|
1727
2772
|
const hex = (0, import_parameters.normalizeHexColor)(value, true) ?? "#000000ff";
|
|
1728
2773
|
const rgb = hex.slice(0, 7);
|
|
1729
|
-
const
|
|
2774
|
+
const shown = alpha ? hex : rgb;
|
|
1730
2775
|
const off = disabled || field.readOnly;
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
2776
|
+
const name = (0, import_parameters.parameterLabel)(field);
|
|
2777
|
+
(0, import_react20.useEffect)(() => {
|
|
2778
|
+
if (!open) return;
|
|
2779
|
+
const onPointerDown = (e) => {
|
|
2780
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
2781
|
+
setOpen(false);
|
|
2782
|
+
}
|
|
2783
|
+
};
|
|
2784
|
+
const onKeyDown = (e) => {
|
|
2785
|
+
if (e.key === "Escape") {
|
|
2786
|
+
e.stopPropagation();
|
|
2787
|
+
setOpen(false);
|
|
2788
|
+
buttonRef.current?.focus();
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
window.addEventListener("pointerdown", onPointerDown, true);
|
|
2792
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
2793
|
+
return () => {
|
|
2794
|
+
window.removeEventListener("pointerdown", onPointerDown, true);
|
|
2795
|
+
window.removeEventListener("keydown", onKeyDown, true);
|
|
2796
|
+
};
|
|
2797
|
+
}, [open]);
|
|
2798
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { ref: containerRef, className: "relative space-y-1.5", children: [
|
|
2799
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
2800
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2801
|
+
"button",
|
|
2802
|
+
{
|
|
2803
|
+
ref: buttonRef,
|
|
2804
|
+
type: "button",
|
|
2805
|
+
"aria-label": name,
|
|
2806
|
+
"aria-expanded": open,
|
|
2807
|
+
"aria-haspopup": "dialog",
|
|
2808
|
+
disabled: off,
|
|
2809
|
+
onClick: () => setOpen((prev) => !prev),
|
|
2810
|
+
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",
|
|
2811
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "absolute inset-0", style: { background: shown } })
|
|
2812
|
+
}
|
|
2813
|
+
),
|
|
2814
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1762
2815
|
ParameterCommitInput,
|
|
1763
2816
|
{
|
|
1764
2817
|
id,
|
|
1765
|
-
"aria-label": `${
|
|
1766
|
-
value:
|
|
2818
|
+
"aria-label": `${name} hex`,
|
|
2819
|
+
value: shown,
|
|
1767
2820
|
disabled: off,
|
|
1768
2821
|
spellCheck: false,
|
|
1769
2822
|
className: `${parameterInputClass} font-mono`,
|
|
@@ -1774,51 +2827,43 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
|
|
|
1774
2827
|
}
|
|
1775
2828
|
)
|
|
1776
2829
|
] }),
|
|
1777
|
-
|
|
1778
|
-
"
|
|
2830
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2831
|
+
"div",
|
|
1779
2832
|
{
|
|
1780
|
-
|
|
1781
|
-
"
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
onPointerDown: start,
|
|
1789
|
-
onPointerUp: end,
|
|
1790
|
-
onPointerCancel: end,
|
|
1791
|
-
onBlur: end,
|
|
1792
|
-
onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
|
|
1793
|
-
}
|
|
1794
|
-
),
|
|
1795
|
-
field.swatches && field.swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
|
|
1796
|
-
const swatch = (0, import_parameters.normalizeHexColor)(s, alpha);
|
|
1797
|
-
if (!swatch) return null;
|
|
1798
|
-
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1799
|
-
"button",
|
|
1800
|
-
{
|
|
1801
|
-
type: "button",
|
|
1802
|
-
title: swatch,
|
|
1803
|
-
"aria-label": `${(0, import_parameters.parameterLabel)(field)} ${swatch}`,
|
|
1804
|
-
"aria-pressed": swatch === (alpha ? hex : rgb),
|
|
1805
|
-
disabled: off,
|
|
1806
|
-
onClick: () => onChange(swatch),
|
|
1807
|
-
className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
|
|
1808
|
-
style: { background: swatch }
|
|
2833
|
+
ref: popoverRef,
|
|
2834
|
+
role: "dialog",
|
|
2835
|
+
"aria-label": name,
|
|
2836
|
+
tabIndex: -1,
|
|
2837
|
+
onBlur: (e) => {
|
|
2838
|
+
if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
|
|
2839
|
+
setOpen(false);
|
|
2840
|
+
}
|
|
1809
2841
|
},
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
2842
|
+
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",
|
|
2843
|
+
style: { background: "var(--popover, var(--background, #fff))" },
|
|
2844
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2845
|
+
ColorPicker,
|
|
2846
|
+
{
|
|
2847
|
+
value: shown,
|
|
2848
|
+
alpha,
|
|
2849
|
+
swatches: field.swatches,
|
|
2850
|
+
disabled: off,
|
|
2851
|
+
onChange,
|
|
2852
|
+
onGestureStart,
|
|
2853
|
+
onGestureEnd
|
|
2854
|
+
}
|
|
2855
|
+
)
|
|
2856
|
+
}
|
|
2857
|
+
)
|
|
1813
2858
|
] });
|
|
1814
2859
|
}
|
|
1815
2860
|
function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
1816
2861
|
const size = (0, import_parameters.vectorSize)(field);
|
|
1817
|
-
return /* @__PURE__ */ (0,
|
|
2862
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
|
|
1818
2863
|
const component = (0, import_parameters.vectorComponentField)(field, i);
|
|
1819
|
-
return /* @__PURE__ */ (0,
|
|
1820
|
-
/* @__PURE__ */ (0,
|
|
1821
|
-
/* @__PURE__ */ (0,
|
|
2864
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
|
|
2865
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
|
|
2866
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1822
2867
|
ParameterNumberInput,
|
|
1823
2868
|
{
|
|
1824
2869
|
field: component,
|
|
@@ -1835,11 +2880,11 @@ function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
|
1835
2880
|
function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
1836
2881
|
const off = disabled || field.readOnly;
|
|
1837
2882
|
const name = (0, import_parameters.parameterLabel)(field);
|
|
1838
|
-
return /* @__PURE__ */ (0,
|
|
1839
|
-
/* @__PURE__ */ (0,
|
|
1840
|
-
/* @__PURE__ */ (0,
|
|
1841
|
-
/* @__PURE__ */ (0,
|
|
1842
|
-
/* @__PURE__ */ (0,
|
|
2883
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "space-y-1.5", children: [
|
|
2884
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
2885
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.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_runtime18.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
|
|
2886
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
2887
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1843
2888
|
ParameterCommitInput,
|
|
1844
2889
|
{
|
|
1845
2890
|
id,
|
|
@@ -1850,10 +2895,10 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
1850
2895
|
onCommit: (text) => onChange(text.trim())
|
|
1851
2896
|
}
|
|
1852
2897
|
),
|
|
1853
|
-
/* @__PURE__ */ (0,
|
|
1854
|
-
resolveFile && /* @__PURE__ */ (0,
|
|
2898
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex gap-1", children: [
|
|
2899
|
+
resolveFile && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
|
|
1855
2900
|
"Choose file\u2026",
|
|
1856
|
-
/* @__PURE__ */ (0,
|
|
2901
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1857
2902
|
"input",
|
|
1858
2903
|
{
|
|
1859
2904
|
type: "file",
|
|
@@ -1869,11 +2914,11 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
1869
2914
|
}
|
|
1870
2915
|
)
|
|
1871
2916
|
] }),
|
|
1872
|
-
value && /* @__PURE__ */ (0,
|
|
2917
|
+
value && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
|
|
1873
2918
|
] })
|
|
1874
2919
|
] })
|
|
1875
2920
|
] }),
|
|
1876
|
-
field.options && field.options.length > 0 && /* @__PURE__ */ (0,
|
|
2921
|
+
field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1877
2922
|
"button",
|
|
1878
2923
|
{
|
|
1879
2924
|
type: "button",
|
|
@@ -1883,14 +2928,14 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
1883
2928
|
disabled: off,
|
|
1884
2929
|
onClick: () => onChange(o.url),
|
|
1885
2930
|
className: "h-9 w-12 overflow-hidden rounded border border-input aria-pressed:ring-2 aria-pressed:ring-primary",
|
|
1886
|
-
children: /* @__PURE__ */ (0,
|
|
2931
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
|
|
1887
2932
|
},
|
|
1888
2933
|
o.url
|
|
1889
2934
|
)) })
|
|
1890
2935
|
] });
|
|
1891
2936
|
}
|
|
1892
2937
|
function ParameterText({ field, value, onChange, disabled, id }) {
|
|
1893
|
-
return /* @__PURE__ */ (0,
|
|
2938
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
1894
2939
|
ParameterCommitInput,
|
|
1895
2940
|
{
|
|
1896
2941
|
id,
|
|
@@ -1909,31 +2954,31 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
|
|
|
1909
2954
|
switch (field.type) {
|
|
1910
2955
|
case "number":
|
|
1911
2956
|
case "int":
|
|
1912
|
-
return /* @__PURE__ */ (0,
|
|
2957
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
|
|
1913
2958
|
case "boolean":
|
|
1914
|
-
return /* @__PURE__ */ (0,
|
|
2959
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
|
|
1915
2960
|
case "choice":
|
|
1916
|
-
return /* @__PURE__ */ (0,
|
|
2961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
|
|
1917
2962
|
case "color":
|
|
1918
|
-
return /* @__PURE__ */ (0,
|
|
2963
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
|
|
1919
2964
|
case "vector":
|
|
1920
|
-
return /* @__PURE__ */ (0,
|
|
2965
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
|
|
1921
2966
|
case "image":
|
|
1922
|
-
return /* @__PURE__ */ (0,
|
|
2967
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
|
|
1923
2968
|
case "text":
|
|
1924
|
-
return /* @__PURE__ */ (0,
|
|
2969
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ParameterText, { field, value, onChange: set, ...rest });
|
|
1925
2970
|
}
|
|
1926
2971
|
}
|
|
1927
2972
|
|
|
1928
2973
|
// src/effects/EffectParameters.tsx
|
|
1929
|
-
var
|
|
2974
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1930
2975
|
function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
|
|
1931
|
-
const fields = (0,
|
|
1932
|
-
const idBase = (0,
|
|
1933
|
-
const gesture =
|
|
1934
|
-
const count =
|
|
1935
|
-
return /* @__PURE__ */ (0,
|
|
1936
|
-
onPreset && description.presets.length > 0 && /* @__PURE__ */ (0,
|
|
2976
|
+
const fields = (0, import_react21.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
|
|
2977
|
+
const idBase = (0, import_react21.useId)();
|
|
2978
|
+
const gesture = import_react21.default.useRef(null);
|
|
2979
|
+
const count = import_react21.default.useRef(0);
|
|
2980
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
|
|
2981
|
+
onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
1937
2982
|
"select",
|
|
1938
2983
|
{
|
|
1939
2984
|
className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
|
|
@@ -1945,8 +2990,8 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
1945
2990
|
if (preset) onPreset({ ...description.defaults, ...preset.values });
|
|
1946
2991
|
},
|
|
1947
2992
|
children: [
|
|
1948
|
-
/* @__PURE__ */ (0,
|
|
1949
|
-
description.presets.map((p) => /* @__PURE__ */ (0,
|
|
2993
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("option", { value: "", children: "Presets\u2026" }),
|
|
2994
|
+
description.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("option", { value: p.name, children: p.name }, p.name))
|
|
1950
2995
|
]
|
|
1951
2996
|
}
|
|
1952
2997
|
),
|
|
@@ -1956,13 +3001,13 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
1956
3001
|
const keyed = keyframed?.has(field.id) ?? false;
|
|
1957
3002
|
const value = (0, import_effects3.effectFieldValue)(field, values[field.id]);
|
|
1958
3003
|
const changed = !keyed && !(0, import_parameters2.parameterValuesEqual)(value, field.default);
|
|
1959
|
-
return /* @__PURE__ */ (0,
|
|
1960
|
-
/* @__PURE__ */ (0,
|
|
1961
|
-
/* @__PURE__ */ (0,
|
|
1962
|
-
keyed && /* @__PURE__ */ (0,
|
|
1963
|
-
onReset && changed && !disabled && /* @__PURE__ */ (0,
|
|
3004
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1", "data-effect-control": field.id, children: [
|
|
3005
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
|
|
3006
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
|
|
3007
|
+
keyed && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
|
|
3008
|
+
onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime19.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" })
|
|
1964
3009
|
] }),
|
|
1965
|
-
/* @__PURE__ */ (0,
|
|
3010
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
1966
3011
|
ParameterFieldControl,
|
|
1967
3012
|
{
|
|
1968
3013
|
field,
|
|
@@ -1976,15 +3021,15 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
1976
3021
|
)
|
|
1977
3022
|
] }, field.id);
|
|
1978
3023
|
}),
|
|
1979
|
-
!fields.length && /* @__PURE__ */ (0,
|
|
3024
|
+
!fields.length && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
|
|
1980
3025
|
] });
|
|
1981
3026
|
}
|
|
1982
3027
|
|
|
1983
3028
|
// src/paint-editor/PaintEffectsPanel.tsx
|
|
1984
|
-
var
|
|
3029
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1985
3030
|
function usePaintEffectsProvider(controller) {
|
|
1986
|
-
const [provider, setProvider] = (0,
|
|
1987
|
-
(0,
|
|
3031
|
+
const [provider, setProvider] = (0, import_react22.useState)(controller.effectsProvider);
|
|
3032
|
+
(0, import_react22.useEffect)(() => {
|
|
1988
3033
|
setProvider(controller.effectsProvider);
|
|
1989
3034
|
return controller.effects.subscribe(setProvider);
|
|
1990
3035
|
}, [controller]);
|
|
@@ -1992,27 +3037,27 @@ function usePaintEffectsProvider(controller) {
|
|
|
1992
3037
|
}
|
|
1993
3038
|
function usePaintEffectsTools(registry, controller, options = {}) {
|
|
1994
3039
|
const { id, namespace, readOnly } = options;
|
|
1995
|
-
(0,
|
|
3040
|
+
(0, import_react22.useEffect)(() => {
|
|
1996
3041
|
if (!registry) return;
|
|
1997
3042
|
return registry.register((0, import_paint_editor13.createPaintEffectsToolProvider)(controller, { id, namespace, readOnly }));
|
|
1998
3043
|
}, [registry, controller, id, namespace, readOnly]);
|
|
1999
3044
|
}
|
|
2000
3045
|
function Controls({ provider, effect, name, values, apply }) {
|
|
2001
3046
|
const { description, error } = useEffectDescription(provider, effect);
|
|
2002
|
-
const drags = (0,
|
|
2003
|
-
if (!provider) return /* @__PURE__ */ (0,
|
|
3047
|
+
const drags = (0, import_react22.useRef)(/* @__PURE__ */ new Set());
|
|
3048
|
+
if (!provider) return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("p", { className: "text-[11px] text-slate-400", children: [
|
|
2004
3049
|
'No effects provider: "',
|
|
2005
3050
|
name ?? effect,
|
|
2006
3051
|
'" is kept as it was drawn.'
|
|
2007
3052
|
] });
|
|
2008
|
-
if (error) return /* @__PURE__ */ (0,
|
|
2009
|
-
if (!description) return /* @__PURE__ */ (0,
|
|
3053
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-amber-400", children: error });
|
|
3054
|
+
if (!description) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-slate-400", children: "Loading\u2026" });
|
|
2010
3055
|
const commit = (gesture) => {
|
|
2011
3056
|
if (!gesture || drags.current.has(gesture)) return !gesture;
|
|
2012
3057
|
drags.current.add(gesture);
|
|
2013
3058
|
return true;
|
|
2014
3059
|
};
|
|
2015
|
-
return /* @__PURE__ */ (0,
|
|
3060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2016
3061
|
EffectParameters,
|
|
2017
3062
|
{
|
|
2018
3063
|
description,
|
|
@@ -2033,8 +3078,8 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
2033
3078
|
const state = usePaintEditorState(controller);
|
|
2034
3079
|
const provider = usePaintEffectsProvider(controller);
|
|
2035
3080
|
const [error, attempt] = useAttempt();
|
|
2036
|
-
const [browse, setBrowse] = (0,
|
|
2037
|
-
const [busy, setBusy] = (0,
|
|
3081
|
+
const [browse, setBrowse] = (0, import_react22.useState)(null);
|
|
3082
|
+
const [busy, setBusy] = (0, import_react22.useState)(false);
|
|
2038
3083
|
const paper = controller.getPaperEffect();
|
|
2039
3084
|
const activeId = state.document.activeLayerId;
|
|
2040
3085
|
const layerEffect = activeId ? controller.getEffectLayer(activeId) : void 0;
|
|
@@ -2053,27 +3098,27 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
2053
3098
|
};
|
|
2054
3099
|
const toggle = (b) => setBrowse(browse === b ? null : b);
|
|
2055
3100
|
const pixel = active?.type === "pixel";
|
|
2056
|
-
return /* @__PURE__ */ (0,
|
|
2057
|
-
/* @__PURE__ */ (0,
|
|
2058
|
-
/* @__PURE__ */ (0,
|
|
2059
|
-
/* @__PURE__ */ (0,
|
|
2060
|
-
/* @__PURE__ */ (0,
|
|
2061
|
-
/* @__PURE__ */ (0,
|
|
2062
|
-
/* @__PURE__ */ (0,
|
|
3101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: `${panel} ${className ?? ""}`, "data-testid": "paint-effects-panel", "aria-busy": busy, children: [
|
|
3102
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
3103
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "flex-1 font-medium text-slate-300", children: "Effects" }),
|
|
3104
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "paper", onClick: () => toggle("paper"), children: "Paper\u2026" }),
|
|
3105
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, disabled: !provider, "aria-pressed": browse === "layer", onClick: () => toggle("layer"), children: "Layer\u2026" }),
|
|
3106
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "fill", onClick: () => toggle("fill"), children: "Fill\u2026" }),
|
|
3107
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, disabled: !provider || !pixel, "aria-pressed": browse === "light", onClick: () => toggle("light"), title: "Bake a light, glow or grade into the active layer's dried paint", children: "Light\u2026" })
|
|
2063
3108
|
] }),
|
|
2064
|
-
!provider && /* @__PURE__ */ (0,
|
|
2065
|
-
browse && /* @__PURE__ */ (0,
|
|
2066
|
-
paper && /* @__PURE__ */ (0,
|
|
2067
|
-
/* @__PURE__ */ (0,
|
|
2068
|
-
/* @__PURE__ */ (0,
|
|
3109
|
+
!provider && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-slate-400", children: "No effects provider is registered. Effects in the painting are kept." }),
|
|
3110
|
+
browse && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: BROWSERS[browse].uses, title: BROWSERS[browse].title, onPick: (e) => pick(e.id) }),
|
|
3111
|
+
paper && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "paper", children: [
|
|
3112
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3113
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("span", { className: "flex-1 truncate", children: [
|
|
2069
3114
|
"Paper: ",
|
|
2070
3115
|
paper.name ?? paper.effect
|
|
2071
3116
|
] }),
|
|
2072
|
-
/* @__PURE__ */ (0,
|
|
3117
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, "aria-label": "Remove the effect paper", onClick: () => run(() => controller.setPaperEffect(null)), children: "\u2715" })
|
|
2073
3118
|
] }),
|
|
2074
|
-
/* @__PURE__ */ (0,
|
|
2075
|
-
/* @__PURE__ */ (0,
|
|
2076
|
-
/* @__PURE__ */ (0,
|
|
3119
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("label", { className: "flex items-center gap-1", children: [
|
|
3120
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "w-14 text-[11px] text-slate-400", children: "Opacity" }),
|
|
3121
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2077
3122
|
"input",
|
|
2078
3123
|
{
|
|
2079
3124
|
type: "range",
|
|
@@ -2095,43 +3140,43 @@ var PaintEffectsPanel = ({ controller, className }) => {
|
|
|
2095
3140
|
`o${paper.opacity}`
|
|
2096
3141
|
)
|
|
2097
3142
|
] }),
|
|
2098
|
-
/* @__PURE__ */ (0,
|
|
2099
|
-
/* @__PURE__ */ (0,
|
|
2100
|
-
/* @__PURE__ */ (0,
|
|
3143
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("label", { className: "flex items-center gap-1", children: [
|
|
3144
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "w-14 text-[11px] text-slate-400", children: "Blend" }),
|
|
3145
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("select", { className: "flex-1 rounded bg-slate-800 px-1 py-0.5 text-[11px]", "aria-label": "Effect paper blend", value: paper.blend, onChange: (e) => {
|
|
2101
3146
|
const blend = e.currentTarget.value;
|
|
2102
3147
|
run(() => controller.updatePaperEffect({ blend }));
|
|
2103
|
-
}, children: import_paint_editor13.PAPER_EFFECT_BLENDS.map((b) => /* @__PURE__ */ (0,
|
|
3148
|
+
}, children: import_paint_editor13.PAPER_EFFECT_BLENDS.map((b) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("option", { value: b, children: b }, b)) })
|
|
2104
3149
|
] }),
|
|
2105
|
-
/* @__PURE__ */ (0,
|
|
3150
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Controls, { provider, effect: paper.effect, name: paper.name, values: paper.values, apply: (values, commit) => run(() => controller.updatePaperEffect({ values }, commit)) })
|
|
2106
3151
|
] }),
|
|
2107
|
-
layerEffect && activeId && /* @__PURE__ */ (0,
|
|
2108
|
-
/* @__PURE__ */ (0,
|
|
2109
|
-
/* @__PURE__ */ (0,
|
|
3152
|
+
layerEffect && activeId && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "layer", children: [
|
|
3153
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3154
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("span", { className: "flex-1 truncate", children: [
|
|
2110
3155
|
"Layer: ",
|
|
2111
3156
|
layerEffect.name ?? layerEffect.effect
|
|
2112
3157
|
] }),
|
|
2113
|
-
/* @__PURE__ */ (0,
|
|
3158
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: button, title: "Keep the pixels as a plain layer", onClick: () => attempt(() => controller.rasterizeEffectLayer(activeId)), children: "Rasterize" })
|
|
2114
3159
|
] }),
|
|
2115
|
-
/* @__PURE__ */ (0,
|
|
3160
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Controls, { provider, effect: layerEffect.effect, name: layerEffect.name, values: layerEffect.values, apply: (values, commit) => run(() => controller.updateEffectLayer(activeId, { values }, commit)) })
|
|
2116
3161
|
] }),
|
|
2117
|
-
/* @__PURE__ */ (0,
|
|
3162
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ErrorLine, { error })
|
|
2118
3163
|
] });
|
|
2119
3164
|
};
|
|
2120
3165
|
|
|
2121
3166
|
// src/paint-editor/PaintEditor.tsx
|
|
2122
|
-
var
|
|
3167
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2123
3168
|
var PAINT_CONTROLS = {
|
|
2124
3169
|
"mixing-pad": '[data-testid="mixing-pad"]',
|
|
2125
3170
|
lighting: '[data-testid="light-panel"]',
|
|
2126
3171
|
symmetry: '[aria-label="Symmetry"]'
|
|
2127
3172
|
};
|
|
2128
3173
|
var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
|
|
2129
|
-
const [tool, setTool] = (0,
|
|
2130
|
-
const [tab, setTab] = (0,
|
|
2131
|
-
const tabRef = (0,
|
|
3174
|
+
const [tool, setTool] = (0, import_react23.useState)("brush");
|
|
3175
|
+
const [tab, setTab] = (0, import_react23.useState)("color");
|
|
3176
|
+
const tabRef = (0, import_react23.useRef)(tab);
|
|
2132
3177
|
tabRef.current = tab;
|
|
2133
|
-
const rootRef = (0,
|
|
2134
|
-
const [ownPresence] = (0,
|
|
3178
|
+
const rootRef = (0, import_react23.useRef)(null);
|
|
3179
|
+
const [ownPresence] = (0, import_react23.useState)(() => new import_paint_editor14.PaintPresence());
|
|
2135
3180
|
const ambientPlayback = useAgentPlayback();
|
|
2136
3181
|
const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
|
|
2137
3182
|
const viewBox = () => {
|
|
@@ -2187,27 +3232,27 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
|
|
|
2187
3232
|
const box = rootRef.current?.getBoundingClientRect();
|
|
2188
3233
|
return c && box ? { x: c.x - box.left, y: c.y - box.top } : p;
|
|
2189
3234
|
};
|
|
2190
|
-
const [error, setError] = (0,
|
|
3235
|
+
const [error, setError] = (0, import_react23.useState)(null);
|
|
2191
3236
|
const effects = usePaintEffectsProvider(controller);
|
|
2192
3237
|
const tabs = effects ? ["color", "wet", "paper", "layers", "effects"] : ["color", "wet", "paper", "layers"];
|
|
2193
|
-
return /* @__PURE__ */ (0,
|
|
2194
|
-
playing && /* @__PURE__ */ (0,
|
|
2195
|
-
/* @__PURE__ */ (0,
|
|
2196
|
-
/* @__PURE__ */ (0,
|
|
2197
|
-
/* @__PURE__ */ (0,
|
|
2198
|
-
/* @__PURE__ */ (0,
|
|
2199
|
-
/* @__PURE__ */ (0,
|
|
2200
|
-
error && /* @__PURE__ */ (0,
|
|
3238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { ref: rootRef, className: `relative flex flex-col gap-2 rounded-xl border border-slate-800 bg-slate-900 p-2 ${className ?? ""}`, style: { height }, "data-testid": "paint-editor", children: [
|
|
3239
|
+
playing && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PresenceLayer, { presence: agentPresence, viewport: docToRoot }),
|
|
3240
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PaintToolbar, { controller, tool, onToolChange: setTool, fileName }),
|
|
3241
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex min-h-0 flex-1 gap-2", children: [
|
|
3242
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
|
|
3243
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
3244
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
|
|
3245
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
|
|
2201
3246
|
] }),
|
|
2202
|
-
/* @__PURE__ */ (0,
|
|
2203
|
-
/* @__PURE__ */ (0,
|
|
2204
|
-
/* @__PURE__ */ (0,
|
|
2205
|
-
tab === "color" && /* @__PURE__ */ (0,
|
|
2206
|
-
tab === "wet" && /* @__PURE__ */ (0,
|
|
2207
|
-
tab === "paper" && /* @__PURE__ */ (0,
|
|
2208
|
-
tab === "layers" && /* @__PURE__ */ (0,
|
|
2209
|
-
tab === "layers" && /* @__PURE__ */ (0,
|
|
2210
|
-
tab === "effects" && effects && /* @__PURE__ */ (0,
|
|
3247
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
|
|
3248
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "flex gap-1", role: "tablist", "aria-label": "Paint panels", children: tabs.map((t) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("button", { type: "button", role: "tab", "aria-selected": tab === t, "data-paint-tab": t, className: chip(tab === t), onClick: () => setTab(t), children: t === "color" ? "Colour" : t === "wet" ? "Wet" : t === "paper" ? "Paper" : t === "layers" ? "Layers" : "Effects" }, t)) }),
|
|
3249
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-2", "data-paint-panel": tab, children: [
|
|
3250
|
+
tab === "color" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ColorPanel, { controller }),
|
|
3251
|
+
tab === "wet" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(WetPanel, { controller }),
|
|
3252
|
+
tab === "paper" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PaperPanel, { controller }),
|
|
3253
|
+
tab === "layers" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PaintLayersPanel, { controller }),
|
|
3254
|
+
tab === "layers" && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(StickerPanel, { controller }),
|
|
3255
|
+
tab === "effects" && effects && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(PaintEffectsPanel, { controller })
|
|
2211
3256
|
] })
|
|
2212
3257
|
] })
|
|
2213
3258
|
] })
|