@widgetic/creator 0.4.35 → 0.4.37

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,585 @@
1
+ <script lang="ts">
2
+ import { writable } from 'svelte/store';
3
+ import { DropdownMenu, Portal } from '@widgetic/design-system';
4
+ import { FontInputController } from '@widgetic/editor';
5
+ import FileUrlSourceControl from './FileUrlSourceControl.svelte';
6
+ import HoverTooltip from './HoverTooltip.svelte';
7
+ import { eventPathMatches } from '../host/creatorHost.js';
8
+ import { useCreatorLanguage } from '../i18n/index.js';
9
+ import { useTextDirection } from '@widgetic/design-system/components/textDirection';
10
+ import { popUpLeftFromAnchor } from '../utils/directionPlacement.js';
11
+
12
+ const { t } = useCreatorLanguage();
13
+ // The direction of the screen the panel is on (a panel with no screen around it reads left to right).
14
+ const textDirection = useTextDirection();
15
+
16
+ interface FontModel {
17
+ family: string;
18
+ weight: string;
19
+ category: string;
20
+ }
21
+
22
+ interface Props {
23
+ class?: string;
24
+ style?: string;
25
+ part?: 'checks' | 'panel';
26
+ brandKitEnabled?: boolean;
27
+ librariesEnabled?: boolean;
28
+ showPresetLibraries?: boolean;
29
+ suspendPickers?: boolean;
30
+ primary?: string;
31
+ secondary?: string;
32
+ title?: string;
33
+ sub?: string;
34
+ fonts?: string[];
35
+ libraries?: string[];
36
+ libraryGitUrl?: string;
37
+ libraryFileName?: string;
38
+ libraryUploads?: { name: string; content: string; encoding: string }[];
39
+ fontUploads?: { name: string; content: string; encoding: string }[];
40
+ showBrandKit?: boolean;
41
+ showLanguage?: boolean;
42
+ language?: string;
43
+ languageLocked?: boolean;
44
+ }
45
+
46
+ const maxFonts = 3;
47
+
48
+ let {
49
+ class: className = '',
50
+ style = '',
51
+ part = 'checks',
52
+ brandKitEnabled = $bindable(false),
53
+ librariesEnabled = $bindable(false),
54
+ showPresetLibraries = false,
55
+ suspendPickers = false,
56
+ primary = $bindable('#314F2F'),
57
+ secondary = $bindable('#7BA668'),
58
+ title = $bindable('#0F2010'),
59
+ sub = $bindable('#5C6B58'),
60
+ fonts = $bindable(['Inter']),
61
+ libraries = $bindable([] as string[]),
62
+ libraryGitUrl = $bindable(''),
63
+ libraryFileName = $bindable(''),
64
+ libraryUploads = $bindable([] as { name: string; content: string; encoding: string }[]),
65
+ fontUploads = $bindable([] as { name: string; content: string; encoding: string }[]),
66
+ showBrandKit = false,
67
+ showLanguage = false,
68
+ language = $bindable('react'),
69
+ languageLocked = false,
70
+ }: Props = $props();
71
+
72
+ const libraryChoices = [
73
+ { id: 'chart.js/auto', label: 'Chart.js' },
74
+ { id: 'd3', label: 'D3' },
75
+ { id: 'gsap', label: 'GSAP' },
76
+ { id: 'three', label: 'Three.js' },
77
+ ];
78
+
79
+ // FontInputController requires a store for its open-dropdown contract.
80
+ const openDropdowns = writable(new Set<string>());
81
+
82
+ let fontModels = $state<FontModel[]>(
83
+ (fonts.length ? fonts : ['Inter']).slice(0, maxFonts).map((family) => ({
84
+ family,
85
+ weight: '400',
86
+ category: 'sans-serif',
87
+ })),
88
+ );
89
+
90
+ function publishFonts() {
91
+ fonts = fontModels.map((model) => model.family);
92
+ }
93
+
94
+ function toggleDropdown(id: string) {
95
+ openDropdowns.update((current) => {
96
+ const next = new Set(current);
97
+ if (next.has(id)) next.delete(id);
98
+ else {
99
+ next.clear();
100
+ next.add(id);
101
+ }
102
+ return next;
103
+ });
104
+ }
105
+
106
+ function updateFont(index: number, next: { family?: string } | null) {
107
+ const family = next?.family?.trim() || 'Inter';
108
+ if (fontModels[index]?.family === family) return;
109
+ fontModels[index] = { family, weight: '400', category: 'sans-serif' };
110
+ publishFonts();
111
+ }
112
+
113
+ function addFont() {
114
+ if (fontModels.length >= maxFonts) return;
115
+ fontModels = [...fontModels, { family: 'Inter', weight: '400', category: 'sans-serif' }];
116
+ publishFonts();
117
+ }
118
+
119
+ function removeFont(index: number) {
120
+ if (fontModels.length <= 1) return;
121
+ fontModels = fontModels.filter((_, entryIndex) => entryIndex !== index);
122
+ publishFonts();
123
+ }
124
+
125
+ function toggleLibrary(id: string) {
126
+ const next = libraries.includes(id)
127
+ ? libraries.filter((entry) => entry !== id)
128
+ : [...libraries, id];
129
+ libraries = next;
130
+ if (next.length > 0) librariesEnabled = true;
131
+ }
132
+
133
+ let iconFileName = $state('');
134
+ let iconUrl = $state('');
135
+
136
+ type SourceRow = { id: string; fileName: string; url: string; content: string; encoding: string };
137
+ const emptySource = (): SourceRow => ({
138
+ id: crypto.randomUUID(),
139
+ fileName: '',
140
+ url: '',
141
+ content: '',
142
+ encoding: 'utf8',
143
+ });
144
+ let libraryRows = $state<SourceRow[]>([emptySource()]);
145
+ let iconRows = $state<SourceRow[]>([emptySource()]);
146
+
147
+ function addSourceRow(kind: 'library' | 'icon') {
148
+ const rows = kind === 'library' ? libraryRows : iconRows;
149
+ if (rows.length >= 4) return;
150
+ const next = [emptySource(), ...rows];
151
+ if (kind === 'library') libraryRows = next;
152
+ else iconRows = next;
153
+ }
154
+
155
+ function removeSourceRow(kind: 'library' | 'icon', id: string) {
156
+ const rows = kind === 'library' ? libraryRows : iconRows;
157
+ const next = rows.filter((row) => row.id !== id);
158
+ const kept = next.length > 0 ? next : [emptySource()];
159
+ if (kind === 'library') libraryRows = kept;
160
+ else iconRows = kept;
161
+ }
162
+
163
+ let fontFileName = $state('');
164
+ let fontFileContent = $state('');
165
+ let fontFileEncoding = $state('base64');
166
+ let fontFileUrl = $state('');
167
+
168
+ function clearFontUpload() {
169
+ fontFileName = '';
170
+ fontFileContent = '';
171
+ fontFileEncoding = 'base64';
172
+ fontFileUrl = '';
173
+ }
174
+
175
+ $effect(() => {
176
+ libraryFileName = libraryRows[0]?.fileName || '';
177
+ libraryGitUrl = libraryRows[0]?.url || '';
178
+ iconFileName = iconRows[0]?.fileName || '';
179
+ iconUrl = iconRows[0]?.url || '';
180
+ libraryUploads = [...libraryRows, ...iconRows]
181
+ .filter((row) => row.fileName && row.content)
182
+ .map((row) => ({ name: row.fileName, content: row.content, encoding: row.encoding }));
183
+ fontUploads = fontFileName && fontFileContent
184
+ ? [{ name: fontFileName, content: fontFileContent, encoding: fontFileEncoding || 'base64' }]
185
+ : [];
186
+ });
187
+
188
+ let brandPanelOpen = $state(false);
189
+ let brandPanelMaxHeight = $state(0);
190
+ let brandButtonEl = $state<HTMLLabelElement | null>(null);
191
+ let brandPopoverEl = $state<HTMLDivElement | null>(null);
192
+ let brandPanelTop = $state(0);
193
+ let brandPanelLeft = $state(0);
194
+
195
+ function placePopover(anchor: HTMLElement | null, panel: HTMLElement | null, width: number) {
196
+ if (!anchor) return { top: 0, left: 8 };
197
+ const rect = anchor.getBoundingClientRect();
198
+ const height = panel?.offsetHeight || 320;
199
+ // Its start edge is lined up with the start edge of the button: the left one on a left to right screen, the right one on a right to left screen.
200
+ const left = popUpLeftFromAnchor($textDirection, rect, width, window.innerWidth, 8);
201
+ const below = rect.bottom + 6;
202
+ const fitsBelow = below + height <= window.innerHeight - 8;
203
+ const top = fitsBelow ? below : Math.max(8, rect.top - height - 6);
204
+ return { top, left };
205
+ }
206
+
207
+ function closeFontPickers() {
208
+ openDropdowns.set(new Set());
209
+ }
210
+
211
+ function onBrandKitChange(event: Event) {
212
+ brandKitEnabled = (event.currentTarget as HTMLInputElement).checked;
213
+ closeFontPickers();
214
+ brandPanelOpen = brandKitEnabled;
215
+ if (!brandKitEnabled) brandPanelMaxHeight = 0;
216
+ }
217
+
218
+ function onLibrariesChange(event: Event) {
219
+ librariesEnabled = (event.currentTarget as HTMLInputElement).checked;
220
+ }
221
+
222
+ function componentExtension() {
223
+ return language === 'react' ? '.jsx' : '.svelte';
224
+ }
225
+
226
+ function sourceAccept(includeSvg: boolean) {
227
+ const extensions = ['.js', '.ts', componentExtension(), '.zip', '.tar', '.tgz', '.gz'];
228
+ if (includeSvg) extensions.unshift('.svg');
229
+ return extensions.join(',');
230
+ }
231
+
232
+ // Words a visitor reads, in the page's language: the function reads `$t`, so a language the page sets later is read on the next draw.
233
+ function uploadTooltip(includeSvg: boolean) {
234
+ return includeSvg ? $t('creator.brandKit.uploadIconLibraryTooltip') : $t('creator.brandKit.uploadCustomLibraryTooltip');
235
+ }
236
+
237
+ function urlPlaceholder(includeSvg: boolean) {
238
+ const extension = componentExtension();
239
+ return includeSvg
240
+ ? $t('creator.brandKit.urlIcons', { extension })
241
+ : $t('creator.brandKit.urlLibraries', { extension });
242
+ }
243
+
244
+ $effect(() => {
245
+ if (!brandPanelOpen) return;
246
+
247
+ function place() {
248
+ const brandPlace = placePopover(brandButtonEl, brandPopoverEl, 320);
249
+ brandPanelTop = brandPlace.top;
250
+ brandPanelLeft = brandPlace.left;
251
+ const openHeight = brandPopoverEl?.offsetHeight || 0;
252
+ if (openHeight > 0 && brandPanelMaxHeight === 0) brandPanelMaxHeight = openHeight;
253
+ }
254
+
255
+ function onPointerDown(event: PointerEvent) {
256
+ // The whole path is looked at, not `event.target`: from `window` the target of a press inside a shadow root is
257
+ // the shadow's host element, so every press, the popover's own included, would count as outside it.
258
+ if (brandButtonEl && event.composedPath().includes(brandButtonEl)) return;
259
+ if (eventPathMatches(event, '.generation-brand-kit-popover, .font-input-popover, #widgetic-font-picker-portal')) return;
260
+ closeFontPickers();
261
+ brandPanelOpen = false;
262
+ brandPanelMaxHeight = 0;
263
+ }
264
+
265
+ place();
266
+ const frame = requestAnimationFrame(place);
267
+ window.addEventListener('pointerdown', onPointerDown, true);
268
+ window.addEventListener('resize', place);
269
+ window.addEventListener('scroll', place, true);
270
+ return () => {
271
+ cancelAnimationFrame(frame);
272
+ window.removeEventListener('pointerdown', onPointerDown, true);
273
+ window.removeEventListener('resize', place);
274
+ window.removeEventListener('scroll', place, true);
275
+ };
276
+ });
277
+ </script>
278
+
279
+ {#if part === 'checks'}
280
+ <div class="generation-options-checks contents {className}" {style}>
281
+ {#if showBrandKit}
282
+ <label
283
+ class="generation-brand-kit-toggle ms-auto flex h-10 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border px-2 text-sm {brandKitEnabled ? 'border-[#314F2F] bg-[#314F2F] text-white' : 'border-gray-300 bg-white text-gray-800'}"
284
+ bind:this={brandButtonEl}
285
+ >
286
+ <input
287
+ class="generation-option-check cursor-pointer"
288
+ type="checkbox"
289
+ checked={brandKitEnabled}
290
+ onchange={onBrandKitChange}
291
+ />
292
+ {$t('creator.brandKit.brandKit')}
293
+ </label>
294
+ {/if}
295
+ {#if showLanguage || showPresetLibraries}
296
+ <div class="generation-libraries-row flex w-full flex-col gap-2">
297
+ <div class="generation-libraries-checks flex flex-nowrap items-center gap-1">
298
+ {#if showLanguage}
299
+ {#if languageLocked}
300
+ <HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.languageIsFixedAfterThe')}>
301
+ <span
302
+ class="generation-language-select flex h-10 w-[4.75rem] shrink-0 cursor-default items-center justify-between gap-0.5 rounded-lg border border-gray-300 bg-white px-1.5 text-sm text-gray-900 opacity-60"
303
+ aria-disabled="true"
304
+ >
305
+ <span class="truncate">{language === 'react' ? 'React' : 'Svelte'}</span>
306
+ </span>
307
+ </HoverTooltip>
308
+ {:else}
309
+ <HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.selectLanguage')}>
310
+ <DropdownMenu.Root>
311
+ <DropdownMenu.Trigger
312
+ class="generation-language-select flex h-10 w-[4.75rem] shrink-0 cursor-pointer items-center justify-between gap-0.5 rounded-lg border border-gray-300 bg-white px-1.5 text-sm text-gray-900"
313
+ >
314
+ <span class="truncate">{language === 'react' ? 'React' : 'Svelte'}</span>
315
+ <svg class="h-3 w-3 shrink-0 text-gray-500" viewBox="0 0 12 12" fill="none" aria-hidden="true">
316
+ <path d="M3 4.5 6 7.5 9 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
317
+ </svg>
318
+ </DropdownMenu.Trigger>
319
+ <DropdownMenu.Content class="w-[4.75rem] min-w-0">
320
+ <DropdownMenu.Item
321
+ class="cursor-pointer {language === 'svelte' ? 'bg-[#314F2F]/15 text-[#314F2F]' : ''}"
322
+ onSelect={() => (language = 'svelte')}
323
+ >Svelte</DropdownMenu.Item>
324
+ <DropdownMenu.Item
325
+ class="cursor-pointer {language === 'react' ? 'bg-[#314F2F]/15 text-[#314F2F]' : ''}"
326
+ onSelect={() => (language = 'react')}
327
+ >React</DropdownMenu.Item>
328
+ </DropdownMenu.Content>
329
+ </DropdownMenu.Root>
330
+ </HoverTooltip>
331
+ {/if}
332
+ {/if}
333
+ {#if showPresetLibraries}
334
+ <label class="generation-option-toggle flex h-10 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border px-2 text-sm {librariesEnabled ? 'border-[#314F2F] bg-[#314F2F] text-white' : 'border-gray-300 bg-white text-gray-800'}">
335
+ <input class="generation-option-check cursor-pointer" type="checkbox" checked={librariesEnabled} onchange={onLibrariesChange} />
336
+ {$t('creator.brandKit.libraries')}
337
+ </label>
338
+ {/if}
339
+ {#if librariesEnabled && showPresetLibraries}
340
+ {#each libraryChoices as choice (choice.id)}
341
+ <label class="generation-library flex items-center gap-1 text-xs text-gray-700">
342
+ <input
343
+ class="generation-library-check cursor-pointer"
344
+ type="checkbox"
345
+ checked={libraries.includes(choice.id)}
346
+ onchange={() => toggleLibrary(choice.id)}
347
+ />
348
+ {choice.label}
349
+ </label>
350
+ {/each}
351
+ {/if}
352
+ {#if librariesEnabled && showPresetLibraries}
353
+ <HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.addLibrary')}>
354
+ <button
355
+ type="button"
356
+ class="generation-library-add flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white text-sm text-gray-800"
357
+ aria-label={$t('creator.brandKit.addLibrary')}
358
+ onclick={() => addSourceRow('library')}
359
+ >+</button>
360
+ </HoverTooltip>
361
+ {/if}
362
+ </div>
363
+ {#if librariesEnabled && showPresetLibraries}
364
+ {#each libraryRows as row (row.id)}
365
+ <div class="generation-source-row flex items-center gap-1">
366
+ <FileUrlSourceControl
367
+ class="min-w-0 flex-1"
368
+ bind:fileName={row.fileName}
369
+ bind:fileContent={row.content}
370
+ bind:fileEncoding={row.encoding}
371
+ bind:url={row.url}
372
+ fileLabel={$t('creator.brandKit.uploadLibrary')}
373
+ fileTitle={uploadTooltip(false)}
374
+ urlPlaceholder={urlPlaceholder(false)}
375
+ accept={sourceAccept(false)}
376
+ />
377
+ {#if libraryRows.length > 1}
378
+ <button
379
+ type="button"
380
+ class="generation-source-remove flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-gray-500"
381
+ aria-label={$t('creator.brandKit.removeLibrary')}
382
+ onclick={() => removeSourceRow('library', row.id)}
383
+ >
384
+ <svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
385
+ <path d="M4 7h16" />
386
+ <path d="M9 7V5h6v2" />
387
+ <path d="M8 7l1 13h6l1-13" />
388
+ </svg>
389
+ </button>
390
+ {/if}
391
+ </div>
392
+ {/each}
393
+ {/if}
394
+ </div>
395
+ {/if}
396
+ </div>
397
+ {#if showBrandKit && brandPanelOpen}
398
+ <Portal
399
+ target="generation-brand-kit-portal"
400
+ class="generation-brand-kit-portal-root"
401
+ style="position: fixed; top: {brandPanelTop}px; left: {brandPanelLeft}px; /* rtl-ok: worked out from where the button is on the screen and kept inside it, in pixels from the left edge */ width: 320px; height: auto;"
402
+ >
403
+ <div
404
+ class="generation-brand-kit-popover flex flex-col gap-3 overflow-y-auto rounded-lg border border-gray-200 bg-white p-3 shadow-lg"
405
+ style={brandPanelMaxHeight > 0 ? `max-height: ${brandPanelMaxHeight}px;` : ''}
406
+ bind:this={brandPopoverEl}
407
+ >
408
+ <p class="generation-options-note text-xs text-gray-500">{$t('creator.brandKit.replacesTheWidgeticPaletteFor')}</p>
409
+ <section class="generation-color-palette flex flex-col gap-2">
410
+ <h3 class="generation-section-title text-xs font-semibold text-gray-800">{$t('creator.brandKit.colorPalette')}</h3>
411
+ <div class="generation-brand-colors flex flex-wrap items-end gap-3">
412
+ <label class="generation-brand-color flex flex-col gap-1 text-xs text-gray-600">
413
+ {$t('creator.brandKit.primary')}
414
+ <input class="generation-brand-color-input h-8 w-14 cursor-pointer border border-gray-200 bg-white" type="color" bind:value={primary} />
415
+ </label>
416
+ <label class="generation-brand-color flex flex-col gap-1 text-xs text-gray-600">
417
+ {$t('creator.brandKit.secondary')}
418
+ <input class="generation-brand-color-input h-8 w-14 cursor-pointer border border-gray-200 bg-white" type="color" bind:value={secondary} />
419
+ </label>
420
+ <label class="generation-brand-color flex flex-col gap-1 text-xs text-gray-600">
421
+ {$t('creator.brandKit.title')}
422
+ <input class="generation-brand-color-input h-8 w-14 cursor-pointer border border-gray-200 bg-white" type="color" bind:value={title} />
423
+ </label>
424
+ <label class="generation-brand-color flex flex-col gap-1 text-xs text-gray-600">
425
+ {$t('creator.brandKit.sub')}
426
+ <input class="generation-brand-color-input h-8 w-14 cursor-pointer border border-gray-200 bg-white" type="color" bind:value={sub} />
427
+ </label>
428
+ </div>
429
+ </section>
430
+ <div class="generation-section-separator border-t border-gray-200"></div>
431
+ <section class="generation-brand-fonts flex flex-col gap-2">
432
+ <div class="generation-fonts-header flex items-center justify-between gap-2">
433
+ <h3 class="generation-section-title text-xs font-semibold text-gray-800">{$t('creator.brandKit.fonts')}</h3>
434
+ {#if fontModels.length < maxFonts && !suspendPickers}
435
+ <button
436
+ type="button"
437
+ class="generation-brand-font-add h-7 cursor-pointer rounded-md border border-gray-300 px-2 text-xs text-gray-700"
438
+ onclick={addFont}
439
+ >
440
+ {$t('creator.brandKit.addFont')}
441
+ </button>
442
+ {/if}
443
+ </div>
444
+ {#each fontModels as model, index (index)}
445
+ <div class="generation-brand-font-row flex items-start gap-2">
446
+ {#if suspendPickers}
447
+ <p class="generation-brand-font-name min-w-0 flex-1 py-2 text-sm text-gray-800">{model.family}</p>
448
+ {:else}
449
+ <div class="generation-brand-font-picker min-w-0 flex-1">
450
+ <FontInputController
451
+ label={index === 0 ? $t('creator.brandKit.fontLabel') : $t('creator.brandKit.font', { number: index + 1 })}
452
+ controllerId="generation-brand-font-{index}"
453
+ value={model}
454
+ {openDropdowns}
455
+ {toggleDropdown}
456
+ hideTrashIcon={true}
457
+ hideRecentFromList={true}
458
+ onChange={(next) => updateFont(index, next)}
459
+ />
460
+ </div>
461
+ {/if}
462
+ {#if fontModels.length > 1}
463
+ <button
464
+ type="button"
465
+ class="generation-brand-font-remove mt-1 flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-gray-500"
466
+ aria-label={$t('creator.brandKit.removeFont')}
467
+ onclick={() => removeFont(index)}
468
+ >
469
+ <svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
470
+ <path d="M4 7h16" />
471
+ <path d="M9 7V5h6v2" />
472
+ <path d="M8 7l1 13h6l1-13" />
473
+ </svg>
474
+ </button>
475
+ {/if}
476
+ </div>
477
+ {/each}
478
+ <div class="generation-font-upload flex items-center gap-1">
479
+ <FileUrlSourceControl
480
+ class="min-w-0 flex-1"
481
+ bind:fileName={fontFileName}
482
+ bind:fileContent={fontFileContent}
483
+ bind:fileEncoding={fontFileEncoding}
484
+ bind:url={fontFileUrl}
485
+ fileLabel={$t('creator.brandKit.uploadFonts')}
486
+ fileTitle={$t('creator.brandKit.uploadAFontFileOr')}
487
+ urlPlaceholder={$t('creator.brandKit.urlArchiveWoff2TtfOtf')}
488
+ accept=".woff,.woff2,.ttf,.otf,.eot,.zip,.tar,.tgz,.gz"
489
+ />
490
+ {#if fontFileName || fontFileUrl}
491
+ <button
492
+ type="button"
493
+ class="generation-source-remove flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-gray-500"
494
+ aria-label={$t('creator.brandKit.removeUploadedFont')}
495
+ onclick={clearFontUpload}
496
+ >
497
+ <svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
498
+ <path d="M4 7h16" />
499
+ <path d="M9 7V5h6v2" />
500
+ <path d="M8 7l1 13h6l1-13" />
501
+ </svg>
502
+ </button>
503
+ {/if}
504
+ </div>
505
+ </section>
506
+ <div class="generation-section-separator border-t border-gray-200"></div>
507
+ <section class="generation-brand-icons flex flex-col gap-2">
508
+ <div class="generation-icons-header flex items-center justify-between gap-2">
509
+ <h3 class="generation-section-title text-xs font-semibold text-gray-800">{$t('creator.brandKit.icons')}</h3>
510
+ <HoverTooltip text={$t('creator.brandKit.addIconLibrary')}>
511
+ <button
512
+ type="button"
513
+ class="generation-icon-add flex h-7 w-7 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-sm text-gray-700"
514
+ aria-label={$t('creator.brandKit.addIconLibrary')}
515
+ onclick={() => addSourceRow('icon')}
516
+ >+</button>
517
+ </HoverTooltip>
518
+ </div>
519
+ {#each iconRows as row (row.id)}
520
+ <div class="generation-source-row flex items-center gap-1">
521
+ <FileUrlSourceControl
522
+ class="min-w-0 flex-1"
523
+ bind:fileName={row.fileName}
524
+ bind:fileContent={row.content}
525
+ bind:fileEncoding={row.encoding}
526
+ bind:url={row.url}
527
+ fileLabel={$t('creator.brandKit.uploadLibrary')}
528
+ fileTitle={uploadTooltip(true)}
529
+ urlPlaceholder={urlPlaceholder(true)}
530
+ accept={sourceAccept(true)}
531
+ />
532
+ {#if iconRows.length > 1}
533
+ <button
534
+ type="button"
535
+ class="generation-source-remove flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-gray-500"
536
+ aria-label={$t('creator.brandKit.removeIconLibrary')}
537
+ onclick={() => removeSourceRow('icon', row.id)}
538
+ >
539
+ <svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
540
+ <path d="M4 7h16" />
541
+ <path d="M9 7V5h6v2" />
542
+ <path d="M8 7l1 13h6l1-13" />
543
+ </svg>
544
+ </button>
545
+ {/if}
546
+ </div>
547
+ {/each}
548
+ </section>
549
+ </div>
550
+ </Portal>
551
+ {/if}
552
+ {/if}
553
+
554
+ <style>
555
+ .generation-options-checks input:focus,
556
+ .generation-options-checks input:focus-visible,
557
+ .generation-brand-kit-popover button:focus,
558
+ .generation-brand-kit-popover button:focus-visible,
559
+ .generation-brand-kit-popover input:focus,
560
+ .generation-brand-kit-popover input:focus-visible,
561
+ .generation-language-select:focus,
562
+ .generation-language-select:focus-visible {
563
+ outline: none;
564
+ box-shadow: none;
565
+ }
566
+
567
+ .generation-brand-kit-popover {
568
+ scrollbar-width: thin;
569
+ scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
570
+ }
571
+
572
+ .generation-brand-kit-popover::-webkit-scrollbar {
573
+ width: 8px;
574
+ background: transparent;
575
+ }
576
+
577
+ .generation-brand-kit-popover::-webkit-scrollbar-track {
578
+ background: transparent;
579
+ }
580
+
581
+ .generation-brand-kit-popover::-webkit-scrollbar-thumb {
582
+ background: rgba(0, 0, 0, 0.2);
583
+ border-radius: 4px;
584
+ }
585
+ </style>
@@ -0,0 +1,34 @@
1
+ interface Props {
2
+ class?: string;
3
+ style?: string;
4
+ part?: 'checks' | 'panel';
5
+ brandKitEnabled?: boolean;
6
+ librariesEnabled?: boolean;
7
+ showPresetLibraries?: boolean;
8
+ suspendPickers?: boolean;
9
+ primary?: string;
10
+ secondary?: string;
11
+ title?: string;
12
+ sub?: string;
13
+ fonts?: string[];
14
+ libraries?: string[];
15
+ libraryGitUrl?: string;
16
+ libraryFileName?: string;
17
+ libraryUploads?: {
18
+ name: string;
19
+ content: string;
20
+ encoding: string;
21
+ }[];
22
+ fontUploads?: {
23
+ name: string;
24
+ content: string;
25
+ encoding: string;
26
+ }[];
27
+ showBrandKit?: boolean;
28
+ showLanguage?: boolean;
29
+ language?: string;
30
+ languageLocked?: boolean;
31
+ }
32
+ declare const BrandKitPanel: import("svelte").Component<Props, {}, "brandKitEnabled" | "librariesEnabled" | "primary" | "secondary" | "title" | "sub" | "fonts" | "libraries" | "libraryGitUrl" | "libraryFileName" | "libraryUploads" | "fontUploads" | "language">;
33
+ type BrandKitPanel = ReturnType<typeof BrandKitPanel>;
34
+ export default BrandKitPanel;
@@ -10,6 +10,6 @@ interface Props {
10
10
  urlPlaceholder?: string;
11
11
  accept?: string;
12
12
  }
13
- declare const FileUrlSourceControl: import("svelte").Component<Props, {}, "url" | "fileName" | "fileContent" | "fileEncoding">;
13
+ declare const FileUrlSourceControl: import("svelte").Component<Props, {}, "fileName" | "fileContent" | "fileEncoding" | "url">;
14
14
  type FileUrlSourceControl = ReturnType<typeof FileUrlSourceControl>;
15
15
  export default FileUrlSourceControl;
@@ -8,7 +8,6 @@
8
8
  * it); LIVE sits in the action slot with the exact width of PUBLISH, so
9
9
  * the right edge lines up across every row.
10
10
  */
11
- import { tick } from 'svelte';
12
11
  import HoverTooltip from './HoverTooltip.svelte';
13
12
  import { useCreatorLanguage } from '../i18n/index.js';
14
13
 
@@ -67,21 +66,6 @@
67
66
  let editingTitle = $state(false);
68
67
  let titleDraft = $state('');
69
68
  let titleInputEl: HTMLInputElement | null = $state(null);
70
- let rowEl: HTMLDivElement | null = $state(null);
71
-
72
- // Both menus open with the newest row at the top. Put the open version at the top of that window.
73
- $effect(() => {
74
- if (!selected || !rowEl) return;
75
- const node = rowEl;
76
- void tick().then(() => {
77
- requestAnimationFrame(() => {
78
- const scroller = node.closest('.widget-shape-version-scroll, .wc-version-history-scroll');
79
- if (!(scroller instanceof HTMLElement)) return;
80
- const rowTop = node.getBoundingClientRect().top - scroller.getBoundingClientRect().top + scroller.scrollTop;
81
- scroller.scrollTop = Math.max(0, rowTop);
82
- });
83
- });
84
- });
85
69
 
86
70
  function openTitleEditor(): void {
87
71
  if (!editableTitle || renameDisabled) return;
@@ -110,7 +94,6 @@
110
94
  </script>
111
95
 
112
96
  <div
113
- bind:this={rowEl}
114
97
  class="version-dropdown-row flex items-center justify-between gap-2 rounded px-2 py-1.5 w-full text-[10px] cursor-pointer {selected ? 'bg-emerald-200 text-emerald-950' : 'text-gray-700 hover:bg-emerald-100'}"
115
98
  role="option"
116
99
  aria-selected={selected}
@@ -186,8 +169,7 @@
186
169
  <span class="{COL_ACTION} flex shrink-0 items-center justify-center rounded bg-emerald-100 py-0.5 font-semibold uppercase tracking-wide text-emerald-600">{$t('creator.versions.live')}</span>
187
170
  {:else if isDraft}
188
171
  <HoverTooltip
189
- text={publishDisabledReason || $t('creator.common.buildThisDraftVersionAnd')}
190
- maxWidth={160}
172
+ text={publishDisabledReason || $t('creator.livePreviews.publishThisDraft')}
191
173
  class="inline-flex shrink-0"
192
174
  >
193
175
  <button