@dotit/editor 1.1.0 → 1.2.0

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.
@@ -1,4 +1,5 @@
1
1
  import type { Editor } from "@tiptap/core";
2
+ import type { TrustState } from "./trust-state";
2
3
  import type { TrustAction } from "./types";
3
4
  interface Props {
4
5
  editor: Editor | null;
@@ -6,12 +7,21 @@ interface Props {
6
7
  onToggleRtl?: () => void;
7
8
  /** Current .it source — used by the export actions. */
8
9
  content: string;
10
+ /** Apply a new source (used by the self-contained trust control). */
11
+ onChange?: (source: string) => void;
9
12
  theme: string;
10
13
  onThemeChange: (theme: string) => void;
11
- /** Trust actions (Seal / Sign / Verify). The group is hidden when omitted. */
14
+ /**
15
+ * Optional host override for the Trust control. When omitted the editor's own
16
+ * self-contained TrustControl handles sign/seal/verify/unseal via core.
17
+ */
12
18
  onTrustAction?: (action: TrustAction) => void;
19
+ /** Trust snapshot — drives the built-in TrustControl. */
20
+ trust?: TrustState;
21
+ /** verifyDocument().intact — null when not sealed. */
22
+ sealIntact?: boolean | null;
13
23
  /** Sealed documents are read-only — formatting groups are disabled. */
14
24
  locked?: boolean;
15
25
  }
16
- export declare function DocsToolbar({ editor, isRtl, onToggleRtl, content, theme, onThemeChange, onTrustAction, locked, }: Props): import("react/jsx-runtime").JSX.Element | null;
26
+ export declare function DocsToolbar({ editor, isRtl, onToggleRtl, content, onChange, theme, onThemeChange, onTrustAction, trust, sealIntact, locked, }: Props): import("react/jsx-runtime").JSX.Element | null;
17
27
  export {};
package/dist/Ruler.d.ts CHANGED
@@ -2,8 +2,22 @@ import type { PageGeometry } from "./page-geometry";
2
2
  interface RulerProps {
3
3
  geometry: PageGeometry;
4
4
  zoom: number;
5
- /** The scrollable canvas element — the ruler mirrors its horizontal scroll. */
5
+ /** The scrollable canvas element — the ruler mirrors its scroll. */
6
6
  scrollEl: React.RefObject<HTMLDivElement | null>;
7
+ /** Apply new margins (px) when a stop is dragged. Omit → read-only ruler. */
8
+ onMargins?: (next: {
9
+ top?: number;
10
+ right?: number;
11
+ bottom?: number;
12
+ left?: number;
13
+ }) => void;
14
+ /** Disable dragging (e.g. sealed document). */
15
+ locked?: boolean;
7
16
  }
8
- export declare function DocsRuler({ geometry, zoom, scrollEl }: RulerProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function DocsRuler({ geometry, zoom, scrollEl, onMargins, locked, }: RulerProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function DocsVerticalRuler({ geometry, zoom, scrollEl, onMargins, locked,
19
+ /** Extra px between the top of the scroll area and the page sheet top. */
20
+ topOffset, }: RulerProps & {
21
+ topOffset?: number;
22
+ }): import("react/jsx-runtime").JSX.Element;
9
23
  export {};
@@ -0,0 +1,13 @@
1
+ import type { TrustState } from "./trust-state";
2
+ interface Props {
3
+ /** Current .it source. */
4
+ content: string;
5
+ /** Apply a new source produced by a trust action. */
6
+ onChange: (source: string) => void;
7
+ /** Trust snapshot (drives the button label + which actions show). */
8
+ trust: TrustState;
9
+ /** verifyDocument().intact — null when not sealed. */
10
+ intact: boolean | null;
11
+ }
12
+ export declare function TrustControl({ content, onChange, trust, intact }: Props): import("react/jsx-runtime").JSX.Element;
13
+ export {};
package/dist/index.cjs CHANGED
@@ -1,32 +1,32 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),p=require("react"),Rt=require("@tiptap/react"),ue=require("@tiptap/starter-kit"),pe=require("@tiptap/extension-placeholder"),fe=require("@tiptap/extension-underline"),ge=require("@tiptap/extension-text-style"),he=require("@tiptap/extension-color"),me=require("@tiptap/extension-highlight"),be=require("@tiptap/extension-text-align"),ye=require("@tiptap/extension-font-family"),xe=require("@tiptap/extension-subscript"),Se=require("@tiptap/extension-superscript"),S=require("@tiptap/core"),yt=require("@tiptap/pm/state"),rt=require("@tiptap/pm/view"),H=require("@dotit/core"),ke=require("@tiptap/extension-paragraph"),v=require("lucide-react"),q=t=>t&&t.__esModule?t:{default:t},we=q(ue),Te=q(pe),ve=q(fe),je=q(he),Ae=q(me),Ce=q(be),Ne=q(ye),Le=q(xe),$e=q(Se),Me=q(ke),_e=S.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize?.replace(/['"]+/g,"")||null,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Q=96/25.4,ht={A4:[210,297],A5:[148,210],A3:[297,420],Letter:[215.9,279.4],Legal:[215.9,355.6],Tabloid:[279.4,431.8]},ze={A4:"cm",A5:"cm",A3:"cm",LETTER:"in",LEGAL:"in",TABLOID:"in"},Re=20,He=4,Ee=120;function vt(t){const e=/^(-?\d+(?:\.\d+)?)\s*(mm|cm|in|px|pt)?$/.exec(t.trim());if(!e)return null;const n=parseFloat(e[1]);switch(e[2]||"mm"){case"mm":return n*Q;case"cm":return n*10*Q;case"in":return n*96;case"pt":return n/72*96;case"px":return n;default:return null}}function Pe(t,e){const n=t.trim().split(/\s+/).map(vt);if(n.some(s=>s===null)||n.length===0)return[e,e,e,e];const r=n;return r.length===1?[r[0],r[0],r[0],r[0]]:r.length===2?[r[0],r[1],r[0],r[1]]:r.length===3?[r[0],r[1],r[2],r[1]]:[r[0],r[1],r[2],r[3]]}function mt(t){let e="A4",n,r="",s="";try{const L=H.parseIntentText(t),w=L.blocks.find(E=>E.type==="page")?.properties||{};w.size&&(e=String(w.size)),n=w.margin??w.margins,r=L.blocks.find(E=>E.type==="header")?.content||String(w.header||""),s=L.blocks.find(E=>E.type==="footer")?.content||String(w.footer||"")}catch{}let l=ht.A4[0]*Q,c=ht.A4[1]*Q,d=!1,i="cm";const g=ht[e]||ht[e.toUpperCase?.()];if(g)l=g[0]*Q,c=g[1]*Q,i=ze[e.toUpperCase()]||"cm";else{const L=e.trim().split(/\s+/),T=L[0]?vt(L[0]):null;if(T&&(l=T),/(\d)\s*in\b/.test(e)&&(i="in"),L[1]==="auto")d=!0,c=1/0;else{const w=L[1]?vt(L[1]):null;w&&(c=w)}}const f=(l<=Ee*Q?He:Re)*Q,[m,h,x,_]=n?Pe(n,f):[f,f,f,f];return{width:l,height:c,autoHeight:d,marginTop:m,marginRight:h,marginBottom:x,marginLeft:_,contentHeight:d?1/0:c-m-x,header:r,footer:s,unit:i}}function Lt(t,e,n){return t.replace(/\{\{\s*page\s*\}\}/g,String(e)).replace(/\{\{\s*pages\s*\}\}/g,String(n))}const dt=new yt.PluginKey("pagination");function St(t,e,n,r){const s=Lt(e,n,r);return`<div class="docs-pb-${t}">
2
- <span class="docs-pb-text">${Ie(s)}</span>
3
- </div>`}function Ie(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const Be=S.Extension.create({name:"pagination",addOptions(){return{geometry:()=>({width:794,height:1122.52,autoHeight:!1,marginTop:75.59,marginRight:75.59,marginBottom:75.59,marginLeft:75.59,contentHeight:971.34,header:"",footer:""}),gap:28,onPages:void 0}},addProseMirrorPlugins(){const t=this.options;return[new yt.Plugin({key:dt,state:{init:()=>rt.DecorationSet.empty,apply(e,n){const r=e.getMeta(dt);return r||n.map(e.mapping,e.doc)}},props:{decorations(e){return dt.getState(e)}},view(e){let n=0,r="";const s=(i,g,f,m)=>{const h=document.createElement("div");return h.className="docs-page-spacer",h.contentEditable="false",h.setAttribute("data-it-spacer",""),h.style.setProperty("--pb-mx-l",`${i.marginLeft}px`),h.style.setProperty("--pb-mx-r",`${i.marginRight}px`),h.innerHTML=`
4
- <div class="docs-pb-fill" style="height:${g}px"></div>
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),p=require("react"),Bt=require("@tiptap/react"),xe=require("@tiptap/starter-kit"),Se=require("@tiptap/extension-underline"),ke=require("@tiptap/extension-text-style"),ve=require("@tiptap/extension-color"),we=require("@tiptap/extension-highlight"),je=require("@tiptap/extension-text-align"),Te=require("@tiptap/extension-font-family"),Ne=require("@tiptap/extension-subscript"),Ce=require("@tiptap/extension-superscript"),j=require("@tiptap/core"),ut=require("@tiptap/pm/state"),ct=require("@tiptap/pm/view"),R=require("@dotit/core"),Ae=require("@tiptap/extension-paragraph"),T=require("lucide-react"),Z=t=>t&&t.__esModule?t:{default:t},Le=Z(xe),_e=Z(Se),$e=Z(ve),Me=Z(we),Ee=Z(je),Re=Z(Te),ze=Z(Ne),He=Z(Ce),Pe=Z(Ae),De=j.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize?.replace(/['"]+/g,"")||null,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Q=96/25.4,yt={A4:[210,297],A5:[148,210],A3:[297,420],Letter:[215.9,279.4],Legal:[215.9,355.6],Tabloid:[279.4,431.8]},Ie={A4:"cm",A5:"cm",A3:"cm",LETTER:"in",LEGAL:"in",TABLOID:"in"},Be=20,Oe=4,Fe=120;function At(t){const e=/^(-?\d+(?:\.\d+)?)\s*(mm|cm|in|px|pt)?$/.exec(t.trim());if(!e)return null;const n=parseFloat(e[1]);switch(e[2]||"mm"){case"mm":return n*Q;case"cm":return n*10*Q;case"in":return n*96;case"pt":return n/72*96;case"px":return n;default:return null}}function qe(t,e){const n=t.trim().split(/\s+/).map(At);if(n.some(o=>o===null)||n.length===0)return[e,e,e,e];const s=n;return s.length===1?[s[0],s[0],s[0],s[0]]:s.length===2?[s[0],s[1],s[0],s[1]]:s.length===3?[s[0],s[1],s[2],s[1]]:[s[0],s[1],s[2],s[3]]}function xt(t){let e="A4",n,s="",o="";try{const w=R.parseIntentText(t),x=w.blocks.find(z=>z.type==="page")?.properties||{};x.size&&(e=String(x.size)),n=x.margin??x.margins,s=w.blocks.find(z=>z.type==="header")?.content||String(x.header||""),o=w.blocks.find(z=>z.type==="footer")?.content||String(x.footer||"")}catch{}let c=yt.A4[0]*Q,a=yt.A4[1]*Q,d=!1,i="cm";const m=yt[e]||yt[e.toUpperCase?.()];if(m)c=m[0]*Q,a=m[1]*Q,i=Ie[e.toUpperCase()]||"cm";else{const w=e.trim().split(/\s+/),y=w[0]?At(w[0]):null;if(y&&(c=y),/(\d)\s*in\b/.test(e)&&(i="in"),w[1]==="auto")d=!0,a=1/0;else{const x=w[1]?At(w[1]):null;x&&(a=x)}}const u=(c<=Fe*Q?Oe:Be)*Q,[h,g,b,k]=n?qe(n,u):[u,u,u,u];return{width:c,height:a,autoHeight:d,marginTop:h,marginRight:g,marginBottom:b,marginLeft:k,contentHeight:d?1/0:a-h-b,header:s,footer:o,unit:i}}function Ue(t,e){const n=t.split(`
2
+ `),s=n.findIndex(a=>/^\s*page\s*:/i.test(a));if(s>=0){let a=n[s].replace(/\s*\|\s*margins?\s*:[^|]*/gi,"").replace(/\s+$/,"");return a=`${a} | margin: ${e}`,n[s]=a,n.join(`
3
+ `)}const o=n.findIndex(a=>a.trim()&&!/^\s*(meta|title|summary)\s*:/i.test(a)),c=`page: A4 | margin: ${e}`;return o<=0?`${c}
4
+ ${t}`:(n.splice(o,0,c),n.join(`
5
+ `))}function Et(t,e,n){return t.replace(/\{\{\s*page\s*\}\}/g,String(e)).replace(/\{\{\s*pages\s*\}\}/g,String(n))}const ft=new ut.PluginKey("pagination");function wt(t,e,n,s){const o=Et(e,n,s);return`<div class="docs-pb-${t}">
6
+ <span class="docs-pb-text">${We(o)}</span>
7
+ </div>`}function We(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const Ge=j.Extension.create({name:"pagination",addOptions(){return{geometry:()=>({width:794,height:1122.52,autoHeight:!1,marginTop:75.59,marginRight:75.59,marginBottom:75.59,marginLeft:75.59,contentHeight:971.34,header:"",footer:""}),gap:28,onPages:void 0}},addProseMirrorPlugins(){const t=this.options;return[new ut.Plugin({key:ft,state:{init:()=>ct.DecorationSet.empty,apply(e,n){const s=e.getMeta(ft);return s||n.map(e.mapping,e.doc)}},props:{decorations(e){return ft.getState(e)}},view(e){let n=0,s="";const o=(i,m,u,h)=>{const g=document.createElement("div");return g.className="docs-page-spacer",g.contentEditable="false",g.setAttribute("data-it-spacer",""),g.style.setProperty("--pb-mx-l",`${i.marginLeft}px`),g.style.setProperty("--pb-mx-r",`${i.marginRight}px`),g.innerHTML=`
8
+ <div class="docs-pb-fill" style="height:${m}px"></div>
5
9
  <div class="docs-pb-margin docs-pb-margin-bottom" style="height:${i.marginBottom}px">
6
- ${St("footer",i.footer,f,m)}
10
+ ${wt("footer",i.footer,u,h)}
7
11
  </div>
8
12
  <div class="docs-pb-gap" style="height:${t.gap}px"></div>
9
13
  <div class="docs-pb-margin docs-pb-margin-top" style="height:${i.marginTop}px">
10
- ${St("header",i.header,f+1,m)}
11
- </div>`,h},l=(i,g,f,m)=>{const h=document.createElement("div");return h.className="docs-page-spacer docs-page-tail",h.contentEditable="false",h.setAttribute("data-it-spacer",""),h.style.setProperty("--pb-mx-l",`${i.marginLeft}px`),h.style.setProperty("--pb-mx-r",`${i.marginRight}px`),h.innerHTML=`
12
- <div class="docs-pb-fill" style="height:${g}px"></div>
14
+ ${wt("header",i.header,u+1,h)}
15
+ </div>`,g},c=(i,m,u,h)=>{const g=document.createElement("div");return g.className="docs-page-spacer docs-page-tail",g.contentEditable="false",g.setAttribute("data-it-spacer",""),g.style.setProperty("--pb-mx-l",`${i.marginLeft}px`),g.style.setProperty("--pb-mx-r",`${i.marginRight}px`),g.innerHTML=`
16
+ <div class="docs-pb-fill" style="height:${m}px"></div>
13
17
  <div class="docs-pb-margin docs-pb-margin-bottom" style="height:${i.marginBottom}px">
14
- ${St("footer",i.footer,f,m)}
15
- </div>`,h},c=()=>{const i=t.geometry(),g=e.dom,f=e.state.doc;if(i.autoHeight){r!=="auto"&&(r="auto",e.dispatch(e.state.tr.setMeta(dt,rt.DecorationSet.empty)),t.onPages?.(1));return}const m=g.getBoundingClientRect().top,h=Array.from(g.children),x=[];let _=0;for(const $ of h){if($.hasAttribute?.("data-it-spacer")){_+=$.offsetHeight;continue}const R=$.getBoundingClientRect();x.push({natTop:R.top-m-_,natBottom:R.bottom-m-_})}const L=[];let T=0,w=x.length?x[0].natTop:0,E=w;for(let $=0;$<x.length&&$<f.childCount;$++){const R=x[$],tt=f.child($).nodeSize;R.natTop>w&&R.natBottom-w>i.contentHeight&&(L.push({pos:T,rest:Math.max(0,i.contentHeight-(R.natTop-w))}),w=R.natTop),E=R.natBottom,T+=tt}const P=L.length+1,W=Math.max(0,i.contentHeight-(E-w)),G=L.map($=>`${$.pos}:${Math.round($.rest)}`).join(",")+`|${Math.round(W)}|${P}|${i.header}|${i.footer}|${Math.round(i.contentHeight)}`;if(G===r)return;r=G;const O=L.map(($,R)=>rt.Decoration.widget($.pos,()=>s(i,$.rest,R+1,P),{side:-1,key:`pb-${R+1}-${Math.round($.rest)}`}));O.push(rt.Decoration.widget(f.content.size,()=>l(i,W,P,P),{side:1,key:`pb-tail-${P}-${Math.round(W)}`}));const X=rt.DecorationSet.create(e.state.doc,O);e.dispatch(e.state.tr.setMeta(dt,X)),t.onPages?.(P)},d=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(c)};return d(),{update:d,destroy:()=>cancelAnimationFrame(n)}}})]}}),Ht=new Set(["tip","info","warning","danger","success"]),Oe=new Set(["page","meta","font","header","footer","watermark"]),De=new Set(["sign","seal","approve","freeze","amend","amendment"]),Et={title:"itTitle",section:"itSection",sub:"itSub"},Fe={note:"text","body-text":"text"},qe=new Set(["weight","italic","underline","strike","color","family","size","bg","valign","align","style","font","bgcolor"]);function We(t){if(!t||t==="{}")return{};try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}function B(t,e){const n=Object.entries(t).filter(([r,s])=>s!==void 0&&s!==""&&(!e||!e.has(r)));return n.length===0?"":" | "+n.map(([r,s])=>`${r}: ${s}`).join(" | ")}function jt(t){if(!t)return[];const e=t.split("\\n"),n=[];return e.forEach((r,s)=>{r&&n.push({type:"text",text:r}),s<e.length-1&&n.push({type:"hardBreak"})}),n}function Ge(t){switch(t.type){case"bold":return[{type:"bold"}];case"italic":return[{type:"italic"}];case"strike":return[{type:"strike"}];case"code":return[{type:"code"}];case"highlight":return[{type:"highlight"}];case"styled":{const e=t.props||{},n=[],r={};return e.weight&&e.weight!=="normal"&&n.push({type:"bold"}),e.italic==="true"&&n.push({type:"italic"}),e.underline==="true"&&n.push({type:"underline"}),e.strike==="true"&&n.push({type:"strike"}),e.color&&(r.color=e.color),e.family&&(r.fontFamily=e.family),e.size&&(r.fontSize=e.size),Object.keys(r).length&&n.push({type:"textStyle",attrs:r}),e.bg&&n.push({type:"highlight",attrs:{color:e.bg}}),e.valign==="sub"&&n.push({type:"subscript"}),e.valign==="super"&&n.push({type:"superscript"}),n.length?n:null}default:return null}}const Ue=new Set(["text","bold","italic","strike","highlight","styled"]);function Ye(t,e){if(!t||t.length===0||t.every(r=>r.type==="text")||!t.every(r=>Ue.has(r.type)))return jt(e);const n=[];for(const r of t){const s=Ge(r),c=(r.value??"").split("\\n");c.forEach((d,i)=>{d&&n.push(s?{type:"text",text:d,marks:s}:{type:"text",text:d}),i<c.length-1&&n.push({type:"hardBreak"})})}return n.length?n:jt(e)}function Ke(t,e){if(!e||t.length===0)return t;const n=[],r={},s=e,l=s.family??s.font,c=s.bg??s.bgcolor;return String(s.weight||"").toLowerCase()==="bold"&&n.push({type:"bold"}),(String(s.italic||"")==="true"||String(s.style||"").toLowerCase()==="italic")&&n.push({type:"italic"}),String(s.underline||"")==="true"&&n.push({type:"underline"}),String(s.strike||"")==="true"&&n.push({type:"strike"}),String(s.valign||"")==="sub"&&n.push({type:"subscript"}),String(s.valign||"")==="super"&&n.push({type:"superscript"}),s.color&&(r.color=String(s.color)),l&&(r.fontFamily=String(l)),s.size&&(r.fontSize=String(s.size)),c&&n.push({type:"highlight",attrs:{color:String(c)}}),Object.keys(r).length>0&&n.push({type:"textStyle",attrs:r}),n.length===0?t:t.map(d=>d.type==="text"?{...d,marks:[...d.marks||[],...n]}:d)}function Ut(t){const e={};for(const n of t||[])switch(n.type){case"bold":e.weight="bold";break;case"italic":e.italic="true";break;case"underline":e.underline="true";break;case"strike":e.strike="true";break;case"textStyle":n.attrs?.color&&(e.color=String(n.attrs.color)),n.attrs?.fontFamily&&(e.family=String(n.attrs.fontFamily)),n.attrs?.fontSize&&(e.size=String(n.attrs.fontSize));break;case"highlight":n.attrs?.color&&(e.bg=String(n.attrs.color));break;case"subscript":e.valign="sub";break;case"superscript":e.valign="super";break}return e}function Je(t){if(t.type==="hardBreak")return"\\n";if(t.type!=="text")return $t(t);const e=t.text||"";if(!e)return"";const n=t.marks||[];if(!n.length)return e;const r=new Set(n.map(m=>m.type)),s=n.find(m=>m.type==="link");if(s?.attrs?.href)return`[${e}](${s.attrs.href})`;const l=n.find(m=>m.type==="textStyle")?.attrs||{},c=n.find(m=>m.type==="highlight")?.attrs||{},d=!!(l.color||l.fontFamily||l.fontSize||c.color),i=["bold","italic","strike","underline","code"].filter(m=>r.has(m)).length;if(!d&&i===1&&!r.has("underline")){if(r.has("bold"))return`*${e}*`;if(r.has("italic"))return`_${e}_`;if(r.has("strike"))return`~${e}~`;if(r.has("code"))return`\`${e}\``}if(!d&&i===0&&r.has("highlight")&&!c.color)return`^${e}^`;const g=Ut(n),f=[];return g.color&&f.push(`color: ${g.color}`),g.family&&f.push(`family: ${g.family}`),g.size&&f.push(`size: ${g.size}`),g.weight&&f.push(`weight: ${g.weight}`),g.italic==="true"&&f.push("italic: true"),g.underline&&f.push("underline: true"),g.strike&&f.push("strike: true"),g.bg&&f.push(`bg: ${g.bg}`),g.valign&&f.push(`valign: ${g.valign}`),f.length?`[${e}]{ ${f.join("; ")} }`:e}const Ve=new Set(["bold","italic","underline","strike","code","highlight","textStyle","link","subscript","superscript"]);function Qe(t){const e=new Set,n=r=>{for(const s of r.marks||[])Ve.has(s.type)||e.add(s.type);for(const s of r.content||[])n(s)};return n(t),[...e].sort()}function At(t){const e=t.content||[],n=t.attrs?.textAlign&&t.attrs.textAlign!=="left"?{align:String(t.attrs.textAlign)}:{};return e.length===1&&e[0].type==="text"?{text:e[0].text||"",props:{...Ut(e[0].marks),...n}}:{text:e.map(Je).join(""),props:{...n}}}function $t(t){return t.content?t.content.map(e=>e.type==="text"?e.text||"":e.type==="hardBreak"?"\\n":$t(e)).join(""):""}function nt(t,e,n){const r=We(t);for(const s of qe)delete r[s];if(n)for(const s of n)delete r[s];return{...r,...e}}function Mt(t){const e=t.toLowerCase();return Fe[e]||e}function Pt(t){if(t==="---")return"divider";const e=t.match(/^([a-zA-Z][\w-]*):/);return e?Mt(e[1]):null}function ot(t){return Mt(t)}function it(t,e){return!!(t===e||t==="info"&&["tip","warning","danger","success"].includes(e)||e==="info"&&["tip","warning","danger","success"].includes(t))}function Ze(t){if(!t)return{content:"",properties:{}};const e=t.split(" | ");let n=e[0]||"";const r={};for(let s=1;s<e.length;s++){const l=e[s],c=l.match(/^([a-zA-Z_][\w-]*)\s*:\s*(.*)$/);if(!c){n+=` | ${l}`;continue}r[c[1]]=c[2]}return{content:n,properties:r}}function It(t){if(t==="---")return{type:"divider"};const e=t.match(/^([a-zA-Z][\w-]*):\s*(.*)$/);if(!e)return null;const n=Mt(e[1]),r=e[2]||"",{content:s,properties:l}=Ze(r);let c;try{c=H.parseIntentText(`text: ${s}`).blocks[0]?.inline}catch{c=void 0}return{type:n,content:s,properties:l,inline:c}}function Bt(t){const e=t.match(/^[-*]\s+(.*)$/);if(e)return{ordered:!1,text:e[1]};const n=t.match(/^\d+\.\s+(.*)$/);return n?{ordered:!0,text:n[1]}:null}function Xe(t){return{type:"listItem",content:[{type:"paragraph",content:jt(t)}]}}function Ct(t){if(!t.trim())return{type:"doc",content:[{type:"paragraph"}]};const e=H.parseIntentText(t),n=[];for(const c of e.blocks){const d=kt(c);d&&n.push(d)}const r=t.split(`
16
- `);let s=0;const l=[];for(let c=0;c<r.length;c++){const i=r[c].trim();if(!i)continue;{const h=Pt(i);if(h&&Oe.has(h)){l.push({type:"itMeta",attrs:{raw:i}});const x=e.blocks[s]?.type;x&&it(h,ot(x))&&s++;continue}if(h&&De.has(h)){l.push({type:"itTrust",attrs:{raw:i,keyword:h}});const x=e.blocks[s]?.type;x&&it(h,ot(x))&&s++;continue}if(h==="metric"){l.push({type:"itMetric",attrs:{raw:i}});const x=e.blocks[s]?.type;x&&it(h,ot(x))&&s++;continue}if(h==="style"){l.push({type:"itStyleRule",attrs:{raw:i}});const x=e.blocks[s]?.type;x&&it(h,ot(x))&&s++;continue}}const g=Bt(i);if(g){const h=g.ordered,x=[];let _=c;for(;_<r.length;){const L=r[_].trim(),T=L?Bt(L):null;if(!T||T.ordered!==h)break;x.push(Xe(T.text));const w=e.blocks[s]?.type;(w==="list-item"||w==="step-item")&&s++,_++}l.push({type:h?"orderedList":"bulletList",content:x}),c=_-1;continue}if(i.startsWith("|")&&i.endsWith("|")&&(i.match(/\|/g)||[]).length>=3){const h=[];let x=c;for(;x<r.length;){const _=r[x].trim();if(!(_.startsWith("|")&&_.endsWith("|")))break;h.push(_.slice(1,-1).split("|").map(L=>L.trim())),x++}l.push({type:"itTable",attrs:{rows:JSON.stringify(h)}}),c=x-1;continue}if(i.startsWith("//")){l.push({type:"itComment",content:i.slice(2).trim()?[{type:"text",text:i.slice(2).trim()}]:[]});continue}if(i.startsWith("```"))continue;const f=Pt(i);if(f&&(f==="text"||i.includes("{{"))){const h=It(i);if(h){const x=kt(h);if(x&&l.push(x),s<e.blocks.length){const _=ot(e.blocks[s].type);it(f,_)&&s++}continue}}if(s<n.length&&f){const h=e.blocks[s],x=ot(h.type);if(it(f,x)){l.push(n[s]),s++;continue}}const m=It(i);if(m){const h=kt(m);h&&l.push(h);continue}s<n.length&&(l.push(n[s]),s++)}for(;s<n.length;)l.push(n[s]),s++;return{type:"doc",content:l.length>0?l:[{type:"paragraph"}]}}function kt(t){const{type:e,content:n,properties:r,inline:s}=t,l=n||"";let c=Ye(s,l);c=Ke(c,r);const d=r?JSON.stringify(Object.fromEntries(Object.entries(r).map(([f,m])=>[f,String(m)]))):"{}",i=r?.align?String(r.align):void 0;if(e in Et)return{type:Et[e],attrs:{props:d,...i&&{textAlign:i}},content:c.length?c:void 0};if(e==="summary")return{type:"itSummary",attrs:{props:d,...i&&{textAlign:i}},content:c.length?c:void 0};if(e==="text"||e==="body-text"){const f={};return i&&(f.textAlign=i),r?.end&&(f.end=String(r.end)),r?.leading&&(f.leading=String(r.leading)),r?.["space-before"]&&(f.spaceBefore=String(r["space-before"])),r?.["space-after"]&&(f.spaceAfter=String(r["space-after"])),{type:"paragraph",...Object.keys(f).length&&{attrs:f},content:c.length?c:void 0}}if(Ht.has(e)){const f=e==="info"?String(r?.type||"info").toLowerCase():e;return{type:"itCallout",attrs:{variant:Ht.has(f)?f:"info",props:d},content:c.length?c:void 0}}if(e==="quote")return{type:"itQuote",attrs:{by:r?.by?String(r.by):"",props:d,...i&&{textAlign:i}},content:c.length?c:void 0};if(e==="code")return{type:"itCode",attrs:{lang:r?.lang?String(r.lang):"",props:d},content:l?[{type:"text",text:l}]:void 0};if(e==="divider")return{type:"itDivider"};if(e==="break")return{type:"itBreak"};const g=r?Object.entries(r).filter(([,f])=>f!==void 0&&f!=="").map(([f,m])=>`${f}: ${m}`).join(" | "):"";return{type:"itGenericBlock",attrs:{keyword:e,properties:g,props:d},content:c.length?c:void 0}}function Yt(t){if(!t.content)return"";const e=[];for(const n of t.content)e.push(...tn(n));return e.join(`
17
- `)}function tn(t){if(t.type==="bulletList"&&t.content)return t.content.flatMap(n=>n.content?n.content.map(r=>{const{text:s,props:l}=At(r);return`- ${s}${B(l)}`}):[]);if(t.type==="orderedList"&&t.content){let n=1;return t.content.flatMap(r=>r.content?r.content.map(s=>{const{text:l,props:c}=At(s);return`${n++}. ${l}${B(c)}`}):[])}const e=en(t);return e!==null?[e]:[]}function en(t){const{text:e,props:n}=At(t);switch(t.type){case"itTitle":{const r=nt(t.attrs?.props,n);return`title: ${e}${B(r)}`}case"itSummary":{const r=nt(t.attrs?.props,n);return`summary: ${e}${B(r)}`}case"itSection":{const r=nt(t.attrs?.props,n);return`section: ${e}${B(r)}`}case"itSub":{const r=nt(t.attrs?.props,n);return`sub: ${e}${B(r)}`}case"paragraph":{const r=t.attrs||{},s={};return r.end&&(s.end=String(r.end)),r.leading&&(s.leading=String(r.leading)),r.spaceBefore&&(s["space-before"]=String(r.spaceBefore)),r.spaceAfter&&(s["space-after"]=String(r.spaceAfter)),`text: ${e}${B({...s,...n})}`}case"itCallout":{const r=t.attrs?.variant||"tip",s=nt(t.attrs?.props,n,new Set(["variant"]));return r==="info"?`info: ${e}${B(s)}`:`info: ${e} | type: ${r}${B(s,new Set(["type"]))}`}case"itQuote":{const r=t.attrs?.by,s=r?` | by: ${r}`:"",l=nt(t.attrs?.props,n,new Set(["by"]));return`quote: ${e}${s}${B(l)}`}case"itCode":return`\`\`\`${t.attrs?.lang||""}
18
- ${$t(t)}
19
- \`\`\``;case"itDivider":return"divider:";case"itTable":{let r=[];try{r=JSON.parse(t.attrs?.rows||"[]")}catch{r=[]}return r.map(s=>`| ${s.join(" | ")} |`).join(`
20
- `)}case"itMeta":return t.attrs?.raw||"";case"itTrust":return t.attrs?.raw||"";case"itMetric":return t.attrs?.raw||"";case"itStyleRule":return t.attrs?.raw||"";case"itBreak":return"break:";case"itComment":return e?`// ${e}`:"//";case"itGenericBlock":{const r=t.attrs?.keyword||"text",s=nt(t.attrs?.props,n);return`${r}: ${e}${B(s)}`}default:return e?`text: ${e}${B(n)}`:null}}function a(t,e){return{property:t,css:e}}const nn=[a("align","textAlign"),a("color","color"),a("size","fontSize"),a("weight","fontWeight"),{property:"style",css:"fontStyle"},a("bgcolor","backgroundColor"),a("padding","padding"),a("indent","paddingLeft"),a("opacity","opacity")],ut=[a("bgcolor","backgroundColor"),a("color","color"),a("border","borderLeft")],N=[a("color","borderColor"),a("bgcolor","backgroundColor")],rn={title:[a("align","textAlign"),a("color","color"),a("size","fontSize"),a("weight","fontWeight"),a("font","fontFamily")],summary:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"}],section:[a("align","textAlign"),a("color","color"),a("size","fontSize"),a("weight","fontWeight"),a("border","borderBottom"),a("spacing","marginTop")],sub:[a("align","textAlign"),a("color","color"),a("size","fontSize"),a("weight","fontWeight")],divider:[{property:"style",css:"borderStyle"},a("color","borderColor"),a("width","borderTopWidth"),a("spacing","margin")],text:[...nn],tip:[...ut],info:[...ut],warning:[...ut],danger:[...ut],success:[...ut],quote:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"},a("border","borderLeft"),a("padding","paddingLeft"),a("bgcolor","backgroundColor")],cite:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"}],def:[a("color","color"),a("bgcolor","backgroundColor"),a("border","borderLeft"),a("padding","paddingLeft")],caption:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"}],footnote:[a("color","color"),a("size","fontSize")],byline:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"},a("weight","fontWeight")],epigraph:[a("align","textAlign"),a("color","color"),a("size","fontSize"),{property:"style",css:"fontStyle"},a("padding","padding")],dedication:[a("align","textAlign"),a("color","color"),{property:"style",css:"fontStyle"},a("padding","padding")],image:[a("width","width"),a("height","height"),a("radius","borderRadius"),a("border","border"),a("opacity","opacity"),a("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],figure:[a("width","width"),a("align","textAlign"),a("border","border"),a("padding","padding"),a("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],link:[a("color","color"),a("weight","fontWeight")],ref:[a("color","color"),{property:"style",css:"fontStyle"}],embed:[a("width","width"),a("height","height"),a("border","border"),a("radius","borderRadius")],metric:[a("color","color"),a("size","fontSize"),a("align","textAlign"),a("bgcolor","backgroundColor"),a("border","border"),a("padding","padding")],columns:[a("border","border"),a("bgcolor","backgroundColor"),a("padding","padding"),a("size","fontSize"),a("align","textAlign")],row:[a("border","border"),a("bgcolor","backgroundColor"),a("padding","padding"),a("size","fontSize"),a("align","textAlign")],input:[a("color","color"),a("bgcolor","backgroundColor"),a("border","borderLeft"),a("size","fontSize")],output:[a("color","color"),a("bgcolor","backgroundColor"),a("border","borderLeft"),a("size","fontSize")],code:[a("size","fontSize"),a("bgcolor","backgroundColor"),a("color","color"),a("padding","padding"),a("radius","borderRadius"),a("border","border")],contact:[a("color","color"),a("bgcolor","backgroundColor"),a("border","border"),a("padding","padding"),a("size","fontSize")],deadline:[a("color","color"),a("bgcolor","backgroundColor"),a("weight","fontWeight"),a("size","fontSize")],step:[...N],decision:[...N],gate:[...N],trigger:[...N],loop:[...N],parallel:[...N],call:[...N],wait:[...N],checkpoint:[...N],error:[...N],result:[...N],audit:[...N],signal:[...N],handoff:[...N],retry:[...N],progress:[...N],tool:[...N],prompt:[...N],memory:[...N],policy:[...N],context:[...N],track:[...N],approve:[...N],sign:[...N],freeze:[...N],revision:[...N],amendment:[...N],history:[a("color","borderColor")],assert:[a("color","borderColor"),a("bgcolor","backgroundColor"),a("border","borderLeft")],secret:[a("color","color"),a("bgcolor","backgroundColor"),a("blur","filter")],watermark:[a("color","color"),a("size","fontSize"),a("opacity","opacity")],signline:[a("color","color"),a("width","width")]};function sn(t,e){const n=rn[t];if(!n)return{};const r={};for(const s of n){const l=e[s.property];l&&(s.transform?r[s.css]=s.transform(l):r[s.css]=l)}return r}function U(t,e){const n=sn(t,e);return e.leading&&(n.lineHeight=e.leading),e["space-before"]&&(n.marginTop=e["space-before"]),e["space-after"]&&(n.marginBottom=e["space-after"]),Object.entries(n).map(([r,s])=>`${r.replace(/([A-Z])/g,"-$1").toLowerCase()}:${s}`).join(";")}function _t(t){return t.end?{"data-it-end":t.end}:{}}const on=S.Node.create({name:"itTitle",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}",parseHTML:t=>t.getAttribute("data-props")||"{}"}}},parseHTML(){return[{tag:'h1[data-it-type="title"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props),r=S.mergeAttributes(t,{"data-it-type":"title",class:"it-doc-title",style:U("title",n),..._t(n)});return n.end?["h1",r,["span",{class:"it-split-main"},0]]:["h1",r,0]}}),an=S.Node.create({name:"itSummary",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'p[data-it-type="summary"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props);return["p",S.mergeAttributes(t,{"data-it-type":"summary",class:"it-doc-summary",style:U("summary",n)}),0]}}),cn=S.Node.create({name:"itSection",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'h2[data-it-type="section"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props),r=S.mergeAttributes(t,{"data-it-type":"section",class:"it-doc-section",style:U("section",n),..._t(n)});return n.end?["h2",r,["span",{class:"it-split-main"},0]]:["h2",r,0]}}),ln=S.Node.create({name:"itSub",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'h3[data-it-type="sub"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props),r=S.mergeAttributes(t,{"data-it-type":"sub",class:"it-doc-sub",style:U("sub",n),..._t(n)});return n.end?["h3",r,["span",{class:"it-split-main"},0]]:["h3",r,0]}}),dn=S.Node.create({name:"itCallout",group:"block",content:"inline*",defining:!0,addAttributes(){return{variant:{default:"tip",parseHTML:t=>t.getAttribute("data-variant")||"tip",renderHTML:t=>({"data-variant":t.variant})},props:{default:"{}"}}},parseHTML(){return[{tag:'div[data-it-type="callout"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.variant||"tip",r=Z(e.attrs.props),s={tip:"tip",info:"info",warning:"warning",danger:"danger",success:"success"};return["div",S.mergeAttributes(t,{"data-it-type":"callout","data-variant":n,class:`it-doc-callout it-doc-callout-${n}`,style:U(n,r)}),["span",{class:`it-doc-callout-icon it-doc-callout-icon-${s[n]||"tip"}`,contenteditable:"false"},""],["span",{class:"it-doc-callout-text"},0]]}}),un=S.Node.create({name:"itQuote",group:"block",content:"inline*",defining:!0,addAttributes(){return{by:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:'blockquote[data-it-type="quote"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props);return["blockquote",S.mergeAttributes(t,{"data-it-type":"quote",class:"it-doc-quote",style:U("quote",n)}),0]}}),pn=S.Node.create({name:"itCode",group:"block",content:"text*",marks:"",code:!0,defining:!0,addAttributes(){return{lang:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:"pre"}]},renderHTML({HTMLAttributes:t,node:e}){const n=Z(e.attrs.props);return["pre",S.mergeAttributes(t,{"data-it-type":"code",class:"it-doc-code","data-lang":e.attrs.lang||"",style:U("code",n)}),["code",0]]}}),fn=S.Node.create({name:"itDivider",group:"block",atom:!0,parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",S.mergeAttributes(t,{class:"it-doc-divider"})]}}),gn=S.Node.create({name:"itMeta",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-meta]"}]},renderHTML({HTMLAttributes:t,node:e}){const n=String(e.attrs.raw||"").replace(/\s*\|\s*/g," · ");return["div",S.mergeAttributes(t,{"data-it-meta":"",class:"it-doc-meta"}),`⚙ ${n}`]}}),hn=S.Node.create({name:"itTable",group:"block",atom:!0,addAttributes(){return{rows:{default:"[]",parseHTML:t=>t.getAttribute("data-rows")||"[]",renderHTML:t=>({"data-rows":t.rows})}}},parseHTML(){return[{tag:"table[data-it-table]"}]},renderHTML({HTMLAttributes:t,node:e}){let n=[];try{n=JSON.parse(e.attrs.rows||"[]")}catch{n=[]}const r=n[0]||[],s=n.slice(1);return["table",S.mergeAttributes(t,{"data-it-table":"",class:"it-doc-table"}),["thead",["tr",...r.map(l=>["th",Ot(l),String(l)])]],["tbody",...s.map(l=>["tr",...l.map(c=>["td",Ot(c),String(c)])])]]}});function Ot(t){return/\{\{[^}]+\}\}|^each:/.test(String(t).trim())?{class:"it-doc-var-cell"}:{}}function zt(t){const e=t.indexOf(":"),n=(e>=0?t.slice(0,e):t).trim().toLowerCase(),s=(e>=0?t.slice(e+1).trim():"").split("|").map(d=>d.trim()),l=s.shift()||"",c={};for(const d of s){const i=d.indexOf(":");i>0&&(c[d.slice(0,i).trim().toLowerCase()]=d.slice(i+1).trim())}return{keyword:n,content:l,props:c}}const mn=S.Node.create({name:"itTrust",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})},keyword:{default:"",parseHTML:t=>t.getAttribute("data-trust")||"",renderHTML:t=>({"data-trust":t.keyword})}}},parseHTML(){return[{tag:"div[data-it-trust]"}]},renderHTML({HTMLAttributes:t,node:e}){const{keyword:n,content:r,props:s}=zt(String(e.attrs.raw||"")),l=s.role||s.title||"",c=(s.at||s.date||s.time||"").slice(0,10),d=[];if(n==="seal"||n==="freeze"){const i=n==="seal"&&r||s.hash||"";d.push(["span",{class:"it-doc-trust__label"},"Sealed document"]),c&&d.push(["span",{class:"it-doc-trust__date"},c]),i&&d.push(["code",{class:"it-doc-trust__hash"},i.length>20?i.slice(0,20)+"...":i])}else if(n==="approve"){const i=s.by||r,g=s.by?r:"";d.push(["span",{class:"it-doc-trust__label"},"Approved"]),g&&d.push(["span",{class:"it-doc-trust__what"},g]),i&&d.push(["span",{class:"it-doc-trust__who"},l?`${i}, ${l}`:i]),c&&d.push(["span",{class:"it-doc-trust__date"},c])}else if(n==="amend"||n==="amendment")d.push(["span",{class:"it-doc-trust__label"},"Amendment"]),r&&d.push(["span",{class:"it-doc-trust__what"},r]),c&&d.push(["span",{class:"it-doc-trust__date"},c]);else{const i=r||s.by||"",g=!!s.hash;d.push(["span",{class:"it-doc-trust__name"},i]),l&&d.push(["span",{class:"it-doc-trust__role"},l]),c&&d.push(["span",{class:"it-doc-trust__date"},c]),d.push(["span",{class:"it-doc-trust__status"},g?"Signed · verified":"Signed"])}return["div",S.mergeAttributes(t,{"data-it-trust":"","data-trust":n,class:`it-doc-trust it-doc-trust--${n}`}),...d]}}),bn=S.Node.create({name:"itMetric",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-metric]"}]},renderHTML({HTMLAttributes:t,node:e}){const{content:n,props:r}=zt(String(e.attrs.raw||"")),s=[r.value,r.unit].filter(Boolean).join(" "),l=/\b(total|balance due|amount due|grand)\b/i.test(n),c=/\{\{[^}]+\}\}/.test(s);return["div",S.mergeAttributes(t,{"data-it-metric":"",class:`it-doc-metric${l?" it-doc-metric--total":""}`}),["span",{class:"it-doc-metric__label"},n],["span",{class:`it-doc-metric__value${c?" it-doc-var":""}`},s]]}}),yn=S.Node.create({name:"itStyleRule",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-style-rule]"}]},renderHTML({HTMLAttributes:t,node:e}){const{content:n,props:r}=zt(String(e.attrs.raw||"")),s=Object.entries(r).map(([l,c])=>`${l}: ${c}`).join(" · ");return["div",S.mergeAttributes(t,{"data-it-style-rule":"",class:"it-doc-stylerule"}),["span",{class:"it-doc-stylerule__icon"},"🎨"],["span",{class:"it-doc-stylerule__target"},n||"?"],["span",{class:"it-doc-stylerule__decl"},s]]}}),xn=S.Node.create({name:"itBreak",group:"block",atom:!0,parseHTML(){return[{tag:'div[data-it-type="break"]'}]},renderHTML({HTMLAttributes:t}){return["div",S.mergeAttributes(t,{"data-it-type":"break",class:"it-doc-break"})]}}),Sn=S.Node.create({name:"itGenericBlock",group:"block",content:"inline*",defining:!0,addAttributes(){return{keyword:{default:"text"},properties:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:'[data-it-type="generic"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.keyword,r=Z(e.attrs.props),s=String(r.to||r.url||r.href||r.file||"").trim();return(n==="link"||n==="ref")&&s?["p",S.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:U(n,r)}),["a",{class:"it-doc-inline-link",href:s,target:"_blank",rel:"noopener noreferrer"},0]]:["p",S.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:U(n,r)}),["span",{class:"it-doc-generic-content"},0]]}}),kn=S.Node.create({name:"itComment",group:"block",content:"inline*",defining:!0,parseHTML(){return[{tag:'p[data-it-type="comment"]'}]},renderHTML({HTMLAttributes:t}){return["p",S.mergeAttributes(t,{"data-it-type":"comment",class:"it-doc-comment"}),0]}});function Z(t){try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}const Kt={leading:"leading","space-before":"spaceBefore","space-after":"spaceAfter",end:"end"},wn=new Set(["itTitle","itSummary","itSection","itSub","itQuote","itCallout","itGenericBlock"]),Tn=new Set(["itTitle","itSection","itSub"]);function Jt(t){try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}function Vt(t,e){return t==="paragraph"?!0:e==="end"?Tn.has(t):wn.has(t)}const vn=Me.default.extend({addAttributes(){return{...this.parent?.(),leading:{default:null,parseHTML:t=>t.style.lineHeight||null,renderHTML:t=>t.leading?{style:`line-height: ${t.leading}`}:{}},spaceBefore:{default:null,parseHTML:t=>t.style.marginTop||null,renderHTML:t=>t.spaceBefore?{style:`margin-top: ${t.spaceBefore}`}:{}},spaceAfter:{default:null,parseHTML:t=>t.style.marginBottom||null,renderHTML:t=>t.spaceAfter?{style:`margin-bottom: ${t.spaceAfter}`}:{}},end:{default:null,parseHTML:t=>t.getAttribute("data-it-end"),renderHTML:t=>t.end?{"data-it-end":t.end}:{}}}},renderHTML({node:t,HTMLAttributes:e}){return t.attrs.end?["p",S.mergeAttributes(e),["span",{class:"it-split-main"},0]]:["p",S.mergeAttributes(e),0]}}),jn=S.Extension.create({name:"blockProps",addCommands(){return{setBlockProp:(t,e)=>({state:n,tr:r,dispatch:s})=>{const{from:l,to:c}=n.selection;let d=!1;return n.doc.nodesBetween(l,c,(i,g)=>{const f=i.type.name;if(f==="bulletList"||f==="orderedList"||!i.isBlock||i.isAtom)return!1;if(!Vt(f,t))return!0;if(f==="paragraph")r.setNodeMarkup(g,void 0,{...i.attrs,[Kt[t]]:e});else{const m=Jt(i.attrs.props);e==null||e===""?delete m[t]:m[t]=e,r.setNodeMarkup(g,void 0,{...i.attrs,props:JSON.stringify(m)})}return d=!0,!1}),d&&s&&s(r),d}}}});function V(t,e){if(!t)return null;const{state:n}=t,{from:r,to:s}=n.selection;let l=null;return n.doc.nodesBetween(r,s,c=>{if(l!==null)return!1;const d=c.type.name;if(!Vt(d,e))return!0;if(d==="paragraph"){const i=c.attrs[Kt[e]];l=i!=null?String(i):""}else l=Jt(c.attrs.props)[e]??"";return!1}),l}const Dt={identity:{label:"Identity",icon:"ID",color:"#3b82f6"},content:{label:"Content",icon:"Tx",color:"#6b7280"},structure:{label:"Structure",icon:"##",color:"#22c55e"},data:{label:"Data",icon:"Dt",color:"#a855f7"},agent:{label:"Agent",icon:"Ag",color:"#f97316"},trust:{label:"Trust",icon:"Tr",color:"#eab308"},layout:{label:"Layout",icon:"Pg",color:"#64748b"}};function Qt(t){const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.style.cssText="position:fixed;right:0;bottom:0;width:210mm;height:297mm;border:0;visibility:hidden;",document.body.appendChild(e);let n=!1;const r=()=>{if(!n){n=!0;try{e.contentWindow.focus(),e.contentWindow.print()}finally{setTimeout(()=>e.remove(),1e3)}}};e.onload=()=>window.setTimeout(r,120);const s=e.contentWindow.document;s.open(),s.write(t),s.close(),s.readyState==="complete"&&window.setTimeout(r,250)}function An(t,e){return t.includes("</head>")?t.replace("</head>",`<style>${e}</style></head>`):t}const Zt=".it-doc-callout{background:none!important;border:1px solid #ccc!important}",Ft=H.cssContentValue;function Cn(t,e){const n=document.querySelector(".docs-page .tiptap");if(!n)return null;const r=n.cloneNode(!0);r.querySelectorAll("[data-it-spacer]").forEach(m=>m.remove());const s=r.innerHTML,l=Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).map(m=>m.outerHTML).join(`
21
- `),c=mt(t),d=c.autoHeight?`${c.width}px auto`:`${c.width}px ${c.height}px`,i=`${c.marginTop}px ${c.marginRight}px ${c.marginBottom}px ${c.marginLeft}px`;let g=`@page{size:${d};margin:${i};}`;c.header&&(g+=`@page{@top-center{content:${Ft(c.header)};font:10px -apple-system,sans-serif;color:#9aa0a6;}}`),c.footer&&(g+=`@page{@bottom-center{content:${Ft(c.footer)};font:10px -apple-system,sans-serif;color:#9aa0a6;}}`);const f=`
18
+ ${wt("footer",i.footer,u,h)}
19
+ </div>`,g},a=()=>{const i=t.geometry(),m=e.dom,u=e.state.doc;if(i.autoHeight){s!=="auto"&&(s="auto",e.dispatch(e.state.tr.setMeta(ft,ct.DecorationSet.empty)),t.onPages?.(1));return}const h=m.getBoundingClientRect().top,g=Array.from(m.children),b=[];let k=0;for(const _ of g){if(_.hasAttribute?.("data-it-spacer")){k+=_.offsetHeight;continue}const H=_.getBoundingClientRect();b.push({natTop:H.top-h-k,natBottom:H.bottom-h-k})}const w=[];let y=0,x=b.length?b[0].natTop:0,z=x;for(let _=0;_<b.length&&_<u.childCount;_++){const H=b[_],G=u.child(_).nodeSize;H.natTop>x&&H.natBottom-x>i.contentHeight&&(w.push({pos:y,rest:Math.max(0,i.contentHeight-(H.natTop-x))}),x=H.natTop),z=H.natBottom,y+=G}const D=w.length+1,F=Math.max(0,i.contentHeight-(z-x)),P=w.map(_=>`${_.pos}:${Math.round(_.rest)}`).join(",")+`|${Math.round(F)}|${D}|${i.header}|${i.footer}|${Math.round(i.contentHeight)}`;if(P===s)return;s=P;const I=w.map((_,H)=>ct.Decoration.widget(_.pos,()=>o(i,_.rest,H+1,D),{side:-1,key:`pb-${H+1}-${Math.round(_.rest)}`}));I.push(ct.Decoration.widget(u.content.size,()=>c(i,F,D,D),{side:1,key:`pb-tail-${D}-${Math.round(F)}`}));const K=ct.DecorationSet.create(e.state.doc,I);e.dispatch(e.state.tr.setMeta(ft,K)),t.onPages?.(D)},d=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(a)};return d(),{update:d,destroy:()=>cancelAnimationFrame(n)}}})]}}),Ot=new Set(["tip","info","warning","danger","success"]),Ke=new Set(["page","meta","font","header","footer","watermark"]),Ye=new Set(["sign","seal","approve","freeze","amend","amendment"]),Ft={title:"itTitle",section:"itSection",sub:"itSub"},Ve={note:"text","body-text":"text"},Je=new Set(["weight","italic","underline","strike","color","family","size","bg","valign","align","style","font","bgcolor"]);function Qe(t){if(!t||t==="{}")return{};try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}function W(t,e){const n=Object.entries(t).filter(([s,o])=>o!==void 0&&o!==""&&(!e||!e.has(s)));return n.length===0?"":" | "+n.map(([s,o])=>`${s}: ${o}`).join(" | ")}function Lt(t){if(!t)return[];const e=t.split("\\n"),n=[];return e.forEach((s,o)=>{s&&n.push({type:"text",text:s}),o<e.length-1&&n.push({type:"hardBreak"})}),n}function Xe(t){switch(t.type){case"bold":return[{type:"bold"}];case"italic":return[{type:"italic"}];case"strike":return[{type:"strike"}];case"code":return[{type:"code"}];case"highlight":return[{type:"highlight"}];case"styled":{const e=t.props||{},n=[],s={};return e.weight&&e.weight!=="normal"&&n.push({type:"bold"}),e.italic==="true"&&n.push({type:"italic"}),e.underline==="true"&&n.push({type:"underline"}),e.strike==="true"&&n.push({type:"strike"}),e.color&&(s.color=e.color),e.family&&(s.fontFamily=e.family),e.size&&(s.fontSize=e.size),Object.keys(s).length&&n.push({type:"textStyle",attrs:s}),e.bg&&n.push({type:"highlight",attrs:{color:e.bg}}),e.valign==="sub"&&n.push({type:"subscript"}),e.valign==="super"&&n.push({type:"superscript"}),n.length?n:null}default:return null}}const Ze=new Set(["text","bold","italic","strike","highlight","styled"]);function tn(t,e){if(!t||t.length===0||t.every(s=>s.type==="text")||!t.every(s=>Ze.has(s.type)))return Lt(e);const n=[];for(const s of t){const o=Xe(s),a=(s.value??"").split("\\n");a.forEach((d,i)=>{d&&n.push(o?{type:"text",text:d,marks:o}:{type:"text",text:d}),i<a.length-1&&n.push({type:"hardBreak"})})}return n.length?n:Lt(e)}function en(t,e){if(!e||t.length===0)return t;const n=[],s={},o=e,c=o.family??o.font,a=o.bg??o.bgcolor;return String(o.weight||"").toLowerCase()==="bold"&&n.push({type:"bold"}),(String(o.italic||"")==="true"||String(o.style||"").toLowerCase()==="italic")&&n.push({type:"italic"}),String(o.underline||"")==="true"&&n.push({type:"underline"}),String(o.strike||"")==="true"&&n.push({type:"strike"}),String(o.valign||"")==="sub"&&n.push({type:"subscript"}),String(o.valign||"")==="super"&&n.push({type:"superscript"}),o.color&&(s.color=String(o.color)),c&&(s.fontFamily=String(c)),o.size&&(s.fontSize=String(o.size)),a&&n.push({type:"highlight",attrs:{color:String(a)}}),Object.keys(s).length>0&&n.push({type:"textStyle",attrs:s}),n.length===0?t:t.map(d=>d.type==="text"?{...d,marks:[...d.marks||[],...n]}:d)}function te(t){const e={};for(const n of t||[])switch(n.type){case"bold":e.weight="bold";break;case"italic":e.italic="true";break;case"underline":e.underline="true";break;case"strike":e.strike="true";break;case"textStyle":n.attrs?.color&&(e.color=String(n.attrs.color)),n.attrs?.fontFamily&&(e.family=String(n.attrs.fontFamily)),n.attrs?.fontSize&&(e.size=String(n.attrs.fontSize));break;case"highlight":n.attrs?.color&&(e.bg=String(n.attrs.color));break;case"subscript":e.valign="sub";break;case"superscript":e.valign="super";break}return e}function nn(t){if(t.type==="hardBreak")return"\\n";if(t.type!=="text")return Rt(t);const e=t.text||"";if(!e)return"";const n=t.marks||[];if(!n.length)return e;const s=new Set(n.map(h=>h.type)),o=n.find(h=>h.type==="link");if(o?.attrs?.href)return`[${e}](${o.attrs.href})`;const c=n.find(h=>h.type==="textStyle")?.attrs||{},a=n.find(h=>h.type==="highlight")?.attrs||{},d=!!(c.color||c.fontFamily||c.fontSize||a.color),i=["bold","italic","strike","underline","code"].filter(h=>s.has(h)).length;if(!d&&i===1&&!s.has("underline")){if(s.has("bold"))return`*${e}*`;if(s.has("italic"))return`_${e}_`;if(s.has("strike"))return`~${e}~`;if(s.has("code"))return`\`${e}\``}if(!d&&i===0&&s.has("highlight")&&!a.color)return`^${e}^`;const m=te(n),u=[];return m.color&&u.push(`color: ${m.color}`),m.family&&u.push(`family: ${m.family}`),m.size&&u.push(`size: ${m.size}`),m.weight&&u.push(`weight: ${m.weight}`),m.italic==="true"&&u.push("italic: true"),m.underline&&u.push("underline: true"),m.strike&&u.push("strike: true"),m.bg&&u.push(`bg: ${m.bg}`),m.valign&&u.push(`valign: ${m.valign}`),u.length?`[${e}]{ ${u.join("; ")} }`:e}const sn=new Set(["bold","italic","underline","strike","code","highlight","textStyle","link","subscript","superscript"]);function rn(t){const e=new Set,n=s=>{for(const o of s.marks||[])sn.has(o.type)||e.add(o.type);for(const o of s.content||[])n(o)};return n(t),[...e].sort()}function _t(t){const e=t.content||[],n=t.attrs?.textAlign&&t.attrs.textAlign!=="left"?{align:String(t.attrs.textAlign)}:{};return e.length===1&&e[0].type==="text"?{text:e[0].text||"",props:{...te(e[0].marks),...n}}:{text:e.map(nn).join(""),props:{...n}}}function Rt(t){return t.content?t.content.map(e=>e.type==="text"?e.text||"":e.type==="hardBreak"?"\\n":Rt(e)).join(""):""}function at(t,e,n){const s=Qe(t);for(const o of Je)delete s[o];if(n)for(const o of n)delete s[o];return{...s,...e}}function zt(t){const e=t.toLowerCase();return Ve[e]||e}function qt(t){if(t==="---")return"divider";const e=t.match(/^([a-zA-Z][\w-]*):/);return e?zt(e[1]):null}function lt(t){return zt(t)}function dt(t,e){return!!(t===e||t==="info"&&["tip","warning","danger","success"].includes(e)||e==="info"&&["tip","warning","danger","success"].includes(t))}function on(t){if(!t)return{content:"",properties:{}};const e=t.split(" | ");let n=e[0]||"";const s={};for(let o=1;o<e.length;o++){const c=e[o],a=c.match(/^([a-zA-Z_][\w-]*)\s*:\s*(.*)$/);if(!a){n+=` | ${c}`;continue}s[a[1]]=a[2]}return{content:n,properties:s}}function Ut(t){if(t==="---")return{type:"divider"};const e=t.match(/^([a-zA-Z][\w-]*):\s*(.*)$/);if(!e)return null;const n=zt(e[1]),s=e[2]||"",{content:o,properties:c}=on(s);let a;try{a=R.parseIntentText(`text: ${o}`).blocks[0]?.inline}catch{a=void 0}return{type:n,content:o,properties:c,inline:a}}function Wt(t){const e=t.match(/^[-*]\s+(.*)$/);if(e)return{ordered:!1,text:e[1]};const n=t.match(/^\d+\.\s+(.*)$/);return n?{ordered:!0,text:n[1]}:null}function an(t){return{type:"listItem",content:[{type:"paragraph",content:Lt(t)}]}}function $t(t){if(!t.trim())return{type:"doc",content:[{type:"paragraph"}]};const e=R.parseIntentText(t),n=[];for(const a of e.blocks){const d=jt(a);d&&n.push(d)}const s=t.split(`
20
+ `);let o=0;const c=[];for(let a=0;a<s.length;a++){const i=s[a].trim();if(!i)continue;{const g=qt(i);if(g&&Ke.has(g)){c.push({type:"itMeta",attrs:{raw:i}});const b=e.blocks[o]?.type;b&&dt(g,lt(b))&&o++;continue}if(g&&Ye.has(g)){c.push({type:"itTrust",attrs:{raw:i,keyword:g}});const b=e.blocks[o]?.type;b&&dt(g,lt(b))&&o++;continue}if(g==="metric"){c.push({type:"itMetric",attrs:{raw:i}});const b=e.blocks[o]?.type;b&&dt(g,lt(b))&&o++;continue}if(g==="style"){c.push({type:"itStyleRule",attrs:{raw:i}});const b=e.blocks[o]?.type;b&&dt(g,lt(b))&&o++;continue}}const m=Wt(i);if(m){const g=m.ordered,b=[];let k=a;for(;k<s.length;){const w=s[k].trim(),y=w?Wt(w):null;if(!y||y.ordered!==g)break;b.push(an(y.text));const x=e.blocks[o]?.type;(x==="list-item"||x==="step-item")&&o++,k++}c.push({type:g?"orderedList":"bulletList",content:b}),a=k-1;continue}if(i.startsWith("|")&&i.endsWith("|")&&(i.match(/\|/g)||[]).length>=3){const g=[];let b=a;for(;b<s.length;){const k=s[b].trim();if(!(k.startsWith("|")&&k.endsWith("|")))break;g.push(k.slice(1,-1).split("|").map(w=>w.trim())),b++}c.push({type:"itTable",attrs:{rows:JSON.stringify(g)}}),a=b-1;continue}if(i.startsWith("//")){c.push({type:"itComment",content:i.slice(2).trim()?[{type:"text",text:i.slice(2).trim()}]:[]});continue}if(i.startsWith("```"))continue;const u=qt(i);if(u&&(u==="text"||i.includes("{{"))){const g=Ut(i);if(g){const b=jt(g);if(b&&c.push(b),o<e.blocks.length){const k=lt(e.blocks[o].type);dt(u,k)&&o++}continue}}if(o<n.length&&u){const g=e.blocks[o],b=lt(g.type);if(dt(u,b)){c.push(n[o]),o++;continue}}const h=Ut(i);if(h){const g=jt(h);g&&c.push(g);continue}o<n.length&&(c.push(n[o]),o++)}for(;o<n.length;)c.push(n[o]),o++;return{type:"doc",content:c.length>0?c:[{type:"paragraph"}]}}function jt(t){const{type:e,content:n,properties:s,inline:o}=t,c=n||"";let a=tn(o,c);a=en(a,s);const d=s?JSON.stringify(Object.fromEntries(Object.entries(s).map(([u,h])=>[u,String(h)]))):"{}",i=s?.align?String(s.align):void 0;if(e in Ft)return{type:Ft[e],attrs:{props:d,...i&&{textAlign:i}},content:a.length?a:void 0};if(e==="summary")return{type:"itSummary",attrs:{props:d,...i&&{textAlign:i}},content:a.length?a:void 0};if(e==="text"||e==="body-text"){const u={};return i&&(u.textAlign=i),s?.end&&(u.end=String(s.end)),s?.leading&&(u.leading=String(s.leading)),s?.["space-before"]&&(u.spaceBefore=String(s["space-before"])),s?.["space-after"]&&(u.spaceAfter=String(s["space-after"])),{type:"paragraph",...Object.keys(u).length&&{attrs:u},content:a.length?a:void 0}}if(Ot.has(e)){const u=e==="info"?String(s?.type||"info").toLowerCase():e;return{type:"itCallout",attrs:{variant:Ot.has(u)?u:"info",props:d},content:a.length?a:void 0}}if(e==="quote")return{type:"itQuote",attrs:{by:s?.by?String(s.by):"",props:d,...i&&{textAlign:i}},content:a.length?a:void 0};if(e==="code")return{type:"itCode",attrs:{lang:s?.lang?String(s.lang):"",props:d},content:c?[{type:"text",text:c}]:void 0};if(e==="divider")return{type:"itDivider"};if(e==="break")return{type:"itBreak"};const m=s?Object.entries(s).filter(([,u])=>u!==void 0&&u!=="").map(([u,h])=>`${u}: ${h}`).join(" | "):"";return{type:"itGenericBlock",attrs:{keyword:e,properties:m,props:d},content:a.length?a:void 0}}function ee(t){if(!t.content)return"";const e=[];for(const n of t.content)e.push(...cn(n));return e.join(`
21
+ `)}function cn(t){if(t.type==="bulletList"&&t.content)return t.content.flatMap(n=>n.content?n.content.map(s=>{const{text:o,props:c}=_t(s);return`- ${o}${W(c)}`}):[]);if(t.type==="orderedList"&&t.content){let n=1;return t.content.flatMap(s=>s.content?s.content.map(o=>{const{text:c,props:a}=_t(o);return`${n++}. ${c}${W(a)}`}):[])}const e=ln(t);return e!==null?[e]:[]}function ln(t){const{text:e,props:n}=_t(t);switch(t.type){case"itTitle":{const s=at(t.attrs?.props,n);return`title: ${e}${W(s)}`}case"itSummary":{const s=at(t.attrs?.props,n);return`summary: ${e}${W(s)}`}case"itSection":{const s=at(t.attrs?.props,n);return`section: ${e}${W(s)}`}case"itSub":{const s=at(t.attrs?.props,n);return`sub: ${e}${W(s)}`}case"paragraph":{const s=t.attrs||{},o={};return s.end&&(o.end=String(s.end)),s.leading&&(o.leading=String(s.leading)),s.spaceBefore&&(o["space-before"]=String(s.spaceBefore)),s.spaceAfter&&(o["space-after"]=String(s.spaceAfter)),`text: ${e}${W({...o,...n})}`}case"itCallout":{const s=t.attrs?.variant||"tip",o=at(t.attrs?.props,n,new Set(["variant"]));return s==="info"?`info: ${e}${W(o)}`:`info: ${e} | type: ${s}${W(o,new Set(["type"]))}`}case"itQuote":{const s=t.attrs?.by,o=s?` | by: ${s}`:"",c=at(t.attrs?.props,n,new Set(["by"]));return`quote: ${e}${o}${W(c)}`}case"itCode":return`\`\`\`${t.attrs?.lang||""}
22
+ ${Rt(t)}
23
+ \`\`\``;case"itDivider":return"divider:";case"itTable":{let s=[];try{s=JSON.parse(t.attrs?.rows||"[]")}catch{s=[]}return s.map(o=>`| ${o.join(" | ")} |`).join(`
24
+ `)}case"itMeta":return t.attrs?.raw||"";case"itTrust":return t.attrs?.raw||"";case"itMetric":return t.attrs?.raw||"";case"itStyleRule":return t.attrs?.raw||"";case"itBreak":return"break:";case"itComment":return e?`// ${e}`:"//";case"itGenericBlock":{const s=t.attrs?.keyword||"text",o=at(t.attrs?.props,n);return`${s}: ${e}${W(o)}`}default:return e?`text: ${e}${W(n)}`:null}}function l(t,e){return{property:t,css:e}}const dn=[l("align","textAlign"),l("color","color"),l("size","fontSize"),l("weight","fontWeight"),{property:"style",css:"fontStyle"},l("bgcolor","backgroundColor"),l("padding","padding"),l("indent","paddingLeft"),l("opacity","opacity")],gt=[l("bgcolor","backgroundColor"),l("color","color"),l("border","borderLeft")],$=[l("color","borderColor"),l("bgcolor","backgroundColor")],un={title:[l("align","textAlign"),l("color","color"),l("size","fontSize"),l("weight","fontWeight"),l("font","fontFamily")],summary:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"}],section:[l("align","textAlign"),l("color","color"),l("size","fontSize"),l("weight","fontWeight"),l("border","borderBottom"),l("spacing","marginTop")],sub:[l("align","textAlign"),l("color","color"),l("size","fontSize"),l("weight","fontWeight")],divider:[{property:"style",css:"borderStyle"},l("color","borderColor"),l("width","borderTopWidth"),l("spacing","margin")],text:[...dn],tip:[...gt],info:[...gt],warning:[...gt],danger:[...gt],success:[...gt],quote:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"},l("border","borderLeft"),l("padding","paddingLeft"),l("bgcolor","backgroundColor")],cite:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"}],def:[l("color","color"),l("bgcolor","backgroundColor"),l("border","borderLeft"),l("padding","paddingLeft")],caption:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"}],footnote:[l("color","color"),l("size","fontSize")],byline:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"},l("weight","fontWeight")],epigraph:[l("align","textAlign"),l("color","color"),l("size","fontSize"),{property:"style",css:"fontStyle"},l("padding","padding")],dedication:[l("align","textAlign"),l("color","color"),{property:"style",css:"fontStyle"},l("padding","padding")],image:[l("width","width"),l("height","height"),l("radius","borderRadius"),l("border","border"),l("opacity","opacity"),l("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],figure:[l("width","width"),l("align","textAlign"),l("border","border"),l("padding","padding"),l("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],link:[l("color","color"),l("weight","fontWeight")],ref:[l("color","color"),{property:"style",css:"fontStyle"}],embed:[l("width","width"),l("height","height"),l("border","border"),l("radius","borderRadius")],metric:[l("color","color"),l("size","fontSize"),l("align","textAlign"),l("bgcolor","backgroundColor"),l("border","border"),l("padding","padding")],columns:[l("border","border"),l("bgcolor","backgroundColor"),l("padding","padding"),l("size","fontSize"),l("align","textAlign")],row:[l("border","border"),l("bgcolor","backgroundColor"),l("padding","padding"),l("size","fontSize"),l("align","textAlign")],input:[l("color","color"),l("bgcolor","backgroundColor"),l("border","borderLeft"),l("size","fontSize")],output:[l("color","color"),l("bgcolor","backgroundColor"),l("border","borderLeft"),l("size","fontSize")],code:[l("size","fontSize"),l("bgcolor","backgroundColor"),l("color","color"),l("padding","padding"),l("radius","borderRadius"),l("border","border")],contact:[l("color","color"),l("bgcolor","backgroundColor"),l("border","border"),l("padding","padding"),l("size","fontSize")],deadline:[l("color","color"),l("bgcolor","backgroundColor"),l("weight","fontWeight"),l("size","fontSize")],step:[...$],decision:[...$],gate:[...$],trigger:[...$],loop:[...$],parallel:[...$],call:[...$],wait:[...$],checkpoint:[...$],error:[...$],result:[...$],audit:[...$],signal:[...$],handoff:[...$],retry:[...$],progress:[...$],tool:[...$],prompt:[...$],memory:[...$],policy:[...$],context:[...$],track:[...$],approve:[...$],sign:[...$],freeze:[...$],revision:[...$],amendment:[...$],history:[l("color","borderColor")],assert:[l("color","borderColor"),l("bgcolor","backgroundColor"),l("border","borderLeft")],secret:[l("color","color"),l("bgcolor","backgroundColor"),l("blur","filter")],watermark:[l("color","color"),l("size","fontSize"),l("opacity","opacity")],signline:[l("color","color"),l("width","width")]};function pn(t,e){const n=un[t];if(!n)return{};const s={};for(const o of n){const c=e[o.property];c&&(o.transform?s[o.css]=o.transform(c):s[o.css]=c)}return s}function X(t,e){const n=pn(t,e);return e.leading&&(n.lineHeight=e.leading),e["space-before"]&&(n.marginTop=e["space-before"]),e["space-after"]&&(n.marginBottom=e["space-after"]),Object.entries(n).map(([s,o])=>`${s.replace(/([A-Z])/g,"-$1").toLowerCase()}:${o}`).join(";")}function Ht(t){return t.end?{"data-it-end":t.end}:{}}const fn=j.Node.create({name:"itTitle",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}",parseHTML:t=>t.getAttribute("data-props")||"{}"}}},parseHTML(){return[{tag:'h1[data-it-type="title"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props),s=j.mergeAttributes(t,{"data-it-type":"title",class:"it-doc-title",style:X("title",n),...Ht(n)});return n.end?["h1",s,["span",{class:"it-split-main"},0]]:["h1",s,0]}}),gn=j.Node.create({name:"itSummary",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'p[data-it-type="summary"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props);return["p",j.mergeAttributes(t,{"data-it-type":"summary",class:"it-doc-summary",style:X("summary",n)}),0]}}),hn=j.Node.create({name:"itSection",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'h2[data-it-type="section"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props),s=j.mergeAttributes(t,{"data-it-type":"section",class:"it-doc-section",style:X("section",n),...Ht(n)});return n.end?["h2",s,["span",{class:"it-split-main"},0]]:["h2",s,0]}}),mn=j.Node.create({name:"itSub",group:"block",content:"inline*",defining:!0,addAttributes(){return{props:{default:"{}"}}},parseHTML(){return[{tag:'h3[data-it-type="sub"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props),s=j.mergeAttributes(t,{"data-it-type":"sub",class:"it-doc-sub",style:X("sub",n),...Ht(n)});return n.end?["h3",s,["span",{class:"it-split-main"},0]]:["h3",s,0]}}),bn=j.Node.create({name:"itCallout",group:"block",content:"inline*",defining:!0,addAttributes(){return{variant:{default:"tip",parseHTML:t=>t.getAttribute("data-variant")||"tip",renderHTML:t=>({"data-variant":t.variant})},props:{default:"{}"}}},parseHTML(){return[{tag:'div[data-it-type="callout"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.variant||"tip",s=ot(e.attrs.props),o={tip:"tip",info:"info",warning:"warning",danger:"danger",success:"success"};return["div",j.mergeAttributes(t,{"data-it-type":"callout","data-variant":n,class:`it-doc-callout it-doc-callout-${n}`,style:X(n,s)}),["span",{class:`it-doc-callout-icon it-doc-callout-icon-${o[n]||"tip"}`,contenteditable:"false"},""],["span",{class:"it-doc-callout-text"},0]]}}),yn=j.Node.create({name:"itQuote",group:"block",content:"inline*",defining:!0,addAttributes(){return{by:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:'blockquote[data-it-type="quote"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props);return["blockquote",j.mergeAttributes(t,{"data-it-type":"quote",class:"it-doc-quote",style:X("quote",n)}),0]}}),xn=j.Node.create({name:"itCode",group:"block",content:"text*",marks:"",code:!0,defining:!0,addAttributes(){return{lang:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:"pre"}]},renderHTML({HTMLAttributes:t,node:e}){const n=ot(e.attrs.props);return["pre",j.mergeAttributes(t,{"data-it-type":"code",class:"it-doc-code","data-lang":e.attrs.lang||"",style:X("code",n)}),["code",0]]}}),Sn=j.Node.create({name:"itDivider",group:"block",atom:!0,parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",j.mergeAttributes(t,{class:"it-doc-divider"})]}}),kn=j.Node.create({name:"itMeta",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-meta]"}]},renderHTML({HTMLAttributes:t,node:e}){const n=String(e.attrs.raw||"").replace(/\s*\|\s*/g," · ");return["div",j.mergeAttributes(t,{"data-it-meta":"",class:"it-doc-meta"}),`⚙ ${n}`]}});function Tt(t){try{const e=JSON.parse(t||"[]");return Array.isArray(e)?e:[]}catch{return[]}}const vn=j.Node.create({name:"itTable",group:"block",atom:!0,selectable:!0,addAttributes(){return{rows:{default:"[]",parseHTML:t=>t.getAttribute("data-rows")||"[]",renderHTML:t=>({"data-rows":t.rows})}}},parseHTML(){return[{tag:"table[data-it-table]"}]},renderHTML({HTMLAttributes:t,node:e}){const n=Tt(e.attrs.rows),s=n[0]||[],o=n.slice(1);return["table",j.mergeAttributes(t,{"data-it-table":"",class:"it-doc-table"}),["thead",["tr",...s.map(c=>["th",Gt(c),String(c)])]],["tbody",...o.map(c=>["tr",...c.map(a=>["td",Gt(a),String(a)])])]]},addNodeView(){return({node:t,editor:e,getPos:n})=>{const s=document.createElement("table");s.className="it-doc-table",s.setAttribute("data-it-table","");const o=document.createElement("thead"),c=document.createElement("tbody");s.append(o,c);let a=Tt(t.attrs.rows);const d=()=>{const u=[];s.querySelectorAll("tr").forEach(g=>{const b=[];g.querySelectorAll("th,td").forEach(k=>b.push((k.textContent||"").trim())),u.push(b)});const h=JSON.stringify(u);if(h!==t.attrs.rows&&(a=u,typeof n=="function")){const g=n();if(g==null)return;const b=e.view.state.tr.setNodeAttribute(g,"rows",h);e.view.dispatch(b)}},i=(u,h)=>{const g=document.createElement(u);g.textContent=h;const b=e.isEditable;return g.contentEditable=b?"true":"false",/\{\{[^}]+\}\}|^each:/.test(String(h).trim())&&(g.className="it-doc-var-cell"),g.addEventListener("blur",d),g.addEventListener("keydown",k=>{k.key==="Enter"&&(k.preventDefault(),k.target.blur())}),g},m=u=>{o.innerHTML="",c.innerHTML="";const h=u[0]||[],g=document.createElement("tr");h.forEach(b=>g.appendChild(i("th",String(b)))),o.appendChild(g),u.slice(1).forEach(b=>{const k=document.createElement("tr");b.forEach(w=>k.appendChild(i("td",String(w)))),c.appendChild(k)})};return m(a),{dom:s,update(u){return u.type.name!=="itTable"?!1:(u.attrs.rows!==JSON.stringify(a)&&(a=Tt(u.attrs.rows),m(a)),!0)},ignoreMutation:()=>!0}}}});function Gt(t){return/\{\{[^}]+\}\}|^each:/.test(String(t).trim())?{class:"it-doc-var-cell"}:{}}function Pt(t){const e=t.indexOf(":"),n=(e>=0?t.slice(0,e):t).trim().toLowerCase(),o=(e>=0?t.slice(e+1).trim():"").split("|").map(d=>d.trim()),c=o.shift()||"",a={};for(const d of o){const i=d.indexOf(":");i>0&&(a[d.slice(0,i).trim().toLowerCase()]=d.slice(i+1).trim())}return{keyword:n,content:c,props:a}}const wn=j.Node.create({name:"itTrust",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})},keyword:{default:"",parseHTML:t=>t.getAttribute("data-trust")||"",renderHTML:t=>({"data-trust":t.keyword})}}},parseHTML(){return[{tag:"div[data-it-trust]"}]},renderHTML({HTMLAttributes:t,node:e}){const{keyword:n,content:s,props:o}=Pt(String(e.attrs.raw||"")),c=o.role||o.title||"",a=(o.at||o.date||o.time||"").slice(0,10),d=[];if(n==="seal"||n==="freeze"){const i=n==="seal"&&s||o.hash||"";d.push(["span",{class:"it-doc-trust__label"},"Sealed document"]),a&&d.push(["span",{class:"it-doc-trust__date"},a]),i&&d.push(["code",{class:"it-doc-trust__hash"},i.length>20?i.slice(0,20)+"...":i])}else if(n==="approve"){const i=o.by||s,m=o.by?s:"";d.push(["span",{class:"it-doc-trust__label"},"Approved"]),m&&d.push(["span",{class:"it-doc-trust__what"},m]),i&&d.push(["span",{class:"it-doc-trust__who"},c?`${i}, ${c}`:i]),a&&d.push(["span",{class:"it-doc-trust__date"},a])}else if(n==="amend"||n==="amendment")d.push(["span",{class:"it-doc-trust__label"},"Amendment"]),s&&d.push(["span",{class:"it-doc-trust__what"},s]),a&&d.push(["span",{class:"it-doc-trust__date"},a]);else{const i=s||o.by||"",m=!!o.hash;d.push(["span",{class:"it-doc-trust__name"},i]),c&&d.push(["span",{class:"it-doc-trust__role"},c]),a&&d.push(["span",{class:"it-doc-trust__date"},a]),d.push(["span",{class:"it-doc-trust__status"},m?"Signed · verified":"Signed"])}return["div",j.mergeAttributes(t,{"data-it-trust":"","data-trust":n,class:`it-doc-trust it-doc-trust--${n}`}),...d]}}),jn=j.Node.create({name:"itMetric",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-metric]"}]},renderHTML({HTMLAttributes:t,node:e}){const{content:n,props:s}=Pt(String(e.attrs.raw||"")),o=[s.value,s.unit].filter(Boolean).join(" "),c=/\b(total|balance due|amount due|grand)\b/i.test(n),a=/\{\{[^}]+\}\}/.test(o);return["div",j.mergeAttributes(t,{"data-it-metric":"",class:`it-doc-metric${c?" it-doc-metric--total":""}`}),["span",{class:"it-doc-metric__label"},n],["span",{class:`it-doc-metric__value${a?" it-doc-var":""}`},o]]}}),Tn=j.Node.create({name:"itStyleRule",group:"block",atom:!0,addAttributes(){return{raw:{default:"",parseHTML:t=>t.getAttribute("data-raw")||"",renderHTML:t=>({"data-raw":t.raw})}}},parseHTML(){return[{tag:"div[data-it-style-rule]"}]},renderHTML({HTMLAttributes:t,node:e}){const{content:n,props:s}=Pt(String(e.attrs.raw||"")),o=Object.entries(s).map(([c,a])=>`${c}: ${a}`).join(" · ");return["div",j.mergeAttributes(t,{"data-it-style-rule":"",class:"it-doc-stylerule"}),["span",{class:"it-doc-stylerule__icon"},"🎨"],["span",{class:"it-doc-stylerule__target"},n||"?"],["span",{class:"it-doc-stylerule__decl"},o]]}}),Nn=j.Node.create({name:"itBreak",group:"block",atom:!0,parseHTML(){return[{tag:'div[data-it-type="break"]'}]},renderHTML({HTMLAttributes:t}){return["div",j.mergeAttributes(t,{"data-it-type":"break",class:"it-doc-break"})]}}),Cn=j.Node.create({name:"itGenericBlock",group:"block",content:"inline*",defining:!0,addAttributes(){return{keyword:{default:"text"},properties:{default:""},props:{default:"{}"}}},parseHTML(){return[{tag:'[data-it-type="generic"]'}]},renderHTML({HTMLAttributes:t,node:e}){const n=e.attrs.keyword,s=ot(e.attrs.props),o=String(s.to||s.url||s.href||s.file||"").trim();return(n==="link"||n==="ref")&&o?["p",j.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:X(n,s)}),["a",{class:"it-doc-inline-link",href:o,target:"_blank",rel:"noopener noreferrer"},0]]:["p",j.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:X(n,s)}),["span",{class:"it-doc-generic-content"},0]]}}),An=j.Node.create({name:"itComment",group:"block",content:"inline*",defining:!0,parseHTML(){return[{tag:'p[data-it-type="comment"]'}]},renderHTML({HTMLAttributes:t}){return["p",j.mergeAttributes(t,{"data-it-type":"comment",class:"it-doc-comment"}),0]}});function ot(t){try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}const ne={leading:"leading","space-before":"spaceBefore","space-after":"spaceAfter",end:"end"},Ln=new Set(["itTitle","itSummary","itSection","itSub","itQuote","itCallout","itGenericBlock"]),_n=new Set(["itTitle","itSection","itSub"]);function se(t){try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}function re(t,e){return t==="paragraph"?!0:e==="end"?_n.has(t):Ln.has(t)}const $n=Pe.default.extend({addAttributes(){return{...this.parent?.(),leading:{default:null,parseHTML:t=>t.style.lineHeight||null,renderHTML:t=>t.leading?{style:`line-height: ${t.leading}`}:{}},spaceBefore:{default:null,parseHTML:t=>t.style.marginTop||null,renderHTML:t=>t.spaceBefore?{style:`margin-top: ${t.spaceBefore}`}:{}},spaceAfter:{default:null,parseHTML:t=>t.style.marginBottom||null,renderHTML:t=>t.spaceAfter?{style:`margin-bottom: ${t.spaceAfter}`}:{}},end:{default:null,parseHTML:t=>t.getAttribute("data-it-end"),renderHTML:t=>t.end?{"data-it-end":t.end}:{}}}},renderHTML({node:t,HTMLAttributes:e}){return t.attrs.end?["p",j.mergeAttributes(e),["span",{class:"it-split-main"},0]]:["p",j.mergeAttributes(e),0]}}),Mn=j.Extension.create({name:"blockProps",addCommands(){return{setBlockProp:(t,e)=>({state:n,tr:s,dispatch:o})=>{const{from:c,to:a}=n.selection;let d=!1;return n.doc.nodesBetween(c,a,(i,m)=>{const u=i.type.name;if(u==="bulletList"||u==="orderedList"||!i.isBlock||i.isAtom)return!1;if(!re(u,t))return!0;if(u==="paragraph")s.setNodeMarkup(m,void 0,{...i.attrs,[ne[t]]:e});else{const h=se(i.attrs.props);e==null||e===""?delete h[t]:h[t]=e,s.setNodeMarkup(m,void 0,{...i.attrs,props:JSON.stringify(h)})}return d=!0,!1}),d&&o&&o(s),d}}}});function st(t,e){if(!t)return null;const{state:n}=t,{from:s,to:o}=n.selection;let c=null;return n.doc.nodesBetween(s,o,a=>{if(c!==null)return!1;const d=a.type.name;if(!re(d,e))return!0;if(d==="paragraph"){const i=a.attrs[ne[e]];c=i!=null?String(i):""}else c=se(a.attrs.props)[e]??"";return!1}),c}const Kt={identity:{label:"Identity",icon:"ID",color:"#3b82f6"},content:{label:"Content",icon:"Tx",color:"#6b7280"},structure:{label:"Structure",icon:"##",color:"#22c55e"},data:{label:"Data",icon:"Dt",color:"#a855f7"},agent:{label:"Agent",icon:"Ag",color:"#f97316"},trust:{label:"Trust",icon:"Tr",color:"#eab308"},layout:{label:"Layout",icon:"Pg",color:"#64748b"}};function oe(t){const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.style.cssText="position:fixed;right:0;bottom:0;width:210mm;height:297mm;border:0;visibility:hidden;",document.body.appendChild(e);let n=!1;const s=()=>{if(!n){n=!0;try{e.contentWindow.focus(),e.contentWindow.print()}finally{setTimeout(()=>e.remove(),1e3)}}};e.onload=()=>window.setTimeout(s,120);const o=e.contentWindow.document;o.open(),o.write(t),o.close(),o.readyState==="complete"&&window.setTimeout(s,250)}function En(t,e){return t.includes("</head>")?t.replace("</head>",`<style>${e}</style></head>`):t}const ie=".it-doc-callout{background:none!important;border:1px solid #ccc!important}",Yt=R.cssContentValue;function Rn(t,e){const n=document.querySelector(".docs-page .tiptap");if(!n)return null;const s=n.cloneNode(!0);s.querySelectorAll("[data-it-spacer]").forEach(h=>h.remove()),s.querySelectorAll('.it-doc-comment, [data-it-type="comment"]').forEach(h=>h.remove());const o=s.innerHTML,c=Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).map(h=>h.outerHTML).join(`
25
+ `),a=xt(t),d=a.autoHeight?`${a.width}px auto`:`${a.width}px ${a.height}px`,i=`${a.marginTop}px ${a.marginRight}px ${a.marginBottom}px ${a.marginLeft}px`;let m=`@page{size:${d};margin:${i};}`;a.header&&(m+=`@page{@top-center{content:${Yt(a.header)};font:10px -apple-system,sans-serif;color:#9aa0a6;}}`),a.footer&&(m+=`@page{@bottom-center{content:${Yt(a.footer)};font:10px -apple-system,sans-serif;color:#9aa0a6;}}`);const u=`
22
26
  html,body{margin:0;background:#fff;}
23
27
  .docs-page,.docs-page.docs-sheet{box-shadow:none;border-radius:0;margin:0;width:auto;min-height:0;padding:0;background:#fff;}
24
28
  .docs-page .tiptap{padding:0;}
25
29
  [data-it-spacer]{display:none!important;}
26
- ${e==="minimal-ink"?Zt:""}
27
- `;return`<!doctype html><html><head><meta charset="utf-8">${l}<style>${g}${f}</style></head><body><div class="docs-page docs-sheet"><div class="tiptap">${s}</div></div></body></html>`}function Nn(t,e,n){const r=new Blob([t],{type:n}),s=URL.createObjectURL(r),l=document.createElement("a");l.href=s,l.download=e,l.click(),URL.revokeObjectURL(s)}function Xt(t,e,n){let r=Cn(t,n);if(!r){const s=H.parseIntentText(t);r=H.renderPrint(s,{theme:e}),n==="minimal-ink"&&(r=An(r,Zt))}return r}function te(t,e,n="normal"){try{Qt(Xt(t,e,n))}catch{}}function ee(t,e,n="normal"){try{Nn(Xt(t,e,n),"document.html","text/html")}catch{}}function ne(){return H.listBuiltinThemes()}const wt=[{label:"Normal text",node:"paragraph"},{label:"Title",node:"itTitle"},{label:"Section",node:"itSection"},{label:"Subsection",node:"itSub"},{label:"Summary",node:"itSummary"},{label:"Quote",node:"itQuote"}],Ln=new Set(["history","revision","track","freeze"]),$n=new Set(["agent","model","meta","context","history"]),Mn=["identity","structure","content","data","trust","layout"],qt=[{label:"Default",value:""},{label:"Inter",value:"Inter"},{label:"Arial",value:"Arial"},{label:"Times New Roman",value:"Times New Roman"},{label:"Georgia",value:"Georgia"},{label:"Courier New",value:"Courier New"},{label:"Verdana",value:"Verdana"},{label:"Trebuchet MS",value:"Trebuchet MS"}],_n=["1","1.15","1.5","2","2.5","3"],zn="12px",Rn=["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#f3f3f3","#ffffff","#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff","#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc","#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd","#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"],Hn=["#ffffff","#cfe2f3","#d9ead3","#fff2cc","#fce5cd","#f4cccc","#d9d2e9","#ead1dc","#d0e0e3","#e6b8af"];function M({onClick:t,active:e,disabled:n,title:r,children:s}){return o.jsx("button",{className:`docs-tb-btn${e?" active":""}`,onClick:t,disabled:n,title:r,children:s})}function at({label:t,children:e,className:n=""}){return o.jsx("div",{className:`ribbon-group ${n}`.trim(),role:"group","aria-label":t,children:e})}function pt(){return o.jsx("div",{className:"ribbon-sep"})}function En({editor:t,isRtl:e=!1,onToggleRtl:n,content:r,theme:s,onThemeChange:l,onTrustAction:c,locked:d=!1}){const[i,g]=p.useState(!1),[f,m]=p.useState(!1),[h,x]=p.useState(!1),[_,L]=p.useState(!1),[T,w]=p.useState(!1),[E,P]=p.useState(!1),[W,G]=p.useState(!1),O=p.useRef(null),X=p.useRef(null),$=p.useRef(null),R=p.useRef(null),tt=p.useRef(null),D=p.useRef(null);p.useEffect(()=>{const u=A=>{const k=A.target;O.current&&!O.current.contains(k)&&g(!1),X.current&&!X.current.contains(k)&&m(!1),$.current&&!$.current.contains(k)&&x(!1),R.current&&!R.current.contains(k)&&L(!1),tt.current&&!tt.current.contains(k)&&w(!1),D.current&&!D.current.contains(k)&&P(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const C=()=>{g(!1),m(!1),x(!1),L(!1),w(!1),P(!1)},et=p.useCallback(()=>{if(!t)return"Normal text";for(const u of wt)if(u.node==="paragraph"&&t.isActive("paragraph")){if(!wt.some(k=>k.node!=="paragraph"&&t.isActive(k.node)))return u.label}else if(t.isActive(u.node))return u.label;return"Normal text"},[t]),ct=p.useCallback(()=>{if(!t)return"Default";const u=t.getAttributes("textStyle")?.fontFamily;if(!u)return"Default";const A=qt.find(k=>k.value===u);return A?A.label:"Default"},[t]),[Y,lt]=p.useState(11),[,st]=p.useState(0),b=p.useMemo(()=>{const u=new Map;for(const k of H.LANGUAGE_REGISTRY){if(k.status!=="stable"||$n.has(k.canonical)||k.category==="agent")continue;const J=k.category,gt=u.get(J)||[];gt.push({label:k.canonical,keyword:k.canonical,category:J,description:k.description,isReadOnly:Ln.has(k.canonical)}),u.set(J,gt)}const A=[];for(const k of Mn){const J=u.get(k);!J||J.length===0||(J.sort((gt,de)=>gt.keyword.localeCompare(de.keyword)),A.push({category:Dt[k]?.label||k,items:J}))}return A},[]);p.useEffect(()=>{if(!t)return;const u=()=>{const A=t.getAttributes("textStyle");if(A?.fontSize){const k=parseInt(A.fontSize,10);isNaN(k)||lt(k)}st(k=>k+1)};return t.on("selectionUpdate",u),t.on("transaction",u),()=>{t.off("selectionUpdate",u),t.off("transaction",u)}},[t]);const y=p.useCallback(u=>{t&&(u==="paragraph"?t.chain().focus().setParagraph().run():u==="itQuote"?t.chain().focus().setNode("itQuote").run():t.chain().focus().setNode(u).run(),C())},[t]),j=p.useCallback(u=>{if(!t)return;const A=t.chain().focus();u==="divider"?A.setNode("itDivider").run():u==="break"?A.setNode("itBreak").run():u==="code"?A.setNode("itCode",{lang:""}).run():["tip","info","warning","danger","success"].includes(u)?A.setNode("itCallout",{variant:u}).run():A.setNode("itGenericBlock",{keyword:u,properties:""}).run(),C()},[t]),I=p.useCallback(u=>{const A=Math.min(96,Math.max(8,Y+u));lt(A),t?.chain().focus().setFontSize(`${A}pt`).run()},[t,Y]),K=p.useCallback(u=>{t?.chain().focus().setBlockProp("leading",u).run(),C()},[t]),F=p.useCallback(u=>{if(!t)return;const A=V(t,u);t.chain().focus().setBlockProp(u,A?null:zn).run(),C()},[t]),re=p.useCallback(()=>{if(!t)return;const u=window.prompt("Space before block (e.g. 12px, 1em — empty for none):",V(t,"space-before")||"");if(u===null)return;const A=window.prompt("Space after block (e.g. 12px, 1em — empty for none):",V(t,"space-after")||"");A!==null&&(t.chain().focus().setBlockProp("space-before",u.trim()||null).setBlockProp("space-after",A.trim()||null).run(),C())},[t]),se=p.useCallback(()=>{if(!t)return;const u=V(t,"end"),A=window.prompt("Line-end text (shown at the end of the line — empty to remove):",u||"");A!==null&&t.chain().focus().setBlockProp("end",A.trim()||null).run()},[t]),oe=p.useCallback(()=>{t&&(t.chain().focus().insertContent({type:"paragraph",attrs:{end:"End text"},content:[{type:"text",text:"Start text"}]}).run(),C())},[t]),ie=p.useMemo(()=>ne(),[]),ft=W?"minimal-ink":"normal",ae=p.useCallback(()=>te(r,s,ft),[r,s,ft]),ce=p.useCallback(()=>ee(r,s,ft),[r,s,ft]);if(!t)return null;const xt=V(t,"leading"),le=!!V(t,"end");return o.jsxs("div",{className:"docs-toolbar docs-ribbon",children:[o.jsxs(at,{label:"Edit",children:[o.jsx(M,{onClick:()=>t.chain().focus().undo().run(),disabled:d||!t.can().undo(),title:"Undo (⌘Z)",children:o.jsx(v.Undo2,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().redo().run(),disabled:d||!t.can().redo(),title:"Redo (⌘⇧Z)",children:o.jsx(v.Redo2,{size:16})})]}),o.jsx(pt,{}),o.jsxs(at,{label:"File",children:[o.jsxs(M,{onClick:ae,title:"Print / Export PDF (WYSIWYG)",children:[o.jsx(v.Printer,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"PDF"})]}),o.jsxs(M,{onClick:ce,title:"Export HTML",children:[o.jsx(v.FileCode2,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"HTML"})]}),o.jsx(M,{onClick:()=>G(u=>!u),active:W,title:"Minimal ink mode (plain callouts when printing)",children:o.jsx(v.Droplets,{size:16})}),o.jsx("select",{className:"ribbon-theme-select",value:s,onChange:u=>l(u.target.value),title:"Document theme (used by print/export)",children:ie.map(u=>o.jsx("option",{value:u,children:u.charAt(0).toUpperCase()+u.slice(1)},u))})]}),o.jsx(pt,{}),o.jsxs("div",{className:d?"ribbon-locked":"ribbon-editing",children:[o.jsxs(at,{label:"Text",children:[o.jsxs("div",{className:"docs-tb-dropdown",ref:$,children:[o.jsxs("button",{className:"docs-tb-select docs-tb-font-select",onClick:()=>{C(),x(!h)},children:[o.jsx("span",{className:"docs-tb-select-label",children:ct()}),o.jsx(v.ChevronDown,{size:14})]}),h&&o.jsx("div",{className:"docs-tb-dropdown-menu docs-font-menu",children:qt.map(u=>o.jsx("button",{className:`docs-tb-dropdown-item${ct()===u.label?" active":""}`,style:{fontFamily:u.value||"inherit"},onClick:()=>{u.value?t.chain().focus().setFontFamily(u.value).run():t.chain().focus().unsetFontFamily().run(),C()},children:u.label},u.value||"default"))})]}),o.jsx(M,{onClick:()=>I(-1),title:"Decrease font size",children:o.jsx(v.Minus,{size:14})}),o.jsx("span",{className:"docs-tb-fontsize",children:Y}),o.jsx(M,{onClick:()=>I(1),title:"Increase font size",children:o.jsx(v.Plus,{size:14})}),o.jsx(M,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (⌘B)",children:o.jsx(v.Bold,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (⌘I)",children:o.jsx(v.Italic,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (⌘U)",children:o.jsx(v.Underline,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().toggleStrike().run(),active:t.isActive("strike"),title:"Strikethrough (⌘⇧X)",children:o.jsx(v.Strikethrough,{size:16})}),o.jsxs("div",{className:"docs-tb-dropdown docs-tb-color-dropdown",ref:R,children:[o.jsxs("button",{className:"docs-tb-btn docs-tb-color-btn",onClick:()=>{C(),L(!_)},title:"Text color",children:[o.jsx(v.Palette,{size:16}),o.jsx("span",{className:"docs-tb-color-indicator",style:{background:t.getAttributes("textStyle")?.color||"#000000"}})]}),_&&o.jsxs("div",{className:"docs-tb-dropdown-menu docs-color-grid-menu",children:[o.jsx("div",{className:"docs-color-grid-label",children:"Text color"}),o.jsx("div",{className:"docs-color-grid",children:Rn.map(u=>o.jsx("button",{className:"docs-color-swatch",style:{background:u},title:u,onClick:()=>{t.chain().focus().setColor(u).run(),C()}},u))}),o.jsxs("button",{className:"docs-tb-dropdown-item",onClick:()=>{t.chain().focus().unsetColor().run(),C()},children:[o.jsx(v.RemoveFormatting,{size:14})," Reset"]})]})]}),o.jsxs("div",{className:"docs-tb-dropdown docs-tb-color-dropdown",ref:tt,children:[o.jsxs("button",{className:"docs-tb-btn docs-tb-color-btn",onClick:()=>{C(),w(!T)},title:"Highlight color",children:[o.jsx(v.Highlighter,{size:16}),o.jsx("span",{className:"docs-tb-color-indicator",style:{background:t.getAttributes("highlight")?.color||"transparent"}})]}),T&&o.jsxs("div",{className:"docs-tb-dropdown-menu docs-color-grid-menu",children:[o.jsx("div",{className:"docs-color-grid-label",children:"Highlight color"}),o.jsx("div",{className:"docs-color-grid docs-highlight-grid",children:Hn.map(u=>o.jsx("button",{className:"docs-color-swatch",style:{background:u},title:u,onClick:()=>{u==="#ffffff"?t.chain().focus().unsetHighlight().run():t.chain().focus().toggleHighlight({color:u}).run(),C()}},u))})]})]}),o.jsx(M,{onClick:()=>t.chain().focus().toggleCode().run(),active:t.isActive("code"),title:"Inline code",children:o.jsx(v.Code,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().unsetAllMarks().clearNodes().run(),title:"Clear formatting",children:o.jsx(v.RemoveFormatting,{size:16})})]}),o.jsx(pt,{}),o.jsxs(at,{label:"Paragraph",children:[o.jsxs("div",{className:"docs-tb-dropdown",ref:O,children:[o.jsxs("button",{className:"docs-tb-select docs-tb-paragraph-select",onClick:()=>{C(),g(!i)},children:[o.jsx("span",{className:"docs-tb-select-label",children:et()}),o.jsx(v.ChevronDown,{size:14})]}),i&&o.jsx("div",{className:"docs-tb-dropdown-menu docs-style-menu",children:wt.map(u=>o.jsx("button",{className:`docs-tb-dropdown-item${et()===u.label?" active":""}`,onClick:()=>y(u.node),children:o.jsx("span",{className:`docs-style-preview docs-style-${u.node}`,children:u.label})},u.node))})]}),o.jsx(M,{onClick:()=>t.chain().focus().setTextAlign("left").run(),active:t.isActive({textAlign:"left"}),title:"Align left",children:o.jsx(v.AlignLeft,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().setTextAlign("center").run(),active:t.isActive({textAlign:"center"}),title:"Align center",children:o.jsx(v.AlignCenter,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().setTextAlign("right").run(),active:t.isActive({textAlign:"right"}),title:"Align right",children:o.jsx(v.AlignRight,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().setTextAlign("justify").run(),active:t.isActive({textAlign:"justify"}),title:"Justify",children:o.jsx(v.AlignJustify,{size:16})}),o.jsx(M,{onClick:()=>n?.(),active:e,title:e?"Switch to LTR (left-to-right)":"Switch to RTL (right-to-left)",children:o.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1},children:e?"LTR":"RTL"})}),o.jsxs("div",{className:"docs-tb-dropdown",ref:D,children:[o.jsxs("button",{className:`docs-tb-btn${xt?" active":""}`,onClick:()=>{C(),P(!E)},title:"Line & paragraph spacing",children:[o.jsx(v.Rows3,{size:16}),o.jsx(v.ChevronDown,{size:12})]}),E&&o.jsxs("div",{className:"docs-tb-dropdown-menu docs-spacing-menu",children:[o.jsx("div",{className:"docs-insert-category",children:"Line spacing"}),o.jsx("button",{className:`docs-tb-dropdown-item${xt?"":" active"}`,onClick:()=>K(null),children:"Default"}),_n.map(u=>o.jsx("button",{className:`docs-tb-dropdown-item${xt===u?" active":""}`,onClick:()=>K(u),children:u==="1"?"Single":u==="2"?"Double":u},u)),o.jsx("div",{className:"docs-insert-divider"}),o.jsx("div",{className:"docs-insert-category",children:"Paragraph spacing"}),o.jsx("button",{className:"docs-tb-dropdown-item",onClick:()=>F("space-before"),children:V(t,"space-before")?"Remove space before block":"Add space before block"}),o.jsx("button",{className:"docs-tb-dropdown-item",onClick:()=>F("space-after"),children:V(t,"space-after")?"Remove space after block":"Add space after block"}),o.jsx("button",{className:"docs-tb-dropdown-item",onClick:re,children:"Custom spacing…"})]})]}),o.jsx(M,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet list",children:o.jsx(v.List,{size:16})}),o.jsx(M,{onClick:()=>t.chain().focus().toggleOrderedList().run(),active:t.isActive("orderedList"),title:"Numbered list",children:o.jsx(v.ListOrdered,{size:16})})]}),o.jsx(pt,{}),o.jsxs(at,{label:"Insert",children:[o.jsxs("div",{className:"docs-tb-dropdown",ref:X,children:[o.jsxs("button",{className:"docs-tb-select docs-tb-insert-select",onClick:()=>{C(),m(!f)},children:[o.jsx(v.Plus,{size:15}),o.jsx("span",{children:"Insert"}),o.jsx(v.ChevronDown,{size:14})]}),f&&o.jsxs("div",{className:"docs-tb-dropdown-menu docs-insert-menu",children:[o.jsxs("button",{className:"docs-tb-dropdown-item docs-insert-item",onClick:oe,title:"Two-sided row — content at the line start, value at the line end (text: … | end: …)",children:[o.jsx("span",{className:"docs-insert-icon",children:o.jsx(v.AlignHorizontalSpaceBetween,{size:13})}),o.jsx("span",{className:"docs-insert-label",children:"two-sided row"}),o.jsx("span",{className:"docs-insert-kw",children:"end:"})]}),o.jsx("div",{className:"docs-insert-divider"}),b.map((u,A)=>o.jsxs("div",{children:[A>0&&o.jsx("div",{className:"docs-insert-divider"}),o.jsx("div",{className:"docs-insert-category",children:u.category}),u.items.map(k=>o.jsxs("button",{className:"docs-tb-dropdown-item docs-insert-item",onClick:()=>j(k.keyword),disabled:k.isReadOnly,title:k.description,children:[o.jsx("span",{className:"docs-insert-icon",children:Dt[k.category]?.icon||"•"}),o.jsx("span",{className:"docs-insert-label",children:k.label}),o.jsx("span",{className:"docs-insert-kw",children:k.isReadOnly?"locked":`.${k.keyword}`})]},k.keyword))]},u.category))]})]}),o.jsx(M,{onClick:se,active:le,title:"Two-sided row — set the text shown at the END of this line (end: property)",children:o.jsx(v.AlignHorizontalSpaceBetween,{size:16})})]})]}),c&&o.jsxs(o.Fragment,{children:[o.jsx(pt,{}),o.jsxs(at,{label:"Trust",children:[o.jsxs(M,{onClick:()=>c("seal"),disabled:d,title:d?"Document is already sealed":"Seal — freeze the document with a tamper-evident hash",children:[o.jsx(v.FileLock2,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"Seal"})]}),o.jsxs(M,{onClick:()=>c("sign"),title:"Sign — add a signature",children:[o.jsx(v.PenTool,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"Sign"})]}),o.jsxs(M,{onClick:()=>c("verify"),title:"Verify — check the document hash and signatures",children:[o.jsx(v.ShieldCheck,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"Verify"})]})]})]})]})}const Pn={in:96,cm:96/2.54},In={in:.25,cm:.5};function Bn({geometry:t,zoom:e,scrollEl:n}){const[r,s]=p.useState(0);p.useEffect(()=>{const d=n.current;if(!d)return;const i=()=>s(d.scrollLeft);return i(),d.addEventListener("scroll",i,{passive:!0}),()=>d.removeEventListener("scroll",i)},[n]);const l=p.useMemo(()=>{const d=Pn[t.unit],i=In[t.unit],g=[],f=t.width/d;for(let m=0;m<=f+1e-6;m+=i){const h=Math.abs(m-Math.round(m))<1e-6;g.push({x:m*d,kind:h?"major":"minor",label:h&&m>0?String(Math.round(m)):void 0})}return g},[t.width,t.unit]),c=t.width*e;return o.jsx("div",{className:"docs-ruler","aria-hidden":"true",children:o.jsxs("div",{className:"docs-ruler-track",style:{width:c,transform:`translateX(${-r}px)`},children:[o.jsx("div",{className:"docs-ruler-margin",style:{left:0,width:t.marginLeft*e}}),o.jsx("div",{className:"docs-ruler-margin",style:{right:0,width:t.marginRight*e}}),l.map((d,i)=>d.label?o.jsx("span",{className:"docs-ruler-num",style:{left:d.x*e},children:d.label},i):o.jsx("span",{className:`docs-ruler-tick docs-ruler-tick--${d.kind}`,style:{left:d.x*e}},i))]})})}function Tt(t,e){return e?`${t} (${e})`:t}function On({trust:t,intact:e}){if(t.isSealed){const n=t.sealedBy||"unknown",r=t.signatures[t.signatures.length-1]?.role;return o.jsxs("div",{className:"docs-trust-banner docs-trust-banner--sealed",role:"status",children:[o.jsx("span",{className:"docs-trust-banner__icon",children:"🔒"}),o.jsx("span",{className:"docs-trust-banner__title",children:"Sealed"}),o.jsxs("span",{className:"docs-trust-banner__text",children:["signed by ",Tt(n,r),t.sealedAt?` on ${t.sealedAt}`:""," · read-only"]}),e===!0&&o.jsx("span",{className:"docs-trust-banner__verify docs-trust-banner__verify--ok",children:"hash verified ✓"}),e===!1&&o.jsx("span",{className:"docs-trust-banner__verify docs-trust-banner__verify--bad",children:"⚠ hash mismatch — content changed after sealing"})]})}return t.signatures.length>0?o.jsxs("div",{className:"docs-trust-banner docs-trust-banner--signed",role:"status",children:[o.jsx("span",{className:"docs-trust-banner__icon",children:"✍"}),o.jsx("span",{className:"docs-trust-banner__title",children:"Signed"}),o.jsxs("span",{className:"docs-trust-banner__text",children:["by"," ",t.signatures.map(n=>`${Tt(n.by,n.role)}${n.at?` on ${n.at}`:""}`).join(" · ")]})]}):t.approvals.length>0?o.jsxs("div",{className:"docs-trust-banner docs-trust-banner--approved",role:"status",children:[o.jsx("span",{className:"docs-trust-banner__icon",children:"✓"}),o.jsx("span",{className:"docs-trust-banner__title",children:"Approved"}),o.jsxs("span",{className:"docs-trust-banner__text",children:["by"," ",t.approvals.map(n=>`${Tt(n.by,n.role)}${n.at?` on ${n.at}`:""}`).join(" · ")]})]}):null}function Dn(t){let e;try{e=H.parseIntentText(t)}catch{return[]}const n=[],r=(s,l)=>{const c=l==null?"":String(l).trim();c&&n.push({key:s,value:c})};for(const s of e.blocks)switch(s.type){case"meta":for(const[l,c]of Object.entries(s.properties||{}))r(l,c);break;case"track":r("tracked",s.properties?.id??s.content);break;case"page":{const l=s.properties?.orientation;r("page",[s.content,l].filter(Boolean).join(" · "));break}case"font":r("font",[s.content||s.properties?.family,s.properties?.size].filter(Boolean).join(" · "));break;case"header":r("header",s.content);break;case"footer":r("footer",s.content);break;case"watermark":r("watermark",s.content);break}return n}function Fn({source:t}){const[e,n]=p.useState(!1),r=p.useMemo(()=>Dn(t),[t]);if(r.length===0)return null;const s=r.slice(0,4).map(l=>`${l.key}: ${l.value}`).join(" · ");return o.jsxs("div",{className:`docs-props-bar${e?" open":""}`,children:[o.jsxs("button",{className:"docs-props-toggle",onClick:()=>n(l=>!l),title:e?"Hide document properties":"Show document properties",children:[o.jsx("span",{className:"docs-props-caret",children:e?"▾":"▸"}),"Document properties",!e&&o.jsx("span",{className:"docs-props-summary",children:s})]}),e&&o.jsx("div",{className:"docs-props-chips",children:r.map((l,c)=>o.jsxs("span",{className:"docs-props-chip",children:[o.jsx("b",{children:l.key})," ",l.value]},`${l.key}-${c}`))})]})}function z(t,e,n=""){const r=t?.properties?.[e];return r!=null?String(r):n}function Nt(t){const e={lifecycle:"draft",isTracked:!1,trackBlock:null,approvals:[],signatures:[],isSealed:!1,sealedBy:null,sealedAt:null,sealHash:null,amendments:[]};if(!t)return e;const n=t.blocks,r=n.find(i=>i.type==="track");r&&(e.isTracked=!0,e.lifecycle="tracked",e.trackBlock={id:z(r,"id",r.content??""),by:z(r,"by"),at:z(r,"at")});const s=n.filter(i=>i.type==="approve");for(const i of s)e.approvals.push({by:z(i,"by",i.content??""),role:z(i,"role"),at:z(i,"at"),note:z(i,"note")||void 0});e.approvals.length>0&&(e.lifecycle="approved");const l=n.filter(i=>i.type==="sign");for(const i of l)e.signatures.push({by:z(i,"by",i.content??""),role:z(i,"role"),at:z(i,"at")});e.signatures.length>0&&(e.lifecycle="signed");const c=n.find(i=>i.type==="freeze");if(c){e.isSealed=!0,e.lifecycle="sealed";const i=e.signatures[e.signatures.length-1];e.sealedBy=i?.by||z(c,"by",c.content??""),e.sealedAt=z(c,"at")||i?.at||"",e.sealHash=z(c,"hash")}const d=n.filter(i=>i.type==="amendment");for(const i of d)e.amendments.push({section:z(i,"section",i.content??""),was:z(i,"was"),now:z(i,"now"),by:z(i,"by"),ref:z(i,"ref"),at:z(i,"at")});return e}const Wt=new yt.PluginKey("template-highlight"),bt=/\{\{[^}]+\}\}/g;function Gt(t){const e=[];return t.descendants((n,r)=>{if(!n.isText||!n.text)return;bt.lastIndex=0;let s;for(;s=bt.exec(n.text);)e.push(rt.Decoration.inline(r+s.index,r+s.index+s[0].length,{class:"it-doc-var"}))}),rt.DecorationSet.create(t,e)}const qn=S.Extension.create({name:"templateHighlight",addProseMirrorPlugins(){return[new yt.Plugin({key:Wt,state:{init:(t,e)=>Gt(e.doc),apply:(t,e)=>t.docChanged?Gt(t.doc):e},props:{decorations(t){return Wt.getState(t)}}})]}});function Wn(t){const e=new Set,n=[];bt.lastIndex=0;let r;for(;r=bt.exec(t);){const s=r[0].slice(2,-2).trim();/^(page|pages|date|time|year)$/i.test(s)||e.has(s)||(e.add(s),n.push(s))}return n}function Gn(t){const e={};for(const n of t){const r=n.split(".");let s=e;for(let l=0;l<r.length;l++){const c=r[l];l===r.length-1?c in s||(s[c]=""):((!(c in s)||typeof s[c]!="object"||s[c]===null)&&(s[c]={}),s=s[c])}}return e}const Un=28,Yn={title:[".it-doc-title"],summary:[".it-doc-summary"],section:[".it-doc-section"],sub:[".it-doc-sub"],text:["p"],quote:[".it-doc-quote"],callout:[".it-doc-callout"],info:[".it-doc-callout"],table:[".it-doc-table th",".it-doc-table td"],"table-header":[".it-doc-table th"],metric:[".it-doc-metric"],contact:['.it-doc-generic[data-keyword="contact"]'],divider:[".it-doc-divider"]};function Kn({value:t,onChange:e,theme:n,onThemeChange:r,readOnly:s=!1,showRibbon:l=!0,showTrustBanner:c=!0,onTrustAction:d}){const i=p.useRef(""),g=p.useRef(!1),f=p.useRef(!0),[m,h]=p.useState([]),x=p.useRef(mt("")),[_,L]=p.useState(1),T=Rt.useEditor({extensions:[Be.configure({geometry:()=>x.current,gap:Un,onPages:L}),we.default.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,paragraph:!1}),vn,jn,Te.default.configure({placeholder:({editor:b})=>b.isEmpty?"Start typing...":""}),ve.default,ge.TextStyle,je.default,Ae.default.configure({multicolor:!0}),Ce.default.configure({types:["paragraph","itTitle","itSummary","itSection","itSub"]}),Ne.default,_e,Le.default,$e.default,on,an,cn,ln,dn,un,pn,fn,hn,gn,mn,bn,yn,xn,Sn,kn,qn],content:Ct(t),onUpdate:({editor:b})=>{if(f.current)return;const y=b.getJSON(),j=Yt(y);i.current=j,g.current=!0,h(Qe(y)),e(j)},editorProps:{attributes:{class:"docs-page-content",spellcheck:"true"}}});p.useEffect(()=>{const b=window.setTimeout(()=>{f.current=!1,i.current=t},0);return()=>window.clearTimeout(b)},[]),p.useEffect(()=>{if(T){if(g.current){g.current=!1;return}if(t!==i.current){const b=Ct(t);T.commands.setContent(b),i.current=t}}},[t,T]),p.useEffect(()=>{if(!T)return;const b=y=>{const j=y.detail;j&&T.chain().focus().insertContent(j).run()};return window.addEventListener("it-insert-text",b),()=>window.removeEventListener("it-insert-text",b)},[T]);const w=p.useMemo(()=>mt(t),[t]);p.useEffect(()=>{x.current=w,T?.view.dispatch(T.state.tr)},[w,T]);const E=p.useRef(null),P=p.useCallback(()=>T?T.storage.characterCount?.words?.()??T.getText().split(/\s+/).filter(Boolean).length:0,[T]),W=p.useMemo(()=>{if(!n)return"";try{const b=H.getBuiltinTheme(n);return b?H.generateThemeCSS(b).replace(/:root\{/,".docs-page{"):""}catch{return""}},[n]),G=p.useMemo(()=>{try{const b=H.parseIntentText(t),y=b.blocks.find(F=>F.type==="header")?.content||"",j=b.blocks.find(F=>F.type==="footer")?.content||"",I=b.blocks.find(F=>F.type==="meta"),K=String(I?.properties?.dir||"ltr").toLowerCase();return{header:y,footer:j,dir:K}}catch{return{header:"",footer:"",dir:"ltr"}}},[t]),O=p.useMemo(()=>{try{return Nt(H.parseIntentText(t))}catch{return Nt(null)}},[t]),X=p.useMemo(()=>{if(!O.isSealed)return null;try{return H.verifyDocument(t).intact}catch{return null}},[t,O.isSealed]),$=O.isSealed||s;p.useEffect(()=>{T&&T.isEditable!==!$&&T.setEditable(!$)},[T,$]);const R=p.useMemo(()=>{try{return H.documentStyleCSS(H.parseIntentText(t),Yn,".docs-page .tiptap ")}catch{return""}},[t]);p.useEffect(()=>{let b=document.getElementById("it-doc-style-rules");b||(b=document.createElement("style"),b.id="it-doc-style-rules",document.head.appendChild(b)),b.textContent=R},[R]);const tt=p.useCallback(()=>{if(G.dir==="rtl"){const y=t.split(`
28
- `).map(j=>{if(/^meta:/i.test(j.trim())){const I=j.replace(/\s*\|\s*dir:\s*rtl/gi,"").trim();return I==="meta:"?null:I}return j}).filter(j=>j!==null).join(`
29
- `);e(y)}else{const y=/^meta:.*$/m.exec(t);y?e(t.replace(/^meta:.*$/m,`${y[0]} | dir: rtl`)):/^(title:|summary:)/m.test(t)?e(t.replace(/^((?:title:|summary:).*)$/m,`$1
30
- meta: | dir: rtl`)):e(`meta: | dir: rtl
31
- ${t}`)}},[t,e,G.dir]);p.useEffect(()=>{const b="it-editor-theme-css";let y=document.getElementById(b);y||(y=document.createElement("style"),y.id=b,document.head.appendChild(y)),y.textContent=W},[W]);const D=p.useRef(null),[C,et]=p.useState(1),ct=p.useRef(C),Y=p.useRef(null),lt=p.useCallback(b=>{const y=D.current;if(!y)return;const j=y.getBoundingClientRect();Y.current={cx:y.scrollLeft+(b.clientX-j.left),cy:y.scrollTop+(b.clientY-j.top)}},[]),st=p.useCallback(()=>{const b=D.current;b&&(Y.current={cx:b.scrollLeft+b.clientWidth/2,cy:b.scrollTop+b.clientHeight/2})},[]);return p.useLayoutEffect(()=>{const b=D.current,y=Y.current,j=ct.current;if(!b||!y||j===C)return;const I=C/j;b.getBoundingClientRect();const K=y.cx-b.scrollLeft,F=y.cy-b.scrollTop;b.scrollLeft=y.cx*I-K,b.scrollTop=y.cy*I-F,Y.current=null,ct.current=C},[C]),p.useEffect(()=>{const b=y=>{(y.metaKey||y.ctrlKey)&&(y.key==="="||y.key==="+"?(y.preventDefault(),st(),et(j=>Math.min(2,+(j+.1).toFixed(2)))):y.key==="-"?(y.preventDefault(),st(),et(j=>Math.max(.25,+(j-.1).toFixed(2)))):y.key==="0"&&(y.preventDefault(),st(),et(1)))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[st]),p.useEffect(()=>{const b=D.current;if(!b)return;const y=j=>{if(j.ctrlKey||j.metaKey){j.preventDefault();const I=j.deltaY>0?-.1:.1;lt(j),et(K=>Math.min(2,Math.max(.25,+(K+I).toFixed(2))))}};return b.addEventListener("wheel",y,{passive:!1}),()=>b.removeEventListener("wheel",y)},[lt]),o.jsxs("div",{className:"docs-container",children:[l&&o.jsx(En,{editor:T,isRtl:G.dir==="rtl",onToggleRtl:tt,content:t,theme:n,onThemeChange:r,onTrustAction:d,locked:$}),c&&o.jsx(On,{trust:O,intact:X}),c&&o.jsx(Fn,{source:t}),m.length>0&&o.jsxs("div",{className:"docs-fidelity-warning",role:"status",children:["⚠ Some formatting (",m.join(", "),") can’t be saved to"," ",o.jsx("code",{children:".it"})," and won’t appear when printed through the template — remove it or use the toolbar’s color/size/style controls instead."]}),o.jsx(Bn,{geometry:w,zoom:C,scrollEl:D}),o.jsxs("div",{className:"docs-canvas",ref:D,children:[o.jsx("div",{className:"docs-page-scaler",style:{width:w.width*C},children:o.jsx("div",{className:"docs-page-flow",dir:G.dir,style:{transform:C!==1?`scale(${C})`:void 0,transformOrigin:"top left"},children:o.jsxs("div",{className:"docs-page docs-sheet",ref:E,style:{width:w.width,minHeight:w.autoHeight?w.width:void 0,"--page-mx-l":`${w.marginLeft}px`,"--page-mx-r":`${w.marginRight}px`},children:[o.jsx("div",{className:"docs-sheet-header","data-it-spacer":"",style:{height:w.autoHeight?void 0:w.marginTop},children:o.jsx("div",{className:"docs-pb-header",children:o.jsx("span",{className:"docs-pb-text",children:w.autoHeight?"":Lt(w.header,1,_)})})}),o.jsx(Rt.EditorContent,{editor:T})]})})}),o.jsxs("div",{className:"docs-page-footer",children:[_," ",_===1?"page":"pages"," ·"," ",P()," words",C!==1&&o.jsxs("span",{className:"zoom-indicator",children:[" ","· ",Math.round(C*100),"%"]})]})]})]})}const Jn="corporate";function Vn({value:t,onChange:e,theme:n,onThemeChange:r,readOnly:s=!1,showRibbon:l=!0,showTrustBanner:c=!0,onTrustAction:d}){const[i,g]=p.useState(n??Jn),f=n??i,m=p.useCallback(h=>{g(h),r?.(h)},[r]);return o.jsx(Kn,{value:t,onChange:e,theme:f,onThemeChange:m,readOnly:s,showRibbon:l,showTrustBanner:c,onTrustAction:d})}exports.IntentTextEditor=Vn;exports.buildSampleSkeleton=Gn;exports.builtinThemes=ne;exports.docToSource=Yt;exports.exportDocumentHTML=ee;exports.exportDocumentPDF=te;exports.extractTemplateVariables=Wn;exports.extractTrustState=Nt;exports.getPageGeometry=mt;exports.printHtmlViaIframe=Qt;exports.resolvePageTokens=Lt;exports.sourceToDoc=Ct;
30
+ ${e==="minimal-ink"?ie:""}
31
+ `;return`<!doctype html><html><head><meta charset="utf-8">${c}<style>${m}${u}</style></head><body><div class="docs-page docs-sheet"><div class="tiptap">${o}</div></div></body></html>`}function ae(t,e,n){const s=new Blob([t],{type:n}),o=URL.createObjectURL(s),c=document.createElement("a");c.href=o,c.download=e,c.click(),URL.revokeObjectURL(o)}function ce(t,e,n){let s=Rn(t,n);if(!s){const o=R.parseIntentText(t);s=R.renderPrint(o,{theme:e}),n==="minimal-ink"&&(s=En(s,ie))}return s}function Dt(t,e,n="normal"){try{oe(ce(t,e,n))}catch{}}function le(t,e){try{let n=e;if(!n)try{const s=R.parseIntentText(t),c=s.blocks.find(i=>i.type==="meta")?.properties?.id,a=s.blocks.find(i=>i.type==="title")?.content||"";n=`${String(c||a||"document").trim().replace(/[^\w\-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||"document"}.it`}catch{n="document.it"}ae(t,n,"text/plain;charset=utf-8")}catch{}}function zn(t,e,n="normal"){try{ae(ce(t,e,n),"document.html","text/html")}catch{}}function de(){return R.listBuiltinThemes()}const Vt="dotit.editor.lastSigner",Jt="dotit.editor.lastRole";function Hn({content:t,onChange:e,trust:n,intact:s}){const[o,c]=p.useState(!1),[a,d]=p.useState(!1),[i,m]=p.useState(()=>localStorage.getItem(Vt)||""),[u,h]=p.useState(()=>localStorage.getItem(Jt)||""),[g,b]=p.useState(!1),k=p.useRef(null),w=p.useRef(0),y=p.useCallback(N=>{const M=Date.now();M-w.current<400||(w.current=M,N())},[]);p.useEffect(()=>{if(!o)return;const N=M=>{k.current&&!k.current.contains(M.target)&&(c(!1),d(!1))};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[o]);const x=n.isSealed||R.isSealed(t),z=p.useCallback(()=>{const N=i.trim();if(N){b(!0);try{const M=R.signDocument(t,{signer:N,role:u.trim()||void 0});M.source&&M.source!==t&&e(M.source),localStorage.setItem(Vt,N),u.trim()&&localStorage.setItem(Jt,u.trim())}finally{b(!1),d(!1),c(!1)}}},[t,e,i,u]),D=p.useCallback(()=>{const N=i.trim()||n.signatures[0]?.by||"Document owner";b(!0);try{const M=R.sealDocument(t,{signer:N,role:u.trim()||n.signatures[0]?.role||void 0});M.source&&M.source!==t&&!M.error&&e(M.source)}finally{b(!1),c(!1)}},[t,e,i,u,n.signatures]),F=p.useCallback(()=>{b(!0);try{const N=R.unsealDocument(t);typeof N=="string"&&N!==t&&e(N)}finally{b(!1),c(!1)}},[t,e]),[P,I]=p.useState(null),K=p.useCallback(()=>{try{I(R.verifyDocument(t))}catch{I(null)}},[t]);let _=r.jsx(T.PenTool,{size:15}),H="Draft",G="trust-face--draft";return x?(_=r.jsx(T.FileLock2,{size:15}),H=s===!1?"Sealed · changed!":"Sealed",G=s===!1?"trust-face--broken":"trust-face--sealed"):n.signatures.length>0&&(_=r.jsx(T.ShieldCheck,{size:15}),H=`Signed · ${n.signatures.length}`,G="trust-face--signed"),r.jsxs("div",{className:"trust-control",ref:k,children:[r.jsxs("button",{className:`docs-tb-btn trust-face ${G}`,onClick:()=>{c(N=>!N),d(!1),x&&K()},title:"Document trust — sign, seal, verify",children:[r.jsx("span",{className:"trust-face__icon",children:_}),r.jsx("span",{className:"ribbon-btn-text",children:H}),x&&s===!0&&r.jsx("span",{className:"trust-face__ok",title:"Hash verified",children:"✓"}),r.jsx(T.ChevronDown,{size:12})]}),o&&r.jsxs("div",{className:"trust-popover",children:[r.jsx("div",{className:"trust-popover__state",children:x?r.jsxs(r.Fragment,{children:[r.jsx("strong",{children:"🔒 Sealed — read-only"}),r.jsxs("div",{className:"trust-popover__meta",children:[n.sealedBy&&r.jsxs(r.Fragment,{children:["by ",n.sealedBy]}),n.sealedAt&&r.jsxs(r.Fragment,{children:[" on ",n.sealedAt]})]})]}):n.signatures.length>0?r.jsxs(r.Fragment,{children:[r.jsx("strong",{children:"Signed"}),r.jsx("div",{className:"trust-popover__meta",children:n.signatures.map(N=>N.role?`${N.by} (${N.role})`:N.by).join(" · ")})]}):r.jsxs(r.Fragment,{children:[r.jsx("strong",{children:"Draft"}),r.jsx("div",{className:"trust-popover__meta",children:"Not signed or sealed yet."})]})}),r.jsx("div",{className:"trust-popover__divider"}),x?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"trust-popover__verify",children:[P?P.intact?r.jsx("span",{className:"trust-verify--ok",children:"✓ Verified — content matches the seal"}):r.jsx("span",{className:"trust-verify--bad",children:"⚠ Hash mismatch — content changed after sealing"}):null,P?.hash&&r.jsxs("details",{className:"trust-popover__hash",children:[r.jsx("summary",{children:"Show hash"}),r.jsx("code",{children:P.hash})]})]}),r.jsxs("button",{className:"trust-popover__action",onClick:()=>y(K),disabled:g,children:[r.jsx(T.ShieldCheck,{size:14})," Re-verify"]}),r.jsxs("button",{className:"trust-popover__action trust-popover__action--warn",onClick:()=>y(F),disabled:g,title:"Remove the freeze lock (keeps signatures) and make the document editable again",children:[r.jsx(T.LockOpen,{size:14})," Unseal (make editable)"]})]}):a?r.jsxs("div",{className:"trust-sign-form",children:[r.jsx("input",{className:"trust-sign-input",placeholder:"Your name",value:i,autoFocus:!0,onChange:N=>m(N.target.value),onKeyDown:N=>{N.key==="Enter"&&z(),N.key==="Escape"&&d(!1)}}),r.jsx("input",{className:"trust-sign-input",placeholder:"Role (optional, e.g. CEO)",value:u,onChange:N=>h(N.target.value),onKeyDown:N=>{N.key==="Enter"&&z(),N.key==="Escape"&&d(!1)}}),r.jsxs("div",{className:"trust-sign-actions",children:[r.jsxs("button",{className:"trust-popover__action trust-popover__action--primary",onClick:z,disabled:g||!i.trim(),children:[r.jsx(T.PenTool,{size:14})," Add signature"]}),r.jsx("button",{className:"trust-popover__action",onClick:()=>d(!1),children:"Cancel"})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"trust-popover__action",onClick:()=>d(!0),disabled:g,title:"Add a signature line (does not freeze the document)",children:[r.jsx(T.PenTool,{size:14})," Sign"]}),r.jsxs("button",{className:"trust-popover__action trust-popover__action--primary",onClick:()=>y(D),disabled:g,title:"Freeze the document with a tamper-evident hash. It becomes read-only until unsealed.",children:[r.jsx(T.FileLock2,{size:14})," Seal (freeze)"]})]})]})]})}const Nt=[{label:"Normal text",node:"paragraph"},{label:"Title",node:"itTitle"},{label:"Section",node:"itSection"},{label:"Subsection",node:"itSub"},{label:"Summary",node:"itSummary"},{label:"Quote",node:"itQuote"}],Pn=new Set(["history","revision","track","freeze"]),Dn=new Set(["agent","model","meta","context","history"]),In=["identity","structure","content","data","trust","layout"],Qt=[{label:"Default",value:""},{label:"Inter",value:"Inter"},{label:"Arial",value:"Arial"},{label:"Times New Roman",value:"Times New Roman"},{label:"Georgia",value:"Georgia"},{label:"Courier New",value:"Courier New"},{label:"Verdana",value:"Verdana"},{label:"Trebuchet MS",value:"Trebuchet MS"}],Bn=["1","1.15","1.5","2","2.5","3"],On="12px",Fn=["#000000","#434343","#666666","#999999","#b7b7b7","#cccccc","#d9d9d9","#efefef","#f3f3f3","#ffffff","#980000","#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#4a86e8","#0000ff","#9900ff","#ff00ff","#e6b8af","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#cfe2f3","#d9d2e9","#ead1dc","#dd7e6b","#ea9999","#f9cb9c","#ffe599","#b6d7a8","#a2c4c9","#a4c2f4","#9fc5e8","#b4a7d6","#d5a6bd","#cc4125","#e06666","#f6b26b","#ffd966","#93c47d","#76a5af","#6d9eeb","#6fa8dc","#8e7cc3","#c27ba0"],qn=["#ffffff","#cfe2f3","#d9ead3","#fff2cc","#fce5cd","#f4cccc","#d9d2e9","#ead1dc","#d0e0e3","#e6b8af"];function E({onClick:t,active:e,disabled:n,title:s,children:o}){return r.jsx("button",{className:`docs-tb-btn${e?" active":""}`,onClick:t,disabled:n,title:s,children:o})}function J({label:t,children:e,className:n=""}){return r.jsx("div",{className:`ribbon-group ${n}`.trim(),role:"group","aria-label":t,children:e})}function rt(){return r.jsx("div",{className:"ribbon-sep"})}function Un({editor:t,isRtl:e=!1,onToggleRtl:n,content:s,onChange:o,theme:c,onThemeChange:a,onTrustAction:d,trust:i,sealIntact:m=null,locked:u=!1}){const[h,g]=p.useState(!1),[b,k]=p.useState(!1),[w,y]=p.useState(!1),[x,z]=p.useState(!1),[D,F]=p.useState(!1),[P,I]=p.useState(!1),[K,_]=p.useState(!1),H=p.useRef(null),G=p.useRef(null),N=p.useRef(null),M=p.useRef(null),q=p.useRef(null),tt=p.useRef(null);p.useEffect(()=>{const f=L=>{const C=L.target;H.current&&!H.current.contains(C)&&g(!1),G.current&&!G.current.contains(C)&&k(!1),N.current&&!N.current.contains(C)&&y(!1),M.current&&!M.current.contains(C)&&z(!1),q.current&&!q.current.contains(C)&&F(!1),tt.current&&!tt.current.contains(C)&&I(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[]);const B=()=>{g(!1),k(!1),y(!1),z(!1),F(!1),I(!1)},it=p.useCallback(()=>{if(!t)return"Normal text";for(const f of Nt)if(f.node==="paragraph"&&t.isActive("paragraph")){if(!Nt.some(C=>C.node!=="paragraph"&&t.isActive(C.node)))return f.label}else if(t.isActive(f.node))return f.label;return"Normal text"},[t]),pt=p.useCallback(()=>{if(!t)return"Default";const f=t.getAttributes("textStyle")?.fontFamily;if(!f)return"Default";const L=Qt.find(C=>C.value===f);return L?L.label:"Default"},[t]),[et,S]=p.useState(11),[,v]=p.useState(0),A=p.useMemo(()=>{const f=new Map;for(const C of R.LANGUAGE_REGISTRY){if(C.status!=="stable"||Dn.has(C.canonical)||C.category==="agent")continue;const nt=C.category,bt=f.get(nt)||[];bt.push({label:C.canonical,keyword:C.canonical,category:nt,description:C.description,isReadOnly:Pn.has(C.canonical)}),f.set(nt,bt)}const L=[];for(const C of In){const nt=f.get(C);!nt||nt.length===0||(nt.sort((bt,ye)=>bt.keyword.localeCompare(ye.keyword)),L.push({category:Kt[C]?.label||C,items:nt}))}return L},[]);p.useEffect(()=>{if(!t)return;const f=()=>{const L=t.getAttributes("textStyle");if(L?.fontSize){const C=parseInt(L.fontSize,10);isNaN(C)||S(C)}v(C=>C+1)};return t.on("selectionUpdate",f),t.on("transaction",f),()=>{t.off("selectionUpdate",f),t.off("transaction",f)}},[t]);const Y=p.useCallback(f=>{t&&(f==="paragraph"?t.chain().focus().setParagraph().run():f==="itQuote"?t.chain().focus().setNode("itQuote").run():t.chain().focus().setNode(f).run(),B())},[t]),V=p.useCallback(f=>{if(!t)return;const L=t.chain().focus();f==="divider"?L.setNode("itDivider").run():f==="break"?L.setNode("itBreak").run():f==="code"?L.setNode("itCode",{lang:""}).run():["tip","info","warning","danger","success"].includes(f)?L.setNode("itCallout",{variant:f}).run():L.setNode("itGenericBlock",{keyword:f,properties:""}).run(),B()},[t]),U=p.useCallback(f=>{const L=Math.min(96,Math.max(8,et+f));S(L),t?.chain().focus().setFontSize(`${L}pt`).run()},[t,et]),ht=p.useCallback(f=>{t?.chain().focus().setBlockProp("leading",f).run(),B()},[t]),mt=p.useCallback(f=>{if(!t)return;const L=st(t,f);t.chain().focus().setBlockProp(f,L?null:On).run(),B()},[t]),kt=p.useCallback(()=>{if(!t)return;const f=window.prompt("Space before block (e.g. 12px, 1em — empty for none):",st(t,"space-before")||"");if(f===null)return;const L=window.prompt("Space after block (e.g. 12px, 1em — empty for none):",st(t,"space-after")||"");L!==null&&(t.chain().focus().setBlockProp("space-before",f.trim()||null).setBlockProp("space-after",L.trim()||null).run(),B())},[t]),pe=p.useCallback(()=>{if(!t)return;const f=st(t,"end"),L=window.prompt("Line-end text (shown at the end of the line — empty to remove):",f||"");L!==null&&t.chain().focus().setBlockProp("end",L.trim()||null).run()},[t]),fe=p.useCallback(()=>{t&&(t.chain().focus().insertContent({type:"paragraph",attrs:{end:"End text"},content:[{type:"text",text:"Start text"}]}).run(),B())},[t]),ge=p.useMemo(()=>de(),[]),It=K?"minimal-ink":"normal",he=p.useCallback(()=>Dt(s,c,It),[s,c,It]),me=p.useCallback(()=>le(s),[s]);if(!t)return null;const vt=st(t,"leading"),be=!!st(t,"end");return r.jsxs("div",{className:"docs-toolbar docs-ribbon",children:[r.jsxs(J,{label:"Edit",children:[r.jsx(E,{onClick:()=>t.chain().focus().undo().run(),disabled:u||!t.can().undo(),title:"Undo (⌘Z)",children:r.jsx(T.Undo2,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().redo().run(),disabled:u||!t.can().redo(),title:"Redo (⌘⇧Z)",children:r.jsx(T.Redo2,{size:16})})]}),r.jsx(rt,{}),r.jsxs(J,{label:"File",children:[r.jsxs(E,{onClick:me,title:"Save / Download the .it file",children:[r.jsx(T.Download,{size:16}),r.jsx("span",{className:"ribbon-btn-text",children:"Save"})]}),r.jsxs(E,{onClick:he,title:"Export PDF (⌘P) — WYSIWYG",children:[r.jsx(T.Printer,{size:16}),r.jsx("span",{className:"ribbon-btn-text",children:"PDF"})]}),r.jsx(E,{onClick:()=>_(f=>!f),active:K,title:"Minimal ink mode (plain callouts when printing)",children:r.jsx(T.Droplets,{size:16})}),r.jsx("select",{className:"ribbon-theme-select",value:c,onChange:f=>a(f.target.value),title:"Document theme (used everywhere — canvas, print, export)",children:ge.map(f=>r.jsx("option",{value:f,children:f.charAt(0).toUpperCase()+f.slice(1)},f))})]}),r.jsx(rt,{}),r.jsxs("div",{className:u?"ribbon-locked":"ribbon-editing",children:[r.jsx(J,{label:"Style",children:r.jsxs("div",{className:"docs-tb-dropdown",ref:H,children:[r.jsxs("button",{className:"docs-tb-select docs-tb-paragraph-select",onClick:()=>{B(),g(!h)},children:[r.jsx("span",{className:"docs-tb-select-label",children:it()}),r.jsx(T.ChevronDown,{size:14})]}),h&&r.jsx("div",{className:"docs-tb-dropdown-menu docs-style-menu",children:Nt.map(f=>r.jsx("button",{className:`docs-tb-dropdown-item${it()===f.label?" active":""}`,onClick:()=>Y(f.node),children:r.jsx("span",{className:`docs-style-preview docs-style-${f.node}`,children:f.label})},f.node))})]})}),r.jsx(rt,{}),r.jsxs(J,{label:"Font",children:[r.jsxs("div",{className:"docs-tb-dropdown",ref:N,children:[r.jsxs("button",{className:"docs-tb-select docs-tb-font-select",onClick:()=>{B(),y(!w)},children:[r.jsx("span",{className:"docs-tb-select-label",children:pt()}),r.jsx(T.ChevronDown,{size:14})]}),w&&r.jsx("div",{className:"docs-tb-dropdown-menu docs-font-menu",children:Qt.map(f=>r.jsx("button",{className:`docs-tb-dropdown-item${pt()===f.label?" active":""}`,style:{fontFamily:f.value||"inherit"},onClick:()=>{f.value?t.chain().focus().setFontFamily(f.value).run():t.chain().focus().unsetFontFamily().run(),B()},children:f.label},f.value||"default"))})]}),r.jsx(E,{onClick:()=>U(-1),title:"Decrease font size",children:r.jsx(T.Minus,{size:14})}),r.jsx("span",{className:"docs-tb-fontsize",children:et}),r.jsx(E,{onClick:()=>U(1),title:"Increase font size",children:r.jsx(T.Plus,{size:14})})]}),r.jsx(rt,{}),r.jsxs(J,{label:"Text",children:[r.jsx(E,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (⌘B)",children:r.jsx(T.Bold,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (⌘I)",children:r.jsx(T.Italic,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (⌘U)",children:r.jsx(T.Underline,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().toggleStrike().run(),active:t.isActive("strike"),title:"Strikethrough (⌘⇧X)",children:r.jsx(T.Strikethrough,{size:16})}),r.jsxs("div",{className:"docs-tb-dropdown docs-tb-color-dropdown",ref:M,children:[r.jsxs("button",{className:"docs-tb-btn docs-tb-color-btn",onClick:()=>{B(),z(!x)},title:"Text color",children:[r.jsx(T.Palette,{size:16}),r.jsx("span",{className:"docs-tb-color-indicator",style:{background:t.getAttributes("textStyle")?.color||"#000000"}})]}),x&&r.jsxs("div",{className:"docs-tb-dropdown-menu docs-color-grid-menu",children:[r.jsx("div",{className:"docs-color-grid-label",children:"Text color"}),r.jsx("div",{className:"docs-color-grid",children:Fn.map(f=>r.jsx("button",{className:"docs-color-swatch",style:{background:f},title:f,onClick:()=>{t.chain().focus().setColor(f).run(),B()}},f))}),r.jsxs("button",{className:"docs-tb-dropdown-item",onClick:()=>{t.chain().focus().unsetColor().run(),B()},children:[r.jsx(T.RemoveFormatting,{size:14})," Reset"]})]})]}),r.jsxs("div",{className:"docs-tb-dropdown docs-tb-color-dropdown",ref:q,children:[r.jsxs("button",{className:"docs-tb-btn docs-tb-color-btn",onClick:()=>{B(),F(!D)},title:"Highlight color",children:[r.jsx(T.Highlighter,{size:16}),r.jsx("span",{className:"docs-tb-color-indicator",style:{background:t.getAttributes("highlight")?.color||"transparent"}})]}),D&&r.jsxs("div",{className:"docs-tb-dropdown-menu docs-color-grid-menu",children:[r.jsx("div",{className:"docs-color-grid-label",children:"Highlight color"}),r.jsx("div",{className:"docs-color-grid docs-highlight-grid",children:qn.map(f=>r.jsx("button",{className:"docs-color-swatch",style:{background:f},title:f,onClick:()=>{f==="#ffffff"?t.chain().focus().unsetHighlight().run():t.chain().focus().toggleHighlight({color:f}).run(),B()}},f))})]})]}),r.jsx(E,{onClick:()=>t.chain().focus().toggleCode().run(),active:t.isActive("code"),title:"Inline code",children:r.jsx(T.Code,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().unsetAllMarks().clearNodes().run(),title:"Clear formatting",children:r.jsx(T.RemoveFormatting,{size:16})})]}),r.jsx(rt,{}),r.jsxs(J,{label:"Paragraph",children:[r.jsx(E,{onClick:()=>t.chain().focus().setTextAlign("left").run(),active:t.isActive({textAlign:"left"}),title:"Align left",children:r.jsx(T.AlignLeft,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().setTextAlign("center").run(),active:t.isActive({textAlign:"center"}),title:"Align center",children:r.jsx(T.AlignCenter,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().setTextAlign("right").run(),active:t.isActive({textAlign:"right"}),title:"Align right",children:r.jsx(T.AlignRight,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().setTextAlign("justify").run(),active:t.isActive({textAlign:"justify"}),title:"Justify",children:r.jsx(T.AlignJustify,{size:16})}),r.jsx(E,{onClick:()=>n?.(),active:e,title:e?"Switch to LTR (left-to-right)":"Switch to RTL (right-to-left)",children:r.jsx("span",{style:{fontSize:11,fontWeight:700,letterSpacing:-.5,lineHeight:1},children:e?"LTR":"RTL"})}),r.jsxs("div",{className:"docs-tb-dropdown",ref:tt,children:[r.jsxs("button",{className:`docs-tb-btn${vt?" active":""}`,onClick:()=>{B(),I(!P)},title:"Line & paragraph spacing",children:[r.jsx(T.Rows3,{size:16}),r.jsx(T.ChevronDown,{size:12})]}),P&&r.jsxs("div",{className:"docs-tb-dropdown-menu docs-spacing-menu",children:[r.jsx("div",{className:"docs-insert-category",children:"Line spacing"}),r.jsx("button",{className:`docs-tb-dropdown-item${vt?"":" active"}`,onClick:()=>ht(null),children:"Default"}),Bn.map(f=>r.jsx("button",{className:`docs-tb-dropdown-item${vt===f?" active":""}`,onClick:()=>ht(f),children:f==="1"?"Single":f==="2"?"Double":f},f)),r.jsx("div",{className:"docs-insert-divider"}),r.jsx("div",{className:"docs-insert-category",children:"Paragraph spacing"}),r.jsx("button",{className:"docs-tb-dropdown-item",onClick:()=>mt("space-before"),children:st(t,"space-before")?"Remove space before block":"Add space before block"}),r.jsx("button",{className:"docs-tb-dropdown-item",onClick:()=>mt("space-after"),children:st(t,"space-after")?"Remove space after block":"Add space after block"}),r.jsx("button",{className:"docs-tb-dropdown-item",onClick:kt,children:"Custom spacing…"})]})]}),r.jsx(E,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet list",children:r.jsx(T.List,{size:16})}),r.jsx(E,{onClick:()=>t.chain().focus().toggleOrderedList().run(),active:t.isActive("orderedList"),title:"Numbered list",children:r.jsx(T.ListOrdered,{size:16})})]}),r.jsx(rt,{}),r.jsxs(J,{label:"Insert",children:[r.jsxs("div",{className:"docs-tb-dropdown",ref:G,children:[r.jsxs("button",{className:"docs-tb-select docs-tb-insert-select",onClick:()=>{B(),k(!b)},children:[r.jsx(T.Plus,{size:15}),r.jsx("span",{children:"Insert"}),r.jsx(T.ChevronDown,{size:14})]}),b&&r.jsxs("div",{className:"docs-tb-dropdown-menu docs-insert-menu",children:[r.jsxs("button",{className:"docs-tb-dropdown-item docs-insert-item",onClick:fe,title:"Two-sided row — content at the line start, value at the line end (text: … | end: …)",children:[r.jsx("span",{className:"docs-insert-icon",children:r.jsx(T.AlignHorizontalSpaceBetween,{size:13})}),r.jsx("span",{className:"docs-insert-label",children:"two-sided row"}),r.jsx("span",{className:"docs-insert-kw",children:"end:"})]}),r.jsx("div",{className:"docs-insert-divider"}),A.map((f,L)=>r.jsxs("div",{children:[L>0&&r.jsx("div",{className:"docs-insert-divider"}),r.jsx("div",{className:"docs-insert-category",children:f.category}),f.items.map(C=>r.jsxs("button",{className:"docs-tb-dropdown-item docs-insert-item",onClick:()=>V(C.keyword),disabled:C.isReadOnly,title:C.description,children:[r.jsx("span",{className:"docs-insert-icon",children:Kt[C.category]?.icon||"•"}),r.jsx("span",{className:"docs-insert-label",children:C.label}),r.jsx("span",{className:"docs-insert-kw",children:C.isReadOnly?"locked":`.${C.keyword}`})]},C.keyword))]},f.category))]})]}),r.jsx(E,{onClick:pe,active:be,title:"Two-sided row — set the text shown at the END of this line (end: property)",children:r.jsx(T.AlignHorizontalSpaceBetween,{size:16})})]})]}),i&&o?r.jsxs(r.Fragment,{children:[r.jsx(rt,{}),r.jsx(J,{label:"Trust",children:r.jsx(Hn,{content:s,onChange:o,trust:i,intact:m})})]}):d&&r.jsxs(r.Fragment,{children:[r.jsx(rt,{}),r.jsxs(J,{label:"Trust",children:[r.jsx(E,{onClick:()=>d("seal"),disabled:u,title:"Seal — freeze the document with a tamper-evident hash",children:r.jsx("span",{className:"ribbon-btn-text",children:"Seal"})}),r.jsx(E,{onClick:()=>d("sign"),title:"Sign",children:r.jsx("span",{className:"ribbon-btn-text",children:"Sign"})}),r.jsx(E,{onClick:()=>d("verify"),title:"Verify",children:r.jsx("span",{className:"ribbon-btn-text",children:"Verify"})})]})]})]})}const Wn={in:96,cm:96/2.54},Gn={in:.25,cm:.5};function ue(t,e){const n=Wn[e],s=Gn[e],o=[],c=t/n;for(let a=0;a<=c+1e-6;a+=s){const d=Math.abs(a-Math.round(a))<1e-6;o.push({x:a*n,kind:d?"major":"minor",label:d&&a>0?String(Math.round(a)):void 0})}return o}function Kn({geometry:t,zoom:e,scrollEl:n,onMargins:s,locked:o=!1}){const[c,a]=p.useState(0),[d,i]=p.useState(null),m=p.useRef(null);p.useEffect(()=>{const k=n.current;if(!k)return;const w=()=>a(k.scrollLeft);return w(),k.addEventListener("scroll",w,{passive:!0}),()=>k.removeEventListener("scroll",w)},[n]);const u=p.useMemo(()=>ue(t.width,t.unit),[t.width,t.unit]),h=p.useCallback(k=>w=>{!s||o||(w.preventDefault(),i(k))},[s,o]);p.useEffect(()=>{if(!d||!s)return;const k=y=>{const x=m.current;if(!x)return;const z=x.getBoundingClientRect(),D=(y.clientX-z.left)/e;if(d==="left"){const F=Math.max(0,Math.min(D,t.width/2));s({left:F})}else{const F=Math.max(0,Math.min(t.width-D,t.width/2));s({right:F})}},w=()=>i(null);return window.addEventListener("pointermove",k),window.addEventListener("pointerup",w),()=>{window.removeEventListener("pointermove",k),window.removeEventListener("pointerup",w)}},[d,s,e,t.width]);const g=t.width*e,b=!!s&&!o;return r.jsx("div",{className:`docs-ruler${b?" docs-ruler--draggable":""}`,children:r.jsxs("div",{ref:m,className:"docs-ruler-track",style:{width:g,transform:`translateX(${-c}px)`},children:[r.jsx("div",{className:"docs-ruler-margin",style:{left:0,width:t.marginLeft*e}}),r.jsx("div",{className:"docs-ruler-margin",style:{right:0,width:t.marginRight*e}}),u.map((k,w)=>k.label?r.jsx("span",{className:"docs-ruler-num",style:{left:k.x*e},children:k.label},w):r.jsx("span",{className:`docs-ruler-tick docs-ruler-tick--${k.kind}`,style:{left:k.x*e}},w)),b&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`docs-ruler-stop docs-ruler-stop--h${d==="left"?" dragging":""}`,style:{left:t.marginLeft*e},onPointerDown:h("left"),title:"Drag to set the left margin"}),r.jsx("span",{className:`docs-ruler-stop docs-ruler-stop--h${d==="right"?" dragging":""}`,style:{left:(t.width-t.marginRight)*e},onPointerDown:h("right"),title:"Drag to set the right margin"})]})]})})}function Yn({geometry:t,zoom:e,scrollEl:n,onMargins:s,locked:o=!1,topOffset:c=0}){const[a,d]=p.useState(0),[i,m]=p.useState(null),u=p.useRef(null);p.useEffect(()=>{const y=n.current;if(!y)return;const x=()=>d(y.scrollTop);return x(),y.addEventListener("scroll",x,{passive:!0}),()=>y.removeEventListener("scroll",x)},[n]);const h=t.autoHeight?t.width*1.414:t.height,g=p.useMemo(()=>ue(h,t.unit),[h,t.unit]),b=p.useCallback(y=>x=>{!s||o||t.autoHeight||(x.preventDefault(),m(y))},[s,o,t.autoHeight]);p.useEffect(()=>{if(!i||!s)return;const y=z=>{const D=u.current;if(!D)return;const F=D.getBoundingClientRect(),P=(z.clientY-F.left)/e;if(i==="top"){const I=Math.max(0,Math.min(P,h/2));s({top:I})}else{const I=Math.max(0,Math.min(h-P,h/2));s({bottom:I})}},x=()=>m(null);return window.addEventListener("pointermove",y),window.addEventListener("pointerup",x),()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",x)}},[i,s,e,h]);const k=h*e,w=!!s&&!o&&!t.autoHeight;return r.jsx("div",{className:"docs-ruler-v",children:r.jsxs("div",{ref:u,className:"docs-ruler-v-track",style:{height:k,transform:`translateY(${c-a}px)`},children:[r.jsx("div",{className:"docs-ruler-margin docs-ruler-margin--v",style:{top:0,height:t.marginTop*e}}),r.jsx("div",{className:"docs-ruler-margin docs-ruler-margin--v",style:{bottom:0,height:t.marginBottom*e}}),g.map((y,x)=>y.label?r.jsx("span",{className:"docs-ruler-num docs-ruler-num--v",style:{top:y.x*e},children:y.label},x):r.jsx("span",{className:`docs-ruler-tick docs-ruler-tick--v docs-ruler-tick--${y.kind}`,style:{top:y.x*e}},x)),w&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:`docs-ruler-stop docs-ruler-stop--v${i==="top"?" dragging":""}`,style:{top:t.marginTop*e},onPointerDown:b("top"),title:"Drag to set the top margin"}),r.jsx("span",{className:`docs-ruler-stop docs-ruler-stop--v${i==="bottom"?" dragging":""}`,style:{top:(h-t.marginBottom)*e},onPointerDown:b("bottom"),title:"Drag to set the bottom margin"})]})]})})}function Ct(t,e){return e?`${t} (${e})`:t}function Vn({trust:t,intact:e}){if(t.isSealed){const n=t.sealedBy||"unknown",s=t.signatures[t.signatures.length-1]?.role;return r.jsxs("div",{className:"docs-trust-banner docs-trust-banner--sealed",role:"status",children:[r.jsx("span",{className:"docs-trust-banner__icon",children:"🔒"}),r.jsx("span",{className:"docs-trust-banner__title",children:"Sealed"}),r.jsxs("span",{className:"docs-trust-banner__text",children:["signed by ",Ct(n,s),t.sealedAt?` on ${t.sealedAt}`:""," · read-only"]}),e===!0&&r.jsx("span",{className:"docs-trust-banner__verify docs-trust-banner__verify--ok",children:"hash verified ✓"}),e===!1&&r.jsx("span",{className:"docs-trust-banner__verify docs-trust-banner__verify--bad",children:"⚠ hash mismatch — content changed after sealing"})]})}return t.signatures.length>0?r.jsxs("div",{className:"docs-trust-banner docs-trust-banner--signed",role:"status",children:[r.jsx("span",{className:"docs-trust-banner__icon",children:"✍"}),r.jsx("span",{className:"docs-trust-banner__title",children:"Signed"}),r.jsxs("span",{className:"docs-trust-banner__text",children:["by"," ",t.signatures.map(n=>`${Ct(n.by,n.role)}${n.at?` on ${n.at}`:""}`).join(" · ")]})]}):t.approvals.length>0?r.jsxs("div",{className:"docs-trust-banner docs-trust-banner--approved",role:"status",children:[r.jsx("span",{className:"docs-trust-banner__icon",children:"✓"}),r.jsx("span",{className:"docs-trust-banner__title",children:"Approved"}),r.jsxs("span",{className:"docs-trust-banner__text",children:["by"," ",t.approvals.map(n=>`${Ct(n.by,n.role)}${n.at?` on ${n.at}`:""}`).join(" · ")]})]}):null}function Jn(t){let e;try{e=R.parseIntentText(t)}catch{return[]}const n=[],s=(o,c)=>{const a=c==null?"":String(c).trim();a&&n.push({key:o,value:a})};for(const o of e.blocks)switch(o.type){case"meta":for(const[c,a]of Object.entries(o.properties||{}))s(c,a);break;case"track":s("tracked",o.properties?.id??o.content);break;case"page":{const c=o.properties?.orientation;s("page",[o.content,c].filter(Boolean).join(" · "));break}case"font":s("font",[o.content||o.properties?.family,o.properties?.size].filter(Boolean).join(" · "));break;case"header":s("header",o.content);break;case"footer":s("footer",o.content);break;case"watermark":s("watermark",o.content);break}return n}function Qn({source:t}){const[e,n]=p.useState(!1),s=p.useMemo(()=>Jn(t),[t]);if(s.length===0)return null;const o=s.slice(0,4).map(c=>`${c.key}: ${c.value}`).join(" · ");return r.jsxs("div",{className:`docs-props-bar${e?" open":""}`,children:[r.jsxs("button",{className:"docs-props-toggle",onClick:()=>n(c=>!c),title:e?"Hide document properties":"Show document properties",children:[r.jsx("span",{className:"docs-props-caret",children:e?"▾":"▸"}),"Document properties",!e&&r.jsx("span",{className:"docs-props-summary",children:o})]}),e&&r.jsx("div",{className:"docs-props-chips",children:s.map((c,a)=>r.jsxs("span",{className:"docs-props-chip",children:[r.jsx("b",{children:c.key})," ",c.value]},`${c.key}-${a}`))})]})}function O(t,e,n=""){const s=t?.properties?.[e];return s!=null?String(s):n}function Mt(t){const e={lifecycle:"draft",isTracked:!1,trackBlock:null,approvals:[],signatures:[],isSealed:!1,sealedBy:null,sealedAt:null,sealHash:null,amendments:[]};if(!t)return e;const n=t.blocks,s=n.find(i=>i.type==="track");s&&(e.isTracked=!0,e.lifecycle="tracked",e.trackBlock={id:O(s,"id",s.content??""),by:O(s,"by"),at:O(s,"at")});const o=n.filter(i=>i.type==="approve");for(const i of o)e.approvals.push({by:O(i,"by",i.content??""),role:O(i,"role"),at:O(i,"at"),note:O(i,"note")||void 0});e.approvals.length>0&&(e.lifecycle="approved");const c=n.filter(i=>i.type==="sign");for(const i of c)e.signatures.push({by:O(i,"by",i.content??""),role:O(i,"role"),at:O(i,"at")});e.signatures.length>0&&(e.lifecycle="signed");const a=n.find(i=>i.type==="freeze");if(a){e.isSealed=!0,e.lifecycle="sealed";const i=e.signatures[e.signatures.length-1];e.sealedBy=i?.by||O(a,"by",a.content??""),e.sealedAt=O(a,"at")||i?.at||"",e.sealHash=O(a,"hash")}const d=n.filter(i=>i.type==="amendment");for(const i of d)e.amendments.push({section:O(i,"section",i.content??""),was:O(i,"was"),now:O(i,"now"),by:O(i,"by"),ref:O(i,"ref"),at:O(i,"at")});return e}const Xt=new ut.PluginKey("template-highlight"),St=/\{\{[^}]+\}\}/g;function Zt(t){const e=[];return t.descendants((n,s)=>{if(!n.isText||!n.text)return;St.lastIndex=0;let o;for(;o=St.exec(n.text);)e.push(ct.Decoration.inline(s+o.index,s+o.index+o[0].length,{class:"it-doc-var"}))}),ct.DecorationSet.create(t,e)}const Xn=j.Extension.create({name:"templateHighlight",addProseMirrorPlugins(){return[new ut.Plugin({key:Xt,state:{init:(t,e)=>Zt(e.doc),apply:(t,e)=>t.docChanged?Zt(t.doc):e},props:{decorations(t){return Xt.getState(t)}}})]}});function Zn(t){const e=new Set,n=[];St.lastIndex=0;let s;for(;s=St.exec(t);){const o=s[0].slice(2,-2).trim();/^(page|pages|date|time|year)$/i.test(o)||e.has(o)||(e.add(o),n.push(o))}return n}function ts(t){const e={};for(const n of t){const s=n.split(".");let o=e;for(let c=0;c<s.length;c++){const a=s[c];c===s.length-1?a in o||(o[a]=""):((!(a in o)||typeof o[a]!="object"||o[a]===null)&&(o[a]={}),o=o[a])}}return e}function es(t,e,n){const s=t.coordsAtPos(e),o=s.top+1,c=s.bottom-1,a=n==="start"?-1:1;let d=e,i=e;for(let m=0;m<1e5;m++){const u=d+a;if(u<0||u>t.state.doc.content.size)break;let h;try{h=t.coordsAtPos(u)}catch{break}if(h.bottom<=o||h.top>=c)break;d=u,i=u}return i}const ns=j.Extension.create({name:"lineKeymap",addKeyboardShortcuts(){const t=(e,n)=>{const{view:s}=this.editor,{state:o}=s,{selection:c}=o,a=c.head,d=es(s,a,e);if(d==null||d===a)return!1;const i=o.doc.resolve(d),m=n?c.anchor:d,u=o.tr.setSelection(n?ut.TextSelection.between(o.doc.resolve(m),i):ut.TextSelection.near(i));return s.dispatch(u.scrollIntoView()),!0};return{Home:()=>t("start",!1),End:()=>t("end",!1),"Shift-Home":()=>t("start",!0),"Shift-End":()=>t("end",!0)}}}),ss=28,rs={title:[".it-doc-title"],summary:[".it-doc-summary"],section:[".it-doc-section"],sub:[".it-doc-sub"],text:["p"],quote:[".it-doc-quote"],callout:[".it-doc-callout"],info:[".it-doc-callout"],table:[".it-doc-table th",".it-doc-table td"],"table-header":[".it-doc-table th"],metric:[".it-doc-metric"],contact:['.it-doc-generic[data-keyword="contact"]'],divider:[".it-doc-divider"]};function os({value:t,onChange:e,theme:n,onThemeChange:s,readOnly:o=!1,showRibbon:c=!0,showTrustBanner:a=!0,onTrustAction:d}){const i=p.useRef(""),m=p.useRef(!1),u=p.useRef(!0),[h,g]=p.useState([]),b=p.useRef(xt("")),[k,w]=p.useState(1),y=Bt.useEditor({extensions:[Ge.configure({geometry:()=>b.current,gap:ss,onPages:w}),Le.default.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,paragraph:!1}),$n,Mn,ns,_e.default,ke.TextStyle,$e.default,Me.default.configure({multicolor:!0}),Ee.default.configure({types:["paragraph","itTitle","itSummary","itSection","itSub"]}),Re.default,De,ze.default,He.default,fn,gn,hn,mn,bn,yn,xn,Sn,vn,kn,wn,jn,Tn,Nn,Cn,An,Xn],content:$t(t),onUpdate:({editor:S})=>{if(u.current)return;const v=S.getJSON(),A=ee(v);i.current=A,m.current=!0,g(rn(v)),e(A)},editorProps:{attributes:{class:"docs-page-content",spellcheck:"true"}}});p.useEffect(()=>{const S=window.setTimeout(()=>{u.current=!1,i.current=t},0);return()=>window.clearTimeout(S)},[]),p.useEffect(()=>{if(y){if(m.current){m.current=!1;return}if(t!==i.current){const S=$t(t);y.commands.setContent(S),i.current=t}}},[t,y]),p.useEffect(()=>{if(!y)return;const S=v=>{const A=v.detail;A&&y.chain().focus().insertContent(A).run()};return window.addEventListener("it-insert-text",S),()=>window.removeEventListener("it-insert-text",S)},[y]);const x=p.useMemo(()=>xt(t),[t]);p.useEffect(()=>{b.current=x,y?.view.dispatch(y.state.tr)},[x,y]);const z=p.useRef(null),D=p.useCallback(()=>y?y.storage.characterCount?.words?.()??y.getText().split(/\s+/).filter(Boolean).length:0,[y]),F=p.useMemo(()=>{if(!n)return"";try{const S=R.getBuiltinTheme(n);return S?R.generateThemeCSS(S).replace(/:root\{/,".docs-page{"):""}catch{return""}},[n]),P=p.useMemo(()=>{try{const S=R.parseIntentText(t),v=S.blocks.find(U=>U.type==="header")?.content||"",A=S.blocks.find(U=>U.type==="footer")?.content||"",Y=S.blocks.find(U=>U.type==="meta"),V=String(Y?.properties?.dir||"ltr").toLowerCase();return{header:v,footer:A,dir:V}}catch{return{header:"",footer:"",dir:"ltr"}}},[t]),I=p.useMemo(()=>{try{return Mt(R.parseIntentText(t))}catch{return Mt(null)}},[t]),K=p.useMemo(()=>{if(!I.isSealed)return null;try{return R.verifyDocument(t).intact}catch{return null}},[t,I.isSealed]),_=I.isSealed||o;p.useEffect(()=>{y&&y.isEditable!==!_&&y.setEditable(!_)},[y,_]),p.useEffect(()=>{if(!y)return;y.view.dom.setAttribute("dir",P.dir==="rtl"?"rtl":"ltr")},[y,P.dir]);const H=p.useMemo(()=>{try{return R.documentStyleCSS(R.parseIntentText(t),rs,".docs-page .tiptap ")}catch{return""}},[t]);p.useEffect(()=>{let S=document.getElementById("it-doc-style-rules");S||(S=document.createElement("style"),S.id="it-doc-style-rules",document.head.appendChild(S)),S.textContent=H},[H]);const G=p.useCallback(()=>{const S=P.dir==="rtl";e(R.upsertMetaProperty(t,"dir",S?null:"rtl"))},[t,e,P.dir]),N=p.useCallback(S=>{const v=b.current,A=kt=>Math.max(0,Math.round(kt/Q*10)/10),Y=A(S.top??v.marginTop),V=A(S.right??v.marginRight),U=A(S.bottom??v.marginBottom),ht=A(S.left??v.marginLeft),mt=`${Y}mm ${V}mm ${U}mm ${ht}mm`;e(Ue(t,mt))},[t,e]);p.useEffect(()=>{const S="it-editor-theme-css";let v=document.getElementById(S);v||(v=document.createElement("style"),v.id=S,document.head.appendChild(v)),v.textContent=F},[F]);const M=p.useRef(null),[q,tt]=p.useState(1),B=p.useRef(q),it=p.useRef(null),pt=p.useCallback(S=>{const v=M.current;if(!v)return;const A=v.getBoundingClientRect();it.current={cx:v.scrollLeft+(S.clientX-A.left),cy:v.scrollTop+(S.clientY-A.top)}},[]),et=p.useCallback(()=>{const S=M.current;S&&(it.current={cx:S.scrollLeft+S.clientWidth/2,cy:S.scrollTop+S.clientHeight/2})},[]);return p.useLayoutEffect(()=>{const S=M.current,v=it.current,A=B.current;if(!S||!v||A===q)return;const Y=q/A;S.getBoundingClientRect();const V=v.cx-S.scrollLeft,U=v.cy-S.scrollTop;S.scrollLeft=v.cx*Y-V,S.scrollTop=v.cy*Y-U,it.current=null,B.current=q},[q]),p.useEffect(()=>{const S=v=>{if(v.metaKey||v.ctrlKey){if(v.key==="p"||v.key==="P"){v.preventDefault(),Dt(t,n);return}v.key==="="||v.key==="+"?(v.preventDefault(),et(),tt(A=>Math.min(2,+(A+.1).toFixed(2)))):v.key==="-"?(v.preventDefault(),et(),tt(A=>Math.max(.25,+(A-.1).toFixed(2)))):v.key==="0"&&(v.preventDefault(),et(),tt(1))}};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[et,t,n]),p.useEffect(()=>{const S=M.current;if(!S)return;const v=A=>{if(A.ctrlKey||A.metaKey){A.preventDefault();const Y=A.deltaY>0?-.1:.1;pt(A),tt(V=>Math.min(2,Math.max(.25,+(V+Y).toFixed(2))))}};return S.addEventListener("wheel",v,{passive:!1}),()=>S.removeEventListener("wheel",v)},[pt]),r.jsxs("div",{className:"docs-container",children:[c&&r.jsx(Un,{editor:y,isRtl:P.dir==="rtl",onToggleRtl:G,content:t,onChange:e,theme:n,onThemeChange:s,onTrustAction:d,trust:I,sealIntact:K,locked:_}),a&&r.jsx(Vn,{trust:I,intact:K}),a&&r.jsx(Qn,{source:t}),h.length>0&&r.jsxs("div",{className:"docs-fidelity-warning",role:"status",children:["⚠ Some formatting (",h.join(", "),") can’t be saved to"," ",r.jsx("code",{children:".it"})," and won’t appear when printed through the template — remove it or use the toolbar’s color/size/style controls instead."]}),r.jsx(Kn,{geometry:x,zoom:q,scrollEl:M,onMargins:N,locked:_}),r.jsxs("div",{className:"docs-canvas-row",children:[r.jsx(Yn,{geometry:x,zoom:q,scrollEl:M,onMargins:N,locked:_}),r.jsxs("div",{className:"docs-canvas",ref:M,children:[r.jsx("div",{className:"docs-page-scaler",style:{width:x.width*q},children:r.jsx("div",{className:"docs-page-flow",dir:P.dir,style:{transform:q!==1?`scale(${q})`:void 0,transformOrigin:"top left"},children:r.jsxs("div",{className:"docs-page docs-sheet",ref:z,style:{width:x.width,minHeight:x.autoHeight?x.width:void 0,"--page-mx-l":`${x.marginLeft}px`,"--page-mx-r":`${x.marginRight}px`},children:[r.jsx("div",{className:"docs-sheet-header","data-it-spacer":"",style:{height:x.autoHeight?void 0:x.marginTop},children:r.jsx("div",{className:"docs-pb-header",children:r.jsx("span",{className:"docs-pb-text",children:x.autoHeight?"":Et(x.header,1,k)})})}),r.jsx(Bt.EditorContent,{editor:y})]})})}),r.jsxs("div",{className:"docs-page-footer",children:[k," ",k===1?"page":"pages"," ·"," ",D()," words",q!==1&&r.jsxs("span",{className:"zoom-indicator",children:[" ","· ",Math.round(q*100),"%"]})]})]})]})]})}const is="corporate";function as({value:t,onChange:e,theme:n,onThemeChange:s,readOnly:o=!1,showRibbon:c=!0,showTrustBanner:a=!0,onTrustAction:d}){const[i,m]=p.useState(n??is),u=n??i,h=p.useCallback(g=>{m(g),s?.(g)},[s]);return r.jsx(os,{value:t,onChange:e,theme:u,onThemeChange:h,readOnly:o,showRibbon:c,showTrustBanner:a,onTrustAction:d})}exports.IntentTextEditor=as;exports.buildSampleSkeleton=ts;exports.builtinThemes=de;exports.docToSource=ee;exports.downloadItFile=le;exports.exportDocumentHTML=zn;exports.exportDocumentPDF=Dt;exports.extractTemplateVariables=Zn;exports.extractTrustState=Mt;exports.getPageGeometry=xt;exports.printHtmlViaIframe=oe;exports.resolvePageTokens=Et;exports.sourceToDoc=$t;
32
32
  //# sourceMappingURL=index.cjs.map