@astl/astrolabe 0.1.3 → 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 +14 -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 +1084 -1075
- 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-DhIyMziw.js → help-form-Di2NtKDp.js} +2 -2
- package/dist/cdn/chunks/{help-form-DhIyMziw.js.map → help-form-Di2NtKDp.js.map} +1 -1
- 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-Cn2E54V9.js → insert-menu-DAQglwtG.js} +2 -2
- package/dist/cdn/chunks/{insert-menu-Cn2E54V9.js.map → insert-menu-DAQglwtG.js.map} +1 -1
- package/dist/cdn/chunks/{issue-list-CQKAW39i.js → issue-list-CzSmohtT.js} +2 -2
- package/dist/cdn/chunks/{issue-list-CQKAW39i.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/{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-BlJ2mRns.js → source-view-gqFlZzwR.js} +2 -2
- package/dist/cdn/chunks/{source-view-BlJ2mRns.js.map → source-view-gqFlZzwR.js.map} +1 -1
- package/dist/cdn/chunks/{style-form-D1C2sHzg.js → style-form-DuR0EEum.js} +2 -2
- package/dist/cdn/chunks/{style-form-D1C2sHzg.js.map → style-form-DuR0EEum.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-ChqPVgZn.js → style-rules-ozpLz2ec.js} +2 -2
- package/dist/cdn/chunks/{style-rules-ChqPVgZn.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-CXkkL_Qi.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/match-DKE_4o-x.js.map +0 -1
- package/dist/cdn/chunks/styles-CXkkL_Qi.js.map +0 -1
- package/dist/cdn/chunks/surface-BhmSAte0.js +0 -1058
- package/dist/cdn/chunks/surface-BhmSAte0.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-form-D1C2sHzg.js","names":["live","nothing","b","i","A","mergeStyles","MAX_STYLE_LENGTH","styleText","LAYOUT_SHAPES","kitStyles","AuthoringElement","l","positionChanges","widthChanges","positionOf","PLACEMENTS","styleMessages","colorStyles","colorControl","FONT","WIDTH","POSITION","TEXT_FIELDS","BOX_FIELDS","SPACING_FIELDS","sectionsOf","text","box","spacing","place","kind","inFigure","refusals","style","removed","STYLE_PROPERTIES","name","numberIn","match","value","number","written","unit","AstlStyleForm","changed","key","#element","#shown","#askDelete","#refused","#draft","#badColors","#revealRefused","note","targets","#styles","one","rule","styles","#currentRule","gone","changes","adding","cleanStyle","element","property","#write","clean","field","id","at","label","#fieldLabel","declared","shown","event","#commit","next","option","fonts","other","font","position","params","reason","named","own","ready","preset","#saveLabel","#save","edit","state","ask","#editLayout","shape","lang","dir","sections","layout","#layout","section","fields","#field","#named","#applyOwn","#refusedList"],"sources":["../../../../editor/src/elements/style-form.ts"],"sourcesContent":["import type {\n EditorLayoutEdit,\n EditorLayoutShape,\n EditorStyleChanges,\n EditorStyleRule,\n EditorStyleTarget,\n EditorStyleTargetKind,\n} from '@astl/core';\nimport {\n cleanStyle,\n MAX_STYLE_LENGTH,\n mergeStyles,\n STYLE_PROPERTIES,\n styleText,\n} from '@astl/core/declarations';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n} from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { styleMessages } from '../style-messages.js';\nimport { LAYOUT_SHAPES } from '../style-model.js';\nimport { PLACEMENTS, type Placement, positionChanges, positionOf, widthChanges } from '../style-placing.js';\nimport { AuthoringElement } from './base.js';\nimport { colorControl, colorStyles } from './color-control.js';\nimport { kitStyles } from './styles.js';\n\n/** A field of the form, table-driven: one property, with the control its values ask for. */\ntype Field =\n | {\n readonly kind: 'number';\n readonly property: string;\n readonly unit: 'px' | '%' | '';\n readonly min: number;\n readonly max: number;\n readonly step?: number;\n }\n | { readonly kind: 'select'; readonly property: string; readonly options: readonly string[] }\n | { readonly kind: 'font'; readonly property: 'font-family' }\n | { readonly kind: 'color'; readonly property: string }\n | { readonly kind: 'position'; readonly property: 'position' };\n\ntype Section = 'text' | 'box' | 'spacing' | 'size';\n\nconst FONT: Field = { kind: 'font', property: 'font-family' };\nconst WIDTH: Field = { kind: 'number', property: 'width', unit: '%', min: 1, max: 100 };\nconst POSITION: Field = { kind: 'position', property: 'position' };\n\nconst TEXT_FIELDS: readonly Field[] = [\n FONT,\n { kind: 'number', property: 'font-size', unit: 'px', min: 10, max: 96 },\n { kind: 'select', property: 'font-weight', options: ['normal', 'bold'] },\n { kind: 'select', property: 'font-style', options: ['normal', 'italic'] },\n { kind: 'color', property: 'color' },\n { kind: 'select', property: 'text-align', options: ['start', 'center', 'end', 'justify'] },\n { kind: 'number', property: 'line-height', unit: '', min: 0.8, max: 4, step: 0.05 },\n];\nconst BOX_FIELDS: readonly Field[] = [\n { kind: 'color', property: 'background-color' },\n { kind: 'number', property: 'border-width', unit: 'px', min: 0, max: 16 },\n { kind: 'select', property: 'border-style', options: ['none', 'solid', 'dashed', 'dotted', 'double'] },\n { kind: 'color', property: 'border-color' },\n { kind: 'number', property: 'border-radius', unit: 'px', min: 0, max: 128 },\n];\nconst SPACING_FIELDS: readonly Field[] = [\n { kind: 'number', property: 'padding', unit: 'px', min: 0, max: 64 },\n { kind: 'number', property: 'margin-block-start', unit: 'px', min: 0, max: 128 },\n { kind: 'number', property: 'margin-block-end', unit: 'px', min: 0, max: 128 },\n];\n\n/** What each kind of element can sensibly change, in the order it comes to mind; the first section starts open. */\nconst sectionsOf = (\n kind: EditorStyleTargetKind | 'tag' | 'named',\n inFigure: boolean,\n): readonly (readonly [Section, readonly Field[]])[] => {\n const text: [Section, readonly Field[]] = ['text', TEXT_FIELDS];\n const box: [Section, readonly Field[]] = ['box', BOX_FIELDS];\n const spacing: [Section, readonly Field[]] = ['spacing', SPACING_FIELDS];\n const place: [Section, readonly Field[]] = ['size', [POSITION, WIDTH]];\n switch (kind) {\n case 'picture':\n // A figure's picture fills the figure, which is what sits on the page.\n return inFigure ? [box] : [place, box];\n case 'figure':\n return [place, box, spacing, text];\n case 'layout':\n return [\n [\n 'size',\n [\n { kind: 'number', property: 'gap', unit: 'px', min: 0, max: 64 },\n {\n kind: 'select',\n property: 'align-items',\n options: ['stretch', 'start', 'center', 'end'],\n },\n ],\n ],\n box,\n spacing,\n text,\n ];\n case 'column':\n return [\n ['size', [{ kind: 'number', property: 'flex-grow', unit: '', min: 0, max: 12 }]],\n box,\n spacing,\n text,\n ];\n case 'component':\n // Placed as a picture is: an exercise can float with text beside it.\n return [text, box, spacing, place];\n case 'named':\n case 'block':\n return [text, box, spacing, ['size', [WIDTH]]];\n default:\n return [text, box, spacing];\n }\n};\n\n/** A refused declaration, with the reason a message says. */\ninterface Refusal {\n readonly name: string;\n readonly reason: 'property' | 'value' | 'text' | 'length';\n}\n\n/** Why the allow-list refused a declaration, from the name `cleanStyle` reports. */\nfunction refusals(style: string, removed: readonly string[]): readonly Refusal[] {\n if (style.length > MAX_STYLE_LENGTH) return [{ name: 'style', reason: 'length' }];\n return removed.map((name) => ({\n name,\n reason: STYLE_PROPERTIES.includes(name)\n ? 'value'\n : /^-{0,2}[a-z][a-z-]*$/.test(name)\n ? 'property'\n : 'text',\n }));\n}\n\n/** A number in the field's unit, or null for what the field cannot show (it says it as a placeholder). */\nconst numberIn = (value: string | undefined, unit: string): string | null => {\n const match = /^(\\d*\\.?\\d+)([a-z%]*)$/.exec(value ?? '');\n if (match === null) return null;\n const [, number, written] = match;\n return written === unit || number === '0' || (unit === '' && written === '') ? (number as string) : null;\n};\n\n/**\n * `<astl-style-form>`: the style of an element at the cursor (`target`, or what the cursor is innermost in), or of a\n * rule of the document (`rule`): text, background and border, spacing, size and position, the named style, and \"Own\n * CSS\", which says what the allow-list refused and why. \"Save as a style\" makes the element's own style a named one.\n * Each commit of a field (a `change`) is one undo step, and the focus stays in the form. The adapter's `style`\n * (`EditorStyles`) does the work; without it the form says so. Comes with `loadStyleElements`, on first use.\n */\nexport class AstlStyleForm extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n target: {},\n rule: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n colorStyles,\n // A summary stays a list item, which keeps the marker that says it opens; its padding makes the line a target. The\n // layout's commands go in a row from the start, wrapping when narrow; its question has a line of its own.\n css`\n .form {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n }\n details {\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n summary {\n box-sizing: border-box;\n min-block-size: var(--astl-target-min);\n padding-block: calc((var(--astl-target-min) - 1lh) / 2);\n padding-inline: var(--astl-space-3);\n font-weight: 600;\n cursor: pointer;\n }\n .fields {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));\n gap: var(--astl-space-3);\n padding: var(--astl-space-3);\n padding-block-start: var(--astl-space-1);\n }\n .field {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n }\n .field.wide,\n .fields > fieldset {\n grid-column: 1 / -1;\n }\n fieldset {\n margin: 0;\n padding: 0;\n border: 0;\n min-inline-size: 0;\n }\n legend,\n label {\n padding: 0;\n font-weight: 600;\n }\n legend {\n margin-block-end: var(--astl-space-1);\n }\n .unit {\n display: flex;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .unit span {\n flex: none;\n color: var(--astl-ink-muted);\n }\n textarea {\n font-family: var(--astl-font-mono, monospace);\n font-size: var(--astl-size-small);\n }\n .refused {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .refused ul {\n gap: var(--astl-space-1);\n }\n .save {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n gap: var(--astl-space-2);\n align-items: end;\n }\n .save label {\n grid-column: 1 / -1;\n }\n .layout {\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-2);\n }\n .layout [role='alert'] {\n flex-basis: 100%;\n }\n `,\n ];\n\n /** What the form styles, of what the cursor is in; null: the innermost. */\n declare target: EditorStyleTargetKind | null;\n /** A rule to edit in place of an element: by its `name`, or `for` a tag. */\n declare rule: Pick<EditorStyleRule, 'name' | 'for'> | null;\n\n /** The refused declarations of the last edit: shown until the next one. */\n #refused: readonly Refusal[] = [];\n /** New refusals to bring into view: in a host's card or sheet the form is taller than its box. */\n #revealRefused = false;\n /** Colour fields whose typed colour was refused. */\n #badColors = new Set<string>();\n /** The field's text when it was refused, kept so the author can correct it. */\n #draft: string | null = null;\n #saveLabel = '';\n /** What the form was last showing: moving to another element forgets the last refusals. */\n #shown = '';\n /** \"Delete with content\" was pressed on a layout that holds some: the form asks first. */\n #askDelete = false;\n\n constructor() {\n super();\n this.target = null;\n this.rule = null;\n }\n\n protected override cursorChanged(): void {\n this.requestUpdate();\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring')) this.authoring?.addMessages(styleMessages);\n const key =\n this.rule === null ? (this.#element()?.kind ?? '') : `rule ${this.rule.name ?? this.rule.for}`;\n if (key !== this.#shown) {\n this.#askDelete = false;\n this.#refused = [];\n this.#draft = null;\n this.#badColors.clear();\n }\n this.#shown = key;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n if (!this.#revealRefused) return;\n this.#revealRefused = false;\n const note = this.renderRoot.querySelector('#own-refused');\n note?.closest('details')?.setAttribute('open', '');\n note?.scrollIntoView({ block: 'nearest' });\n }\n\n #styles() {\n return this.adapter?.style ?? null;\n }\n\n #element(): EditorStyleTarget | null {\n const targets = this.#styles()?.state().targets ?? [];\n return (this.target === null ? targets[0] : targets.find((one) => one.kind === this.target)) ?? null;\n }\n\n #currentRule(): EditorStyleRule | null {\n const rule = this.rule;\n if (rule === null) return null;\n return (\n this.#styles()\n ?.rules()\n .find((one) => (rule.name !== undefined ? one.name === rule.name : one.for === rule.for)) ?? {\n ...(rule.name === undefined ? {} : { name: rule.name }),\n ...(rule.for === undefined ? {} : { for: rule.for }),\n style: '',\n }\n );\n }\n\n #write(changes: EditorStyleChanges): void {\n const styles = this.#styles();\n if (styles === null) return;\n const rule = this.#currentRule();\n if (rule !== null) {\n const gone = new Set(Object.keys(changes));\n const adding = cleanStyle(\n Object.entries(changes)\n .flatMap(([name, value]) => (value === null ? [] : [`${name}: ${value}`]))\n .join('; '),\n ).declarations;\n const style = styleText(\n mergeStyles(\n cleanStyle(rule.style).declarations.filter(([name]) => !gone.has(name)),\n adding,\n ),\n );\n styles.setRule({ ...rule, style });\n } else {\n const element = this.#element();\n if (element !== null) styles.setTarget(element.kind, changes);\n }\n this.#refused = [];\n this.#draft = null;\n this.requestUpdate();\n }\n\n /** One field's value: what the allow-list refuses is said, not written. */\n #commit(property: string, value: string | null): void {\n if (value !== null) {\n const { removed } = cleanStyle(`${property}: ${value}`);\n if (removed.length > 0) {\n this.#refused = refusals('', removed);\n this.#revealRefused = true;\n this.requestUpdate();\n return;\n }\n }\n this.#write({ [property]: value });\n }\n\n /** The \"Own CSS\" field: what the allow-list keeps is the new style, what it refuses is said and never written. */\n #applyOwn(text: string): void {\n const styles = this.#styles();\n if (styles === null) return;\n const clean = cleanStyle(text);\n const rule = this.#currentRule();\n if (rule !== null) styles.setRule({ ...rule, style: clean.style });\n else {\n const element = this.#element();\n if (element !== null) styles.replaceTarget(element.kind, clean.style);\n }\n this.#refused = refusals(text, clean.removed);\n this.#revealRefused = this.#refused.length > 0;\n // The field then shows what stays; the refusals say what went.\n this.#draft = null;\n this.requestUpdate();\n }\n\n #fieldLabel(field: Field): string {\n return this.t(`style.field.${field.property}`);\n }\n\n #field(field: Field, declared: ReadonlyMap<string, string>, style: string, at: string): TemplateResult {\n const id = `${at}-${field.property}`;\n const label = this.#fieldLabel(field);\n const value = declared.get(field.property);\n switch (field.kind) {\n case 'number': {\n const shown = numberIn(value, field.unit);\n return html`<div class=\"field\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <div class=\"unit\">\n <input\n id=${id}\n type=\"number\"\n inputmode=\"decimal\"\n data-property=${field.property}\n min=${field.min}\n max=${field.max}\n step=${field.step ?? 1}\n placeholder=${shown === null ? (value ?? '') : ''}\n .value=${live(shown ?? '')}\n @change=${(event: Event) => {\n const text = (event.target as HTMLInputElement).value.trim();\n // The field writes what the corner handle writes.\n if (\n field.property === 'width' &&\n text !== '' &&\n cleanStyle(`width: ${text}%`).removed.length === 0\n )\n this.#write(widthChanges(style, Number(text)));\n else this.#commit(field.property, text === '' ? null : `${text}${field.unit}`);\n }}\n />\n ${field.unit === '' ? nothing : html`<span aria-hidden=\"true\">${field.unit}</span>`}\n </div>\n </div>`;\n }\n case 'select':\n return html`<div class=\"field\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=${field.property}\n .value=${live(value ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n this.#commit(field.property, next === '' ? null : next);\n }}\n >\n <option value=\"\">${this.t('toolbar.default')}</option>\n ${field.options.map(\n (option) =>\n html`<option value=${option} ?selected=${option === value}>${this.t(`style.value.${option}`)}</option>`,\n )}\n </select>\n </div>`;\n case 'font': {\n const fonts = this.authoring?.fonts ?? [];\n const other = value !== undefined && !fonts.some((font) => font.stack === value);\n return html`<div class=\"field wide\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=${field.property}\n .value=${live(value ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n this.#commit(field.property, next === '' ? null : next);\n }}\n >\n <option value=\"\">${this.t('toolbar.default')}</option>\n ${fonts.map(\n (font) =>\n html`<option value=${font.stack} ?selected=${font.stack === value}>${font.name}</option>`,\n )}\n ${other ? html`<option value=${value} selected>${value}</option>` : nothing}\n </select>\n </div>`;\n }\n case 'position': {\n const position = positionOf(style);\n return html`<div class=\"field wide\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=\"position\"\n .value=${live(position)}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value as Placement;\n this.#write(positionChanges(next, style, this.#element()?.kind === 'figure'));\n }}\n >\n ${PLACEMENTS.map(\n (one) =>\n html`<option value=${one} ?selected=${one === position}>${this.t(`style.position.${one}`)}</option>`,\n )}\n </select>\n </div>`;\n }\n case 'color':\n return html`<fieldset part=\"field\" data-property=${field.property}>\n <legend part=\"label\">${label}</legend>\n ${colorControl({\n id,\n value: value ?? null,\n t: (key, params) => this.t(key, params),\n invalid: this.#badColors.has(field.property),\n ground: field.property === 'background-color',\n pick: (next) => {\n this.#badColors.delete(field.property);\n this.#commit(field.property, next);\n },\n refuse: () => {\n this.#badColors.add(field.property);\n this.requestUpdate();\n },\n })}\n </fieldset>`;\n }\n }\n\n #refusedList(): TemplateResult | typeof nothing {\n if (this.#refused.length === 0) return nothing;\n return html`<div class=\"refused\" id=\"own-refused\">\n <ul>\n ${this.#refused.map(\n ({ name, reason }) =>\n html`<li data-refused=${name}>${this.t(`style.refused.${reason}`, { name, max: MAX_STYLE_LENGTH })}</li>`,\n )}\n </ul>\n </div>`;\n }\n\n /** The named style of the element, the ready styles the document does not have yet, and saving its own style as one. */\n #named(element: EditorStyleTarget): TemplateResult {\n const named = (this.#styles()?.rules() ?? []).filter((rule) => rule.name !== undefined);\n const own = new Set(named.map((rule) => rule.name));\n const ready = (this.authoring?.styles ?? []).filter((preset) => !own.has(preset.name));\n return html`<details part=\"section\" data-section=\"named\">\n <summary>${this.t('style.section.named')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"named\" part=\"label\">${this.t('style.field.named')}</label>\n <select\n id=\"named\"\n .value=${live(element.className ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n const preset = ready.find((one) => one.name === next);\n // A ready style brings its rule, labelled as the author reads it now, in the same undo step.\n if (preset !== undefined)\n this.#styles()?.setClass(element.kind, next, {\n name: next,\n label: preset.label,\n style: preset.style,\n });\n else this.#styles()?.setClass(element.kind, next === '' ? null : next);\n this.requestUpdate();\n }}\n >\n <option value=\"\">${this.t('style.named.none')}</option>\n ${named.map(\n (rule) =>\n html`<option value=${rule.name ?? ''} ?selected=${rule.name === element.className}>${rule.label ?? rule.name}</option>`,\n )}\n ${\n ready.length === 0\n ? nothing\n : html`<optgroup label=${this.t('toolbar.readyStyles')}>\n ${ready.map(\n (preset) =>\n html`<option value=${preset.name} ?selected=${preset.name === element.className}>${preset.label}</option>`,\n )}\n </optgroup>`\n }\n </select>\n </div>\n <div class=\"save field wide\">\n <label for=\"save-label\" part=\"label\">${this.t('style.save.label')}</label>\n <input\n id=\"save-label\"\n type=\"text\"\n autocomplete=\"off\"\n .value=${this.#saveLabel}\n @input=${(event: Event) => {\n this.#saveLabel = (event.target as HTMLInputElement).value;\n }}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n this.#save(element);\n }\n }}\n />\n <button type=\"button\" data-save @click=${() => this.#save(element)}>${this.t('style.save')}</button>\n </div>\n </div>\n </details>`;\n }\n\n #save(element: EditorStyleTarget): void {\n const label = this.#saveLabel.trim();\n if (label === '') {\n this.renderRoot.querySelector<HTMLInputElement>('#save-label')?.focus();\n return;\n }\n if (this.#styles()?.saveRule(element.kind, label) !== null) this.#saveLabel = '';\n this.requestUpdate();\n }\n\n #editLayout(edit: EditorLayoutEdit): void {\n this.#askDelete = false;\n this.#styles()?.editLayout?.(edit);\n this.requestUpdate();\n }\n\n /**\n * The layout's own commands, first in its form and open: another shape, its columns removed with their content kept,\n * or deleted with it, which asks first when there is content to lose. Its style sections follow, closed.\n */\n #layout(): TemplateResult | typeof nothing {\n const styles = this.#styles();\n const state = styles?.layout?.() ?? null;\n if (styles?.editLayout === undefined || state === null) return nothing;\n const ask = this.#askDelete;\n return html`<details open part=\"section\" data-section=\"layout\">\n <summary>${this.t('layout.section')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"layout-shape\" part=\"label\">${this.t('layout.change')}</label>\n <select\n id=\"layout-shape\"\n @change=${(event: Event) => {\n const value = (event.target as HTMLSelectElement).value;\n if (value !== '') this.#editLayout(value as EditorLayoutShape);\n }}\n >\n ${state.shape === null ? html`<option value=\"\" selected>${this.t('layout.other')}</option>` : nothing}\n ${LAYOUT_SHAPES.map(\n (shape) =>\n html`<option value=${shape} ?selected=${shape === state.shape}>\n ${this.t(`insert.layout.${shape}`)}\n </option>`,\n )}\n </select>\n </div>\n <div class=\"layout wide field\" role=\"group\" aria-label=${this.t('layout.section')}>\n ${\n ask\n ? html`<span role=\"alert\">${this.t('layout.confirm')}</span>\n <button type=\"button\" @click=${() => this.#editLayout('delete')}>\n ${this.t('layout.confirmDelete')}\n </button>\n <button\n type=\"button\"\n data-cancel\n @click=${() => {\n this.#askDelete = false;\n this.requestUpdate();\n }}\n >\n ${this.t('layout.cancel')}\n </button>`\n : html`<button type=\"button\" @click=${() => this.#editLayout('unwrap')}>\n ${this.t('layout.unwrap')}\n </button>\n <button\n type=\"button\"\n @click=${() => {\n if (state.empty) this.#editLayout('delete');\n else {\n this.#askDelete = true;\n this.requestUpdate();\n void this.updateComplete.then(() =>\n this.renderRoot.querySelector<HTMLElement>('[data-cancel]')?.focus(),\n );\n }\n }}\n >\n ${this.t('layout.delete')}\n </button>`\n }\n </div>\n </div>\n </details>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const styles = this.#styles();\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const rule = this.#currentRule();\n const element = rule === null ? this.#element() : null;\n if (styles === null || (rule === null && element === null)) {\n return html`<p class=\"note\" lang=${lang} dir=${dir}>${this.t('style.form.none')}</p>`;\n }\n const style = rule?.style ?? element?.style ?? '';\n const declared = new Map(cleanStyle(style).declarations);\n const inFigure =\n element?.kind === 'picture' && styles.state().targets.some((one) => one.kind === 'figure');\n const kind =\n rule === null\n ? (element?.kind as EditorStyleTargetKind)\n : rule.name !== undefined\n ? 'named'\n : rule.for === 'img'\n ? 'picture'\n : 'tag';\n const sections = sectionsOf(kind, inFigure);\n const own = this.#draft ?? style;\n // A layout's form starts with its commands; then its style, closed.\n const layout = element?.kind === 'layout';\n return html`<div class=\"form\" part=\"root\" lang=${lang} dir=${dir} data-kind=${kind}>\n ${layout ? this.#layout() : nothing}\n ${sections.map(\n (\n [section, fields],\n at,\n ) => html`<details ?open=${at === 0 && !layout} part=\"section\" data-section=${section}>\n <summary>${this.t(`style.section.${section}`)}</summary>\n <div class=\"fields\">${fields.map((field) => this.#field(field, declared, style, section))}</div>\n </details>`,\n )}\n ${element === null ? nothing : this.#named(element)}\n <details ?open=${!layout} part=\"section\" data-section=\"own\">\n <summary>${this.t('style.section.own')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"own\" part=\"label\">${this.t('style.field.own')}</label>\n <textarea\n id=\"own\"\n rows=\"3\"\n spellcheck=\"false\"\n placeholder=\"background-color: #fff3cd; padding: 12px\"\n aria-describedby=${this.#refused.length > 0 ? 'own-refused' : nothing}\n .value=${live(own)}\n @change=${(event: Event) => this.#applyOwn((event.target as HTMLTextAreaElement).value)}\n ></textarea>\n <div role=\"alert\">${this.#refusedList()}</div>\n </div>\n </div>\n </details>\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-style-form': AstlStyleForm;\n }\n}\n"],"mappings":"A,2aAiDA,IAAMmB,EAAc,CAAE,KAAM,OAAQ,SAAU,aAAc,EACtDC,EAAe,CAAE,KAAM,SAAU,SAAU,QAAS,KAAM,IAAK,IAAK,EAAG,IAAK,GAAI,EAChFC,EAAkB,CAAE,KAAM,WAAY,SAAU,UAAW,EAE3DC,EAAgC,CACpCH,EACA,CAAE,KAAM,SAAU,SAAU,YAAa,KAAM,KA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OC,EAAI,aAAanE,EAAK;QAC/EqE,EAAS,KAAKC,GAAQ,EAAInG,EAAQ;QAClCiG,EAAS,KAEP,CAACG,EAASC,GACV,IACG,CAAI,kBAAkBhC,IAAO,GAAK,CAAC6B,EAAO,+BAA+BE,EAAQ;qBACzE,KAAK,EAAE,iBAAiBA,GAAS,EAAE;gCACxBC,EAAO,IAAK,GAAU,KAAKC,GAAOnC,EAAOK,EAAUxC,EAAOoE,CAAO,CAAC,EAAE;mBAE9F,EAAE;QACArC,IAAY,KAAO/D,EAAU,KAAKuG,GAAOxC,CAAO,EAAE;uBACnC,CAACmC,EAAO;mBACZ,KAAK,EAAE,mBAAmB,EAAE;;;4CAGH,KAAK,EAAE,iBAAiB,EAAE;;;;;;iCAMrC,KAAKlD,GAAS,OAAS,EAAI,cAAgBhD,EAAQ;uBAC7DD,EAAKsF,CAAG,EAAE;wBACR,GAAiB,KAAKmB,GAAW9B,EAAM,OAA+B,KAAK,EAAE;;gCAEtE,KAAK+B,GAAa,EAAE;;;;WAKlD,CACF,E"}
|
|
1
|
+
{"version":3,"file":"style-form-DuR0EEum.js","names":["live","nothing","b","i","A","mergeStyles","MAX_STYLE_LENGTH","styleText","LAYOUT_SHAPES","kitStyles","AuthoringElement","l","positionChanges","widthChanges","positionOf","PLACEMENTS","styleMessages","colorStyles","colorControl","FONT","WIDTH","POSITION","TEXT_FIELDS","BOX_FIELDS","SPACING_FIELDS","sectionsOf","text","box","spacing","place","kind","inFigure","refusals","style","removed","STYLE_PROPERTIES","name","numberIn","match","value","number","written","unit","AstlStyleForm","changed","key","#element","#shown","#askDelete","#refused","#draft","#badColors","#revealRefused","note","targets","#styles","one","rule","styles","#currentRule","gone","changes","adding","cleanStyle","element","property","#write","clean","field","id","at","label","#fieldLabel","declared","shown","event","#commit","next","option","fonts","other","font","position","params","reason","named","own","ready","preset","#saveLabel","#save","edit","state","ask","#editLayout","shape","lang","dir","sections","layout","#layout","section","fields","#field","#named","#applyOwn","#refusedList"],"sources":["../../../../editor/src/elements/style-form.ts"],"sourcesContent":["import type {\n EditorLayoutEdit,\n EditorLayoutShape,\n EditorStyleChanges,\n EditorStyleRule,\n EditorStyleTarget,\n EditorStyleTargetKind,\n} from '@astl/core';\nimport {\n cleanStyle,\n MAX_STYLE_LENGTH,\n mergeStyles,\n STYLE_PROPERTIES,\n styleText,\n} from '@astl/core/declarations';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n} from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { styleMessages } from '../style-messages.js';\nimport { LAYOUT_SHAPES } from '../style-model.js';\nimport { PLACEMENTS, type Placement, positionChanges, positionOf, widthChanges } from '../style-placing.js';\nimport { AuthoringElement } from './base.js';\nimport { colorControl, colorStyles } from './color-control.js';\nimport { kitStyles } from './styles.js';\n\n/** A field of the form, table-driven: one property, with the control its values ask for. */\ntype Field =\n | {\n readonly kind: 'number';\n readonly property: string;\n readonly unit: 'px' | '%' | '';\n readonly min: number;\n readonly max: number;\n readonly step?: number;\n }\n | { readonly kind: 'select'; readonly property: string; readonly options: readonly string[] }\n | { readonly kind: 'font'; readonly property: 'font-family' }\n | { readonly kind: 'color'; readonly property: string }\n | { readonly kind: 'position'; readonly property: 'position' };\n\ntype Section = 'text' | 'box' | 'spacing' | 'size';\n\nconst FONT: Field = { kind: 'font', property: 'font-family' };\nconst WIDTH: Field = { kind: 'number', property: 'width', unit: '%', min: 1, max: 100 };\nconst POSITION: Field = { kind: 'position', property: 'position' };\n\nconst TEXT_FIELDS: readonly Field[] = [\n FONT,\n { kind: 'number', property: 'font-size', unit: 'px', min: 10, max: 96 },\n { kind: 'select', property: 'font-weight', options: ['normal', 'bold'] },\n { kind: 'select', property: 'font-style', options: ['normal', 'italic'] },\n { kind: 'color', property: 'color' },\n { kind: 'select', property: 'text-align', options: ['start', 'center', 'end', 'justify'] },\n { kind: 'number', property: 'line-height', unit: '', min: 0.8, max: 4, step: 0.05 },\n];\nconst BOX_FIELDS: readonly Field[] = [\n { kind: 'color', property: 'background-color' },\n { kind: 'number', property: 'border-width', unit: 'px', min: 0, max: 16 },\n { kind: 'select', property: 'border-style', options: ['none', 'solid', 'dashed', 'dotted', 'double'] },\n { kind: 'color', property: 'border-color' },\n { kind: 'number', property: 'border-radius', unit: 'px', min: 0, max: 128 },\n];\nconst SPACING_FIELDS: readonly Field[] = [\n { kind: 'number', property: 'padding', unit: 'px', min: 0, max: 64 },\n { kind: 'number', property: 'margin-block-start', unit: 'px', min: 0, max: 128 },\n { kind: 'number', property: 'margin-block-end', unit: 'px', min: 0, max: 128 },\n];\n\n/** What each kind of element can sensibly change, in the order it comes to mind; the first section starts open. */\nconst sectionsOf = (\n kind: EditorStyleTargetKind | 'tag' | 'named',\n inFigure: boolean,\n): readonly (readonly [Section, readonly Field[]])[] => {\n const text: [Section, readonly Field[]] = ['text', TEXT_FIELDS];\n const box: [Section, readonly Field[]] = ['box', BOX_FIELDS];\n const spacing: [Section, readonly Field[]] = ['spacing', SPACING_FIELDS];\n const place: [Section, readonly Field[]] = ['size', [POSITION, WIDTH]];\n switch (kind) {\n case 'picture':\n // A figure's picture fills the figure, which is what sits on the page.\n return inFigure ? [box] : [place, box];\n case 'figure':\n return [place, box, spacing, text];\n case 'layout':\n return [\n [\n 'size',\n [\n { kind: 'number', property: 'gap', unit: 'px', min: 0, max: 64 },\n {\n kind: 'select',\n property: 'align-items',\n options: ['stretch', 'start', 'center', 'end'],\n },\n ],\n ],\n box,\n spacing,\n text,\n ];\n case 'column':\n return [\n ['size', [{ kind: 'number', property: 'flex-grow', unit: '', min: 0, max: 12 }]],\n box,\n spacing,\n text,\n ];\n case 'component':\n // Placed as a picture is: an exercise can float with text beside it.\n return [text, box, spacing, place];\n case 'named':\n case 'block':\n return [text, box, spacing, ['size', [WIDTH]]];\n default:\n return [text, box, spacing];\n }\n};\n\n/** A refused declaration, with the reason a message says. */\ninterface Refusal {\n readonly name: string;\n readonly reason: 'property' | 'value' | 'text' | 'length';\n}\n\n/** Why the allow-list refused a declaration, from the name `cleanStyle` reports. */\nfunction refusals(style: string, removed: readonly string[]): readonly Refusal[] {\n if (style.length > MAX_STYLE_LENGTH) return [{ name: 'style', reason: 'length' }];\n return removed.map((name) => ({\n name,\n reason: STYLE_PROPERTIES.includes(name)\n ? 'value'\n : /^-{0,2}[a-z][a-z-]*$/.test(name)\n ? 'property'\n : 'text',\n }));\n}\n\n/** A number in the field's unit, or null for what the field cannot show (it says it as a placeholder). */\nconst numberIn = (value: string | undefined, unit: string): string | null => {\n const match = /^(\\d*\\.?\\d+)([a-z%]*)$/.exec(value ?? '');\n if (match === null) return null;\n const [, number, written] = match;\n return written === unit || number === '0' || (unit === '' && written === '') ? (number as string) : null;\n};\n\n/**\n * `<astl-style-form>`: the style of an element at the cursor (`target`, or what the cursor is innermost in), or of a\n * rule of the document (`rule`): text, background and border, spacing, size and position, the named style, and \"Own\n * CSS\", which says what the allow-list refused and why. \"Save as a style\" makes the element's own style a named one.\n * Each commit of a field (a `change`) is one undo step, and the focus stays in the form. The adapter's `style`\n * (`EditorStyles`) does the work; without it the form says so. Comes with `loadStyleElements`, on first use.\n */\nexport class AstlStyleForm extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n target: {},\n rule: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n colorStyles,\n // A summary stays a list item, which keeps the marker that says it opens; its padding makes the line a target. The\n // layout's commands go in a row from the start, wrapping when narrow; its question has a line of its own.\n css`\n .form {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n }\n details {\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n summary {\n box-sizing: border-box;\n min-block-size: var(--astl-target-min);\n padding-block: calc((var(--astl-target-min) - 1lh) / 2);\n padding-inline: var(--astl-space-3);\n font-weight: 600;\n cursor: pointer;\n }\n .fields {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));\n gap: var(--astl-space-3);\n padding: var(--astl-space-3);\n padding-block-start: var(--astl-space-1);\n }\n .field {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n }\n .field.wide,\n .fields > fieldset {\n grid-column: 1 / -1;\n }\n fieldset {\n margin: 0;\n padding: 0;\n border: 0;\n min-inline-size: 0;\n }\n legend,\n label {\n padding: 0;\n font-weight: 600;\n }\n legend {\n margin-block-end: var(--astl-space-1);\n }\n .unit {\n display: flex;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .unit span {\n flex: none;\n color: var(--astl-ink-muted);\n }\n textarea {\n font-family: var(--astl-font-mono, monospace);\n font-size: var(--astl-size-small);\n }\n .refused {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .refused ul {\n gap: var(--astl-space-1);\n }\n .save {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n gap: var(--astl-space-2);\n align-items: end;\n }\n .save label {\n grid-column: 1 / -1;\n }\n .layout {\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-2);\n }\n .layout [role='alert'] {\n flex-basis: 100%;\n }\n `,\n ];\n\n /** What the form styles, of what the cursor is in; null: the innermost. */\n declare target: EditorStyleTargetKind | null;\n /** A rule to edit in place of an element: by its `name`, or `for` a tag. */\n declare rule: Pick<EditorStyleRule, 'name' | 'for'> | null;\n\n /** The refused declarations of the last edit: shown until the next one. */\n #refused: readonly Refusal[] = [];\n /** New refusals to bring into view: in a host's card or sheet the form is taller than its box. */\n #revealRefused = false;\n /** Colour fields whose typed colour was refused. */\n #badColors = new Set<string>();\n /** The field's text when it was refused, kept so the author can correct it. */\n #draft: string | null = null;\n #saveLabel = '';\n /** What the form was last showing: moving to another element forgets the last refusals. */\n #shown = '';\n /** \"Delete with content\" was pressed on a layout that holds some: the form asks first. */\n #askDelete = false;\n\n constructor() {\n super();\n this.target = null;\n this.rule = null;\n }\n\n protected override cursorChanged(): void {\n this.requestUpdate();\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring')) this.authoring?.addMessages(styleMessages);\n const key =\n this.rule === null ? (this.#element()?.kind ?? '') : `rule ${this.rule.name ?? this.rule.for}`;\n if (key !== this.#shown) {\n this.#askDelete = false;\n this.#refused = [];\n this.#draft = null;\n this.#badColors.clear();\n }\n this.#shown = key;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n if (!this.#revealRefused) return;\n this.#revealRefused = false;\n const note = this.renderRoot.querySelector('#own-refused');\n note?.closest('details')?.setAttribute('open', '');\n note?.scrollIntoView({ block: 'nearest' });\n }\n\n #styles() {\n return this.adapter?.style ?? null;\n }\n\n #element(): EditorStyleTarget | null {\n const targets = this.#styles()?.state().targets ?? [];\n return (this.target === null ? targets[0] : targets.find((one) => one.kind === this.target)) ?? null;\n }\n\n #currentRule(): EditorStyleRule | null {\n const rule = this.rule;\n if (rule === null) return null;\n return (\n this.#styles()\n ?.rules()\n .find((one) => (rule.name !== undefined ? one.name === rule.name : one.for === rule.for)) ?? {\n ...(rule.name === undefined ? {} : { name: rule.name }),\n ...(rule.for === undefined ? {} : { for: rule.for }),\n style: '',\n }\n );\n }\n\n #write(changes: EditorStyleChanges): void {\n const styles = this.#styles();\n if (styles === null) return;\n const rule = this.#currentRule();\n if (rule !== null) {\n const gone = new Set(Object.keys(changes));\n const adding = cleanStyle(\n Object.entries(changes)\n .flatMap(([name, value]) => (value === null ? [] : [`${name}: ${value}`]))\n .join('; '),\n ).declarations;\n const style = styleText(\n mergeStyles(\n cleanStyle(rule.style).declarations.filter(([name]) => !gone.has(name)),\n adding,\n ),\n );\n styles.setRule({ ...rule, style });\n } else {\n const element = this.#element();\n if (element !== null) styles.setTarget(element.kind, changes);\n }\n this.#refused = [];\n this.#draft = null;\n this.requestUpdate();\n }\n\n /** One field's value: what the allow-list refuses is said, not written. */\n #commit(property: string, value: string | null): void {\n if (value !== null) {\n const { removed } = cleanStyle(`${property}: ${value}`);\n if (removed.length > 0) {\n this.#refused = refusals('', removed);\n this.#revealRefused = true;\n this.requestUpdate();\n return;\n }\n }\n this.#write({ [property]: value });\n }\n\n /** The \"Own CSS\" field: what the allow-list keeps is the new style, what it refuses is said and never written. */\n #applyOwn(text: string): void {\n const styles = this.#styles();\n if (styles === null) return;\n const clean = cleanStyle(text);\n const rule = this.#currentRule();\n if (rule !== null) styles.setRule({ ...rule, style: clean.style });\n else {\n const element = this.#element();\n if (element !== null) styles.replaceTarget(element.kind, clean.style);\n }\n this.#refused = refusals(text, clean.removed);\n this.#revealRefused = this.#refused.length > 0;\n // The field then shows what stays; the refusals say what went.\n this.#draft = null;\n this.requestUpdate();\n }\n\n #fieldLabel(field: Field): string {\n return this.t(`style.field.${field.property}`);\n }\n\n #field(field: Field, declared: ReadonlyMap<string, string>, style: string, at: string): TemplateResult {\n const id = `${at}-${field.property}`;\n const label = this.#fieldLabel(field);\n const value = declared.get(field.property);\n switch (field.kind) {\n case 'number': {\n const shown = numberIn(value, field.unit);\n return html`<div class=\"field\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <div class=\"unit\">\n <input\n id=${id}\n type=\"number\"\n inputmode=\"decimal\"\n data-property=${field.property}\n min=${field.min}\n max=${field.max}\n step=${field.step ?? 1}\n placeholder=${shown === null ? (value ?? '') : ''}\n .value=${live(shown ?? '')}\n @change=${(event: Event) => {\n const text = (event.target as HTMLInputElement).value.trim();\n // The field writes what the corner handle writes.\n if (\n field.property === 'width' &&\n text !== '' &&\n cleanStyle(`width: ${text}%`).removed.length === 0\n )\n this.#write(widthChanges(style, Number(text)));\n else this.#commit(field.property, text === '' ? null : `${text}${field.unit}`);\n }}\n />\n ${field.unit === '' ? nothing : html`<span aria-hidden=\"true\">${field.unit}</span>`}\n </div>\n </div>`;\n }\n case 'select':\n return html`<div class=\"field\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=${field.property}\n .value=${live(value ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n this.#commit(field.property, next === '' ? null : next);\n }}\n >\n <option value=\"\">${this.t('toolbar.default')}</option>\n ${field.options.map(\n (option) =>\n html`<option value=${option} ?selected=${option === value}>${this.t(`style.value.${option}`)}</option>`,\n )}\n </select>\n </div>`;\n case 'font': {\n const fonts = this.authoring?.fonts ?? [];\n const other = value !== undefined && !fonts.some((font) => font.stack === value);\n return html`<div class=\"field wide\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=${field.property}\n .value=${live(value ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n this.#commit(field.property, next === '' ? null : next);\n }}\n >\n <option value=\"\">${this.t('toolbar.default')}</option>\n ${fonts.map(\n (font) =>\n html`<option value=${font.stack} ?selected=${font.stack === value}>${font.name}</option>`,\n )}\n ${other ? html`<option value=${value} selected>${value}</option>` : nothing}\n </select>\n </div>`;\n }\n case 'position': {\n const position = positionOf(style);\n return html`<div class=\"field wide\" part=\"field\">\n <label for=${id} part=\"label\">${label}</label>\n <select\n id=${id}\n data-property=\"position\"\n .value=${live(position)}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value as Placement;\n this.#write(positionChanges(next, style, this.#element()?.kind === 'figure'));\n }}\n >\n ${PLACEMENTS.map(\n (one) =>\n html`<option value=${one} ?selected=${one === position}>${this.t(`style.position.${one}`)}</option>`,\n )}\n </select>\n </div>`;\n }\n case 'color':\n return html`<fieldset part=\"field\" data-property=${field.property}>\n <legend part=\"label\">${label}</legend>\n ${colorControl({\n id,\n value: value ?? null,\n t: (key, params) => this.t(key, params),\n invalid: this.#badColors.has(field.property),\n ground: field.property === 'background-color',\n pick: (next) => {\n this.#badColors.delete(field.property);\n this.#commit(field.property, next);\n },\n refuse: () => {\n this.#badColors.add(field.property);\n this.requestUpdate();\n },\n })}\n </fieldset>`;\n }\n }\n\n #refusedList(): TemplateResult | typeof nothing {\n if (this.#refused.length === 0) return nothing;\n return html`<div class=\"refused\" id=\"own-refused\">\n <ul>\n ${this.#refused.map(\n ({ name, reason }) =>\n html`<li data-refused=${name}>${this.t(`style.refused.${reason}`, { name, max: MAX_STYLE_LENGTH })}</li>`,\n )}\n </ul>\n </div>`;\n }\n\n /** The named style of the element, the ready styles the document does not have yet, and saving its own style as one. */\n #named(element: EditorStyleTarget): TemplateResult {\n const named = (this.#styles()?.rules() ?? []).filter((rule) => rule.name !== undefined);\n const own = new Set(named.map((rule) => rule.name));\n const ready = (this.authoring?.styles ?? []).filter((preset) => !own.has(preset.name));\n return html`<details part=\"section\" data-section=\"named\">\n <summary>${this.t('style.section.named')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"named\" part=\"label\">${this.t('style.field.named')}</label>\n <select\n id=\"named\"\n .value=${live(element.className ?? '')}\n @change=${(event: Event) => {\n const next = (event.target as HTMLSelectElement).value;\n const preset = ready.find((one) => one.name === next);\n // A ready style brings its rule, labelled as the author reads it now, in the same undo step.\n if (preset !== undefined)\n this.#styles()?.setClass(element.kind, next, {\n name: next,\n label: preset.label,\n style: preset.style,\n });\n else this.#styles()?.setClass(element.kind, next === '' ? null : next);\n this.requestUpdate();\n }}\n >\n <option value=\"\">${this.t('style.named.none')}</option>\n ${named.map(\n (rule) =>\n html`<option value=${rule.name ?? ''} ?selected=${rule.name === element.className}>${rule.label ?? rule.name}</option>`,\n )}\n ${\n ready.length === 0\n ? nothing\n : html`<optgroup label=${this.t('toolbar.readyStyles')}>\n ${ready.map(\n (preset) =>\n html`<option value=${preset.name} ?selected=${preset.name === element.className}>${preset.label}</option>`,\n )}\n </optgroup>`\n }\n </select>\n </div>\n <div class=\"save field wide\">\n <label for=\"save-label\" part=\"label\">${this.t('style.save.label')}</label>\n <input\n id=\"save-label\"\n type=\"text\"\n autocomplete=\"off\"\n .value=${this.#saveLabel}\n @input=${(event: Event) => {\n this.#saveLabel = (event.target as HTMLInputElement).value;\n }}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n this.#save(element);\n }\n }}\n />\n <button type=\"button\" data-save @click=${() => this.#save(element)}>${this.t('style.save')}</button>\n </div>\n </div>\n </details>`;\n }\n\n #save(element: EditorStyleTarget): void {\n const label = this.#saveLabel.trim();\n if (label === '') {\n this.renderRoot.querySelector<HTMLInputElement>('#save-label')?.focus();\n return;\n }\n if (this.#styles()?.saveRule(element.kind, label) !== null) this.#saveLabel = '';\n this.requestUpdate();\n }\n\n #editLayout(edit: EditorLayoutEdit): void {\n this.#askDelete = false;\n this.#styles()?.editLayout?.(edit);\n this.requestUpdate();\n }\n\n /**\n * The layout's own commands, first in its form and open: another shape, its columns removed with their content kept,\n * or deleted with it, which asks first when there is content to lose. Its style sections follow, closed.\n */\n #layout(): TemplateResult | typeof nothing {\n const styles = this.#styles();\n const state = styles?.layout?.() ?? null;\n if (styles?.editLayout === undefined || state === null) return nothing;\n const ask = this.#askDelete;\n return html`<details open part=\"section\" data-section=\"layout\">\n <summary>${this.t('layout.section')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"layout-shape\" part=\"label\">${this.t('layout.change')}</label>\n <select\n id=\"layout-shape\"\n @change=${(event: Event) => {\n const value = (event.target as HTMLSelectElement).value;\n if (value !== '') this.#editLayout(value as EditorLayoutShape);\n }}\n >\n ${state.shape === null ? html`<option value=\"\" selected>${this.t('layout.other')}</option>` : nothing}\n ${LAYOUT_SHAPES.map(\n (shape) =>\n html`<option value=${shape} ?selected=${shape === state.shape}>\n ${this.t(`insert.layout.${shape}`)}\n </option>`,\n )}\n </select>\n </div>\n <div class=\"layout wide field\" role=\"group\" aria-label=${this.t('layout.section')}>\n ${\n ask\n ? html`<span role=\"alert\">${this.t('layout.confirm')}</span>\n <button type=\"button\" @click=${() => this.#editLayout('delete')}>\n ${this.t('layout.confirmDelete')}\n </button>\n <button\n type=\"button\"\n data-cancel\n @click=${() => {\n this.#askDelete = false;\n this.requestUpdate();\n }}\n >\n ${this.t('layout.cancel')}\n </button>`\n : html`<button type=\"button\" @click=${() => this.#editLayout('unwrap')}>\n ${this.t('layout.unwrap')}\n </button>\n <button\n type=\"button\"\n @click=${() => {\n if (state.empty) this.#editLayout('delete');\n else {\n this.#askDelete = true;\n this.requestUpdate();\n void this.updateComplete.then(() =>\n this.renderRoot.querySelector<HTMLElement>('[data-cancel]')?.focus(),\n );\n }\n }}\n >\n ${this.t('layout.delete')}\n </button>`\n }\n </div>\n </div>\n </details>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const styles = this.#styles();\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const rule = this.#currentRule();\n const element = rule === null ? this.#element() : null;\n if (styles === null || (rule === null && element === null)) {\n return html`<p class=\"note\" lang=${lang} dir=${dir}>${this.t('style.form.none')}</p>`;\n }\n const style = rule?.style ?? element?.style ?? '';\n const declared = new Map(cleanStyle(style).declarations);\n const inFigure =\n element?.kind === 'picture' && styles.state().targets.some((one) => one.kind === 'figure');\n const kind =\n rule === null\n ? (element?.kind as EditorStyleTargetKind)\n : rule.name !== undefined\n ? 'named'\n : rule.for === 'img'\n ? 'picture'\n : 'tag';\n const sections = sectionsOf(kind, inFigure);\n const own = this.#draft ?? style;\n // A layout's form starts with its commands; then its style, closed.\n const layout = element?.kind === 'layout';\n return html`<div class=\"form\" part=\"root\" lang=${lang} dir=${dir} data-kind=${kind}>\n ${layout ? this.#layout() : nothing}\n ${sections.map(\n (\n [section, fields],\n at,\n ) => html`<details ?open=${at === 0 && !layout} part=\"section\" data-section=${section}>\n <summary>${this.t(`style.section.${section}`)}</summary>\n <div class=\"fields\">${fields.map((field) => this.#field(field, declared, style, section))}</div>\n </details>`,\n )}\n ${element === null ? nothing : this.#named(element)}\n <details ?open=${!layout} part=\"section\" data-section=\"own\">\n <summary>${this.t('style.section.own')}</summary>\n <div class=\"fields\">\n <div class=\"field wide\" part=\"field\">\n <label for=\"own\" part=\"label\">${this.t('style.field.own')}</label>\n <textarea\n id=\"own\"\n rows=\"3\"\n spellcheck=\"false\"\n placeholder=\"background-color: #fff3cd; padding: 12px\"\n aria-describedby=${this.#refused.length > 0 ? 'own-refused' : nothing}\n .value=${live(own)}\n @change=${(event: Event) => this.#applyOwn((event.target as HTMLTextAreaElement).value)}\n ></textarea>\n <div role=\"alert\">${this.#refusedList()}</div>\n </div>\n </div>\n </details>\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-style-form': AstlStyleForm;\n }\n}\n"],"mappings":"A,2aAiDA,IAAMmB,EAAc,CAAE,KAAM,OAAQ,SAAU,aAAc,EACtDC,EAAe,CAAE,KAAM,SAAU,SAAU,QAAS,KAAM,IAAK,IAAK,EAAG,IAAK,GAAI,EAChFC,EAAkB,CAAE,KAAM,WAAY,SAAU,UAAW,EAE3DC,EAAgC,CACpCH,EACA,CAAE,KAAM,SAAU,SAAU,YAAa,KAAM,KAAM,IAAK,GAAI,IAAK,EAAG,EACtE,CAAE,KAAM,SAAU,SAAU,cAAe,QAAS,CAAC,SAAU,MAAM,CAAE,EACvE,CAAE,KAAM,SAAU,SAAU,aAAc,QAAS,CAAC,SAAU,QAAQ,CAAE,EACxE,CAAE,KAAM,QAAS,SAAU,OAAQ,EACnC,CAAE,KAAM,SAAU,SAAU,aAAc,QAAS,CAAC,QAAS,SAAU,MAAO,SAAS,CAAE,EACzF,CAAE,KAAM,SAAU,SAAU,cAAe,KAAM,GAAI,IAAK,GAAK,IAAK,EAAG,KAAM,GAAK,CACpF,EACMI,EAA+B,CACnC,CAAE,KAAM,QAAS,SAAU,kBAAmB,EAC9C,CAAE,KAAM,SAAU,SAAU,eAAgB,KAAM,KAAM,IAAK,EAAG,IAAK,EAAG,EACxE,CAAE,KAAM,SAAU,SAAU,eAAgB,QAAS,CAAC,OAAQ,QAAS,SAAU,SAAU,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W9B,EAAM,OAA+B,KAAK,EAAE;;gCAEtE,KAAK+B,GAAa,EAAE;;;;WAKlD,CACF,E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as e,E as t,b as n}from"./runtime-
|
|
1
|
+
import{C as e,E as t,b as n}from"./runtime-C25QK5B0.js";import{s as r}from"./style-model-ZXNe_c8R.js";import{n as i,t as a}from"./color-control-1kkdM8ns.js";var o=[10,11,12,14,16,18,20,24,28,32,36,48,72],s=[`start`,`center`,`end`,`justify`],c=[`1`,`1.15`,`1.5`,`2`],l=[[`0px`,`none`],[`8px`,`small`],[`16px`,`medium`],[`24px`,`large`]],u=t`
|
|
2
2
|
${i}
|
|
3
3
|
.colors {
|
|
4
4
|
inline-size: min(16rem, calc(100vw - 2 * var(--astl-space-4)));
|
|
@@ -71,4 +71,4 @@ import{C as e,E as t,b as n}from"./runtime-DxAbpr3S.js";import{s as r}from"./sty
|
|
|
71
71
|
</div>
|
|
72
72
|
${n===`rules`?e`<astl-style-rules .authoring=${i} .adapter=${a}></astl-style-rules>`:e`<astl-style-form .authoring=${i} .adapter=${a} .target=${n}></astl-style-form>`}
|
|
73
73
|
</div>`}function m(e){let{popup:t,styles:n,t:i,fonts:a,setText:u,setBlock:m}=e;if(typeof t==`object`)return p(e,t.panel);if(t===`color`||t===`highlight`)return f(e,t);let{text:h}=n,g={value:null,label:i(`toolbar.default`)},_=r(n.targets.find(e=>e.kind===`block`)?.style??``),v=e=>e===void 0?null:String(Number.parseFloat(e));if(t===`font`)return d(e,`font`,[{choices:[g,...a.map(e=>({value:e.stack,label:e.name,font:e.stack}))],now:h[`font-family`]??null}],e=>u({"font-family":e.value}),i(`toolbar.font.name`));if(t===`size`)return d(e,`size`,[{choices:[g,...o.map(e=>({value:`${e}px`,label:String(e)}))],now:h[`font-size`]??null}],e=>u({"font-size":e.value}),i(`toolbar.size.name`));if(t===`align`){let t=_.get(`text-align`);return d(e,`align`,[{choices:s.map(e=>({value:e,label:i(`toolbar.align.${e}`)})),now:t===`left`?`start`:t===`right`?`end`:t??`start`}],e=>m({"text-align":e.value===`start`?null:e.value}),i(`toolbar.align`))}return d(e,`spacing`,[{title:i(`toolbar.spacing.line`),choices:[g,...c.map(e=>({value:e,label:e}))],now:v(_.get(`line-height`))},{title:i(`toolbar.spacing.after`),choices:[g,...l.map(([e,t])=>({value:e,label:i(`toolbar.spacing.${t}`)}))],now:_.has(`margin-block-end`)?`${v(_.get(`margin-block-end`))}px`:null}],(e,t)=>m({[t===0?`line-height`:`margin-block-end`]:e.value}),i(`toolbar.spacing`))}export{m as stylePopup,u as stylePopupStyles};
|
|
74
|
-
//# sourceMappingURL=style-popups-
|
|
74
|
+
//# sourceMappingURL=style-popups-Bcl5imdP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-popups-BobgX1WK.js","names":["nothing","b","i","A","styleMapOf","colorStyles","colorControl","FONT_SIZES","ALIGNS","LINE_HEIGHTS","BLOCK_SPACES","stylePopupStyles","choiceMenu","popup","label","context","groups","group","choice","choose","at","colors","property","event","next","value","panel","title","t","target","authoring","adapter","stylePopup","styles","none","block","number","fonts","font","text","setText","n","now","setBlock","name"],"sources":["../../../../editor/src/elements/style-popups.ts"],"sourcesContent":["/**\n * The toolbar's popups of the style controls: the menus of values, the colours, and the panel with the form or the\n * rules. Outside the editor's first load: the toolbar loads this module when one of them first opens, and draws them\n * in its own root, as its other popups.\n */\nimport type { EditorAdapter, EditorStyleChanges, EditorStyleState } from '@astl/core';\nimport { type CSSResult, css, html, nothing, type TemplateResult } from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { type EditorFont, styleMapOf } from '../style-model.js';\nimport { colorControl, colorStyles } from './color-control.js';\nimport type { StyleOpen } from './style-load.js';\n\n/** The popups of the style controls: menus of values, and the colours. */\nexport type StylePopup = 'font' | 'size' | 'color' | 'highlight' | 'align' | 'spacing';\n\n/** The font sizes of the menu, in px. */\nconst FONT_SIZES: readonly number[] = [10, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 48, 72];\nconst ALIGNS = ['start', 'center', 'end', 'justify'] as const;\nconst LINE_HEIGHTS: readonly string[] = ['1', '1.15', '1.5', '2'];\nconst BLOCK_SPACES: readonly (readonly [string, string])[] = [\n ['0px', 'none'],\n ['8px', 'small'],\n ['16px', 'medium'],\n ['24px', 'large'],\n];\n\n/** One value of a menu of values: what it writes, and its label. */\ninterface Choice {\n readonly value: string | null;\n readonly label: string;\n /** A stack to show the label in, in a font menu. */\n readonly font?: string;\n}\n\nexport const stylePopupStyles: CSSResult = css`\n ${colorStyles}\n .colors {\n inline-size: min(16rem, calc(100vw - 2 * var(--astl-space-4)));\n }\n .panel {\n inline-size: min(26rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: min(40rem, calc(100vh - 2 * var(--astl-space-4)));\n }\n .panel astl-style-rules::part(root) {\n padding: 0;\n border: 0;\n }\n .panel astl-style-rules::part(title) {\n display: none;\n }\n .panel-head {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--astl-space-2);\n margin-block-end: var(--astl-space-2);\n font-weight: 600;\n }\n`;\n\n/** What a popup needs from its toolbar. */\nexport interface StylePopupContext {\n /** Which one is open: `panel` shows the form of a target, or the rules. */\n readonly popup: StylePopup | { readonly panel: StyleOpen['target'] };\n readonly styles: EditorStyleState;\n readonly fonts: readonly EditorFont[];\n /** A typed colour was refused. */\n readonly colorError: boolean;\n readonly authoring: Authoring | null;\n readonly adapter: EditorAdapter | null;\n readonly t: (key: string, params?: Record<string, string | number>) => string;\n /** On the selected text, then closes the popup. */\n readonly setText: (changes: EditorStyleChanges) => void;\n /** On each text block of the selection, then closes the popup. */\n readonly setBlock: (changes: EditorStyleChanges) => void;\n readonly refuseColor: () => void;\n /** Closes the popup; the focus goes back to its button with `back`. */\n readonly close: (back: boolean) => void;\n /** The arrows, Home and End along a menu's buttons, as the toolbar's other menus. */\n readonly menuKeydown: (event: KeyboardEvent) => void;\n}\n\n/** A menu of values: one checked at a time, each writing what it says. */\nfunction choiceMenu(\n context: StylePopupContext,\n popup: StylePopup,\n groups: readonly {\n readonly title?: string;\n readonly choices: readonly Choice[];\n readonly now: string | null;\n }[],\n choose: (choice: Choice, group: number) => void,\n label: string,\n): TemplateResult {\n return html`<div\n id=${popup}\n class=\"menu\"\n popover=\"manual\"\n role=\"menu\"\n aria-label=${label}\n part=\"style-menu\"\n @keydown=${context.menuKeydown}\n >\n ${groups.map(\n (group, at) => html`<div class=\"menu-section\" role=\"group\" aria-label=${group.title ?? nothing}>\n ${group.title === undefined ? nothing : html`<div class=\"menu-group\" aria-hidden=\"true\">${group.title}</div>`}\n ${group.choices.map(\n (choice) => html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-value=${choice.value ?? ''}\n aria-checked=${String(choice.value === group.now)}\n data-font=${choice.font ?? nothing}\n @click=${() => choose(choice, at)}\n >\n ${choice.label}\n </button>`,\n )}\n </div>`,\n )}\n </div>`;\n}\n\nfunction colors(context: StylePopupContext, popup: 'color' | 'highlight'): TemplateResult {\n const property = popup === 'color' ? 'color' : 'background-color';\n return html`<div\n id=${popup}\n class=\"colors\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${context.t(`toolbar.${popup}`)}\n part=\"style-colors\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n context.close(true);\n }\n }}\n @focusout=${(event: FocusEvent) => {\n const next = event.relatedTarget as Node | null;\n if (next !== null && !(event.currentTarget as HTMLElement).contains(next)) context.close(false);\n }}\n >\n ${colorControl({\n id: popup,\n value: context.styles.text[property] ?? null,\n t: context.t,\n invalid: context.colorError,\n ground: popup === 'highlight',\n pick: (value) => context.setText({ [property]: value }),\n refuse: context.refuseColor,\n })}\n </div>`;\n}\n\n/** The default of `astl-style-open`: the form or the rules in a popup. */\nfunction panel(context: StylePopupContext, target: StyleOpen['target']): TemplateResult {\n const { t, authoring, adapter } = context;\n const title = t(target === 'rules' ? 'style.rules.title' : `style.target.${target}`);\n return html`<div\n id=\"panel\"\n class=\"panel\"\n popover=\"manual\"\n role=\"dialog\"\n tabindex=\"-1\"\n aria-label=${title}\n part=\"style-panel\"\n >\n <div class=\"panel-head\">\n <span>${title}</span>\n <button type=\"button\" data-close @click=${() => context.close(true)}>${t('style.close')}</button>\n </div>\n ${\n target === 'rules'\n ? html`<astl-style-rules .authoring=${authoring} .adapter=${adapter}></astl-style-rules>`\n : html`<astl-style-form .authoring=${authoring} .adapter=${adapter} .target=${target}></astl-style-form>`\n }\n </div>`;\n}\n\n/** The popup that is open. */\nexport function stylePopup(context: StylePopupContext): TemplateResult {\n const { popup, styles, t, fonts, setText, setBlock } = context;\n if (typeof popup === 'object') return panel(context, popup.panel);\n if (popup === 'color' || popup === 'highlight') return colors(context, popup);\n const { text } = styles;\n const none = { value: null, label: t('toolbar.default') };\n const block = styleMapOf(styles.targets.find((target) => target.kind === 'block')?.style ?? '');\n const number = (value: string | undefined) =>\n value === undefined ? null : String(Number.parseFloat(value));\n if (popup === 'font')\n return choiceMenu(\n context,\n 'font',\n [\n {\n choices: [\n none,\n ...fonts.map((font) => ({ value: font.stack, label: font.name, font: font.stack })),\n ],\n now: text['font-family'] ?? null,\n },\n ],\n (choice) => setText({ 'font-family': choice.value }),\n t('toolbar.font.name'),\n );\n if (popup === 'size')\n return choiceMenu(\n context,\n 'size',\n [\n {\n choices: [none, ...FONT_SIZES.map((n) => ({ value: `${n}px`, label: String(n) }))],\n now: text['font-size'] ?? null,\n },\n ],\n (choice) => setText({ 'font-size': choice.value }),\n t('toolbar.size.name'),\n );\n if (popup === 'align') {\n const now = block.get('text-align');\n return choiceMenu(\n context,\n 'align',\n [\n {\n choices: ALIGNS.map((value) => ({ value, label: t(`toolbar.align.${value}`) })),\n now: now === 'left' ? 'start' : now === 'right' ? 'end' : (now ?? 'start'),\n },\n ],\n (choice) => setBlock({ 'text-align': choice.value === 'start' ? null : choice.value }),\n t('toolbar.align'),\n );\n }\n return choiceMenu(\n context,\n 'spacing',\n [\n {\n title: t('toolbar.spacing.line'),\n choices: [none, ...LINE_HEIGHTS.map((value) => ({ value, label: value }))],\n now: number(block.get('line-height')),\n },\n {\n title: t('toolbar.spacing.after'),\n choices: [\n none,\n ...BLOCK_SPACES.map(([value, name]) => ({ value, label: t(`toolbar.spacing.${name}`) })),\n ],\n now: block.has('margin-block-end') ? `${number(block.get('margin-block-end'))}px` : null,\n },\n ],\n (choice, group) => setBlock({ [group === 0 ? 'line-height' : 'margin-block-end']: choice.value }),\n t('toolbar.spacing'),\n );\n}\n"],"mappings":"A,6JAgBA,IAAMO,EAAgC,CAAC,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,EAAE,EACnFC,EAAS,CAAC,QAAS,SAAU,MAAO,SAAS,EAC7CC,EAAkC,CAAC,IAAK,OAAQ,MAAO,GAAG,EAC1DC,EAAuD,CAC3D,CAAC,MAAO,MAAM,EACd,CAAC,MAAO,OAAO,EACf,CAAC,OAAQ,QAAQ,EACjB,CAAC,OAAQ,OAAO,CAClB,EAUaC,EAA8B,CAAG;IAC1CN,EAAY;;;;;;;;;;;;;;;;;;;;;;;EAgDhB,SAASO,EACP,EACA,EACA,EAKA,EACA,EACgB,CAChB,MAAO,EAAI;SACJC,EAAM;;;;iBAIEC,EAAM;;eAERC,EAAQ,YAAY;;MAE7BC,EAAO,KACN,EAAO,IAAO,CAAI,qDAAqDC,EAAM,OAASjB,EAAQ;UAC3FiB,EAAM,QAAU,IAAA,GAAYjB,EAAU,CAAI,8CAA8CiB,EAAM,MAAM,QAAQ;UAC5GA,EAAM,QAAQ,IACb,GAAW,CAAI;;;;yBAIDC,EAAO,OAAS,GAAG;2BACjB,OAAOA,EAAO,QAAUD,EAAM,GAAG,EAAE;wBACtCC,EAAO,MAAQlB,EAAQ;yBACpBmB,EAAOD,EAAQE,CAAE,EAAE;;cAEhCF,EAAO,MAAM;oBAEnB,EAAE;aAEN,EAAE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ACM,EAAM,GAAGzB,EAAa,IAAK,IAAW,CAAE,QAAO,MAAOgB,CAAM,EAAE,CAAC,EACzE,IAAKW,EAAOD,EAAM,IAAI,aAAa,CAAC,CACtC,EACA,CACE,MAAOP,EAAE,uBAAuB,EAChC,QAAS,CACPM,EACA,GAAGxB,EAAa,KAAK,CAACe,EAAOmB,MAAW,CAAE,QAAO,MAAOhB,EAAE,mBAAmBgB,GAAM,CAAE,EAAE,CACzF,EACA,IAAKT,EAAM,IAAI,kBAAkB,EAAI,GAAGC,EAAOD,EAAM,IAAI,kBAAkB,CAAC,EAAE,IAAM,IACtF,CACF,GACC,EAAQ,IAAUQ,EAAS,EAAG1B,IAAU,EAAI,cAAgB,oBAAqBC,EAAO,KAAM,CAAC,EAChGU,EAAE,iBAAiB,CACrB,CACF,C"}
|
|
1
|
+
{"version":3,"file":"style-popups-Bcl5imdP.js","names":["nothing","b","i","A","styleMapOf","colorStyles","colorControl","FONT_SIZES","ALIGNS","LINE_HEIGHTS","BLOCK_SPACES","stylePopupStyles","choiceMenu","popup","label","context","groups","group","choice","choose","at","colors","property","event","next","value","panel","title","t","target","authoring","adapter","stylePopup","styles","none","block","number","fonts","font","text","setText","n","now","setBlock","name"],"sources":["../../../../editor/src/elements/style-popups.ts"],"sourcesContent":["/**\n * The toolbar's popups of the style controls: the menus of values, the colours, and the panel with the form or the\n * rules. Outside the editor's first load: the toolbar loads this module when one of them first opens, and draws them\n * in its own root, as its other popups.\n */\nimport type { EditorAdapter, EditorStyleChanges, EditorStyleState } from '@astl/core';\nimport { type CSSResult, css, html, nothing, type TemplateResult } from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { type EditorFont, styleMapOf } from '../style-model.js';\nimport { colorControl, colorStyles } from './color-control.js';\nimport type { StyleOpen } from './style-load.js';\n\n/** The popups of the style controls: menus of values, and the colours. */\nexport type StylePopup = 'font' | 'size' | 'color' | 'highlight' | 'align' | 'spacing';\n\n/** The font sizes of the menu, in px. */\nconst FONT_SIZES: readonly number[] = [10, 11, 12, 14, 16, 18, 20, 24, 28, 32, 36, 48, 72];\nconst ALIGNS = ['start', 'center', 'end', 'justify'] as const;\nconst LINE_HEIGHTS: readonly string[] = ['1', '1.15', '1.5', '2'];\nconst BLOCK_SPACES: readonly (readonly [string, string])[] = [\n ['0px', 'none'],\n ['8px', 'small'],\n ['16px', 'medium'],\n ['24px', 'large'],\n];\n\n/** One value of a menu of values: what it writes, and its label. */\ninterface Choice {\n readonly value: string | null;\n readonly label: string;\n /** A stack to show the label in, in a font menu. */\n readonly font?: string;\n}\n\nexport const stylePopupStyles: CSSResult = css`\n ${colorStyles}\n .colors {\n inline-size: min(16rem, calc(100vw - 2 * var(--astl-space-4)));\n }\n .panel {\n inline-size: min(26rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: min(40rem, calc(100vh - 2 * var(--astl-space-4)));\n }\n .panel astl-style-rules::part(root) {\n padding: 0;\n border: 0;\n }\n .panel astl-style-rules::part(title) {\n display: none;\n }\n .panel-head {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--astl-space-2);\n margin-block-end: var(--astl-space-2);\n font-weight: 600;\n }\n`;\n\n/** What a popup needs from its toolbar. */\nexport interface StylePopupContext {\n /** Which one is open: `panel` shows the form of a target, or the rules. */\n readonly popup: StylePopup | { readonly panel: StyleOpen['target'] };\n readonly styles: EditorStyleState;\n readonly fonts: readonly EditorFont[];\n /** A typed colour was refused. */\n readonly colorError: boolean;\n readonly authoring: Authoring | null;\n readonly adapter: EditorAdapter | null;\n readonly t: (key: string, params?: Record<string, string | number>) => string;\n /** On the selected text, then closes the popup. */\n readonly setText: (changes: EditorStyleChanges) => void;\n /** On each text block of the selection, then closes the popup. */\n readonly setBlock: (changes: EditorStyleChanges) => void;\n readonly refuseColor: () => void;\n /** Closes the popup; the focus goes back to its button with `back`. */\n readonly close: (back: boolean) => void;\n /** The arrows, Home and End along a menu's buttons, as the toolbar's other menus. */\n readonly menuKeydown: (event: KeyboardEvent) => void;\n}\n\n/** A menu of values: one checked at a time, each writing what it says. */\nfunction choiceMenu(\n context: StylePopupContext,\n popup: StylePopup,\n groups: readonly {\n readonly title?: string;\n readonly choices: readonly Choice[];\n readonly now: string | null;\n }[],\n choose: (choice: Choice, group: number) => void,\n label: string,\n): TemplateResult {\n return html`<div\n id=${popup}\n class=\"menu\"\n popover=\"manual\"\n role=\"menu\"\n aria-label=${label}\n part=\"style-menu\"\n @keydown=${context.menuKeydown}\n >\n ${groups.map(\n (group, at) => html`<div class=\"menu-section\" role=\"group\" aria-label=${group.title ?? nothing}>\n ${group.title === undefined ? nothing : html`<div class=\"menu-group\" aria-hidden=\"true\">${group.title}</div>`}\n ${group.choices.map(\n (choice) => html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-value=${choice.value ?? ''}\n aria-checked=${String(choice.value === group.now)}\n data-font=${choice.font ?? nothing}\n @click=${() => choose(choice, at)}\n >\n ${choice.label}\n </button>`,\n )}\n </div>`,\n )}\n </div>`;\n}\n\nfunction colors(context: StylePopupContext, popup: 'color' | 'highlight'): TemplateResult {\n const property = popup === 'color' ? 'color' : 'background-color';\n return html`<div\n id=${popup}\n class=\"colors\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${context.t(`toolbar.${popup}`)}\n part=\"style-colors\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n context.close(true);\n }\n }}\n @focusout=${(event: FocusEvent) => {\n const next = event.relatedTarget as Node | null;\n if (next !== null && !(event.currentTarget as HTMLElement).contains(next)) context.close(false);\n }}\n >\n ${colorControl({\n id: popup,\n value: context.styles.text[property] ?? null,\n t: context.t,\n invalid: context.colorError,\n ground: popup === 'highlight',\n pick: (value) => context.setText({ [property]: value }),\n refuse: context.refuseColor,\n })}\n </div>`;\n}\n\n/** The default of `astl-style-open`: the form or the rules in a popup. */\nfunction panel(context: StylePopupContext, target: StyleOpen['target']): TemplateResult {\n const { t, authoring, adapter } = context;\n const title = t(target === 'rules' ? 'style.rules.title' : `style.target.${target}`);\n return html`<div\n id=\"panel\"\n class=\"panel\"\n popover=\"manual\"\n role=\"dialog\"\n tabindex=\"-1\"\n aria-label=${title}\n part=\"style-panel\"\n >\n <div class=\"panel-head\">\n <span>${title}</span>\n <button type=\"button\" data-close @click=${() => context.close(true)}>${t('style.close')}</button>\n </div>\n ${\n target === 'rules'\n ? html`<astl-style-rules .authoring=${authoring} .adapter=${adapter}></astl-style-rules>`\n : html`<astl-style-form .authoring=${authoring} .adapter=${adapter} .target=${target}></astl-style-form>`\n }\n </div>`;\n}\n\n/** The popup that is open. */\nexport function stylePopup(context: StylePopupContext): TemplateResult {\n const { popup, styles, t, fonts, setText, setBlock } = context;\n if (typeof popup === 'object') return panel(context, popup.panel);\n if (popup === 'color' || popup === 'highlight') return colors(context, popup);\n const { text } = styles;\n const none = { value: null, label: t('toolbar.default') };\n const block = styleMapOf(styles.targets.find((target) => target.kind === 'block')?.style ?? '');\n const number = (value: string | undefined) =>\n value === undefined ? null : String(Number.parseFloat(value));\n if (popup === 'font')\n return choiceMenu(\n context,\n 'font',\n [\n {\n choices: [\n none,\n ...fonts.map((font) => ({ value: font.stack, label: font.name, font: font.stack })),\n ],\n now: text['font-family'] ?? null,\n },\n ],\n (choice) => setText({ 'font-family': choice.value }),\n t('toolbar.font.name'),\n );\n if (popup === 'size')\n return choiceMenu(\n context,\n 'size',\n [\n {\n choices: [none, ...FONT_SIZES.map((n) => ({ value: `${n}px`, label: String(n) }))],\n now: text['font-size'] ?? null,\n },\n ],\n (choice) => setText({ 'font-size': choice.value }),\n t('toolbar.size.name'),\n );\n if (popup === 'align') {\n const now = block.get('text-align');\n return choiceMenu(\n context,\n 'align',\n [\n {\n choices: ALIGNS.map((value) => ({ value, label: t(`toolbar.align.${value}`) })),\n now: now === 'left' ? 'start' : now === 'right' ? 'end' : (now ?? 'start'),\n },\n ],\n (choice) => setBlock({ 'text-align': choice.value === 'start' ? null : choice.value }),\n t('toolbar.align'),\n );\n }\n return choiceMenu(\n context,\n 'spacing',\n [\n {\n title: t('toolbar.spacing.line'),\n choices: [none, ...LINE_HEIGHTS.map((value) => ({ value, label: value }))],\n now: number(block.get('line-height')),\n },\n {\n title: t('toolbar.spacing.after'),\n choices: [\n none,\n ...BLOCK_SPACES.map(([value, name]) => ({ value, label: t(`toolbar.spacing.${name}`) })),\n ],\n now: block.has('margin-block-end') ? `${number(block.get('margin-block-end'))}px` : null,\n },\n ],\n (choice, group) => setBlock({ [group === 0 ? 'line-height' : 'margin-block-end']: choice.value }),\n t('toolbar.spacing'),\n );\n}\n"],"mappings":"A,6JAgBA,IAAMO,EAAgC,CAAC,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,EAAE,EACnFC,EAAS,CAAC,QAAS,SAAU,MAAO,SAAS,EAC7CC,EAAkC,CAAC,IAAK,OAAQ,MAAO,GAAG,EAC1DC,EAAuD,CAC3D,CAAC,MAAO,MAAM,EACd,CAAC,MAAO,OAAO,EACf,CAAC,OAAQ,QAAQ,EACjB,CAAC,OAAQ,OAAO,CAClB,EAUaC,EAA8B,CAAG;IAC1CN,EAAY;;;;;;;;;;;;;;;;;;;;;;;EAgDhB,SAASO,EACP,EACA,EACA,EAKA,EACA,EACgB,CAChB,MAAO,EAAI;SACJC,EAAM;;;;iBAIEC,EAAM;;eAERC,EAAQ,YAAY;;MAE7BC,EAAO,KACN,EAAO,IAAO,CAAI,qDAAqDC,EAAM,OAASjB,EAAQ;UAC3FiB,EAAM,QAAU,IAAA,GAAYjB,EAAU,CAAI,8CAA8CiB,EAAM,MAAM,QAAQ;UAC5GA,EAAM,QAAQ,IACb,GAAW,CAAI;;;;yBAIDC,EAAO,OAAS,GAAG;2BACjB,OAAOA,EAAO,QAAUD,EAAM,GAAG,EAAE;wBACtCC,EAAO,MAAQlB,EAAQ;yBACpBmB,EAAOD,EAAQE,CAAE,EAAE;;cAEhCF,EAAO,MAAM;oBA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AAsB,EAC/B,QAAS,CAACM,EAAM,GAAGzB,EAAa,IAAK,IAAW,CAAE,QAAO,MAAOgB,CAAM,EAAE,CAAC,EACzE,IAAKW,EAAOD,EAAM,IAAI,aAAa,CAAC,CACtC,EACA,CACE,MAAOP,EAAE,uBAAuB,EAChC,QAAS,CACPM,EACA,GAAGxB,EAAa,KAAK,CAACe,EAAOmB,MAAW,CAAE,QAAO,MAAOhB,EAAE,mBAAmBgB,GAAM,CAAE,EAAE,CACzF,EACA,IAAKT,EAAM,IAAI,kBAAkB,EAAI,GAAGC,EAAOD,EAAM,IAAI,kBAAkB,CAAC,EAAE,IAAM,IACtF,CACF,GACC,EAAQ,IAAUQ,EAAS,EAAG1B,IAAU,EAAI,cAAgB,oBAAqBC,EAAO,KAAM,CAAC,EAChGU,EAAE,iBAAiB,CACrB,CACF,C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as e,E as t,b as n}from"./runtime-
|
|
1
|
+
import{C as e,E as t,b as n}from"./runtime-C25QK5B0.js";import"./declarations-BhqOz1ap.js";import{n as r,r as i,t as a}from"./styles-DiY3VA_T.js";import{a as o}from"./style-placing-DPw1zyrz.js";import{t as s}from"./style-messages-B136zSom.js";var c=[[`paragraph`,`p`],[`heading`,`h3`],[`subheading`,`h4`],[`quote`,`blockquote`],[`list`,`li`],[`caption`,`figcaption`],[`picture`,`img`]],l=class extends i{static styles=[r,a(`astl-style-form`),t`
|
|
2
2
|
h3 {
|
|
3
3
|
margin: 0;
|
|
4
4
|
font-size: 1rem;
|
|
@@ -133,4 +133,4 @@ font-size: var(--astl-size-small);
|
|
|
133
133
|
${this.t(`toolbar.undo`)}
|
|
134
134
|
</button>`}
|
|
135
135
|
</section>`}};export{l as AstlStyleRules};
|
|
136
|
-
//# sourceMappingURL=style-rules-
|
|
136
|
+
//# sourceMappingURL=style-rules-ozpLz2ec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-rules-ChqPVgZn.js","names":["nothing","b","i","A","kitStyles","AuthoringElement","inheritTokens","styleNameFrom","styleMessages","TAGS","AstlStyleRules","changed","#open","key","rule","styles","#styles","label","#newLabel","taken","name","#renaming","text","open","#rename","event","#toggle","#delete","#form","lang","dir","rules","named","full","tag","id","own","#namedRow","#add","button"],"sources":["../../../../editor/src/elements/style-rules.ts"],"sourcesContent":["import type { EditorStyleRule } from '@astl/core';\nimport { MAX_STYLE_RULES } from '@astl/core/declarations';\nimport { type CSSResultGroup, css, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { styleMessages } from '../style-messages.js';\nimport { styleNameFrom } from '../style-placing.js';\nimport { AuthoringElement } from './base.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** The tags of \"Text styles\": what authors call them, and the element each rule reaches. */\nconst TAGS: readonly (readonly [key: string, tag: string])[] = [\n ['paragraph', 'p'],\n ['heading', 'h3'],\n ['subheading', 'h4'],\n ['quote', 'blockquote'],\n ['list', 'li'],\n ['caption', 'figcaption'],\n ['picture', 'img'],\n];\n\n/**\n * `<astl-style-rules>`: the document's rules, each opening the form that edits it. \"Text styles\" holds a rule per tag\n * (every paragraph, every heading of the exercise), \"My styles\" the named ones: add, rename, edit, delete. A deleted\n * style leaves no class behind. Everything is one undo step, undone here or in the editor. A host places it (a view of\n * its own, a card), with `authoring` and `adapter`, after `loadStyleElements`; the toolbar's style menu opens it in a\n * popup otherwise.\n */\nexport class AstlStyleRules extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n inheritTokens('astl-style-form'),\n css`\n h3 {\n margin: 0;\n font-size: 1rem;\n }\n li.row {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n }\n .line {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .line > .name {\n flex: 1 1 8rem;\n justify-content: flex-start;\n }\n .line > .name::after {\n content: '';\n margin-inline-start: auto;\n border-block: 0.3em solid transparent;\n border-inline-start: 0.45em solid currentColor;\n }\n .line > .name[aria-expanded='true']::after {\n rotate: 90deg;\n }\n .line > input {\n flex: 1 1 8rem;\n inline-size: auto;\n }\n form {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n gap: var(--astl-space-2);\n align-items: end;\n }\n form label {\n grid-column: 1 / -1;\n font-weight: 600;\n }\n .undo {\n align-self: flex-start;\n }\n .summary {\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n `,\n ];\n\n /** The rule whose form is open: `for:<tag>` or `name:<name>`. */\n #open: string | null = null;\n /** The named style being renamed. */\n #renaming: string | null = null;\n #newLabel = '';\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring')) this.authoring?.addMessages(styleMessages);\n }\n\n #styles() {\n return this.adapter?.style ?? null;\n }\n\n #toggle(key: string): void {\n this.#open = this.#open === key ? null : key;\n this.requestUpdate();\n }\n\n #form(rule: Pick<EditorStyleRule, 'name' | 'for'>): TemplateResult {\n return html`<astl-style-form\n .authoring=${this.authoring}\n .adapter=${this.adapter}\n .rule=${rule}\n ></astl-style-form>`;\n }\n\n #add(): void {\n const styles = this.#styles();\n const label = this.#newLabel.trim();\n if (styles === null || label === '') {\n this.renderRoot.querySelector<HTMLInputElement>('#new-style')?.focus();\n return;\n }\n const taken = new Set(styles.rules().flatMap((rule) => rule.name ?? []));\n const name = styleNameFrom(label, taken);\n if (styles.setRule({ name, label, style: '' })) {\n this.#newLabel = '';\n this.#open = `name:${name}`;\n }\n this.requestUpdate();\n }\n\n #rename(rule: EditorStyleRule, text: string): void {\n // Removing the field after Enter or Escape fires its change: that one is not a rename.\n if (this.#renaming !== rule.name) return;\n const label = text.trim();\n if (label !== '') this.#styles()?.setRule({ ...rule, label });\n this.#renaming = null;\n this.requestUpdate();\n }\n\n #delete(rule: EditorStyleRule): void {\n this.#styles()?.removeRule({ ...(rule.name === undefined ? {} : { name: rule.name }) });\n if (this.#open === `name:${rule.name}`) this.#open = null;\n // The row and its button are gone: the focus goes to what is next to it for sure.\n this.requestUpdate();\n void this.updateComplete.then(() => this.renderRoot.querySelector<HTMLElement>('#new-style')?.focus());\n }\n\n #namedRow(rule: EditorStyleRule): TemplateResult {\n const key = `name:${rule.name}`;\n const label = rule.label ?? rule.name ?? '';\n const open = this.#open === key;\n return html`<li class=\"row\" data-style=${rule.name ?? ''}>\n <div class=\"line\">\n ${\n this.#renaming === rule.name\n ? html`<input\n type=\"text\"\n aria-label=${this.t('style.rules.renameField', { label })}\n .value=${label}\n @change=${(event: Event) => this.#rename(rule, (event.target as HTMLInputElement).value)}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n this.#rename(rule, (event.target as HTMLInputElement).value);\n } else if (event.key === 'Escape') {\n event.preventDefault();\n this.#renaming = null;\n this.requestUpdate();\n }\n }}\n />`\n : html`<button\n type=\"button\"\n class=\"name\"\n data-edit\n aria-expanded=${String(open)}\n aria-label=${this.t('style.rules.edit', { label })}\n @click=${() => this.#toggle(key)}\n >\n ${label}\n </button>`\n }\n <button\n type=\"button\"\n data-rename\n aria-label=${this.t('style.rules.rename', { label })}\n @click=${() => {\n this.#renaming = rule.name ?? null;\n this.requestUpdate();\n void this.updateComplete.then(() =>\n this.renderRoot.querySelector<HTMLInputElement>(`[data-style=\"${rule.name}\"] input`)?.select(),\n );\n }}\n >\n ${this.t('style.rules.renameShort')}\n </button>\n <button\n type=\"button\"\n data-delete\n aria-label=${this.t('style.rules.delete', { label })}\n @click=${() => this.#delete(rule)}\n >\n ${this.t('style.rules.deleteShort')}\n </button>\n </div>\n ${open ? this.#form({ ...(rule.name === undefined ? {} : { name: rule.name }) }) : nothing}\n </li>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const styles = this.#styles();\n if (styles === null)\n return html`<p class=\"note\" lang=${lang} dir=${dir}>${this.t('style.form.none')}</p>`;\n const rules = styles.rules();\n const named = rules.filter((rule) => rule.name !== undefined);\n const full = rules.length >= MAX_STYLE_RULES;\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"rules-title\">\n <h2 class=\"title\" id=\"rules-title\" part=\"title\">${this.t('style.rules.title')}</h2>\n <h3 id=\"tags-title\">${this.t('style.rules.tags')}</h3>\n <ul role=\"list\" aria-labelledby=\"tags-title\">\n ${TAGS.map(([key, tag]) => {\n const id = `for:${tag}`;\n const open = this.#open === id;\n const label = this.t(`style.tag.${key}`);\n const own = rules.find((rule) => rule.for === tag)?.style;\n return html`<li class=\"row\" data-for=${tag}>\n <div class=\"line\">\n <button\n type=\"button\"\n class=\"name\"\n data-edit\n aria-expanded=${String(open)}\n aria-label=${this.t('style.rules.edit', { label })}\n @click=${() => this.#toggle(id)}\n >\n ${label}\n </button>\n </div>\n ${own === undefined ? nothing : html`<span class=\"summary\">${own}</span>`}\n ${open ? this.#form({ for: tag }) : nothing}\n </li>`;\n })}\n </ul>\n <h3 id=\"named-title\">${this.t('toolbar.myStyles')}</h3>\n ${\n named.length === 0\n ? html`<p class=\"note\">${this.t('style.rules.empty')}</p>`\n : html`<ul role=\"list\" aria-labelledby=\"named-title\">${named.map((rule) => this.#namedRow(rule))}</ul>`\n }\n <form\n @submit=${(event: Event) => {\n event.preventDefault();\n this.#add();\n }}\n >\n <label for=\"new-style\">${this.t('style.rules.newLabel')}</label>\n <input\n id=\"new-style\"\n type=\"text\"\n autocomplete=\"off\"\n .value=${this.#newLabel}\n @input=${(event: Event) => {\n this.#newLabel = (event.target as HTMLInputElement).value;\n }}\n />\n <button type=\"submit\" data-add ?disabled=${full}>${this.t('style.rules.add')}</button>\n </form>\n ${\n this.adapter?.undo === undefined\n ? nothing\n : html`<button\n type=\"button\"\n class=\"undo\"\n data-undo\n @click=${(event: Event) => {\n const button = event.currentTarget as HTMLElement;\n this.adapter?.undo?.();\n // Undoing focuses the text a frame later; the author is still here, and in a host's view the text is\n // not on show.\n requestAnimationFrame(() => button.focus());\n this.requestUpdate();\n }}\n >\n ${this.t('toolbar.undo')}\n </button>`\n }\n </section>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-style-rules': AstlStyleRules;\n }\n}\n"],"mappings":"A,mPASA,IAAMS,EAAyD,CAC7D,CAAC,YAAa,GAAG,EACjB,CAAC,UAAW,IAAI,EAChB,CAAC,aAAc,IAAI,EACnB,CAAC,QAAS,YAAY,EACtB,CAAC,OAAQ,IAAI,EACb,CAAC,UAAW,YAAY,EACxB,CAAC,UAAW,KAAK,CACnB,EASaC,EAAb,cAAoCL,CAAiB,CACnD,OAAgB,OAAyB,CACvCD,EACAE,EAAc,iBAAiB,EAC/B,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDL,EAGA,GAAuB,KAEvB,GAA2B,KAC3B,GAAY,GAEZ,WAA8B,EAAqC,CACjE,MAAM,WAAWK,CAAO,EACpBA,EAAQ,IAAI,WAAW,GAAG,KAAK,WAAW,YAAYH,CAAa,CACzE,CAEA,IAAU,CACR,OAAO,KAAK,SAAS,OAAS,IAChC,CAEA,GAAQ,EAAmB,CACzB,KAAKI,GAAQ,KAAKA,KAAUC,EAAM,KAAOA,EACzC,KAAK,cAAc,CACrB,CAEA,GAAM,EAA6D,CACjE,MAAO,EAAI;mBACI,KAAK,UAAU;iBACjB,KAAK,QAAQ;cAChBC,EAAK;wBAEjB,CAEA,IAAa,CACX,IAAMC,EAAS,KAAKC,GAAQ,EACtBC,EAAQ,KAAKC,GAAU,KAAK,EAClC,GAAIH,IAAW,MAAQE,IAAU,GAAI,CACnC,KAAK,WAAW,cAAgC,YAAY,CAAC,EAAE,MAAM,EACrE,MACF,CACA,IAAME,EAAQ,IAAI,IAAIJ,EAAO,MAAM,CAAC,CAAC,QAAS,GAASD,EAAK,MAAQ,CAAC,CAAC,CAAC,EACjEM,EAAOb,EAAcU,EAAOE,CAAK,EACnCJ,EAAO,QAAQ,CAAE,OAAM,QAAO,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G,CAAC,EAAE,MACpD,MAAO,EAAI,4BAA4BA,EAAI;;;;;;gCAMrB,OAAOX,CAAI,EAAE;6BAChB,KAAK,EAAE,mBAAoB,CAAE,OAAM,CAAC,EAAE;6BACpC,KAAKG,GAAQS,CAAE,EAAE;;kBAE9BlB,EAAM;;;cAGVmB,IAAQ,IAAA,GAAYpC,EAAU,CAAI,yBAAyBoC,EAAI,SAAS;cACxEb,EAAO,KAAKK,GAAM,CAAE,IAAKM,CAAI,CAAC,EAAIlC,EAAQ;gBAEhD,CAAC,EAAE;;6BAEkB,KAAK,EAAE,kBAAkB,EAAE;QAEhDgC,EAAM,SAAW,EACb,CAAI,mBAAmB,KAAK,EAAE,mBAAmB,EAAE,MACnD,CAAI,iDAAiDA,EAAM,IAAK,GAAS,KAAKK,GAAUvB,CAAI,CAAC,EAAE,OACpG;;kBAEY,GAAiB,CAC1BW,EAAM,eAAe,EACrB,KAAKa,GAAK,CACZ,EAAE;;iCAEuB,KAAK,EAAE,sBAAsB,EAAE;;;;;mBAK7C,KAAKpB,GAAU;mBACd,GAAiB,CACzB,KAAKA,GAAaO,EAAM,OAA4B,KACtD,EAAE;;mDAEuCQ,EAAK,GAAG,KAAK,EAAE,iBAAiB,EAAE;;QAG7E,KAAK,SAAS,OAAS,IAAA,GACnBjC,EACA,CAAI;;;;uBAIQ,GAAiB,CACzB,IAAMuC,EAASd,EAAM,cACrB,KAAK,SAAS,OAAO,EAGrB,0BAA4Bc,EAAO,MAAM,CAAC,EAC1C,KAAK,cAAc,CACrB,EAAE;;gBAEA,KAAK,EAAE,cAAc,EAAE;uBAEhC;eAEL,CACF,E"}
|
|
1
|
+
{"version":3,"file":"style-rules-ozpLz2ec.js","names":["nothing","b","i","A","kitStyles","AuthoringElement","inheritTokens","styleNameFrom","styleMessages","TAGS","AstlStyleRules","changed","#open","key","rule","styles","#styles","label","#newLabel","taken","name","#renaming","text","open","#rename","event","#toggle","#delete","#form","lang","dir","rules","named","full","tag","id","own","#namedRow","#add","button"],"sources":["../../../../editor/src/elements/style-rules.ts"],"sourcesContent":["import type { EditorStyleRule } from '@astl/core';\nimport { MAX_STYLE_RULES } from '@astl/core/declarations';\nimport { type CSSResultGroup, css, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { styleMessages } from '../style-messages.js';\nimport { styleNameFrom } from '../style-placing.js';\nimport { AuthoringElement } from './base.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** The tags of \"Text styles\": what authors call them, and the element each rule reaches. */\nconst TAGS: readonly (readonly [key: string, tag: string])[] = [\n ['paragraph', 'p'],\n ['heading', 'h3'],\n ['subheading', 'h4'],\n ['quote', 'blockquote'],\n ['list', 'li'],\n ['caption', 'figcaption'],\n ['picture', 'img'],\n];\n\n/**\n * `<astl-style-rules>`: the document's rules, each opening the form that edits it. \"Text styles\" holds a rule per tag\n * (every paragraph, every heading of the exercise), \"My styles\" the named ones: add, rename, edit, delete. A deleted\n * style leaves no class behind. Everything is one undo step, undone here or in the editor. A host places it (a view of\n * its own, a card), with `authoring` and `adapter`, after `loadStyleElements`; the toolbar's style menu opens it in a\n * popup otherwise.\n */\nexport class AstlStyleRules extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n inheritTokens('astl-style-form'),\n css`\n h3 {\n margin: 0;\n font-size: 1rem;\n }\n li.row {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n }\n .line {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .line > .name {\n flex: 1 1 8rem;\n justify-content: flex-start;\n }\n .line > .name::after {\n content: '';\n margin-inline-start: auto;\n border-block: 0.3em solid transparent;\n border-inline-start: 0.45em solid currentColor;\n }\n .line > .name[aria-expanded='true']::after {\n rotate: 90deg;\n }\n .line > input {\n flex: 1 1 8rem;\n inline-size: auto;\n }\n form {\n display: grid;\n grid-template-columns: minmax(0, 1fr) auto;\n gap: var(--astl-space-2);\n align-items: end;\n }\n form label {\n grid-column: 1 / -1;\n font-weight: 600;\n }\n .undo {\n align-self: flex-start;\n }\n .summary {\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n `,\n ];\n\n /** The rule whose form is open: `for:<tag>` or `name:<name>`. */\n #open: string | null = null;\n /** The named style being renamed. */\n #renaming: string | null = null;\n #newLabel = '';\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring')) this.authoring?.addMessages(styleMessages);\n }\n\n #styles() {\n return this.adapter?.style ?? null;\n }\n\n #toggle(key: string): void {\n this.#open = this.#open === key ? null : key;\n this.requestUpdate();\n }\n\n #form(rule: Pick<EditorStyleRule, 'name' | 'for'>): TemplateResult {\n return html`<astl-style-form\n .authoring=${this.authoring}\n .adapter=${this.adapter}\n .rule=${rule}\n ></astl-style-form>`;\n }\n\n #add(): void {\n const styles = this.#styles();\n const label = this.#newLabel.trim();\n if (styles === null || label === '') {\n this.renderRoot.querySelector<HTMLInputElement>('#new-style')?.focus();\n return;\n }\n const taken = new Set(styles.rules().flatMap((rule) => rule.name ?? []));\n const name = styleNameFrom(label, taken);\n if (styles.setRule({ name, label, style: '' })) {\n this.#newLabel = '';\n this.#open = `name:${name}`;\n }\n this.requestUpdate();\n }\n\n #rename(rule: EditorStyleRule, text: string): void {\n // Removing the field after Enter or Escape fires its change: that one is not a rename.\n if (this.#renaming !== rule.name) return;\n const label = text.trim();\n if (label !== '') this.#styles()?.setRule({ ...rule, label });\n this.#renaming = null;\n this.requestUpdate();\n }\n\n #delete(rule: EditorStyleRule): void {\n this.#styles()?.removeRule({ ...(rule.name === undefined ? {} : { name: rule.name }) });\n if (this.#open === `name:${rule.name}`) this.#open = null;\n // The row and its button are gone: the focus goes to what is next to it for sure.\n this.requestUpdate();\n void this.updateComplete.then(() => this.renderRoot.querySelector<HTMLElement>('#new-style')?.focus());\n }\n\n #namedRow(rule: EditorStyleRule): TemplateResult {\n const key = `name:${rule.name}`;\n const label = rule.label ?? rule.name ?? '';\n const open = this.#open === key;\n return html`<li class=\"row\" data-style=${rule.name ?? ''}>\n <div class=\"line\">\n ${\n this.#renaming === rule.name\n ? html`<input\n type=\"text\"\n aria-label=${this.t('style.rules.renameField', { label })}\n .value=${label}\n @change=${(event: Event) => this.#rename(rule, (event.target as HTMLInputElement).value)}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Enter') {\n event.preventDefault();\n this.#rename(rule, (event.target as HTMLInputElement).value);\n } else if (event.key === 'Escape') {\n event.preventDefault();\n this.#renaming = null;\n this.requestUpdate();\n }\n }}\n />`\n : html`<button\n type=\"button\"\n class=\"name\"\n data-edit\n aria-expanded=${String(open)}\n aria-label=${this.t('style.rules.edit', { label })}\n @click=${() => this.#toggle(key)}\n >\n ${label}\n </button>`\n }\n <button\n type=\"button\"\n data-rename\n aria-label=${this.t('style.rules.rename', { label })}\n @click=${() => {\n this.#renaming = rule.name ?? null;\n this.requestUpdate();\n void this.updateComplete.then(() =>\n this.renderRoot.querySelector<HTMLInputElement>(`[data-style=\"${rule.name}\"] input`)?.select(),\n );\n }}\n >\n ${this.t('style.rules.renameShort')}\n </button>\n <button\n type=\"button\"\n data-delete\n aria-label=${this.t('style.rules.delete', { label })}\n @click=${() => this.#delete(rule)}\n >\n ${this.t('style.rules.deleteShort')}\n </button>\n </div>\n ${open ? this.#form({ ...(rule.name === undefined ? {} : { name: rule.name }) }) : nothing}\n </li>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const styles = this.#styles();\n if (styles === null)\n return html`<p class=\"note\" lang=${lang} dir=${dir}>${this.t('style.form.none')}</p>`;\n const rules = styles.rules();\n const named = rules.filter((rule) => rule.name !== undefined);\n const full = rules.length >= MAX_STYLE_RULES;\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"rules-title\">\n <h2 class=\"title\" id=\"rules-title\" part=\"title\">${this.t('style.rules.title')}</h2>\n <h3 id=\"tags-title\">${this.t('style.rules.tags')}</h3>\n <ul role=\"list\" aria-labelledby=\"tags-title\">\n ${TAGS.map(([key, tag]) => {\n const id = `for:${tag}`;\n const open = this.#open === id;\n const label = this.t(`style.tag.${key}`);\n const own = rules.find((rule) => rule.for === tag)?.style;\n return html`<li class=\"row\" data-for=${tag}>\n <div class=\"line\">\n <button\n type=\"button\"\n class=\"name\"\n data-edit\n aria-expanded=${String(open)}\n aria-label=${this.t('style.rules.edit', { label })}\n @click=${() => this.#toggle(id)}\n >\n ${label}\n </button>\n </div>\n ${own === undefined ? nothing : html`<span class=\"summary\">${own}</span>`}\n ${open ? this.#form({ for: tag }) : nothing}\n </li>`;\n })}\n </ul>\n <h3 id=\"named-title\">${this.t('toolbar.myStyles')}</h3>\n ${\n named.length === 0\n ? html`<p class=\"note\">${this.t('style.rules.empty')}</p>`\n : html`<ul role=\"list\" aria-labelledby=\"named-title\">${named.map((rule) => this.#namedRow(rule))}</ul>`\n }\n <form\n @submit=${(event: Event) => {\n event.preventDefault();\n this.#add();\n }}\n >\n <label for=\"new-style\">${this.t('style.rules.newLabel')}</label>\n <input\n id=\"new-style\"\n type=\"text\"\n autocomplete=\"off\"\n .value=${this.#newLabel}\n @input=${(event: Event) => {\n this.#newLabel = (event.target as HTMLInputElement).value;\n }}\n />\n <button type=\"submit\" data-add ?disabled=${full}>${this.t('style.rules.add')}</button>\n </form>\n ${\n this.adapter?.undo === undefined\n ? nothing\n : html`<button\n type=\"button\"\n class=\"undo\"\n data-undo\n @click=${(event: Event) => {\n const button = event.currentTarget as HTMLElement;\n this.adapter?.undo?.();\n // Undoing focuses the text a frame later; the author is still here, and in a host's view the text is\n // not on show.\n requestAnimationFrame(() => button.focus());\n this.requestUpdate();\n }}\n >\n ${this.t('toolbar.undo')}\n </button>`\n }\n </section>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-style-rules': AstlStyleRules;\n }\n}\n"],"mappings":"A,mPASA,IAAMS,EAAyD,CAC7D,CAAC,YA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B,EAAM;;;cAGVmB,IAAQ,IAAA,GAAYpC,EAAU,CAAI,yBAAyBoC,EAAI,SAAS;cACxEb,EAAO,KAAKK,GAAM,CAAE,IAAKM,CAAI,CAAC,EAAIlC,EAAQ;gBAEhD,CAAC,EAAE;;6BAEkB,KAAK,EAAE,kBAAkB,EAAE;QAEhDgC,EAAM,SAAW,EACb,CAAI,mBAAmB,KAAK,EAAE,mBAAmB,EAAE,MACnD,CAAI,iDAAiDA,EAAM,IAAK,GAAS,KAAKK,GAAUvB,CAAI,CAAC,EAAE,OACpG;;kBAEY,GAAiB,CAC1BW,EAAM,eAAe,EACrB,KAAKa,GAAK,CACZ,EAAE;;iCAEuB,KAAK,EAAE,sBAAsB,EAAE;;;;;mBAK7C,KAAKpB,GAAU;mBACd,GAAiB,CACzB,KAAKA,GAAaO,EAAM,OAA4B,KACtD,EAAE;;mDAEuCQ,EAAK,GAAG,KAAK,EAAE,iBAAiB,EAAE;;QAG7E,KAAK,SAAS,OAAS,IAAA,GACnBjC,EACA,CAAI;;;;uBAIQ,GAAiB,CACzB,IAAMuC,EAASd,EAAM,cACrB,KAAK,SAAS,OAAO,EAGrB,0BAA4Bc,EAAO,MAAM,CAAC,EAC1C,KAAK,cAAc,CACrB,EAAE;;gBAEA,KAAK,EAAE,cAAc,EAAE;uBAEhC;eAEL,CACF,E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{E as e,M as t,qt as n}from"./runtime-
|
|
1
|
+
import{E as e,M as t,qt as n}from"./runtime-C25QK5B0.js";import{d as r,l as i,o as a,u as o}from"./declarations-BhqOz1ap.js";var s=4.6,c=/#[0-9a-f]+|rgba?\([^()]*\)/g,l=/^[\d.]/,u=new Set([`width`,`max-width`,`inline-size`,`max-inline-size`]),d=e=>e===`background-color`||e===`box-shadow`?`--astl-author-ground`:`--astl-author-ink`,f=e=>o(e),p=f(t.themes.dark[`surface-raised`]),m=f(t.themes.dark.ink);function h([e,t,n]){let[r,i,a]=[e/255,t/255,n/255],o=Math.max(r,i,a),s=Math.min(r,i,a),c=(o+s)/2,l=o-s;return l===0?[0,0,c]:[o===r?((i-a)/l+6)%6:o===i?(a-r)/l+2:(r-i)/l+4,l/(1-Math.abs(2*c-1)),c]}function g([e,t,n],r){let i=t*Math.min(n,1-n),a=t=>{let r=(t+e*2)%12;return Math.round((n-i*Math.max(-1,Math.min(r-3,9-r,1)))*255)};return[a(0),a(8),a(4),r]}function _(e){let[t,n,r]=h(e);return g([t,n,1-r],e[3])}var v=(e,t)=>r(i(e,t),t);function y(e,t){if(v(e,t)>=s)return e;let[n,r,i]=h(e),a=t=>g([n,r,t],e[3]),o=+(v(a(1),t)>=v(a(0),t)),c=i;for(let e=0;e<8;e++){let e=(o+c)/2;v(a(e),t)>=s?o=e:c=e}return a(o)}var b=([e,t,n,r])=>{let i=[e,t,n].map(Math.round).join(`, `);return r===1?`rgb(${i})`:`rgba(${i}, ${r})`},x=(e,t)=>{let n=e.find(([e])=>e===t)?.[1];return n===void 0?null:o(n)};function S(e,t){let n=t.inked||x(e,`color`)!==null,r=x(e,`background-color`);if(r===null)return{ground:t.ground,inked:n};let a=i(_(r),t.ground);return{ground:n?a:y(a,m),inked:n}}function C(e,t,n){return e===`font-family`?t:e===`font-size`?l.test(t)?`clamp(0.625rem, ${t}, 6rem)`:t:u.has(e)?l.test(t)&&!t.endsWith(`%`)?`min(${t}, 100%)`:t:t.replace(c,t=>{let r=f(t),i=e===`color`?y(_(r),n.ground):e===`background-color`?n.ground:_(r);return`var(${d(e)}, light-dark(${t}, ${b(i)}))`})}function w(e){let t=new Map,r=new Map,i={ground:p,inked:!1};for(let o of Array.from(e.querySelectorAll(`[${n}]`))){let{declarations:e}=a(o.getAttribute(`data-astl-style`)??``);o.removeAttribute(n);let s=i;for(let e=o.parentElement;e!==null;e=e.parentElement){let t=r.get(e);if(t!==void 0){s=t;break}}let c=S(e,s);r.set(o,c),t.set(o,e.map(([e,t])=>[e,C(e,t,c)]))}return t}function T(e,t,n){let r=n.querySelectorAll(`*`);t.querySelectorAll(`*`).forEach((t,n)=>{for(let[i,a]of e.get(t)??[])r[n]?.style.setProperty(i,a)})}var E=e`
|
|
2
2
|
.canvas {
|
|
3
3
|
container-type: inline-size;
|
|
4
4
|
}
|
|
@@ -54,4 +54,4 @@ display: block;
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
`.styleSheet;function D(e){E!==void 0&&e instanceof ShadowRoot&&!e.adoptedStyleSheets.includes(E)&&(e.adoptedStyleSheets=[...e.adoptedStyleSheets,E])}export{D as adoptStyledSheet,T as applyStyles,w as takeStyles};
|
|
57
|
-
//# sourceMappingURL=styled-
|
|
57
|
+
//# sourceMappingURL=styled-bQqnDxBf.js.map
|
|
@@ -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(styledShe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,KAAM,EAAKA,EAAG,cAAe,CAClE,IAAMC,EAAQL,EAAS,IAAII,CAAE,EAC7B,GAAIC,IAAU,IAAA,GAAW,CACvB,EAASA,EACT,KACF,CACF,CACA,IAAMR,EAAUP,EAAYF,EAAcI,CAAM,EAChDQ,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,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K,mBAAmB,SAASF,CAAW,IAE7C,EAAK,mBAAqB,CAAC,GAAGE,EAAK,mBAAoBF,CAAW,EAEtE,C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{D as e,E as t,M as n,Pt as r,_ as i,k as a,y as o}from"./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,CAE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