@astl/astrolabe 0.0.0 → 0.1.1

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.
Files changed (188) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +202 -0
  3. package/README.md +65 -0
  4. package/dist/cdn/astrolabe-editor.js +1441 -0
  5. package/dist/cdn/astrolabe-editor.js.map +1 -0
  6. package/dist/cdn/astrolabe-player.js +2 -0
  7. package/dist/cdn/astrolabe-player.js.map +1 -0
  8. package/dist/cdn/astrolabe.css +238 -0
  9. package/dist/cdn/astrolabe.js +3 -0
  10. package/dist/cdn/astrolabe.js.map +1 -0
  11. package/dist/cdn/astrolabe.standalone.js +8007 -0
  12. package/dist/cdn/chunks/audio-B0LSIn5N.js +48 -0
  13. package/dist/cdn/chunks/audio-B0LSIn5N.js.map +1 -0
  14. package/dist/cdn/chunks/audio-manifest-B9FWQzRy.js +2 -0
  15. package/dist/cdn/chunks/audio-manifest-B9FWQzRy.js.map +1 -0
  16. package/dist/cdn/chunks/block-styles-CKo9x7Vt.js +68 -0
  17. package/dist/cdn/chunks/block-styles-CKo9x7Vt.js.map +1 -0
  18. package/dist/cdn/chunks/book-CHzDDaim.js +15 -0
  19. package/dist/cdn/chunks/book-CHzDDaim.js.map +1 -0
  20. package/dist/cdn/chunks/callout-QFLFLPc5.js +49 -0
  21. package/dist/cdn/chunks/callout-QFLFLPc5.js.map +1 -0
  22. package/dist/cdn/chunks/callout-manifest-Cb12O4jl.js +2 -0
  23. package/dist/cdn/chunks/callout-manifest-Cb12O4jl.js.map +1 -0
  24. package/dist/cdn/chunks/categorise-BO2tNVJ3.js +203 -0
  25. package/dist/cdn/chunks/categorise-BO2tNVJ3.js.map +1 -0
  26. package/dist/cdn/chunks/categorise-manifest-C_hEDVYQ.js +2 -0
  27. package/dist/cdn/chunks/categorise-manifest-C_hEDVYQ.js.map +1 -0
  28. package/dist/cdn/chunks/chip-styles-Dme5daTO.js +77 -0
  29. package/dist/cdn/chunks/chip-styles-Dme5daTO.js.map +1 -0
  30. package/dist/cdn/chunks/choice-CExBvqKj.js +136 -0
  31. package/dist/cdn/chunks/choice-CExBvqKj.js.map +1 -0
  32. package/dist/cdn/chunks/choice-manifest-C-XahD7m.js +2 -0
  33. package/dist/cdn/chunks/choice-manifest-C-XahD7m.js.map +1 -0
  34. package/dist/cdn/chunks/color-control-Cl5cuMSO.js +91 -0
  35. package/dist/cdn/chunks/color-control-Cl5cuMSO.js.map +1 -0
  36. package/dist/cdn/chunks/crossword-Cb-a3Tjj.js +270 -0
  37. package/dist/cdn/chunks/crossword-Cb-a3Tjj.js.map +1 -0
  38. package/dist/cdn/chunks/crossword-manifest-2qlu7AYd.js +2 -0
  39. package/dist/cdn/chunks/crossword-manifest-2qlu7AYd.js.map +1 -0
  40. package/dist/cdn/chunks/declarations-BhqOz1ap.js +2 -0
  41. package/dist/cdn/chunks/declarations-BhqOz1ap.js.map +1 -0
  42. package/dist/cdn/chunks/definitions-CNX90WtL.js +6 -0
  43. package/dist/cdn/chunks/definitions-CNX90WtL.js.map +1 -0
  44. package/dist/cdn/chunks/directive-helpers-D7lOZKnB.js +14 -0
  45. package/dist/cdn/chunks/directive-helpers-D7lOZKnB.js.map +1 -0
  46. package/dist/cdn/chunks/drop-manifest-bzNOa5ks.js +2 -0
  47. package/dist/cdn/chunks/drop-manifest-bzNOa5ks.js.map +1 -0
  48. package/dist/cdn/chunks/drop-vRXndjHu.js +86 -0
  49. package/dist/cdn/chunks/drop-vRXndjHu.js.map +1 -0
  50. package/dist/cdn/chunks/flash-cards-0NrrKdrx.js +87 -0
  51. package/dist/cdn/chunks/flash-cards-0NrrKdrx.js.map +1 -0
  52. package/dist/cdn/chunks/flash-cards-manifest-B8nWXbRy.js +2 -0
  53. package/dist/cdn/chunks/flash-cards-manifest-B8nWXbRy.js.map +1 -0
  54. package/dist/cdn/chunks/gap-lor-khst.js +78 -0
  55. package/dist/cdn/chunks/gap-lor-khst.js.map +1 -0
  56. package/dist/cdn/chunks/gap-manifest-RSydA41N.js +2 -0
  57. package/dist/cdn/chunks/gap-manifest-RSydA41N.js.map +1 -0
  58. package/dist/cdn/chunks/help-C-woafz5.js +138 -0
  59. package/dist/cdn/chunks/help-C-woafz5.js.map +1 -0
  60. package/dist/cdn/chunks/help-form-DaC6KaFG.js +160 -0
  61. package/dist/cdn/chunks/help-form-DaC6KaFG.js.map +1 -0
  62. package/dist/cdn/chunks/hotspot-manifest-CNs1oiZ_.js +2 -0
  63. package/dist/cdn/chunks/hotspot-manifest-CNs1oiZ_.js.map +1 -0
  64. package/dist/cdn/chunks/hotspot-oel1Eelo.js +154 -0
  65. package/dist/cdn/chunks/hotspot-oel1Eelo.js.map +1 -0
  66. package/dist/cdn/chunks/image-drop-Dkprw0Kn.js +295 -0
  67. package/dist/cdn/chunks/image-drop-Dkprw0Kn.js.map +1 -0
  68. package/dist/cdn/chunks/image-drop-manifest-BZ6hCoAd.js +2 -0
  69. package/dist/cdn/chunks/image-drop-manifest-BZ6hCoAd.js.map +1 -0
  70. package/dist/cdn/chunks/image-label-Dm5shQSh.js +177 -0
  71. package/dist/cdn/chunks/image-label-Dm5shQSh.js.map +1 -0
  72. package/dist/cdn/chunks/image-label-manifest--1CLRJzd.js +2 -0
  73. package/dist/cdn/chunks/image-label-manifest--1CLRJzd.js.map +1 -0
  74. package/dist/cdn/chunks/inline-styles-CTgXWnHb.js +80 -0
  75. package/dist/cdn/chunks/inline-styles-CTgXWnHb.js.map +1 -0
  76. package/dist/cdn/chunks/insert-menu-LgrifBYT.js +80 -0
  77. package/dist/cdn/chunks/insert-menu-LgrifBYT.js.map +1 -0
  78. package/dist/cdn/chunks/issue-list-BgnXzXRM.js +51 -0
  79. package/dist/cdn/chunks/issue-list-BgnXzXRM.js.map +1 -0
  80. package/dist/cdn/chunks/keys-DU-Qknmz.js +2 -0
  81. package/dist/cdn/chunks/keys-DU-Qknmz.js.map +1 -0
  82. package/dist/cdn/chunks/live-jdiyYln2.js +7 -0
  83. package/dist/cdn/chunks/live-jdiyYln2.js.map +1 -0
  84. package/dist/cdn/chunks/long-answer-CtzClLAx.js +71 -0
  85. package/dist/cdn/chunks/long-answer-CtzClLAx.js.map +1 -0
  86. package/dist/cdn/chunks/long-answer-manifest-BYJpZRtB.js +2 -0
  87. package/dist/cdn/chunks/long-answer-manifest-BYJpZRtB.js.map +1 -0
  88. package/dist/cdn/chunks/mark-words-CpH3gTcX.js +131 -0
  89. package/dist/cdn/chunks/mark-words-CpH3gTcX.js.map +1 -0
  90. package/dist/cdn/chunks/mark-words-manifest-Cs2pXCEx.js +2 -0
  91. package/dist/cdn/chunks/mark-words-manifest-Cs2pXCEx.js.map +1 -0
  92. package/dist/cdn/chunks/match-DKE_4o-x.js +352 -0
  93. package/dist/cdn/chunks/match-DKE_4o-x.js.map +1 -0
  94. package/dist/cdn/chunks/match-manifest-D0UfoajU.js +2 -0
  95. package/dist/cdn/chunks/match-manifest-D0UfoajU.js.map +1 -0
  96. package/dist/cdn/chunks/memory-B6hSyHyz.js +187 -0
  97. package/dist/cdn/chunks/memory-B6hSyHyz.js.map +1 -0
  98. package/dist/cdn/chunks/memory-manifest-D1589iR0.js +2 -0
  99. package/dist/cdn/chunks/memory-manifest-D1589iR0.js.map +1 -0
  100. package/dist/cdn/chunks/menu-messages-Dx3jYUEp.js +2 -0
  101. package/dist/cdn/chunks/menu-messages-Dx3jYUEp.js.map +1 -0
  102. package/dist/cdn/chunks/messages-9xiYDvRT.js +2 -0
  103. package/dist/cdn/chunks/messages-9xiYDvRT.js.map +1 -0
  104. package/dist/cdn/chunks/option-styles-WKzjKmCH.js +50 -0
  105. package/dist/cdn/chunks/option-styles-WKzjKmCH.js.map +1 -0
  106. package/dist/cdn/chunks/order-BhG_6IC-.js +225 -0
  107. package/dist/cdn/chunks/order-BhG_6IC-.js.map +1 -0
  108. package/dist/cdn/chunks/order-manifest-J5IXN0he.js +2 -0
  109. package/dist/cdn/chunks/order-manifest-J5IXN0he.js.map +1 -0
  110. package/dist/cdn/chunks/pick-and-place-DVQIPYuL.js +2 -0
  111. package/dist/cdn/chunks/pick-and-place-DVQIPYuL.js.map +1 -0
  112. package/dist/cdn/chunks/picture-D10YRMYH.js +2 -0
  113. package/dist/cdn/chunks/picture-D10YRMYH.js.map +1 -0
  114. package/dist/cdn/chunks/picture-view-BKnAyScQ.js +92 -0
  115. package/dist/cdn/chunks/picture-view-BKnAyScQ.js.map +1 -0
  116. package/dist/cdn/chunks/repeat-CY2W2URZ.js +8 -0
  117. package/dist/cdn/chunks/repeat-CY2W2URZ.js.map +1 -0
  118. package/dist/cdn/chunks/roving-focus-BxGgi2DD.js +2 -0
  119. package/dist/cdn/chunks/roving-focus-BxGgi2DD.js.map +1 -0
  120. package/dist/cdn/chunks/runtime-DxAbpr3S.js +526 -0
  121. package/dist/cdn/chunks/runtime-DxAbpr3S.js.map +1 -0
  122. package/dist/cdn/chunks/scan-jWgPnVxA.js +2 -0
  123. package/dist/cdn/chunks/scan-jWgPnVxA.js.map +1 -0
  124. package/dist/cdn/chunks/select-DTA3dJzr.js +345 -0
  125. package/dist/cdn/chunks/select-DTA3dJzr.js.map +1 -0
  126. package/dist/cdn/chunks/select-manifest-BBMbvdkH.js +2 -0
  127. package/dist/cdn/chunks/select-manifest-BBMbvdkH.js.map +1 -0
  128. package/dist/cdn/chunks/source-view-DXKPFCl9.js +29 -0
  129. package/dist/cdn/chunks/source-view-DXKPFCl9.js.map +1 -0
  130. package/dist/cdn/chunks/style-form-D5haJtWM.js +240 -0
  131. package/dist/cdn/chunks/style-form-D5haJtWM.js.map +1 -0
  132. package/dist/cdn/chunks/style-messages-BbZpeD2a.js +2 -0
  133. package/dist/cdn/chunks/style-messages-BbZpeD2a.js.map +1 -0
  134. package/dist/cdn/chunks/style-model-ZXNe_c8R.js +2 -0
  135. package/dist/cdn/chunks/style-model-ZXNe_c8R.js.map +1 -0
  136. package/dist/cdn/chunks/style-placing-DPw1zyrz.js +2 -0
  137. package/dist/cdn/chunks/style-placing-DPw1zyrz.js.map +1 -0
  138. package/dist/cdn/chunks/style-popups-BobgX1WK.js +74 -0
  139. package/dist/cdn/chunks/style-popups-BobgX1WK.js.map +1 -0
  140. package/dist/cdn/chunks/style-rules-D45PZLCv.js +136 -0
  141. package/dist/cdn/chunks/style-rules-D45PZLCv.js.map +1 -0
  142. package/dist/cdn/chunks/styled-Dmx5Yjv7.js +57 -0
  143. package/dist/cdn/chunks/styled-Dmx5Yjv7.js.map +1 -0
  144. package/dist/cdn/chunks/styles-DxJJxVNH.js +136 -0
  145. package/dist/cdn/chunks/styles-DxJJxVNH.js.map +1 -0
  146. package/dist/cdn/chunks/surface-CgxfAwCR.js +1019 -0
  147. package/dist/cdn/chunks/surface-CgxfAwCR.js.map +1 -0
  148. package/dist/cdn/chunks/true-false-DP3MO599.js +146 -0
  149. package/dist/cdn/chunks/true-false-DP3MO599.js.map +1 -0
  150. package/dist/cdn/chunks/true-false-manifest-B4exv60u.js +2 -0
  151. package/dist/cdn/chunks/true-false-manifest-B4exv60u.js.map +1 -0
  152. package/dist/cdn/chunks/video-j9MCH6Kw.js +98 -0
  153. package/dist/cdn/chunks/video-j9MCH6Kw.js.map +1 -0
  154. package/dist/cdn/chunks/video-manifest-8OwkhhAI.js +2 -0
  155. package/dist/cdn/chunks/video-manifest-8OwkhhAI.js.map +1 -0
  156. package/dist/cdn/chunks/word-bank-ARjwUKZf.js +80 -0
  157. package/dist/cdn/chunks/word-bank-ARjwUKZf.js.map +1 -0
  158. package/dist/cdn/chunks/word-bank-manifest-C1FSo1kH.js +2 -0
  159. package/dist/cdn/chunks/word-bank-manifest-C1FSo1kH.js.map +1 -0
  160. package/dist/cdn/chunks/word-search-AHvM7yCJ.js +274 -0
  161. package/dist/cdn/chunks/word-search-AHvM7yCJ.js.map +1 -0
  162. package/dist/cdn/chunks/word-search-manifest-Fg1a59Z1.js +2 -0
  163. package/dist/cdn/chunks/word-search-manifest-Fg1a59Z1.js.map +1 -0
  164. package/dist/editor.d.ts +32 -0
  165. package/dist/editor.d.ts.map +1 -0
  166. package/dist/editor.js +51 -0
  167. package/dist/editor.js.map +1 -0
  168. package/dist/engine.d.ts +33 -0
  169. package/dist/engine.d.ts.map +1 -0
  170. package/dist/engine.js +53 -0
  171. package/dist/engine.js.map +1 -0
  172. package/dist/player.d.ts +19 -0
  173. package/dist/player.d.ts.map +1 -0
  174. package/dist/player.js +22 -0
  175. package/dist/player.js.map +1 -0
  176. package/dist/server.d.ts +8 -0
  177. package/dist/server.d.ts.map +1 -0
  178. package/dist/server.js +8 -0
  179. package/dist/server.js.map +1 -0
  180. package/package.json +82 -4
  181. package/src/bundles/astrolabe-editor.ts +11 -0
  182. package/src/bundles/astrolabe-player.ts +10 -0
  183. package/src/bundles/astrolabe-standalone.ts +23 -0
  184. package/src/bundles/astrolabe.ts +12 -0
  185. package/src/editor.ts +98 -0
  186. package/src/engine.ts +59 -0
  187. package/src/player.ts +23 -0
  188. package/src/server.ts +7 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-menu-LgrifBYT.js","names":["childrenOf","nothing","parseHtml","engineMessages","localChecker","allAttributes","b","i","isSourceId","SCORING_ATTRIBUTES","w","DOC_TAG","isSafeUrl","A","element","isElement","PAGE_TAG","createI18n","textContent","strictUrlPolicy","STYLE_TEMPLATE_ATTRIBUTE","cleanStyle","isStyleName","escapeHtml","scanRanges","usedIds","escapeAttribute","spaceBefore","attributeValue","escapeText","elementTree","scanElements","applyEdits","tokenize","editorMessages","EDITOR_NAMESPACE","DEFAULT_STYLES","layoutHtml","LAYOUTS","DEFAULT_FONTS","kitStyles","AuthoringElement","inheritTokens","NAME","attributeEdits","name","written","tag","a","first","value","source","current","text","at","childrenOf$1","root","c","textOf","node","range","contentEnd","contentEdit","open","html","appendEdit","separator","children","gap","textListEdits","edits","values","child","sep","added","v","last","updateElement","change","out","attribute","attributes","own","el","childrenOf","n","deriveFields","spec","editable","scoring","manifest","common","s","selectOptions","texts","defaultOf","attributeModel","field","label","fallbackLabel","help","base","required","from","find","childOptions","isScoring","options","o","accept","pictureTags","fields","f","shapesOf","shapes","shape","fieldModel","picture","childLabel","labelOf","index","counts","fallback","described","choiceSource","childTable","percent","flag","flagName","pointsOf","columns","attr","column","number","prefix","taken","pair","x","y","said","choices","parent","id","option","styleTemplateField","unset","templates","variantOf","forVariant","variant","commonFields","has","listed","inspectorModel","declared","descriptor","normalFont","stack","font","readyStyles","names","presets","preset","removed","UploadRefused","message","refusalOf","error","pictureSize","pictureHtml","size","img","caption","sessionSalt","bytes","TEMPLATE_ID","freshId","used","withoutRules","nodes","firstElement","DEFAULT_POINTS","sum","numbers","count","issue","issues","where","createAuthoring","registered","engine","m","byTag","ids","template","styleTemplates","i18nWith","d","later","i18n","addMessages","catalogs","catalog","menus","t","locale","namespace","key","params","manifestOf","salt","textsFor","templateOptions","scope","outline","idOf","entry","components","block","parts","part","points","blocks","run","flush","content","page","list","pages","loose","p","named","namesIn","paged","set","inText","seen","walk","withIds","fresh","linkCompanions","companion","other","within","instantiate","templateId","selection","doc","elements","pageOf","companionsOf","e","target","elementHtml","start","result","STYLE_OPEN","registry","loading","styleElementsIn","loadStyleElements","AstlStyleForm","AstlStyleRules","helping","loadHelpForm","module","AstlHelpForm","GLYPHS","TYPE_GLYPHS","HELP_KINDS","GROUPS","INSERTED","searchable","pictureAttribute","withPicture","found","authoring","takes","AstlInsertMenu","changed","popover","#menus","adapter","selected","instantiated","next","#inserted","#press","#dialog","dialog","addHelp","kind","query","description","data","press","icon","glyph","items","entries","item","title","messages","line","shows","group","#button","exercises","layouts","none","lang","dir","#group"],"sources":["../../../../editor/src/edit.ts","../../../../editor/src/inspect.ts","../../../../editor/src/authoring.ts","../../../../editor/src/elements/style-load.ts","../../../../editor/src/elements/insert-menu.ts"],"sourcesContent":["/**\n * Minimal text edits on one element's source HTML: set or remove an attribute, replace repeated text children, toggle\n * a flag or set a value on a child. Everything the change does not touch stays byte-identical (formatting, quotes,\n * other children).\n */\nimport { isElement, textContent } from '@astl/core';\nimport { parseHtml } from '@astl/engine';\nimport {\n applyEdits,\n attributeValue,\n type Edit,\n type ElementRange,\n elementTree,\n escapeAttribute,\n escapeText,\n spaceBefore,\n type TagToken,\n} from './scan.js';\n\n/** What an inspector control changes. Indexes count children with the same tag, from 0. */\nexport type InspectorChange =\n | {\n readonly kind: 'attribute';\n readonly name: string;\n /** A string sets the value, `true` writes a bare boolean attribute, `false` or null removes it. */\n readonly value: string | boolean | null;\n }\n | { readonly kind: 'text-list'; readonly tag: string; readonly values: readonly string[] }\n | {\n readonly kind: 'child-flag';\n readonly tag: string;\n readonly attribute: string;\n readonly index: number;\n readonly value: boolean;\n }\n | {\n readonly kind: 'child-choice';\n readonly tag: string;\n readonly attribute: string;\n readonly index: number;\n /** The value to write; null removes the attribute. */\n readonly value: string | null;\n }\n | {\n /** Several attributes of one child (a zone's shape and coordinates): a string sets one, null removes it. */\n readonly kind: 'child-attributes';\n readonly tag: string;\n readonly index: number;\n readonly attributes: Readonly<Record<string, string | null>>;\n }\n /** A new empty child with these attributes, after the last child of its tag (or at the end). */\n | {\n readonly kind: 'child-add';\n readonly tag: string;\n readonly attributes: Readonly<Record<string, string>>;\n }\n /** Removes one child, its content included. */\n | { readonly kind: 'child-remove'; readonly tag: string; readonly index: number };\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\nfunction attributeEdits(source: string, tag: TagToken, name: string, value: string | boolean | null): Edit[] {\n if (!NAME.test(name)) throw new TypeError(`Invalid attribute name \"${name}\"`);\n const written = tag.attributes.filter((a) => a.name === name);\n const first = written[0];\n if (value === null || value === false) {\n return written.map((a) => ({ start: spaceBefore(source, a.start), end: a.end, text: '' }));\n }\n if (first !== undefined) {\n const current = attributeValue(tag, name) ?? '';\n const same = value === true ? current === '' || current.toLowerCase() === name : current === value;\n if (same) return [];\n }\n const text = value === true ? name : `${name}=\"${escapeAttribute(value)}\"`;\n if (first !== undefined) return [{ start: first.start, end: first.end, text }];\n const last = tag.attributes[tag.attributes.length - 1];\n const at = last?.end ?? tag.start + 1 + tag.name.length;\n return [{ start: at, end: at, text: ` ${text}` }];\n}\n\n/** The children with `tag` in document order, wherever they are in the element (as the inspector lists them). */\nfunction childrenOf(root: ElementRange, tag: string): ElementRange[] {\n return root.children.flatMap((c) => (c.name === tag ? [c] : childrenOf(c, tag)));\n}\n\n/** Text of an element as the HTML parser reads it. */\nfunction textOf(source: string, range: ElementRange): string {\n const [node] = parseHtml(source.slice(range.start, range.end));\n return isElement(node) ? textContent(node) : '';\n}\n\n/** Where content ends: before the end tag, or where the element was implicitly closed. */\nfunction contentEnd(range: ElementRange): number {\n return range.endTag?.start ?? range.end;\n}\n\n/** Replaces the content of an element, turning `<x-y/>` into `<x-y>...</x-y>`. */\nfunction contentEdit(source: string, range: ElementRange, html: string): Edit {\n const tag = range.startTag;\n if (tag.selfClosing && range.endTag === null) {\n const open = source.slice(tag.start, spaceBefore(source, tag.end - 2));\n return { start: range.start, end: range.end, text: `${open}>${html}</${range.name}>` };\n }\n return { start: tag.end, end: contentEnd(range), text: html };\n}\n\n/** Appends HTML at the end of an element's content. */\nfunction appendEdit(source: string, range: ElementRange, html: string): Edit {\n const tag = range.startTag;\n if (tag.selfClosing && range.endTag === null) return contentEdit(source, range, html);\n if (range.endTag === null) return { start: range.end, end: range.end, text: `${html}</${range.name}>` };\n return { start: range.endTag.start, end: range.endTag.start, text: html };\n}\n\n/** Whitespace written between children, reused for new ones. */\nfunction separator(source: string, root: ElementRange, children: readonly ElementRange[]): string {\n const [a, b] = children;\n if (a === undefined) return '';\n const gap =\n b === undefined\n ? source.slice(Math.max(root.startTag.end, spaceBefore(source, a.start)), a.start)\n : source.slice(a.end, b.start);\n return /^\\s*$/.test(gap) ? gap : '';\n}\n\nfunction textListEdits(source: string, root: ElementRange, tag: string, values: readonly string[]): Edit[] {\n const children = childrenOf(root, tag);\n const edits: Edit[] = [];\n children.forEach((child, i) => {\n const value = values[i];\n if (value === undefined) {\n edits.push({ start: spaceBefore(source, child.start), end: child.end, text: '' });\n } else if (textOf(source, child) !== value) {\n edits.push(contentEdit(source, child, escapeText(value)));\n }\n });\n if (values.length > children.length) {\n const sep = separator(source, root, children);\n const added = values.slice(children.length).map((v) => `<${tag}>${escapeText(v)}</${tag}>`);\n const last = children[children.length - 1];\n if (last === undefined) edits.push(appendEdit(source, root, added.join(sep)));\n else edits.push({ start: last.end, end: last.end, text: added.map((a) => sep + a).join('') });\n }\n return edits;\n}\n\n/** Applies one inspector change to the source HTML of one element (the first element in `html`). */\nexport function updateElement(html: string, change: InspectorChange): string {\n const root = elementTree(html)[0];\n if (root === undefined) return html;\n switch (change.kind) {\n case 'attribute':\n return applyEdits(html, attributeEdits(html, root.startTag, change.name, change.value));\n case 'child-flag':\n case 'child-choice': {\n const child = childrenOf(root, change.tag)[change.index];\n if (child === undefined) return html;\n return applyEdits(html, attributeEdits(html, child.startTag, change.attribute, change.value));\n }\n case 'text-list':\n return applyEdits(html, textListEdits(html, root, change.tag, change.values));\n case 'child-attributes': {\n let out = html;\n for (const [attribute, value] of Object.entries(change.attributes)) {\n out = updateElement(out, {\n kind: 'child-choice',\n tag: change.tag,\n attribute,\n index: change.index,\n value,\n });\n }\n return out;\n }\n case 'child-add': {\n if (!NAME.test(change.tag)) throw new TypeError(`Invalid tag name \"${change.tag}\"`);\n const attributes = Object.entries(change.attributes).map(([name, value]) => {\n if (!NAME.test(name)) throw new TypeError(`Invalid attribute name \"${name}\"`);\n return ` ${name}=\"${escapeAttribute(value)}\"`;\n });\n const added = `<${change.tag}${attributes.join('')}></${change.tag}>`;\n const children = childrenOf(root, change.tag);\n // After the last child of the tag, else after the last child: on its own line when the children are.\n const last = children.at(-1) ?? root.children.at(-1);\n if (last === undefined) return applyEdits(html, [appendEdit(html, root, added)]);\n const sep = separator(html, root, children.length > 0 ? children : root.children);\n return applyEdits(html, [{ start: last.end, end: last.end, text: sep + added }]);\n }\n case 'child-remove': {\n const child = childrenOf(root, change.tag)[change.index];\n if (child === undefined) return html;\n return applyEdits(html, [{ start: spaceBefore(html, child.start), end: child.end, text: '' }]);\n }\n }\n}\n","/**\n * Inspector models: what an inspector shows for one component element. Fields come from the EditorDescriptor, or\n * are derived from the manifest; controls follow the AttributeSpec types. Every component also gets `variant` (when\n * its manifest has variants) and `style-template` (when templates are offered for it), after those fields. Plain\n * data, so any UI can render them.\n */\nimport {\n type AttributeSpec,\n allAttributes,\n type ComponentManifest,\n type EditorDescriptor,\n type ElementNode,\n type InspectorField,\n type MessageParams,\n type Node,\n STYLE_TEMPLATE_ATTRIBUTE,\n textContent,\n} from '@astl/core';\n\nexport interface InspectorOption {\n readonly value: string;\n readonly label: string;\n}\n\ninterface FieldTexts {\n /** Translated label. */\n readonly label: string;\n /** Translated help text, or null. */\n readonly help: string | null;\n}\n\nexport interface TextFieldModel extends FieldTexts {\n readonly kind: 'attribute';\n readonly control: 'text';\n readonly name: string;\n /** The written value; '' when absent. */\n readonly value: string;\n readonly required: boolean;\n /** A `url` attribute's files to upload (the field's `accept`), or null: the address is typed. */\n readonly accept: string | null;\n}\n\nexport interface NumberFieldModel extends FieldTexts {\n readonly kind: 'attribute';\n readonly control: 'number';\n readonly name: string;\n /** The written value, else the manifest default; '' when neither. */\n readonly value: string;\n readonly min: number | null;\n readonly max: number | null;\n /** `1` for integers. */\n readonly step: 'any' | '1';\n readonly required: boolean;\n}\n\nexport interface CheckboxFieldModel extends FieldTexts {\n readonly kind: 'attribute';\n readonly control: 'checkbox';\n readonly name: string;\n readonly checked: boolean;\n}\n\nexport interface SelectFieldModel extends FieldTexts {\n readonly kind: 'attribute';\n readonly control: 'select';\n readonly name: string;\n /** The written value, else the default; '' (the \"not set\" option) when neither. */\n readonly value: string;\n readonly options: readonly InspectorOption[];\n}\n\nexport interface TextListFieldModel extends FieldTexts {\n readonly kind: 'text-list';\n readonly tag: string;\n readonly values: readonly string[];\n /** null = unbounded. */\n readonly max: number | null;\n /** Each value in a text area that keeps its line breaks. */\n readonly multiline: boolean;\n}\n\nexport interface ChildFlagModel {\n /** Position among the children with this tag, from 0 (what `child-flag` changes use). */\n readonly index: number;\n readonly id: string | null;\n /** The child's text, or a placeholder when it is empty. */\n readonly label: string;\n readonly checked: boolean;\n}\n\nexport interface ChildFlagFieldModel extends FieldTexts {\n readonly kind: 'child-flag';\n readonly tag: string;\n readonly attribute: string;\n readonly children: readonly ChildFlagModel[];\n}\n\nexport interface ChildTextModel {\n /** Position among the children with this tag, from 0 (what `child-attributes` changes use). */\n readonly index: number;\n readonly id: string | null;\n /** The child's text, or a placeholder when it is empty. */\n readonly label: string;\n /** The written value; '' when absent. */\n readonly value: string;\n}\n\nexport interface ChildTextFieldModel extends FieldTexts {\n readonly kind: 'child-text';\n readonly tag: string;\n readonly attribute: string;\n readonly children: readonly ChildTextModel[];\n}\n\nexport interface ChildChoiceModel {\n /** Position among the children with this tag, from 0 (what `child-choice` changes use). */\n readonly index: number;\n readonly id: string | null;\n /** The child's text, or a placeholder when it is empty. */\n readonly label: string;\n /** The written value; '' when absent. */\n readonly value: string;\n /**\n * The choices of this child. Enum source: the attribute's values, the same for every child (an absent or unknown\n * value matches none). Child source: each option child's id with its text, plus the \"not set\" option when the\n * value is absent and the written value itself when it names no option (so the control shows what the source says).\n */\n readonly options: readonly InspectorOption[];\n}\n\nexport interface ChildChoiceFieldModel extends FieldTexts {\n readonly kind: 'child-choice';\n readonly tag: string;\n readonly attribute: string;\n /** Radios for the enum values of the attribute, a select for the ids of other children (`options`). */\n readonly control: 'radios' | 'select';\n readonly children: readonly ChildChoiceModel[];\n}\n\n/** A column of a `child-table` field: one child attribute, its control picked by the attribute's type. */\nexport interface ChildTableColumnModel {\n readonly attribute: string;\n /** Translated label. */\n readonly label: string;\n readonly control: 'text' | 'number' | 'select';\n /** The choices of a select: the enum's values (a row whose value is none of them shows it, or \"not set\"). */\n readonly options: readonly InspectorOption[];\n readonly min: number | null;\n readonly max: number | null;\n /** `1` for integers. */\n readonly step: 'any' | '1';\n /** A required attribute is written empty rather than removed. */\n readonly required: boolean;\n}\n\nexport interface ChildTableRowModel {\n /** Position among the children with this tag, from 0 (what `child-attributes` and `child-remove` use). */\n readonly index: number;\n readonly id: string | null;\n /** The child's text, or a placeholder when it is empty. */\n readonly label: string;\n /** The written value of each column, '' when absent. */\n readonly values: readonly string[];\n}\n\nexport interface ChildTableFieldModel extends FieldTexts {\n readonly kind: 'child-table';\n readonly tag: string;\n readonly columns: readonly ChildTableColumnModel[];\n readonly rows: readonly ChildTableRowModel[];\n /**\n * The attributes of a new row (`child-add`): a fresh local id, `<tag without astl->-<n>`, and for each required\n * attribute its first enum value, its minimum or ''.\n */\n readonly added: Readonly<Record<string, string>>;\n /** The manifest's bounds on the number of children; null = unbounded. */\n readonly min: number;\n readonly max: number | null;\n}\n\nexport type PictureShape = 'rect' | 'circle' | 'polygon';\n\n/** One zone of a `picture-regions` field, in percent of the picture (absent or invalid numbers read as 0). */\nexport interface PictureRegionModel {\n /** Position among the children with the field's tag, from 0 (what `child-*` changes use). */\n readonly index: number;\n readonly id: string;\n readonly shape: PictureShape;\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n readonly r: number;\n readonly points: readonly (readonly [number, number])[];\n readonly label: string;\n /** Whether the zone has the field's `flag` (a right place): drawn solid, the others dashed. */\n readonly flagged: boolean;\n}\n\n/** One pin of a `picture-points` field, in percent of the picture. */\nexport interface PicturePointModel {\n readonly index: number;\n readonly id: string;\n readonly x: number;\n readonly y: number;\n readonly label: string;\n}\n\ninterface PictureFieldBase extends FieldTexts {\n readonly tag: string;\n /** The tag of the element with the picture: the URL policy is asked for its `srcAttribute`, as the engine does. */\n readonly elementTag: string;\n /** The element's attribute with the picture's address, and its value ('' when absent). */\n readonly srcAttribute: string;\n readonly src: string;\n}\n\nexport interface PictureRegionsFieldModel extends PictureFieldBase {\n readonly kind: 'picture-regions';\n /**\n * The shapes a zone may take: the values of the child's `shape` enum, or rectangles only when it has no `shape`\n * (then no `shape` is written).\n */\n readonly shapes: readonly PictureShape[];\n /**\n * The boolean attribute of a `child-flag` field on the same child tag (a hotspot's right places), whose zones are\n * drawn solid and the others dashed; null without one (every zone solid).\n */\n readonly flag: string | null;\n readonly regions: readonly PictureRegionModel[];\n}\n\nexport interface PicturePointsFieldModel extends PictureFieldBase {\n readonly kind: 'picture-points';\n readonly points: readonly PicturePointModel[];\n}\n\nexport type InspectorFieldModel =\n | TextFieldModel\n | NumberFieldModel\n | CheckboxFieldModel\n | SelectFieldModel\n | TextListFieldModel\n | ChildFlagFieldModel\n | ChildTextFieldModel\n | ChildChoiceFieldModel\n | ChildTableFieldModel\n | PictureRegionsFieldModel\n | PicturePointsFieldModel;\n\nexport interface InspectorModel {\n readonly tag: string;\n readonly id: string | null;\n /** Translated menu label of the type (the tag when there is no descriptor). */\n readonly label: string;\n /** Icon name from the descriptor. */\n readonly icon: string | null;\n readonly fields: readonly InspectorFieldModel[];\n}\n\n/** Texts the model needs: messages of the manifest namespace (with a fallback) and kit strings. */\nexport interface InspectTexts {\n /** A message of the manifest's namespace, or `fallback` when the catalogs lack it. */\n readonly message: (key: string, fallback: string, params?: MessageParams) => string;\n /** Label of the empty option of a select without a default. */\n readonly unset: string;\n /** Placeholder label of an empty child, `n` from 1. */\n readonly untitled: (n: number) => string;\n /** How picture fields number their zones and pins (\"Zone 2\", \"Pin 2\"), for a child of theirs without a label. */\n readonly region: (n: number) => string;\n readonly point: (n: number) => string;\n /** Kit labels of the variant and style template fields, used when the manifest's catalogs have none. */\n readonly variant: string;\n readonly styleTemplate: string;\n /** The style template option that writes nothing: the look around the element. */\n readonly sameAsDocument: string;\n}\n\nconst own = (el: ElementNode, name: string): string | null =>\n Object.hasOwn(el.attrs, name) ? (el.attrs[name] ?? '') : null;\n\n/**\n * The children with `tag` in document order, wherever they are in the element: a rich block's inline children sit in\n * its text (`updateElement` counts them the same way).\n */\nconst childrenOf = (el: ElementNode, tag: string): ElementNode[] =>\n el.children.flatMap((n) => (n.type !== 'element' ? [] : n.tag === tag ? [n] : childrenOf(n, tag)));\n\n/**\n * Fields for a manifest without descriptor fields: type attributes, then private text children (text lists),\n * boolean and enum child attributes (child flags, child choices), then scoring and points. `id`, `v` and derived\n * attributes are left out.\n */\nexport function deriveFields(manifest: ComponentManifest): InspectorField[] {\n const attribute = (spec: AttributeSpec): InspectorField => ({\n kind: 'attribute',\n name: spec.name,\n label: `editor.${spec.name}`,\n });\n const editable = (spec: AttributeSpec) => spec.visibility !== 'derived';\n const scoring = manifest.scoring === null ? [] : ['scoring', 'points'];\n const common = allAttributes(manifest).filter((s) => scoring.includes(s.name));\n return [\n ...manifest.attributes.filter(editable).map(attribute),\n ...manifest.children\n .filter((c) => c.visibility === 'private' && c.content === 'text')\n .map((c): InspectorField => ({ kind: 'text-list', tag: c.tag, label: `editor.${c.tag}` })),\n ...manifest.children.flatMap((c) =>\n c.attributes\n .filter((a) => (a.type === 'boolean' || a.type === 'enum') && editable(a))\n .map(\n (a): InspectorField => ({\n kind: a.type === 'boolean' ? 'child-flag' : 'child-choice',\n tag: c.tag,\n attribute: a.name,\n label: `editor.${c.tag}.${a.name}`,\n }),\n ),\n ),\n ...common.map(attribute),\n ];\n}\n\nfunction selectOptions(\n manifest: ComponentManifest,\n spec: AttributeSpec,\n texts: InspectTexts,\n): InspectorOption[] {\n const values =\n spec.name === 'scoring' && manifest.scoring !== null\n ? Object.keys(manifest.scoring.modes)\n : [...(spec.values ?? [])];\n return values.map((value) => ({\n value,\n label: texts.message(`editor.value.${spec.name}.${value}`, value),\n }));\n}\n\nfunction defaultOf(manifest: ComponentManifest, spec: AttributeSpec): string | null {\n if (spec.name === 'scoring' && manifest.scoring !== null) return manifest.scoring.default;\n return spec.default === undefined ? null : String(spec.default);\n}\n\nfunction attributeModel(\n el: ElementNode,\n manifest: ComponentManifest,\n field: Extract<InspectorField, { kind: 'attribute' }>,\n texts: InspectTexts,\n fallbackLabel: string = field.name,\n find: (id: string) => ElementNode | null = () => null,\n): InspectorFieldModel | null {\n const spec = allAttributes(manifest).find((s) => s.name === field.name);\n if (spec === undefined) return null;\n const name = spec.name;\n const label = texts.message(field.label, fallbackLabel);\n const help = field.help === undefined ? null : texts.message(field.help, '');\n const base = { kind: 'attribute' as const, name, label, help: help === '' ? null : help };\n const written = own(el, name);\n const required = spec.required === true;\n // What another element of the document holds (the words of a drop's bank), when the document has it.\n const from = field.options === undefined ? null : find(own(el, field.options.from) ?? '');\n if (from !== null && field.options !== undefined) {\n const value = written ?? '';\n return {\n ...base,\n control: 'select',\n value,\n options: childOptions(from, field.options.tag, texts)(value),\n };\n }\n const isScoring = name === 'scoring' && manifest.scoring !== null;\n if (spec.type === 'enum' || isScoring) {\n const options = selectOptions(manifest, spec, texts);\n const value = written ?? defaultOf(manifest, spec) ?? '';\n if (value === '' && !options.some((o) => o.value === ''))\n options.unshift({ value: '', label: texts.unset });\n else if (!options.some((o) => o.value === value)) options.push({ value, label: value });\n return { ...base, control: 'select', value, options };\n }\n if (spec.type === 'number' || spec.type === 'integer') {\n return {\n ...base,\n control: 'number',\n value: written ?? defaultOf(manifest, spec) ?? '',\n min: spec.min ?? null,\n max: spec.max ?? null,\n step: spec.type === 'integer' ? '1' : 'any',\n required,\n };\n }\n if (spec.type === 'boolean') return { ...base, control: 'checkbox', checked: written !== null };\n const accept = spec.type === 'url' ? (field.accept ?? null) : null;\n return { ...base, control: 'text', value: written ?? '', required, accept };\n}\n\n/** The kinds of picture field among `fields`, by the child tag of their zones or pins. */\nfunction pictureTags(\n fields: readonly InspectorField[],\n): ReadonlyMap<string, 'picture-regions' | 'picture-points'> {\n return new Map(\n fields.flatMap((f) =>\n f.kind === 'picture-regions' || f.kind === 'picture-points' ? [[f.tag, f.kind]] : [],\n ),\n );\n}\n\n/** The shapes the zones of `tag` take: their `shape` enum's values, or rectangles only without one. */\nfunction shapesOf(manifest: ComponentManifest, tag: string): PictureShape[] {\n const spec = manifest.children.find((c) => c.tag === tag)?.attributes.find((a) => a.name === 'shape');\n if (spec === undefined) return ['rect'];\n const shapes = (['rect', 'circle', 'polygon'] as const).filter((shape) => spec.values?.includes(shape));\n return shapes.length > 0 ? shapes : ['rect'];\n}\n\nfunction fieldModel(\n el: ElementNode,\n manifest: ComponentManifest,\n field: InspectorField,\n texts: InspectTexts,\n fields: readonly InspectorField[] = [field],\n find: (id: string) => ElementNode | null = () => null,\n): InspectorFieldModel | null {\n const help = field.help === undefined ? null : texts.message(field.help, '') || null;\n // Zones and pins have no text: other fields list them as their picture field numbers them.\n const picture = 'tag' in field ? pictureTags(fields).get(field.tag) : undefined;\n const childLabel = (child: ElementNode, index: number): string => labelOf(child, index, texts, picture);\n switch (field.kind) {\n case 'attribute':\n return attributeModel(el, manifest, field, texts, field.name, find);\n case 'text-list':\n return {\n kind: 'text-list',\n tag: field.tag,\n label: texts.message(field.label, field.tag),\n help,\n values: childrenOf(el, field.tag).map(textContent),\n max: manifest.children.find((c) => c.tag === field.tag)?.max ?? null,\n multiline: field.multiline === true,\n };\n case 'child-flag': {\n const children = childrenOf(el, field.tag).map((child, index) => ({\n index,\n id: own(child, 'id'),\n label: childLabel(child, index),\n checked: own(child, field.attribute) !== null,\n }));\n // How many children there are and how many have the flag, for messages that say so (\"2 of 3 correct\").\n const counts = { count: children.length, checked: children.filter((c) => c.checked).length };\n const fallback = `${field.tag} ${field.attribute}`;\n const described = field.help === undefined ? null : texts.message(field.help, '', counts) || null;\n return {\n kind: 'child-flag',\n tag: field.tag,\n attribute: field.attribute,\n label: texts.message(field.label, fallback, counts),\n help: described,\n children,\n };\n }\n case 'child-text':\n return {\n kind: 'child-text',\n tag: field.tag,\n attribute: field.attribute,\n label: texts.message(field.label, `${field.tag} ${field.attribute}`),\n help,\n children: childrenOf(el, field.tag).map((child, index) => ({\n index,\n id: own(child, 'id'),\n label: childLabel(child, index),\n value: own(child, field.attribute) ?? '',\n })),\n };\n case 'child-choice': {\n const source = choiceSource(el, manifest, field, texts);\n if (source === null) return null;\n return {\n kind: 'child-choice',\n tag: field.tag,\n attribute: field.attribute,\n label: texts.message(field.label, `${field.tag} ${field.attribute}`),\n help,\n control: source.control,\n children: childrenOf(el, field.tag).map((child, index) => {\n const value = own(child, field.attribute) ?? '';\n const options = source.options(value);\n return { index, id: own(child, 'id'), label: childLabel(child, index), value, options };\n }),\n };\n }\n case 'child-table':\n return childTable(el, manifest, field, texts, help);\n case 'picture-regions':\n case 'picture-points': {\n const base = {\n tag: field.tag,\n label: texts.message(field.label, field.tag),\n help,\n elementTag: el.tag,\n srcAttribute: field.src,\n src: own(el, field.src) ?? '',\n };\n const children = childrenOf(el, field.tag);\n if (field.kind === 'picture-points') {\n return {\n ...base,\n kind: 'picture-points',\n points: children.map((child, index) => ({\n index,\n id: own(child, 'id') ?? '',\n x: percent(own(child, 'x')),\n y: percent(own(child, 'y')),\n label: own(child, 'label') ?? '',\n })),\n };\n }\n const flag = fields.find((f) => f.kind === 'child-flag' && f.tag === field.tag);\n const flagName = flag !== undefined && 'attribute' in flag ? flag.attribute : null;\n return {\n ...base,\n kind: 'picture-regions',\n shapes: shapesOf(manifest, field.tag),\n flag: flagName,\n regions: children.map((child, index) => {\n const shape = own(child, 'shape');\n return {\n index,\n id: own(child, 'id') ?? '',\n shape: shape === 'circle' || shape === 'polygon' ? shape : 'rect',\n x: percent(own(child, 'x')),\n y: percent(own(child, 'y')),\n width: percent(own(child, 'width')),\n height: percent(own(child, 'height')),\n r: percent(own(child, 'r')),\n points: pointsOf(own(child, 'points')),\n label: own(child, 'label') ?? '',\n flagged: flagName !== null && own(child, flagName) !== null,\n };\n }),\n };\n }\n }\n}\n\nfunction childTable(\n el: ElementNode,\n manifest: ComponentManifest,\n field: Extract<InspectorField, { kind: 'child-table' }>,\n texts: InspectTexts,\n help: string | null,\n): ChildTableFieldModel | null {\n const spec = manifest.children.find((c) => c.tag === field.tag);\n if (spec === undefined) return null;\n const columns = field.columns.flatMap((column): ChildTableColumnModel[] => {\n const attr = spec.attributes.find((a) => a.name === column.attribute);\n if (attr === undefined) return [];\n const number = attr.type === 'integer' || attr.type === 'number';\n return [\n {\n attribute: attr.name,\n label: texts.message(column.label, attr.name),\n control: attr.type === 'enum' ? 'select' : number ? 'number' : 'text',\n options: (attr.values ?? []).map((value) => ({\n value,\n label: texts.message(`editor.value.${attr.name}.${value}`, value),\n })),\n min: attr.min ?? null,\n max: attr.max ?? null,\n step: attr.type === 'integer' ? '1' : 'any',\n required: attr.required === true,\n },\n ];\n });\n const children = childrenOf(el, field.tag);\n const prefix = field.tag.replace(/^astl-/, '');\n const taken = new Set(children.map((child) => own(child, 'id')));\n let n = children.length + 1;\n while (taken.has(`${prefix}-${n}`)) n++;\n const added: Record<string, string> = { id: `${prefix}-${n}` };\n for (const attr of spec.attributes) {\n if (attr.required !== true || attr.name === 'id') continue;\n added[attr.name] = attr.values?.[0] ?? (attr.min === undefined ? '' : String(attr.min));\n }\n return {\n kind: 'child-table',\n tag: field.tag,\n label: texts.message(field.label, field.tag),\n help,\n columns,\n rows: children.map((child, index) => ({\n index,\n id: own(child, 'id'),\n label: labelOf(child, index, texts),\n values: columns.map((c) => own(child, c.attribute) ?? ''),\n })),\n added,\n min: spec.min,\n max: spec.max,\n };\n}\n\n/** A coordinate in percent: a number from 0 to 100 (anything else reads as 0; out-of-range values are clamped). */\nfunction percent(value: string | null): number {\n const n = Number.parseFloat(value ?? '');\n return Number.isFinite(n) ? Math.min(100, Math.max(0, n)) : 0;\n}\n\n/** Polygon points written as `x,y x,y ...`. */\nexport function pointsOf(value: string | null): (readonly [number, number])[] {\n return (value ?? '')\n .trim()\n .split(/\\s+/)\n .filter((pair) => pair !== '')\n .map((pair) => {\n const [x = '', y = ''] = pair.split(',');\n return [percent(x), percent(y)] as const;\n });\n}\n\n/** Text with the alt text of its pictures, as a screen reader reads it: a child may be only a picture (a card). */\nconst said = (node: Node): string =>\n node.type === 'text'\n ? node.value\n : node.tag === 'img'\n ? ` ${node.attrs.alt ?? ''} `\n : node.children.map(said).join('');\n\n/**\n * A child listed by what it says, or a numbered placeholder when it says nothing. A zone or a pin of a picture field\n * (`picture`) says nothing: it is listed by its label, else as that field numbers it (\"Zone 2\").\n */\nfunction labelOf(\n child: ElementNode,\n index: number,\n texts: InspectTexts,\n picture?: 'picture-regions' | 'picture-points',\n): string {\n const text = said(child).replace(/\\s+/g, ' ').trim();\n if (text !== '' || picture === undefined) return text || texts.untitled(index + 1);\n const label = (own(child, 'label') ?? '').replace(/\\s+/g, ' ').trim();\n return label || (picture === 'picture-regions' ? texts.region(index + 1) : texts.point(index + 1));\n}\n\n/**\n * The ids of the `tag` children of `parent` by their text, as the options of a select showing `value`: \"not set\"\n * first while the value is absent, and a written value that names none kept at the end.\n */\nfunction childOptions(\n parent: ElementNode,\n tag: string,\n texts: InspectTexts,\n): (value: string) => InspectorOption[] {\n const choices = childrenOf(parent, tag).flatMap((option, index): InspectorOption[] => {\n const id = own(option, 'id');\n return id === null || id === '' ? [] : [{ value: id, label: labelOf(option, index, texts) }];\n });\n return (value) =>\n value === ''\n ? [{ value: '', label: texts.unset }, ...choices]\n : choices.some((o) => o.value === value)\n ? choices\n : [...choices, { value, label: value }];\n}\n\n/**\n * Where a child choice gets its choices. Without `options`: the attribute's enum values as radios, labelled by\n * `editor.value.<attribute>.<value>` (null when the attribute is no enum). With `options`, a child tag: the ids of\n * those children by their text, in a select.\n */\nfunction choiceSource(\n el: ElementNode,\n manifest: ComponentManifest,\n field: Extract<InspectorField, { kind: 'child-choice' }>,\n texts: InspectTexts,\n): { readonly control: 'radios' | 'select'; readonly options: (value: string) => InspectorOption[] } | null {\n if (field.options === undefined) {\n const spec = manifest.children\n .find((c) => c.tag === field.tag)\n ?.attributes.find((a) => a.name === field.attribute);\n if (spec?.type !== 'enum') return null;\n const values = (spec.values ?? []).map((value) => ({\n value,\n label: texts.message(`editor.value.${spec.name}.${value}`, value),\n }));\n return { control: 'radios', options: () => values };\n }\n return { control: 'select', options: childOptions(el, field.options, texts) };\n}\n\n/**\n * A `style-template` select: `unset` (writes nothing), then the offered templates; a written value that is not\n * offered stays visible, so it can be seen and removed.\n */\nexport function styleTemplateField(\n el: ElementNode,\n label: string,\n unset: string,\n templates: readonly InspectorOption[],\n): SelectFieldModel {\n const value = own(el, STYLE_TEMPLATE_ATTRIBUTE) ?? '';\n const options = [{ value: '', label: unset }, ...templates];\n if (!options.some((o) => o.value === value)) options.push({ value, label: value });\n return {\n kind: 'attribute',\n control: 'select',\n name: STYLE_TEMPLATE_ATTRIBUTE,\n label,\n help: null,\n value,\n options,\n };\n}\n\n/** The variant the element shows: its `variant` when the manifest has that value, else the default; null without variants. */\nfunction variantOf(el: ElementNode, manifest: ComponentManifest): string | null {\n if (manifest.variants === null) return null;\n const written = own(el, 'variant');\n return written !== null && manifest.variants.values.includes(written) ? written : manifest.variants.default;\n}\n\n/** Whether a field applies to the variant the element shows (an attribute field with `variants` lists it). */\nfunction forVariant(field: InspectorField, variant: string | null): boolean {\n return field.kind !== 'attribute' || field.variants === undefined || field.variants.includes(variant ?? '');\n}\n\n/** The fields every component gets after its own: `variant` and `style-template` (unless already listed). */\nfunction commonFields(\n el: ElementNode,\n manifest: ComponentManifest,\n listed: readonly InspectorFieldModel[],\n texts: InspectTexts,\n templates: readonly InspectorOption[],\n): InspectorFieldModel[] {\n const has = (name: string) => listed.some((f) => f.kind === 'attribute' && f.name === name);\n const out: InspectorFieldModel[] = [];\n if (manifest.variants !== null && !has('variant')) {\n const field = { kind: 'attribute', name: 'variant', label: 'editor.variant' } as const;\n const variant = attributeModel(el, manifest, field, texts, texts.variant);\n if (variant !== null) out.push(variant);\n }\n const written = own(el, STYLE_TEMPLATE_ATTRIBUTE) !== null;\n if ((templates.length > 0 || written) && !has(STYLE_TEMPLATE_ATTRIBUTE)) {\n const label = texts.message(`editor.${STYLE_TEMPLATE_ATTRIBUTE}`, texts.styleTemplate);\n out.push(styleTemplateField(el, label, texts.sameAsDocument, templates));\n }\n return out;\n}\n\n/**\n * The inspector model of a parsed component element. `templates`: the style templates offered for its tag at the\n * component scope, labelled. `find`: another element of the document by its id, for the fields that offer what it\n * holds (none by default).\n */\nexport function inspectorModel(\n el: ElementNode,\n manifest: ComponentManifest,\n descriptor: EditorDescriptor | null,\n texts: InspectTexts,\n templates: readonly InspectorOption[] = [],\n find: (id: string) => ElementNode | null = () => null,\n): InspectorModel {\n const declared = descriptor?.fields ?? deriveFields(manifest);\n const variant = variantOf(el, manifest);\n const fields = declared\n .filter((f) => forVariant(f, variant))\n .flatMap((f) => fieldModel(el, manifest, f, texts, declared, find) ?? []);\n return {\n tag: el.tag,\n id: own(el, 'id'),\n label: descriptor === null ? el.tag : texts.message(descriptor.label, el.tag),\n icon: descriptor?.icon ?? null,\n fields: [...fields, ...commonFields(el, manifest, fields, texts, templates)],\n };\n}\n","/**\n * createAuthoring: the editor-independent logic of the authoring kit. Pure (no DOM), so hosts, agents and tests can\n * use it in any runtime; the web components and adapters are thin layers on top.\n */\nimport {\n type AttemptPolicy,\n COLUMN_TAG,\n COLUMNS_TAG,\n type ComponentManifest,\n createI18n,\n DOC_TAG,\n type EditorDescriptor,\n type EditorTemplate,\n type ElementNode,\n ENGINE_NAMESPACE,\n type Engine,\n element,\n type Issue,\n isElement,\n isSafeUrl,\n isSourceId,\n type MessageCatalog,\n type MessageParams,\n type Node,\n PAGE_TAG,\n SCORING_ATTRIBUTES,\n STYLE_TAG,\n STYLE_TEMPLATE_ATTRIBUTE,\n type StyleScope,\n type StyleTemplate,\n strictUrlPolicy,\n type UrlPolicy,\n type ValidationReport,\n} from '@astl/core';\nimport { cleanStyle, isStyleName } from '@astl/core/declarations';\nimport { engineMessages, type LocalChecker, localChecker, parseHtml } from '@astl/engine';\nimport type { ElementEntry } from '@astl/player';\nimport { type InspectorChange, updateElement } from './edit.js';\nimport { type InspectorModel, type InspectorOption, inspectorModel, styleTemplateField } from './inspect.js';\nimport { EDITOR_NAMESPACE, editorMessages } from './messages.js';\nimport {\n applyEdits,\n attributeValue,\n type Edit,\n type ElementRange,\n elementTree,\n escapeHtml,\n scanElements,\n scanRanges,\n tokenize,\n usedIds,\n} from './scan.js';\nimport { DEFAULT_FONTS, DEFAULT_STYLES, type EditorFont, type EditorStylePreset } from './style-model.js';\n\nexport interface AuthoringOptions {\n readonly engine: Engine;\n /** One per component type authors can insert and inspect. Each tag must be registered in the engine. */\n readonly descriptors: readonly EditorDescriptor[];\n /** Player elements for `<astl-preview>`, eager or lazy. */\n readonly elements?: readonly ElementEntry[];\n /** The author's UI locale: labels, issues, template texts. */\n readonly locale: string;\n /** More or overriding catalogs (any namespace), e.g. another UI locale. */\n readonly catalogs?: readonly MessageCatalog[];\n /**\n * Catalogs only insert menus show (the one-line descriptions), loaded when a menu first opens rather than with the\n * editor (`loadMenuMessages`): the built-ins' are the components package's `builtInMenuMessages`. The host's\n * `catalogs` override them.\n */\n readonly menuMessages?: () => Promise<readonly MessageCatalog[]>;\n /**\n * Style templates authors can pick (register the same ones with the engine and the player): the inspector offers\n * them per component and for the whole document, labelled from their catalogs; `<astl-preview>` renders them.\n */\n readonly styleTemplates?: readonly StyleTemplate[];\n /**\n * The engine's URL policy (`createEngine({ urlPolicy })`): the preview's player cleans with it and editors check\n * picture addresses with it before they show them. Default `isSafeUrl`.\n */\n readonly urlPolicy?: UrlPolicy;\n /**\n * The fonts the style controls offer, in order. Default `DEFAULT_FONTS`, stacks every system has. A stack the style\n * allow-list refuses throws.\n */\n readonly fonts?: readonly EditorFont[];\n /**\n * The ready styles the style menu and the style form offer, in order; `[]`: none. Default `DEFAULT_STYLES`. A name\n * `isStyleName` refuses, a declaration the style allow-list refuses, or a name given twice throws.\n */\n readonly styles?: readonly EditorStylePreset[];\n /**\n * Stores a picture file and returns its address (and size): the host's upload, used by the picture dialog, by\n * pictures pasted or dropped into the editor and by picture fields; also by `url` fields with `accept` (a video,\n * its captions). The address must pass `urlPolicy`. Without it, files are added by address only (pictures also\n * from `pickPicture`). `signal` aborts when the author cancels or picks another file. The file's type is the\n * browser's guess: check type and size on the server, and serve SVG with `nosniff`. Reject with `UploadRefused` to\n * tell the author why.\n */\n readonly uploadAsset?: UploadAsset;\n /**\n * Opens the host's own picture library: the picture dialog and picture fields offer it beside the upload. The\n * address it gives must pass `urlPolicy`. The picture dialog closes while the library is open, keeping what the\n * author typed, so a modal of the host's own takes the pointer and the keys; it opens again when the library\n * settles. Reject with `UploadRefused` to tell the author why.\n */\n readonly pickPicture?: PickPicture;\n}\n\n/** A host's font with its stack in the allow-list's normal form, what a style then holds. */\nfunction normalFont(font: EditorFont): EditorFont {\n const stack = cleanStyle(`font-family: ${font.stack}`).declarations[0]?.[1];\n if (stack === undefined) throw new TypeError(`Font \"${font.name}\": the style allow-list refuses its stack`);\n return { name: font.name, stack };\n}\n\n/**\n * A host's ready styles with each style in the allow-list's normal form, what its rule then holds, and each label in\n * the authoring locale. A name `isStyleName` refuses, a declaration the allow-list refuses or a name given twice\n * throws: a style that could not be written as it was offered.\n */\nfunction readyStyles(\n presets: readonly EditorStylePreset[],\n label: (name: string) => string,\n): (EditorStylePreset & { readonly label: string })[] {\n const names = new Set<string>();\n return presets.map((preset) => {\n const { name } = preset;\n if (!isStyleName(name)) throw new TypeError(`Style \"${name}\": not a style name`);\n if (names.has(name)) throw new TypeError(`Style \"${name}\" is given twice`);\n names.add(name);\n const { style, removed } = cleanStyle(preset.style);\n if (removed.length > 0)\n throw new TypeError(`Style \"${name}\": the style allow-list refuses ${removed.join(', ')}`);\n return { ...preset, style, label: preset.label ?? label(name) };\n });\n}\n\n/** A stored picture, as `uploadAsset` and `pickPicture` give it: its address, and its size in pixels when known. */\nexport interface UploadedAsset {\n readonly src: string;\n readonly width?: number;\n readonly height?: number;\n}\n\nexport type UploadAsset = (file: File, options: { readonly signal: AbortSignal }) => Promise<UploadedAsset>;\n\n/**\n * Opens the host's own picture library and resolves with the chosen picture (its address, and its size when known),\n * or null when the author closes it without one. The address must pass `urlPolicy`. Settle once the library has\n * closed: the picture dialog and the picture fields then give the focus back themselves. `signal` aborts when the\n * editor no longer waits for it (the picture dialog was asked for another picture or left the page, the picture field\n * started another upload or pick): the host should then close its library.\n */\nexport type PickPicture = (options: { readonly signal: AbortSignal }) => Promise<UploadedAsset | null>;\n\n/**\n * What a host's `uploadAsset` or `pickPicture` rejects with to tell the author why: its message, already in the\n * editor's locale, is shown as it is, instead of the generic failure text.\n */\nexport class UploadRefused extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'UploadRefused';\n }\n}\n\n/**\n * The words of a host's refusal: the message of an `UploadRefused`, known by its name so that another copy of this\n * package counts too; undefined for any other error and for a refusal without words.\n */\nexport function refusalOf(error: unknown): string | undefined {\n return error instanceof Error && error.name === 'UploadRefused' && error.message.trim() !== ''\n ? error.message\n : undefined;\n}\n\n/** A picture as the picture dialog asks for it: `alt` is `''` for a decorative picture. */\nexport interface PictureFields {\n readonly src: string;\n readonly alt: string;\n readonly width?: number;\n readonly height?: number;\n /** A caption makes the picture a figure. */\n readonly caption?: string;\n}\n\n/**\n * A picture's width or height as the content format takes it: a positive whole number of pixels (a safe integer),\n * from a number or its written form; anything else is no size.\n */\nexport function pictureSize(value: unknown): number | undefined {\n const n =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && /^[1-9]\\d*$/.test(value)\n ? Number(value)\n : NaN;\n return Number.isSafeInteger(n) && n > 0 ? n : undefined;\n}\n\n/**\n * The source HTML of a picture: an `<img>` that sits in text, or with a caption a `<figure>` that stands on its own.\n * Every value is read once and escaped, and only the attributes of the content format are written.\n */\nexport function pictureHtml(picture: PictureFields): string {\n const size = (name: string, value: unknown) => {\n const n = pictureSize(value);\n return n === undefined ? '' : ` ${name}=\"${n}\"`;\n };\n const img =\n `<img src=\"${escapeHtml(String(picture.src))}\" alt=\"${escapeHtml(String(picture.alt))}\"` +\n `${size('width', picture.width)}${size('height', picture.height)}>`;\n const caption = String(picture.caption ?? '').trim();\n return caption === '' ? img : `<figure>${img}<figcaption>${escapeHtml(caption)}</figcaption></figure>`;\n}\n\nexport interface OutlineComponent {\n readonly id: string | null;\n readonly tag: string;\n /** Translated type label (the tag when there is no descriptor). */\n readonly label: string;\n /** Its `points` (default 1) when the type is graded, else null. */\n readonly points: number | null;\n /** Issues located on this component or its children. */\n readonly errors: number;\n readonly warnings: number;\n}\n\n/**\n * One block of a page (`EditorBlockPlace`): a block component directly on the page, or the content between two of\n * them (paragraphs, headings, lists, quotes, pictures, with the inline components in their text).\n */\nexport interface OutlineBlock {\n readonly kind: 'component' | 'text';\n /** The component's source id (null when it has none), or null for a text block. */\n readonly id: string | null;\n /** The component's tag, or null for a text block. */\n readonly tag: string | null;\n /**\n * The block's type: the component's label, else `block.gap` (\"Gap\") for text that holds a graded component and\n * `block.text` (\"Text\") for the rest.\n */\n readonly label: string;\n /** The sum of its components' points, or null when none of them is graded. */\n readonly points: number | null;\n /** Its component, or the components in its text, in document order. */\n readonly components: readonly OutlineComponent[];\n /** Issues located on its components. */\n readonly errors: number;\n readonly warnings: number;\n}\n\nexport interface OutlinePage {\n /** null for the implicit page of a document without pages. */\n readonly id: string | null;\n readonly label: string | null;\n /** Issues located on the page, its content and its components. */\n readonly errors: number;\n readonly warnings: number;\n readonly components: readonly OutlineComponent[];\n /** Its content as blocks, in order. */\n readonly blocks: readonly OutlineBlock[];\n /** The sum of its blocks' points, or null when nothing on it is graded. */\n readonly points: number | null;\n}\n\nexport interface Outline {\n readonly pages: readonly OutlinePage[];\n /** Every issue of the document. */\n readonly errors: number;\n readonly warnings: number;\n /** The sum of its pages' points, or null when nothing is graded. */\n readonly points: number | null;\n}\n\n/** A playable preview, or the issues that block compiling. */\n/** How `Authoring.preview` grades. */\nexport interface PreviewOptions {\n /**\n * The policy of the local grading, the one the host plays the result under: a host whose students get less help than\n * practice offers (no hints, no check of one interaction) previews with that. Default `PRACTICE_POLICY`.\n */\n readonly policy?: AttemptPolicy;\n}\n\nexport type PreviewResult =\n | {\n readonly ok: true;\n readonly view: string;\n /** Local grading for this preview, under its policy (`PreviewOptions.policy`, practice by default). */\n readonly checker: LocalChecker;\n /** Warnings. */\n readonly issues: readonly Issue[];\n }\n | { readonly ok: false; readonly issues: readonly Issue[] };\n\n/** How `Authoring.describe` names a component. */\nexport interface DescribeOptions {\n /**\n * Whether the name says the component's page when the document has pages: \"Question 2 on page 1\" (default true), or\n * \"Question 2\" (false) for a host that shows the page apart.\n */\n readonly page?: boolean;\n}\n\nexport interface Authoring {\n readonly engine: Engine;\n readonly locale: string;\n readonly descriptors: readonly EditorDescriptor[];\n readonly elements: readonly ElementEntry[];\n readonly styleTemplates: readonly StyleTemplate[];\n readonly urlPolicy: UrlPolicy;\n /** The fonts the style controls offer, each stack in the allow-list's normal form. */\n readonly fonts: readonly EditorFont[];\n /**\n * The ready styles the style menu and the style form offer, each style in the allow-list's normal form and each with\n * its label: the host's, else the kit's message `style.preset.<name>` in the authoring locale, else the name.\n */\n readonly styles: readonly (EditorStylePreset & { readonly label: string })[];\n /** The host's upload, or null: files are added by address only. */\n readonly uploadAsset: UploadAsset | null;\n /** The host's picture library, or null. */\n readonly pickPicture: PickPicture | null;\n /** The descriptor of a component tag, or null. */\n descriptor(tag: string): EditorDescriptor | null;\n /** The named starters of a component tag (`EditorDescriptor.templates`); none without a descriptor. */\n templates(tag: string): readonly EditorTemplate[];\n /** A message in the authoring locale: kit (`astl.editor`), descriptor, engine and extra catalogs. */\n t(namespace: string, key: string, params?: MessageParams): string;\n /**\n * Loads the `menuMessages` option's catalogs (what only insert menus show) once; `t` has them when it resolves. A\n * failed load resolves too, and the next call tries again.\n */\n loadMenuMessages(): Promise<void>;\n /**\n * Adds the catalogs of a part of the kit that loads later, under the host's `catalogs`, which may override them; `t`\n * has them at once. Adding the same ones again does nothing.\n */\n addMessages(catalogs: readonly MessageCatalog[]): void;\n /**\n * The descriptor's template, or its named starter `templateId`, ready to insert into `source`: `{{id}}` becomes\n * `<idPrefix>-<n>` with the smallest n whose id `source` does not use, `{{selection}}` the escaped `selection` (the\n * text the author selected, `EditorAdapter.selectedText`; default `''`), `{{t:key}}` an escaped message of the\n * manifest namespace, and other components written without an id get fresh ones too. An element of a type with a\n * `companion` and an empty attribute names the first such element of the template, else of `source`, else the one\n * `withCompanion` adds. Throws for a tag without a descriptor or an unknown starter.\n */\n instantiate(tag: string, source: string, templateId?: string, selection?: string): string;\n /**\n * `source` (with an inserted `tag` element) where that element, the one with the id `id` (default: the first whose\n * companion attribute names none on its page), names a companion element of its own page, as pages play one at a\n * time: the first one there, else the descriptor's `companion` template, added at the end of that page (of the\n * document, without pages). Null when nothing changes: the type has no companion, or the element names one of its\n * page already.\n */\n withCompanion(tag: string, source: string, id?: string): string | null;\n /**\n * The inspector model of one component element (source HTML), or null for elements it does not know. With the\n * whole document (`source`), fields offer what other elements hold (the words of the bank a drop takes its words\n * from); without it they show the attribute's own control.\n */\n inspect(elementHtml: string, source?: string): InspectorModel | null;\n /**\n * The document's own settings (its style template) as an inspector model for `<astl-doc>`, or null when the source\n * has no `<astl-doc>` root or there is nothing to set. Apply its changes with `update(source, change)`: the first\n * element of the source is the document, so only its start tag changes.\n */\n inspectDocument(source: string): InspectorModel | null;\n /** The element HTML with one inspector change applied; everything else stays byte-identical. */\n update(elementHtml: string, change: InspectorChange): string;\n validate(source: string): ValidationReport;\n /**\n * An issue as a sentence in the authoring locale. With the document it is about (`source`), a component's issue\n * names the component as the author sees it, never by its id (the id stays in `issue.at` for \"Show\"): a block\n * component by the number of its block on its page, as its card's head shows it (\"Question 2 on page 1\" for block 2),\n * a component in text by its number among the components of its type on its page (\"Gap 3 on page 1\"); with\n * `page: false`, without its page (\"Question 2\").\n */\n describe(issue: Issue, source?: string, options?: DescribeOptions): string;\n /** `source` with fresh ids on pages and components that lack one (or have an empty one). */\n assignIds(source: string): string;\n /** Pages, their blocks and components, points and issue counts. */\n outline(source: string): Outline;\n /**\n * Compiles with a random per-session salt and grades locally, under `options.policy` (default `PRACTICE_POLICY`). The\n * source is not stored anywhere.\n */\n preview(source: string, options?: PreviewOptions): Promise<PreviewResult>;\n}\n\n/** 128 random bits as hex: mixed into every preview, so preview ids never match published views. */\nfunction sessionSalt(): string {\n const bytes = crypto.getRandomValues(new Uint8Array(16));\n return `preview-${Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')}`;\n}\n\nconst TEMPLATE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\nfunction freshId(prefix: string, used: ReadonlySet<string>): string {\n for (let n = 1; ; n++) {\n const id = `${prefix}-${n}`;\n if (!used.has(id)) return id;\n }\n}\n\n/**\n * The content of a document without its named styles: they are not on any page. What one holds stays: all that follows\n * a self-closed one, as HTML reads it.\n */\nconst withoutRules = (nodes: readonly Node[]): readonly Node[] =>\n nodes.flatMap((node): readonly Node[] =>\n isElement(node, STYLE_TAG) ? withoutRules(node.children) : [node],\n );\n\nfunction firstElement(nodes: readonly Node[]): ElementNode | null {\n return nodes.find((n): n is ElementNode => n.type === 'element') ?? null;\n}\n\ninterface Counts {\n errors: number;\n warnings: number;\n}\n\n/** A graded component's points when its `points` is absent or not a number (`SCORING_ATTRIBUTES`). */\nconst DEFAULT_POINTS = Number(SCORING_ATTRIBUTES.find((a) => a.name === 'points')?.default ?? 1);\n\n/** The sum of the numbers (to the hundredth, as points are written), or null when there are none. */\nfunction sum(values: readonly (number | null)[]): number | null {\n const numbers = values.filter((v): v is number => v !== null);\n if (numbers.length === 0) return null;\n return Math.round(numbers.reduce((a, b) => a + b, 0) * 100) / 100;\n}\n\nfunction count(issues: readonly Issue[], where: (issue: Issue) => boolean): Counts {\n const out = { errors: 0, warnings: 0 };\n for (const issue of issues) {\n if (!where(issue)) continue;\n if (issue.severity === 'error') out.errors++;\n else out.warnings++;\n }\n return out;\n}\n\nexport function createAuthoring(options: AuthoringOptions): Authoring {\n const { engine, locale } = options;\n const registered = new Map(engine.manifests.map((m) => [m.tag, m]));\n const byTag = new Map<string, EditorDescriptor>();\n for (const descriptor of options.descriptors) {\n const tag = descriptor.manifest.tag;\n if (byTag.has(tag)) throw new TypeError(`Editor descriptor for <${tag}> is given twice`);\n if (!registered.has(tag))\n throw new TypeError(`Editor descriptor <${tag}> has no component in the engine`);\n if (!isSourceId(`${descriptor.idPrefix}-1`)) {\n throw new TypeError(\n `Editor descriptor <${tag}>: idPrefix \"${descriptor.idPrefix}\" does not make valid ids`,\n );\n }\n const ids = (descriptor.templates ?? []).map((template) => template.id);\n if (ids.some((id, i) => !TEMPLATE_ID.test(id) || ids.indexOf(id) !== i)) {\n throw new TypeError(`Editor descriptor <${tag}>: template ids must be distinct kebab-case names`);\n }\n byTag.set(tag, descriptor);\n }\n const styleTemplates = options.styleTemplates ?? [];\n // Catalogs that load later go before the host's, which may override them.\n const i18nWith = (later: readonly MessageCatalog[]) =>\n createI18n({\n catalogs: [\n ...editorMessages,\n ...engineMessages,\n ...options.descriptors.flatMap((d) => d.messages ?? []),\n ...later,\n ...styleTemplates.flatMap((template) => template.catalogs ?? []),\n ...(options.catalogs ?? []),\n ],\n });\n let i18n = i18nWith([]);\n let later: readonly MessageCatalog[] = [];\n const addMessages = (catalogs: readonly MessageCatalog[]): void => {\n const added = catalogs.filter((catalog) => !later.includes(catalog));\n if (added.length === 0) return;\n later = [...later, ...added];\n i18n = i18nWith(later);\n };\n let menus: Promise<void> | null = null;\n const t = (namespace: string, key: string, params?: MessageParams): string =>\n i18n.t(locale, namespace, key, params);\n const manifestOf = (tag: string): ComponentManifest | null =>\n byTag.get(tag)?.manifest ?? registered.get(tag) ?? null;\n const salt = sessionSalt();\n\n const textsFor = (manifest: ComponentManifest) => ({\n message: (key: string, fallback: string, params?: MessageParams) => {\n const message = t(manifest.messages, key, params);\n return message === key ? fallback : message;\n },\n unset: t(EDITOR_NAMESPACE, 'inspector.unset'),\n untitled: (n: number) => t(EDITOR_NAMESPACE, 'inspector.untitled', { n }),\n region: (n: number) => t(EDITOR_NAMESPACE, 'field.region', { n }),\n point: (n: number) => t(EDITOR_NAMESPACE, 'field.point', { n }),\n variant: t(EDITOR_NAMESPACE, 'inspector.variant'),\n styleTemplate: t(EDITOR_NAMESPACE, 'inspector.styleTemplate'),\n sameAsDocument: t(EDITOR_NAMESPACE, 'inspector.styleTemplate.inherit'),\n });\n\n /** Templates usable at `scope` (and for `tag` at the component scope), labelled in the authoring locale. */\n const templateOptions = (scope: StyleScope, tag?: string): InspectorOption[] =>\n styleTemplates\n .filter(\n (template) =>\n template.scopes.includes(scope) &&\n (tag === undefined || template.components === undefined || template.components.includes(tag)),\n )\n .map((template) => {\n const label = t(template.messages, 'label');\n return { value: template.name, label: label === 'label' ? template.name : label };\n });\n\n const labelOf = (tag: string): string => {\n const descriptor = byTag.get(tag);\n if (descriptor === undefined) return tag;\n const label = t(descriptor.manifest.messages, descriptor.label);\n return label === descriptor.label ? tag : label;\n };\n\n const pointsOf = (node: ElementNode): number | null => {\n if (registered.get(node.tag)?.graded !== true) return null;\n const n = Object.hasOwn(node.attrs, 'points') ? Number(node.attrs.points) : Number.NaN;\n return Number.isFinite(n) && n > 0 ? n : DEFAULT_POINTS;\n };\n\n const outline = (source: string): Outline => {\n const { issues } = engine.validate(source);\n const idOf = (node: ElementNode) => (Object.hasOwn(node.attrs, 'id') ? (node.attrs.id ?? null) : null);\n const entry = (node: ElementNode): OutlineComponent => {\n const id = idOf(node);\n const counts = count(issues, (i) => id !== null && i.at.element === id);\n return { id, tag: node.tag, label: labelOf(node.tag), points: pointsOf(node), ...counts };\n };\n const components = (nodes: readonly Node[], out: OutlineComponent[] = []): OutlineComponent[] => {\n for (const node of nodes) {\n if (node.type !== 'element') continue;\n if (registered.has(node.tag)) out.push(entry(node));\n else components(node.children, out);\n }\n return out;\n };\n const block = (\n kind: OutlineBlock['kind'],\n node: ElementNode | null,\n parts: readonly OutlineComponent[],\n ): OutlineBlock => {\n const ids = new Set(parts.flatMap((part) => (part.id === null ? [] : [part.id])));\n const points = sum(parts.map((part) => part.points));\n const label =\n node !== null ? labelOf(node.tag) : t(EDITOR_NAMESPACE, points === null ? 'block.text' : 'block.gap');\n return {\n kind,\n id: node === null ? null : idOf(node),\n tag: node?.tag ?? null,\n label,\n points,\n components: parts,\n ...count(issues, (i) => i.at.element !== null && ids.has(i.at.element)),\n };\n };\n const blocks = (content: readonly Node[]): OutlineBlock[] => {\n const out: OutlineBlock[] = [];\n let run: Node[] = [];\n const flush = () => {\n if (run.some((n) => n.type === 'element' || n.value.trim() !== ''))\n out.push(block('text', null, components(run)));\n run = [];\n };\n for (const node of content) {\n if (node.type === 'element' && node.tag === COLUMNS_TAG) {\n // In reading order, as the surface numbers them: a layout is no block, what is in its columns is.\n flush();\n for (const column of node.children) {\n if (isElement(column, COLUMN_TAG)) out.push(...blocks(column.children));\n }\n } else if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {\n flush();\n out.push(block('component', node, [entry(node)]));\n } else {\n run.push(node);\n }\n }\n flush();\n return out;\n };\n const page = (id: string | null, label: string | null, content: readonly Node[]): OutlinePage => {\n const list = blocks(content);\n return {\n id,\n label,\n ...count(issues, (i) =>\n id === null ? i.at.page === null && i.at.tag !== null && i.at.tag !== DOC_TAG : i.at.page === id,\n ),\n components: components(content),\n blocks: list,\n points: sum(list.map((b) => b.points)),\n };\n };\n const nodes = parseHtml(source);\n const doc = nodes.find((n): n is ElementNode => isElement(n, DOC_TAG));\n const content = withoutRules(doc?.children ?? nodes);\n const pages: OutlinePage[] = [];\n if (content.some((n) => isElement(n, PAGE_TAG))) {\n // Loose content between pages (an error) is listed as an implicit page where it has components.\n let loose: Node[] = [];\n const flush = () => {\n const entry = page(null, null, loose);\n if (entry.components.length > 0) pages.push(entry);\n loose = [];\n };\n for (const node of content) {\n if (!isElement(node, PAGE_TAG)) {\n loose.push(node);\n continue;\n }\n flush();\n const attr = (name: string) => (Object.hasOwn(node.attrs, name) ? (node.attrs[name] ?? null) : null);\n pages.push(page(attr('id'), attr('label'), node.children));\n }\n flush();\n } else {\n pages.push(page(null, null, content));\n }\n return { pages, ...count(issues, () => true), points: sum(pages.map((p) => p.points)) };\n };\n\n /**\n * How authors know each component with an id, with its page's number when the document has pages: a block\n * component directly on its page by the number of its block there (the blocks of `outline`, which its card's head\n * shows), any other by its number among the components of its type on its page (document order); `page` is null\n * without pages. The last source's names are kept.\n */\n type Name = { readonly n: number; readonly page: number | null };\n let named: { readonly source: string; readonly names: Map<string, Name> } | null = null;\n const namesIn = (source: string): Map<string, Name> => {\n if (named?.source === source) return named.names;\n const names = new Map<string, Name>();\n const nodes = parseHtml(source);\n const content = withoutRules(\n nodes.find((n): n is ElementNode => isElement(n, DOC_TAG))?.children ?? nodes,\n );\n const paged = content.some((n) => isElement(n, PAGE_TAG));\n const set = (node: ElementNode, n: number, page: number | null) => {\n const id = Object.hasOwn(node.attrs, 'id') ? node.attrs.id : undefined;\n if (id === undefined || id === '' || names.has(id)) return;\n names.set(id, { n, page });\n };\n const inText = (nodes: readonly Node[], page: number | null, seen: Map<string, number>) => {\n for (const node of nodes) {\n if (node.type !== 'element') continue;\n if (!registered.has(node.tag)) {\n inText(node.children, page, seen);\n continue;\n }\n const n = (seen.get(node.tag) ?? 0) + 1;\n seen.set(node.tag, n);\n set(node, n, page);\n }\n };\n const blocks = (nodes: readonly Node[], page: number | null) => {\n const seen = new Map<string, number>();\n let block = 0;\n let text = false;\n const walk = (nodes: readonly Node[]) => {\n for (const node of nodes) {\n if (node.type === 'element' && node.tag === COLUMNS_TAG) {\n for (const column of node.children) {\n text = false;\n if (isElement(column, COLUMN_TAG)) walk(column.children);\n }\n text = false;\n continue;\n }\n if (node.type === 'element' && registered.get(node.tag)?.display === 'block') {\n block++;\n text = false;\n set(node, block, page);\n continue;\n }\n // A text block starts with its first element or words, as in `outline`.\n if (!text && (node.type === 'element' || node.value.trim() !== '')) {\n block++;\n text = true;\n }\n inText([node], page, seen);\n }\n };\n walk(nodes);\n };\n if (paged) {\n const pages = content.filter((n): n is ElementNode => isElement(n, PAGE_TAG));\n pages.forEach((page, i) => {\n blocks(page.children, i + 1);\n });\n } else {\n blocks(content, null);\n }\n named = { source, names };\n return names;\n };\n\n /** `source` with fresh ids, none of them in `used` (which takes them), on pages and components without one. */\n function withIds(source: string, used: Set<string>): string {\n const edits: Edit[] = [];\n for (const { tag, id, range } of scanRanges(source)) {\n if (id !== null && id.trim() !== '') continue;\n if (tag !== PAGE_TAG && !registered.has(tag)) continue;\n const prefix = tag === PAGE_TAG ? 'page' : (byTag.get(tag)?.idPrefix ?? tag.replace(/^astl-/, ''));\n const fresh = freshId(isSourceId(`${prefix}-1`) ? prefix : 'item', used);\n used.add(fresh);\n const written = range.startTag.attributes.find((a) => a.name === 'id');\n const at = range.startTag.start + 1 + tag.length;\n edits.push(\n written === undefined\n ? { start: at, end: at, text: ` id=\"${fresh}\"` }\n : { start: written.start, end: written.end, text: `id=\"${fresh}\"` },\n );\n }\n return applyEdits(source, edits);\n }\n\n /**\n * `html` (to insert into `source`) where each element of a type with a `companion` whose attribute is empty names\n * one: the first of `html` (a starter brings its own), else of `source`, else the one `withCompanion` adds.\n */\n function linkCompanions(html: string, source: string, used: ReadonlySet<string>): string {\n const edits: Edit[] = [];\n for (const { tag, range } of scanRanges(html)) {\n const companion = byTag.get(tag)?.companion;\n const other = companion === undefined ? undefined : byTag.get(companion.tag);\n if (companion === undefined || other === undefined) continue;\n if (attributeValue(range.startTag, companion.attribute)) continue;\n const first = (within: string) => scanElements(within).find((e) => e.tag === companion.tag && e.id)?.id;\n const value = first(html) ?? first(source) ?? freshId(other.idPrefix, used);\n const own = html.slice(range.start, range.end);\n const text = updateElement(own, { kind: 'attribute', name: companion.attribute, value });\n edits.push({ start: range.start, end: range.end, text });\n }\n return applyEdits(html, edits);\n }\n\n function instantiate(tag: string, source: string, templateId?: string, selection = ''): string {\n const descriptor = byTag.get(tag);\n if (descriptor === undefined) throw new TypeError(`No editor descriptor for <${tag}>`);\n const named = templateId === undefined ? null : descriptor.templates?.find((x) => x.id === templateId);\n if (named === undefined)\n throw new TypeError(`Editor descriptor <${tag}> has no template \"${templateId}\"`);\n const used = usedIds(source);\n const id = freshId(descriptor.idPrefix, used);\n const namespace = descriptor.manifest.messages;\n const html = (named?.template ?? descriptor.template)\n .replace(/\\{\\{t:([^}]+)\\}\\}/g, (_, key: string) => escapeHtml(t(namespace, key.trim())))\n .replace(/\\{\\{id\\}\\}/g, id)\n // Last: the author's text is never read for placeholders.\n .replace(/\\{\\{selection\\}\\}/g, () => escapeHtml(selection));\n for (const written of usedIds(html)) used.add(written);\n // A starter can hold more components (gaps and their word bank): those it writes without an id get fresh ones.\n return linkCompanions(withIds(html, used), source, used);\n }\n\n return {\n engine,\n locale,\n descriptors: [...byTag.values()],\n elements: options.elements ?? [],\n styleTemplates,\n urlPolicy: strictUrlPolicy(options.urlPolicy ?? isSafeUrl),\n fonts: (options.fonts ?? DEFAULT_FONTS).map(normalFont),\n styles: readyStyles(options.styles ?? DEFAULT_STYLES, (name) => {\n const key = `style.preset.${name}`;\n const label = t(EDITOR_NAMESPACE, key);\n return label === key ? name : label;\n }),\n uploadAsset: options.uploadAsset ?? null,\n pickPicture: options.pickPicture ?? null,\n descriptor: (tag) => byTag.get(tag) ?? null,\n templates: (tag) => byTag.get(tag)?.templates ?? [],\n t,\n loadMenuMessages: () =>\n (menus ??= Promise.resolve(options.menuMessages?.() ?? []).then(addMessages, (error: unknown) => {\n menus = null;\n console.error(error);\n })),\n addMessages,\n instantiate,\n withCompanion(tag, source, id) {\n const companion = byTag.get(tag)?.companion;\n if (companion === undefined || !byTag.has(companion.tag)) return null;\n const doc = elementTree(source).find((range) => range.name === DOC_TAG);\n if (doc === undefined) return null;\n const pages = doc.children.filter((range) => range.name === PAGE_TAG);\n const elements = scanRanges(source);\n // The page an element plays on: the document without pages (or for an element on none).\n const pageOf = (range: ElementRange) =>\n pages.find((page) => page.start <= range.start && range.end <= page.end) ?? doc;\n const companionsOf = (page: ElementRange) =>\n elements.flatMap((e) =>\n e.tag === companion.tag && e.id && page.start <= e.start && e.end <= page.end ? [e.id] : [],\n );\n const named = (range: ElementRange) => attributeValue(range.startTag, companion.attribute) ?? '';\n const target = elements.find(\n (e) =>\n e.tag === tag &&\n (id === undefined ? !companionsOf(pageOf(e.range)).includes(named(e.range)) : e.id === id),\n );\n if (target === undefined) return null;\n const page = pageOf(target.range);\n const own = companionsOf(page);\n if (own.includes(named(target.range))) return null;\n const [first] = own;\n const added = first === undefined ? instantiate(companion.tag, source) : '';\n const value = first ?? scanElements(added).find((e) => e.tag === companion.tag)?.id ?? '';\n const html = source.slice(target.start, target.end);\n const at = page.endTag?.start ?? page.end;\n return applyEdits(source, [\n {\n start: target.start,\n end: target.end,\n text: updateElement(html, { kind: 'attribute', name: companion.attribute, value }),\n },\n { start: at, end: at, text: added },\n ]);\n },\n inspect(elementHtml, source) {\n const el = firstElement(parseHtml(elementHtml));\n if (el === null) return null;\n const manifest = manifestOf(el.tag);\n if (manifest === null) return null;\n const templates = templateOptions('component', el.tag);\n // Another component of the document, scanned and parsed only when a field asks for it.\n const find = (id: string): ElementNode | null => {\n if (source === undefined || id === '') return null;\n const at = scanElements(source).find((e) => e.id === id);\n return at === undefined ? null : firstElement(parseHtml(source.slice(at.start, at.end)));\n };\n return inspectorModel(el, manifest, byTag.get(el.tag) ?? null, textsFor(manifest), templates, find);\n },\n inspectDocument(source) {\n // The scanner, as `update` uses it: the document is the first start tag (and no full parse per keystroke).\n const start = tokenize(source).find((tag) => tag.type === 'start');\n if (start?.name !== DOC_TAG) return null;\n const written = attributeValue(start, STYLE_TEMPLATE_ATTRIBUTE);\n const templates = templateOptions('document');\n if (templates.length === 0 && written === null) return null;\n const root = element(DOC_TAG, written === null ? {} : { [STYLE_TEMPLATE_ATTRIBUTE]: written });\n const label = t(EDITOR_NAMESPACE, 'inspector.documentStyle');\n const unset = t(EDITOR_NAMESPACE, 'inspector.styleTemplate.default');\n return {\n tag: DOC_TAG,\n id: null,\n label: t(EDITOR_NAMESPACE, 'inspector.document'),\n icon: null,\n fields: [styleTemplateField(root, label, unset, templates)],\n };\n },\n update: updateElement,\n validate: (source) => engine.validate(source),\n describe(issue, source, options) {\n const { id } = issue.params;\n const at =\n source !== undefined &&\n issue.namespace !== ENGINE_NAMESPACE &&\n id === issue.at.element &&\n typeof id === 'string'\n ? namesIn(source).get(id)\n : undefined;\n const name =\n at === undefined\n ? undefined\n : at.page === null || options?.page === false\n ? String(at.n)\n : t(EDITOR_NAMESPACE, 'issue.onPage', { n: at.n, page: at.page });\n const named = name === undefined ? issue : { ...issue, params: { ...issue.params, id: name } };\n const own = t(named.namespace, named.code, named.params);\n return own === named.code ? engine.describe(named, locale) : own;\n },\n assignIds: (source) => withIds(source, usedIds(source)),\n outline,\n async preview(source, options) {\n const result = await engine.compile(source, { salt });\n if (!result.ok) return { ok: false, issues: result.issues };\n return {\n ok: true,\n view: result.view,\n checker: localChecker(engine, result.key, options?.policy),\n issues: result.issues,\n };\n },\n };\n}\n","import type { EditorStyleTargetKind } from '@astl/core';\n\n/**\n * The event of a request for a style form or the rules (`detail.target`: the target at the cursor, or `rules`). It\n * bubbles, is composed and can be cancelled: a host that shows them itself calls `preventDefault`, and the element that\n * was asked shows nothing. Otherwise that element shows its default: the toolbar a popup, the inspector a form in place.\n */\nexport const STYLE_OPEN = 'astl-style-open';\n\n/** What `astl-style-open` asks for. */\nexport interface StyleOpen {\n readonly target: EditorStyleTargetKind | 'rules';\n}\n\nlet registry: CustomElementRegistry | null = null;\nlet loading: Promise<void> | null = null;\n\n/** Where the kit is defined: the style elements go there too. */\nexport function styleElementsIn(where: CustomElementRegistry): void {\n registry = where;\n}\n\n/**\n * Defines `<astl-style-form>` and `<astl-style-rules>` where the kit is defined, and resolves once they are. A module of\n * their own, outside the editor's first load: the toolbar and the inspector call this on first use, a host that places\n * either element itself calls it first.\n */\nexport function loadStyleElements(): Promise<void> {\n loading ??= Promise.all([import('./style-form.js'), import('./style-rules.js')]).then(\n ([{ AstlStyleForm }, { AstlStyleRules }]) => {\n const target = registry ?? customElements;\n if (target.get('astl-style-form') === undefined) target.define('astl-style-form', AstlStyleForm);\n if (target.get('astl-style-rules') === undefined) target.define('astl-style-rules', AstlStyleRules);\n },\n (error: unknown) => {\n // A failed chunk load is not cached by every browser: the next use tries again.\n loading = null;\n throw error;\n },\n );\n return loading;\n}\n\nlet helping: Promise<void> | null = null;\n\n/**\n * Defines `<astl-help-form>` (the inspector's help for students) where the kit is defined, and resolves once it is:\n * a module of its own, outside the editor's first load, like the style elements. The inspector calls this when it shows\n * a graded element, the insert menu before it adds help.\n */\nexport function loadHelpForm(): Promise<typeof import('./help-form.js')> {\n const module = import('./help-form.js');\n helping ??= module.then(\n ({ AstlHelpForm }) => {\n const target = registry ?? customElements;\n if (target.get('astl-help-form') === undefined) target.define('astl-help-form', AstlHelpForm);\n },\n (error: unknown) => {\n helping = null;\n throw error;\n },\n );\n return helping.then(() => module);\n}\n","import type { EditorDescriptor, EditorTemplate } from '@astl/core';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type SVGTemplateResult,\n svg,\n type TemplateResult,\n} from 'lit';\nimport { type Authoring, type PictureFields, pictureHtml } from '../authoring.js';\nimport { scanElements } from '../scan.js';\nimport { LAYOUTS, type LayoutName, layoutHtml } from '../style-model.js';\nimport { AuthoringElement } from './base.js';\nimport type { HelpKind } from './help-form.js';\nimport type { AstlPictureDialog } from './picture-dialog.js';\nimport { loadHelpForm } from './style-load.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/**\n * Generic glyphs by display, for pictures and for a page break: shapes only, stroked by the `.icon` rule of the element\n * showing them (hosts restyle `::part(icon)`; `data-icon` carries the icon name).\n */\nexport const GLYPHS: Readonly<\n Record<'inline' | 'block' | 'picture' | 'page' | 'columns', SVGTemplateResult>\n> = {\n inline: svg`<rect x=\"2.5\" y=\"6.5\" width=\"15\" height=\"7\" rx=\"1.5\"/><path d=\"M6 10h5\"/>`,\n block: svg`<path d=\"M3.5 5h13M3.5 10h13M3.5 15h8\"/>`,\n picture: svg`<rect x=\"2.5\" y=\"3.5\" width=\"15\" height=\"13\" rx=\"1.5\"/><path d=\"M4.5 14l4-4.5 3 3 2-2 2.5 3.5\"/><circle cx=\"13.5\" cy=\"7\" r=\"1.5\"/>`,\n page: svg`<path d=\"M4.5 2.5v4h11v-4M4.5 17.5v-4h11v4M2.5 10h2.5M8.75 10h2.5M15 10h2.5\"/>`,\n columns: svg`<rect x=\"2.5\" y=\"3.5\" width=\"15\" height=\"13\" rx=\"1.5\"/><path d=\"M10 3.5v13\"/>`,\n};\n\nexport type Glyph = keyof typeof GLYPHS;\n\n/**\n * Glyphs of their own for the block types that toolbars feature by default (a choice, an ordering task, sorting into\n * groups), by their descriptor's `icon` name, so featured buttons side by side differ; other types get their display's.\n */\nexport const TYPE_GLYPHS: ReadonlyMap<string, SVGTemplateResult> = new Map([\n [\n 'list-checks',\n svg`<path d=\"M3 6a2 2 0 1 0 4 0 2 2 0 1 0-4 0m0 8a2 2 0 1 0 4 0 2 2 0 1 0-4 0M10 6h7m-7 8h7\"/><circle cx=\"5\" cy=\"6\" r=\"1\"/>`,\n ],\n ['list-numbers', svg`<path d=\"M6.5 16V4M3.5 7l3-3 3 3m4 9V4m-3 9l3 3 3-3\"/>`],\n ['kanban', svg`<path d=\"M3.5 3.5h5v5h-5zm8 0h5v5h-5zm-8 8h5v5h-5zm8 0h5v5h-5z\"/>`],\n // Help for students: a bulb, an \"i\" in a circle, a speech bubble.\n [\n 'help-hint',\n svg`<path d=\"M7.5 15.5h5M8.5 18h3M10 2.5a5 5 0 0 0-3 9c.6.5 1 1.2 1 2v.5h4v-.5c0-.8.4-1.5 1-2a5 5 0 0 0-3-9z\"/>`,\n ],\n ['help-explanation', svg`<circle cx=\"10\" cy=\"10\" r=\"7.5\"/><path d=\"M10 9v5m0-7.5v.5\"/>`],\n ['help-feedback', svg`<path d=\"M3.5 4.5h13v9h-7l-4 3v-3h-2z\"/>`],\n]);\n\n/** What \"Hint\", \"Explanation\" and \"Feedback\" add (`addHelp`). */\nconst HELP_KINDS: readonly HelpKind[] = ['hint', 'explanation', 'feedback'];\n\n/** The groups of `<astl-insert-menu>`, in the order it shows them. */\nexport type InsertGroup = 'components' | 'exercises' | 'content' | 'layouts';\n\nconst GROUPS: readonly InsertGroup[] = ['components', 'exercises', 'content', 'layouts'];\n\n/** The event `<astl-insert-menu>` fires after it inserted something; `detail.html` is what it inserted. */\nexport const INSERTED = 'astl-inserted';\n\n/** Text compared by a search: lower case, without accents. */\nexport const searchable = (text: string): string =>\n text.normalize('NFD').replace(/\\p{M}/gu, '').toLocaleLowerCase();\n\n/** The attribute with the picture of a type whose zones or pins sit on one (its picture field's `src`), or null. */\nfunction pictureAttribute(descriptor: EditorDescriptor): string | null {\n for (const field of descriptor.fields ?? []) {\n if (field.kind === 'picture-regions' || field.kind === 'picture-points') return field.src;\n }\n return null;\n}\n\n/**\n * `source` with `picture` on its first element of `tag`: the address in `attribute`, and the alt text and size where\n * the type takes `alt`, `width` and `height`. The rest stays as written.\n */\nfunction withPicture(\n authoring: Authoring,\n source: string,\n tag: string,\n attribute: string,\n picture: PictureFields,\n): string {\n const found = scanElements(source).find((e) => e.tag === tag);\n const manifest = authoring.descriptor(tag)?.manifest;\n if (found === undefined || manifest === undefined) return source;\n const takes = (name: string) => manifest.attributes.some((a) => a.name === name);\n const values: [string, string | undefined][] = [\n [attribute, picture.src],\n ['alt', takes('alt') ? picture.alt : undefined],\n ['width', takes('width') ? picture.width?.toString() : undefined],\n ['height', takes('height') ? picture.height?.toString() : undefined],\n ];\n let element = source.slice(found.start, found.end);\n for (const [name, value] of values) {\n if (value !== undefined) element = authoring.update(element, { kind: 'attribute', name, value });\n }\n return source.slice(0, found.start) + element + source.slice(found.end);\n}\n\n/**\n * `<astl-insert-menu>`: what authors can add, in named groups (`groups`): \"Components\" (each type with its default\n * template), \"Exercises\" (the types' named starters, when any) and \"Content\" (\"Picture\", which asks for the picture in a\n * dialog, and \"Page break\" when the editor can split pages, `EditorAdapter.splitPage`). Each entry shows its icon, its\n * name and a one-line description, which together name its button; a press inserts at the cursor. The descriptions of\n * types with `menuMessages` load when the menu is first shown (inside a popover: when that opens).\n */\nexport class AstlInsertMenu extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n filter: {},\n groups: { attribute: false },\n dialog: { attribute: false },\n };\n\n /**\n * Shows only the entries whose label or description holds this text (any case, accents ignored), and a note when\n * none does. Default `''`: every entry.\n */\n declare filter: string;\n /**\n * The groups shown, in their own order. Default: all of them. A lone group's title is for screen readers only: the\n * place that shows the menu names it (the toolbar's \"Templates\").\n */\n declare groups: readonly InsertGroup[];\n /** The picture dialog to ask with; null (default): this element's own. */\n declare dialog: AstlPictureDialog | null;\n\n constructor() {\n super();\n this.filter = '';\n this.groups = GROUPS;\n this.dialog = null;\n }\n\n /** The authoring whose menu messages were asked for. */\n #menus: Authoring | null = null;\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n const authoring = this.authoring;\n const popover = this.closest('[popover]');\n if (authoring === null || authoring === this.#menus || popover?.matches(':popover-open') === false)\n return;\n this.#menus = authoring;\n void authoring.loadMenuMessages().then(() => this.requestUpdate());\n }\n\n #dialog(): AstlPictureDialog | null {\n return this.dialog ?? this.renderRoot.querySelector<AstlPictureDialog>('astl-picture-dialog');\n }\n\n static override styles: CSSResultGroup = [\n kitStyles,\n // The dialog redeclares the tokens on its :host: it takes this element's (theme, host overrides).\n inheritTokens('astl-picture-dialog'),\n css`\n .group {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n }\n .group-title {\n margin: 0;\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n font-weight: 700;\n text-transform: uppercase;\n letter-spacing: 0.04em;\n }\n .insert {\n inline-size: 100%;\n align-items: flex-start;\n }\n .text {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n }\n .label {\n font-weight: 600;\n }\n .description {\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n button:disabled .description {\n color: inherit;\n }\n .icon {\n fill: none;\n stroke: currentColor;\n stroke-width: 1.6;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .icon circle {\n fill: currentColor;\n stroke: none;\n }\n `,\n ];\n\n /**\n * Inserts a new element of `tag` at the cursor: its default template, or the named starter `template`; with\n * `picture`, the element takes it (a type whose zones or pins sit on a picture: its picture field's address, its\n * alt text and size). An element whose companion its page lacks brings it at the end of the page (the word bank of\n * a first gap there); the cursor stays on the new element. Returns its source HTML, or null without authoring or\n * adapter.\n */\n insert(tag: string, template?: string, picture?: PictureFields): string | null {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return null;\n // A template that takes the selected text (a gap's answer) puts the element in its place.\n const raw =\n template === undefined\n ? authoring.descriptor(tag)?.template\n : authoring.templates(tag).find((t) => t.id === template)?.template;\n const selected = raw?.includes('{{selection}}') === true ? (adapter.selectedText?.() ?? '') : '';\n const instantiated = authoring.instantiate(tag, adapter.getSource(), template, selected);\n const descriptor = authoring.descriptor(tag);\n const attribute = descriptor === null ? null : pictureAttribute(descriptor);\n const source =\n picture === undefined || attribute === null\n ? instantiated\n : withPicture(authoring, instantiated, tag, attribute, picture);\n adapter.insert(source, selected === '' ? undefined : { replaceSelection: true });\n const id = scanElements(source)[0]?.id ?? undefined;\n const next = template === undefined ? authoring.withCompanion(tag, adapter.getSource(), id) : null;\n if (next !== null) {\n adapter.setSource(next);\n if (id) adapter.select(id);\n }\n this.#inserted(source);\n return source;\n }\n\n #inserted(html: string): void {\n this.dispatchEvent(new CustomEvent(INSERTED, { detail: { html }, bubbles: true, composed: true }));\n }\n\n /**\n * What a press on a component or exercise entry does: inserts it (`insert`), after asking for its picture when the\n * type needs one. Resolves with the inserted HTML, or null when cancelled.\n */\n add(tag: string, template?: string): Promise<string | null> {\n return this.#press(tag, template);\n }\n\n /**\n * A press on a component or exercise button. A type whose zones or pins sit on a picture asks for the picture first\n * (an upload or an address, and its alt text, which it needs): no template can name a picture that loads on every\n * host, so none ever shows a broken one. Cancelling inserts nothing.\n */\n async #press(tag: string, template?: string): Promise<string | null> {\n const descriptor = this.authoring?.descriptor(tag) ?? null;\n const attribute = descriptor === null ? null : pictureAttribute(descriptor);\n if (attribute === null) return this.insert(tag, template);\n const picture = await this.#dialog()?.ask({\n caption: false,\n altRequired: true,\n target: { tag, attribute },\n });\n return picture !== undefined && picture !== null ? this.insert(tag, template, picture) : null;\n }\n\n /** Asks for a picture in the dialog and inserts it at the cursor. Resolves with its HTML, or null when cancelled. */\n async insertPicture(): Promise<string | null> {\n const dialog = this.#dialog();\n if (dialog === null || this.adapter === null) return null;\n const fields = await dialog.ask();\n const adapter = this.adapter;\n if (fields === null || adapter === null) return null;\n const source = pictureHtml(fields);\n adapter.insert(source);\n this.#inserted(source);\n return source;\n }\n\n /**\n * Inserts a layout at the cursor (`EditorStyles.insertLayout`), the cursor in its first empty block. Beside a picture\n * it asks for the picture first, as \"Picture\" does, and cancelling inserts nothing. Resolves with its HTML, or null.\n */\n async insertLayout(name: LayoutName): Promise<string | null> {\n let picture = '';\n if (name === 'picture-text') {\n const fields = await this.#dialog()?.ask();\n if (fields === null || fields === undefined) return null;\n picture = pictureHtml(fields);\n }\n const source = layoutHtml(name, picture);\n if (this.adapter?.style?.insertLayout(source) !== true) return null;\n this.#inserted(source);\n return source;\n }\n\n /**\n * Adds a hint, the explanation or a feedback text to the graded element at the cursor (the inspector's help form\n * shows it, focused), or else to the page at the cursor. Resolves with the HTML put on the page, '' when the element\n * got it, or null without an editor.\n */\n async addHelp(kind: HelpKind): Promise<string | null> {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return null;\n const { addHelp } = await loadHelpForm();\n const added = addHelp(authoring, adapter, kind) ?? '';\n this.#inserted(added);\n return added;\n }\n\n /** Inserts a page break at the cursor (`EditorAdapter.splitPage`): the new page's id, or null. */\n insertPageBreak(): string | null {\n const id = this.adapter?.splitPage?.() ?? null;\n if (id !== null) this.#inserted('');\n return id;\n }\n\n #button(\n glyph: Glyph,\n icon: string,\n label: string,\n description: string | null,\n data: Readonly<Record<string, string>>,\n press: () => void,\n ): TemplateResult | null {\n const query = searchable(this.filter.trim());\n if (query !== '' && !searchable(`${label} ${description ?? ''}`).includes(query)) return null;\n return html`<li>\n <button\n type=\"button\"\n class=\"insert\"\n part=\"button\"\n data-tag=${data.tag ?? nothing}\n data-template=${data.template ?? nothing}\n data-content=${data.content ?? nothing}\n aria-label=${description === null ? nothing : this.t('label.text', { label, text: description })}\n ?disabled=${this.adapter === null}\n @click=${press}\n >\n <svg class=\"icon\" part=\"icon icon-${icon}\" data-icon=${icon} viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">\n ${TYPE_GLYPHS.get(icon) ?? GLYPHS[glyph]}\n </svg>\n <span class=\"text\">\n <span class=\"label\">${label}</span>\n ${description === null ? nothing : html`<span class=\"description\">${description}</span>`}\n </span>\n </button>\n </li>`;\n }\n\n #group(\n id: string,\n title: string,\n entries: readonly (TemplateResult | null)[],\n ): TemplateResult | typeof nothing {\n const items = entries.filter((item) => item !== null);\n if (items.length === 0) return nothing;\n return html`<div class=\"group\" role=\"group\" aria-labelledby=${id}>\n <h3 class=\"group-title ${this.groups.length === 1 ? 'astl-vh' : ''}\" id=${id} part=\"group-title\">${title}</h3>\n <ul role=\"list\">\n ${items}\n </ul>\n </div>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const authoring = this.authoring;\n if (authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const messages = (d: EditorDescriptor) => (key: string) => authoring.t(d.manifest.messages, key);\n // A description not loaded yet (`menuMessages`) is left out, never shown as its key.\n const line = (d: EditorDescriptor, key: string | undefined) => {\n const text = key === undefined ? key : messages(d)(key);\n return text === key ? null : (text ?? null);\n };\n const shows = (group: InsertGroup) => this.groups.includes(group);\n const components = shows('components')\n ? authoring.descriptors.map((d) =>\n this.#button(\n d.manifest.display,\n d.icon,\n messages(d)(d.label),\n line(d, d.description),\n { tag: d.manifest.tag },\n () => void this.#press(d.manifest.tag),\n ),\n )\n : [];\n const exercises = (shows('exercises') ? authoring.descriptors : []).flatMap((d) =>\n authoring.templates(d.manifest.tag).map((template: EditorTemplate) => {\n const t = messages(d);\n const description = line(d, template.description);\n return this.#button(\n d.manifest.display,\n template.icon ?? d.icon,\n t(template.label),\n description,\n { tag: d.manifest.tag, template: template.id },\n () => void this.#press(d.manifest.tag, template.id),\n );\n }),\n );\n const content: (TemplateResult | null)[] = [];\n if (shows('content')) {\n content.push(\n this.#button(\n 'picture',\n 'image',\n this.t('insert.picture'),\n this.t('insert.picture.description'),\n { content: 'picture' },\n () => {\n void this.insertPicture();\n },\n ),\n );\n }\n if (shows('content')) {\n for (const kind of HELP_KINDS) {\n content.push(\n this.#button(\n 'block',\n `help-${kind}`,\n this.t(`insert.${kind}`),\n this.t(`insert.${kind}.description`),\n { content: kind },\n () => void this.addHelp(kind),\n ),\n );\n }\n }\n if (shows('content') && this.adapter?.splitPage !== undefined) {\n content.push(\n this.#button(\n 'page',\n 'files',\n this.t('insert.pageBreak'),\n this.t('insert.pageBreak.description'),\n { content: 'page-break' },\n () => {\n this.insertPageBreak();\n },\n ),\n );\n }\n const layouts: (TemplateResult | null)[] =\n shows('layouts') && this.adapter?.style !== undefined\n ? LAYOUTS.map((name) =>\n this.#button(\n 'columns',\n 'columns',\n this.t(`insert.layout.${name}`),\n this.t(`insert.layout.${name}.description`),\n { content: `layout-${name}` },\n () => void this.insertLayout(name),\n ),\n )\n : [];\n const none = [components, exercises, content, layouts].every((list) =>\n list.every((item) => item === null),\n );\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"title\">\n <h2 class=\"title\" id=\"title\" part=\"title\">${this.t('insert.title')}</h2>\n ${this.#group('group-components', this.t('insert.components'), components)}\n ${this.#group('group-exercises', this.t('insert.exercises'), exercises)}\n ${this.#group('group-content', this.t('insert.content'), content)}\n ${this.#group('group-layouts', this.t('insert.layouts'), layouts)}\n ${none ? html`<p class=\"note\" part=\"no-match\">${this.t('insert.noMatch', { query: this.filter.trim() })}</p>` : nothing}\n </section>\n ${this.dialog === null ? html`<astl-picture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51 @@
1
+ import{C as e,E as t,T as n,b as r}from"./runtime-DxAbpr3S.js";import{t as i}from"./messages-9xiYDvRT.js";var a={error:n`<circle cx="10" cy="10" r="7.5" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M7 7l6 6m0-6l-6 6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>`,warning:n`<path d="M10 2.8l7.6 13.4H2.4z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/><path d="M10 8v3.6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><circle cx="10" cy="14" r="1.1" fill="currentColor"/>`};function o(e){return[...e].sort((e,t)=>Number(e.severity!==`error`)-Number(t.severity!==`error`))}function s(e){return e.at.element??e.at.page}var c=t`
2
+ .issue > button,
3
+ .issue > .static {
4
+ box-sizing: border-box;
5
+ display: flex;
6
+ flex-wrap: wrap;
7
+ align-items: baseline;
8
+ gap: var(--astl-space-1) var(--astl-space-2);
9
+ inline-size: 100%;
10
+ min-block-size: var(--astl-target-min);
11
+ padding-block: var(--astl-space-2);
12
+ padding-inline: var(--astl-space-3);
13
+ border: var(--astl-outline-width) solid var(--astl-line);
14
+ border-inline-start-width: var(--astl-space-1);
15
+ border-radius: var(--astl-radius-m);
16
+ background: var(--astl-surface);
17
+ color: var(--astl-ink);
18
+ text-align: start;
19
+ }
20
+ .issue[data-severity='error'] > * {
21
+ border-inline-start-color: var(--astl-danger);
22
+ }
23
+ .issue[data-severity='warning'] > * {
24
+ border-inline-start-color: var(--astl-warning);
25
+ }
26
+ .severity {
27
+ display: inline-flex;
28
+ align-items: center;
29
+ gap: var(--astl-space-1);
30
+ font-weight: 700;
31
+ }
32
+ .issue[data-severity='error'] .severity {
33
+ color: var(--astl-danger);
34
+ }
35
+ .issue[data-severity='warning'] .severity {
36
+ color: var(--astl-warning);
37
+ }
38
+ .message {
39
+ flex: 1 1 12rem;
40
+ min-inline-size: 0;
41
+ }
42
+ `;function l(t,n,r,o){let c=s(t),l=n.t(i,`severity.${t.severity}`),u=n.describe(t,o),d=e`<span class="severity"
43
+ ><svg class="icon" viewBox="0 0 20 20" aria-hidden="true" focusable="false">${a[t.severity]}</svg
44
+ >${l}<span class="astl-vh">:</span></span
45
+ >
46
+ <span class="message">${u}</span>`;return e`<li class="issue" data-code=${t.code} data-severity=${t.severity}>
47
+ ${c===null||r===null?e`<div class="static">${d}</div>`:e`<button type="button" data-target=${c} aria-label=${n.t(i,`label.text`,{label:l,text:u})} @click=${()=>r.select(c)}>${d}</button>`}
48
+ </li>`}function u(t,n,i,a){return t.length===0?r:e`<ul class="issues" role="list">
49
+ ${o(t).map(e=>l(e,n,i,a))}
50
+ </ul>`}export{o as i,c as n,u as r,a as t};
51
+ //# sourceMappingURL=issue-list-BgnXzXRM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue-list-BgnXzXRM.js","names":["nothing","b","i","w","A","EDITOR_NAMESPACE","SEVERITY_ICONS","sortIssues","issues","a","issueTarget","issue","issueStyles","renderIssue","target","label","authoring","text","source","content","adapter","renderIssues"],"sources":["../../../../editor/src/elements/issue-list.ts"],"sourcesContent":["import type { EditorAdapter, Issue, Severity } from '@astl/core';\nimport { type CSSResult, css, html, nothing, svg, type TemplateResult } from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { EDITOR_NAMESPACE } from '../messages.js';\n\n/** The severity icons (shapes with their own stroke), for the issue list and the inspector's banners. */\nexport const SEVERITY_ICONS: Readonly<Record<Severity, TemplateResult>> = {\n error: svg`<circle cx=\"10\" cy=\"10\" r=\"7.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.8\"/><path d=\"M7 7l6 6m0-6l-6 6\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\"/>`,\n warning: svg`<path d=\"M10 2.8l7.6 13.4H2.4z\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linejoin=\"round\"/><path d=\"M10 8v3.6\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\"/><circle cx=\"10\" cy=\"14\" r=\"1.1\" fill=\"currentColor\"/>`,\n};\n\n/** Errors first, then warnings; document order within each. */\nexport function sortIssues(issues: readonly Issue[]): Issue[] {\n return [...issues].sort((a, b) => Number(a.severity !== 'error') - Number(b.severity !== 'error'));\n}\n\n/** Source id an issue can jump to: its component, else its page. */\nexport function issueTarget(issue: Issue): string | null {\n return issue.at.element ?? issue.at.page;\n}\n\nexport const issueStyles: CSSResult = css`\n .issue > button,\n .issue > .static {\n box-sizing: border-box;\n display: flex;\n flex-wrap: wrap;\n align-items: baseline;\n gap: var(--astl-space-1) var(--astl-space-2);\n inline-size: 100%;\n min-block-size: var(--astl-target-min);\n padding-block: var(--astl-space-2);\n padding-inline: var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-inline-start-width: var(--astl-space-1);\n border-radius: var(--astl-radius-m);\n background: var(--astl-surface);\n color: var(--astl-ink);\n text-align: start;\n }\n .issue[data-severity='error'] > * {\n border-inline-start-color: var(--astl-danger);\n }\n .issue[data-severity='warning'] > * {\n border-inline-start-color: var(--astl-warning);\n }\n .severity {\n display: inline-flex;\n align-items: center;\n gap: var(--astl-space-1);\n font-weight: 700;\n }\n .issue[data-severity='error'] .severity {\n color: var(--astl-danger);\n }\n .issue[data-severity='warning'] .severity {\n color: var(--astl-warning);\n }\n .message {\n flex: 1 1 12rem;\n min-inline-size: 0;\n }\n`;\n\n/**\n * One issue: severity icon + word + message; a button that selects its element when it has one. With the document the\n * issue is about (`source`), the message names components as authors see them, not by id.\n */\nexport function renderIssue(\n issue: Issue,\n authoring: Authoring,\n adapter: EditorAdapter | null,\n source?: string,\n): TemplateResult {\n const target = issueTarget(issue);\n const label = authoring.t(EDITOR_NAMESPACE, `severity.${issue.severity}`);\n const text = authoring.describe(issue, source);\n const content = html`<span class=\"severity\"\n ><svg class=\"icon\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${SEVERITY_ICONS[issue.severity]}</svg\n >${label}<span class=\"astl-vh\">:</span></span\n >\n <span class=\"message\">${text}</span>`;\n return html`<li class=\"issue\" data-code=${issue.code} data-severity=${issue.severity}>\n ${\n target === null || adapter === null\n ? html`<div class=\"static\">${content}</div>`\n : html`<button type=\"button\" data-target=${target} aria-label=${authoring.t(EDITOR_NAMESPACE, 'label.text', { label, text })} @click=${() => adapter.select(target)}>${content}</button>`\n }\n </li>`;\n}\n\n/** A list of issues, or nothing when empty. */\nexport function renderIssues(\n issues: readonly Issue[],\n authoring: Authoring,\n adapter: EditorAdapter | null,\n source?: string,\n): TemplateResult | typeof nothing {\n if (issues.length === 0) return nothing;\n return html`<ul class=\"issues\" role=\"list\">\n ${sortIssues(issues).map((issue) => renderIssue(issue, authoring, adapter, source))}\n </ul>`;\n}\n"],"mappings":"A,0GAMA,IAAaM,EAA6D,CACxE,MAAO,CAAG,sLACV,QAAS,CAAG,0PACd,EAGA,SAAgBC,EAAW,EAAmC,CAC5D,MAAO,CAAC,GAAGC,CAAM,CAAC,CAAC,MAAM,EAAG,IAAM,OAAOC,EAAE,WAAa,OAAO,EAAI,OAAOR,EAAE,WAAa,OAAO,CAAC,CACnG,CAGA,SAAgBS,EAAY,EAA6B,CACvD,OAAOC,EAAM,GAAG,SAAWA,EAAM,GAAG,IACtC,CAEA,IAAaC,EAAyB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CzC,SAAgBC,EACd,EACA,EACA,EACA,EACgB,CAChB,IAAMC,EAASJ,EAAYC,CAAK,EAC1BI,EAAQC,EAAU,EAAEX,EAAkB,YAAYM,EAAM,UAAU,EAClEM,EAAOD,EAAU,SAASL,EAAOO,CAAM,EACvCC,EAAU,CAAI;oFAC8Db,EAAeK,EAAM,UAAU;SAC1GI,EAAM;;4BAEaE,EAAK,SAC/B,MAAO,EAAI,+BAA+BN,EAAM,KAAK,iBAAiBA,EAAM,SAAS;MAEjFG,IAAW,MAAQM,IAAY,KAC3B,CAAI,uBAAuBD,EAAQ,QACnC,CAAI,qCAAqCL,EAAO,cAAcE,EAAU,EAAEX,EAAkB,aAAc,CAAE,QAAO,MAAK,CAAC,EAAE,cAAgBe,EAAQ,OAAON,CAAM,EAAE,GAAGK,EAAQ,WAClL;QAEL,CAGA,SAAgBE,EACd,EACA,EACA,EACA,EACiC,CAEjC,OADIb,EAAO,SAAW,EAAUR,EACzB,CAAI;MACPO,EAAWC,CAAM,CAAC,CAAC,IAAK,GAAUK,EAAYF,EAAOK,EAAWI,EAASF,CAAM,CAAC,EAAE;QAExF,C"}
@@ -0,0 +1,2 @@
1
+ function e(e,t,n){let r=e.key;return t!==`inline`&&(r===`ArrowDown`||r===`ArrowUp`)?r===`ArrowDown`?1:-1:t===`block`||r!==`ArrowRight`&&r!==`ArrowLeft`?0:r===`ArrowRight`==(getComputedStyle(n).direction!==`rtl`)?1:-1}export{e as t};
2
+ //# sourceMappingURL=keys-DU-Qknmz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys-DU-Qknmz.js","names":["arrowDelta","key","event","axis","host"],"sources":["../../../../player/src/interaction/keys.ts"],"sourcesContent":["/**\n * Arrow keys that move: Up and Down (`block`), Left and Right (`inline`, in the writing direction) or all four\n * (`both`, for destinations laid out in two dimensions).\n */\nexport type Axis = 'block' | 'inline' | 'both';\n\n/**\n * The step an arrow key makes along `axis`: 1 forward (Down, or Right in left-to-right text), -1 back, 0 for any other\n * key. Left and Right swap when `host` is laid out right to left, so the next item is always the one read next.\n */\nexport function arrowDelta(event: KeyboardEvent, axis: Axis, host: Element): -1 | 0 | 1 {\n const key = event.key;\n if (axis !== 'inline' && (key === 'ArrowDown' || key === 'ArrowUp')) return key === 'ArrowDown' ? 1 : -1;\n if (axis === 'block' || (key !== 'ArrowRight' && key !== 'ArrowLeft')) return 0;\n return (key === 'ArrowRight') === (getComputedStyle(host).direction !== 'rtl') ? 1 : -1;\n}\n"],"mappings":"AAUA,SAAgBA,EAAW,EAAsB,EAAY,EAA2B,CACtF,IAAMC,EAAMC,EAAM,IAGlB,OAFIC,IAAS,WAAaF,IAAQ,aAAeA,IAAQ,WAAmBA,IAAQ,YAAc,EAAI,GAClGE,IAAS,SAAYF,IAAQ,cAAgBA,IAAQ,YAAqB,EACtEA,IAAQ,eAAmB,iBAAiBG,CAAI,CAAC,CAAC,YAAc,OAAS,EAAI,EACvF,C"}
@@ -0,0 +1,7 @@
1
+ import{S as e,b as t}from"./runtime-DxAbpr3S.js";import{c as n,i as r,l as i,r as a,s as o}from"./directive-helpers-D7lOZKnB.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2020 Google LLC
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */var s=o(class extends n{constructor(e){if(super(e),e.type!==i.PROPERTY&&e.type!==i.ATTRIBUTE&&e.type!==i.BOOLEAN_ATTRIBUTE)throw Error("The `live` directive is not allowed on child or event bindings");if(!r(e))throw Error("`live` bindings can only contain a single expression")}render(e){return e}update(n,[r]){if(r===e||r===t)return r;let o=n.element,s=n.name;if(n.type===i.PROPERTY){if(r===o[s])return e}else if(n.type===i.BOOLEAN_ATTRIBUTE){if(!!r===o.hasAttribute(s))return e}else if(n.type===i.ATTRIBUTE&&o.getAttribute(s)===r+``)return e;return a(n),r}});export{s as t};
7
+ //# sourceMappingURL=live-jdiyYln2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-jdiyYln2.js","names":["i","t","r","n","o","e","s","E","A","i","t","p","e","l","r$1","r","t$1"],"sources":["../../../../../node_modules/.pnpm/lit-html@3.3.3/node_modules/lit-html/directives/live.js"],"sourcesContent":["import{noChange as r,nothing as e}from\"../lit-html.js\";import{directive as i,Directive as t,PartType as n}from\"../directive.js\";import{isSingleExpression as o,setCommittedValue as s}from\"../directive-helpers.js\";\n/**\n * @license\n * Copyright 2020 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */const l=i(class extends t{constructor(r){if(super(r),r.type!==n.PROPERTY&&r.type!==n.ATTRIBUTE&&r.type!==n.BOOLEAN_ATTRIBUTE)throw Error(\"The `live` directive is not allowed on child or event bindings\");if(!o(r))throw Error(\"`live` bindings can only contain a single expression\")}render(r){return r}update(i,[t]){if(t===r||t===e)return t;const o=i.element,l=i.name;if(i.type===n.PROPERTY){if(t===o[l])return r}else if(i.type===n.BOOLEAN_ATTRIBUTE){if(!!t===o.hasAttribute(l))return r}else if(i.type===n.ATTRIBUTE&&o.getAttribute(l)===t+\"\")return r;return s(i),t}});export{l as live};\n//# sourceMappingURL=live.js.map\n"],"ignoreList":[0],"mappings":";;;;;EAKG,IAAMa,EAAEb,EAAE,cAAcC,CAAC,CAAC,YAAY,EAAE,CAAC,GAAG,MAAMC,CAAC,EAAEA,EAAE,OAAOC,EAAE,UAAUD,EAAE,OAAOC,EAAE,WAAWD,EAAE,OAAOC,EAAE,kBAAkB,MAAM,MAAM,gEAAgE,EAAE,GAAG,CAACC,EAAEF,CAAC,EAAE,MAAM,MAAM,sDAAsD,CAAC,CAAC,OAAO,EAAE,CAAC,OAAOa,CAAC,CAAC,OAAO,EAAE,CAACd,GAAG,CAAC,GAAGA,IAAIC,GAAGD,IAAII,EAAE,OAAOJ,EAAE,IAAM,EAAEQ,EAAE,QAAQI,EAAEJ,EAAE,KAAK,GAAGA,EAAE,OAAON,EAAE,SAAaF,IAAAA,IAAI,EAAEY,GAAG,OAAOX,CAAAA,MAAO,GAAGO,EAAE,OAAON,EAAE,kBAAsB,IAAA,CAAC,CAACF,IAAI,EAAE,aAAaY,CAAC,EAAE,OAAOX,CAAAA,MAAO,GAAGO,EAAE,OAAON,EAAE,WAAW,EAAE,aAAaU,CAAC,IAAIZ,EAAE,GAAG,OAAOC,EAAE,OAAOI,EAAEG,CAAC,EAAER,CAAC,CAAC,CAAC,E"}
@@ -0,0 +1,71 @@
1
+ import{C as e,E as t,b as n,r,v as i,y as a}from"./runtime-DxAbpr3S.js";import{n as o,r as s,t as c}from"./long-answer-manifest-BYJpZRtB.js";import{t as l}from"./live-jdiyYln2.js";import{t as u}from"./block-styles-CKo9x7Vt.js";var d=`astl.long-answer`,f=[{namespace:d,locale:`en`,messages:o},{namespace:d,locale:`pl`,messages:c}],p=2e3,m=1e3,h=class extends r{static manifest=s;static messages=f;static shadowRootOptions={...a.shadowRootOptions,delegatesFocus:!0};static styles=[t`
2
+ label,
3
+ .prompt {
4
+ display: block;
5
+ }
6
+ .prompt {
7
+ margin-block-end: var(--astl-space-3);
8
+ font-weight: 600;
9
+ }
10
+ textarea {
11
+ box-sizing: border-box;
12
+ display: block;
13
+ inline-size: 100%;
14
+ margin: 0;
15
+ padding-block: 0;
16
+ padding-inline: var(--astl-space-3);
17
+ border: var(--astl-outline-width) solid var(--astl-outline);
18
+ border-radius: var(--astl-radius-s);
19
+ background: var(--astl-surface);
20
+ color: var(--astl-ink);
21
+ font: inherit;
22
+ resize: vertical;
23
+ }
24
+ textarea::placeholder {
25
+ color: var(--astl-ink-muted);
26
+ opacity: 1;
27
+ }
28
+ `,t`
29
+ textarea[readonly] {
30
+ field-sizing: content;
31
+ resize: none;
32
+ cursor: default;
33
+ }
34
+ .notes {
35
+ display: flex;
36
+ flex-wrap: wrap;
37
+ gap: var(--astl-space-1) var(--astl-space-4);
38
+ margin-block-start: var(--astl-space-2);
39
+ color: var(--astl-ink-muted);
40
+ font-size: var(--astl-size-ui);
41
+ }
42
+ .notes p {
43
+ margin-block: 0;
44
+ }
45
+ .counter {
46
+ margin-inline-start: auto;
47
+ }
48
+ `,u];#e;disconnectedCallback(){super.disconnectedCallback(),clearTimeout(this.#e)}#t(){let e=this.numberAttribute(`maxlength`)??p,t=this.value.length,n=(this.numberAttribute(`minlength`)??0)-t;return{counter:t>=e?this.t(`ui.full`,{max:e}):this.t(`ui.count`,{count:t,max:e}),hint:n>0&&!this.disabled?this.t(`ui.more`,{count:n}):null}}render(){let t=this.numberAttribute(`rows`)??5,{counter:r,hint:a}=this.#t(),o=this.uiLanguage;return e`<div part="long-answer">
49
+ <label>
50
+ <span class="prompt" part="prompt"><slot></slot></span>
51
+ <textarea
52
+ part="input"
53
+ rows=${t}
54
+ maxlength=${this.numberAttribute(`maxlength`)??p}
55
+ placeholder=${i(this.stringAttribute(`placeholder`)??void 0)}
56
+ lang=${i(this.contentLang||void 0)}
57
+ spellcheck="false"
58
+ ?readonly=${this.disabled}
59
+ aria-describedby=${a===null?`counter`:`counter hint`}
60
+ .value=${l(this.value)}
61
+ @input=${e=>this.#n(e.target.value)}
62
+ @keydown=${e=>{t===1&&e.key===`Enter`&&e.preventDefault()}}
63
+ @blur=${()=>clearTimeout(this.#e)}
64
+ ></textarea>
65
+ </label>
66
+ <div class="notes" lang=${o.lang} dir=${o.dir}>
67
+ ${a===null?n:e`<p id="hint" part="hint">${a}</p>`}
68
+ <p class="counter" id="counter" part="counter">${r}</p>
69
+ </div>
70
+ </div>`}#n(e){this.updateValue(e),clearTimeout(this.#e),this.#e=setTimeout(()=>{if(this.disabled)return;let{counter:e,hint:t}=this.#t();this.announce(t===null?e:`${e} ${t}`)},m)}},g={manifest:s,element:h,messages:f};export{g as longAnswerElement};
71
+ //# sourceMappingURL=long-answer-CtzClLAx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"long-answer-CtzClLAx.js","names":["en","pl","LitElement","ifDefined","live","nothing","b","i$1","A","o","i","en_default","longAnswerManifest","pl_default","blockStyles","namespace","longAnswerUiMessages","MAX_LENGTH","PAUSE_MS","LongAnswerElement","SingleSlotElement","#pause","max","count","more","rows","#notes","ui","hint","#write","event","counter","value","longAnswerElement"],"sources":["../../../../components/src/long-answer/ui-messages.ts","../../../../components/src/long-answer/element.ts"],"sourcesContent":["import type { MessageCatalog } from '@astl/core';\nimport en from './messages/ui/en.json' with { type: 'json' };\nimport pl from './messages/ui/pl.json' with { type: 'json' };\n\nconst namespace = 'astl.long-answer';\n\n/**\n * The student strings (`ui.*`): the element's catalogs. A module of their own, because bundlers split by module: one\n * that also built `longAnswerMessages` would put the authoring strings into the element's chunk.\n */\nexport const longAnswerUiMessages: readonly MessageCatalog[] = [\n { namespace, locale: 'en', messages: en },\n { namespace, locale: 'pl', messages: pl },\n];\n","import type { ComponentManifest, MessageCatalog } from '@astl/core';\nimport { type ElementRegistration, SingleSlotElement } from '@astl/player';\nimport { type CSSResultGroup, css, html, LitElement, nothing, type TemplateResult } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { blockStyles } from '../block-styles.js';\nimport { longAnswerManifest } from './manifest.js';\nimport { longAnswerUiMessages } from './ui-messages.js';\n\n/** MAX_OPEN_ANSWER_LENGTH of @astl/core, in the UTF-16 units `maxlength` counts: never more code points. */\nconst MAX_LENGTH = 2000;\n\n/** The counter is announced once typing pauses this long, never on every key. */\nconst PAUSE_MS = 1000;\n\n/**\n * `<astl-long-answer>`: a native text area labelled by the slotted prompt, with a character counter and, below a\n * minimum, how many more to write; both describe the box. The author's maximum is the box's own `maxlength`. One open\n * slot, the element id: no verdict and no solution, read-only once handed in.\n */\nexport class LongAnswerElement extends SingleSlotElement {\n static override manifest: ComponentManifest = longAnswerManifest;\n static override messages: readonly MessageCatalog[] = longAnswerUiMessages;\n static override shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n static override styles: CSSResultGroup = [\n css`\n label,\n .prompt {\n display: block;\n }\n .prompt {\n margin-block-end: var(--astl-space-3);\n font-weight: 600;\n }\n textarea {\n box-sizing: border-box;\n display: block;\n inline-size: 100%;\n margin: 0;\n padding-block: 0;\n padding-inline: var(--astl-space-3);\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 resize: vertical;\n }\n textarea::placeholder {\n color: var(--astl-ink-muted);\n opacity: 1;\n }\n `,\n // Handed in or in review, the answer shows in full: the box grows with it instead of scrolling.\n css`\n textarea[readonly] {\n field-sizing: content;\n resize: none;\n cursor: default;\n }\n .notes {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-1) var(--astl-space-4);\n margin-block-start: var(--astl-space-2);\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-ui);\n }\n .notes p {\n margin-block: 0;\n }\n .counter {\n margin-inline-start: auto;\n }\n `,\n blockStyles,\n ];\n\n #pause: ReturnType<typeof setTimeout> | undefined;\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearTimeout(this.#pause);\n }\n\n /** What describes the box: the counter, and how many more to write while the minimum is not reached. */\n #notes(): { readonly counter: string; readonly hint: string | null } {\n const max = this.numberAttribute('maxlength') ?? MAX_LENGTH;\n const count = this.value.length;\n const more = (this.numberAttribute('minlength') ?? 0) - count;\n return {\n counter: count >= max ? this.t('ui.full', { max }) : this.t('ui.count', { count, max }),\n hint: more > 0 && !this.disabled ? this.t('ui.more', { count: more }) : null,\n };\n }\n\n protected override render(): TemplateResult {\n const rows = this.numberAttribute('rows') ?? 5;\n const { counter, hint } = this.#notes();\n const ui = this.uiLanguage;\n // The label holds the prompt and the box: the prompt names it, and the whole label is a target that focuses it.\n return html`<div part=\"long-answer\">\n <label>\n <span class=\"prompt\" part=\"prompt\"><slot></slot></span>\n <textarea\n part=\"input\"\n rows=${rows}\n maxlength=${this.numberAttribute('maxlength') ?? MAX_LENGTH}\n placeholder=${ifDefined(this.stringAttribute('placeholder') ?? undefined)}\n lang=${ifDefined(this.contentLang || undefined)}\n spellcheck=\"false\"\n ?readonly=${this.disabled}\n aria-describedby=${hint === null ? 'counter' : 'counter hint'}\n .value=${live(this.value)}\n @input=${(event: Event) => this.#write((event.target as HTMLTextAreaElement).value)}\n @keydown=${(event: KeyboardEvent) => {\n // One row is a single-line answer.\n if (rows === 1 && event.key === 'Enter') event.preventDefault();\n }}\n @blur=${() => clearTimeout(this.#pause)}\n ></textarea>\n </label>\n <div class=\"notes\" lang=${ui.lang} dir=${ui.dir}>\n ${hint === null ? nothing : html`<p id=\"hint\" part=\"hint\">${hint}</p>`}\n <p class=\"counter\" id=\"counter\" part=\"counter\">${counter}</p>\n </div>\n </div>`;\n }\n\n #write(value: string): void {\n this.updateValue(value);\n clearTimeout(this.#pause);\n this.#pause = setTimeout(() => {\n // Handed in meanwhile (a deadline): the player's result is what to hear.\n if (this.disabled) return;\n const { counter, hint } = this.#notes();\n this.announce(hint === null ? counter : `${counter} ${hint}`);\n }, PAUSE_MS);\n }\n}\n\nexport const longAnswerElement: ElementRegistration = {\n manifest: longAnswerManifest,\n element: LongAnswerElement,\n messages: longAnswerUiMessages,\n};\n"],"mappings":"A,mOAIA,IAAMe,EAAY,mBAMLC,EAAkD,CAC7D,CAAE,YAAW,OAAQ,KAAM,SAAUhB,CAAG,EACxC,CAAE,YAAW,OAAQ,KAAM,SAAUC,CAAG,CAC1C,ECHMgB,EAAa,IAGbC,EAAW,IAOJC,EAAb,cAAuCC,CAAkB,CACvD,OAAgB,SAA8BR,EAC9C,OAAgB,SAAsCI,EACtD,OAAgB,kBAAoC,CAClD,GAAGd,EAAW,kBACd,eAAgB,EAClB,EAEA,OAAgB,OAAyB,CACvC,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BH,CAAG;;;;;;;;;;;;;;;;;;;;EAqBHY,CACF,EAEA,GAEA,sBAAsC,CACpC,MAAM,qBAAqB,EAC3B,aAAa,KAAKO,EAAM,CAC1B,CAGA,IAAqE,CACnE,IAAMC,EAAM,KAAK,gBAAgB,WAAW,GAAKL,EAC3CM,EAAQ,KAAK,MAAM,OACnBC,GAAQ,KAAK,gBAAgB,WAAW,GAAK,GAAKD,EACxD,MAAO,CACL,QAASA,GAASD,EAAM,KAAK,EAAE,UAAW,CAAE,KAAI,CAAC,EAAI,KAAK,EAAE,WAAY,CAAE,QAAO,KAAI,CAAC,EACtF,KAAME,EAAO,GAAK,CAAC,KAAK,SAAW,KAAK,EAAE,UAAW,CAAE,MAAOA,CAAK,CAAC,EAAI,IAC1E,CACF,CAEA,QAA4C,CAC1C,IAAMC,EAAO,KAAK,gBAAgB,MAAM,GAAK,EACvC,CAAE,UAAS,QAAS,KAAKC,GAAO,EAChCC,EAAK,KAAK,WAEhB,MAAO,EAAI;;;;;iBAKEF,EAAK;sBACA,KAAK,gBAAgB,WAAW,GAAKR,EAAW;wBAC9Cd,EAAU,KAAK,gBAAgB,aAAa,GAAK,IAAA,EAAS,EAAE;iBACnEA,EAAU,KAAK,aAAe,IAAA,EAAS,EAAE;;sBAEpC,KAAK,SAAS;6BACPyB,IAAS,KAAO,UAAY,eAAe;mBACrDxB,EAAK,KAAK,KAAK,EAAE;mBAChB,GAAiB,KAAKyB,GAAQC,EAAM,OAA+B,KAAK,EAAE;qBACxE,GAAyB,CAE/BL,IAAS,GAAKK,EAAM,MAAQ,SAASA,EAAM,eAAe,CAChE,EAAE;sBACY,aAAa,KAAKT,EAAM,EAAE;;;gCAGlBM,EAAG,KAAK,OAAOA,EAAG,IAAI;UAC5CC,IAAS,KAAOvB,EAAU,CAAI,4BAA4BuB,EAAK,MAAM;yDACtBG,EAAQ;;WAG/D,CAEA,GAAO,EAAqB,CAC1B,KAAK,YAAYC,CAAK,EACtB,aAAa,KAAKX,EAAM,EACxB,KAAKA,GAAS,eAAiB,CAE7B,GAAI,KAAK,SAAU,OACnB,GAAM,CAAE,UAAS,QAAS,KAAKK,GAAO,EACtC,KAAK,SAASE,IAAS,KAAOG,EAAU,GAAGA,EAAQ,GAAGH,GAAM,CAC9D,EAAGV,CAAQ,CACb,CACF,EAEae,EAAyC,CACpD,SAAUrB,EACV,QAASO,EACT,SAAUH,CACZ,E"}
@@ -0,0 +1,2 @@
1
+ var e={tag:`astl-long-answer`,version:1,display:`block`,graded:!1,attributes:[{name:`rows`,type:`integer`,min:1,max:20,default:5,visibility:`public`},{name:`minlength`,type:`integer`,min:0,max:2e3,visibility:`public`},{name:`maxlength`,type:`integer`,min:1,max:2e3,visibility:`public`},{name:`placeholder`,type:`string`,visibility:`public`}],children:[{tag:`astl-prompt`,visibility:`public`,content:`inline`,min:0,max:1,attributes:[]}],scoring:null,variants:null,slotKinds:[`open`],issues:[`LONG_ANSWER_PROMPT_MISSING`,`LONG_ANSWER_LIMITS`],messages:`astl.long-answer`,a11y:{pattern:`multi-line textbox labelled by the prompt and described by its character counter`,keys:[`Tab`]},cssParts:[`long-answer`,`prompt`,`input`,`counter`,`hint`]},t={"ui.count":`{count} of {max, plural, one {# character} other {# characters}}`,"ui.full":`The limit of {max, plural, one {# character} other {# characters}} is reached.`,"ui.more":`{count, plural, one {Write at least # more character.} other {Write at least # more characters.}}`},n={"ui.count":`{count} z {max, plural, one {# znaku} few {# znaków} many {# znaków} other {# znaku}}`,"ui.full":`Osiągnięto limit {max, plural, one {# znaku} few {# znaków} many {# znaków} other {# znaku}}.`,"ui.more":`{count, plural, one {Napisz jeszcze co najmniej # znak.} few {Napisz jeszcze co najmniej # znaki.} many {Napisz jeszcze co najmniej # znaków.} other {Napisz jeszcze co najmniej # znaku.}}`};export{t as n,e as r,n as t};
2
+ //# sourceMappingURL=long-answer-manifest-BYJpZRtB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"long-answer-manifest-BYJpZRtB.js","names":["longAnswerManifest","en_default","pl_default"],"sources":["../../../../components/src/long-answer/manifest.ts","../../../../components/src/long-answer/messages/ui/en.json","../../../../components/src/long-answer/messages/ui/pl.json"],"sourcesContent":["import type { ComponentManifest } from '@astl/core';\n\n/**\n * A question the student answers in their own words, for the teacher: one `open` slot, stored with the attempt and\n * never graded (at most 2000 characters). The box is a native text area labelled by the prompt, with a character\n * counter.\n */\nexport const longAnswerManifest: ComponentManifest = {\n tag: 'astl-long-answer',\n version: 1,\n display: 'block',\n graded: false,\n attributes: [\n /** Height of the box in lines; one line makes a single-line answer. */\n { name: 'rows', type: 'integer', min: 1, max: 20, default: 5, visibility: 'public' },\n /** Fewest characters asked for: the student sees how many more to write. Nothing blocks a shorter answer. */\n { name: 'minlength', type: 'integer', min: 0, max: 2000, visibility: 'public' },\n /** Most characters the box takes (2000 without it). */\n { name: 'maxlength', type: 'integer', min: 1, max: 2000, visibility: 'public' },\n /** A hint shown in the empty box, such as how to start. */\n { name: 'placeholder', type: 'string', visibility: 'public' },\n ],\n children: [\n /** The question: the label of the box. Required (LONG_ANSWER_PROMPT_MISSING); the spec is the shared prompt's. */\n { tag: 'astl-prompt', visibility: 'public', content: 'inline', min: 0, max: 1, attributes: [] },\n ],\n scoring: null,\n variants: null,\n slotKinds: ['open'],\n issues: ['LONG_ANSWER_PROMPT_MISSING', 'LONG_ANSWER_LIMITS'],\n messages: 'astl.long-answer',\n a11y: {\n pattern: 'multi-line textbox labelled by the prompt and described by its character counter',\n keys: ['Tab'],\n },\n cssParts: ['long-answer', 'prompt', 'input', 'counter', 'hint'],\n};\n","{\n \"ui.count\": \"{count} of {max, plural, one {# character} other {# characters}}\",\n \"ui.full\": \"The limit of {max, plural, one {# character} other {# characters}} is reached.\",\n \"ui.more\": \"{count, plural, one {Write at least # more character.} other {Write at least # more characters.}}\"\n}\n","{\n \"ui.count\": \"{count} z {max, plural, one {# znaku} few {# znaków} many {# znaków} other {# znaku}}\",\n \"ui.full\": \"Osiągnięto limit {max, plural, one {# znaku} few {# znaków} many {# znaków} other {# znaku}}.\",\n \"ui.more\": \"{count, plural, one {Napisz jeszcze co najmniej # znak.} few {Napisz jeszcze co najmniej # znaki.} many {Napisz jeszcze co najmniej # znaków.} other {Napisz jeszcze co najmniej # znaku.}}\"\n}\n"],"mappings":"AAOA,IAAaA,EAAwC,CACnD,IAAK,mBACL,QAAS,EACT,QAAS,QACT,OAAQ,GACR,WAAY,CAEV,CAAE,KAAM,OAAQ,KAAM,UAAW,IAAK,EAAG,IAAK,GAAI,QAAS,EAAG,WAAY,QAAS,EAEnF,CAAE,KAAM,YAAa,KAAM,UAAW,IAAK,EAAG,IAAK,IAAM,WAAY,QAAS,EAE9E,CAAE,KAAM,YAAa,KAAM,UAAW,IAAK,EAAG,IAAK,IAAM,WAAY,QAAS,EAE9E,CAAE,KAAM,cAAe,KAAM,SAAU,WAAY,QAAS,CAC9D,EACA,SAAU,CAER,CAAE,IAAK,cAAe,WAAY,SAAU,QAAS,SAAU,IAAK,EAAG,IAAK,EAAG,WAAY,CAAC,CAAE,CAChG,EACA,QAAS,KACT,SAAU,KACV,UAAW,CAAC,MAAM,EAClB,OAAQ,CAAC,6BAA8B,oBAAoB,EAC3D,SAAU,mBACV,KAAM,CACJ,QAAS,mFACT,KAAM,CAAC,KAAK,CACd,EACA,SAAU,CAAC,cAAe,SAAU,QAAS,UAAW,MAAM,CAChE,E"}