quill-clausula 0.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.
@@ -0,0 +1,112 @@
1
+ import type { ClausulaModuleOptions, ConversationContext } from './types.js';
2
+ declare const Module: any;
3
+ declare class ClausulaModule extends Module {
4
+ static DEFAULTS: {
5
+ clausulaFormat: import("./types.js").ClausulaFormat;
6
+ subclausulaFormat: import("./types.js").SubclausulaFormat;
7
+ paragrafoFormat: import("./types.js").ParagrafoFormat;
8
+ incisoFormat: import("./types.js").IncisoFormat;
9
+ alineaFormat: import("./types.js").AlineaFormat;
10
+ currentUser?: string;
11
+ users?: string[];
12
+ showActions?: boolean;
13
+ showFloatingBar?: boolean;
14
+ showDragHandle?: boolean;
15
+ onConversation?: (context: ConversationContext) => void;
16
+ onJudge?: () => void;
17
+ onShare?: () => void;
18
+ onSign?: () => void;
19
+ };
20
+ options: ClausulaModuleOptions;
21
+ private renumberScheduled;
22
+ private rafId;
23
+ private destroyed;
24
+ private floatingBar;
25
+ private ghostCut;
26
+ private dragOrganizer;
27
+ private textChangeRenumber;
28
+ private lockedRevertHandler;
29
+ private beforeInputHandler;
30
+ private pasteHandler;
31
+ private cutHandler;
32
+ static register(): void;
33
+ constructor(quill: any, options: Partial<ClausulaModuleOptions>);
34
+ /**
35
+ * Detaches all listeners and overlay DOM. Call when unmounting the editor
36
+ * (SPAs); the module must not be used afterwards.
37
+ */
38
+ destroy(): void;
39
+ /**
40
+ * Add tooltips and visual enhancements to toolbar controls.
41
+ */
42
+ private enhanceToolbar;
43
+ /**
44
+ * Prepend a binding so it fires before Quill's built-in handlers.
45
+ * Quill's addBinding() uses push(), so built-in Backspace/Enter handlers
46
+ * consume events before late-registered bindings. We unshift instead.
47
+ */
48
+ private prependBinding;
49
+ private removeClausulaFormat;
50
+ private removeParteFormat;
51
+ private removeObjetoFormat;
52
+ private addKeyboardBindings;
53
+ private addLockedLinePrevention;
54
+ private isRangeLocked;
55
+ private isSelectionOnLockedLine;
56
+ /**
57
+ * Checks the change against the OLD document (via oldDelta attributes),
58
+ * so it still detects edits that deleted or merged away a locked line.
59
+ * Line attributes live on the trailing \n of each line in the delta.
60
+ */
61
+ private doesDeltaTouchLockedLine;
62
+ private initFloatingBar;
63
+ private getAllItems;
64
+ private getAllParteItems;
65
+ private getAllObjetoItems;
66
+ private handleGlobalUndo;
67
+ private handleGlobalAgree;
68
+ private handleGlobalDisagree;
69
+ private handleGlobalLock;
70
+ private syncFloatingBar;
71
+ private scheduleRenumber;
72
+ /**
73
+ * Exports the current document as pandoc-friendly Markdown with all
74
+ * numbering labels materialized (suitable for MD → DOCX pipelines).
75
+ */
76
+ exportMarkdown(): string;
77
+ /**
78
+ * Exports the current document as clean HTML with all numbering labels
79
+ * materialized (suitable for print/PDF/read-only display).
80
+ */
81
+ exportHTML(): string;
82
+ renumber(): void;
83
+ renumberPartes(): void;
84
+ enforceSingletonObjeto(): void;
85
+ private syncObjetoButton;
86
+ syncAssinatura(): void;
87
+ private updateActions;
88
+ private handleLock;
89
+ private handleAgree;
90
+ private handleDisagree;
91
+ private handleConversation;
92
+ private setAgreed;
93
+ /**
94
+ * Groups clausula items into blocks led by a parent cláusula (level 0)
95
+ * followed by its children. Items before the first parent are not part
96
+ * of any draggable block.
97
+ */
98
+ private getClausulaBlocks;
99
+ /**
100
+ * Moves a whole clause block to another boundary as ONE atomic delta
101
+ * (single undo). Blocks containing locked lines move with API source so
102
+ * the reorder is allowed while their content stays protected.
103
+ */
104
+ private moveClausulaBlock;
105
+ private isParentWithChildren;
106
+ /**
107
+ * Get all children after the given clausula (level 0) until the next level-0 item.
108
+ * Works across container boundaries using the flattened allItems array.
109
+ */
110
+ private getChildren;
111
+ }
112
+ export default ClausulaModule;
@@ -0,0 +1,18 @@
1
+ import type { ClausulaIndex, ClausulaType } from '../types.js';
2
+ interface BlotLike {
3
+ domNode: HTMLElement;
4
+ next: BlotLike | null;
5
+ }
6
+ /**
7
+ * 2-pass counter algorithm:
8
+ *
9
+ * Pass 1: Count parágrafos per cláusula to detect "Parágrafo Único"
10
+ * Pass 2: Walk all items and compute indices
11
+ */
12
+ export declare function computeIndices(items: BlotLike[]): ClausulaIndex[];
13
+ /**
14
+ * DOM-free variant: computes indices from a plain list of clausula types
15
+ * (e.g. extracted from a delta). `computeIndices` delegates here.
16
+ */
17
+ export declare function computeIndicesFromTypes(types: (ClausulaType | null)[]): ClausulaIndex[];
18
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Converts a number (1-based) to its Portuguese ordinal word form.
3
+ *
4
+ * Brazilian legal documents use feminine ordinals for "Cláusula" (PRIMEIRA, SEGUNDA)
5
+ * and masculine ordinals for "Parágrafo" (Primeiro, Segundo).
6
+ */
7
+ export type Gender = 'masculine' | 'feminine';
8
+ export declare function toExtenso(num: number, gender?: Gender): string;
9
+ export declare function toExtensoUpper(num: number, gender?: Gender): string;
@@ -0,0 +1,2 @@
1
+ import type { ClausulaIndex, ClausulaModuleOptions } from '../types.js';
2
+ export declare function formatLabel(indexInfo: ClausulaIndex, options: ClausulaModuleOptions): string;
@@ -0,0 +1,2 @@
1
+ export declare function toRoman(num: number): string;
2
+ export declare function toRomanLower(num: number): string;
@@ -0,0 +1,25 @@
1
+ import type { ParteType, ParteIndex } from '../types.js';
2
+ interface ParteBlotLike {
3
+ domNode: HTMLElement;
4
+ }
5
+ /**
6
+ * Counts contratantes and contratados, then computes the label prefix for each.
7
+ *
8
+ * - 1 contratante → "CONTRATANTE: "
9
+ * - 2+ contratantes → "1º CONTRATANTE: ", "2º CONTRATANTE: "
10
+ * - Same logic for contratado(s)
11
+ */
12
+ export declare function computeParteIndices(items: ParteBlotLike[]): ParteIndex[];
13
+ /**
14
+ * DOM-free variant: computes indices from a plain list of parte types
15
+ * (e.g. extracted from a delta). `computeParteIndices` delegates here.
16
+ */
17
+ export declare function computeParteIndicesFromTypes(types: (ParteType | null)[]): ParteIndex[];
18
+ /**
19
+ * Formats a parte prefix label from an index.
20
+ *
21
+ * If there's only one party of that role, no ordinal number is shown.
22
+ * If there are 2+, prefix with "1º ", "2º ", etc.
23
+ */
24
+ export declare function formatParteLabel(info: ParteIndex): string;
25
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Nt=require("quill"),St=r=>r&&typeof r=="object"&&"default"in r?r:{default:r},h=St(Nt),Et=h.default.import("blots/container");class b extends Et{}b.blotName="clausula-container";b.className="ql-clausula-container";b.tagName="DIV";const Tt=h.default.import("blots/block"),k=class k extends Tt{constructor(t,e){super(t,e),this.actionsNode=null;const n=e.ownerDocument.createElement("span");n.classList.add("ql-clausula-prefix"),this.attachUI(n)}static create(t){const e=super.create();return e.setAttribute("data-clausula-type",t),e}static formats(t){return t.getAttribute("data-clausula-type")||void 0}static register(){h.default.register(b,!0)}format(t,e){t===k.blotName&&e?this.domNode.setAttribute("data-clausula-type",e):super.format(t,e)}update(t,e){const n=t.filter(s=>{if(!this.actionsNode)return!0;if(s.type==="childList"){const i=Array.from(s.addedNodes).some(l=>l===this.actionsNode||this.actionsNode&&this.actionsNode.contains(l)),o=Array.from(s.removedNodes).some(l=>l===this.actionsNode||this.actionsNode&&this.actionsNode.contains(l));if(i||o)return!1}return!(s.target===this.actionsNode||this.actionsNode&&this.actionsNode.contains(s.target))});n.length>0&&super.update(n,e)}};k.blotName="clausula",k.tagName="DIV",k.className="ql-clausula-item";let C=k;b.allowedChildren=[C];C.requiredContainer=b;const It=h.default.import("blots/container");class A extends It{}A.blotName="parte-container";A.className="ql-parte-container";A.tagName="DIV";const Rt=h.default.import("blots/block"),x=class x extends Rt{static create(t){const e=super.create();return e.setAttribute("data-parte-type",t),e}static formats(t){return t.getAttribute("data-parte-type")||void 0}static register(){h.default.register(A,!0)}constructor(t,e){super(t,e);const n=e.ownerDocument.createElement("span");n.classList.add("ql-parte-prefix"),this.attachUI(n)}format(t,e){t===x.blotName&&e?this.domNode.setAttribute("data-parte-type",e):super.format(t,e)}};x.blotName="parte",x.tagName="DIV",x.className="ql-parte-item";let N=x;A.allowedChildren=[N];N.requiredContainer=A;const wt=h.default.import("blots/container");class v extends wt{}v.blotName="objeto-container";v.className="ql-objeto-container";v.tagName="DIV";const $t=h.default.import("blots/block"),L=class L extends $t{static create(t){const e=super.create();return e.setAttribute("data-objeto","true"),e}static formats(t){return t.getAttribute("data-objeto")?"true":void 0}static register(){h.default.register(v,!0)}constructor(t,e){super(t,e);const n=e.ownerDocument.createElement("span");n.classList.add("ql-objeto-prefix"),n.textContent="OBJETO: ",this.attachUI(n)}format(t,e){t===L.blotName&&e?this.domNode.setAttribute("data-objeto","true"):super.format(t,e)}};L.blotName="objeto",L.tagName="DIV",L.className="ql-objeto-item";let S=L;v.allowedChildren=[S];S.requiredContainer=v;const Ot=h.default.import("blots/block/embed"),I=class I extends Ot{static create(t){const e=super.create(),n=typeof t=="string"?JSON.parse(t):t||{};return e.setAttribute("data-assinatura",JSON.stringify(n)),e.setAttribute("contenteditable","false"),e}static value(t){const e=t.getAttribute("data-assinatura");if(!e)return{};try{return JSON.parse(e)}catch{return{}}}static formats(t){}};I.blotName="assinatura",I.tagName="DIV",I.className="ql-assinatura-block";let q=I;const{ClassAttributor:Bt,Scope:_t}=h.default.import("parchment"),z=new Bt("locked","ql-locked",{scope:_t.BLOCK,whitelist:["true"]}),{Attributor:Pt,Scope:Dt}=h.default.import("parchment");class Ut extends Pt{constructor(t,e,n){super(t,e,n)}add(t,e){const n=typeof e=="string"?JSON.parse(e):e;t.setAttribute("data-agreed",JSON.stringify(n));const s=Object.values(n),i=s.length>0&&s.every(Boolean),o=s.some(l=>l===!1);return t.classList.toggle("ql-agreed",i),t.classList.toggle("ql-disagreed",o),!0}remove(t){t.removeAttribute("data-agreed"),t.classList.remove("ql-agreed"),t.classList.remove("ql-disagreed")}value(t){const e=t.getAttribute("data-agreed");if(e)try{return JSON.parse(e)}catch{return}}}const X=new Ut("agreed","data-agreed",{scope:Dt.BLOCK}),{ClassAttributor:Mt,Scope:Ht}=h.default.import("parchment"),Y=new Mt("ghost","ql-ghost",{scope:Ht.INLINE,whitelist:["true"]}),{StyleAttributor:W,Scope:Z}=h.default.import("parchment"),tt=["1","1.15","1.5","2","2.5","3"],et=["0em","0.5em","1em","1.5em","2em"],st=new W("lineheight","line-height",{scope:Z.BLOCK,whitelist:[...tt]}),nt=new W("spacing","margin-bottom",{scope:Z.BLOCK,whitelist:[...et]});function P(r,t,e,n){const s=[];if(e<=r)e>0&&s.push({retain:e}),s.push(...n),r-e>0&&s.push({retain:r-e}),s.push({delete:t});else{r>0&&s.push({retain:r}),s.push({delete:t});const i=e-(r+t);i>0&&s.push({retain:i}),s.push(...n)}return s}function rt(r){var s;let t=0,e=-1,n=-1;for(const i of r.ops||[]){const o=typeof i.insert=="string"?i.insert.length:i.insert?1:0;(s=i.attributes)!=null&&s.ghost&&(e===-1&&(e=t),n=t+o),t+=o}return e===-1?null:{index:e,length:n-e}}class it{constructor(t,e){this.quill=t,this.isRangeLocked=e.isRangeLocked}get active(){return this.findRange()!==null}findRange(){return rt(this.quill.getContents())}expandToLineBoundary(t,e){const n=this.quill,[s,i]=n.getLine(t),[o,l]=n.getLine(t+e);if(!s||!o)return{index:t,length:e};const c=i===0,a=l===o.length()-1,u=t+e+1<n.getLength();return c&&a&&u?{index:t,length:e+1}:{index:t,length:e}}handleCut(t){const e=this.quill.getSelection();if(!e||e.length===0)return!1;if(t.preventDefault(),this.isRangeLocked(e.index,e.length))return!0;this.cancel();const n=this.expandToLineBoundary(e.index,e.length);return this.quill.formatText(n.index,n.length,"ghost","true","silent"),this.markGhostLines(n.index,n.length),this.quill.setSelection(n.index+n.length,0,"silent"),!0}markGhostLines(t,e){const n=this.quill.getLines(t,Math.max(e,1));for(const s of n){if(!(s!=null&&s.domNode))continue;const i=this.quill.getIndex(s),o=i+s.length();i>=t&&o-1<=t+e&&s.domNode.classList.add("ql-ghost-line")}}clearGhostLines(){const t=this.quill.root;for(const e of t.querySelectorAll(".ql-ghost-line"))e.classList.remove("ql-ghost-line")}handlePaste(t){const e=this.findRange();if(!e)return!1;t.preventDefault();const n=this.expandToLineBoundary(e.index,e.length),s=this.quill.getSelection(!0),i=s?s.index:n.index;if(i>n.index&&i<n.index+n.length)return this.cancel(),!0;if(this.isRangeLocked(i,0))return!0;this.clearGhostLines(),this.quill.formatText(e.index,e.length,"ghost",!1,"silent");const o=this.quill.getContents(n.index,n.length),l=P(n.index,n.length,i,o.ops);this.quill.updateContents({ops:l},"user");const c=i<=n.index?i+n.length:i;return this.quill.setSelection(c,0,"silent"),!0}cancel(){this.clearGhostLines();const t=this.findRange();return t?(this.quill.formatText(t.index,t.length,"ghost",!1,"silent"),!0):!1}destroy(){this.cancel()}}const jt='<svg viewBox="0 0 10 16" width="10" height="16" fill="currentColor"><circle cx="2.5" cy="3" r="1.4"/><circle cx="7.5" cy="3" r="1.4"/><circle cx="2.5" cy="8" r="1.4"/><circle cx="7.5" cy="8" r="1.4"/><circle cx="2.5" cy="13" r="1.4"/><circle cx="7.5" cy="13" r="1.4"/></svg>';class ot{constructor(t,e){this.hoveredBlockIndex=-1,this.hoveredParentEl=null,this.hideTimer=null,this.dragging=!1,this.dropBoundary=-1,this.blockRects=[],this.onMouseMove=s=>this.trackHover(s),this.onMouseLeave=()=>{this.dragging||this.scheduleHide()},this.onPointerDown=s=>this.startDrag(s),this.onPointerMove=s=>this.trackDrag(s),this.onPointerUp=s=>this.endDrag(s),this.quill=t,this.callbacks=e,this.container=t.container;const n=this.container.ownerDocument;this.handle=n.createElement("div"),this.handle.className="ql-clausula-drag-handle",this.handle.setAttribute("contenteditable","false"),this.handle.setAttribute("title","Arraste para reordenar a cláusula"),this.handle.innerHTML=jt,this.container.appendChild(this.handle),this.indicator=n.createElement("div"),this.indicator.className="ql-clausula-drop-indicator",this.container.appendChild(this.indicator),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseleave",this.onMouseLeave),this.handle.addEventListener("pointerdown",this.onPointerDown)}hideHandle(){this.cancelHide(),this.handle.classList.remove("visible"),this.hoveredBlockIndex=-1,this.hoveredParentEl=null}scheduleHide(){this.hideTimer===null&&(this.hideTimer=setTimeout(()=>{this.hideTimer=null,this.hideHandle()},350))}cancelHide(){this.hideTimer!==null&&(clearTimeout(this.hideTimer),this.hideTimer=null)}isInReachCorridor(t){if(!this.hoveredParentEl||!this.handle.classList.contains("visible"))return!1;const e=this.hoveredParentEl.getBoundingClientRect(),n=this.handle.getBoundingClientRect();return t.clientY>=Math.min(n.top,e.top)-10&&t.clientY<=Math.max(n.bottom,e.bottom)+10&&t.clientX>=n.left-14&&t.clientX<=e.right}trackHover(t){var l,c,a,u;if(this.dragging)return;if((c=(l=t.target).closest)!=null&&c.call(l,".ql-clausula-drag-handle")){this.cancelHide();return}const e=(u=(a=t.target).closest)==null?void 0:u.call(a,".ql-clausula-item");if(!e){this.isInReachCorridor(t)?this.cancelHide():this.scheduleHide();return}const n=this.callbacks.getBlocks(),s=n.findIndex(d=>d.items.some(f=>f.domNode===e));if(s===-1){this.scheduleHide();return}this.cancelHide(),this.hoveredBlockIndex=s,this.hoveredParentEl=n[s].items[0].domNode;const i=this.hoveredParentEl.getBoundingClientRect(),o=this.container.getBoundingClientRect();this.handle.style.top=`${i.top-o.top+2}px`,this.handle.style.left=`${Math.max(i.left-o.left-26,2)}px`,this.handle.classList.add("visible")}startDrag(t){if(this.hoveredBlockIndex===-1)return;t.preventDefault(),this.dragging=!0,this.dropBoundary=-1;try{this.handle.setPointerCapture(t.pointerId)}catch{}this.handle.addEventListener("pointermove",this.onPointerMove),this.handle.addEventListener("pointerup",this.onPointerUp),this.container.classList.add("ql-clausula-dragging");const e=this.callbacks.getBlocks(),n=this.container.getBoundingClientRect();this.blockRects=e.map(s=>{const i=s.items[0].domNode.getBoundingClientRect(),o=s.items[s.items.length-1].domNode.getBoundingClientRect();return{top:i.top-n.top,bottom:o.bottom-n.top}});for(const s of e[this.hoveredBlockIndex].items)s.domNode.classList.add("ql-drag-source")}trackDrag(t){if(!this.dragging)return;const e=this.container.getBoundingClientRect(),n=t.clientY-e.top,s=[...this.blockRects.map(c=>c.top),this.blockRects.length>0?this.blockRects[this.blockRects.length-1].bottom:0];let i=0,o=1/0;s.forEach((c,a)=>{const u=Math.abs(c-n);u<o&&(o=u,i=a)}),this.dropBoundary=i;const l=i===this.hoveredBlockIndex||i===this.hoveredBlockIndex+1;this.indicator.style.top=`${s[i]-1}px`,this.indicator.classList.toggle("visible",!l)}endDrag(t){try{this.handle.releasePointerCapture(t.pointerId)}catch{}this.handle.removeEventListener("pointermove",this.onPointerMove),this.handle.removeEventListener("pointerup",this.onPointerUp),this.container.classList.remove("ql-clausula-dragging"),this.indicator.classList.remove("visible");const e=this.hoveredBlockIndex,n=this.dropBoundary;this.dragging=!1;for(const i of this.container.querySelectorAll(".ql-drag-source"))i.classList.remove("ql-drag-source");const s=n===-1||n===e||n===e+1;e!==-1&&!s&&this.callbacks.moveBlock(e,n),this.hideHandle()}destroy(){this.cancelHide(),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.handle.removeEventListener("pointerdown",this.onPointerDown),this.handle.remove(),this.indicator.remove()}}function at(r){return D(r.map(t=>t.domNode.getAttribute("data-clausula-type")))}function D(r){const t=[];let e=-1;for(const a of r)a==="clausula"&&(e++,t.push(0)),a==="paragrafo"&&e>=0&&t[e]++;const n=[];let s=0,i=0,o=0,l=0,c=0;for(const a of r)switch(a){case"clausula":s++,i=0,o=0,l=0,c=0,n.push({type:a,index:s,parentClausulaIndex:s,isUnico:!1});break;case"subclausula":i++,l=0,c=0,n.push({type:a,index:i,parentClausulaIndex:s,isUnico:!1});break;case"paragrafo":o++,l=0,c=0,n.push({type:a,index:o,parentClausulaIndex:s,isUnico:s>0&&t[s-1]===1});break;case"inciso":l++,c=0,n.push({type:a,index:l,parentClausulaIndex:s,isUnico:!1});break;case"alinea":c++,n.push({type:a,index:c,parentClausulaIndex:s,isUnico:!1});break;default:n.push({type:a||"clausula",index:1,parentClausulaIndex:s,isUnico:!1})}return n}const Ft=["","Primeiro","Segundo","Terceiro","Quarto","Quinto","Sexto","Sétimo","Oitavo","Nono"],Gt=["","Primeira","Segunda","Terceira","Quarta","Quinta","Sexta","Sétima","Oitava","Nona"],Vt=["","Décimo","Vigésimo","Trigésimo","Quadragésimo","Quinquagésimo","Sexagésimo","Septuagésimo","Octogésimo","Nonagésimo"],Kt=["","Décima","Vigésima","Trigésima","Quadragésima","Quinquagésima","Sexagésima","Septuagésima","Octogésima","Nonagésima"],Jt=["","Centésimo","Ducentésimo","Trecentésimo","Quadringentésimo","Quingentésimo","Sexcentésimo","Septingentésimo","Octingentésimo","Noningentésimo"],Qt=["","Centésima","Ducentésima","Trecentésima","Quadringentésima","Quingentésima","Sexcentésima","Septingentésima","Octingentésima","Noningentésima"];function B(r,t="feminine"){if(r<=0||r>999)return String(r);const e=t==="feminine"?Gt:Ft,n=t==="feminine"?Kt:Vt,s=t==="feminine"?Qt:Jt,i=[],o=Math.floor(r/100),l=Math.floor(r%100/10),c=r%10;return o>0&&i.push(s[o]),l>0&&i.push(n[l]),c>0&&i.push(e[c]),i.join(" ")}function U(r,t="feminine"){return B(r,t).toUpperCase()}const zt=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];function w(r){if(r<=0||r>3999)return String(r);let t="",e=r;for(const[n,s]of zt)for(;e>=n;)t+=s,e-=n;return t}function lt(r){return w(r).toLowerCase()}function $(r){return r<10?`0${r}`:String(r)}function Xt(r){let t="",e=r;for(;e>0;)e--,t=String.fromCharCode(97+e%26)+t,e=Math.floor(e/26);return t}function Yt(r,t){switch(t){case"extenso":return`CLÁUSULA ${U(r,"feminine")} — `;case"numeric":return`CLÁUSULA ${r} — `;case"numeric-padded":return`CLÁUSULA ${$(r)} — `;case"ordinal":return`CLÁUSULA ${r}ª — `;case"abbreviation":return`Cl. ${r} — `;case"regular":return`Cláusula ${r} — `;case"regular-padded":return`Cláusula ${$(r)} — `;default:return`CLÁUSULA ${r} — `}}function Wt(r,t,e){switch(e){case"dotted":return`${t}.${r} `;case"dotted-padded":return`${$(t)}.${$(r)} `;case"numeric":return`${r}. `;case"extenso":return`${B(r,"feminine")} `;default:return`${t}.${r} `}}function Zt(r,t){if(r.isUnico)switch(t){case"extenso":return"Parágrafo Único. ";case"uppercase":return"PARÁGRAFO ÚNICO. ";case"numeric":return"Parágrafo Único. ";case"symbol":return"§ Único. ";default:return"Parágrafo Único. "}switch(t){case"extenso":return`Parágrafo ${B(r.index,"masculine")}. `;case"uppercase":return`PARÁGRAFO ${U(r.index,"masculine")}. `;case"numeric":return`Parágrafo ${r.index}º. `;case"symbol":return`§${r.index}º. `;default:return`Parágrafo ${r.index}º. `}}function te(r,t){switch(t){case"roman":return`${w(r)} — `;case"roman-lower":return`${lt(r)} — `;default:return`${w(r)} — `}}function ee(r,t){const e=Xt(r);switch(t){case"letter-parenthesis":return`${e}) `;case"letter":return`${e}. `;default:return`${e}) `}}function M(r,t){switch(r.type){case"clausula":return Yt(r.index,t.clausulaFormat);case"subclausula":return Wt(r.index,r.parentClausulaIndex,t.subclausulaFormat);case"paragrafo":return Zt(r,t.paragrafoFormat);case"inciso":return te(r.index,t.incisoFormat);case"alinea":return ee(r.index,t.alineaFormat);default:return""}}function ct(r){return H(r.map(t=>t.domNode.getAttribute("data-parte-type")))}function H(r){const t={contratante:0,contratado:0},e=r.map(i=>i&&i in t?i:"contratante");for(const i of e)t[i]++;const n={contratante:0,contratado:0},s=[];for(const i of e)n[i]++,s.push({type:i,index:n[i],total:t[i]});return s}function j(r){const t=r.type==="contratante"?"CONTRATANTE":"CONTRATADO";return r.total<=1?`${t}: `:`${r.index}º ${t}: `}function ut(r){const t=[];for(const e of r){const n=e.domNode,s=n.getAttribute("data-parte-type");if(!s)continue;const i=n.querySelector(".ql-ui");let o=n.textContent||"";i&&i.textContent&&(o=o.replace(i.textContent,"")),o=o.trim();const l=o.indexOf(","),c=l>=0?o.substring(0,l).trim():o.trim();c&&t.push({nome:c,role:s})}return t}function F(r,t){const e=[],n=t.local||"[Local]",s=t.dataAssinatura||"[Data]";e.push(`<div class="ql-assinatura-header">${n}, ${s}</div>`);for(const o of r){const l=o.role==="contratante"?"CONTRATANTE":"CONTRATADO";e.push(`<div class="ql-assinatura-line"><div class="ql-assinatura-rule">____________________________________</div><div class="ql-assinatura-nome">${se(o.nome)}</div><div class="ql-assinatura-role">${l}</div></div>`)}const i=t.testemunhas??2;if(i>0){e.push('<div class="ql-assinatura-testemunhas-header">TESTEMUNHAS:</div>');for(let o=1;o<=i;o++)e.push(`<div class="ql-assinatura-line"><div class="ql-assinatura-rule">____________________________________</div><div class="ql-assinatura-nome">Testemunha ${o}</div><div class="ql-assinatura-role">Nome / CPF</div></div>`)}return e.join("")}function se(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ne(r){this.quill.format("clausula",r||!1)}const re="[NOME COMPLETO], [NACIONALIDADE], [ESTADO CIVIL], [PROFISSÃO], inscrito(a) no CPF sob o nº [CPF], RG nº [RG], residente e domiciliado(a) em [ENDEREÇO COMPLETO]";function ie(r){if(!r){this.quill.format("parte",!1);return}this.quill.format("parte",r);const t=this.quill.getSelection();if(t){const[e]=this.quill.getLine(t.index);if(e){const n=e.domNode.querySelector(".ql-ui");let s=e.domNode.textContent||"";n&&n.textContent&&(s=s.replace(n.textContent,"")),s.trim()===""&&this.quill.insertText(t.index,re,"user")}}}function oe(r){this.quill.format("objeto",r||!1)}function ae(){const r=this.quill;r.focus();const t=r.root.querySelector(".ql-assinatura-block");if(t){t.scrollIntoView({behavior:"smooth",block:"center"});return}const e=r.getLength();r.insertEmbed(e-1,"assinatura",{},"user"),r.setSelection(e,0,"silent")}const le=[[/^sub[- ]?cl[aá]usula$/i,"subclausula"],[/^sub$/i,"subclausula"],[/^cl[aá]usula$/i,"clausula"],[/^cl$/i,"clausula"],[/^par[aá]grafo$/i,"paragrafo"],[/^par$/i,"paragrafo"],[/^§$/,"paragrafo"],[/^inciso$/i,"inciso"],[/^inc$/i,"inciso"],[/^al[ií]nea$/i,"alinea"],[/^al$/i,"alinea"]],ce=[[/^contratante$/i,{format:"parte",value:"contratante"}],[/^contratado$/i,{format:"parte",value:"contratado"}],[/^objeto$/i,{format:"objeto",value:"true"}]],dt=/^\s*?(cl[aá]usula|sub[- ]?cl[aá]usula|sub|cl|par[aá]grafo|par|§|inciso|inc|al[ií]nea|al|contratante|contratado|objeto)$/i;function ht(r){const t=r.trim();for(const[e,n]of le)if(e.test(t))return n;return null}function ft(r){const t=r.trim();for(const[e,n]of ce)if(e.test(t))return n;return null}const y={clausula:0,subclausula:1,paragrafo:1,inciso:2,alinea:3},T=["clausula","subclausula","paragrafo","inciso","alinea"],J={clausulaFormat:"extenso",subclausulaFormat:"dotted",paragrafoFormat:"extenso",incisoFormat:"roman",alineaFormat:"letter-parenthesis",showActions:!0,showFloatingBar:!0,showDragHandle:!0},ue=["bold","italic","underline"];function de(r){const t={};if(!r)return t;for(const e of ue)r[e]&&(t[e]=!0);return t}function he(r){if(typeof r=="string")try{return JSON.parse(r)}catch{return{}}return r||{}}function G(r,t){const e=[];let n=[];const s=a=>{const d={kind:"text",label:"",text:n.map(f=>f.text).join(""),segments:n};(a==null?void 0:a.locked)==="true"&&(d.locked=!0),a!=null&&a.agreed&&typeof a.agreed=="object"&&(d.agreed=a.agreed),typeof(a==null?void 0:a.lineheight)=="string"&&(d.lineHeight=a.lineheight),typeof(a==null?void 0:a.spacing)=="string"&&(d.spacingAfter=a.spacing),a!=null&&a.clausula?(d.kind="clausula",d.clausulaType=a.clausula):a!=null&&a.parte?(d.kind="parte",d.parteType=a.parte):a!=null&&a.objeto?d.kind="objeto":a!=null&&a.table&&(d.kind="table-cell",d.tableRow=String(a.table)),e.push(d),n=[]};for(const a of r.ops||[])if(typeof a.insert=="string"){const u=a.insert.split(`
2
+ `);u.forEach((d,f)=>{d&&n.push({text:d,...de(a.attributes)}),f<u.length-1&&s(a.attributes)})}else a.insert&&typeof a.insert=="object"&&"assinatura"in a.insert&&e.push({kind:"assinatura",label:"",text:"",segments:[],assinatura:he(a.insert.assinatura)});n.length>0&&s();const i=e.filter(a=>a.kind==="clausula"),o=D(i.map(a=>a.clausulaType||null));i.forEach((a,u)=>{a.label=M(o[u],t)});const l=e.filter(a=>a.kind==="parte"),c=H(l.map(a=>a.parteType||null));l.forEach((a,u)=>{a.label=j(c[u])});for(const a of e)a.kind==="objeto"&&(a.label="OBJETO: ");return e}function gt(r){const t=[];let e=[],n;for(const s of r)s.tableRow!==n&&e.length>0&&(t.push(e),e=[]),n=s.tableRow,e.push(s);return e.length>0&&t.push(e),t}function pt(r){const t=[];for(const e of r){if(e.kind!=="parte"||!e.parteType)continue;const n=e.text.indexOf(","),s=(n>=0?e.text.slice(0,n):e.text).trim();s&&t.push({nome:s,role:e.parteType})}return t}function mt(r){return r.replace(/([\\`*_])/g,"\\$1")}function fe(r){let t=mt(r.text);return r.underline&&(t=`[${t}]{.underline}`),r.italic&&(t=`*${t}*`),r.bold&&(t=`**${t}**`),t}function Q(r){return r.segments.map(fe).join("")}function ge(r,t){const e=[],n=r.local||"[Local]",s=r.dataAssinatura||"[Data]";e.push(`${n}, ${s}`);const i="\\_".repeat(36);for(const l of t){const c=l.role==="contratante"?"CONTRATANTE":"CONTRATADO";e.push(`${i}
3
+ ${mt(l.nome)}
4
+ ${c}`)}const o=r.testemunhas??2;if(o>0){e.push("TESTEMUNHAS:");for(let l=1;l<=o;l++)e.push(`${i}
5
+ Testemunha ${l}
6
+ Nome / CPF`)}return e.join(`
7
+
8
+ `)}function bt(r,t){const e=G(r,t),n=pt(e),s=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.kind==="table-cell"){let c=i;for(;c<e.length&&e[c].kind==="table-cell";)c++;const a=gt(e.slice(i,c)),u=p=>`| ${p.map(m=>Q(m).replace(/\|/g,"\\|")).join(" | ")} |`,d=Math.max(...a.map(p=>p.length)),f=`|${" --- |".repeat(d)}`;s.push([u(a[0]),f,...a.slice(1).map(u)].join(`
9
+ `)),i=c-1;continue}const l=Q(o);switch(o.kind){case"clausula":{o.clausulaType==="clausula"?s.push(`## ${o.label}${l}`):o.clausulaType==="alinea"?s.push(`${o.label.replace(")","\\)")}${l}`):o.clausulaType==="inciso"?s.push(`${o.label}${l}`):s.push(`**${o.label.trim()}** ${l}`);break}case"parte":case"objeto":s.push(`**${o.label.trim()}** ${l}`);break;case"assinatura":s.push(ge(o.assinatura||{},n));break;default:o.text.trim()&&s.push(l)}}return s.join(`
10
+
11
+ `)+`
12
+ `}function _(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function yt(r){let t=_(r.text);return r.underline&&(t=`<u>${t}</u>`),r.italic&&(t=`<em>${t}</em>`),r.bold&&(t=`<strong>${t}</strong>`),t}function pe(r,t){const e=r.segments.map(yt).join(""),n=r.label?`<span class="qc-label">${_(r.label)}</span>`:"",s=[r.lineHeight?`line-height:${r.lineHeight}`:"",r.spacingAfter?`margin-bottom:${r.spacingAfter}`:""].filter(Boolean).join(";"),i=[r.locked?' data-locked="true"':"",r.agreed?` data-agreed='${_(JSON.stringify(r.agreed))}'`:"",s?` style="${s}"`:""].join("");switch(r.kind){case"clausula":return`<p class="qc-clausula qc-${r.clausulaType}"${i}>${n}${e}</p>`;case"parte":return`<p class="qc-parte" data-parte-type="${r.parteType}"${i}>${n}${e}</p>`;case"objeto":return`<p class="qc-objeto"${i}>${n}${e}</p>`;case"assinatura":return`<div class="qc-assinatura ql-assinatura-block">${F(t,r.assinatura||{})}</div>`;default:return r.text.trim()?`<p class="qc-text"${i}>${e}</p>`:""}}function At(r,t){const e=G(r,t),n=pt(e),s=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.kind==="table-cell"){let c=i;for(;c<e.length&&e[c].kind==="table-cell";)c++;const u=gt(e.slice(i,c)).map(d=>`<tr>${d.map(f=>`<td>${f.segments.map(yt).join("")}</td>`).join("")}</tr>`).join(`
13
+ `);s.push(`<table class="qc-table"><tbody>
14
+ ${u}
15
+ </tbody></table>`),i=c-1;continue}const l=pe(o,n);l&&s.push(l)}return`<div class="qc-document">
16
+ ${s.join(`
17
+ `)}
18
+ </div>`}const me='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="7" width="10" height="7" rx="1.5"/><path d="M5 7V5a3 3 0 0 1 6 0v2"/></svg>',be='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="3.5 8.5 6.5 11.5 12.5 4.5"/></svg>',ye='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="4" x2="12" y2="12"/><line x1="12" y1="4" x2="4" y2="12"/></svg>',Ae='<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3h12v8H6l-3 2.5V11H2z"/><circle cx="5.5" cy="7" r="0.5" fill="currentColor" stroke="none"/><circle cx="8" cy="7" r="0.5" fill="currentColor" stroke="none"/><circle cx="10.5" cy="7" r="0.5" fill="currentColor" stroke="none"/></svg>';function vt(r){const t=r.createElement("div");t.className="ql-clausula-actions",t.setAttribute("contenteditable","false");const e=r.createElement("button");e.className="ql-clausula-btn ql-clausula-lock",e.setAttribute("tabindex","-1"),e.setAttribute("type","button"),e.setAttribute("title","Lock"),e.innerHTML=me;const n=r.createElement("button");n.className="ql-clausula-btn ql-clausula-agree",n.setAttribute("tabindex","-1"),n.setAttribute("type","button"),n.setAttribute("title","Agree"),n.innerHTML=be;const s=r.createElement("button");s.className="ql-clausula-btn ql-clausula-disagree",s.setAttribute("tabindex","-1"),s.setAttribute("type","button"),s.setAttribute("title","Disagree"),s.innerHTML=ye;const i=r.createElement("button");return i.className="ql-clausula-btn ql-clausula-conversation",i.setAttribute("tabindex","-1"),i.setAttribute("type","button"),i.setAttribute("title","Conversation"),i.innerHTML=Ae,t.appendChild(e),t.appendChild(n),t.appendChild(s),t.appendChild(i),t}function kt(r,t,e,n,s){const i=r.querySelector(".ql-clausula-lock"),o=r.querySelector(".ql-clausula-agree"),l=r.querySelector(".ql-clausula-disagree");if(!i||!o||!l)return;const c=t.classList.contains("ql-locked-true");if(i.classList.toggle("active",c),o.disabled=c,l.disabled=c,!e){o.classList.remove("active"),l.classList.remove("active");return}const a=t.getAttribute("data-clausula-type");if((a?y[a]===0:!1)&&s&&s.length>0){const d=n||[e],f=s.every(m=>{const E=m.getAttribute("data-agreed");if(!E)return!1;try{const K=JSON.parse(E);return d.every(Ct=>K[Ct]===!0)}catch{return!1}}),p=s.some(m=>{const E=m.getAttribute("data-agreed");if(!E)return!1;try{return JSON.parse(E)[e]===!1}catch{return!1}});o.classList.toggle("active",f),l.classList.toggle("active",p),t.classList.toggle("ql-agreed",f),t.classList.toggle("ql-disagreed",p)}else{const d=t.getAttribute("data-agreed");let f=!1,p=!1;if(d)try{const m=JSON.parse(d);f=m[e]===!0,p=m[e]===!1}catch{}o.classList.toggle("active",f),l.classList.toggle("active",p),t.classList.toggle("ql-disagreed",p)}}const ve='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/></svg>',ke='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 12 9 17 20 6"/></svg>',xe='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',Le='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>',qe='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="5" r="3"/><path d="M12 8v4"/><line x1="5" y1="12" x2="19" y2="12"/><line x1="5" y1="12" x2="5" y2="16"/><line x1="19" y1="12" x2="19" y2="16"/><line x1="12" y1="12" x2="12" y2="20"/><rect x="8" y="20" width="8" height="2" rx="1"/></svg>',Ce='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>',Ne='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3l4 4-10 10H7v-4L17 3z"/><path d="M2 21h20"/><path d="M14 7l4 4"/></svg>';function xt(r,t){const e=r.createElement("div");e.className="ql-clausula-floating-bar",e.setAttribute("contenteditable","false");const n=[{className:"ql-floating-undo",title:"Undo / Remake Contract",svg:ve,callback:t.onUndo},{className:"ql-floating-agree-all",title:"Agree to All",svg:ke,callback:t.onAgreeAll},{className:"ql-floating-disagree-all",title:"Disagree to All",svg:xe,callback:t.onDisagreeAll},{className:"ql-floating-lock-all",title:"Lock All",svg:Le,callback:t.onLockAll},{className:"ql-floating-judge",title:"AI Judge",svg:qe,callback:t.onJudge},{className:"ql-floating-share",title:"Share",svg:Ce,callback:t.onShare},{className:"ql-floating-sign",title:"Sign Contract",svg:Ne,callback:t.onSign}];for(const s of n){const i=r.createElement("button");i.className=`ql-floating-btn ${s.className}`,i.setAttribute("type","button"),i.setAttribute("title",s.title),i.innerHTML=s.svg,s.callback&&i.addEventListener("click",o=>{o.preventDefault(),s.callback()}),e.appendChild(i)}return e}function Lt(r,t,e){const n=r.createElement("div");n.className="ql-clausula-modal-overlay";const s=r.createElement("div");s.className="ql-clausula-modal";const i=r.createElement("h3");i.className="ql-clausula-modal-title",i.textContent="Remake Contract";const o=r.createElement("p");o.className="ql-clausula-modal-message",o.textContent="This will undo all agreements, disagreements, and locks on the entire contract. Are you sure you want to proceed?";const l=r.createElement("div");l.className="ql-clausula-modal-actions";const c=r.createElement("button");c.className="ql-clausula-modal-btn ql-clausula-modal-cancel",c.setAttribute("type","button"),c.textContent="Cancel",c.addEventListener("click",()=>{n.remove(),e()});const a=r.createElement("button");return a.className="ql-clausula-modal-btn ql-clausula-modal-confirm",a.setAttribute("type","button"),a.textContent="Confirm",a.addEventListener("click",()=>{n.remove(),t()}),l.appendChild(c),l.appendChild(a),s.appendChild(i),s.appendChild(o),s.appendChild(l),n.appendChild(s),n.addEventListener("click",u=>{u.target===n&&(n.remove(),e())}),n}function qt(r,t){if(t.length===0||r.length===0)return!1;const e=s=>{const i=s.getAttribute("data-clausula-type");return i?y[i]===0:!1},n=r.filter((s,i)=>{if(!e(s))return!0;const o=r[i+1];return o===void 0||e(o)});return n.length===0?!1:n.every(s=>{const i=s.getAttribute("data-agreed");if(!i)return!1;try{const o=JSON.parse(i);return t.every(l=>o[l]===!0)}catch{return!1}})}const Se=h.default.import("core/module"),g=h.default.sources||{USER:"user",SILENT:"silent",API:"api"},V=class V extends Se{constructor(t,e){super(t,e),this.renumberScheduled=!1,this.rafId=null,this.destroyed=!1,this.floatingBar=null,this.ghostCut=null,this.dragOrganizer=null,this.textChangeRenumber=()=>this.scheduleRenumber(),this.lockedRevertHandler=(s,i,o)=>{var l,c;if(o===g.USER&&this.doesDeltaTouchLockedLine(s,i)){const a=s.invert(i);this.quill.updateContents(a,g.API);const u=(l=this.quill.history)==null?void 0:l.stack;(c=u==null?void 0:u.undo)!=null&&c.length&&u.undo.pop()}},this.beforeInputHandler=s=>{this.isSelectionOnLockedLine()&&s.preventDefault()},this.pasteHandler=s=>{var i;if(this.isSelectionOnLockedLine()){s.preventDefault();return}(i=this.ghostCut)==null||i.handlePaste(s)},this.cutHandler=s=>{var i;(i=this.ghostCut)==null||i.handleCut(s)},this.options={...J,...e};const n=t.getModule("toolbar");n&&(n.addHandler("clausula",ne),n.addHandler("parte",ie),n.addHandler("objeto",oe),n.addHandler("assinatura",ae),this.enhanceToolbar(n)),this.addKeyboardBindings(),t.on("text-change",this.textChangeRenumber),this.ghostCut=new it(t,{isRangeLocked:(s,i)=>this.isRangeLocked(s,i)}),this.addLockedLinePrevention(),this.options.showDragHandle!==!1&&(this.dragOrganizer=new ot(t,{getBlocks:()=>this.getClausulaBlocks(),moveBlock:(s,i)=>this.moveClausulaBlock(s,i)})),this.options.showFloatingBar!==!1&&this.initFloatingBar(),this.scheduleRenumber()}static register(){h.default.register(C,!0),h.default.register(b,!0),h.default.register(N,!0),h.default.register(A,!0),h.default.register(S,!0),h.default.register(v,!0),h.default.register(q,!0),h.default.register(z,!0),h.default.register(X,!0),h.default.register(Y,!0),h.default.register(st,!0),h.default.register(nt,!0)}destroy(){var e,n,s;this.destroyed=!0,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.quill.off("text-change",this.textChangeRenumber),this.quill.off("text-change",this.lockedRevertHandler);const t=this.quill.root;t.removeEventListener("beforeinput",this.beforeInputHandler,!0),t.removeEventListener("paste",this.pasteHandler,!0),t.removeEventListener("cut",this.cutHandler,!0),(e=this.ghostCut)==null||e.destroy(),this.ghostCut=null,(n=this.dragOrganizer)==null||n.destroy(),this.dragOrganizer=null,(s=this.floatingBar)==null||s.remove(),this.floatingBar=null;for(const i of t.querySelectorAll(".ql-clausula-actions"))i.remove()}enhanceToolbar(t){const e=t.container;if(!e)return;const n=e.querySelector(".ql-clausula");n&&n.setAttribute("title","Tipo de cláusula (ou digite: cl, par, inc, al + Espaço)");const s=e.querySelector(".ql-picker.ql-parte");s&&s.setAttribute("title","Partes do contrato (ou digite: contratante, contratado + Espaço)");const i=e.querySelector(".ql-objeto");i&&i.setAttribute("title","Inserir OBJETO do contrato (ou digite: objeto + Espaço)");const o=e.querySelector(".ql-assinatura");o&&o.setAttribute("title","Inserir bloco de assinaturas")}prependBinding(t,e,n){t.bindings[e]=t.bindings[e]||[],t.bindings[e].unshift(n)}removeClausulaFormat(){this.quill.format("clausula",!1,g.USER)}removeParteFormat(){this.quill.format("parte",!1,g.USER)}removeObjetoFormat(){this.quill.format("objeto",!1,g.USER)}addKeyboardBindings(){const t=this.quill.getModule("keyboard"),e=this;this.prependBinding(t,"Enter",{key:"Enter",collapsed:!0,empty:!0,format:["clausula"],handler(){return e.removeClausulaFormat(),!1}}),this.prependBinding(t,"Backspace",{key:"Backspace",collapsed:!0,offset:0,format:["clausula"],shiftKey:null,metaKey:null,ctrlKey:null,altKey:null,handler(){return e.removeClausulaFormat(),!1}}),this.prependBinding(t,"Delete",{key:"Delete",collapsed:!0,empty:!0,format:["clausula"],shiftKey:null,metaKey:null,ctrlKey:null,altKey:null,handler(){return e.removeClausulaFormat(),!1}}),this.prependBinding(t,"Tab",{key:"Tab",format:["clausula"],handler(n,s){if(s.collapsed&&s.offset!==0)return!0;const i=s.format.clausula,o=T.indexOf(i);return o<T.length-1&&e.quill.format("clausula",T[o+1],g.USER),!1}}),this.prependBinding(t,"Tab",{key:"Tab",shiftKey:!0,format:["clausula"],handler(n,s){if(s.collapsed&&s.offset!==0)return!0;const i=s.format.clausula,o=T.indexOf(i);return o>0?e.quill.format("clausula",T[o-1],g.USER):e.removeClausulaFormat(),!1}}),this.prependBinding(t,"Enter",{key:"Enter",collapsed:!0,empty:!0,format:["parte"],handler(){return e.removeParteFormat(),!1}}),this.prependBinding(t,"Backspace",{key:"Backspace",collapsed:!0,offset:0,format:["parte"],shiftKey:null,metaKey:null,ctrlKey:null,altKey:null,handler(){return e.removeParteFormat(),!1}}),this.prependBinding(t,"Tab",{key:"Tab",format:["parte"],handler(n,s){const o=s.format.parte==="contratante"?"contratado":"contratante";return e.quill.format("parte",o,g.USER),!1}}),this.prependBinding(t,"Enter",{key:"Enter",collapsed:!0,empty:!0,format:["objeto"],handler(){return e.removeObjetoFormat(),!1}}),this.prependBinding(t,"Backspace",{key:"Backspace",collapsed:!0,offset:0,format:["objeto"],shiftKey:null,metaKey:null,ctrlKey:null,altKey:null,handler(){return e.removeObjetoFormat(),!1}}),this.prependBinding(t,"Escape",{key:"Escape",handler(){return!(e.ghostCut&&e.ghostCut.cancel())}}),this.prependBinding(t," ",{key:" ",shiftKey:null,collapsed:!0,format:{"code-block":!1,blockquote:!1,table:!1,clausula:!1,parte:!1,objeto:!1},prefix:dt,handler(n,s){const i=s.prefix,o=ht(i),l=ft(i);if(!o&&!l)return!0;const c=o?"clausula":l.format,a=o||l.value,{length:u}=i,[d,f]=e.quill.getLine(n.index);if(f>u)return!0;e.quill.insertText(n.index," ",g.USER),e.quill.history.cutoff();const p=new(e.quill.constructor.import("delta"))().retain(n.index-f).delete(u+1).retain(d.length()-2-f).retain(1,{[c]:a});return e.quill.updateContents(p,g.USER),e.quill.history.cutoff(),e.quill.setSelection(n.index-u,g.SILENT),!1}})}addLockedLinePrevention(){const t=this.quill.root;t.addEventListener("beforeinput",this.beforeInputHandler,!0),t.addEventListener("paste",this.pasteHandler,!0),t.addEventListener("cut",this.cutHandler,!0),this.quill.on("text-change",this.lockedRevertHandler)}isRangeLocked(t,e){return this.quill.getLines(t,Math.max(e,1)).some(s=>{var i;return(i=s==null?void 0:s.domNode)==null?void 0:i.classList.contains("ql-locked-true")})}isSelectionOnLockedLine(){const t=this.quill.getSelection();return t?this.isRangeLocked(t.index,t.length):!1}doesDeltaTouchLockedLine(t,e){var c;const n=[];let s=0,i=0;for(const a of e.ops)if(typeof a.insert=="string"){let u=0,d=a.insert.indexOf(`
19
+ `);for(;d!==-1;){const f=s+d;n.push({start:i,end:f,locked:((c=a.attributes)==null?void 0:c.locked)==="true"}),i=f+1,u=d+1,d=a.insert.indexOf(`
20
+ `,u)}s+=a.insert.length}else a.insert&&(s+=1);const o=(a,u)=>n.some(d=>d.locked&&a<=d.end&&u>=d.start);let l=0;for(const a of t.ops)if(a.retain&&!a.attributes)l+=a.retain;else if(a.delete){if(o(l,l+a.delete-1))return!0;l+=a.delete}else if(a.retain&&a.attributes){if(o(l,l+a.retain-1))return!0;l+=a.retain}else if(a.insert&&o(l,l))return!0;return!1}initFloatingBar(){const t=this.quill.root.ownerDocument,e=this.quill.container;this.floatingBar=xt(t,{onUndo:()=>this.handleGlobalUndo(),onAgreeAll:()=>this.handleGlobalAgree(),onDisagreeAll:()=>this.handleGlobalDisagree(),onLockAll:()=>this.handleGlobalLock(),onJudge:()=>{var n,s;return(s=(n=this.options).onJudge)==null?void 0:s.call(n)},onShare:()=>{var n,s;return(s=(n=this.options).onShare)==null?void 0:s.call(n)},onSign:()=>{var n,s;return(s=(n=this.options).onSign)==null?void 0:s.call(n)}}),e.appendChild(this.floatingBar)}getAllItems(){const t=this.quill.scroll.descendants(b),e=[];for(const n of t){if(!n.children)continue;let s=n.children.head;for(;s;)e.push(s),s=s.next}return e}getAllParteItems(){const t=this.quill.scroll.descendants(A),e=[];for(const n of t){if(!n.children)continue;let s=n.children.head;for(;s;)e.push(s),s=s.next}return e}getAllObjetoItems(){const t=this.quill.scroll.descendants(v),e=[];for(const n of t){if(!n.children)continue;let s=n.children.head;for(;s;)e.push(s),s=s.next}return e}handleGlobalUndo(){const t=this.quill.root.ownerDocument;if(t.querySelector(".ql-clausula-modal-overlay"))return;const e=Lt(t,()=>{const n=this.getAllItems();for(const s of n){const i=this.quill.getIndex(s);this.quill.formatLine(i,1,"locked",!1,g.API),this.quill.formatLine(i,1,"agreed",!1,g.API)}this.scheduleRenumber()},()=>{});t.body.appendChild(e)}handleGlobalAgree(){const t=this.options.currentUser;if(!t)return;const e=this.getAllItems();for(const n of e)n.domNode.classList.contains("ql-locked-true")||this.isParentWithChildren(n,e)||this.setAgreed(n,t,!0);this.scheduleRenumber()}handleGlobalDisagree(){const t=this.options.currentUser;if(!t)return;const e=this.getAllItems();for(const n of e)n.domNode.classList.contains("ql-locked-true")||this.isParentWithChildren(n,e)||this.setAgreed(n,t,!1);this.scheduleRenumber()}handleGlobalLock(){const t=this.getAllItems(),n=t.some(s=>!s.domNode.classList.contains("ql-locked-true"))?"true":!1;for(const s of t){const i=this.quill.getIndex(s);this.quill.formatLine(i,1,"locked",n,g.API)}this.scheduleRenumber()}syncFloatingBar(){if(!this.floatingBar)return;const t=this.floatingBar.querySelector(".ql-floating-sign");if(!t)return;const n=this.getAllItems().map(o=>o.domNode),s=this.options.users||(this.options.currentUser?[this.options.currentUser]:[]),i=qt(n,s);t.disabled=!i,t.classList.toggle("ready",i)}scheduleRenumber(){this.renumberScheduled||this.destroyed||(this.renumberScheduled=!0,this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.renumberScheduled=!1,!this.destroyed&&(this.renumber(),this.renumberPartes(),this.enforceSingletonObjeto(),this.syncAssinatura())}))}exportMarkdown(){return bt(this.quill.getContents(),this.options)}exportHTML(){return At(this.quill.getContents(),this.options)}renumber(){const t=this.quill.scroll.descendants(b),e=[];for(const s of t){if(!s.children)continue;let i=s.children.head;for(;i;)e.push(i),i=i.next}const n=at(e);e.forEach((s,i)=>{const o=n[i];if(!o)return;const l=M(o,this.options),c=s.domNode.querySelector(".ql-ui");c&&c.textContent!==l&&(c.textContent=l)}),this.options.showActions!==!1&&this.updateActions(e),this.syncFloatingBar()}renumberPartes(){const t=this.getAllParteItems();if(t.length===0)return;const e=ct(t);t.forEach((n,s)=>{const i=e[s];if(!i)return;const o=j(i),l=n.domNode.querySelector(".ql-ui");l&&l.textContent!==o&&(l.textContent=o)})}enforceSingletonObjeto(){const t=this.getAllObjetoItems();if(t.length>1)for(let e=1;e<t.length;e++){const n=this.quill.getIndex(t[e]);this.quill.formatLine(n,1,"objeto",!1,g.API)}this.syncObjetoButton(t.length>0)}syncObjetoButton(t){const e=this.quill.getModule("toolbar");if(!e||!e.container)return;const n=e.container.querySelector(".ql-objeto");n&&n.classList.toggle("ql-active",t)}syncAssinatura(){const t=this.quill.scroll.descendants(q);if(t.length===0)return;const e=this.getAllParteItems(),n=ut(e);for(const s of t){const i=q.value(s.domNode),o=F(n,i);s.domNode.innerHTML!==o&&(s.domNode.innerHTML=o)}}updateActions(t){const e=this.quill.root.ownerDocument;for(const n of t){const s=n.domNode;let i=s.querySelector(".ql-clausula-actions");i||(i=vt(e),s.appendChild(i),n.actionsNode=i,i.addEventListener("mousedown",a=>{a.preventDefault();const u=a.target.closest(".ql-clausula-btn");if(!u)return;const d=this.getAllItems();d.includes(n)&&(u.classList.contains("ql-clausula-lock")?this.handleLock(n,d):u.classList.contains("ql-clausula-agree")?!u.hasAttribute("disabled")&&!u.disabled&&this.handleAgree(n,d):u.classList.contains("ql-clausula-disagree")?!u.hasAttribute("disabled")&&!u.disabled&&this.handleDisagree(n,d):u.classList.contains("ql-clausula-conversation")&&this.handleConversation(n))}));const o=s.getAttribute("data-clausula-type"),c=(o?y[o]===0:!1)?this.getChildren(n,t).map(a=>a.domNode):void 0;kt(i,s,this.options.currentUser,this.options.users,c)}}handleLock(t,e){const n=t.domNode,s=n.getAttribute("data-clausula-type"),i=s?y[s]===0:!1,l=n.classList.contains("ql-locked-true")?!1:"true",c=this.quill.getIndex(t);if(this.quill.formatLine(c,1,"locked",l,g.API),i){const a=this.getChildren(t,e);for(const u of a){const d=this.quill.getIndex(u);this.quill.formatLine(d,1,"locked",l,g.API)}}this.scheduleRenumber()}handleAgree(t,e){const n=this.options.currentUser;if(!n)return;const i=t.domNode.getAttribute("data-clausula-type"),l=(i?y[i]===0:!1)?this.getChildren(t,e):[];if(l.length>0)for(const c of l)this.setAgreed(c,n,!0);else this.setAgreed(t,n,!0);this.scheduleRenumber()}handleDisagree(t,e){const n=this.options.currentUser;if(!n)return;const i=t.domNode.getAttribute("data-clausula-type"),l=(i?y[i]===0:!1)?this.getChildren(t,e):[];if(l.length>0)for(const c of l)this.setAgreed(c,n,!1);else this.setAgreed(t,n,!1);this.scheduleRenumber()}handleConversation(t){var c;const e=this.options.onConversation;if(!e)return;const n=t.domNode,s=n.getAttribute("data-clausula-type"),i=n.querySelector(".ql-ui"),o=((c=n.textContent)==null?void 0:c.replace((i==null?void 0:i.textContent)||"","").trim())||"",l={type:s,text:o,domNode:n,currentUser:this.options.currentUser};e(l)}setAgreed(t,e,n){const i=t.domNode.getAttribute("data-agreed");let o={};if(i)try{o=JSON.parse(i)}catch{o={}}o[e]=n;const l=this.quill.getIndex(t),c=Object.keys(o).length>0?o:!1;this.quill.formatLine(l,1,"agreed",c,g.API)}getClausulaBlocks(){const t=[];let e=null;for(const n of this.getAllItems()){const s=n.domNode.getAttribute("data-clausula-type");s&&y[s]===0?(e={items:[n]},t.push(e)):e&&e.items.push(n)}return t}moveClausulaBlock(t,e){const n=this.getClausulaBlocks(),s=n[t];if(!s)return;const i=s.items[0],o=s.items[s.items.length-1],l=this.quill.getIndex(i),c=this.quill.getIndex(o)+o.length()-l;let a;if(e<n.length)a=this.quill.getIndex(n[e].items[0]);else{const p=n[n.length-1],m=p.items[p.items.length-1];a=this.quill.getIndex(m)+m.length()}if(a>=l&&a<=l+c)return;const u=this.quill.getContents(l,c),d=u.ops.some(p=>{var m;return((m=p.attributes)==null?void 0:m.locked)==="true"}),f=P(l,c,a,u.ops);this.quill.updateContents({ops:f},d?g.API:g.USER),this.scheduleRenumber()}isParentWithChildren(t,e){const n=t.domNode.getAttribute("data-clausula-type");return(n?y[n]===0:!1)&&this.getChildren(t,e).length>0}getChildren(t,e){const n=e.indexOf(t);if(n===-1)return[];const s=[];for(let i=n+1;i<e.length;i++){const l=e[i].domNode.getAttribute("data-clausula-type");if(l&&y[l]===0)break;s.push(e[i])}return s}};V.DEFAULTS={...J};let O=V;const Ee=/^(?:#{1,6}\s*)?(?:\*\*)?CL[AÁ]USULA\s+[^\s—–:-]+\s*[ª°º]?\s*(?:[—–:-]+\s*)?(?:\*\*)?\s*(.*)$/i,Te=/^(?:\*\*)?(\d+)\.(\d+)(?:\*\*)?[.)]?\s+(.*)$/,Ie=/^(?:\*\*)?§\s*\d*º?\.?(?:\*\*)?\s+(.*)$/,Re=/^(?:\*\*)?PAR[AÁ]GRAFO\s+(?:[ÚU]NICO|PRIMEIRO|SEGUNDO|TERCEIRO|QUARTO|QUINTO|SEXTO|S[ÉE]TIMO|OITAVO|NONO|D[ÉE]CIMO(?:\s+\w+)?|\d+º?)\s*[.:—–-]?(?:\*\*)?\s*(.*)$/i,we=/^([IVXLCDM]+|[ivxlcdm]+)\s*[—–-]\s+(.*)$/,$e=/^([a-z])\\?\)\s+(.*)$/,Oe=/^(?:\*\*)?(CONTRATANTE|CONTRATADO|CONTRATADA)S?\s*:?(?:\*\*)?:?\s*(.*)$/i,Be=/^(?:\*\*)?OBJETO\s*:?(?:\*\*)?:?\s*(.*)$/i,_e=/^#{1,6}\s+(.*)$/;function Pe(r){let t=r.match(Ee);return t?{attributes:{clausula:"clausula"},rest:t[1]}:(t=r.match(Te),t?{attributes:{clausula:"subclausula"},rest:t[3]}:(t=r.match(Ie)||r.match(Re),t?{attributes:{clausula:"paragrafo"},rest:t[1]}:(t=r.match(we),t?{attributes:{clausula:"inciso"},rest:t[2]}:(t=r.match($e),t?{attributes:{clausula:"alinea"},rest:t[2]}:(t=r.match(Oe),t?{attributes:{parte:t[1].toUpperCase()==="CONTRATANTE"?"contratante":"contratado"},rest:t[2]}:(t=r.match(Be),t?{attributes:{objeto:"true"},rest:t[1]}:null))))))}function R(r){const t=[],e=/(\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*|_([^_\s][^_]*)_)/g;let n=0,s;for(;(s=e.exec(r))!==null;)s.index>n&&t.push({insert:r.slice(n,s.index)}),s[2]!==void 0?t.push({insert:s[2],attributes:{bold:!0}}):t.push({insert:s[3]??s[4],attributes:{italic:!0}}),n=s.index+s[0].length;return n<r.length&&t.push({insert:r.slice(n)}),t.filter(i=>i.insert.length>0)}function De(r){const t=r.match(/^---\n[\s\S]*?\n---\n?/);return t?r.slice(t[0].length):r}function Ue(r){const t=[],e=De(r).split(`
21
+ `);for(const n of e){const s=n.trim();if(!s||/^[-*_]{3,}$/.test(s))continue;const i=Pe(s);if(i){const l=i.rest.trim();t.push(...R(l)),t.push({insert:`
22
+ `,attributes:i.attributes});continue}const o=s.match(_e);if(o){const l=R(o[1].trim());for(const c of l)c.attributes={...c.attributes,bold:!0};t.push(...l),t.push({insert:`
23
+ `});continue}t.push(...R(s)),t.push({insert:`
24
+ `})}return t.length===0&&t.push({insert:`
25
+ `}),{ops:t}}function Me(){h.default.register("modules/clausula",O)}exports.AUTOFILL_PREFIX=dt;exports.AgreedAttribute=X;exports.AssinaturaEmbed=q;exports.ClausulaContainer=b;exports.ClausulaItem=C;exports.ClausulaModule=O;exports.DragOrganizer=ot;exports.GhostAttribute=Y;exports.GhostCut=it;exports.LINE_HEIGHTS=tt;exports.LineHeightAttribute=st;exports.LockedAttribute=z;exports.ObjetoContainer=v;exports.ObjetoItem=S;exports.PARAGRAPH_SPACINGS=et;exports.ParagraphSpacingAttribute=nt;exports.ParteContainer=A;exports.ParteItem=N;exports.buildMoveOps=P;exports.computeIndices=at;exports.computeIndicesFromTypes=D;exports.computeParteIndices=ct;exports.computeParteIndicesFromTypes=H;exports.createActionButtons=vt;exports.createFloatingBar=xt;exports.createUndoModal=Lt;exports.exportHTML=At;exports.exportMarkdown=bt;exports.extractSignatureLines=ut;exports.findGhostRange=rt;exports.formatLabel=M;exports.formatParteLabel=j;exports.importMarkdown=Ue;exports.isContractFullyAgreed=qt;exports.matchExtraTrigger=ft;exports.matchTrigger=ht;exports.parseDeltaToLines=G;exports.parseInline=R;exports.register=Me;exports.renderAssinatura=F;exports.syncButtonState=kt;exports.toExtenso=B;exports.toExtensoUpper=U;exports.toRoman=w;exports.toRomanLower=lt;