superdoc 2.4.0-next.13 β 2.4.0-next.15
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-cdn/superdoc.min.js
CHANGED
|
@@ -99,10 +99,10 @@ js: import "konva/skia-backend";
|
|
|
99
99
|
`,k_=()=>{if(typeof document>"u")throw new Error(RD)},zi=class oI{constructor(t=[1,0,0,1,0,0]){this.dirty=!1,this.m=t&&t.slice()||[1,0,0,1,0,0]}reset(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}copy(){return new oI(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const n=this.m;return{x:n[0]*t.x+n[2]*t.y+n[4],y:n[1]*t.x+n[3]*t.y+n[5]}}translate(t,n){return this.m[4]+=this.m[0]*t+this.m[2]*n,this.m[5]+=this.m[1]*t+this.m[3]*n,this}scale(t,n){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=n,this.m[3]*=n,this}rotate(t){const n=Math.cos(t),r=Math.sin(t),o=this.m[0]*n+this.m[2]*r,i=this.m[1]*n+this.m[3]*r,s=this.m[0]*-r+this.m[2]*n,a=this.m[1]*-r+this.m[3]*n;return this.m[0]=o,this.m[1]=i,this.m[2]=s,this.m[3]=a,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,n){const r=this.m[0]+this.m[2]*n,o=this.m[1]+this.m[3]*n,i=this.m[2]+this.m[0]*t,s=this.m[3]+this.m[1]*t;return this.m[0]=r,this.m[1]=o,this.m[2]=i,this.m[3]=s,this}multiply(t){const n=this.m[0]*t.m[0]+this.m[2]*t.m[1],r=this.m[1]*t.m[0]+this.m[3]*t.m[1],o=this.m[0]*t.m[2]+this.m[2]*t.m[3],i=this.m[1]*t.m[2]+this.m[3]*t.m[3],s=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=n,this.m[1]=r,this.m[2]=o,this.m[3]=i,this.m[4]=s,this.m[5]=a,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),n=this.m[3]*t,r=-this.m[1]*t,o=-this.m[2]*t,i=this.m[0]*t,s=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=n,this.m[1]=r,this.m[2]=o,this.m[3]=i,this.m[4]=s,this.m[5]=a,this}getMatrix(){return this.m}decompose(){const t=this.m[0],n=this.m[1],r=this.m[2],o=this.m[3],i=this.m[4],s=this.m[5],a=t*o-n*r,l={x:i,y:s,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||n!=0){const c=Math.sqrt(t*t+n*n);l.rotation=n>0?Math.acos(t/c):-Math.acos(t/c),l.scaleX=c,l.scaleY=a/c,l.skewX=(t*r+n*o)/a,l.skewY=0}else if(r!=0||o!=0){const c=Math.sqrt(r*r+o*o);l.rotation=Math.PI/2-(o>0?Math.acos(-r/c):-Math.acos(r/c)),l.scaleX=a/c,l.scaleY=c,l.skewX=0,l.skewY=(t*r+n*o)/a}return l.rotation=xe._getRotation(l.rotation),l}},MD="[object Array]",LD="[object Number]",PD="[object String]",DD="[object Boolean]",OD=Math.PI/180,FD=180/Math.PI,yf="#",ND="",BD="0",zD="Konva warning: ",S_="Konva error: ",VD="rgb(",A0={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},jD=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,Gp=[],bf=null,UD=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(e){setTimeout(e,16)},xe={_isElement(e){return!!(e&&e.nodeType==1)},_isFunction(e){return!!(e&&e.constructor&&e.call&&e.apply)},_isPlainObject(e){return!!e&&e.constructor===Object},_isArray(e){return Object.prototype.toString.call(e)===MD},_isNumber(e){return Object.prototype.toString.call(e)===LD&&!isNaN(e)&&isFinite(e)},_isString(e){return Object.prototype.toString.call(e)===PD},_isBoolean(e){return Object.prototype.toString.call(e)===DD},isObject(e){return e instanceof Object},isValidSelector(e){if(typeof e!="string")return!1;const t=e[0];return t==="#"||t==="."||t===t.toUpperCase()},_sign(e){return e===0||e>0?1:-1},requestAnimFrame(e){Gp.push(e),Gp.length===1&&UD(function(){const t=Gp;Gp=[],t.forEach(function(n){n()})})},createCanvasElement(){k_();const e=document.createElement("canvas");try{e.style=e.style||{}}catch{}return e},createImageElement(){return k_(),document.createElement("img")},_isInDocument(e){for(;e=e.parentNode;)if(e==document)return!0;return!1},_urlToImage(e,t){const n=xe.createImageElement();n.onload=function(){t(n)},n.src=e},_rgbToHex(e,t,n){return((1<<24)+(e<<16)+(t<<8)+n).toString(16).slice(1)},_hexToRgb(e){e=e.replace(yf,ND);const t=parseInt(e,16);return{r:t>>16&255,g:t>>8&255,b:t&255}},getRandomColor(){let e=(Math.random()*16777215<<0).toString(16);for(;e.length<6;)e=BD+e;return yf+e},isCanvasFarblingActive(){if(bf!==null)return bf;if(typeof document>"u")return bf=!1,!1;const e=this.createCanvasElement();e.width=10,e.height=10;const t=e.getContext("2d",{willReadFrequently:!0});t.clearRect(0,0,10,10),t.fillStyle="#282828",t.fillRect(0,0,10,10);const n=t.getImageData(0,0,10,10).data;let r=!1;for(let o=0;o<100;o++)if(n[o*4]!==40||n[o*4+1]!==40||n[o*4+2]!==40||n[o*4+3]!==255){r=!0;break}return bf=r,this.releaseCanvas(e),bf},getHitColor(){const e=this.getRandomColor();return this.isCanvasFarblingActive()?this.getSnappedHexColor(e):e},getHitColorKey(e,t,n){return this.isCanvasFarblingActive()&&(e=Math.round(e/5)*5,t=Math.round(t/5)*5,n=Math.round(n/5)*5),yf+this._rgbToHex(e,t,n)},getSnappedHexColor(e){const t=this._hexToRgb(e);return yf+this._rgbToHex(Math.round(t.r/5)*5,Math.round(t.g/5)*5,Math.round(t.b/5)*5)},getRGB(e){let t;return e in A0?(t=A0[e],{r:t[0],g:t[1],b:t[2]}):e[0]===yf?this._hexToRgb(e.substring(1)):e.substr(0,4)===VD?(t=jD.exec(e.replace(/ /g,"")),{r:parseInt(t[1],10),g:parseInt(t[2],10),b:parseInt(t[3],10)}):{r:0,g:0,b:0}},colorToRGBA(e){return e=e||"black",xe._namedColorToRBA(e)||xe._hex3ColorToRGBA(e)||xe._hex4ColorToRGBA(e)||xe._hex6ColorToRGBA(e)||xe._hex8ColorToRGBA(e)||xe._rgbColorToRGBA(e)||xe._rgbaColorToRGBA(e)||xe._hslColorToRGBA(e)},_namedColorToRBA(e){const t=A0[e.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(e){if(e.indexOf("rgb(")===0){e=e.match(/rgb\(([^)]+)\)/)[1];const t=e.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(e){if(e.indexOf("rgba(")===0){e=e.match(/rgba\(([^)]+)\)/)[1];const t=e.split(/ *, */).map((n,r)=>n.slice(-1)==="%"?r===3?parseInt(n)/100:parseInt(n)/100*255:Number(n));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(e){if(e[0]==="#"&&e.length===9)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:parseInt(e.slice(7,9),16)/255}},_hex6ColorToRGBA(e){if(e[0]==="#"&&e.length===7)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:1}},_hex4ColorToRGBA(e){if(e[0]==="#"&&e.length===5)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:parseInt(e[4]+e[4],16)/255}},_hex3ColorToRGBA(e){if(e[0]==="#"&&e.length===4)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:1}},_hslColorToRGBA(e){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(e)){const[t,...n]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(e),r=Number(n[0])/360,o=Number(n[1])/100,i=Number(n[2])/100;let s,a,l;if(o===0)return l=i*255,{r:Math.round(l),g:Math.round(l),b:Math.round(l),a:1};i<.5?s=i*(1+o):s=i+o-i*o;const c=2*i-s,u=[0,0,0];for(let d=0;d<3;d++)a=r+1/3*-(d-1),a<0&&a++,a>1&&a--,6*a<1?l=c+(s-c)*6*a:2*a<1?l=s:3*a<2?l=c+(s-c)*(2/3-a)*6:l=c,u[d]=l*255;return{r:Math.round(u[0]),g:Math.round(u[1]),b:Math.round(u[2]),a:1}}},haveIntersection(e,t){return!(t.x>e.x+e.width||t.x+t.width<e.x||t.y>e.y+e.height||t.y+t.height<e.y)},cloneObject(e){const t={};for(const n in e)this._isPlainObject(e[n])?t[n]=this.cloneObject(e[n]):this._isArray(e[n])?t[n]=this.cloneArray(e[n]):t[n]=e[n];return t},cloneArray(e){return e.slice(0)},degToRad(e){return e*OD},radToDeg(e){return e*FD},_degToRad(e){return xe.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),xe.degToRad(e)},_radToDeg(e){return xe.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),xe.radToDeg(e)},_getRotation(e){return wt.angleDeg?xe.radToDeg(e):e},_capitalize(e){return e.charAt(0).toUpperCase()+e.slice(1)},throw(e){throw new Error(S_+e)},error(e){console.error(S_+e)},warn(e){wt.showWarnings&&console.warn(zD+e)},each(e,t){for(const n in e)t(n,e[n])},_inRange(e,t,n){return t<=e&&e<n},_getProjectionToSegment(e,t,n,r,o,i){let s,a,l;const c=(e-n)*(e-n)+(t-r)*(t-r);if(c==0)s=e,a=t,l=(o-n)*(o-n)+(i-r)*(i-r);else{const u=((o-e)*(n-e)+(i-t)*(r-t))/c;u<0?(s=e,a=t,l=(e-o)*(e-o)+(t-i)*(t-i)):u>1?(s=n,a=r,l=(n-o)*(n-o)+(r-i)*(r-i)):(s=e+u*(n-e),a=t+u*(r-t),l=(s-o)*(s-o)+(a-i)*(a-i))}return[s,a,l]},_getProjectionToLine(e,t,n){const r=xe.cloneObject(e);let o=Number.MAX_VALUE;return t.forEach(function(i,s){if(!n&&s===t.length-1)return;const a=t[(s+1)%t.length],l=xe._getProjectionToSegment(i.x,i.y,a.x,a.y,e.x,e.y),c=l[0],u=l[1],d=l[2];d<o&&(r.x=c,r.y=u,o=d)}),r},_prepareArrayForTween(e,t,n){const r=[],o=[];if(e.length>t.length){const s=t;t=e,e=s}for(let s=0;s<e.length;s+=2)r.push({x:e[s],y:e[s+1]});for(let s=0;s<t.length;s+=2)o.push({x:t[s],y:t[s+1]});const i=[];return o.forEach(function(s){const a=xe._getProjectionToLine(s,r,n);i.push(a.x),i.push(a.y)}),i},_prepareToStringify(e){let t;e.visitedByCircularReferenceRemoval=!0;for(const n in e)if(e.hasOwnProperty(n)&&e[n]&&typeof e[n]=="object"){if(t=Object.getOwnPropertyDescriptor(e,n),e[n].visitedByCircularReferenceRemoval||xe._isElement(e[n]))if(t.configurable)delete e[n];else return null;else if(xe._prepareToStringify(e[n])===null)if(t.configurable)delete e[n];else return null}return delete e.visitedByCircularReferenceRemoval,e},_assign(e,t){for(const n in t)e[n]=t[n];return e},_getFirstPointerId(e){return e.touches?e.changedTouches[0].identifier:e.pointerId||999},releaseCanvas(...e){wt.releaseCanvasOnDestroy&&e.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(e,t,n,r){let o=t<0?t:0,i=n<0?n:0;t=Math.abs(t),n=Math.abs(n);let s=0,a=0,l=0,c=0;typeof r=="number"?s=a=l=c=Math.min(r,t/2,n/2):(s=Math.min(r[0]||0,t/2,n/2),a=Math.min(r[1]||0,t/2,n/2),c=Math.min(r[2]||0,t/2,n/2),l=Math.min(r[3]||0,t/2,n/2)),e.moveTo(o+s,i),e.lineTo(o+t-a,i),e.arc(o+t-a,i+a,a,Math.PI*3/2,0,!1),e.lineTo(o+t,i+n-c),e.arc(o+t-c,i+n-c,c,0,Math.PI/2,!1),e.lineTo(o+l,i+n),e.arc(o+l,i+n-l,l,Math.PI/2,Math.PI,!1),e.lineTo(o,i+s),e.arc(o+s,i+s,s,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(e,t,n,r,o){r=Math.abs(r);for(let i=0;i<n;i++){const s=t[(i-1+n)%n],a=t[i],l=t[(i+1)%n],c={x:a.x-s.x,y:a.y-s.y},u={x:l.x-a.x,y:l.y-a.y},d=Math.hypot(c.x,c.y),h=Math.hypot(u.x,u.y);let g;typeof o=="number"?g=o:g=i<o.length?o[i]:0,g=r*Math.cos(Math.PI/n)*Math.min(1,g/r*2);const p={x:c.x/d,y:c.y/d},v={x:u.x/h,y:u.y/h},k={x:a.x-p.x*g,y:a.y-p.y*g},C={x:a.x+v.x*g,y:a.y+v.y*g};i===0?e.moveTo(k.x,k.y):e.lineTo(k.x,k.y),e.arcTo(a.x,a.y,C.x,C.y,g)}}};function HD(e){const t=[],n=e.length,r=xe;for(let o=0;o<n;o++){let i=e[o];r._isNumber(i)?i=Math.round(i*1e3)/1e3:r._isString(i)||(i=i+""),t.push(i)}return t}var __=",",$D="(",GD=")",WD="([",KD="])",qD=";",YD="()",XD="=",A_=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","roundRect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],ZD=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],QD=100,Wp=null;function I_(){if(Wp!==null)return Wp;try{const e=xe.createCanvasElement().getContext("2d");return e?!!e&&"filter"in e:(Wp=!1,!1)}catch{return Wp=!1,!1}}var Kp=class{constructor(e){this.canvas=e,wt.enableTrace&&(this.traceArr=[],this._enableTrace())}fillShape(e){e.fillEnabled()&&this._fill(e)}_fill(e){}strokeShape(e){e.hasStroke()&&this._stroke(e)}_stroke(e){}fillStrokeShape(e){e.attrs.fillAfterStrokeEnabled?(this.strokeShape(e),this.fillShape(e)):(this.fillShape(e),this.strokeShape(e))}getTrace(e,t){let n=this.traceArr,r=n.length,o="",i,s,a,l;for(i=0;i<r;i++)s=n[i],a=s.method,a?(l=s.args,o+=a,e?o+=YD:xe._isArray(l[0])?o+=WD+l.join(__)+KD:(t&&(l=l.map(c=>typeof c=="number"?Math.floor(c):c)),o+=$D+l.join(__)+GD)):(o+=s.property,e||(o+=XD+s.val)),o+=qD;return o}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,n;t.push(e),n=t.length,n>=QD&&t.shift()}reset(){const e=this.getCanvas().getPixelRatio();this.setTransform(1*e,0,0,1*e,0,0)}getCanvas(){return this.canvas}clear(e){const t=this.getCanvas();e?this.clearRect(e.x||0,e.y||0,e.width||0,e.height||0):this.clearRect(0,0,t.getWidth()/t.pixelRatio,t.getHeight()/t.pixelRatio)}_applyLineCap(e){const t=e.attrs.lineCap;t&&this.setAttr("lineCap",t)}_applyOpacity(e){const t=e.getAbsoluteOpacity();t!==1&&this.setAttr("globalAlpha",t)}_applyLineJoin(e){const t=e.attrs.lineJoin;t&&this.setAttr("lineJoin",t)}_applyMiterLimit(e){const t=e.attrs.miterLimit;t!=null&&this.setAttr("miterLimit",t)}setAttr(e,t){this._context[e]=t}arc(e,t,n,r,o,i){this._context.arc(e,t,n,r,o,i)}arcTo(e,t,n,r,o){this._context.arcTo(e,t,n,r,o)}beginPath(){this._context.beginPath()}bezierCurveTo(e,t,n,r,o,i){this._context.bezierCurveTo(e,t,n,r,o,i)}clearRect(e,t,n,r){this._context.clearRect(e,t,n,r)}clip(...e){this._context.clip.apply(this._context,e)}closePath(){this._context.closePath()}createImageData(e,t){const n=arguments;if(n.length===2)return this._context.createImageData(e,t);if(n.length===1)return this._context.createImageData(e)}createLinearGradient(e,t,n,r){return this._context.createLinearGradient(e,t,n,r)}createPattern(e,t){return this._context.createPattern(e,t)}createRadialGradient(e,t,n,r,o,i){return this._context.createRadialGradient(e,t,n,r,o,i)}drawImage(e,t,n,r,o,i,s,a,l){const c=arguments,u=this._context;c.length===3?u.drawImage(e,t,n):c.length===5?u.drawImage(e,t,n,r,o):c.length===9&&u.drawImage(e,t,n,r,o,i,s,a,l)}ellipse(e,t,n,r,o,i,s,a){this._context.ellipse(e,t,n,r,o,i,s,a)}isPointInPath(e,t,n,r){return n?this._context.isPointInPath(n,e,t,r):this._context.isPointInPath(e,t,r)}fill(...e){this._context.fill.apply(this._context,e)}fillRect(e,t,n,r){this._context.fillRect(e,t,n,r)}strokeRect(e,t,n,r){this._context.strokeRect(e,t,n,r)}fillText(e,t,n,r){r?this._context.fillText(e,t,n,r):this._context.fillText(e,t,n)}measureText(e){return this._context.measureText(e)}getImageData(e,t,n,r){return this._context.getImageData(e,t,n,r)}lineTo(e,t){this._context.lineTo(e,t)}moveTo(e,t){this._context.moveTo(e,t)}rect(e,t,n,r){this._context.rect(e,t,n,r)}roundRect(e,t,n,r,o){this._context.roundRect(e,t,n,r,o)}putImageData(e,t,n){this._context.putImageData(e,t,n)}quadraticCurveTo(e,t,n,r){this._context.quadraticCurveTo(e,t,n,r)}restore(){this._context.restore()}rotate(e){this._context.rotate(e)}save(){this._context.save()}scale(e,t){this._context.scale(e,t)}setLineDash(e){this._context.setLineDash?this._context.setLineDash(e):"mozDash"in this._context?this._context.mozDash=e:"webkitLineDash"in this._context&&(this._context.webkitLineDash=e)}getLineDash(){return this._context.getLineDash()}setTransform(e,t,n,r,o,i){this._context.setTransform(e,t,n,r,o,i)}stroke(e){e?this._context.stroke(e):this._context.stroke()}strokeText(e,t,n,r){this._context.strokeText(e,t,n,r)}transform(e,t,n,r,o,i){this._context.transform(e,t,n,r,o,i)}translate(e,t){this._context.translate(e,t)}_enableTrace(){let e=this,t=A_.length,n=this.setAttr,r,o;const i=function(s){let a=e[s],l;e[s]=function(){return o=HD(Array.prototype.slice.call(arguments,0)),l=a.apply(e,arguments),e._trace({method:s,args:o}),l}};for(r=0;r<t;r++)i(A_[r]);e.setAttr=function(){n.apply(e,arguments);const s=arguments[0];let a=arguments[1];(s==="shadowOffsetX"||s==="shadowOffsetY"||s==="shadowBlur")&&(a=a/this.canvas.getPixelRatio()),e._trace({property:s,val:a})}}_applyGlobalCompositeOperation(e){const t=e.attrs.globalCompositeOperation;!t||t==="source-over"||this.setAttr("globalCompositeOperation",t)}};ZD.forEach(function(e){Object.defineProperty(Kp.prototype,e,{get(){return this._context[e]},set(t){this._context[e]=t}})});var JD=class extends Kp{constructor(e,{willReadFrequently:t=!1}={}){super(e),this._context=e._canvas.getContext("2d",{willReadFrequently:t})}_fillColor(e){const t=e.fill();this.setAttr("fillStyle",t),e._fillFunc(this)}_fillPattern(e){this.setAttr("fillStyle",e._getFillPattern()),e._fillFunc(this)}_fillLinearGradient(e){const t=e._getLinearGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fillRadialGradient(e){const t=e._getRadialGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fill(e){const t=e.fill(),n=e.getFillPriority();if(t&&n==="color"){this._fillColor(e);return}const r=e.getFillPatternImage();if(r&&n==="pattern"){this._fillPattern(e);return}const o=e.getFillLinearGradientColorStops();if(o&&n==="linear-gradient"){this._fillLinearGradient(e);return}const i=e.getFillRadialGradientColorStops();if(i&&n==="radial-gradient"){this._fillRadialGradient(e);return}t?this._fillColor(e):r?this._fillPattern(e):o?this._fillLinearGradient(e):i&&this._fillRadialGradient(e)}_strokeLinearGradient(e){const t=e.getStrokeLinearGradientStartPoint(),n=e.getStrokeLinearGradientEndPoint(),r=e.getStrokeLinearGradientColorStops(),o=this.createLinearGradient(t.x,t.y,n.x,n.y);if(r){for(let i=0;i<r.length;i+=2)o.addColorStop(r[i],r[i+1]);this.setAttr("strokeStyle",o)}}_stroke(e){const t=e.dash(),n=e.getStrokeScaleEnabled();if(e.hasStroke()){if(!n){this.save();const r=this.getCanvas().getPixelRatio();this.setTransform(r,0,0,r,0,0)}this._applyLineCap(e),t&&e.dashEnabled()&&(this.setLineDash(t),this.setAttr("lineDashOffset",e.dashOffset())),this.setAttr("lineWidth",e.strokeWidth()),e.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),e.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(e):this.setAttr("strokeStyle",e.stroke()),e._strokeFunc(this),n||this.restore()}}_applyShadow(e){var t,n,r;const o=(t=e.getShadowRGBA())!==null&&t!==void 0?t:"black",i=(n=e.getShadowBlur())!==null&&n!==void 0?n:5,s=(r=e.getShadowOffset())!==null&&r!==void 0?r:{x:0,y:0},a=e.getAbsoluteScale(),l=this.canvas.getPixelRatio(),c=a.x*l,u=a.y*l;this.setAttr("shadowColor",o),this.setAttr("shadowBlur",i*Math.min(Math.abs(c),Math.abs(u))),this.setAttr("shadowOffsetX",s.x*c),this.setAttr("shadowOffsetY",s.y*u)}},eO=class extends Kp{constructor(e){super(e),this._context=e._canvas.getContext("2d",{willReadFrequently:!0})}_fill(e){this.save(),this.setAttr("fillStyle",e.colorKey),e._fillFuncHit(this),this.restore()}strokeShape(e){e.hasHitStroke()&&this._stroke(e)}_stroke(e){if(e.hasHitStroke()){const t=e.getStrokeScaleEnabled();if(!t){this.save();const o=this.getCanvas().getPixelRatio();this.setTransform(o,0,0,o,0,0)}this._applyLineCap(e);const n=e.hitStrokeWidth(),r=n==="auto"?e.strokeWidth():n;this.setAttr("lineWidth",r),this.setAttr("strokeStyle",e.colorKey),e._strokeFuncHit(this),t||this.restore()}}},qp;function tO(){if(qp)return qp;const e=xe.createCanvasElement(),t=e.getContext("2d");return qp=(function(){return(wt._global.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)})(),xe.releaseCanvas(e),qp}var I0=class{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const t=(e||{}).pixelRatio||wt.pixelRatio||tO();this.pixelRatio=t,this._canvas=xe.createCanvasElement(),this._canvas.style.padding="0",this._canvas.style.margin="0",this._canvas.style.border="0",this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top="0",this._canvas.style.left="0"}getContext(){return this.context}getPixelRatio(){return this.pixelRatio}setPixelRatio(e){const t=this.pixelRatio;this.pixelRatio=e,this.setSize(this.getWidth()/t,this.getHeight()/t)}setWidth(e){this.width=this._canvas.width=e*this.pixelRatio,this._canvas.style.width=e+"px";const t=this.pixelRatio;this.getContext()._context.scale(t,t)}setHeight(e){this.height=this._canvas.height=e*this.pixelRatio,this._canvas.style.height=e+"px";const t=this.pixelRatio;this.getContext()._context.scale(t,t)}getWidth(){return this.width}getHeight(){return this.height}setSize(e,t){this.setWidth(e||0),this.setHeight(t||0)}toDataURL(e,t){try{return this._canvas.toDataURL(e,t)}catch{try{return this._canvas.toDataURL()}catch(r){return xe.error("Unable to get data URL. "+r.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},Xa=class extends I0{constructor(e={width:0,height:0,willReadFrequently:!1}){super(e),this.context=new JD(this,{willReadFrequently:e.willReadFrequently}),this.setSize(e.width,e.height)}},E0=class extends I0{constructor(e={width:0,height:0}){super(e),this.hitCanvas=!0,this.context=new eO(this),this.setSize(e.width,e.height)}},On={get isDragging(){let e=!1;return On._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(e=!0)}),e},justDragged:!1,get node(){let e;return On._dragElements.forEach(t=>{e=t.node}),e},_dragElements:new Map,_drag(e){const t=[];On._dragElements.forEach((n,r)=>{const{node:o}=n,i=o.getStage();i.setPointersPositions(e),n.pointerId===void 0&&(n.pointerId=xe._getFirstPointerId(e));const s=i._changedPointerPositions.find(a=>a.id===n.pointerId);if(s){if(n.dragStatus!=="dragging"){const a=o.dragDistance();if(Math.max(Math.abs(s.x-n.startPointerPos.x),Math.abs(s.y-n.startPointerPos.y))<a||(o.startDrag({evt:e}),!o.isDragging()))return}o._setDragPosition(e,n),t.push(o)}}),t.forEach(n=>{n.getStage()&&n.fire("dragmove",{type:"dragmove",target:n,evt:e},!0)})},_endDragBefore(e){const t=[];On._dragElements.forEach(n=>{const{node:r}=n,o=r.getStage();if(e&&o.setPointersPositions(e),!o._changedPointerPositions.find(s=>s.id===n.pointerId))return;(n.dragStatus==="dragging"||n.dragStatus==="stopped")&&(On.justDragged=!0,wt._mouseListenClick=!1,wt._touchListenClick=!1,wt._pointerListenClick=!1,n.dragStatus="stopped");const i=n.node.getLayer()||n.node instanceof wt.Stage&&n.node;i&&t.indexOf(i)===-1&&t.push(i)}),t.forEach(n=>{n.draw()})},_endDragAfter(e){On._dragElements.forEach((t,n)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:e},!0),t.dragStatus!=="dragging"&&On._dragElements.delete(n)})}};wt.isBrowser&&(window.addEventListener("mouseup",On._endDragBefore,!0),window.addEventListener("touchend",On._endDragBefore,!0),window.addEventListener("touchcancel",On._endDragBefore,!0),window.addEventListener("mousemove",On._drag),window.addEventListener("touchmove",On._drag),window.addEventListener("mouseup",On._endDragAfter,!1),window.addEventListener("touchend",On._endDragAfter,!1),window.addEventListener("touchcancel",On._endDragAfter,!1));function Za(e){return xe._isString(e)?'"'+e+'"':Object.prototype.toString.call(e)==="[object Number]"||xe._isBoolean(e)?e:Object.prototype.toString.call(e)}function E_(e){return e>255?255:e<0?0:Math.round(e)}function yt(){if(wt.isUnminified)return function(e,t){return xe._isNumber(e)||xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),e}}function Yp(e){if(wt.isUnminified)return function(t,n){let r=xe._isNumber(t),o=xe._isArray(t)&&t.length==e;return!r&&!o&&xe.warn(Za(t)+' is a not valid value for "'+n+'" attribute. The value should be a number or Array<number>('+e+")"),t}}function T0(){if(wt.isUnminified)return function(e,t){return xe._isNumber(e)||e==="auto"||xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),e}}function Vl(){if(wt.isUnminified)return function(e,t){return xe._isString(e)||xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),e}}function T_(){if(wt.isUnminified)return function(e,t){const n=xe._isString(e),r=Object.prototype.toString.call(e)==="[object CanvasGradient]"||e&&e.addColorStop;return n||r||xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),e}}function nO(){if(wt.isUnminified)return function(e,t){const n=Int8Array?Object.getPrototypeOf(Int8Array):null;return n&&e instanceof n||(xe._isArray(e)?e.forEach(function(r){xe._isNumber(r)||xe.warn('"'+t+'" attribute has non numeric element '+r+". Make sure that all elements are numbers.")}):xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a array of numbers.')),e}}function Vi(){if(wt.isUnminified)return function(e,t){return e===!0||e===!1||xe.warn(Za(e)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),e}}function rO(e){if(wt.isUnminified)return function(t,n){return t==null||xe.isObject(t)||xe.warn(Za(t)+' is a not valid value for "'+n+'" attribute. The value should be an object with properties '+e),t}}var wf="get",Cf="set",de={addGetterSetter(e,t,n,r,o){de.addGetter(e,t,n),de.addSetter(e,t,r,o),de.addOverloadedGetterSetter(e,t)},addGetter(e,t,n){const r=wf+xe._capitalize(t);e.prototype[r]=e.prototype[r]||function(){const o=this.attrs[t];return o===void 0?n:o}},addSetter(e,t,n,r){const o=Cf+xe._capitalize(t);e.prototype[o]||de.overWriteSetter(e,t,n,r)},overWriteSetter(e,t,n,r){const o=Cf+xe._capitalize(t);e.prototype[o]=function(i){return n&&i!==void 0&&i!==null&&(i=n.call(this,i,t)),this._setAttr(t,i),r&&r.call(this),this}},addComponentsGetterSetter(e,t,n,r,o){const i=n.length,s=xe._capitalize,a=wf+s(t),l=Cf+s(t);e.prototype[a]=function(){const u={};for(let d=0;d<i;d++){const h=n[d];u[h]=this.getAttr(t+s(h))}return u};const c=rO(n);e.prototype[l]=function(u){const d=this.attrs[t];r&&(u=r.call(this,u,t)),c&&c.call(this,u,t);for(const h in u)u.hasOwnProperty(h)&&this._setAttr(t+s(h),u[h]);return u||n.forEach(h=>{this._setAttr(t+s(h),void 0)}),this._fireChangeEvent(t,d,u),o&&o.call(this),this},de.addOverloadedGetterSetter(e,t)},addOverloadedGetterSetter(e,t){const n=xe._capitalize(t),r=Cf+n,o=wf+n;e.prototype[t]=function(){return arguments.length?(this[r](arguments[0]),this):this[o]()}},addDeprecatedGetterSetter(e,t,n,r){xe.error("Adding deprecated "+t);const o=wf+xe._capitalize(t),i=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";e.prototype[o]=function(){xe.error(i);const s=this.attrs[t];return s===void 0?n:s},de.addSetter(e,t,r,function(){xe.error(i)}),de.addOverloadedGetterSetter(e,t)},backCompat(e,t){xe.each(t,function(n,r){const o=e.prototype[r],i=wf+xe._capitalize(n),s=Cf+xe._capitalize(n);function a(){o.apply(this,arguments),xe.error('"'+n+'" method is deprecated and will be removed soon. Use ""'+r+'" instead.')}e.prototype[n]=a,e.prototype[i]=a,e.prototype[s]=a})},afterSetFilter(){this._filterUpToDate=!1}};function oO(e){const t=/(\w+)\(([^)]+)\)/g;let n;for(;(n=t.exec(e))!==null;){const[,r,o]=n;switch(r){case"blur":{const i=parseFloat(o.replace("px",""));return function(s){this.blurRadius(i*.5);const a=wt.Filters;a&&a.Blur&&a.Blur.call(this,s)}}case"brightness":{const i=o.includes("%")?parseFloat(o)/100:parseFloat(o);return function(s){this.brightness(i);const a=wt.Filters;a&&a.Brightness&&a.Brightness.call(this,s)}}case"contrast":{const i=parseFloat(o);return function(s){const a=100*(Math.sqrt(i)-1);this.contrast(a);const l=wt.Filters;l&&l.Contrast&&l.Contrast.call(this,s)}}case"grayscale":return function(i){const s=wt.Filters;s&&s.Grayscale&&s.Grayscale.call(this,i)};case"sepia":return function(i){const s=wt.Filters;s&&s.Sepia&&s.Sepia.call(this,i)};case"invert":return function(i){const s=wt.Filters;s&&s.Invert&&s.Invert.call(this,i)};default:xe.warn(`CSS filter "${r}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var Xp="absoluteOpacity",x_="allEventListeners",la="absoluteTransform",R_="absoluteScale",jl="canvas",iO="Change",sO="children",aO="konva",x0="listening",lO="mouseenter",cO="mouseleave",uO="pointerenter",dO="pointerleave",fO="touchenter",hO="touchleave",M_="set",L_="Shape",Zp=" ",P_="stage",Qa="transform",pO="Stage",R0="visible",mO=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(Zp),gO=1,St=class sh{constructor(t){this._id=gO++,this.eventListeners={},this.attrs={},this.index=0,this._allEventListeners=null,this.parent=null,this._cache=new Map,this._attachedDepsListeners=new Map,this._lastPos=null,this._batchingTransformChange=!1,this._needClearTransformCache=!1,this._filterUpToDate=!1,this._isUnderCache=!1,this._dragEventId=null,this._shouldFireChangeEvents=!1,this.setAttrs(t),this._shouldFireChangeEvents=!0}hasChildren(){return!1}_clearCache(t){(t===Qa||t===la)&&this._cache.get(t)?this._cache.get(t).dirty=!0:t?this._cache.delete(t):this._cache.clear()}_getCache(t,n){let r=this._cache.get(t);return(r===void 0||(t===Qa||t===la)&&r.dirty===!0)&&(r=n.call(this),this._cache.set(t,r)),r}_calculate(t,n,r){if(!this._attachedDepsListeners.get(t)){const o=n.map(i=>i+"Change.konva").join(Zp);this.on(o,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,r)}_getCanvasCache(){return this._cache.get(jl)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===la&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(jl)){const{scene:t,filter:n,hit:r}=this._cache.get(jl);xe.releaseCanvas(t._canvas,n._canvas,r._canvas),this._cache.delete(jl)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const n=t||{};let r={};(n.x===void 0||n.y===void 0||n.width===void 0||n.height===void 0)&&(r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let o=Math.ceil(n.width||r.width),i=Math.ceil(n.height||r.height),s=n.pixelRatio,a=n.x===void 0?Math.floor(r.x):n.x,l=n.y===void 0?Math.floor(r.y):n.y,c=n.offset||0,u=n.drawBorder||!1,d=n.hitCanvasPixelRatio||1;if(!o||!i){xe.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}const h=Math.abs(Math.round(r.x)-a)>.5?1:0,g=Math.abs(Math.round(r.y)-l)>.5?1:0;o+=c*2+h,i+=c*2+g,a-=c,l-=c;const p=new Xa({pixelRatio:s,width:o,height:i}),v=new Xa({pixelRatio:s,width:0,height:0,willReadFrequently:!0}),k=new E0({pixelRatio:d,width:o,height:i}),C=p.getContext(),_=k.getContext(),y=new Xa({width:p.width/p.pixelRatio+Math.abs(a),height:p.height/p.pixelRatio+Math.abs(l),pixelRatio:p.pixelRatio}),w=y.getContext();return k.isCache=!0,p.isCache=!0,this._cache.delete(jl),this._filterUpToDate=!1,n.imageSmoothingEnabled===!1&&(p.getContext()._context.imageSmoothingEnabled=!1,v.getContext()._context.imageSmoothingEnabled=!1),C.save(),_.save(),w.save(),C.translate(-a,-l),_.translate(-a,-l),w.translate(-a,-l),y.x=a,y.y=l,this._isUnderCache=!0,this._clearSelfAndDescendantCache(Xp),this._clearSelfAndDescendantCache(R_),this.drawScene(p,this,y),this.drawHit(k,this),this._isUnderCache=!1,C.restore(),_.restore(),u&&(C.save(),C.beginPath(),C.rect(0,0,o,i),C.closePath(),C.setAttr("strokeStyle","red"),C.setAttr("lineWidth",5),C.stroke(),C.restore()),xe.releaseCanvas(y._canvas),this._cache.set(jl,{scene:p,filter:v,hit:k,x:a,y:l}),this._requestDraw(),this}isCached(){return this._cache.has(jl)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,n){const r=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let o=1/0,i=1/0,s=-1/0,a=-1/0;const l=this.getAbsoluteTransform(n);return r.forEach(function(c){const u=l.point(c);o===void 0&&(o=s=u.x,i=a=u.y),o=Math.min(o,u.x),i=Math.min(i,u.y),s=Math.max(s,u.x),a=Math.max(a,u.y)}),{x:o,y:i,width:s-o,height:a-i}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const n=this._getCanvasCache();t.translate(n.x,n.y);const r=this._getCachedSceneCanvas(),o=r.pixelRatio;t.drawImage(r._canvas,0,0,r.width/o,r.height/o),t.restore()}_drawCachedHitCanvas(t){const n=this._getCanvasCache(),r=n.hit;t.save(),t.translate(n.x,n.y),t.drawImage(r._canvas,0,0,r.width/r.pixelRatio,r.height/r.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),n=this._getCanvasCache(),r=n.scene,o=n.filter,i=o.getContext(),s,a,l,c;if(!t||t.length===0)return r;if(this._filterUpToDate)return o;let u=!0;for(let h=0;h<t.length;h++)if(typeof t[h]=="string"&&I_(),typeof t[h]!="string"||!I_()){u=!1;break}const d=r.pixelRatio;if(o.setSize(r.width/r.pixelRatio,r.height/r.pixelRatio),u){const h=t.join(" ");return i.save(),i.setAttr("filter",h),i.drawImage(r._canvas,0,0,r.getWidth()/d,r.getHeight()/d),i.restore(),this._filterUpToDate=!0,o}try{for(s=t.length,i.clear(),i.drawImage(r._canvas,0,0,r.getWidth()/d,r.getHeight()/d),a=i.getImageData(0,0,o.getWidth(),o.getHeight()),l=0;l<s;l++)c=t[l],typeof c=="string"&&(c=oO(c)),c.call(this,a),i.putImageData(a,0,0)}catch(h){xe.error("Unable to apply filter. "+h.message+" This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.")}return this._filterUpToDate=!0,o}on(...t){const n=t[0],r=t[1];if(t[2],this._cache&&this._cache.delete(x_),t.length===3)return this._delegate.apply(this,t);const o=n.split(Zp);for(let i=0;i<o.length;i++){const s=o[i].split("."),a=s[0],l=s[1]||"";this.eventListeners[a]||(this.eventListeners[a]=[]),this.eventListeners[a].push({name:l,handler:r})}return this}off(t,n){let r=(t||"").split(Zp),o=r.length,i,s,a,l,c,u;if(this._cache&&this._cache.delete(x_),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<o;i++)if(a=r[i],l=a.split("."),c=l[0],u=l[1],c)this.eventListeners[c]&&this._off(c,u,n);else for(s in this.eventListeners)this._off(s,u,n);return this}dispatchEvent(t){const n={target:this,type:t.type,evt:t};return this.fire(t.type,n),this}addEventListener(t,n){return this.on(t,function(r){n.call(this,r.evt)}),this}removeEventListener(t){return this.off(t),this}_delegate(t,n,r){const o=this;return this.on(t,function(i){const s=i.target.findAncestors(n,!0,o);for(let a=0;a<s.length;a++)i=xe.cloneObject(i),i.currentTarget=s[a],r.call(s[a],i)}),this}remove(){return this.isDragging()&&this.stopDrag(),On._dragElements.delete(this._id),On._dragElements.forEach((t,n)=>{this.isAncestorOf(t.node)&&On._dragElements.delete(n)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(la),this._clearSelfAndDescendantCache(Xp),this._clearSelfAndDescendantCache(R_),this._clearSelfAndDescendantCache(P_),this._clearSelfAndDescendantCache(R0),this._clearSelfAndDescendantCache(x0)}_remove(){this._clearCaches();const t=this.getParent();t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),this.parent=null)}destroy(){return this.remove(),this.clearCache(),this}getAttr(t){const n="get"+xe._capitalize(t);return xe._isFunction(this[n])?this[n]():this.attrs[t]}getAncestors(){let t=this.getParent(),n=[];for(;t;)n.push(t),t=t.getParent();return n}getAttrs(){return this.attrs||{}}setAttrs(t){return this._batchTransformChanges(()=>{let n,r;if(!t)return this;for(n in t)n!==sO&&(r=M_+xe._capitalize(n),xe._isFunction(this[r])?this[r](t[n]):this._setAttr(n,t[n]))}),this}isListening(){return this._getCache(x0,this._isListening)}_isListening(t){if(!this.listening())return!1;const n=this.getParent();return n&&n!==t&&this!==t?n._isListening(t):!0}isVisible(){return this._getCache(R0,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const n=this.getParent();return n&&n!==t&&this!==t?n._isVisible(t):!0}shouldDrawHit(t,n=!1){if(t)return this._isVisible(t)&&this._isListening(t);const r=this.getLayer();let o=!1;On._dragElements.forEach(s=>{s.dragStatus==="dragging"&&(s.node.nodeType==="Stage"||s.node.getLayer()===r)&&(o=!0)});const i=!n&&!wt.hitOnDragEnabled&&(o||wt.isTransforming());return this.isListening()&&this.isVisible()&&!i}show(){return this.visible(!0),this}hide(){return this.visible(!1),this}getZIndex(){return this.index||0}getAbsoluteZIndex(){let t=this.getDepth(),n=this,r=0,o,i,s,a;function l(u){for(o=[],i=u.length,s=0;s<i;s++)a=u[s],r++,a.nodeType!==L_&&(o=o.concat(a.getChildren().slice())),a._id===n._id&&(s=i);o.length>0&&o[0].getDepth()<=t&&l(o)}const c=this.getStage();return n.nodeType!==pO&&c&&l(c.getChildren()),r}getDepth(){let t=0,n=this.parent;for(;n;)t++,n=n.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(Qa),this._clearSelfAndDescendantCache(la)),this._needClearTransformCache=!1}setPosition(t){return this._batchTransformChanges(()=>{this.x(t.x),this.y(t.y)}),this}getPosition(){return{x:this.x(),y:this.y()}}getRelativePointerPosition(){const t=this.getStage();if(!t)return null;const n=t.getPointerPosition();if(!n)return null;const r=this.getAbsoluteTransform().copy();return r.invert(),r.point(n)}getAbsolutePosition(t){let n=!1,r=this.parent;for(;r;){if(r.isCached()){n=!0;break}r=r.parent}n&&!t&&(t=!0);const o=this.getAbsoluteTransform(t).getMatrix(),i=new zi,s=this.offset();return i.m=o.slice(),i.translate(s.x,s.y),i.getTranslation()}setAbsolutePosition(t){const{x:n,y:r,...o}=this._clearTransform();this.attrs.x=n,this.attrs.y=r,this._clearCache(Qa);const i=this._getAbsoluteTransform().copy();return i.invert(),i.translate(t.x,t.y),t={x:this.attrs.x+i.getTranslation().x,y:this.attrs.y+i.getTranslation().y},this._setTransform(o),this.setPosition({x:t.x,y:t.y}),this._clearCache(Qa),this._clearSelfAndDescendantCache(la),this}_setTransform(t){let n;for(n in t)this.attrs[n]=t[n]}_clearTransform(){const t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}move(t){let n=t.x,r=t.y,o=this.x(),i=this.y();return n!==void 0&&(o+=n),r!==void 0&&(i+=r),this.setPosition({x:o,y:i}),this}_eachAncestorReverse(t,n){let r=[],o=this.getParent(),i,s;if(!(n&&n._id===this._id)){for(r.unshift(this);o&&(!n||o._id!==n._id);)r.unshift(o),o=o.parent;for(i=r.length,s=0;s<i;s++)t(r[s])}}rotate(t){return this.rotation(this.rotation()+t),this}moveToTop(){if(!this.parent)return xe.warn("Node has no parent. moveToTop function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1?(this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0):!1}moveUp(){if(!this.parent)return xe.warn("Node has no parent. moveUp function is ignored."),!1;const t=this.index;return t<this.parent.getChildren().length-1?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1}moveDown(){if(!this.parent)return xe.warn("Node has no parent. moveDown function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1}moveToBottom(){if(!this.parent)return xe.warn("Node has no parent. moveToBottom function is ignored."),!1;const t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1}setZIndex(t){if(!this.parent)return xe.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&xe.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");const n=this.index;return this.parent.children.splice(n,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}getAbsoluteOpacity(){return this._getCache(Xp,this._getAbsoluteOpacity)}_getAbsoluteOpacity(){let t=this.opacity();const n=this.getParent();return n&&!n._isUnderCache&&(t*=n.getAbsoluteOpacity()),t}moveTo(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}toObject(){let t=this.getAttrs(),n,r,o,i,s;const a={attrs:{},className:this.getClassName()};for(n in t)r=t[n],s=xe.isObject(r)&&!xe._isPlainObject(r)&&!xe._isArray(r),!s&&(o=typeof this[n]=="function"&&this[n],delete t[n],i=o?o.call(this):null,t[n]=r,i!==r&&(a.attrs[n]=r));return xe._prepareToStringify(a)}toJSON(){return JSON.stringify(this.toObject())}getParent(){return this.parent}findAncestors(t,n,r){const o=[];n&&this._isMatch(t)&&o.push(this);let i=this.parent;for(;i;){if(i===r)return o;i._isMatch(t)&&o.push(i),i=i.parent}return o}isAncestorOf(t){return!1}findAncestor(t,n,r){return this.findAncestors(t,n,r)[0]}_isMatch(t){if(!t)return!1;if(typeof t=="function")return t(this);let n=t.replace(/ /g,"").split(","),r=n.length,o,i;for(o=0;o<r;o++)if(i=n[o],xe.isValidSelector(i)||(xe.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),xe.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),xe.warn("Konva is awesome, right?")),i.charAt(0)==="#"){if(this.id()===i.slice(1))return!0}else if(i.charAt(0)==="."){if(this.hasName(i.slice(1)))return!0}else if(this.className===i||this.nodeType===i)return!0;return!1}getLayer(){const t=this.getParent();return t?t.getLayer():null}getStage(){return this._getCache(P_,this._getStage)}_getStage(){const t=this.getParent();return t?t.getStage():null}fire(t,n={},r){return n.target=n.target||this,r?this._fireAndBubble(t,n):this._fire(t,n),this}getAbsoluteTransform(t){return t?this._getAbsoluteTransform(t):this._getCache(la,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let n;if(t)return n=new zi,this._eachAncestorReverse(function(r){const o=r.transformsEnabled();o==="all"?n.multiply(r.getTransform()):o==="position"&&n.translate(r.x()-r.offsetX(),r.y()-r.offsetY())},t),n;{n=this._cache.get(la)||new zi,this.parent?this.parent.getAbsoluteTransform().copyInto(n):n.reset();const r=this.transformsEnabled();if(r==="all")n.multiply(this.getTransform());else if(r==="position"){const o=this.attrs.x||0,i=this.attrs.y||0,s=this.attrs.offsetX||0,a=this.attrs.offsetY||0;n.translate(o-s,i-a)}return n.dirty=!1,n}}getAbsoluteScale(t){let n=this;for(;n;)n._isUnderCache&&(t=n),n=n.getParent();const r=this.getAbsoluteTransform(t).decompose();return{x:r.scaleX,y:r.scaleY}}getAbsoluteRotation(){return this.getAbsoluteTransform().decompose().rotation}getTransform(){return this._getCache(Qa,this._getTransform)}_getTransform(){var t,n;const r=this._cache.get(Qa)||new zi;r.reset();const o=this.x(),i=this.y(),s=wt.getAngle(this.rotation()),a=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,l=(n=this.attrs.scaleY)!==null&&n!==void 0?n:1,c=this.attrs.skewX||0,u=this.attrs.skewY||0,d=this.attrs.offsetX||0,h=this.attrs.offsetY||0;return(o!==0||i!==0)&&r.translate(o,i),s!==0&&r.rotate(s),(c!==0||u!==0)&&r.skew(c,u),(a!==1||l!==1)&&r.scale(a,l),(d!==0||h!==0)&&r.translate(-1*d,-1*h),r.dirty=!1,r}clone(t){let n=xe.cloneObject(this.attrs),r,o,i,s,a;for(r in t)n[r]=t[r];const l=new this.constructor(n);for(r in this.eventListeners)for(o=this.eventListeners[r],i=o.length,s=0;s<i;s++)a=o[s],a.name.indexOf(aO)<0&&(l.eventListeners[r]||(l.eventListeners[r]=[]),l.eventListeners[r].push(a));return l}_toKonvaCanvas(t){t=t||{};const n=this.getClientRect(),r=this.getStage(),o=t.x!==void 0?t.x:Math.floor(n.x),i=t.y!==void 0?t.y:Math.floor(n.y),s=t.pixelRatio||1,a=new Xa({width:t.width||Math.ceil(n.width)||(r?r.width():0),height:t.height||Math.ceil(n.height)||(r?r.height():0),pixelRatio:s}),l=a.getContext(),c=new Xa({width:a.width/a.pixelRatio+Math.abs(o),height:a.height/a.pixelRatio+Math.abs(i),pixelRatio:a.pixelRatio});return t.imageSmoothingEnabled===!1&&(l._context.imageSmoothingEnabled=!1),l.save(),(o||i)&&l.translate(-1*o,-1*i),this.drawScene(a,void 0,c),l.restore(),a}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};const n=t.mimeType||null,r=t.quality||null,o=this._toKonvaCanvas(t).toDataURL(n,r);return t.callback&&t.callback(o),o}toImage(t){return new Promise((n,r)=>{try{const o=t?.callback;o&&delete t.callback,xe._urlToImage(this.toDataURL(t),function(i){n(i),o?.(i)})}catch(o){r(o)}})}toBlob(t){return new Promise((n,r)=>{try{const o=t?.callback;o&&delete t.callback,this.toCanvas(t).toBlob(i=>{n(i),o?.(i)},t?.mimeType,t?.quality)}catch(o){r(o)}})}setSize(t){return this.width(t.width),this.height(t.height),this}getSize(){return{width:this.width(),height:this.height()}}getClassName(){return this.className||this.nodeType}getType(){return this.nodeType}getDragDistance(){return this.attrs.dragDistance!==void 0?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():wt.dragDistance}_off(t,n,r){let o=this.eventListeners[t],i,s,a;for(i=0;i<o.length;i++)if(s=o[i].name,a=o[i].handler,(s!=="konva"||n==="konva")&&(!n||s===n)&&(!r||r===a)){if(o.splice(i,1),o.length===0){delete this.eventListeners[t];break}i--}}_fireChangeEvent(t,n,r){this._fire(t+iO,{oldVal:n,newVal:r})}addName(t){if(!this.hasName(t)){const n=this.name(),r=n?n+" "+t:t;this.name(r)}return this}hasName(t){if(!t)return!1;const n=this.name();return n?(n||"").split(/\s/g).indexOf(t)!==-1:!1}removeName(t){const n=(this.name()||"").split(/\s/g),r=n.indexOf(t);return r!==-1&&(n.splice(r,1),this.name(n.join(" "))),this}setAttr(t,n){const r=this[M_+xe._capitalize(t)];return xe._isFunction(r)?r.call(this,n):this._setAttr(t,n),this}_requestDraw(){if(wt.autoDrawEnabled){const t=this.getLayer()||this.getStage();t?.batchDraw()}}_setAttr(t,n){const r=this.attrs[t];r===n&&!xe.isObject(n)||(n==null?delete this.attrs[t]:this.attrs[t]=n,this._shouldFireChangeEvents&&this._fireChangeEvent(t,r,n),this._requestDraw())}_setComponentAttr(t,n,r){let o;r!==void 0&&(o=this.attrs[t],o||(this.attrs[t]=this.getAttr(t)),this.attrs[t][n]=r,this._fireChangeEvent(t,o,r))}_fireAndBubble(t,n,r){n&&this.nodeType===L_&&(n.target=this);const o=[lO,cO,uO,dO,fO,hO];if(!(o.indexOf(t)!==-1&&(r&&(this===r||this.isAncestorOf&&this.isAncestorOf(r))||this.nodeType==="Stage"&&!r))){this._fire(t,n);const i=o.indexOf(t)!==-1&&r&&r.isAncestorOf&&r.isAncestorOf(this)&&!r.isAncestorOf(this.parent);(n&&!n.cancelBubble||!n)&&this.parent&&this.parent.isListening()&&!i&&(r&&r.parent?this._fireAndBubble.call(this.parent,t,n,r):this._fireAndBubble.call(this.parent,t,n))}}_getProtoListeners(t){var n,r;const{nodeType:o}=this,i=sh.protoListenerMap.get(o)||{};let s=i?.[t];if(s===void 0){s=[];let a=Object.getPrototypeOf(this);for(;a;){const l=(r=(n=a.eventListeners)===null||n===void 0?void 0:n[t])!==null&&r!==void 0?r:[];s.push(...l),a=Object.getPrototypeOf(a)}i[t]=s,sh.protoListenerMap.set(o,i)}return s}_fire(t,n){n=n||{},n.currentTarget=this,n.type=t;const r=this._getProtoListeners(t);if(r){const i=r.slice();for(let s=0;s<i.length;s++)i[s].handler.call(this,n)}const o=this.eventListeners[t];if(o){const i=o.slice(),s=i.length;for(let l=0;l<i.length;l++)i[l].handler.call(this,n);const a=this.eventListeners[t];if(a)for(let l=s;l<a.length;l++)a[l].handler.call(this,n)}}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const n=t?t.pointerId:void 0,r=this.getStage(),o=this.getAbsolutePosition();if(!r)return;const i=r._getPointerById(n)||r._changedPointerPositions[0]||o;On._dragElements.set(this._id,{node:this,startPointerPos:i,offset:{x:i.x-o.x,y:i.y-o.y},dragStatus:"ready",pointerId:n,startEvent:t})}startDrag(t,n=!0){On._dragElements.has(this._id)||this._createDragElement(t);const r=On._dragElements.get(this._id);r.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:r.startEvent&&r.startEvent.evt||t&&t.evt},n)}_setDragPosition(t,n){const r=this.getStage()._getPointerById(n.pointerId);if(!r)return;let o={x:r.x-n.offset.x,y:r.y-n.offset.y};const i=this.dragBoundFunc();if(i!==void 0){const s=i.call(this,o,t);s?o=s:xe.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==o.x||this._lastPos.y!==o.y)&&(this.setAbsolutePosition(o),this._requestDraw()),this._lastPos=o}stopDrag(t){const n=On._dragElements.get(this._id);n&&(n.dragStatus="stopped"),On._endDragBefore(t),On._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=On._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(t.evt.button===void 0||wt.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let n=!1;On._dragElements.forEach(r=>{this.isAncestorOf(r.node)&&(n=!0)}),n||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const t=On._dragElements.get(this._id),n=t&&t.dragStatus==="dragging",r=t&&t.dragStatus==="ready";n?this.stopDrag():r&&On._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const n=this.getStage();if(!n)return!1;const r={x:-t.x,y:-t.y,width:n.width()+2*t.x,height:n.height()+2*t.y};return xe.haveIntersection(r,this.getClientRect())}static create(t,n){return xe._isString(t)&&(t=JSON.parse(t)),this._createNode(t,n)}static _createNode(t,n){let r=sh.prototype.getClassName.call(t),o=t.children,i,s,a;n&&(t.attrs.container=n),wt[r]||(xe.warn('Can not find a node with class name "'+r+'". Fallback to "Shape".'),r="Shape");const l=wt[r];if(i=new l(t.attrs),o)for(s=o.length,a=0;a<s;a++)i.add(sh._createNode(o[a]));return i}};St.protoListenerMap=new Map,St.prototype.nodeType="Node",St.prototype._attrsAffectingSize=[],St.prototype.eventListeners={},St.prototype.on(mO,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(Qa),this._clearSelfAndDescendantCache(la)}),St.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(R0)}),St.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(x0)}),St.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(Xp)});var Jn=de.addGetterSetter;Jn(St,"zIndex"),Jn(St,"absolutePosition"),Jn(St,"position"),Jn(St,"x",0,yt()),Jn(St,"y",0,yt()),Jn(St,"globalCompositeOperation","source-over",Vl()),Jn(St,"opacity",1,yt()),Jn(St,"name","",Vl()),Jn(St,"id","",Vl()),Jn(St,"rotation",0,yt()),de.addComponentsGetterSetter(St,"scale",["x","y"]),Jn(St,"scaleX",1,yt()),Jn(St,"scaleY",1,yt()),de.addComponentsGetterSetter(St,"skew",["x","y"]),Jn(St,"skewX",0,yt()),Jn(St,"skewY",0,yt()),de.addComponentsGetterSetter(St,"offset",["x","y"]),Jn(St,"offsetX",0,yt()),Jn(St,"offsetY",0,yt()),Jn(St,"dragDistance",void 0,yt()),Jn(St,"width",0,yt()),Jn(St,"height",0,yt()),Jn(St,"listening",!0,Vi()),Jn(St,"preventDefault",!0,Vi()),Jn(St,"filters",void 0,function(e){return this._filterUpToDate=!1,e}),Jn(St,"visible",!0,Vi()),Jn(St,"transformsEnabled","all",Vl()),Jn(St,"size"),Jn(St,"dragBoundFunc"),Jn(St,"draggable",!1,Vi()),de.backCompat(St,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var fi=class extends St{constructor(){super(...arguments),this.children=[]}getChildren(e){const t=this.children||[];return e?t.filter(e):t}hasChildren(){return this.getChildren().length>0}removeChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.remove()}),this.children=[],this._requestDraw(),this}destroyChildren(){return this.getChildren().forEach(e=>{e.parent=null,e.index=0,e.destroy()}),this.children=[],this._requestDraw(),this}add(...e){if(e.length===0)return this;if(e.length>1){for(let n=0;n<e.length;n++)this.add(e[n]);return this}const t=e[0];return t.getParent()?(t.moveTo(this),this):(this._validateAdd(t),t.index=this.getChildren().length,t.parent=this,t._clearCaches(),this.getChildren().push(t),this._fire("add",{child:t}),this._requestDraw(),this)}destroy(){return this.hasChildren()&&this.destroyChildren(),super.destroy(),this}find(e){return this._generalFind(e,!1)}findOne(e){const t=this._generalFind(e,!0);return t.length>0?t[0]:void 0}_generalFind(e,t){const n=[];return this._descendants(r=>{const o=r._isMatch(e);return o&&n.push(r),!!(o&&t)}),n}_descendants(e){let t=!1;const n=this.getChildren();for(const r of n){if(t=e(r),t)return!0;if(r.hasChildren()&&(t=r._descendants(e),t))return!0}return!1}toObject(){const e=St.prototype.toObject.call(this);return e.children=[],this.getChildren().forEach(t=>{e.children.push(t.toObject())}),e}isAncestorOf(e){let t=e.getParent();for(;t;){if(t._id===this._id)return!0;t=t.getParent()}return!1}clone(e){const t=St.prototype.clone.call(this,e);return this.getChildren().forEach(function(n){t.add(n.clone())}),t}getAllIntersections(e){const t=[];return this.find("Shape").forEach(n=>{n.isVisible()&&n.intersects(e)&&t.push(n)}),t}_clearSelfAndDescendantCache(e){var t;super._clearSelfAndDescendantCache(e),!this.isCached()&&((t=this.children)===null||t===void 0||t.forEach(function(n){n._clearSelfAndDescendantCache(e)}))}_setChildrenIndices(){var e;(e=this.children)===null||e===void 0||e.forEach(function(t,n){t.index=n}),this._requestDraw()}drawScene(e,t,n){const r=this.getLayer(),o=e||r&&r.getCanvas(),i=o&&o.getContext(),s=this._getCanvasCache(),a=s&&s.scene,l=o&&o.isCache;if(!this.isVisible()&&!l)return this;if(a){i.save();const c=this.getAbsoluteTransform(t).getMatrix();i.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(i),i.restore()}else this._drawChildren("drawScene",o,t,n);return this}drawHit(e,t){if(!this.shouldDrawHit(t))return this;const n=this.getLayer(),r=e||n&&n.hitCanvas,o=r&&r.getContext(),i=this._getCanvasCache();if(i&&i.hit){o.save();const s=this.getAbsoluteTransform(t).getMatrix();o.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._drawCachedHitCanvas(o),o.restore()}else this._drawChildren("drawHit",r,t);return this}_drawChildren(e,t,n,r){var o;const i=t&&t.getContext(),s=this.clipWidth(),a=this.clipHeight(),l=this.clipFunc(),c=typeof s=="number"&&typeof a=="number"||l,u=n===this;if(c){i.save();const h=this.getAbsoluteTransform(n);let g=h.getMatrix();i.transform(g[0],g[1],g[2],g[3],g[4],g[5]),i.beginPath();let p;if(l)p=l.call(this,i,this);else{const v=this.clipX(),k=this.clipY();i.rect(v||0,k||0,s,a)}i.clip.apply(i,p),g=h.copy().invert().getMatrix(),i.transform(g[0],g[1],g[2],g[3],g[4],g[5])}const d=!u&&this.globalCompositeOperation()!=="source-over"&&e==="drawScene";d&&(i.save(),i._applyGlobalCompositeOperation(this)),(o=this.children)===null||o===void 0||o.forEach(function(h){h[e](t,n,r)}),d&&i.restore(),c&&i.restore()}getClientRect(e={}){var t;const n=e.skipTransform,r=e.relativeTo;let o,i,s,a,l={x:1/0,y:1/0,width:0,height:0};const c=this;(t=this.children)===null||t===void 0||t.forEach(function(h){if(!h.visible())return;const g=h.getClientRect({relativeTo:c,skipShadow:e.skipShadow,skipStroke:e.skipStroke});g.width===0&&g.height===0||(o===void 0?(o=g.x,i=g.y,s=g.x+g.width,a=g.y+g.height):(o=Math.min(o,g.x),i=Math.min(i,g.y),s=Math.max(s,g.x+g.width),a=Math.max(a,g.y+g.height)))});const u=this.find("Shape");let d=!1;for(let h=0;h<u.length;h++)if(u[h]._isVisible(this)){d=!0;break}return d&&o!==void 0?l={x:o,y:i,width:s-o,height:a-i}:l={x:0,y:0,width:0,height:0},n?l:this._transformedRect(l,r)}};de.addComponentsGetterSetter(fi,"clip",["x","y","width","height"]),de.addGetterSetter(fi,"clipX",void 0,yt()),de.addGetterSetter(fi,"clipY",void 0,yt()),de.addGetterSetter(fi,"clipWidth",void 0,yt()),de.addGetterSetter(fi,"clipHeight",void 0,yt()),de.addGetterSetter(fi,"clipFunc");var kf=new Map,D_=wt._global.PointerEvent!==void 0;function M0(e){return kf.get(e)}function L0(e){return{evt:e,pointerId:e.pointerId}}function O_(e,t){return kf.get(e)===t}function F_(e,t){Sf(e),t.getStage()&&(kf.set(e,t),D_&&t._fire("gotpointercapture",L0(new PointerEvent("gotpointercapture"))))}function Sf(e,t){const n=kf.get(e);if(!n)return;const r=n.getStage();r&&r.content,kf.delete(e),D_&&n._fire("lostpointercapture",L0(new PointerEvent("lostpointercapture")))}var vO="Stage",yO="string",N_="px",bO="mouseout",B_="mouseleave",z_="mouseover",V_="mouseenter",j_="mousemove",U_="mousedown",H_="mouseup",_f="pointermove",Af="pointerdown",cu="pointerup",If="pointercancel",wO="lostpointercapture",Qp="pointerout",Ef="pointerleave",Jp="pointerover",em="pointerenter",P0="contextmenu",$_="touchstart",G_="touchend",W_="touchmove",K_="touchcancel",D0="wheel",CO=5,kO=[[V_,"_pointerenter"],[U_,"_pointerdown"],[j_,"_pointermove"],[H_,"_pointerup"],[B_,"_pointerleave"],[$_,"_pointerdown"],[W_,"_pointermove"],[G_,"_pointerup"],[K_,"_pointercancel"],[z_,"_pointerover"],[D0,"_wheel"],[P0,"_contextmenu"],[Af,"_pointerdown"],[_f,"_pointermove"],[cu,"_pointerup"],[If,"_pointercancel"],[Ef,"_pointerleave"],[wO,"_lostpointercapture"]],O0={mouse:{[Qp]:bO,[Ef]:B_,[Jp]:z_,[em]:V_,[_f]:j_,[Af]:U_,[cu]:H_,[If]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Qp]:"touchout",[Ef]:"touchleave",[Jp]:"touchover",[em]:"touchenter",[_f]:W_,[Af]:$_,[cu]:G_,[If]:K_,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Qp]:Qp,[Ef]:Ef,[Jp]:Jp,[em]:em,[_f]:_f,[Af]:Af,[cu]:cu,[If]:If,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Tf=e=>e.indexOf("pointer")>=0?"pointer":e.indexOf("touch")>=0?"touch":"mouse",uu=e=>{const t=Tf(e);if(t==="pointer")return wt.pointerEventsEnabled&&O0.pointer;if(t==="touch")return O0.touch;if(t==="mouse")return O0.mouse};function q_(e={}){return(e.clipFunc||e.clipWidth||e.clipHeight)&&xe.warn("Stage does not support clipping. Please use clip for Layers or Groups."),e}var SO="Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);",xf=[],tm=class extends fi{constructor(e){super(q_(e)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),xf.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{q_(this.attrs)}),this._checkVisibility()}_validateAdd(e){const t=e.getType()==="Layer",n=e.getType()==="FastLayer";t||n||xe.throw("You may only add layers to the stage.")}_checkVisibility(){if(!this.content)return;const e=this.visible()?"":"none";this.content.style.display=e}setContainer(e){if(typeof e===yO){let t;if(e.charAt(0)==="."){const n=e.slice(1);e=document.getElementsByClassName(n)[0]}else e.charAt(0)!=="#"?t=e:t=e.slice(1),e=document.getElementById(t);if(!e)throw"Can not find container in document with id "+t}return this._setAttr("container",e),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),e.appendChild(this.content)),this}shouldDrawHit(){return!0}clear(){const e=this.children,t=e.length;for(let n=0;n<t;n++)e[n].clear();return this}clone(e){return e||(e={}),e.container=typeof document<"u"&&document.createElement("div"),fi.prototype.clone.call(this,e)}destroy(){super.destroy();const e=this.content;e&&xe._isInDocument(e)&&this.container().removeChild(e);const t=xf.indexOf(this);return t>-1&&xf.splice(t,1),xe.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}getPointerPosition(){const e=this._pointerPositions[0]||this._changedPointerPositions[0];return e?{x:e.x,y:e.y}:(xe.warn(SO),null)}_getPointerById(e){return this._pointerPositions.find(t=>t.id===e)}getPointersPositions(){return this._pointerPositions}getStage(){return this}getContent(){return this.content}_toKonvaCanvas(e){e={...e},e.x=e.x||0,e.y=e.y||0,e.width=e.width||this.width(),e.height=e.height||this.height();const t=new Xa({width:e.width,height:e.height,pixelRatio:e.pixelRatio||1}),n=t.getContext()._context,r=this.children;return(e.x||e.y)&&n.translate(-1*e.x,-1*e.y),r.forEach(function(o){if(!o.isVisible())return;const i=o._toKonvaCanvas(e);n.drawImage(i._canvas,e.x,e.y,i.getWidth()/i.getPixelRatio(),i.getHeight()/i.getPixelRatio())}),t}getIntersection(e){if(!e)return null;const t=this.children,n=t.length-1;for(let r=n;r>=0;r--){const o=t[r].getIntersection(e);if(o)return o}return null}_resizeDOM(){const e=this.width(),t=this.height();this.content&&(this.content.style.width=e+N_,this.content.style.height=t+N_),this.bufferCanvas.setSize(e,t),this.bufferHitCanvas.setSize(e,t),this.children.forEach(n=>{n.setSize({width:e,height:t}),n.draw()})}add(e,...t){if(arguments.length>1){for(let r=0;r<arguments.length;r++)this.add(arguments[r]);return this}super.add(e);const n=this.children.length;return n>CO&&xe.warn("The stage has "+n+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),e.setSize({width:this.width(),height:this.height()}),e.draw(),wt.isBrowser&&this.content.appendChild(e.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(e){return O_(e,this)}setPointerCapture(e){F_(e,this)}releaseCapture(e){Sf(e,this)}getLayers(){return this.children}_bindContentEvents(){wt.isBrowser&&kO.forEach(([e,t])=>{this.content.addEventListener(e,n=>{this[t](n)},{passive:!1})})}_pointerenter(e){this.setPointersPositions(e);const t=uu(e.type);t&&this._fire(t.pointerenter,{evt:e,target:this,currentTarget:this})}_pointerover(e){this.setPointersPositions(e);const t=uu(e.type);t&&this._fire(t.pointerover,{evt:e,target:this,currentTarget:this})}_getTargetShape(e){let t=this[e+"targetShape"];return t&&!t.getStage()&&(t=null),t}_pointerleave(e){const t=uu(e.type),n=Tf(e.type);if(!t)return;this.setPointersPositions(e);const r=this._getTargetShape(n),o=!(wt.isDragging()||wt.isTransforming())||wt.hitOnDragEnabled;r&&o?(r._fireAndBubble(t.pointerout,{evt:e}),r._fireAndBubble(t.pointerleave,{evt:e}),this._fire(t.pointerleave,{evt:e,target:this,currentTarget:this}),this[n+"targetShape"]=null):o&&(this._fire(t.pointerleave,{evt:e,target:this,currentTarget:this}),this._fire(t.pointerout,{evt:e,target:this,currentTarget:this})),this.pointerPos=null,this._pointerPositions=[]}_pointerdown(e){const t=uu(e.type),n=Tf(e.type);if(!t)return;this.setPointersPositions(e);let r=!1;this._changedPointerPositions.forEach(o=>{const i=this.getIntersection(o);if(On.justDragged=!1,wt["_"+n+"ListenClick"]=!0,!i||!i.isListening()){this[n+"ClickStartShape"]=void 0;return}wt.capturePointerEventsEnabled&&i.setPointerCapture(o.id),this[n+"ClickStartShape"]=i,i._fireAndBubble(t.pointerdown,{evt:e,pointerId:o.id}),r=!0;const s=e.type.indexOf("touch")>=0;i.preventDefault()&&e.cancelable&&s&&e.preventDefault()}),r||this._fire(t.pointerdown,{evt:e,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}_pointermove(e){const t=uu(e.type),n=Tf(e.type);if(!t)return;const r=e.type.indexOf("touch")>=0||e.pointerType==="touch";if(wt.isDragging()&&On.node.preventDefault()&&e.cancelable&&r&&e.preventDefault(),this.setPointersPositions(e),!(!(wt.isDragging()||wt.isTransforming())||wt.hitOnDragEnabled))return;const o={};let i=!1;const s=this._getTargetShape(n);this._changedPointerPositions.forEach(a=>{const l=M0(a.id)||this.getIntersection(a),c=a.id,u={evt:e,pointerId:c},d=s!==l;if(d&&s&&(s._fireAndBubble(t.pointerout,{...u},l),s._fireAndBubble(t.pointerleave,{...u},l)),l){if(o[l._id])return;o[l._id]=!0}l&&l.isListening()?(i=!0,d&&(l._fireAndBubble(t.pointerover,{...u},s),l._fireAndBubble(t.pointerenter,{...u},s),this[n+"targetShape"]=l),l._fireAndBubble(t.pointermove,{...u})):s&&(this._fire(t.pointerover,{evt:e,target:this,currentTarget:this,pointerId:c}),this[n+"targetShape"]=null)}),i||this._fire(t.pointermove,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(e){const t=uu(e.type),n=Tf(e.type);if(!t)return;this.setPointersPositions(e);const r=this[n+"ClickStartShape"],o=this[n+"ClickEndShape"],i={};let s=!1;this._changedPointerPositions.forEach(a=>{const l=M0(a.id)||this.getIntersection(a);if(l){if(l.releaseCapture(a.id),i[l._id])return;i[l._id]=!0}const c=a.id,u={evt:e,pointerId:c};let d=!1;wt["_"+n+"InDblClickWindow"]?(d=!0,clearTimeout(this[n+"DblTimeout"])):On.justDragged||(wt["_"+n+"InDblClickWindow"]=!0,clearTimeout(this[n+"DblTimeout"])),this[n+"DblTimeout"]=setTimeout(function(){wt["_"+n+"InDblClickWindow"]=!1},wt.dblClickWindow),l&&l.isListening()?(s=!0,this[n+"ClickEndShape"]=l,l._fireAndBubble(t.pointerup,{...u}),wt["_"+n+"ListenClick"]&&r&&r===l&&(l._fireAndBubble(t.pointerclick,{...u}),d&&o&&o===l&&l._fireAndBubble(t.pointerdblclick,{...u}))):(this[n+"ClickEndShape"]=null,s||(this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),s=!0),wt["_"+n+"ListenClick"]&&this._fire(t.pointerclick,{evt:e,target:this,currentTarget:this,pointerId:c}),d&&this._fire(t.pointerdblclick,{evt:e,target:this,currentTarget:this,pointerId:c}))}),s||this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),wt["_"+n+"ListenClick"]=!1,e.cancelable&&n!=="touch"&&n!=="pointer"&&e.preventDefault()}_contextmenu(e){this.setPointersPositions(e);const t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(P0,{evt:e}):this._fire(P0,{evt:e,target:this,currentTarget:this})}_wheel(e){this.setPointersPositions(e);const t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(D0,{evt:e}):this._fire(D0,{evt:e,target:this,currentTarget:this})}_pointercancel(e){this.setPointersPositions(e);const t=M0(e.pointerId)||this.getIntersection(this.getPointerPosition());t&&t._fireAndBubble(cu,L0(e)),Sf(e.pointerId)}_lostpointercapture(e){Sf(e.pointerId)}setPointersPositions(e){const t=this._getContentPosition();let n=null,r=null;e=e||window.event,e.touches!==void 0?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(e.touches,o=>{this._pointerPositions.push({id:o.identifier,x:(o.clientX-t.left)/t.scaleX,y:(o.clientY-t.top)/t.scaleY})}),Array.prototype.forEach.call(e.changedTouches||e.touches,o=>{this._changedPointerPositions.push({id:o.identifier,x:(o.clientX-t.left)/t.scaleX,y:(o.clientY-t.top)/t.scaleY})})):(n=(e.clientX-t.left)/t.scaleX,r=(e.clientY-t.top)/t.scaleY,this.pointerPos={x:n,y:r},this._pointerPositions=[{x:n,y:r,id:xe._getFirstPointerId(e)}],this._changedPointerPositions=[{x:n,y:r,id:xe._getFirstPointerId(e)}])}_setPointerPosition(e){xe.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(e)}_getContentPosition(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};const e=this.content.getBoundingClientRect();return{top:e.top,left:e.left,scaleX:e.width/this.content.clientWidth||1,scaleY:e.height/this.content.clientHeight||1}}_buildDOM(){if(this.bufferCanvas=new Xa({width:this.width(),height:this.height()}),this.bufferHitCanvas=new E0({pixelRatio:1,width:this.width(),height:this.height()}),!wt.isBrowser)return;const e=this.container();if(!e)throw"Stage has no container. A container is required.";e.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),e.appendChild(this.content),this._resizeDOM()}cache(){return xe.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."),this}clearCache(){return this}batchDraw(){return this.getChildren().forEach(function(e){e.batchDraw()}),this}};tm.prototype.nodeType=vO,kr(tm),de.addGetterSetter(tm,"container"),wt.isBrowser&&document.addEventListener("visibilitychange",()=>{xf.forEach(e=>{e.batchDraw()})});var Y_="hasShadow",X_="shadowRGBA",Z_="patternImage",Q_="linearGradient",J_="radialGradient",nm;function F0(){return nm||(nm=xe.createCanvasElement().getContext("2d"),nm)}var Rf={};function _O(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function AO(e){e.stroke()}function IO(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function EO(e){e.stroke()}function TO(){this._clearCache(Y_)}function xO(){this._clearCache(X_)}function RO(){this._clearCache(Z_)}function MO(){this._clearCache(Q_)}function LO(){this._clearCache(J_)}var gt=class extends St{constructor(e){super(e);let t,n=0;for(;t=xe.getHitColor(),!(t&&!(t in Rf));)if(n++,n>=1e4){xe.warn("Failed to find a unique color key for a shape. Konva may work incorrectly. Most likely your browser is using canvas farbling. Consider disabling it."),t=xe.getRandomColor();break}this.colorKey=t,Rf[t]=this}getContext(){return xe.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return xe.warn("shape.getCanvas() method is deprecated. Please do not use it."),this.getLayer().getCanvas()}getSceneFunc(){return this.attrs.sceneFunc||this._sceneFunc}getHitFunc(){return this.attrs.hitFunc||this._hitFunc}hasShadow(){return this._getCache(Y_,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(Z_,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const e=F0().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){const t=new zi;t.translate(this.fillPatternX(),this.fillPatternY()),t.rotate(wt.getAngle(this.fillPatternRotation())),t.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),t.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());const n=t.getMatrix(),r=typeof DOMMatrix>"u"?{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]}:new DOMMatrix(n);e.setTransform(r)}return e}}_getLinearGradient(){return this._getCache(Q_,this.__getLinearGradient)}__getLinearGradient(){const e=this.fillLinearGradientColorStops();if(e){const t=F0(),n=this.fillLinearGradientStartPoint(),r=this.fillLinearGradientEndPoint(),o=t.createLinearGradient(n.x,n.y,r.x,r.y);for(let i=0;i<e.length;i+=2)o.addColorStop(e[i],e[i+1]);return o}}_getRadialGradient(){return this._getCache(J_,this.__getRadialGradient)}__getRadialGradient(){const e=this.fillRadialGradientColorStops();if(e){const t=F0(),n=this.fillRadialGradientStartPoint(),r=this.fillRadialGradientEndPoint(),o=t.createRadialGradient(n.x,n.y,this.fillRadialGradientStartRadius(),r.x,r.y,this.fillRadialGradientEndRadius());for(let i=0;i<e.length;i+=2)o.addColorStop(e[i],e[i+1]);return o}}getShadowRGBA(){return this._getCache(X_,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const e=xe.colorToRGBA(this.shadowColor());if(e)return"rgba("+e.r+","+e.g+","+e.b+","+e.a*(this.shadowOpacity()||1)+")"}hasFill(){return this._calculate("hasFill",["fillEnabled","fill","fillPatternImage","fillLinearGradientColorStops","fillRadialGradientColorStops"],()=>this.fillEnabled()&&!!(this.fill()||this.fillPatternImage()||this.fillLinearGradientColorStops()||this.fillRadialGradientColorStops()))}hasStroke(){return this._calculate("hasStroke",["strokeEnabled","strokeWidth","stroke","strokeLinearGradientColorStops"],()=>this.strokeEnabled()&&this.strokeWidth()&&!!(this.stroke()||this.strokeLinearGradientColorStops()))}hasHitStroke(){const e=this.hitStrokeWidth();return e==="auto"?this.hasStroke():this.strokeEnabled()&&!!e}intersects(e){const t=this.getStage();if(!t)return!1;const n=t.bufferHitCanvas;return n.getContext().clear(),this.drawHit(n,void 0,!0),n.context.getImageData(Math.round(e.x),Math.round(e.y),1,1).data[3]>0}destroy(){return St.prototype.destroy.call(this),delete Rf[this.colorKey],delete this.colorKey,this}_useBufferCanvas(e){var t;if(!(!((t=this.attrs.perfectDrawEnabled)!==null&&t!==void 0)||t))return!1;const n=e||this.hasFill(),r=this.hasStroke(),o=this.getAbsoluteOpacity()!==1;if(n&&r&&o)return!0;const i=this.hasShadow(),s=this.shadowForStrokeEnabled();return!!(n&&r&&i&&s)}setStrokeHitEnabled(e){xe.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),e?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){const e=this.size();return{x:this._centroid?-e.width/2:0,y:this._centroid?-e.height/2:0,width:e.width,height:e.height}}getClientRect(e={}){let t=!1,n=this.getParent();for(;n;){if(n.isCached()){t=!0;break}n=n.getParent()}const r=e.skipTransform,o=e.relativeTo||t&&this.getStage()||void 0,i=this.getSelfRect(),s=!e.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=i.width+s,l=i.height+s,c=!e.skipShadow&&this.hasShadow(),u=c?this.shadowOffsetX():0,d=c?this.shadowOffsetY():0,h=a+Math.abs(u),g=l+Math.abs(d),p=c&&this.shadowBlur()||0,v={width:h+p*2,height:g+p*2,x:-(s/2+p)+Math.min(u,0)+i.x,y:-(s/2+p)+Math.min(d,0)+i.y};return r?v:this._transformedRect(v,o)}drawScene(e,t,n){const r=this.getLayer(),o=(e||r.getCanvas()).getContext(),i=this._getCanvasCache(),s=this.getSceneFunc(),a=this.hasShadow();let l;const c=t===this;if(!this.isVisible()&&!c)return this;if(i){o.save();const u=this.getAbsoluteTransform(t).getMatrix();return o.transform(u[0],u[1],u[2],u[3],u[4],u[5]),this._drawCachedSceneCanvas(o),o.restore(),this}if(!s)return this;if(o.save(),this._useBufferCanvas()){l=this.getStage();const u=n||l.bufferCanvas,d=u.getContext();n?(d.save(),d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,u.width,u.height),d.restore()):d.clear(),d.save(),d._applyLineJoin(this),d._applyMiterLimit(this);const h=this.getAbsoluteTransform(t).getMatrix();d.transform(h[0],h[1],h[2],h[3],h[4],h[5]),s.call(this,d,this),d.restore();const g=u.pixelRatio;a&&o._applyShadow(this),c||(o._applyOpacity(this),o._applyGlobalCompositeOperation(this)),o.drawImage(u._canvas,u.x||0,u.y||0,u.width/g,u.height/g)}else{if(o._applyLineJoin(this),o._applyMiterLimit(this),!c){const u=this.getAbsoluteTransform(t).getMatrix();o.transform(u[0],u[1],u[2],u[3],u[4],u[5]),o._applyOpacity(this),o._applyGlobalCompositeOperation(this)}a&&o._applyShadow(this),s.call(this,o,this)}return o.restore(),this}drawHit(e,t,n=!1){if(!this.shouldDrawHit(t,n))return this;const r=this.getLayer(),o=e||r.hitCanvas,i=o&&o.getContext(),s=this.hitFunc()||this.sceneFunc(),a=this._getCanvasCache(),l=a&&a.hit;if(this.colorKey||xe.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){i.save();const c=this.getAbsoluteTransform(t).getMatrix();return i.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedHitCanvas(i),i.restore(),this}if(!s)return this;if(i.save(),i._applyLineJoin(this),i._applyMiterLimit(this),this!==t){const c=this.getAbsoluteTransform(t).getMatrix();i.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return s.call(this,i,this),i.restore(),this}drawHitFromCache(e=0){const t=this._getCanvasCache(),n=this._getCachedSceneCanvas(),r=t.hit,o=r.getContext(),i=r.getWidth(),s=r.getHeight();o.clear(),o.drawImage(n._canvas,0,0,i,s);try{const a=o.getImageData(0,0,i,s),l=a.data,c=l.length,u=xe._hexToRgb(this.colorKey);for(let d=0;d<c;d+=4)l[d+3]>e?(l[d]=u.r,l[d+1]=u.g,l[d+2]=u.b,l[d+3]=255):l[d+3]=0;o.putImageData(a,0,0)}catch(a){xe.error("Unable to draw hit graph from cached scene canvas. "+a.message)}return this}hasPointerCapture(e){return O_(e,this)}setPointerCapture(e){F_(e,this)}releaseCapture(e){Sf(e,this)}};gt.prototype._fillFunc=_O,gt.prototype._strokeFunc=AO,gt.prototype._fillFuncHit=IO,gt.prototype._strokeFuncHit=EO,gt.prototype._centroid=!1,gt.prototype.nodeType="Shape",kr(gt),gt.prototype.eventListeners={},gt.prototype.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",TO),gt.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",xO),gt.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",RO),gt.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",MO),gt.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",LO),de.addGetterSetter(gt,"stroke",void 0,T_()),de.addGetterSetter(gt,"strokeWidth",2,yt()),de.addGetterSetter(gt,"fillAfterStrokeEnabled",!1),de.addGetterSetter(gt,"hitStrokeWidth","auto",T0()),de.addGetterSetter(gt,"strokeHitEnabled",!0,Vi()),de.addGetterSetter(gt,"perfectDrawEnabled",!0,Vi()),de.addGetterSetter(gt,"shadowForStrokeEnabled",!0,Vi()),de.addGetterSetter(gt,"lineJoin"),de.addGetterSetter(gt,"lineCap"),de.addGetterSetter(gt,"miterLimit"),de.addGetterSetter(gt,"sceneFunc"),de.addGetterSetter(gt,"hitFunc"),de.addGetterSetter(gt,"dash"),de.addGetterSetter(gt,"dashOffset",0,yt()),de.addGetterSetter(gt,"shadowColor",void 0,Vl()),de.addGetterSetter(gt,"shadowBlur",0,yt()),de.addGetterSetter(gt,"shadowOpacity",1,yt()),de.addComponentsGetterSetter(gt,"shadowOffset",["x","y"]),de.addGetterSetter(gt,"shadowOffsetX",0,yt()),de.addGetterSetter(gt,"shadowOffsetY",0,yt()),de.addGetterSetter(gt,"fillPatternImage"),de.addGetterSetter(gt,"fill",void 0,T_()),de.addGetterSetter(gt,"fillPatternX",0,yt()),de.addGetterSetter(gt,"fillPatternY",0,yt()),de.addGetterSetter(gt,"fillLinearGradientColorStops"),de.addGetterSetter(gt,"strokeLinearGradientColorStops"),de.addGetterSetter(gt,"fillRadialGradientStartRadius",0),de.addGetterSetter(gt,"fillRadialGradientEndRadius",0),de.addGetterSetter(gt,"fillRadialGradientColorStops"),de.addGetterSetter(gt,"fillPatternRepeat","repeat"),de.addGetterSetter(gt,"fillEnabled",!0),de.addGetterSetter(gt,"strokeEnabled",!0),de.addGetterSetter(gt,"shadowEnabled",!0),de.addGetterSetter(gt,"dashEnabled",!0),de.addGetterSetter(gt,"strokeScaleEnabled",!0),de.addGetterSetter(gt,"fillPriority","color"),de.addComponentsGetterSetter(gt,"fillPatternOffset",["x","y"]),de.addGetterSetter(gt,"fillPatternOffsetX",0,yt()),de.addGetterSetter(gt,"fillPatternOffsetY",0,yt()),de.addComponentsGetterSetter(gt,"fillPatternScale",["x","y"]),de.addGetterSetter(gt,"fillPatternScaleX",1,yt()),de.addGetterSetter(gt,"fillPatternScaleY",1,yt()),de.addComponentsGetterSetter(gt,"fillLinearGradientStartPoint",["x","y"]),de.addComponentsGetterSetter(gt,"strokeLinearGradientStartPoint",["x","y"]),de.addGetterSetter(gt,"fillLinearGradientStartPointX",0),de.addGetterSetter(gt,"strokeLinearGradientStartPointX",0),de.addGetterSetter(gt,"fillLinearGradientStartPointY",0),de.addGetterSetter(gt,"strokeLinearGradientStartPointY",0),de.addComponentsGetterSetter(gt,"fillLinearGradientEndPoint",["x","y"]),de.addComponentsGetterSetter(gt,"strokeLinearGradientEndPoint",["x","y"]),de.addGetterSetter(gt,"fillLinearGradientEndPointX",0),de.addGetterSetter(gt,"strokeLinearGradientEndPointX",0),de.addGetterSetter(gt,"fillLinearGradientEndPointY",0),de.addGetterSetter(gt,"strokeLinearGradientEndPointY",0),de.addComponentsGetterSetter(gt,"fillRadialGradientStartPoint",["x","y"]),de.addGetterSetter(gt,"fillRadialGradientStartPointX",0),de.addGetterSetter(gt,"fillRadialGradientStartPointY",0),de.addComponentsGetterSetter(gt,"fillRadialGradientEndPoint",["x","y"]),de.addGetterSetter(gt,"fillRadialGradientEndPointX",0),de.addGetterSetter(gt,"fillRadialGradientEndPointY",0),de.addGetterSetter(gt,"fillPatternRotation",0),de.addGetterSetter(gt,"fillRule",void 0,Vl()),de.backCompat(gt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var PO="beforeDraw",DO="draw",e4=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],OO=e4.length,Ul=class extends fi{constructor(e){super(e),this.canvas=new Xa,this.hitCanvas=new E0({pixelRatio:1}),this._waitingForDraw=!1,this.on("visibleChange.konva",this._checkVisibility),this._checkVisibility(),this.on("imageSmoothingEnabledChange.konva",this._setSmoothEnabled),this._setSmoothEnabled()}createPNGStream(){return this.canvas._canvas.createPNGStream()}getCanvas(){return this.canvas}getNativeCanvasElement(){return this.canvas._canvas}getHitCanvas(){return this.hitCanvas}getContext(){return this.getCanvas().getContext()}clear(e){return this.getContext().clear(e),this.getHitCanvas().getContext().clear(e),this}setZIndex(e){super.setZIndex(e);const t=this.getStage();return t&&t.content&&(t.content.removeChild(this.getNativeCanvasElement()),e<t.children.length-1?t.content.insertBefore(this.getNativeCanvasElement(),t.children[e+1].getCanvas()._canvas):t.content.appendChild(this.getNativeCanvasElement())),this}moveToTop(){St.prototype.moveToTop.call(this);const e=this.getStage();return e&&e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.appendChild(this.getNativeCanvasElement())),!0}moveUp(){if(!St.prototype.moveUp.call(this))return!1;const e=this.getStage();return!e||!e.content?!1:(e.content.removeChild(this.getNativeCanvasElement()),this.index<e.children.length-1?e.content.insertBefore(this.getNativeCanvasElement(),e.children[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getNativeCanvasElement()),!0)}moveDown(){if(St.prototype.moveDown.call(this)){const e=this.getStage();if(e){const t=e.children;e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.insertBefore(this.getNativeCanvasElement(),t[this.index+1].getCanvas()._canvas))}return!0}return!1}moveToBottom(){if(St.prototype.moveToBottom.call(this)){const e=this.getStage();if(e){const t=e.children;e.content&&(e.content.removeChild(this.getNativeCanvasElement()),e.content.insertBefore(this.getNativeCanvasElement(),t[1].getCanvas()._canvas))}return!0}return!1}getLayer(){return this}remove(){const e=this.getNativeCanvasElement();return St.prototype.remove.call(this),e&&e.parentNode&&xe._isInDocument(e)&&e.parentNode.removeChild(e),this}getStage(){return this.parent}setSize({width:e,height:t}){return this.canvas.setSize(e,t),this.hitCanvas.setSize(e,t),this._setSmoothEnabled(),this}_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&xe.throw("You may only add groups and shapes to a layer.")}_toKonvaCanvas(e){return e={...e},e.width=e.width||this.getWidth(),e.height=e.height||this.getHeight(),e.x=e.x!==void 0?e.x:this.x(),e.y=e.y!==void 0?e.y:this.y(),St.prototype._toKonvaCanvas.call(this,e)}_checkVisibility(){this.visible()?this.canvas._canvas.style.display="block":this.canvas._canvas.style.display="none"}_setSmoothEnabled(){this.getContext()._context.imageSmoothingEnabled=this.imageSmoothingEnabled()}getWidth(){if(this.parent)return this.parent.width()}setWidth(){xe.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){xe.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,xe.requestAnimFrame(()=>{this.draw(),this._waitingForDraw=!1})),this}getIntersection(e){if(!this.isListening()||!this.isVisible())return null;let t=1,n=!1;for(;;){for(let r=0;r<OO;r++){const o=e4[r],i=this._getIntersection({x:e.x+o.x*t,y:e.y+o.y*t}),s=i.shape;if(s)return s;if(n=!!i.antialiased,!i.antialiased)break}if(n)t+=1;else return null}}_getIntersection(e){const t=this.hitCanvas.pixelRatio,n=this.hitCanvas.context.getImageData(Math.round(e.x*t),Math.round(e.y*t),1,1).data,r=n[3];if(r===255){const o=Rf[xe.getHitColorKey(n[0],n[1],n[2])];return o?{shape:o}:{antialiased:!0}}else if(r>0)return{antialiased:!0};return{}}drawScene(e,t,n){const r=this.getLayer(),o=e||r&&r.getCanvas();return this._fire(PO,{node:this}),this.clearBeforeDraw()&&o.getContext().clear(),fi.prototype.drawScene.call(this,o,t,n),this._fire(DO,{node:this}),this}drawHit(e,t){const n=this.getLayer(),r=e||n&&n.hitCanvas;return n&&n.clearBeforeDraw()&&n.getHitCanvas().getContext().clear(),fi.prototype.drawHit.call(this,r,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){xe.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(e)}getHitGraphEnabled(e){return xe.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}toggleHitCanvas(){if(!this.parent||!this.parent.content)return;const e=this.parent;this.hitCanvas._canvas.parentNode?e.content.removeChild(this.hitCanvas._canvas):e.content.appendChild(this.hitCanvas._canvas)}destroy(){return xe.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};Ul.prototype.nodeType="Layer",kr(Ul),de.addGetterSetter(Ul,"imageSmoothingEnabled",!0),de.addGetterSetter(Ul,"clearBeforeDraw",!0),de.addGetterSetter(Ul,"hitGraphEnabled",!0,Vi());var N0=class extends Ul{constructor(e){super(e),this.listening(!1),xe.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}};N0.prototype.nodeType="FastLayer",kr(N0);var du=class extends fi{_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&xe.throw("You may only add groups and shapes to groups.")}};du.prototype.nodeType="Group",kr(du);var B0=(function(){return zl.performance&&zl.performance.now?function(){return zl.performance.now()}:function(){return new Date().getTime()}})(),fu=class rd{constructor(t,n){this.id=rd.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:B0(),frameRate:0},this.func=t,this.setLayers(n)}setLayers(t){let n=[];return t&&(n=Array.isArray(t)?t:[t]),this.layers=n,this}getLayers(){return this.layers}addLayer(t){const n=this.layers,r=n.length;for(let o=0;o<r;o++)if(n[o]._id===t._id)return!1;return this.layers.push(t),!0}isRunning(){const t=rd.animations,n=t.length;for(let r=0;r<n;r++)if(t[r].id===this.id)return!0;return!1}start(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=B0(),rd._addAnimation(this),this}stop(){return rd._removeAnimation(this),this}_updateFrameObject(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}static _addAnimation(t){this.animations.push(t),this._handleAnimation()}static _removeAnimation(t){const n=t.id,r=this.animations,o=r.length;for(let i=0;i<o;i++)if(r[i].id===n){this.animations.splice(i,1);break}}static _runFrames(){const t={},n=this.animations;for(let r=0;r<n.length;r++){const o=n[r],i=o.layers,s=o.func;o._updateFrameObject(B0());const a=i.length;let l;if(s?l=s.call(o,o.frame)!==!1:l=!0,!!l)for(let c=0;c<a;c++){const u=i[c];u._id!==void 0&&(t[u._id]=u)}}for(const r in t)t.hasOwnProperty(r)&&t[r].batchDraw()}static _animationLoop(){const t=rd;t.animations.length?(t._runFrames(),xe.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,xe.requestAnimFrame(this._animationLoop))}};fu.animations=[],fu.animIdCounter=0,fu.animRunning=!1;var FO={node:1,duration:1,easing:1,onFinish:1,yoyo:1},NO=1,t4=2,n4=3,r4=["fill","stroke","shadowColor"],BO=0,zO=class{constructor(e,t,n,r,o,i,s){this.prop=e,this.propFunc=t,this.begin=r,this._pos=r,this.duration=i,this._change=0,this.prevPos=0,this.yoyo=s,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=n,this._change=o-this.begin,this.pause()}fire(e){const t=this[e];t&&t()}setTime(e){e>this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():e<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=e,this.update())}getTime(){return this._time}setPosition(e){this.prevPos=this._pos,this.propFunc(e),this._pos=e}getPosition(e){return e===void 0&&(e=this._time),this.func(e,this.begin,this._change,this.duration)}play(){this.state=t4,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=n4,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}seek(e){this.pause(),this._time=e,this.update(),this.fire("onSeek")}reset(){this.pause(),this._time=0,this.update(),this.fire("onReset")}finish(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}update(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}onEnterFrame(){const e=this.getTimer()-this._startTime;this.state===t4?this.setTime(e):this.state===n4&&this.setTime(this.duration-e)}pause(){this.state=NO,this.fire("onPause")}getTimer(){return new Date().getTime()}},rm=class Pr{constructor(t){const n=this,r=t.node,o=r._id,i=t.easing||Mf.Linear,s=!!t.yoyo;let a,l;typeof t.duration>"u"?a=.3:t.duration===0?a=.001:a=t.duration,this.node=r,this._id=BO++;const c=r.getLayer()||(r instanceof wt.Stage?r.getLayers():null);c||xe.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new fu(function(){n.tween.onEnterFrame()},c),this.tween=new zO(l,function(u){n._tweenFunc(u)},i,0,1,a*1e3,s),this._addListeners(),Pr.attrs[o]||(Pr.attrs[o]={}),Pr.attrs[o][this._id]||(Pr.attrs[o][this._id]={}),Pr.tweens[o]||(Pr.tweens[o]={});for(l in t)FO[l]===void 0&&this._addAttr(l,t[l]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,n){const r=this.node,o=r._id;let i,s,a,l,c;const u=Pr.tweens[o][t];u&&delete Pr.attrs[o][u][t];let d=r.getAttr(t);if(xe._isArray(n))if(i=[],s=Math.max(n.length,d.length),t==="points"&&n.length!==d.length&&(n.length>d.length?(l=d,d=xe._prepareArrayForTween(d,n,r.closed())):(a=n,n=xe._prepareArrayForTween(n,d,r.closed()))),t.indexOf("fill")===0)for(let h=0;h<s;h++)if(h%2===0)i.push(n[h]-d[h]);else{const g=xe.colorToRGBA(d[h]);c=xe.colorToRGBA(n[h]),d[h]=g,i.push({r:c.r-g.r,g:c.g-g.g,b:c.b-g.b,a:c.a-g.a})}else for(let h=0;h<s;h++)i.push(n[h]-d[h]);else r4.indexOf(t)!==-1?(d=xe.colorToRGBA(d),c=xe.colorToRGBA(n),i={r:c.r-d.r,g:c.g-d.g,b:c.b-d.b,a:c.a-d.a}):i=n-d;Pr.attrs[o][this._id][t]={start:d,diff:i,end:n,trueEnd:a,trueStart:l},Pr.tweens[o][t]=this._id}_tweenFunc(t){const n=this.node,r=Pr.attrs[n._id][this._id];let o,i,s,a,l,c,u,d;for(o in r){if(i=r[o],s=i.start,a=i.diff,d=i.end,xe._isArray(s))if(l=[],u=Math.max(s.length,d.length),o.indexOf("fill")===0)for(c=0;c<u;c++)c%2===0?l.push((s[c]||0)+a[c]*t):l.push("rgba("+Math.round(s[c].r+a[c].r*t)+","+Math.round(s[c].g+a[c].g*t)+","+Math.round(s[c].b+a[c].b*t)+","+(s[c].a+a[c].a*t)+")");else for(c=0;c<u;c++)l.push((s[c]||0)+a[c]*t);else r4.indexOf(o)!==-1?l="rgba("+Math.round(s.r+a.r*t)+","+Math.round(s.g+a.g*t)+","+Math.round(s.b+a.b*t)+","+(s.a+a.a*t)+")":l=s+a*t;n.setAttr(o,l)}}_addListeners(){this.tween.onPlay=()=>{this.anim.start()},this.tween.onReverse=()=>{this.anim.start()},this.tween.onPause=()=>{this.anim.stop()},this.tween.onFinish=()=>{const t=this.node,n=Pr.attrs[t._id][this._id];n.points&&n.points.trueEnd&&t.setAttr("points",n.points.trueEnd),this.onFinish&&this.onFinish.call(this)},this.tween.onReset=()=>{const t=this.node,n=Pr.attrs[t._id][this._id];n.points&&n.points.trueStart&&t.points(n.points.trueStart),this.onReset&&this.onReset()},this.tween.onUpdate=()=>{this.onUpdate&&this.onUpdate.call(this)}}play(){return this.tween.play(),this}reverse(){return this.tween.reverse(),this}reset(){return this.tween.reset(),this}seek(t){return this.tween.seek(t*1e3),this}pause(){return this.tween.pause(),this}finish(){return this.tween.finish(),this}destroy(){const t=this.node._id,n=this._id,r=Pr.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const o in r)delete Pr.tweens[t][o];delete Pr.attrs[t][n],Pr.tweens[t]&&(Object.keys(Pr.tweens[t]).length===0&&delete Pr.tweens[t],Object.keys(Pr.attrs[t]).length===0&&delete Pr.attrs[t])}};rm.attrs={},rm.tweens={},St.prototype.to=function(e){const t=e.onFinish;e.node=this,e.onFinish=function(){this.destroy(),t&&t()},new rm(e).play()};var Mf={BackEaseIn(e,t,n,r){return n*(e/=r)*e*(2.70158*e-1.70158)+t},BackEaseOut(e,t,n,r){return n*((e=e/r-1)*e*(2.70158*e+1.70158)+1)+t},BackEaseInOut(e,t,n,r){let o=1.70158;return(e/=r/2)<1?n/2*(e*e*(((o*=1.525)+1)*e-o))+t:n/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+t},ElasticEaseIn(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r)===1?t+n:(i||(i=r*.3),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),-(o*Math.pow(2,10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i))+t)},ElasticEaseOut(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r)===1?t+n:(i||(i=r*.3),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),o*Math.pow(2,-10*e)*Math.sin((e*r-s)*(2*Math.PI)/i)+n+t)},ElasticEaseInOut(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r/2)===2?t+n:(i||(i=r*(.3*1.5)),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),e<1?-.5*(o*Math.pow(2,10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i))+t:o*Math.pow(2,-10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i)*.5+n+t)},BounceEaseOut(e,t,n,r){return(e/=r)<1/2.75?n*(7.5625*e*e)+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t},BounceEaseIn(e,t,n,r){return n-Mf.BounceEaseOut(r-e,0,n,r)+t},BounceEaseInOut(e,t,n,r){return e<r/2?Mf.BounceEaseIn(e*2,0,n,r)*.5+t:Mf.BounceEaseOut(e*2-r,0,n,r)*.5+n*.5+t},EaseIn(e,t,n,r){return n*(e/=r)*e+t},EaseOut(e,t,n,r){return-n*(e/=r)*(e-2)+t},EaseInOut(e,t,n,r){return(e/=r/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t},StrongEaseIn(e,t,n,r){return n*(e/=r)*e*e*e*e+t},StrongEaseOut(e,t,n,r){return n*((e=e/r-1)*e*e*e*e+1)+t},StrongEaseInOut(e,t,n,r){return(e/=r/2)<1?n/2*e*e*e*e*e+t:n/2*((e-=2)*e*e*e*e+2)+t},Linear(e,t,n,r){return n*e/r+t}},o4=xe._assign(wt,{Util:xe,Transform:zi,Node:St,Container:fi,Stage:tm,stages:xf,Layer:Ul,FastLayer:N0,Group:du,DD:On,Shape:gt,shapes:Rf,Animation:fu,Tween:rm,Easings:Mf,Context:Kp,Canvas:I0}),ca=class extends gt{_sceneFunc(e){const t=wt.getAngle(this.angle()),n=this.clockwise();e.beginPath(),e.arc(0,0,this.outerRadius(),0,t,n),e.arc(0,0,this.innerRadius(),t,0,!n),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}getSelfRect(){const e=this.innerRadius(),t=this.outerRadius(),n=this.clockwise(),r=wt.getAngle(n?360-this.angle():this.angle()),o=Math.cos(Math.min(r,Math.PI)),i=1,s=Math.sin(Math.min(Math.max(Math.PI,r),3*Math.PI/2)),a=Math.sin(Math.min(r,Math.PI/2)),l=o*(o>0?e:t),c=i*t,u=s*(s>0?e:t),d=a*(a>0?t:e);return{x:l,y:n?-1*d:u,width:c-l,height:d-u}}};ca.prototype._centroid=!0,ca.prototype.className="Arc",ca.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],kr(ca),de.addGetterSetter(ca,"innerRadius",0,yt()),de.addGetterSetter(ca,"outerRadius",0,yt()),de.addGetterSetter(ca,"angle",0,yt()),de.addGetterSetter(ca,"clockwise",!1,Vi());function z0(e,t,n,r,o,i,s){const a=Math.sqrt(Math.pow(n-e,2)+Math.pow(r-t,2)),l=Math.sqrt(Math.pow(o-n,2)+Math.pow(i-r,2)),c=s*a/(a+l),u=s*l/(a+l);return[n-c*(o-e),r-c*(i-t),n+u*(o-e),r+u*(i-t)]}function i4(e,t){const n=e.length,r=[];for(let o=2;o<n-2;o+=2){const i=z0(e[o-2],e[o-1],e[o],e[o+1],e[o+2],e[o+3],t);isNaN(i[0])||(r.push(i[0]),r.push(i[1]),r.push(e[o]),r.push(e[o+1]),r.push(i[2]),r.push(i[3]))}return r}function VO(e){const t=[[e[0],e[2],e[4],e[6]],[e[1],e[3],e[5],e[7]]],n=[];for(const r of t){const o=-3*r[0]+9*r[1]-9*r[2]+3*r[3];if(o!==0){const i=6*r[0]-12*r[1]+6*r[2],s=-3*r[0]+3*r[1],a=i*i-4*o*s;if(a>=0){const l=Math.sqrt(a);n.push((-i+l)/(2*o)),n.push((-i-l)/(2*o))}}}return n.filter(r=>r>0&&r<1).flatMap(r=>t.map(o=>{const i=1-r;return i*i*i*o[0]+3*i*i*r*o[1]+3*i*r*r*o[2]+r*r*r*o[3]}))}var ua=class extends gt{constructor(e){super(e),this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")})}_sceneFunc(e){const t=this.points(),n=t.length,r=this.tension(),o=this.closed(),i=this.bezier();if(!n)return;let s=0;if(e.beginPath(),e.moveTo(t[0],t[1]),r!==0&&n>4){const a=this.getTensionPoints(),l=a.length;for(s=o?0:4,o||e.quadraticCurveTo(a[0],a[1],a[2],a[3]);s<l-2;)e.bezierCurveTo(a[s++],a[s++],a[s++],a[s++],a[s++],a[s++]);o||e.quadraticCurveTo(a[l-2],a[l-1],t[n-2],t[n-1])}else if(i)for(s=2;s<n;)e.bezierCurveTo(t[s++],t[s++],t[s++],t[s++],t[s++],t[s++]);else for(s=2;s<n;s+=2)e.lineTo(t[s],t[s+1]);o?(e.closePath(),e.fillStrokeShape(this)):e.strokeShape(this)}getTensionPoints(){return this._getCache("tensionPoints",this._getTensionPoints)}_getTensionPoints(){return this.closed()?this._getTensionPointsClosed():i4(this.points(),this.tension())}_getTensionPointsClosed(){const e=this.points(),t=e.length,n=this.tension(),r=z0(e[t-2],e[t-1],e[0],e[1],e[2],e[3],n),o=z0(e[t-4],e[t-3],e[t-2],e[t-1],e[0],e[1],n),i=i4(e,n);return[r[2],r[3]].concat(i).concat([o[0],o[1],e[t-2],e[t-1],o[2],o[3],r[0],r[1],e[0],e[1]])}getWidth(){return this.getSelfRect().width}getHeight(){return this.getSelfRect().height}getSelfRect(){let e=this.points();if(e.length<4)return{x:e[0]||0,y:e[1]||0,width:0,height:0};this.tension()!==0?e=[e[0],e[1],...this._getTensionPoints(),e[e.length-2],e[e.length-1]]:this.bezier()?e=[e[0],e[1],...VO(this.points()),e[e.length-2],e[e.length-1]]:e=this.points();let t=e[0],n=e[0],r=e[1],o=e[1],i,s;for(let a=0;a<e.length/2;a++)i=e[a*2],s=e[a*2+1],t=Math.min(t,i),n=Math.max(n,i),r=Math.min(r,s),o=Math.max(o,s);return{x:t,y:r,width:n-t,height:o-r}}};ua.prototype.className="Line",ua.prototype._attrsAffectingSize=["points","bezier","tension"],kr(ua),de.addGetterSetter(ua,"closed",!1),de.addGetterSetter(ua,"bezier",!1),de.addGetterSetter(ua,"tension",0,yt()),de.addGetterSetter(ua,"points",[],nO());var jO=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],UO=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],HO=[[1],[1,1],[1,2,1],[1,3,3,1]],s4=(e,t,n)=>{let r,o;const s=n/2;r=0;for(let a=0;a<20;a++)o=s*jO[20][a]+s,r+=UO[20][a]*$O(e,t,o);return s*r},a4=(e,t,n)=>{n===void 0&&(n=1);const r=e[0]-2*e[1]+e[2],o=t[0]-2*t[1]+t[2],i=2*e[1]-2*e[0],s=2*t[1]-2*t[0],a=4*(r*r+o*o),l=4*(r*i+o*s),c=i*i+s*s;if(a===0)return n*Math.sqrt(Math.pow(e[2]-e[0],2)+Math.pow(t[2]-t[0],2));const u=l/(2*a),d=c/a,h=n+u,g=d-u*u,p=h*h+g>0?Math.sqrt(h*h+g):0,v=u*u+g>0?Math.sqrt(u*u+g):0,k=u+Math.sqrt(u*u+g)!==0?g*Math.log(Math.abs((h+p)/(u+v))):0;return Math.sqrt(a)/2*(h*p-u*v+k)};function $O(e,t,n){const r=V0(1,n,e),o=V0(1,n,t),i=r*r+o*o;return Math.sqrt(i)}var V0=(e,t,n)=>{const r=n.length-1;let o,i;if(r===0)return 0;if(e===0){i=0;for(let s=0;s<=r;s++)i+=HO[r][s]*Math.pow(1-t,r-s)*Math.pow(t,s)*n[s];return i}else{o=new Array(r);for(let s=0;s<r;s++)o[s]=r*(n[s+1]-n[s]);return V0(e-1,t,o)}},l4=(e,t,n)=>{let r=1,o=e/t,i=(e-n(o))/t,s=0;for(;r>.001;){const a=n(o+i),l=Math.abs(e-a)/t;if(l<r)r=l,o+=i;else{const c=n(o-i),u=Math.abs(e-c)/t;u<r?(r=u,o-=i):i/=2}if(s++,s>500)break}return o},Si=class si extends gt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=si.parsePathData(this.data()),this.pathLength=si.getPathLength(this.dataArray)}_sceneFunc(t){const n=this.dataArray;t.beginPath();let r=!1;for(let o=0;o<n.length;o++){const i=n[o].command,s=n[o].points;switch(i){case"L":t.lineTo(s[0],s[1]);break;case"M":t.moveTo(s[0],s[1]);break;case"C":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"Q":t.quadraticCurveTo(s[0],s[1],s[2],s[3]);break;case"A":const a=s[0],l=s[1],c=s[2],u=s[3],d=s[4],h=s[5],g=s[6],p=s[7],v=c>u?c:u,k=c>u?1:c/u,C=c>u?u/c:1;t.translate(a,l),t.rotate(g),t.scale(k,C),t.arc(0,0,v,d,d+h,1-p),t.scale(1/k,1/C),t.rotate(-g),t.translate(-a,-l);break;case"z":r=!0,t.closePath();break}}!r&&!this.hasFill()?t.strokeShape(this):t.fillStrokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(l){if(l.command==="A"){const c=l.points[4],u=l.points[5],d=l.points[4]+u;let h=Math.PI/180;if(Math.abs(c-d)<h&&(h=Math.abs(c-d)),u<0)for(let g=c-h;g>d;g-=h){const p=si.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],g,0);t.push(p.x,p.y)}else for(let g=c+h;g<d;g+=h){const p=si.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],g,0);t.push(p.x,p.y)}}else if(l.command==="C")for(let c=0;c<=1;c+=.01){const u=si.getPointOnCubicBezier(c,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3],l.points[4],l.points[5]);t.push(u.x,u.y)}else t=t.concat(l.points)});let n=t[0],r=t[0],o=t[1],i=t[1],s,a;for(let l=0;l<t.length/2;l++)s=t[l*2],a=t[l*2+1],isNaN(s)||(n=Math.min(n,s),r=Math.max(r,s)),isNaN(a)||(o=Math.min(o,a),i=Math.max(i,a));return{x:n,y:o,width:r-n,height:i-o}}getLength(){return this.pathLength}getPointAtLength(t){return si.getPointAtLengthOfDataArray(t,this.dataArray)}static getLineLength(t,n,r,o){return Math.sqrt((r-t)*(r-t)+(o-n)*(o-n))}static getPathLength(t){let n=0;for(let r=0;r<t.length;++r)n+=t[r].pathLength;return n}static getPointAtLengthOfDataArray(t,n){let r,o=0,i=n.length;if(!i)return null;for(;o<i&&t>n[o].pathLength;)t-=n[o].pathLength,++o;if(o===i)return r=n[o-1].points.slice(-2),{x:r[0],y:r[1]};if(t<.01)return n[o].command==="M"?(r=n[o].points.slice(0,2),{x:r[0],y:r[1]}):{x:n[o].start.x,y:n[o].start.y};const s=n[o],a=s.points;switch(s.command){case"L":return si.getPointOnLine(t,s.start.x,s.start.y,a[0],a[1]);case"C":return si.getPointOnCubicBezier(l4(t,si.getPathLength(n),v=>s4([s.start.x,a[0],a[2],a[4]],[s.start.y,a[1],a[3],a[5]],v)),s.start.x,s.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return si.getPointOnQuadraticBezier(l4(t,si.getPathLength(n),v=>a4([s.start.x,a[0],a[2]],[s.start.y,a[1],a[3]],v)),s.start.x,s.start.y,a[0],a[1],a[2],a[3]);case"A":const l=a[0],c=a[1],u=a[2],d=a[3],h=a[5],g=a[6];let p=a[4];return p+=h*t/s.pathLength,si.getPointOnEllipticalArc(l,c,u,d,p,g)}return null}static getPointOnLine(t,n,r,o,i,s,a){s=s??n,a=a??r;const l=this.getLineLength(n,r,o,i);if(l<1e-10)return{x:n,y:r};if(o===n)return{x:s,y:a+(i>r?t:-t)};const c=(i-r)/(o-n),u=Math.sqrt(t*t/(1+c*c))*(o<n?-1:1),d=c*u;if(Math.abs(a-r-c*(s-n))<1e-10)return{x:s+u,y:a+d};const h=((s-n)*(o-n)+(a-r)*(i-r))/(l*l),g=n+h*(o-n),p=r+h*(i-r),v=this.getLineLength(s,a,g,p),k=Math.sqrt(t*t-v*v),C=Math.sqrt(k*k/(1+c*c))*(o<n?-1:1),_=c*C;return{x:g+C,y:p+_}}static getPointOnCubicBezier(t,n,r,o,i,s,a,l,c){function u(p){return p*p*p}function d(p){return 3*p*p*(1-p)}function h(p){return 3*p*(1-p)*(1-p)}function g(p){return(1-p)*(1-p)*(1-p)}return{x:l*u(t)+s*d(t)+o*h(t)+n*g(t),y:c*u(t)+a*d(t)+i*h(t)+r*g(t)}}static getPointOnQuadraticBezier(t,n,r,o,i,s,a){function l(d){return d*d}function c(d){return 2*d*(1-d)}function u(d){return(1-d)*(1-d)}return{x:s*l(t)+o*c(t)+n*u(t),y:a*l(t)+i*c(t)+r*u(t)}}static getPointOnEllipticalArc(t,n,r,o,i,s){const a=Math.cos(s),l=Math.sin(s),c={x:r*Math.cos(i),y:o*Math.sin(i)};return{x:t+(c.x*a-c.y*l),y:n+(c.x*l+c.y*a)}}static parsePathData(t){if(!t)return[];let n=t;const r=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];n=n.replace(new RegExp(" ","g"),",");for(let d=0;d<r.length;d++)n=n.replace(new RegExp(r[d],"g"),"|"+r[d]);const o=n.split("|"),i=[],s=[];let a=0,l=0;const c=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let u;for(let d=1;d<o.length;d++){let h=o[d],g=h.charAt(0);for(h=h.slice(1),s.length=0;u=c.exec(h);)s.push(u[0]);let p=[],v=g==="A"||g==="a"?0:-1;for(let k=0,C=s.length;k<C;k++){const _=s[k];if(_==="00"){p.push(0,0),v>=0&&(v+=2,v>=7&&(v-=7));continue}if(v>=0){if(v===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(_)){p.push(parseInt(_[0],10)),p.push(parseInt(_[1],10)),p.push(parseFloat(_.slice(2))),v+=3,v>=7&&(v-=7);continue}if(_==="11"||_==="10"||_==="01"){p.push(parseInt(_[0],10)),p.push(parseInt(_[1],10)),v+=2,v>=7&&(v-=7);continue}if(_==="0"||_==="1"){p.push(parseInt(_,10)),v+=1,v>=7&&(v-=7);continue}}else if(v===4){if(/^[01]\d+(?:\.\d+)?$/.test(_)){p.push(parseInt(_[0],10)),p.push(parseFloat(_.slice(1))),v+=2,v>=7&&(v-=7);continue}if(_==="0"||_==="1"){p.push(parseInt(_,10)),v+=1,v>=7&&(v-=7);continue}}const y=parseFloat(_);isNaN(y)?p.push(0):p.push(y),v+=1,v>=7&&(v-=7)}else{const y=parseFloat(_);isNaN(y)?p.push(0):p.push(y)}}for(;p.length>0&&!isNaN(p[0]);){let k="",C=[];const _=a,y=l;let w,x,L,z,$,R,F,X,D,V;switch(g){case"l":a+=p.shift(),l+=p.shift(),k="L",C.push(a,l);break;case"L":a=p.shift(),l=p.shift(),C.push(a,l);break;case"m":const T=p.shift(),N=p.shift();if(a+=T,l+=N,k="M",i.length>2&&i[i.length-1].command==="z"){for(let Q=i.length-2;Q>=0;Q--)if(i[Q].command==="M"){a=i[Q].points[0]+T,l=i[Q].points[1]+N;break}}C.push(a,l),g="l";break;case"M":a=p.shift(),l=p.shift(),k="M",C.push(a,l),g="L";break;case"h":a+=p.shift(),k="L",C.push(a,l);break;case"H":a=p.shift(),k="L",C.push(a,l);break;case"v":l+=p.shift(),k="L",C.push(a,l);break;case"V":l=p.shift(),k="L",C.push(a,l);break;case"C":C.push(p.shift(),p.shift(),p.shift(),p.shift()),a=p.shift(),l=p.shift(),C.push(a,l);break;case"c":C.push(a+p.shift(),l+p.shift(),a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="C",C.push(a,l);break;case"S":x=a,L=l,w=i[i.length-1],w.command==="C"&&(x=a+(a-w.points[2]),L=l+(l-w.points[3])),C.push(x,L,p.shift(),p.shift()),a=p.shift(),l=p.shift(),k="C",C.push(a,l);break;case"s":x=a,L=l,w=i[i.length-1],w.command==="C"&&(x=a+(a-w.points[2]),L=l+(l-w.points[3])),C.push(x,L,a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="C",C.push(a,l);break;case"Q":C.push(p.shift(),p.shift()),a=p.shift(),l=p.shift(),C.push(a,l);break;case"q":C.push(a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="Q",C.push(a,l);break;case"T":x=a,L=l,w=i[i.length-1],w.command==="Q"&&(x=a+(a-w.points[0]),L=l+(l-w.points[1])),a=p.shift(),l=p.shift(),k="Q",C.push(x,L,a,l);break;case"t":x=a,L=l,w=i[i.length-1],w.command==="Q"&&(x=a+(a-w.points[0]),L=l+(l-w.points[1])),a+=p.shift(),l+=p.shift(),k="Q",C.push(x,L,a,l);break;case"A":z=p.shift(),$=p.shift(),R=p.shift(),F=p.shift(),X=p.shift(),D=a,V=l,a=p.shift(),l=p.shift(),k="A",C=this.convertEndpointToCenterParameterization(D,V,a,l,F,X,z,$,R);break;case"a":z=p.shift(),$=p.shift(),R=p.shift(),F=p.shift(),X=p.shift(),D=a,V=l,a+=p.shift(),l+=p.shift(),k="A",C=this.convertEndpointToCenterParameterization(D,V,a,l,F,X,z,$,R);break}i.push({command:k||g,points:C,start:{x:_,y},pathLength:this.calcLength(_,y,k||g,C)})}(g==="z"||g==="Z")&&i.push({command:"z",points:[],start:void 0,pathLength:0})}return i}static calcLength(t,n,r,o){let i,s,a,l;const c=si;switch(r){case"L":return c.getLineLength(t,n,o[0],o[1]);case"C":return s4([t,o[0],o[2],o[4]],[n,o[1],o[3],o[5]],1);case"Q":return a4([t,o[0],o[2]],[n,o[1],o[3]],1);case"A":i=0;const u=o[4],d=o[5],h=o[4]+d;let g=Math.PI/180;if(Math.abs(u-h)<g&&(g=Math.abs(u-h)),s=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],u,0),d<0)for(l=u-g;l>h;l-=g)a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),s=a;else for(l=u+g;l<h;l+=g)a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),s=a;return a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],h,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),i}return 0}static convertEndpointToCenterParameterization(t,n,r,o,i,s,a,l,c){const u=c*(Math.PI/180),d=Math.cos(u)*(t-r)/2+Math.sin(u)*(n-o)/2,h=-1*Math.sin(u)*(t-r)/2+Math.cos(u)*(n-o)/2,g=d*d/(a*a)+h*h/(l*l);g>1&&(a*=Math.sqrt(g),l*=Math.sqrt(g));let p=Math.sqrt((a*a*(l*l)-a*a*(h*h)-l*l*(d*d))/(a*a*(h*h)+l*l*(d*d)));i===s&&(p*=-1),isNaN(p)&&(p=0);const v=p*a*h/l,k=p*-l*d/a,C=(t+r)/2+Math.cos(u)*v-Math.sin(u)*k,_=(n+o)/2+Math.sin(u)*v+Math.cos(u)*k,y=function(F){return Math.sqrt(F[0]*F[0]+F[1]*F[1])},w=function(F,X){return(F[0]*X[0]+F[1]*X[1])/(y(F)*y(X))},x=function(F,X){return(F[0]*X[1]<F[1]*X[0]?-1:1)*Math.acos(w(F,X))},L=x([1,0],[(d-v)/a,(h-k)/l]),z=[(d-v)/a,(h-k)/l],$=[(-1*d-v)/a,(-1*h-k)/l];let R=x(z,$);return w(z,$)<=-1&&(R=Math.PI),w(z,$)>=1&&(R=0),s===0&&R>0&&(R=R-2*Math.PI),s===1&&R<0&&(R=R+2*Math.PI),[C,_,a,l,L,R,u,s]}};Si.prototype.className="Path",Si.prototype._attrsAffectingSize=["data"],kr(Si),de.addGetterSetter(Si,"data");var Hl=class extends ua{_sceneFunc(e){super._sceneFunc(e);const t=Math.PI*2,n=this.points();let r=n;const o=this.tension()!==0&&n.length>4;o&&(r=this.getTensionPoints());const i=this.pointerLength(),s=n.length;let a,l;if(o){const d=[r[r.length-4],r[r.length-3],r[r.length-2],r[r.length-1],n[s-2],n[s-1]],h=Si.calcLength(r[r.length-4],r[r.length-3],"C",d),g=Si.getPointOnQuadraticBezier(Math.min(1,1-i/h),d[0],d[1],d[2],d[3],d[4],d[5]);a=n[s-2]-g.x,l=n[s-1]-g.y}else a=n[s-2]-n[s-4],l=n[s-1]-n[s-3];const c=(Math.atan2(l,a)+t)%t,u=this.pointerWidth();this.pointerAtEnding()&&(e.save(),e.beginPath(),e.translate(n[s-2],n[s-1]),e.rotate(c),e.moveTo(0,0),e.lineTo(-i,u/2),e.lineTo(-i,-u/2),e.closePath(),e.restore(),this.__fillStroke(e)),this.pointerAtBeginning()&&(e.save(),e.beginPath(),e.translate(n[0],n[1]),o?(a=(r[0]+r[2])/2-n[0],l=(r[1]+r[3])/2-n[1]):(a=n[2]-n[0],l=n[3]-n[1]),e.rotate((Math.atan2(-l,-a)+t)%t),e.moveTo(0,0),e.lineTo(-i,u/2),e.lineTo(-i,-u/2),e.closePath(),e.restore(),this.__fillStroke(e))}__fillStroke(e){const t=this.dashEnabled();t&&(this.attrs.dashEnabled=!1,e.setLineDash([])),e.fillStrokeShape(this),t&&(this.attrs.dashEnabled=!0)}getSelfRect(){const e=super.getSelfRect(),t=this.pointerWidth()/2;return{x:e.x,y:e.y-t,width:e.width,height:e.height+t*2}}};Hl.prototype.className="Arrow",kr(Hl),de.addGetterSetter(Hl,"pointerLength",10,yt()),de.addGetterSetter(Hl,"pointerWidth",10,yt()),de.addGetterSetter(Hl,"pointerAtBeginning",!1),de.addGetterSetter(Hl,"pointerAtEnding",!0);var hu=class extends gt{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.attrs.radius||0,0,Math.PI*2,!1),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius()!==e/2&&this.radius(e/2)}setHeight(e){this.radius()!==e/2&&this.radius(e/2)}};hu.prototype._centroid=!0,hu.prototype.className="Circle",hu.prototype._attrsAffectingSize=["radius"],kr(hu),de.addGetterSetter(hu,"radius",0,yt());var Ja=class extends gt{_sceneFunc(e){const t=this.radiusX(),n=this.radiusY();e.beginPath(),e.save(),t!==n&&e.scale(1,n/t),e.arc(0,0,t,0,Math.PI*2,!1),e.restore(),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radiusX()*2}getHeight(){return this.radiusY()*2}setWidth(e){this.radiusX(e/2)}setHeight(e){this.radiusY(e/2)}};Ja.prototype.className="Ellipse",Ja.prototype._centroid=!0,Ja.prototype._attrsAffectingSize=["radiusX","radiusY"],kr(Ja),de.addComponentsGetterSetter(Ja,"radius",["x","y"]),de.addGetterSetter(Ja,"radiusX",0,yt()),de.addGetterSetter(Ja,"radiusY",0,yt());var ji=class iI extends gt{constructor(t){super(t),this._loadListener=()=>{this._requestDraw()},this.on("imageChange.konva",n=>{this._removeImageLoad(n.oldVal),this._setImageLoad()}),this._setImageLoad()}_setImageLoad(){const t=this.image();t&&t.complete||t&&t.readyState===4||t&&t.addEventListener&&t.addEventListener("load",this._loadListener)}_removeImageLoad(t){t&&t.removeEventListener&&t.removeEventListener("load",this._loadListener)}destroy(){return this._removeImageLoad(this.image()),super.destroy(),this}_useBufferCanvas(){const t=!!this.cornerRadius(),n=this.hasShadow();return t&&n?!0:super._useBufferCanvas(!0)}_sceneFunc(t){const n=this.getWidth(),r=this.getHeight(),o=this.cornerRadius(),i=this.attrs.image;let s;if(i){const a=this.attrs.cropWidth,l=this.attrs.cropHeight;a&&l?s=[i,this.cropX(),this.cropY(),a,l,0,0,n,r]:s=[i,0,0,n,r]}(this.hasFill()||this.hasStroke()||o)&&(t.beginPath(),o?xe.drawRoundedRectPath(t,n,r,o):t.rect(0,0,n,r),t.closePath(),t.fillStrokeShape(this)),i&&(o&&t.clip(),t.drawImage.apply(t,s))}_hitFunc(t){const n=this.width(),r=this.height(),o=this.cornerRadius();t.beginPath(),o?xe.drawRoundedRectPath(t,n,r,o):t.rect(0,0,n,r),t.closePath(),t.fillStrokeShape(this)}getWidth(){var t,n,r;return(r=(t=this.attrs.width)!==null&&t!==void 0?t:(n=this.image())===null||n===void 0?void 0:n.width)!==null&&r!==void 0?r:0}getHeight(){var t,n,r;return(r=(t=this.attrs.height)!==null&&t!==void 0?t:(n=this.image())===null||n===void 0?void 0:n.height)!==null&&r!==void 0?r:0}static fromURL(t,n,r=null){const o=xe.createImageElement();o.onload=function(){n(new iI({image:o}))},o.onerror=r,o.crossOrigin="Anonymous",o.src=t}};ji.prototype.className="Image",ji.prototype._attrsAffectingSize=["image"],kr(ji),de.addGetterSetter(ji,"cornerRadius",0,Yp(4)),de.addGetterSetter(ji,"image"),de.addComponentsGetterSetter(ji,"crop",["x","y","width","height"]),de.addGetterSetter(ji,"cropX",0,yt()),de.addGetterSetter(ji,"cropY",0,yt()),de.addGetterSetter(ji,"cropWidth",0,yt()),de.addGetterSetter(ji,"cropHeight",0,yt());var c4=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],GO="Change.konva",WO="none",j0="up",U0="right",H0="down",$0="left",KO=c4.length,G0=class extends du{constructor(e){super(e),this.on("add.konva",function(t){this._addListeners(t.child),this._sync()})}getText(){return this.find("Text")[0]}getTag(){return this.find("Tag")[0]}_addListeners(e){let t=this,n;const r=function(){t._sync()};for(n=0;n<KO;n++)e.on(c4[n]+GO,r)}getWidth(){return this.getText().width()}getHeight(){return this.getText().height()}_sync(){let e=this.getText(),t=this.getTag(),n,r,o,i,s,a,l;if(e&&t){switch(n=e.width(),r=e.height(),o=t.pointerDirection(),i=t.pointerWidth(),l=t.pointerHeight(),s=0,a=0,o){case j0:s=n/2,a=-1*l;break;case U0:s=n+i,a=r/2;break;case H0:s=n/2,a=r+l;break;case $0:s=-1*i,a=r/2;break}t.setAttrs({x:-1*s,y:-1*a,width:n,height:r}),e.setAttrs({x:-1*s,y:-1*a})}}};G0.prototype.className="Label",kr(G0);var $l=class extends gt{_sceneFunc(e){const t=this.width(),n=this.height(),r=this.pointerDirection(),o=this.pointerWidth(),i=this.pointerHeight(),s=this.cornerRadius();let a=0,l=0,c=0,u=0;typeof s=="number"?a=l=c=u=Math.min(s,t/2,n/2):(a=Math.min(s[0]||0,t/2,n/2),l=Math.min(s[1]||0,t/2,n/2),u=Math.min(s[2]||0,t/2,n/2),c=Math.min(s[3]||0,t/2,n/2)),e.beginPath(),e.moveTo(a,0),r===j0&&(e.lineTo((t-o)/2,0),e.lineTo(t/2,-1*i),e.lineTo((t+o)/2,0)),e.lineTo(t-l,0),e.arc(t-l,l,l,Math.PI*3/2,0,!1),r===U0&&(e.lineTo(t,(n-i)/2),e.lineTo(t+o,n/2),e.lineTo(t,(n+i)/2)),e.lineTo(t,n-u),e.arc(t-u,n-u,u,0,Math.PI/2,!1),r===H0&&(e.lineTo((t+o)/2,n),e.lineTo(t/2,n+i),e.lineTo((t-o)/2,n)),e.lineTo(c,n),e.arc(c,n-c,c,Math.PI/2,Math.PI,!1),r===$0&&(e.lineTo(0,(n+i)/2),e.lineTo(-1*o,n/2),e.lineTo(0,(n-i)/2)),e.lineTo(0,a),e.arc(a,a,a,Math.PI,Math.PI*3/2,!1),e.closePath(),e.fillStrokeShape(this)}getSelfRect(){let e=0,t=0,n=this.pointerWidth(),r=this.pointerHeight(),o=this.pointerDirection(),i=this.width(),s=this.height();return o===j0?(t-=r,s+=r):o===H0?s+=r:o===$0?(e-=n*1.5,i+=n):o===U0&&(i+=n*1.5),{x:e,y:t,width:i,height:s}}};$l.prototype.className="Tag",kr($l),de.addGetterSetter($l,"pointerDirection",WO),de.addGetterSetter($l,"pointerWidth",0,yt()),de.addGetterSetter($l,"pointerHeight",0,yt()),de.addGetterSetter($l,"cornerRadius",0,Yp(4));var Lf=class extends gt{_sceneFunc(e){const t=this.cornerRadius(),n=this.width(),r=this.height();e.beginPath(),t?xe.drawRoundedRectPath(e,n,r,t):e.rect(0,0,n,r),e.closePath(),e.fillStrokeShape(this)}};Lf.prototype.className="Rect",kr(Lf),de.addGetterSetter(Lf,"cornerRadius",0,Yp(4));var el=class extends gt{_sceneFunc(e){const t=this._getPoints(),n=this.radius(),r=this.sides(),o=this.cornerRadius();if(e.beginPath(),o)xe.drawRoundedPolygonPath(e,t,r,n,o);else{e.moveTo(t[0].x,t[0].y);for(let i=1;i<t.length;i++)e.lineTo(t[i].x,t[i].y)}e.closePath(),e.fillStrokeShape(this)}_getPoints(){const e=this.attrs.sides,t=this.attrs.radius||0,n=[];for(let r=0;r<e;r++)n.push({x:t*Math.sin(r*2*Math.PI/e),y:-1*t*Math.cos(r*2*Math.PI/e)});return n}getSelfRect(){const e=this._getPoints();let t=e[0].x,n=e[0].x,r=e[0].y,o=e[0].y;return e.forEach(i=>{t=Math.min(t,i.x),n=Math.max(n,i.x),r=Math.min(r,i.y),o=Math.max(o,i.y)}),{x:t,y:r,width:n-t,height:o-r}}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};el.prototype.className="RegularPolygon",el.prototype._centroid=!0,el.prototype._attrsAffectingSize=["radius"],kr(el),de.addGetterSetter(el,"radius",0,yt()),de.addGetterSetter(el,"sides",0,yt()),de.addGetterSetter(el,"cornerRadius",0,Yp(4));var u4=Math.PI*2,Gl=class extends gt{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,u4,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),u4,0,!0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}};Gl.prototype.className="Ring",Gl.prototype._centroid=!0,Gl.prototype._attrsAffectingSize=["innerRadius","outerRadius"],kr(Gl),de.addGetterSetter(Gl,"innerRadius",0,yt()),de.addGetterSetter(Gl,"outerRadius",0,yt());var vs=class extends gt{constructor(e){super(e),this._updated=!0,this.anim=new fu(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(e){const t=this.animation(),n=this.frameIndex(),r=n*4,o=this.animations()[t],i=this.frameOffsets(),s=o[r+0],a=o[r+1],l=o[r+2],c=o[r+3],u=this.image();if((this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(0,0,l,c),e.closePath(),e.fillStrokeShape(this)),u)if(i){const d=i[t],h=n*2;e.drawImage(u,s,a,l,c,d[h+0],d[h+1],l,c)}else e.drawImage(u,s,a,l,c,0,0,l,c)}_hitFunc(e){const t=this.animation(),n=this.frameIndex(),r=n*4,o=this.animations()[t],i=this.frameOffsets(),s=o[r+2],a=o[r+3];if(e.beginPath(),i){const l=i[t],c=n*2;e.rect(l[c+0],l[c+1],s,a)}else e.rect(0,0,s,a);e.closePath(),e.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const e=this;this.interval=setInterval(function(){e._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const e=this.getLayer();this.anim.setLayers(e),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const e=this.frameIndex(),t=this.animation();e<this.animations()[t].length/4-1?this.frameIndex(e+1):this.frameIndex(0)}};vs.prototype.className="Sprite",kr(vs),de.addGetterSetter(vs,"animation"),de.addGetterSetter(vs,"animations"),de.addGetterSetter(vs,"frameOffsets"),de.addGetterSetter(vs,"image"),de.addGetterSetter(vs,"frameIndex",0,yt()),de.addGetterSetter(vs,"frameRate",17,yt()),de.backCompat(vs,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});var tl=class extends gt{_sceneFunc(e){const t=this.innerRadius(),n=this.outerRadius(),r=this.numPoints();e.beginPath(),e.moveTo(0,0-n);for(let o=1;o<r*2;o++){const i=o%2===0?n:t,s=i*Math.sin(o*Math.PI/r),a=-1*i*Math.cos(o*Math.PI/r);e.lineTo(s,a)}e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.outerRadius()*2}getHeight(){return this.outerRadius()*2}setWidth(e){this.outerRadius(e/2)}setHeight(e){this.outerRadius(e/2)}};tl.prototype.className="Star",tl.prototype._centroid=!0,tl.prototype._attrsAffectingSize=["innerRadius","outerRadius"],kr(tl),de.addGetterSetter(tl,"numPoints",5,yt()),de.addGetterSetter(tl,"innerRadius",0,yt()),de.addGetterSetter(tl,"outerRadius",0,yt());function nl(e){return[...e].reduce((t,n,r,o)=>{if(/\p{Emoji}/u.test(n)){const i=o[r+1];i&&/\p{Emoji_Modifier}|\u200D/u.test(i)?(t.push(n+i),o[r+1]=""):t.push(n)}else/\p{Regional_Indicator}{2}/u.test(n+(o[r+1]||""))?t.push(n+o[r+1]):r>0&&/\p{Mn}|\p{Me}|\p{Mc}/u.test(n)?t[t.length-1]+=n:n&&t.push(n);return t},[])}var pu="auto",qO="center",d4="inherit",Pf="justify",YO="Change.konva",f4="2d",h4="-",p4="left",XO="text",ZO="Text",QO="top",JO="bottom",m4="middle",g4="normal",eF="px ",om=" ",tF="right",v4="rtl",nF="word",rF="char",y4="none",W0="β¦",b4=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],oF=b4.length,Df=null;function iF(){if(Df!==null)return Df;Df=!1;try{const e=document.createElement("canvas");e.width=10,e.height=10;const t=e.getContext(f4);if(t){t.globalAlpha=0,t.shadowColor="black",t.shadowBlur=5,t.shadowOffsetX=5,t.shadowOffsetY=5,t.fillStyle="black",t.font="10px Arial",t.fillText("X",0,10);const n=t.getImageData(0,0,10,10).data;for(let r=3;r<n.length;r+=4)if(n[r]>0){Df=!0;break}}}catch{}return Df}function sF(e){return e.split(",").map(t=>{t=t.trim();const n=t.indexOf(" ")>=0,r=t.indexOf('"')>=0||t.indexOf("'")>=0;return n&&!r&&(t=`"${t}"`),t}).join(", ")}var im;function K0(){return im||(im=xe.createCanvasElement().getContext(f4),im)}function aF(e){e.fillText(this._partialText,this._partialTextX,this._partialTextY)}function lF(e){e.setAttr("miterLimit",2),e.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function cF(e){return e=e||{},!e.fillLinearGradientColorStops&&!e.fillRadialGradientColorStops&&!e.fillPatternImage&&(e.fill=e.fill||"black"),e}var or=class extends gt{constructor(e){super(cF(e)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<oF;t++)this.on(b4[t]+YO,this._setTextData);this._setTextData()}_sceneFunc(e){var t,n;const r=this.textArr,o=r.length;if(!this.text())return;let i=this.padding(),s=this.fontSize(),a=this.lineHeight()*s,l=this.verticalAlign(),c=this.direction(),u=0,d=this.align(),h=this.getWidth(),g=this.letterSpacing(),p=this.charRenderFunc(),v=this.fill(),k=this.textDecoration(),C=this.underlineOffset(),_=k.indexOf("underline")!==-1,y=k.indexOf("line-through")!==-1,w;c=c===d4?e.direction:c;let x=a/2,L=m4;if(!wt.legacyTextRendering){const z=this.measureSize("M");L="alphabetic",x=(((t=z.fontBoundingBoxAscent)!==null&&t!==void 0?t:z.actualBoundingBoxAscent)-((n=z.fontBoundingBoxDescent)!==null&&n!==void 0?n:z.actualBoundingBoxDescent))/2+a/2}for(c===v4&&e.setAttr("direction",c),e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",L),e.setAttr("textAlign",p4),l===m4?u=(this.getHeight()-o*a-i*2)/2:l===JO&&(u=this.getHeight()-o*a-i*2),e.translate(i,u+i),w=0;w<o;w++){let z=0,$=0;const R=r[w],F=R.text,X=R.width,D=R.lastInParagraph;if(e.save(),d===tF?z+=h-X-i*2:d===qO&&(z+=(h-X-i*2)/2),_){e.save(),e.beginPath();const T=C??(wt.legacyTextRendering?Math.round(s/2):Math.round(s/4)),N=z,Q=x+$+T;e.moveTo(N,Q);const K=d===Pf&&!D?h-i*2:X;e.lineTo(N+Math.round(K),Q),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||v,e.stroke(),e.restore()}const V=z;if(c!==v4&&(g!==0||d===Pf||p)){const T=F.split(" ").length-1,N=nl(F);for(let Q=0;Q<N.length;Q++){const K=N[Q];if(K===" "&&!D&&d===Pf&&(z+=(h-i*2-X)/T),this._partialTextX=z,this._partialTextY=x+$,this._partialText=K,p){e.save();const se=r.slice(0,w).reduce((me,Be)=>me+nl(Be.text).length,0);p({char:K,index:Q+se,x:z,y:x+$,lineIndex:w,column:Q,isLastInLine:D,width:this.measureSize(K).width,context:e})}e.fillStrokeShape(this),p&&e.restore(),z+=this.measureSize(K).width+g}}else g!==0&&e.setAttr("letterSpacing",`${g}px`),this._partialTextX=z,this._partialTextY=x+$,this._partialText=F,e.fillStrokeShape(this);if(y){e.save(),e.beginPath();const T=wt.legacyTextRendering?0:-Math.round(s/4),N=V;e.moveTo(N,x+$+T);const Q=d===Pf&&!D?h-i*2:X;e.lineTo(N+Math.round(Q),x+$+T),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||v,e.stroke(),e.restore()}e.restore(),o>1&&(x+=a)}}_hitFunc(e){const t=this.getWidth(),n=this.getHeight();e.beginPath(),e.rect(0,0,t,n),e.closePath(),e.fillStrokeShape(this)}setText(e){const t=xe._isString(e)?e:e==null?"":e+"";return this._setAttr(XO,t),this}getWidth(){return this.attrs.width===pu||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===pu||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return xe.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(e){var t,n,r,o,i,s,a,l,c,u,d;let h=K0(),g=this.fontSize(),p;h.save(),h.font=this._getContextFont(),p=h.measureText(e),h.restore();const v=g/100;return{actualBoundingBoxAscent:(t=p.actualBoundingBoxAscent)!==null&&t!==void 0?t:71.58203125*v,actualBoundingBoxDescent:(n=p.actualBoundingBoxDescent)!==null&&n!==void 0?n:0,actualBoundingBoxLeft:(r=p.actualBoundingBoxLeft)!==null&&r!==void 0?r:-7.421875*v,actualBoundingBoxRight:(o=p.actualBoundingBoxRight)!==null&&o!==void 0?o:75.732421875*v,alphabeticBaseline:(i=p.alphabeticBaseline)!==null&&i!==void 0?i:0,emHeightAscent:(s=p.emHeightAscent)!==null&&s!==void 0?s:100*v,emHeightDescent:(a=p.emHeightDescent)!==null&&a!==void 0?a:-20*v,fontBoundingBoxAscent:(l=p.fontBoundingBoxAscent)!==null&&l!==void 0?l:91*v,fontBoundingBoxDescent:(c=p.fontBoundingBoxDescent)!==null&&c!==void 0?c:21*v,hangingBaseline:(u=p.hangingBaseline)!==null&&u!==void 0?u:72.80000305175781*v,ideographicBaseline:(d=p.ideographicBaseline)!==null&&d!==void 0?d:-21*v,width:p.width,height:g}}_getContextFont(){return this.fontStyle()+om+this.fontVariant()+om+(this.fontSize()+eF)+sF(this.fontFamily())}_addTextLine(e){this.align()===Pf&&(e=e.trim());const t=this._getTextWidth(e);return this.textArr.push({text:e,width:t,lastInParagraph:!1})}_getTextWidth(e){const t=this.letterSpacing(),n=e.length;return K0().measureText(e).width+t*n}_setTextData(){let e=this.text().split(`
|
|
100
100
|
`),t=+this.fontSize(),n=0,r=this.lineHeight()*t,o=this.attrs.width,i=this.attrs.height,s=o!==pu&&o!==void 0,a=i!==pu&&i!==void 0,l=this.padding(),c=o-l*2,u=i-l*2,d=0,h=this.wrap(),g=h!==rF&&h!==y4,p=this.ellipsis();this.textArr=[],K0().font=this._getContextFont();const v=p?this._getTextWidth(W0):0;for(let k=0,C=e.length;k<C;++k){let _=e[k],y=this._getTextWidth(_);if(s&&y>c)for(;_.length>0;){let w=0,x=nl(_).length,L="",z=0;for(;w<x;){const $=w+x>>>1,R=nl(_).slice(0,$+1).join(""),F=this._getTextWidth(R);(p&&a&&d+r>u?F+v:F)<=c?(w=$+1,L=R,z=F):x=$}if(L){if(g){const $=nl(_),R=nl(L),F=$[R.length],X=F===om||F===h4;let D;if(X&&z<=c)D=R.length;else{const V=R.lastIndexOf(om),T=R.lastIndexOf(h4);D=Math.max(V,T)+1}D>0&&(w=D,L=$.slice(0,w).join(""),z=this._getTextWidth(L))}if(L=L.trimRight(),this._addTextLine(L),n=Math.max(n,z),d+=r,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if(_=nl(_).slice(w).join("").trimLeft(),_.length>0&&(y=this._getTextWidth(_),y<=c)){this._addTextLine(_),d+=r,n=Math.max(n,y);break}}else break}else this._addTextLine(_),d+=r,n=Math.max(n,y),this._shouldHandleEllipsis(d)&&k<C-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&d+r>u)break}this.textHeight=t,this.textWidth=n}_shouldHandleEllipsis(e){const t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.height,o=r!==pu&&r!==void 0,i=r-this.padding()*2;return this.wrap()===y4||o&&e+n>i}_tryToAddEllipsisToLastLine(){const e=this.attrs.width,t=e!==pu&&e!==void 0,n=e-this.padding()*2,r=this.ellipsis(),o=this.textArr[this.textArr.length-1];!o||!r||(t&&(this._getTextWidth(o.text+W0)<n||(o.text=o.text.slice(0,o.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(o.text+W0))}getStrokeScaleEnabled(){return!0}_useBufferCanvas(){const e=this.textDecoration().indexOf("underline")!==-1||this.textDecoration().indexOf("line-through")!==-1,t=this.hasShadow();return e&&t||t&&this.getAbsoluteOpacity()!==1&&iF()?!0:super._useBufferCanvas()}};or.prototype._fillFunc=aF,or.prototype._strokeFunc=lF,or.prototype.className=ZO,or.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],kr(or),de.overWriteSetter(or,"width",T0()),de.overWriteSetter(or,"height",T0()),de.addGetterSetter(or,"direction",d4),de.addGetterSetter(or,"fontFamily","Arial"),de.addGetterSetter(or,"fontSize",12,yt()),de.addGetterSetter(or,"fontStyle",g4),de.addGetterSetter(or,"fontVariant",g4),de.addGetterSetter(or,"padding",0,yt()),de.addGetterSetter(or,"align",p4),de.addGetterSetter(or,"verticalAlign",QO),de.addGetterSetter(or,"lineHeight",1,yt()),de.addGetterSetter(or,"wrap",nF),de.addGetterSetter(or,"ellipsis",!1,Vi()),de.addGetterSetter(or,"letterSpacing",0,yt()),de.addGetterSetter(or,"text","",Vl()),de.addGetterSetter(or,"textDecoration",""),de.addGetterSetter(or,"underlineOffset",void 0,yt()),de.addGetterSetter(or,"charRenderFunc",void 0);var uF="",w4="normal";function C4(e){e.fillText(this.partialText,0,0)}function k4(e){e.strokeText(this.partialText,0,0)}var to=class extends gt{constructor(e){super(e),this.dummyCanvas=xe.createCanvasElement(),this.dataArray=[],this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute(),this._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva",this._setTextData),this._setTextData()}_getTextPathLength(){return Si.getPathLength(this.dataArray)}_getPointAtLength(e){return!this.attrs.data||e>this.pathLength?null:Si.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=Si.parsePathData(this.attrs.data),this.pathLength=this._getTextPathLength()}_sceneFunc(e){e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",this.textBaseline()),e.setAttr("textAlign","left"),e.save();const t=this.textDecoration(),n=this.fill(),r=this.fontSize(),o=this.glyphInfo,i=t.indexOf("underline")!==-1,s=t.indexOf("line-through")!==-1;i&&e.beginPath();for(let a=0;a<o.length;a++){e.save();const l=o[a].p0;e.translate(l.x,l.y),e.rotate(o[a].rotation),this.partialText=o[a].text,e.fillStrokeShape(this),i&&(a===0&&e.moveTo(0,r/2+1),e.lineTo(o[a].width,r/2+1)),e.restore()}if(i&&(e.strokeStyle=n,e.lineWidth=r/20,e.stroke()),s){e.beginPath();for(let a=0;a<o.length;a++){e.save();const l=o[a].p0;e.translate(l.x,l.y),e.rotate(o[a].rotation),a===0&&e.moveTo(0,0),e.lineTo(o[a].width,0),e.restore()}e.strokeStyle=n,e.lineWidth=r/20,e.stroke()}e.restore()}_hitFunc(e){e.beginPath();const t=this.glyphInfo;if(t.length>=1){const n=t[0].p0;e.moveTo(n.x,n.y)}for(let n=0;n<t.length;n++){const r=t[n].p1;e.lineTo(r.x,r.y)}e.setAttr("lineWidth",this.fontSize()),e.setAttr("strokeStyle",this.colorKey),e.stroke()}getTextWidth(){return this.textWidth}getTextHeight(){return xe.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(e){return or.prototype.setText.call(this,e)}_getContextFont(){return or.prototype._getContextFont.call(this)}_getTextSize(e){const t=this.dummyCanvas.getContext("2d");t.save(),t.font=this._getContextFont();const n=t.measureText(e);return t.restore(),{width:n.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const e=nl(this.text()),t=[];let n=0;for(let h=0;h<e.length;h++)t.push({char:e[h],width:this._getTextSize(e[h]).width}),n+=t[h].width;const{width:r,height:o}=this._getTextSize(this.attrs.text);if(this.textWidth=n,this.textHeight=o,this.glyphInfo=[],!this.attrs.data)return null;const i=this.letterSpacing(),s=this.align(),a=this.kerningFunc(),l=Math.max(0,n-r),c=Math.max(this.textWidth+((this.attrs.text||"").length-1)*i,0);let u=0;s==="center"&&(u=Math.max(0,this.pathLength/2-c/2)),s==="right"&&(u=Math.max(0,this.pathLength-c));let d=u;for(let h=0;h<t.length;h++){const g=this._getPointAtLength(d);if(!g)return;const p=t[h].char;let v=t[h].width+i;if(p===" "&&s==="justify"){const L=this.text().split(" ").length-1;v+=(this.pathLength-c)/L}const k=d+v,C=this._getPointAtLength(k>this.pathLength&&k-this.pathLength<=l?this.pathLength:k);if(!C)return;const _=Si.getLineLength(g.x,g.y,C.x,C.y);let y=0;if(a)try{y=a(t[h-1].char,p)*this.fontSize()}catch{y=0}g.x+=y,C.x+=y,this.textWidth+=y;const w=Si.getPointOnLine(y+_/2,g.x,g.y,C.x,C.y),x=Math.atan2(C.y-g.y,C.x-g.x);this.glyphInfo.push({transposeX:w.x,transposeY:w.y,text:e[h],rotation:x,p0:g,p1:C,width:_}),d+=v}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const e=[];this.glyphInfo.forEach(function(l){e.push(l.p0.x),e.push(l.p0.y),e.push(l.p1.x),e.push(l.p1.y)});let t=e[0]||0,n=e[0]||0,r=e[1]||0,o=e[1]||0,i,s;for(let l=0;l<e.length/2;l++)i=e[l*2],s=e[l*2+1],t=Math.min(t,i),n=Math.max(n,i),r=Math.min(r,s),o=Math.max(o,s);const a=this.fontSize();return{x:t-a/2,y:r-a/2,width:n-t+a,height:o-r+a}}destroy(){return xe.releaseCanvas(this.dummyCanvas),super.destroy()}};to.prototype._fillFunc=C4,to.prototype._strokeFunc=k4,to.prototype._fillFuncHit=C4,to.prototype._strokeFuncHit=k4,to.prototype.className="TextPath",to.prototype._attrsAffectingSize=["text","fontSize","data"],kr(to),de.addGetterSetter(to,"data"),de.addGetterSetter(to,"fontFamily","Arial"),de.addGetterSetter(to,"fontSize",12,yt()),de.addGetterSetter(to,"fontStyle",w4),de.addGetterSetter(to,"align","left"),de.addGetterSetter(to,"letterSpacing",0,yt()),de.addGetterSetter(to,"textBaseline","middle"),de.addGetterSetter(to,"fontVariant",w4),de.addGetterSetter(to,"text",uF),de.addGetterSetter(to,"textDecoration",""),de.addGetterSetter(to,"kerningFunc",void 0);var S4="tr-konva",dF=["resizeEnabledChange","rotateAnchorOffsetChange","rotateAnchorAngleChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(e=>e+`.${S4}`).join(" "),_4="nodesRect",fF=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],hF={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},pF="ontouchstart"in wt._global;function mF(e,t,n){if(e==="rotater")return n;t+=xe.degToRad(hF[e]||0);const r=(xe.radToDeg(t)%360+360)%360;return xe._inRange(r,337.5,360)||xe._inRange(r,0,22.5)?"ns-resize":xe._inRange(r,22.5,67.5)?"nesw-resize":xe._inRange(r,67.5,112.5)?"ew-resize":xe._inRange(r,112.5,157.5)?"nwse-resize":xe._inRange(r,157.5,202.5)?"ns-resize":xe._inRange(r,202.5,247.5)?"nesw-resize":xe._inRange(r,247.5,292.5)?"ew-resize":xe._inRange(r,292.5,337.5)?"nwse-resize":(xe.error("Transformer has unknown angle for cursor detection: "+r),"pointer")}var sm=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function gF(e){return{x:e.x+e.width/2*Math.cos(e.rotation)+e.height/2*Math.sin(-e.rotation),y:e.y+e.height/2*Math.cos(e.rotation)+e.width/2*Math.sin(e.rotation)}}function A4(e,t,n){const r=n.x+(e.x-n.x)*Math.cos(t)-(e.y-n.y)*Math.sin(t),o=n.y+(e.x-n.x)*Math.sin(t)+(e.y-n.y)*Math.cos(t);return{...e,rotation:e.rotation+t,x:r,y:o}}function vF(e,t){return A4(e,t,gF(e))}function yF(e,t,n){let r=t;for(let o=0;o<e.length;o++){const i=wt.getAngle(e[o]),s=Math.abs(i-t)%(Math.PI*2);Math.min(s,Math.PI*2-s)<n&&(r=i)}return r}var q0=0,xn=class extends du{constructor(e){super(e),this._movingAnchorName=null,this._transforming=!1,this._elementsCreated=!1,this._createElements(),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(dF,this.update),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return xe.warn("tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead."),this.setNodes([e])}getNode(){return this._nodes&&this._nodes[0]}_getEventNamespace(){return S4+this._id}setNodes(e=[]){this._nodes&&this._nodes.length&&this.detach();const t=e.filter(n=>n.isAncestorOf(this)?(xe.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0);return this._nodes=e=t,e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(n=>{const r=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(n._attrsAffectingSize.length){const o=n._attrsAffectingSize.map(i=>i+"Change."+this._getEventNamespace()).join(" ");n.on(o,r)}n.on(fF.map(o=>o+`.${this._getEventNamespace()}`).join(" "),r),n.on(`absoluteTransformChange.${this._getEventNamespace()}`,r),this._proxyDrag(n)}),this._resetTransformCache(),this.findOne(".top-left")&&this.update(),this}_proxyDrag(e){let t;e.on(`dragstart.${this._getEventNamespace()}`,n=>{t=e.getAbsolutePosition(),!this.isDragging()&&e!==this.findOne(".back")&&this.startDrag(n,!1)}),e.on(`dragmove.${this._getEventNamespace()}`,n=>{if(!t)return;const r=e.getAbsolutePosition(),o=r.x-t.x,i=r.y-t.y;this.nodes().forEach(s=>{if(s===e||s.isDragging())return;const a=s.getAbsolutePosition();s.setAbsolutePosition({x:a.x+o,y:a.y+i}),s.startDrag(n)}),t=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(e=>{e.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(_4),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(_4,this.__getNodeRect)}__getNodeShape(e,t=this.rotation(),n){const r=e.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),o=e.getAbsoluteScale(n),i=e.getAbsolutePosition(n),s=r.x*o.x-e.offsetX()*o.x,a=r.y*o.y-e.offsetY()*o.y,l=(wt.getAngle(e.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2);return A4({x:i.x+s*Math.cos(l)+a*Math.sin(-l),y:i.y+a*Math.cos(l)+s*Math.sin(l),width:r.width*o.x,height:r.height*o.y,rotation:l},-wt.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const e=[];this.nodes().map(a=>{const l=a.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),c=[{x:l.x,y:l.y},{x:l.x+l.width,y:l.y},{x:l.x+l.width,y:l.y+l.height},{x:l.x,y:l.y+l.height}],u=a.getAbsoluteTransform();c.forEach(function(d){const h=u.point(d);e.push(h)})});const t=new zi;t.rotate(-wt.getAngle(this.rotation()));let n=1/0,r=1/0,o=-1/0,i=-1/0;e.forEach(function(a){const l=t.point(a);n===void 0&&(n=o=l.x,r=i=l.y),n=Math.min(n,l.x),r=Math.min(r,l.y),o=Math.max(o,l.x),i=Math.max(i,l.y)}),t.invert();const s=t.point({x:n,y:r});return{x:s.x,y:s.y,width:o-n,height:i-r,rotation:wt.getAngle(this.rotation())}}getX(){return this._getNodeRect().x}getY(){return this._getNodeRect().y}getWidth(){return this._getNodeRect().width}getHeight(){return this._getNodeRect().height}_createElements(){this._createBack(),sm.forEach(e=>{this._createAnchor(e)}),this._createAnchor("rotater"),this._elementsCreated=!0}_createAnchor(e){const t=new Lf({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:e+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:pF?10:"auto"}),n=this;t.on("mousedown touchstart",function(r){n._handleMouseDown(r)}),t.on("dragstart",r=>{t.stopDrag(),r.cancelBubble=!0}),t.on("dragend",r=>{r.cancelBubble=!0}),t.on("mouseenter",()=>{const r=mF(e,wt.getAngle(this.rotation()),this.rotateAnchorCursor());t.getStage().content&&(t.getStage().content.style.cursor=r),this._cursorChange=!0}),t.on("mouseout",()=>{t.getStage().content&&(t.getStage().content.style.cursor=""),this._cursorChange=!1}),this.add(t)}_createBack(){const e=new gt({name:"back",width:0,height:0,sceneFunc(t,n){const r=n.getParent(),o=r.padding(),i=n.width(),s=n.height();if(t.beginPath(),t.rect(-o,-o,i+o*2,s+o*2),r.rotateEnabled()&&r.rotateLineVisible()){const a=r.rotateAnchorAngle(),l=r.rotateAnchorOffset(),c=xe.degToRad(a),u=Math.sin(c),d=-Math.cos(c),h=i/2,g=s/2;let p=1/0;d<0?p=Math.min(p,-g/d):d>0&&(p=Math.min(p,(s-g)/d)),u<0?p=Math.min(p,-h/u):u>0&&(p=Math.min(p,(i-h)/u));const v=h+u*p,k=g+d*p,C=xe._sign(s),_=v+u*l*C,y=k+d*l*C;t.moveTo(v,k),t.lineTo(_,y)}t.fillStrokeShape(n)},hitFunc:(t,n)=>{if(!this.shouldOverdrawWholeArea())return;const r=this.padding();t.beginPath(),t.rect(-r,-r,n.width()+r*2,n.height()+r*2),t.fillStrokeShape(n)}});this.add(e),this._proxyDrag(e),e.on("dragstart",t=>{t.cancelBubble=!0}),e.on("dragmove",t=>{t.cancelBubble=!0}),e.on("dragend",t=>{t.cancelBubble=!0}),this.on("dragmove",t=>{this.update()})}_handleMouseDown(e){if(this._transforming)return;this._movingAnchorName=e.target.name().split(" ")[0];const t=this._getNodeRect(),n=t.width,r=t.height,o=Math.sqrt(Math.pow(n,2)+Math.pow(r,2));this.sin=Math.abs(r/o),this.cos=Math.abs(n/o),typeof window<"u"&&(window.addEventListener("mousemove",this._handleMouseMove),window.addEventListener("touchmove",this._handleMouseMove),window.addEventListener("mouseup",this._handleMouseUp,!0),window.addEventListener("touchend",this._handleMouseUp,!0)),this._transforming=!0;const i=e.target.getAbsolutePosition(),s=e.target.getStage().getPointerPosition();this._anchorDragOffset={x:s.x-i.x,y:s.y-i.y},q0++,this._fire("transformstart",{evt:e.evt,target:this.getNode()}),this._nodes.forEach(a=>{a._fire("transformstart",{evt:e.evt,target:a})})}_handleMouseMove(e){let t,n,r;const o=this.findOne("."+this._movingAnchorName),i=o.getStage();i.setPointersPositions(e);const s=i.getPointerPosition();let a={x:s.x-this._anchorDragOffset.x,y:s.y-this._anchorDragOffset.y};const l=o.getAbsolutePosition();this.anchorDragBoundFunc()&&(a=this.anchorDragBoundFunc()(l,a,e)),o.setAbsolutePosition(a);const c=o.getAbsolutePosition();if(l.x===c.x&&l.y===c.y)return;if(this._movingAnchorName==="rotater"){const C=this._getNodeRect();t=o.x()-C.width/2,n=-o.y()+C.height/2;const _=wt.getAngle(this.rotateAnchorAngle());let y=Math.atan2(-n,t)+Math.PI/2-_;C.height<0&&(y-=Math.PI);const w=wt.getAngle(this.rotation())+y,x=wt.getAngle(this.rotationSnapTolerance()),L=vF(C,yF(this.rotationSnaps(),w,x)-C.rotation);this._fitNodesInto(L,e);return}const u=this.shiftBehavior();let d;u==="inverted"?d=this.keepRatio()&&!e.shiftKey:u==="none"?d=this.keepRatio():d=this.keepRatio()||e.shiftKey;let h=this.centeredScaling()||e.altKey;if(this._movingAnchorName==="top-left"){if(d){const C=h?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-right").x(),y:this.findOne(".bottom-right").y()};r=Math.sqrt(Math.pow(C.x-o.x(),2)+Math.pow(C.y-o.y(),2));const _=this.findOne(".top-left").x()>C.x?-1:1,y=this.findOne(".top-left").y()>C.y?-1:1;t=r*this.cos*_,n=r*this.sin*y,this.findOne(".top-left").x(C.x-t),this.findOne(".top-left").y(C.y-n)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(o.y());else if(this._movingAnchorName==="top-right"){if(d){const C=h?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()};r=Math.sqrt(Math.pow(o.x()-C.x,2)+Math.pow(C.y-o.y(),2));const _=this.findOne(".top-right").x()<C.x?-1:1,y=this.findOne(".top-right").y()>C.y?-1:1;t=r*this.cos*_,n=r*this.sin*y,this.findOne(".top-right").x(C.x+t),this.findOne(".top-right").y(C.y-n)}var g=o.position();this.findOne(".top-left").y(g.y),this.findOne(".bottom-right").x(g.x)}else if(this._movingAnchorName==="middle-left")this.findOne(".top-left").x(o.x());else if(this._movingAnchorName==="middle-right")this.findOne(".bottom-right").x(o.x());else if(this._movingAnchorName==="bottom-left"){if(d){const C=h?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()};r=Math.sqrt(Math.pow(C.x-o.x(),2)+Math.pow(o.y()-C.y,2));const _=C.x<o.x()?-1:1,y=o.y()<C.y?-1:1;t=r*this.cos*_,n=r*this.sin*y,o.x(C.x-t),o.y(C.y+n)}g=o.position(),this.findOne(".top-left").x(g.x),this.findOne(".bottom-right").y(g.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(o.y());else if(this._movingAnchorName==="bottom-right"){if(d){const C=h?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-left").x(),y:this.findOne(".top-left").y()};r=Math.sqrt(Math.pow(o.x()-C.x,2)+Math.pow(o.y()-C.y,2));const _=this.findOne(".bottom-right").x()<C.x?-1:1,y=this.findOne(".bottom-right").y()<C.y?-1:1;t=r*this.cos*_,n=r*this.sin*y,this.findOne(".bottom-right").x(C.x+t),this.findOne(".bottom-right").y(C.y+n)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(h=this.centeredScaling()||e.altKey,h){const C=this.findOne(".top-left"),_=this.findOne(".bottom-right"),y=C.x(),w=C.y(),x=this.getWidth()-_.x(),L=this.getHeight()-_.y();_.move({x:-y,y:-w}),C.move({x,y:L})}const p=this.findOne(".top-left").getAbsolutePosition();t=p.x,n=p.y;const v=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),k=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:t,y:n,width:v,height:k,rotation:wt.getAngle(this.rotation())},e)}_handleMouseUp(e){this._removeEvents(e)}getAbsoluteTransform(){return this.getTransform()}_removeEvents(e){var t;if(this._transforming){this._transforming=!1,typeof window<"u"&&(window.removeEventListener("mousemove",this._handleMouseMove),window.removeEventListener("touchmove",this._handleMouseMove),window.removeEventListener("mouseup",this._handleMouseUp,!0),window.removeEventListener("touchend",this._handleMouseUp,!0));const n=this.getNode();q0--,this._fire("transformend",{evt:e,target:n}),(t=this.getLayer())===null||t===void 0||t.batchDraw(),n&&this._nodes.forEach(r=>{var o;r._fire("transformend",{evt:e,target:r}),(o=r.getLayer())===null||o===void 0||o.batchDraw()}),this._movingAnchorName=null}}_fitNodesInto(e,t){const n=this._getNodeRect(),r=1;if(xe._inRange(e.width,-this.padding()*2-r,r)){this.update();return}if(xe._inRange(e.height,-this.padding()*2-r,r)){this.update();return}const o=new zi;if(o.rotate(wt.getAngle(this.rotation())),this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("left")>=0){const d=o.point({x:-this.padding()*2,y:0});e.x+=d.x,e.y+=d.y,e.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y}else if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("right")>=0){const d=o.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,e.width+=this.padding()*2}if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("top")>=0){const d=o.point({x:0,y:-this.padding()*2});e.x+=d.x,e.y+=d.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,e.height+=this.padding()*2}else if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const d=o.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=d.x,this._anchorDragOffset.y-=d.y,e.height+=this.padding()*2}if(this.boundBoxFunc()){const d=this.boundBoxFunc()(n,e);d?e=d:xe.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const i=1e7,s=new zi;s.translate(n.x,n.y),s.rotate(n.rotation),s.scale(n.width/i,n.height/i);const a=new zi,l=e.width/i,c=e.height/i;this.flipEnabled()===!1?(a.translate(e.x,e.y),a.rotate(e.rotation),a.translate(e.width<0?e.width:0,e.height<0?e.height:0),a.scale(Math.abs(l),Math.abs(c))):(a.translate(e.x,e.y),a.rotate(e.rotation),a.scale(l,c));const u=a.multiply(s.invert());this._nodes.forEach(d=>{var h;if(!d.getStage())return;const g=d.getParent().getAbsoluteTransform(),p=d.getTransform().copy();p.translate(d.offsetX(),d.offsetY());const v=new zi;v.multiply(g.copy().invert()).multiply(u).multiply(g).multiply(p);const k=v.decompose();d.setAttrs(k),(h=d.getLayer())===null||h===void 0||h.batchDraw()}),this.rotation(xe._getRotation(e.rotation)),this._nodes.forEach(d=>{this._fire("transform",{evt:t,target:d}),d._fire("transform",{evt:t,target:d})}),this._resetTransformCache(),this.update(),this.getLayer().batchDraw()}forceUpdate(){this._resetTransformCache(),this.update()}_batchChangeChild(e,t){this.findOne(e).setAttrs(t)}update(){var e;const t=this._getNodeRect();this.rotation(xe._getRotation(t.rotation));const n=t.width,r=t.height,o=this.enabledAnchors(),i=this.resizeEnabled(),s=this.padding(),a=this.anchorSize(),l=this.find("._anchor");l.forEach(x=>{x.setAttrs({width:a,height:a,offsetX:a/2,offsetY:a/2,stroke:this.anchorStroke(),strokeWidth:this.anchorStrokeWidth(),fill:this.anchorFill(),cornerRadius:this.anchorCornerRadius()})}),this._batchChangeChild(".top-left",{x:0,y:0,offsetX:a/2+s,offsetY:a/2+s,visible:i&&o.indexOf("top-left")>=0}),this._batchChangeChild(".top-center",{x:n/2,y:0,offsetY:a/2+s,visible:i&&o.indexOf("top-center")>=0}),this._batchChangeChild(".top-right",{x:n,y:0,offsetX:a/2-s,offsetY:a/2+s,visible:i&&o.indexOf("top-right")>=0}),this._batchChangeChild(".middle-left",{x:0,y:r/2,offsetX:a/2+s,visible:i&&o.indexOf("middle-left")>=0}),this._batchChangeChild(".middle-right",{x:n,y:r/2,offsetX:a/2-s,visible:i&&o.indexOf("middle-right")>=0}),this._batchChangeChild(".bottom-left",{x:0,y:r,offsetX:a/2+s,offsetY:a/2-s,visible:i&&o.indexOf("bottom-left")>=0}),this._batchChangeChild(".bottom-center",{x:n/2,y:r,offsetY:a/2-s,visible:i&&o.indexOf("bottom-center")>=0}),this._batchChangeChild(".bottom-right",{x:n,y:r,offsetX:a/2-s,offsetY:a/2-s,visible:i&&o.indexOf("bottom-right")>=0});const c=this.rotateAnchorAngle(),u=this.rotateAnchorOffset(),d=xe.degToRad(c),h=Math.sin(d),g=-Math.cos(d),p=n/2,v=r/2;let k=1/0;g<0?k=Math.min(k,-v/g):g>0&&(k=Math.min(k,(r-v)/g)),h<0?k=Math.min(k,-p/h):h>0&&(k=Math.min(k,(n-p)/h));const C=p+h*k,_=v+g*k,y=xe._sign(r);this._batchChangeChild(".rotater",{x:C+h*u*y,y:_+g*u*y-s*g,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:n,height:r,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(x=>x.draggable()),x:0,y:0});const w=this.anchorStyleFunc();w&&l.forEach(x=>{w(x)}),(e=this.getLayer())===null||e===void 0||e.batchDraw()}isTransforming(){return this._transforming}stopTransform(){if(this._transforming){this._removeEvents();const e=this.findOne("."+this._movingAnchorName);e&&e.stopDrag()}}destroy(){return this.getStage()&&this._cursorChange&&this.getStage().content&&(this.getStage().content.style.cursor=""),du.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}add(...e){return this._elementsCreated?(xe.error("You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead."),this):super.add(...e)}toObject(){return St.prototype.toObject.call(this)}clone(e){return St.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}};xn.isTransforming=()=>q0>0;function bF(e){return e instanceof Array||xe.warn("enabledAnchors value should be an array"),e instanceof Array&&e.forEach(function(t){sm.indexOf(t)===-1&&xe.warn("Unknown anchor name: "+t+". Available names are: "+sm.join(", "))}),e||[]}xn.prototype.className="Transformer",kr(xn),de.addGetterSetter(xn,"enabledAnchors",sm,bF),de.addGetterSetter(xn,"flipEnabled",!0,Vi()),de.addGetterSetter(xn,"resizeEnabled",!0),de.addGetterSetter(xn,"anchorSize",10,yt()),de.addGetterSetter(xn,"rotateEnabled",!0),de.addGetterSetter(xn,"rotateLineVisible",!0),de.addGetterSetter(xn,"rotationSnaps",[]),de.addGetterSetter(xn,"rotateAnchorOffset",50,yt()),de.addGetterSetter(xn,"rotateAnchorAngle",0,yt()),de.addGetterSetter(xn,"rotateAnchorCursor","crosshair"),de.addGetterSetter(xn,"rotationSnapTolerance",5,yt()),de.addGetterSetter(xn,"borderEnabled",!0),de.addGetterSetter(xn,"anchorStroke","rgb(0, 161, 255)"),de.addGetterSetter(xn,"anchorStrokeWidth",1,yt()),de.addGetterSetter(xn,"anchorFill","white"),de.addGetterSetter(xn,"anchorCornerRadius",0,yt()),de.addGetterSetter(xn,"borderStroke","rgb(0, 161, 255)"),de.addGetterSetter(xn,"borderStrokeWidth",1,yt()),de.addGetterSetter(xn,"borderDash"),de.addGetterSetter(xn,"keepRatio",!0),de.addGetterSetter(xn,"shiftBehavior","default"),de.addGetterSetter(xn,"centeredScaling",!1),de.addGetterSetter(xn,"ignoreStroke",!1),de.addGetterSetter(xn,"padding",0,yt()),de.addGetterSetter(xn,"nodes"),de.addGetterSetter(xn,"node"),de.addGetterSetter(xn,"boundBoxFunc"),de.addGetterSetter(xn,"anchorDragBoundFunc"),de.addGetterSetter(xn,"anchorStyleFunc"),de.addGetterSetter(xn,"shouldOverdrawWholeArea",!1),de.addGetterSetter(xn,"useSingleNodeRotation",!0),de.backCompat(xn,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});var da=class extends gt{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,wt.getAngle(this.angle()),this.clockwise()),e.lineTo(0,0),e.closePath(),e.fillStrokeShape(this)}getWidth(){return this.radius()*2}getHeight(){return this.radius()*2}setWidth(e){this.radius(e/2)}setHeight(e){this.radius(e/2)}};da.prototype.className="Wedge",da.prototype._centroid=!0,da.prototype._attrsAffectingSize=["radius"],kr(da),de.addGetterSetter(da,"radius",0,yt()),de.addGetterSetter(da,"angle",0,yt()),de.addGetterSetter(da,"clockwise",!1),de.backCompat(da,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});function I4(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var wF=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],CF=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function kF(e,t){const n=e.data,r=e.width,o=e.height;let i,s,a,l,c,u,d,h,g,p,v,k,C,_,y,w,x,L,z,$;const R=t+t+1,F=r-1,X=o-1,D=t+1,V=D*(D+1)/2,T=new I4,N=wF[t],Q=CF[t];let K=null,se=T,me=null,Be=null;for(let he=1;he<R;he++)se=se.next=new I4,he===D&&(K=se);se.next=T,a=s=0;for(let he=0;he<o;he++){k=C=_=y=l=c=u=d=0,h=D*(w=n[s]),g=D*(x=n[s+1]),p=D*(L=n[s+2]),v=D*(z=n[s+3]),l+=V*w,c+=V*x,u+=V*L,d+=V*z,se=T;for(let ve=0;ve<D;ve++)se.r=w,se.g=x,se.b=L,se.a=z,se=se.next;for(let ve=1;ve<D;ve++)i=s+((F<ve?F:ve)<<2),l+=(se.r=w=n[i])*($=D-ve),c+=(se.g=x=n[i+1])*$,u+=(se.b=L=n[i+2])*$,d+=(se.a=z=n[i+3])*$,k+=w,C+=x,_+=L,y+=z,se=se.next;me=T,Be=K;for(let ve=0;ve<r;ve++)n[s+3]=z=d*N>>Q,z!==0?(z=255/z,n[s]=(l*N>>Q)*z,n[s+1]=(c*N>>Q)*z,n[s+2]=(u*N>>Q)*z):n[s]=n[s+1]=n[s+2]=0,l-=h,c-=g,u-=p,d-=v,h-=me.r,g-=me.g,p-=me.b,v-=me.a,i=a+((i=ve+t+1)<F?i:F)<<2,k+=me.r=n[i],C+=me.g=n[i+1],_+=me.b=n[i+2],y+=me.a=n[i+3],l+=k,c+=C,u+=_,d+=y,me=me.next,h+=w=Be.r,g+=x=Be.g,p+=L=Be.b,v+=z=Be.a,k-=w,C-=x,_-=L,y-=z,Be=Be.next,s+=4;a+=r}for(let he=0;he<r;he++){C=_=y=k=c=u=d=l=0,s=he<<2,h=D*(w=n[s]),g=D*(x=n[s+1]),p=D*(L=n[s+2]),v=D*(z=n[s+3]),l+=V*w,c+=V*x,u+=V*L,d+=V*z,se=T;for(let ue=0;ue<D;ue++)se.r=w,se.g=x,se.b=L,se.a=z,se=se.next;let ve=r;for(let ue=1;ue<=t;ue++)s=ve+he<<2,l+=(se.r=w=n[s])*($=D-ue),c+=(se.g=x=n[s+1])*$,u+=(se.b=L=n[s+2])*$,d+=(se.a=z=n[s+3])*$,k+=w,C+=x,_+=L,y+=z,se=se.next,ue<X&&(ve+=r);s=he,me=T,Be=K;for(let ue=0;ue<o;ue++)i=s<<2,n[i+3]=z=d*N>>Q,z>0?(z=255/z,n[i]=(l*N>>Q)*z,n[i+1]=(c*N>>Q)*z,n[i+2]=(u*N>>Q)*z):n[i]=n[i+1]=n[i+2]=0,l-=h,c-=g,u-=p,d-=v,h-=me.r,g-=me.g,p-=me.b,v-=me.a,i=he+((i=ue+D)<X?i:X)*r<<2,l+=k+=me.r=n[i],c+=C+=me.g=n[i+1],u+=_+=me.b=n[i+2],d+=y+=me.a=n[i+3],me=me.next,h+=w=Be.r,g+=x=Be.g,p+=L=Be.b,v+=z=Be.a,k-=w,C-=x,_-=L,y-=z,Be=Be.next,s+=r}}var SF=function(t){const n=Math.round(this.blurRadius());n>0&&kF(t,n)};de.addGetterSetter(St,"blurRadius",0,yt(),de.afterSetFilter);var _F=function(e){const t=this.brightness()*255,n=e.data,r=n.length;for(let o=0;o<r;o+=4)n[o]+=t,n[o+1]+=t,n[o+2]+=t};de.addGetterSetter(St,"brightness",0,yt(),de.afterSetFilter);var AF=function(e){const t=this.brightness(),n=e.data,r=n.length;for(let o=0;o<r;o+=4)n[o]=Math.min(255,n[o]*t),n[o+1]=Math.min(255,n[o+1]*t),n[o+2]=Math.min(255,n[o+2]*t)},IF=function(e){const t=Math.pow((this.contrast()+100)/100,2),n=e.data,r=n.length;let o=150,i=150,s=150;for(let a=0;a<r;a+=4)o=n[a],i=n[a+1],s=n[a+2],o/=255,o-=.5,o*=t,o+=.5,o*=255,i/=255,i-=.5,i*=t,i+=.5,i*=255,s/=255,s-=.5,s*=t,s+=.5,s*=255,o=o<0?0:o>255?255:o,i=i<0?0:i>255?255:i,s=s<0?0:s>255?255:s,n[a]=o,n[a+1]=i,n[a+2]=s};de.addGetterSetter(St,"contrast",0,yt(),de.afterSetFilter);var EF=function(e){var t,n,r,o,i,s,a,l,c;const u=e.data,d=e.width,h=e.height,g=Math.min(1,Math.max(0,(n=(t=this.embossStrength)===null||t===void 0?void 0:t.call(this))!==null&&n!==void 0?n:.5)),p=Math.min(1,Math.max(0,(o=(r=this.embossWhiteLevel)===null||r===void 0?void 0:r.call(this))!==null&&o!==void 0?o:.5)),v=(a={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[(s=(i=this.embossDirection)===null||i===void 0?void 0:i.call(this))!==null&&s!==void 0?s:"top-left"])!==null&&a!==void 0?a:315,k=!!((c=(l=this.embossBlend)===null||l===void 0?void 0:l.call(this))!==null&&c!==void 0&&c),C=g*10,_=p*255,y=v*Math.PI/180,w=Math.cos(y),x=Math.sin(y),L=128/1020*C,z=new Uint8ClampedArray(u),$=new Float32Array(d*h);for(let V=0,T=0;T<u.length;T+=4,V++)$[V]=.2126*z[T]+.7152*z[T+1]+.0722*z[T+2];const R=[-1,0,1,-2,0,2,-1,0,1],F=[-1,-2,-1,0,0,0,1,2,1],X=[-d-1,-d,-d+1,-1,0,1,d-1,d,d+1],D=V=>V<0?0:V>255?255:V;for(let V=1;V<h-1;V++)for(let T=1;T<d-1;T++){const N=V*d+T;let Q=0,K=0;Q+=$[N+X[0]]*R[0],K+=$[N+X[0]]*F[0],Q+=$[N+X[1]]*R[1],K+=$[N+X[1]]*F[1],Q+=$[N+X[2]]*R[2],K+=$[N+X[2]]*F[2],Q+=$[N+X[3]]*R[3],K+=$[N+X[3]]*F[3],Q+=$[N+X[5]]*R[5],K+=$[N+X[5]]*F[5],Q+=$[N+X[6]]*R[6],K+=$[N+X[6]]*F[6],Q+=$[N+X[7]]*R[7],K+=$[N+X[7]]*F[7],Q+=$[N+X[8]]*R[8],K+=$[N+X[8]]*F[8];const se=D(_+(w*Q+x*K)*L),me=N*4;if(k){const Be=se-_;u[me]=D(z[me]+Be),u[me+1]=D(z[me+1]+Be),u[me+2]=D(z[me+2]+Be),u[me+3]=z[me+3]}else u[me]=u[me+1]=u[me+2]=se,u[me+3]=z[me+3]}for(let V=0;V<d;V++){let T=V*4,N=((h-1)*d+V)*4;u[T]=z[T],u[T+1]=z[T+1],u[T+2]=z[T+2],u[T+3]=z[T+3],u[N]=z[N],u[N+1]=z[N+1],u[N+2]=z[N+2],u[N+3]=z[N+3]}for(let V=1;V<h-1;V++){let T=V*d*4,N=(V*d+(d-1))*4;u[T]=z[T],u[T+1]=z[T+1],u[T+2]=z[T+2],u[T+3]=z[T+3],u[N]=z[N],u[N+1]=z[N+1],u[N+2]=z[N+2],u[N+3]=z[N+3]}return e};de.addGetterSetter(St,"embossStrength",.5,yt(),de.afterSetFilter),de.addGetterSetter(St,"embossWhiteLevel",.5,yt(),de.afterSetFilter),de.addGetterSetter(St,"embossDirection","top-left",void 0,de.afterSetFilter),de.addGetterSetter(St,"embossBlend",!1,void 0,de.afterSetFilter);function Y0(e,t,n,r,o){const i=n-t,s=o-r;if(i===0)return r+s/2;if(s===0)return r;let a=(e-t)/i;return a=s*a+r,a}var TF=function(e){const t=e.data,n=t.length;let r=t[0],o=r,i,s=t[1],a=s,l,c=t[2],u=c,d;const h=this.enhance();if(h===0)return;for(let y=0;y<n;y+=4)i=t[y+0],i<r?r=i:i>o&&(o=i),l=t[y+1],l<s?s=l:l>a&&(a=l),d=t[y+2],d<c?c=d:d>u&&(u=d);o===r&&(o=255,r=0),a===s&&(a=255,s=0),u===c&&(u=255,c=0);let g,p,v,k,C,_;if(h>0)g=o+h*(255-o),p=r-h*(r-0),v=a+h*(255-a),k=s-h*(s-0),C=u+h*(255-u),_=c-h*(c-0);else{const y=(o+r)*.5;g=o+h*(o-y),p=r+h*(r-y);const w=(a+s)*.5;v=a+h*(a-w),k=s+h*(s-w);const x=(u+c)*.5;C=u+h*(u-x),_=c+h*(c-x)}for(let y=0;y<n;y+=4)t[y+0]=Y0(t[y+0],r,o,p,g),t[y+1]=Y0(t[y+1],s,a,k,v),t[y+2]=Y0(t[y+2],c,u,_,C)};de.addGetterSetter(St,"enhance",0,yt(),de.afterSetFilter);var xF=function(e){const t=e.data,n=t.length;for(let r=0;r<n;r+=4){const o=.34*t[r]+.5*t[r+1]+.16*t[r+2];t[r]=o,t[r+1]=o,t[r+2]=o}};de.addGetterSetter(St,"hue",0,yt(),de.afterSetFilter),de.addGetterSetter(St,"saturation",0,yt(),de.afterSetFilter),de.addGetterSetter(St,"luminance",0,yt(),de.afterSetFilter);var RF=function(e){const t=e.data,n=t.length,r=1,o=Math.pow(2,this.saturation()),i=Math.abs(this.hue()+360)%360,s=this.luminance()*127,a=r*o*Math.cos(i*Math.PI/180),l=r*o*Math.sin(i*Math.PI/180),c=.299*r+.701*a+.167*l,u=.587*r-.587*a+.33*l,d=.114*r-.114*a-.497*l,h=.299*r-.299*a-.328*l,g=.587*r+.413*a+.035*l,p=.114*r-.114*a+.293*l,v=.299*r-.3*a+1.25*l,k=.587*r-.586*a-1.05*l,C=.114*r+.886*a-.2*l;let _,y,w,x;for(let L=0;L<n;L+=4)_=t[L+0],y=t[L+1],w=t[L+2],x=t[L+3],t[L+0]=c*_+u*y+d*w+s,t[L+1]=h*_+g*y+p*w+s,t[L+2]=v*_+k*y+C*w+s,t[L+3]=x},MF=function(e){const t=e.data,n=t.length,r=Math.pow(2,this.value()),o=Math.pow(2,this.saturation()),i=Math.abs(this.hue()+360)%360,s=r*o*Math.cos(i*Math.PI/180),a=r*o*Math.sin(i*Math.PI/180),l=.299*r+.701*s+.167*a,c=.587*r-.587*s+.33*a,u=.114*r-.114*s-.497*a,d=.299*r-.299*s-.328*a,h=.587*r+.413*s+.035*a,g=.114*r-.114*s+.293*a,p=.299*r-.3*s+1.25*a,v=.587*r-.586*s-1.05*a,k=.114*r+.886*s-.2*a;for(let C=0;C<n;C+=4){const _=t[C+0],y=t[C+1],w=t[C+2],x=t[C+3];t[C+0]=l*_+c*y+u*w,t[C+1]=d*_+h*y+g*w,t[C+2]=p*_+v*y+k*w,t[C+3]=x}};de.addGetterSetter(St,"hue",0,yt(),de.afterSetFilter),de.addGetterSetter(St,"saturation",0,yt(),de.afterSetFilter),de.addGetterSetter(St,"value",0,yt(),de.afterSetFilter);var LF=function(e){const t=e.data,n=t.length;for(let r=0;r<n;r+=4)t[r]=255-t[r],t[r+1]=255-t[r+1],t[r+2]=255-t[r+2]},PF=function(e,t,n){const r=e.data,o=t.data,i=e.width,s=e.height,a=n.polarCenterX||i/2,l=n.polarCenterY||s/2;let c=Math.sqrt(a*a+l*l),u=i-a,d=s-l;const h=Math.sqrt(u*u+d*d);c=h>c?h:c;const g=s,p=i,v=360/p*Math.PI/180;for(let k=0;k<p;k+=1){const C=Math.sin(k*v),_=Math.cos(k*v);for(let y=0;y<g;y+=1){u=Math.floor(a+c*y/g*_),d=Math.floor(l+c*y/g*C);let w=(d*i+u)*4;const x=r[w+0],L=r[w+1],z=r[w+2],$=r[w+3];w=(k+y*i)*4,o[w+0]=x,o[w+1]=L,o[w+2]=z,o[w+3]=$}}},DF=function(e,t,n){const r=e.data,o=t.data,i=e.width,s=e.height,a=n.polarCenterX||i/2,l=n.polarCenterY||s/2;let c=Math.sqrt(a*a+l*l),u=i-a,d=s-l;const h=Math.sqrt(u*u+d*d);c=h>c?h:c;const g=s,p=i,v=n.polarRotation||0;let k,C;for(u=0;u<i;u+=1)for(d=0;d<s;d+=1){const _=u-a,y=d-l,w=Math.sqrt(_*_+y*y)*g/c;let x=(Math.atan2(y,_)*180/Math.PI+360+v)%360;x=x*p/360,k=Math.floor(x),C=Math.floor(w);let L=(C*i+k)*4;const z=r[L+0],$=r[L+1],R=r[L+2],F=r[L+3];L=(d*i+u)*4,o[L+0]=z,o[L+1]=$,o[L+2]=R,o[L+3]=F}},OF=function(e){const t=e.width,n=e.height;let r,o,i,s,a,l,c,u,d,h,g=Math.round(this.kaleidoscopePower());const p=Math.round(this.kaleidoscopeAngle()),v=Math.floor(t*(p%360)/360);if(g<1)return;const k=xe.createCanvasElement();k.width=t,k.height=n;const C=k.getContext("2d").getImageData(0,0,t,n);xe.releaseCanvas(k),PF(e,C,{polarCenterX:t/2,polarCenterY:n/2});let _=t/Math.pow(2,g);for(;_<=8;)_=_*2,g-=1;_=Math.ceil(_);let y=_,w=0,x=y,L=1;for(v+_>t&&(w=y,x=0,L=-1),o=0;o<n;o+=1)for(r=w;r!==x;r+=L)i=Math.round(r+v)%t,d=(t*o+i)*4,a=C.data[d+0],l=C.data[d+1],c=C.data[d+2],u=C.data[d+3],h=(t*o+r)*4,C.data[h+0]=a,C.data[h+1]=l,C.data[h+2]=c,C.data[h+3]=u;for(o=0;o<n;o+=1)for(y=Math.floor(_),s=0;s<g;s+=1){for(r=0;r<y+1;r+=1)d=(t*o+r)*4,a=C.data[d+0],l=C.data[d+1],c=C.data[d+2],u=C.data[d+3],h=(t*o+y*2-r-1)*4,C.data[h+0]=a,C.data[h+1]=l,C.data[h+2]=c,C.data[h+3]=u;y*=2}DF(C,e,{polarRotation:0})};de.addGetterSetter(St,"kaleidoscopePower",2,yt(),de.afterSetFilter),de.addGetterSetter(St,"kaleidoscopeAngle",0,yt(),de.afterSetFilter);function am(e,t,n){let r=(n*e.width+t)*4;const o=[];return o.push(e.data[r++],e.data[r++],e.data[r++],e.data[r++]),o}function Of(e,t){return Math.sqrt(Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)+Math.pow(e[2]-t[2],2))}function FF(e){const t=[0,0,0];for(let n=0;n<e.length;n++)t[0]+=e[n][0],t[1]+=e[n][1],t[2]+=e[n][2];return t[0]/=e.length,t[1]/=e.length,t[2]/=e.length,t}function NF(e,t){const n=am(e,0,0),r=am(e,e.width-1,0),o=am(e,0,e.height-1),i=am(e,e.width-1,e.height-1),s=t||10;if(Of(n,r)<s&&Of(r,i)<s&&Of(i,o)<s&&Of(o,n)<s){const a=FF([r,n,i,o]),l=[];for(let c=0;c<e.width*e.height;c++)l[c]=Of(a,[e.data[c*4],e.data[c*4+1],e.data[c*4+2]])<s?0:255;return l}}function BF(e,t){for(let n=0;n<e.width*e.height;n++)e.data[4*n+3]=t[n]}function zF(e,t,n){const r=[1,1,1,1,0,1,1,1,1],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let u=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const g=a+d-i,p=l+h-i;if(g>=0&&g<n&&p>=0&&p<t){const v=g*t+p,k=r[d*o+h];u+=e[v]*k}}s[c]=u===2040?255:0}return s}function VF(e,t,n){const r=[1,1,1,1,1,1,1,1,1],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let u=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const g=a+d-i,p=l+h-i;if(g>=0&&g<n&&p>=0&&p<t){const v=g*t+p,k=r[d*o+h];u+=e[v]*k}}s[c]=u>=1020?255:0}return s}function jF(e,t,n){const r=[.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let u=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const g=a+d-i,p=l+h-i;if(g>=0&&g<n&&p>=0&&p<t){const v=g*t+p,k=r[d*o+h];u+=e[v]*k}}s[c]=u}return s}var UF=function(e){let t=NF(e,this.threshold());return t&&(t=zF(t,e.width,e.height),t=VF(t,e.width,e.height),t=jF(t,e.width,e.height),BF(e,t)),e};de.addGetterSetter(St,"threshold",0,yt(),de.afterSetFilter);var HF=function(e){const t=this.noise()*255,n=e.data,r=n.length,o=t/2;for(let i=0;i<r;i+=4)n[i+0]+=o-2*o*Math.random(),n[i+1]+=o-2*o*Math.random(),n[i+2]+=o-2*o*Math.random()};de.addGetterSetter(St,"noise",.2,yt(),de.afterSetFilter);var $F=function(e){let t=Math.ceil(this.pixelSize()),n=e.width,r=e.height,o=Math.ceil(n/t),i=Math.ceil(r/t),s=e.data;if(t<=0){xe.error("pixelSize value can not be <= 0");return}for(let a=0;a<o;a+=1)for(let l=0;l<i;l+=1){let c=0,u=0,d=0,h=0;const g=a*t,p=g+t,v=l*t,k=v+t;let C=0;for(let _=g;_<p;_+=1)if(!(_>=n))for(let y=v;y<k;y+=1){if(y>=r)continue;const w=(n*y+_)*4;c+=s[w+0],u+=s[w+1],d+=s[w+2],h+=s[w+3],C+=1}c=c/C,u=u/C,d=d/C,h=h/C;for(let _=g;_<p;_+=1)if(!(_>=n))for(let y=v;y<k;y+=1){if(y>=r)continue;const w=(n*y+_)*4;s[w+0]=c,s[w+1]=u,s[w+2]=d,s[w+3]=h}}};de.addGetterSetter(St,"pixelSize",8,yt(),de.afterSetFilter);var GF=function(e){const t=Math.round(this.levels()*254)+1,n=e.data,r=n.length,o=255/t;for(let i=0;i<r;i+=1)n[i]=Math.floor(n[i]/o)*o};de.addGetterSetter(St,"levels",.5,yt(),de.afterSetFilter);var WF=function(e){const t=e.data,n=t.length,r=this.red(),o=this.green(),i=this.blue();for(let s=0;s<n;s+=4){const a=(.34*t[s]+.5*t[s+1]+.16*t[s+2])/255;t[s]=a*r,t[s+1]=a*o,t[s+2]=a*i,t[s+3]=t[s+3]}};de.addGetterSetter(St,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),de.addGetterSetter(St,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),de.addGetterSetter(St,"blue",0,E_,de.afterSetFilter);var KF=function(e){const t=e.data,n=t.length,r=this.red(),o=this.green(),i=this.blue(),s=this.alpha();for(let a=0;a<n;a+=4){const l=1-s;t[a]=r*s+t[a]*l,t[a+1]=o*s+t[a+1]*l,t[a+2]=i*s+t[a+2]*l}};de.addGetterSetter(St,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),de.addGetterSetter(St,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),de.addGetterSetter(St,"blue",0,E_,de.afterSetFilter),de.addGetterSetter(St,"alpha",1,function(e){return this._filterUpToDate=!1,e>1?1:e<0?0:e});var qF=function(e){const t=e.data,n=t.length;for(let r=0;r<n;r+=4){const o=t[r+0],i=t[r+1],s=t[r+2];t[r+0]=Math.min(255,o*.393+i*.769+s*.189),t[r+1]=Math.min(255,o*.349+i*.686+s*.168),t[r+2]=Math.min(255,o*.272+i*.534+s*.131)}},YF=function(e){const n=e.data;for(let r=0;r<n.length;r+=4){const o=n[r],i=n[r+1],s=n[r+2];.2126*o+.7152*i+.0722*s>=128&&(n[r]=255-o,n[r+1]=255-i,n[r+2]=255-s)}return e},XF=function(e){const t=this.threshold()*255,n=e.data,r=n.length;for(let o=0;o<r;o+=1)n[o]=n[o]<t?0:255};de.addGetterSetter(St,"threshold",.5,yt(),de.afterSetFilter);var ZF=o4.Util._assign(o4,{Arc:ca,Arrow:Hl,Circle:hu,Ellipse:Ja,Image:ji,Label:G0,Tag:$l,Line:ua,Path:Si,Rect:Lf,RegularPolygon:el,Ring:Gl,Sprite:vs,Star:tl,Text:or,TextPath:to,Transformer:xn,Wedge:da,Filters:{Blur:SF,Brightness:AF,Brighten:_F,Contrast:IF,Emboss:EF,Enhance:TF,Grayscale:xF,HSL:RF,HSV:MF,Invert:LF,Kaleidoscope:OF,Mask:UF,Noise:HF,Pixelate:$F,Posterize:GF,RGB:WF,RGBA:KF,Sepia:qF,Solarize:YF,Threshold:XF}}),QF=ZF;Lt();var JF=["dialog","floating"],E4=["top-right","top-left","bottom-right","bottom-left","top-center","bottom-center"];function eN(e){if(!e||typeof e!="object")throw new Error("SurfaceManager: request must be a non-null object.");if(!JF.includes(e.mode))throw new Error(`SurfaceManager: mode must be "dialog" or "floating", got "${e.mode}".`);const t="kind"in e&&e.kind!=null,n="component"in e&&e.component!=null,r="render"in e&&typeof e.render=="function";if(n&&r)throw new Error('SurfaceManager: request cannot provide both "component" and "render". Use one or the other.');if(!t&&!n&&!r)throw new Error('SurfaceManager: request must provide "kind" (intent-based) or "component"/"render" (direct-render).');if(e.mode==="floating"&&e.floating?.placement!=null&&!E4.includes(e.floating.placement))throw new Error(`SurfaceManager: floating.placement must be one of ${E4.join(", ")}, got "${e.floating.placement}".`)}var tN=class{activeDialog=eo(null);activeFloating=eo(null);#t=!1;#n=1;#e;constructor({getModuleConfig:e}){this.#e=e}open(e){if(this.#t)return this.#f(e);eN(e);const t=this.#d(e),{component:n,props:r,render:o}=this.#h(t);let i,s=!1;const a=new Promise(g=>{i=p=>s?!1:(s=!0,g(p),!0)});let l;const c=g=>{i({status:"submitted",data:g})&&this.#i(l)},u=g=>{i({status:"closed",reason:g})&&this.#i(l)};l={id:t.id,mode:t.mode,request:t,component:n,props:r,render:o,resolve:c,close:u,settle:g=>i(g),get settled(){return s}};const d=t.mode==="dialog"?"activeDialog":"activeFloating",h=this[d].value;return h&&!h.settled&&h.settle({status:"replaced",replacedBy:t.id}),this[d].value=l,{id:t.id,mode:t.mode,close:g=>this.#r(l,g),result:a}}close(e,t){if(e!=null){const o=this.#s(e);o&&this.#r(o,t);return}const n=this.activeDialog.value;if(n&&!n.settled){this.#r(n,t);return}const r=this.activeFloating.value;r&&!r.settled&&this.#r(r,t)}settleAll(e){for(const t of[this.activeDialog,this.activeFloating]){const n=t.value;n&&!n.settled&&n.settle(e),t.value=null}}destroy(){this.#t=!0,this.settleAll({status:"destroyed"})}#r(e,t){e.settled||(e.settle({status:"closed",reason:t}),this.#i(e))}#i(e){const t=e.mode==="dialog"?this.activeDialog:this.activeFloating;t.value===e&&(t.value=null)}#s(e){return this.activeDialog.value?.id===e?this.activeDialog.value:this.activeFloating.value?.id===e?this.activeFloating.value:null}#d(e){const t=e.id??`surface-${this.#n++}`,n=this.#e()??{},r=e.mode==="dialog"?n.dialog:n.floating,o=e.mode==="dialog"?{maxWidth:r?.maxWidth,...e.dialog}:e.dialog,i=e.mode==="floating"?{placement:r?.placement??"top-right",width:r?.width,maxWidth:r?.maxWidth,maxHeight:r?.maxHeight,autoFocus:r?.autoFocus??!0,closeOnOutsidePointerDown:r?.closeOnOutsidePointerDown??!1,...e.floating}:e.floating;return{...e,id:t,closeOnEscape:e.closeOnEscape??r?.closeOnEscape??!0,closeOnBackdrop:e.mode==="dialog"?e.closeOnBackdrop??r?.closeOnBackdrop??!0:!1,dialog:o,floating:i}}#h(e){if("component"in e&&e.component!=null)return{component:e.component,props:e.props};if("render"in e&&typeof e.render=="function")return{render:e.render};const t=this.#e()?.resolver;if(typeof t=="function"){const n=t(e);if(n!=null){if(n.type==="none")throw new Error(`SurfaceManager: resolver explicitly suppressed surface for kind "${e.kind}".`);if(n.type==="custom")return{component:n.component,props:n.props};if(n.type==="external")return{render:n.render}}}throw new Error(`SurfaceManager: no renderer resolved for kind "${e.kind}". Provide a resolver via surfaces.resolver, or use a direct-render request.`)}#f(e){return{id:e?.id??`surface-${this.#n++}`,mode:e?.mode??"dialog",close:()=>{},result:Promise.resolve({status:"destroyed"})}}},nN="https://docs.superdoc.dev/guides/migration/document-api",T4=new Set;function rN(e,t){T4.has(e)||(T4.add(e),console.warn(t))}var oN={state:"editor.state",view:"editor.view",schema:"editor.schema",commands:"editor.commands",chain:"editor.chain()",can:"editor.can()",dispatch:"editor.dispatch()"},x4=Symbol.for("superdoc:rawEditor"),R4=new WeakMap;function M4(e){return!e||e[x4]?e:new Proxy(e,{get(t,n){if(n===x4)return t;const r=oN[n];r&&rN(`deprecated:${String(n)}`,`[SuperDoc] ${r} is deprecated and will be removed in a future version. Use the Document API (editor.doc) instead. See ${nN}`);const o=Reflect.get(t,n,t);if(typeof o=="function"){let i=R4.get(t);return i||(i=new Map,R4.set(t,i)),i.has(n)||i.set(n,o.bind(t)),i.get(n)}return o}})}var L4=["review","original","final","off"],iN=["paired","independent"],P4=Symbol.for("@superdoc/trackChanges:normalized"),D4=new Set;function O4(e,t){D4.has(e)||(D4.add(e),console.warn(`[SuperDoc] ${e} is deprecated β use ${t} instead.`))}function F4(e,t,n){return typeof e=="boolean"?e:typeof t=="boolean"?t:n}function sN(e,t,n){return typeof e=="string"&&L4.includes(e)?e:typeof t=="string"&&L4.includes(t)?t:n}function aN(e){return typeof e=="string"&&iN.includes(e)?e:null}function Wl(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function lN(e){const t=e[P4]===!0;Wl(e.modules)||(e.modules={});const n=Wl(e.modules.trackChanges),r=Wl(e.trackChanges),o=Wl(e.layoutEngineOptions?.trackedChanges);t||(r&&O4("config.trackChanges","config.modules.trackChanges"),o&&O4("config.layoutEngineOptions.trackedChanges","config.modules.trackChanges"));const i=F4(n?.visible,r?.visible,!1),s=F4(n?.enabled,o?.enabled,!0),a=aN(n?.replacements)??"paired",l=Wl(n?.authorColors)?n.authorColors:void 0,c=Wl(n?.semanticColors)?n.semanticColors:void 0,u=e.documentMode==="viewing"?i?"review":"original":"review",d=sN(n?.mode,o?.mode,u),h={visible:i,mode:d,enabled:s,replacements:a};return l&&(h.authorColors=l),c&&(h.semanticColors=c),e.modules.trackChanges=h,e.trackChanges={visible:i},Wl(e.layoutEngineOptions)||(e.layoutEngineOptions={}),e.layoutEngineOptions.trackedChanges={mode:d,enabled:s},Object.defineProperty(e,P4,{value:!0,writable:!0,configurable:!0,enumerable:!1}),h}var X0=Object.freeze({id:null,name:"Default SuperDoc user",email:null});function cN(e){return!e||typeof e!="object"?{...X0}:{...X0,...e}}var N4=Object.freeze({toolbar:!0,comments:!0,contextMenu:!0,search:!1,linkPopover:!1,ruler:!1,contentControls:!0}),uN=Object.freeze(["left","center","right"]),UH=Object.freeze(Object.keys(N4)),mu=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function B4(e,t){const n=e?.[t];return n===!1?!1:n===void 0?N4[t]:!0}function dN(e,t){const n=e?.[t];return mu(n)?n:{}}var z4=Object.freeze(["readOnly","allowResolve","permissionResolver"]);function fN(e){if(!z4.some(n=>n in e))return e;const t={...e};for(const n of z4)delete t[n];return t}function V4(e={}){const t=e.ui,n=t===!1,r=mu(t)?t:void 0,o=R=>!n&&B4(r,R),i=R=>n?!1:r?.[R]===void 0?void 0:B4(r,R),s=R=>n?{}:dN(r,R),a=n||i("ruler")===!1,l=n||i("linkPopover")===!1,c=l?void 0:v0(s("linkPopover").popoverResolver,e.modules?.links?.popoverResolver),u=i("contentControls")??(!n&&e.modules?.contentControls?.chrome!=="none"),d=e.modules?.contentControls?.chrome==="none"?void 0:e.modules?.contentControls?.chrome,h=s("toolbar"),g=e.modules?.toolbar,p=mu(g)?g:{},v=e.modules?.contextMenu??e.modules?.slashMenu,k=mu(v)?v:{},C=e.modules?.surfaces?.findReplace,_=mu(C)?C:{},y=[h.groups,p.groups],w=y.find(mu),x=v0(y.find(Array.isArray),p.toolbarGroups,e.toolbarGroups),L=Array.isArray(x)?x:null,z=(R,F)=>Object.prototype.hasOwnProperty.call(R,F),$=w&&L?Object.fromEntries([...L.filter(R=>z(w,R)),...Object.keys(w).filter(R=>!uN.includes(R))].map(R=>[R,w[R]])):w;return{enabled:!n,toolbar:{enabled:o("toolbar"),container:n?null:v0(h.container,p.selector,e.toolbar)??null,options:n?{}:{...gs(p,h),groups:$,toolbarGroups:x,icons:gs(e.toolbarIcons,p.icons,h.icons),texts:gs(e.toolbarTexts,p.texts,h.texts)}},comments:{enabled:i("comments")??(!n&&e.modules?.comments!==!1),options:n?{}:Ok(fN(s("comments")))},contextMenu:{enabled:i("contextMenu")??(!n&&e.disableContextMenu!==!0),suppressed:n||i("contextMenu")===!1,options:n?{}:gs(k,s("contextMenu"))},search:{enabled:i("search")??(!n&&!!e.modules?.surfaces?.findReplace),options:n?{}:gs(_,s("search"))},linkPopover:{enabled:typeof c=="function",suppressed:l,options:gs(s("linkPopover"),{popoverResolver:c})},ruler:{enabled:i("ruler")??(!n&&!!e.rulers),suppressed:a,container:a?null:s("ruler").container??e.rulerContainer??null},contentControls:{enabled:u,options:u?gs({chrome:d},s("contentControls")):{chrome:"none"}}}}var Z0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function j4(e={}){const t=Z0(e.interaction)?e.interaction:{},n=Z0(t.comments)?t.comments:{},r=Z0(e.modules?.comments)?e.modules.comments:{};return{comments:{readOnly:(n.readOnly??r.readOnly??!1)===!0,allowResolve:(n.allowResolve??r.allowResolve??!0)!==!1}}}var U4=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function H4(e={}){const t=U4(e.surfaces)?e.surfaces:{},n=U4(e.modules?.surfaces)?e.modules.surfaces:{},r=t.resolver===void 0?n.resolver:t.resolver;return{resolver:typeof r=="function"?r:null,dialog:gs(n.dialog,t.dialog),floating:gs(n.floating,t.floating)}}var hN=class{#t=new Map;#n=new Map;#e=null;#r=new Set;register(e){if(this.#t.has(e.id))throw new Error(`EditorRuntimeRegistry: duplicate runtime id "${e.id}"`);const t=e.root,n=t?this.#n.get(t):void 0;if(n!==void 0&&n!==e.id)throw new Error(`EditorRuntimeRegistry: root element already registered to runtime "${n}"`);this.#t.set(e.id,e),t&&this.#n.set(t,e.id)}unregister(e){const t=this.#t.get(e);return t?(this.#t.delete(e),t.root&&this.#n.delete(t.root),this.#e===e&&(this.#e=null,this.#i({previousRuntimeId:e,nextRuntimeId:null,reason:"active-runtime-unregistered",legacyEditorProjection:null})),!0):!1}get(e){return this.#t.get(e)??null}getAll(){return Array.from(this.#t.values())}getAllByDocumentId(e){const t=[];for(const n of this.#t.values())n.documentId===e&&t.push(n);return t}getActive(){return this.#e===null?null:this.#t.get(this.#e)}getActiveId(){return this.#e}setActive(e,t){if(e!==null&&!this.#t.has(e))throw new Error(`EditorRuntimeRegistry: cannot activate unknown runtime "${e}"`);if(e===this.#e)return;const n=this.#e;this.#e=e;let r=null;e!==null&&(r=this.#t.get(e).getLegacyEditorProjection?.()??null),this.#i({previousRuntimeId:n,nextRuntimeId:e,reason:t,legacyEditorProjection:r})}resolveFromEventTarget(e){const t=e instanceof Element?e:e instanceof Node?e.parentElement:null;if(!t)return null;const n=t.closest(`[${jp}]`);if(!n)return null;const r=n.getAttribute(jp),o=r?this.get(r):null;return o&&o.root===n?o:null}subscribe(e){return this.#r.add(e),()=>{this.#r.delete(e)}}clear(){this.#t.clear(),this.#n.clear(),this.#e=null,this.#r.clear()}#i(e){for(const t of Array.from(this.#r))try{t(e)}catch{}}},dt={notReady:"not-ready",documentApiUnavailable:"document-api-unavailable",documentReadonly:"document-readonly",selectionRequired:"selection-required",rangeSelectionRequired:"range-selection-required",contextUnavailable:"context-unavailable",geometryUnavailable:"geometry-unavailable",targetUnresolved:"target-unresolved",targetNotVisible:"target-not-visible",commandUnsupported:"command-unsupported",commandDeferred:"command-deferred",tableContextUnavailable:"table-context-unavailable",operationUnavailable:"operation-unavailable",bulkDecisionsDisabled:"bulk-decisions-disabled",hostCapabilityUnavailable:"host-capability-unavailable",historyEmpty:"history-empty",searchUnavailable:"search-unavailable",searchInvalidPattern:"search-invalid-pattern",replaceUnsupported:"replace-unsupported",contentControlLocked:"content-control-locked"},$4={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strikethrough",fontFamily:"font-family",fontSize:"font-size",setFontFamily:"setFontFamily",setFontSize:"setFontSize",undo:"undo",redo:"redo",acceptChange:"acceptChange",rejectChange:"rejectChange",acceptAllChanges:"acceptAllChanges",rejectAllChanges:"rejectAllChanges",bulletList:"bullet-list",numberedList:"numbered-list"};function G4(e){const t=n=>typeof n=="string"?n.replace(/\s*pt$/i,"").trim():n;if(typeof e=="string")return t(e);if(e&&typeof e=="object"&&"value"in e){const n=e;return{...n,value:t(n.value)}}return e}function pN(e){const t=(n,r)=>!r&&n>0&&n<=5?n*100:n;if(typeof e=="string"){const n=e.includes("%"),r=Number.parseFloat(e.replace("%","").trim());return Number.isFinite(r)?t(r,n):e}return typeof e=="number"&&Number.isFinite(e)?t(e,!1):e}function mN(e){const t=e&&typeof e=="object"&&"value"in e?e.value:e;if(t==="in"||t==="cm")return t;if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="in"||n==="inch"||n==="inches")return"in";if(n==="cm"||n==="centimeter"||n==="centimeters"||n==="centimetre"||n==="centimetres")return"cm"}return t}function W4(e){const t=n=>{if(n===null)return null;if(typeof n!="string")return n;const r=n.trim();return r===""?n:/^#[0-9a-fA-F]{6}$/.test(r)?r:/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r};if(e&&typeof e=="object"&&"value"in e){const n=e;return{...n,value:t(n.value)}}return t(e)}function Q0(e,t){if(e&&typeof e=="object"){const n=e;for(const r of t)if(r in n)return n[r]}return e}function gN(e){const t=Q0(e,["alignment","value"]);if(typeof t!="string")return t;const n=t.trim().toLowerCase();return n==="justified"||n==="both"?"justify":n}function vN(e){const t=Q0(e,["line","lineHeight","value"]),n=typeof t=="number"?t:typeof t=="string"?Number.parseFloat(t.trim()):NaN;return!Number.isFinite(n)||n<=0?t:n<=10?Math.round(n*240):Math.round(n)}function yN(e){if(e&&typeof e=="object"&&"role"in e)return e;const t=Q0(e,["styleId","value","style"]);return typeof t=="string"?t.trim():t}function bN(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){const t=e.mode;if(typeof t=="string")return t}return e}var wN=dt.commandUnsupported,ys=dt.tableContextUnavailable,K4=[{id:"bold",family:"inline marks",disposition:"routed",mutates:!0,docRoute:"format.bold",activeMark:"bold",inline:{key:"bold",kind:"toggle"}},{id:"italic",family:"inline marks",disposition:"routed",mutates:!0,docRoute:"format.italic",activeMark:"italic",inline:{key:"italic",kind:"toggle"}},{id:"underline",family:"inline marks",disposition:"routed",mutates:!0,docRoute:"format.underline",activeMark:"underline",inline:{key:"underline",kind:"toggle"}},{id:"strikethrough",family:"inline marks",disposition:"routed",mutates:!0,docRoute:"format.strikethrough",activeMark:"strikethrough",inline:{key:"strike",kind:"toggle"}},{id:"font-family",family:"fonts",disposition:"routed",mutates:!0,docRoute:"format.fontFamily",aliases:["setFontFamily"],inline:{key:"fontFamily",kind:"value-string"}},{id:"font-size",family:"fonts",disposition:"routed",mutates:!0,docRoute:"format.fontSize",aliases:["setFontSize"],normalizePayload:G4,inline:{key:"fontSize",kind:"value-number"}},{id:"setFontFamily",family:"fonts",disposition:"routed",mutates:!0,docRoute:"format.fontFamily",aliasOf:"font-family",inline:{key:"fontFamily",kind:"value-string"}},{id:"setFontSize",family:"fonts",disposition:"routed",mutates:!0,docRoute:"format.fontSize",aliasOf:"font-size",normalizePayload:G4,inline:{key:"fontSize",kind:"value-number"}},{id:"undo",family:"history",disposition:"routed",mutates:!0,docRoute:"history.undo"},{id:"redo",family:"history",disposition:"routed",mutates:!0,docRoute:"history.redo"},{id:"acceptChange",family:"tracked changes",disposition:"routed",mutates:!0,trackDecision:{kind:"accept",scope:"id"},aliases:["track-changes-accept-selection"]},{id:"rejectChange",family:"tracked changes",disposition:"routed",mutates:!0,trackDecision:{kind:"reject",scope:"id"},aliases:["track-changes-reject-selection"]},{id:"acceptAllChanges",family:"tracked changes (bulk)",disposition:"routed",mutates:!0,trackDecision:{kind:"accept",scope:"all"}},{id:"rejectAllChanges",family:"tracked changes (bulk)",disposition:"routed",mutates:!0,trackDecision:{kind:"reject",scope:"all"}},{id:"track-changes-accept-selection",family:"tracked changes",disposition:"routed",mutates:!0,trackDecision:{kind:"accept",scope:"id"},aliasOf:"acceptChange"},{id:"track-changes-reject-selection",family:"tracked changes",disposition:"routed",mutates:!0,trackDecision:{kind:"reject",scope:"id"},aliasOf:"rejectChange"},{id:"zoom",family:"zoom",disposition:"routed",mutates:!1,instanceRoute:"setZoom",valueFrom:"zoom",normalizePayload:pN},{id:"zoom-fit-width",family:"zoom",disposition:"routed",mutates:!1,instanceRoute:"setZoomMode",fixedArg:"fit-width",valueFrom:"zoom"},{id:"document-mode",family:"document",disposition:"routed",mutates:!1,instanceRoute:"setDocumentMode",valueFrom:"documentMode",normalizePayload:bN},{id:"measurement-unit",family:"measurement",disposition:"routed",mutates:!1,instanceRoute:"setMeasurementUnit",valueFrom:"measurementUnit",normalizePayload:mN},{id:"text-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.color",inline:{key:"color",kind:"value-string"},normalizePayload:W4},{id:"highlight-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.highlight",inline:{key:"highlight",kind:"value-string"},normalizePayload:W4},{id:"link",family:"links",disposition:"routed",mutates:!0,docRoute:"hyperlinks.wrap",activeMark:"link",link:{kind:"link"}},{id:"text-align",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setAlignment",blockParagraph:{kind:"alignment"},normalizePayload:gN},{id:"line-height",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setSpacing",blockParagraph:{kind:"spacing-line"},normalizePayload:vN},{id:"linked-style",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"styles.paragraph.setStyle",blockParagraph:{kind:"style"},normalizePayload:yN},{id:"bullet-list",family:"lists",disposition:"routed",mutates:!0,docRoute:"lists.apply",list:{mode:"toggle-seed",seed:"bullet"}},{id:"numbered-list",family:"lists",disposition:"routed",mutates:!0,docRoute:"lists.apply",list:{mode:"toggle-seed",seed:"ordered"}},{id:"indent-increase",family:"lists/indent",disposition:"routed",mutates:!0,docRoute:"lists.indent",list:{mode:"indent"}},{id:"indent-decrease",family:"lists/indent",disposition:"routed",mutates:!0,docRoute:"lists.outdent",list:{mode:"outdent"}},{id:"direction-ltr",family:"direction",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setDirection",blockParagraph:{kind:"direction",fixedValue:"ltr"}},{id:"direction-rtl",family:"direction",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setDirection",blockParagraph:{kind:"direction",fixedValue:"rtl"}},{id:"clear-formatting",family:"formatting",disposition:"routed",mutates:!0,docRoute:"format.apply",inline:{key:"*",kind:"clear"}},{id:"image",family:"media",disposition:"routed",mutates:!0,docRoute:"create.image",create:{kind:"image"}},{id:"table-of-contents-insert",family:"TOC",disposition:"routed",mutates:!0,docRoute:"create.tableOfContents",create:{kind:"toc"}},{id:"table-insert",family:"tables",disposition:"routed",mutates:!0,docRoute:"create.table",create:{kind:"table"}},{id:"table-add-row-before",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertRow",table:{action:"insert-row-before",op:"insertRow"},reason:ys},{id:"table-add-row-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertRow",table:{action:"insert-row-after",op:"insertRow"},reason:ys},{id:"table-delete-row",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteRow",table:{action:"delete-row",op:"deleteRow"},reason:ys},{id:"table-add-column-before",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-before",op:"insertColumn"},reason:ys},{id:"table-add-column-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-after",op:"insertColumn"},reason:ys},{id:"table-delete-column",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteColumn",table:{action:"delete-column",op:"deleteColumn"},reason:ys},{id:"table-delete",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.delete",table:{action:"delete-table",op:"delete"},reason:ys},{id:"table-merge-cells",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.mergeCells",table:{action:"merge-cells",op:"mergeCells"},reason:ys},{id:"table-split-cell",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.splitCell",table:{action:"split-cell",op:"splitCell",requiresCell:!0},reason:ys},{id:"table-remove-borders",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.setBorders",table:{action:"remove-borders",op:"setBorders"},reason:ys},{id:"ruler",family:"UI chrome",disposition:"routed",mutates:!1,instanceRoute:"toggleRuler",valueFrom:"ruler"},{id:"formatting-marks",family:"UI chrome",disposition:"routed",mutates:!1,instanceRoute:"toggleFormattingMarks",valueFrom:"formattingMarks"},{id:"copy-format",family:"formatting",disposition:"routed",mutates:!1},{id:"table-fix",family:"tables",disposition:"unsupported",mutates:!0,reason:wN}],CN=new Map(K4.map(e=>[e.id,e])),kN=K4.map(e=>e.id);function gu(e){return CN.get(e)??null}var SN=["table-add-row-before","table-add-row-after","table-delete-row","table-add-column-before","table-add-column-after","table-delete-column","table-delete","table-merge-cells","table-split-cell","table-remove-borders"],q4=[{name:"bold",commandId:"bold",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"italic",commandId:"italic",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"underline",commandId:"underline",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"strike",commandId:"strikethrough",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"clearFormatting",commandId:"clear-formatting",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"copyFormat",commandId:"copy-format",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"fontFamily",commandId:"font-family",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"fontSize",commandId:"font-size",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"color",commandId:"text-color",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"highlight",commandId:"highlight-color",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"textAlign",commandId:"text-align",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"list",commandId:"bullet-list",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"numberedlist",commandId:"numbered-list",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"indentleft",commandId:"indent-decrease",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"indentright",commandId:"indent-increase",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"lineHeight",commandId:"line-height",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"linkedStyles",commandId:"linked-style",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"link",commandId:"link",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"image",commandId:"image",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"table",commandId:"table-insert",instanceMethod:null,disposition:"controller-routed",group:"center"},{name:"tableActions",commandId:null,instanceMethod:null,disposition:"shell-owned",group:"center",memberCommandIds:SN,note:"table editing dropdown is shell chrome; its member commands are controller-routed through the shared table-context facade (ui.tables / host.getTableContext()) and fail closed with table-context-unavailable when the caret is not in a table"},{name:"undo",commandId:"undo",instanceMethod:null,disposition:"controller-routed",group:"left"},{name:"redo",commandId:"redo",instanceMethod:null,disposition:"controller-routed",group:"left"},{name:"search",commandId:null,instanceMethod:null,disposition:"shell-owned",group:"right",note:"built-in search button; opens the shared find/replace surface (the same one Cmd/Ctrl+F opens) by emitting a `search:open` event on the SuperDoc instance, which the shell handles. The surface reads/drives the controller search surface (ui.search), backed by the single V2 host search session (host.search) which owns query, navigation, reveal, and replace. Find/navigation are always available when the host exposes search; replace/replaceAll mutate through the host session and fail closed (document-readonly) in viewing/read-only mode. If a runtime cannot expose search, the surface fails closed with search-unavailable"},{name:"zoom",commandId:"zoom",instanceMethod:null,disposition:"controller-routed",group:"right"},{name:"measurementUnit",commandId:"measurement-unit",instanceMethod:null,disposition:"controller-routed",group:"right"},{name:"ruler",commandId:null,instanceMethod:"toggleRuler",disposition:"host-routed",group:"right",note:"built-in shell toggles ruler visibility through the public SuperDoc.toggleRuler() instance method; the controller also routes the ruler command through it so custom UIs drive the same chrome (active state from config.rulers)"},{name:"formattingMarks",commandId:null,instanceMethod:"toggleFormattingMarks",disposition:"host-routed",group:"right",note:"built-in shell toggles nonprinting marks through the public SuperDoc.toggleFormattingMarks()/setShowFormattingMarks() instance methods (not a controller command)"},{name:"documentMode",commandId:"document-mode",instanceMethod:null,disposition:"controller-routed",group:"right"},{name:"acceptTrackedChangeBySelection",commandId:"track-changes-accept-selection",instanceMethod:null,disposition:"controller-routed",group:"right"},{name:"rejectTrackedChangeOnSelection",commandId:"track-changes-reject-selection",instanceMethod:null,disposition:"controller-routed",group:"right"},{name:"customButtons",commandId:null,instanceMethod:null,disposition:"shell-owned",group:"center",note:"consumer-defined buttons the rendered shell owns; their execution context surface is phase 2"}],Y4=new Map(q4.map(e=>[e.name,e])),HH=q4.map(e=>e.name);function J0(e){return Y4.get(e)??null}function _N(e){const t=Y4.get(e);return t?.disposition==="controller-routed"?t.commandId:null}var AN=".png,.jpg,.jpeg,image/png,image/jpeg",X4=new Set(["image/png","image/jpeg","image/jpg"]),IN=/\.(png|jpe?g)$/i;function EN(e){if(!e)return!1;const t=typeof e.type=="string"?e.type.toLowerCase():"";return t?X4.has(t):IN.test(String(e.name??""))}function Z4(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(TN(String(r.result),e)),r.onerror=()=>n(r.error??new Error("image-read-failed")),r.readAsDataURL(e)})}function TN(e,t){const n=/^data:([^;,]*);base64,/.exec(e);if(!n)return e;const r=n[1].toLowerCase();if(X4.has(r))return e;const o=String(t?.name??""),i=/\.jpe?g$/i.test(o)?"image/jpeg":/\.png$/i.test(o)?"image/png":null;return i?`data:${i};base64,${e.slice(n[0].length)}`:e}async function xN(e,t){if(typeof t=="function"){const n=await t(e);if(typeof n!="string"||n.trim()==="")throw new Error("handleImageUpload returned an empty result");return n.startsWith("data:")?n:RN(n,e)}return Z4(e)}async function RN(e,t){const n=await fetch(e);if(!n.ok)throw new Error(`image fetch failed: ${n.status}`);const r=await n.blob(),o=(/\.(?:png|jpe?g)(?:$|[?#])/i.test(e)?e.split(/[?#]/)[0]:"")||t?.name||"";return Z4(o?Object.assign(r,{name:o}):r)}function MN({ownerDocument:e=document,onPick:t,onError:n}={}){const r=e.createElement("input");return r.type="file",r.accept=AN,r.hidden=!0,r.tabIndex=-1,r.setAttribute("data-superdoc-image-picker","true"),r.setAttribute("aria-hidden","true"),r.addEventListener("change",()=>{const o=r.files&&r.files[0];if(r.value="",!!o){if(!EN(o)){n?.(new Error(`unsupported image type: ${o.type||o.name}`));return}try{const i=t?.(o);i&&typeof i.then=="function"&&i.catch(s=>n?.(s))}catch(i){n?.(i)}}}),e.body?.appendChild(r),{input:r,open(){r.click()},destroy(){r.remove()}}}var LN=(e,t)=>{let n=e.replace(/[^0-9.]/g,"");return n=parseFloat(n),isNaN(n)&&(n=t),n=parseFloat(n),n},PN=(e,t,n)=>{let r,o,i,s=0;n||(n={});const a=()=>{s=n.leading===!1?0:Date.now(),r=null,i=e(...o),r||(o=null)},l=(...c)=>{const u=Date.now();!s&&n.leading===!1&&(s=u);const d=t-(u-s);return o=c,d<=0||d>t?(r&&(clearTimeout(r),r=null),s=u,i=e(...c),r||(o=null)):!r&&n.trailing!==!1&&(r=setTimeout(a,d)),i};return l.cancel=function(){clearTimeout(r),s=0,r=o=null},l};Lt(),kn();var DN={class:"sd-toolbar-icon"},ON=["innerHTML"],FN={__name:"ToolbarButtonIcon",props:{name:{type:String,required:!0},color:{type:String,default:null},icon:{type:String,default:null}},setup(e){const t=e,n=Ae(()=>{if(t.name==="color")return{backgroundColor:t.color||"#111111"};if(t.name==="highlight")return{backgroundColor:t.color||"#D6D6D6"}}),r=Ae(()=>["color","highlight"].includes(t.name));return(o,i)=>(ge(),Ie("div",DN,[Oe("div",{class:ln(["sd-toolbar-icon__icon",[`sd-toolbar-icon__icon--${t.name}`]]),innerHTML:e.icon},null,10,ON),r.value?(ge(),Ie("div",{key:0,class:"color-bar",style:Sn(n.value)},null,4)):vt("",!0)]))}},Q4=vn(FN,[["__scopeId","data-v-d7d79424"]]);Lt(),kn();var NN=["role","aria-label"],BN=["data-item"],zN=["data-item"],VN={key:1,class:"sd-button-label"},jN=["data-item","aria-label"],UN=["innerHTML"],HN={key:2},$N=["onKeydown","id"],GN=["placeholder","onKeydown","id","data-item"],WN=["data-item","innerHTML"],KN={"aria-live":"polite",class:"sd-visually-hidden"},qN={__name:"ToolbarButton",props:{iconColor:{type:String,default:null},active:{type:Boolean,default:!1},isNarrow:{type:Boolean,default:!1},isWide:{type:Boolean,default:!1},toolbarItem:{type:Object,required:!0},defaultLabel:{type:String,default:null},isOverflowItem:{type:Boolean,default:!1},allowEnterPropagation:{type:Boolean,default:!1}},emits:["buttonClick","textSubmit","mainClick"],setup(e,{emit:t}){const n=t,{proxy:r}=ur(),o=e,{name:i,active:s,icon:a,label:l,hideLabel:c,iconColor:u,hasCaret:d,splitButton:h,disabled:g,expand:p,inlineTextInputVisible:v,hasInlineTextInput:k,minWidth:C,style:_,attributes:y}=o.toolbarItem,w=Ae(()=>!!h?.value&&!!d?.value),x=Ae(()=>i?.value??""),L=ne(""),z=ne(null),{isHighContrastMode:$}=Ni();Vt(()=>l?.value,ke=>{document.activeElement!==z.value&&(L.value=ke==null?"":String(ke))},{immediate:!0});const R=()=>{k&&It(()=>{z.value?.focus(),z.value?.select()}),n("buttonClick")},F=ke=>{g?.value||(ke?.stopPropagation(),n("mainClick"))},X=()=>{w.value||R()},D=ke=>{if(w.value){F(ke);return}R()},V=ke=>{o.allowEnterPropagation||ke.stopPropagation(),D(ke)},T=ke=>{const re=o.toolbarItem?.nestedOptions?.value??[],Re=ke.trim();if(!Re)return"";const Je=re.find(st=>typeof st?.label=="string"&&st.label.toLowerCase()===Re.toLowerCase());return Je?.label?Je.label:re.find(st=>typeof st?.label=="string"&&st.label.toLowerCase().startsWith(Re.toLowerCase()))?.label??Re},N=()=>{const ke=String(L.value??"").trim();let re=ke;if(x.value==="fontSize"){const Re=Number.parseFloat(ke);re=ke.match(/^\d+(\.5)?$/)?ke:Number.isFinite(Re)?Math.floor(Re).toString():""}else x.value==="fontFamily"&&(re=T(ke));return re?(n("textSubmit",re),L.value=re,!0):!1},Q=ke=>{const re=ke?.currentTarget;re instanceof HTMLInputElement&&(re.focus({preventScroll:!0}),re.select())},K=ke=>{requestAnimationFrame(()=>{const re=document.getElementById(`inlineTextInput-${ke}`);re instanceof HTMLInputElement&&(re.focus({preventScroll:!0}),re.select())})},se=()=>{const ke=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return ke instanceof HTMLElement?(ke.focus({preventScroll:!0}),!0):!1},me=()=>{const ke=r?.$toolbar?.pendingSelectionCapture,re=()=>{ke&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(ke)};if(se()){re();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),re())},Be=()=>{N()&&me()},he=ke=>{if(N(),ke.shiftKey){x.value==="fontSize"&&(ke.preventDefault(),It(()=>K("fontFamily")));return}if(ke.preventDefault(),x.value==="fontFamily"){It(()=>K("fontSize"));return}x.value==="fontSize"&&It(me)},ve=Ae(()=>_.value?_.value:{minWidth:o.minWidth}),ue=Ae(()=>p?.value?rr.dropdownCaretUp:rr.dropdownCaretDown);return(ke,re)=>(ge(),Ie("div",{class:ln(["sd-toolbar-item",Qe(y).className]),style:Sn(ve.value),role:e.isOverflowItem?"menuitem":"button","aria-label":Qe(y).ariaLabel,"data-sd-part":"toolbar-item",onClick:X,onKeydown:re[9]||(re[9]=Yo(Re=>V(Re),["enter"])),tabindex:"0"},[Oe("div",{class:ln(["sd-toolbar-button",{"sd-active":Qe(s),"sd-disabled":Qe(g),narrow:e.isNarrow,wide:e.isWide,split:w.value,"has-inline-text-input":Qe(k),"high-contrast":Qe($)}]),"data-item":`btn-${Qe(i)||""}`},[w.value?(ge(),Ie("div",{key:0,class:"sd-toolbar-button__main","data-item":`btn-${Qe(i)||""}-main`,onClick:re[0]||(re[0]=Re=>F(Re))},[Qe(a)?(ge(),gn(Q4,{key:0,color:Qe(u),class:"sd-toolbar-icon",icon:Qe(a),name:Qe(i)},null,8,["color","icon","name"])):vt("",!0),Qe(l)&&!Qe(c)&&!Qe(v)?(ge(),Ie("div",VN,Wt(Qe(l)),1)):vt("",!0)],8,zN)):vt("",!0),w.value?(ge(),Ie("div",{key:1,class:"sd-toolbar-button__caret","data-item":`btn-${Qe(i)||""}-caret`,"aria-label":`${Qe(y).ariaLabel} options`,role:"button"},[Oe("div",{class:"sd-dropdown-caret",innerHTML:ue.value,style:Sn({opacity:Qe(g)?.6:1})},null,12,UN)],8,jN)):(ge(),Ie(Jt,{key:2},[Qe(a)?(ge(),gn(Q4,{key:0,color:Qe(u),class:"sd-toolbar-icon",icon:Qe(a),name:Qe(i)},null,8,["color","icon","name"])):vt("",!0),Qe(l)&&!Qe(c)&&(!Qe(v)||x.value==="fontFamily")?(ge(),Ie("div",{key:1,class:ln(["sd-button-label",{"sd-visually-hidden":Qe(v)&&x.value==="fontFamily"}])},Wt(Qe(l)),3)):vt("",!0),Qe(v)?(ge(),Ie("span",HN,[Qe(i)==="fontSize"?js((ge(),Ie("input",{key:0,"onUpdate:modelValue":re[1]||(re[1]=Re=>L.value=Re),onKeydown:[Yo(sn(Be,["stop","prevent"]),["enter"]),re[2]||(re[2]=Yo(Re=>he(Re),["tab"]))],onClick:re[3]||(re[3]=sn(Re=>Q(Re),["stop"])),onFocus:re[4]||(re[4]=Re=>Q(Re)),type:"text",class:ln(["button-text-input button-text-input--font-size",{"high-contrast":Qe($)}]),id:"inlineTextInput-"+Qe(i),autocomplete:"off",ref_key:"inlineInput",ref:z},null,42,$N)),[[Ci,L.value]]):js((ge(),Ie("input",{key:1,"onUpdate:modelValue":re[5]||(re[5]=Re=>L.value=Re),placeholder:Qe(l),onKeydown:[Yo(sn(Be,["stop","prevent"]),["enter"]),re[6]||(re[6]=Yo(Re=>he(Re),["tab"]))],onClick:re[7]||(re[7]=sn(Re=>Q(Re),["stop"])),onFocus:re[8]||(re[8]=Re=>Q(Re)),type:"text",class:ln(["button-text-input",{"button-text-input--font-family":x.value==="fontFamily","high-contrast":Qe($)}]),id:"inlineTextInput-"+Qe(i),"data-item":x.value==="fontFamily"?`btn-${Qe(i)}-input`:void 0,autocomplete:"off",ref_key:"inlineInput",ref:z},null,42,GN)),[[Ci,L.value]])])):vt("",!0),Qe(d)?(ge(),Ie("div",{key:3,class:"sd-dropdown-caret","data-item":`btn-${Qe(i)||""}-toggle`,innerHTML:ue.value,style:Sn({opacity:Qe(g)?.6:1})},null,12,WN)):vt("",!0)],64)),Oe("div",KN,Wt(`${Qe(y).ariaLabel} ${Qe(s)?"selected":"unset"}`),1)],10,BN)],46,NN))}},e2=vn(qN,[["__scopeId","data-v-dbdea151"]]);Lt(),kn();var YN={class:"toolbar-separator",role:"separator","aria-label":"Toolbar separator"},XN={__name:"ToolbarSeparator",props:{active:{type:Boolean,default:!1}},emits:["command"],setup(e,{emit:t}){const{isHighContrastMode:n}=Ni(),r=()=>n.value?"#000":"var(--sd-ui-border, #dbdbdb)";return(o,i)=>(ge(),Ie("div",YN,[Oe("div",{class:"separator-inner",style:Sn({backgroundColor:r()})},null,4)]))}},ZN=vn(XN,[["__scopeId","data-v-cb82253a"]]);Lt(),kn();var QN={class:"overflow-menu"},JN={class:"overflow-menu-trigger"},eB={key:0,class:"overflow-menu_items",role:"group"},tB={__name:"OverflowMenu",props:{toolbarItem:{type:Object,required:!0},overflowItems:{type:Array,required:!0}},emits:["buttonClick","close"],setup(e,{emit:t}){const{proxy:n}=ur(),r=t,o=e,i=Ae(()=>o.toolbarItem.expand.value),s=ne(!1),a=Ae(()=>({...o.toolbarItem,active:i.value})),l=()=>{r("buttonClick",o.toolbarItem)},c=({item:d,argument:h})=>{n.$toolbar.emitCommand({item:d,argument:h})},u=d=>{d.key==="Escape"&&i.value&&!s.value&&(d.preventDefault(),r("close"))};return zn(()=>{document.addEventListener("keydown",u,!0)}),cr(()=>{document.removeEventListener("keydown",u,!0)}),(d,h)=>(ge(),Ie("div",QN,[Oe("div",JN,[Zt(e2,{"toolbar-item":a.value,onButtonClick:l},null,8,["toolbar-item"])]),i.value?(ge(),Ie("div",eB,[Zt(dm,{class:"superdoc-toolbar-overflow","toolbar-items":e.overflowItems,"from-overflow":"",onCommand:c,onDropdownUpdateShow:h[0]||(h[0]=g=>s.value=g)},null,8,["toolbar-items"])])):vt("",!0)]))}},nB=vn(tB,[["__scopeId","data-v-504ecd05"]]);Lt(),kn();var rB={class:"toolbar-dropdown"},oB=["onClick"],iB={key:0,class:"toolbar-dropdown-option__icon"},sB={class:"toolbar-dropdown-option__label"},lm='button, [href], input, select, textarea, [role="button"], [tabindex]:not([tabindex="-1"])',aB={__name:"ToolbarDropdown",props:{options:{type:Array,default:()=>[]},show:{type:Boolean,required:!0},placement:{type:String,default:"bottom-start"},disabled:{type:Boolean,default:!1},contentStyle:{type:Object,default:()=>({})},menuProps:{type:Function,default:null},nodeProps:{type:Function,default:null}},emits:["update:show","select"],setup(e,{emit:t}){const n=e,r=t,o=ne(null),i=ne(null),s=ne({top:"0px",left:"0px",maxHeight:"none"}),a=ne([]),l=ne(-1),c=Ae(()=>!!n.show),u=Ae(()=>n.options.some(re=>re?.type==="render")),d=Ae(()=>typeof n.menuProps!="function"?{}:n.menuProps()||{}),h=Ae(()=>{const{class:re,style:Re,...Je}=d.value;return Je}),g=Ae(()=>["toolbar-dropdown-menu",d.value.class,{"toolbar-dropdown-menu--render-only":n.options.length>0&&n.options.every(re=>re&&re.type==="render")}]),p=Ae(()=>{const re=d.value.style||{};return{...n.contentStyle,...re}}),v=Ae(()=>({...p.value,position:"fixed",top:s.value.top,left:s.value.left,maxHeight:s.value.maxHeight,zIndex:2e3})),k=re=>{r("update:show",re)},C=()=>{c.value&&k(!1)},_=()=>{if(!o.value)return;const re=o.value.getBoundingClientRect(),Re=i.value,Je=Re?.offsetWidth??0,st=Re?.scrollHeight??Re?.offsetHeight??0,Tt=window.innerWidth||document.documentElement.clientWidth||0,Ee=window.innerHeight||document.documentElement.clientHeight||0,$e=8,qe=4,J=re.bottom+qe,S=re.top-qe,ee=Math.max(0,Ee-J-$e),O=Math.max(0,S-$e),H=ee<st&&O>ee,U=H?O:ee,G=H?Math.max($e,S-(st?Math.min(st,U):U)):J;let te=re.left;n.placement==="bottom-end"&&(te=re.right-Je);const Y=Math.max($e,Tt-Je-$e);te=Math.min(Math.max($e,te),Y),s.value={top:`${G}px`,left:`${te}px`,maxHeight:`${U}px`}},y=()=>{n.disabled||k(!c.value)},w=re=>typeof n.nodeProps!="function"?{}:n.nodeProps(re)||{},x=re=>{re?.disabled||re?.type!=="render"&&(r("select",re?.key,re),C())},L=re=>re?.type==="render",z=re=>!re?.disabled&&re?.type!=="render",$=re=>typeof re?.icon=="function"||!!re?.icon,R=re=>typeof re?.icon=="function"?re.icon(re):re?.icon||null,F=re=>re?typeof re=="string"?re.split(/\s+/).includes("sd-selected"):Array.isArray(re)?re.some(F):typeof re=="object"?!!re["sd-selected"]:!1:!1,X=re=>F(re?.props?.class)||F(re?.class),D=()=>n.options.map((re,Re)=>z(re)?Re:-1).filter(re=>re>=0),V=()=>{const re=n.options.findIndex(Re=>z(Re)&&X(Re));return re>=0?re:D()[0]??-1},T=(re,Re)=>{if(!re){delete a.value[Re];return}a.value[Re]=re},N=()=>{a.value.forEach((Re,Je)=>{Re&&Re.setAttribute("tabindex",Je===l.value?"0":"-1")});const re=a.value[l.value];re&&typeof re.focus=="function"&&(re.focus(),re.scrollIntoView?.({block:"nearest",inline:"nearest"}))},Q=re=>{const Re=D();if(!Re.length){l.value=-1;return}const Je=Re.indexOf(l.value);if(Je<0){l.value=re>0?Re[0]:Re[Re.length-1];return}const st=(Je+re+Re.length)%Re.length;l.value=Re[st]},K=()=>{let re=n.options[l.value];if(!z(re)){const Re=D()[0];re=Re===void 0?null:n.options[Re]}re&&x(re)},se=Il({name:"ToolbarDropdownRenderOption",props:{option:{type:Object,required:!0}},setup(re){return()=>typeof re.option.render!="function"?null:re.option.render()}}),me=Il({name:"ToolbarDropdownOptionIcon",props:{option:{type:Object,required:!0}},setup(re){return()=>R(re.option)}}),Be=re=>{if(!c.value)return;const Re=re.target;if(!(Re instanceof Element))return;const Je=o.value?.contains(Re),st=i.value?.contains(Re);Je||st||C()},he=ne(null),ve=()=>{const re=o.value,Re=document.activeElement;if(re&&Re instanceof HTMLElement&&re.contains(Re)){he.value=Re;return}he.value=re?.matches?.(lm)?re:re?.querySelector(lm)},ue=()=>{const re=he.value;if(re instanceof HTMLElement&&document.contains(re)){re.focus();return}const Re=o.value;if(!Re)return;const Je=Re.matches?.(lm)?Re:Re.querySelector(lm);if(Je instanceof HTMLElement){Je.focus();return}Re.setAttribute("tabindex","-1"),Re.focus()},ke=re=>{if(!c.value)return;const{key:Re}=re;if(["Escape","ArrowDown","ArrowUp","Enter"].includes(Re)){if(Re==="Escape"){re.preventDefault(),C(),It(()=>{requestAnimationFrame(ue)});return}if(!u.value){if(re.preventDefault(),Re==="ArrowDown"){Q(1),N();return}if(Re==="ArrowUp"){Q(-1),N();return}Re==="Enter"&&K()}}};return Vt(c,async re=>{if(!re){l.value=-1,a.value=[];return}ve(),await It(),_(),!u.value&&(l.value=V(),await It(),N())},{immediate:!0}),Vt(c,re=>{re?(document.addEventListener("pointerdown",Be,!0),document.addEventListener("keydown",ke,!0),window.addEventListener("resize",_),window.addEventListener("scroll",_,!0)):(document.removeEventListener("pointerdown",Be,!0),document.removeEventListener("keydown",ke,!0),window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0))},{immediate:!0}),cr(()=>{document.removeEventListener("pointerdown",Be,!0),document.removeEventListener("keydown",ke,!0),window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0)}),(re,Re)=>(ge(),Ie("div",rB,[Oe("div",{ref_key:"triggerRef",ref:o,class:"toolbar-dropdown-trigger","data-sd-part":"dropdown-trigger",onClick:y},[Ed(re.$slots,"trigger",{},void 0,!0)],512),(ge(),gn(Fa,{to:"body"},[Zt(Xh,{name:"fade-in-scale-up-transition"},{default:To(()=>[c.value?(ge(),Ie("div",ss({key:0,ref_key:"menuRef",ref:i,"data-sd-part":"dropdown-menu",class:g.value,style:v.value},h.value),[(ge(!0),Ie(Jt,null,lr(e.options,(Je,st)=>(ge(),Ie("div",ss({key:Je.key,ref_for:!0,ref:Tt=>T(Tt,st),class:["toolbar-dropdown-option",[Je.class,Je.props?.class,{"sd-disabled":Je.disabled,"sd-render":L(Je)}]],tabindex:"-1",onClick:Tt=>x(Je)},{ref_for:!0},{...Je.props,...w(Je)}),[L(Je)?(ge(),gn(Qe(se),{key:0,option:Je},null,8,["option"])):(ge(),Ie(Jt,{key:1},[$(Je)?(ge(),Ie("span",iB,[Zt(Qe(me),{option:Je},null,8,["option"])])):vt("",!0),Oe("span",sB,Wt(Je.label),1)],64))],16,oB))),128))],16)):vt("",!0)]),_:1})]))]))}},lB=vn(aB,[["__scopeId","data-v-fef410f7"]]),J4=e=>String(e??"").trim().toLowerCase(),cm=(e,t)=>{const n=J4(e);if(!n)return-1;for(let r=0;r<t.length;r+=1)if(J4(t[r]).startsWith(n))return r;return-1},cB=(e,t,{autocomplete:n=!0}={})=>{const r=String(e??""),o=cm(r,t),i=o>=0?String(t[o]??""):"";return n&&o>=0&&i.length>r.length?{matchIndex:o,display:i,selectionStart:r.length,selectionEnd:i.length}:{matchIndex:o,display:r,selectionStart:r.length,selectionEnd:r.length}},uB=e=>{let t=String(e??"").trim();for(;t.length>=2&&(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"));)t=t.slice(1,-1).trim();return t},dB=e=>e<=31||e===127,fB=e=>e===32||e===160||e===65279,hB=e=>Array.from(String(e)).filter(t=>!dB(t.charCodeAt(0))).join(""),pB=e=>{let t="",n=!1;for(const r of String(e)){if(fB(r.charCodeAt(0))){n=t.length>0;continue}n&&(t+=" "),n=!1,t+=r}return t},mB=e=>{const t=String(e??"").split(",")[0]??"",n=hB(t);return pB(uB(n)).trim()},gB=1,vB=1638,yB=e=>{const t=String(e??"").replace(/[^0-9.-]/g,""),n=Number.parseFloat(t);if(!Number.isFinite(n))return"";const r=Math.round(n*2)/2;return r<gB?"":String(Math.min(r,vB))};Lt(),kn();var bB=["data-item"],wB=["id","value","disabled","aria-label","aria-expanded","aria-controls","aria-activedescendant","data-item"],CB=["data-item","aria-label","disabled"],kB=["innerHTML"],SB=["id","aria-label"],_B=["id","aria-selected","aria-label","onMousedown","onMouseenter"],AB={class:"toolbar-dropdown-option__label"},IB={class:"sd-button-label sd-font-combobox__legacy-label","aria-hidden":"true"},EB={__name:"ToolbarComboBox",props:{item:{type:Object,required:!0},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"},showPreview:{type:Boolean,default:!1},normalizeValue:{type:Function,default:e=>String(e??"").trim()}},emits:["command","item-clicked","tab-out","editor-handoff"],setup(e,{emit:t}){const n=e,r=t,{isHighContrastMode:o}=Ni(),i=ne(null),s=ne(null),a=ne(null),l=ne([]),c=ne(!1),u=ne(!1),d=ne(-1),h=ne(""),g=ne(""),p=ne(!1),v=ne({top:"0px",left:"0px",minWidth:"0px",maxHeight:"none"}),k=Ae(()=>n.item.nestedOptions?.value??[]),C=Ae(()=>k.value.map(Y=>String(Y?.label??""))),_=Ae(()=>String(n.item.label?.value??"")),y=Ae(()=>!!n.item.disabled?.value),w=Ae(()=>String(n.item.name?.value??"")),x=Ae(()=>n.item.attributes?.value?.ariaLabel??"Font family"),L=Ae(()=>c.value?g.value:_.value),z=Ae(()=>`sd-${w.value||"combobox"}-listbox-${n.item.id?.value??"default"}`),$=Y=>`${z.value}-option-${Y}`,R=Ae(()=>u.value&&d.value>=0?$(d.value):void 0),F=Ae(()=>u.value?rr.dropdownCaretUp:rr.dropdownCaretDown),X=Y=>{const q=String(Y??"").trim().toLowerCase();return k.value.find(be=>String(be?.label??"").trim().toLowerCase()===q)?.props?.style?.fontFamily||Y||n.uiFontFamily},D=Ae(()=>n.showPreview?{fontFamily:X(c.value?g.value:_.value)}:{fontFamily:n.uiFontFamily}),V=()=>{const Y=n.item.selectedValue?.value;if(Y){const q=k.value.findIndex(be=>be?.key===Y);if(q>=0)return q}return C.value.findIndex(q=>q.toLowerCase()===_.value.toLowerCase())},T=(Y,q)=>{const be=i.value;if(!(!be||typeof be.setSelectionRange!="function"))try{be.setSelectionRange(Y,q)}catch{}},N=()=>{l.value[d.value]?.scrollIntoView?.({block:"nearest",inline:"nearest"})},Q=()=>{l.value[d.value]?.focus?.()},K=()=>{const Y=s.value;if(!Y)return;const q=Y.getBoundingClientRect(),be=a.value,ye=be?.scrollHeight??be?.offsetHeight??0,we=window.innerHeight||document.documentElement.clientHeight||0,ze=window.innerWidth||document.documentElement.clientWidth||0,rt=8,it=4,Ct=q.bottom+it,en=q.top-it,Rt=Math.max(0,we-Ct-rt),zt=Math.max(0,en-rt),$t=Rt<ye&&zt>Rt,_n=$t?zt:Rt,bt=$t?Math.max(rt,en-(ye?Math.min(ye,_n):_n)):Ct,tn=Math.min(Math.max(rt,q.left),Math.max(rt,ze-q.width-rt));v.value={top:`${bt}px`,left:`${tn}px`,minWidth:`${q.width}px`,maxHeight:`${_n}px`}},se=Ae(()=>({position:"fixed",top:v.value.top,left:v.value.left,minWidth:v.value.minWidth,maxHeight:v.value.maxHeight,fontFamily:n.uiFontFamily,zIndex:2e3})),me=Y=>{n.item.expand&&typeof n.item.expand=="object"&&"value"in n.item.expand&&(n.item.expand.value=Y)},Be=(Y,{focusInput:q=!1,focusOption:be=!1}={})=>{if(y.value||!k.value.length){me(!1);return}u.value=!0,me(!0),d.value=Y??-1,q&&(c.value=!0,g.value=_.value,i.value?.focus()),It(()=>{K(),N(),be&&Q()})},he=({syncItem:Y=!0}={})=>{u.value=!1,d.value=-1,Y&&me(!1)},ve=()=>{he(),c.value=!1,h.value="",g.value=_.value},ue=()=>{y.value||(u.value||r("item-clicked"),c.value=!0,h.value="",g.value=_.value,It(()=>T(0,g.value.length)))},ke=Y=>{if(y.value)return;const q=document.activeElement===i.value;if(r("item-clicked"),c.value=!0,q||(h.value="",g.value=_.value,Y.preventDefault(),i.value?.focus({preventScroll:!0}),T(0,_.value.length)),!u.value){const be=V();Be(be>=0?be:0)}},re=Y=>{const q=Y.relatedTarget;q instanceof Node&&s.value?.contains(q)||q instanceof Node&&a.value?.contains(q)||ve()},Re=Y=>{if(p.value)return;const q=Y.target,be=q.value,ye=typeof q.selectionStart=="number"?q.selectionStart:be.length,we=typeof q.selectionEnd=="number"?q.selectionEnd:ye,ze=typeof Y.inputType=="string"&&Y.inputType.startsWith("delete"),rt=ye===be.length&&we===be.length;h.value=be;const it=cB(be,C.value,{autocomplete:!ze&&rt});g.value=it.display,q.value=it.display,it.display===be&&!rt?T(ye,we):T(it.selectionStart,it.selectionEnd),u.value&&(d.value=it.matchIndex,It(N))},Je=Y=>{p.value=!1,Re(Y)},st=Y=>{if(!k.value.length)return;const q=k.value.length,be=d.value<0?Y>0?-1:0:d.value;d.value=(be+Y+q)%q,It(N)},Tt=(Y,q)=>{r("item-clicked"),r("command",{item:n.item,argument:Y,option:q}),q&&(n.item.selectedValue.value=q.key)},Ee=Y=>{Y&&(Tt(Y.label,Y),c.value=!1,h.value="",g.value=Y.label,he())},$e=()=>{if(u.value&&d.value>=0)return Ee(k.value[d.value]),!0;const Y=cm(h.value,C.value);if(Y>=0)return Ee(k.value[Y]),!0;const q=n.normalizeValue(h.value);return q?(Tt(q,null),c.value=!1,h.value="",g.value=q,he(),!0):!1},qe=Y=>{if(!(Y.isComposing||p.value||Y.keyCode===229)&&!(Y.ctrlKey||Y.metaKey||Y.altKey))switch(Y.key){case"ArrowDown":if(Y.preventDefault(),u.value)Q();else{const q=cm(h.value,C.value),be=q>=0?q:V();Be(be>=0?be:0,{focusOption:!0})}break;case"ArrowUp":if(Y.preventDefault(),u.value)Q();else{const q=cm(h.value,C.value),be=q>=0?q:V();Be(be>=0?be:k.value.length-1,{focusOption:!0})}break;case"Enter":Y.preventDefault(),$e()&&r("editor-handoff"),i.value?.blur();break;case"Tab":Y.preventDefault(),$e(),he(),i.value?.blur(),r("tab-out",Y);break;case"Escape":Y.preventDefault(),ve(),It(()=>i.value?.focus());break;default:break}},J=Y=>{if(Y.preventDefault(),!y.value)if(r("item-clicked"),u.value)he(),i.value?.focus();else{const q=V();Be(q>=0?q:0,{focusOption:!0})}},S=(Y,q)=>{Y.preventDefault(),Ee(q),r("editor-handoff"),i.value?.blur()},ee=Y=>{d.value=Y},O=Y=>{if(!(Y.ctrlKey||Y.metaKey||Y.altKey))switch(Y.key){case"ArrowDown":Y.preventDefault(),st(1),Q();break;case"ArrowUp":Y.preventDefault(),st(-1),Q();break;case"Enter":Y.preventDefault(),d.value>=0&&(Ee(k.value[d.value]),r("editor-handoff"));break;case"Escape":Y.preventDefault(),ve(),It(()=>i.value?.focus());break;case"Tab":Y.preventDefault(),d.value>=0?Ee(k.value[d.value]):he(),r("tab-out",{shiftKey:Y.shiftKey,target:i.value});break;default:break}},H=Y=>{if(!u.value)return;const q=Y.target;q instanceof Element&&(s.value?.contains(q)||a.value?.contains(q)||ve())};Vt(u,Y=>{Y?(document.addEventListener("pointerdown",H,!0),window.addEventListener("resize",K),window.addEventListener("scroll",K,!0)):(document.removeEventListener("pointerdown",H,!0),window.removeEventListener("resize",K),window.removeEventListener("scroll",K,!0),l.value=[])},{immediate:!0}),cr(()=>{document.removeEventListener("pointerdown",H,!0),window.removeEventListener("resize",K),window.removeEventListener("scroll",K,!0)});const U=(Y,q)=>{if(!Y){delete l.value[q];return}l.value[q]=Y},G=Y=>Y===d.value,te=Y=>Y?.key&&Y.key===n.item.selectedValue?.value;return Vt(_,Y=>{c.value||(g.value=Y)}),Vt(()=>!!n.item.expand?.value,Y=>{if(Y&&!u.value){const q=V();Be(q>=0?q:0,{focusInput:!0});return}!Y&&u.value&&he({syncItem:!1})}),(Y,q)=>(ge(),Ie("div",{ref_key:"rootRef",ref:s,class:ln(["sd-font-combobox sd-toolbar-split-field",{"sd-disabled":y.value,"high-contrast":Qe(o)}]),style:Sn(n.item.style?.value),"data-item":`btn-${w.value}`},[Oe("span",{class:"sd-font-combobox__field sd-toolbar-split-field__main",onMousedown:ke},[Oe("input",{ref_key:"inputRef",ref:i,id:`inlineTextInput-${w.value}`,class:"button-text-input sd-font-combobox__input",type:"text",role:"combobox",autocomplete:"off",spellcheck:"false",value:L.value,style:Sn(D.value),disabled:y.value,"aria-label":x.value,"aria-expanded":u.value?"true":"false","aria-controls":z.value,"aria-activedescendant":R.value,"aria-haspopup":"listbox","aria-autocomplete":"both","data-item":`btn-${w.value}-input`,onFocus:ue,onBlur:re,onInput:Re,onKeydown:qe,onCompositionstart:q[0]||(q[0]=be=>p.value=!0),onCompositionend:Je},null,44,wB)],32),Oe("button",{type:"button",class:"sd-font-combobox__caret sd-toolbar-split-field__caret","data-item":`btn-${w.value}-toggle`,tabindex:"-1","aria-label":`${x.value} options`,disabled:y.value,onMousedown:J},[Oe("span",{class:"sd-dropdown-caret",innerHTML:F.value},null,8,kB)],40,CB),(ge(),gn(Fa,{to:"body"},[u.value?(ge(),Ie("div",{key:0,ref_key:"popupRef",ref:a,role:"listbox",id:z.value,"aria-label":x.value,class:ln(["sd-font-combobox__listbox",{"high-contrast":Qe(o)}]),style:Sn(se.value)},[(ge(!0),Ie(Jt,null,lr(k.value,(be,ye)=>(ge(),Ie("div",ss({key:be.key,ref_for:!0,ref:we=>U(we,ye),id:$(ye),role:"option",tabindex:"-1",class:["toolbar-dropdown-option sd-font-combobox__option",{"sd-active":G(ye),"sd-selected":te(be)}],"aria-selected":te(be)?"true":"false","aria-label":`${x.value} - ${be.label}`},{ref_for:!0},be.props,{onMousedown:we=>S(we,be),onMouseenter:we=>ee(ye),onKeydown:O}),[Oe("span",AB,Wt(be.label),1)],16,_B))),128))],14,SB)):vt("",!0)])),Oe("span",IB,Wt(_.value),1)],14,bB))}},eA=vn(EB,[["__scopeId","data-v-99070b63"]]);Lt();var TB={__name:"FontFamilyCombobox",props:{item:{type:Object,required:!0},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"}},emits:["command","item-clicked","tab-out","editor-handoff"],setup(e,{emit:t}){const n=e,r=t;return(o,i)=>(ge(),gn(eA,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!0,"normalize-value":Qe(mB),onCommand:i[0]||(i[0]=s=>r("command",s)),onItemClicked:i[1]||(i[1]=s=>r("item-clicked")),onTabOut:i[2]||(i[2]=s=>r("tab-out",s)),onEditorHandoff:i[3]||(i[3]=s=>r("editor-handoff"))},null,8,["item","ui-font-family","normalize-value"]))}};Lt();var xB={__name:"FontSizeCombobox",props:{item:{type:Object,required:!0},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"}},emits:["command","item-clicked","tab-out","editor-handoff"],setup(e,{emit:t}){const n=e,r=t;return(o,i)=>(ge(),gn(eA,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!1,"normalize-value":Qe(yB),onCommand:i[0]||(i[0]=s=>r("command",s)),onItemClicked:i[1]||(i[1]=s=>r("item-clicked")),onTabOut:i[2]||(i[2]=s=>r("tab-out",s)),onEditorHandoff:i[3]||(i[3]=s=>r("editor-handoff"))},null,8,["item","ui-font-family","normalize-value"]))}};Lt(),kn();var RB=2500,MB=Object.assign({inheritAttrs:!1},{__name:"SdTooltip",props:{trigger:{type:String,default:"hover"},delay:{type:Number,default:100},duration:{type:Number,default:100},disabled:{type:Boolean,default:!1},contentStyle:{type:Object,default:()=>({})}},setup(e){const t=e,n=Q1(),r=ne(!1),o=ne(null),i=ne(null),s=ne({top:"0px",left:"0px"});let a=null,l=null,c=null;const u=Ae(()=>["sd-tooltip-content",n.class]),d=Ae(()=>({...t.contentStyle,...n.style||{},position:"fixed",top:s.value.top,left:s.value.left,zIndex:2100})),h=()=>{a&&(window.clearTimeout(a),a=null)},g=()=>{l&&(window.clearTimeout(l),l=null)},p=()=>{c&&(window.clearTimeout(c),c=null)},v=()=>{p(),c=window.setTimeout(()=>{c=null,_()},RB)},k=()=>{if(!o.value||!i.value)return;const F=o.value.getBoundingClientRect(),X=i.value.offsetWidth,D=i.value.offsetHeight,V=window.innerWidth||document.documentElement.clientWidth||0,T=8;let N=F.left+F.width/2-X/2;N=Math.max(T,Math.min(N,V-X-T)),s.value={top:`${F.top-D-10}px`,left:`${N}px`}},C=async()=>{t.disabled||(h(),g(),!r.value&&(r.value=!0,v(),await It(),k()))},_=()=>{g(),h(),p(),r.value&&(r.value=!1)},y=()=>{if(h(),g(),!r.value){if(t.delay===0){C();return}l=window.setTimeout(()=>{l=null,C()},t.delay)}},w=()=>{if(g(),h(),!!r.value){if(t.duration===0){_();return}a=window.setTimeout(()=>{a=null,_()},t.duration)}},x=()=>{t.trigger==="hover"&&y()},L=()=>{t.trigger==="hover"&&w()},z=()=>{g(),h()},$=()=>{w()},R=F=>{F.key==="Escape"&&_()};return Vt(()=>t.disabled,F=>{F&&_()}),Vt(r,F=>{F?(window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),document.addEventListener("keydown",R,!0)):(window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("keydown",R,!0))}),cr(()=>{g(),h(),p(),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("keydown",R,!0)}),(F,X)=>(ge(),Ie(Jt,null,[Oe("span",{ref_key:"triggerRef",ref:o,class:"sd-tooltip-trigger",onMouseenter:x,onMouseleave:L,onFocusin:x,onFocusout:L},[Ed(F.$slots,"trigger",{},void 0,!0)],544),(ge(),gn(Fa,{to:"body"},[Zt(Xh,{name:"fade-in-scale-up-transition"},{default:To(()=>[r.value&&!e.disabled?(ge(),Ie("div",{key:0,ref_key:"contentRef",ref:i,class:ln(u.value),style:Sn(d.value),onMouseenter:z,onMouseleave:$},[X[0]||(X[0]=Oe("span",{class:"sd-tooltip-arrow","aria-hidden":"true"},null,-1)),Ed(F.$slots,"default",{},void 0,!0)],38)):vt("",!0)]),_:3})]))],64))}}),um=vn(MB,[["__scopeId","data-v-2a872eae"]]),vu=(e,t=null)=>{if(typeof t?.focus=="function"){t.focus();return}const n=e?.superdoc?.focus??e?.activeEditor?.focus;if(typeof n=="function"){n.call(e?.superdoc??e?.activeEditor,{preventScroll:!0});return}const r=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');r instanceof HTMLElement&&r.focus({preventScroll:!0})};Lt(),kn();var LB=["onKeydown","tabindex","data-item-id"],PB={key:0},DB={key:0},OB={key:0},FB={key:0},NB={key:0},BB={__name:"ButtonGroup",props:{toolbarItems:{type:Array,required:!0},overflowItems:{type:Array,default:()=>[]},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"},position:{type:String,default:"left"},fromOverflow:{type:Boolean,default:!1},compactSideGroups:{type:Boolean,default:!1}},emits:["command","item-clicked","dropdown-update-show"],setup(e,{emit:t}){const n=t,{proxy:r}=ur(),o=ne([]),i=ne(null),s=e,a=ne(null),{isHighContrastMode:l}=Ni(),c=window.matchMedia("(max-width: 768px)").matches,u=Ae(()=>s.position==="left"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-start"}:s.position==="right"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-end"}:{flexGrow:c?0:1,justifyContent:"center"}),d=Ee=>Ee.type==="button",h=Ee=>Ee.type==="dropdown",g=Ee=>Ee.type==="dropdown"&&Ee.name?.value==="fontFamily",p=Ee=>Ee.type==="dropdown"&&Ee.name?.value==="fontSize",v=Ee=>Ee.type==="separator",k=Ee=>Ee.type==="overflow",C=Ee=>!!Ee.nestedOptions?.value?.length,_=Ee=>{if(!Ee)return!1;const $e=Ee.expand;return typeof $e=="object"&&$e!==null&&"value"in $e?!!$e.value:!!$e},y=(Ee,$e)=>{Ee?.expand&&(Ee.expand.value=$e)},w=(Ee,$e=void 0)=>{if(Ee.disabled.value)return;if(k(Ee)){const J=!_(Ee);J&&z(),y(Ee,J),a.value=J?Ee:null,n("item-clicked");return}if(h(Ee))return;a.value&&h(a.value)&&_(a.value)&&z(),n("item-clicked");const qe=$e!==void 0?$e:Ee.argument?.value;n("command",qe===void 0?{item:Ee}:{item:Ee,argument:qe})},x=(Ee,$e)=>{Ee.disabled.value||(a.value=null,n("command",{item:Ee,argument:$e}))},L=Ee=>{if(Ee.disabled.value)return;z();const $e=Ee.splitButtonCommand,qe=Ee.command,J=$e||qe;if(!J)return;const S={...Ee,command:J};n("item-clicked"),n("command",{item:S})},z=()=>{const Ee=r?.$toolbar?.toolbarItems||[],$e=r?.$toolbar?.overflowItems||[],qe=[...Ee,...$e];(qe.length?qe:s.toolbarItems).forEach(J=>{const S=k(J)&&!s.fromOverflow;(h(J)||S)&&y(J,!1)}),a.value=null},$=(Ee,$e)=>{z();const qe=Ee.dropdownValueKey.value?$e[Ee.dropdownValueKey.value]:$e.label;n("command",{item:Ee,argument:qe,option:$e}),Ee.selectedValue.value=$e.key,Ee.restoreEditorFocus&&vu(r?.$toolbar)},R=Ee=>{n("command",Ee)},F=()=>{z(),n("item-clicked")},X=()=>{const Ee=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return Ee instanceof HTMLElement?(Ee.focus({preventScroll:!0}),!0):!1},D=()=>{const Ee=r?.$toolbar?.pendingSelectionCapture,$e=()=>{Ee&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(Ee)};if(X()){$e();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),$e())},V=Ee=>!(Ee instanceof HTMLElement)||Ee.classList.contains("sd-disabled")?null:Ee.querySelector("input:not([disabled]), textarea:not([disabled]), select:not([disabled])")||Ee.querySelector('button:not([disabled]), [role="button"]:not(.sd-disabled), [tabindex]:not([tabindex="-1"])'),T=(Ee,$e)=>{const qe=Ee?.target?.closest?.(".sd-toolbar-item-ctn");if(!(qe instanceof HTMLElement))return!1;let J=$e>0?qe.nextElementSibling:qe.previousElementSibling;for(;J;){const S=V(J);if(S instanceof HTMLElement)return qe.setAttribute("tabindex","-1"),J.setAttribute("tabindex","0"),S.focus(),!0;J=$e>0?J.nextElementSibling:J.previousElementSibling}return!1},N=Ee=>{z();const $e=Ee?.shiftKey?-1:1;T(Ee,$e)||D()},Q=Ee=>{if(z(),Ee?.shiftKey){T(Ee,-1)||D();return}D()},K=()=>{D()},se=Ee=>Ee.nestedOptions?.value?.length?Ee.nestedOptions.value.map($e=>{const qe=$e?.type!=="render"&&Ee.selectedValue.value===$e.key;return{...$e,props:{...$e.props,class:qe?"sd-selected":""}}}):[],me=(Ee,$e)=>({role:"menuitem",ariaLabel:`${$e.attributes.value.ariaLabel} - ${Ee.label}`}),Be=Ee=>{const $e=Ee.target,qe=Ee.target.closest(".sd-toolbar-item-ctn").nextElementSibling;qe&&($e.setAttribute("tabindex","-1"),qe.setAttribute("tabindex","0"),qe.focus())},he=Ee=>{const $e=Ee.target,qe=Ee.target.closest(".sd-toolbar-item-ctn").previousElementSibling;qe&&($e.setAttribute("tabindex","-1"),qe.setAttribute("tabindex","0"),qe.focus())},ve=Ee=>{const $e=Ee.target.closest(".button-group").nextElementSibling;if($e)$e.setAttribute("tabindex","0"),$e.focus();else{const qe=document.querySelector(".ProseMirror");qe&&qe.focus()}},ue=Ee=>{const $e=Ee.target.closest(".button-group").previousElementSibling;$e&&($e.setAttribute("tabindex","0"),$e.focus())},ke=Ee=>{if(!Ee.disabled.value){if(h(Ee)){Je(!_(Ee),Ee);return}w(Ee)}},re=(Ee,$e)=>{const qe=Ee.target.nodeName==="INPUT"||Ee.target.nodeName==="TEXTAREA",J=$e.name.value==="fontSize"||$e.name.value==="fontFamily";if(!(qe&&J)&&["Enter"," ","Spacebar","Escape","ArrowRight","ArrowLeft","Tab"].includes(Ee.key))switch(Ee.preventDefault(),Ee.key){case"Enter":case" ":case"Spacebar":ke($e);break;case"Escape":z();break;case"ArrowRight":z(),Be(Ee);break;case"ArrowLeft":z(),he(Ee);break;case"Tab":Ee.shiftKey?ue(Ee):ve(Ee);break;default:break}},Re=Ee=>{const $e=o.value.find(qe=>!qe.classList.contains("sd-disabled"));$e&&($e.setAttribute("tabindex","0"),$e.focus())},Je=(Ee,$e)=>{if(n("item-clicked"),!Ee){z(),n("dropdown-update-show",!1);return}z(),a.value=$e,y($e,!0),n("dropdown-update-show",!0)},st=Ee=>{if(!a.value)return;const $e=Ee.target;$e instanceof Element&&($e.closest(".sd-toolbar-dropdown-menu")||i.value?.contains($e)||z())};return Vt(()=>_(a.value),Ee=>{Ee?document.addEventListener("pointerdown",st,!0):document.removeEventListener("pointerdown",st,!0)},{immediate:!0}),cr(()=>{document.removeEventListener("pointerdown",st,!0)}),(Ee,$e)=>(ge(),Ie("div",{style:Sn(u.value),class:"button-group",role:"group",onFocus:Re,ref_key:"buttonGroupRef",ref:i},[(ge(!0),Ie(Jt,null,lr(e.toolbarItems,(qe,J)=>(ge(),Ie("div",{key:qe.id.value,class:ln([{narrow:qe.isNarrow.value,wide:qe.isWide.value,"sd-disabled":qe.disabled.value},"sd-toolbar-item-ctn"]),onKeydown:S=>re(S,qe),ref_for:!0,ref_key:"toolbarItemRefs",ref:o,tabindex:J===0?0:-1,"data-item-id":qe.id.value},[v(qe)?(ge(),gn(ZN,{key:0,style:{width:"20px"}})):vt("",!0),g(qe)&&C(qe)?(ge(),gn(um,{key:1,trigger:"hover",disabled:!qe.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:To(()=>[Zt(TB,{item:qe,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:R,onItemClicked:F,onTabOut:$e[0]||($e[0]=S=>N(S)),onEditorHandoff:K},null,8,["item","ui-font-family"])]),default:To(()=>[Oe("div",null,[Pi(Wt(qe.tooltip)+" ",1),qe.disabled.value?(ge(),Ie("span",PB,"(disabled)")):vt("",!0)])]),_:2},1032,["disabled","content-style"])):p(qe)&&C(qe)?(ge(),gn(um,{key:2,trigger:"hover",disabled:!qe.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:To(()=>[Zt(xB,{item:qe,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:R,onItemClicked:F,onTabOut:$e[1]||($e[1]=S=>Q(S)),onEditorHandoff:K},null,8,["item","ui-font-family"])]),default:To(()=>[Oe("div",null,[Pi(Wt(qe.tooltip)+" ",1),qe.disabled.value?(ge(),Ie("span",DB,"(disabled)")):vt("",!0)])]),_:2},1032,["disabled","content-style"])):h(qe)&&qe.nestedOptions?.value?.length?(ge(),gn(lB,{key:3,options:se(qe),disabled:qe.disabled.value,show:_(qe),"content-style":{fontFamily:s.uiFontFamily},placement:"bottom-start",class:"sd-toolbar-button sd-editor-toolbar-dropdown",onSelect:(S,ee)=>$(qe,ee),"onUpdate:show":S=>Je(S,qe),style:Sn(qe.dropdownStyles.value),"menu-props":()=>({role:"menu",style:{fontFamily:s.uiFontFamily},class:["sd-toolbar-dropdown-menu",{"high-contrast":Qe(l)}]}),"node-props":S=>me(S,qe)},{trigger:To(()=>[Zt(um,{trigger:"hover",disabled:!qe.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:To(()=>[Zt(e2,{"toolbar-item":qe,disabled:qe.disabled.value,"allow-enter-propagation":!0,onTextSubmit:S=>x(qe,S),onMainClick:S=>L(qe)},null,8,["toolbar-item","disabled","onTextSubmit","onMainClick"])]),default:To(()=>[Oe("div",null,[Pi(Wt(qe.tooltip)+" ",1),qe.disabled.value?(ge(),Ie("span",OB,"(disabled)")):vt("",!0)])]),_:2},1032,["disabled","content-style"])]),_:2},1032,["options","disabled","show","content-style","onSelect","onUpdate:show","style","menu-props","node-props"])):d(qe)?(ge(),gn(um,{key:4,trigger:"hover",class:"sd-editor-toolbar-tooltip","content-style":{fontFamily:s.uiFontFamily}},{trigger:To(()=>[Zt(e2,{"toolbar-item":qe,"is-overflow-item":e.fromOverflow,onTextSubmit:S=>x(qe,S),onButtonClick:S=>w(qe)},null,8,["toolbar-item","is-overflow-item","onTextSubmit","onButtonClick"])]),default:To(()=>[qe.tooltip?(ge(),Ie("div",FB,[Pi(Wt(qe.tooltip)+" ",1),qe.disabled.value?(ge(),Ie("span",NB,"(disabled)")):vt("",!0)])):vt("",!0)]),_:2},1032,["content-style"])):vt("",!0),k(qe)&&e.overflowItems.length?(ge(),gn(nB,{key:5,"toolbar-item":qe,onButtonClick:S=>w(qe),"overflow-items":e.overflowItems,onClose:z},null,8,["toolbar-item","onButtonClick","overflow-items"])):vt("",!0)],42,LB))),128))],36))}},dm=vn(BB,[["__scopeId","data-v-2bc00f65"]]),zB=[["Arial","sans-serif"],["Arial Black","sans-serif"],["Arial Narrow","sans-serif"],["Baskerville Old Face","serif"],["Bookman Old Style","serif"],["Brush Script MT","cursive"],["Calibri","sans-serif"],["Century","serif"],["Century Gothic","sans-serif"],["Comic Sans MS","sans-serif"],["Cooper Black","serif"],["Courier New","monospace"],["Garamond","serif"],["Georgia","serif"],["Gill Sans MT Condensed","sans-serif"],["Helvetica","sans-serif"],["Lucida Console","monospace"],["Segoe UI","sans-serif"],["Tahoma","sans-serif"],["Times New Roman","serif"],["Trebuchet MS","sans-serif"],["Verdana","sans-serif"]],VB=zB.map(([e,t])=>({label:e,key:e,props:{style:{fontFamily:`${e}, ${t}`},"data-item":"btn-fontFamily-option"}}));function jB(e){if(e?.length)return e.map(t=>({label:t.label,key:t.value,props:{style:{fontFamily:t.previewFamily||t.label},"data-item":"btn-fontFamily-option"}}))}var UB=[{label:"8",key:"8pt",props:{"data-item":"btn-fontSize-option"}},{label:"9",key:"9pt",props:{"data-item":"btn-fontSize-option"}},{label:"10",key:"10pt",props:{"data-item":"btn-fontSize-option"}},{label:"11",key:"11pt",props:{"data-item":"btn-fontSize-option"}},{label:"12",key:"12pt",props:{"data-item":"btn-fontSize-option"}},{label:"14",key:"14pt",props:{"data-item":"btn-fontSize-option"}},{label:"18",key:"18pt",props:{"data-item":"btn-fontSize-option"}},{label:"24",key:"24pt",props:{"data-item":"btn-fontSize-option"}},{label:"30",key:"30pt",props:{"data-item":"btn-fontSize-option"}},{label:"36",key:"36pt",props:{"data-item":"btn-fontSize-option"}},{label:"48",key:"48pt",props:{"data-item":"btn-fontSize-option"}},{label:"60",key:"60pt",props:{"data-item":"btn-fontSize-option"}},{label:"72",key:"72pt",props:{"data-item":"btn-fontSize-option"}},{label:"96",key:"96pt",props:{"data-item":"btn-fontSize-option"}}],Ff={sm:768,md:1024,lg:1280,xl:1410},t2={undo:"undo",redo:"redo",bold:"bold",italic:"italic",underline:"underline",strike:"strikethrough",acceptTrackedChangeBySelection:"track-changes-accept-selection",rejectTrackedChangeOnSelection:"track-changes-reject-selection",ruler:"ruler",formattingMarks:"formatting-marks",zoom:"zoom",measurementUnit:"measurement-unit",documentMode:"document-mode",link:"link",fontFamily:"font-family",fontSize:"font-size",list:"bullet-list",numberedlist:"numbered-list",table:"table-insert",image:"image",tableOfContents:"table-of-contents-insert",color:"text-color",highlight:"highlight-color",textAlign:"text-align",lineHeight:"line-height",linkedStyles:"linked-style",indentleft:"indent-decrease",indentright:"indent-increase",directionLtr:"direction-ltr",directionRtl:"direction-rtl",clearFormatting:"clear-formatting",copyFormat:"copy-format"},tA={addRowBefore:"table-add-row-before",addRowAfter:"table-add-row-after",deleteRow:"table-delete-row",addColumnBefore:"table-add-column-before",addColumnAfter:"table-add-column-after",deleteColumn:"table-delete-column",deleteTable:"table-delete",deleteCellAndTableBorders:"table-remove-borders",mergeCells:"table-merge-cells",splitCell:"table-split-cell",fixTables:"table-fix"},nA=Object.values(tA),$H=[...new Set([...Object.values(t2),...nA])],HB=new Set(["link"]),GH=new Set(Object.keys(t2).filter(e=>!HB.has(e)));Lt(),kn();var $B="Arial, Helvetica, sans-serif",GB={__name:"Toolbar",emits:["command","toggle","select"],setup(e,{emit:t}){const{proxy:n}=ur();let r=ne(1);const o=ne(0),i=ne(!1);let s=null,a=null;const l=Ae(()=>{const $=n?.$toolbar?.config?.uiDisplayFallbackFont;return typeof $=="string"&&$.trim()?$.trim():$B}),c=n.$toolbar.config?.toolbarGroups?.includes("left"),u=n.$toolbar.config?.toolbarGroups?.includes("right"),d=n.$toolbar.config?.toolbarButtonsExclude||[],h=$=>(o.value,n.$toolbar.getToolbarItemByGroup($).filter(R=>!d.includes(R.name.value))),g=()=>{i.value=n.$toolbar.getAvailableWidth()<=Ff.lg},v=PN(async()=>{await n.$toolbar.onToolbarResize(),g(),r.value+=1},300),k=()=>{r.value+=1},C=()=>{o.value+=1};function _(){window.removeEventListener("resize",v),n.$toolbar.off?.("toolbar-items-changed",k),n.$toolbar.off?.("toolbar-state-change",C),s?.disconnect(),s=null}function y(){_(),window.addEventListener("resize",v),n.$toolbar.on?.("toolbar-items-changed",k),n.$toolbar.on?.("toolbar-state-change",C),typeof ResizeObserver<"u"&&n.$toolbar.config?.responsiveToContainer&&n.$toolbar.toolbarContainer&&(s=new ResizeObserver(()=>{v()}),s.observe(n.$toolbar.toolbarContainer)),g()}zn(y),Mg(y),Lg(_),cr(_);const w=()=>{if(!n.$toolbar.activeEditor){a=null,n.$toolbar.pendingSelectionCapture=null;return}a=n.$toolbar.ui?.selection?.capture?.()??null,n.$toolbar.pendingSelectionCapture=a},x=({item:$,argument:R,option:F})=>{L(),n.$toolbar.emitCommand({item:$,argument:R,option:F})},L=()=>{const $=n.$toolbar.activeEditor;if(!$)return;const R=n.$toolbar.pendingSelectionCapture??a;if(R&&typeof n.$toolbar.ui?.selection?.restore=="function"){n.$toolbar.ui.selection.restore(R);return}$.commands?.restoreSelection?.()},z=$=>{w(),!$.target.closest('input, textarea, [contenteditable="true"]')&&$.preventDefault()};return($,R)=>(ge(),Ie("div",{class:"superdoc-toolbar",key:Qe(r),role:"toolbar","aria-label":"Toolbar","data-sd-part":"toolbar","data-editor-ui-surface":"",onMousedown:z},[Qe(c)?(ge(),gn(dm,{key:0,tabindex:"0","toolbar-items":h("left"),"overflow-items":Qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"left",onCommand:x,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):vt("",!0),Zt(dm,{tabindex:"0","toolbar-items":h("center"),"overflow-items":Qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"center",onCommand:x},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"]),Qe(u)?(ge(),gn(dm,{key:1,tabindex:"0","toolbar-items":h("right"),"overflow-items":Qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"right",onCommand:x,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):vt("",!0)],32))}},WB=vn(GB,[["__scopeId","data-v-55b5af7a"]]),KB=e=>{if(!e)return e;const t=e.props?.style?.fontFamily??e.label??e.key;return{...e,props:{...e.props,style:{...e.props?.style,fontFamily:t},"data-item":e.props?.["data-item"]??"btn-fontFamily-option"}}};Lt();var En=e=>{if(!["button","options","separator","dropdown","overflow"].includes(e.type))throw new Error("Invalid toolbar item type - "+e.type);if(e.type==="button"&&!e.defaultLabel&&!e.icon)throw new Error(`Toolbar button item needs either "icon" or "defaultLabel" - ${e.name}. "label" is the live label and is not a substitute for "defaultLabel".`);if(!e.name)throw new Error("Invalid toolbar item name - "+e.name);const t=ne(ts()),n=e.type,r=ne(e.name),o=e.command,i=e.noArgumentCommand,s=ne(e.icon),a=ne(e.group||"center"),l=ne(e.allowWithoutEditor),c=ne(e.attributes||{}),u=e.disabled||!1,d=ne(e.disabled),h=ne(!1),g=ne(!1),p=ne(e.style),v=ne(e.isNarrow),k=ne(e.isWide),C=ne(e.minWidth),_=ne(e.suppressActiveHighlight||!1),y=ne(e.argument),w=ne(null),x=ne(null),L=ne(e.iconColor),z=ne(e.hasCaret),$=ne(!!e.splitButton),R=e.splitButtonCommand,F=!!e.restoreEditorFocus,X=ne(e.dropdownStyles),D=ne(e.tooltip),V=ne(e.tooltipVisible),T=ne(e.tooltipTimeout),N=ne(e.defaultLabel),Q=ne(e.label),K=ne(e.hideLabel),se=ne(e.inlineTextInputVisible),me=ne(e.hasInlineTextInput),Be=ne(e.markName),he=ne(e.labelAttr),ve=ne(e.selectedValue),ue=ne(e.dropdownValueKey),ke=ne(e.inputRef||null),re=ne([]);if(e.options){if(!Array.isArray(e.options))throw new Error("Invalid toolbar item options - "+e.options);let S=0;for(let ee=0;ee<e.options.length;ee+=1){const O=e.options[ee];(!O||typeof O!="object")&&(S+=1)}if(S)throw new Error(`Toolbar item options must all be objects - ${e.name}. ${S} row(s) are not, so this item is skipped.`);re.value?.push(...e.options)}const Re=(S={},...ee)=>{Ee(S,...ee),!_.value&&(h.value=!0)},Je=()=>{$e(),h.value=!1},st=S=>{d.value=S},Tt=()=>{d.value=u},Ee=e.onActivate||(()=>null),$e=e.onDeactivate||(()=>null),qe=()=>{const S={};return Object.keys(J).forEach(ee=>{J[ee].value!==void 0&&(S[ee]=J[ee].value)}),S},J={id:t,name:r,type:n,command:o,noArgumentCommand:i,icon:s,tooltip:D,group:a,attributes:c,disabled:d,active:h,expand:g,nestedOptions:re,style:p,isNarrow:v,isWide:k,minWidth:C,argument:y,parentItem:x,iconColor:L,hasCaret:z,splitButton:$,splitButtonCommand:R,dropdownStyles:X,tooltipVisible:V,tooltipTimeout:T,defaultLabel:N,label:Q,hideLabel:K,inlineTextInputVisible:se,hasInlineTextInput:me,restoreEditorFocus:F,markName:Be,labelAttr:he,childItem:w,allowWithoutEditor:l,dropdownValueKey:ue,selectedValue:ve,inputRef:ke};return{...J,unref:qe,activate:Re,deactivate:Je,setDisabled:st,resetDisabled:Tt,onActivate:Ee,onDeactivate:$e}};Lt(),kn();var qB=["onClick","innerHTML","aria-label","onKeydown"],YB={__name:"AlignmentButtons",emits:["select"],setup(e,{emit:t}){const{isHighContrastMode:n}=Ni(),r=t,o=ne([]),i=[{key:"left",ariaLabel:"Align left",icon:rr.alignLeft},{key:"center",ariaLabel:"Align center",icon:rr.alignCenter},{key:"right",ariaLabel:"Align right",icon:rr.alignRight},{key:"justify",ariaLabel:"Justify",icon:rr.alignJustify}],s=u=>{r("select",u)},a=u=>{if(u===o.value.length-1)return;const d=o.value[u+1];d&&(d.setAttribute("tabindex","0"),d.focus())},l=u=>{if(u===0)return;const d=o.value[u-1];d&&(d.setAttribute("tabindex","0"),d.focus())},c=(u,d)=>{switch(u.key){case"ArrowLeft":l(d);break;case"ArrowRight":a(d);break;case"Enter":s(i[d].key);break;default:break}};return zn(()=>{const u=o.value[0];u&&(u.setAttribute("tabindex","0"),u.focus())}),(u,d)=>(ge(),Ie("div",{class:ln(["alignment-buttons",{"high-contrast":Qe(n)}])},[(ge(),Ie(Jt,null,lr(i,(h,g)=>Oe("div",{key:h.key,class:"sd-button-icon",onClick:p=>s(h.key),innerHTML:h.icon,"data-item":"btn-textAlign-option",role:"menuitem","aria-label":h.ariaLabel,ref_for:!0,ref_key:"alignmentButtonsRefs",ref:o,onKeydown:sn(p=>c(p,g),["prevent"])},null,40,qB)),64))],2))}},XB=vn(YB,[["__scopeId","data-v-13e5f7a4"]]);Lt(),kn();var ZB=["onClick","innerHTML","aria-label","onKeydown"],QB={__name:"StyleButtonsList",props:{buttons:{type:Array,required:!0},selectedStyle:{type:String,default:null},iconSize:{type:Number,default:25}},emits:["select"],setup(e,{emit:t}){const{isHighContrastMode:n}=Ni(),r=t,o=e,i=ne([]),s=Ae(()=>({width:`${o.iconSize}px`,height:`${o.iconSize}px`})),a=d=>{r("select",d)},l=d=>{if(d===i.value.length-1)return;const h=i.value[d+1];h&&(h.setAttribute("tabindex","0"),h.focus())},c=d=>{if(d===0)return;const h=i.value[d-1];h&&(h.setAttribute("tabindex","0"),h.focus())},u=(d,h)=>{switch(d.key){case"ArrowLeft":c(h);break;case"ArrowRight":l(h);break;case"Enter":a(o.buttons[h].key);break;default:break}};return zn(()=>{const d=i.value[0];d&&(d.setAttribute("tabindex","0"),d.focus())}),(d,h)=>(ge(),Ie("div",{class:ln(["style-buttons-list",{"high-contrast":Qe(n)}])},[(ge(!0),Ie(Jt,null,lr(o.buttons,(g,p)=>(ge(),Ie("div",{key:g.key,class:ln(["sd-button-icon",{"sd-selected":o.selectedStyle===g.key}]),style:Sn(s.value),onClick:v=>a(g.key),innerHTML:g.icon,role:"menuitem","aria-label":g.ariaLabel,ref_for:!0,ref_key:"buttonRefs",ref:i,onKeydown:sn(v=>u(v,p),["prevent"])},null,46,ZB))),128))],2))}},rA=vn(QB,[["__scopeId","data-v-44f37ff6"]]),JB=[{key:"disc",icon:rr.bulletListDisc,ariaLabel:"Opaque circle"},{key:"circle",icon:rr.bulletListCircle,ariaLabel:"Outline circle"},{key:"square",icon:rr.bulletListSquare,ariaLabel:"Opaque square"}],ez=[{key:"decimal",icon:rr.numberedListDecimal,ariaLabel:"1. 2. 3."},{key:"decimal-paren",icon:rr.numberedListDecimalParen,ariaLabel:"1) 2) 3)"},{key:"upper-roman",icon:rr.numberedListUpperRoman,ariaLabel:"I. II. III."},{key:"lower-roman",icon:rr.numberedListLowerRoman,ariaLabel:"i. ii. iii."},{key:"upper-alpha",icon:rr.numberedListUpperAlpha,ariaLabel:"A. B. C."},{key:"upper-alpha-paren",icon:rr.numberedListUpperAlphaParen,ariaLabel:"A) B) C)"},{key:"lower-alpha",icon:rr.numberedListLowerAlpha,ariaLabel:"a. b. c."},{key:"lower-alpha-paren",icon:rr.numberedListLowerAlphaParen,ariaLabel:"a) b) c)"}];Lt(),kn();var tz=["onClick","onKeydown"],nz={class:"document-mode-column icon-column"},rz=["innerHTML"],oz={class:"document-mode-column text-column"},iz={class:"document-mode-type"},sz={class:"document-mode-description"},az={__name:"DocumentMode",props:{options:{type:Array}},emits:["select"],setup(e,{emit:t}){const n=t,r=ne([]),{isHighContrastMode:o}=Ni(),i=e,s=u=>{n("select",u)},a=u=>{if(u===r.value.length-1)return;const d=r.value[u+1];d&&(d.setAttribute("tabindex","0"),d.focus())},l=u=>{if(u===0)return;const d=r.value[u-1];d&&(d.setAttribute("tabindex","0"),d.focus())},c=(u,d)=>{switch(u.key){case"ArrowDown":a(d);break;case"ArrowUp":l(d);break;case"Enter":s(i.options[d]);break;default:break}};return zn(()=>{r.value[0].setAttribute("tabindex","0"),r.value[0].focus()}),(u,d)=>(ge(),Ie("div",{class:ln(["document-mode",{"high-contrast":Qe(o)}])},[(ge(!0),Ie(Jt,null,lr(e.options,(h,g)=>(ge(),Ie("div",{class:ln(["sd-option-item",{"sd-disabled":h.disabled}]),onClick:p=>s(h),"data-item":"btn-documentMode-option",role:"menuitem",ref_for:!0,ref_key:"documentModeRefs",ref:r,onKeydown:sn(p=>c(p,g),["prevent"])},[Oe("div",nz,[Oe("div",{class:"icon-column__icon",innerHTML:h.icon},null,8,rz)]),Oe("div",oz,[Oe("div",iz,Wt(h.label),1),Oe("div",sz,Wt(h.description),1)])],42,tz))),256))],2))}},lz=vn(az,[["__scopeId","data-v-bee14d7a"]]);Lt(),kn();var cz={class:"linked-style-buttons","data-editor-ui-surface":""},uz=["onClick","onKeydown","aria-label"],dz={__name:"LinkedStyle",props:{styles:{type:Array,default:()=>[]},selectedOption:{type:String,default:null}},emits:["select"],setup(e,{emit:t}){const n=t,r=ne([]),o=e,i=d=>{n("select",d)},s=d=>{if(d===r.value.length-1)return;const h=r.value[d+1];h.setAttribute("tabindex","0"),h.focus()},a=d=>{if(d===0)return;const h=r.value[d-1];h.setAttribute("tabindex","0"),h.focus()},l=(d,h,g)=>{switch(d.key){case"ArrowDown":s(h);break;case"ArrowUp":a(h);break;case"Enter":d.preventDefault(),i(g);break;default:break}},c=d=>d?.name??d?.id??"",u=d=>{const h=d?.preview?.css;return h&&typeof h=="object"?h:void 0};return zn(()=>{r.value[0]&&(r.value[0].setAttribute("tabindex","0"),r.value[0].focus())}),(d,h)=>(ge(),Ie("div",cz,[(ge(!0),Ie(Jt,null,lr(o.styles,(g,p)=>(ge(),Ie("div",{key:g.id??p,class:ln(["style-item",{selected:e.selectedOption===g.id}]),onClick:v=>i(g),onKeydown:v=>l(v,p,g),"aria-label":`Linked style - ${g.id??c(g)}`,ref_for:!0,ref_key:"styleRefs",ref:r},[Oe("div",{class:"style-name","data-item":"btn-linkedStyles-option",style:Sn(u(g))},Wt(c(g)),5)],42,uz))),128))]))}},fz=vn(dz,[["__scopeId","data-v-43b5dcca"]]);Lt(),kn();var hz=["placeholder"],pz={class:"sd-ai-writer__footer"},mz={key:0,class:"sd-ai-writer__error",role:"alert"},gz=["disabled"],vz="https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights",yz="You are an expert copywriter and you are immersed in a document editor. Only write what is asked for.",bz={__name:"AIWriter",props:{selectedText:{type:String,default:""},target:{type:Object,default:null},doc:{type:Object,default:null},apiKey:{type:String,default:""},endpoint:{type:String,default:""},restoreSelection:{type:Function,default:null},handleClose:{type:Function,required:!0}},setup(e){const t=e,n=ne(""),r=ne(!1),o=ne(""),i=ne(null),s=Ae(()=>t.selectedText?"Insert prompt to update text":"Insert prompt to generate text"),a=Ae(()=>n.value.trim().length>0&&!r.value);zn(()=>{It(()=>{i.value?.focus()})});function l(p){if(typeof p=="string")return p;if(!p||typeof p!="object")return"";const v=p.custom_prompt;if(Array.isArray(v)){const k=v[0];if(k&&typeof k.value=="string")return k.value}return v&&typeof v=="object"&&typeof v.value=="string"?v.value:typeof p.value=="string"?p.value:typeof p.text=="string"?p.text:""}async function c(p){const v={"Content-Type":"application/json"};t.apiKey&&(v["x-api-key"]=t.apiKey);const k=t.selectedText.trim(),C=k?`Rewrite the following text: "${k}" using these instructions: ${p}`:`Generate text based on the following prompt: ${p}`,_=await fetch(t.endpoint||vz,{method:"POST",headers:v,body:JSON.stringify({stream:!1,context:yz,insights:[{type:"custom_prompt",name:k?"text_rewrite":"text_generation",message:C,format:[{value:""}]}]})});if(!_.ok){const w=await _.text().catch(()=>"");throw new Error(w||`AI request failed with ${_.status}`)}const y=l((_.headers.get("content-type")||"").includes("application/json")?await _.json():await _.text()).trim();if(!y)throw new Error("AI returned no text.");return y}function u(p){return!p||typeof p!="object"?!0:!(p.success===!1||p.ok===!1)}function d(p){const v=t.doc;if(!v)throw new Error("Document API is unavailable.");t.restoreSelection?.();let k=null,C=!1;if(t.selectedText&&t.target&&typeof v.replace=="function"?(k=v.replace({target:t.target,text:p}),C=!0):t.target&&typeof v.insert=="function"?(k=v.insert({target:t.target,value:p,type:"text"}),C=!0):typeof v.insert=="function"&&(k=v.insert({value:p,type:"text"}),C=!0),!C)throw new Error("Document text insertion is unavailable.");if(!u(k))throw new Error("Unable to insert generated text.")}async function h(){if(a.value){o.value="",r.value=!0;try{d(await c(n.value.trim())),t.handleClose()}catch(p){o.value=p instanceof Error?p.message:String(p)}finally{r.value=!1}}}function g(p){p.key!=="Enter"||p.shiftKey||(p.preventDefault(),h())}return(p,v)=>(ge(),Ie("form",{class:"sd-ai-writer","data-item":"ai-writer",onSubmit:sn(h,["prevent"])},[js(Oe("textarea",{ref_key:"textareaRef",ref:i,"onUpdate:modelValue":v[0]||(v[0]=k=>n.value=k),class:"sd-ai-writer__input",placeholder:s.value,rows:"4",onKeydown:g},null,40,hz),[[Ci,n.value]]),Oe("div",pz,[o.value?(ge(),Ie("p",mz,Wt(o.value),1)):vt("",!0),Oe("button",{class:"sd-ai-writer__submit",type:"submit",disabled:!a.value},Wt(r.value?"Generating":"Generate"),9,gz)])],32))}},wz=vn(bz,[["__scopeId","data-v-67f6c6f7"]]);Lt(),kn();var Cz=["aria-label","onClick","onKeydown"],kz=["innerHTML"],Sz=["innerHTML"],fm=7,_z={__name:"IconGridRow",props:{icons:{type:Array,required:!0},activeColor:{type:Object,required:!1}},emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=e,o=Ae(()=>p=>r.activeColor.value?r.activeColor.value.toUpperCase()===p.value:!1),i=(p,v)=>v===5||["#FFFFFF","#FAFF09"].includes(p)?{color:"#000"}:{color:"#FFF"},s=p=>{n("select",p.value)},a=ne([]),l=ne([]);zn(()=>{if(!r.icons.every(v=>Array.isArray(v)))throw new Error("icon props must be 2d array");const p=l.value[0];p&&(p.setAttribute("tabindex","0"),p.focus({preventScroll:!0}))});const c=(p,v)=>{const k=fm*p+v+1,C=l.value[k];C&&(C.setAttribute("tabindex","0"),C.focus({preventScroll:!0}))},u=(p,v)=>{const k=fm*p+v-1,C=l.value[k];C&&(C.setAttribute("tabindex","0"),C.focus({preventScroll:!0}))},d=(p,v)=>{const k=v+fm*(p+1),C=l.value[k];C&&(C.setAttribute("tabindex","0"),C.focus({preventScroll:!0}))},h=(p,v)=>{const k=v+fm*(p-1),C=l.value[k];C&&(C.setAttribute("tabindex","0"),C.focus({preventScroll:!0}))},g=(p,v,k,C)=>{switch(p.key){case"ArrowRight":c(v,k);break;case"ArrowLeft":u(v,k);break;case"ArrowDown":d(v,k);break;case"ArrowUp":h(v,k);break;case"Enter":s(C);break;case"Escape":n("clickoutside");break;default:break}};return(p,v)=>(ge(!0),Ie(Jt,null,lr(e.icons,(k,C)=>(ge(),Ie("div",{class:"sd-option-row",key:C,role:"group",ref_for:!0,ref_key:"rowRefs",ref:a},[(ge(!0),Ie(Jt,null,lr(k,(_,y)=>(ge(),Ie("div",{class:"sd-option",key:y,"aria-label":_.label,role:"menuitem",ref_for:!0,ref_key:"iconRefs",ref:l,onClick:sn(w=>s(_),["stop","prevent"]),onKeydown:sn(w=>g(w,C,y,_),["prevent"])},[Oe("div",{class:"sd-option__icon",innerHTML:_.icon,style:Sn(_.style)},null,12,kz),o.value(_)?(ge(),Ie("div",{key:0,class:"sd-option__check",innerHTML:Qe(rr).colorOptionCheck,style:Sn(i(_.value,y))},null,12,Sz)):vt("",!0)],40,Cz))),128))]))),128))}},oA=vn(_z,[["__scopeId","data-v-05eb02fc"]]),Az=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 512c53.2 0 101.4-21.6 136.1-56.6l-298.3-235C140 257.1 128 292.3 128 320c0 106 86 192 192 192zM505.2 370.7c4.4-16.2 6.8-33.1 6.8-50.7c0-91.2-130.2-262.3-166.6-308.3C339.4 4.2 330.5 0 320.9 0l-1.8 0c-9.6 0-18.5 4.2-24.5 11.7C277.8 33 240.7 81.3 205.8 136L38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2S-1.2 34.7 9.2 42.9l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7L505.2 370.7zM224 336c0 44.2 35.8 80 80 80c8.8 0 16 7.2 16 16s-7.2 16-16 16c-61.9 0-112-50.1-112-112c0-8.8 7.2-16 16-16s16 7.2 16 16z"/></svg>
|
|
101
101
|
`;Lt(),kn();var Iz={class:"options-grid-wrap"},Ez=["innerHTML"],Tz={class:"option-grid-ctn"},xz={__name:"IconGrid",props:{icons:{type:Array,required:!0},customIcons:{type:Array,required:!1},activeColor:{type:Object,required:!1},hasNoneIcon:{type:Boolean,required:!1}},emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=o=>{n("select",o)};return(o,i)=>(ge(),Ie("div",Iz,[e.hasNoneIcon?(ge(),Ie("div",{key:0,class:"none-option",role:"menuitem","aria-label":"Clear color selection",onClick:i[0]||(i[0]=s=>r("none"))},[Oe("span",{innerHTML:Qe(Az),class:"none-icon"},null,8,Ez),i[1]||(i[1]=Pi(" None ",-1))])):vt("",!0),Oe("div",Tz,[Zt(oA,{icons:e.icons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"]),e.customIcons.flat().length?(ge(),Ie(Jt,{key:0},[i[2]||(i[2]=Oe("span",{class:"option-grid-ctn__subtitle"},"Custom colors",-1)),Zt(oA,{icons:e.customIcons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"])],64)):vt("",!0)])]))}},Rz=vn(xz,[["__scopeId","data-v-52b0283a"]]);Lt();var Mz=e=>{e.expand.value=!1},qt=(e,t=null)=>({label:t,icon:rr.colorOption,value:e,style:{color:e,boxShadow:"0 0 5px 1px rgba(0, 0, 0, 0.1)",borderRadius:"50%"}}),n2=(e,t,n=[],r=!1)=>{const o=i=>{t.iconColor.value=i,e.emitCommand({item:t,argument:i}),Mz(t),vu(e)};return $r("div",{},[$r(Rz,{icons:Lz,customIcons:n,activeColor:t.iconColor,hasNoneIcon:r,onSelect:o})])},Lz=[[qt("#111111","black"),qt("#333333","dark gray"),qt("#5C5C5C","medium gray"),qt("#858585","light gray"),qt("#ADADAD","very light gray"),qt("#D6D6D6","transparent gray"),qt("#FFFFFF","white")],[qt("#860028","dark red"),qt("#D2003F","red"),qt("#DB3365","coral red"),qt("#E4668C","light red"),qt("#ED99B2","pale pink"),qt("#F6CCD9","transparent pink"),qt("#FF004D","bright pink")],[qt("#83015E","dark purple"),qt("#CD0194","purple"),qt("#D734A9","orchid"),qt("#E167BF","light purple"),qt("#EB99D4","lavender"),qt("#F5CCEA","transparent pink"),qt("#FF00A8","neon pink")],[qt("#8E220A","maroon"),qt("#DD340F","red-orange"),qt("#E45C3F","burnt orange"),qt("#EB856F","peach"),qt("#F1AE9F","pale peach"),qt("#F8D6CF","transparent peach"),qt("#FF7A00","orange")],[qt("#947D02","olive"),qt("#E7C302","mustard yellow"),qt("#ECCF35","yellow"),qt("#F1DB67","light yellow"),qt("#F5E79A","very pale yellow"),qt("#FAF3CC","transparent yellow"),qt("#FAFF09","neon yellow")],[qt("#055432","forest green"),qt("#07834F","green"),qt("#399C72","medium green"),qt("#6AB595","light green"),qt("#9CCDB9","mint"),qt("#CDE6DC","transparent mint"),qt("#05F38F","bright teal")],[qt("#063E7E","navy blue"),qt("#0A60C5","blue"),qt("#3B80D1","sky blue"),qt("#6CA0DC","cornflower blue"),qt("#9DBFE8","light blue"),qt("#CEDFF3","very light blue"),qt("#21c8ce","cyan")],[qt("#3E027A","deep purple"),qt("#6103BF","indigo"),qt("#8136CC","violet"),qt("#A068D9","lavender pink"),qt("#C09AE6","light lilac"),qt("#DFCDF2","transparent lilac"),qt("#A91DFF","neon purple")]];Lt(),kn();var Pz=["data-cols","data-rows","onKeydown","onClick"],Dz=["aria-valuetext"],hm=5,Oz={__name:"TableGrid",emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=ne(0),o=ne(0),{isHighContrastMode:i}=Ni(),s=ne([]),a=d=>{let h=d.target;if(h.dataset.grid)return;let g=[...h.parentElement.querySelectorAll("[data-item]")],p=parseInt(h.dataset.cols,10),v=parseInt(h.dataset.rows,10);l(g,p,v)},l=(d,h,g)=>{o.value=h,r.value=g;for(let p=0;p<d.length;p++){let v=d[p],k=parseInt(v.dataset.cols,10),C=parseInt(v.dataset.rows,10);k<=h&&C<=g?v.classList.add("sd-selected"):v.classList.remove("sd-selected")}},c=({cols:d,rows:h})=>{n("select",{cols:d,rows:h})},u=(d,h,g)=>{let p=h-1,v=g-1;switch(d.key){case"ArrowRight":{if(p>=4)return;const k=v*hm;s.value[k+p+1].setAttribute("tabindex","0"),s.value[k+p+1].focus(),l(s.value,h+1,g);break}case"ArrowLeft":{if(p<=0)return;const k=v*hm;s.value[k+p-1].setAttribute("tabindex","0"),s.value[k+p-1].focus(),l(s.value,h-1,g);break}case"ArrowDown":{if(v>=4)return;const k=(v+1)*hm;s.value[k+p].setAttribute("tabindex","0"),s.value[k+p].focus(),l(s.value,h,g+1);break}case"ArrowUp":{if(v<=0)return;const k=(v-1)*hm;s.value[k+p].setAttribute("tabindex","0"),s.value[k+p].focus(),l(s.value,h,g-1);break}case"Enter":c({cols:h,rows:g});break;default:break}};return zn(()=>{s.value[0].setAttribute("tabindex","0"),s.value[0].focus(),l(s.value,1,1)}),(d,h)=>(ge(),Ie("div",{class:ln(["toolbar-table-grid-wrapper",{"high-contrast":Qe(i)}])},[Oe("div",{class:"toolbar-table-grid",onMouseover:a,"data-grid":"true"},[(ge(),Ie(Jt,null,lr(5,g=>(ge(),Ie(Jt,{key:g},[(ge(),Ie(Jt,null,lr(5,p=>Oe("div",{class:"toolbar-table-grid__item",key:`${g}_${p}`,"data-cols":p,"data-rows":g,"data-item":"true",ref_for:!0,ref_key:"tableGridItems",ref:s,onKeydown:sn(v=>u(v,p,g),["prevent"]),onClick:sn(v=>c({cols:p,rows:g}),["stop","prevent"])},null,40,Pz)),64))],64))),64))],32),Oe("div",{class:"toolbar-table-grid-value","aria-valuetext":`${r.value} x ${o.value}`},Wt(r.value)+" x "+Wt(o.value),9,Dz)],2))}},Fz=vn(Oz,[["__scopeId","data-v-b87d6ca2"]]);Lt(),kn();var Nz={class:"toolbar-table-actions"},Bz=["onClick","data-item","ariaLabel"],zz={class:"toolbar-table-actions__icon"},Vz=["innerHTML"],jz={class:"toolbar-table-actions__label"},Uz={__name:"TableActions",props:{options:{type:Array}},emits:["select"],setup(e,{emit:t}){const n=t,r=o=>{n("select",{command:o.command})};return(o,i)=>(ge(),Ie("div",Nz,[(ge(!0),Ie(Jt,null,lr(e.options,s=>(ge(),Ie("div",{class:ln(["toolbar-table-actions__item",{"toolbar-table-actions__item--border":s.bottomBorder}]),onClick:a=>r(s),"data-item":s.props?.["data-item"]||"",ariaLabel:s.props?.ariaLabel,role:"menuitem"},[Oe("div",zz,[Oe("div",{class:"toolbar-table-actions__icon-wrapper",innerHTML:s.icon},null,8,Vz)]),Oe("div",jz,Wt(s.label),1)],10,Bz))),256))]))}},Hz=vn(Uz,[["__scopeId","data-v-0cdad084"]]),$z=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>
|
|
102
|
-
`;Lt();var bs=e=>{e.expand.value=!1};function r2(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function iA(e){const t=Array.isArray(e?.segments)?e.segments:[];if(e?.kind!=="text"||!t.length)return null;const n=t[0],r=t[t.length-1];if(!n?.blockId||!r?.blockId||!n.range||!r.range)return null;const o=e.story;return{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.range.start??0,...o?{story:o}:{}},end:{kind:"text",blockId:r.blockId,offset:r.range.end??0,...o?{story:o}:{}},...o?{story:o}:{}}}function Gz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function sA(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Wz(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function Kz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}var qz=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=En({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),c=(r??VB).map(KB),u=En({type:"dropdown",name:"fontFamily",tooltip:n.fontFamily,command:"setFontFamily",defaultLabel:"Arial",label:"Arial",markName:"textStyle",labelAttr:"fontFamily",hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,isWide:!0,style:{width:"116px"},suppressActiveHighlight:!0,attributes:{ariaLabel:"Font family"},options:c,onActivate:({fontFamily:nt}={},Dt=!1)=>{if(Dt){u.label.value="",u.selectedValue.value="";return}if(!nt)return;nt=nt.split(",")[0],u.label.value=nt;const Gt=c.find(Nt=>Nt.label===u.defaultLabel.value),Rn=c.find(Nt=>Nt.label===nt);Rn?u.selectedValue.value=Rn.key:Gt?u.selectedValue.value=Gt.key:u.selectedValue.value=""},onDeactivate:()=>{u.label.value=u.defaultLabel.value;const nt=c.find(Dt=>Dt.label===u.defaultLabel.value);nt?u.selectedValue.value=nt.key:u.selectedValue.value=""}}),d=En({type:"dropdown",name:"ai",dropdownStyles:{padding:0,outline:"none"},tooltip:n.ai,icon:t.ai,hideLabel:!0,hasCaret:!1,isWide:!0,suppressActiveHighlight:!0,attributes:{ariaLabel:"AI"},options:[{type:"render",key:"ai",render:()=>h(d)}]});function h(nt){const Dt=sA(e),Gt=Dt?.selectionTarget??iA(Dt?.target),Rn=Dt?.empty?"":Gz(Dt),Nt=Kz(e),dn=()=>bs(nt),Mn=()=>{const De=e.pendingSelectionCapture;De&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(De)};return $r("div",{},[$r(wz,{handleClose:dn,selectedText:Rn,target:Gt,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Nt?.apiKey||e.config?.aiApiKey||"",endpoint:Nt?.endpoint||e.config?.aiEndpoint||"",restoreSelection:Mn})])}const g=UB,p=En({type:"dropdown",name:"fontSize",defaultLabel:"12",label:"12",style:{width:"56px"},markName:"textStyle",labelAttr:"fontSize",tooltip:n.fontSize,hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,suppressActiveHighlight:!0,isWide:!0,command:"setFontSize",attributes:{ariaLabel:"Font size"},options:g,onActivate:({fontSize:nt},Dt=!1)=>{if(Dt){p.label.value="",p.selectedValue.value="";return}const Gt=g.find(Mn=>Mn.label===String(p.defaultLabel.value));if(!nt){p.label.value=p.defaultLabel.value,Gt?p.selectedValue.value=Gt.key:p.selectedValue.value="";return}let Rn=LN(nt,12);Rn<8&&(Rn=8),Rn>96&&(Rn=96);let Nt=String(Rn);const dn=g.find(Mn=>Mn.label===Nt||Mn.key===Nt);dn?p.selectedValue.value=dn.key:p.selectedValue.value="",p.label.value=Nt},onDeactivate:()=>{p.label.value=p.defaultLabel.value;const nt=g.find(Dt=>Dt.label===String(p.defaultLabel.value));nt?p.selectedValue.value=nt.key:p.selectedValue.value=""}}),v=En({type:"separator",name:"separator",isNarrow:!0}),k=En({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),C=En({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),_=En({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=En({type:"dropdown",name:"highlight",icon:t.highlight,hideLabel:!0,markName:"highlight",labelAttr:"color",active:!1,tooltip:n.highlight,command:"setHighlight",noArgumentCommand:"unsetHighlight",suppressActiveHighlight:!0,attributes:{ariaLabel:"Highlight"},options:[{key:"color",type:"render",render:()=>n2(e,y,[],!0)}],onActivate:({color:nt})=>{y.iconColor.value=nt||""},onDeactivate:()=>y.iconColor.value=""}),w=En({type:"dropdown",name:"color",icon:t.color,hideLabel:!0,markName:"textStyle",labelAttr:"color",active:!1,tooltip:n.color,command:"setColor",suppressActiveHighlight:!0,attributes:{ariaLabel:"Color"},options:[{key:"color",type:"render",render:()=>n2(e,w)}],onActivate:({color:nt})=>{w.iconColor.value=nt},onDeactivate:()=>w.iconColor.value="#000"}),x=En({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),L=En({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>z(L)}],onActivate:({href:nt})=>{L.attributes.value=r2(L.attributes.value,nt)},onDeactivate:()=>{L.attributes.value=r2(L.attributes.value,null),L.expand.value=!1}});function z(nt){const Dt=sA(e),Gt=Dt?.selectionTarget??iA(Dt?.target),Rn=()=>{const Nt=e.pendingSelectionCapture;Nt&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Nt)};return $r("div",{},[$r(MS,{ui:e.ui,linkItem:nt,textTarget:Gt,restoreSelection:Rn,closePopover:()=>{bs(nt),vu(e)},goToAnchor:()=>{bs(nt);const Nt=nt.attributes.value?.href;if(!Nt)return;const dn=Nt.slice(1),Mn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${dn}']`);Mn&&mf(Mn)}})])}const $=En({type:"options",name:"linkInput",command:"toggleLink",active:!1});L.childItem=$,$.parentItem=L;const R=En({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),F=En({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),X=En({type:"dropdown",name:"table",icon:t.table,hideLabel:!0,labelAttr:"table",active:!1,tooltip:n.table,command:"insertTable",suppressActiveHighlight:!0,attributes:{ariaLabel:"Table"},options:[{key:"table",type:"render",render:()=>D(X)}]});function D(nt){return $r("div",{},[$r(Fz,{onSelect:Gt=>{e.emitCommand({item:nt,argument:Gt}),bs(nt),vu(e)}})])}const V=En({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>N(V)}]}),T=[{label:n.addRowBefore,command:"addRowBefore",icon:t.addRowBefore,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add row before"}},{label:n.addRowAfter,command:"addRowAfter",icon:t.addRowAfter,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add row after"}},{label:n.addColumnBefore,command:"addColumnBefore",icon:t.addColumnBefore,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add column before"}},{label:n.addColumnAfter,command:"addColumnAfter",icon:t.addColumnAfter,bottomBorder:!0,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add column after"}},{label:n.deleteRow,command:"deleteRow",icon:t.deleteRow,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete row"}},{label:n.deleteColumn,command:"deleteColumn",icon:t.deleteColumn,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete column"}},{label:n.deleteTable,command:"deleteTable",icon:t.deleteTable,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete table"}},{label:n.removeBorders,command:"deleteCellAndTableBorders",icon:t.deleteBorders,bottomBorder:!0,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete cell and table borders"}},{label:n.mergeCells,command:"mergeCells",icon:t.mergeCells,props:{"data-item":"btn-tableActions-option",ariaLabel:"Merge cells"}},{label:n.splitCell,command:"splitCell",icon:t.splitCell,props:{"data-item":"btn-tableActions-option",ariaLabel:"Split cells"}},{label:n.fixTables,command:"fixTables",icon:t.fixTables,props:{"data-item":"btn-tableActions-option",ariaLabel:"Fix tables"}}];function N(nt){return $r(Hz,{options:T,onSelect:Dt=>{bs(nt);const{command:Gt}=Dt;e.emitCommand({item:nt,argument:{command:Gt}})}})}const Q=En({type:"dropdown",name:"textAlign",tooltip:n.textAlign,icon:t.alignLeft,command:"setTextAlign",hasCaret:!0,markName:"textAlign",labelAttr:"textAlign",suppressActiveHighlight:!0,attributes:{ariaLabel:"Text align"},options:[{type:"render",render:()=>$r("div",{},[$r(XB,{onSelect:Dt=>{bs(Q);const Gt={...Q,command:"setTextAlign"};Gt.command="setTextAlign",e.emitCommand({item:Gt,argument:Dt}),K(Q,Dt),vu(e)}})]),key:"alignment"}],onActivate:({textAlign:nt})=>{K(Q,nt)},onDeactivate:()=>{K(Q,"left")}}),K=(nt,Dt)=>{let Gt=Dt==="both"?"justify":Dt,Rn={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Nt=Rn[Gt]??Rn.left;nt.icon.value=Nt},se=En({type:"dropdown",name:"list",command:"toggleBulletListStyle",splitButton:!0,splitButtonCommand:"toggleBulletList",icon:t.bulletList,hasCaret:!0,tooltip:n.bulletList,restoreEditorFocus:!0,attributes:{ariaLabel:"Bullet list"},options:[{type:"render",key:"bullet-style-buttons",render:()=>{const nt=Dt=>{bs(se);const Gt={...se,command:"toggleBulletListStyle"};e.emitCommand({item:Gt,argument:Dt})};return $r(rA,{buttons:JB,iconSize:25,selectedStyle:se.selectedValue.value,onSelect:nt})}}]}),me=En({type:"dropdown",name:"numberedlist",command:"toggleOrderedListStyle",splitButton:!0,splitButtonCommand:"toggleOrderedList",icon:t.numberedList,hasCaret:!0,tooltip:n.numberedList,restoreEditorFocus:!0,attributes:{ariaLabel:"Numbered list"},options:[{type:"render",key:"numbered-style-buttons",render:()=>{const nt=Dt=>{bs(me);const Gt={...me,command:"toggleOrderedListStyle"};e.emitCommand({item:Gt,argument:Dt})};return $r(rA,{buttons:ez,iconSize:30,selectedStyle:me.selectedValue.value,onSelect:nt})}}]}),Be=En({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),he=En({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ve=En({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ue=En({type:"dropdown",name:"zoom",allowWithoutEditor:!0,tooltip:n.zoom,defaultLabel:"100%",label:"100%",hasCaret:!0,command:"setZoom",isWide:!0,style:{width:"71px",minWidth:"71px"},inlineTextInputVisible:!1,hasInlineTextInput:!0,attributes:{ariaLabel:"Zoom"},options:[{label:"50%",key:.5,props:{"data-item":"btn-zoom-option"}},{label:"75%",key:.75,props:{"data-item":"btn-zoom-option"}},{label:"90%",key:.9,props:{"data-item":"btn-zoom-option"}},{label:"100%",key:1,props:{"data-item":"btn-zoom-option"}},{label:"125%",key:1.25,props:{"data-item":"btn-zoom-option"}},{label:"150%",key:1.5,props:{"data-item":"btn-zoom-option"}},{label:"200%",key:2,props:{"data-item":"btn-zoom-option"}}],onActivate:({zoom:nt})=>{nt&&(ue.label.value=nt)}}),ke=En({type:"dropdown",name:"measurementUnit",allowWithoutEditor:!0,tooltip:n.measurementUnit,defaultLabel:"in",label:"in",hasCaret:!0,command:"setMeasurementUnit",group:"right",style:{width:"52px",minWidth:"52px"},inlineTextInputVisible:!1,hasInlineTextInput:!1,attributes:{ariaLabel:"Measurement unit"},options:[{label:"Inches",key:"in",props:{"data-item":"btn-measurement-unit-option"}},{label:"Centimeters",key:"cm",props:{"data-item":"btn-measurement-unit-option"}}],onActivate:({measurementUnit:nt})=>{nt&&(ke.label.value=nt)}}),re=En({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Re=En({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),Je=En({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),st=En({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),Tt=En({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),Ee=En({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),$e=(nt,Dt)=>nt==="editor"?Dt:nt==="suggester"?Dt.filter(Gt=>Gt.value==="suggesting"):Dt.filter(Gt=>Gt.value==="viewing"),qe=nt=>nt==="editor"?"Editing":nt==="suggester"?"Suggesting":"Viewing",J=En({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:qe(s),label:qe(s),hasCaret:s==="editor",isWide:!0,style:{display:"flex",justifyContent:"flex-end"},inlineTextInputVisible:!1,hasInlineTextInput:!1,group:"right",disabled:s!=="editor",attributes:{dropdownPosition:"right",className:"sd-toolbar-item--doc-mode",ariaLabel:"Document mode"},options:[{type:"render",render:()=>ee(J)}]}),S=[{label:n.documentEditingMode,value:"editing",icon:t.documentEditingMode,description:n.documentEditingModeDescription},{label:n.documentSuggestingMode,value:"suggesting",icon:t.documentSuggestingMode,description:n.documentSuggestingModeDescription},{label:n.documentViewingMode,value:"viewing",icon:t.documentViewingMode,description:n.documentViewingModeDescription}];function ee(nt){return $r(lz,{options:$e(s,S),onSelect:Dt=>{const Gt=e.superdoc?.activeEditor??e.activeEditor;bs(nt);const{label:Rn,icon:Nt,value:dn}=Dt;J.label.value=Rn,J.icon.value=Nt,e.emitCommand({item:J,argument:dn}),vu(e,Gt)}})}const O=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),H=["search","ruler","undo","overflow","documentMode"],U=En({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),G=En({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),te=En({type:"dropdown",name:"linkedStyles",command:"setLinkedStyle",tooltip:n.linkedStyles,icon:t.paintbrush,defaultLabel:n.formatText,label:n.formatText,hasCaret:!0,isWide:!0,style:{width:"140px"},suppressActiveHighlight:!0,disabled:!1,attributes:{className:"sd-toolbar-item--linked-styles",ariaLabel:"Linked styles"},options:[{type:"render",key:"linkedStyle",render:()=>{const nt=Gt=>{bs(te);const Rn=typeof Gt=="string"?Gt:Gt?.id??null;if(!Rn)return;const Nt={...te,command:"setLinkedStyle"};e.emitCommand({item:Nt,argument:Rn})},Dt=e.getActiveLinkedStyleId?.()??null;return $r("div",{},[$r(fz,{styles:e.getLinkedStyleOptions?.()??[],onSelect:nt,selectedOption:Dt})])}}],onActivate:({styleId:nt,styleName:Dt})=>{const Gt=Dt||nt;te.label.value=nt&&nt!=="Normal"?String(Gt):n.formatText,te.disabled.value=!1},onDeactivate:()=>{te.disabled.value=!0,te.label.value=n.formatText}}),Y=(nt,Dt)=>{if(Dt.value==nt)return $r("div",{innerHTML:$z,class:"dropdown-select-icon"})},q=En({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,restoreEditorFocus:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(nt=>({label:nt.toFixed(2),key:nt,icon:()=>Y(nt,q.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),be=20,ye=32,we=H.reduce((nt,Dt)=>nt+(O.get(Dt)||O.get("default")),0),ze=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],rt=["zoom","fontFamily","fontSize","redo"],it=i<=Ff.lg,Ct=e.config?.showFormattingMarksButton===!0,en=e.config?.showTableOfContentsButton===!0;it&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),it&&(te.attributes.value={...te.attributes.value,className:`${te.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let Rt=[re,Re,Je,st,x,ue,u,v,p,v,l,k,C,_,w,y,v,L,R,...en?[F]:[],X,V,v,Q,se,me,Be,he,q,v,te,v,U,ke,...Ct?[G]:[],Ee,Tt,...Wz(e)?[d]:[],ve,J];if(i<=Ff.md&&o&&(Rt=Rt.filter(nt=>nt.type!=="separator")),e.config.mode!=="docx"){const nt=Rt.findIndex(Gt=>Gt.name.value==="linkedStyles");Rt.splice(nt-1,2);const Dt=["ruler","zoom","undo","redo"];Rt=Rt.filter(Gt=>!Dt.includes(Gt.name.value))}const zt=[];a||(s==="viewer"&&zt.push(Je,st),Rt=Rt.filter(nt=>!zt.includes(nt)));const $t=nt=>H.includes(nt.name.value),_n=[],bt=[];let tn=ye+we;return Rt.forEach(nt=>{const Dt=O.get(nt.name.value)||O.get("default");if(i<Ff.xl+be&&ze.includes(nt.name.value)&&o){if(_n.push(nt),nt.name.value==="linkedStyles"){const Gt=Rt.findIndex(Rn=>Rn.name.value==="linkedStyles");Rt.splice(Gt+1,1)}return}if(i<Ff.sm&&rt.includes(nt.name.value)&&o){_n.push(nt);return}if($t(nt)){bt.push(nt),tn+=Dt;return}tn<i||!o?(bt.push(nt),tn+=Dt):_n.push(nt)}),{defaultItems:bt,overflowItems:_n.filter(nt=>nt.type!=="separator")}},aA={bold:"Bold",fontFamily:"Font family",ai:"AI text generation",fontSize:"Font size",italic:"Italic",underline:"Underline",highlight:"Highlight color",strikethrough:"Strikethrough",color:"Text color",search:"Search",link:"Link",image:"Image",tableOfContents:"Table of contents",table:"Insert table",tableActions:"Table options",addRowBefore:"Insert row above",addRowAfter:"Insert row below",addColumnBefore:"Insert column left",addColumnAfter:"Insert column right",deleteRow:"Delete row",deleteColumn:"Delete column",deleteTable:"Delete table",removeBorders:"Remove borders",mergeCells:"Merge cells",splitCell:"Split cell",fixTables:"Fix tables",textAlign:"Alignment",bulletList:"Bullet list",numberedList:"Numbered list",indentLeft:"Left indent",indentRight:"Right indent",directionLtr:"Left-to-right",directionRtl:"Right-to-left",zoom:"Zoom",measurementUnit:"Measurement unit",undo:"Undo",redo:"Redo",trackChanges:"Track Changes",trackChangesAccept:"Accept changes under selection",trackChangesReject:"Reject changes under selection",trackChangesOriginal:"Toggle Show Original",trackChangesFinal:"Toggle Show Final",clearFormatting:"Clear formatting",copyFormat:"Format painter",lineHeight:"Line height",formatText:"Format text",ruler:"Show or hide ruler",formattingMarks:"Show or hide formatting marks",pageBreak:"Insert page break",documentEditingMode:"Editing",documentSuggestingMode:"Suggesting",documentViewingMode:"Viewing",documentEditingModeDescription:"Edit document directly",documentSuggestingModeDescription:"Edits become suggestions",documentViewingModeDescription:"View clean version of document only",linkedStyles:"Linked styles"},Yz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;Lt();function lA(e){return _N(e)??t2[e]??null}function pm(e,t,n,r={}){if(!e?.commands||!t||typeof e.commands.has=="function"&&!e.commands.has(t))return!1;const o=typeof e.commands.executeAsync=="function"?e.commands.executeAsync:e.commands.execute;if(typeof o!="function")return!1;const i=n===void 0?o.call(e.commands,t):o.call(e.commands,t,n);return i&&typeof i.then=="function"&&Promise.resolve(i).then(()=>r.onSettled?.(),s=>{r.onError?.(s),r.onSettled?.()}),!0}var Xz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Zz=new Set(["list","numberedlist"]);function Qz(e,t){if(e==="fontFamily"||e==="fontSize"||Zz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Xz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function cA(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Jz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var eV=class extends Ym.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...rr},texts:{...aA},fonts:null,hideButtons:!0,responsiveToContainer:!1,mode:"docx",excludeItems:[],groups:null,customButtons:[],showFormattingMarksButton:!1,showTableOfContentsButton:!1};toolbarItems=[];overflowItems=[];#t=null;#n=null;isDev=!1;role="editor";superdoc;toolbarContainer=null;toolbar=null;_detachFontsChanged=null;constructor(e={}){if(super(),this.config={...this.config,...e},this.toolbarItems=[],this.overflowItems=[],this.isDev=e.isDev||!1,this.superdoc=e.superdoc,this.role=e.role||"editor",this.toolbarContainer=null,this.config.icons={...rr,...e.icons},this.config.texts={...aA,...e.texts},this.config.hideButtons=e.hideButtons??!0,this.config.responsiveToContainer=e.responsiveToContainer??!1,this.activeEditor=e.editor??this.superdoc?.activeEditor??null,this.ui=null,this.snapshot=null,this._unsubscribeController=null,this._detachFormatPainterModeChange=null,this._customCommandRegs=new Map,this._reportedInvalidCustomItems=new Set,this._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=Yz(this.config.selector),this.toolbarContainer){const t=(this.config?.uiDisplayFallbackFont||"").toString().trim()||"Arial, Helvetica, sans-serif";this.toolbarContainer.style.setProperty("--sd-ui-font-family",t)}try{if(this.#e(),this.#d(),this.#f(),this.#i(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Dl(WB),this.app.directive("click-outside",Qv),this.app.config.globalProperties.$toolbar=this,this.toolbar=this.app.mount(this.toolbarContainer),this.updateToolbarState()}catch(t){try{this.destroy()}catch{}throw t}}#e(){this.ui=this.superdoc?.ui??null,this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot(),this._unsubscribeController=this.ui.toolbar.subscribe(()=>{this.snapshot=this.ui.toolbar.getSnapshot(),this.updateToolbarState()}),this._detachFormatPainterModeChange=this.ui.formatPainter.onModeChange(e=>{e==="armed"||e==="persistent"?this.#a():this.#S()}))}#r(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#S();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#i(){if(!this.superdoc||typeof this.superdoc.on!="function"||typeof this.superdoc.off!="function")return;const e=()=>{const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#s(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#d(){if(Array.isArray(this.config.groups)){this.config.toolbarGroups=this.config.groups,this.config.groups=null;return}this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length&&(this.config.toolbarGroups=Object.keys(this.config.groups))}getAvailableWidth(){const e=document.documentElement.clientWidth,t=this.toolbarContainer?.offsetWidth??0;return this.config.responsiveToContainer?t:e}#h(e){return e||jB(this.superdoc?.fonts?.getFontFamilyOptions?.()??[])}#f(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=qz({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#h(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=new Set([...n,...r].map(c=>c.name?.value).filter(Boolean)),s=o.map((c,u)=>{try{if(c?.name&&i.has(c.name))throw new Error(`Toolbar item name "${c.name}" is already taken by another item, so this entry is skipped.`);const d=this.#c(c);return i.add(d.name?.value),d}catch(d){const h=`${c?.name??`<unnamed@${u}>`}::${d?.message??String(d)}`;return this._reportedInvalidCustomItems.has(h)||(this._reportedInvalidCustomItems.add(h),this.#b(d,c?.name??null)),null}}).filter(Boolean);s.length&&n.push(...s);let a=[...n.map(c=>c.name.value),...r.map(c=>c.name.value)];if(t){const c=Object.values(this.config.groups).flatMap(h=>h),u=new Set(Object.keys(this.config.groups)),d=s.filter(h=>u.has(h.group?.value||"center")).map(h=>h.name.value);a=[...new Set([...c,...d])]}const l=n.filter(c=>a.includes(c.name.value)).filter(c=>!this.config.excludeItems.includes(c.name.value));if(t)for(const[c,u]of Object.entries(this.config.groups))for(const d of l)u.includes(d.name.value)&&(d.group.value=c);this.toolbarItems=l,this.overflowItems=r.filter(c=>a.includes(c.name.value))}#c(e){const t=En({...e});t.isCustomToolbarItem=!0;const n=e.command;if(typeof n=="function"&&this.ui?.commands?.register){const r=`__builtin_toolbar__${e.name}`;if(!this._customCommandRegs.has(r)){const o=this.ui.commands.register({id:r,execute:i=>{const s=i?.payload&&typeof i.payload=="object"?i.payload:{};return n({...i,item:t,argument:s.argument,option:s.option})}});this._customCommandRegs.set(r,o)}}return t}#p(){this.#f(),this.emit("toolbar-items-changed")}#o(){if(this.config.fonts)return"custom-fonts";const e=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return JSON.stringify(e.map(t=>[t.label,t.value,t.previewFamily]))}getToolbarItemByGroup(e){return this.toolbarItems.filter(t=>(t.group?.value||"center")===e)}getToolbarItemByName(e){return this.#l().find(t=>t.name.value===e)}#l(){return[...this.toolbarItems,...this.overflowItems]}getLinkedStyleOptions(){return this.ui?.styles?.getQuickGallery?.()??[]}getActiveLinkedStyleId(){return this.ui?.styles?.getActiveParagraphStyle?.()?.styleId??null}setActiveEditor(e){this.activeEditor=e;const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#f(),this.updateToolbarState()};#g(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#u(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#y(){const e=this.getToolbarItemByName("documentMode");if(!e)return;const t=(this.snapshot?.commands?.["document-mode"]?.value||"editing").toLowerCase(),n=this.config.texts||{},r=this.config.icons||{},o={editing:{label:n.documentEditingMode||"Editing",icon:r.documentEditingMode||r.documentMode},suggesting:{label:n.documentSuggestingMode||"Suggesting",icon:r.documentSuggestingMode||r.documentMode},viewing:{label:n.documentViewingMode||"Viewing",icon:r.documentViewingMode||r.documentMode}},i=o[t]||o.editing;e.label?.value!==void 0&&(e.label.value=i.label),e.defaultLabel?.value!==void 0&&(e.defaultLabel.value=i.label),e.icon?.value!==void 0&&i.icon&&(e.icon.value=i.icon)}#w(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>n2(this,e,[],!0)};e.nestedOptions.value=[t]}#k(e){return!!e?.active&&e?.value==null}#I(e){return!!e&&e.disabled===!1&&e.value==null}#E(e){const t=e.name.value;if(t==="tableActions"){const i=nA.map(s=>this.snapshot?.commands?.[s]).some(s=>s&&!s.disabled);return e.setDisabled(!i),!0}if(t==="search")return e.setDisabled(!1),!0;if(J0(t)?.disposition==="host-routed")return e.setDisabled(!this.#u(t)),this.#g(t)?e.activate():e.deactivate(),!0;const n=lA(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];Qz(t,r)?e.setDisabled(!1):e.setDisabled(!!r?.disabled);const o={textAlign:()=>{r?.value?e.activate({textAlign:r.value}):e.deactivate()},lineHeight:()=>{e.selectedValue.value=r?.value!=null?r.value:""},zoom:()=>{if(r?.value!=null){const i=typeof r.value=="number"?`${r.value}%`:String(r.value);e.onActivate({zoom:i})}},measurementUnit:()=>{r?.value!=null&&e.onActivate({measurementUnit:String(r.value)})},documentMode:()=>{this.#y()},link:()=>{e.active.value=!!r?.active,e.attributes.value=r2(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#I(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#k(r)){e.activate({},!0);return}e.deactivate()},color:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},highlight:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},linkedStyles:()=>{const i=r?.value,s=typeof i=="string"?i:i?.styleId,a=i&&typeof i=="object"?i.styleName:null;s?e.activate({styleId:s,styleName:a}):e.label.value=this.config.texts?.formatText||"Format text"},list:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},numberedlist:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},default:()=>{r?.active?e.activate():e.deactivate()}};return(o[t]??o.default)(),!0}updateToolbarState(){this.#y(),this.#w();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#L(),this.#l().forEach(n=>{n.allowWithoutEditor?.value&&this.#E(n)})):this.#l().forEach(n=>{n.resetDisabled(),this.#E(n)});const t=this.getToolbarItemByName("copyFormat");t&&(this.snapshot?.copyFormatActive?t.activate():t.deactivate()),this.emit("toolbar-state-change")}#L(){this.#l().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#P(e,t){const n=this.superdoc;if(e==="ruler")return typeof n?.toggleRuler=="function"?(n.toggleRuler(),!0):!1;if(e==="formattingMarks"){if(typeof t=="boolean"&&typeof n?.setShowFormattingMarks=="function")return n.setShowFormattingMarks(t),!0;if(typeof n?.toggleFormattingMarks=="function")return n.toggleFormattingMarks(),!0}return!1}#D(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#b(i,n)};if(n==="image"&&t==null)return this.#T();if(n==="tableActions"){const i=tA[t?.command];return i?pm(this.ui,i,void 0,r):!1}if(J0(n)?.disposition==="unsupported")return!0;const o=lA(n);return o?pm(this.ui,o,t,r):!1}#T(){return this.snapshot?.commands?.image?.disabled||(this.#t||(this.#t=MN({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await xN(e,this.superdoc?.config?.handleImageUpload);pm(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#b(n,"image")})},onError:e=>this.#b(e,"image")})),this.#t.open()),!0}#a(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{cA(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!cA(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Jz(i)&&this.ui.formatPainter.setKeyboardSelecting(!0)},o=()=>{this.ui.formatPainter.setKeyboardSelecting(!1),this.ui.formatPainter.notifyKeyUp()};e.addEventListener("pointerdown",t),e.addEventListener("pointerup",n),e.addEventListener("keydown",r),e.addEventListener("keyup",o),this.#n=()=>{e.removeEventListener("pointerdown",t),e.removeEventListener("pointerup",n),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}}#S(){this.#n&&(this.#n(),this.#n=null)}#b(e,t){const n={error:e instanceof Error?e:new Error(String(e)),originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null},r={...n};this.emit("exception",n),this.superdoc?.emit?.("exception",r)}emitCommand({item:e,argument:t,option:n}){const r=e?.name?.value,{command:o}=e,i=t!=null;if(!(e?.type==="dropdown"&&!i&&(o==="setFontFamily"||o==="setFontSize"))){if(r==="search"){this.superdoc?.emit?.("search:open");return}try{if(J0(r)?.disposition==="host-routed"){this.#P(r,t),this.updateToolbarState();return}if(typeof o=="function"){const s=`__builtin_toolbar__${r}`;this._customCommandRegs.has(s)&&this.ui?.commands?.execute?this.ui.commands.execute(s,{argument:t,option:n}):o({item:e,argument:t,option:n,ui:this.ui,superdoc:this.superdoc}),this.updateToolbarState();return}if(e?.isCustomToolbarItem&&typeof o=="string"){if(!pm(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#b(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#D(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#b(s,r)}}}destroy(){this.#S(),this.#t?.destroy(),this.#t=null,this.#s(),this.#r(),this.app?.unmount(),this.app=null,this.toolbar=null}};function tV(e){return new eV(e)}function nV(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null||Array.isArray(e)!==Array.isArray(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function rV(e){if(!e||typeof e!="object")return{};const t={};e.fonts&&(t.rFonts={ascii:e.fonts.ascii,hAnsi:e.fonts.hAnsi,eastAsia:e.fonts.eastAsia,cs:e.fonts.cs,asciiTheme:e.fonts.asciiTheme,hAnsiTheme:e.fonts.hAnsiTheme,eastAsiaTheme:e.fonts.eastAsiaTheme,csTheme:e.fonts.csTheme,hint:e.fonts.hint}),e.fontFamily!=null&&(t.fontFamily=e.fontFamily),e.lang&&(t.lang={val:e.lang.val,eastAsia:e.lang.eastAsia,bidi:e.lang.bidi}),e.fontSize!=null&&(t.fontSize=e.fontSize),e.fontSizeCs!=null&&(t.fontSizeCs=e.fontSizeCs);const n=mm(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=iV(e.shading);r&&(t.shading=r),e.cs!=null&&(t.cs=e.cs),e.rtl!=null&&(t.rtl=e.rtl),e.bold!=null&&(t.bold=e.bold),e.boldCs!=null&&(t.bCs=e.boldCs),e.italic!=null&&(t.italic=e.italic),e.italicCs!=null&&(t.iCs=e.italicCs);const o=oV(e.underline);o!==void 0&&(t.underline=o),e.strikethrough!=null&&(t.strike=e.strikethrough),e.doubleStrikethrough!=null&&(t.dstrike=e.doubleStrikethrough),e.caps!=null&&(t.caps=e.caps),e.smallCaps!=null&&(t.smallCaps=e.smallCaps),e.outline!=null&&(t.outline=e.outline),e.shadow!=null&&(t.shadow=e.shadow),e.emboss!=null&&(t.emboss=e.emboss),e.imprint!=null&&(t.imprint=e.imprint),e.verticalAlign!=null&&(t.vertAlign=e.verticalAlign),e.characterSpacing!=null&&(t.letterSpacing=e.characterSpacing),e.characterScale!=null&&(t.charScale=e.characterScale),e.kern!=null&&(t.kerning=e.kern),e.baselineShift!=null&&(t.position=e.baselineShift),e.fitTextWidth!=null&&(t.fitText={val:e.fitTextWidth}),e.vanish!=null&&(t.vanish=e.vanish),e.webHidden!=null&&(t.webHidden=e.webHidden),e.specVanish!=null&&(t.specVanish=e.specVanish);const i=sV(e.border);return i&&(t.border=i),t}function mm(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function oV(e){if(e==null)return;const t={};return e.style!=null&&(t.style=e.style),e.color?.model==="rgb"&&(t.color=e.color.value),e.color?.model==="theme"&&(t.themeColor=e.color.theme),Object.keys(t).length>0?t:!0}function iV(e){if(!e)return;const t={},n=mm(e.fill);n!=null&&(t.fill=n);const r=mm(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function sV(e){if(!e)return;const t={};e.style!=null&&(t.val=e.style),e.width!=null&&(t.sz=e.width),e.space!=null&&(t.space=e.space);const n=mm(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function Kl(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}function uA(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function aV(e){const t=[],n=o=>{o&&!t.includes(o)&&t.push(o)};n(e.getAttribute("data-track-change-preferred-target-id"));const r=e.getAttribute("data-track-change-ids");if(r)for(const o of uA(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function dA(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=aV(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const g of a){const p=`trackedChange:${g}`;if(!r.has(p)){r.add(p);const v={type:"trackedChange",id:g};l&&(v.storyKey=l),n.push(v),o.push(v)}}const c=s.getAttribute("data-layout-story");if(c&&o.length>0){for(const g of o)g.story=c;o=[]}const u=s.getAttribute("data-comment-ids");if(u)for(const g of uA(u)){const p=`comment:${g}`;r.has(p)||(r.add(p),n.push({type:"comment",id:g}))}const d=s.getAttribute("data-sdt-type"),h=s.getAttribute("data-sdt-id");if(h&&d==="structuredContent"){const g=`contentControl:${h}`;if(!r.has(g)){r.add(g);const p=s.getAttribute("data-sdt-scope"),v=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:h};(p==="block"||p==="inline")&&(k.scope=p),v&&(k.tag=v),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}var mo=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),rl=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),yu=()=>({oneOf:[{type:"number"},{type:"null"}]}),bu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),lV={type:"object",properties:{style:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},themeColor:{oneOf:[{type:"string",minLength:1},{type:"null"}]}},additionalProperties:!1,minProperties:1},cV={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},uV=()=>({oneOf:[{type:"boolean"},{type:"null"},lV]}),dV=()=>({oneOf:[{type:"array",items:cV,minItems:1},{type:"null"}]});function gm(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function fV(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var o2=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:gm(n),schema:mo()}),ql=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:gm("textStyle",o??e),schema:r}),Un=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:fV(o??e),schema:r}),vm=[o2("bold","w:b","bold"),o2("italic","w:i","italic"),o2("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:gm("underline"),schema:uV()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:gm("highlight"),schema:rl()},ql("color","string","w:color",rl()),ql("fontSize","number","w:sz",yu()),ql("fontFamily","string","w:rFonts",rl()),ql("letterSpacing","number","w:spacing",yu()),ql("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),ql("position","number","w:position",yu()),Un("dstrike","boolean","w:dstrike",mo()),Un("smallCaps","boolean","w:smallCaps",mo()),ql("caps","boolean","w:caps",mo(),"textTransform"),Un("shading","object","w:shd",bu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("border","object","w:bdr",bu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},sz:{oneOf:[{type:"number"},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},space:{oneOf:[{type:"number"},{type:"null"}]}}),"borders"),Un("outline","boolean","w:outline",mo()),Un("shadow","boolean","w:shadow",mo()),Un("emboss","boolean","w:emboss",mo()),Un("imprint","boolean","w:imprint",mo()),Un("charScale","number","w:w",yu(),"w"),Un("kerning","number","w:kern",yu(),"kern"),Un("vanish","boolean","w:vanish",mo()),Un("webHidden","boolean","w:webHidden",mo()),Un("specVanish","boolean","w:specVanish",mo()),Un("rtl","boolean","w:rtl",mo()),Un("cs","boolean","w:cs",mo()),Un("bCs","boolean","w:bCs",mo(),"boldCs"),Un("iCs","boolean","w:iCs",mo(),"italicCs"),Un("eastAsianLayout","object","w:eastAsianLayout",bu({id:{oneOf:[{type:"string",minLength:1},{type:"null"}]},combine:{oneOf:[{type:"boolean"},{type:"null"}]},combineBrackets:{oneOf:[{type:"string",minLength:1},{type:"null"}]},vert:{oneOf:[{type:"boolean"},{type:"null"}]},vertCompress:{oneOf:[{type:"boolean"},{type:"null"}]}})),Un("em","string","w:em",rl()),Un("fitText","object","w:fitText",bu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("snapToGrid","boolean","w:snapToGrid",mo()),Un("lang","object","w:lang",bu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("oMath","boolean","w:oMath",mo()),Un("rStyle","string","w:rStyle",rl(),"styleId"),Un("rFonts","object","w:rFonts",bu({ascii:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsi:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},cs:{oneOf:[{type:"string",minLength:1},{type:"null"}]},asciiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsiaTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},csTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hint:{oneOf:[{type:"string",minLength:1},{type:"null"}]}}),"fontFamily"),Un("fontSizeCs","number","w:szCs",yu()),Un("ligatures","string","w14:ligatures",rl()),Un("numForm","string","w14:numForm",rl()),Un("numSpacing","string","w14:numSpacing",rl()),Un("stylisticSets","array","w14:stylisticSets",dV()),Un("contextualAlternates","boolean","w14:cntxtAlts",mo())],WH=new Set(vm.map(e=>e.key)),hV=Object.fromEntries(vm.map(e=>[e.key,e])),KH={mark:vm.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:vm.filter(e=>e.storage==="runAttribute").map(e=>e.key)},i2=new WeakMap;function pV(e){let t=i2.get(e);return t||(t={refCount:0,generation:0,abortController:new AbortController,inFlight:null,activeMutationTokens:new Set},i2.set(e,t)),t.refCount+=1,t}function mV(e,t){t.refCount=Math.max(0,t.refCount-1),!(t.refCount>0)&&(t.abortController.abort("ui-controller-destroyed"),t.inFlight=null,t.activeMutationTokens.clear(),i2.delete(e))}var gV=new Set(Object.values(dt));function s2(e,t){return typeof e=="string"&&gV.has(e)?e:t}function fA(e){if(e&&typeof e=="object"&&e.ok===!1){const t=e.reason;return t==="host-not-ready"||t==="host-disposed"||t==="editing-mount-required"?{ok:!1,reason:dt.notReady}:{ok:!1,reason:s2(t,dt.targetUnresolved)}}return{ok:!0}}var vV=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],yV={[$4.bulletList]:"bullet",[$4.numberedList]:"ordered"};function hA(e){return yV[e]??null}var bV={disc:"disc",circle:"circle",square:"square",decimal:"decimal","decimal-paren":"decimalParenthesis","upper-roman":"upperRoman","lower-roman":"lowerRoman","upper-alpha":"upperLetter","upper-alpha-paren":"upperLetterParenthesis","lower-alpha":"lowerLetter","lower-alpha-paren":"lowerLetterParenthesis"};function wV(e){const t=bV[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var CV={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""},kV=[{key:"contentControls",match:"exact",note:"full-document SDT catalog parse (the measured during-load cliff)"},{key:"contentControls:inRange:",match:"prefix",note:"same adapter load() as the catalog, issued per settled selection"},{key:"hyperlinks:",match:"prefix",note:"per-block hyperlink list over the loading story"},{key:"styles:catalog:",match:"prefix",note:"WordStyleModel recompile from package bytes"},{key:"comments",match:"exact",note:"audited: full comments list; stale-served during load"},{key:"trackChanges",match:"exact",note:"audited: shared all-story tracked-changes catalog; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: current-token validation over the shared all-story catalog; consumers fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}],SV=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function _V(e){return kV.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var pA={ready:0,stale:1,pending:2};function wu(...e){let t="ready";for(const n of e)pA[n]>pA[t]&&(t=n);return t}function Pt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Sr(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function vr(e,t){if(!e)return null;const n=t.split(".");let r=e;for(const o of n){if(r==null)return null;r=r[o]}return typeof r=="function"?r:null}function Xn(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Nf(e,t){return{success:!1,failure:{code:"PARTIAL_LINK_EDIT",message:"Hyperlink target was updated, but display text replacement failed."},applied:{href:!0,text:!1},hyperlinkResult:e,textResult:t}}function Bf(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function a2(e){if(!e||typeof e!="object")return!1;const t=e,n=i=>{if(!i||typeof i!="object")return!1;const s=i;return s.kind==="text"&&typeof s.blockId=="string"&&typeof s.offset=="number"},r=i=>{if(!i||typeof i!="object")return!1;const s=i,a=s.range;return typeof s.blockId=="string"&&typeof a?.start=="number"&&typeof a.end=="number"};if(Array.isArray(t.segments)){const i=t.segments[0],s=t.segments[t.segments.length-1];return r(i)&&r(s)}if(t.kind==="selection")return n(t.start)&&n(t.end);if(t.kind!=="text"||typeof t.blockId!="string")return!1;const o=t.range;return typeof o?.start=="number"&&typeof o.end=="number"}function AV(e){if(!e||typeof e!="object")return null;const t=Bf(e);if(a2(t))return t;const n=e,r=n.navigationTarget&&typeof n.navigationTarget=="object"?n.navigationTarget:null;return r?.kind==="block"&&typeof r.blockId=="string"&&r.blockId.length>0?{kind:"text",blockId:r.blockId,range:{start:0,end:0},...r.story&&typeof r.story=="object"?{story:r.story}:{},...n.address&&typeof n.address=="object"?{address:n.address}:{}}:t}function _r(e){if(!e||typeof e!="object")return"story:body";const t=e,n=typeof t.storyType=="string"?t.storyType:"body";switch(n){case"body":return"story:body";case"headerFooterPart":return`story:headerFooterPart:${typeof t.refId=="string"?t.refId:""}`;case"headerFooterSlot":return JSON.stringify({storyType:n,section:t.section??null,headerFooterKind:t.headerFooterKind??null,variant:t.variant??null,resolution:t.resolution??"effective",onWrite:t.onWrite??"materializeIfInherited"});case"footnote":return`story:footnote:${typeof t.noteId=="string"?t.noteId:""}`;case"endnote":return`story:endnote:${typeof t.noteId=="string"?t.noteId:""}`;case"textbox":return`story:textbox:${typeof t.textboxId=="string"?t.textboxId:""}`;default:return JSON.stringify(t)}}function Cu(e){if(!e||typeof e!="object")return null;const t=e,n=t.address&&typeof t.address=="object"?t.address:null;if(n?.story&&typeof n.story=="object")return n.story;if(t.storyLocator&&typeof t.storyLocator=="object")return t.storyLocator;if(t.trackedChangeStory&&typeof t.trackedChangeStory=="object")return t.trackedChangeStory;const r=Bf(e);if(!r||typeof r!="object")return null;const o=r;if(o.story&&typeof o.story=="object")return o.story;const i=o.address&&typeof o.address=="object"?o.address:null;return i?.story&&typeof i.story=="object"?i.story:null}function Ui(e,t,n){return Gn(e)!==t?!1:n?_r(Cu(e))===_r(n):!0}function ym(e){const t=Cu(e);if(!(!t||_r(t)===_r(null)))return t}function IV(e){if(typeof e!="string"||e.length===0)return;const t=S6(e);switch(t.kind){case"body":return;case"footnote":return t.id?{kind:"story",storyType:"footnote",noteId:t.id}:void 0;case"endnote":return t.id?{kind:"story",storyType:"endnote",noteId:t.id}:void 0;case"header":case"footer":return t.id?{kind:"story",storyType:"headerFooterPart",refId:t.id}:void 0;default:return}}function EV(e){if(!(typeof e!="string"||e.length===0||e==="body")){if(e.startsWith("hf:part:")){const t=e.slice(8);return t?{kind:"story",storyType:"headerFooterPart",refId:t}:void 0}if(e.startsWith("fn:")){const t=e.slice(3);return t?{kind:"story",storyType:"footnote",noteId:t}:void 0}if(e.startsWith("en:")){const t=e.slice(3);return t?{kind:"story",storyType:"endnote",noteId:t}:void 0}}}function l2(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function bm(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function TV(e){if(!e||typeof e!="object")return null;const t=e;if(t.kind!=="selection")return e;const n=t.start;return!n||typeof n!="object"?null:{...t,end:n}}function Gn(e){if(!e||typeof e!="object")return null;const t=e,n=t.id??t.commentId??t.changeId;return typeof n=="string"&&n.length>0?n:null}function xV(e){if(!e||typeof e!="object")return null;const t=e,n=t.anchor,r=t.focus,o=n?.visualCaret,i=r?.visualCaret,s=o?.trackChangeId,a=i?.trackChangeId;return typeof s=="string"&&s.length>0&&s===a?s:null}var mA=new WeakMap;function gA(e){const t=[],n=i=>{typeof i=="string"&&i.length>0&&!t.includes(i)&&t.push(i)},r=i=>{if(!i||typeof i!="object")return;const s=i,a=s.sourceIds;if(a&&typeof a=="object"&&(n(a.wordIdInsert),n(a.wordIdDelete),Array.isArray(a.wordIdOther)))for(const d of a.wordIdOther)n(d);const l=s.wordRevisionIds;l&&typeof l=="object"&&(n(l.insert),n(l.delete),n(l.format));const c=s.replacement;if(c&&typeof c=="object")for(const d of[c.inserted,c.deleted])d&&typeof d=="object"&&(n(d.id),n(d.wordId));const u=s.move;if(u&&typeof u=="object")for(const d of[u.source,u.destination])d&&typeof d=="object"&&(n(d.id),n(d.wordId))};r(e);const o=e?.change;return o&&o!==e&&r(o),t}function fa(e){const t=mA.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=Gn(i);if(s){n.add(s);for(const a of gA(i)){r.has(a)||r.set(a,s);const l=`imported:${a}`;r.has(l)||r.set(l,s)}}}const o={toPublicId(i){if(n.has(i))return i;const s=r.get(i);return s!=null&&n.has(s)?s:null},aliasesFor(i){const s=[i];for(const[a,l]of r)l===i&&!s.includes(a)&&s.push(a);return s}};return mA.set(e,o),o}var vA=new WeakMap,yA=new WeakMap;function ku(e,t){const n=_r(t);let r=vA.get(e);r||(r=new Map,vA.set(e,r));const o=r.get(n);if(o)return o;const i=fa(e.filter(s=>_r(Cu(s))===n));return r.set(n,i),i}function RV(e){return!!e&&typeof e=="object"&&e.storyType==="textbox"}function MV(e,t){const n=t.filter(o=>e.some(i=>Gn(i)===o&&Cu(i)==null));if(n.length===0)return null;if(n.length===1)return n[0];const r=new Set;for(const o of n){const i=e.find(s=>Gn(s)===o);if(i)for(const s of gA(i)){if(r.has(s))return null;r.add(s)}}return n[0]}function LV(e){const t=yA.get(e);if(t)return t;const n=e.filter(o=>Cu(o)!=null),r=n.length===e.length?e:n;return yA.set(e,r),r}function PV(e){const{selectionIds:t,publicIds:n,selection:r,bodyItems:o,allStoryItems:i}=e;if(t.length===0)return null;const s=c=>{for(const u of t){const d=c.toPublicId(u);if(d)return d}return null},a=Hi(r),l=_r(a)===_r(null);if(i){const c=l?LV(i):i,u=s(ku(c,a));if(u)return u;const d=n?.find(h=>c.some(g=>Ui(g,h,a)));return d||(l?s(fa(o)):RV(a)?MV(i,t):null)}return l?s(fa(o))??t[0]??null:null}function DV(e,t){const n=e.find(r=>Gn(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??Gn(n)??t:null}function OV(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,c=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:c??l}}const n=e.target,r=n&&Array.isArray(n.segments)?n.segments:[],o=r[0]?.blockId,i=r[r.length-1]?.blockId;return typeof o=="string"?{startBlockId:o,endBlockId:typeof i=="string"?i:o}:null}function Nr(e){const t=[],n=s=>{typeof s=="string"&&s.length>0&&!t.includes(s)&&t.push(s)},r=e.target,o=r&&Array.isArray(r.segments)?r.segments:[];for(const s of o)n(s?.blockId);const i=e.selectionTarget;return i&&(n(i.start?.blockId),n(i.end?.blockId)),t}var FV=64;function Yl(e){return e.length<=FV}function Hi(e){const t=e.target,n=e.selectionTarget,r=n?.start,o=n?.end,i=t?.story??n?.story??r?.story??o?.story;return i&&typeof i=="object"?i:{kind:"story",storyType:"body"}}function Co(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function ha(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function bA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var wA=720;function ws(e){return Math.round(e*20)}function Su(e){return typeof e=="number"&&Number.isFinite(e)}function NV(e){if(!e||typeof e!="object")return null;const t=e.node;if(!t||typeof t!="object")return null;const n=t.kind==="heading"?t.heading??null:t.kind==="paragraph"?t.paragraph??null:null;if(!n)return null;const r=n.resolved,o=n.props,i=r?.indent??o?.indent;if(!i||typeof i!="object")return null;const s=Su(i.left)?ws(i.left):Su(i.start)?ws(i.start):void 0,a=Su(i.right)?ws(i.right):Su(i.end)?ws(i.end):void 0,l=Su(i.firstLine)?ws(i.firstLine):void 0,c=Su(i.hanging)?ws(i.hanging):void 0;return s==null&&a==null&&l==null&&c==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...c!=null?{hanging:c}:{}}}function c2(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=t?.story,o=[];for(const i of n){if(!i||typeof i.blockId!="string")continue;const s=i.range;!s||typeof s.start!="number"||typeof s.end!="number"||s.start===s.end||o.push({kind:"text",blockId:i.blockId,range:{start:s.start,end:s.end},...r?{story:r}:{}})}return o}function BV(e){if(!e||typeof e!="object")return[];const t=e,n=t.story,r=[];if(t.kind==="text"&&t.range&&typeof t.blockId=="string"){const o=t.range;return typeof o.start=="number"&&typeof o.end=="number"&&o.start!==o.end&&r.push({kind:"text",blockId:t.blockId,range:{start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)},...n?{story:n}:{}}),r}if(t.kind==="text"&&Array.isArray(t.segments)){for(const o of t.segments){const i=o?.range;typeof o?.blockId=="string"&&typeof i?.start=="number"&&typeof i?.end=="number"&&i.start!==i.end&&r.push({kind:"text",blockId:o.blockId,range:{start:Math.min(i.start,i.end),end:Math.max(i.start,i.end)},...n?{story:n}:{}})}return r}if(t.kind==="selection"){const o=t.start,i=t.end,s=typeof o?.blockId=="string"&&i?.blockId===o.blockId?o.blockId:null;o?.kind==="text"&&i?.kind==="text"&&s&&typeof o.offset=="number"&&typeof i.offset=="number"&&o.offset!==i.offset&&r.push({kind:"text",blockId:s,range:{start:Math.min(o.offset,i.offset),end:Math.max(o.offset,i.offset)},...t.story??o.story?{story:t.story??o.story}:{}})}return r}function zf(e){if(!e||typeof e!="object")return null;const t=e,n=t.story;if(t.kind==="text"&&t.range&&typeof t.blockId=="string"){const r=t.range;if(typeof r.start=="number"&&typeof r.end=="number"&&r.start===r.end)return{kind:"text",blockId:t.blockId,range:{start:r.start,end:r.end},...n?{story:n}:{}}}if(t.kind==="text"&&Array.isArray(t.segments)){const r=t.segments[0],o=r?.range;if(typeof r?.blockId=="string"&&typeof o?.start=="number"&&typeof o?.end=="number"&&o.start===o.end)return{kind:"text",blockId:r.blockId,range:{start:o.start,end:o.end},...n?{story:n}:{}}}if(t.kind==="selection"){const r=t.start,o=t.end,i=typeof r?.blockId=="string"&&o?.blockId===r.blockId?r.blockId:null;if(r?.kind==="text"&&o?.kind==="text"&&i&&typeof r.offset=="number"&&typeof o.offset=="number"&&r.offset===o.offset)return{kind:"text",blockId:i,range:{start:r.offset,end:r.offset},...t.story??r.story?{story:t.story??r.story}:{}}}return null}function ol(e){return zf(e.target)??zf(e.selectionTarget)}var CA=["fontFamily","fontSize","color","highlight"],zV={undo:"history.undo",redo:"history.redo"},Vf=["bold","italic","underline","strikethrough"];function u2(e){return CA.includes(e)}function _u(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,c,u)=>{typeof l!="string"||typeof c!="number"||typeof u!="number"||r.push({blockId:l,start:Math.min(c,u),end:Math.max(c,u)})};for(const l of n){const c=l?.range;o(l?.blockId,c?.start,c?.end)}if(r.length>0)return r;const i=e.selectionTarget,s=i?.start,a=i?.end;return!s||!a||s.blockId!==a.blockId||o(s.blockId,s.offset,a.offset),r}function $i(e){const t=e.target,n=e.selectionTarget,r=n?.start,o=n?.end,i=t?.story??n?.story??r?.story??o?.story;return i&&typeof i=="object"?i:void 0}function VV(e){const t=$i(e);if(!t||typeof t!="object")return"body";const n=t;return JSON.stringify({storyType:typeof n.storyType=="string"?n.storyType:"body",refId:typeof n.refId=="string"?n.refId:null,noteId:typeof n.noteId=="string"?n.noteId:null,textboxId:typeof n.textboxId=="string"?n.textboxId:null})}function pa(e){const t=_u(e);return t.length===0?null:[VV(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function kA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:Kl({selectionTarget:t})}function jV(e,t){if(e==="fontSize"){const r=typeof t=="number"?t:Number(t);return Number.isFinite(r)&&r>0?String(r):null}if(typeof t!="string")return null;const n=t.trim();return n.length===0?null:e==="color"||e==="highlight"?n.toUpperCase():n}function UV(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function HV(e){if(!e)return[];const t=Array.isArray(e.blocks)?e.blocks:[],n=[];for(const r of t){const o=r?.range,i=r?.blockId;typeof i!="string"||typeof o?.start!="number"||typeof o?.end!="number"||n.push({blockId:i,start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)})}return n}function $V(e,t){return e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return o?.blockId===n.blockId&&o?.start===n.start&&o?.end===n.end})}function SA(e,t){const n=_u(t);if(n.length===0)return null;const r=e&&Array.isArray(e.items)?e.items:[];if(r.length===0)return null;const o=r.find(i=>$V(n,HV(i)));if(o)return o;if(n.length===1){const i=r.find(s=>{const a=s?.address;return a?.kind==="block"&&a.nodeId===n[0].blockId});if(i)return i}return r[0]??null}function GV(e,t){const n=t==="fontSize"?e?.fontSizePt??e?.fontSize:t==="highlight"?e?.highlight??e?.backgroundColor:e?.[t];if(typeof n=="number")return Number.isFinite(n)?String(n):void 0;if(typeof n!="string")return;const r=n.trim();if(r.length!==0)return t==="color"||t==="highlight"?r.toUpperCase():r}function d2(e){if(typeof e!="string")return;const t=e.split(",")[0]?.trim().replace(/^['"]+|['"]+$/g,"").trim();if(!t)return;const n=t.toLowerCase();if(!(n==="serif"||n==="sans-serif"||n==="monospace"||n==="cursive"||n==="fantasy"))return t}function WV(e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return;const t=Math.round(e*.75*2)/2;if(!(t<=0))return String(t)}function KV(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function _A(e,t){if(!e)return{};const n=new Map;for(const i of _u(t)){const s=n.get(i.blockId)??[];s.push({start:i.start,end:i.end}),n.set(i.blockId,s)}if(n.size===0)return{};const r=Array.isArray(e.blocks)?e.blocks:[],o={};for(const i of CA){const s=new Map;let a=!1,l=!1;for(const c of r){const u=typeof c?.blockId=="string"?c.blockId:null;if(!u)continue;const d=n.get(u);if(!d?.length)continue;const h=Array.isArray(c?.runs)?c.runs:[];for(const g of h){const p=g?.range,v=typeof p?.start=="number"?p.start:null,k=typeof p?.end=="number"?p.end:null;if(v==null||k==null||!d.some(y=>UV(y,{start:v,end:k})))continue;a=!0;const C=GV(g?.styles,i);if(C===void 0){l=!0;continue}const _=KV(i,C);if(s.has(_)||s.set(_,C),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function f2(e,t){const n=Nr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:Co(n)}:{kind:"documentEnd"}}function cn(e,t){const n=e.supported??t!=="unsupported",r=e.enabled??(e.disabled!==void 0?!e.disabled:n);return{enabled:r,disabled:!r,active:e.active??!1,supported:n,value:e.value,source:t,reason:r?void 0:e.reason}}function il(e){if(!e||typeof e!="object")return null;const t=e,n=t.change,r=n&&typeof n=="object"?n:t;return{...t,id:t.id??r.id,change:r}}function wm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function Cs(e){if(Sr(e))return!0;if(e===!1)return!1;if(e===!0||e==null||typeof e!="object")return!0;const t=e;return"success"in t||"failure"in t||"effects"in t?e:t.status!=="rejected"}function Cm(e){return!!e&&typeof e=="object"&&e.success===!0}function ko(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function Xl(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function h2(e){const t=[],n=r=>{if(!r||typeof r!="object")return;const o=r;if(Array.isArray(o.runs)&&t.push(o),Array.isArray(o.rows))for(const i of o.rows){const s=i?.cells;if(Array.isArray(s))for(const a of s){const l=a;if(Array.isArray(l?.blocks))for(const c of l.blocks)n(c);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function Zl(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function km(e){return e.trackedChange?.kind==="delete"?0:typeof e.text=="string"?e.text.length:0}function hi(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!ko(i)&&n===null&&(n=i),Cm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function qV(e){const t=e?.anchor,n=t?.start,r=t?.end;return typeof n?.blockId!="string"||typeof r?.blockId!="string"||n.blockId!==r.blockId||typeof n.offset!="number"||typeof r.offset!="number"?null:{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.offset},end:{kind:"text",blockId:r.blockId,offset:r.offset}}}function YV(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function Sm(e){return gu(e)?.trackDecision??null}function XV(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function sl(e){return{found:!1,success:!1,rects:[],reason:e}}function ZV(e,t){if(!t||typeof t.getBoundingClientRect!="function"||e.rects.length===0)return e;let n;try{const o=t.getBoundingClientRect();n={left:o.left,top:o.top}}catch{return e}const r=e.rects.map(o=>({...o,left:o.left-n.left,right:o.right-n.left,top:o.top-n.top,bottom:o.bottom-n.top}));return{...e,rects:r,rect:r[0]}}function QV(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.blockId!="string"||!t.range||typeof t.range!="object")return!1;const n=t.range;return Number.isInteger(n.start)&&Number.isInteger(n.end)&&n.start>=0&&n.start<=n.end}function AA(e){if(!e||e.kind!=="text"||!Array.isArray(e.segments)||e.segments.length===0)return null;const t=Array.from(e.segments);if(!t.every(QV))return null;const n=t[0],r=t[t.length-1],o=e.story;return{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.range.start,...o?{story:o}:{}},end:{kind:"text",blockId:r.blockId,offset:r.range.end,...o?{story:o}:{}},...o?{story:o}:{}}}function JV(e){return e.selectionTarget?e.selectionTarget:AA(e.target)}function Au(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=AA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function p2(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var m2={bold:null,italic:null,underline:null,strike:null,color:null,highlight:null,fontFamily:null,fontSize:null,vertAlign:null,smallCaps:null,caps:null,letterSpacing:null,dstrike:null},ej=Object.fromEntries(Object.entries(m2).filter(([e])=>hV[e]?.tracked===!0));function tj(e,t,n,r){switch(e.kind){case"toggle":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n;return typeof o=="boolean"||o===null?{target:t,value:o}:{target:t,value:!r}}case"value-string":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n;return o===null?{target:t,value:null}:typeof o!="string"||o.trim()===""?null:{target:t,value:o}}case"value-number":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n,i=typeof o=="number"?o:Number(o);return!Number.isFinite(i)||i<=0?null:{target:t,value:i}}case"clear":return{target:t,inline:{...m2}};default:return null}}function nj(e){const t=o=>{if(!o||typeof o!="object")return null;const i=o,s=i.rowIndex,a=i.columnIndex;return typeof s!="number"||!Number.isInteger(s)||typeof a!="number"||!Number.isInteger(a)?null:{rowIndex:s,columnIndex:a}};if(!e)return null;const n=t(e.start),r=t(e.end);return!n||!r?null:{start:n,end:r}}function rj(e,t){const{tableNodeId:n,rowIndex:r,columnIndex:o,cellNodeId:i,mergeRange:s}=t;switch(e){case"insert-row-before":return{nodeId:n,rowIndex:r,position:"above"};case"insert-row-after":return{nodeId:n,rowIndex:r,position:"below"};case"delete-row":return{nodeId:n,rowIndex:r};case"insert-column-before":return{nodeId:n,columnIndex:o,position:"left"};case"insert-column-after":return{nodeId:n,columnIndex:o,position:"right"};case"delete-column":return{nodeId:n,columnIndex:o};case"delete-table":return{nodeId:n};case"merge-cells":{const a=s??{start:{rowIndex:r,columnIndex:o},end:{rowIndex:r,columnIndex:o}};return{nodeId:n,start:a.start,end:a.end}}case"split-cell":return i?{nodeId:i,rows:1,columns:2}:null;case"remove-borders":return{nodeId:n,mode:"applyTo",applyTo:"all",border:null};default:return null}}function oj(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,c=!1,u=Promise.resolve(),d=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},g=0;const p=new Set;let v={},k="",C=null;const _=()=>{const f=t?.activeEditor;return f&&typeof f=="object"?f:null},y=()=>{const f=_()?.doc;return f&&typeof f=="object"?f:null},w=()=>{const f=_()?.v2TrackedChanges;return f&&typeof f=="object"?f:null},x=()=>{const f=_()?.host;return f&&typeof f=="object"?f:null},L=f=>{if(f.storyType!=="headerFooterPart"||typeof f.refId!="string")return null;const m=_(),b=x(),I=m?.pageLayout??b?.pageLayout;if(!I||typeof I!="object")return null;const E=I.getActiveRulerContext,B=b?.resolveHeaderFooterEditTarget;if(typeof E!="function"||typeof B!="function")return null;const W=Pt(()=>E.call(I),null);if(!W||typeof W.pageIndex!="number")return null;for(const ie of["header","footer"]){const fe=Pt(()=>B.call(b,{pageIndex:W.pageIndex,kind:ie}),null);if(!(fe?.status!=="ready"||fe.refId!==f.refId||typeof fe.sectionId!="string"||!["default","first","even"].includes(String(fe.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:fe.sectionId},headerFooterKind:ie,variant:fe.slotVariant}}return null},z=()=>{const f=x(),m=f?.getPendingInlineFormat;if(typeof m!="function")return null;const b=Pt(()=>m.call(f),null);return b&&typeof b=="object"?b:null},$=f=>{const m=p2(f);if(!m)return null;const b=z();if(!b||!(m in b))return null;const I=b[m];return f.inline?.kind==="toggle"?I===!0:I!=null&&I!==""},R=f=>{const m=p2(f);if(!m)return;const b=z();if(!b||!(m in b))return;const I=b[m];if(typeof I=="string"&&I!=="")return I;if(typeof I=="number"&&Number.isFinite(I))return String(I)},F=(f,m)=>{const b=x(),I=b?.setPendingInlineFormat;typeof I=="function"&&Pt(()=>I.call(b,f,m),void 0)},X=f=>{const m=x(),b=m?.clearPendingInlineFormat;typeof b=="function"&&Pt(()=>b.call(m,f),void 0)},D=new Set(["bold","italic","underline","strikethrough"]),V=f=>{const m=z();if(!m)return;const b=Array.isArray(f.activeMarks)?f.activeMarks:[];let I=null;for(const E of Object.keys(m)){const B=m[E];let W;if(D.has(E))W=b.includes(E)===(B===!0);else if(u2(E)){if(B==null)continue;I||(I=fl(f)),W=I[E]===B}else W=!1;W&&X(E)}},T=()=>{const f=_()?.editCommands;return f&&typeof f=="object"?f:null},N=f=>{const m=T();if(!m||typeof m.getSnapshot!="function")return null;const b=Pt(()=>m.getSnapshot(),null)?.commands?.[f];return b&&typeof b=="object"?b:null},Q=()=>N("lists.apply"),K=f=>{const m=f?.value?.seed;return m==="bullet"||m==="ordered"?m:null},se=f=>{const m=zV[f];return m?N(m):null},me=()=>{const f=x();if(!f||typeof f.getTableContext!="function")return null;const m=Pt(()=>f.getTableContext(),null);return m&&typeof m=="object"?m:null},Be=()=>{const f=me();if(!f||f.inTable!==!0)return null;const m=f.table,b=typeof m?.nodeId=="string"&&m.nodeId.length>0?m.nodeId:null;if(!b)return null;const I=f.row,E=f.column,B=f.cell,W=typeof I?.index=="number"&&Number.isInteger(I.index)?I.index:null,ie=typeof E?.index=="number"&&Number.isInteger(E.index)?E.index:null;if(W==null||ie==null)return null;const fe=typeof B?.nodeId=="string"&&B.nodeId.length>0?B.nodeId:null,Le=f.cellRange;return{tableNodeId:b,rowIndex:W,columnIndex:ie,cellNodeId:fe,mergeRange:nj(Le)}},he=new Map;let ve=null,ue=null,ke=0,re=0,Re=0;const Je=new Set,st=(f,m)=>f===m?!0:!f||!m?!1:f.id===m.id&&f.paintedEntityId===m.paintedEntityId&&_r(f.story)===_r(m.story),Tt=f=>Array.from(Je).some(m=>st(m,f)),Ee=f=>{const m=x();if(typeof m?.getHandles!="function")return;const b=Pt(()=>m.getHandles(),null),I=b?.review;if(I){if(f){if(typeof I.setActiveReviewTarget!="function")return;const E=b?.layout;Pt(()=>I.setActiveReviewTarget({entityType:"trackedChange",entityId:f.id,...f.paintedEntityId?{paintedEntityId:f.paintedEntityId}:{},origin:"panel",layoutEpoch:typeof E?.generation=="number"?E.generation:0,story:f.story??{kind:"story",storyType:"body"}}),null);return}typeof I.getActiveReviewTarget!="function"||typeof I.clearActiveReviewTarget!="function"||Pt(()=>I.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Pt(()=>I.clearActiveReviewTarget(),void 0)}},$e=(f,m)=>{ue=f,ke+=1,Re+=1,m?.invalidateQueuedNavigation!==!1&&(re+=1)},qe=new Set;let J=!1,S=null;const ee=new Map,O=new Set;let H=null,U=null,G=!1,te=null,Y=0,q=null,be=null,ye=null;const we=()=>{if(G||J)return;G=!0;const f=()=>{G=!1,J||Kt()};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},ze=250,rt=5e3,it=f=>{J||te&&Y<=f||(te&&clearTimeout(te),Y=f,te=setTimeout(()=>{te=null,Y=0,J||Kt()},Math.max(0,f-Date.now())))},Ct=new WeakMap;let en=0;const Rt=f=>{if(!f)return"none";let m=Ct.get(f);return m==null&&(m=en+=1,Ct.set(f,m)),`e${m}`};let zt=0,$t={};const _n=e.superdoc,bt=pV(_n),tn=()=>{bt.abortController.abort("review-mutation-started"),bt.inFlight=null},nt=()=>{bt.generation+=1,bt.abortController=new AbortController,bt.inFlight=null},Dt=f=>{const m=bt.activeMutationTokens;if(typeof f!="string"||f.length===0||m.has(f))return;const b=m.size===0;m.add(f),b&&tn()},Gt=f=>{const m=bt.activeMutationTokens;typeof f!="string"||!m.delete(f)||m.size===0&&nt()},Rn=f=>{const m=w(),b=m?.listTrackedChanges;if(typeof b!="function")return _()?.editorVersion===2?Promise.reject(new Error("v2-tracked-changes-bridge-pending")):f();if(bt.activeMutationTokens.size>0)return Promise.reject(new Error("ui-review-catalog-superseded"));if(_()?.reviewHydration?.getDiagnostics?.()?.inFlight===!0)return Promise.reject(new Error("shell-review-hydration-in-flight"));const I=bt.generation,E=bt.inFlight;if(E?.generation===I)return E.promise;const B=bt.abortController.signal,W=Le=>{if(B.aborted||I!==bt.generation||Le?.reason==="review-hydration-superseded")throw new Error("ui-review-catalog-superseded");return Le},ie=b.call(m,{blocking:!1,signal:B});if(!Sr(ie))return W(ie);const fe=Promise.resolve(ie).then(W);return bt.inFlight={generation:I,promise:fe},fe.then(()=>{bt.inFlight?.promise===fe&&(bt.inFlight=null)},()=>{bt.inFlight?.promise===fe&&(bt.inFlight=null)}),fe};let Nt=null,dn=null,Mn=0;const De=()=>{dn&&clearTimeout(dn),dn=null,Mn=0};let We=f=>{},Ke=null,mt=new Set,jt=null,_t=0,Yt=null;const Et=()=>`${Rt(_())}|m${zt}`,pn=()=>{Ke=null,mt=new Set},Kn=f=>{for(const m of["trackChanges","trackChanges:all"]){const b=ee.get(m);if(!b?.hasSettled||!Array.isArray(b.value))continue;const I=b.value.filter(E=>{const B=Gn(E);return!B||!f.has(B)});I.length!==b.value.length&&ee.set(m,{...b,value:I})}},go=f=>{const m=()=>{if(!J)for(const B of[...qe])B(pt)},b=Xl(f)?f:null,I=_()?.documentMutationReadiness,E=()=>{const B=globalThis.requestAnimationFrame;return typeof B!="function"?Promise.resolve():new Promise(W=>{let ie=!1;const fe=()=>{ie||(ie=!0,clearTimeout(Le),W())},Le=setTimeout(fe,250);B(()=>B(()=>setTimeout(fe,0)))})};if(b?.success===!0&&typeof b.txId=="string"&&b.txId.length>0&&typeof I?.whenPainted=="function")try{Promise.resolve(I.whenPainted.call(I,b)).then(E,()=>{}).then(m,m);return}catch{}m()},qn=(f,m)=>{const b=pt.trackChanges,I=b.items.filter(W=>{const ie=Gn(W);return!ie||!f.has(ie)});if(I.length===b.items.length)return;ue&&f.has(ue.id)&&$e(null);const E=new Set;for(const W of I){const ie=wm(W),fe=W,Le=ie.author??ie.authorEmail??fe.author??fe.authorEmail;typeof Le=="string"&&E.add(Le)}const B=b.items.length-I.length;pt={...pt,trackChanges:{...b,items:I,total:Math.max(I.length,b.total-B),activeId:b.activeId&&f.has(b.activeId)?null:b.activeId,authors:[...E]}},go(m)},nn=f=>{const m=pt.trackChanges,b=m.items.length>0||m.total!==0||m.activeId!==null||m.authors.length>0;jt=Et(),ue!==null&&$e(null),pt={...pt,trackChanges:{...m,items:[],total:0,activeId:null,authors:[]}},b&&go(f)},Yn=(f,m)=>{if(f.size===0)return;const b=Et(),I=Ke===b?mt:new Set,E=new Set([...f].filter(B=>!I.has(B)));E.size!==0&&(Ke=b,mt=new Set([...I,...E]),Kn(mt),qn(E,m))},yr=f=>Ke===f&&mt.size>0?mt:null,ir=(f,m=[])=>{const b=f.map(il).filter(E=>E!=null&&Gn(E)!=null);if(b.length===0)return;const I=m.map(il).map(E=>E==null?null:Gn(E)).filter(E=>E!=null);for(const E of["trackChanges","trackChanges:all"]){const B=ee.get(E),W=B?.hasSettled&&Array.isArray(B.value)?[...B.value]:[],ie=new Set;let fe=!1;for(const Le of b){const Ue=Gn(Le);if(!Ue)continue;const je=W.findIndex(Ne=>Gn(Ne)===Ue);if(je<0)W.push(Le),ie.add(Ue);else{const Ne=W[je];W[je]=Xl(Ne)?{...Ne,...Le}:Le}fe=!0}if(E==="trackChanges"&&ie.size>0&&I.length>0){const Le=new Set(I.filter(Ne=>ie.has(Ne))),Ue=new Map(W.filter(Ne=>Le.has(Gn(Ne)??"")).map(Ne=>[Gn(Ne),Ne])),je=W.filter(Ne=>!Le.has(Gn(Ne)??""));for(const[Ne,Ye]of I.entries()){if(!Le.has(Ye))continue;const He=Ue.get(Ye);if(!He)continue;const Xe=I.slice(Ne+1).map(ot=>je.findIndex(tt=>Gn(tt)===ot)).find(ot=>ot>=0);if(Xe!=null){je.splice(Xe,0,He);continue}const Ze=I.slice(0,Ne).reverse().map(ot=>je.findIndex(tt=>Gn(tt)===ot)).find(ot=>ot>=0);je.splice(Ze==null?je.length:Ze+1,0,He)}W.splice(0,W.length,...je)}fe&&ee.set(E,{token:B?.token??null,value:W,hasSettled:!0,inflightToken:null})}},un=f=>{const m=Et(),b=yr(m),I=f.map(il).filter(E=>{if(E==null)return!1;const B=Gn(E);return B!=null&&!b?.has(B)});for(const E of["trackChanges","trackChanges:all"])ee.set(E,{token:m,value:[...I],hasSettled:!0,inflightToken:null})},Hn=async(f,m)=>{try{const b=f.v2TrackedChanges?.listTrackedChanges;if(typeof b=="function"){const B=await Promise.resolve(b.call(f.v2TrackedChanges,{mode:m.trackedChangesListMode,refreshReason:m.refreshReason,blocking:m.blocking,...m.targetIds?.length?{targetIds:m.targetIds}:{}})),W=m.trackedChangesListMode==="all"&&m.refreshReason==="mutation-history-render-reconcile"?B?.ok===!0:B?.ok!==!1;return{ok:W,items:W&&Array.isArray(B?.items)?B.items:[],...typeof B?.complete=="boolean"?{complete:B.complete}:{},...typeof B?.sourceCoverageComplete=="boolean"?{sourceCoverageComplete:B.sourceCoverageComplete}:{}}}const I=f.docTrackChanges?.list;if(typeof I!="function")return{ok:!1,items:[]};const E=await Promise.resolve(I.call(f.docTrackChanges));return{ok:!0,items:Array.isArray(E?.items)?E.items:[]}}catch(b){return{ok:!1,items:[],failures:[b]}}},br=jk({getContext:()=>{const f=_();if(!f)return null;const m=w(),b=y()?.trackChanges??null,I=m??b;if(!I)return null;const E=f.documentId??m?.documentId;return{editor:f,adapter:I,documentId:E==null?null:String(E),reconcileToken:$t,v2TrackedChanges:m,docTrackChanges:b}},reconcile:async(f,m)=>{m.removedIds.size>0&&Yn(new Set(m.removedIds));const b=[...new Set(m.upsertIds)];if(b.length===0)return{ok:!0,items:[],resolvedIds:[],unresolvedIds:[]};const I=ee.get("trackChanges"),E=I?.hasSettled&&Array.isArray(I.value)?I.value:null,B=new Set(E?E.map(Gn).filter(Ze=>Ze!=null):[]),W=E?.length===0&&Ki()==="complete",ie=new Set(b.filter(Ze=>!B.has(Ze))),fe=f.v2TrackedChanges?.getTrackedChange,Le=f.docTrackChanges?.get;if(typeof fe!="function"&&typeof Le!="function")return{ok:!1,items:[],resolvedIds:[],unresolvedIds:b};const Ue=await Promise.all(b.map(async Ze=>{try{if(typeof fe=="function"){const tt=await Promise.resolve(fe.call(f.v2TrackedChanges,Ze));return{id:Ze,ok:tt?.ok!==!1,items:tt?.ok!==!1&&Array.isArray(tt?.items)?tt.items:[],result:tt}}const ot=await Promise.resolve(Le.call(f.docTrackChanges,{id:Ze}));return{id:Ze,ok:!0,items:ot&&typeof ot=="object"?[ot]:[],result:ot}}catch(ot){return{id:Ze,ok:!1,items:[],result:ot}}})),je=[],Ne=[],Ye=[];for(const Ze of Ue){const ot=Ze.items.filter(tt=>{const Bt=il(tt);return Bt!=null&&Gn(Bt)===Ze.id});Ze.ok&&ot.length>0?(je.push(...ot),Ne.push(Ze.id)):Ye.push(Ze.id)}let He;const Xe=Ne.filter(Ze=>ie.has(Ze));if(Xe.length>0&&!W){const Ze=await Hn(f,{trackedChangesListMode:"interaction-prime",refreshReason:"mutation-render-reconcile",blocking:!1,targetIds:Xe});Ze.ok&&(He=Ze.items)}return{ok:Ye.length===0,items:je,orderedItems:He,resolvedIds:Ne,unresolvedIds:Ye,failures:Ue.filter(Ze=>!Ze.ok).map(Ze=>Ze.result)}},hydrate:Hn,onReconciled:(f,m,b)=>{if(b?.reconcileMode==="authoritative"){if(f.reconcileToken!==$t)return;b.ok===!0&&b.complete===!0&&b.sourceCoverageComplete===!0?(De(),un(b.items??[]),Nt=null):b.ok===!0?(De(),ir(b.items??[])):We(f.reconcileToken),Kt();return}const I=(b?.items??[]).filter(E=>{const B=il(E),W=B==null?null:Gn(B);return W!=null&&m.has(W)});ir(I,b?.orderedItems??b?.items??[]),Kt()}});We=f=>{if(J||dn)return;const m=Math.min(ze*2**Mn,rt);Mn+=1,dn=setTimeout(()=>{dn=null,!(J||Nt===null||f!==$t)&&br.onRender(!0)},m)};const Br=()=>`${Et()}|m${Wn()}|s${_t}`,Wr=f=>JSON.stringify({t:f.target??null,s:f.selectionTarget??null}),Qo=["contentControls:inRange:","query:","effInline:"],Wi=120,ma=180,Ki=()=>{const f=x(),m=f?.getDocumentLoadingSnapshot;if(typeof m!="function")return"unknown";const b=Pt(()=>m.call(f),null)?.sourceStage;return b==="opening"||b==="bootstrap-ready"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},_i=new Map,ga=f=>{const m=Et();_i.get(f)!==m&&(_i.set(f,m),we())},va=()=>{const f=ee.get("comments");return f?.hasSettled?Array.isArray(f.value)&&f.value.length>0:f?.inflightToken!=null},Jo=(f,m)=>_i.get(f)===m,No=f=>{ga("contentControls")},_e=()=>{const f=ee.get("trackChanges");f?.hasSettled||f?.inflightToken!=null||ga("trackChanges")},Ve=6500,ft=250;let ut=0,Vn=0,yn=!1,Ar=null;const no=()=>{if(J||Ar)return;const f=()=>{if(Ar=null,J)return;const m=Date.now()-ut;if(io()||m<Ve){Ar=setTimeout(f,ft);return}yn=!1,Kt()};Ar=setTimeout(f,0)};let ro=null,oo=null;const qi=()=>{const f=x();if(!f||ro===f)return;oo&&(oo(),oo=null),ro=f;const m=f.subscribeDocumentLoading;if(typeof m!="function"){ro=null,Ai(Ve);return}try{const b=B=>{const W=B?.sourceStage;(W==="source-complete"||W==="source-failed"||W==="source-cancelled")&&(ut=Math.max(ut,Date.now()),no())},I=m.call(f,b);typeof I=="function"&&(oo=I);const E=f.getDocumentLoadingSnapshot;typeof E=="function"&&b(Pt(()=>E.call(f),null))}catch{ro=null,Ai(Ve)}},Bo=()=>{const f=_()?.host,m=f?.getForegroundMutationState;if(typeof m!="function")return null;const b=Pt(()=>m.call(f),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},io=()=>{const f=Bo();return!!(f&&(f.active>0||f.pending>0))},Ai=(f=Wi)=>{J||q||(q=setTimeout(()=>{if(q=null,J)return;if(be&&io()){Ai(),Kt();return}const m=be;be=null,m===Br()&&ba("selection",m,ll,Ti),Kt()},f))},Ql=(f,m)=>{if(!Bo())return!1;const b=`${f}\0${m}`;return O.has(b)?!1:(O.add(b),Ai(ma),!0)},Kr=f=>{if(H==null||f===H)return U?.timer&&clearTimeout(U.timer),U=null,H=f,!1;if(U?.key===f)return U.ready?(U=null,H=f,!1):!0;U?.timer&&clearTimeout(U.timer);const m={key:f,ready:!1,timer:null};return m.timer=setTimeout(()=>{J||U!==m||(m.timer=null,m.ready=!0,Kt())},ma),U=m,!0},Ii=f=>Uk(f),ei=()=>{ks(),Kt()};let qr=null,zo=!1,Yi=0;const Jl=()=>{qr=null,zo=!1,Yi+=1},ya=()=>{const f=_(),m=f?.documentMutationReadiness;if(!f||typeof m?.whenPainted!="function"||(qr={editor:f,readiness:m,afterEpoch:typeof m.getRenderEpoch=="function"?Pt(()=>m.getRenderEpoch.call(m),null):null},zo))return;zo=!0;const b=Yi;(async()=>{for(;!J&&b===Yi;){const E=qr;if(qr=null,!E){zo=!1;return}let B=!1;try{await E.readiness.whenPainted.call(E.readiness,typeof E.afterEpoch=="number"?{afterEpoch:E.afterEpoch}:void 0),B=!0}catch{}if(J||b!==Yi)return;if(_()!==E.editor){Jl();return}B&&ei()}})()},Xi=()=>{ye&&clearTimeout(ye),ye=setTimeout(()=>{ye=null,J||ei()},500)},ba=(f,m,b,I)=>{let E;try{E=b()}catch{E=void 0}if(!Sr(E)){const ie={token:m,value:I(E),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return ee.set(f,ie),ie}const B=ee.get(f),W=B?.failedToken===m;return ee.set(f,{token:B?.token??null,value:B?.value??null,hasSettled:B?.hasSettled??!1,inflightToken:m,failedToken:W?m:null,failureCount:W?B.failureCount??0:0,retryAtMs:0}),Promise.resolve(E).then(ie=>{const fe=ee.get(f);!fe||fe.inflightToken!==m||(ee.set(f,{token:m,value:I(ie),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0}),we())},()=>{const ie=ee.get(f);if(!ie||ie.inflightToken!==m)return;const fe=ie.failedToken===m?(ie.failureCount??0)+1:1,Le=Math.min(rt,ze*2**Math.min(fe-1,8)),Ue=Date.now()+Le;ee.set(f,{...ie,inflightToken:null,failedToken:m,failureCount:fe,retryAtMs:Ue}),it(Ue)}),null},wr=(f,m,b,I)=>{const E=ee.get(f);if(E&&E.token===m&&E.hasSettled)return{value:E.value,status:"ready"};if(_V(f)&&!Jo(f,m)){if(Ki()==="loading")return yn=!0,qi(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(yn)return no(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(Date.now()-Vn<Ve)return yn=!0,no(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"}}if(io())return Ai(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(E?.failedToken===m&&E.inflightToken==null&&(E.retryAtMs??0)>Date.now())return it(E.retryAtMs),E.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!E&&f.startsWith("effInline:")&&Kr(f))return{value:null,status:"pending"};if(!E&&Ql(f,m))return{value:null,status:"pending"};if(!E||E.inflightToken!==m){const W=ba(f,m,b,I);if(W)return{value:W.value,status:"ready"}}const B=ee.get(f);return B?.hasSettled?{value:B.value,status:"stale"}:{value:null,status:"pending"}},jf=f=>{for(const m of ee.keys())f(m)&&ee.delete(m)},wa=f=>{const m=Wr(f),b=kA(f);return new Set([`contentControls:inRange:${m}`,`query:${m}`,...b?[`effInline:${b}`]:[]])},ec=f=>{const m=wa(f);jf(b=>Qo.some(I=>b.startsWith(I))&&!m.has(b));for(const b of O){const I=b.split("\0",1)[0];Qo.some(E=>I.startsWith(E))&&!m.has(I)&&O.delete(b)}},Ei=()=>{const f=_();f!==Yt&&(Jl(),br.reset(),$t={},Yt=f,ee.clear(),Nt=null,De(),te&&clearTimeout(te),te=null,Y=0,U?.timer&&clearTimeout(U.timer),U=null,H=null,C=null,o=null,be=null,O.clear(),_i.clear(),yn=!1,oo&&oo(),oo=null,ro=null,pn(),jt=null)},ks=()=>{const f=Nt!==null;zt+=1,f&&(Nt=Et()),pn()},Ss=()=>{const f=jt===Et();ks(),f&&(un([]),jt=Et()),Kt()},Uf=f=>{if(typeof f!="string"||f.length===0)return Xn("insertText requires a non-empty string.","INVALID_INPUT");if(Wn()==="viewing")return Xn("The document is read-only.","DOCUMENT_READONLY");const m=y(),b=m?.insert;if(!m||typeof b!="function")return Xn("insert is unavailable.");const I=m.selection?.current;if(typeof I!="function")return Xn("selection.current is unavailable.");const E=W=>{const ie=W&&typeof W=="object"?W:null,fe=ie?.selectionTarget??ie?.target??null;return!fe||typeof fe!="object"?Xn("insertText requires a live selection target.","PRECONDITION_FAILED"):Pt(()=>Ms(b.call(m,{type:"text",value:f,target:fe}),Xn("insert failed.")),Xn("insert failed."))};let B;try{B=I.call(m.selection)}catch{return Xn("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Sr(B)?Promise.resolve(B).then(E,()=>Xn("insertText could not resolve the live selection.","PRECONDITION_FAILED")):E(B)},tc=(f,m)=>({payload:f,state:pt,editor:_(),superdoc:t,context:m,ui:S,execute:(b,I)=>bc(b,I),executeAsync:(b,I)=>Lm(b,I),doc:y(),selection:pt.selection,documentMode:Wn(),insertText:Uf}),ti=f=>f==="editing"||f==="suggesting"||f==="viewing"?f:null,Wn=()=>{const f=_(),m=t&&typeof t=="object"?t:null,b=ti(m?.config?.documentMode),I=Pt(typeof m?.getActiveRuntime=="function"?()=>{const W=m.getActiveRuntime();return typeof W?.getSnapshot=="function"?W.getSnapshot():null}:void 0,null),E=ti(I?.documentMode),B=ti(f?.options?.documentMode);return b&&E&&b!==E?b:E??b??B},Iu=()=>{const f=t&&typeof t=="object"?t:null,m=f?.interactionConfig?.comments;if(m&&typeof m.readOnly=="boolean")return m.readOnly===!0;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},Hf=()=>{const f=t&&typeof t=="object"?t:null,m=f?.interactionConfig?.comments;if(m&&typeof m.allowResolve=="boolean")return m.allowResolve===!1;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},Vo=()=>Wn()==="viewing"||Iu(),Ti=f=>f&&typeof f=="object"?f:null,al=(f,m)=>{if(!f)return{...CV,status:m};const b=f.target??null,I=typeof f.text=="string"?f.text:"";return{status:m,empty:f.empty===!0,target:b,selectionTarget:f.selectionTarget??null,activeMarks:Array.isArray(f.activeMarks)?f.activeMarks:[],activeCommentIds:Array.isArray(f.activeCommentIds)?f.activeCommentIds:[],activeChangeIds:Array.isArray(f.activeChangeIds)?f.activeChangeIds:[],quotedText:I}},So=()=>{const f=y()?.selection;return wr("selection",Br(),()=>f?.current?f.current({includeText:!0}):void 0,Ti)},Eu=()=>{const{value:f,status:m}=So();return al(f,m)},ll=()=>{const f=y()?.selection;return f?.current?f.current({includeText:!0}):void 0},nc=f=>{if(f.empty!==!0)return!1;const m=f.selectionTarget,b=m?.start,I=m?.end;return b?.kind==="text"&&I?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===I.blockId&&typeof b.offset=="number"&&b.offset===I.offset},Tu=f=>{const m=x(),b=m?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const I=Ti(Pt(()=>b.call(m),null));if(!I||!nc(I))return;const E=Br(),B=Bo(),W=!!(B&&(B.active>0||B.pending>0));if(W)be=E,Ai();else if(be=null,ba("selection",E,ll,Ti))return;const ie=ee.get("selection"),fe=Array.isArray(I.activeMarks)&&I.activeMarks.length>0?I.activeMarks:Array.isArray(pt.selection.activeMarks)?pt.selection.activeMarks:[],Le=Array.isArray(I.activeCommentIds)?I.activeCommentIds:[],Ue=xV(f),je=ol(pt.selection),Ne=zf(I.selectionTarget)??zf(I.target),Ye=je?.range,He=Ne?.range,Xe=!!(B&&B.active>0&&je&&Ne&&je.blockId===Ne.blockId&&_r(je.story)===_r(Ne.story)&&typeof Ye?.start=="number"&&typeof He?.start=="number"&&Math.abs(He.start-Ye.start)<=2),Ze=Ue!=null||Xe?pt.selection.activeChangeIds.filter(tt=>Ue==null||fa(pt.trackChanges.items).aliasesFor(tt).includes(Ue)):[],ot=Array.isArray(I.activeChangeIds)&&I.activeChangeIds.length>0?I.activeChangeIds:Ze;ee.set("selection",{token:E,value:{...I,activeMarks:fe,activeCommentIds:Le,activeChangeIds:ot},hasSettled:!0,inflightToken:W?null:ie?.inflightToken??null})},_s=async(f=0)=>{const m=y()?.selection,b=m?.current,I=Br();if(typeof b!="function")return ee.set("selection",{token:I,value:null,hasSettled:!0,inflightToken:null}),Kt(),pt.selection;let E;try{E=b.call(m,{includeText:!0}),Sr(E)&&(E=await Promise.resolve(E))}catch{E=null}return J?al(null,"pending"):Br()!==I?f<1?_s(f+1):pt.selection:(ee.set("selection",{token:I,value:Ti(E),hasSettled:!0,inflightToken:null}),Kt(),pt.selection)},xu=f=>{const m=y()?.comments,{value:b,status:I}=wr("comments",Et(),()=>m?.list?m.list():void 0,ie=>ie&&Array.isArray(ie.items)?ie.items:[]),E=b??[],B=f.activeCommentIds;ve&&!E.some(ie=>Gn(ie)===ve)&&(ve=null);const W=ve??B[0]??null;return{status:wu(I,f.status),listStatus:I,items:E,total:E.length,activeIds:B,activeId:W}},Zi=()=>{const f=y()?.trackChanges,m=Et(),b=ee.get("trackChanges:all"),{value:I,status:E}=Nt===m?{value:b?.hasSettled?b.value:null,status:b?.hasSettled?"stale":"pending"}:wr("trackChanges:all",m,()=>{if(!f?.list)return;const B=()=>f.list({in:"all"}),W=typeof w()?.listTrackedChanges=="function",ie=Rn(B);return W?Promise.resolve(ie).then(fe=>{const Le=Xl(fe)?fe:null;return(Array.isArray(Le?.items)?Le.items:[]).some(Ue=>Cu(Ue)==null)?B():fe}):ie},B=>(B&&Array.isArray(B.items)?B.items:[]).map(il).filter(W=>W!=null));return E==="ready"?I:null},rc=f=>{const m=y()?.trackChanges,b=w(),I=typeof b?.listTrackedChanges=="function"?b.listTrackedChanges:null,E=Et(),B=yr(E),W=ee.get("trackChanges"),{value:ie,status:fe}=Nt===E?{value:W?.hasSettled?W.value:null,status:W?.hasSettled?"stale":"pending"}:wr("trackChanges",E,()=>I?Rn(()=>m?.list?.()):m?.list?m.list({in:"all"}):void 0,an=>an&&Array.isArray(an.items)?an.items:[]),Le=(ie??[]).map(il).filter(an=>an!=null).filter(an=>{const Pn=Gn(an);return!Pn||!B?.has(Pn)}),Ue=new Set;for(const an of Le){const Pn=wm(an),Hr=an,Er=Pn.author??Pn.authorEmail??Hr.author??Hr.authorEmail;typeof Er=="string"&&Ue.add(Er)}const je=m?.list?Zi():null,Ne=ue;Ne&&(Ne.story?je&&!je.some(an=>Ui(an,Ne.id,Ne.story))&&$e(null):Le.some(an=>Gn(an)===Ne.id)||$e(null));const Ye=je??Le,He=ku(Ye,Hi(f)),Xe=jt===E?[]:B?f.activeChangeIds.filter(an=>!B.has(an)):f.activeChangeIds,Ze=Xe.map(an=>He.toPublicId(an)??an),ot=ue?.story?ku(Ye,ue.story):fa(Ye),tt=ue?ot.toPublicId(ue.id)??ue.id:null,Bt=PV({selectionIds:Xe,publicIds:Ze,selection:f,bodyItems:Le,allStoryItems:je}),Qt=tt??Bt;return{status:wu(fe,f.status),items:Le,total:Le.length,activeId:Qt,authors:[...Ue]}},oc=f=>{const m=y()?.contentControls,{value:b,status:I}=wr("contentControls",Et(),()=>m?.list?m.list():void 0,ie=>ie&&Array.isArray(ie.items)?ie.items:[]),E=b??[],{ids:B,status:W}=Ru(m,f);return{status:wu(I,W,f.status),items:E,total:E.length,activeId:B[0]??null,activeIds:B}},pi=(f,m)=>{if(!f||typeof f.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=OV(m);if(!b)return{lockModesById:new Map,status:"ready"};const{value:I,status:E}=wr(`contentControls:inRange:${Wr(m)}`,Et(),()=>f.listInRange(b),ie=>ie&&Array.isArray(ie.items)?ie.items:[]),B=I??[],W=new Map;for(const ie of B)typeof ie?.id=="string"&&W.set(ie.id,typeof ie.lockMode=="string"?ie.lockMode:"unlocked");return{lockModesById:W,status:E}},Ru=(f,m)=>{const{lockModesById:b,status:I}=pi(f,m);return{ids:[...b.keys()],status:I}},$f=()=>{const f=t?.fonts;return{options:cj(aj(Pt(f?.getDocumentFontOptions?()=>f.getDocumentFontOptions():void 0,[])),lj(Pt(f?.getFontFamilyOptions?()=>f.getFontFamilyOptions():void 0,[]))),sizeOptions:uj}},cl=()=>{const f=Pt(t?.getZoomState?()=>t.getZoomState():void 0,null),m=typeof f?.value=="number"?f.value:100,b=f?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:m,min:typeof f?.min=="number"?f.min:10,max:typeof f?.max=="number"?f.max:100}},Gf=()=>Pt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",ul=()=>{const f=_();return{ready:f!=null,mode:Wn(),dirty:f?!!f.isDirty:!1}},jo=f=>{const m=f.quotedText;if(typeof m!="string"||m.length===0)return null;const b=_u(f);if(b.length===0||!Yl(b.map(B=>B.blockId)))return null;const I=f.target,E=b.length===1?Co(b[0].blockId,I?.story):void 0;return{select:{type:"text",pattern:m,mode:"contains",caseSensitive:!0},...E?{within:E}:{},require:"any"}},Cr=f=>{const m=y()?.query;if(typeof m?.match!="function")return null;const b=jo(f);if(!b)return null;const{value:I}=wr(`query:${Wr(f)}`,Et(),()=>m.match(b),E=>E&&typeof E=="object"?E:null);return SA(I,f)},Mu=f=>{const m=x(),b=new Set(Nr(f));if(b.size===0)return{};const I=m?.readMountedProjectionBlocksByIds,E=m?.readMountedProjectionBlocks;if(typeof I!="function"&&typeof E!="function")return{};const B=Pt(()=>{if(typeof I!="function")return E.call(m);const Xe=$i(f);return Xe?I.call(m,[...b],Xe):I.call(m,[...b])},null);if(!Array.isArray(B))return{};const W=h2(B),ie=Xe=>{const Ze={},ot=d2(Xe.fontFamily);ot&&(Ze.fontFamily=ot);const tt=WV(Xe.fontSize);return tt&&(Ze.fontSize=tt),typeof Xe.color=="string"&&Xe.color.trim()!==""&&(Ze.color=Xe.color.trim().toUpperCase()),typeof Xe.highlight=="string"&&Xe.highlight.trim()!==""&&(Ze.highlight=Xe.highlight.trim().toUpperCase()),Ze},fe=ol(f),Le=fe&&typeof fe.range?.start=="number"?fe.range.start:null;if(fe&&Le!==null&&b.has(fe.blockId)){const Xe=W.find(ot=>Zl(ot,fe.blockId)),Ze=Xe&&Array.isArray(Xe.runs)?Xe.runs:null;if(Ze&&Ze.length>0&&Ze.every(ot=>ot?.kind==="text"||ot?.kind==="tab")){let ot=0,tt=null;for(const Bt of Ze){const Qt=km(Bt);if(Le>=ot&&Le<ot+Qt){tt=Bt;break}ot+=Qt}if(!tt){for(let Bt=Ze.length-1;Bt>=0&&!tt;Bt-=1)Ze[Bt]?.kind==="text"&&(tt=Ze[Bt]);tt??=Ze[Ze.length-1]??null}return tt?ie(tt):{}}}const Ue=_u(f);if(Ue.length>0){const Xe=new Set,Ze=new Set;let ot=!1,tt=!0;for(const Bt of Ue){const Qt=W.find(Hr=>Zl(Hr,Bt.blockId));if(!Qt)return{};const an=Array.isArray(Qt.runs)?Qt.runs:[];if(an.length===0)continue;if(!an.every(Hr=>Hr?.kind==="text"||Hr?.kind==="tab")){tt=!1;break}let Pn=0;for(const Hr of an){const Er=km(Hr),Tr=Pn,Lr=Pn+Er;if(Tr<Bt.end&&Lr>Bt.start){ot=!0;const $o=ie(Hr);$o.fontFamily&&Xe.add($o.fontFamily),$o.fontSize&&Ze.add($o.fontSize)}Pn=Lr}}if(tt&&ot){const Bt={};return Xe.size===1&&(Bt.fontFamily=[...Xe][0]),Ze.size===1&&(Bt.fontSize=[...Ze][0]),Bt}}const je=new Set,Ne=new Set;let Ye=!1;for(const Xe of W){if(![...b].some(ot=>Zl(Xe,ot)))continue;const Ze=Array.isArray(Xe.runs)?Xe.runs:[];for(const ot of Ze){if(ot?.kind!=="text")continue;Ye=!0;const tt=ie(ot);tt.fontFamily&&je.add(tt.fontFamily),tt.fontSize&&Ne.add(tt.fontSize)}}if(!Ye)return{};const He={};return je.size===1&&(He.fontFamily=[...je][0]),Ne.size===1&&(He.fontSize=[...Ne][0]),He},dl=f=>{const m=x(),b=new Set(Nr(f));if(b.size===0)return{};const I=m?.readMountedProjectionBlocksByIds,E=m?.readMountedProjectionBlocks;if(typeof I!="function"&&typeof E!="function")return{};const B=Pt(()=>{if(typeof I!="function")return E.call(m);const He=$i(f);return He?I.call(m,[...b],He):I.call(m,[...b])},null);if(!Array.isArray(B))return{};const W=h2(B),ie=He=>({bold:He.bold===!0,italic:He.italic===!0,underline:He.underline!=null,strikethrough:He.strike===!0}),fe=He=>{const Xe={};for(const Ze of Vf){const ot=He[Ze];ot.size===1&&(Xe[Ze]=[...ot][0])}return Xe},Le=ol(f),Ue=Le&&typeof Le.range?.start=="number"?Le.range.start:null;if(Le&&Ue!==null&&b.has(Le.blockId)){const He=W.find(Ze=>Zl(Ze,Le.blockId)),Xe=He&&Array.isArray(He.runs)?He.runs:null;if(Xe&&Xe.length>0&&Xe.every(Ze=>Ze?.kind==="text"||Ze?.kind==="tab")){let Ze=0,ot=null;for(const tt of Xe){const Bt=km(tt);if(Ue>=Ze&&Ue<Ze+Bt){ot=tt;break}Ze+=Bt}if(!ot){for(let tt=Xe.length-1;tt>=0&&!ot;tt-=1)Xe[tt]?.kind==="text"&&(ot=Xe[tt]);ot??=Xe[Xe.length-1]??null}return ot?ie(ot):{}}}const je=_u(f);if(je.length>0){const He={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Xe=!1,Ze=!0;for(const ot of je){const tt=W.find(an=>Zl(an,ot.blockId));if(!tt)return{};const Bt=Array.isArray(tt.runs)?tt.runs:[];if(Bt.length===0)continue;if(!Bt.every(an=>an?.kind==="text"||an?.kind==="tab")){Ze=!1;break}let Qt=0;for(const an of Bt){const Pn=km(an),Hr=Qt,Er=Qt+Pn;if(Hr<ot.end&&Er>ot.start){Xe=!0;const Tr=ie(an);for(const Lr of Vf)He[Lr].add(Tr[Lr])}Qt=Er}}if(Ze&&Xe)return fe(He)}const Ne={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ye=!1;for(const He of W){if(![...b].some(Ze=>Zl(He,Ze)))continue;const Xe=Array.isArray(He.runs)?He.runs:[];for(const Ze of Xe){if(Ze?.kind!=="text")continue;Ye=!0;const ot=ie(Ze);for(const tt of Vf)Ne[tt].add(ot[tt])}}return Ye?fe(Ne):{}},Ca=(f,m)=>{if(m.fontFamily!==void 0&&m.fontSize!==void 0&&m.color!==void 0&&m.highlight!==void 0)return{values:m,effectiveUniformityStatus:"ready"};const b=Mu(f),I={...b.fontFamily!==void 0?{fontFamily:b.fontFamily}:{},...b.fontSize!==void 0?{fontSize:b.fontSize}:{},...b.color!==void 0?{color:b.color}:{},...b.highlight!==void 0?{highlight:b.highlight}:{},...m};if(!f.empty&&(I.fontFamily===void 0||I.fontSize===void 0)){const E=ic(f);return E.values&&(I.fontFamily===void 0&&E.values.fontFamily!==void 0&&(I.fontFamily=E.values.fontFamily),I.fontSize===void 0&&E.values.fontSize!==void 0&&(I.fontSize=E.values.fontSize)),{values:I,effectiveUniformityStatus:E.status}}return{values:I,effectiveUniformityStatus:"ready"}},Lu=["fontFamily","fontSize","bold","italic","underline","strikethrough"],mi=f=>{const m=f.selectionTarget;if(!m)return{value:null,status:"ready"};const b=vr(y(),"format.readEffectiveInlineUniformity");if(!b)return{value:null,status:"ready"};const I=kA(f)??Wr(f);return wr(`effInline:${I}`,Et(),()=>b({target:m,offsetSpace:"selection",keys:Lu}),E=>E&&typeof E=="object"?E:null)},ic=f=>{const{value:m,status:b}=mi(f);if(!m||m.success!==!0)return{values:null,status:b};const I=m.values,E=B=>{const W=I?.[B];if(!(!W||W.state!=="uniform"||typeof W.value!="string"))return B==="fontFamily"?d2(W.value):W.value};return{values:{fontFamily:E("fontFamily"),fontSize:E("fontSize")},status:b}},Pu=f=>{const{value:m,status:b}=mi(f);if(!m||m.success!==!0)return{values:null,status:b};const I=m.values,E={};for(const B of Vf){const W=I?.[B];W?.state==="uniform"&&(W.value==="true"||W.value==="false")&&(E[B]=W.value==="true")}return{values:E,status:b}},Du=(f,m)=>{const b=f.activeMark;if(!b||!Vf.includes(b))return null;const I=b,E=dl(m)[I];if(E!==void 0)return E;const{values:B}=Pu(m),W=B?.[I];return W!==void 0?W:null},sc=async f=>{const m=f.selectionTarget;if(!m)return null;const b=vr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const I=await Promise.resolve(b({target:m,offsetSpace:"selection"}));return I&&typeof I=="object"&&I.success===!0?I:null}catch{return null}},Ou=(f,m,b)=>{const I=b.values;for(const E of["fontFamily","fontSize"]){if(m[E]!==void 0)continue;const B=I?.[E];B?.state==="uniform"&&typeof B.value=="string"?f[E]=E==="fontFamily"?d2(B.value):B.value:delete f[E]}},ac=f=>Ca(f,_A(Cr(f),f)),fl=f=>ac(f).values,Fu=async f=>{const m=y()?.query,b=jo(f);if(typeof m?.match!="function"||!b)return fl(f);try{const I=await Promise.resolve(m.match(b)),E=_A(SA(I&&typeof I=="object"?I:null,f),f),B=Ca(f,E);if(B.effectiveUniformityStatus!=="ready"&&(E.fontFamily===void 0||E.fontSize===void 0)){const W=await sc(f);W&&Ou(B.values,E,W)}return B.values}catch{return fl(f)}},As=async f=>{const m=y();if(m)return typeof m.getNode=="function"?await Promise.resolve(m.getNode(f)):await Promise.resolve(m.getNodeById?.({nodeId:f.nodeId,nodeType:f.nodeType}))},lc=f=>{const m=y()?.query;if(typeof m?.match!="function")return"ready";const b=jo(f);if(!b)return"ready";const{status:I}=wr(`query:${Wr(f)}`,Et(),()=>m.match(b),E=>E&&typeof E=="object"?E:null);return I},Nu=f=>{const m=ac(f),b=m.values;if(f.empty)return m;const I=pa(f);return I?f.status==="ready"&&lc(f)==="ready"&&m.effectiveUniformityStatus==="ready"?(C={key:I,values:b},m):C&&C.key===I?{...m,values:{...C.values,...b}}:m:m},Bu=f=>{const m=y(),b=Nu(f),I=b.values;f.status==="ready"&&!f.empty&&lc(f)==="ready"&&b.effectiveUniformityStatus==="ready"&&(v=I,k=`${Kl(f)}:${Et()}`);const E=m?.contentControls,{lockModesById:B}=pi(E,f),W={};for(const ie of ae())W[ie]=uc(ie,m,f,I,B);return W},xi=f=>f?dt.operationUnavailable:_()?dt.documentApiUnavailable:dt.notReady,Ri=f=>f==="contentLocked"||f==="sdtContentLocked",Is=f=>{for(const m of f.values())if(Ri(m))return dt.contentControlLocked},zu=(f,m,b,I,E)=>{if(!m)return f.scope==="all"?dt.bulkDecisionsDisabled:xi(E);if(b)return dt.documentReadonly;if(f.scope!=="all"&&I.activeChangeIds.length===0)return dt.selectionRequired},Vu=f=>{const m=x(),b=Pt(typeof m?.getCapabilities=="function"?()=>m.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(I=>I?.command===f||I?.id===f)??null;if(b&&typeof b=="object"){const I=b[f];return I&&typeof I=="object"?I:null}return null},cc=(f,m)=>{if(f.scope!=="all"||typeof m?.[`${f.kind}All`]=="function")return;const b=Vu(`trackedChanges.${f.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return dt.bulkDecisionsDisabled},uc=(f,m,b,I,E=new Map)=>{if(he.has(f))return cn({supported:!0,enabled:!0,...Pt(he.get(f).getState?()=>he.get(f).getState(tc(void 0)):void 0,{})},"custom");const B=Wn()==="viewing",W=hA(f);if(W&&typeof T()?.lists?.apply=="function"){const Ye=Q(),He=typeof Ye?.shippedStatus=="string"?Ye.shippedStatus:null,Xe=He!=="not-shipped"&&He!=="disabled";return cn({enabled:Xe&&(typeof Ye?.enabled=="boolean"?Ye.enabled:!0),active:(Xe?K(Ye):null)===W,supported:Xe,value:Ye?.value},"builtin")}const ie=Sm(f);if(ie){const Ye=m?.trackChanges,He=typeof Ye?.decide=="function"||typeof Ye?.[ie.kind]=="function",Xe=typeof Ye?.decide=="function"||typeof Ye?.[`${ie.kind}All`]=="function",Ze=ie.scope==="all"?Xe:He,ot=cc(ie,Ye)??zu(ie,Ze,Vo(),b,m);return cn({enabled:ot==null,active:!1,supported:Ze,reason:ot},"builtin")}if(f==="copy-format")return Wn()==="viewing"?cn({supported:!0,enabled:!1,active:!1},"builtin"):_()?cn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):cn({supported:!0,enabled:!1,active:!1,reason:dt.notReady},"builtin");const fe=gu(f);if(!fe)return cn({enabled:!1,active:!1,supported:!1,reason:dt.commandUnsupported},"unsupported");if(fe.disposition!=="routed")return cn({enabled:!1,active:!1,supported:!1,reason:fe.reason??dt.commandUnsupported},fe.disposition==="unsupported"?"unsupported":"builtin");if(fe.instanceRoute)return Zf(fe);if(fe.table)return M(fe,m,B);if(fe.inline?.kind==="clear"){if(fe.mutates&&B)return cn({enabled:!1,active:!1,supported:!0,reason:dt.documentReadonly},"builtin");const Ye=Is(E);if(Ye)return cn({enabled:!1,active:!1,supported:!0,reason:Ye},"builtin");const He=Nr(b).length>0||Au(b)!=null;return cn({enabled:He,active:!1,supported:!0,reason:He?void 0:dt.selectionRequired},"builtin")}const Le=fe.docRoute;if(!Le)return cn({enabled:!1,active:!1,supported:!1,reason:dt.commandUnsupported},"unsupported");if(vr(m,Le)==null)return cn({enabled:!1,active:!1,supported:!1,reason:xi(m)},"builtin");const Ue=se(f);if(Ue){const Ye=Ue.shippedStatus,He=Ye!=="not-shipped"&&Ye!=="disabled",Xe=typeof Ue.enabled=="boolean"?Ue.enabled:!0,Ze=f==="undo"||f==="redo",ot=Ze&&Ue.historyResolved===!1,tt=Ze&&He&&Xe===!1&&Ue.reason===null&&!ot,Bt=Ue.reason===void 0?void 0:tt?dt.historyEmpty:ot?dt.notReady:s2(Ue.reason,dt.commandUnsupported);return fe.mutates&&B?cn({enabled:!1,active:!1,supported:He,reason:dt.documentReadonly},"builtin"):cn({enabled:He&&Xe,active:!1,supported:He,reason:Bt},"builtin")}const je=Es(fe,m,b),Ne=Uu(fe,m,b,I);if(fe.list?.mode==="indent"||fe.list?.mode==="outdent")return Yf(fe,m,B,b,je,Ne);if(fe.list?.mode==="toggle-seed")return Xf(fe,m,B,b,je,Ne);if(fe.mutates&&B)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:dt.documentReadonly},"builtin");if(fe.inline&&!Au(b)){const Ye=Is(E);return cn(Ye?{enabled:!1,active:je,supported:!0,value:Ne,reason:Ye}:Nr(b).length>0&&typeof x()?.setPendingInlineFormat=="function"?{enabled:!0,active:je,supported:!0,value:Ne}:{enabled:!1,active:je,supported:!0,value:Ne,reason:dt.rangeSelectionRequired},"builtin")}if((fe.blockParagraph||fe.list)&&Nr(b).length===0)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:dt.selectionRequired},"builtin");if(fe.link&&!je&&c2(b).length===0&&!ol(b))return cn({enabled:!1,active:je,supported:!0,reason:dt.rangeSelectionRequired},"builtin");if(fe.inline){const Ye=Is(E);if(Ye)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:Ye},"builtin")}return cn({enabled:!0,active:je,supported:!0,value:Ne},"builtin")};function ju(f,m){const b=f.address?.anchor,I=b?.start,E=b?.end,B=typeof I?.blockId=="string"?I.blockId:null,W=typeof E?.blockId=="string"?E.blockId:null;if(!B||!W)return!1;const ie=typeof I?.offset=="number"?I.offset:null,fe=typeof E?.offset=="number"?E.offset:null;if(ie==null||fe==null)return!1;const Le=m.target,Ue=Le&&Array.isArray(Le.segments)?Le.segments:[];for(const je of Ue){const Ne=typeof je?.blockId=="string"?je.blockId:null;if(!Ne)continue;const Ye=je.range,He=typeof Ye?.start=="number"?Ye.start:null,Xe=typeof Ye?.end=="number"?Ye.end:null;if(!(He==null||Xe==null)){if(B!==W){if(Ne===B&&Xe>ie||Ne===W&&He<fe)return!0;continue}if(Ne===B){if(He===Xe){if(He>=ie&&He<=fe)return!0;continue}if(Math.max(He,ie)<Math.min(Xe,fe))return!0}}}return!1}const dc=(f,m)=>{const b=f?.hyperlinks;if(!b||typeof b.list!="function")return null;const I=Nr(m);if(!Yl(I))return null;for(const E of I){const B={kind:"block",nodeType:"paragraph",nodeId:E},{value:W}=wr(`hyperlinks:${E}`,Et(),()=>b.list({within:B}),fe=>fe&&typeof fe=="object"?fe:null),ie=(W&&Array.isArray(W.items)?W.items:[]).find(fe=>ju(fe,m));if(ie)return ie}return null},Es=(f,m,b)=>{if(f.link)return dc(m,b)!=null;if(f.list?.mode==="toggle-seed"&&f.list.seed)return $u(m,b)===f.list.seed;const I=$(f);if(I!==null)return I;const E=r.get(f.id),B=pa(b);if(B&&E?.selectionSignature===B)return E.active;const W=Du(f,b);return W!==null?W:dj(f,b)},Uu=(f,m,b,I)=>{if(f.inline&&u2(f.inline.key)){const E=R(f);if(E!==void 0)return E;const B=I[f.inline.key];if(B!==void 0)return B;const W=pa(b),ie=W?n.get(f.inline.key):void 0;if(W&&ie?.selectionSignature===W)return ie.value}if(f.id==="linked-style"){const{style:E}=Te(b,Se().cache);return!E.styleId||E.mixed?void 0:{styleId:E.styleId,styleName:E.styleName}}if(f.id==="text-align")return hc(m,b);if(f.id==="link")return mc(m,b)??void 0},fc=(f,m,b)=>{const I=f?.lists;if(!I)return{value:null,status:"ready"};const E=b.storyType==="body",B=typeof I.getStateInStory=="function"?()=>I.getStateInStory({target:ha(m),story:b}):E&&typeof I.getState=="function"?()=>I.getState({target:ha(m)}):null;if(!B)return{value:null,status:"ready"};const{value:W,status:ie}=wr(`lists:${_r(b)}:${m}`,Et(),B,fe=>fe&&typeof fe=="object"?fe:null);return{value:W?.success===!0?W:null,status:ie}},Wf=(f,m,b)=>fc(f,m,b).value,Hu=(f,m,b)=>{const I=Wf(f,m,b);return!I||I.isListItem!==!0?null:I.seed==="bullet"||I.seed==="ordered"?I.seed:null},Uo=(f,m,b)=>{const I=fc(f,m,b),E=I.value;return{value:E&&typeof E.isListItem=="boolean"?E.isListItem:null,status:I.status}},$u=(f,m)=>{const b=Nr(m);if(b.length===0||!Yl(b))return null;const I=Hi(m),E=Hu(f,b[0],I);if(E!=="bullet"&&E!=="ordered")return null;for(const B of b.slice(1))if(Hu(f,B,I)!==E)return null;return E},hl=(f,m,b)=>{if(!f)return{value:null,status:"ready",refreshing:!1};const I=_r(b),E=I==="story:body";if(E&&typeof f.getNodeById!="function")return{value:null,status:"ready",refreshing:!1};if(!E&&typeof f.getNode!="function")return{value:null,status:"ready",refreshing:!1};const B=`node:${I}:${m}`,W=Et(),ie=wr(B,W,()=>E?f.getNodeById({nodeId:m,nodeType:"paragraph"}):f.getNode(Co(m,b)),Le=>Le&&typeof Le=="object"?Le:null),fe=ee.get(B);return{...ie,refreshing:ie.status==="stale"&&fe?.inflightToken===W&&fe.failedToken!==W}},pl=f=>f==="left"||f==="center"||f==="right"||f==="justify"?f:void 0,Gu=f=>f==="start"||f==="end"||f==="distributed"||f==="numTab"||f==="lowKashida"||f==="mediumKashida"||f==="highKashida"||f==="thaiDistribute",ka=(f,m)=>{const b=x(),I=b?.readMountedProjectionBlocksByIds;if(typeof I!="function")return null;const E=$i(f),B=Pt(()=>E?I.call(b,[...m],E):I.call(b,[...m]),null);if(!Array.isArray(B))return new Map;const W=h2(B),ie=new Map;for(const fe of m){const Le=W.find(Ye=>Zl(Ye,fe));if(!Le)continue;const Ue=Le.attrs,je=pl(Ue?.alignment),Ne=S9(Ue);ie.set(fe,je??(Ne==="rtl"?"right":"left"))}return ie},Wu=(f,m,b,I)=>{const{value:E,status:B,refreshing:W}=hl(f,m,b),ie=I?.get(m);if(B==="pending")return ie?{status:"uniform",value:ie}:{status:"pending"};if(B==="stale"&&!W)return{status:"pending"};if(B==="stale"&&ie)return{status:"uniform",value:ie};if(B==="stale"&&I&&!ie)return{status:"unavailable"};if(!E)return{status:"unavailable"};const fe=E.node;if(!fe)return{status:"unavailable"};const Le=fe.kind;if(Le!=="paragraph"&&Le!=="heading")return{status:"unavailable"};const Ue=fe[Le];if(!Ue||typeof Ue!="object")return{status:"unavailable"};const je=Ue.props?.alignment;if(je==null)return ie?{status:"uniform",value:ie}:{status:"unavailable"};const Ne=pl(je);return Ne?{status:"uniform",value:Ne}:Gu(je)&&ie?{status:"uniform",value:ie}:{status:"unavailable"}},Kf=(f,m)=>{const b=Nr(m);if(b.length===0||!Yl(b))return{status:"unavailable"};const I=Hi(m),E=ka(m,b),B=Wu(f,b[0],I,E);if(B.status!=="uniform")return B;for(const W of b.slice(1)){const ie=Wu(f,W,I,E);if(ie.status!=="uniform")return ie;if(ie.value!==B.value)return{status:"mixed"}}return B},Ku=f=>{const m=Nr(f);return m.length===0?null:`${_r(Hi(f))}:${m.join(",")}`},hc=(f,m)=>{const b=Kf(f,m),I=b.status==="uniform"?b.value:void 0,E=o;if(!E)return I;const B=Ku(m);return B&&B!==E.selectionSignature?(o=null,I):!B||!E.settled?E.value:b.status!=="pending"?(o=null,I):E.value},pc=(f,m)=>{const b=pl(m),I=Ku(f),E=Nr(f);if(!b||!I||E.length===0)return null;const B=++i;return o={selectionSignature:I,value:b,generation:B,settled:!1,canReconcile:Yl(E)},Kt(),B},qu=(f,m)=>{if(f==null)return;const b=o;if(!(!b||b.generation!==f)){if(!ko(m)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},ni=async(f,m,b)=>{const I=f?.lists;if(!I)return null;try{const E=b.storyType==="body",B=typeof I.getStateInStory=="function"?await I.getStateInStory({target:ha(m),story:b}):E&&typeof I.getState=="function"?await I.getState({target:ha(m)}):null,W=B&&typeof B=="object"?B:null;return!W||W.success!==!0||typeof W.isListItem!="boolean"?null:W.isListItem}catch{return null}},Yr=(f,m,b)=>{const I={resolved:!1,seed:null},E=f?.lists;if(!E)return I;const B=b.storyType==="body",W=typeof E.getStateInStory=="function"?()=>E.getStateInStory({target:ha(m),story:b}):B&&typeof E.getState=="function"?()=>E.getState({target:ha(m)}):null;if(!W)return I;const ie=fe=>{const Le=fe&&typeof fe=="object"?fe:null;return!Le||Le.success!==!0||typeof Le.isListItem!="boolean"?I:{resolved:!0,seed:Le.isListItem===!0&&(Le.seed==="bullet"||Le.seed==="ordered")?Le.seed:null}};try{const fe=W();return Sr(fe)?Promise.resolve(fe).then(ie,()=>I):ie(fe)}catch{return I}},qf=async(f,m,b)=>{if(!f)return null;try{const I=!b||b.storyType==="body",E=b&&typeof f.getNode=="function"?await f.getNode(Co(m,b)):I&&typeof f.getNodeById=="function"?await f.getNodeById({nodeId:m,nodeType:"paragraph"}):null;return NV(E&&typeof E=="object"?E:null)}catch{return null}},Yf=(f,m,b,I,E,B)=>{if(f.mutates&&b)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.documentReadonly},"builtin");const W=Nr(I);if(W.length===0)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.selectionRequired},"builtin");const ie=f.docRoute?vr(m,f.docRoute):null,fe=vr(m,"format.paragraph.setIndentation"),Le=vr(m,"format.paragraph.clearIndentation"),Ue=f.list?.mode,je=Ue==="indent"?fe!=null:fe!=null||Le!=null,Ne=Hi(I);let Ye=null;if(Ne.storyType!=="body"){Ye=[];for(const He of W){const{value:Xe,status:Ze}=Uo(m,He,Ne);if(Xe===null)return Ze!=="ready"&&(ie!=null||je)?cn({enabled:!0,active:E,supported:!0,value:B},"builtin"):cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin");Ye.push(Xe)}}if(Ye?.some(He=>He===!0)){const He=Ue==="indent"?"lists.indentRange":"lists.outdentRange",Xe=Wn()!=="suggesting"&&Ye.every(ot=>ot===!0)&&vr(m,He)!=null,Ze=Ue==="outdent"&&vr(m,"lists.outdentInStory")!=null;if(!Xe&&!Ze)return cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")}for(const[He,Xe]of W.entries()){const Ze=Ye?{value:Ye[He]??null,status:"ready"}:Uo(m,Xe,Ne),ot=Ze.value;if(ot===!0){if(ie!=null)return cn({enabled:!0,active:E,supported:!0,value:B},"builtin");continue}if(ot===!1&&je){if(Ne.storyType!=="body"&&typeof m?.getNode!="function")continue;return cn({enabled:!0,active:E,supported:!0,value:B},"builtin")}if(ot===null)return Ze.status!=="ready"&&(ie!=null||je)?cn({enabled:!0,active:E,supported:!0,value:B},"builtin"):cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")}return cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")},Xf=(f,m,b,I,E,B)=>{if(f.mutates&&b)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.documentReadonly},"builtin");const W=Nr(I);if(W.length===0)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.selectionRequired},"builtin");const ie=Hi(I),fe=m?.lists;if(!(typeof fe?.getStateInStory=="function"||ie.storyType==="body"&&typeof fe?.getState=="function"))return cn({enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");if(!Yl(W))return cn(ie.storyType==="body"&&vr(m,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Le=W.map(Ye=>fc(m,Ye,ie));if(Le.some(({status:Ye})=>Ye!=="ready"))return cn({enabled:!0,active:E,supported:!0,value:B},"builtin");if(Le.some(({value:Ye})=>Ye===null))return cn({enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Ue=f.list?.seed,je=Le.every(({value:Ye})=>Ye?.isListItem===!0&&Ye.seed===Ue);if(ie.storyType==="body")return cn(!je||vr(m,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Ne=vr(m,"lists.removeInStory");return cn(je&&Ne?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin")},mc=(f,m)=>{const b=dc(f,m)?.properties?.href;return typeof b=="string"?b:null},Zf=f=>{if(!_())return cn({enabled:!1,active:!1,supported:!1,reason:dt.notReady},"builtin");const m=f.instanceRoute;return typeof t?.[m]!="function"?cn({enabled:!1,active:!1,supported:!1,reason:dt.operationUnavailable},"builtin"):cn({enabled:!0,active:A(f),supported:!0,value:Z(f)},"builtin")},A=f=>{const m=t?.config??void 0;return f.valueFrom==="ruler"?!!m?.rulers:f.valueFrom==="formattingMarks"?!!m?.layoutEngineOptions?.showFormattingMarks:!1},M=(f,m,b)=>{if(b)return cn({enabled:!1,active:!1,supported:!0,reason:dt.documentReadonly},"builtin");const I=Be();return I!=null&&(!f.table.requiresCell||I.cellNodeId!=null)?(f.docRoute?vr(m,f.docRoute):null)==null?cn({enabled:!1,active:!1,supported:!1,reason:xi(m)},"builtin"):cn({enabled:!0,active:!1,supported:!0},"builtin"):cn({enabled:!1,active:!1,supported:!0,reason:dt.tableContextUnavailable},"builtin")},Z=f=>{if(f.valueFrom==="zoom")return cl().value;if(f.valueFrom==="documentMode")return Wn();if(f.valueFrom==="measurementUnit")return Gf();if(f.valueFrom==="ruler"||f.valueFrom==="formattingMarks")return A(f)},oe=(f,m)=>f.id==="zoom"?typeof m=="number"&&Number.isFinite(m)&&m>0:f.id==="document-mode"?m==="editing"||m==="suggesting"||m==="viewing":f.id==="measurement-unit"?m==="in"||m==="cm":!0,ae=()=>[...new Set([...kN,...he.keys()])],pe="Normal",le={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},ce=f=>{const m=y()?.styles;return!m||typeof m.getCatalog!="function"?{value:null,status:"ready"}:wr(`styles:catalog:${JSON.stringify(f??{})}`,Et(),()=>m.getCatalog(f),b=>b&&typeof b=="object"?b:null)},Se=()=>{const f=ce({includePreview:!0});if(!f.value)return{cache:null,status:f.status};const m=ce({view:"quickGallery",includePreview:!0}),b=m.value?m.value.items:f.value.styles.filter(E=>E.visibility.quickGallery),I=new Map;for(const E of f.value.styles)I.set(E.id,E);return{cache:{full:f.value,quickGallery:b,byId:I},status:wu(f.status,m.status)}},Me=(f,m,b)=>{const{value:I,status:E}=hl(f,m,b);if(!I)return{ok:!1,styleRef:null,status:E};const B=I.node;if(!B||typeof B!="object")return{ok:!1,styleRef:null,status:E};const W=B.kind,ie=typeof W=="string"?B[W]:void 0,fe=ie&&typeof ie=="object"?ie.styleRef:void 0;return{ok:!0,styleRef:typeof fe=="string"&&fe.length>0?fe:null,status:E}},Te=(f,m)=>{const b=[],I=y();if(!I)return b.push({severity:"warning",code:"active-style-unavailable",message:"Active paragraph style is unavailable: the Document API is not reachable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};const E=Nr(f);if(E.length===0)return b.push({severity:"info",code:"active-style-no-selection",message:"No paragraph block is resolvable from the current selection; active paragraph style is unavailable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};if(!Yl(E))return b.push({severity:"info",code:"active-style-selection-too-large",message:"Active paragraph style is unavailable for a large multi-paragraph selection."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};const B=m?.full.defaults.paragraphStyleId??(m?pe:null),W=new Set;let ie=0,fe=0,Le=0,Ue="ready";const je=Hi(f);for(const He of E){const Xe=Me(I,He,je);if(Ue=wu(Ue,Xe.status),!Xe.ok){fe+=1;continue}if(!Xe.styleRef&&!B){Le+=1;continue}const Ze=Xe.styleRef??B;if(!Ze){Le+=1;continue}ie+=1,W.add(Ze)}if(ie===0){const He=Le>0&&fe===0;return b.push({severity:"warning",code:He?"active-style-default-unavailable":"active-style-read-failed",message:He?"Selected paragraphs have no explicit style and the style catalogue is unavailable, so the document default cannot be resolved.":"Could not read the paragraph style of any selected block; active paragraph style is unavailable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ue}}const Ne=fe+Le;if(Ne>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${ie} of ${ie+Ne} selected blocks; ${Ne} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ue};if(W.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:Ue};const Ye=[...W][0];return{style:{styleId:Ye,styleName:m?.byId.get(Ye)?.name??null,mixed:!1,diagnostics:b},status:Ue}},Fe=f=>{if(!_())return le;const{cache:m,status:b}=Se(),{style:I,status:E}=Te(f,m);let B;return m?B=I.diagnostics.length===0?m.full.diagnostics:[...m.full.diagnostics,...I.diagnostics]:B=[{severity:"warning",code:"catalog-unavailable",message:"The style catalogue is unavailable: the Document API styles surface is not reachable (e.g. viewing mode or a worker-backed editor)."},...I.diagnostics],{ready:!0,status:wu(b,E,f.status),catalogRevision:m?.full.revision??null,quickGallery:m?.quickGallery??[],activeParagraphStyleId:I.styleId,activeParagraphStyleName:I.styleName,mixedSelection:I.mixed,sourceStatus:m?.full.sourceStatus??null,diagnostics:B}},Ge=()=>{const f=Wn(),m=Eu();m.status==="ready"&&ec(m),V(m);const b=pa(m);for(const[I,E]of r)(!b||E.selectionSignature!==b||E.settled&&m.status==="ready")&&r.delete(I);return{ready:_()!=null,documentMode:f,document:ul(),selection:m,toolbar:{context:f,commands:Bu(m),copyFormatActive:h.mode!=="idle"},comments:xu(m),trackChanges:rc(m),contentControls:oc(m),zoom:cl(),fonts:$f(),styles:Fe(m)}},ct=f=>{const m=pa(f);m&&a&&m!==a&&(n.clear(),r.clear()),m&&(a=m)};let et=null,kt=null,ht=null,Ot=null,on=!1;const At=()=>{if(J||on)return;on=!0;const f=()=>{on&&(on=!1,!J&&Kt())};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},hr=()=>{const f=T();if(f!==ht&&(Ot&&(Ot(),Ot=null),ht=f,!(!f||typeof f.subscribe!="function")))try{const m=f.subscribe(()=>At());typeof m=="function"&&(Ot=m)}catch{ht=null}};let Xt=null,Mt=null,jn=null,pr=null,er=null,zr=null;const Lo=()=>{const f=_()?.host,m=Pt(f?.getHandles?()=>f.getHandles():void 0,null)?.editing?.selection;return m&&typeof m.subscribe=="function"?m:null},lt=()=>{const f=Lo();if(f!==et&&(kt&&(kt(),kt=null),et=f,!!f))try{const m=f.subscribe(b=>{_t+=1,Tu(b),Kt()});typeof m=="function"&&(kt=m)}catch{et=null}},An=()=>{const f=_()?.host,m=Pt(f?.getHandles?()=>f.getHandles():void 0,null)?.review;return m&&typeof m.subscribe=="function"?m:null},Xr=f=>f?typeof f.getActiveReviewTarget=="function"?Pt(()=>f.getActiveReviewTarget(),null):typeof f.getSnapshot=="function"?Pt(()=>f.getSnapshot(),null)?.activeReviewTarget??null:null:null;let so=0;const Vr=(f,m)=>{const b=(m&&typeof m=="object"?m:null)?.lastInteractionRejection;if(so>0&&f==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const I=f&&typeof f=="object"?f:null;let E=null;if(I?.entityType==="trackedChange"&&typeof I.entityId=="string"&&I.entityId.length>0){const B=I.entityId,W=I.story&&typeof I.story=="object"?I.story:void 0,ie=Zi(),fe=(ie?W?ku(ie,W).toPublicId(B):fa(ie).toPublicId(B):null)??B,Le=W&&_r(W)!==_r(null)?W:void 0;E={id:fe,...Le?{story:Le}:{},...typeof I.paintedEntityId=="string"&&I.paintedEntityId.length>0?{paintedEntityId:I.paintedEntityId}:fe!==B?{paintedEntityId:B}:{}}}return f==null&&E==null&&ue!=null&&Tt(ue)||st(ue,E)?!1:($e(E),!0)},Ts=()=>{const f=An();if(f===Xt)return;if(Mt&&(Mt(),Mt=null),Xt=f,!f){Vr(null);return}let m=!0;try{const b=f.subscribe(I=>{const E=I&&typeof I=="object"?I:null,B=E&&Object.prototype.hasOwnProperty.call(E,"activeReviewTarget")?E.activeReviewTarget:Xr(f);!Vr(B,I)||m||Kt()});typeof b=="function"&&(Mt=b),Vr(Xr(f))}catch{Xt=null}finally{m=!1}},ml=()=>{if(et||Wn()!=="viewing")return null;const f=_()?.mount?.container,m=(f&&typeof f=="object"&&"ownerDocument"in f?f.ownerDocument??null:null)??globalThis.document??null;return m&&typeof m.addEventListener=="function"?m:null},Qi=()=>{const f=ml();if(f===er||(zr&&(zr(),zr=null),er=f,!f))return;const m=()=>{_t+=1,Kt()};f.addEventListener("selectionchange",m),f.addEventListener("pointerup",m,!0),f.addEventListener("mouseup",m,!0),zr=()=>{f.removeEventListener("selectionchange",m),f.removeEventListener("pointerup",m,!0),f.removeEventListener("mouseup",m,!0)}};Ei(),Vr(Xr(An()));let pt=Ge();a=pa(pt.selection);const Mi=()=>{const f=_()?.host?.events,m=f&&typeof f.subscribe=="function"?f:null;if(m!==jn&&(pr&&(pr(),pr=null),jn=m,!!m))try{const b=m.subscribe(I=>{const E=I?.type;if(E==="review-mutation:started"){Dt(I.reviewMutation?.token);return}if(E==="review-mutation:aborted"){Gt(I.reviewMutation?.token),we();return}if(E==="mutation:rejected"&&I.reviewMutation&&(Gt(I.reviewMutation.token),we()),E==="mutation:committed"&&I.reviewMutation&&Gt(I.reviewMutation.token),E==="source:complete"||E==="source:signals-complete"){Nt!==null&&(De(),br.onRender(!0));return}if((E==="mutation:committed"||E==="collaboration:remote-changed")&&(ut=Date.now()),E==="mutation:committed"&&(De(),$t={}),E==="mutation:committed"||E==="save:completed"||E==="collaboration:remote-changed"){const B=E==="mutation:committed"?Vk(I):null,W=E==="mutation:committed"&&br.getPendingIds().size>0;if(B?.allResolved){br.reset(),un([]),Nt=null,nn(I.receipt);return}B?.removedIds.size&&Yn(new Set(B.removedIds),I.receipt);const ie=B?.reconcileMode==="authoritative"&&B.upsertIds.size>0;if(ie&&(ks(),De(),Nt=Et(),Kt()),B?.upsertIds.size||W){const je=I.origin==="history"?null:I.receipt,Ne=_()?.documentMutationReadiness,Ye=typeof je?.txId=="string"&&je.txId.length>0&&typeof Ne?.whenPainted=="function",He=I.origin==="history"&&typeof Ne?.getRenderEpoch=="function"?Pt(()=>Ne.getRenderEpoch.call(Ne),null):null,Xe=I.origin==="history"&&typeof Ne?.whenPainted=="function",Ze={upsertIds:B?.upsertIds??new Set,removedIds:new Set,reconcileMode:B?.reconcileMode==="authoritative"?"authoritative":"targeted"};Ye?br.enqueueAfterPaint(Ze,()=>Ne.whenPainted.call(Ne,je)):Xe?br.enqueueAfterPaint(Ze,()=>Ne.whenPainted.call(Ne,typeof He=="number"?{afterEpoch:He}:void 0)):(br.enqueue(Ze),br.onRender(W))}if(ie)return;const fe=E==="mutation:committed"&&Ii(I)||E==="collaboration:remote-changed"&&Array.isArray(I.changedStoryIds)&&I.changedStoryIds.length>0;if(fe&&(Vn=Date.now()),E==="mutation:committed"&&fe){Xi();return}if(B?.removedIds.size&&B.upsertIds.size===0)return;(E==="collaboration:remote-changed"||E==="mutation:committed"&&!fe)&&ya();const Le=E==="collaboration:remote-changed"&&Array.isArray(I.changedPartUris)&&I.changedPartUris.some(je=>typeof je=="string"&&SV.has(je)),Ue=E==="collaboration:remote-changed"&&Array.isArray(I.changedStoryIds)&&I.changedStoryIds.length>0&&va();Le&&!fe&&(yn=!0),ks(),Le&&!fe?ga("comments"):Ue&&(yn=!0,no()),Kt()}});typeof b=="function"&&(pr=b)}catch{jn=null}},Kt=()=>{if(J)return;on=!1,Ei(),lt(),hr(),Ts(),Qi(),Mi();const f=Ge();ct(f.selection),pt=f;for(const m of[...qe])m(pt)},Sa=[],_a=[],Aa=f=>{for(const m of f)try{m()}catch{}},gl=()=>Aa(Sa),Ji=()=>Aa(_a),gc=[];((f,m)=>{if(!(!f||typeof f.on!="function"))for(const b of m){const I=b==="active-editor-change"?()=>{gl(),Ji(),Kt()}:b==="document-replaced"?E=>{const B=E&&typeof E=="object"?E:null,W=B?.editor,ie=B?.host,fe=!!W&&W===_(),Le=!!ie&&ie===x();!fe&&!Le||(Ji(),ee.clear(),ks(),Kt())}:()=>Kt();try{f.on(b,I),gc.push(()=>{try{typeof f.off=="function"&&f.off(b,I)}catch{}})}catch{}}})(t,vV),lt(),hr(),Ts(),Qi(),Mi();const xs=(f,m=nV)=>({get:()=>f(pt),subscribe:b=>{let I=f(pt);const E=B=>{const W=f(B);m(I,W)||(I=W,b(W))};return qe.add(E),()=>qe.delete(E)}}),Ho=f=>xs(f),Po=f=>{const m=b=>{const I=B=>{try{b(B)}catch{}},E=f.subscribe(I);return I(f.get()),E};return{get:()=>f.get(),getSnapshot:()=>f.get(),observe:m,subscribe:b=>m(I=>b({snapshot:I}))}};function Yu(f){return f&&typeof f=="object"&&typeof f.id=="string"?String(f.id):null}function Rs(f){const m=$i(f);return m&&_r(m)!==_r(null)?m:void 0}function vc(f,m){return{kind:"id",id:f,...m?{story:m}:{}}}function Qf(f){if(f.empty)return null;const m=f.selectionTarget,b=m?.start,I=m?.end;if(m?.kind!=="selection"||b?.kind!=="text"||I?.kind!=="text"||typeof b.blockId!="string"||b.blockId!==I.blockId||!Number.isInteger(b.offset)||!Number.isInteger(I.offset)||b.offset<0||I.offset<0||b.offset===I.offset)return null;const E=Math.min(b.offset,I.offset),B=Math.max(b.offset,I.offset),W=$i(f);return{kind:"range",coordinateSpace:m.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...W?{story:W}:{},segments:[{blockId:b.blockId,range:{start:E,end:B}}]}}}function P(f,m){if(_r(m)!==_r(null))return;const b=y()?.trackChanges,I=b?.list;if(typeof I!="function")return;const E=Pt(()=>I.call(b),null);if(Sr(E)||!E||typeof E!="object")return;const B=E.items;if(Array.isArray(B))return B.map(il).find(W=>W!=null&&Ui(W,f,m))}function j(f,m){const b=Ce(f.quotedText);if(!b)return!1;const I=wm(m);return[I.insertedText,I.deletedText,I.excerpt].some(E=>Ce(E)===b)}function Ce(f){return typeof f=="string"?f.replace(/\s+/g," ").trim():""}function Pe(){const f=pt.selection.activeChangeIds[0];if(!f)return"unavailable";const m=$i(pt.selection),b=(pt.trackChanges.status==="ready"?pt.trackChanges.items.find(W=>Ui(W,f,m)):void 0)??P(f,m)??Zi()?.find(W=>Ui(W,f,m));if(!b)return"unavailable";const I=wm(b),E=I.type,B=I.grouping;return j(pt.selection,b)?"id":E==="replacement"&&B==="replacement-pair"||(E==="insertion"||E==="deletion"||E==="insert"||E==="delete")&&B==="standalone"?"range":"id"}function at(f,m,b,I){const E=()=>A2(f,vc(b,I),b,I);try{const B=A2(f,m,null);if(Sr(B))return Zr(Promise.resolve(B).then(ie=>ko(Cs(ie))?ie:E()));const W=Cs(B);return Zr(ko(W)?B:E())}catch{return!1}}function Ut(f,m){if(f.scope==="all")return{target:{kind:"all"},changeId:null};if(typeof m=="string"&&m.length>0)return{target:{kind:"id",id:m},changeId:m};if(m&&typeof m=="object"){const E=m;if(E.target&&typeof E.target=="object"){const W=E.target;return{target:W,changeId:Yu(W),story:W.story}}const B=typeof E.changeId=="string"?E.changeId:E.id;if(typeof B=="string"&&B.length>0)return{target:vc(B,E.story),changeId:B,story:E.story}}const b=pt.selection.activeChangeIds[0],I=Rs(pt.selection);return b?{target:vc(b,I),changeId:b,story:I}:null}function In(f,m){if(f.scope==="id"&&m==null){if(pt.selection.activeChangeIds.length>1)return rh(f.kind,{kind:"ids",ids:pt.selection.activeChangeIds},null);if(pt.selection.activeChangeIds.length===1&&!pt.selection.empty&&pt.selection.selectionTarget){const I=Pe();if(I==="unavailable")return!1;if(I==="range"){const E=Qf(pt.selection),B=Rs(pt.selection);return E?at(f.kind,E,pt.selection.activeChangeIds[0],B):!1}if(I==="id"){const E=pt.selection.activeChangeIds[0],B=$i(pt.selection),W=B&&_r(B)!==_r(null)?B:void 0;return _2(f.kind,W?{id:E,story:W}:E)}}}const b=Ut(f,m);return b?rh(f.kind,b.target,b.changeId,b.story):!1}function Fn(f,m){const b=T()?.lists,I=b?.apply;if(typeof I!="function")return!1;const{behavior:E,preset:B,continuity:W}=typeof m=="string"?wV(m):m&&typeof m=="object"?m:{},ie={kind:f,behavior:E??"toggle"};B!==void 0&&(ie.preset=B),W!==void 0&&(ie.continuity=W);try{return Zr(I.call(b,ie))}catch{return!1}}let hn=Promise.resolve(!1),fn=null,bn=Promise.resolve(!1);const sr=async f=>{if(!Cm(f))return f;const m=_()?.documentMutationReadiness,b=m?.whenPainted;if(typeof b!="function")return f;const I=typeof f.txId=="string"?f.txId:void 0;try{await b.call(m,I?{txId:I}:void 0)}catch{}return f},Ln=f=>{if(Sr(f)){const b=Promise.resolve(f);return{immediate:!0,committed:b.then(I=>Cs(I),()=>!1),settled:b.then(I=>sr(Cs(I)),()=>!1)}}const m=Cs(f);return{immediate:m,committed:Promise.resolve(m),settled:sr(m)}},ri=()=>{const f=s.shift();if(!f){c=!1,d?.(),d=null;return}try{f.resolve(J?!1:f.mutate())}catch{f.resolve(!1)}},Ia=()=>{let f=!1;return()=>{f||(f=!0,ri())}},oi=(f,m)=>{if(!c){c=!0,u=new Promise(B=>{d=B});try{return{result:m(),release:Ia()}}catch(B){throw c=!1,d?.(),d=null,B}}const b=s.find(B=>B.key===f);if(b)return b.mutate=m,{result:b.result,release:()=>{}};let I;const E=new Promise(B=>{I=B});return s.push({key:f,mutate:m,result:E,resolve:I}),{result:E,release:Ia()}},yl=new Set(["create.tableOfContents"]),bl=f=>Xn(`Tracked authoring is not supported for ${f}.`),Jf=f=>{if(Wn()==="suggesting")return yl.has(f)?bl(f):{changeMode:"tracked"}},Im=()=>Wn()==="suggesting"?ej:m2,jr=(f,m,b)=>{const I=Jf(f);return I&&I.success===!1?I:I?m(b,I):m(b)},y2=(f,m,b,I)=>{const E=f.inline;if(!E)return;const B=Cs(I);if(B===!1||typeof B=="object"&&B&&B.success===!1)return;if(E.kind==="clear"){n.clear();return}if(E.kind==="toggle"||!u2(E.key))return;const W=pa(m);if(!W)return;const ie=jV(E.key,b.value);if(ie==null){n.delete(E.key);return}n.set(E.key,{selectionSignature:W,value:ie})},b2=(f,m,b,I)=>!f.inline||f.inline.kind==="toggle"?I:Sr(I)?Promise.resolve(I).then(E=>(y2(f,m,b,E),E)):I,eh=(f,m,b,I)=>{if(f.inline?.kind!=="toggle"||!ko(Cs(I))||typeof b.value!="boolean"&&b.value!==null)return null;const E=pa(m);if(!E)return null;const B=++l;return r.set(f.id,{selectionSignature:E,active:b.value===!0,generation:B,settled:!1}),Kt(),B},tr=(f,m,b)=>{if(m==null)return;const I=r.get(f.id);if(!(!I||I.generation!==m)){if(!ko(b)){r.delete(f.id);return}I.settled=!0}},Xu=(f,m)=>f.then(b=>(m?.(b),Ss(),b),()=>(m?.(!1),Ss(),!1)),Zr=(f,m)=>{const b=fn;if(fn=null,b)return hn=Xu(b,m),Cs(f);if(Sr(f))return hn=Xu(Ln(f).settled,m),!0;const I=Cs(f);return Cm(I)&&typeof _()?.documentMutationReadiness?.whenPainted=="function"?(hn=Xu(sr(I),m),I):(m?.(I),hn=Promise.resolve(I),Ss(),I)},Em=(f,m)=>!f||typeof f!="object"?m:f,Ms=(f,m=Xn("Document API operation failed."))=>{if(Sr(f))return Promise.resolve(f).then(I=>Ms(I,m),()=>m);const b=Em(f,m);return ks(),Cm(b)&&typeof _()?.documentMutationReadiness?.whenPainted=="function"?(Xu(sr(b)),Kt(),b):(Kt(),b)},Tm=(f,m,b,I)=>{const E=[],B=[];for(const W of b){const ie=I(W);if(ie)try{const fe=Ln(jr(f,m,ie));E.push(fe.immediate),B.push(fe.settled)}catch{E.push(!1),B.push(Promise.resolve(!1))}}return fn=B.length?Promise.all(B).then(W=>hi(W)):null,hi(E)},xm=(f,m,b,I)=>{const E=[],B=[];for(const W of b){const ie=I(W);if(ie)try{const fe=Ln(jr(f,m,ie));E.push(fe.immediate),B.push(fe.settled)}catch{E.push(!1),B.push(Promise.resolve(!1))}}return fn=B.length?Promise.all(B).then(W=>hi(W)):null,hi(E)},Zu=(f,m,b,I=pt.selection)=>{const E=Jf(f);return E&&E.success===!1?E:I.selectionTarget?m(b,{...E??{},offsetSpace:"selection"}):E?m(b,E):m(b)},w2=(f,m,b,I)=>{const E=Co(m,I);switch(f.kind){case"alignment":{const B=b;return B!=="left"&&B!=="center"&&B!=="right"&&B!=="justify"?null:{target:E,alignment:B}}case"spacing-line":{const B=typeof b=="number"?b:Number(b);return!Number.isFinite(B)||B<=0?null:{target:E,line:B,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const B=b.role;if(B&&typeof B=="object")return{target:E,role:B}}return typeof b!="string"||b.trim()===""?null:{target:E,styleId:b};case"direction":{const B=f.fixedValue;return B!=="ltr"&&B!=="rtl"?null:{target:E,direction:B}}default:return null}},Rm=(f,m)=>{const b=f.inline,I=p2(f),E=x();if(!b||typeof E?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return X(),!0;if(!I)return!1;let B;if(b.kind==="toggle")B=!Es(f,y(),pt.selection);else{const W=m&&typeof m=="object"&&"value"in m?m.value:m;if(b.kind==="value-number"){const ie=typeof W=="number"?W:Number(W);B=Number.isFinite(ie)&&ie>0?ie:null}else B=typeof W=="string"&&W.trim()!==""?W:null;if(B===null)return F(I,null),!0}return F(I,B),!0},yc=()=>{const f=y(),{lockModesById:m}=pi(f?.contentControls,pt.selection);if(Is(m))return!1;const b=[],I=[],E=Ye=>{const He=Ln(Ye);b.push(He.immediate),I.push(He.settled)},B=(Ye,He,Xe)=>{try{E(Xe?Ye(He,Xe):Ye(He))}catch{b.push(!1),I.push(Promise.resolve(!1))}},W=Se().cache?.full.defaults.paragraphStyleId??pe,ie=Au(pt.selection);if(ie){const Ye=vr(f,"format.apply");if(Ye)try{E(Zu("format.apply",Ye,{target:ie,inline:{...Im()}}))}catch{b.push(!1),I.push(Promise.resolve(!1))}}const fe=vr(f,"format.paragraph.resetDirectFormatting"),Le=vr(f,"styles.paragraph.setStyleRef"),Ue=$i(pt.selection),je=!Ue||Ue.storyType==="body",Ne=vr(f,je?"lists.remove":"lists.removeInStory");for(const Ye of Nr(pt.selection)){const He=Co(Ye,Ue);if(fe&&B(fe,{target:He}),Ne)try{const Xe=ha(Ye),Ze=Ln(Ne(je?{target:Xe}:{target:Xe,story:Ue}));I.push(Ze.settled.then(ot=>ko(ot)?ot:!0))}catch{}Le&&B(Le,{target:He,styleId:W})}if(!ie&&Wn()!=="suggesting"){const Ye=vr(f,"format.paragraph.setMarkRunProps");if(Ye)for(const He of Nr(pt.selection))B(Ye,{target:Co(He,Ue),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return fn=I.length?Promise.all(I).then(Ye=>hi(Ye)):null,hi(b.length?b:[!1])},Qu=(f,m,b)=>{const I=Nr(pt.selection);if(I.length===0)return!1;const E=$i(pt.selection);return Tm(f.docRoute,m,I,B=>w2(f.blockParagraph,B,b,E))},th=(f,m,b)=>{const I=y(),E=vr(I,"format.paragraph.setIndentation"),B=vr(I,"format.paragraph.clearIndentation"),W=f.list?.mode,ie=Hi(pt.selection),fe=$i(pt.selection),Le=async Ue=>{const je=await ni(I,Ue,ie);if(je===!0)return{kind:"list",routeToCall:f.docRoute,opToCall:m,input:{target:bA(Ue)}};if(je===null||fe&&fe.storyType!=="body"&&typeof I?.getNode!="function")return null;const Ne=await qf(I,Ue,fe),Ye={};if(Ne?.right!=null&&(Ye.right=Ne.right),Ne?.firstLine!=null&&(Ye.firstLine=Ne.firstLine),Ne?.hanging!=null&&(Ye.hanging=Ne.hanging),W==="indent")return E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),left:Math.max(0,Ne?.left??0)+wA,...Ye}}:null;const He=Math.max(0,(Ne?.left??0)-wA);return He>0&&(Ye.left=He),Object.keys(Ye).length===0?B?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:B,input:{target:Co(Ue,fe)}}:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),left:0}}:null:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),...Ye}}:null};return fn=(async()=>{const Ue=await Promise.all(b.map(He=>Le(He).catch(()=>null)));if(Ue.length===b.length&&Ue.every(He=>He?.kind==="list")&&Wn()!=="suggesting"){const He=W==="indent"?"lists.indentRange":"lists.outdentRange",Xe=vr(I,He);if(Xe)try{return await Ln(jr(He,Xe,{paraIds:b,story:ie})).settled}catch{return!1}}const je=ie.storyType!=="body"&&Ue.some(He=>He?.kind==="list"),Ne=je&&W==="outdent"?vr(I,"lists.outdentInStory"):null;if(je&&!Ne)return!1;const Ye=Ue.map(He=>{if(!He)return Promise.resolve(!1);try{return He.kind==="list"&&Ne?Ln(jr("lists.outdentInStory",Ne,{target:He.input.target,story:ie})).settled:Ln(jr(He.routeToCall,He.opToCall,He.input)).settled}catch{return Promise.resolve(!1)}});return hi(await Promise.all(Ye))})(),!0},xt=(f,m)=>{const b=f.list,I=y(),E=Nr(pt.selection);if(E.length===0)return!1;const B=Hi(pt.selection),W=B.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return th(f,m,E);const ie=b.seed,fe=je=>{if(je.some(ot=>!ot.resolved))return{immediate:!1,settled:null};const Ne=je.every(ot=>ot.seed===ie);if(!Ne&&!W)return{immediate:!1,settled:null};const Ye=Ne?W?"lists.remove":"lists.removeInStory":f.docRoute,He=Ne?vr(I,Ye):m;if(!He)return{immediate:!1,settled:null};const Xe=[],Ze=[];return E.forEach((ot,tt)=>{if(!Ne&&je[tt]?.seed===ie)return;const Bt=Ne?{target:ha(ot),...W?{}:{story:B}}:{target:ha(ot),seed:ie};try{const Qt=Ln(jr(Ye,He,Bt));Xe.push(Qt.immediate),Ze.push(Qt.settled)}catch{Xe.push(!1),Ze.push(Promise.resolve(!1))}}),{immediate:hi(Xe),settled:Ze.length?Promise.all(Ze).then(ot=>hi(ot)):null}},Le=E.map(je=>Yr(I,je,B));if(Le.some(Sr))return fn=Promise.all(Le).then(async je=>{const Ne=fe(je);return Ne.settled?await Ne.settled:Ne.immediate}),!0;const Ue=fe(Le);return fn=Ue.settled,Ue.immediate};function Ht(f){return f&&typeof f=="object"?f:{}}function wn(f){if(typeof f=="string")return f;const m=Ht(f);if(Object.prototype.hasOwnProperty.call(m,"href"))return m.href;if(Object.prototype.hasOwnProperty.call(m,"value"))return m.value}function Ir(f,m){const b=Ht(f).text;return typeof b=="string"&&b.trim()!==""?b:m}function Ur(f){const m=Ht(f),b=m.capture&&typeof m.capture=="object"?m.capture:null;return m.target??b?.target??b?.selectionTarget??m.selectionTarget??m.textTarget??null}const vo=f=>{const m=y(),b=m?.hyperlinks;if(!b)return!1;const I=Ht(f),E=wn(f),B=Ur(f),W=typeof I.text=="string"?I.text:void 0,ie=typeof I.currentText=="string"?I.currentText:void 0,fe=Xl(I.hyperlinkTarget)?I.hyperlinkTarget:null,Le=Xl(I.textTarget)?I.textTarget:null,Ue=dc(m,pt.selection),je=typeof fe?.storyId=="string"&&typeof fe?.hyperlinkNodeId=="string";if(je&&E===null){const Ne=b.remove;if(typeof Ne!="function")return!1;try{return jr("hyperlinks.remove",Ne,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(Ue&&E===null){const Ne=b.remove;if(typeof Ne!="function")return!1;try{return jr("hyperlinks.remove",Ne,{target:Ue.address,mode:"unwrap"})}catch{return!1}}if((Ue||fe)&&typeof E=="string"&&E.trim()!==""){const Ne=b.patch,Ye=b.updateTarget;if(!(!je&&Ue&&typeof Ne=="function")&&!(je&&typeof Ye=="function"))return!1;const He=typeof W=="string"&&W!==(je?ie:Ue?.text??ie),Xe=m?.text?.replace,Ze=He?je?Le:qV(Ue?.address):null,ot=He&&!!Ze&&typeof Xe=="function";if(He&&!ot)return!1;const tt=[],Bt=[];let Qt=null,an=null,Pn=null,Hr=!1;try{if(je){if(typeof Ye!="function")return!1;const Er=jr("hyperlinks.updateTarget",Ye,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,newTarget:YV(E)});Hr=Sr(Er);const Tr=Ln(Er);if(!ko(Tr.immediate))return!1;tt.push(Tr.immediate),Bt.push(Tr.settled),Qt=Tr.immediate,an=Tr.committed,Pn=Tr.settled}else if(Ue){if(typeof Ne!="function")return!1;const Er=jr("hyperlinks.patch",Ne,{target:Ue.address,patch:{href:E}});Hr=Sr(Er);const Tr=Ln(Er);if(!ko(Tr.immediate))return!1;tt.push(Tr.immediate),Bt.push(Tr.settled),Qt=Tr.immediate,an=Tr.committed,Pn=Tr.settled}}catch{return!1}if(ot){const Er=(Lr,$o)=>ko($o)?hi([Lr,$o]):ko(Lr)?Nf(Lr,$o):$o,Tr=Lr=>{if(!ko(Lr))return Lr;try{const $o=Ln(jr("text.replace",Xe,{target:Ze,text:W}));return ko($o.immediate)?Promise.all([Pn??Promise.resolve(Lr),$o.settled]).then(([R2,mU])=>Er(R2,mU)):Nf(Lr,$o.immediate)}catch{return Nf(Lr,!1)}};if(Hr)return fn=(an??Promise.resolve(Qt??!1)).then(Tr),hi(tt);try{const Lr=Ln(jr("text.replace",Xe,{target:Ze,text:W}));if(!ko(Lr.immediate))return Qt?Nf(Qt,Lr.immediate):Lr.immediate;tt.push(Lr.immediate),Bt.push(Lr.settled),fn=Promise.all([Pn??Promise.resolve(Qt??!1),Lr.settled]).then(([$o,R2])=>Er($o,R2))}catch{return Qt?Nf(Qt,!1):!1}}return!ot&&Bt.length>0&&(fn=Promise.all(Bt).then(Er=>hi(Er))),hi(tt)}if(typeof E=="string"&&E.trim()!==""){const Ne=E.trim(),Ye=b.wrap,He=BV(B),Xe=He.length>0?He:c2(pt.selection);if(Xe.length>0){if(typeof Ye!="function")return!1;try{return xm("hyperlinks.wrap",Ye,Xe,Bt=>({target:Bt,link:{destination:{href:Ne}}}))}catch{return!1}}const Ze=b.insert,ot=Ir(f,Ne);if(typeof Ze!="function"||ot.trim()==="")return!1;const tt=zf(B)??ol(pt.selection);if(!tt)return!1;try{return jr("hyperlinks.insert",Ze,{target:tt,text:ot,link:{destination:{href:Ne}}})}catch{return!1}}return!1},gi=(f,m,b)=>{const I=f.create.kind,E=b&&typeof b=="object"?b:{};if(I==="table"){const W=Number(E.rows??E.rowCount),ie=Number(E.columns??E.cols??E.colCount);if(!Number.isInteger(W)||W<1||!Number.isInteger(ie)||ie<1)return!1;const fe=ol(pt.selection),Le=fe&&typeof fe.blockId=="string"?{kind:"inParagraph",target:Co(fe.blockId),offset:fe.range?.start??0}:f2(pt.selection,"nodeId");try{return jr(f.docRoute,m,{rows:W,columns:ie,at:Le})}catch{return!1}}if(I==="image"){const W=E.src??E.value;if(typeof W!="string"||W.trim()==="")return!1;const ie=ol(pt.selection),fe=Hi(pt.selection),Le=fe.storyType==="body"?null:fe;let Ue;ie&&typeof ie.blockId=="string"?Ue={kind:"inParagraph",target:Co(ie.blockId,Le),offset:ie.range?.start??0}:(Ue=f2(pt.selection,"target"),Le&&Ue.kind==="after"&&(Ue={...Ue,target:{...Ue.target,story:Le}}));const je={src:W,at:Ue};Le&&(je.in=Ue.kind==="inParagraph"?L(Le)??Le:Le),typeof E.alt=="string"&&(je.alt=E.alt),typeof E.title=="string"&&(je.title=E.title),E.size&&typeof E.size=="object"&&(je.size=E.size);try{return jr(f.docRoute,m,je)}catch{return!1}}const B={at:f2(pt.selection,"target")};typeof E.instruction=="string"&&(B.instruction=E.instruction),E.config&&typeof E.config=="object"&&(B.config=E.config);try{return jr(f.docRoute,m,B)}catch{return!1}},Ls=(f,m)=>{const b=f.table,I=Be();if(!I||b.requiresCell&&!I.cellNodeId)return!1;const E=rj(b.action,I);if(!E)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const B=x(),W=(typeof B?.getHandles=="function"?B.getHandles():null)?.editing?.tables;if(typeof W?.insertRow!="function")return!1;const ie=Jf(f.docRoute);return ie&&ie.success===!1?ie:ie?W.insertRow(E,ie):W.insertRow(E)}return jr(f.docRoute,m,E)}catch{return!1}},Ju=f=>!f||f.disposition!=="routed"?!1:!!(f.inline||f.blockParagraph||f.list||f.link||f.create),Fj=f=>{const m=Ht(f);return!!(Ur(f)||Xl(m.hyperlinkTarget)||Xl(m.textTarget))},Nj=(f,m,b)=>pt.selection.status!=="ready"?!1:Sm(f)?.scope==="id"||!m||m.disposition!=="routed"?!0:m.inline?.kind==="clear"?Nr(pt.selection).length>0||Au(pt.selection)!=null:m.inline?Au(pt.selection)!=null||Nr(pt.selection).length>0:m.blockParagraph||m.list?Nr(pt.selection).length>0:m.link?Fj(b)||c2(pt.selection).length>0||ol(pt.selection)!=null||Es(m,y(),pt.selection):!0,Bj=(f,m)=>{const b=Sm(f),I=gu(f);return b?.scope!=="id"&&!Ju(I)?!1:!Nj(f,I,m)},zj=(f,m)=>Bj(f,m)?_s().then(()=>{}):null,bc=(f,m,b)=>{if(fn=null,hn=Promise.resolve(!1),J)return!1;const I=he.get(f);if(I)try{const je=I.execute(tc(m,b));return Zr(je)}catch{return!1}const E=hA(f);if(E&&typeof T()?.lists?.apply=="function")return Fn(E,m);const B=Sm(f);if(B)return In(B,m);if(f==="copy-format")return Zr(Vj());const W=gu(f);if(!W||W.disposition!=="routed")return!1;const ie=W.normalizePayload?W.normalizePayload(m):m;if(W.instanceRoute){if(!_()||!oe(W,ie))return!1;const je=t?.[W.instanceRoute];if(typeof je!="function")return!1;try{const Ne=W.fixedArg!==void 0?W.fixedArg:ie,Ye=je.call(t,Ne);return Zr(Ye)}catch{return!1}}if(W.inline?.kind==="clear")return W.mutates&&Wn()==="viewing"?!1:Zr(yc());const fe=W.docRoute;if(!fe||W.mutates&&Wn()==="viewing")return!1;const Le=y(),Ue=vr(Le,fe);if(!Ue)return!1;if(W.inline){const{lockModesById:je}=pi(Le?.contentControls,pt.selection);if(Is(je))return!1;const Ne=Au(pt.selection);if(!Ne)return pt.selection.empty===!1?Zr(!1):Zr(Rm(W,ie));const Ye=Es(W,Le,pt.selection),He=tj(W.inline,Ne,ie,Ye);if(!He)return!1;let Xe=null;try{const Ze=_(),ot=Wn(),tt=()=>_()!==Ze||y()!==Le||Wn()!==ot?!1:Zu(fe,Ue,He),Bt=pa(pt.selection)??Kl(pt.selection),Qt=W.inline.kind==="toggle"?oi(`${W.id}:${Bt}`,tt):null;Xe=Qt?.release??null;const an=Qt?Qt.result:tt(),Pn=eh(W,pt.selection,He,an),Hr=b2(W,pt.selection,He,an),Er=Zr(Hr,Tr=>{tr(W,Pn,Tr),Xe?.(),Xe=null});return W.inline.kind==="toggle"&&(bn=hn),Er}catch{return Xe?.(),!1}}if(W.blockParagraph){const je=Qu(W,Ue,ie),Ne=W.blockParagraph.kind==="alignment"&&ko(je)?pc(pt.selection,ie):null;return Zr(je,Ye=>{qu(Ne,Ye)})}if(W.list){const je=xt(W,Ue);return Zr(je)}if(W.link){const je=vo(ie);return Zr(je)}if(W.create){const je=gi(W,Ue,ie);return Zr(je)}if(W.table){const je=Ls(W,Ue);return Zr(je)}try{return Zr(W.mutates?jr(fe,Ue,ie):Ue(ie))}catch{return!1}},Mm=()=>{g+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const f of p)f("idle");Kt()},Vj=async()=>{const f=["bold","italic","underline","strikethrough"].filter(Ue=>pt.toolbar.commands[Ue]?.active===!0),m=await bn;await u;const b=ko(m)?f:[],I=500,E=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&E-h.lastClickAt<I){h={...h,mode:"persistent",lastClickAt:E};for(const Ue of p)Ue("persistent");return Kt(),!0}return Mm(),!1}const B=E-h.lastClickAt<I,W=++g;h={...h,lastClickAt:E};const ie=await _s(),fe=`${Kl(ie)}:${Et()}`,Le=await jj(null,ie,fe&&fe===k?v:void 0,b);if(W!==g)return!0;h={...h,mode:B?"persistent":"armed",snapshot:Le,sourceSelectionKey:Kl(ie),lastClickAt:E};for(const Ue of p)Ue(h.mode);return Kt(),!0},jj=async(f,m,b,I=[])=>{const E=m?.target??f?.target;if(!E||E.kind!=="text")return null;const B=Array.isArray(E.segments)?E.segments:[];if(B.length===0)return null;const W=y();if(!W)return null;const ie=E.story;let fe=null;for(const He of B){const Xe=(await As(Co(He.blockId,ie)))?.node??null;if(!Xe)continue;const Ze=C2(Xe),ot=Array.isArray(Ze?.inlines)?Ze.inlines:[],tt=Uj(ot,He.range);fe?fe=MA(fe,tt):fe=tt}const Le=fe?rV(fe):{},Ue={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},je=new Set([...m?.activeMarks??(Array.isArray(f?.activeMarks)?f.activeMarks:[]),...I]);for(const[He,Xe]of Object.entries(Ue))je.has(He)&&(Le[Xe]=!0);const Ne=b??await Fu(m??al(f,"ready"));if(Ne.fontFamily&&(Le.fontFamily=Ne.fontFamily),Ne.color&&(Le.color=Ne.color),Ne.highlight&&(Le.highlight=Ne.highlight),Ne.fontSize){const He=Number.parseFloat(Ne.fontSize);Number.isNaN(He)||(Le.fontSize=He)}let Ye=null;if(B.length===1){const He=B[0],Xe=(await As(Co(He.blockId,ie)))?.node??null;Xe&&C2(Xe)&&(Ye=await Hj(Xe,He.blockId,W,ie))}return{story:ie??null,inline:Le,paragraph:Ye}},C2=f=>f?f.kind==="paragraph"?f.paragraph??null:f.kind==="heading"?f.heading??null:null:null,Uj=(f,m)=>{const b=W=>{const ie=W.run;return typeof ie?.text=="string"?ie.text:""},I=W=>W.run?.props;if(m.start===m.end){let W=0;for(const ie of f){const fe=b(ie),Le=W,Ue=W+fe.length;if(W=Ue,m.start>=Le&&m.start<=Ue){const je=I(ie);return je?{...je}:{}}}return{}}let E=0;const B=[];for(const W of f){const ie=b(W),fe=E,Le=E+ie.length;if(E=Le,Le<=m.start||fe>=m.end)continue;const Ue=I(W);Ue&&B.push(Ue)}return B.length===0?{}:B.length===1?{...B[0]}:MA(B[0],...B.slice(1))},MA=(f,...m)=>{const b={...f};for(const I of m)for(const E of Object.keys(b)){if(!(E in I)){delete b[E];continue}const B=b[E],W=I[E];(typeof B!=typeof W||JSON.stringify(B)!==JSON.stringify(W))&&delete b[E]}return b},Hj=async(f,m,b,I)=>{const E=C2(f),B=E.props??{},W=E.styleRef??null,ie=B.alignment??null,fe=B.spacing??null,Le=B.indent??null,Ue=Le?{...Le.left!=null?{left:Le.left}:{},...Le.right!=null?{right:Le.right}:{},...Le.firstLine!=null?{firstLine:Le.firstLine}:{},...Le.hanging!=null?{hanging:Le.hanging}:{}}:null,je=B.markRunProps??null,Ne=B.numbering?.numId,Ye=typeof Ne=="string"?parseInt(Ne,10):typeof Ne=="number"?Ne:NaN,He=B.numbering?.level,Xe=isNaN(Ye)?null:{numId:Ye,...He!=null?{level:He}:{}};let Ze=null;if(Xe&&typeof b.lists?.getState=="function")try{const ot=await b.lists.getState({target:Co(m,I)});ot&&typeof b.lists?.getStyle=="function"&&(Ze=await b.lists.getStyle(ot)??null)}catch{}return{styleId:W,alignment:ie,spacing:fe,indentation:Ue,markRunProps:je,numbering:Xe,listStyle:Ze}},LA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const f=y()?.selection,m=async()=>{const W=typeof f?.current=="function"?await Promise.resolve(f.current({includeText:!0})):So().value;return Ti(W)},b=()=>new Promise(W=>setTimeout(W,16)),I=8;let E=null,B="";for(let W=0;W<I;W+=1){if(W>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(E=await m(),!(!E||E.empty)&&(B=Kl(E),B!==h.sourceSelectionKey))break}if(E&&!E.empty&&B!==h.sourceSelectionKey){await PA(E);return}if(h.snapshot?.paragraph){const W=await m();if(!W||Kl(W)===h.sourceSelectionKey)return;await PA(W)}},PA=async f=>{const m=h.snapshot;if(!m){h.mode==="armed"&&Mm();return}const b=y();if(!b)return;const I=al(f,"ready"),{lockModesById:E}=pi(b.contentControls,I);if(Is(E)){Kt();return}const B=f.target,W=f.selectionTarget;if(f.empty!==!0&&Object.keys(m.inline).length>0){const ie=vr(b,"format.apply");if(ie&&W)try{if(!ko(Cs(await Promise.resolve(Zu("format.apply",ie,{target:W,inline:m.inline},f))))){Kt();return}}catch{Kt();return}}if(m.paragraph){const ie=Array.isArray(B?.segments)?B.segments:[],fe=B?.story;for(const Le of ie){const Ue=Co(Le.blockId,fe),je=await As(Ue),Ne=je?.node??null,Ye=je?.address??null;if(!Ne)continue;const He={kind:"block",nodeType:Ye?.nodeType??Ne.kind??"paragraph",nodeId:Le.blockId,...fe&&typeof fe=="object"?{story:fe}:{}},{styleId:Xe,alignment:Ze,spacing:ot,indentation:tt,markRunProps:Bt,numbering:Qt,listStyle:an}=m.paragraph;if(Xe&&await b.styles?.paragraph?.setStyle?.({target:He,styleId:Xe}),Ze&&await b.format?.paragraph?.setAlignment?.({target:He,alignment:Ze}),ot){const Pn=ot,Hr=Pn.lineRule??"auto",Er=new Set(["auto","exact","atLeast"]).has(Hr)?Hr:"auto",Tr={...Pn.before!=null?{before:Math.round(Pn.before*20)}:{},...Pn.after!=null?{after:Math.round(Pn.after*20)}:{},...Pn.line!=null?{line:Math.round(Er==="auto"?Pn.line*240:Pn.line*20),lineRule:Er}:{}};await b.format?.paragraph?.setSpacing?.({target:He,...Tr})}if(tt){const Pn={...tt.left!=null?{left:ws(tt.left)}:{},...tt.right!=null?{right:ws(tt.right)}:{},...tt.firstLine!=null?{firstLine:ws(tt.firstLine)}:{},...tt.hanging!=null?{hanging:ws(tt.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:He,...Pn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:He,markRunProps:Bt}),Qt&&await b.format?.paragraph?.setNumbering?.({target:He,...Qt}),an&&((await As(Ue))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:bA(Le.blockId,fe),style:an}):Qt&&await b.format?.paragraph?.setNumbering?.({target:He,...Qt}))}}h.mode==="armed"&&Mm(),Kt()},Lm=(f,m,b)=>{const I=zj(f,m),E=I?I.then(()=>(bc(f,m,b),hn)):(bc(f,m,b),hn);return gu(f)?.inline?.kind==="toggle"&&(bn=E),E},DA=f=>({id:f,getState:()=>pt.toolbar.commands[f]??uc(f,y(),pt.selection,fl(pt.selection)),observe:m=>xs(b=>b.toolbar.commands[f]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:dt.commandUnsupported}).subscribe(m),execute:m=>bc(f,m),executeAsync:m=>Lm(f,m)}),$j=f=>{he.set(f.id,f),Kt();const m=()=>{he.delete(f.id),Kt()};return Object.assign(m,{handle:DA(f.id),unregister:m})},Pm=Ho(f=>f.selection),Dm=Po(Pm),OA=()=>{const f=x();if(typeof f?.getHandles!="function")return{reason:dt.hostCapabilityUnavailable};let m=null;try{m=f.getHandles()}catch(I){const E=I?.reason;return{reason:E==="host-not-ready"||E==="host-disposed"||E==="editing-mount-required"?dt.notReady:dt.hostCapabilityUnavailable}}const b=m?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:dt.hostCapabilityUnavailable}:{helper:b}},Gj=f=>{const m=x();if(typeof m?.getHandles=="function")try{const b=m.getHandles()?.editing?.contentControls;typeof b?.activate=="function"&&b.activate({id:f})}catch{}},FA={get:Dm.get,getSnapshot:Dm.getSnapshot,subscribe:Dm.subscribe,observe:Dm.observe,current:()=>So().value,capture:()=>{const f=Pm.get();return f.empty||!f.target&&!f.selectionTarget?null:{...f,capturedAt:Date.now()}},restore:f=>{const m=E=>(Kt(),{...E,success:E.ok});if(!f||typeof f!="object")return m({ok:!1,reason:dt.targetUnresolved});if(!_())return m({ok:!1,reason:dt.notReady});const b=JV(f);if(!b)return m({ok:!1,reason:dt.targetUnresolved});const I=OA();if(!("helper"in I))return m({ok:!1,reason:I.reason});try{return m(fA(I.helper.apply(b)))}catch{return m({ok:!1,reason:dt.hostCapabilityUnavailable})}},apply:f=>{if(!_())return{ok:!1,reason:dt.notReady};const m=OA();if(!("helper"in m))return{ok:!1,reason:m.reason};try{const b=m.helper.apply(f);return Kt(),fA(b)}catch{return{ok:!1,reason:dt.hostCapabilityUnavailable}}},getAnchorRect:f=>{const m=x();if(typeof m?.getSelectionAnchorRect=="function"){const b=Pt(()=>m.getSelectionAnchorRect(f),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:f=>{const m=Pm.get(),b=m.selectionTarget??m.target;if(m.empty||!b)return[];const I=Hm.getRect({target:b,relativeTo:f?.relativeTo});return I.found?I.rects:[]}},Wj={get ids(){return ae()},has:f=>gu(f)!=null||he.has(f),get:f=>DA(f),execute:bc,executeAsync:Lm,register:$j,getContextMenuItems:f=>{const m=[];for(const b of he.values()){const I=b.contextMenu;I&&Pt(I.when?()=>I.when(f):void 0,!0)&&m.push({id:b.id,label:I.label,group:I.group,order:I.order,invoke:()=>bc(b.id,void 0,f)})}return m.sort((b,I)=>(b.order??0)-(I.order??0)||b.label.localeCompare(I.label))}},k2=Po(Ho(f=>f.toolbar)),Kj={get:k2.get,getSnapshot:()=>pt.toolbar,subscribe:k2.subscribe,observe:k2.observe,execute:bc,executeAsync:Lm},wc=async(f,m)=>{if(!_())return{success:!1,ok:!1,reason:dt.notReady};if(!f)return{success:!1,ok:!1,reason:dt.targetUnresolved};const b=x(),I=b?.scrollTargetIntoView;if(typeof I!="function")return{success:!1,ok:!1,reason:dt.hostCapabilityUnavailable};try{const E={target:f,block:m?.block??"center",behavior:m?.behavior??"smooth"},B=await Promise.resolve(m?.shouldContinue?I.call(b,E,m.shouldContinue):I.call(b,E));return B&&typeof B=="object"&&B.success===!1?{success:!1,ok:!1,reason:s2(B.reason,dt.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:dt.hostCapabilityUnavailable}}},Om=async(f,m,b,I)=>{const E=f==="trackChanges"?I?.story:void 0,B=ot=>{if(!E||!ot||typeof ot!="object")return ot;const tt=ot,Bt=tt.address&&typeof tt.address=="object"?tt.address:null;return tt.story||Bt?.story?ot:{...tt,story:E}},W=f==="trackChanges"?AV:Bf,ie=b.find(ot=>Ui(ot,m,E)),fe=ie&&typeof ie=="object"?ie:null,Le=f==="trackChanges"&&fe?.type==="move"&&(fe.subtype==="move-to"||fe.subtype==="move-from")?fe.subtype:null,Ue=Le&&typeof fe?.trackedChangeCanonicalId=="string"?fe.trackedChangeCanonicalId:m,je=ot=>{if(!Le)return W(ot);const tt=Bf(ot);if(tt?.kind!=="move")return null;const Bt=Le==="move-to"?tt.destination:tt.source;return a2(Bt)?Bt:null},Ne=W(ie),Ye=f!=="trackChanges"||!Le&&a2(Bf(ie));if(Ne&&Ye)return B(Ne);const He=y()?.[f],Xe=f==="comments"?{commentId:m}:{id:Ue,...E?{story:E}:{}},Ze=He?.get;if(typeof Ze!="function")return B(Ne);try{return B(je(await Promise.resolve(Ze.call(He,Xe)))??Ne)}catch{return B(Ne)}};function NA(f,m){if(Vo())return Xn("Comments are read-only.","DOCUMENT_READONLY");if(Hf())return Xn("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,I=b?.patch;if(typeof I!="function")return Xn("comments.patch is unavailable.");const E=Xn("comments.patch failed.");return Pt(()=>Ms(I.call(b,{commentId:f,status:m}),E),E)}const nh=()=>Vo()?Xn("Comments are read-only.","DOCUMENT_READONLY"):null,BA=(f,m)=>{const b=m&&typeof m=="object"?m:null;let I=Array.from(f);b?.includeResolved===!1&&(I=I.filter(fe=>fe.status!=="resolved"));const E=Number(b?.offset),B=Number.isInteger(E)&&E>0?E:0,W=Number(b?.limit),ie=Number.isInteger(W)&&W>=0?B+W:void 0;return I.slice(B,ie)},ed=Ho(f=>f.comments),Fm=Po(ed),qj={get:Fm.get,getSnapshot:Fm.getSnapshot,subscribe:Fm.subscribe,observe:Fm.observe,list:f=>{const m=ed.get();if(m.status!=="pending")return BA(m.items,f);const b=y()?.comments,I=Pt(b?.list?()=>b.list(f):void 0,null);return Sr(I)?[]:BA(Array.isArray(I?.items)?I.items:[],f)},getById:f=>{const m=ed.get().items.find(E=>Gn(E)===f)??null;if(m)return m;const b=y()?.comments,I=Pt(b?.get?()=>b.get({commentId:f}):void 0,null);return Sr(I)?null:I},createFromCapture:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.create;if(typeof E!="function")return Xn("comments.create is unavailable.");const B=Xn("comments.create failed.");return Pt(()=>{const W=f&&typeof f=="object"?f.target??f.selectionTarget:null;return W==null?Xn("A range selection is required to comment.","NO_SELECTION"):Ms(E.call(I,{target:W,text:m.text}),B)},B)},createFromSelection:f=>{const m=nh();if(m)return m;const b=y()?.comments,I=b?.create;if(typeof I!="function")return Xn("comments.create is unavailable.");const E=Pm.get(),B=E.target??E.selectionTarget;if(E.empty||!B)return Xn("A range selection is required to comment.","NO_SELECTION");const W=Xn("comments.create failed.");return Pt(()=>Ms(I.call(b,{target:B,text:f.text}),W),W)},reply:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.reply??I?.create;if(typeof E!="function")return Xn("comments.reply is unavailable.");const B=Xn("comments.reply failed.");return Pt(()=>Ms(E===I?.reply?E.call(I,{parentCommentId:f,text:m.text}):E.call(I,{parentCommentId:f,text:m.text}),B),B)},edit:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.patch;if(typeof E!="function")return Xn("comments.patch is unavailable.");const B=Xn("comments.patch failed.");return Pt(()=>Ms(E.call(I,{commentId:f,text:m.text}),B),B)},resolve:f=>NA(f,"resolved"),reopen:f=>NA(f,"active"),delete:f=>{const m=nh();if(m)return m;const b=y()?.comments,I=b?.delete??b?.remove;if(typeof I!="function")return Xn("comments.delete is unavailable.");const E=Xn("comments.delete failed.");return Pt(()=>Ms(I.call(b,{commentId:f}),E),E)},setActive:f=>{if(f==null)return ve=null,Kt(),!0;if(!_())return!1;const m=ed.get();if(m.listStatus!=="ready")return!1;const b=DV(m.items,f);return!b||!m.items.some(I=>Gn(I)===b)?!1:(ve=b,Kt(),!0)},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:_()?dt.documentApiUnavailable:dt.notReady};const m=await Om("comments",f,ed.get().items);return m?wc(m):{success:!1,ok:!1,reason:dt.targetUnresolved}}},Ea=Ho(f=>f.trackChanges),S2=(f,m)=>{const b=Ea.get().items.filter(je=>Gn(je)!==null);if(b.length===0)return null;const I=pt.trackChanges.activeId,E=ue?.id===I?ue.story:void 0,B=b.filter(je=>ym(je)==null),W=E||B.length===0?b:B;let ie=I?W.findIndex(je=>Ui(je,I,E)):-1;ie===-1&&I&&E&&(ie=W.findIndex(je=>Ui(je,I)));const fe=W[ie===-1?f>0?0:W.length-1:(ie+f+W.length)%W.length],Le=Gn(fe),Ue=ym(fe);return $e(Ue?{id:Le,story:Ue}:{id:Le},m),Kt(),Le};let zA=Promise.resolve();const Yj=f=>{const m=re;return zA.catch(()=>{}).then(()=>Xj(f,m))},Xj=async(f,m)=>{if(re!==m)return{success:!1};const b=ue,I=S2(f,{invalidateQueuedNavigation:!1});if(I==null)return{success:!1};const E=ue,B=ke,W=()=>re===m&&ue===E&&ke===B,ie=()=>{W()&&($e(b,{invalidateQueuedNavigation:!1}),Kt())};E&&Je.add(E);try{const fe=await Om("trackChanges",I,Ea.get().items,E?.story?{story:E.story}:void 0);if(!W())return{success:!1};if(!fe)return ie(),{success:!1};so+=1;try{const Le=await wc(fe,{behavior:"auto",shouldContinue:W});return W()?(!Le.ok&&Le.reason!==dt.targetNotVisible?(ie(),Ee(b)):Ee(E),{success:Le.ok}):{success:!1}}finally{so=Math.max(0,so-1),so===0&&(W()?Xt&&Vr(Xr(Xt)):Ee(ue))}}finally{E&&Je.delete(E)}},VA=f=>{const m=Yj(f);return zA=m.then(()=>{},()=>{}),m},Nm=Po(Ea),Zj={get:Nm.get,getSnapshot:Nm.getSnapshot,subscribe:Nm.subscribe,observe:Nm.observe,list:()=>(_e(),Ea.get().items),accept:f=>_2("accept",f),reject:f=>_2("reject",f),acceptAll:()=>rh("accept",{kind:"all"},null),rejectAll:()=>rh("reject",{kind:"all"},null),next:()=>S2(1),previous:()=>S2(-1),navigateNext:()=>VA(1),navigatePrevious:()=>VA(-1),getAt:f=>{if(!f||typeof f!="object"||typeof f.x!="number"||typeof f.y!="number")return null;const m=E2(f);if(m.length===0)return null;const b=Ea.get().items;let I;for(const E of m){if(E.type!=="trackedChange")continue;let B;if(E.story){if(I===void 0&&(I=Zi()),!I)continue;B=I}else B=b;const W=B.find(ie=>Ui(ie,E.id,E.story));if(W)return E.story?{id:W.id,item:W,story:E.story}:{id:W.id,item:W}}return null},setActive:f=>{if(f==null)return $e(null),Ee(null),Kt(),!0;if(!_())return!1;const m=typeof f=="string"?{id:f}:{id:f.id,story:f.story};if(typeof m.id!="string"||m.id.length===0)return!1;const b=m.id;if(m.story){const I=Zi();if(!I)return!1;const E=ku(I,m.story).toPublicId(m.id)??m.id;if(!I.some(B=>Ui(B,E,m.story)))return!1;m.id=E}else{const I=Ea.get().items,E=fa(I).toPublicId(m.id)??m.id,B=I.find(W=>Gn(W)===E);if(!B)return!1;m.id=E,m.story=ym(B)}return b!==m.id&&(m.paintedEntityId=b),$e(m),Ee(m),Kt(),!0},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:_()?dt.documentApiUnavailable:dt.notReady};re+=1,Re+=1;const m=Re,b=Ea.get().items,I=fa(b).toPublicId(f)??f,E=ym(b.find(ie=>Gn(ie)===I)),B=ue,W={id:I,...E?{story:E}:{},...I!==f?{paintedEntityId:f}:{}};Je.add(W);try{const ie=await Om("trackChanges",I,b,E?{story:E}:void 0);if(Re!==m)return{success:!1,ok:!1};if(!ie)return{success:!1,ok:!1,reason:dt.targetUnresolved};$e(W);const fe=Re,Le=ue,Ue=ke,je=()=>Re===fe&&ue===Le&&ke===Ue,Ne=()=>{je()&&($e(B,{invalidateQueuedNavigation:!1}),Kt())};Kt(),so+=1;try{const Ye=await wc(ie,{behavior:"auto",shouldContinue:je});return je()?(!Ye.ok&&Ye.reason!==dt.targetNotVisible?(Ne(),Ee(B)):Ee(W),Ye):{success:!1,ok:!1}}finally{so=Math.max(0,so-1),so===0&&(je()?Xt&&Vr(Xr(Xt)):Ee(ue))}}finally{Je.delete(W)}}},_2=(f,m)=>{const{id:b,story:I}=typeof m=="string"?{id:m,story:void 0}:m,E={kind:"id",id:b,...I?{story:I}:{}};return rh(f,E,b,I)},rh=(f,m,b,I)=>{try{return Zr(A2(f,m,b,I))}catch{return!1}},A2=(f,m,b,I)=>{if(Vo())return!1;const E=y()?.trackChanges,B=m.kind==="all"||m.scope==="all",W=m.kind==="range",ie=m.kind==="ids";if(cc({kind:f,scope:B?"all":"id"},E))return!1;const fe=B?`${f}All`:f,Le=!W&&!ie&&!I&&E&&typeof E[fe]=="function"?E[fe]:null,Ue=E&&typeof E.decide=="function"?E.decide:null;return!Le&&!Ue?!1:Le?Le.call(E,b??{}):Ue.call(E,{decision:f,target:m})},I2=Ho(f=>f.contentControls),oh=f=>I2.get().items.find(m=>m?.id===f)??null,Bm=Po(I2),Qj=(f=>{if(f===void 0)return Bm.get();const m=bm(f);return m?oh(m):null}),Jj={get:(f=>(f!==void 0&&No("api"),Qj(f))),getSnapshot:Bm.getSnapshot,subscribe:Bm.subscribe,observe:Bm.observe,list:()=>(No("api"),I2.get().items),getById:f=>(No("api"),oh(f)),getRect:f=>{const m=bm(f);if(!m)return sl("unresolved");No("panel");const b=oh(m);if(!b)return sl("unresolved");const I=l2(b);return I?Hm.getRect({target:I}):sl("unavailable")},scrollIntoView:async f=>{const m=bm(f);if(!m)return{success:!1};No("panel");const b=oh(m);if(!b)return{success:!1};const I=l2(b);return I?{success:(await wc(I,{block:f.block,behavior:f.behavior})).ok}:{success:!1}},focus:async f=>{const m=bm(f);if(!m)return{success:!1,reason:"invalid-id"};if(!_())return{success:!1,reason:"not-ready"};No("panel");const b=oh(m);if(!b)return{success:!1,reason:"not-found"};const I=l2(b);if(!I)return{success:!1,reason:"not-reachable"};if(!(await wc(I,{block:f.block,behavior:f.behavior})).ok)return{success:!1,reason:"not-reachable"};const E=TV(I);if(!E)return{success:!1,reason:"not-reachable"};const B=FA.apply(E);return!B.ok&&B.reason!==dt.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:(Gj(m),{success:!0})}},zm=Po(Ho(f=>f.fonts)),eU={get:zm.get,getSnapshot:zm.getSnapshot,subscribe:zm.subscribe,observe:zm.observe,getFamilyOptions:()=>pt.fonts.options,getSizeOptions:()=>pt.fonts.sizeOptions},Vm=Po(Ho(f=>f.zoom)),tU={get:Vm.get,getSnapshot:Vm.getSnapshot,subscribe:Vm.subscribe,observe:Vm.observe,set:f=>{if(typeof t?.setZoom=="function")try{t.setZoom(f),Kt()}catch{}},setMode:f=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(f),Kt()}catch{}}},jm=Po(Ho(f=>f.document)),nU={get:jm.get,getSnapshot:jm.getSnapshot,subscribe:jm.subscribe,observe:jm.observe,setMode:f=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(f),Kt()}catch{}},export:f=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(f))}catch{return}},getText:()=>{const f=y(),m=Pt(f?.getText?()=>f.getText({}):void 0,null);return typeof m=="string"?m:m&&typeof m=="object"&&typeof m.text=="string"?m.text:null},replaceFile:f=>{const m=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof m=="function")try{return Promise.resolve(m.call(t,f))}catch{return}}},jA=()=>{if(typeof HTMLElement>"u")return null;const f=_()?.mount?.container;if(f instanceof HTMLElement)return f;const m=t?.element;return m instanceof HTMLElement?m:null},rU=(f,m)=>{if(typeof f!="number"||typeof m!="number"||!Number.isFinite(f)||!Number.isFinite(m))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const I=jA();if(!I)return[];const E=b.elementFromPoint(f,m);if(!E||!I.contains(E))return[];const B=[E],W=tt=>{tt&&I.contains(tt)&&!B.includes(tt)&&B.push(tt)},ie=b.elementsFromPoint;if(typeof ie=="function"){let tt=[];try{tt=ie.call(b,f,m)??[]}catch{tt=[]}for(const Bt of tt)W(Bt)}const fe=[],Le=tt=>{tt&&I.contains(tt)&&!fe.includes(tt)&&!B.includes(tt)&&fe.push(tt)},Ue=tt=>{const Bt=tt.getBoundingClientRect;if(typeof Bt!="function")return!1;let Qt;try{Qt=Bt.call(tt)}catch{return!1}return Qt!=null&&f>=Qt.left&&f<=Qt.right&&m>=Qt.top&&m<=Qt.bottom};for(const tt of B){const Bt=tt.querySelectorAll;if(typeof Bt!="function")continue;let Qt;try{Qt=Bt.call(tt,"[data-track-change-marker]")}catch{continue}for(let an=0;an<Qt.length;an+=1)Ue(Qt[an])&&Le(Qt[an])}fe.reverse();const je=[...fe,...B],Ne=dA(je[0],I);for(let tt=1;tt<je.length;tt+=1)for(const Bt of dA(je[tt],I))Ne.push(Bt);if(Ne.length===0)return Ne;const Ye=Ea.get().items,He=fa(Ye);let Xe;const Ze=new Set,ot=[];for(const tt of Ne){if(tt.type!=="trackedChange"){const Pn=`${tt.type}:${tt.id}`;if(Ze.has(Pn))continue;Ze.add(Pn),ot.push(tt);continue}const Bt=EV(tt.storyKey)??IV(tt.story);let Qt;if(Bt){if(Xe===void 0&&(Xe=Zi()),!Xe||(Qt=ku(Xe,Bt).toPublicId(tt.id),!Qt||!Xe.some(Pn=>Ui(Pn,Qt,Bt))))continue}else if(Qt=He.toPublicId(tt.id),!Qt)continue;const an=`trackedChange:${Qt}`;Ze.has(an)||(Ze.add(an),ot.push(Bt?{type:"trackedChange",id:Qt,story:Bt}:{type:"trackedChange",id:Qt}))}return ot};function E2(f,m){return typeof f=="object"?rU(f?.x,f?.y):null}const td=new Set;let T2=!1;const UA=f=>{const m=x();if(typeof m?.observeGeometry!="function")return;let b=!1;const I=Pt(()=>{const E=m.observeGeometry(()=>f.schedule());return b=!0,E},null);f.detach=typeof I=="function"?I:null,f.boundHost=b?m:null},Um=f=>{if(f.detach){try{f.detach()}catch{}f.detach=null}f.boundHost=null},HA=()=>{if(T2=!1,!(J||x()))for(const f of td)Um(f)},oU=()=>{if(!T2){if(T2=!0,typeof queueMicrotask=="function"){queueMicrotask(HA);return}Promise.resolve().then(HA)}},iU=()=>{const f=x();if(!f){oU();return}for(const m of td)m.boundHost&&m.boundHost===f||(Um(m),UA(m),m.schedule())};Sa.push(iU);const Hm={getRect:f=>{const m=x(),b=m?.getTargetRects;if(typeof b=="function"){const I=Pt(()=>b.call(m,{target:f.target}),null);return I&&typeof I=="object"?I.success===!0&&Array.isArray(I.rects)?ZV(XV(I.rects.filter(E=>E!=null&&typeof E=="object")),f.relativeTo):sl(typeof I.reason=="string"?I.reason:"unresolved"):sl("unresolved")}return sl("unavailable")},observe:f=>{const m=[];let b=0;const I=typeof requestAnimationFrame=="function",E=()=>{if(!I){f();return}b||(b=requestAnimationFrame(()=>{b=0,f()}))},B=xs(ie=>({ready:ie.ready,selection:ie.selection,zoom:ie.zoom}));m.push(B.subscribe(()=>E()));const W={schedule:E,detach:null,boundHost:null};return UA(W),td.add(W),()=>{td.delete(W),Um(W),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const ie of m.splice(0))try{ie()}catch{}}},getHost:()=>jA(),entityAt:E2,contextAt:f=>{const m=!!f&&typeof f.x=="number"&&typeof f.y=="number",b=m?f.x:0,I=m?f.y:0;return{point:{x:b,y:I},entities:m?E2({x:b,y:I}):[],selection:pt.selection,position:null,insideSelection:!1}},scrollIntoView:async f=>{const m=f?.target;if(!m)return{success:!1};let b=null;if(m.kind==="entity"){const I=m.entityType==="comment"?"comments":"trackChanges",E=I==="comments"?ed.get().items:Ea.get().items,B=m.entityType==="trackedChange"&&m.story?{story:m.story}:void 0;b=await Om(I,m.entityId,E,B)}else{const I=m,E=m,B=Array.isArray(I.segments)&&I.segments.length>0?I.segments:E.blockId&&E.range?[{blockId:E.blockId,range:E.range}]:null;if(B){const W=m.story;b={kind:"text",segments:B,...W?{story:W}:{}}}}return b?{success:(await wc(b,{block:f.block??"center",behavior:f.behavior??"smooth"})).ok}:{success:!1}}},$A=f=>{const m=(f&&typeof f=="object"?f:null)?.target;return m&&typeof m=="object"?m:null},GA=f=>`metadata:resolve:${f}`,sU=f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return null;const{value:b}=wr(GA(f),Et(),()=>m.resolve({id:f}),$A);return b},aU=async f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return null;try{const b=Et(),I=await Promise.resolve(m.resolve({id:f}));if(b!==Et())return null;const E=$A(I);return ee.set(GA(f),{token:b,value:E,hasSettled:!0,inflightToken:null}),E}catch{return null}},lU={getRect:f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return sl("unavailable");const b=sU(f.id);return b?Hm.getRect({target:b}):sl("unresolved")},scrollIntoView:async f=>{const m=await aU(f.id);return m?{success:(await wc(m,{block:f.block,behavior:f.behavior})).ok}:{success:!1}}},cU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},uU={getContext:()=>{const f=Be();if(!f)return{...cU};const m=me()?.table;return{inTable:!0,tableNodeId:f.tableNodeId,rowIndex:f.rowIndex,columnIndex:f.columnIndex,cellNodeId:f.cellNodeId,rows:typeof m?.rows=="number"?m.rows:null,columns:typeof m?.columns=="number"?m.columns:null}},isInTable:()=>Be()!=null},$m={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:dt.searchUnavailable};let Nn={...$m};const Gm=new Set,Ta=()=>{const f=x()?.search;return f&&typeof f=="object"?f:null},Ps=()=>{const f=T()?.search;return f&&typeof f=="object"?f:null},ih=()=>{const f=Ta();if(f&&typeof f.setSession=="function")return!0;const m=Ps();return!!m&&typeof m.query=="function"&&typeof m.getState=="function"},es=()=>{for(const f of[...Gm])try{f(Nn)}catch{}},ii=f=>(Nn={...Nn,...f},es(),Nn);let ao=0,Cc=null;const WA=()=>{const f=Cc;Cc=null,f&&Pt(()=>(f(),null),null)},dU=()=>{ao+=1,WA();const f=ih();Nn={...$m,available:f,reason:f?void 0:dt.searchUnavailable},es()};_a.push(dU);const fU=f=>{if(!f)return!1;const m=f.queryError;if(m&&typeof m=="object"&&m.code==="invalid-pattern")return!0;const b=f.rejection;return f.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},x2=(f,m=!1)=>{const b=f&&typeof f=="object"?f:null;if(!b)return null;const I=Array.isArray(b.matches)?b.matches:[],E=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:I.length,B=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:E,activeIndex:B,canReplace:b.canReplace===!0||m,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...fU(b)?{invalidPattern:!0}:{}}},_o=()=>{const f=N("find.replace"),m=N("find.replaceAll");return f?.enabled===!0||m?.enabled===!0},Ao=(f,m=!1)=>{const b=x2(f,m);if(!b){ii({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}ii({...b.query!==void 0?{query:b.query}:{},total:b.total,activeIndex:b.activeIndex,canReplace:b.canReplace,...b.includeDeletedText!==void 0?{includeDeletedText:b.includeDeletedText}:{},...b.regex!==void 0?{regex:b.regex}:{},reason:b.invalidPattern?dt.searchInvalidPattern:void 0})},xa=()=>{const f=Ta();if(f&&typeof f.getState!="function")return Nn={...Nn,available:ih(),reason:ih()?void 0:dt.searchUnavailable},Nn;if(!f){const b=Ps();if(b&&typeof b.getState=="function"){const I=x2(Pt(()=>b.getState(),null),_o());if(I)return Nn={...Nn,...I.query!==void 0?{query:I.query}:{},total:I.total,activeIndex:I.activeIndex,canReplace:I.canReplace,available:!0,reason:I.invalidPattern?dt.searchInvalidPattern:void 0,open:Nn.open||!!I.query},Nn}return Nn={...$m,query:Nn.query,caseSensitive:Nn.caseSensitive,includeDeletedText:Nn.includeDeletedText},Nn}const m=x2(Pt(()=>f.getState(),null));return m&&(Nn={...Nn,...m.query!==void 0?{query:m.query}:{},total:m.total,activeIndex:m.activeIndex,canReplace:m.canReplace,...m.includeDeletedText!==void 0?{includeDeletedText:m.includeDeletedText}:{},...m.regex!==void 0?{regex:m.regex}:{},available:!0,reason:m.invalidPattern?dt.searchInvalidPattern:void 0,open:Nn.open||!!m.query}),Nn},nd=f=>{const m=f&&typeof f=="object"?f:null;if(m?.status==="committed")return{ok:!0};if(m?.status==="rejected"&&m.reason==="read-only")return{ok:!1,reason:dt.documentReadonly};const b=m?.rejection;return m?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:dt.documentReadonly}:{ok:!1,reason:dt.operationUnavailable}},Wm=Po({get:()=>xa(),subscribe:f=>(Gm.add(f),()=>Gm.delete(f))}),hU={get:Wm.get,getSnapshot:Wm.getSnapshot,subscribe:Wm.subscribe,observe:Wm.observe,open:()=>ih()?(ii({available:!0,open:!0,reason:void 0}),{ok:!0}):(ii({available:!1,open:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}),close:()=>{if(ao+=1,Cc)WA();else{const f=Ta();if(f&&typeof f.clear=="function")Pt(()=>f.clear(),null);else{const m=Ps();m&&typeof m.query=="function"&&Pt(()=>m.query({query:""}),null)}}Nn={...$m,available:ih(),reason:void 0},Nn.available||(Nn.reason=dt.searchUnavailable),es()},search:(f,m)=>{const b=Ta(),I=!!m?.caseSensitive,E=m?.includeDeletedText===!0,B=m?.regex===!0,W=++ao;if(!b||typeof b.setSession!="function"){const fe=Ps();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){ii({query:f,caseSensitive:I,includeDeletedText:E,regex:B,available:!0,open:!0,reason:void 0}),Cc=()=>{fe.query({query:""})};const Le=Pt(()=>fe.query({query:f,caseSensitive:I,includeDeletedText:E,regex:B}),null);return Sr(Le)?Promise.resolve(Le).then(Ue=>{W===ao&&Ao(Ue,_o())},()=>{W===ao&&ii({available:!1,reason:dt.searchUnavailable})}):Ao(Le,_o()),Ao(Pt(()=>fe.getState(),null),_o()),Nn}return ii({query:f,total:0,activeIndex:-1,available:!1,caseSensitive:I,includeDeletedText:E,regex:B,reason:dt.searchUnavailable})}ii({query:f,caseSensitive:I,includeDeletedText:E,regex:B,available:!0,open:!0,reason:void 0}),Cc=()=>{typeof b.clear=="function"&&b.clear()};const ie=Pt(()=>b.setSession(f,{caseSensitive:I,includeDeletedText:E,...B?{regex:!0}:{},highlight:!0}),null);if(Ao(ie),f.length>0&&Nn.total===0&&Nn.reason!==dt.searchInvalidPattern){const fe=Ps();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){const Le=Cc;Cc=()=>{Le?.(),fe.query({query:""})};const Ue=Pt(()=>fe.query({query:f,caseSensitive:I,includeDeletedText:E,regex:B}),null);Sr(Ue)?Promise.resolve(Ue).then(je=>{W===ao&&Ao(je,_o())},()=>{W===ao&&ii({available:!1,reason:dt.searchUnavailable})}):Ao(Ue,_o()),Ao(Pt(()=>fe.getState(),null),_o())}}return Nn},next:()=>{const f=Ta();if(!f||typeof f.next!="function"){const m=Ps();if(!m||typeof m.next!="function"||typeof m.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(Nn.total===0)return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.next(),null);if(Sr(b)){const I=ao;Promise.resolve(b).then(E=>{I===ao&&Ao(E,_o())}).catch(()=>{I===ao&&ii({available:!1,reason:dt.searchUnavailable})})}else Ao(b,_o());return Ao(Pt(()=>m.getState(),null),_o()),{ok:!0}}return Nn.total===0?{ok:!1,reason:dt.operationUnavailable}:(Ao(Pt(()=>f.next(),null)),{ok:!0})},previous:()=>{const f=Ta();if(!f||typeof f.previous!="function"){const m=Ps();if(!m||typeof m.previous!="function"||typeof m.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(Nn.total===0)return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.previous(),null);if(Sr(b)){const I=ao;Promise.resolve(b).then(E=>{I===ao&&Ao(E,_o())}).catch(()=>{I===ao&&ii({available:!1,reason:dt.searchUnavailable})})}else Ao(b,_o());return Ao(Pt(()=>m.getState(),null),_o()),{ok:!0}}return Nn.total===0?{ok:!1,reason:dt.operationUnavailable}:(Ao(Pt(()=>f.previous(),null)),{ok:!0})},clear:()=>{ao+=1;const f=Ta();if(f&&typeof f.clear=="function"&&Pt(()=>f.clear(),null),!f||typeof f.clear!="function"){const m=Ps();m&&typeof m.query=="function"&&Pt(()=>m.query({query:""}),null)}ii({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:f=>{const m=Ta();if(!m){const I=Ps();if(!I||typeof I.replace!="function"||typeof I.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(!_o())return{ok:!1,reason:dt.operationUnavailable};const E=Pt(()=>I.replace({replacement:typeof f=="string"?f:""}),null);if(Sr(E)){const B=ao;xa(),es();const W=()=>B===ao;return Promise.resolve(E).then(ie=>(W()&&(Ao(ie,_o()),xa(),es()),nd(ie)),()=>(W()&&ii({available:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}))}return xa(),es(),nd(E)}if(typeof m.replaceCurrent!="function")return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.replaceCurrent(typeof f=="string"?f:""),null);return xa(),es(),nd(b)},replaceAll:f=>{const m=Ta();if(!m){const I=Ps();if(!I||typeof I.replaceAll!="function"||typeof I.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(!_o())return{ok:!1,reason:dt.operationUnavailable};const E=Pt(()=>I.replaceAll({replacement:typeof f=="string"?f:""}),null);if(Sr(E)){const B=ao;xa(),es();const W=()=>B===ao;return Promise.resolve(E).then(ie=>(W()&&(Ao(ie,_o()),xa(),es()),nd(ie)),()=>(W()&&ii({available:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}))}return xa(),es(),nd(E)}if(typeof m.replaceAll!="function")return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.replaceAll(typeof f=="string"?f:""),null);return xa(),es(),nd(b)}},KA=Ho(f=>f.styles),Km=Po(KA),pU={get:Km.get,getSnapshot:Km.getSnapshot,subscribe:Km.subscribe,observe:Km.observe,getCatalog:f=>ce(f).value,getQuickGallery:()=>KA.get().quickGallery,getActiveParagraphStyle:()=>Te(pt.selection,Se().cache).style},qA={select:xs,get state(){return pt},selection:FA,commands:Wj,toolbar:Kj,comments:qj,trackChanges:Zj,contentControls:Jj,fonts:eU,zoom:tU,document:nU,viewport:Hm,metadata:lU,tables:uU,search:hU,styles:pU,formatPainter:{setPointerSelecting(f){J||(h={...h,pointerSelecting:f})},notifyPointerUp(){J||(h={...h,pointerSelecting:!1},LA())},setKeyboardSelecting(f){J||(h={...h,keyboardSelecting:f})},notifyKeyUp(){J||(h={...h,keyboardSelecting:!1},LA())},cancel(){J||Mm()},onModeChange(f){return J?()=>{}:(p.add(f),()=>p.delete(f))}},createScope:()=>{const f=[];return{select:(m,b)=>{const I=xs(m,b);return{get:I.get,subscribe:E=>{const B=I.subscribe(E);return f.push(B),B}}},dispose:()=>{for(const m of f.splice(0))m()}}},destroy:()=>{if(!J){J=!0,mV(_n,bt),br.reset(),De(),q&&(clearTimeout(q),q=null),te&&(clearTimeout(te),te=null,Y=0),U?.timer&&(clearTimeout(U.timer),U.timer=null),U=null,ye&&(clearTimeout(ye),ye=null),Ar&&(clearTimeout(Ar),Ar=null),oo&&oo(),oo=null,ro=null,_i.clear(),O.clear();for(const f of gc.splice(0))f();kt&&kt(),kt=null,et=null,Ot&&Ot(),Ot=null,ht=null,Mt&&Mt(),Mt=null,Xt=null,pr&&pr(),pr=null,jn=null,zr&&zr(),zr=null,er=null;for(const f of td)Um(f);td.clear(),qe.clear(),Gm.clear(),g+=1,p.clear(),ao+=1,he.clear()}}};return S=qA,qA}var ij=[{value:"Arial",label:"Arial",previewFamily:"Arial, sans-serif"},{value:"Calibri",label:"Calibri",previewFamily:"Calibri, sans-serif"},{value:"Courier New",label:"Courier New",previewFamily:'"Courier New", monospace'},{value:"Georgia",label:"Georgia",previewFamily:"Georgia, serif"},{value:"Times New Roman",label:"Times New Roman",previewFamily:'"Times New Roman", serif'},{value:"Verdana",label:"Verdana",previewFamily:"Verdana, sans-serif"}];function sj(e){const t=e.trim(),n=t[0];if(n==='"'||n==="'"){const o=t.indexOf(n,1);if(o>0)return t.slice(1,o).trim()}const r=t.indexOf(",");return(r===-1?t:t.slice(0,r)).trim().replace(/^["']|["']$/g,"")}function aj(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(!n||typeof n!="object")continue;const r=n,o=typeof r.logicalFamily=="string"?sj(r.logicalFamily):"";if(!o)continue;const i=typeof r.previewFamily=="string"&&r.previewFamily.trim()?r.previewFamily.trim():o;t.push({value:o,label:o,previewFamily:i})}return t}function lj(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(!n||typeof n!="object")continue;const r=n,o=typeof r.value=="string"?r.value.trim():"";if(!o)continue;const i=typeof r.label=="string"&&r.label.trim()?r.label.trim():o,s=typeof r.previewFamily=="string"&&r.previewFamily.trim()?r.previewFamily.trim():o;t.push({value:o,label:i,previewFamily:s})}return t}function cj(e,t=[]){const n=[],r=new Set,o=s=>{const a=String(s.value).trim().toLowerCase();!a||r.has(a)||(r.add(a),n.push(s))};for(const s of e)o(s);const i=t.length?t:ij;for(const s of i)o(s);return n}var uj=[{value:"8",label:"8"},{value:"9",label:"9"},{value:"10",label:"10"},{value:"11",label:"11"},{value:"12",label:"12"},{value:"14",label:"14"},{value:"16",label:"16"},{value:"18",label:"18"},{value:"24",label:"24"},{value:"36",label:"36"}];function dj(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}Lt();var fj=['[data-sdt-type="structuredContent"][data-sdt-id]','[data-sdt-type="structuredContent"][data-sdt-container-id]','[data-sdt-container-type="structuredContent"][data-sdt-container-id]'].join(", "),hj=Object.freeze(["#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F","#BB8FCE","#85C1E2","#F1948A","#82E0AA","#F8C471","#AED6F1","#D7BDE2","#A3E4D7","#F0B27A","#AEB6BF","#E74C3C","#2ECC71","#3498DB","#E67E22","#1ABC9C","#9B59B6","#34495E","#F39C12"]);async function pj(e,t){const n=new p6.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function g2(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function IA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function mj(e,t){if(!e)return()=>{};if(g2(e))return t(),()=>{};const n=typeof e.on=="function"?e.on.bind(e):null,r=typeof e.off=="function"?e.off.bind(e):null;if(!n)return t(),()=>{};let o=!1;const i=()=>{o||(o=!0,r?.("synced",a),r?.("sync",l))},s=()=>{o||(i(),t())},a=()=>{IA(e),s()},l=c=>{c!==!1&&(c===!0||g2(e))&&(IA(e),s())};return n("synced",a),n("sync",l),g2(e)&&s(),i}function gj(e,t){const n=e.composedPath();if(!n.includes(t))return null;const r=n.find(a=>a instanceof HTMLElement&&a.matches(fj));if(!r)return null;const o=n.some(a=>a instanceof HTMLElement&&a.classList.contains(ip.BLOCK_SDT_LABEL)),i=r.getAttribute("data-sdt-container-id")?.trim()||null,s=r.getAttribute("data-sdt-id")?.trim()||null;return o?i??s:s??i}function vj(e){if(!e||typeof e!="object")return[];const t=e.items;return Array.isArray(t)?t:[]}function yj(e){if(!e||typeof e.id!="string"||e.kind!=="inline"&&e.kind!=="block"||typeof e.controlType!="string")return null;const t=e.properties?.tag,n=e.properties?.alias;return{id:e.id,controlType:e.controlType,scope:e.kind,...typeof t=="string"&&t?{tag:t}:{},...typeof n=="string"&&n?{alias:n}:{}}}function Zo(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function bj(e){const t=e&&typeof e=="object"?e.code:null;return t==="comment-export-missing-story-reference"||t==="v2-worker-comment-export-mode-unsupported"}function EA(e){return typeof e=="string"&&e.length>0?e:null}function v2(e){return e?Zo(e)?EA(e.documentId??e.options?.documentId??null):EA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function wj(e){if(!e||Zo(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function Gi(e){if(!e)return null;if(Zo(e))return e.fonts??null;const t=wj(e);return t?{getReport:()=>t.getFontReport?.()??[],getMissingFonts:()=>t.getMissingFonts?.()??[],getDocumentFonts:()=>[...new Set((t.getFontReport?.()??[]).map(n=>n.logicalFamily))],getDocumentFontOptions:()=>t.getDocumentFontOptions?.()??[],getFontFamilyOptions:()=>t.getFontFamilyOptions?.()??[],getLastFontsChangedPayload:()=>t.getLastFontsChangedPayload?.()??null,map:n=>t.mapFonts(n),unmap:n=>t.unmapFonts(n),add:n=>t.addFonts(Array.isArray(n)?n:[n]),preload:n=>t.preloadFonts(n)}:null}var _m=class extends Ym.default{static{this.allowedTypes=[Fr,Ol,tp]}#t;#n;#e;#r;#i;#s;#d;#h;#f;#c;#p;get uiConfig(){return this.#p}#o;get interactionConfig(){return this.#o}#l;get surfacesConfig(){return this.#l}#g;#u;#y;#w;constructor(e){if(super(),this.#t=!1,this.#n=!1,this.#e=null,this.#r=null,this.#i=null,this.#s=null,this.#d=null,this.#h=null,this.#f=n=>{this.#k(n)},this.#c=null,this.#p=V4({}),this.#o=j4({}),this.#l=H4({}),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,this.#u=new hN,this.#y=null,this.#w=!1,this.config={selector:"#superdoc",documentMode:"editing",allowSelectionInViewMode:!1,role:"editor",document:{},documents:[],editorExtensions:[],colors:[],users:[],user:{...X0},layoutEngineOptions:{},modules:{},licenseKey:void 0,telemetry:{enabled:!0},title:"SuperDoc",conversations:[],isInternal:!1,comments:{visible:!1},toolbarGroups:["left","center","right"],toolbarIcons:{},toolbarTexts:{},uiDisplayFallbackFont:"Arial, Helvetica, sans-serif",isDev:!1,disablePiniaDevtools:!1,onEditorBeforeCreate:()=>null,onEditorCreate:()=>null,onEditorDestroy:()=>null,onSourceComplete:()=>null,onSourceSignalsComplete:()=>null,onContentError:()=>null,onReady:()=>null,onCommentsUpdate:()=>null,onContentControlActiveChange:()=>null,onContentControlClick:()=>null,onAwarenessUpdate:()=>null,onLocked:()=>null,onPdfDocumentReady:()=>null,onSidebarToggle:()=>null,onCollaborationReady:()=>null,onEditorUpdate:()=>null,onCommentsListChange:()=>null,onException:()=>null,onListDefinitionsChange:()=>null,onPaginationUpdate:()=>null,onTransaction:()=>null,disableContextMenu:!1,viewOptions:{layout:"print"},useLayoutEngine:!0},this.#Z=new WeakSet,this.#Q=null,this.#j=null,this.#M=null,!e.selector)throw new Error("SuperDoc: selector is required");const t=typeof e.selector=="string"?document.querySelector(e.selector):e.selector;if(!(t instanceof HTMLElement))throw new Error("SuperDoc: selector must be a valid CSS selector string or DOM element");this.#g=new tN({getModuleConfig:()=>this.#l}),this.#h=t,t.addEventListener("click",this.#f,!0),this.#I(e,t)}async#k(e){const t=this.#h;if(!t)return;const n=gj(e,t),r=this.activeEditor?.doc?.contentControls?.list;if(!(!n||typeof r!="function"))try{const o=await r();if(this.#t)return;const i=yj(vj(o).find(s=>s.id===n));i&&this.emit("content-control:click",{target:i,source:"pointer"})}catch{return}}async#I(e,t){this.config={...this.config,...e},!this.config.comments||typeof this.config.comments!="object"?this.config.comments={visible:!1}:typeof this.config.comments.visible!="boolean"&&(this.config.comments.visible=!1),lN(this.config),this.config.documents=this.config.documents||[],this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};const n=this.config.viewOptions?.layout==="web",r=this.config.layoutEngineOptions?.flowMode==="semantic";if(n&&this.config.useLayoutEngine&&!r&&(console.warn("[SuperDoc] Web layout uses PM fallback unless layoutEngineOptions.flowMode is set to 'semantic'. Automatically disabling layout engine."),this.config.useLayoutEngine=!1),!n&&r&&(console.warn("[SuperDoc] flowMode 'semantic' is only valid with web layout. Coercing to 'paginated'."),this.config.layoutEngineOptions.flowMode="paginated"),this.editorVersion=2,this.#we(),this.config.user=cN(this.config.user),this.config.layoutEngineOptions.virtualization||(this.config.layoutEngineOptions.virtualization={enabled:!0,window:5,overscan:1}),this.config.modules=this.config.modules||{},Object.prototype.hasOwnProperty.call(this.config.modules,"comments")||(this.config.modules.comments={}),this.config.modules.comments=Ok(this.config.modules.comments),this.#p=V4(this.config),this.#o=j4(this.config),this.#l=H4(this.config),this.config.disableContextMenu=!this.#p.contextMenu.enabled,this.config.rulers=this.#p.ruler.enabled,this.#p.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#p.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#o.comments)}if(this.config.colors=k6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.4.0-next.13",this.#C("π¦ [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||ts(),this.colors=this.config.colors??[],this.#D(),await T8(),this.#t)return;if(await this.#b(this.config.modules),this.#t){this.#de();return}this.config.cspNonce&&this.#P(),this.user=this.config.user,this.users=this.config.users||[],this.socket=null,this.isDev=this.config.isDev||!1,this.activeEditor=null,this.comments=[],this.#y||(this.#y=this.#u.subscribe(i=>{this.#ke(i.nextRuntimeId,i.legacyEditorProjection)})),this.isLocked=this.config.isLocked||!1,this.lockedBy=this.config.lockedBy||null;const o=document.createElement("div");o.style.display="contents",t.appendChild(o),this.#d=o,this.#S(),this.#L(),this.#Se(),this.#E()}#E(){if(this.#T(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#d)}#L(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new ED({Renderer:QF,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#m("requiredNumberOfEditors").documents.filter(e=>e.type===Fr).length}get ui(){return this.#c||(this.#c=oj({superdoc:this}),this.#t&&this.#c.destroy()),this.#c}get state(){return{documents:this.#m("state").documents,users:this.users}}getDocumentRuntimeForDocument(e){return typeof e!="string"||e.length===0?null:(this.superdocStore?.documents??[]).find(t=>t?.getEditor?.()?.options?.documentId===e)?.getDocumentRuntime?.()??null}getComment(e){return typeof e!="string"||e.length===0?null:this.commentsStore?.getComment?.(e)??null}get element(){return typeof this.config.selector=="string"?document.querySelector(this.config.selector):this.config.selector}#P(){const e=this.config.cspNonce,t=document.createElement;document.createElement=function(n){const r=t.call(this,n);return n.toLowerCase()==="style"&&r.setAttribute("nonce",e),r}}#D(){const e=this.config.document,t=!!e&&typeof e=="object"&&Object.keys(e)?.length,n=!!e&&typeof e=="string"&&e.length>0,r=!!e&&typeof File=="function"&&e instanceof File,o=!!e&&e instanceof Blob&&!(e instanceof File),i=this.config.documents&&this.config.documents?.length;if(t&&i&&console.warn("π¦ [superdoc] You can only provide one of document or documents"),t){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}else if(n)this.config.documents=[{id:ts(),type:Fr,url:this.config.document,name:"document.docx"}];else if(r){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}else if(o){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Xd(s);if(!a||typeof a!="object")return a;const l=typeof a=="object"&&"id"in a&&a.id||s&&typeof s=="object"&&"id"in s&&s.id;return{...a,id:l||ts()}}))}#T(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=mD({disablePiniaDevtools:!!this.config.disablePiniaDevtools});this.app=e,this.pinia=t,this.app.config.globalProperties.$config=this.config,this.app.config.globalProperties.$documentMode=this.config.documentMode,this.app.config.globalProperties.$superdoc=this,this.app.provide("surfaceManager",this.#g),this.superdocStore=n,this.commentsStore=r,this.highContrastModeStore=o,typeof this.superdocStore.setExceptionHandler=="function"&&this.superdocStore.setExceptionHandler(s=>this.emit("exception",s)),this.superdocStore.init(this.config);const i=this.config.modules.comments;this.commentsStore.init(i||{}),this.isCollaborative&&h8(this),this.#ue()}#a(e,t){t&&this.on(e,t)}#S(){this.#a("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#a("editorCreate",this.config.onEditorCreate),this.#a("editorDestroy",this.config.onEditorDestroy),this.#a("source:complete",this.config.onSourceComplete),this.#a("source:signals-complete",this.config.onSourceSignalsComplete),this.#a("ready",this.config.onReady),this.#a("comments-update",this.config.onCommentsUpdate),this.#a("content-control:active-change",this.config.onContentControlActiveChange),this.#a("content-control:click",this.config.onContentControlClick),this.#a("awareness-update",this.config.onAwarenessUpdate),this.#a("locked",this.config.onLocked),this.#a("pdf:document-ready",this.config.onPdfDocumentReady),this.#a("sidebar-toggle",this.config.onSidebarToggle),this.#a("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#$(e?.editor??null)),this.#a("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#a("exception",this.config.onException),this.#a("list-definitions-change",this.config.onListDefinitionsChange),this.#a("pagination-update",this.config.onPaginationUpdate),this.#a("fonts-resolved",this.config.onFontsResolved),this.#a("fonts-changed",this.config.onFontsChanged),this.#a("zoomChange",this.config.onZoomChange),this.#a("viewport-change",this.config.onViewportChange)}async#b({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:ts(),type:Fr,name:"document.docx"}]),this.config.v2CollaborationPreflightFailure={code:"collaboration-v1-config-unsupported",message:"SuperDoc v2 cannot use modules.collaboration because it is the SuperDoc v1 collaboration API. SuperDoc did not attach the provider or change the document. Configure Document.v2Collaboration with a v2 room instead."},this.config.documents):this.config.documents}#ee(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=Jr(e),this.provider=Jr(t),this.#_();const n=this.config;this._cleanupAwareness=l8(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#H(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null),this.isCollaborative=!1,this._commentsCollabInitialized=!1,this.ydoc=void 0,this.provider=void 0;const e=this.config;delete e.modules.collaboration,e.documents.forEach(t=>{delete t.ydoc,delete t.provider})}#A(){if(this.#r){try{this.#r()}catch{}this.#r=null}if(this.#i){try{this.#i()}catch{}this.#i=null}}#$(e){this.#A(),Zo(e)&&(this.#O(e),this.#x(e))}#O(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=SD(()=>this.user),r=o=>{if(this.#t)return;const i=n.next(o);this.emit("awareness-update",{...i,superdoc:this})};try{const o=t.getSnapshot?.();o&&r(o),this.#r=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#x(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#t||this.#v(!!r.isLocked,this.#F(r.lockedBy??null))};try{if(this.#s&&typeof t.setLocked=="function"){const o=this.#s;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#s=null}const r=t.getSnapshot?.();r&&n(r),this.#i=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#F(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#G(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#v(e,t){this.isLocked===e&&this.#G(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#C("π¦ [superdoc] Locking superdoc:",e,t,`
|
|
102
|
+
`;Lt();var bs=e=>{e.expand.value=!1};function r2(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function iA(e){const t=Array.isArray(e?.segments)?e.segments:[];if(e?.kind!=="text"||!t.length)return null;const n=t[0],r=t[t.length-1];if(!n?.blockId||!r?.blockId||!n.range||!r.range)return null;const o=e.story;return{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.range.start??0,...o?{story:o}:{}},end:{kind:"text",blockId:r.blockId,offset:r.range.end??0,...o?{story:o}:{}},...o?{story:o}:{}}}function Gz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function sA(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Wz(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function Kz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}var qz=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=En({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),c=(r??VB).map(KB),u=En({type:"dropdown",name:"fontFamily",tooltip:n.fontFamily,command:"setFontFamily",defaultLabel:"Arial",label:"Arial",markName:"textStyle",labelAttr:"fontFamily",hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,isWide:!0,style:{width:"116px"},suppressActiveHighlight:!0,attributes:{ariaLabel:"Font family"},options:c,onActivate:({fontFamily:nt}={},Dt=!1)=>{if(Dt){u.label.value="",u.selectedValue.value="";return}if(!nt)return;nt=nt.split(",")[0],u.label.value=nt;const Gt=c.find(Nt=>Nt.label===u.defaultLabel.value),Rn=c.find(Nt=>Nt.label===nt);Rn?u.selectedValue.value=Rn.key:Gt?u.selectedValue.value=Gt.key:u.selectedValue.value=""},onDeactivate:()=>{u.label.value=u.defaultLabel.value;const nt=c.find(Dt=>Dt.label===u.defaultLabel.value);nt?u.selectedValue.value=nt.key:u.selectedValue.value=""}}),d=En({type:"dropdown",name:"ai",dropdownStyles:{padding:0,outline:"none"},tooltip:n.ai,icon:t.ai,hideLabel:!0,hasCaret:!1,isWide:!0,suppressActiveHighlight:!0,attributes:{ariaLabel:"AI"},options:[{type:"render",key:"ai",render:()=>h(d)}]});function h(nt){const Dt=sA(e),Gt=Dt?.selectionTarget??iA(Dt?.target),Rn=Dt?.empty?"":Gz(Dt),Nt=Kz(e),dn=()=>bs(nt),Mn=()=>{const De=e.pendingSelectionCapture;De&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(De)};return $r("div",{},[$r(wz,{handleClose:dn,selectedText:Rn,target:Gt,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Nt?.apiKey||e.config?.aiApiKey||"",endpoint:Nt?.endpoint||e.config?.aiEndpoint||"",restoreSelection:Mn})])}const g=UB,p=En({type:"dropdown",name:"fontSize",defaultLabel:"12",label:"12",style:{width:"56px"},markName:"textStyle",labelAttr:"fontSize",tooltip:n.fontSize,hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,suppressActiveHighlight:!0,isWide:!0,command:"setFontSize",attributes:{ariaLabel:"Font size"},options:g,onActivate:({fontSize:nt},Dt=!1)=>{if(Dt){p.label.value="",p.selectedValue.value="";return}const Gt=g.find(Mn=>Mn.label===String(p.defaultLabel.value));if(!nt){p.label.value=p.defaultLabel.value,Gt?p.selectedValue.value=Gt.key:p.selectedValue.value="";return}let Rn=LN(nt,12);Rn<8&&(Rn=8),Rn>96&&(Rn=96);let Nt=String(Rn);const dn=g.find(Mn=>Mn.label===Nt||Mn.key===Nt);dn?p.selectedValue.value=dn.key:p.selectedValue.value="",p.label.value=Nt},onDeactivate:()=>{p.label.value=p.defaultLabel.value;const nt=g.find(Dt=>Dt.label===String(p.defaultLabel.value));nt?p.selectedValue.value=nt.key:p.selectedValue.value=""}}),v=En({type:"separator",name:"separator",isNarrow:!0}),k=En({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),C=En({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),_=En({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=En({type:"dropdown",name:"highlight",icon:t.highlight,hideLabel:!0,markName:"highlight",labelAttr:"color",active:!1,tooltip:n.highlight,command:"setHighlight",noArgumentCommand:"unsetHighlight",suppressActiveHighlight:!0,attributes:{ariaLabel:"Highlight"},options:[{key:"color",type:"render",render:()=>n2(e,y,[],!0)}],onActivate:({color:nt})=>{y.iconColor.value=nt||""},onDeactivate:()=>y.iconColor.value=""}),w=En({type:"dropdown",name:"color",icon:t.color,hideLabel:!0,markName:"textStyle",labelAttr:"color",active:!1,tooltip:n.color,command:"setColor",suppressActiveHighlight:!0,attributes:{ariaLabel:"Color"},options:[{key:"color",type:"render",render:()=>n2(e,w)}],onActivate:({color:nt})=>{w.iconColor.value=nt},onDeactivate:()=>w.iconColor.value="#000"}),x=En({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),L=En({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>z(L)}],onActivate:({href:nt})=>{L.attributes.value=r2(L.attributes.value,nt)},onDeactivate:()=>{L.attributes.value=r2(L.attributes.value,null),L.expand.value=!1}});function z(nt){const Dt=sA(e),Gt=Dt?.selectionTarget??iA(Dt?.target),Rn=()=>{const Nt=e.pendingSelectionCapture;Nt&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Nt)};return $r("div",{},[$r(MS,{ui:e.ui,linkItem:nt,textTarget:Gt,restoreSelection:Rn,closePopover:()=>{bs(nt),vu(e)},goToAnchor:()=>{bs(nt);const Nt=nt.attributes.value?.href;if(!Nt)return;const dn=Nt.slice(1),Mn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${dn}']`);Mn&&mf(Mn)}})])}const $=En({type:"options",name:"linkInput",command:"toggleLink",active:!1});L.childItem=$,$.parentItem=L;const R=En({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),F=En({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),X=En({type:"dropdown",name:"table",icon:t.table,hideLabel:!0,labelAttr:"table",active:!1,tooltip:n.table,command:"insertTable",suppressActiveHighlight:!0,attributes:{ariaLabel:"Table"},options:[{key:"table",type:"render",render:()=>D(X)}]});function D(nt){return $r("div",{},[$r(Fz,{onSelect:Gt=>{e.emitCommand({item:nt,argument:Gt}),bs(nt),vu(e)}})])}const V=En({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>N(V)}]}),T=[{label:n.addRowBefore,command:"addRowBefore",icon:t.addRowBefore,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add row before"}},{label:n.addRowAfter,command:"addRowAfter",icon:t.addRowAfter,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add row after"}},{label:n.addColumnBefore,command:"addColumnBefore",icon:t.addColumnBefore,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add column before"}},{label:n.addColumnAfter,command:"addColumnAfter",icon:t.addColumnAfter,bottomBorder:!0,props:{"data-item":"btn-tableActions-option",ariaLabel:"Add column after"}},{label:n.deleteRow,command:"deleteRow",icon:t.deleteRow,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete row"}},{label:n.deleteColumn,command:"deleteColumn",icon:t.deleteColumn,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete column"}},{label:n.deleteTable,command:"deleteTable",icon:t.deleteTable,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete table"}},{label:n.removeBorders,command:"deleteCellAndTableBorders",icon:t.deleteBorders,bottomBorder:!0,props:{"data-item":"btn-tableActions-option",ariaLabel:"Delete cell and table borders"}},{label:n.mergeCells,command:"mergeCells",icon:t.mergeCells,props:{"data-item":"btn-tableActions-option",ariaLabel:"Merge cells"}},{label:n.splitCell,command:"splitCell",icon:t.splitCell,props:{"data-item":"btn-tableActions-option",ariaLabel:"Split cells"}},{label:n.fixTables,command:"fixTables",icon:t.fixTables,props:{"data-item":"btn-tableActions-option",ariaLabel:"Fix tables"}}];function N(nt){return $r(Hz,{options:T,onSelect:Dt=>{bs(nt);const{command:Gt}=Dt;e.emitCommand({item:nt,argument:{command:Gt}})}})}const Q=En({type:"dropdown",name:"textAlign",tooltip:n.textAlign,icon:t.alignLeft,command:"setTextAlign",hasCaret:!0,markName:"textAlign",labelAttr:"textAlign",suppressActiveHighlight:!0,attributes:{ariaLabel:"Text align"},options:[{type:"render",render:()=>$r("div",{},[$r(XB,{onSelect:Dt=>{bs(Q);const Gt={...Q,command:"setTextAlign"};Gt.command="setTextAlign",e.emitCommand({item:Gt,argument:Dt}),K(Q,Dt),vu(e)}})]),key:"alignment"}],onActivate:({textAlign:nt})=>{K(Q,nt)},onDeactivate:()=>{K(Q,"left")}}),K=(nt,Dt)=>{let Gt=Dt==="both"?"justify":Dt,Rn={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Nt=Rn[Gt]??Rn.left;nt.icon.value=Nt},se=En({type:"dropdown",name:"list",command:"toggleBulletListStyle",splitButton:!0,splitButtonCommand:"toggleBulletList",icon:t.bulletList,hasCaret:!0,tooltip:n.bulletList,restoreEditorFocus:!0,attributes:{ariaLabel:"Bullet list"},options:[{type:"render",key:"bullet-style-buttons",render:()=>{const nt=Dt=>{bs(se);const Gt={...se,command:"toggleBulletListStyle"};e.emitCommand({item:Gt,argument:Dt})};return $r(rA,{buttons:JB,iconSize:25,selectedStyle:se.selectedValue.value,onSelect:nt})}}]}),me=En({type:"dropdown",name:"numberedlist",command:"toggleOrderedListStyle",splitButton:!0,splitButtonCommand:"toggleOrderedList",icon:t.numberedList,hasCaret:!0,tooltip:n.numberedList,restoreEditorFocus:!0,attributes:{ariaLabel:"Numbered list"},options:[{type:"render",key:"numbered-style-buttons",render:()=>{const nt=Dt=>{bs(me);const Gt={...me,command:"toggleOrderedListStyle"};e.emitCommand({item:Gt,argument:Dt})};return $r(rA,{buttons:ez,iconSize:30,selectedStyle:me.selectedValue.value,onSelect:nt})}}]}),Be=En({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),he=En({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ve=En({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ue=En({type:"dropdown",name:"zoom",allowWithoutEditor:!0,tooltip:n.zoom,defaultLabel:"100%",label:"100%",hasCaret:!0,command:"setZoom",isWide:!0,style:{width:"71px",minWidth:"71px"},inlineTextInputVisible:!1,hasInlineTextInput:!0,attributes:{ariaLabel:"Zoom"},options:[{label:"50%",key:.5,props:{"data-item":"btn-zoom-option"}},{label:"75%",key:.75,props:{"data-item":"btn-zoom-option"}},{label:"90%",key:.9,props:{"data-item":"btn-zoom-option"}},{label:"100%",key:1,props:{"data-item":"btn-zoom-option"}},{label:"125%",key:1.25,props:{"data-item":"btn-zoom-option"}},{label:"150%",key:1.5,props:{"data-item":"btn-zoom-option"}},{label:"200%",key:2,props:{"data-item":"btn-zoom-option"}}],onActivate:({zoom:nt})=>{nt&&(ue.label.value=nt)}}),ke=En({type:"dropdown",name:"measurementUnit",allowWithoutEditor:!0,tooltip:n.measurementUnit,defaultLabel:"in",label:"in",hasCaret:!0,command:"setMeasurementUnit",group:"right",style:{width:"52px",minWidth:"52px"},inlineTextInputVisible:!1,hasInlineTextInput:!1,attributes:{ariaLabel:"Measurement unit"},options:[{label:"Inches",key:"in",props:{"data-item":"btn-measurement-unit-option"}},{label:"Centimeters",key:"cm",props:{"data-item":"btn-measurement-unit-option"}}],onActivate:({measurementUnit:nt})=>{nt&&(ke.label.value=nt)}}),re=En({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Re=En({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),Je=En({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),st=En({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),Tt=En({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),Ee=En({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),$e=(nt,Dt)=>nt==="editor"?Dt:nt==="suggester"?Dt.filter(Gt=>Gt.value==="suggesting"):Dt.filter(Gt=>Gt.value==="viewing"),qe=nt=>nt==="editor"?"Editing":nt==="suggester"?"Suggesting":"Viewing",J=En({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:qe(s),label:qe(s),hasCaret:s==="editor",isWide:!0,style:{display:"flex",justifyContent:"flex-end"},inlineTextInputVisible:!1,hasInlineTextInput:!1,group:"right",disabled:s!=="editor",attributes:{dropdownPosition:"right",className:"sd-toolbar-item--doc-mode",ariaLabel:"Document mode"},options:[{type:"render",render:()=>ee(J)}]}),S=[{label:n.documentEditingMode,value:"editing",icon:t.documentEditingMode,description:n.documentEditingModeDescription},{label:n.documentSuggestingMode,value:"suggesting",icon:t.documentSuggestingMode,description:n.documentSuggestingModeDescription},{label:n.documentViewingMode,value:"viewing",icon:t.documentViewingMode,description:n.documentViewingModeDescription}];function ee(nt){return $r(lz,{options:$e(s,S),onSelect:Dt=>{const Gt=e.superdoc?.activeEditor??e.activeEditor;bs(nt);const{label:Rn,icon:Nt,value:dn}=Dt;J.label.value=Rn,J.icon.value=Nt,e.emitCommand({item:J,argument:dn}),vu(e,Gt)}})}const O=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),H=["search","ruler","undo","overflow","documentMode"],U=En({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),G=En({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),te=En({type:"dropdown",name:"linkedStyles",command:"setLinkedStyle",tooltip:n.linkedStyles,icon:t.paintbrush,defaultLabel:n.formatText,label:n.formatText,hasCaret:!0,isWide:!0,style:{width:"140px"},suppressActiveHighlight:!0,disabled:!1,attributes:{className:"sd-toolbar-item--linked-styles",ariaLabel:"Linked styles"},options:[{type:"render",key:"linkedStyle",render:()=>{const nt=Gt=>{bs(te);const Rn=typeof Gt=="string"?Gt:Gt?.id??null;if(!Rn)return;const Nt={...te,command:"setLinkedStyle"};e.emitCommand({item:Nt,argument:Rn})},Dt=e.getActiveLinkedStyleId?.()??null;return $r("div",{},[$r(fz,{styles:e.getLinkedStyleOptions?.()??[],onSelect:nt,selectedOption:Dt})])}}],onActivate:({styleId:nt,styleName:Dt})=>{const Gt=Dt||nt;te.label.value=nt&&nt!=="Normal"?String(Gt):n.formatText,te.disabled.value=!1},onDeactivate:()=>{te.disabled.value=!0,te.label.value=n.formatText}}),Y=(nt,Dt)=>{if(Dt.value==nt)return $r("div",{innerHTML:$z,class:"dropdown-select-icon"})},q=En({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,restoreEditorFocus:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(nt=>({label:nt.toFixed(2),key:nt,icon:()=>Y(nt,q.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),be=20,ye=32,we=H.reduce((nt,Dt)=>nt+(O.get(Dt)||O.get("default")),0),ze=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],rt=["zoom","fontFamily","fontSize","redo"],it=i<=Ff.lg,Ct=e.config?.showFormattingMarksButton===!0,en=e.config?.showTableOfContentsButton===!0;it&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),it&&(te.attributes.value={...te.attributes.value,className:`${te.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let Rt=[re,Re,Je,st,x,ue,u,v,p,v,l,k,C,_,w,y,v,L,R,...en?[F]:[],X,V,v,Q,se,me,Be,he,q,v,te,v,U,ke,...Ct?[G]:[],Ee,Tt,...Wz(e)?[d]:[],ve,J];if(i<=Ff.md&&o&&(Rt=Rt.filter(nt=>nt.type!=="separator")),e.config.mode!=="docx"){const nt=Rt.findIndex(Gt=>Gt.name.value==="linkedStyles");Rt.splice(nt-1,2);const Dt=["ruler","zoom","undo","redo"];Rt=Rt.filter(Gt=>!Dt.includes(Gt.name.value))}const zt=[];a||(s==="viewer"&&zt.push(Je,st),Rt=Rt.filter(nt=>!zt.includes(nt)));const $t=nt=>H.includes(nt.name.value),_n=[],bt=[];let tn=ye+we;return Rt.forEach(nt=>{const Dt=O.get(nt.name.value)||O.get("default");if(i<Ff.xl+be&&ze.includes(nt.name.value)&&o){if(_n.push(nt),nt.name.value==="linkedStyles"){const Gt=Rt.findIndex(Rn=>Rn.name.value==="linkedStyles");Rt.splice(Gt+1,1)}return}if(i<Ff.sm&&rt.includes(nt.name.value)&&o){_n.push(nt);return}if($t(nt)){bt.push(nt),tn+=Dt;return}tn<i||!o?(bt.push(nt),tn+=Dt):_n.push(nt)}),{defaultItems:bt,overflowItems:_n.filter(nt=>nt.type!=="separator")}},aA={bold:"Bold",fontFamily:"Font family",ai:"AI text generation",fontSize:"Font size",italic:"Italic",underline:"Underline",highlight:"Highlight color",strikethrough:"Strikethrough",color:"Text color",search:"Search",link:"Link",image:"Image",tableOfContents:"Table of contents",table:"Insert table",tableActions:"Table options",addRowBefore:"Insert row above",addRowAfter:"Insert row below",addColumnBefore:"Insert column left",addColumnAfter:"Insert column right",deleteRow:"Delete row",deleteColumn:"Delete column",deleteTable:"Delete table",removeBorders:"Remove borders",mergeCells:"Merge cells",splitCell:"Split cell",fixTables:"Fix tables",textAlign:"Alignment",bulletList:"Bullet list",numberedList:"Numbered list",indentLeft:"Left indent",indentRight:"Right indent",directionLtr:"Left-to-right",directionRtl:"Right-to-left",zoom:"Zoom",measurementUnit:"Measurement unit",undo:"Undo",redo:"Redo",trackChanges:"Track Changes",trackChangesAccept:"Accept changes under selection",trackChangesReject:"Reject changes under selection",trackChangesOriginal:"Toggle Show Original",trackChangesFinal:"Toggle Show Final",clearFormatting:"Clear formatting",copyFormat:"Format painter",lineHeight:"Line height",formatText:"Format text",ruler:"Show or hide ruler",formattingMarks:"Show or hide formatting marks",pageBreak:"Insert page break",documentEditingMode:"Editing",documentSuggestingMode:"Suggesting",documentViewingMode:"Viewing",documentEditingModeDescription:"Edit document directly",documentSuggestingModeDescription:"Edits become suggestions",documentViewingModeDescription:"View clean version of document only",linkedStyles:"Linked styles"},Yz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;Lt();function lA(e){return _N(e)??t2[e]??null}function pm(e,t,n,r={}){if(!e?.commands||!t||typeof e.commands.has=="function"&&!e.commands.has(t))return!1;const o=typeof e.commands.executeAsync=="function"?e.commands.executeAsync:e.commands.execute;if(typeof o!="function")return!1;const i=n===void 0?o.call(e.commands,t):o.call(e.commands,t,n);return i&&typeof i.then=="function"&&Promise.resolve(i).then(()=>r.onSettled?.(),s=>{r.onError?.(s),r.onSettled?.()}),!0}var Xz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Zz=new Set(["list","numberedlist"]);function Qz(e,t){if(e==="fontFamily"||e==="fontSize"||Zz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Xz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function cA(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Jz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var eV=class extends Ym.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...rr},texts:{...aA},fonts:null,hideButtons:!0,responsiveToContainer:!1,mode:"docx",excludeItems:[],groups:null,customButtons:[],showFormattingMarksButton:!1,showTableOfContentsButton:!1};toolbarItems=[];overflowItems=[];#t=null;#n=null;isDev=!1;role="editor";superdoc;toolbarContainer=null;toolbar=null;_detachFontsChanged=null;constructor(e={}){if(super(),this.config={...this.config,...e},this.toolbarItems=[],this.overflowItems=[],this.isDev=e.isDev||!1,this.superdoc=e.superdoc,this.role=e.role||"editor",this.toolbarContainer=null,this.config.icons={...rr,...e.icons},this.config.texts={...aA,...e.texts},this.config.hideButtons=e.hideButtons??!0,this.config.responsiveToContainer=e.responsiveToContainer??!1,this.activeEditor=e.editor??this.superdoc?.activeEditor??null,this.ui=null,this.snapshot=null,this._unsubscribeController=null,this._detachFormatPainterModeChange=null,this._customCommandRegs=new Map,this._reportedInvalidCustomItems=new Set,this._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=Yz(this.config.selector),this.toolbarContainer){const t=(this.config?.uiDisplayFallbackFont||"").toString().trim()||"Arial, Helvetica, sans-serif";this.toolbarContainer.style.setProperty("--sd-ui-font-family",t)}try{if(this.#e(),this.#d(),this.#f(),this.#i(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Dl(WB),this.app.directive("click-outside",Qv),this.app.config.globalProperties.$toolbar=this,this.toolbar=this.app.mount(this.toolbarContainer),this.updateToolbarState()}catch(t){try{this.destroy()}catch{}throw t}}#e(){this.ui=this.superdoc?.ui??null,this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot(),this._unsubscribeController=this.ui.toolbar.subscribe(()=>{this.snapshot=this.ui.toolbar.getSnapshot(),this.updateToolbarState()}),this._detachFormatPainterModeChange=this.ui.formatPainter.onModeChange(e=>{e==="armed"||e==="persistent"?this.#a():this.#S()}))}#r(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#S();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#i(){if(!this.superdoc||typeof this.superdoc.on!="function"||typeof this.superdoc.off!="function")return;const e=()=>{const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#s(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#d(){if(Array.isArray(this.config.groups)){this.config.toolbarGroups=this.config.groups,this.config.groups=null;return}this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length&&(this.config.toolbarGroups=Object.keys(this.config.groups))}getAvailableWidth(){const e=document.documentElement.clientWidth,t=this.toolbarContainer?.offsetWidth??0;return this.config.responsiveToContainer?t:e}#h(e){return e||jB(this.superdoc?.fonts?.getFontFamilyOptions?.()??[])}#f(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=qz({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#h(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=new Set([...n,...r].map(c=>c.name?.value).filter(Boolean)),s=o.map((c,u)=>{try{if(c?.name&&i.has(c.name))throw new Error(`Toolbar item name "${c.name}" is already taken by another item, so this entry is skipped.`);const d=this.#c(c);return i.add(d.name?.value),d}catch(d){const h=`${c?.name??`<unnamed@${u}>`}::${d?.message??String(d)}`;return this._reportedInvalidCustomItems.has(h)||(this._reportedInvalidCustomItems.add(h),this.#b(d,c?.name??null)),null}}).filter(Boolean);s.length&&n.push(...s);let a=[...n.map(c=>c.name.value),...r.map(c=>c.name.value)];if(t){const c=Object.values(this.config.groups).flatMap(h=>h),u=new Set(Object.keys(this.config.groups)),d=s.filter(h=>u.has(h.group?.value||"center")).map(h=>h.name.value);a=[...new Set([...c,...d])]}const l=n.filter(c=>a.includes(c.name.value)).filter(c=>!this.config.excludeItems.includes(c.name.value));if(t)for(const[c,u]of Object.entries(this.config.groups))for(const d of l)u.includes(d.name.value)&&(d.group.value=c);this.toolbarItems=l,this.overflowItems=r.filter(c=>a.includes(c.name.value))}#c(e){const t=En({...e});t.isCustomToolbarItem=!0;const n=e.command;if(typeof n=="function"&&this.ui?.commands?.register){const r=`__builtin_toolbar__${e.name}`;if(!this._customCommandRegs.has(r)){const o=this.ui.commands.register({id:r,execute:i=>{const s=i?.payload&&typeof i.payload=="object"?i.payload:{};return n({...i,item:t,argument:s.argument,option:s.option})}});this._customCommandRegs.set(r,o)}}return t}#p(){this.#f(),this.emit("toolbar-items-changed")}#o(){if(this.config.fonts)return"custom-fonts";const e=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return JSON.stringify(e.map(t=>[t.label,t.value,t.previewFamily]))}getToolbarItemByGroup(e){return this.toolbarItems.filter(t=>(t.group?.value||"center")===e)}getToolbarItemByName(e){return this.#l().find(t=>t.name.value===e)}#l(){return[...this.toolbarItems,...this.overflowItems]}getLinkedStyleOptions(){return this.ui?.styles?.getQuickGallery?.()??[]}getActiveLinkedStyleId(){return this.ui?.styles?.getActiveParagraphStyle?.()?.styleId??null}setActiveEditor(e){this.activeEditor=e;const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#f(),this.updateToolbarState()};#g(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#u(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#y(){const e=this.getToolbarItemByName("documentMode");if(!e)return;const t=(this.snapshot?.commands?.["document-mode"]?.value||"editing").toLowerCase(),n=this.config.texts||{},r=this.config.icons||{},o={editing:{label:n.documentEditingMode||"Editing",icon:r.documentEditingMode||r.documentMode},suggesting:{label:n.documentSuggestingMode||"Suggesting",icon:r.documentSuggestingMode||r.documentMode},viewing:{label:n.documentViewingMode||"Viewing",icon:r.documentViewingMode||r.documentMode}},i=o[t]||o.editing;e.label?.value!==void 0&&(e.label.value=i.label),e.defaultLabel?.value!==void 0&&(e.defaultLabel.value=i.label),e.icon?.value!==void 0&&i.icon&&(e.icon.value=i.icon)}#w(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>n2(this,e,[],!0)};e.nestedOptions.value=[t]}#k(e){return!!e?.active&&e?.value==null}#I(e){return!!e&&e.disabled===!1&&e.value==null}#E(e){const t=e.name.value;if(t==="tableActions"){const i=nA.map(s=>this.snapshot?.commands?.[s]).some(s=>s&&!s.disabled);return e.setDisabled(!i),!0}if(t==="search")return e.setDisabled(!1),!0;if(J0(t)?.disposition==="host-routed")return e.setDisabled(!this.#u(t)),this.#g(t)?e.activate():e.deactivate(),!0;const n=lA(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];Qz(t,r)?e.setDisabled(!1):e.setDisabled(!!r?.disabled);const o={textAlign:()=>{r?.value?e.activate({textAlign:r.value}):e.deactivate()},lineHeight:()=>{e.selectedValue.value=r?.value!=null?r.value:""},zoom:()=>{if(r?.value!=null){const i=typeof r.value=="number"?`${r.value}%`:String(r.value);e.onActivate({zoom:i})}},measurementUnit:()=>{r?.value!=null&&e.onActivate({measurementUnit:String(r.value)})},documentMode:()=>{this.#y()},link:()=>{e.active.value=!!r?.active,e.attributes.value=r2(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#I(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#k(r)){e.activate({},!0);return}e.deactivate()},color:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},highlight:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},linkedStyles:()=>{const i=r?.value,s=typeof i=="string"?i:i?.styleId,a=i&&typeof i=="object"?i.styleName:null;s?e.activate({styleId:s,styleName:a}):e.label.value=this.config.texts?.formatText||"Format text"},list:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},numberedlist:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},default:()=>{r?.active?e.activate():e.deactivate()}};return(o[t]??o.default)(),!0}updateToolbarState(){this.#y(),this.#w();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#L(),this.#l().forEach(n=>{n.allowWithoutEditor?.value&&this.#E(n)})):this.#l().forEach(n=>{n.resetDisabled(),this.#E(n)});const t=this.getToolbarItemByName("copyFormat");t&&(this.snapshot?.copyFormatActive?t.activate():t.deactivate()),this.emit("toolbar-state-change")}#L(){this.#l().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#P(e,t){const n=this.superdoc;if(e==="ruler")return typeof n?.toggleRuler=="function"?(n.toggleRuler(),!0):!1;if(e==="formattingMarks"){if(typeof t=="boolean"&&typeof n?.setShowFormattingMarks=="function")return n.setShowFormattingMarks(t),!0;if(typeof n?.toggleFormattingMarks=="function")return n.toggleFormattingMarks(),!0}return!1}#D(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#b(i,n)};if(n==="image"&&t==null)return this.#T();if(n==="tableActions"){const i=tA[t?.command];return i?pm(this.ui,i,void 0,r):!1}if(J0(n)?.disposition==="unsupported")return!0;const o=lA(n);return o?pm(this.ui,o,t,r):!1}#T(){return this.snapshot?.commands?.image?.disabled||(this.#t||(this.#t=MN({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await xN(e,this.superdoc?.config?.handleImageUpload);pm(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#b(n,"image")})},onError:e=>this.#b(e,"image")})),this.#t.open()),!0}#a(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{cA(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!cA(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Jz(i)&&this.ui.formatPainter.setKeyboardSelecting(!0)},o=()=>{this.ui.formatPainter.setKeyboardSelecting(!1),this.ui.formatPainter.notifyKeyUp()};e.addEventListener("pointerdown",t),e.addEventListener("pointerup",n),e.addEventListener("keydown",r),e.addEventListener("keyup",o),this.#n=()=>{e.removeEventListener("pointerdown",t),e.removeEventListener("pointerup",n),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}}#S(){this.#n&&(this.#n(),this.#n=null)}#b(e,t){const n={error:e instanceof Error?e:new Error(String(e)),originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null},r={...n};this.emit("exception",n),this.superdoc?.emit?.("exception",r)}emitCommand({item:e,argument:t,option:n}){const r=e?.name?.value,{command:o}=e,i=t!=null;if(!(e?.type==="dropdown"&&!i&&(o==="setFontFamily"||o==="setFontSize"))){if(r==="search"){this.superdoc?.emit?.("search:open");return}try{if(J0(r)?.disposition==="host-routed"){this.#P(r,t),this.updateToolbarState();return}if(typeof o=="function"){const s=`__builtin_toolbar__${r}`;this._customCommandRegs.has(s)&&this.ui?.commands?.execute?this.ui.commands.execute(s,{argument:t,option:n}):o({item:e,argument:t,option:n,ui:this.ui,superdoc:this.superdoc}),this.updateToolbarState();return}if(e?.isCustomToolbarItem&&typeof o=="string"){if(!pm(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#b(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#D(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#b(s,r)}}}destroy(){this.#S(),this.#t?.destroy(),this.#t=null,this.#s(),this.#r(),this.app?.unmount(),this.app=null,this.toolbar=null}};function tV(e){return new eV(e)}function nV(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null||Array.isArray(e)!==Array.isArray(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function rV(e){if(!e||typeof e!="object")return{};const t={};e.fonts&&(t.rFonts={ascii:e.fonts.ascii,hAnsi:e.fonts.hAnsi,eastAsia:e.fonts.eastAsia,cs:e.fonts.cs,asciiTheme:e.fonts.asciiTheme,hAnsiTheme:e.fonts.hAnsiTheme,eastAsiaTheme:e.fonts.eastAsiaTheme,csTheme:e.fonts.csTheme,hint:e.fonts.hint}),e.fontFamily!=null&&(t.fontFamily=e.fontFamily),e.lang&&(t.lang={val:e.lang.val,eastAsia:e.lang.eastAsia,bidi:e.lang.bidi}),e.fontSize!=null&&(t.fontSize=e.fontSize),e.fontSizeCs!=null&&(t.fontSizeCs=e.fontSizeCs);const n=mm(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=iV(e.shading);r&&(t.shading=r),e.cs!=null&&(t.cs=e.cs),e.rtl!=null&&(t.rtl=e.rtl),e.bold!=null&&(t.bold=e.bold),e.boldCs!=null&&(t.bCs=e.boldCs),e.italic!=null&&(t.italic=e.italic),e.italicCs!=null&&(t.iCs=e.italicCs);const o=oV(e.underline);o!==void 0&&(t.underline=o),e.strikethrough!=null&&(t.strike=e.strikethrough),e.doubleStrikethrough!=null&&(t.dstrike=e.doubleStrikethrough),e.caps!=null&&(t.caps=e.caps),e.smallCaps!=null&&(t.smallCaps=e.smallCaps),e.outline!=null&&(t.outline=e.outline),e.shadow!=null&&(t.shadow=e.shadow),e.emboss!=null&&(t.emboss=e.emboss),e.imprint!=null&&(t.imprint=e.imprint),e.verticalAlign!=null&&(t.vertAlign=e.verticalAlign),e.characterSpacing!=null&&(t.letterSpacing=e.characterSpacing),e.characterScale!=null&&(t.charScale=e.characterScale),e.kern!=null&&(t.kerning=e.kern),e.baselineShift!=null&&(t.position=e.baselineShift),e.fitTextWidth!=null&&(t.fitText={val:e.fitTextWidth}),e.vanish!=null&&(t.vanish=e.vanish),e.webHidden!=null&&(t.webHidden=e.webHidden),e.specVanish!=null&&(t.specVanish=e.specVanish);const i=sV(e.border);return i&&(t.border=i),t}function mm(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function oV(e){if(e==null)return;const t={};return e.style!=null&&(t.style=e.style),e.color?.model==="rgb"&&(t.color=e.color.value),e.color?.model==="theme"&&(t.themeColor=e.color.theme),Object.keys(t).length>0?t:!0}function iV(e){if(!e)return;const t={},n=mm(e.fill);n!=null&&(t.fill=n);const r=mm(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function sV(e){if(!e)return;const t={};e.style!=null&&(t.val=e.style),e.width!=null&&(t.sz=e.width),e.space!=null&&(t.space=e.space);const n=mm(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function Kl(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}function uA(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function aV(e){const t=[],n=o=>{o&&!t.includes(o)&&t.push(o)};n(e.getAttribute("data-track-change-preferred-target-id"));const r=e.getAttribute("data-track-change-ids");if(r)for(const o of uA(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function dA(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=aV(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const g of a){const p=`trackedChange:${g}`;if(!r.has(p)){r.add(p);const v={type:"trackedChange",id:g};l&&(v.storyKey=l),n.push(v),o.push(v)}}const c=s.getAttribute("data-layout-story");if(c&&o.length>0){for(const g of o)g.story=c;o=[]}const u=s.getAttribute("data-comment-ids");if(u)for(const g of uA(u)){const p=`comment:${g}`;r.has(p)||(r.add(p),n.push({type:"comment",id:g}))}const d=s.getAttribute("data-sdt-type"),h=s.getAttribute("data-sdt-id");if(h&&d==="structuredContent"){const g=`contentControl:${h}`;if(!r.has(g)){r.add(g);const p=s.getAttribute("data-sdt-scope"),v=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:h};(p==="block"||p==="inline")&&(k.scope=p),v&&(k.tag=v),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}var mo=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),rl=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),yu=()=>({oneOf:[{type:"number"},{type:"null"}]}),bu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),lV={type:"object",properties:{style:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},themeColor:{oneOf:[{type:"string",minLength:1},{type:"null"}]}},additionalProperties:!1,minProperties:1},cV={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},uV=()=>({oneOf:[{type:"boolean"},{type:"null"},lV]}),dV=()=>({oneOf:[{type:"array",items:cV,minItems:1},{type:"null"}]});function gm(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function fV(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var o2=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:gm(n),schema:mo()}),ql=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:gm("textStyle",o??e),schema:r}),Un=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:fV(o??e),schema:r}),vm=[o2("bold","w:b","bold"),o2("italic","w:i","italic"),o2("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:gm("underline"),schema:uV()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:gm("highlight"),schema:rl()},ql("color","string","w:color",rl()),ql("fontSize","number","w:sz",yu()),ql("fontFamily","string","w:rFonts",rl()),ql("letterSpacing","number","w:spacing",yu()),ql("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),ql("position","number","w:position",yu()),Un("dstrike","boolean","w:dstrike",mo()),Un("smallCaps","boolean","w:smallCaps",mo()),ql("caps","boolean","w:caps",mo(),"textTransform"),Un("shading","object","w:shd",bu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("border","object","w:bdr",bu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},sz:{oneOf:[{type:"number"},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},space:{oneOf:[{type:"number"},{type:"null"}]}}),"borders"),Un("outline","boolean","w:outline",mo()),Un("shadow","boolean","w:shadow",mo()),Un("emboss","boolean","w:emboss",mo()),Un("imprint","boolean","w:imprint",mo()),Un("charScale","number","w:w",yu(),"w"),Un("kerning","number","w:kern",yu(),"kern"),Un("vanish","boolean","w:vanish",mo()),Un("webHidden","boolean","w:webHidden",mo()),Un("specVanish","boolean","w:specVanish",mo()),Un("rtl","boolean","w:rtl",mo()),Un("cs","boolean","w:cs",mo()),Un("bCs","boolean","w:bCs",mo(),"boldCs"),Un("iCs","boolean","w:iCs",mo(),"italicCs"),Un("eastAsianLayout","object","w:eastAsianLayout",bu({id:{oneOf:[{type:"string",minLength:1},{type:"null"}]},combine:{oneOf:[{type:"boolean"},{type:"null"}]},combineBrackets:{oneOf:[{type:"string",minLength:1},{type:"null"}]},vert:{oneOf:[{type:"boolean"},{type:"null"}]},vertCompress:{oneOf:[{type:"boolean"},{type:"null"}]}})),Un("em","string","w:em",rl()),Un("fitText","object","w:fitText",bu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("snapToGrid","boolean","w:snapToGrid",mo()),Un("lang","object","w:lang",bu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("oMath","boolean","w:oMath",mo()),Un("rStyle","string","w:rStyle",rl(),"styleId"),Un("rFonts","object","w:rFonts",bu({ascii:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsi:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},cs:{oneOf:[{type:"string",minLength:1},{type:"null"}]},asciiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsiaTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},csTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hint:{oneOf:[{type:"string",minLength:1},{type:"null"}]}}),"fontFamily"),Un("fontSizeCs","number","w:szCs",yu()),Un("ligatures","string","w14:ligatures",rl()),Un("numForm","string","w14:numForm",rl()),Un("numSpacing","string","w14:numSpacing",rl()),Un("stylisticSets","array","w14:stylisticSets",dV()),Un("contextualAlternates","boolean","w14:cntxtAlts",mo())],WH=new Set(vm.map(e=>e.key)),hV=Object.fromEntries(vm.map(e=>[e.key,e])),KH={mark:vm.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:vm.filter(e=>e.storage==="runAttribute").map(e=>e.key)},i2=new WeakMap;function pV(e){let t=i2.get(e);return t||(t={refCount:0,generation:0,abortController:new AbortController,inFlight:null,activeMutationTokens:new Set},i2.set(e,t)),t.refCount+=1,t}function mV(e,t){t.refCount=Math.max(0,t.refCount-1),!(t.refCount>0)&&(t.abortController.abort("ui-controller-destroyed"),t.inFlight=null,t.activeMutationTokens.clear(),i2.delete(e))}var gV=new Set(Object.values(dt));function s2(e,t){return typeof e=="string"&&gV.has(e)?e:t}function fA(e){if(e&&typeof e=="object"&&e.ok===!1){const t=e.reason;return t==="host-not-ready"||t==="host-disposed"||t==="editing-mount-required"?{ok:!1,reason:dt.notReady}:{ok:!1,reason:s2(t,dt.targetUnresolved)}}return{ok:!0}}var vV=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],yV={[$4.bulletList]:"bullet",[$4.numberedList]:"ordered"};function hA(e){return yV[e]??null}var bV={disc:"disc",circle:"circle",square:"square",decimal:"decimal","decimal-paren":"decimalParenthesis","upper-roman":"upperRoman","lower-roman":"lowerRoman","upper-alpha":"upperLetter","upper-alpha-paren":"upperLetterParenthesis","lower-alpha":"lowerLetter","lower-alpha-paren":"lowerLetterParenthesis"};function wV(e){const t=bV[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var CV={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""},kV=[{key:"contentControls",match:"exact",note:"full-document SDT catalog parse (the measured during-load cliff)"},{key:"contentControls:inRange:",match:"prefix",note:"same adapter load() as the catalog, issued per settled selection"},{key:"hyperlinks:",match:"prefix",note:"per-block hyperlink list over the loading story"},{key:"styles:catalog:",match:"prefix",note:"WordStyleModel recompile from package bytes"},{key:"comments",match:"exact",note:"audited: full comments list; stale-served during load"},{key:"trackChanges",match:"exact",note:"audited: shared all-story tracked-changes catalog; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: current-token validation over the shared all-story catalog; consumers fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}],SV=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function _V(e){return kV.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var pA={ready:0,stale:1,pending:2};function wu(...e){let t="ready";for(const n of e)pA[n]>pA[t]&&(t=n);return t}function Pt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Sr(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function vr(e,t){if(!e)return null;const n=t.split(".");let r=e;for(const o of n){if(r==null)return null;r=r[o]}return typeof r=="function"?r:null}function Xn(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Nf(e,t){return{success:!1,failure:{code:"PARTIAL_LINK_EDIT",message:"Hyperlink target was updated, but display text replacement failed."},applied:{href:!0,text:!1},hyperlinkResult:e,textResult:t}}function Bf(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function a2(e){if(!e||typeof e!="object")return!1;const t=e,n=i=>{if(!i||typeof i!="object")return!1;const s=i;return s.kind==="text"&&typeof s.blockId=="string"&&typeof s.offset=="number"},r=i=>{if(!i||typeof i!="object")return!1;const s=i,a=s.range;return typeof s.blockId=="string"&&typeof a?.start=="number"&&typeof a.end=="number"};if(Array.isArray(t.segments)){const i=t.segments[0],s=t.segments[t.segments.length-1];return r(i)&&r(s)}if(t.kind==="selection")return n(t.start)&&n(t.end);if(t.kind!=="text"||typeof t.blockId!="string")return!1;const o=t.range;return typeof o?.start=="number"&&typeof o.end=="number"}function AV(e){if(!e||typeof e!="object")return null;const t=Bf(e);if(a2(t))return t;const n=e,r=n.navigationTarget&&typeof n.navigationTarget=="object"?n.navigationTarget:null;return r?.kind==="block"&&typeof r.blockId=="string"&&r.blockId.length>0?{kind:"text",blockId:r.blockId,range:{start:0,end:0},...r.story&&typeof r.story=="object"?{story:r.story}:{},...n.address&&typeof n.address=="object"?{address:n.address}:{}}:t}function _r(e){if(!e||typeof e!="object")return"story:body";const t=e,n=typeof t.storyType=="string"?t.storyType:"body";switch(n){case"body":return"story:body";case"headerFooterPart":return`story:headerFooterPart:${typeof t.refId=="string"?t.refId:""}`;case"headerFooterSlot":return JSON.stringify({storyType:n,section:t.section??null,headerFooterKind:t.headerFooterKind??null,variant:t.variant??null,resolution:t.resolution??"effective",onWrite:t.onWrite??"materializeIfInherited"});case"footnote":return`story:footnote:${typeof t.noteId=="string"?t.noteId:""}`;case"endnote":return`story:endnote:${typeof t.noteId=="string"?t.noteId:""}`;case"textbox":return`story:textbox:${typeof t.textboxId=="string"?t.textboxId:""}`;default:return JSON.stringify(t)}}function Cu(e){if(!e||typeof e!="object")return null;const t=e,n=t.address&&typeof t.address=="object"?t.address:null;if(n?.story&&typeof n.story=="object")return n.story;if(t.storyLocator&&typeof t.storyLocator=="object")return t.storyLocator;if(t.trackedChangeStory&&typeof t.trackedChangeStory=="object")return t.trackedChangeStory;const r=Bf(e);if(!r||typeof r!="object")return null;const o=r;if(o.story&&typeof o.story=="object")return o.story;const i=o.address&&typeof o.address=="object"?o.address:null;return i?.story&&typeof i.story=="object"?i.story:null}function Ui(e,t,n){return Gn(e)!==t?!1:n?_r(Cu(e))===_r(n):!0}function ym(e){const t=Cu(e);if(!(!t||_r(t)===_r(null)))return t}function IV(e){if(typeof e!="string"||e.length===0)return;const t=S6(e);switch(t.kind){case"body":return;case"footnote":return t.id?{kind:"story",storyType:"footnote",noteId:t.id}:void 0;case"endnote":return t.id?{kind:"story",storyType:"endnote",noteId:t.id}:void 0;case"header":case"footer":return t.id?{kind:"story",storyType:"headerFooterPart",refId:t.id}:void 0;default:return}}function EV(e){if(!(typeof e!="string"||e.length===0||e==="body")){if(e.startsWith("hf:part:")){const t=e.slice(8);return t?{kind:"story",storyType:"headerFooterPart",refId:t}:void 0}if(e.startsWith("fn:")){const t=e.slice(3);return t?{kind:"story",storyType:"footnote",noteId:t}:void 0}if(e.startsWith("en:")){const t=e.slice(3);return t?{kind:"story",storyType:"endnote",noteId:t}:void 0}}}function l2(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function bm(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function TV(e){if(!e||typeof e!="object")return null;const t=e;if(t.kind!=="selection")return e;const n=t.start;return!n||typeof n!="object"?null:{...t,end:n}}function Gn(e){if(!e||typeof e!="object")return null;const t=e,n=t.id??t.commentId??t.changeId;return typeof n=="string"&&n.length>0?n:null}function xV(e){if(!e||typeof e!="object")return null;const t=e,n=t.anchor,r=t.focus,o=n?.visualCaret,i=r?.visualCaret,s=o?.trackChangeId,a=i?.trackChangeId;return typeof s=="string"&&s.length>0&&s===a?s:null}var mA=new WeakMap;function gA(e){const t=[],n=i=>{typeof i=="string"&&i.length>0&&!t.includes(i)&&t.push(i)},r=i=>{if(!i||typeof i!="object")return;const s=i,a=s.sourceIds;if(a&&typeof a=="object"&&(n(a.wordIdInsert),n(a.wordIdDelete),Array.isArray(a.wordIdOther)))for(const d of a.wordIdOther)n(d);const l=s.wordRevisionIds;l&&typeof l=="object"&&(n(l.insert),n(l.delete),n(l.format));const c=s.replacement;if(c&&typeof c=="object")for(const d of[c.inserted,c.deleted])d&&typeof d=="object"&&(n(d.id),n(d.wordId));const u=s.move;if(u&&typeof u=="object")for(const d of[u.source,u.destination])d&&typeof d=="object"&&(n(d.id),n(d.wordId))};r(e);const o=e?.change;return o&&o!==e&&r(o),t}function fa(e){const t=mA.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=Gn(i);if(s){n.add(s);for(const a of gA(i)){r.has(a)||r.set(a,s);const l=`imported:${a}`;r.has(l)||r.set(l,s)}}}const o={toPublicId(i){if(n.has(i))return i;const s=r.get(i);return s!=null&&n.has(s)?s:null},aliasesFor(i){const s=[i];for(const[a,l]of r)l===i&&!s.includes(a)&&s.push(a);return s}};return mA.set(e,o),o}var vA=new WeakMap,yA=new WeakMap;function ku(e,t){const n=_r(t);let r=vA.get(e);r||(r=new Map,vA.set(e,r));const o=r.get(n);if(o)return o;const i=fa(e.filter(s=>_r(Cu(s))===n));return r.set(n,i),i}function RV(e){return!!e&&typeof e=="object"&&e.storyType==="textbox"}function MV(e,t){const n=t.filter(o=>e.some(i=>Gn(i)===o&&Cu(i)==null));if(n.length===0)return null;if(n.length===1)return n[0];const r=new Set;for(const o of n){const i=e.find(s=>Gn(s)===o);if(i)for(const s of gA(i)){if(r.has(s))return null;r.add(s)}}return n[0]}function LV(e){const t=yA.get(e);if(t)return t;const n=e.filter(o=>Cu(o)!=null),r=n.length===e.length?e:n;return yA.set(e,r),r}function PV(e){const{selectionIds:t,publicIds:n,selection:r,bodyItems:o,allStoryItems:i}=e;if(t.length===0)return null;const s=c=>{for(const u of t){const d=c.toPublicId(u);if(d)return d}return null},a=Hi(r),l=_r(a)===_r(null);if(i){const c=l?LV(i):i,u=s(ku(c,a));if(u)return u;const d=n?.find(h=>c.some(g=>Ui(g,h,a)));return d||(l?s(fa(o)):RV(a)?MV(i,t):null)}return l?s(fa(o))??t[0]??null:null}function DV(e,t){const n=e.find(r=>Gn(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??Gn(n)??t:null}function OV(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,c=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:c??l}}const n=e.target,r=n&&Array.isArray(n.segments)?n.segments:[],o=r[0]?.blockId,i=r[r.length-1]?.blockId;return typeof o=="string"?{startBlockId:o,endBlockId:typeof i=="string"?i:o}:null}function Nr(e){const t=[],n=s=>{typeof s=="string"&&s.length>0&&!t.includes(s)&&t.push(s)},r=e.target,o=r&&Array.isArray(r.segments)?r.segments:[];for(const s of o)n(s?.blockId);const i=e.selectionTarget;return i&&(n(i.start?.blockId),n(i.end?.blockId)),t}var FV=64;function Yl(e){return e.length<=FV}function Hi(e){const t=e.target,n=e.selectionTarget,r=n?.start,o=n?.end,i=t?.story??n?.story??r?.story??o?.story;return i&&typeof i=="object"?i:{kind:"story",storyType:"body"}}function Co(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function ha(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function bA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var wA=720;function ws(e){return Math.round(e*20)}function Su(e){return typeof e=="number"&&Number.isFinite(e)}function NV(e){if(!e||typeof e!="object")return null;const t=e.node;if(!t||typeof t!="object")return null;const n=t.kind==="heading"?t.heading??null:t.kind==="paragraph"?t.paragraph??null:null;if(!n)return null;const r=n.resolved,o=n.props,i=r?.indent??o?.indent;if(!i||typeof i!="object")return null;const s=Su(i.left)?ws(i.left):Su(i.start)?ws(i.start):void 0,a=Su(i.right)?ws(i.right):Su(i.end)?ws(i.end):void 0,l=Su(i.firstLine)?ws(i.firstLine):void 0,c=Su(i.hanging)?ws(i.hanging):void 0;return s==null&&a==null&&l==null&&c==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...c!=null?{hanging:c}:{}}}function c2(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=t?.story,o=[];for(const i of n){if(!i||typeof i.blockId!="string")continue;const s=i.range;!s||typeof s.start!="number"||typeof s.end!="number"||s.start===s.end||o.push({kind:"text",blockId:i.blockId,range:{start:s.start,end:s.end},...r?{story:r}:{}})}return o}function BV(e){if(!e||typeof e!="object")return[];const t=e,n=t.story,r=[];if(t.kind==="text"&&t.range&&typeof t.blockId=="string"){const o=t.range;return typeof o.start=="number"&&typeof o.end=="number"&&o.start!==o.end&&r.push({kind:"text",blockId:t.blockId,range:{start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)},...n?{story:n}:{}}),r}if(t.kind==="text"&&Array.isArray(t.segments)){for(const o of t.segments){const i=o?.range;typeof o?.blockId=="string"&&typeof i?.start=="number"&&typeof i?.end=="number"&&i.start!==i.end&&r.push({kind:"text",blockId:o.blockId,range:{start:Math.min(i.start,i.end),end:Math.max(i.start,i.end)},...n?{story:n}:{}})}return r}if(t.kind==="selection"){const o=t.start,i=t.end,s=typeof o?.blockId=="string"&&i?.blockId===o.blockId?o.blockId:null;o?.kind==="text"&&i?.kind==="text"&&s&&typeof o.offset=="number"&&typeof i.offset=="number"&&o.offset!==i.offset&&r.push({kind:"text",blockId:s,range:{start:Math.min(o.offset,i.offset),end:Math.max(o.offset,i.offset)},...t.story??o.story?{story:t.story??o.story}:{}})}return r}function zf(e){if(!e||typeof e!="object")return null;const t=e,n=t.story;if(t.kind==="text"&&t.range&&typeof t.blockId=="string"){const r=t.range;if(typeof r.start=="number"&&typeof r.end=="number"&&r.start===r.end)return{kind:"text",blockId:t.blockId,range:{start:r.start,end:r.end},...n?{story:n}:{}}}if(t.kind==="text"&&Array.isArray(t.segments)){const r=t.segments[0],o=r?.range;if(typeof r?.blockId=="string"&&typeof o?.start=="number"&&typeof o?.end=="number"&&o.start===o.end)return{kind:"text",blockId:r.blockId,range:{start:o.start,end:o.end},...n?{story:n}:{}}}if(t.kind==="selection"){const r=t.start,o=t.end,i=typeof r?.blockId=="string"&&o?.blockId===r.blockId?r.blockId:null;if(r?.kind==="text"&&o?.kind==="text"&&i&&typeof r.offset=="number"&&typeof o.offset=="number"&&r.offset===o.offset)return{kind:"text",blockId:i,range:{start:r.offset,end:r.offset},...t.story??r.story?{story:t.story??r.story}:{}}}return null}function ol(e){return zf(e.target)??zf(e.selectionTarget)}var CA=["fontFamily","fontSize","color","highlight"],zV={undo:"history.undo",redo:"history.redo"},Vf=["bold","italic","underline","strikethrough"];function u2(e){return CA.includes(e)}function _u(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,c,u)=>{typeof l!="string"||typeof c!="number"||typeof u!="number"||r.push({blockId:l,start:Math.min(c,u),end:Math.max(c,u)})};for(const l of n){const c=l?.range;o(l?.blockId,c?.start,c?.end)}if(r.length>0)return r;const i=e.selectionTarget,s=i?.start,a=i?.end;return!s||!a||s.blockId!==a.blockId||o(s.blockId,s.offset,a.offset),r}function $i(e){const t=e.target,n=e.selectionTarget,r=n?.start,o=n?.end,i=t?.story??n?.story??r?.story??o?.story;return i&&typeof i=="object"?i:void 0}function VV(e){const t=$i(e);if(!t||typeof t!="object")return"body";const n=t;return JSON.stringify({storyType:typeof n.storyType=="string"?n.storyType:"body",refId:typeof n.refId=="string"?n.refId:null,noteId:typeof n.noteId=="string"?n.noteId:null,textboxId:typeof n.textboxId=="string"?n.textboxId:null})}function pa(e){const t=_u(e);return t.length===0?null:[VV(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function kA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:Kl({selectionTarget:t})}function jV(e,t){if(e==="fontSize"){const r=typeof t=="number"?t:Number(t);return Number.isFinite(r)&&r>0?String(r):null}if(typeof t!="string")return null;const n=t.trim();return n.length===0?null:e==="color"||e==="highlight"?n.toUpperCase():n}function UV(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function HV(e){if(!e)return[];const t=Array.isArray(e.blocks)?e.blocks:[],n=[];for(const r of t){const o=r?.range,i=r?.blockId;typeof i!="string"||typeof o?.start!="number"||typeof o?.end!="number"||n.push({blockId:i,start:Math.min(o.start,o.end),end:Math.max(o.start,o.end)})}return n}function $V(e,t){return e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return o?.blockId===n.blockId&&o?.start===n.start&&o?.end===n.end})}function SA(e,t){const n=_u(t);if(n.length===0)return null;const r=e&&Array.isArray(e.items)?e.items:[];if(r.length===0)return null;const o=r.find(i=>$V(n,HV(i)));if(o)return o;if(n.length===1){const i=r.find(s=>{const a=s?.address;return a?.kind==="block"&&a.nodeId===n[0].blockId});if(i)return i}return r[0]??null}function GV(e,t){const n=t==="fontSize"?e?.fontSizePt??e?.fontSize:t==="highlight"?e?.highlight??e?.backgroundColor:e?.[t];if(typeof n=="number")return Number.isFinite(n)?String(n):void 0;if(typeof n!="string")return;const r=n.trim();if(r.length!==0)return t==="color"||t==="highlight"?r.toUpperCase():r}function d2(e){if(typeof e!="string")return;const t=e.split(",")[0]?.trim().replace(/^['"]+|['"]+$/g,"").trim();if(!t)return;const n=t.toLowerCase();if(!(n==="serif"||n==="sans-serif"||n==="monospace"||n==="cursive"||n==="fantasy"))return t}function WV(e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return;const t=Math.round(e*.75*2)/2;if(!(t<=0))return String(t)}function KV(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function _A(e,t){if(!e)return{};const n=new Map;for(const i of _u(t)){const s=n.get(i.blockId)??[];s.push({start:i.start,end:i.end}),n.set(i.blockId,s)}if(n.size===0)return{};const r=Array.isArray(e.blocks)?e.blocks:[],o={};for(const i of CA){const s=new Map;let a=!1,l=!1;for(const c of r){const u=typeof c?.blockId=="string"?c.blockId:null;if(!u)continue;const d=n.get(u);if(!d?.length)continue;const h=Array.isArray(c?.runs)?c.runs:[];for(const g of h){const p=g?.range,v=typeof p?.start=="number"?p.start:null,k=typeof p?.end=="number"?p.end:null;if(v==null||k==null||!d.some(y=>UV(y,{start:v,end:k})))continue;a=!0;const C=GV(g?.styles,i);if(C===void 0){l=!0;continue}const _=KV(i,C);if(s.has(_)||s.set(_,C),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function f2(e,t){const n=Nr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:Co(n)}:{kind:"documentEnd"}}function cn(e,t){const n=e.supported??t!=="unsupported",r=e.enabled??(e.disabled!==void 0?!e.disabled:n);return{enabled:r,disabled:!r,active:e.active??!1,supported:n,value:e.value,source:t,reason:r?void 0:e.reason}}function il(e){if(!e||typeof e!="object")return null;const t=e,n=t.change,r=n&&typeof n=="object"?n:t;return{...t,id:t.id??r.id,change:r}}function wm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function Cs(e){if(Sr(e))return!0;if(e===!1)return!1;if(e===!0||e==null||typeof e!="object")return!0;const t=e;return"success"in t||"failure"in t||"effects"in t?e:t.status!=="rejected"}function Cm(e){return!!e&&typeof e=="object"&&e.success===!0}function ko(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function Xl(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function h2(e){const t=[],n=r=>{if(!r||typeof r!="object")return;const o=r;if(Array.isArray(o.runs)&&t.push(o),Array.isArray(o.rows))for(const i of o.rows){const s=i?.cells;if(Array.isArray(s))for(const a of s){const l=a;if(Array.isArray(l?.blocks))for(const c of l.blocks)n(c);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function Zl(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function km(e){return e.trackedChange?.kind==="delete"?0:typeof e.text=="string"?e.text.length:0}function hi(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!ko(i)&&n===null&&(n=i),Cm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function qV(e){const t=e?.anchor,n=t?.start,r=t?.end;return typeof n?.blockId!="string"||typeof r?.blockId!="string"||n.blockId!==r.blockId||typeof n.offset!="number"||typeof r.offset!="number"?null:{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.offset},end:{kind:"text",blockId:r.blockId,offset:r.offset}}}function YV(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function Sm(e){return gu(e)?.trackDecision??null}function XV(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function sl(e){return{found:!1,success:!1,rects:[],reason:e}}function ZV(e,t){if(!t||typeof t.getBoundingClientRect!="function"||e.rects.length===0)return e;let n;try{const o=t.getBoundingClientRect();n={left:o.left,top:o.top}}catch{return e}const r=e.rects.map(o=>({...o,left:o.left-n.left,right:o.right-n.left,top:o.top-n.top,bottom:o.bottom-n.top}));return{...e,rects:r,rect:r[0]}}function QV(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.blockId!="string"||!t.range||typeof t.range!="object")return!1;const n=t.range;return Number.isInteger(n.start)&&Number.isInteger(n.end)&&n.start>=0&&n.start<=n.end}function AA(e){if(!e||e.kind!=="text"||!Array.isArray(e.segments)||e.segments.length===0)return null;const t=Array.from(e.segments);if(!t.every(QV))return null;const n=t[0],r=t[t.length-1],o=e.story;return{kind:"selection",start:{kind:"text",blockId:n.blockId,offset:n.range.start,...o?{story:o}:{}},end:{kind:"text",blockId:r.blockId,offset:r.range.end,...o?{story:o}:{}},...o?{story:o}:{}}}function JV(e){return e.selectionTarget?e.selectionTarget:AA(e.target)}function Au(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=AA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function p2(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var m2={bold:null,italic:null,underline:null,strike:null,color:null,highlight:null,fontFamily:null,fontSize:null,vertAlign:null,smallCaps:null,caps:null,letterSpacing:null,dstrike:null},ej=Object.fromEntries(Object.entries(m2).filter(([e])=>hV[e]?.tracked===!0));function tj(e,t,n,r){switch(e.kind){case"toggle":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n;return typeof o=="boolean"||o===null?{target:t,value:o}:{target:t,value:!r}}case"value-string":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n;return o===null?{target:t,value:null}:typeof o!="string"||o.trim()===""?null:{target:t,value:o}}case"value-number":{const o=typeof n=="object"&&n!==null&&"value"in n?n.value:n,i=typeof o=="number"?o:Number(o);return!Number.isFinite(i)||i<=0?null:{target:t,value:i}}case"clear":return{target:t,inline:{...m2}};default:return null}}function nj(e){const t=o=>{if(!o||typeof o!="object")return null;const i=o,s=i.rowIndex,a=i.columnIndex;return typeof s!="number"||!Number.isInteger(s)||typeof a!="number"||!Number.isInteger(a)?null:{rowIndex:s,columnIndex:a}};if(!e)return null;const n=t(e.start),r=t(e.end);return!n||!r?null:{start:n,end:r}}function rj(e,t){const{tableNodeId:n,rowIndex:r,columnIndex:o,cellNodeId:i,mergeRange:s}=t;switch(e){case"insert-row-before":return{nodeId:n,rowIndex:r,position:"above"};case"insert-row-after":return{nodeId:n,rowIndex:r,position:"below"};case"delete-row":return{nodeId:n,rowIndex:r};case"insert-column-before":return{nodeId:n,columnIndex:o,position:"left"};case"insert-column-after":return{nodeId:n,columnIndex:o,position:"right"};case"delete-column":return{nodeId:n,columnIndex:o};case"delete-table":return{nodeId:n};case"merge-cells":{const a=s??{start:{rowIndex:r,columnIndex:o},end:{rowIndex:r,columnIndex:o}};return{nodeId:n,start:a.start,end:a.end}}case"split-cell":return i?{nodeId:i,rows:1,columns:2}:null;case"remove-borders":return{nodeId:n,mode:"applyTo",applyTo:"all",border:null};default:return null}}function oj(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,c=!1,u=Promise.resolve(),d=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},g=0;const p=new Set;let v={},k="",C=null;const _=()=>{const f=t?.activeEditor;return f&&typeof f=="object"?f:null},y=()=>{const f=_()?.doc;return f&&typeof f=="object"?f:null},w=()=>{const f=_()?.v2TrackedChanges;return f&&typeof f=="object"?f:null},x=()=>{const f=_()?.host;return f&&typeof f=="object"?f:null},L=f=>{if(f.storyType!=="headerFooterPart"||typeof f.refId!="string")return null;const m=_(),b=x(),I=m?.pageLayout??b?.pageLayout;if(!I||typeof I!="object")return null;const E=I.getActiveRulerContext,B=b?.resolveHeaderFooterEditTarget;if(typeof E!="function"||typeof B!="function")return null;const W=Pt(()=>E.call(I),null);if(!W||typeof W.pageIndex!="number")return null;for(const ie of["header","footer"]){const fe=Pt(()=>B.call(b,{pageIndex:W.pageIndex,kind:ie}),null);if(!(fe?.status!=="ready"||fe.refId!==f.refId||typeof fe.sectionId!="string"||!["default","first","even"].includes(String(fe.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:fe.sectionId},headerFooterKind:ie,variant:fe.slotVariant}}return null},z=()=>{const f=x(),m=f?.getPendingInlineFormat;if(typeof m!="function")return null;const b=Pt(()=>m.call(f),null);return b&&typeof b=="object"?b:null},$=f=>{const m=p2(f);if(!m)return null;const b=z();if(!b||!(m in b))return null;const I=b[m];return f.inline?.kind==="toggle"?I===!0:I!=null&&I!==""},R=f=>{const m=p2(f);if(!m)return;const b=z();if(!b||!(m in b))return;const I=b[m];if(typeof I=="string"&&I!=="")return I;if(typeof I=="number"&&Number.isFinite(I))return String(I)},F=(f,m)=>{const b=x(),I=b?.setPendingInlineFormat;typeof I=="function"&&Pt(()=>I.call(b,f,m),void 0)},X=f=>{const m=x(),b=m?.clearPendingInlineFormat;typeof b=="function"&&Pt(()=>b.call(m,f),void 0)},D=new Set(["bold","italic","underline","strikethrough"]),V=f=>{const m=z();if(!m)return;const b=Array.isArray(f.activeMarks)?f.activeMarks:[];let I=null;for(const E of Object.keys(m)){const B=m[E];let W;if(D.has(E))W=b.includes(E)===(B===!0);else if(u2(E)){if(B==null)continue;I||(I=fl(f)),W=I[E]===B}else W=!1;W&&X(E)}},T=()=>{const f=_()?.editCommands;return f&&typeof f=="object"?f:null},N=f=>{const m=T();if(!m||typeof m.getSnapshot!="function")return null;const b=Pt(()=>m.getSnapshot(),null)?.commands?.[f];return b&&typeof b=="object"?b:null},Q=()=>N("lists.apply"),K=f=>{const m=f?.value?.seed;return m==="bullet"||m==="ordered"?m:null},se=f=>{const m=zV[f];return m?N(m):null},me=()=>{const f=x();if(!f||typeof f.getTableContext!="function")return null;const m=Pt(()=>f.getTableContext(),null);return m&&typeof m=="object"?m:null},Be=()=>{const f=me();if(!f||f.inTable!==!0)return null;const m=f.table,b=typeof m?.nodeId=="string"&&m.nodeId.length>0?m.nodeId:null;if(!b)return null;const I=f.row,E=f.column,B=f.cell,W=typeof I?.index=="number"&&Number.isInteger(I.index)?I.index:null,ie=typeof E?.index=="number"&&Number.isInteger(E.index)?E.index:null;if(W==null||ie==null)return null;const fe=typeof B?.nodeId=="string"&&B.nodeId.length>0?B.nodeId:null,Le=f.cellRange;return{tableNodeId:b,rowIndex:W,columnIndex:ie,cellNodeId:fe,mergeRange:nj(Le)}},he=new Map;let ve=null,ue=null,ke=0,re=0,Re=0;const Je=new Set,st=(f,m)=>f===m?!0:!f||!m?!1:f.id===m.id&&f.paintedEntityId===m.paintedEntityId&&_r(f.story)===_r(m.story),Tt=f=>Array.from(Je).some(m=>st(m,f)),Ee=f=>{const m=x();if(typeof m?.getHandles!="function")return;const b=Pt(()=>m.getHandles(),null),I=b?.review;if(I){if(f){if(typeof I.setActiveReviewTarget!="function")return;const E=b?.layout;Pt(()=>I.setActiveReviewTarget({entityType:"trackedChange",entityId:f.id,...f.paintedEntityId?{paintedEntityId:f.paintedEntityId}:{},origin:"panel",layoutEpoch:typeof E?.generation=="number"?E.generation:0,story:f.story??{kind:"story",storyType:"body"}}),null);return}typeof I.getActiveReviewTarget!="function"||typeof I.clearActiveReviewTarget!="function"||Pt(()=>I.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Pt(()=>I.clearActiveReviewTarget(),void 0)}},$e=(f,m)=>{ue=f,ke+=1,Re+=1,m?.invalidateQueuedNavigation!==!1&&(re+=1)},qe=new Set;let J=!1,S=null;const ee=new Map,O=new Set;let H=null,U=null,G=!1,te=null,Y=0,q=null,be=null,ye=null;const we=()=>{if(G||J)return;G=!0;const f=()=>{G=!1,J||Kt()};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},ze=250,rt=5e3,it=f=>{J||te&&Y<=f||(te&&clearTimeout(te),Y=f,te=setTimeout(()=>{te=null,Y=0,J||Kt()},Math.max(0,f-Date.now())))},Ct=new WeakMap;let en=0;const Rt=f=>{if(!f)return"none";let m=Ct.get(f);return m==null&&(m=en+=1,Ct.set(f,m)),`e${m}`};let zt=0,$t={};const _n=e.superdoc,bt=pV(_n),tn=()=>{bt.abortController.abort("review-mutation-started"),bt.inFlight=null},nt=()=>{bt.generation+=1,bt.abortController=new AbortController,bt.inFlight=null},Dt=f=>{const m=bt.activeMutationTokens;if(typeof f!="string"||f.length===0||m.has(f))return;const b=m.size===0;m.add(f),b&&tn()},Gt=f=>{const m=bt.activeMutationTokens;typeof f!="string"||!m.delete(f)||m.size===0&&nt()},Rn=f=>{const m=w(),b=m?.listTrackedChanges;if(typeof b!="function")return _()?.editorVersion===2?Promise.reject(new Error("v2-tracked-changes-bridge-pending")):f();if(bt.activeMutationTokens.size>0)return Promise.reject(new Error("ui-review-catalog-superseded"));if(_()?.reviewHydration?.getDiagnostics?.()?.inFlight===!0)return Promise.reject(new Error("shell-review-hydration-in-flight"));const I=bt.generation,E=bt.inFlight;if(E?.generation===I)return E.promise;const B=bt.abortController.signal,W=Le=>{if(B.aborted||I!==bt.generation||Le?.reason==="review-hydration-superseded")throw new Error("ui-review-catalog-superseded");return Le},ie=b.call(m,{blocking:!1,signal:B});if(!Sr(ie))return W(ie);const fe=Promise.resolve(ie).then(W);return bt.inFlight={generation:I,promise:fe},fe.then(()=>{bt.inFlight?.promise===fe&&(bt.inFlight=null)},()=>{bt.inFlight?.promise===fe&&(bt.inFlight=null)}),fe};let Nt=null,dn=null,Mn=0;const De=()=>{dn&&clearTimeout(dn),dn=null,Mn=0};let We=f=>{},Ke=null,mt=new Set,jt=null,_t=0,Yt=null;const Et=()=>`${Rt(_())}|m${zt}`,pn=()=>{Ke=null,mt=new Set},Kn=f=>{for(const m of["trackChanges","trackChanges:all"]){const b=ee.get(m);if(!b?.hasSettled||!Array.isArray(b.value))continue;const I=b.value.filter(E=>{const B=Gn(E);return!B||!f.has(B)});I.length!==b.value.length&&ee.set(m,{...b,value:I})}},go=f=>{const m=()=>{if(!J)for(const B of[...qe])B(pt)},b=Xl(f)?f:null,I=_()?.documentMutationReadiness,E=()=>{const B=globalThis.requestAnimationFrame;return typeof B!="function"?Promise.resolve():new Promise(W=>{let ie=!1;const fe=()=>{ie||(ie=!0,clearTimeout(Le),W())},Le=setTimeout(fe,250);B(()=>B(()=>setTimeout(fe,0)))})};if(b?.success===!0&&typeof b.txId=="string"&&b.txId.length>0&&typeof I?.whenPainted=="function")try{Promise.resolve(I.whenPainted.call(I,b)).then(E,()=>{}).then(m,m);return}catch{}m()},qn=(f,m)=>{const b=pt.trackChanges,I=b.items.filter(W=>{const ie=Gn(W);return!ie||!f.has(ie)});if(I.length===b.items.length)return;ue&&f.has(ue.id)&&$e(null);const E=new Set;for(const W of I){const ie=wm(W),fe=W,Le=ie.author??ie.authorEmail??fe.author??fe.authorEmail;typeof Le=="string"&&E.add(Le)}const B=b.items.length-I.length;pt={...pt,trackChanges:{...b,items:I,total:Math.max(I.length,b.total-B),activeId:b.activeId&&f.has(b.activeId)?null:b.activeId,authors:[...E]}},go(m)},nn=f=>{const m=pt.trackChanges,b=m.items.length>0||m.total!==0||m.activeId!==null||m.authors.length>0;jt=Et(),ue!==null&&$e(null),pt={...pt,trackChanges:{...m,items:[],total:0,activeId:null,authors:[]}},b&&go(f)},Yn=(f,m)=>{if(f.size===0)return;const b=Et(),I=Ke===b?mt:new Set,E=new Set([...f].filter(B=>!I.has(B)));E.size!==0&&(Ke=b,mt=new Set([...I,...E]),Kn(mt),qn(E,m))},yr=f=>Ke===f&&mt.size>0?mt:null,ir=(f,m=[])=>{const b=f.map(il).filter(E=>E!=null&&Gn(E)!=null);if(b.length===0)return;const I=m.map(il).map(E=>E==null?null:Gn(E)).filter(E=>E!=null);for(const E of["trackChanges","trackChanges:all"]){const B=ee.get(E),W=B?.hasSettled&&Array.isArray(B.value)?[...B.value]:[],ie=new Set;let fe=!1;for(const Le of b){const Ue=Gn(Le);if(!Ue)continue;const je=W.findIndex(Ne=>Gn(Ne)===Ue);if(je<0)W.push(Le),ie.add(Ue);else{const Ne=W[je];W[je]=Xl(Ne)?{...Ne,...Le}:Le}fe=!0}if(E==="trackChanges"&&ie.size>0&&I.length>0){const Le=new Set(I.filter(Ne=>ie.has(Ne))),Ue=new Map(W.filter(Ne=>Le.has(Gn(Ne)??"")).map(Ne=>[Gn(Ne),Ne])),je=W.filter(Ne=>!Le.has(Gn(Ne)??""));for(const[Ne,Ye]of I.entries()){if(!Le.has(Ye))continue;const He=Ue.get(Ye);if(!He)continue;const Xe=I.slice(Ne+1).map(ot=>je.findIndex(tt=>Gn(tt)===ot)).find(ot=>ot>=0);if(Xe!=null){je.splice(Xe,0,He);continue}const Ze=I.slice(0,Ne).reverse().map(ot=>je.findIndex(tt=>Gn(tt)===ot)).find(ot=>ot>=0);je.splice(Ze==null?je.length:Ze+1,0,He)}W.splice(0,W.length,...je)}fe&&ee.set(E,{token:B?.token??null,value:W,hasSettled:!0,inflightToken:null})}},un=f=>{const m=Et(),b=yr(m),I=f.map(il).filter(E=>{if(E==null)return!1;const B=Gn(E);return B!=null&&!b?.has(B)});for(const E of["trackChanges","trackChanges:all"])ee.set(E,{token:m,value:[...I],hasSettled:!0,inflightToken:null})},Hn=async(f,m)=>{try{const b=f.v2TrackedChanges?.listTrackedChanges;if(typeof b=="function"){const B=await Promise.resolve(b.call(f.v2TrackedChanges,{mode:m.trackedChangesListMode,refreshReason:m.refreshReason,blocking:m.blocking,...m.targetIds?.length?{targetIds:m.targetIds}:{}})),W=m.trackedChangesListMode==="all"&&m.refreshReason==="mutation-history-render-reconcile"?B?.ok===!0:B?.ok!==!1;return{ok:W,items:W&&Array.isArray(B?.items)?B.items:[],...typeof B?.complete=="boolean"?{complete:B.complete}:{},...typeof B?.sourceCoverageComplete=="boolean"?{sourceCoverageComplete:B.sourceCoverageComplete}:{}}}const I=f.docTrackChanges?.list;if(typeof I!="function")return{ok:!1,items:[]};const E=await Promise.resolve(I.call(f.docTrackChanges));return{ok:!0,items:Array.isArray(E?.items)?E.items:[]}}catch(b){return{ok:!1,items:[],failures:[b]}}},br=jk({getContext:()=>{const f=_();if(!f)return null;const m=w(),b=y()?.trackChanges??null,I=m??b;if(!I)return null;const E=f.documentId??m?.documentId;return{editor:f,adapter:I,documentId:E==null?null:String(E),reconcileToken:$t,v2TrackedChanges:m,docTrackChanges:b}},reconcile:async(f,m)=>{m.removedIds.size>0&&Yn(new Set(m.removedIds));const b=[...new Set(m.upsertIds)];if(b.length===0)return{ok:!0,items:[],resolvedIds:[],unresolvedIds:[]};const I=ee.get("trackChanges"),E=I?.hasSettled&&Array.isArray(I.value)?I.value:null,B=new Set(E?E.map(Gn).filter(Ze=>Ze!=null):[]),W=E?.length===0&&Ki()==="complete",ie=new Set(b.filter(Ze=>!B.has(Ze))),fe=f.v2TrackedChanges?.getTrackedChange,Le=f.docTrackChanges?.get;if(typeof fe!="function"&&typeof Le!="function")return{ok:!1,items:[],resolvedIds:[],unresolvedIds:b};const Ue=await Promise.all(b.map(async Ze=>{try{if(typeof fe=="function"){const tt=await Promise.resolve(fe.call(f.v2TrackedChanges,Ze));return{id:Ze,ok:tt?.ok!==!1,items:tt?.ok!==!1&&Array.isArray(tt?.items)?tt.items:[],result:tt}}const ot=await Promise.resolve(Le.call(f.docTrackChanges,{id:Ze}));return{id:Ze,ok:!0,items:ot&&typeof ot=="object"?[ot]:[],result:ot}}catch(ot){return{id:Ze,ok:!1,items:[],result:ot}}})),je=[],Ne=[],Ye=[];for(const Ze of Ue){const ot=Ze.items.filter(tt=>{const Bt=il(tt);return Bt!=null&&Gn(Bt)===Ze.id});Ze.ok&&ot.length>0?(je.push(...ot),Ne.push(Ze.id)):Ye.push(Ze.id)}let He;const Xe=Ne.filter(Ze=>ie.has(Ze));if(Xe.length>0&&!W){const Ze=await Hn(f,{trackedChangesListMode:"interaction-prime",refreshReason:"mutation-render-reconcile",blocking:!1,targetIds:Xe});Ze.ok&&(He=Ze.items)}return{ok:Ye.length===0,items:je,orderedItems:He,resolvedIds:Ne,unresolvedIds:Ye,failures:Ue.filter(Ze=>!Ze.ok).map(Ze=>Ze.result)}},hydrate:Hn,onReconciled:(f,m,b)=>{if(b?.reconcileMode==="authoritative"){if(f.reconcileToken!==$t)return;b.ok===!0&&b.complete===!0&&b.sourceCoverageComplete===!0?(De(),un(b.items??[]),Nt=null):b.ok===!0?(De(),ir(b.items??[])):We(f.reconcileToken),Kt();return}const I=(b?.items??[]).filter(E=>{const B=il(E),W=B==null?null:Gn(B);return W!=null&&m.has(W)});ir(I,b?.orderedItems??b?.items??[]),Kt()}});We=f=>{if(J||dn)return;const m=Math.min(ze*2**Mn,rt);Mn+=1,dn=setTimeout(()=>{dn=null,!(J||Nt===null||f!==$t)&&br.onRender(!0)},m)};const Br=()=>`${Et()}|m${Wn()}|s${_t}`,Wr=f=>JSON.stringify({t:f.target??null,s:f.selectionTarget??null}),Qo=["contentControls:inRange:","query:","effInline:"],Wi=120,ma=180,Ki=()=>{const f=x(),m=f?.getDocumentLoadingSnapshot;if(typeof m!="function")return"unknown";const b=Pt(()=>m.call(f),null)?.sourceStage;return b==="opening"||b==="bootstrap-ready"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},_i=new Map,ga=f=>{const m=Et();_i.get(f)!==m&&(_i.set(f,m),we())},va=()=>{const f=ee.get("comments");return f?.hasSettled?Array.isArray(f.value)&&f.value.length>0:f?.inflightToken!=null},Jo=(f,m)=>_i.get(f)===m,No=f=>{ga("contentControls")},_e=()=>{const f=ee.get("trackChanges");f?.hasSettled||f?.inflightToken!=null||ga("trackChanges")},Ve=6500,ft=250;let ut=0,Vn=0,yn=!1,Ar=null;const no=()=>{if(J||Ar)return;const f=()=>{if(Ar=null,J)return;const m=Date.now()-ut;if(io()||m<Ve){Ar=setTimeout(f,ft);return}yn=!1,Kt()};Ar=setTimeout(f,0)};let ro=null,oo=null;const qi=()=>{const f=x();if(!f||ro===f)return;oo&&(oo(),oo=null),ro=f;const m=f.subscribeDocumentLoading;if(typeof m!="function"){ro=null,Ai(Ve);return}try{const b=B=>{const W=B?.sourceStage;(W==="source-complete"||W==="source-failed"||W==="source-cancelled")&&(ut=Math.max(ut,Date.now()),no())},I=m.call(f,b);typeof I=="function"&&(oo=I);const E=f.getDocumentLoadingSnapshot;typeof E=="function"&&b(Pt(()=>E.call(f),null))}catch{ro=null,Ai(Ve)}},Bo=()=>{const f=_()?.host,m=f?.getForegroundMutationState;if(typeof m!="function")return null;const b=Pt(()=>m.call(f),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},io=()=>{const f=Bo();return!!(f&&(f.active>0||f.pending>0))},Ai=(f=Wi)=>{J||q||(q=setTimeout(()=>{if(q=null,J)return;if(be&&io()){Ai(),Kt();return}const m=be;be=null,m===Br()&&ba("selection",m,ll,Ti),Kt()},f))},Ql=(f,m)=>{if(!Bo())return!1;const b=`${f}\0${m}`;return O.has(b)?!1:(O.add(b),Ai(ma),!0)},Kr=f=>{if(H==null||f===H)return U?.timer&&clearTimeout(U.timer),U=null,H=f,!1;if(U?.key===f)return U.ready?(U=null,H=f,!1):!0;U?.timer&&clearTimeout(U.timer);const m={key:f,ready:!1,timer:null};return m.timer=setTimeout(()=>{J||U!==m||(m.timer=null,m.ready=!0,Kt())},ma),U=m,!0},Ii=f=>Uk(f),ei=()=>{ks(),Kt()};let qr=null,zo=!1,Yi=0;const Jl=()=>{qr=null,zo=!1,Yi+=1},ya=()=>{const f=_(),m=f?.documentMutationReadiness;if(!f||typeof m?.whenPainted!="function"||(qr={editor:f,readiness:m,afterEpoch:typeof m.getRenderEpoch=="function"?Pt(()=>m.getRenderEpoch.call(m),null):null},zo))return;zo=!0;const b=Yi;(async()=>{for(;!J&&b===Yi;){const E=qr;if(qr=null,!E){zo=!1;return}let B=!1;try{await E.readiness.whenPainted.call(E.readiness,typeof E.afterEpoch=="number"?{afterEpoch:E.afterEpoch}:void 0),B=!0}catch{}if(J||b!==Yi)return;if(_()!==E.editor){Jl();return}B&&ei()}})()},Xi=()=>{ye&&clearTimeout(ye),ye=setTimeout(()=>{ye=null,J||ei()},500)},ba=(f,m,b,I)=>{let E;try{E=b()}catch{E=void 0}if(!Sr(E)){const ie={token:m,value:I(E),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return ee.set(f,ie),ie}const B=ee.get(f),W=B?.failedToken===m;return ee.set(f,{token:B?.token??null,value:B?.value??null,hasSettled:B?.hasSettled??!1,inflightToken:m,failedToken:W?m:null,failureCount:W?B.failureCount??0:0,retryAtMs:0}),Promise.resolve(E).then(ie=>{const fe=ee.get(f);!fe||fe.inflightToken!==m||(ee.set(f,{token:m,value:I(ie),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0}),we())},()=>{const ie=ee.get(f);if(!ie||ie.inflightToken!==m)return;const fe=ie.failedToken===m?(ie.failureCount??0)+1:1,Le=Math.min(rt,ze*2**Math.min(fe-1,8)),Ue=Date.now()+Le;ee.set(f,{...ie,inflightToken:null,failedToken:m,failureCount:fe,retryAtMs:Ue}),it(Ue)}),null},wr=(f,m,b,I)=>{const E=ee.get(f);if(E&&E.token===m&&E.hasSettled)return{value:E.value,status:"ready"};if(_V(f)&&!Jo(f,m)){if(Ki()==="loading")return yn=!0,qi(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(yn)return no(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(Date.now()-Vn<Ve)return yn=!0,no(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"}}if(io())return Ai(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(E?.failedToken===m&&E.inflightToken==null&&(E.retryAtMs??0)>Date.now())return it(E.retryAtMs),E.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!E&&f.startsWith("effInline:")&&Kr(f))return{value:null,status:"pending"};if(!E&&Ql(f,m))return{value:null,status:"pending"};if(!E||E.inflightToken!==m){const W=ba(f,m,b,I);if(W)return{value:W.value,status:"ready"}}const B=ee.get(f);return B?.hasSettled?{value:B.value,status:"stale"}:{value:null,status:"pending"}},jf=f=>{for(const m of ee.keys())f(m)&&ee.delete(m)},wa=f=>{const m=Wr(f),b=kA(f);return new Set([`contentControls:inRange:${m}`,`query:${m}`,...b?[`effInline:${b}`]:[]])},ec=f=>{const m=wa(f);jf(b=>Qo.some(I=>b.startsWith(I))&&!m.has(b));for(const b of O){const I=b.split("\0",1)[0];Qo.some(E=>I.startsWith(E))&&!m.has(I)&&O.delete(b)}},Ei=()=>{const f=_();f!==Yt&&(Jl(),br.reset(),$t={},Yt=f,ee.clear(),Nt=null,De(),te&&clearTimeout(te),te=null,Y=0,U?.timer&&clearTimeout(U.timer),U=null,H=null,C=null,o=null,be=null,O.clear(),_i.clear(),yn=!1,oo&&oo(),oo=null,ro=null,pn(),jt=null)},ks=()=>{const f=Nt!==null;zt+=1,f&&(Nt=Et()),pn()},Ss=()=>{const f=jt===Et();ks(),f&&(un([]),jt=Et()),Kt()},Uf=f=>{if(typeof f!="string"||f.length===0)return Xn("insertText requires a non-empty string.","INVALID_INPUT");if(Wn()==="viewing")return Xn("The document is read-only.","DOCUMENT_READONLY");const m=y(),b=m?.insert;if(!m||typeof b!="function")return Xn("insert is unavailable.");const I=m.selection?.current;if(typeof I!="function")return Xn("selection.current is unavailable.");const E=W=>{const ie=W&&typeof W=="object"?W:null,fe=ie?.selectionTarget??ie?.target??null;return!fe||typeof fe!="object"?Xn("insertText requires a live selection target.","PRECONDITION_FAILED"):Pt(()=>Ms(b.call(m,{type:"text",value:f,target:fe}),Xn("insert failed.")),Xn("insert failed."))};let B;try{B=I.call(m.selection)}catch{return Xn("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Sr(B)?Promise.resolve(B).then(E,()=>Xn("insertText could not resolve the live selection.","PRECONDITION_FAILED")):E(B)},tc=(f,m)=>({payload:f,state:pt,editor:_(),superdoc:t,context:m,ui:S,execute:(b,I)=>bc(b,I),executeAsync:(b,I)=>Lm(b,I),doc:y(),selection:pt.selection,documentMode:Wn(),insertText:Uf}),ti=f=>f==="editing"||f==="suggesting"||f==="viewing"?f:null,Wn=()=>{const f=_(),m=t&&typeof t=="object"?t:null,b=ti(m?.config?.documentMode),I=Pt(typeof m?.getActiveRuntime=="function"?()=>{const W=m.getActiveRuntime();return typeof W?.getSnapshot=="function"?W.getSnapshot():null}:void 0,null),E=ti(I?.documentMode),B=ti(f?.options?.documentMode);return b&&E&&b!==E?b:E??b??B},Iu=()=>{const f=t&&typeof t=="object"?t:null,m=f?.interactionConfig?.comments;if(m&&typeof m.readOnly=="boolean")return m.readOnly===!0;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},Hf=()=>{const f=t&&typeof t=="object"?t:null,m=f?.interactionConfig?.comments;if(m&&typeof m.allowResolve=="boolean")return m.allowResolve===!1;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},Vo=()=>Wn()==="viewing"||Iu(),Ti=f=>f&&typeof f=="object"?f:null,al=(f,m)=>{if(!f)return{...CV,status:m};const b=f.target??null,I=typeof f.text=="string"?f.text:"";return{status:m,empty:f.empty===!0,target:b,selectionTarget:f.selectionTarget??null,activeMarks:Array.isArray(f.activeMarks)?f.activeMarks:[],activeCommentIds:Array.isArray(f.activeCommentIds)?f.activeCommentIds:[],activeChangeIds:Array.isArray(f.activeChangeIds)?f.activeChangeIds:[],quotedText:I}},So=()=>{const f=y()?.selection;return wr("selection",Br(),()=>f?.current?f.current({includeText:!0}):void 0,Ti)},Eu=()=>{const{value:f,status:m}=So();return al(f,m)},ll=()=>{const f=y()?.selection;return f?.current?f.current({includeText:!0}):void 0},nc=f=>{if(f.empty!==!0)return!1;const m=f.selectionTarget,b=m?.start,I=m?.end;return b?.kind==="text"&&I?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===I.blockId&&typeof b.offset=="number"&&b.offset===I.offset},Tu=f=>{const m=x(),b=m?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const I=Ti(Pt(()=>b.call(m),null));if(!I||!nc(I))return;const E=Br(),B=Bo(),W=!!(B&&(B.active>0||B.pending>0));if(W)be=E,Ai();else if(be=null,ba("selection",E,ll,Ti))return;const ie=ee.get("selection"),fe=Array.isArray(I.activeMarks)&&I.activeMarks.length>0?I.activeMarks:Array.isArray(pt.selection.activeMarks)?pt.selection.activeMarks:[],Le=Array.isArray(I.activeCommentIds)?I.activeCommentIds:[],Ue=xV(f),je=ol(pt.selection),Ne=zf(I.selectionTarget)??zf(I.target),Ye=je?.range,He=Ne?.range,Xe=!!(B&&B.active>0&&je&&Ne&&je.blockId===Ne.blockId&&_r(je.story)===_r(Ne.story)&&typeof Ye?.start=="number"&&typeof He?.start=="number"&&Math.abs(He.start-Ye.start)<=2),Ze=Ue!=null||Xe?pt.selection.activeChangeIds.filter(tt=>Ue==null||fa(pt.trackChanges.items).aliasesFor(tt).includes(Ue)):[],ot=Array.isArray(I.activeChangeIds)&&I.activeChangeIds.length>0?I.activeChangeIds:Ze;ee.set("selection",{token:E,value:{...I,activeMarks:fe,activeCommentIds:Le,activeChangeIds:ot},hasSettled:!0,inflightToken:W?null:ie?.inflightToken??null})},_s=async(f=0)=>{const m=y()?.selection,b=m?.current,I=Br();if(typeof b!="function")return ee.set("selection",{token:I,value:null,hasSettled:!0,inflightToken:null}),Kt(),pt.selection;let E;try{E=b.call(m,{includeText:!0}),Sr(E)&&(E=await Promise.resolve(E))}catch{E=null}return J?al(null,"pending"):Br()!==I?f<1?_s(f+1):pt.selection:(ee.set("selection",{token:I,value:Ti(E),hasSettled:!0,inflightToken:null}),Kt(),pt.selection)},xu=f=>{const m=y()?.comments,{value:b,status:I}=wr("comments",Et(),()=>m?.list?m.list():void 0,ie=>ie&&Array.isArray(ie.items)?ie.items:[]),E=b??[],B=f.activeCommentIds;ve&&!E.some(ie=>Gn(ie)===ve)&&(ve=null);const W=ve??B[0]??null;return{status:wu(I,f.status),listStatus:I,items:E,total:E.length,activeIds:B,activeId:W}},Zi=()=>{const f=y()?.trackChanges,m=Et(),b=ee.get("trackChanges:all"),{value:I,status:E}=Nt===m?{value:b?.hasSettled?b.value:null,status:b?.hasSettled?"stale":"pending"}:wr("trackChanges:all",m,()=>{if(!f?.list)return;const B=()=>f.list({in:"all"}),W=typeof w()?.listTrackedChanges=="function",ie=Rn(B);return W?Promise.resolve(ie).then(fe=>{const Le=Xl(fe)?fe:null;return(Array.isArray(Le?.items)?Le.items:[]).some(Ue=>Cu(Ue)==null)?B():fe}):ie},B=>(B&&Array.isArray(B.items)?B.items:[]).map(il).filter(W=>W!=null));return E==="ready"?I:null},rc=f=>{const m=y()?.trackChanges,b=w(),I=typeof b?.listTrackedChanges=="function"?b.listTrackedChanges:null,E=Et(),B=yr(E),W=ee.get("trackChanges"),{value:ie,status:fe}=Nt===E?{value:W?.hasSettled?W.value:null,status:W?.hasSettled?"stale":"pending"}:wr("trackChanges",E,()=>I?Rn(()=>m?.list?.()):m?.list?m.list({in:"all"}):void 0,an=>an&&Array.isArray(an.items)?an.items:[]),Le=(ie??[]).map(il).filter(an=>an!=null).filter(an=>{const Pn=Gn(an);return!Pn||!B?.has(Pn)}),Ue=new Set;for(const an of Le){const Pn=wm(an),Hr=an,Er=Pn.author??Pn.authorEmail??Hr.author??Hr.authorEmail;typeof Er=="string"&&Ue.add(Er)}const je=m?.list?Zi():null,Ne=ue;Ne&&(Ne.story?je&&!je.some(an=>Ui(an,Ne.id,Ne.story))&&$e(null):Le.some(an=>Gn(an)===Ne.id)||$e(null));const Ye=je??Le,He=ku(Ye,Hi(f)),Xe=jt===E?[]:B?f.activeChangeIds.filter(an=>!B.has(an)):f.activeChangeIds,Ze=Xe.map(an=>He.toPublicId(an)??an),ot=ue?.story?ku(Ye,ue.story):fa(Ye),tt=ue?ot.toPublicId(ue.id)??ue.id:null,Bt=PV({selectionIds:Xe,publicIds:Ze,selection:f,bodyItems:Le,allStoryItems:je}),Qt=tt??Bt;return{status:wu(fe,f.status),items:Le,total:Le.length,activeId:Qt,authors:[...Ue]}},oc=f=>{const m=y()?.contentControls,{value:b,status:I}=wr("contentControls",Et(),()=>m?.list?m.list():void 0,ie=>ie&&Array.isArray(ie.items)?ie.items:[]),E=b??[],{ids:B,status:W}=Ru(m,f);return{status:wu(I,W,f.status),items:E,total:E.length,activeId:B[0]??null,activeIds:B}},pi=(f,m)=>{if(!f||typeof f.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=OV(m);if(!b)return{lockModesById:new Map,status:"ready"};const{value:I,status:E}=wr(`contentControls:inRange:${Wr(m)}`,Et(),()=>f.listInRange(b),ie=>ie&&Array.isArray(ie.items)?ie.items:[]),B=I??[],W=new Map;for(const ie of B)typeof ie?.id=="string"&&W.set(ie.id,typeof ie.lockMode=="string"?ie.lockMode:"unlocked");return{lockModesById:W,status:E}},Ru=(f,m)=>{const{lockModesById:b,status:I}=pi(f,m);return{ids:[...b.keys()],status:I}},$f=()=>{const f=t?.fonts;return{options:cj(aj(Pt(f?.getDocumentFontOptions?()=>f.getDocumentFontOptions():void 0,[])),lj(Pt(f?.getFontFamilyOptions?()=>f.getFontFamilyOptions():void 0,[]))),sizeOptions:uj}},cl=()=>{const f=Pt(t?.getZoomState?()=>t.getZoomState():void 0,null),m=typeof f?.value=="number"?f.value:100,b=f?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:m,min:typeof f?.min=="number"?f.min:10,max:typeof f?.max=="number"?f.max:100}},Gf=()=>Pt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",ul=()=>{const f=_();return{ready:f!=null,mode:Wn(),dirty:f?!!f.isDirty:!1}},jo=f=>{const m=f.quotedText;if(typeof m!="string"||m.length===0)return null;const b=_u(f);if(b.length===0||!Yl(b.map(B=>B.blockId)))return null;const I=f.target,E=b.length===1?Co(b[0].blockId,I?.story):void 0;return{select:{type:"text",pattern:m,mode:"contains",caseSensitive:!0},...E?{within:E}:{},require:"any"}},Cr=f=>{const m=y()?.query;if(typeof m?.match!="function")return null;const b=jo(f);if(!b)return null;const{value:I}=wr(`query:${Wr(f)}`,Et(),()=>m.match(b),E=>E&&typeof E=="object"?E:null);return SA(I,f)},Mu=f=>{const m=x(),b=new Set(Nr(f));if(b.size===0)return{};const I=m?.readMountedProjectionBlocksByIds,E=m?.readMountedProjectionBlocks;if(typeof I!="function"&&typeof E!="function")return{};const B=Pt(()=>{if(typeof I!="function")return E.call(m);const Xe=$i(f);return Xe?I.call(m,[...b],Xe):I.call(m,[...b])},null);if(!Array.isArray(B))return{};const W=h2(B),ie=Xe=>{const Ze={},ot=d2(Xe.fontFamily);ot&&(Ze.fontFamily=ot);const tt=WV(Xe.fontSize);return tt&&(Ze.fontSize=tt),typeof Xe.color=="string"&&Xe.color.trim()!==""&&(Ze.color=Xe.color.trim().toUpperCase()),typeof Xe.highlight=="string"&&Xe.highlight.trim()!==""&&(Ze.highlight=Xe.highlight.trim().toUpperCase()),Ze},fe=ol(f),Le=fe&&typeof fe.range?.start=="number"?fe.range.start:null;if(fe&&Le!==null&&b.has(fe.blockId)){const Xe=W.find(ot=>Zl(ot,fe.blockId)),Ze=Xe&&Array.isArray(Xe.runs)?Xe.runs:null;if(Ze&&Ze.length>0&&Ze.every(ot=>ot?.kind==="text"||ot?.kind==="tab")){let ot=0,tt=null;for(const Bt of Ze){const Qt=km(Bt);if(Le>=ot&&Le<ot+Qt){tt=Bt;break}ot+=Qt}if(!tt){for(let Bt=Ze.length-1;Bt>=0&&!tt;Bt-=1)Ze[Bt]?.kind==="text"&&(tt=Ze[Bt]);tt??=Ze[Ze.length-1]??null}return tt?ie(tt):{}}}const Ue=_u(f);if(Ue.length>0){const Xe=new Set,Ze=new Set;let ot=!1,tt=!0;for(const Bt of Ue){const Qt=W.find(Hr=>Zl(Hr,Bt.blockId));if(!Qt)return{};const an=Array.isArray(Qt.runs)?Qt.runs:[];if(an.length===0)continue;if(!an.every(Hr=>Hr?.kind==="text"||Hr?.kind==="tab")){tt=!1;break}let Pn=0;for(const Hr of an){const Er=km(Hr),Tr=Pn,Lr=Pn+Er;if(Tr<Bt.end&&Lr>Bt.start){ot=!0;const $o=ie(Hr);$o.fontFamily&&Xe.add($o.fontFamily),$o.fontSize&&Ze.add($o.fontSize)}Pn=Lr}}if(tt&&ot){const Bt={};return Xe.size===1&&(Bt.fontFamily=[...Xe][0]),Ze.size===1&&(Bt.fontSize=[...Ze][0]),Bt}}const je=new Set,Ne=new Set;let Ye=!1;for(const Xe of W){if(![...b].some(ot=>Zl(Xe,ot)))continue;const Ze=Array.isArray(Xe.runs)?Xe.runs:[];for(const ot of Ze){if(ot?.kind!=="text")continue;Ye=!0;const tt=ie(ot);tt.fontFamily&&je.add(tt.fontFamily),tt.fontSize&&Ne.add(tt.fontSize)}}if(!Ye)return{};const He={};return je.size===1&&(He.fontFamily=[...je][0]),Ne.size===1&&(He.fontSize=[...Ne][0]),He},dl=f=>{const m=x(),b=new Set(Nr(f));if(b.size===0)return{};const I=m?.readMountedProjectionBlocksByIds,E=m?.readMountedProjectionBlocks;if(typeof I!="function"&&typeof E!="function")return{};const B=Pt(()=>{if(typeof I!="function")return E.call(m);const He=$i(f);return He?I.call(m,[...b],He):I.call(m,[...b])},null);if(!Array.isArray(B))return{};const W=h2(B),ie=He=>({bold:He.bold===!0,italic:He.italic===!0,underline:He.underline!=null,strikethrough:He.strike===!0}),fe=He=>{const Xe={};for(const Ze of Vf){const ot=He[Ze];ot.size===1&&(Xe[Ze]=[...ot][0])}return Xe},Le=ol(f),Ue=Le&&typeof Le.range?.start=="number"?Le.range.start:null;if(Le&&Ue!==null&&b.has(Le.blockId)){const He=W.find(Ze=>Zl(Ze,Le.blockId)),Xe=He&&Array.isArray(He.runs)?He.runs:null;if(Xe&&Xe.length>0&&Xe.every(Ze=>Ze?.kind==="text"||Ze?.kind==="tab")){let Ze=0,ot=null;for(const tt of Xe){const Bt=km(tt);if(Ue>=Ze&&Ue<Ze+Bt){ot=tt;break}Ze+=Bt}if(!ot){for(let tt=Xe.length-1;tt>=0&&!ot;tt-=1)Xe[tt]?.kind==="text"&&(ot=Xe[tt]);ot??=Xe[Xe.length-1]??null}return ot?ie(ot):{}}}const je=_u(f);if(je.length>0){const He={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Xe=!1,Ze=!0;for(const ot of je){const tt=W.find(an=>Zl(an,ot.blockId));if(!tt)return{};const Bt=Array.isArray(tt.runs)?tt.runs:[];if(Bt.length===0)continue;if(!Bt.every(an=>an?.kind==="text"||an?.kind==="tab")){Ze=!1;break}let Qt=0;for(const an of Bt){const Pn=km(an),Hr=Qt,Er=Qt+Pn;if(Hr<ot.end&&Er>ot.start){Xe=!0;const Tr=ie(an);for(const Lr of Vf)He[Lr].add(Tr[Lr])}Qt=Er}}if(Ze&&Xe)return fe(He)}const Ne={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ye=!1;for(const He of W){if(![...b].some(Ze=>Zl(He,Ze)))continue;const Xe=Array.isArray(He.runs)?He.runs:[];for(const Ze of Xe){if(Ze?.kind!=="text")continue;Ye=!0;const ot=ie(Ze);for(const tt of Vf)Ne[tt].add(ot[tt])}}return Ye?fe(Ne):{}},Ca=(f,m)=>{if(m.fontFamily!==void 0&&m.fontSize!==void 0&&m.color!==void 0&&m.highlight!==void 0)return{values:m,effectiveUniformityStatus:"ready"};const b=Mu(f),I={...b.fontFamily!==void 0?{fontFamily:b.fontFamily}:{},...b.fontSize!==void 0?{fontSize:b.fontSize}:{},...b.color!==void 0?{color:b.color}:{},...b.highlight!==void 0?{highlight:b.highlight}:{},...m};if(!f.empty&&(I.fontFamily===void 0||I.fontSize===void 0)){const E=ic(f);return E.values&&(I.fontFamily===void 0&&E.values.fontFamily!==void 0&&(I.fontFamily=E.values.fontFamily),I.fontSize===void 0&&E.values.fontSize!==void 0&&(I.fontSize=E.values.fontSize)),{values:I,effectiveUniformityStatus:E.status}}return{values:I,effectiveUniformityStatus:"ready"}},Lu=["fontFamily","fontSize","bold","italic","underline","strikethrough"],mi=f=>{const m=f.selectionTarget;if(!m)return{value:null,status:"ready"};const b=vr(y(),"format.readEffectiveInlineUniformity");if(!b)return{value:null,status:"ready"};const I=kA(f)??Wr(f);return wr(`effInline:${I}`,Et(),()=>b({target:m,offsetSpace:"selection",keys:Lu}),E=>E&&typeof E=="object"?E:null)},ic=f=>{const{value:m,status:b}=mi(f);if(!m||m.success!==!0)return{values:null,status:b};const I=m.values,E=B=>{const W=I?.[B];if(!(!W||W.state!=="uniform"||typeof W.value!="string"))return B==="fontFamily"?d2(W.value):W.value};return{values:{fontFamily:E("fontFamily"),fontSize:E("fontSize")},status:b}},Pu=f=>{const{value:m,status:b}=mi(f);if(!m||m.success!==!0)return{values:null,status:b};const I=m.values,E={};for(const B of Vf){const W=I?.[B];W?.state==="uniform"&&(W.value==="true"||W.value==="false")&&(E[B]=W.value==="true")}return{values:E,status:b}},Du=(f,m)=>{const b=f.activeMark;if(!b||!Vf.includes(b))return null;const I=b,E=dl(m)[I];if(E!==void 0)return E;const{values:B}=Pu(m),W=B?.[I];return W!==void 0?W:null},sc=async f=>{const m=f.selectionTarget;if(!m)return null;const b=vr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const I=await Promise.resolve(b({target:m,offsetSpace:"selection"}));return I&&typeof I=="object"&&I.success===!0?I:null}catch{return null}},Ou=(f,m,b)=>{const I=b.values;for(const E of["fontFamily","fontSize"]){if(m[E]!==void 0)continue;const B=I?.[E];B?.state==="uniform"&&typeof B.value=="string"?f[E]=E==="fontFamily"?d2(B.value):B.value:delete f[E]}},ac=f=>Ca(f,_A(Cr(f),f)),fl=f=>ac(f).values,Fu=async f=>{const m=y()?.query,b=jo(f);if(typeof m?.match!="function"||!b)return fl(f);try{const I=await Promise.resolve(m.match(b)),E=_A(SA(I&&typeof I=="object"?I:null,f),f),B=Ca(f,E);if(B.effectiveUniformityStatus!=="ready"&&(E.fontFamily===void 0||E.fontSize===void 0)){const W=await sc(f);W&&Ou(B.values,E,W)}return B.values}catch{return fl(f)}},As=async f=>{const m=y();if(m)return typeof m.getNode=="function"?await Promise.resolve(m.getNode(f)):await Promise.resolve(m.getNodeById?.({nodeId:f.nodeId,nodeType:f.nodeType}))},lc=f=>{const m=y()?.query;if(typeof m?.match!="function")return"ready";const b=jo(f);if(!b)return"ready";const{status:I}=wr(`query:${Wr(f)}`,Et(),()=>m.match(b),E=>E&&typeof E=="object"?E:null);return I},Nu=f=>{const m=ac(f),b=m.values;if(f.empty)return m;const I=pa(f);return I?f.status==="ready"&&lc(f)==="ready"&&m.effectiveUniformityStatus==="ready"?(C={key:I,values:b},m):C&&C.key===I?{...m,values:{...C.values,...b}}:m:m},Bu=f=>{const m=y(),b=Nu(f),I=b.values;f.status==="ready"&&!f.empty&&lc(f)==="ready"&&b.effectiveUniformityStatus==="ready"&&(v=I,k=`${Kl(f)}:${Et()}`);const E=m?.contentControls,{lockModesById:B}=pi(E,f),W={};for(const ie of ae())W[ie]=uc(ie,m,f,I,B);return W},xi=f=>f?dt.operationUnavailable:_()?dt.documentApiUnavailable:dt.notReady,Ri=f=>f==="contentLocked"||f==="sdtContentLocked",Is=f=>{for(const m of f.values())if(Ri(m))return dt.contentControlLocked},zu=(f,m,b,I,E)=>{if(!m)return f.scope==="all"?dt.bulkDecisionsDisabled:xi(E);if(b)return dt.documentReadonly;if(f.scope!=="all"&&I.activeChangeIds.length===0)return dt.selectionRequired},Vu=f=>{const m=x(),b=Pt(typeof m?.getCapabilities=="function"?()=>m.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(I=>I?.command===f||I?.id===f)??null;if(b&&typeof b=="object"){const I=b[f];return I&&typeof I=="object"?I:null}return null},cc=(f,m)=>{if(f.scope!=="all"||typeof m?.[`${f.kind}All`]=="function")return;const b=Vu(`trackedChanges.${f.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return dt.bulkDecisionsDisabled},uc=(f,m,b,I,E=new Map)=>{if(he.has(f))return cn({supported:!0,enabled:!0,...Pt(he.get(f).getState?()=>he.get(f).getState(tc(void 0)):void 0,{})},"custom");const B=Wn()==="viewing",W=hA(f);if(W&&typeof T()?.lists?.apply=="function"){const Ye=Q(),He=typeof Ye?.shippedStatus=="string"?Ye.shippedStatus:null,Xe=He!=="not-shipped"&&He!=="disabled";return cn({enabled:Xe&&(typeof Ye?.enabled=="boolean"?Ye.enabled:!0),active:(Xe?K(Ye):null)===W,supported:Xe,value:Ye?.value},"builtin")}const ie=Sm(f);if(ie){const Ye=m?.trackChanges,He=typeof Ye?.decide=="function"||typeof Ye?.[ie.kind]=="function",Xe=typeof Ye?.decide=="function"||typeof Ye?.[`${ie.kind}All`]=="function",Ze=ie.scope==="all"?Xe:He,ot=cc(ie,Ye)??zu(ie,Ze,Vo(),b,m);return cn({enabled:ot==null,active:!1,supported:Ze,reason:ot},"builtin")}if(f==="copy-format")return Wn()==="viewing"?cn({supported:!0,enabled:!1,active:!1},"builtin"):_()?cn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):cn({supported:!0,enabled:!1,active:!1,reason:dt.notReady},"builtin");const fe=gu(f);if(!fe)return cn({enabled:!1,active:!1,supported:!1,reason:dt.commandUnsupported},"unsupported");if(fe.disposition!=="routed")return cn({enabled:!1,active:!1,supported:!1,reason:fe.reason??dt.commandUnsupported},fe.disposition==="unsupported"?"unsupported":"builtin");if(fe.instanceRoute)return Zf(fe);if(fe.table)return M(fe,m,B);if(fe.inline?.kind==="clear"){if(fe.mutates&&B)return cn({enabled:!1,active:!1,supported:!0,reason:dt.documentReadonly},"builtin");const Ye=Is(E);if(Ye)return cn({enabled:!1,active:!1,supported:!0,reason:Ye},"builtin");const He=Nr(b).length>0||Au(b)!=null;return cn({enabled:He,active:!1,supported:!0,reason:He?void 0:dt.selectionRequired},"builtin")}const Le=fe.docRoute;if(!Le)return cn({enabled:!1,active:!1,supported:!1,reason:dt.commandUnsupported},"unsupported");if(vr(m,Le)==null)return cn({enabled:!1,active:!1,supported:!1,reason:xi(m)},"builtin");const Ue=se(f);if(Ue){const Ye=Ue.shippedStatus,He=Ye!=="not-shipped"&&Ye!=="disabled",Xe=typeof Ue.enabled=="boolean"?Ue.enabled:!0,Ze=f==="undo"||f==="redo",ot=Ze&&Ue.historyResolved===!1,tt=Ze&&He&&Xe===!1&&Ue.reason===null&&!ot,Bt=Ue.reason===void 0?void 0:tt?dt.historyEmpty:ot?dt.notReady:s2(Ue.reason,dt.commandUnsupported);return fe.mutates&&B?cn({enabled:!1,active:!1,supported:He,reason:dt.documentReadonly},"builtin"):cn({enabled:He&&Xe,active:!1,supported:He,reason:Bt},"builtin")}const je=Es(fe,m,b),Ne=Uu(fe,m,b,I);if(fe.list?.mode==="indent"||fe.list?.mode==="outdent")return Yf(fe,m,B,b,je,Ne);if(fe.list?.mode==="toggle-seed")return Xf(fe,m,B,b,je,Ne);if(fe.mutates&&B)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:dt.documentReadonly},"builtin");if(fe.inline&&!Au(b)){const Ye=Is(E);return cn(Ye?{enabled:!1,active:je,supported:!0,value:Ne,reason:Ye}:Nr(b).length>0&&typeof x()?.setPendingInlineFormat=="function"?{enabled:!0,active:je,supported:!0,value:Ne}:{enabled:!1,active:je,supported:!0,value:Ne,reason:dt.rangeSelectionRequired},"builtin")}if((fe.blockParagraph||fe.list)&&Nr(b).length===0)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:dt.selectionRequired},"builtin");if(fe.link&&!je&&c2(b).length===0&&!ol(b))return cn({enabled:!1,active:je,supported:!0,reason:dt.rangeSelectionRequired},"builtin");if(fe.inline){const Ye=Is(E);if(Ye)return cn({enabled:!1,active:je,supported:!0,value:Ne,reason:Ye},"builtin")}return cn({enabled:!0,active:je,supported:!0,value:Ne},"builtin")};function ju(f,m){const b=f.address?.anchor,I=b?.start,E=b?.end,B=typeof I?.blockId=="string"?I.blockId:null,W=typeof E?.blockId=="string"?E.blockId:null;if(!B||!W)return!1;const ie=typeof I?.offset=="number"?I.offset:null,fe=typeof E?.offset=="number"?E.offset:null;if(ie==null||fe==null)return!1;const Le=m.target,Ue=Le&&Array.isArray(Le.segments)?Le.segments:[];for(const je of Ue){const Ne=typeof je?.blockId=="string"?je.blockId:null;if(!Ne)continue;const Ye=je.range,He=typeof Ye?.start=="number"?Ye.start:null,Xe=typeof Ye?.end=="number"?Ye.end:null;if(!(He==null||Xe==null)){if(B!==W){if(Ne===B&&Xe>ie||Ne===W&&He<fe)return!0;continue}if(Ne===B){if(He===Xe){if(He>=ie&&He<=fe)return!0;continue}if(Math.max(He,ie)<Math.min(Xe,fe))return!0}}}return!1}const dc=(f,m)=>{const b=f?.hyperlinks;if(!b||typeof b.list!="function")return null;const I=Nr(m);if(!Yl(I))return null;for(const E of I){const B={kind:"block",nodeType:"paragraph",nodeId:E},{value:W}=wr(`hyperlinks:${E}`,Et(),()=>b.list({within:B}),fe=>fe&&typeof fe=="object"?fe:null),ie=(W&&Array.isArray(W.items)?W.items:[]).find(fe=>ju(fe,m));if(ie)return ie}return null},Es=(f,m,b)=>{if(f.link)return dc(m,b)!=null;if(f.list?.mode==="toggle-seed"&&f.list.seed)return $u(m,b)===f.list.seed;const I=$(f);if(I!==null)return I;const E=r.get(f.id),B=pa(b);if(B&&E?.selectionSignature===B)return E.active;const W=Du(f,b);return W!==null?W:dj(f,b)},Uu=(f,m,b,I)=>{if(f.inline&&u2(f.inline.key)){const E=R(f);if(E!==void 0)return E;const B=I[f.inline.key];if(B!==void 0)return B;const W=pa(b),ie=W?n.get(f.inline.key):void 0;if(W&&ie?.selectionSignature===W)return ie.value}if(f.id==="linked-style"){const{style:E}=Te(b,Se().cache);return!E.styleId||E.mixed?void 0:{styleId:E.styleId,styleName:E.styleName}}if(f.id==="text-align")return hc(m,b);if(f.id==="link")return mc(m,b)??void 0},fc=(f,m,b)=>{const I=f?.lists;if(!I)return{value:null,status:"ready"};const E=b.storyType==="body",B=typeof I.getStateInStory=="function"?()=>I.getStateInStory({target:ha(m),story:b}):E&&typeof I.getState=="function"?()=>I.getState({target:ha(m)}):null;if(!B)return{value:null,status:"ready"};const{value:W,status:ie}=wr(`lists:${_r(b)}:${m}`,Et(),B,fe=>fe&&typeof fe=="object"?fe:null);return{value:W?.success===!0?W:null,status:ie}},Wf=(f,m,b)=>fc(f,m,b).value,Hu=(f,m,b)=>{const I=Wf(f,m,b);return!I||I.isListItem!==!0?null:I.seed==="bullet"||I.seed==="ordered"?I.seed:null},Uo=(f,m,b)=>{const I=fc(f,m,b),E=I.value;return{value:E&&typeof E.isListItem=="boolean"?E.isListItem:null,status:I.status}},$u=(f,m)=>{const b=Nr(m);if(b.length===0||!Yl(b))return null;const I=Hi(m),E=Hu(f,b[0],I);if(E!=="bullet"&&E!=="ordered")return null;for(const B of b.slice(1))if(Hu(f,B,I)!==E)return null;return E},hl=(f,m,b)=>{if(!f)return{value:null,status:"ready",refreshing:!1};const I=_r(b),E=I==="story:body";if(E&&typeof f.getNodeById!="function")return{value:null,status:"ready",refreshing:!1};if(!E&&typeof f.getNode!="function")return{value:null,status:"ready",refreshing:!1};const B=`node:${I}:${m}`,W=Et(),ie=wr(B,W,()=>E?f.getNodeById({nodeId:m,nodeType:"paragraph"}):f.getNode(Co(m,b)),Le=>Le&&typeof Le=="object"?Le:null),fe=ee.get(B);return{...ie,refreshing:ie.status==="stale"&&fe?.inflightToken===W&&fe.failedToken!==W}},pl=f=>f==="left"||f==="center"||f==="right"||f==="justify"?f:void 0,Gu=f=>f==="start"||f==="end"||f==="distributed"||f==="numTab"||f==="lowKashida"||f==="mediumKashida"||f==="highKashida"||f==="thaiDistribute",ka=(f,m)=>{const b=x(),I=b?.readMountedProjectionBlocksByIds;if(typeof I!="function")return null;const E=$i(f),B=Pt(()=>E?I.call(b,[...m],E):I.call(b,[...m]),null);if(!Array.isArray(B))return new Map;const W=h2(B),ie=new Map;for(const fe of m){const Le=W.find(Ye=>Zl(Ye,fe));if(!Le)continue;const Ue=Le.attrs,je=pl(Ue?.alignment),Ne=S9(Ue);ie.set(fe,je??(Ne==="rtl"?"right":"left"))}return ie},Wu=(f,m,b,I)=>{const{value:E,status:B,refreshing:W}=hl(f,m,b),ie=I?.get(m);if(B==="pending")return ie?{status:"uniform",value:ie}:{status:"pending"};if(B==="stale"&&!W)return{status:"pending"};if(B==="stale"&&ie)return{status:"uniform",value:ie};if(B==="stale"&&I&&!ie)return{status:"unavailable"};if(!E)return{status:"unavailable"};const fe=E.node;if(!fe)return{status:"unavailable"};const Le=fe.kind;if(Le!=="paragraph"&&Le!=="heading")return{status:"unavailable"};const Ue=fe[Le];if(!Ue||typeof Ue!="object")return{status:"unavailable"};const je=Ue.props?.alignment;if(je==null)return ie?{status:"uniform",value:ie}:{status:"unavailable"};const Ne=pl(je);return Ne?{status:"uniform",value:Ne}:Gu(je)&&ie?{status:"uniform",value:ie}:{status:"unavailable"}},Kf=(f,m)=>{const b=Nr(m);if(b.length===0||!Yl(b))return{status:"unavailable"};const I=Hi(m),E=ka(m,b),B=Wu(f,b[0],I,E);if(B.status!=="uniform")return B;for(const W of b.slice(1)){const ie=Wu(f,W,I,E);if(ie.status!=="uniform")return ie;if(ie.value!==B.value)return{status:"mixed"}}return B},Ku=f=>{const m=Nr(f);return m.length===0?null:`${_r(Hi(f))}:${m.join(",")}`},hc=(f,m)=>{const b=Kf(f,m),I=b.status==="uniform"?b.value:void 0,E=o;if(!E)return I;const B=Ku(m);return B&&B!==E.selectionSignature?(o=null,I):!B||!E.settled?E.value:b.status!=="pending"?(o=null,I):E.value},pc=(f,m)=>{const b=pl(m),I=Ku(f),E=Nr(f);if(!b||!I||E.length===0)return null;const B=++i;return o={selectionSignature:I,value:b,generation:B,settled:!1,canReconcile:Yl(E)},Kt(),B},qu=(f,m)=>{if(f==null)return;const b=o;if(!(!b||b.generation!==f)){if(!ko(m)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},ni=async(f,m,b)=>{const I=f?.lists;if(!I)return null;try{const E=b.storyType==="body",B=typeof I.getStateInStory=="function"?await I.getStateInStory({target:ha(m),story:b}):E&&typeof I.getState=="function"?await I.getState({target:ha(m)}):null,W=B&&typeof B=="object"?B:null;return!W||W.success!==!0||typeof W.isListItem!="boolean"?null:W.isListItem}catch{return null}},Yr=(f,m,b)=>{const I={resolved:!1,seed:null},E=f?.lists;if(!E)return I;const B=b.storyType==="body",W=typeof E.getStateInStory=="function"?()=>E.getStateInStory({target:ha(m),story:b}):B&&typeof E.getState=="function"?()=>E.getState({target:ha(m)}):null;if(!W)return I;const ie=fe=>{const Le=fe&&typeof fe=="object"?fe:null;return!Le||Le.success!==!0||typeof Le.isListItem!="boolean"?I:{resolved:!0,seed:Le.isListItem===!0&&(Le.seed==="bullet"||Le.seed==="ordered")?Le.seed:null}};try{const fe=W();return Sr(fe)?Promise.resolve(fe).then(ie,()=>I):ie(fe)}catch{return I}},qf=async(f,m,b)=>{if(!f)return null;try{const I=!b||b.storyType==="body",E=b&&typeof f.getNode=="function"?await f.getNode(Co(m,b)):I&&typeof f.getNodeById=="function"?await f.getNodeById({nodeId:m,nodeType:"paragraph"}):null;return NV(E&&typeof E=="object"?E:null)}catch{return null}},Yf=(f,m,b,I,E,B)=>{if(f.mutates&&b)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.documentReadonly},"builtin");const W=Nr(I);if(W.length===0)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.selectionRequired},"builtin");const ie=f.docRoute?vr(m,f.docRoute):null,fe=vr(m,"format.paragraph.setIndentation"),Le=vr(m,"format.paragraph.clearIndentation"),Ue=f.list?.mode,je=Ue==="indent"?fe!=null:fe!=null||Le!=null,Ne=Hi(I);let Ye=null;if(Ne.storyType!=="body"){Ye=[];for(const He of W){const{value:Xe,status:Ze}=Uo(m,He,Ne);if(Xe===null)return Ze!=="ready"&&(ie!=null||je)?cn({enabled:!0,active:E,supported:!0,value:B},"builtin"):cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin");Ye.push(Xe)}}if(Ye?.some(He=>He===!0)){const He=Ue==="indent"?"lists.indentRange":"lists.outdentRange",Xe=Wn()!=="suggesting"&&Ye.every(ot=>ot===!0)&&vr(m,He)!=null,Ze=Ue==="outdent"&&vr(m,"lists.outdentInStory")!=null;if(!Xe&&!Ze)return cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")}for(const[He,Xe]of W.entries()){const Ze=Ye?{value:Ye[He]??null,status:"ready"}:Uo(m,Xe,Ne),ot=Ze.value;if(ot===!0){if(ie!=null)return cn({enabled:!0,active:E,supported:!0,value:B},"builtin");continue}if(ot===!1&&je){if(Ne.storyType!=="body"&&typeof m?.getNode!="function")continue;return cn({enabled:!0,active:E,supported:!0,value:B},"builtin")}if(ot===null)return Ze.status!=="ready"&&(ie!=null||je)?cn({enabled:!0,active:E,supported:!0,value:B},"builtin"):cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")}return cn({enabled:!1,active:E,supported:!1,value:B,reason:xi(m)},"builtin")},Xf=(f,m,b,I,E,B)=>{if(f.mutates&&b)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.documentReadonly},"builtin");const W=Nr(I);if(W.length===0)return cn({enabled:!1,active:E,supported:!0,value:B,reason:dt.selectionRequired},"builtin");const ie=Hi(I),fe=m?.lists;if(!(typeof fe?.getStateInStory=="function"||ie.storyType==="body"&&typeof fe?.getState=="function"))return cn({enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");if(!Yl(W))return cn(ie.storyType==="body"&&vr(m,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Le=W.map(Ye=>fc(m,Ye,ie));if(Le.some(({status:Ye})=>Ye!=="ready"))return cn({enabled:!0,active:E,supported:!0,value:B},"builtin");if(Le.some(({value:Ye})=>Ye===null))return cn({enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Ue=f.list?.seed,je=Le.every(({value:Ye})=>Ye?.isListItem===!0&&Ye.seed===Ue);if(ie.storyType==="body")return cn(!je||vr(m,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin");const Ne=vr(m,"lists.removeInStory");return cn(je&&Ne?{enabled:!0,active:E,supported:!0,value:B}:{enabled:!1,active:E,supported:!1,value:B,reason:dt.operationUnavailable},"builtin")},mc=(f,m)=>{const b=dc(f,m)?.properties?.href;return typeof b=="string"?b:null},Zf=f=>{if(!_())return cn({enabled:!1,active:!1,supported:!1,reason:dt.notReady},"builtin");const m=f.instanceRoute;return typeof t?.[m]!="function"?cn({enabled:!1,active:!1,supported:!1,reason:dt.operationUnavailable},"builtin"):cn({enabled:!0,active:A(f),supported:!0,value:Z(f)},"builtin")},A=f=>{const m=t?.config??void 0;return f.valueFrom==="ruler"?!!m?.rulers:f.valueFrom==="formattingMarks"?!!m?.layoutEngineOptions?.showFormattingMarks:!1},M=(f,m,b)=>{if(b)return cn({enabled:!1,active:!1,supported:!0,reason:dt.documentReadonly},"builtin");const I=Be();return I!=null&&(!f.table.requiresCell||I.cellNodeId!=null)?(f.docRoute?vr(m,f.docRoute):null)==null?cn({enabled:!1,active:!1,supported:!1,reason:xi(m)},"builtin"):cn({enabled:!0,active:!1,supported:!0},"builtin"):cn({enabled:!1,active:!1,supported:!0,reason:dt.tableContextUnavailable},"builtin")},Z=f=>{if(f.valueFrom==="zoom")return cl().value;if(f.valueFrom==="documentMode")return Wn();if(f.valueFrom==="measurementUnit")return Gf();if(f.valueFrom==="ruler"||f.valueFrom==="formattingMarks")return A(f)},oe=(f,m)=>f.id==="zoom"?typeof m=="number"&&Number.isFinite(m)&&m>0:f.id==="document-mode"?m==="editing"||m==="suggesting"||m==="viewing":f.id==="measurement-unit"?m==="in"||m==="cm":!0,ae=()=>[...new Set([...kN,...he.keys()])],pe="Normal",le={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},ce=f=>{const m=y()?.styles;return!m||typeof m.getCatalog!="function"?{value:null,status:"ready"}:wr(`styles:catalog:${JSON.stringify(f??{})}`,Et(),()=>m.getCatalog(f),b=>b&&typeof b=="object"?b:null)},Se=()=>{const f=ce({includePreview:!0});if(!f.value)return{cache:null,status:f.status};const m=ce({view:"quickGallery",includePreview:!0}),b=m.value?m.value.items:f.value.styles.filter(E=>E.visibility.quickGallery),I=new Map;for(const E of f.value.styles)I.set(E.id,E);return{cache:{full:f.value,quickGallery:b,byId:I},status:wu(f.status,m.status)}},Me=(f,m,b)=>{const{value:I,status:E}=hl(f,m,b);if(!I)return{ok:!1,styleRef:null,status:E};const B=I.node;if(!B||typeof B!="object")return{ok:!1,styleRef:null,status:E};const W=B.kind,ie=typeof W=="string"?B[W]:void 0,fe=ie&&typeof ie=="object"?ie.styleRef:void 0;return{ok:!0,styleRef:typeof fe=="string"&&fe.length>0?fe:null,status:E}},Te=(f,m)=>{const b=[],I=y();if(!I)return b.push({severity:"warning",code:"active-style-unavailable",message:"Active paragraph style is unavailable: the Document API is not reachable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};const E=Nr(f);if(E.length===0)return b.push({severity:"info",code:"active-style-no-selection",message:"No paragraph block is resolvable from the current selection; active paragraph style is unavailable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};if(!Yl(E))return b.push({severity:"info",code:"active-style-selection-too-large",message:"Active paragraph style is unavailable for a large multi-paragraph selection."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:"ready"};const B=m?.full.defaults.paragraphStyleId??(m?pe:null),W=new Set;let ie=0,fe=0,Le=0,Ue="ready";const je=Hi(f);for(const He of E){const Xe=Me(I,He,je);if(Ue=wu(Ue,Xe.status),!Xe.ok){fe+=1;continue}if(!Xe.styleRef&&!B){Le+=1;continue}const Ze=Xe.styleRef??B;if(!Ze){Le+=1;continue}ie+=1,W.add(Ze)}if(ie===0){const He=Le>0&&fe===0;return b.push({severity:"warning",code:He?"active-style-default-unavailable":"active-style-read-failed",message:He?"Selected paragraphs have no explicit style and the style catalogue is unavailable, so the document default cannot be resolved.":"Could not read the paragraph style of any selected block; active paragraph style is unavailable."}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ue}}const Ne=fe+Le;if(Ne>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${ie} of ${ie+Ne} selected blocks; ${Ne} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ue};if(W.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:Ue};const Ye=[...W][0];return{style:{styleId:Ye,styleName:m?.byId.get(Ye)?.name??null,mixed:!1,diagnostics:b},status:Ue}},Fe=f=>{if(!_())return le;const{cache:m,status:b}=Se(),{style:I,status:E}=Te(f,m);let B;return m?B=I.diagnostics.length===0?m.full.diagnostics:[...m.full.diagnostics,...I.diagnostics]:B=[{severity:"warning",code:"catalog-unavailable",message:"The style catalogue is unavailable: the Document API styles surface is not reachable (e.g. viewing mode or a worker-backed editor)."},...I.diagnostics],{ready:!0,status:wu(b,E,f.status),catalogRevision:m?.full.revision??null,quickGallery:m?.quickGallery??[],activeParagraphStyleId:I.styleId,activeParagraphStyleName:I.styleName,mixedSelection:I.mixed,sourceStatus:m?.full.sourceStatus??null,diagnostics:B}},Ge=()=>{const f=Wn(),m=Eu();m.status==="ready"&&ec(m),V(m);const b=pa(m);for(const[I,E]of r)(!b||E.selectionSignature!==b||E.settled&&m.status==="ready")&&r.delete(I);return{ready:_()!=null,documentMode:f,document:ul(),selection:m,toolbar:{context:f,commands:Bu(m),copyFormatActive:h.mode!=="idle"},comments:xu(m),trackChanges:rc(m),contentControls:oc(m),zoom:cl(),fonts:$f(),styles:Fe(m)}},ct=f=>{const m=pa(f);m&&a&&m!==a&&(n.clear(),r.clear()),m&&(a=m)};let et=null,kt=null,ht=null,Ot=null,on=!1;const At=()=>{if(J||on)return;on=!0;const f=()=>{on&&(on=!1,!J&&Kt())};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},hr=()=>{const f=T();if(f!==ht&&(Ot&&(Ot(),Ot=null),ht=f,!(!f||typeof f.subscribe!="function")))try{const m=f.subscribe(()=>At());typeof m=="function"&&(Ot=m)}catch{ht=null}};let Xt=null,Mt=null,jn=null,pr=null,er=null,zr=null;const Lo=()=>{const f=_()?.host,m=Pt(f?.getHandles?()=>f.getHandles():void 0,null)?.editing?.selection;return m&&typeof m.subscribe=="function"?m:null},lt=()=>{const f=Lo();if(f!==et&&(kt&&(kt(),kt=null),et=f,!!f))try{const m=f.subscribe(b=>{_t+=1,Tu(b),Kt()});typeof m=="function"&&(kt=m)}catch{et=null}},An=()=>{const f=_()?.host,m=Pt(f?.getHandles?()=>f.getHandles():void 0,null)?.review;return m&&typeof m.subscribe=="function"?m:null},Xr=f=>f?typeof f.getActiveReviewTarget=="function"?Pt(()=>f.getActiveReviewTarget(),null):typeof f.getSnapshot=="function"?Pt(()=>f.getSnapshot(),null)?.activeReviewTarget??null:null:null;let so=0;const Vr=(f,m)=>{const b=(m&&typeof m=="object"?m:null)?.lastInteractionRejection;if(so>0&&f==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const I=f&&typeof f=="object"?f:null;let E=null;if(I?.entityType==="trackedChange"&&typeof I.entityId=="string"&&I.entityId.length>0){const B=I.entityId,W=I.story&&typeof I.story=="object"?I.story:void 0,ie=Zi(),fe=(ie?W?ku(ie,W).toPublicId(B):fa(ie).toPublicId(B):null)??B,Le=W&&_r(W)!==_r(null)?W:void 0;E={id:fe,...Le?{story:Le}:{},...typeof I.paintedEntityId=="string"&&I.paintedEntityId.length>0?{paintedEntityId:I.paintedEntityId}:fe!==B?{paintedEntityId:B}:{}}}return f==null&&E==null&&ue!=null&&Tt(ue)||st(ue,E)?!1:($e(E),!0)},Ts=()=>{const f=An();if(f===Xt)return;if(Mt&&(Mt(),Mt=null),Xt=f,!f){Vr(null);return}let m=!0;try{const b=f.subscribe(I=>{const E=I&&typeof I=="object"?I:null,B=E&&Object.prototype.hasOwnProperty.call(E,"activeReviewTarget")?E.activeReviewTarget:Xr(f);!Vr(B,I)||m||Kt()});typeof b=="function"&&(Mt=b),Vr(Xr(f))}catch{Xt=null}finally{m=!1}},ml=()=>{if(et||Wn()!=="viewing")return null;const f=_()?.mount?.container,m=(f&&typeof f=="object"&&"ownerDocument"in f?f.ownerDocument??null:null)??globalThis.document??null;return m&&typeof m.addEventListener=="function"?m:null},Qi=()=>{const f=ml();if(f===er||(zr&&(zr(),zr=null),er=f,!f))return;const m=()=>{_t+=1,Kt()};f.addEventListener("selectionchange",m),f.addEventListener("pointerup",m,!0),f.addEventListener("mouseup",m,!0),zr=()=>{f.removeEventListener("selectionchange",m),f.removeEventListener("pointerup",m,!0),f.removeEventListener("mouseup",m,!0)}};Ei(),Vr(Xr(An()));let pt=Ge();a=pa(pt.selection);const Mi=()=>{const f=_()?.host?.events,m=f&&typeof f.subscribe=="function"?f:null;if(m!==jn&&(pr&&(pr(),pr=null),jn=m,!!m))try{const b=m.subscribe(I=>{const E=I?.type;if(E==="review-mutation:started"){Dt(I.reviewMutation?.token);return}if(E==="review-mutation:aborted"){Gt(I.reviewMutation?.token),we();return}if(E==="mutation:rejected"&&I.reviewMutation&&(Gt(I.reviewMutation.token),we()),E==="mutation:committed"&&I.reviewMutation&&Gt(I.reviewMutation.token),E==="source:complete"||E==="source:signals-complete"){Nt!==null&&(De(),br.onRender(!0));return}if((E==="mutation:committed"||E==="collaboration:remote-changed")&&(ut=Date.now()),E==="mutation:committed"&&(De(),$t={}),E==="mutation:committed"||E==="save:completed"||E==="collaboration:remote-changed"){const B=E==="mutation:committed"?Vk(I):null,W=E==="mutation:committed"&&br.getPendingIds().size>0;if(B?.allResolved){br.reset(),un([]),Nt=null,nn(I.receipt);return}B?.removedIds.size&&Yn(new Set(B.removedIds),I.receipt);const ie=B?.reconcileMode==="authoritative"&&B.upsertIds.size>0;if(ie&&(ks(),De(),Nt=Et(),Kt()),B?.upsertIds.size||W){const je=I.origin==="history"?null:I.receipt,Ne=_()?.documentMutationReadiness,Ye=typeof je?.txId=="string"&&je.txId.length>0&&typeof Ne?.whenPainted=="function",He=I.origin==="history"&&typeof Ne?.getRenderEpoch=="function"?Pt(()=>Ne.getRenderEpoch.call(Ne),null):null,Xe=I.origin==="history"&&typeof Ne?.whenPainted=="function",Ze={upsertIds:B?.upsertIds??new Set,removedIds:new Set,reconcileMode:B?.reconcileMode==="authoritative"?"authoritative":"targeted"};Ye?br.enqueueAfterPaint(Ze,()=>Ne.whenPainted.call(Ne,je)):Xe?br.enqueueAfterPaint(Ze,()=>Ne.whenPainted.call(Ne,typeof He=="number"?{afterEpoch:He}:void 0)):(br.enqueue(Ze),br.onRender(W))}if(ie)return;const fe=E==="mutation:committed"&&Ii(I)||E==="collaboration:remote-changed"&&Array.isArray(I.changedStoryIds)&&I.changedStoryIds.length>0;if(fe&&(Vn=Date.now()),E==="mutation:committed"&&fe){Xi();return}if(B?.removedIds.size&&B.upsertIds.size===0)return;(E==="collaboration:remote-changed"||E==="mutation:committed"&&!fe)&&ya();const Le=E==="collaboration:remote-changed"&&Array.isArray(I.changedPartUris)&&I.changedPartUris.some(je=>typeof je=="string"&&SV.has(je)),Ue=E==="collaboration:remote-changed"&&Array.isArray(I.changedStoryIds)&&I.changedStoryIds.length>0&&va();Le&&!fe&&(yn=!0),ks(),Le&&!fe?ga("comments"):Ue&&(yn=!0,no()),Kt()}});typeof b=="function"&&(pr=b)}catch{jn=null}},Kt=()=>{if(J)return;on=!1,Ei(),lt(),hr(),Ts(),Qi(),Mi();const f=Ge();ct(f.selection),pt=f;for(const m of[...qe])m(pt)},Sa=[],_a=[],Aa=f=>{for(const m of f)try{m()}catch{}},gl=()=>Aa(Sa),Ji=()=>Aa(_a),gc=[];((f,m)=>{if(!(!f||typeof f.on!="function"))for(const b of m){const I=b==="active-editor-change"?()=>{gl(),Ji(),Kt()}:b==="document-replaced"?E=>{const B=E&&typeof E=="object"?E:null,W=B?.editor,ie=B?.host,fe=!!W&&W===_(),Le=!!ie&&ie===x();!fe&&!Le||(Ji(),ee.clear(),ks(),Kt())}:()=>Kt();try{f.on(b,I),gc.push(()=>{try{typeof f.off=="function"&&f.off(b,I)}catch{}})}catch{}}})(t,vV),lt(),hr(),Ts(),Qi(),Mi();const xs=(f,m=nV)=>({get:()=>f(pt),subscribe:b=>{let I=f(pt);const E=B=>{const W=f(B);m(I,W)||(I=W,b(W))};return qe.add(E),()=>qe.delete(E)}}),Ho=f=>xs(f),Po=f=>{const m=b=>{const I=B=>{try{b(B)}catch{}},E=f.subscribe(I);return I(f.get()),E};return{get:()=>f.get(),getSnapshot:()=>f.get(),observe:m,subscribe:b=>m(I=>b({snapshot:I}))}};function Yu(f){return f&&typeof f=="object"&&typeof f.id=="string"?String(f.id):null}function Rs(f){const m=$i(f);return m&&_r(m)!==_r(null)?m:void 0}function vc(f,m){return{kind:"id",id:f,...m?{story:m}:{}}}function Qf(f){if(f.empty)return null;const m=f.selectionTarget,b=m?.start,I=m?.end;if(m?.kind!=="selection"||b?.kind!=="text"||I?.kind!=="text"||typeof b.blockId!="string"||b.blockId!==I.blockId||!Number.isInteger(b.offset)||!Number.isInteger(I.offset)||b.offset<0||I.offset<0||b.offset===I.offset)return null;const E=Math.min(b.offset,I.offset),B=Math.max(b.offset,I.offset),W=$i(f);return{kind:"range",coordinateSpace:m.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...W?{story:W}:{},segments:[{blockId:b.blockId,range:{start:E,end:B}}]}}}function P(f,m){if(_r(m)!==_r(null))return;const b=y()?.trackChanges,I=b?.list;if(typeof I!="function")return;const E=Pt(()=>I.call(b),null);if(Sr(E)||!E||typeof E!="object")return;const B=E.items;if(Array.isArray(B))return B.map(il).find(W=>W!=null&&Ui(W,f,m))}function j(f,m){const b=Ce(f.quotedText);if(!b)return!1;const I=wm(m);return[I.insertedText,I.deletedText,I.excerpt].some(E=>Ce(E)===b)}function Ce(f){return typeof f=="string"?f.replace(/\s+/g," ").trim():""}function Pe(){const f=pt.selection.activeChangeIds[0];if(!f)return"unavailable";const m=$i(pt.selection),b=(pt.trackChanges.status==="ready"?pt.trackChanges.items.find(W=>Ui(W,f,m)):void 0)??P(f,m)??Zi()?.find(W=>Ui(W,f,m));if(!b)return"unavailable";const I=wm(b),E=I.type,B=I.grouping;return j(pt.selection,b)?"id":E==="replacement"&&B==="replacement-pair"||(E==="insertion"||E==="deletion"||E==="insert"||E==="delete")&&B==="standalone"?"range":"id"}function at(f,m,b,I){const E=()=>A2(f,vc(b,I),b,I);try{const B=A2(f,m,null);if(Sr(B))return Zr(Promise.resolve(B).then(ie=>ko(Cs(ie))?ie:E()));const W=Cs(B);return Zr(ko(W)?B:E())}catch{return!1}}function Ut(f,m){if(f.scope==="all")return{target:{kind:"all"},changeId:null};if(typeof m=="string"&&m.length>0)return{target:{kind:"id",id:m},changeId:m};if(m&&typeof m=="object"){const E=m;if(E.target&&typeof E.target=="object"){const W=E.target;return{target:W,changeId:Yu(W),story:W.story}}const B=typeof E.changeId=="string"?E.changeId:E.id;if(typeof B=="string"&&B.length>0)return{target:vc(B,E.story),changeId:B,story:E.story}}const b=pt.selection.activeChangeIds[0],I=Rs(pt.selection);return b?{target:vc(b,I),changeId:b,story:I}:null}function In(f,m){if(f.scope==="id"&&m==null){if(pt.selection.activeChangeIds.length>1)return rh(f.kind,{kind:"ids",ids:pt.selection.activeChangeIds},null);if(pt.selection.activeChangeIds.length===1&&!pt.selection.empty&&pt.selection.selectionTarget){const I=Pe();if(I==="unavailable")return!1;if(I==="range"){const E=Qf(pt.selection),B=Rs(pt.selection);return E?at(f.kind,E,pt.selection.activeChangeIds[0],B):!1}if(I==="id"){const E=pt.selection.activeChangeIds[0],B=$i(pt.selection),W=B&&_r(B)!==_r(null)?B:void 0;return _2(f.kind,W?{id:E,story:W}:E)}}}const b=Ut(f,m);return b?rh(f.kind,b.target,b.changeId,b.story):!1}function Fn(f,m){const b=T()?.lists,I=b?.apply;if(typeof I!="function")return!1;const{behavior:E,preset:B,continuity:W}=typeof m=="string"?wV(m):m&&typeof m=="object"?m:{},ie={kind:f,behavior:E??"toggle"};B!==void 0&&(ie.preset=B),W!==void 0&&(ie.continuity=W);try{return Zr(I.call(b,ie))}catch{return!1}}let hn=Promise.resolve(!1),fn=null,bn=Promise.resolve(!1);const sr=async f=>{if(!Cm(f))return f;const m=_()?.documentMutationReadiness,b=m?.whenPainted;if(typeof b!="function")return f;const I=typeof f.txId=="string"?f.txId:void 0;try{await b.call(m,I?{txId:I}:void 0)}catch{}return f},Ln=f=>{if(Sr(f)){const b=Promise.resolve(f);return{immediate:!0,committed:b.then(I=>Cs(I),()=>!1),settled:b.then(I=>sr(Cs(I)),()=>!1)}}const m=Cs(f);return{immediate:m,committed:Promise.resolve(m),settled:sr(m)}},ri=()=>{const f=s.shift();if(!f){c=!1,d?.(),d=null;return}try{f.resolve(J?!1:f.mutate())}catch{f.resolve(!1)}},Ia=()=>{let f=!1;return()=>{f||(f=!0,ri())}},oi=(f,m)=>{if(!c){c=!0,u=new Promise(B=>{d=B});try{return{result:m(),release:Ia()}}catch(B){throw c=!1,d?.(),d=null,B}}const b=s.find(B=>B.key===f);if(b)return b.mutate=m,{result:b.result,release:()=>{}};let I;const E=new Promise(B=>{I=B});return s.push({key:f,mutate:m,result:E,resolve:I}),{result:E,release:Ia()}},yl=new Set(["create.tableOfContents"]),bl=f=>Xn(`Tracked authoring is not supported for ${f}.`),Jf=f=>{if(Wn()==="suggesting")return yl.has(f)?bl(f):{changeMode:"tracked"}},Im=()=>Wn()==="suggesting"?ej:m2,jr=(f,m,b)=>{const I=Jf(f);return I&&I.success===!1?I:I?m(b,I):m(b)},y2=(f,m,b,I)=>{const E=f.inline;if(!E)return;const B=Cs(I);if(B===!1||typeof B=="object"&&B&&B.success===!1)return;if(E.kind==="clear"){n.clear();return}if(E.kind==="toggle"||!u2(E.key))return;const W=pa(m);if(!W)return;const ie=jV(E.key,b.value);if(ie==null){n.delete(E.key);return}n.set(E.key,{selectionSignature:W,value:ie})},b2=(f,m,b,I)=>!f.inline||f.inline.kind==="toggle"?I:Sr(I)?Promise.resolve(I).then(E=>(y2(f,m,b,E),E)):I,eh=(f,m,b,I)=>{if(f.inline?.kind!=="toggle"||!ko(Cs(I))||typeof b.value!="boolean"&&b.value!==null)return null;const E=pa(m);if(!E)return null;const B=++l;return r.set(f.id,{selectionSignature:E,active:b.value===!0,generation:B,settled:!1}),Kt(),B},tr=(f,m,b)=>{if(m==null)return;const I=r.get(f.id);if(!(!I||I.generation!==m)){if(!ko(b)){r.delete(f.id);return}I.settled=!0}},Xu=(f,m)=>f.then(b=>(m?.(b),Ss(),b),()=>(m?.(!1),Ss(),!1)),Zr=(f,m)=>{const b=fn;if(fn=null,b)return hn=Xu(b,m),Cs(f);if(Sr(f))return hn=Xu(Ln(f).settled,m),!0;const I=Cs(f);return Cm(I)&&typeof _()?.documentMutationReadiness?.whenPainted=="function"?(hn=Xu(sr(I),m),I):(m?.(I),hn=Promise.resolve(I),Ss(),I)},Em=(f,m)=>!f||typeof f!="object"?m:f,Ms=(f,m=Xn("Document API operation failed."))=>{if(Sr(f))return Promise.resolve(f).then(I=>Ms(I,m),()=>m);const b=Em(f,m);return ks(),Cm(b)&&typeof _()?.documentMutationReadiness?.whenPainted=="function"?(Xu(sr(b)),Kt(),b):(Kt(),b)},Tm=(f,m,b,I)=>{const E=[],B=[];for(const W of b){const ie=I(W);if(ie)try{const fe=Ln(jr(f,m,ie));E.push(fe.immediate),B.push(fe.settled)}catch{E.push(!1),B.push(Promise.resolve(!1))}}return fn=B.length?Promise.all(B).then(W=>hi(W)):null,hi(E)},xm=(f,m,b,I)=>{const E=[],B=[];for(const W of b){const ie=I(W);if(ie)try{const fe=Ln(jr(f,m,ie));E.push(fe.immediate),B.push(fe.settled)}catch{E.push(!1),B.push(Promise.resolve(!1))}}return fn=B.length?Promise.all(B).then(W=>hi(W)):null,hi(E)},Zu=(f,m,b,I=pt.selection)=>{const E=Jf(f);return E&&E.success===!1?E:I.selectionTarget?m(b,{...E??{},offsetSpace:"selection"}):E?m(b,E):m(b)},w2=(f,m,b,I)=>{const E=Co(m,I);switch(f.kind){case"alignment":{const B=b;return B!=="left"&&B!=="center"&&B!=="right"&&B!=="justify"?null:{target:E,alignment:B}}case"spacing-line":{const B=typeof b=="number"?b:Number(b);return!Number.isFinite(B)||B<=0?null:{target:E,line:B,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const B=b.role;if(B&&typeof B=="object")return{target:E,role:B}}return typeof b!="string"||b.trim()===""?null:{target:E,styleId:b};case"direction":{const B=f.fixedValue;return B!=="ltr"&&B!=="rtl"?null:{target:E,direction:B}}default:return null}},Rm=(f,m)=>{const b=f.inline,I=p2(f),E=x();if(!b||typeof E?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return X(),!0;if(!I)return!1;let B;if(b.kind==="toggle")B=!Es(f,y(),pt.selection);else{const W=m&&typeof m=="object"&&"value"in m?m.value:m;if(b.kind==="value-number"){const ie=typeof W=="number"?W:Number(W);B=Number.isFinite(ie)&&ie>0?ie:null}else B=typeof W=="string"&&W.trim()!==""?W:null;if(B===null)return F(I,null),!0}return F(I,B),!0},yc=()=>{const f=y(),{lockModesById:m}=pi(f?.contentControls,pt.selection);if(Is(m))return!1;const b=[],I=[],E=Ye=>{const He=Ln(Ye);b.push(He.immediate),I.push(He.settled)},B=(Ye,He,Xe)=>{try{E(Xe?Ye(He,Xe):Ye(He))}catch{b.push(!1),I.push(Promise.resolve(!1))}},W=Se().cache?.full.defaults.paragraphStyleId??pe,ie=Au(pt.selection);if(ie){const Ye=vr(f,"format.apply");if(Ye)try{E(Zu("format.apply",Ye,{target:ie,inline:{...Im()}}))}catch{b.push(!1),I.push(Promise.resolve(!1))}}const fe=vr(f,"format.paragraph.resetDirectFormatting"),Le=vr(f,"styles.paragraph.setStyleRef"),Ue=$i(pt.selection),je=!Ue||Ue.storyType==="body",Ne=vr(f,je?"lists.remove":"lists.removeInStory");for(const Ye of Nr(pt.selection)){const He=Co(Ye,Ue);if(fe&&B(fe,{target:He}),Ne)try{const Xe=ha(Ye),Ze=Ln(Ne(je?{target:Xe}:{target:Xe,story:Ue}));I.push(Ze.settled.then(ot=>ko(ot)?ot:!0))}catch{}Le&&B(Le,{target:He,styleId:W})}if(!ie&&Wn()!=="suggesting"){const Ye=vr(f,"format.paragraph.setMarkRunProps");if(Ye)for(const He of Nr(pt.selection))B(Ye,{target:Co(He,Ue),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return fn=I.length?Promise.all(I).then(Ye=>hi(Ye)):null,hi(b.length?b:[!1])},Qu=(f,m,b)=>{const I=Nr(pt.selection);if(I.length===0)return!1;const E=$i(pt.selection);return Tm(f.docRoute,m,I,B=>w2(f.blockParagraph,B,b,E))},th=(f,m,b)=>{const I=y(),E=vr(I,"format.paragraph.setIndentation"),B=vr(I,"format.paragraph.clearIndentation"),W=f.list?.mode,ie=Hi(pt.selection),fe=$i(pt.selection),Le=async Ue=>{const je=await ni(I,Ue,ie);if(je===!0)return{kind:"list",routeToCall:f.docRoute,opToCall:m,input:{target:bA(Ue)}};if(je===null||fe&&fe.storyType!=="body"&&typeof I?.getNode!="function")return null;const Ne=await qf(I,Ue,fe),Ye={};if(Ne?.right!=null&&(Ye.right=Ne.right),Ne?.firstLine!=null&&(Ye.firstLine=Ne.firstLine),Ne?.hanging!=null&&(Ye.hanging=Ne.hanging),W==="indent")return E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),left:Math.max(0,Ne?.left??0)+wA,...Ye}}:null;const He=Math.max(0,(Ne?.left??0)-wA);return He>0&&(Ye.left=He),Object.keys(Ye).length===0?B?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:B,input:{target:Co(Ue,fe)}}:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),left:0}}:null:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:Co(Ue,fe),...Ye}}:null};return fn=(async()=>{const Ue=await Promise.all(b.map(He=>Le(He).catch(()=>null)));if(Ue.length===b.length&&Ue.every(He=>He?.kind==="list")&&Wn()!=="suggesting"){const He=W==="indent"?"lists.indentRange":"lists.outdentRange",Xe=vr(I,He);if(Xe)try{return await Ln(jr(He,Xe,{paraIds:b,story:ie})).settled}catch{return!1}}const je=ie.storyType!=="body"&&Ue.some(He=>He?.kind==="list"),Ne=je&&W==="outdent"?vr(I,"lists.outdentInStory"):null;if(je&&!Ne)return!1;const Ye=Ue.map(He=>{if(!He)return Promise.resolve(!1);try{return He.kind==="list"&&Ne?Ln(jr("lists.outdentInStory",Ne,{target:He.input.target,story:ie})).settled:Ln(jr(He.routeToCall,He.opToCall,He.input)).settled}catch{return Promise.resolve(!1)}});return hi(await Promise.all(Ye))})(),!0},xt=(f,m)=>{const b=f.list,I=y(),E=Nr(pt.selection);if(E.length===0)return!1;const B=Hi(pt.selection),W=B.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return th(f,m,E);const ie=b.seed,fe=je=>{if(je.some(ot=>!ot.resolved))return{immediate:!1,settled:null};const Ne=je.every(ot=>ot.seed===ie);if(!Ne&&!W)return{immediate:!1,settled:null};const Ye=Ne?W?"lists.remove":"lists.removeInStory":f.docRoute,He=Ne?vr(I,Ye):m;if(!He)return{immediate:!1,settled:null};const Xe=[],Ze=[];return E.forEach((ot,tt)=>{if(!Ne&&je[tt]?.seed===ie)return;const Bt=Ne?{target:ha(ot),...W?{}:{story:B}}:{target:ha(ot),seed:ie};try{const Qt=Ln(jr(Ye,He,Bt));Xe.push(Qt.immediate),Ze.push(Qt.settled)}catch{Xe.push(!1),Ze.push(Promise.resolve(!1))}}),{immediate:hi(Xe),settled:Ze.length?Promise.all(Ze).then(ot=>hi(ot)):null}},Le=E.map(je=>Yr(I,je,B));if(Le.some(Sr))return fn=Promise.all(Le).then(async je=>{const Ne=fe(je);return Ne.settled?await Ne.settled:Ne.immediate}),!0;const Ue=fe(Le);return fn=Ue.settled,Ue.immediate};function Ht(f){return f&&typeof f=="object"?f:{}}function wn(f){if(typeof f=="string")return f;const m=Ht(f);if(Object.prototype.hasOwnProperty.call(m,"href"))return m.href;if(Object.prototype.hasOwnProperty.call(m,"value"))return m.value}function Ir(f,m){const b=Ht(f).text;return typeof b=="string"&&b.trim()!==""?b:m}function Ur(f){const m=Ht(f),b=m.capture&&typeof m.capture=="object"?m.capture:null;return m.target??b?.target??b?.selectionTarget??m.selectionTarget??m.textTarget??null}const vo=f=>{const m=y(),b=m?.hyperlinks;if(!b)return!1;const I=Ht(f),E=wn(f),B=Ur(f),W=typeof I.text=="string"?I.text:void 0,ie=typeof I.currentText=="string"?I.currentText:void 0,fe=Xl(I.hyperlinkTarget)?I.hyperlinkTarget:null,Le=Xl(I.textTarget)?I.textTarget:null,Ue=dc(m,pt.selection),je=typeof fe?.storyId=="string"&&typeof fe?.hyperlinkNodeId=="string";if(je&&E===null){const Ne=b.remove;if(typeof Ne!="function")return!1;try{return jr("hyperlinks.remove",Ne,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(Ue&&E===null){const Ne=b.remove;if(typeof Ne!="function")return!1;try{return jr("hyperlinks.remove",Ne,{target:Ue.address,mode:"unwrap"})}catch{return!1}}if((Ue||fe)&&typeof E=="string"&&E.trim()!==""){const Ne=b.patch,Ye=b.updateTarget;if(!(!je&&Ue&&typeof Ne=="function")&&!(je&&typeof Ye=="function"))return!1;const He=typeof W=="string"&&W!==(je?ie:Ue?.text??ie),Xe=m?.text?.replace,Ze=He?je?Le:qV(Ue?.address):null,ot=He&&!!Ze&&typeof Xe=="function";if(He&&!ot)return!1;const tt=[],Bt=[];let Qt=null,an=null,Pn=null,Hr=!1;try{if(je){if(typeof Ye!="function")return!1;const Er=jr("hyperlinks.updateTarget",Ye,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,newTarget:YV(E)});Hr=Sr(Er);const Tr=Ln(Er);if(!ko(Tr.immediate))return!1;tt.push(Tr.immediate),Bt.push(Tr.settled),Qt=Tr.immediate,an=Tr.committed,Pn=Tr.settled}else if(Ue){if(typeof Ne!="function")return!1;const Er=jr("hyperlinks.patch",Ne,{target:Ue.address,patch:{href:E}});Hr=Sr(Er);const Tr=Ln(Er);if(!ko(Tr.immediate))return!1;tt.push(Tr.immediate),Bt.push(Tr.settled),Qt=Tr.immediate,an=Tr.committed,Pn=Tr.settled}}catch{return!1}if(ot){const Er=(Lr,$o)=>ko($o)?hi([Lr,$o]):ko(Lr)?Nf(Lr,$o):$o,Tr=Lr=>{if(!ko(Lr))return Lr;try{const $o=Ln(jr("text.replace",Xe,{target:Ze,text:W}));return ko($o.immediate)?Promise.all([Pn??Promise.resolve(Lr),$o.settled]).then(([R2,mU])=>Er(R2,mU)):Nf(Lr,$o.immediate)}catch{return Nf(Lr,!1)}};if(Hr)return fn=(an??Promise.resolve(Qt??!1)).then(Tr),hi(tt);try{const Lr=Ln(jr("text.replace",Xe,{target:Ze,text:W}));if(!ko(Lr.immediate))return Qt?Nf(Qt,Lr.immediate):Lr.immediate;tt.push(Lr.immediate),Bt.push(Lr.settled),fn=Promise.all([Pn??Promise.resolve(Qt??!1),Lr.settled]).then(([$o,R2])=>Er($o,R2))}catch{return Qt?Nf(Qt,!1):!1}}return!ot&&Bt.length>0&&(fn=Promise.all(Bt).then(Er=>hi(Er))),hi(tt)}if(typeof E=="string"&&E.trim()!==""){const Ne=E.trim(),Ye=b.wrap,He=BV(B),Xe=He.length>0?He:c2(pt.selection);if(Xe.length>0){if(typeof Ye!="function")return!1;try{return xm("hyperlinks.wrap",Ye,Xe,Bt=>({target:Bt,link:{destination:{href:Ne}}}))}catch{return!1}}const Ze=b.insert,ot=Ir(f,Ne);if(typeof Ze!="function"||ot.trim()==="")return!1;const tt=zf(B)??ol(pt.selection);if(!tt)return!1;try{return jr("hyperlinks.insert",Ze,{target:tt,text:ot,link:{destination:{href:Ne}}})}catch{return!1}}return!1},gi=(f,m,b)=>{const I=f.create.kind,E=b&&typeof b=="object"?b:{};if(I==="table"){const W=Number(E.rows??E.rowCount),ie=Number(E.columns??E.cols??E.colCount);if(!Number.isInteger(W)||W<1||!Number.isInteger(ie)||ie<1)return!1;const fe=ol(pt.selection),Le=fe&&typeof fe.blockId=="string"?{kind:"inParagraph",target:Co(fe.blockId),offset:fe.range?.start??0}:f2(pt.selection,"nodeId");try{return jr(f.docRoute,m,{rows:W,columns:ie,at:Le})}catch{return!1}}if(I==="image"){const W=E.src??E.value;if(typeof W!="string"||W.trim()==="")return!1;const ie=ol(pt.selection),fe=Hi(pt.selection),Le=fe.storyType==="body"?null:fe;let Ue;ie&&typeof ie.blockId=="string"?Ue={kind:"inParagraph",target:Co(ie.blockId,Le),offset:ie.range?.start??0}:(Ue=f2(pt.selection,"target"),Le&&Ue.kind==="after"&&(Ue={...Ue,target:{...Ue.target,story:Le}}));const je={src:W,at:Ue};Le&&(je.in=Ue.kind==="inParagraph"?L(Le)??Le:Le),typeof E.alt=="string"&&(je.alt=E.alt),typeof E.title=="string"&&(je.title=E.title),E.size&&typeof E.size=="object"&&(je.size=E.size);try{return jr(f.docRoute,m,je)}catch{return!1}}const B={at:f2(pt.selection,"target")};typeof E.instruction=="string"&&(B.instruction=E.instruction),E.config&&typeof E.config=="object"&&(B.config=E.config);try{return jr(f.docRoute,m,B)}catch{return!1}},Ls=(f,m)=>{const b=f.table,I=Be();if(!I||b.requiresCell&&!I.cellNodeId)return!1;const E=rj(b.action,I);if(!E)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const B=x(),W=(typeof B?.getHandles=="function"?B.getHandles():null)?.editing?.tables;if(typeof W?.insertRow!="function")return!1;const ie=Jf(f.docRoute);return ie&&ie.success===!1?ie:ie?W.insertRow(E,ie):W.insertRow(E)}return jr(f.docRoute,m,E)}catch{return!1}},Ju=f=>!f||f.disposition!=="routed"?!1:!!(f.inline||f.blockParagraph||f.list||f.link||f.create),Fj=f=>{const m=Ht(f);return!!(Ur(f)||Xl(m.hyperlinkTarget)||Xl(m.textTarget))},Nj=(f,m,b)=>pt.selection.status!=="ready"?!1:Sm(f)?.scope==="id"||!m||m.disposition!=="routed"?!0:m.inline?.kind==="clear"?Nr(pt.selection).length>0||Au(pt.selection)!=null:m.inline?Au(pt.selection)!=null||Nr(pt.selection).length>0:m.blockParagraph||m.list?Nr(pt.selection).length>0:m.link?Fj(b)||c2(pt.selection).length>0||ol(pt.selection)!=null||Es(m,y(),pt.selection):!0,Bj=(f,m)=>{const b=Sm(f),I=gu(f);return b?.scope!=="id"&&!Ju(I)?!1:!Nj(f,I,m)},zj=(f,m)=>Bj(f,m)?_s().then(()=>{}):null,bc=(f,m,b)=>{if(fn=null,hn=Promise.resolve(!1),J)return!1;const I=he.get(f);if(I)try{const je=I.execute(tc(m,b));return Zr(je)}catch{return!1}const E=hA(f);if(E&&typeof T()?.lists?.apply=="function")return Fn(E,m);const B=Sm(f);if(B)return In(B,m);if(f==="copy-format")return Zr(Vj());const W=gu(f);if(!W||W.disposition!=="routed")return!1;const ie=W.normalizePayload?W.normalizePayload(m):m;if(W.instanceRoute){if(!_()||!oe(W,ie))return!1;const je=t?.[W.instanceRoute];if(typeof je!="function")return!1;try{const Ne=W.fixedArg!==void 0?W.fixedArg:ie,Ye=je.call(t,Ne);return Zr(Ye)}catch{return!1}}if(W.inline?.kind==="clear")return W.mutates&&Wn()==="viewing"?!1:Zr(yc());const fe=W.docRoute;if(!fe||W.mutates&&Wn()==="viewing")return!1;const Le=y(),Ue=vr(Le,fe);if(!Ue)return!1;if(W.inline){const{lockModesById:je}=pi(Le?.contentControls,pt.selection);if(Is(je))return!1;const Ne=Au(pt.selection);if(!Ne)return pt.selection.empty===!1?Zr(!1):Zr(Rm(W,ie));const Ye=Es(W,Le,pt.selection),He=tj(W.inline,Ne,ie,Ye);if(!He)return!1;let Xe=null;try{const Ze=_(),ot=Wn(),tt=()=>_()!==Ze||y()!==Le||Wn()!==ot?!1:Zu(fe,Ue,He),Bt=pa(pt.selection)??Kl(pt.selection),Qt=W.inline.kind==="toggle"?oi(`${W.id}:${Bt}`,tt):null;Xe=Qt?.release??null;const an=Qt?Qt.result:tt(),Pn=eh(W,pt.selection,He,an),Hr=b2(W,pt.selection,He,an),Er=Zr(Hr,Tr=>{tr(W,Pn,Tr),Xe?.(),Xe=null});return W.inline.kind==="toggle"&&(bn=hn),Er}catch{return Xe?.(),!1}}if(W.blockParagraph){const je=Qu(W,Ue,ie),Ne=W.blockParagraph.kind==="alignment"&&ko(je)?pc(pt.selection,ie):null;return Zr(je,Ye=>{qu(Ne,Ye)})}if(W.list){const je=xt(W,Ue);return Zr(je)}if(W.link){const je=vo(ie);return Zr(je)}if(W.create){const je=gi(W,Ue,ie);return Zr(je)}if(W.table){const je=Ls(W,Ue);return Zr(je)}try{return Zr(W.mutates?jr(fe,Ue,ie):Ue(ie))}catch{return!1}},Mm=()=>{g+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const f of p)f("idle");Kt()},Vj=async()=>{const f=["bold","italic","underline","strikethrough"].filter(Ue=>pt.toolbar.commands[Ue]?.active===!0),m=await bn;await u;const b=ko(m)?f:[],I=500,E=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&E-h.lastClickAt<I){h={...h,mode:"persistent",lastClickAt:E};for(const Ue of p)Ue("persistent");return Kt(),!0}return Mm(),!1}const B=E-h.lastClickAt<I,W=++g;h={...h,lastClickAt:E};const ie=await _s(),fe=`${Kl(ie)}:${Et()}`,Le=await jj(null,ie,fe&&fe===k?v:void 0,b);if(W!==g)return!0;h={...h,mode:B?"persistent":"armed",snapshot:Le,sourceSelectionKey:Kl(ie),lastClickAt:E};for(const Ue of p)Ue(h.mode);return Kt(),!0},jj=async(f,m,b,I=[])=>{const E=m?.target??f?.target;if(!E||E.kind!=="text")return null;const B=Array.isArray(E.segments)?E.segments:[];if(B.length===0)return null;const W=y();if(!W)return null;const ie=E.story;let fe=null;for(const He of B){const Xe=(await As(Co(He.blockId,ie)))?.node??null;if(!Xe)continue;const Ze=C2(Xe),ot=Array.isArray(Ze?.inlines)?Ze.inlines:[],tt=Uj(ot,He.range);fe?fe=MA(fe,tt):fe=tt}const Le=fe?rV(fe):{},Ue={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},je=new Set([...m?.activeMarks??(Array.isArray(f?.activeMarks)?f.activeMarks:[]),...I]);for(const[He,Xe]of Object.entries(Ue))je.has(He)&&(Le[Xe]=!0);const Ne=b??await Fu(m??al(f,"ready"));if(Ne.fontFamily&&(Le.fontFamily=Ne.fontFamily),Ne.color&&(Le.color=Ne.color),Ne.highlight&&(Le.highlight=Ne.highlight),Ne.fontSize){const He=Number.parseFloat(Ne.fontSize);Number.isNaN(He)||(Le.fontSize=He)}let Ye=null;if(B.length===1){const He=B[0],Xe=(await As(Co(He.blockId,ie)))?.node??null;Xe&&C2(Xe)&&(Ye=await Hj(Xe,He.blockId,W,ie))}return{story:ie??null,inline:Le,paragraph:Ye}},C2=f=>f?f.kind==="paragraph"?f.paragraph??null:f.kind==="heading"?f.heading??null:null:null,Uj=(f,m)=>{const b=W=>{const ie=W.run;return typeof ie?.text=="string"?ie.text:""},I=W=>W.run?.props;if(m.start===m.end){let W=0;for(const ie of f){const fe=b(ie),Le=W,Ue=W+fe.length;if(W=Ue,m.start>=Le&&m.start<=Ue){const je=I(ie);return je?{...je}:{}}}return{}}let E=0;const B=[];for(const W of f){const ie=b(W),fe=E,Le=E+ie.length;if(E=Le,Le<=m.start||fe>=m.end)continue;const Ue=I(W);Ue&&B.push(Ue)}return B.length===0?{}:B.length===1?{...B[0]}:MA(B[0],...B.slice(1))},MA=(f,...m)=>{const b={...f};for(const I of m)for(const E of Object.keys(b)){if(!(E in I)){delete b[E];continue}const B=b[E],W=I[E];(typeof B!=typeof W||JSON.stringify(B)!==JSON.stringify(W))&&delete b[E]}return b},Hj=async(f,m,b,I)=>{const E=C2(f),B=E.props??{},W=E.styleRef??null,ie=B.alignment??null,fe=B.spacing??null,Le=B.indent??null,Ue=Le?{...Le.left!=null?{left:Le.left}:{},...Le.right!=null?{right:Le.right}:{},...Le.firstLine!=null?{firstLine:Le.firstLine}:{},...Le.hanging!=null?{hanging:Le.hanging}:{}}:null,je=B.markRunProps??null,Ne=B.numbering?.numId,Ye=typeof Ne=="string"?parseInt(Ne,10):typeof Ne=="number"?Ne:NaN,He=B.numbering?.level,Xe=isNaN(Ye)?null:{numId:Ye,...He!=null?{level:He}:{}};let Ze=null;if(Xe&&typeof b.lists?.getState=="function")try{const ot=await b.lists.getState({target:Co(m,I)});ot&&typeof b.lists?.getStyle=="function"&&(Ze=await b.lists.getStyle(ot)??null)}catch{}return{styleId:W,alignment:ie,spacing:fe,indentation:Ue,markRunProps:je,numbering:Xe,listStyle:Ze}},LA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const f=y()?.selection,m=async()=>{const W=typeof f?.current=="function"?await Promise.resolve(f.current({includeText:!0})):So().value;return Ti(W)},b=()=>new Promise(W=>setTimeout(W,16)),I=8;let E=null,B="";for(let W=0;W<I;W+=1){if(W>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(E=await m(),!(!E||E.empty)&&(B=Kl(E),B!==h.sourceSelectionKey))break}if(E&&!E.empty&&B!==h.sourceSelectionKey){await PA(E);return}if(h.snapshot?.paragraph){const W=await m();if(!W||Kl(W)===h.sourceSelectionKey)return;await PA(W)}},PA=async f=>{const m=h.snapshot;if(!m){h.mode==="armed"&&Mm();return}const b=y();if(!b)return;const I=al(f,"ready"),{lockModesById:E}=pi(b.contentControls,I);if(Is(E)){Kt();return}const B=f.target,W=f.selectionTarget;if(f.empty!==!0&&Object.keys(m.inline).length>0){const ie=vr(b,"format.apply");if(ie&&W)try{if(!ko(Cs(await Promise.resolve(Zu("format.apply",ie,{target:W,inline:m.inline},f))))){Kt();return}}catch{Kt();return}}if(m.paragraph){const ie=Array.isArray(B?.segments)?B.segments:[],fe=B?.story;for(const Le of ie){const Ue=Co(Le.blockId,fe),je=await As(Ue),Ne=je?.node??null,Ye=je?.address??null;if(!Ne)continue;const He={kind:"block",nodeType:Ye?.nodeType??Ne.kind??"paragraph",nodeId:Le.blockId,...fe&&typeof fe=="object"?{story:fe}:{}},{styleId:Xe,alignment:Ze,spacing:ot,indentation:tt,markRunProps:Bt,numbering:Qt,listStyle:an}=m.paragraph;if(Xe&&await b.styles?.paragraph?.setStyle?.({target:He,styleId:Xe}),Ze&&await b.format?.paragraph?.setAlignment?.({target:He,alignment:Ze}),ot){const Pn=ot,Hr=Pn.lineRule??"auto",Er=new Set(["auto","exact","atLeast"]).has(Hr)?Hr:"auto",Tr={...Pn.before!=null?{before:Math.round(Pn.before*20)}:{},...Pn.after!=null?{after:Math.round(Pn.after*20)}:{},...Pn.line!=null?{line:Math.round(Er==="auto"?Pn.line*240:Pn.line*20),lineRule:Er}:{}};await b.format?.paragraph?.setSpacing?.({target:He,...Tr})}if(tt){const Pn={...tt.left!=null?{left:ws(tt.left)}:{},...tt.right!=null?{right:ws(tt.right)}:{},...tt.firstLine!=null?{firstLine:ws(tt.firstLine)}:{},...tt.hanging!=null?{hanging:ws(tt.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:He,...Pn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:He,markRunProps:Bt}),Qt&&await b.format?.paragraph?.setNumbering?.({target:He,...Qt}),an&&((await As(Ue))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:bA(Le.blockId,fe),style:an}):Qt&&await b.format?.paragraph?.setNumbering?.({target:He,...Qt}))}}h.mode==="armed"&&Mm(),Kt()},Lm=(f,m,b)=>{const I=zj(f,m),E=I?I.then(()=>(bc(f,m,b),hn)):(bc(f,m,b),hn);return gu(f)?.inline?.kind==="toggle"&&(bn=E),E},DA=f=>({id:f,getState:()=>pt.toolbar.commands[f]??uc(f,y(),pt.selection,fl(pt.selection)),observe:m=>xs(b=>b.toolbar.commands[f]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:dt.commandUnsupported}).subscribe(m),execute:m=>bc(f,m),executeAsync:m=>Lm(f,m)}),$j=f=>{he.set(f.id,f),Kt();const m=()=>{he.delete(f.id),Kt()};return Object.assign(m,{handle:DA(f.id),unregister:m})},Pm=Ho(f=>f.selection),Dm=Po(Pm),OA=()=>{const f=x();if(typeof f?.getHandles!="function")return{reason:dt.hostCapabilityUnavailable};let m=null;try{m=f.getHandles()}catch(I){const E=I?.reason;return{reason:E==="host-not-ready"||E==="host-disposed"||E==="editing-mount-required"?dt.notReady:dt.hostCapabilityUnavailable}}const b=m?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:dt.hostCapabilityUnavailable}:{helper:b}},Gj=f=>{const m=x();if(typeof m?.getHandles=="function")try{const b=m.getHandles()?.editing?.contentControls;typeof b?.activate=="function"&&b.activate({id:f})}catch{}},FA={get:Dm.get,getSnapshot:Dm.getSnapshot,subscribe:Dm.subscribe,observe:Dm.observe,current:()=>So().value,capture:()=>{const f=Pm.get();return f.empty||!f.target&&!f.selectionTarget?null:{...f,capturedAt:Date.now()}},restore:f=>{const m=E=>(Kt(),{...E,success:E.ok});if(!f||typeof f!="object")return m({ok:!1,reason:dt.targetUnresolved});if(!_())return m({ok:!1,reason:dt.notReady});const b=JV(f);if(!b)return m({ok:!1,reason:dt.targetUnresolved});const I=OA();if(!("helper"in I))return m({ok:!1,reason:I.reason});try{return m(fA(I.helper.apply(b)))}catch{return m({ok:!1,reason:dt.hostCapabilityUnavailable})}},apply:f=>{if(!_())return{ok:!1,reason:dt.notReady};const m=OA();if(!("helper"in m))return{ok:!1,reason:m.reason};try{const b=m.helper.apply(f);return Kt(),fA(b)}catch{return{ok:!1,reason:dt.hostCapabilityUnavailable}}},getAnchorRect:f=>{const m=x();if(typeof m?.getSelectionAnchorRect=="function"){const b=Pt(()=>m.getSelectionAnchorRect(f),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:f=>{const m=Pm.get(),b=m.selectionTarget??m.target;if(m.empty||!b)return[];const I=Hm.getRect({target:b,relativeTo:f?.relativeTo});return I.found?I.rects:[]}},Wj={get ids(){return ae()},has:f=>gu(f)!=null||he.has(f),get:f=>DA(f),execute:bc,executeAsync:Lm,register:$j,getContextMenuItems:f=>{const m=[];for(const b of he.values()){const I=b.contextMenu;I&&Pt(I.when?()=>I.when(f):void 0,!0)&&m.push({id:b.id,label:I.label,group:I.group,order:I.order,invoke:()=>bc(b.id,void 0,f)})}return m.sort((b,I)=>(b.order??0)-(I.order??0)||b.label.localeCompare(I.label))}},k2=Po(Ho(f=>f.toolbar)),Kj={get:k2.get,getSnapshot:()=>pt.toolbar,subscribe:k2.subscribe,observe:k2.observe,execute:bc,executeAsync:Lm},wc=async(f,m)=>{if(!_())return{success:!1,ok:!1,reason:dt.notReady};if(!f)return{success:!1,ok:!1,reason:dt.targetUnresolved};const b=x(),I=b?.scrollTargetIntoView;if(typeof I!="function")return{success:!1,ok:!1,reason:dt.hostCapabilityUnavailable};try{const E={target:f,block:m?.block??"center",behavior:m?.behavior??"smooth"},B=await Promise.resolve(m?.shouldContinue?I.call(b,E,m.shouldContinue):I.call(b,E));return B&&typeof B=="object"&&B.success===!1?{success:!1,ok:!1,reason:s2(B.reason,dt.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:dt.hostCapabilityUnavailable}}},Om=async(f,m,b,I)=>{const E=f==="trackChanges"?I?.story:void 0,B=ot=>{if(!E||!ot||typeof ot!="object")return ot;const tt=ot,Bt=tt.address&&typeof tt.address=="object"?tt.address:null;return tt.story||Bt?.story?ot:{...tt,story:E}},W=f==="trackChanges"?AV:Bf,ie=b.find(ot=>Ui(ot,m,E)),fe=ie&&typeof ie=="object"?ie:null,Le=f==="trackChanges"&&fe?.type==="move"&&(fe.subtype==="move-to"||fe.subtype==="move-from")?fe.subtype:null,Ue=Le&&typeof fe?.trackedChangeCanonicalId=="string"?fe.trackedChangeCanonicalId:m,je=ot=>{if(!Le)return W(ot);const tt=Bf(ot);if(tt?.kind!=="move")return null;const Bt=Le==="move-to"?tt.destination:tt.source;return a2(Bt)?Bt:null},Ne=W(ie),Ye=f!=="trackChanges"||!Le&&a2(Bf(ie));if(Ne&&Ye)return B(Ne);const He=y()?.[f],Xe=f==="comments"?{commentId:m}:{id:Ue,...E?{story:E}:{}},Ze=He?.get;if(typeof Ze!="function")return B(Ne);try{return B(je(await Promise.resolve(Ze.call(He,Xe)))??Ne)}catch{return B(Ne)}};function NA(f,m){if(Vo())return Xn("Comments are read-only.","DOCUMENT_READONLY");if(Hf())return Xn("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,I=b?.patch;if(typeof I!="function")return Xn("comments.patch is unavailable.");const E=Xn("comments.patch failed.");return Pt(()=>Ms(I.call(b,{commentId:f,status:m}),E),E)}const nh=()=>Vo()?Xn("Comments are read-only.","DOCUMENT_READONLY"):null,BA=(f,m)=>{const b=m&&typeof m=="object"?m:null;let I=Array.from(f);b?.includeResolved===!1&&(I=I.filter(fe=>fe.status!=="resolved"));const E=Number(b?.offset),B=Number.isInteger(E)&&E>0?E:0,W=Number(b?.limit),ie=Number.isInteger(W)&&W>=0?B+W:void 0;return I.slice(B,ie)},ed=Ho(f=>f.comments),Fm=Po(ed),qj={get:Fm.get,getSnapshot:Fm.getSnapshot,subscribe:Fm.subscribe,observe:Fm.observe,list:f=>{const m=ed.get();if(m.status!=="pending")return BA(m.items,f);const b=y()?.comments,I=Pt(b?.list?()=>b.list(f):void 0,null);return Sr(I)?[]:BA(Array.isArray(I?.items)?I.items:[],f)},getById:f=>{const m=ed.get().items.find(E=>Gn(E)===f)??null;if(m)return m;const b=y()?.comments,I=Pt(b?.get?()=>b.get({commentId:f}):void 0,null);return Sr(I)?null:I},createFromCapture:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.create;if(typeof E!="function")return Xn("comments.create is unavailable.");const B=Xn("comments.create failed.");return Pt(()=>{const W=f&&typeof f=="object"?f.target??f.selectionTarget:null;return W==null?Xn("A range selection is required to comment.","NO_SELECTION"):Ms(E.call(I,{target:W,text:m.text}),B)},B)},createFromSelection:f=>{const m=nh();if(m)return m;const b=y()?.comments,I=b?.create;if(typeof I!="function")return Xn("comments.create is unavailable.");const E=Pm.get(),B=E.target??E.selectionTarget;if(E.empty||!B)return Xn("A range selection is required to comment.","NO_SELECTION");const W=Xn("comments.create failed.");return Pt(()=>Ms(I.call(b,{target:B,text:f.text}),W),W)},reply:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.reply??I?.create;if(typeof E!="function")return Xn("comments.reply is unavailable.");const B=Xn("comments.reply failed.");return Pt(()=>Ms(E===I?.reply?E.call(I,{parentCommentId:f,text:m.text}):E.call(I,{parentCommentId:f,text:m.text}),B),B)},edit:(f,m)=>{const b=nh();if(b)return b;const I=y()?.comments,E=I?.patch;if(typeof E!="function")return Xn("comments.patch is unavailable.");const B=Xn("comments.patch failed.");return Pt(()=>Ms(E.call(I,{commentId:f,text:m.text}),B),B)},resolve:f=>NA(f,"resolved"),reopen:f=>NA(f,"active"),delete:f=>{const m=nh();if(m)return m;const b=y()?.comments,I=b?.delete??b?.remove;if(typeof I!="function")return Xn("comments.delete is unavailable.");const E=Xn("comments.delete failed.");return Pt(()=>Ms(I.call(b,{commentId:f}),E),E)},setActive:f=>{if(f==null)return ve=null,Kt(),!0;if(!_())return!1;const m=ed.get();if(m.listStatus!=="ready")return!1;const b=DV(m.items,f);return!b||!m.items.some(I=>Gn(I)===b)?!1:(ve=b,Kt(),!0)},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:_()?dt.documentApiUnavailable:dt.notReady};const m=await Om("comments",f,ed.get().items);return m?wc(m):{success:!1,ok:!1,reason:dt.targetUnresolved}}},Ea=Ho(f=>f.trackChanges),S2=(f,m)=>{const b=Ea.get().items.filter(je=>Gn(je)!==null);if(b.length===0)return null;const I=pt.trackChanges.activeId,E=ue?.id===I?ue.story:void 0,B=b.filter(je=>ym(je)==null),W=E||B.length===0?b:B;let ie=I?W.findIndex(je=>Ui(je,I,E)):-1;ie===-1&&I&&E&&(ie=W.findIndex(je=>Ui(je,I)));const fe=W[ie===-1?f>0?0:W.length-1:(ie+f+W.length)%W.length],Le=Gn(fe),Ue=ym(fe);return $e(Ue?{id:Le,story:Ue}:{id:Le},m),Kt(),Le};let zA=Promise.resolve();const Yj=f=>{const m=re;return zA.catch(()=>{}).then(()=>Xj(f,m))},Xj=async(f,m)=>{if(re!==m)return{success:!1};const b=ue,I=S2(f,{invalidateQueuedNavigation:!1});if(I==null)return{success:!1};const E=ue,B=ke,W=()=>re===m&&ue===E&&ke===B,ie=()=>{W()&&($e(b,{invalidateQueuedNavigation:!1}),Kt())};E&&Je.add(E);try{const fe=await Om("trackChanges",I,Ea.get().items,E?.story?{story:E.story}:void 0);if(!W())return{success:!1};if(!fe)return ie(),{success:!1};so+=1;try{const Le=await wc(fe,{behavior:"auto",shouldContinue:W});return W()?(!Le.ok&&Le.reason!==dt.targetNotVisible?(ie(),Ee(b)):Ee(E),{success:Le.ok}):{success:!1}}finally{so=Math.max(0,so-1),so===0&&(W()?Xt&&Vr(Xr(Xt)):Ee(ue))}}finally{E&&Je.delete(E)}},VA=f=>{const m=Yj(f);return zA=m.then(()=>{},()=>{}),m},Nm=Po(Ea),Zj={get:Nm.get,getSnapshot:Nm.getSnapshot,subscribe:Nm.subscribe,observe:Nm.observe,list:()=>(_e(),Ea.get().items),accept:f=>_2("accept",f),reject:f=>_2("reject",f),acceptAll:()=>rh("accept",{kind:"all"},null),rejectAll:()=>rh("reject",{kind:"all"},null),next:()=>S2(1),previous:()=>S2(-1),navigateNext:()=>VA(1),navigatePrevious:()=>VA(-1),getAt:f=>{if(!f||typeof f!="object"||typeof f.x!="number"||typeof f.y!="number")return null;const m=E2(f);if(m.length===0)return null;const b=Ea.get().items;let I;for(const E of m){if(E.type!=="trackedChange")continue;let B;if(E.story){if(I===void 0&&(I=Zi()),!I)continue;B=I}else B=b;const W=B.find(ie=>Ui(ie,E.id,E.story));if(W)return E.story?{id:W.id,item:W,story:E.story}:{id:W.id,item:W}}return null},setActive:f=>{if(f==null)return $e(null),Ee(null),Kt(),!0;if(!_())return!1;const m=typeof f=="string"?{id:f}:{id:f.id,story:f.story};if(typeof m.id!="string"||m.id.length===0)return!1;const b=m.id;if(m.story){const I=Zi();if(!I)return!1;const E=ku(I,m.story).toPublicId(m.id)??m.id;if(!I.some(B=>Ui(B,E,m.story)))return!1;m.id=E}else{const I=Ea.get().items,E=fa(I).toPublicId(m.id)??m.id,B=I.find(W=>Gn(W)===E);if(!B)return!1;m.id=E,m.story=ym(B)}return b!==m.id&&(m.paintedEntityId=b),$e(m),Ee(m),Kt(),!0},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:_()?dt.documentApiUnavailable:dt.notReady};re+=1,Re+=1;const m=Re,b=Ea.get().items,I=fa(b).toPublicId(f)??f,E=ym(b.find(ie=>Gn(ie)===I)),B=ue,W={id:I,...E?{story:E}:{},...I!==f?{paintedEntityId:f}:{}};Je.add(W);try{const ie=await Om("trackChanges",I,b,E?{story:E}:void 0);if(Re!==m)return{success:!1,ok:!1};if(!ie)return{success:!1,ok:!1,reason:dt.targetUnresolved};$e(W);const fe=Re,Le=ue,Ue=ke,je=()=>Re===fe&&ue===Le&&ke===Ue,Ne=()=>{je()&&($e(B,{invalidateQueuedNavigation:!1}),Kt())};Kt(),so+=1;try{const Ye=await wc(ie,{behavior:"auto",shouldContinue:je});return je()?(!Ye.ok&&Ye.reason!==dt.targetNotVisible?(Ne(),Ee(B)):Ee(W),Ye):{success:!1,ok:!1}}finally{so=Math.max(0,so-1),so===0&&(je()?Xt&&Vr(Xr(Xt)):Ee(ue))}}finally{Je.delete(W)}}},_2=(f,m)=>{const{id:b,story:I}=typeof m=="string"?{id:m,story:void 0}:m,E={kind:"id",id:b,...I?{story:I}:{}};return rh(f,E,b,I)},rh=(f,m,b,I)=>{try{return Zr(A2(f,m,b,I))}catch{return!1}},A2=(f,m,b,I)=>{if(Vo())return!1;const E=y()?.trackChanges,B=m.kind==="all"||m.scope==="all",W=m.kind==="range",ie=m.kind==="ids";if(cc({kind:f,scope:B?"all":"id"},E))return!1;const fe=B?`${f}All`:f,Le=!W&&!ie&&!I&&E&&typeof E[fe]=="function"?E[fe]:null,Ue=E&&typeof E.decide=="function"?E.decide:null;return!Le&&!Ue?!1:Le?Le.call(E,b??{}):Ue.call(E,{decision:f,target:m})},I2=Ho(f=>f.contentControls),oh=f=>I2.get().items.find(m=>m?.id===f)??null,Bm=Po(I2),Qj=(f=>{if(f===void 0)return Bm.get();const m=bm(f);return m?oh(m):null}),Jj={get:(f=>(f!==void 0&&No("api"),Qj(f))),getSnapshot:Bm.getSnapshot,subscribe:Bm.subscribe,observe:Bm.observe,list:()=>(No("api"),I2.get().items),getById:f=>(No("api"),oh(f)),getRect:f=>{const m=bm(f);if(!m)return sl("unresolved");No("panel");const b=oh(m);if(!b)return sl("unresolved");const I=l2(b);return I?Hm.getRect({target:I}):sl("unavailable")},scrollIntoView:async f=>{const m=bm(f);if(!m)return{success:!1};No("panel");const b=oh(m);if(!b)return{success:!1};const I=l2(b);return I?{success:(await wc(I,{block:f.block,behavior:f.behavior})).ok}:{success:!1}},focus:async f=>{const m=bm(f);if(!m)return{success:!1,reason:"invalid-id"};if(!_())return{success:!1,reason:"not-ready"};No("panel");const b=oh(m);if(!b)return{success:!1,reason:"not-found"};const I=l2(b);if(!I)return{success:!1,reason:"not-reachable"};if(!(await wc(I,{block:f.block,behavior:f.behavior})).ok)return{success:!1,reason:"not-reachable"};const E=TV(I);if(!E)return{success:!1,reason:"not-reachable"};const B=FA.apply(E);return!B.ok&&B.reason!==dt.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:(Gj(m),{success:!0})}},zm=Po(Ho(f=>f.fonts)),eU={get:zm.get,getSnapshot:zm.getSnapshot,subscribe:zm.subscribe,observe:zm.observe,getFamilyOptions:()=>pt.fonts.options,getSizeOptions:()=>pt.fonts.sizeOptions},Vm=Po(Ho(f=>f.zoom)),tU={get:Vm.get,getSnapshot:Vm.getSnapshot,subscribe:Vm.subscribe,observe:Vm.observe,set:f=>{if(typeof t?.setZoom=="function")try{t.setZoom(f),Kt()}catch{}},setMode:f=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(f),Kt()}catch{}}},jm=Po(Ho(f=>f.document)),nU={get:jm.get,getSnapshot:jm.getSnapshot,subscribe:jm.subscribe,observe:jm.observe,setMode:f=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(f),Kt()}catch{}},export:f=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(f))}catch{return}},getText:()=>{const f=y(),m=Pt(f?.getText?()=>f.getText({}):void 0,null);return typeof m=="string"?m:m&&typeof m=="object"&&typeof m.text=="string"?m.text:null},replaceFile:f=>{const m=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof m=="function")try{return Promise.resolve(m.call(t,f))}catch{return}}},jA=()=>{if(typeof HTMLElement>"u")return null;const f=_()?.mount?.container;if(f instanceof HTMLElement)return f;const m=t?.element;return m instanceof HTMLElement?m:null},rU=(f,m)=>{if(typeof f!="number"||typeof m!="number"||!Number.isFinite(f)||!Number.isFinite(m))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const I=jA();if(!I)return[];const E=b.elementFromPoint(f,m);if(!E||!I.contains(E))return[];const B=[E],W=tt=>{tt&&I.contains(tt)&&!B.includes(tt)&&B.push(tt)},ie=b.elementsFromPoint;if(typeof ie=="function"){let tt=[];try{tt=ie.call(b,f,m)??[]}catch{tt=[]}for(const Bt of tt)W(Bt)}const fe=[],Le=tt=>{tt&&I.contains(tt)&&!fe.includes(tt)&&!B.includes(tt)&&fe.push(tt)},Ue=tt=>{const Bt=tt.getBoundingClientRect;if(typeof Bt!="function")return!1;let Qt;try{Qt=Bt.call(tt)}catch{return!1}return Qt!=null&&f>=Qt.left&&f<=Qt.right&&m>=Qt.top&&m<=Qt.bottom};for(const tt of B){const Bt=tt.querySelectorAll;if(typeof Bt!="function")continue;let Qt;try{Qt=Bt.call(tt,"[data-track-change-marker]")}catch{continue}for(let an=0;an<Qt.length;an+=1)Ue(Qt[an])&&Le(Qt[an])}fe.reverse();const je=[...fe,...B],Ne=dA(je[0],I);for(let tt=1;tt<je.length;tt+=1)for(const Bt of dA(je[tt],I))Ne.push(Bt);if(Ne.length===0)return Ne;const Ye=Ea.get().items,He=fa(Ye);let Xe;const Ze=new Set,ot=[];for(const tt of Ne){if(tt.type!=="trackedChange"){const Pn=`${tt.type}:${tt.id}`;if(Ze.has(Pn))continue;Ze.add(Pn),ot.push(tt);continue}const Bt=EV(tt.storyKey)??IV(tt.story);let Qt;if(Bt){if(Xe===void 0&&(Xe=Zi()),!Xe||(Qt=ku(Xe,Bt).toPublicId(tt.id),!Qt||!Xe.some(Pn=>Ui(Pn,Qt,Bt))))continue}else if(Qt=He.toPublicId(tt.id),!Qt)continue;const an=`trackedChange:${Qt}`;Ze.has(an)||(Ze.add(an),ot.push(Bt?{type:"trackedChange",id:Qt,story:Bt}:{type:"trackedChange",id:Qt}))}return ot};function E2(f,m){return typeof f=="object"?rU(f?.x,f?.y):null}const td=new Set;let T2=!1;const UA=f=>{const m=x();if(typeof m?.observeGeometry!="function")return;let b=!1;const I=Pt(()=>{const E=m.observeGeometry(()=>f.schedule());return b=!0,E},null);f.detach=typeof I=="function"?I:null,f.boundHost=b?m:null},Um=f=>{if(f.detach){try{f.detach()}catch{}f.detach=null}f.boundHost=null},HA=()=>{if(T2=!1,!(J||x()))for(const f of td)Um(f)},oU=()=>{if(!T2){if(T2=!0,typeof queueMicrotask=="function"){queueMicrotask(HA);return}Promise.resolve().then(HA)}},iU=()=>{const f=x();if(!f){oU();return}for(const m of td)m.boundHost&&m.boundHost===f||(Um(m),UA(m),m.schedule())};Sa.push(iU);const Hm={getRect:f=>{const m=x(),b=m?.getTargetRects;if(typeof b=="function"){const I=Pt(()=>b.call(m,{target:f.target}),null);return I&&typeof I=="object"?I.success===!0&&Array.isArray(I.rects)?ZV(XV(I.rects.filter(E=>E!=null&&typeof E=="object")),f.relativeTo):sl(typeof I.reason=="string"?I.reason:"unresolved"):sl("unresolved")}return sl("unavailable")},observe:f=>{const m=[];let b=0;const I=typeof requestAnimationFrame=="function",E=()=>{if(!I){f();return}b||(b=requestAnimationFrame(()=>{b=0,f()}))},B=xs(ie=>({ready:ie.ready,selection:ie.selection,zoom:ie.zoom}));m.push(B.subscribe(()=>E()));const W={schedule:E,detach:null,boundHost:null};return UA(W),td.add(W),()=>{td.delete(W),Um(W),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const ie of m.splice(0))try{ie()}catch{}}},getHost:()=>jA(),entityAt:E2,contextAt:f=>{const m=!!f&&typeof f.x=="number"&&typeof f.y=="number",b=m?f.x:0,I=m?f.y:0;return{point:{x:b,y:I},entities:m?E2({x:b,y:I}):[],selection:pt.selection,position:null,insideSelection:!1}},scrollIntoView:async f=>{const m=f?.target;if(!m)return{success:!1};let b=null;if(m.kind==="entity"){const I=m.entityType==="comment"?"comments":"trackChanges",E=I==="comments"?ed.get().items:Ea.get().items,B=m.entityType==="trackedChange"&&m.story?{story:m.story}:void 0;b=await Om(I,m.entityId,E,B)}else{const I=m,E=m,B=Array.isArray(I.segments)&&I.segments.length>0?I.segments:E.blockId&&E.range?[{blockId:E.blockId,range:E.range}]:null;if(B){const W=m.story;b={kind:"text",segments:B,...W?{story:W}:{}}}}return b?{success:(await wc(b,{block:f.block??"center",behavior:f.behavior??"smooth"})).ok}:{success:!1}}},$A=f=>{const m=(f&&typeof f=="object"?f:null)?.target;return m&&typeof m=="object"?m:null},GA=f=>`metadata:resolve:${f}`,sU=f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return null;const{value:b}=wr(GA(f),Et(),()=>m.resolve({id:f}),$A);return b},aU=async f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return null;try{const b=Et(),I=await Promise.resolve(m.resolve({id:f}));if(b!==Et())return null;const E=$A(I);return ee.set(GA(f),{token:b,value:E,hasSettled:!0,inflightToken:null}),E}catch{return null}},lU={getRect:f=>{const m=y()?.metadata;if(!m||typeof m.resolve!="function")return sl("unavailable");const b=sU(f.id);return b?Hm.getRect({target:b}):sl("unresolved")},scrollIntoView:async f=>{const m=await aU(f.id);return m?{success:(await wc(m,{block:f.block,behavior:f.behavior})).ok}:{success:!1}}},cU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},uU={getContext:()=>{const f=Be();if(!f)return{...cU};const m=me()?.table;return{inTable:!0,tableNodeId:f.tableNodeId,rowIndex:f.rowIndex,columnIndex:f.columnIndex,cellNodeId:f.cellNodeId,rows:typeof m?.rows=="number"?m.rows:null,columns:typeof m?.columns=="number"?m.columns:null}},isInTable:()=>Be()!=null},$m={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:dt.searchUnavailable};let Nn={...$m};const Gm=new Set,Ta=()=>{const f=x()?.search;return f&&typeof f=="object"?f:null},Ps=()=>{const f=T()?.search;return f&&typeof f=="object"?f:null},ih=()=>{const f=Ta();if(f&&typeof f.setSession=="function")return!0;const m=Ps();return!!m&&typeof m.query=="function"&&typeof m.getState=="function"},es=()=>{for(const f of[...Gm])try{f(Nn)}catch{}},ii=f=>(Nn={...Nn,...f},es(),Nn);let ao=0,Cc=null;const WA=()=>{const f=Cc;Cc=null,f&&Pt(()=>(f(),null),null)},dU=()=>{ao+=1,WA();const f=ih();Nn={...$m,available:f,reason:f?void 0:dt.searchUnavailable},es()};_a.push(dU);const fU=f=>{if(!f)return!1;const m=f.queryError;if(m&&typeof m=="object"&&m.code==="invalid-pattern")return!0;const b=f.rejection;return f.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},x2=(f,m=!1)=>{const b=f&&typeof f=="object"?f:null;if(!b)return null;const I=Array.isArray(b.matches)?b.matches:[],E=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:I.length,B=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:E,activeIndex:B,canReplace:b.canReplace===!0||m,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...fU(b)?{invalidPattern:!0}:{}}},_o=()=>{const f=N("find.replace"),m=N("find.replaceAll");return f?.enabled===!0||m?.enabled===!0},Ao=(f,m=!1)=>{const b=x2(f,m);if(!b){ii({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}ii({...b.query!==void 0?{query:b.query}:{},total:b.total,activeIndex:b.activeIndex,canReplace:b.canReplace,...b.includeDeletedText!==void 0?{includeDeletedText:b.includeDeletedText}:{},...b.regex!==void 0?{regex:b.regex}:{},reason:b.invalidPattern?dt.searchInvalidPattern:void 0})},xa=()=>{const f=Ta();if(f&&typeof f.getState!="function")return Nn={...Nn,available:ih(),reason:ih()?void 0:dt.searchUnavailable},Nn;if(!f){const b=Ps();if(b&&typeof b.getState=="function"){const I=x2(Pt(()=>b.getState(),null),_o());if(I)return Nn={...Nn,...I.query!==void 0?{query:I.query}:{},total:I.total,activeIndex:I.activeIndex,canReplace:I.canReplace,available:!0,reason:I.invalidPattern?dt.searchInvalidPattern:void 0,open:Nn.open||!!I.query},Nn}return Nn={...$m,query:Nn.query,caseSensitive:Nn.caseSensitive,includeDeletedText:Nn.includeDeletedText},Nn}const m=x2(Pt(()=>f.getState(),null));return m&&(Nn={...Nn,...m.query!==void 0?{query:m.query}:{},total:m.total,activeIndex:m.activeIndex,canReplace:m.canReplace,...m.includeDeletedText!==void 0?{includeDeletedText:m.includeDeletedText}:{},...m.regex!==void 0?{regex:m.regex}:{},available:!0,reason:m.invalidPattern?dt.searchInvalidPattern:void 0,open:Nn.open||!!m.query}),Nn},nd=f=>{const m=f&&typeof f=="object"?f:null;if(m?.status==="committed")return{ok:!0};if(m?.status==="rejected"&&m.reason==="read-only")return{ok:!1,reason:dt.documentReadonly};const b=m?.rejection;return m?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:dt.documentReadonly}:{ok:!1,reason:dt.operationUnavailable}},Wm=Po({get:()=>xa(),subscribe:f=>(Gm.add(f),()=>Gm.delete(f))}),hU={get:Wm.get,getSnapshot:Wm.getSnapshot,subscribe:Wm.subscribe,observe:Wm.observe,open:()=>ih()?(ii({available:!0,open:!0,reason:void 0}),{ok:!0}):(ii({available:!1,open:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}),close:()=>{if(ao+=1,Cc)WA();else{const f=Ta();if(f&&typeof f.clear=="function")Pt(()=>f.clear(),null);else{const m=Ps();m&&typeof m.query=="function"&&Pt(()=>m.query({query:""}),null)}}Nn={...$m,available:ih(),reason:void 0},Nn.available||(Nn.reason=dt.searchUnavailable),es()},search:(f,m)=>{const b=Ta(),I=!!m?.caseSensitive,E=m?.includeDeletedText===!0,B=m?.regex===!0,W=++ao;if(!b||typeof b.setSession!="function"){const fe=Ps();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){ii({query:f,caseSensitive:I,includeDeletedText:E,regex:B,available:!0,open:!0,reason:void 0}),Cc=()=>{fe.query({query:""})};const Le=Pt(()=>fe.query({query:f,caseSensitive:I,includeDeletedText:E,regex:B}),null);return Sr(Le)?Promise.resolve(Le).then(Ue=>{W===ao&&Ao(Ue,_o())},()=>{W===ao&&ii({available:!1,reason:dt.searchUnavailable})}):Ao(Le,_o()),Ao(Pt(()=>fe.getState(),null),_o()),Nn}return ii({query:f,total:0,activeIndex:-1,available:!1,caseSensitive:I,includeDeletedText:E,regex:B,reason:dt.searchUnavailable})}ii({query:f,caseSensitive:I,includeDeletedText:E,regex:B,available:!0,open:!0,reason:void 0}),Cc=()=>{typeof b.clear=="function"&&b.clear()};const ie=Pt(()=>b.setSession(f,{caseSensitive:I,includeDeletedText:E,...B?{regex:!0}:{},highlight:!0}),null);if(Ao(ie),f.length>0&&Nn.total===0&&Nn.reason!==dt.searchInvalidPattern){const fe=Ps();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){const Le=Cc;Cc=()=>{Le?.(),fe.query({query:""})};const Ue=Pt(()=>fe.query({query:f,caseSensitive:I,includeDeletedText:E,regex:B}),null);Sr(Ue)?Promise.resolve(Ue).then(je=>{W===ao&&Ao(je,_o())},()=>{W===ao&&ii({available:!1,reason:dt.searchUnavailable})}):Ao(Ue,_o()),Ao(Pt(()=>fe.getState(),null),_o())}}return Nn},next:()=>{const f=Ta();if(!f||typeof f.next!="function"){const m=Ps();if(!m||typeof m.next!="function"||typeof m.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(Nn.total===0)return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.next(),null);if(Sr(b)){const I=ao;Promise.resolve(b).then(E=>{I===ao&&Ao(E,_o())}).catch(()=>{I===ao&&ii({available:!1,reason:dt.searchUnavailable})})}else Ao(b,_o());return Ao(Pt(()=>m.getState(),null),_o()),{ok:!0}}return Nn.total===0?{ok:!1,reason:dt.operationUnavailable}:(Ao(Pt(()=>f.next(),null)),{ok:!0})},previous:()=>{const f=Ta();if(!f||typeof f.previous!="function"){const m=Ps();if(!m||typeof m.previous!="function"||typeof m.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(Nn.total===0)return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.previous(),null);if(Sr(b)){const I=ao;Promise.resolve(b).then(E=>{I===ao&&Ao(E,_o())}).catch(()=>{I===ao&&ii({available:!1,reason:dt.searchUnavailable})})}else Ao(b,_o());return Ao(Pt(()=>m.getState(),null),_o()),{ok:!0}}return Nn.total===0?{ok:!1,reason:dt.operationUnavailable}:(Ao(Pt(()=>f.previous(),null)),{ok:!0})},clear:()=>{ao+=1;const f=Ta();if(f&&typeof f.clear=="function"&&Pt(()=>f.clear(),null),!f||typeof f.clear!="function"){const m=Ps();m&&typeof m.query=="function"&&Pt(()=>m.query({query:""}),null)}ii({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:f=>{const m=Ta();if(!m){const I=Ps();if(!I||typeof I.replace!="function"||typeof I.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(!_o())return{ok:!1,reason:dt.operationUnavailable};const E=Pt(()=>I.replace({replacement:typeof f=="string"?f:""}),null);if(Sr(E)){const B=ao;xa(),es();const W=()=>B===ao;return Promise.resolve(E).then(ie=>(W()&&(Ao(ie,_o()),xa(),es()),nd(ie)),()=>(W()&&ii({available:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}))}return xa(),es(),nd(E)}if(typeof m.replaceCurrent!="function")return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.replaceCurrent(typeof f=="string"?f:""),null);return xa(),es(),nd(b)},replaceAll:f=>{const m=Ta();if(!m){const I=Ps();if(!I||typeof I.replaceAll!="function"||typeof I.getState!="function")return{ok:!1,reason:dt.searchUnavailable};if(!_o())return{ok:!1,reason:dt.operationUnavailable};const E=Pt(()=>I.replaceAll({replacement:typeof f=="string"?f:""}),null);if(Sr(E)){const B=ao;xa(),es();const W=()=>B===ao;return Promise.resolve(E).then(ie=>(W()&&(Ao(ie,_o()),xa(),es()),nd(ie)),()=>(W()&&ii({available:!1,reason:dt.searchUnavailable}),{ok:!1,reason:dt.searchUnavailable}))}return xa(),es(),nd(E)}if(typeof m.replaceAll!="function")return{ok:!1,reason:dt.operationUnavailable};const b=Pt(()=>m.replaceAll(typeof f=="string"?f:""),null);return xa(),es(),nd(b)}},KA=Ho(f=>f.styles),Km=Po(KA),pU={get:Km.get,getSnapshot:Km.getSnapshot,subscribe:Km.subscribe,observe:Km.observe,getCatalog:f=>ce(f).value,getQuickGallery:()=>KA.get().quickGallery,getActiveParagraphStyle:()=>Te(pt.selection,Se().cache).style},qA={select:xs,get state(){return pt},selection:FA,commands:Wj,toolbar:Kj,comments:qj,trackChanges:Zj,contentControls:Jj,fonts:eU,zoom:tU,document:nU,viewport:Hm,metadata:lU,tables:uU,search:hU,styles:pU,formatPainter:{setPointerSelecting(f){J||(h={...h,pointerSelecting:f})},notifyPointerUp(){J||(h={...h,pointerSelecting:!1},LA())},setKeyboardSelecting(f){J||(h={...h,keyboardSelecting:f})},notifyKeyUp(){J||(h={...h,keyboardSelecting:!1},LA())},cancel(){J||Mm()},onModeChange(f){return J?()=>{}:(p.add(f),()=>p.delete(f))}},createScope:()=>{const f=[];return{select:(m,b)=>{const I=xs(m,b);return{get:I.get,subscribe:E=>{const B=I.subscribe(E);return f.push(B),B}}},dispose:()=>{for(const m of f.splice(0))m()}}},destroy:()=>{if(!J){J=!0,mV(_n,bt),br.reset(),De(),q&&(clearTimeout(q),q=null),te&&(clearTimeout(te),te=null,Y=0),U?.timer&&(clearTimeout(U.timer),U.timer=null),U=null,ye&&(clearTimeout(ye),ye=null),Ar&&(clearTimeout(Ar),Ar=null),oo&&oo(),oo=null,ro=null,_i.clear(),O.clear();for(const f of gc.splice(0))f();kt&&kt(),kt=null,et=null,Ot&&Ot(),Ot=null,ht=null,Mt&&Mt(),Mt=null,Xt=null,pr&&pr(),pr=null,jn=null,zr&&zr(),zr=null,er=null;for(const f of td)Um(f);td.clear(),qe.clear(),Gm.clear(),g+=1,p.clear(),ao+=1,he.clear()}}};return S=qA,qA}var ij=[{value:"Arial",label:"Arial",previewFamily:"Arial, sans-serif"},{value:"Calibri",label:"Calibri",previewFamily:"Calibri, sans-serif"},{value:"Courier New",label:"Courier New",previewFamily:'"Courier New", monospace'},{value:"Georgia",label:"Georgia",previewFamily:"Georgia, serif"},{value:"Times New Roman",label:"Times New Roman",previewFamily:'"Times New Roman", serif'},{value:"Verdana",label:"Verdana",previewFamily:"Verdana, sans-serif"}];function sj(e){const t=e.trim(),n=t[0];if(n==='"'||n==="'"){const o=t.indexOf(n,1);if(o>0)return t.slice(1,o).trim()}const r=t.indexOf(",");return(r===-1?t:t.slice(0,r)).trim().replace(/^["']|["']$/g,"")}function aj(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(!n||typeof n!="object")continue;const r=n,o=typeof r.logicalFamily=="string"?sj(r.logicalFamily):"";if(!o)continue;const i=typeof r.previewFamily=="string"&&r.previewFamily.trim()?r.previewFamily.trim():o;t.push({value:o,label:o,previewFamily:i})}return t}function lj(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(!n||typeof n!="object")continue;const r=n,o=typeof r.value=="string"?r.value.trim():"";if(!o)continue;const i=typeof r.label=="string"&&r.label.trim()?r.label.trim():o,s=typeof r.previewFamily=="string"&&r.previewFamily.trim()?r.previewFamily.trim():o;t.push({value:o,label:i,previewFamily:s})}return t}function cj(e,t=[]){const n=[],r=new Set,o=s=>{const a=String(s.value).trim().toLowerCase();!a||r.has(a)||(r.add(a),n.push(s))};for(const s of e)o(s);const i=t.length?t:ij;for(const s of i)o(s);return n}var uj=[{value:"8",label:"8"},{value:"9",label:"9"},{value:"10",label:"10"},{value:"11",label:"11"},{value:"12",label:"12"},{value:"14",label:"14"},{value:"16",label:"16"},{value:"18",label:"18"},{value:"24",label:"24"},{value:"36",label:"36"}];function dj(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}Lt();var fj=['[data-sdt-type="structuredContent"][data-sdt-id]','[data-sdt-type="structuredContent"][data-sdt-container-id]','[data-sdt-container-type="structuredContent"][data-sdt-container-id]'].join(", "),hj=Object.freeze(["#FF6B6B","#4ECDC4","#45B7D1","#FFA07A","#98D8C8","#F7DC6F","#BB8FCE","#85C1E2","#F1948A","#82E0AA","#F8C471","#AED6F1","#D7BDE2","#A3E4D7","#F0B27A","#AEB6BF","#E74C3C","#2ECC71","#3498DB","#E67E22","#1ABC9C","#9B59B6","#34495E","#F39C12"]);async function pj(e,t){const n=new p6.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function g2(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function IA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function mj(e,t){if(!e)return()=>{};if(g2(e))return t(),()=>{};const n=typeof e.on=="function"?e.on.bind(e):null,r=typeof e.off=="function"?e.off.bind(e):null;if(!n)return t(),()=>{};let o=!1;const i=()=>{o||(o=!0,r?.("synced",a),r?.("sync",l))},s=()=>{o||(i(),t())},a=()=>{IA(e),s()},l=c=>{c!==!1&&(c===!0||g2(e))&&(IA(e),s())};return n("synced",a),n("sync",l),g2(e)&&s(),i}function gj(e,t){const n=e.composedPath();if(!n.includes(t))return null;const r=n.find(a=>a instanceof HTMLElement&&a.matches(fj));if(!r)return null;const o=n.some(a=>a instanceof HTMLElement&&a.classList.contains(ip.BLOCK_SDT_LABEL)),i=r.getAttribute("data-sdt-container-id")?.trim()||null,s=r.getAttribute("data-sdt-id")?.trim()||null;return o?i??s:s??i}function vj(e){if(!e||typeof e!="object")return[];const t=e.items;return Array.isArray(t)?t:[]}function yj(e){if(!e||typeof e.id!="string"||e.kind!=="inline"&&e.kind!=="block"||typeof e.controlType!="string")return null;const t=e.properties?.tag,n=e.properties?.alias;return{id:e.id,controlType:e.controlType,scope:e.kind,...typeof t=="string"&&t?{tag:t}:{},...typeof n=="string"&&n?{alias:n}:{}}}function Zo(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function bj(e){const t=e&&typeof e=="object"?e.code:null;return t==="comment-export-missing-story-reference"||t==="v2-worker-comment-export-mode-unsupported"}function EA(e){return typeof e=="string"&&e.length>0?e:null}function v2(e){return e?Zo(e)?EA(e.documentId??e.options?.documentId??null):EA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function wj(e){if(!e||Zo(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function Gi(e){if(!e)return null;if(Zo(e))return e.fonts??null;const t=wj(e);return t?{getReport:()=>t.getFontReport?.()??[],getMissingFonts:()=>t.getMissingFonts?.()??[],getDocumentFonts:()=>[...new Set((t.getFontReport?.()??[]).map(n=>n.logicalFamily))],getDocumentFontOptions:()=>t.getDocumentFontOptions?.()??[],getFontFamilyOptions:()=>t.getFontFamilyOptions?.()??[],getLastFontsChangedPayload:()=>t.getLastFontsChangedPayload?.()??null,map:n=>t.mapFonts(n),unmap:n=>t.unmapFonts(n),add:n=>t.addFonts(Array.isArray(n)?n:[n]),preload:n=>t.preloadFonts(n)}:null}var _m=class extends Ym.default{static{this.allowedTypes=[Fr,Ol,tp]}#t;#n;#e;#r;#i;#s;#d;#h;#f;#c;#p;get uiConfig(){return this.#p}#o;get interactionConfig(){return this.#o}#l;get surfacesConfig(){return this.#l}#g;#u;#y;#w;constructor(e){if(super(),this.#t=!1,this.#n=!1,this.#e=null,this.#r=null,this.#i=null,this.#s=null,this.#d=null,this.#h=null,this.#f=n=>{this.#k(n)},this.#c=null,this.#p=V4({}),this.#o=j4({}),this.#l=H4({}),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,this.#u=new hN,this.#y=null,this.#w=!1,this.config={selector:"#superdoc",documentMode:"editing",allowSelectionInViewMode:!1,role:"editor",document:{},documents:[],editorExtensions:[],colors:[],users:[],user:{...X0},layoutEngineOptions:{},modules:{},licenseKey:void 0,telemetry:{enabled:!0},title:"SuperDoc",conversations:[],isInternal:!1,comments:{visible:!1},toolbarGroups:["left","center","right"],toolbarIcons:{},toolbarTexts:{},uiDisplayFallbackFont:"Arial, Helvetica, sans-serif",isDev:!1,disablePiniaDevtools:!1,onEditorBeforeCreate:()=>null,onEditorCreate:()=>null,onEditorDestroy:()=>null,onSourceComplete:()=>null,onSourceSignalsComplete:()=>null,onContentError:()=>null,onReady:()=>null,onCommentsUpdate:()=>null,onContentControlActiveChange:()=>null,onContentControlClick:()=>null,onAwarenessUpdate:()=>null,onLocked:()=>null,onPdfDocumentReady:()=>null,onSidebarToggle:()=>null,onCollaborationReady:()=>null,onEditorUpdate:()=>null,onCommentsListChange:()=>null,onException:()=>null,onListDefinitionsChange:()=>null,onPaginationUpdate:()=>null,onTransaction:()=>null,disableContextMenu:!1,viewOptions:{layout:"print"},useLayoutEngine:!0},this.#Z=new WeakSet,this.#Q=null,this.#j=null,this.#M=null,!e.selector)throw new Error("SuperDoc: selector is required");const t=typeof e.selector=="string"?document.querySelector(e.selector):e.selector;if(!(t instanceof HTMLElement))throw new Error("SuperDoc: selector must be a valid CSS selector string or DOM element");this.#g=new tN({getModuleConfig:()=>this.#l}),this.#h=t,t.addEventListener("click",this.#f,!0),this.#I(e,t)}async#k(e){const t=this.#h;if(!t)return;const n=gj(e,t),r=this.activeEditor?.doc?.contentControls?.list;if(!(!n||typeof r!="function"))try{const o=await r();if(this.#t)return;const i=yj(vj(o).find(s=>s.id===n));i&&this.emit("content-control:click",{target:i,source:"pointer"})}catch{return}}async#I(e,t){this.config={...this.config,...e},!this.config.comments||typeof this.config.comments!="object"?this.config.comments={visible:!1}:typeof this.config.comments.visible!="boolean"&&(this.config.comments.visible=!1),lN(this.config),this.config.documents=this.config.documents||[],this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};const n=this.config.viewOptions?.layout==="web",r=this.config.layoutEngineOptions?.flowMode==="semantic";if(n&&this.config.useLayoutEngine&&!r&&(console.warn("[SuperDoc] Web layout uses PM fallback unless layoutEngineOptions.flowMode is set to 'semantic'. Automatically disabling layout engine."),this.config.useLayoutEngine=!1),!n&&r&&(console.warn("[SuperDoc] flowMode 'semantic' is only valid with web layout. Coercing to 'paginated'."),this.config.layoutEngineOptions.flowMode="paginated"),this.editorVersion=2,this.#we(),this.config.user=cN(this.config.user),this.config.layoutEngineOptions.virtualization||(this.config.layoutEngineOptions.virtualization={enabled:!0,window:5,overscan:1}),this.config.modules=this.config.modules||{},Object.prototype.hasOwnProperty.call(this.config.modules,"comments")||(this.config.modules.comments={}),this.config.modules.comments=Ok(this.config.modules.comments),this.#p=V4(this.config),this.#o=j4(this.config),this.#l=H4(this.config),this.config.disableContextMenu=!this.#p.contextMenu.enabled,this.config.rulers=this.#p.ruler.enabled,this.#p.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#p.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#o.comments)}if(this.config.colors=k6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.4.0-next.15",this.#C("π¦ [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||ts(),this.colors=this.config.colors??[],this.#D(),await T8(),this.#t)return;if(await this.#b(this.config.modules),this.#t){this.#de();return}this.config.cspNonce&&this.#P(),this.user=this.config.user,this.users=this.config.users||[],this.socket=null,this.isDev=this.config.isDev||!1,this.activeEditor=null,this.comments=[],this.#y||(this.#y=this.#u.subscribe(i=>{this.#ke(i.nextRuntimeId,i.legacyEditorProjection)})),this.isLocked=this.config.isLocked||!1,this.lockedBy=this.config.lockedBy||null;const o=document.createElement("div");o.style.display="contents",t.appendChild(o),this.#d=o,this.#S(),this.#L(),this.#Se(),this.#E()}#E(){if(this.#T(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#d)}#L(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new ED({Renderer:QF,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#m("requiredNumberOfEditors").documents.filter(e=>e.type===Fr).length}get ui(){return this.#c||(this.#c=oj({superdoc:this}),this.#t&&this.#c.destroy()),this.#c}get state(){return{documents:this.#m("state").documents,users:this.users}}getDocumentRuntimeForDocument(e){return typeof e!="string"||e.length===0?null:(this.superdocStore?.documents??[]).find(t=>t?.getEditor?.()?.options?.documentId===e)?.getDocumentRuntime?.()??null}getComment(e){return typeof e!="string"||e.length===0?null:this.commentsStore?.getComment?.(e)??null}get element(){return typeof this.config.selector=="string"?document.querySelector(this.config.selector):this.config.selector}#P(){const e=this.config.cspNonce,t=document.createElement;document.createElement=function(n){const r=t.call(this,n);return n.toLowerCase()==="style"&&r.setAttribute("nonce",e),r}}#D(){const e=this.config.document,t=!!e&&typeof e=="object"&&Object.keys(e)?.length,n=!!e&&typeof e=="string"&&e.length>0,r=!!e&&typeof File=="function"&&e instanceof File,o=!!e&&e instanceof Blob&&!(e instanceof File),i=this.config.documents&&this.config.documents?.length;if(t&&i&&console.warn("π¦ [superdoc] You can only provide one of document or documents"),t){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}else if(n)this.config.documents=[{id:ts(),type:Fr,url:this.config.document,name:"document.docx"}];else if(r){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}else if(o){const s=Xd(this.config.document);this.config.documents=[{id:ts(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Xd(s);if(!a||typeof a!="object")return a;const l=typeof a=="object"&&"id"in a&&a.id||s&&typeof s=="object"&&"id"in s&&s.id;return{...a,id:l||ts()}}))}#T(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=mD({disablePiniaDevtools:!!this.config.disablePiniaDevtools});this.app=e,this.pinia=t,this.app.config.globalProperties.$config=this.config,this.app.config.globalProperties.$documentMode=this.config.documentMode,this.app.config.globalProperties.$superdoc=this,this.app.provide("surfaceManager",this.#g),this.superdocStore=n,this.commentsStore=r,this.highContrastModeStore=o,typeof this.superdocStore.setExceptionHandler=="function"&&this.superdocStore.setExceptionHandler(s=>this.emit("exception",s)),this.superdocStore.init(this.config);const i=this.config.modules.comments;this.commentsStore.init(i||{}),this.isCollaborative&&h8(this),this.#ue()}#a(e,t){t&&this.on(e,t)}#S(){this.#a("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#a("editorCreate",this.config.onEditorCreate),this.#a("editorDestroy",this.config.onEditorDestroy),this.#a("source:complete",this.config.onSourceComplete),this.#a("source:signals-complete",this.config.onSourceSignalsComplete),this.#a("ready",this.config.onReady),this.#a("comments-update",this.config.onCommentsUpdate),this.#a("content-control:active-change",this.config.onContentControlActiveChange),this.#a("content-control:click",this.config.onContentControlClick),this.#a("awareness-update",this.config.onAwarenessUpdate),this.#a("locked",this.config.onLocked),this.#a("pdf:document-ready",this.config.onPdfDocumentReady),this.#a("sidebar-toggle",this.config.onSidebarToggle),this.#a("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#$(e?.editor??null)),this.#a("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#a("exception",this.config.onException),this.#a("list-definitions-change",this.config.onListDefinitionsChange),this.#a("pagination-update",this.config.onPaginationUpdate),this.#a("fonts-resolved",this.config.onFontsResolved),this.#a("fonts-changed",this.config.onFontsChanged),this.#a("zoomChange",this.config.onZoomChange),this.#a("viewport-change",this.config.onViewportChange)}async#b({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:ts(),type:Fr,name:"document.docx"}]),this.config.v2CollaborationPreflightFailure={code:"collaboration-v1-config-unsupported",message:"SuperDoc v2 cannot use modules.collaboration because it is the SuperDoc v1 collaboration API. SuperDoc did not attach the provider or change the document. Configure Document.v2Collaboration with a v2 room instead."},this.config.documents):this.config.documents}#ee(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=Jr(e),this.provider=Jr(t),this.#_();const n=this.config;this._cleanupAwareness=l8(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#H(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null),this.isCollaborative=!1,this._commentsCollabInitialized=!1,this.ydoc=void 0,this.provider=void 0;const e=this.config;delete e.modules.collaboration,e.documents.forEach(t=>{delete t.ydoc,delete t.provider})}#A(){if(this.#r){try{this.#r()}catch{}this.#r=null}if(this.#i){try{this.#i()}catch{}this.#i=null}}#$(e){this.#A(),Zo(e)&&(this.#O(e),this.#x(e))}#O(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=SD(()=>this.user),r=o=>{if(this.#t)return;const i=n.next(o);this.emit("awareness-update",{...i,superdoc:this})};try{const o=t.getSnapshot?.();o&&r(o),this.#r=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#x(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#t||this.#v(!!r.isLocked,this.#F(r.lockedBy??null))};try{if(this.#s&&typeof t.setLocked=="function"){const o=this.#s;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#s=null}const r=t.getSnapshot?.();r&&n(r),this.#i=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#F(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#G(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#v(e,t){this.isLocked===e&&this.#G(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#C("π¦ [superdoc] Locking superdoc:",e,t,`
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
`),this.emit("locked",{isLocked:e,lockedBy:t}))}#_(){const e=this.config.user;if(!e||e.color)return;const t=this.colors.length>0?this.colors:hj,n=e.id||e.email||e.name||"";let r=5381;for(let o=0;o<n.length;o++)r=(r<<5)+r^n.charCodeAt(o);e.color=t[Math.abs(r)%t.length]}async upgradeToCollaboration(e){const{target:t,mountedDocumentId:n}=this.#ge(e);this.#n=!0;try{const r=await this.#pe(),o=this.#W(),i=this.#N();this.#K();let s=null;try{this.#s=i,s=this.#me(n);const a=this.#fe(t,r);await s,this.#he(a,t),this.#s=null}catch(a){if(s&&this.#e){const l=this.#e;this.#e=null,l(),await s.catch(()=>{})}throw this.#B(o),a}}finally{this.#e=null,this.#n=!1}}#N(){return{isLocked:this.isLocked,lockedBy:this.lockedBy?{...this.lockedBy}:null}}#W(){const e=this.config.documents.find(r=>r.type===Fr),t=this.superdocStore?.documents.find(r=>r.id===e.id)??null,n=t?Cn(t):null;return{isCollaborative:this.isCollaborative,configV2Collaboration:e.v2Collaboration??null,configData:e.data,storeDoc:t,storeV2Collaboration:this.#Y(n),storeData:t?.data}}#B(e){this.#s=null;const t=this.config.documents.find(n=>n.type===Fr);t.v2Collaboration=e.configV2Collaboration,t.data=e.configData,this.isCollaborative=e.isCollaborative,e.storeDoc&&(e.storeDoc.data=e.storeData,this.#z(e.storeDoc,e.storeV2Collaboration),this.#ne(e.storeDoc))}#K(){if(this.#t)throw new Error("SuperDoc: instance was destroyed during upgrade")}#m(e){if(!this.superdocStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`);return this.superdocStore}#te(e){if(!this.commentsStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`);return this.commentsStore}#R(e){if(!this.superdocStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`)}#q(e,t){const n=this.superdocStore?.documents;if(Array.isArray(n))for(const r of n){const o=Cn(r);o.ydoc&&typeof o.ydoc=="object"&&"value"in o.ydoc&&(o.ydoc.value=e),o.provider&&typeof o.provider=="object"&&"value"in o.provider&&(o.provider.value=t)}}#Y(e){if(!e)return null;const t=e.v2Collaboration;return t&&typeof t=="object"&&"value"in t?t.value:t??null}#z(e,t){const n=Cn(e).v2Collaboration;if(n&&typeof n=="object"&&"value"in n){n.value=t;return}e.v2Collaboration=t}#ne(e){const t=Cn(e).editorMountNonce;if(t&&typeof t=="object"&&"value"in t&&typeof t.value=="number"){t.value+=1;return}const n=e;n.editorMountNonce=(typeof n.editorMountNonce=="number"?n.editorMountNonce:0)+1}#re(e){return e.providerFamily==="liveblocks"?{providerType:"liveblocks",documentId:e.documentId,roomMode:e.roomMode,...e.publicApiKey?{publicApiKey:e.publicApiKey}:{},...e.authEndpoint?{authEndpoint:e.authEndpoint}:{}}:e.providerFamily==="hocuspocus"?{providerType:"hocuspocus",documentId:e.documentId,roomMode:e.roomMode,...e.serverUrl?{serverUrl:e.serverUrl}:{},...e.params?{params:e.params}:{},...e.token?{token:e.token}:{}}:{providerType:"y-websocket",documentId:e.documentId,roomMode:e.roomMode,...e.serverUrl?{serverUrl:e.serverUrl}:{},...e.params?{params:e.params}:{}}}#fe(e,t){const n=this.config.documents.find(i=>i.type===Fr),r=this.#m("upgradeToCollaboration").documents.find(i=>i.id===n.id);if(!r)throw new Error("SuperDoc: source document store entry is not available for upgrade");const o=this.#re({...e,roomMode:"create"});return n.data=t,n.v2Collaboration=o,r.data=t,this.#z(r,o),this.isCollaborative=!0,this.readyEditors=0,this.#ne(r),{configDoc:n,storeDoc:r}}#he(e,t){const n=this.#re({...t,roomMode:"join"});e.configDoc.v2Collaboration=n,this.#z(e.storeDoc,n)}async#pe(){const e=this.activeEditor;if(Zo(e)&&typeof e.save=="function"){const r=await e.save();return this.#X(r)}const t=this.config.documents.find(r=>r.type===Fr),n=(this.superdocStore?.documents.find(r=>r.id===t.id)??null)?.data??t.data;if(n instanceof Blob)return n;if(n instanceof Uint8Array||n instanceof ArrayBuffer)return this.#X(n);throw new Error("SuperDoc: upgradeToCollaboration() requires a live v2 editor save or DOCX Blob source")}#X(e){if(e instanceof Blob)return e;if(e instanceof Uint8Array){const t=new Uint8Array(e.byteLength);return t.set(e),new Blob([t],{type:Fr})}if(e instanceof ArrayBuffer)return new Blob([e],{type:Fr});throw new Error("SuperDoc: active v2 editor returned an unsupported DOCX save payload")}#oe(e,t){const n=v2(e),r=(n?this.config.documents.find(a=>a.id===n):null)??this.config.documents.find(a=>a.type==="application/vnd.openxmlformats-officedocument.wordprocessingml.document");if(!r)return;const o=this.#X(t),i=r.v2Collaboration&&typeof r.v2Collaboration=="object"&&r.v2Collaboration.roomMode==="create"?{...r.v2Collaboration,roomMode:"join"}:null;r.data=o,i&&(r.v2Collaboration=i);const s=this.superdocStore?.documents.find(a=>a.id===r.id)??null;s&&(s.data=o,i&&this.#z(s,i))}#Ee(){const e=this.superdocStore?.documents;if(!e?.length)throw new Error("SuperDoc: no store documents available for upgrade");const t=e[0].getDocumentRuntime?.()||e[0].getEditor?.();if(!t?.attachCollaboration)throw new Error("SuperDoc: editor does not support attachCollaboration");return t}#Te(){this.#H(),this.#q(null,null)}#xe(e){const n=e.editor??e;return n.options?.collaborationIsReady?Promise.resolve():new Promise(r=>{let o=!1;const i=()=>{o||(o=!0,clearTimeout(s),typeof n.off=="function"&&n.off("collaborationReady",a))},s=setTimeout(()=>{i(),console.warn("[SuperDoc] collaborationReady did not fire within 10 s after collaboration attach. Continuing β collaboration is active but cursor/presence setup may be delayed."),r(void 0)},1e4),a=()=>{i(),r(void 0)};this.#e=()=>{i(),r(void 0)},typeof n.on=="function"?n.on("collaborationReady",a):(i(),r(void 0))})}#me(e){return new Promise((n,r)=>{let o=!1;const i=()=>{o||(o=!0,clearTimeout(a),this.off("collaboration-ready",s))},s=l=>{const c=l?.editor;Zo(c)&&v2(c)===e&&(!c.presence&&!c.lock||(i(),n()))},a=setTimeout(()=>{i(),r(new Error(`SuperDoc: v2 collaboration runtime did not become ready within 20000 ms for mounted document "${e}".`))},2e4);this.on("collaboration-ready",s),this.#e=()=>{i(),r(new Error("SuperDoc: instance was destroyed during upgrade"))}})}#Re(e){return new Promise((n,r)=>{let o,i=!1,s=()=>{};const a=()=>{i=!0,clearTimeout(o),s()};s=mj(e,()=>{i||(a(),n())}),i||(o=setTimeout(()=>{a(),r(new Error("SuperDoc: collaboration provider did not sync within 10000 ms. The provider exposes on/off but never emitted sync(true) or synced."))},1e4)),this.#e=()=>{i||(a(),r(new Error("SuperDoc: instance was destroyed during upgrade")))}})}#ge(e){if(this.#t)throw new Error("SuperDoc: cannot upgrade a destroyed instance");if(this.#n)throw new Error("SuperDoc: upgrade already in progress");if(this.isCollaborative)throw new Error("SuperDoc: instance is already collaborative");const t=this.config,n=t.documents.filter(l=>l.type===Fr);if(n.length===0)throw new Error("SuperDoc: no DOCX document found for upgrade");if(n.length>1)throw new Error("SuperDoc: upgradeToCollaboration() only supports a single DOCX document");if(t.documents.length!==n.length)throw new Error("SuperDoc: upgradeToCollaboration() only supports single-DOCX instances");if(!Zo(this.#ye()))throw new Error("SuperDoc: upgradeToCollaboration() requires a ready v2 DOCX editor");const r=n[0],o=r.id;if(typeof o!="string"||o.length===0)throw new Error("SuperDoc: source document is missing its mounted document identity");const i=t.modules?.collaboration,s=e.ydoc||e.provider?{ydoc:e.ydoc,provider:e.provider}:i?{...i}:null,a=XS({v2Collaboration:e.v2Collaboration??this.#ve(r.v2Collaboration)??i?.v2Collaboration??i?.v2??null,legacyCollaboration:s,documentType:Fr,documentCount:t.documents.length,...typeof window<"u"?{authEndpointBaseUrl:window.location.href}:{}});if(!a.ok)throw new Error(`SuperDoc: upgradeToCollaboration() ${a.reason}: ${a.message}`);return{target:a.target,mountedDocumentId:o}}#ve(e){return e&&typeof e=="object"&&"value"in e?e.value:e}#ye(){const e=this.config.documents.find(n=>n.type===Fr),t=this.#m("upgradeToCollaboration").documents.find(n=>n.id===e.id)?.getEditor?.();if(!t)throw new Error("SuperDoc: source editor not yet created β wait for the ready event before upgrading");return t}addSharedUser(e){this.#R("addSharedUser");const t=Hc({actor:e});t&&this.users.some(n=>Hc({actor:n})===t)||this.users.push(e)}removeSharedUser(e){this.#R("removeSharedUser");const t=typeof e=="string"?Xv(e):"",n=typeof e=="string"?`email:${t}`:Hc({actor:e});this.users=this.users.filter(r=>{const o=Hc({actor:r});return n?o!==n:t?Xv(r.email)!==t:!0})}onContentError({error:e,editor:t}){const n=t.options?.documentId,r=this.#m("onContentError").documents.find(i=>i.id===n),o=typeof r?.id=="string"?r.id:typeof n=="string"?n:"";this.config.onContentError?.({error:e,editor:t,documentId:o,file:r?.data})}broadcastPdfDocumentReady(){this.emit("pdf:document-ready")}broadcastReady(){this.readyEditors===this.requiredNumberOfEditors&&this.emit("ready",{superdoc:this})}broadcastEditorBeforeCreate(e){this.emit("editorBeforeCreate",{editor:M4(e)})}broadcastEditorCreate(e){this.readyEditors++,this.broadcastReady(),this.#be(e),this.emit("editorCreate",{editor:M4(e)})}broadcastSourceComplete(){this.emit("source:complete")}broadcastSourceSignalsComplete(){this.emit("source:signals-complete")}#Z;#be(e){if(!e||typeof e.on!="function"||this.#Z.has(e))return;this.#Z.add(e),e.on("fonts-changed",n=>{this.#ie(e)&&this.#V(n)});const t=(e.documentRenderer??e.presentationEditor)?.getLastFontsChangedPayload?.();t&&this.#ie(e)&&this.#V(t)}#ie(e){return!this.activeEditor||e===this.activeEditor}#Q;#V(e){this.#Q=e,this.emit("fonts-changed",e)}broadcastEditorDestroy(){this.emit("editorDestroy")}broadcastSidebarToggle(e){this.emit("sidebar-toggle",e)}#we(){Array.isArray(this.config.editorExtensions)&&this.config.editorExtensions.length>0&&console.warn("[SuperDoc] `editorExtensions` is a legacy ProseMirror concept and is ignored by superdoc@2. Use `extensions` with `defineSuperDocExtension`; legacy ProseMirror extensions (Node.create, Mark.create, addPmPlugins, custom schema) do not run in v2.")}#C(...e){(console.debug?console.debug:console.log)("π¦ π¦ΈββοΈ [superdoc]",...e)}#j;get fonts(){return this.#j||(this.#j={getReport:()=>Gi(this.activeEditor)?.getReport()??[],getMissingFonts:()=>Gi(this.activeEditor)?.getMissingFonts()??[],getDocumentFontOptions:()=>Gi(this.activeEditor)?.getDocumentFontOptions()??[],getFontFamilyOptions:()=>Gi(this.activeEditor)?.getFontFamilyOptions()??[],getDocumentFonts:()=>Gi(this.activeEditor)?.getDocumentFonts()??[],onReport:e=>{const t=this.activeEditor,n=t?Gi(t)?.getLastFontsChangedPayload?.()??null:this.#Q??null;return n&&e(n),this.on("fonts-changed",e),()=>this.off("fonts-changed",e)},map:e=>{const t=Gi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.map requires an active editor");t.map(e)},unmap:e=>{const t=Gi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.unmap requires an active editor");t.unmap(e)},add:e=>{const t=Gi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.add requires an active editor");t.add(e)},preload:e=>{const t=Gi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.preload requires an active editor");return t.preload(e)}}),this.#j}#U(){const e=this.activeEditor!==null;this.#se(),this.activeEditor=null,this.toolbar?.setActiveEditor?this.toolbar.setActiveEditor(null):this.toolbar&&(this.toolbar.activeEditor=null),e&&this.emit("active-editor-change")}#M;#se(){if(this.#M){try{this.#M()}catch{}this.#M=null}}#Ce(e){this.#se();const t=Gi(e);if(!t?.onChanged)return;const n=t.getLastFontsChangedPayload?.();n&&this.#V(n),this.#M=t.onChanged(r=>this.#V(r))}#ke(e,t){this.#w=!0;try{if(e===null){this.#U();return}this.#u.get(e)?.kind==="v2"&&Zo(t)?this.#ae(t):this.#U()}finally{this.#w=!1}}#ae(e){if(Zo(e)){!this.#w&&this.#u.getActive()&&this.#u.setActive(null,"set-active-v2-facade");const t=this.activeEditor;this.activeEditor=e,this.#Ce(e),this.toolbar?.setActiveEditor?.(e),t!==this.activeEditor&&this.emit("active-editor-change");return}this.#U()}setActiveEditor(e){this.#ae(e)}getV2FeatureMatrix(){return[{feature:"source.docx-bytes",status:"supported",reason:"SuperDoc normalizes File/Blob/ArrayBuffer/Uint8Array DOCX inputs for the separate DOCX Engine dependency"},{feature:"source.url",status:"supported",reason:"shell-owned source normalization resolves URL-backed DOCX inputs before opening the injected v2 editor"},{feature:"source.blank",status:"supported",reason:"shell-owned blank-document seeding resolves to DOCX bytes before mounting the injected v2 editor"},{feature:"execution.browser-worker",status:"supported",reason:"the shipped public v2 shell opens DOCX documents through the browser-worker path by default when collaboration is not active"},{feature:"distribution.cdn-iife",status:"supported",reason:"the CDN/IIFE distribution ships the public bundle plus the emitted v2 browser-worker asset and opens DOCX documents through the worker-backed v2 runtime"},{feature:"docx.open-render",status:"supported",reason:"superdoc@2 opens and renders DOCX documents through its DOCX Engine dependency"},{feature:"docx.review-handles",status:"supported",reason:"Comment/tracked-change list + decide via v2 host handles"},{feature:"shell.toolbar",status:"supported",reason:"new SuperDoc({ toolbar }) mounts the rendered built-in toolbar shell and the superdoc.toolbar handle, both backed by the V2 command controller and the internal compatibility catalog. Explicit item-level limits stay fail-closed in the shared command matrix (for example search replace and copyFormat)."},{feature:"shell.rich-formatting",status:"supported",reason:"Rich inline, paragraph, and list formatting route through the V2 command controller and public Document API (format.* / styles.* / lists.*): bold, italic, underline, strikethrough, font family/size, text/highlight color, alignment, line spacing, linked styles, bullet/numbered lists, indent, and clear formatting."},{feature:"shell.comments-sidebar",status:"supported",reason:"ui-phase3-002: v2 comments adapter routes create/reply/edit/resolve/delete through V2EditorHost.dispatch"},{feature:"shell.comments-sidebar.reopen",status:"supported",reason:'ui-phase3-002: v2 comments sidebar reopens resolved threads through the v2 comments adapter (activeEditor.doc.comments.patch({ status: "active" }))'},{feature:"shell.tracked-change-sidebar",status:"supported",reason:"SD-3722: v2 tracked-change adapter lists and decides exact body, header/footer-part, and note targets"},{feature:"shell.tracked-change-sidebar.bulk",status:"supported",reason:"SD-4039/SD-4040: the shipped v2 command posture exposes all-story Accept All and Reject All through the canonical doc.trackChanges.decide({ target: { kind: 'all' } }) mutation"},{feature:"shell.tracked-change-sidebar.non-body",status:"supported",reason:"SD-3722: public v2 shell hydrates and targets header/footer-part and note tracked changes"},{feature:"shell.comments-sidebar.persistence",status:"supported",reason:"ui-phase3-004: comment create/reply/edit/resolve/delete persist through SuperDoc.export() β re-mount via the v2 host save bridge"},{feature:"shell.tracked-change-sidebar.persistence",status:"supported",reason:"ui-phase3-004: tracked-change accept/reject persist through SuperDoc.export() β re-mount via the v2 host save bridge"},{feature:"shell.comments-sidebar.author-required",status:"supported",reason:"ui-phase3-004: v2 comments adapter surfaces commentCommandsReason=author-required from the host capability matrix; write controls disable and forced dispatch reports ok:false"},{feature:"shell.find-replace",status:"supported",reason:"Ctrl/Cmd+F opens the SuperDoc find/replace surface in v2; find/navigation/replace/replaceAll route through the single host search session (host.search) via ui.search, with replace failing closed in viewing/read-only mode"},{feature:"shell.ai-writer",status:"supported",reason:"built-in toolbar renders the modules.ai-gated AI writer and applies generated text through the public Document API facade"},{feature:"shell.collaboration",status:"supported",reason:"v2 single-doc y-websocket collaboration is wired through document.v2Collaboration, including collaboration-ready, awareness-update, and locked event bridges; arbitrary external { ydoc, provider } adapters remain unsupported"},{feature:"shell.context-menu",status:"not-shipped",reason:"context-menu-omitted: public v2 shell disables the legacy context menu"},{feature:"shell.page-metrics",status:"supported",reason:"ui-phase4-001: v2 page metrics snapshot (editorVersion: 2, documentId, renderEpoch, layoutGeneration, zoom, pages[], capabilities) available via superdoc.activeEditor.pageMetrics.{ getSnapshot, subscribe, setZoom, scrollToPage, revealBodyTarget, pageIndexForBodyTarget }"},{feature:"shell.zoom",status:"supported",reason:"ui-phase4-001: SuperDoc.setZoom routes to V2EditorHost.setZoom in v2 mode; single CSS-transform wrapper applies scale to the painted document, page metrics viewport coords scale with the same zoom value"},{feature:"shell.ruler-page-margins",status:"supported",reason:"ui-phase4-002: v2 ruler renders against the V2PageMetricsSnapshot and dispatches margin drags through a narrow v2 page-layout bridge (`activeEditor.pageLayout.setMargins(...)`) backed by `doc.sections.setPageMargins(...)`. The v2 page metrics snapshot now reports `capabilities.marginEdit = { supported: true }`"},{feature:"shell.custom-extensions",status:"supported",reason:"superdoc@2 supports customer extensions through `extensions` + `defineSuperDocExtension`; command execution and diagnostics are exposed through the narrow `activeEditor.extensions` facet. Legacy ProseMirror `editorExtensions` are ignored in v2."},{feature:"pdf.viewer",status:"supported",reason:"editorVersion ignored for PDF documents"},{feature:"html.viewer",status:"supported",reason:"editorVersion ignored for HTML documents"}]}get v2(){return this.editorVersion!==2?null:{version:2,featureMatrix:this.getV2FeatureMatrix()}}registerEditorRuntime(e){this.#u.register(e)}unregisterEditorRuntime(e){return this.#u.unregister(e)}getActiveRuntime(){return this.#u.getActive()}setActiveRuntime(e,t){this.#u.setActive(e,t)}resolveRuntimeFromEventTarget(e){return this.#u.resolveFromEventTarget(e)}activateRuntimeFromEventTarget(e,t){const n=this.#u.resolveFromEventTarget(e);return n?(this.#u.setActive(n.id,t),!0):!1}toggleRuler(){const e=this.#m("toggleRuler");this.config.rulers=!this.config.rulers,e.documents.forEach(t=>{t.rulers=this.config.rulers}),this.toolbar?.updateToolbarState?.()}canPerformPermission({permission:e,role:t=this.config.role,isInternal:n=this.config.isInternal,comment:r=null,trackedChange:o=null}={}){if(!e)return!1;let i=r??o?.comment??null;const s=o?.commentId||o?.id;if(!i&&s&&this.commentsStore?.getComment){const a=this.commentsStore.getComment(s),l=a?.getValues;i=typeof l=="function"?l.call(a):a}return aa(e,t,n,{superdoc:this,currentUser:this.config.user,comment:i??null,trackedChange:o??null})}#Se(){const e=this.config.modules?.toolbar,t=e&&typeof e=="object"?e:{},n=this.#p.toolbar;this.toolbarElement=n.container??void 0;const r=this.config.ui,o=typeof r=="object"&&r!==null&&r.toolbar!==void 0;if(!(n.enabled&&(n.container||e===!0||e!=null&&typeof e=="object"||o))){this.toolbar=null;return}try{this.toolbar=tV({...t,...n.options,selector:this.toolbarElement,superdoc:this,editor:this.activeEditor,role:this.config.role,isDev:this.isDev,documentMode:this.config.documentMode,groups:n.options.groups,toolbarGroups:n.options.toolbarGroups,icons:n.options.icons,texts:n.options.texts,uiDisplayFallbackFont:this.config.uiDisplayFallbackFont})}catch(i){console.warn("[SuperDoc] built-in toolbar mount failed",i),this.toolbar=null}}addCommentsList(e){!this.config?.modules?.comments||this.config.role==="viewer"||(e&&(this.config.modules.comments.element=e),this.commentsList=new qR(this.config.modules?.comments,this),this.config.onCommentsListChange&&this.config.onCommentsListChange({isRendered:!0}),this.emit("comments-list-change",{isRendered:!0}))}removeCommentsList(){this.commentsList&&(this.commentsList.close(),this.commentsList=null,this.config.onCommentsListChange&&this.config.onCommentsListChange({isRendered:!1}),this.emit("comments-list-change",{isRendered:!1}))}scrollToComment(e,t={}){if(!this.config?.modules?.comments||!e||typeof e!="string")return!1;const n=this.element||document,r=globalThis.CSS?.escape?globalThis.CSS.escape(e):e.replace(/"/g,'\\"'),o=n.querySelector(`[data-comment-ids*="${r}"]`);if(!o)return!1;const{behavior:i="smooth",block:s="start"}=t??{};return o.scrollIntoView({behavior:i,block:s}),this.commentsStore?.setActiveComment?.(this,e),!0}async navigateTo(e){const t=this.superdocStore?.documents;if(!t?.length)return!1;const n=t[0].getDocumentRuntime?.();return n?.navigateTo?n.navigateTo(e):!1}async scrollToElement(e){const t=this.superdocStore?.documents;if(!t?.length)return!1;const n=t[0].getDocumentRuntime?.();return n?.scrollToElement?n.scrollToElement(e):!1}setDisableContextMenu(e=!0){if(!e&&this.#p.contextMenu.suppressed)return;const t=!!e;this.config.disableContextMenu!==t&&(this.config.disableContextMenu=t,this.superdocStore?.documents?.forEach(n=>{const r=n.getDocumentRuntime?.();r?.setContextMenuDisabled&&r.setContextMenuDisabled(t);const o=n.getEditor?.();o?.setOptions&&o.setOptions({disableContextMenu:t})}))}setShowBookmarks(e=!0){const t=!!e,n=this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};n.showBookmarks!==t&&(n.showBookmarks=t,this.superdocStore?.documents?.forEach(r=>{r.getDocumentRuntime?.()?.setShowBookmarks?.(t)}))}setShowFormattingMarks(e=!0){const t=!!e,n=this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};n.showFormattingMarks!==t&&(n.showFormattingMarks=t,this.superdocStore?.documents?.forEach(r=>{r.getDocumentRuntime?.()?.setShowFormattingMarks?.(t)}),this.emit("formatting-marks-change",{showFormattingMarks:t,superdoc:this}),this.toolbar?.updateToolbarState?.())}toggleFormattingMarks(){const e=!!this.config.layoutEngineOptions?.showFormattingMarks;this.setShowFormattingMarks(!e)}setDocumentMode(e){if(!e)return;this.#R("setDocumentMode"),e=e.toLowerCase(),this.config.documentMode=e,this.#ue();const t={viewing:()=>this.#ce(),editing:()=>this.#_e(),suggesting:()=>this.#le()};t[e]&&(t[e](),this.emit("document-mode-change",{documentMode:e}))}#J(e,t){const n=typeof e.id=="string"&&e.id.length>0?e.id:null;if(n){const i=this.#u.getAllByDocumentId(n);if(i.length>0){for(const s of i)s.setDocumentMode(t);return}}const r=typeof e.getDocumentRuntime=="function"?e.getDocumentRuntime():null;if(typeof r?.setDocumentMode=="function"){r.setDocumentMode(t);return}const o=typeof e.getEditor=="function"?e.getEditor():null;o&&typeof o.setDocumentMode=="function"&&o.setDocumentMode(t)}setTrackedChangesPreferences(e){const t=e&&Object.keys(e).length?{...e}:void 0;this.config.layoutEngineOptions||(this.config.layoutEngineOptions={}),this.config.layoutEngineOptions.trackedChanges=t,this.superdocStore?.documents?.forEach(n=>{const r=typeof n.getDocumentRuntime=="function"?n.getDocumentRuntime():null;r?.setTrackedChangesOverrides&&r.setTrackedChangesOverrides(t)})}#_e(){if(this.config.role!=="editor")return this.#le();const e=this.#m("setDocumentMode");if(e.documents.length>0){const t=e.documents[0]?.getEditor();t&&this.setActiveEditor(t)}this.setTrackedChangesPreferences({mode:"review",enabled:!0}),e.documents.forEach(t=>{t.restoreComments?.(),this.#J(t,"editing")})}#le(){if(!["editor","suggester"].includes(this.config.role??""))return this.#ce();const e=this.#m("setDocumentMode");if(e.documents.length>0){const t=e.documents[0]?.getEditor();t&&this.setActiveEditor(t)}this.setTrackedChangesPreferences({mode:"review",enabled:!0}),e.documents.forEach(t=>{t.restoreComments?.(),this.#J(t,"suggesting")})}#ce(){const e=this.#m("setDocumentMode");this.toolbar?.setActiveEditor?this.toolbar.setActiveEditor(null):this.toolbar&&(this.toolbar.activeEditor=null);const t=this.config.comments?.visible===!0,n=this.config.trackChanges?.visible===!0;this.setTrackedChangesPreferences(n?{mode:"review",enabled:!0}:{mode:"original",enabled:!0}),!t&&!n&&this.commentsStore?.clearEditorCommentPositions?.(),e.documents.forEach(r=>{t||n?r.restoreComments?.():r.removeComments?.(),this.#J(r,"viewing")})}#ue(){const e=this.config.comments?.visible===!0,t=this.config.trackChanges?.visible===!0,n=this.config.documentMode==="viewing",r=e||t;this.commentsStore?.setViewingVisibility&&this.commentsStore.setViewingVisibility({documentMode:this.config.documentMode,commentsVisible:e,trackChangesVisible:t});const o=this.superdocStore?.documents;Array.isArray(o)&&o.length>0&&o.forEach(i=>{const s=typeof i.getDocumentRuntime=="function"?i.getDocumentRuntime():null;s?.setViewingCommentOptions&&s.setViewingCommentOptions({emitCommentPositionsInViewing:n&&r,enableCommentsInViewing:n&&e})})}search(e){const t=this.activeEditor?.commands,n=t?.search;if(typeof n=="function")return n.call(t,e,{searchModel:"visible"})}goToSearchResult(e){const t=this.activeEditor?.commands,n=t?.goToSearchResult;if(typeof n=="function")return!!n.call(t,e)}getZoom(){return this.superdocStore?.activeZoom??100}setZoom(e){if(typeof e!="number"||!Number.isFinite(e)||e<=0){console.warn("[SuperDoc] setZoom expects a positive number representing percentage");return}if(!this.superdocStore){console.warn("[SuperDoc] setZoom called before initialization; use config.zoom.initial for the starting zoom");return}this.superdocStore.activeZoom=e,this.superdocStore.zoomMode="manual",this.emit("zoomChange",{zoom:e,mode:"manual"})}setZoomMode(e){if(e!=="manual"&&e!=="fit-width"){console.warn("[SuperDoc] setZoomMode expects 'manual' or 'fit-width'");return}if(!this.superdocStore){console.warn("[SuperDoc] setZoomMode called before initialization; use config.zoom.mode for the starting mode");return}this.superdocStore.zoomMode!==e&&(this.superdocStore.zoomMode=e,this.emit("zoomChange",{zoom:this.getZoom(),mode:e}))}getZoomState(){const e=xk(this.config.zoom?.fitWidth);return{mode:this.superdocStore?.zoomMode??"manual",value:this.superdocStore?.activeZoom??100,fitZoom:this.superdocStore?.viewportMetrics?.fitZoom??null,min:e.min,max:e.max}}getViewportMetrics(){return this.superdocStore?.viewportMetrics??null}getMeasurementUnit(){return this.superdocStore?.measurementUnit??"in"}setMeasurementUnit(e){if(e!=="in"&&e!=="cm"){console.warn("[SuperDoc] setMeasurementUnit expects 'in' or 'cm'");return}if(!this.superdocStore){console.warn("[SuperDoc] setMeasurementUnit called before initialization; use config.measurementUnit for the starting unit");return}this.superdocStore.measurementUnit!==e&&(this.superdocStore.measurementUnit=e,this.emit("measurement-unit-change",{unit:e}))}setLocked(e=!0){const t=this.activeEditor;if(Zo(t)&&typeof t.lock?.setLocked=="function"){t.lock.setLocked(e,e?{...this.user}:null);const n=t.lock.getSnapshot?.();n&&this.#v(!!n.isLocked,this.#F(n.lockedBy??null));return}this.config.documents.forEach(n=>{const r=n.ydoc;if(!r)return;const o=r.getMap("meta");r.transact(()=>{o.set("locked",e),e?o.set("lockedBy",this.user):o.delete("lockedBy")})}),this.#v(e,e?this.user:null)}getHTML(e={}){const t=[];return this.#m("getHTML").documents.forEach(n=>{const r=n.getEditor?.();r&&t.push(r)}),t.map(n=>n.getHTML(e))}lockSuperdoc(e=!1,t=null){this.#v(e,t)}async export({exportType:e=["docx"],commentsType:t="external",exportedName:n,additionalFiles:r=[],additionalFileNames:o=[],isFinalDoc:i=!1,triggerDownload:s=!0,fieldsHighlightColor:a=null}={}){const l=b_(n||this.config.title),c=await this.exportEditorsToDOCX({commentsType:t,isFinalDoc:i,fieldsHighlightColor:a}),u=[...r],d=[...o];if(e.includes("docx")&&c.forEach(g=>{u.push(g),d.push(`${l}.docx`)}),u.length===1)return s?y_(u[0],l,e[0]):u[0];const h=await pj(u,d);return s?y_(h,l,"zip"):h}async replaceFile(e){const t=this.activeEditor;if(Zo(t)&&typeof t.replaceFile=="function"){const r=await t.replaceFile(e),o=r&&typeof r=="object"?r.state:null;return(o===null||o==="review-ready"||o==="editing-ready")&&(this.#oe(t,e),this.emit("document-replaced",{editor:t,host:t?.host})),r}const n=t&&!Zo(t)?t.replaceFile:null;if(typeof n=="function"){const r=await n.call(t,e),o=r&&typeof r=="object"?r.state:void 0;return(o==null||o==="review-ready"||o==="editing-ready")&&(this.#oe(t,e),this.emit("document-replaced",{editor:t,host:t?.host})),r}throw new Error("SuperDoc: replaceFile is unavailable for the active editor")}async exportEditorsToDOCX({commentsType:e,isFinalDoc:t,fieldsHighlightColor:n}={}){const r=this.config?.modules?.comments!==!1;let o,i=!1;const s=()=>(i||(i=!0,e==="clean"?o=[]:r&&this.commentsStore&&typeof this.commentsStore.translateCommentsForExport=="function"&&(o=this.commentsStore.translateCommentsForExport(),Array.isArray(o)||(o=[]))),o),a=new WeakSet,l=c=>{"editor"in c&&c.error&&typeof c.error=="object"&&a.add(c.error)};this.on("exception",l);try{const c=this.#m("exportEditorsToDOCX").documents.map(async u=>{if(!u||u.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")return null;const d=typeof u.getEditor=="function"?u.getEditor():null,h=()=>!u.data||u.data.type&&u.data.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?null:u.data;if(!d||typeof d.exportDocx!="function")return h();const g=d.editorVersion===2;try{const p=await d.exportDocx(g?{isFinalDoc:t,commentsType:e,fieldsHighlightColor:n}:{isFinalDoc:t,comments:s(),commentsType:e,fieldsHighlightColor:n});if(p)return p}catch(p){if((!p||typeof p!="object"||!a.has(p))&&this.emit("exception",{error:p,document:u}),g&&(e==="clean"||bj(p)))throw p}return h()});return(await Promise.all(c)).filter(u=>u!=null)}finally{this.off("exception",l)}}async#Ae(){this.#C("π¦ [superdoc] Triggering collaboration saves");const e=this.#m("save");return new Promise(t=>{e.documents.forEach((n,r)=>{if(this.#C(`Before reset - Doc ${r}: pending = ${this.pendingCollaborationSaves}`),this.pendingCollaborationSaves=0,n.ydoc){this.pendingCollaborationSaves++,this.#C(`After increment - Doc ${r}: pending = ${this.pendingCollaborationSaves}`);const o=n.ydoc.getMap("meta");o.observe(i=>{i.changes.keys.has("immediate-save-finished")&&(this.pendingCollaborationSaves--,this.pendingCollaborationSaves<=0&&t())}),o.set("immediate-save",!0)}}),this.#C(`FINAL pending = ${this.pendingCollaborationSaves}, but we have ${e.documents.filter(n=>n.ydoc).length} docs!`)})}async save(){const e=[this.#Ae()];this.#C("π¦ [superdoc] Saving superdoc"),await Promise.all(e),this.#C("π¦ [superdoc] Save complete")}#Ie(e,t){const n=e.provider;n&&n!==this.provider&&!t.some(o=>o.provider===n)&&(n.disconnect?.(),n.destroy?.());const r=e.ydoc;r&&r!==this.ydoc&&!t.some(o=>o.ydoc===r)&&r.destroy?.()}#de(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null);const e=this.config;e.socket?.cancelWebsocketRetry?.(),e.socket?.disconnect(),e.socket?.destroy(),this.ydoc?.destroy(),this.provider?.disconnect?.(),this.provider?.destroy?.(),e.documents.forEach(t=>{t.provider?.disconnect?.(),t.provider?.destroy?.(),t.ydoc?.destroy()})}openSurface(e){return this.#g.open(e)}closeSurface(e){this.#g.close(e)}async removeDocument(e){const t=typeof e=="string"?e:String(e??"");if(!t)return!1;const n=this.#m("removeDocument"),r=this.activeEditor,o=v2(r);for(const s of this.#u.getAllByDocumentId(t))this.#u.unregister(s.id);o===t&&r!==null&&this.#U();const i=n.removeDocument(t);return i?(this.#Ie(i,n.documents),await It(),!0):!1}destroy(){this.#t=!0,this.#h?.removeEventListener("click",this.#f,!0),this.#h=null,this.#e&&(this.#e(),this.#e=null),this.#g&&this.#g.destroy(),this.toolbar?.destroy?.(),this.app&&(this.#C("[superdoc] Unmounting app"),this.superdocStore?.reset(),this.app.unmount(),this.removeAllListeners(),delete this.app.config.globalProperties.$config,delete this.app.config.globalProperties.$superdoc),this.#c?.destroy(),this.#de(),this.#y?.(),this.#y=null,this.#u.clear(),this.#d&&(this.#d.remove(),this.#d=null)}focus(e={}){const t=this.getActiveRuntime();if(t?.getCapabilities().lifecycle.canFocus){t.focus(e).catch(n=>{console.warn("[SuperDoc] active editor runtime focus failed",n)});return}this.activeEditor?Zo(this.activeEditor)?this.activeEditor.focus?.(e):this.activeEditor.focus?.():this.#m("focus").documents.find(n=>{const r=n.getEditor?.();return r?(Zo(r)?r.focus?.(e):r.focus?.(),!0):!1})}setHighContrastMode(e){this.activeEditor&&(this.activeEditor.setHighContrastMode?.(e),this.highContrastModeStore?.setHighContrastMode(e))}};Lt();var TA="__SUPERDOC_V2_BROWSER_RUNTIME__";function Cj(e=globalThis){const t=e[TA];return t&&typeof t=="object"?t:null}function kj(e={},t=globalThis){const n=Cj(t)??{},r={...n,...e,vue:e.vue??n.vue??d6};return t[TA]=r,r}kj();var Sj={action:"--sd-ui-action",actionHover:"--sd-ui-action-hover",actionText:"--sd-ui-action-text",bg:"--sd-ui-bg",hoverBg:"--sd-ui-hover-bg",activeBg:"--sd-ui-active-bg",disabledBg:"--sd-ui-disabled-bg",text:"--sd-ui-text",textMuted:"--sd-ui-text-muted",textDisabled:"--sd-ui-text-disabled",border:"--sd-ui-border"},_j=0;function xA(e){const{name:t,font:n,radius:r,shadow:o,colors:i,vars:s}=e,a=`sd-theme-${(t?t.replace(/[^a-zA-Z0-9-_]/g,"-"):null)||`custom-${++_j}`}`,l=[];if(i)for(const[c,u]of Object.entries(i)){if(u==null)continue;const d=Sj[c];d&&l.push(` ${d}: ${u};`)}if(n!=null&&l.push(` --sd-ui-font-family: ${n};`),r!=null&&l.push(` --sd-ui-radius: ${r};`),o!=null&&l.push(` --sd-ui-shadow: ${o};`),s)for(const[c,u]of Object.entries(s))u!=null&&l.push(` ${c}: ${u};`);return{className:a,css:l.length>0?`.${a} {
|
|
106
106
|
${l.join(`
|
|
107
107
|
`)}
|
|
108
|
-
}`:""}}function Aj(e,t){if(typeof document>"u"||!t)return;let n=document.querySelector(`[data-sd-theme="${e}"]`);n||(n=document.createElement("style"),n.setAttribute("data-sd-theme",e),document.head.appendChild(n)),n.textContent=t}function Ij(e){const{className:t,css:n}=xA(e);return Aj(t,n),t}function Ej(e){return xA(e)}function Tj(e){if(!e||typeof e!="object")throw new Error("defineSuperDocExtension requires an extension object.");if(typeof e.id!="string"||e.id.length===0)throw new Error("defineSuperDocExtension requires a non-empty string `id`.");if(typeof e.activate!="function")throw new Error(`defineSuperDocExtension("${e.id}") requires an \`activate(ctx)\` function.`);if(e.storage!==void 0&&typeof e.storage!="function")throw new Error(`defineSuperDocExtension("${e.id}") \`storage\` must be a function returning the initial storage object.`);return e}var xj=od({BlankDOCX:()=>lk,DOCX:()=>Fr,HTML:()=>tp,PDF:()=>Ol,SuperDoc:()=>_m,buildTheme:()=>Ej,compareVersions:()=>b6,createTheme:()=>Ij,defineSuperDocExtension:()=>Tj,getFileObject:()=>Zv}),Rj="SUPERDOC_ENGINE_CDN_BASE_URL",RA=Symbol.for("superdoc.docx-engine.cdn-load-state"),Am="superdocDocxEngineStatus";function Mj(e,t,n=null){const r=e?.[Rj],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return Lj(o);if(!t)throw new Error("SuperDoc: the CDN build is missing its exact DOCX Engine version");return`https://cdn.jsdelivr.net/npm/@superdoc/docx-engine@${t}`}function Lj(e){const t=e.trim().replace(/\/+$/,""),n=t.match(/^([a-z][a-z\d+.-]*):/iu)?.[1]?.toLowerCase();if(n&&n!=="http"&&n!=="https")throw new TypeError(`SuperDoc: unsupported DOCX Engine CDN URL scheme ${n}:`);return t}function Pj({engineVersion:e,buildBaseUrl:t}){I8(()=>{const n=Mj(globalThis,e,t),r=globalThis[RA],o=r instanceof Map?r:new Map;if(globalThis[RA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),Dj(`${n}/dist-cdn/style.css`)]).then(([s])=>s);o.set(n,i),i.catch(()=>{o.get(n)===i&&o.delete(n)})}return o.get(n)})}function Dj(e){if(typeof document>"u")return Promise.resolve();const t=new URL(e,document.baseURI).href,n=Array.from(document.querySelectorAll('link[rel~="stylesheet"]')).find(o=>o.href===t);if(n?.sheet||n?.dataset[Am]==="loaded")return Promise.resolve();const r=n?.dataset[Am]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const c=(g,p)=>{a||(a=!0,l?.disconnect(),s.dataset[Am]=g,p())},u=()=>c("loaded",o),d=()=>c("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||c("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",u,{once:!0}),s.addEventListener("error",d,{once:!0}),typeof globalThis.MutationObserver=="function"&&(l=new globalThis.MutationObserver(h),l.observe(document.head,{childList:!0})),r||(s.rel="stylesheet",s.href=t,s.dataset.superdocDocxEngine="true",s.dataset[Am]="loading",document.head.appendChild(s))})}Pj({engineVersion:"0.3.0-next.
|
|
108
|
+
}`:""}}function Aj(e,t){if(typeof document>"u"||!t)return;let n=document.querySelector(`[data-sd-theme="${e}"]`);n||(n=document.createElement("style"),n.setAttribute("data-sd-theme",e),document.head.appendChild(n)),n.textContent=t}function Ij(e){const{className:t,css:n}=xA(e);return Aj(t,n),t}function Ej(e){return xA(e)}function Tj(e){if(!e||typeof e!="object")throw new Error("defineSuperDocExtension requires an extension object.");if(typeof e.id!="string"||e.id.length===0)throw new Error("defineSuperDocExtension requires a non-empty string `id`.");if(typeof e.activate!="function")throw new Error(`defineSuperDocExtension("${e.id}") requires an \`activate(ctx)\` function.`);if(e.storage!==void 0&&typeof e.storage!="function")throw new Error(`defineSuperDocExtension("${e.id}") \`storage\` must be a function returning the initial storage object.`);return e}var xj=od({BlankDOCX:()=>lk,DOCX:()=>Fr,HTML:()=>tp,PDF:()=>Ol,SuperDoc:()=>_m,buildTheme:()=>Ej,compareVersions:()=>b6,createTheme:()=>Ij,defineSuperDocExtension:()=>Tj,getFileObject:()=>Zv}),Rj="SUPERDOC_ENGINE_CDN_BASE_URL",RA=Symbol.for("superdoc.docx-engine.cdn-load-state"),Am="superdocDocxEngineStatus";function Mj(e,t,n=null){const r=e?.[Rj],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return Lj(o);if(!t)throw new Error("SuperDoc: the CDN build is missing its exact DOCX Engine version");return`https://cdn.jsdelivr.net/npm/@superdoc/docx-engine@${t}`}function Lj(e){const t=e.trim().replace(/\/+$/,""),n=t.match(/^([a-z][a-z\d+.-]*):/iu)?.[1]?.toLowerCase();if(n&&n!=="http"&&n!=="https")throw new TypeError(`SuperDoc: unsupported DOCX Engine CDN URL scheme ${n}:`);return t}function Pj({engineVersion:e,buildBaseUrl:t}){I8(()=>{const n=Mj(globalThis,e,t),r=globalThis[RA],o=r instanceof Map?r:new Map;if(globalThis[RA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),Dj(`${n}/dist-cdn/style.css`)]).then(([s])=>s);o.set(n,i),i.catch(()=>{o.get(n)===i&&o.delete(n)})}return o.get(n)})}function Dj(e){if(typeof document>"u")return Promise.resolve();const t=new URL(e,document.baseURI).href,n=Array.from(document.querySelectorAll('link[rel~="stylesheet"]')).find(o=>o.href===t);if(n?.sheet||n?.dataset[Am]==="loaded")return Promise.resolve();const r=n?.dataset[Am]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const c=(g,p)=>{a||(a=!0,l?.disconnect(),s.dataset[Am]=g,p())},u=()=>c("loaded",o),d=()=>c("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||c("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",u,{once:!0}),s.addEventListener("error",d,{once:!0}),typeof globalThis.MutationObserver=="function"&&(l=new globalThis.MutationObserver(h),l.observe(document.head,{childList:!0})),r||(s.rel="stylesheet",s.href=t,s.dataset.superdocDocxEngine="true",s.dataset[Am]="loading",document.head.appendChild(s))})}Pj({engineVersion:"0.3.0-next.12",buildBaseUrl:null});for(const[e,t]of Object.entries(xj))e==="SuperDoc"||e==="default"||Object.prototype.hasOwnProperty.call(_m,e)||(_m[e]=t);var Oj=_m;return Oj})();
|