@astryxdesign/cli 0.6.2-canary.9a80beb → 0.6.2-canary.9cfb2b5

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.
@@ -0,0 +1,2875 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {Fragment, useCallback, useRef, useState, type SVGProps} from 'react';
6
+ import * as stylex from '@stylexjs/stylex';
7
+
8
+ import {AspectRatio} from '@astryxdesign/core/AspectRatio';
9
+ import {Card} from '@astryxdesign/core/Card';
10
+ import {Center} from '@astryxdesign/core/Center';
11
+ import {Divider} from '@astryxdesign/core/Divider';
12
+ import {
13
+ DropdownMenu,
14
+ DropdownMenuCheckboxItem,
15
+ DropdownMenuDivider,
16
+ DropdownMenuItem,
17
+ DropdownMenuRadioGroup,
18
+ DropdownMenuRadioItem,
19
+ DropdownMenuSubMenu,
20
+ } from '@astryxdesign/core/DropdownMenu';
21
+ import {Icon, type IconType} from '@astryxdesign/core/Icon';
22
+ import {IconButton} from '@astryxdesign/core/IconButton';
23
+ import {Item} from '@astryxdesign/core/Item';
24
+ import {
25
+ HStack,
26
+ Layout,
27
+ LayoutContent,
28
+ LayoutFooter,
29
+ LayoutHeader,
30
+ LayoutPanel,
31
+ StackItem,
32
+ VStack,
33
+ } from '@astryxdesign/core/Layout';
34
+ import {List} from '@astryxdesign/core/List';
35
+ import {NumberInput} from '@astryxdesign/core/NumberInput';
36
+ import {Popover} from '@astryxdesign/core/Popover';
37
+ import {ResizeHandle, useResizable} from '@astryxdesign/core/Resizable';
38
+ import {Section} from '@astryxdesign/core/Section';
39
+ import {Slider} from '@astryxdesign/core/Slider';
40
+ import {
41
+ SegmentedControl,
42
+ SegmentedControlItem,
43
+ } from '@astryxdesign/core/SegmentedControl';
44
+ import {Selector} from '@astryxdesign/core/Selector';
45
+ import {Heading, Text} from '@astryxdesign/core/Text';
46
+ import {TextArea} from '@astryxdesign/core/TextArea';
47
+ import {TextInput} from '@astryxdesign/core/TextInput';
48
+ import {Thumbnail} from '@astryxdesign/core/Thumbnail';
49
+ import {TreeList, type TreeListItemData} from '@astryxdesign/core/TreeList';
50
+ import {useContainerReveal} from '@astryxdesign/core/hooks';
51
+ import {Theme, defineTheme} from '@astryxdesign/core/theme';
52
+ import {Toolbar} from '@astryxdesign/core/Toolbar';
53
+ import {neutralTheme} from '@astryxdesign/theme-neutral/built';
54
+ import {
55
+ Aperture,
56
+ ArrowDownToLine,
57
+ ArrowUpToLine,
58
+ Baseline,
59
+ CaseLower,
60
+ CaseSensitive,
61
+ CaseUpper,
62
+ Contrast,
63
+ Download,
64
+ // Aliased: a bare `File` would shadow the DOM type the image picker reads.
65
+ File as FileIcon,
66
+ FlipHorizontal2,
67
+ FlipVertical2,
68
+ FoldVertical,
69
+ Frame,
70
+ Grip,
71
+ Group,
72
+ Image as ImageIcon,
73
+ Italic,
74
+ Lock,
75
+ LockOpen,
76
+ Menu,
77
+ Minus,
78
+ PanelBottom,
79
+ PanelLeft,
80
+ PanelLeftRightDashed,
81
+ PanelRight,
82
+ PanelTopBottomDashed,
83
+ Plus,
84
+ Redo2,
85
+ RotateCcw,
86
+ RotateCw,
87
+ Scan,
88
+ SquareSquare,
89
+ SquareRoundCorner,
90
+ Strikethrough,
91
+ TextAlignCenter,
92
+ TextAlignEnd,
93
+ TextAlignJustify,
94
+ TextAlignStart,
95
+ // The angle mark for the Rotation field. Not `Angle`: that landed in
96
+ // lucide after the version this repo pins, and a template has to build
97
+ // against the pack the consumer actually gets.
98
+ TriangleRight,
99
+ Type,
100
+ Underline,
101
+ Undo2,
102
+ X,
103
+ } from 'lucide-react';
104
+
105
+ // =============================================================================
106
+ // Canvas editor theme
107
+ // =============================================================================
108
+
109
+ /**
110
+ * The template keeps its visual overrides in one theme. The artboard is artwork,
111
+ * not app chrome, so that theme is mounted around it with a heavy condensed
112
+ * display face, poster-scale type, and a light palette pinned with `mode="light"`
113
+ * so the poster holds when the editor goes dark.
114
+ *
115
+ * The theme owns what belongs to the poster as a whole — the face, the
116
+ * leading, the uppercase treatment, the frame margins. Per-layer size and
117
+ * tracking are not here: those belong to a layer, and the inspector edits
118
+ * them.
119
+ *
120
+ * Sizes here are artboard pixels, not screen pixels. The artboard always lays
121
+ * out at its native 1080 x 1920 and the zoom control scales the whole frame,
122
+ * so these stay the numbers a designer would type into the inspector.
123
+ */
124
+ const canvasEditorTheme = defineTheme({
125
+ name: 'canvas-editor',
126
+ typography: {
127
+ // Anton is the reference face. It and the fallbacks are all single-weight
128
+ // blacks, so display-1 stays at weight 400 and the poster needs no
129
+ // webfont. Order matters: Impact outranks Arial Narrow because Arial
130
+ // Narrow at 400 renders thin, which reads nothing like a poster.
131
+ heading: {
132
+ family: 'Anton',
133
+ fallbacks: 'Haettenschweiler, Impact, "Arial Narrow", sans-serif',
134
+ },
135
+ },
136
+ tokens: {
137
+ '--text-display-1-leading': '1.02',
138
+ // The two spacing steps the poster lockup uses: the frame margin and the
139
+ // gap under the eyebrow.
140
+ '--spacing-6': '56px',
141
+ '--spacing-3': '24px',
142
+ },
143
+ components: {
144
+ heading: {'type:display-1': {textTransform: 'uppercase'}},
145
+ text: {'type:supporting': {textTransform: 'uppercase'}},
146
+ // The hue rail is a Slider whose track is the only custom paint. Keeping
147
+ // the override in this template's one theme avoids a component-only theme;
148
+ // the theme is mounted narrowly where the hue control and poster need it.
149
+ 'slider-track': {
150
+ base: {
151
+ backgroundImage:
152
+ 'linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)',
153
+ },
154
+ },
155
+ },
156
+ });
157
+
158
+ // =============================================================================
159
+ // Document
160
+ // =============================================================================
161
+
162
+ /** Artboard size in design pixels — a 9:16 social poster. */
163
+ const FRAME = {width: 1080, height: 1920};
164
+
165
+ /**
166
+ * Every icon on this page is 16px.
167
+ *
168
+ * Icon's own scale runs 12/16/20/24, and a page that mixes them reads as
169
+ * drift rather than hierarchy: the rail's layer marks, the inspector's
170
+ * buttons, and the canvas tools are all the same rank of thing. Button sizes
171
+ * its icon slot to 16px at `sm` and `md`, so this is also the size that fits
172
+ * the slot exactly instead of being scaled into it.
173
+ */
174
+ const ICON = 'sm' as const;
175
+
176
+ /**
177
+ * Width of the inspector's label column, in pixels.
178
+ *
179
+ * Wide enough for the longest label the panel uses at the label type size,
180
+ * which is what puts every control on a single left edge.
181
+ */
182
+ const LABEL_COLUMN = 80;
183
+
184
+ /**
185
+ * Widest a document tab is allowed to get, in pixels.
186
+ *
187
+ * A ceiling rather than a fixed width: it holds the longest seeded name with
188
+ * its close showing, and tabs fall below it as the strip fills or the window
189
+ * narrows.
190
+ */
191
+ const TAB_MAX_WIDTH = 164;
192
+
193
+ /**
194
+ * Room the tab strip leaves for the rest of the header, in pixels.
195
+ *
196
+ * Covers the menu button ahead of the strip, the save note and Export button
197
+ * after it, and the bar's own gutters. Generous rather than exact: too small
198
+ * and the strip crowds Export, too large and it gives up room it could have
199
+ * spent on tabs.
200
+ */
201
+ const TAB_STRIP_RESERVE = 320;
202
+
203
+ /**
204
+ * Width below which the inspector is folded away.
205
+ *
206
+ * It is the wider of the two panels and the one whose absence costs least:
207
+ * you can still see the artwork and pick layers without it. Set where the
208
+ * canvas would otherwise be squeezed under the artboard's own width.
209
+ */
210
+ const HIDE_INSPECTOR = '@media (max-width: 1099.98px)';
211
+
212
+ /**
213
+ * Width below which the layer rail folds away too.
214
+ *
215
+ * Later than the inspector, since knowing what is on the canvas survives
216
+ * longer than being able to adjust it.
217
+ */
218
+ const HIDE_RAIL = '@media (max-width: 839.98px)';
219
+
220
+ const PHOTO_LAYER_SRC = '/template-assets/moody-scene-vertical-1.png';
221
+
222
+ type LayerKind = 'text' | 'image';
223
+
224
+ /** What the Appearance submenu sets on the editor chrome. */
225
+ type ThemeMode = 'light' | 'dark' | 'system';
226
+
227
+ /** The menubar's menus, left to right. */
228
+ /** Horizontal and vertical placement of a text layer inside its box. */
229
+ type AlignX = 'start' | 'center' | 'end' | 'justify';
230
+ type AlignY = 'start' | 'center' | 'end';
231
+ type Decoration = 'none' | 'underline' | 'line-through';
232
+ type Transform = 'none' | 'capitalize' | 'uppercase' | 'lowercase';
233
+
234
+ /**
235
+ * The nine CSS filters the image inspector exposes, in the order they are
236
+ * listed there. Kept as one record so a layer carries a single `filters`
237
+ * object and the artboard can build a `filter` string by walking it, rather
238
+ * than nine optional fields that every read has to spell out.
239
+ */
240
+ interface Filters {
241
+ blur: number;
242
+ brightness: number;
243
+ contrast: number;
244
+ grayscale: number;
245
+ hue: number;
246
+ invert: number;
247
+ opacity: number;
248
+ saturate: number;
249
+ sepia: number;
250
+ }
251
+
252
+ /** A drop shadow, in the four numbers the shadow popover edits. */
253
+ interface Shadow {
254
+ x: number;
255
+ y: number;
256
+ blur: number;
257
+ spread: number;
258
+ color: string;
259
+ }
260
+
261
+ interface Layer {
262
+ id: string;
263
+ name: string;
264
+ kind: LayerKind;
265
+ x: number;
266
+ y: number;
267
+ width: number;
268
+ height: number;
269
+ rotation: number;
270
+ /**
271
+ * Padding is two numbers, not one: a poster's inset is almost never square,
272
+ * and a single field makes the common case — wide margins, tight leading
273
+ * above and below — impossible to express without opening a per-side
274
+ * editor. Inline is the left/right pair, block the top/bottom, matching the
275
+ * axis names CSS uses for the same thing.
276
+ */
277
+ paddingInline: number;
278
+ paddingBlock: number;
279
+ radius: number;
280
+ isLocked: boolean;
281
+ /** Copy for a text layer; the alt text for an image layer. */
282
+ content: string;
283
+ /** Undefined means the slot is empty and the field shows its placeholder. */
284
+ border?: string;
285
+ fill?: string;
286
+ /** The shadow cast by the layer's box. */
287
+ shadow?: Shadow;
288
+ /** Type settings. Only text layers carry them, and only they show them. */
289
+ family?: string;
290
+ weight?: string;
291
+ color?: string;
292
+ size?: number;
293
+ line?: number;
294
+ tracking?: number;
295
+ alignX?: AlignX;
296
+ alignY?: AlignY;
297
+ isItalic?: boolean;
298
+ decoration?: Decoration;
299
+ transform?: Transform;
300
+ /**
301
+ * The shadow cast by the glyphs, which is a different property from the
302
+ * one in Styles: that one is the box's, this one is the type's, and a
303
+ * layer can carry both.
304
+ */
305
+ textShadow?: Shadow;
306
+ stroke?: number;
307
+ /** Image settings. Only image layers carry them. */
308
+ fit?: string;
309
+ filters?: Filters;
310
+ }
311
+
312
+ const NO_SHADOW: Shadow = {x: 0, y: 0, blur: 0, spread: 0, color: '#000000'};
313
+
314
+ const NO_FILTERS: Filters = {
315
+ blur: 0,
316
+ brightness: 100,
317
+ contrast: 100,
318
+ grayscale: 0,
319
+ hue: 0,
320
+ invert: 0,
321
+ opacity: 100,
322
+ saturate: 100,
323
+ sepia: 0,
324
+ };
325
+
326
+ /** An open document in the strip above the menubar. */
327
+ interface DocumentTabData {
328
+ id: string;
329
+ name: string;
330
+ icon: IconType;
331
+ }
332
+
333
+ // Every tab carries the same mark: varying it per document would imply a
334
+ // distinction the editor does not make, and a strip of mixed glyphs is harder
335
+ // to scan than a strip of one. A tab stands for an open file, so the file mark
336
+ // is the literal one; the frame mark belongs to the layer groups, where it
337
+ // names an actual container.
338
+ const INITIAL_TABS: DocumentTabData[] = [
339
+ {id: 'poster', name: 'Salzburg poster', icon: FileIcon},
340
+ {id: 'brand', name: 'Brand sheet', icon: FileIcon},
341
+ {id: 'draft', name: 'Untitled draft', icon: FileIcon},
342
+ ];
343
+
344
+ const INITIAL_LAYERS: Layer[] = [
345
+ {
346
+ id: 'headline',
347
+ name: 'Headline',
348
+ kind: 'text',
349
+ x: 56,
350
+ y: 136,
351
+ width: 968,
352
+ height: 300,
353
+ rotation: 0,
354
+ paddingInline: 0,
355
+ paddingBlock: 0,
356
+ radius: 0,
357
+ isLocked: false,
358
+ content: 'A weekend in Salzburg',
359
+ fill: '#111111',
360
+ family: 'Anton',
361
+ weight: 'Regular',
362
+ color: '#111111',
363
+ size: 112,
364
+ line: 100,
365
+ tracking: -2,
366
+ alignX: 'start',
367
+ alignY: 'start',
368
+ isItalic: false,
369
+ decoration: 'none',
370
+ transform: 'uppercase',
371
+ stroke: 0,
372
+ },
373
+ {
374
+ id: 'dateline',
375
+ name: 'Dateline',
376
+ kind: 'text',
377
+ x: 56,
378
+ y: 56,
379
+ width: 968,
380
+ height: 56,
381
+ rotation: 0,
382
+ paddingInline: 0,
383
+ paddingBlock: 0,
384
+ radius: 0,
385
+ isLocked: false,
386
+ content: 'March 14–16 · Austria',
387
+ family: 'Inter Tight',
388
+ weight: 'Medium',
389
+ color: '#111111',
390
+ size: 26,
391
+ line: 120,
392
+ tracking: 32,
393
+ alignX: 'center',
394
+ alignY: 'start',
395
+ isItalic: false,
396
+ decoration: 'none',
397
+ transform: 'uppercase',
398
+ stroke: 0,
399
+ },
400
+ {
401
+ id: 'photo',
402
+ name: 'Photo',
403
+ kind: 'image',
404
+ x: 0,
405
+ y: 0,
406
+ width: 1080,
407
+ height: 1920,
408
+ rotation: 0,
409
+ paddingInline: 0,
410
+ paddingBlock: 0,
411
+ radius: 0,
412
+ isLocked: true,
413
+ content: 'The Salzach river and old town rooftops at dusk',
414
+ fit: 'Cover',
415
+ filters: NO_FILTERS,
416
+ },
417
+ ];
418
+
419
+ const LAYER_ICON = {text: Type, image: ImageIcon} as const;
420
+
421
+ /** The inspector's vertical alignment, in the words a Stack uses for it. */
422
+ const V_ALIGN = {start: 'start', center: 'center', end: 'end'} as const;
423
+
424
+ // =============================================================================
425
+ // Field glyphs
426
+ // =============================================================================
427
+
428
+ /**
429
+ * Draws a letterform sized to the icon grid.
430
+ *
431
+ * A design tool names a numeric field from inside it — the X sits in the box
432
+ * with the number, not in a segment bolted to its edge — so the row reads as
433
+ * one control. That is the input's start-icon slot, which takes an SVG
434
+ * component; Lucide ships no letterforms, so these are drawn on the same 24px
435
+ * grid Lucide uses. They inherit `currentColor` and the slot's sizing, so a
436
+ * letter and an icon are interchangeable in the same position.
437
+ */
438
+ function glyph(char: string): IconType {
439
+ const Glyph = (props: SVGProps<SVGSVGElement>) => (
440
+ <svg viewBox="0 0 24 24" {...props}>
441
+ <text
442
+ x={12}
443
+ y={12}
444
+ fill="currentColor"
445
+ // Two-letter glyphs get the smaller size so both fit the same box.
446
+ fontSize={char.length > 1 ? 13 : 17}
447
+ fontWeight={500}
448
+ textAnchor="middle"
449
+ dominantBaseline="central">
450
+ {char}
451
+ </text>
452
+ </svg>
453
+ );
454
+ Glyph.displayName = `Glyph(${char})`;
455
+ return Glyph;
456
+ }
457
+
458
+ /**
459
+ * Built once at module scope so each glyph keeps a stable component identity.
460
+ *
461
+ * Only the axis fields are lettered. A letter is the right mark when the
462
+ * field names a *dimension* a reader already has a letter for — X, Y, W, H
463
+ * are how the value is written down anyway. Where the pack has a drawing of
464
+ * the thing being set (an angle, a pair of insets, a rounded corner), the
465
+ * drawing says it in one glance and the letter makes you translate.
466
+ */
467
+ const GLYPH = {
468
+ x: glyph('X'),
469
+ y: glyph('Y'),
470
+ width: glyph('W'),
471
+ height: glyph('H'),
472
+ } as const;
473
+
474
+ /**
475
+ * Each preset carries its own icon. A library where every row shows the same
476
+ * glyph is a list you have to read word by word; distinct marks let the eye
477
+ * find the row it wants.
478
+ */
479
+ const EFFECT_PRESETS: {label: string; icon: IconType}[] = [
480
+ {label: 'Grain overlay', icon: Aperture},
481
+ {label: 'Halftone', icon: Grip},
482
+ {label: 'Duotone teal', icon: Contrast},
483
+ ];
484
+
485
+ /**
486
+ * The icon-only segmented rows in the text inspector. Each entry keeps its
487
+ * spoken label next to its glyph, because `isLabelHidden` hides the text but
488
+ * still needs it for the accessible name.
489
+ */
490
+ const ALIGN_X: {value: AlignX; label: string; icon: IconType}[] = [
491
+ {value: 'start', label: 'Align left', icon: TextAlignStart},
492
+ {value: 'center', label: 'Align centre', icon: TextAlignCenter},
493
+ {value: 'end', label: 'Align right', icon: TextAlignEnd},
494
+ {value: 'justify', label: 'Justify', icon: TextAlignJustify},
495
+ ];
496
+
497
+ const ALIGN_Y: {value: AlignY; label: string; icon: IconType}[] = [
498
+ {value: 'start', label: 'Align top', icon: ArrowUpToLine},
499
+ {value: 'center', label: 'Align middle', icon: FoldVertical},
500
+ {value: 'end', label: 'Align bottom', icon: ArrowDownToLine},
501
+ ];
502
+
503
+ const DECORATIONS: {value: Decoration; label: string; icon: IconType}[] = [
504
+ {value: 'none', label: 'No decoration', icon: CaseSensitive},
505
+ {value: 'underline', label: 'Underline', icon: Underline},
506
+ {value: 'line-through', label: 'Strikethrough', icon: Strikethrough},
507
+ ];
508
+
509
+ const TRANSFORMS: {value: Transform; label: string; icon: IconType}[] = [
510
+ {value: 'none', label: 'As typed', icon: Minus},
511
+ {value: 'capitalize', label: 'Capitalise', icon: CaseSensitive},
512
+ {value: 'uppercase', label: 'Uppercase', icon: CaseUpper},
513
+ {value: 'lowercase', label: 'Lowercase', icon: CaseLower},
514
+ ];
515
+
516
+ /**
517
+ * The nine image filters, with the range and unit each one is stated in.
518
+ * `max` is what the slider runs to rather than what CSS allows — brightness
519
+ * and saturate go past 200%, but a rail that reaches 500 spends most of its
520
+ * travel somewhere nobody drags to.
521
+ */
522
+ const FILTERS: {
523
+ key: keyof Filters;
524
+ label: string;
525
+ max: number;
526
+ unit: string;
527
+ }[] = [
528
+ {key: 'blur', label: 'Blur', max: 20, unit: 'px'},
529
+ {key: 'brightness', label: 'Brightness', max: 200, unit: '%'},
530
+ {key: 'contrast', label: 'Contrast', max: 200, unit: '%'},
531
+ {key: 'grayscale', label: 'Grayscale', max: 100, unit: '%'},
532
+ {key: 'hue', label: 'Hue', max: 360, unit: 'deg'},
533
+ {key: 'invert', label: 'Invert', max: 100, unit: '%'},
534
+ {key: 'opacity', label: 'Opacity', max: 100, unit: '%'},
535
+ {key: 'saturate', label: 'Saturate', max: 200, unit: '%'},
536
+ {key: 'sepia', label: 'Sepia', max: 100, unit: '%'},
537
+ ];
538
+
539
+ const ZOOM_OPTIONS = [
540
+ {value: '0.25', label: '25%'},
541
+ {value: '0.4', label: '40%'},
542
+ {value: '0.6', label: '60%'},
543
+ {value: '1', label: '100%'},
544
+ ];
545
+
546
+ const FONT_OPTIONS = ['Anton', 'Archivo Black', 'Bebas Neue', 'Inter Tight'];
547
+ const WEIGHT_OPTIONS = ['Regular', 'Medium', 'Semibold', 'Bold'];
548
+
549
+ /** What the Insert submenu can add to the artboard. */
550
+ const INSERT_ITEMS: {label: string; icon: IconType}[] = [
551
+ {label: 'Frame', icon: Frame},
552
+ {label: 'Group', icon: Group},
553
+ {label: 'Text', icon: Type},
554
+ {label: 'Image', icon: ImageIcon},
555
+ ];
556
+
557
+ /** Written once: the Export button and the File menu offer the same three. */
558
+ const EXPORT_FORMATS = [
559
+ 'PNG · 1080 × 1920',
560
+ 'JPG · 1080 × 1920',
561
+ 'PDF · print ready',
562
+ ];
563
+
564
+ const EXPORT_MENU = EXPORT_FORMATS.map(label => ({label}));
565
+
566
+ // =============================================================================
567
+ // Colour
568
+ // =============================================================================
569
+
570
+ /** A colour as the picker holds it: hue 0–360, saturation and value 0–100. */
571
+ interface Hsv {
572
+ h: number;
573
+ s: number;
574
+ v: number;
575
+ }
576
+
577
+ /**
578
+ * The picker thinks in HSV because that is the shape of its two controls — a
579
+ * hue rail and a saturation/value plane — while every value it reads and
580
+ * writes is a hex string. These convert between the two.
581
+ */
582
+ function hsvToHex({h, s, v}: Hsv): string {
583
+ const channel = (n: number) => {
584
+ const k = (n + h / 60) % 6;
585
+ const value =
586
+ (v / 100) * (1 - (s / 100) * Math.max(0, Math.min(k, 4 - k, 1)));
587
+ return Math.round(value * 255)
588
+ .toString(16)
589
+ .padStart(2, '0');
590
+ };
591
+ return `#${channel(5)}${channel(3)}${channel(1)}`;
592
+ }
593
+
594
+ function hexToHsv(hex: string): Hsv {
595
+ const parsed = /^#?([\da-f]{6})$/i.exec(hex.trim());
596
+ if (!parsed) {
597
+ return {h: 0, s: 0, v: 0};
598
+ }
599
+ const int = parseInt(parsed[1], 16);
600
+ const r = ((int >> 16) & 255) / 255;
601
+ const g = ((int >> 8) & 255) / 255;
602
+ const b = (int & 255) / 255;
603
+ const max = Math.max(r, g, b);
604
+ const span = max - Math.min(r, g, b);
605
+ let h = 0;
606
+ if (span !== 0) {
607
+ if (max === r) {
608
+ h = ((g - b) / span) % 6;
609
+ } else if (max === g) {
610
+ h = (b - r) / span + 2;
611
+ } else {
612
+ h = (r - g) / span + 4;
613
+ }
614
+ }
615
+ return {
616
+ h: (Math.round(h * 60) + 360) % 360,
617
+ s: max === 0 ? 0 : Math.round((span / max) * 100),
618
+ v: Math.round(max * 100),
619
+ };
620
+ }
621
+
622
+ /**
623
+ * Drag tracking for the saturation/value plane, which is the one control
624
+ * here that has to be painted: it is two axes at once, and no slider is.
625
+ * Reports the pointer as a fraction of the element on press and for as long
626
+ * as the drag lasts.
627
+ *
628
+ * Pointer capture is what makes the drag survive leaving the element: a fast
629
+ * diagonal out of the plane keeps tracking instead of stopping dead at the
630
+ * edge, which is the difference between a picker that feels attached to the
631
+ * cursor and one that keeps dropping it.
632
+ */
633
+ function usePointerTrack(onTrack: (x: number, y: number) => void) {
634
+ const read = useCallback(
635
+ (event: React.PointerEvent<HTMLElement>) => {
636
+ const box = event.currentTarget.getBoundingClientRect();
637
+ onTrack(
638
+ Math.min(1, Math.max(0, (event.clientX - box.left) / box.width)),
639
+ Math.min(1, Math.max(0, (event.clientY - box.top) / box.height)),
640
+ );
641
+ },
642
+ [onTrack],
643
+ );
644
+ return {
645
+ onPointerDown: (event: React.PointerEvent<HTMLElement>) => {
646
+ event.currentTarget.setPointerCapture(event.pointerId);
647
+ read(event);
648
+ },
649
+ onPointerMove: (event: React.PointerEvent<HTMLElement>) => {
650
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) {
651
+ read(event);
652
+ }
653
+ },
654
+ };
655
+ }
656
+
657
+ /**
658
+ * Builds the `filter` shorthand from the nine values the inspector edits.
659
+ *
660
+ * Only the ones that are off their neutral point are emitted: a filter list
661
+ * of nine no-op functions still forces the image onto its own composited
662
+ * layer, and a poster that is only ever blurred should not pay for the other
663
+ * eight.
664
+ */
665
+ function filterCss(filters: Filters): string {
666
+ const parts = [
667
+ ['blur', filters.blur, 0, 'px'],
668
+ ['brightness', filters.brightness, 100, '%'],
669
+ ['contrast', filters.contrast, 100, '%'],
670
+ ['grayscale', filters.grayscale, 0, '%'],
671
+ ['hue-rotate', filters.hue, 0, 'deg'],
672
+ ['invert', filters.invert, 0, '%'],
673
+ ['opacity', filters.opacity, 100, '%'],
674
+ ['saturate', filters.saturate, 100, '%'],
675
+ ['sepia', filters.sepia, 0, '%'],
676
+ ] as const;
677
+ const active = parts
678
+ .filter(([, value, neutral]) => value !== neutral)
679
+ .map(([name, value, , unit]) => `${name}(${value}${unit})`);
680
+ return active.length > 0 ? active.join(' ') : 'none';
681
+ }
682
+
683
+ /** `text-shadow` takes no spread, so a text layer's shadow drops it. */
684
+ function shadowCss(shadow: Shadow | undefined): string {
685
+ return shadow
686
+ ? `${shadow.x}px ${shadow.y}px ${shadow.blur}px ${shadow.color}`
687
+ : 'none';
688
+ }
689
+
690
+ // =============================================================================
691
+ // Styles
692
+ // =============================================================================
693
+
694
+ const styles = stylex.create({
695
+ // Zoom the way a design tool does: lay the artboard out once at its native
696
+ // size and scale the painted result. Type and spacing stay in artboard
697
+ // pixels, and the poster gets no reflow between zoom steps.
698
+ artboard: (scale: number) => ({
699
+ width: FRAME.width,
700
+ transform: `scale(${scale})`,
701
+ transformOrigin: 'top left',
702
+ }),
703
+ // Type the inspector owns. Size and tracking can't be theme tokens: they
704
+ // belong to a layer, not to the poster, and they change per keystroke.
705
+ // Tracking is a percentage of the type size, the way a design tool states
706
+ // it, so it holds when the size changes.
707
+ type: (
708
+ size: number,
709
+ tracking: number,
710
+ line: number,
711
+ color: string,
712
+ stroke: number,
713
+ shadow: string,
714
+ ) => ({
715
+ fontSize: `${size}px`,
716
+ letterSpacing: `${tracking / 100}em`,
717
+ lineHeight: `${line}%`,
718
+ color,
719
+ WebkitTextStrokeWidth: stroke > 0 ? `${stroke}px` : null,
720
+ WebkitTextStrokeColor: stroke > 0 ? color : null,
721
+ textShadow: shadow,
722
+ }),
723
+ // AspectRatio's `fit` stretches every direct child to fill the box, so a
724
+ // second one would flow below the photo and clip. Taking the text layers
725
+ // out of flow is what stacks them over it, the way they sit on an artboard.
726
+ textLayers: {position: 'absolute', inset: 0},
727
+ // A Card given a height prop turns into a scroll container, which is the
728
+ // right default for a card holding more copy than fits. This one is a
729
+ // viewport onto an artboard that is deliberately larger than its frame —
730
+ // the artboard lays out at 1080 wide at every zoom step and the frame
731
+ // scales it — so it clips instead. `clip` over `hidden`: nothing here
732
+ // should scroll, including the quiet scroll that focusing a clipped child
733
+ // would otherwise cause.
734
+ artboardFrame: {overflow: 'clip'},
735
+ // The canvas pans in both axes, which centring normally breaks.
736
+ //
737
+ // A scroll port that centres with `justify-content`/`align-items` has no
738
+ // scrollable overflow on the *start* side: once the artboard is bigger than
739
+ // the port, its top-left is pushed out and nothing can scroll back to it.
740
+ // Auto margins centre the same way while leaving that overflow reachable —
741
+ // when there is spare room they split it, and when there is none they
742
+ // resolve to zero instead of pushing.
743
+ //
744
+ // The stage sizes to whichever is larger, the port or the artboard, so the
745
+ // scrollbars describe the artboard rather than the port.
746
+ // The one part HStack has no prop for; the rest of the stage — the flex
747
+ // box, the max-content sizing and the 100% floor on the block axis — says
748
+ // itself in props.
749
+ canvasStage: {minWidth: '100%'},
750
+ artboardCentered: {margin: 'auto'},
751
+ // Concentric corners. The card rounds to --radius-container and holds one
752
+ // spacing step of padding, so the controls inside it round to the
753
+ // difference: an inner corner struck from the same centre as the outer one
754
+ // rather than a rounder curve cutting across it. Stated as the subtraction
755
+ // so it still holds if either token moves.
756
+ toolBarControl: {
757
+ borderRadius: 'calc(var(--radius-container) - var(--spacing-1))',
758
+ },
759
+ // The trailing control is a ghost, so edge compensation pulls it out to the
760
+ // card's edge to optically align its label. That is the right call when the
761
+ // control is the only thing in a container, but here it leaves the bar with
762
+ // a gutter on the left and none on the right. Putting the step back matches
763
+ // the two ends. It rides on the control itself rather than a wrapper — a
764
+ // div whose only job is one margin is a div the control can absorb.
765
+ toolBarTrailing: {
766
+ marginInlineEnd: 'var(--spacing-2)',
767
+ },
768
+ // A vertical Divider is `height: 100%`, and a flex row that centres its
769
+ // items gives a percentage height nothing to resolve against — the rule
770
+ // collapses to nothing and the tool bar loses its groups. Stretching the
771
+ // item is what gives it a height; the inset then pulls it back off the
772
+ // buttons so it separates them rather than boxing them in.
773
+ toolBarRule: {
774
+ alignSelf: 'stretch',
775
+ height: 'auto',
776
+ marginBlock: 'var(--spacing-1)',
777
+ },
778
+ // Give the header bar its own inline padding, so the Export button stops
779
+ // at a margin instead of the window edge.
780
+ //
781
+ // The layout under it is set to zero padding — the panels have to reach
782
+ // the edges — and a Toolbar takes its inline padding from whatever
783
+ // container it sits in, so it inherits that zero. The fix has to arrive as
784
+ // Section's padding token rather than as `paddingInline`: Section renders
785
+ // an outer wrapper that escapes its parent's gutter and an inner one that
786
+ // holds the padding, xstyle lands on the outer, and padding set there
787
+ // makes the bar bleed 12px past the window rather than inset its contents.
788
+ // The token is read on the inner element, where it also republishes
789
+ // --container-padding-inline-*. That second effect is the one that
790
+ // matters: it feeds the toolbar's edge compensation, which pulls ghost
791
+ // triggers back out by their own padding so the menu button's *icon* lines
792
+ // up on the gutter while its hover box still bleeds into it.
793
+ headerBar: {
794
+ // Named so the tab strip can size against the bar rather than the window:
795
+ // cqw tracks this element, so it stays right if the bar ever stops being
796
+ // full-bleed, and it excludes a scrollbar the way vw does not.
797
+ containerType: 'inline-size',
798
+ containerName: 'editor-header',
799
+ },
800
+ // The menu, the tabs and the add button. It has to be allowed to shrink or
801
+ // the strip's own ceiling never binds — a flex item defaults to min-width
802
+ // auto, which floors it at the tabs' combined width.
803
+ headerLead: {
804
+ minWidth: 0,
805
+ },
806
+ // The open-document strip above the menubar. It scrolls rather than wraps:
807
+ // a second row of tabs would move the menubar down, and the whole point of
808
+ // the strip is that the chrome above the canvas has a fixed height.
809
+ tabStrip: {
810
+ minWidth: 0,
811
+ flexShrink: 1,
812
+ // The strip has to cap itself, which is the one thing HStack's maxWidth
813
+ // cannot say for it. It sits in Toolbar's start slot, and that slot is
814
+ // not the one built to give way — only the centre slot carries
815
+ // `min-width: 0`, so a start slot grows to its content and pushes the bar
816
+ // wider instead of squeezing. Widening the start slot in core would
817
+ // change every toolbar's behaviour to suit one page's tab strip, so the
818
+ // cap arrives as a maxWidth prop and this only has to let it shrink.
819
+ //
820
+ // The strip is short enough that a scrollbar would eat most of it, and
821
+ // the tabs are draggable-looking targets already.
822
+ scrollbarWidth: 'none',
823
+ },
824
+ // Folded by width, not by the View menu's toggles. Those record what the
825
+ // user asked for; this records whether there is room to honour it, so the
826
+ // panel comes back on its own when the window grows rather than leaving
827
+ // the toggle switched off. Applied to the handle as well as the panel, or
828
+ // a grip is left behind on a seam with nothing on the other side.
829
+ foldsAtRail: {display: {default: null, [HIDE_RAIL]: 'none'}},
830
+ foldsAtInspector: {display: {default: null, [HIDE_INSPECTOR]: 'none'}},
831
+ // A short rule, not a full-height one: the strip has no columns to divide,
832
+ // it only needs the smallest mark that reads as "these are separate tabs".
833
+ // A vertical Divider takes its height from the row unless given one, and a
834
+ // centred 16px keeps it clear of both the tab fill and the bar's own edges.
835
+ tabRule: {height: 16, alignSelf: 'center', flexShrink: 0},
836
+ tabRuleHidden: {visibility: 'hidden'},
837
+ // Everything a tab needs beyond an Item: a width ceiling and a tighter
838
+ // measure. Item brings the 28px box, the radius, the fill when selected,
839
+ // the inline padding, and the ellipsis on a string label.
840
+ tab: {
841
+ // Item spaces a list row, where 8px either side of the label is right
842
+ // because the rows are stacked and the eye reads down a column. A tab is
843
+ // read across, and at this ceiling those three 8px channels cost the
844
+ // name six characters: "Salzburg poster" needs 102px and would get 96.
845
+ // Back to the measure the strip had before, which clears it with 2px
846
+ // spare — the close end tighter still, because a bare 20px icon carries
847
+ // its own inset and an equal gap there reads as a wider one.
848
+ gap: 'var(--spacing-1-5)',
849
+ paddingInlineEnd: 'var(--spacing-1)',
850
+ // A width the tab is allowed to shrink under, which makes it a ceiling:
851
+ // it never grows, so it sits at this size until something squeezes it.
852
+ // It has to be `width` and not `flexBasis` — a basis does not raise an
853
+ // item's max-content contribution, so the strip above would size itself
854
+ // to the tabs' *content* and then squeeze them back under their basis,
855
+ // leaving every tab short even with the bar half empty.
856
+ flexGrow: 0,
857
+ flexShrink: 1,
858
+ width: TAB_MAX_WIDTH,
859
+ // A floor, so a crowded strip scrolls instead of grinding every tab down
860
+ // to an unreadable sliver. Enough for the mark, a few characters and the
861
+ // close; past it the strip's own overflow takes over.
862
+ minWidth: 96,
863
+ },
864
+ // Item marks a selected row with --color-accent-muted, which this editor's
865
+ // theme resolves to #262626 in dark — the exact colour of the header bar
866
+ // the strip sits on, so the open document would read as no document at
867
+ // all. The muted background is a step off the bar in both schemes, and it
868
+ // is the fill hover already uses, so selection and hover agree.
869
+ tabSelected: {backgroundColor: 'var(--color-background-muted)'},
870
+ // Item paints a fill when selected but leaves hover to the list that owns
871
+ // it, and the strip is not a list. The tab is a target on its own, so it
872
+ // answers the pointer itself.
873
+ tabHover: {
874
+ backgroundColor: {
875
+ default: 'transparent',
876
+ ':hover': 'var(--color-background-muted)',
877
+ },
878
+ },
879
+ // Hold the label column at its set width. The fields beside it carry the
880
+ // flex min-width reset, so without this the row spends its shrinkage on
881
+ // whichever item gives way first and each label ends up a different width —
882
+ // which is exactly the shared left edge the panel is built around.
883
+ labelColumn: {flexShrink: 0},
884
+ // An action nested *inside* a row, as opposed to one standing beside a
885
+ // field. This is the only place a control drops below the 28px the rest
886
+ // of the panel aligns to.
887
+ //
888
+ // It has to: the smallest IconButton is 28px, which is the whole row's
889
+ // height budget once compact density adds its 4px above and below, so a
890
+ // rail of 28px rows cannot hold a 28px button. Hence a bare button — no
891
+ // painted box, no size floor, just a hit area around the icon. It stays a
892
+ // <button> because the lock is a real action that has to remain
893
+ // keyboard-reachable; it was the Button *component's* minimum that had to
894
+ // go, not the element.
895
+ itemAction: {
896
+ // A full 28px button laid out as 20px. The row is 28px with a step of
897
+ // padding, so a control its own height would push it to 36; pulling that
898
+ // same step off every edge hands the padding back to the layout. The
899
+ // glyph does not move — centred in a 28px box that now starts a step
900
+ // early, it lands exactly where a 20px button would have put it — but
901
+ // the target it sits in is the full 28px the pointer expects.
902
+ //
903
+ // Stated against the row's own padding token rather than as -4px, so the
904
+ // two cannot drift apart.
905
+ margin: 'calc(-1 * var(--spacing-1))',
906
+ // Icon tokens, not the text ones a ghost Button reaches for. The two
907
+ // agree at the theme root but this editor's theme separates them, and a
908
+ // lock keyed to the text ramp came out darker than the layer glyphs
909
+ // sitting beside it on the same row.
910
+ color: {
911
+ default: 'var(--color-icon-secondary)',
912
+ ':hover': 'var(--color-icon-primary)',
913
+ ':disabled': 'var(--color-icon-disabled)',
914
+ },
915
+ },
916
+ // The colour chip that opens a picker. Square at the field's own height
917
+ // and rounded to the field's own corner, so it reads as another control
918
+ // on the row rather than a tile dropped beside one. --radius-element is
919
+ // the token an input rounds to; --radius-inner is a step tighter and
920
+ // reads as a different family at this size.
921
+ swatch: {
922
+ width: 'var(--spacing-7)',
923
+ height: 'var(--spacing-7)',
924
+ flexShrink: 0,
925
+ padding: 0,
926
+ borderWidth: '1px',
927
+ borderStyle: 'solid',
928
+ borderColor: 'var(--color-border-emphasized)',
929
+ borderRadius: 'var(--radius-element)',
930
+ cursor: 'pointer',
931
+ // A chip for an unset slot reads as empty rather than as black.
932
+ backgroundImage:
933
+ 'linear-gradient(45deg, transparent 45%, var(--color-border-emphasized) 45% 55%, transparent 55%)',
934
+ },
935
+ swatchFilled: {backgroundImage: 'none'},
936
+ // The saturation/value plane. White runs left to right and black bottom to
937
+ // top over the pure hue, so every point in the square is one colour at
938
+ // that hue.
939
+ plane: {
940
+ position: 'relative',
941
+ height: 160,
942
+ borderRadius: 'var(--radius-inner)',
943
+ backgroundImage:
944
+ 'linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)',
945
+ cursor: 'crosshair',
946
+ touchAction: 'none',
947
+ },
948
+ // Both thumbs are positioned by their centre, so the translate is what
949
+ // keeps them on the value rather than beside it.
950
+ thumb: {
951
+ position: 'absolute',
952
+ width: 'var(--spacing-3)',
953
+ height: 'var(--spacing-3)',
954
+ borderWidth: '2px',
955
+ borderStyle: 'solid',
956
+ borderColor: '#fff',
957
+ borderRadius: 'var(--radius-full)',
958
+ boxShadow: '0 0 0 1px rgba(0, 0, 0, 0.35)',
959
+ transform: 'translate(-50%, -50%)',
960
+ pointerEvents: 'none',
961
+ },
962
+ planeStack: {display: 'grid', gap: 'var(--spacing-3)'},
963
+ // Filter rows put the slider beside the number rather than under it, so
964
+ // nine of them still read as one column.
965
+ //
966
+ // The slider takes the fill and the number trails it at a fixed width: the
967
+ // slider is the control being used and the number is the read-out, so the
968
+ // draggable track gets the room. Fixed rather than hugging, so nine
969
+ // read-outs share one right edge instead of stepping in and out as their
970
+ // values change width.
971
+ filterValue: {flexShrink: 0, width: 64},
972
+ // Thumbnail ships at 64px for media grids; here it is a control sitting in
973
+ // a row of 28px controls, so it takes the same box as the colour swatches.
974
+ // Width alone is enough — the picture is kept square by an aspect ratio.
975
+ sourceThumbnail: {width: 'var(--spacing-7)'},
976
+ });
977
+
978
+ /**
979
+ * The enumerable half of a text layer's styling. These are closed sets, so
980
+ * they compile to static classes picked by key rather than to a custom
981
+ * property set at runtime.
982
+ */
983
+ const typeCase = stylex.create({
984
+ none: {textTransform: 'none'},
985
+ capitalize: {textTransform: 'capitalize'},
986
+ uppercase: {textTransform: 'uppercase'},
987
+ lowercase: {textTransform: 'lowercase'},
988
+ });
989
+
990
+ const typeLine = stylex.create({
991
+ none: {textDecorationLine: 'none'},
992
+ underline: {textDecorationLine: 'underline'},
993
+ 'line-through': {textDecorationLine: 'line-through'},
994
+ });
995
+
996
+ const typeSlant = stylex.create({
997
+ normal: {fontStyle: 'normal'},
998
+ italic: {fontStyle: 'italic'},
999
+ });
1000
+
1001
+ const typeAlign = stylex.create({
1002
+ start: {textAlign: 'start'},
1003
+ center: {textAlign: 'center'},
1004
+ end: {textAlign: 'end'},
1005
+ justify: {textAlign: 'justify'},
1006
+ });
1007
+
1008
+ /** Runtime values the painted controls need, kept out of the static sheet. */
1009
+ const paint = stylex.create({
1010
+ photo: (filter: string) => ({filter}),
1011
+ hue: (h: number) => ({backgroundColor: `hsl(${h} 100% 50%)`}),
1012
+ planeThumb: (s: number, v: number) => ({
1013
+ insetInlineStart: `${s}%`,
1014
+ insetBlockStart: `${100 - v}%`,
1015
+ }),
1016
+ fill: (color: string) => ({backgroundColor: color}),
1017
+ });
1018
+
1019
+ // =============================================================================
1020
+ // Panel building blocks
1021
+ // =============================================================================
1022
+
1023
+ /**
1024
+ * One inspector row: a fixed label column, then the controls for it.
1025
+ *
1026
+ * The label column is a set width rather than intrinsic so that every control
1027
+ * in the panel starts on the same vertical line, whatever its label is
1028
+ * called. That shared edge is what lets the eye run down the column and
1029
+ * compare values instead of hunting for each field.
1030
+ */
1031
+ function InspectorRow({
1032
+ label,
1033
+ hAlign,
1034
+ labelWidth = LABEL_COLUMN,
1035
+ children,
1036
+ }: {
1037
+ label: string;
1038
+ /** Set to "end" for a row of bare buttons, which have no field to fill. */
1039
+ hAlign?: 'start' | 'end';
1040
+ /** Narrower inside a popover, where the panel's column would not fit. */
1041
+ labelWidth?: number;
1042
+ children: React.ReactNode;
1043
+ }) {
1044
+ return (
1045
+ <HStack gap={2} vAlign="center">
1046
+ <HStack width={labelWidth} xstyle={styles.labelColumn}>
1047
+ <Text type="label" color="secondary" maxLines={1}>
1048
+ {label}
1049
+ </Text>
1050
+ </HStack>
1051
+ <StackItem size="fill">
1052
+ <HStack gap={1} vAlign="center" hAlign={hAlign}>
1053
+ {children}
1054
+ </HStack>
1055
+ </StackItem>
1056
+ </HStack>
1057
+ );
1058
+ }
1059
+
1060
+ /** A numeric field that names itself from inside, like X 40. */
1061
+ function AxisInput({
1062
+ icon,
1063
+ label,
1064
+ value,
1065
+ onChange,
1066
+ }: {
1067
+ icon: IconType;
1068
+ label: string;
1069
+ value: number;
1070
+ onChange: (next: number) => void;
1071
+ }) {
1072
+ return (
1073
+ <StackItem size="fill">
1074
+ <NumberInput
1075
+ label={label}
1076
+ isLabelHidden
1077
+ startIcon={icon}
1078
+ size="sm"
1079
+ value={value}
1080
+ onChange={onChange}
1081
+ isWheelEnabled={false}
1082
+ />
1083
+ </StackItem>
1084
+ );
1085
+ }
1086
+
1087
+ /**
1088
+ * A numeric row with the steppers showing. Size, line height and letter
1089
+ * spacing get them because they are values you arrive at by nudging rather
1090
+ * than by typing a number you already know.
1091
+ */
1092
+ function StepperRow({
1093
+ label,
1094
+ value,
1095
+ onChange,
1096
+ }: {
1097
+ label: string;
1098
+ value: number;
1099
+ onChange: (next: number) => void;
1100
+ }) {
1101
+ return (
1102
+ <InspectorRow label={label}>
1103
+ <StackItem size="fill">
1104
+ <NumberInput
1105
+ label={label}
1106
+ isLabelHidden
1107
+ size="sm"
1108
+ hasNumberSteppers
1109
+ value={value}
1110
+ onChange={onChange}
1111
+ isWheelEnabled={false}
1112
+ />
1113
+ </StackItem>
1114
+ </InspectorRow>
1115
+ );
1116
+ }
1117
+
1118
+ /**
1119
+ * One image filter: the number and the rail that drags it.
1120
+ *
1121
+ * Both are wired to the same value, which is the point — you drag to find
1122
+ * the look and read the number to reproduce it, and nine of these read as
1123
+ * one column because the rail is fixed-width instead of filling.
1124
+ */
1125
+ function FilterRow({
1126
+ filter,
1127
+ value,
1128
+ onChange,
1129
+ }: {
1130
+ filter: (typeof FILTERS)[number];
1131
+ value: number;
1132
+ onChange: (next: number) => void;
1133
+ }) {
1134
+ return (
1135
+ <InspectorRow label={filter.label}>
1136
+ <StackItem size="fill">
1137
+ <Slider
1138
+ label={`${filter.label} slider`}
1139
+ isLabelHidden
1140
+ min={0}
1141
+ max={filter.max}
1142
+ value={value}
1143
+ onChange={onChange}
1144
+ valueDisplay="none"
1145
+ />
1146
+ </StackItem>
1147
+ <NumberInput
1148
+ label={filter.label}
1149
+ isLabelHidden
1150
+ size="sm"
1151
+ min={0}
1152
+ max={filter.max}
1153
+ value={value}
1154
+ onChange={onChange}
1155
+ isWheelEnabled={false}
1156
+ xstyle={styles.filterValue}
1157
+ />
1158
+ </InspectorRow>
1159
+ );
1160
+ }
1161
+
1162
+ /** An inspector group: a caption, its rows, and a closing divider. */
1163
+ function InspectorSection({
1164
+ title,
1165
+ children,
1166
+ }: {
1167
+ title: string;
1168
+ children: React.ReactNode;
1169
+ }) {
1170
+ return (
1171
+ // The panel itself stays at zero padding and each section carries the
1172
+ // gutter instead. That is what keeps the rules between sections running
1173
+ // edge to edge: pad the panel and every divider insets by the gutter,
1174
+ // turning a full-bleed rule into a floating line.
1175
+ <Section padding={3} dividers={['bottom']}>
1176
+ <VStack gap={3}>
1177
+ <Text type="label" weight="semibold">
1178
+ {title}
1179
+ </Text>
1180
+ {children}
1181
+ </VStack>
1182
+ </Section>
1183
+ );
1184
+ }
1185
+
1186
+ /**
1187
+ * An action nested inside a list row: an icon you can click, not a button
1188
+ * with an icon in it.
1189
+ *
1190
+ * This is the exception, not the pattern. An action standing beside a field
1191
+ * uses `IconButton size="sm"`, so its 28px box lines up with the input's
1192
+ * and the row reads as one band. Only an action *inside* a 28px row shrinks,
1193
+ * because the row has no space for a control its own height. See
1194
+ * `styles.itemAction`.
1195
+ */
1196
+ function ItemAction({
1197
+ label,
1198
+ icon,
1199
+ isDisabled,
1200
+ onClick,
1201
+ xstyle,
1202
+ className,
1203
+ style,
1204
+ }: {
1205
+ label: string;
1206
+ icon: IconType;
1207
+ isDisabled?: boolean;
1208
+ onClick?: () => void;
1209
+ xstyle?: stylex.StyleXStyles;
1210
+ className?: string;
1211
+ style?: React.CSSProperties;
1212
+ }) {
1213
+ return (
1214
+ <IconButton
1215
+ label={label}
1216
+ // No tooltip. These sit in 28px rows, and a bubble opening off one
1217
+ // covers the row above it — a lot of chrome for a padlock and an ×
1218
+ // that already say what they do. `label` still names them for anyone
1219
+ // reading the rail through assistive tech.
1220
+ icon={<Icon icon={icon} size={ICON} />}
1221
+ variant="ghost"
1222
+ size="sm"
1223
+ isDisabled={isDisabled}
1224
+ onClick={onClick}
1225
+ xstyle={[styles.itemAction, xstyle]}
1226
+ className={className}
1227
+ style={style}
1228
+ />
1229
+ );
1230
+ }
1231
+
1232
+ /**
1233
+ * One open document in the strip above the menubar.
1234
+ *
1235
+ * An open document is the same kind of thing as a layer: a name with a mark
1236
+ * in front of it and an action behind, which is why this is the same Item
1237
+ * the rail is built from rather than a tab. Item ellipsizes a string label
1238
+ * on its own, so the width ceiling below is the only thing left to say, and
1239
+ * it ignores a click that lands on a nested button — that is what stops the
1240
+ * close from also switching to the document it is closing.
1241
+ *
1242
+ * Not TabList: a Tab marks the open one with an underline rather than a
1243
+ * fill, sizes itself to its label with no way to cap it from out here, and
1244
+ * keeps both of those in spans an xstyle cannot reach.
1245
+ *
1246
+ * The close follows the same rule as the layer rail's lock: hidden until the
1247
+ * tab is hovered or holds focus, and pinned open on the active tab, which is
1248
+ * the one whose close a user reaches for. Because it only fades, the tab does
1249
+ * not change width when the control arrives.
1250
+ */
1251
+ function DocumentTab({
1252
+ tab,
1253
+ isActive,
1254
+ onSelect,
1255
+ onClose,
1256
+ }: {
1257
+ tab: DocumentTabData;
1258
+ isActive: boolean;
1259
+ onSelect: () => void;
1260
+ onClose: () => void;
1261
+ }) {
1262
+ const {getContainerProps, getContentRevealProps} = useContainerReveal();
1263
+
1264
+ return (
1265
+ <Item
1266
+ label={tab.name}
1267
+ density="compact"
1268
+ isSelected={isActive}
1269
+ onClick={onSelect}
1270
+ aria-current={isActive ? 'true' : undefined}
1271
+ {...getContainerProps()}
1272
+ startContent={
1273
+ <Icon
1274
+ icon={tab.icon}
1275
+ size={ICON}
1276
+ color={isActive ? 'primary' : 'secondary'}
1277
+ />
1278
+ }
1279
+ endContent={
1280
+ <ItemAction
1281
+ label={`Close ${tab.name}`}
1282
+ icon={X}
1283
+ onClick={onClose}
1284
+ {...getContentRevealProps({
1285
+ forceVisibility: isActive ? 'shown' : undefined,
1286
+ })}
1287
+ />
1288
+ }
1289
+ // Both fills land after Item's own, which is what lets the selected one
1290
+ // be replaced; they stay mutually exclusive so hover cannot erase it.
1291
+ xstyle={[styles.tab, isActive ? styles.tabSelected : styles.tabHover]}
1292
+ />
1293
+ );
1294
+ }
1295
+
1296
+ /**
1297
+ * The saturation/value plane, the hue rail, and the hex field, which are the
1298
+ * three ways the same colour gets said.
1299
+ *
1300
+ * The plane and the rail are painted rather than composed: a two-dimensional
1301
+ * gradient and a rainbow track are not controls the system ships, and a
1302
+ * Slider styled into a hue rail would still only give one of the two axes.
1303
+ * They carry `role="slider"` with arrow keys so the picker is not
1304
+ * pointer-only, and the hex field is the exact route for anyone who already
1305
+ * knows the value.
1306
+ *
1307
+ * HSV lives here rather than on the layer. A layer stores a hex string —
1308
+ * that is what the artboard paints — but hex has no hue to slide once the
1309
+ * colour reaches black or white, so the picker keeps the HSV it is working
1310
+ * in for as long as it is open.
1311
+ */
1312
+ function ColorPicker({
1313
+ value,
1314
+ onChange,
1315
+ }: {
1316
+ value: string;
1317
+ onChange: (next: string) => void;
1318
+ }) {
1319
+ const [hsv, setHsv] = useState(() => hexToHsv(value));
1320
+ const [draft, setDraft] = useState(value);
1321
+
1322
+ const commit = useCallback(
1323
+ (next: Hsv) => {
1324
+ setHsv(next);
1325
+ const hex = hsvToHex(next);
1326
+ setDraft(hex);
1327
+ onChange(hex);
1328
+ },
1329
+ [onChange],
1330
+ );
1331
+
1332
+ const planeTrack = usePointerTrack(
1333
+ useCallback(
1334
+ (x, y) =>
1335
+ commit({...hsv, s: Math.round(x * 100), v: Math.round(100 - y * 100)}),
1336
+ [commit, hsv],
1337
+ ),
1338
+ );
1339
+ /** Arrow keys on the plane: left/right saturate, up/down brighten. */
1340
+ const nudge = (event: React.KeyboardEvent) => {
1341
+ const sign =
1342
+ event.key === 'ArrowRight' || event.key === 'ArrowUp'
1343
+ ? 1
1344
+ : event.key === 'ArrowLeft' || event.key === 'ArrowDown'
1345
+ ? -1
1346
+ : 0;
1347
+ if (sign === 0) {
1348
+ return;
1349
+ }
1350
+ event.preventDefault();
1351
+ const horizontal = event.key === 'ArrowRight' || event.key === 'ArrowLeft';
1352
+ const clamp = (n: number) => Math.min(100, Math.max(0, n));
1353
+ commit({
1354
+ h: hsv.h,
1355
+ s: clamp(hsv.s + (horizontal ? sign * 2 : 0)),
1356
+ v: clamp(hsv.v + (horizontal ? 0 : sign * 2)),
1357
+ });
1358
+ };
1359
+
1360
+ return (
1361
+ <div {...stylex.props(styles.planeStack)}>
1362
+ <div
1363
+ role="slider"
1364
+ tabIndex={0}
1365
+ aria-label="Saturation and brightness"
1366
+ aria-valuetext={`${hsv.s}% saturation, ${hsv.v}% brightness`}
1367
+ aria-valuenow={hsv.s}
1368
+ aria-valuemin={0}
1369
+ aria-valuemax={100}
1370
+ onKeyDown={nudge}
1371
+ {...planeTrack}
1372
+ {...stylex.props(styles.plane, paint.hue(hsv.h))}>
1373
+ <span
1374
+ {...stylex.props(
1375
+ styles.thumb,
1376
+ paint.planeThumb(hsv.s, hsv.v),
1377
+ paint.fill(hsvToHex(hsv)),
1378
+ )}
1379
+ />
1380
+ </div>
1381
+ {/* The hue rail is a real Slider with its track repainted, not a
1382
+ hand-rolled one: the rainbow is the only thing about it that is not
1383
+ already a Slider, and `slider-track` is a theming target. The template's
1384
+ one custom theme is mounted narrowly here so the nine filter sliders in
1385
+ the same panel keep the plain track they should have. */}
1386
+ <Theme theme={canvasEditorTheme}>
1387
+ <Slider
1388
+ label="Hue"
1389
+ isLabelHidden
1390
+ min={0}
1391
+ max={360}
1392
+ value={hsv.h}
1393
+ // Annotated because Slider's props are a union of the single and
1394
+ // range forms, and with no `value` tuple to discriminate on there is
1395
+ // nothing for the parameter to infer from.
1396
+ onChange={(h: number) => commit({...hsv, h})}
1397
+ valueDisplay="none"
1398
+ />
1399
+ </Theme>
1400
+ <TextInput
1401
+ label="Hex"
1402
+ isLabelHidden
1403
+ size="sm"
1404
+ value={draft}
1405
+ onChange={next => {
1406
+ setDraft(next);
1407
+ if (/^#?[\da-f]{6}$/i.test(next.trim())) {
1408
+ setHsv(hexToHsv(next));
1409
+ onChange(next.startsWith('#') ? next : `#${next}`);
1410
+ }
1411
+ }}
1412
+ />
1413
+ </div>
1414
+ );
1415
+ }
1416
+
1417
+ /**
1418
+ * The chip that opens a picker. Twenty pixels square, so a row carrying one
1419
+ * still measures 28.
1420
+ */
1421
+ function Swatch({
1422
+ label,
1423
+ value,
1424
+ onChange,
1425
+ children,
1426
+ }: {
1427
+ label: string;
1428
+ value?: string;
1429
+ onChange: (next: string) => void;
1430
+ children?: React.ReactNode;
1431
+ }) {
1432
+ return (
1433
+ <Popover
1434
+ label={label}
1435
+ placement="start"
1436
+ alignment="start"
1437
+ width={248}
1438
+ content={
1439
+ <VStack gap={3}>
1440
+ <Text type="label" weight="semibold">
1441
+ {label}
1442
+ </Text>
1443
+ <ColorPicker value={value ?? '#ffffff'} onChange={onChange} />
1444
+ {children}
1445
+ </VStack>
1446
+ }>
1447
+ <button
1448
+ type="button"
1449
+ aria-label={`${label}${value ? `, ${value}` : ', not set'}`}
1450
+ {...stylex.props(
1451
+ styles.swatch,
1452
+ value != null && styles.swatchFilled,
1453
+ value != null && paint.fill(value),
1454
+ )}
1455
+ />
1456
+ </Popover>
1457
+ );
1458
+ }
1459
+
1460
+ /**
1461
+ * A menu shortcut, printed the way a desktop menu prints one: quiet
1462
+ * secondary text set hard against the menu's right edge.
1463
+ *
1464
+ * `Kbd` paints one key cap per key, so `⌘` and `N` arrive as two small
1465
+ * objects sitting beside the item. A shortcut is a hint about the item, not
1466
+ * a control on it, so it reads better as one dim string that the eye can
1467
+ * skip.
1468
+ *
1469
+ * The glyphs are literal because platform detection is core's, not a
1470
+ * template's — `Kbd` resolves `mod` to ⌘ or Ctrl through an internal util
1471
+ * that is deliberately unexported. These read as macOS, as they do in the
1472
+ * shell-nav template.
1473
+ */
1474
+ function Shortcut({children}: {children: string}) {
1475
+ return (
1476
+ <Text type="supporting" color="secondary">
1477
+ {children}
1478
+ </Text>
1479
+ );
1480
+ }
1481
+
1482
+ /**
1483
+ * One row of the layer rail: an icon, the layer's name, and a lock.
1484
+ *
1485
+ * The lock is an action on the row, so it stays out of the way until the row
1486
+ * is the one being pointed at — the rail reads as a list of names, and the
1487
+ * control arrives where the cursor already is. A locked row is the exception:
1488
+ * it shows the closed lock at rest, because that is a fact about the layer
1489
+ * rather than an action being offered.
1490
+ */
1491
+ /**
1492
+ * The layer rail as a tree, grouped by what each layer is.
1493
+ *
1494
+ * A poster's layers are not a flat list — the two text layers belong together
1495
+ * and the images belong together — and a tree says so structurally rather
1496
+ * than by sorting and hoping the reader infers it. It also buys collapse: a
1497
+ * document with thirty layers is navigable when the groups fold.
1498
+ *
1499
+ * Built as data rather than rows because TreeList owns the disclosure state,
1500
+ * the guide lines and the roving focus that a hand-rolled tree would have to
1501
+ * reimplement. The per-row pieces still come through the content slots, so
1502
+ * the lock keeps its hover reveal.
1503
+ */
1504
+ function layerTree(
1505
+ layers: Layer[],
1506
+ selectedID: string,
1507
+ onSelect: (id: string) => void,
1508
+ onToggleLock: (id: string) => void,
1509
+ reveal: ReturnType<typeof useContainerReveal>,
1510
+ ): TreeListItemData[] {
1511
+ const row = (layer: Layer): TreeListItemData => ({
1512
+ id: layer.id,
1513
+ label: layer.name,
1514
+ isSelected: layer.id === selectedID,
1515
+ onClick: () => onSelect(layer.id),
1516
+ // The hook owns both sides of the reveal. TreeList forwards the complete
1517
+ // container props to this row, including the inline custom properties that
1518
+ // isolate nested reveal containers.
1519
+ ...reveal.getContainerProps(),
1520
+ startContent: (
1521
+ <Icon icon={LAYER_ICON[layer.kind]} size={ICON} color="secondary" />
1522
+ ),
1523
+ endContent: (
1524
+ <ItemAction
1525
+ label={layer.isLocked ? `Unlock ${layer.name}` : `Lock ${layer.name}`}
1526
+ icon={layer.isLocked ? Lock : LockOpen}
1527
+ onClick={() => onToggleLock(layer.id)}
1528
+ {...reveal.getContentRevealProps({
1529
+ forceVisibility: layer.isLocked ? 'shown' : undefined,
1530
+ })}
1531
+ />
1532
+ ),
1533
+ });
1534
+
1535
+ const groups: {id: string; label: string; kind: LayerKind}[] = [
1536
+ {id: 'group-text', label: 'Text', kind: 'text'},
1537
+ {id: 'group-images', label: 'Images', kind: 'image'},
1538
+ ];
1539
+
1540
+ // A group with nothing in it is a disclosure that opens onto nothing, so it
1541
+ // does not get drawn.
1542
+ return groups
1543
+ .map(group => ({
1544
+ id: group.id,
1545
+ label: group.label,
1546
+ isExpanded: true,
1547
+ // A group is a frame, not a bigger version of what it holds. Repeating
1548
+ // the child's glyph on the parent says the row is another layer of that
1549
+ // kind; the frame mark says it is the container.
1550
+ startContent: <Icon icon={Frame} size={ICON} color="secondary" />,
1551
+ children: layers.filter(l => l.kind === group.kind).map(row),
1552
+ }))
1553
+ .filter(group => group.children.length > 0);
1554
+ }
1555
+
1556
+ /**
1557
+ * A style slot that is either unset or carries a value: a field led by the
1558
+ * slot's own icon, and a clear that only lights up once the slot holds
1559
+ * something.
1560
+ *
1561
+ * The icon is a prop rather than one shared swatch. Border, shadow and fill
1562
+ * are three different properties, and giving them one icon makes the column
1563
+ * read as three copies of the same control.
1564
+ */
1565
+ function StyleRow({
1566
+ label,
1567
+ name = label,
1568
+ value,
1569
+ placeholder,
1570
+ onChange,
1571
+ onClear,
1572
+ children,
1573
+ }: {
1574
+ label: string;
1575
+ /**
1576
+ * What the row's controls are called, when that has to differ from what
1577
+ * the row is captioned. A text layer carries two shadows — its box's and
1578
+ * its type's — and both are captioned "Shadow" because the section
1579
+ * heading above each already says which. Screen reader users get no such
1580
+ * heading with the control, so they get the longer name instead.
1581
+ */
1582
+ name?: string;
1583
+ value?: string;
1584
+ placeholder: string;
1585
+ onChange: (next: string) => void;
1586
+ onClear: () => void;
1587
+ /** Extra controls for the popover, e.g. a shadow's offset and blur. */
1588
+ children?: React.ReactNode;
1589
+ }) {
1590
+ return (
1591
+ <InspectorRow label={label}>
1592
+ <StackItem size="fill">
1593
+ <TextInput
1594
+ label={name}
1595
+ isLabelHidden
1596
+ size="sm"
1597
+ value={value ?? ''}
1598
+ placeholder={placeholder}
1599
+ onChange={onChange}
1600
+ />
1601
+ </StackItem>
1602
+ <Swatch label={name} value={value} onChange={onChange}>
1603
+ {children}
1604
+ </Swatch>
1605
+ <IconButton
1606
+ label={`Clear ${name.toLowerCase()}`}
1607
+ tooltip="Clear"
1608
+ size="sm"
1609
+ variant="ghost"
1610
+ isDisabled={value === undefined}
1611
+ onClick={onClear}
1612
+ icon={<Icon icon={X} size={ICON} />}
1613
+ />
1614
+ </InspectorRow>
1615
+ );
1616
+ }
1617
+
1618
+ /**
1619
+ * The four numbers a shadow has beyond its colour. They live in the same
1620
+ * popover as the colour because a shadow is one thing to set, not five.
1621
+ */
1622
+ function ShadowFields({
1623
+ name,
1624
+ shadow,
1625
+ onChange,
1626
+ }: {
1627
+ /** Prefixes each field, so two shadows on one layer stay tellable apart. */
1628
+ name: string;
1629
+ shadow: Shadow;
1630
+ onChange: (next: Shadow) => void;
1631
+ }) {
1632
+ const field = (key: 'x' | 'y' | 'blur' | 'spread', label: string) => (
1633
+ <InspectorRow label={label} labelWidth={56}>
1634
+ <StackItem size="fill">
1635
+ <NumberInput
1636
+ label={`${name} ${label.toLowerCase()}`}
1637
+ isLabelHidden
1638
+ size="sm"
1639
+ hasNumberSteppers
1640
+ value={shadow[key]}
1641
+ onChange={next => onChange({...shadow, [key]: next})}
1642
+ isWheelEnabled={false}
1643
+ />
1644
+ </StackItem>
1645
+ </InspectorRow>
1646
+ );
1647
+ return (
1648
+ <VStack gap={2}>
1649
+ {field('x', 'X')}
1650
+ {field('y', 'Y')}
1651
+ {field('blur', 'Blur')}
1652
+ {field('spread', 'Spread')}
1653
+ </VStack>
1654
+ );
1655
+ }
1656
+
1657
+ // =============================================================================
1658
+ // Page
1659
+ // =============================================================================
1660
+
1661
+ export default function CanvasEditor() {
1662
+ const [layers, setLayers] = useState(INITIAL_LAYERS);
1663
+ const [selectedID, setSelectedID] = useState('headline');
1664
+ const [panel, setPanel] = useState('layers');
1665
+ const [zoom, setZoom] = useState('0.4');
1666
+
1667
+ // The picker is presentational here: a template has no upload endpoint to
1668
+ // post to, and swapping the artboard for a local object URL would leave the
1669
+ // page showing something the template does not ship. Naming the chosen file
1670
+ // is the honest middle — the control demonstrably works, and nothing
1671
+ // pretends to have been uploaded.
1672
+ const fileRef = useRef<HTMLInputElement>(null);
1673
+ const [imageName, setImageName] = useState('Image');
1674
+ // What the View submenu toggles. A design tool trades chrome for canvas, so
1675
+ // these drive the real Layout slots rather than standing in for them.
1676
+ const [chrome, setChrome] = useState({
1677
+ left: true,
1678
+ right: true,
1679
+ toolbar: true,
1680
+ });
1681
+ const [appearance, setAppearance] = useState<ThemeMode>('system');
1682
+ const [tabs, setTabs] = useState(INITIAL_TABS);
1683
+ const [activeTab, setActiveTab] = useState(INITIAL_TABS[0].id);
1684
+ const layerReveal = useContainerReveal();
1685
+ // Only used to name new tabs, so it counts documents opened rather than
1686
+ // documents open — reusing "Untitled 2" after closing one would be worse.
1687
+ const untitledCount = useRef(1);
1688
+
1689
+ // Closing the open document has to hand the strip a new one, and the
1690
+ // neighbour is the least surprising choice: the tab that slides under the
1691
+ // pointer is the one that takes over. Closing the last tab leaves the strip
1692
+ // empty rather than inventing a document nobody asked for.
1693
+ const closeTab = (id: string) => {
1694
+ setTabs(current => {
1695
+ const index = current.findIndex(tab => tab.id === id);
1696
+ const next = current.filter(tab => tab.id !== id);
1697
+ if (id === activeTab) {
1698
+ const neighbour = next[index] ?? next[index - 1];
1699
+ setActiveTab(neighbour ? neighbour.id : '');
1700
+ }
1701
+ return next;
1702
+ });
1703
+ };
1704
+
1705
+ const addTab = () => {
1706
+ untitledCount.current += 1;
1707
+ const tab: DocumentTabData = {
1708
+ id: `untitled-${untitledCount.current}`,
1709
+ name: `Untitled ${untitledCount.current}`,
1710
+ icon: FileIcon,
1711
+ };
1712
+ setTabs(current => [...current, tab]);
1713
+ setActiveTab(tab.id);
1714
+ };
1715
+
1716
+ // Both rails are drag-sized. The floors are the width each panel stops
1717
+ // being useful below — the rail at the point layer names start truncating,
1718
+ // the inspector at the point its two-field rows stop fitting side by side —
1719
+ // and the ceilings keep either from eating the canvas they exist to serve.
1720
+ const rail = useResizable({defaultSize: 216, minSize: 176, maxSize: 320});
1721
+ const inspector = useResizable({
1722
+ defaultSize: 288,
1723
+ minSize: 264,
1724
+ maxSize: 400,
1725
+ });
1726
+
1727
+ const selected = layers.find(layer => layer.id === selectedID) ?? layers[0];
1728
+ const scale = Number(zoom);
1729
+
1730
+ const updateSelected = useCallback(
1731
+ (patch: Partial<Layer>) => {
1732
+ setLayers(current =>
1733
+ current.map(layer =>
1734
+ layer.id === selectedID ? {...layer, ...patch} : layer,
1735
+ ),
1736
+ );
1737
+ },
1738
+ [selectedID],
1739
+ );
1740
+
1741
+ const [headline, dateline] = layers.filter(layer => layer.kind === 'text');
1742
+ const photo = layers.filter(layer => layer.kind === 'image')[0];
1743
+
1744
+ return (
1745
+ // Appearance drives a Theme around the whole editor, and that Theme needs
1746
+ // a surface of its own. Panels and toolbars are transparent, so without
1747
+ // one they keep showing the host page's background while their text takes
1748
+ // the new mode's colour — light text on a light page. The Section paints
1749
+ // the mode's own background, which is what makes the editor consistent.
1750
+ <Theme theme={neutralTheme} mode={appearance}>
1751
+ <Section variant="section" padding={0} height="100%">
1752
+ <Layout
1753
+ height="fill"
1754
+ padding={0}
1755
+ header={
1756
+ // Not a Toolbar. A toolbar is a set of peer commands that arrow
1757
+ // keys walk across, and the document tabs make that wrong twice
1758
+ // over: arrowing off a tab lands on its own close button, and a
1759
+ // strip of documents is not a band of tools. This is the header
1760
+ // slot of the layout it heads, which is what LayoutHeader is.
1761
+ <LayoutHeader
1762
+ hasDivider
1763
+ // 4px on every edge. A toolbar's padding is sized for a band
1764
+ // heading content, and app chrome wants to sit tighter: the
1765
+ // strip inside carries its own 4px around a 28px tab. It also
1766
+ // lands the menu button on the inset a ghost trigger wants, so
1767
+ // nothing has to be pulled back out again.
1768
+ padding={1}
1769
+ xstyle={styles.headerBar}>
1770
+ <HStack gap={0.5} vAlign="center" hAlign="between">
1771
+ <HStack gap={0.5} vAlign="center" xstyle={styles.headerLead}>
1772
+ {/*
1773
+ One button for every command in the editor, the way a
1774
+ single-window design tool does it. A menubar spends the
1775
+ top-left on five words that are only read when someone is
1776
+ already looking for a command; folding them into submenus
1777
+ hands that space to the tabs, which are read constantly.
1778
+ The commands keep their grouping — the bar became the
1779
+ first level of the menu rather than disappearing.
1780
+ */}
1781
+ <DropdownMenu
1782
+ button={{
1783
+ label: 'Menu',
1784
+ tooltip: 'Menu',
1785
+ variant: 'ghost',
1786
+ size: 'sm',
1787
+ isIconOnly: true,
1788
+ icon: <Icon icon={Menu} size={ICON} />,
1789
+ }}
1790
+ hasChevron={false}
1791
+ // Left to itself the menu matches its trigger, and the
1792
+ // trigger is a 28px icon button — five one-word rows in a
1793
+ // column barely wider than the words. A set width gives
1794
+ // the submenu chevrons somewhere to sit at the far edge,
1795
+ // which is what makes the rows read as a menu bar folded
1796
+ // into a list rather than a stack of buttons.
1797
+ menuWidth={280}>
1798
+ <DropdownMenuSubMenu label="File">
1799
+ <DropdownMenuItem
1800
+ label="New poster"
1801
+ endContent={<Shortcut>⌘N</Shortcut>}
1802
+ />
1803
+ <DropdownMenuItem
1804
+ label="Open…"
1805
+ endContent={<Shortcut>⌘O</Shortcut>}
1806
+ />
1807
+ <DropdownMenuDivider />
1808
+ <DropdownMenuItem
1809
+ label="Save"
1810
+ endContent={<Shortcut>⌘S</Shortcut>}
1811
+ />
1812
+ <DropdownMenuItem
1813
+ label="Save as…"
1814
+ endContent={<Shortcut>⇧⌘S</Shortcut>}
1815
+ />
1816
+ <DropdownMenuSubMenu label="Export">
1817
+ {EXPORT_FORMATS.map(format => (
1818
+ <DropdownMenuItem key={format} label={format} />
1819
+ ))}
1820
+ </DropdownMenuSubMenu>
1821
+ <DropdownMenuDivider />
1822
+ <DropdownMenuItem
1823
+ label="Close"
1824
+ endContent={<Shortcut>⌘W</Shortcut>}
1825
+ />
1826
+ </DropdownMenuSubMenu>
1827
+
1828
+ <DropdownMenuSubMenu label="Edit">
1829
+ <DropdownMenuItem
1830
+ label="Undo"
1831
+ endContent={<Shortcut>⌘Z</Shortcut>}
1832
+ />
1833
+ <DropdownMenuItem
1834
+ label="Redo"
1835
+ endContent={<Shortcut>⇧⌘Z</Shortcut>}
1836
+ />
1837
+ <DropdownMenuDivider />
1838
+ <DropdownMenuItem
1839
+ label="Cut"
1840
+ endContent={<Shortcut>⌘X</Shortcut>}
1841
+ />
1842
+ <DropdownMenuItem
1843
+ label="Copy"
1844
+ endContent={<Shortcut>⌘C</Shortcut>}
1845
+ />
1846
+ <DropdownMenuItem
1847
+ label="Paste"
1848
+ endContent={<Shortcut>⌘V</Shortcut>}
1849
+ />
1850
+ <DropdownMenuDivider />
1851
+ <DropdownMenuItem
1852
+ label="Duplicate"
1853
+ endContent={<Shortcut>⌘D</Shortcut>}
1854
+ />
1855
+ {/* Named, because a menu opened from the bar has lost
1856
+ sight of the rail: the row that would go is worth saying
1857
+ out loud before a destructive item is clicked. */}
1858
+ <DropdownMenuItem
1859
+ label={`Delete ${selected.name}`}
1860
+ variant="destructive"
1861
+ endContent={<Shortcut>⌫</Shortcut>}
1862
+ />
1863
+ </DropdownMenuSubMenu>
1864
+
1865
+ {/* Checkbox rows, not actions: each reports a state the
1866
+ user can see on the page, and the menu stays open so all
1867
+ three can be set in one visit. */}
1868
+ <DropdownMenuSubMenu label="View">
1869
+ <DropdownMenuCheckboxItem
1870
+ label="Left panel"
1871
+ icon={PanelLeft}
1872
+ endContent={<Shortcut>⌘B</Shortcut>}
1873
+ value={chrome.left}
1874
+ onChange={next => setChrome(c => ({...c, left: next}))}
1875
+ />
1876
+ <DropdownMenuCheckboxItem
1877
+ label="Right panel"
1878
+ icon={PanelRight}
1879
+ endContent={<Shortcut>⇧⌘B</Shortcut>}
1880
+ value={chrome.right}
1881
+ onChange={next => setChrome(c => ({...c, right: next}))}
1882
+ />
1883
+ <DropdownMenuCheckboxItem
1884
+ label="Canvas tools"
1885
+ icon={PanelBottom}
1886
+ endContent={<Shortcut>⌘.</Shortcut>}
1887
+ value={chrome.toolbar}
1888
+ onChange={next =>
1889
+ setChrome(c => ({...c, toolbar: next}))
1890
+ }
1891
+ />
1892
+ <DropdownMenuDivider />
1893
+ {/* The same value the tool bar's zoom control holds, so
1894
+ setting it in either place moves the other. */}
1895
+ <DropdownMenuSubMenu label="Zoom">
1896
+ <DropdownMenuRadioGroup
1897
+ label="Zoom"
1898
+ value={zoom}
1899
+ onChange={setZoom}>
1900
+ {ZOOM_OPTIONS.map(option => (
1901
+ <DropdownMenuRadioItem
1902
+ key={option.value}
1903
+ value={option.value}
1904
+ label={option.label}
1905
+ />
1906
+ ))}
1907
+ </DropdownMenuRadioGroup>
1908
+ </DropdownMenuSubMenu>
1909
+ <DropdownMenuSubMenu label="Appearance">
1910
+ <DropdownMenuRadioGroup
1911
+ label="Appearance"
1912
+ value={appearance}
1913
+ onChange={next => setAppearance(next as ThemeMode)}>
1914
+ <DropdownMenuRadioItem value="light" label="Light" />
1915
+ <DropdownMenuRadioItem value="dark" label="Dark" />
1916
+ <DropdownMenuRadioItem
1917
+ value="system"
1918
+ label="System"
1919
+ />
1920
+ </DropdownMenuRadioGroup>
1921
+ </DropdownMenuSubMenu>
1922
+ </DropdownMenuSubMenu>
1923
+
1924
+ <DropdownMenuSubMenu label="Object">
1925
+ <DropdownMenuSubMenu label="Insert">
1926
+ {INSERT_ITEMS.map(item => (
1927
+ <DropdownMenuItem
1928
+ key={item.label}
1929
+ label={item.label}
1930
+ icon={item.icon}
1931
+ />
1932
+ ))}
1933
+ </DropdownMenuSubMenu>
1934
+ <DropdownMenuDivider />
1935
+ <DropdownMenuItem
1936
+ label="Bring forward"
1937
+ endContent={<Shortcut>⌘]</Shortcut>}
1938
+ />
1939
+ <DropdownMenuItem
1940
+ label="Send backward"
1941
+ endContent={<Shortcut>⌘[</Shortcut>}
1942
+ />
1943
+ <DropdownMenuDivider />
1944
+ {/* The lock the rail row reveals on hover, reached from
1945
+ the menubar instead — one piece of state, two ways in. */}
1946
+ <DropdownMenuCheckboxItem
1947
+ label={`Lock ${selected.name}`}
1948
+ icon={selected.isLocked ? Lock : LockOpen}
1949
+ endContent={<Shortcut>⇧⌘L</Shortcut>}
1950
+ value={selected.isLocked}
1951
+ onChange={next => updateSelected({isLocked: next})}
1952
+ />
1953
+ </DropdownMenuSubMenu>
1954
+
1955
+ <DropdownMenuDivider />
1956
+
1957
+ <DropdownMenuSubMenu label="Help">
1958
+ <DropdownMenuItem
1959
+ label="Keyboard shortcuts"
1960
+ endContent={<Shortcut>⌘/</Shortcut>}
1961
+ />
1962
+ <DropdownMenuItem label="Documentation" />
1963
+ <DropdownMenuDivider />
1964
+ <DropdownMenuItem label="About this editor" />
1965
+ </DropdownMenuSubMenu>
1966
+ </DropdownMenu>
1967
+
1968
+ {/*
1969
+ A group, not a nav landmark: a landmark inside a
1970
+ role="toolbar" is not a place a screen reader expects one,
1971
+ and the toolbar already is the region. The group gives the
1972
+ strip a name, and each tab says whether it is the open
1973
+ document with aria-current.
1974
+ */}
1975
+ <HStack
1976
+ role="group"
1977
+ aria-label="Open documents"
1978
+ gap={0}
1979
+ vAlign="center"
1980
+ paddingInline={2}
1981
+ paddingBlock={1}
1982
+ isScrollable
1983
+ maxWidth={`calc(100cqw - ${TAB_STRIP_RESERVE}px)`}
1984
+ xstyle={styles.tabStrip}>
1985
+ {tabs.map((tab, index) => {
1986
+ // Tabs are all one width, so the rule marks a boundary
1987
+ // rather than sitting midway between two labels. It is
1988
+ // dropped either side of the open document: that tab
1989
+ // already reads as separate by its fill, and a rule
1990
+ // running into the fill's rounded edge only crowds it.
1991
+ // Hidden rather than unmounted, so moving the selection
1992
+ // does not add or remove a flex item and slide the whole
1993
+ // strip sideways under the pointer that just clicked it.
1994
+ const previous = tabs[index - 1];
1995
+ const isRuleHidden =
1996
+ previous?.id === activeTab || tab.id === activeTab;
1997
+ return (
1998
+ <Fragment key={tab.id}>
1999
+ {previous != null ? (
2000
+ <Divider
2001
+ orientation="vertical"
2002
+ xstyle={[
2003
+ styles.tabRule,
2004
+ isRuleHidden && styles.tabRuleHidden,
2005
+ ]}
2006
+ />
2007
+ ) : null}
2008
+ <DocumentTab
2009
+ tab={tab}
2010
+ isActive={tab.id === activeTab}
2011
+ onSelect={() => setActiveTab(tab.id)}
2012
+ onClose={() => closeTab(tab.id)}
2013
+ />
2014
+ </Fragment>
2015
+ );
2016
+ })}
2017
+ </HStack>
2018
+ {/*
2019
+ Outside the strip on both counts: it is not one of the
2020
+ open documents the group is named for, and inside a strip
2021
+ that scrolls once the tabs stop fitting it would be the
2022
+ first thing to scroll out of reach — exactly when adding
2023
+ a document is most likely to be what you came for.
2024
+ */}
2025
+ <IconButton
2026
+ label="New document"
2027
+ tooltip="New document"
2028
+ variant="ghost"
2029
+ size="sm"
2030
+ onClick={addTab}
2031
+ icon={<Icon icon={Plus} size={ICON} color="secondary" />}
2032
+ />
2033
+ </HStack>
2034
+ <HStack gap={3} vAlign="center">
2035
+ <Text type="supporting" color="secondary">
2036
+ Saved · 2 min ago
2037
+ </Text>
2038
+ <DropdownMenu
2039
+ button={{
2040
+ label: 'Export',
2041
+ variant: 'ghost',
2042
+ size: 'sm',
2043
+ icon: <Icon icon={Download} size={ICON} />,
2044
+ }}
2045
+ alignment="end"
2046
+ items={EXPORT_MENU}
2047
+ />
2048
+ </HStack>
2049
+ </HStack>
2050
+ </LayoutHeader>
2051
+ }
2052
+ content={
2053
+ <LayoutContent padding={0}>
2054
+ <Layout
2055
+ height="fill"
2056
+ start={
2057
+ chrome.left ? (
2058
+ <>
2059
+ <LayoutPanel
2060
+ resizable={rail.props}
2061
+ hasDivider
2062
+ padding={2}
2063
+ label="Layers and assets"
2064
+ xstyle={styles.foldsAtRail}>
2065
+ <VStack gap={3}>
2066
+ <SegmentedControl
2067
+ label="Left panel"
2068
+ size="sm"
2069
+ layout="fill"
2070
+ value={panel}
2071
+ onChange={setPanel}>
2072
+ <SegmentedControlItem
2073
+ label="Layers"
2074
+ value="layers"
2075
+ />
2076
+ <SegmentedControlItem
2077
+ label="Library"
2078
+ value="library"
2079
+ />
2080
+ </SegmentedControl>
2081
+ {panel === 'layers' ? (
2082
+ <TreeList
2083
+ density="compact"
2084
+ items={layerTree(
2085
+ layers,
2086
+ selectedID,
2087
+ setSelectedID,
2088
+ id =>
2089
+ setLayers(current =>
2090
+ current.map(l =>
2091
+ l.id === id
2092
+ ? {...l, isLocked: !l.isLocked}
2093
+ : l,
2094
+ ),
2095
+ ),
2096
+ layerReveal,
2097
+ )}
2098
+ />
2099
+ ) : (
2100
+ <List>
2101
+ {EFFECT_PRESETS.map(preset => (
2102
+ <Item
2103
+ key={preset.label}
2104
+ as="li"
2105
+ density="compact"
2106
+ label={preset.label}
2107
+ startContent={
2108
+ <Icon
2109
+ icon={preset.icon}
2110
+ size={ICON}
2111
+ color="secondary"
2112
+ />
2113
+ }
2114
+ />
2115
+ ))}
2116
+ </List>
2117
+ )}
2118
+ </VStack>
2119
+ </LayoutPanel>
2120
+ {/* The panel draws the separator, so the handle stays
2121
+ divider-less and keeps its grip hidden until the pointer
2122
+ is on the seam. */}
2123
+ <ResizeHandle
2124
+ resizable={rail.props}
2125
+ isAlwaysVisible={false}
2126
+ // Centred on the seam rather than pushed onto the
2127
+ // content side: the grip marks the edge it moves, and
2128
+ // an offset pill points at a boundary that is not
2129
+ // where the drag actually happens.
2130
+ pillPlacement="center"
2131
+ label="Resize layers panel"
2132
+ xstyle={styles.foldsAtRail}
2133
+ />
2134
+ </>
2135
+ ) : undefined
2136
+ }
2137
+ content={
2138
+ <LayoutContent padding={0}>
2139
+ <Section variant="muted" padding={0} height="100%">
2140
+ <Layout
2141
+ height="fill"
2142
+ // Lifts the tool bar off the bottom edge: the footer
2143
+ // reads this as its outer padding, so the bar floats
2144
+ // over the backdrop rather than sitting on the sill.
2145
+ padding={4}
2146
+ content={
2147
+ <LayoutContent padding={6}>
2148
+ <HStack
2149
+ width="max-content"
2150
+ height="max-content"
2151
+ minHeight="100%"
2152
+ xstyle={styles.canvasStage}>
2153
+ <Card
2154
+ padding={0}
2155
+ elevation="med"
2156
+ width={FRAME.width * scale}
2157
+ height={FRAME.height * scale}
2158
+ xstyle={[
2159
+ styles.artboardFrame,
2160
+ styles.artboardCentered,
2161
+ ]}>
2162
+ <Theme theme={canvasEditorTheme} mode="light">
2163
+ <AspectRatio
2164
+ ratio={FRAME.width / FRAME.height}
2165
+ fit="cover"
2166
+ xstyle={styles.artboard(scale)}>
2167
+ <img
2168
+ src={PHOTO_LAYER_SRC}
2169
+ alt={photo.content}
2170
+ {...stylex.props(
2171
+ paint.photo(
2172
+ filterCss(
2173
+ photo.filters ?? NO_FILTERS,
2174
+ ),
2175
+ ),
2176
+ )}
2177
+ />
2178
+ {/* Both text layers share one column, so
2179
+ vertical alignment is a property of the
2180
+ column and the headline speaks for it. */}
2181
+ <VStack
2182
+ padding={6}
2183
+ gap={3}
2184
+ vAlign={
2185
+ V_ALIGN[headline.alignY ?? 'start']
2186
+ }
2187
+ xstyle={styles.textLayers}>
2188
+ <Text
2189
+ type="supporting"
2190
+ display="block"
2191
+ xstyle={[
2192
+ styles.type(
2193
+ dateline.size ?? 0,
2194
+ dateline.tracking ?? 0,
2195
+ dateline.line ?? 100,
2196
+ dateline.color ?? '#111111',
2197
+ dateline.stroke ?? 0,
2198
+ shadowCss(dateline.textShadow),
2199
+ ),
2200
+ typeAlign[dateline.alignX ?? 'start'],
2201
+ typeCase[
2202
+ dateline.transform ?? 'none'
2203
+ ],
2204
+ typeLine[
2205
+ dateline.decoration ?? 'none'
2206
+ ],
2207
+ typeSlant[
2208
+ dateline.isItalic
2209
+ ? 'italic'
2210
+ : 'normal'
2211
+ ],
2212
+ ]}>
2213
+ {dateline.content}
2214
+ </Text>
2215
+ <Heading
2216
+ level={2}
2217
+ type="display-1"
2218
+ textWrap="balance"
2219
+ xstyle={[
2220
+ styles.type(
2221
+ headline.size ?? 0,
2222
+ headline.tracking ?? 0,
2223
+ headline.line ?? 100,
2224
+ headline.color ?? '#111111',
2225
+ headline.stroke ?? 0,
2226
+ shadowCss(headline.textShadow),
2227
+ ),
2228
+ typeAlign[headline.alignX ?? 'start'],
2229
+ typeCase[
2230
+ headline.transform ?? 'none'
2231
+ ],
2232
+ typeLine[
2233
+ headline.decoration ?? 'none'
2234
+ ],
2235
+ typeSlant[
2236
+ headline.isItalic
2237
+ ? 'italic'
2238
+ : 'normal'
2239
+ ],
2240
+ ]}>
2241
+ {headline.content}
2242
+ </Heading>
2243
+ </VStack>
2244
+ </AspectRatio>
2245
+ </Theme>
2246
+ </Card>
2247
+ </HStack>
2248
+ </LayoutContent>
2249
+ }
2250
+ footer={
2251
+ chrome.toolbar ? (
2252
+ <LayoutFooter>
2253
+ <Center>
2254
+ {/* Padding of one step, and the controls
2255
+ inside round to the card's radius less that
2256
+ step — see styles.toolBarControl. */}
2257
+ <Card padding={1} elevation="high">
2258
+ <Toolbar
2259
+ label="Canvas tools"
2260
+ size="sm"
2261
+ startContent={
2262
+ <>
2263
+ <IconButton
2264
+ label="Undo"
2265
+ tooltip="Undo"
2266
+ variant="ghost"
2267
+ icon={
2268
+ <Icon icon={Undo2} size={ICON} />
2269
+ }
2270
+ xstyle={styles.toolBarControl}
2271
+ />
2272
+ <IconButton
2273
+ label="Redo"
2274
+ tooltip="Redo"
2275
+ variant="ghost"
2276
+ icon={
2277
+ <Icon icon={Redo2} size={ICON} />
2278
+ }
2279
+ xstyle={styles.toolBarControl}
2280
+ />
2281
+ <Divider
2282
+ orientation="vertical"
2283
+ xstyle={styles.toolBarRule}
2284
+ />
2285
+ <IconButton
2286
+ label="Add frame"
2287
+ tooltip="Add frame"
2288
+ variant="ghost"
2289
+ icon={
2290
+ <Icon icon={Frame} size={ICON} />
2291
+ }
2292
+ xstyle={styles.toolBarControl}
2293
+ />
2294
+ <IconButton
2295
+ label="Add text"
2296
+ tooltip="Add text"
2297
+ variant="ghost"
2298
+ icon={
2299
+ <Icon icon={Type} size={ICON} />
2300
+ }
2301
+ xstyle={styles.toolBarControl}
2302
+ />
2303
+ <IconButton
2304
+ label="Add image"
2305
+ tooltip="Add image"
2306
+ variant="ghost"
2307
+ icon={
2308
+ <Icon
2309
+ icon={ImageIcon}
2310
+ size={ICON}
2311
+ />
2312
+ }
2313
+ xstyle={styles.toolBarControl}
2314
+ />
2315
+ <Divider
2316
+ orientation="vertical"
2317
+ xstyle={styles.toolBarRule}
2318
+ />
2319
+ <Selector
2320
+ label="Zoom"
2321
+ isLabelHidden
2322
+ variant="ghost"
2323
+ value={zoom}
2324
+ onChange={setZoom}
2325
+ options={ZOOM_OPTIONS}
2326
+ placement="above"
2327
+ // Fixed so the bar does not reflow
2328
+ // as the value changes, and wide
2329
+ // enough for the longest option
2330
+ // ("100%") to avoid truncation.
2331
+ width={92}
2332
+ xstyle={[
2333
+ styles.toolBarControl,
2334
+ styles.toolBarTrailing,
2335
+ ]}
2336
+ />
2337
+ </>
2338
+ }
2339
+ />
2340
+ </Card>
2341
+ </Center>
2342
+ </LayoutFooter>
2343
+ ) : undefined
2344
+ }
2345
+ />
2346
+ </Section>
2347
+ </LayoutContent>
2348
+ }
2349
+ end={
2350
+ chrome.right ? (
2351
+ <>
2352
+ <ResizeHandle
2353
+ resizable={inspector.props}
2354
+ isReversed
2355
+ isAlwaysVisible={false}
2356
+ pillPlacement="center"
2357
+ label="Resize properties panel"
2358
+ xstyle={styles.foldsAtInspector}
2359
+ />
2360
+ <LayoutPanel
2361
+ resizable={inspector.props}
2362
+ hasDivider
2363
+ padding={0}
2364
+ isScrollable
2365
+ label={`${selected.name} properties`}
2366
+ xstyle={styles.foldsAtInspector}>
2367
+ <InspectorSection title="Layout">
2368
+ <InspectorRow label="Padding">
2369
+ <AxisInput
2370
+ icon={PanelLeftRightDashed}
2371
+ label="Horizontal padding"
2372
+ value={selected.paddingInline}
2373
+ onChange={next =>
2374
+ updateSelected({paddingInline: next})
2375
+ }
2376
+ />
2377
+ <AxisInput
2378
+ icon={PanelTopBottomDashed}
2379
+ label="Vertical padding"
2380
+ value={selected.paddingBlock}
2381
+ onChange={next =>
2382
+ updateSelected({paddingBlock: next})
2383
+ }
2384
+ />
2385
+ <IconButton
2386
+ label="Set padding per side"
2387
+ tooltip="Per side"
2388
+ size="sm"
2389
+ variant="ghost"
2390
+ icon={<Icon icon={SquareSquare} size={ICON} />}
2391
+ />
2392
+ </InspectorRow>
2393
+ </InspectorSection>
2394
+
2395
+ <InspectorSection title="Layer">
2396
+ <InspectorRow label="Position">
2397
+ <AxisInput
2398
+ icon={GLYPH.x}
2399
+ label="Horizontal position"
2400
+ value={selected.x}
2401
+ onChange={next => updateSelected({x: next})}
2402
+ />
2403
+ <AxisInput
2404
+ icon={GLYPH.y}
2405
+ label="Vertical position"
2406
+ value={selected.y}
2407
+ onChange={next => updateSelected({y: next})}
2408
+ />
2409
+ </InspectorRow>
2410
+ <InspectorRow label="Size">
2411
+ <AxisInput
2412
+ icon={GLYPH.width}
2413
+ label="Width"
2414
+ value={selected.width}
2415
+ onChange={next => updateSelected({width: next})}
2416
+ />
2417
+ <AxisInput
2418
+ icon={GLYPH.height}
2419
+ label="Height"
2420
+ value={selected.height}
2421
+ onChange={next => updateSelected({height: next})}
2422
+ />
2423
+ </InspectorRow>
2424
+ </InspectorSection>
2425
+
2426
+ <InspectorSection title="Styles">
2427
+ <InspectorRow label="Radius">
2428
+ <AxisInput
2429
+ icon={Scan}
2430
+ label="Corner radius"
2431
+ value={selected.radius}
2432
+ onChange={next => updateSelected({radius: next})}
2433
+ />
2434
+ <IconButton
2435
+ label="Set radius per corner"
2436
+ tooltip="Per corner"
2437
+ size="sm"
2438
+ variant="ghost"
2439
+ icon={
2440
+ <Icon icon={SquareRoundCorner} size={ICON} />
2441
+ }
2442
+ />
2443
+ </InspectorRow>
2444
+ <StyleRow
2445
+ label="Border"
2446
+ value={selected.border}
2447
+ placeholder="Add…"
2448
+ onChange={next => updateSelected({border: next})}
2449
+ onClear={() => updateSelected({border: undefined})}
2450
+ />
2451
+ <StyleRow
2452
+ label="Shadow"
2453
+ name="Box shadow"
2454
+ value={selected.shadow?.color}
2455
+ placeholder="Add…"
2456
+ onChange={next =>
2457
+ updateSelected({
2458
+ shadow: {
2459
+ ...(selected.shadow ?? NO_SHADOW),
2460
+ color: next,
2461
+ },
2462
+ })
2463
+ }
2464
+ onClear={() => updateSelected({shadow: undefined})}>
2465
+ <ShadowFields
2466
+ name="Box shadow"
2467
+ shadow={selected.shadow ?? NO_SHADOW}
2468
+ onChange={next => updateSelected({shadow: next})}
2469
+ />
2470
+ </StyleRow>
2471
+ <StyleRow
2472
+ label="Fill"
2473
+ value={selected.fill}
2474
+ placeholder="Add…"
2475
+ onChange={next => updateSelected({fill: next})}
2476
+ onClear={() => updateSelected({fill: undefined})}
2477
+ />
2478
+ </InspectorSection>
2479
+
2480
+ <InspectorSection title="Transforms">
2481
+ <InspectorRow label="Rotate">
2482
+ <AxisInput
2483
+ icon={TriangleRight}
2484
+ label="Rotation"
2485
+ value={selected.rotation}
2486
+ onChange={next =>
2487
+ updateSelected({rotation: next})
2488
+ }
2489
+ />
2490
+ <IconButton
2491
+ label="Rotate counterclockwise"
2492
+ tooltip="−90°"
2493
+ size="sm"
2494
+ variant="ghost"
2495
+ onClick={() =>
2496
+ updateSelected({
2497
+ rotation: (selected.rotation + 270) % 360,
2498
+ })
2499
+ }
2500
+ icon={<Icon icon={RotateCcw} size={ICON} />}
2501
+ />
2502
+ <IconButton
2503
+ label="Rotate clockwise"
2504
+ tooltip="+90°"
2505
+ size="sm"
2506
+ variant="ghost"
2507
+ onClick={() =>
2508
+ updateSelected({
2509
+ rotation: (selected.rotation + 90) % 360,
2510
+ })
2511
+ }
2512
+ icon={<Icon icon={RotateCw} size={ICON} />}
2513
+ />
2514
+ </InspectorRow>
2515
+ <InspectorRow label="Flip" hAlign="end">
2516
+ <IconButton
2517
+ label="Flip horizontally"
2518
+ tooltip="Flip horizontally"
2519
+ size="sm"
2520
+ variant="ghost"
2521
+ icon={<Icon icon={FlipHorizontal2} size={ICON} />}
2522
+ />
2523
+ <IconButton
2524
+ label="Flip vertically"
2525
+ tooltip="Flip vertically"
2526
+ size="sm"
2527
+ variant="ghost"
2528
+ icon={<Icon icon={FlipVertical2} size={ICON} />}
2529
+ />
2530
+ </InspectorRow>
2531
+ </InspectorSection>
2532
+
2533
+ {selected.kind === 'text' ? (
2534
+ <InspectorSection title="Text">
2535
+ <TextArea
2536
+ label="Content"
2537
+ isLabelHidden
2538
+ size="sm"
2539
+ rows={2}
2540
+ value={selected.content}
2541
+ onChange={next => updateSelected({content: next})}
2542
+ />
2543
+ <InspectorRow label="Font">
2544
+ <StackItem size="fill">
2545
+ <Selector
2546
+ label="Font family"
2547
+ isLabelHidden
2548
+ size="sm"
2549
+ value={selected.family}
2550
+ onChange={next =>
2551
+ updateSelected({family: next})
2552
+ }
2553
+ options={FONT_OPTIONS}
2554
+ />
2555
+ </StackItem>
2556
+ </InspectorRow>
2557
+ <InspectorRow label="Weight">
2558
+ <StackItem size="fill">
2559
+ <Selector
2560
+ label="Font weight"
2561
+ isLabelHidden
2562
+ size="sm"
2563
+ value={selected.weight}
2564
+ onChange={next =>
2565
+ updateSelected({weight: next})
2566
+ }
2567
+ options={WEIGHT_OPTIONS}
2568
+ />
2569
+ </StackItem>
2570
+ </InspectorRow>
2571
+ <InspectorRow label="Color">
2572
+ <StackItem size="fill">
2573
+ <TextInput
2574
+ label="Text colour"
2575
+ isLabelHidden
2576
+ size="sm"
2577
+ value={selected.color ?? ''}
2578
+ onChange={next =>
2579
+ updateSelected({color: next})
2580
+ }
2581
+ />
2582
+ </StackItem>
2583
+ <Swatch
2584
+ label="Text colour"
2585
+ value={selected.color}
2586
+ onChange={next => updateSelected({color: next})}
2587
+ />
2588
+ </InspectorRow>
2589
+ <StepperRow
2590
+ label="Size"
2591
+ value={selected.size ?? 0}
2592
+ onChange={next => updateSelected({size: next})}
2593
+ />
2594
+ <StepperRow
2595
+ label="Line"
2596
+ value={selected.line ?? 100}
2597
+ onChange={next => updateSelected({line: next})}
2598
+ />
2599
+ <StepperRow
2600
+ label="Spacing"
2601
+ value={selected.tracking ?? 0}
2602
+ onChange={next =>
2603
+ updateSelected({tracking: next})
2604
+ }
2605
+ />
2606
+ <InspectorRow label="Align">
2607
+ <StackItem size="fill">
2608
+ <SegmentedControl
2609
+ label="Horizontal alignment"
2610
+ size="sm"
2611
+ layout="fill"
2612
+ value={selected.alignX ?? 'start'}
2613
+ onChange={next =>
2614
+ updateSelected({alignX: next as AlignX})
2615
+ }>
2616
+ {ALIGN_X.map(option => (
2617
+ <SegmentedControlItem
2618
+ key={option.value}
2619
+ value={option.value}
2620
+ label={option.label}
2621
+ isLabelHidden
2622
+ icon={
2623
+ <Icon icon={option.icon} size={ICON} />
2624
+ }
2625
+ />
2626
+ ))}
2627
+ </SegmentedControl>
2628
+ </StackItem>
2629
+ </InspectorRow>
2630
+ <InspectorRow label="Align">
2631
+ <StackItem size="fill">
2632
+ <SegmentedControl
2633
+ label="Vertical alignment"
2634
+ size="sm"
2635
+ layout="fill"
2636
+ value={selected.alignY ?? 'start'}
2637
+ onChange={next =>
2638
+ updateSelected({alignY: next as AlignY})
2639
+ }>
2640
+ {ALIGN_Y.map(option => (
2641
+ <SegmentedControlItem
2642
+ key={option.value}
2643
+ value={option.value}
2644
+ label={option.label}
2645
+ isLabelHidden
2646
+ icon={
2647
+ <Icon icon={option.icon} size={ICON} />
2648
+ }
2649
+ />
2650
+ ))}
2651
+ </SegmentedControl>
2652
+ </StackItem>
2653
+ </InspectorRow>
2654
+ <InspectorRow label="Style">
2655
+ <StackItem size="fill">
2656
+ <SegmentedControl
2657
+ label="Font style"
2658
+ size="sm"
2659
+ layout="fill"
2660
+ value={
2661
+ selected.isItalic ? 'italic' : 'normal'
2662
+ }
2663
+ onChange={next =>
2664
+ updateSelected({
2665
+ isItalic: next === 'italic',
2666
+ })
2667
+ }>
2668
+ <SegmentedControlItem
2669
+ value="normal"
2670
+ label="Regular"
2671
+ isLabelHidden
2672
+ icon={<Icon icon={Baseline} size={ICON} />}
2673
+ />
2674
+ <SegmentedControlItem
2675
+ value="italic"
2676
+ label="Italic"
2677
+ isLabelHidden
2678
+ icon={<Icon icon={Italic} size={ICON} />}
2679
+ />
2680
+ </SegmentedControl>
2681
+ </StackItem>
2682
+ </InspectorRow>
2683
+ <InspectorRow label="Decoration">
2684
+ <StackItem size="fill">
2685
+ <SegmentedControl
2686
+ label="Text decoration"
2687
+ size="sm"
2688
+ layout="fill"
2689
+ value={selected.decoration ?? 'none'}
2690
+ onChange={next =>
2691
+ updateSelected({
2692
+ decoration: next as Decoration,
2693
+ })
2694
+ }>
2695
+ {DECORATIONS.map(option => (
2696
+ <SegmentedControlItem
2697
+ key={option.value}
2698
+ value={option.value}
2699
+ label={option.label}
2700
+ isLabelHidden
2701
+ icon={
2702
+ <Icon icon={option.icon} size={ICON} />
2703
+ }
2704
+ />
2705
+ ))}
2706
+ </SegmentedControl>
2707
+ </StackItem>
2708
+ </InspectorRow>
2709
+ <InspectorRow label="Transform">
2710
+ <StackItem size="fill">
2711
+ <SegmentedControl
2712
+ label="Text transform"
2713
+ size="sm"
2714
+ layout="fill"
2715
+ value={selected.transform ?? 'none'}
2716
+ onChange={next =>
2717
+ updateSelected({
2718
+ transform: next as Transform,
2719
+ })
2720
+ }>
2721
+ {TRANSFORMS.map(option => (
2722
+ <SegmentedControlItem
2723
+ key={option.value}
2724
+ value={option.value}
2725
+ label={option.label}
2726
+ isLabelHidden
2727
+ icon={
2728
+ <Icon icon={option.icon} size={ICON} />
2729
+ }
2730
+ />
2731
+ ))}
2732
+ </SegmentedControl>
2733
+ </StackItem>
2734
+ </InspectorRow>
2735
+ <StyleRow
2736
+ label="Shadow"
2737
+ name="Text shadow"
2738
+ value={selected.textShadow?.color}
2739
+ placeholder="Add…"
2740
+ onChange={next =>
2741
+ updateSelected({
2742
+ textShadow: {
2743
+ ...(selected.textShadow ?? NO_SHADOW),
2744
+ color: next,
2745
+ },
2746
+ })
2747
+ }
2748
+ onClear={() =>
2749
+ updateSelected({textShadow: undefined})
2750
+ }>
2751
+ <ShadowFields
2752
+ name="Text shadow"
2753
+ shadow={selected.textShadow ?? NO_SHADOW}
2754
+ onChange={next =>
2755
+ updateSelected({textShadow: next})
2756
+ }
2757
+ />
2758
+ </StyleRow>
2759
+ <InspectorRow label="Stroke">
2760
+ <StackItem size="fill">
2761
+ <NumberInput
2762
+ label="Text stroke"
2763
+ isLabelHidden
2764
+ size="sm"
2765
+ value={selected.stroke ?? 0}
2766
+ onChange={next =>
2767
+ updateSelected({stroke: next})
2768
+ }
2769
+ isWheelEnabled={false}
2770
+ />
2771
+ </StackItem>
2772
+ <IconButton
2773
+ label="Clear stroke"
2774
+ tooltip="Clear"
2775
+ size="sm"
2776
+ variant="ghost"
2777
+ isDisabled={!selected.stroke}
2778
+ onClick={() => updateSelected({stroke: 0})}
2779
+ icon={<Icon icon={X} size={ICON} />}
2780
+ />
2781
+ </InspectorRow>
2782
+ </InspectorSection>
2783
+ ) : (
2784
+ <>
2785
+ <InspectorSection title="Image">
2786
+ <InspectorRow label="Edit">
2787
+ <StackItem size="fill">
2788
+ <TextInput
2789
+ label="Image source"
2790
+ isLabelHidden
2791
+ size="sm"
2792
+ value={imageName}
2793
+ isReadOnly
2794
+ />
2795
+ </StackItem>
2796
+ {/* Astryx's FileInput is fixed at the medium
2797
+ element height, and this row is built on the
2798
+ 28px rhythm the rest of the inspector keeps,
2799
+ so the picker is driven from the thumbnail
2800
+ instead. The input stays in the DOM — hiding
2801
+ it with the attribute rather than unmounting
2802
+ it is what lets the button open it. */}
2803
+ <input
2804
+ ref={fileRef}
2805
+ type="file"
2806
+ accept="image/*"
2807
+ hidden
2808
+ onChange={event => {
2809
+ const file = event.target.files?.[0];
2810
+ if (file) {
2811
+ setImageName(file.name);
2812
+ }
2813
+ }}
2814
+ />
2815
+ {/* The trigger shows the picture rather than
2816
+ an icon standing in for one: the row is about
2817
+ which image this is. `onClick` is what gives
2818
+ Thumbnail its button semantics and hover
2819
+ overlay, and `label` doubles as the tooltip. */}
2820
+ <Thumbnail
2821
+ src={PHOTO_LAYER_SRC}
2822
+ alt={`Current image, ${imageName}`}
2823
+ label="Replace image"
2824
+ onClick={() => fileRef.current?.click()}
2825
+ xstyle={styles.sourceThumbnail}
2826
+ />
2827
+ </InspectorRow>
2828
+ <InspectorRow label="Fit">
2829
+ <StackItem size="fill">
2830
+ <Selector
2831
+ label="Image fit"
2832
+ isLabelHidden
2833
+ size="sm"
2834
+ value={selected.fit ?? 'Cover'}
2835
+ onChange={next =>
2836
+ updateSelected({fit: next})
2837
+ }
2838
+ options={['Cover', 'Contain', 'Fill']}
2839
+ />
2840
+ </StackItem>
2841
+ </InspectorRow>
2842
+ </InspectorSection>
2843
+ <InspectorSection title="Filters">
2844
+ {FILTERS.map(filter => (
2845
+ <FilterRow
2846
+ key={filter.key}
2847
+ filter={filter}
2848
+ value={
2849
+ (selected.filters ?? NO_FILTERS)[filter.key]
2850
+ }
2851
+ onChange={next =>
2852
+ updateSelected({
2853
+ filters: {
2854
+ ...(selected.filters ?? NO_FILTERS),
2855
+ [filter.key]: next,
2856
+ },
2857
+ })
2858
+ }
2859
+ />
2860
+ ))}
2861
+ </InspectorSection>
2862
+ </>
2863
+ )}
2864
+ </LayoutPanel>
2865
+ </>
2866
+ ) : undefined
2867
+ }
2868
+ />
2869
+ </LayoutContent>
2870
+ }
2871
+ />
2872
+ </Section>
2873
+ </Theme>
2874
+ );
2875
+ }