@panneau/ui 5.0.0-alpha.5 → 5.0.0-alpha.7
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/README.md +77 -1
- package/dist/alert/Alert.js +108 -40
- package/dist/alert/Alert.js.map +1 -1
- package/dist/alert/tokens.js.map +1 -1
- package/dist/badge/Badge.js +34 -6
- package/dist/badge/Badge.js.map +1 -1
- package/dist/badge/tokens.js.map +1 -1
- package/dist/button/Button.js +111 -17
- package/dist/button/Button.js.map +1 -1
- package/dist/button/tokens.js.map +1 -1
- package/dist/card/Card.js +76 -23
- package/dist/card/Card.js.map +1 -1
- package/dist/card/tokens.js.map +1 -1
- package/dist/checkbox/Checkbox.js +86 -25
- package/dist/checkbox/Checkbox.js.map +1 -1
- package/dist/checkbox/ChoiceChrome.js +82 -21
- package/dist/checkbox/ChoiceChrome.js.map +1 -1
- package/dist/checkbox/tokens.js.map +1 -1
- package/dist/combo-box/ComboBox.js +291 -79
- package/dist/combo-box/ComboBox.js.map +1 -1
- package/dist/command-palette/CommandPalette.js +463 -160
- package/dist/command-palette/CommandPalette.js.map +1 -1
- package/dist/command-palette/match.js.map +1 -1
- package/dist/command-palette/tokens.js.map +1 -1
- package/dist/command-palette/useCommandShortcut.js +31 -12
- package/dist/command-palette/useCommandShortcut.js.map +1 -1
- package/dist/container/Container.js +48 -5
- package/dist/container/Container.js.map +1 -1
- package/dist/container/tokens.js.map +1 -1
- package/dist/date-picker/DatePicker.js +234 -73
- package/dist/date-picker/DatePicker.js.map +1 -1
- package/dist/date-picker/calendarTokens.js.map +1 -1
- package/dist/dialog/Dialog.js +161 -45
- package/dist/dialog/Dialog.js.map +1 -1
- package/dist/dialog/tokens.js.map +1 -1
- package/dist/disclosure/Disclosure.js +132 -28
- package/dist/disclosure/Disclosure.js.map +1 -1
- package/dist/disclosure/tokens.js.map +1 -1
- package/dist/divider/Divider.js +55 -11
- package/dist/divider/Divider.js.map +1 -1
- package/dist/divider/tokens.js.map +1 -1
- package/dist/field/FieldParts.js +69 -15
- package/dist/field/FieldParts.js.map +1 -1
- package/dist/field/Fieldset.js +99 -32
- package/dist/field/Fieldset.js.map +1 -1
- package/dist/field/inputTokens.js.map +1 -1
- package/dist/field/tokens.js.map +1 -1
- package/dist/grid/Grid.js +123 -14
- package/dist/grid/Grid.js.map +1 -1
- package/dist/grid/tokens.js.map +1 -1
- package/dist/heading/Heading.js +41 -6
- package/dist/heading/Heading.js.map +1 -1
- package/dist/heading/tokens.js.map +1 -1
- package/dist/icon/Icon.js +36 -11
- package/dist/icon/Icon.js.map +1 -1
- package/dist/icon/lucideIconLoader.js.map +1 -1
- package/dist/icon/namedIcons.js +87 -26
- package/dist/icon/namedIcons.js.map +1 -1
- package/dist/icon-button/IconButton.js +70 -13
- package/dist/icon-button/IconButton.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/inline/Inline.js +65 -7
- package/dist/inline/Inline.js.map +1 -1
- package/dist/inline/tokens.js.map +1 -1
- package/dist/intl/usePanneauIntl.js.map +1 -1
- package/dist/layout/responsive.js.map +1 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/menu/Menu.css +84 -0
- package/dist/menu/Menu.d.ts +33 -6
- package/dist/menu/Menu.d.ts.map +1 -1
- package/dist/menu/Menu.js +243 -32
- package/dist/menu/Menu.js.map +1 -1
- package/dist/menu/Menu.module.js +22 -0
- package/dist/menu/Menu.module.js.map +1 -0
- package/dist/menu/tokens.d.ts +3 -0
- package/dist/menu/tokens.d.ts.map +1 -0
- package/dist/menu/tokens.js +31 -0
- package/dist/menu/tokens.js.map +1 -0
- package/dist/number-input/NumberInput.css +18 -0
- package/dist/number-input/NumberInput.js +232 -60
- package/dist/number-input/NumberInput.js.map +1 -1
- package/dist/number-input/NumberInput.module.js +3 -1
- package/dist/number-input/NumberInput.module.js.map +1 -1
- package/dist/number-input/tokens.js.map +1 -1
- package/dist/pill-trigger/PillTrigger.css +104 -0
- package/dist/pill-trigger/PillTrigger.d.ts +20 -0
- package/dist/pill-trigger/PillTrigger.d.ts.map +1 -0
- package/dist/pill-trigger/PillTrigger.js +94 -0
- package/dist/pill-trigger/PillTrigger.js.map +1 -0
- package/dist/pill-trigger/PillTrigger.module.js +18 -0
- package/dist/pill-trigger/PillTrigger.module.js.map +1 -0
- package/dist/pill-trigger/tokens.d.ts +3 -0
- package/dist/pill-trigger/tokens.d.ts.map +1 -0
- package/dist/pill-trigger/tokens.js +37 -0
- package/dist/pill-trigger/tokens.js.map +1 -0
- package/dist/popover/Popover.js +109 -18
- package/dist/popover/Popover.js.map +1 -1
- package/dist/popover/tokens.js.map +1 -1
- package/dist/prose/Prose.js +36 -5
- package/dist/prose/Prose.js.map +1 -1
- package/dist/prose/tokens.js.map +1 -1
- package/dist/radio-group/RadioGroup.css +90 -0
- package/dist/radio-group/RadioGroup.d.ts +22 -3
- package/dist/radio-group/RadioGroup.d.ts.map +1 -1
- package/dist/radio-group/RadioGroup.js +214 -43
- package/dist/radio-group/RadioGroup.js.map +1 -1
- package/dist/radio-group/RadioGroup.module.js +12 -2
- package/dist/radio-group/RadioGroup.module.js.map +1 -1
- package/dist/radio-group/tokens.d.ts +2 -2
- package/dist/radio-group/tokens.d.ts.map +1 -1
- package/dist/radio-group/tokens.js +22 -2
- package/dist/radio-group/tokens.js.map +1 -1
- package/dist/root/PanneauRoot.js +197 -49
- package/dist/root/PanneauRoot.js.map +1 -1
- package/dist/root/ThemeScope.js +107 -26
- package/dist/root/ThemeScope.js.map +1 -1
- package/dist/segmented-control/SegmentedControl.js +120 -22
- package/dist/segmented-control/SegmentedControl.js.map +1 -1
- package/dist/segmented-control/tokens.js.map +1 -1
- package/dist/select/ListBox.css +15 -0
- package/dist/select/ListBox.module.js.map +1 -1
- package/dist/select/Select.js +298 -92
- package/dist/select/Select.js.map +1 -1
- package/dist/select/listBoxTokens.js.map +1 -1
- package/dist/skeleton/LoadingRegion.d.ts +16 -0
- package/dist/skeleton/LoadingRegion.d.ts.map +1 -0
- package/dist/skeleton/LoadingRegion.js +65 -0
- package/dist/skeleton/LoadingRegion.js.map +1 -0
- package/dist/skeleton/Skeleton.css +62 -0
- package/dist/skeleton/Skeleton.d.ts +25 -0
- package/dist/skeleton/Skeleton.d.ts.map +1 -0
- package/dist/skeleton/Skeleton.js +106 -0
- package/dist/skeleton/Skeleton.js.map +1 -0
- package/dist/skeleton/Skeleton.module.js +22 -0
- package/dist/skeleton/Skeleton.module.js.map +1 -0
- package/dist/skeleton/tokens.d.ts +3 -0
- package/dist/skeleton/tokens.d.ts.map +1 -0
- package/dist/skeleton/tokens.js +15 -0
- package/dist/skeleton/tokens.js.map +1 -0
- package/dist/slider/Slider.css +84 -0
- package/dist/slider/Slider.d.ts +20 -0
- package/dist/slider/Slider.d.ts.map +1 -0
- package/dist/slider/Slider.js +248 -0
- package/dist/slider/Slider.js.map +1 -0
- package/dist/slider/Slider.module.js +20 -0
- package/dist/slider/Slider.module.js.map +1 -0
- package/dist/spinner/Spinner.js +49 -9
- package/dist/spinner/Spinner.js.map +1 -1
- package/dist/spinner/tokens.js.map +1 -1
- package/dist/stack/Stack.js +60 -7
- package/dist/stack/Stack.js.map +1 -1
- package/dist/stack/tokens.js.map +1 -1
- package/dist/switch/Switch.js +68 -11
- package/dist/switch/Switch.js.map +1 -1
- package/dist/switch/tokens.js.map +1 -1
- package/dist/tabs/Tabs.js +1 -1
- package/dist/tabs/Tabs.js.map +1 -1
- package/dist/tabs/tokens.js.map +1 -1
- package/dist/tags-input/TagsInput.css +60 -0
- package/dist/tags-input/TagsInput.d.ts +32 -0
- package/dist/tags-input/TagsInput.d.ts.map +1 -0
- package/dist/tags-input/TagsInput.js +316 -0
- package/dist/tags-input/TagsInput.js.map +1 -0
- package/dist/tags-input/TagsInput.module.js +20 -0
- package/dist/tags-input/TagsInput.module.js.map +1 -0
- package/dist/text/Text.js +70 -5
- package/dist/text/Text.js.map +1 -1
- package/dist/text/tokens.js.map +1 -1
- package/dist/text-area/TextArea.js +135 -28
- package/dist/text-area/TextArea.js.map +1 -1
- package/dist/text-input/TextInput.js +164 -49
- package/dist/text-input/TextInput.js.map +1 -1
- package/dist/theme/bootstrap.js.map +1 -1
- package/dist/theme/chartColors.js.map +1 -1
- package/dist/theme/checkTheme.js.map +1 -1
- package/dist/theme/cli.js.map +1 -1
- package/dist/theme/color.js.map +1 -1
- package/dist/theme/colorVision.js.map +1 -1
- package/dist/theme/componentTokens.js.map +1 -1
- package/dist/theme/components.d.ts +4 -1
- package/dist/theme/components.d.ts.map +1 -1
- package/dist/theme/components.js +6 -0
- package/dist/theme/components.js.map +1 -1
- package/dist/theme/defineTheme.js.map +1 -1
- package/dist/theme/fonts.js.map +1 -1
- package/dist/theme/semanticTokens.js.map +1 -1
- package/dist/theme/theme.js.map +1 -1
- package/dist/theme/toneClass.js.map +1 -1
- package/dist/theme/tones.js.map +1 -1
- package/dist/time-input/TimeInput.js +138 -31
- package/dist/time-input/TimeInput.js.map +1 -1
- package/dist/toast/Toast.js +1 -1
- package/dist/toast/Toast.js.map +1 -1
- package/dist/toast/tokens.js.map +1 -1
- package/dist/tooltip/Tooltip.js +38 -8
- package/dist/tooltip/Tooltip.js.map +1 -1
- package/dist/tooltip/tokens.js.map +1 -1
- package/dist/utils/cx.js.map +1 -1
- package/package.json +3 -3
package/dist/theme/color.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","names":[],"sources":["../../src/theme/color.ts"],"sourcesContent":["/** An sRGB color, with channels from 0 to 255. */\nexport interface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nconst HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;\nconst RGB =\n /^rgba?\\(\\s*(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)\\s*(?:[,/]\\s*[\\d.]+%?\\s*)?\\)$/i;\n\n/**\n * Reads a hex (`#05f`, `#0055ff`) or `rgb()` color. Returns `null` for anything else (a CSS\n * variable, a named color, `color-mix()`), which Panneau can't compute with.\n */\nexport function parseColor(value: string): Rgb | null {\n const color = value.trim();\n const hex = HEX.exec(color);\n if (hex?.[1] !== undefined) {\n const digits =\n hex[1].length === 3 ? [...hex[1]].map((digit) => digit + digit).join('') : hex[1];\n return {\n r: Number.parseInt(digits.slice(0, 2), 16),\n g: Number.parseInt(digits.slice(2, 4), 16),\n b: Number.parseInt(digits.slice(4, 6), 16),\n };\n }\n const rgb = RGB.exec(color);\n if (rgb !== null) {\n const [r, g, b] = [rgb[1], rgb[2], rgb[3]].map((channel) =>\n Math.min(255, Math.max(0, Number(channel))),\n );\n return { r: r ?? 0, g: g ?? 0, b: b ?? 0 };\n }\n return null;\n}\n\n/** A color as `#rrggbb`. */\nexport function toHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b]\n .map((channel) => Math.round(channel).toString(16).padStart(2, '0'))\n .join('')}`;\n}\n\n/** Mixes two colors in sRGB, like `color-mix(in srgb, a, b <amount>)`: 0 gives `a`, 1 gives `b`. */\nexport function mixColors(a: Rgb, b: Rgb, amount: number): Rgb {\n return {\n r: a.r + (b.r - a.r) * amount,\n g: a.g + (b.g - a.g) * amount,\n b: a.b + (b.b - a.b) * amount,\n };\n}\n\nfunction linear(channel: number): number {\n const value = channel / 255;\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n}\n\n/** Relative luminance, as defined by WCAG 2. */\nexport function luminance({ r, g, b }: Rgb): number {\n return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** Contrast ratio between two colors, from 1 to 21 (WCAG 2). */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n const [light, dark] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number];\n return (light + 0.05) / (dark + 0.05);\n}\n\nexport const WHITE: Rgb = { r: 255, g: 255, b: 255 };\nexport const BLACK: Rgb = { r: 0, g: 0, b: 0 };\n\n/**\n * The closest color to `color` that reaches `ratio` against `background`, by mixing it with black\n * or white (whichever moves away from the background), like Bootstrap's shade and tint. Returns\n * the color itself when it already passes.\n */\nexport function ensureContrast(color: Rgb, background: Rgb, ratio: number): Rgb {\n if (contrastRatio(color, background) >= ratio) {\n return color;\n }\n const target = luminance(background) > 0.18 ? BLACK : WHITE;\n for (let step = 1; step <= 20; step += 1) {\n const mixed = mixColors(color, target, step / 20);\n if (contrastRatio(mixed, background) >= ratio) {\n return mixed;\n }\n }\n return target;\n}\n\n/** White or black, whichever reads better on `background`, like Bootstrap's `color-contrast()`. */\nexport function readableTextColor(background: Rgb): Rgb {\n return contrastRatio(WHITE, background) >= contrastRatio(BLACK, background) ? WHITE : BLACK;\n}\n"],"mappings":";AAOA,
|
|
1
|
+
{"version":3,"file":"color.js","names":["Rgb","r","g","b","HEX","RGB","parseColor","value","color","trim","hex","exec","undefined","digits","length","map","digit","join","Number","parseInt","slice","rgb","channel","Math","min","max","toHex","round","toString","padStart","mixColors","a","amount","linear","luminance","contrastRatio","light","dark","sort","x","y","WHITE","BLACK","ensureContrast","background","ratio","target","step","mixed","readableTextColor"],"sources":["../../src/theme/color.ts"],"sourcesContent":["/** An sRGB color, with channels from 0 to 255. */\nexport interface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\nconst HEX = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;\nconst RGB =\n /^rgba?\\(\\s*(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)[\\s,]+(\\d+(?:\\.\\d+)?)\\s*(?:[,/]\\s*[\\d.]+%?\\s*)?\\)$/i;\n\n/**\n * Reads a hex (`#05f`, `#0055ff`) or `rgb()` color. Returns `null` for anything else (a CSS\n * variable, a named color, `color-mix()`), which Panneau can't compute with.\n */\nexport function parseColor(value: string): Rgb | null {\n const color = value.trim();\n const hex = HEX.exec(color);\n if (hex?.[1] !== undefined) {\n const digits =\n hex[1].length === 3 ? [...hex[1]].map((digit) => digit + digit).join('') : hex[1];\n return {\n r: Number.parseInt(digits.slice(0, 2), 16),\n g: Number.parseInt(digits.slice(2, 4), 16),\n b: Number.parseInt(digits.slice(4, 6), 16),\n };\n }\n const rgb = RGB.exec(color);\n if (rgb !== null) {\n const [r, g, b] = [rgb[1], rgb[2], rgb[3]].map((channel) =>\n Math.min(255, Math.max(0, Number(channel))),\n );\n return { r: r ?? 0, g: g ?? 0, b: b ?? 0 };\n }\n return null;\n}\n\n/** A color as `#rrggbb`. */\nexport function toHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b]\n .map((channel) => Math.round(channel).toString(16).padStart(2, '0'))\n .join('')}`;\n}\n\n/** Mixes two colors in sRGB, like `color-mix(in srgb, a, b <amount>)`: 0 gives `a`, 1 gives `b`. */\nexport function mixColors(a: Rgb, b: Rgb, amount: number): Rgb {\n return {\n r: a.r + (b.r - a.r) * amount,\n g: a.g + (b.g - a.g) * amount,\n b: a.b + (b.b - a.b) * amount,\n };\n}\n\nfunction linear(channel: number): number {\n const value = channel / 255;\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n}\n\n/** Relative luminance, as defined by WCAG 2. */\nexport function luminance({ r, g, b }: Rgb): number {\n return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);\n}\n\n/** Contrast ratio between two colors, from 1 to 21 (WCAG 2). */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n const [light, dark] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number];\n return (light + 0.05) / (dark + 0.05);\n}\n\nexport const WHITE: Rgb = { r: 255, g: 255, b: 255 };\nexport const BLACK: Rgb = { r: 0, g: 0, b: 0 };\n\n/**\n * The closest color to `color` that reaches `ratio` against `background`, by mixing it with black\n * or white (whichever moves away from the background), like Bootstrap's shade and tint. Returns\n * the color itself when it already passes.\n */\nexport function ensureContrast(color: Rgb, background: Rgb, ratio: number): Rgb {\n if (contrastRatio(color, background) >= ratio) {\n return color;\n }\n const target = luminance(background) > 0.18 ? BLACK : WHITE;\n for (let step = 1; step <= 20; step += 1) {\n const mixed = mixColors(color, target, step / 20);\n if (contrastRatio(mixed, background) >= ratio) {\n return mixed;\n }\n }\n return target;\n}\n\n/** White or black, whichever reads better on `background`, like Bootstrap's `color-contrast()`. */\nexport function readableTextColor(background: Rgb): Rgb {\n return contrastRatio(WHITE, background) >= contrastRatio(BLACK, background) ? WHITE : BLACK;\n}\n"],"mappings":";AAOA,IAAMI,MAAM;AACZ,IAAMC,MACF;;;;;AAMJ,SAAgBC,WAAWC,OAA2B;CAClD,MAAMC,QAAQD,MAAME,KAAK;CACzB,MAAMC,MAAMN,IAAIO,KAAKH,KAAK;CAC1B,IAAIE,MAAM,OAAOE,KAAAA,GAAW;EACxB,MAAMC,SACFH,IAAI,EAAE,CAACI,WAAW,IAAI,CAAC,GAAGJ,IAAI,EAAE,CAAC,CAACK,KAAKC,UAAUA,QAAQA,KAAK,CAAC,CAACC,KAAK,EAAE,IAAIP,IAAI;EACnF,OAAO;GACHT,GAAGiB,OAAOC,SAASN,OAAOO,MAAM,GAAG,CAAC,GAAG,EAAE;GACzClB,GAAGgB,OAAOC,SAASN,OAAOO,MAAM,GAAG,CAAC,GAAG,EAAE;GACzCjB,GAAGe,OAAOC,SAASN,OAAOO,MAAM,GAAG,CAAC,GAAG,EAAE;EAC7C;CACJ;CACA,MAAMC,MAAMhB,IAAIM,KAAKH,KAAK;CAC1B,IAAIa,QAAQ,MAAM;EACd,MAAM,CAACpB,GAAGC,GAAGC,KAAK;GAACkB,IAAI;GAAIA,IAAI;GAAIA,IAAI;EAAE,CAAC,CAACN,KAAKO,YAC5CC,KAAKC,IAAI,KAAKD,KAAKE,IAAI,GAAGP,OAAOI,OAAO,CAAC,CAAC,CAC9C;EACA,OAAO;GAAErB,GAAGA,KAAK;GAAGC,GAAGA,KAAK;GAAGC,GAAGA,KAAK;EAAE;CAC7C;CACA,OAAO;AACX;;AAGA,SAA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SAASZ,UAAUU,UAAU,IAAI,MAAOF,QAAQD;CACtD,KAAK,IAAIM,OAAO,GAAGA,QAAQ,IAAIA,QAAQ,GAAG;EACtC,MAAMC,QAAQlB,UAAUtB,OAAOsC,QAAQC,OAAO,EAAE;EAChD,IAAIZ,cAAca,OAAOJ,UAAU,KAAKC,OACpC,OAAOG;CAEf;CACA,OAAOF;AACX;;AAGA,SAAgBG,kBAAkBL,YAAsB;CACpD,OAAOT,cAAcM,OAAOG,UAAU,KAAKT,cAAcO,OAAOE,UAAU,IAAIH,QAAQC;AAC1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colorVision.js","names":[],"sources":["../../src/theme/colorVision.ts"],"sourcesContent":["import { type Rgb, parseColor } from './color';\n\n/** A color vision deficiency, at full severity: red-blind, green-blind or blue-blind. */\nexport type ColorVisionDeficiency = 'protanopia' | 'deuteranopia' | 'tritanopia';\n\n/** Simulation matrices of Machado, Oliveira and Fernandes (2009), severity 1, on linear RGB. */\nconst MATRICES: Record<ColorVisionDeficiency, readonly (readonly number[])[]> = {\n protanopia: [\n [0.152286, 1.052583, -0.204868],\n [0.114503, 0.786281, 0.099216],\n [-0.003882, -0.048116, 1.051998],\n ],\n deuteranopia: [\n [0.367322, 0.860646, -0.227968],\n [0.280085, 0.672501, 0.047413],\n [-0.01182, 0.04294, 0.968881],\n ],\n tritanopia: [\n [1.255528, -0.076749, -0.178779],\n [-0.078411, 0.930809, 0.147602],\n [0.004733, 0.691367, 0.3039],\n ],\n};\n\nconst toLinear = (channel: number) => {\n const value = channel / 255;\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n};\n\nconst fromLinear = (value: number) => {\n const clamped = Math.min(1, Math.max(0, value));\n return (clamped <= 0.0031308 ? clamped * 12.92 : 1.055 * clamped ** (1 / 2.4) - 0.055) * 255;\n};\n\n/** A color as a person with a color vision deficiency sees it. */\nexport function simulateColorVision(color: Rgb, deficiency: ColorVisionDeficiency): Rgb {\n const linear = [toLinear(color.r), toLinear(color.g), toLinear(color.b)];\n const [r = 0, g = 0, b = 0] = MATRICES[deficiency].map((row) =>\n fromLinear(row.reduce((sum, weight, index) => sum + weight * (linear[index] ?? 0), 0)),\n );\n return { r, g, b };\n}\n\nfunction toLab(color: Rgb): [number, number, number] {\n const [r, g, b] = [toLinear(color.r), toLinear(color.g), toLinear(color.b)];\n const f = (t: number) => (t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116);\n const x = f((0.4124 * r + 0.3576 * g + 0.1805 * b) / 0.95047);\n const y = f(0.2126 * r + 0.7152 * g + 0.0722 * b);\n const z = f((0.0193 * r + 0.1192 * g + 0.9505 * b) / 1.08883);\n return [116 * y - 16, 500 * (x - y), 200 * (y - z)];\n}\n\n/** The perceived difference between two colors: the CIE76 distance in CIELAB. */\nexport function colorDifference(first: Rgb, second: Rgb): number {\n const [l1, a1, b1] = toLab(first);\n const [l2, a2, b2] = toLab(second);\n return Math.hypot(l1 - l2, a1 - a2, b1 - b2);\n}\n\n/** Two colors of a palette that look too alike, for everyone or with a deficiency. */\nexport interface ColorDifferenceCheck {\n vision: 'typical' | ColorVisionDeficiency;\n first: string;\n second: string;\n difference: number;\n minimum: number;\n}\n\n/**\n * Checks that the colors of a palette (the categorical colors of charts) stay distinct, for\n * typical vision and under protanopia, deuteranopia and tritanopia: every pair must differ by at\n * least `minimum` (CIE76, 10 by default, a difference anyone notices side by side). Colors Panneau\n * can't read are skipped. Returns the pairs below the minimum.\n */\nexport function checkColorDifferences(\n colors: readonly string[],\n minimum = 10,\n): ColorDifferenceCheck[] {\n const parsed = colors.flatMap((color) => {\n const rgb = parseColor(color);\n return rgb !== null ? [{ color, rgb }] : [];\n });\n const visions = ['typical', 'protanopia', 'deuteranopia', 'tritanopia'] as const;\n return visions.flatMap((vision) => {\n const seen = parsed.map(({ color, rgb }) => ({\n color,\n rgb: vision === 'typical' ? rgb : simulateColorVision(rgb, vision),\n }));\n return seen.flatMap((first, index) =>\n seen.slice(index + 1).flatMap((second) => {\n const difference = Math.round(colorDifference(first.rgb, second.rgb) * 10) / 10;\n return difference < minimum\n ? [{ vision, first: first.color, second: second.color, difference, minimum }]\n : [];\n }),\n );\n });\n}\n"],"mappings":";;;AAMA,
|
|
1
|
+
{"version":3,"file":"colorVision.js","names":["Rgb","parseColor","ColorVisionDeficiency","MATRICES","Record","protanopia","deuteranopia","tritanopia","toLinear","channel","value","fromLinear","clamped","Math","min","max","simulateColorVision","color","deficiency","linear","r","g","b","map","row","reduce","sum","weight","index","toLab","f","t","cbrt","x","y","z","colorDifference","first","second","l1","a1","b1","l2","a2","b2","hypot","ColorDifferenceCheck","vision","difference","minimum","checkColorDifferences","colors","parsed","flatMap","rgb","visions","const","seen","slice","round"],"sources":["../../src/theme/colorVision.ts"],"sourcesContent":["import { type Rgb, parseColor } from './color';\n\n/** A color vision deficiency, at full severity: red-blind, green-blind or blue-blind. */\nexport type ColorVisionDeficiency = 'protanopia' | 'deuteranopia' | 'tritanopia';\n\n/** Simulation matrices of Machado, Oliveira and Fernandes (2009), severity 1, on linear RGB. */\nconst MATRICES: Record<ColorVisionDeficiency, readonly (readonly number[])[]> = {\n protanopia: [\n [0.152286, 1.052583, -0.204868],\n [0.114503, 0.786281, 0.099216],\n [-0.003882, -0.048116, 1.051998],\n ],\n deuteranopia: [\n [0.367322, 0.860646, -0.227968],\n [0.280085, 0.672501, 0.047413],\n [-0.01182, 0.04294, 0.968881],\n ],\n tritanopia: [\n [1.255528, -0.076749, -0.178779],\n [-0.078411, 0.930809, 0.147602],\n [0.004733, 0.691367, 0.3039],\n ],\n};\n\nconst toLinear = (channel: number) => {\n const value = channel / 255;\n return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;\n};\n\nconst fromLinear = (value: number) => {\n const clamped = Math.min(1, Math.max(0, value));\n return (clamped <= 0.0031308 ? clamped * 12.92 : 1.055 * clamped ** (1 / 2.4) - 0.055) * 255;\n};\n\n/** A color as a person with a color vision deficiency sees it. */\nexport function simulateColorVision(color: Rgb, deficiency: ColorVisionDeficiency): Rgb {\n const linear = [toLinear(color.r), toLinear(color.g), toLinear(color.b)];\n const [r = 0, g = 0, b = 0] = MATRICES[deficiency].map((row) =>\n fromLinear(row.reduce((sum, weight, index) => sum + weight * (linear[index] ?? 0), 0)),\n );\n return { r, g, b };\n}\n\nfunction toLab(color: Rgb): [number, number, number] {\n const [r, g, b] = [toLinear(color.r), toLinear(color.g), toLinear(color.b)];\n const f = (t: number) => (t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116);\n const x = f((0.4124 * r + 0.3576 * g + 0.1805 * b) / 0.95047);\n const y = f(0.2126 * r + 0.7152 * g + 0.0722 * b);\n const z = f((0.0193 * r + 0.1192 * g + 0.9505 * b) / 1.08883);\n return [116 * y - 16, 500 * (x - y), 200 * (y - z)];\n}\n\n/** The perceived difference between two colors: the CIE76 distance in CIELAB. */\nexport function colorDifference(first: Rgb, second: Rgb): number {\n const [l1, a1, b1] = toLab(first);\n const [l2, a2, b2] = toLab(second);\n return Math.hypot(l1 - l2, a1 - a2, b1 - b2);\n}\n\n/** Two colors of a palette that look too alike, for everyone or with a deficiency. */\nexport interface ColorDifferenceCheck {\n vision: 'typical' | ColorVisionDeficiency;\n first: string;\n second: string;\n difference: number;\n minimum: number;\n}\n\n/**\n * Checks that the colors of a palette (the categorical colors of charts) stay distinct, for\n * typical vision and under protanopia, deuteranopia and tritanopia: every pair must differ by at\n * least `minimum` (CIE76, 10 by default, a difference anyone notices side by side). Colors Panneau\n * can't read are skipped. Returns the pairs below the minimum.\n */\nexport function checkColorDifferences(\n colors: readonly string[],\n minimum = 10,\n): ColorDifferenceCheck[] {\n const parsed = colors.flatMap((color) => {\n const rgb = parseColor(color);\n return rgb !== null ? [{ color, rgb }] : [];\n });\n const visions = ['typical', 'protanopia', 'deuteranopia', 'tritanopia'] as const;\n return visions.flatMap((vision) => {\n const seen = parsed.map(({ color, rgb }) => ({\n color,\n rgb: vision === 'typical' ? rgb : simulateColorVision(rgb, vision),\n }));\n return seen.flatMap((first, index) =>\n seen.slice(index + 1).flatMap((second) => {\n const difference = Math.round(colorDifference(first.rgb, second.rgb) * 10) / 10;\n return difference < minimum\n ? [{ vision, first: first.color, second: second.color, difference, minimum }]\n : [];\n }),\n );\n });\n}\n"],"mappings":";;;AAMA,IAAMG,WAA0E;CAC5EE,YAAY;EACR;GAAC;GAAU;GAAU;EAAS;EAC9B;GAAC;GAAU;GAAU;EAAQ;EAC7B;GAAC;GAAW;GAAW;EAAQ;CAAC;CAEpCC,cAAc;EACV;GAAC;GAAU;GAAU;EAAS;EAC9B;GAAC;GAAU;GAAU;EAAQ;EAC7B;GAAC;GAAU;GAAS;EAAQ;CAAC;CAEjCC,YAAY;EACR;GAAC;GAAU;GAAW;EAAS;EAC/B;GAAC;GAAW;GAAU;EAAQ;EAC9B;GAAC;GAAU;GAAU;EAAM;CAAC;AAEpC;AAEA,IAAMC,YAAYC,YAAoB;CAClC,MAAMC,QAAQD,UAAU;CACxB,OAAOC,SAAS,SAAUA,QAAQ,UAAUA,QAAQ,QAAS,UAAU;AAC3E;AAEA,IAAMC,cAAcD,UAAkB;CAClC,MAAME,UAAUC,KAAKC,IAAI,GAAGD,KAAKE,IAAI,GAAGL,KAAK,CAAC;CAC9C,QAAQE,WAAW,WAAYA,UAAU,QAAQ,QAAQA,YAAY,IAAI,OAAO,QAAS;AAC7F;;AAGA,SAAgBI,oBAAoBC,OAAYC,YAAwC;CACpF,MAAMC,SAAS;EAACX,SAASS,MAAMG,CAAC;EAAGZ,SAASS,MAAMI,CAAC;EAAGb,SAASS,MAAMK,CAAC;CAAC;CACvE,MAAM,CAACF,IAAI,GAAGC,IAAI,GAAGC,IAAI,KAAKnB,SAASe,WAAW,CAACK,KAAKC,QACpDb,WAAWa,IAAIC,QAAQC,KAAKC,QAAQC,UAAUF,MAAMC,UAAUR,OAAOS,UAAU,IAAI,CAAC,CAAC,CACzF;CACA,OAAO;E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AShB,OAAOT,UACxB6B,KAAKC,MAAM9B,QAAQ,CAAC,CAAC,CAACyB,SAASf,WAAW;GACtC,MAAMU,aAAanC,KAAK8C,MAAMvB,gBAAgBC,MAAMiB,KAAKhB,OAAOgB,GAAG,IAAI,EAAE,IAAI;GAC7E,OAAON,aAAaC,UACd,CAAC;IAAEF;IAAQV,OAAOA,MAAMpB;IAAOqB,QAAQA,OAAOrB;IAAO+B;IAAYC;GAAQ,CAAC,IAC1E,CAAA;EACV,CAAC,CACL;CACJ,CAAC;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentTokens.js","names":[],"sources":["../../src/theme/componentTokens.ts"],"sourcesContent":["/**\n * The tokens of one component: CSS variables named `--panneau-<component>-<token>`, with their\n * default values (decision 0024).\n */\nexport interface ComponentTokens<Component extends string = string, Name extends string = string> {\n /**\n * The component or the part it styles, as in its `panneau-<component>` class (`button`,\n * `badge`), or a part shared by several components (`input`, `field`, `list-box`, `calendar`).\n */\n readonly component: Component;\n /** Default values, keyed by token name without the leading `--`: `panneau-button-radius`. */\n readonly tokens: Readonly<Record<Name, string>>;\n}\n\n/**\n * Declares the tokens of a component, as `{ <token>: <default> }`. Each token becomes the CSS\n * variable `--panneau-<component>-<token>`.\n *\n * The component's CSS reads every token with its default as the fallback,\n * `var(--panneau-button-radius, var(--panneau-radius-md))`, and never declares it: a value set by a\n * theme, a scope or any ancestor element then reaches the component, and semantic tokens resolve\n * where the component is. A test checks that the CSS and this declaration agree.\n */\nexport function defineComponentTokens<\n const Component extends string,\n const Tokens extends Record<string, string>,\n>(\n component: Component,\n tokens: Tokens,\n): ComponentTokens<Component, `panneau-${Component}-${keyof Tokens & string}`> {\n return {\n component,\n tokens: Object.freeze(\n Object.fromEntries(\n Object.entries(tokens).map(([name, value]) => [\n `panneau-${component}-${name}`,\n value,\n ]),\n ),\n ) as Record<`panneau-${Component}-${keyof Tokens & string}`, string>,\n };\n}\n"],"mappings":";;;;;;;;;;AAuBA,
|
|
1
|
+
{"version":3,"file":"componentTokens.js","names":["ComponentTokens","component","Component","tokens","Readonly","Record","Name","defineComponentTokens","Tokens","Object","freeze","fromEntries","entries","map","name","value"],"sources":["../../src/theme/componentTokens.ts"],"sourcesContent":["/**\n * The tokens of one component: CSS variables named `--panneau-<component>-<token>`, with their\n * default values (decision 0024).\n */\nexport interface ComponentTokens<Component extends string = string, Name extends string = string> {\n /**\n * The component or the part it styles, as in its `panneau-<component>` class (`button`,\n * `badge`), or a part shared by several components (`input`, `field`, `list-box`, `calendar`).\n */\n readonly component: Component;\n /** Default values, keyed by token name without the leading `--`: `panneau-button-radius`. */\n readonly tokens: Readonly<Record<Name, string>>;\n}\n\n/**\n * Declares the tokens of a component, as `{ <token>: <default> }`. Each token becomes the CSS\n * variable `--panneau-<component>-<token>`.\n *\n * The component's CSS reads every token with its default as the fallback,\n * `var(--panneau-button-radius, var(--panneau-radius-md))`, and never declares it: a value set by a\n * theme, a scope or any ancestor element then reaches the component, and semantic tokens resolve\n * where the component is. A test checks that the CSS and this declaration agree.\n */\nexport function defineComponentTokens<\n const Component extends string,\n const Tokens extends Record<string, string>,\n>(\n component: Component,\n tokens: Tokens,\n): ComponentTokens<Component, `panneau-${Component}-${keyof Tokens & string}`> {\n return {\n component,\n tokens: Object.freeze(\n Object.fromEntries(\n Object.entries(tokens).map(([name, value]) => [\n `panneau-${component}-${name}`,\n value,\n ]),\n ),\n ) as Record<`panneau-${Component}-${keyof Tokens & string}`, string>,\n };\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgBO,sBAIZN,WACAE,QAC2E;CAC3E,OAAO;EACHF;EACAE,QAAQM,OAAOC,OACXD,OAAOE,YACHF,OAAOG,QAAQT,MAAM,CAAC,CAACU,KAAK,CAACC,MAAMC,WAAW,CAC1C,WAAWd,UAAS,GAAIa,QACxBC,KAAK,CACR,CACL,CACJ;CACJ;AACJ"}
|
|
@@ -20,11 +20,14 @@ export declare const componentTokens: Readonly<{
|
|
|
20
20
|
inline: Readonly<Record<"panneau-inline-gap", string>>;
|
|
21
21
|
input: Readonly<Record<"panneau-input-radius" | "panneau-input-padding-x" | "panneau-input-border-width" | "panneau-input-bg" | "panneau-input-border-color" | "panneau-input-border-color-hover", string>>;
|
|
22
22
|
'list-box': Readonly<Record<"panneau-list-box-padding" | "panneau-list-box-item-radius" | "panneau-list-box-item-padding-y" | "panneau-list-box-item-padding-y-described" | "panneau-list-box-item-padding-x" | "panneau-list-box-item-bg-hover", string>>;
|
|
23
|
+
menu: Readonly<Record<"panneau-menu-header-font-size" | "panneau-menu-header-font-weight" | "panneau-menu-header-color" | "panneau-menu-header-text-transform" | "panneau-menu-header-letter-spacing" | "panneau-menu-footer-font-size" | "panneau-menu-footer-color" | "panneau-menu-media-size" | "panneau-menu-media-size-described" | "panneau-menu-media-radius" | "panneau-menu-item-bg-selected", string>>;
|
|
23
24
|
'number-input': Readonly<Record<"panneau-number-input-stepper-width", string>>;
|
|
25
|
+
'pill-trigger': Readonly<Record<"panneau-pill-trigger-color" | "panneau-pill-trigger-radius" | "panneau-pill-trigger-gap" | "panneau-pill-trigger-padding-x" | "panneau-pill-trigger-font-size" | "panneau-pill-trigger-font-weight" | "panneau-pill-trigger-padding-x-sm" | "panneau-pill-trigger-font-size-sm" | "panneau-pill-trigger-bg" | "panneau-pill-trigger-border-color" | "panneau-pill-trigger-media-size" | "panneau-pill-trigger-media-radius" | "panneau-pill-trigger-bg-hover" | "panneau-pill-trigger-media-size-sm", string>>;
|
|
24
26
|
popover: Readonly<Record<"panneau-popover-radius" | "panneau-popover-padding" | "panneau-popover-bg" | "panneau-popover-border-color" | "panneau-popover-shadow", string>>;
|
|
25
27
|
prose: Readonly<Record<"panneau-prose-gap" | "panneau-prose-border-color" | "panneau-prose-line-height" | "panneau-prose-heading-gap" | "panneau-prose-list-indent" | "panneau-prose-link-color" | "panneau-prose-code-font-size" | "panneau-prose-code-color" | "panneau-prose-code-bg" | "panneau-prose-code-radius" | "panneau-prose-quote-border-color" | "panneau-prose-quote-color", string>>;
|
|
26
|
-
radio: Readonly<Record<"panneau-radio-size" | "panneau-radio-bg" | "panneau-radio-border-color" | "panneau-radio-checked-color" | "panneau-radio-checked-border-width", string>>;
|
|
28
|
+
radio: Readonly<Record<"panneau-radio-size" | "panneau-radio-bg" | "panneau-radio-border-color" | "panneau-radio-checked-color" | "panneau-radio-media-size" | "panneau-radio-media-radius" | "panneau-radio-checked-border-width" | "panneau-radio-card-gap" | "panneau-radio-card-padding" | "panneau-radio-card-bg" | "panneau-radio-card-border-color" | "panneau-radio-card-border-color-hover" | "panneau-radio-card-border-color-selected" | "panneau-radio-card-radius" | "panneau-radio-card-label-font-weight", string>>;
|
|
27
29
|
'segmented-control': Readonly<Record<"panneau-segmented-control-radius" | "panneau-segmented-control-padding" | "panneau-segmented-control-bg" | "panneau-segmented-control-border-color" | "panneau-segmented-control-segment-padding-x" | "panneau-segmented-control-segment-font-weight" | "panneau-segmented-control-segment-color" | "panneau-segmented-control-segment-color-selected" | "panneau-segmented-control-segment-bg-selected" | "panneau-segmented-control-segment-shadow-selected", string>>;
|
|
30
|
+
skeleton: Readonly<Record<"panneau-skeleton-color" | "panneau-skeleton-radius" | "panneau-skeleton-duration", string>>;
|
|
28
31
|
spinner: Readonly<Record<"panneau-spinner-border-width", string>>;
|
|
29
32
|
stack: Readonly<Record<"panneau-stack-gap", string>>;
|
|
30
33
|
switch: Readonly<Record<"panneau-switch-height" | "panneau-switch-width" | "panneau-switch-radius" | "panneau-switch-checked-bg" | "panneau-switch-track-bg" | "panneau-switch-thumb-size" | "panneau-switch-thumb-bg" | "panneau-switch-checked-thumb-bg", string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/theme/components.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/theme/components.ts"],"names":[],"mappings":"AAiCA;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiC1B,CAAC;AAEH,gFAAgF;AAChF,MAAM,MAAM,kBAAkB,GAAG;KAC5B,SAAS,IAAI,MAAM,OAAO,eAAe,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC,SAAS,CAAC;CACzF,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC"}
|
package/dist/theme/components.js
CHANGED
|
@@ -14,12 +14,15 @@ import { fieldTokens } from "../field/tokens.js";
|
|
|
14
14
|
import { gridTokens } from "../grid/tokens.js";
|
|
15
15
|
import { headingTokens } from "../heading/tokens.js";
|
|
16
16
|
import { inlineTokens } from "../inline/tokens.js";
|
|
17
|
+
import { menuTokens } from "../menu/tokens.js";
|
|
17
18
|
import { numberInputTokens } from "../number-input/tokens.js";
|
|
19
|
+
import { pillTriggerTokens } from "../pill-trigger/tokens.js";
|
|
18
20
|
import { popoverTokens } from "../popover/tokens.js";
|
|
19
21
|
import { proseTokens } from "../prose/tokens.js";
|
|
20
22
|
import { radioTokens } from "../radio-group/tokens.js";
|
|
21
23
|
import { segmentedControlTokens } from "../segmented-control/tokens.js";
|
|
22
24
|
import { listBoxTokens } from "../select/listBoxTokens.js";
|
|
25
|
+
import { skeletonTokens } from "../skeleton/tokens.js";
|
|
23
26
|
import { spinnerTokens } from "../spinner/tokens.js";
|
|
24
27
|
import { stackTokens } from "../stack/tokens.js";
|
|
25
28
|
import { switchTokens } from "../switch/tokens.js";
|
|
@@ -50,11 +53,14 @@ var componentTokens = Object.freeze({
|
|
|
50
53
|
inline: inlineTokens.tokens,
|
|
51
54
|
input: inputTokens.tokens,
|
|
52
55
|
"list-box": listBoxTokens.tokens,
|
|
56
|
+
menu: menuTokens.tokens,
|
|
53
57
|
"number-input": numberInputTokens.tokens,
|
|
58
|
+
"pill-trigger": pillTriggerTokens.tokens,
|
|
54
59
|
popover: popoverTokens.tokens,
|
|
55
60
|
prose: proseTokens.tokens,
|
|
56
61
|
radio: radioTokens.tokens,
|
|
57
62
|
"segmented-control": segmentedControlTokens.tokens,
|
|
63
|
+
skeleton: skeletonTokens.tokens,
|
|
58
64
|
spinner: spinnerTokens.tokens,
|
|
59
65
|
stack: stackTokens.tokens,
|
|
60
66
|
switch: switchTokens.tokens,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","names":[],"sources":["../../src/theme/components.ts"],"sourcesContent":["import { alertTokens } from '../alert/tokens';\nimport { badgeTokens } from '../badge/tokens';\nimport { buttonTokens } from '../button/tokens';\nimport { cardTokens } from '../card/tokens';\nimport { checkboxTokens } from '../checkbox/tokens';\nimport { commandPaletteTokens } from '../command-palette/tokens';\nimport { containerTokens } from '../container/tokens';\nimport { calendarTokens } from '../date-picker/calendarTokens';\nimport { dialogTokens } from '../dialog/tokens';\nimport { disclosureTokens } from '../disclosure/tokens';\nimport { dividerTokens } from '../divider/tokens';\nimport { inputTokens } from '../field/inputTokens';\nimport { fieldTokens } from '../field/tokens';\nimport { gridTokens } from '../grid/tokens';\nimport { headingTokens } from '../heading/tokens';\nimport { inlineTokens } from '../inline/tokens';\nimport { numberInputTokens } from '../number-input/tokens';\nimport { popoverTokens } from '../popover/tokens';\nimport { proseTokens } from '../prose/tokens';\nimport { radioTokens } from '../radio-group/tokens';\nimport { segmentedControlTokens } from '../segmented-control/tokens';\nimport { listBoxTokens } from '../select/listBoxTokens';\nimport { spinnerTokens } from '../spinner/tokens';\nimport { stackTokens } from '../stack/tokens';\nimport { switchTokens } from '../switch/tokens';\nimport { tabsTokens } from '../tabs/tokens';\nimport { textTokens } from '../text/tokens';\nimport { toastTokens } from '../toast/tokens';\nimport { tooltipTokens } from '../tooltip/tokens';\n\n/**\n * The component tokens of `@panneau/ui` and their defaults, by component: what a theme, a scope or\n * a project's CSS can set to restyle one component without touching the others (decision 0024).\n */\nexport const componentTokens = Object.freeze({\n alert: alertTokens.tokens,\n badge: badgeTokens.tokens,\n button: buttonTokens.tokens,\n calendar: calendarTokens.tokens,\n card: cardTokens.tokens,\n checkbox: checkboxTokens.tokens,\n 'command-palette': commandPaletteTokens.tokens,\n container: containerTokens.tokens,\n dialog: dialogTokens.tokens,\n disclosure: disclosureTokens.tokens,\n divider: dividerTokens.tokens,\n field: fieldTokens.tokens,\n grid: gridTokens.tokens,\n heading: headingTokens.tokens,\n inline: inlineTokens.tokens,\n input: inputTokens.tokens,\n 'list-box': listBoxTokens.tokens,\n 'number-input': numberInputTokens.tokens,\n popover: popoverTokens.tokens,\n prose: proseTokens.tokens,\n radio: radioTokens.tokens,\n 'segmented-control': segmentedControlTokens.tokens,\n spinner: spinnerTokens.tokens,\n stack: stackTokens.tokens,\n switch: switchTokens.tokens,\n tabs: tabsTokens.tokens,\n text: textTokens.tokens,\n toast: toastTokens.tokens,\n tooltip: tooltipTokens.tokens,\n});\n\n/** The name of a component token of `@panneau/ui`, without the leading `--`. */\nexport type ComponentTokenName = {\n [Component in keyof typeof componentTokens]: keyof (typeof componentTokens)[Component];\n}[keyof typeof componentTokens];\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"components.js","names":["alertTokens","badgeTokens","buttonTokens","cardTokens","checkboxTokens","commandPaletteTokens","containerTokens","calendarTokens","dialogTokens","disclosureTokens","dividerTokens","inputTokens","fieldTokens","gridTokens","headingTokens","inlineTokens","menuTokens","numberInputTokens","pillTriggerTokens","popoverTokens","proseTokens","radioTokens","segmentedControlTokens","listBoxTokens","skeletonTokens","spinnerTokens","stackTokens","switchTokens","tabsTokens","textTokens","toastTokens","tooltipTokens","componentTokens","Object","freeze","alert","tokens","badge","button","calendar","card","checkbox","container","dialog","disclosure","divider","field","grid","heading","inline","input","menu","popover","prose","radio","skeleton","spinner","stack","switch","tabs","text","toast","tooltip","ComponentTokenName","Component"],"sources":["../../src/theme/components.ts"],"sourcesContent":["import { alertTokens } from '../alert/tokens';\nimport { badgeTokens } from '../badge/tokens';\nimport { buttonTokens } from '../button/tokens';\nimport { cardTokens } from '../card/tokens';\nimport { checkboxTokens } from '../checkbox/tokens';\nimport { commandPaletteTokens } from '../command-palette/tokens';\nimport { containerTokens } from '../container/tokens';\nimport { calendarTokens } from '../date-picker/calendarTokens';\nimport { dialogTokens } from '../dialog/tokens';\nimport { disclosureTokens } from '../disclosure/tokens';\nimport { dividerTokens } from '../divider/tokens';\nimport { inputTokens } from '../field/inputTokens';\nimport { fieldTokens } from '../field/tokens';\nimport { gridTokens } from '../grid/tokens';\nimport { headingTokens } from '../heading/tokens';\nimport { inlineTokens } from '../inline/tokens';\nimport { menuTokens } from '../menu/tokens';\nimport { numberInputTokens } from '../number-input/tokens';\nimport { pillTriggerTokens } from '../pill-trigger/tokens';\nimport { popoverTokens } from '../popover/tokens';\nimport { proseTokens } from '../prose/tokens';\nimport { radioTokens } from '../radio-group/tokens';\nimport { segmentedControlTokens } from '../segmented-control/tokens';\nimport { listBoxTokens } from '../select/listBoxTokens';\nimport { skeletonTokens } from '../skeleton/tokens';\nimport { spinnerTokens } from '../spinner/tokens';\nimport { stackTokens } from '../stack/tokens';\nimport { switchTokens } from '../switch/tokens';\nimport { tabsTokens } from '../tabs/tokens';\nimport { textTokens } from '../text/tokens';\nimport { toastTokens } from '../toast/tokens';\nimport { tooltipTokens } from '../tooltip/tokens';\n\n/**\n * The component tokens of `@panneau/ui` and their defaults, by component: what a theme, a scope or\n * a project's CSS can set to restyle one component without touching the others (decision 0024).\n */\nexport const componentTokens = Object.freeze({\n alert: alertTokens.tokens,\n badge: badgeTokens.tokens,\n button: buttonTokens.tokens,\n calendar: calendarTokens.tokens,\n card: cardTokens.tokens,\n checkbox: checkboxTokens.tokens,\n 'command-palette': commandPaletteTokens.tokens,\n container: containerTokens.tokens,\n dialog: dialogTokens.tokens,\n disclosure: disclosureTokens.tokens,\n divider: dividerTokens.tokens,\n field: fieldTokens.tokens,\n grid: gridTokens.tokens,\n heading: headingTokens.tokens,\n inline: inlineTokens.tokens,\n input: inputTokens.tokens,\n 'list-box': listBoxTokens.tokens,\n menu: menuTokens.tokens,\n 'number-input': numberInputTokens.tokens,\n 'pill-trigger': pillTriggerTokens.tokens,\n popover: popoverTokens.tokens,\n prose: proseTokens.tokens,\n radio: radioTokens.tokens,\n 'segmented-control': segmentedControlTokens.tokens,\n skeleton: skeletonTokens.tokens,\n spinner: spinnerTokens.tokens,\n stack: stackTokens.tokens,\n switch: switchTokens.tokens,\n tabs: tabsTokens.tokens,\n text: textTokens.tokens,\n toast: toastTokens.tokens,\n tooltip: tooltipTokens.tokens,\n});\n\n/** The name of a component token of `@panneau/ui`, without the leading `--`. */\nexport type ComponentTokenName = {\n [Component in keyof typeof componentTokens]: keyof (typeof componentTokens)[Component];\n}[keyof typeof componentTokens];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAagC,kBAAkBC,OAAOC,OAAO;CACzCC,OAAOnC,YAAYoC;CACnBC,OAAOpC,YAAYmC;CACnBE,QAAQpC,aAAakC;CACrBG,UAAUhC,eAAe6B;CACzBI,MAAMrC,WAAWiC;CACjBK,UAAUrC,eAAegC;CACzB,mBAAmB/B,qBAAqB+B;CACxCM,WAAWpC,gBAAgB8B;CAC3BO,QAAQnC,aAAa4B;CACrBQ,YAAYnC,iBAAiB2B;CAC7BS,SAASnC,cAAc0B;CACvBU,OAAOlC,YAAYwB;CACnBW,MAAMlC,WAAWuB;CACjBY,SAASlC,cAAcsB;CACvBa,QAAQlC,aAAaqB;CACrBc,OAAOvC,YAAYyB;CACnB,YAAYb,cAAca;CAC1Be,MAAMnC,WAAWoB;CACjB,gBAAgBnB,kBAAkBmB;CAClC,gBAAgBlB,kBAAkBkB;CAClCgB,SAASjC,cAAciB;CACvBiB,OAAOjC,YAAYgB;CACnBkB,OAAOjC,YAAYe;CACnB,qBAAqBd,uBAAuBc;CAC5CmB,UAAU/B,eAAeY;CACzBoB,SAAS/B,cAAcW;CACvBqB,OAAO/B,YAAYU;CACnBsB,QAAQ/B,aAAaS;CACrBuB,MAAM/B,WAAWQ;CACjBwB,MAAM/B,WAAWO;CACjByB,OAAO/B,YAAYM;CACnB0B,SAAS/B,cAAcK;AAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineTheme.js","names":[],"sources":["../../src/theme/defineTheme.ts"],"sourcesContent":["import { type ComponentTokenName, componentTokens } from './components';\nimport type { ThemeFont } from './fonts';\nimport { SEMANTIC_TOKENS, type SemanticTokenName } from './semanticTokens';\nimport type { Density, Theme } from './theme';\nimport type { ToneInput } from './tones';\n\n/**\n * Tokens that a project adds, such as those of its own components: declare them here so that\n * `defineTheme()` accepts them.\n *\n * ```ts\n * declare module '@panneau/ui' {\n * interface PanneauTokens {\n * 'panneau-map-marker-color': true;\n * }\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extended by projects\nexport interface PanneauTokens {}\n\n/** The variable of a palette color: `panneau-palette-orange`. */\nexport type PaletteTokenName = `panneau-palette-${string}`;\n\n/**\n * The name of a token a theme can set, without the leading `--`: a semantic token, a component\n * token, a palette color, or a token declared in `PanneauTokens`.\n */\nexport type TokenName =\n SemanticTokenName | ComponentTokenName | PaletteTokenName | (keyof PanneauTokens & string);\n\n/** Values of tokens, keyed by their name: only known names type-check. */\nexport type ThemeTokens = {\n [Name in SemanticTokenName | ComponentTokenName | (keyof PanneauTokens & string)]?: string;\n} & { [Name in PaletteTokenName]?: string };\n\n/** A theme as `defineTheme()` takes it: like `Theme`, with typed tokens and `extends`. */\nexport interface ThemeDefinition {\n /** A name for theme pickers. */\n label?: string;\n /** Themes this one builds on, in order: its own values override theirs. */\n extends?: Theme | readonly Theme[];\n /** Tokens of the light scheme, or of both schemes when `dark` does not set them. */\n tokens?: ThemeTokens;\n /** Tokens that change in the dark scheme. */\n dark?: ThemeTokens;\n /** Raw colors, used with `var(--panneau-palette-<name>)`. */\n palette?: Record<string, string>;\n /** Tones added or redefined by the theme. Declare added tones in `PanneauTones`. */\n tones?: Record<string, ToneInput>;\n /** Named variants of components. Declare them in `BadgeVariants` (and the like). */\n components?: Record<string, { variants?: Record<string, ThemeTokens> }>;\n /** Tokens of each density, which change with the density of the root. */\n densities?: Partial<Record<Exclude<Density, 'auto'>, ThemeTokens>>;\n /** Font faces and font stylesheets. */\n fonts?: ThemeFont[];\n}\n\nfunction mergeRecords<T>(\n first: Readonly<Record<string, T>> | undefined,\n second: Readonly<Record<string, T>> | undefined,\n): Record<string, T> | undefined {\n return first === undefined && second === undefined ? undefined : { ...first, ...second };\n}\n\nfunction mergeComponents(\n first: Theme['components'],\n second: Theme['components'],\n): Theme['components'] {\n const components = mergeRecords(first, second);\n if (components === undefined) {\n return undefined;\n }\n return Object.fromEntries(\n Object.keys(components).map((component) => {\n const before = first?.[component];\n const after = second?.[component];\n const variants = mergeRecords(before?.variants, after?.variants);\n return [\n component,\n {\n ...before,\n ...after,\n ...(variants !== undefined && {\n variants: Object.fromEntries(\n Object.keys(variants).map((name) => [\n name,\n { ...before?.variants?.[name], ...after?.variants?.[name] },\n ]),\n ),\n }),\n },\n ];\n }),\n );\n}\n\nconst DENSITIES = ['compact', 'comfortable', 'touch'] as const;\n\nfunction mergeDensities(first: Theme['densities'], second: Theme['densities']): Theme['densities'] {\n if (first === undefined && second === undefined) {\n return undefined;\n }\n const densities = { ...first, ...second };\n DENSITIES.forEach((density) => {\n if (first?.[density] !== undefined && second?.[density] !== undefined) {\n densities[density] = { ...first[density], ...second[density] };\n }\n });\n return densities;\n}\n\nfunction mergeFonts(first: Theme['fonts'], second: Theme['fonts']): Theme['fonts'] {\n if (first === undefined && second === undefined) {\n return undefined;\n }\n const fonts = [...(first ?? []), ...(second ?? [])];\n return fonts.filter(\n (font, index) =>\n fonts.findIndex((other) => JSON.stringify(other) === JSON.stringify(font)) === index,\n );\n}\n\n/**\n * Merges themes, in order: each one overrides the tokens, palette colors, tones and variants of\n * those before it. A token a theme sets in `tokens` but not in `dark` applies to both schemes, so it\n * also replaces the dark value of earlier themes. Variants merge token by token; tones are replaced\n * whole; densities merge token by token; fonts add up. The label is the last one set. Same as `mergeThemes()` of `@panneau/protocol`.\n */\nexport function mergeThemes(...themes: readonly Partial<Theme>[]): Theme {\n return themes.reduce<Theme>(\n (merged, theme) => {\n const tokens = theme.tokens ?? {};\n const dark = mergeRecords(\n merged.dark !== undefined\n ? Object.fromEntries(\n Object.entries(merged.dark).filter(\n ([name]) => !Object.hasOwn(tokens, name),\n ),\n )\n : undefined,\n theme.dark,\n );\n const result: Theme = {\n ...merged,\n ...theme,\n label: theme.label ?? merged.label,\n tokens: { ...merged.tokens, ...tokens },\n dark: dark !== undefined && Object.keys(dark).length > 0 ? dark : undefined,\n palette: mergeRecords(merged.palette, theme.palette),\n tones: mergeRecords(merged.tones, theme.tones),\n components: mergeComponents(merged.components, theme.components),\n densities: mergeDensities(merged.densities, theme.densities),\n fonts: mergeFonts(merged.fonts, theme.fonts),\n };\n return Object.fromEntries(\n Object.entries(result).filter(([, value]) => value !== undefined),\n ) as unknown as Theme;\n },\n { tokens: {} },\n );\n}\n\n/** The first segments of the semantic tokens, and the components: names Panneau owns. */\nconst NAMESPACES = [\n ...new Set([\n ...SEMANTIC_TOKENS.map((name) => name.split('-')[1]),\n ...Object.keys(componentTokens),\n 'tone',\n ]),\n];\n\nconst KNOWN_TOKENS = new Set<string>([\n ...SEMANTIC_TOKENS,\n ...Object.values(componentTokens).flatMap((tokens) => Object.keys(tokens)),\n]);\n\n/**\n * Tokens of a theme (in its tokens, dark tokens, densities and variants) that Panneau doesn't know although they are in its namespaces\n * (`panneau-color-*`, `panneau-button-*`…): most likely typos. Tokens of a project's own components\n * are outside these namespaces, and palette colors are always accepted.\n */\nexport function findUnknownTokens(theme: Theme): string[] {\n const names = [\n ...Object.keys(theme.tokens),\n ...Object.keys(theme.dark ?? {}),\n ...Object.values(theme.densities ?? {}).flatMap((tokens) => Object.keys(tokens)),\n ...Object.values(theme.components ?? {}).flatMap(({ variants = {} }) =>\n Object.values(variants).flatMap((tokens) => Object.keys(tokens)),\n ),\n ];\n return [\n ...new Set(\n names.filter(\n (name) =>\n !KNOWN_TOKENS.has(name) &&\n !name.startsWith('panneau-palette-') &&\n NAMESPACES.some((namespace) => name.startsWith(`panneau-${namespace}-`)),\n ),\n ),\n ];\n}\n\n/**\n * Declares a theme: TypeScript checks the names of its tokens, and `extends` builds it on other\n * themes (`bootstrapTheme`, a shared brand theme), whose values its own override. It returns a\n * plain `Theme`, which `PanneauRoot`, plugins and JSON files all take. Tokens that Panneau doesn't\n * know in its own namespaces, most likely typos, are reported in the console.\n *\n * ```ts\n * const brand = defineTheme({\n * palette: { orange: '#f25c05' },\n * tokens: { 'panneau-color-accent': 'var(--panneau-palette-orange)' },\n * tones: { signal: 'var(--panneau-palette-orange)' },\n * });\n * const compact = defineTheme({ extends: brand, tokens: { 'panneau-control-height': '2rem' } });\n * ```\n */\nexport function defineTheme(definition: ThemeDefinition): Theme {\n const { extends: extended = [], ...own } = definition;\n const bases: readonly Theme[] = Array.isArray(extended) ? extended : [extended as Theme];\n const ownTheme = { ...own, tokens: own.tokens ?? {} } as Theme;\n const theme = mergeThemes(...bases, ownTheme);\n const unknown = findUnknownTokens(ownTheme);\n if (unknown.length > 0) {\n console.warn(\n `[panneau] Unknown tokens in theme${theme.label !== undefined ? ` \"${theme.label}\"` : ''}: ${unknown.join(', ')}.`,\n );\n }\n return theme;\n}\n"],"mappings":";;;AA0DA,SAAS,aACL,OACA,QAC6B;CAC7B,OAAO,UAAU,KAAA,KAAa,WAAW,KAAA,IAAY,KAAA,IAAY;EAAE,GAAG;EAAO,GAAG;CAAO;AAC3F;AAEA,SAAS,gBACL,OACA,QACmB;CACnB,MAAM,aAAa,aAAa,OAAO,MAAM;CAC7C,IAAI,eAAe,KAAA,GACf;CAEJ,OAAO,OAAO,YACV,OAAO,KAAK,UAAU,CAAC,CAAC,KAAK,cAAc;EACvC,MAAM,SAAS,QAAQ;EACvB,MAAM,QAAQ,SAAS;EACvB,MAAM,WAAW,aAAa,QAAQ,UAAU,OAAO,QAAQ;E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AAO,CACH,GAAG,IAAI,IACH,MAAM,QACD,SACG,CAAC,aAAa,IAAI,IAAI,KACtB,CAAC,KAAK,WAAW,kBAAkB,KACnC,WAAW,MAAM,cAAc,KAAK,WAAW,WAAW,UAAS,EAAG,CAAC,CAC/E,CACJ,CAAC;AAET;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAY,YAAoC;CAC5D,MAAM,EAAE,SAAS,WAAW,CAAA,GAAI,GAAG,QAAQ;CAC3C,MAAM,QAA0B,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAiB;CACvF,MAAM,WAAW;EAAE,GAAG;EAAK,QAAQ,IAAI,UAAU,CAAC;CAAE;CACpD,MAAM,QAAQ,YAAY,GAAG,OAAO,QAAQ;CAC5C,MAAM,UAAU,kBAAkB,QAAQ;CAC1C,IAAI,QAAQ,SAAS,GACjB,QAAQ,KACJ,oCAAoC,MAAM,UAAU,KAAA,IAAY,KAAK,MAAM,MAAK,KAAM,GAAE,IAAK,QAAQ,KAAK,IAAI,EAAC,EACnH;CAEJ,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"defineTheme.js","names":["ComponentTokenName","componentTokens","ThemeFont","SEMANTIC_TOKENS","SemanticTokenName","Density","Theme","ToneInput","PanneauTokens","PaletteTokenName","TokenName","ThemeTokens","ThemeDefinition","label","extends","tokens","dark","palette","Record","tones","components","variants","densities","Partial","Exclude","fonts","mergeRecords","first","Readonly","T","second","undefined","mergeComponents","Object","fromEntries","keys","map","component","before","after","name","DENSITIES","const","mergeDensities","forEach","density","mergeFonts","filter","font","index","findIndex","other","JSON","stringify","mergeThemes","themes","reduce","merged","theme","entries","hasOwn","result","length","value","NAMESPACES","Set","split","KNOWN_TOKENS","values","flatMap","findUnknownTokens","names","has","startsWith","some","namespace","defineTheme","definition","extended","own","bases","Array","isArray","ownTheme","unknown","console","warn","join"],"sources":["../../src/theme/defineTheme.ts"],"sourcesContent":["import { type ComponentTokenName, componentTokens } from './components';\nimport type { ThemeFont } from './fonts';\nimport { SEMANTIC_TOKENS, type SemanticTokenName } from './semanticTokens';\nimport type { Density, Theme } from './theme';\nimport type { ToneInput } from './tones';\n\n/**\n * Tokens that a project adds, such as those of its own components: declare them here so that\n * `defineTheme()` accepts them.\n *\n * ```ts\n * declare module '@panneau/ui' {\n * interface PanneauTokens {\n * 'panneau-map-marker-color': true;\n * }\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extended by projects\nexport interface PanneauTokens {}\n\n/** The variable of a palette color: `panneau-palette-orange`. */\nexport type PaletteTokenName = `panneau-palette-${string}`;\n\n/**\n * The name of a token a theme can set, without the leading `--`: a semantic token, a component\n * token, a palette color, or a token declared in `PanneauTokens`.\n */\nexport type TokenName =\n SemanticTokenName | ComponentTokenName | PaletteTokenName | (keyof PanneauTokens & string);\n\n/** Values of tokens, keyed by their name: only known names type-check. */\nexport type ThemeTokens = {\n [Name in SemanticTokenName | ComponentTokenName | (keyof PanneauTokens & string)]?: string;\n} & { [Name in PaletteTokenName]?: string };\n\n/** A theme as `defineTheme()` takes it: like `Theme`, with typed tokens and `extends`. */\nexport interface ThemeDefinition {\n /** A name for theme pickers. */\n label?: string;\n /** Themes this one builds on, in order: its own values override theirs. */\n extends?: Theme | readonly Theme[];\n /** Tokens of the light scheme, or of both schemes when `dark` does not set them. */\n tokens?: ThemeTokens;\n /** Tokens that change in the dark scheme. */\n dark?: ThemeTokens;\n /** Raw colors, used with `var(--panneau-palette-<name>)`. */\n palette?: Record<string, string>;\n /** Tones added or redefined by the theme. Declare added tones in `PanneauTones`. */\n tones?: Record<string, ToneInput>;\n /** Named variants of components. Declare them in `BadgeVariants` (and the like). */\n components?: Record<string, { variants?: Record<string, ThemeTokens> }>;\n /** Tokens of each density, which change with the density of the root. */\n densities?: Partial<Record<Exclude<Density, 'auto'>, ThemeTokens>>;\n /** Font faces and font stylesheets. */\n fonts?: ThemeFont[];\n}\n\nfunction mergeRecords<T>(\n first: Readonly<Record<string, T>> | undefined,\n second: Readonly<Record<string, T>> | undefined,\n): Record<string, T> | undefined {\n return first === undefined && second === undefined ? undefined : { ...first, ...second };\n}\n\nfunction mergeComponents(\n first: Theme['components'],\n second: Theme['components'],\n): Theme['components'] {\n const components = mergeRecords(first, second);\n if (components === undefined) {\n return undefined;\n }\n return Object.fromEntries(\n Object.keys(components).map((component) => {\n const before = first?.[component];\n const after = second?.[component];\n const variants = mergeRecords(before?.variants, after?.variants);\n return [\n component,\n {\n ...before,\n ...after,\n ...(variants !== undefined && {\n variants: Object.fromEntries(\n Object.keys(variants).map((name) => [\n name,\n { ...before?.variants?.[name], ...after?.variants?.[name] },\n ]),\n ),\n }),\n },\n ];\n }),\n );\n}\n\nconst DENSITIES = ['compact', 'comfortable', 'touch'] as const;\n\nfunction mergeDensities(first: Theme['densities'], second: Theme['densities']): Theme['densities'] {\n if (first === undefined && second === undefined) {\n return undefined;\n }\n const densities = { ...first, ...second };\n DENSITIES.forEach((density) => {\n if (first?.[density] !== undefined && second?.[density] !== undefined) {\n densities[density] = { ...first[density], ...second[density] };\n }\n });\n return densities;\n}\n\nfunction mergeFonts(first: Theme['fonts'], second: Theme['fonts']): Theme['fonts'] {\n if (first === undefined && second === undefined) {\n return undefined;\n }\n const fonts = [...(first ?? []), ...(second ?? [])];\n return fonts.filter(\n (font, index) =>\n fonts.findIndex((other) => JSON.stringify(other) === JSON.stringify(font)) === index,\n );\n}\n\n/**\n * Merges themes, in order: each one overrides the tokens, palette colors, tones and variants of\n * those before it. A token a theme sets in `tokens` but not in `dark` applies to both schemes, so it\n * also replaces the dark value of earlier themes. Variants merge token by token; tones are replaced\n * whole; densities merge token by token; fonts add up. The label is the last one set. Same as `mergeThemes()` of `@panneau/protocol`.\n */\nexport function mergeThemes(...themes: readonly Partial<Theme>[]): Theme {\n return themes.reduce<Theme>(\n (merged, theme) => {\n const tokens = theme.tokens ?? {};\n const dark = mergeRecords(\n merged.dark !== undefined\n ? Object.fromEntries(\n Object.entries(merged.dark).filter(\n ([name]) => !Object.hasOwn(tokens, name),\n ),\n )\n : undefined,\n theme.dark,\n );\n const result: Theme = {\n ...merged,\n ...theme,\n label: theme.label ?? merged.label,\n tokens: { ...merged.tokens, ...tokens },\n dark: dark !== undefined && Object.keys(dark).length > 0 ? dark : undefined,\n palette: mergeRecords(merged.palette, theme.palette),\n tones: mergeRecords(merged.tones, theme.tones),\n components: mergeComponents(merged.components, theme.components),\n densities: mergeDensities(merged.densities, theme.densities),\n fonts: mergeFonts(merged.fonts, theme.fonts),\n };\n return Object.fromEntries(\n Object.entries(result).filter(([, value]) => value !== undefined),\n ) as unknown as Theme;\n },\n { tokens: {} },\n );\n}\n\n/** The first segments of the semantic tokens, and the components: names Panneau owns. */\nconst NAMESPACES = [\n ...new Set([\n ...SEMANTIC_TOKENS.map((name) => name.split('-')[1]),\n ...Object.keys(componentTokens),\n 'tone',\n ]),\n];\n\nconst KNOWN_TOKENS = new Set<string>([\n ...SEMANTIC_TOKENS,\n ...Object.values(componentTokens).flatMap((tokens) => Object.keys(tokens)),\n]);\n\n/**\n * Tokens of a theme (in its tokens, dark tokens, densities and variants) that Panneau doesn't know although they are in its namespaces\n * (`panneau-color-*`, `panneau-button-*`…): most likely typos. Tokens of a project's own components\n * are outside these namespaces, and palette colors are always accepted.\n */\nexport function findUnknownTokens(theme: Theme): string[] {\n const names = [\n ...Object.keys(theme.tokens),\n ...Object.keys(theme.dark ?? {}),\n ...Object.values(theme.densities ?? {}).flatMap((tokens) => Object.keys(tokens)),\n ...Object.values(theme.components ?? {}).flatMap(({ variants = {} }) =>\n Object.values(variants).flatMap((tokens) => Object.keys(tokens)),\n ),\n ];\n return [\n ...new Set(\n names.filter(\n (name) =>\n !KNOWN_TOKENS.has(name) &&\n !name.startsWith('panneau-palette-') &&\n NAMESPACES.some((namespace) => name.startsWith(`panneau-${namespace}-`)),\n ),\n ),\n ];\n}\n\n/**\n * Declares a theme: TypeScript checks the names of its tokens, and `extends` builds it on other\n * themes (`bootstrapTheme`, a shared brand theme), whose values its own override. It returns a\n * plain `Theme`, which `PanneauRoot`, plugins and JSON files all take. Tokens that Panneau doesn't\n * know in its own namespaces, most likely typos, are reported in the console.\n *\n * ```ts\n * const brand = defineTheme({\n * palette: { orange: '#f25c05' },\n * tokens: { 'panneau-color-accent': 'var(--panneau-palette-orange)' },\n * tones: { signal: 'var(--panneau-palette-orange)' },\n * });\n * const compact = defineTheme({ extends: brand, tokens: { 'panneau-control-height': '2rem' } });\n * ```\n */\nexport function defineTheme(definition: ThemeDefinition): Theme {\n const { extends: extended = [], ...own } = definition;\n const bases: readonly Theme[] = Array.isArray(extended) ? extended : [extended as Theme];\n const ownTheme = { ...own, tokens: own.tokens ?? {} } as Theme;\n const theme = mergeThemes(...bases, ownTheme);\n const unknown = findUnknownTokens(ownTheme);\n if (unknown.length > 0) {\n console.warn(\n `[panneau] Unknown tokens in theme${theme.label !== undefined ? ` \"${theme.label}\"` : ''}: ${unknown.join(', ')}.`,\n );\n }\n return theme;\n}\n"],"mappings":";;;AA0DA,SAAS0B,aACLC,OACAG,QAC6B;CAC7B,OAAOH,UAAUI,KAAAA,KAAaD,WAAWC,KAAAA,IAAYA,KAAAA,IAAY;EAAE,GAAGJ;EAAO,GAAGG;CAAO;AAC3F;AAEA,SAASE,gBACLL,OACAG,QACmB;CACnB,MAAMV,aAAaM,aAAaC,OAAOG,MAAM;CAC7C,IAAIV,eAAeW,KAAAA,GACf;CAEJ,OAAOE,OAAOC,YACVD,OAAOE,KAAKf,UAAU,CAAC,CAACgB,KAAKC,cAAc;EACvC,MAAMC,SAASX,QAAQU;EACvB,MAAME,QAAQT,SAASO;EACvB,MAAMhB,WAAWK,aAAaY,QAAQjB,UAAUkB,OAAOlB,QAAQ;EAC/D,OAAO,CACHgB,WACA;GACI,GAAGC;GACH,GAAGC;GACH,GAAIlB,aAAaU,KAAAA,KAAa,EAC1BV,UAAUY,OAAOC,YACbD,OAAOE,KAAKd,QAAQ,CAAC,CAACe,KAAKI,SAAS,CAChCA,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AC/E,GAAGkB,OAAOmC,OAAOV,MAAMtC,cAAc,CAAC,CAAC,CAAC,CAACiD,SAAS,EAAEhD,WAAW,CAAC,QAC5DY,OAAOmC,OAAO/C,QAAQ,CAAC,CAACgD,SAAStD,WAAWkB,OAAOE,KAAKpB,MAAM,CAAC,CACnE;CAAC;CAEL,OAAO,CACH,GAAG,IAAIkD,IACHM,MAAMxB,QACDP,SACG,CAAC2B,aAAaK,IAAIhC,IAAI,KACtB,CAACA,KAAKiC,WAAW,kBAAkB,KACnCT,WAAWU,MAAMC,cAAcnC,KAAKiC,WAAW,WAAWE,UAAS,EAAG,CAAC,CAC/E,CACJ,CAAC;AAET;;;;;;;;;;;;;;;;AAiBA,SAAgBC,YAAYC,YAAoC;CAC5D,MAAM,EAAE/D,SAASgE,WAAW,CAAA,GAAI,GAAGC,QAAQF;CAC3C,MAAMG,QAA0BC,MAAMC,QAAQJ,QAAQ,IAAIA,WAAW,CAACA,QAAiB;CACvF,MAAMK,WAAW;EAAE,GAAGJ;EAAKhE,QAAQgE,IAAIhE,UAAU,CAAC;CAAE;CACpD,MAAM2C,QAAQJ,YAAY,GAAG0B,OAAOG,QAAQ;CAC5C,MAAMC,UAAUd,kBAAkBa,QAAQ;CAC1C,IAAIC,QAAQtB,SAAS,GACjBuB,QAAQC,KACJ,oCAAoC5B,MAAM7C,UAAUkB,KAAAA,IAAY,KAAK2B,MAAM7C,MAAK,KAAM,GAAE,IAAKuE,QAAQG,KAAK,IAAI,EAAC,EACnH;CAEJ,OAAO7B;AACX"}
|
package/dist/theme/fonts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fonts.js","names":[],"sources":["../../src/theme/fonts.ts"],"sourcesContent":["/** A font face of a theme, written as an `@font-face` rule. */\nexport type ThemeFontFace = {\n /** The family name that font tokens use: `'Geist'`. */\n family: string;\n /** The `src` descriptor: `url(/fonts/geist.woff2) format('woff2')`. */\n src: string;\n /** A weight or a range of a variable font: `400`, `400 700`. */\n weight?: string;\n /** `normal` or `italic`. */\n style?: string;\n /** Defaults to `swap`. */\n display?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';\n unicodeRange?: string;\n};\n\n/** A hosted stylesheet that declares font faces: Google Fonts, Adobe Fonts, a site's own. */\nexport type ThemeFontStylesheet = {\n stylesheet: string;\n};\n\n/**\n * A font of a theme: a face, or a stylesheet that declares faces. `PanneauRoot` adds them to the\n * page once, however many roots use the theme. Font faces are global by nature, unlike tokens.\n */\nexport type ThemeFont = ThemeFontFace | ThemeFontStylesheet;\n\n/** Values that could break out of an `@font-face` rule, or out of the family name. */\nconst UNSAFE = /[{}<]/;\nconst UNSAFE_FAMILY = /[{}<;\"\\\\]/;\nconst UNSAFE_DESCRIPTOR = /[{}<;]/;\n\nfunction isFace(font: ThemeFont): font is ThemeFontFace {\n return 'family' in font && 'src' in font;\n}\n\n/**\n * The `@font-face` rules of the fonts of a theme. Faces with a value that could break out of the\n * rule are ignored: `{`, `}` or `<` anywhere, `;` outside of `src` (which can hold data URLs), and\n * quotes or backslashes in the family.\n */\nexport function getFontFaceCss(fonts: readonly ThemeFont[] = []): string {\n return fonts\n .filter(isFace)\n .filter(\n (face) =>\n !UNSAFE_FAMILY.test(face.family) &&\n !UNSAFE.test(face.src) &&\n [face.weight, face.style, face.display, face.unicodeRange].every(\n (value) => value === undefined || !UNSAFE_DESCRIPTOR.test(value),\n ),\n )\n .map((face) =>\n [\n `@font-face{font-family:\"${face.family}\";src:${face.src};`,\n face.weight !== undefined ? `font-weight:${face.weight};` : '',\n face.style !== undefined ? `font-style:${face.style};` : '',\n `font-display:${face.display ?? 'swap'};`,\n face.unicodeRange !== undefined ? `unicode-range:${face.unicodeRange};` : '',\n '}',\n ].join(''),\n )\n .join('');\n}\n\n/** The URLs of the font stylesheets of a theme, without duplicates. */\nexport function getFontStylesheets(fonts: readonly ThemeFont[] = []): string[] {\n return [\n ...new Set(\n fonts.flatMap((font) =>\n 'stylesheet' in font && typeof font.stylesheet === 'string'\n ? [font.stylesheet]\n : [],\n ),\n ),\n ];\n}\n"],"mappings":";;AA2BA,
|
|
1
|
+
{"version":3,"file":"fonts.js","names":["ThemeFontFace","family","src","weight","style","display","unicodeRange","ThemeFontStylesheet","stylesheet","ThemeFont","UNSAFE","UNSAFE_FAMILY","UNSAFE_DESCRIPTOR","isFace","font","getFontFaceCss","fonts","filter","face","test","every","value","undefined","map","join","getFontStylesheets","Set","flatMap"],"sources":["../../src/theme/fonts.ts"],"sourcesContent":["/** A font face of a theme, written as an `@font-face` rule. */\nexport type ThemeFontFace = {\n /** The family name that font tokens use: `'Geist'`. */\n family: string;\n /** The `src` descriptor: `url(/fonts/geist.woff2) format('woff2')`. */\n src: string;\n /** A weight or a range of a variable font: `400`, `400 700`. */\n weight?: string;\n /** `normal` or `italic`. */\n style?: string;\n /** Defaults to `swap`. */\n display?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';\n unicodeRange?: string;\n};\n\n/** A hosted stylesheet that declares font faces: Google Fonts, Adobe Fonts, a site's own. */\nexport type ThemeFontStylesheet = {\n stylesheet: string;\n};\n\n/**\n * A font of a theme: a face, or a stylesheet that declares faces. `PanneauRoot` adds them to the\n * page once, however many roots use the theme. Font faces are global by nature, unlike tokens.\n */\nexport type ThemeFont = ThemeFontFace | ThemeFontStylesheet;\n\n/** Values that could break out of an `@font-face` rule, or out of the family name. */\nconst UNSAFE = /[{}<]/;\nconst UNSAFE_FAMILY = /[{}<;\"\\\\]/;\nconst UNSAFE_DESCRIPTOR = /[{}<;]/;\n\nfunction isFace(font: ThemeFont): font is ThemeFontFace {\n return 'family' in font && 'src' in font;\n}\n\n/**\n * The `@font-face` rules of the fonts of a theme. Faces with a value that could break out of the\n * rule are ignored: `{`, `}` or `<` anywhere, `;` outside of `src` (which can hold data URLs), and\n * quotes or backslashes in the family.\n */\nexport function getFontFaceCss(fonts: readonly ThemeFont[] = []): string {\n return fonts\n .filter(isFace)\n .filter(\n (face) =>\n !UNSAFE_FAMILY.test(face.family) &&\n !UNSAFE.test(face.src) &&\n [face.weight, face.style, face.display, face.unicodeRange].every(\n (value) => value === undefined || !UNSAFE_DESCRIPTOR.test(value),\n ),\n )\n .map((face) =>\n [\n `@font-face{font-family:\"${face.family}\";src:${face.src};`,\n face.weight !== undefined ? `font-weight:${face.weight};` : '',\n face.style !== undefined ? `font-style:${face.style};` : '',\n `font-display:${face.display ?? 'swap'};`,\n face.unicodeRange !== undefined ? `unicode-range:${face.unicodeRange};` : '',\n '}',\n ].join(''),\n )\n .join('');\n}\n\n/** The URLs of the font stylesheets of a theme, without duplicates. */\nexport function getFontStylesheets(fonts: readonly ThemeFont[] = []): string[] {\n return [\n ...new Set(\n fonts.flatMap((font) =>\n 'stylesheet' in font && typeof font.stylesheet === 'string'\n ? [font.stylesheet]\n : [],\n ),\n ),\n ];\n}\n"],"mappings":";;AA2BA,IAAMU,SAAS;AACf,IAAMC,gBAAgB;AACtB,IAAMC,oBAAoB;AAE1B,SAASC,OAAOC,MAAwC;CACpD,OAAO,YAAYA,QAAQ,SAASA;AACxC;;;;;;AAOA,SAAgBC,eAAeC,QAA8B,CAAA,GAAY;CACrE,OAAOA,MACFC,OAAOJ,MAAM,CAAC,CACdI,QACIC,SACG,CAACP,cAAcQ,KAAKD,KAAKjB,MAAM,KAC/B,CAACS,OAAOS,KAAKD,KAAKhB,GAAG,KACrB;EAACgB,KAAKf;EAAQe,KAAKd;EAAOc,KAAKb;EAASa,KAAKZ;CAAY,CAAC,CAACc,OACtDC,UAAUA,UAAUC,KAAAA,KAAa,CAACV,kBAAkBO,KAAKE,KAAK,CACnE,CACR,CAAC,CACAE,KAAKL,SACF;EACI,2BAA2BA,KAAKjB,OAAM,QAASiB,KAAKhB,IAAG;EACvDgB,KAAKf,WAAWmB,KAAAA,IAAY,eAAeJ,KAAKf,OAAM,KAAM;EAC5De,KAAKd,UAAUkB,KAAAA,IAAY,cAAcJ,KAAKd,MAAK,KAAM;EACzD,gBAAgBc,KAAKb,WAAW,OAAM;EACtCa,KAAKZ,iBAAiBgB,KAAAA,IAAY,iBAAiBJ,KAAKZ,aAAY,KAAM;EAC1E;CAAG,CACN,CAACkB,KAAK,EAAE,CACb,CAAC,CACAA,KAAK,EAAE;AAChB;;AAGA,SAAgBC,mBAAmBT,QAA8B,CAAA,GAAc;CAC3E,OAAO,CACH,GAAG,IAAIU,IACHV,MAAMW,SAASb,SACX,gBAAgBA,QAAQ,OAAOA,KAAKN,eAAe,WAC7C,CAACM,KAAKN,UAAU,IAChB,CAAA,CACV,CACJ,CAAC;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticTokens.js","names":[],"sources":["../../src/theme/semanticTokens.ts"],"sourcesContent":["/**\n * The semantic tokens of Panneau, without the leading `--`: what the default theme defines on the\n * root (`PanneauRoot.module.css`), and what a theme sets to restyle every component at once\n * (decision 0024). A test keeps this list in sync with the stylesheet.\n */\nexport const SEMANTIC_TOKENS = [\n 'panneau-color-bg',\n 'panneau-color-surface',\n 'panneau-color-surface-sunken',\n 'panneau-color-surface-raised',\n 'panneau-color-hover',\n 'panneau-color-pressed',\n 'panneau-color-backdrop',\n 'panneau-color-text',\n 'panneau-color-text-muted',\n 'panneau-color-link',\n 'panneau-color-border',\n 'panneau-color-border-control',\n 'panneau-color-accent',\n 'panneau-color-accent-hover',\n 'panneau-color-accent-text',\n 'panneau-color-accent-subtle',\n 'panneau-color-focus',\n 'panneau-color-danger',\n 'panneau-color-danger-subtle',\n 'panneau-color-danger-border',\n 'panneau-color-danger-solid',\n 'panneau-color-danger-solid-hover',\n 'panneau-color-danger-solid-text',\n 'panneau-color-success',\n 'panneau-color-success-subtle',\n 'panneau-color-success-border',\n 'panneau-color-success-solid',\n 'panneau-color-success-solid-hover',\n 'panneau-color-success-solid-text',\n 'panneau-color-warning',\n 'panneau-color-warning-subtle',\n 'panneau-color-warning-border',\n 'panneau-color-warning-solid',\n 'panneau-color-warning-solid-hover',\n 'panneau-color-warning-solid-text',\n 'panneau-color-info',\n 'panneau-color-info-subtle',\n 'panneau-color-info-border',\n 'panneau-color-info-solid',\n 'panneau-color-info-solid-hover',\n 'panneau-color-info-solid-text',\n 'panneau-chart-categorical-1',\n 'panneau-chart-categorical-2',\n 'panneau-chart-categorical-3',\n 'panneau-chart-categorical-4',\n 'panneau-chart-categorical-5',\n 'panneau-chart-categorical-6',\n 'panneau-chart-categorical-7',\n 'panneau-chart-categorical-8',\n 'panneau-chart-sequential-1',\n 'panneau-chart-sequential-2',\n 'panneau-chart-sequential-3',\n 'panneau-chart-sequential-4',\n 'panneau-chart-sequential-5',\n 'panneau-chart-diverging-negative',\n 'panneau-chart-diverging-neutral',\n 'panneau-chart-diverging-positive',\n 'panneau-font-family-body',\n 'panneau-font-family-heading',\n 'panneau-font-family-display',\n 'panneau-font-family-mono',\n 'panneau-font-family',\n 'panneau-font-numeric',\n 'panneau-font-size-xs',\n 'panneau-font-size-sm',\n 'panneau-font-size-md',\n 'panneau-font-size-lg',\n 'panneau-font-size-xl',\n 'panneau-font-size-control',\n 'panneau-line-height',\n 'panneau-line-height-tight',\n 'panneau-font-weight-normal',\n 'panneau-font-weight-medium',\n 'panneau-font-weight-bold',\n 'panneau-space-1',\n 'panneau-space-2',\n 'panneau-space-3',\n 'panneau-space-4',\n 'panneau-space-5',\n 'panneau-space-6',\n 'panneau-space-8',\n 'panneau-space-10',\n 'panneau-radius-sm',\n 'panneau-radius-md',\n 'panneau-radius-lg',\n 'panneau-radius-full',\n 'panneau-border-width',\n 'panneau-shadow-sm',\n 'panneau-shadow-md',\n 'panneau-shadow-lg',\n 'panneau-control-height',\n 'panneau-control-height-sm',\n 'panneau-control-padding-x',\n 'panneau-row-padding-y',\n 'panneau-focus-width',\n 'panneau-duration',\n 'panneau-z-overlay',\n 'panneau-z-toast',\n] as const;\n\n/** The name of a semantic token, without the leading `--`. */\nexport type SemanticTokenName = (typeof SEMANTIC_TOKENS)[number];\n"],"mappings":";;;;;;AAKA,
|
|
1
|
+
{"version":3,"file":"semanticTokens.js","names":["SEMANTIC_TOKENS","const","SemanticTokenName"],"sources":["../../src/theme/semanticTokens.ts"],"sourcesContent":["/**\n * The semantic tokens of Panneau, without the leading `--`: what the default theme defines on the\n * root (`PanneauRoot.module.css`), and what a theme sets to restyle every component at once\n * (decision 0024). A test keeps this list in sync with the stylesheet.\n */\nexport const SEMANTIC_TOKENS = [\n 'panneau-color-bg',\n 'panneau-color-surface',\n 'panneau-color-surface-sunken',\n 'panneau-color-surface-raised',\n 'panneau-color-hover',\n 'panneau-color-pressed',\n 'panneau-color-backdrop',\n 'panneau-color-text',\n 'panneau-color-text-muted',\n 'panneau-color-link',\n 'panneau-color-border',\n 'panneau-color-border-control',\n 'panneau-color-accent',\n 'panneau-color-accent-hover',\n 'panneau-color-accent-text',\n 'panneau-color-accent-subtle',\n 'panneau-color-focus',\n 'panneau-color-danger',\n 'panneau-color-danger-subtle',\n 'panneau-color-danger-border',\n 'panneau-color-danger-solid',\n 'panneau-color-danger-solid-hover',\n 'panneau-color-danger-solid-text',\n 'panneau-color-success',\n 'panneau-color-success-subtle',\n 'panneau-color-success-border',\n 'panneau-color-success-solid',\n 'panneau-color-success-solid-hover',\n 'panneau-color-success-solid-text',\n 'panneau-color-warning',\n 'panneau-color-warning-subtle',\n 'panneau-color-warning-border',\n 'panneau-color-warning-solid',\n 'panneau-color-warning-solid-hover',\n 'panneau-color-warning-solid-text',\n 'panneau-color-info',\n 'panneau-color-info-subtle',\n 'panneau-color-info-border',\n 'panneau-color-info-solid',\n 'panneau-color-info-solid-hover',\n 'panneau-color-info-solid-text',\n 'panneau-chart-categorical-1',\n 'panneau-chart-categorical-2',\n 'panneau-chart-categorical-3',\n 'panneau-chart-categorical-4',\n 'panneau-chart-categorical-5',\n 'panneau-chart-categorical-6',\n 'panneau-chart-categorical-7',\n 'panneau-chart-categorical-8',\n 'panneau-chart-sequential-1',\n 'panneau-chart-sequential-2',\n 'panneau-chart-sequential-3',\n 'panneau-chart-sequential-4',\n 'panneau-chart-sequential-5',\n 'panneau-chart-diverging-negative',\n 'panneau-chart-diverging-neutral',\n 'panneau-chart-diverging-positive',\n 'panneau-font-family-body',\n 'panneau-font-family-heading',\n 'panneau-font-family-display',\n 'panneau-font-family-mono',\n 'panneau-font-family',\n 'panneau-font-numeric',\n 'panneau-font-size-xs',\n 'panneau-font-size-sm',\n 'panneau-font-size-md',\n 'panneau-font-size-lg',\n 'panneau-font-size-xl',\n 'panneau-font-size-control',\n 'panneau-line-height',\n 'panneau-line-height-tight',\n 'panneau-font-weight-normal',\n 'panneau-font-weight-medium',\n 'panneau-font-weight-bold',\n 'panneau-space-1',\n 'panneau-space-2',\n 'panneau-space-3',\n 'panneau-space-4',\n 'panneau-space-5',\n 'panneau-space-6',\n 'panneau-space-8',\n 'panneau-space-10',\n 'panneau-radius-sm',\n 'panneau-radius-md',\n 'panneau-radius-lg',\n 'panneau-radius-full',\n 'panneau-border-width',\n 'panneau-shadow-sm',\n 'panneau-shadow-md',\n 'panneau-shadow-lg',\n 'panneau-control-height',\n 'panneau-control-height-sm',\n 'panneau-control-padding-x',\n 'panneau-row-padding-y',\n 'panneau-focus-width',\n 'panneau-duration',\n 'panneau-z-overlay',\n 'panneau-z-toast',\n] as const;\n\n/** The name of a semantic token, without the leading `--`. */\nexport type SemanticTokenName = (typeof SEMANTIC_TOKENS)[number];\n"],"mappings":";;;;;;AAKA,IAAaA,kBAAkB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAiB"}
|
package/dist/theme/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":[],"sources":["../../src/theme/theme.ts"],"sourcesContent":["import { parseColor } from './color';\nimport type { ThemeFont } from './fonts';\nimport {\n TONE_VARIABLES,\n type ToneInput,\n type ToneSurfaces,\n type ToneValues,\n resolveTone,\n toneClassName,\n} from './tones';\n\n/**\n * A theme: design tokens, as CSS variables without the leading `--`, with optional overrides for\n * the dark scheme, raw palette colors, its own tones, and named variants of components (decision\n * 0024). A theme is plain data: the `Theme` schema of `@panneau/protocol` validates it, and plugins\n * of `@panneau/core` register it. Write one with `defineTheme()` to check token names.\n *\n * It is a type rather than an interface so that it is assignable to the `Theme` of\n * `@panneau/protocol`, which accepts properties of later versions.\n */\nexport type Theme = {\n /** A name for theme pickers. */\n label?: string;\n /** Tokens of the light scheme, or of both schemes without `dark`: `{ 'panneau-color-accent': '#05f' }`. */\n tokens: Record<string, string>;\n /** Tokens that change in the dark scheme. */\n dark?: Record<string, string>;\n /**\n * Raw colors, written as `--panneau-palette-<name>`: tokens and tones use them with\n * `var(--panneau-palette-<name>)`, so that a theme names its brand colors once.\n */\n palette?: Record<string, string>;\n /**\n * Tones added or redefined by the theme: one color, from which Panneau derives the others,\n * or every value. Declare added tones in `PanneauTones` so that `tone=\"signal\"` type-checks.\n */\n tones?: Record<string, ToneInput>;\n /**\n * Named variants of components: token overrides that `<Badge variant=\"tag\">` applies through\n * its `panneau-badge-variant-tag` class. Declare them in `BadgeVariants` (and the like).\n */\n components?: Record<string, { variants?: Record<string, Record<string, string>> }>;\n /**\n * Tokens of each density, such as `panneau-control-height`: tokens set here change with the\n * density of the root, while the same tokens in `tokens` would apply to every density.\n */\n densities?: Partial<Record<Exclude<Density, 'auto'>, Record<string, string>>>;\n /**\n * Font faces and font stylesheets, which `PanneauRoot` adds to the page once. Font tokens\n * (`panneau-font-family-heading`) then use their families.\n */\n fonts?: ThemeFont[];\n};\n\n/** `auto` follows the system setting (`prefers-color-scheme`). */\nexport type ColorScheme = 'light' | 'dark' | 'auto';\n\n/**\n * How much room controls and rows take: `compact`, `comfortable`, or `touch`, with larger targets.\n * `auto` is `touch` on coarse pointers (touch screens) and `comfortable` otherwise.\n */\nexport type Density = 'compact' | 'comfortable' | 'touch' | 'auto';\n\nfunction declarations(tokens: Record<string, string>): string {\n return Object.entries(tokens)\n .filter(([name, value]) => /^[a-zA-Z0-9-_]+$/.test(name) && !/[{};<]/.test(value))\n .map(([name, value]) => `--${name}:${value};`)\n .join('');\n}\n\n/** A short, stable hash of a string, to scope the CSS of a theme. */\nexport function hashString(value: string): string {\n let hash = 5381;\n for (let index = 0; index < value.length; index += 1) {\n hash = (hash * 33) ^ value.charCodeAt(index);\n }\n return (hash >>> 0).toString(36);\n}\n\nconst NAME = /^[a-z0-9-]+$/;\n\nconst VARIABLE = /^var\\(--([a-zA-Z0-9_-]+)\\)$/;\n\n/** The palette of a theme, as variables: `{ 'panneau-palette-orange': '#f25c05' }`. */\nexport function paletteVariables(\n palette: Readonly<Record<string, string>> = {},\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(palette)\n .filter(([name]) => NAME.test(name))\n .map(([name, value]) => [`panneau-palette-${name}`, value]),\n );\n}\n\n/**\n * Follows `var(--name)` references through the given variables (tokens, palette colors), until a\n * value that is not one: `var(--panneau-palette-orange)` becomes `#f25c05`. A reference to a\n * variable that isn't given is returned as is.\n */\nexport function resolveReference(\n value: string,\n variables: Readonly<Record<string, string>>,\n): string {\n let current = value;\n for (let depth = 0; depth < 10; depth += 1) {\n const name = VARIABLE.exec(current.trim())?.[1];\n if (name === undefined || !Object.hasOwn(variables, name)) {\n return current;\n }\n current = variables[name] ?? current;\n }\n return current;\n}\n\nfunction toneDeclarations(values: ToneValues): string {\n return declarations(\n Object.fromEntries(\n (Object.keys(TONE_VARIABLES) as (keyof ToneValues)[]).map((key) => [\n TONE_VARIABLES[key],\n values[key],\n ]),\n ),\n );\n}\n\n/**\n * The surfaces of a theme in each scheme, when it sets ones Panneau can read: tones derived from\n * one color are made readable on them.\n */\nexport function themeSurfaces(theme: Theme): ToneSurfaces {\n const palette = paletteVariables(theme.palette);\n const surface = (tokens: Record<string, string>) => {\n const variables = { ...palette, ...tokens };\n const value = variables['panneau-color-surface'];\n return value !== undefined ? parseColor(resolveReference(value, variables)) : null;\n };\n const light = surface(theme.tokens);\n const dark =\n theme.dark?.['panneau-color-surface'] !== undefined\n ? surface({ ...theme.tokens, ...theme.dark })\n : null;\n return {\n ...(light !== null && { light }),\n ...(dark !== null && { dark }),\n };\n}\n\n/**\n * The rules of the densities of a theme. `auto` takes the comfortable values on fine pointers and\n * the touch ones on coarse pointers, like the default theme.\n */\nfunction densityCss(root: string, densities: Theme['densities'] = {}): string {\n const body = (density: Exclude<Density, 'auto'>) => declarations(densities[density] ?? {});\n const rule = (selector: string, css: string) => (css !== '' ? `${selector}{${css}}` : '');\n const media = (query: string, css: string) => (css !== '' ? `@media ${query}{${css}}` : '');\n const selector = (density: Density) => `${root}[data-density=\"${density}\"]`;\n return [\n rule(selector('compact'), body('compact')),\n rule(selector('comfortable'), body('comfortable')),\n media('not (pointer: coarse)', rule(selector('auto'), body('comfortable'))),\n rule(selector('touch'), body('touch')),\n media('(pointer: coarse)', rule(selector('auto'), body('touch'))),\n ].join('');\n}\n\n/**\n * The CSS of a theme, scoped to the roots that carry `data-panneau-theme=\"<scope>\"`: its palette and\n * tokens, its densities, its tones and the variants of components. Its rules are more specific than the default\n * tokens and the built-in tones, and dark overrides more specific than light ones. Token, tone,\n * component and variant names must be plain identifiers, and values can't contain `{`, `}`, `;` or\n * `<`: other entries are ignored.\n */\nexport function getThemeCss(theme: Theme, scope: string): string {\n const root = `[data-panneau-theme=\"${scope}\"]`;\n const dark = `${root}[data-color-scheme=\"dark\"]`;\n const auto = `${root}[data-color-scheme=\"auto\"]`;\n const light: string[] = [];\n const darkRules: string[] = [];\n const rule = (selector: string, body: string) => (body !== '' ? `${selector}{${body}}` : '');\n\n const palette = paletteVariables(theme.palette);\n const surfaces = themeSurfaces(theme);\n light.push(rule(root, declarations({ ...palette, ...theme.tokens })));\n light.push(densityCss(root, theme.densities));\n if (theme.dark !== undefined) {\n darkRules.push(rule('§', declarations(theme.dark)));\n }\n Object.entries(theme.tones ?? {})\n .filter(([name]) => NAME.test(name))\n .forEach(([name, input]) => {\n // A tone from a palette color derives from the color itself.\n const values = resolveTone(\n typeof input === 'string' ? resolveReference(input, palette) : input,\n surfaces,\n );\n const selector = `.${toneClassName(name)}`;\n light.push(rule(`${root} ${selector}`, toneDeclarations(values.light)));\n darkRules.push(rule(`§ ${selector}`, toneDeclarations(values.dark)));\n });\n Object.entries(theme.components ?? {})\n .filter(([component]) => NAME.test(component))\n .forEach(([component, { variants = {} }]) => {\n Object.entries(variants)\n .filter(([name]) => NAME.test(name))\n .forEach(([name, tokens]) => {\n light.push(\n rule(`${root} .panneau-${component}-variant-${name}`, declarations(tokens)),\n );\n });\n });\n\n const darkCss = darkRules.filter(Boolean);\n return [\n ...light,\n ...darkCss.map((css) => css.replaceAll('§', dark)),\n darkCss.length > 0\n ? `@media (prefers-color-scheme: dark){${darkCss.map((css) => css.replaceAll('§', auto)).join('')}}`\n : '',\n ].join('');\n}\n"],"mappings":";;;AA+DA,SAAS,aAAa,QAAwC;CAC1D,OAAO,OAAO,QAAQ,MAAM,CAAC,CACxB,QAAQ,CAAC,MAAM,WAAW,mBAAmB,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CACjF,KAAK,CAAC,MAAM,WAAW,KAAK,KAAI,GAAI,MAAK,EAAG,CAAC,CAC7C,KAAK,EAAE;AAChB;;AAGA,SAAgB,WAAW,OAAuB;CAC9C,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAA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okens","Record","dark","palette","tones","components","variants","densities","Partial","Exclude","Density","fonts","ColorScheme","declarations","Object","entries","filter","name","value","test","map","join","hashString","hash","index","length","charCodeAt","toString","NAME","VARIABLE","paletteVariables","Readonly","fromEntries","resolveReference","variables","current","depth","exec","trim","undefined","hasOwn","toneDeclarations","values","keys","key","themeSurfaces","theme","surface","light","densityCss","root","body","density","rule","selector","css","media","query","getThemeCss","scope","auto","darkRules","surfaces","push","forEach","input","component","darkCss","Boolean","replaceAll"],"sources":["../../src/theme/theme.ts"],"sourcesContent":["import { parseColor } from './color';\nimport type { ThemeFont } from './fonts';\nimport {\n TONE_VARIABLES,\n type ToneInput,\n type ToneSurfaces,\n type ToneValues,\n resolveTone,\n toneClassName,\n} from './tones';\n\n/**\n * A theme: design tokens, as CSS variables without the leading `--`, with optional overrides for\n * the dark scheme, raw palette colors, its own tones, and named variants of components (decision\n * 0024). A theme is plain data: the `Theme` schema of `@panneau/protocol` validates it, and plugins\n * of `@panneau/core` register it. Write one with `defineTheme()` to check token names.\n *\n * It is a type rather than an interface so that it is assignable to the `Theme` of\n * `@panneau/protocol`, which accepts properties of later versions.\n */\nexport type Theme = {\n /** A name for theme pickers. */\n label?: string;\n /** Tokens of the light scheme, or of both schemes without `dark`: `{ 'panneau-color-accent': '#05f' }`. */\n tokens: Record<string, string>;\n /** Tokens that change in the dark scheme. */\n dark?: Record<string, string>;\n /**\n * Raw colors, written as `--panneau-palette-<name>`: tokens and tones use them with\n * `var(--panneau-palette-<name>)`, so that a theme names its brand colors once.\n */\n palette?: Record<string, string>;\n /**\n * Tones added or redefined by the theme: one color, from which Panneau derives the others,\n * or every value. Declare added tones in `PanneauTones` so that `tone=\"signal\"` type-checks.\n */\n tones?: Record<string, ToneInput>;\n /**\n * Named variants of components: token overrides that `<Badge variant=\"tag\">` applies through\n * its `panneau-badge-variant-tag` class. Declare them in `BadgeVariants` (and the like).\n */\n components?: Record<string, { variants?: Record<string, Record<string, string>> }>;\n /**\n * Tokens of each density, such as `panneau-control-height`: tokens set here change with the\n * density of the root, while the same tokens in `tokens` would apply to every density.\n */\n densities?: Partial<Record<Exclude<Density, 'auto'>, Record<string, string>>>;\n /**\n * Font faces and font stylesheets, which `PanneauRoot` adds to the page once. Font tokens\n * (`panneau-font-family-heading`) then use their families.\n */\n fonts?: ThemeFont[];\n};\n\n/** `auto` follows the system setting (`prefers-color-scheme`). */\nexport type ColorScheme = 'light' | 'dark' | 'auto';\n\n/**\n * How much room controls and rows take: `compact`, `comfortable`, or `touch`, with larger targets.\n * `auto` is `touch` on coarse pointers (touch screens) and `comfortable` otherwise.\n */\nexport type Density = 'compact' | 'comfortable' | 'touch' | 'auto';\n\nfunction declarations(tokens: Record<string, string>): string {\n return Object.entries(tokens)\n .filter(([name, value]) => /^[a-zA-Z0-9-_]+$/.test(name) && !/[{};<]/.test(value))\n .map(([name, value]) => `--${name}:${value};`)\n .join('');\n}\n\n/** A short, stable hash of a string, to scope the CSS of a theme. */\nexport function hashString(value: string): string {\n let hash = 5381;\n for (let index = 0; index < value.length; index += 1) {\n hash = (hash * 33) ^ value.charCodeAt(index);\n }\n return (hash >>> 0).toString(36);\n}\n\nconst NAME = /^[a-z0-9-]+$/;\n\nconst VARIABLE = /^var\\(--([a-zA-Z0-9_-]+)\\)$/;\n\n/** The palette of a theme, as variables: `{ 'panneau-palette-orange': '#f25c05' }`. */\nexport function paletteVariables(\n palette: Readonly<Record<string, string>> = {},\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(palette)\n .filter(([name]) => NAME.test(name))\n .map(([name, value]) => [`panneau-palette-${name}`, value]),\n );\n}\n\n/**\n * Follows `var(--name)` references through the given variables (tokens, palette colors), until a\n * value that is not one: `var(--panneau-palette-orange)` becomes `#f25c05`. A reference to a\n * variable that isn't given is returned as is.\n */\nexport function resolveReference(\n value: string,\n variables: Readonly<Record<string, string>>,\n): string {\n let current = value;\n for (let depth = 0; depth < 10; depth += 1) {\n const name = VARIABLE.exec(current.trim())?.[1];\n if (name === undefined || !Object.hasOwn(variables, name)) {\n return current;\n }\n current = variables[name] ?? current;\n }\n return current;\n}\n\nfunction toneDeclarations(values: ToneValues): string {\n return declarations(\n Object.fromEntries(\n (Object.keys(TONE_VARIABLES) as (keyof ToneValues)[]).map((key) => [\n TONE_VARIABLES[key],\n values[key],\n ]),\n ),\n );\n}\n\n/**\n * The surfaces of a theme in each scheme, when it sets ones Panneau can read: tones derived from\n * one color are made readable on them.\n */\nexport function themeSurfaces(theme: Theme): ToneSurfaces {\n const palette = paletteVariables(theme.palette);\n const surface = (tokens: Record<string, string>) => {\n const variables = { ...palette, ...tokens };\n const value = variables['panneau-color-surface'];\n return value !== undefined ? parseColor(resolveReference(value, variables)) : null;\n };\n const light = surface(theme.tokens);\n const dark =\n theme.dark?.['panneau-color-surface'] !== undefined\n ? surface({ ...theme.tokens, ...theme.dark })\n : null;\n return {\n ...(light !== null && { light }),\n ...(dark !== null && { dark }),\n };\n}\n\n/**\n * The rules of the densities of a theme. `auto` takes the comfortable values on fine pointers and\n * the touch ones on coarse pointers, like the default theme.\n */\nfunction densityCss(root: string, densities: Theme['densities'] = {}): string {\n const body = (density: Exclude<Density, 'auto'>) => declarations(densities[density] ?? {});\n const rule = (selector: string, css: string) => (css !== '' ? `${selector}{${css}}` : '');\n const media = (query: string, css: string) => (css !== '' ? `@media ${query}{${css}}` : '');\n const selector = (density: Density) => `${root}[data-density=\"${density}\"]`;\n return [\n rule(selector('compact'), body('compact')),\n rule(selector('comfortable'), body('comfortable')),\n media('not (pointer: coarse)', rule(selector('auto'), body('comfortable'))),\n rule(selector('touch'), body('touch')),\n media('(pointer: coarse)', rule(selector('auto'), body('touch'))),\n ].join('');\n}\n\n/**\n * The CSS of a theme, scoped to the roots that carry `data-panneau-theme=\"<scope>\"`: its palette and\n * tokens, its densities, its tones and the variants of components. Its rules are more specific than the default\n * tokens and the built-in tones, and dark overrides more specific than light ones. Token, tone,\n * component and variant names must be plain identifiers, and values can't contain `{`, `}`, `;` or\n * `<`: other entries are ignored.\n */\nexport function getThemeCss(theme: Theme, scope: string): string {\n const root = `[data-panneau-theme=\"${scope}\"]`;\n const dark = `${root}[data-color-scheme=\"dark\"]`;\n const auto = `${root}[data-color-scheme=\"auto\"]`;\n const light: string[] = [];\n const darkRules: string[] = [];\n const rule = (selector: string, body: string) => (body !== '' ? `${selector}{${body}}` : '');\n\n const palette = paletteVariables(theme.palette);\n const surfaces = themeSurfaces(theme);\n light.push(rule(root, declarations({ ...palette, ...theme.tokens })));\n light.push(densityCss(root, theme.densities));\n if (theme.dark !== undefined) {\n darkRules.push(rule('§', declarations(theme.dark)));\n }\n Object.entries(theme.tones ?? {})\n .filter(([name]) => NAME.test(name))\n .forEach(([name, input]) => {\n // A tone from a palette color derives from the color itself.\n const values = resolveTone(\n typeof input === 'string' ? resolveReference(input, palette) : input,\n surfaces,\n );\n const selector = `.${toneClassName(name)}`;\n light.push(rule(`${root} ${selector}`, toneDeclarations(values.light)));\n darkRules.push(rule(`§ ${selector}`, toneDeclarations(values.dark)));\n });\n Object.entries(theme.components ?? {})\n .filter(([component]) => NAME.test(component))\n .forEach(([component, { variants = {} }]) => {\n Object.entries(variants)\n .filter(([name]) => NAME.test(name))\n .forEach(([name, tokens]) => {\n light.push(\n rule(`${root} .panneau-${component}-variant-${name}`, declarations(tokens)),\n );\n });\n });\n\n const darkCss = darkRules.filter(Boolean);\n return [\n ...light,\n ...darkCss.map((css) => css.replaceAll('§', dark)),\n darkCss.length > 0\n ? `@media (prefers-color-scheme: dark){${darkCss.map((css) => css.replaceAll('§', auto)).join('')}}`\n : '',\n ].join('');\n}\n"],"mappings":";;;AA+DA,SAASuB,aAAab,QAAwC;CAC1D,OAAOc,OAAOC,QAAQf,MAAM,CAAC,CACxBgB,QAAQ,CAACC,MAAMC,WAAW,mBAAmBC,KAAKF,IAAI,KAAK,CAAC,SAASE,KAAKD,KAAK,CAAC,CAAC,CACjFE,KAAK,CAACH,MAAMC,WAAW,KAAKD,KAAI,GAAIC,MAAK,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,CAAC/C,MAAMjB,YAAY;GACzBgD,MAAMe,KACFV,KAAK,GAAGH,KAAI,YAAagB,UAAS,WAAYjD,QAAQJ,aAAab,MAAM,CAAC,CAC9E;EACJ,CAAC;CACT,CAAC;CAEL,MAAMmE,UAAUN,UAAU7C,OAAOoD,OAAO;CACxC,OAAO;EACH,GAAGpB;EACH,GAAGmB,QAAQ/C,KAAKmC,QAAQA,IAAIc,WAAW,KAAKnE,IAAI,CAAC;EACjDiE,QAAQ1C,SAAS,IACX,uCAAuC0C,QAAQ/C,KAAKmC,QAAQA,IAAIc,WAAW,KAAKT,IAAI,CAAC,CAAC,CAACvC,KAAK,EAAE,EAAC,KAC/F;CAAE,CACX,CAACA,KAAK,EAAE;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toneClass.js","names":["styles"],"sources":["../../src/theme/toneClass.ts"],"sourcesContent":["import styles from './Tone.module.css';\nimport { type Tone, toneClassName } from './tones';\n\n/**\n * The class of a tone, `panneau-tone-<tone>`. The built-in tones come from `Tone.module.css`, whose\n * classes get the same stable names, so using it includes their CSS; a theme's own tones get their\n * rules from the theme.\n */\nexport function toneClass(tone: Tone): string {\n return (Object.hasOwn(styles, tone) ? styles[tone] : undefined) ?? toneClassName(tone);\n}\n"],"mappings":";;;;;;;;AAQA,
|
|
1
|
+
{"version":3,"file":"toneClass.js","names":["styles","Tone","toneClassName","toneClass","tone","Object","hasOwn","undefined","styles"],"sources":["../../src/theme/toneClass.ts"],"sourcesContent":["import styles from './Tone.module.css';\nimport { type Tone, toneClassName } from './tones';\n\n/**\n * The class of a tone, `panneau-tone-<tone>`. The built-in tones come from `Tone.module.css`, whose\n * classes get the same stable names, so using it includes their CSS; a theme's own tones get their\n * rules from the theme.\n */\nexport function toneClass(tone: Tone): string {\n return (Object.hasOwn(styles, tone) ? styles[tone] : undefined) ?? toneClassName(tone);\n}\n"],"mappings":";;;;;;;;AAQA,SAAgBG,UAAUC,MAAoB;CAC1C,QAAQC,OAAOC,OAAON,qBAAQI,IAAI,IAAIJ,oBAAOI,QAAQG,KAAAA,MAAcL,cAAcE,IAAI;AACzF"}
|
package/dist/theme/tones.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tones.js","names":[],"sources":["../../src/theme/tones.ts"],"sourcesContent":["import {\n type Rgb,\n WHITE,\n contrastRatio,\n ensureContrast,\n mixColors,\n parseColor,\n readableTextColor,\n toHex,\n} from './color';\n\n/**\n * The tones that components accept (`tone=\"success\"`), like Bootstrap's `$theme-colors`. A theme\n * adds its own; declare them here so that `tone=\"signal\"` type-checks:\n *\n * ```ts\n * declare module '@panneau/ui' {\n * interface PanneauTones {\n * signal: true;\n * }\n * }\n * ```\n */\nexport interface PanneauTones {\n neutral: true;\n accent: true;\n success: true;\n warning: true;\n danger: true;\n info: true;\n}\n\n/** A tone name: a built-in tone, or one declared in `PanneauTones`. */\nexport type Tone = keyof PanneauTones & string;\n\n/** The tones Panneau defines, from the semantic tokens of the theme. */\nexport const BUILT_IN_TONES = [\n 'neutral',\n 'accent',\n 'success',\n 'warning',\n 'danger',\n 'info',\n] as const;\n\n/** The colors of a tone, as CSS values. */\nexport type ToneValues = {\n /** Text and icons on surfaces: the outline, subtle and ghost appearances. */\n text: string;\n /** Background of the subtle appearance. */\n subtle: string;\n /** Border of the subtle appearance. */\n border: string;\n /** Border of the outline appearance. */\n outline: string;\n /** Background of the solid appearance. */\n solid: string;\n /** Background of the solid appearance on hover and press. */\n solidHover: string;\n /** Text on the solid appearance. */\n solidText: string;\n};\n\n/**\n * A tone of a theme: one color, from which Panneau derives the others (`'#f25c05'`), or every\n * value, with optional overrides for the dark scheme.\n */\nexport type ToneInput = string | (ToneValues & { dark?: Partial<ToneValues> });\n\n/** The local CSS variables of a tone, which components read. */\nexport const TONE_VARIABLES: Readonly<Record<keyof ToneValues, string>> = {\n text: 'panneau-tone-text',\n subtle: 'panneau-tone-subtle',\n border: 'panneau-tone-border',\n outline: 'panneau-tone-outline',\n solid: 'panneau-tone-solid',\n solidHover: 'panneau-tone-solid-hover',\n solidText: 'panneau-tone-solid-text',\n};\n\n/** The class that applies a tone: `panneau-tone-<tone>`. */\nexport function toneClassName(tone: string): string {\n return `panneau-tone-${tone}`;\n}\n\n/** Surfaces text must be readable on, in each scheme of the default theme. */\nconst SURFACES: Record<'light' | 'dark', Rgb> = { light: WHITE, dark: { r: 24, g: 24, b: 27 } };\n\n/** The surfaces of a theme, in each scheme, when it sets ones Panneau can read. */\nexport type ToneSurfaces = Partial<Record<'light' | 'dark', Rgb>>;\n\n/** How much of the tone's color the subtle background mixes into the surface, per scheme. */\nexport const SUBTLE_AMOUNTS = { light: 0.12, dark: 0.22 };\n\n/** Text must reach this contrast ratio (WCAG AA for normal text). */\nexport const MIN_CONTRAST_RATIO = 4.5;\n\n/**\n * The values of a tone, in both schemes, from one color: Panneau's `button-variant()` and\n * `color-contrast()`.\n *\n * - The solid background is the color, with white or black text, whichever reads better, and a\n * hover 15% darker (or lighter, when the text is black and darker would hurt it).\n * - The text color is the color, darkened (light scheme) or lightened (dark scheme) until it\n * reaches 4.5:1 against the subtle background, which is tinted, and so against the surface too.\n * - The subtle background and the border are mixed with the surface in CSS, so they follow the\n * surface of any theme.\n *\n * A color Panneau can't read (a CSS variable, a named color) is used as is, with `color-mix()` for\n * the hover and white text: `checkTheme()` reports it as unchecked.\n *\n * Text is made readable on the surfaces of the default theme, or on those given, which themes pass\n * so that a tone stays readable on their own surfaces.\n */\nexport function deriveTone(\n color: string,\n surfaces: ToneSurfaces = {},\n): { light: ToneValues; dark: ToneValues } {\n const subtle = (amount: number) =>\n `color-mix(in srgb, ${color} ${amount}%, var(--panneau-color-surface))`;\n const parsed = parseColor(color);\n if (parsed === null) {\n const values: ToneValues = {\n text: color,\n subtle: subtle(SUBTLE_AMOUNTS.light * 100),\n border: subtle(45),\n outline: color,\n solid: color,\n solidHover: `color-mix(in srgb, ${color}, #000 15%)`,\n solidText: '#fff',\n };\n return { light: values, dark: { ...values, subtle: subtle(SUBTLE_AMOUNTS.dark * 100) } };\n }\n const solidText = readableTextColor(parsed);\n const darker = mixColors(parsed, { r: 0, g: 0, b: 0 }, 0.15);\n const hover =\n contrastRatio(solidText, darker) >= contrastRatio(solidText, parsed)\n ? darker\n : mixColors(parsed, WHITE, 0.15);\n const solid = toHex(parsed);\n const shared = {\n solid,\n solidHover: toHex(hover),\n solidText: toHex(solidText),\n };\n // Readable on the subtle background, which is closer to the text color than the surface.\n const readable = (scheme: 'light' | 'dark') =>\n toHex(\n ensureContrast(\n parsed,\n mixColors(surfaces[scheme] ?? SURFACES[scheme], parsed, SUBTLE_AMOUNTS[scheme]),\n MIN_CONTRAST_RATIO,\n ),\n );\n const light = readable('light');\n const dark = readable('dark');\n return {\n light: {\n ...shared,\n text: light,\n outline: light,\n subtle: subtle(SUBTLE_AMOUNTS.light * 100),\n border: subtle(45),\n },\n dark: {\n ...shared,\n text: dark,\n outline: dark,\n subtle: subtle(SUBTLE_AMOUNTS.dark * 100),\n border: subtle(55),\n },\n };\n}\n\n/** The values of a tone input, in both schemes, derived on the given surfaces if it is one color. */\nexport function resolveTone(\n input: ToneInput,\n surfaces: ToneSurfaces = {},\n): { light: ToneValues; dark: ToneValues } {\n if (typeof input === 'string') {\n return deriveTone(input, surfaces);\n }\n const { dark, ...light } = input;\n return { light, dark: { ...light, ...dark } };\n}\n"],"mappings":";;;AAoCA,
|
|
1
|
+
{"version":3,"file":"tones.js","names":["Rgb","WHITE","contrastRatio","ensureContrast","mixColors","parseColor","readableTextColor","toHex","PanneauTones","neutral","accent","success","warning","danger","info","Tone","BUILT_IN_TONES","const","ToneValues","text","subtle","border","outline","solid","solidHover","solidText","ToneInput","dark","Partial","TONE_VARIABLES","Readonly","Record","toneClassName","tone","SURFACES","light","r","g","b","ToneSurfaces","SUBTLE_AMOUNTS","MIN_CONTRAST_RATIO","deriveTone","color","surfaces","amount","parsed","values","darker","hover","shared","readable","scheme","resolveTone","input"],"sources":["../../src/theme/tones.ts"],"sourcesContent":["import {\n type Rgb,\n WHITE,\n contrastRatio,\n ensureContrast,\n mixColors,\n parseColor,\n readableTextColor,\n toHex,\n} from './color';\n\n/**\n * The tones that components accept (`tone=\"success\"`), like Bootstrap's `$theme-colors`. A theme\n * adds its own; declare them here so that `tone=\"signal\"` type-checks:\n *\n * ```ts\n * declare module '@panneau/ui' {\n * interface PanneauTones {\n * signal: true;\n * }\n * }\n * ```\n */\nexport interface PanneauTones {\n neutral: true;\n accent: true;\n success: true;\n warning: true;\n danger: true;\n info: true;\n}\n\n/** A tone name: a built-in tone, or one declared in `PanneauTones`. */\nexport type Tone = keyof PanneauTones & string;\n\n/** The tones Panneau defines, from the semantic tokens of the theme. */\nexport const BUILT_IN_TONES = [\n 'neutral',\n 'accent',\n 'success',\n 'warning',\n 'danger',\n 'info',\n] as const;\n\n/** The colors of a tone, as CSS values. */\nexport type ToneValues = {\n /** Text and icons on surfaces: the outline, subtle and ghost appearances. */\n text: string;\n /** Background of the subtle appearance. */\n subtle: string;\n /** Border of the subtle appearance. */\n border: string;\n /** Border of the outline appearance. */\n outline: string;\n /** Background of the solid appearance. */\n solid: string;\n /** Background of the solid appearance on hover and press. */\n solidHover: string;\n /** Text on the solid appearance. */\n solidText: string;\n};\n\n/**\n * A tone of a theme: one color, from which Panneau derives the others (`'#f25c05'`), or every\n * value, with optional overrides for the dark scheme.\n */\nexport type ToneInput = string | (ToneValues & { dark?: Partial<ToneValues> });\n\n/** The local CSS variables of a tone, which components read. */\nexport const TONE_VARIABLES: Readonly<Record<keyof ToneValues, string>> = {\n text: 'panneau-tone-text',\n subtle: 'panneau-tone-subtle',\n border: 'panneau-tone-border',\n outline: 'panneau-tone-outline',\n solid: 'panneau-tone-solid',\n solidHover: 'panneau-tone-solid-hover',\n solidText: 'panneau-tone-solid-text',\n};\n\n/** The class that applies a tone: `panneau-tone-<tone>`. */\nexport function toneClassName(tone: string): string {\n return `panneau-tone-${tone}`;\n}\n\n/** Surfaces text must be readable on, in each scheme of the default theme. */\nconst SURFACES: Record<'light' | 'dark', Rgb> = { light: WHITE, dark: { r: 24, g: 24, b: 27 } };\n\n/** The surfaces of a theme, in each scheme, when it sets ones Panneau can read. */\nexport type ToneSurfaces = Partial<Record<'light' | 'dark', Rgb>>;\n\n/** How much of the tone's color the subtle background mixes into the surface, per scheme. */\nexport const SUBTLE_AMOUNTS = { light: 0.12, dark: 0.22 };\n\n/** Text must reach this contrast ratio (WCAG AA for normal text). */\nexport const MIN_CONTRAST_RATIO = 4.5;\n\n/**\n * The values of a tone, in both schemes, from one color: Panneau's `button-variant()` and\n * `color-contrast()`.\n *\n * - The solid background is the color, with white or black text, whichever reads better, and a\n * hover 15% darker (or lighter, when the text is black and darker would hurt it).\n * - The text color is the color, darkened (light scheme) or lightened (dark scheme) until it\n * reaches 4.5:1 against the subtle background, which is tinted, and so against the surface too.\n * - The subtle background and the border are mixed with the surface in CSS, so they follow the\n * surface of any theme.\n *\n * A color Panneau can't read (a CSS variable, a named color) is used as is, with `color-mix()` for\n * the hover and white text: `checkTheme()` reports it as unchecked.\n *\n * Text is made readable on the surfaces of the default theme, or on those given, which themes pass\n * so that a tone stays readable on their own surfaces.\n */\nexport function deriveTone(\n color: string,\n surfaces: ToneSurfaces = {},\n): { light: ToneValues; dark: ToneValues } {\n const subtle = (amount: number) =>\n `color-mix(in srgb, ${color} ${amount}%, var(--panneau-color-surface))`;\n const parsed = parseColor(color);\n if (parsed === null) {\n const values: ToneValues = {\n text: color,\n subtle: subtle(SUBTLE_AMOUNTS.light * 100),\n border: subtle(45),\n outline: color,\n solid: color,\n solidHover: `color-mix(in srgb, ${color}, #000 15%)`,\n solidText: '#fff',\n };\n return { light: values, dark: { ...values, subtle: subtle(SUBTLE_AMOUNTS.dark * 100) } };\n }\n const solidText = readableTextColor(parsed);\n const darker = mixColors(parsed, { r: 0, g: 0, b: 0 }, 0.15);\n const hover =\n contrastRatio(solidText, darker) >= contrastRatio(solidText, parsed)\n ? darker\n : mixColors(parsed, WHITE, 0.15);\n const solid = toHex(parsed);\n const shared = {\n solid,\n solidHover: toHex(hover),\n solidText: toHex(solidText),\n };\n // Readable on the subtle background, which is closer to the text color than the surface.\n const readable = (scheme: 'light' | 'dark') =>\n toHex(\n ensureContrast(\n parsed,\n mixColors(surfaces[scheme] ?? SURFACES[scheme], parsed, SUBTLE_AMOUNTS[scheme]),\n MIN_CONTRAST_RATIO,\n ),\n );\n const light = readable('light');\n const dark = readable('dark');\n return {\n light: {\n ...shared,\n text: light,\n outline: light,\n subtle: subtle(SUBTLE_AMOUNTS.light * 100),\n border: subtle(45),\n },\n dark: {\n ...shared,\n text: dark,\n outline: dark,\n subtle: subtle(SUBTLE_AMOUNTS.dark * 100),\n border: subtle(55),\n },\n };\n}\n\n/** The values of a tone input, in both schemes, derived on the given surfaces if it is one color. */\nexport function resolveTone(\n input: ToneInput,\n surfaces: ToneSurfaces = {},\n): { light: ToneValues; dark: ToneValues } {\n if (typeof input === 'string') {\n return deriveTone(input, surfaces);\n }\n const { dark, ...light } = input;\n return { light, dark: { ...light, ...dark } };\n}\n"],"mappings":";;;AAoCA,IAAagB,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;AAAM;;AA4BV,IAAaa,iBAA6D;CACtEV,MAAM;CACNC,QAAQ;CACRC,QAAQ;CACRC,SAAS;CACTC,OAAO;CACPC,YAAY;CACZC,WAAW;AACf;;AAGA,SAAgBO,cAAcC,MAAsB;CAChD,OAAO,gBAAgBA;AAC3B;;AAGA,IAAMC,WAA0C;CAAEC,OAAOlC;CAAO0B,MAAM;EAAES,GAAG;EAAIC,GAAG;EAAIC,GAAG;CAAG;AAAE;;AAM9F,IAAaE,iBAAiB;CAAEL,OAAO;CAAMR,MAAM;AAAK;;AAGxD,IAAac,qBAAqB;;;;;;;;;;;;;;;;;;AAmBlC,SAAgBC,WACZC,OACAC,WAAyB,CAAC,GACa;CACvC,MAAMxB,UAAUyB,WACZ,sBAAsBF,MAAK,GAAIE,OAAM;C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