wicked-studio 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,161 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="wicked-editor" content="wicked-doc">
6
+ <meta name="wicked-editor-version" content="0.9.1">
7
+ <title>Document</title>
8
+ <style>
9
+ /* The plugin's own chrome takes the host's tokens (`host.hello.theme` / `host.theme`), with plain
10
+ fallbacks for a host that passes none. The PAGE inside the nested frame styles itself. */
11
+ :root {
12
+ --surface-base: #ffffff; --surface-card: #f6f7f9; --ink-high: #0d1117; --ink-muted: #5b6673;
13
+ --border: #d5dae1; --accent: #224a5e; --status-fail: #b4232c; --font-sans: system-ui, sans-serif;
14
+ }
15
+ html, body { height: 100%; margin: 0; }
16
+ body { font: 13px var(--font-sans); color: var(--ink-high); background: var(--surface-base); overflow: hidden; }
17
+ .editor { position: relative; width: 100%; height: 100%; outline: none; }
18
+ .editor:focus { box-shadow: inset 0 0 0 2px var(--accent); }
19
+ .stage { position: absolute; inset: 0; }
20
+ /* The page is a document: one with no background of its own is drawn on white, as a browser would, whatever the host theme. */
21
+ .frame { display: block; width: 100%; height: 100%; border: 0; background: #ffffff; }
22
+ body[data-size="inline"] .editor:not([data-mode="simple"]):not([data-mode="advanced"]) { pointer-events: none; }
23
+ /* Protocol 2: the Style tab (the options instance). */
24
+ .style-pane { height: 100%; overflow: auto; box-sizing: border-box; padding: 12px; background: var(--surface-base); color: var(--ink-high); }
25
+ .box { position: absolute; pointer-events: none; border: 2px solid var(--accent); border-radius: 3px; box-sizing: border-box; }
26
+ .box--hover { border-style: dashed; opacity: .55; }
27
+ .handle { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; }
28
+ .input { position: absolute; box-sizing: border-box; font: inherit; line-height: 1.35; padding: 4px 6px; border: 2px solid var(--accent); border-radius: 3px; background: var(--surface-base); color: var(--ink-high); outline: none; z-index: 2; resize: none; overflow: auto; }
29
+ .hint, .note { position: absolute; left: 8px; bottom: 8px; margin: 0; padding: 2px 8px; font-size: 12px; color: var(--ink-muted); background: var(--surface-card); border: 1px solid var(--border); border-radius: 4px; pointer-events: none; max-width: calc(100% - 32px); }
30
+ .note { color: var(--status-fail); }
31
+ /* EP-P3: the width header and the picked element's peek. */
32
+ .tools { position: absolute; z-index: 2; left: 0; right: 0; top: 0; height: 34px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 8px; border-bottom: 1px solid var(--border); background: var(--surface-card); }
33
+ .tools button, .peek button { font: inherit; font-size: 12px; line-height: 20px; padding: 1px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-base); color: var(--ink-high); cursor: pointer; }
34
+ .tools button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
35
+ .tools button:focus-visible, .peek button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
36
+ .stage { overflow: hidden; }
37
+ .peek { position: absolute; z-index: 3; box-sizing: border-box; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; max-width: calc(100% - 8px); padding: 4px 6px; background: var(--surface-base); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
38
+ .peek .danger { color: var(--status-fail); }
39
+ .swatches { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 3px; min-width: 0; }
40
+ .swatches .word { font-size: 11px; color: var(--ink-muted); margin: 0 2px 0 4px; }
41
+ .peek .swatch { width: 20px; height: 20px; padding: 0; border-radius: 50%; background: var(--swatch, transparent); }
42
+ .peek .swatch--default { width: auto; height: auto; border-radius: 4px; padding: 1px 6px; font-size: 11px; }
43
+ [hidden] { display: none !important; }
44
+ @media (prefers-reduced-motion: no-preference) { .box { transition: left 80ms linear, top 80ms linear; } }
45
+ </style>
46
+ </head>
47
+ <body data-size="pane">
48
+ <script>var en=Object.defineProperty;var tn=(P,K,W)=>K in P?en(P,K,{enumerable:!0,configurable:!0,writable:!0,value:W}):P[K]=W;var at=(P,K,W)=>tn(P,typeof K!="symbol"?K+"":K,W);(function(){"use strict";const P=/^slide-(\d+)-([a-z-]+)-(\d+)$/,K=/^section-(\d+)$/,W={heading:"heading",paragraph:"paragraph","list-item":"list item",quote:"quote",caption:"caption",cell:"table cell",link:"link",button:"button",image:"image",block:"block",text:"line"},lt=/^[A-Za-z]{2,}(?:[-_ ][A-Za-z]{2,})*$/;function ee(n,o){const s=P.exec(n);if(s!==null){const l=Number(s[1]),f=W[s[2]??""]??(s[2]??"").replace(/-+/g," "),c=Number(s[3]);return o==="deck"?`slide ${l+1}’s ${f==="heading"&&c===1?"title":`${f} ${c}`}`:l===0?`${f} ${c}`:`${f} ${c} in section ${l+1}`}const r=K.exec(n);return r!==null?o==="deck"?`slide ${Number(r[1])+1}`:`section ${Number(r[1])+1}`:lt.test(n)?`the ${n.replace(/[-_]+/g," ").toLowerCase()}`:"this part"}function ct(n,o){const s=Object.entries(o).filter(([,r])=>!r.composite&&r.text!=="");return n.map(r=>{const l=r.reqId.trim();if(l==="")return{...r,wid:null};const f=s.find(([,c])=>dt(c.text,l));return{...r,wid:f===void 0?null:f[0]}})}const Pe=/[A-Za-z0-9_-]/,Xe=/[A-Za-z0-9]/;function dt(n,o){const s=n.toLowerCase(),r=o.toLowerCase();if(r==="")return!1;for(let l=s.indexOf(r);l!==-1;l=s.indexOf(r,l+1)){const f=s.charAt(l-1),c=s.charAt(l+r.length),h=Pe.test(f)||f==="."&&Xe.test(s.charAt(l-2)),x=Pe.test(c)||c==="."&&Xe.test(s.charAt(l+r.length+1));if(!h&&!x)return!0}return!1}function ut(n,o){const s=n.filter(l=>l.wid!==null).length,r=o>n.length?` (the first ${n.length} of ${o})`:"";return`${s} of ${n.length} named in this document${r}`}const pt={"Alt+J":{verb:"navigate",what:"next card or row"},"Alt+K":{verb:"navigate",what:"previous card or row"},"Alt+/":{verb:"navigate",what:"the keyboard shortcuts overlay"},"Alt+P":{verb:"navigate",what:"peek at the top item that needs you"},"Alt+G":{verb:"navigate",what:"jump to the top item that needs you"},"Alt+B":{verb:"navigate",what:"back to where you were"},"Alt+T":{verb:"navigate",what:"the run’s evidence timeline"},"Alt+U":{verb:"navigate",what:"the run’s unit list"},"Alt+A":{verb:"approve",what:"approve the open gate"},"Alt+R":{verb:"decide",what:"reject the open gate"},"Alt+X":{verb:"decide",what:"select a gate for batch resolution"},"Alt+N":{verb:"compose",what:"compose a steer note"}},ft=new Set(["Escape","Mod+K","Tab","Shift+Tab"]);function Ye(n){if(ft.has(n))return!0;const o=pt[ht(n)];return o!==void 0&&o.verb==="navigate"}function ht(n){const o=/^alt\+(.)$/i.exec(n);return o===null?n:`Alt+${o[1].toUpperCase()}`}function yt(n,o,s){return{left:n.left-(s.scrollX-o.scrollX),top:n.top-(s.scrollY-o.scrollY),width:n.width,height:n.height}}const mt=/^[A-Za-z0-9_.:-]{1,100}$/;function L(n){return typeof n=="number"&&isFinite(n)}function gt(n){if(typeof n!="object"||n===null)return!1;const o=n;return o.section!==void 0&&(typeof o.section!="string"||!mt.test(o.section))?!1:typeof o.text=="string"&&typeof o.composite=="boolean"}function vt(n){if(typeof n!="object"||n===null)return!1;const o=n;return L(o.x)&&L(o.y)&&L(o.width)&&L(o.height)&&L(o.top)&&L(o.left)&&L(o.right)&&L(o.bottom)}function bt(n){if(typeof n!="object"||n===null)return null;const o=n;if(o.v!==1)return null;const s=o.type;if(s==="wid-inventory"){const r=o.widMap,l=o.scrollX,f=o.scrollY;if(typeof r!="object"||r===null||!L(l)||!L(f))return null;const c={};for(const[D,S]of Object.entries(r)){if(!vt(S))return null;c[D]=S}const h=o.blocks;if(h===void 0)return{v:1,type:"wid-inventory",widMap:c,scrollX:l,scrollY:f};if(typeof h!="object"||h===null)return null;const x={};for(const[D,S]of Object.entries(h)){if(!gt(S))return null;x[D]={text:S.text,composite:S.composite,...S.cut===!0?{cut:!0}:{},...S.section!==void 0?{section:S.section}:{}}}return{v:1,type:"wid-inventory",widMap:c,scrollX:l,scrollY:f,blocks:x}}if(s==="scroll-state"){const r=o.scrollX,l=o.scrollY;return!L(r)||!L(l)?null:{v:1,type:"scroll-state",scrollX:r,scrollY:l}}if(s==="scroll-ack"){const r=o.wid;if(typeof r!="string"||r==="")return null;const l=o.scrollX,f=o.scrollY,c=o.seq;return{v:1,type:"scroll-ack",wid:r,...L(l)&&L(f)?{scrollX:l,scrollY:f}:{},...typeof c=="number"&&Number.isInteger(c)&&c>0?{seq:c}:{}}}if(s==="wid-click"){const r=o.wid;return typeof r!="string"||r===""?null:{v:1,type:"wid-click",wid:r}}if(s==="wid-hover"){const r=o.wid;return r!==null&&(typeof r!="string"||r==="")?null:{v:1,type:"wid-hover",wid:r}}return null}const wt=Object.freeze({v:1,type:"request-inventory"});function kt(n,o){return o===void 0?{v:1,type:"scroll-to-wid",wid:n}:{v:1,type:"scroll-to-wid",wid:n,seq:o}}const xt="request-inventory";function At(n){return n.includes(xt)}const Et=`
49
+ (function () {
50
+ if (window.__wickedInstrumentBridge) return;
51
+ window.__wickedInstrumentBridge = 1;
52
+ function nearest(node) {
53
+ var el = node;
54
+ while (el) {
55
+ if (el.getAttribute && el.getAttribute('data-wid')) return el;
56
+ el = el.parentElement;
57
+ }
58
+ return null;
59
+ }
60
+ function inventory() {
61
+ var widMap = {};
62
+ var blocks = {};
63
+ var nodes = document.querySelectorAll('[data-wid]');
64
+ for (var i = 0; i < nodes.length; i++) {
65
+ var el = nodes[i];
66
+ var wid = el.getAttribute('data-wid');
67
+ var r = el.getBoundingClientRect();
68
+ widMap[wid] = { x: r.x, y: r.y, width: r.width, height: r.height,
69
+ top: r.top, left: r.left, right: r.right, bottom: r.bottom };
70
+ var text = (el.textContent || '').replace(/\\s+/g, ' ').trim();
71
+ var composite = el.querySelector('[data-wid]') !== null;
72
+ var cap = composite ? 400 : 20000;
73
+ blocks[wid] = { text: text.length > cap ? text.slice(0, cap) : text, composite: composite };
74
+ if (text.length > cap) blocks[wid].cut = true;
75
+ var sec = el.parentElement ? el.parentElement.closest('section[data-wid], [data-wid^="section-"]') : null;
76
+ var secWid = sec ? sec.getAttribute('data-wid') : null;
77
+ // Only an id the parent's parser accepts: an odd one would invalidate the whole inventory.
78
+ if (secWid && /^[A-Za-z0-9_.:-]{1,100}$/.test(secWid)) blocks[wid].section = secWid;
79
+ }
80
+ return { v: 1, type: 'wid-inventory', widMap: widMap, blocks: blocks,
81
+ scrollX: window.scrollX, scrollY: window.scrollY };
82
+ }
83
+ function post(msg) { parent.postMessage(msg, '*'); }
84
+ window.addEventListener('message', function (e) {
85
+ var m = e.data;
86
+ if (!m || m.v !== 1) return;
87
+ if (m.type === 'request-inventory') {
88
+ post(inventory());
89
+ } else if (m.type === 'scroll-to-wid' && typeof m.wid === 'string') {
90
+ var el = document.querySelector('[data-wid="' + m.wid.replace(/["\\\\]/g, '') + '"]');
91
+ // An instant jump, whatever the document's own scroll-behavior: the position read on the
92
+ // next line is then where it landed.
93
+ if (el && el.scrollIntoView) el.scrollIntoView({ block: 'center', behavior: 'instant' });
94
+ post({ v: 1, type: 'scroll-ack', wid: m.wid, seq: m.seq, scrollX: window.scrollX, scrollY: window.scrollY });
95
+ }
96
+ });
97
+ document.addEventListener('scroll', function (e) {
98
+ if (e.target === document || e.target === document.documentElement || e.target === document.body) {
99
+ post({ v: 1, type: 'scroll-state', scrollX: window.scrollX, scrollY: window.scrollY });
100
+ } else {
101
+ post(inventory());
102
+ }
103
+ }, { passive: true, capture: true });
104
+ window.addEventListener('resize', function () { post(inventory()); });
105
+ document.addEventListener('click', function (e) {
106
+ var el = nearest(e.target);
107
+ if (!el) return;
108
+ e.preventDefault();
109
+ post({ v: 1, type: 'wid-click', wid: el.getAttribute('data-wid') });
110
+ });
111
+ var lastHover = null;
112
+ document.addEventListener('mousemove', function (e) {
113
+ var el = nearest(e.target);
114
+ var wid = el ? el.getAttribute('data-wid') : null;
115
+ if (wid !== lastHover) {
116
+ lastHover = wid;
117
+ post({ v: 1, type: 'wid-hover', wid: wid });
118
+ }
119
+ });
120
+ if (document.readyState === 'loading') {
121
+ document.addEventListener('DOMContentLoaded', function () { post(inventory()); });
122
+ } else {
123
+ post(inventory());
124
+ }
125
+ })();
126
+ `;function $t(n){const o=`<script>${Et}<\/script>`;return/<\/body>/i.test(n)?n.replace(/<\/body>/i,()=>`${o}</body>`):`${n}${o}`}const H=String.raw`\s*-?(?:\d+(?:\.\d+)?|\.\d+)%?\s*`,Ct=new RegExp(`^(?:#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\((?:${H},){2}${H}(?:,${H})?\\)|hsla?\\(\\s*-?\\d+(?:\\.\\d+)?(?:deg)?\\s*,${H},${H}(?:,${H})?\\)|var\\(--wi-[a-z0-9-]{1,40}\\)|revert-layer)$`,"i");function St(n,o=new Set){if(!Ct.test(n))return!1;const s=/^var\((--wi-[a-z0-9-]+)\)$/i.exec(n);return s===null||o.has(s[1].toLowerCase())}const Tt=[["--wi-bg","Background"],["--wi-surface","Surface"],["--wi-card-bg","Card"],["--wi-primary","Primary"],["--wi-secondary","Secondary"],["--wi-accent","Accent"],["--wi-text","Text"],["--wi-text-secondary","Secondary text"],["--wi-muted","Muted"],["--wi-border","Border"]],Ae="revert-layer";function Ot(n){const o=new Map;for(const l of n.matchAll(/(--wi-[a-z-]{1,40})\s*:\s*([^;}{]{1,80})/gi))o.set(l[1].toLowerCase(),l[2].trim());const s=new Set,r=[];for(const[l,f]of Tt){const c=o.get(l);if(c===void 0)continue;const h=c.startsWith("#")?c.toLowerCase():c;!St(h)||s.has(h.toLowerCase())||(s.add(h.toLowerCase()),r.push({token:l,value:h,label:f}))}return r}const te="wicked.editor",ne=1,We=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),Lt=["card","options","full"];function Mt(n){return n==="inline"?"card":n==="pane"?"options":"full"}function Bt(n){return n==="card"?"inline":n==="options"?"pane":"full"}function Ft(n){const o=We(n)?n:{},s=o.size==="inline"||o.size==="full"?o.size:"pane",r=o.protocol===2?2:1,l=r===2&&typeof o.tab=="string"?o.tab:null,f=r===2&&Lt.includes(o.surface)?o.surface:Mt(s),c=f==="options"&&l===null?"full":f,h=r===2&&(o.mode==="simple"||o.mode==="advanced")?o.mode:null;return{protocol:r,surface:c,tab:l,mode:h,size:s}}function _t(n,o,s){return{editor:n,version:o,protocol:[1,2],surfaces:s}}function Rt(n,o){const s=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:te,v:ne,type:"plugin.ready",payload:_t(n,s,o)},"*")}function zt(n,o,s){const r=n.metaKey||n.ctrlKey;let l=null;if(n.key==="Escape")l="Escape";else if(r&&!n.altKey&&n.key.toLowerCase()==="k")l="Mod+K";else if(n.altKey&&!r&&/^Key[A-Z]$/.test(n.code)&&Ye(`Alt+${n.code.slice(3)}`))l=`Alt+${n.code.slice(3)}`;else if(n.key==="Tab"){const f=Array.from(o.querySelectorAll("button, input, select, textarea, [tabindex]")).filter(h=>h.tabIndex>=0&&!h.matches(":disabled")&&h.closest("[hidden]")===null),c=f.indexOf(n.target);(n.shiftKey?c<=0:c===-1||c===f.length-1)&&(l=n.shiftKey?"Shift+Tab":"Tab")}return l===null?!1:(n.preventDefault(),n.stopPropagation(),s(l),!0)}class Dt{constructor(o,s){at(this,"revs",new Map);this.port=o,this.h=s}reply(o,s){this.port.postMessage({p:te,v:ne,re:o,ok:!0,payload:s})}refuse(o,s,r){this.port.postMessage({p:te,v:ne,re:o,ok:!1,error:{code:s,message:r}})}bump(o){const s=(this.revs.get(o)??0)+1;return this.revs.set(o,s),s}values(o,s){this.port.postMessage({p:te,v:ne,type:"options.values",payload:{tab:o,rev:this.bump(o),values:s}})}height(o){this.port.postMessage({p:te,v:ne,type:"ui.height",payload:{px:Math.round(o)}})}dispatch(o){const s=We(o.payload)?o.payload:{},r=typeof o.id=="string"?o.id:null;switch(o.type){case"host.surface":{const l=s.surface;return(l==="card"||l==="options"||l==="full")&&this.h.surface?.(l,s.mode==="simple"||s.mode==="advanced"?s.mode:null),!0}case"host.mode":{if(r===null)return!0;const l=s.mode;return l!=="simple"&&l!=="advanced"?(this.refuse(r,"bad_request","mode is simple or advanced"),!0):(this.reply(r,{mode:this.h.mode?.(l)??l}),!0)}case"host.action":{if(r===null)return!0;const l=s.id;return typeof l!="string"||this.h.action===void 0?(this.reply(r,{handled:!1}),!0):(Promise.resolve(this.h.action(l)).then(f=>this.reply(r,{handled:f.handled===!0,...typeof f.status=="string"?{status:f.status.slice(0,120)}:{}}),()=>this.reply(r,{handled:!1})),!0)}case"host.tab":return typeof s.tab=="string"&&this.h.tab?.(s.tab),!0;case"host.selection":return Array.isArray(s.anchors)&&this.h.selection?.(s.anchors),!0;case"options.changed":{if(r===null)return!0;const l=s.tab,f=s.id;return typeof l!="string"||typeof f!="string"||this.h.optionsChanged===void 0?(this.refuse(r,"unsupported","no controls here"),!0):(Promise.resolve(this.h.optionsChanged(l,f,s.value)).then(c=>this.reply(r,{applied:c.applied,rev:this.bump(l),values:c.values,...c.reason!==void 0?{reason:c.reason.slice(0,120)}:{}}),c=>this.refuse(r,"unavailable",c instanceof Error?c.message.slice(0,120):"failed")),!0)}default:return!1}}}const ce=[{name:"corporate-light",display_name:"Corporate Light",colors:{background:"#FFFFFF",surface:"#F8FAFC",primary:"#1E3A5F",secondary:"#2563EB",accent:"#0891B2",text_primary:"#1E293B",text_secondary:"#64748B",text_muted:"#94A3B8",border:"#E2E8F0"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}},{name:"midnight-purple",display_name:"Midnight Purple",colors:{background:"#0A0A0F",surface:"#13091D",primary:"#A100FF",secondary:"#6B2FA0",accent:"#F59E0B",text_primary:"#FFFFFF",text_secondary:"#A0A0B0",text_muted:"#6B6B80",border:"#2A2A3D"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}},{name:"warm-dark",display_name:"Warm Dark",colors:{background:"#1A1A2E",surface:"#16213E",primary:"#FF6B6B",secondary:"#C44569",accent:"#FFD93D",text_primary:"#F8F8F2",text_secondary:"#B0B0C0",text_muted:"#6B6B80",border:"#2D2D44"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}}],He=["Inter","Roboto","Source Sans 3","IBM Plex Sans","Calibri","Georgia","system-ui"],qt=[["background","Background"],["surface","Surface"],["primary","Primary"],["accent","Accent"],["text_primary","Text"]],Ee=n=>({name:n.name,colors:{...n.colors},fonts:{...n.fonts}});function Kt(n,o){n.replaceChildren(),n.classList.add("plugin-style"),n.onkeydown=g=>{o.key!==void 0&&zt(g,n,o.key)};const s=document.createElement("style");s.textContent=`.plugin-style{padding:16px;box-sizing:border-box;color:var(--ink-high);background:var(--surface-base);font:13px var(--font-sans,system-ui)}
127
+ .plugin-style h2{font-size:16px;margin:0 0 12px}.plugin-style .theme-cards{display:grid;gap:8px;margin-bottom:18px}
128
+ .plugin-style button,.plugin-style input,.plugin-style select{font:inherit;color:var(--ink-high);background:var(--surface-card);border:1px solid var(--border);border-radius:4px}
129
+ .plugin-style button{padding:8px;text-align:left;cursor:pointer}.plugin-style button:focus-visible,.plugin-style input:focus-visible,.plugin-style select:focus-visible{outline:2px solid var(--accent)}
130
+ .plugin-style .ps-swatches{display:flex;width:100%;height:16px;margin-bottom:6px;border:1px solid var(--border)}.plugin-style .ps-swatches span{flex:1}
131
+ .plugin-style label{display:flex;align-items:center;gap:8px;margin:10px 0}.plugin-style label>span:first-child{flex:1}.plugin-style input[type=color]{width:36px;height:30px;padding:2px}.plugin-style input[type=text]{width:80px;padding:5px}.plugin-style select{max-width:170px;padding:5px}
132
+ .plugin-style p{line-height:1.5;color:var(--ink-body)}.plugin-style [role=status]{min-height:1.5em}.plugin-style :disabled{opacity:.6;cursor:default}`,n.append(s);const r=document.createElement("h2");r.textContent="Style",n.append(r);const l=document.createElement("div");l.className="theme-cards",n.append(l);const f=document.createElement("p");f.setAttribute("role","status"),f.setAttribute("aria-live","polite");let c=!1;const h=[],x=()=>Ee(o.tokens()??ce[0]),D=[],S=[],F=()=>{const g=x();for(const{key:y,picker:k,hex:A}of D)A.value=g.colors[y],k.value=/^#[0-9a-f]{6}$/i.test(g.colors[y])?g.colors[y]:"";for(const{key:y,select:k}of S)k.value=He.includes(g.fonts[y])?g.fonts[y]:"system-ui";for(const y of Array.from(l.querySelectorAll("button")))y.setAttribute("aria-pressed",String(y.dataset.theme===g.name))},U=async g=>{if(!c){c=!0,h.forEach(y=>{y.disabled=!0}),f.textContent="Applying theme…";try{const y=await o.apply(g);f.textContent=y.ok?"Theme applied.":`Theme was not applied: ${y.reason}`}catch(y){f.textContent=`Theme was not applied: ${y instanceof Error?y.message:"unavailable"}`}finally{c=!1,h.forEach(y=>{y.disabled=!1}),F()}}};for(const g of ce){const y=document.createElement("button");y.type="button",y.dataset.theme=g.name;const k=document.createElement("span");k.className="ps-swatches",k.setAttribute("aria-hidden","true");for(const v of["background","surface","primary","secondary","accent"]){const b=document.createElement("span");b.style.backgroundColor=g.colors[v],k.append(b)}const A=document.createElement("span");A.textContent=g.display_name,y.append(k,A),y.addEventListener("click",()=>{U(Ee(g))}),l.append(y),h.push(y)}for(const[g,y]of qt){const k=document.createElement("label"),A=document.createElement("span");A.textContent=y;const v=document.createElement("input");v.type="color",v.setAttribute("aria-label",y);const b=document.createElement("input");b.type="text",b.maxLength=7,b.setAttribute("aria-label",`${y} hex`);const M=Z=>{if(!/^#[0-9a-f]{6}$/i.test(Z)){f.textContent="Enter a six-digit hex colour: a # and six digits or letters a to f.",F();return}const _=x();_.name="custom",_.colors[g]=Z,U(_)};v.addEventListener("change",()=>M(v.value)),b.addEventListener("change",()=>M(b.value)),k.append(A,v,b),n.append(k),h.push(v,b),D.push({key:g,picker:v,hex:b})}for(const g of["heading","body"]){const y=document.createElement("label"),k=document.createElement("span");k.textContent=g==="heading"?"Heading font":"Body font";const A=document.createElement("select");A.setAttribute("aria-label",k.textContent);for(const v of He){const b=document.createElement("option");b.value=v,b.textContent=v,A.append(b)}A.addEventListener("change",()=>{const v=x();v.name="custom",v.fonts[g]=A.value,U(v)}),y.append(k,A),n.append(y),h.push(A),S.push({key:g,select:A})}const re=document.createElement("p");return re.textContent="Match a website or a PDF: the host's Match button under this tab",n.append(re,f),F(),{refresh:F}}function Nt(n){const o=new DOMParser().parseFromString(n,"text/html"),s=Array.from(o.querySelectorAll("style")).map(h=>h.textContent??"").join(`
133
+ `),r=new Map;for(const h of s.matchAll(/(--wi-[a-z-]+)\s*:\s*([^;}{]+)/gi))r.set(h[1].toLowerCase(),h[2].trim());if(r.size===0)return null;const l=Ee(ce[0]),f={background:"--wi-bg",surface:"--wi-surface",primary:"--wi-primary",secondary:"--wi-secondary",accent:"--wi-accent",text_primary:"--wi-text",text_secondary:"--wi-text-secondary",text_muted:"--wi-muted",border:"--wi-border"};for(const h of Object.keys(f)){const x=r.get(f[h]);x!==void 0&&/^(#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|hsl)a?\([0-9.,%\s]+\))$/i.test(x)&&(l.colors[h]=x)}for(const h of["heading","body","mono"]){const x=r.get(`--wi-font-${h}`);x!==void 0&&(l.fonts[h]=x.split(",")[0].trim().replace(/^['"]|['"]$/g,""))}const c=ce.find(h=>JSON.stringify(h.colors)===JSON.stringify(l.colors)&&JSON.stringify(h.fonts)===JSON.stringify(l.fonts));return l.name=c?.name??"custom",l}const oe="wicked.editor",de=1,jt=[[390,"Phone"],[820,"Tablet"],[1280,"Desktop"]],$e=34,It=[0,250,750,1500],Pt=`
134
+ <div data-testid="page-style" id="style" class="style-pane" hidden></div>
135
+ <div data-testid="page-editor" id="editor" class="editor" data-kind="page" data-head="" data-pickable="false" data-selected="" data-size="pane" data-width="" tabindex="0" role="application" aria-label="The page">
136
+ <div data-testid="page-tools" id="tools" class="tools" role="toolbar" aria-label="Page width">
137
+ ${jt.map(([n,o])=>`<button type="button" data-testid="page-width" data-width="${n}" aria-pressed="false" title="${o} · ${n} px wide">${o} ${n}</button>`).join("")}
138
+ </div>
139
+ <div id="stage" class="stage"></div>
140
+ <div data-testid="page-hover-box" id="hover" class="box box--hover" hidden></div>
141
+ <div data-testid="page-selected-box" id="selected" class="box" data-wid="" hidden></div>
142
+ <textarea data-testid="page-edit-input" id="input" class="input" rows="1" aria-label="New text" hidden></textarea>
143
+ <div data-testid="page-handle" id="handle" class="handle" tabindex="-1"></div>
144
+ <p data-testid="page-hint" id="hint" class="hint" hidden></p>
145
+ <p data-testid="page-note" id="note" class="note" hidden></p>
146
+ <div data-testid="page-peek" id="peek" class="peek" role="group" aria-label="The picked element" hidden>
147
+ <button type="button" data-testid="page-section" id="to-section" hidden>Whole section</button>
148
+ <button type="button" data-testid="page-remove" id="remove" class="danger" title="Remove it (⌘⌫ / Ctrl+Backspace) — Undo puts it back">Remove</button>
149
+ <span class="swatches" data-testid="page-swatches" data-prop="background" id="fills"><span class="word">Fill</span></span>
150
+ <span class="swatches" data-testid="page-swatches" data-prop="color" id="inks"><span class="word">Text</span></span>
151
+ </div>
152
+ </div>`;function O(n){const o=document.getElementById(n);if(o===null)throw new Error(`wicked-page: no #${n}`);return o}function Ue(n,o){const s=n?.blocks[o];return n===null||n.widMap[o]===void 0||s===void 0?"unmeasured":s.composite?"container":s.cut===!0?"cut":"yes"}function Ce(n){return`${n.charAt(0).toUpperCase()}${n.slice(1)}`}function Xt(n){document.body.insertAdjacentHTML("afterbegin",Pt);const o=O("editor");o.dataset.kind=n.kind,o.setAttribute("aria-label",n.kind==="document"?"The document":"The page");const s=O("stage");let r=null;const l=O("hover"),f=O("selected"),c=O("input"),h=O("handle"),x=O("hint"),D=O("note"),S=O("tools"),F=O("peek"),U=O("to-section"),re=O("remove"),g=O("fills"),y=O("inks");let k=null,A=[],v="pane",b=1,M="options",Z="style",_="simple",Se=null;const se=()=>b===1?v!=="inline":M==="full",J=()=>se()&&(b===1||_==="advanced");let ue=null,Yt=0;const Te=new Map,N=(e,t)=>{k?.postMessage({p:oe,v:de,type:e,payload:t})},ie=(e,t)=>new Promise(i=>{if(k===null){i({ok:!1,error:{code:"unavailable",message:"no host yet"}});return}const a=`wp-${++Yt}`;Te.set(a,i),k.postMessage({p:oe,v:de,type:e,id:a,payload:t})}),pe=e=>N("ui.status",{line:e.slice(0,120)});let C=null,Oe=Object.create(null),V=null,Le=0,ae=!1,Me=!1,X=null;const w=n.coverage?document.createElement("aside"):null;if(w!==null){w.id="coverage",w.dataset.testid="doc-coverage",w.setAttribute("aria-label","Requirements"),w.hidden=!0,document.body.append(w);const e=document.createElement("style");e.textContent=`#coverage{box-sizing:border-box;height:100%;overflow:auto;padding:16px;color:var(--ink-high);background:var(--surface-base);font:13px var(--font-sans,system-ui)}
153
+ #coverage h2{font-size:16px;margin:0 0 12px}#coverage p{color:var(--ink-muted);line-height:1.5}
154
+ #coverage button{display:block;width:100%;padding:10px 8px;text-align:left;font:inherit;color:var(--ink-high);background:var(--surface-card);border:1px solid var(--border);border-radius:4px;margin:6px 0;cursor:pointer}
155
+ #coverage button:disabled{cursor:default}#coverage button:focus-visible{outline:2px solid var(--accent)}
156
+ #coverage p button{display:inline;width:auto;padding:0;margin:0;border:0;background:transparent;color:var(--accent);text-decoration:underline}
157
+ body[data-coverage="side"] .editor{width:calc(100% - min(300px,38%))}
158
+ body[data-coverage="side"] #coverage{position:absolute;right:0;top:0;width:min(300px,38%);border-left:1px solid var(--border)}`,document.body.append(e)}const fe=()=>{if(w===null)return;if(w.replaceChildren(),delete w.dataset.total,delete w.dataset.rows,delete w.dataset.named,ae){const p=document.createElement("p");p.textContent="Couldn't read the requirements · ";const $=document.createElement("button");$.type="button",$.textContent="Try again",$.addEventListener("click",()=>{Be()}),p.append($),w.append(p);return}if(V===null){const p=document.createElement("p");p.textContent="Reading requirements…",w.append(p);return}if(V.length===0){const p=document.createElement("p");p.textContent="No requirements for this document's repository",w.append(p);return}const e=ct(V.map(p=>({key:p.id,reqId:p.id,title:p.text,risk:!1})),Oe),t=e.filter(p=>p.wid!==null),i=e.filter(p=>p.wid===null);w.dataset.total=String(Le),w.dataset.rows=String(e.length),w.dataset.named=String(t.length);const a=document.createElement("h2");a.textContent="Requirements",w.append(a);const d=document.createElement("p");d.dataset.testid="doc-coverage-line",d.textContent=ut(e,Le),w.append(d);const u=(p,$)=>{if($.length===0)return;const le=document.createElement("p");le.textContent=`${p} (${$.length})`,w.append(le);for(const z of $){const I=document.createElement("button");I.type="button",I.dataset.testid="doc-coverage-row",I.dataset.req=z.reqId,I.dataset.named=String(z.wid!==null),I.disabled=z.wid===null,I.textContent=`${z.reqId} · ${z.title}${z.wid===null?"":` · ${ee(z.wid,n.kind)}`}`,I.addEventListener("click",()=>{if(z.wid!==null){if(M==="options"){A.includes("selection.chip")&&N("selection.set",{anchors:[{kind:"element",id:z.wid}]});return}Q(z.wid,!0),ke(z.wid)}}),w.append(I)}};u("Not named",i),u("Named",t)},Be=async()=>{if(!(!n.coverage||V!==null||Me)){Me=!0,ae=!1,fe();try{const e=await ie("checks.read",{}),t=e.ok?e.payload.checks:null;if(!e.ok||!Array.isArray(t)){ae=!0;return}V=t.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.text=="string"),Le=typeof e.payload.total=="number"?e.payload.total:V.length}catch{ae=!0}finally{Me=!1,fe()}}},Wt=e=>{const t=new DOMParser().parseFromString(e,"text/html");Oe=Object.create(null);const i=Array.from(t.querySelectorAll("[data-wid]")),a=new Map;for(const d of i){const u=d.getAttribute("data-wid")??"";a.set(u,(a.get(u)??0)+1)}for(const d of i){const u=d.getAttribute("data-wid")??"";!/^[A-Za-z0-9_.:-]{1,100}$/.test(u)||a.get(u)!==1||(Oe[u]={text:(d.textContent??"").replace(/\s+/g," ").trim(),composite:d.querySelector("[data-wid]")!==null})}fe()};let E=null,he={scrollX:0,scrollY:0},ye=null,m=null,B=null,me=null,R=!1,Ze=[],q=null,Fe=0,Je=-1,G=null,_e=null,Ve=0,ge=[],Re=!1,ze=null,ve=null;const Ge=e=>{r?.contentWindow?.postMessage(e,"*")},Ht=e=>{if(e===r){Je=Fe;for(const t of ge)clearTimeout(t);ge=It.map(t=>setTimeout(()=>Ge(wt),t))}},Ut=e=>{const t=document.createElement("iframe");for(const[a,d]of Object.entries({"data-testid":"page-frame",sandbox:"allow-scripts",title:n.kind==="document"?"The document":"The page",class:"frame"}))t.setAttribute(a,d);t.addEventListener("load",()=>Ht(t));const i=r;r=t;for(const a of ge)clearTimeout(a);t.srcdoc=e,s.appendChild(t),i?.remove(),be()},Qe=()=>{const e=v==="inline"?0:$e;if(q===null)return{x:0,y:e,s:1};const t=s.clientWidth,i=t>0?Math.min(1,t/q):1;return{x:Math.max(0,(t-q*i)/2),y:e,s:i}},be=()=>{s.style.top=`${v==="inline"?0:$e}px`,o.dataset.width=q===null?"":String(q);for(const i of Array.from(S.querySelectorAll("[data-width]")))i.setAttribute("aria-pressed",String(Number(i.dataset.width)===q));if(r===null)return;if(q===null){r.style.cssText="";return}const e=Qe(),t=s.clientHeight>0?s.clientHeight/e.s:0;r.style.cssText=`position:absolute;left:${e.x}px;top:0;width:${q}px;${t>0?`height:${t}px;`:""}transform:scale(${e.s});transform-origin:0 0`},we=e=>{if(e===null||E===null)return null;const t=E.widMap[e];if(t===void 0)return null;const i=yt(t,E.measured,he),a=Qe();return{left:a.x+i.left*a.s,top:a.y+i.top*a.s,width:i.width*a.s,height:i.height*a.s}},De=(e,t,i=0,a=0)=>{if(t===null){e.hidden=!0;return}e.hidden=!1,e.style.left=`${t.left}px`,e.style.top=`${t.top}px`,e.style.width=`${Math.max(t.width,i)}px`,e.style.height=`${Math.max(t.height,a)}px`},qe=()=>(v!=="inline"||b>=2&&M==="card")&&E!==null,T=()=>{if(o.dataset.head=C===null?"":String(C),o.dataset.pickable=String(qe()),o.dataset.selected=m??"",o.dataset.size=v,De(l,ye!==m&&B===null?we(ye):null),f.dataset.wid=m??"",De(f,B===null?we(m):null),B!==null?De(c,we(B.wid),160,30):c.hidden=!0,S.hidden=v==="inline",o.dataset.mode=b>=2?_:"",re.hidden=!J(),g.hidden=!J(),y.hidden=!J(),Zt(),!se()||!qe()||B!==null){x.hidden=!0;return}if(x.hidden=!1,m===null){x.removeAttribute("data-editable"),x.textContent="Click an element to make it the subject · type on it to change it";return}const e=ee(m,n.kind),t=Ue(E,m);x.dataset.editable=String(t==="yes"),x.textContent=t==="yes"?`Type to change ${e} · Enter to edit its text · Esc to let go`:t==="container"?`${Ce(e)} holds other parts — click a line of text inside it to change the words · Esc to let go`:t==="cut"?`${Ce(e)} is too long to change by typing — say what to change in the message box · Esc to let go`:`${Ce(e)} can’t be changed by typing — say what to change in the message box · Esc to let go`},Zt=()=>{const e=J()&&qe()&&B===null&&!R?we(m):null;if(e===null||m===null){F.hidden=!0;return}F.hidden=!1,U.hidden=E?.blocks[m]?.section===void 0;const t=F.offsetHeight||30,i=e.top+e.height+6,a=o.clientHeight===0||i+t<=o.clientHeight-4,d=F.offsetWidth,u=o.clientWidth>0?o.clientWidth-d-4:1/0;F.style.left=`${Math.max(4,Math.min(e.left,u))}px`,F.style.top=`${a?i:Math.max($e+2,e.top-t-6)}px`},et=(e,t)=>{for(const a of Array.from(e.querySelectorAll("button")))a.remove();const i=(a,d)=>{const u=document.createElement("button");u.type="button",u.className=a===Ae?"swatch swatch--default":"swatch";for(const[p,$]of Object.entries({"data-testid":"page-swatch"}))u.setAttribute(p,$);u.dataset.prop=t,u.dataset.value=a,u.title=`${t==="background"?"Fill":"Text"}: ${d}`,u.setAttribute("aria-label",u.title),a===Ae?u.textContent="Default":u.style.setProperty("--swatch",a),u.addEventListener("click",()=>{m!==null&&Vt(m,t,a,d)}),e.appendChild(u)};for(const a of Ze)i(a.value,a.label);i(Ae,"Default")},j=()=>{if(B===null)return;B=null,c.hidden=!0,c.value="";const e=me;me=null,e!==null&&Ke(e),T()},Q=(e,t=!1)=>{X=null,m=e,j(),T(),e!==null&&(A.includes("selection.chip")&&N("selection.set",{anchors:[{kind:"element",id:e}]}),t||h.focus())},ke=e=>{Ve+=1,Ge(kt(e,Ve))},Ke=e=>{const t=e.version;if(typeof t=="number"&&C!==null&&t<C)return;if(B!==null){const d=me?.version;typeof t=="number"&&t>B.base&&(typeof d!="number"||t>=d)&&(me=e);return}D.hidden=!0;const i=e.content,a=typeof i?.html=="string"?i.html:"";n.coverage&&Wt(a),C=typeof t=="number"?t:C,Ze=Ot(a),ue=Nt(a)??ue,Ie?.refresh(),et(g,"background"),et(y,"color"),Fe+=1,_e=G,G=null,E=null,ye=null,m=null,j(),T(),Ut(At(a)?a:$t(a))},Y=async e=>{if(Re){if(e!==void 0&&e===ze)return;ve=e===void 0?{}:{version:e};return}Re=!0,ze=e??null;try{const t=await ie("artifact.read",e===void 0?{}:{version:e});if(!t.ok){D.hidden=!1,D.textContent=t.error.code==="not_granted"?`This editor may not read the ${n.kind} here.`:`The ${n.kind} could not be read (${t.error.code}).`;return}Ke(t.payload)}finally{if(Re=!1,ze=null,ve!==null){const t=ve;ve=null,(t.version===void 0||t.version!==C)&&Y(t.version)}}};window.addEventListener("message",e=>{if(r===null||r.contentWindow===null||e.source!==r.contentWindow||Je!==Fe)return;const t=bt(e.data);if(t!==null){if(t.type==="wid-inventory"){for(const a of ge)clearTimeout(a);E={widMap:t.widMap,blocks:t.blocks??{},measured:{scrollX:t.scrollX,scrollY:t.scrollY}},he={scrollX:t.scrollX,scrollY:t.scrollY};const i=_e;_e=null,i!==null&&t.widMap[i]!==void 0&&ke(i),X!==null&&t.widMap[X]!==void 0&&(m=X,n.coverage&&ke(X)),T()}else if(t.type==="scroll-state")he={scrollX:t.scrollX,scrollY:t.scrollY},T();else if(t.type==="scroll-ack")t.scrollX!==void 0&&t.scrollY!==void 0&&(he={scrollX:t.scrollX,scrollY:t.scrollY},T());else if(t.type==="wid-hover")ye=t.wid,T();else if(t.type==="wid-click"){if(b===1&&v==="inline")return;if(b===2&&M==="card"){Q(t.wid);return}const i=t.wid===m?E?.blocks[t.wid]?.section:void 0;Q(i!==void 0&&E?.widMap[i]!==void 0?i:t.wid)}}});const tt=(e,t)=>{if(!se()||R||C===null||E===null||Ue(E,e)!=="yes")return;const i=E.blocks[e]?.text??"";B={wid:e,before:i,base:C},c.value=t??i,T(),c.focus(),t===null?c.select():c.setSelectionRange(c.value.length,c.value.length)},Ne=async(e,t,i,a,d=C)=>{if(C===null||R)return;R=!0,T(),pe(i);const u=a;try{const p=await ie("version.write",{base:d,ops:e,summary:t});if(p.ok)G=u,await Y(typeof p.payload.version=="number"?p.payload.version:void 0);else if(p.error.code==="stale"||p.error.code==="head_moved"){pe(p.error.code==="stale"&&p.error.message?p.error.message:"Not changed: it moved while you typed"),G=u;const $=p.payload?.head;p.error.code==="head_moved"?await Y(typeof $=="number"?$:void 0):typeof $=="number"&&$!==C&&await Y($)}else p.error.code==="timeout"||(p.error.code==="refused"?pe(p.error.message||"Nothing changed"):pe(`Not changed: ${p.error.message||p.error.code}`))}finally{R=!1,T()}},Jt=async()=>{if(B===null||C===null||R)return;const{wid:e,before:t,base:i}=B,a=c.value.replace(/\s*\n\s*/g," ");if(j(),h.focus(),a===t)return;const d=ee(e,n.kind);await Ne([{op:"text",anchor:e,value:a,before:t}],d,`Changing ${d}…`,e,i)},nt=async e=>{if(!J()||R||E?.widMap[e]===void 0)return;const t=ee(e,n.kind),i=E.blocks[e]?.section??null;h.focus(),await Ne([{op:"remove",anchor:e}],t,`Removing ${t}…`,i)},Vt=async(e,t,i,a)=>{if(!J()||R||E?.widMap[e]===void 0)return;const d=ee(e,n.kind);h.focus(),await Ne([{op:"style",anchor:e,style:{[t]:i}}],d,`${t==="background"?"Filling":"Colouring the text of"} ${d}: ${a.toLowerCase()}…`,e)},ot=e=>{const t=E?.blocks[e]?.section;return t===void 0||E?.widMap[t]===void 0?!1:(Q(t),!0)};U.addEventListener("click",()=>{m!==null&&ot(m)}),re.addEventListener("click",()=>{m!==null&&nt(m)});for(const e of Array.from(S.querySelectorAll("[data-width]")))e.addEventListener("click",()=>{const t=Number(e.dataset.width);q=q===t?null:t,be(),T()});window.addEventListener("resize",()=>{be(),T()}),c.addEventListener("keydown",e=>{e.stopPropagation(),e.key==="Enter"?(e.preventDefault(),Jt()):e.key==="Escape"&&(e.preventDefault(),j(),h.focus())}),c.addEventListener("blur",()=>{j()});const Gt=()=>[...Array.from(S.querySelectorAll("button")),h,...Array.from(F.querySelectorAll("button")),...Array.from(w?.querySelectorAll("button")??[])].filter(e=>e.closest("[hidden]")===null&&!(e instanceof HTMLButtonElement&&e.disabled)),rt=(e,t)=>{if(e.target===c)return;const i=e.target?.tagName==="BUTTON";if(!(i&&(e.key==="Enter"||e.key===" "))){if(e.key==="Escape"){if(!t&&m!==null){e.preventDefault(),Q(null);return}e.preventDefault(),N("ui.key",{key:"Escape"});return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="k"){e.preventDefault(),N("ui.key",{key:"Mod+K"});return}if(!t&&(e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key==="Backspace"||e.key==="Delete")){e.preventDefault(),m!==null&&!R&&nt(m);return}if(!t&&e.altKey&&!e.metaKey&&!e.ctrlKey&&e.key==="ArrowUp"){e.preventDefault(),m!==null&&ot(m);return}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&/^Key[A-Z]$/.test(e.code)&&Ye(`Alt+${e.code.slice(3)}`)){e.preventDefault(),N("ui.key",{key:`Alt+${e.code.slice(3)}`});return}if(e.key==="Tab"){e.preventDefault();const a=Gt(),d=a.indexOf(document.activeElement),u=d===-1&&document.activeElement===o&&!e.shiftKey?0:d+(e.shiftKey?-1:1);if(d===-1&&u!==0||u<0||u>=a.length){N("ui.key",{key:e.shiftKey?"Shift+Tab":"Tab"});return}a[u].focus();return}if(!(e.metaKey||e.ctrlKey||e.altKey)&&!(i&&e.key.length!==1)){if(e.key==="Enter"){!t&&m!==null&&!R&&se()&&(e.preventDefault(),tt(m,null));return}if(e.key.length===1){if(e.preventDefault(),!t&&m!==null&&!R&&se()){tt(m,e.key);return}N("ui.typed",{grapheme:e.key})}}}};o.addEventListener("keydown",e=>rt(e,!1)),w?.addEventListener("keydown",e=>rt(e,!0));const je=e=>{v=e,document.body.dataset.size=e,e==="inline"&&(j(),b<2&&Q(null),document.activeElement?.blur?.()),be(),T()},st=e=>{if(!(typeof e!="object"||e===null))for(const[t,i]of Object.entries(e))/^--[a-z0-9-]+$/.test(t)&&typeof i=="string"&&i.length<=200&&!/url\(/i.test(i)&&document.documentElement.style.setProperty(t,i)},Qt=e=>{const t=e.data;try{if(t===null||typeof t!="object"||t.p!==oe||t.v!==de)return;if(typeof t.re=="string"){const a=Te.get(t.re);if(a===void 0)return;Te.delete(t.re);const d=typeof t.payload=="object"&&t.payload!==null?t.payload:{};t.ok===!0?a({ok:!0,payload:d}):a({ok:!1,error:t.error??{code:"unavailable",message:"no answer"},payload:d});return}if(Se!==null&&Se.dispatch(t))return;const i=typeof t.payload=="object"&&t.payload!==null?t.payload:{};switch(t.type){case"host.ping":typeof t.id=="string"&&k?.postMessage({p:oe,v:de,re:t.id,ok:!0,payload:{}});return;case"host.size":(i.size==="inline"||i.size==="pane"||i.size==="full")&&je(i.size);return;case"host.theme":st(i.theme);return;case"artifact.changed":{ae&&Be();const a=i.version;typeof a=="number"&&a!==C&&(G=G??m,Y(a));return}case"selection.cleared":X=null,m!==null&&(m=null,j(),T());return;default:return}}catch{}};window.addEventListener("message",e=>{const t=e.data;if(k!==null||t===null||typeof t!="object"||t.p!==oe||t.type!=="host.hello"||e.ports[0]===void 0)return;k=e.ports[0],k.onmessage=Qt;const i=typeof t.payload=="object"&&t.payload!==null?t.payload:{};A=Array.isArray(i.grants)?i.grants.filter(d=>typeof d=="string"):[],st(i.theme);const a=Ft(i);b=a.protocol,b>=2?(M=i.surface==="options"?"options":a.surface,Z=a.tab??"style",_=a.mode??"simple",Se=new Dt(k,{surface:(d,u)=>{M=d,u!==null&&(_=u),xe()},mode:d=>(_=d,n.coverage?xe():T(),_),tab:d=>{n.coverage&&(Z=d,xe())},selection:d=>{const u=d.find(p=>typeof p=="object"&&p!==null&&p.kind==="element"&&typeof p.id=="string");M==="options"&&u!==void 0||(X=u?.id??null,m=u!==void 0&&E?.widMap[u.id]!==void 0?u.id:null,m!==null&&n.coverage&&ke(m),j(),T())}}),xe()):je(a.size),Y()});const it=O("style");let Ie=null;const xe=()=>{const e=M==="options",t=n.coverage&&e&&Z==="coverage",i=n.coverage&&M==="full"&&_==="advanced";n.coverage&&(document.body.dataset.coverage=i?"side":"",w!==null&&(w.hidden=!t&&!i),(t||i)&&(fe(),Be())),it.hidden=!e||t,o.hidden=e,e&&!t&&Ie===null&&(Ie=Kt(it,{tokens:()=>ue,key:a=>N("ui.key",{key:a}),apply:async a=>{for(let d=0;d<2;d+=1){if(C===null)return{ok:!1,reason:`The ${n.kind} is not loaded yet`};const u=await ie("theme.set",{base:C,tokens:a});if(u.ok){const le=u.payload.version;return ue={name:a.name,colors:{...a.colors},fonts:{...a.fonts}},typeof le=="number"&&await Y(le),{ok:!0}}if(u.error.code!=="head_moved")return{ok:!1,reason:u.error.message};const p=await ie("artifact.read",{});if(!p.ok)return{ok:!1,reason:p.error.message||p.error.code};const $=p.payload.version;if(typeof $!="number"||C!==null&&$<C)return{ok:!1,reason:`The current ${n.kind} version could not be read.`};if(Ke(p.payload),d===1)return{ok:!1,reason:u.error.message||u.error.code}}return{ok:!1,reason:`The ${n.kind} changed again: try once more`}}})),je(Bt(M))};Rt(n.editor,n.surfaces)}Xt({editor:"wicked-doc",surfaces:{card:{interactive:!0,aspect:"16:9",actions:[{id:"ask",label:"Ask about this",verb:"host:ask"},{id:"export",label:"Export",verb:"host:export"}]},options:{tabs:[{id:"style",label:"Style",render:"plugin"},{id:"coverage",label:"Coverage",render:"plugin"}]},full:{modes:["simple","advanced"],default:"simple"}},kind:"document",coverage:!0})})();
159
+ </script>
160
+ </body>
161
+ </html>
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "id": "wicked-page",
3
- "title": "Document",
4
- "version": "0.8.0",
3
+ "title": "Page",
4
+ "version": "0.9.1",
5
5
  "protocol": [
6
- 1
6
+ 1,
7
+ 2
7
8
  ],
8
9
  "kinds": [
9
10
  "page"
@@ -30,6 +31,43 @@
30
31
  {
31
32
  "id": "network.media",
32
33
  "why": "to show the page’s web images and fonts"
34
+ },
35
+ {
36
+ "id": "artifact.theme",
37
+ "why": "to change the page’s theme, colours and fonts from its Style tab, as one version with Undo"
38
+ },
39
+ {
40
+ "id": "ui.fullscreen",
41
+ "why": "to show the page full screen"
42
+ }
43
+ ],
44
+ "surfaces": {
45
+ "card": {
46
+ "interactive": true,
47
+ "aspect": "16:9",
48
+ "actions": [
49
+ {
50
+ "id": "ask",
51
+ "label": "Ask about this",
52
+ "verb": "host:ask"
53
+ }
54
+ ]
55
+ },
56
+ "options": {
57
+ "tabs": [
58
+ {
59
+ "id": "style",
60
+ "label": "Style",
61
+ "render": "plugin"
62
+ }
63
+ ]
64
+ },
65
+ "full": {
66
+ "modes": [
67
+ "simple",
68
+ "advanced"
69
+ ],
70
+ "default": "simple"
33
71
  }
34
- ]
72
+ }
35
73
  }
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="wicked-editor" content="wicked-page">
6
- <meta name="wicked-editor-version" content="0.8.0">
6
+ <meta name="wicked-editor-version" content="0.9.1">
7
7
  <title>Document</title>
8
8
  <style>
9
9
  /* The plugin's own chrome takes the host's tokens (`host.hello.theme` / `host.theme`), with plain
@@ -17,8 +17,11 @@
17
17
  .editor { position: relative; width: 100%; height: 100%; outline: none; }
18
18
  .editor:focus { box-shadow: inset 0 0 0 2px var(--accent); }
19
19
  .stage { position: absolute; inset: 0; }
20
- .frame { display: block; width: 100%; height: 100%; border: 0; background: var(--surface-base); }
21
- body[data-size="inline"] .editor { pointer-events: none; }
20
+ /* The page is a document: one with no background of its own is drawn on white, as a browser would, whatever the host theme. */
21
+ .frame { display: block; width: 100%; height: 100%; border: 0; background: #ffffff; }
22
+ body[data-size="inline"] .editor:not([data-mode="simple"]):not([data-mode="advanced"]) { pointer-events: none; }
23
+ /* Protocol 2: the Style tab (the options instance). */
24
+ .style-pane { height: 100%; overflow: auto; box-sizing: border-box; padding: 12px; background: var(--surface-base); color: var(--ink-high); }
22
25
  .box { position: absolute; pointer-events: none; border: 2px solid var(--accent); border-radius: 3px; box-sizing: border-box; }
23
26
  .box--hover { border-style: dashed; opacity: .55; }
24
27
  .handle { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; }
@@ -42,7 +45,7 @@
42
45
  </style>
43
46
  </head>
44
47
  <body data-size="pane">
45
- <script>var wickedEditor=(function(P){"use strict";const me=/^slide-(\d+)-([a-z-]+)-(\d+)$/,be=/^section-(\d+)$/,ke={heading:"heading",paragraph:"paragraph","list-item":"list item",quote:"quote",caption:"caption",cell:"table cell",link:"link",button:"button",image:"image",block:"block",text:"line"},xe=/^[A-Za-z]{2,}(?:[-_ ][A-Za-z]{2,})*$/;function Y(o,r){const i=me.exec(o);if(i!==null){const p=Number(i[1]),d=ke[i[2]??""]??(i[2]??"").replace(/-+/g," "),u=Number(i[3]);return p===0?`${d} ${u}`:`${d} ${u} in section ${p+1}`}const c=be.exec(o);return c!==null?`section ${Number(c[1])+1}`:xe.test(o)?`the ${o.replace(/[-_]+/g," ").toLowerCase()}`:"this part"}function $e(o,r,i){return{left:o.left-(i.scrollX-r.scrollX),top:o.top-(i.scrollY-r.scrollY),width:o.width,height:o.height}}const Ee=/^[A-Za-z0-9_.:-]{1,100}$/;function g(o){return typeof o=="number"&&isFinite(o)}function Ae(o){if(typeof o!="object"||o===null)return!1;const r=o;return r.section!==void 0&&(typeof r.section!="string"||!Ee.test(r.section))?!1:typeof r.text=="string"&&typeof r.composite=="boolean"}function Se(o){if(typeof o!="object"||o===null)return!1;const r=o;return g(r.x)&&g(r.y)&&g(r.width)&&g(r.height)&&g(r.top)&&g(r.left)&&g(r.right)&&g(r.bottom)}function Te(o){if(typeof o!="object"||o===null)return null;const r=o;if(r.v!==1)return null;const i=r.type;if(i==="wid-inventory"){const c=r.widMap,p=r.scrollX,d=r.scrollY;if(typeof c!="object"||c===null||!g(p)||!g(d))return null;const u={};for(const[E,y]of Object.entries(c)){if(!Se(y))return null;u[E]=y}const w=r.blocks;if(w===void 0)return{v:1,type:"wid-inventory",widMap:u,scrollX:p,scrollY:d};if(typeof w!="object"||w===null)return null;const z={};for(const[E,y]of Object.entries(w)){if(!Ae(y))return null;z[E]={text:y.text,composite:y.composite,...y.cut===!0?{cut:!0}:{},...y.section!==void 0?{section:y.section}:{}}}return{v:1,type:"wid-inventory",widMap:u,scrollX:p,scrollY:d,blocks:z}}if(i==="scroll-state"){const c=r.scrollX,p=r.scrollY;return!g(c)||!g(p)?null:{v:1,type:"scroll-state",scrollX:c,scrollY:p}}if(i==="scroll-ack"){const c=r.wid;if(typeof c!="string"||c==="")return null;const p=r.scrollX,d=r.scrollY,u=r.seq;return{v:1,type:"scroll-ack",wid:c,...g(p)&&g(d)?{scrollX:p,scrollY:d}:{},...typeof u=="number"&&Number.isInteger(u)&&u>0?{seq:u}:{}}}if(i==="wid-click"){const c=r.wid;return typeof c!="string"||c===""?null:{v:1,type:"wid-click",wid:c}}if(i==="wid-hover"){const c=r.wid;return c!==null&&(typeof c!="string"||c==="")?null:{v:1,type:"wid-hover",wid:c}}return null}const Me=Object.freeze({v:1,type:"request-inventory"});function Oe(o,r){return r===void 0?{v:1,type:"scroll-to-wid",wid:o}:{v:1,type:"scroll-to-wid",wid:o,seq:r}}const Le="request-inventory";function Ce(o){return o.includes(Le)}const ze=`
48
+ <script>var wickedEditor=(function(K){"use strict";var on=Object.defineProperty;var rn=(K,N,W)=>N in K?on(K,N,{enumerable:!0,configurable:!0,writable:!0,value:W}):K[N]=W;var lt=(K,N,W)=>rn(K,typeof N!="symbol"?N+"":N,W);const N=/^slide-(\d+)-([a-z-]+)-(\d+)$/,W=/^section-(\d+)$/,ct={heading:"heading",paragraph:"paragraph","list-item":"list item",quote:"quote",caption:"caption",cell:"table cell",link:"link",button:"button",image:"image",block:"block",text:"line"},dt=/^[A-Za-z]{2,}(?:[-_ ][A-Za-z]{2,})*$/;function ee(n,o){const s=N.exec(n);if(s!==null){const l=Number(s[1]),f=ct[s[2]??""]??(s[2]??"").replace(/-+/g," "),c=Number(s[3]);return o==="deck"?`slide ${l+1}’s ${f==="heading"&&c===1?"title":`${f} ${c}`}`:l===0?`${f} ${c}`:`${f} ${c} in section ${l+1}`}const r=W.exec(n);return r!==null?o==="deck"?`slide ${Number(r[1])+1}`:`section ${Number(r[1])+1}`:dt.test(n)?`the ${n.replace(/[-_]+/g," ").toLowerCase()}`:"this part"}function ut(n,o){const s=Object.entries(o).filter(([,r])=>!r.composite&&r.text!=="");return n.map(r=>{const l=r.reqId.trim();if(l==="")return{...r,wid:null};const f=s.find(([,c])=>pt(c.text,l));return{...r,wid:f===void 0?null:f[0]}})}const Pe=/[A-Za-z0-9_-]/,Xe=/[A-Za-z0-9]/;function pt(n,o){const s=n.toLowerCase(),r=o.toLowerCase();if(r==="")return!1;for(let l=s.indexOf(r);l!==-1;l=s.indexOf(r,l+1)){const f=s.charAt(l-1),c=s.charAt(l+r.length),h=Pe.test(f)||f==="."&&Xe.test(s.charAt(l-2)),x=Pe.test(c)||c==="."&&Xe.test(s.charAt(l+r.length+1));if(!h&&!x)return!0}return!1}function ft(n,o){const s=n.filter(l=>l.wid!==null).length,r=o>n.length?` (the first ${n.length} of ${o})`:"";return`${s} of ${n.length} named in this document${r}`}const ht={"Alt+J":{verb:"navigate",what:"next card or row"},"Alt+K":{verb:"navigate",what:"previous card or row"},"Alt+/":{verb:"navigate",what:"the keyboard shortcuts overlay"},"Alt+P":{verb:"navigate",what:"peek at the top item that needs you"},"Alt+G":{verb:"navigate",what:"jump to the top item that needs you"},"Alt+B":{verb:"navigate",what:"back to where you were"},"Alt+T":{verb:"navigate",what:"the run’s evidence timeline"},"Alt+U":{verb:"navigate",what:"the run’s unit list"},"Alt+A":{verb:"approve",what:"approve the open gate"},"Alt+R":{verb:"decide",what:"reject the open gate"},"Alt+X":{verb:"decide",what:"select a gate for batch resolution"},"Alt+N":{verb:"compose",what:"compose a steer note"}},yt=new Set(["Escape","Mod+K","Tab","Shift+Tab"]);function Ye(n){if(yt.has(n))return!0;const o=ht[mt(n)];return o!==void 0&&o.verb==="navigate"}function mt(n){const o=/^alt\+(.)$/i.exec(n);return o===null?n:`Alt+${o[1].toUpperCase()}`}function gt(n,o,s){return{left:n.left-(s.scrollX-o.scrollX),top:n.top-(s.scrollY-o.scrollY),width:n.width,height:n.height}}const vt=/^[A-Za-z0-9_.:-]{1,100}$/;function L(n){return typeof n=="number"&&isFinite(n)}function bt(n){if(typeof n!="object"||n===null)return!1;const o=n;return o.section!==void 0&&(typeof o.section!="string"||!vt.test(o.section))?!1:typeof o.text=="string"&&typeof o.composite=="boolean"}function wt(n){if(typeof n!="object"||n===null)return!1;const o=n;return L(o.x)&&L(o.y)&&L(o.width)&&L(o.height)&&L(o.top)&&L(o.left)&&L(o.right)&&L(o.bottom)}function kt(n){if(typeof n!="object"||n===null)return null;const o=n;if(o.v!==1)return null;const s=o.type;if(s==="wid-inventory"){const r=o.widMap,l=o.scrollX,f=o.scrollY;if(typeof r!="object"||r===null||!L(l)||!L(f))return null;const c={};for(const[D,S]of Object.entries(r)){if(!wt(S))return null;c[D]=S}const h=o.blocks;if(h===void 0)return{v:1,type:"wid-inventory",widMap:c,scrollX:l,scrollY:f};if(typeof h!="object"||h===null)return null;const x={};for(const[D,S]of Object.entries(h)){if(!bt(S))return null;x[D]={text:S.text,composite:S.composite,...S.cut===!0?{cut:!0}:{},...S.section!==void 0?{section:S.section}:{}}}return{v:1,type:"wid-inventory",widMap:c,scrollX:l,scrollY:f,blocks:x}}if(s==="scroll-state"){const r=o.scrollX,l=o.scrollY;return!L(r)||!L(l)?null:{v:1,type:"scroll-state",scrollX:r,scrollY:l}}if(s==="scroll-ack"){const r=o.wid;if(typeof r!="string"||r==="")return null;const l=o.scrollX,f=o.scrollY,c=o.seq;return{v:1,type:"scroll-ack",wid:r,...L(l)&&L(f)?{scrollX:l,scrollY:f}:{},...typeof c=="number"&&Number.isInteger(c)&&c>0?{seq:c}:{}}}if(s==="wid-click"){const r=o.wid;return typeof r!="string"||r===""?null:{v:1,type:"wid-click",wid:r}}if(s==="wid-hover"){const r=o.wid;return r!==null&&(typeof r!="string"||r==="")?null:{v:1,type:"wid-hover",wid:r}}return null}const xt=Object.freeze({v:1,type:"request-inventory"});function At(n,o){return o===void 0?{v:1,type:"scroll-to-wid",wid:n}:{v:1,type:"scroll-to-wid",wid:n,seq:o}}const Et="request-inventory";function $t(n){return n.includes(Et)}const Ct=`
46
49
  (function () {
47
50
  if (window.__wickedInstrumentBridge) return;
48
51
  window.__wickedInstrumentBridge = 1;
@@ -120,10 +123,18 @@
120
123
  post(inventory());
121
124
  }
122
125
  })();
123
- `;function De(o){const r=`<script>${ze}<\/script>`;return/<\/body>/i.test(o)?o.replace(/<\/body>/i,()=>`${r}</body>`):`${o}${r}`}const O=String.raw`\s*-?(?:\d+(?:\.\d+)?|\.\d+)%?\s*`,Ke=new RegExp(`^(?:#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\((?:${O},){2}${O}(?:,${O})?\\)|hsla?\\(\\s*-?\\d+(?:\\.\\d+)?(?:deg)?\\s*,${O},${O}(?:,${O})?\\)|var\\(--wi-[a-z0-9-]{1,40}\\)|revert-layer)$`,"i");function Re(o,r=new Set){if(!Ke.test(o))return!1;const i=/^var\((--wi-[a-z0-9-]+)\)$/i.exec(o);return i===null||r.has(i[1].toLowerCase())}const Ye=[["--wi-bg","Background"],["--wi-surface","Surface"],["--wi-card-bg","Card"],["--wi-primary","Primary"],["--wi-secondary","Secondary"],["--wi-accent","Accent"],["--wi-text","Text"],["--wi-text-secondary","Secondary text"],["--wi-muted","Muted"],["--wi-border","Border"]],H="revert-layer";function Xe(o){const r=new Map;for(const p of o.matchAll(/(--wi-[a-z-]{1,40})\s*:\s*([^;}{]{1,80})/gi))r.set(p[1].toLowerCase(),p[2].trim());const i=new Set,c=[];for(const[p,d]of Ye){const u=r.get(p);if(u===void 0)continue;const w=u.startsWith("#")?u.toLowerCase():u;!Re(w)||i.has(w.toLowerCase())||(i.add(w.toLowerCase()),c.push({token:p,value:w,label:d}))}return c}const L="wicked.editor",C=1,je="wicked-page",Ne=[[390,"Phone"],[820,"Tablet"],[1280,"Desktop"]],U=34,We=[0,250,750,1500],Ie=`
126
+ `;function St(n){const o=`<script>${Ct}<\/script>`;return/<\/body>/i.test(n)?n.replace(/<\/body>/i,()=>`${o}</body>`):`${n}${o}`}const H=String.raw`\s*-?(?:\d+(?:\.\d+)?|\.\d+)%?\s*`,Tt=new RegExp(`^(?:#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\((?:${H},){2}${H}(?:,${H})?\\)|hsla?\\(\\s*-?\\d+(?:\\.\\d+)?(?:deg)?\\s*,${H},${H}(?:,${H})?\\)|var\\(--wi-[a-z0-9-]{1,40}\\)|revert-layer)$`,"i");function Ot(n,o=new Set){if(!Tt.test(n))return!1;const s=/^var\((--wi-[a-z0-9-]+)\)$/i.exec(n);return s===null||o.has(s[1].toLowerCase())}const Lt=[["--wi-bg","Background"],["--wi-surface","Surface"],["--wi-card-bg","Card"],["--wi-primary","Primary"],["--wi-secondary","Secondary"],["--wi-accent","Accent"],["--wi-text","Text"],["--wi-text-secondary","Secondary text"],["--wi-muted","Muted"],["--wi-border","Border"]],Ae="revert-layer";function Mt(n){const o=new Map;for(const l of n.matchAll(/(--wi-[a-z-]{1,40})\s*:\s*([^;}{]{1,80})/gi))o.set(l[1].toLowerCase(),l[2].trim());const s=new Set,r=[];for(const[l,f]of Lt){const c=o.get(l);if(c===void 0)continue;const h=c.startsWith("#")?c.toLowerCase():c;!Ot(h)||s.has(h.toLowerCase())||(s.add(h.toLowerCase()),r.push({token:l,value:h,label:f}))}return r}const te="wicked.editor",ne=1,We=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),Bt=["card","options","full"];function Ft(n){return n==="inline"?"card":n==="pane"?"options":"full"}function _t(n){return n==="card"?"inline":n==="options"?"pane":"full"}function Rt(n){const o=We(n)?n:{},s=o.size==="inline"||o.size==="full"?o.size:"pane",r=o.protocol===2?2:1,l=r===2&&typeof o.tab=="string"?o.tab:null,f=r===2&&Bt.includes(o.surface)?o.surface:Ft(s),c=f==="options"&&l===null?"full":f,h=r===2&&(o.mode==="simple"||o.mode==="advanced")?o.mode:null;return{protocol:r,surface:c,tab:l,mode:h,size:s}}function zt(n,o,s){return{editor:n,version:o,protocol:[1,2],surfaces:s}}function Dt(n,o){const s=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:te,v:ne,type:"plugin.ready",payload:zt(n,s,o)},"*")}function qt(n,o,s){const r=n.metaKey||n.ctrlKey;let l=null;if(n.key==="Escape")l="Escape";else if(r&&!n.altKey&&n.key.toLowerCase()==="k")l="Mod+K";else if(n.altKey&&!r&&/^Key[A-Z]$/.test(n.code)&&Ye(`Alt+${n.code.slice(3)}`))l=`Alt+${n.code.slice(3)}`;else if(n.key==="Tab"){const f=Array.from(o.querySelectorAll("button, input, select, textarea, [tabindex]")).filter(h=>h.tabIndex>=0&&!h.matches(":disabled")&&h.closest("[hidden]")===null),c=f.indexOf(n.target);(n.shiftKey?c<=0:c===-1||c===f.length-1)&&(l=n.shiftKey?"Shift+Tab":"Tab")}return l===null?!1:(n.preventDefault(),n.stopPropagation(),s(l),!0)}class Kt{constructor(o,s){lt(this,"revs",new Map);this.port=o,this.h=s}reply(o,s){this.port.postMessage({p:te,v:ne,re:o,ok:!0,payload:s})}refuse(o,s,r){this.port.postMessage({p:te,v:ne,re:o,ok:!1,error:{code:s,message:r}})}bump(o){const s=(this.revs.get(o)??0)+1;return this.revs.set(o,s),s}values(o,s){this.port.postMessage({p:te,v:ne,type:"options.values",payload:{tab:o,rev:this.bump(o),values:s}})}height(o){this.port.postMessage({p:te,v:ne,type:"ui.height",payload:{px:Math.round(o)}})}dispatch(o){const s=We(o.payload)?o.payload:{},r=typeof o.id=="string"?o.id:null;switch(o.type){case"host.surface":{const l=s.surface;return(l==="card"||l==="options"||l==="full")&&this.h.surface?.(l,s.mode==="simple"||s.mode==="advanced"?s.mode:null),!0}case"host.mode":{if(r===null)return!0;const l=s.mode;return l!=="simple"&&l!=="advanced"?(this.refuse(r,"bad_request","mode is simple or advanced"),!0):(this.reply(r,{mode:this.h.mode?.(l)??l}),!0)}case"host.action":{if(r===null)return!0;const l=s.id;return typeof l!="string"||this.h.action===void 0?(this.reply(r,{handled:!1}),!0):(Promise.resolve(this.h.action(l)).then(f=>this.reply(r,{handled:f.handled===!0,...typeof f.status=="string"?{status:f.status.slice(0,120)}:{}}),()=>this.reply(r,{handled:!1})),!0)}case"host.tab":return typeof s.tab=="string"&&this.h.tab?.(s.tab),!0;case"host.selection":return Array.isArray(s.anchors)&&this.h.selection?.(s.anchors),!0;case"options.changed":{if(r===null)return!0;const l=s.tab,f=s.id;return typeof l!="string"||typeof f!="string"||this.h.optionsChanged===void 0?(this.refuse(r,"unsupported","no controls here"),!0):(Promise.resolve(this.h.optionsChanged(l,f,s.value)).then(c=>this.reply(r,{applied:c.applied,rev:this.bump(l),values:c.values,...c.reason!==void 0?{reason:c.reason.slice(0,120)}:{}}),c=>this.refuse(r,"unavailable",c instanceof Error?c.message.slice(0,120):"failed")),!0)}default:return!1}}}const ce=[{name:"corporate-light",display_name:"Corporate Light",colors:{background:"#FFFFFF",surface:"#F8FAFC",primary:"#1E3A5F",secondary:"#2563EB",accent:"#0891B2",text_primary:"#1E293B",text_secondary:"#64748B",text_muted:"#94A3B8",border:"#E2E8F0"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}},{name:"midnight-purple",display_name:"Midnight Purple",colors:{background:"#0A0A0F",surface:"#13091D",primary:"#A100FF",secondary:"#6B2FA0",accent:"#F59E0B",text_primary:"#FFFFFF",text_secondary:"#A0A0B0",text_muted:"#6B6B80",border:"#2A2A3D"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}},{name:"warm-dark",display_name:"Warm Dark",colors:{background:"#1A1A2E",surface:"#16213E",primary:"#FF6B6B",secondary:"#C44569",accent:"#FFD93D",text_primary:"#F8F8F2",text_secondary:"#B0B0C0",text_muted:"#6B6B80",border:"#2D2D44"},fonts:{heading:"Calibri",body:"Calibri",mono:"Consolas"}}],He=["Inter","Roboto","Source Sans 3","IBM Plex Sans","Calibri","Georgia","system-ui"],Nt=[["background","Background"],["surface","Surface"],["primary","Primary"],["accent","Accent"],["text_primary","Text"]],Ee=n=>({name:n.name,colors:{...n.colors},fonts:{...n.fonts}});function jt(n,o){n.replaceChildren(),n.classList.add("plugin-style"),n.onkeydown=g=>{o.key!==void 0&&qt(g,n,o.key)};const s=document.createElement("style");s.textContent=`.plugin-style{padding:16px;box-sizing:border-box;color:var(--ink-high);background:var(--surface-base);font:13px var(--font-sans,system-ui)}
127
+ .plugin-style h2{font-size:16px;margin:0 0 12px}.plugin-style .theme-cards{display:grid;gap:8px;margin-bottom:18px}
128
+ .plugin-style button,.plugin-style input,.plugin-style select{font:inherit;color:var(--ink-high);background:var(--surface-card);border:1px solid var(--border);border-radius:4px}
129
+ .plugin-style button{padding:8px;text-align:left;cursor:pointer}.plugin-style button:focus-visible,.plugin-style input:focus-visible,.plugin-style select:focus-visible{outline:2px solid var(--accent)}
130
+ .plugin-style .ps-swatches{display:flex;width:100%;height:16px;margin-bottom:6px;border:1px solid var(--border)}.plugin-style .ps-swatches span{flex:1}
131
+ .plugin-style label{display:flex;align-items:center;gap:8px;margin:10px 0}.plugin-style label>span:first-child{flex:1}.plugin-style input[type=color]{width:36px;height:30px;padding:2px}.plugin-style input[type=text]{width:80px;padding:5px}.plugin-style select{max-width:170px;padding:5px}
132
+ .plugin-style p{line-height:1.5;color:var(--ink-body)}.plugin-style [role=status]{min-height:1.5em}.plugin-style :disabled{opacity:.6;cursor:default}`,n.append(s);const r=document.createElement("h2");r.textContent="Style",n.append(r);const l=document.createElement("div");l.className="theme-cards",n.append(l);const f=document.createElement("p");f.setAttribute("role","status"),f.setAttribute("aria-live","polite");let c=!1;const h=[],x=()=>Ee(o.tokens()??ce[0]),D=[],S=[],F=()=>{const g=x();for(const{key:y,picker:k,hex:A}of D)A.value=g.colors[y],k.value=/^#[0-9a-f]{6}$/i.test(g.colors[y])?g.colors[y]:"";for(const{key:y,select:k}of S)k.value=He.includes(g.fonts[y])?g.fonts[y]:"system-ui";for(const y of Array.from(l.querySelectorAll("button")))y.setAttribute("aria-pressed",String(y.dataset.theme===g.name))},U=async g=>{if(!c){c=!0,h.forEach(y=>{y.disabled=!0}),f.textContent="Applying theme…";try{const y=await o.apply(g);f.textContent=y.ok?"Theme applied.":`Theme was not applied: ${y.reason}`}catch(y){f.textContent=`Theme was not applied: ${y instanceof Error?y.message:"unavailable"}`}finally{c=!1,h.forEach(y=>{y.disabled=!1}),F()}}};for(const g of ce){const y=document.createElement("button");y.type="button",y.dataset.theme=g.name;const k=document.createElement("span");k.className="ps-swatches",k.setAttribute("aria-hidden","true");for(const v of["background","surface","primary","secondary","accent"]){const b=document.createElement("span");b.style.backgroundColor=g.colors[v],k.append(b)}const A=document.createElement("span");A.textContent=g.display_name,y.append(k,A),y.addEventListener("click",()=>{U(Ee(g))}),l.append(y),h.push(y)}for(const[g,y]of Nt){const k=document.createElement("label"),A=document.createElement("span");A.textContent=y;const v=document.createElement("input");v.type="color",v.setAttribute("aria-label",y);const b=document.createElement("input");b.type="text",b.maxLength=7,b.setAttribute("aria-label",`${y} hex`);const M=Z=>{if(!/^#[0-9a-f]{6}$/i.test(Z)){f.textContent="Enter a six-digit hex colour: a # and six digits or letters a to f.",F();return}const _=x();_.name="custom",_.colors[g]=Z,U(_)};v.addEventListener("change",()=>M(v.value)),b.addEventListener("change",()=>M(b.value)),k.append(A,v,b),n.append(k),h.push(v,b),D.push({key:g,picker:v,hex:b})}for(const g of["heading","body"]){const y=document.createElement("label"),k=document.createElement("span");k.textContent=g==="heading"?"Heading font":"Body font";const A=document.createElement("select");A.setAttribute("aria-label",k.textContent);for(const v of He){const b=document.createElement("option");b.value=v,b.textContent=v,A.append(b)}A.addEventListener("change",()=>{const v=x();v.name="custom",v.fonts[g]=A.value,U(v)}),y.append(k,A),n.append(y),h.push(A),S.push({key:g,select:A})}const re=document.createElement("p");return re.textContent="Match a website or a PDF: the host's Match button under this tab",n.append(re,f),F(),{refresh:F}}function It(n){const o=new DOMParser().parseFromString(n,"text/html"),s=Array.from(o.querySelectorAll("style")).map(h=>h.textContent??"").join(`
133
+ `),r=new Map;for(const h of s.matchAll(/(--wi-[a-z-]+)\s*:\s*([^;}{]+)/gi))r.set(h[1].toLowerCase(),h[2].trim());if(r.size===0)return null;const l=Ee(ce[0]),f={background:"--wi-bg",surface:"--wi-surface",primary:"--wi-primary",secondary:"--wi-secondary",accent:"--wi-accent",text_primary:"--wi-text",text_secondary:"--wi-text-secondary",text_muted:"--wi-muted",border:"--wi-border"};for(const h of Object.keys(f)){const x=r.get(f[h]);x!==void 0&&/^(#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|hsl)a?\([0-9.,%\s]+\))$/i.test(x)&&(l.colors[h]=x)}for(const h of["heading","body","mono"]){const x=r.get(`--wi-font-${h}`);x!==void 0&&(l.fonts[h]=x.split(",")[0].trim().replace(/^['"]|['"]$/g,""))}const c=ce.find(h=>JSON.stringify(h.colors)===JSON.stringify(l.colors)&&JSON.stringify(h.fonts)===JSON.stringify(l.fonts));return l.name=c?.name??"custom",l}const oe="wicked.editor",de=1,Pt=[[390,"Phone"],[820,"Tablet"],[1280,"Desktop"]],$e=34,Xt=[0,250,750,1500],Yt=`
134
+ <div data-testid="page-style" id="style" class="style-pane" hidden></div>
124
135
  <div data-testid="page-editor" id="editor" class="editor" data-kind="page" data-head="" data-pickable="false" data-selected="" data-size="pane" data-width="" tabindex="0" role="application" aria-label="The page">
125
136
  <div data-testid="page-tools" id="tools" class="tools" role="toolbar" aria-label="Page width">
126
- ${Ne.map(([o,r])=>`<button type="button" data-testid="page-width" data-width="${o}" aria-pressed="false" title="${r} · ${o} px wide">${r} ${o}</button>`).join("")}
137
+ ${Pt.map(([n,o])=>`<button type="button" data-testid="page-width" data-width="${n}" aria-pressed="false" title="${o} · ${n} px wide">${o} ${n}</button>`).join("")}
127
138
  </div>
128
139
  <div id="stage" class="stage"></div>
129
140
  <div data-testid="page-hover-box" id="hover" class="box box--hover" hidden></div>
@@ -138,7 +149,13 @@
138
149
  <span class="swatches" data-testid="page-swatches" data-prop="background" id="fills"><span class="word">Fill</span></span>
139
150
  <span class="swatches" data-testid="page-swatches" data-prop="color" id="inks"><span class="word">Text</span></span>
140
151
  </div>
141
- </div>`;function v(o){const r=document.getElementById(o);if(r===null)throw new Error(`wicked-page: no #${o}`);return r}function oe(o,r){const i=o?.blocks[r];return o===null||o.widMap[r]===void 0||i===void 0?"unmeasured":i.composite?"container":i.cut===!0?"cut":"yes"}function F(o){return`${o.charAt(0).toUpperCase()}${o.slice(1)}`}function re(){document.body.insertAdjacentHTML("afterbegin",Ie);const o=v("editor"),r=v("stage");let i=null;const c=v("hover"),p=v("selected"),d=v("input"),u=v("handle"),w=v("hint"),z=v("note"),E=v("tools"),y=v("peek"),le=v("to-section"),_e=v("remove"),qe=v("fills"),Be=v("inks");let A=null,ie=[],S="pane",Pe=0;const Z=new Map,T=(e,t)=>{A?.postMessage({p:L,v:C,type:e,payload:t})},se=(e,t)=>new Promise(n=>{if(A===null){n({ok:!1,error:{code:"unavailable",message:"no host yet"}});return}const l=`wp-${++Pe}`;Z.set(l,n),A.postMessage({p:L,v:C,type:e,id:l,payload:t})}),X=e=>T("ui.status",{line:e.slice(0,120)});let x=null,h=null,j={scrollX:0,scrollY:0},N=null,s=null,b=null,k=!1,ae=[],$=null,V=0,ce=-1,D=null,G=null,de=0,W=[],Q=!1,J=null,I=null;const ue=e=>{i?.contentWindow?.postMessage(e,"*")},He=e=>{if(e===i){ce=V;for(const t of W)clearTimeout(t);W=We.map(t=>setTimeout(()=>ue(Me),t))}},Ue=e=>{const t=document.createElement("iframe");for(const[l,f]of Object.entries({"data-testid":"page-frame",sandbox:"allow-scripts",title:"The page",class:"frame"}))t.setAttribute(l,f);t.addEventListener("load",()=>He(t));const n=i;i=t;for(const l of W)clearTimeout(l);t.srcdoc=e,r.appendChild(t),n?.remove(),_()},pe=()=>{const e=S==="inline"?0:U;if($===null)return{x:0,y:e,s:1};const t=r.clientWidth,n=t>0?Math.min(1,t/$):1;return{x:Math.max(0,(t-$*n)/2),y:e,s:n}},_=()=>{r.style.top=`${S==="inline"?0:U}px`,o.dataset.width=$===null?"":String($);for(const n of Array.from(E.querySelectorAll("[data-width]")))n.setAttribute("aria-pressed",String(Number(n.dataset.width)===$));if(i===null)return;if($===null){i.style.cssText="";return}const e=pe(),t=r.clientHeight>0?r.clientHeight/e.s:0;i.style.cssText=`position:absolute;left:${e.x}px;top:0;width:${$}px;${t>0?`height:${t}px;`:""}transform:scale(${e.s});transform-origin:0 0`},q=e=>{if(e===null||h===null)return null;const t=h.widMap[e];if(t===void 0)return null;const n=$e(t,h.measured,j),l=pe();return{left:l.x+n.left*l.s,top:l.y+n.top*l.s,width:n.width*l.s,height:n.height*l.s}},ee=(e,t,n=0,l=0)=>{if(t===null){e.hidden=!0;return}e.hidden=!1,e.style.left=`${t.left}px`,e.style.top=`${t.top}px`,e.style.width=`${Math.max(t.width,n)}px`,e.style.height=`${Math.max(t.height,l)}px`},te=()=>S!=="inline"&&h!==null,m=()=>{if(o.dataset.head=x===null?"":String(x),o.dataset.pickable=String(te()),o.dataset.selected=s??"",o.dataset.size=S,ee(c,N!==s&&b===null?q(N):null),p.dataset.wid=s??"",ee(p,b===null?q(s):null),b!==null?ee(d,q(b.wid),160,30):d.hidden=!0,E.hidden=S==="inline",Fe(),!te()||b!==null){w.hidden=!0;return}if(w.hidden=!1,s===null){w.removeAttribute("data-editable"),w.textContent="Click an element to make it the subject · type on it to change it";return}const e=Y(s),t=oe(h,s);w.dataset.editable=String(t==="yes"),w.textContent=t==="yes"?`Type to change ${e} · Enter to edit its text · Esc to let go`:t==="container"?`${F(e)} holds other parts — click a line of text inside it to change the words · Esc to let go`:t==="cut"?`${F(e)} is too long to change by typing — say what to change in the message box · Esc to let go`:`${F(e)} can’t be changed by typing — say what to change in the message box · Esc to let go`},Fe=()=>{const e=te()&&b===null&&!k?q(s):null;if(e===null||s===null){y.hidden=!0;return}y.hidden=!1,le.hidden=h?.blocks[s]?.section===void 0;const t=y.offsetHeight||30,n=e.top+e.height+6,l=o.clientHeight===0||n+t<=o.clientHeight-4,f=y.offsetWidth,a=o.clientWidth>0?o.clientWidth-f-4:1/0;y.style.left=`${Math.max(4,Math.min(e.left,a))}px`,y.style.top=`${l?n:Math.max(U+2,e.top-t-6)}px`},fe=(e,t)=>{for(const l of Array.from(e.querySelectorAll("button")))l.remove();const n=(l,f)=>{const a=document.createElement("button");a.type="button",a.className=l===H?"swatch swatch--default":"swatch";for(const[R,tt]of Object.entries({"data-testid":"page-swatch"}))a.setAttribute(R,tt);a.dataset.prop=t,a.dataset.value=l,a.title=`${t==="background"?"Fill":"Text"}: ${f}`,a.setAttribute("aria-label",a.title),l===H?a.textContent="Default":a.style.setProperty("--swatch",l),a.addEventListener("click",()=>{s!==null&&Ge(s,t,l,f)}),e.appendChild(a)};for(const l of ae)n(l.value,l.label);n(H,"Default")},M=()=>{b!==null&&(b=null,d.hidden=!0,d.value="",m())},B=e=>{s=e,M(),m(),e!==null&&(ie.includes("selection.chip")&&T("selection.set",{anchors:[{kind:"element",id:e}]}),u.focus())},Ze=e=>{de+=1,ue(Oe(e,de))},K=async e=>{if(Q){if(e!==void 0&&e===J)return;I=e===void 0?{}:{version:e};return}Q=!0,J=e??null;try{const t=await se("artifact.read",e===void 0?{}:{version:e});if(!t.ok){z.hidden=!1,z.textContent=t.error.code==="not_granted"?"This editor may not read the page here.":`The page could not be read (${t.error.code}).`;return}z.hidden=!0;const n=t.payload.content,l=typeof n?.html=="string"?n.html:"";x=typeof t.payload.version=="number"?t.payload.version:x,ae=Xe(l),fe(qe,"background"),fe(Be,"color"),V+=1,G=D,D=null,h=null,N=null,s=null,M(),m(),Ue(Ce(l)?l:De(l))}finally{if(Q=!1,J=null,I!==null){const t=I;I=null,(t.version===void 0||t.version!==x)&&K(t.version)}}};window.addEventListener("message",e=>{if(i===null||i.contentWindow===null||e.source!==i.contentWindow||ce!==V)return;const t=Te(e.data);if(t!==null){if(t.type==="wid-inventory"){for(const l of W)clearTimeout(l);h={widMap:t.widMap,blocks:t.blocks??{},measured:{scrollX:t.scrollX,scrollY:t.scrollY}},j={scrollX:t.scrollX,scrollY:t.scrollY};const n=G;G=null,n!==null&&t.widMap[n]!==void 0&&Ze(n),m()}else if(t.type==="scroll-state")j={scrollX:t.scrollX,scrollY:t.scrollY},m();else if(t.type==="scroll-ack")t.scrollX!==void 0&&t.scrollY!==void 0&&(j={scrollX:t.scrollX,scrollY:t.scrollY},m());else if(t.type==="wid-hover")N=t.wid,m();else if(t.type==="wid-click"){if(S==="inline")return;const n=t.wid===s?h?.blocks[t.wid]?.section:void 0;B(n!==void 0&&h?.widMap[n]!==void 0?n:t.wid)}}});const ye=(e,t)=>{if(k||h===null||oe(h,e)!=="yes")return;const n=h.blocks[e]?.text??"";b={wid:e,before:n},d.value=t??n,m(),d.focus(),t===null?d.select():d.setSelectionRange(d.value.length,d.value.length)},ne=async(e,t,n,l)=>{if(x===null||k)return;k=!0,m(),X(n);const f=l;try{const a=await se("version.write",{base:x,ops:e,summary:t});if(a.ok)D=f,await K(typeof a.payload.version=="number"?a.payload.version:void 0);else if(a.error.code==="stale"||a.error.code==="head_moved"){X(a.error.code==="stale"&&a.error.message?a.error.message:"Not changed: it moved while you typed"),D=f;const R=a.payload?.head;typeof R=="number"&&R!==x&&await K(R)}else a.error.code==="timeout"||(a.error.code==="refused"?X(a.error.message||"Nothing changed"):X(`Not changed: ${a.error.message||a.error.code}`))}finally{k=!1,m()}},Ve=async()=>{if(b===null||x===null||k)return;const{wid:e,before:t}=b,n=d.value.replace(/\s*\n\s*/g," ");if(M(),u.focus(),n===t)return;const l=Y(e);await ne([{op:"text",anchor:e,value:n,before:t}],l,`Changing ${l}…`,e)},he=async e=>{if(k||h?.widMap[e]===void 0)return;const t=Y(e),n=h.blocks[e]?.section??null;u.focus(),await ne([{op:"remove",anchor:e}],t,`Removing ${t}…`,n)},Ge=async(e,t,n,l)=>{if(k||h?.widMap[e]===void 0)return;const f=Y(e);u.focus(),await ne([{op:"style",anchor:e,style:{[t]:n}}],f,`${t==="background"?"Filling":"Colouring the text of"} ${f}: ${l.toLowerCase()}…`,e)},we=e=>{const t=h?.blocks[e]?.section;return t===void 0||h?.widMap[t]===void 0?!1:(B(t),!0)};le.addEventListener("click",()=>{s!==null&&we(s)}),_e.addEventListener("click",()=>{s!==null&&he(s)});for(const e of Array.from(E.querySelectorAll("[data-width]")))e.addEventListener("click",()=>{const t=Number(e.dataset.width);$=$===t?null:t,_(),m()});window.addEventListener("resize",()=>{_(),m()}),d.addEventListener("keydown",e=>{e.stopPropagation(),e.key==="Enter"?(e.preventDefault(),Ve()):e.key==="Escape"&&(e.preventDefault(),M(),u.focus())}),d.addEventListener("blur",()=>{M()});const Qe=()=>[...Array.from(E.querySelectorAll("button")).filter(()=>!E.hidden),u,...Array.from(y.querySelectorAll("button")).filter(e=>!y.hidden&&!e.hidden)];o.addEventListener("keydown",e=>{if(e.target===d)return;const t=e.target?.tagName==="BUTTON";if(!(t&&(e.key==="Enter"||e.key===" "))){if(e.key==="Escape"){if(s!==null){e.preventDefault(),B(null);return}e.preventDefault(),T("ui.key",{key:"Escape"});return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="k"){e.preventDefault(),T("ui.key",{key:"Mod+K"});return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key==="Backspace"||e.key==="Delete")){e.preventDefault(),s!==null&&!k&&he(s);return}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&e.key==="ArrowUp"){e.preventDefault(),s!==null&&we(s);return}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&/^Key[A-Z]$/.test(e.code)){e.preventDefault(),T("ui.key",{key:`Alt+${e.code.slice(3)}`});return}if(e.key==="Tab"){e.preventDefault();const n=Qe(),l=n.indexOf(document.activeElement),f=l===-1&&document.activeElement===o&&!e.shiftKey?0:l+(e.shiftKey?-1:1);if(l===-1&&f!==0||f<0||f>=n.length){T("ui.key",{key:e.shiftKey?"Shift+Tab":"Tab"});return}n[f].focus();return}if(!(e.metaKey||e.ctrlKey||e.altKey)&&!(t&&e.key.length!==1)){if(e.key==="Enter"){s!==null&&!k&&(e.preventDefault(),ye(s,null));return}if(e.key.length===1){if(e.preventDefault(),s!==null&&!k){ye(s,e.key);return}T("ui.typed",{grapheme:e.key})}}}});const ge=e=>{S=e,document.body.dataset.size=e,e==="inline"&&(M(),B(null),document.activeElement?.blur?.()),_(),m()},ve=e=>{if(!(typeof e!="object"||e===null))for(const[t,n]of Object.entries(e))/^--[a-z0-9-]+$/.test(t)&&typeof n=="string"&&n.length<=200&&!/url\(/i.test(n)&&document.documentElement.style.setProperty(t,n)},Je=e=>{const t=e.data;try{if(t===null||typeof t!="object"||t.p!==L||t.v!==C)return;if(typeof t.re=="string"){const l=Z.get(t.re);if(l===void 0)return;Z.delete(t.re);const f=typeof t.payload=="object"&&t.payload!==null?t.payload:{};t.ok===!0?l({ok:!0,payload:f}):l({ok:!1,error:t.error??{code:"unavailable",message:"no answer"},payload:f});return}const n=typeof t.payload=="object"&&t.payload!==null?t.payload:{};switch(t.type){case"host.ping":typeof t.id=="string"&&A?.postMessage({p:L,v:C,re:t.id,ok:!0,payload:{}});return;case"host.size":(n.size==="inline"||n.size==="pane"||n.size==="full")&&ge(n.size);return;case"host.theme":ve(n.theme);return;case"artifact.changed":{const l=n.version;typeof l=="number"&&l!==x&&(D=D??s,K(l));return}case"selection.cleared":s!==null&&(s=null,M(),m());return;default:return}}catch{}};window.addEventListener("message",e=>{const t=e.data;if(A!==null||t===null||typeof t!="object"||t.p!==L||t.type!=="host.hello"||e.ports[0]===void 0)return;A=e.ports[0],A.onmessage=Je;const n=typeof t.payload=="object"&&t.payload!==null?t.payload:{};ie=Array.isArray(n.grants)?n.grants.filter(l=>typeof l=="string"):[],ve(n.theme),ge(n.size==="inline"||n.size==="full"?n.size:"pane"),K()});const et=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:L,v:C,type:"plugin.ready",payload:{editor:je,version:et,protocol:[C]}},"*")}return re(),P.start=re,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"}),P})({});
152
+ </div>`;function O(n){const o=document.getElementById(n);if(o===null)throw new Error(`wicked-page: no #${n}`);return o}function Ue(n,o){const s=n?.blocks[o];return n===null||n.widMap[o]===void 0||s===void 0?"unmeasured":s.composite?"container":s.cut===!0?"cut":"yes"}function Ce(n){return`${n.charAt(0).toUpperCase()}${n.slice(1)}`}function Wt(n){document.body.insertAdjacentHTML("afterbegin",Yt);const o=O("editor");o.dataset.kind=n.kind,o.setAttribute("aria-label",n.kind==="document"?"The document":"The page");const s=O("stage");let r=null;const l=O("hover"),f=O("selected"),c=O("input"),h=O("handle"),x=O("hint"),D=O("note"),S=O("tools"),F=O("peek"),U=O("to-section"),re=O("remove"),g=O("fills"),y=O("inks");let k=null,A=[],v="pane",b=1,M="options",Z="style",_="simple",Se=null;const se=()=>b===1?v!=="inline":M==="full",J=()=>se()&&(b===1||_==="advanced");let ue=null,Ut=0;const Te=new Map,j=(e,t)=>{k?.postMessage({p:oe,v:de,type:e,payload:t})},ie=(e,t)=>new Promise(i=>{if(k===null){i({ok:!1,error:{code:"unavailable",message:"no host yet"}});return}const a=`wp-${++Ut}`;Te.set(a,i),k.postMessage({p:oe,v:de,type:e,id:a,payload:t})}),pe=e=>j("ui.status",{line:e.slice(0,120)});let C=null,Oe=Object.create(null),V=null,Le=0,ae=!1,Me=!1,X=null;const w=n.coverage?document.createElement("aside"):null;if(w!==null){w.id="coverage",w.dataset.testid="doc-coverage",w.setAttribute("aria-label","Requirements"),w.hidden=!0,document.body.append(w);const e=document.createElement("style");e.textContent=`#coverage{box-sizing:border-box;height:100%;overflow:auto;padding:16px;color:var(--ink-high);background:var(--surface-base);font:13px var(--font-sans,system-ui)}
153
+ #coverage h2{font-size:16px;margin:0 0 12px}#coverage p{color:var(--ink-muted);line-height:1.5}
154
+ #coverage button{display:block;width:100%;padding:10px 8px;text-align:left;font:inherit;color:var(--ink-high);background:var(--surface-card);border:1px solid var(--border);border-radius:4px;margin:6px 0;cursor:pointer}
155
+ #coverage button:disabled{cursor:default}#coverage button:focus-visible{outline:2px solid var(--accent)}
156
+ #coverage p button{display:inline;width:auto;padding:0;margin:0;border:0;background:transparent;color:var(--accent);text-decoration:underline}
157
+ body[data-coverage="side"] .editor{width:calc(100% - min(300px,38%))}
158
+ body[data-coverage="side"] #coverage{position:absolute;right:0;top:0;width:min(300px,38%);border-left:1px solid var(--border)}`,document.body.append(e)}const fe=()=>{if(w===null)return;if(w.replaceChildren(),delete w.dataset.total,delete w.dataset.rows,delete w.dataset.named,ae){const p=document.createElement("p");p.textContent="Couldn't read the requirements · ";const $=document.createElement("button");$.type="button",$.textContent="Try again",$.addEventListener("click",()=>{Be()}),p.append($),w.append(p);return}if(V===null){const p=document.createElement("p");p.textContent="Reading requirements…",w.append(p);return}if(V.length===0){const p=document.createElement("p");p.textContent="No requirements for this document's repository",w.append(p);return}const e=ut(V.map(p=>({key:p.id,reqId:p.id,title:p.text,risk:!1})),Oe),t=e.filter(p=>p.wid!==null),i=e.filter(p=>p.wid===null);w.dataset.total=String(Le),w.dataset.rows=String(e.length),w.dataset.named=String(t.length);const a=document.createElement("h2");a.textContent="Requirements",w.append(a);const d=document.createElement("p");d.dataset.testid="doc-coverage-line",d.textContent=ft(e,Le),w.append(d);const u=(p,$)=>{if($.length===0)return;const le=document.createElement("p");le.textContent=`${p} (${$.length})`,w.append(le);for(const z of $){const P=document.createElement("button");P.type="button",P.dataset.testid="doc-coverage-row",P.dataset.req=z.reqId,P.dataset.named=String(z.wid!==null),P.disabled=z.wid===null,P.textContent=`${z.reqId} · ${z.title}${z.wid===null?"":` · ${ee(z.wid,n.kind)}`}`,P.addEventListener("click",()=>{if(z.wid!==null){if(M==="options"){A.includes("selection.chip")&&j("selection.set",{anchors:[{kind:"element",id:z.wid}]});return}Q(z.wid,!0),ke(z.wid)}}),w.append(P)}};u("Not named",i),u("Named",t)},Be=async()=>{if(!(!n.coverage||V!==null||Me)){Me=!0,ae=!1,fe();try{const e=await ie("checks.read",{}),t=e.ok?e.payload.checks:null;if(!e.ok||!Array.isArray(t)){ae=!0;return}V=t.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.text=="string"),Le=typeof e.payload.total=="number"?e.payload.total:V.length}catch{ae=!0}finally{Me=!1,fe()}}},Zt=e=>{const t=new DOMParser().parseFromString(e,"text/html");Oe=Object.create(null);const i=Array.from(t.querySelectorAll("[data-wid]")),a=new Map;for(const d of i){const u=d.getAttribute("data-wid")??"";a.set(u,(a.get(u)??0)+1)}for(const d of i){const u=d.getAttribute("data-wid")??"";!/^[A-Za-z0-9_.:-]{1,100}$/.test(u)||a.get(u)!==1||(Oe[u]={text:(d.textContent??"").replace(/\s+/g," ").trim(),composite:d.querySelector("[data-wid]")!==null})}fe()};let E=null,he={scrollX:0,scrollY:0},ye=null,m=null,B=null,me=null,R=!1,Je=[],q=null,Fe=0,Ve=-1,G=null,_e=null,Ge=0,ge=[],Re=!1,ze=null,ve=null;const Qe=e=>{r?.contentWindow?.postMessage(e,"*")},Jt=e=>{if(e===r){Ve=Fe;for(const t of ge)clearTimeout(t);ge=Xt.map(t=>setTimeout(()=>Qe(xt),t))}},Vt=e=>{const t=document.createElement("iframe");for(const[a,d]of Object.entries({"data-testid":"page-frame",sandbox:"allow-scripts",title:n.kind==="document"?"The document":"The page",class:"frame"}))t.setAttribute(a,d);t.addEventListener("load",()=>Jt(t));const i=r;r=t;for(const a of ge)clearTimeout(a);t.srcdoc=e,s.appendChild(t),i?.remove(),be()},et=()=>{const e=v==="inline"?0:$e;if(q===null)return{x:0,y:e,s:1};const t=s.clientWidth,i=t>0?Math.min(1,t/q):1;return{x:Math.max(0,(t-q*i)/2),y:e,s:i}},be=()=>{s.style.top=`${v==="inline"?0:$e}px`,o.dataset.width=q===null?"":String(q);for(const i of Array.from(S.querySelectorAll("[data-width]")))i.setAttribute("aria-pressed",String(Number(i.dataset.width)===q));if(r===null)return;if(q===null){r.style.cssText="";return}const e=et(),t=s.clientHeight>0?s.clientHeight/e.s:0;r.style.cssText=`position:absolute;left:${e.x}px;top:0;width:${q}px;${t>0?`height:${t}px;`:""}transform:scale(${e.s});transform-origin:0 0`},we=e=>{if(e===null||E===null)return null;const t=E.widMap[e];if(t===void 0)return null;const i=gt(t,E.measured,he),a=et();return{left:a.x+i.left*a.s,top:a.y+i.top*a.s,width:i.width*a.s,height:i.height*a.s}},De=(e,t,i=0,a=0)=>{if(t===null){e.hidden=!0;return}e.hidden=!1,e.style.left=`${t.left}px`,e.style.top=`${t.top}px`,e.style.width=`${Math.max(t.width,i)}px`,e.style.height=`${Math.max(t.height,a)}px`},qe=()=>(v!=="inline"||b>=2&&M==="card")&&E!==null,T=()=>{if(o.dataset.head=C===null?"":String(C),o.dataset.pickable=String(qe()),o.dataset.selected=m??"",o.dataset.size=v,De(l,ye!==m&&B===null?we(ye):null),f.dataset.wid=m??"",De(f,B===null?we(m):null),B!==null?De(c,we(B.wid),160,30):c.hidden=!0,S.hidden=v==="inline",o.dataset.mode=b>=2?_:"",re.hidden=!J(),g.hidden=!J(),y.hidden=!J(),Gt(),!se()||!qe()||B!==null){x.hidden=!0;return}if(x.hidden=!1,m===null){x.removeAttribute("data-editable"),x.textContent="Click an element to make it the subject · type on it to change it";return}const e=ee(m,n.kind),t=Ue(E,m);x.dataset.editable=String(t==="yes"),x.textContent=t==="yes"?`Type to change ${e} · Enter to edit its text · Esc to let go`:t==="container"?`${Ce(e)} holds other parts — click a line of text inside it to change the words · Esc to let go`:t==="cut"?`${Ce(e)} is too long to change by typing — say what to change in the message box · Esc to let go`:`${Ce(e)} can’t be changed by typing — say what to change in the message box · Esc to let go`},Gt=()=>{const e=J()&&qe()&&B===null&&!R?we(m):null;if(e===null||m===null){F.hidden=!0;return}F.hidden=!1,U.hidden=E?.blocks[m]?.section===void 0;const t=F.offsetHeight||30,i=e.top+e.height+6,a=o.clientHeight===0||i+t<=o.clientHeight-4,d=F.offsetWidth,u=o.clientWidth>0?o.clientWidth-d-4:1/0;F.style.left=`${Math.max(4,Math.min(e.left,u))}px`,F.style.top=`${a?i:Math.max($e+2,e.top-t-6)}px`},tt=(e,t)=>{for(const a of Array.from(e.querySelectorAll("button")))a.remove();const i=(a,d)=>{const u=document.createElement("button");u.type="button",u.className=a===Ae?"swatch swatch--default":"swatch";for(const[p,$]of Object.entries({"data-testid":"page-swatch"}))u.setAttribute(p,$);u.dataset.prop=t,u.dataset.value=a,u.title=`${t==="background"?"Fill":"Text"}: ${d}`,u.setAttribute("aria-label",u.title),a===Ae?u.textContent="Default":u.style.setProperty("--swatch",a),u.addEventListener("click",()=>{m!==null&&en(m,t,a,d)}),e.appendChild(u)};for(const a of Je)i(a.value,a.label);i(Ae,"Default")},I=()=>{if(B===null)return;B=null,c.hidden=!0,c.value="";const e=me;me=null,e!==null&&Ke(e),T()},Q=(e,t=!1)=>{X=null,m=e,I(),T(),e!==null&&(A.includes("selection.chip")&&j("selection.set",{anchors:[{kind:"element",id:e}]}),t||h.focus())},ke=e=>{Ge+=1,Qe(At(e,Ge))},Ke=e=>{const t=e.version;if(typeof t=="number"&&C!==null&&t<C)return;if(B!==null){const d=me?.version;typeof t=="number"&&t>B.base&&(typeof d!="number"||t>=d)&&(me=e);return}D.hidden=!0;const i=e.content,a=typeof i?.html=="string"?i.html:"";n.coverage&&Zt(a),C=typeof t=="number"?t:C,Je=Mt(a),ue=It(a)??ue,Ie?.refresh(),tt(g,"background"),tt(y,"color"),Fe+=1,_e=G,G=null,E=null,ye=null,m=null,I(),T(),Vt($t(a)?a:St(a))},Y=async e=>{if(Re){if(e!==void 0&&e===ze)return;ve=e===void 0?{}:{version:e};return}Re=!0,ze=e??null;try{const t=await ie("artifact.read",e===void 0?{}:{version:e});if(!t.ok){D.hidden=!1,D.textContent=t.error.code==="not_granted"?`This editor may not read the ${n.kind} here.`:`The ${n.kind} could not be read (${t.error.code}).`;return}Ke(t.payload)}finally{if(Re=!1,ze=null,ve!==null){const t=ve;ve=null,(t.version===void 0||t.version!==C)&&Y(t.version)}}};window.addEventListener("message",e=>{if(r===null||r.contentWindow===null||e.source!==r.contentWindow||Ve!==Fe)return;const t=kt(e.data);if(t!==null){if(t.type==="wid-inventory"){for(const a of ge)clearTimeout(a);E={widMap:t.widMap,blocks:t.blocks??{},measured:{scrollX:t.scrollX,scrollY:t.scrollY}},he={scrollX:t.scrollX,scrollY:t.scrollY};const i=_e;_e=null,i!==null&&t.widMap[i]!==void 0&&ke(i),X!==null&&t.widMap[X]!==void 0&&(m=X,n.coverage&&ke(X)),T()}else if(t.type==="scroll-state")he={scrollX:t.scrollX,scrollY:t.scrollY},T();else if(t.type==="scroll-ack")t.scrollX!==void 0&&t.scrollY!==void 0&&(he={scrollX:t.scrollX,scrollY:t.scrollY},T());else if(t.type==="wid-hover")ye=t.wid,T();else if(t.type==="wid-click"){if(b===1&&v==="inline")return;if(b===2&&M==="card"){Q(t.wid);return}const i=t.wid===m?E?.blocks[t.wid]?.section:void 0;Q(i!==void 0&&E?.widMap[i]!==void 0?i:t.wid)}}});const nt=(e,t)=>{if(!se()||R||C===null||E===null||Ue(E,e)!=="yes")return;const i=E.blocks[e]?.text??"";B={wid:e,before:i,base:C},c.value=t??i,T(),c.focus(),t===null?c.select():c.setSelectionRange(c.value.length,c.value.length)},Ne=async(e,t,i,a,d=C)=>{if(C===null||R)return;R=!0,T(),pe(i);const u=a;try{const p=await ie("version.write",{base:d,ops:e,summary:t});if(p.ok)G=u,await Y(typeof p.payload.version=="number"?p.payload.version:void 0);else if(p.error.code==="stale"||p.error.code==="head_moved"){pe(p.error.code==="stale"&&p.error.message?p.error.message:"Not changed: it moved while you typed"),G=u;const $=p.payload?.head;p.error.code==="head_moved"?await Y(typeof $=="number"?$:void 0):typeof $=="number"&&$!==C&&await Y($)}else p.error.code==="timeout"||(p.error.code==="refused"?pe(p.error.message||"Nothing changed"):pe(`Not changed: ${p.error.message||p.error.code}`))}finally{R=!1,T()}},Qt=async()=>{if(B===null||C===null||R)return;const{wid:e,before:t,base:i}=B,a=c.value.replace(/\s*\n\s*/g," ");if(I(),h.focus(),a===t)return;const d=ee(e,n.kind);await Ne([{op:"text",anchor:e,value:a,before:t}],d,`Changing ${d}…`,e,i)},ot=async e=>{if(!J()||R||E?.widMap[e]===void 0)return;const t=ee(e,n.kind),i=E.blocks[e]?.section??null;h.focus(),await Ne([{op:"remove",anchor:e}],t,`Removing ${t}…`,i)},en=async(e,t,i,a)=>{if(!J()||R||E?.widMap[e]===void 0)return;const d=ee(e,n.kind);h.focus(),await Ne([{op:"style",anchor:e,style:{[t]:i}}],d,`${t==="background"?"Filling":"Colouring the text of"} ${d}: ${a.toLowerCase()}…`,e)},rt=e=>{const t=E?.blocks[e]?.section;return t===void 0||E?.widMap[t]===void 0?!1:(Q(t),!0)};U.addEventListener("click",()=>{m!==null&&rt(m)}),re.addEventListener("click",()=>{m!==null&&ot(m)});for(const e of Array.from(S.querySelectorAll("[data-width]")))e.addEventListener("click",()=>{const t=Number(e.dataset.width);q=q===t?null:t,be(),T()});window.addEventListener("resize",()=>{be(),T()}),c.addEventListener("keydown",e=>{e.stopPropagation(),e.key==="Enter"?(e.preventDefault(),Qt()):e.key==="Escape"&&(e.preventDefault(),I(),h.focus())}),c.addEventListener("blur",()=>{I()});const tn=()=>[...Array.from(S.querySelectorAll("button")),h,...Array.from(F.querySelectorAll("button")),...Array.from(w?.querySelectorAll("button")??[])].filter(e=>e.closest("[hidden]")===null&&!(e instanceof HTMLButtonElement&&e.disabled)),st=(e,t)=>{if(e.target===c)return;const i=e.target?.tagName==="BUTTON";if(!(i&&(e.key==="Enter"||e.key===" "))){if(e.key==="Escape"){if(!t&&m!==null){e.preventDefault(),Q(null);return}e.preventDefault(),j("ui.key",{key:"Escape"});return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="k"){e.preventDefault(),j("ui.key",{key:"Mod+K"});return}if(!t&&(e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key==="Backspace"||e.key==="Delete")){e.preventDefault(),m!==null&&!R&&ot(m);return}if(!t&&e.altKey&&!e.metaKey&&!e.ctrlKey&&e.key==="ArrowUp"){e.preventDefault(),m!==null&&rt(m);return}if(e.altKey&&!e.metaKey&&!e.ctrlKey&&/^Key[A-Z]$/.test(e.code)&&Ye(`Alt+${e.code.slice(3)}`)){e.preventDefault(),j("ui.key",{key:`Alt+${e.code.slice(3)}`});return}if(e.key==="Tab"){e.preventDefault();const a=tn(),d=a.indexOf(document.activeElement),u=d===-1&&document.activeElement===o&&!e.shiftKey?0:d+(e.shiftKey?-1:1);if(d===-1&&u!==0||u<0||u>=a.length){j("ui.key",{key:e.shiftKey?"Shift+Tab":"Tab"});return}a[u].focus();return}if(!(e.metaKey||e.ctrlKey||e.altKey)&&!(i&&e.key.length!==1)){if(e.key==="Enter"){!t&&m!==null&&!R&&se()&&(e.preventDefault(),nt(m,null));return}if(e.key.length===1){if(e.preventDefault(),!t&&m!==null&&!R&&se()){nt(m,e.key);return}j("ui.typed",{grapheme:e.key})}}}};o.addEventListener("keydown",e=>st(e,!1)),w?.addEventListener("keydown",e=>st(e,!0));const je=e=>{v=e,document.body.dataset.size=e,e==="inline"&&(I(),b<2&&Q(null),document.activeElement?.blur?.()),be(),T()},it=e=>{if(!(typeof e!="object"||e===null))for(const[t,i]of Object.entries(e))/^--[a-z0-9-]+$/.test(t)&&typeof i=="string"&&i.length<=200&&!/url\(/i.test(i)&&document.documentElement.style.setProperty(t,i)},nn=e=>{const t=e.data;try{if(t===null||typeof t!="object"||t.p!==oe||t.v!==de)return;if(typeof t.re=="string"){const a=Te.get(t.re);if(a===void 0)return;Te.delete(t.re);const d=typeof t.payload=="object"&&t.payload!==null?t.payload:{};t.ok===!0?a({ok:!0,payload:d}):a({ok:!1,error:t.error??{code:"unavailable",message:"no answer"},payload:d});return}if(Se!==null&&Se.dispatch(t))return;const i=typeof t.payload=="object"&&t.payload!==null?t.payload:{};switch(t.type){case"host.ping":typeof t.id=="string"&&k?.postMessage({p:oe,v:de,re:t.id,ok:!0,payload:{}});return;case"host.size":(i.size==="inline"||i.size==="pane"||i.size==="full")&&je(i.size);return;case"host.theme":it(i.theme);return;case"artifact.changed":{ae&&Be();const a=i.version;typeof a=="number"&&a!==C&&(G=G??m,Y(a));return}case"selection.cleared":X=null,m!==null&&(m=null,I(),T());return;default:return}}catch{}};window.addEventListener("message",e=>{const t=e.data;if(k!==null||t===null||typeof t!="object"||t.p!==oe||t.type!=="host.hello"||e.ports[0]===void 0)return;k=e.ports[0],k.onmessage=nn;const i=typeof t.payload=="object"&&t.payload!==null?t.payload:{};A=Array.isArray(i.grants)?i.grants.filter(d=>typeof d=="string"):[],it(i.theme);const a=Rt(i);b=a.protocol,b>=2?(M=i.surface==="options"?"options":a.surface,Z=a.tab??"style",_=a.mode??"simple",Se=new Kt(k,{surface:(d,u)=>{M=d,u!==null&&(_=u),xe()},mode:d=>(_=d,n.coverage?xe():T(),_),tab:d=>{n.coverage&&(Z=d,xe())},selection:d=>{const u=d.find(p=>typeof p=="object"&&p!==null&&p.kind==="element"&&typeof p.id=="string");M==="options"&&u!==void 0||(X=u?.id??null,m=u!==void 0&&E?.widMap[u.id]!==void 0?u.id:null,m!==null&&n.coverage&&ke(m),I(),T())}}),xe()):je(a.size),Y()});const at=O("style");let Ie=null;const xe=()=>{const e=M==="options",t=n.coverage&&e&&Z==="coverage",i=n.coverage&&M==="full"&&_==="advanced";n.coverage&&(document.body.dataset.coverage=i?"side":"",w!==null&&(w.hidden=!t&&!i),(t||i)&&(fe(),Be())),at.hidden=!e||t,o.hidden=e,e&&!t&&Ie===null&&(Ie=jt(at,{tokens:()=>ue,key:a=>j("ui.key",{key:a}),apply:async a=>{for(let d=0;d<2;d+=1){if(C===null)return{ok:!1,reason:`The ${n.kind} is not loaded yet`};const u=await ie("theme.set",{base:C,tokens:a});if(u.ok){const le=u.payload.version;return ue={name:a.name,colors:{...a.colors},fonts:{...a.fonts}},typeof le=="number"&&await Y(le),{ok:!0}}if(u.error.code!=="head_moved")return{ok:!1,reason:u.error.message};const p=await ie("artifact.read",{});if(!p.ok)return{ok:!1,reason:p.error.message||p.error.code};const $=p.payload.version;if(typeof $!="number"||C!==null&&$<C)return{ok:!1,reason:`The current ${n.kind} version could not be read.`};if(Ke(p.payload),d===1)return{ok:!1,reason:u.error.message||u.error.code}}return{ok:!1,reason:`The ${n.kind} changed again: try once more`}}})),je(_t(M))};Dt(n.editor,n.surfaces)}const Ht={card:{interactive:!0,aspect:"16:9",actions:[{id:"ask",label:"Ask about this",verb:"host:ask"}]},options:{tabs:[{id:"style",label:"Style",render:"plugin"}]},full:{modes:["simple","advanced"],default:"simple"}};function Ze(){Wt({editor:"wicked-page",surfaces:Ht,kind:"page",coverage:!1})}return Ze(),K.start=Ze,Object.defineProperty(K,Symbol.toStringTag,{value:"Module"}),K})({});
142
159
  </script>
143
160
  </body>
144
161
  </html>