@pixerate/editor-react 0.105.0 → 0.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation-editor/index.cjs +2 -1
- package/dist/animation-editor/index.js +1 -1
- package/dist/canvas/index.cjs +2 -1
- package/dist/canvas/index.js +1 -1
- package/dist/{chunk-CEV4OEOY.js → chunk-6XI62THS.js} +1 -1
- package/dist/{chunk-Q7LAFHGP.js → chunk-ZQ6H2C7N.js} +2 -1
- package/dist/effects/EffectParameters.d.cts +4 -2
- package/dist/effects/EffectParameters.d.ts +4 -2
- package/dist/effects/index.cjs +2 -1
- package/dist/effects/index.js +1 -1
- package/dist/image-editor/index.cjs +2 -1
- package/dist/image-editor/index.js +2 -2
- package/dist/index.cjs +2 -1
- package/dist/index.js +2 -2
- package/dist/paint-editor/index.cjs +2 -1
- package/dist/paint-editor/index.js +1 -1
- package/dist/typography/FontPicker.d.cts +48 -0
- package/dist/typography/FontPicker.d.ts +48 -0
- package/dist/typography/TypographyControl.d.cts +11 -0
- package/dist/typography/TypographyControl.d.ts +11 -0
- package/dist/typography/index.cjs +328 -0
- package/dist/typography/index.d.cts +7 -0
- package/dist/typography/index.d.ts +7 -0
- package/dist/typography/index.js +299 -0
- package/dist/typography/useFontPicker.d.cts +17 -0
- package/dist/typography/useFontPicker.d.ts +17 -0
- package/dist/vector/index.cjs +2 -1
- package/dist/vector/index.js +1 -1
- package/dist/video-editor/EditPlanPreview.d.cts +16 -0
- package/dist/video-editor/EditPlanPreview.d.ts +16 -0
- package/dist/video-editor/TranscriptEditor.d.cts +20 -0
- package/dist/video-editor/TranscriptEditor.d.ts +20 -0
- package/dist/video-editor/VideoEditor.d.cts +7 -1
- package/dist/video-editor/VideoEditor.d.ts +7 -1
- package/dist/video-editor/VideoTransport.d.cts +2 -1
- package/dist/video-editor/VideoTransport.d.ts +2 -1
- package/dist/video-editor/index.cjs +1054 -260
- package/dist/video-editor/index.d.cts +3 -0
- package/dist/video-editor/index.d.ts +3 -0
- package/dist/video-editor/index.js +438 -70
- package/dist/video-editor/useTranscriptVideo.d.cts +8 -0
- package/dist/video-editor/useTranscriptVideo.d.ts +8 -0
- package/dist/video-editor/useVideoEditor.d.cts +12 -1
- package/dist/video-editor/useVideoEditor.d.ts +12 -1
- package/package.json +16 -3
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/typography/index.ts
|
|
22
|
+
var typography_exports = {};
|
|
23
|
+
__export(typography_exports, {
|
|
24
|
+
FontPicker: () => FontPicker,
|
|
25
|
+
FontPickerView: () => FontPickerView,
|
|
26
|
+
TypographyControl: () => TypographyControl,
|
|
27
|
+
useFontPicker: () => useFontPicker
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(typography_exports);
|
|
30
|
+
|
|
31
|
+
// src/typography/FontPicker.tsx
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
var import_typography2 = require("@pixerate/editor/typography");
|
|
34
|
+
|
|
35
|
+
// src/typography/useFontPicker.ts
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_typography = require("@pixerate/editor/typography");
|
|
38
|
+
function useFontPicker(options = {}) {
|
|
39
|
+
const onChangeRef = (0, import_react.useRef)(options.onChange);
|
|
40
|
+
onChangeRef.current = options.onChange;
|
|
41
|
+
const [model] = (0, import_react.useState)(() => options.model ?? new import_typography.FontPickerModel({ ...options, onChange: void 0 }));
|
|
42
|
+
const state = (0, import_react.useSyncExternalStore)(model.subscribe, model.getState, model.getState);
|
|
43
|
+
(0, import_react.useEffect)(() => model.onValueChange((value) => onChangeRef.current?.(value)), [model]);
|
|
44
|
+
const valueKey = options.value ? JSON.stringify(options.value) : "";
|
|
45
|
+
(0, import_react.useEffect)(() => {
|
|
46
|
+
if (options.value) model.setValue(options.value);
|
|
47
|
+
}, [model, valueKey]);
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
49
|
+
if (!options.model && options.provider) void model.refresh();
|
|
50
|
+
}, [model]);
|
|
51
|
+
return { model, state };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/typography/FontPicker.tsx
|
|
55
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
56
|
+
var FIELD = {
|
|
57
|
+
boxSizing: "border-box",
|
|
58
|
+
width: "100%",
|
|
59
|
+
padding: "5px 8px",
|
|
60
|
+
borderRadius: "6px",
|
|
61
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)",
|
|
62
|
+
background: "var(--pixerate-font-picker-field-bg, #151922)",
|
|
63
|
+
color: "inherit",
|
|
64
|
+
font: "inherit"
|
|
65
|
+
};
|
|
66
|
+
function FontPickerView({
|
|
67
|
+
model,
|
|
68
|
+
showPreview = true,
|
|
69
|
+
showCategories = true,
|
|
70
|
+
showWeight = true,
|
|
71
|
+
maxResults = 200,
|
|
72
|
+
disabled = false,
|
|
73
|
+
className,
|
|
74
|
+
id,
|
|
75
|
+
"aria-label": ariaLabel = "Font picker",
|
|
76
|
+
children
|
|
77
|
+
}) {
|
|
78
|
+
const { state } = useFontPicker({ model });
|
|
79
|
+
const baseId = (0, import_react2.useId)();
|
|
80
|
+
const listId = `${baseId}-list`;
|
|
81
|
+
const optionId = (i) => `${baseId}-opt-${i}`;
|
|
82
|
+
const listRef = (0, import_react2.useRef)(null);
|
|
83
|
+
const shown = state.results.slice(0, maxResults);
|
|
84
|
+
const css = model.css;
|
|
85
|
+
(0, import_react2.useEffect)(() => {
|
|
86
|
+
if (state.highlighted < 0) return;
|
|
87
|
+
const el = listRef.current?.ownerDocument.getElementById(optionId(state.highlighted));
|
|
88
|
+
el?.scrollIntoView?.({ block: "nearest" });
|
|
89
|
+
}, [state.highlighted]);
|
|
90
|
+
const status = state.loading ? "Loading fonts\u2026" : state.error ? `Could not load fonts: ${state.error}` : state.loadStatus[state.value.family.toLowerCase()] === "failed" ? `${state.value.family} could not be loaded; a fallback is shown.` : "";
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
92
|
+
"div",
|
|
93
|
+
{
|
|
94
|
+
id,
|
|
95
|
+
role: "group",
|
|
96
|
+
"aria-label": ariaLabel,
|
|
97
|
+
"aria-disabled": disabled || void 0,
|
|
98
|
+
className,
|
|
99
|
+
style: {
|
|
100
|
+
boxSizing: "border-box",
|
|
101
|
+
width: "var(--pixerate-font-picker-width, 280px)",
|
|
102
|
+
borderRadius: "var(--pixerate-font-picker-radius, 8px)",
|
|
103
|
+
background: "var(--pixerate-font-picker-bg, #1f2430)",
|
|
104
|
+
color: "var(--pixerate-font-picker-fg, #f0f2f5)",
|
|
105
|
+
padding: "12px",
|
|
106
|
+
display: "flex",
|
|
107
|
+
flexDirection: "column",
|
|
108
|
+
gap: "8px",
|
|
109
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
110
|
+
fontSize: "12px",
|
|
111
|
+
opacity: disabled ? 0.6 : 1,
|
|
112
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
113
|
+
},
|
|
114
|
+
children: [
|
|
115
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
117
|
+
"input",
|
|
118
|
+
{
|
|
119
|
+
type: "text",
|
|
120
|
+
role: "combobox",
|
|
121
|
+
"aria-label": "Search fonts",
|
|
122
|
+
"aria-expanded": "true",
|
|
123
|
+
"aria-controls": listId,
|
|
124
|
+
"aria-autocomplete": "list",
|
|
125
|
+
"aria-activedescendant": state.highlighted >= 0 && state.highlighted < shown.length ? optionId(state.highlighted) : void 0,
|
|
126
|
+
placeholder: "Search fonts",
|
|
127
|
+
value: state.query,
|
|
128
|
+
disabled,
|
|
129
|
+
onChange: (e) => model.setQuery(e.target.value),
|
|
130
|
+
onKeyDown: (e) => {
|
|
131
|
+
if (model.handleKey(e.key)) e.preventDefault();
|
|
132
|
+
},
|
|
133
|
+
style: FIELD
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
showCategories && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
137
|
+
"select",
|
|
138
|
+
{
|
|
139
|
+
"aria-label": "Font category",
|
|
140
|
+
value: state.category,
|
|
141
|
+
disabled,
|
|
142
|
+
onChange: (e) => model.setCategory(e.target.value),
|
|
143
|
+
style: { ...FIELD, width: "auto" },
|
|
144
|
+
children: ["all", ...import_typography2.FONT_CATEGORIES].map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: c, children: import_typography2.FONT_CATEGORY_LABELS[c] }, c))
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
149
|
+
"ul",
|
|
150
|
+
{
|
|
151
|
+
ref: listRef,
|
|
152
|
+
id: listId,
|
|
153
|
+
role: "listbox",
|
|
154
|
+
"aria-label": "Fonts",
|
|
155
|
+
style: {
|
|
156
|
+
listStyle: "none",
|
|
157
|
+
margin: 0,
|
|
158
|
+
padding: "2px",
|
|
159
|
+
maxHeight: "var(--pixerate-font-picker-list-height, 180px)",
|
|
160
|
+
overflowY: "auto",
|
|
161
|
+
borderRadius: "6px",
|
|
162
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)"
|
|
163
|
+
},
|
|
164
|
+
children: [
|
|
165
|
+
shown.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { role: "presentation", style: { padding: "6px 8px", opacity: 0.7 }, children: state.loading ? "Loading\u2026" : "No fonts match" }),
|
|
166
|
+
shown.map((font, i) => {
|
|
167
|
+
const selected = font.family.toLowerCase() === state.value.family.toLowerCase();
|
|
168
|
+
const highlighted = i === state.highlighted;
|
|
169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
170
|
+
"li",
|
|
171
|
+
{
|
|
172
|
+
id: optionId(i),
|
|
173
|
+
role: "option",
|
|
174
|
+
"aria-selected": selected,
|
|
175
|
+
"data-highlighted": highlighted || void 0,
|
|
176
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
177
|
+
onMouseEnter: () => model.setHighlight(i),
|
|
178
|
+
onClick: () => model.selectFamily(font.family),
|
|
179
|
+
style: {
|
|
180
|
+
display: "flex",
|
|
181
|
+
justifyContent: "space-between",
|
|
182
|
+
alignItems: "baseline",
|
|
183
|
+
gap: "8px",
|
|
184
|
+
padding: "5px 8px",
|
|
185
|
+
borderRadius: "4px",
|
|
186
|
+
cursor: "pointer",
|
|
187
|
+
background: selected ? "var(--pixerate-font-picker-selected, #2f3b57)" : highlighted ? "var(--pixerate-font-picker-hover, #2a3040)" : "transparent"
|
|
188
|
+
},
|
|
189
|
+
children: [
|
|
190
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontFamily: model.familyCss(font), fontSize: "14px" }, children: font.family }),
|
|
191
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { opacity: 0.6, fontSize: "10px" }, children: import_typography2.FONT_CATEGORY_LABELS[font.category] })
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
font.family
|
|
195
|
+
);
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
showWeight && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
201
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
202
|
+
"select",
|
|
203
|
+
{
|
|
204
|
+
"aria-label": "Font weight",
|
|
205
|
+
value: state.value.weight,
|
|
206
|
+
disabled,
|
|
207
|
+
onChange: (e) => model.setWeight(Number(e.target.value)),
|
|
208
|
+
style: FIELD,
|
|
209
|
+
children: model.availableWeights.map((w) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: w, children: w }, w))
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
213
|
+
"select",
|
|
214
|
+
{
|
|
215
|
+
"aria-label": "Font style",
|
|
216
|
+
value: state.value.style,
|
|
217
|
+
disabled,
|
|
218
|
+
onChange: (e) => model.setStyle(e.target.value),
|
|
219
|
+
style: FIELD,
|
|
220
|
+
children: model.availableStyles.map((s) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: s, children: s }, s))
|
|
221
|
+
}
|
|
222
|
+
)
|
|
223
|
+
] }),
|
|
224
|
+
children,
|
|
225
|
+
showPreview && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
|
+
"div",
|
|
227
|
+
{
|
|
228
|
+
"aria-label": "Font preview",
|
|
229
|
+
style: {
|
|
230
|
+
fontFamily: css.fontFamily,
|
|
231
|
+
fontWeight: css.fontWeight,
|
|
232
|
+
fontStyle: css.fontStyle,
|
|
233
|
+
fontSize: `${Math.min(state.value.size, 48)}px`,
|
|
234
|
+
lineHeight: css.lineHeight,
|
|
235
|
+
letterSpacing: css.letterSpacing,
|
|
236
|
+
padding: "6px 4px",
|
|
237
|
+
overflowWrap: "anywhere"
|
|
238
|
+
},
|
|
239
|
+
children: state.previewText
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { role: "status", "aria-live": "polite", style: { minHeight: status ? void 0 : 0, opacity: 0.75 }, children: status })
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
function FontPicker({ value, onChange, model, provider, fonts, previewText, ...view }) {
|
|
248
|
+
const picker = useFontPicker({ model, provider, fonts, previewText, value, onChange });
|
|
249
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FontPickerView, { model: picker.model, ...view });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/typography/TypographyControl.tsx
|
|
253
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
254
|
+
var NUMBER = {
|
|
255
|
+
boxSizing: "border-box",
|
|
256
|
+
width: "100%",
|
|
257
|
+
padding: "5px 6px",
|
|
258
|
+
borderRadius: "6px",
|
|
259
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)",
|
|
260
|
+
background: "var(--pixerate-font-picker-field-bg, #151922)",
|
|
261
|
+
color: "inherit",
|
|
262
|
+
font: "inherit"
|
|
263
|
+
};
|
|
264
|
+
function NumberField({
|
|
265
|
+
label,
|
|
266
|
+
unit,
|
|
267
|
+
value,
|
|
268
|
+
step,
|
|
269
|
+
min,
|
|
270
|
+
max,
|
|
271
|
+
disabled,
|
|
272
|
+
onCommit
|
|
273
|
+
}) {
|
|
274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { style: { display: "flex", flexDirection: "column", gap: "2px", flex: 1, minWidth: 0 }, children: [
|
|
275
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: { opacity: 0.75 }, children: [
|
|
276
|
+
label,
|
|
277
|
+
" ",
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { opacity: 0.6 }, children: unit })
|
|
279
|
+
] }),
|
|
280
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
281
|
+
"input",
|
|
282
|
+
{
|
|
283
|
+
type: "number",
|
|
284
|
+
"aria-label": label,
|
|
285
|
+
value,
|
|
286
|
+
step,
|
|
287
|
+
min,
|
|
288
|
+
max,
|
|
289
|
+
disabled,
|
|
290
|
+
onChange: (e) => {
|
|
291
|
+
const n = e.target.valueAsNumber;
|
|
292
|
+
if (Number.isFinite(n)) onCommit(n);
|
|
293
|
+
},
|
|
294
|
+
style: NUMBER
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
] });
|
|
298
|
+
}
|
|
299
|
+
function TypographyControl({
|
|
300
|
+
value,
|
|
301
|
+
onChange,
|
|
302
|
+
model,
|
|
303
|
+
provider,
|
|
304
|
+
fonts,
|
|
305
|
+
previewText,
|
|
306
|
+
disabled = false,
|
|
307
|
+
"aria-label": ariaLabel = "Typography",
|
|
308
|
+
...view
|
|
309
|
+
}) {
|
|
310
|
+
const { model: m, state } = useFontPicker({ model, provider, fonts, previewText, value, onChange });
|
|
311
|
+
const v = state.value;
|
|
312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FontPickerView, { model: m, disabled, "aria-label": ariaLabel, ...view, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
313
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NumberField, { label: "Font size", unit: "px", value: v.size, step: 1, min: 1, max: 1e3, disabled, onCommit: (n) => m.setSize(n) }),
|
|
314
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NumberField, { label: "Line height", unit: "\xD7", value: v.lineHeight ?? 1.5, step: 0.05, min: 0.5, max: 4, disabled, onCommit: (n) => m.setLineHeight(n) }),
|
|
315
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NumberField, { label: "Letter spacing", unit: "em", value: v.letterSpacing ?? 0, step: 0.01, min: -0.5, max: 1, disabled, onCommit: (n) => m.setLetterSpacing(n) })
|
|
316
|
+
] }) });
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/typography/index.ts
|
|
320
|
+
__reExport(typography_exports, require("@pixerate/editor/typography"), module.exports);
|
|
321
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
322
|
+
0 && (module.exports = {
|
|
323
|
+
FontPicker,
|
|
324
|
+
FontPickerView,
|
|
325
|
+
TypographyControl,
|
|
326
|
+
useFontPicker,
|
|
327
|
+
...require("@pixerate/editor/typography")
|
|
328
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FontPicker, FontPickerView } from "./FontPicker.cjs";
|
|
2
|
+
export type { FontPickerProps } from "./FontPicker.cjs";
|
|
3
|
+
export { TypographyControl } from "./TypographyControl.cjs";
|
|
4
|
+
export type { TypographyControlProps } from "./TypographyControl.cjs";
|
|
5
|
+
export { useFontPicker } from "./useFontPicker.cjs";
|
|
6
|
+
export type { UseFontPickerOptions, UseFontPickerResult } from "./useFontPicker.cjs";
|
|
7
|
+
export * from "@pixerate/editor/typography";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FontPicker, FontPickerView } from "./FontPicker.js";
|
|
2
|
+
export type { FontPickerProps } from "./FontPicker.js";
|
|
3
|
+
export { TypographyControl } from "./TypographyControl.js";
|
|
4
|
+
export type { TypographyControlProps } from "./TypographyControl.js";
|
|
5
|
+
export { useFontPicker } from "./useFontPicker.js";
|
|
6
|
+
export type { UseFontPickerOptions, UseFontPickerResult } from "./useFontPicker.js";
|
|
7
|
+
export * from "@pixerate/editor/typography";
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// src/typography/FontPicker.tsx
|
|
2
|
+
import { useEffect as useEffect2, useId, useRef as useRef2 } from "react";
|
|
3
|
+
import {
|
|
4
|
+
FONT_CATEGORIES,
|
|
5
|
+
FONT_CATEGORY_LABELS
|
|
6
|
+
} from "@pixerate/editor/typography";
|
|
7
|
+
|
|
8
|
+
// src/typography/useFontPicker.ts
|
|
9
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
10
|
+
import { FontPickerModel } from "@pixerate/editor/typography";
|
|
11
|
+
function useFontPicker(options = {}) {
|
|
12
|
+
const onChangeRef = useRef(options.onChange);
|
|
13
|
+
onChangeRef.current = options.onChange;
|
|
14
|
+
const [model] = useState(() => options.model ?? new FontPickerModel({ ...options, onChange: void 0 }));
|
|
15
|
+
const state = useSyncExternalStore(model.subscribe, model.getState, model.getState);
|
|
16
|
+
useEffect(() => model.onValueChange((value) => onChangeRef.current?.(value)), [model]);
|
|
17
|
+
const valueKey = options.value ? JSON.stringify(options.value) : "";
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (options.value) model.setValue(options.value);
|
|
20
|
+
}, [model, valueKey]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!options.model && options.provider) void model.refresh();
|
|
23
|
+
}, [model]);
|
|
24
|
+
return { model, state };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/typography/FontPicker.tsx
|
|
28
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
var FIELD = {
|
|
30
|
+
boxSizing: "border-box",
|
|
31
|
+
width: "100%",
|
|
32
|
+
padding: "5px 8px",
|
|
33
|
+
borderRadius: "6px",
|
|
34
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)",
|
|
35
|
+
background: "var(--pixerate-font-picker-field-bg, #151922)",
|
|
36
|
+
color: "inherit",
|
|
37
|
+
font: "inherit"
|
|
38
|
+
};
|
|
39
|
+
function FontPickerView({
|
|
40
|
+
model,
|
|
41
|
+
showPreview = true,
|
|
42
|
+
showCategories = true,
|
|
43
|
+
showWeight = true,
|
|
44
|
+
maxResults = 200,
|
|
45
|
+
disabled = false,
|
|
46
|
+
className,
|
|
47
|
+
id,
|
|
48
|
+
"aria-label": ariaLabel = "Font picker",
|
|
49
|
+
children
|
|
50
|
+
}) {
|
|
51
|
+
const { state } = useFontPicker({ model });
|
|
52
|
+
const baseId = useId();
|
|
53
|
+
const listId = `${baseId}-list`;
|
|
54
|
+
const optionId = (i) => `${baseId}-opt-${i}`;
|
|
55
|
+
const listRef = useRef2(null);
|
|
56
|
+
const shown = state.results.slice(0, maxResults);
|
|
57
|
+
const css = model.css;
|
|
58
|
+
useEffect2(() => {
|
|
59
|
+
if (state.highlighted < 0) return;
|
|
60
|
+
const el = listRef.current?.ownerDocument.getElementById(optionId(state.highlighted));
|
|
61
|
+
el?.scrollIntoView?.({ block: "nearest" });
|
|
62
|
+
}, [state.highlighted]);
|
|
63
|
+
const status = state.loading ? "Loading fonts\u2026" : state.error ? `Could not load fonts: ${state.error}` : state.loadStatus[state.value.family.toLowerCase()] === "failed" ? `${state.value.family} could not be loaded; a fallback is shown.` : "";
|
|
64
|
+
return /* @__PURE__ */ jsxs(
|
|
65
|
+
"div",
|
|
66
|
+
{
|
|
67
|
+
id,
|
|
68
|
+
role: "group",
|
|
69
|
+
"aria-label": ariaLabel,
|
|
70
|
+
"aria-disabled": disabled || void 0,
|
|
71
|
+
className,
|
|
72
|
+
style: {
|
|
73
|
+
boxSizing: "border-box",
|
|
74
|
+
width: "var(--pixerate-font-picker-width, 280px)",
|
|
75
|
+
borderRadius: "var(--pixerate-font-picker-radius, 8px)",
|
|
76
|
+
background: "var(--pixerate-font-picker-bg, #1f2430)",
|
|
77
|
+
color: "var(--pixerate-font-picker-fg, #f0f2f5)",
|
|
78
|
+
padding: "12px",
|
|
79
|
+
display: "flex",
|
|
80
|
+
flexDirection: "column",
|
|
81
|
+
gap: "8px",
|
|
82
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
83
|
+
fontSize: "12px",
|
|
84
|
+
opacity: disabled ? 0.6 : 1,
|
|
85
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
86
|
+
},
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
"input",
|
|
91
|
+
{
|
|
92
|
+
type: "text",
|
|
93
|
+
role: "combobox",
|
|
94
|
+
"aria-label": "Search fonts",
|
|
95
|
+
"aria-expanded": "true",
|
|
96
|
+
"aria-controls": listId,
|
|
97
|
+
"aria-autocomplete": "list",
|
|
98
|
+
"aria-activedescendant": state.highlighted >= 0 && state.highlighted < shown.length ? optionId(state.highlighted) : void 0,
|
|
99
|
+
placeholder: "Search fonts",
|
|
100
|
+
value: state.query,
|
|
101
|
+
disabled,
|
|
102
|
+
onChange: (e) => model.setQuery(e.target.value),
|
|
103
|
+
onKeyDown: (e) => {
|
|
104
|
+
if (model.handleKey(e.key)) e.preventDefault();
|
|
105
|
+
},
|
|
106
|
+
style: FIELD
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
showCategories && /* @__PURE__ */ jsx(
|
|
110
|
+
"select",
|
|
111
|
+
{
|
|
112
|
+
"aria-label": "Font category",
|
|
113
|
+
value: state.category,
|
|
114
|
+
disabled,
|
|
115
|
+
onChange: (e) => model.setCategory(e.target.value),
|
|
116
|
+
style: { ...FIELD, width: "auto" },
|
|
117
|
+
children: ["all", ...FONT_CATEGORIES].map((c) => /* @__PURE__ */ jsx("option", { value: c, children: FONT_CATEGORY_LABELS[c] }, c))
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
] }),
|
|
121
|
+
/* @__PURE__ */ jsxs(
|
|
122
|
+
"ul",
|
|
123
|
+
{
|
|
124
|
+
ref: listRef,
|
|
125
|
+
id: listId,
|
|
126
|
+
role: "listbox",
|
|
127
|
+
"aria-label": "Fonts",
|
|
128
|
+
style: {
|
|
129
|
+
listStyle: "none",
|
|
130
|
+
margin: 0,
|
|
131
|
+
padding: "2px",
|
|
132
|
+
maxHeight: "var(--pixerate-font-picker-list-height, 180px)",
|
|
133
|
+
overflowY: "auto",
|
|
134
|
+
borderRadius: "6px",
|
|
135
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)"
|
|
136
|
+
},
|
|
137
|
+
children: [
|
|
138
|
+
shown.length === 0 && /* @__PURE__ */ jsx("li", { role: "presentation", style: { padding: "6px 8px", opacity: 0.7 }, children: state.loading ? "Loading\u2026" : "No fonts match" }),
|
|
139
|
+
shown.map((font, i) => {
|
|
140
|
+
const selected = font.family.toLowerCase() === state.value.family.toLowerCase();
|
|
141
|
+
const highlighted = i === state.highlighted;
|
|
142
|
+
return /* @__PURE__ */ jsxs(
|
|
143
|
+
"li",
|
|
144
|
+
{
|
|
145
|
+
id: optionId(i),
|
|
146
|
+
role: "option",
|
|
147
|
+
"aria-selected": selected,
|
|
148
|
+
"data-highlighted": highlighted || void 0,
|
|
149
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
150
|
+
onMouseEnter: () => model.setHighlight(i),
|
|
151
|
+
onClick: () => model.selectFamily(font.family),
|
|
152
|
+
style: {
|
|
153
|
+
display: "flex",
|
|
154
|
+
justifyContent: "space-between",
|
|
155
|
+
alignItems: "baseline",
|
|
156
|
+
gap: "8px",
|
|
157
|
+
padding: "5px 8px",
|
|
158
|
+
borderRadius: "4px",
|
|
159
|
+
cursor: "pointer",
|
|
160
|
+
background: selected ? "var(--pixerate-font-picker-selected, #2f3b57)" : highlighted ? "var(--pixerate-font-picker-hover, #2a3040)" : "transparent"
|
|
161
|
+
},
|
|
162
|
+
children: [
|
|
163
|
+
/* @__PURE__ */ jsx("span", { style: { fontFamily: model.familyCss(font), fontSize: "14px" }, children: font.family }),
|
|
164
|
+
/* @__PURE__ */ jsx("span", { style: { opacity: 0.6, fontSize: "10px" }, children: FONT_CATEGORY_LABELS[font.category] })
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
font.family
|
|
168
|
+
);
|
|
169
|
+
})
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
showWeight && /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
174
|
+
/* @__PURE__ */ jsx(
|
|
175
|
+
"select",
|
|
176
|
+
{
|
|
177
|
+
"aria-label": "Font weight",
|
|
178
|
+
value: state.value.weight,
|
|
179
|
+
disabled,
|
|
180
|
+
onChange: (e) => model.setWeight(Number(e.target.value)),
|
|
181
|
+
style: FIELD,
|
|
182
|
+
children: model.availableWeights.map((w) => /* @__PURE__ */ jsx("option", { value: w, children: w }, w))
|
|
183
|
+
}
|
|
184
|
+
),
|
|
185
|
+
/* @__PURE__ */ jsx(
|
|
186
|
+
"select",
|
|
187
|
+
{
|
|
188
|
+
"aria-label": "Font style",
|
|
189
|
+
value: state.value.style,
|
|
190
|
+
disabled,
|
|
191
|
+
onChange: (e) => model.setStyle(e.target.value),
|
|
192
|
+
style: FIELD,
|
|
193
|
+
children: model.availableStyles.map((s) => /* @__PURE__ */ jsx("option", { value: s, children: s }, s))
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
] }),
|
|
197
|
+
children,
|
|
198
|
+
showPreview && /* @__PURE__ */ jsx(
|
|
199
|
+
"div",
|
|
200
|
+
{
|
|
201
|
+
"aria-label": "Font preview",
|
|
202
|
+
style: {
|
|
203
|
+
fontFamily: css.fontFamily,
|
|
204
|
+
fontWeight: css.fontWeight,
|
|
205
|
+
fontStyle: css.fontStyle,
|
|
206
|
+
fontSize: `${Math.min(state.value.size, 48)}px`,
|
|
207
|
+
lineHeight: css.lineHeight,
|
|
208
|
+
letterSpacing: css.letterSpacing,
|
|
209
|
+
padding: "6px 4px",
|
|
210
|
+
overflowWrap: "anywhere"
|
|
211
|
+
},
|
|
212
|
+
children: state.previewText
|
|
213
|
+
}
|
|
214
|
+
),
|
|
215
|
+
/* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", style: { minHeight: status ? void 0 : 0, opacity: 0.75 }, children: status })
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
function FontPicker({ value, onChange, model, provider, fonts, previewText, ...view }) {
|
|
221
|
+
const picker = useFontPicker({ model, provider, fonts, previewText, value, onChange });
|
|
222
|
+
return /* @__PURE__ */ jsx(FontPickerView, { model: picker.model, ...view });
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/typography/TypographyControl.tsx
|
|
226
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
227
|
+
var NUMBER = {
|
|
228
|
+
boxSizing: "border-box",
|
|
229
|
+
width: "100%",
|
|
230
|
+
padding: "5px 6px",
|
|
231
|
+
borderRadius: "6px",
|
|
232
|
+
border: "1px solid var(--pixerate-font-picker-border, #3a4152)",
|
|
233
|
+
background: "var(--pixerate-font-picker-field-bg, #151922)",
|
|
234
|
+
color: "inherit",
|
|
235
|
+
font: "inherit"
|
|
236
|
+
};
|
|
237
|
+
function NumberField({
|
|
238
|
+
label,
|
|
239
|
+
unit,
|
|
240
|
+
value,
|
|
241
|
+
step,
|
|
242
|
+
min,
|
|
243
|
+
max,
|
|
244
|
+
disabled,
|
|
245
|
+
onCommit
|
|
246
|
+
}) {
|
|
247
|
+
return /* @__PURE__ */ jsxs2("label", { style: { display: "flex", flexDirection: "column", gap: "2px", flex: 1, minWidth: 0 }, children: [
|
|
248
|
+
/* @__PURE__ */ jsxs2("span", { style: { opacity: 0.75 }, children: [
|
|
249
|
+
label,
|
|
250
|
+
" ",
|
|
251
|
+
/* @__PURE__ */ jsx2("span", { style: { opacity: 0.6 }, children: unit })
|
|
252
|
+
] }),
|
|
253
|
+
/* @__PURE__ */ jsx2(
|
|
254
|
+
"input",
|
|
255
|
+
{
|
|
256
|
+
type: "number",
|
|
257
|
+
"aria-label": label,
|
|
258
|
+
value,
|
|
259
|
+
step,
|
|
260
|
+
min,
|
|
261
|
+
max,
|
|
262
|
+
disabled,
|
|
263
|
+
onChange: (e) => {
|
|
264
|
+
const n = e.target.valueAsNumber;
|
|
265
|
+
if (Number.isFinite(n)) onCommit(n);
|
|
266
|
+
},
|
|
267
|
+
style: NUMBER
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
] });
|
|
271
|
+
}
|
|
272
|
+
function TypographyControl({
|
|
273
|
+
value,
|
|
274
|
+
onChange,
|
|
275
|
+
model,
|
|
276
|
+
provider,
|
|
277
|
+
fonts,
|
|
278
|
+
previewText,
|
|
279
|
+
disabled = false,
|
|
280
|
+
"aria-label": ariaLabel = "Typography",
|
|
281
|
+
...view
|
|
282
|
+
}) {
|
|
283
|
+
const { model: m, state } = useFontPicker({ model, provider, fonts, previewText, value, onChange });
|
|
284
|
+
const v = state.value;
|
|
285
|
+
return /* @__PURE__ */ jsx2(FontPickerView, { model: m, disabled, "aria-label": ariaLabel, ...view, children: /* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
286
|
+
/* @__PURE__ */ jsx2(NumberField, { label: "Font size", unit: "px", value: v.size, step: 1, min: 1, max: 1e3, disabled, onCommit: (n) => m.setSize(n) }),
|
|
287
|
+
/* @__PURE__ */ jsx2(NumberField, { label: "Line height", unit: "\xD7", value: v.lineHeight ?? 1.5, step: 0.05, min: 0.5, max: 4, disabled, onCommit: (n) => m.setLineHeight(n) }),
|
|
288
|
+
/* @__PURE__ */ jsx2(NumberField, { label: "Letter spacing", unit: "em", value: v.letterSpacing ?? 0, step: 0.01, min: -0.5, max: 1, disabled, onCommit: (n) => m.setLetterSpacing(n) })
|
|
289
|
+
] }) });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/typography/index.ts
|
|
293
|
+
export * from "@pixerate/editor/typography";
|
|
294
|
+
export {
|
|
295
|
+
FontPicker,
|
|
296
|
+
FontPickerView,
|
|
297
|
+
TypographyControl,
|
|
298
|
+
useFontPicker
|
|
299
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FontPickerModel, type FontPickerOptions, type FontPickerState } from "@pixerate/editor/typography";
|
|
2
|
+
export interface UseFontPickerOptions extends FontPickerOptions {
|
|
3
|
+
/** Use an existing model (e.g. one an agent tool provider also drives) instead of creating one. */
|
|
4
|
+
model?: FontPickerModel;
|
|
5
|
+
}
|
|
6
|
+
export interface UseFontPickerResult {
|
|
7
|
+
model: FontPickerModel;
|
|
8
|
+
state: FontPickerState;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates (or adopts) a {@link FontPickerModel} and re-renders on its changes. `value` is kept in
|
|
12
|
+
* sync when it changes; `onChange` always calls the latest callback, for changes made in the
|
|
13
|
+
* picker or by its agent tools. With a `provider`, fonts are
|
|
14
|
+
* fetched on mount. The model is not destroyed on unmount (StrictMode re-runs effects), so a model
|
|
15
|
+
* passed in can outlive the component.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFontPicker(options?: UseFontPickerOptions): UseFontPickerResult;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FontPickerModel, type FontPickerOptions, type FontPickerState } from "@pixerate/editor/typography";
|
|
2
|
+
export interface UseFontPickerOptions extends FontPickerOptions {
|
|
3
|
+
/** Use an existing model (e.g. one an agent tool provider also drives) instead of creating one. */
|
|
4
|
+
model?: FontPickerModel;
|
|
5
|
+
}
|
|
6
|
+
export interface UseFontPickerResult {
|
|
7
|
+
model: FontPickerModel;
|
|
8
|
+
state: FontPickerState;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates (or adopts) a {@link FontPickerModel} and re-renders on its changes. `value` is kept in
|
|
12
|
+
* sync when it changes; `onChange` always calls the latest callback, for changes made in the
|
|
13
|
+
* picker or by its agent tools. With a `provider`, fonts are
|
|
14
|
+
* fetched on mount. The model is not destroyed on unmount (StrictMode re-runs effects), so a model
|
|
15
|
+
* passed in can outlive the component.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFontPicker(options?: UseFontPickerOptions): UseFontPickerResult;
|