@pixerate/editor-react 0.95.0 → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/animation-editor/index.cjs +1240 -195
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1418 -373
- package/dist/canvas/index.js +4 -2
- package/dist/chunk-3I7FOSLF.js +988 -0
- package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
- package/dist/{chunk-5R67YSSD.js → chunk-GLSOQNQR.js} +1 -1
- package/dist/{chunk-6YRSQW2V.js → chunk-IY6YOY5B.js} +1 -1
- package/dist/chunk-KIRIU53A.js +72 -0
- package/dist/color/ColorPicker.d.cts +30 -0
- package/dist/color/ColorPicker.d.ts +30 -0
- package/dist/color/DualColorPicker.d.cts +29 -0
- package/dist/color/DualColorPicker.d.ts +29 -0
- package/dist/color/index.cjs +1067 -0
- package/dist/color/index.d.cts +7 -0
- package/dist/color/index.d.ts +7 -0
- package/dist/color/index.js +14 -0
- package/dist/color/useColorScheme.d.cts +16 -0
- package/dist/color/useColorScheme.d.ts +16 -0
- package/dist/effects/index.cjs +1169 -124
- package/dist/effects/index.js +4 -2
- package/dist/gradient/FillPicker.d.cts +27 -0
- package/dist/gradient/FillPicker.d.ts +27 -0
- package/dist/gradient/GradientEditor.d.cts +21 -0
- package/dist/gradient/GradientEditor.d.ts +21 -0
- package/dist/gradient/index.cjs +1601 -0
- package/dist/gradient/index.d.cts +6 -0
- package/dist/gradient/index.d.ts +6 -0
- package/dist/gradient/index.js +617 -0
- package/dist/gradient/useGradientController.d.cts +10 -0
- package/dist/gradient/useGradientController.d.ts +10 -0
- package/dist/image-editor/index.cjs +1742 -697
- package/dist/image-editor/index.js +5 -3
- package/dist/index.cjs +2160 -1115
- package/dist/index.js +5 -3
- package/dist/paint-editor/index.cjs +1233 -188
- package/dist/paint-editor/index.js +4 -2
- package/dist/parameters/fields.d.cts +1 -1
- package/dist/parameters/fields.d.ts +1 -1
- package/dist/parameters/index.cjs +1218 -173
- package/dist/parameters/index.js +3 -1
- package/dist/vector/index.cjs +1219 -174
- package/dist/vector/index.js +4 -2
- package/dist/video-editor/index.cjs +1230 -185
- package/dist/video-editor/index.js +4 -2
- package/package.json +29 -3
package/dist/canvas/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-
|
|
@@ -1849,7 +1850,7 @@ function useCanvasBrushes(options = {}) {
|
|
|
1849
1850
|
}
|
|
1850
1851
|
|
|
1851
1852
|
// src/canvas/CanvasEffects.tsx
|
|
1852
|
-
var
|
|
1853
|
+
var import_react27 = require("react");
|
|
1853
1854
|
var import_canvas14 = require("@pixerate/editor/canvas");
|
|
1854
1855
|
|
|
1855
1856
|
// src/effects/useEffects.ts
|
|
@@ -1983,14 +1984,1055 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
1983
1984
|
}
|
|
1984
1985
|
|
|
1985
1986
|
// src/effects/EffectParameters.tsx
|
|
1986
|
-
var
|
|
1987
|
+
var import_react26 = __toESM(require("react"), 1);
|
|
1987
1988
|
var import_effects3 = require("@pixerate/editor/effects");
|
|
1988
1989
|
var import_parameters2 = require("@pixerate/editor/parameters");
|
|
1989
1990
|
|
|
1990
1991
|
// src/parameters/fields.tsx
|
|
1991
|
-
var
|
|
1992
|
+
var import_react25 = require("react");
|
|
1992
1993
|
var import_parameters = require("@pixerate/editor/parameters");
|
|
1994
|
+
|
|
1995
|
+
// src/color/index.ts
|
|
1996
|
+
var color_exports = {};
|
|
1997
|
+
__export(color_exports, {
|
|
1998
|
+
ColorPicker: () => ColorPicker,
|
|
1999
|
+
DualColorPicker: () => DualColorPicker,
|
|
2000
|
+
useColorScheme: () => useColorScheme,
|
|
2001
|
+
useResolvedColor: () => useResolvedColor
|
|
2002
|
+
});
|
|
2003
|
+
|
|
2004
|
+
// src/color/ColorPicker.tsx
|
|
2005
|
+
var import_react22 = require("react");
|
|
2006
|
+
var import_color = require("@pixerate/editor/color");
|
|
1993
2007
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2008
|
+
var LOCAL_STORAGE_KEY = "pixerate:color:recent";
|
|
2009
|
+
function readLocalRecents() {
|
|
2010
|
+
try {
|
|
2011
|
+
if (typeof localStorage === "undefined") return [];
|
|
2012
|
+
const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
2013
|
+
if (!raw) return [];
|
|
2014
|
+
const parsed = JSON.parse(raw);
|
|
2015
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
2016
|
+
} catch {
|
|
2017
|
+
return [];
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
function writeLocalRecents(list) {
|
|
2021
|
+
try {
|
|
2022
|
+
if (typeof localStorage !== "undefined") {
|
|
2023
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
|
|
2024
|
+
}
|
|
2025
|
+
} catch {
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
|
|
2029
|
+
var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
|
|
2030
|
+
var ColorPicker = ({
|
|
2031
|
+
value,
|
|
2032
|
+
onChange,
|
|
2033
|
+
onGestureStart,
|
|
2034
|
+
onGestureEnd,
|
|
2035
|
+
alpha = false,
|
|
2036
|
+
swatches,
|
|
2037
|
+
recent: controlledRecent,
|
|
2038
|
+
onRecentChange,
|
|
2039
|
+
contrastAgainst,
|
|
2040
|
+
disabled = false,
|
|
2041
|
+
className,
|
|
2042
|
+
id,
|
|
2043
|
+
"aria-label": ariaLabel = "Color picker"
|
|
2044
|
+
}) => {
|
|
2045
|
+
const generatedId = (0, import_react22.useId)();
|
|
2046
|
+
const pickerId = id || generatedId;
|
|
2047
|
+
const [pickerState, setPickerState] = (0, import_react22.useState)(
|
|
2048
|
+
() => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
|
|
2049
|
+
);
|
|
2050
|
+
const stateRef = (0, import_react22.useRef)(pickerState);
|
|
2051
|
+
stateRef.current = pickerState;
|
|
2052
|
+
(0, import_react22.useEffect)(() => {
|
|
2053
|
+
const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
|
|
2054
|
+
if (next) {
|
|
2055
|
+
setPickerState(next);
|
|
2056
|
+
}
|
|
2057
|
+
}, [value]);
|
|
2058
|
+
const [internalRecent, setInternalRecent] = (0, import_react22.useState)(
|
|
2059
|
+
() => controlledRecent ? [] : readLocalRecents()
|
|
2060
|
+
);
|
|
2061
|
+
const activeRecent = controlledRecent ?? internalRecent;
|
|
2062
|
+
const recordRecent = (0, import_react22.useCallback)(
|
|
2063
|
+
(color) => {
|
|
2064
|
+
const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
|
|
2065
|
+
if (!controlledRecent) {
|
|
2066
|
+
setInternalRecent(updated);
|
|
2067
|
+
writeLocalRecents(updated);
|
|
2068
|
+
}
|
|
2069
|
+
onRecentChange?.(updated);
|
|
2070
|
+
},
|
|
2071
|
+
[activeRecent, controlledRecent, onRecentChange]
|
|
2072
|
+
);
|
|
2073
|
+
const [textDraft, setTextDraft] = (0, import_react22.useState)(value);
|
|
2074
|
+
const [isInvalid, setIsInvalid] = (0, import_react22.useState)(false);
|
|
2075
|
+
const [isClipped, setIsClipped] = (0, import_react22.useState)(false);
|
|
2076
|
+
const isTypingRef = (0, import_react22.useRef)(false);
|
|
2077
|
+
(0, import_react22.useEffect)(() => {
|
|
2078
|
+
if (!isTypingRef.current) {
|
|
2079
|
+
setTextDraft(value);
|
|
2080
|
+
setIsInvalid(false);
|
|
2081
|
+
const parsed = (0, import_color.parseColor)(value);
|
|
2082
|
+
setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
|
|
2083
|
+
}
|
|
2084
|
+
}, [value]);
|
|
2085
|
+
const [hasEyeDropper, setHasEyeDropper] = (0, import_react22.useState)(false);
|
|
2086
|
+
(0, import_react22.useEffect)(() => {
|
|
2087
|
+
setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
|
|
2088
|
+
}, []);
|
|
2089
|
+
const emitColorChange = (0, import_react22.useCallback)(
|
|
2090
|
+
(nextState) => {
|
|
2091
|
+
setPickerState(nextState);
|
|
2092
|
+
const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
|
|
2093
|
+
onChange(hex);
|
|
2094
|
+
},
|
|
2095
|
+
[alpha, onChange]
|
|
2096
|
+
);
|
|
2097
|
+
const latest = (0, import_react22.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
|
|
2098
|
+
latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
|
|
2099
|
+
const endDragRef = (0, import_react22.useRef)(null);
|
|
2100
|
+
(0, import_react22.useEffect)(() => () => endDragRef.current?.(), []);
|
|
2101
|
+
const startDrag = (e, next) => {
|
|
2102
|
+
if (disabled) return;
|
|
2103
|
+
e.preventDefault();
|
|
2104
|
+
endDragRef.current?.();
|
|
2105
|
+
onGestureStart?.();
|
|
2106
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
2107
|
+
const update = (clientX, clientY) => {
|
|
2108
|
+
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
2109
|
+
const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
|
|
2110
|
+
latest.current.emitColorChange(next(stateRef.current, x, y));
|
|
2111
|
+
};
|
|
2112
|
+
update(e.clientX, e.clientY);
|
|
2113
|
+
const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
|
|
2114
|
+
const end = () => {
|
|
2115
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
2116
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
2117
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
2118
|
+
endDragRef.current = null;
|
|
2119
|
+
latest.current.onGestureEnd?.();
|
|
2120
|
+
};
|
|
2121
|
+
const onPointerUp = () => {
|
|
2122
|
+
end();
|
|
2123
|
+
latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
|
|
2124
|
+
};
|
|
2125
|
+
endDragRef.current = end;
|
|
2126
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
2127
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
2128
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
2129
|
+
};
|
|
2130
|
+
const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
|
|
2131
|
+
const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
|
|
2132
|
+
const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
|
|
2133
|
+
const handleAreaKeyDown = (e) => {
|
|
2134
|
+
if (disabled) return;
|
|
2135
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
|
|
2136
|
+
if (next) {
|
|
2137
|
+
e.preventDefault();
|
|
2138
|
+
emitColorChange(next);
|
|
2139
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
const handleHueKeyDown = (e) => {
|
|
2143
|
+
if (disabled) return;
|
|
2144
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
|
|
2145
|
+
if (next) {
|
|
2146
|
+
e.preventDefault();
|
|
2147
|
+
emitColorChange(next);
|
|
2148
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
const handleAlphaKeyDown = (e) => {
|
|
2152
|
+
if (disabled) return;
|
|
2153
|
+
const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
|
|
2154
|
+
if (next) {
|
|
2155
|
+
e.preventDefault();
|
|
2156
|
+
emitColorChange(next);
|
|
2157
|
+
recordRecent((0, import_color.pickerStateToHex)(next, alpha));
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
const commitTextInput = (inputElement) => {
|
|
2161
|
+
isTypingRef.current = false;
|
|
2162
|
+
const parsed = (0, import_color.parseColor)(textDraft);
|
|
2163
|
+
if (parsed) {
|
|
2164
|
+
setIsInvalid(false);
|
|
2165
|
+
setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
|
|
2166
|
+
const formatted = (0, import_color.formatHex)(parsed);
|
|
2167
|
+
onChange(formatted);
|
|
2168
|
+
recordRecent(formatted);
|
|
2169
|
+
} else {
|
|
2170
|
+
setIsInvalid(true);
|
|
2171
|
+
setTextDraft(value);
|
|
2172
|
+
if (inputElement) {
|
|
2173
|
+
inputElement.value = value;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
const handleTextKeyDown = (e) => {
|
|
2178
|
+
if (e.key === "Enter") {
|
|
2179
|
+
e.preventDefault();
|
|
2180
|
+
commitTextInput(e.currentTarget);
|
|
2181
|
+
} else if (e.key === "Escape") {
|
|
2182
|
+
e.preventDefault();
|
|
2183
|
+
isTypingRef.current = false;
|
|
2184
|
+
setIsInvalid(false);
|
|
2185
|
+
setTextDraft(value);
|
|
2186
|
+
e.currentTarget.value = value;
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
const handleEyeDropper = async () => {
|
|
2190
|
+
if (disabled || !hasEyeDropper) return;
|
|
2191
|
+
try {
|
|
2192
|
+
const EyeDropperClass = window.EyeDropper;
|
|
2193
|
+
const eyeDropper = new EyeDropperClass();
|
|
2194
|
+
const res = await eyeDropper.open();
|
|
2195
|
+
if (res?.sRGBHex) {
|
|
2196
|
+
onChange(res.sRGBHex);
|
|
2197
|
+
recordRecent(res.sRGBHex);
|
|
2198
|
+
}
|
|
2199
|
+
} catch {
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
const contrastResult = (0, import_react22.useMemo)(() => {
|
|
2203
|
+
if (!contrastAgainst) return null;
|
|
2204
|
+
const fg = (0, import_color.parseColor)(value);
|
|
2205
|
+
const bg = (0, import_color.parseColor)(contrastAgainst);
|
|
2206
|
+
if (!fg || !bg) return null;
|
|
2207
|
+
const ratio = (0, import_color.contrastRatio)(fg, bg);
|
|
2208
|
+
const aa = ratio >= 4.5;
|
|
2209
|
+
const aaa = ratio >= 7;
|
|
2210
|
+
return { ratio, aa, aaa };
|
|
2211
|
+
}, [value, contrastAgainst]);
|
|
2212
|
+
const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
|
|
2213
|
+
const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
|
|
2214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2215
|
+
"div",
|
|
2216
|
+
{
|
|
2217
|
+
id: pickerId,
|
|
2218
|
+
role: "group",
|
|
2219
|
+
"aria-label": ariaLabel,
|
|
2220
|
+
className,
|
|
2221
|
+
style: {
|
|
2222
|
+
boxSizing: "border-box",
|
|
2223
|
+
width: "var(--pixerate-color-picker-width, 240px)",
|
|
2224
|
+
borderRadius: "var(--pixerate-color-picker-radius, 8px)",
|
|
2225
|
+
background: "var(--pixerate-color-picker-bg, #1f2430)",
|
|
2226
|
+
color: "var(--pixerate-color-picker-fg, #f0f2f5)",
|
|
2227
|
+
padding: "12px",
|
|
2228
|
+
display: "flex",
|
|
2229
|
+
flexDirection: "column",
|
|
2230
|
+
gap: "10px",
|
|
2231
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
2232
|
+
fontSize: "12px",
|
|
2233
|
+
userSelect: "none",
|
|
2234
|
+
opacity: disabled ? 0.6 : 1,
|
|
2235
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
2236
|
+
},
|
|
2237
|
+
children: [
|
|
2238
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2239
|
+
"span",
|
|
2240
|
+
{
|
|
2241
|
+
role: "status",
|
|
2242
|
+
"aria-live": "polite",
|
|
2243
|
+
style: {
|
|
2244
|
+
position: "absolute",
|
|
2245
|
+
width: "1px",
|
|
2246
|
+
height: "1px",
|
|
2247
|
+
padding: 0,
|
|
2248
|
+
margin: "-1px",
|
|
2249
|
+
overflow: "hidden",
|
|
2250
|
+
clip: "rect(0, 0, 0, 0)",
|
|
2251
|
+
whiteSpace: "nowrap",
|
|
2252
|
+
border: 0
|
|
2253
|
+
},
|
|
2254
|
+
children: liveDescription
|
|
2255
|
+
}
|
|
2256
|
+
),
|
|
2257
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2258
|
+
"div",
|
|
2259
|
+
{
|
|
2260
|
+
role: "slider",
|
|
2261
|
+
tabIndex: disabled ? -1 : 0,
|
|
2262
|
+
"aria-label": "Saturation and brightness",
|
|
2263
|
+
"aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
|
|
2264
|
+
pickerState.v * 100
|
|
2265
|
+
)}%`,
|
|
2266
|
+
"aria-disabled": disabled,
|
|
2267
|
+
onPointerDown: handleAreaPointerDown,
|
|
2268
|
+
onKeyDown: handleAreaKeyDown,
|
|
2269
|
+
style: {
|
|
2270
|
+
position: "relative",
|
|
2271
|
+
width: "100%",
|
|
2272
|
+
height: "150px",
|
|
2273
|
+
borderRadius: "6px",
|
|
2274
|
+
background: (0, import_color.pickerAreaBackground)(pickerState),
|
|
2275
|
+
cursor: disabled ? "default" : "crosshair",
|
|
2276
|
+
touchAction: "none",
|
|
2277
|
+
outline: "none"
|
|
2278
|
+
},
|
|
2279
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2280
|
+
"div",
|
|
2281
|
+
{
|
|
2282
|
+
style: {
|
|
2283
|
+
position: "absolute",
|
|
2284
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2285
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2286
|
+
borderRadius: "50%",
|
|
2287
|
+
transform: "translate(-50%, -50%)",
|
|
2288
|
+
left: `${pickerState.s * 100}%`,
|
|
2289
|
+
top: `${(1 - pickerState.v) * 100}%`,
|
|
2290
|
+
border: "2px solid #ffffff",
|
|
2291
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
2292
|
+
pointerEvents: "none",
|
|
2293
|
+
backgroundColor: currentHex
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
)
|
|
2297
|
+
}
|
|
2298
|
+
),
|
|
2299
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2300
|
+
"div",
|
|
2301
|
+
{
|
|
2302
|
+
role: "slider",
|
|
2303
|
+
tabIndex: disabled ? -1 : 0,
|
|
2304
|
+
"aria-label": "Hue",
|
|
2305
|
+
"aria-valuenow": Math.round(pickerState.h),
|
|
2306
|
+
"aria-valuemin": 0,
|
|
2307
|
+
"aria-valuemax": 360,
|
|
2308
|
+
"aria-valuetext": `${Math.round(pickerState.h)} degrees`,
|
|
2309
|
+
"aria-disabled": disabled,
|
|
2310
|
+
onPointerDown: handleHuePointerDown,
|
|
2311
|
+
onKeyDown: handleHueKeyDown,
|
|
2312
|
+
style: {
|
|
2313
|
+
position: "relative",
|
|
2314
|
+
width: "100%",
|
|
2315
|
+
height: "12px",
|
|
2316
|
+
borderRadius: "6px",
|
|
2317
|
+
background: import_color.PICKER_HUE_BACKGROUND,
|
|
2318
|
+
cursor: disabled ? "default" : "pointer",
|
|
2319
|
+
touchAction: "none",
|
|
2320
|
+
outline: "none"
|
|
2321
|
+
},
|
|
2322
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2323
|
+
"div",
|
|
2324
|
+
{
|
|
2325
|
+
style: {
|
|
2326
|
+
position: "absolute",
|
|
2327
|
+
top: "50%",
|
|
2328
|
+
transform: "translate(-50%, -50%)",
|
|
2329
|
+
left: `${pickerState.h / 360 * 100}%`,
|
|
2330
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2331
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2332
|
+
borderRadius: "50%",
|
|
2333
|
+
border: "2px solid #ffffff",
|
|
2334
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
2335
|
+
pointerEvents: "none",
|
|
2336
|
+
backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
)
|
|
2340
|
+
}
|
|
2341
|
+
),
|
|
2342
|
+
alpha && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2343
|
+
"div",
|
|
2344
|
+
{
|
|
2345
|
+
role: "slider",
|
|
2346
|
+
tabIndex: disabled ? -1 : 0,
|
|
2347
|
+
"aria-label": "Alpha",
|
|
2348
|
+
"aria-valuenow": Math.round(pickerState.alpha * 100),
|
|
2349
|
+
"aria-valuemin": 0,
|
|
2350
|
+
"aria-valuemax": 100,
|
|
2351
|
+
"aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
|
|
2352
|
+
"aria-disabled": disabled,
|
|
2353
|
+
onPointerDown: handleAlphaPointerDown,
|
|
2354
|
+
onKeyDown: handleAlphaKeyDown,
|
|
2355
|
+
style: {
|
|
2356
|
+
position: "relative",
|
|
2357
|
+
width: "100%",
|
|
2358
|
+
height: "12px",
|
|
2359
|
+
borderRadius: "6px",
|
|
2360
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
2361
|
+
backgroundSize: "8px 8px",
|
|
2362
|
+
cursor: disabled ? "default" : "pointer",
|
|
2363
|
+
touchAction: "none",
|
|
2364
|
+
outline: "none",
|
|
2365
|
+
overflow: "hidden"
|
|
2366
|
+
},
|
|
2367
|
+
children: [
|
|
2368
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2369
|
+
"div",
|
|
2370
|
+
{
|
|
2371
|
+
style: {
|
|
2372
|
+
position: "absolute",
|
|
2373
|
+
inset: 0,
|
|
2374
|
+
background: (0, import_color.pickerAlphaBackground)(pickerState)
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
),
|
|
2378
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2379
|
+
"div",
|
|
2380
|
+
{
|
|
2381
|
+
style: {
|
|
2382
|
+
position: "absolute",
|
|
2383
|
+
top: "50%",
|
|
2384
|
+
transform: "translate(-50%, -50%)",
|
|
2385
|
+
left: `${pickerState.alpha * 100}%`,
|
|
2386
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2387
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
2388
|
+
borderRadius: "50%",
|
|
2389
|
+
border: "2px solid #ffffff",
|
|
2390
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
2391
|
+
pointerEvents: "none",
|
|
2392
|
+
backgroundColor: currentHex
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
)
|
|
2396
|
+
]
|
|
2397
|
+
}
|
|
2398
|
+
),
|
|
2399
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
|
|
2400
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2401
|
+
"div",
|
|
2402
|
+
{
|
|
2403
|
+
style: {
|
|
2404
|
+
position: "relative",
|
|
2405
|
+
width: "28px",
|
|
2406
|
+
height: "28px",
|
|
2407
|
+
borderRadius: "4px",
|
|
2408
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
2409
|
+
backgroundSize: "8px 8px",
|
|
2410
|
+
overflow: "hidden",
|
|
2411
|
+
flexShrink: 0,
|
|
2412
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
2413
|
+
},
|
|
2414
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2415
|
+
"div",
|
|
2416
|
+
{
|
|
2417
|
+
style: {
|
|
2418
|
+
width: "100%",
|
|
2419
|
+
height: "100%",
|
|
2420
|
+
backgroundColor: currentHex
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
)
|
|
2424
|
+
}
|
|
2425
|
+
),
|
|
2426
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2427
|
+
"input",
|
|
2428
|
+
{
|
|
2429
|
+
type: "text",
|
|
2430
|
+
value: textDraft,
|
|
2431
|
+
disabled,
|
|
2432
|
+
"aria-label": "Color hex or CSS string",
|
|
2433
|
+
"aria-invalid": isInvalid ? "true" : void 0,
|
|
2434
|
+
onChange: (e) => {
|
|
2435
|
+
isTypingRef.current = true;
|
|
2436
|
+
setTextDraft(e.target.value);
|
|
2437
|
+
setIsInvalid(false);
|
|
2438
|
+
},
|
|
2439
|
+
onKeyDown: handleTextKeyDown,
|
|
2440
|
+
onBlur: (e) => commitTextInput(e.currentTarget),
|
|
2441
|
+
style: {
|
|
2442
|
+
flex: 1,
|
|
2443
|
+
minWidth: 0,
|
|
2444
|
+
height: "28px",
|
|
2445
|
+
padding: "0 8px",
|
|
2446
|
+
fontSize: "12px",
|
|
2447
|
+
fontFamily: "monospace",
|
|
2448
|
+
borderRadius: "4px",
|
|
2449
|
+
border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
|
|
2450
|
+
background: "rgba(0,0,0,0.2)",
|
|
2451
|
+
color: "inherit",
|
|
2452
|
+
outline: "none"
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
),
|
|
2456
|
+
hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2457
|
+
"button",
|
|
2458
|
+
{
|
|
2459
|
+
type: "button",
|
|
2460
|
+
disabled,
|
|
2461
|
+
"aria-label": "Pick color from screen",
|
|
2462
|
+
title: "Pick color from screen",
|
|
2463
|
+
onClick: handleEyeDropper,
|
|
2464
|
+
style: {
|
|
2465
|
+
display: "inline-flex",
|
|
2466
|
+
alignItems: "center",
|
|
2467
|
+
justifyContent: "center",
|
|
2468
|
+
width: "28px",
|
|
2469
|
+
height: "28px",
|
|
2470
|
+
borderRadius: "4px",
|
|
2471
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
2472
|
+
background: "transparent",
|
|
2473
|
+
color: "inherit",
|
|
2474
|
+
cursor: disabled ? "default" : "pointer"
|
|
2475
|
+
},
|
|
2476
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2477
|
+
"svg",
|
|
2478
|
+
{
|
|
2479
|
+
width: "14",
|
|
2480
|
+
height: "14",
|
|
2481
|
+
viewBox: "0 0 24 24",
|
|
2482
|
+
fill: "none",
|
|
2483
|
+
stroke: "currentColor",
|
|
2484
|
+
strokeWidth: "2",
|
|
2485
|
+
strokeLinecap: "round",
|
|
2486
|
+
strokeLinejoin: "round",
|
|
2487
|
+
children: [
|
|
2488
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.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" }),
|
|
2489
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
|
|
2490
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "m14 6 4 4" })
|
|
2491
|
+
]
|
|
2492
|
+
}
|
|
2493
|
+
)
|
|
2494
|
+
}
|
|
2495
|
+
)
|
|
2496
|
+
] }),
|
|
2497
|
+
isClipped && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2498
|
+
"div",
|
|
2499
|
+
{
|
|
2500
|
+
role: "note",
|
|
2501
|
+
title: "This colour was outside standard sRGB and clipped.",
|
|
2502
|
+
style: {
|
|
2503
|
+
display: "inline-flex",
|
|
2504
|
+
alignItems: "center",
|
|
2505
|
+
gap: "4px",
|
|
2506
|
+
fontSize: "10px",
|
|
2507
|
+
color: "#f59e0b",
|
|
2508
|
+
background: "rgba(245, 158, 11, 0.1)",
|
|
2509
|
+
padding: "2px 6px",
|
|
2510
|
+
borderRadius: "4px",
|
|
2511
|
+
alignSelf: "flex-start"
|
|
2512
|
+
},
|
|
2513
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
|
|
2514
|
+
}
|
|
2515
|
+
),
|
|
2516
|
+
contrastResult && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2517
|
+
"div",
|
|
2518
|
+
{
|
|
2519
|
+
style: {
|
|
2520
|
+
display: "flex",
|
|
2521
|
+
alignItems: "center",
|
|
2522
|
+
justifyContent: "space-between",
|
|
2523
|
+
fontSize: "11px",
|
|
2524
|
+
padding: "4px 8px",
|
|
2525
|
+
borderRadius: "4px",
|
|
2526
|
+
background: "rgba(255,255,255,0.05)",
|
|
2527
|
+
border: "1px solid rgba(255,255,255,0.1)"
|
|
2528
|
+
},
|
|
2529
|
+
children: [
|
|
2530
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { children: [
|
|
2531
|
+
"Contrast: ",
|
|
2532
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("strong", { children: [
|
|
2533
|
+
contrastResult.ratio.toFixed(2),
|
|
2534
|
+
":1"
|
|
2535
|
+
] })
|
|
2536
|
+
] }),
|
|
2537
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
2538
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2539
|
+
"span",
|
|
2540
|
+
{
|
|
2541
|
+
style: {
|
|
2542
|
+
color: contrastResult.aa ? "#10b981" : "#ef4444",
|
|
2543
|
+
fontWeight: 600
|
|
2544
|
+
},
|
|
2545
|
+
children: [
|
|
2546
|
+
"AA ",
|
|
2547
|
+
contrastResult.aa ? "\u2713" : "\u2717"
|
|
2548
|
+
]
|
|
2549
|
+
}
|
|
2550
|
+
),
|
|
2551
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2552
|
+
"span",
|
|
2553
|
+
{
|
|
2554
|
+
style: {
|
|
2555
|
+
color: contrastResult.aaa ? "#10b981" : "#ef4444",
|
|
2556
|
+
fontWeight: 600
|
|
2557
|
+
},
|
|
2558
|
+
children: [
|
|
2559
|
+
"AAA ",
|
|
2560
|
+
contrastResult.aaa ? "\u2713" : "\u2717"
|
|
2561
|
+
]
|
|
2562
|
+
}
|
|
2563
|
+
)
|
|
2564
|
+
] })
|
|
2565
|
+
]
|
|
2566
|
+
}
|
|
2567
|
+
),
|
|
2568
|
+
swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
2569
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
|
|
2570
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2571
|
+
"button",
|
|
2572
|
+
{
|
|
2573
|
+
type: "button",
|
|
2574
|
+
"data-testid": "color-picker-swatch",
|
|
2575
|
+
title: color,
|
|
2576
|
+
disabled,
|
|
2577
|
+
"aria-label": `Color ${color}`,
|
|
2578
|
+
onClick: () => {
|
|
2579
|
+
onChange(color);
|
|
2580
|
+
recordRecent(color);
|
|
2581
|
+
},
|
|
2582
|
+
style: {
|
|
2583
|
+
width: "18px",
|
|
2584
|
+
height: "18px",
|
|
2585
|
+
borderRadius: "3px",
|
|
2586
|
+
backgroundColor: color,
|
|
2587
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
2588
|
+
cursor: disabled ? "default" : "pointer",
|
|
2589
|
+
padding: 0,
|
|
2590
|
+
outline: "none"
|
|
2591
|
+
}
|
|
2592
|
+
},
|
|
2593
|
+
`${color}-${idx}`
|
|
2594
|
+
)) })
|
|
2595
|
+
] }),
|
|
2596
|
+
activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
2597
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
|
|
2598
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2599
|
+
"button",
|
|
2600
|
+
{
|
|
2601
|
+
type: "button",
|
|
2602
|
+
"data-testid": "color-picker-recent",
|
|
2603
|
+
disabled,
|
|
2604
|
+
"aria-label": `Color ${color}`,
|
|
2605
|
+
onClick: () => {
|
|
2606
|
+
onChange(color);
|
|
2607
|
+
recordRecent(color);
|
|
2608
|
+
},
|
|
2609
|
+
style: {
|
|
2610
|
+
width: "18px",
|
|
2611
|
+
height: "18px",
|
|
2612
|
+
borderRadius: "3px",
|
|
2613
|
+
backgroundColor: color,
|
|
2614
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
2615
|
+
cursor: disabled ? "default" : "pointer",
|
|
2616
|
+
padding: 0,
|
|
2617
|
+
outline: "none"
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
`recent-${color}-${idx}`
|
|
2621
|
+
)) })
|
|
2622
|
+
] })
|
|
2623
|
+
]
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
// src/color/DualColorPicker.tsx
|
|
2629
|
+
var import_react23 = require("react");
|
|
2630
|
+
var import_color2 = require("@pixerate/editor/color");
|
|
2631
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
2632
|
+
function DualColorPicker({
|
|
2633
|
+
value,
|
|
2634
|
+
onChange,
|
|
2635
|
+
onGestureStart,
|
|
2636
|
+
onGestureEnd,
|
|
2637
|
+
scheme: controlledScheme,
|
|
2638
|
+
onSchemeChange,
|
|
2639
|
+
surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
|
|
2640
|
+
contrastAgainst,
|
|
2641
|
+
alpha = false,
|
|
2642
|
+
swatches,
|
|
2643
|
+
disabled = false,
|
|
2644
|
+
className = ""
|
|
2645
|
+
}) {
|
|
2646
|
+
const sameId = (0, import_react23.useId)();
|
|
2647
|
+
const [internalScheme, setInternalScheme] = (0, import_react23.useState)("light");
|
|
2648
|
+
const activeScheme = controlledScheme ?? internalScheme;
|
|
2649
|
+
const handleSchemeSelect = (nextScheme) => {
|
|
2650
|
+
if (onSchemeChange) {
|
|
2651
|
+
onSchemeChange(nextScheme);
|
|
2652
|
+
} else {
|
|
2653
|
+
setInternalScheme(nextScheme);
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
|
|
2657
|
+
const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
|
|
2658
|
+
const [sameInBoth, setSameInBoth] = (0, import_react23.useState)(isSame);
|
|
2659
|
+
const handleSameToggle = (e) => {
|
|
2660
|
+
const nextSame = e.target.checked;
|
|
2661
|
+
setSameInBoth(nextSame);
|
|
2662
|
+
if (nextSame) {
|
|
2663
|
+
const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2664
|
+
onChange({ light: activeVal, dark: activeVal });
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
const handleDerive = () => {
|
|
2668
|
+
if (disabled) return;
|
|
2669
|
+
onGestureStart?.();
|
|
2670
|
+
const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2671
|
+
const derived = (0, import_color2.deriveDualColor)(currentActive, {
|
|
2672
|
+
from: activeScheme,
|
|
2673
|
+
// An unreadable surfaces prop falls back to the defaults rather than throwing.
|
|
2674
|
+
surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
|
|
2675
|
+
});
|
|
2676
|
+
onChange(derived);
|
|
2677
|
+
onGestureEnd?.();
|
|
2678
|
+
};
|
|
2679
|
+
const handleInnerChange = (hex) => {
|
|
2680
|
+
if (sameInBoth) {
|
|
2681
|
+
onChange({ light: hex, dark: hex });
|
|
2682
|
+
} else {
|
|
2683
|
+
const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
|
|
2684
|
+
onChange(updated);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
|
|
2688
|
+
const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
|
|
2689
|
+
const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
|
|
2690
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2691
|
+
"div",
|
|
2692
|
+
{
|
|
2693
|
+
className: `pixerate-dual-color-picker ${className}`,
|
|
2694
|
+
style: {
|
|
2695
|
+
display: "flex",
|
|
2696
|
+
flexDirection: "column",
|
|
2697
|
+
gap: "12px",
|
|
2698
|
+
padding: "12px",
|
|
2699
|
+
background: "#1a1d24",
|
|
2700
|
+
color: "#e2e8f0",
|
|
2701
|
+
borderRadius: "10px",
|
|
2702
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
2703
|
+
width: "260px",
|
|
2704
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
2705
|
+
fontSize: "13px",
|
|
2706
|
+
boxSizing: "border-box"
|
|
2707
|
+
},
|
|
2708
|
+
children: [
|
|
2709
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2710
|
+
"div",
|
|
2711
|
+
{
|
|
2712
|
+
role: "tablist",
|
|
2713
|
+
"aria-label": "Color scheme mode",
|
|
2714
|
+
style: {
|
|
2715
|
+
display: "flex",
|
|
2716
|
+
background: "#111318",
|
|
2717
|
+
borderRadius: "6px",
|
|
2718
|
+
padding: "2px",
|
|
2719
|
+
gap: "2px"
|
|
2720
|
+
},
|
|
2721
|
+
children: [
|
|
2722
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2723
|
+
"button",
|
|
2724
|
+
{
|
|
2725
|
+
type: "button",
|
|
2726
|
+
role: "tab",
|
|
2727
|
+
"aria-selected": activeScheme === "light",
|
|
2728
|
+
onClick: () => handleSchemeSelect("light"),
|
|
2729
|
+
disabled,
|
|
2730
|
+
style: {
|
|
2731
|
+
flex: 1,
|
|
2732
|
+
padding: "6px 8px",
|
|
2733
|
+
border: "none",
|
|
2734
|
+
borderRadius: "4px",
|
|
2735
|
+
background: activeScheme === "light" ? "#2d3342" : "transparent",
|
|
2736
|
+
color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
|
|
2737
|
+
fontWeight: activeScheme === "light" ? 600 : 400,
|
|
2738
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2739
|
+
fontSize: "12px",
|
|
2740
|
+
transition: "all 0.15s ease"
|
|
2741
|
+
},
|
|
2742
|
+
children: "Light"
|
|
2743
|
+
}
|
|
2744
|
+
),
|
|
2745
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2746
|
+
"button",
|
|
2747
|
+
{
|
|
2748
|
+
type: "button",
|
|
2749
|
+
role: "tab",
|
|
2750
|
+
"aria-selected": activeScheme === "dark",
|
|
2751
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
2752
|
+
disabled,
|
|
2753
|
+
style: {
|
|
2754
|
+
flex: 1,
|
|
2755
|
+
padding: "6px 8px",
|
|
2756
|
+
border: "none",
|
|
2757
|
+
borderRadius: "4px",
|
|
2758
|
+
background: activeScheme === "dark" ? "#2d3342" : "transparent",
|
|
2759
|
+
color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
|
|
2760
|
+
fontWeight: activeScheme === "dark" ? 600 : 400,
|
|
2761
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2762
|
+
fontSize: "12px",
|
|
2763
|
+
transition: "all 0.15s ease"
|
|
2764
|
+
},
|
|
2765
|
+
children: "Dark"
|
|
2766
|
+
}
|
|
2767
|
+
)
|
|
2768
|
+
]
|
|
2769
|
+
}
|
|
2770
|
+
),
|
|
2771
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
2772
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2773
|
+
"button",
|
|
2774
|
+
{
|
|
2775
|
+
type: "button",
|
|
2776
|
+
onClick: () => handleSchemeSelect("light"),
|
|
2777
|
+
disabled,
|
|
2778
|
+
title: "Edit light mode colour",
|
|
2779
|
+
style: {
|
|
2780
|
+
flex: 1,
|
|
2781
|
+
display: "flex",
|
|
2782
|
+
flexDirection: "column",
|
|
2783
|
+
alignItems: "center",
|
|
2784
|
+
gap: "6px",
|
|
2785
|
+
padding: "8px",
|
|
2786
|
+
background: surfaces.light,
|
|
2787
|
+
color: "#000000",
|
|
2788
|
+
border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
2789
|
+
borderRadius: "6px",
|
|
2790
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2791
|
+
outline: "none"
|
|
2792
|
+
},
|
|
2793
|
+
children: [
|
|
2794
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2795
|
+
"span",
|
|
2796
|
+
{
|
|
2797
|
+
style: {
|
|
2798
|
+
width: "100%",
|
|
2799
|
+
height: "24px",
|
|
2800
|
+
borderRadius: "4px",
|
|
2801
|
+
background: dual.light,
|
|
2802
|
+
border: "1px solid rgba(0,0,0,0.15)"
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
),
|
|
2806
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
|
|
2807
|
+
]
|
|
2808
|
+
}
|
|
2809
|
+
),
|
|
2810
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2811
|
+
"button",
|
|
2812
|
+
{
|
|
2813
|
+
type: "button",
|
|
2814
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
2815
|
+
disabled,
|
|
2816
|
+
title: "Edit dark mode colour",
|
|
2817
|
+
style: {
|
|
2818
|
+
flex: 1,
|
|
2819
|
+
display: "flex",
|
|
2820
|
+
flexDirection: "column",
|
|
2821
|
+
alignItems: "center",
|
|
2822
|
+
gap: "6px",
|
|
2823
|
+
padding: "8px",
|
|
2824
|
+
background: surfaces.dark,
|
|
2825
|
+
color: "#ffffff",
|
|
2826
|
+
border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
2827
|
+
borderRadius: "6px",
|
|
2828
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2829
|
+
outline: "none"
|
|
2830
|
+
},
|
|
2831
|
+
children: [
|
|
2832
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2833
|
+
"span",
|
|
2834
|
+
{
|
|
2835
|
+
style: {
|
|
2836
|
+
width: "100%",
|
|
2837
|
+
height: "24px",
|
|
2838
|
+
borderRadius: "4px",
|
|
2839
|
+
background: dual.dark,
|
|
2840
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
),
|
|
2844
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
|
|
2845
|
+
]
|
|
2846
|
+
}
|
|
2847
|
+
)
|
|
2848
|
+
] }),
|
|
2849
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2850
|
+
"div",
|
|
2851
|
+
{
|
|
2852
|
+
style: {
|
|
2853
|
+
display: "flex",
|
|
2854
|
+
alignItems: "center",
|
|
2855
|
+
justifyContent: "space-between",
|
|
2856
|
+
gap: "8px",
|
|
2857
|
+
padding: "2px 0"
|
|
2858
|
+
},
|
|
2859
|
+
children: [
|
|
2860
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2861
|
+
"label",
|
|
2862
|
+
{
|
|
2863
|
+
htmlFor: sameId,
|
|
2864
|
+
style: {
|
|
2865
|
+
display: "flex",
|
|
2866
|
+
alignItems: "center",
|
|
2867
|
+
gap: "6px",
|
|
2868
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2869
|
+
userSelect: "none",
|
|
2870
|
+
fontSize: "12px",
|
|
2871
|
+
color: "#c4cad4"
|
|
2872
|
+
},
|
|
2873
|
+
children: [
|
|
2874
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2875
|
+
"input",
|
|
2876
|
+
{
|
|
2877
|
+
id: sameId,
|
|
2878
|
+
type: "checkbox",
|
|
2879
|
+
checked: sameInBoth,
|
|
2880
|
+
onChange: handleSameToggle,
|
|
2881
|
+
disabled,
|
|
2882
|
+
style: { cursor: disabled ? "not-allowed" : "pointer" }
|
|
2883
|
+
}
|
|
2884
|
+
),
|
|
2885
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "Same in both" })
|
|
2886
|
+
]
|
|
2887
|
+
}
|
|
2888
|
+
),
|
|
2889
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2890
|
+
"button",
|
|
2891
|
+
{
|
|
2892
|
+
type: "button",
|
|
2893
|
+
onClick: handleDerive,
|
|
2894
|
+
disabled,
|
|
2895
|
+
style: {
|
|
2896
|
+
padding: "4px 10px",
|
|
2897
|
+
background: "#2d3342",
|
|
2898
|
+
color: "#e2e8f0",
|
|
2899
|
+
border: "1px solid #3b4252",
|
|
2900
|
+
borderRadius: "4px",
|
|
2901
|
+
fontSize: "11px",
|
|
2902
|
+
fontWeight: 500,
|
|
2903
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
2904
|
+
},
|
|
2905
|
+
children: "Derive"
|
|
2906
|
+
}
|
|
2907
|
+
)
|
|
2908
|
+
]
|
|
2909
|
+
}
|
|
2910
|
+
),
|
|
2911
|
+
dualContrast && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2912
|
+
"div",
|
|
2913
|
+
{
|
|
2914
|
+
"data-testid": "dual-contrast-summary",
|
|
2915
|
+
style: {
|
|
2916
|
+
display: "flex",
|
|
2917
|
+
justifyContent: "space-between",
|
|
2918
|
+
background: "#111318",
|
|
2919
|
+
padding: "6px 8px",
|
|
2920
|
+
borderRadius: "6px",
|
|
2921
|
+
fontSize: "11px",
|
|
2922
|
+
color: "#8c95a6"
|
|
2923
|
+
},
|
|
2924
|
+
children: [
|
|
2925
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
|
|
2926
|
+
"Light:",
|
|
2927
|
+
" ",
|
|
2928
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
2929
|
+
dualContrast.light.ratio.toFixed(2),
|
|
2930
|
+
" (",
|
|
2931
|
+
dualContrast.light.level,
|
|
2932
|
+
")"
|
|
2933
|
+
] })
|
|
2934
|
+
] }),
|
|
2935
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
|
|
2936
|
+
"Dark:",
|
|
2937
|
+
" ",
|
|
2938
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
2939
|
+
dualContrast.dark.ratio.toFixed(2),
|
|
2940
|
+
" (",
|
|
2941
|
+
dualContrast.dark.level,
|
|
2942
|
+
")"
|
|
2943
|
+
] })
|
|
2944
|
+
] })
|
|
2945
|
+
]
|
|
2946
|
+
}
|
|
2947
|
+
),
|
|
2948
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
2949
|
+
ColorPicker,
|
|
2950
|
+
{
|
|
2951
|
+
value: activeColor,
|
|
2952
|
+
onChange: handleInnerChange,
|
|
2953
|
+
onGestureStart,
|
|
2954
|
+
onGestureEnd,
|
|
2955
|
+
contrastAgainst: activeContrastTarget,
|
|
2956
|
+
alpha,
|
|
2957
|
+
swatches,
|
|
2958
|
+
disabled
|
|
2959
|
+
}
|
|
2960
|
+
)
|
|
2961
|
+
]
|
|
2962
|
+
}
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
// src/color/useColorScheme.ts
|
|
2967
|
+
var import_react24 = require("react");
|
|
2968
|
+
var import_color3 = require("@pixerate/editor/color");
|
|
2969
|
+
function getSnapshot(attribute) {
|
|
2970
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2971
|
+
return "light";
|
|
2972
|
+
}
|
|
2973
|
+
if (attribute) {
|
|
2974
|
+
const el = document.documentElement;
|
|
2975
|
+
if (attribute === "class") {
|
|
2976
|
+
return el.classList.contains("dark") ? "dark" : "light";
|
|
2977
|
+
}
|
|
2978
|
+
const val = el.getAttribute(attribute);
|
|
2979
|
+
return val === "dark" ? "dark" : "light";
|
|
2980
|
+
}
|
|
2981
|
+
if (typeof window.matchMedia === "function") {
|
|
2982
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
2983
|
+
}
|
|
2984
|
+
return "light";
|
|
2985
|
+
}
|
|
2986
|
+
function getServerSnapshot() {
|
|
2987
|
+
return "light";
|
|
2988
|
+
}
|
|
2989
|
+
function useColorScheme(options) {
|
|
2990
|
+
const override = options?.override;
|
|
2991
|
+
const attribute = options?.attribute;
|
|
2992
|
+
const subscribe = (0, import_react24.useMemo)(() => {
|
|
2993
|
+
return (callback) => {
|
|
2994
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2995
|
+
return () => {
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
if (attribute) {
|
|
2999
|
+
const observer = new MutationObserver(() => {
|
|
3000
|
+
callback();
|
|
3001
|
+
});
|
|
3002
|
+
observer.observe(document.documentElement, {
|
|
3003
|
+
attributes: true,
|
|
3004
|
+
attributeFilter: [attribute]
|
|
3005
|
+
});
|
|
3006
|
+
return () => observer.disconnect();
|
|
3007
|
+
}
|
|
3008
|
+
if (typeof window.matchMedia === "function") {
|
|
3009
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
3010
|
+
const handler = () => callback();
|
|
3011
|
+
mql.addEventListener("change", handler);
|
|
3012
|
+
return () => mql.removeEventListener("change", handler);
|
|
3013
|
+
}
|
|
3014
|
+
return () => {
|
|
3015
|
+
};
|
|
3016
|
+
};
|
|
3017
|
+
}, [attribute]);
|
|
3018
|
+
const detected = (0, import_react24.useSyncExternalStore)(
|
|
3019
|
+
subscribe,
|
|
3020
|
+
() => getSnapshot(attribute),
|
|
3021
|
+
getServerSnapshot
|
|
3022
|
+
);
|
|
3023
|
+
return override ?? detected;
|
|
3024
|
+
}
|
|
3025
|
+
function useResolvedColor(value, scheme) {
|
|
3026
|
+
const detectedScheme = useColorScheme();
|
|
3027
|
+
const activeScheme = scheme ?? detectedScheme;
|
|
3028
|
+
return (0, import_color3.resolveColor)(value, activeScheme);
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
// src/color/index.ts
|
|
3032
|
+
__reExport(color_exports, require("@pixerate/editor/color"));
|
|
3033
|
+
|
|
3034
|
+
// src/parameters/fields.tsx
|
|
3035
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1994
3036
|
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";
|
|
1995
3037
|
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";
|
|
1996
3038
|
var rangeClass = "h-4 w-full min-w-0 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
@@ -2014,7 +3056,7 @@ function ParameterCommitInput({ value, onCommit, multiline, className, onKeyDown
|
|
|
2014
3056
|
onKeyDown: keyDown,
|
|
2015
3057
|
...rest
|
|
2016
3058
|
};
|
|
2017
|
-
return multiline ? /* @__PURE__ */ (0,
|
|
3059
|
+
return multiline ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("input", { type: "text", ...props }, value);
|
|
2018
3060
|
}
|
|
2019
3061
|
var plainNumber = (field, value) => (0, import_parameters.formatParameterNumber)({ ...field, unit: void 0 }, value);
|
|
2020
3062
|
function ParameterNumberInput({
|
|
@@ -2025,8 +3067,8 @@ function ParameterNumberInput({
|
|
|
2025
3067
|
id,
|
|
2026
3068
|
"aria-label": ariaLabel
|
|
2027
3069
|
}) {
|
|
2028
|
-
return /* @__PURE__ */ (0,
|
|
2029
|
-
/* @__PURE__ */ (0,
|
|
3070
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
|
|
3071
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2030
3072
|
ParameterCommitInput,
|
|
2031
3073
|
{
|
|
2032
3074
|
id,
|
|
@@ -2048,21 +3090,21 @@ function ParameterNumberInput({
|
|
|
2048
3090
|
}
|
|
2049
3091
|
}
|
|
2050
3092
|
),
|
|
2051
|
-
field.unit && /* @__PURE__ */ (0,
|
|
3093
|
+
field.unit && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
|
|
2052
3094
|
] });
|
|
2053
3095
|
}
|
|
2054
3096
|
function ParameterSlider(props) {
|
|
2055
3097
|
const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
|
|
2056
|
-
const dragging = (0,
|
|
3098
|
+
const dragging = (0, import_react25.useRef)(false);
|
|
2057
3099
|
const end = () => {
|
|
2058
3100
|
if (!dragging.current) return;
|
|
2059
3101
|
dragging.current = false;
|
|
2060
3102
|
onGestureEnd?.();
|
|
2061
3103
|
};
|
|
2062
|
-
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0,
|
|
3104
|
+
if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterNumberInput, { ...props });
|
|
2063
3105
|
const step = (0, import_parameters.parameterStep)(field);
|
|
2064
|
-
return /* @__PURE__ */ (0,
|
|
2065
|
-
/* @__PURE__ */ (0,
|
|
3106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
3107
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2066
3108
|
"input",
|
|
2067
3109
|
{
|
|
2068
3110
|
type: "range",
|
|
@@ -2085,11 +3127,11 @@ function ParameterSlider(props) {
|
|
|
2085
3127
|
onChange: (e) => onChange((0, import_parameters.clampParameterNumber)(field, Number(e.target.value)))
|
|
2086
3128
|
}
|
|
2087
3129
|
),
|
|
2088
|
-
/* @__PURE__ */ (0,
|
|
3130
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters.parameterLabel)(field)} value` }) })
|
|
2089
3131
|
] });
|
|
2090
3132
|
}
|
|
2091
3133
|
function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
2092
|
-
return /* @__PURE__ */ (0,
|
|
3134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2093
3135
|
"button",
|
|
2094
3136
|
{
|
|
2095
3137
|
type: "button",
|
|
@@ -2100,7 +3142,7 @@ function ParameterToggle({ field, value, onChange, disabled, id }) {
|
|
|
2100
3142
|
disabled: disabled || field.readOnly,
|
|
2101
3143
|
onClick: () => onChange(!value),
|
|
2102
3144
|
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"}`,
|
|
2103
|
-
children: /* @__PURE__ */ (0,
|
|
3145
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2104
3146
|
"span",
|
|
2105
3147
|
{
|
|
2106
3148
|
className: `pointer-events-none block h-4 w-4 rounded-full bg-background shadow transition-transform ${value ? "translate-x-4" : "translate-x-0.5"}`
|
|
@@ -2113,7 +3155,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
2113
3155
|
const options = (0, import_parameters.getChoiceOptions)(field);
|
|
2114
3156
|
const off = disabled || field.readOnly;
|
|
2115
3157
|
if (field.control === "segmented") {
|
|
2116
|
-
return /* @__PURE__ */ (0,
|
|
3158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.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_runtime11.jsx)(
|
|
2117
3159
|
"button",
|
|
2118
3160
|
{
|
|
2119
3161
|
type: "button",
|
|
@@ -2129,7 +3171,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
2129
3171
|
)) });
|
|
2130
3172
|
}
|
|
2131
3173
|
const index = options.findIndex((o) => o.value === value);
|
|
2132
|
-
return /* @__PURE__ */ (0,
|
|
3174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2133
3175
|
"select",
|
|
2134
3176
|
{
|
|
2135
3177
|
id,
|
|
@@ -2141,53 +3183,64 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
2141
3183
|
if (option) onChange(option.value);
|
|
2142
3184
|
},
|
|
2143
3185
|
className: parameterInputClass,
|
|
2144
|
-
children: options.map((o, i) => /* @__PURE__ */ (0,
|
|
3186
|
+
children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters.choiceOptionLabel)(o) }, String(o.value)))
|
|
2145
3187
|
}
|
|
2146
3188
|
);
|
|
2147
3189
|
}
|
|
2148
3190
|
function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
|
|
2149
|
-
const
|
|
3191
|
+
const [open, setOpen] = (0, import_react25.useState)(false);
|
|
3192
|
+
const containerRef = (0, import_react25.useRef)(null);
|
|
3193
|
+
const buttonRef = (0, import_react25.useRef)(null);
|
|
3194
|
+
const popoverRef = (0, import_react25.useRef)(null);
|
|
2150
3195
|
const alpha = !!field.alpha;
|
|
2151
3196
|
const hex = (0, import_parameters.normalizeHexColor)(value, true) ?? "#000000ff";
|
|
2152
3197
|
const rgb = hex.slice(0, 7);
|
|
2153
|
-
const
|
|
3198
|
+
const shown = alpha ? hex : rgb;
|
|
2154
3199
|
const off = disabled || field.readOnly;
|
|
2155
|
-
const
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
3200
|
+
const name = (0, import_parameters.parameterLabel)(field);
|
|
3201
|
+
(0, import_react25.useEffect)(() => {
|
|
3202
|
+
if (!open) return;
|
|
3203
|
+
const onPointerDown = (e) => {
|
|
3204
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
3205
|
+
setOpen(false);
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3208
|
+
const onKeyDown = (e) => {
|
|
3209
|
+
if (e.key === "Escape") {
|
|
3210
|
+
e.stopPropagation();
|
|
3211
|
+
setOpen(false);
|
|
3212
|
+
buttonRef.current?.focus();
|
|
3213
|
+
}
|
|
3214
|
+
};
|
|
3215
|
+
window.addEventListener("pointerdown", onPointerDown, true);
|
|
3216
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
3217
|
+
return () => {
|
|
3218
|
+
window.removeEventListener("pointerdown", onPointerDown, true);
|
|
3219
|
+
window.removeEventListener("keydown", onKeyDown, true);
|
|
3220
|
+
};
|
|
3221
|
+
}, [open]);
|
|
3222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "relative space-y-1.5", children: [
|
|
3223
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
3224
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3225
|
+
"button",
|
|
3226
|
+
{
|
|
3227
|
+
ref: buttonRef,
|
|
3228
|
+
type: "button",
|
|
3229
|
+
"aria-label": name,
|
|
3230
|
+
"aria-expanded": open,
|
|
3231
|
+
"aria-haspopup": "dialog",
|
|
3232
|
+
disabled: off,
|
|
3233
|
+
onClick: () => setOpen((prev) => !prev),
|
|
3234
|
+
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",
|
|
3235
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "absolute inset-0", style: { background: shown } })
|
|
3236
|
+
}
|
|
3237
|
+
),
|
|
3238
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2186
3239
|
ParameterCommitInput,
|
|
2187
3240
|
{
|
|
2188
3241
|
id,
|
|
2189
|
-
"aria-label": `${
|
|
2190
|
-
value:
|
|
3242
|
+
"aria-label": `${name} hex`,
|
|
3243
|
+
value: shown,
|
|
2191
3244
|
disabled: off,
|
|
2192
3245
|
spellCheck: false,
|
|
2193
3246
|
className: `${parameterInputClass} font-mono`,
|
|
@@ -2198,51 +3251,43 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
|
|
|
2198
3251
|
}
|
|
2199
3252
|
)
|
|
2200
3253
|
] }),
|
|
2201
|
-
|
|
2202
|
-
"
|
|
3254
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3255
|
+
"div",
|
|
2203
3256
|
{
|
|
2204
|
-
|
|
2205
|
-
"
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
onPointerDown: start,
|
|
2213
|
-
onPointerUp: end,
|
|
2214
|
-
onPointerCancel: end,
|
|
2215
|
-
onBlur: end,
|
|
2216
|
-
onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
|
|
2217
|
-
}
|
|
2218
|
-
),
|
|
2219
|
-
field.swatches && field.swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
|
|
2220
|
-
const swatch = (0, import_parameters.normalizeHexColor)(s, alpha);
|
|
2221
|
-
if (!swatch) return null;
|
|
2222
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2223
|
-
"button",
|
|
2224
|
-
{
|
|
2225
|
-
type: "button",
|
|
2226
|
-
title: swatch,
|
|
2227
|
-
"aria-label": `${(0, import_parameters.parameterLabel)(field)} ${swatch}`,
|
|
2228
|
-
"aria-pressed": swatch === (alpha ? hex : rgb),
|
|
2229
|
-
disabled: off,
|
|
2230
|
-
onClick: () => onChange(swatch),
|
|
2231
|
-
className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
|
|
2232
|
-
style: { background: swatch }
|
|
3257
|
+
ref: popoverRef,
|
|
3258
|
+
role: "dialog",
|
|
3259
|
+
"aria-label": name,
|
|
3260
|
+
tabIndex: -1,
|
|
3261
|
+
onBlur: (e) => {
|
|
3262
|
+
if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
|
|
3263
|
+
setOpen(false);
|
|
3264
|
+
}
|
|
2233
3265
|
},
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
3266
|
+
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",
|
|
3267
|
+
style: { background: "var(--popover, var(--background, #fff))" },
|
|
3268
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3269
|
+
ColorPicker,
|
|
3270
|
+
{
|
|
3271
|
+
value: shown,
|
|
3272
|
+
alpha,
|
|
3273
|
+
swatches: field.swatches,
|
|
3274
|
+
disabled: off,
|
|
3275
|
+
onChange,
|
|
3276
|
+
onGestureStart,
|
|
3277
|
+
onGestureEnd
|
|
3278
|
+
}
|
|
3279
|
+
)
|
|
3280
|
+
}
|
|
3281
|
+
)
|
|
2237
3282
|
] });
|
|
2238
3283
|
}
|
|
2239
3284
|
function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
2240
3285
|
const size = (0, import_parameters.vectorSize)(field);
|
|
2241
|
-
return /* @__PURE__ */ (0,
|
|
3286
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
|
|
2242
3287
|
const component = (0, import_parameters.vectorComponentField)(field, i);
|
|
2243
|
-
return /* @__PURE__ */ (0,
|
|
2244
|
-
/* @__PURE__ */ (0,
|
|
2245
|
-
/* @__PURE__ */ (0,
|
|
3288
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
|
|
3289
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
|
|
3290
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2246
3291
|
ParameterNumberInput,
|
|
2247
3292
|
{
|
|
2248
3293
|
field: component,
|
|
@@ -2259,11 +3304,11 @@ function ParameterVector({ field, value, onChange, disabled, id }) {
|
|
|
2259
3304
|
function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
2260
3305
|
const off = disabled || field.readOnly;
|
|
2261
3306
|
const name = (0, import_parameters.parameterLabel)(field);
|
|
2262
|
-
return /* @__PURE__ */ (0,
|
|
2263
|
-
/* @__PURE__ */ (0,
|
|
2264
|
-
/* @__PURE__ */ (0,
|
|
2265
|
-
/* @__PURE__ */ (0,
|
|
2266
|
-
/* @__PURE__ */ (0,
|
|
3307
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "space-y-1.5", children: [
|
|
3308
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
3309
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.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_runtime11.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
|
|
3310
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
3311
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2267
3312
|
ParameterCommitInput,
|
|
2268
3313
|
{
|
|
2269
3314
|
id,
|
|
@@ -2274,10 +3319,10 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
2274
3319
|
onCommit: (text) => onChange(text.trim())
|
|
2275
3320
|
}
|
|
2276
3321
|
),
|
|
2277
|
-
/* @__PURE__ */ (0,
|
|
2278
|
-
resolveFile && /* @__PURE__ */ (0,
|
|
3322
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex gap-1", children: [
|
|
3323
|
+
resolveFile && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
|
|
2279
3324
|
"Choose file\u2026",
|
|
2280
|
-
/* @__PURE__ */ (0,
|
|
3325
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2281
3326
|
"input",
|
|
2282
3327
|
{
|
|
2283
3328
|
type: "file",
|
|
@@ -2293,11 +3338,11 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
2293
3338
|
}
|
|
2294
3339
|
)
|
|
2295
3340
|
] }),
|
|
2296
|
-
value && /* @__PURE__ */ (0,
|
|
3341
|
+
value && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
|
|
2297
3342
|
] })
|
|
2298
3343
|
] })
|
|
2299
3344
|
] }),
|
|
2300
|
-
field.options && field.options.length > 0 && /* @__PURE__ */ (0,
|
|
3345
|
+
field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2301
3346
|
"button",
|
|
2302
3347
|
{
|
|
2303
3348
|
type: "button",
|
|
@@ -2307,14 +3352,14 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
|
|
|
2307
3352
|
disabled: off,
|
|
2308
3353
|
onClick: () => onChange(o.url),
|
|
2309
3354
|
className: "h-9 w-12 overflow-hidden rounded border border-input aria-pressed:ring-2 aria-pressed:ring-primary",
|
|
2310
|
-
children: /* @__PURE__ */ (0,
|
|
3355
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
|
|
2311
3356
|
},
|
|
2312
3357
|
o.url
|
|
2313
3358
|
)) })
|
|
2314
3359
|
] });
|
|
2315
3360
|
}
|
|
2316
3361
|
function ParameterText({ field, value, onChange, disabled, id }) {
|
|
2317
|
-
return /* @__PURE__ */ (0,
|
|
3362
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
2318
3363
|
ParameterCommitInput,
|
|
2319
3364
|
{
|
|
2320
3365
|
id,
|
|
@@ -2333,31 +3378,31 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
|
|
|
2333
3378
|
switch (field.type) {
|
|
2334
3379
|
case "number":
|
|
2335
3380
|
case "int":
|
|
2336
|
-
return /* @__PURE__ */ (0,
|
|
3381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
|
|
2337
3382
|
case "boolean":
|
|
2338
|
-
return /* @__PURE__ */ (0,
|
|
3383
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
|
|
2339
3384
|
case "choice":
|
|
2340
|
-
return /* @__PURE__ */ (0,
|
|
3385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
|
|
2341
3386
|
case "color":
|
|
2342
|
-
return /* @__PURE__ */ (0,
|
|
3387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
|
|
2343
3388
|
case "vector":
|
|
2344
|
-
return /* @__PURE__ */ (0,
|
|
3389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
|
|
2345
3390
|
case "image":
|
|
2346
|
-
return /* @__PURE__ */ (0,
|
|
3391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
|
|
2347
3392
|
case "text":
|
|
2348
|
-
return /* @__PURE__ */ (0,
|
|
3393
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ParameterText, { field, value, onChange: set, ...rest });
|
|
2349
3394
|
}
|
|
2350
3395
|
}
|
|
2351
3396
|
|
|
2352
3397
|
// src/effects/EffectParameters.tsx
|
|
2353
|
-
var
|
|
3398
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2354
3399
|
function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
|
|
2355
|
-
const fields = (0,
|
|
2356
|
-
const idBase = (0,
|
|
2357
|
-
const gesture =
|
|
2358
|
-
const count =
|
|
2359
|
-
return /* @__PURE__ */ (0,
|
|
2360
|
-
onPreset && description.presets.length > 0 && /* @__PURE__ */ (0,
|
|
3400
|
+
const fields = (0, import_react26.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
|
|
3401
|
+
const idBase = (0, import_react26.useId)();
|
|
3402
|
+
const gesture = import_react26.default.useRef(null);
|
|
3403
|
+
const count = import_react26.default.useRef(0);
|
|
3404
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
|
|
3405
|
+
onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
2361
3406
|
"select",
|
|
2362
3407
|
{
|
|
2363
3408
|
className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
|
|
@@ -2369,8 +3414,8 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
2369
3414
|
if (preset) onPreset({ ...description.defaults, ...preset.values });
|
|
2370
3415
|
},
|
|
2371
3416
|
children: [
|
|
2372
|
-
/* @__PURE__ */ (0,
|
|
2373
|
-
description.presets.map((p) => /* @__PURE__ */ (0,
|
|
3417
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "", children: "Presets\u2026" }),
|
|
3418
|
+
description.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: p.name, children: p.name }, p.name))
|
|
2374
3419
|
]
|
|
2375
3420
|
}
|
|
2376
3421
|
),
|
|
@@ -2380,13 +3425,13 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
2380
3425
|
const keyed = keyframed?.has(field.id) ?? false;
|
|
2381
3426
|
const value = (0, import_effects3.effectFieldValue)(field, values[field.id]);
|
|
2382
3427
|
const changed = !keyed && !(0, import_parameters2.parameterValuesEqual)(value, field.default);
|
|
2383
|
-
return /* @__PURE__ */ (0,
|
|
2384
|
-
/* @__PURE__ */ (0,
|
|
2385
|
-
/* @__PURE__ */ (0,
|
|
2386
|
-
keyed && /* @__PURE__ */ (0,
|
|
2387
|
-
onReset && changed && !disabled && /* @__PURE__ */ (0,
|
|
3428
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "space-y-1", "data-effect-control": field.id, children: [
|
|
3429
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "flex items-center gap-1.5", children: [
|
|
3430
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
|
|
3431
|
+
keyed && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
|
|
3432
|
+
onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime12.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" })
|
|
2388
3433
|
] }),
|
|
2389
|
-
/* @__PURE__ */ (0,
|
|
3434
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
2390
3435
|
ParameterFieldControl,
|
|
2391
3436
|
{
|
|
2392
3437
|
field,
|
|
@@ -2400,46 +3445,46 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
|
|
|
2400
3445
|
)
|
|
2401
3446
|
] }, field.id);
|
|
2402
3447
|
}),
|
|
2403
|
-
!fields.length && /* @__PURE__ */ (0,
|
|
3448
|
+
!fields.length && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
|
|
2404
3449
|
] });
|
|
2405
3450
|
}
|
|
2406
3451
|
|
|
2407
3452
|
// src/canvas/CanvasEffects.tsx
|
|
2408
|
-
var
|
|
2409
|
-
var ProviderContext = (0,
|
|
3453
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3454
|
+
var ProviderContext = (0, import_react27.createContext)(null);
|
|
2410
3455
|
function CanvasEffectsProvider({ provider, children }) {
|
|
2411
|
-
return /* @__PURE__ */ (0,
|
|
3456
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ProviderContext.Provider, { value: provider ?? null, children });
|
|
2412
3457
|
}
|
|
2413
|
-
var useCanvasEffectsProviderContext = () => (0,
|
|
3458
|
+
var useCanvasEffectsProviderContext = () => (0, import_react27.useContext)(ProviderContext);
|
|
2414
3459
|
function CanvasNodeEffectLayer({ effect, width, height, clipPath, clipTransform }) {
|
|
2415
3460
|
const provider = useCanvasEffectsProviderContext();
|
|
2416
|
-
const ref = (0,
|
|
2417
|
-
const [failed, setFailed] = (0,
|
|
3461
|
+
const ref = (0, import_react27.useRef)(null);
|
|
3462
|
+
const [failed, setFailed] = (0, import_react27.useState)(false);
|
|
2418
3463
|
const dpr = typeof window !== "undefined" ? Math.min(2, window.devicePixelRatio || 1) : 1;
|
|
2419
3464
|
const pw = Math.max(1, Math.round(width * dpr));
|
|
2420
3465
|
const ph = Math.max(1, Math.round(height * dpr));
|
|
2421
3466
|
const key = JSON.stringify(effect);
|
|
2422
|
-
(0,
|
|
3467
|
+
(0, import_react27.useEffect)(() => {
|
|
2423
3468
|
const canvas2 = ref.current;
|
|
2424
3469
|
if (!provider || !canvas2) return;
|
|
2425
3470
|
setFailed(false);
|
|
2426
3471
|
const run = (0, import_canvas14.runCanvasNodeEffect)({ provider, effect, target: canvas2, onError: () => setFailed(true) });
|
|
2427
3472
|
return () => run.stop();
|
|
2428
3473
|
}, [provider, key, pw, ph]);
|
|
2429
|
-
const clipId = (0,
|
|
3474
|
+
const clipId = (0, import_react27.useMemo)(() => `pixerate-effect-clip-${Math.random().toString(36).slice(2)}`, []);
|
|
2430
3475
|
if (!provider || failed || !(width > 0 && height > 0)) return null;
|
|
2431
3476
|
const style = { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none", opacity: effect.opacity ?? 1 };
|
|
2432
|
-
const canvas = /* @__PURE__ */ (0,
|
|
2433
|
-
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ (0,
|
|
2434
|
-
return /* @__PURE__ */ (0,
|
|
2435
|
-
/* @__PURE__ */ (0,
|
|
2436
|
-
/* @__PURE__ */ (0,
|
|
3477
|
+
const canvas = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("canvas", { ref, width: pw, height: ph, style: { width: "100%", height: "100%", display: "block" }, "data-canvas-effect": effect.effect });
|
|
3478
|
+
if (effect.mode === "overlay" || !clipPath) return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style, children: canvas });
|
|
3479
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("svg", { style, viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", "aria-hidden": "true", children: [
|
|
3480
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("clipPath", { id: clipId, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("path", { d: clipPath, transform: clipTransform }) }) }),
|
|
3481
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("foreignObject", { x: 0, y: 0, width, height, clipPath: `url(#${clipId})`, children: canvas })
|
|
2437
3482
|
] });
|
|
2438
3483
|
}
|
|
2439
3484
|
function useCanvasEffects(options) {
|
|
2440
|
-
const opts = (0,
|
|
3485
|
+
const opts = (0, import_react27.useRef)(options);
|
|
2441
3486
|
opts.current = options;
|
|
2442
|
-
const controller = (0,
|
|
3487
|
+
const controller = (0, import_react27.useMemo)(
|
|
2443
3488
|
() => (0, import_canvas14.createCanvasEffectsController)({
|
|
2444
3489
|
getNodes: () => opts.current.getNodes(),
|
|
2445
3490
|
setNodes: (n) => opts.current.setNodes(n),
|
|
@@ -2450,7 +3495,7 @@ function useCanvasEffects(options) {
|
|
|
2450
3495
|
}),
|
|
2451
3496
|
[]
|
|
2452
3497
|
);
|
|
2453
|
-
(0,
|
|
3498
|
+
(0, import_react27.useEffect)(() => {
|
|
2454
3499
|
if (!options.effects) return;
|
|
2455
3500
|
return controller.useEffects(options.effects);
|
|
2456
3501
|
}, [controller, options.effects]);
|
|
@@ -2458,7 +3503,7 @@ function useCanvasEffects(options) {
|
|
|
2458
3503
|
}
|
|
2459
3504
|
function useCanvasEffectsTools(registry, controller, options = {}) {
|
|
2460
3505
|
const { id, namespace, readOnly, subscribe } = options;
|
|
2461
|
-
(0,
|
|
3506
|
+
(0, import_react27.useEffect)(() => {
|
|
2462
3507
|
if (!registry) return;
|
|
2463
3508
|
return registry.register((0, import_canvas14.createCanvasEffectsToolProvider)(controller, { id, namespace, readOnly, subscribe }));
|
|
2464
3509
|
}, [registry, controller, id, namespace, readOnly, subscribe]);
|
|
@@ -2466,12 +3511,12 @@ function useCanvasEffectsTools(registry, controller, options = {}) {
|
|
|
2466
3511
|
var btn = "rounded border border-border px-1.5 py-0.5 text-[11px] disabled:opacity-40";
|
|
2467
3512
|
function Controls({ controller, nodeId, effect }) {
|
|
2468
3513
|
const { description, error } = useEffectDescription(controller.effectsProvider, effect.effect);
|
|
2469
|
-
const [message, setMessage] = (0,
|
|
3514
|
+
const [message, setMessage] = (0, import_react27.useState)(null);
|
|
2470
3515
|
const run = (work) => void work.then(() => setMessage(null), (e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
2471
|
-
if (error) return /* @__PURE__ */ (0,
|
|
2472
|
-
if (!description) return /* @__PURE__ */ (0,
|
|
2473
|
-
return /* @__PURE__ */ (0,
|
|
2474
|
-
/* @__PURE__ */ (0,
|
|
3516
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-[11px] text-amber-500", children: error });
|
|
3517
|
+
if (!description) return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Loading\u2026" });
|
|
3518
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
3519
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2475
3520
|
EffectParameters,
|
|
2476
3521
|
{
|
|
2477
3522
|
description,
|
|
@@ -2481,75 +3526,75 @@ function Controls({ controller, nodeId, effect }) {
|
|
|
2481
3526
|
onPreset: (v) => run(controller.updateNodeEffect(nodeId, { values: v }))
|
|
2482
3527
|
}
|
|
2483
3528
|
),
|
|
2484
|
-
message && /* @__PURE__ */ (0,
|
|
3529
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
2485
3530
|
] });
|
|
2486
3531
|
}
|
|
2487
3532
|
function CanvasEffectsPanel({ controller, nodeId, shape, sceneId, className = "" }) {
|
|
2488
|
-
const [, setTick] = (0,
|
|
2489
|
-
(0,
|
|
3533
|
+
const [, setTick] = (0, import_react27.useState)(0);
|
|
3534
|
+
(0, import_react27.useEffect)(() => controller.effects.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
2490
3535
|
const provider = controller.effectsProvider;
|
|
2491
|
-
const [browse, setBrowse] = (0,
|
|
2492
|
-
const [message, setMessage] = (0,
|
|
3536
|
+
const [browse, setBrowse] = (0, import_react27.useState)(null);
|
|
3537
|
+
const [message, setMessage] = (0, import_react27.useState)(null);
|
|
2493
3538
|
const run = (work) => {
|
|
2494
3539
|
setMessage(null);
|
|
2495
3540
|
Promise.resolve().then(work).then(() => setTick((n) => n + 1), (e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
2496
3541
|
};
|
|
2497
3542
|
const effect = (0, import_canvas14.isShapeDescription)(shape) ? shape.effect : void 0;
|
|
2498
3543
|
const transition = sceneId ? controller.sceneTransition(sceneId) : void 0;
|
|
2499
|
-
return /* @__PURE__ */ (0,
|
|
2500
|
-
/* @__PURE__ */ (0,
|
|
2501
|
-
/* @__PURE__ */ (0,
|
|
2502
|
-
/* @__PURE__ */ (0,
|
|
2503
|
-
/* @__PURE__ */ (0,
|
|
2504
|
-
/* @__PURE__ */ (0,
|
|
3544
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("section", { className: `flex flex-col gap-2 text-xs ${className}`, "aria-label": "Canvas effects", "data-canvas-effects": "", children: [
|
|
3545
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
3546
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "flex-1 font-semibold", children: "Effects" }),
|
|
3547
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: btn, disabled: !provider || !nodeId || !shape, "aria-pressed": browse === "fill", onClick: () => setBrowse(browse === "fill" ? null : "fill"), children: "Fill\u2026" }),
|
|
3548
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: btn, disabled: !provider || !nodeId || !shape, "aria-pressed": browse === "overlay", onClick: () => setBrowse(browse === "overlay" ? null : "overlay"), children: "Overlay\u2026" }),
|
|
3549
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: btn, disabled: !provider || !sceneId, "aria-pressed": browse === "transition", onClick: () => setBrowse(browse === "transition" ? null : "transition"), children: "Scene transition\u2026" })
|
|
2505
3550
|
] }),
|
|
2506
|
-
!provider && /* @__PURE__ */ (0,
|
|
2507
|
-
browse === "fill" && nodeId && /* @__PURE__ */ (0,
|
|
2508
|
-
browse === "overlay" && nodeId && /* @__PURE__ */ (0,
|
|
2509
|
-
browse === "transition" && sceneId && /* @__PURE__ */ (0,
|
|
2510
|
-
effect && nodeId && /* @__PURE__ */ (0,
|
|
2511
|
-
/* @__PURE__ */ (0,
|
|
2512
|
-
/* @__PURE__ */ (0,
|
|
3551
|
+
!provider && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider is registered. Effects on the canvas are kept." }),
|
|
3552
|
+
browse === "fill" && nodeId && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(EffectsBrowser, { provider, uses: ["generator", "interactive"], title: "Fills", onPick: (e) => (setBrowse(null), run(() => controller.applyNodeEffect(nodeId, e.id, { mode: "fill" }))) }),
|
|
3553
|
+
browse === "overlay" && nodeId && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(EffectsBrowser, { provider, uses: ["overlay", "title", "interactive", "generator"], title: "Overlays", onPick: (e) => (setBrowse(null), run(() => controller.applyNodeEffect(nodeId, e.id, { mode: "overlay" }))) }),
|
|
3554
|
+
browse === "transition" && sceneId && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(EffectsBrowser, { provider, uses: ["transition"], title: "Transitions", onPick: (e) => (setBrowse(null), run(() => controller.setSceneTransition(sceneId, e.id))) }),
|
|
3555
|
+
effect && nodeId && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "space-y-1 rounded border border-border p-1", "data-canvas-node-effect": nodeId, children: [
|
|
3556
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3557
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "min-w-0 flex-1 truncate font-medium", children: [
|
|
2513
3558
|
effect.name ?? effect.effect,
|
|
2514
3559
|
" ",
|
|
2515
|
-
/* @__PURE__ */ (0,
|
|
3560
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "text-muted-foreground", children: [
|
|
2516
3561
|
"\xB7 ",
|
|
2517
3562
|
effect.mode
|
|
2518
3563
|
] })
|
|
2519
3564
|
] }),
|
|
2520
|
-
/* @__PURE__ */ (0,
|
|
2521
|
-
/* @__PURE__ */ (0,
|
|
3565
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "flex items-center gap-1", children: [
|
|
3566
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("input", { type: "checkbox", checked: effect.playing !== false, "aria-label": "Play", onChange: (e) => {
|
|
2522
3567
|
const playing = e.currentTarget.checked;
|
|
2523
3568
|
run(() => controller.updateNodeEffect(nodeId, { playing }));
|
|
2524
3569
|
} }),
|
|
2525
3570
|
" Play"
|
|
2526
3571
|
] }),
|
|
2527
|
-
/* @__PURE__ */ (0,
|
|
3572
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: btn, "aria-label": "Remove effect", onClick: () => run(() => controller.removeNodeEffect(nodeId)), children: "\u2715" })
|
|
2528
3573
|
] }),
|
|
2529
|
-
provider && /* @__PURE__ */ (0,
|
|
3574
|
+
provider && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Controls, { controller, nodeId, effect })
|
|
2530
3575
|
] }),
|
|
2531
|
-
sceneId && transition && /* @__PURE__ */ (0,
|
|
2532
|
-
/* @__PURE__ */ (0,
|
|
3576
|
+
sceneId && transition && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center gap-1", "data-canvas-scene-transition": sceneId, children: [
|
|
3577
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [
|
|
2533
3578
|
"Into scene: ",
|
|
2534
3579
|
transition.name ?? transition.effect,
|
|
2535
3580
|
" (",
|
|
2536
3581
|
transition.duration ?? 600,
|
|
2537
3582
|
" ms)"
|
|
2538
3583
|
] }),
|
|
2539
|
-
/* @__PURE__ */ (0,
|
|
3584
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", className: btn, "aria-label": "Remove transition", onClick: () => run(() => controller.setSceneTransition(sceneId, null)), children: "\u2715" })
|
|
2540
3585
|
] }),
|
|
2541
|
-
message && /* @__PURE__ */ (0,
|
|
3586
|
+
message && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
2542
3587
|
] });
|
|
2543
3588
|
}
|
|
2544
3589
|
|
|
2545
3590
|
// src/canvas/ShapeNode.tsx
|
|
2546
|
-
var
|
|
3591
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2547
3592
|
function ShapeNode({ id, data, width, height, selected, className = "", children, positionAbsoluteX, positionAbsoluteY }) {
|
|
2548
3593
|
const shape = data?.shape;
|
|
2549
3594
|
const brushImage = useShapeBrushstroke((0, import_canvas15.isShapeDescription)(shape) ? shape : null, width, height, { x: positionAbsoluteX ?? 0, y: positionAbsoluteY ?? 0 });
|
|
2550
3595
|
if (!(0, import_canvas15.isShapeDescription)(shape)) return null;
|
|
2551
3596
|
const render = (0, import_canvas15.getShapeRenderData)(shape, { width, height }, { id: id || data?.id });
|
|
2552
|
-
return /* @__PURE__ */ (0,
|
|
3597
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2553
3598
|
"div",
|
|
2554
3599
|
{
|
|
2555
3600
|
className: `pixerate-shape-node ${className}`.trim(),
|
|
@@ -2557,7 +3602,7 @@ function ShapeNode({ id, data, width, height, selected, className = "", children
|
|
|
2557
3602
|
"data-selected": selected ? "true" : void 0,
|
|
2558
3603
|
style: { position: "relative", width: "100%", height: "100%" },
|
|
2559
3604
|
children: [
|
|
2560
|
-
/* @__PURE__ */ (0,
|
|
3605
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2561
3606
|
"svg",
|
|
2562
3607
|
{
|
|
2563
3608
|
viewBox: render.viewBox,
|
|
@@ -2567,13 +3612,13 @@ function ShapeNode({ id, data, width, height, selected, className = "", children
|
|
|
2567
3612
|
style: { display: "block", overflow: "visible" },
|
|
2568
3613
|
"aria-hidden": "true",
|
|
2569
3614
|
children: [
|
|
2570
|
-
(render.fillGradient || render.strokeGradient) && /* @__PURE__ */ (0,
|
|
2571
|
-
render.fillGradient && render.fillGradient.type === "linear" && /* @__PURE__ */ (0,
|
|
2572
|
-
render.fillGradient && render.fillGradient.type === "radial" && /* @__PURE__ */ (0,
|
|
2573
|
-
render.strokeGradient && render.strokeGradient.type === "linear" && /* @__PURE__ */ (0,
|
|
2574
|
-
render.strokeGradient && render.strokeGradient.type === "radial" && /* @__PURE__ */ (0,
|
|
3615
|
+
(render.fillGradient || render.strokeGradient) && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("defs", { children: [
|
|
3616
|
+
render.fillGradient && render.fillGradient.type === "linear" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("linearGradient", { id: render.fillGradient.id, ...render.fillGradient.attrs, children: render.fillGradient.stops.map((stop, i) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("stop", { offset: stop.offset, stopColor: stop.stopColor, stopOpacity: stop.stopOpacity }, i)) }),
|
|
3617
|
+
render.fillGradient && render.fillGradient.type === "radial" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("radialGradient", { id: render.fillGradient.id, ...render.fillGradient.attrs, children: render.fillGradient.stops.map((stop, i) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("stop", { offset: stop.offset, stopColor: stop.stopColor, stopOpacity: stop.stopOpacity }, i)) }),
|
|
3618
|
+
render.strokeGradient && render.strokeGradient.type === "linear" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("linearGradient", { id: render.strokeGradient.id, ...render.strokeGradient.attrs, children: render.strokeGradient.stops.map((stop, i) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("stop", { offset: stop.offset, stopColor: stop.stopColor, stopOpacity: stop.stopOpacity }, i)) }),
|
|
3619
|
+
render.strokeGradient && render.strokeGradient.type === "radial" && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("radialGradient", { id: render.strokeGradient.id, ...render.strokeGradient.attrs, children: render.strokeGradient.stops.map((stop, i) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("stop", { offset: stop.offset, stopColor: stop.stopColor, stopOpacity: stop.stopOpacity }, i)) })
|
|
2575
3620
|
] }),
|
|
2576
|
-
brushImage ? /* @__PURE__ */ (0,
|
|
3621
|
+
brushImage ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("g", { transform: render.transform, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2577
3622
|
"image",
|
|
2578
3623
|
{
|
|
2579
3624
|
className: "pixerate-shape-brushstroke",
|
|
@@ -2585,7 +3630,7 @@ function ShapeNode({ id, data, width, height, selected, className = "", children
|
|
|
2585
3630
|
preserveAspectRatio: "none",
|
|
2586
3631
|
opacity: render.opacity
|
|
2587
3632
|
}
|
|
2588
|
-
) }) : /* @__PURE__ */ (0,
|
|
3633
|
+
) }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2589
3634
|
"path",
|
|
2590
3635
|
{
|
|
2591
3636
|
d: render.d,
|
|
@@ -2603,7 +3648,7 @@ function ShapeNode({ id, data, width, height, selected, className = "", children
|
|
|
2603
3648
|
]
|
|
2604
3649
|
}
|
|
2605
3650
|
),
|
|
2606
|
-
shape.effect && width && height ? /* @__PURE__ */ (0,
|
|
3651
|
+
shape.effect && width && height ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CanvasNodeEffectLayer, { effect: shape.effect, width, height, clipPath: render.d, clipTransform: render.transform }) : null,
|
|
2607
3652
|
children
|
|
2608
3653
|
]
|
|
2609
3654
|
}
|
|
@@ -2617,15 +3662,15 @@ var import_canvas31 = require("@pixerate/editor/canvas");
|
|
|
2617
3662
|
var import_canvas32 = require("@pixerate/editor/canvas");
|
|
2618
3663
|
|
|
2619
3664
|
// src/canvas/useCanvasAutoLayout.ts
|
|
2620
|
-
var
|
|
3665
|
+
var import_react28 = require("react");
|
|
2621
3666
|
var import_canvas16 = require("@pixerate/editor/canvas");
|
|
2622
3667
|
function useCanvasAutoLayout(options) {
|
|
2623
|
-
const [guides, setGuides] = (0,
|
|
2624
|
-
const nodesRef = (0,
|
|
3668
|
+
const [guides, setGuides] = (0, import_react28.useState)([]);
|
|
3669
|
+
const nodesRef = (0, import_react28.useRef)(options.nodes);
|
|
2625
3670
|
nodesRef.current = options.nodes;
|
|
2626
|
-
const optionsRef = (0,
|
|
3671
|
+
const optionsRef = (0, import_react28.useRef)(options);
|
|
2627
3672
|
optionsRef.current = options;
|
|
2628
|
-
const controller = (0,
|
|
3673
|
+
const controller = (0, import_react28.useMemo)(
|
|
2629
3674
|
() => (0, import_canvas16.createCanvasAutoLayoutController)({
|
|
2630
3675
|
getNodes: () => nodesRef.current,
|
|
2631
3676
|
setNodes: (next) => {
|
|
@@ -2651,10 +3696,10 @@ function useCanvasAutoLayout(options) {
|
|
|
2651
3696
|
}),
|
|
2652
3697
|
[]
|
|
2653
3698
|
);
|
|
2654
|
-
(0,
|
|
3699
|
+
(0, import_react28.useLayoutEffect)(() => {
|
|
2655
3700
|
if (controller.hasPending) controller.flush();
|
|
2656
3701
|
}, [options.nodes, controller]);
|
|
2657
|
-
return (0,
|
|
3702
|
+
return (0, import_react28.useMemo)(
|
|
2658
3703
|
() => ({
|
|
2659
3704
|
...controller,
|
|
2660
3705
|
/** Drop marker of the active reorder drag (flow coordinates). */
|
|
@@ -2668,15 +3713,15 @@ function useCanvasAutoLayout(options) {
|
|
|
2668
3713
|
}
|
|
2669
3714
|
|
|
2670
3715
|
// src/canvas/useCanvasTokens.ts
|
|
2671
|
-
var
|
|
3716
|
+
var import_react29 = require("react");
|
|
2672
3717
|
var import_canvas17 = require("@pixerate/editor/canvas");
|
|
2673
3718
|
function useCanvasTokens(options) {
|
|
2674
3719
|
const { store, nodes, setNodes, modes, properties } = options;
|
|
2675
|
-
const state = (0,
|
|
2676
|
-
const latest = (0,
|
|
3720
|
+
const state = (0, import_react29.useSyncExternalStore)(store.subscribe, store.getState, store.getState);
|
|
3721
|
+
const latest = (0, import_react29.useRef)({ nodes, setNodes, modes, properties });
|
|
2677
3722
|
latest.current = { nodes, setNodes, modes, properties };
|
|
2678
3723
|
const opts = () => ({ modes: latest.current.modes, properties: latest.current.properties });
|
|
2679
|
-
(0,
|
|
3724
|
+
(0, import_react29.useEffect)(
|
|
2680
3725
|
() => store.subscribe((event) => {
|
|
2681
3726
|
if (event.deletedVariableIds.length === 0) return;
|
|
2682
3727
|
latest.current.setNodes((prev) => (0, import_canvas17.detachTokenBindings)(prev, event.previous, event.deletedVariableIds, opts()));
|
|
@@ -2685,11 +3730,11 @@ function useCanvasTokens(options) {
|
|
|
2685
3730
|
[store]
|
|
2686
3731
|
);
|
|
2687
3732
|
const modesKey = JSON.stringify(modes ?? {});
|
|
2688
|
-
(0,
|
|
3733
|
+
(0, import_react29.useEffect)(() => {
|
|
2689
3734
|
const next = (0, import_canvas17.resolveCanvasTokens)(nodes, state, opts());
|
|
2690
3735
|
if (next !== nodes) setNodes(next);
|
|
2691
3736
|
}, [nodes, state, modesKey, properties]);
|
|
2692
|
-
const bind = (0,
|
|
3737
|
+
const bind = (0, import_react29.useCallback)(
|
|
2693
3738
|
(ids, propertyKey, variableId) => {
|
|
2694
3739
|
const next = (0, import_canvas17.bindCanvasToken)(latest.current.nodes, ids, propertyKey, variableId, store.getState(), opts());
|
|
2695
3740
|
if (next !== latest.current.nodes) latest.current.setNodes(next);
|
|
@@ -2697,7 +3742,7 @@ function useCanvasTokens(options) {
|
|
|
2697
3742
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2698
3743
|
[store]
|
|
2699
3744
|
);
|
|
2700
|
-
const setMode = (0,
|
|
3745
|
+
const setMode = (0, import_react29.useCallback)(
|
|
2701
3746
|
(ids, collectionId, modeId) => {
|
|
2702
3747
|
const next = (0, import_canvas17.setCanvasTokenMode)(latest.current.nodes, ids, collectionId, modeId, store.getState(), opts());
|
|
2703
3748
|
if (next !== latest.current.nodes) latest.current.setNodes(next);
|
|
@@ -2705,7 +3750,7 @@ function useCanvasTokens(options) {
|
|
|
2705
3750
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2706
3751
|
[store]
|
|
2707
3752
|
);
|
|
2708
|
-
const modesOf = (0,
|
|
3753
|
+
const modesOf = (0, import_react29.useCallback)(
|
|
2709
3754
|
(nodeId) => {
|
|
2710
3755
|
const node = latest.current.nodes.find((n) => n.id === nodeId);
|
|
2711
3756
|
return node ? (0, import_canvas17.getEffectiveTokenModes)(node, latest.current.nodes, store.getState(), opts()) : {};
|
|
@@ -2719,7 +3764,7 @@ function useCanvasTokens(options) {
|
|
|
2719
3764
|
// src/canvas/TokenBindingPicker.tsx
|
|
2720
3765
|
var import_canvas18 = require("@pixerate/editor/canvas");
|
|
2721
3766
|
var import_tokens = require("@pixerate/editor/tokens");
|
|
2722
|
-
var
|
|
3767
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2723
3768
|
function TokenBindingPicker({
|
|
2724
3769
|
state,
|
|
2725
3770
|
nodes,
|
|
@@ -2736,15 +3781,15 @@ function TokenBindingPicker({
|
|
|
2736
3781
|
let rows = (0, import_canvas18.getBindableTokenProperties)(first, options);
|
|
2737
3782
|
if (properties) rows = properties.map((key) => rows.find((p) => p.key === key)).filter((p) => !!p);
|
|
2738
3783
|
const modes = (0, import_canvas18.getEffectiveTokenModes)(first, nodes, state, options);
|
|
2739
|
-
return /* @__PURE__ */ (0,
|
|
3784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { "data-token-binding-picker": "", className: `flex flex-col gap-1 text-xs text-foreground ${className}`, children: [
|
|
2740
3785
|
rows.map((property) => {
|
|
2741
3786
|
const ids = new Set(selected.map((n) => (0, import_canvas18.getNodeTokenBindings)(n)[property.key] ?? ""));
|
|
2742
3787
|
const value = ids.size === 1 ? [...ids][0] : "__mixed";
|
|
2743
3788
|
const candidates = (0, import_canvas18.getTokensForProperty)(state, property, first);
|
|
2744
3789
|
const resolved = value && value !== "__mixed" ? (0, import_tokens.resolveToken)(state, value, modes) : null;
|
|
2745
|
-
return /* @__PURE__ */ (0,
|
|
2746
|
-
/* @__PURE__ */ (0,
|
|
2747
|
-
/* @__PURE__ */ (0,
|
|
3790
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "flex items-center gap-2", "data-token-property": property.key, children: [
|
|
3791
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "w-28 shrink-0 text-muted-foreground", children: property.label }),
|
|
3792
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
2748
3793
|
"select",
|
|
2749
3794
|
{
|
|
2750
3795
|
"aria-label": `${property.label} variable`,
|
|
@@ -2759,11 +3804,11 @@ function TokenBindingPicker({
|
|
|
2759
3804
|
}
|
|
2760
3805
|
},
|
|
2761
3806
|
children: [
|
|
2762
|
-
value === "__mixed" ? /* @__PURE__ */ (0,
|
|
2763
|
-
/* @__PURE__ */ (0,
|
|
3807
|
+
value === "__mixed" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "__mixed", children: "Mixed" }) : null,
|
|
3808
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "", children: "None" }),
|
|
2764
3809
|
candidates.map((v) => {
|
|
2765
3810
|
const collection = state.collections.find((c) => c.id === v.collectionId);
|
|
2766
|
-
return /* @__PURE__ */ (0,
|
|
3811
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("option", { value: v.id, children: [
|
|
2767
3812
|
v.name,
|
|
2768
3813
|
collection && state.collections.length > 1 ? ` (${collection.name})` : ""
|
|
2769
3814
|
] }, v.id);
|
|
@@ -2771,17 +3816,17 @@ function TokenBindingPicker({
|
|
|
2771
3816
|
]
|
|
2772
3817
|
}
|
|
2773
3818
|
),
|
|
2774
|
-
/* @__PURE__ */ (0,
|
|
3819
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "w-16 shrink-0 truncate text-right text-muted-foreground", "data-token-resolved": "", children: resolved?.ok ? property.type === "color" ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
2775
3820
|
"span",
|
|
2776
3821
|
{
|
|
2777
3822
|
className: "inline-block h-3 w-3 rounded border border-border align-middle",
|
|
2778
3823
|
style: { background: String(resolved.value) },
|
|
2779
3824
|
title: String(resolved.value)
|
|
2780
3825
|
}
|
|
2781
|
-
) : String(resolved.value) : resolved ? /* @__PURE__ */ (0,
|
|
3826
|
+
) : String(resolved.value) : resolved ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { title: resolved.message, children: "\u26A0" }) : null })
|
|
2782
3827
|
] }, property.key);
|
|
2783
3828
|
}),
|
|
2784
|
-
state.collections.length === 0 ? /* @__PURE__ */ (0,
|
|
3829
|
+
state.collections.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "text-muted-foreground", children: "No variables yet." }) : null
|
|
2785
3830
|
] });
|
|
2786
3831
|
}
|
|
2787
3832
|
function TokenModeSwitcher({
|
|
@@ -2799,12 +3844,12 @@ function TokenModeSwitcher({
|
|
|
2799
3844
|
const parent = first.parentId ? nodes.find((n) => n.id === first.parentId) : void 0;
|
|
2800
3845
|
const inherited = parent ? (0, import_canvas18.getEffectiveTokenModes)(parent, nodes, state, options) : { ...options.modes };
|
|
2801
3846
|
const collections = state.collections.filter((c) => showSingleMode || c.modes.length > 1);
|
|
2802
|
-
return /* @__PURE__ */ (0,
|
|
3847
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { "data-token-mode-switcher": "", className: `flex flex-col gap-1 text-xs text-foreground ${className}`, children: collections.map((collection) => {
|
|
2803
3848
|
const auto = (0, import_tokens.getCurrentMode)(collection, inherited);
|
|
2804
3849
|
const explicit = collection.modes.some((m) => m.id === own[collection.id]) ? own[collection.id] : "";
|
|
2805
|
-
return /* @__PURE__ */ (0,
|
|
2806
|
-
/* @__PURE__ */ (0,
|
|
2807
|
-
/* @__PURE__ */ (0,
|
|
3850
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: "flex items-center gap-2", "data-token-collection": collection.id, children: [
|
|
3851
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "w-28 shrink-0 truncate text-muted-foreground", children: collection.name }),
|
|
3852
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
2808
3853
|
"select",
|
|
2809
3854
|
{
|
|
2810
3855
|
"aria-label": `${collection.name} mode`,
|
|
@@ -2812,12 +3857,12 @@ function TokenModeSwitcher({
|
|
|
2812
3857
|
value: explicit,
|
|
2813
3858
|
onChange: (e) => onChange((0, import_canvas18.setCanvasTokenMode)(nodes, nodeIds, collection.id, e.currentTarget.value || null, state, options)),
|
|
2814
3859
|
children: [
|
|
2815
|
-
/* @__PURE__ */ (0,
|
|
3860
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("option", { value: "", children: [
|
|
2816
3861
|
"Auto (",
|
|
2817
3862
|
auto.name,
|
|
2818
3863
|
")"
|
|
2819
3864
|
] }),
|
|
2820
|
-
collection.modes.map((m) => /* @__PURE__ */ (0,
|
|
3865
|
+
collection.modes.map((m) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: m.id, children: m.name }, m.id))
|
|
2821
3866
|
]
|
|
2822
3867
|
}
|
|
2823
3868
|
)
|
|
@@ -2829,14 +3874,14 @@ function TokenModeSwitcher({
|
|
|
2829
3874
|
var import_canvas33 = require("@pixerate/editor/canvas");
|
|
2830
3875
|
|
|
2831
3876
|
// src/canvas/useCanvasAnimation.ts
|
|
2832
|
-
var
|
|
3877
|
+
var import_react30 = require("react");
|
|
2833
3878
|
var import_canvas19 = require("@pixerate/editor/canvas");
|
|
2834
3879
|
function useCanvasAnimation(options) {
|
|
2835
|
-
const nodesRef = (0,
|
|
3880
|
+
const nodesRef = (0, import_react30.useRef)(options.nodes);
|
|
2836
3881
|
nodesRef.current = options.nodes;
|
|
2837
|
-
const optionsRef = (0,
|
|
3882
|
+
const optionsRef = (0, import_react30.useRef)(options);
|
|
2838
3883
|
optionsRef.current = options;
|
|
2839
|
-
const controller = (0,
|
|
3884
|
+
const controller = (0, import_react30.useMemo)(
|
|
2840
3885
|
() => (0, import_canvas19.createCanvasAnimationController)({
|
|
2841
3886
|
getNodes: () => nodesRef.current,
|
|
2842
3887
|
setNodes: (next) => {
|
|
@@ -2863,26 +3908,26 @@ function useCanvasAnimation(options) {
|
|
|
2863
3908
|
}),
|
|
2864
3909
|
[]
|
|
2865
3910
|
);
|
|
2866
|
-
(0,
|
|
2867
|
-
(0,
|
|
3911
|
+
(0, import_react30.useEffect)(() => () => controller.destroy(), [controller]);
|
|
3912
|
+
(0, import_react30.useEffect)(() => {
|
|
2868
3913
|
if (options.loop !== void 0) controller.setLoop(options.loop);
|
|
2869
3914
|
}, [controller, options.loop]);
|
|
2870
|
-
(0,
|
|
3915
|
+
(0, import_react30.useEffect)(() => {
|
|
2871
3916
|
if (options.playbackRate !== void 0) controller.setPlaybackRate(options.playbackRate);
|
|
2872
3917
|
}, [controller, options.playbackRate]);
|
|
2873
|
-
(0,
|
|
3918
|
+
(0, import_react30.useEffect)(() => {
|
|
2874
3919
|
if (options.recording !== void 0) controller.setRecording(options.recording);
|
|
2875
3920
|
}, [controller, options.recording]);
|
|
2876
|
-
const state = (0,
|
|
3921
|
+
const state = (0, import_react30.useSyncExternalStore)(
|
|
2877
3922
|
(listener) => controller.subscribe(listener),
|
|
2878
3923
|
() => controller.getState(),
|
|
2879
3924
|
() => controller.getState()
|
|
2880
3925
|
);
|
|
2881
|
-
(0,
|
|
3926
|
+
(0, import_react30.useEffect)(() => {
|
|
2882
3927
|
controller.refresh();
|
|
2883
3928
|
}, [controller, options.nodes]);
|
|
2884
|
-
const displayNodes = (0,
|
|
2885
|
-
return (0,
|
|
3929
|
+
const displayNodes = (0, import_react30.useMemo)(() => controller.display(options.nodes), [controller, options.nodes, state.time]);
|
|
3930
|
+
return (0, import_react30.useMemo)(
|
|
2886
3931
|
() => ({
|
|
2887
3932
|
...controller,
|
|
2888
3933
|
state,
|
|
@@ -2903,9 +3948,9 @@ function useCanvasAnimation(options) {
|
|
|
2903
3948
|
}
|
|
2904
3949
|
|
|
2905
3950
|
// src/canvas/AnimationTimeline.tsx
|
|
2906
|
-
var
|
|
3951
|
+
var import_react31 = require("react");
|
|
2907
3952
|
var import_canvas20 = require("@pixerate/editor/canvas");
|
|
2908
|
-
var
|
|
3953
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2909
3954
|
var LOOP_LABELS = { none: "Once", loop: "Loop", "ping-pong": "Ping-pong" };
|
|
2910
3955
|
var easingValue = (easing) => typeof easing === "string" ? easing : easing ? "custom" : "linear";
|
|
2911
3956
|
function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8, labelOf, className = "" }) {
|
|
@@ -2919,8 +3964,8 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
2919
3964
|
for (const row of rows) for (const k of row.keyframes) if (k.selected && k.ref.property === first.property && k.ref.nodeId === first.nodeId) return easingValue(k.easing);
|
|
2920
3965
|
return "";
|
|
2921
3966
|
})();
|
|
2922
|
-
const dragRef = (0,
|
|
2923
|
-
(0,
|
|
3967
|
+
const dragRef = (0, import_react31.useRef)(null);
|
|
3968
|
+
(0, import_react31.useEffect)(() => {
|
|
2924
3969
|
const onKey = (event) => {
|
|
2925
3970
|
if (event.key === "Escape" && dragRef.current) {
|
|
2926
3971
|
dragRef.current = null;
|
|
@@ -2976,10 +4021,10 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
2976
4021
|
const btn2 = "rounded border border-border px-2 py-0.5 text-xs hover:bg-muted disabled:opacity-50";
|
|
2977
4022
|
const playheadX = (0, import_canvas20.timeToX)(state.time, duration, width);
|
|
2978
4023
|
const labelWidth = 120;
|
|
2979
|
-
return /* @__PURE__ */ (0,
|
|
2980
|
-
/* @__PURE__ */ (0,
|
|
2981
|
-
/* @__PURE__ */ (0,
|
|
2982
|
-
/* @__PURE__ */ (0,
|
|
4024
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { "data-animation-timeline": "", className: `flex flex-col gap-1 text-xs text-foreground ${className}`, tabIndex: 0, onKeyDown: onTimelineKey, children: [
|
|
4025
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex flex-wrap items-center gap-2", role: "toolbar", "aria-label": "Animation", children: [
|
|
4026
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", className: btn2, "data-action": "toggle-play", "aria-label": state.playing ? "Pause" : "Play", onClick: () => animation.toggle(), children: state.playing ? "\u275A\u275A" : "\u25B6" }),
|
|
4027
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
2983
4028
|
"button",
|
|
2984
4029
|
{
|
|
2985
4030
|
type: "button",
|
|
@@ -2991,13 +4036,13 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
2991
4036
|
children: "\u25CF Rec"
|
|
2992
4037
|
}
|
|
2993
4038
|
),
|
|
2994
|
-
/* @__PURE__ */ (0,
|
|
2995
|
-
/* @__PURE__ */ (0,
|
|
4039
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", className: btn2, "data-action": "add-keyframe", onClick: () => animation.addKeyframe(), children: "\u25C6 Key" }),
|
|
4040
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { "data-time": "", className: "tabular-nums text-muted-foreground", children: [
|
|
2996
4041
|
(0, import_canvas20.formatAnimationTime)(state.time),
|
|
2997
4042
|
" / ",
|
|
2998
4043
|
(0, import_canvas20.formatAnimationTime)(duration)
|
|
2999
4044
|
] }),
|
|
3000
|
-
/* @__PURE__ */ (0,
|
|
4045
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
3001
4046
|
"select",
|
|
3002
4047
|
{
|
|
3003
4048
|
"aria-label": "Easing",
|
|
@@ -3007,13 +4052,13 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
3007
4052
|
disabled: state.selection.length === 0,
|
|
3008
4053
|
onChange: (e) => e.target.value && e.target.value !== "custom" && animation.setEasing(e.target.value),
|
|
3009
4054
|
children: [
|
|
3010
|
-
/* @__PURE__ */ (0,
|
|
3011
|
-
import_canvas20.ANIMATION_EASING_PRESETS.map((preset) => /* @__PURE__ */ (0,
|
|
3012
|
-
selectedEasing === "custom" ? /* @__PURE__ */ (0,
|
|
4055
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("option", { value: "", children: "Easing\u2026" }),
|
|
4056
|
+
import_canvas20.ANIMATION_EASING_PRESETS.map((preset) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("option", { value: preset, children: import_canvas20.ANIMATION_EASING_LABELS[preset] }, preset)),
|
|
4057
|
+
selectedEasing === "custom" ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("option", { value: "custom", children: "Custom" }) : null
|
|
3013
4058
|
]
|
|
3014
4059
|
}
|
|
3015
4060
|
),
|
|
3016
|
-
/* @__PURE__ */ (0,
|
|
4061
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3017
4062
|
"select",
|
|
3018
4063
|
{
|
|
3019
4064
|
"aria-label": "Loop",
|
|
@@ -3021,13 +4066,13 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
3021
4066
|
className: "rounded border border-border bg-background px-1 py-0.5",
|
|
3022
4067
|
value: state.loop,
|
|
3023
4068
|
onChange: (e) => animation.setLoop(e.target.value),
|
|
3024
|
-
children: Object.keys(LOOP_LABELS).map((mode) => /* @__PURE__ */ (0,
|
|
4069
|
+
children: Object.keys(LOOP_LABELS).map((mode) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("option", { value: mode, children: LOOP_LABELS[mode] }, mode))
|
|
3025
4070
|
}
|
|
3026
4071
|
)
|
|
3027
4072
|
] }),
|
|
3028
|
-
/* @__PURE__ */ (0,
|
|
3029
|
-
/* @__PURE__ */ (0,
|
|
3030
|
-
/* @__PURE__ */ (0,
|
|
4073
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex", children: [
|
|
4074
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { style: { width: labelWidth }, className: "shrink-0" }),
|
|
4075
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
3031
4076
|
"div",
|
|
3032
4077
|
{
|
|
3033
4078
|
"data-timeline-ruler": "",
|
|
@@ -3035,15 +4080,15 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
3035
4080
|
style: { width },
|
|
3036
4081
|
onPointerDown: onRulerDown,
|
|
3037
4082
|
children: [
|
|
3038
|
-
ticks.map((tick) => /* @__PURE__ */ (0,
|
|
3039
|
-
/* @__PURE__ */ (0,
|
|
4083
|
+
ticks.map((tick) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "absolute top-0 -translate-x-1/2 text-[10px] text-muted-foreground", style: { left: tick.x }, children: tick.label }, tick.time)),
|
|
4084
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { "data-playhead": "", className: "absolute top-0 h-5 w-px bg-red-500", style: { left: playheadX } })
|
|
3040
4085
|
]
|
|
3041
4086
|
}
|
|
3042
4087
|
)
|
|
3043
4088
|
] }),
|
|
3044
|
-
rows.length === 0 ? /* @__PURE__ */ (0,
|
|
3045
|
-
/* @__PURE__ */ (0,
|
|
3046
|
-
/* @__PURE__ */ (0,
|
|
4089
|
+
rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("p", { className: "text-muted-foreground", "data-timeline-empty": "", children: "Select an animated node, or press \u25C6 Key to add a keyframe." }) : rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex items-center", "data-track": row.id, children: [
|
|
4090
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("label", { className: "flex shrink-0 items-center gap-1 truncate pr-2", style: { width: labelWidth }, title: `${row.nodeLabel} \xB7 ${row.label}`, children: [
|
|
4091
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3047
4092
|
"input",
|
|
3048
4093
|
{
|
|
3049
4094
|
type: "checkbox",
|
|
@@ -3052,15 +4097,15 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
3052
4097
|
onChange: (e) => animation.setTrackEnabled(row.nodeId, row.property, e.target.checked)
|
|
3053
4098
|
}
|
|
3054
4099
|
),
|
|
3055
|
-
/* @__PURE__ */ (0,
|
|
4100
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "truncate", children: [
|
|
3056
4101
|
rows.filter((r) => r.nodeId === row.nodeId).length < rows.length ? `${row.nodeLabel} \xB7 ` : "",
|
|
3057
4102
|
row.label
|
|
3058
4103
|
] })
|
|
3059
4104
|
] }),
|
|
3060
|
-
/* @__PURE__ */ (0,
|
|
3061
|
-
/* @__PURE__ */ (0,
|
|
3062
|
-
state.drag?.target != null ? /* @__PURE__ */ (0,
|
|
3063
|
-
row.keyframes.map((k) => /* @__PURE__ */ (0,
|
|
4105
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { "data-lane": "", className: `relative h-5 rounded bg-muted/40 ${row.enabled ? "" : "opacity-50"}`, style: { width }, children: [
|
|
4106
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "pointer-events-none absolute top-0 h-5 w-px bg-red-500/60", style: { left: playheadX } }),
|
|
4107
|
+
state.drag?.target != null ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { "data-snap-target": "", className: "pointer-events-none absolute top-0 h-5 w-px bg-sky-400", style: { left: (0, import_canvas20.timeToX)(state.drag.target, duration, width) } }) : null,
|
|
4108
|
+
row.keyframes.map((k) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3064
4109
|
"button",
|
|
3065
4110
|
{
|
|
3066
4111
|
type: "button",
|
|
@@ -3083,14 +4128,14 @@ function AnimationTimeline({ animation, nodeIds, width = 360, snapThreshold = 8,
|
|
|
3083
4128
|
var import_canvas34 = require("@pixerate/editor/canvas");
|
|
3084
4129
|
|
|
3085
4130
|
// src/canvas/useCanvasComponents.ts
|
|
3086
|
-
var
|
|
4131
|
+
var import_react32 = require("react");
|
|
3087
4132
|
var import_canvas21 = require("@pixerate/editor/canvas");
|
|
3088
4133
|
function useCanvasComponents(options) {
|
|
3089
|
-
const nodesRef = (0,
|
|
4134
|
+
const nodesRef = (0, import_react32.useRef)(options.nodes);
|
|
3090
4135
|
nodesRef.current = options.nodes;
|
|
3091
|
-
const optionsRef = (0,
|
|
4136
|
+
const optionsRef = (0, import_react32.useRef)(options);
|
|
3092
4137
|
optionsRef.current = options;
|
|
3093
|
-
const controller = (0,
|
|
4138
|
+
const controller = (0, import_react32.useMemo)(
|
|
3094
4139
|
() => (0, import_canvas21.createCanvasComponentsController)({
|
|
3095
4140
|
getNodes: () => nodesRef.current,
|
|
3096
4141
|
setNodes: (next) => {
|
|
@@ -3119,18 +4164,18 @@ function useCanvasComponents(options) {
|
|
|
3119
4164
|
}),
|
|
3120
4165
|
[]
|
|
3121
4166
|
);
|
|
3122
|
-
(0,
|
|
4167
|
+
(0, import_react32.useLayoutEffect)(() => {
|
|
3123
4168
|
if (optionsRef.current.autoSync !== false) controller.sync();
|
|
3124
4169
|
}, [options.nodes, controller]);
|
|
3125
4170
|
return controller;
|
|
3126
4171
|
}
|
|
3127
4172
|
|
|
3128
4173
|
// src/canvas/CanvasComponentsPanel.tsx
|
|
3129
|
-
var
|
|
4174
|
+
var import_react33 = require("react");
|
|
3130
4175
|
var import_canvas22 = require("@pixerate/editor/canvas");
|
|
3131
|
-
var
|
|
4176
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
3132
4177
|
function InlineField({ value, label, onCommit }) {
|
|
3133
|
-
return /* @__PURE__ */ (0,
|
|
4178
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3134
4179
|
"input",
|
|
3135
4180
|
{
|
|
3136
4181
|
type: "text",
|
|
@@ -3161,10 +4206,10 @@ function CanvasComponentsPanel({
|
|
|
3161
4206
|
search = true,
|
|
3162
4207
|
className = ""
|
|
3163
4208
|
}) {
|
|
3164
|
-
const [query, setQuery] = (0,
|
|
3165
|
-
const [propsOpen, setPropsOpen] = (0,
|
|
3166
|
-
const [menuFor, setMenuFor] = (0,
|
|
3167
|
-
const [editing, setEditing] = (0,
|
|
4209
|
+
const [query, setQuery] = (0, import_react33.useState)("");
|
|
4210
|
+
const [propsOpen, setPropsOpen] = (0, import_react33.useState)(null);
|
|
4211
|
+
const [menuFor, setMenuFor] = (0, import_react33.useState)(null);
|
|
4212
|
+
const [editing, setEditing] = (0, import_react33.useState)(null);
|
|
3168
4213
|
const { components: all, sets } = (0, import_canvas22.listCanvasComponents)(nodes);
|
|
3169
4214
|
const q = query.trim().toLowerCase();
|
|
3170
4215
|
const match = (name) => !q || name.toLowerCase().includes(q);
|
|
@@ -3176,7 +4221,7 @@ function CanvasComponentsPanel({
|
|
|
3176
4221
|
};
|
|
3177
4222
|
const small = "shrink-0 rounded px-1 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-40";
|
|
3178
4223
|
const menuItem = "rounded px-2 py-0.5 text-left hover:bg-muted disabled:opacity-40";
|
|
3179
|
-
const item = (id, name, count, extra = {}, onContextMenu) => /* @__PURE__ */ (0,
|
|
4224
|
+
const item = (id, name, count, extra = {}, onContextMenu) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
3180
4225
|
"button",
|
|
3181
4226
|
{
|
|
3182
4227
|
type: "button",
|
|
@@ -3193,17 +4238,17 @@ function CanvasComponentsPanel({
|
|
|
3193
4238
|
e.dataTransfer.effectAllowed = "copy";
|
|
3194
4239
|
},
|
|
3195
4240
|
children: [
|
|
3196
|
-
/* @__PURE__ */ (0,
|
|
3197
|
-
/* @__PURE__ */ (0,
|
|
4241
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "truncate", children: [
|
|
4242
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { "aria-hidden": true, className: "mr-1 text-muted-foreground", children: "\u25C7" }),
|
|
3198
4243
|
name
|
|
3199
4244
|
] }),
|
|
3200
|
-
/* @__PURE__ */ (0,
|
|
4245
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "text-[10px] text-muted-foreground", "data-instance-count": "", children: count })
|
|
3201
4246
|
]
|
|
3202
4247
|
},
|
|
3203
4248
|
id
|
|
3204
4249
|
);
|
|
3205
|
-
return /* @__PURE__ */ (0,
|
|
3206
|
-
search ? /* @__PURE__ */ (0,
|
|
4250
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { "data-components-panel": "", className: `flex flex-col gap-1 text-xs text-foreground ${className}`, children: [
|
|
4251
|
+
search ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3207
4252
|
"input",
|
|
3208
4253
|
{
|
|
3209
4254
|
type: "search",
|
|
@@ -3213,11 +4258,11 @@ function CanvasComponentsPanel({
|
|
|
3213
4258
|
onInput: (e) => setQuery(e.target.value)
|
|
3214
4259
|
}
|
|
3215
4260
|
) : null,
|
|
3216
|
-
shownSets.map((set) => /* @__PURE__ */ (0,
|
|
3217
|
-
/* @__PURE__ */ (0,
|
|
4261
|
+
shownSets.map((set) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { "data-component-set": set.id, className: "flex flex-col", children: [
|
|
4262
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3218
4263
|
item(set.id, set.name, set.variants.reduce((sum, v) => sum + v.instanceCount, 0), { "data-kind": "set" }),
|
|
3219
|
-
components ? /* @__PURE__ */ (0,
|
|
3220
|
-
/* @__PURE__ */ (0,
|
|
4264
|
+
components ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
4265
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3221
4266
|
"button",
|
|
3222
4267
|
{
|
|
3223
4268
|
type: "button",
|
|
@@ -3229,7 +4274,7 @@ function CanvasComponentsPanel({
|
|
|
3229
4274
|
children: "+\xA0Variant"
|
|
3230
4275
|
}
|
|
3231
4276
|
),
|
|
3232
|
-
/* @__PURE__ */ (0,
|
|
4277
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3233
4278
|
"button",
|
|
3234
4279
|
{
|
|
3235
4280
|
type: "button",
|
|
@@ -3244,8 +4289,8 @@ function CanvasComponentsPanel({
|
|
|
3244
4289
|
)
|
|
3245
4290
|
] }) : null
|
|
3246
4291
|
] }),
|
|
3247
|
-
components && propsOpen === set.id ? /* @__PURE__ */ (0,
|
|
3248
|
-
/* @__PURE__ */ (0,
|
|
4292
|
+
components && propsOpen === set.id ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { "data-variant-properties": set.id, className: "ml-3 flex flex-col gap-1 border-l border-border py-1 pl-2", children: set.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { "data-variant-option": option.name, className: "flex flex-col gap-0.5", children: [
|
|
4293
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3249
4294
|
InlineField,
|
|
3250
4295
|
{
|
|
3251
4296
|
value: option.name,
|
|
@@ -3253,7 +4298,7 @@ function CanvasComponentsPanel({
|
|
|
3253
4298
|
onCommit: (next) => report(components.renameVariantProperty(option.name, next, set.id))
|
|
3254
4299
|
}
|
|
3255
4300
|
),
|
|
3256
|
-
/* @__PURE__ */ (0,
|
|
4301
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "ml-2 flex flex-wrap gap-1", children: option.values.map((value) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3257
4302
|
InlineField,
|
|
3258
4303
|
{
|
|
3259
4304
|
value,
|
|
@@ -3263,8 +4308,8 @@ function CanvasComponentsPanel({
|
|
|
3263
4308
|
value
|
|
3264
4309
|
)) })
|
|
3265
4310
|
] }, option.name)) }) : null,
|
|
3266
|
-
/* @__PURE__ */ (0,
|
|
3267
|
-
/* @__PURE__ */ (0,
|
|
4311
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "ml-3 flex flex-col border-l border-border pl-1", children: set.variants.map((v) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { "data-variant-row": v.id, className: "flex flex-col", children: [
|
|
4312
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
3268
4313
|
item(
|
|
3269
4314
|
v.id,
|
|
3270
4315
|
v.name,
|
|
@@ -3275,7 +4320,7 @@ function CanvasComponentsPanel({
|
|
|
3275
4320
|
setMenuFor(v.id);
|
|
3276
4321
|
} : void 0
|
|
3277
4322
|
),
|
|
3278
|
-
components ? /* @__PURE__ */ (0,
|
|
4323
|
+
components ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3279
4324
|
"button",
|
|
3280
4325
|
{
|
|
3281
4326
|
type: "button",
|
|
@@ -3289,8 +4334,8 @@ function CanvasComponentsPanel({
|
|
|
3289
4334
|
}
|
|
3290
4335
|
) : null
|
|
3291
4336
|
] }),
|
|
3292
|
-
components && menuFor === v.id ? /* @__PURE__ */ (0,
|
|
3293
|
-
/* @__PURE__ */ (0,
|
|
4337
|
+
components && menuFor === v.id ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { role: "menu", "data-variant-menu": v.id, className: "ml-2 flex flex-col rounded border border-border bg-background p-1 shadow", children: [
|
|
4338
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3294
4339
|
"button",
|
|
3295
4340
|
{
|
|
3296
4341
|
type: "button",
|
|
@@ -3304,7 +4349,7 @@ function CanvasComponentsPanel({
|
|
|
3304
4349
|
children: "Edit values\u2026"
|
|
3305
4350
|
}
|
|
3306
4351
|
),
|
|
3307
|
-
/* @__PURE__ */ (0,
|
|
4352
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3308
4353
|
"button",
|
|
3309
4354
|
{
|
|
3310
4355
|
type: "button",
|
|
@@ -3318,7 +4363,7 @@ function CanvasComponentsPanel({
|
|
|
3318
4363
|
children: "Duplicate"
|
|
3319
4364
|
}
|
|
3320
4365
|
),
|
|
3321
|
-
/* @__PURE__ */ (0,
|
|
4366
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3322
4367
|
"button",
|
|
3323
4368
|
{
|
|
3324
4369
|
type: "button",
|
|
@@ -3335,7 +4380,7 @@ function CanvasComponentsPanel({
|
|
|
3335
4380
|
}
|
|
3336
4381
|
)
|
|
3337
4382
|
] }) : null,
|
|
3338
|
-
components && editing === v.id ? /* @__PURE__ */ (0,
|
|
4383
|
+
components && editing === v.id ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
3339
4384
|
"form",
|
|
3340
4385
|
{
|
|
3341
4386
|
"data-variant-editor": v.id,
|
|
@@ -3349,9 +4394,9 @@ function CanvasComponentsPanel({
|
|
|
3349
4394
|
if (report(components.setVariantProperties(values, v.id))) setEditing(null);
|
|
3350
4395
|
},
|
|
3351
4396
|
children: [
|
|
3352
|
-
set.options.map((option) => /* @__PURE__ */ (0,
|
|
3353
|
-
/* @__PURE__ */ (0,
|
|
3354
|
-
/* @__PURE__ */ (0,
|
|
4397
|
+
set.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "flex items-center gap-2", children: [
|
|
4398
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "w-16 shrink-0 truncate text-muted-foreground", children: option.name }),
|
|
4399
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3355
4400
|
"input",
|
|
3356
4401
|
{
|
|
3357
4402
|
type: "text",
|
|
@@ -3362,9 +4407,9 @@ function CanvasComponentsPanel({
|
|
|
3362
4407
|
}
|
|
3363
4408
|
)
|
|
3364
4409
|
] }, option.name)),
|
|
3365
|
-
/* @__PURE__ */ (0,
|
|
3366
|
-
/* @__PURE__ */ (0,
|
|
3367
|
-
/* @__PURE__ */ (0,
|
|
4410
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex gap-1", children: [
|
|
4411
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "submit", className: "rounded border border-border px-2 py-0.5 hover:bg-muted", "data-action": "save-variant", children: "Save" }),
|
|
4412
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: "rounded px-2 py-0.5 hover:bg-muted", "data-action": "cancel-variant", onClick: () => setEditing(null), children: "Cancel" })
|
|
3368
4413
|
] })
|
|
3369
4414
|
]
|
|
3370
4415
|
}
|
|
@@ -3372,7 +4417,7 @@ function CanvasComponentsPanel({
|
|
|
3372
4417
|
] }, v.id)) })
|
|
3373
4418
|
] }, set.id)),
|
|
3374
4419
|
lone.map((c) => item(c.id, c.name, c.instanceCount, { "data-kind": "component" })),
|
|
3375
|
-
all.length === 0 ? /* @__PURE__ */ (0,
|
|
4420
|
+
all.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("p", { className: "text-muted-foreground", children: "No components yet. Select a frame and choose Create Component." }) : null
|
|
3376
4421
|
] });
|
|
3377
4422
|
}
|
|
3378
4423
|
function CanvasInstanceInspector({
|
|
@@ -3391,27 +4436,27 @@ function CanvasInstanceInspector({
|
|
|
3391
4436
|
const allComponents = (0, import_canvas22.listCanvasComponents)(nodes).components;
|
|
3392
4437
|
const linked = info.status === "linked";
|
|
3393
4438
|
const btn2 = "rounded border border-border px-2 py-0.5 text-xs hover:bg-muted disabled:opacity-40";
|
|
3394
|
-
return /* @__PURE__ */ (0,
|
|
3395
|
-
/* @__PURE__ */ (0,
|
|
3396
|
-
/* @__PURE__ */ (0,
|
|
3397
|
-
info.nested ? /* @__PURE__ */ (0,
|
|
4439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { "data-instance-inspector": "", "data-instance-id": info.id, className: `flex flex-col gap-2 text-xs text-foreground ${className}`, children: [
|
|
4440
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center justify-between gap-2", children: [
|
|
4441
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "truncate font-medium", "data-instance-main": "", children: linked ? info.componentName : "Main component missing" }),
|
|
4442
|
+
info.nested ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "text-muted-foreground", children: "Nested" }) : null
|
|
3398
4443
|
] }),
|
|
3399
|
-
info.variantOptions.map((option) => /* @__PURE__ */ (0,
|
|
3400
|
-
/* @__PURE__ */ (0,
|
|
3401
|
-
/* @__PURE__ */ (0,
|
|
4444
|
+
info.variantOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "flex items-center gap-2", "data-variant-property": option.name, children: [
|
|
4445
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "w-24 shrink-0 truncate text-muted-foreground", children: option.name }),
|
|
4446
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3402
4447
|
"select",
|
|
3403
4448
|
{
|
|
3404
4449
|
"aria-label": `${option.name} variant`,
|
|
3405
4450
|
className: "min-w-0 flex-1 rounded border border-border bg-background px-1 py-0.5 text-xs",
|
|
3406
4451
|
value: info.variant[option.name] ?? "",
|
|
3407
4452
|
onChange: (e) => setProp(option.name, e.currentTarget.value),
|
|
3408
|
-
children: option.values.map((v) => /* @__PURE__ */ (0,
|
|
4453
|
+
children: option.values.map((v) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("option", { value: v, children: v }, v))
|
|
3409
4454
|
}
|
|
3410
4455
|
)
|
|
3411
4456
|
] }, option.name)),
|
|
3412
|
-
info.properties.map((p) => /* @__PURE__ */ (0,
|
|
3413
|
-
/* @__PURE__ */ (0,
|
|
3414
|
-
p.type === "boolean" ? /* @__PURE__ */ (0,
|
|
4457
|
+
info.properties.map((p) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "flex items-center gap-2", "data-component-property": p.name, children: [
|
|
4458
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "w-24 shrink-0 truncate text-muted-foreground", children: p.name }),
|
|
4459
|
+
p.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("input", { type: "checkbox", "aria-label": p.name, checked: p.value === true, onChange: (e) => setProp(p.name, e.currentTarget.checked) }) : p.type === "text" ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3415
4460
|
"input",
|
|
3416
4461
|
{
|
|
3417
4462
|
type: "text",
|
|
@@ -3426,22 +4471,22 @@ function CanvasInstanceInspector({
|
|
|
3426
4471
|
}
|
|
3427
4472
|
},
|
|
3428
4473
|
String(p.value)
|
|
3429
|
-
) : /* @__PURE__ */ (0,
|
|
4474
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3430
4475
|
"select",
|
|
3431
4476
|
{
|
|
3432
4477
|
"aria-label": p.name,
|
|
3433
4478
|
className: "min-w-0 flex-1 rounded border border-border bg-background px-1 py-0.5 text-xs",
|
|
3434
4479
|
value: String(p.value),
|
|
3435
4480
|
onChange: (e) => setProp(p.name, e.currentTarget.value),
|
|
3436
|
-
children: allComponents.filter((c) => !p.preferred?.length || p.preferred.includes(c.id) || c.id === p.value).map((c) => /* @__PURE__ */ (0,
|
|
4481
|
+
children: allComponents.filter((c) => !p.preferred?.length || p.preferred.includes(c.id) || c.id === p.value).map((c) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("option", { value: c.id, children: c.name }, c.id))
|
|
3437
4482
|
}
|
|
3438
4483
|
)
|
|
3439
4484
|
] }, p.name)),
|
|
3440
|
-
info.overrides.length ? /* @__PURE__ */ (0,
|
|
3441
|
-
/* @__PURE__ */ (0,
|
|
3442
|
-
info.overrides.map((o) => /* @__PURE__ */ (0,
|
|
3443
|
-
/* @__PURE__ */ (0,
|
|
3444
|
-
o.groups.map((g) => /* @__PURE__ */ (0,
|
|
4485
|
+
info.overrides.length ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex flex-col gap-1", "data-instance-overrides": "", children: [
|
|
4486
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "text-muted-foreground", children: "Overrides" }),
|
|
4487
|
+
info.overrides.map((o) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex flex-wrap items-center gap-1", "data-override-layer": o.id, children: [
|
|
4488
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "mr-1 truncate", children: o.name }),
|
|
4489
|
+
o.groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
|
|
3445
4490
|
"button",
|
|
3446
4491
|
{
|
|
3447
4492
|
type: "button",
|
|
@@ -3458,11 +4503,11 @@ function CanvasInstanceInspector({
|
|
|
3458
4503
|
))
|
|
3459
4504
|
] }, o.id))
|
|
3460
4505
|
] }) : null,
|
|
3461
|
-
/* @__PURE__ */ (0,
|
|
3462
|
-
linked ? /* @__PURE__ */ (0,
|
|
3463
|
-
/* @__PURE__ */ (0,
|
|
3464
|
-
/* @__PURE__ */ (0,
|
|
3465
|
-
/* @__PURE__ */ (0,
|
|
4506
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex flex-wrap gap-1", children: [
|
|
4507
|
+
linked ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
4508
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: btn2, "data-action": "reset", onClick: () => report(components.resetOverrides(info.id)), children: "Reset all" }),
|
|
4509
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: btn2, "data-action": "go-to-main", onClick: () => components.goToMainComponent(info.id), children: "Go to main" }),
|
|
4510
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3466
4511
|
"button",
|
|
3467
4512
|
{
|
|
3468
4513
|
type: "button",
|
|
@@ -3473,8 +4518,8 @@ function CanvasInstanceInspector({
|
|
|
3473
4518
|
children: "Push changes"
|
|
3474
4519
|
}
|
|
3475
4520
|
)
|
|
3476
|
-
] }) : /* @__PURE__ */ (0,
|
|
3477
|
-
/* @__PURE__ */ (0,
|
|
4521
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { type: "button", className: btn2, "data-action": "restore", onClick: () => report(components.restoreMainComponent(info.rootId)), children: "Restore main component" }),
|
|
4522
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
3478
4523
|
"button",
|
|
3479
4524
|
{
|
|
3480
4525
|
type: "button",
|
|
@@ -3494,9 +4539,9 @@ function CanvasInstanceInspector({
|
|
|
3494
4539
|
var import_canvas35 = require("@pixerate/editor/canvas");
|
|
3495
4540
|
|
|
3496
4541
|
// src/canvas/MermaidFamilyScene.tsx
|
|
3497
|
-
var
|
|
4542
|
+
var import_react34 = require("react");
|
|
3498
4543
|
var import_canvas23 = require("@pixerate/editor/canvas");
|
|
3499
|
-
var
|
|
4544
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
3500
4545
|
function MermaidFamilyScene({
|
|
3501
4546
|
scene,
|
|
3502
4547
|
padding = 16,
|
|
@@ -3509,7 +4554,7 @@ function MermaidFamilyScene({
|
|
|
3509
4554
|
style,
|
|
3510
4555
|
title
|
|
3511
4556
|
}) {
|
|
3512
|
-
const uid = (0,
|
|
4557
|
+
const uid = (0, import_react34.useId)().replace(/:/g, "");
|
|
3513
4558
|
const marker = (kind) => kind ? `url(#${uid}-${kind})` : void 0;
|
|
3514
4559
|
const x = scene.x - padding;
|
|
3515
4560
|
const y = scene.y - padding;
|
|
@@ -3527,7 +4572,7 @@ function MermaidFamilyScene({
|
|
|
3527
4572
|
cursor: "pointer"
|
|
3528
4573
|
} : { pointerEvents: "none" };
|
|
3529
4574
|
const stroke = (mark) => mark.selected ? { stroke: selectionColor, strokeWidth: Math.max(2, mark.strokeWidth ?? 0) } : { stroke: mark.stroke, strokeWidth: mark.strokeWidth };
|
|
3530
|
-
return /* @__PURE__ */ (0,
|
|
4575
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
|
|
3531
4576
|
"svg",
|
|
3532
4577
|
{
|
|
3533
4578
|
className: `pixerate-diagram-scene ${className}`.trim(),
|
|
@@ -3540,15 +4585,15 @@ function MermaidFamilyScene({
|
|
|
3540
4585
|
style: { display: "block", maxWidth: "100%", height: "auto", overflow: "visible", ...style },
|
|
3541
4586
|
onClick: interactive ? (event) => onSelect?.(null, event) : void 0,
|
|
3542
4587
|
children: [
|
|
3543
|
-
/* @__PURE__ */ (0,
|
|
3544
|
-
/* @__PURE__ */ (0,
|
|
3545
|
-
/* @__PURE__ */ (0,
|
|
4588
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("defs", { children: [
|
|
4589
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("marker", { id: `${uid}-arrowclosed`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M0,0 L10,5 L0,10 Z", style: { fill: markerColor } }) }),
|
|
4590
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("marker", { id: `${uid}-arrow`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M0,0 L10,5 L0,10", style: { fill: "none", stroke: markerColor, strokeWidth: 1.5 } }) })
|
|
3546
4591
|
] }),
|
|
3547
4592
|
scene.marks.map((mark) => {
|
|
3548
4593
|
const common = { "data-role": mark.role, "data-target": mark.target, "data-selected": mark.selected ? "" : void 0, opacity: mark.opacity, ...handlers(mark) };
|
|
3549
4594
|
switch (mark.kind) {
|
|
3550
4595
|
case "rect":
|
|
3551
|
-
return /* @__PURE__ */ (0,
|
|
4596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3552
4597
|
"rect",
|
|
3553
4598
|
{
|
|
3554
4599
|
...common,
|
|
@@ -3563,9 +4608,9 @@ function MermaidFamilyScene({
|
|
|
3563
4608
|
mark.key
|
|
3564
4609
|
);
|
|
3565
4610
|
case "circle":
|
|
3566
|
-
return /* @__PURE__ */ (0,
|
|
4611
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("circle", { ...common, cx: mark.cx, cy: mark.cy, r: mark.r, style: { fill: mark.fill, ...stroke(mark) } }, mark.key);
|
|
3567
4612
|
case "line":
|
|
3568
|
-
return /* @__PURE__ */ (0,
|
|
4613
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3569
4614
|
"line",
|
|
3570
4615
|
{
|
|
3571
4616
|
...common,
|
|
@@ -3581,7 +4626,7 @@ function MermaidFamilyScene({
|
|
|
3581
4626
|
mark.key
|
|
3582
4627
|
);
|
|
3583
4628
|
case "path":
|
|
3584
|
-
return /* @__PURE__ */ (0,
|
|
4629
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3585
4630
|
"path",
|
|
3586
4631
|
{
|
|
3587
4632
|
...common,
|
|
@@ -3595,7 +4640,7 @@ function MermaidFamilyScene({
|
|
|
3595
4640
|
mark.key
|
|
3596
4641
|
);
|
|
3597
4642
|
case "text":
|
|
3598
|
-
return /* @__PURE__ */ (0,
|
|
4643
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
3599
4644
|
"text",
|
|
3600
4645
|
{
|
|
3601
4646
|
...common,
|
|
@@ -3623,14 +4668,14 @@ function MermaidFamilyScene({
|
|
|
3623
4668
|
}
|
|
3624
4669
|
|
|
3625
4670
|
// src/canvas/useMermaidDiagram.ts
|
|
3626
|
-
var
|
|
4671
|
+
var import_react35 = require("react");
|
|
3627
4672
|
var import_diagram = require("@pixerate/editor/diagram");
|
|
3628
4673
|
var import_canvas24 = require("@pixerate/editor/canvas");
|
|
3629
4674
|
function useDiagramState(controller) {
|
|
3630
|
-
return (0,
|
|
4675
|
+
return (0, import_react35.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
3631
4676
|
}
|
|
3632
4677
|
function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
3633
|
-
const own = (0,
|
|
4678
|
+
const own = (0, import_react35.useRef)(null);
|
|
3634
4679
|
let controller;
|
|
3635
4680
|
if (controllerOrOptions instanceof import_diagram.DiagramController) controller = controllerOrOptions;
|
|
3636
4681
|
else {
|
|
@@ -3640,21 +4685,21 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3640
4685
|
const layoutOptions = (controllerOrOptions instanceof import_diagram.DiagramController ? void 0 : controllerOrOptions.layoutOptions) ?? view.layoutOptions;
|
|
3641
4686
|
const sceneTheme = (controllerOrOptions instanceof import_diagram.DiagramController ? void 0 : controllerOrOptions.sceneTheme) ?? view.sceneTheme;
|
|
3642
4687
|
const state = useDiagramState(controller);
|
|
3643
|
-
const editorDocument = (0,
|
|
3644
|
-
(0,
|
|
3645
|
-
const canvas = (0,
|
|
4688
|
+
const editorDocument = (0, import_react35.useMemo)(() => (0, import_diagram.createDiagramEditorDocument)(controller), [controller]);
|
|
4689
|
+
(0, import_react35.useEffect)(() => () => editorDocument.destroy(), [editorDocument]);
|
|
4690
|
+
const canvas = (0, import_react35.useMemo)(
|
|
3646
4691
|
() => (0, import_canvas24.mermaidToCanvas)(state.document, { ...layoutOptions, editable: state.editable }),
|
|
3647
4692
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3648
4693
|
[state.document, state.editable]
|
|
3649
4694
|
);
|
|
3650
|
-
const scene = (0,
|
|
4695
|
+
const scene = (0, import_react35.useMemo)(
|
|
3651
4696
|
() => state.document.tier === "editable" ? (0, import_canvas24.familySceneFromLayout)(state.document.family, state.document.graph, canvas.layout, { theme: { ...import_canvas24.CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
|
|
3652
4697
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3653
4698
|
[state.document, canvas.layout, state.selection]
|
|
3654
4699
|
);
|
|
3655
|
-
const layoutRef = (0,
|
|
4700
|
+
const layoutRef = (0, import_react35.useRef)(canvas.layout);
|
|
3656
4701
|
layoutRef.current = canvas.layout;
|
|
3657
|
-
const actions = (0,
|
|
4702
|
+
const actions = (0, import_react35.useMemo)(
|
|
3658
4703
|
() => ({
|
|
3659
4704
|
apply: (ops, label) => controller.apply(ops, label),
|
|
3660
4705
|
load: (source, options) => controller.load(source, options),
|
|
@@ -3691,13 +4736,13 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
|
|
|
3691
4736
|
}
|
|
3692
4737
|
function useMermaidStream(source, options = {}) {
|
|
3693
4738
|
const { complete = false, duration = 300, ...layoutOptions } = options;
|
|
3694
|
-
const stream = (0,
|
|
4739
|
+
const stream = (0, import_react35.useRef)(null);
|
|
3695
4740
|
if (!stream.current) stream.current = new import_canvas24.DiagramStream(layoutOptions);
|
|
3696
|
-
const result = (0,
|
|
3697
|
-
const [shown, setShown] = (0,
|
|
3698
|
-
const shownRef = (0,
|
|
4741
|
+
const result = (0, import_react35.useMemo)(() => stream.current.update(source, complete), [source, complete]);
|
|
4742
|
+
const [shown, setShown] = (0, import_react35.useState)({ layout: result.layout, settled: true });
|
|
4743
|
+
const shownRef = (0, import_react35.useRef)(shown.layout);
|
|
3699
4744
|
shownRef.current = shown.layout;
|
|
3700
|
-
(0,
|
|
4745
|
+
(0, import_react35.useEffect)(() => {
|
|
3701
4746
|
const target = result.layout;
|
|
3702
4747
|
if (!target) return setShown({ layout: null, settled: true });
|
|
3703
4748
|
const from = shownRef.current;
|
|
@@ -3714,7 +4759,7 @@ function useMermaidStream(source, options = {}) {
|
|
|
3714
4759
|
return () => cancelAnimationFrame(frame);
|
|
3715
4760
|
}, [result.layout, duration]);
|
|
3716
4761
|
const doc = result.document.tier === "editable" ? result.document : null;
|
|
3717
|
-
const canvas = (0,
|
|
4762
|
+
const canvas = (0, import_react35.useMemo)(() => {
|
|
3718
4763
|
if (!doc || !shown.layout) return { nodes: [], edges: [] };
|
|
3719
4764
|
const placed = new Set(Object.keys(shown.layout.positions));
|
|
3720
4765
|
const graph = {
|
|
@@ -3730,7 +4775,7 @@ function useMermaidStream(source, options = {}) {
|
|
|
3730
4775
|
|
|
3731
4776
|
// src/canvas/MermaidDiagramNode.tsx
|
|
3732
4777
|
var import_canvas25 = require("@pixerate/editor/canvas");
|
|
3733
|
-
var
|
|
4778
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3734
4779
|
function mermaidNodeStyle(styles = {}, selected = false) {
|
|
3735
4780
|
const paint = (0, import_canvas25.mermaidNodePaint)(styles, selected);
|
|
3736
4781
|
const { color, "stroke-width": strokeWidth, "stroke-dasharray": strokeDasharray, ...vars } = paint;
|
|
@@ -3740,7 +4785,7 @@ function MermaidDiagramNode({ data, width = 160, height = 56, selected, classNam
|
|
|
3740
4785
|
const node = data.node;
|
|
3741
4786
|
if (!node) return null;
|
|
3742
4787
|
const members = (0, import_canvas25.mermaidNodeMembers)(node.data);
|
|
3743
|
-
return /* @__PURE__ */ (0,
|
|
4788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
3744
4789
|
"div",
|
|
3745
4790
|
{
|
|
3746
4791
|
className: `pixerate-diagram-node ${className}`.trim(),
|
|
@@ -3748,14 +4793,14 @@ function MermaidDiagramNode({ data, width = 160, height = 56, selected, classNam
|
|
|
3748
4793
|
"data-selected": selected ? "true" : void 0,
|
|
3749
4794
|
style: { position: "relative", width: "100%", height: "100%", ...mermaidNodeStyle(data.resolvedStyles, selected) },
|
|
3750
4795
|
children: [
|
|
3751
|
-
/* @__PURE__ */ (0,
|
|
3752
|
-
/* @__PURE__ */ (0,
|
|
4796
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("svg", { viewBox: `0 0 ${width} ${height}`, preserveAspectRatio: "none", width: "100%", height: "100%", style: { position: "absolute", inset: 0, overflow: "visible" }, "aria-hidden": "true", children: (0, import_canvas25.mermaidShapePaths)(node.shape, width, height).map((path, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("path", { d: path.d, style: { ...import_canvas25.MERMAID_SHAPE_PAINT[path.paint], vectorEffect: "non-scaling-stroke" } }, i)) }),
|
|
4797
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
3753
4798
|
"div",
|
|
3754
4799
|
{
|
|
3755
4800
|
style: { position: "relative", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: members.length ? "flex-start" : "center", height: "100%", padding: "6px 10px", boxSizing: "border-box", fontSize: 13, lineHeight: 1.3, textAlign: "center", pointerEvents: "none" },
|
|
3756
4801
|
children: [
|
|
3757
|
-
(0, import_canvas25.mermaidLabelLines)(node.label).map((line, i) => /* @__PURE__ */ (0,
|
|
3758
|
-
members.length > 0 && /* @__PURE__ */ (0,
|
|
4802
|
+
(0, import_canvas25.mermaidLabelLines)(node.label).map((line, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { style: { fontWeight: members.length ? 600 : void 0 }, children: line }, i)),
|
|
4803
|
+
members.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { style: { alignSelf: "stretch", marginTop: 4, paddingTop: 4, borderTop: "1px solid var(--pixerate-diagram-node-border)", textAlign: "left", fontSize: 12 }, children: members.map((m, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: m }, i)) })
|
|
3759
4804
|
]
|
|
3760
4805
|
}
|
|
3761
4806
|
),
|
|
@@ -3767,7 +4812,7 @@ function MermaidDiagramNode({ data, width = 160, height = 56, selected, classNam
|
|
|
3767
4812
|
function MermaidDiagramGroup({ data, selected, className = "", children }) {
|
|
3768
4813
|
const group = data.group;
|
|
3769
4814
|
if (!group) return null;
|
|
3770
|
-
return /* @__PURE__ */ (0,
|
|
4815
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
3771
4816
|
"div",
|
|
3772
4817
|
{
|
|
3773
4818
|
className: `pixerate-diagram-group ${className}`.trim(),
|
|
@@ -3782,7 +4827,7 @@ function MermaidDiagramGroup({ data, selected, className = "", children }) {
|
|
|
3782
4827
|
color: data.resolvedStyles?.color ?? "var(--muted-foreground, #475569)"
|
|
3783
4828
|
},
|
|
3784
4829
|
children: [
|
|
3785
|
-
/* @__PURE__ */ (0,
|
|
4830
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { style: { padding: "6px 10px", fontSize: 12, fontWeight: 600 }, children: (0, import_canvas25.mermaidLabelLines)(group.label).join(" ") }),
|
|
3786
4831
|
children
|
|
3787
4832
|
]
|
|
3788
4833
|
}
|
|
@@ -3790,29 +4835,29 @@ function MermaidDiagramGroup({ data, selected, className = "", children }) {
|
|
|
3790
4835
|
}
|
|
3791
4836
|
|
|
3792
4837
|
// src/canvas/MermaidThumbnail.tsx
|
|
3793
|
-
var
|
|
4838
|
+
var import_react36 = require("react");
|
|
3794
4839
|
var import_diagram2 = require("@pixerate/editor/diagram");
|
|
3795
4840
|
var import_canvas26 = require("@pixerate/editor/canvas");
|
|
3796
|
-
var
|
|
4841
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3797
4842
|
function MermaidThumbnail({ source, className = "", fallback = null, ...options }) {
|
|
3798
|
-
const doc = (0,
|
|
4843
|
+
const doc = (0, import_react36.useMemo)(() => typeof source === "string" ? (0, import_diagram2.parseMermaid)(source) : source, [source]);
|
|
3799
4844
|
const key = JSON.stringify(options);
|
|
3800
|
-
const drawn = (0,
|
|
4845
|
+
const drawn = (0, import_react36.useMemo)(
|
|
3801
4846
|
() => doc.tier === "editable" && doc.graph.nodes.length ? (0, import_canvas26.mermaidThumbnailSvg)(doc, options) : null,
|
|
3802
4847
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3803
4848
|
[doc, key]
|
|
3804
4849
|
);
|
|
3805
|
-
if (!drawn) return /* @__PURE__ */ (0,
|
|
3806
|
-
return /* @__PURE__ */ (0,
|
|
4850
|
+
if (!drawn) return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_jsx_runtime20.Fragment, { children: fallback });
|
|
4851
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: `pixerate-diagram-thumbnail ${className}`.trim(), style: { display: "inline-block", lineHeight: 0 }, dangerouslySetInnerHTML: { __html: drawn.svg } });
|
|
3807
4852
|
}
|
|
3808
4853
|
|
|
3809
4854
|
// src/canvas/useDiagramDirector.ts
|
|
3810
|
-
var
|
|
4855
|
+
var import_react37 = require("react");
|
|
3811
4856
|
var import_diagram3 = require("@pixerate/editor/diagram");
|
|
3812
4857
|
function useDiagramDirector(controller, options) {
|
|
3813
|
-
const placement = (0,
|
|
4858
|
+
const placement = (0, import_react37.useRef)(options.placement);
|
|
3814
4859
|
placement.current = options.placement;
|
|
3815
|
-
const ref = (0,
|
|
4860
|
+
const ref = (0, import_react37.useRef)(null);
|
|
3816
4861
|
if (!ref.current) {
|
|
3817
4862
|
const presence = new import_diagram3.PresenceStore();
|
|
3818
4863
|
ref.current = {
|
|
@@ -3823,17 +4868,17 @@ function useDiagramDirector(controller, options) {
|
|
|
3823
4868
|
return ref.current;
|
|
3824
4869
|
}
|
|
3825
4870
|
function usePresenceState(presence) {
|
|
3826
|
-
return (0,
|
|
4871
|
+
return (0, import_react37.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
3827
4872
|
}
|
|
3828
4873
|
|
|
3829
4874
|
// src/canvas/DiagramPresenceLayer.tsx
|
|
3830
|
-
var
|
|
4875
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
3831
4876
|
function DiagramPresenceLayer({ presence, viewport, className = "" }) {
|
|
3832
4877
|
const { actors } = usePresenceState(presence);
|
|
3833
4878
|
if (!actors.length) return null;
|
|
3834
|
-
return /* @__PURE__ */ (0,
|
|
3835
|
-
/* @__PURE__ */ (0,
|
|
3836
|
-
/* @__PURE__ */ (0,
|
|
4879
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: `pixerate-diagram-presence ${className}`.trim(), "aria-hidden": "true", style: { position: "absolute", inset: 0, pointerEvents: "none", overflow: "hidden", zIndex: 50 }, children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { "data-actor": a.id, style: { position: "absolute", left: 0, top: 0, transform: `translate(${a.x * viewport.zoom + viewport.x}px, ${a.y * viewport.zoom + viewport.y}px)` }, children: [
|
|
4880
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("svg", { width: "18", height: "20", viewBox: "0 0 12 18", style: { display: "block", transform: a.pressed ? "scale(0.85)" : void 0, transformOrigin: "0 0" }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 } }) }),
|
|
4881
|
+
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { style: { position: "absolute", left: 14, top: 16, whiteSpace: "nowrap", borderRadius: 4, padding: "1px 6px", fontSize: 11, fontWeight: 600, color: "#ffffff", background: a.color }, children: a.message ?? a.name })
|
|
3837
4882
|
] }, a.id)) });
|
|
3838
4883
|
}
|
|
3839
4884
|
// Annotate the CommonJS export names for ESM import in node:
|