@pixerate/editor-react 0.106.0 → 0.108.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.
Files changed (39) hide show
  1. package/README.md +1 -1
  2. package/dist/animation-editor/index.cjs +2 -1
  3. package/dist/animation-editor/index.js +1 -1
  4. package/dist/canvas/index.cjs +2 -1
  5. package/dist/canvas/index.js +1 -1
  6. package/dist/chart/ChartDataGrid.d.cts +5 -0
  7. package/dist/chart/ChartDataGrid.d.ts +5 -0
  8. package/dist/chart/ChartInspector.d.cts +1 -1
  9. package/dist/chart/ChartInspector.d.ts +1 -1
  10. package/dist/chart/index.cjs +136 -3
  11. package/dist/chart/index.js +3 -1
  12. package/dist/{chunk-CEV4OEOY.js → chunk-6XI62THS.js} +1 -1
  13. package/dist/{chunk-FUR7LCDM.js → chunk-GJ3IMZQW.js} +152 -5
  14. package/dist/{chunk-Q7LAFHGP.js → chunk-ZQ6H2C7N.js} +2 -1
  15. package/dist/effects/EffectParameters.d.cts +4 -2
  16. package/dist/effects/EffectParameters.d.ts +4 -2
  17. package/dist/effects/index.cjs +2 -1
  18. package/dist/effects/index.js +1 -1
  19. package/dist/image-editor/index.cjs +2 -1
  20. package/dist/image-editor/index.js +2 -2
  21. package/dist/index.cjs +136 -4
  22. package/dist/index.js +3 -3
  23. package/dist/paint-editor/index.cjs +2 -1
  24. package/dist/paint-editor/index.js +1 -1
  25. package/dist/typography/FontPicker.d.cts +48 -0
  26. package/dist/typography/FontPicker.d.ts +48 -0
  27. package/dist/typography/TypographyControl.d.cts +11 -0
  28. package/dist/typography/TypographyControl.d.ts +11 -0
  29. package/dist/typography/index.cjs +328 -0
  30. package/dist/typography/index.d.cts +7 -0
  31. package/dist/typography/index.d.ts +7 -0
  32. package/dist/typography/index.js +299 -0
  33. package/dist/typography/useFontPicker.d.cts +17 -0
  34. package/dist/typography/useFontPicker.d.ts +17 -0
  35. package/dist/vector/index.cjs +2 -1
  36. package/dist/vector/index.js +1 -1
  37. package/dist/video-editor/index.cjs +2 -1
  38. package/dist/video-editor/index.js +1 -1
  39. package/package.json +16 -3
@@ -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;
@@ -4669,10 +4669,11 @@ function EffectParameters({
4669
4669
  onPreset,
4670
4670
  onPresetName,
4671
4671
  renderControlAddon,
4672
+ fonts,
4672
4673
  disabled = false,
4673
4674
  className = ""
4674
4675
  }) {
4675
- const fields = (0, import_react22.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
4676
+ const fields = (0, import_react22.useMemo)(() => (0, import_effects3.effectParameterFields)(description, { fonts }), [description, fonts]);
4676
4677
  const idBase = (0, import_react22.useId)();
4677
4678
  const gesture = import_react22.default.useRef(null);
4678
4679
  const count = import_react22.default.useRef(0);
@@ -3,7 +3,7 @@ import {
3
3
  EffectsBrowser,
4
4
  useEffectDescription,
5
5
  useEffects
6
- } from "../chunk-Q7LAFHGP.js";
6
+ } from "../chunk-ZQ6H2C7N.js";
7
7
  import "../chunk-5LFQ2UQZ.js";
8
8
  import "../chunk-KIRIU53A.js";
9
9
  import "../chunk-3I7FOSLF.js";
@@ -3175,10 +3175,11 @@ function EffectParameters({
3175
3175
  onPreset,
3176
3176
  onPresetName,
3177
3177
  renderControlAddon,
3178
+ fonts,
3178
3179
  disabled = false,
3179
3180
  className = ""
3180
3181
  }) {
3181
- const fields = (0, import_react21.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
3182
+ const fields = (0, import_react21.useMemo)(() => (0, import_effects3.effectParameterFields)(description, { fonts }), [description, fonts]);
3182
3183
  const idBase = (0, import_react21.useId)();
3183
3184
  const gesture = import_react21.default.useRef(null);
3184
3185
  const count = import_react21.default.useRef(0);
@@ -4,7 +4,7 @@ import {
4
4
  EffectsBrowser,
5
5
  useEffectDescription,
6
6
  useEffects
7
- } from "../chunk-Q7LAFHGP.js";
7
+ } from "../chunk-ZQ6H2C7N.js";
8
8
  import "../chunk-5LFQ2UQZ.js";
9
9
  import "../chunk-KIRIU53A.js";
10
10
  import "../chunk-3I7FOSLF.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.106.0",
3
+ "version": "0.108.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -174,6 +174,16 @@
174
174
  "default": "./dist/color/index.cjs"
175
175
  }
176
176
  },
177
+ "./typography": {
178
+ "import": {
179
+ "types": "./dist/typography/index.d.ts",
180
+ "default": "./dist/typography/index.js"
181
+ },
182
+ "require": {
183
+ "types": "./dist/typography/index.d.cts",
184
+ "default": "./dist/typography/index.cjs"
185
+ }
186
+ },
177
187
  "./gradient": {
178
188
  "import": {
179
189
  "types": "./dist/gradient/index.d.ts",
@@ -229,6 +239,9 @@
229
239
  "color": [
230
240
  "./dist/color/index.d.ts"
231
241
  ],
242
+ "typography": [
243
+ "./dist/typography/index.d.ts"
244
+ ],
232
245
  "gradient": [
233
246
  "./dist/gradient/index.d.ts"
234
247
  ]
@@ -245,7 +258,7 @@
245
258
  },
246
259
  "peerDependencies": {
247
260
  "@dagrejs/dagre": "^1.1.8",
248
- "@pixerate/editor": ">=0.161.0 <1.0.0-0",
261
+ "@pixerate/editor": ">=0.163.0 <1.0.0-0",
249
262
  "@tiptap/core": "^2.27.3",
250
263
  "@tiptap/pm": "^2.27.3",
251
264
  "@tiptap/react": "^2.27.3",
@@ -272,7 +285,7 @@
272
285
  "tsup": "^9.0.0",
273
286
  "typescript": "^5.7.3",
274
287
  "vitest": "^5.0.5",
275
- "@pixerate/editor": "0.161.0"
288
+ "@pixerate/editor": "0.163.0"
276
289
  },
277
290
  "scripts": {
278
291
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",