@unpunnyfuns/swatchbook-blocks 0.19.9 → 0.20.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.
package/dist/index.d.mts CHANGED
@@ -513,6 +513,58 @@ declare function MotionPreview({
513
513
  caption
514
514
  }: MotionPreviewProps): ReactElement;
515
515
  //#endregion
516
+ //#region src/OpacityScale.d.ts
517
+ interface OpacityScaleProps {
518
+ /**
519
+ * Token-path filter. Use `"number.opacity.*"` or `"opacity.*"` depending
520
+ * on your layout. Omit to match every `$type: 'number'` token whose
521
+ * value is in `[0, 1]` — the value-range check (applied alongside
522
+ * the glob) keeps line-heights / z-indexes out.
523
+ */
524
+ filter?: string;
525
+ /**
526
+ * DTCG `$type` filter. `opacity` tokens where DTCG ships them as a
527
+ * dedicated type; otherwise `number` (the common placement pre-spec).
528
+ * Accepts either.
529
+ */
530
+ type?: 'number' | 'opacity';
531
+ /**
532
+ * Sample token rendered at each opacity. Defaults to `color.accent.bg`
533
+ * — swap to whatever colour your system uses to demonstrate scrim /
534
+ * overlay behaviour.
535
+ */
536
+ sampleColor?: string;
537
+ /** Override the caption. */
538
+ caption?: string;
539
+ /**
540
+ * Sort order.
541
+ * - `'value'` (default) — numeric, low opacity first.
542
+ * - `'path'` — lexicographic on the dot-path.
543
+ * - `'none'` — preserve project iteration order.
544
+ */
545
+ sortBy?: SortBy;
546
+ /** `'asc'` (default) or `'desc'`. */
547
+ sortDir?: SortDir;
548
+ }
549
+ /**
550
+ * Render each opacity token as a colored sample at that opacity over a
551
+ * checkerboard backdrop, so the transparency is visually readable. The
552
+ * number by itself (`0.4`) doesn't convey what the token looks like
553
+ * applied to a surface; the sample does.
554
+ *
555
+ * Only tokens whose `$value` is a finite number between 0 and 1
556
+ * inclusive are rendered — non-opacity `number` siblings (`line-height`,
557
+ * `z-index`) fall out naturally.
558
+ */
559
+ declare function OpacityScale({
560
+ filter,
561
+ type,
562
+ sampleColor,
563
+ caption,
564
+ sortBy,
565
+ sortDir
566
+ }: OpacityScaleProps): ReactElement;
567
+ //#endregion
516
568
  //#region src/provider.d.ts
517
569
  interface SwatchbookProviderProps {
518
570
  value: ProjectSnapshot;
@@ -803,5 +855,5 @@ declare function TypographyScale({
803
855
  sortDir
804
856
  }: TypographyScaleProps): ReactElement;
805
857
  //#endregion
806
- export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps, BorderPreview, type BorderPreviewProps, BorderSample, type BorderSampleProps, COLOR_FORMATS, type ColorFormat, ColorFormatContext, ColorPalette, type ColorPaletteProps, ColorTable, type ColorTableProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, Diagnostics, type DiagnosticsProps, DimensionBar, type DimensionBarProps, type DimensionKind, DimensionScale, type DimensionScaleProps, FontFamilySample, type FontFamilySampleProps, FontWeightScale, type FontWeightScaleProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, type ProjectSnapshot, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, StrokeStyleSample, type StrokeStyleSampleProps, SwatchbookContext, SwatchbookProvider, type SwatchbookProviderProps, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, TokenTable, type TokenTableProps, TokenUsageSnippet, type TokenUsageSnippetProps, TypographyScale, type TypographyScaleProps, type VirtualAxisShape as VirtualAxis, type VirtualAxisShape, type VirtualDiagnosticShape as VirtualDiagnostic, type VirtualDiagnosticShape, type VirtualPresetShape as VirtualPreset, type VirtualPresetShape, type VirtualThemeShape as VirtualTheme, type VirtualThemeShape, type VirtualTokenShape as VirtualToken, type VirtualTokenShape, type VirtualTokenListingShape, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
858
+ export { AliasChain, type AliasChainProps, AliasedBy, type AliasedByProps, AxesContext, AxisVariance, type AxisVarianceProps, BorderPreview, type BorderPreviewProps, BorderSample, type BorderSampleProps, COLOR_FORMATS, type ColorFormat, ColorFormatContext, ColorPalette, type ColorPaletteProps, ColorTable, type ColorTableProps, CompositeBreakdown, type CompositeBreakdownProps, CompositePreview, type CompositePreviewProps, ConsumerOutput, type ConsumerOutputProps, Diagnostics, type DiagnosticsProps, DimensionBar, type DimensionBarProps, type DimensionKind, DimensionScale, type DimensionScaleProps, FontFamilySample, type FontFamilySampleProps, FontWeightScale, type FontWeightScaleProps, type FormatColorResult, GradientPalette, type GradientPaletteProps, MotionPreview, type MotionPreviewProps, MotionSample, type MotionSampleProps, type MotionSpeed, type NormalizedColor, OpacityScale, type OpacityScaleProps, type ProjectSnapshot, ShadowPreview, type ShadowPreviewProps, ShadowSample, type ShadowSampleProps, StrokeStyleSample, type StrokeStyleSampleProps, SwatchbookContext, SwatchbookProvider, type SwatchbookProviderProps, ThemeContext, TokenDetail, type TokenDetailProps, TokenHeader, type TokenHeaderProps, TokenNavigator, type TokenNavigatorProps, TokenTable, type TokenTableProps, TokenUsageSnippet, type TokenUsageSnippetProps, TypographyScale, type TypographyScaleProps, type VirtualAxisShape as VirtualAxis, type VirtualAxisShape, type VirtualDiagnosticShape as VirtualDiagnostic, type VirtualDiagnosticShape, type VirtualPresetShape as VirtualPreset, type VirtualPresetShape, type VirtualThemeShape as VirtualTheme, type VirtualThemeShape, type VirtualTokenShape as VirtualToken, type VirtualTokenShape, type VirtualTokenListingShape, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
807
859
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -2068,13 +2068,31 @@ function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" })
2068
2068
  //#endregion
2069
2069
  //#region src/internal/prefers-reduced-motion.ts
2070
2070
  /**
2071
+ * True when rendering inside Chromatic's snapshot runner. Chromatic's
2072
+ * browser ships a recognisable user-agent string; checked here so
2073
+ * motion-looping components can fall back to their static state for
2074
+ * deterministic snapshots without needing a global Chromatic parameter
2075
+ * (globally forcing `prefersReducedMotion: true` broke Chromatic's
2076
+ * verification parser in our setup — see commit 893331f).
2077
+ */
2078
+ function isChromatic() {
2079
+ if (typeof navigator === "undefined") return false;
2080
+ return navigator.userAgent.includes("Chromatic");
2081
+ }
2082
+ /**
2071
2083
  * Reactive `prefers-reduced-motion: reduce` detector. Returns the current
2072
- * match and updates if the user toggles the OS-level preference.
2084
+ * match and updates if the user toggles the OS-level preference. Also
2085
+ * returns `true` under Chromatic to keep animated samples deterministic
2086
+ * during visual regression capture.
2073
2087
  */
2074
2088
  function usePrefersReducedMotion() {
2075
2089
  const [reduced, setReduced] = useState(false);
2076
2090
  useEffect(() => {
2077
2091
  if (typeof window === "undefined") return;
2092
+ if (isChromatic()) {
2093
+ setReduced(true);
2094
+ return;
2095
+ }
2078
2096
  const query = window.matchMedia("(prefers-reduced-motion: reduce)");
2079
2097
  setReduced(query.matches);
2080
2098
  const onChange = (e) => setReduced(e.matches);
@@ -2337,6 +2355,97 @@ function MotionPreview({ filter, caption }) {
2337
2355
  });
2338
2356
  }
2339
2357
  //#endregion
2358
+ //#region src/OpacityScale.tsx
2359
+ function toOpacity(raw) {
2360
+ if (typeof raw === "number") return raw;
2361
+ return NaN;
2362
+ }
2363
+ /**
2364
+ * Render each opacity token as a colored sample at that opacity over a
2365
+ * checkerboard backdrop, so the transparency is visually readable. The
2366
+ * number by itself (`0.4`) doesn't convey what the token looks like
2367
+ * applied to a surface; the sample does.
2368
+ *
2369
+ * Only tokens whose `$value` is a finite number between 0 and 1
2370
+ * inclusive are rendered — non-opacity `number` siblings (`line-height`,
2371
+ * `z-index`) fall out naturally.
2372
+ */
2373
+ function OpacityScale({ filter, type = "number", sampleColor = "color.accent.bg", caption, sortBy = "value", sortDir = "asc" }) {
2374
+ const project = useProject();
2375
+ const { resolved, activeTheme, cssVarPrefix } = project;
2376
+ const rows = useMemo(() => {
2377
+ return sortTokens(Object.entries(resolved).filter(([path, token]) => {
2378
+ if (token.$type !== type) return false;
2379
+ const v = toOpacity(token.$value);
2380
+ if (!Number.isFinite(v) || v < 0 || v > 1) return false;
2381
+ return globMatch(path, filter);
2382
+ }), {
2383
+ by: sortBy,
2384
+ dir: sortDir
2385
+ }).map(([path, token]) => {
2386
+ const opacity = toOpacity(token.$value);
2387
+ return {
2388
+ path,
2389
+ cssVar: resolveCssVar(path, project),
2390
+ opacity,
2391
+ displayValue: String(opacity)
2392
+ };
2393
+ });
2394
+ }, [
2395
+ resolved,
2396
+ filter,
2397
+ type,
2398
+ project,
2399
+ sortBy,
2400
+ sortDir
2401
+ ]);
2402
+ const captionText = caption ?? `${rows.length} opacity token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
2403
+ if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
2404
+ ...themeAttrs(cssVarPrefix, activeTheme),
2405
+ children: /* @__PURE__ */ jsx("div", {
2406
+ className: "sb-block__empty",
2407
+ children: "No opacity tokens match this filter."
2408
+ })
2409
+ });
2410
+ const sampleColorVar = resolveCssVar(sampleColor, project);
2411
+ return /* @__PURE__ */ jsxs("div", {
2412
+ ...themeAttrs(cssVarPrefix, activeTheme),
2413
+ children: [/* @__PURE__ */ jsx("div", {
2414
+ className: "sb-block__caption",
2415
+ children: captionText
2416
+ }), /* @__PURE__ */ jsx("div", {
2417
+ className: "sb-opacity-scale__grid",
2418
+ children: rows.map((row) => /* @__PURE__ */ jsxs("div", {
2419
+ className: "sb-opacity-scale__card",
2420
+ children: [/* @__PURE__ */ jsx("div", {
2421
+ className: "sb-opacity-scale__swatch",
2422
+ style: {
2423
+ "--sb-opacity-scale-color": sampleColorVar,
2424
+ "--sb-opacity-scale-alpha": String(row.opacity)
2425
+ },
2426
+ "aria-hidden": true
2427
+ }), /* @__PURE__ */ jsxs("div", {
2428
+ className: "sb-opacity-scale__meta",
2429
+ children: [
2430
+ /* @__PURE__ */ jsx("span", {
2431
+ className: "sb-opacity-scale__path",
2432
+ children: row.path
2433
+ }),
2434
+ /* @__PURE__ */ jsx("span", {
2435
+ className: "sb-opacity-scale__value",
2436
+ children: row.displayValue
2437
+ }),
2438
+ /* @__PURE__ */ jsx("span", {
2439
+ className: "sb-opacity-scale__css-var",
2440
+ children: row.cssVar
2441
+ })
2442
+ ]
2443
+ })]
2444
+ }, row.path))
2445
+ })]
2446
+ });
2447
+ }
2448
+ //#endregion
2340
2449
  //#region src/provider.tsx
2341
2450
  /**
2342
2451
  * Wraps a tree of blocks with the token data they need to render.
@@ -4177,6 +4286,6 @@ function TypographyScale({ filter, sample = "The quick brown fox jumps over the
4177
4286
  });
4178
4287
  }
4179
4288
  //#endregion
4180
- export { AliasChain, AliasedBy, AxesContext, AxisVariance, BorderPreview, BorderSample, COLOR_FORMATS, ColorFormatContext, ColorPalette, ColorTable, CompositeBreakdown, CompositePreview, ConsumerOutput, Diagnostics, DimensionBar, DimensionScale, FontFamilySample, FontWeightScale, GradientPalette, MotionPreview, MotionSample, ShadowPreview, ShadowSample, StrokeStyleSample, SwatchbookContext, SwatchbookProvider, ThemeContext, TokenDetail, TokenHeader, TokenNavigator, TokenTable, TokenUsageSnippet, TypographyScale, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
4289
+ export { AliasChain, AliasedBy, AxesContext, AxisVariance, BorderPreview, BorderSample, COLOR_FORMATS, ColorFormatContext, ColorPalette, ColorTable, CompositeBreakdown, CompositePreview, ConsumerOutput, Diagnostics, DimensionBar, DimensionScale, FontFamilySample, FontWeightScale, GradientPalette, MotionPreview, MotionSample, OpacityScale, ShadowPreview, ShadowSample, StrokeStyleSample, SwatchbookContext, SwatchbookProvider, ThemeContext, TokenDetail, TokenHeader, TokenNavigator, TokenTable, TokenUsageSnippet, TypographyScale, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
4181
4290
 
4182
4291
  //# sourceMappingURL=index.mjs.map