@datalayer/design 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/lib/App.js +4 -5
  3. package/lib/pages/HomePage.js +223 -45
  4. package/lib/pages/IconsPage.js +12 -4
  5. package/lib/pages/SvgPage.js +386 -106
  6. package/lib/svg/SvgAI.d.ts +11 -0
  7. package/lib/svg/SvgAI.js +15 -0
  8. package/lib/svg/SvgAI2.d.ts +11 -0
  9. package/lib/svg/SvgAI2.js +17 -0
  10. package/lib/svg/SvgAI3.d.ts +12 -0
  11. package/lib/svg/SvgAI3.js +60 -0
  12. package/lib/svg/SvgAssignmentArtifact.d.ts +8 -0
  13. package/lib/svg/SvgAssignmentArtifact.js +15 -0
  14. package/lib/svg/SvgCellOutputshotPlaceholder.d.ts +28 -0
  15. package/lib/svg/SvgCellOutputshotPlaceholder.js +70 -0
  16. package/lib/svg/SvgEarthHero.d.ts +2 -2
  17. package/lib/svg/SvgEarthHero.js +41 -8
  18. package/lib/svg/SvgEvalsHero.d.ts +15 -0
  19. package/lib/svg/SvgEvalsHero.js +23 -0
  20. package/lib/svg/SvgExerciseArtifact.d.ts +8 -0
  21. package/lib/svg/SvgExerciseArtifact.js +15 -0
  22. package/lib/svg/SvgLessonArtifact.d.ts +8 -0
  23. package/lib/svg/SvgLessonArtifact.js +15 -0
  24. package/lib/svg/SvgNotebookMock.d.ts +10 -0
  25. package/lib/svg/SvgNotebookMock.js +70 -0
  26. package/lib/svg/SvgOSAContributions.d.ts +11 -0
  27. package/lib/svg/SvgOSAContributions.js +25 -0
  28. package/lib/svg/SvgPartnersHero.d.ts +16 -0
  29. package/lib/svg/SvgPartnersHero.js +94 -0
  30. package/lib/svg/SvgPixel1.js +29 -2
  31. package/lib/svg/SvgPixel2.js +37 -8
  32. package/lib/svg/SvgSkubble.d.ts +11 -0
  33. package/lib/svg/SvgSkubble.js +23 -0
  34. package/lib/svg/gallery.d.ts +1 -1
  35. package/lib/svg/gallery.js +16 -1
  36. package/lib/svg/images/eric-charles-2.svg +1249 -0
  37. package/lib/svg/images/eric-charles.svg +1131 -0
  38. package/lib/svg/index.d.ts +17 -0
  39. package/lib/svg/index.js +12 -0
  40. package/package.json +11 -4
  41. package/lib/DatalayerIcons.d.ts +0 -2
  42. package/lib/DatalayerIcons.js +0 -169
@@ -1,17 +1,23 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { useNavigate, useParams } from 'react-router-dom';
4
- import { Box, Button, Heading, Text } from '@primer/react';
5
- import { AI, DatalayerLogo, DatalayerLogoText, DatalayerTextAI, getLogoColors, useColorPalette, useThemeStore, } from '@datalayer/primer-addons';
4
+ import { ActionList, ActionMenu, Box, Button, Heading, Text, TextInput } from '@primer/react';
5
+ import { ArrowLeftIcon } from '@primer/octicons-react';
6
+ import GIF from 'gif.js';
7
+ import gifWorkerUrl from 'gif.js/dist/gif.worker.js?url';
8
+ import { DI, DatalayerLogo, DatalayerLogoText, DatalayerTextAI, getLogoColors, useColorPalette, useThemeStore, } from '@datalayer/primer-addons';
6
9
  import { DATALAYER_SVG_GALLERY } from '../svg/gallery';
7
10
  import * as SvgAssets from '../svg';
8
11
  import SpitfireAssetUrl from '../svg/images/datalayer-1.3.0-spitfire.svg';
9
12
  import BlackSnakeAssetUrl from '../svg/images/datalayer-1.2.0-black-snake.svg';
10
- const SEGMENTS = ['Hero', 'Features', 'System', 'Artifacts', 'Pixels', 'Communication', 'Cases', 'Releases', 'Logo'];
13
+ const SEGMENTS = ['All', 'Artifacts', 'Cases', 'Communication', 'Features', 'Heros', 'Logos', 'Pictos', 'Pixels', 'Releases', 'Systems'];
11
14
  const SEGMENT_BY_SLUG = SEGMENTS.reduce((acc, segment) => {
12
15
  acc[segment.toLowerCase()] = segment;
13
16
  return acc;
14
17
  }, {});
18
+ SEGMENT_BY_SLUG.logo = 'Logos';
19
+ SEGMENT_BY_SLUG.hero = 'Heros';
20
+ SEGMENT_BY_SLUG.system = 'Systems';
15
21
  const slugForSegment = (segment) => segment.toLowerCase();
16
22
  const BaseSvgLinesLogo = SvgAssets.SvgLinesLogo;
17
23
  function SvgSpitfireInline() {
@@ -201,13 +207,13 @@ function SvgDatalayerTextLogoFirst(props) {
201
207
  overflow: 'hidden',
202
208
  }, style: hostStyle, children: _jsx(DatalayerLogoText, { size: 30, inverse: true, variant: theme, colorMode: effectiveColorMode, primaryColor: logoColors.primary, secondaryColor: logoColors.secondary, textColor: logoColors.textColor }) }));
203
209
  }
204
- function SvgAI(props) {
210
+ function SvgDI(props) {
205
211
  const { colorMode, theme } = useThemeStore();
206
212
  const effectiveColorMode = colorMode === 'auto'
207
213
  ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
208
214
  : colorMode;
209
215
  const hostStyle = props?.style;
210
- return (_jsx(Box, { "aria-label": "AI mark", sx: {
216
+ return (_jsx(Box, { "aria-label": "DI mark", sx: {
211
217
  width: '100%',
212
218
  height: '100%',
213
219
  minHeight: 120,
@@ -216,7 +222,7 @@ function SvgAI(props) {
216
222
  alignItems: 'center',
217
223
  justifyContent: 'center',
218
224
  overflow: 'hidden',
219
- }, style: hostStyle, children: _jsx(AI, { size: 96, variant: theme, colorMode: effectiveColorMode }) }));
225
+ }, style: hostStyle, children: _jsx(DI, { size: 96, variant: theme, colorMode: effectiveColorMode }) }));
220
226
  }
221
227
  function SvgDatalayerTextAI(props) {
222
228
  const { colorMode, theme } = useThemeStore();
@@ -235,20 +241,55 @@ function SvgDatalayerTextAI(props) {
235
241
  overflow: 'hidden',
236
242
  }, style: hostStyle, children: _jsx(DatalayerTextAI, { aiGap: 1, variant: theme, colorMode: effectiveColorMode }) }));
237
243
  }
244
+ function SvgAIMarkPreview({ ariaLabel, Component, props, }) {
245
+ const { colorMode, theme } = useThemeStore();
246
+ const effectiveColorMode = colorMode === 'auto'
247
+ ? (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
248
+ : colorMode;
249
+ const hostStyle = props?.style;
250
+ return (_jsx(Box, { "aria-label": ariaLabel, sx: {
251
+ width: '100%',
252
+ height: '100%',
253
+ minHeight: 120,
254
+ px: 2,
255
+ display: 'flex',
256
+ alignItems: 'center',
257
+ justifyContent: 'center',
258
+ overflow: 'hidden',
259
+ }, style: hostStyle, children: _jsx(Component, { size: 96, variant: theme, colorMode: effectiveColorMode }) }));
260
+ }
261
+ function SvgAIPreview(props) {
262
+ return _jsx(SvgAIMarkPreview, { ariaLabel: "AI mark", Component: SvgAssets.SvgAI, props: props });
263
+ }
264
+ function SvgAI2Preview(props) {
265
+ return _jsx(SvgAIMarkPreview, { ariaLabel: "AI2 mark", Component: SvgAssets.SvgAI2, props: props });
266
+ }
267
+ function SvgAI3Preview(props) {
268
+ return _jsx(SvgAIMarkPreview, { ariaLabel: "AI3 mark", Component: SvgAssets.SvgAI3, props: props });
269
+ }
238
270
  const SVG_COMPONENT_OVERRIDES = {
239
271
  SvgSpitfire: SvgSpitfireInline,
240
272
  SvgBlackSnake: SvgBlackSnakeInline,
273
+ SvgAI: SvgAIPreview,
274
+ SvgAI2: SvgAI2Preview,
275
+ SvgAI3: SvgAI3Preview,
276
+ SvgDI,
241
277
  SvgLinesLogo,
242
278
  SvgDatalayerLogo,
243
279
  SvgDatalayerTextLogo,
244
280
  SvgDatalayerTextLogoFirst,
245
281
  SvgDatalayerTextAI,
246
282
  };
283
+ const ALL_SVG_ASSET_NAMES = Array.from(new Set([
284
+ ...DATALAYER_SVG_GALLERY,
285
+ ...Object.keys(SvgAssets).filter((name) => /^Svg[A-Z]/.test(name)),
286
+ ]));
247
287
  const DATALAYER_SVGS = [
248
- ...DATALAYER_SVG_GALLERY
288
+ ...ALL_SVG_ASSET_NAMES
249
289
  .map((name) => {
250
290
  const component = SvgAssets[name];
251
- if (typeof component !== 'function' && !SVG_COMPONENT_OVERRIDES[name]) {
291
+ if (component === null ||
292
+ (typeof component !== 'function' && typeof component !== 'object' && !SVG_COMPONENT_OVERRIDES[name])) {
252
293
  return null;
253
294
  }
254
295
  return {
@@ -256,7 +297,21 @@ const DATALAYER_SVGS = [
256
297
  Component: SVG_COMPONENT_OVERRIDES[name] || component,
257
298
  };
258
299
  })
259
- .filter((entry) => entry !== null),
300
+ .filter((entry) => entry !== null)
301
+ .sort((a, b) => {
302
+ const ia = DATALAYER_SVG_GALLERY.indexOf(a.name);
303
+ const ib = DATALAYER_SVG_GALLERY.indexOf(b.name);
304
+ if (ia !== -1 && ib !== -1) {
305
+ return ia - ib;
306
+ }
307
+ if (ia !== -1) {
308
+ return -1;
309
+ }
310
+ if (ib !== -1) {
311
+ return 1;
312
+ }
313
+ return a.name.localeCompare(b.name);
314
+ }),
260
315
  {
261
316
  name: 'SvgDatalayerLogo',
262
317
  Component: SvgDatalayerLogo,
@@ -273,10 +328,6 @@ const DATALAYER_SVGS = [
273
328
  name: 'SvgDatalayerTextAI',
274
329
  Component: SvgDatalayerTextAI,
275
330
  },
276
- {
277
- name: 'SvgAI',
278
- Component: SvgAI,
279
- },
280
331
  {
281
332
  name: 'SvgLinesColored',
282
333
  Component: SvgLinesColored,
@@ -286,6 +337,9 @@ const RELEASE_SVG_NAMES = new Set(['SvgSpitfire', 'SvgBlackSnake']);
286
337
  const SYSTEM_SVG_NAMES = new Set(['SvgNotFound', 'SvgUnauthorized']);
287
338
  const LOGO_SVG_NAMES = new Set([
288
339
  'SvgAI',
340
+ 'SvgAI2',
341
+ 'SvgAI3',
342
+ 'SvgDI',
289
343
  'SvgDatalayerLogo',
290
344
  'SvgDatalayerTextLogo',
291
345
  'SvgDatalayerTextLogoFirst',
@@ -294,29 +348,20 @@ const LOGO_SVG_NAMES = new Set([
294
348
  'SvgLinesColored',
295
349
  'SvgLinesLogo',
296
350
  ]);
297
- const LOGO_SVG_TRAILING_NAMES = new Set(['SvgLines', 'SvgLinesColored', 'SvgLinesLogo']);
298
- const LOGO_SVG_TRAILING_ORDER = {
299
- SvgLines: 0,
300
- SvgLinesColored: 1,
301
- SvgLinesLogo: 2,
302
- };
303
- const COMMUNICATION_SVG_NAMES = new Set(['SvgFastA2ADonation', 'SvgJupyterMcp', 'SvgDiscord', 'SvgRadar']);
351
+ const COMMUNICATION_SVG_NAMES = new Set(['SvgDiscord', 'SvgFastA2ADonation', 'SvgJupyterMcp', 'SvgOSAContributions', 'SvgRadar']);
304
352
  const CASES_SVG_NAMES = new Set(['SvgEarthHero', 'SvgUsecasesHero']);
305
353
  const ARTIFACTS_SVG_NAMES = new Set([
306
354
  'SvgNotebookArtifact',
307
355
  'SvgDocumentArtifact',
308
356
  'SvgCellArtifact',
357
+ 'SvgLessonArtifact',
358
+ 'SvgExerciseArtifact',
359
+ 'SvgAssignmentArtifact',
309
360
  'SvgDataset',
310
361
  'SvgPublication',
311
362
  ]);
312
363
  const PIXELS_SVG_NAMES = new Set(['SvgPixel1', 'SvgPixel2']);
313
- const ARTIFACTS_SVG_ORDER = {
314
- SvgNotebookArtifact: 0,
315
- SvgDocumentArtifact: 1,
316
- SvgCellArtifact: 2,
317
- SvgDataset: 3,
318
- SvgPublication: 4,
319
- };
364
+ const PICTOS_SVG_NAMES = new Set(['SvgSkubble']);
320
365
  function isCaseSvg(name) {
321
366
  return CASES_SVG_NAMES.has(name);
322
367
  }
@@ -341,17 +386,23 @@ function isArtifactsSvg(name) {
341
386
  function isPixelsSvg(name) {
342
387
  return PIXELS_SVG_NAMES.has(name);
343
388
  }
389
+ function isPictosSvg(name) {
390
+ return PICTOS_SVG_NAMES.has(name);
391
+ }
344
392
  function svgInSegment(entry, segment) {
345
- if (segment === 'Hero') {
393
+ if (segment === 'All') {
394
+ return true;
395
+ }
396
+ if (segment === 'Heros') {
346
397
  return isHeroSvg(entry.name);
347
398
  }
348
399
  if (segment === 'Releases') {
349
400
  return isReleaseSvg(entry.name);
350
401
  }
351
- if (segment === 'System') {
402
+ if (segment === 'Systems') {
352
403
  return isSystemSvg(entry.name);
353
404
  }
354
- if (segment === 'Logo') {
405
+ if (segment === 'Logos') {
355
406
  return isLogoSvg(entry.name);
356
407
  }
357
408
  if (segment === 'Communication') {
@@ -363,6 +414,9 @@ function svgInSegment(entry, segment) {
363
414
  if (segment === 'Pixels') {
364
415
  return isPixelsSvg(entry.name);
365
416
  }
417
+ if (segment === 'Pictos') {
418
+ return isPictosSvg(entry.name);
419
+ }
366
420
  if (segment === 'Cases') {
367
421
  return isCaseSvg(entry.name);
368
422
  }
@@ -373,6 +427,7 @@ function svgInSegment(entry, segment) {
373
427
  && !isCommunicationSvg(entry.name)
374
428
  && !isArtifactsSvg(entry.name)
375
429
  && !isPixelsSvg(entry.name)
430
+ && !isPictosSvg(entry.name)
376
431
  && !isCaseSvg(entry.name));
377
432
  }
378
433
  function SegmentControl({ value, onChange, counts, }) {
@@ -400,13 +455,45 @@ function SegmentControl({ value, onChange, counts, }) {
400
455
  }, children: [segment, " (", counts[segment], ")"] }, segment));
401
456
  }) }));
402
457
  }
403
- async function downloadSvgElement(svg, fileName, format) {
404
- const clone = svg.cloneNode(true);
458
+ function getSvgExportDimensions(svg) {
459
+ if (!svg) {
460
+ return null;
461
+ }
405
462
  const rect = svg.getBoundingClientRect();
406
- const width = Math.max(1, Math.round(rect.width));
407
- const height = Math.max(1, Math.round(rect.height));
408
- clone.setAttribute('width', String(width));
409
- clone.setAttribute('height', String(height));
463
+ return {
464
+ width: Math.max(1, Math.round(rect.width)),
465
+ height: Math.max(1, Math.round(rect.height)),
466
+ };
467
+ }
468
+ function getSvgDisplayDimensions(svg) {
469
+ if (!svg) {
470
+ return null;
471
+ }
472
+ const measured = getSvgExportDimensions(svg);
473
+ if (measured) {
474
+ return measured;
475
+ }
476
+ const viewBox = svg.viewBox?.baseVal;
477
+ if (viewBox && viewBox.width > 0 && viewBox.height > 0) {
478
+ return {
479
+ width: Math.round(viewBox.width),
480
+ height: Math.round(viewBox.height),
481
+ };
482
+ }
483
+ return null;
484
+ }
485
+ async function downloadSvgElement(svg, fileName, format, scale = 1) {
486
+ const clone = svg.cloneNode(true);
487
+ const dimensions = getSvgExportDimensions(svg);
488
+ if (!dimensions) {
489
+ return;
490
+ }
491
+ const width = dimensions.width;
492
+ const height = dimensions.height;
493
+ const targetWidth = width * scale;
494
+ const targetHeight = height * scale;
495
+ clone.setAttribute('width', String(targetWidth));
496
+ clone.setAttribute('height', String(targetHeight));
410
497
  const serializer = new XMLSerializer();
411
498
  const markup = serializer.serializeToString(clone);
412
499
  if (format === 'svg') {
@@ -423,20 +510,21 @@ async function downloadSvgElement(svg, fileName, format) {
423
510
  const url = URL.createObjectURL(blob);
424
511
  const mimeType = format === 'jpg' ? 'image/jpeg' : 'image/png';
425
512
  const extension = format === 'jpg' ? 'jpg' : 'png';
513
+ const fileScaleSuffix = scale === 1 ? '' : `@${scale}x`;
426
514
  await new Promise((resolve, reject) => {
427
515
  const img = new Image();
428
516
  img.onload = () => {
429
517
  const canvas = document.createElement('canvas');
430
- canvas.width = width;
431
- canvas.height = height;
518
+ canvas.width = targetWidth;
519
+ canvas.height = targetHeight;
432
520
  const ctx = canvas.getContext('2d');
433
521
  if (!ctx) {
434
522
  URL.revokeObjectURL(url);
435
523
  reject(new Error('Unable to create canvas context'));
436
524
  return;
437
525
  }
438
- ctx.clearRect(0, 0, width, height);
439
- ctx.drawImage(img, 0, 0, width, height);
526
+ ctx.clearRect(0, 0, targetWidth, targetHeight);
527
+ ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
440
528
  canvas.toBlob((output) => {
441
529
  URL.revokeObjectURL(url);
442
530
  if (!output) {
@@ -446,7 +534,7 @@ async function downloadSvgElement(svg, fileName, format) {
446
534
  const outUrl = URL.createObjectURL(output);
447
535
  const link = document.createElement('a');
448
536
  link.href = outUrl;
449
- link.download = `${fileName}.${extension}`;
537
+ link.download = `${fileName}${fileScaleSuffix}.${extension}`;
450
538
  link.click();
451
539
  URL.revokeObjectURL(outUrl);
452
540
  resolve();
@@ -459,6 +547,221 @@ async function downloadSvgElement(svg, fileName, format) {
459
547
  img.src = url;
460
548
  });
461
549
  }
550
+ async function downloadAnimatedGif(svg, fileName, scale = 1, durationMs = 10_000) {
551
+ const dimensions = getSvgExportDimensions(svg);
552
+ if (!dimensions) {
553
+ return;
554
+ }
555
+ const sourceWidth = dimensions.width;
556
+ const sourceHeight = dimensions.height;
557
+ const width = sourceWidth * scale;
558
+ const height = sourceHeight * scale;
559
+ const gif = new GIF({
560
+ workers: 2,
561
+ quality: 10,
562
+ workerScript: gifWorkerUrl,
563
+ width,
564
+ height,
565
+ repeat: 0,
566
+ });
567
+ const fps = 10;
568
+ const frameDelay = Math.round(1000 / fps);
569
+ const frameCount = Math.max(1, Math.floor(durationMs / frameDelay));
570
+ const stagingHost = document.createElement('div');
571
+ stagingHost.style.position = 'fixed';
572
+ stagingHost.style.left = '-100000px';
573
+ stagingHost.style.top = '-100000px';
574
+ stagingHost.style.width = `${sourceWidth}px`;
575
+ stagingHost.style.height = `${sourceHeight}px`;
576
+ stagingHost.style.pointerEvents = 'none';
577
+ stagingHost.style.opacity = '0';
578
+ const workingSvg = svg.cloneNode(true);
579
+ workingSvg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
580
+ workingSvg.setAttribute('width', String(sourceWidth));
581
+ workingSvg.setAttribute('height', String(sourceHeight));
582
+ workingSvg.style.width = `${sourceWidth}px`;
583
+ workingSvg.style.height = `${sourceHeight}px`;
584
+ workingSvg.style.display = 'block';
585
+ stagingHost.appendChild(workingSvg);
586
+ document.body.appendChild(stagingHost);
587
+ const ANIMATION_TAGS = new Set(['animate', 'animatemotion', 'animatetransform', 'set']);
588
+ const formatMatrix = (m) => `matrix(${m.a},${m.b},${m.c},${m.d},${m.e},${m.f})`;
589
+ // Bake the current animated state (transforms from animateMotion /
590
+ // animateTransform, opacity from animate) of the live SVG into a static
591
+ // snapshot. Serializing an SVG with SMIL animations and loading it through an
592
+ // <img> always renders it at time 0, so we must freeze the computed values.
593
+ const bakeAndRasterizeFrame = async () => {
594
+ const snapshot = workingSvg.cloneNode(true);
595
+ const liveElements = Array.from(workingSvg.querySelectorAll('*'));
596
+ const snapElements = Array.from(snapshot.querySelectorAll('*'));
597
+ for (let index = 0; index < liveElements.length; index += 1) {
598
+ const liveEl = liveElements[index];
599
+ const snapEl = snapElements[index];
600
+ if (!snapEl) {
601
+ continue;
602
+ }
603
+ if (liveEl instanceof SVGGraphicsElement && liveEl.parentNode) {
604
+ const parent = liveEl.parentNode;
605
+ const parentCtm = parent instanceof SVGGraphicsElement ? parent.getScreenCTM() : null;
606
+ const elCtm = liveEl.getScreenCTM();
607
+ if (parentCtm && elCtm) {
608
+ const localMatrix = parentCtm.inverse().multiply(elCtm);
609
+ snapEl.setAttribute('transform', formatMatrix(localMatrix));
610
+ }
611
+ const computedOpacity = window.getComputedStyle(liveEl).opacity;
612
+ if (computedOpacity && computedOpacity !== '1') {
613
+ snapEl.setAttribute('opacity', computedOpacity);
614
+ }
615
+ // The matrix above is the frozen CSS-animation state. Disable the
616
+ // cloned animation so it cannot restart at zero and override that
617
+ // matrix when the serialized frame is loaded into an image.
618
+ snapEl.style.animation = 'none';
619
+ }
620
+ }
621
+ // Remove all animation elements so the snapshot renders as a frozen frame.
622
+ snapshot
623
+ .querySelectorAll('*')
624
+ .forEach((node) => {
625
+ if (ANIMATION_TAGS.has(node.tagName.toLowerCase())) {
626
+ node.parentNode?.removeChild(node);
627
+ }
628
+ });
629
+ const markup = new XMLSerializer().serializeToString(snapshot);
630
+ const blob = new Blob([markup], { type: 'image/svg+xml;charset=utf-8' });
631
+ const url = URL.createObjectURL(blob);
632
+ try {
633
+ const image = await new Promise((resolve, reject) => {
634
+ const img = new Image();
635
+ img.onload = () => resolve(img);
636
+ img.onerror = () => reject(new Error('Unable to render animated SVG frame'));
637
+ img.src = url;
638
+ });
639
+ const frameCanvas = document.createElement('canvas');
640
+ frameCanvas.width = width;
641
+ frameCanvas.height = height;
642
+ const ctx = frameCanvas.getContext('2d', { willReadFrequently: true });
643
+ if (!ctx) {
644
+ throw new Error('Unable to create canvas context');
645
+ }
646
+ ctx.clearRect(0, 0, width, height);
647
+ ctx.drawImage(image, 0, 0, width, height);
648
+ return frameCanvas;
649
+ }
650
+ finally {
651
+ URL.revokeObjectURL(url);
652
+ }
653
+ };
654
+ try {
655
+ // Build both animation timelines before recording, then rewind them
656
+ // together. SVG SMIL and CSS animations use separate timing APIs.
657
+ workingSvg.getBoundingClientRect();
658
+ if (typeof workingSvg.pauseAnimations === 'function') {
659
+ workingSvg.pauseAnimations();
660
+ }
661
+ if (typeof workingSvg.setCurrentTime === 'function') {
662
+ workingSvg.setCurrentTime(0);
663
+ }
664
+ const webAnimations = workingSvg.getAnimations({ subtree: true });
665
+ webAnimations.forEach((animation) => {
666
+ animation.pause();
667
+ animation.currentTime = 0;
668
+ });
669
+ workingSvg.getBoundingClientRect();
670
+ for (let i = 0; i < frameCount; i += 1) {
671
+ const frameTimeMs = i * frameDelay;
672
+ if (typeof workingSvg.setCurrentTime === 'function') {
673
+ workingSvg.setCurrentTime(frameTimeMs / 1000);
674
+ }
675
+ webAnimations.forEach((animation) => {
676
+ animation.currentTime = frameTimeMs;
677
+ });
678
+ // Force both animation engines to update before reading the frame.
679
+ workingSvg.getBoundingClientRect();
680
+ const frameCanvas = await bakeAndRasterizeFrame();
681
+ gif.addFrame(frameCanvas, { copy: true, delay: frameDelay });
682
+ }
683
+ }
684
+ finally {
685
+ document.body.removeChild(stagingHost);
686
+ }
687
+ const output = await new Promise((resolve) => {
688
+ gif.on('finished', (gifBlob) => resolve(gifBlob));
689
+ gif.render();
690
+ });
691
+ const outUrl = URL.createObjectURL(output);
692
+ const fileScaleSuffix = scale === 1 ? '' : `@${scale}x`;
693
+ const link = document.createElement('a');
694
+ link.href = outUrl;
695
+ link.download = `${fileName}${fileScaleSuffix}.gif`;
696
+ link.click();
697
+ URL.revokeObjectURL(outUrl);
698
+ }
699
+ function RasterDownloadMenu({ label, format, fileName, containerRef, }) {
700
+ const [dimensions, setDimensions] = useState(null);
701
+ useEffect(() => {
702
+ const measure = () => {
703
+ const svg = containerRef.current?.querySelector('svg') ?? null;
704
+ setDimensions(getSvgDisplayDimensions(svg));
705
+ };
706
+ measure();
707
+ window.addEventListener('resize', measure);
708
+ return () => {
709
+ window.removeEventListener('resize', measure);
710
+ };
711
+ }, [containerRef]);
712
+ const sizeLabel = (scale) => {
713
+ if (!dimensions) {
714
+ return 'unavailable';
715
+ }
716
+ return `${dimensions.width * scale}x${dimensions.height * scale}`;
717
+ };
718
+ const handleExport = async (scale) => {
719
+ const target = containerRef.current?.querySelector('svg');
720
+ if (!target) {
721
+ return;
722
+ }
723
+ await downloadSvgElement(target, fileName, format, scale);
724
+ };
725
+ return (_jsxs(ActionMenu, { children: [_jsx(ActionMenu.Button, { children: label }), _jsx(ActionMenu.Overlay, { children: _jsxs(ActionList, { children: [_jsxs(ActionList.Item, { onSelect: () => { void handleExport(1); }, children: ["Current size (", sizeLabel(1), ")"] }), _jsxs(ActionList.Item, { onSelect: () => { void handleExport(2); }, children: ["Double (", sizeLabel(2), ")"] }), _jsxs(ActionList.Item, { onSelect: () => { void handleExport(4); }, children: ["Quadruple (", sizeLabel(4), ")"] })] }) })] }));
726
+ }
727
+ function GifDownloadMenu({ fileName, containerRef, }) {
728
+ const [isGenerating, setIsGenerating] = useState(false);
729
+ const [dimensions, setDimensions] = useState(null);
730
+ useEffect(() => {
731
+ const measure = () => {
732
+ const svg = containerRef.current?.querySelector('svg') ?? null;
733
+ setDimensions(getSvgDisplayDimensions(svg));
734
+ };
735
+ measure();
736
+ window.addEventListener('resize', measure);
737
+ return () => {
738
+ window.removeEventListener('resize', measure);
739
+ };
740
+ }, [containerRef]);
741
+ const sizeLabel = (scale) => {
742
+ if (!dimensions) {
743
+ return 'unavailable';
744
+ }
745
+ return `${dimensions.width * scale}x${dimensions.height * scale}`;
746
+ };
747
+ const handleDownload = async (scale) => {
748
+ const targetSvg = containerRef.current?.querySelector('svg');
749
+ if (!targetSvg || isGenerating) {
750
+ return;
751
+ }
752
+ try {
753
+ setIsGenerating(true);
754
+ await downloadAnimatedGif(targetSvg, fileName, scale, 10_000);
755
+ }
756
+ catch (error) {
757
+ console.error(error);
758
+ }
759
+ finally {
760
+ setIsGenerating(false);
761
+ }
762
+ };
763
+ return (_jsxs(ActionMenu, { children: [_jsx(ActionMenu.Button, { disabled: isGenerating, children: isGenerating ? 'Generating GIF…' : 'Download GIF (10s)' }), _jsx(ActionMenu.Overlay, { children: _jsxs(ActionList, { children: [_jsxs(ActionList.Item, { onSelect: () => { void handleDownload(1); }, children: ["Current size (", sizeLabel(1), ")"] }), _jsxs(ActionList.Item, { onSelect: () => { void handleDownload(2); }, children: ["Double (", sizeLabel(2), ")"] }), _jsxs(ActionList.Item, { onSelect: () => { void handleDownload(4); }, children: ["Quadruple (", sizeLabel(4), ")"] })] }) })] }));
764
+ }
462
765
  function SvgCard({ name, Component }) {
463
766
  const navigate = useNavigate();
464
767
  const ref = useRef(null);
@@ -472,6 +775,7 @@ function SvgCard({ name, Component }) {
472
775
  p: 2,
473
776
  border: '1px dashed',
474
777
  borderColor: 'border.default',
778
+ bg: 'canvas.subtle',
475
779
  borderRadius: 2,
476
780
  minHeight: 160,
477
781
  display: 'flex',
@@ -484,24 +788,13 @@ function SvgCard({ name, Component }) {
484
788
  cursor: 'pointer',
485
789
  ':hover': {
486
790
  borderColor: 'accent.fg',
487
- bg: 'canvas.subtle',
488
791
  },
489
792
  ':focus-visible': {
490
793
  outline: '2px solid',
491
794
  outlineColor: 'accent.fg',
492
795
  outlineOffset: '2px',
493
796
  },
494
- }, children: _jsx(Component, { style: { width: '100%', height: '100%' } }) }), _jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { onClick: openDetail, children: "View" }), _jsx(Button, { onClick: async () => {
495
- const svg = ref.current?.querySelector('svg');
496
- if (!svg)
497
- return;
498
- await downloadSvgElement(svg, name, 'png');
499
- }, children: "Download PNG" }), _jsx(Button, { onClick: async () => {
500
- const svg = ref.current?.querySelector('svg');
501
- if (!svg)
502
- return;
503
- await downloadSvgElement(svg, name, 'jpg');
504
- }, children: "Download JPG" }), _jsx(Button, { onClick: async () => {
797
+ }, children: _jsx(Component, { style: { width: '100%', height: '100%' } }) }), _jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { onClick: openDetail, children: "View" }), _jsx(RasterDownloadMenu, { label: "Download PNG", format: "png", fileName: name, containerRef: ref }), _jsx(RasterDownloadMenu, { label: "Download JPG", format: "jpg", fileName: name, containerRef: ref }), _jsx(GifDownloadMenu, { fileName: name, containerRef: ref }), _jsx(Button, { onClick: async () => {
505
798
  const svg = ref.current?.querySelector('svg');
506
799
  if (!svg)
507
800
  return;
@@ -511,35 +804,28 @@ function SvgCard({ name, Component }) {
511
804
  function SvgDetailPage() {
512
805
  const navigate = useNavigate();
513
806
  const { name } = useParams();
514
- const entry = useMemo(() => DATALAYER_SVGS.find((item) => item.name === name), [name]);
807
+ const resolvedName = name?.toLowerCase() === 'logo' ? 'SvgDI' : name;
808
+ const entry = useMemo(() => DATALAYER_SVGS.find((item) => item.name === resolvedName), [resolvedName]);
515
809
  const ref = useRef(null);
516
810
  if (!entry) {
517
- return (_jsx(Box, { sx: { maxWidth: 1200, mx: 'auto', px: 4, py: 5 }, children: _jsx(Text, { children: "SVG not found." }) }));
811
+ return (_jsx(Box, { sx: { px: 4, py: 5 }, children: _jsx(Box, { sx: { maxWidth: 1200, mx: 'auto' }, children: _jsx(Text, { children: "SVG not found." }) }) }));
518
812
  }
519
813
  const Component = entry.Component;
520
- return (_jsxs(Box, { sx: { maxWidth: 1200, mx: 'auto', px: 4, py: 5 }, children: [_jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { onClick: () => navigate('/svg'), children: "Back" }), _jsx(Button, { onClick: async () => {
521
- const svg = ref.current?.querySelector('svg');
522
- if (!svg)
523
- return;
524
- await downloadSvgElement(svg, entry.name, 'png');
525
- }, children: "Download PNG" }), _jsx(Button, { onClick: async () => {
526
- const svg = ref.current?.querySelector('svg');
527
- if (!svg)
528
- return;
529
- await downloadSvgElement(svg, entry.name, 'jpg');
530
- }, children: "Download JPG" }), _jsx(Button, { onClick: async () => {
531
- const svg = ref.current?.querySelector('svg');
532
- if (!svg)
533
- return;
534
- await downloadSvgElement(svg, entry.name, 'svg');
535
- }, children: "Download SVG" })] }), _jsx(Heading, { as: "h2", sx: { mt: 3, mb: 3 }, children: entry.name }), _jsx(Box, { ref: ref, sx: { p: 4, border: '1px solid', borderColor: 'border.default', borderRadius: 2, display: 'flex', justifyContent: 'center', minHeight: 280, overflow: 'hidden', position: 'relative', isolation: 'isolate' }, children: _jsx(Component, { style: { width: '100%', maxWidth: 900 } }) })] }));
814
+ return (_jsx(Box, { sx: { px: 4, py: 5 }, children: _jsxs(Box, { sx: { maxWidth: 1200, mx: 'auto' }, children: [_jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap' }, children: [_jsx(Button, { variant: "invisible", leadingVisual: ArrowLeftIcon, onClick: () => navigate('/svg'), children: "Back" }), _jsx(RasterDownloadMenu, { label: "Download PNG", format: "png", fileName: entry.name, containerRef: ref }), _jsx(RasterDownloadMenu, { label: "Download JPG", format: "jpg", fileName: entry.name, containerRef: ref }), _jsx(GifDownloadMenu, { fileName: entry.name, containerRef: ref }), _jsx(Button, { onClick: async () => {
815
+ const svg = ref.current?.querySelector('svg');
816
+ if (!svg)
817
+ return;
818
+ await downloadSvgElement(svg, entry.name, 'svg');
819
+ }, children: "Download SVG" })] }), _jsx(Heading, { as: "h2", sx: { mt: 3, mb: 3 }, children: entry.name }), _jsx(Box, { ref: ref, sx: { p: 4, border: '1px solid', borderColor: 'border.default', borderRadius: 2, display: 'flex', justifyContent: 'center', minHeight: 280, overflow: 'hidden', position: 'relative', isolation: 'isolate' }, children: _jsx(Component, { style: { width: '100%', maxWidth: 900 } }) })] }) }));
536
820
  }
537
821
  export function SvgPage() {
538
822
  const navigate = useNavigate();
539
823
  const { name } = useParams();
540
- const routeSegment = name ? SEGMENT_BY_SLUG[name.toLowerCase()] : undefined;
824
+ const normalizedName = name?.toLowerCase();
825
+ const routeSegment = normalizedName ? SEGMENT_BY_SLUG[normalizedName] : undefined;
541
826
  const isDetailRoute = !!name && !routeSegment;
542
- const [segment, setSegmentState] = useState(routeSegment ?? 'Hero');
827
+ const [segment, setSegmentState] = useState(routeSegment ?? 'All');
828
+ const [filter, setFilter] = useState('');
543
829
  useEffect(() => {
544
830
  if (routeSegment && routeSegment !== segment) {
545
831
  setSegmentState(routeSegment);
@@ -547,46 +833,40 @@ export function SvgPage() {
547
833
  }, [routeSegment, segment]);
548
834
  const setSegment = (next) => {
549
835
  setSegmentState(next);
550
- navigate(`/svg/${slugForSegment(next)}`);
836
+ navigate(next === 'All' ? '/svg' : `/svg/${slugForSegment(next)}`);
837
+ };
838
+ const normalizedFilter = filter.trim().toLowerCase();
839
+ const filterMatches = (entry) => {
840
+ if (!normalizedFilter) {
841
+ return true;
842
+ }
843
+ return entry.name.toLowerCase().includes(normalizedFilter);
551
844
  };
552
845
  const segmentCounts = useMemo(() => {
846
+ const textFiltered = DATALAYER_SVGS.filter(filterMatches);
553
847
  return {
554
- Hero: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Hero')).length,
555
- System: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'System')).length,
556
- Features: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Features')).length,
557
- Artifacts: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Artifacts')).length,
558
- Pixels: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Pixels')).length,
559
- Releases: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Releases')).length,
560
- Logo: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Logo')).length,
561
- Communication: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Communication')).length,
562
- Cases: DATALAYER_SVGS.filter((entry) => svgInSegment(entry, 'Cases')).length,
848
+ All: textFiltered.length,
849
+ Heros: textFiltered.filter((entry) => svgInSegment(entry, 'Heros')).length,
850
+ Systems: textFiltered.filter((entry) => svgInSegment(entry, 'Systems')).length,
851
+ Features: textFiltered.filter((entry) => svgInSegment(entry, 'Features')).length,
852
+ Artifacts: textFiltered.filter((entry) => svgInSegment(entry, 'Artifacts')).length,
853
+ Pixels: textFiltered.filter((entry) => svgInSegment(entry, 'Pixels')).length,
854
+ Pictos: textFiltered.filter((entry) => svgInSegment(entry, 'Pictos')).length,
855
+ Releases: textFiltered.filter((entry) => svgInSegment(entry, 'Releases')).length,
856
+ Logos: textFiltered.filter((entry) => svgInSegment(entry, 'Logos')).length,
857
+ Communication: textFiltered.filter((entry) => svgInSegment(entry, 'Communication')).length,
858
+ Cases: textFiltered.filter((entry) => svgInSegment(entry, 'Cases')).length,
563
859
  };
564
- }, []);
860
+ }, [normalizedFilter]);
565
861
  const filteredSvgs = useMemo(() => {
566
- const entries = DATALAYER_SVGS.filter((entry) => svgInSegment(entry, segment));
567
- if (segment === 'Artifacts') {
568
- return [...entries].sort((a, b) => {
569
- return (ARTIFACTS_SVG_ORDER[a.name] ?? 99) - (ARTIFACTS_SVG_ORDER[b.name] ?? 99);
570
- });
571
- }
572
- if (segment !== 'Logo') {
573
- return entries;
574
- }
575
- return [...entries].sort((a, b) => {
576
- const aTrailing = LOGO_SVG_TRAILING_NAMES.has(a.name);
577
- const bTrailing = LOGO_SVG_TRAILING_NAMES.has(b.name);
578
- if (aTrailing === bTrailing) {
579
- if (aTrailing && bTrailing) {
580
- return (LOGO_SVG_TRAILING_ORDER[a.name] ?? 99) - (LOGO_SVG_TRAILING_ORDER[b.name] ?? 99);
581
- }
582
- return 0;
583
- }
584
- return aTrailing ? 1 : -1;
585
- });
586
- }, [segment]);
862
+ return DATALAYER_SVGS
863
+ .filter(filterMatches)
864
+ .filter((entry) => svgInSegment(entry, segment))
865
+ .sort((a, b) => a.name.localeCompare(b.name));
866
+ }, [segment, normalizedFilter]);
587
867
  if (isDetailRoute) {
588
868
  return _jsx(SvgDetailPage, {});
589
869
  }
590
- return (_jsxs(Box, { sx: { maxWidth: 1200, mx: 'auto', px: 4, py: 5 }, children: [_jsxs(Box, { sx: { border: '1px solid', borderColor: 'border.default', borderRadius: 2, bg: 'canvas.subtle', p: [3, 4], mb: 4 }, children: [_jsx(Heading, { as: "h2", sx: { fontSize: 4, mb: 2 }, children: "SVG Gallery" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: "Gallery generated from local design SVG exports." }), _jsx(Box, { sx: { mt: 3, display: 'flex', alignItems: 'center', gap: 2, flexWrap: 'wrap' }, children: _jsx(SegmentControl, { value: segment, onChange: setSegment, counts: segmentCounts }) })] }), _jsx(Box, { sx: { display: 'grid', gridTemplateColumns: ['1fr', '1fr', '1fr 1fr'], gap: 3 }, children: filteredSvgs.map((entry) => (_jsx(SvgCard, { ...entry }, entry.name))) })] }));
870
+ return (_jsx(Box, { sx: { px: 4, py: 5 }, children: _jsxs(Box, { sx: { maxWidth: 1200, mx: 'auto' }, children: [_jsxs(Box, { sx: { border: '1px solid', borderColor: 'border.default', borderRadius: 2, bg: 'canvas.subtle', p: [3, 4], mb: 4 }, children: [_jsx(Heading, { as: "h2", sx: { fontSize: 4, mb: 2 }, children: "SVG Gallery" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: "Gallery generated from local design SVG exports." }), _jsx(Box, { sx: { mt: 3, maxWidth: 420 }, children: _jsx(TextInput, { block: true, value: filter, onChange: (event) => setFilter(event.target.value), placeholder: "Filter SVGs by name...", "aria-label": "Filter SVGs by name" }) }), _jsx(Box, { sx: { mt: 3, display: 'flex', alignItems: 'center', gap: 2, flexWrap: 'wrap' }, children: _jsx(SegmentControl, { value: segment, onChange: setSegment, counts: segmentCounts }) })] }), _jsxs(Box, { sx: { display: 'grid', gridTemplateColumns: ['1fr', '1fr', '1fr 1fr'], gap: 3 }, children: [filteredSvgs.length === 0 && (_jsx(Box, { sx: { gridColumn: '1 / -1', p: 4, border: '1px solid', borderColor: 'border.default', borderRadius: 2, bg: 'canvas.subtle' }, children: _jsx(Text, { sx: { color: 'fg.muted' }, children: "No SVG matches this filter in the current segment." }) })), filteredSvgs.map((entry) => (_jsx(SvgCard, { ...entry }, entry.name)))] })] }) }));
591
871
  }
592
872
  export default SvgPage;