@dxos/ui-theme 0.16.0 → 0.17.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/lib/index.mjs +9 -1
- package/dist/lib/index.mjs.map +1 -1
- package/dist/plugin/ThemePlugin.cjs +2 -1
- package/dist/plugin/ThemePlugin.cjs.map +1 -1
- package/dist/plugin/ThemePlugin.mjs +2 -1
- package/dist/plugin/ThemePlugin.mjs.map +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/plugins/ThemePlugin.d.ts +2 -1
- package/dist/types/src/plugins/ThemePlugin.d.ts.map +1 -1
- package/dist/types/src/util/accent.d.ts +5 -0
- package/dist/types/src/util/accent.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -6
- package/src/css/theme/surfaces.css +2 -2
- package/src/index.ts +0 -1
- package/src/plugins/ThemePlugin.ts +2 -1
- package/src/util/accent.ts +12 -0
package/dist/lib/index.mjs
CHANGED
|
@@ -73,6 +73,14 @@ var applyAccent = (element, hue) => {
|
|
|
73
73
|
for (const [name, value] of Object.entries(tokens)) if (hue) element.style.setProperty(name, value);
|
|
74
74
|
else element.style.removeProperty(name);
|
|
75
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Sets the keyboard focus colour for an element's subtree, or clears it back to the stylesheet's default when `hue`
|
|
78
|
+
* is undefined.
|
|
79
|
+
*/
|
|
80
|
+
var applyFocusHue = (element, hue) => {
|
|
81
|
+
if (hue) element.style.setProperty("--color-focus", `var(--color-${hue}-500)`);
|
|
82
|
+
else element.style.removeProperty("--color-focus");
|
|
83
|
+
};
|
|
76
84
|
//#endregion
|
|
77
85
|
//#region src/util/elevation.ts
|
|
78
86
|
var surfaceShadow = ({ elevation }) => [elevation === "positioned" ? "shadow-sm" : elevation === "dialog" || elevation === "toast" ? "shadow-md" : "shadow-none"];
|
|
@@ -565,6 +573,6 @@ var messageValence = (valence) => {
|
|
|
565
573
|
*/
|
|
566
574
|
var buttonValence = (_valence) => "text-(--dx-valence-text) bg-(--dx-valence-bg) hover:bg-(--dx-valence-bg-hover)";
|
|
567
575
|
//#endregion
|
|
568
|
-
export { ACCENT_HUES, accentTokens, applyAccent, bridgeTv, buttonValence, cardDefaultInlineSize, cardMaxBlockSize, cardMaxInlineSize, cardMinBlockSize, cardMinInlineSize, dataDisabled, descriptionMessage, dialogExitDuration, elevationAttrs, elevationSurface, getHashHue, getHashStyles, getHeight, getSize, getStyles, getWidth, groupHoverControlItemWithTransition, hoverableControlItem, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableOpenControlItem, hueShades, iconSize, messageValence, mx, osTranslations, palette, positionerUnplaced, roles, sizeToRem, sizeValue, snapSize, staticDisabled, surfaceShadow, surfaceZIndex, surfaceZIndexVar, surfaces, textValence, toHue, tv, twMergeConfig };
|
|
576
|
+
export { ACCENT_HUES, accentTokens, applyAccent, applyFocusHue, bridgeTv, buttonValence, cardDefaultInlineSize, cardMaxBlockSize, cardMaxInlineSize, cardMinBlockSize, cardMinInlineSize, dataDisabled, descriptionMessage, dialogExitDuration, elevationAttrs, elevationSurface, getHashHue, getHashStyles, getHeight, getSize, getStyles, getWidth, groupHoverControlItemWithTransition, hoverableControlItem, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableOpenControlItem, hueShades, iconSize, messageValence, mx, osTranslations, palette, positionerUnplaced, roles, sizeToRem, sizeValue, snapSize, staticDisabled, surfaceShadow, surfaceZIndex, surfaceZIndexVar, surfaces, textValence, toHue, tv, twMergeConfig };
|
|
569
577
|
|
|
570
578
|
//# sourceMappingURL=index.mjs.map
|
package/dist/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/defs.ts","../../src/fragments/disabled.ts","../../src/fragments/hover.ts","../../src/fragments/text.ts","../../src/util/accent.ts","../../src/util/elevation.ts","../../src/util/hash-styles.ts","../../src/util/tw-merge-config.ts","../../src/util/mx.ts","../../src/util/positioner.ts","../../src/util/size.ts","../../src/util/tv.ts","../../src/util/valence.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/**\n * Translation namespace for OS-level translations.\n */\nexport const osTranslations = 'org.dxos.i18n.os';\n\nexport const hueShades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const;\n\n// NOTE: These are the JS-side style-API role keys (see ColorStyles in util/hash-styles.ts), kept\n// distinct from the renamed CSS custom-property suffixes (`-bg`/`-fg`).\nexport const roles = ['fill', 'surface', 'foreground', 'text', 'border'] as const;\n\n/**\n * Card size constants (Tailwind spacing units).\n * Cards should be no larger than 320px per WCAG 2.1 SC 1.4.10.\n */\n// TODO(burdon): Replace usage of these with semantic tokens.\nexport const cardMinInlineSize = 18;\nexport const cardDefaultInlineSize = 20; // 320px\nexport const cardMaxInlineSize = 22;\nexport const cardMinBlockSize = 18;\nexport const cardMaxBlockSize = 30;\n\n/** How long a dialog takes to leave: `--animate-fade-out` and `--animate-slide-down-and-fade`, in ms. */\nexport const dialogExitDuration = 400;\n","//\n// Copyright 2022 DXOS.org\n//\n\nexport const staticDisabled = 'opacity-40 cursor-not-allowed shadow-none';\nexport const dataDisabled = 'data-[disabled]:opacity-40 data-[disabled]:cursor-not-allowed';\n","//\n// Copyright 2022 DXOS.org\n//\n\nexport const hoverableControls =\n '[--controls-opacity:1] hover-hover:[--controls-opacity:0] hover-hover:hover:[--controls-opacity:1]';\n\nexport const groupHoverControlItemWithTransition = 'transition-opacity duration-200 opacity-0 group-hover:opacity-100';\n\nexport const hoverableFocusedKeyboardControls = 'focus-visible:[--controls-opacity:1]';\nexport const hoverableFocusedWithinControls = 'focus-within:[--controls-opacity:1]';\nexport const hoverableOpenControlItem = 'hover-hover:aria-[expanded=true]:[--controls-opacity:1]';\nexport const hoverableControlItem = 'opacity-(--controls-opacity)';\n","//\n// Copyright 2022 DXOS.org\n//\n\n// TODO(burdon): Replace with Message component.\nexport const descriptionMessage = 'text-fg-muted border border-dashed border-separator rounded-sm p-4';\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type ChromaticPalette, hues } from '@dxos/ui-types';\n\n/** The hues the accent can take: the theme's chromatic palette, each with a full Tailwind scale. */\nexport const ACCENT_HUES: readonly ChromaticPalette[] = hues;\n\nexport type AccentHue = ChromaticPalette;\n\n/** The accent role tokens, derived from one hue the way `roles.css` derives them from blue. */\nexport const accentTokens = (hue: AccentHue): Record<string, string> => ({\n '--color-accent-bg': `light-dark(var(--color-${hue}-600), var(--color-${hue}-700))`,\n '--color-accent-bg-hover': `light-dark(var(--color-${hue}-700), var(--color-${hue}-800))`,\n '--color-accent-fg': `var(--color-${hue}-100)`,\n '--color-accent-text': `light-dark(var(--color-${hue}-600), var(--color-${hue}-400))`,\n '--color-accent-text-hover': `var(--color-${hue}-500)`,\n});\n\n/**\n * Sets the accent for an element's subtree — the document root for the whole app — or clears it back\n * to the stylesheet's default when `hue` is undefined.\n */\nexport const applyAccent = (element: HTMLElement, hue: AccentHue | undefined): void => {\n const tokens = accentTokens(hue ?? ACCENT_HUES[0]);\n for (const [name, value] of Object.entries(tokens)) {\n if (hue) {\n element.style.setProperty(name, value);\n } else {\n element.style.removeProperty(name);\n }\n }\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport {\n type ComponentFragment,\n type Elevation,\n type ElevationLevel,\n type Surface,\n type SurfaceLevel,\n} from '@dxos/ui-types';\n\nexport const surfaceShadow: ComponentFragment<{ elevation?: Elevation }> = ({ elevation }) => [\n elevation === 'positioned'\n ? 'shadow-sm'\n : elevation === 'dialog' || elevation === 'toast'\n ? 'shadow-md'\n : 'shadow-none',\n];\n\nexport const surfaceZIndex: ComponentFragment<{ level?: SurfaceLevel; elevation?: Elevation }> = ({\n level,\n elevation,\n}) => {\n switch (level) {\n case 'tooltip':\n return elevation === 'dialog' ? ['z-[53]'] : elevation === 'toast' ? ['z-[43]'] : ['z-50'];\n case 'menu':\n return elevation === 'dialog' ? ['z-[52]'] : elevation === 'toast' ? ['z-[42]'] : ['z-20'];\n default:\n return elevation === 'dialog' ? ['z-[51]'] : elevation === 'toast' ? ['z-[41]'] : ['z-[1]'];\n }\n};\n\n/**\n * The same layer as {@link surfaceZIndex}, handed over as `--z-index` for an element whose inline\n * style reads the variable (a Zag positioner) and so ignores a `z-*` class.\n */\nexport const surfaceZIndexVar: ComponentFragment<{ level?: SurfaceLevel; elevation?: Elevation }> = ({\n level,\n elevation,\n}) => {\n switch (level) {\n case 'tooltip':\n return elevation === 'dialog'\n ? ['[--z-index:53]']\n : elevation === 'toast'\n ? ['[--z-index:43]']\n : ['[--z-index:50]'];\n case 'menu':\n return elevation === 'dialog'\n ? ['[--z-index:52]']\n : elevation === 'toast'\n ? ['[--z-index:42]']\n : ['[--z-index:20]'];\n default:\n return elevation === 'dialog'\n ? ['[--z-index:51]']\n : elevation === 'toast'\n ? ['[--z-index:41]']\n : ['[--z-index:1]'];\n }\n};\n\n/** The ladder by elevation number; the tones live in `css/theme/surfaces.css`. */\nexport const surfaces: readonly Surface[] = ['sunken', 'chrome', 'base', 'raised', 'overlay', 'popup'];\n\n/** The surface an elevation lands on, or nothing for no elevation. */\nexport const elevationSurface = (elevation?: ElevationLevel): Surface | undefined =>\n elevation === undefined ? undefined : surfaces[elevation];\n\n/**\n * The attribute that enters a surface zone: `data-surface` paints the tone, sets the ink, re-derives\n * every aspect for the subtree, and above `raised` casts the level's shadow (components/surface.css).\n */\nexport const elevationAttrs = (elevation?: ElevationLevel): { 'data-surface'?: Surface } => {\n const surface = elevationSurface(elevation);\n return surface === undefined ? {} : { 'data-surface': surface };\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { type ChromaticPalette } from '@dxos/ui-types';\n\nexport type Hue = ChromaticPalette | 'neutral';\n\n/**\n * See theme.css\n */\nexport type ColorStyles = {\n hue: Hue;\n bg: string;\n surface: string;\n fg: string;\n text: string;\n border: string;\n};\n\nconst neutral: ColorStyles = {\n hue: 'neutral',\n bg: 'bg-neutral-bg',\n surface: 'bg-neutral-surface',\n fg: 'text-neutral-fg',\n text: 'text-neutral-text',\n border: 'border-neutral-border',\n};\n\n// NOTE: Coordinated with `tag.css`.\n// https://github.com/dxos/dxos/blob/main/packages/ui/react-ui-theme/src/styles/layers/tag.css\nconst styles: ColorStyles[] = [\n {\n hue: 'red',\n bg: 'bg-red-bg',\n surface: 'bg-red-surface',\n fg: 'text-red-fg',\n text: 'text-red-text',\n border: 'border-red-border',\n },\n {\n hue: 'orange',\n bg: 'bg-orange-bg',\n surface: 'bg-orange-surface',\n fg: 'text-orange-fg',\n text: 'text-orange-text',\n border: 'border-orange-border',\n },\n {\n hue: 'amber',\n bg: 'bg-amber-bg',\n surface: 'bg-amber-surface',\n fg: 'text-amber-fg',\n text: 'text-amber-text',\n border: 'border-amber-border',\n },\n {\n hue: 'yellow',\n bg: 'bg-yellow-bg',\n surface: 'bg-yellow-surface',\n fg: 'text-yellow-fg',\n text: 'text-yellow-text',\n border: 'border-yellow-border',\n },\n {\n hue: 'lime',\n bg: 'bg-lime-bg',\n surface: 'bg-lime-surface',\n fg: 'text-lime-fg',\n text: 'text-lime-text',\n border: 'border-lime-border',\n },\n {\n hue: 'green',\n bg: 'bg-green-bg',\n surface: 'bg-green-surface',\n fg: 'text-green-fg',\n text: 'text-green-text',\n border: 'border-green-border',\n },\n {\n hue: 'emerald',\n bg: 'bg-emerald-bg',\n surface: 'bg-emerald-surface',\n fg: 'text-emerald-fg',\n text: 'text-emerald-text',\n border: 'border-emerald-border',\n },\n {\n hue: 'teal',\n bg: 'bg-teal-bg',\n surface: 'bg-teal-surface',\n fg: 'text-teal-fg',\n text: 'text-teal-text',\n border: 'border-teal-border',\n },\n {\n hue: 'cyan',\n bg: 'bg-cyan-bg',\n surface: 'bg-cyan-surface',\n fg: 'text-cyan-fg',\n text: 'text-cyan-text',\n border: 'border-cyan-border',\n },\n {\n hue: 'sky',\n bg: 'bg-sky-bg',\n surface: 'bg-sky-surface',\n fg: 'text-sky-fg',\n text: 'text-sky-text',\n border: 'border-sky-border',\n },\n {\n hue: 'blue',\n bg: 'bg-blue-bg',\n surface: 'bg-blue-surface',\n fg: 'text-blue-fg',\n text: 'text-blue-text',\n border: 'border-blue-border',\n },\n {\n hue: 'indigo',\n bg: 'bg-indigo-bg',\n surface: 'bg-indigo-surface',\n fg: 'text-indigo-fg',\n text: 'text-indigo-text',\n border: 'border-indigo-border',\n },\n {\n hue: 'violet',\n bg: 'bg-violet-bg',\n surface: 'bg-violet-surface',\n fg: 'text-violet-fg',\n text: 'text-violet-text',\n border: 'border-violet-border',\n },\n {\n hue: 'purple',\n bg: 'bg-purple-bg',\n surface: 'bg-purple-surface',\n fg: 'text-purple-fg',\n text: 'text-purple-text',\n border: 'border-purple-border',\n },\n {\n hue: 'fuchsia',\n bg: 'bg-fuchsia-bg',\n surface: 'bg-fuchsia-surface',\n fg: 'text-fuchsia-fg',\n text: 'text-fuchsia-text',\n border: 'border-fuchsia-border',\n },\n {\n hue: 'pink',\n bg: 'bg-pink-bg',\n surface: 'bg-pink-surface',\n fg: 'text-pink-fg',\n text: 'text-pink-text',\n border: 'border-pink-border',\n },\n {\n hue: 'rose',\n bg: 'bg-rose-bg',\n surface: 'bg-rose-surface',\n fg: 'text-rose-fg',\n text: 'text-rose-text',\n border: 'border-rose-border',\n },\n];\n\nexport const palette = {\n neutral,\n hues: styles,\n};\n\nconst validHues: ReadonlySet<Hue> = new Set<Hue>([neutral.hue, ...styles.map((s) => s.hue)]);\n\n/**\n * Normalise an arbitrary string into a known `Hue`, falling back to `'neutral'` when the\n * input doesn't match one of the catalogued palette entries. Useful when accepting hue\n * values from user-authored data (e.g. ECHO objects, plugin settings) that need to be\n * forwarded to a hue-keyed prop like `Tag`'s `palette`.\n */\nexport const toHue = (hue: string | undefined): Hue => (hue && validHues.has(hue as Hue) ? (hue as Hue) : 'neutral');\n\n// TODO(burdon): Rename getClassNames.\nexport const getStyles = (hue: string): ColorStyles => {\n return styles.find((color) => color.hue === hue) || neutral;\n};\n\n// TODO(thure): Reconcile with `to-fallback.ts` which exports `toHue` which overlaps a lot.\nexport const getHashStyles = (id: string | undefined): ColorStyles => {\n return getStyles(getHashHue(id));\n};\n\nexport const getHashHue = (id: string | undefined): Hue => {\n return id ? styles[getHash(id) % styles.length].hue : 'neutral';\n};\n\nconst getHash = (id: string): number => id.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Shared tailwind-merge configuration. The single source for both {@link mx} (extendTailwindMerge)\n * and the {@link tv} instance (createTV `twMergeConfig`) so conflict resolution can't drift —\n * notably for dxos custom tokens (`text-fg`, density, focus-ring).\n */\nexport const twMergeConfig = {\n extend: {\n classGroups: {\n 'font-family': ['font-body', 'font-mono'],\n 'font-weight': [\n 'font-thin',\n 'font-extralight',\n 'font-light',\n 'font-normal',\n 'font-medium',\n 'font-semibold',\n 'font-bold',\n 'font-extrabold',\n 'font-black',\n ],\n 'density': ['dx-density-sm', 'dx-density-md', 'dx-density-lg'],\n // Theme ring tokens (`--ring-width-focus-line`, `--ring-offset-width-focus-offset`) are not\n // recognisable as widths, so tailwind-merge files them as colours and drops one of a\n // width + colour pair.\n 'ring-w': ['ring-focus-line'],\n 'ring-offset-w': ['ring-offset-focus-offset'],\n 'dx-focus-ring': ['dx-focus-ring', 'dx-focus-ring-inset', 'dx-focus-ring-group', 'dx-focus-ring-inset-over-all'],\n },\n },\n} as const;\n\nexport type AdditionalClassGroups = 'density' | 'dx-focus-ring';\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { extendTailwindMerge, validators } from 'tailwind-merge';\n\nimport { type AdditionalClassGroups, twMergeConfig } from './tw-merge-config.ts';\n\nexport const mx = extendTailwindMerge<AdditionalClassGroups>({\n extend: {\n ...twMergeConfig.extend,\n classGroups: {\n ...twMergeConfig.extend.classGroups,\n // Arbitrary numeric font-weights require a validator (not expressible as a plain string token).\n 'font-weight': [...twMergeConfig.extend.classGroups['font-weight'], validators.isArbitraryNumber],\n },\n },\n});\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * A Zag positioner moves with `translate3d(var(--x), var(--y), 0)`, but the machine sets the two\n * variables only once its deferred measurement lands, a frame after the element mounts, and an\n * undefined variable voids the transform: that frame paints at the viewport's origin. Defaults keep\n * the unmeasured frame off screen, where the machine parks a positioner that has no placement yet.\n */\nexport const positionerUnplaced = '[--x:-100vw] [--y:-100vh]';\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { type CSSProperties } from 'react';\n\nimport { type Size } from '@dxos/ui-types';\n\nimport { mx } from '../util/index.ts';\n\n// NOTE: Class names must be fully-specified string literals so Tailwind's static scanner can detect them.\nconst sizeMap: Record<string, { w: string; h: string }> = {\n 0: { w: 'w-0', h: 'h-0' },\n px: { w: 'w-px', h: 'h-px' },\n 0.5: { w: 'w-0.5', h: 'h-0.5' },\n 1: { w: 'w-1', h: 'h-1' },\n 1.5: { w: 'w-1.5', h: 'h-1.5' },\n 2: { w: 'w-2', h: 'h-2' },\n 2.5: { w: 'w-2.5', h: 'h-2.5' },\n 3: { w: 'w-3', h: 'h-3' },\n 3.5: { w: 'w-3.5', h: 'h-3.5' },\n 4: { w: 'w-4', h: 'h-4' },\n 5: { w: 'w-5', h: 'h-5' },\n 6: { w: 'w-6', h: 'h-6' },\n 7: { w: 'w-7', h: 'h-7' },\n 8: { w: 'w-8', h: 'h-8' },\n 9: { w: 'w-9', h: 'h-9' },\n 10: { w: 'w-10', h: 'h-10' },\n 11: { w: 'w-11', h: 'h-11' },\n 12: { w: 'w-12', h: 'h-12' },\n 14: { w: 'w-14', h: 'h-14' },\n 16: { w: 'w-16', h: 'h-16' },\n 20: { w: 'w-20', h: 'h-20' },\n 24: { w: 'w-24', h: 'h-24' },\n 28: { w: 'w-28', h: 'h-28' },\n 32: { w: 'w-32', h: 'h-32' },\n 36: { w: 'w-36', h: 'h-36' },\n 40: { w: 'w-40', h: 'h-40' },\n 44: { w: 'w-44', h: 'h-44' },\n 48: { w: 'w-48', h: 'h-48' },\n 52: { w: 'w-52', h: 'h-52' },\n 56: { w: 'w-56', h: 'h-56' },\n 60: { w: 'w-60', h: 'h-60' },\n 64: { w: 'w-64', h: 'h-64' },\n 72: { w: 'w-72', h: 'h-72' },\n 80: { w: 'w-80', h: 'h-80' },\n 96: { w: 'w-96', h: 'h-96' },\n};\n\nconst SIZE_VALUES: Size[] = Object.keys(sizeMap).map((key) => (key === 'px' ? 'px' : (Number(key) as Size)));\n\nexport const getHeight = (size: Size) => sizeMap[size]?.h;\nexport const getWidth = (size: Size) => sizeMap[size]?.w;\nexport const getSize = (size: Size) => mx(getHeight(size), getWidth(size));\n\nexport const sizeValue = (size: Size): number => (size === 'px' ? 1 : size);\nexport const sizeToRem = (size: Size): string => (size === 'px' ? '1px' : `${(size as number) * 0.25}rem`);\n\nexport const iconSize = (size: Size | null): CSSProperties =>\n ({ '--icon-size': size ? sizeToRem(size) : 'initial' }) as CSSProperties;\n\n/**\n * Snaps an arbitrary numeric value to the nearest valid Tailwind size token.\n *\n * The function tries progressively coarser series in order until a match is found:\n * 1. Exact match — returns the value as-is if it is already a valid `Size`.\n * 2. Zero or negative — clamps to `0`.\n * 3. Sub-half values (`< 0.5`) — maps to the `'px'` token (1 px).\n * 4. Half-step series (0.5 increments, e.g. 1.5, 2.5 …).\n * 5. Whole-number series (1, 2, 3 …).\n * 6. Double series (even numbers: 2, 4, 6 …).\n * 7. Quadruple series (multiples of 4: 4, 8, 12 …).\n * 8. Falls back to `defaultSize` if no series matches.\n *\n * @param value - Numeric size to snap (in Tailwind spacing units, where 1 unit = 0.25 rem).\n * @param defaultSize - Fallback `Size` token used when no series produces a valid match.\n * @returns The nearest valid `Size` token.\n */\nexport const snapSize = (value: number, defaultSize: Size): Size => {\n if (SIZE_VALUES.includes(value as Size)) {\n return value as Size;\n } else if (value <= 0) {\n return 0;\n } else if (value < 0.5) {\n return 'px';\n } else {\n const wholeSeries = Math.floor(value);\n const halfSeries = Math.floor(value * 2) / 2;\n const doubleSeries = Math.floor(value / 2) * 2;\n const quadrupleSeries = Math.floor(value / 4) * 4;\n if (SIZE_VALUES.includes(halfSeries as Size)) {\n return halfSeries as Size;\n } else if (SIZE_VALUES.includes(wholeSeries as Size)) {\n return wholeSeries as Size;\n } else if (SIZE_VALUES.includes(doubleSeries as Size)) {\n return doubleSeries as Size;\n } else if (SIZE_VALUES.includes(quadrupleSeries as Size)) {\n return quadrupleSeries as Size;\n } else {\n return defaultSize;\n }\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { createTV } from 'tailwind-variants';\n\nimport { type ClassNameArray, type ClassNameValue, type Theme } from '@dxos/ui-types';\n\nimport { twMergeConfig } from './tw-merge-config.ts';\n\nexport type { VariantProps } from 'tailwind-variants';\n\n/**\n * Shared tailwind-variants instance bound to the dxos tailwind-merge config (see {@link twMergeConfig}),\n * so recipes resolve class conflicts identically to {@link mx}. All component theme recipes import this,\n * never the bare `tailwind-variants` package.\n */\nexport const tv = createTV({ twMerge: true, twMergeConfig });\n\ntype SlotsRecipe<P extends Record<string, any>, S extends string> = (\n props?: P,\n) => Record<S, (opts?: { class?: ClassNameValue }) => string>;\n\n/**\n * The {@link Theme} sub-tree produced by {@link bridgeTv}, with each slot's resolver explicitly typed\n * so call sites (and tests) stay fully typed instead of falling back to `any`.\n */\nexport type BridgedTheme<P extends Record<string, any>, S extends string> = Theme<P> & {\n [K in S]: (styleProps: P, ...etc: ClassNameArray) => string;\n};\n\n/**\n * Adapt a tailwind-variants slots recipe into the existing {@link Theme} shape (a map of\n * {@link import('@dxos/ui-types').ComponentFunction}) so it can register in the `tx` theme tree and be\n * consumed via `tx('component.slot', styleProps, ...classNames)`. Slots are enumerated explicitly (not\n * via Proxy) so unknown paths resolve to `undefined` exactly as `getDeep` does today, and the result is\n * a plain, inspectable object. Derive `slots` from `Object.keys(recipe())` at the call site.\n */\nexport const bridgeTv = <P extends Record<string, any>, S extends string>(\n recipe: SlotsRecipe<P, S>,\n slots: readonly S[],\n): BridgedTheme<P, S> =>\n Object.fromEntries(\n slots.map((slot) => [slot, (styleProps: P, ...etc: ClassNameArray) => recipe(styleProps)[slot]({ class: etc })]),\n ) as BridgedTheme<P, S>;\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { type MessageValence } from '@dxos/ui-types';\n\nexport const textValence = (valence?: MessageValence) => {\n switch (valence) {\n case 'success':\n return 'font-medium text-success-text';\n case 'info':\n return 'font-medium text-info-text';\n case 'warning':\n return 'font-medium text-warning-text';\n case 'error':\n return 'font-medium text-error-text';\n default:\n return 'font-medium';\n }\n};\n\nexport const messageValence = (valence?: MessageValence) => {\n switch (valence) {\n case 'success':\n return 'font-medium border-success-text text-success-fg bg-success-surface';\n case 'info':\n return 'font-medium border-info-text text-info-fg bg-info-surface';\n case 'warning':\n return 'font-medium border-warning-text text-warning-fg bg-warning-surface';\n case 'error':\n return 'font-medium border-error-text text-error-fg bg-error-surface';\n default:\n return 'font-medium border-neutral-text text-neutral-fg bg-neutral-surface';\n }\n};\n\n/**\n * Classes for a Button rendered inside a Banner.Root that should inherit the banner's valence color.\n * Banner.Root sets --dx-valence-bg / --dx-valence-bg-hover / --dx-valence-text on its DOM node.\n * Pass variant='valence' to the Button so button.css reads those variables.\n */\nexport const buttonValence = (_valence?: MessageValence): string =>\n 'text-(--dx-valence-text) bg-(--dx-valence-bg) hover:bg-(--dx-valence-bg-hover)';\n"],"mappings":";;;;;;;AAOA,IAAa,iBAAiB;AAE9B,IAAa,YAAY;CAAC;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG;AAI9E,IAAa,QAAQ;CAAC;CAAQ;CAAW;CAAc;CAAQ;AAAQ;;;;;AAOvE,IAAa,oBAAoB;AACjC,IAAa,wBAAwB;AACrC,IAAa,oBAAoB;AACjC,IAAa,mBAAmB;AAChC,IAAa,mBAAmB;;AAGhC,IAAa,qBAAqB;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ACF;;;;;;AAOA,IAAa,iBAAiB,aAC5B"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/defs.ts","../../src/fragments/disabled.ts","../../src/fragments/hover.ts","../../src/fragments/text.ts","../../src/util/accent.ts","../../src/util/elevation.ts","../../src/util/hash-styles.ts","../../src/util/tw-merge-config.ts","../../src/util/mx.ts","../../src/util/positioner.ts","../../src/util/size.ts","../../src/util/tv.ts","../../src/util/valence.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/**\n * Translation namespace for OS-level translations.\n */\nexport const osTranslations = 'org.dxos.i18n.os';\n\nexport const hueShades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const;\n\n// NOTE: These are the JS-side style-API role keys (see ColorStyles in util/hash-styles.ts), kept\n// distinct from the renamed CSS custom-property suffixes (`-bg`/`-fg`).\nexport const roles = ['fill', 'surface', 'foreground', 'text', 'border'] as const;\n\n/**\n * Card size constants (Tailwind spacing units).\n * Cards should be no larger than 320px per WCAG 2.1 SC 1.4.10.\n */\n// TODO(burdon): Replace usage of these with semantic tokens.\nexport const cardMinInlineSize = 18;\nexport const cardDefaultInlineSize = 20; // 320px\nexport const cardMaxInlineSize = 22;\nexport const cardMinBlockSize = 18;\nexport const cardMaxBlockSize = 30;\n\n/** How long a dialog takes to leave: `--animate-fade-out` and `--animate-slide-down-and-fade`, in ms. */\nexport const dialogExitDuration = 400;\n","//\n// Copyright 2022 DXOS.org\n//\n\nexport const staticDisabled = 'opacity-40 cursor-not-allowed shadow-none';\nexport const dataDisabled = 'data-[disabled]:opacity-40 data-[disabled]:cursor-not-allowed';\n","//\n// Copyright 2022 DXOS.org\n//\n\nexport const hoverableControls =\n '[--controls-opacity:1] hover-hover:[--controls-opacity:0] hover-hover:hover:[--controls-opacity:1]';\n\nexport const groupHoverControlItemWithTransition = 'transition-opacity duration-200 opacity-0 group-hover:opacity-100';\n\nexport const hoverableFocusedKeyboardControls = 'focus-visible:[--controls-opacity:1]';\nexport const hoverableFocusedWithinControls = 'focus-within:[--controls-opacity:1]';\nexport const hoverableOpenControlItem = 'hover-hover:aria-[expanded=true]:[--controls-opacity:1]';\nexport const hoverableControlItem = 'opacity-(--controls-opacity)';\n","//\n// Copyright 2022 DXOS.org\n//\n\n// TODO(burdon): Replace with Message component.\nexport const descriptionMessage = 'text-fg-muted border border-dashed border-separator rounded-sm p-4';\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type ChromaticPalette, hues } from '@dxos/ui-types';\n\n/** The hues the accent can take: the theme's chromatic palette, each with a full Tailwind scale. */\nexport const ACCENT_HUES: readonly ChromaticPalette[] = hues;\n\nexport type AccentHue = ChromaticPalette;\n\n/** The accent role tokens, derived from one hue the way `roles.css` derives them from blue. */\nexport const accentTokens = (hue: AccentHue): Record<string, string> => ({\n '--color-accent-bg': `light-dark(var(--color-${hue}-600), var(--color-${hue}-700))`,\n '--color-accent-bg-hover': `light-dark(var(--color-${hue}-700), var(--color-${hue}-800))`,\n '--color-accent-fg': `var(--color-${hue}-100)`,\n '--color-accent-text': `light-dark(var(--color-${hue}-600), var(--color-${hue}-400))`,\n '--color-accent-text-hover': `var(--color-${hue}-500)`,\n});\n\n/**\n * Sets the accent for an element's subtree — the document root for the whole app — or clears it back\n * to the stylesheet's default when `hue` is undefined.\n */\nexport const applyAccent = (element: HTMLElement, hue: AccentHue | undefined): void => {\n const tokens = accentTokens(hue ?? ACCENT_HUES[0]);\n for (const [name, value] of Object.entries(tokens)) {\n if (hue) {\n element.style.setProperty(name, value);\n } else {\n element.style.removeProperty(name);\n }\n }\n};\n\n/**\n * Sets the keyboard focus colour for an element's subtree, or clears it back to the stylesheet's default when `hue`\n * is undefined.\n */\nexport const applyFocusHue = (element: HTMLElement, hue: AccentHue | undefined): void => {\n if (hue) {\n element.style.setProperty('--color-focus', `var(--color-${hue}-500)`);\n } else {\n element.style.removeProperty('--color-focus');\n }\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport {\n type ComponentFragment,\n type Elevation,\n type ElevationLevel,\n type Surface,\n type SurfaceLevel,\n} from '@dxos/ui-types';\n\nexport const surfaceShadow: ComponentFragment<{ elevation?: Elevation }> = ({ elevation }) => [\n elevation === 'positioned'\n ? 'shadow-sm'\n : elevation === 'dialog' || elevation === 'toast'\n ? 'shadow-md'\n : 'shadow-none',\n];\n\nexport const surfaceZIndex: ComponentFragment<{ level?: SurfaceLevel; elevation?: Elevation }> = ({\n level,\n elevation,\n}) => {\n switch (level) {\n case 'tooltip':\n return elevation === 'dialog' ? ['z-[53]'] : elevation === 'toast' ? ['z-[43]'] : ['z-50'];\n case 'menu':\n return elevation === 'dialog' ? ['z-[52]'] : elevation === 'toast' ? ['z-[42]'] : ['z-20'];\n default:\n return elevation === 'dialog' ? ['z-[51]'] : elevation === 'toast' ? ['z-[41]'] : ['z-[1]'];\n }\n};\n\n/**\n * The same layer as {@link surfaceZIndex}, handed over as `--z-index` for an element whose inline\n * style reads the variable (a Zag positioner) and so ignores a `z-*` class.\n */\nexport const surfaceZIndexVar: ComponentFragment<{ level?: SurfaceLevel; elevation?: Elevation }> = ({\n level,\n elevation,\n}) => {\n switch (level) {\n case 'tooltip':\n return elevation === 'dialog'\n ? ['[--z-index:53]']\n : elevation === 'toast'\n ? ['[--z-index:43]']\n : ['[--z-index:50]'];\n case 'menu':\n return elevation === 'dialog'\n ? ['[--z-index:52]']\n : elevation === 'toast'\n ? ['[--z-index:42]']\n : ['[--z-index:20]'];\n default:\n return elevation === 'dialog'\n ? ['[--z-index:51]']\n : elevation === 'toast'\n ? ['[--z-index:41]']\n : ['[--z-index:1]'];\n }\n};\n\n/** The ladder by elevation number; the tones live in `css/theme/surfaces.css`. */\nexport const surfaces: readonly Surface[] = ['sunken', 'chrome', 'base', 'raised', 'overlay', 'popup'];\n\n/** The surface an elevation lands on, or nothing for no elevation. */\nexport const elevationSurface = (elevation?: ElevationLevel): Surface | undefined =>\n elevation === undefined ? undefined : surfaces[elevation];\n\n/**\n * The attribute that enters a surface zone: `data-surface` paints the tone, sets the ink, re-derives\n * every aspect for the subtree, and above `raised` casts the level's shadow (components/surface.css).\n */\nexport const elevationAttrs = (elevation?: ElevationLevel): { 'data-surface'?: Surface } => {\n const surface = elevationSurface(elevation);\n return surface === undefined ? {} : { 'data-surface': surface };\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { type ChromaticPalette } from '@dxos/ui-types';\n\nexport type Hue = ChromaticPalette | 'neutral';\n\n/**\n * See theme.css\n */\nexport type ColorStyles = {\n hue: Hue;\n bg: string;\n surface: string;\n fg: string;\n text: string;\n border: string;\n};\n\nconst neutral: ColorStyles = {\n hue: 'neutral',\n bg: 'bg-neutral-bg',\n surface: 'bg-neutral-surface',\n fg: 'text-neutral-fg',\n text: 'text-neutral-text',\n border: 'border-neutral-border',\n};\n\n// NOTE: Coordinated with `tag.css`.\n// https://github.com/dxos/dxos/blob/main/packages/ui/react-ui-theme/src/styles/layers/tag.css\nconst styles: ColorStyles[] = [\n {\n hue: 'red',\n bg: 'bg-red-bg',\n surface: 'bg-red-surface',\n fg: 'text-red-fg',\n text: 'text-red-text',\n border: 'border-red-border',\n },\n {\n hue: 'orange',\n bg: 'bg-orange-bg',\n surface: 'bg-orange-surface',\n fg: 'text-orange-fg',\n text: 'text-orange-text',\n border: 'border-orange-border',\n },\n {\n hue: 'amber',\n bg: 'bg-amber-bg',\n surface: 'bg-amber-surface',\n fg: 'text-amber-fg',\n text: 'text-amber-text',\n border: 'border-amber-border',\n },\n {\n hue: 'yellow',\n bg: 'bg-yellow-bg',\n surface: 'bg-yellow-surface',\n fg: 'text-yellow-fg',\n text: 'text-yellow-text',\n border: 'border-yellow-border',\n },\n {\n hue: 'lime',\n bg: 'bg-lime-bg',\n surface: 'bg-lime-surface',\n fg: 'text-lime-fg',\n text: 'text-lime-text',\n border: 'border-lime-border',\n },\n {\n hue: 'green',\n bg: 'bg-green-bg',\n surface: 'bg-green-surface',\n fg: 'text-green-fg',\n text: 'text-green-text',\n border: 'border-green-border',\n },\n {\n hue: 'emerald',\n bg: 'bg-emerald-bg',\n surface: 'bg-emerald-surface',\n fg: 'text-emerald-fg',\n text: 'text-emerald-text',\n border: 'border-emerald-border',\n },\n {\n hue: 'teal',\n bg: 'bg-teal-bg',\n surface: 'bg-teal-surface',\n fg: 'text-teal-fg',\n text: 'text-teal-text',\n border: 'border-teal-border',\n },\n {\n hue: 'cyan',\n bg: 'bg-cyan-bg',\n surface: 'bg-cyan-surface',\n fg: 'text-cyan-fg',\n text: 'text-cyan-text',\n border: 'border-cyan-border',\n },\n {\n hue: 'sky',\n bg: 'bg-sky-bg',\n surface: 'bg-sky-surface',\n fg: 'text-sky-fg',\n text: 'text-sky-text',\n border: 'border-sky-border',\n },\n {\n hue: 'blue',\n bg: 'bg-blue-bg',\n surface: 'bg-blue-surface',\n fg: 'text-blue-fg',\n text: 'text-blue-text',\n border: 'border-blue-border',\n },\n {\n hue: 'indigo',\n bg: 'bg-indigo-bg',\n surface: 'bg-indigo-surface',\n fg: 'text-indigo-fg',\n text: 'text-indigo-text',\n border: 'border-indigo-border',\n },\n {\n hue: 'violet',\n bg: 'bg-violet-bg',\n surface: 'bg-violet-surface',\n fg: 'text-violet-fg',\n text: 'text-violet-text',\n border: 'border-violet-border',\n },\n {\n hue: 'purple',\n bg: 'bg-purple-bg',\n surface: 'bg-purple-surface',\n fg: 'text-purple-fg',\n text: 'text-purple-text',\n border: 'border-purple-border',\n },\n {\n hue: 'fuchsia',\n bg: 'bg-fuchsia-bg',\n surface: 'bg-fuchsia-surface',\n fg: 'text-fuchsia-fg',\n text: 'text-fuchsia-text',\n border: 'border-fuchsia-border',\n },\n {\n hue: 'pink',\n bg: 'bg-pink-bg',\n surface: 'bg-pink-surface',\n fg: 'text-pink-fg',\n text: 'text-pink-text',\n border: 'border-pink-border',\n },\n {\n hue: 'rose',\n bg: 'bg-rose-bg',\n surface: 'bg-rose-surface',\n fg: 'text-rose-fg',\n text: 'text-rose-text',\n border: 'border-rose-border',\n },\n];\n\nexport const palette = {\n neutral,\n hues: styles,\n};\n\nconst validHues: ReadonlySet<Hue> = new Set<Hue>([neutral.hue, ...styles.map((s) => s.hue)]);\n\n/**\n * Normalise an arbitrary string into a known `Hue`, falling back to `'neutral'` when the\n * input doesn't match one of the catalogued palette entries. Useful when accepting hue\n * values from user-authored data (e.g. ECHO objects, plugin settings) that need to be\n * forwarded to a hue-keyed prop like `Tag`'s `palette`.\n */\nexport const toHue = (hue: string | undefined): Hue => (hue && validHues.has(hue as Hue) ? (hue as Hue) : 'neutral');\n\n// TODO(burdon): Rename getClassNames.\nexport const getStyles = (hue: string): ColorStyles => {\n return styles.find((color) => color.hue === hue) || neutral;\n};\n\n// TODO(thure): Reconcile with `to-fallback.ts` which exports `toHue` which overlaps a lot.\nexport const getHashStyles = (id: string | undefined): ColorStyles => {\n return getStyles(getHashHue(id));\n};\n\nexport const getHashHue = (id: string | undefined): Hue => {\n return id ? styles[getHash(id) % styles.length].hue : 'neutral';\n};\n\nconst getHash = (id: string): number => id.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Shared tailwind-merge configuration. The single source for both {@link mx} (extendTailwindMerge)\n * and the {@link tv} instance (createTV `twMergeConfig`) so conflict resolution can't drift —\n * notably for dxos custom tokens (`text-fg`, density, focus-ring).\n */\nexport const twMergeConfig = {\n extend: {\n classGroups: {\n 'font-family': ['font-body', 'font-mono'],\n 'font-weight': [\n 'font-thin',\n 'font-extralight',\n 'font-light',\n 'font-normal',\n 'font-medium',\n 'font-semibold',\n 'font-bold',\n 'font-extrabold',\n 'font-black',\n ],\n 'density': ['dx-density-sm', 'dx-density-md', 'dx-density-lg'],\n // Theme ring tokens (`--ring-width-focus-line`, `--ring-offset-width-focus-offset`) are not\n // recognisable as widths, so tailwind-merge files them as colours and drops one of a\n // width + colour pair.\n 'ring-w': ['ring-focus-line'],\n 'ring-offset-w': ['ring-offset-focus-offset'],\n 'dx-focus-ring': ['dx-focus-ring', 'dx-focus-ring-inset', 'dx-focus-ring-group', 'dx-focus-ring-inset-over-all'],\n },\n },\n} as const;\n\nexport type AdditionalClassGroups = 'density' | 'dx-focus-ring';\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { extendTailwindMerge, validators } from 'tailwind-merge';\n\nimport { type AdditionalClassGroups, twMergeConfig } from './tw-merge-config.ts';\n\nexport const mx = extendTailwindMerge<AdditionalClassGroups>({\n extend: {\n ...twMergeConfig.extend,\n classGroups: {\n ...twMergeConfig.extend.classGroups,\n // Arbitrary numeric font-weights require a validator (not expressible as a plain string token).\n 'font-weight': [...twMergeConfig.extend.classGroups['font-weight'], validators.isArbitraryNumber],\n },\n },\n});\n","//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * A Zag positioner moves with `translate3d(var(--x), var(--y), 0)`, but the machine sets the two\n * variables only once its deferred measurement lands, a frame after the element mounts, and an\n * undefined variable voids the transform: that frame paints at the viewport's origin. Defaults keep\n * the unmeasured frame off screen, where the machine parks a positioner that has no placement yet.\n */\nexport const positionerUnplaced = '[--x:-100vw] [--y:-100vh]';\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { type CSSProperties } from 'react';\n\nimport { type Size } from '@dxos/ui-types';\n\nimport { mx } from '../util/index.ts';\n\n// NOTE: Class names must be fully-specified string literals so Tailwind's static scanner can detect them.\nconst sizeMap: Record<string, { w: string; h: string }> = {\n 0: { w: 'w-0', h: 'h-0' },\n px: { w: 'w-px', h: 'h-px' },\n 0.5: { w: 'w-0.5', h: 'h-0.5' },\n 1: { w: 'w-1', h: 'h-1' },\n 1.5: { w: 'w-1.5', h: 'h-1.5' },\n 2: { w: 'w-2', h: 'h-2' },\n 2.5: { w: 'w-2.5', h: 'h-2.5' },\n 3: { w: 'w-3', h: 'h-3' },\n 3.5: { w: 'w-3.5', h: 'h-3.5' },\n 4: { w: 'w-4', h: 'h-4' },\n 5: { w: 'w-5', h: 'h-5' },\n 6: { w: 'w-6', h: 'h-6' },\n 7: { w: 'w-7', h: 'h-7' },\n 8: { w: 'w-8', h: 'h-8' },\n 9: { w: 'w-9', h: 'h-9' },\n 10: { w: 'w-10', h: 'h-10' },\n 11: { w: 'w-11', h: 'h-11' },\n 12: { w: 'w-12', h: 'h-12' },\n 14: { w: 'w-14', h: 'h-14' },\n 16: { w: 'w-16', h: 'h-16' },\n 20: { w: 'w-20', h: 'h-20' },\n 24: { w: 'w-24', h: 'h-24' },\n 28: { w: 'w-28', h: 'h-28' },\n 32: { w: 'w-32', h: 'h-32' },\n 36: { w: 'w-36', h: 'h-36' },\n 40: { w: 'w-40', h: 'h-40' },\n 44: { w: 'w-44', h: 'h-44' },\n 48: { w: 'w-48', h: 'h-48' },\n 52: { w: 'w-52', h: 'h-52' },\n 56: { w: 'w-56', h: 'h-56' },\n 60: { w: 'w-60', h: 'h-60' },\n 64: { w: 'w-64', h: 'h-64' },\n 72: { w: 'w-72', h: 'h-72' },\n 80: { w: 'w-80', h: 'h-80' },\n 96: { w: 'w-96', h: 'h-96' },\n};\n\nconst SIZE_VALUES: Size[] = Object.keys(sizeMap).map((key) => (key === 'px' ? 'px' : (Number(key) as Size)));\n\nexport const getHeight = (size: Size) => sizeMap[size]?.h;\nexport const getWidth = (size: Size) => sizeMap[size]?.w;\nexport const getSize = (size: Size) => mx(getHeight(size), getWidth(size));\n\nexport const sizeValue = (size: Size): number => (size === 'px' ? 1 : size);\nexport const sizeToRem = (size: Size): string => (size === 'px' ? '1px' : `${(size as number) * 0.25}rem`);\n\nexport const iconSize = (size: Size | null): CSSProperties =>\n ({ '--icon-size': size ? sizeToRem(size) : 'initial' }) as CSSProperties;\n\n/**\n * Snaps an arbitrary numeric value to the nearest valid Tailwind size token.\n *\n * The function tries progressively coarser series in order until a match is found:\n * 1. Exact match — returns the value as-is if it is already a valid `Size`.\n * 2. Zero or negative — clamps to `0`.\n * 3. Sub-half values (`< 0.5`) — maps to the `'px'` token (1 px).\n * 4. Half-step series (0.5 increments, e.g. 1.5, 2.5 …).\n * 5. Whole-number series (1, 2, 3 …).\n * 6. Double series (even numbers: 2, 4, 6 …).\n * 7. Quadruple series (multiples of 4: 4, 8, 12 …).\n * 8. Falls back to `defaultSize` if no series matches.\n *\n * @param value - Numeric size to snap (in Tailwind spacing units, where 1 unit = 0.25 rem).\n * @param defaultSize - Fallback `Size` token used when no series produces a valid match.\n * @returns The nearest valid `Size` token.\n */\nexport const snapSize = (value: number, defaultSize: Size): Size => {\n if (SIZE_VALUES.includes(value as Size)) {\n return value as Size;\n } else if (value <= 0) {\n return 0;\n } else if (value < 0.5) {\n return 'px';\n } else {\n const wholeSeries = Math.floor(value);\n const halfSeries = Math.floor(value * 2) / 2;\n const doubleSeries = Math.floor(value / 2) * 2;\n const quadrupleSeries = Math.floor(value / 4) * 4;\n if (SIZE_VALUES.includes(halfSeries as Size)) {\n return halfSeries as Size;\n } else if (SIZE_VALUES.includes(wholeSeries as Size)) {\n return wholeSeries as Size;\n } else if (SIZE_VALUES.includes(doubleSeries as Size)) {\n return doubleSeries as Size;\n } else if (SIZE_VALUES.includes(quadrupleSeries as Size)) {\n return quadrupleSeries as Size;\n } else {\n return defaultSize;\n }\n }\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { createTV } from 'tailwind-variants';\n\nimport { type ClassNameArray, type ClassNameValue, type Theme } from '@dxos/ui-types';\n\nimport { twMergeConfig } from './tw-merge-config.ts';\n\nexport type { VariantProps } from 'tailwind-variants';\n\n/**\n * Shared tailwind-variants instance bound to the dxos tailwind-merge config (see {@link twMergeConfig}),\n * so recipes resolve class conflicts identically to {@link mx}. All component theme recipes import this,\n * never the bare `tailwind-variants` package.\n */\nexport const tv = createTV({ twMerge: true, twMergeConfig });\n\ntype SlotsRecipe<P extends Record<string, any>, S extends string> = (\n props?: P,\n) => Record<S, (opts?: { class?: ClassNameValue }) => string>;\n\n/**\n * The {@link Theme} sub-tree produced by {@link bridgeTv}, with each slot's resolver explicitly typed\n * so call sites (and tests) stay fully typed instead of falling back to `any`.\n */\nexport type BridgedTheme<P extends Record<string, any>, S extends string> = Theme<P> & {\n [K in S]: (styleProps: P, ...etc: ClassNameArray) => string;\n};\n\n/**\n * Adapt a tailwind-variants slots recipe into the existing {@link Theme} shape (a map of\n * {@link import('@dxos/ui-types').ComponentFunction}) so it can register in the `tx` theme tree and be\n * consumed via `tx('component.slot', styleProps, ...classNames)`. Slots are enumerated explicitly (not\n * via Proxy) so unknown paths resolve to `undefined` exactly as `getDeep` does today, and the result is\n * a plain, inspectable object. Derive `slots` from `Object.keys(recipe())` at the call site.\n */\nexport const bridgeTv = <P extends Record<string, any>, S extends string>(\n recipe: SlotsRecipe<P, S>,\n slots: readonly S[],\n): BridgedTheme<P, S> =>\n Object.fromEntries(\n slots.map((slot) => [slot, (styleProps: P, ...etc: ClassNameArray) => recipe(styleProps)[slot]({ class: etc })]),\n ) as BridgedTheme<P, S>;\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { type MessageValence } from '@dxos/ui-types';\n\nexport const textValence = (valence?: MessageValence) => {\n switch (valence) {\n case 'success':\n return 'font-medium text-success-text';\n case 'info':\n return 'font-medium text-info-text';\n case 'warning':\n return 'font-medium text-warning-text';\n case 'error':\n return 'font-medium text-error-text';\n default:\n return 'font-medium';\n }\n};\n\nexport const messageValence = (valence?: MessageValence) => {\n switch (valence) {\n case 'success':\n return 'font-medium border-success-text text-success-fg bg-success-surface';\n case 'info':\n return 'font-medium border-info-text text-info-fg bg-info-surface';\n case 'warning':\n return 'font-medium border-warning-text text-warning-fg bg-warning-surface';\n case 'error':\n return 'font-medium border-error-text text-error-fg bg-error-surface';\n default:\n return 'font-medium border-neutral-text text-neutral-fg bg-neutral-surface';\n }\n};\n\n/**\n * Classes for a Button rendered inside a Banner.Root that should inherit the banner's valence color.\n * Banner.Root sets --dx-valence-bg / --dx-valence-bg-hover / --dx-valence-text on its DOM node.\n * Pass variant='valence' to the Button so button.css reads those variables.\n */\nexport const buttonValence = (_valence?: MessageValence): string =>\n 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AAE,SAAS;CAAM;AAAc,CAAC;;;;;;;;AAqB3D,IAAa,YACX,QACA,UAEA,OAAO,YACL,MAAM,KAAK,SAAS,CAAC,OAAO,YAAe,GAAG,QAAwB,OAAO,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CACjH;;;ACtCF,IAAa,eAAe,YAA6B;CACvD,QAAQ,SAAR;EACE,KAAK,WACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,IAAa,kBAAkB,YAA6B;CAC1D,QAAQ,SAAR;EACE,KAAK,WACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE,OAAO;CACX;AACF;;;;;;AAOA,IAAa,iBAAiB,aAC5B"}
|
|
@@ -113,8 +113,9 @@ var writeConsumerTheme = ({ packageRoot, root, outPath, content }) => {
|
|
|
113
113
|
/**
|
|
114
114
|
* Vite plugin to configure theme.
|
|
115
115
|
* Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.
|
|
116
|
+
* Every option has a default, so a consumer of the published package can call `ThemePlugin()`.
|
|
116
117
|
*/
|
|
117
|
-
var ThemePlugin = (options) => {
|
|
118
|
+
var ThemePlugin = (options = {}) => {
|
|
118
119
|
const packageRoot = (0, node_fs.realpathSync)((0, node_path.resolve)(__dirname, ROOT));
|
|
119
120
|
const isMonorepo = !packageRoot.split(node_path.sep).includes("node_modules");
|
|
120
121
|
const pluginsDir = (0, node_path.resolve)(__dirname, ROOT, "src/plugins");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemePlugin.cjs","names":["sep","dirname","resolve","join","existsSync","readFileSync","realpathSync","postcssImport","postcssNesting","tailwindcssPostcss","tailwindcssVite"],"sources":["../../src/plugins/ThemePlugin.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport tailwindcssPostcss from '@tailwindcss/postcss';\nimport tailwindcssVite from '@tailwindcss/vite';\nimport autoprefixer from 'autoprefixer';\nimport { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport postcssImport from 'postcss-import';\nimport postcssNesting from 'postcss-nesting';\nimport { type HtmlTagDescriptor, type Plugin, type UserConfig } from 'vite';\n\n/**\n * CSS cascade layer order.\n * Must be established before any stylesheets load so that Tailwind's own @layer declarations don't override our ordering. Exported so consuming\n */\nexport const LAYER_ORDER = [\n 'properties',\n 'theme',\n 'dx-tokens',\n 'user-tokens',\n 'base',\n 'tw-base',\n 'dx-base',\n 'components',\n 'tw-components',\n 'dx-components',\n 'utilities',\n] as const;\n\n// Package root relative to this module's built location, `dist/plugin/ThemePlugin.{mjs,cjs}`.\n// Tied to the output depth: the two-pass vite build in `vite.plugin.config.ts` emits flat into\n// `dist/plugin`, where the retired pipeline nested a platform slug and a mirrored source tree.\nconst ROOT = '../../';\n\n/**\n * Disable `@tailwindcss/vite`'s `hotUpdate` hook under Vite's full-bundle dev mode.\n *\n * `vite dev --experimentalBundle` routes `hotUpdate` through Rolldown's plugin bridge, whose\n * options object carries no `server` and whose context carries no `environment` — so the hook\n * throws on its first dereference and takes the whole rebuild with it (`TypeError: Cannot read\n * properties of undefined (reading 'environments')`, then `(reading 'name')` once `server` is\n * supplied). Its job is to invalidate the generated CSS in Vite's module graph when a scanned\n * source file changes, and that graph is not what serves CSS under bundled dev, so there is\n * nothing to salvage by filling the gaps in: skipping it keeps HMR working for everything else,\n * at the cost of needing a server restart before a NEWLY USED utility class is generated.\n */\nconst skipHotUpdateInBundledDev = (plugin: Plugin): Plugin => {\n const hotUpdate = plugin.hotUpdate;\n const handler = typeof hotUpdate === 'function' ? hotUpdate : hotUpdate?.handler;\n if (!handler) {\n return plugin;\n }\n\n // Chained rather than assigned: only `@tailwindcss/vite:generate:serve` declares `hotUpdate` and\n // it declares no `configResolved` today, but this package publishes against a caret range where\n // a later minor could add one, and a clobbered hook would fail silently.\n const configResolved = plugin.configResolved;\n const inheritedConfigResolved = typeof configResolved === 'function' ? configResolved : configResolved?.handler;\n\n let bundledDev = false;\n return {\n ...plugin,\n configResolved(config) {\n bundledDev = config.experimental.bundledDev === true;\n return inheritedConfigResolved?.call(this, config);\n },\n hotUpdate: {\n ...(typeof hotUpdate === 'object' ? hotUpdate : {}),\n handler(context) {\n if (bundledDev) {\n return;\n }\n return handler.call(this, context);\n },\n },\n };\n};\n\nexport type ThemePluginOptions = {\n srcCssPath?: string;\n /** Extra Tailwind scan globs (absolute, or relative to the Vite root) for a consumer of the published package. */\n content?: string[];\n virtualFileId?: string;\n verbose?: boolean;\n};\n\nconst toCssString = (path: string): string => JSON.stringify(path.split(sep).join('/'));\n\n/**\n * Writes the theme entry for a consumer of the published package and returns its path.\n * `workspace.css` cannot serve them: its scan paths are relative to this package, which from inside\n * `node_modules` reaches every installed package, and Tailwind walks all of it before answering.\n */\nconst writeConsumerTheme = ({\n packageRoot,\n root,\n outPath,\n content,\n}: {\n packageRoot: string;\n root: string;\n outPath: string;\n content: string[];\n}): string => {\n // The scope this package was installed into, and the consumer's own, which differ under pnpm's isolated layout.\n const scopeDirs = new Set([dirname(packageRoot), resolve(root, 'node_modules/@dxos')]);\n const sources = [\n // Tailwind skips `node_modules` below an explicit base, so this covers only the consumer's own files.\n join(root, '**/*.{ts,tsx,js,jsx,html}'),\n ...[...scopeDirs].map((scopeDir) => join(scopeDir, '*/dist/lib/**/*.mjs')),\n ...content.map((glob) => resolve(root, glob)),\n ];\n const css = [\n `@import ${toCssString(join(packageRoot, 'src/main.css'))};`,\n ...sources.map((source) => `@source ${toCssString(source)};`),\n '',\n ].join('\\n');\n\n // Rewriting identical content would bump the mtime, which Tailwind reads as a reason to rebuild.\n if (!existsSync(outPath) || readFileSync(outPath, 'utf-8') !== css) {\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, css);\n }\n\n return outPath;\n};\n\n/**\n * Vite plugin to configure theme.\n * Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.\n */\nexport const ThemePlugin = (options: ThemePluginOptions): Plugin[] => {\n // `src` is published too, so only the location tells a workspace checkout from an installed copy.\n const packageRoot = realpathSync(resolve(import.meta.dirname, ROOT));\n const isMonorepo = !packageRoot.split(sep).includes('node_modules');\n\n // Static assets shipped via \"files\": [\"src\"] in package.json.\n // Both monorepo and installed package resolve to the same src/plugins/ directory.\n const pluginsDir = resolve(import.meta.dirname, ROOT, 'src/plugins');\n const darkModeScriptPath = resolve(pluginsDir, 'dark-mode.ts');\n const mainCssPath = resolve(pluginsDir, 'main.css');\n\n const config = {\n // Installed copies get theirs from `configResolved`, which knows the consumer's root.\n srcCssPath: options.srcCssPath ?? (isMonorepo ? resolve(packageRoot, 'src/workspace.css') : ''),\n virtualFileId: options.virtualFileId ?? '@dxos-theme',\n verbose: options.verbose,\n };\n\n // Set under `vite dev --experimentalBundle`; see the guard in `hotUpdate`.\n let bundledDev = false;\n\n // Trailing-edge debounce handle for theme CSS reloads (see `hotUpdate`).\n let themeReloadTimer: ReturnType<typeof setTimeout> | undefined;\n\n // Under Vitest there is no HMR, and a live watcher leaks per-file `fs_event` handles: Tailwind's\n // `@source` scan registers every scanned source file as a Vite watch dependency, and those handles\n // are never released on close, hanging single-pass `vitest run` teardown. A non-null `server.watch`\n // here also overrides the `watch: null` set by the test configs, so gate it: disable the watcher\n // entirely under Vitest (`VITEST` is exported to the whole process tree), keep the HMR-ignore\n // patterns for interactive `storybook dev` / `vite dev` (where `VITEST` is unset).\n const isVitest = process.env.VITEST === 'true';\n\n const themePlugin: Plugin = {\n name: 'vite-plugin-dxos-ui-theme',\n configResolved: (resolved) => {\n bundledDev = resolved.experimental.bundledDev === true;\n if (!config.srcCssPath) {\n config.srcCssPath = writeConsumerTheme({\n packageRoot,\n root: resolved.root,\n outPath: resolve(resolved.cacheDir, '..', '.dxos-ui-theme.css'),\n content: options.content ?? [],\n });\n }\n\n if (process.env.DEBUG || options.verbose) {\n console.log('ThemePlugin:\\n', JSON.stringify(config, null, 2));\n }\n },\n config: (): UserConfig => {\n return {\n server: {\n watch: isVitest\n ? null\n : {\n // Stop build outputs from driving HMR — they are the root of the\n // `main.css` HMR storm.\n //\n // Tailwind's `@source` scanning (see `src/main.css`) registers its\n // scanned source files as Vite watch dependencies of the compiled\n // theme CSS. Tailwind's own scanner respects `.gitignore` (and the\n // `@source not` directives), so it never *scans* `dist/`. BUT the\n // scanner hands Vite a coarse `dir-dependency` glob — e.g.\n // `{**/*.html,**/*.ts,**/*.tsx}` — and Vite re-expands that glob\n // itself, ignoring only `node_modules` (not `.gitignore`, not the\n // `@source not` negations). The re-expansion therefore sweeps in\n // every `packages/*/dist/**/*.d.ts` (`.d.ts` matches `**/*.ts`),\n // making each emitted declaration file a watch-dependency of\n // `main.css`. A single package rebuild emits dozens of `.d.ts` in a\n // tight burst, and each write re-invalidates the theme — 40+ HMR\n // pings for `main.css` in one second, repeating on every rebuild.\n //\n // Ignoring build outputs in the watcher is also semantically\n // correct: in dev the workspace resolves `@dxos/*` via the `source`\n // export condition (see `vite-plugin-import-source`), so `dist/`\n // is never consumed at runtime and its churn should never trigger\n // HMR. Vite concatenates these patterns with its built-in ignores\n // (`**/node_modules/**`, `**/.git/**`, …), so this is purely\n // additive.\n //\n // `<root>/.claude/**` covers agent worktrees checked out under the\n // repo root (`.claude/worktrees/<name>/packages/**`): they are full\n // source copies, so the glob re-expansion above sweeps them in and\n // every agent-side edit burst or checkout invalidates the theme in\n // the user's dev server. The pattern is anchored at the resolved\n // repo root (not `**/.claude/**`) because chokidar matches against\n // absolute paths — a bare pattern would match *everything* when the\n // dev server itself runs from inside a worktree whose path contains\n // a `.claude` segment. `*.log` covers runtime log sinks (e.g.\n // vite-plugin-log's `app.log` in the app root), which are appended\n // continuously at runtime and must never feed back into the\n // watcher.\n ignored: ['**/dist/**', '**/out/**', '**/*.log', `${resolve(import.meta.dirname, ROOT, '.claude')}/**`],\n },\n },\n css: {\n postcss: {\n plugins: [\n // Handles @import statements in CSS.\n postcssImport(),\n // Processes CSS nesting syntax.\n postcssNesting(),\n // Resolves @reference/@apply in `.pcss` files (e.g. lit-grid, lit-ui), which the\n // @tailwindcss/vite plugin skips — its transform filter only matches `.css`.\n // Theme `.css` files are compiled by @tailwindcss/vite first (enforce: 'pre'),\n // so this plugin's quick-bail check passes them through untouched.\n tailwindcssPostcss(),\n // Adds vendor prefixes.\n autoprefixer,\n ],\n },\n },\n };\n },\n resolveId: (id) => {\n if (id === config.virtualFileId) {\n return config.srcCssPath;\n }\n },\n hotUpdate({ type, file, modules }) {\n // Everything below is an optimization of Vite's per-module dev graph, which full-bundle dev\n // mode does not have — and Rolldown's plugin bridge passes no `environment` there, so the\n // first dereference would throw and fail the rebuild instead of updating the page.\n if (bundledDev) {\n return;\n }\n\n // Direct edits to CSS (the theme source or its imports) keep Vite's\n // default immediate update for instant feedback while authoring styles.\n if (this.environment.name !== 'client' || type !== 'update' || file.endsWith('.css')) {\n return;\n }\n\n // Every content file Tailwind scans is registered as a dependency of the\n // theme CSS — Vite models it as a file-only entry node whose importer is\n // `main.css` — so each source-file save invalidates `main.css` and\n // re-runs the monorepo-wide Tailwind scan. During an edit wave that\n // serializes one full scan per save. Drop the theme-dep entries from the\n // update (the changed module itself still hot-updates immediately) and\n // reload the theme CSS once on the trailing edge of a quiet window, so a\n // wave costs at most one scan.\n const isThemeDep = (mod: (typeof modules)[number]): boolean =>\n mod.file === config.srcCssPath ||\n (mod.id === null &&\n mod.importers.size > 0 &&\n [...mod.importers].every((importer) => importer.file === config.srcCssPath));\n if (!modules.some(isThemeDep)) {\n return;\n }\n\n const environment = this.environment;\n clearTimeout(themeReloadTimer);\n themeReloadTimer = setTimeout(() => {\n for (const mod of environment.moduleGraph.getModulesByFile(config.srcCssPath) ?? []) {\n environment.reloadModule(mod).catch(() => {\n // Server may be mid-restart; the next edit reschedules the reload.\n });\n }\n }, 300);\n\n return modules.filter((mod) => !isThemeDep(mod));\n },\n transformIndexHtml: () => {\n // Apply .dark class to <html> synchronously before any scripts run, so that\n // the critical CSS html.dark rules apply on the very first paint.\n const darkModeTag: HtmlTagDescriptor = {\n tag: 'script',\n attrs: { 'data-dxos-theme': '' },\n injectTo: 'head-prepend',\n children: readFileSync(darkModeScriptPath, 'utf-8'),\n };\n\n // Establish cascade layer order before any stylesheet loads.\n const layersTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-layers': '' },\n children: `@layer ${LAYER_ORDER.join(', ')};`,\n injectTo: 'head-prepend',\n };\n\n // Critical styles: font sizing, overscroll, color fallbacks.\n // Loaded from critical.css to keep styles maintainable and out of index.html.\n const criticalTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-critical': '' },\n injectTo: 'head-prepend',\n children: readFileSync(mainCssPath, 'utf-8'),\n };\n\n return [darkModeTag, layersTag, criticalTag];\n },\n };\n\n // The Tailwind Vite plugins are `enforce: 'pre'`, so they compile theme CSS (resolving\n // `@import 'tailwindcss'`, @source, @plugin, @theme) before the postcss chain runs —\n // postcss-import never sees the raw Tailwind directives. Scan roots come from the @source\n // directives in main.css (relative to that file); no project-root base is needed.\n return [...tailwindcssVite().map(skipHotUpdateInBundledDev), themePlugin];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAKA,IAAM,OAAO;;;;;;;;;;;;;AAcb,IAAM,6BAA6B,WAA2B;CAC5D,MAAM,YAAY,OAAO;CACzB,MAAM,UAAU,OAAO,cAAc,aAAa,YAAY,WAAW;CACzE,IAAI,CAAC,SACH,OAAO;CAMT,MAAM,iBAAiB,OAAO;CAC9B,MAAM,0BAA0B,OAAO,mBAAmB,aAAa,iBAAiB,gBAAg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ACF;CAMA,OAAO,CAAC,IAAA,GAAGK,kBAAAA,QAAAA,CAAgB,CAAC,CAAC,IAAI,yBAAyB,GAAG,WAAW;AAC1E"}
|
|
1
|
+
{"version":3,"file":"ThemePlugin.cjs","names":["sep","dirname","resolve","join","existsSync","readFileSync","realpathSync","postcssImport","postcssNesting","tailwindcssPostcss","tailwindcssVite"],"sources":["../../src/plugins/ThemePlugin.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport tailwindcssPostcss from '@tailwindcss/postcss';\nimport tailwindcssVite from '@tailwindcss/vite';\nimport autoprefixer from 'autoprefixer';\nimport { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport postcssImport from 'postcss-import';\nimport postcssNesting from 'postcss-nesting';\nimport { type HtmlTagDescriptor, type Plugin, type UserConfig } from 'vite';\n\n/**\n * CSS cascade layer order.\n * Must be established before any stylesheets load so that Tailwind's own @layer declarations don't override our ordering. Exported so consuming\n */\nexport const LAYER_ORDER = [\n 'properties',\n 'theme',\n 'dx-tokens',\n 'user-tokens',\n 'base',\n 'tw-base',\n 'dx-base',\n 'components',\n 'tw-components',\n 'dx-components',\n 'utilities',\n] as const;\n\n// Package root relative to this module's built location, `dist/plugin/ThemePlugin.{mjs,cjs}`.\n// Tied to the output depth: the two-pass vite build in `vite.plugin.config.ts` emits flat into\n// `dist/plugin`, where the retired pipeline nested a platform slug and a mirrored source tree.\nconst ROOT = '../../';\n\n/**\n * Disable `@tailwindcss/vite`'s `hotUpdate` hook under Vite's full-bundle dev mode.\n *\n * `vite dev --experimentalBundle` routes `hotUpdate` through Rolldown's plugin bridge, whose\n * options object carries no `server` and whose context carries no `environment` — so the hook\n * throws on its first dereference and takes the whole rebuild with it (`TypeError: Cannot read\n * properties of undefined (reading 'environments')`, then `(reading 'name')` once `server` is\n * supplied). Its job is to invalidate the generated CSS in Vite's module graph when a scanned\n * source file changes, and that graph is not what serves CSS under bundled dev, so there is\n * nothing to salvage by filling the gaps in: skipping it keeps HMR working for everything else,\n * at the cost of needing a server restart before a NEWLY USED utility class is generated.\n */\nconst skipHotUpdateInBundledDev = (plugin: Plugin): Plugin => {\n const hotUpdate = plugin.hotUpdate;\n const handler = typeof hotUpdate === 'function' ? hotUpdate : hotUpdate?.handler;\n if (!handler) {\n return plugin;\n }\n\n // Chained rather than assigned: only `@tailwindcss/vite:generate:serve` declares `hotUpdate` and\n // it declares no `configResolved` today, but this package publishes against a caret range where\n // a later minor could add one, and a clobbered hook would fail silently.\n const configResolved = plugin.configResolved;\n const inheritedConfigResolved = typeof configResolved === 'function' ? configResolved : configResolved?.handler;\n\n let bundledDev = false;\n return {\n ...plugin,\n configResolved(config) {\n bundledDev = config.experimental.bundledDev === true;\n return inheritedConfigResolved?.call(this, config);\n },\n hotUpdate: {\n ...(typeof hotUpdate === 'object' ? hotUpdate : {}),\n handler(context) {\n if (bundledDev) {\n return;\n }\n return handler.call(this, context);\n },\n },\n };\n};\n\nexport type ThemePluginOptions = {\n srcCssPath?: string;\n /** Extra Tailwind scan globs (absolute, or relative to the Vite root) for a consumer of the published package. */\n content?: string[];\n virtualFileId?: string;\n verbose?: boolean;\n};\n\nconst toCssString = (path: string): string => JSON.stringify(path.split(sep).join('/'));\n\n/**\n * Writes the theme entry for a consumer of the published package and returns its path.\n * `workspace.css` cannot serve them: its scan paths are relative to this package, which from inside\n * `node_modules` reaches every installed package, and Tailwind walks all of it before answering.\n */\nconst writeConsumerTheme = ({\n packageRoot,\n root,\n outPath,\n content,\n}: {\n packageRoot: string;\n root: string;\n outPath: string;\n content: string[];\n}): string => {\n // The scope this package was installed into, and the consumer's own, which differ under pnpm's isolated layout.\n const scopeDirs = new Set([dirname(packageRoot), resolve(root, 'node_modules/@dxos')]);\n const sources = [\n // Tailwind skips `node_modules` below an explicit base, so this covers only the consumer's own files.\n join(root, '**/*.{ts,tsx,js,jsx,html}'),\n ...[...scopeDirs].map((scopeDir) => join(scopeDir, '*/dist/lib/**/*.mjs')),\n ...content.map((glob) => resolve(root, glob)),\n ];\n const css = [\n `@import ${toCssString(join(packageRoot, 'src/main.css'))};`,\n ...sources.map((source) => `@source ${toCssString(source)};`),\n '',\n ].join('\\n');\n\n // Rewriting identical content would bump the mtime, which Tailwind reads as a reason to rebuild.\n if (!existsSync(outPath) || readFileSync(outPath, 'utf-8') !== css) {\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, css);\n }\n\n return outPath;\n};\n\n/**\n * Vite plugin to configure theme.\n * Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.\n * Every option has a default, so a consumer of the published package can call `ThemePlugin()`.\n */\nexport const ThemePlugin = (options: ThemePluginOptions = {}): Plugin[] => {\n // `src` is published too, so only the location tells a workspace checkout from an installed copy.\n const packageRoot = realpathSync(resolve(import.meta.dirname, ROOT));\n const isMonorepo = !packageRoot.split(sep).includes('node_modules');\n\n // Static assets shipped via \"files\": [\"src\"] in package.json.\n // Both monorepo and installed package resolve to the same src/plugins/ directory.\n const pluginsDir = resolve(import.meta.dirname, ROOT, 'src/plugins');\n const darkModeScriptPath = resolve(pluginsDir, 'dark-mode.ts');\n const mainCssPath = resolve(pluginsDir, 'main.css');\n\n const config = {\n // Installed copies get theirs from `configResolved`, which knows the consumer's root.\n srcCssPath: options.srcCssPath ?? (isMonorepo ? resolve(packageRoot, 'src/workspace.css') : ''),\n virtualFileId: options.virtualFileId ?? '@dxos-theme',\n verbose: options.verbose,\n };\n\n // Set under `vite dev --experimentalBundle`; see the guard in `hotUpdate`.\n let bundledDev = false;\n\n // Trailing-edge debounce handle for theme CSS reloads (see `hotUpdate`).\n let themeReloadTimer: ReturnType<typeof setTimeout> | undefined;\n\n // Under Vitest there is no HMR, and a live watcher leaks per-file `fs_event` handles: Tailwind's\n // `@source` scan registers every scanned source file as a Vite watch dependency, and those handles\n // are never released on close, hanging single-pass `vitest run` teardown. A non-null `server.watch`\n // here also overrides the `watch: null` set by the test configs, so gate it: disable the watcher\n // entirely under Vitest (`VITEST` is exported to the whole process tree), keep the HMR-ignore\n // patterns for interactive `storybook dev` / `vite dev` (where `VITEST` is unset).\n const isVitest = process.env.VITEST === 'true';\n\n const themePlugin: Plugin = {\n name: 'vite-plugin-dxos-ui-theme',\n configResolved: (resolved) => {\n bundledDev = resolved.experimental.bundledDev === true;\n if (!config.srcCssPath) {\n config.srcCssPath = writeConsumerTheme({\n packageRoot,\n root: resolved.root,\n outPath: resolve(resolved.cacheDir, '..', '.dxos-ui-theme.css'),\n content: options.content ?? [],\n });\n }\n\n if (process.env.DEBUG || options.verbose) {\n console.log('ThemePlugin:\\n', JSON.stringify(config, null, 2));\n }\n },\n config: (): UserConfig => {\n return {\n server: {\n watch: isVitest\n ? null\n : {\n // Stop build outputs from driving HMR — they are the root of the\n // `main.css` HMR storm.\n //\n // Tailwind's `@source` scanning (see `src/main.css`) registers its\n // scanned source files as Vite watch dependencies of the compiled\n // theme CSS. Tailwind's own scanner respects `.gitignore` (and the\n // `@source not` directives), so it never *scans* `dist/`. BUT the\n // scanner hands Vite a coarse `dir-dependency` glob — e.g.\n // `{**/*.html,**/*.ts,**/*.tsx}` — and Vite re-expands that glob\n // itself, ignoring only `node_modules` (not `.gitignore`, not the\n // `@source not` negations). The re-expansion therefore sweeps in\n // every `packages/*/dist/**/*.d.ts` (`.d.ts` matches `**/*.ts`),\n // making each emitted declaration file a watch-dependency of\n // `main.css`. A single package rebuild emits dozens of `.d.ts` in a\n // tight burst, and each write re-invalidates the theme — 40+ HMR\n // pings for `main.css` in one second, repeating on every rebuild.\n //\n // Ignoring build outputs in the watcher is also semantically\n // correct: in dev the workspace resolves `@dxos/*` via the `source`\n // export condition (see `vite-plugin-import-source`), so `dist/`\n // is never consumed at runtime and its churn should never trigger\n // HMR. Vite concatenates these patterns with its built-in ignores\n // (`**/node_modules/**`, `**/.git/**`, …), so this is purely\n // additive.\n //\n // `<root>/.claude/**` covers agent worktrees checked out under the\n // repo root (`.claude/worktrees/<name>/packages/**`): they are full\n // source copies, so the glob re-expansion above sweeps them in and\n // every agent-side edit burst or checkout invalidates the theme in\n // the user's dev server. The pattern is anchored at the resolved\n // repo root (not `**/.claude/**`) because chokidar matches against\n // absolute paths — a bare pattern would match *everything* when the\n // dev server itself runs from inside a worktree whose path contains\n // a `.claude` segment. `*.log` covers runtime log sinks (e.g.\n // vite-plugin-log's `app.log` in the app root), which are appended\n // continuously at runtime and must never feed back into the\n // watcher.\n ignored: ['**/dist/**', '**/out/**', '**/*.log', `${resolve(import.meta.dirname, ROOT, '.claude')}/**`],\n },\n },\n css: {\n postcss: {\n plugins: [\n // Handles @import statements in CSS.\n postcssImport(),\n // Processes CSS nesting syntax.\n postcssNesting(),\n // Resolves @reference/@apply in `.pcss` files (e.g. lit-grid, lit-ui), which the\n // @tailwindcss/vite plugin skips — its transform filter only matches `.css`.\n // Theme `.css` files are compiled by @tailwindcss/vite first (enforce: 'pre'),\n // so this plugin's quick-bail check passes them through untouched.\n tailwindcssPostcss(),\n // Adds vendor prefixes.\n autoprefixer,\n ],\n },\n },\n };\n },\n resolveId: (id) => {\n if (id === config.virtualFileId) {\n return config.srcCssPath;\n }\n },\n hotUpdate({ type, file, modules }) {\n // Everything below is an optimization of Vite's per-module dev graph, which full-bundle dev\n // mode does not have — and Rolldown's plugin bridge passes no `environment` there, so the\n // first dereference would throw and fail the rebuild instead of updating the page.\n if (bundledDev) {\n return;\n }\n\n // Direct edits to CSS (the theme source or its imports) keep Vite's\n // default immediate update for instant feedback while authoring styles.\n if (this.environment.name !== 'client' || type !== 'update' || file.endsWith('.css')) {\n return;\n }\n\n // Every content file Tailwind scans is registered as a dependency of the\n // theme CSS — Vite models it as a file-only entry node whose importer is\n // `main.css` — so each source-file save invalidates `main.css` and\n // re-runs the monorepo-wide Tailwind scan. During an edit wave that\n // serializes one full scan per save. Drop the theme-dep entries from the\n // update (the changed module itself still hot-updates immediately) and\n // reload the theme CSS once on the trailing edge of a quiet window, so a\n // wave costs at most one scan.\n const isThemeDep = (mod: (typeof modules)[number]): boolean =>\n mod.file === config.srcCssPath ||\n (mod.id === null &&\n mod.importers.size > 0 &&\n [...mod.importers].every((importer) => importer.file === config.srcCssPath));\n if (!modules.some(isThemeDep)) {\n return;\n }\n\n const environment = this.environment;\n clearTimeout(themeReloadTimer);\n themeReloadTimer = setTimeout(() => {\n for (const mod of environment.moduleGraph.getModulesByFile(config.srcCssPath) ?? []) {\n environment.reloadModule(mod).catch(() => {\n // Server may be mid-restart; the next edit reschedules the reload.\n });\n }\n }, 300);\n\n return modules.filter((mod) => !isThemeDep(mod));\n },\n transformIndexHtml: () => {\n // Apply .dark class to <html> synchronously before any scripts run, so that\n // the critical CSS html.dark rules apply on the very first paint.\n const darkModeTag: HtmlTagDescriptor = {\n tag: 'script',\n attrs: { 'data-dxos-theme': '' },\n injectTo: 'head-prepend',\n children: readFileSync(darkModeScriptPath, 'utf-8'),\n };\n\n // Establish cascade layer order before any stylesheet loads.\n const layersTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-layers': '' },\n children: `@layer ${LAYER_ORDER.join(', ')};`,\n injectTo: 'head-prepend',\n };\n\n // Critical styles: font sizing, overscroll, color fallbacks.\n // Loaded from critical.css to keep styles maintainable and out of index.html.\n const criticalTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-critical': '' },\n injectTo: 'head-prepend',\n children: readFileSync(mainCssPath, 'utf-8'),\n };\n\n return [darkModeTag, layersTag, criticalTag];\n },\n };\n\n // The Tailwind Vite plugins are `enforce: 'pre'`, so they compile theme CSS (resolving\n // `@import 'tailwindcss'`, @source, @plugin, @theme) before the postcss chain runs —\n // postcss-import never sees the raw Tailwind directives. Scan roots come from the @source\n // directives in main.css (relative to that file); no project-root base is needed.\n return [...tailwindcssVite().map(skipHotUpdateInBundledDev), themePlugin];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AE,mBAAmB,GAAG;KAC/B,UAAU;KACV,WAAA,GAAUJ,QAAAA,aAAAA,CAAa,oBAAoB,OAAO;IAoB5C;IAAa;KAfnB,KAAK;KACL,OAAO,EAAE,oBAAoB,GAAG;KAChC,UAAU,UAAU,YAAY,KAAK,IAAI,EAAE;KAC3C,UAAU;IAYS;IAAW;KAN9B,KAAK;KACL,OAAO,EAAE,sBAAsB,GAAG;KAClC,UAAU;KACV,WAAA,GAAUA,QAAAA,aAAAA,CAAa,aAAa,OAAO;IAGb;GAAW;EAC7C;CACF;CAMA,OAAO,CAAC,IAAA,GAAGK,kBAAAA,QAAAA,CAAgB,CAAC,CAAC,IAAI,yBAAyB,GAAG,WAAW;AAC1E"}
|
|
@@ -85,8 +85,9 @@ var writeConsumerTheme = ({ packageRoot, root, outPath, content }) => {
|
|
|
85
85
|
/**
|
|
86
86
|
* Vite plugin to configure theme.
|
|
87
87
|
* Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.
|
|
88
|
+
* Every option has a default, so a consumer of the published package can call `ThemePlugin()`.
|
|
88
89
|
*/
|
|
89
|
-
var ThemePlugin = (options) => {
|
|
90
|
+
var ThemePlugin = (options = {}) => {
|
|
90
91
|
const packageRoot = realpathSync(resolve(import.meta.dirname, ROOT));
|
|
91
92
|
const isMonorepo = !packageRoot.split(sep).includes("node_modules");
|
|
92
93
|
const pluginsDir = resolve(import.meta.dirname, ROOT, "src/plugins");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemePlugin.mjs","names":[],"sources":["../../src/plugins/ThemePlugin.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport tailwindcssPostcss from '@tailwindcss/postcss';\nimport tailwindcssVite from '@tailwindcss/vite';\nimport autoprefixer from 'autoprefixer';\nimport { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport postcssImport from 'postcss-import';\nimport postcssNesting from 'postcss-nesting';\nimport { type HtmlTagDescriptor, type Plugin, type UserConfig } from 'vite';\n\n/**\n * CSS cascade layer order.\n * Must be established before any stylesheets load so that Tailwind's own @layer declarations don't override our ordering. Exported so consuming\n */\nexport const LAYER_ORDER = [\n 'properties',\n 'theme',\n 'dx-tokens',\n 'user-tokens',\n 'base',\n 'tw-base',\n 'dx-base',\n 'components',\n 'tw-components',\n 'dx-components',\n 'utilities',\n] as const;\n\n// Package root relative to this module's built location, `dist/plugin/ThemePlugin.{mjs,cjs}`.\n// Tied to the output depth: the two-pass vite build in `vite.plugin.config.ts` emits flat into\n// `dist/plugin`, where the retired pipeline nested a platform slug and a mirrored source tree.\nconst ROOT = '../../';\n\n/**\n * Disable `@tailwindcss/vite`'s `hotUpdate` hook under Vite's full-bundle dev mode.\n *\n * `vite dev --experimentalBundle` routes `hotUpdate` through Rolldown's plugin bridge, whose\n * options object carries no `server` and whose context carries no `environment` — so the hook\n * throws on its first dereference and takes the whole rebuild with it (`TypeError: Cannot read\n * properties of undefined (reading 'environments')`, then `(reading 'name')` once `server` is\n * supplied). Its job is to invalidate the generated CSS in Vite's module graph when a scanned\n * source file changes, and that graph is not what serves CSS under bundled dev, so there is\n * nothing to salvage by filling the gaps in: skipping it keeps HMR working for everything else,\n * at the cost of needing a server restart before a NEWLY USED utility class is generated.\n */\nconst skipHotUpdateInBundledDev = (plugin: Plugin): Plugin => {\n const hotUpdate = plugin.hotUpdate;\n const handler = typeof hotUpdate === 'function' ? hotUpdate : hotUpdate?.handler;\n if (!handler) {\n return plugin;\n }\n\n // Chained rather than assigned: only `@tailwindcss/vite:generate:serve` declares `hotUpdate` and\n // it declares no `configResolved` today, but this package publishes against a caret range where\n // a later minor could add one, and a clobbered hook would fail silently.\n const configResolved = plugin.configResolved;\n const inheritedConfigResolved = typeof configResolved === 'function' ? configResolved : configResolved?.handler;\n\n let bundledDev = false;\n return {\n ...plugin,\n configResolved(config) {\n bundledDev = config.experimental.bundledDev === true;\n return inheritedConfigResolved?.call(this, config);\n },\n hotUpdate: {\n ...(typeof hotUpdate === 'object' ? hotUpdate : {}),\n handler(context) {\n if (bundledDev) {\n return;\n }\n return handler.call(this, context);\n },\n },\n };\n};\n\nexport type ThemePluginOptions = {\n srcCssPath?: string;\n /** Extra Tailwind scan globs (absolute, or relative to the Vite root) for a consumer of the published package. */\n content?: string[];\n virtualFileId?: string;\n verbose?: boolean;\n};\n\nconst toCssString = (path: string): string => JSON.stringify(path.split(sep).join('/'));\n\n/**\n * Writes the theme entry for a consumer of the published package and returns its path.\n * `workspace.css` cannot serve them: its scan paths are relative to this package, which from inside\n * `node_modules` reaches every installed package, and Tailwind walks all of it before answering.\n */\nconst writeConsumerTheme = ({\n packageRoot,\n root,\n outPath,\n content,\n}: {\n packageRoot: string;\n root: string;\n outPath: string;\n content: string[];\n}): string => {\n // The scope this package was installed into, and the consumer's own, which differ under pnpm's isolated layout.\n const scopeDirs = new Set([dirname(packageRoot), resolve(root, 'node_modules/@dxos')]);\n const sources = [\n // Tailwind skips `node_modules` below an explicit base, so this covers only the consumer's own files.\n join(root, '**/*.{ts,tsx,js,jsx,html}'),\n ...[...scopeDirs].map((scopeDir) => join(scopeDir, '*/dist/lib/**/*.mjs')),\n ...content.map((glob) => resolve(root, glob)),\n ];\n const css = [\n `@import ${toCssString(join(packageRoot, 'src/main.css'))};`,\n ...sources.map((source) => `@source ${toCssString(source)};`),\n '',\n ].join('\\n');\n\n // Rewriting identical content would bump the mtime, which Tailwind reads as a reason to rebuild.\n if (!existsSync(outPath) || readFileSync(outPath, 'utf-8') !== css) {\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, css);\n }\n\n return outPath;\n};\n\n/**\n * Vite plugin to configure theme.\n * Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.\n */\nexport const ThemePlugin = (options: ThemePluginOptions): Plugin[] => {\n // `src` is published too, so only the location tells a workspace checkout from an installed copy.\n const packageRoot = realpathSync(resolve(import.meta.dirname, ROOT));\n const isMonorepo = !packageRoot.split(sep).includes('node_modules');\n\n // Static assets shipped via \"files\": [\"src\"] in package.json.\n // Both monorepo and installed package resolve to the same src/plugins/ directory.\n const pluginsDir = resolve(import.meta.dirname, ROOT, 'src/plugins');\n const darkModeScriptPath = resolve(pluginsDir, 'dark-mode.ts');\n const mainCssPath = resolve(pluginsDir, 'main.css');\n\n const config = {\n // Installed copies get theirs from `configResolved`, which knows the consumer's root.\n srcCssPath: options.srcCssPath ?? (isMonorepo ? resolve(packageRoot, 'src/workspace.css') : ''),\n virtualFileId: options.virtualFileId ?? '@dxos-theme',\n verbose: options.verbose,\n };\n\n // Set under `vite dev --experimentalBundle`; see the guard in `hotUpdate`.\n let bundledDev = false;\n\n // Trailing-edge debounce handle for theme CSS reloads (see `hotUpdate`).\n let themeReloadTimer: ReturnType<typeof setTimeout> | undefined;\n\n // Under Vitest there is no HMR, and a live watcher leaks per-file `fs_event` handles: Tailwind's\n // `@source` scan registers every scanned source file as a Vite watch dependency, and those handles\n // are never released on close, hanging single-pass `vitest run` teardown. A non-null `server.watch`\n // here also overrides the `watch: null` set by the test configs, so gate it: disable the watcher\n // entirely under Vitest (`VITEST` is exported to the whole process tree), keep the HMR-ignore\n // patterns for interactive `storybook dev` / `vite dev` (where `VITEST` is unset).\n const isVitest = process.env.VITEST === 'true';\n\n const themePlugin: Plugin = {\n name: 'vite-plugin-dxos-ui-theme',\n configResolved: (resolved) => {\n bundledDev = resolved.experimental.bundledDev === true;\n if (!config.srcCssPath) {\n config.srcCssPath = writeConsumerTheme({\n packageRoot,\n root: resolved.root,\n outPath: resolve(resolved.cacheDir, '..', '.dxos-ui-theme.css'),\n content: options.content ?? [],\n });\n }\n\n if (process.env.DEBUG || options.verbose) {\n console.log('ThemePlugin:\\n', JSON.stringify(config, null, 2));\n }\n },\n config: (): UserConfig => {\n return {\n server: {\n watch: isVitest\n ? null\n : {\n // Stop build outputs from driving HMR — they are the root of the\n // `main.css` HMR storm.\n //\n // Tailwind's `@source` scanning (see `src/main.css`) registers its\n // scanned source files as Vite watch dependencies of the compiled\n // theme CSS. Tailwind's own scanner respects `.gitignore` (and the\n // `@source not` directives), so it never *scans* `dist/`. BUT the\n // scanner hands Vite a coarse `dir-dependency` glob — e.g.\n // `{**/*.html,**/*.ts,**/*.tsx}` — and Vite re-expands that glob\n // itself, ignoring only `node_modules` (not `.gitignore`, not the\n // `@source not` negations). The re-expansion therefore sweeps in\n // every `packages/*/dist/**/*.d.ts` (`.d.ts` matches `**/*.ts`),\n // making each emitted declaration file a watch-dependency of\n // `main.css`. A single package rebuild emits dozens of `.d.ts` in a\n // tight burst, and each write re-invalidates the theme — 40+ HMR\n // pings for `main.css` in one second, repeating on every rebuild.\n //\n // Ignoring build outputs in the watcher is also semantically\n // correct: in dev the workspace resolves `@dxos/*` via the `source`\n // export condition (see `vite-plugin-import-source`), so `dist/`\n // is never consumed at runtime and its churn should never trigger\n // HMR. Vite concatenates these patterns with its built-in ignores\n // (`**/node_modules/**`, `**/.git/**`, …), so this is purely\n // additive.\n //\n // `<root>/.claude/**` covers agent worktrees checked out under the\n // repo root (`.claude/worktrees/<name>/packages/**`): they are full\n // source copies, so the glob re-expansion above sweeps them in and\n // every agent-side edit burst or checkout invalidates the theme in\n // the user's dev server. The pattern is anchored at the resolved\n // repo root (not `**/.claude/**`) because chokidar matches against\n // absolute paths — a bare pattern would match *everything* when the\n // dev server itself runs from inside a worktree whose path contains\n // a `.claude` segment. `*.log` covers runtime log sinks (e.g.\n // vite-plugin-log's `app.log` in the app root), which are appended\n // continuously at runtime and must never feed back into the\n // watcher.\n ignored: ['**/dist/**', '**/out/**', '**/*.log', `${resolve(import.meta.dirname, ROOT, '.claude')}/**`],\n },\n },\n css: {\n postcss: {\n plugins: [\n // Handles @import statements in CSS.\n postcssImport(),\n // Processes CSS nesting syntax.\n postcssNesting(),\n // Resolves @reference/@apply in `.pcss` files (e.g. lit-grid, lit-ui), which the\n // @tailwindcss/vite plugin skips — its transform filter only matches `.css`.\n // Theme `.css` files are compiled by @tailwindcss/vite first (enforce: 'pre'),\n // so this plugin's quick-bail check passes them through untouched.\n tailwindcssPostcss(),\n // Adds vendor prefixes.\n autoprefixer,\n ],\n },\n },\n };\n },\n resolveId: (id) => {\n if (id === config.virtualFileId) {\n return config.srcCssPath;\n }\n },\n hotUpdate({ type, file, modules }) {\n // Everything below is an optimization of Vite's per-module dev graph, which full-bundle dev\n // mode does not have — and Rolldown's plugin bridge passes no `environment` there, so the\n // first dereference would throw and fail the rebuild instead of updating the page.\n if (bundledDev) {\n return;\n }\n\n // Direct edits to CSS (the theme source or its imports) keep Vite's\n // default immediate update for instant feedback while authoring styles.\n if (this.environment.name !== 'client' || type !== 'update' || file.endsWith('.css')) {\n return;\n }\n\n // Every content file Tailwind scans is registered as a dependency of the\n // theme CSS — Vite models it as a file-only entry node whose importer is\n // `main.css` — so each source-file save invalidates `main.css` and\n // re-runs the monorepo-wide Tailwind scan. During an edit wave that\n // serializes one full scan per save. Drop the theme-dep entries from the\n // update (the changed module itself still hot-updates immediately) and\n // reload the theme CSS once on the trailing edge of a quiet window, so a\n // wave costs at most one scan.\n const isThemeDep = (mod: (typeof modules)[number]): boolean =>\n mod.file === config.srcCssPath ||\n (mod.id === null &&\n mod.importers.size > 0 &&\n [...mod.importers].every((importer) => importer.file === config.srcCssPath));\n if (!modules.some(isThemeDep)) {\n return;\n }\n\n const environment = this.environment;\n clearTimeout(themeReloadTimer);\n themeReloadTimer = setTimeout(() => {\n for (const mod of environment.moduleGraph.getModulesByFile(config.srcCssPath) ?? []) {\n environment.reloadModule(mod).catch(() => {\n // Server may be mid-restart; the next edit reschedules the reload.\n });\n }\n }, 300);\n\n return modules.filter((mod) => !isThemeDep(mod));\n },\n transformIndexHtml: () => {\n // Apply .dark class to <html> synchronously before any scripts run, so that\n // the critical CSS html.dark rules apply on the very first paint.\n const darkModeTag: HtmlTagDescriptor = {\n tag: 'script',\n attrs: { 'data-dxos-theme': '' },\n injectTo: 'head-prepend',\n children: readFileSync(darkModeScriptPath, 'utf-8'),\n };\n\n // Establish cascade layer order before any stylesheet loads.\n const layersTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-layers': '' },\n children: `@layer ${LAYER_ORDER.join(', ')};`,\n injectTo: 'head-prepend',\n };\n\n // Critical styles: font sizing, overscroll, color fallbacks.\n // Loaded from critical.css to keep styles maintainable and out of index.html.\n const criticalTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-critical': '' },\n injectTo: 'head-prepend',\n children: readFileSync(mainCssPath, 'utf-8'),\n };\n\n return [darkModeTag, layersTag, criticalTag];\n },\n };\n\n // The Tailwind Vite plugins are `enforce: 'pre'`, so they compile theme CSS (resolving\n // `@import 'tailwindcss'`, @source, @plugin, @theme) before the postcss chain runs —\n // postcss-import never sees the raw Tailwind directives. Scan roots come from the @source\n // directives in main.css (relative to that file); no project-root base is needed.\n return [...tailwindcssVite().map(skipHotUpdateInBundledDev), themePlugin];\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAKA,IAAM,OAAO;;;;;;;;;;;;;AAcb,IAAM,6BAA6B,WAA2B;CAC5D,MAAM,YAAY,OAAO;CACzB,MAAM,UAAU,OAAO,cAAc,aAAa,YAAY,WAAW;CACzE,IAAI,CAAC,SACH,OAAO;CAMT,MAAM,iBAAiB,OAAO;CAC9B,MAAM,0BAA0B,OAAO,mBAAmB,aAAa,iBAAiB,gBAAgB;CAExG,IAAI,aAAa;CACjB,OAAO;EACL,GAAG;EACH,eAAe,QAAQ;GACrB,aAAa,OAAO,aAAa,eAAe;GAChD,OAAO,yBAAyB,KAAK,MAAM,MAAM;EACnD;EACA,WAAW;GACT,GAAI,OAAO,cAAc,WAAW,YAAY,CAAC;GACjD,QAAQ,SAAS;IACf,IAAI,YACF;IAEF,OAAO,QAAQ,KAAK,MA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CAAC;GAEL,GAAG,GAAG;GAEN,OAAO,QAAQ,QAAQ,QAAQ,CAAC,WAAW,GAAG,CAAC;EACjD;EACA,0BAA0B;GA2BxB,OAAO;IAAC;KAvBN,KAAK;KACL,OAAO,EAAE,mBAAmB,GAAG;KAC/B,UAAU;KACV,UAAU,aAAa,oBAAoB,OAAO;IAoB5C;IAAa;KAfnB,KAAK;KACL,OAAO,EAAE,oBAAoB,GAAG;KAChC,UAAU,UAAU,YAAY,KAAK,IAAI,EAAE;KAC3C,UAAU;IAYS;IAAW;KAN9B,KAAK;KACL,OAAO,EAAE,sBAAsB,GAAG;KAClC,UAAU;KACV,UAAU,aAAa,aAAa,OAAO;IAGb;GAAW;EAC7C;CACF;CAMA,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC,IAAI,yBAAyB,GAAG,WAAW;AAC1E"}
|
|
1
|
+
{"version":3,"file":"ThemePlugin.mjs","names":[],"sources":["../../src/plugins/ThemePlugin.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n/* eslint-disable no-console */\n\nimport tailwindcssPostcss from '@tailwindcss/postcss';\nimport tailwindcssVite from '@tailwindcss/vite';\nimport autoprefixer from 'autoprefixer';\nimport { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve, sep } from 'node:path';\nimport postcssImport from 'postcss-import';\nimport postcssNesting from 'postcss-nesting';\nimport { type HtmlTagDescriptor, type Plugin, type UserConfig } from 'vite';\n\n/**\n * CSS cascade layer order.\n * Must be established before any stylesheets load so that Tailwind's own @layer declarations don't override our ordering. Exported so consuming\n */\nexport const LAYER_ORDER = [\n 'properties',\n 'theme',\n 'dx-tokens',\n 'user-tokens',\n 'base',\n 'tw-base',\n 'dx-base',\n 'components',\n 'tw-components',\n 'dx-components',\n 'utilities',\n] as const;\n\n// Package root relative to this module's built location, `dist/plugin/ThemePlugin.{mjs,cjs}`.\n// Tied to the output depth: the two-pass vite build in `vite.plugin.config.ts` emits flat into\n// `dist/plugin`, where the retired pipeline nested a platform slug and a mirrored source tree.\nconst ROOT = '../../';\n\n/**\n * Disable `@tailwindcss/vite`'s `hotUpdate` hook under Vite's full-bundle dev mode.\n *\n * `vite dev --experimentalBundle` routes `hotUpdate` through Rolldown's plugin bridge, whose\n * options object carries no `server` and whose context carries no `environment` — so the hook\n * throws on its first dereference and takes the whole rebuild with it (`TypeError: Cannot read\n * properties of undefined (reading 'environments')`, then `(reading 'name')` once `server` is\n * supplied). Its job is to invalidate the generated CSS in Vite's module graph when a scanned\n * source file changes, and that graph is not what serves CSS under bundled dev, so there is\n * nothing to salvage by filling the gaps in: skipping it keeps HMR working for everything else,\n * at the cost of needing a server restart before a NEWLY USED utility class is generated.\n */\nconst skipHotUpdateInBundledDev = (plugin: Plugin): Plugin => {\n const hotUpdate = plugin.hotUpdate;\n const handler = typeof hotUpdate === 'function' ? hotUpdate : hotUpdate?.handler;\n if (!handler) {\n return plugin;\n }\n\n // Chained rather than assigned: only `@tailwindcss/vite:generate:serve` declares `hotUpdate` and\n // it declares no `configResolved` today, but this package publishes against a caret range where\n // a later minor could add one, and a clobbered hook would fail silently.\n const configResolved = plugin.configResolved;\n const inheritedConfigResolved = typeof configResolved === 'function' ? configResolved : configResolved?.handler;\n\n let bundledDev = false;\n return {\n ...plugin,\n configResolved(config) {\n bundledDev = config.experimental.bundledDev === true;\n return inheritedConfigResolved?.call(this, config);\n },\n hotUpdate: {\n ...(typeof hotUpdate === 'object' ? hotUpdate : {}),\n handler(context) {\n if (bundledDev) {\n return;\n }\n return handler.call(this, context);\n },\n },\n };\n};\n\nexport type ThemePluginOptions = {\n srcCssPath?: string;\n /** Extra Tailwind scan globs (absolute, or relative to the Vite root) for a consumer of the published package. */\n content?: string[];\n virtualFileId?: string;\n verbose?: boolean;\n};\n\nconst toCssString = (path: string): string => JSON.stringify(path.split(sep).join('/'));\n\n/**\n * Writes the theme entry for a consumer of the published package and returns its path.\n * `workspace.css` cannot serve them: its scan paths are relative to this package, which from inside\n * `node_modules` reaches every installed package, and Tailwind walks all of it before answering.\n */\nconst writeConsumerTheme = ({\n packageRoot,\n root,\n outPath,\n content,\n}: {\n packageRoot: string;\n root: string;\n outPath: string;\n content: string[];\n}): string => {\n // The scope this package was installed into, and the consumer's own, which differ under pnpm's isolated layout.\n const scopeDirs = new Set([dirname(packageRoot), resolve(root, 'node_modules/@dxos')]);\n const sources = [\n // Tailwind skips `node_modules` below an explicit base, so this covers only the consumer's own files.\n join(root, '**/*.{ts,tsx,js,jsx,html}'),\n ...[...scopeDirs].map((scopeDir) => join(scopeDir, '*/dist/lib/**/*.mjs')),\n ...content.map((glob) => resolve(root, glob)),\n ];\n const css = [\n `@import ${toCssString(join(packageRoot, 'src/main.css'))};`,\n ...sources.map((source) => `@source ${toCssString(source)};`),\n '',\n ].join('\\n');\n\n // Rewriting identical content would bump the mtime, which Tailwind reads as a reason to rebuild.\n if (!existsSync(outPath) || readFileSync(outPath, 'utf-8') !== css) {\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, css);\n }\n\n return outPath;\n};\n\n/**\n * Vite plugin to configure theme.\n * Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.\n * Every option has a default, so a consumer of the published package can call `ThemePlugin()`.\n */\nexport const ThemePlugin = (options: ThemePluginOptions = {}): Plugin[] => {\n // `src` is published too, so only the location tells a workspace checkout from an installed copy.\n const packageRoot = realpathSync(resolve(import.meta.dirname, ROOT));\n const isMonorepo = !packageRoot.split(sep).includes('node_modules');\n\n // Static assets shipped via \"files\": [\"src\"] in package.json.\n // Both monorepo and installed package resolve to the same src/plugins/ directory.\n const pluginsDir = resolve(import.meta.dirname, ROOT, 'src/plugins');\n const darkModeScriptPath = resolve(pluginsDir, 'dark-mode.ts');\n const mainCssPath = resolve(pluginsDir, 'main.css');\n\n const config = {\n // Installed copies get theirs from `configResolved`, which knows the consumer's root.\n srcCssPath: options.srcCssPath ?? (isMonorepo ? resolve(packageRoot, 'src/workspace.css') : ''),\n virtualFileId: options.virtualFileId ?? '@dxos-theme',\n verbose: options.verbose,\n };\n\n // Set under `vite dev --experimentalBundle`; see the guard in `hotUpdate`.\n let bundledDev = false;\n\n // Trailing-edge debounce handle for theme CSS reloads (see `hotUpdate`).\n let themeReloadTimer: ReturnType<typeof setTimeout> | undefined;\n\n // Under Vitest there is no HMR, and a live watcher leaks per-file `fs_event` handles: Tailwind's\n // `@source` scan registers every scanned source file as a Vite watch dependency, and those handles\n // are never released on close, hanging single-pass `vitest run` teardown. A non-null `server.watch`\n // here also overrides the `watch: null` set by the test configs, so gate it: disable the watcher\n // entirely under Vitest (`VITEST` is exported to the whole process tree), keep the HMR-ignore\n // patterns for interactive `storybook dev` / `vite dev` (where `VITEST` is unset).\n const isVitest = process.env.VITEST === 'true';\n\n const themePlugin: Plugin = {\n name: 'vite-plugin-dxos-ui-theme',\n configResolved: (resolved) => {\n bundledDev = resolved.experimental.bundledDev === true;\n if (!config.srcCssPath) {\n config.srcCssPath = writeConsumerTheme({\n packageRoot,\n root: resolved.root,\n outPath: resolve(resolved.cacheDir, '..', '.dxos-ui-theme.css'),\n content: options.content ?? [],\n });\n }\n\n if (process.env.DEBUG || options.verbose) {\n console.log('ThemePlugin:\\n', JSON.stringify(config, null, 2));\n }\n },\n config: (): UserConfig => {\n return {\n server: {\n watch: isVitest\n ? null\n : {\n // Stop build outputs from driving HMR — they are the root of the\n // `main.css` HMR storm.\n //\n // Tailwind's `@source` scanning (see `src/main.css`) registers its\n // scanned source files as Vite watch dependencies of the compiled\n // theme CSS. Tailwind's own scanner respects `.gitignore` (and the\n // `@source not` directives), so it never *scans* `dist/`. BUT the\n // scanner hands Vite a coarse `dir-dependency` glob — e.g.\n // `{**/*.html,**/*.ts,**/*.tsx}` — and Vite re-expands that glob\n // itself, ignoring only `node_modules` (not `.gitignore`, not the\n // `@source not` negations). The re-expansion therefore sweeps in\n // every `packages/*/dist/**/*.d.ts` (`.d.ts` matches `**/*.ts`),\n // making each emitted declaration file a watch-dependency of\n // `main.css`. A single package rebuild emits dozens of `.d.ts` in a\n // tight burst, and each write re-invalidates the theme — 40+ HMR\n // pings for `main.css` in one second, repeating on every rebuild.\n //\n // Ignoring build outputs in the watcher is also semantically\n // correct: in dev the workspace resolves `@dxos/*` via the `source`\n // export condition (see `vite-plugin-import-source`), so `dist/`\n // is never consumed at runtime and its churn should never trigger\n // HMR. Vite concatenates these patterns with its built-in ignores\n // (`**/node_modules/**`, `**/.git/**`, …), so this is purely\n // additive.\n //\n // `<root>/.claude/**` covers agent worktrees checked out under the\n // repo root (`.claude/worktrees/<name>/packages/**`): they are full\n // source copies, so the glob re-expansion above sweeps them in and\n // every agent-side edit burst or checkout invalidates the theme in\n // the user's dev server. The pattern is anchored at the resolved\n // repo root (not `**/.claude/**`) because chokidar matches against\n // absolute paths — a bare pattern would match *everything* when the\n // dev server itself runs from inside a worktree whose path contains\n // a `.claude` segment. `*.log` covers runtime log sinks (e.g.\n // vite-plugin-log's `app.log` in the app root), which are appended\n // continuously at runtime and must never feed back into the\n // watcher.\n ignored: ['**/dist/**', '**/out/**', '**/*.log', `${resolve(import.meta.dirname, ROOT, '.claude')}/**`],\n },\n },\n css: {\n postcss: {\n plugins: [\n // Handles @import statements in CSS.\n postcssImport(),\n // Processes CSS nesting syntax.\n postcssNesting(),\n // Resolves @reference/@apply in `.pcss` files (e.g. lit-grid, lit-ui), which the\n // @tailwindcss/vite plugin skips — its transform filter only matches `.css`.\n // Theme `.css` files are compiled by @tailwindcss/vite first (enforce: 'pre'),\n // so this plugin's quick-bail check passes them through untouched.\n tailwindcssPostcss(),\n // Adds vendor prefixes.\n autoprefixer,\n ],\n },\n },\n };\n },\n resolveId: (id) => {\n if (id === config.virtualFileId) {\n return config.srcCssPath;\n }\n },\n hotUpdate({ type, file, modules }) {\n // Everything below is an optimization of Vite's per-module dev graph, which full-bundle dev\n // mode does not have — and Rolldown's plugin bridge passes no `environment` there, so the\n // first dereference would throw and fail the rebuild instead of updating the page.\n if (bundledDev) {\n return;\n }\n\n // Direct edits to CSS (the theme source or its imports) keep Vite's\n // default immediate update for instant feedback while authoring styles.\n if (this.environment.name !== 'client' || type !== 'update' || file.endsWith('.css')) {\n return;\n }\n\n // Every content file Tailwind scans is registered as a dependency of the\n // theme CSS — Vite models it as a file-only entry node whose importer is\n // `main.css` — so each source-file save invalidates `main.css` and\n // re-runs the monorepo-wide Tailwind scan. During an edit wave that\n // serializes one full scan per save. Drop the theme-dep entries from the\n // update (the changed module itself still hot-updates immediately) and\n // reload the theme CSS once on the trailing edge of a quiet window, so a\n // wave costs at most one scan.\n const isThemeDep = (mod: (typeof modules)[number]): boolean =>\n mod.file === config.srcCssPath ||\n (mod.id === null &&\n mod.importers.size > 0 &&\n [...mod.importers].every((importer) => importer.file === config.srcCssPath));\n if (!modules.some(isThemeDep)) {\n return;\n }\n\n const environment = this.environment;\n clearTimeout(themeReloadTimer);\n themeReloadTimer = setTimeout(() => {\n for (const mod of environment.moduleGraph.getModulesByFile(config.srcCssPath) ?? []) {\n environment.reloadModule(mod).catch(() => {\n // Server may be mid-restart; the next edit reschedules the reload.\n });\n }\n }, 300);\n\n return modules.filter((mod) => !isThemeDep(mod));\n },\n transformIndexHtml: () => {\n // Apply .dark class to <html> synchronously before any scripts run, so that\n // the critical CSS html.dark rules apply on the very first paint.\n const darkModeTag: HtmlTagDescriptor = {\n tag: 'script',\n attrs: { 'data-dxos-theme': '' },\n injectTo: 'head-prepend',\n children: readFileSync(darkModeScriptPath, 'utf-8'),\n };\n\n // Establish cascade layer order before any stylesheet loads.\n const layersTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-layers': '' },\n children: `@layer ${LAYER_ORDER.join(', ')};`,\n injectTo: 'head-prepend',\n };\n\n // Critical styles: font sizing, overscroll, color fallbacks.\n // Loaded from critical.css to keep styles maintainable and out of index.html.\n const criticalTag: HtmlTagDescriptor = {\n tag: 'style',\n attrs: { 'data-dxos-critical': '' },\n injectTo: 'head-prepend',\n children: readFileSync(mainCssPath, 'utf-8'),\n };\n\n return [darkModeTag, layersTag, criticalTag];\n },\n };\n\n // The Tailwind Vite plugins are `enforce: 'pre'`, so they compile theme CSS (resolving\n // `@import 'tailwindcss'`, @source, @plugin, @theme) before the postcss chain runs —\n // postcss-import never sees the raw Tailwind directives. Scan roots come from the @source\n // directives in main.css (relative to that file); no project-root base is needed.\n return [...tailwindcssVite().map(skipHotUpdateInBundledDev), themePlugin];\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAKA,IAAM,OAAO;;;;;;;;;;;;;AAcb,IAAM,6BAA6B,WAA2B;CAC5D,MAAM,YAAY,OAAO;CACzB,MAAM,UAAU,OAAO,cAAc,aAAa,YAAY,WAAW;CACzE,IAAI,CAAC,SACH,OAAO;CAMT,MAAM,iBAAiB,OAAO;CAC9B,MAAM,0BAA0B,OAAO,mBAAmB,aAAa,iBAAiB,gBAAgB;CAExG,IAAI,aAAa;CACjB,OAAO;EACL,GAAG;EACH,eAAe,QAAQ;GACrB,aAAa,OAAO,aAAa,eAAe;GAChD,OAAO,yBAAyB,KAAK,MAAM,MAAM;EACnD;EACA,WAAW;GACT,GAAI,OAAO,cAAc,WAAW,YAAY,CAAC;GACjD,QAAQ,SAAS;IACf,IAAI,YACF;IAEF,OAAO,QAAQ,KAAK,MAAM,OAAO;GACnC;EACF;CACF;AACF;AAUA,IAAM,eAAe,SAAyB,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;;;;;;AAOtF,IAAM,sBAAsB,EAC1B,aACA,MACA,SACA,cAMY;CAEZ,MAAM,4BAAY,IAAI,IAAI,CAAC,QAAQ,WAAW,GAAG,QAAQ,MAAM,oBAAoB,CAAC,CAAC;CACrF,MAAM,UAAU;EAEd,KAAK,MAAM,2BAA2B;EACtC,GAAG,CAAC,GAAG,SAAS,CAAC,CA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IAAW;KAN9B,KAAK;KACL,OAAO,EAAE,sBAAsB,GAAG;KAClC,UAAU;KACV,UAAU,aAAa,aAAa,OAAO;IAGb;GAAW;EAC7C;CACF;CAMA,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC,IAAI,yBAAyB,GAAG,WAAW;AAC1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC"}
|
|
@@ -14,6 +14,7 @@ export type ThemePluginOptions = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Vite plugin to configure theme.
|
|
16
16
|
* Returns the official Tailwind Vite plugin (persistent incremental scanner) alongside the theme plugin.
|
|
17
|
+
* Every option has a default, so a consumer of the published package can call `ThemePlugin()`.
|
|
17
18
|
*/
|
|
18
|
-
export declare const ThemePlugin: (options
|
|
19
|
+
export declare const ThemePlugin: (options?: ThemePluginOptions) => Plugin[];
|
|
19
20
|
//# sourceMappingURL=ThemePlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemePlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/ThemePlugin.ts"],"names":[],"mappings":"AAaA,OAAO,EAA0B,KAAK,MAAM,EAAmB,MAAM,MAAM,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,WAAW,YACtB,YAAY,EACZ,OAAO,EACP,WAAW,EACX,aAAa,EACb,MAAM,EACN,SAAS,EACT,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,WAAW,CACH,CAAC;AAmDX,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kHAAkH;IAClH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AA2CF
|
|
1
|
+
{"version":3,"file":"ThemePlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/ThemePlugin.ts"],"names":[],"mappings":"AAaA,OAAO,EAA0B,KAAK,MAAM,EAAmB,MAAM,MAAM,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,WAAW,YACtB,YAAY,EACZ,OAAO,EACP,WAAW,EACX,aAAa,EACb,MAAM,EACN,SAAS,EACT,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,WAAW,CACH,CAAC;AAmDX,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kHAAkH;IAClH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AA2CF;;;;GAIG;AACH,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,MAAM,EAsMpE,CAAC"}
|
|
@@ -9,4 +9,9 @@ export declare const accentTokens: (hue: AccentHue) => Record<string, string>;
|
|
|
9
9
|
* to the stylesheet's default when `hue` is undefined.
|
|
10
10
|
*/
|
|
11
11
|
export declare const applyAccent: (element: HTMLElement, hue: AccentHue | undefined) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the keyboard focus colour for an element's subtree, or clears it back to the stylesheet's default when `hue`
|
|
14
|
+
* is undefined.
|
|
15
|
+
*/
|
|
16
|
+
export declare const applyFocusHue: (element: HTMLElement, hue: AccentHue | undefined) => void;
|
|
12
17
|
//# sourceMappingURL=accent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accent.d.ts","sourceRoot":"","sources":["../../../../src/util/accent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAQ,MAAM,gBAAgB,CAAC;AAE7D,oGAAoG;AACpG,eAAO,MAAM,WAAW,EAAE,SAAS,gBAAgB,EAAS,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEzC,+FAA+F;AAC/F,eAAO,MAAM,YAAY,QAAS,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAMjE,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW,YAAa,WAAW,OAAO,SAAS,GAAG,SAAS,KAAG,IAS9E,CAAC"}
|
|
1
|
+
{"version":3,"file":"accent.d.ts","sourceRoot":"","sources":["../../../../src/util/accent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAQ,MAAM,gBAAgB,CAAC;AAE7D,oGAAoG;AACpG,eAAO,MAAM,WAAW,EAAE,SAAS,gBAAgB,EAAS,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEzC,+FAA+F;AAC/F,eAAO,MAAM,YAAY,QAAS,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAMjE,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW,YAAa,WAAW,OAAO,SAAS,GAAG,SAAS,KAAG,IAS9E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,YAAa,WAAW,OAAO,SAAS,GAAG,SAAS,KAAG,IAMhF,CAAC"}
|