@astl/astrolabe 0.1.1 → 0.1.2

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 (27) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cdn/astrolabe-editor.js +55 -19
  3. package/dist/cdn/astrolabe-editor.js.map +1 -1
  4. package/dist/cdn/astrolabe.standalone.js +74 -20
  5. package/dist/cdn/chunks/{help-form-DaC6KaFG.js → help-form-CDg3TCwI.js} +2 -2
  6. package/dist/cdn/chunks/{help-form-DaC6KaFG.js.map → help-form-CDg3TCwI.js.map} +1 -1
  7. package/dist/cdn/chunks/{insert-menu-LgrifBYT.js → insert-menu-7vANVmTK.js} +2 -2
  8. package/dist/cdn/chunks/{insert-menu-LgrifBYT.js.map → insert-menu-7vANVmTK.js.map} +1 -1
  9. package/dist/cdn/chunks/{issue-list-BgnXzXRM.js → issue-list-BT9qvnZU.js} +2 -2
  10. package/dist/cdn/chunks/{issue-list-BgnXzXRM.js.map → issue-list-BT9qvnZU.js.map} +1 -1
  11. package/dist/cdn/chunks/messages-D1aJfyS_.js +2 -0
  12. package/dist/cdn/chunks/messages-D1aJfyS_.js.map +1 -0
  13. package/dist/cdn/chunks/{source-view-DXKPFCl9.js → source-view-CZVxgTNQ.js} +2 -2
  14. package/dist/cdn/chunks/{source-view-DXKPFCl9.js.map → source-view-CZVxgTNQ.js.map} +1 -1
  15. package/dist/cdn/chunks/{style-form-D5haJtWM.js → style-form-DUGbG_kL.js} +2 -2
  16. package/dist/cdn/chunks/{style-form-D5haJtWM.js.map → style-form-DUGbG_kL.js.map} +1 -1
  17. package/dist/cdn/chunks/{style-messages-BbZpeD2a.js → style-messages-qdf3pZbT.js} +2 -2
  18. package/dist/cdn/chunks/{style-messages-BbZpeD2a.js.map → style-messages-qdf3pZbT.js.map} +1 -1
  19. package/dist/cdn/chunks/{style-rules-D45PZLCv.js → style-rules-D17QGzXk.js} +2 -2
  20. package/dist/cdn/chunks/{style-rules-D45PZLCv.js.map → style-rules-D17QGzXk.js.map} +1 -1
  21. package/dist/cdn/chunks/{styles-DxJJxVNH.js → styles-CdJT6Pp9.js} +2 -2
  22. package/dist/cdn/chunks/{styles-DxJJxVNH.js.map → styles-CdJT6Pp9.js.map} +1 -1
  23. package/dist/cdn/chunks/{surface-CgxfAwCR.js → surface-C6wtQkTY.js} +21 -3
  24. package/dist/cdn/chunks/{surface-CgxfAwCR.js.map → surface-C6wtQkTY.js.map} +1 -1
  25. package/package.json +9 -9
  26. package/dist/cdn/chunks/messages-9xiYDvRT.js +0 -2
  27. package/dist/cdn/chunks/messages-9xiYDvRT.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"astrolabe-editor.js","names":["inheritTokens","nothing","live","ifDefined","nothing","nothing","live","LitElement","nothing","registered","inheritTokens","nothing","inheritTokens","nothing","t","e","r","s","unsafeCSS","LitElement","nothing","keyed","defineEditor","audioMessages","dropMessages","trueFalseMessages","categoriseMessages","memoryMessages","longAnswerMessages","imageLabelMessages","flashCardsMessages","gapMessages","videoMessages","matchMessages","hotspotMessages","wordSearchMessages","selectMessages","imageDropMessages","wordBankMessages","orderMessages","builtInDefinitions","markWordsMessages","crosswordMessages","createEngine","calloutMessages","choiceMessages","allAttributes","PAGE_ATTRIBUTES","builtInStyleTemplates","OPAQUE_ID_PATTERN","MAX_REQUEST_BYTES","COLUMNS_TAG","b","HINT_TAG","r","FORMAT_VERSION","i$1","ELEMENT_TAG_PATTERN","DEFAULT_PROFILE","isOpaqueId","isProblemDetails","DOC_KINDS","PROTOCOL_VERSION","CONTENT_ATTRIBUTES","SCORING_RULES","isSourceId","helpPolicy","INLINE_TAGS","PRACTICE_POLICY","FIGURE_TAG","groupMax","BLOCK_TAGS","tokens","SOURCE_ID_PATTERN","SNAPSHOT_FORMAT","SUPPORTED_FORMATS","builtInElements","LANGUAGE_TAG_PATTERN","isSnapshot","directionOf","SCORING_ATTRIBUTES","MIN_COLUMNS","roundScore","CAPTION_TAG","maxAnswerLength","HELP_TAGS","w","DOC_TAG","ProblemCode","DEFAULT_DOC_KIND","PROBLEM_MEDIA_TYPE","COLUMN_TAG","ProtocolPath","DOC_ATTRIBUTES","PlayerEvent","MAX_COLUMNS","isAttemptPolicy","MAX_ATTRIBUTES_PER_ELEMENT","COMMON_ATTRIBUTES","MAX_NESTING_DEPTH","MAX_ANSWER_LENGTH","pluralCategories","definePlayer","isSafeUrl","A","fitsAnswer","FEEDBACK_VARIANTS","isAnswerKey","hasErrors","element","REMOVED_WITH_CONTENT","childTagConflict","isElement","compareCatalogs","MAX_ANSWER_COUNT","parseMessage","FLAG_SELECTED","messageParams","inertStyles","STYLE_TEMPLATE_NAME","PALETTE","PAGE_TAG","tokensCss","MAX_SOURCE_LENGTH","CheckerError","createI18n","textContent","icuFormatter","TAG_ATTRIBUTES","variantAttribute","strictUrlPolicy","ENGINE_NAMESPACE","text","MessageSyntaxError","TEST_POLICY","INERT_STYLE","URL_ATTRIBUTES","STYLE_TEMPLATE_ATTRIBUTE","KEY_FORMAT_VERSION","EngineIssue","STYLE_TAG","sameChildSpec","childElements","negotiateLocale","o","MAX_OPEN_ANSWER_LENGTH","EXPLANATION_TAG","BUILT_IN_PREFIX","isAnswers","HELP_ATTRIBUTES","i$2","OPEN_SLOT_KIND","FEEDBACK_TAG","JSON_MEDIA_TYPE","CLASS_ATTRIBUTE","audioManifest","calloutManifest","categoriseManifest","choiceManifest","crosswordManifest","dropManifest","flashCardsManifest","gapManifest","hotspotManifest","imageDropManifest","imageLabelManifest","longAnswerManifest","markWordsManifest","matchManifest","memoryManifest","orderManifest","selectManifest","trueFalseManifest","videoManifest","wordBankManifest","wordSearchManifest","usedIds","attributeValue","elementTree","scanElements","tokenize","loadHelpForm","UploadRefused","pictureSize","refusalOf","STYLE_OPEN","createAuthoring","GLYPHS","loadStyleElements","TYPE_GLYPHS","styleElementsIn","AstlInsertMenu","editorMessages","EDITOR_NAMESPACE","DEFAULT_STYLES","styleMapOf","DEFAULT_FONTS","kitStyles","AuthoringElement","inheritTokens$1","i$3","p","e","l","sortIssues","issueStyles","renderIssues","SEVERITY_ICONS","RovingFocus","audioEditor","calloutEditor","categoriseEditor","choiceEditor","grid","head","crosswordEditor","dropEditor","PICTURES","card","front","back","picture","name","flashCardsEditor","gapEditor","hotspotEditor","imageDropEditor","imageLabelEditor","longAnswerEditor","word","id","correct","key","line","row","odd","markWordsEditor","task","attrs","n","i","set","c","starter","matchEditor","game","memoryEditor","orderEditor","selectEditor","trueFalseEditor","videoEditor","wordBankEditor","DIRECTIONS","OPEN","WORDS","builtInEditors","ACTION_ICONS","fitsBeside","field","inputValue","event","checkedOf","AstlInspector","#model","authoring","adapter","#document","source","next","change","#shown","current","focus","#focus","item","#fieldClass","#describedBy","value","#apply","#help","#uploadControl","said","#upload","status","words","accept","input","file","#uploadFile","upload","tag","#abort","abort","say","asset","src","error","option","values","add","remove","k","j","full","described","write","v","child","choose","attribute","required","rows","index","control","commit","column","first","options","columns","#textList","#childFlags","#childTexts","#childChoices","#childTable","#text","#number","#checkbox","#select","place","page","button","off","run","move","direction","model","issues","issue","display","glyph","#actions","targets","kinds","target","#styleKinds","#styleOpen","#showStyle","kind","open","#askStyle","selection","document","body","note","#field","f","manifest","#head","#issues","lang","dir","#styleSection","AstlIssues","#timer","#check","changed","#source","summary","errors","AstlPictureDialog","#finish","request","#editing","#withCaption","#altRequired","#target","#src","#alt","#decorative","#caption","#width","#height","#preview","#message","#uploadMessage","#stop","result","#resolve","resolve","#dialog","#previewTimer","dialog","fields","#generation","#busy","#picking","policy","#allowed","message","#take","#pick","pick","picked","shown","alt","caption","library","#submit","#live","FIELD_CHANGE","round","num","MAX_LISTED","slot","reshaped","box","boundsOf","region","cx","cy","h","cleared","shape","points","x","y","anchorOf","AstlPictureField","#status","params","context","taken","prefix","#freshId","label","#t","#change","at","width","height","#write","canvas","#at","#draft","draft","#add","unflagged","cls","#aspect","pin","badge","shapes","#shape","badges","#badge","#down","#move","#up","img","count","raw","optional","setPoints","numbers","#more","lx","ly","#labelField","point","regions","#canvas","#region","#point","registered$1","AstlPreview","root","type","#state","generation","#stale","#set","player","state","theme","ICONS","STYLES","MENU_GROUPS","INSERT_MENUS","MARKS","LISTS","STYLE_POPUPS","isMenu","popup","popoverOf","openerOf","VIEW_PICKED","NO_STATE","barStyles","buttonStyles","popupStyles","AstlToolbar","#items","#open","menu","detail","#close","#panel","#loadStylePopups","#stylePopupsModule","module","sheet","#follow","#outside","#escape","#styles","#off","listen","#popup","path","opener","node","panel","inside","#linkError","#colorError","#query","#menu","#place","rect","rtl","room","start","inset","below","format","href","#done","changes","styles","where","#namedTarget","ready","#isBox","rule","#namedNow","stack","font","hasBlock","popupItem","enabled","#fontName","size","valued","textEnabled","blockStyle","align","alignIcon","#insert","template","disabled","items","descriptor","t","icon","groups","formatItem","#format","style","named","one","styleName","#styleGroups","mark","list","starters","d","#featuredItems","wraps","view","history","#roving","unavailable","part","buttons","step","own","preset","group","none","#setNamed","#setText","#setBlock","#menuKeydown","s","#styleMenuMore","apply","away","#groups","#keydown","#button","#styleMenu","#linkPopup","#insertPopup","#stylePopup","choice","ELEMENTS","defineAuthoringElements","registry","existing","TEXT_BLOCKS","contentEnd","range","documentOf","roots","doc","children","content","blocks","freshPage","used","blank","fragment","inlinePath","block","el","caret","splitPageSource","from","to","close","language","a","before","empty","left","addPageSource","after","mergePageSource","pages","end","SELECTION_EVENTS","same","isComponent","insertionRange","elements","hit","last","tags","offset","cut","reveal","textarea","createTextareaAdapter","selections","cache","component","emitSelection","now","listener","emitChange","setSource","old","shorter","edit","html","delta","map","selectionStart","selectionEnd","selectionDirection","inheritTokens","lines","selector","editorStyles","elementTag","secret","previewSecret","engineOf","lists","EMPTY","registered","connected","added","out","into","what","register","maps","profile","engine","editor","authoringFor","keep","allowed","THEMES","CHANGE","READY","VIEW","OWN_VIEWS","COUNT_DELAY_MS","PANELS","listAttribute","viewsAttribute","KIT_ICONS","INSPECTOR_PARTS","surfaces","sourceViews","AstlEditor","#resolveReady","#notice","#pageNotice","has","#slotted","#pending","#ready","locale","#uiLocale","given","#authoring","#builtIn","#subscribe","#counting","#readyFor","surface","#surface","views","#hostViews","#errors","#notices","#outline","delay","#theme","#leaveSource","#decide","#pictures","#pages","#count","#opening","#failed","#subscription","notice","requested","available","waiting","featured","panels","icons","exported","#view","#statusLine","#slotChange","outline","TAG","defineEditor$1","DEFAULT_FEATURED","loadMenuMessages","defineEditor","components","definition","checkCatalog","isStyleTemplate"],"sources":["../../../components/src/audio/editor.ts","../../../components/src/callout/editor.ts","../../../components/src/categorise/editor.ts","../../../components/src/choice/editor.ts","../../../components/src/crossword/editor.ts","../../../components/src/drop/editor.ts","../../../components/src/flash-cards/editor.ts","../../../components/src/gap/editor.ts","../../../components/src/hotspot/editor.ts","../../../components/src/image-drop/editor.ts","../../../components/src/image-label/editor.ts","../../../components/src/long-answer/editor.ts","../../../components/src/mark-words/editor.ts","../../../components/src/match/editor.ts","../../../components/src/memory/editor.ts","../../../components/src/order/editor.ts","../../../components/src/select/editor.ts","../../../components/src/true-false/editor.ts","../../../components/src/video/editor.ts","../../../components/src/word-bank/editor.ts","../../../components/src/word-search/editor.ts","../../../components/src/editors.ts","../../../editor/src/elements/inspector.ts","../../../editor/src/elements/issues.ts","../../../editor/src/elements/picture-dialog.ts","../../../editor/src/elements/picture-field.ts","../../../editor/src/elements/preview.ts","../../../editor/src/elements/toolbar.ts","../../../editor/src/define.ts","../../../editor/src/pages.ts","../../../editor/src/textarea.ts","../../../../node_modules/.pnpm/lit-html@3.3.3/node_modules/lit-html/directives/keyed.js","../../../editor-tiptap/src/element.ts","../../../editor-tiptap/src/define.ts","../../src/editor.ts","../../src/bundles/astrolabe-editor.ts"],"sourcesContent":["import type { EditorDescriptor } from '@astl/core';\nimport { audioManifest } from './manifest.js';\nimport { audioMessages } from './messages.js';\n\n/** The default template has a title and a transcript to replace; the author gives the file (until then, an error). */\nexport const audioEditor: EditorDescriptor = {\n manifest: audioManifest,\n messages: audioMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'speaker-high',\n idPrefix: 'audio',\n template:\n '<astl-audio id=\"{{id}}\" label=\"{{t:template.label}}\">' +\n '<astl-transcript>{{t:template.transcript}}</astl-transcript></astl-audio>',\n fields: [\n { kind: 'attribute', name: 'label', label: 'editor.title', help: 'editor.titleHelp' },\n { kind: 'attribute', name: 'src', label: 'editor.src', help: 'editor.srcHelp', accept: 'audio/*' },\n {\n kind: 'text-list',\n tag: 'astl-transcript',\n label: 'editor.transcript',\n help: 'editor.transcriptHelp',\n multiline: true,\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { calloutManifest } from './manifest.js';\nimport { calloutMessages } from './messages.js';\n\nexport const calloutEditor: EditorDescriptor = {\n manifest: calloutManifest,\n messages: calloutMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'info',\n idPrefix: 'callout',\n template: '<astl-callout id=\"{{id}}\" kind=\"tip\"><p>{{t:template.text}}</p></astl-callout>',\n fields: [{ kind: 'attribute', name: 'kind', label: 'editor.kind' }],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { categoriseManifest } from './manifest.js';\nimport { categoriseMessages } from './messages.js';\n\nexport const categoriseEditor: EditorDescriptor = {\n manifest: categoriseManifest,\n messages: categoriseMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'kanban',\n idPrefix: 'cat',\n template:\n '<astl-categorise id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-category id=\"a\">{{t:template.categoryA}}</astl-category>' +\n '<astl-category id=\"b\">{{t:template.categoryB}}</astl-category>' +\n '<astl-card id=\"a1\" category=\"a\">{{t:template.cardA1}}</astl-card>' +\n '<astl-card id=\"a2\" category=\"a\">{{t:template.cardA2}}</astl-card>' +\n '<astl-card id=\"b1\" category=\"b\">{{t:template.cardB1}}</astl-card>' +\n '<astl-card id=\"b2\" category=\"b\">{{t:template.cardB2}}</astl-card></astl-categorise>',\n templates: [\n {\n id: 'sort-into-groups',\n label: 'template.sort.label',\n description: 'template.sort.description',\n template:\n '<h3>{{t:template.sort.heading}}</h3><p>{{t:template.sort.instruction}}</p>' +\n '<astl-categorise id=\"{{id}}\"><astl-prompt>{{t:template.sort.prompt}}</astl-prompt>' +\n '<astl-category id=\"a\">{{t:template.sort.groupA}}</astl-category>' +\n '<astl-category id=\"b\">{{t:template.sort.groupB}}</astl-category>' +\n '<astl-card id=\"a1\" category=\"a\">{{t:template.sort.card1}}</astl-card>' +\n '<astl-card id=\"b1\" category=\"b\">{{t:template.sort.card2}}</astl-card>' +\n '<astl-card id=\"a2\" category=\"a\">{{t:template.sort.card3}}</astl-card>' +\n '<astl-card id=\"b2\" category=\"b\">{{t:template.sort.card4}}</astl-card></astl-categorise>',\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-card',\n attribute: 'category',\n options: 'astl-category',\n label: 'editor.cardCategories',\n help: 'editor.cardCategoriesHelp',\n },\n // The groups as rows, with the palette slot (1 to 8) of each.\n {\n kind: 'child-table',\n tag: 'astl-category',\n columns: [{ attribute: 'palette', label: 'editor.palette' }],\n label: 'editor.groups',\n help: 'editor.groupsHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { choiceManifest } from './manifest.js';\nimport { choiceMessages } from './messages.js';\n\nexport const choiceEditor: EditorDescriptor = {\n manifest: choiceManifest,\n messages: choiceMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'list-checks',\n idPrefix: 'choice',\n template:\n '<astl-choice id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-option id=\"a\" correct>{{t:template.option1}}</astl-option>' +\n '<astl-option id=\"b\">{{t:template.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.option3}}</astl-option></astl-choice>',\n templates: [\n {\n id: 'multiple-choice',\n label: 'template.choice.label',\n description: 'template.choice.description',\n template:\n '<h3>{{t:template.choice.heading}}</h3><p>{{t:template.choice.instruction}}</p>' +\n '<astl-choice id=\"{{id}}\"><astl-prompt>{{t:template.choice.prompt}}</astl-prompt>' +\n '<astl-option id=\"a\">{{t:template.choice.option1}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.choice.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.choice.option3}}</astl-option></astl-choice>',\n },\n ],\n fields: [\n { kind: 'child-flag', tag: 'astl-option', attribute: 'correct', label: 'editor.correctOptions' },\n { kind: 'attribute', name: 'multiple', label: 'editor.multiple' },\n { kind: 'attribute', name: 'shuffle', label: 'editor.shuffle' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { crosswordManifest } from './manifest.js';\nimport { crosswordMessages } from './messages.js';\n\n/** A 5 by 5 grid of two words crossing at their first letter, after `head` (a prompt, or nothing). */\nconst grid = (head: string): string =>\n `<astl-crossword id=\"{{id}}\" rows=\"5\" columns=\"5\">${head}` +\n '<astl-crossword-word id=\"w1\" answer=\"{{t:template.crossword.across}}\" row=\"0\" column=\"0\" direction=\"across\">' +\n '{{t:template.crossword.acrossClue}}</astl-crossword-word>' +\n '<astl-crossword-word id=\"w2\" answer=\"{{t:template.crossword.down}}\" row=\"0\" column=\"0\" direction=\"down\">' +\n '{{t:template.crossword.downClue}}</astl-crossword-word></astl-crossword>';\n\nexport const crosswordEditor: EditorDescriptor = {\n manifest: crosswordManifest,\n messages: crosswordMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'grid-four',\n idPrefix: 'crossword',\n template: grid('<astl-prompt>{{t:template.crossword.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'crossword',\n label: 'template.crossword',\n description: 'template.crossword.description',\n template: `<h3>{{t:template.crossword.heading}}</h3><p>{{t:template.crossword.prompt}}</p>${grid('')}`,\n },\n ],\n fields: [\n { kind: 'attribute', name: 'rows', label: 'editor.rows' },\n { kind: 'attribute', name: 'columns', label: 'editor.columns' },\n {\n kind: 'child-table',\n tag: 'astl-crossword-word',\n label: 'editor.words',\n help: 'editor.wordsHelp',\n columns: [\n { attribute: 'answer', label: 'editor.answer' },\n { attribute: 'row', label: 'editor.row' },\n { attribute: 'column', label: 'editor.column' },\n { attribute: 'direction', label: 'editor.direction' },\n ],\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { dropManifest } from './manifest.js';\nimport { dropMessages } from './messages.js';\n\nexport const dropEditor: EditorDescriptor = {\n manifest: dropManifest,\n messages: dropMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'arrow-square-in',\n idPrefix: 'drop',\n // The first word of a new bank (its template's ids); the inspector then picks the right one.\n template: '<astl-drop id=\"{{id}}\" answer=\"a\" bank=\"\"></astl-drop>',\n companion: { tag: 'astl-word-bank', attribute: 'bank' },\n fields: [\n {\n kind: 'attribute',\n name: 'answer',\n label: 'editor.answer',\n help: 'editor.answerHelp',\n options: { from: 'bank', tag: 'astl-word' },\n },\n { kind: 'attribute', name: 'bank', label: 'editor.bank', help: 'editor.bankHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { flashCardsManifest } from './manifest.js';\nimport { flashCardsMessages } from './messages.js';\n\n/** Sample pictures of the starter, on the address range kept for documentation: authors replace them with their own. */\nconst PICTURES = 'https://assets.example.org/flash-cards/';\n\nconst card = (front: string, back: string): string =>\n `<astl-front>${front}</astl-front><astl-back>{{t:template.cards.${back}}}</astl-back>`;\nconst picture = (name: string): string =>\n `<img src=\"${PICTURES}${name}.svg\" alt=\"{{t:template.cards.${name}}}\" width=\"96\" height=\"96\">`;\n\nexport const flashCardsEditor: EditorDescriptor = {\n manifest: flashCardsManifest,\n messages: flashCardsMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'cards',\n template:\n '<astl-flash-cards id=\"{{id}}\"><astl-front>{{t:template.front}}</astl-front>' +\n '<astl-back>{{t:template.back}}</astl-back></astl-flash-cards>',\n templates: [\n {\n id: 'flash-cards',\n label: 'editor.template.cards',\n description: 'editor.template.cards.description',\n template:\n '<h3>{{t:template.cards.title}}</h3><p>{{t:template.cards.instruction}}</p><astl-flash-cards id=\"{{id}}\">' +\n card(picture('sun'), 'sunBack') +\n card(picture('moon'), 'moonBack') +\n card('{{t:template.cards.mars}}', 'marsBack') +\n card('{{t:template.cards.saturn}}', 'saturnBack') +\n '</astl-flash-cards>',\n },\n ],\n fields: [{ kind: 'text-list', tag: 'astl-back', label: 'editor.backs', help: 'editor.backsHelp' }],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { gapManifest } from './manifest.js';\nimport { gapMessages } from './messages.js';\n\nexport const gapEditor: EditorDescriptor = {\n manifest: gapManifest,\n messages: gapMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'text-t',\n idPrefix: 'gap',\n template: '<astl-gap id=\"{{id}}\" answer=\"{{selection}}\"></astl-gap>',\n templates: [\n {\n id: 'fill-the-gaps',\n label: 'template.fill.label',\n description: 'template.fill.description',\n template:\n '<h3>{{t:template.fill.heading}}</h3><p>{{t:template.fill.instruction}}</p>' +\n '<p>{{t:template.fill.start}} <astl-gap id=\"{{id}}\" answer=\"{{t:template.fill.answer1}}\"></astl-gap> ' +\n '{{t:template.fill.middle}} <astl-gap answer=\"{{t:template.fill.answer2}}\"></astl-gap>' +\n '{{t:template.fill.end}}</p>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'answer', label: 'editor.answer' },\n { kind: 'text-list', tag: 'astl-alt', label: 'editor.alternatives', help: 'editor.alternativesHelp' },\n { kind: 'attribute', name: 'type', label: 'editor.type' },\n { kind: 'attribute', name: 'case', label: 'editor.case' },\n { kind: 'attribute', name: 'marks', label: 'editor.marks', help: 'editor.marksHelp' },\n { kind: 'attribute', name: 'tolerance', label: 'editor.tolerance' },\n { kind: 'attribute', name: 'width', label: 'editor.width' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { hotspotManifest } from './manifest.js';\nimport { hotspotMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const hotspotEditor: EditorDescriptor = {\n manifest: hotspotManifest,\n messages: hotspotMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'crosshair',\n idPrefix: 'hotspot',\n template:\n '<astl-hotspot id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-hotspot-region id=\"r1\" x=\"5\" y=\"10\" width=\"40\" height=\"80\" label=\"{{t:template.place1}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r2\" x=\"55\" y=\"10\" width=\"40\" height=\"80\" label=\"{{t:template.place2}}\"></astl-hotspot-region>' +\n '</astl-hotspot>',\n templates: [\n {\n id: 'find-it-in-the-picture',\n label: 'template.find.label',\n description: 'template.find.description',\n template:\n '<h3>{{t:template.find.heading}}</h3><p>{{t:template.find.instruction}}</p>' +\n '<astl-hotspot id=\"{{id}}\" multiple><astl-prompt>{{t:template.find.prompt}}</astl-prompt>' +\n '<astl-hotspot-region id=\"r1\" x=\"4\" y=\"6\" width=\"22\" height=\"26\" label=\"{{t:template.find.topLeft}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r2\" shape=\"circle\" x=\"85\" y=\"18\" r=\"10\" label=\"{{t:template.find.topRight}}\"></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r3\" shape=\"circle\" x=\"50\" y=\"50\" r=\"12\" label=\"{{t:template.find.centre}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r4\" shape=\"circle\" x=\"15\" y=\"82\" r=\"10\" label=\"{{t:template.find.bottomLeft}}\"></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r5\" x=\"74\" y=\"68\" width=\"22\" height=\"26\" label=\"{{t:template.find.bottomRight}}\" correct></astl-hotspot-region>' +\n '</astl-hotspot>',\n },\n ],\n fields: [\n {\n kind: 'picture-regions',\n tag: 'astl-hotspot-region',\n src: 'src',\n label: 'editor.regions',\n help: 'editor.regionsHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-flag',\n tag: 'astl-hotspot-region',\n attribute: 'correct',\n label: 'editor.correct',\n help: 'editor.correctHelp',\n },\n { kind: 'attribute', name: 'multiple', label: 'editor.multiple' },\n { kind: 'attribute', name: 'outline', label: 'editor.outline' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { imageDropManifest } from './manifest.js';\nimport { imageDropMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const imageDropEditor: EditorDescriptor = {\n manifest: imageDropManifest,\n messages: imageDropMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'tag',\n idPrefix: 'image-drop',\n template:\n '<astl-image-drop id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-image-drop-zone id=\"z1\" x=\"10\" y=\"35\" width=\"30\" height=\"30\" answer=\"l1\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z2\" x=\"60\" y=\"35\" width=\"30\" height=\"30\" answer=\"l2\"></astl-image-drop-zone>' +\n '<astl-image-drop-label id=\"l1\">{{t:template.label1}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l2\">{{t:template.label2}}</astl-image-drop-label></astl-image-drop>',\n templates: [\n {\n id: 'drag-labels-onto-the-picture',\n label: 'template.drag.label',\n description: 'template.drag.description',\n template:\n '<h3>{{t:template.drag.heading}}</h3><p>{{t:template.drag.instruction}}</p>' +\n '<astl-image-drop id=\"{{id}}\"><astl-prompt>{{t:template.drag.prompt}}</astl-prompt>' +\n '<astl-image-drop-zone id=\"z1\" x=\"20\" y=\"5\" width=\"60\" height=\"25\" answer=\"l1\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z2\" x=\"20\" y=\"37.5\" width=\"60\" height=\"25\" answer=\"l2\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z3\" x=\"20\" y=\"70\" width=\"60\" height=\"25\" answer=\"l3\"></astl-image-drop-zone>' +\n '<astl-image-drop-label id=\"l1\">{{t:template.drag.label1}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l2\">{{t:template.drag.label2}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l3\">{{t:template.drag.label3}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l4\">{{t:template.drag.label4}}</astl-image-drop-label></astl-image-drop>',\n },\n ],\n fields: [\n {\n kind: 'picture-regions',\n tag: 'astl-image-drop-zone',\n src: 'src',\n label: 'editor.zones',\n help: 'editor.zonesHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-choice',\n tag: 'astl-image-drop-zone',\n attribute: 'answer',\n options: 'astl-image-drop-label',\n label: 'editor.answers',\n help: 'editor.answersHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { imageLabelManifest } from './manifest.js';\nimport { imageLabelMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const imageLabelEditor: EditorDescriptor = {\n manifest: imageLabelManifest,\n messages: imageLabelMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'map-pin',\n idPrefix: 'image-label',\n template:\n '<astl-image-label id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-image-label-pin id=\"p1\" x=\"30\" y=\"50\" label=\"{{t:template.answer1}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p2\" x=\"70\" y=\"50\" label=\"{{t:template.answer2}}\"></astl-image-label-pin>' +\n '</astl-image-label>',\n templates: [\n {\n id: 'label-the-picture',\n label: 'template.label.label',\n description: 'template.label.description',\n template:\n '<h3>{{t:template.label.heading}}</h3><p>{{t:template.label.instruction}}</p>' +\n '<astl-image-label id=\"{{id}}\"><astl-prompt>{{t:template.label.prompt}}</astl-prompt>' +\n '<astl-image-label-pin id=\"p1\" x=\"50\" y=\"15\" label=\"{{t:template.label.top}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p2\" x=\"50\" y=\"50\" label=\"{{t:template.label.centre}}\" alternatives=\"{{t:template.label.centreAlternative}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p3\" x=\"50\" y=\"85\" label=\"{{t:template.label.bottom}}\"></astl-image-label-pin>' +\n '</astl-image-label>',\n },\n ],\n fields: [\n {\n kind: 'picture-points',\n tag: 'astl-image-label-pin',\n src: 'src',\n label: 'editor.pins',\n help: 'editor.pinsHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-text',\n tag: 'astl-image-label-pin',\n attribute: 'alternatives',\n label: 'editor.alternatives',\n help: 'editor.alternativesHelp',\n },\n { kind: 'attribute', name: 'case', label: 'editor.case' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { longAnswerManifest } from './manifest.js';\nimport { longAnswerMessages } from './messages.js';\n\nexport const longAnswerEditor: EditorDescriptor = {\n manifest: longAnswerManifest,\n messages: longAnswerMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'note-pencil',\n idPrefix: 'answer',\n template:\n '<astl-long-answer id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt></astl-long-answer>',\n templates: [\n {\n id: 'write-your-answer',\n label: 'editor.template.write',\n description: 'editor.template.write.description',\n template:\n '<h3>{{t:template.write.title}}</h3><p>{{t:template.write.instruction}}</p>' +\n '<astl-long-answer id=\"{{id}}\" rows=\"6\" minlength=\"100\" maxlength=\"800\" placeholder=\"{{t:template.write.placeholder}}\">' +\n '<astl-prompt>{{t:template.write.question}}</astl-prompt></astl-long-answer>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'rows', label: 'editor.rows', help: 'editor.rowsHelp' },\n { kind: 'attribute', name: 'minlength', label: 'editor.minlength', help: 'editor.minlengthHelp' },\n { kind: 'attribute', name: 'maxlength', label: 'editor.maxlength', help: 'editor.maxlengthHelp' },\n { kind: 'attribute', name: 'placeholder', label: 'editor.placeholder' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { markWordsManifest } from './manifest.js';\nimport { markWordsMessages } from './messages.js';\n\nconst word = (id: string, key: string, correct = false) =>\n `<astl-mark-word id=\"${id}\"${correct ? ' correct' : ''}>{{t:template.${key}}}</astl-mark-word>`;\n/** One line of four words of the odd-word starter, the `odd`-th of them correct. */\nconst line = (row: string, odd: number) =>\n `<p>${[1, 2, 3, 4].map((n) => word(`${row}${n}`, `odd.${row}${n}`, n === odd)).join(' ')}</p>`;\n\nexport const markWordsEditor: EditorDescriptor = {\n manifest: markWordsManifest,\n messages: markWordsMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'highlighter',\n idPrefix: 'mark-words',\n template: `<astl-mark-words id=\"{{id}}\"><p>{{t:template.before}} ${word('w1', 'word', true)} {{t:template.after}}</p></astl-mark-words>`,\n templates: [\n {\n id: 'select-words',\n label: 'template.select.label',\n description: 'template.select.description',\n template:\n '<h3>{{t:template.select.heading}}</h3><p>{{t:template.select.instruction}}</p>' +\n `<astl-mark-words id=\"{{id}}\"><astl-prompt>{{t:template.select.prompt}}</astl-prompt><p>{{t:template.select.before}} ${word('w1', 'select.word1', true)} ` +\n `{{t:template.select.middle}} ${word('w2', 'select.word2')} {{t:template.select.and}} ` +\n `${word('w3', 'select.word3', true)} {{t:template.select.after}}</p></astl-mark-words>`,\n },\n {\n id: 'odd-word',\n label: 'template.odd.label',\n description: 'template.odd.description',\n icon: 'strikethrough',\n template:\n '<h3>{{t:template.odd.heading}}</h3><p>{{t:template.odd.instruction}}</p>' +\n `<astl-mark-words id=\"{{id}}\" variant=\"strike\"><astl-prompt>{{t:template.odd.prompt}}</astl-prompt>${line('a', 3)}${line('b', 4)}${line('c', 2)}</astl-mark-words>`,\n },\n ],\n fields: [\n { kind: 'attribute', name: 'variant', label: 'editor.variant' },\n {\n kind: 'child-flag',\n tag: 'astl-mark-word',\n attribute: 'correct',\n label: 'editor.correct',\n help: 'editor.correctHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n wrap: { label: 'editor.wrap', child: 'astl-mark-word', attributes: { correct: '' } },\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { matchManifest } from './manifest.js';\nimport { matchMessages } from './messages.js';\n\n/**\n * A task of the sample set `template.<set>.*`: three rows matched one to one with three columns (r1 with a, r2 with\n * b, r3 with c), after `head` (a prompt, or nothing) and with `attrs` on the element.\n */\nconst task = (set: string, attrs: string, head: string): string =>\n `<astl-match id=\"{{id}}\"${attrs}>${head}` +\n ['1', '2', '3']\n .map((n, i) => `<astl-row id=\"r${n}\" column=\"${'abc'[i]}\">{{t:template.${set}.row${n}}}</astl-row>`)\n .join('') +\n ['A', 'B', 'C']\n .map((c) => `<astl-column id=\"${c.toLowerCase()}\">{{t:template.${set}.column${c}}}</astl-column>`)\n .join('') +\n '</astl-match>';\n\n/** A named starter: a level-3 heading, the instruction, then the task. */\nconst starter = (set: string, attrs = ''): string =>\n `<h3>{{t:template.${set}.heading}}</h3><p>{{t:template.${set}.prompt}}</p>${task(set, attrs, '')}`;\n\nexport const matchEditor: EditorDescriptor = {\n manifest: matchManifest,\n messages: matchMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'arrows-left-right',\n idPrefix: 'match',\n template: task('matching', '', '<astl-prompt>{{t:template.matching.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'matching',\n label: 'template.matching',\n description: 'template.matching.description',\n template: starter('matching'),\n },\n {\n id: 'join-the-lines',\n label: 'template.lines',\n description: 'template.lines.description',\n template: starter('lines', ' variant=\"lines\"'),\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-row',\n attribute: 'column',\n options: 'astl-column',\n label: 'editor.answers',\n help: 'editor.answersHelp',\n },\n { kind: 'attribute', name: 'variant', label: 'editor.layout' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { memoryManifest } from './manifest.js';\nimport { memoryMessages } from './messages.js';\n\n/** Three text-only pairs, written pair by pair (the view shuffles them), after `head` (a prompt, or nothing). */\nconst game = (head: string): string =>\n `<astl-memory id=\"{{id}}\">${head}` +\n ['1', '2', '3']\n .map(\n (n) =>\n `<astl-card-a id=\"a${n}\">{{t:template.memory.a${n}}}</astl-card-a>` +\n `<astl-card-b id=\"b${n}\" pair=\"a${n}\">{{t:template.memory.b${n}}}</astl-card-b>`,\n )\n .join('') +\n '</astl-memory>';\n\nexport const memoryEditor: EditorDescriptor = {\n manifest: memoryManifest,\n messages: memoryMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'memory',\n template: game('<astl-prompt>{{t:template.memory.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'memory',\n label: 'template.memory',\n description: 'template.memory.description',\n template: `<h3>{{t:template.memory.heading}}</h3><p>{{t:template.memory.prompt}}</p>${game('')}`,\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-card-b',\n attribute: 'pair',\n options: 'astl-card-a',\n label: 'editor.pairs',\n help: 'editor.pairsHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { orderManifest } from './manifest.js';\nimport { orderMessages } from './messages.js';\n\n/** The items are written in their correct order, so the template's own texts already show how the answer works. */\nexport const orderEditor: EditorDescriptor = {\n manifest: orderManifest,\n messages: orderMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'list-numbers',\n idPrefix: 'order',\n template:\n '<astl-order id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-item id=\"a\">{{t:template.item1}}</astl-item>' +\n '<astl-item id=\"b\">{{t:template.item2}}</astl-item>' +\n '<astl-item id=\"c\">{{t:template.item3}}</astl-item></astl-order>',\n templates: [\n {\n id: 'ordering',\n label: 'template.cycle.label',\n description: 'template.cycle.description',\n template:\n '<h3>{{t:template.cycle.heading}}</h3><p>{{t:template.cycle.instruction}}</p>' +\n '<astl-order id=\"{{id}}\"><astl-prompt>{{t:template.cycle.prompt}}</astl-prompt>' +\n '<astl-item id=\"a\">{{t:template.cycle.item1}}</astl-item>' +\n '<astl-item id=\"b\">{{t:template.cycle.item2}}</astl-item>' +\n '<astl-item id=\"c\">{{t:template.cycle.item3}}</astl-item>' +\n '<astl-item id=\"d\">{{t:template.cycle.item4}}</astl-item></astl-order>',\n },\n ],\n fields: [\n // First, with the help that explains the answer: the source order is the correct one.\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'variant', label: 'editor.variant', help: 'editor.variantHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { selectManifest } from './manifest.js';\nimport { selectMessages } from './messages.js';\n\n/** The variant is listed so the dropdown's `native` switch can follow it (the kit would add it after the fields). */\nexport const selectEditor: EditorDescriptor = {\n manifest: selectManifest,\n messages: selectMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'caret-circle-down',\n idPrefix: 'select',\n template:\n '<astl-select id=\"{{id}}\"><astl-option id=\"a\" correct>{{t:template.option1}}</astl-option>' +\n '<astl-option id=\"b\">{{t:template.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.option3}}</astl-option></astl-select>',\n templates: [\n {\n id: 'choose-from-a-list',\n label: 'template.list.label',\n description: 'template.list.description',\n template:\n '<h3>{{t:template.list.heading}}</h3><p>{{t:template.list.instruction}}</p>' +\n '<p>{{t:template.list.start}} <astl-select id=\"{{id}}\">' +\n '<astl-option id=\"a\">{{t:template.list.option1}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.list.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.list.option3}}</astl-option></astl-select>{{t:template.list.end}}</p>',\n },\n {\n id: 'click-the-right-word',\n label: 'template.click.label',\n description: 'template.click.description',\n template:\n '<h3>{{t:template.click.heading}}</h3><p>{{t:template.click.instruction}}</p>' +\n '<p>{{t:template.click.start1}} <astl-select id=\"{{id}}\" variant=\"buttons\">' +\n '<astl-option id=\"a\">{{t:template.click.option1a}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.click.option1b}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.click.option1c}}</astl-option></astl-select>{{t:template.click.end}}</p>' +\n '<p>{{t:template.click.start2}} <astl-select variant=\"buttons\">' +\n '<astl-option id=\"a\">{{t:template.click.option2a}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.click.option2b}}</astl-option></astl-select>' +\n '{{t:template.click.end}}</p>',\n },\n ],\n fields: [\n {\n kind: 'child-flag',\n tag: 'astl-option',\n attribute: 'correct',\n label: 'editor.correctOption',\n help: 'editor.correctOptionHelp',\n },\n { kind: 'attribute', name: 'shuffle', label: 'editor.shuffle' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n { kind: 'attribute', name: 'variant', label: 'editor.variant' },\n {\n kind: 'attribute',\n name: 'native',\n label: 'editor.native',\n help: 'editor.nativeHelp',\n variants: ['dropdown'],\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { trueFalseManifest } from './manifest.js';\nimport { trueFalseMessages } from './messages.js';\n\nexport const trueFalseEditor: EditorDescriptor = {\n manifest: trueFalseManifest,\n messages: trueFalseMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'toggle-left',\n idPrefix: 'tf',\n template:\n '<astl-true-false id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-statement id=\"s1\" answer=\"true\">{{t:template.statement1}}</astl-statement>' +\n '<astl-statement id=\"s2\" answer=\"false\">{{t:template.statement2}}</astl-statement></astl-true-false>',\n templates: [\n {\n id: 'true-or-false',\n label: 'template.tf.label',\n description: 'template.tf.description',\n template:\n '<h3>{{t:template.tf.heading}}</h3><p>{{t:template.tf.instruction}}</p><astl-true-false id=\"{{id}}\">' +\n '<astl-statement id=\"s1\" answer=\"true\">{{t:template.tf.statement1}}</astl-statement>' +\n '<astl-statement id=\"s2\" answer=\"false\">{{t:template.tf.statement2}}</astl-statement>' +\n '<astl-statement id=\"s3\" answer=\"true\">{{t:template.tf.statement3}}</astl-statement></astl-true-false>',\n },\n ],\n fields: [\n { kind: 'child-choice', tag: 'astl-statement', attribute: 'answer', label: 'editor.answers' },\n { kind: 'attribute', name: 'true-label', label: 'editor.trueLabel', help: 'editor.labelsHelp' },\n { kind: 'attribute', name: 'false-label', label: 'editor.falseLabel' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { videoManifest } from './manifest.js';\nimport { videoMessages } from './messages.js';\n\n/** The starter's sample video: authors paste their own link over it. */\nconst SAMPLE = 'https://youtu.be/Bq7mT2kWx4E';\n\n/**\n * The default template names the video only: the author pastes a link or gives a file (until then, an error says so).\n * The \"Watch, then answer\" starter is two pages: the video with a tip, then a sentence to complete.\n */\nexport const videoEditor: EditorDescriptor = {\n manifest: videoManifest,\n messages: videoMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'film-strip',\n idPrefix: 'video',\n template: '<astl-video id=\"{{id}}\" label=\"{{t:template.label}}\"></astl-video>',\n templates: [\n {\n id: 'watch-then-answer',\n label: 'editor.template.watch',\n description: 'editor.template.watch.description',\n template:\n '<h3>{{t:template.watch.title}}</h3><p>{{t:template.watch.instruction}}</p>' +\n '<astl-callout kind=\"tip\"><p>{{t:template.watch.tip}}</p></astl-callout>' +\n `<astl-video id=\"{{id}}\" label=\"{{t:template.watch.label}}\" youtube=\"${SAMPLE}\"></astl-video>` +\n '<p>{{t:template.watch.sentence}} <astl-gap answer=\"{{t:template.watch.gap}}\"></astl-gap>.</p>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'label', label: 'editor.title', help: 'editor.titleHelp' },\n { kind: 'attribute', name: 'youtube', label: 'editor.youtube', help: 'editor.youtubeHelp' },\n { kind: 'attribute', name: 'vimeo', label: 'editor.vimeo', help: 'editor.vimeoHelp' },\n {\n kind: 'attribute',\n name: 'src',\n label: 'editor.src',\n help: 'editor.srcHelp',\n accept: 'video/mp4,video/webm',\n },\n {\n kind: 'attribute',\n name: 'poster',\n label: 'editor.poster',\n help: 'editor.posterHelp',\n accept: 'image/*',\n },\n {\n kind: 'attribute',\n name: 'captions',\n label: 'editor.captions',\n help: 'editor.captionsHelp',\n accept: '.vtt,text/vtt',\n },\n {\n kind: 'attribute',\n name: 'captions-lang',\n label: 'editor.captionsLang',\n help: 'editor.captionsLangHelp',\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { wordBankManifest } from './manifest.js';\nimport { wordBankMessages } from './messages.js';\n\n/** Words are edited in place (Enter adds one); the inspector tags distractors and switches reuse. */\nexport const wordBankEditor: EditorDescriptor = {\n manifest: wordBankManifest,\n messages: wordBankMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'bank',\n template:\n '<astl-word-bank id=\"{{id}}\"><astl-word id=\"a\">{{t:template.word1}}</astl-word>' +\n '<astl-word id=\"b\">{{t:template.word2}}</astl-word>' +\n '<astl-word id=\"c\" distractor>{{t:template.word3}}</astl-word></astl-word-bank>',\n templates: [\n {\n // The kit gives the gaps their ids and links them to this bank.\n id: 'drag-words',\n label: 'editor.template.dragWords',\n description: 'editor.template.dragWords.description',\n template:\n '<h3>{{t:template.dragWords.heading}}</h3><p>{{t:template.dragWords.instruction}}</p>' +\n '<astl-word-bank id=\"{{id}}\"><astl-word id=\"a\">{{t:template.dragWords.answer1}}</astl-word>' +\n '<astl-word id=\"b\">{{t:template.dragWords.answer2}}</astl-word>' +\n '<astl-word id=\"c\" distractor>{{t:template.dragWords.distractor}}</astl-word></astl-word-bank>' +\n '<p>{{t:template.dragWords.start}} <astl-drop answer=\"a\"></astl-drop>{{t:template.dragWords.middle}} ' +\n '<astl-drop answer=\"b\"></astl-drop>{{t:template.dragWords.end}}</p>',\n },\n ],\n fields: [\n {\n kind: 'child-flag',\n tag: 'astl-word',\n attribute: 'distractor',\n label: 'editor.distractors',\n help: 'editor.distractorsHelp',\n },\n { kind: 'attribute', name: 'reuse', label: 'editor.reuse', help: 'editor.reuseHelp' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { wordSearchManifest } from './manifest.js';\nimport { wordSearchMessages } from './messages.js';\n\nconst DIRECTIONS = ['right', 'down', 'down-right', 'left', 'up', 'up-left', 'down-left', 'up-right'];\n/** The default directions, written so the inspector's checkboxes show them. */\nconst OPEN = '<astl-word-search id=\"{{id}}\" right down down-right>';\nconst WORDS = [1, 2, 3]\n .map((n) => `<astl-search-word id=\"w${n}\">{{t:template.word${n}}}</astl-search-word>`)\n .join('');\n\nexport const wordSearchEditor: EditorDescriptor = {\n manifest: wordSearchManifest,\n messages: wordSearchMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'magnifying-glass',\n idPrefix: 'word-search',\n template: `${OPEN}<astl-prompt>{{t:template.instruction}}</astl-prompt>${WORDS}</astl-word-search>`,\n templates: [\n {\n id: 'word-search',\n label: 'editor.template.wordSearch',\n description: 'editor.template.wordSearch.description',\n template: `<h3>{{t:template.title}}</h3><p>{{t:template.instruction}}</p>${OPEN}${WORDS}</astl-word-search>`,\n },\n ],\n fields: [\n {\n kind: 'child-text',\n tag: 'astl-search-word',\n attribute: 'word',\n label: 'editor.words',\n help: 'editor.wordsHelp',\n },\n { kind: 'attribute', name: 'size', label: 'editor.size', help: 'editor.sizeHelp' },\n ...DIRECTIONS.map((name) => ({\n kind: 'attribute' as const,\n name,\n label: `editor.${name}`,\n ...(name === 'right' ? { help: 'editor.rightHelp' } : {}),\n })),\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","/** The built-in editor descriptors, for the authoring kit (`createAuthoring`, `defineAuthoringElements`). */\nimport type { EditorDescriptor } from '@astl/core';\nimport { audioEditor } from './audio/editor.js';\nimport { calloutEditor } from './callout/editor.js';\nimport { categoriseEditor } from './categorise/editor.js';\nimport { choiceEditor } from './choice/editor.js';\nimport { crosswordEditor } from './crossword/editor.js';\nimport { dropEditor } from './drop/editor.js';\nimport { flashCardsEditor } from './flash-cards/editor.js';\nimport { gapEditor } from './gap/editor.js';\nimport { hotspotEditor } from './hotspot/editor.js';\nimport { imageDropEditor } from './image-drop/editor.js';\nimport { imageLabelEditor } from './image-label/editor.js';\nimport { longAnswerEditor } from './long-answer/editor.js';\nimport { markWordsEditor } from './mark-words/editor.js';\nimport { matchEditor } from './match/editor.js';\nimport { memoryEditor } from './memory/editor.js';\nimport { orderEditor } from './order/editor.js';\nimport { selectEditor } from './select/editor.js';\nimport { trueFalseEditor } from './true-false/editor.js';\nimport { videoEditor } from './video/editor.js';\nimport { wordBankEditor } from './word-bank/editor.js';\nimport { wordSearchEditor } from './word-search/editor.js';\n\nexport const builtInEditors: readonly EditorDescriptor[] = [\n gapEditor,\n choiceEditor,\n selectEditor,\n trueFalseEditor,\n orderEditor,\n categoriseEditor,\n matchEditor,\n wordBankEditor,\n dropEditor,\n wordSearchEditor,\n memoryEditor,\n crosswordEditor,\n flashCardsEditor,\n longAnswerEditor,\n markWordsEditor,\n calloutEditor,\n hotspotEditor,\n imageDropEditor,\n imageLabelEditor,\n videoEditor,\n audioEditor,\n];\n","import type { EditorBlockPlace, EditorStyleTargetKind } from '@astl/core';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type SVGTemplateResult,\n svg,\n type TemplateResult,\n} from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { refusalOf } from '../authoring.js';\nimport type { InspectorChange } from '../edit.js';\nimport type {\n CheckboxFieldModel,\n ChildChoiceFieldModel,\n ChildFlagFieldModel,\n ChildTableFieldModel,\n ChildTextFieldModel,\n InspectorFieldModel,\n InspectorModel,\n NumberFieldModel,\n SelectFieldModel,\n TextFieldModel,\n TextListFieldModel,\n} from '../inspect.js';\nimport { AuthoringElement } from './base.js';\nimport { GLYPHS, TYPE_GLYPHS } from './insert-menu.js';\nimport { SEVERITY_ICONS, sortIssues } from './issue-list.js';\nimport type { FieldChange } from './picture-field.js';\nimport { loadHelpForm, loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** A control to focus after the next render (text list rows come and go). */\ninterface PendingFocus {\n readonly field: number;\n readonly item: number | 'add';\n}\n\n/** The icons of the head's actions: shapes only, stroked by the `.glyph` rule. */\nconst ACTION_ICONS = {\n moveUp: svg`<path d=\"M10 16V4M5 9l5-5 5 5\"/>`,\n moveDown: svg`<path d=\"M10 4v12M5 11l5 5 5-5\"/>`,\n delete: svg`<path d=\"M4 6h12M8 6V4h4v2M6 6l.8 10h6.4L14 6M9 9v4M11 9v4\"/>`,\n} satisfies Readonly<Record<string, SVGTemplateResult>>;\n\n/** Fields that fit beside another in the two-column form: a select, a number or a short text (no upload). */\nconst fitsBeside = (field: InspectorFieldModel): boolean =>\n field.kind === 'attribute' &&\n field.control !== 'checkbox' &&\n !(field.control === 'text' && field.accept !== null);\n\nconst inputValue = (event: Event) => (event.target as HTMLInputElement | HTMLSelectElement).value;\nconst checkedOf = (event: Event) => (event.target as HTMLInputElement).checked;\n\n/**\n * `<astl-inspector>`: a form for the component at the cursor (answers, alternatives, correct options, whether each\n * statement is true, the category of each card, scoring, points, variant, look), or, with the cursor outside every\n * component, the document's own settings (its look). Every edit goes through `authoring.update` and the adapter\n * (`replaceElement`, or `setSource` for the document), so the editor stays the source of truth. A block component's\n * head has \"Move up\", \"Move down\" and \"Delete\" (`EditorAdapter.moveBlock`, `removeBlock`, at `getCursor`), each left\n * out when the adapter cannot do it; at its page's start or end, a move is unavailable (`aria-disabled`). The head\n * shows the type's icon and name and the element's id in a chip; under it, the element's own issues, as banners. The\n * custom property `--astl-inspector-columns` (default 1) sets the form's columns: with 2, selects, numbers and short\n * texts sit side by side and every other field spans the row.\n */\nexport class AstlInspector extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n // The picture fields redeclare the tokens on their :host: they take this element's (theme, host overrides).\n inheritTokens('astl-picture-field, astl-style-form, astl-help-form'),\n css`\n .style {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n padding-block-start: var(--astl-space-3);\n border-block-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .style-title {\n margin: 0;\n font-size: 1rem;\n }\n .style-targets {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-1);\n }\n .fields {\n display: grid;\n grid-template-columns: repeat(var(--astl-inspector-columns, 1), minmax(0, 1fr));\n gap: var(--astl-space-3);\n }\n .fields > * {\n grid-column: 1 / -1;\n }\n .fields > .short {\n grid-column: auto;\n }\n .field,\n fieldset {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n margin: 0;\n padding: 0;\n border: 0;\n }\n label:not(.check),\n legend {\n padding: 0;\n font-weight: 600;\n }\n fieldset > ul,\n fieldset > .check:first-of-type {\n margin-block-start: var(--astl-space-1);\n }\n .check {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: var(--astl-space-2);\n min-block-size: var(--astl-target-min);\n cursor: pointer;\n }\n `,\n // One child of a child-choice field with a select: its text above the select.\n css`\n .pick {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n margin-block-start: var(--astl-space-1);\n }\n .pick label {\n font-weight: 400;\n }\n .item {\n display: flex;\n gap: var(--astl-space-2);\n align-items: center;\n }\n .item :is(input, textarea) {\n flex: 1 1 auto;\n }\n .item:has(textarea) {\n align-items: flex-start;\n }\n .item button {\n flex: none;\n }\n fieldset > button {\n align-self: flex-start;\n }\n `,\n // One child of a child-choice field with radios: its text, then the values side by side.\n css`\n .choice > legend {\n font-weight: 400;\n }\n .choice > .values {\n display: flex;\n flex-wrap: wrap;\n column-gap: var(--astl-space-4);\n }\n .help {\n margin: 0;\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n `,\n // One row of a child-table field: its text, then its controls side by side while they fit, and Remove.\n css`\n .row {\n margin-block-start: var(--astl-space-2);\n padding: var(--astl-space-2) var(--astl-space-3) var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n .row > legend {\n padding-inline: var(--astl-space-1);\n font-weight: 400;\n }\n .cells {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n gap: var(--astl-space-2);\n }\n .cell {\n flex: 1 1 5rem;\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n font-weight: 400;\n }\n .cell > input,\n .cell > select {\n inline-size: 100%;\n }\n `,\n // The head: the type's icon and name, the id in a chip, then the block's actions (icons), which wrap under it when\n // narrow. Under it the element's issues, each a banner in its severity's colour with an icon and words.\n css`\n .head,\n .actions {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1) var(--astl-space-2);\n }\n .title {\n flex: 0 1 auto;\n min-inline-size: 0;\n }\n .actions {\n margin-inline-start: auto;\n }\n .glyph {\n fill: none;\n stroke: currentColor;\n stroke-width: 1.8;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .glyph circle {\n fill: currentColor;\n stroke: none;\n }\n .id {\n padding-inline: var(--astl-space-2);\n border-radius: var(--astl-radius-s);\n background: var(--astl-accent-soft);\n color: var(--astl-ink);\n font-family: var(--astl-font-mono);\n font-size: var(--astl-size-small);\n }\n .delete {\n color: var(--astl-danger);\n }\n .issue {\n display: flex;\n align-items: flex-start;\n gap: var(--astl-space-2);\n padding-block: var(--astl-space-2);\n padding-inline: var(--astl-space-3);\n border-radius: var(--astl-radius-s);\n background: var(--astl-danger-soft);\n color: var(--astl-ink);\n }\n .issue .icon {\n color: var(--astl-danger);\n }\n .issue[data-severity='warning'] {\n background: var(--astl-warning-soft);\n }\n .issue[data-severity='warning'] .icon {\n color: var(--astl-warning);\n }\n @media (forced-colors: active) {\n .issue {\n border: var(--astl-outline-width) solid CanvasText;\n }\n }\n `,\n // A text-list row in a text area keeps its line breaks and grows with them.\n css`\n textarea {\n field-sizing: content;\n min-block-size: 5lh;\n resize: vertical;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .upload p {\n margin-block: var(--astl-space-1) 0;\n }\n .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n `,\n ];\n\n /** Source id of the element shown: edits go to it. */\n #shown: string | null = null;\n /** The document's settings are shown: edits go to the start tag of `<astl-doc>`. */\n #document = false;\n #model: InspectorModel | null = null;\n #focus: PendingFocus | null = null;\n /**\n * The last upload of a `url` field: its element and attribute, and what it says (a message key, or with `text` a\n * host's own words, `UploadRefused`).\n */\n #upload: {\n readonly element: string | null;\n readonly name: string;\n readonly key: string;\n readonly error: boolean;\n readonly text?: string | undefined;\n } | null = null;\n /** Aborts the upload under way (its `signal`): another pick replaces it. */\n #abort: AbortController | null = null;\n\n /** The inspector model on screen (a component's, or the document's), or null. */\n get model(): InspectorModel | null {\n return this.#model;\n }\n\n /**\n * Applies a change to what is shown (the element, or the document), or to the element `element` (a picture field's\n * late upload, whatever the cursor is in by then).\n */\n #apply(change: InspectorChange, element?: string | null): void {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return;\n if (element === undefined && this.#document) {\n const source = adapter.getSource();\n const next = authoring.update(source, change);\n if (next !== source) adapter.setSource(next);\n return;\n }\n const id = element === undefined ? this.#shown : element;\n if (id === null) return;\n const current = adapter.getElement(id);\n if (current === null) return;\n const next = authoring.update(current, change);\n if (next !== current) adapter.replaceElement(id, next);\n }\n\n protected override updated(): void {\n const focus = this.#focus;\n if (focus === null) return;\n this.#focus = null;\n const item = focus.item === 'add' ? '[data-add]' : `[data-item=\"${focus.item}\"]`;\n this.renderRoot.querySelector<HTMLElement>(`[data-field=\"${focus.field}\"]${item}`)?.focus();\n }\n\n /** `short` marks a field that may sit beside another (`--astl-inspector-columns`). */\n #fieldClass(field: InspectorFieldModel): string {\n return fitsBeside(field) ? 'field short' : 'field';\n }\n\n #help(field: InspectorFieldModel, i: number): TemplateResult | typeof nothing {\n return field.help === null ? nothing : html`<p class=\"help\" id=\"help-${i}\">${field.help}</p>`;\n }\n\n #describedBy(field: InspectorFieldModel, i: number): string | undefined {\n return field.help === null ? undefined : `help-${i}`;\n }\n\n #text(field: TextFieldModel, i: number): TemplateResult {\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({\n kind: 'attribute',\n name: field.name,\n value: value === '' && !field.required ? null : value,\n });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <input\n id=\"field-${i}\"\n type=\"text\"\n dir=\"auto\"\n autocomplete=\"off\"\n data-name=${field.name}\n .value=${live(field.value)}\n ?required=${field.required}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @input=${commit}\n />\n ${this.#help(field, i)}\n ${field.accept === null || this.authoring?.uploadAsset == null ? nothing : this.#uploadControl(field, field.accept)}\n </div>`;\n }\n\n /** A button that picks a file for a `url` field and uploads it, and what the last upload says. */\n #uploadControl(field: TextFieldModel, accept: string): TemplateResult {\n const said = this.#upload;\n const status = said?.element === this.#shown && said.name === field.name ? said : null;\n const words = status === null ? '' : (status.text ?? this.t(status.key));\n const pick = (event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n input.value = '';\n if (file !== undefined) void this.#uploadFile(field, file);\n };\n return html`<div class=\"upload\">\n <button\n type=\"button\"\n aria-label=${this.t('inspector.uploadItem', { label: field.label })}\n @click=${(event: Event) => ((event.currentTarget as Element).nextElementSibling as HTMLElement).click()}\n >\n ${this.t('inspector.upload')}\n </button>\n <input type=\"file\" accept=${accept} hidden data-name=${field.name} @change=${pick} />\n <div role=\"status\">${status !== null && !status.error ? html`<p class=\"help\">${words}</p>` : nothing}</div>\n <div role=\"alert\">${status?.error ? html`<p class=\"error\">${words}</p>` : nothing}</div>\n </div>`;\n }\n\n /**\n * Uploads a file with the host's `uploadAsset` and writes its address, when the URL policy allows it (asked as the\n * engine asks: the element's tag and attribute), into the element shown when it started.\n */\n async #uploadFile(field: TextFieldModel, file: File): Promise<void> {\n const authoring = this.authoring;\n const upload = authoring?.uploadAsset ?? null;\n if (authoring === null || upload === null) return;\n const element = this.#shown;\n const tag = this.#model?.tag ?? '';\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n const say = (key: string, error = false, text?: string) => {\n this.#upload = { element, name: field.name, key, error, text };\n this.requestUpdate();\n };\n say('inspector.uploading');\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (abort.signal.aborted) return;\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (src === '' || !authoring.urlPolicy(src, { tag, attribute: field.name })) {\n say('inspector.uploadBlocked', true);\n return;\n }\n this.#apply({ kind: 'attribute', name: field.name, value: src }, element);\n say('inspector.uploaded');\n } catch (error) {\n if (!abort.signal.aborted) say('inspector.uploadFailed', true, refusalOf(error));\n }\n }\n\n #number(field: NumberFieldModel, i: number): TemplateResult {\n // Numbers commit on change (blur, Enter, arrows): half-typed values like \"0.\" never reach the source.\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({ kind: 'attribute', name: field.name, value: value === '' ? null : value });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <input\n id=\"field-${i}\"\n type=\"number\"\n data-name=${field.name}\n min=${ifDefined(field.min ?? undefined)}\n max=${ifDefined(field.max ?? undefined)}\n step=${field.step}\n .value=${live(field.value)}\n ?required=${field.required}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${commit}\n />\n ${this.#help(field, i)}\n </div>`;\n }\n\n #checkbox(field: CheckboxFieldModel, i: number): TemplateResult {\n return html`<div class=\"field\" part=\"field\">\n <label class=\"check\" part=\"label\">\n <input\n type=\"checkbox\"\n data-name=${field.name}\n .checked=${live(field.checked)}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${(event: Event) =>\n this.#apply({ kind: 'attribute', name: field.name, value: checkedOf(event) })}\n />\n <span>${field.label}</span>\n </label>\n ${this.#help(field, i)}\n </div>`;\n }\n\n #select(field: SelectFieldModel, i: number): TemplateResult {\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({ kind: 'attribute', name: field.name, value: value === '' ? null : value });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <select\n id=\"field-${i}\"\n data-name=${field.name}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${commit}\n >\n ${field.options.map(\n (option) =>\n html`<option value=${option.value} .selected=${live(option.value === field.value)}>${option.label}</option>`,\n )}\n </select>\n ${this.#help(field, i)}\n </div>`;\n }\n\n #textList(field: TextListFieldModel, i: number): TemplateResult {\n const values = field.values;\n const set = (next: readonly string[]) => this.#apply({ kind: 'text-list', tag: field.tag, values: next });\n const add = () => {\n this.#focus = { field: i, item: values.length };\n set([...values, '']);\n };\n const remove = (j: number) => {\n const next = values.filter((_, k) => k !== j);\n this.#focus = { field: i, item: next.length === 0 ? 'add' : Math.min(j, next.length - 1) };\n set(next);\n };\n const full = field.max !== null && values.length >= field.max;\n return html`<fieldset data-tag=${field.tag} part=\"field\">\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${\n values.length === 0\n ? nothing\n : html`<ul role=\"list\">\n ${values.map((value, j) => {\n const name = this.t('inspector.item', { label: field.label, n: j + 1 });\n const described = ifDefined(this.#describedBy(field, i));\n const write = (event: Event) => set(values.map((v, k) => (k === j ? inputValue(event) : v)));\n // A multi-line value (a transcript) in a text area that keeps its line breaks.\n return html`<li class=\"item\">\n ${\n field.multiline\n ? html`<textarea dir=\"auto\" data-field=${i} data-item=${j} aria-label=${name}\n aria-describedby=${described} .value=${live(value)} @input=${write}></textarea>`\n : html`<input type=\"text\" dir=\"auto\" autocomplete=\"off\" data-field=${i} data-item=${j}\n aria-label=${name} aria-describedby=${described} .value=${live(value)} @input=${write} />`\n }\n <button\n type=\"button\"\n aria-label=${this.t('inspector.removeItem', { label: field.label, n: j + 1 })}\n @click=${() => remove(j)}\n >\n ${this.t('inspector.remove')}\n </button>\n </li>`;\n })}\n </ul>`\n }\n <button type=\"button\" data-field=${i} data-add ?disabled=${full} @click=${add}>${this.t('inspector.add')}</button>\n </fieldset>`;\n }\n\n #childFlags(field: ChildFlagFieldModel, i: number): TemplateResult {\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map(\n (child) => html`<label class=\"check\">\n <input\n type=\"checkbox\"\n data-index=${child.index}\n .checked=${live(child.checked)}\n @change=${(event: Event) =>\n this.#apply({\n kind: 'child-flag',\n tag: field.tag,\n attribute: field.attribute,\n index: child.index,\n value: checkedOf(event),\n })}\n />\n <span dir=\"auto\">${child.label}</span>\n </label>`,\n )}\n </fieldset>`;\n }\n\n /** A text input per child, labelled by the child's text (e.g. the word each clue hides); empty removes the value. */\n #childTexts(field: ChildTextFieldModel, i: number): TemplateResult {\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map(\n (child) => html`<div class=\"pick\">\n <label for=\"field-${i}-${child.index}\" dir=\"auto\">${child.label}</label>\n <input\n id=\"field-${i}-${child.index}\"\n type=\"text\"\n dir=\"auto\"\n autocomplete=\"off\"\n data-index=${child.index}\n .value=${live(child.value)}\n @input=${(event: Event) =>\n this.#apply({\n kind: 'child-attributes',\n tag: field.tag,\n index: child.index,\n attributes: { [field.attribute]: inputValue(event) || null },\n })}\n />\n </div>`,\n )}\n </fieldset>`;\n }\n\n /**\n * One control per child, named by the child's text: a radio group of the attribute's values (e.g. True / False for\n * each statement), or a select of the ids of other children (e.g. the group of each card).\n */\n #childChoices(field: ChildChoiceFieldModel, i: number): TemplateResult {\n const choose = (index: number, value: string | null) =>\n this.#apply({ kind: 'child-choice', tag: field.tag, attribute: field.attribute, index, value });\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map((child) =>\n field.control === 'radios'\n ? html`<fieldset class=\"choice\" data-index=${child.index}>\n <legend dir=\"auto\">${child.label}</legend>\n <div class=\"values\">\n ${child.options.map(\n (option) => html`<label class=\"check\">\n <input\n type=\"radio\"\n name=\"choice-${i}-${child.index}\"\n value=${option.value}\n .checked=${live(child.value === option.value)}\n @change=${() => choose(child.index, option.value)}\n />\n <span>${option.label}</span>\n </label>`,\n )}\n </div>\n </fieldset>`\n : html`<div class=\"pick\">\n <label for=\"field-${i}-${child.index}\" dir=\"auto\">${child.label}</label>\n <select\n id=\"field-${i}-${child.index}\"\n data-index=${child.index}\n @change=${(event: Event) => choose(child.index, inputValue(event) || null)}\n >\n ${child.options.map(\n (option) =>\n html`<option value=${option.value} .selected=${live(option.value === child.value)}>${option.label}</option>`,\n )}\n </select>\n </div>`,\n )}\n </fieldset>`;\n }\n\n /**\n * A row per child, named by its text, with a labelled control per column (text and numbers commit like the attribute\n * fields), a button that removes the row, and one that adds a row at the end.\n */\n #childTable(field: ChildTableFieldModel, i: number): TemplateResult {\n const { tag, rows, columns } = field;\n const change = (index: number, attribute: string, value: string, required: boolean) =>\n this.#apply({\n kind: 'child-attributes',\n tag,\n index,\n attributes: { [attribute]: value || (required ? '' : null) },\n });\n const add = () => {\n this.#focus = { field: i, item: rows.length };\n this.#apply({ kind: 'child-add', tag, attributes: field.added });\n };\n const remove = (index: number) => {\n this.#focus = { field: i, item: rows.length > 1 ? Math.min(index, rows.length - 2) : 'add' };\n this.#apply({ kind: 'child-remove', tag, index });\n };\n const control = (\n column: ChildTableFieldModel['columns'][number],\n row: ChildTableFieldModel['rows'][number],\n k: number,\n ) => {\n const value = row.values[k] ?? '';\n const commit = (event: Event) =>\n change(row.index, column.attribute, inputValue(event), column.required);\n const first = k === 0 ? { field: i, item: row.index } : null;\n if (column.control === 'select') {\n const known = column.options.some((o) => o.value === value);\n const options = known\n ? column.options\n : [...column.options, { value, label: value || this.t('inspector.unset') }];\n return html`<select data-field=${ifDefined(first?.field)} data-item=${ifDefined(first?.item)} data-name=${column.attribute} @change=${commit}>\n ${options.map((o) => html`<option value=${o.value} .selected=${live(o.value === value)}>${o.label}</option>`)}\n </select>`;\n }\n return html`<input\n type=${column.control}\n dir=${column.control === 'text' ? 'auto' : nothing}\n autocomplete=\"off\"\n data-field=${ifDefined(first?.field)}\n data-item=${ifDefined(first?.item)}\n data-name=${column.attribute}\n min=${ifDefined(column.min ?? undefined)}\n max=${ifDefined(column.max ?? undefined)}\n step=${ifDefined(column.control === 'number' ? column.step : undefined)}\n .value=${live(value)}\n @input=${column.control === 'text' ? commit : nothing}\n @change=${column.control === 'number' ? commit : nothing}\n />`;\n };\n return html`<fieldset data-tag=${tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${rows.map(\n (row) => html`<fieldset class=\"row\" data-index=${row.index}>\n <legend dir=\"auto\">${row.label}</legend>\n <div class=\"cells\">\n ${columns.map(\n (column, k) =>\n html`<label class=\"cell\"><span>${column.label}</span>${control(column, row, k)}</label>`,\n )}\n <button\n type=\"button\"\n aria-label=${this.t('inspector.removeItem', { label: field.label, n: row.index + 1 })}\n ?disabled=${rows.length <= field.min}\n @click=${() => remove(row.index)}\n >\n ${this.t('inspector.remove')}\n </button>\n </div>\n </fieldset>`,\n )}\n <button type=\"button\" data-field=${i} data-add ?disabled=${field.max !== null && rows.length >= field.max} @click=${add}>\n ${this.t('inspector.add')}\n </button>\n </fieldset>`;\n }\n\n #field(field: InspectorFieldModel, i: number): TemplateResult {\n switch (field.kind) {\n case 'picture-regions':\n case 'picture-points':\n return html`<astl-picture-field\n .field=${field}\n .authoring=${this.authoring}\n .element=${this.#shown}\n @astl-field-change=${(event: CustomEvent<FieldChange>) => this.#apply(event.detail.change, event.detail.element)}\n ></astl-picture-field>`;\n case 'text-list':\n return this.#textList(field, i);\n case 'child-flag':\n return this.#childFlags(field, i);\n case 'child-text':\n return this.#childTexts(field, i);\n case 'child-choice':\n return this.#childChoices(field, i);\n case 'child-table':\n return this.#childTable(field, i);\n case 'attribute':\n switch (field.control) {\n case 'text':\n return this.#text(field, i);\n case 'number':\n return this.#number(field, i);\n case 'checkbox':\n return this.#checkbox(field, i);\n case 'select':\n return this.#select(field, i);\n }\n }\n }\n\n /**\n * The icon buttons of a block component's head, named and with a tooltip by their text: each needs the cursor's block\n * (`getCursor`) and its own capability. A move off the page's start or end is unavailable but keeps the focus; after a\n * delete the focus goes to the editor.\n */\n #actions(tag: string): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n const place: EditorBlockPlace | null = adapter?.getCursor?.() ?? null;\n if (authoring === null || adapter === null || place === null) return nothing;\n if (authoring.descriptor(tag)?.manifest.display !== 'block') return nothing;\n const page = authoring.outline(adapter.getSource()).pages.find((p) => p.id === place.page);\n const button = (name: keyof typeof ACTION_ICONS, off: boolean, run: () => void) =>\n html`<button type=\"button\" class=${name} data-action=${name} aria-label=${this.t(`inspector.${name}`)}\n title=${this.t(`inspector.${name}`)} aria-disabled=${off ? 'true' : nothing}\n @click=${() => {\n if (!off) run();\n }}><svg class=\"icon glyph\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${ACTION_ICONS[name]}</svg></button>`;\n const move = (direction: 'up' | 'down') => () => adapter.moveBlock?.(place, direction);\n return html`<div class=\"actions\" part=\"actions\">\n ${adapter.moveBlock === undefined ? nothing : button('moveUp', place.index === 0, move('up'))}\n ${adapter.moveBlock === undefined ? nothing : button('moveDown', place.index >= (page?.blocks.length ?? 0) - 1, move('down'))}\n ${\n adapter.removeBlock === undefined\n ? nothing\n : button('delete', false, () => {\n adapter.removeBlock?.(place);\n adapter.focus?.();\n })\n }\n </div>`;\n }\n\n /** The element's own issues, the sentences its frame shows (`authoring.describe` without the page), errors first. */\n #issues(model: InspectorModel): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null || model.id === null) return nothing;\n const source = adapter.getSource();\n const issues = sortIssues(authoring.validate(source).issues.filter((i) => i.at.element === model.id));\n if (issues.length === 0) return nothing;\n return html`<ul class=\"issues\" role=\"list\">\n ${issues.map(\n (\n issue,\n ) => html`<li class=\"issue\" part=\"issue\" data-code=${issue.code} data-severity=${issue.severity}>\n <svg class=\"icon\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${SEVERITY_ICONS[issue.severity]}</svg>\n <span class=\"astl-vh\">${this.t(`severity.${issue.severity}`)}: </span>\n <span>${authoring.describe(issue, source, { page: false })}</span>\n </li>`,\n )}\n </ul>`;\n }\n\n /** The head: the type's icon and name, the id in a chip when it has one, then the block's actions. */\n #head(model: InspectorModel): TemplateResult {\n const display = this.authoring?.descriptor(model.tag)?.manifest.display;\n const glyph = TYPE_GLYPHS.get(model.icon ?? '') ?? GLYPHS[display === 'inline' ? 'inline' : 'block'];\n return html`<div class=\"head\" part=\"head header\">\n <svg class=\"icon glyph\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${glyph}</svg>\n <h2 class=\"title\" id=\"title\" part=\"title\" data-id=${model.id ?? nothing}>${model.label}</h2>\n ${model.id === null ? nothing : html`<code class=\"id\" part=\"id\">${model.id}</code>`}\n ${this.#actions(model.tag)}\n </div>`;\n }\n\n /** The kinds at the cursor: when they change, so does the style section. */\n #styleKinds = '';\n /** The target whose form is open here, while it is at the cursor. */\n #styleOpen: EditorStyleTargetKind | null = null;\n\n protected override cursorChanged(): void {\n const targets = this.adapter?.style?.state().targets ?? [];\n const kinds = targets.map((target) => target.kind).join(' ');\n if (kinds === this.#styleKinds) return;\n this.#styleKinds = kinds;\n // A picture has nothing else to set here, and its position and size are why it was selected.\n const first = targets[0]?.kind;\n this.#styleOpen = first === 'picture' ? first : null;\n if (this.#styleOpen !== null) void this.#showStyle(this.#styleOpen);\n this.requestUpdate();\n }\n\n /** Shows a form here, the module loaded first. */\n async #showStyle(kind: EditorStyleTargetKind): Promise<void> {\n await loadStyleElements();\n this.#styleOpen = kind;\n this.requestUpdate();\n }\n\n /** A press on a target: a host may take it (`astl-style-open`); otherwise its form opens here, or closes. */\n #askStyle(kind: EditorStyleTargetKind): void {\n if (this.#styleOpen === kind) {\n this.#styleOpen = null;\n this.requestUpdate();\n return;\n }\n const detail: StyleOpen = { target: kind };\n const event = new CustomEvent(STYLE_OPEN, { detail, bubbles: true, composed: true, cancelable: true });\n if (this.dispatchEvent(event)) void this.#showStyle(kind);\n }\n\n /** The style of what the cursor is in: a button per target, and the open one's form. */\n #styleSection(): TemplateResult | typeof nothing {\n const targets = this.adapter?.style?.state().targets ?? [];\n if (targets.length === 0) return nothing;\n const open = targets.some((target) => target.kind === this.#styleOpen) ? this.#styleOpen : null;\n return html`<div class=\"style\" part=\"style\">\n <h3 class=\"style-title\">${this.t('inspector.style')}</h3>\n <div class=\"style-targets\">\n ${targets.map(\n (target) => html`<button\n type=\"button\"\n data-style-target=${target.kind}\n aria-expanded=${String(open === target.kind)}\n @click=${() => this.#askStyle(target.kind)}\n >\n ${this.t(`style.target.${target.kind}`)}\n </button>`,\n )}\n </div>\n ${\n open === null\n ? nothing\n : html`<astl-style-form .authoring=${this.authoring} .adapter=${this.adapter} .target=${open}></astl-style-form>`\n }\n </div>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n const selection = adapter?.getSelection() ?? null;\n const source = selection === null || adapter === null ? null : adapter.getElement(selection.id);\n // With the document: a field may list what another element holds (the words of a drop's bank).\n const model = source === null ? null : authoring.inspect(source, adapter?.getSource());\n // Outside every component: the document's own settings, under the hint.\n const document =\n selection === null && adapter !== null ? authoring.inspectDocument(adapter.getSource()) : null;\n this.#shown = model === null ? null : (selection?.id ?? null);\n this.#document = model === null && document !== null;\n this.#model = model ?? document;\n const { lang, dir } = this.ui;\n let body: TemplateResult;\n if (model === null) {\n const note =\n source !== null && selection !== null\n ? this.t('inspector.unsupported', { tag: selection.tag })\n : this.t('inspector.empty');\n body = html`<h2 class=\"title\" id=\"title\" part=\"title\">${this.t('inspector.title')}</h2>\n <p class=\"note\">${note}</p>\n ${\n document === null\n ? nothing\n : html`<div class=\"fields\" data-tag=${document.tag}>${document.fields.map((f, i) => this.#field(f, i))}</div>`\n }`;\n } else {\n // The heading says the type; the id is beside it in a chip, outside the heading.\n // A graded element's help for students: a form of its own, loaded on first use.\n const manifest = authoring.descriptor(model.tag)?.manifest;\n if (manifest?.graded === true) void loadHelpForm().catch(() => {});\n body = html`${this.#head(model)}${this.#issues(model)}\n <div class=\"fields\" data-tag=${model.tag}>${model.fields.map((f, i) => this.#field(f, i))}</div>\n ${\n manifest?.graded === true\n ? html`<astl-help-form .authoring=${authoring} .adapter=${adapter} .element=${this.#shown}\n ?inline=${manifest.display === 'inline'}></astl-help-form>`\n : nothing\n }`;\n }\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"title\">${body}${this.#styleSection()}</section>`;\n }\n}\n","import type { Issue } from '@astl/core';\nimport { type CSSResultGroup, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { AuthoringElement } from './base.js';\nimport { issueStyles, renderIssues } from './issue-list.js';\nimport { kitStyles } from './styles.js';\n\n/** Validation waits this long after the last change, so typing is not interrupted. */\nexport const VALIDATION_DELAY_MS = 300;\n\n/**\n * `<astl-issues>`: live validation of the whole document in the UI locale, errors first. Selecting an issue moves the\n * editor's cursor to its element (`adapter.select`).\n */\nexport class AstlIssues extends AuthoringElement {\n static override styles: CSSResultGroup = [kitStyles, issueStyles];\n\n #issues: readonly Issue[] | null = null;\n /** The source the issues are about. */\n #source = '';\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n /** The issues on screen (null before the first validation). */\n get issues(): readonly Issue[] | null {\n return this.#issues;\n }\n\n /** Validates now instead of waiting for the debounce. */\n validate(): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#check();\n this.requestUpdate();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // Back in the document: the source may have changed while we were not listening.\n if (this.hasUpdated) this.validate();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearTimeout(this.#timer);\n this.#timer = undefined;\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring') || changed.has('adapter')) this.#check();\n }\n\n #check(): void {\n const { authoring, adapter } = this;\n this.#source = adapter?.getSource() ?? '';\n this.#issues = authoring === null || adapter === null ? null : authoring.validate(this.#source).issues;\n }\n\n protected override sourceChanged(): void {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.validate(), VALIDATION_DELAY_MS);\n }\n\n protected override selectionChanged(): void {\n // The list does not depend on the cursor.\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n // Validation is synchronous: no issues means no adapter (no editor yet, or one that failed to load), so there is\n // no document to check and nothing to say.\n const issues = adapter === null ? null : this.#issues;\n const { lang, dir } = this.ui;\n let summary = '';\n if (issues !== null && issues.length === 0) summary = this.t('issues.none');\n else if (issues !== null) {\n const errors = issues.filter((i) => i.severity === 'error').length;\n summary = this.t('issues.summary', {\n errors: this.t('issues.errors', { count: errors }),\n warnings: this.t('issues.warnings', { count: issues.length - errors }),\n });\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('issues.title')}</h2>\n <p class=\"note summary\" role=\"status\" ?hidden=${issues === null}>${summary}</p>\n ${issues === null ? nothing : renderIssues(issues, authoring, adapter, this.#source)}\n </section>`;\n }\n}\n","import { type CSSResultGroup, css, html, nothing, type TemplateResult } from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { type PictureFields, pictureSize, refusalOf, type UploadedAsset } from '../authoring.js';\nimport { AuthoringElement } from './base.js';\nimport { kitStyles } from './styles.js';\n\n/** What `ask` opens the dialog with. */\nexport interface PictureRequest {\n /** A picture to edit: its address, alt text and size. Absent: a new picture. */\n readonly current?: PictureFields;\n /** A file to upload first (pasted or dropped), through the authoring's `uploadAsset`. */\n readonly file?: File;\n /** Whether to ask for a caption (a new picture). Default: true for a new picture, false for an edit. */\n readonly caption?: boolean;\n /** Whether `current` is decorative; default: when its alt text is empty. */\n readonly decorative?: boolean;\n /** The picture carries the task (a component's): its alt text is required, with no decorative choice. */\n readonly altRequired?: boolean;\n /** The element and attribute the address is for, as the URL policy is asked; default `img` and `src`. */\n readonly target?: { readonly tag: string; readonly attribute: string };\n}\n\n/** A message of the kit's catalog, or with `text` a host's own words in its place (`UploadRefused`). */\ntype Message = { readonly key: string; readonly error: boolean; readonly text?: string | undefined } | null;\n\n/** How long typing in the address pauses before the preview loads it: one request per address, not per keystroke. */\nexport const PREVIEW_DELAY_MS = 600;\n\n/**\n * `<astl-picture-dialog>`: asks for a picture in a modal dialog: a file, uploaded with the host's `uploadAsset`, one\n * from the host's library (`pickPicture`), or an address (the only way without either, as it says); the alt text,\n * required unless the picture is decorative (`alt=\"\"`); and, for a new picture, an optional caption. The address must\n * pass the authoring's URL policy, an uploaded or picked one too. `ask` resolves with the fields, or null when the\n * author cancels. While the library is open the dialog steps aside: it closes and keeps every field, so a modal of\n * the host's own, outside the top layer, takes the pointer and the keys; it opens again when the library settles.\n */\nexport class AstlPictureDialog extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n css`\n dialog {\n box-sizing: border-box;\n inline-size: min(32rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: calc(100dvh - 2 * var(--astl-space-4));\n padding: var(--astl-space-4);\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n color: var(--astl-ink);\n }\n dialog::backdrop {\n background: color-mix(in srgb, var(--astl-ink) 40%, transparent);\n }\n form {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n font-weight: 600;\n }\n label input {\n font-weight: 400;\n }\n label.check {\n flex-direction: row;\n align-items: center;\n min-block-size: var(--astl-target-min);\n font-weight: 400;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .sources {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .upload :is(.note, .error),\n .messages :is(.note, .error) {\n margin-block-start: var(--astl-space-2);\n }\n .preview {\n display: block;\n max-inline-size: 100%;\n max-block-size: 10rem;\n object-fit: contain;\n align-self: flex-start;\n border: var(--astl-outline-width) solid var(--astl-line);\n }\n .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .actions {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: var(--astl-space-2);\n }\n `,\n ];\n\n #resolve: ((fields: PictureFields | null) => void) | null = null;\n #editing = false;\n #withCaption = true;\n #altRequired = false;\n #target: { readonly tag: string; readonly attribute: string } = { tag: 'img', attribute: 'src' };\n #src = '';\n #alt = '';\n #decorative = false;\n #caption = '';\n #width: number | undefined;\n #height: number | undefined;\n /** What the last submit found wrong, shown by the buttons. */\n #message: Message = null;\n /** How the upload or the pick goes, shown by their buttons. */\n #uploadMessage: Message = null;\n /** An upload is under way: nothing is inserted before it ends. */\n #busy = false;\n /** The host's library is open: the dialog stepped aside for it, and its close is no cancel. */\n #picking = false;\n /** Bumped by every upload, pick, `ask` and close: an upload or a pick that ends after one is dropped. */\n #generation = 0;\n /** Aborts the upload or the pick under way (its `signal`). */\n #abort: AbortController | null = null;\n /** The address the preview shows: the current one, the uploaded one, or a typed one once typing pauses. */\n #preview = '';\n #previewTimer: ReturnType<typeof setTimeout> | undefined;\n\n /** Opens the dialog. Resolves with the picture's fields, or null when the author cancels. */\n async ask(request: PictureRequest = {}): Promise<PictureFields | null> {\n this.#finish(null);\n const current = request.current;\n this.#editing = current !== undefined;\n this.#withCaption = request.caption ?? !this.#editing;\n this.#altRequired = request.altRequired ?? false;\n this.#target = request.target ?? { tag: 'img', attribute: 'src' };\n this.#src = current?.src ?? '';\n this.#alt = current?.alt ?? '';\n this.#decorative = !this.#altRequired && (request.decorative ?? current?.alt === '');\n this.#caption = current?.caption ?? '';\n this.#width = current?.width;\n this.#height = current?.height;\n this.#preview = this.#src;\n this.#message = null;\n this.#uploadMessage = null;\n this.#stop();\n this.requestUpdate();\n await this.updateComplete;\n const result = new Promise<PictureFields | null>((resolve) => {\n this.#resolve = resolve;\n });\n this.#dialog()?.showModal();\n if (request.file !== undefined) void this.#upload(request.file);\n return result;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // Out of the document the dialog is out of the top layer, and a pick that ends later could not open it again.\n this.#finish(null);\n }\n\n #dialog(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n #finish(fields: PictureFields | null): void {\n const resolve = this.#resolve;\n this.#resolve = null;\n clearTimeout(this.#previewTimer);\n this.#stop();\n const dialog = this.#dialog();\n if (dialog?.open) dialog.close();\n resolve?.(fields);\n }\n\n /** Aborts the upload or the pick under way and drops its result. */\n #stop(): void {\n this.#abort?.abort();\n this.#abort = null;\n this.#generation++;\n this.#busy = false;\n this.#picking = false;\n }\n\n #allowed(src: string): boolean {\n const policy = this.authoring?.urlPolicy;\n return src.trim() !== '' && policy !== undefined && policy(src, this.#target);\n }\n\n /** Takes an uploaded or picked picture when the URL policy allows its address: the address, the preview, the size. */\n #take(asset: UploadedAsset): boolean {\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (!this.#allowed(src)) return false;\n this.#src = src;\n this.#preview = src;\n this.#width = pictureSize(asset.width);\n this.#height = pictureSize(asset.height);\n return true;\n }\n\n async #upload(file: File): Promise<void> {\n const upload = this.authoring?.uploadAsset ?? null;\n if (upload === null) return;\n this.#stop();\n const id = this.#generation;\n const abort = new AbortController();\n this.#abort = abort;\n this.#busy = true;\n this.#uploadMessage = { key: 'picture.uploading', error: false };\n this.requestUpdate();\n let message: Message;\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (id !== this.#generation) return;\n message = this.#take(asset)\n ? { key: 'picture.uploaded', error: false }\n : { key: 'picture.uploadBlocked', error: true };\n } catch (error) {\n if (id !== this.#generation) return;\n message = { key: 'picture.uploadFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n this.#busy = false;\n this.#uploadMessage = message;\n this.requestUpdate();\n }\n\n /**\n * Opens the host's library (`pickPicture`), stopping the upload under way. The dialog steps aside meanwhile: closed,\n * every field kept, so a modal of the host's own takes the pointer and the keys. When the library settles, the\n * dialog opens again with what it gave (unless the ask ended meanwhile), and the focus goes to the alt text after a\n * picture (to Insert or Save for a decorative one), else back to the library's button.\n */\n async #pick(): Promise<void> {\n const pick = this.authoring?.pickPicture ?? null;\n const dialog = this.#dialog();\n if (pick === null || dialog === null || !dialog.open) return;\n this.#stop();\n const id = this.#generation;\n const abort = new AbortController();\n this.#abort = abort;\n this.#picking = true;\n // What the buttons said was about an earlier upload or pick.\n this.#uploadMessage = null;\n dialog.close();\n let message: Message = null;\n let picked = false;\n try {\n const asset = await pick({ signal: abort.signal });\n if (id !== this.#generation) return;\n // Null: the author closed the library, and nothing changes.\n if (asset != null) {\n picked = this.#take(asset);\n message = picked\n ? { key: 'picture.picked', error: false }\n : { key: 'picture.pickBlocked', error: true };\n }\n } catch (error) {\n if (id !== this.#generation) return;\n message = { key: 'picture.pickFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n // The fields render before the dialog opens again; the message after, so its live region changes in sight.\n this.requestUpdate();\n await this.updateComplete;\n if (id !== this.#generation) return;\n // Gone with the authoring meanwhile: nothing to open again.\n const shown = this.#dialog();\n if (shown === null) {\n this.#finish(null);\n return;\n }\n this.#picking = false;\n shown.showModal();\n const next = picked ? (this.#decorative ? 'button[type=\"submit\"]' : '#alt') : '[data-library]';\n this.renderRoot.querySelector<HTMLElement>(next)?.focus();\n this.#uploadMessage = message;\n this.requestUpdate();\n }\n\n /** A polite status, or an alert for an error: both regions are always there, so screen readers hear the change. */\n #live(message: Message): TemplateResult {\n const said = message === null ? '' : (message.text ?? this.t(message.key));\n return html`<div role=\"status\">${message !== null && !message.error ? html`<p class=\"note\">${said}</p>` : nothing}</div>\n <div role=\"alert\">${message?.error ? html`<p class=\"error\">${said}</p>` : nothing}</div>`;\n }\n\n #submit(event: Event): void {\n event.preventDefault();\n if (this.#busy) return;\n const src = this.#src.trim();\n const alt = this.#alt.trim();\n if (src === '') this.#message = { key: 'picture.srcMissing', error: true };\n else if (!this.#allowed(src)) this.#message = { key: 'picture.srcBlocked', error: true };\n else if (!this.#decorative && alt === '') {\n this.#message = { key: this.#altRequired ? 'picture.altRequired' : 'picture.altMissing', error: true };\n } else {\n const caption = this.#withCaption ? this.#caption.trim() : '';\n this.#finish({\n src,\n alt: this.#decorative ? '' : alt,\n ...(this.#width === undefined ? {} : { width: this.#width }),\n ...(this.#height === undefined ? {} : { height: this.#height }),\n ...(caption === '' ? {} : { caption }),\n });\n return;\n }\n this.requestUpdate();\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const upload = this.authoring.uploadAsset !== null;\n const library = this.authoring.pickPicture !== null;\n const message = this.#message;\n return html`<dialog\n part=\"dialog\"\n lang=${lang}\n dir=${dir}\n aria-labelledby=\"picture-title\"\n @close=${() => {\n // Escape, or a close the page made. The event comes a task later: a dialog opened again since stays, and one\n // that stepped aside for the host's library still asks.\n if (!this.#picking && !this.#dialog()?.open) this.#finish(null);\n }}\n >\n <form @submit=${(event: Event) => this.#submit(event)} novalidate>\n <h2 class=\"title\" id=\"picture-title\">${this.t(this.#editing ? 'picture.editTitle' : 'picture.title')}</h2>\n ${\n upload || library\n ? html`<div class=\"upload\">\n <div class=\"sources\">\n ${\n upload\n ? html`<button\n type=\"button\"\n part=\"button\"\n ?disabled=${this.#busy}\n @click=${() => this.renderRoot.querySelector<HTMLInputElement>('input[type=\"file\"]')?.click()}\n >\n ${this.t('picture.file')}\n </button>`\n : nothing\n }\n ${\n library\n ? html`<button type=\"button\" part=\"button\" data-library @click=${() => void this.#pick()}>\n ${this.t('picture.library')}\n </button>`\n : nothing\n }\n </div>\n ${\n upload\n ? html`<input\n type=\"file\"\n accept=\"image/*\"\n hidden\n @change=${(event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n // Picking the same file again uploads it again.\n input.value = '';\n if (file !== undefined) void this.#upload(file);\n }}\n />`\n : nothing\n }\n ${this.#live(this.#uploadMessage)}\n </div>`\n : html`<p class=\"note\">${this.t('picture.urlOnly')}</p>`\n }\n <label>\n ${this.t('picture.src')}\n <input\n type=\"url\"\n inputmode=\"url\"\n autocomplete=\"off\"\n .value=${live(this.#src)}\n @input=${(event: Event) => {\n this.#src = (event.target as HTMLInputElement).value;\n this.#width = undefined;\n this.#height = undefined;\n clearTimeout(this.#previewTimer);\n this.#previewTimer = setTimeout(() => {\n this.#preview = this.#src.trim();\n this.requestUpdate();\n }, PREVIEW_DELAY_MS);\n }}\n />\n </label>\n ${\n this.#allowed(this.#preview)\n ? html`<img class=\"preview\" src=${this.#preview} alt=\"\" referrerpolicy=\"no-referrer\" />`\n : nothing\n }\n <label>\n ${this.t('picture.alt')}\n <input\n type=\"text\"\n id=\"alt\"\n aria-describedby=\"alt-help\"\n .value=${live(this.#alt)}\n ?disabled=${this.#decorative}\n @input=${(event: Event) => {\n this.#alt = (event.target as HTMLInputElement).value;\n }}\n />\n </label>\n <p class=\"note\" id=\"alt-help\">${this.t('picture.altHelp')}</p>\n ${\n this.#altRequired\n ? nothing\n : html`<label class=\"check\">\n <input\n type=\"checkbox\"\n .checked=${this.#decorative}\n @change=${(event: Event) => {\n this.#decorative = (event.target as HTMLInputElement).checked;\n this.requestUpdate();\n }}\n />\n ${this.t('picture.decorative')}\n </label>`\n }\n ${\n this.#withCaption\n ? html`<label>\n ${this.t('picture.caption')}\n <input\n type=\"text\"\n .value=${live(this.#caption)}\n @input=${(event: Event) => {\n this.#caption = (event.target as HTMLInputElement).value;\n }}\n />\n </label>`\n : nothing\n }\n <div class=\"messages\">${this.#live(message)}</div>\n <div class=\"actions\">\n <button type=\"button\" part=\"button\" @click=${() => this.#finish(null)}>${this.t('picture.cancel')}</button>\n <button type=\"submit\" class=\"primary\" part=\"button\" ?disabled=${this.#busy}>\n ${this.t(this.#editing ? 'picture.save' : 'picture.insert')}\n </button>\n </div>\n </form>\n </dialog>`;\n }\n}\n","import type { MessageParams } from '@astl/core';\nimport { PALETTE } from '@astl/tokens';\nimport {\n type CSSResultGroup,\n css,\n html,\n LitElement,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type SVGTemplateResult,\n svg,\n type TemplateResult,\n} from 'lit';\nimport { type Authoring, refusalOf, type UploadedAsset } from '../authoring.js';\nimport type { InspectorChange } from '../edit.js';\nimport type {\n PicturePointModel,\n PicturePointsFieldModel,\n PictureRegionModel,\n PictureRegionsFieldModel,\n} from '../inspect.js';\nimport { EDITOR_NAMESPACE } from '../messages.js';\nimport { kitStyles } from './styles.js';\n\n/** Fired with a FieldChange for the inspector to apply. */\nexport const FIELD_CHANGE = 'astl-field-change';\n\n/** A change of the field, and the source id of the element it is for (an upload may end after the cursor moved). */\nexport interface FieldChange {\n readonly change: InspectorChange;\n readonly element: string | null;\n}\n\ntype Field = PictureRegionsFieldModel | PicturePointsFieldModel;\ntype Shape = PictureRegionModel['shape'];\n/** What the field says of its upload or pick: a key of the kit's catalog, or a host's own words (`UploadRefused`). */\ntype Status = { readonly key: string; readonly error: boolean; readonly text?: string | undefined };\n\nconst round = (n: number) => Math.round(Math.min(100, Math.max(0, n)) * 10) / 10;\nconst num = (n: number) => String(round(n));\n/** Most zones, pins or polygon points the field lists (and polygons take): more are edited in the source. */\nconst MAX_LISTED = 64;\n/** Palette slot of the n-th item (from 0), as a class: `c1` to `c8`. */\nconst slot = (index: number) => `c${(index % PALETTE.length) + 1}`;\n\n/** The attributes that describe a zone of `shape` around the zone's centre: switching the shape keeps the centre. */\nfunction reshaped(region: PictureRegionModel, shape: Shape): Record<string, string | null> {\n const box = boundsOf(region);\n const cx = (box.left + box.right) / 2;\n const cy = (box.top + box.bottom) / 2;\n const w = Math.max(1, box.right - box.left);\n const h = Math.max(1, box.bottom - box.top);\n const cleared = { x: null, y: null, width: null, height: null, r: null, points: null };\n if (shape === 'circle') return { ...cleared, shape, x: num(cx), y: num(cy), r: num(w / 2) };\n if (shape === 'polygon') {\n const points = [\n [box.left, box.top],\n [box.right, box.top],\n [box.right, box.bottom],\n [box.left, box.bottom],\n ];\n return { ...cleared, shape, points: points.map(([x = 0, y = 0]) => `${num(x)},${num(y)}`).join(' ') };\n }\n return { ...cleared, shape, x: num(cx - w / 2), y: num(cy - h / 2), width: num(w), height: num(h) };\n}\n\n/** A zone's bounding box in percent. */\nfunction boundsOf(region: PictureRegionModel): { left: number; top: number; right: number; bottom: number } {\n if (region.shape === 'circle') {\n return {\n left: region.x - region.r,\n top: region.y - region.r,\n right: region.x + region.r,\n bottom: region.y + region.r,\n };\n }\n if (region.shape === 'polygon' && region.points.length > 0) {\n // A loop, not Math.min(...xs): a polygon of any size never overflows the call stack.\n const box = { left: 100, top: 100, right: 0, bottom: 0 };\n for (const [x, y] of region.points) {\n box.left = Math.min(box.left, x);\n box.top = Math.min(box.top, y);\n box.right = Math.max(box.right, x);\n box.bottom = Math.max(box.bottom, y);\n }\n return box;\n }\n return { left: region.x, top: region.y, right: region.x + region.width, bottom: region.y + region.height };\n}\n\n/** Where a zone's number sits: its centre. */\nfunction anchorOf(region: PictureRegionModel): readonly [number, number] {\n const box = boundsOf(region);\n return [(box.left + box.right) / 2, (box.top + box.bottom) / 2];\n}\n\n/**\n * `<astl-picture-field>`: the inspector's `picture-regions` and `picture-points` fields. The picture (by address,\n * uploaded with the host's `uploadAsset` or chosen from its library, `pickPicture`) with its zones or pins drawn on\n * it in palette colours and numbered; drag on it to draw a zone, click to place a pin; and every value in number\n * fields, so nothing needs a pointer. Changes go to the inspector as `astl-field-change` events.\n */\nexport class AstlPictureField extends LitElement {\n static override properties: PropertyDeclarations = {\n field: { attribute: false },\n authoring: { attribute: false },\n element: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n css`\n fieldset {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n min-inline-size: 0;\n margin: 0;\n padding: var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n legend {\n padding-inline: var(--astl-space-1);\n font-weight: 600;\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n }\n .canvas {\n position: relative;\n inline-size: 100%;\n touch-action: none;\n cursor: crosshair;\n user-select: none;\n border: var(--astl-outline-width) solid var(--astl-line);\n background: var(--astl-surface-raised);\n }\n .canvas img {\n display: block;\n inline-size: 100%;\n block-size: auto;\n }\n .canvas .blank {\n aspect-ratio: 4 / 3;\n }\n .canvas svg {\n position: absolute;\n inset: 0;\n inline-size: 100%;\n block-size: 100%;\n overflow: visible;\n }\n .shape {\n fill: var(--soft);\n fill-opacity: 0.4;\n stroke: var(--line);\n stroke-width: 2;\n vector-effect: non-scaling-stroke;\n }\n .shape.unflagged {\n fill-opacity: 0.15;\n stroke-dasharray: 6 4;\n }\n .draft {\n fill: none;\n stroke: var(--astl-ink);\n stroke-width: 2;\n stroke-dasharray: 4 3;\n vector-effect: non-scaling-stroke;\n }\n .badge {\n position: absolute;\n inset-inline-start: var(--x);\n inset-block-start: var(--y);\n transform: translate(-50%, -50%);\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n min-inline-size: 1.5rem;\n block-size: 1.5rem;\n padding-inline: var(--astl-space-1);\n border: var(--astl-outline-width) solid var(--line);\n border-radius: 999px;\n background: var(--astl-surface);\n color: var(--astl-ink);\n font-size: var(--astl-size-small);\n font-weight: 700;\n pointer-events: none;\n }\n .pin {\n border-width: calc(2 * var(--astl-outline-width));\n }\n .swatch {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-inline-size: 1.5rem;\n block-size: 1.5rem;\n margin-inline-end: var(--astl-space-2);\n border: calc(2 * var(--astl-outline-width)) solid var(--line);\n border-radius: 999px;\n background: var(--soft);\n font-weight: 700;\n }\n .items {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n .numbers {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));\n gap: var(--astl-space-2);\n }\n .numbers label {\n justify-content: flex-end;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .upload :is(.note, .error) {\n margin-block-start: var(--astl-space-2);\n }\n .sources {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .error {\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .vertex {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n gap: var(--astl-space-2);\n }\n .vertex label {\n flex: 1 1 6rem;\n }\n .c1 { --line: var(--astl-palette-1); --soft: var(--astl-palette-1-soft); }\n .c2 { --line: var(--astl-palette-2); --soft: var(--astl-palette-2-soft); }\n .c3 { --line: var(--astl-palette-3); --soft: var(--astl-palette-3-soft); }\n .c4 { --line: var(--astl-palette-4); --soft: var(--astl-palette-4-soft); }\n .c5 { --line: var(--astl-palette-5); --soft: var(--astl-palette-5-soft); }\n .c6 { --line: var(--astl-palette-6); --soft: var(--astl-palette-6-soft); }\n .c7 { --line: var(--astl-palette-7); --soft: var(--astl-palette-7-soft); }\n .c8 { --line: var(--astl-palette-8); --soft: var(--astl-palette-8-soft); }\n @media (forced-colors: active) {\n .shape {\n fill: none;\n stroke: CanvasText;\n }\n .badge,\n .swatch {\n border-color: CanvasText;\n }\n }\n `,\n ];\n\n declare field: Field | null;\n declare authoring: Authoring | null;\n /** The source id of the element the field belongs to (the inspector sets it). */\n declare element: string | null;\n\n /** A zone being drawn: where the pointer went down and where it is, in percent. */\n #draft: { readonly x0: number; readonly y0: number; x1: number; y1: number } | null = null;\n /** Width over height of the picture (1 until it loads), so circles stay round. */\n #aspect = 1;\n #status: Status | null = null;\n /** Aborts the upload or the pick under way (its `signal`). */\n #abort: AbortController | null = null;\n\n constructor() {\n super();\n this.field = null;\n this.authoring = null;\n this.element = null;\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n // Another element's field: an upload message was about the one before.\n if (changed.has('element') && changed.get('element') !== undefined) this.#status = null;\n }\n\n #t(key: string, params?: MessageParams): string {\n return this.authoring?.t(EDITOR_NAMESPACE, key, params) ?? key;\n }\n\n #change(change: InspectorChange, element: string | null = this.element): void {\n this.dispatchEvent(new CustomEvent<FieldChange>(FIELD_CHANGE, { detail: { change, element } }));\n }\n\n /** Whether the URL policy allows the picture, asked as the engine and the player ask it: the element's attribute. */\n #allowed(field: Field, src: string): boolean {\n const context = { tag: field.elementTag, attribute: field.srcAttribute };\n return src.trim() !== '' && (this.authoring?.urlPolicy(src, context) ?? false);\n }\n\n /** A fresh local id for a new child: `<tag without astl->-<n>`. */\n #freshId(field: Field): string {\n const taken = new Set(\n field.kind === 'picture-points' ? field.points.map((p) => p.id) : field.regions.map((r) => r.id),\n );\n const prefix = field.tag.replace(/^astl-/, '');\n let n = 1;\n while (taken.has(`${prefix}-${n}`)) n++;\n return `${prefix}-${n}`;\n }\n\n #add(field: Field, at?: { x: number; y: number; width?: number; height?: number }): void {\n const id = this.#freshId(field);\n if (field.kind === 'picture-points') {\n const label = this.#t('field.point', { n: field.points.length + 1 });\n this.#change({\n kind: 'child-add',\n tag: field.tag,\n attributes: { id, x: num(at?.x ?? 50), y: num(at?.y ?? 50), label },\n });\n return;\n }\n const width = at?.width ?? 20;\n const height = at?.height ?? 20;\n const x = at === undefined ? 10 : at.x;\n const y = at === undefined ? 10 : at.y;\n // A zone that takes no other shape is written without one.\n const shape: Record<string, string> = field.shapes.length > 1 ? { shape: 'rect' } : {};\n this.#change({\n kind: 'child-add',\n tag: field.tag,\n attributes: { id, ...shape, x: num(x), y: num(y), width: num(width), height: num(height) },\n });\n }\n\n /** Writes the address of an uploaded or picked picture into the field's attribute of `element`, if the policy allows. */\n #write(field: Field, asset: UploadedAsset, element: string | null): boolean {\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (!this.#allowed(field, src)) return false;\n this.#change({ kind: 'attribute', name: field.srcAttribute, value: src }, element);\n return true;\n }\n\n async #upload(field: Field, file: File): Promise<void> {\n const upload = this.authoring?.uploadAsset ?? null;\n if (upload === null) return;\n // The address goes to the element of this field, wherever the cursor is when the upload ends.\n const element = this.element;\n // Another upload or pick replaces this upload.\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n this.#status = { key: 'picture.uploading', error: false };\n this.requestUpdate();\n let status: Status;\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (abort.signal.aborted) return;\n status = this.#write(field, asset, element)\n ? { key: 'picture.uploaded', error: false }\n : { key: 'picture.uploadBlocked', error: true };\n } catch (error) {\n if (abort.signal.aborted) return;\n status = { key: 'picture.uploadFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n // Said where it happened only: the field may show another element by now.\n this.#status = this.element === element ? status : null;\n this.requestUpdate();\n }\n\n /** Opens the host's library (`pickPicture`) and writes the address it gives, as an upload does. */\n async #pick(field: Field): Promise<void> {\n const pick = this.authoring?.pickPicture ?? null;\n if (pick === null) return;\n const element = this.element;\n // Another upload or pick replaces this pick.\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n // What the field said was about an earlier upload or pick.\n this.#status = null;\n this.requestUpdate();\n let status: Status | null = null;\n try {\n const asset = await pick({ signal: abort.signal });\n if (abort.signal.aborted) return;\n // Null: the author closed the library, and nothing changes.\n if (asset != null) {\n status = this.#write(field, asset, element)\n ? { key: 'picture.picked', error: false }\n : { key: 'picture.pickBlocked', error: true };\n }\n } catch (error) {\n if (abort.signal.aborted) return;\n status = { key: 'picture.pickFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n this.#status = this.element === element ? status : null;\n this.requestUpdate();\n // The focus goes back to the library's button, as the dialog gives it back: a host's modal restoring its own\n // cannot see into this shadow root, and the author's place would be lost.\n await this.updateComplete;\n if (this.isConnected) this.renderRoot.querySelector<HTMLElement>('[data-library]')?.focus();\n }\n\n /** Pointer position in percent of the picture: the canvas inside its border. */\n #at(event: PointerEvent): { x: number; y: number } {\n const canvas = event.currentTarget as HTMLElement;\n const box = canvas.getBoundingClientRect();\n return {\n x: round(((event.clientX - box.left - canvas.clientLeft) / Math.max(1, canvas.clientWidth)) * 100),\n y: round(((event.clientY - box.top - canvas.clientTop) / Math.max(1, canvas.clientHeight)) * 100),\n };\n }\n\n #down(event: PointerEvent): void {\n if (event.button !== 0) return;\n const { x, y } = this.#at(event);\n (event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId);\n this.#draft = { x0: x, y0: y, x1: x, y1: y };\n }\n\n #move(event: PointerEvent): void {\n if (this.#draft === null) return;\n const { x, y } = this.#at(event);\n this.#draft.x1 = x;\n this.#draft.y1 = y;\n this.requestUpdate();\n }\n\n #up(field: Field, event: PointerEvent): void {\n const draft = this.#draft;\n this.#draft = null;\n if (draft === null) return;\n const { x, y } = this.#at(event);\n if (field.kind === 'picture-points') {\n this.#add(field, { x, y });\n return;\n }\n const width = Math.abs(x - draft.x0);\n const height = Math.abs(y - draft.y0);\n // A click without a drag: a small zone around it.\n if (width < 2 && height < 2)\n this.#add(field, { x: draft.x0 - 5, y: draft.y0 - 5, width: 10, height: 10 });\n else this.#add(field, { x: Math.min(x, draft.x0), y: Math.min(y, draft.y0), width, height });\n this.requestUpdate();\n }\n\n /** A zone in its palette colour: solid, or dashed without the field's flag (a wrong place among right ones). */\n #shape(field: PictureRegionsFieldModel, region: PictureRegionModel): SVGTemplateResult {\n const unflagged = field.flag !== null && !region.flagged;\n const cls = `shape ${slot(region.index)}${unflagged ? ' unflagged' : ''}`;\n if (region.shape === 'circle') {\n return svg`<ellipse class=${cls} cx=${region.x} cy=${region.y} rx=${region.r} ry=${region.r * this.#aspect}></ellipse>`;\n }\n if (region.shape === 'polygon') {\n return svg`<polygon class=${cls} points=${region.points.map(([x, y]) => `${x},${y}`).join(' ')}></polygon>`;\n }\n return svg`<rect class=${cls} x=${region.x} y=${region.y} width=${region.width} height=${region.height}></rect>`;\n }\n\n #badge(index: number, [x, y]: readonly [number, number], pin: boolean): TemplateResult {\n return html`<span\n class=\"badge ${pin ? 'pin ' : ''}${slot(index)}\"\n aria-hidden=\"true\"\n data-x=${x}\n data-y=${y}\n >${index + 1}</span\n >`;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n // Badges are placed through the CSSOM: a strict Content Security Policy blocks a style attribute, which Lit's\n // styleMap writes on its first render.\n for (const badge of this.renderRoot.querySelectorAll<HTMLElement>('.badge')) {\n badge.style.setProperty('--x', `${badge.dataset.x}%`);\n badge.style.setProperty('--y', `${badge.dataset.y}%`);\n }\n }\n\n #canvas(field: Field): TemplateResult {\n const draft = this.#draft;\n const shown = this.#allowed(field, field.src);\n const shapes = field.kind === 'picture-regions' ? field.regions.map((r) => this.#shape(field, r)) : [];\n const badges =\n field.kind === 'picture-regions'\n ? field.regions.map((r) => this.#badge(r.index, anchorOf(r), false))\n : field.points.map((p) => this.#badge(p.index, [p.x, p.y], true));\n return html`<div\n class=\"canvas\"\n dir=\"ltr\"\n @pointerdown=${(event: PointerEvent) => this.#down(event)}\n @pointermove=${(event: PointerEvent) => this.#move(event)}\n @pointerup=${(event: PointerEvent) => this.#up(field, event)}\n @pointercancel=${() => {\n this.#draft = null;\n this.requestUpdate();\n }}\n >\n ${\n shown\n ? html`<img\n src=${field.src}\n alt=\"\"\n referrerpolicy=\"no-referrer\"\n draggable=\"false\"\n @load=${(event: Event) => {\n const img = event.target as HTMLImageElement;\n if (img.naturalHeight > 0) this.#aspect = img.naturalWidth / img.naturalHeight;\n this.requestUpdate();\n }}\n />`\n : html`<div class=\"blank\"></div>`\n }\n <svg viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" aria-hidden=\"true\" focusable=\"false\">\n ${shapes}\n ${\n draft === null || field.kind === 'picture-points'\n ? nothing\n : svg`<rect class=\"draft\" x=${Math.min(draft.x0, draft.x1)} y=${Math.min(draft.y0, draft.y1)}\n width=${Math.abs(draft.x1 - draft.x0)} height=${Math.abs(draft.y1 - draft.y0)}></rect>`\n }\n </svg>\n ${badges}\n </div>`;\n }\n\n /** Says that only the first items are listed, when there are more. */\n #more(count: number): TemplateResult | typeof nothing {\n return count > MAX_LISTED\n ? html`<p class=\"note\">${this.#t('field.more', { shown: MAX_LISTED, count })}</p>`\n : nothing;\n }\n\n #number(label: string, value: number, commit: (value: string) => void): TemplateResult {\n return html`<label>\n ${label}\n <input\n type=\"number\"\n min=\"0\"\n max=\"100\"\n step=\"0.1\"\n .value=${num(value)}\n @change=${(event: Event) => {\n const raw = (event.target as HTMLInputElement).value;\n if (raw !== '' && Number.isFinite(Number(raw))) commit(num(Number(raw)));\n }}\n />\n </label>`;\n }\n\n #labelField(field: Field, index: number, value: string): TemplateResult {\n const optional = field.kind === 'picture-regions';\n return html`<label>\n ${this.#t(optional ? 'field.label.optional' : 'field.label')}\n <input\n type=\"text\"\n dir=\"auto\"\n .value=${value}\n @change=${(event: Event) => {\n const text = (event.target as HTMLInputElement).value.trim();\n this.#change({\n kind: 'child-attributes',\n tag: field.tag,\n index,\n attributes: { label: text === '' && optional ? null : text },\n });\n }}\n />\n </label>`;\n }\n\n #region(field: PictureRegionsFieldModel, region: PictureRegionModel): TemplateResult {\n const n = region.index + 1;\n const set = (attributes: Record<string, string | null>) =>\n this.#change({ kind: 'child-attributes', tag: field.tag, index: region.index, attributes });\n const points = region.points;\n const setPoints = (next: readonly (readonly [number, number])[]) =>\n set({ points: next.map(([x, y]) => `${num(x)},${num(y)}`).join(' ') });\n const numbers =\n region.shape === 'circle'\n ? [\n this.#number(this.#t('field.cx'), region.x, (x) => set({ x })),\n this.#number(this.#t('field.cy'), region.y, (y) => set({ y })),\n this.#number(this.#t('field.r'), region.r, (r) => set({ r })),\n ]\n : region.shape === 'rect'\n ? [\n this.#number(this.#t('field.x'), region.x, (x) => set({ x })),\n this.#number(this.#t('field.y'), region.y, (y) => set({ y })),\n this.#number(this.#t('field.width'), region.width, (width) => set({ width })),\n this.#number(this.#t('field.height'), region.height, (height) => set({ height })),\n ]\n : [];\n return html`<li data-index=${region.index}>\n <fieldset>\n <legend><span class=\"swatch ${slot(region.index)}\" aria-hidden=\"true\">${n}</span>${this.#t('field.region', { n })}</legend>\n ${\n // Only zones that take more than one shape choose theirs.\n field.shapes.length > 1\n ? html`<label>\n ${this.#t('field.shape')}\n <select\n @change=${(event: Event) => set(reshaped(region, (event.target as HTMLSelectElement).value as Shape))}\n >\n ${field.shapes.map(\n (shape) =>\n html`<option value=${shape} ?selected=${shape === region.shape}>${this.#t(`field.shape.${shape}`)}</option>`,\n )}\n </select>\n </label>`\n : nothing\n }\n ${numbers.length > 0 ? html`<div class=\"numbers\">${numbers}</div>` : nothing}\n ${\n region.shape === 'polygon'\n ? html`<ol class=\"items\">\n ${points.slice(0, MAX_LISTED).map(\n ([x, y], k) => html`<li class=\"vertex\">\n ${this.#number(this.#t('field.vertex.x', { n: k + 1 }), x, (value) =>\n setPoints(points.map((p, j) => (j === k ? [Number(value), p[1]] : p))),\n )}\n ${this.#number(this.#t('field.vertex.y', { n: k + 1 }), y, (value) =>\n setPoints(points.map((p, j) => (j === k ? [p[0], Number(value)] : p))),\n )}\n <button\n type=\"button\"\n ?disabled=${points.length <= 3}\n @click=${() => setPoints(points.filter((_, j) => j !== k))}\n >\n ${this.#t('field.vertex.remove', { n: k + 1 })}\n </button>\n </li>`,\n )}\n </ol>\n ${this.#more(points.length)}\n <button\n type=\"button\"\n ?disabled=${points.length >= MAX_LISTED}\n @click=${() => {\n const [lx, ly] = points[points.length - 1] ?? [50, 50];\n setPoints([...points, [round(lx + 5), round(ly + 5)]]);\n }}\n >\n ${this.#t('field.vertex.add')}\n </button>`\n : nothing\n }\n ${this.#labelField(field, region.index, region.label)}\n <button type=\"button\" @click=${() => this.#change({ kind: 'child-remove', tag: field.tag, index: region.index })}>\n ${this.#t('field.region.remove', { n })}\n </button>\n </fieldset>\n </li>`;\n }\n\n #point(field: PicturePointsFieldModel, point: PicturePointModel): TemplateResult {\n const n = point.index + 1;\n const set = (attributes: Record<string, string | null>) =>\n this.#change({ kind: 'child-attributes', tag: field.tag, index: point.index, attributes });\n return html`<li data-index=${point.index}>\n <fieldset>\n <legend><span class=\"swatch ${slot(point.index)}\" aria-hidden=\"true\">${n}</span>${this.#t('field.point', { n })}</legend>\n <div class=\"numbers\">\n ${this.#number(this.#t('field.x'), point.x, (x) => set({ x }))}\n ${this.#number(this.#t('field.y'), point.y, (y) => set({ y }))}\n </div>\n ${this.#labelField(field, point.index, point.label)}\n <button type=\"button\" @click=${() => this.#change({ kind: 'child-remove', tag: field.tag, index: point.index })}>\n ${this.#t('field.point.remove', { n })}\n </button>\n </fieldset>\n </li>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const field = this.field;\n if (field === null || this.authoring === null) return nothing;\n const regions = field.kind === 'picture-regions';\n const upload = this.authoring.uploadAsset !== null;\n const library = this.authoring.pickPicture !== null;\n const status = this.#status;\n const said = status === null ? '' : (status.text ?? this.#t(status.key));\n return html`<fieldset data-tag=${field.tag}>\n <legend>${field.label}</legend>\n ${field.help === null ? nothing : html`<p class=\"note\">${field.help}</p>`}\n <label>\n ${this.#t('field.picture.src')}\n <input\n type=\"url\"\n autocomplete=\"off\"\n .value=${field.src}\n @change=${(event: Event) => {\n const value = (event.target as HTMLInputElement).value.trim();\n this.#change({ kind: 'attribute', name: field.srcAttribute, value: value === '' ? null : value });\n }}\n />\n </label>\n ${\n upload || library\n ? html`<div class=\"upload\">\n <div class=\"sources\">\n ${\n upload\n ? html`<button\n type=\"button\"\n @click=${() => this.renderRoot.querySelector<HTMLInputElement>('input[type=\"file\"]')?.click()}\n >\n ${this.#t('picture.file')}\n </button>`\n : nothing\n }\n ${\n library\n ? html`<button type=\"button\" data-library @click=${() => void this.#pick(field)}>\n ${this.#t('picture.library')}\n </button>`\n : nothing\n }\n </div>\n ${\n upload\n ? html`<input\n type=\"file\"\n accept=\"image/*\"\n hidden\n @change=${(event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n input.value = '';\n if (file !== undefined) void this.#upload(field, file);\n }}\n />`\n : nothing\n }\n <div role=\"status\">${status !== null && !status.error ? html`<p class=\"note\">${said}</p>` : nothing}</div>\n <div role=\"alert\">${status?.error ? html`<p class=\"error\">${said}</p>` : nothing}</div>\n </div>`\n : html`<p class=\"note\">${this.#t('picture.urlOnly')}</p>`\n }\n ${this.#canvas(field)}\n <p class=\"note\">${this.#t(regions ? 'field.regions.draw' : 'field.points.place')}</p>\n <ol class=\"items\">\n ${\n regions\n ? field.regions.slice(0, MAX_LISTED).map((r) => this.#region(field, r))\n : field.points.slice(0, MAX_LISTED).map((p) => this.#point(field, p))\n }\n </ol>\n ${this.#more(regions ? field.regions.length : field.points.length)}\n <button type=\"button\" data-add @click=${() => this.#add(field)}>\n ${this.#t(regions ? 'field.region.add' : 'field.point.add')}\n </button>\n </fieldset>`;\n }\n}\n","import { type AttemptPolicy, type Issue, isSafeUrl, PlayerEvent, PRACTICE_POLICY } from '@astl/core';\nimport { type AstlPlayer, definePlayer } from '@astl/player';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n} from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { AuthoringElement } from './base.js';\nimport { issueStyles, renderIssues } from './issue-list.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\ntype PreviewState = 'idle' | 'loading' | 'ready' | 'invalid' | 'failed';\n\n/** Authorings whose elements are already registered with the player. */\nconst registered = new WeakSet<Authoring>();\n\n/**\n * `<astl-preview>`: a button that compiles the current source with a throw-away salt and plays it in `<astl-player>`\n * with local grading and the authoring's style templates, the way a student sees it, under `policy`. Invalid sources\n * show their errors instead. Tokens set on the preview reach the player; the player's events stay inside.\n */\nexport class AstlPreview extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n policy: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n issueStyles,\n inheritTokens('astl-player'),\n css`\n .bar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: space-between;\n gap: var(--astl-space-2) var(--astl-space-3);\n }\n astl-player {\n border-radius: var(--astl-radius-m);\n overflow: hidden;\n }\n astl-player[hidden] {\n display: none;\n }\n `,\n ];\n\n /**\n * The policy the preview plays and grades under, the one the host's students get (default `PRACTICE_POLICY`). A\n * change plays the preview again, once it has been shown.\n */\n declare policy: AttemptPolicy;\n\n #state: PreviewState = 'idle';\n #issues: readonly Issue[] = [];\n /** The source the issues are about. */\n #source = '';\n #stale = false;\n #generation = 0;\n\n constructor() {\n super();\n this.policy = PRACTICE_POLICY;\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n // A preview attempt is not a student's: its player events (results, answers, state) never reach the host page.\n for (const type of Object.values(PlayerEvent))\n root.addEventListener(type, (event) => event.stopPropagation());\n return root;\n }\n\n /** `idle`, `loading`, `ready`, `invalid` (errors shown) or `failed`. */\n get state(): PreviewState {\n return this.#state;\n }\n\n /** The player, once the first preview started. */\n get player(): AstlPlayer | null {\n return this.renderRoot?.querySelector<AstlPlayer>('astl-player') ?? null;\n }\n\n /** Compiles the current source and plays it. Resolves when the player is ready or the errors are shown. */\n async refresh(): Promise<void> {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return;\n const generation = ++this.#generation;\n this.#stale = false;\n try {\n if (!registered.has(authoring)) {\n definePlayer({\n elements: authoring.elements,\n styleTemplates: authoring.styleTemplates,\n // The page's players share one policy: the default never replaces one a host set for its students.\n ...(authoring.urlPolicy === isSafeUrl ? {} : { urlPolicy: authoring.urlPolicy }),\n });\n registered.add(authoring);\n }\n this.#set('loading');\n const source = adapter.getSource();\n const { policy } = this;\n const result = await authoring.preview(source, { policy });\n if (generation !== this.#generation) return;\n if (!result.ok) {\n this.#issues = result.issues.filter((i) => i.severity === 'error');\n this.#source = source;\n this.#set('invalid');\n await this.updateComplete;\n return;\n }\n await this.updateComplete;\n const player = this.player;\n if (player === null) throw new Error('astl-player is not rendered');\n await player.load({\n view: result.view,\n checker: result.checker,\n policy,\n snapshot: null,\n });\n if (generation === this.#generation) this.#set('ready');\n } catch {\n if (generation === this.#generation) this.#set('failed');\n }\n await this.updateComplete;\n }\n\n #set(state: PreviewState): void {\n this.#state = state;\n this.requestUpdate();\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n if (changed.has('policy') && changed.get('policy') !== undefined && this.#state !== 'idle')\n void this.refresh();\n }\n\n protected override sourceChanged(): void {\n if (this.#state === 'idle' || this.#stale) return;\n this.#stale = true;\n this.requestUpdate();\n }\n\n protected override selectionChanged(): void {\n // The preview does not depend on the cursor.\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n const state = this.#state;\n const { lang, dir } = this.ui;\n let message: TemplateResult | typeof nothing = nothing;\n if (state === 'idle') message = html`<p class=\"note\">${this.t('preview.hint')}</p>`;\n else if (state === 'loading') message = html`<p class=\"note\">${this.t('preview.loading')}</p>`;\n else if (state === 'failed') message = html`<p class=\"note\">${this.t('preview.failed')}</p>`;\n else if (state === 'invalid') {\n message = html`<p class=\"note\">${this.t('preview.invalid', { count: this.#issues.length })}</p>\n ${renderIssues(this.#issues, authoring, adapter, this.#source)}`;\n }\n const theme = this.getAttribute('data-theme') ?? 'light';\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"title\">\n <div class=\"bar\">\n <h2 class=\"title\" id=\"title\" part=\"title\">${this.t('preview.title')}</h2>\n <button type=\"button\" class=\"primary\" part=\"button\" ?disabled=${adapter === null} @click=${() => this.refresh()}>\n ${this.t(state === 'idle' ? 'preview.show' : 'preview.refresh')}\n </button>\n </div>\n <div role=\"status\">${this.#stale ? html`<p class=\"note\">${this.t('preview.stale')}</p>` : nothing}</div>\n ${message}\n ${\n state === 'idle'\n ? nothing\n : html`<astl-player part=\"player\" locale=${authoring.locale} theme=${theme} ?hidden=${state !== 'ready'}></astl-player>`\n }\n </section>`;\n }\n}\n","import type {\n EditorAdapter,\n EditorFormat,\n EditorFormatState,\n EditorStyleChanges,\n EditorStyleRule,\n EditorStyleState,\n EditorStyleTarget,\n EditorStyleTargetKind,\n} from '@astl/core';\nimport { RovingFocus } from '@astl/player/interaction';\nimport {\n type CSSResult,\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 { styleMapOf } from '../style-model.js';\nimport { AuthoringElement } from './base.js';\nimport { type AstlInsertMenu, GLYPHS, type Glyph, type InsertGroup, TYPE_GLYPHS } from './insert-menu.js';\nimport { loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';\nimport type { StylePopup } from './style-popups.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** Kit items a host can feature besides component tags (`tag`) and starters (`tag:template`). */\nexport const FEATURED_ITEMS: readonly string[] = ['text', 'picture', 'page-break'];\n\nconst ICONS = {\n bold: svg`<path d=\"M6 4h5a3 3 0 0 1 0 6H6zm0 6h6a3 3 0 0 1 0 6H6z\" stroke-width=\"2\"/>`,\n italic: svg`<path d=\"M9 4h7M4 16h7M12.5 4l-5 12\"/>`,\n underline: svg`<path d=\"M6 3v6a4 4 0 0 0 8 0V3M5 17h10\"/>`,\n link: svg`<path d=\"M8.5 11.5l3-3M7.5 9.5l-2 2a2.8 2.8 0 0 0 4 4l2-2M12.5 10.5l2-2a2.8 2.8 0 0 0-4-4l-2 2\"/>`,\n bulleted: svg`<path d=\"M8 5h9M8 10h9M8 15h9\"/><circle cx=\"4\" cy=\"5\" r=\"1.3\"/><circle cx=\"4\" cy=\"10\" r=\"1.3\"/><circle cx=\"4\" cy=\"15\" r=\"1.3\"/>`,\n numbered: svg`<path d=\"M9 5h8M9 10h8M9 15h8M3 3.5h1.5V8M2.5 12.2c.4-.8 2.5-.9 2.5.4 0 1-2.5 2-2.5 3.4H5\" stroke-width=\"1.5\"/>`,\n undo: svg`<path d=\"M7.5 5L4 8.5 7.5 12M4 8.5h8a4 4 0 0 1 0 8H9\"/>`,\n redo: svg`<path d=\"M12.5 5L16 8.5 12.5 12M16 8.5H8a4 4 0 0 0 0 8h3\"/>`,\n text: svg`<path d=\"M4 5V4h12v1M10 4v12M7.5 16h5\"/>`,\n add: svg`<path d=\"M10 4v12M4 10h12\"/>`,\n layouts: GLYPHS.columns,\n templates: svg`<rect x=\"3\" y=\"3\" width=\"14\" height=\"14\" rx=\"1.5\"/><path d=\"M3 8h14M8 8v9\"/>`,\n wrap: svg`<path d=\"M3 6h14M3 10h6M11 10h6M3 14h14\" stroke-width=\"1.6\"/><rect x=\"8\" y=\"8\" width=\"4\" height=\"4\" rx=\"1\" stroke-width=\"1.4\"/>`,\n chevron: svg`<path d=\"M6 8l4 4 4-4\"/>`,\n color: svg`<path d=\"M5.5 13L10 3l4.5 10M7 10h6\" stroke-width=\"1.8\"/>`,\n highlight: svg`<path d=\"M12.5 3.5l4 4-7.5 7.5H5v-4zM3.5 16.5h6\" stroke-width=\"1.6\"/>`,\n 'align-start': svg`<path d=\"M3.5 5h13M3.5 9h8M3.5 13h13M3.5 17h8\"/>`,\n 'align-center': svg`<path d=\"M3.5 5h13M6 9h8M3.5 13h13M6 17h8\"/>`,\n 'align-end': svg`<path d=\"M3.5 5h13M8.5 9h8M3.5 13h13M8.5 17h8\"/>`,\n 'align-justify': svg`<path d=\"M3.5 5h13M3.5 9h13M3.5 13h13M3.5 17h13\"/>`,\n spacing: svg`<path d=\"M9 5h8M9 10h8M9 15h8M4.5 4v12M2.5 6l2-2 2 2M2.5 14l2 2 2-2\"/>`,\n clear: svg`<path d=\"M5 5V4h10v1M10 4l-1.5 7M4 16h7M13 11.5l4 4M17 11.5l-4 4\"/>`,\n} satisfies Readonly<Record<string, SVGTemplateResult>>;\n\n/** The formats with a button of their own (the text styles are in a menu). */\ntype Toggle = 'bold' | 'italic' | 'underline' | 'link' | 'bulleted' | 'numbered';\n\nconst STYLES: readonly EditorFormat[] = ['paragraph', 'heading', 'subheading'];\nconst ELEMENT_GROUPS: readonly InsertGroup[] = ['components', 'content'];\nconst TEMPLATE_GROUPS: readonly InsertGroup[] = ['exercises'];\nconst LAYOUT_GROUPS: readonly InsertGroup[] = ['layouts'];\nconst MENU_GROUPS: Readonly<Record<InsertMenu, readonly InsertGroup[]>> = {\n elements: ELEMENT_GROUPS,\n templates: TEMPLATE_GROUPS,\n layouts: LAYOUT_GROUPS,\n};\nconst INSERT_MENUS: ReadonlySet<string> = new Set(Object.keys(MENU_GROUPS));\nconst MARKS: readonly Toggle[] = ['bold', 'italic', 'underline'];\nconst LISTS: readonly Toggle[] = ['bulleted', 'numbered'];\n\nconst STYLE_POPUPS: ReadonlySet<string> = new Set(['font', 'size', 'color', 'highlight', 'align', 'spacing']);\n\n/** `panel`: the style form or the rules, the default of a request nobody else took (`astl-style-open`). */\ntype Popup = 'style' | 'link' | 'panel' | InsertMenu | StylePopup;\n\n/** The toolbar's insert menus: every component and content insert, the named starters, or the layouts. */\nexport type InsertMenu = 'elements' | 'templates' | 'layouts';\n\nconst isMenu = (popup: Popup): popup is InsertMenu => INSERT_MENUS.has(popup);\n/** The popover a popup opens: the insert menus share one. */\nconst popoverOf = (popup: Popup) => (isMenu(popup) ? 'insert' : popup);\n/** The button a popup hangs from: the panel, reached from the style menu, hangs from that. */\nconst openerOf = (popup: Popup) => (popup === 'panel' ? 'style' : popup);\n\n/** A view the toolbar's view switch offers (`AstlToolbar.views`). */\nexport interface ToolbarView {\n readonly name: string;\n readonly label: string;\n}\n\n/** The event the view switch fires when an author picks a view; `detail.view` is its name. */\nexport const VIEW_PICKED = 'astl-toolbar-view';\n\n/** One button of the bar, in tab order. */\ninterface Item {\n readonly id: string;\n readonly label: string;\n /** Shown beside the icon; null: the icon alone (its name is `label`). */\n readonly text: string | null;\n readonly icon: TemplateResult | SVGTemplateResult | null;\n /** The icon's name, for `::part(icon-<name>)`. */\n readonly iconName: string;\n readonly pressed?: boolean;\n /** A view of the view switch: whether it is the current one. */\n readonly checked?: boolean;\n readonly disabled?: boolean;\n readonly popup?: Popup;\n /** A button that says its value (the text style, the font, the size): a chevron after its text. */\n readonly menu?: boolean;\n /** A bar under the icon in this colour (the colour now). */\n readonly bar?: string | null;\n readonly data?: Readonly<Record<string, string>>;\n press(): void;\n}\n\nconst NO_STATE: EditorFormatState = { active: [], enabled: [], href: null, undo: false, redo: false };\n\n/**\n * The bar: one row of groups with a thin rule between them (each group's `separator`, a part a host can redraw), undo\n * and redo at its end. A group that wraps to the start of a row has its rule on the bar's own border, where it does not\n * show. Wider than a phone, the groups wrap into rows\n * when they do not fit, so every button is on show; on a phone the bar is one row that scrolls sideways, as a mobile\n * editor's:\n * wrapped, it would push the text below the fold. A shade at an edge says more buttons lie that way (the covers scroll\n * with the buttons and hide it at either end), and the arrow keys scroll the focused button into view.\n */\nconst barStyles: CSSResult = css`\n :host {\n display: block;\n container-type: inline-size;\n }\n .bar {\n box-sizing: border-box;\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1) calc(2 * var(--astl-space-2) + var(--astl-outline-width));\n padding: var(--astl-space-2);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n }\n .group {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .group + .group {\n position: relative;\n margin-inline-start: calc(-1 * var(--astl-space-2) - var(--astl-outline-width));\n padding-inline-start: calc(var(--astl-space-2) + var(--astl-outline-width));\n }\n .separator {\n position: absolute;\n inset-block: 0;\n inset-inline-start: 0;\n border-inline-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .group.history {\n margin-inline-start: auto;\n }\n @container (inline-size < 30rem) {\n .bar {\n flex-wrap: nowrap;\n overflow-x: auto;\n scrollbar-width: thin;\n background:\n linear-gradient(90deg, var(--astl-surface) 50%, #0000) left / 1.5rem no-repeat local,\n linear-gradient(-90deg, var(--astl-surface) 50%, #0000) right / 1.5rem no-repeat local,\n radial-gradient(farthest-side at 0, var(--astl-outline), #0000) left / 0.5rem no-repeat,\n radial-gradient(farthest-side at 100%, var(--astl-outline), #0000) right / 0.5rem no-repeat,\n var(--astl-surface);\n }\n .group {\n flex: none;\n flex-wrap: nowrap;\n }\n }\n`;\n\n/** The buttons: hovered, pressed. */\nconst buttonStyles: CSSResult = css`\n .bar button {\n justify-content: center;\n padding-inline: var(--astl-space-2);\n border-color: transparent;\n background: transparent;\n white-space: nowrap;\n }\n .bar button.labelled {\n padding-inline: var(--astl-space-2) var(--astl-space-3);\n }\n .bar button:hover {\n border-color: var(--astl-line);\n background: var(--astl-accent-soft);\n }\n .bar button[aria-pressed='true'] {\n border-color: var(--astl-accent);\n background: var(--astl-accent-soft);\n color: var(--astl-ink);\n }\n .group.views {\n gap: 0;\n padding: calc(2 * var(--astl-outline-width));\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-m);\n }\n .bar .views [aria-checked='true'] {\n background: var(--astl-accent);\n color: var(--astl-on-accent);\n font-weight: 600;\n }\n`;\n\n/**\n * Unavailable here: dimmed and dashed (not by colour alone), still reachable by the arrow keys. Then the icons (shapes\n * stroked here) and the popups: the text style menu, the link and the insert menus. Popups are compact: little\n * padding, items without a frame (the hover's fill shows them; a disabled entry keeps its dashed one), the target kept\n * (`--astl-target-min`). An insert menu has no visible title: the button that opened it names it, and the title is\n * still the section's name.\n */\nconst popupStyles: CSSResult = css`\n .bar button[aria-disabled='true'] {\n border-color: var(--astl-line);\n border-style: dashed;\n background: transparent;\n color: var(--astl-ink-muted);\n cursor: not-allowed;\n }\n .bar button[aria-expanded='true'] {\n border-color: var(--astl-outline);\n }\n .icon {\n fill: none;\n stroke: currentColor;\n stroke-width: 1.8;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .icon circle {\n fill: currentColor;\n stroke: none;\n }\n .chevron {\n inline-size: 1rem;\n block-size: 1rem;\n }\n [popover] {\n box-sizing: border-box;\n position: fixed;\n inset: auto;\n margin: 0;\n padding: var(--astl-space-2);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n background: var(--astl-surface);\n color: var(--astl-ink);\n box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);\n overflow: auto;\n }\n [popover]:not(:popover-open) {\n display: none;\n }\n .menu {\n display: flex;\n flex-direction: column;\n gap: 2px;\n min-inline-size: 12rem;\n max-block-size: calc(100dvh - 2 * var(--astl-space-4));\n }\n .menu button {\n justify-content: flex-start;\n padding: var(--astl-space-1) var(--astl-space-2);\n border-color: transparent;\n }\n .menu button[aria-checked='true'] {\n border-color: var(--astl-accent);\n background: var(--astl-accent-soft);\n font-weight: 600;\n }\n .insert {\n inline-size: min(26rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: min(32rem, calc(100vh - 2 * var(--astl-space-4)));\n padding: 0;\n }\n .insert .search {\n position: sticky;\n inset-block-start: 0;\n z-index: 1;\n padding: var(--astl-space-2);\n border-block-end: var(--astl-outline-width) solid var(--astl-line);\n background: var(--astl-surface);\n }\n .insert astl-insert-menu::part(root) {\n padding: var(--astl-space-2);\n border: 0;\n border-radius: 0;\n }\n .insert astl-insert-menu::part(title) {\n display: none;\n }\n .insert astl-insert-menu::part(button) {\n padding-inline: var(--astl-space-2);\n }\n .insert astl-insert-menu::part(button):enabled {\n border-color: transparent;\n }\n .link {\n display: flex;\n flex-direction: column;\n inline-size: min(22rem, calc(100vw - 2 * var(--astl-space-4)));\n }\n .menu .menu-section {\n display: contents;\n }\n .menu .menu-group {\n margin-block: var(--astl-space-2) 0;\n padding-inline: var(--astl-space-2);\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n font-weight: 600;\n }\n .menu hr {\n inline-size: 100%;\n margin-block: var(--astl-space-1);\n border: 0;\n border-block-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .bar button .value {\n max-inline-size: 8rem;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n .color-mark {\n position: absolute;\n inset-inline: 25%;\n inset-block-end: var(--astl-space-1);\n block-size: 0.2rem;\n border: var(--astl-outline-width) solid var(--astl-outline);\n forced-color-adjust: none;\n }\n .bar button[data-popup='color'],\n .bar button[data-popup='highlight'] {\n position: relative;\n }\n .link > * + * {\n margin-block-start: var(--astl-space-2);\n }\n .link > [role='alert']:empty {\n margin-block-start: 0;\n }\n .link label {\n font-weight: 600;\n }\n .link .buttons {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .link .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n @media (forced-colors: active) {\n .bar button:is([aria-pressed='true'], [aria-checked='true']) {\n border-color: Highlight;\n }\n .bar button[aria-disabled='true'] {\n color: GrayText;\n }\n }\n`;\n\n/**\n * `<astl-toolbar>`: a word processor's toolbar for the editor in `adapter`, one row while it fits. In order: the text\n * style (a menu: paragraph, heading, subheading), bold, italic, underline, link, the two lists; the host's `featured`\n * inserts as buttons, \"Elements\" (every component and content insert) and \"Templates\" (the named starters), menus with\n * a search over one `<astl-insert-menu>`; the types' commands on the selection (`EditorDescriptor.wrap`, \"Mark\n * word\"); the view switch (`views`, a segmented control of radios); undo and redo at the end. Controls the adapter has\n * no capability for are left out (`format`, `undo`, `wrap`). One tab stop: the arrow keys, Home and End move along it.\n * Format buttons show the state at the cursor: pressed, or unavailable (`aria-disabled`, still focusable). A press\n * never moves the editor's cursor: a pointer's leaves the focus in the editor, and a key's gives it back.\n */\nexport class AstlToolbar extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n featured: { attribute: false },\n views: { attribute: false },\n view: {},\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n inheritTokens('astl-insert-menu, astl-picture-dialog, astl-style-form, astl-style-rules'),\n barStyles,\n buttonStyles,\n popupStyles,\n ];\n\n /**\n * The inserts shown as buttons, in order: component tags (their default template), `tag:template` for a named\n * starter, and the kit items `text` (an empty paragraph after the cursor's block), `picture` and `page-break`.\n * Unknown names are skipped. Default: none (everything is under \"Elements\" and \"Templates\").\n */\n declare featured: readonly string[];\n /**\n * The views of the view switch, in order; the first is the one the adapter edits, and in any other only the switch\n * works. A pick fires `astl-toolbar-view` (bubbles, composed) with the view's name in `detail.view`; the host then\n * sets `view`. Empty (default): no switch.\n */\n declare views: readonly ToolbarView[];\n /** The name of the current view. */\n declare view: string;\n\n #state: EditorFormatState = NO_STATE;\n #styles: EditorStyleState | null = null;\n #popup: Popup | null = null;\n /** The popups of the style controls, once one was asked for. */\n #stylePopupsModule: typeof import('./style-popups.js') | null = null;\n /** What the panel shows. */\n #panel: StyleOpen['target'] = 'block';\n /** A typed colour was refused, in the open colours popup. */\n #colorError = false;\n /** The insert menu shown last: its groups stay while closed. */\n #menu: InsertMenu = 'elements';\n #query = '';\n #linkError = false;\n #off: { readonly adapter: EditorAdapter; readonly off: () => void } | null = null;\n #items: readonly Item[] = [];\n readonly #roving = new RovingFocus(this, {\n count: () => this.#items.length,\n item: (index) => this.renderRoot.querySelector<HTMLElement>(`.bar [data-item=\"${index}\"]`),\n axis: 'inline',\n });\n\n constructor() {\n super();\n this.featured = [];\n this.views = [];\n this.view = '';\n }\n\n /** The insert menu of \"Elements\" and \"Templates\": insert from it as a host would from `<astl-insert-menu>`. */\n get menu(): AstlInsertMenu | null {\n return this.renderRoot.querySelector<AstlInsertMenu>('astl-insert-menu');\n }\n\n /** Opens \"Elements\", \"Templates\" or \"Layout\" with its search, as its button does. */\n async openMenu(menu: InsertMenu): Promise<void> {\n await this.#open(menu);\n }\n\n /**\n * Asks for the style form of a target at the cursor, or the rules, as the style menu does: fires `astl-style-open`,\n * and unless a host cancels it, shows them in a popup (they load now).\n */\n async openStyle(target: StyleOpen['target']): Promise<void> {\n const detail: StyleOpen = { target };\n this.#close(false);\n const event = new CustomEvent(STYLE_OPEN, { detail, bubbles: true, composed: true, cancelable: true });\n if (!this.dispatchEvent(event)) return;\n await loadStyleElements();\n this.#panel = target;\n await this.#open('panel');\n }\n\n /** Loads the popups of the style controls and their styles, once; false if that failed (it says so in the console). */\n async #loadStylePopups(): Promise<boolean> {\n if (this.#stylePopupsModule !== null) return true;\n try {\n const module = await import('./style-popups.js');\n const root = this.renderRoot as ShadowRoot;\n const sheet = module.stylePopupStyles.styleSheet;\n if (this.#stylePopupsModule === null && sheet !== undefined)\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n this.#stylePopupsModule = module;\n return true;\n } catch (error) {\n console.error(error);\n return false;\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#follow();\n document.addEventListener('pointerdown', this.#outside, true);\n document.addEventListener('keydown', this.#escape);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#follow();\n document.removeEventListener('pointerdown', this.#outside, true);\n document.removeEventListener('keydown', this.#escape);\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('adapter')) this.#follow();\n this.#state = this.adapter?.formatState?.() ?? NO_STATE;\n this.#styles = this.adapter?.style?.state() ?? null;\n }\n\n /** Follows the cursor of the adapter: every move may change the state at it. */\n #follow(): void {\n const adapter = this.isConnected ? this.adapter : null;\n if ((this.#off?.adapter ?? null) === adapter) return;\n this.#off?.off();\n this.#off = null;\n const listen = adapter?.onCursorChange;\n if (adapter === null || listen === undefined) return;\n this.#off = { adapter, off: listen.call(adapter, () => this.requestUpdate()) };\n }\n\n /** A press outside the open popup and its button closes it. */\n #outside = (event: Event): void => {\n if (this.#popup === null) return;\n const path = event.composedPath();\n const popup = this.renderRoot.querySelector(`#${popoverOf(this.#popup)}`);\n const opener = this.renderRoot.querySelector(`[data-popup=\"${openerOf(this.#popup)}\"]`);\n if ((popup !== null && path.includes(popup)) || (opener !== null && path.includes(opener))) return;\n // The picture dialog of an insert menu sits outside the popover in the top layer, above it.\n if (path.some((node) => node instanceof Element && node.localName === 'astl-picture-dialog')) return;\n this.#close(false);\n };\n\n /**\n * The style panel is not modal: the focus can leave it, by Tab or to the surface after an undo, and it stays open\n * over what it covers. Escape closes it from there too; only from inside does the focus go back to its button.\n */\n #escape = (event: KeyboardEvent): void => {\n if (this.#popup !== 'panel' || event.key !== 'Escape') return;\n const panel = this.renderRoot.querySelector('#panel');\n const inside = panel !== null && event.composedPath().includes(panel);\n // Inside, a field may have its own use for the key (a rename). ProseMirror claims every Escape, with no use for it.\n if (inside && event.defaultPrevented) return;\n event.preventDefault();\n this.#close(inside);\n };\n\n async #open(popup: Popup): Promise<void> {\n if ((popup === 'panel' || STYLE_POPUPS.has(popup)) && !(await this.#loadStylePopups())) return;\n if (this.#popup !== null && this.#popup !== popup) this.#close(false);\n this.#popup = popup;\n this.#linkError = false;\n this.#colorError = false;\n if (isMenu(popup)) {\n this.#query = '';\n this.#menu = popup;\n }\n this.requestUpdate();\n await this.updateComplete;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(popup)}`);\n const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(popup)}\"]`);\n if (element === null || opener === null) return;\n if (!element.matches(':popover-open')) element.showPopover();\n // Its descriptions load now (`menuMessages`), not with the editor.\n this.menu?.requestUpdate();\n this.#place(element, opener);\n const first =\n popup === 'style' || STYLE_POPUPS.has(popup)\n ? (element.querySelector<HTMLElement>('[aria-checked=\"true\"], [aria-pressed=\"true\"]') ??\n element.querySelector('button'))\n : popup === 'panel'\n ? element\n : element.querySelector<HTMLElement>('input');\n first?.focus();\n }\n\n /** Closes the open popup; the focus goes back to its button with `back`. */\n #close(back: boolean): void {\n const popup = this.#popup;\n if (popup === null) return;\n this.#popup = null;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(popup)}`);\n if (element?.matches(':popover-open') === true) element.hidePopover();\n if (back) this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(popup)}\"]`)?.focus();\n this.requestUpdate();\n }\n\n /** Puts a popup below its button, its start edge on the button's, inside the viewport. */\n #place(popup: HTMLElement, opener: HTMLElement): void {\n const rect = opener.getBoundingClientRect();\n const rtl = getComputedStyle(opener).direction === 'rtl';\n const width = popup.offsetWidth;\n const room = document.documentElement.clientWidth;\n const start = rtl ? room - rect.right : rect.left;\n const inset = Math.max(8, Math.min(start, room - width - 8));\n popup.style.setProperty('inset-inline-start', `${inset}px`);\n // Below the button, or as low as it fits: a tall popup (the style form) from a bar far down the page.\n const below = document.documentElement.clientHeight - popup.offsetHeight - 8;\n popup.style.setProperty('inset-block-start', `${Math.max(8, Math.min(rect.bottom + 4, below))}px`);\n }\n\n /** After a command: the editor gets the focus back when a key pressed the button (a pointer never took it). */\n #done(): void {\n this.adapter?.focus?.();\n }\n\n #format(format: EditorFormat, href?: string): void {\n if (!this.#state.enabled.includes(format)) return;\n this.adapter?.format?.(format, href);\n this.#done();\n this.requestUpdate();\n }\n\n /** A style on the selected text (with only a cursor, on what is typed next), the popup closed. */\n #setText(changes: EditorStyleChanges): void {\n this.adapter?.style?.setText(changes);\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /** A style on each text block of the selection, the popup closed. */\n #setBlock(changes: EditorStyleChanges): void {\n this.adapter?.style?.setTarget('block', changes);\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /**\n * Where a named style goes: on the selected text, and with only a cursor on what the cursor is in. A style of boxes\n * (`box`) goes on what the cursor is in, words selected or not, as a paragraph style does in a word processor.\n */\n #namedTarget(box = false): 'text' | EditorStyleTargetKind | null {\n const styles = this.#styles;\n if (styles === null) return null;\n return styles.hasSelection && !box ? 'text' : (styles.targets[0]?.kind ?? null);\n }\n\n /** The named style on that target. */\n #namedNow(box = false): string | null {\n const where = this.#namedTarget(box);\n return where === 'text'\n ? (this.#styles?.textClass ?? null)\n : (this.#styles?.targets.find((target) => target.kind === where)?.className ?? null);\n }\n\n /** Whether a named style is a ready style of boxes: its rule in the document keeps that way of going on. */\n #isBox(name: string): boolean {\n return this.authoring?.styles.some((ready) => ready.name === name && ready.text !== true) ?? false;\n }\n\n /** Sets a named style, or takes it away when it is there; a ready style (`rule`) brings its rule in the same step. */\n #setNamed(name: string, rule?: EditorStyleRule): void {\n const box = this.#isBox(name);\n const where = this.#namedTarget(box);\n if (where !== null) {\n if (rule === undefined)\n this.adapter?.style?.setClass(where, this.#namedNow(box) === name ? null : name);\n else this.adapter?.style?.setClass(where, name, rule);\n }\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /** The style at the cursor as a font's name: the host's, else the stack's first name; '' with none or a mix. */\n #fontName(): string {\n const stack = this.#styles?.text['font-family'];\n if (stack === undefined) return '';\n const known = this.authoring?.fonts.find((font) => font.stack === stack);\n return known?.name ?? (stack.split(',')[0] ?? '').replace(/\"/g, '').trim();\n }\n\n /** The bar's style controls, by group (font and size; colours; alignment and spacing), and clear formatting. */\n #styleGroups(): { fonts: Item[]; colors: Item[]; blocks: Item[]; clear: Item[] } {\n const styles = this.#styles;\n if (styles === null) return { fonts: [], colors: [], blocks: [], clear: [] };\n const { text, textEnabled, targets } = styles;\n const hasBlock = targets.some((target) => target.kind === 'block');\n const popupItem = (\n popup: StylePopup,\n label: string,\n enabled: boolean,\n icon: SVGTemplateResult,\n iconName: string,\n ): Item => ({\n id: popup,\n label,\n text: null,\n icon,\n iconName,\n disabled: !enabled,\n popup,\n press: () => {\n if (this.#popup === popup) this.#close(true);\n else void this.#open(popup);\n },\n });\n const font = this.#fontName();\n const size = /^(\\d+(?:\\.\\d+)?)px$/.exec(text['font-size'] ?? '')?.[1] ?? text['font-size'] ?? '';\n const valued = (popup: StylePopup, label: string, value: string): Item => ({\n ...popupItem(\n popup,\n this.t(label, { value: value === '' ? this.t('toolbar.default') : value }),\n textEnabled,\n ICONS.chevron,\n 'chevron',\n ),\n text: value === '' ? this.t(`toolbar.${popup}.name`) : value,\n menu: true,\n });\n const blockStyle = targets.find((target) => target.kind === 'block')?.style ?? '';\n const align = styleMapOf(blockStyle).get('text-align');\n const alignIcon =\n align === 'right' || align === 'end'\n ? 'align-end'\n : align === 'center'\n ? 'align-center'\n : align === 'justify'\n ? 'align-justify'\n : 'align-start';\n return {\n fonts: [valued('font', 'toolbar.font', font), valued('size', 'toolbar.size', size)],\n colors: [\n {\n ...popupItem('color', this.t('toolbar.color'), textEnabled, ICONS.color, 'color'),\n bar: text.color ?? null,\n },\n {\n ...popupItem('highlight', this.t('toolbar.highlight'), textEnabled, ICONS.highlight, 'highlight'),\n bar: text['background-color'] ?? null,\n },\n ],\n blocks: [\n popupItem('align', this.t('toolbar.align'), hasBlock, ICONS[alignIcon], alignIcon),\n popupItem('spacing', this.t('toolbar.spacing'), hasBlock, ICONS.spacing, 'spacing'),\n ],\n clear: [\n {\n id: 'clear',\n label: this.t('toolbar.clear'),\n text: null,\n icon: ICONS.clear,\n iconName: 'clear',\n disabled: !textEnabled && !hasBlock,\n press: () => {\n this.adapter?.style?.clear();\n this.#done();\n this.requestUpdate();\n },\n },\n ],\n };\n }\n\n async #insert(name: string): Promise<void> {\n const menu = this.menu;\n const adapter = this.adapter;\n if (menu === null || adapter === null) return;\n if (name === 'text') {\n adapter.insert('<p></p>');\n this.#done();\n return;\n }\n if (name === 'picture') await menu.insertPicture();\n else if (name === 'page-break') menu.insertPageBreak();\n else {\n const [tag = '', template] = name.split(':');\n await menu.add(tag, template);\n }\n this.#done();\n }\n\n /** The featured names this editor can insert, as buttons. */\n #featuredItems(): Item[] {\n const authoring = this.authoring;\n if (authoring === null) return [];\n const disabled = this.adapter === null;\n const items: Item[] = [];\n for (const name of this.featured) {\n if (name === 'text' || name === 'picture') {\n const label = this.t(name === 'text' ? 'insert.text' : 'insert.picture');\n items.push({\n id: `insert-${name}`,\n label,\n text: label,\n icon: name === 'text' ? ICONS.text : GLYPHS.picture,\n iconName: name === 'text' ? 'text' : 'image',\n disabled,\n data: { content: name },\n press: () => void this.#insert(name),\n });\n continue;\n }\n if (name === 'page-break') {\n if (this.adapter?.splitPage === undefined) continue;\n const label = this.t('insert.pageBreak');\n items.push({\n id: 'insert-page-break',\n label,\n text: label,\n icon: GLYPHS.page,\n iconName: 'files',\n data: { content: name },\n press: () => void this.#insert(name),\n });\n continue;\n }\n const [tag = '', template] = name.split(':');\n const descriptor = authoring.descriptor(tag);\n if (descriptor === null) continue;\n const starter = template === undefined ? null : authoring.templates(tag).find((t) => t.id === template);\n if (starter === undefined) continue;\n const label = authoring.t(descriptor.manifest.messages, starter?.label ?? descriptor.label);\n const icon = starter?.icon ?? descriptor.icon;\n items.push({\n id: `insert-${name}`,\n label,\n text: label,\n icon: TYPE_GLYPHS.get(icon) ?? GLYPHS[descriptor.manifest.display as Glyph],\n iconName: icon,\n disabled,\n data: template === undefined ? { tag } : { tag, template },\n press: () => void this.#insert(name),\n });\n }\n return items;\n }\n\n /** The bar's buttons in order, by group (named for its class). */\n #groups(): [string, Item[]][] {\n const adapter = this.adapter;\n const authoring = this.authoring;\n const state = this.#state;\n const groups: [string, Item[]][] = [];\n const formatItem = (format: Toggle, popup?: Popup): Item => ({\n id: format,\n label: this.t(`toolbar.${format}`),\n text: null,\n icon: ICONS[format],\n iconName: format,\n pressed: state.active.includes(format),\n disabled: !state.enabled.includes(format),\n ...(popup === undefined ? {} : { popup }),\n press: () => {\n if (popup !== undefined) void this.#open(popup);\n else this.#format(format);\n },\n });\n if (adapter?.format !== undefined && adapter.formatState !== undefined) {\n const current = STYLES.find((style) => state.active.includes(style));\n // The named style on what the menu would change says more than the tag.\n const named = this.#namedNow();\n const rule = named === null ? undefined : adapter.style?.rules().find((one) => one.name === named);\n const styleName = rule?.label ?? rule?.name ?? this.t(`toolbar.${current ?? 'paragraph'}`);\n const style = this.#styleGroups();\n groups.push([\n 'group',\n [\n {\n id: 'style',\n label: this.t('toolbar.style', { style: styleName }),\n text: styleName,\n icon: ICONS.chevron,\n iconName: 'chevron',\n menu: true,\n // A selected picture or component has no text style, but its style form is in this menu.\n disabled:\n !STYLES.some((one) => state.enabled.includes(one)) && (this.#styles?.targets.length ?? 0) === 0,\n popup: 'style',\n press: () => void this.#open('style'),\n },\n ],\n ]);\n if (style.fonts.length > 0) groups.push(['group', style.fonts]);\n groups.push(['group', [...MARKS.map((mark) => formatItem(mark)), formatItem('link', 'link')]]);\n if (style.colors.length > 0) groups.push(['group', style.colors]);\n if (style.blocks.length > 0) groups.push(['group', style.blocks]);\n groups.push(['group', [...LISTS.map((list) => formatItem(list)), ...style.clear]]);\n }\n const menu = (popup: InsertMenu, icon: 'add' | 'templates' | 'layouts'): Item => ({\n id: popup,\n label: this.t(`toolbar.${popup}`),\n text: this.t(`toolbar.${popup}`),\n icon: ICONS[icon],\n iconName: icon,\n disabled: adapter === null,\n popup,\n press: () => {\n if (this.#popup === popup) this.#close(true);\n else void this.#open(popup);\n },\n });\n const starters = authoring?.descriptors.some((d) => (d.templates ?? []).length > 0) === true;\n groups.push([\n 'group inserts',\n [\n ...this.#featuredItems(),\n menu('elements', 'add'),\n ...(starters ? [menu('templates', 'templates')] : []),\n // Layouts are styles: a host without the style API has none to insert.\n ...(adapter?.style !== undefined ? [menu('layouts', 'layouts')] : []),\n ],\n ]);\n if (adapter?.wrap !== undefined && authoring !== null) {\n const wraps = authoring.descriptors.filter((d) => d.wrap !== undefined);\n if (wraps.length > 0) {\n groups.push([\n 'group',\n wraps.map((d) => {\n const label = authoring.t(d.manifest.messages, d.wrap?.label ?? '');\n return {\n id: `wrap-${d.manifest.tag}`,\n label,\n text: label,\n icon: ICONS.wrap,\n iconName: 'wrap',\n data: { wrap: d.manifest.tag },\n press: () => {\n this.adapter?.wrap?.(d.manifest.tag);\n this.#done();\n },\n };\n }),\n ]);\n }\n }\n if (this.views.length > 0) {\n groups.push([\n 'group views',\n this.views.map((view) => ({\n id: `view-${view.name}`,\n label: view.label,\n text: view.label,\n icon: null,\n iconName: '',\n checked: view.name === this.view,\n press: () => {\n if (view.name === this.view) return;\n const detail = { view: view.name };\n this.dispatchEvent(new CustomEvent(VIEW_PICKED, { detail, bubbles: true, composed: true }));\n },\n })),\n ]);\n }\n if (adapter?.undo !== undefined && adapter.redo !== undefined) {\n const history = (name: 'undo' | 'redo'): Item => ({\n id: name,\n label: this.t(`toolbar.${name}`),\n text: null,\n icon: ICONS[name],\n iconName: name,\n disabled: !state[name],\n press: () => {\n if (!state[name]) return;\n adapter[name]?.();\n this.#done();\n },\n });\n groups.push(['group history', [history('undo'), history('redo')]]);\n }\n return groups;\n }\n\n #keydown(event: KeyboardEvent): void {\n const target = (event.target as HTMLElement).closest<HTMLElement>('[data-item]');\n if (target === null) return;\n const index = Number(target.dataset.item);\n const item = this.#items[index];\n const menu = item?.popup === 'style' || STYLE_POPUPS.has(item?.popup ?? '');\n if (menu && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {\n event.preventDefault();\n if (item?.disabled !== true && item?.popup !== undefined) void this.#open(item.popup);\n return;\n }\n this.#roving.keydown(event, index);\n }\n\n #button(item: Item, index: number): TemplateResult {\n const unavailable = item.disabled === true;\n // The parts: every button; an icon-only one is also an `icon-button`, and an option of the view switch a `view`.\n const part =\n item.checked !== undefined ? 'button view' : item.text === null ? 'button icon-button' : 'button';\n return html`<button\n type=\"button\"\n part=${part}\n class=${item.text === null ? 'icon-only' : 'labelled'}\n data-item=${index}\n data-id=${item.id}\n data-tag=${item.data?.tag ?? nothing}\n data-template=${item.data?.template ?? nothing}\n data-content=${item.data?.content ?? nothing}\n data-popup=${item.popup ?? nothing}\n tabindex=${this.#roving.tabIndex(index)}\n aria-label=${item.text === null || item.menu === true ? item.label : nothing}\n title=${item.text === null ? item.label : nothing}\n aria-pressed=${item.pressed === undefined ? nothing : String(item.pressed)}\n role=${item.checked === undefined ? nothing : 'radio'}\n aria-checked=${item.checked === undefined ? nothing : String(item.checked)}\n aria-disabled=${unavailable ? 'true' : nothing}\n aria-haspopup=${\n item.popup === undefined\n ? nothing\n : item.popup === 'style' || item.menu === true || item.popup === 'align' || item.popup === 'spacing'\n ? 'menu'\n : 'dialog'\n }\n aria-expanded=${item.popup === undefined ? nothing : String(this.#popup === item.popup)}\n aria-controls=${item.popup === undefined ? nothing : popoverOf(item.popup)}\n @click=${() => {\n this.#roving.focus(index);\n if (!unavailable) item.press();\n }}\n >\n ${\n item.menu === true\n ? html`<span class=\"value\">${item.text}</span>\n <svg class=\"icon chevron\" part=\"icon icon-chevron\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${item.icon}</svg>`\n : html`${item.icon === null ? nothing : html`<svg class=\"icon\" part=\"icon icon-${item.iconName}\" data-icon=${item.iconName} viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${item.icon}</svg>`}\n ${item.text === null ? nothing : html`<span>${item.text}</span>`}${\n item.bar === undefined || item.bar === null\n ? nothing\n : html`<span class=\"color-mark\" data-color=${item.bar}></span>`\n }`\n }\n </button>`;\n }\n\n /** The arrows, Home and End along a menu's buttons; Escape closes it, back on its button; Tab goes on. */\n #menuKeydown = (event: KeyboardEvent): void => {\n const buttons = [...(event.currentTarget as HTMLElement).querySelectorAll<HTMLElement>('button')];\n const at = buttons.indexOf(event.target as HTMLElement);\n const step = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0;\n if (step !== 0) {\n event.preventDefault();\n buttons[(at + step + buttons.length) % buttons.length]?.focus();\n } else if (event.key === 'Home' || event.key === 'End') {\n event.preventDefault();\n buttons[event.key === 'Home' ? 0 : buttons.length - 1]?.focus();\n } else if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n } else if (event.key === 'Tab') this.#close(false);\n };\n\n /**\n * The rest of the style menu: the document's named styles, the ready styles it does not have yet, then the forms of\n * what the cursor is in.\n */\n #styleMenuMore(): TemplateResult | typeof nothing {\n const styles = this.#styles;\n if (styles === null) return nothing;\n const named = this.adapter?.style?.rules().filter((rule) => rule.name !== undefined) ?? [];\n const own = new Set(named.map((rule) => rule.name));\n const ready = (this.authoring?.styles ?? []).filter((preset) => !own.has(preset.name));\n const targets: readonly EditorStyleTarget[] = styles.targets;\n const group = (label: string, items: readonly TemplateResult[]) => html`<hr />\n <div class=\"menu-section\" role=\"group\" aria-label=${label}>\n <div class=\"menu-group\" aria-hidden=\"true\">${label}</div>\n ${items}\n </div>`;\n return html`${\n named.length === 0\n ? nothing\n : group(\n this.t('toolbar.myStyles'),\n named.map((rule) => {\n const name = rule.name ?? '';\n const box = this.#isBox(name);\n const none = this.#namedTarget(box) === null;\n return html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-named=${name}\n aria-checked=${String(this.#namedNow(box) === name)}\n aria-disabled=${none ? 'true' : nothing}\n @click=${() => {\n if (!none) this.#setNamed(name);\n }}\n >\n ${rule.label ?? name}\n </button>`;\n }),\n )\n }\n ${\n ready.length === 0\n ? nothing\n : group(\n this.t('toolbar.readyStyles'),\n ready.map(({ name, label, style, text }) => {\n const none = this.#namedTarget(text !== true) === null;\n return html`<button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-ready=${name}\n aria-disabled=${none ? 'true' : nothing}\n @click=${() => {\n // Its label as the author reads it now: from here on it is a style of this exercise.\n if (!none) this.#setNamed(name, { name, label, style });\n }}\n >\n ${label}\n </button>`;\n }),\n )\n }\n <hr />\n ${targets.map(\n (target) => html`<button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-style-target=${target.kind}\n @click=${() => void this.openStyle(target.kind)}\n >\n ${this.t('style.target.more', { target: this.t(`style.target.${target.kind}`) })}\n </button>`,\n )}\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-style-target=\"rules\"\n @click=${() => void this.openStyle('rules')}\n >\n ${this.t('style.rules.open')}\n </button>`;\n }\n\n /** The open popup of the style controls, from its module. */\n #stylePopup(): TemplateResult | typeof nothing {\n const module = this.#stylePopupsModule;\n const popup = this.#popup;\n const styles = this.#styles;\n if (module === null || styles === null || (popup !== 'panel' && !STYLE_POPUPS.has(popup ?? '')))\n return nothing;\n return module.stylePopup({\n popup: popup === 'panel' ? { panel: this.#panel } : (popup as StylePopup),\n styles,\n fonts: this.authoring?.fonts ?? [],\n colorError: this.#colorError,\n authoring: this.authoring,\n adapter: this.adapter,\n t: (key, params) => this.t(key, params),\n setText: (changes) => this.#setText(changes),\n setBlock: (changes) => this.#setBlock(changes),\n refuseColor: () => {\n this.#colorError = true;\n this.requestUpdate();\n },\n close: (back) => this.#close(back),\n menuKeydown: this.#menuKeydown,\n });\n }\n\n #styleMenu(): TemplateResult {\n const state = this.#state;\n const choose = (style: EditorFormat) => {\n this.#close(false);\n if (!state.active.includes(style) || style === 'paragraph') this.#format(style);\n else this.#done();\n };\n return html`<div\n id=\"style\"\n class=\"menu\"\n popover=\"manual\"\n role=\"menu\"\n aria-label=${this.t('toolbar.style', { style: this.t(`toolbar.${STYLES.find((s) => state.active.includes(s)) ?? 'paragraph'}`) })}\n part=\"style-menu\"\n @keydown=${this.#menuKeydown}\n >\n ${STYLES.map(\n (style) => html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-format=${style}\n aria-checked=${String(state.active.includes(style))}\n aria-disabled=${state.enabled.includes(style) ? nothing : 'true'}\n @click=${() => choose(style)}\n >\n ${this.t(`toolbar.${style}`)}\n </button>`,\n )}\n ${this.#styleMenuMore()}\n </div>`;\n }\n\n #linkPopup(): TemplateResult {\n const state = this.#state;\n const apply = () => {\n const input = this.renderRoot.querySelector<HTMLInputElement>('#link-address');\n const href = input?.value.trim() ?? '';\n if (href === '') {\n this.#close(false);\n this.#format('link');\n return;\n }\n if (this.authoring?.urlPolicy(href, { tag: 'a', attribute: 'href' }) !== true) {\n this.#linkError = true;\n this.requestUpdate();\n input?.focus();\n return;\n }\n this.#close(false);\n this.#format('link', href);\n };\n return html`<div\n id=\"link\"\n class=\"link\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${this.t('toolbar.link')}\n part=\"link\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n } else if (event.key === 'Enter' && (event.target as HTMLElement).localName === 'input') {\n event.preventDefault();\n apply();\n }\n }}\n >\n <label for=\"link-address\">${this.t('toolbar.link.address')}</label>\n <input\n id=\"link-address\"\n type=\"url\"\n inputmode=\"url\"\n .value=${this.#popup === 'link' ? (state.href ?? '') : ''}\n aria-invalid=${this.#linkError ? 'true' : nothing}\n aria-describedby=${this.#linkError ? 'link-error' : nothing}\n />\n <div role=\"alert\">${this.#linkError ? html`<p class=\"error\" id=\"link-error\">${this.t('toolbar.link.blocked')}</p>` : nothing}</div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"primary\" @click=${apply}>${this.t('toolbar.link.apply')}</button>\n ${\n state.href === null\n ? nothing\n : html`<button\n type=\"button\"\n @click=${() => {\n this.#close(false);\n this.#format('link');\n }}\n >\n ${this.t('toolbar.link.remove')}\n </button>`\n }\n </div>\n </div>`;\n }\n\n #insertPopup(): TemplateResult {\n const authoring = this.authoring;\n return html`<div\n id=\"insert\"\n class=\"insert\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${this.t(`toolbar.${this.#menu}`)}\n part=\"insert\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n }\n }}\n @focusout=${(event: FocusEvent) => {\n const next = event.relatedTarget as Node | null;\n if (next !== null && !(event.currentTarget as HTMLElement).contains(next)) this.#close(false);\n }}\n @astl-inserted=${() => {\n this.#close(false);\n this.#done();\n }}\n >\n <div class=\"search\">\n <input\n type=\"search\"\n aria-label=${this.t('toolbar.search')}\n placeholder=${this.t('toolbar.search')}\n .value=${this.#query}\n @input=${(event: Event) => {\n this.#query = (event.target as HTMLInputElement).value;\n this.requestUpdate();\n }}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n const first = this.menu?.renderRoot.querySelector<HTMLButtonElement>(\n 'button.insert:not(:disabled)',\n );\n first?.click();\n }}\n />\n </div>\n <astl-insert-menu\n part=\"menu\"\n .authoring=${authoring}\n .adapter=${this.adapter}\n .filter=${this.#query}\n .groups=${MENU_GROUPS[this.#menu]}\n ></astl-insert-menu>\n </div>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n // Out of the editing view (the first), only the switch works.\n const away = this.views.length > 0 && this.view !== this.views[0]?.name;\n const groups = this.#groups().map(\n ([name, items]) =>\n [\n name,\n away\n ? items.map((item) => (item.checked === undefined ? { ...item, disabled: true } : item))\n : items,\n ] as const,\n );\n this.#items = groups.flatMap(([, items]) => items);\n let index = 0;\n // The picture dialog is outside the popovers: a picture asked for from a menu or a featured button shows while\n // they are closed.\n return html`<div\n class=\"bar\"\n part=\"toolbar\"\n role=\"toolbar\"\n aria-label=${this.t('toolbar.label')}\n lang=${lang}\n dir=${dir}\n @mousedown=${(event: MouseEvent) => {\n // A press keeps the editor's focus and selection.\n if ((event.target as HTMLElement).closest('button') !== null) event.preventDefault();\n }}\n @keydown=${(event: KeyboardEvent) => this.#keydown(event)}\n >\n ${groups.map(\n (\n [name, items],\n at,\n ) => html`<div class=${name} role=${name === 'group views' ? 'radiogroup' : 'presentation'}\n part=${name === 'group views' ? 'views' : nothing}\n aria-label=${name === 'group views' ? this.t('toolbar.view') : nothing}>\n ${at === 0 || name === 'group views' ? nothing : html`<span class=\"separator\" part=\"separator\" aria-hidden=\"true\"></span>`}\n ${items.map((item) => this.#button(item, index++))}\n </div>`,\n )}\n </div>\n <div lang=${lang} dir=${dir}>\n ${this.#styleMenu()} ${this.#linkPopup()} ${this.#insertPopup()} ${this.#stylePopup()}\n </div>\n <astl-picture-dialog .authoring=${this.authoring}></astl-picture-dialog>`;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n const menu = this.menu;\n if (menu !== null) menu.dialog = this.renderRoot.querySelector('astl-picture-dialog');\n // Through the CSSOM: a strict Content Security Policy blocks a style attribute, which Lit's styleMap writes on its\n // first render.\n for (const mark of this.renderRoot.querySelectorAll<HTMLElement>('.color-mark')) {\n mark.style.background = mark.dataset.color ?? '';\n }\n for (const choice of this.renderRoot.querySelectorAll<HTMLElement>('[data-font]')) {\n choice.style.fontFamily = choice.dataset.font ?? '';\n }\n // Popups stay where their buttons are while the page scrolls or the bar wraps.\n if (this.#popup === null) return;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(this.#popup)}`);\n const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(this.#popup)}\"]`);\n if (element !== null && opener !== null && element.matches(':popover-open')) this.#place(element, opener);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-toolbar': AstlToolbar;\n }\n}\n","import { AstlInsertMenu } from './elements/insert-menu.js';\nimport { AstlInspector } from './elements/inspector.js';\nimport { AstlIssues } from './elements/issues.js';\nimport { AstlPictureDialog } from './elements/picture-dialog.js';\nimport { AstlPictureField } from './elements/picture-field.js';\nimport { AstlPreview } from './elements/preview.js';\nimport { styleElementsIn } from './elements/style-load.js';\nimport { AstlToolbar } from './elements/toolbar.js';\n\nconst ELEMENTS: readonly (readonly [string, CustomElementConstructor])[] = [\n ['astl-insert-menu', AstlInsertMenu],\n ['astl-inspector', AstlInspector],\n ['astl-issues', AstlIssues],\n ['astl-preview', AstlPreview],\n ['astl-toolbar', AstlToolbar],\n ['astl-picture-dialog', AstlPictureDialog],\n ['astl-picture-field', AstlPictureField],\n];\n\n/**\n * Defines `<astl-toolbar>`, `<astl-insert-menu>`, `<astl-inspector>`, `<astl-issues>` and `<astl-preview>`, and the\n * two they use for pictures, `<astl-picture-dialog>` and `<astl-picture-field>` (nothing is defined on import;\n * `<astl-style-form>` and `<astl-style-rules>` come with `loadStyleElements`, on first use). Safe to call again; a\n * tag already defined by another class throws, as two copies of the kit would otherwise mix silently.\n */\nexport function defineAuthoringElements(registry: CustomElementRegistry = customElements): void {\n styleElementsIn(registry);\n for (const [tag, element] of ELEMENTS) {\n const existing = registry.get(tag);\n if (existing === element) continue;\n if (existing !== undefined) throw new Error(`<${tag}> is already defined by another class`);\n registry.define(tag, element);\n }\n}\n","/**\n * Page breaks, new pages and joins as edits of the source text, for text-based adapters (the textarea adapter's\n * `splitPage`, `addPage` and `mergePage`): the rules of `EditorAdapter`, on the element ranges of `scan.ts`, so\n * everything around an edit stays as written.\n */\nimport { CLASS_ATTRIBUTE, CONTENT_ATTRIBUTES, DOC_TAG, PAGE_TAG, STYLE_TAG } from '@astl/core';\nimport { attributeValue, type ElementRange, elementTree, tokenize, usedIds } from './scan.js';\n\n/** A source after a page edit, and the offset of the caret in it. */\nexport interface PageEdit {\n readonly source: string;\n readonly caret: number;\n}\n\n/** A page edit that added a page: its id. */\nexport interface AddedPage extends PageEdit {\n readonly id: string;\n}\n\n/** Blocks that break at the caret: the others break after themselves. */\nconst TEXT_BLOCKS: ReadonlySet<string> = new Set(['p', 'h2', 'h3', 'h4']);\n\n/** Where an element's content ends: at its end tag, or where it was closed. */\nconst contentEnd = (range: ElementRange): number => range.endTag?.start ?? range.end;\n\n/**\n * The content of `<astl-doc>` (the whole source without one), its blocks and its pages. It starts after the named styles\n * at its head: they stay there, out of any page.\n */\nfunction documentOf(source: string) {\n const roots = elementTree(source);\n const doc = roots.find((range) => range.name === DOC_TAG);\n const children = doc?.children ?? roots;\n const content = children.findIndex((range) => range.name !== STYLE_TAG);\n const blocks = content < 0 ? [] : children.slice(content);\n return {\n start: (content < 0 ? children.at(-1) : children[content - 1])?.end ?? doc?.startTag.end ?? 0,\n end: doc === undefined ? source.length : contentEnd(doc),\n blocks,\n pages: blocks.filter((range) => range.name === PAGE_TAG),\n };\n}\n\n/** `page-<n>` with the smallest n no id of the source uses; `used` takes it. */\nfunction freshPage(used: Set<string>): string {\n let n = 1;\n while (used.has(`page-${n}`)) n++;\n used.add(`page-${n}`);\n return `page-${n}`;\n}\n\n/** Nothing a student would see: whitespace and formatting tags, no text, line break, picture or component. */\nfunction blank(fragment: string): boolean {\n let at = 0;\n for (const tag of tokenize(fragment)) {\n if (fragment.slice(at, tag.start).trim() !== '') return false;\n if (tag.type === 'start' && (tag.name === 'br' || tag.name === 'img' || tag.name.includes('-')))\n return false;\n at = tag.end;\n }\n return fragment.slice(at).trim() === '';\n}\n\n/**\n * The elements from `block` down to the innermost one whose content holds `caret` (its formatting), or null when the\n * caret is in a tag or in a component.\n */\nfunction inlinePath(block: ElementRange, caret: number): ElementRange[] | null {\n const path = [block];\n for (let el = block; ; ) {\n if (caret < el.startTag.end || caret > contentEnd(el)) return null;\n const child = el.children.find((c) => c.start < caret && caret < c.end);\n if (child === undefined) return path;\n if (child.name.includes('-')) return null;\n path.push(child);\n el = child;\n }\n}\n\n/**\n * A page break at `caret` (`EditorAdapter.splitPage`): in a paragraph or a heading on a page, at the caret (the\n * formatting around it closed before the break and opened again after it); at its start before it, at its end after\n * it; in any other block (a layout, whatever holds the caret in it), or in a tag, after that block. Null when the caret\n * is not in a page's content (or in the document's, without pages).\n */\nexport function splitPageSource(source: string, caret: number): AddedPage | null {\n const doc = documentOf(source);\n const page = doc.pages.find((p) => p.startTag.end <= caret && caret <= contentEnd(p));\n if (doc.pages.length > 0 ? page === undefined : caret < doc.start || caret > doc.end) return null;\n const [from, to] = page === undefined ? [doc.start, doc.end] : [page.startTag.end, contentEnd(page)];\n const blocks = page?.children ?? doc.blocks;\n let at = caret;\n // In the middle of a paragraph: its formatting, closed before the break and opened again after it.\n let close = '';\n let open = '';\n const block = blocks.find((b) => b.start < caret && caret < b.end);\n if (block !== undefined) {\n const path = TEXT_BLOCKS.has(block.name) ? inlinePath(block, caret) : null;\n if (path === null) at = block.end;\n else if (blank(source.slice(block.startTag.end, caret))) at = block.start;\n else if (blank(source.slice(caret, contentEnd(block)))) at = block.end;\n else {\n close = path\n .map((el) => `</${el.name}>`)\n .reverse()\n .join('');\n open = path.map((el) => source.slice(el.startTag.start, el.startTag.end)).join('');\n }\n }\n const used = usedIds(source);\n const first = page === undefined ? `<astl-page id=\"${freshPage(used)}\">` : '';\n const id = freshPage(used);\n // The new page keeps the content language and the look of what moves to it, as written.\n const language = (page?.startTag.attributes ?? [])\n .filter((a) => CONTENT_ATTRIBUTES.has(a.name) || a.name === CLASS_ATTRIBUTE)\n .map((a) => ` ${source.slice(a.start, a.end)}`)\n .join('');\n // A side left without blocks gets an empty paragraph, as an editor needs one to put the cursor in.\n const before = open !== '' || blocks.some((b) => b.end <= at) ? '' : '<p></p>';\n const empty = open === '' && !blocks.some((b) => b.start >= at);\n const left =\n `${source.slice(0, from)}${first}${source.slice(from, at)}${close}${before}</astl-page>` +\n `<astl-page id=\"${id}\"${language}>${empty ? '<p>' : open}`;\n const right = `${empty ? '</p>' : ''}${source.slice(at, to)}${first === '' ? '' : '</astl-page>'}${source.slice(to)}`;\n return { source: left + right, caret: left.length, id };\n}\n\n/**\n * An empty page (one empty paragraph) after the page `after`, else after the last page (`EditorAdapter.addPage`); in a\n * document without pages, after its content made the first page. The caret goes into the paragraph.\n */\nexport function addPageSource(source: string, after?: string): AddedPage {\n const doc = documentOf(source);\n const used = usedIds(source);\n const page = doc.pages.find((p) => attributeValue(p.startTag, 'id') === after) ?? doc.pages.at(-1);\n const head =\n page === undefined\n ? `${source.slice(0, doc.start)}<astl-page id=\"${freshPage(used)}\">${source.slice(doc.start, doc.end)}</astl-page>`\n : source.slice(0, page.end);\n const id = freshPage(used);\n const left = `${head}<astl-page id=\"${id}\"><p>`;\n return { source: `${left}</p></astl-page>${source.slice(page?.end ?? doc.end)}`, caret: left.length, id };\n}\n\n/**\n * The page `id` joined to the page before it (`EditorAdapter.mergePage`): the end tag of that page and the start tag\n * of this one go, so nothing between them is lost. The caret goes where its content starts. Null for the first page\n * or an id that is not a page's.\n */\nexport function mergePageSource(source: string, id: string): PageEdit | null {\n const { pages } = documentOf(source);\n const index = pages.findIndex((p) => attributeValue(p.startTag, 'id') === id);\n const end = pages[index - 1]?.endTag;\n const start = pages[index]?.startTag;\n if (index < 1 || end == null || start === undefined) return null;\n const left = source.slice(0, end.start) + source.slice(end.end, start.start);\n return { source: left + source.slice(start.end), caret: left.length };\n}\n","/**\n * The reference EditorAdapter: the source edited as text in a `<textarea>`. Elements are found with `scanElements`,\n * edits are string splices, so the author's formatting outside the edited element is never touched.\n */\nimport { DOC_TAG, type EditorAdapter, type EditorSelection, PAGE_TAG } from '@astl/core';\nimport { addPageSource, mergePageSource, type PageEdit, splitPageSource } from './pages.js';\nimport { type ScannedElement, scanElements, tokenize } from './scan.js';\n\nexport interface TextareaAdapter extends EditorAdapter {\n /** A page break at the caret, in the source text (`EditorAdapter.splitPage`). */\n splitPage(): string | null;\n /** An empty page after the page `after`, in the source text (`EditorAdapter.addPage`). */\n addPage(after?: string): string;\n /** The page `id` joined to the page before it, in the source text (`EditorAdapter.mergePage`). */\n mergePage(id: string): boolean;\n /** Removes the textarea listeners and every subscription. */\n destroy(): void;\n}\n\nconst SELECTION_EVENTS = ['select', 'keyup', 'click', 'focus'] as const;\n\nfunction same(a: EditorSelection | null, b: EditorSelection | null): boolean {\n return a?.id === b?.id && a?.tag === b?.tag;\n}\n\nconst isComponent = (el: ScannedElement) => el.tag !== PAGE_TAG;\n\n/**\n * Where an insertion may go without breaking the source: never inside a tag or comment, never inside a component\n * (it goes after it: components do not nest), never outside `<astl-doc>` (it goes to the end of the last page).\n */\nfunction insertionRange(source: string, start: number, end: number): [number, number] {\n const elements = scanElements(source);\n // A caret right before an element is not in it; a selection that touches an element is.\n const hit = elements.filter(\n (el) => isComponent(el) && (start === end ? el.start < start : el.start < end) && start < el.end,\n );\n const last = hit[hit.length - 1];\n if (last !== undefined) return [last.end, last.end];\n const tags = tokenize(source);\n const inside = (offset: number) => tags.find((tag) => tag.start < offset && offset < tag.end);\n const cut = inside(start);\n if (cut !== undefined) return [cut.end, cut.end];\n if (inside(end) !== undefined) return [start, start];\n const open = tags.find((tag) => tag.type === 'start' && tag.name === DOC_TAG);\n const close = tags.findLast((tag) => tag.type === 'end' && tag.name === DOC_TAG);\n if (open === undefined) return [start, end];\n if (start >= open.end && (close === undefined || end <= close.start)) return [start, end];\n const pages = elements.filter((el) => el.tag === PAGE_TAG);\n const page = pages[pages.length - 1];\n const pageClose =\n page && tags.find((tag) => tag.type === 'end' && tag.name === PAGE_TAG && tag.end === page.end);\n const at = pageClose?.start ?? close?.start ?? source.length;\n return [at, at];\n}\n\n/** Puts the caret of a textarea at `offset` and scrolls the line into view (the caret line, approximately). */\nfunction reveal(textarea: HTMLTextAreaElement, offset: number): void {\n const line = textarea.value.slice(0, offset).split('\\n').length - 1;\n const height = Number.parseFloat(getComputedStyle(textarea).lineHeight) || 20;\n textarea.scrollTop = Math.max(0, line * height - textarea.clientHeight / 3);\n textarea.setSelectionRange(offset, offset);\n}\n\nexport function createTextareaAdapter(textarea: HTMLTextAreaElement): TextareaAdapter {\n const changes = new Set<() => void>();\n const selections = new Set<(selection: EditorSelection | null) => void>();\n let cache: { readonly value: string; readonly elements: ScannedElement[] } | null = null;\n const elements = (): ScannedElement[] => {\n const value = textarea.value;\n if (cache?.value !== value) cache = { value, elements: scanElements(value) };\n return cache.elements;\n };\n const component = (id: string) => elements().find((el) => isComponent(el) && el.id === id) ?? null;\n\n const current = (): EditorSelection | null => {\n const caret = textarea.selectionStart;\n const el = elements().find((e) => isComponent(e) && e.start <= caret && caret < e.end);\n return el?.id ? { id: el.id, tag: el.tag } : null;\n };\n let last = current();\n const emitSelection = () => {\n const now = current();\n if (same(now, last)) return;\n last = now;\n for (const listener of [...selections]) listener(now);\n };\n const emitChange = () => {\n for (const listener of [...changes]) listener();\n emitSelection();\n };\n\n textarea.addEventListener('input', emitChange);\n for (const type of SELECTION_EVENTS) textarea.addEventListener(type, emitSelection);\n\n const setSource = (source: string) => {\n // Only the span that differs is replaced, so a change at one place (the document's start tag, from the\n // inspector) leaves the caret where it was in the text around it.\n const old = textarea.value;\n const shorter = Math.min(old.length, source.length);\n let start = 0;\n while (start < shorter && old[start] === source[start]) start++;\n let end = 0;\n while (end < shorter - start && old[old.length - 1 - end] === source[source.length - 1 - end]) end++;\n textarea.setRangeText(source.slice(start, source.length - end), start, old.length - end, 'preserve');\n emitChange();\n };\n /** A page edit (`pages.ts`): the new source, then the caret where the edit puts it. */\n const apply = (edit: PageEdit) => {\n setSource(edit.source);\n reveal(textarea, edit.caret);\n emitSelection();\n };\n\n return {\n getSource: () => textarea.value,\n setSource,\n insert(html) {\n const [start, end] = insertionRange(textarea.value, textarea.selectionStart, textarea.selectionEnd);\n // The inserted element ends up selected: the inspector shows it and the next insert goes after it.\n textarea.setRangeText(html, start, end, 'select');\n emitChange();\n },\n getElement(id) {\n const el = component(id);\n return el === null ? null : textarea.value.slice(el.start, el.end);\n },\n replaceElement(id, html) {\n const el = component(id);\n if (el === null) return;\n const { selectionStart, selectionEnd, selectionDirection } = textarea;\n const delta = html.length - (el.end - el.start);\n // A caret inside the element stays inside it (at most on its last character); later offsets shift.\n const map = (offset: number) =>\n offset < el.start\n ? offset\n : offset >= el.end\n ? offset + delta\n : Math.min(offset, el.start + Math.max(0, html.length - 1));\n textarea.setRangeText(html, el.start, el.end, 'preserve');\n textarea.setSelectionRange(map(selectionStart), map(selectionEnd), selectionDirection);\n emitChange();\n },\n getSelection: current,\n select(id) {\n const el = elements().find((e) => e.id === id);\n if (el === undefined) return;\n reveal(textarea, el.start);\n textarea.focus();\n emitSelection();\n },\n splitPage() {\n const edit = splitPageSource(textarea.value, textarea.selectionStart);\n if (edit !== null) apply(edit);\n return edit?.id ?? null;\n },\n addPage(after) {\n const edit = addPageSource(textarea.value, after);\n apply(edit);\n return edit.id;\n },\n mergePage(id) {\n const edit = mergePageSource(textarea.value, id);\n if (edit !== null) apply(edit);\n return edit !== null;\n },\n onChange(listener) {\n changes.add(listener);\n return () => changes.delete(listener);\n },\n onSelectionChange(listener) {\n selections.add(listener);\n return () => selections.delete(listener);\n },\n destroy() {\n textarea.removeEventListener('input', emitChange);\n for (const type of SELECTION_EVENTS) textarea.removeEventListener(type, emitSelection);\n changes.clear();\n selections.clear();\n },\n };\n}\n","import{nothing as r}from\"../lit-html.js\";import{directive as t,Directive as e}from\"../directive.js\";import{setCommittedValue as s}from\"../directive-helpers.js\";\n/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */const i=t(class extends e{constructor(){super(...arguments),this.key=r}render(r,t){return this.key=r,t}update(r,[t,e]){return t!==this.key&&(s(r),this.key=t),e}});export{i as keyed};\n//# sourceMappingURL=keyed.js.map\n","/**\n * `<astl-editor>`: the authoring kit (toolbar, inspector, issues, preview) around an editing surface. The surface is\n * TipTap by default, imported on demand; any other editor plugs in through `adapter` and a `slot=\"surface\"` child, and\n * then TipTap is never loaded.\n */\nimport {\n type AttemptPolicy,\n type ComponentDefinition,\n type ComponentManifest,\n directionOf,\n type EditorAdapter,\n type EditorDescriptor,\n type Engine,\n type GroundColors,\n type Issue,\n type MessageCatalog,\n type MessageParams,\n type NormalisationProfile,\n negotiateLocale,\n PRACTICE_POLICY,\n type SlotKind,\n type StyleTemplate,\n type UrlPolicy,\n} from '@astl/core';\nimport {\n type AstlPictureDialog,\n type AstlPreview,\n type AstlToolbar,\n type Authoring,\n createAuthoring,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n EDITOR_NAMESPACE,\n type EditorFont,\n type EditorStylePreset,\n editorMessages,\n type Outline,\n type PickPicture,\n type ToolbarView,\n type UploadAsset,\n} from '@astl/editor';\nimport { createEngine } from '@astl/engine';\nimport type { ElementEntry } from '@astl/player';\nimport { type ThemeSetting, tokens, tokensCss } from '@astl/tokens';\nimport {\n type CSSResult,\n type CSSResultGroup,\n css,\n html,\n LitElement,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n unsafeCSS,\n} from 'lit';\nimport { keyed } from 'lit/directives/keyed.js';\nimport type { SurfaceChange } from './blocks.js';\nimport type { DefineEditorOptions, EditorHostView } from './define.js';\nimport type { Surface } from './surface.js';\n\n/**\n * Every token as `inherit` on `selector`, for elements that redeclare the tokens on their own `:host` (the kit\n * elements): a rule from the outer tree wins over `:host`, so tokens set on `<astl-editor>` reach them. The kit's\n * preview forwards them to its player the same way.\n */\nfunction inheritTokens(selector: string): CSSResult {\n const names = [tokens.scale, tokens.themes.light, tokens.themeScale.light].flatMap(Object.keys);\n const lines = ['color-scheme: inherit;', ...names.map((name) => `--astl-${name}: inherit;`)];\n return unsafeCSS(`${selector} {\\n${lines.join('\\n')}\\n}`);\n}\n\n/**\n * The shadow root of `<astl-editor>`: tokens, the toolbar over the surface beside the kit, everything in one column\n * when narrow. The surface's own stylesheet comes with the surface (`styles.ts`).\n */\nconst editorStyles: CSSResultGroup = [\n // Tokens sit on :host so host pages can override any --astl-* property on <astl-editor> itself.\n unsafeCSS(tokensCss(':host')),\n inheritTokens('astl-toolbar, astl-inspector, astl-issues, astl-preview, astl-picture-dialog'),\n css`\n :host {\n display: block;\n container-type: inline-size;\n color: var(--astl-ink);\n font-family: var(--astl-font-body);\n font-size: var(--astl-size-ui);\n line-height: 1.4;\n }\n :host([hidden]) {\n display: none;\n }\n `,\n // The bands are a column of flex items, not a grid: the spec makes a grid item's containing block its grid area,\n // which may hold a host's sticky toolbar (`::part(toolbar)`) to its own row; a flex item's is the whole column.\n css`\n .layout {\n display: flex;\n flex-direction: column;\n gap: var(--astl-editor-layout-gap, var(--astl-space-4));\n }\n .work {\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n align-items: start;\n gap: var(--astl-space-4);\n }\n .surface,\n .side,\n .start,\n .end {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-4);\n min-inline-size: 0;\n }\n .surface {\n position: relative;\n }\n ::slotted(*) {\n box-sizing: border-box;\n inline-size: 100%;\n max-inline-size: 100%;\n }\n .status {\n margin: 0;\n padding: var(--astl-space-4);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n color: var(--astl-ink-muted);\n }\n `,\n // The side column and the host's columns in another view, and a host column with nothing slotted: out of the way (the\n // grid keeps no track and no gap for them). The notice line with nothing to say: out of sight, but still in the\n // accessibility tree, so its next message is announced.\n css`\n .side[hidden],\n .start[hidden],\n .end[hidden] {\n display: none;\n }\n .status.idle {\n position: absolute;\n inline-size: 1px;\n block-size: 1px;\n padding: 0;\n border: 0;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n `,\n // The status line under the toolbar: the counts in mono, then whether it is ready to share (in words, never the\n // colour alone).\n css`\n .status-line {\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n gap: 0 var(--astl-space-3);\n margin: 0;\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n .counts {\n font-family: var(--astl-font-mono);\n }\n .counts span + span::before {\n content: '\\\\00b7' / '';\n margin-inline: var(--astl-space-1);\n }\n .ready {\n color: var(--astl-success);\n font-weight: 600;\n }\n .error {\n color: var(--astl-danger);\n }\n `,\n // Wide: one row, between the toolbar and the preview: the host's `start` column, the surface, the side column (3:2 with\n // the surface, at least 18rem), the host's `end` column. A row, not a grid, so a column that is not there takes no\n // track and no gap. The side column and the host's columns stay in view while the content scrolls, within the work\n // row only (never over the preview), each scrolling on its own when taller than the window.\n css`\n @container (min-inline-size: 48rem) {\n .work {\n display: flex;\n }\n .surface {\n flex: 3 1 0;\n }\n .side {\n flex: 2 1 0;\n min-inline-size: 18rem;\n }\n .start,\n .end {\n flex: none;\n }\n .side,\n .start,\n .end {\n position: sticky;\n inset-block-start: var(--astl-editor-sticky-top, var(--astl-space-4));\n max-block-size: calc(100dvh - var(--astl-editor-sticky-top, var(--astl-space-4)) - var(--astl-space-4));\n overflow-y: auto;\n padding: var(--astl-focus-width);\n margin: calc(-1 * var(--astl-focus-width));\n }\n }\n `,\n];\n\n/** What `defineEditor` registered: shared by every `<astl-editor>` of this module instance. */\ninterface Registered {\n readonly components: ReadonlyMap<string, ComponentDefinition>;\n readonly editors: ReadonlyMap<string, EditorDescriptor>;\n readonly elements: ReadonlyMap<string, ElementEntry>;\n readonly styleTemplates: ReadonlyMap<string, StyleTemplate>;\n readonly slotKinds: ReadonlyMap<string, SlotKind>;\n readonly catalogs: readonly MessageCatalog[];\n readonly profile: Partial<NormalisationProfile>;\n readonly urlPolicy: UrlPolicy | null;\n readonly groundColors: GroundColors | null;\n readonly uploadAsset: UploadAsset | null;\n readonly pickPicture: PickPicture | null;\n /** The style controls' fonts (`DefineEditorOptions.fonts`). */\n readonly fonts: readonly EditorFont[];\n /** The ready styles (`DefineEditorOptions.styles`). */\n readonly styles: readonly EditorStylePreset[];\n /** The toolbar's featured inserts (`DefineEditorOptions.featured`). */\n readonly featured: readonly string[];\n /** The host's views (`DefineEditorOptions.views`). */\n readonly views: readonly EditorHostView[];\n /** The insert menus' catalogs (`DefineEditorOptions.menuMessages`). */\n readonly menuMessages: (() => Promise<readonly MessageCatalog[]>) | null;\n /** The engine of every registered component, for editors without a `components` list. */\n readonly engine: Engine;\n /** Bumped on every registration. */\n readonly version: number;\n}\n\n/** The tag of a preview element: the one place that reads the shape of `elements`. */\nconst elementTag = (element: ElementEntry): string =>\n 'load' in element ? element.tag : element.manifest.tag;\n\nlet secret: string | null = null;\n\n/**\n * The preview compiles in the browser, so its secret only keeps preview ids apart from published ones: a random one\n * per page, never a known value.\n */\nfunction previewSecret(): string {\n secret ??= Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) =>\n b.toString(16).padStart(2, '0'),\n ).join('');\n return secret;\n}\n\ntype Lists = Omit<Registered, 'engine' | 'version'>;\n\nfunction engineOf(lists: Lists, components: readonly ComponentDefinition[]): Engine {\n return createEngine({\n components,\n secret: previewSecret(),\n slotKinds: [...lists.slotKinds.values()],\n profile: lists.profile,\n catalogs: lists.catalogs,\n styleTemplates: [...lists.styleTemplates.values()],\n ...(lists.urlPolicy === null ? {} : { urlPolicy: lists.urlPolicy }),\n ...(lists.groundColors === null ? {} : { groundColors: lists.groundColors }),\n });\n}\n\nconst EMPTY: Lists = {\n components: new Map(),\n editors: new Map(),\n elements: new Map(),\n styleTemplates: new Map(),\n slotKinds: new Map(),\n catalogs: [],\n profile: {},\n urlPolicy: null,\n groundColors: null,\n uploadAsset: null,\n pickPicture: null,\n fonts: DEFAULT_FONTS,\n styles: DEFAULT_STYLES,\n featured: [],\n views: [],\n menuMessages: null,\n};\n\nlet registered: Registered | null = null;\n\n/** Without `defineEditor` (the class defined by hand): nothing registered. */\nfunction current(): Registered {\n registered ??= { ...EMPTY, engine: engineOf(EMPTY, []), version: 0 };\n return registered;\n}\n\n/** Connected editors: a registration re-renders them. */\nconst connected = new Set<AstlEditor>();\n\n/** `items` added by key: the same object again is skipped, another object under a taken key throws. */\nfunction added<T>(\n into: ReadonlyMap<string, T>,\n items: readonly T[] | undefined,\n key: (item: T) => string,\n what: string,\n): ReadonlyMap<string, T> {\n const out = new Map(into);\n for (const item of items ?? []) {\n const name = key(item);\n const taken = out.get(name);\n if (taken !== undefined && taken !== item) throw new Error(`${what} ${name} is already registered`);\n out.set(name, item);\n }\n return out;\n}\n\n/** Adds to what every `<astl-editor>` offers (`defineEditor`). Checks everything before anything changes. */\nexport function register(options: DefineEditorOptions): void {\n const before = registered ?? { ...EMPTY, version: 0 };\n const tag = (item: { readonly manifest: ComponentManifest }) => item.manifest.tag;\n const lists: Lists = {\n components: added(before.components, options.components, tag, 'Component'),\n editors: added(before.editors, options.editors, tag, 'Editor descriptor'),\n elements: added(before.elements, options.elements, elementTag, 'Preview element'),\n styleTemplates: added(before.styleTemplates, options.styleTemplates, (t) => t.name, 'Style template'),\n slotKinds: added(before.slotKinds, options.slotKinds, (k) => k.kind, 'Slot kind'),\n catalogs: [...new Set([...before.catalogs, ...(options.catalogs ?? [])])],\n profile: { ...before.profile, ...options.profile },\n urlPolicy: options.urlPolicy ?? before.urlPolicy,\n groundColors: options.groundColors ?? before.groundColors,\n uploadAsset: options.uploadAsset ?? before.uploadAsset,\n pickPicture: options.pickPicture ?? before.pickPicture,\n fonts: options.fonts ?? before.fonts,\n styles: options.styles ?? before.styles,\n featured: options.featured ?? before.featured,\n views: options.views ?? before.views,\n menuMessages: options.menuMessages ?? before.menuMessages,\n };\n // Nothing new (the same objects again): connected editors keep their surface, cursor and undo history.\n const maps = ['components', 'editors', 'elements', 'styleTemplates', 'slotKinds'] as const;\n const profile = (p: Lists['profile']) => JSON.stringify(Object.entries(p).sort());\n if (\n registered !== null &&\n maps.every((list) => lists[list].size === before[list].size) &&\n lists.catalogs.length === before.catalogs.length &&\n lists.urlPolicy === before.urlPolicy &&\n JSON.stringify(lists.groundColors) === JSON.stringify(before.groundColors) &&\n lists.uploadAsset === before.uploadAsset &&\n lists.pickPicture === before.pickPicture &&\n lists.menuMessages === before.menuMessages &&\n JSON.stringify(lists.fonts) === JSON.stringify(before.fonts) &&\n JSON.stringify(lists.styles) === JSON.stringify(before.styles) &&\n lists.featured.join(' ') === before.featured.join(' ') &&\n JSON.stringify(lists.views) === JSON.stringify(before.views) &&\n profile(lists.profile) === profile(before.profile)\n ) {\n return;\n }\n // The engine and the kit check definitions and descriptors now, not when an editor first renders.\n const engine = engineOf(lists, [...lists.components.values()]);\n createAuthoring({\n engine,\n descriptors: [...lists.editors.values()],\n locale: 'en',\n fonts: lists.fonts,\n styles: lists.styles,\n });\n registered = { ...lists, engine, version: before.version + 1 };\n for (const editor of connected) editor.requestUpdate();\n}\n\n/** The authoring of one editor: every registered type, or those `allowed` names. */\nfunction authoringFor(r: Registered, locale: string, allowed: readonly string[] | null): Authoring {\n const keep = <T>(items: ReadonlyMap<string, T>) =>\n [...items.entries()].filter(([tag]) => allowed === null || allowed.includes(tag)).map(([, item]) => item);\n return createAuthoring({\n engine: allowed === null ? r.engine : engineOf(r, keep(r.components)),\n descriptors: keep(r.editors),\n elements: keep(r.elements),\n locale,\n catalogs: r.catalogs,\n styleTemplates: [...r.styleTemplates.values()],\n fonts: r.fonts,\n styles: r.styles,\n ...(r.urlPolicy === null ? {} : { urlPolicy: r.urlPolicy }),\n ...(r.uploadAsset === null ? {} : { uploadAsset: r.uploadAsset }),\n ...(r.pickPicture === null ? {} : { pickPicture: r.pickPicture }),\n ...(r.menuMessages === null ? {} : { menuMessages: r.menuMessages }),\n });\n}\n\nconst THEMES: readonly ThemeSetting[] = ['light', 'dark', 'hc', 'auto'];\n\n/** A message of the status line: a key of the kit's namespace and its parameters. */\ninterface Notice {\n readonly key: string;\n readonly params?: MessageParams;\n}\nconst CHANGE = 'astl-editor-change';\nconst READY = 'astl-editor-ready';\nconst VIEW = 'astl-editor-view';\n\n/** The views of every editor: the surface, and the source as HTML. */\nconst OWN_VIEWS: readonly string[] = ['visual', 'source'];\n\n/** The status line counts this long after the last change, as the issues list does. */\nconst COUNT_DELAY_MS = 300;\n\n/** The side panels, in the order `<astl-editor>` shows them by default. */\nconst PANELS: readonly string[] = ['issues', 'inspector'];\n\n/** A space-separated list attribute as a list (null when absent). */\nconst listAttribute = {\n fromAttribute: (value: string | null) =>\n value === null ? null : value.split(/\\s+/).filter((tag) => tag !== ''),\n};\n\n/** The `views` attribute: a JSON list of `{ name, label }` (null when absent or not JSON). */\nconst viewsAttribute = {\n fromAttribute: (value: string | null): unknown => {\n try {\n return value === null ? null : JSON.parse(value);\n } catch {\n return null;\n }\n },\n};\n\n/** The icon parts of the toolbar, forwarded so hosts can draw their own icons (`::part(icon-text-t)`). */\nconst KIT_ICONS: readonly string[] = [\n 'chevron',\n 'bold',\n 'italic',\n 'underline',\n 'link',\n 'bulleted',\n 'numbered',\n 'undo',\n 'redo',\n 'wrap',\n 'text',\n 'image',\n 'files',\n 'add',\n 'templates',\n];\n\n/** The inspector's parts, forwarded so hosts can restyle its header, banners and fields (`::part(inspector-issue)`). */\nconst INSPECTOR_PARTS =\n 'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style';\n\n/** The built-in surface module, once imported. */\nlet surfaces: typeof import('./surface.js') | null = null;\n/** The source view's module, once imported (when the view first opens). */\nlet sourceViews: typeof import('./source-view.js') | null = null;\n\nexport class AstlEditor extends LitElement {\n static override properties: PropertyDeclarations = {\n locale: {},\n components: { converter: listAttribute },\n featured: { converter: listAttribute },\n panels: { converter: listAttribute },\n view: {},\n views: { converter: viewsAttribute },\n theme: {},\n previewPolicy: { attribute: false },\n adapter: { attribute: false },\n };\n\n static override styles: CSSResultGroup = editorStyles;\n\n /** UI locale (`en`, `pl`); default: the `lang` attribute, else the browser languages, else `en`. */\n declare locale: string | null;\n /**\n * The component types authors can use (space-separated tags in the attribute); null: every registered type. Others\n * stay in the document, reported as unknown elements.\n */\n declare components: readonly string[] | null;\n /**\n * The toolbar's featured inserts, as buttons before \"More\" (space-separated in the attribute): component tags,\n * `tag:template` for a named starter, and `text`, `picture`, `page-break`. Null: the list `defineEditor` got.\n */\n declare featured: readonly string[] | null;\n /**\n * The side column's panels, in order (space-separated in the attribute): `issues` and `inspector`. Null: both,\n * issues first. Empty: no side column, the surface takes the width; a host then shows its own `<astl-inspector>`\n * or `<astl-issues>`, wired with `authoring` and `adapter` once the editor is ready.\n */\n declare panels: readonly string[] | null;\n /**\n * What the editor shows: `visual` (default) the surface; `source` the document's HTML in a text area, which leaving\n * applies (with errors the editor stays there and lists them, so no text is lost); or the `name` of one of `views`.\n * The toolbar's view switch sets it; each change fires `astl-editor-view` (bubbles, composed; `detail.view`).\n */\n declare view: string;\n /**\n * The host's views, after \"Visual\" and \"HTML\" in the view switch: `{ name, label }` each (the attribute: a JSON\n * list). One shows the host's `slot=\"view-<name>\"` children in place of the editor. Null: the list `defineEditor` got.\n */\n declare views: readonly EditorHostView[] | null;\n /** `light`, `dark`, `hc` or `auto` (the system's light or dark), passed on as `data-theme`. */\n declare theme: ThemeSetting | null;\n /**\n * The policy the preview plays under: the one the host's students get, when it offers less than practice (no hints,\n * no check of one interaction). Null: `PRACTICE_POLICY`. A change plays a shown preview again.\n */\n declare previewPolicy: AttemptPolicy | null;\n /**\n * The editor the kit drives. Default: TipTap, on a surface this element creates when it first renders without an\n * adapter and without a `slot=\"surface\"` child. Setting another adapter swaps the editor; null brings the TipTap\n * surface back (with its document), unless a `slot=\"surface\"` child is there.\n */\n declare adapter: EditorAdapter | null;\n\n /** A value set while there is no adapter to take it. */\n #pending: string | null = null;\n /** Whether this element uses the built-in surface: decided when it first connects. */\n #builtIn: boolean | null = null;\n #surface: Surface | null = null;\n #opening = false;\n #failed = false;\n /**\n * The status line's message until the next edit: why a pasted or dropped picture was not inserted (no upload), or\n * the page an edit added or joined.\n */\n #notice: Notice | null = null;\n /** The page or block the surface's edit changed, waiting for that edit's change event, which shows it. */\n #pageNotice: Notice | null = null;\n /** Counts notices: the same message again is a new one for screen readers. */\n #notices = 0;\n /** The adapter the last ready event was for. */\n #readyFor: EditorAdapter | null = null;\n #resolveReady: () => void = () => {};\n readonly #ready: Promise<void> = new Promise((resolve) => {\n this.#resolveReady = resolve;\n });\n\n /** What the surface asks about pictures: the picture dialog of this element. */\n #pictures = {\n ask: (request: Parameters<AstlPictureDialog['ask']>[0]) =>\n this.renderRoot.querySelector<AstlPictureDialog>('astl-picture-dialog')?.ask(request) ??\n Promise.resolve(null),\n refuse: () => {\n this.#notice = { key: 'picture.pasteRefused' };\n this.requestUpdate();\n },\n style: (kind: 'picture' | 'figure' | 'component') => {\n void this.renderRoot.querySelector<AstlToolbar>('astl-toolbar')?.openStyle(kind);\n },\n };\n\n /** What the surface tells of pages and blocks: a page added, joined or deleted, a block moved or deleted. */\n #pages = (change: SurfaceChange) => {\n this.#pageNotice = change;\n };\n\n /** Whether the host's `start` and `end` slots have elements: a column exists only while its slot does. */\n #slotted = { start: false, end: false };\n #slotChange = (event: Event): void => {\n const slot = event.target as HTMLSlotElement;\n const name = slot.name === 'end' ? 'end' : 'start';\n const has = slot.assignedElements().length > 0;\n if (this.#slotted[name] === has) return;\n this.#slotted[name] = has;\n this.requestUpdate();\n };\n\n /**\n * The source view: the value laid out for reading when it opened (null until it shows), the author's text once they\n * type (null before), and the errors that kept it there.\n */\n #shown: string | null = null;\n #draft: string | null = null;\n #errors: readonly Issue[] = [];\n /** What the status line counts, a moment after each change. */\n #outline: Outline | null = null;\n #counting: ReturnType<typeof setTimeout> | undefined;\n #authoring: { readonly key: string; readonly authoring: Authoring } | null = null;\n #subscription: { readonly adapter: EditorAdapter; readonly off: () => void } | null = null;\n\n constructor() {\n super();\n this.locale = null;\n this.components = null;\n this.featured = null;\n this.panels = null;\n this.view = 'visual';\n this.views = null;\n this.theme = 'auto';\n this.previewPolicy = null;\n this.adapter = null;\n // A value set before the element was defined is an own property that hides the accessor.\n if (Object.hasOwn(this, 'value')) {\n const value: unknown = (this as { value?: unknown }).value;\n delete (this as { value?: unknown }).value;\n if (typeof value === 'string') this.value = value;\n }\n }\n\n /** The source HTML (`<astl-doc>`): the adapter's, or a value waiting for it, or an empty document. */\n get value(): string {\n return (\n this.adapter?.getSource() ?? this.#pending ?? `<astl-doc lang=\"${this.authoring.locale}\"></astl-doc>`\n );\n }\n\n set value(source: string) {\n if (this.adapter === null) this.#pending = source;\n else this.adapter.setSource(source);\n }\n\n /**\n * Resolves when the editor is first ready: its surface loaded (or the host's `adapter` set) and the value in place,\n * so `adapter`, `authoring` and `value` are usable. Each time an editor becomes ready (again after a swap or a\n * reconnect, with a new `adapter`), `astl-editor-ready` fires (bubbles, composed).\n */\n get ready(): Promise<void> {\n return this.#ready;\n }\n\n /**\n * Compiles the current value and plays it in the preview, as the preview's own button does. Resolves when it plays,\n * or shows why it cannot.\n */\n async preview(): Promise<void> {\n await this.updateComplete;\n await this.renderRoot.querySelector<AstlPreview>('astl-preview')?.refresh();\n }\n\n /** The kit's logic, built from the registrations, the UI locale and `components`. */\n get authoring(): Authoring {\n const r = current();\n const locale = this.#uiLocale(r);\n // The property also takes the attribute's form, a space-separated string.\n const given = this.components as readonly string[] | string | null;\n const allowed = typeof given === 'string' ? given.split(/\\s+/).filter((tag) => tag !== '') : given;\n const key = `${r.version}\\n${locale}\\n${allowed === null ? '*' : allowed.join(' ')}`;\n if (this.#authoring?.key !== key) this.#authoring = { key, authoring: authoringFor(r, locale, allowed) };\n return this.#authoring.authoring;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n connected.add(this);\n // Back in the document: the built-in surface again. The first decision waits for the first update, when Lit has\n // applied the properties set before the element was defined (an `adapter`).\n if (this.#builtIn === true) void this.#open();\n this.#subscribe();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n connected.delete(this);\n clearTimeout(this.#counting);\n this.#readyFor = null;\n this.#subscribe();\n // ProseMirror listens on the document: a removed editor is destroyed, its source kept for a reconnect.\n const surface = this.#surface;\n if (surface === null) return;\n this.#pending = surface.adapter.getSource();\n surface.destroy();\n this.#surface = null;\n this.adapter = null;\n }\n\n /** The host's views: the element's, else the registered ones. */\n #hostViews(): readonly EditorHostView[] {\n const views = this.views ?? current().views;\n return Array.isArray(views) ? views : [];\n }\n\n /** The view on show: `view` when it names one, else `visual`. */\n #view(): string {\n const names = [...OWN_VIEWS, ...this.#hostViews().map((v) => v.name)];\n return names.includes(this.view) ? this.view : 'visual';\n }\n\n /**\n * Applies the source view's text, unless it has errors: then they show and the editor stays there. Only text that\n * says something else than what was shown is applied (laid out the same, it is the same document): looking changes\n * nothing.\n */\n #leaveSource(): boolean {\n const text = this.#draft ?? this.#shown ?? this.value;\n const errors = this.authoring.validate(text).issues.filter((issue) => issue.severity === 'error');\n this.#errors = errors;\n if (errors.length > 0) {\n this.#notice = { key: 'view.sourceErrors', params: { n: errors.length } };\n this.#notices++;\n return false;\n }\n if (this.#draft !== null && sourceViews?.formatHtml(this.#draft) !== this.#shown)\n this.value = this.#draft;\n this.#draft = null;\n return true;\n }\n\n /** Counts the document for the status line, after `delay` ms. */\n #count(delay: number): void {\n clearTimeout(this.#counting);\n this.#counting = setTimeout(() => {\n const adapter = this.adapter;\n this.#outline = adapter === null ? null : this.authoring.outline(adapter.getSource());\n this.requestUpdate();\n }, delay);\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('theme')) this.dataset.theme = this.#theme();\n if (changed.has('view')) {\n const before = changed.get('view');\n if (before === 'source' && this.view !== 'source' && !this.#leaveSource()) this.view = 'source';\n else if (this.view === 'source' && before !== 'source') {\n this.#shown = this.#draft = null;\n this.#errors = [];\n if (sourceViews === null) {\n import('./source-view.js').then(\n (module) => {\n sourceViews = module;\n this.requestUpdate();\n },\n (error: unknown) => console.error(error),\n );\n }\n }\n }\n const surface = this.#surface;\n if (surface !== null && this.adapter !== surface.adapter) {\n // Another editor plugged in, or none (null): the built-in one goes, keeping its document for a comeback.\n if (this.adapter === null) this.#pending = surface.adapter.getSource();\n surface.destroy();\n this.#surface = null;\n }\n if (this.adapter !== null && this.#surface === null) {\n this.#builtIn = false;\n if (this.#pending !== null) this.adapter.setSource(this.#pending);\n this.#pending = null;\n } else if (this.adapter === null && this.#surface === null) {\n // The first update, or the host took its editor away: the built-in surface, unless one is in the slot.\n if (this.isConnected && (this.#builtIn === null || changed.has('adapter'))) this.#decide();\n } else if (this.#surface !== null && surfaces !== null && this.#surface.authoring !== this.authoring) {\n // Other labels or other types: the same document in a new editor.\n const source = this.#surface.adapter.getSource();\n this.#surface.destroy();\n this.#surface = surfaces.createSurface(\n this,\n this.authoring,\n current().engine.manifests,\n source,\n this.#pictures,\n this.#pages,\n );\n this.adapter = this.#surface.adapter;\n }\n this.#subscribe();\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n // The preview reads its theme when it renders.\n if (changed.has('theme')) this.renderRoot.querySelector<LitElement>('astl-preview')?.requestUpdate();\n const adapter = this.adapter;\n if (adapter !== null && adapter !== this.#readyFor && this.isConnected) {\n this.#readyFor = adapter;\n this.#count(0);\n this.#resolveReady();\n this.dispatchEvent(new Event(READY, { bubbles: true, composed: true }));\n }\n const before = changed.get('view');\n if (changed.has('view') && before !== undefined && before !== this.view) {\n this.dispatchEvent(\n new CustomEvent(VIEW, { detail: { view: this.view }, bubbles: true, composed: true }),\n );\n }\n }\n\n #decide(): void {\n // An element the HTML parser is still filling may not have its slot=\"surface\" child yet.\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => this.requestUpdate('adapter'), { once: true });\n return;\n }\n this.#builtIn = this.querySelector(':scope > [slot=\"surface\"]') === null;\n if (this.#builtIn) void this.#open();\n }\n\n async #open(): Promise<void> {\n if (this.#opening || this.#surface !== null) return;\n this.#opening = true;\n this.#failed = false;\n try {\n surfaces ??= await import('./surface.js');\n if (!this.isConnected || !this.#builtIn || this.adapter !== null || this.#surface !== null) return;\n this.#surface = surfaces.createSurface(\n this,\n this.authoring,\n current().engine.manifests,\n this.value,\n this.#pictures,\n this.#pages,\n );\n this.#pending = null;\n this.adapter = this.#surface.adapter;\n } catch (error) {\n // A failed chunk load is not cached by every browser: the next connect tries again.\n this.#failed = true;\n console.error(error);\n } finally {\n this.#opening = false;\n this.requestUpdate();\n }\n }\n\n #subscribe(): void {\n const adapter = this.isConnected ? this.adapter : null;\n if ((this.#subscription?.adapter ?? null) === adapter) return;\n this.#subscription?.off();\n this.#subscription =\n adapter === null\n ? null\n : {\n adapter,\n off: adapter.onChange(() => {\n const notice = this.#pageNotice;\n this.#pageNotice = null;\n if (this.#notice !== null || notice !== null) {\n this.#notice = notice;\n if (notice !== null) this.#notices++;\n this.requestUpdate();\n }\n this.#count(COUNT_DELAY_MS);\n this.dispatchEvent(new Event(CHANGE, { bubbles: true, composed: true }));\n }),\n };\n }\n\n #uiLocale(r: Registered): string {\n const requested = this.locale\n ? [this.locale]\n : this.lang\n ? [this.lang]\n : [...(navigator.languages ?? []), navigator.language].filter((l) => !!l);\n const available = [...editorMessages, ...r.catalogs]\n .filter((c) => c.namespace === EDITOR_NAMESPACE)\n .map((c) => c.locale);\n return negotiateLocale(requested, [...new Set(available)], 'en');\n }\n\n #theme(): ThemeSetting {\n const theme = this.theme;\n return theme !== null && THEMES.includes(theme) ? theme : 'auto';\n }\n\n protected override render(): TemplateResult {\n const { authoring, adapter } = this;\n const theme = this.#theme();\n const waiting: Notice | null = this.#failed\n ? { key: 'surface.failed' }\n : this.#builtIn && adapter === null\n ? { key: 'surface.loading' }\n : this.#notice;\n const lang = authoring.locale;\n // Given as a string (the attribute's form) or a list.\n const list = (value: readonly string[] | string | null) =>\n typeof value === 'string' ? value.split(/\\s+/).filter((name) => name !== '') : value;\n const featured = list(this.featured) ?? current().featured;\n const panels = (list(this.panels) ?? PANELS).filter((name) => PANELS.includes(name));\n const icons = new Set([\n ...KIT_ICONS,\n ...authoring.descriptors.flatMap((d) => [d.icon, ...(d.templates ?? []).map((t) => t.icon ?? d.icon)]),\n ]);\n const exported = [\n 'toolbar: toolbar-bar',\n 'button: toolbar-button',\n 'icon-button: toolbar-icon-button',\n 'views: toolbar-views',\n 'view: toolbar-view',\n 'separator: toolbar-separator',\n 'icon: toolbar-icon',\n 'insert',\n 'menu: insert-menu',\n 'style-menu',\n 'style-colors',\n 'style-panel',\n ]\n .concat([...icons].map((name) => `icon-${name}`))\n .join(', ');\n const panel = (name: string) =>\n name === 'issues'\n ? html`<astl-issues part=\"issues\" data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-issues>`\n : html`<astl-inspector part=\"inspector\" exportparts=${INSPECTOR_PARTS} data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-inspector>`;\n const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);\n const view = this.#view();\n const views: ToolbarView[] = [\n ...OWN_VIEWS.map((name) => ({ name, label: t(`view.${name}`) })),\n ...this.#hostViews(),\n ];\n // The toolbar spans the editor, as a word processor's: above the text and the side column.\n // Another view takes the surface's place, without the side column; the notice line stays, the one live region.\n const away = view !== 'visual';\n return html`<div class=${panels.length === 0 || away ? 'layout solo' : 'layout'}>\n <astl-toolbar part=\"toolbar\" exportparts=${exported} data-theme=${theme} .authoring=${authoring}\n .adapter=${adapter} .featured=${featured} .views=${views} .view=${view}\n @astl-toolbar-view=${(event: CustomEvent<{ view: string }>) => {\n this.view = event.detail.view;\n }}></astl-toolbar>\n ${this.#statusLine()}\n <div class=\"work\" part=\"work\">\n <div class=\"start\" part=\"start\" ?hidden=${away || !this.#slotted.start}>\n <slot name=\"start\" @slotchange=${this.#slotChange}></slot>\n </div>\n <div class=\"surface\" part=\"surface\">\n ${away ? nothing : html`<slot name=\"surface\"></slot>`}\n ${view === 'source' ? this.#source() : away ? html`<slot name=\"view-${view}\"></slot>` : nothing}\n <p class=${waiting === null ? 'status idle' : 'status'} role=\"status\" lang=${lang} dir=${directionOf(lang)}\n >${keyed(this.#notices, waiting === null ? '' : authoring.t(EDITOR_NAMESPACE, waiting.key, waiting.params))}</p>\n <astl-picture-dialog data-theme=${theme} .authoring=${authoring}></astl-picture-dialog>\n </div>\n ${panels.length === 0 ? nothing : html`<div class=\"side\" part=\"side\" ?hidden=${away}>${panels.map(panel)}</div>`}\n <div class=\"end\" part=\"end\" ?hidden=${away || !this.#slotted.end}>\n <slot name=\"end\" @slotchange=${this.#slotChange}></slot>\n </div>\n </div>\n <astl-preview part=\"preview\" data-theme=${theme} .authoring=${authoring} .adapter=${adapter}\n .policy=${this.previewPolicy ?? PRACTICE_POLICY}></astl-preview>\n </div>`;\n }\n\n /**\n * The status line (`part=\"status-line\"`): how many elements and points the document has, then \"Ready to share\" or\n * its errors and warnings. Text to read, not a live region: the notice line stays the editor's one.\n */\n #statusLine(): TemplateResult | typeof nothing {\n const outline = this.#outline;\n if (outline === null) return nothing;\n const { authoring } = this;\n const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);\n const elements = outline.pages.reduce((n, page) => n + page.components.length, 0);\n const ready = outline.errors === 0;\n const lang = authoring.locale;\n return html`<p class=\"status-line\" part=\"status-line\" lang=${lang} dir=${directionOf(lang)}>\n <span class=\"counts\"><span>${t('status.elements', { n: elements })}</span>${\n outline.points === null\n ? nothing\n : html`<span>${t('surface.points', { points: outline.points })}</span>`\n }</span>\n <span class=${ready ? 'ready' : 'counts error'}>${\n ready\n ? t('status.ready')\n : html`<span>${t('status.errors', { n: outline.errors })}</span><span>${t('status.warnings', { n: outline.warnings })}</span>`\n }</span>\n </p>`;\n }\n\n /**\n * The source view (`source-view.ts`, nothing until its module has loaded), with the value laid out for reading once\n * per opening.\n */\n #source(): TemplateResult | typeof nothing {\n const views = sourceViews;\n if (views === null) return nothing;\n this.#shown ??= views.formatHtml(this.value);\n return views.renderSource(\n this.renderRoot,\n this.authoring,\n this.#draft ?? this.#shown,\n this.#errors,\n (text) => {\n this.#draft = text;\n },\n );\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-editor': AstlEditor;\n }\n interface HTMLElementEventMap {\n 'astl-editor-change': Event;\n 'astl-editor-ready': Event;\n }\n}\n","import type { EditorDescriptor, EngineOptions, MessageCatalog } from '@astl/core';\nimport {\n defineAuthoringElements,\n type EditorFont,\n type EditorStylePreset,\n type PickPicture,\n type UploadAsset,\n} from '@astl/editor';\nimport type { ElementEntry } from '@astl/player';\nimport { AstlEditor, register } from './element.js';\n\n/** The same option names, types and meanings as `createEngine` and `definePlayer`; the editor makes its own secret. */\nexport interface DefineEditorOptions extends Omit<EngineOptions, 'secret'> {\n /** Insert menu and inspector entries: one per type authors can add. */\n readonly editors: readonly EditorDescriptor[];\n /** Player elements for the preview, eager or lazy. */\n readonly elements: readonly ElementEntry[];\n /**\n * Stores a picture file and returns its address (it must pass `urlPolicy`): the picture dialog, pasted and dropped\n * pictures and picture fields use it. Without it, pictures are added by address only (or from `pickPicture`).\n * Reject with `UploadRefused` to tell the author why.\n */\n readonly uploadAsset?: UploadAsset;\n /**\n * Opens the host's own picture library and gives the chosen picture (its address must pass `urlPolicy`), or null:\n * the picture dialog and picture fields offer it beside the upload. The picture dialog closes while the library is\n * open, keeping what the author typed, so a modal of the host's own takes the pointer and the keys.\n */\n readonly pickPicture?: PickPicture;\n /**\n * Catalogs only the insert menus show (their one-line descriptions), loaded when a menu first opens;\n * `@astl/astrolabe` passes the built-in ones. Default: none (the menus show the names alone).\n */\n readonly menuMessages?: () => Promise<readonly MessageCatalog[]>;\n /**\n * The fonts the toolbar and the style form offer, in order: a name and a CSS stack the style allow-list keeps (any\n * other throws). A later call's list replaces it. Default: `DEFAULT_FONTS`, stacks every system has.\n */\n readonly fonts?: readonly EditorFont[];\n /**\n * The ready styles the style menu and the style form offer, in order; `[]`: none. A name `isStyleName` refuses, a\n * declaration the style allow-list refuses or a name given twice throws. A later call's list replaces it. Default:\n * `DEFAULT_STYLES`.\n */\n readonly styles?: readonly EditorStylePreset[];\n /** Default: the global `customElements`. */\n readonly registry?: CustomElementRegistry;\n /**\n * The toolbar's featured inserts, as buttons before \"Elements\": component tags, `tag:template` for a named starter,\n * and `text`, `picture`, `page-break`. A later call's list replaces it; an element's `featured` overrides it.\n * Default: none.\n */\n readonly featured?: readonly string[];\n /**\n * The host's views, after \"Visual\" and \"HTML\" in the view switch: each shows the host's content in the slot\n * `view-<name>` in place of the editor. A later call's list replaces it; an element's `views` overrides it.\n * Default: none.\n */\n readonly views?: readonly EditorHostView[];\n}\n\n/** A host view of `<astl-editor>`: its name (lower-case letters, digits and dashes) and its label in the switch. */\nexport interface EditorHostView {\n readonly name: string;\n readonly label: string;\n}\n\nconst TAG = 'astl-editor';\n\n/**\n * Registers components, editor descriptors, preview elements and looks for every `<astl-editor>`, and defines\n * `<astl-editor>` and the kit elements (nothing is defined on import). A second call adds to the first; a tag or a look\n * name already registered by another object throws, as two copies would otherwise mix silently.\n */\nexport function defineEditor(options: DefineEditorOptions): void {\n const registry = options.registry ?? customElements;\n const existing = registry.get(TAG);\n if (existing !== undefined && existing !== AstlEditor)\n throw new Error(`<${TAG}> is already defined by another class`);\n // The kit first: if it throws, nothing is registered.\n defineAuthoringElements(registry);\n register(options);\n if (existing === undefined) registry.define(TAG, AstlEditor);\n}\n","/**\n * `@astl/astrolabe/editor`: `<astl-editor>` with every built-in component, editor descriptor, preview element\n * and look. Only the main entry of `@astl/editor-tiptap`, never its `/tiptap` entry: importing this module\n * never loads TipTap, which `<astl-editor>` imports on demand when it creates its own surface. Hosts that build\n * their own TipTap editor install `@astl/editor-tiptap` and take `astrolabeExtensions` and\n * `createTiptapAdapter` from its `/tiptap` entry.\n */\nimport { builtInDefinitions } from '@astl/components/definitions';\nimport { builtInEditors } from '@astl/components/editors';\nimport { builtInElements } from '@astl/components/elements';\nimport type { MessageCatalog } from '@astl/core';\nimport {\n createAuthoring,\n createTextareaAdapter,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n loadStyleElements,\n STYLE_OPEN,\n UploadRefused,\n} from '@astl/editor';\nimport { type DefineEditorOptions, defineEditor as defineBaseEditor } from '@astl/editor-tiptap';\nimport { builtInStyleTemplates, tokens, tokensCss } from '@astl/tokens';\n\nexport * from '@astl/core';\nexport type {\n AstlStyleForm,\n AstlStyleRules,\n Authoring,\n AuthoringOptions,\n DescribeOptions,\n EditorFont,\n EditorStylePreset,\n Outline,\n OutlineBlock,\n OutlineComponent,\n OutlinePage,\n PickPicture,\n PreviewOptions,\n PreviewResult,\n StyleOpen,\n TextareaAdapter,\n UploadAsset,\n UploadedAsset,\n} from '@astl/editor';\nexport type { DefineEditorOptions } from '@astl/editor-tiptap';\nexport { AstlEditor } from '@astl/editor-tiptap';\n// `tokensCss`: the --astl-* tokens for the page around the editor, with the same themes.\n// `createAuthoring`: the kit's logic without the element (validate, outline, preview), Node-safe.\n// `UploadRefused`: what a host's upload or picture library rejects with to tell the author why.\n// `DEFAULT_FONTS` and `DEFAULT_STYLES`: the `fonts` and `styles` defaults, to extend. `loadStyleElements`: for a host\n// that places `<astl-style-form>` or `<astl-style-rules>` itself. `STYLE_OPEN`: the event of a request for them.\nexport {\n builtInDefinitions,\n builtInEditors,\n builtInElements,\n builtInStyleTemplates,\n createAuthoring,\n createTextareaAdapter,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n loadStyleElements,\n STYLE_OPEN,\n tokensCss,\n UploadRefused,\n};\n\n/**\n * The toolbar's default featured inserts: none, every component and starter is under \"Elements\" and \"Templates\".\n * `featured` replaces it.\n */\nexport const DEFAULT_FEATURED: readonly string[] = [];\n\n/** The built-ins' insert menu descriptions, imported when a menu first opens. */\nconst loadMenuMessages = async (): Promise<readonly MessageCatalog[]> =>\n (await import('@astl/components/menu-messages')).builtInMenuMessages;\n\n/**\n * Defines `<astl-editor>` with `components: builtInDefinitions`, `styleTemplates: builtInStyleTemplates`, the light\n * theme's `groundColors` (what an author sees while writing),\n * the built-ins' `menuMessages` and `featured: DEFAULT_FEATURED`, and as `editors` and `elements` the built-in entries of the `components` tags (so a\n * subset of components brings its own editors and elements). An option replaces its default (extend with\n * `[...builtInDefinitions, mine]`); a second call adds.\n */\nexport function defineEditor(options: Partial<DefineEditorOptions> = {}): void {\n const components = options.components ?? builtInDefinitions;\n const tags = new Set(components.map((definition) => definition.manifest.tag));\n const { surface, ink } = tokens.themes.light;\n defineBaseEditor({\n styleTemplates: builtInStyleTemplates,\n groundColors: { surface, ink },\n featured: DEFAULT_FEATURED,\n menuMessages: loadMenuMessages,\n ...options,\n components,\n editors: options.editors ?? builtInEditors.filter((editor) => tags.has(editor.manifest.tag)),\n elements: options.elements ?? builtInElements.filter((element) => tags.has(element.tag)),\n });\n}\n","/**\n * astrolabe-editor.js, for authoring pages: `@astl/astrolabe/editor`, defined on load with every built-in\n * component, editor descriptor, preview element and look. TipTap is a chunk of its own, fetched only when an\n * `<astl-editor>` without an adapter and without a `slot=\"surface\"` child connects; the bundle check keeps it out of\n * the first load.\n */\nimport { defineEditor } from '../editor.js';\n\ndefineEditor();\n\nexport * from '../editor.js';\n"],"ignoreList":[31],"mappings":"A,kiGAKA,IAAaiN,GAAgC,CAC3C,SAAUtD,GACV,SAAUpI,EACV,MAAO,eACP,YAAa,qBACb,KAAM,eACN,SAAU,QACV,SACE,iIAEF,OAAQ,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,EAAG,EACjC,GAAIhJ,IAAa,IAAA,IAAaA,IAAamG,GACzC,MAAU,MAAM,IAAI6C,GAAI,sCAAsC,EAEhElJ,GAAwBC,CAAQ,EAChC+E,GAASjX,CAAO,EACZmS,IAAa,IAAA,IAAWD,EAAS,OAAOiJ,GAAK7C,EAAU,CAC7D,CCbA,IAAa+C,GAAsC,CAAC,EAG9CC,GAAmB,UACtB,MAAM,OAAO,sCAAA,CAAmC,oBASnD,SAAgBC,GAAa,EAAwC,CAAC,EAAS,CAC7E,IAAMC,EAAaxb,EAAQ,YAAcrR,EACnC+lB,EAAO,IAAI,IAAI8G,EAAW,IAAK,GAAeC,EAAW,SAAS,GAAG,CAAC,EACtE,CAAE,UAAS,OAAQ9qB,EAAO,OAAO,MACvCyqB,GAAiB,CACf,eAAgBjsB,GAChB,aAAc,CAAE,UAAS,KAAI,EAC7B,SAAUksB,GACV,aAAcC,GACd,GAAGtb,EACH,aACA,QAASA,EAAQ,SAAW9D,GAAe,OAAQ,GAAWwY,EAAK,IAAI2C,EAAO,SAAS,GAAG,CAAC,EAC3F,SAAUrX,EAAQ,UAAYjP,GAAgB,OAAQ,GAAY2jB,EAAK,IAAI1hB,EAAQ,GAAG,CAAC,CACzF,CAAC,CACH,CCzFAuoB,GAAa,E"}
1
+ {"version":3,"file":"astrolabe-editor.js","names":["inheritTokens","nothing","live","ifDefined","nothing","nothing","live","LitElement","nothing","registered","inheritTokens","nothing","inheritTokens","nothing","t","e","r","s","unsafeCSS","LitElement","nothing","keyed","defineEditor","audioMessages","dropMessages","trueFalseMessages","categoriseMessages","memoryMessages","longAnswerMessages","imageLabelMessages","flashCardsMessages","gapMessages","videoMessages","matchMessages","hotspotMessages","wordSearchMessages","selectMessages","imageDropMessages","wordBankMessages","orderMessages","builtInDefinitions","markWordsMessages","crosswordMessages","createEngine","calloutMessages","choiceMessages","allAttributes","PAGE_ATTRIBUTES","builtInStyleTemplates","OPAQUE_ID_PATTERN","MAX_REQUEST_BYTES","COLUMNS_TAG","b","HINT_TAG","r","FORMAT_VERSION","i$1","ELEMENT_TAG_PATTERN","DEFAULT_PROFILE","isOpaqueId","isProblemDetails","DOC_KINDS","PROTOCOL_VERSION","CONTENT_ATTRIBUTES","SCORING_RULES","isSourceId","helpPolicy","INLINE_TAGS","PRACTICE_POLICY","FIGURE_TAG","groupMax","BLOCK_TAGS","tokens","SOURCE_ID_PATTERN","SNAPSHOT_FORMAT","SUPPORTED_FORMATS","builtInElements","LANGUAGE_TAG_PATTERN","isSnapshot","directionOf","SCORING_ATTRIBUTES","MIN_COLUMNS","roundScore","CAPTION_TAG","maxAnswerLength","HELP_TAGS","w","DOC_TAG","ProblemCode","DEFAULT_DOC_KIND","PROBLEM_MEDIA_TYPE","COLUMN_TAG","ProtocolPath","DOC_ATTRIBUTES","PlayerEvent","MAX_COLUMNS","isAttemptPolicy","MAX_ATTRIBUTES_PER_ELEMENT","COMMON_ATTRIBUTES","MAX_NESTING_DEPTH","MAX_ANSWER_LENGTH","pluralCategories","definePlayer","isSafeUrl","A","fitsAnswer","FEEDBACK_VARIANTS","isAnswerKey","hasErrors","element","REMOVED_WITH_CONTENT","childTagConflict","isElement","compareCatalogs","MAX_ANSWER_COUNT","parseMessage","FLAG_SELECTED","messageParams","inertStyles","STYLE_TEMPLATE_NAME","PALETTE","PAGE_TAG","tokensCss","MAX_SOURCE_LENGTH","CheckerError","createI18n","textContent","icuFormatter","TAG_ATTRIBUTES","variantAttribute","strictUrlPolicy","ENGINE_NAMESPACE","text","MessageSyntaxError","TEST_POLICY","INERT_STYLE","URL_ATTRIBUTES","STYLE_TEMPLATE_ATTRIBUTE","KEY_FORMAT_VERSION","EngineIssue","STYLE_TAG","sameChildSpec","childElements","negotiateLocale","o","MAX_OPEN_ANSWER_LENGTH","EXPLANATION_TAG","BUILT_IN_PREFIX","isAnswers","HELP_ATTRIBUTES","i$2","OPEN_SLOT_KIND","FEEDBACK_TAG","JSON_MEDIA_TYPE","CLASS_ATTRIBUTE","audioManifest","calloutManifest","categoriseManifest","choiceManifest","crosswordManifest","dropManifest","flashCardsManifest","gapManifest","hotspotManifest","imageDropManifest","imageLabelManifest","longAnswerManifest","markWordsManifest","matchManifest","memoryManifest","orderManifest","selectManifest","trueFalseManifest","videoManifest","wordBankManifest","wordSearchManifest","usedIds","attributeValue","elementTree","scanElements","tokenize","loadHelpForm","UploadRefused","pictureSize","refusalOf","STYLE_OPEN","createAuthoring","GLYPHS","loadStyleElements","TYPE_GLYPHS","styleElementsIn","AstlInsertMenu","editorMessages","EDITOR_NAMESPACE","DEFAULT_STYLES","styleMapOf","DEFAULT_FONTS","kitStyles","AuthoringElement","inheritTokens$1","i$3","p","e","l","sortIssues","issueStyles","renderIssues","SEVERITY_ICONS","RovingFocus","audioEditor","calloutEditor","categoriseEditor","choiceEditor","grid","head","crosswordEditor","dropEditor","PICTURES","card","front","back","picture","name","flashCardsEditor","gapEditor","hotspotEditor","imageDropEditor","imageLabelEditor","longAnswerEditor","word","id","correct","key","line","row","odd","markWordsEditor","task","attrs","n","i","set","c","starter","matchEditor","game","memoryEditor","orderEditor","selectEditor","trueFalseEditor","videoEditor","wordBankEditor","DIRECTIONS","OPEN","WORDS","builtInEditors","ACTION_ICONS","fitsBeside","field","inputValue","event","checkedOf","AstlInspector","#model","authoring","adapter","#document","source","next","change","#shown","current","focus","#focus","item","#fieldClass","#describedBy","value","#apply","#help","#uploadControl","said","#upload","status","words","accept","input","file","#uploadFile","upload","tag","#abort","abort","say","asset","src","error","option","values","add","remove","k","j","full","described","write","v","child","choose","attribute","required","rows","index","control","commit","column","first","options","columns","#textList","#childFlags","#childTexts","#childChoices","#childTable","#text","#number","#checkbox","#select","place","page","button","off","run","move","direction","model","issues","issue","display","glyph","#actions","targets","kinds","target","#styleKinds","#styleOpen","#showStyle","kind","open","#askStyle","selection","document","body","note","#field","f","manifest","#head","#issues","lang","dir","#styleSection","AstlIssues","#timer","#check","changed","#source","summary","errors","AstlPictureDialog","#finish","request","#editing","#withCaption","#altRequired","#target","#src","#alt","#decorative","#caption","#width","#height","#preview","#message","#uploadMessage","#stop","result","#resolve","resolve","#dialog","#previewTimer","dialog","fields","#generation","#busy","#picking","policy","#allowed","message","#take","#pick","pick","picked","shown","alt","caption","library","#submit","#live","FIELD_CHANGE","round","num","MAX_LISTED","slot","reshaped","box","boundsOf","region","cx","cy","h","cleared","shape","points","x","y","anchorOf","AstlPictureField","#status","params","context","taken","prefix","#freshId","label","#t","#change","at","width","height","#write","canvas","#at","#draft","draft","#add","unflagged","cls","#aspect","pin","badge","shapes","#shape","badges","#badge","#down","#move","#up","img","count","raw","optional","setPoints","numbers","#more","lx","ly","#labelField","point","regions","#canvas","#region","#point","registered$1","AstlPreview","root","type","#state","generation","#stale","#set","player","state","theme","ICONS","STYLES","MENU_GROUPS","INSERT_MENUS","MARKS","LISTS","STYLE_POPUPS","isMenu","popup","popoverOf","openerOf","VIEW_PICKED","NO_STATE","barStyles","buttonStyles","popupStyles","AstlToolbar","#items","#open","menu","detail","#close","#panel","#loadStylePopups","#stylePopupsModule","module","sheet","#follow","#outside","#escape","#styles","#off","listen","#popup","path","opener","node","panel","inside","#linkError","#colorError","#query","#menu","#place","rect","rtl","room","start","inset","below","format","href","#done","changes","styles","where","#namedTarget","ready","#isBox","rule","#namedNow","stack","font","hasBlock","popupItem","enabled","#fontName","size","valued","textEnabled","blockStyle","align","alignIcon","#insert","template","disabled","items","descriptor","t","icon","groups","formatItem","#format","style","named","one","styleName","#styleGroups","mark","list","starters","d","#featuredItems","wraps","view","history","#roving","unavailable","part","buttons","step","own","preset","group","none","#setNamed","#setText","#setBlock","#menuKeydown","s","#styleMenuMore","apply","away","#groups","#button","split","#keydown","g","#styleMenu","#linkPopup","#insertPopup","#stylePopup","choice","ELEMENTS","defineAuthoringElements","registry","existing","TEXT_BLOCKS","contentEnd","range","documentOf","roots","doc","children","content","blocks","freshPage","used","blank","fragment","inlinePath","block","el","caret","splitPageSource","from","to","close","language","a","before","empty","left","addPageSource","after","mergePageSource","pages","end","SELECTION_EVENTS","same","isComponent","insertionRange","elements","hit","last","tags","offset","cut","reveal","textarea","createTextareaAdapter","selections","cache","component","emitSelection","now","listener","emitChange","setSource","old","shorter","edit","html","delta","map","selectionStart","selectionEnd","selectionDirection","inheritTokens","lines","selector","editorStyles","elementTag","secret","previewSecret","engineOf","lists","EMPTY","registered","connected","added","out","into","what","register","maps","profile","engine","editor","authoringFor","keep","allowed","THEMES","CHANGE","READY","VIEW","OWN_VIEWS","COUNT_DELAY_MS","PANELS","listAttribute","viewsAttribute","KIT_ICONS","INSPECTOR_PARTS","surfaces","sourceViews","AstlEditor","#resolveReady","#notice","#pageNotice","has","#slotted","#pending","#ready","locale","#uiLocale","given","#authoring","#builtIn","#subscribe","#counting","#readyFor","surface","#surface","views","#ownViews","#hostViews","#errors","#notices","#outline","delay","#theme","#leaveSource","#decide","#pictures","#pages","#count","#opening","#failed","#subscription","notice","requested","available","waiting","featured","panels","icons","exported","#view","#statusLine","#slotChange","outline","TAG","defineEditor$1","DEFAULT_FEATURED","loadMenuMessages","defineEditor","components","definition","checkCatalog","isStyleTemplate"],"sources":["../../../components/src/audio/editor.ts","../../../components/src/callout/editor.ts","../../../components/src/categorise/editor.ts","../../../components/src/choice/editor.ts","../../../components/src/crossword/editor.ts","../../../components/src/drop/editor.ts","../../../components/src/flash-cards/editor.ts","../../../components/src/gap/editor.ts","../../../components/src/hotspot/editor.ts","../../../components/src/image-drop/editor.ts","../../../components/src/image-label/editor.ts","../../../components/src/long-answer/editor.ts","../../../components/src/mark-words/editor.ts","../../../components/src/match/editor.ts","../../../components/src/memory/editor.ts","../../../components/src/order/editor.ts","../../../components/src/select/editor.ts","../../../components/src/true-false/editor.ts","../../../components/src/video/editor.ts","../../../components/src/word-bank/editor.ts","../../../components/src/word-search/editor.ts","../../../components/src/editors.ts","../../../editor/src/elements/inspector.ts","../../../editor/src/elements/issues.ts","../../../editor/src/elements/picture-dialog.ts","../../../editor/src/elements/picture-field.ts","../../../editor/src/elements/preview.ts","../../../editor/src/elements/toolbar.ts","../../../editor/src/define.ts","../../../editor/src/pages.ts","../../../editor/src/textarea.ts","../../../../node_modules/.pnpm/lit-html@3.3.3/node_modules/lit-html/directives/keyed.js","../../../editor-tiptap/src/element.ts","../../../editor-tiptap/src/define.ts","../../src/editor.ts","../../src/bundles/astrolabe-editor.ts"],"sourcesContent":["import type { EditorDescriptor } from '@astl/core';\nimport { audioManifest } from './manifest.js';\nimport { audioMessages } from './messages.js';\n\n/** The default template has a title and a transcript to replace; the author gives the file (until then, an error). */\nexport const audioEditor: EditorDescriptor = {\n manifest: audioManifest,\n messages: audioMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'speaker-high',\n idPrefix: 'audio',\n template:\n '<astl-audio id=\"{{id}}\" label=\"{{t:template.label}}\">' +\n '<astl-transcript>{{t:template.transcript}}</astl-transcript></astl-audio>',\n fields: [\n { kind: 'attribute', name: 'label', label: 'editor.title', help: 'editor.titleHelp' },\n { kind: 'attribute', name: 'src', label: 'editor.src', help: 'editor.srcHelp', accept: 'audio/*' },\n {\n kind: 'text-list',\n tag: 'astl-transcript',\n label: 'editor.transcript',\n help: 'editor.transcriptHelp',\n multiline: true,\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { calloutManifest } from './manifest.js';\nimport { calloutMessages } from './messages.js';\n\nexport const calloutEditor: EditorDescriptor = {\n manifest: calloutManifest,\n messages: calloutMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'info',\n idPrefix: 'callout',\n template: '<astl-callout id=\"{{id}}\" kind=\"tip\"><p>{{t:template.text}}</p></astl-callout>',\n fields: [{ kind: 'attribute', name: 'kind', label: 'editor.kind' }],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { categoriseManifest } from './manifest.js';\nimport { categoriseMessages } from './messages.js';\n\nexport const categoriseEditor: EditorDescriptor = {\n manifest: categoriseManifest,\n messages: categoriseMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'kanban',\n idPrefix: 'cat',\n template:\n '<astl-categorise id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-category id=\"a\">{{t:template.categoryA}}</astl-category>' +\n '<astl-category id=\"b\">{{t:template.categoryB}}</astl-category>' +\n '<astl-card id=\"a1\" category=\"a\">{{t:template.cardA1}}</astl-card>' +\n '<astl-card id=\"a2\" category=\"a\">{{t:template.cardA2}}</astl-card>' +\n '<astl-card id=\"b1\" category=\"b\">{{t:template.cardB1}}</astl-card>' +\n '<astl-card id=\"b2\" category=\"b\">{{t:template.cardB2}}</astl-card></astl-categorise>',\n templates: [\n {\n id: 'sort-into-groups',\n label: 'template.sort.label',\n description: 'template.sort.description',\n template:\n '<h3>{{t:template.sort.heading}}</h3><p>{{t:template.sort.instruction}}</p>' +\n '<astl-categorise id=\"{{id}}\"><astl-prompt>{{t:template.sort.prompt}}</astl-prompt>' +\n '<astl-category id=\"a\">{{t:template.sort.groupA}}</astl-category>' +\n '<astl-category id=\"b\">{{t:template.sort.groupB}}</astl-category>' +\n '<astl-card id=\"a1\" category=\"a\">{{t:template.sort.card1}}</astl-card>' +\n '<astl-card id=\"b1\" category=\"b\">{{t:template.sort.card2}}</astl-card>' +\n '<astl-card id=\"a2\" category=\"a\">{{t:template.sort.card3}}</astl-card>' +\n '<astl-card id=\"b2\" category=\"b\">{{t:template.sort.card4}}</astl-card></astl-categorise>',\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-card',\n attribute: 'category',\n options: 'astl-category',\n label: 'editor.cardCategories',\n help: 'editor.cardCategoriesHelp',\n },\n // The groups as rows, with the palette slot (1 to 8) of each.\n {\n kind: 'child-table',\n tag: 'astl-category',\n columns: [{ attribute: 'palette', label: 'editor.palette' }],\n label: 'editor.groups',\n help: 'editor.groupsHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { choiceManifest } from './manifest.js';\nimport { choiceMessages } from './messages.js';\n\nexport const choiceEditor: EditorDescriptor = {\n manifest: choiceManifest,\n messages: choiceMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'list-checks',\n idPrefix: 'choice',\n template:\n '<astl-choice id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-option id=\"a\" correct>{{t:template.option1}}</astl-option>' +\n '<astl-option id=\"b\">{{t:template.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.option3}}</astl-option></astl-choice>',\n templates: [\n {\n id: 'multiple-choice',\n label: 'template.choice.label',\n description: 'template.choice.description',\n template:\n '<h3>{{t:template.choice.heading}}</h3><p>{{t:template.choice.instruction}}</p>' +\n '<astl-choice id=\"{{id}}\"><astl-prompt>{{t:template.choice.prompt}}</astl-prompt>' +\n '<astl-option id=\"a\">{{t:template.choice.option1}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.choice.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.choice.option3}}</astl-option></astl-choice>',\n },\n ],\n fields: [\n { kind: 'child-flag', tag: 'astl-option', attribute: 'correct', label: 'editor.correctOptions' },\n { kind: 'attribute', name: 'multiple', label: 'editor.multiple' },\n { kind: 'attribute', name: 'shuffle', label: 'editor.shuffle' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { crosswordManifest } from './manifest.js';\nimport { crosswordMessages } from './messages.js';\n\n/** A 5 by 5 grid of two words crossing at their first letter, after `head` (a prompt, or nothing). */\nconst grid = (head: string): string =>\n `<astl-crossword id=\"{{id}}\" rows=\"5\" columns=\"5\">${head}` +\n '<astl-crossword-word id=\"w1\" answer=\"{{t:template.crossword.across}}\" row=\"0\" column=\"0\" direction=\"across\">' +\n '{{t:template.crossword.acrossClue}}</astl-crossword-word>' +\n '<astl-crossword-word id=\"w2\" answer=\"{{t:template.crossword.down}}\" row=\"0\" column=\"0\" direction=\"down\">' +\n '{{t:template.crossword.downClue}}</astl-crossword-word></astl-crossword>';\n\nexport const crosswordEditor: EditorDescriptor = {\n manifest: crosswordManifest,\n messages: crosswordMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'grid-four',\n idPrefix: 'crossword',\n template: grid('<astl-prompt>{{t:template.crossword.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'crossword',\n label: 'template.crossword',\n description: 'template.crossword.description',\n template: `<h3>{{t:template.crossword.heading}}</h3><p>{{t:template.crossword.prompt}}</p>${grid('')}`,\n },\n ],\n fields: [\n { kind: 'attribute', name: 'rows', label: 'editor.rows' },\n { kind: 'attribute', name: 'columns', label: 'editor.columns' },\n {\n kind: 'child-table',\n tag: 'astl-crossword-word',\n label: 'editor.words',\n help: 'editor.wordsHelp',\n columns: [\n { attribute: 'answer', label: 'editor.answer' },\n { attribute: 'row', label: 'editor.row' },\n { attribute: 'column', label: 'editor.column' },\n { attribute: 'direction', label: 'editor.direction' },\n ],\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { dropManifest } from './manifest.js';\nimport { dropMessages } from './messages.js';\n\nexport const dropEditor: EditorDescriptor = {\n manifest: dropManifest,\n messages: dropMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'arrow-square-in',\n idPrefix: 'drop',\n // The first word of a new bank (its template's ids); the inspector then picks the right one.\n template: '<astl-drop id=\"{{id}}\" answer=\"a\" bank=\"\"></astl-drop>',\n companion: { tag: 'astl-word-bank', attribute: 'bank' },\n fields: [\n {\n kind: 'attribute',\n name: 'answer',\n label: 'editor.answer',\n help: 'editor.answerHelp',\n options: { from: 'bank', tag: 'astl-word' },\n },\n { kind: 'attribute', name: 'bank', label: 'editor.bank', help: 'editor.bankHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { flashCardsManifest } from './manifest.js';\nimport { flashCardsMessages } from './messages.js';\n\n/** Sample pictures of the starter, on the address range kept for documentation: authors replace them with their own. */\nconst PICTURES = 'https://assets.example.org/flash-cards/';\n\nconst card = (front: string, back: string): string =>\n `<astl-front>${front}</astl-front><astl-back>{{t:template.cards.${back}}}</astl-back>`;\nconst picture = (name: string): string =>\n `<img src=\"${PICTURES}${name}.svg\" alt=\"{{t:template.cards.${name}}}\" width=\"96\" height=\"96\">`;\n\nexport const flashCardsEditor: EditorDescriptor = {\n manifest: flashCardsManifest,\n messages: flashCardsMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'cards',\n template:\n '<astl-flash-cards id=\"{{id}}\"><astl-front>{{t:template.front}}</astl-front>' +\n '<astl-back>{{t:template.back}}</astl-back></astl-flash-cards>',\n templates: [\n {\n id: 'flash-cards',\n label: 'editor.template.cards',\n description: 'editor.template.cards.description',\n template:\n '<h3>{{t:template.cards.title}}</h3><p>{{t:template.cards.instruction}}</p><astl-flash-cards id=\"{{id}}\">' +\n card(picture('sun'), 'sunBack') +\n card(picture('moon'), 'moonBack') +\n card('{{t:template.cards.mars}}', 'marsBack') +\n card('{{t:template.cards.saturn}}', 'saturnBack') +\n '</astl-flash-cards>',\n },\n ],\n fields: [{ kind: 'text-list', tag: 'astl-back', label: 'editor.backs', help: 'editor.backsHelp' }],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { gapManifest } from './manifest.js';\nimport { gapMessages } from './messages.js';\n\nexport const gapEditor: EditorDescriptor = {\n manifest: gapManifest,\n messages: gapMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'text-t',\n idPrefix: 'gap',\n template: '<astl-gap id=\"{{id}}\" answer=\"{{selection}}\"></astl-gap>',\n templates: [\n {\n id: 'fill-the-gaps',\n label: 'template.fill.label',\n description: 'template.fill.description',\n template:\n '<h3>{{t:template.fill.heading}}</h3><p>{{t:template.fill.instruction}}</p>' +\n '<p>{{t:template.fill.start}} <astl-gap id=\"{{id}}\" answer=\"{{t:template.fill.answer1}}\"></astl-gap> ' +\n '{{t:template.fill.middle}} <astl-gap answer=\"{{t:template.fill.answer2}}\"></astl-gap>' +\n '{{t:template.fill.end}}</p>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'answer', label: 'editor.answer' },\n { kind: 'text-list', tag: 'astl-alt', label: 'editor.alternatives', help: 'editor.alternativesHelp' },\n { kind: 'attribute', name: 'type', label: 'editor.type' },\n { kind: 'attribute', name: 'case', label: 'editor.case' },\n { kind: 'attribute', name: 'marks', label: 'editor.marks', help: 'editor.marksHelp' },\n { kind: 'attribute', name: 'tolerance', label: 'editor.tolerance' },\n { kind: 'attribute', name: 'width', label: 'editor.width' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { hotspotManifest } from './manifest.js';\nimport { hotspotMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const hotspotEditor: EditorDescriptor = {\n manifest: hotspotManifest,\n messages: hotspotMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'crosshair',\n idPrefix: 'hotspot',\n template:\n '<astl-hotspot id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-hotspot-region id=\"r1\" x=\"5\" y=\"10\" width=\"40\" height=\"80\" label=\"{{t:template.place1}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r2\" x=\"55\" y=\"10\" width=\"40\" height=\"80\" label=\"{{t:template.place2}}\"></astl-hotspot-region>' +\n '</astl-hotspot>',\n templates: [\n {\n id: 'find-it-in-the-picture',\n label: 'template.find.label',\n description: 'template.find.description',\n template:\n '<h3>{{t:template.find.heading}}</h3><p>{{t:template.find.instruction}}</p>' +\n '<astl-hotspot id=\"{{id}}\" multiple><astl-prompt>{{t:template.find.prompt}}</astl-prompt>' +\n '<astl-hotspot-region id=\"r1\" x=\"4\" y=\"6\" width=\"22\" height=\"26\" label=\"{{t:template.find.topLeft}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r2\" shape=\"circle\" x=\"85\" y=\"18\" r=\"10\" label=\"{{t:template.find.topRight}}\"></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r3\" shape=\"circle\" x=\"50\" y=\"50\" r=\"12\" label=\"{{t:template.find.centre}}\" correct></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r4\" shape=\"circle\" x=\"15\" y=\"82\" r=\"10\" label=\"{{t:template.find.bottomLeft}}\"></astl-hotspot-region>' +\n '<astl-hotspot-region id=\"r5\" x=\"74\" y=\"68\" width=\"22\" height=\"26\" label=\"{{t:template.find.bottomRight}}\" correct></astl-hotspot-region>' +\n '</astl-hotspot>',\n },\n ],\n fields: [\n {\n kind: 'picture-regions',\n tag: 'astl-hotspot-region',\n src: 'src',\n label: 'editor.regions',\n help: 'editor.regionsHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-flag',\n tag: 'astl-hotspot-region',\n attribute: 'correct',\n label: 'editor.correct',\n help: 'editor.correctHelp',\n },\n { kind: 'attribute', name: 'multiple', label: 'editor.multiple' },\n { kind: 'attribute', name: 'outline', label: 'editor.outline' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { imageDropManifest } from './manifest.js';\nimport { imageDropMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const imageDropEditor: EditorDescriptor = {\n manifest: imageDropManifest,\n messages: imageDropMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'tag',\n idPrefix: 'image-drop',\n template:\n '<astl-image-drop id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-image-drop-zone id=\"z1\" x=\"10\" y=\"35\" width=\"30\" height=\"30\" answer=\"l1\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z2\" x=\"60\" y=\"35\" width=\"30\" height=\"30\" answer=\"l2\"></astl-image-drop-zone>' +\n '<astl-image-drop-label id=\"l1\">{{t:template.label1}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l2\">{{t:template.label2}}</astl-image-drop-label></astl-image-drop>',\n templates: [\n {\n id: 'drag-labels-onto-the-picture',\n label: 'template.drag.label',\n description: 'template.drag.description',\n template:\n '<h3>{{t:template.drag.heading}}</h3><p>{{t:template.drag.instruction}}</p>' +\n '<astl-image-drop id=\"{{id}}\"><astl-prompt>{{t:template.drag.prompt}}</astl-prompt>' +\n '<astl-image-drop-zone id=\"z1\" x=\"20\" y=\"5\" width=\"60\" height=\"25\" answer=\"l1\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z2\" x=\"20\" y=\"37.5\" width=\"60\" height=\"25\" answer=\"l2\"></astl-image-drop-zone>' +\n '<astl-image-drop-zone id=\"z3\" x=\"20\" y=\"70\" width=\"60\" height=\"25\" answer=\"l3\"></astl-image-drop-zone>' +\n '<astl-image-drop-label id=\"l1\">{{t:template.drag.label1}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l2\">{{t:template.drag.label2}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l3\">{{t:template.drag.label3}}</astl-image-drop-label>' +\n '<astl-image-drop-label id=\"l4\">{{t:template.drag.label4}}</astl-image-drop-label></astl-image-drop>',\n },\n ],\n fields: [\n {\n kind: 'picture-regions',\n tag: 'astl-image-drop-zone',\n src: 'src',\n label: 'editor.zones',\n help: 'editor.zonesHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-choice',\n tag: 'astl-image-drop-zone',\n attribute: 'answer',\n options: 'astl-image-drop-label',\n label: 'editor.answers',\n help: 'editor.answersHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { imageLabelManifest } from './manifest.js';\nimport { imageLabelMessages } from './messages.js';\n\n/** The picture comes from the author: the insert menu asks for it (and its alt text) before it inserts a template. */\nexport const imageLabelEditor: EditorDescriptor = {\n manifest: imageLabelManifest,\n messages: imageLabelMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'map-pin',\n idPrefix: 'image-label',\n template:\n '<astl-image-label id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-image-label-pin id=\"p1\" x=\"30\" y=\"50\" label=\"{{t:template.answer1}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p2\" x=\"70\" y=\"50\" label=\"{{t:template.answer2}}\"></astl-image-label-pin>' +\n '</astl-image-label>',\n templates: [\n {\n id: 'label-the-picture',\n label: 'template.label.label',\n description: 'template.label.description',\n template:\n '<h3>{{t:template.label.heading}}</h3><p>{{t:template.label.instruction}}</p>' +\n '<astl-image-label id=\"{{id}}\"><astl-prompt>{{t:template.label.prompt}}</astl-prompt>' +\n '<astl-image-label-pin id=\"p1\" x=\"50\" y=\"15\" label=\"{{t:template.label.top}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p2\" x=\"50\" y=\"50\" label=\"{{t:template.label.centre}}\" alternatives=\"{{t:template.label.centreAlternative}}\"></astl-image-label-pin>' +\n '<astl-image-label-pin id=\"p3\" x=\"50\" y=\"85\" label=\"{{t:template.label.bottom}}\"></astl-image-label-pin>' +\n '</astl-image-label>',\n },\n ],\n fields: [\n {\n kind: 'picture-points',\n tag: 'astl-image-label-pin',\n src: 'src',\n label: 'editor.pins',\n help: 'editor.pinsHelp',\n },\n { kind: 'attribute', name: 'alt', label: 'editor.alt', help: 'editor.altHelp' },\n {\n kind: 'child-text',\n tag: 'astl-image-label-pin',\n attribute: 'alternatives',\n label: 'editor.alternatives',\n help: 'editor.alternativesHelp',\n },\n { kind: 'attribute', name: 'case', label: 'editor.case' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { longAnswerManifest } from './manifest.js';\nimport { longAnswerMessages } from './messages.js';\n\nexport const longAnswerEditor: EditorDescriptor = {\n manifest: longAnswerManifest,\n messages: longAnswerMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'note-pencil',\n idPrefix: 'answer',\n template:\n '<astl-long-answer id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt></astl-long-answer>',\n templates: [\n {\n id: 'write-your-answer',\n label: 'editor.template.write',\n description: 'editor.template.write.description',\n template:\n '<h3>{{t:template.write.title}}</h3><p>{{t:template.write.instruction}}</p>' +\n '<astl-long-answer id=\"{{id}}\" rows=\"6\" minlength=\"100\" maxlength=\"800\" placeholder=\"{{t:template.write.placeholder}}\">' +\n '<astl-prompt>{{t:template.write.question}}</astl-prompt></astl-long-answer>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'rows', label: 'editor.rows', help: 'editor.rowsHelp' },\n { kind: 'attribute', name: 'minlength', label: 'editor.minlength', help: 'editor.minlengthHelp' },\n { kind: 'attribute', name: 'maxlength', label: 'editor.maxlength', help: 'editor.maxlengthHelp' },\n { kind: 'attribute', name: 'placeholder', label: 'editor.placeholder' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { markWordsManifest } from './manifest.js';\nimport { markWordsMessages } from './messages.js';\n\nconst word = (id: string, key: string, correct = false) =>\n `<astl-mark-word id=\"${id}\"${correct ? ' correct' : ''}>{{t:template.${key}}}</astl-mark-word>`;\n/** One line of four words of the odd-word starter, the `odd`-th of them correct. */\nconst line = (row: string, odd: number) =>\n `<p>${[1, 2, 3, 4].map((n) => word(`${row}${n}`, `odd.${row}${n}`, n === odd)).join(' ')}</p>`;\n\nexport const markWordsEditor: EditorDescriptor = {\n manifest: markWordsManifest,\n messages: markWordsMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'highlighter',\n idPrefix: 'mark-words',\n template: `<astl-mark-words id=\"{{id}}\"><p>{{t:template.before}} ${word('w1', 'word', true)} {{t:template.after}}</p></astl-mark-words>`,\n templates: [\n {\n id: 'select-words',\n label: 'template.select.label',\n description: 'template.select.description',\n template:\n '<h3>{{t:template.select.heading}}</h3><p>{{t:template.select.instruction}}</p>' +\n `<astl-mark-words id=\"{{id}}\"><astl-prompt>{{t:template.select.prompt}}</astl-prompt><p>{{t:template.select.before}} ${word('w1', 'select.word1', true)} ` +\n `{{t:template.select.middle}} ${word('w2', 'select.word2')} {{t:template.select.and}} ` +\n `${word('w3', 'select.word3', true)} {{t:template.select.after}}</p></astl-mark-words>`,\n },\n {\n id: 'odd-word',\n label: 'template.odd.label',\n description: 'template.odd.description',\n icon: 'strikethrough',\n template:\n '<h3>{{t:template.odd.heading}}</h3><p>{{t:template.odd.instruction}}</p>' +\n `<astl-mark-words id=\"{{id}}\" variant=\"strike\"><astl-prompt>{{t:template.odd.prompt}}</astl-prompt>${line('a', 3)}${line('b', 4)}${line('c', 2)}</astl-mark-words>`,\n },\n ],\n fields: [\n { kind: 'attribute', name: 'variant', label: 'editor.variant' },\n {\n kind: 'child-flag',\n tag: 'astl-mark-word',\n attribute: 'correct',\n label: 'editor.correct',\n help: 'editor.correctHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n wrap: { label: 'editor.wrap', child: 'astl-mark-word', attributes: { correct: '' } },\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { matchManifest } from './manifest.js';\nimport { matchMessages } from './messages.js';\n\n/**\n * A task of the sample set `template.<set>.*`: three rows matched one to one with three columns (r1 with a, r2 with\n * b, r3 with c), after `head` (a prompt, or nothing) and with `attrs` on the element.\n */\nconst task = (set: string, attrs: string, head: string): string =>\n `<astl-match id=\"{{id}}\"${attrs}>${head}` +\n ['1', '2', '3']\n .map((n, i) => `<astl-row id=\"r${n}\" column=\"${'abc'[i]}\">{{t:template.${set}.row${n}}}</astl-row>`)\n .join('') +\n ['A', 'B', 'C']\n .map((c) => `<astl-column id=\"${c.toLowerCase()}\">{{t:template.${set}.column${c}}}</astl-column>`)\n .join('') +\n '</astl-match>';\n\n/** A named starter: a level-3 heading, the instruction, then the task. */\nconst starter = (set: string, attrs = ''): string =>\n `<h3>{{t:template.${set}.heading}}</h3><p>{{t:template.${set}.prompt}}</p>${task(set, attrs, '')}`;\n\nexport const matchEditor: EditorDescriptor = {\n manifest: matchManifest,\n messages: matchMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'arrows-left-right',\n idPrefix: 'match',\n template: task('matching', '', '<astl-prompt>{{t:template.matching.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'matching',\n label: 'template.matching',\n description: 'template.matching.description',\n template: starter('matching'),\n },\n {\n id: 'join-the-lines',\n label: 'template.lines',\n description: 'template.lines.description',\n template: starter('lines', ' variant=\"lines\"'),\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-row',\n attribute: 'column',\n options: 'astl-column',\n label: 'editor.answers',\n help: 'editor.answersHelp',\n },\n { kind: 'attribute', name: 'variant', label: 'editor.layout' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { memoryManifest } from './manifest.js';\nimport { memoryMessages } from './messages.js';\n\n/** Three text-only pairs, written pair by pair (the view shuffles them), after `head` (a prompt, or nothing). */\nconst game = (head: string): string =>\n `<astl-memory id=\"{{id}}\">${head}` +\n ['1', '2', '3']\n .map(\n (n) =>\n `<astl-card-a id=\"a${n}\">{{t:template.memory.a${n}}}</astl-card-a>` +\n `<astl-card-b id=\"b${n}\" pair=\"a${n}\">{{t:template.memory.b${n}}}</astl-card-b>`,\n )\n .join('') +\n '</astl-memory>';\n\nexport const memoryEditor: EditorDescriptor = {\n manifest: memoryManifest,\n messages: memoryMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'memory',\n template: game('<astl-prompt>{{t:template.memory.prompt}}</astl-prompt>'),\n templates: [\n {\n id: 'memory',\n label: 'template.memory',\n description: 'template.memory.description',\n template: `<h3>{{t:template.memory.heading}}</h3><p>{{t:template.memory.prompt}}</p>${game('')}`,\n },\n ],\n fields: [\n {\n kind: 'child-choice',\n tag: 'astl-card-b',\n attribute: 'pair',\n options: 'astl-card-a',\n label: 'editor.pairs',\n help: 'editor.pairsHelp',\n },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { orderManifest } from './manifest.js';\nimport { orderMessages } from './messages.js';\n\n/** The items are written in their correct order, so the template's own texts already show how the answer works. */\nexport const orderEditor: EditorDescriptor = {\n manifest: orderManifest,\n messages: orderMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'list-numbers',\n idPrefix: 'order',\n template:\n '<astl-order id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-item id=\"a\">{{t:template.item1}}</astl-item>' +\n '<astl-item id=\"b\">{{t:template.item2}}</astl-item>' +\n '<astl-item id=\"c\">{{t:template.item3}}</astl-item></astl-order>',\n templates: [\n {\n id: 'ordering',\n label: 'template.cycle.label',\n description: 'template.cycle.description',\n template:\n '<h3>{{t:template.cycle.heading}}</h3><p>{{t:template.cycle.instruction}}</p>' +\n '<astl-order id=\"{{id}}\"><astl-prompt>{{t:template.cycle.prompt}}</astl-prompt>' +\n '<astl-item id=\"a\">{{t:template.cycle.item1}}</astl-item>' +\n '<astl-item id=\"b\">{{t:template.cycle.item2}}</astl-item>' +\n '<astl-item id=\"c\">{{t:template.cycle.item3}}</astl-item>' +\n '<astl-item id=\"d\">{{t:template.cycle.item4}}</astl-item></astl-order>',\n },\n ],\n fields: [\n // First, with the help that explains the answer: the source order is the correct one.\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring', help: 'editor.scoringHelp' },\n { kind: 'attribute', name: 'variant', label: 'editor.variant', help: 'editor.variantHelp' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { selectManifest } from './manifest.js';\nimport { selectMessages } from './messages.js';\n\n/** The variant is listed so the dropdown's `native` switch can follow it (the kit would add it after the fields). */\nexport const selectEditor: EditorDescriptor = {\n manifest: selectManifest,\n messages: selectMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'caret-circle-down',\n idPrefix: 'select',\n template:\n '<astl-select id=\"{{id}}\"><astl-option id=\"a\" correct>{{t:template.option1}}</astl-option>' +\n '<astl-option id=\"b\">{{t:template.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.option3}}</astl-option></astl-select>',\n templates: [\n {\n id: 'choose-from-a-list',\n label: 'template.list.label',\n description: 'template.list.description',\n template:\n '<h3>{{t:template.list.heading}}</h3><p>{{t:template.list.instruction}}</p>' +\n '<p>{{t:template.list.start}} <astl-select id=\"{{id}}\">' +\n '<astl-option id=\"a\">{{t:template.list.option1}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.list.option2}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.list.option3}}</astl-option></astl-select>{{t:template.list.end}}</p>',\n },\n {\n id: 'click-the-right-word',\n label: 'template.click.label',\n description: 'template.click.description',\n template:\n '<h3>{{t:template.click.heading}}</h3><p>{{t:template.click.instruction}}</p>' +\n '<p>{{t:template.click.start1}} <astl-select id=\"{{id}}\" variant=\"buttons\">' +\n '<astl-option id=\"a\">{{t:template.click.option1a}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.click.option1b}}</astl-option>' +\n '<astl-option id=\"c\">{{t:template.click.option1c}}</astl-option></astl-select>{{t:template.click.end}}</p>' +\n '<p>{{t:template.click.start2}} <astl-select variant=\"buttons\">' +\n '<astl-option id=\"a\">{{t:template.click.option2a}}</astl-option>' +\n '<astl-option id=\"b\" correct>{{t:template.click.option2b}}</astl-option></astl-select>' +\n '{{t:template.click.end}}</p>',\n },\n ],\n fields: [\n {\n kind: 'child-flag',\n tag: 'astl-option',\n attribute: 'correct',\n label: 'editor.correctOption',\n help: 'editor.correctOptionHelp',\n },\n { kind: 'attribute', name: 'shuffle', label: 'editor.shuffle' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n { kind: 'attribute', name: 'variant', label: 'editor.variant' },\n {\n kind: 'attribute',\n name: 'native',\n label: 'editor.native',\n help: 'editor.nativeHelp',\n variants: ['dropdown'],\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { trueFalseManifest } from './manifest.js';\nimport { trueFalseMessages } from './messages.js';\n\nexport const trueFalseEditor: EditorDescriptor = {\n manifest: trueFalseManifest,\n messages: trueFalseMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'toggle-left',\n idPrefix: 'tf',\n template:\n '<astl-true-false id=\"{{id}}\"><astl-prompt>{{t:template.prompt}}</astl-prompt>' +\n '<astl-statement id=\"s1\" answer=\"true\">{{t:template.statement1}}</astl-statement>' +\n '<astl-statement id=\"s2\" answer=\"false\">{{t:template.statement2}}</astl-statement></astl-true-false>',\n templates: [\n {\n id: 'true-or-false',\n label: 'template.tf.label',\n description: 'template.tf.description',\n template:\n '<h3>{{t:template.tf.heading}}</h3><p>{{t:template.tf.instruction}}</p><astl-true-false id=\"{{id}}\">' +\n '<astl-statement id=\"s1\" answer=\"true\">{{t:template.tf.statement1}}</astl-statement>' +\n '<astl-statement id=\"s2\" answer=\"false\">{{t:template.tf.statement2}}</astl-statement>' +\n '<astl-statement id=\"s3\" answer=\"true\">{{t:template.tf.statement3}}</astl-statement></astl-true-false>',\n },\n ],\n fields: [\n { kind: 'child-choice', tag: 'astl-statement', attribute: 'answer', label: 'editor.answers' },\n { kind: 'attribute', name: 'true-label', label: 'editor.trueLabel', help: 'editor.labelsHelp' },\n { kind: 'attribute', name: 'false-label', label: 'editor.falseLabel' },\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { videoManifest } from './manifest.js';\nimport { videoMessages } from './messages.js';\n\n/** The starter's sample video: authors paste their own link over it. */\nconst SAMPLE = 'https://youtu.be/Bq7mT2kWx4E';\n\n/**\n * The default template names the video only: the author pastes a link or gives a file (until then, an error says so).\n * The \"Watch, then answer\" starter is two pages: the video with a tip, then a sentence to complete.\n */\nexport const videoEditor: EditorDescriptor = {\n manifest: videoManifest,\n messages: videoMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'film-strip',\n idPrefix: 'video',\n template: '<astl-video id=\"{{id}}\" label=\"{{t:template.label}}\"></astl-video>',\n templates: [\n {\n id: 'watch-then-answer',\n label: 'editor.template.watch',\n description: 'editor.template.watch.description',\n template:\n '<h3>{{t:template.watch.title}}</h3><p>{{t:template.watch.instruction}}</p>' +\n '<astl-callout kind=\"tip\"><p>{{t:template.watch.tip}}</p></astl-callout>' +\n `<astl-video id=\"{{id}}\" label=\"{{t:template.watch.label}}\" youtube=\"${SAMPLE}\"></astl-video>` +\n '<p>{{t:template.watch.sentence}} <astl-gap answer=\"{{t:template.watch.gap}}\"></astl-gap>.</p>',\n },\n ],\n fields: [\n { kind: 'attribute', name: 'label', label: 'editor.title', help: 'editor.titleHelp' },\n { kind: 'attribute', name: 'youtube', label: 'editor.youtube', help: 'editor.youtubeHelp' },\n { kind: 'attribute', name: 'vimeo', label: 'editor.vimeo', help: 'editor.vimeoHelp' },\n {\n kind: 'attribute',\n name: 'src',\n label: 'editor.src',\n help: 'editor.srcHelp',\n accept: 'video/mp4,video/webm',\n },\n {\n kind: 'attribute',\n name: 'poster',\n label: 'editor.poster',\n help: 'editor.posterHelp',\n accept: 'image/*',\n },\n {\n kind: 'attribute',\n name: 'captions',\n label: 'editor.captions',\n help: 'editor.captionsHelp',\n accept: '.vtt,text/vtt',\n },\n {\n kind: 'attribute',\n name: 'captions-lang',\n label: 'editor.captionsLang',\n help: 'editor.captionsLangHelp',\n },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { wordBankManifest } from './manifest.js';\nimport { wordBankMessages } from './messages.js';\n\n/** Words are edited in place (Enter adds one); the inspector tags distractors and switches reuse. */\nexport const wordBankEditor: EditorDescriptor = {\n manifest: wordBankManifest,\n messages: wordBankMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'cards',\n idPrefix: 'bank',\n template:\n '<astl-word-bank id=\"{{id}}\"><astl-word id=\"a\">{{t:template.word1}}</astl-word>' +\n '<astl-word id=\"b\">{{t:template.word2}}</astl-word>' +\n '<astl-word id=\"c\" distractor>{{t:template.word3}}</astl-word></astl-word-bank>',\n templates: [\n {\n // The kit gives the gaps their ids and links them to this bank.\n id: 'drag-words',\n label: 'editor.template.dragWords',\n description: 'editor.template.dragWords.description',\n template:\n '<h3>{{t:template.dragWords.heading}}</h3><p>{{t:template.dragWords.instruction}}</p>' +\n '<astl-word-bank id=\"{{id}}\"><astl-word id=\"a\">{{t:template.dragWords.answer1}}</astl-word>' +\n '<astl-word id=\"b\">{{t:template.dragWords.answer2}}</astl-word>' +\n '<astl-word id=\"c\" distractor>{{t:template.dragWords.distractor}}</astl-word></astl-word-bank>' +\n '<p>{{t:template.dragWords.start}} <astl-drop answer=\"a\"></astl-drop>{{t:template.dragWords.middle}} ' +\n '<astl-drop answer=\"b\"></astl-drop>{{t:template.dragWords.end}}</p>',\n },\n ],\n fields: [\n {\n kind: 'child-flag',\n tag: 'astl-word',\n attribute: 'distractor',\n label: 'editor.distractors',\n help: 'editor.distractorsHelp',\n },\n { kind: 'attribute', name: 'reuse', label: 'editor.reuse', help: 'editor.reuseHelp' },\n ],\n};\n","import type { EditorDescriptor } from '@astl/core';\nimport { wordSearchManifest } from './manifest.js';\nimport { wordSearchMessages } from './messages.js';\n\nconst DIRECTIONS = ['right', 'down', 'down-right', 'left', 'up', 'up-left', 'down-left', 'up-right'];\n/** The default directions, written so the inspector's checkboxes show them. */\nconst OPEN = '<astl-word-search id=\"{{id}}\" right down down-right>';\nconst WORDS = [1, 2, 3]\n .map((n) => `<astl-search-word id=\"w${n}\">{{t:template.word${n}}}</astl-search-word>`)\n .join('');\n\nexport const wordSearchEditor: EditorDescriptor = {\n manifest: wordSearchManifest,\n messages: wordSearchMessages,\n label: 'editor.label',\n description: 'editor.description',\n icon: 'magnifying-glass',\n idPrefix: 'word-search',\n template: `${OPEN}<astl-prompt>{{t:template.instruction}}</astl-prompt>${WORDS}</astl-word-search>`,\n templates: [\n {\n id: 'word-search',\n label: 'editor.template.wordSearch',\n description: 'editor.template.wordSearch.description',\n template: `<h3>{{t:template.title}}</h3><p>{{t:template.instruction}}</p>${OPEN}${WORDS}</astl-word-search>`,\n },\n ],\n fields: [\n {\n kind: 'child-text',\n tag: 'astl-search-word',\n attribute: 'word',\n label: 'editor.words',\n help: 'editor.wordsHelp',\n },\n { kind: 'attribute', name: 'size', label: 'editor.size', help: 'editor.sizeHelp' },\n ...DIRECTIONS.map((name) => ({\n kind: 'attribute' as const,\n name,\n label: `editor.${name}`,\n ...(name === 'right' ? { help: 'editor.rightHelp' } : {}),\n })),\n { kind: 'attribute', name: 'scoring', label: 'editor.scoring' },\n { kind: 'attribute', name: 'points', label: 'editor.points' },\n ],\n};\n","/** The built-in editor descriptors, for the authoring kit (`createAuthoring`, `defineAuthoringElements`). */\nimport type { EditorDescriptor } from '@astl/core';\nimport { audioEditor } from './audio/editor.js';\nimport { calloutEditor } from './callout/editor.js';\nimport { categoriseEditor } from './categorise/editor.js';\nimport { choiceEditor } from './choice/editor.js';\nimport { crosswordEditor } from './crossword/editor.js';\nimport { dropEditor } from './drop/editor.js';\nimport { flashCardsEditor } from './flash-cards/editor.js';\nimport { gapEditor } from './gap/editor.js';\nimport { hotspotEditor } from './hotspot/editor.js';\nimport { imageDropEditor } from './image-drop/editor.js';\nimport { imageLabelEditor } from './image-label/editor.js';\nimport { longAnswerEditor } from './long-answer/editor.js';\nimport { markWordsEditor } from './mark-words/editor.js';\nimport { matchEditor } from './match/editor.js';\nimport { memoryEditor } from './memory/editor.js';\nimport { orderEditor } from './order/editor.js';\nimport { selectEditor } from './select/editor.js';\nimport { trueFalseEditor } from './true-false/editor.js';\nimport { videoEditor } from './video/editor.js';\nimport { wordBankEditor } from './word-bank/editor.js';\nimport { wordSearchEditor } from './word-search/editor.js';\n\nexport const builtInEditors: readonly EditorDescriptor[] = [\n gapEditor,\n choiceEditor,\n selectEditor,\n trueFalseEditor,\n orderEditor,\n categoriseEditor,\n matchEditor,\n wordBankEditor,\n dropEditor,\n wordSearchEditor,\n memoryEditor,\n crosswordEditor,\n flashCardsEditor,\n longAnswerEditor,\n markWordsEditor,\n calloutEditor,\n hotspotEditor,\n imageDropEditor,\n imageLabelEditor,\n videoEditor,\n audioEditor,\n];\n","import type { EditorBlockPlace, EditorStyleTargetKind } from '@astl/core';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type SVGTemplateResult,\n svg,\n type TemplateResult,\n} from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { refusalOf } from '../authoring.js';\nimport type { InspectorChange } from '../edit.js';\nimport type {\n CheckboxFieldModel,\n ChildChoiceFieldModel,\n ChildFlagFieldModel,\n ChildTableFieldModel,\n ChildTextFieldModel,\n InspectorFieldModel,\n InspectorModel,\n NumberFieldModel,\n SelectFieldModel,\n TextFieldModel,\n TextListFieldModel,\n} from '../inspect.js';\nimport { AuthoringElement } from './base.js';\nimport { GLYPHS, TYPE_GLYPHS } from './insert-menu.js';\nimport { SEVERITY_ICONS, sortIssues } from './issue-list.js';\nimport type { FieldChange } from './picture-field.js';\nimport { loadHelpForm, loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** A control to focus after the next render (text list rows come and go). */\ninterface PendingFocus {\n readonly field: number;\n readonly item: number | 'add';\n}\n\n/** The icons of the head's actions: shapes only, stroked by the `.glyph` rule. */\nconst ACTION_ICONS = {\n moveUp: svg`<path d=\"M10 16V4M5 9l5-5 5 5\"/>`,\n moveDown: svg`<path d=\"M10 4v12M5 11l5 5 5-5\"/>`,\n delete: svg`<path d=\"M4 6h12M8 6V4h4v2M6 6l.8 10h6.4L14 6M9 9v4M11 9v4\"/>`,\n} satisfies Readonly<Record<string, SVGTemplateResult>>;\n\n/** Fields that fit beside another in the two-column form: a select, a number or a short text (no upload). */\nconst fitsBeside = (field: InspectorFieldModel): boolean =>\n field.kind === 'attribute' &&\n field.control !== 'checkbox' &&\n !(field.control === 'text' && field.accept !== null);\n\nconst inputValue = (event: Event) => (event.target as HTMLInputElement | HTMLSelectElement).value;\nconst checkedOf = (event: Event) => (event.target as HTMLInputElement).checked;\n\n/**\n * `<astl-inspector>`: a form for the component at the cursor (answers, alternatives, correct options, whether each\n * statement is true, the category of each card, scoring, points, variant, look), or, with the cursor outside every\n * component, the document's own settings (its look). Every edit goes through `authoring.update` and the adapter\n * (`replaceElement`, or `setSource` for the document), so the editor stays the source of truth. A block component's\n * head has \"Move up\", \"Move down\" and \"Delete\" (`EditorAdapter.moveBlock`, `removeBlock`, at `getCursor`), each left\n * out when the adapter cannot do it; at its page's start or end, a move is unavailable (`aria-disabled`). The head\n * shows the type's icon and name and the element's id in a chip; under it, the element's own issues, as banners. The\n * custom property `--astl-inspector-columns` (default 1) sets the form's columns: with 2, selects, numbers and short\n * texts sit side by side and every other field spans the row.\n */\nexport class AstlInspector extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n // The picture fields redeclare the tokens on their :host: they take this element's (theme, host overrides).\n inheritTokens('astl-picture-field, astl-style-form, astl-help-form'),\n css`\n .style {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-2);\n padding-block-start: var(--astl-space-3);\n border-block-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .style-title {\n margin: 0;\n font-size: 1rem;\n }\n .style-targets {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-1);\n }\n .fields {\n display: grid;\n grid-template-columns: repeat(var(--astl-inspector-columns, 1), minmax(0, 1fr));\n gap: var(--astl-space-3);\n }\n .fields > * {\n grid-column: 1 / -1;\n }\n .fields > .short {\n grid-column: auto;\n }\n .field,\n fieldset {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n margin: 0;\n padding: 0;\n border: 0;\n }\n label:not(.check),\n legend {\n padding: 0;\n font-weight: 600;\n }\n fieldset > ul,\n fieldset > .check:first-of-type {\n margin-block-start: var(--astl-space-1);\n }\n .check {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: var(--astl-space-2);\n min-block-size: var(--astl-target-min);\n cursor: pointer;\n }\n `,\n // One child of a child-choice field with a select: its text above the select.\n css`\n .pick {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n margin-block-start: var(--astl-space-1);\n }\n .pick label {\n font-weight: 400;\n }\n .item {\n display: flex;\n gap: var(--astl-space-2);\n align-items: center;\n }\n .item :is(input, textarea) {\n flex: 1 1 auto;\n }\n .item:has(textarea) {\n align-items: flex-start;\n }\n .item button {\n flex: none;\n }\n fieldset > button {\n align-self: flex-start;\n }\n `,\n // One child of a child-choice field with radios: its text, then the values side by side.\n css`\n .choice > legend {\n font-weight: 400;\n }\n .choice > .values {\n display: flex;\n flex-wrap: wrap;\n column-gap: var(--astl-space-4);\n }\n .help {\n margin: 0;\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n `,\n // One row of a child-table field: its text, then its controls side by side while they fit, and Remove.\n css`\n .row {\n margin-block-start: var(--astl-space-2);\n padding: var(--astl-space-2) var(--astl-space-3) var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n .row > legend {\n padding-inline: var(--astl-space-1);\n font-weight: 400;\n }\n .cells {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n gap: var(--astl-space-2);\n }\n .cell {\n flex: 1 1 5rem;\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n min-inline-size: 0;\n font-weight: 400;\n }\n .cell > input,\n .cell > select {\n inline-size: 100%;\n }\n `,\n // The head: the type's icon and name, the id in a chip, then the block's actions (icons), which wrap under it when\n // narrow. Under it the element's issues, each a banner in its severity's colour with an icon and words.\n css`\n .head,\n .actions {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1) var(--astl-space-2);\n }\n .title {\n flex: 0 1 auto;\n min-inline-size: 0;\n }\n .actions {\n margin-inline-start: auto;\n }\n .glyph {\n fill: none;\n stroke: currentColor;\n stroke-width: 1.8;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .glyph circle {\n fill: currentColor;\n stroke: none;\n }\n .id {\n padding-inline: var(--astl-space-2);\n border-radius: var(--astl-radius-s);\n background: var(--astl-accent-soft);\n color: var(--astl-ink);\n font-family: var(--astl-font-mono);\n font-size: var(--astl-size-small);\n }\n .delete {\n color: var(--astl-danger);\n }\n .issue {\n display: flex;\n align-items: flex-start;\n gap: var(--astl-space-2);\n padding-block: var(--astl-space-2);\n padding-inline: var(--astl-space-3);\n border-radius: var(--astl-radius-s);\n background: var(--astl-danger-soft);\n color: var(--astl-ink);\n }\n .issue .icon {\n color: var(--astl-danger);\n }\n .issue[data-severity='warning'] {\n background: var(--astl-warning-soft);\n }\n .issue[data-severity='warning'] .icon {\n color: var(--astl-warning);\n }\n @media (forced-colors: active) {\n .issue {\n border: var(--astl-outline-width) solid CanvasText;\n }\n }\n `,\n // A text-list row in a text area keeps its line breaks and grows with them.\n css`\n textarea {\n field-sizing: content;\n min-block-size: 5lh;\n resize: vertical;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .upload p {\n margin-block: var(--astl-space-1) 0;\n }\n .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n `,\n ];\n\n /** Source id of the element shown: edits go to it. */\n #shown: string | null = null;\n /** The document's settings are shown: edits go to the start tag of `<astl-doc>`. */\n #document = false;\n #model: InspectorModel | null = null;\n #focus: PendingFocus | null = null;\n /**\n * The last upload of a `url` field: its element and attribute, and what it says (a message key, or with `text` a\n * host's own words, `UploadRefused`).\n */\n #upload: {\n readonly element: string | null;\n readonly name: string;\n readonly key: string;\n readonly error: boolean;\n readonly text?: string | undefined;\n } | null = null;\n /** Aborts the upload under way (its `signal`): another pick replaces it. */\n #abort: AbortController | null = null;\n\n /** The inspector model on screen (a component's, or the document's), or null. */\n get model(): InspectorModel | null {\n return this.#model;\n }\n\n /**\n * Applies a change to what is shown (the element, or the document), or to the element `element` (a picture field's\n * late upload, whatever the cursor is in by then).\n */\n #apply(change: InspectorChange, element?: string | null): void {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return;\n if (element === undefined && this.#document) {\n const source = adapter.getSource();\n const next = authoring.update(source, change);\n if (next !== source) adapter.setSource(next);\n return;\n }\n const id = element === undefined ? this.#shown : element;\n if (id === null) return;\n const current = adapter.getElement(id);\n if (current === null) return;\n const next = authoring.update(current, change);\n if (next !== current) adapter.replaceElement(id, next);\n }\n\n protected override updated(): void {\n const focus = this.#focus;\n if (focus === null) return;\n this.#focus = null;\n const item = focus.item === 'add' ? '[data-add]' : `[data-item=\"${focus.item}\"]`;\n this.renderRoot.querySelector<HTMLElement>(`[data-field=\"${focus.field}\"]${item}`)?.focus();\n }\n\n /** `short` marks a field that may sit beside another (`--astl-inspector-columns`). */\n #fieldClass(field: InspectorFieldModel): string {\n return fitsBeside(field) ? 'field short' : 'field';\n }\n\n #help(field: InspectorFieldModel, i: number): TemplateResult | typeof nothing {\n return field.help === null ? nothing : html`<p class=\"help\" id=\"help-${i}\">${field.help}</p>`;\n }\n\n #describedBy(field: InspectorFieldModel, i: number): string | undefined {\n return field.help === null ? undefined : `help-${i}`;\n }\n\n #text(field: TextFieldModel, i: number): TemplateResult {\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({\n kind: 'attribute',\n name: field.name,\n value: value === '' && !field.required ? null : value,\n });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <input\n id=\"field-${i}\"\n type=\"text\"\n dir=\"auto\"\n autocomplete=\"off\"\n data-name=${field.name}\n .value=${live(field.value)}\n ?required=${field.required}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @input=${commit}\n />\n ${this.#help(field, i)}\n ${field.accept === null || this.authoring?.uploadAsset == null ? nothing : this.#uploadControl(field, field.accept)}\n </div>`;\n }\n\n /** A button that picks a file for a `url` field and uploads it, and what the last upload says. */\n #uploadControl(field: TextFieldModel, accept: string): TemplateResult {\n const said = this.#upload;\n const status = said?.element === this.#shown && said.name === field.name ? said : null;\n const words = status === null ? '' : (status.text ?? this.t(status.key));\n const pick = (event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n input.value = '';\n if (file !== undefined) void this.#uploadFile(field, file);\n };\n return html`<div class=\"upload\">\n <button\n type=\"button\"\n aria-label=${this.t('inspector.uploadItem', { label: field.label })}\n @click=${(event: Event) => ((event.currentTarget as Element).nextElementSibling as HTMLElement).click()}\n >\n ${this.t('inspector.upload')}\n </button>\n <input type=\"file\" accept=${accept} hidden data-name=${field.name} @change=${pick} />\n <div role=\"status\">${status !== null && !status.error ? html`<p class=\"help\">${words}</p>` : nothing}</div>\n <div role=\"alert\">${status?.error ? html`<p class=\"error\">${words}</p>` : nothing}</div>\n </div>`;\n }\n\n /**\n * Uploads a file with the host's `uploadAsset` and writes its address, when the URL policy allows it (asked as the\n * engine asks: the element's tag and attribute), into the element shown when it started.\n */\n async #uploadFile(field: TextFieldModel, file: File): Promise<void> {\n const authoring = this.authoring;\n const upload = authoring?.uploadAsset ?? null;\n if (authoring === null || upload === null) return;\n const element = this.#shown;\n const tag = this.#model?.tag ?? '';\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n const say = (key: string, error = false, text?: string) => {\n this.#upload = { element, name: field.name, key, error, text };\n this.requestUpdate();\n };\n say('inspector.uploading');\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (abort.signal.aborted) return;\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (src === '' || !authoring.urlPolicy(src, { tag, attribute: field.name })) {\n say('inspector.uploadBlocked', true);\n return;\n }\n this.#apply({ kind: 'attribute', name: field.name, value: src }, element);\n say('inspector.uploaded');\n } catch (error) {\n if (!abort.signal.aborted) say('inspector.uploadFailed', true, refusalOf(error));\n }\n }\n\n #number(field: NumberFieldModel, i: number): TemplateResult {\n // Numbers commit on change (blur, Enter, arrows): half-typed values like \"0.\" never reach the source.\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({ kind: 'attribute', name: field.name, value: value === '' ? null : value });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <input\n id=\"field-${i}\"\n type=\"number\"\n data-name=${field.name}\n min=${ifDefined(field.min ?? undefined)}\n max=${ifDefined(field.max ?? undefined)}\n step=${field.step}\n .value=${live(field.value)}\n ?required=${field.required}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${commit}\n />\n ${this.#help(field, i)}\n </div>`;\n }\n\n #checkbox(field: CheckboxFieldModel, i: number): TemplateResult {\n return html`<div class=\"field\" part=\"field\">\n <label class=\"check\" part=\"label\">\n <input\n type=\"checkbox\"\n data-name=${field.name}\n .checked=${live(field.checked)}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${(event: Event) =>\n this.#apply({ kind: 'attribute', name: field.name, value: checkedOf(event) })}\n />\n <span>${field.label}</span>\n </label>\n ${this.#help(field, i)}\n </div>`;\n }\n\n #select(field: SelectFieldModel, i: number): TemplateResult {\n const commit = (event: Event) => {\n const value = inputValue(event);\n this.#apply({ kind: 'attribute', name: field.name, value: value === '' ? null : value });\n };\n return html`<div class=${this.#fieldClass(field)} part=\"field\">\n <label for=\"field-${i}\" part=\"label\">${field.label}</label>\n <select\n id=\"field-${i}\"\n data-name=${field.name}\n aria-describedby=${ifDefined(this.#describedBy(field, i))}\n @change=${commit}\n >\n ${field.options.map(\n (option) =>\n html`<option value=${option.value} .selected=${live(option.value === field.value)}>${option.label}</option>`,\n )}\n </select>\n ${this.#help(field, i)}\n </div>`;\n }\n\n #textList(field: TextListFieldModel, i: number): TemplateResult {\n const values = field.values;\n const set = (next: readonly string[]) => this.#apply({ kind: 'text-list', tag: field.tag, values: next });\n const add = () => {\n this.#focus = { field: i, item: values.length };\n set([...values, '']);\n };\n const remove = (j: number) => {\n const next = values.filter((_, k) => k !== j);\n this.#focus = { field: i, item: next.length === 0 ? 'add' : Math.min(j, next.length - 1) };\n set(next);\n };\n const full = field.max !== null && values.length >= field.max;\n return html`<fieldset data-tag=${field.tag} part=\"field\">\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${\n values.length === 0\n ? nothing\n : html`<ul role=\"list\">\n ${values.map((value, j) => {\n const name = this.t('inspector.item', { label: field.label, n: j + 1 });\n const described = ifDefined(this.#describedBy(field, i));\n const write = (event: Event) => set(values.map((v, k) => (k === j ? inputValue(event) : v)));\n // A multi-line value (a transcript) in a text area that keeps its line breaks.\n return html`<li class=\"item\">\n ${\n field.multiline\n ? html`<textarea dir=\"auto\" data-field=${i} data-item=${j} aria-label=${name}\n aria-describedby=${described} .value=${live(value)} @input=${write}></textarea>`\n : html`<input type=\"text\" dir=\"auto\" autocomplete=\"off\" data-field=${i} data-item=${j}\n aria-label=${name} aria-describedby=${described} .value=${live(value)} @input=${write} />`\n }\n <button\n type=\"button\"\n aria-label=${this.t('inspector.removeItem', { label: field.label, n: j + 1 })}\n @click=${() => remove(j)}\n >\n ${this.t('inspector.remove')}\n </button>\n </li>`;\n })}\n </ul>`\n }\n <button type=\"button\" data-field=${i} data-add ?disabled=${full} @click=${add}>${this.t('inspector.add')}</button>\n </fieldset>`;\n }\n\n #childFlags(field: ChildFlagFieldModel, i: number): TemplateResult {\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map(\n (child) => html`<label class=\"check\">\n <input\n type=\"checkbox\"\n data-index=${child.index}\n .checked=${live(child.checked)}\n @change=${(event: Event) =>\n this.#apply({\n kind: 'child-flag',\n tag: field.tag,\n attribute: field.attribute,\n index: child.index,\n value: checkedOf(event),\n })}\n />\n <span dir=\"auto\">${child.label}</span>\n </label>`,\n )}\n </fieldset>`;\n }\n\n /** A text input per child, labelled by the child's text (e.g. the word each clue hides); empty removes the value. */\n #childTexts(field: ChildTextFieldModel, i: number): TemplateResult {\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map(\n (child) => html`<div class=\"pick\">\n <label for=\"field-${i}-${child.index}\" dir=\"auto\">${child.label}</label>\n <input\n id=\"field-${i}-${child.index}\"\n type=\"text\"\n dir=\"auto\"\n autocomplete=\"off\"\n data-index=${child.index}\n .value=${live(child.value)}\n @input=${(event: Event) =>\n this.#apply({\n kind: 'child-attributes',\n tag: field.tag,\n index: child.index,\n attributes: { [field.attribute]: inputValue(event) || null },\n })}\n />\n </div>`,\n )}\n </fieldset>`;\n }\n\n /**\n * One control per child, named by the child's text: a radio group of the attribute's values (e.g. True / False for\n * each statement), or a select of the ids of other children (e.g. the group of each card).\n */\n #childChoices(field: ChildChoiceFieldModel, i: number): TemplateResult {\n const choose = (index: number, value: string | null) =>\n this.#apply({ kind: 'child-choice', tag: field.tag, attribute: field.attribute, index, value });\n return html`<fieldset data-tag=${field.tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${field.children.map((child) =>\n field.control === 'radios'\n ? html`<fieldset class=\"choice\" data-index=${child.index}>\n <legend dir=\"auto\">${child.label}</legend>\n <div class=\"values\">\n ${child.options.map(\n (option) => html`<label class=\"check\">\n <input\n type=\"radio\"\n name=\"choice-${i}-${child.index}\"\n value=${option.value}\n .checked=${live(child.value === option.value)}\n @change=${() => choose(child.index, option.value)}\n />\n <span>${option.label}</span>\n </label>`,\n )}\n </div>\n </fieldset>`\n : html`<div class=\"pick\">\n <label for=\"field-${i}-${child.index}\" dir=\"auto\">${child.label}</label>\n <select\n id=\"field-${i}-${child.index}\"\n data-index=${child.index}\n @change=${(event: Event) => choose(child.index, inputValue(event) || null)}\n >\n ${child.options.map(\n (option) =>\n html`<option value=${option.value} .selected=${live(option.value === child.value)}>${option.label}</option>`,\n )}\n </select>\n </div>`,\n )}\n </fieldset>`;\n }\n\n /**\n * A row per child, named by its text, with a labelled control per column (text and numbers commit like the attribute\n * fields), a button that removes the row, and one that adds a row at the end.\n */\n #childTable(field: ChildTableFieldModel, i: number): TemplateResult {\n const { tag, rows, columns } = field;\n const change = (index: number, attribute: string, value: string, required: boolean) =>\n this.#apply({\n kind: 'child-attributes',\n tag,\n index,\n attributes: { [attribute]: value || (required ? '' : null) },\n });\n const add = () => {\n this.#focus = { field: i, item: rows.length };\n this.#apply({ kind: 'child-add', tag, attributes: field.added });\n };\n const remove = (index: number) => {\n this.#focus = { field: i, item: rows.length > 1 ? Math.min(index, rows.length - 2) : 'add' };\n this.#apply({ kind: 'child-remove', tag, index });\n };\n const control = (\n column: ChildTableFieldModel['columns'][number],\n row: ChildTableFieldModel['rows'][number],\n k: number,\n ) => {\n const value = row.values[k] ?? '';\n const commit = (event: Event) =>\n change(row.index, column.attribute, inputValue(event), column.required);\n const first = k === 0 ? { field: i, item: row.index } : null;\n if (column.control === 'select') {\n const known = column.options.some((o) => o.value === value);\n const options = known\n ? column.options\n : [...column.options, { value, label: value || this.t('inspector.unset') }];\n return html`<select data-field=${ifDefined(first?.field)} data-item=${ifDefined(first?.item)} data-name=${column.attribute} @change=${commit}>\n ${options.map((o) => html`<option value=${o.value} .selected=${live(o.value === value)}>${o.label}</option>`)}\n </select>`;\n }\n return html`<input\n type=${column.control}\n dir=${column.control === 'text' ? 'auto' : nothing}\n autocomplete=\"off\"\n data-field=${ifDefined(first?.field)}\n data-item=${ifDefined(first?.item)}\n data-name=${column.attribute}\n min=${ifDefined(column.min ?? undefined)}\n max=${ifDefined(column.max ?? undefined)}\n step=${ifDefined(column.control === 'number' ? column.step : undefined)}\n .value=${live(value)}\n @input=${column.control === 'text' ? commit : nothing}\n @change=${column.control === 'number' ? commit : nothing}\n />`;\n };\n return html`<fieldset data-tag=${tag} part=\"field\" aria-describedby=${ifDefined(this.#describedBy(field, i))}>\n <legend part=\"label\">${field.label}</legend>\n ${this.#help(field, i)}\n ${rows.map(\n (row) => html`<fieldset class=\"row\" data-index=${row.index}>\n <legend dir=\"auto\">${row.label}</legend>\n <div class=\"cells\">\n ${columns.map(\n (column, k) =>\n html`<label class=\"cell\"><span>${column.label}</span>${control(column, row, k)}</label>`,\n )}\n <button\n type=\"button\"\n aria-label=${this.t('inspector.removeItem', { label: field.label, n: row.index + 1 })}\n ?disabled=${rows.length <= field.min}\n @click=${() => remove(row.index)}\n >\n ${this.t('inspector.remove')}\n </button>\n </div>\n </fieldset>`,\n )}\n <button type=\"button\" data-field=${i} data-add ?disabled=${field.max !== null && rows.length >= field.max} @click=${add}>\n ${this.t('inspector.add')}\n </button>\n </fieldset>`;\n }\n\n #field(field: InspectorFieldModel, i: number): TemplateResult {\n switch (field.kind) {\n case 'picture-regions':\n case 'picture-points':\n return html`<astl-picture-field\n .field=${field}\n .authoring=${this.authoring}\n .element=${this.#shown}\n @astl-field-change=${(event: CustomEvent<FieldChange>) => this.#apply(event.detail.change, event.detail.element)}\n ></astl-picture-field>`;\n case 'text-list':\n return this.#textList(field, i);\n case 'child-flag':\n return this.#childFlags(field, i);\n case 'child-text':\n return this.#childTexts(field, i);\n case 'child-choice':\n return this.#childChoices(field, i);\n case 'child-table':\n return this.#childTable(field, i);\n case 'attribute':\n switch (field.control) {\n case 'text':\n return this.#text(field, i);\n case 'number':\n return this.#number(field, i);\n case 'checkbox':\n return this.#checkbox(field, i);\n case 'select':\n return this.#select(field, i);\n }\n }\n }\n\n /**\n * The icon buttons of a block component's head, named and with a tooltip by their text: each needs the cursor's block\n * (`getCursor`) and its own capability. A move off the page's start or end is unavailable but keeps the focus; after a\n * delete the focus goes to the editor.\n */\n #actions(tag: string): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n const place: EditorBlockPlace | null = adapter?.getCursor?.() ?? null;\n if (authoring === null || adapter === null || place === null) return nothing;\n if (authoring.descriptor(tag)?.manifest.display !== 'block') return nothing;\n const page = authoring.outline(adapter.getSource()).pages.find((p) => p.id === place.page);\n const button = (name: keyof typeof ACTION_ICONS, off: boolean, run: () => void) =>\n html`<button type=\"button\" class=${name} data-action=${name} aria-label=${this.t(`inspector.${name}`)}\n title=${this.t(`inspector.${name}`)} aria-disabled=${off ? 'true' : nothing}\n @click=${() => {\n if (!off) run();\n }}><svg class=\"icon glyph\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${ACTION_ICONS[name]}</svg></button>`;\n const move = (direction: 'up' | 'down') => () => adapter.moveBlock?.(place, direction);\n return html`<div class=\"actions\" part=\"actions\">\n ${adapter.moveBlock === undefined ? nothing : button('moveUp', place.index === 0, move('up'))}\n ${adapter.moveBlock === undefined ? nothing : button('moveDown', place.index >= (page?.blocks.length ?? 0) - 1, move('down'))}\n ${\n adapter.removeBlock === undefined\n ? nothing\n : button('delete', false, () => {\n adapter.removeBlock?.(place);\n adapter.focus?.();\n })\n }\n </div>`;\n }\n\n /** The element's own issues, the sentences its frame shows (`authoring.describe` without the page), errors first. */\n #issues(model: InspectorModel): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null || model.id === null) return nothing;\n const source = adapter.getSource();\n const issues = sortIssues(authoring.validate(source).issues.filter((i) => i.at.element === model.id));\n if (issues.length === 0) return nothing;\n return html`<ul class=\"issues\" role=\"list\">\n ${issues.map(\n (\n issue,\n ) => html`<li class=\"issue\" part=\"issue\" data-code=${issue.code} data-severity=${issue.severity}>\n <svg class=\"icon\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${SEVERITY_ICONS[issue.severity]}</svg>\n <span class=\"astl-vh\">${this.t(`severity.${issue.severity}`)}: </span>\n <span>${authoring.describe(issue, source, { page: false })}</span>\n </li>`,\n )}\n </ul>`;\n }\n\n /** The head: the type's icon and name, the id in a chip when it has one, then the block's actions. */\n #head(model: InspectorModel): TemplateResult {\n const display = this.authoring?.descriptor(model.tag)?.manifest.display;\n const glyph = TYPE_GLYPHS.get(model.icon ?? '') ?? GLYPHS[display === 'inline' ? 'inline' : 'block'];\n return html`<div class=\"head\" part=\"head header\">\n <svg class=\"icon glyph\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${glyph}</svg>\n <h2 class=\"title\" id=\"title\" part=\"title\" data-id=${model.id ?? nothing}>${model.label}</h2>\n ${model.id === null ? nothing : html`<code class=\"id\" part=\"id\">${model.id}</code>`}\n ${this.#actions(model.tag)}\n </div>`;\n }\n\n /** The kinds at the cursor: when they change, so does the style section. */\n #styleKinds = '';\n /** The target whose form is open here, while it is at the cursor. */\n #styleOpen: EditorStyleTargetKind | null = null;\n\n protected override cursorChanged(): void {\n const targets = this.adapter?.style?.state().targets ?? [];\n const kinds = targets.map((target) => target.kind).join(' ');\n if (kinds === this.#styleKinds) return;\n this.#styleKinds = kinds;\n // A picture has nothing else to set here, and its position and size are why it was selected.\n const first = targets[0]?.kind;\n this.#styleOpen = first === 'picture' ? first : null;\n if (this.#styleOpen !== null) void this.#showStyle(this.#styleOpen);\n this.requestUpdate();\n }\n\n /** Shows a form here, the module loaded first. */\n async #showStyle(kind: EditorStyleTargetKind): Promise<void> {\n await loadStyleElements();\n this.#styleOpen = kind;\n this.requestUpdate();\n }\n\n /** A press on a target: a host may take it (`astl-style-open`); otherwise its form opens here, or closes. */\n #askStyle(kind: EditorStyleTargetKind): void {\n if (this.#styleOpen === kind) {\n this.#styleOpen = null;\n this.requestUpdate();\n return;\n }\n const detail: StyleOpen = { target: kind };\n const event = new CustomEvent(STYLE_OPEN, { detail, bubbles: true, composed: true, cancelable: true });\n if (this.dispatchEvent(event)) void this.#showStyle(kind);\n }\n\n /** The style of what the cursor is in: a button per target, and the open one's form. */\n #styleSection(): TemplateResult | typeof nothing {\n const targets = this.adapter?.style?.state().targets ?? [];\n if (targets.length === 0) return nothing;\n const open = targets.some((target) => target.kind === this.#styleOpen) ? this.#styleOpen : null;\n return html`<div class=\"style\" part=\"style\">\n <h3 class=\"style-title\">${this.t('inspector.style')}</h3>\n <div class=\"style-targets\">\n ${targets.map(\n (target) => html`<button\n type=\"button\"\n data-style-target=${target.kind}\n aria-expanded=${String(open === target.kind)}\n @click=${() => this.#askStyle(target.kind)}\n >\n ${this.t(`style.target.${target.kind}`)}\n </button>`,\n )}\n </div>\n ${\n open === null\n ? nothing\n : html`<astl-style-form .authoring=${this.authoring} .adapter=${this.adapter} .target=${open}></astl-style-form>`\n }\n </div>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n const selection = adapter?.getSelection() ?? null;\n const source = selection === null || adapter === null ? null : adapter.getElement(selection.id);\n // With the document: a field may list what another element holds (the words of a drop's bank).\n const model = source === null ? null : authoring.inspect(source, adapter?.getSource());\n // Outside every component: the document's own settings, under the hint.\n const document =\n selection === null && adapter !== null ? authoring.inspectDocument(adapter.getSource()) : null;\n this.#shown = model === null ? null : (selection?.id ?? null);\n this.#document = model === null && document !== null;\n this.#model = model ?? document;\n const { lang, dir } = this.ui;\n let body: TemplateResult;\n if (model === null) {\n const note =\n source !== null && selection !== null\n ? this.t('inspector.unsupported', { tag: selection.tag })\n : this.t('inspector.empty');\n body = html`<h2 class=\"title\" id=\"title\" part=\"title\">${this.t('inspector.title')}</h2>\n <p class=\"note\">${note}</p>\n ${\n document === null\n ? nothing\n : html`<div class=\"fields\" data-tag=${document.tag}>${document.fields.map((f, i) => this.#field(f, i))}</div>`\n }`;\n } else {\n // The heading says the type; the id is beside it in a chip, outside the heading.\n // A graded element's help for students: a form of its own, loaded on first use.\n const manifest = authoring.descriptor(model.tag)?.manifest;\n if (manifest?.graded === true) void loadHelpForm().catch(() => {});\n body = html`${this.#head(model)}${this.#issues(model)}\n <div class=\"fields\" data-tag=${model.tag}>${model.fields.map((f, i) => this.#field(f, i))}</div>\n ${\n manifest?.graded === true\n ? html`<astl-help-form .authoring=${authoring} .adapter=${adapter} .element=${this.#shown}\n ?inline=${manifest.display === 'inline'}></astl-help-form>`\n : nothing\n }`;\n }\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"title\">${body}${this.#styleSection()}</section>`;\n }\n}\n","import type { Issue } from '@astl/core';\nimport { type CSSResultGroup, html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { AuthoringElement } from './base.js';\nimport { issueStyles, renderIssues } from './issue-list.js';\nimport { kitStyles } from './styles.js';\n\n/** Validation waits this long after the last change, so typing is not interrupted. */\nexport const VALIDATION_DELAY_MS = 300;\n\n/**\n * `<astl-issues>`: live validation of the whole document in the UI locale, errors first. Selecting an issue moves the\n * editor's cursor to its element (`adapter.select`).\n */\nexport class AstlIssues extends AuthoringElement {\n static override styles: CSSResultGroup = [kitStyles, issueStyles];\n\n #issues: readonly Issue[] | null = null;\n /** The source the issues are about. */\n #source = '';\n #timer: ReturnType<typeof setTimeout> | undefined;\n\n /** The issues on screen (null before the first validation). */\n get issues(): readonly Issue[] | null {\n return this.#issues;\n }\n\n /** Validates now instead of waiting for the debounce. */\n validate(): void {\n clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#check();\n this.requestUpdate();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n // Back in the document: the source may have changed while we were not listening.\n if (this.hasUpdated) this.validate();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n clearTimeout(this.#timer);\n this.#timer = undefined;\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('authoring') || changed.has('adapter')) this.#check();\n }\n\n #check(): void {\n const { authoring, adapter } = this;\n this.#source = adapter?.getSource() ?? '';\n this.#issues = authoring === null || adapter === null ? null : authoring.validate(this.#source).issues;\n }\n\n protected override sourceChanged(): void {\n clearTimeout(this.#timer);\n this.#timer = setTimeout(() => this.validate(), VALIDATION_DELAY_MS);\n }\n\n protected override selectionChanged(): void {\n // The list does not depend on the cursor.\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n // Validation is synchronous: no issues means no adapter (no editor yet, or one that failed to load), so there is\n // no document to check and nothing to say.\n const issues = adapter === null ? null : this.#issues;\n const { lang, dir } = this.ui;\n let summary = '';\n if (issues !== null && issues.length === 0) summary = this.t('issues.none');\n else if (issues !== null) {\n const errors = issues.filter((i) => i.severity === 'error').length;\n summary = this.t('issues.summary', {\n errors: this.t('issues.errors', { count: errors }),\n warnings: this.t('issues.warnings', { count: issues.length - errors }),\n });\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('issues.title')}</h2>\n <p class=\"note summary\" role=\"status\" ?hidden=${issues === null}>${summary}</p>\n ${issues === null ? nothing : renderIssues(issues, authoring, adapter, this.#source)}\n </section>`;\n }\n}\n","import { type CSSResultGroup, css, html, nothing, type TemplateResult } from 'lit';\nimport { live } from 'lit/directives/live.js';\nimport { type PictureFields, pictureSize, refusalOf, type UploadedAsset } from '../authoring.js';\nimport { AuthoringElement } from './base.js';\nimport { kitStyles } from './styles.js';\n\n/** What `ask` opens the dialog with. */\nexport interface PictureRequest {\n /** A picture to edit: its address, alt text and size. Absent: a new picture. */\n readonly current?: PictureFields;\n /** A file to upload first (pasted or dropped), through the authoring's `uploadAsset`. */\n readonly file?: File;\n /** Whether to ask for a caption (a new picture). Default: true for a new picture, false for an edit. */\n readonly caption?: boolean;\n /** Whether `current` is decorative; default: when its alt text is empty. */\n readonly decorative?: boolean;\n /** The picture carries the task (a component's): its alt text is required, with no decorative choice. */\n readonly altRequired?: boolean;\n /** The element and attribute the address is for, as the URL policy is asked; default `img` and `src`. */\n readonly target?: { readonly tag: string; readonly attribute: string };\n}\n\n/** A message of the kit's catalog, or with `text` a host's own words in its place (`UploadRefused`). */\ntype Message = { readonly key: string; readonly error: boolean; readonly text?: string | undefined } | null;\n\n/** How long typing in the address pauses before the preview loads it: one request per address, not per keystroke. */\nexport const PREVIEW_DELAY_MS = 600;\n\n/**\n * `<astl-picture-dialog>`: asks for a picture in a modal dialog: a file, uploaded with the host's `uploadAsset`, one\n * from the host's library (`pickPicture`), or an address (the only way without either, as it says); the alt text,\n * required unless the picture is decorative (`alt=\"\"`); and, for a new picture, an optional caption. The address must\n * pass the authoring's URL policy, an uploaded or picked one too. `ask` resolves with the fields, or null when the\n * author cancels. While the library is open the dialog steps aside: it closes and keeps every field, so a modal of\n * the host's own, outside the top layer, takes the pointer and the keys; it opens again when the library settles.\n */\nexport class AstlPictureDialog extends AuthoringElement {\n static override styles: CSSResultGroup = [\n kitStyles,\n css`\n dialog {\n box-sizing: border-box;\n inline-size: min(32rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: calc(100dvh - 2 * var(--astl-space-4));\n padding: var(--astl-space-4);\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n color: var(--astl-ink);\n }\n dialog::backdrop {\n background: color-mix(in srgb, var(--astl-ink) 40%, transparent);\n }\n form {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n font-weight: 600;\n }\n label input {\n font-weight: 400;\n }\n label.check {\n flex-direction: row;\n align-items: center;\n min-block-size: var(--astl-target-min);\n font-weight: 400;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .sources {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .upload :is(.note, .error),\n .messages :is(.note, .error) {\n margin-block-start: var(--astl-space-2);\n }\n .preview {\n display: block;\n max-inline-size: 100%;\n max-block-size: 10rem;\n object-fit: contain;\n align-self: flex-start;\n border: var(--astl-outline-width) solid var(--astl-line);\n }\n .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .actions {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: var(--astl-space-2);\n }\n `,\n ];\n\n #resolve: ((fields: PictureFields | null) => void) | null = null;\n #editing = false;\n #withCaption = true;\n #altRequired = false;\n #target: { readonly tag: string; readonly attribute: string } = { tag: 'img', attribute: 'src' };\n #src = '';\n #alt = '';\n #decorative = false;\n #caption = '';\n #width: number | undefined;\n #height: number | undefined;\n /** What the last submit found wrong, shown by the buttons. */\n #message: Message = null;\n /** How the upload or the pick goes, shown by their buttons. */\n #uploadMessage: Message = null;\n /** An upload is under way: nothing is inserted before it ends. */\n #busy = false;\n /** The host's library is open: the dialog stepped aside for it, and its close is no cancel. */\n #picking = false;\n /** Bumped by every upload, pick, `ask` and close: an upload or a pick that ends after one is dropped. */\n #generation = 0;\n /** Aborts the upload or the pick under way (its `signal`). */\n #abort: AbortController | null = null;\n /** The address the preview shows: the current one, the uploaded one, or a typed one once typing pauses. */\n #preview = '';\n #previewTimer: ReturnType<typeof setTimeout> | undefined;\n\n /** Opens the dialog. Resolves with the picture's fields, or null when the author cancels. */\n async ask(request: PictureRequest = {}): Promise<PictureFields | null> {\n this.#finish(null);\n const current = request.current;\n this.#editing = current !== undefined;\n this.#withCaption = request.caption ?? !this.#editing;\n this.#altRequired = request.altRequired ?? false;\n this.#target = request.target ?? { tag: 'img', attribute: 'src' };\n this.#src = current?.src ?? '';\n this.#alt = current?.alt ?? '';\n this.#decorative = !this.#altRequired && (request.decorative ?? current?.alt === '');\n this.#caption = current?.caption ?? '';\n this.#width = current?.width;\n this.#height = current?.height;\n this.#preview = this.#src;\n this.#message = null;\n this.#uploadMessage = null;\n this.#stop();\n this.requestUpdate();\n await this.updateComplete;\n const result = new Promise<PictureFields | null>((resolve) => {\n this.#resolve = resolve;\n });\n this.#dialog()?.showModal();\n if (request.file !== undefined) void this.#upload(request.file);\n return result;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // Out of the document the dialog is out of the top layer, and a pick that ends later could not open it again.\n this.#finish(null);\n }\n\n #dialog(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n #finish(fields: PictureFields | null): void {\n const resolve = this.#resolve;\n this.#resolve = null;\n clearTimeout(this.#previewTimer);\n this.#stop();\n const dialog = this.#dialog();\n if (dialog?.open) dialog.close();\n resolve?.(fields);\n }\n\n /** Aborts the upload or the pick under way and drops its result. */\n #stop(): void {\n this.#abort?.abort();\n this.#abort = null;\n this.#generation++;\n this.#busy = false;\n this.#picking = false;\n }\n\n #allowed(src: string): boolean {\n const policy = this.authoring?.urlPolicy;\n return src.trim() !== '' && policy !== undefined && policy(src, this.#target);\n }\n\n /** Takes an uploaded or picked picture when the URL policy allows its address: the address, the preview, the size. */\n #take(asset: UploadedAsset): boolean {\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (!this.#allowed(src)) return false;\n this.#src = src;\n this.#preview = src;\n this.#width = pictureSize(asset.width);\n this.#height = pictureSize(asset.height);\n return true;\n }\n\n async #upload(file: File): Promise<void> {\n const upload = this.authoring?.uploadAsset ?? null;\n if (upload === null) return;\n this.#stop();\n const id = this.#generation;\n const abort = new AbortController();\n this.#abort = abort;\n this.#busy = true;\n this.#uploadMessage = { key: 'picture.uploading', error: false };\n this.requestUpdate();\n let message: Message;\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (id !== this.#generation) return;\n message = this.#take(asset)\n ? { key: 'picture.uploaded', error: false }\n : { key: 'picture.uploadBlocked', error: true };\n } catch (error) {\n if (id !== this.#generation) return;\n message = { key: 'picture.uploadFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n this.#busy = false;\n this.#uploadMessage = message;\n this.requestUpdate();\n }\n\n /**\n * Opens the host's library (`pickPicture`), stopping the upload under way. The dialog steps aside meanwhile: closed,\n * every field kept, so a modal of the host's own takes the pointer and the keys. When the library settles, the\n * dialog opens again with what it gave (unless the ask ended meanwhile), and the focus goes to the alt text after a\n * picture (to Insert or Save for a decorative one), else back to the library's button.\n */\n async #pick(): Promise<void> {\n const pick = this.authoring?.pickPicture ?? null;\n const dialog = this.#dialog();\n if (pick === null || dialog === null || !dialog.open) return;\n this.#stop();\n const id = this.#generation;\n const abort = new AbortController();\n this.#abort = abort;\n this.#picking = true;\n // What the buttons said was about an earlier upload or pick.\n this.#uploadMessage = null;\n dialog.close();\n let message: Message = null;\n let picked = false;\n try {\n const asset = await pick({ signal: abort.signal });\n if (id !== this.#generation) return;\n // Null: the author closed the library, and nothing changes.\n if (asset != null) {\n picked = this.#take(asset);\n message = picked\n ? { key: 'picture.picked', error: false }\n : { key: 'picture.pickBlocked', error: true };\n }\n } catch (error) {\n if (id !== this.#generation) return;\n message = { key: 'picture.pickFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n // The fields render before the dialog opens again; the message after, so its live region changes in sight.\n this.requestUpdate();\n await this.updateComplete;\n if (id !== this.#generation) return;\n // Gone with the authoring meanwhile: nothing to open again.\n const shown = this.#dialog();\n if (shown === null) {\n this.#finish(null);\n return;\n }\n this.#picking = false;\n shown.showModal();\n const next = picked ? (this.#decorative ? 'button[type=\"submit\"]' : '#alt') : '[data-library]';\n this.renderRoot.querySelector<HTMLElement>(next)?.focus();\n this.#uploadMessage = message;\n this.requestUpdate();\n }\n\n /** A polite status, or an alert for an error: both regions are always there, so screen readers hear the change. */\n #live(message: Message): TemplateResult {\n const said = message === null ? '' : (message.text ?? this.t(message.key));\n return html`<div role=\"status\">${message !== null && !message.error ? html`<p class=\"note\">${said}</p>` : nothing}</div>\n <div role=\"alert\">${message?.error ? html`<p class=\"error\">${said}</p>` : nothing}</div>`;\n }\n\n #submit(event: Event): void {\n event.preventDefault();\n if (this.#busy) return;\n const src = this.#src.trim();\n const alt = this.#alt.trim();\n if (src === '') this.#message = { key: 'picture.srcMissing', error: true };\n else if (!this.#allowed(src)) this.#message = { key: 'picture.srcBlocked', error: true };\n else if (!this.#decorative && alt === '') {\n this.#message = { key: this.#altRequired ? 'picture.altRequired' : 'picture.altMissing', error: true };\n } else {\n const caption = this.#withCaption ? this.#caption.trim() : '';\n this.#finish({\n src,\n alt: this.#decorative ? '' : alt,\n ...(this.#width === undefined ? {} : { width: this.#width }),\n ...(this.#height === undefined ? {} : { height: this.#height }),\n ...(caption === '' ? {} : { caption }),\n });\n return;\n }\n this.requestUpdate();\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n const upload = this.authoring.uploadAsset !== null;\n const library = this.authoring.pickPicture !== null;\n const message = this.#message;\n return html`<dialog\n part=\"dialog\"\n lang=${lang}\n dir=${dir}\n aria-labelledby=\"picture-title\"\n @close=${() => {\n // Escape, or a close the page made. The event comes a task later: a dialog opened again since stays, and one\n // that stepped aside for the host's library still asks.\n if (!this.#picking && !this.#dialog()?.open) this.#finish(null);\n }}\n >\n <form @submit=${(event: Event) => this.#submit(event)} novalidate>\n <h2 class=\"title\" id=\"picture-title\">${this.t(this.#editing ? 'picture.editTitle' : 'picture.title')}</h2>\n ${\n upload || library\n ? html`<div class=\"upload\">\n <div class=\"sources\">\n ${\n upload\n ? html`<button\n type=\"button\"\n part=\"button\"\n ?disabled=${this.#busy}\n @click=${() => this.renderRoot.querySelector<HTMLInputElement>('input[type=\"file\"]')?.click()}\n >\n ${this.t('picture.file')}\n </button>`\n : nothing\n }\n ${\n library\n ? html`<button type=\"button\" part=\"button\" data-library @click=${() => void this.#pick()}>\n ${this.t('picture.library')}\n </button>`\n : nothing\n }\n </div>\n ${\n upload\n ? html`<input\n type=\"file\"\n accept=\"image/*\"\n hidden\n @change=${(event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n // Picking the same file again uploads it again.\n input.value = '';\n if (file !== undefined) void this.#upload(file);\n }}\n />`\n : nothing\n }\n ${this.#live(this.#uploadMessage)}\n </div>`\n : html`<p class=\"note\">${this.t('picture.urlOnly')}</p>`\n }\n <label>\n ${this.t('picture.src')}\n <input\n type=\"url\"\n inputmode=\"url\"\n autocomplete=\"off\"\n .value=${live(this.#src)}\n @input=${(event: Event) => {\n this.#src = (event.target as HTMLInputElement).value;\n this.#width = undefined;\n this.#height = undefined;\n clearTimeout(this.#previewTimer);\n this.#previewTimer = setTimeout(() => {\n this.#preview = this.#src.trim();\n this.requestUpdate();\n }, PREVIEW_DELAY_MS);\n }}\n />\n </label>\n ${\n this.#allowed(this.#preview)\n ? html`<img class=\"preview\" src=${this.#preview} alt=\"\" referrerpolicy=\"no-referrer\" />`\n : nothing\n }\n <label>\n ${this.t('picture.alt')}\n <input\n type=\"text\"\n id=\"alt\"\n aria-describedby=\"alt-help\"\n .value=${live(this.#alt)}\n ?disabled=${this.#decorative}\n @input=${(event: Event) => {\n this.#alt = (event.target as HTMLInputElement).value;\n }}\n />\n </label>\n <p class=\"note\" id=\"alt-help\">${this.t('picture.altHelp')}</p>\n ${\n this.#altRequired\n ? nothing\n : html`<label class=\"check\">\n <input\n type=\"checkbox\"\n .checked=${this.#decorative}\n @change=${(event: Event) => {\n this.#decorative = (event.target as HTMLInputElement).checked;\n this.requestUpdate();\n }}\n />\n ${this.t('picture.decorative')}\n </label>`\n }\n ${\n this.#withCaption\n ? html`<label>\n ${this.t('picture.caption')}\n <input\n type=\"text\"\n .value=${live(this.#caption)}\n @input=${(event: Event) => {\n this.#caption = (event.target as HTMLInputElement).value;\n }}\n />\n </label>`\n : nothing\n }\n <div class=\"messages\">${this.#live(message)}</div>\n <div class=\"actions\">\n <button type=\"button\" part=\"button\" @click=${() => this.#finish(null)}>${this.t('picture.cancel')}</button>\n <button type=\"submit\" class=\"primary\" part=\"button\" ?disabled=${this.#busy}>\n ${this.t(this.#editing ? 'picture.save' : 'picture.insert')}\n </button>\n </div>\n </form>\n </dialog>`;\n }\n}\n","import type { MessageParams } from '@astl/core';\nimport { PALETTE } from '@astl/tokens';\nimport {\n type CSSResultGroup,\n css,\n html,\n LitElement,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type SVGTemplateResult,\n svg,\n type TemplateResult,\n} from 'lit';\nimport { type Authoring, refusalOf, type UploadedAsset } from '../authoring.js';\nimport type { InspectorChange } from '../edit.js';\nimport type {\n PicturePointModel,\n PicturePointsFieldModel,\n PictureRegionModel,\n PictureRegionsFieldModel,\n} from '../inspect.js';\nimport { EDITOR_NAMESPACE } from '../messages.js';\nimport { kitStyles } from './styles.js';\n\n/** Fired with a FieldChange for the inspector to apply. */\nexport const FIELD_CHANGE = 'astl-field-change';\n\n/** A change of the field, and the source id of the element it is for (an upload may end after the cursor moved). */\nexport interface FieldChange {\n readonly change: InspectorChange;\n readonly element: string | null;\n}\n\ntype Field = PictureRegionsFieldModel | PicturePointsFieldModel;\ntype Shape = PictureRegionModel['shape'];\n/** What the field says of its upload or pick: a key of the kit's catalog, or a host's own words (`UploadRefused`). */\ntype Status = { readonly key: string; readonly error: boolean; readonly text?: string | undefined };\n\nconst round = (n: number) => Math.round(Math.min(100, Math.max(0, n)) * 10) / 10;\nconst num = (n: number) => String(round(n));\n/** Most zones, pins or polygon points the field lists (and polygons take): more are edited in the source. */\nconst MAX_LISTED = 64;\n/** Palette slot of the n-th item (from 0), as a class: `c1` to `c8`. */\nconst slot = (index: number) => `c${(index % PALETTE.length) + 1}`;\n\n/** The attributes that describe a zone of `shape` around the zone's centre: switching the shape keeps the centre. */\nfunction reshaped(region: PictureRegionModel, shape: Shape): Record<string, string | null> {\n const box = boundsOf(region);\n const cx = (box.left + box.right) / 2;\n const cy = (box.top + box.bottom) / 2;\n const w = Math.max(1, box.right - box.left);\n const h = Math.max(1, box.bottom - box.top);\n const cleared = { x: null, y: null, width: null, height: null, r: null, points: null };\n if (shape === 'circle') return { ...cleared, shape, x: num(cx), y: num(cy), r: num(w / 2) };\n if (shape === 'polygon') {\n const points = [\n [box.left, box.top],\n [box.right, box.top],\n [box.right, box.bottom],\n [box.left, box.bottom],\n ];\n return { ...cleared, shape, points: points.map(([x = 0, y = 0]) => `${num(x)},${num(y)}`).join(' ') };\n }\n return { ...cleared, shape, x: num(cx - w / 2), y: num(cy - h / 2), width: num(w), height: num(h) };\n}\n\n/** A zone's bounding box in percent. */\nfunction boundsOf(region: PictureRegionModel): { left: number; top: number; right: number; bottom: number } {\n if (region.shape === 'circle') {\n return {\n left: region.x - region.r,\n top: region.y - region.r,\n right: region.x + region.r,\n bottom: region.y + region.r,\n };\n }\n if (region.shape === 'polygon' && region.points.length > 0) {\n // A loop, not Math.min(...xs): a polygon of any size never overflows the call stack.\n const box = { left: 100, top: 100, right: 0, bottom: 0 };\n for (const [x, y] of region.points) {\n box.left = Math.min(box.left, x);\n box.top = Math.min(box.top, y);\n box.right = Math.max(box.right, x);\n box.bottom = Math.max(box.bottom, y);\n }\n return box;\n }\n return { left: region.x, top: region.y, right: region.x + region.width, bottom: region.y + region.height };\n}\n\n/** Where a zone's number sits: its centre. */\nfunction anchorOf(region: PictureRegionModel): readonly [number, number] {\n const box = boundsOf(region);\n return [(box.left + box.right) / 2, (box.top + box.bottom) / 2];\n}\n\n/**\n * `<astl-picture-field>`: the inspector's `picture-regions` and `picture-points` fields. The picture (by address,\n * uploaded with the host's `uploadAsset` or chosen from its library, `pickPicture`) with its zones or pins drawn on\n * it in palette colours and numbered; drag on it to draw a zone, click to place a pin; and every value in number\n * fields, so nothing needs a pointer. Changes go to the inspector as `astl-field-change` events.\n */\nexport class AstlPictureField extends LitElement {\n static override properties: PropertyDeclarations = {\n field: { attribute: false },\n authoring: { attribute: false },\n element: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n css`\n fieldset {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n min-inline-size: 0;\n margin: 0;\n padding: var(--astl-space-3);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n }\n legend {\n padding-inline: var(--astl-space-1);\n font-weight: 600;\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-1);\n }\n .canvas {\n position: relative;\n inline-size: 100%;\n touch-action: none;\n cursor: crosshair;\n user-select: none;\n border: var(--astl-outline-width) solid var(--astl-line);\n background: var(--astl-surface-raised);\n }\n .canvas img {\n display: block;\n inline-size: 100%;\n block-size: auto;\n }\n .canvas .blank {\n aspect-ratio: 4 / 3;\n }\n .canvas svg {\n position: absolute;\n inset: 0;\n inline-size: 100%;\n block-size: 100%;\n overflow: visible;\n }\n .shape {\n fill: var(--soft);\n fill-opacity: 0.4;\n stroke: var(--line);\n stroke-width: 2;\n vector-effect: non-scaling-stroke;\n }\n .shape.unflagged {\n fill-opacity: 0.15;\n stroke-dasharray: 6 4;\n }\n .draft {\n fill: none;\n stroke: var(--astl-ink);\n stroke-width: 2;\n stroke-dasharray: 4 3;\n vector-effect: non-scaling-stroke;\n }\n .badge {\n position: absolute;\n inset-inline-start: var(--x);\n inset-block-start: var(--y);\n transform: translate(-50%, -50%);\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n min-inline-size: 1.5rem;\n block-size: 1.5rem;\n padding-inline: var(--astl-space-1);\n border: var(--astl-outline-width) solid var(--line);\n border-radius: 999px;\n background: var(--astl-surface);\n color: var(--astl-ink);\n font-size: var(--astl-size-small);\n font-weight: 700;\n pointer-events: none;\n }\n .pin {\n border-width: calc(2 * var(--astl-outline-width));\n }\n .swatch {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-inline-size: 1.5rem;\n block-size: 1.5rem;\n margin-inline-end: var(--astl-space-2);\n border: calc(2 * var(--astl-outline-width)) solid var(--line);\n border-radius: 999px;\n background: var(--soft);\n font-weight: 700;\n }\n .items {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-3);\n margin: 0;\n padding: 0;\n list-style: none;\n }\n .numbers {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));\n gap: var(--astl-space-2);\n }\n .numbers label {\n justify-content: flex-end;\n }\n .upload {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n }\n .upload :is(.note, .error) {\n margin-block-start: var(--astl-space-2);\n }\n .sources {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .error {\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n .vertex {\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n gap: var(--astl-space-2);\n }\n .vertex label {\n flex: 1 1 6rem;\n }\n .c1 { --line: var(--astl-palette-1); --soft: var(--astl-palette-1-soft); }\n .c2 { --line: var(--astl-palette-2); --soft: var(--astl-palette-2-soft); }\n .c3 { --line: var(--astl-palette-3); --soft: var(--astl-palette-3-soft); }\n .c4 { --line: var(--astl-palette-4); --soft: var(--astl-palette-4-soft); }\n .c5 { --line: var(--astl-palette-5); --soft: var(--astl-palette-5-soft); }\n .c6 { --line: var(--astl-palette-6); --soft: var(--astl-palette-6-soft); }\n .c7 { --line: var(--astl-palette-7); --soft: var(--astl-palette-7-soft); }\n .c8 { --line: var(--astl-palette-8); --soft: var(--astl-palette-8-soft); }\n @media (forced-colors: active) {\n .shape {\n fill: none;\n stroke: CanvasText;\n }\n .badge,\n .swatch {\n border-color: CanvasText;\n }\n }\n `,\n ];\n\n declare field: Field | null;\n declare authoring: Authoring | null;\n /** The source id of the element the field belongs to (the inspector sets it). */\n declare element: string | null;\n\n /** A zone being drawn: where the pointer went down and where it is, in percent. */\n #draft: { readonly x0: number; readonly y0: number; x1: number; y1: number } | null = null;\n /** Width over height of the picture (1 until it loads), so circles stay round. */\n #aspect = 1;\n #status: Status | null = null;\n /** Aborts the upload or the pick under way (its `signal`). */\n #abort: AbortController | null = null;\n\n constructor() {\n super();\n this.field = null;\n this.authoring = null;\n this.element = null;\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n // Another element's field: an upload message was about the one before.\n if (changed.has('element') && changed.get('element') !== undefined) this.#status = null;\n }\n\n #t(key: string, params?: MessageParams): string {\n return this.authoring?.t(EDITOR_NAMESPACE, key, params) ?? key;\n }\n\n #change(change: InspectorChange, element: string | null = this.element): void {\n this.dispatchEvent(new CustomEvent<FieldChange>(FIELD_CHANGE, { detail: { change, element } }));\n }\n\n /** Whether the URL policy allows the picture, asked as the engine and the player ask it: the element's attribute. */\n #allowed(field: Field, src: string): boolean {\n const context = { tag: field.elementTag, attribute: field.srcAttribute };\n return src.trim() !== '' && (this.authoring?.urlPolicy(src, context) ?? false);\n }\n\n /** A fresh local id for a new child: `<tag without astl->-<n>`. */\n #freshId(field: Field): string {\n const taken = new Set(\n field.kind === 'picture-points' ? field.points.map((p) => p.id) : field.regions.map((r) => r.id),\n );\n const prefix = field.tag.replace(/^astl-/, '');\n let n = 1;\n while (taken.has(`${prefix}-${n}`)) n++;\n return `${prefix}-${n}`;\n }\n\n #add(field: Field, at?: { x: number; y: number; width?: number; height?: number }): void {\n const id = this.#freshId(field);\n if (field.kind === 'picture-points') {\n const label = this.#t('field.point', { n: field.points.length + 1 });\n this.#change({\n kind: 'child-add',\n tag: field.tag,\n attributes: { id, x: num(at?.x ?? 50), y: num(at?.y ?? 50), label },\n });\n return;\n }\n const width = at?.width ?? 20;\n const height = at?.height ?? 20;\n const x = at === undefined ? 10 : at.x;\n const y = at === undefined ? 10 : at.y;\n // A zone that takes no other shape is written without one.\n const shape: Record<string, string> = field.shapes.length > 1 ? { shape: 'rect' } : {};\n this.#change({\n kind: 'child-add',\n tag: field.tag,\n attributes: { id, ...shape, x: num(x), y: num(y), width: num(width), height: num(height) },\n });\n }\n\n /** Writes the address of an uploaded or picked picture into the field's attribute of `element`, if the policy allows. */\n #write(field: Field, asset: UploadedAsset, element: string | null): boolean {\n const src = typeof asset?.src === 'string' ? asset.src.trim() : '';\n if (!this.#allowed(field, src)) return false;\n this.#change({ kind: 'attribute', name: field.srcAttribute, value: src }, element);\n return true;\n }\n\n async #upload(field: Field, file: File): Promise<void> {\n const upload = this.authoring?.uploadAsset ?? null;\n if (upload === null) return;\n // The address goes to the element of this field, wherever the cursor is when the upload ends.\n const element = this.element;\n // Another upload or pick replaces this upload.\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n this.#status = { key: 'picture.uploading', error: false };\n this.requestUpdate();\n let status: Status;\n try {\n const asset = await upload(file, { signal: abort.signal });\n if (abort.signal.aborted) return;\n status = this.#write(field, asset, element)\n ? { key: 'picture.uploaded', error: false }\n : { key: 'picture.uploadBlocked', error: true };\n } catch (error) {\n if (abort.signal.aborted) return;\n status = { key: 'picture.uploadFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n // Said where it happened only: the field may show another element by now.\n this.#status = this.element === element ? status : null;\n this.requestUpdate();\n }\n\n /** Opens the host's library (`pickPicture`) and writes the address it gives, as an upload does. */\n async #pick(field: Field): Promise<void> {\n const pick = this.authoring?.pickPicture ?? null;\n if (pick === null) return;\n const element = this.element;\n // Another upload or pick replaces this pick.\n this.#abort?.abort();\n const abort = new AbortController();\n this.#abort = abort;\n // What the field said was about an earlier upload or pick.\n this.#status = null;\n this.requestUpdate();\n let status: Status | null = null;\n try {\n const asset = await pick({ signal: abort.signal });\n if (abort.signal.aborted) return;\n // Null: the author closed the library, and nothing changes.\n if (asset != null) {\n status = this.#write(field, asset, element)\n ? { key: 'picture.picked', error: false }\n : { key: 'picture.pickBlocked', error: true };\n }\n } catch (error) {\n if (abort.signal.aborted) return;\n status = { key: 'picture.pickFailed', error: true, text: refusalOf(error) };\n }\n this.#abort = null;\n this.#status = this.element === element ? status : null;\n this.requestUpdate();\n // The focus goes back to the library's button, as the dialog gives it back: a host's modal restoring its own\n // cannot see into this shadow root, and the author's place would be lost.\n await this.updateComplete;\n if (this.isConnected) this.renderRoot.querySelector<HTMLElement>('[data-library]')?.focus();\n }\n\n /** Pointer position in percent of the picture: the canvas inside its border. */\n #at(event: PointerEvent): { x: number; y: number } {\n const canvas = event.currentTarget as HTMLElement;\n const box = canvas.getBoundingClientRect();\n return {\n x: round(((event.clientX - box.left - canvas.clientLeft) / Math.max(1, canvas.clientWidth)) * 100),\n y: round(((event.clientY - box.top - canvas.clientTop) / Math.max(1, canvas.clientHeight)) * 100),\n };\n }\n\n #down(event: PointerEvent): void {\n if (event.button !== 0) return;\n const { x, y } = this.#at(event);\n (event.currentTarget as HTMLElement).setPointerCapture?.(event.pointerId);\n this.#draft = { x0: x, y0: y, x1: x, y1: y };\n }\n\n #move(event: PointerEvent): void {\n if (this.#draft === null) return;\n const { x, y } = this.#at(event);\n this.#draft.x1 = x;\n this.#draft.y1 = y;\n this.requestUpdate();\n }\n\n #up(field: Field, event: PointerEvent): void {\n const draft = this.#draft;\n this.#draft = null;\n if (draft === null) return;\n const { x, y } = this.#at(event);\n if (field.kind === 'picture-points') {\n this.#add(field, { x, y });\n return;\n }\n const width = Math.abs(x - draft.x0);\n const height = Math.abs(y - draft.y0);\n // A click without a drag: a small zone around it.\n if (width < 2 && height < 2)\n this.#add(field, { x: draft.x0 - 5, y: draft.y0 - 5, width: 10, height: 10 });\n else this.#add(field, { x: Math.min(x, draft.x0), y: Math.min(y, draft.y0), width, height });\n this.requestUpdate();\n }\n\n /** A zone in its palette colour: solid, or dashed without the field's flag (a wrong place among right ones). */\n #shape(field: PictureRegionsFieldModel, region: PictureRegionModel): SVGTemplateResult {\n const unflagged = field.flag !== null && !region.flagged;\n const cls = `shape ${slot(region.index)}${unflagged ? ' unflagged' : ''}`;\n if (region.shape === 'circle') {\n return svg`<ellipse class=${cls} cx=${region.x} cy=${region.y} rx=${region.r} ry=${region.r * this.#aspect}></ellipse>`;\n }\n if (region.shape === 'polygon') {\n return svg`<polygon class=${cls} points=${region.points.map(([x, y]) => `${x},${y}`).join(' ')}></polygon>`;\n }\n return svg`<rect class=${cls} x=${region.x} y=${region.y} width=${region.width} height=${region.height}></rect>`;\n }\n\n #badge(index: number, [x, y]: readonly [number, number], pin: boolean): TemplateResult {\n return html`<span\n class=\"badge ${pin ? 'pin ' : ''}${slot(index)}\"\n aria-hidden=\"true\"\n data-x=${x}\n data-y=${y}\n >${index + 1}</span\n >`;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n // Badges are placed through the CSSOM: a strict Content Security Policy blocks a style attribute, which Lit's\n // styleMap writes on its first render.\n for (const badge of this.renderRoot.querySelectorAll<HTMLElement>('.badge')) {\n badge.style.setProperty('--x', `${badge.dataset.x}%`);\n badge.style.setProperty('--y', `${badge.dataset.y}%`);\n }\n }\n\n #canvas(field: Field): TemplateResult {\n const draft = this.#draft;\n const shown = this.#allowed(field, field.src);\n const shapes = field.kind === 'picture-regions' ? field.regions.map((r) => this.#shape(field, r)) : [];\n const badges =\n field.kind === 'picture-regions'\n ? field.regions.map((r) => this.#badge(r.index, anchorOf(r), false))\n : field.points.map((p) => this.#badge(p.index, [p.x, p.y], true));\n return html`<div\n class=\"canvas\"\n dir=\"ltr\"\n @pointerdown=${(event: PointerEvent) => this.#down(event)}\n @pointermove=${(event: PointerEvent) => this.#move(event)}\n @pointerup=${(event: PointerEvent) => this.#up(field, event)}\n @pointercancel=${() => {\n this.#draft = null;\n this.requestUpdate();\n }}\n >\n ${\n shown\n ? html`<img\n src=${field.src}\n alt=\"\"\n referrerpolicy=\"no-referrer\"\n draggable=\"false\"\n @load=${(event: Event) => {\n const img = event.target as HTMLImageElement;\n if (img.naturalHeight > 0) this.#aspect = img.naturalWidth / img.naturalHeight;\n this.requestUpdate();\n }}\n />`\n : html`<div class=\"blank\"></div>`\n }\n <svg viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" aria-hidden=\"true\" focusable=\"false\">\n ${shapes}\n ${\n draft === null || field.kind === 'picture-points'\n ? nothing\n : svg`<rect class=\"draft\" x=${Math.min(draft.x0, draft.x1)} y=${Math.min(draft.y0, draft.y1)}\n width=${Math.abs(draft.x1 - draft.x0)} height=${Math.abs(draft.y1 - draft.y0)}></rect>`\n }\n </svg>\n ${badges}\n </div>`;\n }\n\n /** Says that only the first items are listed, when there are more. */\n #more(count: number): TemplateResult | typeof nothing {\n return count > MAX_LISTED\n ? html`<p class=\"note\">${this.#t('field.more', { shown: MAX_LISTED, count })}</p>`\n : nothing;\n }\n\n #number(label: string, value: number, commit: (value: string) => void): TemplateResult {\n return html`<label>\n ${label}\n <input\n type=\"number\"\n min=\"0\"\n max=\"100\"\n step=\"0.1\"\n .value=${num(value)}\n @change=${(event: Event) => {\n const raw = (event.target as HTMLInputElement).value;\n if (raw !== '' && Number.isFinite(Number(raw))) commit(num(Number(raw)));\n }}\n />\n </label>`;\n }\n\n #labelField(field: Field, index: number, value: string): TemplateResult {\n const optional = field.kind === 'picture-regions';\n return html`<label>\n ${this.#t(optional ? 'field.label.optional' : 'field.label')}\n <input\n type=\"text\"\n dir=\"auto\"\n .value=${value}\n @change=${(event: Event) => {\n const text = (event.target as HTMLInputElement).value.trim();\n this.#change({\n kind: 'child-attributes',\n tag: field.tag,\n index,\n attributes: { label: text === '' && optional ? null : text },\n });\n }}\n />\n </label>`;\n }\n\n #region(field: PictureRegionsFieldModel, region: PictureRegionModel): TemplateResult {\n const n = region.index + 1;\n const set = (attributes: Record<string, string | null>) =>\n this.#change({ kind: 'child-attributes', tag: field.tag, index: region.index, attributes });\n const points = region.points;\n const setPoints = (next: readonly (readonly [number, number])[]) =>\n set({ points: next.map(([x, y]) => `${num(x)},${num(y)}`).join(' ') });\n const numbers =\n region.shape === 'circle'\n ? [\n this.#number(this.#t('field.cx'), region.x, (x) => set({ x })),\n this.#number(this.#t('field.cy'), region.y, (y) => set({ y })),\n this.#number(this.#t('field.r'), region.r, (r) => set({ r })),\n ]\n : region.shape === 'rect'\n ? [\n this.#number(this.#t('field.x'), region.x, (x) => set({ x })),\n this.#number(this.#t('field.y'), region.y, (y) => set({ y })),\n this.#number(this.#t('field.width'), region.width, (width) => set({ width })),\n this.#number(this.#t('field.height'), region.height, (height) => set({ height })),\n ]\n : [];\n return html`<li data-index=${region.index}>\n <fieldset>\n <legend><span class=\"swatch ${slot(region.index)}\" aria-hidden=\"true\">${n}</span>${this.#t('field.region', { n })}</legend>\n ${\n // Only zones that take more than one shape choose theirs.\n field.shapes.length > 1\n ? html`<label>\n ${this.#t('field.shape')}\n <select\n @change=${(event: Event) => set(reshaped(region, (event.target as HTMLSelectElement).value as Shape))}\n >\n ${field.shapes.map(\n (shape) =>\n html`<option value=${shape} ?selected=${shape === region.shape}>${this.#t(`field.shape.${shape}`)}</option>`,\n )}\n </select>\n </label>`\n : nothing\n }\n ${numbers.length > 0 ? html`<div class=\"numbers\">${numbers}</div>` : nothing}\n ${\n region.shape === 'polygon'\n ? html`<ol class=\"items\">\n ${points.slice(0, MAX_LISTED).map(\n ([x, y], k) => html`<li class=\"vertex\">\n ${this.#number(this.#t('field.vertex.x', { n: k + 1 }), x, (value) =>\n setPoints(points.map((p, j) => (j === k ? [Number(value), p[1]] : p))),\n )}\n ${this.#number(this.#t('field.vertex.y', { n: k + 1 }), y, (value) =>\n setPoints(points.map((p, j) => (j === k ? [p[0], Number(value)] : p))),\n )}\n <button\n type=\"button\"\n ?disabled=${points.length <= 3}\n @click=${() => setPoints(points.filter((_, j) => j !== k))}\n >\n ${this.#t('field.vertex.remove', { n: k + 1 })}\n </button>\n </li>`,\n )}\n </ol>\n ${this.#more(points.length)}\n <button\n type=\"button\"\n ?disabled=${points.length >= MAX_LISTED}\n @click=${() => {\n const [lx, ly] = points[points.length - 1] ?? [50, 50];\n setPoints([...points, [round(lx + 5), round(ly + 5)]]);\n }}\n >\n ${this.#t('field.vertex.add')}\n </button>`\n : nothing\n }\n ${this.#labelField(field, region.index, region.label)}\n <button type=\"button\" @click=${() => this.#change({ kind: 'child-remove', tag: field.tag, index: region.index })}>\n ${this.#t('field.region.remove', { n })}\n </button>\n </fieldset>\n </li>`;\n }\n\n #point(field: PicturePointsFieldModel, point: PicturePointModel): TemplateResult {\n const n = point.index + 1;\n const set = (attributes: Record<string, string | null>) =>\n this.#change({ kind: 'child-attributes', tag: field.tag, index: point.index, attributes });\n return html`<li data-index=${point.index}>\n <fieldset>\n <legend><span class=\"swatch ${slot(point.index)}\" aria-hidden=\"true\">${n}</span>${this.#t('field.point', { n })}</legend>\n <div class=\"numbers\">\n ${this.#number(this.#t('field.x'), point.x, (x) => set({ x }))}\n ${this.#number(this.#t('field.y'), point.y, (y) => set({ y }))}\n </div>\n ${this.#labelField(field, point.index, point.label)}\n <button type=\"button\" @click=${() => this.#change({ kind: 'child-remove', tag: field.tag, index: point.index })}>\n ${this.#t('field.point.remove', { n })}\n </button>\n </fieldset>\n </li>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const field = this.field;\n if (field === null || this.authoring === null) return nothing;\n const regions = field.kind === 'picture-regions';\n const upload = this.authoring.uploadAsset !== null;\n const library = this.authoring.pickPicture !== null;\n const status = this.#status;\n const said = status === null ? '' : (status.text ?? this.#t(status.key));\n return html`<fieldset data-tag=${field.tag}>\n <legend>${field.label}</legend>\n ${field.help === null ? nothing : html`<p class=\"note\">${field.help}</p>`}\n <label>\n ${this.#t('field.picture.src')}\n <input\n type=\"url\"\n autocomplete=\"off\"\n .value=${field.src}\n @change=${(event: Event) => {\n const value = (event.target as HTMLInputElement).value.trim();\n this.#change({ kind: 'attribute', name: field.srcAttribute, value: value === '' ? null : value });\n }}\n />\n </label>\n ${\n upload || library\n ? html`<div class=\"upload\">\n <div class=\"sources\">\n ${\n upload\n ? html`<button\n type=\"button\"\n @click=${() => this.renderRoot.querySelector<HTMLInputElement>('input[type=\"file\"]')?.click()}\n >\n ${this.#t('picture.file')}\n </button>`\n : nothing\n }\n ${\n library\n ? html`<button type=\"button\" data-library @click=${() => void this.#pick(field)}>\n ${this.#t('picture.library')}\n </button>`\n : nothing\n }\n </div>\n ${\n upload\n ? html`<input\n type=\"file\"\n accept=\"image/*\"\n hidden\n @change=${(event: Event) => {\n const input = event.target as HTMLInputElement;\n const file = input.files?.[0];\n input.value = '';\n if (file !== undefined) void this.#upload(field, file);\n }}\n />`\n : nothing\n }\n <div role=\"status\">${status !== null && !status.error ? html`<p class=\"note\">${said}</p>` : nothing}</div>\n <div role=\"alert\">${status?.error ? html`<p class=\"error\">${said}</p>` : nothing}</div>\n </div>`\n : html`<p class=\"note\">${this.#t('picture.urlOnly')}</p>`\n }\n ${this.#canvas(field)}\n <p class=\"note\">${this.#t(regions ? 'field.regions.draw' : 'field.points.place')}</p>\n <ol class=\"items\">\n ${\n regions\n ? field.regions.slice(0, MAX_LISTED).map((r) => this.#region(field, r))\n : field.points.slice(0, MAX_LISTED).map((p) => this.#point(field, p))\n }\n </ol>\n ${this.#more(regions ? field.regions.length : field.points.length)}\n <button type=\"button\" data-add @click=${() => this.#add(field)}>\n ${this.#t(regions ? 'field.region.add' : 'field.point.add')}\n </button>\n </fieldset>`;\n }\n}\n","import { type AttemptPolicy, type Issue, isSafeUrl, PlayerEvent, PRACTICE_POLICY } from '@astl/core';\nimport { type AstlPlayer, definePlayer } from '@astl/player';\nimport {\n type CSSResultGroup,\n css,\n html,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n} from 'lit';\nimport type { Authoring } from '../authoring.js';\nimport { AuthoringElement } from './base.js';\nimport { issueStyles, renderIssues } from './issue-list.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\ntype PreviewState = 'idle' | 'loading' | 'ready' | 'invalid' | 'failed';\n\n/** Authorings whose elements are already registered with the player. */\nconst registered = new WeakSet<Authoring>();\n\n/**\n * `<astl-preview>`: a button that compiles the current source with a throw-away salt and plays it in `<astl-player>`\n * with local grading and the authoring's style templates, the way a student sees it, under `policy`. Invalid sources\n * show their errors instead. Tokens set on the preview reach the player; the player's events stay inside.\n */\nexport class AstlPreview extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n policy: { attribute: false },\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n issueStyles,\n inheritTokens('astl-player'),\n css`\n .bar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: space-between;\n gap: var(--astl-space-2) var(--astl-space-3);\n }\n astl-player {\n border-radius: var(--astl-radius-m);\n overflow: hidden;\n }\n astl-player[hidden] {\n display: none;\n }\n `,\n ];\n\n /**\n * The policy the preview plays and grades under, the one the host's students get (default `PRACTICE_POLICY`). A\n * change plays the preview again, once it has been shown.\n */\n declare policy: AttemptPolicy;\n\n #state: PreviewState = 'idle';\n #issues: readonly Issue[] = [];\n /** The source the issues are about. */\n #source = '';\n #stale = false;\n #generation = 0;\n\n constructor() {\n super();\n this.policy = PRACTICE_POLICY;\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n // A preview attempt is not a student's: its player events (results, answers, state) never reach the host page.\n for (const type of Object.values(PlayerEvent))\n root.addEventListener(type, (event) => event.stopPropagation());\n return root;\n }\n\n /** `idle`, `loading`, `ready`, `invalid` (errors shown) or `failed`. */\n get state(): PreviewState {\n return this.#state;\n }\n\n /** The player, once the first preview started. */\n get player(): AstlPlayer | null {\n return this.renderRoot?.querySelector<AstlPlayer>('astl-player') ?? null;\n }\n\n /** Compiles the current source and plays it. Resolves when the player is ready or the errors are shown. */\n async refresh(): Promise<void> {\n const { authoring, adapter } = this;\n if (authoring === null || adapter === null) return;\n const generation = ++this.#generation;\n this.#stale = false;\n try {\n if (!registered.has(authoring)) {\n definePlayer({\n elements: authoring.elements,\n styleTemplates: authoring.styleTemplates,\n // The page's players share one policy: the default never replaces one a host set for its students.\n ...(authoring.urlPolicy === isSafeUrl ? {} : { urlPolicy: authoring.urlPolicy }),\n });\n registered.add(authoring);\n }\n this.#set('loading');\n const source = adapter.getSource();\n const { policy } = this;\n const result = await authoring.preview(source, { policy });\n if (generation !== this.#generation) return;\n if (!result.ok) {\n this.#issues = result.issues.filter((i) => i.severity === 'error');\n this.#source = source;\n this.#set('invalid');\n await this.updateComplete;\n return;\n }\n await this.updateComplete;\n const player = this.player;\n if (player === null) throw new Error('astl-player is not rendered');\n await player.load({\n view: result.view,\n checker: result.checker,\n policy,\n snapshot: null,\n });\n if (generation === this.#generation) this.#set('ready');\n } catch {\n if (generation === this.#generation) this.#set('failed');\n }\n await this.updateComplete;\n }\n\n #set(state: PreviewState): void {\n this.#state = state;\n this.requestUpdate();\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n if (changed.has('policy') && changed.get('policy') !== undefined && this.#state !== 'idle')\n void this.refresh();\n }\n\n protected override sourceChanged(): void {\n if (this.#state === 'idle' || this.#stale) return;\n this.#stale = true;\n this.requestUpdate();\n }\n\n protected override selectionChanged(): void {\n // The preview does not depend on the cursor.\n }\n\n protected override render(): TemplateResult | typeof nothing {\n const { authoring, adapter } = this;\n if (authoring === null) return nothing;\n const state = this.#state;\n const { lang, dir } = this.ui;\n let message: TemplateResult | typeof nothing = nothing;\n if (state === 'idle') message = html`<p class=\"note\">${this.t('preview.hint')}</p>`;\n else if (state === 'loading') message = html`<p class=\"note\">${this.t('preview.loading')}</p>`;\n else if (state === 'failed') message = html`<p class=\"note\">${this.t('preview.failed')}</p>`;\n else if (state === 'invalid') {\n message = html`<p class=\"note\">${this.t('preview.invalid', { count: this.#issues.length })}</p>\n ${renderIssues(this.#issues, authoring, adapter, this.#source)}`;\n }\n const theme = this.getAttribute('data-theme') ?? 'light';\n return html`<section class=\"kit\" part=\"root\" lang=${lang} dir=${dir} aria-labelledby=\"title\">\n <div class=\"bar\">\n <h2 class=\"title\" id=\"title\" part=\"title\">${this.t('preview.title')}</h2>\n <button type=\"button\" class=\"primary\" part=\"button\" ?disabled=${adapter === null} @click=${() => this.refresh()}>\n ${this.t(state === 'idle' ? 'preview.show' : 'preview.refresh')}\n </button>\n </div>\n <div role=\"status\">${this.#stale ? html`<p class=\"note\">${this.t('preview.stale')}</p>` : nothing}</div>\n ${message}\n ${\n state === 'idle'\n ? nothing\n : html`<astl-player part=\"player\" locale=${authoring.locale} theme=${theme} ?hidden=${state !== 'ready'}></astl-player>`\n }\n </section>`;\n }\n}\n","import type {\n EditorAdapter,\n EditorFormat,\n EditorFormatState,\n EditorStyleChanges,\n EditorStyleRule,\n EditorStyleState,\n EditorStyleTarget,\n EditorStyleTargetKind,\n} from '@astl/core';\nimport { RovingFocus } from '@astl/player/interaction';\nimport {\n type CSSResult,\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 { styleMapOf } from '../style-model.js';\nimport { AuthoringElement } from './base.js';\nimport { type AstlInsertMenu, GLYPHS, type Glyph, type InsertGroup, TYPE_GLYPHS } from './insert-menu.js';\nimport { loadStyleElements, STYLE_OPEN, type StyleOpen } from './style-load.js';\nimport type { StylePopup } from './style-popups.js';\nimport { inheritTokens, kitStyles } from './styles.js';\n\n/** Kit items a host can feature besides component tags (`tag`) and starters (`tag:template`). */\nexport const FEATURED_ITEMS: readonly string[] = ['text', 'picture', 'page-break'];\n\nconst ICONS = {\n bold: svg`<path d=\"M6 4h5a3 3 0 0 1 0 6H6zm0 6h6a3 3 0 0 1 0 6H6z\" stroke-width=\"2\"/>`,\n italic: svg`<path d=\"M9 4h7M4 16h7M12.5 4l-5 12\"/>`,\n underline: svg`<path d=\"M6 3v6a4 4 0 0 0 8 0V3M5 17h10\"/>`,\n link: svg`<path d=\"M8.5 11.5l3-3M7.5 9.5l-2 2a2.8 2.8 0 0 0 4 4l2-2M12.5 10.5l2-2a2.8 2.8 0 0 0-4-4l-2 2\"/>`,\n bulleted: svg`<path d=\"M8 5h9M8 10h9M8 15h9\"/><circle cx=\"4\" cy=\"5\" r=\"1.3\"/><circle cx=\"4\" cy=\"10\" r=\"1.3\"/><circle cx=\"4\" cy=\"15\" r=\"1.3\"/>`,\n numbered: svg`<path d=\"M9 5h8M9 10h8M9 15h8M3 3.5h1.5V8M2.5 12.2c.4-.8 2.5-.9 2.5.4 0 1-2.5 2-2.5 3.4H5\" stroke-width=\"1.5\"/>`,\n undo: svg`<path d=\"M7.5 5L4 8.5 7.5 12M4 8.5h8a4 4 0 0 1 0 8H9\"/>`,\n redo: svg`<path d=\"M12.5 5L16 8.5 12.5 12M16 8.5H8a4 4 0 0 0 0 8h3\"/>`,\n text: svg`<path d=\"M4 5V4h12v1M10 4v12M7.5 16h5\"/>`,\n add: svg`<path d=\"M10 4v12M4 10h12\"/>`,\n layouts: GLYPHS.columns,\n templates: svg`<rect x=\"3\" y=\"3\" width=\"14\" height=\"14\" rx=\"1.5\"/><path d=\"M3 8h14M8 8v9\"/>`,\n wrap: svg`<path d=\"M3 6h14M3 10h6M11 10h6M3 14h14\" stroke-width=\"1.6\"/><rect x=\"8\" y=\"8\" width=\"4\" height=\"4\" rx=\"1\" stroke-width=\"1.4\"/>`,\n chevron: svg`<path d=\"M6 8l4 4 4-4\"/>`,\n color: svg`<path d=\"M5.5 13L10 3l4.5 10M7 10h6\" stroke-width=\"1.8\"/>`,\n highlight: svg`<path d=\"M12.5 3.5l4 4-7.5 7.5H5v-4zM3.5 16.5h6\" stroke-width=\"1.6\"/>`,\n 'align-start': svg`<path d=\"M3.5 5h13M3.5 9h8M3.5 13h13M3.5 17h8\"/>`,\n 'align-center': svg`<path d=\"M3.5 5h13M6 9h8M3.5 13h13M6 17h8\"/>`,\n 'align-end': svg`<path d=\"M3.5 5h13M8.5 9h8M3.5 13h13M8.5 17h8\"/>`,\n 'align-justify': svg`<path d=\"M3.5 5h13M3.5 9h13M3.5 13h13M3.5 17h13\"/>`,\n spacing: svg`<path d=\"M9 5h8M9 10h8M9 15h8M4.5 4v12M2.5 6l2-2 2 2M2.5 14l2 2 2-2\"/>`,\n clear: svg`<path d=\"M5 5V4h10v1M10 4l-1.5 7M4 16h7M13 11.5l4 4M17 11.5l-4 4\"/>`,\n} satisfies Readonly<Record<string, SVGTemplateResult>>;\n\n/** The formats with a button of their own (the text styles are in a menu). */\ntype Toggle = 'bold' | 'italic' | 'underline' | 'link' | 'bulleted' | 'numbered';\n\nconst STYLES: readonly EditorFormat[] = ['paragraph', 'heading', 'subheading'];\nconst ELEMENT_GROUPS: readonly InsertGroup[] = ['components', 'content'];\nconst TEMPLATE_GROUPS: readonly InsertGroup[] = ['exercises'];\nconst LAYOUT_GROUPS: readonly InsertGroup[] = ['layouts'];\nconst MENU_GROUPS: Readonly<Record<InsertMenu, readonly InsertGroup[]>> = {\n elements: ELEMENT_GROUPS,\n templates: TEMPLATE_GROUPS,\n layouts: LAYOUT_GROUPS,\n};\nconst INSERT_MENUS: ReadonlySet<string> = new Set(Object.keys(MENU_GROUPS));\nconst MARKS: readonly Toggle[] = ['bold', 'italic', 'underline'];\nconst LISTS: readonly Toggle[] = ['bulleted', 'numbered'];\n\nconst STYLE_POPUPS: ReadonlySet<string> = new Set(['font', 'size', 'color', 'highlight', 'align', 'spacing']);\n\n/** `panel`: the style form or the rules, the default of a request nobody else took (`astl-style-open`). */\ntype Popup = 'style' | 'link' | 'panel' | InsertMenu | StylePopup;\n\n/** The toolbar's insert menus: every component and content insert, the named starters, or the layouts. */\nexport type InsertMenu = 'elements' | 'templates' | 'layouts';\n\nconst isMenu = (popup: Popup): popup is InsertMenu => INSERT_MENUS.has(popup);\n/** The popover a popup opens: the insert menus share one. */\nconst popoverOf = (popup: Popup) => (isMenu(popup) ? 'insert' : popup);\n/** The button a popup hangs from: the panel, reached from the style menu, hangs from that. */\nconst openerOf = (popup: Popup) => (popup === 'panel' ? 'style' : popup);\n\n/** A view the toolbar's view switch offers (`AstlToolbar.views`). */\nexport interface ToolbarView {\n readonly name: string;\n readonly label: string;\n /** What the view shows, said by its option's tooltip and to screen readers (its description). */\n readonly description?: string;\n}\n\n/** The event the view switch fires when an author picks a view; `detail.view` is its name. */\nexport const VIEW_PICKED = 'astl-toolbar-view';\n\n/** One button of the bar, in tab order. */\ninterface Item {\n readonly id: string;\n readonly label: string;\n /** Shown beside the icon; null: the icon alone (its name is `label`). */\n readonly text: string | null;\n readonly icon: TemplateResult | SVGTemplateResult | null;\n /** The icon's name, for `::part(icon-<name>)`. */\n readonly iconName: string;\n readonly pressed?: boolean;\n /** A view of the view switch: whether it is the current one. */\n readonly checked?: boolean;\n /** Said by the tooltip and as the button's description: what a view shows. */\n readonly description?: string;\n readonly disabled?: boolean;\n readonly popup?: Popup;\n /** A button that says its value (the text style, the font, the size): a chevron after its text. */\n readonly menu?: boolean;\n /** A bar under the icon in this colour (the colour now). */\n readonly bar?: string | null;\n readonly data?: Readonly<Record<string, string>>;\n press(): void;\n}\n\nconst NO_STATE: EditorFormatState = { active: [], enabled: [], href: null, undo: false, redo: false };\n\n/**\n * The bar: groups with a thin rule between them (each group's `separator`, a part a host can redraw), undo and redo at\n * its end. A group that wraps to the start of a row has its rule on the bar's own border, where it does not show. Wider\n * than a phone, the groups wrap into rows when they do not fit, so every button is on show. The groups sit in two\n * wrappers, the formats (`formats`: the text style to the lists) and the actions (`actions`: the inserts, the types'\n * commands, the view switch, undo and redo), which only a phone lays out: there the formats are one row that scrolls\n * sideways, as a mobile editor's (wrapped, they would push the text below the fold), and the actions wrap under it, so\n * none of them is ever out of sight. A shade at an edge of the formats says more buttons lie that way (the covers\n * scroll with the buttons and hide it at either end), and the arrow keys scroll the focused button into view. The\n * actions wrap button by button, without rules (a group that wrapped as a whole would take a row of its own): only the\n * view switch and undo with redo stay together.\n */\nconst barStyles: CSSResult = css`\n :host {\n display: block;\n container-type: inline-size;\n }\n .bar {\n box-sizing: border-box;\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1) calc(2 * var(--astl-space-2) + var(--astl-outline-width));\n padding: var(--astl-space-2);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n }\n .formats,\n .actions {\n display: contents;\n }\n .group {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: var(--astl-space-1);\n }\n .group + .group,\n .formats + .actions > .group:first-child {\n position: relative;\n margin-inline-start: calc(-1 * var(--astl-space-2) - var(--astl-outline-width));\n padding-inline-start: calc(var(--astl-space-2) + var(--astl-outline-width));\n }\n .separator {\n position: absolute;\n inset-block: 0;\n inset-inline-start: 0;\n border-inline-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .group.history {\n margin-inline-start: auto;\n }\n @container (inline-size < 30rem) {\n .bar {\n flex-flow: column nowrap;\n align-items: stretch;\n }\n .formats,\n .actions {\n display: flex;\n align-items: center;\n }\n .actions {\n flex-wrap: wrap;\n gap: var(--astl-space-1);\n }\n .actions > .group:not(.views, .history) {\n display: contents;\n }\n .actions .separator {\n display: none;\n }\n .actions > .group {\n margin-inline-start: 0;\n }\n .actions > .history {\n margin-inline-start: auto;\n padding-inline-start: 0;\n }\n .formats {\n --ring: calc(var(--astl-focus-width) + var(--astl-focus-offset));\n gap: var(--astl-space-1) calc(2 * var(--astl-space-2) + var(--astl-outline-width));\n overflow-x: auto;\n scrollbar-width: thin;\n padding: var(--ring);\n margin-block: calc(-1 * var(--ring)) 0;\n margin-inline: calc(-1 * var(--ring));\n background:\n linear-gradient(90deg, var(--astl-surface) 50%, #0000) left / 1.5rem no-repeat local,\n linear-gradient(-90deg, var(--astl-surface) 50%, #0000) right / 1.5rem no-repeat local,\n radial-gradient(farthest-side at 0, var(--astl-outline), #0000) left / 0.5rem no-repeat,\n radial-gradient(farthest-side at 100%, var(--astl-outline), #0000) right / 0.5rem no-repeat,\n var(--astl-surface);\n }\n .formats > .group {\n flex: none;\n flex-wrap: nowrap;\n }\n }\n`;\n\n/** The buttons: hovered, pressed. */\nconst buttonStyles: CSSResult = css`\n .bar button {\n justify-content: center;\n padding-inline: var(--astl-space-2);\n border-color: transparent;\n background: transparent;\n white-space: nowrap;\n }\n .bar button.labelled {\n padding-inline: var(--astl-space-2) var(--astl-space-3);\n }\n .bar button:hover {\n border-color: var(--astl-line);\n background: var(--astl-accent-soft);\n }\n .bar button[aria-pressed='true'] {\n border-color: var(--astl-accent);\n background: var(--astl-accent-soft);\n color: var(--astl-ink);\n }\n .group.views {\n gap: 0;\n padding: calc(2 * var(--astl-outline-width));\n border: var(--astl-outline-width) solid var(--astl-outline);\n border-radius: var(--astl-radius-m);\n }\n .bar .views [aria-checked='true'] {\n background: var(--astl-accent);\n color: var(--astl-on-accent);\n font-weight: 600;\n }\n`;\n\n/**\n * Unavailable here: dimmed and dashed (not by colour alone), still reachable by the arrow keys. Then the icons (shapes\n * stroked here) and the popups: the text style menu, the link and the insert menus. Popups are compact: little\n * padding, items without a frame (the hover's fill shows them; a disabled entry keeps its dashed one), the target kept\n * (`--astl-target-min`). An insert menu has no visible title: the button that opened it names it, and the title is\n * still the section's name.\n */\nconst popupStyles: CSSResult = css`\n .bar button[aria-disabled='true'] {\n border-color: var(--astl-line);\n border-style: dashed;\n background: transparent;\n color: var(--astl-ink-muted);\n cursor: not-allowed;\n }\n .bar button[aria-expanded='true'] {\n border-color: var(--astl-outline);\n }\n .icon {\n fill: none;\n stroke: currentColor;\n stroke-width: 1.8;\n stroke-linecap: round;\n stroke-linejoin: round;\n }\n .icon circle {\n fill: currentColor;\n stroke: none;\n }\n .chevron {\n inline-size: 1rem;\n block-size: 1rem;\n }\n [popover] {\n box-sizing: border-box;\n position: fixed;\n inset: auto;\n margin: 0;\n padding: var(--astl-space-2);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-m);\n background: var(--astl-surface);\n color: var(--astl-ink);\n box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.2);\n overflow: auto;\n }\n [popover]:not(:popover-open) {\n display: none;\n }\n .menu {\n display: flex;\n flex-direction: column;\n gap: 2px;\n min-inline-size: 12rem;\n max-block-size: calc(100dvh - 2 * var(--astl-space-4));\n }\n .menu button {\n justify-content: flex-start;\n padding: var(--astl-space-1) var(--astl-space-2);\n border-color: transparent;\n }\n .menu button[aria-checked='true'] {\n border-color: var(--astl-accent);\n background: var(--astl-accent-soft);\n font-weight: 600;\n }\n .insert {\n inline-size: min(26rem, calc(100vw - 2 * var(--astl-space-4)));\n max-block-size: min(32rem, calc(100vh - 2 * var(--astl-space-4)));\n padding: 0;\n }\n .insert .search {\n position: sticky;\n inset-block-start: 0;\n z-index: 1;\n padding: var(--astl-space-2);\n border-block-end: var(--astl-outline-width) solid var(--astl-line);\n background: var(--astl-surface);\n }\n .insert astl-insert-menu::part(root) {\n padding: var(--astl-space-2);\n border: 0;\n border-radius: 0;\n }\n .insert astl-insert-menu::part(title) {\n display: none;\n }\n .insert astl-insert-menu::part(button) {\n padding-inline: var(--astl-space-2);\n }\n .insert astl-insert-menu::part(button):enabled {\n border-color: transparent;\n }\n .link {\n display: flex;\n flex-direction: column;\n inline-size: min(22rem, calc(100vw - 2 * var(--astl-space-4)));\n }\n .menu .menu-section {\n display: contents;\n }\n .menu .menu-group {\n margin-block: var(--astl-space-2) 0;\n padding-inline: var(--astl-space-2);\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n font-weight: 600;\n }\n .menu hr {\n inline-size: 100%;\n margin-block: var(--astl-space-1);\n border: 0;\n border-block-start: var(--astl-outline-width) solid var(--astl-line);\n }\n .bar button .value {\n max-inline-size: 8rem;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n .color-mark {\n position: absolute;\n inset-inline: 25%;\n inset-block-end: var(--astl-space-1);\n block-size: 0.2rem;\n border: var(--astl-outline-width) solid var(--astl-outline);\n forced-color-adjust: none;\n }\n .bar button[data-popup='color'],\n .bar button[data-popup='highlight'] {\n position: relative;\n }\n .link > * + * {\n margin-block-start: var(--astl-space-2);\n }\n .link > [role='alert']:empty {\n margin-block-start: 0;\n }\n .link label {\n font-weight: 600;\n }\n .link .buttons {\n display: flex;\n flex-wrap: wrap;\n gap: var(--astl-space-2);\n }\n .link .error {\n margin: 0;\n padding: var(--astl-space-2);\n border-inline-start: var(--astl-space-1) solid var(--astl-danger);\n background: var(--astl-danger-soft);\n }\n @media (forced-colors: active) {\n .bar button:is([aria-pressed='true'], [aria-checked='true']) {\n border-color: Highlight;\n }\n .bar button[aria-disabled='true'] {\n color: GrayText;\n }\n }\n`;\n\n/**\n * `<astl-toolbar>`: a word processor's toolbar for the editor in `adapter`, one row while it fits. In order: the text\n * style (a menu: paragraph, heading, subheading), bold, italic, underline, link, the two lists; the host's `featured`\n * inserts as buttons, \"Elements\" (every component and content insert) and \"Templates\" (the named starters), menus with\n * a search over one `<astl-insert-menu>`; the types' commands on the selection (`EditorDescriptor.wrap`, \"Mark\n * word\"); the view switch (`views`, two or more: a segmented control of radios); undo and redo at the end. Controls\n * the adapter has no capability for are left out (`format`, `undo`, `wrap`). One tab stop: the arrow keys, Home and\n * End move along it. Format buttons show the state at the cursor: pressed, or unavailable (`aria-disabled`, still\n * focusable). A press never moves the editor's cursor: a pointer's leaves the focus in the editor, and a key's gives\n * it back.\n */\nexport class AstlToolbar extends AuthoringElement {\n static override properties: PropertyDeclarations = {\n ...AuthoringElement.properties,\n featured: { attribute: false },\n views: { attribute: false },\n view: {},\n };\n\n static override styles: CSSResultGroup = [\n kitStyles,\n inheritTokens('astl-insert-menu, astl-picture-dialog, astl-style-form, astl-style-rules'),\n barStyles,\n buttonStyles,\n popupStyles,\n ];\n\n /**\n * The inserts shown as buttons, in order: component tags (their default template), `tag:template` for a named\n * starter, and the kit items `text` (an empty paragraph after the cursor's block), `picture` and `page-break`.\n * Unknown names are skipped. Default: none (everything is under \"Elements\" and \"Templates\").\n */\n declare featured: readonly string[];\n /**\n * The views of the view switch, in order; the first is the one the adapter edits, and in any other only the switch\n * works. A pick fires `astl-toolbar-view` (bubbles, composed) with the view's name in `detail.view`; the host then\n * sets `view`. Fewer than two (default: none): no switch.\n */\n declare views: readonly ToolbarView[];\n /** The name of the current view. */\n declare view: string;\n\n #state: EditorFormatState = NO_STATE;\n #styles: EditorStyleState | null = null;\n #popup: Popup | null = null;\n /** The popups of the style controls, once one was asked for. */\n #stylePopupsModule: typeof import('./style-popups.js') | null = null;\n /** What the panel shows. */\n #panel: StyleOpen['target'] = 'block';\n /** A typed colour was refused, in the open colours popup. */\n #colorError = false;\n /** The insert menu shown last: its groups stay while closed. */\n #menu: InsertMenu = 'elements';\n #query = '';\n #linkError = false;\n #off: { readonly adapter: EditorAdapter; readonly off: () => void } | null = null;\n #items: readonly Item[] = [];\n readonly #roving = new RovingFocus(this, {\n count: () => this.#items.length,\n item: (index) => this.renderRoot.querySelector<HTMLElement>(`.bar [data-item=\"${index}\"]`),\n axis: 'inline',\n });\n\n constructor() {\n super();\n this.featured = [];\n this.views = [];\n this.view = '';\n }\n\n /** The insert menu of \"Elements\" and \"Templates\": insert from it as a host would from `<astl-insert-menu>`. */\n get menu(): AstlInsertMenu | null {\n return this.renderRoot.querySelector<AstlInsertMenu>('astl-insert-menu');\n }\n\n /** Opens \"Elements\", \"Templates\" or \"Layout\" with its search, as its button does. */\n async openMenu(menu: InsertMenu): Promise<void> {\n await this.#open(menu);\n }\n\n /**\n * Asks for the style form of a target at the cursor, or the rules, as the style menu does: fires `astl-style-open`,\n * and unless a host cancels it, shows them in a popup (they load now).\n */\n async openStyle(target: StyleOpen['target']): Promise<void> {\n const detail: StyleOpen = { target };\n this.#close(false);\n const event = new CustomEvent(STYLE_OPEN, { detail, bubbles: true, composed: true, cancelable: true });\n if (!this.dispatchEvent(event)) return;\n await loadStyleElements();\n this.#panel = target;\n await this.#open('panel');\n }\n\n /** Loads the popups of the style controls and their styles, once; false if that failed (it says so in the console). */\n async #loadStylePopups(): Promise<boolean> {\n if (this.#stylePopupsModule !== null) return true;\n try {\n const module = await import('./style-popups.js');\n const root = this.renderRoot as ShadowRoot;\n const sheet = module.stylePopupStyles.styleSheet;\n if (this.#stylePopupsModule === null && sheet !== undefined)\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];\n this.#stylePopupsModule = module;\n return true;\n } catch (error) {\n console.error(error);\n return false;\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.#follow();\n document.addEventListener('pointerdown', this.#outside, true);\n document.addEventListener('keydown', this.#escape);\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n this.#follow();\n document.removeEventListener('pointerdown', this.#outside, true);\n document.removeEventListener('keydown', this.#escape);\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n super.willUpdate(changed);\n if (changed.has('adapter')) this.#follow();\n this.#state = this.adapter?.formatState?.() ?? NO_STATE;\n this.#styles = this.adapter?.style?.state() ?? null;\n }\n\n /** Follows the cursor of the adapter: every move may change the state at it. */\n #follow(): void {\n const adapter = this.isConnected ? this.adapter : null;\n if ((this.#off?.adapter ?? null) === adapter) return;\n this.#off?.off();\n this.#off = null;\n const listen = adapter?.onCursorChange;\n if (adapter === null || listen === undefined) return;\n this.#off = { adapter, off: listen.call(adapter, () => this.requestUpdate()) };\n }\n\n /** A press outside the open popup and its button closes it. */\n #outside = (event: Event): void => {\n if (this.#popup === null) return;\n const path = event.composedPath();\n const popup = this.renderRoot.querySelector(`#${popoverOf(this.#popup)}`);\n const opener = this.renderRoot.querySelector(`[data-popup=\"${openerOf(this.#popup)}\"]`);\n if ((popup !== null && path.includes(popup)) || (opener !== null && path.includes(opener))) return;\n // The picture dialog of an insert menu sits outside the popover in the top layer, above it.\n if (path.some((node) => node instanceof Element && node.localName === 'astl-picture-dialog')) return;\n this.#close(false);\n };\n\n /**\n * The style panel is not modal: the focus can leave it, by Tab or to the surface after an undo, and it stays open\n * over what it covers. Escape closes it from there too; only from inside does the focus go back to its button.\n */\n #escape = (event: KeyboardEvent): void => {\n if (this.#popup !== 'panel' || event.key !== 'Escape') return;\n const panel = this.renderRoot.querySelector('#panel');\n const inside = panel !== null && event.composedPath().includes(panel);\n // Inside, a field may have its own use for the key (a rename). ProseMirror claims every Escape, with no use for it.\n if (inside && event.defaultPrevented) return;\n event.preventDefault();\n this.#close(inside);\n };\n\n async #open(popup: Popup): Promise<void> {\n if ((popup === 'panel' || STYLE_POPUPS.has(popup)) && !(await this.#loadStylePopups())) return;\n if (this.#popup !== null && this.#popup !== popup) this.#close(false);\n this.#popup = popup;\n this.#linkError = false;\n this.#colorError = false;\n if (isMenu(popup)) {\n this.#query = '';\n this.#menu = popup;\n }\n this.requestUpdate();\n await this.updateComplete;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(popup)}`);\n const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(popup)}\"]`);\n if (element === null || opener === null) return;\n if (!element.matches(':popover-open')) element.showPopover();\n // Its descriptions load now (`menuMessages`), not with the editor.\n this.menu?.requestUpdate();\n this.#place(element, opener);\n const first =\n popup === 'style' || STYLE_POPUPS.has(popup)\n ? (element.querySelector<HTMLElement>('[aria-checked=\"true\"], [aria-pressed=\"true\"]') ??\n element.querySelector('button'))\n : popup === 'panel'\n ? element\n : element.querySelector<HTMLElement>('input');\n first?.focus();\n }\n\n /** Closes the open popup; the focus goes back to its button with `back`. */\n #close(back: boolean): void {\n const popup = this.#popup;\n if (popup === null) return;\n this.#popup = null;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(popup)}`);\n if (element?.matches(':popover-open') === true) element.hidePopover();\n if (back) this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(popup)}\"]`)?.focus();\n this.requestUpdate();\n }\n\n /** Puts a popup below its button, its start edge on the button's, inside the viewport. */\n #place(popup: HTMLElement, opener: HTMLElement): void {\n const rect = opener.getBoundingClientRect();\n const rtl = getComputedStyle(opener).direction === 'rtl';\n const width = popup.offsetWidth;\n const room = document.documentElement.clientWidth;\n const start = rtl ? room - rect.right : rect.left;\n const inset = Math.max(8, Math.min(start, room - width - 8));\n popup.style.setProperty('inset-inline-start', `${inset}px`);\n // Below the button, or as low as it fits: a tall popup (the style form) from a bar far down the page.\n const below = document.documentElement.clientHeight - popup.offsetHeight - 8;\n popup.style.setProperty('inset-block-start', `${Math.max(8, Math.min(rect.bottom + 4, below))}px`);\n }\n\n /** After a command: the editor gets the focus back when a key pressed the button (a pointer never took it). */\n #done(): void {\n this.adapter?.focus?.();\n }\n\n #format(format: EditorFormat, href?: string): void {\n if (!this.#state.enabled.includes(format)) return;\n this.adapter?.format?.(format, href);\n this.#done();\n this.requestUpdate();\n }\n\n /** A style on the selected text (with only a cursor, on what is typed next), the popup closed. */\n #setText(changes: EditorStyleChanges): void {\n this.adapter?.style?.setText(changes);\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /** A style on each text block of the selection, the popup closed. */\n #setBlock(changes: EditorStyleChanges): void {\n this.adapter?.style?.setTarget('block', changes);\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /**\n * Where a named style goes: on the selected text, and with only a cursor on what the cursor is in. A style of boxes\n * (`box`) goes on what the cursor is in, words selected or not, as a paragraph style does in a word processor.\n */\n #namedTarget(box = false): 'text' | EditorStyleTargetKind | null {\n const styles = this.#styles;\n if (styles === null) return null;\n return styles.hasSelection && !box ? 'text' : (styles.targets[0]?.kind ?? null);\n }\n\n /** The named style on that target. */\n #namedNow(box = false): string | null {\n const where = this.#namedTarget(box);\n return where === 'text'\n ? (this.#styles?.textClass ?? null)\n : (this.#styles?.targets.find((target) => target.kind === where)?.className ?? null);\n }\n\n /** Whether a named style is a ready style of boxes: its rule in the document keeps that way of going on. */\n #isBox(name: string): boolean {\n return this.authoring?.styles.some((ready) => ready.name === name && ready.text !== true) ?? false;\n }\n\n /** Sets a named style, or takes it away when it is there; a ready style (`rule`) brings its rule in the same step. */\n #setNamed(name: string, rule?: EditorStyleRule): void {\n const box = this.#isBox(name);\n const where = this.#namedTarget(box);\n if (where !== null) {\n if (rule === undefined)\n this.adapter?.style?.setClass(where, this.#namedNow(box) === name ? null : name);\n else this.adapter?.style?.setClass(where, name, rule);\n }\n this.#close(false);\n this.#done();\n this.requestUpdate();\n }\n\n /** The style at the cursor as a font's name: the host's, else the stack's first name; '' with none or a mix. */\n #fontName(): string {\n const stack = this.#styles?.text['font-family'];\n if (stack === undefined) return '';\n const known = this.authoring?.fonts.find((font) => font.stack === stack);\n return known?.name ?? (stack.split(',')[0] ?? '').replace(/\"/g, '').trim();\n }\n\n /** The bar's style controls, by group (font and size; colours; alignment and spacing), and clear formatting. */\n #styleGroups(): { fonts: Item[]; colors: Item[]; blocks: Item[]; clear: Item[] } {\n const styles = this.#styles;\n if (styles === null) return { fonts: [], colors: [], blocks: [], clear: [] };\n const { text, textEnabled, targets } = styles;\n const hasBlock = targets.some((target) => target.kind === 'block');\n const popupItem = (\n popup: StylePopup,\n label: string,\n enabled: boolean,\n icon: SVGTemplateResult,\n iconName: string,\n ): Item => ({\n id: popup,\n label,\n text: null,\n icon,\n iconName,\n disabled: !enabled,\n popup,\n press: () => {\n if (this.#popup === popup) this.#close(true);\n else void this.#open(popup);\n },\n });\n const font = this.#fontName();\n const size = /^(\\d+(?:\\.\\d+)?)px$/.exec(text['font-size'] ?? '')?.[1] ?? text['font-size'] ?? '';\n const valued = (popup: StylePopup, label: string, value: string): Item => ({\n ...popupItem(\n popup,\n this.t(label, { value: value === '' ? this.t('toolbar.default') : value }),\n textEnabled,\n ICONS.chevron,\n 'chevron',\n ),\n text: value === '' ? this.t(`toolbar.${popup}.name`) : value,\n menu: true,\n });\n const blockStyle = targets.find((target) => target.kind === 'block')?.style ?? '';\n const align = styleMapOf(blockStyle).get('text-align');\n const alignIcon =\n align === 'right' || align === 'end'\n ? 'align-end'\n : align === 'center'\n ? 'align-center'\n : align === 'justify'\n ? 'align-justify'\n : 'align-start';\n return {\n fonts: [valued('font', 'toolbar.font', font), valued('size', 'toolbar.size', size)],\n colors: [\n {\n ...popupItem('color', this.t('toolbar.color'), textEnabled, ICONS.color, 'color'),\n bar: text.color ?? null,\n },\n {\n ...popupItem('highlight', this.t('toolbar.highlight'), textEnabled, ICONS.highlight, 'highlight'),\n bar: text['background-color'] ?? null,\n },\n ],\n blocks: [\n popupItem('align', this.t('toolbar.align'), hasBlock, ICONS[alignIcon], alignIcon),\n popupItem('spacing', this.t('toolbar.spacing'), hasBlock, ICONS.spacing, 'spacing'),\n ],\n clear: [\n {\n id: 'clear',\n label: this.t('toolbar.clear'),\n text: null,\n icon: ICONS.clear,\n iconName: 'clear',\n disabled: !textEnabled && !hasBlock,\n press: () => {\n this.adapter?.style?.clear();\n this.#done();\n this.requestUpdate();\n },\n },\n ],\n };\n }\n\n async #insert(name: string): Promise<void> {\n const menu = this.menu;\n const adapter = this.adapter;\n if (menu === null || adapter === null) return;\n if (name === 'text') {\n adapter.insert('<p></p>');\n this.#done();\n return;\n }\n if (name === 'picture') await menu.insertPicture();\n else if (name === 'page-break') menu.insertPageBreak();\n else {\n const [tag = '', template] = name.split(':');\n await menu.add(tag, template);\n }\n this.#done();\n }\n\n /** The featured names this editor can insert, as buttons. */\n #featuredItems(): Item[] {\n const authoring = this.authoring;\n if (authoring === null) return [];\n const disabled = this.adapter === null;\n const items: Item[] = [];\n for (const name of this.featured) {\n if (name === 'text' || name === 'picture') {\n const label = this.t(name === 'text' ? 'insert.text' : 'insert.picture');\n items.push({\n id: `insert-${name}`,\n label,\n text: label,\n icon: name === 'text' ? ICONS.text : GLYPHS.picture,\n iconName: name === 'text' ? 'text' : 'image',\n disabled,\n data: { content: name },\n press: () => void this.#insert(name),\n });\n continue;\n }\n if (name === 'page-break') {\n if (this.adapter?.splitPage === undefined) continue;\n const label = this.t('insert.pageBreak');\n items.push({\n id: 'insert-page-break',\n label,\n text: label,\n icon: GLYPHS.page,\n iconName: 'files',\n data: { content: name },\n press: () => void this.#insert(name),\n });\n continue;\n }\n const [tag = '', template] = name.split(':');\n const descriptor = authoring.descriptor(tag);\n if (descriptor === null) continue;\n const starter = template === undefined ? null : authoring.templates(tag).find((t) => t.id === template);\n if (starter === undefined) continue;\n const label = authoring.t(descriptor.manifest.messages, starter?.label ?? descriptor.label);\n const icon = starter?.icon ?? descriptor.icon;\n items.push({\n id: `insert-${name}`,\n label,\n text: label,\n icon: TYPE_GLYPHS.get(icon) ?? GLYPHS[descriptor.manifest.display as Glyph],\n iconName: icon,\n disabled,\n data: template === undefined ? { tag } : { tag, template },\n press: () => void this.#insert(name),\n });\n }\n return items;\n }\n\n /** The bar's buttons in order, by group (named for its class). */\n #groups(): [string, Item[]][] {\n const adapter = this.adapter;\n const authoring = this.authoring;\n const state = this.#state;\n const groups: [string, Item[]][] = [];\n const formatItem = (format: Toggle, popup?: Popup): Item => ({\n id: format,\n label: this.t(`toolbar.${format}`),\n text: null,\n icon: ICONS[format],\n iconName: format,\n pressed: state.active.includes(format),\n disabled: !state.enabled.includes(format),\n ...(popup === undefined ? {} : { popup }),\n press: () => {\n if (popup !== undefined) void this.#open(popup);\n else this.#format(format);\n },\n });\n if (adapter?.format !== undefined && adapter.formatState !== undefined) {\n const current = STYLES.find((style) => state.active.includes(style));\n // The named style on what the menu would change says more than the tag.\n const named = this.#namedNow();\n const rule = named === null ? undefined : adapter.style?.rules().find((one) => one.name === named);\n const styleName = rule?.label ?? rule?.name ?? this.t(`toolbar.${current ?? 'paragraph'}`);\n const style = this.#styleGroups();\n groups.push([\n 'group',\n [\n {\n id: 'style',\n label: this.t('toolbar.style', { style: styleName }),\n text: styleName,\n icon: ICONS.chevron,\n iconName: 'chevron',\n menu: true,\n // A selected picture or component has no text style, but its style form is in this menu.\n disabled:\n !STYLES.some((one) => state.enabled.includes(one)) && (this.#styles?.targets.length ?? 0) === 0,\n popup: 'style',\n press: () => void this.#open('style'),\n },\n ],\n ]);\n if (style.fonts.length > 0) groups.push(['group', style.fonts]);\n groups.push(['group', [...MARKS.map((mark) => formatItem(mark)), formatItem('link', 'link')]]);\n if (style.colors.length > 0) groups.push(['group', style.colors]);\n if (style.blocks.length > 0) groups.push(['group', style.blocks]);\n groups.push(['group', [...LISTS.map((list) => formatItem(list)), ...style.clear]]);\n }\n const menu = (popup: InsertMenu, icon: 'add' | 'templates' | 'layouts'): Item => ({\n id: popup,\n label: this.t(`toolbar.${popup}`),\n text: this.t(`toolbar.${popup}`),\n icon: ICONS[icon],\n iconName: icon,\n disabled: adapter === null,\n popup,\n press: () => {\n if (this.#popup === popup) this.#close(true);\n else void this.#open(popup);\n },\n });\n const starters = authoring?.descriptors.some((d) => (d.templates ?? []).length > 0) === true;\n groups.push([\n 'group inserts',\n [\n ...this.#featuredItems(),\n menu('elements', 'add'),\n ...(starters ? [menu('templates', 'templates')] : []),\n // Layouts are styles: a host without the style API has none to insert.\n ...(adapter?.style !== undefined ? [menu('layouts', 'layouts')] : []),\n ],\n ]);\n if (adapter?.wrap !== undefined && authoring !== null) {\n const wraps = authoring.descriptors.filter((d) => d.wrap !== undefined);\n if (wraps.length > 0) {\n groups.push([\n 'group',\n wraps.map((d) => {\n const label = authoring.t(d.manifest.messages, d.wrap?.label ?? '');\n return {\n id: `wrap-${d.manifest.tag}`,\n label,\n text: label,\n icon: ICONS.wrap,\n iconName: 'wrap',\n data: { wrap: d.manifest.tag },\n press: () => {\n this.adapter?.wrap?.(d.manifest.tag);\n this.#done();\n },\n };\n }),\n ]);\n }\n }\n // A switch needs two views at least.\n if (this.views.length > 1) {\n groups.push([\n 'group views',\n this.views.map((view) => ({\n id: `view-${view.name}`,\n label: view.label,\n text: view.label,\n icon: null,\n iconName: '',\n checked: view.name === this.view,\n ...(view.description === undefined ? {} : { description: view.description }),\n press: () => {\n if (view.name === this.view) return;\n const detail = { view: view.name };\n this.dispatchEvent(new CustomEvent(VIEW_PICKED, { detail, bubbles: true, composed: true }));\n },\n })),\n ]);\n }\n if (adapter?.undo !== undefined && adapter.redo !== undefined) {\n const history = (name: 'undo' | 'redo'): Item => ({\n id: name,\n label: this.t(`toolbar.${name}`),\n text: null,\n icon: ICONS[name],\n iconName: name,\n disabled: !state[name],\n press: () => {\n if (!state[name]) return;\n adapter[name]?.();\n this.#done();\n },\n });\n groups.push(['group history', [history('undo'), history('redo')]]);\n }\n return groups;\n }\n\n #keydown(event: KeyboardEvent): void {\n const target = (event.target as HTMLElement).closest<HTMLElement>('[data-item]');\n if (target === null) return;\n const index = Number(target.dataset.item);\n const item = this.#items[index];\n const menu = item?.popup === 'style' || STYLE_POPUPS.has(item?.popup ?? '');\n if (menu && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {\n event.preventDefault();\n if (item?.disabled !== true && item?.popup !== undefined) void this.#open(item.popup);\n return;\n }\n this.#roving.keydown(event, index);\n }\n\n #button(item: Item, index: number): TemplateResult {\n const unavailable = item.disabled === true;\n // The parts: every button; an icon-only one is also an `icon-button`, and an option of the view switch a `view`.\n const part =\n item.checked !== undefined ? 'button view' : item.text === null ? 'button icon-button' : 'button';\n return html`<button\n type=\"button\"\n part=${part}\n class=${item.text === null ? 'icon-only' : 'labelled'}\n data-item=${index}\n data-id=${item.id}\n data-tag=${item.data?.tag ?? nothing}\n data-template=${item.data?.template ?? nothing}\n data-content=${item.data?.content ?? nothing}\n data-popup=${item.popup ?? nothing}\n tabindex=${this.#roving.tabIndex(index)}\n aria-label=${item.text === null || item.menu === true ? item.label : nothing}\n title=${item.description ?? (item.text === null ? item.label : nothing)}\n aria-pressed=${item.pressed === undefined ? nothing : String(item.pressed)}\n role=${item.checked === undefined ? nothing : 'radio'}\n aria-checked=${item.checked === undefined ? nothing : String(item.checked)}\n aria-disabled=${unavailable ? 'true' : nothing}\n aria-haspopup=${\n item.popup === undefined\n ? nothing\n : item.popup === 'style' || item.menu === true || item.popup === 'align' || item.popup === 'spacing'\n ? 'menu'\n : 'dialog'\n }\n aria-expanded=${item.popup === undefined ? nothing : String(this.#popup === item.popup)}\n aria-controls=${item.popup === undefined ? nothing : popoverOf(item.popup)}\n @click=${() => {\n this.#roving.focus(index);\n if (!unavailable) item.press();\n }}\n >\n ${\n item.menu === true\n ? html`<span class=\"value\">${item.text}</span>\n <svg class=\"icon chevron\" part=\"icon icon-chevron\" viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${item.icon}</svg>`\n : html`${item.icon === null ? nothing : html`<svg class=\"icon\" part=\"icon icon-${item.iconName}\" data-icon=${item.iconName} viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">${item.icon}</svg>`}\n ${item.text === null ? nothing : html`<span>${item.text}</span>`}${\n item.bar === undefined || item.bar === null\n ? nothing\n : html`<span class=\"color-mark\" data-color=${item.bar}></span>`\n }`\n }\n </button>`;\n }\n\n /** The arrows, Home and End along a menu's buttons; Escape closes it, back on its button; Tab goes on. */\n #menuKeydown = (event: KeyboardEvent): void => {\n const buttons = [...(event.currentTarget as HTMLElement).querySelectorAll<HTMLElement>('button')];\n const at = buttons.indexOf(event.target as HTMLElement);\n const step = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0;\n if (step !== 0) {\n event.preventDefault();\n buttons[(at + step + buttons.length) % buttons.length]?.focus();\n } else if (event.key === 'Home' || event.key === 'End') {\n event.preventDefault();\n buttons[event.key === 'Home' ? 0 : buttons.length - 1]?.focus();\n } else if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n } else if (event.key === 'Tab') this.#close(false);\n };\n\n /**\n * The rest of the style menu: the document's named styles, the ready styles it does not have yet, then the forms of\n * what the cursor is in.\n */\n #styleMenuMore(): TemplateResult | typeof nothing {\n const styles = this.#styles;\n if (styles === null) return nothing;\n const named = this.adapter?.style?.rules().filter((rule) => rule.name !== undefined) ?? [];\n const own = new Set(named.map((rule) => rule.name));\n const ready = (this.authoring?.styles ?? []).filter((preset) => !own.has(preset.name));\n const targets: readonly EditorStyleTarget[] = styles.targets;\n const group = (label: string, items: readonly TemplateResult[]) => html`<hr />\n <div class=\"menu-section\" role=\"group\" aria-label=${label}>\n <div class=\"menu-group\" aria-hidden=\"true\">${label}</div>\n ${items}\n </div>`;\n return html`${\n named.length === 0\n ? nothing\n : group(\n this.t('toolbar.myStyles'),\n named.map((rule) => {\n const name = rule.name ?? '';\n const box = this.#isBox(name);\n const none = this.#namedTarget(box) === null;\n return html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-named=${name}\n aria-checked=${String(this.#namedNow(box) === name)}\n aria-disabled=${none ? 'true' : nothing}\n @click=${() => {\n if (!none) this.#setNamed(name);\n }}\n >\n ${rule.label ?? name}\n </button>`;\n }),\n )\n }\n ${\n ready.length === 0\n ? nothing\n : group(\n this.t('toolbar.readyStyles'),\n ready.map(({ name, label, style, text }) => {\n const none = this.#namedTarget(text !== true) === null;\n return html`<button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-ready=${name}\n aria-disabled=${none ? 'true' : nothing}\n @click=${() => {\n // Its label as the author reads it now: from here on it is a style of this exercise.\n if (!none) this.#setNamed(name, { name, label, style });\n }}\n >\n ${label}\n </button>`;\n }),\n )\n }\n <hr />\n ${targets.map(\n (target) => html`<button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-style-target=${target.kind}\n @click=${() => void this.openStyle(target.kind)}\n >\n ${this.t('style.target.more', { target: this.t(`style.target.${target.kind}`) })}\n </button>`,\n )}\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n data-style-target=\"rules\"\n @click=${() => void this.openStyle('rules')}\n >\n ${this.t('style.rules.open')}\n </button>`;\n }\n\n /** The open popup of the style controls, from its module. */\n #stylePopup(): TemplateResult | typeof nothing {\n const module = this.#stylePopupsModule;\n const popup = this.#popup;\n const styles = this.#styles;\n if (module === null || styles === null || (popup !== 'panel' && !STYLE_POPUPS.has(popup ?? '')))\n return nothing;\n return module.stylePopup({\n popup: popup === 'panel' ? { panel: this.#panel } : (popup as StylePopup),\n styles,\n fonts: this.authoring?.fonts ?? [],\n colorError: this.#colorError,\n authoring: this.authoring,\n adapter: this.adapter,\n t: (key, params) => this.t(key, params),\n setText: (changes) => this.#setText(changes),\n setBlock: (changes) => this.#setBlock(changes),\n refuseColor: () => {\n this.#colorError = true;\n this.requestUpdate();\n },\n close: (back) => this.#close(back),\n menuKeydown: this.#menuKeydown,\n });\n }\n\n #styleMenu(): TemplateResult {\n const state = this.#state;\n const choose = (style: EditorFormat) => {\n this.#close(false);\n if (!state.active.includes(style) || style === 'paragraph') this.#format(style);\n else this.#done();\n };\n return html`<div\n id=\"style\"\n class=\"menu\"\n popover=\"manual\"\n role=\"menu\"\n aria-label=${this.t('toolbar.style', { style: this.t(`toolbar.${STYLES.find((s) => state.active.includes(s)) ?? 'paragraph'}`) })}\n part=\"style-menu\"\n @keydown=${this.#menuKeydown}\n >\n ${STYLES.map(\n (style) => html`<button\n type=\"button\"\n role=\"menuitemradio\"\n tabindex=\"-1\"\n data-format=${style}\n aria-checked=${String(state.active.includes(style))}\n aria-disabled=${state.enabled.includes(style) ? nothing : 'true'}\n @click=${() => choose(style)}\n >\n ${this.t(`toolbar.${style}`)}\n </button>`,\n )}\n ${this.#styleMenuMore()}\n </div>`;\n }\n\n #linkPopup(): TemplateResult {\n const state = this.#state;\n const apply = () => {\n const input = this.renderRoot.querySelector<HTMLInputElement>('#link-address');\n const href = input?.value.trim() ?? '';\n if (href === '') {\n this.#close(false);\n this.#format('link');\n return;\n }\n if (this.authoring?.urlPolicy(href, { tag: 'a', attribute: 'href' }) !== true) {\n this.#linkError = true;\n this.requestUpdate();\n input?.focus();\n return;\n }\n this.#close(false);\n this.#format('link', href);\n };\n return html`<div\n id=\"link\"\n class=\"link\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${this.t('toolbar.link')}\n part=\"link\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n } else if (event.key === 'Enter' && (event.target as HTMLElement).localName === 'input') {\n event.preventDefault();\n apply();\n }\n }}\n >\n <label for=\"link-address\">${this.t('toolbar.link.address')}</label>\n <input\n id=\"link-address\"\n type=\"url\"\n inputmode=\"url\"\n .value=${this.#popup === 'link' ? (state.href ?? '') : ''}\n aria-invalid=${this.#linkError ? 'true' : nothing}\n aria-describedby=${this.#linkError ? 'link-error' : nothing}\n />\n <div role=\"alert\">${this.#linkError ? html`<p class=\"error\" id=\"link-error\">${this.t('toolbar.link.blocked')}</p>` : nothing}</div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"primary\" @click=${apply}>${this.t('toolbar.link.apply')}</button>\n ${\n state.href === null\n ? nothing\n : html`<button\n type=\"button\"\n @click=${() => {\n this.#close(false);\n this.#format('link');\n }}\n >\n ${this.t('toolbar.link.remove')}\n </button>`\n }\n </div>\n </div>`;\n }\n\n #insertPopup(): TemplateResult {\n const authoring = this.authoring;\n return html`<div\n id=\"insert\"\n class=\"insert\"\n popover=\"manual\"\n role=\"dialog\"\n aria-label=${this.t(`toolbar.${this.#menu}`)}\n part=\"insert\"\n @keydown=${(event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.#close(true);\n }\n }}\n @focusout=${(event: FocusEvent) => {\n const next = event.relatedTarget as Node | null;\n if (next !== null && !(event.currentTarget as HTMLElement).contains(next)) this.#close(false);\n }}\n @astl-inserted=${() => {\n this.#close(false);\n this.#done();\n }}\n >\n <div class=\"search\">\n <input\n type=\"search\"\n aria-label=${this.t('toolbar.search')}\n placeholder=${this.t('toolbar.search')}\n .value=${this.#query}\n @input=${(event: Event) => {\n this.#query = (event.target as HTMLInputElement).value;\n this.requestUpdate();\n }}\n @keydown=${(event: KeyboardEvent) => {\n if (event.key !== 'Enter') return;\n event.preventDefault();\n const first = this.menu?.renderRoot.querySelector<HTMLButtonElement>(\n 'button.insert:not(:disabled)',\n );\n first?.click();\n }}\n />\n </div>\n <astl-insert-menu\n part=\"menu\"\n .authoring=${authoring}\n .adapter=${this.adapter}\n .filter=${this.#query}\n .groups=${MENU_GROUPS[this.#menu]}\n ></astl-insert-menu>\n </div>`;\n }\n\n protected override render(): TemplateResult | typeof nothing {\n if (this.authoring === null) return nothing;\n const { lang, dir } = this.ui;\n // Out of the editing view (the first), only the switch works.\n const away = this.views.length > 0 && this.view !== this.views[0]?.name;\n const groups = this.#groups().map(\n ([name, items]) =>\n [\n name,\n away\n ? items.map((item) => (item.checked === undefined ? { ...item, disabled: true } : item))\n : items,\n ] as const,\n );\n this.#items = groups.flatMap(([, items]) => items);\n let index = 0;\n const group = ([name, items]: readonly [string, readonly Item[]], at: number) =>\n html`<div class=${name} role=${name === 'group views' ? 'radiogroup' : 'presentation'}\n part=${name === 'group views' ? 'views' : nothing}\n aria-label=${name === 'group views' ? this.t('toolbar.view') : nothing}>\n ${at === 0 || name === 'group views' ? nothing : html`<span class=\"separator\" part=\"separator\" aria-hidden=\"true\"></span>`}\n ${items.map((item) => this.#button(item, index++))}\n </div>`;\n // The formats come first, up to the inserts: on a phone they scroll in a row of their own (barStyles).\n const split = Math.max(\n 0,\n groups.findIndex(([name]) => name === 'group inserts'),\n );\n // The picture dialog is outside the popovers: a picture asked for from a menu or a featured button shows while\n // they are closed.\n return html`<div\n class=\"bar\"\n part=\"toolbar\"\n role=\"toolbar\"\n aria-label=${this.t('toolbar.label')}\n lang=${lang}\n dir=${dir}\n @mousedown=${(event: MouseEvent) => {\n // A press keeps the editor's focus and selection.\n if ((event.target as HTMLElement).closest('button') !== null) event.preventDefault();\n }}\n @keydown=${(event: KeyboardEvent) => this.#keydown(event)}\n >\n ${split === 0 ? nothing : html`<div class=\"formats\">${groups.slice(0, split).map((g, at) => group(g, at))}</div>`}\n <div class=\"actions\">${groups.slice(split).map((g, at) => group(g, split + at))}</div>\n </div>\n <div lang=${lang} dir=${dir}>\n ${this.#styleMenu()} ${this.#linkPopup()} ${this.#insertPopup()} ${this.#stylePopup()}\n </div>\n <astl-picture-dialog .authoring=${this.authoring}></astl-picture-dialog>`;\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n super.updated(changed);\n const menu = this.menu;\n if (menu !== null) menu.dialog = this.renderRoot.querySelector('astl-picture-dialog');\n // Through the CSSOM: a strict Content Security Policy blocks a style attribute, which Lit's styleMap writes on its\n // first render.\n for (const mark of this.renderRoot.querySelectorAll<HTMLElement>('.color-mark')) {\n mark.style.background = mark.dataset.color ?? '';\n }\n for (const choice of this.renderRoot.querySelectorAll<HTMLElement>('[data-font]')) {\n choice.style.fontFamily = choice.dataset.font ?? '';\n }\n // Popups stay where their buttons are while the page scrolls or the bar wraps.\n if (this.#popup === null) return;\n const element = this.renderRoot.querySelector<HTMLElement>(`#${popoverOf(this.#popup)}`);\n const opener = this.renderRoot.querySelector<HTMLElement>(`[data-popup=\"${openerOf(this.#popup)}\"]`);\n if (element !== null && opener !== null && element.matches(':popover-open')) this.#place(element, opener);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-toolbar': AstlToolbar;\n }\n}\n","import { AstlInsertMenu } from './elements/insert-menu.js';\nimport { AstlInspector } from './elements/inspector.js';\nimport { AstlIssues } from './elements/issues.js';\nimport { AstlPictureDialog } from './elements/picture-dialog.js';\nimport { AstlPictureField } from './elements/picture-field.js';\nimport { AstlPreview } from './elements/preview.js';\nimport { styleElementsIn } from './elements/style-load.js';\nimport { AstlToolbar } from './elements/toolbar.js';\n\nconst ELEMENTS: readonly (readonly [string, CustomElementConstructor])[] = [\n ['astl-insert-menu', AstlInsertMenu],\n ['astl-inspector', AstlInspector],\n ['astl-issues', AstlIssues],\n ['astl-preview', AstlPreview],\n ['astl-toolbar', AstlToolbar],\n ['astl-picture-dialog', AstlPictureDialog],\n ['astl-picture-field', AstlPictureField],\n];\n\n/**\n * Defines `<astl-toolbar>`, `<astl-insert-menu>`, `<astl-inspector>`, `<astl-issues>` and `<astl-preview>`, and the\n * two they use for pictures, `<astl-picture-dialog>` and `<astl-picture-field>` (nothing is defined on import;\n * `<astl-style-form>` and `<astl-style-rules>` come with `loadStyleElements`, on first use). Safe to call again; a\n * tag already defined by another class throws, as two copies of the kit would otherwise mix silently.\n */\nexport function defineAuthoringElements(registry: CustomElementRegistry = customElements): void {\n styleElementsIn(registry);\n for (const [tag, element] of ELEMENTS) {\n const existing = registry.get(tag);\n if (existing === element) continue;\n if (existing !== undefined) throw new Error(`<${tag}> is already defined by another class`);\n registry.define(tag, element);\n }\n}\n","/**\n * Page breaks, new pages and joins as edits of the source text, for text-based adapters (the textarea adapter's\n * `splitPage`, `addPage` and `mergePage`): the rules of `EditorAdapter`, on the element ranges of `scan.ts`, so\n * everything around an edit stays as written.\n */\nimport { CLASS_ATTRIBUTE, CONTENT_ATTRIBUTES, DOC_TAG, PAGE_TAG, STYLE_TAG } from '@astl/core';\nimport { attributeValue, type ElementRange, elementTree, tokenize, usedIds } from './scan.js';\n\n/** A source after a page edit, and the offset of the caret in it. */\nexport interface PageEdit {\n readonly source: string;\n readonly caret: number;\n}\n\n/** A page edit that added a page: its id. */\nexport interface AddedPage extends PageEdit {\n readonly id: string;\n}\n\n/** Blocks that break at the caret: the others break after themselves. */\nconst TEXT_BLOCKS: ReadonlySet<string> = new Set(['p', 'h2', 'h3', 'h4']);\n\n/** Where an element's content ends: at its end tag, or where it was closed. */\nconst contentEnd = (range: ElementRange): number => range.endTag?.start ?? range.end;\n\n/**\n * The content of `<astl-doc>` (the whole source without one), its blocks and its pages. It starts after the named styles\n * at its head: they stay there, out of any page.\n */\nfunction documentOf(source: string) {\n const roots = elementTree(source);\n const doc = roots.find((range) => range.name === DOC_TAG);\n const children = doc?.children ?? roots;\n const content = children.findIndex((range) => range.name !== STYLE_TAG);\n const blocks = content < 0 ? [] : children.slice(content);\n return {\n start: (content < 0 ? children.at(-1) : children[content - 1])?.end ?? doc?.startTag.end ?? 0,\n end: doc === undefined ? source.length : contentEnd(doc),\n blocks,\n pages: blocks.filter((range) => range.name === PAGE_TAG),\n };\n}\n\n/** `page-<n>` with the smallest n no id of the source uses; `used` takes it. */\nfunction freshPage(used: Set<string>): string {\n let n = 1;\n while (used.has(`page-${n}`)) n++;\n used.add(`page-${n}`);\n return `page-${n}`;\n}\n\n/** Nothing a student would see: whitespace and formatting tags, no text, line break, picture or component. */\nfunction blank(fragment: string): boolean {\n let at = 0;\n for (const tag of tokenize(fragment)) {\n if (fragment.slice(at, tag.start).trim() !== '') return false;\n if (tag.type === 'start' && (tag.name === 'br' || tag.name === 'img' || tag.name.includes('-')))\n return false;\n at = tag.end;\n }\n return fragment.slice(at).trim() === '';\n}\n\n/**\n * The elements from `block` down to the innermost one whose content holds `caret` (its formatting), or null when the\n * caret is in a tag or in a component.\n */\nfunction inlinePath(block: ElementRange, caret: number): ElementRange[] | null {\n const path = [block];\n for (let el = block; ; ) {\n if (caret < el.startTag.end || caret > contentEnd(el)) return null;\n const child = el.children.find((c) => c.start < caret && caret < c.end);\n if (child === undefined) return path;\n if (child.name.includes('-')) return null;\n path.push(child);\n el = child;\n }\n}\n\n/**\n * A page break at `caret` (`EditorAdapter.splitPage`): in a paragraph or a heading on a page, at the caret (the\n * formatting around it closed before the break and opened again after it); at its start before it, at its end after\n * it; in any other block (a layout, whatever holds the caret in it), or in a tag, after that block. Null when the caret\n * is not in a page's content (or in the document's, without pages).\n */\nexport function splitPageSource(source: string, caret: number): AddedPage | null {\n const doc = documentOf(source);\n const page = doc.pages.find((p) => p.startTag.end <= caret && caret <= contentEnd(p));\n if (doc.pages.length > 0 ? page === undefined : caret < doc.start || caret > doc.end) return null;\n const [from, to] = page === undefined ? [doc.start, doc.end] : [page.startTag.end, contentEnd(page)];\n const blocks = page?.children ?? doc.blocks;\n let at = caret;\n // In the middle of a paragraph: its formatting, closed before the break and opened again after it.\n let close = '';\n let open = '';\n const block = blocks.find((b) => b.start < caret && caret < b.end);\n if (block !== undefined) {\n const path = TEXT_BLOCKS.has(block.name) ? inlinePath(block, caret) : null;\n if (path === null) at = block.end;\n else if (blank(source.slice(block.startTag.end, caret))) at = block.start;\n else if (blank(source.slice(caret, contentEnd(block)))) at = block.end;\n else {\n close = path\n .map((el) => `</${el.name}>`)\n .reverse()\n .join('');\n open = path.map((el) => source.slice(el.startTag.start, el.startTag.end)).join('');\n }\n }\n const used = usedIds(source);\n const first = page === undefined ? `<astl-page id=\"${freshPage(used)}\">` : '';\n const id = freshPage(used);\n // The new page keeps the content language and the look of what moves to it, as written.\n const language = (page?.startTag.attributes ?? [])\n .filter((a) => CONTENT_ATTRIBUTES.has(a.name) || a.name === CLASS_ATTRIBUTE)\n .map((a) => ` ${source.slice(a.start, a.end)}`)\n .join('');\n // A side left without blocks gets an empty paragraph, as an editor needs one to put the cursor in.\n const before = open !== '' || blocks.some((b) => b.end <= at) ? '' : '<p></p>';\n const empty = open === '' && !blocks.some((b) => b.start >= at);\n const left =\n `${source.slice(0, from)}${first}${source.slice(from, at)}${close}${before}</astl-page>` +\n `<astl-page id=\"${id}\"${language}>${empty ? '<p>' : open}`;\n const right = `${empty ? '</p>' : ''}${source.slice(at, to)}${first === '' ? '' : '</astl-page>'}${source.slice(to)}`;\n return { source: left + right, caret: left.length, id };\n}\n\n/**\n * An empty page (one empty paragraph) after the page `after`, else after the last page (`EditorAdapter.addPage`); in a\n * document without pages, after its content made the first page. The caret goes into the paragraph.\n */\nexport function addPageSource(source: string, after?: string): AddedPage {\n const doc = documentOf(source);\n const used = usedIds(source);\n const page = doc.pages.find((p) => attributeValue(p.startTag, 'id') === after) ?? doc.pages.at(-1);\n const head =\n page === undefined\n ? `${source.slice(0, doc.start)}<astl-page id=\"${freshPage(used)}\">${source.slice(doc.start, doc.end)}</astl-page>`\n : source.slice(0, page.end);\n const id = freshPage(used);\n const left = `${head}<astl-page id=\"${id}\"><p>`;\n return { source: `${left}</p></astl-page>${source.slice(page?.end ?? doc.end)}`, caret: left.length, id };\n}\n\n/**\n * The page `id` joined to the page before it (`EditorAdapter.mergePage`): the end tag of that page and the start tag\n * of this one go, so nothing between them is lost. The caret goes where its content starts. Null for the first page\n * or an id that is not a page's.\n */\nexport function mergePageSource(source: string, id: string): PageEdit | null {\n const { pages } = documentOf(source);\n const index = pages.findIndex((p) => attributeValue(p.startTag, 'id') === id);\n const end = pages[index - 1]?.endTag;\n const start = pages[index]?.startTag;\n if (index < 1 || end == null || start === undefined) return null;\n const left = source.slice(0, end.start) + source.slice(end.end, start.start);\n return { source: left + source.slice(start.end), caret: left.length };\n}\n","/**\n * The reference EditorAdapter: the source edited as text in a `<textarea>`. Elements are found with `scanElements`,\n * edits are string splices, so the author's formatting outside the edited element is never touched.\n */\nimport { DOC_TAG, type EditorAdapter, type EditorSelection, PAGE_TAG } from '@astl/core';\nimport { addPageSource, mergePageSource, type PageEdit, splitPageSource } from './pages.js';\nimport { type ScannedElement, scanElements, tokenize } from './scan.js';\n\nexport interface TextareaAdapter extends EditorAdapter {\n /** A page break at the caret, in the source text (`EditorAdapter.splitPage`). */\n splitPage(): string | null;\n /** An empty page after the page `after`, in the source text (`EditorAdapter.addPage`). */\n addPage(after?: string): string;\n /** The page `id` joined to the page before it, in the source text (`EditorAdapter.mergePage`). */\n mergePage(id: string): boolean;\n /** Removes the textarea listeners and every subscription. */\n destroy(): void;\n}\n\nconst SELECTION_EVENTS = ['select', 'keyup', 'click', 'focus'] as const;\n\nfunction same(a: EditorSelection | null, b: EditorSelection | null): boolean {\n return a?.id === b?.id && a?.tag === b?.tag;\n}\n\nconst isComponent = (el: ScannedElement) => el.tag !== PAGE_TAG;\n\n/**\n * Where an insertion may go without breaking the source: never inside a tag or comment, never inside a component\n * (it goes after it: components do not nest), never outside `<astl-doc>` (it goes to the end of the last page).\n */\nfunction insertionRange(source: string, start: number, end: number): [number, number] {\n const elements = scanElements(source);\n // A caret right before an element is not in it; a selection that touches an element is.\n const hit = elements.filter(\n (el) => isComponent(el) && (start === end ? el.start < start : el.start < end) && start < el.end,\n );\n const last = hit[hit.length - 1];\n if (last !== undefined) return [last.end, last.end];\n const tags = tokenize(source);\n const inside = (offset: number) => tags.find((tag) => tag.start < offset && offset < tag.end);\n const cut = inside(start);\n if (cut !== undefined) return [cut.end, cut.end];\n if (inside(end) !== undefined) return [start, start];\n const open = tags.find((tag) => tag.type === 'start' && tag.name === DOC_TAG);\n const close = tags.findLast((tag) => tag.type === 'end' && tag.name === DOC_TAG);\n if (open === undefined) return [start, end];\n if (start >= open.end && (close === undefined || end <= close.start)) return [start, end];\n const pages = elements.filter((el) => el.tag === PAGE_TAG);\n const page = pages[pages.length - 1];\n const pageClose =\n page && tags.find((tag) => tag.type === 'end' && tag.name === PAGE_TAG && tag.end === page.end);\n const at = pageClose?.start ?? close?.start ?? source.length;\n return [at, at];\n}\n\n/** Puts the caret of a textarea at `offset` and scrolls the line into view (the caret line, approximately). */\nfunction reveal(textarea: HTMLTextAreaElement, offset: number): void {\n const line = textarea.value.slice(0, offset).split('\\n').length - 1;\n const height = Number.parseFloat(getComputedStyle(textarea).lineHeight) || 20;\n textarea.scrollTop = Math.max(0, line * height - textarea.clientHeight / 3);\n textarea.setSelectionRange(offset, offset);\n}\n\nexport function createTextareaAdapter(textarea: HTMLTextAreaElement): TextareaAdapter {\n const changes = new Set<() => void>();\n const selections = new Set<(selection: EditorSelection | null) => void>();\n let cache: { readonly value: string; readonly elements: ScannedElement[] } | null = null;\n const elements = (): ScannedElement[] => {\n const value = textarea.value;\n if (cache?.value !== value) cache = { value, elements: scanElements(value) };\n return cache.elements;\n };\n const component = (id: string) => elements().find((el) => isComponent(el) && el.id === id) ?? null;\n\n const current = (): EditorSelection | null => {\n const caret = textarea.selectionStart;\n const el = elements().find((e) => isComponent(e) && e.start <= caret && caret < e.end);\n return el?.id ? { id: el.id, tag: el.tag } : null;\n };\n let last = current();\n const emitSelection = () => {\n const now = current();\n if (same(now, last)) return;\n last = now;\n for (const listener of [...selections]) listener(now);\n };\n const emitChange = () => {\n for (const listener of [...changes]) listener();\n emitSelection();\n };\n\n textarea.addEventListener('input', emitChange);\n for (const type of SELECTION_EVENTS) textarea.addEventListener(type, emitSelection);\n\n const setSource = (source: string) => {\n // Only the span that differs is replaced, so a change at one place (the document's start tag, from the\n // inspector) leaves the caret where it was in the text around it.\n const old = textarea.value;\n const shorter = Math.min(old.length, source.length);\n let start = 0;\n while (start < shorter && old[start] === source[start]) start++;\n let end = 0;\n while (end < shorter - start && old[old.length - 1 - end] === source[source.length - 1 - end]) end++;\n textarea.setRangeText(source.slice(start, source.length - end), start, old.length - end, 'preserve');\n emitChange();\n };\n /** A page edit (`pages.ts`): the new source, then the caret where the edit puts it. */\n const apply = (edit: PageEdit) => {\n setSource(edit.source);\n reveal(textarea, edit.caret);\n emitSelection();\n };\n\n return {\n editsSource: true,\n getSource: () => textarea.value,\n setSource,\n insert(html) {\n const [start, end] = insertionRange(textarea.value, textarea.selectionStart, textarea.selectionEnd);\n // The inserted element ends up selected: the inspector shows it and the next insert goes after it.\n textarea.setRangeText(html, start, end, 'select');\n emitChange();\n },\n getElement(id) {\n const el = component(id);\n return el === null ? null : textarea.value.slice(el.start, el.end);\n },\n replaceElement(id, html) {\n const el = component(id);\n if (el === null) return;\n const { selectionStart, selectionEnd, selectionDirection } = textarea;\n const delta = html.length - (el.end - el.start);\n // A caret inside the element stays inside it (at most on its last character); later offsets shift.\n const map = (offset: number) =>\n offset < el.start\n ? offset\n : offset >= el.end\n ? offset + delta\n : Math.min(offset, el.start + Math.max(0, html.length - 1));\n textarea.setRangeText(html, el.start, el.end, 'preserve');\n textarea.setSelectionRange(map(selectionStart), map(selectionEnd), selectionDirection);\n emitChange();\n },\n getSelection: current,\n select(id) {\n const el = elements().find((e) => e.id === id);\n if (el === undefined) return;\n reveal(textarea, el.start);\n textarea.focus();\n emitSelection();\n },\n splitPage() {\n const edit = splitPageSource(textarea.value, textarea.selectionStart);\n if (edit !== null) apply(edit);\n return edit?.id ?? null;\n },\n addPage(after) {\n const edit = addPageSource(textarea.value, after);\n apply(edit);\n return edit.id;\n },\n mergePage(id) {\n const edit = mergePageSource(textarea.value, id);\n if (edit !== null) apply(edit);\n return edit !== null;\n },\n onChange(listener) {\n changes.add(listener);\n return () => changes.delete(listener);\n },\n onSelectionChange(listener) {\n selections.add(listener);\n return () => selections.delete(listener);\n },\n destroy() {\n textarea.removeEventListener('input', emitChange);\n for (const type of SELECTION_EVENTS) textarea.removeEventListener(type, emitSelection);\n changes.clear();\n selections.clear();\n },\n };\n}\n","import{nothing as r}from\"../lit-html.js\";import{directive as t,Directive as e}from\"../directive.js\";import{setCommittedValue as s}from\"../directive-helpers.js\";\n/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */const i=t(class extends e{constructor(){super(...arguments),this.key=r}render(r,t){return this.key=r,t}update(r,[t,e]){return t!==this.key&&(s(r),this.key=t),e}});export{i as keyed};\n//# sourceMappingURL=keyed.js.map\n","/**\n * `<astl-editor>`: the authoring kit (toolbar, inspector, issues, preview) around an editing surface. The surface is\n * TipTap by default, imported on demand; any other editor plugs in through `adapter` and a `slot=\"surface\"` child, and\n * then TipTap is never loaded.\n */\nimport {\n type AttemptPolicy,\n type ComponentDefinition,\n type ComponentManifest,\n directionOf,\n type EditorAdapter,\n type EditorDescriptor,\n type Engine,\n type GroundColors,\n type Issue,\n type MessageCatalog,\n type MessageParams,\n type NormalisationProfile,\n negotiateLocale,\n PRACTICE_POLICY,\n type SlotKind,\n type StyleTemplate,\n type UrlPolicy,\n} from '@astl/core';\nimport {\n type AstlPictureDialog,\n type AstlPreview,\n type AstlToolbar,\n type Authoring,\n createAuthoring,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n EDITOR_NAMESPACE,\n type EditorFont,\n type EditorStylePreset,\n editorMessages,\n type Outline,\n type PickPicture,\n type ToolbarView,\n type UploadAsset,\n} from '@astl/editor';\nimport { createEngine } from '@astl/engine';\nimport type { ElementEntry } from '@astl/player';\nimport { type ThemeSetting, tokens, tokensCss } from '@astl/tokens';\nimport {\n type CSSResult,\n type CSSResultGroup,\n css,\n html,\n LitElement,\n nothing,\n type PropertyDeclarations,\n type PropertyValues,\n type TemplateResult,\n unsafeCSS,\n} from 'lit';\nimport { keyed } from 'lit/directives/keyed.js';\nimport type { SurfaceChange } from './blocks.js';\nimport type { DefineEditorOptions, EditorHostView } from './define.js';\nimport type { Surface } from './surface.js';\n\n/**\n * Every token as `inherit` on `selector`, for elements that redeclare the tokens on their own `:host` (the kit\n * elements): a rule from the outer tree wins over `:host`, so tokens set on `<astl-editor>` reach them. The kit's\n * preview forwards them to its player the same way.\n */\nfunction inheritTokens(selector: string): CSSResult {\n const names = [tokens.scale, tokens.themes.light, tokens.themeScale.light].flatMap(Object.keys);\n const lines = ['color-scheme: inherit;', ...names.map((name) => `--astl-${name}: inherit;`)];\n return unsafeCSS(`${selector} {\\n${lines.join('\\n')}\\n}`);\n}\n\n/**\n * The shadow root of `<astl-editor>`: tokens, the toolbar over the surface beside the kit, everything in one column\n * when narrow. The surface's own stylesheet comes with the surface (`styles.ts`).\n */\nconst editorStyles: CSSResultGroup = [\n // Tokens sit on :host so host pages can override any --astl-* property on <astl-editor> itself.\n unsafeCSS(tokensCss(':host')),\n inheritTokens('astl-toolbar, astl-inspector, astl-issues, astl-preview, astl-picture-dialog'),\n css`\n :host {\n display: block;\n container-type: inline-size;\n color: var(--astl-ink);\n font-family: var(--astl-font-body);\n font-size: var(--astl-size-ui);\n line-height: 1.4;\n }\n :host([hidden]) {\n display: none;\n }\n `,\n // The bands are a column of flex items, not a grid: the spec makes a grid item's containing block its grid area,\n // which may hold a host's sticky toolbar (`::part(toolbar)`) to its own row; a flex item's is the whole column.\n css`\n .layout {\n display: flex;\n flex-direction: column;\n gap: var(--astl-editor-layout-gap, var(--astl-space-4));\n }\n .work {\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n align-items: start;\n gap: var(--astl-space-4);\n }\n .surface,\n .side,\n .start,\n .end {\n display: flex;\n flex-direction: column;\n gap: var(--astl-space-4);\n min-inline-size: 0;\n }\n .surface {\n position: relative;\n }\n ::slotted(*) {\n box-sizing: border-box;\n inline-size: 100%;\n max-inline-size: 100%;\n }\n .status {\n margin: 0;\n padding: var(--astl-space-4);\n border: var(--astl-outline-width) solid var(--astl-line);\n border-radius: var(--astl-radius-l);\n background: var(--astl-surface);\n color: var(--astl-ink-muted);\n }\n `,\n // The side column and the host's columns in another view, and a host column with nothing slotted: out of the way (the\n // grid keeps no track and no gap for them). The notice line with nothing to say: out of sight, but still in the\n // accessibility tree, so its next message is announced.\n css`\n .side[hidden],\n .start[hidden],\n .end[hidden] {\n display: none;\n }\n .status.idle {\n position: absolute;\n inline-size: 1px;\n block-size: 1px;\n padding: 0;\n border: 0;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n }\n `,\n // The status line under the toolbar: the counts in mono, then whether it is ready to share (in words, never the\n // colour alone).\n css`\n .status-line {\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n gap: 0 var(--astl-space-3);\n margin: 0;\n color: var(--astl-ink-muted);\n font-size: var(--astl-size-small);\n }\n .counts {\n font-family: var(--astl-font-mono);\n }\n .counts span + span::before {\n content: '\\\\00b7' / '';\n margin-inline: var(--astl-space-1);\n }\n .ready {\n color: var(--astl-success);\n font-weight: 600;\n }\n .error {\n color: var(--astl-danger);\n }\n `,\n // Wide: one row, between the toolbar and the preview: the host's `start` column, the surface, the side column (3:2 with\n // the surface, at least 18rem), the host's `end` column. A row, not a grid, so a column that is not there takes no\n // track and no gap. The side column and the host's columns stay in view while the content scrolls, within the work\n // row only (never over the preview), each scrolling on its own when taller than the window.\n css`\n @container (min-inline-size: 48rem) {\n .work {\n display: flex;\n }\n .surface {\n flex: 3 1 0;\n }\n .side {\n flex: 2 1 0;\n min-inline-size: 18rem;\n }\n .start,\n .end {\n flex: none;\n }\n .side,\n .start,\n .end {\n position: sticky;\n inset-block-start: var(--astl-editor-sticky-top, var(--astl-space-4));\n max-block-size: calc(100dvh - var(--astl-editor-sticky-top, var(--astl-space-4)) - var(--astl-space-4));\n overflow-y: auto;\n padding: var(--astl-focus-width);\n margin: calc(-1 * var(--astl-focus-width));\n }\n }\n `,\n];\n\n/** What `defineEditor` registered: shared by every `<astl-editor>` of this module instance. */\ninterface Registered {\n readonly components: ReadonlyMap<string, ComponentDefinition>;\n readonly editors: ReadonlyMap<string, EditorDescriptor>;\n readonly elements: ReadonlyMap<string, ElementEntry>;\n readonly styleTemplates: ReadonlyMap<string, StyleTemplate>;\n readonly slotKinds: ReadonlyMap<string, SlotKind>;\n readonly catalogs: readonly MessageCatalog[];\n readonly profile: Partial<NormalisationProfile>;\n readonly urlPolicy: UrlPolicy | null;\n readonly groundColors: GroundColors | null;\n readonly uploadAsset: UploadAsset | null;\n readonly pickPicture: PickPicture | null;\n /** The style controls' fonts (`DefineEditorOptions.fonts`). */\n readonly fonts: readonly EditorFont[];\n /** The ready styles (`DefineEditorOptions.styles`). */\n readonly styles: readonly EditorStylePreset[];\n /** The toolbar's featured inserts (`DefineEditorOptions.featured`). */\n readonly featured: readonly string[];\n /** The host's views (`DefineEditorOptions.views`). */\n readonly views: readonly EditorHostView[];\n /** The insert menus' catalogs (`DefineEditorOptions.menuMessages`). */\n readonly menuMessages: (() => Promise<readonly MessageCatalog[]>) | null;\n /** The engine of every registered component, for editors without a `components` list. */\n readonly engine: Engine;\n /** Bumped on every registration. */\n readonly version: number;\n}\n\n/** The tag of a preview element: the one place that reads the shape of `elements`. */\nconst elementTag = (element: ElementEntry): string =>\n 'load' in element ? element.tag : element.manifest.tag;\n\nlet secret: string | null = null;\n\n/**\n * The preview compiles in the browser, so its secret only keeps preview ids apart from published ones: a random one\n * per page, never a known value.\n */\nfunction previewSecret(): string {\n secret ??= Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) =>\n b.toString(16).padStart(2, '0'),\n ).join('');\n return secret;\n}\n\ntype Lists = Omit<Registered, 'engine' | 'version'>;\n\nfunction engineOf(lists: Lists, components: readonly ComponentDefinition[]): Engine {\n return createEngine({\n components,\n secret: previewSecret(),\n slotKinds: [...lists.slotKinds.values()],\n profile: lists.profile,\n catalogs: lists.catalogs,\n styleTemplates: [...lists.styleTemplates.values()],\n ...(lists.urlPolicy === null ? {} : { urlPolicy: lists.urlPolicy }),\n ...(lists.groundColors === null ? {} : { groundColors: lists.groundColors }),\n });\n}\n\nconst EMPTY: Lists = {\n components: new Map(),\n editors: new Map(),\n elements: new Map(),\n styleTemplates: new Map(),\n slotKinds: new Map(),\n catalogs: [],\n profile: {},\n urlPolicy: null,\n groundColors: null,\n uploadAsset: null,\n pickPicture: null,\n fonts: DEFAULT_FONTS,\n styles: DEFAULT_STYLES,\n featured: [],\n views: [],\n menuMessages: null,\n};\n\nlet registered: Registered | null = null;\n\n/** Without `defineEditor` (the class defined by hand): nothing registered. */\nfunction current(): Registered {\n registered ??= { ...EMPTY, engine: engineOf(EMPTY, []), version: 0 };\n return registered;\n}\n\n/** Connected editors: a registration re-renders them. */\nconst connected = new Set<AstlEditor>();\n\n/** `items` added by key: the same object again is skipped, another object under a taken key throws. */\nfunction added<T>(\n into: ReadonlyMap<string, T>,\n items: readonly T[] | undefined,\n key: (item: T) => string,\n what: string,\n): ReadonlyMap<string, T> {\n const out = new Map(into);\n for (const item of items ?? []) {\n const name = key(item);\n const taken = out.get(name);\n if (taken !== undefined && taken !== item) throw new Error(`${what} ${name} is already registered`);\n out.set(name, item);\n }\n return out;\n}\n\n/** Adds to what every `<astl-editor>` offers (`defineEditor`). Checks everything before anything changes. */\nexport function register(options: DefineEditorOptions): void {\n const before = registered ?? { ...EMPTY, version: 0 };\n const tag = (item: { readonly manifest: ComponentManifest }) => item.manifest.tag;\n const lists: Lists = {\n components: added(before.components, options.components, tag, 'Component'),\n editors: added(before.editors, options.editors, tag, 'Editor descriptor'),\n elements: added(before.elements, options.elements, elementTag, 'Preview element'),\n styleTemplates: added(before.styleTemplates, options.styleTemplates, (t) => t.name, 'Style template'),\n slotKinds: added(before.slotKinds, options.slotKinds, (k) => k.kind, 'Slot kind'),\n catalogs: [...new Set([...before.catalogs, ...(options.catalogs ?? [])])],\n profile: { ...before.profile, ...options.profile },\n urlPolicy: options.urlPolicy ?? before.urlPolicy,\n groundColors: options.groundColors ?? before.groundColors,\n uploadAsset: options.uploadAsset ?? before.uploadAsset,\n pickPicture: options.pickPicture ?? before.pickPicture,\n fonts: options.fonts ?? before.fonts,\n styles: options.styles ?? before.styles,\n featured: options.featured ?? before.featured,\n views: options.views ?? before.views,\n menuMessages: options.menuMessages ?? before.menuMessages,\n };\n // Nothing new (the same objects again): connected editors keep their surface, cursor and undo history.\n const maps = ['components', 'editors', 'elements', 'styleTemplates', 'slotKinds'] as const;\n const profile = (p: Lists['profile']) => JSON.stringify(Object.entries(p).sort());\n if (\n registered !== null &&\n maps.every((list) => lists[list].size === before[list].size) &&\n lists.catalogs.length === before.catalogs.length &&\n lists.urlPolicy === before.urlPolicy &&\n JSON.stringify(lists.groundColors) === JSON.stringify(before.groundColors) &&\n lists.uploadAsset === before.uploadAsset &&\n lists.pickPicture === before.pickPicture &&\n lists.menuMessages === before.menuMessages &&\n JSON.stringify(lists.fonts) === JSON.stringify(before.fonts) &&\n JSON.stringify(lists.styles) === JSON.stringify(before.styles) &&\n lists.featured.join(' ') === before.featured.join(' ') &&\n JSON.stringify(lists.views) === JSON.stringify(before.views) &&\n profile(lists.profile) === profile(before.profile)\n ) {\n return;\n }\n // The engine and the kit check definitions and descriptors now, not when an editor first renders.\n const engine = engineOf(lists, [...lists.components.values()]);\n createAuthoring({\n engine,\n descriptors: [...lists.editors.values()],\n locale: 'en',\n fonts: lists.fonts,\n styles: lists.styles,\n });\n registered = { ...lists, engine, version: before.version + 1 };\n for (const editor of connected) editor.requestUpdate();\n}\n\n/** The authoring of one editor: every registered type, or those `allowed` names. */\nfunction authoringFor(r: Registered, locale: string, allowed: readonly string[] | null): Authoring {\n const keep = <T>(items: ReadonlyMap<string, T>) =>\n [...items.entries()].filter(([tag]) => allowed === null || allowed.includes(tag)).map(([, item]) => item);\n return createAuthoring({\n engine: allowed === null ? r.engine : engineOf(r, keep(r.components)),\n descriptors: keep(r.editors),\n elements: keep(r.elements),\n locale,\n catalogs: r.catalogs,\n styleTemplates: [...r.styleTemplates.values()],\n fonts: r.fonts,\n styles: r.styles,\n ...(r.urlPolicy === null ? {} : { urlPolicy: r.urlPolicy }),\n ...(r.uploadAsset === null ? {} : { uploadAsset: r.uploadAsset }),\n ...(r.pickPicture === null ? {} : { pickPicture: r.pickPicture }),\n ...(r.menuMessages === null ? {} : { menuMessages: r.menuMessages }),\n });\n}\n\nconst THEMES: readonly ThemeSetting[] = ['light', 'dark', 'hc', 'auto'];\n\n/** A message of the status line: a key of the kit's namespace and its parameters. */\ninterface Notice {\n readonly key: string;\n readonly params?: MessageParams;\n}\nconst CHANGE = 'astl-editor-change';\nconst READY = 'astl-editor-ready';\nconst VIEW = 'astl-editor-view';\n\n/** The views of every editor: the surface, and the source as HTML (not for a surface that is the source already). */\nconst OWN_VIEWS: readonly string[] = ['visual', 'source'];\n\n/** The status line counts this long after the last change, as the issues list does. */\nconst COUNT_DELAY_MS = 300;\n\n/** The side panels, in the order `<astl-editor>` shows them by default. */\nconst PANELS: readonly string[] = ['issues', 'inspector'];\n\n/** A space-separated list attribute as a list (null when absent). */\nconst listAttribute = {\n fromAttribute: (value: string | null) =>\n value === null ? null : value.split(/\\s+/).filter((tag) => tag !== ''),\n};\n\n/** The `views` attribute: a JSON list of `{ name, label }` (null when absent or not JSON). */\nconst viewsAttribute = {\n fromAttribute: (value: string | null): unknown => {\n try {\n return value === null ? null : JSON.parse(value);\n } catch {\n return null;\n }\n },\n};\n\n/** The icon parts of the toolbar, forwarded so hosts can draw their own icons (`::part(icon-text-t)`). */\nconst KIT_ICONS: readonly string[] = [\n 'chevron',\n 'bold',\n 'italic',\n 'underline',\n 'link',\n 'bulleted',\n 'numbered',\n 'undo',\n 'redo',\n 'wrap',\n 'text',\n 'image',\n 'files',\n 'add',\n 'templates',\n];\n\n/** The inspector's parts, forwarded so hosts can restyle its header, banners and fields (`::part(inspector-issue)`). */\nconst INSPECTOR_PARTS =\n 'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style';\n\n/** The built-in surface module, once imported. */\nlet surfaces: typeof import('./surface.js') | null = null;\n/** The source view's module, once imported (when the view first opens). */\nlet sourceViews: typeof import('./source-view.js') | null = null;\n\nexport class AstlEditor extends LitElement {\n static override properties: PropertyDeclarations = {\n locale: {},\n components: { converter: listAttribute },\n featured: { converter: listAttribute },\n panels: { converter: listAttribute },\n view: {},\n views: { converter: viewsAttribute },\n theme: {},\n previewPolicy: { attribute: false },\n adapter: { attribute: false },\n };\n\n static override styles: CSSResultGroup = editorStyles;\n\n /** UI locale (`en`, `pl`); default: the `lang` attribute, else the browser languages, else `en`. */\n declare locale: string | null;\n /**\n * The component types authors can use (space-separated tags in the attribute); null: every registered type. Others\n * stay in the document, reported as unknown elements.\n */\n declare components: readonly string[] | null;\n /**\n * The toolbar's featured inserts, as buttons before \"More\" (space-separated in the attribute): component tags,\n * `tag:template` for a named starter, and `text`, `picture`, `page-break`. Null: the list `defineEditor` got.\n */\n declare featured: readonly string[] | null;\n /**\n * The side column's panels, in order (space-separated in the attribute): `issues` and `inspector`. Null: both,\n * issues first. Empty: no side column, the surface takes the width; a host then shows its own `<astl-inspector>`\n * or `<astl-issues>`, wired with `authoring` and `adapter` once the editor is ready.\n */\n declare panels: readonly string[] | null;\n /**\n * What the editor shows: `visual` (default) the surface; `source` the document's HTML in a text area, which leaving\n * applies (with errors the editor stays there and lists them, so no text is lost); or the `name` of one of `views`.\n * The toolbar's view switch sets it; each change fires `astl-editor-view` (bubbles, composed; `detail.view`).\n */\n declare view: string;\n /**\n * The host's views, after \"Visual\" and \"HTML\" in the view switch: `{ name, label }` each (the attribute: a JSON\n * list). One shows the host's `slot=\"view-<name>\"` children in place of the editor. Null: the list `defineEditor` got.\n */\n declare views: readonly EditorHostView[] | null;\n /** `light`, `dark`, `hc` or `auto` (the system's light or dark), passed on as `data-theme`. */\n declare theme: ThemeSetting | null;\n /**\n * The policy the preview plays under: the one the host's students get, when it offers less than practice (no hints,\n * no check of one interaction). Null: `PRACTICE_POLICY`. A change plays a shown preview again.\n */\n declare previewPolicy: AttemptPolicy | null;\n /**\n * The editor the kit drives. Default: TipTap, on a surface this element creates when it first renders without an\n * adapter and without a `slot=\"surface\"` child. Setting another adapter swaps the editor; null brings the TipTap\n * surface back (with its document), unless a `slot=\"surface\"` child is there.\n */\n declare adapter: EditorAdapter | null;\n\n /** A value set while there is no adapter to take it. */\n #pending: string | null = null;\n /** Whether this element uses the built-in surface: decided when it first connects. */\n #builtIn: boolean | null = null;\n #surface: Surface | null = null;\n #opening = false;\n #failed = false;\n /**\n * The status line's message until the next edit: why a pasted or dropped picture was not inserted (no upload), or\n * the page an edit added or joined.\n */\n #notice: Notice | null = null;\n /** The page or block the surface's edit changed, waiting for that edit's change event, which shows it. */\n #pageNotice: Notice | null = null;\n /** Counts notices: the same message again is a new one for screen readers. */\n #notices = 0;\n /** The adapter the last ready event was for. */\n #readyFor: EditorAdapter | null = null;\n #resolveReady: () => void = () => {};\n readonly #ready: Promise<void> = new Promise((resolve) => {\n this.#resolveReady = resolve;\n });\n\n /** What the surface asks about pictures: the picture dialog of this element. */\n #pictures = {\n ask: (request: Parameters<AstlPictureDialog['ask']>[0]) =>\n this.renderRoot.querySelector<AstlPictureDialog>('astl-picture-dialog')?.ask(request) ??\n Promise.resolve(null),\n refuse: () => {\n this.#notice = { key: 'picture.pasteRefused' };\n this.requestUpdate();\n },\n style: (kind: 'picture' | 'figure' | 'component') => {\n void this.renderRoot.querySelector<AstlToolbar>('astl-toolbar')?.openStyle(kind);\n },\n };\n\n /** What the surface tells of pages and blocks: a page added, joined or deleted, a block moved or deleted. */\n #pages = (change: SurfaceChange) => {\n this.#pageNotice = change;\n };\n\n /** Whether the host's `start` and `end` slots have elements: a column exists only while its slot does. */\n #slotted = { start: false, end: false };\n #slotChange = (event: Event): void => {\n const slot = event.target as HTMLSlotElement;\n const name = slot.name === 'end' ? 'end' : 'start';\n const has = slot.assignedElements().length > 0;\n if (this.#slotted[name] === has) return;\n this.#slotted[name] = has;\n this.requestUpdate();\n };\n\n /**\n * The source view: the value laid out for reading when it opened (null until it shows), the author's text once they\n * type (null before), and the errors that kept it there.\n */\n #shown: string | null = null;\n #draft: string | null = null;\n #errors: readonly Issue[] = [];\n /** What the status line counts, a moment after each change. */\n #outline: Outline | null = null;\n #counting: ReturnType<typeof setTimeout> | undefined;\n #authoring: { readonly key: string; readonly authoring: Authoring } | null = null;\n #subscription: { readonly adapter: EditorAdapter; readonly off: () => void } | null = null;\n\n constructor() {\n super();\n this.locale = null;\n this.components = null;\n this.featured = null;\n this.panels = null;\n this.view = 'visual';\n this.views = null;\n this.theme = 'auto';\n this.previewPolicy = null;\n this.adapter = null;\n // A value set before the element was defined is an own property that hides the accessor.\n if (Object.hasOwn(this, 'value')) {\n const value: unknown = (this as { value?: unknown }).value;\n delete (this as { value?: unknown }).value;\n if (typeof value === 'string') this.value = value;\n }\n }\n\n /** The source HTML (`<astl-doc>`): the adapter's, or a value waiting for it, or an empty document. */\n get value(): string {\n return (\n this.adapter?.getSource() ?? this.#pending ?? `<astl-doc lang=\"${this.authoring.locale}\"></astl-doc>`\n );\n }\n\n set value(source: string) {\n if (this.adapter === null) this.#pending = source;\n else this.adapter.setSource(source);\n }\n\n /**\n * Resolves when the editor is first ready: its surface loaded (or the host's `adapter` set) and the value in place,\n * so `adapter`, `authoring` and `value` are usable. Each time an editor becomes ready (again after a swap or a\n * reconnect, with a new `adapter`), `astl-editor-ready` fires (bubbles, composed).\n */\n get ready(): Promise<void> {\n return this.#ready;\n }\n\n /**\n * Compiles the current value and plays it in the preview, as the preview's own button does. Resolves when it plays,\n * or shows why it cannot.\n */\n async preview(): Promise<void> {\n await this.updateComplete;\n await this.renderRoot.querySelector<AstlPreview>('astl-preview')?.refresh();\n }\n\n /** The kit's logic, built from the registrations, the UI locale and `components`. */\n get authoring(): Authoring {\n const r = current();\n const locale = this.#uiLocale(r);\n // The property also takes the attribute's form, a space-separated string.\n const given = this.components as readonly string[] | string | null;\n const allowed = typeof given === 'string' ? given.split(/\\s+/).filter((tag) => tag !== '') : given;\n const key = `${r.version}\\n${locale}\\n${allowed === null ? '*' : allowed.join(' ')}`;\n if (this.#authoring?.key !== key) this.#authoring = { key, authoring: authoringFor(r, locale, allowed) };\n return this.#authoring.authoring;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n connected.add(this);\n // Back in the document: the built-in surface again. The first decision waits for the first update, when Lit has\n // applied the properties set before the element was defined (an `adapter`).\n if (this.#builtIn === true) void this.#open();\n this.#subscribe();\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n connected.delete(this);\n clearTimeout(this.#counting);\n this.#readyFor = null;\n this.#subscribe();\n // ProseMirror listens on the document: a removed editor is destroyed, its source kept for a reconnect.\n const surface = this.#surface;\n if (surface === null) return;\n this.#pending = surface.adapter.getSource();\n surface.destroy();\n this.#surface = null;\n this.adapter = null;\n }\n\n /** The host's views: the element's, else the registered ones. */\n #hostViews(): readonly EditorHostView[] {\n const views = this.views ?? current().views;\n return Array.isArray(views) ? views : [];\n }\n\n /** The editor's own views: without `source` when the surface edits the source as text. */\n #ownViews(): readonly string[] {\n return this.adapter?.editsSource === true ? ['visual'] : OWN_VIEWS;\n }\n\n /** The view on show: `view` when it names one, else `visual`. */\n #view(): string {\n const names = [...this.#ownViews(), ...this.#hostViews().map((v) => v.name)];\n return names.includes(this.view) ? this.view : 'visual';\n }\n\n /**\n * Applies the source view's text, unless it has errors: then they show and the editor stays there. Only text that\n * says something else than what was shown is applied (laid out the same, it is the same document): looking changes\n * nothing.\n */\n #leaveSource(): boolean {\n const text = this.#draft ?? this.#shown ?? this.value;\n const errors = this.authoring.validate(text).issues.filter((issue) => issue.severity === 'error');\n this.#errors = errors;\n if (errors.length > 0) {\n this.#notice = { key: 'view.sourceErrors', params: { n: errors.length } };\n this.#notices++;\n return false;\n }\n if (this.#draft !== null && sourceViews?.formatHtml(this.#draft) !== this.#shown)\n this.value = this.#draft;\n this.#draft = null;\n return true;\n }\n\n /** Counts the document for the status line, after `delay` ms. */\n #count(delay: number): void {\n clearTimeout(this.#counting);\n this.#counting = setTimeout(() => {\n const adapter = this.adapter;\n this.#outline = adapter === null ? null : this.authoring.outline(adapter.getSource());\n this.requestUpdate();\n }, delay);\n }\n\n protected override willUpdate(changed: PropertyValues<this>): void {\n if (changed.has('theme')) this.dataset.theme = this.#theme();\n // A surface that edits the source has no source view to leave or to load.\n if (changed.has('view') && this.adapter?.editsSource !== true) {\n const before = changed.get('view');\n if (before === 'source' && this.view !== 'source' && !this.#leaveSource()) this.view = 'source';\n else if (this.view === 'source' && before !== 'source') {\n this.#shown = this.#draft = null;\n this.#errors = [];\n if (sourceViews === null) {\n import('./source-view.js').then(\n (module) => {\n sourceViews = module;\n this.requestUpdate();\n },\n (error: unknown) => console.error(error),\n );\n }\n }\n }\n const surface = this.#surface;\n if (surface !== null && this.adapter !== surface.adapter) {\n // Another editor plugged in, or none (null): the built-in one goes, keeping its document for a comeback.\n if (this.adapter === null) this.#pending = surface.adapter.getSource();\n surface.destroy();\n this.#surface = null;\n }\n if (this.adapter !== null && this.#surface === null) {\n this.#builtIn = false;\n if (this.#pending !== null) this.adapter.setSource(this.#pending);\n this.#pending = null;\n } else if (this.adapter === null && this.#surface === null) {\n // The first update, or the host took its editor away: the built-in surface, unless one is in the slot.\n if (this.isConnected && (this.#builtIn === null || changed.has('adapter'))) this.#decide();\n } else if (this.#surface !== null && surfaces !== null && this.#surface.authoring !== this.authoring) {\n // Other labels or other types: the same document in a new editor.\n const source = this.#surface.adapter.getSource();\n this.#surface.destroy();\n this.#surface = surfaces.createSurface(\n this,\n this.authoring,\n current().engine.manifests,\n source,\n this.#pictures,\n this.#pages,\n );\n this.adapter = this.#surface.adapter;\n }\n this.#subscribe();\n }\n\n protected override updated(changed: PropertyValues<this>): void {\n // The preview reads its theme when it renders.\n if (changed.has('theme')) this.renderRoot.querySelector<LitElement>('astl-preview')?.requestUpdate();\n const adapter = this.adapter;\n if (adapter !== null && adapter !== this.#readyFor && this.isConnected) {\n this.#readyFor = adapter;\n this.#count(0);\n this.#resolveReady();\n this.dispatchEvent(new Event(READY, { bubbles: true, composed: true }));\n }\n const before = changed.get('view');\n if (changed.has('view') && before !== undefined && before !== this.view) {\n this.dispatchEvent(\n new CustomEvent(VIEW, { detail: { view: this.view }, bubbles: true, composed: true }),\n );\n }\n }\n\n #decide(): void {\n // An element the HTML parser is still filling may not have its slot=\"surface\" child yet.\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => this.requestUpdate('adapter'), { once: true });\n return;\n }\n this.#builtIn = this.querySelector(':scope > [slot=\"surface\"]') === null;\n if (this.#builtIn) void this.#open();\n }\n\n async #open(): Promise<void> {\n if (this.#opening || this.#surface !== null) return;\n this.#opening = true;\n this.#failed = false;\n try {\n surfaces ??= await import('./surface.js');\n if (!this.isConnected || !this.#builtIn || this.adapter !== null || this.#surface !== null) return;\n this.#surface = surfaces.createSurface(\n this,\n this.authoring,\n current().engine.manifests,\n this.value,\n this.#pictures,\n this.#pages,\n );\n this.#pending = null;\n this.adapter = this.#surface.adapter;\n } catch (error) {\n // A failed chunk load is not cached by every browser: the next connect tries again.\n this.#failed = true;\n console.error(error);\n } finally {\n this.#opening = false;\n this.requestUpdate();\n }\n }\n\n #subscribe(): void {\n const adapter = this.isConnected ? this.adapter : null;\n if ((this.#subscription?.adapter ?? null) === adapter) return;\n this.#subscription?.off();\n this.#subscription =\n adapter === null\n ? null\n : {\n adapter,\n off: adapter.onChange(() => {\n const notice = this.#pageNotice;\n this.#pageNotice = null;\n if (this.#notice !== null || notice !== null) {\n this.#notice = notice;\n if (notice !== null) this.#notices++;\n this.requestUpdate();\n }\n this.#count(COUNT_DELAY_MS);\n this.dispatchEvent(new Event(CHANGE, { bubbles: true, composed: true }));\n }),\n };\n }\n\n #uiLocale(r: Registered): string {\n const requested = this.locale\n ? [this.locale]\n : this.lang\n ? [this.lang]\n : [...(navigator.languages ?? []), navigator.language].filter((l) => !!l);\n const available = [...editorMessages, ...r.catalogs]\n .filter((c) => c.namespace === EDITOR_NAMESPACE)\n .map((c) => c.locale);\n return negotiateLocale(requested, [...new Set(available)], 'en');\n }\n\n #theme(): ThemeSetting {\n const theme = this.theme;\n return theme !== null && THEMES.includes(theme) ? theme : 'auto';\n }\n\n protected override render(): TemplateResult {\n const { authoring, adapter } = this;\n const theme = this.#theme();\n const waiting: Notice | null = this.#failed\n ? { key: 'surface.failed' }\n : this.#builtIn && adapter === null\n ? { key: 'surface.loading' }\n : this.#notice;\n const lang = authoring.locale;\n // Given as a string (the attribute's form) or a list.\n const list = (value: readonly string[] | string | null) =>\n typeof value === 'string' ? value.split(/\\s+/).filter((name) => name !== '') : value;\n const featured = list(this.featured) ?? current().featured;\n const panels = (list(this.panels) ?? PANELS).filter((name) => PANELS.includes(name));\n const icons = new Set([\n ...KIT_ICONS,\n ...authoring.descriptors.flatMap((d) => [d.icon, ...(d.templates ?? []).map((t) => t.icon ?? d.icon)]),\n ]);\n const exported = [\n 'toolbar: toolbar-bar',\n 'button: toolbar-button',\n 'icon-button: toolbar-icon-button',\n 'views: toolbar-views',\n 'view: toolbar-view',\n 'separator: toolbar-separator',\n 'icon: toolbar-icon',\n 'insert',\n 'menu: insert-menu',\n 'style-menu',\n 'style-colors',\n 'style-panel',\n ]\n .concat([...icons].map((name) => `icon-${name}`))\n .join(', ');\n const panel = (name: string) =>\n name === 'issues'\n ? html`<astl-issues part=\"issues\" data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-issues>`\n : html`<astl-inspector part=\"inspector\" exportparts=${INSPECTOR_PARTS} data-theme=${theme} .authoring=${authoring} .adapter=${adapter}></astl-inspector>`;\n const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);\n const view = this.#view();\n // A surface that edits the source as text is the HTML already: its one view takes the HTML view's name and\n // description, as it makes that view needless.\n const views: ToolbarView[] = [\n ...this.#ownViews().map((name) => {\n const shown = adapter?.editsSource === true ? 'source' : name;\n return { name, label: t(`view.${shown}`), description: t(`view.${shown}Hint`) };\n }),\n ...this.#hostViews(),\n ];\n // The toolbar spans the editor, as a word processor's: above the text and the side column.\n // Another view takes the surface's place, without the side column; the notice line stays, the one live region.\n const away = view !== 'visual';\n return html`<div class=${panels.length === 0 || away ? 'layout solo' : 'layout'}>\n <astl-toolbar part=\"toolbar\" exportparts=${exported} data-theme=${theme} .authoring=${authoring}\n .adapter=${adapter} .featured=${featured} .views=${views} .view=${view}\n @astl-toolbar-view=${(event: CustomEvent<{ view: string }>) => {\n this.view = event.detail.view;\n }}></astl-toolbar>\n ${this.#statusLine()}\n <div class=\"work\" part=\"work\">\n <div class=\"start\" part=\"start\" ?hidden=${away || !this.#slotted.start}>\n <slot name=\"start\" @slotchange=${this.#slotChange}></slot>\n </div>\n <div class=\"surface\" part=\"surface\">\n ${away ? nothing : html`<slot name=\"surface\"></slot>`}\n ${view === 'source' ? this.#source() : away ? html`<slot name=\"view-${view}\"></slot>` : nothing}\n <p class=${waiting === null ? 'status idle' : 'status'} role=\"status\" lang=${lang} dir=${directionOf(lang)}\n >${keyed(this.#notices, waiting === null ? '' : authoring.t(EDITOR_NAMESPACE, waiting.key, waiting.params))}</p>\n <astl-picture-dialog data-theme=${theme} .authoring=${authoring}></astl-picture-dialog>\n </div>\n ${panels.length === 0 ? nothing : html`<div class=\"side\" part=\"side\" ?hidden=${away}>${panels.map(panel)}</div>`}\n <div class=\"end\" part=\"end\" ?hidden=${away || !this.#slotted.end}>\n <slot name=\"end\" @slotchange=${this.#slotChange}></slot>\n </div>\n </div>\n <astl-preview part=\"preview\" data-theme=${theme} .authoring=${authoring} .adapter=${adapter}\n .policy=${this.previewPolicy ?? PRACTICE_POLICY}></astl-preview>\n </div>`;\n }\n\n /**\n * The status line (`part=\"status-line\"`): how many elements and points the document has, then \"Ready to share\" or\n * its errors and warnings. Text to read, not a live region: the notice line stays the editor's one.\n */\n #statusLine(): TemplateResult | typeof nothing {\n const outline = this.#outline;\n if (outline === null) return nothing;\n const { authoring } = this;\n const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);\n const elements = outline.pages.reduce((n, page) => n + page.components.length, 0);\n const ready = outline.errors === 0;\n const lang = authoring.locale;\n return html`<p class=\"status-line\" part=\"status-line\" lang=${lang} dir=${directionOf(lang)}>\n <span class=\"counts\"><span>${t('status.elements', { n: elements })}</span>${\n outline.points === null\n ? nothing\n : html`<span>${t('surface.points', { points: outline.points })}</span>`\n }</span>\n <span class=${ready ? 'ready' : 'counts error'}>${\n ready\n ? t('status.ready')\n : html`<span>${t('status.errors', { n: outline.errors })}</span><span>${t('status.warnings', { n: outline.warnings })}</span>`\n }</span>\n </p>`;\n }\n\n /**\n * The source view (`source-view.ts`, nothing until its module has loaded), with the value laid out for reading once\n * per opening.\n */\n #source(): TemplateResult | typeof nothing {\n const views = sourceViews;\n if (views === null) return nothing;\n this.#shown ??= views.formatHtml(this.value);\n return views.renderSource(\n this.renderRoot,\n this.authoring,\n this.#draft ?? this.#shown,\n this.#errors,\n (text) => {\n this.#draft = text;\n },\n );\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'astl-editor': AstlEditor;\n }\n interface HTMLElementEventMap {\n 'astl-editor-change': Event;\n 'astl-editor-ready': Event;\n }\n}\n","import type { EditorDescriptor, EngineOptions, MessageCatalog } from '@astl/core';\nimport {\n defineAuthoringElements,\n type EditorFont,\n type EditorStylePreset,\n type PickPicture,\n type UploadAsset,\n} from '@astl/editor';\nimport type { ElementEntry } from '@astl/player';\nimport { AstlEditor, register } from './element.js';\n\n/** The same option names, types and meanings as `createEngine` and `definePlayer`; the editor makes its own secret. */\nexport interface DefineEditorOptions extends Omit<EngineOptions, 'secret'> {\n /** Insert menu and inspector entries: one per type authors can add. */\n readonly editors: readonly EditorDescriptor[];\n /** Player elements for the preview, eager or lazy. */\n readonly elements: readonly ElementEntry[];\n /**\n * Stores a picture file and returns its address (it must pass `urlPolicy`): the picture dialog, pasted and dropped\n * pictures and picture fields use it. Without it, pictures are added by address only (or from `pickPicture`).\n * Reject with `UploadRefused` to tell the author why.\n */\n readonly uploadAsset?: UploadAsset;\n /**\n * Opens the host's own picture library and gives the chosen picture (its address must pass `urlPolicy`), or null:\n * the picture dialog and picture fields offer it beside the upload. The picture dialog closes while the library is\n * open, keeping what the author typed, so a modal of the host's own takes the pointer and the keys.\n */\n readonly pickPicture?: PickPicture;\n /**\n * Catalogs only the insert menus show (their one-line descriptions), loaded when a menu first opens;\n * `@astl/astrolabe` passes the built-in ones. Default: none (the menus show the names alone).\n */\n readonly menuMessages?: () => Promise<readonly MessageCatalog[]>;\n /**\n * The fonts the toolbar and the style form offer, in order: a name and a CSS stack the style allow-list keeps (any\n * other throws). A later call's list replaces it. Default: `DEFAULT_FONTS`, stacks every system has.\n */\n readonly fonts?: readonly EditorFont[];\n /**\n * The ready styles the style menu and the style form offer, in order; `[]`: none. A name `isStyleName` refuses, a\n * declaration the style allow-list refuses or a name given twice throws. A later call's list replaces it. Default:\n * `DEFAULT_STYLES`.\n */\n readonly styles?: readonly EditorStylePreset[];\n /** Default: the global `customElements`. */\n readonly registry?: CustomElementRegistry;\n /**\n * The toolbar's featured inserts, as buttons before \"Elements\": component tags, `tag:template` for a named starter,\n * and `text`, `picture`, `page-break`. A later call's list replaces it; an element's `featured` overrides it.\n * Default: none.\n */\n readonly featured?: readonly string[];\n /**\n * The host's views, after \"Visual\" and \"HTML\" in the view switch: each shows the host's content in the slot\n * `view-<name>` in place of the editor. A later call's list replaces it; an element's `views` overrides it.\n * Default: none.\n */\n readonly views?: readonly EditorHostView[];\n}\n\n/** A host view of `<astl-editor>`: its name (lower-case letters, digits and dashes) and its label in the switch. */\nexport interface EditorHostView {\n readonly name: string;\n readonly label: string;\n}\n\nconst TAG = 'astl-editor';\n\n/**\n * Registers components, editor descriptors, preview elements and looks for every `<astl-editor>`, and defines\n * `<astl-editor>` and the kit elements (nothing is defined on import). A second call adds to the first; a tag or a look\n * name already registered by another object throws, as two copies would otherwise mix silently.\n */\nexport function defineEditor(options: DefineEditorOptions): void {\n const registry = options.registry ?? customElements;\n const existing = registry.get(TAG);\n if (existing !== undefined && existing !== AstlEditor)\n throw new Error(`<${TAG}> is already defined by another class`);\n // The kit first: if it throws, nothing is registered.\n defineAuthoringElements(registry);\n register(options);\n if (existing === undefined) registry.define(TAG, AstlEditor);\n}\n","/**\n * `@astl/astrolabe/editor`: `<astl-editor>` with every built-in component, editor descriptor, preview element\n * and look. Only the main entry of `@astl/editor-tiptap`, never its `/tiptap` entry: importing this module\n * never loads TipTap, which `<astl-editor>` imports on demand when it creates its own surface. Hosts that build\n * their own TipTap editor install `@astl/editor-tiptap` and take `astrolabeExtensions` and\n * `createTiptapAdapter` from its `/tiptap` entry.\n */\nimport { builtInDefinitions } from '@astl/components/definitions';\nimport { builtInEditors } from '@astl/components/editors';\nimport { builtInElements } from '@astl/components/elements';\nimport type { MessageCatalog } from '@astl/core';\nimport {\n createAuthoring,\n createTextareaAdapter,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n loadStyleElements,\n STYLE_OPEN,\n UploadRefused,\n} from '@astl/editor';\nimport { type DefineEditorOptions, defineEditor as defineBaseEditor } from '@astl/editor-tiptap';\nimport { builtInStyleTemplates, tokens, tokensCss } from '@astl/tokens';\n\nexport * from '@astl/core';\nexport type {\n AstlStyleForm,\n AstlStyleRules,\n Authoring,\n AuthoringOptions,\n DescribeOptions,\n EditorFont,\n EditorStylePreset,\n Outline,\n OutlineBlock,\n OutlineComponent,\n OutlinePage,\n PickPicture,\n PreviewOptions,\n PreviewResult,\n StyleOpen,\n TextareaAdapter,\n UploadAsset,\n UploadedAsset,\n} from '@astl/editor';\nexport type { DefineEditorOptions } from '@astl/editor-tiptap';\nexport { AstlEditor } from '@astl/editor-tiptap';\n// `tokensCss`: the --astl-* tokens for the page around the editor, with the same themes.\n// `createAuthoring`: the kit's logic without the element (validate, outline, preview), Node-safe.\n// `UploadRefused`: what a host's upload or picture library rejects with to tell the author why.\n// `DEFAULT_FONTS` and `DEFAULT_STYLES`: the `fonts` and `styles` defaults, to extend. `loadStyleElements`: for a host\n// that places `<astl-style-form>` or `<astl-style-rules>` itself. `STYLE_OPEN`: the event of a request for them.\nexport {\n builtInDefinitions,\n builtInEditors,\n builtInElements,\n builtInStyleTemplates,\n createAuthoring,\n createTextareaAdapter,\n DEFAULT_FONTS,\n DEFAULT_STYLES,\n loadStyleElements,\n STYLE_OPEN,\n tokensCss,\n UploadRefused,\n};\n\n/**\n * The toolbar's default featured inserts: none, every component and starter is under \"Elements\" and \"Templates\".\n * `featured` replaces it.\n */\nexport const DEFAULT_FEATURED: readonly string[] = [];\n\n/** The built-ins' insert menu descriptions, imported when a menu first opens. */\nconst loadMenuMessages = async (): Promise<readonly MessageCatalog[]> =>\n (await import('@astl/components/menu-messages')).builtInMenuMessages;\n\n/**\n * Defines `<astl-editor>` with `components: builtInDefinitions`, `styleTemplates: builtInStyleTemplates`, the light\n * theme's `groundColors` (what an author sees while writing),\n * the built-ins' `menuMessages` and `featured: DEFAULT_FEATURED`, and as `editors` and `elements` the built-in entries of the `components` tags (so a\n * subset of components brings its own editors and elements). An option replaces its default (extend with\n * `[...builtInDefinitions, mine]`); a second call adds.\n */\nexport function defineEditor(options: Partial<DefineEditorOptions> = {}): void {\n const components = options.components ?? builtInDefinitions;\n const tags = new Set(components.map((definition) => definition.manifest.tag));\n const { surface, ink } = tokens.themes.light;\n defineBaseEditor({\n styleTemplates: builtInStyleTemplates,\n groundColors: { surface, ink },\n featured: DEFAULT_FEATURED,\n menuMessages: loadMenuMessages,\n ...options,\n components,\n editors: options.editors ?? builtInEditors.filter((editor) => tags.has(editor.manifest.tag)),\n elements: options.elements ?? builtInElements.filter((element) => tags.has(element.tag)),\n });\n}\n","/**\n * astrolabe-editor.js, for authoring pages: `@astl/astrolabe/editor`, defined on load with every built-in\n * component, editor descriptor, preview element and look. TipTap is a chunk of its own, fetched only when an\n * `<astl-editor>` without an adapter and without a `slot=\"surface\"` child connects; the bundle check keeps it out of\n * the first load.\n */\nimport { defineEditor } from '../editor.js';\n\ndefineEditor();\n\nexport * from '../editor.js';\n"],"ignoreList":[31],"mappings":"A,kiGAKA,IAAaiN,GAAgC,CAC3C,SAAUtD,GACV,SAAUpI,EACV,MAAO,eACP,YAAa,qBACb,KAAM,eACN,SAAU,QACV,SACE,iIAEF,OAAQ,CACN,CAAE,KAAM,YAAa,KAAM,QAAS,MAAO,eAAgB,KAAM,kBAAmB,EACpF,CAAE,KAAM,YAAa,KAAM,MAAO,MAAO,aAAc,KAAM,iBAAkB,OAAQ,SAAU,EACjG,CACE,KAAM,YACN,IAAK,kBACL,MAAO,oBACP,KAAM,wBACN,UAAW,EACb,CACF,CACF,ECtBa2L,GAAkC,CAC7C,SAAUtD,GACV,SAAUhH,GACV,MAAO,eACP,YAAa,qBACb,KAAM,OACN,SAAU,UACV,SAAU,iFACV,OAAQ,CAAC,CAAE,KAAM,YAAa,KAAM,OAAQ,MAAO,aAAc,CAAC,CACpE,ECTauK,GAAqC,CAChD,SAAUtD,GACV,SAAUnI,EACV,MAAO,eACP,YAAa,qBACb,KAAM,SACN,SAAU,MACV,SACE,keAOF,UAAW,CACT,CACE,GAAI,mBACJ,MAAO,sBACP,YAAa,4BACb,SACE,okBAQJ,CACF,EACA,OAAQ,CACN,CACE,KAAM,eACN,IAAK,YACL,UAAW,WACX,QAAS,gBACT,MAAO,wBACP,KAAM,2BACR,EAEA,CACE,KAAM,cACN,IAAK,gBACL,QAAS,CAAC,CAAE,UAAW,UAAW,MAAO,gBAAiB,CAAC,EAC3D,MAAO,gBACP,KAAM,mBACR,EACA,CAAE,KAAM,YAAa,KAAM,UAA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