@astl/astrolabe 0.1.2 → 0.1.4
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/CHANGELOG.md +30 -0
- package/dist/cdn/astrolabe-editor.js +3 -3
- package/dist/cdn/astrolabe-player.js +1 -1
- package/dist/cdn/astrolabe.js +1 -1
- package/dist/cdn/astrolabe.standalone.js +1094 -1060
- package/dist/cdn/chunks/{audio-B0LSIn5N.js → audio-Biof5aA3.js} +2 -2
- package/dist/cdn/chunks/{audio-B0LSIn5N.js.map → audio-Biof5aA3.js.map} +1 -1
- package/dist/cdn/chunks/{block-styles-CKo9x7Vt.js → block-styles-CCtSFM4j.js} +2 -2
- package/dist/cdn/chunks/{block-styles-CKo9x7Vt.js.map → block-styles-CCtSFM4j.js.map} +1 -1
- package/dist/cdn/chunks/{book-CHzDDaim.js → book-IFipARhv.js} +2 -2
- package/dist/cdn/chunks/{book-CHzDDaim.js.map → book-IFipARhv.js.map} +1 -1
- package/dist/cdn/chunks/{callout-QFLFLPc5.js → callout-CuajbbYY.js} +2 -2
- package/dist/cdn/chunks/{callout-QFLFLPc5.js.map → callout-CuajbbYY.js.map} +1 -1
- package/dist/cdn/chunks/{categorise-BO2tNVJ3.js → categorise-Cm6kXLXw.js} +2 -2
- package/dist/cdn/chunks/{categorise-BO2tNVJ3.js.map → categorise-Cm6kXLXw.js.map} +1 -1
- package/dist/cdn/chunks/{chip-styles-Dme5daTO.js → chip-styles--gboWK2Z.js} +2 -2
- package/dist/cdn/chunks/{chip-styles-Dme5daTO.js.map → chip-styles--gboWK2Z.js.map} +1 -1
- package/dist/cdn/chunks/{choice-CExBvqKj.js → choice-BSpB6LHl.js} +2 -2
- package/dist/cdn/chunks/{choice-CExBvqKj.js.map → choice-BSpB6LHl.js.map} +1 -1
- package/dist/cdn/chunks/{color-control-Cl5cuMSO.js → color-control-1kkdM8ns.js} +2 -2
- package/dist/cdn/chunks/{color-control-Cl5cuMSO.js.map → color-control-1kkdM8ns.js.map} +1 -1
- package/dist/cdn/chunks/{crossword-Cb-a3Tjj.js → crossword-BdOAEPcL.js} +2 -2
- package/dist/cdn/chunks/{crossword-Cb-a3Tjj.js.map → crossword-BdOAEPcL.js.map} +1 -1
- package/dist/cdn/chunks/{definitions-CNX90WtL.js → definitions-BybSa1mq.js} +2 -2
- package/dist/cdn/chunks/{definitions-CNX90WtL.js.map → definitions-BybSa1mq.js.map} +1 -1
- package/dist/cdn/chunks/{directive-helpers-D7lOZKnB.js → directive-helpers-US6zRjJ1.js} +2 -2
- package/dist/cdn/chunks/{directive-helpers-D7lOZKnB.js.map → directive-helpers-US6zRjJ1.js.map} +1 -1
- package/dist/cdn/chunks/{drop-vRXndjHu.js → drop-D4NQ0WK_.js} +2 -2
- package/dist/cdn/chunks/{drop-vRXndjHu.js.map → drop-D4NQ0WK_.js.map} +1 -1
- package/dist/cdn/chunks/{flash-cards-0NrrKdrx.js → flash-cards-D4ebb5m6.js} +2 -2
- package/dist/cdn/chunks/{flash-cards-0NrrKdrx.js.map → flash-cards-D4ebb5m6.js.map} +1 -1
- package/dist/cdn/chunks/{gap-lor-khst.js → gap-D-Sipuyu.js} +2 -2
- package/dist/cdn/chunks/{gap-lor-khst.js.map → gap-D-Sipuyu.js.map} +1 -1
- package/dist/cdn/chunks/{help-C-woafz5.js → help-CmCFuNXk.js} +2 -2
- package/dist/cdn/chunks/{help-C-woafz5.js.map → help-CmCFuNXk.js.map} +1 -1
- package/dist/cdn/chunks/{help-form-CDg3TCwI.js → help-form-Di2NtKDp.js} +14 -10
- package/dist/cdn/chunks/help-form-Di2NtKDp.js.map +1 -0
- package/dist/cdn/chunks/{hotspot-oel1Eelo.js → hotspot-B3bvqVzf.js} +2 -2
- package/dist/cdn/chunks/{hotspot-oel1Eelo.js.map → hotspot-B3bvqVzf.js.map} +1 -1
- package/dist/cdn/chunks/{image-drop-Dkprw0Kn.js → image-drop-vLc2B7rF.js} +2 -2
- package/dist/cdn/chunks/{image-drop-Dkprw0Kn.js.map → image-drop-vLc2B7rF.js.map} +1 -1
- package/dist/cdn/chunks/{image-label-Dm5shQSh.js → image-label-DsKxQDTQ.js} +2 -2
- package/dist/cdn/chunks/{image-label-Dm5shQSh.js.map → image-label-DsKxQDTQ.js.map} +1 -1
- package/dist/cdn/chunks/{inline-styles-CTgXWnHb.js → inline-styles-CFNlb6f2.js} +2 -2
- package/dist/cdn/chunks/{inline-styles-CTgXWnHb.js.map → inline-styles-CFNlb6f2.js.map} +1 -1
- package/dist/cdn/chunks/{insert-menu-7vANVmTK.js → insert-menu-DAQglwtG.js} +2 -2
- package/dist/cdn/chunks/{insert-menu-7vANVmTK.js.map → insert-menu-DAQglwtG.js.map} +1 -1
- package/dist/cdn/chunks/{issue-list-BT9qvnZU.js → issue-list-CzSmohtT.js} +2 -2
- package/dist/cdn/chunks/{issue-list-BT9qvnZU.js.map → issue-list-CzSmohtT.js.map} +1 -1
- package/dist/cdn/chunks/{live-jdiyYln2.js → live-qnReIRtj.js} +2 -2
- package/dist/cdn/chunks/{live-jdiyYln2.js.map → live-qnReIRtj.js.map} +1 -1
- package/dist/cdn/chunks/{long-answer-CtzClLAx.js → long-answer-NSWJiK0z.js} +2 -2
- package/dist/cdn/chunks/{long-answer-CtzClLAx.js.map → long-answer-NSWJiK0z.js.map} +1 -1
- package/dist/cdn/chunks/{mark-words-CpH3gTcX.js → mark-words-BKu-_uIl.js} +2 -2
- package/dist/cdn/chunks/{mark-words-CpH3gTcX.js.map → mark-words-BKu-_uIl.js.map} +1 -1
- package/dist/cdn/chunks/{match-DKE_4o-x.js → match-BpnJGW_5.js} +21 -13
- package/dist/cdn/chunks/match-BpnJGW_5.js.map +1 -0
- package/dist/cdn/chunks/{memory-B6hSyHyz.js → memory-BgTHujsU.js} +2 -2
- package/dist/cdn/chunks/{memory-B6hSyHyz.js.map → memory-BgTHujsU.js.map} +1 -1
- package/dist/cdn/chunks/messages-Qzse5KMX.js +2 -0
- package/dist/cdn/chunks/messages-Qzse5KMX.js.map +1 -0
- package/dist/cdn/chunks/{option-styles-WKzjKmCH.js → option-styles-B2sBX5Oz.js} +2 -2
- package/dist/cdn/chunks/{option-styles-WKzjKmCH.js.map → option-styles-B2sBX5Oz.js.map} +1 -1
- package/dist/cdn/chunks/{order-BhG_6IC-.js → order-B9gqH5wm.js} +2 -2
- package/dist/cdn/chunks/{order-BhG_6IC-.js.map → order-B9gqH5wm.js.map} +1 -1
- package/dist/cdn/chunks/{picture-view-BKnAyScQ.js → picture-view-Deodu_mb.js} +2 -2
- package/dist/cdn/chunks/{picture-view-BKnAyScQ.js.map → picture-view-Deodu_mb.js.map} +1 -1
- package/dist/cdn/chunks/{repeat-CY2W2URZ.js → repeat-BDXokpxQ.js} +2 -2
- package/dist/cdn/chunks/{repeat-CY2W2URZ.js.map → repeat-BDXokpxQ.js.map} +1 -1
- package/dist/cdn/chunks/{runtime-DxAbpr3S.js → runtime-C25QK5B0.js} +3 -3
- package/dist/cdn/chunks/{runtime-DxAbpr3S.js.map → runtime-C25QK5B0.js.map} +1 -1
- package/dist/cdn/chunks/{scan-jWgPnVxA.js → scan-BVhxT2Hw.js} +2 -2
- package/dist/cdn/chunks/{scan-jWgPnVxA.js.map → scan-BVhxT2Hw.js.map} +1 -1
- package/dist/cdn/chunks/{select-DTA3dJzr.js → select-DPpKJwSg.js} +2 -2
- package/dist/cdn/chunks/{select-DTA3dJzr.js.map → select-DPpKJwSg.js.map} +1 -1
- package/dist/cdn/chunks/select-QZ35cyns.js +2 -0
- package/dist/cdn/chunks/select-QZ35cyns.js.map +1 -0
- package/dist/cdn/chunks/{source-view-CZVxgTNQ.js → source-view-gqFlZzwR.js} +2 -2
- package/dist/cdn/chunks/{source-view-CZVxgTNQ.js.map → source-view-gqFlZzwR.js.map} +1 -1
- package/dist/cdn/chunks/{style-form-DUGbG_kL.js → style-form-DuR0EEum.js} +2 -2
- package/dist/cdn/chunks/{style-form-DUGbG_kL.js.map → style-form-DuR0EEum.js.map} +1 -1
- package/dist/cdn/chunks/{style-messages-qdf3pZbT.js → style-messages-B136zSom.js} +2 -2
- package/dist/cdn/chunks/{style-messages-qdf3pZbT.js.map → style-messages-B136zSom.js.map} +1 -1
- package/dist/cdn/chunks/{style-popups-BobgX1WK.js → style-popups-Bcl5imdP.js} +2 -2
- package/dist/cdn/chunks/{style-popups-BobgX1WK.js.map → style-popups-Bcl5imdP.js.map} +1 -1
- package/dist/cdn/chunks/{style-rules-D17QGzXk.js → style-rules-ozpLz2ec.js} +2 -2
- package/dist/cdn/chunks/{style-rules-D17QGzXk.js.map → style-rules-ozpLz2ec.js.map} +1 -1
- package/dist/cdn/chunks/{styled-Dmx5Yjv7.js → styled-bQqnDxBf.js} +2 -2
- package/dist/cdn/chunks/{styled-Dmx5Yjv7.js.map → styled-bQqnDxBf.js.map} +1 -1
- package/dist/cdn/chunks/{styles-CdJT6Pp9.js → styles-DiY3VA_T.js} +5 -5
- package/dist/cdn/chunks/styles-DiY3VA_T.js.map +1 -0
- package/dist/cdn/chunks/surface-CIz1z2oY.js +1059 -0
- package/dist/cdn/chunks/surface-CIz1z2oY.js.map +1 -0
- package/dist/cdn/chunks/{true-false-DP3MO599.js → true-false-C-S6RmZY.js} +2 -2
- package/dist/cdn/chunks/{true-false-DP3MO599.js.map → true-false-C-S6RmZY.js.map} +1 -1
- package/dist/cdn/chunks/{video-j9MCH6Kw.js → video-Dae8Gguf.js} +2 -2
- package/dist/cdn/chunks/{video-j9MCH6Kw.js.map → video-Dae8Gguf.js.map} +1 -1
- package/dist/cdn/chunks/{word-bank-ARjwUKZf.js → word-bank-CsIle0Ro.js} +2 -2
- package/dist/cdn/chunks/{word-bank-ARjwUKZf.js.map → word-bank-CsIle0Ro.js.map} +1 -1
- package/dist/cdn/chunks/{word-search-AHvM7yCJ.js → word-search-IOCwqo3y.js} +2 -2
- package/dist/cdn/chunks/{word-search-AHvM7yCJ.js.map → word-search-IOCwqo3y.js.map} +1 -1
- package/package.json +9 -9
- package/dist/cdn/chunks/help-form-CDg3TCwI.js.map +0 -1
- package/dist/cdn/chunks/match-DKE_4o-x.js.map +0 -1
- package/dist/cdn/chunks/messages-D1aJfyS_.js +0 -2
- package/dist/cdn/chunks/messages-D1aJfyS_.js.map +0 -1
- package/dist/cdn/chunks/styles-CdJT6Pp9.js.map +0 -1
- package/dist/cdn/chunks/surface-C6wtQkTY.js +0 -1037
- package/dist/cdn/chunks/surface-C6wtQkTY.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-Dmx5Yjv7.js","names":["i","tokens","INERT_STYLE","styleContrast","overStyleColor","cleanStyle","parseStyleColor","MIN_CONTRAST","RAW_COLOR","LENGTH","MEASURES","offWith","name","hex","value","DARK_SURFACE","DARK_INK","toHsl","red","green","blue","g","b","max","min","lightness","chroma","fromHsl","hue","saturation","a","channel","k","at","alpha","inverted","color","contrastOn","ink","ground","legible","l","reads","fails","step","middle","written","channels","declared","declarations","property","darkContext","inked","around","fill","dark","painted","raw","context","takeStyles","taken","contexts","page","el","fragment","up","known","applyStyles","copies","content","index","styledSheet","adoptStyledSheet","root"],"sources":["../../../../player/src/player/styled.ts"],"sourcesContent":["/**\n * Authors' styles and layouts in the player, in a module of its own: a view that has neither never loads it. Without it\n * (or when its chunk fails) `cleanView` removes every `style`, and the exercise plays unstyled.\n *\n * A view is engine output, and is still read as hostile here: each `style` goes through `cleanStyle` again. Declarations\n * are written with `el.style.setProperty`, on the mounted copy of the view: a strict CSP (`style-src 'self'`) blocks a\n * `style` attribute, and allows the CSSOM.\n *\n * What an author writes for a light page is changed in four ways, which is why nothing here is a plain copy:\n * - a colour becomes `light-dark(as written, lightness inverted)`, so it follows the player's `color-scheme`; text keeps\n * the nearest lightness that can be read on its ground, because inverting a colour of middle lightness changes nothing;\n * - in `hc` a colour resolves to `--astl-author-ink` or `--astl-author-ground`, set only there. A custom property, not\n * `!important` in the sheet, because it also reaches the copies components keep of their content in shadow roots;\n * - a font size is clamped: relative sizes compound through nesting;\n * - a width stays within its box: an inline `max-width` would beat any cap in a sheet.\n */\nimport { INERT_STYLE } from '@astl/core';\nimport {\n cleanStyle,\n overStyleColor,\n parseStyleColor,\n type StyleColor,\n type StyleDeclaration,\n styleContrast,\n} from '@astl/core/declarations';\nimport { tokens } from '@astl/tokens';\nimport { css } from 'lit';\n\n/**\n * The contrast text keeps on its ground in the dark: the one the engine asks of the light page (WCAG AA), and a little\n * more, because this module knows the theme's surfaces and not those of the looks, a shade lighter (a test holds the\n * built-in ones to 4.5).\n */\nconst MIN_CONTRAST = 4.6;\nconst RAW_COLOR = /#[0-9a-f]+|rgba?\\([^()]*\\)/g;\nconst LENGTH = /^[\\d.]/;\nconst MEASURES: ReadonlySet<string> = new Set(['width', 'max-width', 'inline-size', 'max-inline-size']);\n\n/** Off in `hc`: what is drawn on (a fill, a shadow) goes; what is drawn with (text, lines) takes the text colour. */\nconst offWith = (name: string): string =>\n name === 'background-color' || name === 'box-shadow' ? '--astl-author-ground' : '--astl-author-ink';\n\nconst hex = (value: string): StyleColor => parseStyleColor(value) as StyleColor;\n/** The lighter of the theme's surfaces: text sits on both. */\nconst DARK_SURFACE = hex(tokens.themes.dark['surface-raised']);\nconst DARK_INK = hex(tokens.themes.dark.ink);\n\n/** Hue (0 to 6), saturation and lightness (0 to 1). */\ntype Hsl = readonly [hue: number, saturation: number, lightness: number];\n\nfunction toHsl([red, green, blue]: StyleColor): Hsl {\n const [r, g, b] = [red / 255, green / 255, blue / 255];\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const lightness = (max + min) / 2;\n const chroma = max - min;\n if (chroma === 0) return [0, 0, lightness];\n const hue =\n max === r ? ((g - b) / chroma + 6) % 6 : max === g ? (b - r) / chroma + 2 : (r - g) / chroma + 4;\n return [hue, chroma / (1 - Math.abs(2 * lightness - 1)), lightness];\n}\n\nfunction fromHsl([hue, saturation, lightness]: Hsl, alpha: number): StyleColor {\n const a = saturation * Math.min(lightness, 1 - lightness);\n const channel = (at: number): number => {\n const k = (at + hue * 2) % 12;\n return Math.round((lightness - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))) * 255);\n };\n return [channel(0), channel(8), channel(4), alpha];\n}\n\n/** The author's lightness inverted, with hue and saturation kept. */\nfunction inverted(color: StyleColor): StyleColor {\n const [hue, saturation, lightness] = toHsl(color);\n return fromHsl([hue, saturation, 1 - lightness], color[3]);\n}\n\nconst contrastOn = (ink: StyleColor, ground: StyleColor): number =>\n styleContrast(overStyleColor(ink, ground), ground);\n\n/** `color` with the lightness nearest its own that can be read on `ground`, hue and saturation kept. */\nfunction legible(color: StyleColor, ground: StyleColor): StyleColor {\n if (contrastOn(color, ground) >= MIN_CONTRAST) return color;\n const [hue, saturation, lightness] = toHsl(color);\n const at = (l: number) => fromHsl([hue, saturation, l], color[3]);\n let reads = contrastOn(at(1), ground) >= contrastOn(at(0), ground) ? 1 : 0;\n let fails = lightness;\n for (let step = 0; step < 8; step++) {\n const middle = (reads + fails) / 2;\n if (contrastOn(at(middle), ground) >= MIN_CONTRAST) reads = middle;\n else fails = middle;\n }\n return at(reads);\n}\n\nconst written = ([red, green, blue, alpha]: StyleColor): string => {\n const channels = [red, green, blue].map(Math.round).join(', ');\n return alpha === 1 ? `rgb(${channels})` : `rgba(${channels}, ${alpha})`;\n};\n\n/** What is known of the dark theme at an element: the ground, and whether an author's colour is the text colour. */\ninterface DarkContext {\n readonly ground: StyleColor;\n readonly inked: boolean;\n}\n\nconst declared = (declarations: readonly StyleDeclaration[], name: string): StyleColor | null => {\n const value = declarations.find(([property]) => property === name)?.[1];\n return value === undefined ? null : parseStyleColor(value);\n};\n\n/** The dark theme at an element with these declarations, inside `around`. */\nfunction darkContext(declarations: readonly StyleDeclaration[], around: DarkContext): DarkContext {\n const inked = around.inked || declared(declarations, 'color') !== null;\n const fill = declared(declarations, 'background-color');\n if (fill === null) return { ground: around.ground, inked };\n const dark = overStyleColor(inverted(fill), around.ground);\n // Without an author's colour, the text is the theme's: the fill is what has to give way.\n return { ground: inked ? dark : legible(dark, DARK_INK), inked };\n}\n\n/** A declaration as it is written on the mounted element. */\nfunction painted(name: string, value: string, context: DarkContext): string {\n if (name === 'font-family') return value;\n if (name === 'font-size') return LENGTH.test(value) ? `clamp(0.625rem, ${value}, 6rem)` : value;\n if (MEASURES.has(name)) return LENGTH.test(value) && !value.endsWith('%') ? `min(${value}, 100%)` : value;\n return value.replace(RAW_COLOR, (raw) => {\n const color = hex(raw);\n const dark =\n name === 'color'\n ? legible(inverted(color), context.ground)\n : name === 'background-color'\n ? context.ground\n : inverted(color);\n return `var(${offWith(name)}, light-dark(${raw}, ${written(dark)}))`;\n });\n}\n\n/** Styles taken from a view, by element of the fragment, as they will be written. */\nexport type TakenStyles = ReadonlyMap<Element, readonly StyleDeclaration[]>;\n\n/** Takes every `style` (read under its parsing name) out of a read view, before `cleanView` removes what is left. */\nexport function takeStyles(fragment: DocumentFragment): TakenStyles {\n const taken = new Map<Element, readonly StyleDeclaration[]>();\n const contexts = new Map<Element, DarkContext>();\n const page: DarkContext = { ground: DARK_SURFACE, inked: false };\n // In document order, so what is around an element has been read before it.\n for (const el of Array.from(fragment.querySelectorAll(`[${INERT_STYLE}]`))) {\n const { declarations } = cleanStyle(el.getAttribute(INERT_STYLE) ?? '');\n el.removeAttribute(INERT_STYLE);\n let around = page;\n for (let up = el.parentElement; up !== null; up = up.parentElement) {\n const known = contexts.get(up);\n if (known !== undefined) {\n around = known;\n break;\n }\n }\n const context = darkContext(declarations, around);\n contexts.set(el, context);\n taken.set(\n el,\n declarations.map(([name, value]): StyleDeclaration => [name, painted(name, value, context)]),\n );\n }\n return taken;\n}\n\n/** Writes taken styles on `content`, the copy of the cleaned `fragment` that gets mounted: same shape, same order. */\nexport function applyStyles(taken: TakenStyles, fragment: DocumentFragment, content: DocumentFragment): void {\n const copies = content.querySelectorAll<HTMLElement>('*');\n fragment.querySelectorAll('*').forEach((el, index) => {\n for (const [name, value] of taken.get(el) ?? []) copies[index]?.style.setProperty(name, value);\n });\n}\n\n// Pages hold their floats. `:not([hidden])` because `.canvas astl-page` would otherwise beat `astl-page[hidden]`.\n// An author's `display` must not bring back what the player or a component hides.\n// A page never scrolls sideways whatever is nested in it: the caps stop one element, not ten inside each other.\n// On a narrow player only what an author set gives way, so a coloured word gets no padding; `auto` margins centre.\nconst styledSheet = css`\n .canvas {\n container-type: inline-size;\n }\n .canvas astl-doc,\n .canvas astl-page:not([hidden]) {\n display: flow-root;\n }\n .canvas astl-page {\n overflow-x: clip;\n overflow-clip-margin: var(--astl-space-5);\n }\n .canvas [style][hidden] {\n display: none !important;\n }\n .canvas [style] {\n box-sizing: border-box;\n max-inline-size: 100%;\n }\n .canvas astl-columns {\n display: flex;\n flex-wrap: wrap;\n clear: both;\n gap: var(--astl-space-4);\n margin-block-end: var(--astl-space-4);\n }\n .canvas astl-columns > astl-column {\n flex: 1 1 0;\n min-inline-size: min(10rem, 100%);\n }\n .canvas astl-columns > astl-column > :first-child {\n margin-block-start: 0;\n }\n .canvas astl-columns > astl-column > :last-child {\n margin-block-end: 0;\n }\n :host([data-theme='hc']) {\n --astl-author-ink: currentcolor;\n --astl-author-ground: transparent;\n }\n @container (max-inline-size: 30rem) {\n .canvas [style*='float'] {\n float: none !important;\n inline-size: auto !important;\n }\n .canvas [style*='margin']:not([style*='auto']) {\n margin-inline: 0 !important;\n }\n .canvas [style*='padding'] {\n padding-inline: min(var(--astl-space-3), 5%) !important;\n }\n .canvas img[style*='float'] {\n display: block;\n }\n }\n`.styleSheet;\n\n/** Adopts the stylesheet of styles and layouts in a player's root, once. */\nexport function adoptStyledSheet(root: Node): void {\n if (\n styledSheet !== undefined &&\n root instanceof ShadowRoot &&\n !root.adoptedStyleSheets.includes(styledSheet)\n ) {\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, styledSheet];\n }\n}\n"],"mappings":"A,6HAiCA,IAAMO,EAAe,IACfC,EAAY,8BACZC,EAAS,SACTC,EAAgC,IAAI,IAAI,CAAC,QAAS,YAAa,cAAe,iB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EAAS,IAAIE,EAAIL,CAAO,EACxBE,EAAM,IACJG,EACAd,EAAa,KAAK,CAACrC,EAAME,KAA6B,CAACF,EAAM4C,EAAQ5C,EAAME,EAAO4C,CAAO,CAAC,CAAC,CAC7F,CACF,CACA,OAAOE,CACT,CAGA,SAAgBO,EAAY,EAAoB,EAA4B,EAAiC,CAC3G,IAAMC,EAASC,EAAQ,iBAA8B,GAAG,EACxDL,EAAS,iBAAiB,GAAG,CAAC,CAAC,SAAS,EAAI,IAAU,CACpD,IAAK,GAAM,CAACpD,EAAME,KAAU8C,EAAM,IAAIG,CAAE,GAAK,CAAC,EAAGK,EAAOE,EAAM,EAAE,MAAM,YAAY1D,EAAME,CAAK,CAC/F,CAAC,CACH,CAMA,IAAMyD,EAAc,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDrB,WAGF,SAAgBC,EAAiB,EAAkB,CAE/CD,IAAgB,IAAA,IAChBE,aAAgB,YAChB,CAACA,EAAK,mBAAmB,SAASF,CAAW,IAE7C,EAAK,mBAAqB,CAAC,GAAGE,EAAK,mBAAoBF,CAAW,EAEtE,C"}
|
|
1
|
+
{"version":3,"file":"styled-bQqnDxBf.js","names":["i","tokens","INERT_STYLE","styleContrast","overStyleColor","cleanStyle","parseStyleColor","MIN_CONTRAST","RAW_COLOR","LENGTH","MEASURES","offWith","name","hex","value","DARK_SURFACE","DARK_INK","toHsl","red","green","blue","g","b","max","min","lightness","chroma","fromHsl","hue","saturation","a","channel","k","at","alpha","inverted","color","contrastOn","ink","ground","legible","l","reads","fails","step","middle","written","channels","declared","declarations","property","darkContext","inked","around","fill","dark","painted","raw","context","takeStyles","taken","contexts","page","el","fragment","up","known","applyStyles","copies","content","index","styledSheet","adoptStyledSheet","root"],"sources":["../../../../player/src/player/styled.ts"],"sourcesContent":["/**\n * Authors' styles and layouts in the player, in a module of its own: a view that has neither never loads it. Without it\n * (or when its chunk fails) `cleanView` removes every `style`, and the exercise plays unstyled.\n *\n * A view is engine output, and is still read as hostile here: each `style` goes through `cleanStyle` again. Declarations\n * are written with `el.style.setProperty`, on the mounted copy of the view: a strict CSP (`style-src 'self'`) blocks a\n * `style` attribute, and allows the CSSOM.\n *\n * What an author writes for a light page is changed in four ways, which is why nothing here is a plain copy:\n * - a colour becomes `light-dark(as written, lightness inverted)`, so it follows the player's `color-scheme`; text keeps\n * the nearest lightness that can be read on its ground, because inverting a colour of middle lightness changes nothing;\n * - in `hc` a colour resolves to `--astl-author-ink` or `--astl-author-ground`, set only there. A custom property, not\n * `!important` in the sheet, because it also reaches the copies components keep of their content in shadow roots;\n * - a font size is clamped: relative sizes compound through nesting;\n * - a width stays within its box: an inline `max-width` would beat any cap in a sheet.\n */\nimport { INERT_STYLE } from '@astl/core';\nimport {\n cleanStyle,\n overStyleColor,\n parseStyleColor,\n type StyleColor,\n type StyleDeclaration,\n styleContrast,\n} from '@astl/core/declarations';\nimport { tokens } from '@astl/tokens';\nimport { css } from 'lit';\n\n/**\n * The contrast text keeps on its ground in the dark: the one the engine asks of the light page (WCAG AA), and a little\n * more, because this module knows the theme's surfaces and not those of the looks, a shade lighter (a test holds the\n * built-in ones to 4.5).\n */\nconst MIN_CONTRAST = 4.6;\nconst RAW_COLOR = /#[0-9a-f]+|rgba?\\([^()]*\\)/g;\nconst LENGTH = /^[\\d.]/;\nconst MEASURES: ReadonlySet<string> = new Set(['width', 'max-width', 'inline-size', 'max-inline-size']);\n\n/** Off in `hc`: what is drawn on (a fill, a shadow) goes; what is drawn with (text, lines) takes the text colour. */\nconst offWith = (name: string): string =>\n name === 'background-color' || name === 'box-shadow' ? '--astl-author-ground' : '--astl-author-ink';\n\nconst hex = (value: string): StyleColor => parseStyleColor(value) as StyleColor;\n/** The lighter of the theme's surfaces: text sits on both. */\nconst DARK_SURFACE = hex(tokens.themes.dark['surface-raised']);\nconst DARK_INK = hex(tokens.themes.dark.ink);\n\n/** Hue (0 to 6), saturation and lightness (0 to 1). */\ntype Hsl = readonly [hue: number, saturation: number, lightness: number];\n\nfunction toHsl([red, green, blue]: StyleColor): Hsl {\n const [r, g, b] = [red / 255, green / 255, blue / 255];\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const lightness = (max + min) / 2;\n const chroma = max - min;\n if (chroma === 0) return [0, 0, lightness];\n const hue =\n max === r ? ((g - b) / chroma + 6) % 6 : max === g ? (b - r) / chroma + 2 : (r - g) / chroma + 4;\n return [hue, chroma / (1 - Math.abs(2 * lightness - 1)), lightness];\n}\n\nfunction fromHsl([hue, saturation, lightness]: Hsl, alpha: number): StyleColor {\n const a = saturation * Math.min(lightness, 1 - lightness);\n const channel = (at: number): number => {\n const k = (at + hue * 2) % 12;\n return Math.round((lightness - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))) * 255);\n };\n return [channel(0), channel(8), channel(4), alpha];\n}\n\n/** The author's lightness inverted, with hue and saturation kept. */\nfunction inverted(color: StyleColor): StyleColor {\n const [hue, saturation, lightness] = toHsl(color);\n return fromHsl([hue, saturation, 1 - lightness], color[3]);\n}\n\nconst contrastOn = (ink: StyleColor, ground: StyleColor): number =>\n styleContrast(overStyleColor(ink, ground), ground);\n\n/** `color` with the lightness nearest its own that can be read on `ground`, hue and saturation kept. */\nfunction legible(color: StyleColor, ground: StyleColor): StyleColor {\n if (contrastOn(color, ground) >= MIN_CONTRAST) return color;\n const [hue, saturation, lightness] = toHsl(color);\n const at = (l: number) => fromHsl([hue, saturation, l], color[3]);\n let reads = contrastOn(at(1), ground) >= contrastOn(at(0), ground) ? 1 : 0;\n let fails = lightness;\n for (let step = 0; step < 8; step++) {\n const middle = (reads + fails) / 2;\n if (contrastOn(at(middle), ground) >= MIN_CONTRAST) reads = middle;\n else fails = middle;\n }\n return at(reads);\n}\n\nconst written = ([red, green, blue, alpha]: StyleColor): string => {\n const channels = [red, green, blue].map(Math.round).join(', ');\n return alpha === 1 ? `rgb(${channels})` : `rgba(${channels}, ${alpha})`;\n};\n\n/** What is known of the dark theme at an element: the ground, and whether an author's colour is the text colour. */\ninterface DarkContext {\n readonly ground: StyleColor;\n readonly inked: boolean;\n}\n\nconst declared = (declarations: readonly StyleDeclaration[], name: string): StyleColor | null => {\n const value = declarations.find(([property]) => property === name)?.[1];\n return value === undefined ? null : parseStyleColor(value);\n};\n\n/** The dark theme at an element with these declarations, inside `around`. */\nfunction darkContext(declarations: readonly StyleDeclaration[], around: DarkContext): DarkContext {\n const inked = around.inked || declared(declarations, 'color') !== null;\n const fill = declared(declarations, 'background-color');\n if (fill === null) return { ground: around.ground, inked };\n const dark = overStyleColor(inverted(fill), around.ground);\n // Without an author's colour, the text is the theme's: the fill is what has to give way.\n return { ground: inked ? dark : legible(dark, DARK_INK), inked };\n}\n\n/** A declaration as it is written on the mounted element. */\nfunction painted(name: string, value: string, context: DarkContext): string {\n if (name === 'font-family') return value;\n if (name === 'font-size') return LENGTH.test(value) ? `clamp(0.625rem, ${value}, 6rem)` : value;\n if (MEASURES.has(name)) return LENGTH.test(value) && !value.endsWith('%') ? `min(${value}, 100%)` : value;\n return value.replace(RAW_COLOR, (raw) => {\n const color = hex(raw);\n const dark =\n name === 'color'\n ? legible(inverted(color), context.ground)\n : name === 'background-color'\n ? context.ground\n : inverted(color);\n return `var(${offWith(name)}, light-dark(${raw}, ${written(dark)}))`;\n });\n}\n\n/** Styles taken from a view, by element of the fragment, as they will be written. */\nexport type TakenStyles = ReadonlyMap<Element, readonly StyleDeclaration[]>;\n\n/** Takes every `style` (read under its parsing name) out of a read view, before `cleanView` removes what is left. */\nexport function takeStyles(fragment: DocumentFragment): TakenStyles {\n const taken = new Map<Element, readonly StyleDeclaration[]>();\n const contexts = new Map<Element, DarkContext>();\n const page: DarkContext = { ground: DARK_SURFACE, inked: false };\n // In document order, so what is around an element has been read before it.\n for (const el of Array.from(fragment.querySelectorAll(`[${INERT_STYLE}]`))) {\n const { declarations } = cleanStyle(el.getAttribute(INERT_STYLE) ?? '');\n el.removeAttribute(INERT_STYLE);\n let around = page;\n for (let up = el.parentElement; up !== null; up = up.parentElement) {\n const known = contexts.get(up);\n if (known !== undefined) {\n around = known;\n break;\n }\n }\n const context = darkContext(declarations, around);\n contexts.set(el, context);\n taken.set(\n el,\n declarations.map(([name, value]): StyleDeclaration => [name, painted(name, value, context)]),\n );\n }\n return taken;\n}\n\n/** Writes taken styles on `content`, the copy of the cleaned `fragment` that gets mounted: same shape, same order. */\nexport function applyStyles(taken: TakenStyles, fragment: DocumentFragment, content: DocumentFragment): void {\n const copies = content.querySelectorAll<HTMLElement>('*');\n fragment.querySelectorAll('*').forEach((el, index) => {\n for (const [name, value] of taken.get(el) ?? []) copies[index]?.style.setProperty(name, value);\n });\n}\n\n// Pages hold their floats. `:not([hidden])` because `.canvas astl-page` would otherwise beat `astl-page[hidden]`.\n// An author's `display` must not bring back what the player or a component hides.\n// A page never scrolls sideways whatever is nested in it: the caps stop one element, not ten inside each other.\n// On a narrow player only what an author set gives way, so a coloured word gets no padding; `auto` margins centre.\nconst styledSheet = css`\n .canvas {\n container-type: inline-size;\n }\n .canvas astl-doc,\n .canvas astl-page:not([hidden]) {\n display: flow-root;\n }\n .canvas astl-page {\n overflow-x: clip;\n overflow-clip-margin: var(--astl-space-5);\n }\n .canvas [style][hidden] {\n display: none !important;\n }\n .canvas [style] {\n box-sizing: border-box;\n max-inline-size: 100%;\n }\n .canvas astl-columns {\n display: flex;\n flex-wrap: wrap;\n clear: both;\n gap: var(--astl-space-4);\n margin-block-end: var(--astl-space-4);\n }\n .canvas astl-columns > astl-column {\n flex: 1 1 0;\n min-inline-size: min(10rem, 100%);\n }\n .canvas astl-columns > astl-column > :first-child {\n margin-block-start: 0;\n }\n .canvas astl-columns > astl-column > :last-child {\n margin-block-end: 0;\n }\n :host([data-theme='hc']) {\n --astl-author-ink: currentcolor;\n --astl-author-ground: transparent;\n }\n @container (max-inline-size: 30rem) {\n .canvas [style*='float'] {\n float: none !important;\n inline-size: auto !important;\n }\n .canvas [style*='margin']:not([style*='auto']) {\n margin-inline: 0 !important;\n }\n .canvas [style*='padding'] {\n padding-inline: min(var(--astl-space-3), 5%) !important;\n }\n .canvas img[style*='float'] {\n display: block;\n }\n }\n`.styleSheet;\n\n/** Adopts the stylesheet of styles and layouts in a player's root, once. */\nexport function adoptStyledSheet(root: Node): void {\n if (\n styledSheet !== undefined &&\n root instanceof ShadowRoot &&\n !root.adoptedStyleSheets.includes(styledSheet)\n ) {\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, styledSheet];\n }\n}\n"],"mappings":"A,6HAiCA,IAAMO,EAAe,IACfC,EAAY,8BACZC,EAAS,SACTC,EAAgC,IAAI,IAAI,CAAC,QAAS,YAAa,cAAe,iBAAiB,CAAC,EAGhGC,EAAW,GACfC,IAAS,oBAAsBA,IAAS,aAAe,uBAAyB,oBAE5EC,EAAO,GAA8BP,EAAgBQ,CAAK,EAE1DC,EAAeF,EAAIZ,EAAO,OAAO,KAAK,iBAAiB,EACvDe,EAAWH,EAAIZ,EAAO,OAAO,KAAK,GAAG,EAK3C,SAASgB,EAAM,CAACC,EAAKC,EAAOC,GAAwB,CAClD,GAAM,CAAC,EAAGC,EAAGC,GAAK,CAACJ,EAAM,IAAKC,EAAQ,IAAKC,EAAO,GAAG,EAC/CG,EAAM,KAAK,IAAI,EAAGF,EAAGC,CAAC,EACtBE,EAAM,KAAK,IAAI,EAAGH,EAAGC,CAAC,EACtBG,GAAaF,EAAMC,GAAO,EAC1BE,EAASH,EAAMC,EAIrB,OAHIE,IAAW,EAAU,CAAC,EAAG,EAAGD,CAAS,EAGlC,CADLF,IAAQ,IAAMF,EAAIC,GAAKI,EAAS,GAAK,EAAIH,IAAQF,GAAKC,EAAI,GAAKI,EAAS,GAAK,EAAIL,GAAKK,EAAS,EACpFA,GAAU,EAAI,KAAK,IAAI,EAAID,EAAY,CAAC,GAAIA,CAAS,CACpE,CAEA,SAASE,EAAQ,CAACC,EAAKC,EAAYJ,GAAiB,EAA2B,CAC7E,IAAMK,EAAID,EAAa,K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./runtime-
|
|
2
|
-
`)}\n}`)}var
|
|
1
|
+
import{D as e,E as t,M as n,Pt as r,_ as i,k as a,y as o}from"./runtime-C25QK5B0.js";import{t as s}from"./select-QZ35cyns.js";import"./messages-Qzse5KMX.js";var c=class extends o{static properties={authoring:{attribute:!1},adapter:{attribute:!1}};#e=null;constructor(){super(),this.authoring=null,this.adapter=null}connectedCallback(){super.connectedCallback(),this.#t()}disconnectedCallback(){super.disconnectedCallback(),this.#n()}willUpdate(e){e.has(`adapter`)&&this.#t()}#t(){let e=this.isConnected?this.adapter:null;if((this.#e?.adapter??null)===e||(this.#n(),e===null))return;let t=[e.onChange(()=>this.sourceChanged()),e.onSelectionChange(e=>this.selectionChanged(e)),e.onCursorChange?.(()=>this.cursorChanged())??(()=>{})];this.#e={adapter:e,off:()=>{for(let e of t)e()}}}#n(){this.#e?.off(),this.#e=null}sourceChanged(){this.requestUpdate()}selectionChanged(e){this.requestUpdate()}cursorChanged(){}t(e,t){return this.authoring?.t(`astl.editor`,e,t)??e}get ui(){let e=this.authoring?.locale??`en`;return{lang:e,dir:r(e)}}};function l(t){let r=[`color-scheme: inherit;`,...[n.scale,n.themes.light,n.themeScale.light].flatMap(Object.keys).map(e=>`--astl-${e}: inherit;`)];return e(`${t} {\n${r.join(`
|
|
2
|
+
`)}\n}`)}var u=[e(a(`:host`)),i,t`
|
|
3
3
|
:host {
|
|
4
4
|
display: block;
|
|
5
5
|
color: var(--astl-ink);
|
|
@@ -118,7 +118,7 @@ flex: none;
|
|
|
118
118
|
inline-size: 1.25rem;
|
|
119
119
|
block-size: 1.25rem;
|
|
120
120
|
}
|
|
121
|
-
`,t`
|
|
121
|
+
`,e(s(`select`)),t`
|
|
122
122
|
@media (forced-colors: active) {
|
|
123
123
|
button.primary {
|
|
124
124
|
border-color: ButtonText;
|
|
@@ -132,5 +132,5 @@ button.primary:not(:disabled) {
|
|
|
132
132
|
forced-color-adjust: none;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
`];export{
|
|
136
|
-
//# sourceMappingURL=styles-
|
|
135
|
+
`];export{u as n,c as r,l as t};
|
|
136
|
+
//# sourceMappingURL=styles-DiY3VA_T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles-DiY3VA_T.js","names":["LitElement","unsafeCSS","r","i$1","tokens","directionOf","visuallyHidden","tokensCss","i","nativeSelectCss","AuthoringElement","#subscribe","#unsubscribe","changed","adapter","#subscription","offs","selection","off","key","params","lang","inheritTokens","lines","name","selector","kitStyles"],"sources":["../../../../editor/src/elements/base.ts","../../../../editor/src/elements/styles.ts"],"sourcesContent":["import {\n type Direction,\n directionOf,\n type EditorAdapter,\n type EditorSelection,\n type MessageParams,\n} from '@astl/core';\nimport { LitElement, type PropertyDeclarations, type PropertyValues } from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { EDITOR_NAMESPACE } from '../messages.js';\n\n/**\n * Base of the kit elements: `authoring` and `adapter` properties, a subscription to the adapter's events while\n * connected (re-rendering by default) and UI strings in the authoring locale.\n */\nexport class AuthoringElement extends LitElement {\n static override properties: PropertyDeclarations = {\n authoring: { attribute: false },\n adapter: { attribute: false },\n };\n\n declare authoring: Authoring | null;\n declare adapter: EditorAdapter | null;\n\n #subscription: { readonly adapter: EditorAdapter; readonly off: () => void } | null = null;\n\n constructor() {\n super();\n this.authoring = null;\n this.adapter = null;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#subscribe();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#unsubscribe();\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('adapter')) this.#subscribe();\n }\n\n #subscribe(): void {\n const adapter = this.isConnected ? this.adapter : null;\n if ((this.#subscription?.adapter ?? null) === adapter) return;\n this.#unsubscribe();\n if (adapter === null) return;\n const offs = [\n adapter.onChange(() => this.sourceChanged()),\n adapter.onSelectionChange((selection) => this.selectionChanged(selection)),\n adapter.onCursorChange?.(() => this.cursorChanged()) ?? (() => {}),\n ];\n this.#subscription = {\n adapter,\n off: () => {\n for (const off of offs) off();\n },\n };\n }\n\n #unsubscribe(): void {\n this.#subscription?.off();\n this.#subscription = null;\n }\n\n /** The document changed. */\n protected sourceChanged(): void {\n this.requestUpdate();\n }\n\n /** The cursor entered or left a component. */\n protected selectionChanged(_selection: EditorSelection | null): void {\n this.requestUpdate();\n }\n\n /** The cursor moved, or the document or its history changed. Most elements have nothing to do. */\n protected cursorChanged(): void {}\n\n /** A kit message (`astl.editor`) in the authoring locale. */\n protected t(key: string, params?: MessageParams): string {\n return this.authoring?.t(EDITOR_NAMESPACE, key, params) ?? key;\n }\n\n /** Language and direction of the UI strings. */\n protected get ui(): { readonly lang: string; readonly dir: Direction } {\n const lang = this.authoring?.locale ?? 'en';\n return { lang, dir: directionOf(lang) };\n }\n}\n","import { visuallyHidden } from '@astl/player';\nimport { nativeSelectCss, tokens, tokensCss } from '@astl/tokens';\nimport { type CSSResult, type CSSResultGroup, css, unsafeCSS } from 'lit';\n\n/**\n * Every token as `inherit` on `selector`, for elements that redeclare the tokens on their own `:host` (the player): a\n * rule from the outer tree wins over `:host`, so tokens set on the kit element reach them.\n */\nexport function inheritTokens(selector: string): CSSResult {\n const names = [tokens.scale, tokens.themes.light, tokens.themeScale.light].flatMap(Object.keys);\n const lines = ['color-scheme: inherit;', ...names.map((name) => `--astl-${name}: inherit;`)];\n return unsafeCSS(`${selector} {\\n${lines.join('\\n')}\\n}`);\n}\n\n/** Shared look of the kit elements: a card, native controls with 44px targets, visible focus. Tokens only. */\nexport const kitStyles: CSSResultGroup = [\n // Tokens sit on :host so host pages can override any --astl-* property on the element itself.\n unsafeCSS(tokensCss(':host')),\n visuallyHidden,\n css`\n :host {\n display: block;\n color: var(--astl-ink);\n font-family: var(--astl-font-body);\n font-size: var(--astl-size-ui);\n line-height: 1.4;\n }\n :host([hidden]) {\n display: none;\n }\n .kit {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n min-inline-size: 0;\n padding: var(--astl-space-4);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n color: var(--astl-ink);\n overflow-wrap: anywhere;\n }\n .title {\n margin: 0;\n font-family: var(--astl-font-display);\n font-size: 1.125rem;\n line-height: 1.3;\n }\n .note {\n margin: 0;\n color: var(--astl-ink-muted);\n }\n ul {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n button {\n box-sizing: border-box;\n display: inline-flex;\n align-items: center;\n gap: var(--astl-space-2);\n min-block-size: var(--astl-target-min);\n min-inline-size: var(--astl-target-min);\n margin: 0;\n padding-block: var(--astl-space-2);\n padding-inline: var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-m);\n background: var(--astl-surface);\n color: var(--astl-ink);\n font: inherit;\n text-align: start;\n cursor: pointer;\n }\n button:hover:not(:disabled) {\n background: var(--astl-accent-soft);\n }\n `,\n // Disabled shows without colour too: a dashed border and no fill. In the high contrast theme the line and muted\n // colours are as dark as the enabled ones. Disabled (no editor yet), the primary button must not look pressable.\n css`\n button:is(:disabled, [aria-disabled='true']) {\n border-color: var(--astl-line);\n border-style: dashed;\n background: transparent;\n color: var(--astl-ink-muted);\n cursor: not-allowed;\n }\n button.primary {\n border-color: var(--astl-accent);\n background: var(--astl-accent);\n color: var(--astl-on-accent);\n font-weight: 600;\n }\n button.primary:hover:not(:disabled) {\n background: var(--astl-accent);\n text-decoration: underline;\n }\n button.primary:disabled {\n border-color: var(--astl-line);\n background: transparent;\n color: var(--astl-ink-muted);\n }\n input:not([type='checkbox'], [type='radio']),\n select,\n textarea {\n box-sizing: border-box;\n inline-size: 100%;\n min-inline-size: 0;\n min-block-size: var(--astl-target-min);\n margin: 0;\n padding-block: var(--astl-space-1);\n padding-inline: var(--astl-space-2);\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-s);\n background: var(--astl-surface);\n color: var(--astl-ink);\n font: inherit;\n }\n input[type='checkbox'],\n input[type='radio'] {\n flex: none;\n inline-size: 1.25rem;\n block-size: 1.25rem;\n margin: 0;\n accent-color: var(--astl-accent);\n }\n :focus-visible {\n outline: var(--astl-focus-width) solid var(--astl-focus);\n outline-offset: var(--astl-focus-offset);\n }\n .icon {\n flex: none;\n inline-size: 1.25rem;\n block-size: 1.25rem;\n }\n `,\n // A select's chevron of its own, inset from the end like the dropdown's, after the fields' padding and background.\n unsafeCSS(nativeSelectCss('select')),\n // Forced colours: disabled as the system draws disabled controls (the dashed border stays). The Canvas backplate\n // forced colours draw behind text would hide the HighlightText label on the Highlight fill, so the primary button\n // uses only system colours here and keeps its own. Disabled, it stays forced: its muted label would not read on the\n // fill.\n css`\n @media (forced-colors: active) {\n button.primary {\n border-color: ButtonText;\n }\n button:disabled,\n button.primary:disabled {\n border-color: GrayText;\n color: GrayText;\n }\n button.primary:not(:disabled) {\n forced-color-adjust: none;\n }\n }\n `,\n];\n"],"mappings":"A,6JAeA,IAAaU,EAAb,cAAsCV,CAAW,CAC/C,OAAgB,WAAmC,CACjD,UAAW,CAAE,UAAW,EAAM,EAC9B,QAAS,CAAE,UAAW,EAAM,CAC9B,EAKA,GAAsF,KAEtF,aAAc,CACZ,MAAM,EACN,KAAK,UAAY,KACjB,KAAK,QAAU,IACjB,CAEA,mBAAmC,CACjC,MAAM,kBAAkB,EACxB,KAAKW,GAAW,CAClB,CAEA,sBAAsC,CACpC,MAAM,qBAAqB,EAC3B,KAAKC,GAAa,CACpB,CAEA,WAA8B,EAAqC,CAC7DC,EAAQ,IAAI,SAAS,GAAG,KAAKF,GAAW,CAC9C,CAEA,IAAmB,CACjB,IAAMG,EAAU,KAAK,YAAc,KAAK,QAAU,KAGlD,IAFK,KAAKC,IAAe,SAAW,QAAUD,IAC9C,KAAKF,GAAa,EACdE,IAAY,MAAM,OACtB,IAAME,EAAO,CACXF,EAAQ,aAAe,KAA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