@dotit/editor 1.0.0 → 1.1.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.
- package/dist/Ruler.d.ts +9 -0
- package/dist/index.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1070 -1035
- package/dist/index.mjs.map +1 -1
- package/dist/page-geometry.d.ts +2 -0
- package/dist/style.css +177 -137
- package/package.json +2 -2
package/dist/Ruler.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PageGeometry } from "./page-geometry";
|
|
2
|
+
interface RulerProps {
|
|
3
|
+
geometry: PageGeometry;
|
|
4
|
+
zoom: number;
|
|
5
|
+
/** The scrollable canvas element — the ruler mirrors its horizontal scroll. */
|
|
6
|
+
scrollEl: React.RefObject<HTMLDivElement | null>;
|
|
7
|
+
}
|
|
8
|
+
export declare function DocsRuler({ geometry, zoom, scrollEl }: RulerProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
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"),
|
|
2
|
-
<span class="docs-pb-text">${
|
|
3
|
-
</div>`}function
|
|
4
|
-
<div class="docs-pb-fill" style="height:${
|
|
5
|
-
<div class="docs-pb-margin docs-pb-margin-bottom" style="height:${
|
|
6
|
-
${St("footer",
|
|
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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}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>
|
|
5
|
+
<div class="docs-pb-margin docs-pb-margin-bottom" style="height:${i.marginBottom}px">
|
|
6
|
+
${St("footer",i.footer,f,m)}
|
|
7
7
|
</div>
|
|
8
8
|
<div class="docs-pb-gap" style="height:${t.gap}px"></div>
|
|
9
|
-
<div class="docs-pb-margin docs-pb-margin-top" style="height:${
|
|
10
|
-
${St("header",
|
|
11
|
-
</div>`,
|
|
12
|
-
<div class="docs-pb-fill" style="height:${
|
|
13
|
-
<div class="docs-pb-margin docs-pb-margin-bottom" style="height:${
|
|
14
|
-
${St("footer",
|
|
15
|
-
</div>`,
|
|
16
|
-
`);let s=0;const l=[];for(let
|
|
17
|
-
`)}function
|
|
18
|
-
${
|
|
9
|
+
<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>
|
|
13
|
+
<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
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 i(t,e){return{property:t,css:e}}const en=[i("align","textAlign"),i("color","color"),i("size","fontSize"),i("weight","fontWeight"),{property:"style",css:"fontStyle"},i("bgcolor","backgroundColor"),i("padding","padding"),i("indent","paddingLeft"),i("opacity","opacity")],ut=[i("bgcolor","backgroundColor"),i("color","color"),i("border","borderLeft")],L=[i("color","borderColor"),i("bgcolor","backgroundColor")],nn={title:[i("align","textAlign"),i("color","color"),i("size","fontSize"),i("weight","fontWeight"),i("font","fontFamily")],summary:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"}],section:[i("align","textAlign"),i("color","color"),i("size","fontSize"),i("weight","fontWeight"),i("border","borderBottom"),i("spacing","marginTop")],sub:[i("align","textAlign"),i("color","color"),i("size","fontSize"),i("weight","fontWeight")],divider:[{property:"style",css:"borderStyle"},i("color","borderColor"),i("width","borderTopWidth"),i("spacing","margin")],text:[...en],tip:[...ut],info:[...ut],warning:[...ut],danger:[...ut],success:[...ut],quote:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"},i("border","borderLeft"),i("padding","paddingLeft"),i("bgcolor","backgroundColor")],cite:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"}],def:[i("color","color"),i("bgcolor","backgroundColor"),i("border","borderLeft"),i("padding","paddingLeft")],caption:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"}],footnote:[i("color","color"),i("size","fontSize")],byline:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"},i("weight","fontWeight")],epigraph:[i("align","textAlign"),i("color","color"),i("size","fontSize"),{property:"style",css:"fontStyle"},i("padding","padding")],dedication:[i("align","textAlign"),i("color","color"),{property:"style",css:"fontStyle"},i("padding","padding")],image:[i("width","width"),i("height","height"),i("radius","borderRadius"),i("border","border"),i("opacity","opacity"),i("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],figure:[i("width","width"),i("align","textAlign"),i("border","border"),i("padding","padding"),i("bgcolor","backgroundColor"),{property:"shadow",css:"boxShadow",transform:()=>"0 4px 12px rgba(0,0,0,0.15)"}],link:[i("color","color"),i("weight","fontWeight")],ref:[i("color","color"),{property:"style",css:"fontStyle"}],embed:[i("width","width"),i("height","height"),i("border","border"),i("radius","borderRadius")],metric:[i("color","color"),i("size","fontSize"),i("align","textAlign"),i("bgcolor","backgroundColor"),i("border","border"),i("padding","padding")],columns:[i("border","border"),i("bgcolor","backgroundColor"),i("padding","padding"),i("size","fontSize"),i("align","textAlign")],row:[i("border","border"),i("bgcolor","backgroundColor"),i("padding","padding"),i("size","fontSize"),i("align","textAlign")],input:[i("color","color"),i("bgcolor","backgroundColor"),i("border","borderLeft"),i("size","fontSize")],output:[i("color","color"),i("bgcolor","backgroundColor"),i("border","borderLeft"),i("size","fontSize")],code:[i("size","fontSize"),i("bgcolor","backgroundColor"),i("color","color"),i("padding","padding"),i("radius","borderRadius"),i("border","border")],contact:[i("color","color"),i("bgcolor","backgroundColor"),i("border","border"),i("padding","padding"),i("size","fontSize")],deadline:[i("color","color"),i("bgcolor","backgroundColor"),i("weight","fontWeight"),i("size","fontSize")],step:[...L],decision:[...L],gate:[...L],trigger:[...L],loop:[...L],parallel:[...L],call:[...L],wait:[...L],checkpoint:[...L],error:[...L],result:[...L],audit:[...L],signal:[...L],handoff:[...L],retry:[...L],progress:[...L],tool:[...L],prompt:[...L],memory:[...L],policy:[...L],context:[...L],track:[...L],approve:[...L],sign:[...L],freeze:[...L],revision:[...L],amendment:[...L],history:[i("color","borderColor")],assert:[i("color","borderColor"),i("bgcolor","backgroundColor"),i("border","borderLeft")],secret:[i("color","color"),i("bgcolor","backgroundColor"),i("blur","filter")],watermark:[i("color","color"),i("size","fontSize"),i("opacity","opacity")],signline:[i("color","color"),i("width","width")]};function rn(t,e){const n=nn[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 G(t,e){const n=rn(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 Mt(t){return t.end?{"data-it-end":t.end}:{}}const sn=x.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=Q(e.attrs.props),r=x.mergeAttributes(t,{"data-it-type":"title",class:"it-doc-title",style:G("title",n),...Mt(n)});return n.end?["h1",r,["span",{class:"it-split-main"},0]]:["h1",r,0]}}),on=x.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=Q(e.attrs.props);return["p",x.mergeAttributes(t,{"data-it-type":"summary",class:"it-doc-summary",style:G("summary",n)}),0]}}),an=x.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=Q(e.attrs.props),r=x.mergeAttributes(t,{"data-it-type":"section",class:"it-doc-section",style:G("section",n),...Mt(n)});return n.end?["h2",r,["span",{class:"it-split-main"},0]]:["h2",r,0]}}),cn=x.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=Q(e.attrs.props),r=x.mergeAttributes(t,{"data-it-type":"sub",class:"it-doc-sub",style:G("sub",n),...Mt(n)});return n.end?["h3",r,["span",{class:"it-split-main"},0]]:["h3",r,0]}}),ln=x.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=Q(e.attrs.props),s={tip:"tip",info:"info",warning:"warning",danger:"danger",success:"success"};return["div",x.mergeAttributes(t,{"data-it-type":"callout","data-variant":n,class:`it-doc-callout it-doc-callout-${n}`,style:G(n,r)}),["span",{class:`it-doc-callout-icon it-doc-callout-icon-${s[n]||"tip"}`,contenteditable:"false"},""],["span",{class:"it-doc-callout-text"},0]]}}),dn=x.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=Q(e.attrs.props);return["blockquote",x.mergeAttributes(t,{"data-it-type":"quote",class:"it-doc-quote",style:G("quote",n)}),0]}}),un=x.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=Q(e.attrs.props);return["pre",x.mergeAttributes(t,{"data-it-type":"code",class:"it-doc-code","data-lang":e.attrs.lang||"",style:G("code",n)}),["code",0]]}}),pn=x.Node.create({name:"itDivider",group:"block",atom:!0,parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",x.mergeAttributes(t,{class:"it-doc-divider"})]}}),fn=x.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",x.mergeAttributes(t,{"data-it-meta":"",class:"it-doc-meta"}),`⚙ ${n}`]}}),gn=x.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",x.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(a=>["td",Ot(a),String(a)])])]]}});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(p=>p.trim()),l=s.shift()||"",a={};for(const p of s){const c=p.indexOf(":");c>0&&(a[p.slice(0,c).trim().toLowerCase()]=p.slice(c+1).trim())}return{keyword:n,content:l,props:a}}const mn=x.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||"",a=s.at||s.date||s.time||"",p=[];if(n==="seal"){const c=r||s.hash||"",m=s.algo||"sha-256";p.push(["span",{class:"it-doc-trust__icon"},"🔒"],["span",{class:"it-doc-trust__label"},"Sealed"],["span",{class:"it-doc-trust__meta"},m],...c?[["code",{class:"it-doc-trust__hash"},c.slice(0,16)+"…"]]:[])}else if(n==="approve")p.push(["span",{class:"it-doc-trust__icon"},"✓"],["span",{class:"it-doc-trust__label"},"Approved"],["span",{class:"it-doc-trust__name"},r],...l?[["span",{class:"it-doc-trust__role"},l]]:[],...a?[["span",{class:"it-doc-trust__date"},a]]:[]);else if(n==="freeze")p.push(["span",{class:"it-doc-trust__icon"},"❄"],["span",{class:"it-doc-trust__label"},"Frozen"],...r?[["span",{class:"it-doc-trust__name"},r]]:[],...a?[["span",{class:"it-doc-trust__date"},a]]:[]);else if(n==="amend"||n==="amendment")p.push(["span",{class:"it-doc-trust__icon"},"✎"],["span",{class:"it-doc-trust__label"},"Amendment"],["span",{class:"it-doc-trust__name"},r],...a?[["span",{class:"it-doc-trust__date"},a]]:[]);else return["div",x.mergeAttributes(t,{"data-it-trust":"","data-trust":n,class:"it-doc-trust it-doc-sign"}),["div",{class:"it-doc-sign__script"},r||" "],["div",{class:"it-doc-sign__rule"}],["div",{class:"it-doc-sign__row"},["span",{class:"it-doc-sign__name"},r],...l?[["span",{class:"it-doc-sign__role"},l]]:[],...a?[["span",{class:"it-doc-sign__date"},a]]:[]]];return["div",x.mergeAttributes(t,{"data-it-trust":"","data-trust":n,class:`it-doc-trust it-doc-trust--${n}`}),...p]}}),hn=x.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),a=/\{\{[^}]+\}\}/.test(s);return["div",x.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${a?" it-doc-var":""}`},s]]}}),bn=x.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,a])=>`${l}: ${a}`).join(" · ");return["div",x.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]]}}),yn=x.Node.create({name:"itBreak",group:"block",atom:!0,parseHTML(){return[{tag:'div[data-it-type="break"]'}]},renderHTML({HTMLAttributes:t}){return["div",x.mergeAttributes(t,{"data-it-type":"break",class:"it-doc-break"})]}}),xn=x.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=Q(e.attrs.props),s=String(r.to||r.url||r.href||r.file||"").trim();return(n==="link"||n==="ref")&&s?["p",x.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:G(n,r)}),["a",{class:"it-doc-inline-link",href:s,target:"_blank",rel:"noopener noreferrer"},0]]:["p",x.mergeAttributes(t,{"data-it-type":"generic","data-keyword":n,class:`it-doc-generic it-doc-kw-${n}`,style:G(n,r)}),["span",{class:"it-doc-generic-content"},0]]}}),Sn=x.Node.create({name:"itComment",group:"block",content:"inline*",defining:!0,parseHTML(){return[{tag:'p[data-it-type="comment"]'}]},renderHTML({HTMLAttributes:t}){return["p",x.mergeAttributes(t,{"data-it-type":"comment",class:"it-doc-comment"}),0]}});function Q(t){try{return typeof t=="string"?JSON.parse(t):t||{}}catch{return{}}}const Kt={leading:"leading","space-before":"spaceBefore","space-after":"spaceAfter",end:"end"},kn=new Set(["itTitle","itSummary","itSection","itSub","itQuote","itCallout","itGenericBlock"]),wn=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"?wn.has(t):kn.has(t)}const vn=$e.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",x.mergeAttributes(e),["span",{class:"it-split-main"},0]]:["p",x.mergeAttributes(e),0]}}),Tn=x.Extension.create({name:"blockProps",addCommands(){return{setBlockProp:(t,e)=>({state:n,tr:r,dispatch:s})=>{const{from:l,to:a}=n.selection;let p=!1;return n.doc.nodesBetween(l,a,(c,m)=>{const f=c.type.name;if(f==="bulletList"||f==="orderedList"||!c.isBlock||c.isAtom)return!1;if(!Vt(f,t))return!0;if(f==="paragraph")r.setNodeMarkup(m,void 0,{...c.attrs,[Kt[t]]:e});else{const b=Jt(c.attrs.props);e==null||e===""?delete b[t]:b[t]=e,r.setNodeMarkup(m,void 0,{...c.attrs,props:JSON.stringify(b)})}return p=!0,!1}),p&&s&&s(r),p}}}});function J(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,a=>{if(l!==null)return!1;const p=a.type.name;if(!Vt(p,e))return!0;if(p==="paragraph"){const c=a.attrs[Kt[e]];l=c!=null?String(c):""}else l=Jt(a.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 jn(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=R.cssContentValue;function An(t,e){const n=document.querySelector(".docs-page .tiptap");if(!n)return null;const r=n.cloneNode(!0);r.querySelectorAll("[data-it-spacer]").forEach(b=>b.remove());const s=r.innerHTML,l=Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).map(b=>b.outerHTML).join(`
|
|
21
|
-
`),
|
|
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=`
|
|
22
22
|
html,body{margin:0;background:#fff;}
|
|
23
23
|
.docs-page,.docs-page.docs-sheet{box-shadow:none;border-radius:0;margin:0;width:auto;min-height:0;padding:0;background:#fff;}
|
|
24
24
|
.docs-page .tiptap{padding:0;}
|
|
25
25
|
[data-it-spacer]{display:none!important;}
|
|
26
26
|
${e==="minimal-ink"?Zt:""}
|
|
27
|
-
`;return`<!doctype html><html><head><meta charset="utf-8">${l}<style>${m}${f}</style></head><body><div class="docs-page docs-sheet"><div class="tiptap">${s}</div></div></body></html>`}function Cn(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=An(t,n);if(!r){const s=R.parseIntentText(t);r=R.renderPrint(s,{theme:e}),n==="minimal-ink"&&(r=jn(r,Zt))}return r}function te(t,e,n="normal"){try{Qt(Xt(t,e,n))}catch{}}function ee(t,e,n="normal"){try{Cn(Xt(t,e,n),"document.html","text/html")}catch{}}function ne(){return R.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"}],Nn=new Set(["history","revision","track","freeze"]),Ln=new Set(["agent","model","meta","context","history"]),_n=["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"],Mn="12px",zn=["#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 _({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.jsxs("div",{className:`ribbon-group ${n}`.trim(),children:[o.jsx("div",{className:"ribbon-group-row",children:e}),o.jsx("div",{className:"ribbon-group-label",children:t})]})}function pt(){return o.jsx("div",{className:"ribbon-sep"})}function Rn({editor:t,isRtl:e=!1,onToggleRtl:n,content:r,theme:s,onThemeChange:l,onTrustAction:a,locked:p=!1}){const[c,m]=u.useState(!1),[f,b]=u.useState(!1),[g,S]=u.useState(!1),[j,M]=u.useState(!1),[k,T]=u.useState(!1),[Z,E]=u.useState(!1),[F,q]=u.useState(!1),I=u.useRef(null),X=u.useRef(null),$=u.useRef(null),H=u.useRef(null),tt=u.useRef(null),W=u.useRef(null);u.useEffect(()=>{const d=C=>{const w=C.target;I.current&&!I.current.contains(w)&&m(!1),X.current&&!X.current.contains(w)&&b(!1),$.current&&!$.current.contains(w)&&S(!1),H.current&&!H.current.contains(w)&&M(!1),tt.current&&!tt.current.contains(w)&&T(!1),W.current&&!W.current.contains(w)&&E(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[]);const N=()=>{m(!1),b(!1),S(!1),M(!1),T(!1),E(!1)},et=u.useCallback(()=>{if(!t)return"Normal text";for(const d of wt)if(d.node==="paragraph"&&t.isActive("paragraph")){if(!wt.some(w=>w.node!=="paragraph"&&t.isActive(w.node)))return d.label}else if(t.isActive(d.node))return d.label;return"Normal text"},[t]),ct=u.useCallback(()=>{if(!t)return"Default";const d=t.getAttributes("textStyle")?.fontFamily;if(!d)return"Default";const C=qt.find(w=>w.value===d);return C?C.label:"Default"},[t]),[U,lt]=u.useState(11),[,st]=u.useState(0),h=u.useMemo(()=>{const d=new Map;for(const w of R.LANGUAGE_REGISTRY){if(w.status!=="stable"||Ln.has(w.canonical)||w.category==="agent")continue;const K=w.category,gt=d.get(K)||[];gt.push({label:w.canonical,keyword:w.canonical,category:K,description:w.description,isReadOnly:Nn.has(w.canonical)}),d.set(K,gt)}const C=[];for(const w of _n){const K=d.get(w);!K||K.length===0||(K.sort((gt,de)=>gt.keyword.localeCompare(de.keyword)),C.push({category:Dt[w]?.label||w,items:K}))}return C},[]);u.useEffect(()=>{if(!t)return;const d=()=>{const C=t.getAttributes("textStyle");if(C?.fontSize){const w=parseInt(C.fontSize,10);isNaN(w)||lt(w)}st(w=>w+1)};return t.on("selectionUpdate",d),t.on("transaction",d),()=>{t.off("selectionUpdate",d),t.off("transaction",d)}},[t]);const y=u.useCallback(d=>{t&&(d==="paragraph"?t.chain().focus().setParagraph().run():d==="itQuote"?t.chain().focus().setNode("itQuote").run():t.chain().focus().setNode(d).run(),N())},[t]),A=u.useCallback(d=>{if(!t)return;const C=t.chain().focus();d==="divider"?C.setNode("itDivider").run():d==="break"?C.setNode("itBreak").run():d==="code"?C.setNode("itCode",{lang:""}).run():["tip","info","warning","danger","success"].includes(d)?C.setNode("itCallout",{variant:d}).run():C.setNode("itGenericBlock",{keyword:d,properties:""}).run(),N()},[t]),P=u.useCallback(d=>{const C=Math.min(96,Math.max(8,U+d));lt(C),t?.chain().focus().setFontSize(`${C}pt`).run()},[t,U]),Y=u.useCallback(d=>{t?.chain().focus().setBlockProp("leading",d).run(),N()},[t]),O=u.useCallback(d=>{if(!t)return;const C=J(t,d);t.chain().focus().setBlockProp(d,C?null:Mn).run(),N()},[t]),re=u.useCallback(()=>{if(!t)return;const d=window.prompt("Space before block (e.g. 12px, 1em — empty for none):",J(t,"space-before")||"");if(d===null)return;const C=window.prompt("Space after block (e.g. 12px, 1em — empty for none):",J(t,"space-after")||"");C!==null&&(t.chain().focus().setBlockProp("space-before",d.trim()||null).setBlockProp("space-after",C.trim()||null).run(),N())},[t]),se=u.useCallback(()=>{if(!t)return;const d=J(t,"end"),C=window.prompt("Line-end text (shown at the end of the line — empty to remove):",d||"");C!==null&&t.chain().focus().setBlockProp("end",C.trim()||null).run()},[t]),oe=u.useCallback(()=>{t&&(t.chain().focus().insertContent({type:"paragraph",attrs:{end:"End text"},content:[{type:"text",text:"Start text"}]}).run(),N())},[t]),ie=u.useMemo(()=>ne(),[]),ft=F?"minimal-ink":"normal",ae=u.useCallback(()=>te(r,s,ft),[r,s,ft]),ce=u.useCallback(()=>ee(r,s,ft),[r,s,ft]);if(!t)return null;const xt=J(t,"leading"),le=!!J(t,"end");return o.jsxs("div",{className:"docs-toolbar docs-ribbon",children:[o.jsxs(at,{label:"Edit",children:[o.jsx(_,{onClick:()=>t.chain().focus().undo().run(),disabled:p||!t.can().undo(),title:"Undo (⌘Z)",children:o.jsx(v.Undo2,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().redo().run(),disabled:p||!t.can().redo(),title:"Redo (⌘⇧Z)",children:o.jsx(v.Redo2,{size:16})})]}),o.jsx(pt,{}),o.jsxs(at,{label:"File",children:[o.jsxs(_,{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(_,{onClick:ce,title:"Export HTML",children:[o.jsx(v.FileCode2,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"HTML"})]}),o.jsx(_,{onClick:()=>q(d=>!d),active:F,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:d=>l(d.target.value),title:"Document theme (used by print/export)",children:ie.map(d=>o.jsx("option",{value:d,children:d.charAt(0).toUpperCase()+d.slice(1)},d))})]}),o.jsx(pt,{}),o.jsxs("div",{className:p?"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:()=>{N(),S(!g)},children:[o.jsx("span",{className:"docs-tb-select-label",children:ct()}),o.jsx(v.ChevronDown,{size:14})]}),g&&o.jsx("div",{className:"docs-tb-dropdown-menu docs-font-menu",children:qt.map(d=>o.jsx("button",{className:`docs-tb-dropdown-item${ct()===d.label?" active":""}`,style:{fontFamily:d.value||"inherit"},onClick:()=>{d.value?t.chain().focus().setFontFamily(d.value).run():t.chain().focus().unsetFontFamily().run(),N()},children:d.label},d.value||"default"))})]}),o.jsx(_,{onClick:()=>P(-1),title:"Decrease font size",children:o.jsx(v.Minus,{size:14})}),o.jsx("span",{className:"docs-tb-fontsize",children:U}),o.jsx(_,{onClick:()=>P(1),title:"Increase font size",children:o.jsx(v.Plus,{size:14})}),o.jsx(_,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (⌘B)",children:o.jsx(v.Bold,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (⌘I)",children:o.jsx(v.Italic,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (⌘U)",children:o.jsx(v.Underline,{size:16})}),o.jsx(_,{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:H,children:[o.jsxs("button",{className:"docs-tb-btn docs-tb-color-btn",onClick:()=>{N(),M(!j)},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"}})]}),j&&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:zn.map(d=>o.jsx("button",{className:"docs-color-swatch",style:{background:d},title:d,onClick:()=>{t.chain().focus().setColor(d).run(),N()}},d))}),o.jsxs("button",{className:"docs-tb-dropdown-item",onClick:()=>{t.chain().focus().unsetColor().run(),N()},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:()=>{N(),T(!k)},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"}})]}),k&&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(d=>o.jsx("button",{className:"docs-color-swatch",style:{background:d},title:d,onClick:()=>{d==="#ffffff"?t.chain().focus().unsetHighlight().run():t.chain().focus().toggleHighlight({color:d}).run(),N()}},d))})]})]}),o.jsx(_,{onClick:()=>t.chain().focus().toggleSubscript().run(),active:t.isActive("subscript"),title:"Subscript",children:o.jsx(v.Subscript,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().toggleSuperscript().run(),active:t.isActive("superscript"),title:"Superscript",children:o.jsx(v.Superscript,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().toggleCode().run(),active:t.isActive("code"),title:"Inline code",children:o.jsx(v.Code,{size:16})}),o.jsx(_,{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:I,children:[o.jsxs("button",{className:"docs-tb-select docs-tb-paragraph-select",onClick:()=>{N(),m(!c)},children:[o.jsx("span",{className:"docs-tb-select-label",children:et()}),o.jsx(v.ChevronDown,{size:14})]}),c&&o.jsx("div",{className:"docs-tb-dropdown-menu docs-style-menu",children:wt.map(d=>o.jsx("button",{className:`docs-tb-dropdown-item${et()===d.label?" active":""}`,onClick:()=>y(d.node),children:o.jsx("span",{className:`docs-style-preview docs-style-${d.node}`,children:d.label})},d.node))})]}),o.jsx(_,{onClick:()=>t.chain().focus().setTextAlign("left").run(),active:t.isActive({textAlign:"left"}),title:"Align left",children:o.jsx(v.AlignLeft,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().setTextAlign("center").run(),active:t.isActive({textAlign:"center"}),title:"Align center",children:o.jsx(v.AlignCenter,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().setTextAlign("right").run(),active:t.isActive({textAlign:"right"}),title:"Align right",children:o.jsx(v.AlignRight,{size:16})}),o.jsx(_,{onClick:()=>t.chain().focus().setTextAlign("justify").run(),active:t.isActive({textAlign:"justify"}),title:"Justify",children:o.jsx(v.AlignJustify,{size:16})}),o.jsx(_,{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:W,children:[o.jsxs("button",{className:`docs-tb-btn${xt?" active":""}`,onClick:()=>{N(),E(!Z)},title:"Line & paragraph spacing",children:[o.jsx(v.Rows3,{size:16}),o.jsx(v.ChevronDown,{size:12})]}),Z&&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:()=>Y(null),children:"Default"}),$n.map(d=>o.jsx("button",{className:`docs-tb-dropdown-item${xt===d?" active":""}`,onClick:()=>Y(d),children:d==="1"?"Single":d==="2"?"Double":d},d)),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:()=>O("space-before"),children:J(t,"space-before")?"Remove space before block":"Add space before block"}),o.jsx("button",{className:"docs-tb-dropdown-item",onClick:()=>O("space-after"),children:J(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(_,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet list",children:o.jsx(v.List,{size:16})}),o.jsx(_,{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:()=>{N(),b(!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"}),h.map((d,C)=>o.jsxs("div",{children:[C>0&&o.jsx("div",{className:"docs-insert-divider"}),o.jsx("div",{className:"docs-insert-category",children:d.category}),d.items.map(w=>o.jsxs("button",{className:"docs-tb-dropdown-item docs-insert-item",onClick:()=>A(w.keyword),disabled:w.isReadOnly,title:w.description,children:[o.jsx("span",{className:"docs-insert-icon",children:Dt[w.category]?.icon||"•"}),o.jsx("span",{className:"docs-insert-label",children:w.label}),o.jsx("span",{className:"docs-insert-kw",children:w.isReadOnly?"locked":`.${w.keyword}`})]},w.keyword))]},d.category))]})]}),o.jsx(_,{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})})]})]}),a&&o.jsxs(o.Fragment,{children:[o.jsx(pt,{}),o.jsxs(at,{label:"Trust",children:[o.jsxs(_,{onClick:()=>a("seal"),disabled:p,title:p?"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(_,{onClick:()=>a("sign"),title:"Sign — add a signature",children:[o.jsx(v.PenTool,{size:16}),o.jsx("span",{className:"ribbon-btn-text",children:"Sign"})]}),o.jsxs(_,{onClick:()=>a("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"})]})]})]})]})}function vt(t,e){return e?`${t} (${e})`:t}function En({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 ",vt(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=>`${vt(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=>`${vt(n.by,n.role)}${n.at?` on ${n.at}`:""}`).join(" · ")]})]}):null}function Pn(t){let e;try{e=R.parseIntentText(t)}catch{return[]}const n=[],r=(s,l)=>{const a=l==null?"":String(l).trim();a&&n.push({key:s,value:a})};for(const s of e.blocks)switch(s.type){case"meta":for(const[l,a]of Object.entries(s.properties||{}))r(l,a);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 Bn({source:t}){const[e,n]=u.useState(!1),r=u.useMemo(()=>Pn(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,a)=>o.jsxs("span",{className:"docs-props-chip",children:[o.jsx("b",{children:l.key})," ",l.value]},`${l.key}-${a}`))})]})}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(c=>c.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(c=>c.type==="approve");for(const c of s)e.approvals.push({by:z(c,"by",c.content??""),role:z(c,"role"),at:z(c,"at"),note:z(c,"note")||void 0});e.approvals.length>0&&(e.lifecycle="approved");const l=n.filter(c=>c.type==="sign");for(const c of l)e.signatures.push({by:z(c,"by",c.content??""),role:z(c,"role"),at:z(c,"at")});e.signatures.length>0&&(e.lifecycle="signed");const a=n.find(c=>c.type==="freeze");if(a){e.isSealed=!0,e.lifecycle="sealed";const c=e.signatures[e.signatures.length-1];e.sealedBy=c?.by||z(a,"by",a.content??""),e.sealedAt=z(a,"at")||c?.at||"",e.sealHash=z(a,"hash")}const p=n.filter(c=>c.type==="amendment");for(const c of p)e.amendments.push({section:z(c,"section",c.content??""),was:z(c,"was"),now:z(c,"now"),by:z(c,"by"),ref:z(c,"ref"),at:z(c,"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 In=x.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 On(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 Dn(t){const e={};for(const n of t){const r=n.split(".");let s=e;for(let l=0;l<r.length;l++){const a=r[l];l===r.length-1?a in s||(s[a]=""):((!(a in s)||typeof s[a]!="object"||s[a]===null)&&(s[a]={}),s=s[a])}}return e}const Fn=28,qn={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 Wn({value:t,onChange:e,theme:n,onThemeChange:r,readOnly:s=!1,showRibbon:l=!0,showTrustBanner:a=!0,onTrustAction:p}){const c=u.useRef(""),m=u.useRef(!1),f=u.useRef(!0),[b,g]=u.useState([]),S=u.useRef(ht("")),[j,M]=u.useState(1),k=Ht.useEditor({extensions:[Be.configure({geometry:()=>S.current,gap:Fn,onPages:M}),we.default.configure({heading:!1,codeBlock:!1,blockquote:!1,horizontalRule:!1,paragraph:!1}),vn,Tn,ve.default.configure({placeholder:({editor:h})=>h.isEmpty?"Start typing...":""}),Te.default,ge.TextStyle,je.default,Ae.default.configure({multicolor:!0}),Ce.default.configure({types:["paragraph","itTitle","itSummary","itSection","itSub"]}),Ne.default,Me,Le.default,_e.default,sn,on,an,cn,ln,dn,un,pn,gn,fn,mn,hn,bn,yn,xn,Sn,In],content:Ct(t),onUpdate:({editor:h})=>{if(f.current)return;const y=h.getJSON(),A=Yt(y);c.current=A,m.current=!0,g(Ve(y)),e(A)},editorProps:{attributes:{class:"docs-page-content",spellcheck:"true"}}});u.useEffect(()=>{const h=window.setTimeout(()=>{f.current=!1,c.current=t},0);return()=>window.clearTimeout(h)},[]),u.useEffect(()=>{if(k){if(m.current){m.current=!1;return}if(t!==c.current){const h=Ct(t);k.commands.setContent(h),c.current=t}}},[t,k]),u.useEffect(()=>{if(!k)return;const h=y=>{const A=y.detail;A&&k.chain().focus().insertContent(A).run()};return window.addEventListener("it-insert-text",h),()=>window.removeEventListener("it-insert-text",h)},[k]);const T=u.useMemo(()=>ht(t),[t]);u.useEffect(()=>{S.current=T,k?.view.dispatch(k.state.tr)},[T,k]);const Z=u.useRef(null),E=u.useCallback(()=>k?k.storage.characterCount?.words?.()??k.getText().split(/\s+/).filter(Boolean).length:0,[k]),F=u.useMemo(()=>{if(!n)return"";try{const h=R.getBuiltinTheme(n);return h?R.generateThemeCSS(h).replace(/:root\{/,".docs-page{"):""}catch{return""}},[n]),q=u.useMemo(()=>{try{const h=R.parseIntentText(t),y=h.blocks.find(O=>O.type==="header")?.content||"",A=h.blocks.find(O=>O.type==="footer")?.content||"",P=h.blocks.find(O=>O.type==="meta"),Y=String(P?.properties?.dir||"ltr").toLowerCase();return{header:y,footer:A,dir:Y}}catch{return{header:"",footer:"",dir:"ltr"}}},[t]),I=u.useMemo(()=>{try{return Nt(R.parseIntentText(t))}catch{return Nt(null)}},[t]),X=u.useMemo(()=>{if(!I.isSealed)return null;try{return R.verifyDocument(t).intact}catch{return null}},[t,I.isSealed]),$=I.isSealed||s;u.useEffect(()=>{k&&k.isEditable!==!$&&k.setEditable(!$)},[k,$]);const H=u.useMemo(()=>{try{return R.documentStyleCSS(R.parseIntentText(t),qn,".docs-page .tiptap ")}catch{return""}},[t]);u.useEffect(()=>{let h=document.getElementById("it-doc-style-rules");h||(h=document.createElement("style"),h.id="it-doc-style-rules",document.head.appendChild(h)),h.textContent=H},[H]);const tt=u.useCallback(()=>{if(q.dir==="rtl"){const y=t.split(`
|
|
28
|
-
`).map(
|
|
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
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
30
|
meta: | dir: rtl`)):e(`meta: | dir: rtl
|
|
31
|
-
${t}`)}},[t,e,
|
|
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;
|
|
32
32
|
//# sourceMappingURL=index.cjs.map
|