@unpunnyfuns/swatchbook-blocks 0.19.9 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +53 -1
- package/dist/index.mjs +92 -1
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +49 -0
- package/package.json +2 -2
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
|
@@ -2337,6 +2337,97 @@ function MotionPreview({ filter, caption }) {
|
|
|
2337
2337
|
});
|
|
2338
2338
|
}
|
|
2339
2339
|
//#endregion
|
|
2340
|
+
//#region src/OpacityScale.tsx
|
|
2341
|
+
function toOpacity(raw) {
|
|
2342
|
+
if (typeof raw === "number") return raw;
|
|
2343
|
+
return NaN;
|
|
2344
|
+
}
|
|
2345
|
+
/**
|
|
2346
|
+
* Render each opacity token as a colored sample at that opacity over a
|
|
2347
|
+
* checkerboard backdrop, so the transparency is visually readable. The
|
|
2348
|
+
* number by itself (`0.4`) doesn't convey what the token looks like
|
|
2349
|
+
* applied to a surface; the sample does.
|
|
2350
|
+
*
|
|
2351
|
+
* Only tokens whose `$value` is a finite number between 0 and 1
|
|
2352
|
+
* inclusive are rendered — non-opacity `number` siblings (`line-height`,
|
|
2353
|
+
* `z-index`) fall out naturally.
|
|
2354
|
+
*/
|
|
2355
|
+
function OpacityScale({ filter, type = "number", sampleColor = "color.accent.bg", caption, sortBy = "value", sortDir = "asc" }) {
|
|
2356
|
+
const project = useProject();
|
|
2357
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2358
|
+
const rows = useMemo(() => {
|
|
2359
|
+
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
2360
|
+
if (token.$type !== type) return false;
|
|
2361
|
+
const v = toOpacity(token.$value);
|
|
2362
|
+
if (!Number.isFinite(v) || v < 0 || v > 1) return false;
|
|
2363
|
+
return globMatch(path, filter);
|
|
2364
|
+
}), {
|
|
2365
|
+
by: sortBy,
|
|
2366
|
+
dir: sortDir
|
|
2367
|
+
}).map(([path, token]) => {
|
|
2368
|
+
const opacity = toOpacity(token.$value);
|
|
2369
|
+
return {
|
|
2370
|
+
path,
|
|
2371
|
+
cssVar: resolveCssVar(path, project),
|
|
2372
|
+
opacity,
|
|
2373
|
+
displayValue: String(opacity)
|
|
2374
|
+
};
|
|
2375
|
+
});
|
|
2376
|
+
}, [
|
|
2377
|
+
resolved,
|
|
2378
|
+
filter,
|
|
2379
|
+
type,
|
|
2380
|
+
project,
|
|
2381
|
+
sortBy,
|
|
2382
|
+
sortDir
|
|
2383
|
+
]);
|
|
2384
|
+
const captionText = caption ?? `${rows.length} opacity token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2385
|
+
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2386
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2387
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2388
|
+
className: "sb-block__empty",
|
|
2389
|
+
children: "No opacity tokens match this filter."
|
|
2390
|
+
})
|
|
2391
|
+
});
|
|
2392
|
+
const sampleColorVar = resolveCssVar(sampleColor, project);
|
|
2393
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2394
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2395
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2396
|
+
className: "sb-block__caption",
|
|
2397
|
+
children: captionText
|
|
2398
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2399
|
+
className: "sb-opacity-scale__grid",
|
|
2400
|
+
children: rows.map((row) => /* @__PURE__ */ jsxs("div", {
|
|
2401
|
+
className: "sb-opacity-scale__card",
|
|
2402
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2403
|
+
className: "sb-opacity-scale__swatch",
|
|
2404
|
+
style: {
|
|
2405
|
+
"--sb-opacity-scale-color": sampleColorVar,
|
|
2406
|
+
"--sb-opacity-scale-alpha": String(row.opacity)
|
|
2407
|
+
},
|
|
2408
|
+
"aria-hidden": true
|
|
2409
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
2410
|
+
className: "sb-opacity-scale__meta",
|
|
2411
|
+
children: [
|
|
2412
|
+
/* @__PURE__ */ jsx("span", {
|
|
2413
|
+
className: "sb-opacity-scale__path",
|
|
2414
|
+
children: row.path
|
|
2415
|
+
}),
|
|
2416
|
+
/* @__PURE__ */ jsx("span", {
|
|
2417
|
+
className: "sb-opacity-scale__value",
|
|
2418
|
+
children: row.displayValue
|
|
2419
|
+
}),
|
|
2420
|
+
/* @__PURE__ */ jsx("span", {
|
|
2421
|
+
className: "sb-opacity-scale__css-var",
|
|
2422
|
+
children: row.cssVar
|
|
2423
|
+
})
|
|
2424
|
+
]
|
|
2425
|
+
})]
|
|
2426
|
+
}, row.path))
|
|
2427
|
+
})]
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
//#endregion
|
|
2340
2431
|
//#region src/provider.tsx
|
|
2341
2432
|
/**
|
|
2342
2433
|
* Wraps a tree of blocks with the token data they need to render.
|
|
@@ -4177,6 +4268,6 @@ function TypographyScale({ filter, sample = "The quick brown fox jumps over the
|
|
|
4177
4268
|
});
|
|
4178
4269
|
}
|
|
4179
4270
|
//#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 };
|
|
4271
|
+
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
4272
|
|
|
4182
4273
|
//# sourceMappingURL=index.mjs.map
|