superdoc 2.0.0-next.50 → 2.0.0-next.51

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.
@@ -99,10 +99,10 @@ js: import "konva/skia-backend";
99
99
  `,t4=()=>{if(typeof document>"u")throw new Error(cP)},Vi=class HA{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 HA(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 u=Math.sqrt(t*t+n*n);l.rotation=n>0?Math.acos(t/u):-Math.acos(t/u),l.scaleX=u,l.scaleY=a/u,l.skewX=(t*r+n*o)/a,l.skewY=0}else if(r!=0||o!=0){const u=Math.sqrt(r*r+o*o);l.rotation=Math.PI/2-(o>0?Math.acos(-r/u):-Math.acos(r/u)),l.scaleX=a/u,l.scaleY=u,l.skewX=0,l.skewY=(t*r+n*o)/a}return l.rotation=Ie._getRotation(l.rotation),l}},uP="[object Array]",dP="[object Number]",fP="[object String]",hP="[object Boolean]",pP=Math.PI/180,mP=180/Math.PI,nf="#",gP="",vP="0",yP="Konva warning: ",n4="Konva error: ",bP="rgb(",r0={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]},wP=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,kp=[],rf=null,CP=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(e){setTimeout(e,16)};const Ie={_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)===uP},_isNumber(e){return Object.prototype.toString.call(e)===dP&&!isNaN(e)&&isFinite(e)},_isString(e){return Object.prototype.toString.call(e)===fP},_isBoolean(e){return Object.prototype.toString.call(e)===hP},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){kp.push(e),kp.length===1&&CP(function(){const t=kp;kp=[],t.forEach(function(n){n()})})},createCanvasElement(){t4();const e=document.createElement("canvas");try{e.style=e.style||{}}catch{}return e},createImageElement(){return t4(),document.createElement("img")},_isInDocument(e){for(;e=e.parentNode;)if(e==document)return!0;return!1},_urlToImage(e,t){const n=Ie.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(nf,gP);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=vP+e;return nf+e},isCanvasFarblingActive(){if(rf!==null)return rf;if(typeof document>"u")return rf=!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 rf=r,this.releaseCanvas(e),rf},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),nf+this._rgbToHex(e,t,n)},getSnappedHexColor(e){const t=this._hexToRgb(e);return nf+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 r0?(t=r0[e],{r:t[0],g:t[1],b:t[2]}):e[0]===nf?this._hexToRgb(e.substring(1)):e.substr(0,4)===bP?(t=wP.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",Ie._namedColorToRBA(e)||Ie._hex3ColorToRGBA(e)||Ie._hex4ColorToRGBA(e)||Ie._hex6ColorToRGBA(e)||Ie._hex8ColorToRGBA(e)||Ie._rgbColorToRGBA(e)||Ie._rgbaColorToRGBA(e)||Ie._hslColorToRGBA(e)},_namedColorToRBA(e){const t=r0[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 u=2*i-s,c=[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=u+(s-u)*6*a:2*a<1?l=s:3*a<2?l=u+(s-u)*(2/3-a)*6:l=u,c[d]=l*255;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[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*pP},radToDeg(e){return e*mP},_degToRad(e){return Ie.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),Ie.degToRad(e)},_radToDeg(e){return Ie.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),Ie.radToDeg(e)},_getRotation(e){return vt.angleDeg?Ie.radToDeg(e):e},_capitalize(e){return e.charAt(0).toUpperCase()+e.slice(1)},throw(e){throw new Error(n4+e)},error(e){console.error(n4+e)},warn(e){vt.showWarnings&&console.warn(yP+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 u=(e-n)*(e-n)+(t-r)*(t-r);if(u==0)s=e,a=t,l=(o-n)*(o-n)+(i-r)*(i-r);else{const c=((o-e)*(n-e)+(i-t)*(r-t))/u;c<0?(s=e,a=t,l=(e-o)*(e-o)+(t-i)*(t-i)):c>1?(s=n,a=r,l=(n-o)*(n-o)+(r-i)*(r-i)):(s=e+c*(n-e),a=t+c*(r-t),l=(s-o)*(s-o)+(a-i)*(a-i))}return[s,a,l]},_getProjectionToLine(e,t,n){const r=Ie.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=Ie._getProjectionToSegment(i.x,i.y,a.x,a.y,e.x,e.y),u=l[0],c=l[1],d=l[2];d<o&&(r.x=u,r.y=c,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=Ie._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||Ie._isElement(e[n]))if(t.configurable)delete e[n];else return null;else if(Ie._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){vt.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,u=0;typeof r=="number"?s=a=l=u=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),u=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-u),e.arc(o+t-u,i+n-u,u,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],u={x:a.x-s.x,y:a.y-s.y},c={x:l.x-a.x,y:l.y-a.y},d=Math.hypot(u.x,u.y),h=Math.hypot(c.x,c.y);let m;typeof o=="number"?m=o:m=i<o.length?o[i]:0,m=r*Math.cos(Math.PI/n)*Math.min(1,m/r*2);const p={x:u.x/d,y:u.y/d},g={x:c.x/h,y:c.y/h},k={x:a.x-p.x*m,y:a.y-p.y*m},w={x:a.x+g.x*m,y:a.y+g.y*m};i===0?e.moveTo(k.x,k.y):e.lineTo(k.x,k.y),e.arcTo(a.x,a.y,w.x,w.y,m)}}};function _P(e){const t=[],n=e.length,r=Ie;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 r4=",",SP="(",kP=")",AP="([",IP="])",EP=";",xP="()",TP="=",o4=["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"],RP=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],MP=100,Ap=null;function i4(){if(Ap!==null)return Ap;try{const e=Ie.createCanvasElement().getContext("2d");return e?!!e&&"filter"in e:(Ap=!1,!1)}catch{return Ap=!1,!1}}var Ip=class{constructor(e){this.canvas=e,vt.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+=xP:Ie._isArray(l[0])?o+=AP+l.join(r4)+IP:(t&&(l=l.map(u=>typeof u=="number"?Math.floor(u):u)),o+=SP+l.join(r4)+kP)):(o+=s.property,e||(o+=TP+s.val)),o+=EP;return o}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,n;t.push(e),n=t.length,n>=MP&&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 u=arguments,c=this._context;u.length===3?c.drawImage(e,t,n):u.length===5?c.drawImage(e,t,n,r,o):u.length===9&&c.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=o4.length,n=this.setAttr,r,o;const i=function(s){let a=e[s],l;e[s]=function(){return o=_P(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(o4[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)}};RP.forEach(function(e){Object.defineProperty(Ip.prototype,e,{get(){return this._context[e]},set(t){this._context[e]=t}})});var LP=class extends Ip{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(),u=a.x*l,c=a.y*l;this.setAttr("shadowColor",o),this.setAttr("shadowBlur",i*Math.min(Math.abs(u),Math.abs(c))),this.setAttr("shadowOffsetX",s.x*u),this.setAttr("shadowOffsetY",s.y*c)}},DP=class extends Ip{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()}}},Ep;function PP(){if(Ep)return Ep;const e=Ie.createCanvasElement(),t=e.getContext("2d");return Ep=(function(){return(vt._global.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)})(),Ie.releaseCanvas(e),Ep}var o0=class{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1,this.pixelRatio=(e||{}).pixelRatio||vt.pixelRatio||PP(),this._canvas=Ie.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 Ie.error("Unable to get data URL. "+r.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},Ga=class extends o0{constructor(e={width:0,height:0,willReadFrequently:!1}){super(e),this.context=new LP(this,{willReadFrequently:e.willReadFrequently}),this.setSize(e.width,e.height)}},i0=class extends o0{constructor(e={width:0,height:0}){super(e),this.hitCanvas=!0,this.context=new DP(this),this.setSize(e.width,e.height)}};const In={get isDragging(){let e=!1;return In._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(e=!0)}),e},justDragged:!1,get node(){let e;return In._dragElements.forEach(t=>{e=t.node}),e},_dragElements:new Map,_drag(e){const t=[];In._dragElements.forEach((n,r)=>{const{node:o}=n,i=o.getStage();i.setPointersPositions(e),n.pointerId===void 0&&(n.pointerId=Ie._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=[];In._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")&&(In.justDragged=!0,vt._mouseListenClick=!1,vt._touchListenClick=!1,vt._pointerListenClick=!1,n.dragStatus="stopped");const i=n.node.getLayer()||n.node instanceof vt.Stage&&n.node;i&&t.indexOf(i)===-1&&t.push(i)}),t.forEach(n=>{n.draw()})},_endDragAfter(e){In._dragElements.forEach((t,n)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:e},!0),t.dragStatus!=="dragging"&&In._dragElements.delete(n)})}};vt.isBrowser&&(window.addEventListener("mouseup",In._endDragBefore,!0),window.addEventListener("touchend",In._endDragBefore,!0),window.addEventListener("touchcancel",In._endDragBefore,!0),window.addEventListener("mousemove",In._drag),window.addEventListener("touchmove",In._drag),window.addEventListener("mouseup",In._endDragAfter,!1),window.addEventListener("touchend",In._endDragAfter,!1),window.addEventListener("touchcancel",In._endDragAfter,!1));function Wa(e){return Ie._isString(e)?'"'+e+'"':Object.prototype.toString.call(e)==="[object Number]"||Ie._isBoolean(e)?e:Object.prototype.toString.call(e)}function s4(e){return e>255?255:e<0?0:Math.round(e)}function dt(){if(vt.isUnminified)return function(e,t){return Ie._isNumber(e)||Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),e}}function xp(e){if(vt.isUnminified)return function(t,n){let r=Ie._isNumber(t),o=Ie._isArray(t)&&t.length==e;return!r&&!o&&Ie.warn(Wa(t)+' is a not valid value for "'+n+'" attribute. The value should be a number or Array<number>('+e+")"),t}}function s0(){if(vt.isUnminified)return function(e,t){return Ie._isNumber(e)||e==="auto"||Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),e}}function jl(){if(vt.isUnminified)return function(e,t){return Ie._isString(e)||Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),e}}function a4(){if(vt.isUnminified)return function(e,t){const n=Ie._isString(e),r=Object.prototype.toString.call(e)==="[object CanvasGradient]"||e&&e.addColorStop;return n||r||Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),e}}function OP(){if(vt.isUnminified)return function(e,t){const n=Int8Array?Object.getPrototypeOf(Int8Array):null;return n&&e instanceof n||(Ie._isArray(e)?e.forEach(function(r){Ie._isNumber(r)||Ie.warn('"'+t+'" attribute has non numeric element '+r+". Make sure that all elements are numbers.")}):Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a array of numbers.')),e}}function ji(){if(vt.isUnminified)return function(e,t){return e===!0||e===!1||Ie.warn(Wa(e)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),e}}function FP(e){if(vt.isUnminified)return function(t,n){return t==null||Ie.isObject(t)||Ie.warn(Wa(t)+' is a not valid value for "'+n+'" attribute. The value should be an object with properties '+e),t}}var of="get",sf="set";const ce={addGetterSetter(e,t,n,r,o){ce.addGetter(e,t,n),ce.addSetter(e,t,r,o),ce.addOverloadedGetterSetter(e,t)},addGetter(e,t,n){const r=of+Ie._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=sf+Ie._capitalize(t);e.prototype[o]||ce.overWriteSetter(e,t,n,r)},overWriteSetter(e,t,n,r){const o=sf+Ie._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=Ie._capitalize,a=of+s(t),l=sf+s(t);e.prototype[a]=function(){const c={};for(let d=0;d<i;d++){const h=n[d];c[h]=this.getAttr(t+s(h))}return c};const u=FP(n);e.prototype[l]=function(c){const d=this.attrs[t];r&&(c=r.call(this,c,t)),u&&u.call(this,c,t);for(const h in c)c.hasOwnProperty(h)&&this._setAttr(t+s(h),c[h]);return c||n.forEach(h=>{this._setAttr(t+s(h),void 0)}),this._fireChangeEvent(t,d,c),o&&o.call(this),this},ce.addOverloadedGetterSetter(e,t)},addOverloadedGetterSetter(e,t){const n=Ie._capitalize(t),r=sf+n,o=of+n;e.prototype[t]=function(){return arguments.length?(this[r](arguments[0]),this):this[o]()}},addDeprecatedGetterSetter(e,t,n,r){Ie.error("Adding deprecated "+t);const o=of+Ie._capitalize(t),i=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";e.prototype[o]=function(){Ie.error(i);const s=this.attrs[t];return s===void 0?n:s},ce.addSetter(e,t,r,function(){Ie.error(i)}),ce.addOverloadedGetterSetter(e,t)},backCompat(e,t){Ie.each(t,function(n,r){const o=e.prototype[r],i=of+Ie._capitalize(n),s=sf+Ie._capitalize(n);function a(){o.apply(this,arguments),Ie.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 BP(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=vt.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=vt.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=vt.Filters;l&&l.Contrast&&l.Contrast.call(this,s)}}case"grayscale":return function(i){const s=vt.Filters;s&&s.Grayscale&&s.Grayscale.call(this,i)};case"sepia":return function(i){const s=vt.Filters;s&&s.Sepia&&s.Sepia.call(this,i)};case"invert":return function(i){const s=vt.Filters;s&&s.Invert&&s.Invert.call(this,i)};default:Ie.warn(`CSS filter "${r}" is not supported in fallback mode. Consider using function filters for better compatibility.`);break}}return()=>{}}var Tp="absoluteOpacity",l4="allEventListeners",Js="absoluteTransform",c4="absoluteScale",Gl="canvas",NP="Change",zP="children",HP="konva",a0="listening",UP="mouseenter",VP="mouseleave",jP="pointerenter",GP="pointerleave",WP="touchenter",KP="touchleave",u4="set",d4="Shape",Rp=" ",f4="stage",Ka="transform",qP="Stage",l0="visible",YP=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(Rp),XP=1,wt=class zf{constructor(t){this._id=XP++,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===Ka||t===Js)&&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===Ka||t===Js)&&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(Rp);this.on(o,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,r)}_getCanvasCache(){return this._cache.get(Gl)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===Js&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(Gl)){const{scene:t,filter:n,hit:r}=this._cache.get(Gl);Ie.releaseCanvas(t._canvas,n._canvas,r._canvas),this._cache.delete(Gl)}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,u=n.offset||0,c=n.drawBorder||!1,d=n.hitCanvasPixelRatio||1;if(!o||!i){Ie.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,m=Math.abs(Math.round(r.y)-l)>.5?1:0;o+=u*2+h,i+=u*2+m,a-=u,l-=u;const p=new Ga({pixelRatio:s,width:o,height:i}),g=new Ga({pixelRatio:s,width:0,height:0,willReadFrequently:!0}),k=new i0({pixelRatio:d,width:o,height:i}),w=p.getContext(),S=k.getContext(),y=new Ga({width:p.width/p.pixelRatio+Math.abs(a),height:p.height/p.pixelRatio+Math.abs(l),pixelRatio:p.pixelRatio}),C=y.getContext();return k.isCache=!0,p.isCache=!0,this._cache.delete(Gl),this._filterUpToDate=!1,n.imageSmoothingEnabled===!1&&(p.getContext()._context.imageSmoothingEnabled=!1,g.getContext()._context.imageSmoothingEnabled=!1),w.save(),S.save(),C.save(),w.translate(-a,-l),S.translate(-a,-l),C.translate(-a,-l),y.x=a,y.y=l,this._isUnderCache=!0,this._clearSelfAndDescendantCache(Tp),this._clearSelfAndDescendantCache(c4),this.drawScene(p,this,y),this.drawHit(k,this),this._isUnderCache=!1,w.restore(),S.restore(),c&&(w.save(),w.beginPath(),w.rect(0,0,o,i),w.closePath(),w.setAttr("strokeStyle","red"),w.setAttr("lineWidth",5),w.stroke(),w.restore()),Ie.releaseCanvas(y._canvas),this._cache.set(Gl,{scene:p,filter:g,hit:k,x:a,y:l}),this._requestDraw(),this}isCached(){return this._cache.has(Gl)}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(u){const c=l.point(u);o===void 0&&(o=s=c.x,i=a=c.y),o=Math.min(o,c.x),i=Math.min(i,c.y),s=Math.max(s,c.x),a=Math.max(a,c.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,u;if(!t||t.length===0)return r;if(this._filterUpToDate)return o;let c=!0;for(let h=0;h<t.length;h++)if(typeof t[h]=="string"&&i4(),typeof t[h]!="string"||!i4()){c=!1;break}const d=r.pixelRatio;if(o.setSize(r.width/r.pixelRatio,r.height/r.pixelRatio),c){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++)u=t[l],typeof u=="string"&&(u=BP(u)),u.call(this,a),i.putImageData(a,0,0)}catch(h){Ie.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(l4),t.length===3)return this._delegate.apply(this,t);const o=n.split(Rp);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(Rp),o=r.length,i,s,a,l,u,c;if(this._cache&&this._cache.delete(l4),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<o;i++)if(a=r[i],l=a.split("."),u=l[0],c=l[1],u)this.eventListeners[u]&&this._off(u,c,n);else for(s in this.eventListeners)this._off(s,c,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=Ie.cloneObject(i),i.currentTarget=s[a],r.call(s[a],i)}),this}remove(){return this.isDragging()&&this.stopDrag(),In._dragElements.delete(this._id),In._dragElements.forEach((t,n)=>{this.isAncestorOf(t.node)&&In._dragElements.delete(n)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(Js),this._clearSelfAndDescendantCache(Tp),this._clearSelfAndDescendantCache(c4),this._clearSelfAndDescendantCache(f4),this._clearSelfAndDescendantCache(l0),this._clearSelfAndDescendantCache(a0)}_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"+Ie._capitalize(t);return Ie._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!==zP&&(r=u4+Ie._capitalize(n),Ie._isFunction(this[r])?this[r](t[n]):this._setAttr(n,t[n]))}),this}isListening(){return this._getCache(a0,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(l0,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;In._dragElements.forEach(s=>{s.dragStatus==="dragging"&&(s.node.nodeType==="Stage"||s.node.getLayer()===r)&&(o=!0)});const i=!n&&!vt.hitOnDragEnabled&&(o||vt.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(c){for(o=[],i=c.length,s=0;s<i;s++)a=c[s],r++,a.nodeType!==d4&&(o=o.concat(a.getChildren().slice())),a._id===n._id&&(s=i);o.length>0&&o[0].getDepth()<=t&&l(o)}const u=this.getStage();return n.nodeType!==qP&&u&&l(u.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(Ka),this._clearSelfAndDescendantCache(Js)),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 Vi,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(Ka);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(Ka),this._clearSelfAndDescendantCache(Js),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 Ie.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 Ie.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 Ie.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 Ie.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 Ie.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&Ie.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(Tp,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=Ie.isObject(r)&&!Ie._isPlainObject(r)&&!Ie._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 Ie._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],Ie.isValidSelector(i)||(Ie.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Ie.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Ie.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(f4,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(Js,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let n;if(t)return n=new Vi,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(Js)||new Vi,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(Ka,this._getTransform)}_getTransform(){var t,n;const r=this._cache.get(Ka)||new Vi;r.reset();const o=this.x(),i=this.y(),s=vt.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,u=this.attrs.skewX||0,c=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),(u!==0||c!==0)&&r.skew(u,c),(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=Ie.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(HP)<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 Ga({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(),u=new Ga({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,u),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,Ie._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():vt.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+NP,{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[u4+Ie._capitalize(t)];return Ie._isFunction(r)?r.call(this,n):this._setAttr(t,n),this}_requestDraw(){if(vt.autoDrawEnabled){const t=this.getLayer()||this.getStage();t?.batchDraw()}}_setAttr(t,n){const r=this.attrs[t];r===n&&!Ie.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===d4&&(n.target=this);const o=[UP,VP,jP,GP,WP,KP];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=zf.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,zf.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;In._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){In._dragElements.has(this._id)||this._createDragElement(t);const r=In._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:Ie.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=In._dragElements.get(this._id);n&&(n.dragStatus="stopped"),In._endDragBefore(t),In._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=In._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||vt.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let n=!1;In._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=In._dragElements.get(this._id),n=t&&t.dragStatus==="dragging",r=t&&t.dragStatus==="ready";n?this.stopDrag():r&&In._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 Ie.haveIntersection(r,this.getClientRect())}static create(t,n){return Ie._isString(t)&&(t=JSON.parse(t)),this._createNode(t,n)}static _createNode(t,n){let r=zf.prototype.getClassName.call(t),o=t.children,i,s,a;n&&(t.attrs.container=n),vt[r]||(Ie.warn('Can not find a node with class name "'+r+'". Fallback to "Shape".'),r="Shape");const l=vt[r];if(i=new l(t.attrs),o)for(s=o.length,a=0;a<s;a++)i.add(zf._createNode(o[a]));return i}};wt.protoListenerMap=new Map,wt.prototype.nodeType="Node",wt.prototype._attrsAffectingSize=[],wt.prototype.eventListeners={},wt.prototype.on(YP,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(Ka),this._clearSelfAndDescendantCache(Js)}),wt.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(l0)}),wt.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(a0)}),wt.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache(Tp)});var qn=ce.addGetterSetter;qn(wt,"zIndex"),qn(wt,"absolutePosition"),qn(wt,"position"),qn(wt,"x",0,dt()),qn(wt,"y",0,dt()),qn(wt,"globalCompositeOperation","source-over",jl()),qn(wt,"opacity",1,dt()),qn(wt,"name","",jl()),qn(wt,"id","",jl()),qn(wt,"rotation",0,dt()),ce.addComponentsGetterSetter(wt,"scale",["x","y"]),qn(wt,"scaleX",1,dt()),qn(wt,"scaleY",1,dt()),ce.addComponentsGetterSetter(wt,"skew",["x","y"]),qn(wt,"skewX",0,dt()),qn(wt,"skewY",0,dt()),ce.addComponentsGetterSetter(wt,"offset",["x","y"]),qn(wt,"offsetX",0,dt()),qn(wt,"offsetY",0,dt()),qn(wt,"dragDistance",void 0,dt()),qn(wt,"width",0,dt()),qn(wt,"height",0,dt()),qn(wt,"listening",!0,ji()),qn(wt,"preventDefault",!0,ji()),qn(wt,"filters",void 0,function(e){return this._filterUpToDate=!1,e}),qn(wt,"visible",!0,ji()),qn(wt,"transformsEnabled","all",jl()),qn(wt,"size"),qn(wt,"dragBoundFunc"),qn(wt,"draggable",!1,ji()),ce.backCompat(wt,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var di=class extends wt{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=wt.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=wt.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 u=this.getAbsoluteTransform(t).getMatrix();i.transform(u[0],u[1],u[2],u[3],u[4],u[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(),u=typeof s=="number"&&typeof a=="number"||l,c=n===this;if(u){i.save();const h=this.getAbsoluteTransform(n);let m=h.getMatrix();i.transform(m[0],m[1],m[2],m[3],m[4],m[5]),i.beginPath();let p;if(l)p=l.call(this,i,this);else{const g=this.clipX(),k=this.clipY();i.rect(g||0,k||0,s,a)}i.clip.apply(i,p),m=h.copy().invert().getMatrix(),i.transform(m[0],m[1],m[2],m[3],m[4],m[5])}const d=!c&&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(),u&&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 u=this;(t=this.children)===null||t===void 0||t.forEach(function(h){if(!h.visible())return;const m=h.getClientRect({relativeTo:u,skipShadow:e.skipShadow,skipStroke:e.skipStroke});m.width===0&&m.height===0||(o===void 0?(o=m.x,i=m.y,s=m.x+m.width,a=m.y+m.height):(o=Math.min(o,m.x),i=Math.min(i,m.y),s=Math.max(s,m.x+m.width),a=Math.max(a,m.y+m.height)))});const c=this.find("Shape");let d=!1;for(let h=0;h<c.length;h++)if(c[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)}};ce.addComponentsGetterSetter(di,"clip",["x","y","width","height"]),ce.addGetterSetter(di,"clipX",void 0,dt()),ce.addGetterSetter(di,"clipY",void 0,dt()),ce.addGetterSetter(di,"clipWidth",void 0,dt()),ce.addGetterSetter(di,"clipHeight",void 0,dt()),ce.addGetterSetter(di,"clipFunc");var af=new Map,h4=vt._global.PointerEvent!==void 0;function c0(e){return af.get(e)}function u0(e){return{evt:e,pointerId:e.pointerId}}function p4(e,t){return af.get(e)===t}function m4(e,t){lf(e),t.getStage()&&(af.set(e,t),h4&&t._fire("gotpointercapture",u0(new PointerEvent("gotpointercapture"))))}function lf(e,t){const n=af.get(e);if(!n)return;const r=n.getStage();r&&r.content,af.delete(e),h4&&n._fire("lostpointercapture",u0(new PointerEvent("lostpointercapture")))}var QP="Stage",ZP="string",g4="px",JP="mouseout",v4="mouseleave",y4="mouseover",b4="mouseenter",w4="mousemove",C4="mousedown",_4="mouseup",cf="pointermove",uf="pointerdown",ou="pointerup",df="pointercancel",$P="lostpointercapture",Mp="pointerout",ff="pointerleave",Lp="pointerover",Dp="pointerenter",d0="contextmenu",S4="touchstart",k4="touchend",A4="touchmove",I4="touchcancel",f0="wheel",eO=5,tO=[[b4,"_pointerenter"],[C4,"_pointerdown"],[w4,"_pointermove"],[_4,"_pointerup"],[v4,"_pointerleave"],[S4,"_pointerdown"],[A4,"_pointermove"],[k4,"_pointerup"],[I4,"_pointercancel"],[y4,"_pointerover"],[f0,"_wheel"],[d0,"_contextmenu"],[uf,"_pointerdown"],[cf,"_pointermove"],[ou,"_pointerup"],[df,"_pointercancel"],[ff,"_pointerleave"],[$P,"_lostpointercapture"]],h0={mouse:{[Mp]:JP,[ff]:v4,[Lp]:y4,[Dp]:b4,[cf]:w4,[uf]:C4,[ou]:_4,[df]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Mp]:"touchout",[ff]:"touchleave",[Lp]:"touchover",[Dp]:"touchenter",[cf]:A4,[uf]:S4,[ou]:k4,[df]:I4,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Mp]:Mp,[ff]:ff,[Lp]:Lp,[Dp]:Dp,[cf]:cf,[uf]:uf,[ou]:ou,[df]:df,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},hf=e=>e.indexOf("pointer")>=0?"pointer":e.indexOf("touch")>=0?"touch":"mouse",iu=e=>{const t=hf(e);if(t==="pointer")return vt.pointerEventsEnabled&&h0.pointer;if(t==="touch")return h0.touch;if(t==="mouse")return h0.mouse};function E4(e={}){return(e.clipFunc||e.clipWidth||e.clipHeight)&&Ie.warn("Stage does not support clipping. Please use clip for Layers or Groups."),e}var nO="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);";const pf=[];var Pp=class extends di{constructor(e){super(E4(e)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),pf.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{E4(this.attrs)}),this._checkVisibility()}_validateAdd(e){const t=e.getType()==="Layer",n=e.getType()==="FastLayer";t||n||Ie.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===ZP){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"),di.prototype.clone.call(this,e)}destroy(){super.destroy();const e=this.content;e&&Ie._isInDocument(e)&&this.container().removeChild(e);const t=pf.indexOf(this);return t>-1&&pf.splice(t,1),Ie.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}:(Ie.warn(nO),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 Ga({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+g4,this.content.style.height=t+g4),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>eO&&Ie.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(),vt.isBrowser&&this.content.appendChild(e.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(e){return p4(e,this)}setPointerCapture(e){m4(e,this)}releaseCapture(e){lf(e,this)}getLayers(){return this.children}_bindContentEvents(){vt.isBrowser&&tO.forEach(([e,t])=>{this.content.addEventListener(e,n=>{this[t](n)},{passive:!1})})}_pointerenter(e){this.setPointersPositions(e);const t=iu(e.type);t&&this._fire(t.pointerenter,{evt:e,target:this,currentTarget:this})}_pointerover(e){this.setPointersPositions(e);const t=iu(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=iu(e.type),n=hf(e.type);if(!t)return;this.setPointersPositions(e);const r=this._getTargetShape(n),o=!(vt.isDragging()||vt.isTransforming())||vt.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=iu(e.type),n=hf(e.type);if(!t)return;this.setPointersPositions(e);let r=!1;this._changedPointerPositions.forEach(o=>{const i=this.getIntersection(o);if(In.justDragged=!1,vt["_"+n+"ListenClick"]=!0,!i||!i.isListening()){this[n+"ClickStartShape"]=void 0;return}vt.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=iu(e.type),n=hf(e.type);if(!t)return;const r=e.type.indexOf("touch")>=0||e.pointerType==="touch";if(vt.isDragging()&&In.node.preventDefault()&&e.cancelable&&r&&e.preventDefault(),this.setPointersPositions(e),!(!(vt.isDragging()||vt.isTransforming())||vt.hitOnDragEnabled))return;const o={};let i=!1;const s=this._getTargetShape(n);this._changedPointerPositions.forEach(a=>{const l=c0(a.id)||this.getIntersection(a),u=a.id,c={evt:e,pointerId:u},d=s!==l;if(d&&s&&(s._fireAndBubble(t.pointerout,{...c},l),s._fireAndBubble(t.pointerleave,{...c},l)),l){if(o[l._id])return;o[l._id]=!0}l&&l.isListening()?(i=!0,d&&(l._fireAndBubble(t.pointerover,{...c},s),l._fireAndBubble(t.pointerenter,{...c},s),this[n+"targetShape"]=l),l._fireAndBubble(t.pointermove,{...c})):s&&(this._fire(t.pointerover,{evt:e,target:this,currentTarget:this,pointerId:u}),this[n+"targetShape"]=null)}),i||this._fire(t.pointermove,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(e){const t=iu(e.type),n=hf(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=c0(a.id)||this.getIntersection(a);if(l){if(l.releaseCapture(a.id),i[l._id])return;i[l._id]=!0}const u=a.id,c={evt:e,pointerId:u};let d=!1;vt["_"+n+"InDblClickWindow"]?(d=!0,clearTimeout(this[n+"DblTimeout"])):In.justDragged||(vt["_"+n+"InDblClickWindow"]=!0,clearTimeout(this[n+"DblTimeout"])),this[n+"DblTimeout"]=setTimeout(function(){vt["_"+n+"InDblClickWindow"]=!1},vt.dblClickWindow),l&&l.isListening()?(s=!0,this[n+"ClickEndShape"]=l,l._fireAndBubble(t.pointerup,{...c}),vt["_"+n+"ListenClick"]&&r&&r===l&&(l._fireAndBubble(t.pointerclick,{...c}),d&&o&&o===l&&l._fireAndBubble(t.pointerdblclick,{...c}))):(this[n+"ClickEndShape"]=null,s||(this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),s=!0),vt["_"+n+"ListenClick"]&&this._fire(t.pointerclick,{evt:e,target:this,currentTarget:this,pointerId:u}),d&&this._fire(t.pointerdblclick,{evt:e,target:this,currentTarget:this,pointerId:u}))}),s||this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),vt["_"+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(d0,{evt:e}):this._fire(d0,{evt:e,target:this,currentTarget:this})}_wheel(e){this.setPointersPositions(e);const t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(f0,{evt:e}):this._fire(f0,{evt:e,target:this,currentTarget:this})}_pointercancel(e){this.setPointersPositions(e);const t=c0(e.pointerId)||this.getIntersection(this.getPointerPosition());t&&t._fireAndBubble(ou,u0(e)),lf(e.pointerId)}_lostpointercapture(e){lf(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:Ie._getFirstPointerId(e)}],this._changedPointerPositions=[{x:n,y:r,id:Ie._getFirstPointerId(e)}])}_setPointerPosition(e){Ie.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 Ga({width:this.width(),height:this.height()}),this.bufferHitCanvas=new i0({pixelRatio:1,width:this.width(),height:this.height()}),!vt.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 Ie.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}};Pp.prototype.nodeType=QP,vr(Pp),ce.addGetterSetter(Pp,"container"),vt.isBrowser&&document.addEventListener("visibilitychange",()=>{pf.forEach(e=>{e.batchDraw()})});var x4="hasShadow",T4="shadowRGBA",R4="patternImage",M4="linearGradient",L4="radialGradient",Op;function p0(){return Op||(Op=Ie.createCanvasElement().getContext("2d"),Op)}const mf={};function rO(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function oO(e){e.stroke()}function iO(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function sO(e){e.stroke()}function aO(){this._clearCache(x4)}function lO(){this._clearCache(T4)}function cO(){this._clearCache(R4)}function uO(){this._clearCache(M4)}function dO(){this._clearCache(L4)}var ct=class extends wt{constructor(e){super(e);let t,n=0;for(;t=Ie.getHitColor(),!(t&&!(t in mf));)if(n++,n>=1e4){Ie.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=Ie.getRandomColor();break}this.colorKey=t,mf[t]=this}getContext(){return Ie.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return Ie.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(x4,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(R4,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const e=p0().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){const t=new Vi;t.translate(this.fillPatternX(),this.fillPatternY()),t.rotate(vt.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(M4,this.__getLinearGradient)}__getLinearGradient(){const e=this.fillLinearGradientColorStops();if(e){const t=p0(),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(L4,this.__getRadialGradient)}__getRadialGradient(){const e=this.fillRadialGradientColorStops();if(e){const t=p0(),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(T4,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const e=Ie.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 wt.prototype.destroy.call(this),delete mf[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){Ie.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,u=!e.skipShadow&&this.hasShadow(),c=u?this.shadowOffsetX():0,d=u?this.shadowOffsetY():0,h=a+Math.abs(c),m=l+Math.abs(d),p=u&&this.shadowBlur()||0,g={width:h+p*2,height:m+p*2,x:-(s/2+p)+Math.min(c,0)+i.x,y:-(s/2+p)+Math.min(d,0)+i.y};return r?g:this._transformedRect(g,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 u=t===this;if(!this.isVisible()&&!u)return this;if(i){o.save();const c=this.getAbsoluteTransform(t).getMatrix();return o.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(o),o.restore(),this}if(!s)return this;if(o.save(),this._useBufferCanvas()){l=this.getStage();const c=n||l.bufferCanvas,d=c.getContext();n?(d.save(),d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,c.width,c.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 m=c.pixelRatio;a&&o._applyShadow(this),u||(o._applyOpacity(this),o._applyGlobalCompositeOperation(this)),o.drawImage(c._canvas,c.x||0,c.y||0,c.width/m,c.height/m)}else{if(o._applyLineJoin(this),o._applyMiterLimit(this),!u){const c=this.getAbsoluteTransform(t).getMatrix();o.transform(c[0],c[1],c[2],c[3],c[4],c[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||Ie.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 u=this.getAbsoluteTransform(t).getMatrix();return i.transform(u[0],u[1],u[2],u[3],u[4],u[5]),this._drawCachedHitCanvas(i),i.restore(),this}if(!s)return this;if(i.save(),i._applyLineJoin(this),i._applyMiterLimit(this),this!==t){const u=this.getAbsoluteTransform(t).getMatrix();i.transform(u[0],u[1],u[2],u[3],u[4],u[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,u=l.length,c=Ie._hexToRgb(this.colorKey);for(let d=0;d<u;d+=4)l[d+3]>e?(l[d]=c.r,l[d+1]=c.g,l[d+2]=c.b,l[d+3]=255):l[d+3]=0;o.putImageData(a,0,0)}catch(a){Ie.error("Unable to draw hit graph from cached scene canvas. "+a.message)}return this}hasPointerCapture(e){return p4(e,this)}setPointerCapture(e){m4(e,this)}releaseCapture(e){lf(e,this)}};ct.prototype._fillFunc=rO,ct.prototype._strokeFunc=oO,ct.prototype._fillFuncHit=iO,ct.prototype._strokeFuncHit=sO,ct.prototype._centroid=!1,ct.prototype.nodeType="Shape",vr(ct),ct.prototype.eventListeners={},ct.prototype.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",aO),ct.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",lO),ct.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",cO),ct.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",uO),ct.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",dO),ce.addGetterSetter(ct,"stroke",void 0,a4()),ce.addGetterSetter(ct,"strokeWidth",2,dt()),ce.addGetterSetter(ct,"fillAfterStrokeEnabled",!1),ce.addGetterSetter(ct,"hitStrokeWidth","auto",s0()),ce.addGetterSetter(ct,"strokeHitEnabled",!0,ji()),ce.addGetterSetter(ct,"perfectDrawEnabled",!0,ji()),ce.addGetterSetter(ct,"shadowForStrokeEnabled",!0,ji()),ce.addGetterSetter(ct,"lineJoin"),ce.addGetterSetter(ct,"lineCap"),ce.addGetterSetter(ct,"miterLimit"),ce.addGetterSetter(ct,"sceneFunc"),ce.addGetterSetter(ct,"hitFunc"),ce.addGetterSetter(ct,"dash"),ce.addGetterSetter(ct,"dashOffset",0,dt()),ce.addGetterSetter(ct,"shadowColor",void 0,jl()),ce.addGetterSetter(ct,"shadowBlur",0,dt()),ce.addGetterSetter(ct,"shadowOpacity",1,dt()),ce.addComponentsGetterSetter(ct,"shadowOffset",["x","y"]),ce.addGetterSetter(ct,"shadowOffsetX",0,dt()),ce.addGetterSetter(ct,"shadowOffsetY",0,dt()),ce.addGetterSetter(ct,"fillPatternImage"),ce.addGetterSetter(ct,"fill",void 0,a4()),ce.addGetterSetter(ct,"fillPatternX",0,dt()),ce.addGetterSetter(ct,"fillPatternY",0,dt()),ce.addGetterSetter(ct,"fillLinearGradientColorStops"),ce.addGetterSetter(ct,"strokeLinearGradientColorStops"),ce.addGetterSetter(ct,"fillRadialGradientStartRadius",0),ce.addGetterSetter(ct,"fillRadialGradientEndRadius",0),ce.addGetterSetter(ct,"fillRadialGradientColorStops"),ce.addGetterSetter(ct,"fillPatternRepeat","repeat"),ce.addGetterSetter(ct,"fillEnabled",!0),ce.addGetterSetter(ct,"strokeEnabled",!0),ce.addGetterSetter(ct,"shadowEnabled",!0),ce.addGetterSetter(ct,"dashEnabled",!0),ce.addGetterSetter(ct,"strokeScaleEnabled",!0),ce.addGetterSetter(ct,"fillPriority","color"),ce.addComponentsGetterSetter(ct,"fillPatternOffset",["x","y"]),ce.addGetterSetter(ct,"fillPatternOffsetX",0,dt()),ce.addGetterSetter(ct,"fillPatternOffsetY",0,dt()),ce.addComponentsGetterSetter(ct,"fillPatternScale",["x","y"]),ce.addGetterSetter(ct,"fillPatternScaleX",1,dt()),ce.addGetterSetter(ct,"fillPatternScaleY",1,dt()),ce.addComponentsGetterSetter(ct,"fillLinearGradientStartPoint",["x","y"]),ce.addComponentsGetterSetter(ct,"strokeLinearGradientStartPoint",["x","y"]),ce.addGetterSetter(ct,"fillLinearGradientStartPointX",0),ce.addGetterSetter(ct,"strokeLinearGradientStartPointX",0),ce.addGetterSetter(ct,"fillLinearGradientStartPointY",0),ce.addGetterSetter(ct,"strokeLinearGradientStartPointY",0),ce.addComponentsGetterSetter(ct,"fillLinearGradientEndPoint",["x","y"]),ce.addComponentsGetterSetter(ct,"strokeLinearGradientEndPoint",["x","y"]),ce.addGetterSetter(ct,"fillLinearGradientEndPointX",0),ce.addGetterSetter(ct,"strokeLinearGradientEndPointX",0),ce.addGetterSetter(ct,"fillLinearGradientEndPointY",0),ce.addGetterSetter(ct,"strokeLinearGradientEndPointY",0),ce.addComponentsGetterSetter(ct,"fillRadialGradientStartPoint",["x","y"]),ce.addGetterSetter(ct,"fillRadialGradientStartPointX",0),ce.addGetterSetter(ct,"fillRadialGradientStartPointY",0),ce.addComponentsGetterSetter(ct,"fillRadialGradientEndPoint",["x","y"]),ce.addGetterSetter(ct,"fillRadialGradientEndPointX",0),ce.addGetterSetter(ct,"fillRadialGradientEndPointY",0),ce.addGetterSetter(ct,"fillPatternRotation",0),ce.addGetterSetter(ct,"fillRule",void 0,jl()),ce.backCompat(ct,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var fO="beforeDraw",hO="draw",D4=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],pO=D4.length,Wl=class extends di{constructor(e){super(e),this.canvas=new Ga,this.hitCanvas=new i0({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(){wt.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(!wt.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(wt.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(wt.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 wt.prototype.remove.call(this),e&&e.parentNode&&Ie._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"&&Ie.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(),wt.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(){Ie.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){Ie.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,Ie.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<pO;r++){const o=D4[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=mf[Ie.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(fO,{node:this}),this.clearBeforeDraw()&&o.getContext().clear(),di.prototype.drawScene.call(this,o,t,n),this._fire(hO,{node:this}),this}drawHit(e,t){const n=this.getLayer(),r=e||n&&n.hitCanvas;return n&&n.clearBeforeDraw()&&n.getHitCanvas().getContext().clear(),di.prototype.drawHit.call(this,r,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){Ie.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(e)}getHitGraphEnabled(e){return Ie.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 Ie.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};Wl.prototype.nodeType="Layer",vr(Wl),ce.addGetterSetter(Wl,"imageSmoothingEnabled",!0),ce.addGetterSetter(Wl,"clearBeforeDraw",!0),ce.addGetterSetter(Wl,"hitGraphEnabled",!0,ji());var m0=class extends Wl{constructor(e){super(e),this.listening(!1),Ie.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}};m0.prototype.nodeType="FastLayer",vr(m0);var su=class extends di{_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&Ie.throw("You may only add groups and shapes to groups.")}};su.prototype.nodeType="Group",vr(su);var g0=(function(){return Vl.performance&&Vl.performance.now?function(){return Vl.performance.now()}:function(){return new Date().getTime()}})(),au=class Uu{constructor(t,n){this.id=Uu.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:g0(),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=Uu.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=g0(),Uu._addAnimation(this),this}stop(){return Uu._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(g0());const a=i.length;let l;if(s?l=s.call(o,o.frame)!==!1:l=!0,!!l)for(let u=0;u<a;u++){const c=i[u];c._id!==void 0&&(t[c._id]=c)}}for(const r in t)t.hasOwnProperty(r)&&t[r].batchDraw()}static _animationLoop(){const t=Uu;t.animations.length?(t._runFrames(),Ie.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Ie.requestAnimFrame(this._animationLoop))}};au.animations=[],au.animIdCounter=0,au.animRunning=!1;var mO={node:1,duration:1,easing:1,onFinish:1,yoyo:1},gO=1,P4=2,O4=3,F4=["fill","stroke","shadowColor"],vO=0,yO=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=P4,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=O4,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===P4?this.setTime(e):this.state===O4&&this.setTime(this.duration-e)}pause(){this.state=gO,this.fire("onPause")}getTimer(){return new Date().getTime()}},Fp=class Ir{constructor(t){const n=this,r=t.node,o=r._id,i=t.easing||gf.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=vO++;const u=r.getLayer()||(r instanceof vt.Stage?r.getLayers():null);u||Ie.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new au(function(){n.tween.onEnterFrame()},u),this.tween=new yO(l,function(c){n._tweenFunc(c)},i,0,1,a*1e3,s),this._addListeners(),Ir.attrs[o]||(Ir.attrs[o]={}),Ir.attrs[o][this._id]||(Ir.attrs[o][this._id]={}),Ir.tweens[o]||(Ir.tweens[o]={});for(l in t)mO[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,u;const c=Ir.tweens[o][t];c&&delete Ir.attrs[o][c][t];let d=r.getAttr(t);if(Ie._isArray(n))if(i=[],s=Math.max(n.length,d.length),t==="points"&&n.length!==d.length&&(n.length>d.length?(l=d,d=Ie._prepareArrayForTween(d,n,r.closed())):(a=n,n=Ie._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 m=Ie.colorToRGBA(d[h]);u=Ie.colorToRGBA(n[h]),d[h]=m,i.push({r:u.r-m.r,g:u.g-m.g,b:u.b-m.b,a:u.a-m.a})}else for(let h=0;h<s;h++)i.push(n[h]-d[h]);else F4.indexOf(t)!==-1?(d=Ie.colorToRGBA(d),u=Ie.colorToRGBA(n),i={r:u.r-d.r,g:u.g-d.g,b:u.b-d.b,a:u.a-d.a}):i=n-d;Ir.attrs[o][this._id][t]={start:d,diff:i,end:n,trueEnd:a,trueStart:l},Ir.tweens[o][t]=this._id}_tweenFunc(t){const n=this.node,r=Ir.attrs[n._id][this._id];let o,i,s,a,l,u,c,d;for(o in r){if(i=r[o],s=i.start,a=i.diff,d=i.end,Ie._isArray(s))if(l=[],c=Math.max(s.length,d.length),o.indexOf("fill")===0)for(u=0;u<c;u++)u%2===0?l.push((s[u]||0)+a[u]*t):l.push("rgba("+Math.round(s[u].r+a[u].r*t)+","+Math.round(s[u].g+a[u].g*t)+","+Math.round(s[u].b+a[u].b*t)+","+(s[u].a+a[u].a*t)+")");else for(u=0;u<c;u++)l.push((s[u]||0)+a[u]*t);else F4.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=Ir.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=Ir.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=Ir.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const o in r)delete Ir.tweens[t][o];delete Ir.attrs[t][n],Ir.tweens[t]&&(Object.keys(Ir.tweens[t]).length===0&&delete Ir.tweens[t],Object.keys(Ir.attrs[t]).length===0&&delete Ir.attrs[t])}};Fp.attrs={},Fp.tweens={},wt.prototype.to=function(e){const t=e.onFinish;e.node=this,e.onFinish=function(){this.destroy(),t&&t()},new Fp(e).play()};const gf={BackEaseIn(e,t,n,r){return n*(e/=r)*e*((1.70158+1)*e-1.70158)+t},BackEaseOut(e,t,n,r){return n*((e=e/r-1)*e*((1.70158+1)*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-gf.BounceEaseOut(r-e,0,n,r)+t},BounceEaseInOut(e,t,n,r){return e<r/2?gf.BounceEaseIn(e*2,0,n,r)*.5+t:gf.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}},B4=Ie._assign(vt,{Util:Ie,Transform:Vi,Node:wt,Container:di,Stage:Pp,stages:pf,Layer:Wl,FastLayer:m0,Group:su,DD:In,Shape:ct,shapes:mf,Animation:au,Tween:Fp,Easings:gf,Context:Ip,Canvas:o0});var $s=class extends ct{_sceneFunc(e){const t=vt.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=vt.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),u=i*(i>0?t:e),c=s*(s>0?e:t),d=a*(a>0?t:e);return{x:l,y:n?-1*d:c,width:u-l,height:d-c}}};$s.prototype._centroid=!0,$s.prototype.className="Arc",$s.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],vr($s),ce.addGetterSetter($s,"innerRadius",0,dt()),ce.addGetterSetter($s,"outerRadius",0,dt()),ce.addGetterSetter($s,"angle",0,dt()),ce.addGetterSetter($s,"clockwise",!1,ji());function v0(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)),u=s*a/(a+l),c=s*l/(a+l);return[n-u*(o-e),r-u*(i-t),n+c*(o-e),r+c*(i-t)]}function N4(e,t){const n=e.length,r=[];for(let o=2;o<n-2;o+=2){const i=v0(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 bO(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 ea=class extends ct{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():N4(this.points(),this.tension())}_getTensionPointsClosed(){const e=this.points(),t=e.length,n=this.tension(),r=v0(e[t-2],e[t-1],e[0],e[1],e[2],e[3],n),o=v0(e[t-4],e[t-3],e[t-2],e[t-1],e[0],e[1],n),i=N4(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],...bO(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}}};ea.prototype.className="Line",ea.prototype._attrsAffectingSize=["points","bezier","tension"],vr(ea),ce.addGetterSetter(ea,"closed",!1),ce.addGetterSetter(ea,"bezier",!1),ce.addGetterSetter(ea,"tension",0,dt()),ce.addGetterSetter(ea,"points",[],OP());const wO=[[],[],[-.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]],CO=[[],[],[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]],_O=[[1],[1,1],[1,2,1],[1,3,3,1]],z4=(e,t,n)=>{let r,o;const s=n/2;r=0;for(let a=0;a<20;a++)o=s*wO[20][a]+s,r+=CO[20][a]*SO(e,t,o);return s*r},H4=(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),u=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 c=l/(2*a),d=u/a,h=n+c,m=d-c*c,p=h*h+m>0?Math.sqrt(h*h+m):0,g=c*c+m>0?Math.sqrt(c*c+m):0,k=c+Math.sqrt(c*c+m)!==0?m*Math.log(Math.abs((h+p)/(c+g))):0;return Math.sqrt(a)/2*(h*p-c*g+k)};function SO(e,t,n){const r=y0(1,n,e),o=y0(1,n,t),i=r*r+o*o;return Math.sqrt(i)}var y0=(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+=_O[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 y0(e-1,t,o)}};const U4=(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 u=n(o-i),c=Math.abs(e-u)/t;c<r?(r=c,o-=i):i/=2}if(s++,s>500)break}return o};var xi=class ii extends ct{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=ii.parsePathData(this.data()),this.pathLength=ii.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],u=s[2],c=s[3],d=s[4],h=s[5],m=s[6],p=s[7],g=u>c?u:c,k=u>c?1:u/c,w=u>c?c/u:1;t.translate(a,l),t.rotate(m),t.scale(k,w),t.arc(0,0,g,d,d+h,1-p),t.scale(1/k,1/w),t.rotate(-m),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 u=l.points[4],c=l.points[5],d=l.points[4]+c;let h=Math.PI/180;if(Math.abs(u-d)<h&&(h=Math.abs(u-d)),c<0)for(let m=u-h;m>d;m-=h){const p=ii.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],m,0);t.push(p.x,p.y)}else for(let m=u+h;m<d;m+=h){const p=ii.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],m,0);t.push(p.x,p.y)}}else if(l.command==="C")for(let u=0;u<=1;u+=.01){const c=ii.getPointOnCubicBezier(u,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(c.x,c.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 ii.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 ii.getPointOnLine(t,s.start.x,s.start.y,a[0],a[1]);case"C":return ii.getPointOnCubicBezier(U4(t,ii.getPathLength(n),g=>z4([s.start.x,a[0],a[2],a[4]],[s.start.y,a[1],a[3],a[5]],g)),s.start.x,s.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return ii.getPointOnQuadraticBezier(U4(t,ii.getPathLength(n),g=>H4([s.start.x,a[0],a[2]],[s.start.y,a[1],a[3]],g)),s.start.x,s.start.y,a[0],a[1],a[2],a[3]);case"A":const l=a[0],u=a[1],c=a[2],d=a[3],h=a[5],m=a[6];let p=a[4];return p+=h*t/s.pathLength,ii.getPointOnEllipticalArc(l,u,c,d,p,m)}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 u=(i-r)/(o-n),c=Math.sqrt(t*t/(1+u*u))*(o<n?-1:1),d=u*c;if(Math.abs(a-r-u*(s-n))<1e-10)return{x:s+c,y:a+d};const h=((s-n)*(o-n)+(a-r)*(i-r))/(l*l),m=n+h*(o-n),p=r+h*(i-r),g=this.getLineLength(s,a,m,p),k=Math.sqrt(t*t-g*g),w=Math.sqrt(k*k/(1+u*u))*(o<n?-1:1),S=u*w;return{x:m+w,y:p+S}}static getPointOnCubicBezier(t,n,r,o,i,s,a,l,u){function c(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 m(p){return(1-p)*(1-p)*(1-p)}return{x:l*c(t)+s*d(t)+o*h(t)+n*m(t),y:u*c(t)+a*d(t)+i*h(t)+r*m(t)}}static getPointOnQuadraticBezier(t,n,r,o,i,s,a){function l(d){return d*d}function u(d){return 2*d*(1-d)}function c(d){return(1-d)*(1-d)}return{x:s*l(t)+o*u(t)+n*c(t),y:a*l(t)+i*u(t)+r*c(t)}}static getPointOnEllipticalArc(t,n,r,o,i,s){const a=Math.cos(s),l=Math.sin(s),u={x:r*Math.cos(i),y:o*Math.sin(i)};return{x:t+(u.x*a-u.y*l),y:n+(u.x*l+u.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 u=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let c;for(let d=1;d<o.length;d++){let h=o[d],m=h.charAt(0);for(h=h.slice(1),s.length=0;c=u.exec(h);)s.push(c[0]);let p=[],g=m==="A"||m==="a"?0:-1;for(let k=0,w=s.length;k<w;k++){const S=s[k];if(S==="00"){p.push(0,0),g>=0&&(g+=2,g>=7&&(g-=7));continue}if(g>=0){if(g===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(S)){p.push(parseInt(S[0],10)),p.push(parseInt(S[1],10)),p.push(parseFloat(S.slice(2))),g+=3,g>=7&&(g-=7);continue}if(S==="11"||S==="10"||S==="01"){p.push(parseInt(S[0],10)),p.push(parseInt(S[1],10)),g+=2,g>=7&&(g-=7);continue}if(S==="0"||S==="1"){p.push(parseInt(S,10)),g+=1,g>=7&&(g-=7);continue}}else if(g===4){if(/^[01]\d+(?:\.\d+)?$/.test(S)){p.push(parseInt(S[0],10)),p.push(parseFloat(S.slice(1))),g+=2,g>=7&&(g-=7);continue}if(S==="0"||S==="1"){p.push(parseInt(S,10)),g+=1,g>=7&&(g-=7);continue}}const y=parseFloat(S);isNaN(y)?p.push(0):p.push(y),g+=1,g>=7&&(g-=7)}else{const y=parseFloat(S);isNaN(y)?p.push(0):p.push(y)}}for(;p.length>0&&!isNaN(p[0]);){let k="",w=[];const S=a,y=l;let C,T,R,M,H,B,z,X,P,N;switch(m){case"l":a+=p.shift(),l+=p.shift(),k="L",w.push(a,l);break;case"L":a=p.shift(),l=p.shift(),w.push(a,l);break;case"m":const I=p.shift(),L=p.shift();if(a+=I,l+=L,k="M",i.length>2&&i[i.length-1].command==="z"){for(let Y=i.length-2;Y>=0;Y--)if(i[Y].command==="M"){a=i[Y].points[0]+I,l=i[Y].points[1]+L;break}}w.push(a,l),m="l";break;case"M":a=p.shift(),l=p.shift(),k="M",w.push(a,l),m="L";break;case"h":a+=p.shift(),k="L",w.push(a,l);break;case"H":a=p.shift(),k="L",w.push(a,l);break;case"v":l+=p.shift(),k="L",w.push(a,l);break;case"V":l=p.shift(),k="L",w.push(a,l);break;case"C":w.push(p.shift(),p.shift(),p.shift(),p.shift()),a=p.shift(),l=p.shift(),w.push(a,l);break;case"c":w.push(a+p.shift(),l+p.shift(),a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="C",w.push(a,l);break;case"S":T=a,R=l,C=i[i.length-1],C.command==="C"&&(T=a+(a-C.points[2]),R=l+(l-C.points[3])),w.push(T,R,p.shift(),p.shift()),a=p.shift(),l=p.shift(),k="C",w.push(a,l);break;case"s":T=a,R=l,C=i[i.length-1],C.command==="C"&&(T=a+(a-C.points[2]),R=l+(l-C.points[3])),w.push(T,R,a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="C",w.push(a,l);break;case"Q":w.push(p.shift(),p.shift()),a=p.shift(),l=p.shift(),w.push(a,l);break;case"q":w.push(a+p.shift(),l+p.shift()),a+=p.shift(),l+=p.shift(),k="Q",w.push(a,l);break;case"T":T=a,R=l,C=i[i.length-1],C.command==="Q"&&(T=a+(a-C.points[0]),R=l+(l-C.points[1])),a=p.shift(),l=p.shift(),k="Q",w.push(T,R,a,l);break;case"t":T=a,R=l,C=i[i.length-1],C.command==="Q"&&(T=a+(a-C.points[0]),R=l+(l-C.points[1])),a+=p.shift(),l+=p.shift(),k="Q",w.push(T,R,a,l);break;case"A":M=p.shift(),H=p.shift(),B=p.shift(),z=p.shift(),X=p.shift(),P=a,N=l,a=p.shift(),l=p.shift(),k="A",w=this.convertEndpointToCenterParameterization(P,N,a,l,z,X,M,H,B);break;case"a":M=p.shift(),H=p.shift(),B=p.shift(),z=p.shift(),X=p.shift(),P=a,N=l,a+=p.shift(),l+=p.shift(),k="A",w=this.convertEndpointToCenterParameterization(P,N,a,l,z,X,M,H,B);break}i.push({command:k||m,points:w,start:{x:S,y},pathLength:this.calcLength(S,y,k||m,w)})}(m==="z"||m==="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 u=ii;switch(r){case"L":return u.getLineLength(t,n,o[0],o[1]);case"C":return z4([t,o[0],o[2],o[4]],[n,o[1],o[3],o[5]],1);case"Q":return H4([t,o[0],o[2]],[n,o[1],o[3]],1);case"A":i=0;const c=o[4],d=o[5],h=o[4]+d;let m=Math.PI/180;if(Math.abs(c-h)<m&&(m=Math.abs(c-h)),s=u.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],c,0),d<0)for(l=c-m;l>h;l-=m)a=u.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=u.getLineLength(s.x,s.y,a.x,a.y),s=a;else for(l=c+m;l<h;l+=m)a=u.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=u.getLineLength(s.x,s.y,a.x,a.y),s=a;return a=u.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],h,0),i+=u.getLineLength(s.x,s.y,a.x,a.y),i}return 0}static convertEndpointToCenterParameterization(t,n,r,o,i,s,a,l,u){const c=u*(Math.PI/180),d=Math.cos(c)*(t-r)/2+Math.sin(c)*(n-o)/2,h=-1*Math.sin(c)*(t-r)/2+Math.cos(c)*(n-o)/2,m=d*d/(a*a)+h*h/(l*l);m>1&&(a*=Math.sqrt(m),l*=Math.sqrt(m));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 g=p*a*h/l,k=p*-l*d/a,w=(t+r)/2+Math.cos(c)*g-Math.sin(c)*k,S=(n+o)/2+Math.sin(c)*g+Math.cos(c)*k,y=function(z){return Math.sqrt(z[0]*z[0]+z[1]*z[1])},C=function(z,X){return(z[0]*X[0]+z[1]*X[1])/(y(z)*y(X))},T=function(z,X){return(z[0]*X[1]<z[1]*X[0]?-1:1)*Math.acos(C(z,X))},R=T([1,0],[(d-g)/a,(h-k)/l]),M=[(d-g)/a,(h-k)/l],H=[(-1*d-g)/a,(-1*h-k)/l];let B=T(M,H);return C(M,H)<=-1&&(B=Math.PI),C(M,H)>=1&&(B=0),s===0&&B>0&&(B=B-2*Math.PI),s===1&&B<0&&(B=B+2*Math.PI),[w,S,a,l,R,B,c,s]}};xi.prototype.className="Path",xi.prototype._attrsAffectingSize=["data"],vr(xi),ce.addGetterSetter(xi,"data");var Kl=class extends ea{_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=xi.calcLength(r[r.length-4],r[r.length-3],"C",d),m=xi.getPointOnQuadraticBezier(Math.min(1,1-i/h),d[0],d[1],d[2],d[3],d[4],d[5]);a=n[s-2]-m.x,l=n[s-1]-m.y}else a=n[s-2]-n[s-4],l=n[s-1]-n[s-3];const u=(Math.atan2(l,a)+t)%t,c=this.pointerWidth();this.pointerAtEnding()&&(e.save(),e.beginPath(),e.translate(n[s-2],n[s-1]),e.rotate(u),e.moveTo(0,0),e.lineTo(-i,c/2),e.lineTo(-i,-c/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,c/2),e.lineTo(-i,-c/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}}};Kl.prototype.className="Arrow",vr(Kl),ce.addGetterSetter(Kl,"pointerLength",10,dt()),ce.addGetterSetter(Kl,"pointerWidth",10,dt()),ce.addGetterSetter(Kl,"pointerAtBeginning",!1),ce.addGetterSetter(Kl,"pointerAtEnding",!0);var lu=class extends ct{_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)}};lu.prototype._centroid=!0,lu.prototype.className="Circle",lu.prototype._attrsAffectingSize=["radius"],vr(lu),ce.addGetterSetter(lu,"radius",0,dt());var qa=class extends ct{_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)}};qa.prototype.className="Ellipse",qa.prototype._centroid=!0,qa.prototype._attrsAffectingSize=["radiusX","radiusY"],vr(qa),ce.addComponentsGetterSetter(qa,"radius",["x","y"]),ce.addGetterSetter(qa,"radiusX",0,dt()),ce.addGetterSetter(qa,"radiusY",0,dt());var Gi=class UA extends ct{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?Ie.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?Ie.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=Ie.createImageElement();o.onload=function(){n(new UA({image:o}))},o.onerror=r,o.crossOrigin="Anonymous",o.src=t}};Gi.prototype.className="Image",Gi.prototype._attrsAffectingSize=["image"],vr(Gi),ce.addGetterSetter(Gi,"cornerRadius",0,xp(4)),ce.addGetterSetter(Gi,"image"),ce.addComponentsGetterSetter(Gi,"crop",["x","y","width","height"]),ce.addGetterSetter(Gi,"cropX",0,dt()),ce.addGetterSetter(Gi,"cropY",0,dt()),ce.addGetterSetter(Gi,"cropWidth",0,dt()),ce.addGetterSetter(Gi,"cropHeight",0,dt());var V4=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],kO="Change.konva",AO="none",b0="up",w0="right",C0="down",_0="left",IO=V4.length,S0=class extends su{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<IO;n++)e.on(V4[n]+kO,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 b0:s=n/2,a=-1*l;break;case w0:s=n+i,a=r/2;break;case C0: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})}}};S0.prototype.className="Label",vr(S0);var ql=class extends ct{_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,u=0,c=0;typeof s=="number"?a=l=u=c=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),c=Math.min(s[2]||0,t/2,n/2),u=Math.min(s[3]||0,t/2,n/2)),e.beginPath(),e.moveTo(a,0),r===b0&&(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===w0&&(e.lineTo(t,(n-i)/2),e.lineTo(t+o,n/2),e.lineTo(t,(n+i)/2)),e.lineTo(t,n-c),e.arc(t-c,n-c,c,0,Math.PI/2,!1),r===C0&&(e.lineTo((t+o)/2,n),e.lineTo(t/2,n+i),e.lineTo((t-o)/2,n)),e.lineTo(u,n),e.arc(u,n-u,u,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===b0?(t-=r,s+=r):o===C0?s+=r:o===_0?(e-=n*1.5,i+=n):o===w0&&(i+=n*1.5),{x:e,y:t,width:i,height:s}}};ql.prototype.className="Tag",vr(ql),ce.addGetterSetter(ql,"pointerDirection",AO),ce.addGetterSetter(ql,"pointerWidth",0,dt()),ce.addGetterSetter(ql,"pointerHeight",0,dt()),ce.addGetterSetter(ql,"cornerRadius",0,xp(4));var vf=class extends ct{_sceneFunc(e){const t=this.cornerRadius(),n=this.width(),r=this.height();e.beginPath(),t?Ie.drawRoundedRectPath(e,n,r,t):e.rect(0,0,n,r),e.closePath(),e.fillStrokeShape(this)}};vf.prototype.className="Rect",vr(vf),ce.addGetterSetter(vf,"cornerRadius",0,xp(4));var Ya=class extends ct{_sceneFunc(e){const t=this._getPoints(),n=this.radius(),r=this.sides(),o=this.cornerRadius();if(e.beginPath(),o)Ie.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)}};Ya.prototype.className="RegularPolygon",Ya.prototype._centroid=!0,Ya.prototype._attrsAffectingSize=["radius"],vr(Ya),ce.addGetterSetter(Ya,"radius",0,dt()),ce.addGetterSetter(Ya,"sides",0,dt()),ce.addGetterSetter(Ya,"cornerRadius",0,xp(4));var j4=Math.PI*2,Yl=class extends ct{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,j4,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),j4,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)}};Yl.prototype.className="Ring",Yl.prototype._centroid=!0,Yl.prototype._attrsAffectingSize=["innerRadius","outerRadius"],vr(Yl),ce.addGetterSetter(Yl,"innerRadius",0,dt()),ce.addGetterSetter(Yl,"outerRadius",0,dt());var fs=class extends ct{constructor(e){super(e),this._updated=!0,this.anim=new au(()=>{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],u=o[r+3],c=this.image();if((this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(0,0,l,u),e.closePath(),e.fillStrokeShape(this)),c)if(i){const d=i[t],h=n*2;e.drawImage(c,s,a,l,u,d[h+0],d[h+1],l,u)}else e.drawImage(c,s,a,l,u,0,0,l,u)}_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],u=n*2;e.rect(l[u+0],l[u+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)}};fs.prototype.className="Sprite",vr(fs),ce.addGetterSetter(fs,"animation"),ce.addGetterSetter(fs,"animations"),ce.addGetterSetter(fs,"frameOffsets"),ce.addGetterSetter(fs,"image"),ce.addGetterSetter(fs,"frameIndex",0,dt()),ce.addGetterSetter(fs,"frameRate",17,dt()),ce.backCompat(fs,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});var Xa=class extends ct{_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)}};Xa.prototype.className="Star",Xa.prototype._centroid=!0,Xa.prototype._attrsAffectingSize=["innerRadius","outerRadius"],vr(Xa),ce.addGetterSetter(Xa,"numPoints",5,dt()),ce.addGetterSetter(Xa,"innerRadius",0,dt()),ce.addGetterSetter(Xa,"outerRadius",0,dt());function Qa(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 cu="auto",EO="center",G4="inherit",yf="justify",xO="Change.konva",W4="2d",K4="-",q4="left",TO="text",RO="Text",MO="top",LO="bottom",Y4="middle",X4="normal",DO="px ",Bp=" ",PO="right",Q4="rtl",OO="word",FO="char",Z4="none",k0="…",J4=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],BO=J4.length,bf=null;function NO(){if(bf!==null)return bf;bf=!1;try{const e=document.createElement("canvas");e.width=10,e.height=10;const t=e.getContext(W4);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){bf=!0;break}}}catch{}return bf}function zO(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 Np;function A0(){return Np||(Np=Ie.createCanvasElement().getContext(W4),Np)}function HO(e){e.fillText(this._partialText,this._partialTextX,this._partialTextY)}function UO(e){e.setAttr("miterLimit",2),e.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function VO(e){return e=e||{},!e.fillLinearGradientColorStops&&!e.fillRadialGradientColorStops&&!e.fillPatternImage&&(e.fill=e.fill||"black"),e}var Jn=class extends ct{constructor(e){super(VO(e)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<BO;t++)this.on(J4[t]+xO,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(),u=this.direction(),c=0,d=this.align(),h=this.getWidth(),m=this.letterSpacing(),p=this.charRenderFunc(),g=this.fill(),k=this.textDecoration(),w=this.underlineOffset(),S=k.indexOf("underline")!==-1,y=k.indexOf("line-through")!==-1,C;u=u===G4?e.direction:u;let T=a/2,R=Y4;if(!vt.legacyTextRendering){const M=this.measureSize("M");R="alphabetic",T=(((t=M.fontBoundingBoxAscent)!==null&&t!==void 0?t:M.actualBoundingBoxAscent)-((n=M.fontBoundingBoxDescent)!==null&&n!==void 0?n:M.actualBoundingBoxDescent))/2+a/2}for(u===Q4&&e.setAttr("direction",u),e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",R),e.setAttr("textAlign",q4),l===Y4?c=(this.getHeight()-o*a-i*2)/2:l===LO&&(c=this.getHeight()-o*a-i*2),e.translate(i,c+i),C=0;C<o;C++){let M=0,H=0;const B=r[C],z=B.text,X=B.width,P=B.lastInParagraph;if(e.save(),d===PO?M+=h-X-i*2:d===EO&&(M+=(h-X-i*2)/2),S){e.save(),e.beginPath();const I=w??(vt.legacyTextRendering?Math.round(s/2):Math.round(s/4)),L=M,Y=T+H+I;e.moveTo(L,Y);const te=d===yf&&!P?h-i*2:X;e.lineTo(L+Math.round(te),Y),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||g,e.stroke(),e.restore()}const N=M;if(u!==Q4&&(m!==0||d===yf||p)){const I=z.split(" ").length-1,L=Qa(z);for(let Y=0;Y<L.length;Y++){const te=L[Y];if(te===" "&&!P&&d===yf&&(M+=(h-i*2-X)/I),this._partialTextX=M,this._partialTextY=T+H,this._partialText=te,p){e.save();const le=r.slice(0,C).reduce((fe,Ne)=>fe+Qa(Ne.text).length,0);p({char:te,index:Y+le,x:M,y:T+H,lineIndex:C,column:Y,isLastInLine:P,width:this.measureSize(te).width,context:e})}e.fillStrokeShape(this),p&&e.restore(),M+=this.measureSize(te).width+m}}else m!==0&&e.setAttr("letterSpacing",`${m}px`),this._partialTextX=M,this._partialTextY=T+H,this._partialText=z,e.fillStrokeShape(this);if(y){e.save(),e.beginPath();const I=vt.legacyTextRendering?0:-Math.round(s/4),L=N;e.moveTo(L,T+H+I);const Y=d===yf&&!P?h-i*2:X;e.lineTo(L+Math.round(Y),T+H+I),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||g,e.stroke(),e.restore()}e.restore(),o>1&&(T+=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=Ie._isString(e)?e:e==null?"":e+"";return this._setAttr(TO,t),this}getWidth(){return this.attrs.width===cu||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===cu||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return Ie.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,u,c,d;let h=A0(),m=this.fontSize(),p;h.save(),h.font=this._getContextFont(),p=h.measureText(e),h.restore();const g=m/100;return{actualBoundingBoxAscent:(t=p.actualBoundingBoxAscent)!==null&&t!==void 0?t:71.58203125*g,actualBoundingBoxDescent:(n=p.actualBoundingBoxDescent)!==null&&n!==void 0?n:0,actualBoundingBoxLeft:(r=p.actualBoundingBoxLeft)!==null&&r!==void 0?r:-7.421875*g,actualBoundingBoxRight:(o=p.actualBoundingBoxRight)!==null&&o!==void 0?o:75.732421875*g,alphabeticBaseline:(i=p.alphabeticBaseline)!==null&&i!==void 0?i:0,emHeightAscent:(s=p.emHeightAscent)!==null&&s!==void 0?s:100*g,emHeightDescent:(a=p.emHeightDescent)!==null&&a!==void 0?a:-20*g,fontBoundingBoxAscent:(l=p.fontBoundingBoxAscent)!==null&&l!==void 0?l:91*g,fontBoundingBoxDescent:(u=p.fontBoundingBoxDescent)!==null&&u!==void 0?u:21*g,hangingBaseline:(c=p.hangingBaseline)!==null&&c!==void 0?c:72.80000305175781*g,ideographicBaseline:(d=p.ideographicBaseline)!==null&&d!==void 0?d:-21*g,width:p.width,height:m}}_getContextFont(){return this.fontStyle()+Bp+this.fontVariant()+Bp+(this.fontSize()+DO)+zO(this.fontFamily())}_addTextLine(e){this.align()===yf&&(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 A0().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!==cu&&o!==void 0,a=i!==cu&&i!==void 0,l=this.padding(),u=o-l*2,c=i-l*2,d=0,h=this.wrap(),m=h!==FO&&h!==Z4,p=this.ellipsis();this.textArr=[],A0().font=this._getContextFont();const g=p?this._getTextWidth(k0):0;for(let k=0,w=e.length;k<w;++k){let S=e[k],y=this._getTextWidth(S);if(s&&y>u)for(;S.length>0;){let C=0,T=Qa(S).length,R="",M=0;for(;C<T;){const H=C+T>>>1,B=Qa(S).slice(0,H+1).join(""),z=this._getTextWidth(B);(p&&a&&d+r>c?z+g:z)<=u?(C=H+1,R=B,M=z):T=H}if(R){if(m){const H=Qa(S),B=Qa(R),z=H[B.length],X=z===Bp||z===K4;let P;if(X&&M<=u)P=B.length;else{const N=B.lastIndexOf(Bp),I=B.lastIndexOf(K4);P=Math.max(N,I)+1}P>0&&(C=P,R=H.slice(0,C).join(""),M=this._getTextWidth(R))}if(R=R.trimRight(),this._addTextLine(R),n=Math.max(n,M),d+=r,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if(S=Qa(S).slice(C).join("").trimLeft(),S.length>0&&(y=this._getTextWidth(S),y<=u)){this._addTextLine(S),d+=r,n=Math.max(n,y);break}}else break}else this._addTextLine(S),d+=r,n=Math.max(n,y),this._shouldHandleEllipsis(d)&&k<w-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&d+r>c)break}this.textHeight=t,this.textWidth=n}_shouldHandleEllipsis(e){const t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.height,o=r!==cu&&r!==void 0,i=r-this.padding()*2;return this.wrap()===Z4||o&&e+n>i}_tryToAddEllipsisToLastLine(){const e=this.attrs.width,t=e!==cu&&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+k0)<n||(o.text=o.text.slice(0,o.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(o.text+k0))}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&&NO()?!0:super._useBufferCanvas()}};Jn.prototype._fillFunc=HO,Jn.prototype._strokeFunc=UO,Jn.prototype.className=RO,Jn.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],vr(Jn),ce.overWriteSetter(Jn,"width",s0()),ce.overWriteSetter(Jn,"height",s0()),ce.addGetterSetter(Jn,"direction",G4),ce.addGetterSetter(Jn,"fontFamily","Arial"),ce.addGetterSetter(Jn,"fontSize",12,dt()),ce.addGetterSetter(Jn,"fontStyle",X4),ce.addGetterSetter(Jn,"fontVariant",X4),ce.addGetterSetter(Jn,"padding",0,dt()),ce.addGetterSetter(Jn,"align",q4),ce.addGetterSetter(Jn,"verticalAlign",MO),ce.addGetterSetter(Jn,"lineHeight",1,dt()),ce.addGetterSetter(Jn,"wrap",OO),ce.addGetterSetter(Jn,"ellipsis",!1,ji()),ce.addGetterSetter(Jn,"letterSpacing",0,dt()),ce.addGetterSetter(Jn,"text","",jl()),ce.addGetterSetter(Jn,"textDecoration",""),ce.addGetterSetter(Jn,"underlineOffset",void 0,dt()),ce.addGetterSetter(Jn,"charRenderFunc",void 0);var jO="",$4="normal";function ek(e){e.fillText(this.partialText,0,0)}function tk(e){e.strokeText(this.partialText,0,0)}var Kr=class extends ct{constructor(e){super(e),this.dummyCanvas=Ie.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 xi.getPathLength(this.dataArray)}_getPointAtLength(e){return!this.attrs.data||e>this.pathLength?null:xi.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=xi.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 Ie.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(e){return Jn.prototype.setText.call(this,e)}_getContextFont(){return Jn.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=Qa(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),u=Math.max(this.textWidth+((this.attrs.text||"").length-1)*i,0);let c=0;s==="center"&&(c=Math.max(0,this.pathLength/2-u/2)),s==="right"&&(c=Math.max(0,this.pathLength-u));let d=c;for(let h=0;h<t.length;h++){const m=this._getPointAtLength(d);if(!m)return;const p=t[h].char;let g=t[h].width+i;if(p===" "&&s==="justify"){const R=this.text().split(" ").length-1;g+=(this.pathLength-u)/R}const k=d+g,w=this._getPointAtLength(k>this.pathLength&&k-this.pathLength<=l?this.pathLength:k);if(!w)return;const S=xi.getLineLength(m.x,m.y,w.x,w.y);let y=0;if(a)try{y=a(t[h-1].char,p)*this.fontSize()}catch{y=0}m.x+=y,w.x+=y,this.textWidth+=y;const C=xi.getPointOnLine(y+S/2,m.x,m.y,w.x,w.y),T=Math.atan2(w.y-m.y,w.x-m.x);this.glyphInfo.push({transposeX:C.x,transposeY:C.y,text:e[h],rotation:T,p0:m,p1:w,width:S}),d+=g}}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 Ie.releaseCanvas(this.dummyCanvas),super.destroy()}};Kr.prototype._fillFunc=ek,Kr.prototype._strokeFunc=tk,Kr.prototype._fillFuncHit=ek,Kr.prototype._strokeFuncHit=tk,Kr.prototype.className="TextPath",Kr.prototype._attrsAffectingSize=["text","fontSize","data"],vr(Kr),ce.addGetterSetter(Kr,"data"),ce.addGetterSetter(Kr,"fontFamily","Arial"),ce.addGetterSetter(Kr,"fontSize",12,dt()),ce.addGetterSetter(Kr,"fontStyle",$4),ce.addGetterSetter(Kr,"align","left"),ce.addGetterSetter(Kr,"letterSpacing",0,dt()),ce.addGetterSetter(Kr,"textBaseline","middle"),ce.addGetterSetter(Kr,"fontVariant",$4),ce.addGetterSetter(Kr,"text",jO),ce.addGetterSetter(Kr,"textDecoration",""),ce.addGetterSetter(Kr,"kerningFunc",void 0);var nk="tr-konva",GO=["resizeEnabledChange","rotateAnchorOffsetChange","rotateAnchorAngleChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(e=>e+`.${nk}`).join(" "),rk="nodesRect",WO=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],KO={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},qO="ontouchstart"in vt._global;function YO(e,t,n){if(e==="rotater")return n;t+=Ie.degToRad(KO[e]||0);const r=(Ie.radToDeg(t)%360+360)%360;return Ie._inRange(r,337.5,360)||Ie._inRange(r,0,22.5)?"ns-resize":Ie._inRange(r,22.5,67.5)?"nesw-resize":Ie._inRange(r,67.5,112.5)?"ew-resize":Ie._inRange(r,112.5,157.5)?"nwse-resize":Ie._inRange(r,157.5,202.5)?"ns-resize":Ie._inRange(r,202.5,247.5)?"nesw-resize":Ie._inRange(r,247.5,292.5)?"ew-resize":Ie._inRange(r,292.5,337.5)?"nwse-resize":(Ie.error("Transformer has unknown angle for cursor detection: "+r),"pointer")}var zp=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"],ok=1e8;function XO(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 ik(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 QO(e,t){return ik(e,t,XO(e))}function ZO(e,t,n){let r=t;for(let o=0;o<e.length;o++){const i=vt.getAngle(e[o]),s=Math.abs(i-t)%(Math.PI*2);Math.min(s,Math.PI*2-s)<n&&(r=i)}return r}var I0=0,Sn=class extends su{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(GO,this.update),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return Ie.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 nk+this._id}setNodes(e=[]){return this._nodes&&this._nodes.length&&this.detach(),this._nodes=e=e.filter(t=>t.isAncestorOf(this)?(Ie.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0),e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(t=>{const n=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(t._attrsAffectingSize.length){const r=t._attrsAffectingSize.map(o=>o+"Change."+this._getEventNamespace()).join(" ");t.on(r,n)}t.on(WO.map(r=>r+`.${this._getEventNamespace()}`).join(" "),n),t.on(`absoluteTransformChange.${this._getEventNamespace()}`,n),this._proxyDrag(t)}),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(rk),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(rk,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=(vt.getAngle(e.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2);return ik({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},-vt.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-ok,y:-ok,width:0,height:0,rotation:0};const e=[];this.nodes().map(a=>{const l=a.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),u=[{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}],c=a.getAbsoluteTransform();u.forEach(function(d){const h=c.point(d);e.push(h)})});const t=new Vi;t.rotate(-vt.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:vt.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(),zp.forEach(e=>{this._createAnchor(e)}),this._createAnchor("rotater"),this._elementsCreated=!0}_createAnchor(e){const t=new vf({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:e+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:qO?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=YO(e,vt.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 ct({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(),u=Ie.degToRad(a),c=Math.sin(u),d=-Math.cos(u),h=i/2,m=s/2;let p=1/0;d<0?p=Math.min(p,-m/d):d>0&&(p=Math.min(p,(s-m)/d)),c<0?p=Math.min(p,-h/c):c>0&&(p=Math.min(p,(i-h)/c));const g=h+c*p,k=m+d*p,w=Ie._sign(s),S=g+c*l*w,y=k+d*l*w;t.moveTo(g,k),t.lineTo(S,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},I0++,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 u=o.getAbsolutePosition();if(l.x===u.x&&l.y===u.y)return;if(this._movingAnchorName==="rotater"){const w=this._getNodeRect();t=o.x()-w.width/2,n=-o.y()+w.height/2;const S=vt.getAngle(this.rotateAnchorAngle());let y=Math.atan2(-n,t)+Math.PI/2-S;w.height<0&&(y-=Math.PI);const C=vt.getAngle(this.rotation())+y,T=vt.getAngle(this.rotationSnapTolerance()),R=QO(w,ZO(this.rotationSnaps(),C,T)-w.rotation);this._fitNodesInto(R,e);return}const c=this.shiftBehavior();let d;c==="inverted"?d=this.keepRatio()&&!e.shiftKey:c==="none"?d=this.keepRatio():d=this.keepRatio()||e.shiftKey;let h=this.centeredScaling()||e.altKey;if(this._movingAnchorName==="top-left"){if(d){const w=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(w.x-o.x(),2)+Math.pow(w.y-o.y(),2));const S=this.findOne(".top-left").x()>w.x?-1:1,y=this.findOne(".top-left").y()>w.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".top-left").x(w.x-t),this.findOne(".top-left").y(w.y-n)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(o.y());else if(this._movingAnchorName==="top-right"){if(d){const w=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()-w.x,2)+Math.pow(w.y-o.y(),2));const S=this.findOne(".top-right").x()<w.x?-1:1,y=this.findOne(".top-right").y()>w.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".top-right").x(w.x+t),this.findOne(".top-right").y(w.y-n)}var m=o.position();this.findOne(".top-left").y(m.y),this.findOne(".bottom-right").x(m.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 w=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(w.x-o.x(),2)+Math.pow(o.y()-w.y,2));const S=w.x<o.x()?-1:1,y=o.y()<w.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,o.x(w.x-t),o.y(w.y+n)}m=o.position(),this.findOne(".top-left").x(m.x),this.findOne(".bottom-right").y(m.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(o.y());else if(this._movingAnchorName==="bottom-right"){if(d){const w=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()-w.x,2)+Math.pow(o.y()-w.y,2));const S=this.findOne(".bottom-right").x()<w.x?-1:1,y=this.findOne(".bottom-right").y()<w.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".bottom-right").x(w.x+t),this.findOne(".bottom-right").y(w.y+n)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(h=this.centeredScaling()||e.altKey,h){const w=this.findOne(".top-left"),S=this.findOne(".bottom-right"),y=w.x(),C=w.y(),T=this.getWidth()-S.x(),R=this.getHeight()-S.y();S.move({x:-y,y:-C}),w.move({x:T,y:R})}const p=this.findOne(".top-left").getAbsolutePosition();t=p.x,n=p.y;const g=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:g,height:k,rotation:vt.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();I0--,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(Ie._inRange(e.width,-this.padding()*2-r,r)){this.update();return}if(Ie._inRange(e.height,-this.padding()*2-r,r)){this.update();return}const o=new Vi;if(o.rotate(vt.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:Ie.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const i=1e7,s=new Vi;s.translate(n.x,n.y),s.rotate(n.rotation),s.scale(n.width/i,n.height/i);const a=new Vi,l=e.width/i,u=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(u))):(a.translate(e.x,e.y),a.rotate(e.rotation),a.scale(l,u));const c=a.multiply(s.invert());this._nodes.forEach(d=>{var h;if(!d.getStage())return;const m=d.getParent().getAbsoluteTransform(),p=d.getTransform().copy();p.translate(d.offsetX(),d.offsetY());const g=new Vi;g.multiply(m.copy().invert()).multiply(c).multiply(m).multiply(p);const k=g.decompose();d.setAttrs(k),(h=d.getLayer())===null||h===void 0||h.batchDraw()}),this.rotation(Ie._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(Ie._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(T=>{T.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 u=this.rotateAnchorAngle(),c=this.rotateAnchorOffset(),d=Ie.degToRad(u),h=Math.sin(d),m=-Math.cos(d),p=n/2,g=r/2;let k=1/0;m<0?k=Math.min(k,-g/m):m>0&&(k=Math.min(k,(r-g)/m)),h<0?k=Math.min(k,-p/h):h>0&&(k=Math.min(k,(n-p)/h));const w=p+h*k,S=g+m*k,y=Ie._sign(r);this._batchChangeChild(".rotater",{x:w+h*c*y,y:S+m*c*y-s*m,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(T=>T.draggable()),x:0,y:0});const C=this.anchorStyleFunc();C&&l.forEach(T=>{C(T)}),(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=""),su.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}add(...e){return this._elementsCreated?(Ie.error("You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead."),this):super.add(...e)}toObject(){return wt.prototype.toObject.call(this)}clone(e){return wt.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}};Sn.isTransforming=()=>I0>0;function JO(e){return e instanceof Array||Ie.warn("enabledAnchors value should be an array"),e instanceof Array&&e.forEach(function(t){zp.indexOf(t)===-1&&Ie.warn("Unknown anchor name: "+t+". Available names are: "+zp.join(", "))}),e||[]}Sn.prototype.className="Transformer",vr(Sn),ce.addGetterSetter(Sn,"enabledAnchors",zp,JO),ce.addGetterSetter(Sn,"flipEnabled",!0,ji()),ce.addGetterSetter(Sn,"resizeEnabled",!0),ce.addGetterSetter(Sn,"anchorSize",10,dt()),ce.addGetterSetter(Sn,"rotateEnabled",!0),ce.addGetterSetter(Sn,"rotateLineVisible",!0),ce.addGetterSetter(Sn,"rotationSnaps",[]),ce.addGetterSetter(Sn,"rotateAnchorOffset",50,dt()),ce.addGetterSetter(Sn,"rotateAnchorAngle",0,dt()),ce.addGetterSetter(Sn,"rotateAnchorCursor","crosshair"),ce.addGetterSetter(Sn,"rotationSnapTolerance",5,dt()),ce.addGetterSetter(Sn,"borderEnabled",!0),ce.addGetterSetter(Sn,"anchorStroke","rgb(0, 161, 255)"),ce.addGetterSetter(Sn,"anchorStrokeWidth",1,dt()),ce.addGetterSetter(Sn,"anchorFill","white"),ce.addGetterSetter(Sn,"anchorCornerRadius",0,dt()),ce.addGetterSetter(Sn,"borderStroke","rgb(0, 161, 255)"),ce.addGetterSetter(Sn,"borderStrokeWidth",1,dt()),ce.addGetterSetter(Sn,"borderDash"),ce.addGetterSetter(Sn,"keepRatio",!0),ce.addGetterSetter(Sn,"shiftBehavior","default"),ce.addGetterSetter(Sn,"centeredScaling",!1),ce.addGetterSetter(Sn,"ignoreStroke",!1),ce.addGetterSetter(Sn,"padding",0,dt()),ce.addGetterSetter(Sn,"nodes"),ce.addGetterSetter(Sn,"node"),ce.addGetterSetter(Sn,"boundBoxFunc"),ce.addGetterSetter(Sn,"anchorDragBoundFunc"),ce.addGetterSetter(Sn,"anchorStyleFunc"),ce.addGetterSetter(Sn,"shouldOverdrawWholeArea",!1),ce.addGetterSetter(Sn,"useSingleNodeRotation",!0),ce.backCompat(Sn,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});var ta=class extends ct{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,vt.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)}};ta.prototype.className="Wedge",ta.prototype._centroid=!0,ta.prototype._attrsAffectingSize=["radius"],vr(ta),ce.addGetterSetter(ta,"radius",0,dt()),ce.addGetterSetter(ta,"angle",0,dt()),ce.addGetterSetter(ta,"clockwise",!1),ce.backCompat(ta,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});function sk(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var $O=[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],eF=[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 tF(e,t){const n=e.data,r=e.width,o=e.height;let i,s,a,l,u,c,d,h,m,p,g,k,w,S,y,C,T,R,M,H;const B=t+t+1,z=r-1,X=o-1,P=t+1,N=P*(P+1)/2,I=new sk,L=$O[t],Y=eF[t];let te=null,le=I,fe=null,Ne=null;for(let he=1;he<B;he++)le=le.next=new sk,he===P&&(te=le);le.next=I,a=s=0;for(let he=0;he<o;he++){k=w=S=y=l=u=c=d=0,h=P*(C=n[s]),m=P*(T=n[s+1]),p=P*(R=n[s+2]),g=P*(M=n[s+3]),l+=N*C,u+=N*T,c+=N*R,d+=N*M,le=I;for(let ge=0;ge<P;ge++)le.r=C,le.g=T,le.b=R,le.a=M,le=le.next;for(let ge=1;ge<P;ge++)i=s+((z<ge?z:ge)<<2),l+=(le.r=C=n[i])*(H=P-ge),u+=(le.g=T=n[i+1])*H,c+=(le.b=R=n[i+2])*H,d+=(le.a=M=n[i+3])*H,k+=C,w+=T,S+=R,y+=M,le=le.next;fe=I,Ne=te;for(let ge=0;ge<r;ge++)n[s+3]=M=d*L>>Y,M!==0?(M=255/M,n[s]=(l*L>>Y)*M,n[s+1]=(u*L>>Y)*M,n[s+2]=(c*L>>Y)*M):n[s]=n[s+1]=n[s+2]=0,l-=h,u-=m,c-=p,d-=g,h-=fe.r,m-=fe.g,p-=fe.b,g-=fe.a,i=a+((i=ge+t+1)<z?i:z)<<2,k+=fe.r=n[i],w+=fe.g=n[i+1],S+=fe.b=n[i+2],y+=fe.a=n[i+3],l+=k,u+=w,c+=S,d+=y,fe=fe.next,h+=C=Ne.r,m+=T=Ne.g,p+=R=Ne.b,g+=M=Ne.a,k-=C,w-=T,S-=R,y-=M,Ne=Ne.next,s+=4;a+=r}for(let he=0;he<r;he++){w=S=y=k=u=c=d=l=0,s=he<<2,h=P*(C=n[s]),m=P*(T=n[s+1]),p=P*(R=n[s+2]),g=P*(M=n[s+3]),l+=N*C,u+=N*T,c+=N*R,d+=N*M,le=I;for(let ae=0;ae<P;ae++)le.r=C,le.g=T,le.b=R,le.a=M,le=le.next;let ge=r;for(let ae=1;ae<=t;ae++)s=ge+he<<2,l+=(le.r=C=n[s])*(H=P-ae),u+=(le.g=T=n[s+1])*H,c+=(le.b=R=n[s+2])*H,d+=(le.a=M=n[s+3])*H,k+=C,w+=T,S+=R,y+=M,le=le.next,ae<X&&(ge+=r);s=he,fe=I,Ne=te;for(let ae=0;ae<o;ae++)i=s<<2,n[i+3]=M=d*L>>Y,M>0?(M=255/M,n[i]=(l*L>>Y)*M,n[i+1]=(u*L>>Y)*M,n[i+2]=(c*L>>Y)*M):n[i]=n[i+1]=n[i+2]=0,l-=h,u-=m,c-=p,d-=g,h-=fe.r,m-=fe.g,p-=fe.b,g-=fe.a,i=he+((i=ae+P)<X?i:X)*r<<2,l+=k+=fe.r=n[i],u+=w+=fe.g=n[i+1],c+=S+=fe.b=n[i+2],d+=y+=fe.a=n[i+3],fe=fe.next,h+=C=Ne.r,m+=T=Ne.g,p+=R=Ne.b,g+=M=Ne.a,k-=C,w-=T,S-=R,y-=M,Ne=Ne.next,s+=r}}const nF=function(t){const n=Math.round(this.blurRadius());n>0&&tF(t,n)};ce.addGetterSetter(wt,"blurRadius",0,dt(),ce.afterSetFilter);const rF=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};ce.addGetterSetter(wt,"brightness",0,dt(),ce.afterSetFilter);const oF=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};ce.addGetterSetter(wt,"contrast",0,dt(),ce.afterSetFilter);const sF=function(e){var t,n,r,o,i,s,a,l,u;const c=e.data,d=e.width,h=e.height,m=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)),g=(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=!!((u=(l=this.embossBlend)===null||l===void 0?void 0:l.call(this))!==null&&u!==void 0&&u),w=m*10,S=p*255,y=g*Math.PI/180,C=Math.cos(y),T=Math.sin(y),R=128/1020*w,M=new Uint8ClampedArray(c),H=new Float32Array(d*h);for(let N=0,I=0;I<c.length;I+=4,N++)H[N]=.2126*M[I]+.7152*M[I+1]+.0722*M[I+2];const B=[-1,0,1,-2,0,2,-1,0,1],z=[-1,-2,-1,0,0,0,1,2,1],X=[-d-1,-d,-d+1,-1,0,1,d-1,d,d+1],P=N=>N<0?0:N>255?255:N;for(let N=1;N<h-1;N++)for(let I=1;I<d-1;I++){const L=N*d+I;let Y=0,te=0;Y+=H[L+X[0]]*B[0],te+=H[L+X[0]]*z[0],Y+=H[L+X[1]]*B[1],te+=H[L+X[1]]*z[1],Y+=H[L+X[2]]*B[2],te+=H[L+X[2]]*z[2],Y+=H[L+X[3]]*B[3],te+=H[L+X[3]]*z[3],Y+=H[L+X[5]]*B[5],te+=H[L+X[5]]*z[5],Y+=H[L+X[6]]*B[6],te+=H[L+X[6]]*z[6],Y+=H[L+X[7]]*B[7],te+=H[L+X[7]]*z[7],Y+=H[L+X[8]]*B[8],te+=H[L+X[8]]*z[8];const le=P(S+(C*Y+T*te)*R),fe=L*4;if(k){const Ne=le-S;c[fe]=P(M[fe]+Ne),c[fe+1]=P(M[fe+1]+Ne),c[fe+2]=P(M[fe+2]+Ne),c[fe+3]=M[fe+3]}else c[fe]=c[fe+1]=c[fe+2]=le,c[fe+3]=M[fe+3]}for(let N=0;N<d;N++){let I=N*4,L=((h-1)*d+N)*4;c[I]=M[I],c[I+1]=M[I+1],c[I+2]=M[I+2],c[I+3]=M[I+3],c[L]=M[L],c[L+1]=M[L+1],c[L+2]=M[L+2],c[L+3]=M[L+3]}for(let N=1;N<h-1;N++){let I=N*d*4,L=(N*d+(d-1))*4;c[I]=M[I],c[I+1]=M[I+1],c[I+2]=M[I+2],c[I+3]=M[I+3],c[L]=M[L],c[L+1]=M[L+1],c[L+2]=M[L+2],c[L+3]=M[L+3]}return e};ce.addGetterSetter(wt,"embossStrength",.5,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"embossWhiteLevel",.5,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"embossDirection","top-left",void 0,ce.afterSetFilter),ce.addGetterSetter(wt,"embossBlend",!1,void 0,ce.afterSetFilter);function E0(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}const aF=function(e){const t=e.data,n=t.length;let r=t[0],o=r,i,s=t[1],a=s,l,u=t[2],c=u,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<u?u=d:d>c&&(c=d);o===r&&(o=255,r=0),a===s&&(a=255,s=0),c===u&&(c=255,u=0);let m,p,g,k,w,S;if(h>0)m=o+h*(255-o),p=r-h*(r-0),g=a+h*(255-a),k=s-h*(s-0),w=c+h*(255-c),S=u-h*(u-0);else{const y=(o+r)*.5;m=o+h*(o-y),p=r+h*(r-y);const C=(a+s)*.5;g=a+h*(a-C),k=s+h*(s-C);const T=(c+u)*.5;w=c+h*(c-T),S=u+h*(u-T)}for(let y=0;y<n;y+=4)t[y+0]=E0(t[y+0],r,o,p,m),t[y+1]=E0(t[y+1],s,a,k,g),t[y+2]=E0(t[y+2],u,c,S,w)};ce.addGetterSetter(wt,"enhance",0,dt(),ce.afterSetFilter);const lF=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}};ce.addGetterSetter(wt,"hue",0,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"saturation",0,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"luminance",0,dt(),ce.afterSetFilter);const cF=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),u=.299*r+.701*a+.167*l,c=.587*r-.587*a+.33*l,d=.114*r-.114*a-.497*l,h=.299*r-.299*a-.328*l,m=.587*r+.413*a+.035*l,p=.114*r-.114*a+.293*l,g=.299*r-.3*a+1.25*l,k=.587*r-.586*a-1.05*l,w=.114*r+.886*a-.2*l;let S,y,C,T;for(let R=0;R<n;R+=4)S=t[R+0],y=t[R+1],C=t[R+2],T=t[R+3],t[R+0]=u*S+c*y+d*C+s,t[R+1]=h*S+m*y+p*C+s,t[R+2]=g*S+k*y+w*C+s,t[R+3]=T},uF=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,u=.587*r-.587*s+.33*a,c=.114*r-.114*s-.497*a,d=.299*r-.299*s-.328*a,h=.587*r+.413*s+.035*a,m=.114*r-.114*s+.293*a,p=.299*r-.3*s+1.25*a,g=.587*r-.586*s-1.05*a,k=.114*r+.886*s-.2*a;for(let w=0;w<n;w+=4){const S=t[w+0],y=t[w+1],C=t[w+2],T=t[w+3];t[w+0]=l*S+u*y+c*C,t[w+1]=d*S+h*y+m*C,t[w+2]=p*S+g*y+k*C,t[w+3]=T}};ce.addGetterSetter(wt,"hue",0,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"saturation",0,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"value",0,dt(),ce.afterSetFilter);const dF=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]};var fF=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 u=Math.sqrt(a*a+l*l),c=i-a,d=s-l;const h=Math.sqrt(c*c+d*d);u=h>u?h:u;const m=s,p=i,g=360/p*Math.PI/180;for(let k=0;k<p;k+=1){const w=Math.sin(k*g),S=Math.cos(k*g);for(let y=0;y<m;y+=1){c=Math.floor(a+u*y/m*S),d=Math.floor(l+u*y/m*w);let C=(d*i+c)*4;const T=r[C+0],R=r[C+1],M=r[C+2],H=r[C+3];C=(k+y*i)*4,o[C+0]=T,o[C+1]=R,o[C+2]=M,o[C+3]=H}}},hF=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 u=Math.sqrt(a*a+l*l),c=i-a,d=s-l;const h=Math.sqrt(c*c+d*d);u=h>u?h:u;const m=s,p=i,g=n.polarRotation||0;let k,w;for(c=0;c<i;c+=1)for(d=0;d<s;d+=1){const S=c-a,y=d-l,C=Math.sqrt(S*S+y*y)*m/u;let T=(Math.atan2(y,S)*180/Math.PI+360+g)%360;T=T*p/360,k=Math.floor(T),w=Math.floor(C);let R=(w*i+k)*4;const M=r[R+0],H=r[R+1],B=r[R+2],z=r[R+3];R=(d*i+c)*4,o[R+0]=M,o[R+1]=H,o[R+2]=B,o[R+3]=z}};const pF=function(e){const t=e.width,n=e.height;let r,o,i,s,a,l,u,c,d,h,m=Math.round(this.kaleidoscopePower());const p=Math.round(this.kaleidoscopeAngle()),g=Math.floor(t*(p%360)/360);if(m<1)return;const k=Ie.createCanvasElement();k.width=t,k.height=n;const w=k.getContext("2d").getImageData(0,0,t,n);Ie.releaseCanvas(k),fF(e,w,{polarCenterX:t/2,polarCenterY:n/2});let S=t/Math.pow(2,m);for(;S<=8;)S=S*2,m-=1;S=Math.ceil(S);let y=S,C=0,T=y,R=1;for(g+S>t&&(C=y,T=0,R=-1),o=0;o<n;o+=1)for(r=C;r!==T;r+=R)i=Math.round(r+g)%t,d=(t*o+i)*4,a=w.data[d+0],l=w.data[d+1],u=w.data[d+2],c=w.data[d+3],h=(t*o+r)*4,w.data[h+0]=a,w.data[h+1]=l,w.data[h+2]=u,w.data[h+3]=c;for(o=0;o<n;o+=1)for(y=Math.floor(S),s=0;s<m;s+=1){for(r=0;r<y+1;r+=1)d=(t*o+r)*4,a=w.data[d+0],l=w.data[d+1],u=w.data[d+2],c=w.data[d+3],h=(t*o+y*2-r-1)*4,w.data[h+0]=a,w.data[h+1]=l,w.data[h+2]=u,w.data[h+3]=c;y*=2}hF(w,e,{polarRotation:0})};ce.addGetterSetter(wt,"kaleidoscopePower",2,dt(),ce.afterSetFilter),ce.addGetterSetter(wt,"kaleidoscopeAngle",0,dt(),ce.afterSetFilter);function Hp(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 wf(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 mF(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 gF(e,t){const n=Hp(e,0,0),r=Hp(e,e.width-1,0),o=Hp(e,0,e.height-1),i=Hp(e,e.width-1,e.height-1),s=t||10;if(wf(n,r)<s&&wf(r,i)<s&&wf(i,o)<s&&wf(o,n)<s){const a=mF([r,n,i,o]),l=[];for(let u=0;u<e.width*e.height;u++)l[u]=wf(a,[e.data[u*4],e.data[u*4+1],e.data[u*4+2]])<s?0:255;return l}}function vF(e,t){for(let n=0;n<e.width*e.height;n++)e.data[4*n+3]=t[n]}function yF(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 u=a*t+l;let c=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const m=a+d-i,p=l+h-i;if(m>=0&&m<n&&p>=0&&p<t){const g=m*t+p,k=r[d*o+h];c+=e[g]*k}}s[u]=c===2040?255:0}return s}function bF(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 u=a*t+l;let c=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const m=a+d-i,p=l+h-i;if(m>=0&&m<n&&p>=0&&p<t){const g=m*t+p,k=r[d*o+h];c+=e[g]*k}}s[u]=c>=1020?255:0}return s}function wF(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 u=a*t+l;let c=0;for(let d=0;d<o;d++)for(let h=0;h<o;h++){const m=a+d-i,p=l+h-i;if(m>=0&&m<n&&p>=0&&p<t){const g=m*t+p,k=r[d*o+h];c+=e[g]*k}}s[u]=c}return s}const CF=function(e){let t=gF(e,this.threshold());return t&&(t=yF(t,e.width,e.height),t=bF(t,e.width,e.height),t=wF(t,e.width,e.height),vF(e,t)),e};ce.addGetterSetter(wt,"threshold",0,dt(),ce.afterSetFilter);const _F=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()};ce.addGetterSetter(wt,"noise",.2,dt(),ce.afterSetFilter);const SF=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){Ie.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 u=0,c=0,d=0,h=0;const m=a*t,p=m+t,g=l*t,k=g+t;let w=0;for(let S=m;S<p;S+=1)if(!(S>=n))for(let y=g;y<k;y+=1){if(y>=r)continue;const C=(n*y+S)*4;u+=s[C+0],c+=s[C+1],d+=s[C+2],h+=s[C+3],w+=1}u=u/w,c=c/w,d=d/w,h=h/w;for(let S=m;S<p;S+=1)if(!(S>=n))for(let y=g;y<k;y+=1){if(y>=r)continue;const C=(n*y+S)*4;s[C+0]=u,s[C+1]=c,s[C+2]=d,s[C+3]=h}}};ce.addGetterSetter(wt,"pixelSize",8,dt(),ce.afterSetFilter);const kF=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};ce.addGetterSetter(wt,"levels",.5,dt(),ce.afterSetFilter);const AF=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]}};ce.addGetterSetter(wt,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),ce.addGetterSetter(wt,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),ce.addGetterSetter(wt,"blue",0,s4,ce.afterSetFilter);const IF=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}};ce.addGetterSetter(wt,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),ce.addGetterSetter(wt,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),ce.addGetterSetter(wt,"blue",0,s4,ce.afterSetFilter),ce.addGetterSetter(wt,"alpha",1,function(e){return this._filterUpToDate=!1,e>1?1:e<0?0:e});const EF=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)}},xF=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},TF=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};ce.addGetterSetter(wt,"threshold",.5,dt(),ce.afterSetFilter);var RF=B4.Util._assign(B4,{Arc:$s,Arrow:Kl,Circle:lu,Ellipse:qa,Image:Gi,Label:S0,Tag:ql,Line:ea,Path:xi,Rect:vf,RegularPolygon:Ya,Ring:Yl,Sprite:fs,Star:Xa,Text:Jn,TextPath:Kr,Transformer:Sn,Wedge:ta,Filters:{Blur:nF,Brightness:oF,Brighten:rF,Contrast:iF,Emboss:sF,Enhance:aF,Grayscale:lF,HSL:cF,HSV:uF,Invert:dF,Kaleidoscope:pF,Mask:CF,Noise:_F,Pixelate:SF,Posterize:kF,RGB:AF,RGBA:IF,Sepia:EF,Solarize:xF,Threshold:TF}});It();var MF=["dialog","floating"],ak=["top-right","top-left","bottom-right","bottom-left","top-center","bottom-center"];function LF(e){if(!e||typeof e!="object")throw new Error("SurfaceManager: request must be a non-null object.");if(!MF.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&&!ak.includes(e.floating.placement))throw new Error(`SurfaceManager: floating.placement must be one of ${ak.join(", ")}, got "${e.floating.placement}".`)}var DF=class{activeDialog=Wr(null);activeFloating=Wr(null);#t=!1;#n=1;#e;constructor({getModuleConfig:e}){this.#e=e}open(e){if(this.#t)return this.#l(e);LF(e);const t=this.#u(e),{component:n,props:r,render:o}=this.#d(t);let i,s=!1;const a=new Promise(m=>{i=p=>s?!1:(s=!0,m(p),!0)});let l;const u=m=>{i({status:"submitted",data:m})&&this.#s(l)},c=m=>{i({status:"closed",reason:m})&&this.#s(l)};l={id:t.id,mode:t.mode,request:t,component:n,props:r,render:o,resolve:u,close:c,settle:m=>i(m),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:m=>this.#i(l,m),result:a}}close(e,t){if(e!=null){const o=this.#a(e);o&&this.#i(o,t);return}const n=this.activeDialog.value;if(n&&!n.settled){this.#i(n,t);return}const r=this.activeFloating.value;r&&!r.settled&&this.#i(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"})}#i(e,t){e.settled||(e.settle({status:"closed",reason:t}),this.#s(e))}#s(e){const t=e.mode==="dialog"?this.activeDialog:this.activeFloating;t.value===e&&(t.value=null)}#a(e){return this.activeDialog.value?.id===e?this.activeDialog.value:this.activeFloating.value?.id===e?this.activeFloating.value:null}#u(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}}#d(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.`)}#l(e){return{id:e?.id??`surface-${this.#n++}`,mode:e?.mode??"dialog",close:()=>{},result:Promise.resolve({status:"destroyed"})}}},PF="https://docs.superdoc.dev/guides/migration/document-api",lk=new Set;function OF(e,t){lk.has(e)||(lk.add(e),console.warn(t))}var FF={state:"editor.state",view:"editor.view",schema:"editor.schema",commands:"editor.commands",chain:"editor.chain()",can:"editor.can()",dispatch:"editor.dispatch()"},ck=Symbol.for("superdoc:rawEditor"),uk=new WeakMap;function dk(e){return!e||e[ck]?e:new Proxy(e,{get(t,n){if(n===ck)return t;const r=FF[n];r&&OF(`deprecated:${String(n)}`,`[SuperDoc] ${r} is deprecated and will be removed in a future version. Use the Document API (editor.doc) instead. See ${PF}`);const o=Reflect.get(t,n,t);if(typeof o=="function"){let i=uk.get(t);return i||(i=new Map,uk.set(t,i)),i.has(n)||i.set(n,o.bind(t)),i.get(n)}return o}})}var fk=["review","original","final","off"],BF=["paired","independent"],hk=Symbol.for("@superdoc/trackChanges:normalized"),pk=new Set;function mk(e,t){pk.has(e)||(pk.add(e),console.warn(`[SuperDoc] ${e} is deprecated — use ${t} instead.`))}function gk(e,t,n){return typeof e=="boolean"?e:typeof t=="boolean"?t:n}function NF(e,t,n){return typeof e=="string"&&fk.includes(e)?e:typeof t=="string"&&fk.includes(t)?t:n}function zF(e){return typeof e=="string"&&BF.includes(e)?e:null}function Xl(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function HF(e){const t=e[hk]===!0;Xl(e.modules)||(e.modules={});const n=Xl(e.modules.trackChanges),r=Xl(e.trackChanges),o=Xl(e.layoutEngineOptions?.trackedChanges);t||(r&&mk("config.trackChanges","config.modules.trackChanges"),o&&mk("config.layoutEngineOptions.trackedChanges","config.modules.trackChanges"));const i=gk(n?.visible,r?.visible,!1),s=gk(n?.enabled,o?.enabled,!0),a=zF(n?.replacements)??"paired",l=Xl(n?.authorColors)?n.authorColors:void 0,u=Xl(n?.semanticColors)?n.semanticColors:void 0,c=e.documentMode==="viewing"?i?"review":"original":"review",d=NF(n?.mode,o?.mode,c),h={visible:i,mode:d,enabled:s,replacements:a};return l&&(h.authorColors=l),u&&(h.semanticColors=u),e.modules.trackChanges=h,e.trackChanges={visible:i},Xl(e.layoutEngineOptions)||(e.layoutEngineOptions={}),e.layoutEngineOptions.trackedChanges={mode:d,enabled:s},Object.defineProperty(e,hk,{value:!0,writable:!0,configurable:!0,enumerable:!1}),h}const x0=Object.freeze({id:null,name:"Default SuperDoc user",email:null});function UF(e){return!e||typeof e!="object"?{...x0}:{...x0,...e}}function Cf(...e){const t={};for(const n of e)if(!(typeof n!="object"||n===null))for(const[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t}function vk(...e){for(const t of e)if(t!==void 0)return t}var yk=Object.freeze({toolbar:!0,comments:!0,contextMenu:!0,search:!1,linkPopover:!1,ruler:!1,contentControls:!0}),VF=Object.freeze(["left","center","right"]),bj=Object.freeze(Object.keys(yk)),Up=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function bk(e,t){const n=e?.[t];return n===!1?!1:n===void 0?yk[t]:!0}function jF(e,t){const n=e?.[t];return Up(n)?n:{}}function wk(e={}){const t=e.ui,n=t===!1,r=Up(t)?t:void 0,o=w=>!n&&bk(r,w),i=w=>n?!1:r?.[w]===void 0?void 0:bk(r,w),s=w=>n?{}:jF(r,w),a=n||i("ruler")===!1,l=s("toolbar"),u=e.modules?.toolbar,c=Up(u)?u:{},d=[l.groups,c.groups],h=d.find(Up),m=vk(d.find(Array.isArray),c.toolbarGroups,e.toolbarGroups),p=Array.isArray(m)?m:null,g=(w,S)=>Object.prototype.hasOwnProperty.call(w,S),k=h&&p?Object.fromEntries([...p.filter(w=>g(h,w)),...Object.keys(h).filter(w=>!VF.includes(w))].map(w=>[w,h[w]])):h;return{enabled:!n,toolbar:{enabled:o("toolbar"),container:n?null:vk(l.container,c.selector,e.toolbar)??null,options:n?{}:{...Cf(c,l),groups:k,toolbarGroups:m,icons:Cf(e.toolbarIcons,c.icons,l.icons),texts:Cf(e.toolbarTexts,c.texts,l.texts)}},comments:{enabled:i("comments")??(!n&&e.modules?.comments!==!1),options:s("comments")},contextMenu:{enabled:i("contextMenu")??(!n&&e.disableContextMenu!==!0),suppressed:n||i("contextMenu")===!1,options:s("contextMenu")},search:{enabled:i("search")??(!n&&!!e.modules?.surfaces?.findReplace),options:s("search")},linkPopover:{enabled:i("linkPopover")??(!n&&!!e.modules?.links?.popoverResolver),suppressed:n||i("linkPopover")===!1,options:s("linkPopover")},ruler:{enabled:i("ruler")??(!n&&!!e.rulers),suppressed:a,container:a?null:s("ruler").container??e.rulerContainer??null},contentControls:{enabled:i("contentControls")??(!n&&e.modules?.contentControls?.chrome!=="none"),options:s("contentControls")}}}var T0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Ck(e={}){const t=T0(e.interaction)?e.interaction:{},n=T0(t.comments)?t.comments:{},r=T0(e.modules?.comments)?e.modules.comments:{};return{comments:{readOnly:(n.readOnly??r.readOnly??!1)===!0,allowResolve:(n.allowResolve??r.allowResolve??!0)!==!1}}}var _k=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Sk(e={}){const t=_k(e.surfaces)?e.surfaces:{},n=_k(e.modules?.surfaces)?e.modules.surfaces:{},r=t.resolver===void 0?n.resolver:t.resolver;return{resolver:typeof r=="function"?r:null,dialog:Cf(n.dialog,t.dialog),floating:Cf(n.floating,t.floating)}}var GF=class{#t=new Map;#n=new Map;#e=null;#i=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.#s({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.#s({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(`[${wp}]`);if(!n)return null;const r=n.getAttribute(wp),o=r?this.get(r):null;return o&&o.root===n?o:null}subscribe(e){return this.#i.add(e),()=>{this.#i.delete(e)}}clear(){this.#t.clear(),this.#n.clear(),this.#e=null,this.#i.clear()}#s(e){for(const t of Array.from(this.#i))try{t(e)}catch{}}};const at={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"},kk={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 Ak(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 WF(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 KF(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 Ik(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 R0(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 qF(e){const t=R0(e,["alignment","value"]);if(typeof t!="string")return t;const n=t.trim().toLowerCase();return n==="justified"||n==="both"?"justify":n}function YF(e){const t=R0(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 XF(e){if(e&&typeof e=="object"&&"role"in e)return e;const t=R0(e,["styleId","value","style"]);return typeof t=="string"?t.trim():t}function QF(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 ZF=at.commandUnsupported,hs=at.tableContextUnavailable;const Ek=[{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:Ak,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:Ak,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:WF},{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:QF},{id:"measurement-unit",family:"measurement",disposition:"routed",mutates:!1,instanceRoute:"setMeasurementUnit",valueFrom:"measurementUnit",normalizePayload:KF},{id:"text-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.color",inline:{key:"color",kind:"value-string"},normalizePayload:Ik},{id:"highlight-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.highlight",inline:{key:"highlight",kind:"value-string"},normalizePayload:Ik},{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:qF},{id:"line-height",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setSpacing",blockParagraph:{kind:"spacing-line"},normalizePayload:YF},{id:"linked-style",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"styles.paragraph.setStyle",blockParagraph:{kind:"style"},normalizePayload:XF},{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:hs},{id:"table-add-row-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertRow",table:{action:"insert-row-after",op:"insertRow"},reason:hs},{id:"table-delete-row",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteRow",table:{action:"delete-row",op:"deleteRow"},reason:hs},{id:"table-add-column-before",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-before",op:"insertColumn"},reason:hs},{id:"table-add-column-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-after",op:"insertColumn"},reason:hs},{id:"table-delete-column",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteColumn",table:{action:"delete-column",op:"deleteColumn"},reason:hs},{id:"table-delete",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.delete",table:{action:"delete-table",op:"delete"},reason:hs},{id:"table-merge-cells",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.mergeCells",table:{action:"merge-cells",op:"mergeCells"},reason:hs},{id:"table-split-cell",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.splitCell",table:{action:"split-cell",op:"splitCell",requiresCell:!0},reason:hs},{id:"table-remove-borders",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.setBorders",table:{action:"remove-borders",op:"setBorders"},reason:hs},{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:ZF}];var JF=new Map(Ek.map(e=>[e.id,e]));const $F=Ek.map(e=>e.id);function uu(e){return JF.get(e)??null}var eB=["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"];const xk=[{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:eB,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"}];var Tk=new Map(xk.map(e=>[e.name,e]));const wj=xk.map(e=>e.name);function M0(e){return Tk.get(e)??null}function tB(e){const t=Tk.get(e);return t?.disposition==="controller-routed"?t.commandId:null}const nB=".png,.jpg,.jpeg,image/png,image/jpeg";var Rk=new Set(["image/png","image/jpeg","image/jpg"]),rB=/\.(png|jpe?g)$/i;function oB(e){if(!e)return!1;const t=typeof e.type=="string"?e.type.toLowerCase():"";return t?Rk.has(t):rB.test(String(e.name??""))}function Mk(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(iB(String(r.result),e)),r.onerror=()=>n(r.error??new Error("image-read-failed")),r.readAsDataURL(e)})}function iB(e,t){const n=/^data:([^;,]*);base64,/.exec(e);if(!n)return e;const r=n[1].toLowerCase();if(Rk.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 sB(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:aB(n,e)}return Mk(e)}async function aB(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 Mk(o?Object.assign(r,{name:o}):r)}function lB({ownerDocument:e=document,onPick:t,onError:n}={}){const r=e.createElement("input");return r.type="file",r.accept=nB,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(!oB(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 cB=(e,t)=>{let n=e.replace(/[^0-9.]/g,"");return n=parseFloat(n),isNaN(n)&&(n=t),n=parseFloat(n),n},uB=(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=(...u)=>{const c=Date.now();!s&&n.leading===!1&&(s=c);const d=t-(c-s);return o=u,d<=0||d>t?(r&&(clearTimeout(r),r=null),s=c,i=e(...u),r||(o=null)):!r&&n.trailing!==!1&&(r=setTimeout(a,d)),i};return l.cancel=function(){clearTimeout(r),s=0,r=o=null},l};It(),mn();var dB={class:"sd-toolbar-icon"},fB=["innerHTML"],hB={__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)=>(me(),ke("div",dB,[Me("div",{class:en(["sd-toolbar-icon__icon",[`sd-toolbar-icon__icon--${t.name}`]]),innerHTML:e.icon},null,10,fB),r.value?(me(),ke("div",{key:0,class:"color-bar",style:gn(n.value)},null,4)):ut("",!0)]))}},Lk=fn(hB,[["__scopeId","data-v-d7d79424"]]);It(),mn();var pB=["role","aria-label"],mB=["data-item"],gB=["data-item"],vB={key:1,class:"sd-button-label"},yB=["data-item","aria-label"],bB=["innerHTML"],wB={key:2},CB=["onKeydown","id"],_B=["placeholder","onKeydown","id","data-item"],SB=["data-item","innerHTML"],kB={"aria-live":"polite",class:"sd-visually-hidden"},AB={__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}=or(),o=e,{name:i,active:s,icon:a,label:l,hideLabel:u,iconColor:c,hasCaret:d,splitButton:h,disabled:m,expand:p,inlineTextInputVisible:g,hasInlineTextInput:k,minWidth:w,style:S,attributes:y}=o.toolbarItem,C=Ae(()=>!!h?.value&&!!d?.value),T=Ae(()=>i?.value??""),R=ne(""),M=ne(null),{isHighContrastMode:H}=Hi();Pt(()=>l?.value,_e=>{document.activeElement!==M.value&&(R.value=_e==null?"":String(_e))},{immediate:!0});const B=()=>{k&&St(()=>{M.value?.focus(),M.value?.select()}),n("buttonClick")},z=_e=>{m?.value||(_e?.stopPropagation(),n("mainClick"))},X=()=>{C.value||B()},P=_e=>{if(C.value){z(_e);return}B()},N=_e=>{o.allowEnterPropagation||_e.stopPropagation(),P(_e)},I=_e=>{const oe=o.toolbarItem?.nestedOptions?.value??[],Te=_e.trim();if(!Te)return"";const Ge=oe.find(Je=>typeof Je?.label=="string"&&Je.label.toLowerCase()===Te.toLowerCase());return Ge?.label?Ge.label:oe.find(Je=>typeof Je?.label=="string"&&Je.label.toLowerCase().startsWith(Te.toLowerCase()))?.label??Te},L=()=>{const _e=String(R.value??"").trim();let oe=_e;if(T.value==="fontSize"){const Te=Number.parseFloat(_e);oe=_e.match(/^\d+(\.5)?$/)?_e:Number.isFinite(Te)?Math.floor(Te).toString():""}else T.value==="fontFamily"&&(oe=I(_e));return oe?(n("textSubmit",oe),R.value=oe,!0):!1},Y=_e=>{const oe=_e?.currentTarget;oe instanceof HTMLInputElement&&(oe.focus({preventScroll:!0}),oe.select())},te=_e=>{requestAnimationFrame(()=>{const oe=document.getElementById(`inlineTextInput-${_e}`);oe instanceof HTMLInputElement&&(oe.focus({preventScroll:!0}),oe.select())})},le=()=>{const _e=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return _e instanceof HTMLElement?(_e.focus({preventScroll:!0}),!0):!1},fe=()=>{const _e=r?.$toolbar?.pendingSelectionCapture,oe=()=>{_e&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(_e)};if(le()){oe();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),oe())},Ne=()=>{L()&&fe()},he=_e=>{if(L(),_e.shiftKey){T.value==="fontSize"&&(_e.preventDefault(),St(()=>te("fontFamily")));return}if(_e.preventDefault(),T.value==="fontFamily"){St(()=>te("fontSize"));return}T.value==="fontSize"&&St(fe)},ge=Ae(()=>S.value?S.value:{minWidth:o.minWidth}),ae=Ae(()=>p?.value?Zn.dropdownCaretUp:Zn.dropdownCaretDown);return(_e,oe)=>(me(),ke("div",{class:en(["sd-toolbar-item",We(y).className]),style:gn(ge.value),role:e.isOverflowItem?"menuitem":"button","aria-label":We(y).ariaLabel,"data-sd-part":"toolbar-item",onClick:X,onKeydown:oe[9]||(oe[9]=Qo(Te=>N(Te),["enter"])),tabindex:"0"},[Me("div",{class:en(["sd-toolbar-button",{"sd-active":We(s),"sd-disabled":We(m),narrow:e.isNarrow,wide:e.isWide,split:C.value,"has-inline-text-input":We(k),"high-contrast":We(H)}]),"data-item":`btn-${We(i)||""}`},[C.value?(me(),ke("div",{key:0,class:"sd-toolbar-button__main","data-item":`btn-${We(i)||""}-main`,onClick:oe[0]||(oe[0]=Te=>z(Te))},[We(a)?(me(),dn(Lk,{key:0,color:We(c),class:"sd-toolbar-icon",icon:We(a),name:We(i)},null,8,["color","icon","name"])):ut("",!0),We(l)&&!We(u)&&!We(g)?(me(),ke("div",vB,Nt(We(l)),1)):ut("",!0)],8,gB)):ut("",!0),C.value?(me(),ke("div",{key:1,class:"sd-toolbar-button__caret","data-item":`btn-${We(i)||""}-caret`,"aria-label":`${We(y).ariaLabel} options`,role:"button"},[Me("div",{class:"sd-dropdown-caret",innerHTML:ae.value,style:gn({opacity:We(m)?.6:1})},null,12,bB)],8,yB)):(me(),ke(qt,{key:2},[We(a)?(me(),dn(Lk,{key:0,color:We(c),class:"sd-toolbar-icon",icon:We(a),name:We(i)},null,8,["color","icon","name"])):ut("",!0),We(l)&&!We(u)&&(!We(g)||T.value==="fontFamily")?(me(),ke("div",{key:1,class:en(["sd-button-label",{"sd-visually-hidden":We(g)&&T.value==="fontFamily"}])},Nt(We(l)),3)):ut("",!0),We(g)?(me(),ke("span",wB,[We(i)==="fontSize"?Ms((me(),ke("input",{key:0,"onUpdate:modelValue":oe[1]||(oe[1]=Te=>R.value=Te),onKeydown:[Qo(Jt(Ne,["stop","prevent"]),["enter"]),oe[2]||(oe[2]=Qo(Te=>he(Te),["tab"]))],onClick:oe[3]||(oe[3]=Jt(Te=>Y(Te),["stop"])),onFocus:oe[4]||(oe[4]=Te=>Y(Te)),type:"text",class:en(["button-text-input button-text-input--font-size",{"high-contrast":We(H)}]),id:"inlineTextInput-"+We(i),autocomplete:"off",ref_key:"inlineInput",ref:M},null,42,CB)),[[Ii,R.value]]):Ms((me(),ke("input",{key:1,"onUpdate:modelValue":oe[5]||(oe[5]=Te=>R.value=Te),placeholder:We(l),onKeydown:[Qo(Jt(Ne,["stop","prevent"]),["enter"]),oe[6]||(oe[6]=Qo(Te=>he(Te),["tab"]))],onClick:oe[7]||(oe[7]=Jt(Te=>Y(Te),["stop"])),onFocus:oe[8]||(oe[8]=Te=>Y(Te)),type:"text",class:en(["button-text-input",{"button-text-input--font-family":T.value==="fontFamily","high-contrast":We(H)}]),id:"inlineTextInput-"+We(i),"data-item":T.value==="fontFamily"?`btn-${We(i)}-input`:void 0,autocomplete:"off",ref_key:"inlineInput",ref:M},null,42,_B)),[[Ii,R.value]])])):ut("",!0),We(d)?(me(),ke("div",{key:3,class:"sd-dropdown-caret","data-item":`btn-${We(i)||""}-toggle`,innerHTML:ae.value,style:gn({opacity:We(m)?.6:1})},null,12,SB)):ut("",!0)],64)),Me("div",kB,Nt(`${We(y).ariaLabel} ${We(s)?"selected":"unset"}`),1)],10,mB)],46,pB))}},L0=fn(AB,[["__scopeId","data-v-dbdea151"]]);It(),mn();var IB={class:"toolbar-separator",role:"separator","aria-label":"Toolbar separator"},EB={__name:"ToolbarSeparator",props:{active:{type:Boolean,default:!1}},emits:["command"],setup(e,{emit:t}){const{isHighContrastMode:n}=Hi(),r=()=>n.value?"#000":"var(--sd-ui-border, #dbdbdb)";return(o,i)=>(me(),ke("div",IB,[Me("div",{class:"separator-inner",style:gn({backgroundColor:r()})},null,4)]))}},xB=fn(EB,[["__scopeId","data-v-cb82253a"]]);It(),mn();var TB={class:"overflow-menu"},RB={class:"overflow-menu-trigger"},MB={key:0,class:"overflow-menu_items",role:"group"},LB={__name:"OverflowMenu",props:{toolbarItem:{type:Object,required:!0},overflowItems:{type:Array,required:!0}},emits:["buttonClick","close"],setup(e,{emit:t}){const{proxy:n}=or(),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)},u=({item:d,argument:h})=>{n.$toolbar.emitCommand({item:d,argument:h})},c=d=>{d.key==="Escape"&&i.value&&!s.value&&(d.preventDefault(),r("close"))};return Rn(()=>{document.addEventListener("keydown",c,!0)}),rr(()=>{document.removeEventListener("keydown",c,!0)}),(d,h)=>(me(),ke("div",TB,[Me("div",RB,[Wt(L0,{"toolbar-item":a.value,onButtonClick:l},null,8,["toolbar-item"])]),i.value?(me(),ke("div",MB,[Wt(Wp,{class:"superdoc-toolbar-overflow","toolbar-items":e.overflowItems,"from-overflow":"",onCommand:u,onDropdownUpdateShow:h[0]||(h[0]=m=>s.value=m)},null,8,["toolbar-items"])])):ut("",!0)]))}},DB=fn(LB,[["__scopeId","data-v-504ecd05"]]);It(),mn();var PB={class:"toolbar-dropdown"},OB=["onClick"],FB={key:0,class:"toolbar-dropdown-option__icon"},BB={class:"toolbar-dropdown-option__label"},Vp='button, [href], input, select, textarea, [role="button"], [tabindex]:not([tabindex="-1"])',NB={__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),u=Ae(()=>!!n.show),c=Ae(()=>n.options.some(oe=>oe?.type==="render")),d=Ae(()=>typeof n.menuProps!="function"?{}:n.menuProps()||{}),h=Ae(()=>{const{class:oe,style:Te,...Ge}=d.value;return Ge}),m=Ae(()=>{const oe=d.value.class,Te=n.options.length>0&&n.options.every(Ge=>Ge&&Ge.type==="render");return["toolbar-dropdown-menu",oe,{"toolbar-dropdown-menu--render-only":Te}]}),p=Ae(()=>{const oe=d.value.style||{};return{...n.contentStyle,...oe}}),g=Ae(()=>({...p.value,position:"fixed",top:s.value.top,left:s.value.left,maxHeight:s.value.maxHeight,zIndex:2e3})),k=oe=>{r("update:show",oe)},w=()=>{u.value&&k(!1)},S=()=>{if(!o.value)return;const oe=o.value.getBoundingClientRect(),Te=i.value,Ge=Te?.offsetWidth??0,Je=Te?.scrollHeight??Te?.offsetHeight??0,_t=window.innerWidth||document.documentElement.clientWidth||0,be=window.innerHeight||document.documentElement.clientHeight||0,Ve=8,Le=4,J=oe.bottom+Le,_=oe.top-Le,$=Math.max(0,be-J-Ve),F=Math.max(0,_-Ve),j=$<Je&&F>$,V=j?F:$,G=Je?Math.min(Je,V):V,Z=j?Math.max(Ve,_-G):J;let W=oe.left;n.placement==="bottom-end"&&(W=oe.right-Ge);const K=Math.max(Ve,_t-Ge-Ve);W=Math.min(Math.max(Ve,W),K),s.value={top:`${Z}px`,left:`${W}px`,maxHeight:`${V}px`}},y=()=>{n.disabled||k(!u.value)},C=oe=>typeof n.nodeProps!="function"?{}:n.nodeProps(oe)||{},T=oe=>{oe?.disabled||oe?.type!=="render"&&(r("select",oe?.key,oe),w())},R=oe=>oe?.type==="render",M=oe=>!oe?.disabled&&oe?.type!=="render",H=oe=>typeof oe?.icon=="function"||!!oe?.icon,B=oe=>typeof oe?.icon=="function"?oe.icon(oe):oe?.icon||null,z=oe=>oe?typeof oe=="string"?oe.split(/\s+/).includes("sd-selected"):Array.isArray(oe)?oe.some(z):typeof oe=="object"?!!oe["sd-selected"]:!1:!1,X=oe=>z(oe?.props?.class)||z(oe?.class),P=()=>n.options.map((oe,Te)=>M(oe)?Te:-1).filter(oe=>oe>=0),N=()=>{const oe=n.options.findIndex(Te=>M(Te)&&X(Te));return oe>=0?oe:P()[0]??-1},I=(oe,Te)=>{if(!oe){delete a.value[Te];return}a.value[Te]=oe},L=()=>{a.value.forEach((Te,Ge)=>{Te&&Te.setAttribute("tabindex",Ge===l.value?"0":"-1")});const oe=a.value[l.value];oe&&typeof oe.focus=="function"&&(oe.focus(),oe.scrollIntoView?.({block:"nearest",inline:"nearest"}))},Y=oe=>{const Te=P();if(!Te.length){l.value=-1;return}const Ge=Te.indexOf(l.value);if(Ge<0){l.value=oe>0?Te[0]:Te[Te.length-1];return}l.value=Te[(Ge+oe+Te.length)%Te.length]},te=()=>{let oe=n.options[l.value];if(!M(oe)){const Te=P()[0];oe=Te===void 0?null:n.options[Te]}oe&&T(oe)},le=Tl({name:"ToolbarDropdownRenderOption",props:{option:{type:Object,required:!0}},setup(oe){return()=>typeof oe.option.render!="function"?null:oe.option.render()}}),fe=Tl({name:"ToolbarDropdownOptionIcon",props:{option:{type:Object,required:!0}},setup(oe){return()=>B(oe.option)}}),Ne=oe=>{if(!u.value)return;const Te=oe.target;if(!(Te instanceof Element))return;const Ge=o.value?.contains(Te),Je=i.value?.contains(Te);Ge||Je||w()},he=ne(null),ge=()=>{const oe=o.value,Te=document.activeElement;if(oe&&Te instanceof HTMLElement&&oe.contains(Te)){he.value=Te;return}he.value=oe?.matches?.(Vp)?oe:oe?.querySelector(Vp)},ae=()=>{const oe=he.value;if(oe instanceof HTMLElement&&document.contains(oe)){oe.focus();return}const Te=o.value;if(!Te)return;const Ge=Te.matches?.(Vp)?Te:Te.querySelector(Vp);if(Ge instanceof HTMLElement){Ge.focus();return}Te.setAttribute("tabindex","-1"),Te.focus()},_e=oe=>{if(!u.value)return;const{key:Te}=oe;if(["Escape","ArrowDown","ArrowUp","Enter"].includes(Te)){if(Te==="Escape"){oe.preventDefault(),w(),St(()=>{requestAnimationFrame(ae)});return}if(!c.value){if(oe.preventDefault(),Te==="ArrowDown"){Y(1),L();return}if(Te==="ArrowUp"){Y(-1),L();return}Te==="Enter"&&te()}}};return Pt(u,async oe=>{if(!oe){l.value=-1,a.value=[];return}ge(),await St(),S(),!c.value&&(l.value=N(),await St(),L())},{immediate:!0}),Pt(u,oe=>{oe?(document.addEventListener("pointerdown",Ne,!0),document.addEventListener("keydown",_e,!0),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0)):(document.removeEventListener("pointerdown",Ne,!0),document.removeEventListener("keydown",_e,!0),window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0))},{immediate:!0}),rr(()=>{document.removeEventListener("pointerdown",Ne,!0),document.removeEventListener("keydown",_e,!0),window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}),(oe,Te)=>(me(),ke("div",PB,[Me("div",{ref_key:"triggerRef",ref:o,class:"toolbar-dropdown-trigger","data-sd-part":"dropdown-trigger",onClick:y},[dd(oe.$slots,"trigger",{},void 0,!0)],512),(me(),dn(Ra,{to:"body"},[Wt(Th,{name:"fade-in-scale-up-transition"},{default:ko(()=>[u.value?(me(),ke("div",rs({key:0,ref_key:"menuRef",ref:i,"data-sd-part":"dropdown-menu",class:m.value,style:g.value},h.value),[(me(!0),ke(qt,null,nr(e.options,(Ge,Je)=>(me(),ke("div",rs({key:Ge.key,ref_for:!0,ref:_t=>I(_t,Je),class:["toolbar-dropdown-option",[Ge.class,Ge.props?.class,{"sd-disabled":Ge.disabled,"sd-render":R(Ge)}]],tabindex:"-1",onClick:_t=>T(Ge)},{ref_for:!0},{...Ge.props,...C(Ge)}),[R(Ge)?(me(),dn(We(le),{key:0,option:Ge},null,8,["option"])):(me(),ke(qt,{key:1},[H(Ge)?(me(),ke("span",FB,[Wt(We(fe),{option:Ge},null,8,["option"])])):ut("",!0),Me("span",BB,Nt(Ge.label),1)],64))],16,OB))),128))],16)):ut("",!0)]),_:1})]))]))}},zB=fn(NB,[["__scopeId","data-v-fef410f7"]]),Dk=e=>String(e??"").trim().toLowerCase();const jp=(e,t)=>{const n=Dk(e);if(!n)return-1;for(let r=0;r<t.length;r+=1)if(Dk(t[r]).startsWith(n))return r;return-1},HB=(e,t,{autocomplete:n=!0}={})=>{const r=String(e??""),o=jp(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}};var 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},VB=e=>e<=31||e===127,jB=e=>e===32||e===160||e===65279,GB=e=>Array.from(String(e)).filter(t=>!VB(t.charCodeAt(0))).join(""),WB=e=>{let t="",n=!1;for(const r of String(e)){if(jB(r.charCodeAt(0))){n=t.length>0;continue}n&&(t+=" "),n=!1,t+=r}return t};const KB=e=>WB(UB(GB(String(e??"").split(",")[0]??""))).trim();var qB=1,YB=1638;const XB=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<qB?"":String(Math.min(r,YB))};It(),mn();var QB=["data-item"],ZB=["id","value","disabled","aria-label","aria-expanded","aria-controls","aria-activedescendant","data-item"],JB=["data-item","aria-label","disabled"],$B=["innerHTML"],eN=["id","aria-label"],tN=["id","aria-selected","aria-label","onMousedown","onMouseenter"],nN={class:"toolbar-dropdown-option__label"},rN={class:"sd-button-label sd-font-combobox__legacy-label","aria-hidden":"true"},oN={__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}=Hi(),i=ne(null),s=ne(null),a=ne(null),l=ne([]),u=ne(!1),c=ne(!1),d=ne(-1),h=ne(""),m=ne(""),p=ne(!1),g=ne({top:"0px",left:"0px",minWidth:"0px",maxHeight:"none"}),k=Ae(()=>n.item.nestedOptions?.value??[]),w=Ae(()=>k.value.map(W=>String(W?.label??""))),S=Ae(()=>String(n.item.label?.value??"")),y=Ae(()=>!!n.item.disabled?.value),C=Ae(()=>String(n.item.name?.value??"")),T=Ae(()=>n.item.attributes?.value?.ariaLabel??"Font family"),R=Ae(()=>u.value?m.value:S.value),M=Ae(()=>`sd-${C.value||"combobox"}-listbox-${n.item.id?.value??"default"}`),H=W=>`${M.value}-option-${W}`,B=Ae(()=>c.value&&d.value>=0?H(d.value):void 0),z=Ae(()=>c.value?Zn.dropdownCaretUp:Zn.dropdownCaretDown),X=W=>{const K=String(W??"").trim().toLowerCase();return k.value.find(ue=>String(ue?.label??"").trim().toLowerCase()===K)?.props?.style?.fontFamily||W||n.uiFontFamily},P=Ae(()=>n.showPreview?{fontFamily:X(u.value?m.value:S.value)}:{fontFamily:n.uiFontFamily}),N=()=>{const W=n.item.selectedValue?.value;if(W){const K=k.value.findIndex(ue=>ue?.key===W);if(K>=0)return K}return w.value.findIndex(K=>K.toLowerCase()===S.value.toLowerCase())},I=(W,K)=>{const ue=i.value;if(!(!ue||typeof ue.setSelectionRange!="function"))try{ue.setSelectionRange(W,K)}catch{}},L=()=>{l.value[d.value]?.scrollIntoView?.({block:"nearest",inline:"nearest"})},Y=()=>{l.value[d.value]?.focus?.()},te=()=>{const W=s.value;if(!W)return;const K=W.getBoundingClientRect(),ue=a.value,we=ue?.scrollHeight??ue?.offsetHeight??0,Ce=window.innerHeight||document.documentElement.clientHeight||0,xe=window.innerWidth||document.documentElement.clientWidth||0,ot=8,tt=4,Ct=K.bottom+tt,Kt=K.top-tt,pt=Math.max(0,Ce-Ct-ot),Mt=Math.max(0,Kt-ot),zt=pt<we&&Mt>pt,ln=zt?Mt:pt,$n=we?Math.min(we,ln):ln,Ht=zt?Math.max(ot,Kt-$n):Ct,Ke=Math.min(Math.max(ot,K.left),Math.max(ot,xe-K.width-ot));g.value={top:`${Ht}px`,left:`${Ke}px`,minWidth:`${K.width}px`,maxHeight:`${ln}px`}},le=Ae(()=>({position:"fixed",top:g.value.top,left:g.value.left,minWidth:g.value.minWidth,maxHeight:g.value.maxHeight,fontFamily:n.uiFontFamily,zIndex:2e3})),fe=W=>{n.item.expand&&typeof n.item.expand=="object"&&"value"in n.item.expand&&(n.item.expand.value=W)},Ne=(W,{focusInput:K=!1,focusOption:ue=!1}={})=>{if(y.value||!k.value.length){fe(!1);return}c.value=!0,fe(!0),d.value=W??-1,K&&(u.value=!0,m.value=S.value,i.value?.focus()),St(()=>{te(),L(),ue&&Y()})},he=({syncItem:W=!0}={})=>{c.value=!1,d.value=-1,W&&fe(!1)},ge=()=>{he(),u.value=!1,h.value="",m.value=S.value},ae=()=>{y.value||(c.value||r("item-clicked"),u.value=!0,h.value="",m.value=S.value,St(()=>I(0,m.value.length)))},_e=W=>{if(y.value)return;const K=document.activeElement===i.value;if(r("item-clicked"),u.value=!0,K||(h.value="",m.value=S.value,W.preventDefault(),i.value?.focus({preventScroll:!0}),I(0,S.value.length)),!c.value){const ue=N();Ne(ue>=0?ue:0)}},oe=W=>{const K=W.relatedTarget;K instanceof Node&&s.value?.contains(K)||K instanceof Node&&a.value?.contains(K)||ge()},Te=W=>{if(p.value)return;const K=W.target,ue=K.value,we=typeof K.selectionStart=="number"?K.selectionStart:ue.length,Ce=typeof K.selectionEnd=="number"?K.selectionEnd:we,xe=typeof W.inputType=="string"&&W.inputType.startsWith("delete"),ot=we===ue.length&&Ce===ue.length;h.value=ue;const tt=HB(ue,w.value,{autocomplete:!xe&&ot});m.value=tt.display,K.value=tt.display,tt.display===ue&&!ot?I(we,Ce):I(tt.selectionStart,tt.selectionEnd),c.value&&(d.value=tt.matchIndex,St(L))},Ge=W=>{p.value=!1,Te(W)},Je=W=>{if(!k.value.length)return;const K=k.value.length;d.value=((d.value<0?W>0?-1:0:d.value)+W+K)%K,St(L)},_t=(W,K)=>{r("item-clicked"),r("command",{item:n.item,argument:W,option:K}),K&&(n.item.selectedValue.value=K.key)},be=W=>{W&&(_t(W.label,W),u.value=!1,h.value="",m.value=W.label,he())},Ve=()=>{if(c.value&&d.value>=0)return be(k.value[d.value]),!0;const W=jp(h.value,w.value);if(W>=0)return be(k.value[W]),!0;const K=n.normalizeValue(h.value);return K?(_t(K,null),u.value=!1,h.value="",m.value=K,he(),!0):!1},Le=W=>{if(!(W.isComposing||p.value||W.keyCode===229)&&!(W.ctrlKey||W.metaKey||W.altKey))switch(W.key){case"ArrowDown":if(W.preventDefault(),c.value)Y();else{const K=jp(h.value,w.value),ue=K>=0?K:N();Ne(ue>=0?ue:0,{focusOption:!0})}break;case"ArrowUp":if(W.preventDefault(),c.value)Y();else{const K=jp(h.value,w.value),ue=K>=0?K:N();Ne(ue>=0?ue:k.value.length-1,{focusOption:!0})}break;case"Enter":W.preventDefault(),Ve()&&r("editor-handoff"),i.value?.blur();break;case"Tab":W.preventDefault(),Ve(),he(),i.value?.blur(),r("tab-out",W);break;case"Escape":W.preventDefault(),ge(),St(()=>i.value?.focus());break;default:break}},J=W=>{if(W.preventDefault(),!y.value)if(r("item-clicked"),c.value)he(),i.value?.focus();else{const K=N();Ne(K>=0?K:0,{focusOption:!0})}},_=(W,K)=>{W.preventDefault(),be(K),r("editor-handoff"),i.value?.blur()},$=W=>{d.value=W},F=W=>{if(!(W.ctrlKey||W.metaKey||W.altKey))switch(W.key){case"ArrowDown":W.preventDefault(),Je(1),Y();break;case"ArrowUp":W.preventDefault(),Je(-1),Y();break;case"Enter":W.preventDefault(),d.value>=0&&(be(k.value[d.value]),r("editor-handoff"));break;case"Escape":W.preventDefault(),ge(),St(()=>i.value?.focus());break;case"Tab":W.preventDefault(),d.value>=0?be(k.value[d.value]):he(),r("tab-out",{shiftKey:W.shiftKey,target:i.value});break;default:break}},j=W=>{if(!c.value)return;const K=W.target;K instanceof Element&&(s.value?.contains(K)||a.value?.contains(K)||ge())};Pt(c,W=>{W?(document.addEventListener("pointerdown",j,!0),window.addEventListener("resize",te),window.addEventListener("scroll",te,!0)):(document.removeEventListener("pointerdown",j,!0),window.removeEventListener("resize",te),window.removeEventListener("scroll",te,!0),l.value=[])},{immediate:!0}),rr(()=>{document.removeEventListener("pointerdown",j,!0),window.removeEventListener("resize",te),window.removeEventListener("scroll",te,!0)});const V=(W,K)=>{if(!W){delete l.value[K];return}l.value[K]=W},G=W=>W===d.value,Z=W=>W?.key&&W.key===n.item.selectedValue?.value;return Pt(S,W=>{u.value||(m.value=W)}),Pt(()=>!!n.item.expand?.value,W=>{if(W&&!c.value){const K=N();Ne(K>=0?K:0,{focusInput:!0});return}!W&&c.value&&he({syncItem:!1})}),(W,K)=>(me(),ke("div",{ref_key:"rootRef",ref:s,class:en(["sd-font-combobox sd-toolbar-split-field",{"sd-disabled":y.value,"high-contrast":We(o)}]),style:gn(n.item.style?.value),"data-item":`btn-${C.value}`},[Me("span",{class:"sd-font-combobox__field sd-toolbar-split-field__main",onMousedown:_e},[Me("input",{ref_key:"inputRef",ref:i,id:`inlineTextInput-${C.value}`,class:"button-text-input sd-font-combobox__input",type:"text",role:"combobox",autocomplete:"off",spellcheck:"false",value:R.value,style:gn(P.value),disabled:y.value,"aria-label":T.value,"aria-expanded":c.value?"true":"false","aria-controls":M.value,"aria-activedescendant":B.value,"aria-haspopup":"listbox","aria-autocomplete":"both","data-item":`btn-${C.value}-input`,onFocus:ae,onBlur:oe,onInput:Te,onKeydown:Le,onCompositionstart:K[0]||(K[0]=ue=>p.value=!0),onCompositionend:Ge},null,44,ZB)],32),Me("button",{type:"button",class:"sd-font-combobox__caret sd-toolbar-split-field__caret","data-item":`btn-${C.value}-toggle`,tabindex:"-1","aria-label":`${T.value} options`,disabled:y.value,onMousedown:J},[Me("span",{class:"sd-dropdown-caret",innerHTML:z.value},null,8,$B)],40,JB),(me(),dn(Ra,{to:"body"},[c.value?(me(),ke("div",{key:0,ref_key:"popupRef",ref:a,role:"listbox",id:M.value,"aria-label":T.value,class:en(["sd-font-combobox__listbox",{"high-contrast":We(o)}]),style:gn(le.value)},[(me(!0),ke(qt,null,nr(k.value,(ue,we)=>(me(),ke("div",rs({key:ue.key,ref_for:!0,ref:Ce=>V(Ce,we),id:H(we),role:"option",tabindex:"-1",class:["toolbar-dropdown-option sd-font-combobox__option",{"sd-active":G(we),"sd-selected":Z(ue)}],"aria-selected":Z(ue)?"true":"false","aria-label":`${T.value} - ${ue.label}`},{ref_for:!0},ue.props,{onMousedown:Ce=>_(Ce,ue),onMouseenter:Ce=>$(we),onKeydown:F}),[Me("span",nN,Nt(ue.label),1)],16,tN))),128))],14,eN)):ut("",!0)])),Me("span",rN,Nt(S.value),1)],14,QB))}},Pk=fn(oN,[["__scopeId","data-v-99070b63"]]);It();var iN={__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)=>(me(),dn(Pk,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!0,"normalize-value":We(KB),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"]))}},sN=iN;It();var aN={__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)=>(me(),dn(Pk,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!1,"normalize-value":We(XB),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"]))}},lN=aN;It(),mn();var cN=2500,uN=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=M2(),r=ne(!1),o=ne(null),i=ne(null),s=ne({top:"0px",left:"0px"});let a=null,l=null,u=null;const c=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)},m=()=>{l&&(window.clearTimeout(l),l=null)},p=()=>{u&&(window.clearTimeout(u),u=null)},g=()=>{p(),u=window.setTimeout(()=>{u=null,S()},cN)},k=()=>{if(!o.value||!i.value)return;const z=o.value.getBoundingClientRect(),X=i.value.offsetWidth,P=i.value.offsetHeight,N=window.innerWidth||document.documentElement.clientWidth||0,I=8;let L=z.left+z.width/2-X/2;L=Math.max(I,Math.min(L,N-X-I)),s.value={top:`${z.top-P-10}px`,left:`${L}px`}},w=async()=>{t.disabled||(h(),m(),!r.value&&(r.value=!0,g(),await St(),k()))},S=()=>{m(),h(),p(),r.value&&(r.value=!1)},y=()=>{if(h(),m(),!r.value){if(t.delay===0){w();return}l=window.setTimeout(()=>{l=null,w()},t.delay)}},C=()=>{if(m(),h(),!!r.value){if(t.duration===0){S();return}a=window.setTimeout(()=>{a=null,S()},t.duration)}},T=()=>{t.trigger==="hover"&&y()},R=()=>{t.trigger==="hover"&&C()},M=()=>{m(),h()},H=()=>{C()},B=z=>{z.key==="Escape"&&S()};return Pt(()=>t.disabled,z=>{z&&S()}),Pt(r,z=>{z?(window.addEventListener("resize",k),window.addEventListener("scroll",k,!0),document.addEventListener("keydown",B,!0)):(window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("keydown",B,!0))}),rr(()=>{m(),h(),p(),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0),document.removeEventListener("keydown",B,!0)}),(z,X)=>(me(),ke(qt,null,[Me("span",{ref_key:"triggerRef",ref:o,class:"sd-tooltip-trigger",onMouseenter:T,onMouseleave:R,onFocusin:T,onFocusout:R},[dd(z.$slots,"trigger",{},void 0,!0)],544),(me(),dn(Ra,{to:"body"},[Wt(Th,{name:"fade-in-scale-up-transition"},{default:ko(()=>[r.value&&!e.disabled?(me(),ke("div",{key:0,ref_key:"contentRef",ref:i,class:en(c.value),style:gn(d.value),onMouseenter:M,onMouseleave:H},[X[0]||(X[0]=Me("span",{class:"sd-tooltip-arrow","aria-hidden":"true"},null,-1)),dd(z.$slots,"default",{},void 0,!0)],38)):ut("",!0)]),_:3})]))],64))}}),Gp=fn(uN,[["__scopeId","data-v-2a872eae"]]);It(),mn();var dN=["onKeydown","tabindex","data-item-id"],fN={key:0},hN={key:0},pN={key:0},mN={key:0},gN={key:0},vN={__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}=or(),o=ne([]),i=ne(null),s=e,a=ne(null),{isHighContrastMode:l}=Hi(),u=window.matchMedia("(max-width: 768px)").matches,c=Ae(()=>s.position==="left"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-start"}:s.position==="right"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-end"}:{flexGrow:u?0:1,justifyContent:"center"}),d=be=>be.type==="button",h=be=>be.type==="dropdown",m=be=>be.type==="dropdown"&&be.name?.value==="fontFamily",p=be=>be.type==="dropdown"&&be.name?.value==="fontSize",g=be=>be.type==="separator",k=be=>be.type==="overflow",w=be=>!!be.nestedOptions?.value?.length,S=be=>{if(!be)return!1;const Ve=be.expand;return typeof Ve=="object"&&Ve!==null&&"value"in Ve?!!Ve.value:!!Ve},y=(be,Ve)=>{be?.expand&&(be.expand.value=Ve)},C=(be,Ve=void 0)=>{if(be.disabled.value)return;if(k(be)){const J=!S(be);J&&M(),y(be,J),a.value=J?be:null,n("item-clicked");return}if(h(be))return;a.value&&h(a.value)&&S(a.value)&&M(),n("item-clicked");const Le=Ve!==void 0?Ve:be.argument?.value;n("command",Le===void 0?{item:be}:{item:be,argument:Le})},T=(be,Ve)=>{be.disabled.value||(a.value=null,n("command",{item:be,argument:Ve}))},R=be=>{if(be.disabled.value)return;M();const Ve=be.splitButtonCommand,Le=be.command,J=Ve||Le;if(!J)return;const _={...be,command:J};n("item-clicked"),n("command",{item:_})},M=()=>{const be=r?.$toolbar?.toolbarItems||[],Ve=r?.$toolbar?.overflowItems||[],Le=[...be,...Ve];(Le.length?Le:s.toolbarItems).forEach(J=>{const _=k(J)&&!s.fromOverflow;(h(J)||_)&&y(J,!1)}),a.value=null},H=(be,Ve)=>{M(),n("command",{item:be,argument:be.dropdownValueKey.value?Ve[be.dropdownValueKey.value]:Ve.label,option:Ve}),be.selectedValue.value=Ve.key},B=be=>{n("command",be)},z=()=>{M(),n("item-clicked")},X=()=>{const be=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return be instanceof HTMLElement?(be.focus({preventScroll:!0}),!0):!1},P=()=>{const be=r?.$toolbar?.pendingSelectionCapture,Ve=()=>{be&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(be)};if(X()){Ve();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),Ve())},N=be=>!(be instanceof HTMLElement)||be.classList.contains("sd-disabled")?null:be.querySelector("input:not([disabled]), textarea:not([disabled]), select:not([disabled])")||be.querySelector('button:not([disabled]), [role="button"]:not(.sd-disabled), [tabindex]:not([tabindex="-1"])'),I=(be,Ve)=>{const Le=be?.target?.closest?.(".sd-toolbar-item-ctn");if(!(Le instanceof HTMLElement))return!1;let J=Ve>0?Le.nextElementSibling:Le.previousElementSibling;for(;J;){const _=N(J);if(_ instanceof HTMLElement)return Le.setAttribute("tabindex","-1"),J.setAttribute("tabindex","0"),_.focus(),!0;J=Ve>0?J.nextElementSibling:J.previousElementSibling}return!1},L=be=>{M(),I(be,be?.shiftKey?-1:1)||P()},Y=be=>{if(M(),be?.shiftKey){I(be,-1)||P();return}P()},te=()=>{P()},le=be=>be.nestedOptions?.value?.length?be.nestedOptions.value.map(Ve=>{const Le=Ve?.type!=="render"&&be.selectedValue.value===Ve.key;return{...Ve,props:{...Ve.props,class:Le?"sd-selected":""}}}):[],fe=(be,Ve)=>({role:"menuitem",ariaLabel:`${Ve.attributes.value.ariaLabel} - ${be.label}`}),Ne=be=>{const Ve=be.target,Le=be.target.closest(".sd-toolbar-item-ctn").nextElementSibling;Le&&(Ve.setAttribute("tabindex","-1"),Le.setAttribute("tabindex","0"),Le.focus())},he=be=>{const Ve=be.target,Le=be.target.closest(".sd-toolbar-item-ctn").previousElementSibling;Le&&(Ve.setAttribute("tabindex","-1"),Le.setAttribute("tabindex","0"),Le.focus())},ge=be=>{const Ve=be.target.closest(".button-group").nextElementSibling;if(Ve)Ve.setAttribute("tabindex","0"),Ve.focus();else{const Le=document.querySelector(".ProseMirror");Le&&Le.focus()}},ae=be=>{const Ve=be.target.closest(".button-group").previousElementSibling;Ve&&(Ve.setAttribute("tabindex","0"),Ve.focus())},_e=be=>{if(!be.disabled.value){if(h(be)){Ge(!S(be),be);return}C(be)}},oe=(be,Ve)=>{const Le=be.target.nodeName==="INPUT"||be.target.nodeName==="TEXTAREA",J=Ve.name.value==="fontSize"||Ve.name.value==="fontFamily";if(!(Le&&J)&&["Enter"," ","Spacebar","Escape","ArrowRight","ArrowLeft","Tab"].includes(be.key))switch(be.preventDefault(),be.key){case"Enter":case" ":case"Spacebar":_e(Ve);break;case"Escape":M();break;case"ArrowRight":M(),Ne(be);break;case"ArrowLeft":M(),he(be);break;case"Tab":be.shiftKey?ae(be):ge(be);break;default:break}},Te=be=>{const Ve=o.value.find(Le=>!Le.classList.contains("sd-disabled"));Ve&&(Ve.setAttribute("tabindex","0"),Ve.focus())},Ge=(be,Ve)=>{if(n("item-clicked"),!be){M(),n("dropdown-update-show",!1);return}M(),a.value=Ve,y(Ve,!0),n("dropdown-update-show",!0)},Je=be=>{if(!a.value)return;const Ve=be.target;Ve instanceof Element&&(Ve.closest(".sd-toolbar-dropdown-menu")||i.value?.contains(Ve)||M())};return Pt(()=>S(a.value),be=>{be?document.addEventListener("pointerdown",Je,!0):document.removeEventListener("pointerdown",Je,!0)},{immediate:!0}),rr(()=>{document.removeEventListener("pointerdown",Je,!0)}),(be,Ve)=>(me(),ke("div",{style:gn(c.value),class:"button-group",role:"group",onFocus:Te,ref_key:"buttonGroupRef",ref:i},[(me(!0),ke(qt,null,nr(e.toolbarItems,(Le,J)=>(me(),ke("div",{key:Le.id.value,class:en([{narrow:Le.isNarrow.value,wide:Le.isWide.value,"sd-disabled":Le.disabled.value},"sd-toolbar-item-ctn"]),onKeydown:_=>oe(_,Le),ref_for:!0,ref_key:"toolbarItemRefs",ref:o,tabindex:J===0?0:-1,"data-item-id":Le.id.value},[g(Le)?(me(),dn(xB,{key:0,style:{width:"20px"}})):ut("",!0),m(Le)&&w(Le)?(me(),dn(Gp,{key:1,trigger:"hover",disabled:!Le.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:ko(()=>[Wt(sN,{item:Le,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:B,onItemClicked:z,onTabOut:Ve[0]||(Ve[0]=_=>L(_)),onEditorHandoff:te},null,8,["item","ui-font-family"])]),default:ko(()=>[Me("div",null,[Fi(Nt(Le.tooltip)+" ",1),Le.disabled.value?(me(),ke("span",fN,"(disabled)")):ut("",!0)])]),_:2},1032,["disabled","content-style"])):p(Le)&&w(Le)?(me(),dn(Gp,{key:2,trigger:"hover",disabled:!Le.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:ko(()=>[Wt(lN,{item:Le,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:B,onItemClicked:z,onTabOut:Ve[1]||(Ve[1]=_=>Y(_)),onEditorHandoff:te},null,8,["item","ui-font-family"])]),default:ko(()=>[Me("div",null,[Fi(Nt(Le.tooltip)+" ",1),Le.disabled.value?(me(),ke("span",hN,"(disabled)")):ut("",!0)])]),_:2},1032,["disabled","content-style"])):h(Le)&&Le.nestedOptions?.value?.length?(me(),dn(zB,{key:3,options:le(Le),disabled:Le.disabled.value,show:S(Le),"content-style":{fontFamily:s.uiFontFamily},placement:"bottom-start",class:"sd-toolbar-button sd-editor-toolbar-dropdown",onSelect:(_,$)=>H(Le,$),"onUpdate:show":_=>Ge(_,Le),style:gn(Le.dropdownStyles.value),"menu-props":()=>({role:"menu",style:{fontFamily:s.uiFontFamily},class:["sd-toolbar-dropdown-menu",{"high-contrast":We(l)}]}),"node-props":_=>fe(_,Le)},{trigger:ko(()=>[Wt(Gp,{trigger:"hover",disabled:!Le.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:ko(()=>[Wt(L0,{"toolbar-item":Le,disabled:Le.disabled.value,"allow-enter-propagation":!0,onTextSubmit:_=>T(Le,_),onMainClick:_=>R(Le)},null,8,["toolbar-item","disabled","onTextSubmit","onMainClick"])]),default:ko(()=>[Me("div",null,[Fi(Nt(Le.tooltip)+" ",1),Le.disabled.value?(me(),ke("span",pN,"(disabled)")):ut("",!0)])]),_:2},1032,["disabled","content-style"])]),_:2},1032,["options","disabled","show","content-style","onSelect","onUpdate:show","style","menu-props","node-props"])):d(Le)?(me(),dn(Gp,{key:4,trigger:"hover",class:"sd-editor-toolbar-tooltip","content-style":{fontFamily:s.uiFontFamily}},{trigger:ko(()=>[Wt(L0,{"toolbar-item":Le,"is-overflow-item":e.fromOverflow,onTextSubmit:_=>T(Le,_),onButtonClick:_=>C(Le)},null,8,["toolbar-item","is-overflow-item","onTextSubmit","onButtonClick"])]),default:ko(()=>[Le.tooltip?(me(),ke("div",mN,[Fi(Nt(Le.tooltip)+" ",1),Le.disabled.value?(me(),ke("span",gN,"(disabled)")):ut("",!0)])):ut("",!0)]),_:2},1032,["content-style"])):ut("",!0),k(Le)&&e.overflowItems.length?(me(),dn(DB,{key:5,"toolbar-item":Le,onButtonClick:_=>C(Le),"overflow-items":e.overflowItems,onClose:M},null,8,["toolbar-item","onButtonClick","overflow-items"])):ut("",!0)],42,dN))),128))],36))}},Wp=fn(vN,[["__scopeId","data-v-590293ab"]]),yN=[["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"]];const bN=yN.map(([e,t])=>({label:e,key:e,fontWeight:400,props:{style:{fontFamily:`${e}, ${t}`},"data-item":"btn-fontFamily-option"}}));function wN(e){if(e?.length)return e.map(t=>({label:t.label,key:t.value,fontWeight:400,props:{style:{fontFamily:t.previewFamily||t.label},"data-item":"btn-fontFamily-option"}}))}const CN=[{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"}}],_f={sm:768,md:1024,lg:1280,xl:1410},D0={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"},Ok={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"},Fk=Object.values(Ok),Cj=[...new Set([...Object.values(D0),...Fk])];var _N=new Set(["link"]);const _j=new Set(Object.keys(D0).filter(e=>!_N.has(e)));It(),mn();var SN="Arial, Helvetica, sans-serif",kN={__name:"Toolbar",emits:["command","toggle","select"],setup(e,{emit:t}){const{proxy:n}=or();let r=ne(1);const o=ne(0),i=ne(!1);let s=null,a=null;const l=Ae(()=>{const H=n?.$toolbar?.config?.uiDisplayFallbackFont;return typeof H=="string"&&H.trim()?H.trim():SN}),u=n.$toolbar.config?.toolbarGroups?.includes("left"),c=n.$toolbar.config?.toolbarGroups?.includes("right"),d=n.$toolbar.config?.toolbarButtonsExclude||[],h=H=>(o.value,n.$toolbar.getToolbarItemByGroup(H).filter(B=>!d.includes(B.name.value))),m=()=>{i.value=n.$toolbar.getAvailableWidth()<=_f.lg},g=uB(async()=>{await n.$toolbar.onToolbarResize(),m(),r.value+=1},300),k=()=>{r.value+=1},w=()=>{o.value+=1};function S(){window.removeEventListener("resize",g),n.$toolbar.off?.("toolbar-items-changed",k),n.$toolbar.off?.("toolbar-state-change",w),s?.disconnect(),s=null}function y(){S(),window.addEventListener("resize",g),n.$toolbar.on?.("toolbar-items-changed",k),n.$toolbar.on?.("toolbar-state-change",w),typeof ResizeObserver<"u"&&n.$toolbar.config?.responsiveToContainer&&n.$toolbar.toolbarContainer&&(s=new ResizeObserver(()=>{g()}),s.observe(n.$toolbar.toolbarContainer)),m()}Rn(y),fg(y),hg(S),rr(S);const C=()=>{if(!n.$toolbar.activeEditor){a=null,n.$toolbar.pendingSelectionCapture=null;return}a=n.$toolbar.ui?.selection?.capture?.()??null,n.$toolbar.pendingSelectionCapture=a},T=({item:H,argument:B,option:z})=>{R(),n.$toolbar.emitCommand({item:H,argument:B,option:z})},R=()=>{const H=n.$toolbar.activeEditor;if(!H)return;const B=n.$toolbar.pendingSelectionCapture??a;if(B&&typeof n.$toolbar.ui?.selection?.restore=="function"){n.$toolbar.ui.selection.restore(B);return}H.commands?.restoreSelection?.()},M=H=>{C(),!H.target.closest('input, textarea, [contenteditable="true"]')&&H.preventDefault()};return(H,B)=>(me(),ke("div",{class:"superdoc-toolbar",key:We(r),role:"toolbar","aria-label":"Toolbar","data-sd-part":"toolbar","data-editor-ui-surface":"",onMousedown:M},[We(u)?(me(),dn(Wp,{key:0,tabindex:"0","toolbar-items":h("left"),"overflow-items":We(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"left",onCommand:T,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):ut("",!0),Wt(Wp,{tabindex:"0","toolbar-items":h("center"),"overflow-items":We(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"center",onCommand:T},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"]),We(c)?(me(),dn(Wp,{key:1,tabindex:"0","toolbar-items":h("right"),"overflow-items":We(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"right",onCommand:T,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):ut("",!0)],32))}},AN=fn(kN,[["__scopeId","data-v-55b5af7a"]]);const IN=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"}}};It();const wn=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 label - "+e.name);if(!e.name)throw new Error("Invalid toolbar item name - "+e.name);const t=ne(Ji()),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),u=ne(e.attributes||{}),c=e.disabled||!1,d=ne(e.disabled),h=ne(!1),m=ne(!1),p=ne(e.style),g=ne(e.isNarrow),k=ne(e.isWide),w=ne(e.minWidth),S=ne(e.suppressActiveHighlight||!1),y=ne(e.argument),C=ne(null),T=ne(null),R=ne(e.iconColor),M=ne(e.hasCaret),H=ne(!!e.splitButton),B=e.splitButtonCommand,z=!!e.restoreEditorFocus,X=ne(e.dropdownStyles),P=ne(e.tooltip),N=ne(e.tooltipVisible),I=ne(e.tooltipTimeout),L=ne(e.defaultLabel),Y=ne(e.label),te=ne(e.hideLabel),le=ne(e.inlineTextInputVisible),fe=ne(e.hasInlineTextInput),Ne=ne(e.markName),he=ne(e.labelAttr),ge=ne(e.selectedValue),ae=ne(e.dropdownValueKey),_e=ne(e.inputRef||null),oe=ne([]);if(e.options){if(!Array.isArray(e.options))throw new Error("Invalid toolbar item options - "+e.options);oe.value?.push(...e.options)}const Te=(_={},...$)=>{be(_,...$),!S.value&&(h.value=!0)},Ge=()=>{Ve(),h.value=!1},Je=_=>{d.value=_},_t=()=>{d.value=c},be=e.onActivate||(()=>null),Ve=e.onDeactivate||(()=>null),Le=()=>{const _={};return Object.keys(J).forEach($=>{J[$].value!==void 0&&(_[$]=J[$].value)}),_},J={id:t,name:r,type:n,command:o,noArgumentCommand:i,icon:s,tooltip:P,group:a,attributes:u,disabled:d,active:h,expand:m,nestedOptions:oe,style:p,isNarrow:g,isWide:k,minWidth:w,argument:y,parentItem:T,iconColor:R,hasCaret:M,splitButton:H,splitButtonCommand:B,dropdownStyles:X,tooltipVisible:N,tooltipTimeout:I,defaultLabel:L,label:Y,hideLabel:te,inlineTextInputVisible:le,hasInlineTextInput:fe,restoreEditorFocus:z,markName:Ne,labelAttr:he,childItem:C,allowWithoutEditor:l,dropdownValueKey:ae,selectedValue:ge,inputRef:_e};return{...J,unref:Le,activate:Te,deactivate:Ge,setDisabled:Je,resetDisabled:_t,onActivate:be,onDeactivate:Ve}};It(),mn();var EN=["onClick","innerHTML","aria-label","onKeydown"],xN={__name:"AlignmentButtons",emits:["select"],setup(e,{emit:t}){const{isHighContrastMode:n}=Hi(),r=t,o=ne([]),i=[{key:"left",ariaLabel:"Align left",icon:Zn.alignLeft},{key:"center",ariaLabel:"Align center",icon:Zn.alignCenter},{key:"right",ariaLabel:"Align right",icon:Zn.alignRight},{key:"justify",ariaLabel:"Justify",icon:Zn.alignJustify}],s=c=>{r("select",c)},a=c=>{if(c===o.value.length-1)return;const d=o.value[c+1];d&&(d.setAttribute("tabindex","0"),d.focus())},l=c=>{if(c===0)return;const d=o.value[c-1];d&&(d.setAttribute("tabindex","0"),d.focus())},u=(c,d)=>{switch(c.key){case"ArrowLeft":l(d);break;case"ArrowRight":a(d);break;case"Enter":s(i[d].key);break;default:break}};return Rn(()=>{const c=o.value[0];c&&(c.setAttribute("tabindex","0"),c.focus())}),(c,d)=>(me(),ke("div",{class:en(["alignment-buttons",{"high-contrast":We(n)}])},[(me(),ke(qt,null,nr(i,(h,m)=>Me("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:Jt(p=>u(p,m),["prevent"])},null,40,EN)),64))],2))}},TN=fn(xN,[["__scopeId","data-v-13e5f7a4"]]);It(),mn();var RN=["onClick","innerHTML","aria-label","onKeydown"],MN={__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}=Hi(),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())},u=d=>{if(d===0)return;const h=i.value[d-1];h&&(h.setAttribute("tabindex","0"),h.focus())},c=(d,h)=>{switch(d.key){case"ArrowLeft":u(h);break;case"ArrowRight":l(h);break;case"Enter":a(o.buttons[h].key);break;default:break}};return Rn(()=>{const d=i.value[0];d&&(d.setAttribute("tabindex","0"),d.focus())}),(d,h)=>(me(),ke("div",{class:en(["style-buttons-list",{"high-contrast":We(n)}])},[(me(!0),ke(qt,null,nr(o.buttons,(m,p)=>(me(),ke("div",{key:m.key,class:en(["sd-button-icon",{"sd-selected":o.selectedStyle===m.key}]),style:gn(s.value),onClick:g=>a(m.key),innerHTML:m.icon,role:"menuitem","aria-label":m.ariaLabel,ref_for:!0,ref_key:"buttonRefs",ref:i,onKeydown:Jt(g=>c(g,p),["prevent"])},null,46,RN))),128))],2))}},Bk=fn(MN,[["__scopeId","data-v-44f37ff6"]]);const LN=[{key:"disc",icon:Zn.bulletListDisc,ariaLabel:"Opaque circle"},{key:"circle",icon:Zn.bulletListCircle,ariaLabel:"Outline circle"},{key:"square",icon:Zn.bulletListSquare,ariaLabel:"Opaque square"}],DN=[{key:"decimal",icon:Zn.numberedListDecimal,ariaLabel:"1. 2. 3."},{key:"decimal-paren",icon:Zn.numberedListDecimalParen,ariaLabel:"1) 2) 3)"},{key:"upper-roman",icon:Zn.numberedListUpperRoman,ariaLabel:"I. II. III."},{key:"lower-roman",icon:Zn.numberedListLowerRoman,ariaLabel:"i. ii. iii."},{key:"upper-alpha",icon:Zn.numberedListUpperAlpha,ariaLabel:"A. B. C."},{key:"upper-alpha-paren",icon:Zn.numberedListUpperAlphaParen,ariaLabel:"A) B) C)"},{key:"lower-alpha",icon:Zn.numberedListLowerAlpha,ariaLabel:"a. b. c."},{key:"lower-alpha-paren",icon:Zn.numberedListLowerAlphaParen,ariaLabel:"a) b) c)"}];It(),mn();var PN=["onClick","onKeydown"],ON={class:"document-mode-column icon-column"},FN=["innerHTML"],BN={class:"document-mode-column text-column"},NN={class:"document-mode-type"},zN={class:"document-mode-description"},HN={__name:"DocumentMode",props:{options:{type:Array}},emits:["select"],setup(e,{emit:t}){const n=t,r=ne([]),{isHighContrastMode:o}=Hi(),i=e,s=c=>{n("select",c)},a=c=>{if(c===r.value.length-1)return;const d=r.value[c+1];d&&(d.setAttribute("tabindex","0"),d.focus())},l=c=>{if(c===0)return;const d=r.value[c-1];d&&(d.setAttribute("tabindex","0"),d.focus())},u=(c,d)=>{switch(c.key){case"ArrowDown":a(d);break;case"ArrowUp":l(d);break;case"Enter":s(i.options[d]);break;default:break}};return Rn(()=>{r.value[0].setAttribute("tabindex","0"),r.value[0].focus()}),(c,d)=>(me(),ke("div",{class:en(["document-mode",{"high-contrast":We(o)}])},[(me(!0),ke(qt,null,nr(e.options,(h,m)=>(me(),ke("div",{class:en(["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:Jt(p=>u(p,m),["prevent"])},[Me("div",ON,[Me("div",{class:"icon-column__icon",innerHTML:h.icon},null,8,FN)]),Me("div",BN,[Me("div",NN,Nt(h.label),1),Me("div",zN,Nt(h.description),1)])],42,PN))),256))],2))}},UN=fn(HN,[["__scopeId","data-v-bee14d7a"]]);It(),mn();var VN={class:"linked-style-buttons","data-editor-ui-surface":""},jN=["onClick","onKeydown","aria-label"],GN={__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,m)=>{switch(d.key){case"ArrowDown":s(h);break;case"ArrowUp":a(h);break;case"Enter":d.preventDefault(),i(m);break;default:break}},u=d=>d?.name??d?.id??"",c=d=>{const h=d?.preview?.css;return h&&typeof h=="object"?h:void 0};return Rn(()=>{r.value[0]&&(r.value[0].setAttribute("tabindex","0"),r.value[0].focus())}),(d,h)=>(me(),ke("div",VN,[(me(!0),ke(qt,null,nr(o.styles,(m,p)=>(me(),ke("div",{key:m.id??p,class:en(["style-item",{selected:e.selectedOption===m.id}]),onClick:g=>i(m),onKeydown:g=>l(g,p,m),"aria-label":`Linked style - ${m.id??u(m)}`,ref_for:!0,ref_key:"styleRefs",ref:r},[Me("div",{class:"style-name","data-item":"btn-linkedStyles-option",style:gn(c(m))},Nt(u(m)),5)],42,jN))),128))]))}},WN=fn(GN,[["__scopeId","data-v-43b5dcca"]]);It(),mn();var KN=["placeholder"],qN={class:"sd-ai-writer__footer"},YN={key:0,class:"sd-ai-writer__error",role:"alert"},XN=["disabled"],QN="https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights",ZN="You are an expert copywriter and you are immersed in a document editor. Only write what is asked for.",JN={__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);Rn(()=>{St(()=>{i.value?.focus()})});function l(p){if(typeof p=="string")return p;if(!p||typeof p!="object")return"";const g=p.custom_prompt;if(Array.isArray(g)){const k=g[0];if(k&&typeof k.value=="string")return k.value}return g&&typeof g=="object"&&typeof g.value=="string"?g.value:typeof p.value=="string"?p.value:typeof p.text=="string"?p.text:""}async function u(p){const g={"Content-Type":"application/json"};t.apiKey&&(g["x-api-key"]=t.apiKey);const k=t.selectedText.trim(),w=k?`Rewrite the following text: "${k}" using these instructions: ${p}`:`Generate text based on the following prompt: ${p}`,S=await fetch(t.endpoint||QN,{method:"POST",headers:g,body:JSON.stringify({stream:!1,context:ZN,insights:[{type:"custom_prompt",name:k?"text_rewrite":"text_generation",message:w,format:[{value:""}]}]})});if(!S.ok){const C=await S.text().catch(()=>"");throw new Error(C||`AI request failed with ${S.status}`)}const y=l((S.headers.get("content-type")||"").includes("application/json")?await S.json():await S.text()).trim();if(!y)throw new Error("AI returned no text.");return y}function c(p){return!p||typeof p!="object"?!0:!(p.success===!1||p.ok===!1)}function d(p){const g=t.doc;if(!g)throw new Error("Document API is unavailable.");t.restoreSelection?.();let k=null,w=!1;if(t.selectedText&&t.target&&typeof g.replace=="function"?(k=g.replace({target:t.target,text:p}),w=!0):t.target&&typeof g.insert=="function"?(k=g.insert({target:t.target,value:p,type:"text"}),w=!0):typeof g.insert=="function"&&(k=g.insert({value:p,type:"text"}),w=!0),!w)throw new Error("Document text insertion is unavailable.");if(!c(k))throw new Error("Unable to insert generated text.")}async function h(){if(a.value){o.value="",r.value=!0;try{d(await u(n.value.trim())),t.handleClose()}catch(p){o.value=p instanceof Error?p.message:String(p)}finally{r.value=!1}}}function m(p){p.key!=="Enter"||p.shiftKey||(p.preventDefault(),h())}return(p,g)=>(me(),ke("form",{class:"sd-ai-writer","data-item":"ai-writer",onSubmit:Jt(h,["prevent"])},[Ms(Me("textarea",{ref_key:"textareaRef",ref:i,"onUpdate:modelValue":g[0]||(g[0]=k=>n.value=k),class:"sd-ai-writer__input",placeholder:s.value,rows:"4",onKeydown:m},null,40,KN),[[Ii,n.value]]),Me("div",qN,[o.value?(me(),ke("p",YN,Nt(o.value),1)):ut("",!0),Me("button",{class:"sd-ai-writer__submit",type:"submit",disabled:!a.value},Nt(r.value?"Generating":"Generate"),9,XN)])],32))}},$N=fn(JN,[["__scopeId","data-v-67f6c6f7"]]);It(),mn();var ez=["aria-label","onClick","onKeydown"],tz=["innerHTML"],nz=["innerHTML"],Kp=7,rz={__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,g)=>g===5||["#FFFFFF","#FAFF09"].includes(p)?{color:"#000"}:{color:"#FFF"},s=p=>{n("select",p.value)},a=ne([]),l=ne([]);Rn(()=>{if(!r.icons.every(g=>Array.isArray(g)))throw new Error("icon props must be 2d array");const p=l.value[0];p&&(p.setAttribute("tabindex","0"),p.focus({preventScroll:!0}))});const u=(p,g)=>{const k=Kp*p+g+1,w=l.value[k];w&&(w.setAttribute("tabindex","0"),w.focus({preventScroll:!0}))},c=(p,g)=>{const k=Kp*p+g-1,w=l.value[k];w&&(w.setAttribute("tabindex","0"),w.focus({preventScroll:!0}))},d=(p,g)=>{const k=g+Kp*(p+1),w=l.value[k];w&&(w.setAttribute("tabindex","0"),w.focus({preventScroll:!0}))},h=(p,g)=>{const k=g+Kp*(p-1),w=l.value[k];w&&(w.setAttribute("tabindex","0"),w.focus({preventScroll:!0}))},m=(p,g,k,w)=>{switch(p.key){case"ArrowRight":u(g,k);break;case"ArrowLeft":c(g,k);break;case"ArrowDown":d(g,k);break;case"ArrowUp":h(g,k);break;case"Enter":s(w);break;case"Escape":n("clickoutside");break;default:break}};return(p,g)=>(me(!0),ke(qt,null,nr(e.icons,(k,w)=>(me(),ke("div",{class:"sd-option-row",key:w,role:"group",ref_for:!0,ref_key:"rowRefs",ref:a},[(me(!0),ke(qt,null,nr(k,(S,y)=>(me(),ke("div",{class:"sd-option",key:y,"aria-label":S.label,role:"menuitem",ref_for:!0,ref_key:"iconRefs",ref:l,onClick:Jt(C=>s(S),["stop","prevent"]),onKeydown:Jt(C=>m(C,w,y,S),["prevent"])},[Me("div",{class:"sd-option__icon",innerHTML:S.icon,style:gn(S.style)},null,12,tz),o.value(S)?(me(),ke("div",{key:0,class:"sd-option__check",innerHTML:We(Zn).colorOptionCheck,style:gn(i(S.value,y))},null,12,nz)):ut("",!0)],40,ez))),128))]))),128))}},Nk=fn(rz,[["__scopeId","data-v-05eb02fc"]]),oz=`<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
  `;It(),mn();var iz={class:"options-grid-wrap"},sz=["innerHTML"],az={class:"option-grid-ctn"},lz={__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)=>(me(),ke("div",iz,[e.hasNoneIcon?(me(),ke("div",{key:0,class:"none-option",role:"menuitem","aria-label":"Clear color selection",onClick:i[0]||(i[0]=s=>r("none"))},[Me("span",{innerHTML:We(oz),class:"none-icon"},null,8,sz),i[1]||(i[1]=Fi(" None ",-1))])):ut("",!0),Me("div",az,[Wt(Nk,{icons:e.icons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"]),e.customIcons.flat().length?(me(),ke(qt,{key:0},[i[2]||(i[2]=Me("span",{class:"option-grid-ctn__subtitle"},"Custom colors",-1)),Wt(Nk,{icons:e.customIcons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"])],64)):ut("",!0)])]))}},cz=fn(lz,[["__scopeId","data-v-52b0283a"]]);const P0=(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})};It();var uz=e=>{e.expand.value=!1};const Vt=(e,t=null)=>({label:t,icon:Zn.colorOption,value:e,style:{color:e,boxShadow:"0 0 5px 1px rgba(0, 0, 0, 0.1)",borderRadius:"50%"}}),O0=(e,t,n=[],r=!1)=>{const o=i=>{t.iconColor.value=i,e.emitCommand({item:t,argument:i}),uz(t),P0(e)};return Dr("div",{},[Dr(cz,{icons:dz,customIcons:n,activeColor:t.iconColor,hasNoneIcon:r,onSelect:o})])},dz=[[Vt("#111111","black"),Vt("#333333","dark gray"),Vt("#5C5C5C","medium gray"),Vt("#858585","light gray"),Vt("#ADADAD","very light gray"),Vt("#D6D6D6","transparent gray"),Vt("#FFFFFF","white")],[Vt("#860028","dark red"),Vt("#D2003F","red"),Vt("#DB3365","coral red"),Vt("#E4668C","light red"),Vt("#ED99B2","pale pink"),Vt("#F6CCD9","transparent pink"),Vt("#FF004D","bright pink")],[Vt("#83015E","dark purple"),Vt("#CD0194","purple"),Vt("#D734A9","orchid"),Vt("#E167BF","light purple"),Vt("#EB99D4","lavender"),Vt("#F5CCEA","transparent pink"),Vt("#FF00A8","neon pink")],[Vt("#8E220A","maroon"),Vt("#DD340F","red-orange"),Vt("#E45C3F","burnt orange"),Vt("#EB856F","peach"),Vt("#F1AE9F","pale peach"),Vt("#F8D6CF","transparent peach"),Vt("#FF7A00","orange")],[Vt("#947D02","olive"),Vt("#E7C302","mustard yellow"),Vt("#ECCF35","yellow"),Vt("#F1DB67","light yellow"),Vt("#F5E79A","very pale yellow"),Vt("#FAF3CC","transparent yellow"),Vt("#FAFF09","neon yellow")],[Vt("#055432","forest green"),Vt("#07834F","green"),Vt("#399C72","medium green"),Vt("#6AB595","light green"),Vt("#9CCDB9","mint"),Vt("#CDE6DC","transparent mint"),Vt("#05F38F","bright teal")],[Vt("#063E7E","navy blue"),Vt("#0A60C5","blue"),Vt("#3B80D1","sky blue"),Vt("#6CA0DC","cornflower blue"),Vt("#9DBFE8","light blue"),Vt("#CEDFF3","very light blue"),Vt("#21c8ce","cyan")],[Vt("#3E027A","deep purple"),Vt("#6103BF","indigo"),Vt("#8136CC","violet"),Vt("#A068D9","lavender pink"),Vt("#C09AE6","light lilac"),Vt("#DFCDF2","transparent lilac"),Vt("#A91DFF","neon purple")]];It(),mn();var fz=["data-cols","data-rows","onKeydown","onClick"],hz=["aria-valuetext"],qp=5,pz={__name:"TableGrid",emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=ne(0),o=ne(0),{isHighContrastMode:i}=Hi(),s=ne([]),a=d=>{let h=d.target;h.dataset.grid||l([...h.parentElement.querySelectorAll("[data-item]")],parseInt(h.dataset.cols,10),parseInt(h.dataset.rows,10))},l=(d,h,m)=>{o.value=h,r.value=m;for(let p=0;p<d.length;p++){let g=d[p],k=parseInt(g.dataset.cols,10),w=parseInt(g.dataset.rows,10);k<=h&&w<=m?g.classList.add("sd-selected"):g.classList.remove("sd-selected")}},u=({cols:d,rows:h})=>{n("select",{cols:d,rows:h})},c=(d,h,m)=>{let p=h-1,g=m-1;switch(d.key){case"ArrowRight":{if(p>=4)return;const k=g*qp;s.value[k+p+1].setAttribute("tabindex","0"),s.value[k+p+1].focus(),l(s.value,h+1,m);break}case"ArrowLeft":{if(p<=0)return;const k=g*qp;s.value[k+p-1].setAttribute("tabindex","0"),s.value[k+p-1].focus(),l(s.value,h-1,m);break}case"ArrowDown":{if(g>=4)return;const k=(g+1)*qp;s.value[k+p].setAttribute("tabindex","0"),s.value[k+p].focus(),l(s.value,h,m+1);break}case"ArrowUp":{if(g<=0)return;const k=(g-1)*qp;s.value[k+p].setAttribute("tabindex","0"),s.value[k+p].focus(),l(s.value,h,m-1);break}case"Enter":u({cols:h,rows:m});break;default:break}};return Rn(()=>{s.value[0].setAttribute("tabindex","0"),s.value[0].focus(),l(s.value,1,1)}),(d,h)=>(me(),ke("div",{class:en(["toolbar-table-grid-wrapper",{"high-contrast":We(i)}])},[Me("div",{class:"toolbar-table-grid",onMouseover:a,"data-grid":"true"},[(me(),ke(qt,null,nr(5,m=>(me(),ke(qt,{key:m},[(me(),ke(qt,null,nr(5,p=>Me("div",{class:"toolbar-table-grid__item",key:`${m}_${p}`,"data-cols":p,"data-rows":m,"data-item":"true",ref_for:!0,ref_key:"tableGridItems",ref:s,onKeydown:Jt(g=>c(g,p,m),["prevent"]),onClick:Jt(g=>u({cols:p,rows:m}),["stop","prevent"])},null,40,fz)),64))],64))),64))],32),Me("div",{class:"toolbar-table-grid-value","aria-valuetext":`${r.value} x ${o.value}`},Nt(r.value)+" x "+Nt(o.value),9,hz)],2))}},mz=fn(pz,[["__scopeId","data-v-b87d6ca2"]]);It(),mn();var gz={class:"toolbar-table-actions"},vz=["onClick","data-item","ariaLabel"],yz={class:"toolbar-table-actions__icon"},bz=["innerHTML"],wz={class:"toolbar-table-actions__label"},Cz={__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)=>(me(),ke("div",gz,[(me(!0),ke(qt,null,nr(e.options,s=>(me(),ke("div",{class:en(["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"},[Me("div",yz,[Me("div",{class:"toolbar-table-actions__icon-wrapper",innerHTML:s.icon},null,8,bz)]),Me("div",wz,Nt(s.label),1)],10,vz))),256))]))}},_z=fn(Cz,[["__scopeId","data-v-0cdad084"]]),Sz=`<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
- `;It();var ps=e=>{e.expand.value=!1};function F0(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function zk(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 kz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function Hk(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Az(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function Iz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}const Ez=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=wn({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),u=(r??bN).map(IN),c=wn({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:u,onActivate:({fontFamily:Ke}={},kt=!1)=>{if(kt){c.label.value="",c.selectedValue.value="";return}if(!Ke)return;Ke=Ke.split(",")[0],c.label.value=Ke;const Ut=u.find(Ot=>Ot.label===c.defaultLabel.value),Ft=u.find(Ot=>Ot.label===Ke);Ft?c.selectedValue.value=Ft.key:Ut?c.selectedValue.value=Ut.key:c.selectedValue.value=""},onDeactivate:()=>{c.label.value=c.defaultLabel.value;const Ke=u.find(kt=>kt.label===c.defaultLabel.value);Ke?c.selectedValue.value=Ke.key:c.selectedValue.value=""}}),d=wn({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(Ke){const kt=Hk(e),Ut=kt?.selectionTarget??zk(kt?.target),Ft=kt?.empty?"":kz(kt),Ot=Iz(e),hn=()=>ps(Ke),yn=()=>{const De=e.pendingSelectionCapture;De&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(De)};return Dr("div",{},[Dr($N,{handleClose:hn,selectedText:Ft,target:Ut,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Ot?.apiKey||e.config?.aiApiKey||"",endpoint:Ot?.endpoint||e.config?.aiEndpoint||"",restoreSelection:yn})])}const m=CN,p=wn({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:m,onActivate:({fontSize:Ke},kt=!1)=>{if(kt){p.label.value="",p.selectedValue.value="";return}const Ut=m.find(yn=>yn.label===String(p.defaultLabel.value));if(!Ke){p.label.value=p.defaultLabel.value,Ut?p.selectedValue.value=Ut.key:p.selectedValue.value="";return}let Ft=cB(Ke,12);Ft<8&&(Ft=8),Ft>96&&(Ft=96);let Ot=String(Ft);const hn=m.find(yn=>yn.label===Ot||yn.key===Ot);hn?p.selectedValue.value=hn.key:p.selectedValue.value="",p.label.value=Ot},onDeactivate:()=>{p.label.value=p.defaultLabel.value;const Ke=m.find(kt=>kt.label===String(p.defaultLabel.value));Ke?p.selectedValue.value=Ke.key:p.selectedValue.value=""}}),g=wn({type:"separator",name:"separator",isNarrow:!0}),k=wn({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),w=wn({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),S=wn({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=wn({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:()=>O0(e,y,[],!0)}],onActivate:({color:Ke})=>{y.iconColor.value=Ke||""},onDeactivate:()=>y.iconColor.value=""}),C=wn({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:()=>O0(e,C)}],onActivate:({color:Ke})=>{C.iconColor.value=Ke},onDeactivate:()=>C.iconColor.value="#000"}),T=wn({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),R=wn({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>M(R)}],onActivate:({href:Ke})=>{R.attributes.value=F0(R.attributes.value,Ke)},onDeactivate:()=>{R.attributes.value=F0(R.attributes.value,null),R.expand.value=!1}});function M(Ke){const kt=Hk(e),Ut=kt?.selectionTarget??zk(kt?.target),Ft=()=>{const Ot=e.pendingSelectionCapture;Ot&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Ot)};return Dr("div",{},[Dr(uS,{ui:e.ui,linkItem:Ke,textTarget:Ut,restoreSelection:Ft,closePopover:()=>ps(Ke),goToAnchor:()=>{ps(Ke);const Ot=Ke.attributes.value?.href;if(!Ot)return;const hn=Ot.slice(1),yn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${hn}']`);yn&&$d(yn)}})])}const H=wn({type:"options",name:"linkInput",command:"toggleLink",active:!1});R.childItem=H,H.parentItem=R;const B=wn({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),z=wn({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),X=wn({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:()=>P(X)}]});function P(Ke){return Dr("div",{},[Dr(mz,{onSelect:Ut=>{e.emitCommand({item:Ke,argument:Ut}),ps(Ke),P0(e)}})])}const N=wn({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>L(N)}]}),I=[{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 L(Ke){return Dr(_z,{options:I,onSelect:kt=>{ps(Ke);const{command:Ut}=kt;e.emitCommand({item:Ke,argument:{command:Ut}})}})}const Y=wn({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:()=>Dr("div",{},[Dr(TN,{onSelect:kt=>{ps(Y);const Ut={...Y,command:"setTextAlign"};Ut.command="setTextAlign",e.emitCommand({item:Ut,argument:kt}),te(Y,kt)}})]),key:"alignment"}],onActivate:({textAlign:Ke})=>{te(Y,Ke)},onDeactivate:()=>{te(Y,"left")}}),te=(Ke,kt)=>{let Ut=kt==="both"?"justify":kt,Ft={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Ot=Ft[Ut]??Ft.left;Ke.icon.value=Ot},le=wn({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 Ke=kt=>{ps(le);const Ut={...le,command:"toggleBulletListStyle"};e.emitCommand({item:Ut,argument:kt})};return Dr(Bk,{buttons:LN,iconSize:25,selectedStyle:le.selectedValue.value,onSelect:Ke})}}]}),fe=wn({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 Ke=kt=>{ps(fe);const Ut={...fe,command:"toggleOrderedListStyle"};e.emitCommand({item:Ut,argument:kt})};return Dr(Bk,{buttons:DN,iconSize:30,selectedStyle:fe.selectedValue.value,onSelect:Ke})}}]}),Ne=wn({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),he=wn({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ge=wn({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ae=wn({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:Ke})=>{Ke&&(ae.label.value=Ke)}}),_e=wn({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:Ke})=>{Ke&&(_e.label.value=Ke)}}),oe=wn({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Te=wn({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),Ge=wn({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),Je=wn({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),_t=wn({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),be=wn({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),Ve=(Ke,kt)=>Ke==="editor"?kt:Ke==="suggester"?kt.filter(Ut=>Ut.value==="suggesting"):kt.filter(Ut=>Ut.value==="viewing"),Le=Ke=>Ke==="editor"?"Editing":Ke==="suggester"?"Suggesting":"Viewing",J=wn({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:Le(s),label:Le(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:()=>$(J)}]}),_=[{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 $(Ke){return Dr(UN,{options:Ve(s,_),onSelect:kt=>{const Ut=e.superdoc?.activeEditor??e.activeEditor;ps(Ke);const{label:Ft,icon:Ot,value:hn}=kt;J.label.value=Ft,J.icon.value=Ot,e.emitCommand({item:J,argument:hn}),P0(e,Ut)}})}const F=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),j=["search","ruler","undo","overflow","documentMode"],V=wn({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),G=wn({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),Z=wn({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 Ke=Ut=>{ps(Z);const Ft=typeof Ut=="string"?Ut:Ut?.id??null;if(!Ft)return;const Ot={...Z,command:"setLinkedStyle"};e.emitCommand({item:Ot,argument:Ft})},kt=e.getActiveLinkedStyleId?.()??null;return Dr("div",{},[Dr(WN,{styles:e.getLinkedStyleOptions?.()??[],onSelect:Ke,selectedOption:kt})])}}],onActivate:({styleId:Ke,styleName:kt})=>{const Ut=kt||Ke;Z.label.value=Ke&&Ke!=="Normal"?String(Ut):n.formatText,Z.disabled.value=!1},onDeactivate:()=>{Z.disabled.value=!0,Z.label.value=n.formatText}}),W=(Ke,kt)=>{if(kt.value==Ke)return Dr("div",{innerHTML:Sz,class:"dropdown-select-icon"})},K=wn({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(Ke=>({label:Ke.toFixed(2),key:Ke,icon:()=>W(Ke,K.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),ue=20,we=32,Ce=j.reduce((Ke,kt)=>Ke+(F.get(kt)||F.get("default")),0),xe=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],ot=["zoom","fontFamily","fontSize","redo"],tt=i<=_f.lg,Ct=e.config?.showFormattingMarksButton===!0,Kt=e.config?.showTableOfContentsButton===!0;tt&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),tt&&(Z.attributes.value={...Z.attributes.value,className:`${Z.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let pt=[oe,Te,Ge,Je,T,ae,c,g,p,g,l,k,w,S,C,y,g,R,B,...Kt?[z]:[],X,N,g,Y,le,fe,Ne,he,K,g,Z,g,V,_e,...Ct?[G]:[],be,_t,...Az(e)?[d]:[],ge,J];if(i<=_f.md&&o&&(pt=pt.filter(Ke=>Ke.type!=="separator")),e.config.mode!=="docx"){const Ke=pt.findIndex(Ut=>Ut.name.value==="linkedStyles");pt.splice(Ke-1,2);const kt=["ruler","zoom","undo","redo"];pt=pt.filter(Ut=>!kt.includes(Ut.name.value))}const Mt=[];a||(s==="viewer"&&Mt.push(Ge,Je),pt=pt.filter(Ke=>!Mt.includes(Ke)));const zt=Ke=>j.includes(Ke.name.value),ln=[],$n=[];let Ht=we+Ce;return pt.forEach(Ke=>{const kt=F.get(Ke.name.value)||F.get("default");if(i<_f.xl+ue&&xe.includes(Ke.name.value)&&o){if(ln.push(Ke),Ke.name.value==="linkedStyles"){const Ut=pt.findIndex(Ft=>Ft.name.value==="linkedStyles");pt.splice(Ut+1,1)}return}if(i<_f.sm&&ot.includes(Ke.name.value)&&o){ln.push(Ke);return}if(zt(Ke)){$n.push(Ke),Ht+=kt;return}Ht<i||!o?($n.push(Ke),Ht+=kt):ln.push(Ke)}),{defaultItems:$n,overflowItems:ln.filter(Ke=>Ke.type!=="separator")}},Uk={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"},xz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;It();function Vk(e){return tB(e)??D0[e]??null}function Yp(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 Tz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Rz=new Set(["list","numberedlist"]);function Mz(e,t){if(e==="fontFamily"||e==="fontSize"||Rz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Tz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function jk(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Lz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var Dz=class extends Rm.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...Zn},texts:{...Uk},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={...Zn,...e.icons},this.config.texts={...Uk,...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._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=xz(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.#u(),this.#l(),this.#s(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Bl(AN),this.app.directive("click-outside",Dv),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.#D():this.#k()}))}#i(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#k();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#s(){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.#m()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#a(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#u(){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}#d(e){return e||wN(this.superdoc?.fonts?.getFontFamilyOptions?.()??[])}#l(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=Ez({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#d(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=o.map(l=>this.#f(l));o.length&&n.push(...i);let s=[...n.map(l=>l.name.value),...r.map(l=>l.name.value)];if(t){const l=Object.values(this.config.groups).flatMap(d=>d),u=new Set(Object.keys(this.config.groups)),c=i.filter(d=>u.has(d.group?.value||"center")).map(d=>d.name.value);s=[...new Set([...l,...c])]}const a=n.filter(l=>s.includes(l.name.value)).filter(l=>!this.config.excludeItems.includes(l.name.value));if(t)for(const[l,u]of Object.entries(this.config.groups))for(const c of a)u.includes(c.name.value)&&(c.group.value=l);this.toolbarItems=a,this.overflowItems=r.filter(l=>s.includes(l.name.value))}#f(e){const t=wn({...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}#m(){this.#l(),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.#r().find(t=>t.name.value===e)}#r(){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.#m()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#l(),this.updateToolbarState()};#p(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#y(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#w(){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)}#_(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>O0(this,e,[],!0)};e.nestedOptions.value=[t]}#S(e){return!!e?.active&&e?.value==null}#E(e){return!!e&&e.disabled===!1&&e.value==null}#x(e){const t=e.name.value;if(t==="tableActions"){const i=Fk.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(M0(t)?.disposition==="host-routed")return e.setDisabled(!this.#y(t)),this.#p(t)?e.activate():e.deactivate(),!0;const n=Vk(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];Mz(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.#w()},link:()=>{e.active.value=!!r?.active,e.attributes.value=F0(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#E(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#S(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.#w(),this.#_();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#M(),this.#r().forEach(n=>{n.allowWithoutEditor?.value&&this.#x(n)})):this.#r().forEach(n=>{n.resetDisabled(),this.#x(n)});const t=this.getToolbarItemByName("copyFormat");t&&(this.snapshot?.copyFormatActive?t.activate():t.deactivate()),this.emit("toolbar-state-change")}#M(){this.#r().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#c(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}#L(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#g(i,n)};if(n==="image"&&t==null)return this.#T();if(n==="tableActions"){const i=Ok[t?.command];return i?Yp(this.ui,i,void 0,r):!1}if(M0(n)?.disposition==="unsupported")return!0;const o=Vk(n);return o?Yp(this.ui,o,t,r):!1}#T(){return this.snapshot?.commands?.image?.disabled||(this.#t||(this.#t=lB({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await sB(e,this.superdoc?.config?.handleImageUpload);Yp(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#g(n,"image")})},onError:e=>this.#g(e,"image")})),this.#t.open()),!0}#D(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{jk(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!jk(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Lz(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)}}#k(){this.#n&&(this.#n(),this.#n=null)}#g(e,t){const n=e instanceof Error?e:new Error(String(e));this.emit("exception",{error:n,originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null})}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(M0(r)?.disposition==="host-routed"){this.#c(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(!Yp(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#g(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#L(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#g(s,r)}}}destroy(){this.#k(),this.#t?.destroy(),this.#t=null,this.#a(),this.#i(),this.app?.unmount(),this.app=null,this.toolbar=null}};function Pz(e){return new Dz(e)}function Oz(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 Fz(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=Xp(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=Nz(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=Bz(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=zz(e.border);return i&&(t.border=i),t}function Xp(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function Bz(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 Nz(e){if(!e)return;const t={},n=Xp(e.fill);n!=null&&(t.fill=n);const r=Xp(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function zz(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=Xp(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function Ql(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}function Gk(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function Hz(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 Gk(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function Wk(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=Hz(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const m of a){const p=`trackedChange:${m}`;if(!r.has(p)){r.add(p);const g={type:"trackedChange",id:m};l&&(g.storyKey=l),n.push(g),o.push(g)}}const u=s.getAttribute("data-layout-story");if(u&&o.length>0){for(const m of o)m.story=u;o=[]}const c=s.getAttribute("data-comment-ids");if(c)for(const m of Gk(c)){const p=`comment:${m}`;r.has(p)||(r.add(p),n.push({type:"comment",id:m}))}const d=s.getAttribute("data-sdt-type"),h=s.getAttribute("data-sdt-id");if(h&&d==="structuredContent"){const m=`contentControl:${h}`;if(!r.has(m)){r.add(m);const p=s.getAttribute("data-sdt-scope"),g=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:h};(p==="block"||p==="inline")&&(k.scope=p),g&&(k.tag=g),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}const B0={PAGE:"superdoc-page",FRAGMENT:"superdoc-fragment",LINE:"superdoc-line",INLINE_SDT_WRAPPER:"superdoc-structured-content-inline",INLINE_SDT_LABEL:"superdoc-structured-content-inline__label",BLOCK_SDT:"superdoc-structured-content-block",BLOCK_SDT_LABEL:"superdoc-structured-content__label",TABLE_FRAGMENT:"superdoc-table-fragment",DOCUMENT_SECTION:"superdoc-document-section",SDT_GROUP_HOVER:"sdt-group-hover",TOC_ENTRY:"superdoc-toc-entry",TOC_GROUP_HOVER:"toc-group-hover",IMAGE_FRAGMENT:"superdoc-image-fragment",INLINE_IMAGE:"superdoc-inline-image",LIST_MARKER:"superdoc-list-marker",INLINE_IMAGE_CLIP_WRAPPER:"superdoc-inline-image-clip-wrapper",ANNOTATION:"annotation",ANNOTATION_CONTENT:"annotation-content",ANNOTATION_CARET_ANCHOR:"annotation-caret-anchor"},Sj=[B0.INLINE_SDT_LABEL,B0.BLOCK_SDT_LABEL],Kk={PM_START:"data-pm-start",PM_END:"data-pm-end",LAYOUT_EPOCH:"data-layout-epoch",TABLE_BOUNDARIES:"data-table-boundaries",SDT_ID:"data-sdt-id",SDT_TYPE:"data-sdt-type",FIELD_ID:"data-field-id",FIELD_TYPE:"data-field-type",DRAGGABLE:"data-draggable",DISPLAY_LABEL:"data-display-label",VARIANT:"data-variant",TYPE:"data-type",LAYOUT_BOUNDARY_SCHEMA:"data-layout-boundary-schema",LAYOUT_FRAGMENT_ID:"data-layout-fragment-id",LAYOUT_STORY:"data-layout-story",LAYOUT_BLOCK_REF:"data-layout-block-ref"},Uz=e=>{if(!e)return{kind:"unknown"};if(e==="body")return{kind:"body"};const t=e.indexOf(":"),n=t===-1?e:e.slice(0,t),r=t===-1?void 0:e.slice(t+1);switch(n){case"body":case"header":case"footer":case"footnote":case"endnote":case"textbox":return r?{kind:n,id:r}:{kind:n};default:return{kind:"unknown"}}},kj=`.${B0.BLOCK_SDT}[${Kk.SDT_ID}]`,Aj=`[${Kk.DRAGGABLE}="true"]`;var io=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),Za=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),du=()=>({oneOf:[{type:"number"},{type:"null"}]}),fu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),Vz={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},jz={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},Gz=()=>({oneOf:[{type:"boolean"},{type:"null"},Vz]}),Wz=()=>({oneOf:[{type:"array",items:jz,minItems:1},{type:"null"}]});function Qp(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function Kz(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var N0=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:Qp(n),schema:io()}),Zl=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:Qp("textStyle",o??e),schema:r}),Ln=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:Kz(o??e),schema:r});const Zp=[N0("bold","w:b","bold"),N0("italic","w:i","italic"),N0("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:Qp("underline"),schema:Gz()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:Qp("highlight"),schema:Za()},Zl("color","string","w:color",Za()),Zl("fontSize","number","w:sz",du()),Zl("fontFamily","string","w:rFonts",Za()),Zl("letterSpacing","number","w:spacing",du()),Zl("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),Zl("position","number","w:position",du()),Ln("dstrike","boolean","w:dstrike",io()),Ln("smallCaps","boolean","w:smallCaps",io()),Zl("caps","boolean","w:caps",io(),"textTransform"),Ln("shading","object","w:shd",fu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("border","object","w:bdr",fu({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"),Ln("outline","boolean","w:outline",io()),Ln("shadow","boolean","w:shadow",io()),Ln("emboss","boolean","w:emboss",io()),Ln("imprint","boolean","w:imprint",io()),Ln("charScale","number","w:w",du(),"w"),Ln("kerning","number","w:kern",du(),"kern"),Ln("vanish","boolean","w:vanish",io()),Ln("webHidden","boolean","w:webHidden",io()),Ln("specVanish","boolean","w:specVanish",io()),Ln("rtl","boolean","w:rtl",io()),Ln("cs","boolean","w:cs",io()),Ln("bCs","boolean","w:bCs",io(),"boldCs"),Ln("iCs","boolean","w:iCs",io(),"italicCs"),Ln("eastAsianLayout","object","w:eastAsianLayout",fu({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"}]}})),Ln("em","string","w:em",Za()),Ln("fitText","object","w:fitText",fu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("snapToGrid","boolean","w:snapToGrid",io()),Ln("lang","object","w:lang",fu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("oMath","boolean","w:oMath",io()),Ln("rStyle","string","w:rStyle",Za(),"styleId"),Ln("rFonts","object","w:rFonts",fu({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"),Ln("fontSizeCs","number","w:szCs",du()),Ln("ligatures","string","w14:ligatures",Za()),Ln("numForm","string","w14:numForm",Za()),Ln("numSpacing","string","w14:numSpacing",Za()),Ln("stylisticSets","array","w14:stylisticSets",Wz()),Ln("contextualAlternates","boolean","w14:cntxtAlts",io())],Ij=new Set(Zp.map(e=>e.key)),qz=Object.fromEntries(Zp.map(e=>[e.key,e])),Ej={mark:Zp.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:Zp.filter(e=>e.storage==="runAttribute").map(e=>e.key)};var Yz=new Set(Object.values(at));function z0(e,t){return typeof e=="string"&&Yz.has(e)?e:t}function qk(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:at.notReady}:{ok:!1,reason:z0(t,at.targetUnresolved)}}return{ok:!0}}var Xz=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],Qz={[kk.bulletList]:"bullet",[kk.numberedList]:"ordered"};function Yk(e){return Qz[e]??null}var Zz={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 Jz(e){const t=Zz[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var $z={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""};const eH=[{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: body tracked-changes list; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: all-story tracked-changes list; consumers already fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}];var tH=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function nH(e){return eH.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var Xk={ready:0,stale:1,pending:2};function hu(...e){let t="ready";for(const n of e)Xk[n]>Xk[t]&&(t=n);return t}function Tt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Or(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function gr(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 ar(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Sf(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 H0(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function xo(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 Jp(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=H0(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 Ja(e,t,n){return Hn(e)!==t?!1:n?xo(Jp(e))===xo(n):!0}function Qk(e){const t=Jp(e);if(!(!t||xo(t)===xo(null)))return t}function rH(e){if(typeof e!="string"||e.length===0)return;const t=Uz(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 oH(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 U0(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function $p(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function iH(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 Hn(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 sH(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 Zk=new WeakMap;function aH(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 u=s.replacement;if(u&&typeof u=="object")for(const d of[u.inserted,u.deleted])d&&typeof d=="object"&&(n(d.id),n(d.wordId));const c=s.move;if(c&&typeof c=="object")for(const d of[c.source,c.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 em(e){const t=Zk.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=Hn(i);if(s){n.add(s);for(const a of aH(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 Zk.set(e,o),o}var Jk=new WeakMap;function $k(e,t){const n=xo(t);let r=Jk.get(e);r||(r=new Map,Jk.set(e,r));const o=r.get(n);if(o)return o;const i=em(e.filter(s=>xo(Jp(s))===n));return r.set(n,i),i}function lH(e,t){const n=e.find(r=>Hn(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??Hn(n)??t:null}function cH(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,u=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:u??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 Rr(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 uH=64;function Jl(e){return e.length<=uH}function na(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 mo(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function ra(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function eA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var tA=720;function ms(e){return Math.round(e*20)}function pu(e){return typeof e=="number"&&Number.isFinite(e)}function dH(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=pu(i.left)?ms(i.left):pu(i.start)?ms(i.start):void 0,a=pu(i.right)?ms(i.right):pu(i.end)?ms(i.end):void 0,l=pu(i.firstLine)?ms(i.firstLine):void 0,u=pu(i.hanging)?ms(i.hanging):void 0;return s==null&&a==null&&l==null&&u==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...u!=null?{hanging:u}:{}}}function V0(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 fH(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 kf(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 $a(e){return kf(e.target)??kf(e.selectionTarget)}var nA=["fontFamily","fontSize","color","highlight"],hH={undo:"history.undo",redo:"history.redo"},Af=["bold","italic","underline","strikethrough"];function j0(e){return nA.includes(e)}function mu(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,u,c)=>{typeof l!="string"||typeof u!="number"||typeof c!="number"||r.push({blockId:l,start:Math.min(u,c),end:Math.max(u,c)})};for(const l of n){const u=l?.range;o(l?.blockId,u?.start,u?.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 oa(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 pH(e){const t=oa(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 ia(e){const t=mu(e);return t.length===0?null:[pH(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function rA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:Ql({selectionTarget:t})}function mH(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 gH(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function vH(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 yH(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 oA(e,t){const n=mu(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=>yH(n,vH(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 bH(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 G0(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 wH(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 CH(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function iA(e,t){if(!e)return{};const n=new Map;for(const i of mu(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 nA){const s=new Map;let a=!1,l=!1;for(const u of r){const c=typeof u?.blockId=="string"?u.blockId:null;if(!c)continue;const d=n.get(c);if(!d?.length)continue;const h=Array.isArray(u?.runs)?u.runs:[];for(const m of h){const p=m?.range,g=typeof p?.start=="number"?p.start:null,k=typeof p?.end=="number"?p.end:null;if(g==null||k==null||!d.some(y=>gH(y,{start:g,end:k})))continue;a=!0;const w=bH(m?.styles,i);if(w===void 0){l=!0;continue}const S=CH(i,w);if(s.has(S)||s.set(S,w),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function W0(e,t){const n=Rr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:mo(n)}:{kind:"documentEnd"}}function tn(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 $l(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 tm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function el(e){if(Or(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 nm(e){return!!e&&typeof e=="object"&&e.success===!0}function No(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function gu(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function K0(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 u of l.blocks)n(u);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function ec(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function fi(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!No(i)&&n===null&&(n=i),nm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function _H(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 SH(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function rm(e){return uu(e)?.trackDecision??null}function kH(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function tl(e){return{found:!1,success:!1,rects:[],reason:e}}function AH(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 IH(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 sA(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(IH))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 EH(e){return e.selectionTarget?e.selectionTarget:sA(e.target)}function vu(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=sA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function q0(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var Y0={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},xH=Object.fromEntries(Object.entries(Y0).filter(([e])=>qz[e]?.tracked===!0));function TH(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:{...Y0}};default:return null}}function RH(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 MH(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 LH(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,u=!1,c=Promise.resolve(),d=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},m=0;const p=new Set;let g={},k="",w=null;const S=()=>{const f=t?.activeEditor;return f&&typeof f=="object"?f:null},y=()=>{const f=S()?.doc;return f&&typeof f=="object"?f:null},C=()=>{const f=S()?.v2TrackedChanges;return f&&typeof f=="object"?f:null},T=()=>{const f=S()?.host;return f&&typeof f=="object"?f:null},R=f=>{if(f.storyType!=="headerFooterPart"||typeof f.refId!="string")return null;const v=S(),b=T(),A=v?.pageLayout??b?.pageLayout;if(!A||typeof A!="object")return null;const E=A.getActiveRulerContext,U=b?.resolveHeaderFooterEditTarget;if(typeof E!="function"||typeof U!="function")return null;const Q=Tt(()=>E.call(A),null);if(!Q||typeof Q.pageIndex!="number")return null;for(const re of["header","footer"]){const ye=Tt(()=>U.call(b,{pageIndex:Q.pageIndex,kind:re}),null);if(!(ye?.status!=="ready"||ye.refId!==f.refId||typeof ye.sectionId!="string"||!["default","first","even"].includes(String(ye.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:ye.sectionId},headerFooterKind:re,variant:ye.slotVariant}}return null},M=()=>{const f=T(),v=f?.getPendingInlineFormat;if(typeof v!="function")return null;const b=Tt(()=>v.call(f),null);return b&&typeof b=="object"?b:null},H=f=>{const v=q0(f);if(!v)return null;const b=M();if(!b||!(v in b))return null;const A=b[v];return f.inline?.kind==="toggle"?A===!0:A!=null&&A!==""},B=f=>{const v=q0(f);if(!v)return;const b=M();if(!b||!(v in b))return;const A=b[v];if(typeof A=="string"&&A!=="")return A;if(typeof A=="number"&&Number.isFinite(A))return String(A)},z=(f,v)=>{const b=T(),A=b?.setPendingInlineFormat;typeof A=="function"&&Tt(()=>A.call(b,f,v),void 0)},X=f=>{const v=T(),b=v?.clearPendingInlineFormat;typeof b=="function"&&Tt(()=>b.call(v,f),void 0)},P=new Set(["bold","italic","underline","strikethrough"]),N=f=>{const v=M();if(!v)return;const b=Array.isArray(f.activeMarks)?f.activeMarks:[];let A=null;for(const E of Object.keys(v)){const U=v[E];let Q;if(P.has(E))Q=b.includes(E)===(U===!0);else if(j0(E)){if(U==null)continue;A||(A=pl(f)),Q=A[E]===U}else Q=!1;Q&&X(E)}},I=()=>{const f=S()?.editCommands;return f&&typeof f=="object"?f:null},L=f=>{const v=I();if(!v||typeof v.getSnapshot!="function")return null;const b=Tt(()=>v.getSnapshot(),null)?.commands?.[f];return b&&typeof b=="object"?b:null},Y=()=>L("lists.apply"),te=f=>{const v=f?.value?.seed;return v==="bullet"||v==="ordered"?v:null},le=f=>{const v=hH[f];return v?L(v):null},fe=()=>{const f=T();if(!f||typeof f.getTableContext!="function")return null;const v=Tt(()=>f.getTableContext(),null);return v&&typeof v=="object"?v:null},Ne=()=>{const f=fe();if(!f||f.inTable!==!0)return null;const v=f.table,b=typeof v?.nodeId=="string"&&v.nodeId.length>0?v.nodeId:null;if(!b)return null;const A=f.row,E=f.column,U=f.cell,Q=typeof A?.index=="number"&&Number.isInteger(A.index)?A.index:null,re=typeof E?.index=="number"&&Number.isInteger(E.index)?E.index:null;if(Q==null||re==null)return null;const ye=typeof U?.nodeId=="string"&&U.nodeId.length>0?U.nodeId:null,Re=f.cellRange;return{tableNodeId:b,rowIndex:Q,columnIndex:re,cellNodeId:ye,mergeRange:RH(Re)}},he=new Map;let ge=null,ae=null,_e=0,oe=0;const Te=(f,v)=>f===v?!0:!f||!v?!1:f.id===v.id&&f.paintedEntityId===v.paintedEntityId&&xo(f.story)===xo(v.story),Ge=f=>{const v=T();if(typeof v?.getHandles!="function")return;const b=Tt(()=>v.getHandles(),null),A=b?.review;if(A){if(f){if(typeof A.setActiveReviewTarget!="function")return;const E=b?.layout;Tt(()=>A.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 A.getActiveReviewTarget!="function"||typeof A.clearActiveReviewTarget!="function"||Tt(()=>A.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Tt(()=>A.clearActiveReviewTarget(),void 0)}},Je=(f,v)=>{ae=f,_e+=1,v?.invalidateQueuedNavigation!==!1&&(oe+=1)},_t=new Set;let be=!1,Ve=null;const Le=new Map,J=new Set;let _=null,$=null,F=!1,j=null,V=0,G=null,Z=null,W=null;const K=()=>{if(F||be)return;F=!0;const f=()=>{F=!1,be||jt()};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},ue=250,we=5e3,Ce=f=>{be||j&&V<=f||(j&&clearTimeout(j),V=f,j=setTimeout(()=>{j=null,V=0,be||jt()},Math.max(0,f-Date.now())))},xe=new WeakMap;let ot=0;const tt=f=>{if(!f)return"none";let v=xe.get(f);return v==null&&(v=ot+=1,xe.set(f,v)),`e${v}`};let Ct=0,Kt={},pt=null,Mt=null,zt=0;const ln=()=>{Mt&&clearTimeout(Mt),Mt=null,zt=0};let $n=f=>{},Ht=null,Ke=new Set,kt=0,Ut=null;const Ft=()=>`${tt(S())}|m${Ct}`,Ot=()=>{Ht=null,Ke=new Set},hn=f=>{for(const v of["trackChanges","trackChanges:all"]){const b=Le.get(v);if(!b?.hasSettled||!Array.isArray(b.value))continue;const A=b.value.filter(E=>{const U=Hn(E);return!U||!f.has(U)});A.length!==b.value.length&&Le.set(v,{...b,value:A})}},yn=f=>{const v=()=>{if(!be)for(const U of[..._t])U(bt)},b=gu(f)?f:null,A=S()?.documentMutationReadiness,E=()=>{const U=globalThis.requestAnimationFrame;return typeof U!="function"?Promise.resolve():new Promise(Q=>{let re=!1;const ye=()=>{re||(re=!0,clearTimeout(Re),Q())},Re=setTimeout(ye,250);U(()=>U(()=>setTimeout(ye,0)))})};if(b?.success===!0&&typeof b.txId=="string"&&b.txId.length>0&&typeof A?.whenPainted=="function")try{Promise.resolve(A.whenPainted.call(A,b)).then(E,()=>{}).then(v,v);return}catch{}v()},De=(f,v)=>{const b=bt.trackChanges,A=b.items.filter(Q=>{const re=Hn(Q);return!re||!f.has(re)});if(A.length===b.items.length)return;ae&&f.has(ae.id)&&Je(null);const E=new Set;for(const Q of A){const re=tm(Q),ye=Q,Re=re.author??re.authorEmail??ye.author??ye.authorEmail;typeof Re=="string"&&E.add(Re)}const U=b.items.length-A.length;bt={...bt,trackChanges:{...b,items:A,total:Math.max(A.length,b.total-U),activeId:b.activeId&&f.has(b.activeId)?null:b.activeId,authors:[...E]}},yn(v)},Oe=(f,v)=>{if(f.size===0)return;const b=Ft(),A=Ht===b?Ke:new Set,E=new Set([...f].filter(U=>!A.has(U)));E.size!==0&&(Ht=b,Ke=new Set([...A,...E]),hn(Ke),De(E,v))},Qe=f=>Ht===f&&Ke.size>0?Ke:null,nt=(f,v=[])=>{const b=f.map($l).filter(E=>E!=null&&Hn(E)!=null);if(b.length===0)return;const A=v.map($l).map(E=>E==null?null:Hn(E)).filter(E=>E!=null);for(const E of["trackChanges","trackChanges:all"]){const U=Le.get(E),Q=U?.hasSettled&&Array.isArray(U.value)?[...U.value]:[],re=new Set;let ye=!1;for(const Re of b){const ze=Hn(Re);if(!ze)continue;const Ye=Q.findIndex(Be=>Hn(Be)===ze);if(Ye<0)Q.push(Re),re.add(ze);else{const Be=Q[Ye];Q[Ye]=gu(Be)?{...Be,...Re}:Re}ye=!0}if(E==="trackChanges"&&re.size>0&&A.length>0){const Re=new Set(A.filter(Be=>re.has(Be))),ze=new Map(Q.filter(Be=>Re.has(Hn(Be)??"")).map(Be=>[Hn(Be),Be])),Ye=Q.filter(Be=>!Re.has(Hn(Be)??""));for(const[Be,Ze]of A.entries()){if(!Re.has(Ze))continue;const He=ze.get(Ze);if(!He)continue;const Ue=A.slice(Be+1).map(rt=>Ye.findIndex($e=>Hn($e)===rt)).find(rt=>rt>=0);if(Ue!=null){Ye.splice(Ue,0,He);continue}const je=A.slice(0,Be).reverse().map(rt=>Ye.findIndex($e=>Hn($e)===rt)).find(rt=>rt>=0);Ye.splice(je==null?Ye.length:je+1,0,He)}Q.splice(0,Q.length,...Ye)}ye&&Le.set(E,{token:U?.token??null,value:Q,hasSettled:!0,inflightToken:null})}},Dt=f=>{const v=Ft(),b=Qe(v),A=f.map($l).filter(E=>{if(E==null)return!1;const U=Hn(E);return U!=null&&!b?.has(U)});for(const E of["trackChanges","trackChanges:all"])Le.set(E,{token:v,value:[...A],hasSettled:!0,inflightToken:null})},Et=async(f,v)=>{try{const b=f.v2TrackedChanges?.listTrackedChanges;if(typeof b=="function"){const U=await Promise.resolve(b.call(f.v2TrackedChanges,{mode:v.trackedChangesListMode,refreshReason:v.refreshReason,blocking:v.blocking,...v.targetIds?.length?{targetIds:v.targetIds}:{}})),Q=v.trackedChangesListMode==="all"&&v.refreshReason==="mutation-history-render-reconcile"?U?.ok===!0:U?.ok!==!1;return{ok:Q,items:Q&&Array.isArray(U?.items)?U.items:[],...typeof U?.complete=="boolean"?{complete:U.complete}:{},...typeof U?.sourceCoverageComplete=="boolean"?{sourceCoverageComplete:U.sourceCoverageComplete}:{}}}const A=f.docTrackChanges?.list;if(typeof A!="function")return{ok:!1,items:[]};const E=await Promise.resolve(A.call(f.docTrackChanges));return{ok:!0,items:Array.isArray(E?.items)?E.items:[]}}catch(b){return{ok:!1,items:[],failures:[b]}}},Yt=w_({getContext:()=>{const f=S();if(!f)return null;const v=C(),b=y()?.trackChanges??null,A=v??b;if(!A)return null;const E=f.documentId??v?.documentId;return{editor:f,adapter:A,documentId:E==null?null:String(E),reconcileToken:Kt,v2TrackedChanges:v,docTrackChanges:b}},reconcile:async(f,v)=>{v.removedIds.size>0&&Oe(new Set(v.removedIds));const b=[...new Set(v.upsertIds)];if(b.length===0)return{ok:!0,items:[],resolvedIds:[],unresolvedIds:[]};const A=Le.get("trackChanges"),E=A?.hasSettled&&Array.isArray(A.value)?A.value:null,U=new Set(E?E.map(Hn).filter(je=>je!=null):[]),Q=E?.length===0&&Vn()==="complete",re=new Set(b.filter(je=>!U.has(je))),ye=f.v2TrackedChanges?.getTrackedChange,Re=f.docTrackChanges?.get;if(typeof ye!="function"&&typeof Re!="function")return{ok:!1,items:[],resolvedIds:[],unresolvedIds:b};const ze=await Promise.all(b.map(async je=>{try{if(typeof ye=="function"){const $e=await Promise.resolve(ye.call(f.v2TrackedChanges,je));return{id:je,ok:$e?.ok!==!1,items:$e?.ok!==!1&&Array.isArray($e?.items)?$e.items:[],result:$e}}const rt=await Promise.resolve(Re.call(f.docTrackChanges,{id:je}));return{id:je,ok:!0,items:rt&&typeof rt=="object"?[rt]:[],result:rt}}catch(rt){return{id:je,ok:!1,items:[],result:rt}}})),Ye=[],Be=[],Ze=[];for(const je of ze){const rt=je.items.filter($e=>{const Bt=$l($e);return Bt!=null&&Hn(Bt)===je.id});je.ok&&rt.length>0?(Ye.push(...rt),Be.push(je.id)):Ze.push(je.id)}let He;const Ue=Be.filter(je=>re.has(je));if(Ue.length>0&&!Q){const je=await Et(f,{trackedChangesListMode:"interaction-prime",refreshReason:"mutation-render-reconcile",blocking:!1,targetIds:Ue});je.ok&&(He=je.items)}return{ok:Ze.length===0,items:Ye,orderedItems:He,resolvedIds:Be,unresolvedIds:Ze,failures:ze.filter(je=>!je.ok).map(je=>je.result)}},hydrate:Et,onReconciled:(f,v,b)=>{if(b?.reconcileMode==="authoritative"){if(f.reconcileToken!==Kt)return;b.ok===!0&&b.complete===!0&&b.sourceCoverageComplete===!0?(ln(),Dt(b.items??[]),pt=null):b.ok===!0?(ln(),nt(b.items??[])):$n(f.reconcileToken),jt();return}nt((b?.items??[]).filter(A=>{const E=$l(A),U=E==null?null:Hn(E);return U!=null&&v.has(U)}),b?.orderedItems??b?.items??[]),jt()}});$n=f=>{if(be||Mt)return;const v=Math.min(ue*2**zt,we);zt+=1,Mt=setTimeout(()=>{Mt=null,!(be||pt===null||f!==Kt)&&Yt.onRender(!0)},v)};const xt=()=>`${Ft()}|m${br()}|s${kt}`,Un=f=>JSON.stringify({t:f.target??null,s:f.selectionTarget??null}),so=["contentControls:inRange:","query:","effInline:"],zo=120,rn=180,Vn=()=>{const f=T(),v=f?.getDocumentLoadingSnapshot;if(typeof v!="function")return"unknown";const b=Tt(()=>v.call(f),null)?.sourceStage;return b==="opening"||b==="ready-window"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},lr=new Map,yr=f=>{const v=Ft();lr.get(f)!==v&&(lr.set(f,v),K())},To=()=>{const f=Le.get("comments");return f?.hasSettled?Array.isArray(f.value)&&f.value.length>0:f?.inflightToken!=null},$t=(f,v)=>lr.get(f)===v,cn=f=>{yr("contentControls")},Fr=()=>{const f=Le.get("trackChanges");f?.hasSettled||f?.inflightToken!=null||yr("trackChanges")},go=6500,nl=8e3,sa=250;let rl=0,gs=0,Ho=!1,$o=0,hi=!1,qr=null;const Ee=()=>{if(be||qr)return;const f=$o||Date.now(),v=()=>{if(qr=null,be)return;const b=Date.now()-rl,A=bn()||b<go;if(A&&Date.now()-f<nl){qr=setTimeout(v,sa);return}Ho=!1,hi=A;try{jt()}finally{hi=!1,$o=0}};qr=setTimeout(v,0)};let Fe=null,ft=null;const lt=()=>{const f=T();if(!f||Fe===f)return;ft&&(ft(),ft=null),Fe=f;const v=f.subscribeDocumentLoading;if(typeof v!="function"){Fe=null,cr(go);return}try{const b=U=>{const Q=U?.sourceStage;(Q==="source-complete"||Q==="source-failed"||Q==="source-cancelled")&&Ee()},A=v.call(f,b);typeof A=="function"&&(ft=A);const E=f.getDocumentLoadingSnapshot;typeof E=="function"&&b(Tt(()=>E.call(f),null))}catch{Fe=null,cr(go)}},Cn=()=>{const f=S()?.host,v=f?.getForegroundMutationState;if(typeof v!="function")return null;const b=Tt(()=>v.call(f),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},bn=()=>{const f=Cn();return!!(f&&(f.active>0||f.pending>0))},cr=(f=zo)=>{be||G||(G=setTimeout(()=>{if(G=null,be)return;if(Z&&bn()){cr(),jt();return}const v=Z;Z=null,v===xt()&&Ro("selection",v,cl,Ri),jt()},f))},Uo=(f,v)=>{if(!Cn())return!1;const b=`${f}\0${v}`;return J.has(b)?!1:(J.add(b),cr(rn),!0)},pi=f=>{if(_==null||f===_)return $?.timer&&clearTimeout($.timer),$=null,_=f,!1;if($?.key===f)return $.ready?($=null,_=f,!1):!0;$?.timer&&clearTimeout($.timer);const v={key:f,ready:!1,timer:null};return v.timer=setTimeout(()=>{be||$!==v||(v.timer=null,v.ready=!0,jt())},rn),$=v,!0},Ti=f=>C_(f),ol=()=>{Xr(),jt()};let Vo=null,mi=!1,gi=0;const vo=()=>{Vo=null,mi=!1,gi+=1},Yr=()=>{const f=S(),v=f?.documentMutationReadiness;if(!f||typeof v?.whenPainted!="function"||(Vo={editor:f,readiness:v,afterEpoch:typeof v.getRenderEpoch=="function"?Tt(()=>v.getRenderEpoch.call(v),null):null},mi))return;mi=!0;const b=gi;(async()=>{for(;!be&&b===gi;){const E=Vo;if(Vo=null,!E){mi=!1;return}let U=!1;try{await E.readiness.whenPainted.call(E.readiness,typeof E.afterEpoch=="number"?{afterEpoch:E.afterEpoch}:void 0),U=!0}catch{}if(be||b!==gi)return;if(S()!==E.editor){vo();return}U&&ol()}})()},vi=()=>{W&&clearTimeout(W),W=setTimeout(()=>{W=null,be||ol()},500)},Ro=(f,v,b,A)=>{let E;try{E=b()}catch{E=void 0}if(!Or(E)){const re={token:v,value:A(E),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return Le.set(f,re),re}const U=Le.get(f),Q=U?.failedToken===v;return Le.set(f,{token:U?.token??null,value:U?.value??null,hasSettled:U?.hasSettled??!1,inflightToken:v,failedToken:Q?v:null,failureCount:Q?U.failureCount??0:0,retryAtMs:0}),Promise.resolve(E).then(re=>{const ye=Le.get(f);!ye||ye.inflightToken!==v||(Le.set(f,{token:v,value:A(re),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0}),K())},()=>{const re=Le.get(f);if(!re||re.inflightToken!==v)return;const ye=re.failedToken===v?(re.failureCount??0)+1:1,Re=Math.min(we,ue*2**Math.min(ye-1,8)),ze=Date.now()+Re;Le.set(f,{...re,inflightToken:null,failedToken:v,failureCount:ye,retryAtMs:ze}),Ce(ze)}),null},Yn=(f,v,b,A)=>{const E=Le.get(f);if(E&&E.token===v&&E.hasSettled)return{value:E.value,status:"ready"};if(nH(f)&&!$t(f,v)){if(Vn()==="loading")return Ho=!0,lt(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(Ho&&!hi)return Ee(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!hi){const Q=Date.now();if(Q-gs<go&&(!$o||Q-$o<nl))return $o||($o=Q),Ho=!0,Ee(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};$o=0}}if(bn())return cr(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(E?.failedToken===v&&E.inflightToken==null&&(E.retryAtMs??0)>Date.now())return Ce(E.retryAtMs),E.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!E&&f.startsWith("effInline:")&&pi(f))return{value:null,status:"pending"};if(!E&&Uo(f,v))return{value:null,status:"pending"};if(!E||E.inflightToken!==v){const Q=Ro(f,v,b,A);if(Q)return{value:Q.value,status:"ready"}}const U=Le.get(f);return U?.hasSettled?{value:U.value,status:"stale"}:{value:null,status:"pending"}},il=f=>{for(const v of Le.keys())f(v)&&Le.delete(v)},If=f=>{const v=Un(f),b=rA(f);return new Set([`contentControls:inRange:${v}`,`query:${v}`,...b?[`effInline:${b}`]:[]])},aa=f=>{const v=If(f);il(b=>so.some(A=>b.startsWith(A))&&!v.has(b));for(const b of J){const A=b.split("\0",1)[0];so.some(E=>A.startsWith(E))&&!v.has(A)&&J.delete(b)}},Mo=()=>{const f=S();f!==Ut&&(vo(),Yt.reset(),Kt={},Ut=f,Le.clear(),pt=null,ln(),j&&clearTimeout(j),j=null,V=0,$?.timer&&clearTimeout($.timer),$=null,_=null,w=null,o=null,Z=null,J.clear(),lr.clear(),Ho=!1,$o=0,ft&&ft(),ft=null,Fe=null,Ot())},Xr=()=>{const f=pt!==null;Ct+=1,f&&(pt=Ft()),Ot()},sl=f=>{if(typeof f!="string"||f.length===0)return ar("insertText requires a non-empty string.","INVALID_INPUT");if(br()==="viewing")return ar("The document is read-only.","DOCUMENT_READONLY");const v=y(),b=v?.insert;if(!v||typeof b!="function")return ar("insert is unavailable.");const A=v.selection?.current;if(typeof A!="function")return ar("selection.current is unavailable.");const E=Q=>{const re=Q&&typeof Q=="object"?Q:null,ye=re?.selectionTarget??re?.target??null;return!ye||typeof ye!="object"?ar("insertText requires a live selection target.","PRECONDITION_FAILED"):Tt(()=>ba(b.call(v,{type:"text",value:f,target:ye}),ar("insert failed.")),ar("insert failed."))};let U;try{U=A.call(v.selection)}catch{return ar("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Or(U)?Promise.resolve(U).then(E,()=>ar("insertText could not resolve the live selection.","PRECONDITION_FAILED")):E(U)},Ki=(f,v)=>({payload:f,state:bt,editor:S(),superdoc:t,context:v,ui:Ve,execute:(b,A)=>ri(b,A),executeAsync:(b,A)=>fm(b,A),doc:y(),selection:bt.selection,documentMode:br(),insertText:sl}),al=f=>f==="editing"||f==="suggesting"||f==="viewing"?f:null,br=()=>{const f=S(),v=t&&typeof t=="object"?t:null,b=al(v?.config?.documentMode),A=al(Tt(typeof v?.getActiveRuntime=="function"?()=>{const U=v.getActiveRuntime();return typeof U?.getSnapshot=="function"?U.getSnapshot():null}:void 0,null)?.documentMode),E=al(f?.options?.documentMode);return b&&A&&b!==A?b:A??b??E},yi=()=>{const f=t&&typeof t=="object"?t:null,v=f?.interactionConfig?.comments;if(v&&typeof v.readOnly=="boolean")return v.readOnly===!0;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},yu=()=>{const f=t&&typeof t=="object"?t:null,v=f?.interactionConfig?.comments;if(v&&typeof v.allowResolve=="boolean")return v.allowResolve===!1;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},bi=()=>br()==="viewing"||yi(),Ri=f=>f&&typeof f=="object"?f:null,la=(f,v)=>{if(!f)return{...$z,status:v};const b=f.target??null,A=typeof f.text=="string"?f.text:"";return{status:v,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:A}},ll=()=>{const f=y()?.selection;return Yn("selection",xt(),()=>f?.current?f.current({includeText:!0}):void 0,Ri)},bu=()=>{const{value:f,status:v}=ll();return la(f,v)},cl=()=>{const f=y()?.selection;return f?.current?f.current({includeText:!0}):void 0},wu=f=>{if(f.empty!==!0)return!1;const v=f.selectionTarget,b=v?.start,A=v?.end;return b?.kind==="text"&&A?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===A.blockId&&typeof b.offset=="number"&&b.offset===A.offset},Cu=f=>{const v=T(),b=v?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const A=Ri(Tt(()=>b.call(v),null));if(!A||!wu(A))return;const E=xt(),U=Cn(),Q=!!(U&&(U.active>0||U.pending>0));if(Q)Z=E,cr();else if(Z=null,Ro("selection",E,cl,Ri))return;const re=Le.get("selection"),ye=Array.isArray(A.activeMarks)&&A.activeMarks.length>0?A.activeMarks:Array.isArray(bt.selection.activeMarks)?bt.selection.activeMarks:[],Re=Array.isArray(A.activeCommentIds)?A.activeCommentIds:[],ze=sH(f),Ye=$a(bt.selection),Be=kf(A.selectionTarget)??kf(A.target),Ze=Ye?.range,He=Be?.range,Ue=!!(U&&U.active>0&&Ye&&Be&&Ye.blockId===Be.blockId&&xo(Ye.story)===xo(Be.story)&&typeof Ze?.start=="number"&&typeof He?.start=="number"&&Math.abs(He.start-Ze.start)<=2),je=ze!=null||Ue?bt.selection.activeChangeIds.filter($e=>ze==null||em(bt.trackChanges.items).aliasesFor($e).includes(ze)):[],rt=Array.isArray(A.activeChangeIds)&&A.activeChangeIds.length>0?A.activeChangeIds:je;Le.set("selection",{token:E,value:{...A,activeMarks:ye,activeCommentIds:Re,activeChangeIds:rt},hasSettled:!0,inflightToken:Q?null:re?.inflightToken??null})},ca=async(f=0)=>{const v=y()?.selection,b=v?.current,A=xt();if(typeof b!="function")return Le.set("selection",{token:A,value:null,hasSettled:!0,inflightToken:null}),jt(),bt.selection;let E;try{E=b.call(v,{includeText:!0}),Or(E)&&(E=await Promise.resolve(E))}catch{E=null}return be?la(null,"pending"):xt()!==A?f<1?ca(f+1):bt.selection:(Le.set("selection",{token:A,value:Ri(E),hasSettled:!0,inflightToken:null}),jt(),bt.selection)},_u=f=>{const v=y()?.comments,{value:b,status:A}=Yn("comments",Ft(),()=>v?.list?v.list():void 0,re=>re&&Array.isArray(re.items)?re.items:[]),E=b??[],U=f.activeCommentIds;ge&&!E.some(re=>Hn(re)===ge)&&(ge=null);const Q=ge??U[0]??null;return{status:hu(A,f.status),listStatus:A,items:E,total:E.length,activeIds:U,activeId:Q}},Lo=()=>{const f=y()?.trackChanges,v=Ft(),b=Le.get("trackChanges:all"),{value:A,status:E}=pt===v?{value:b?.hasSettled?b.value:null,status:b?.hasSettled?"stale":"pending"}:Yn("trackChanges:all",v,()=>f?.list?f.list({in:"all"}):void 0,U=>(U&&Array.isArray(U.items)?U.items:[]).map($l).filter(Q=>Q!=null));return E==="ready"?A:null},ul=f=>{const v=y()?.trackChanges,b=C(),A=typeof b?.listTrackedChanges=="function"?b.listTrackedChanges:null,E=Ft(),U=Qe(E),Q=Le.get("trackChanges"),{value:re,status:ye}=pt===E?{value:Q?.hasSettled?Q.value:null,status:Q?.hasSettled?"stale":"pending"}:Yn("trackChanges",E,()=>A?A.call(b):v?.list?v.list():void 0,Ue=>Ue&&Array.isArray(Ue.items)?Ue.items.filter(je=>!A||xo(Jp(je))==="story:body"):[]),Re=(re??[]).map($l).filter(Ue=>Ue!=null).filter(Ue=>{const je=Hn(Ue);return!je||!U?.has(je)}),ze=new Set;for(const Ue of Re){const je=tm(Ue),rt=Ue,$e=je.author??je.authorEmail??rt.author??rt.authorEmail;typeof $e=="string"&&ze.add($e)}const Ye=v?.list?Lo():null,Be=ae;Be&&(Be.story?Ye&&!Ye.some(Ue=>Ja(Ue,Be.id,Be.story))&&Je(null):Re.some(Ue=>Hn(Ue)===Be.id)||Je(null));const Ze=U?f.activeChangeIds.filter(Ue=>!U.has(Ue)):f.activeChangeIds,He=ae?.id??Ze[0]??null;return{status:hu(ye,f.status),items:Re,total:Re.length,activeId:He,authors:[...ze]}},Ef=f=>{const v=y()?.contentControls,{value:b,status:A}=Yn("contentControls",Ft(),()=>v?.list?v.list():void 0,re=>re&&Array.isArray(re.items)?re.items:[]),E=b??[],{ids:U,status:Q}=dl(v,f);return{status:hu(A,Q,f.status),items:E,total:E.length,activeId:U[0]??null,activeIds:U}},vs=(f,v)=>{if(!f||typeof f.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=cH(v);if(!b)return{lockModesById:new Map,status:"ready"};const{value:A,status:E}=Yn(`contentControls:inRange:${Un(v)}`,Ft(),()=>f.listInRange(b),re=>re&&Array.isArray(re.items)?re.items:[]),U=A??[],Q=new Map;for(const re of U)typeof re?.id=="string"&&Q.set(re.id,typeof re.lockMode=="string"?re.lockMode:"unlocked");return{lockModesById:Q,status:E}},dl=(f,v)=>{const{lockModesById:b,status:A}=vs(f,v);return{ids:[...b.keys()],status:A}},Do=()=>{const f=t?.fonts;return{options:BH(OH(Tt(f?.getDocumentFontOptions?()=>f.getDocumentFontOptions():void 0,[])),FH(Tt(f?.getFontFamilyOptions?()=>f.getFontFamilyOptions():void 0,[]))),sizeOptions:NH}},qi=()=>{const f=Tt(t?.getZoomState?()=>t.getZoomState():void 0,null),v=typeof f?.value=="number"?f.value:100,b=f?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:v,min:typeof f?.min=="number"?f.min:10,max:typeof f?.max=="number"?f.max:100}},Su=()=>Tt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",ku=()=>{const f=S();return{ready:f!=null,mode:br(),dirty:f?!!f.isDirty:!1}},jo=f=>{const v=f.quotedText;if(typeof v!="string"||v.length===0)return null;const b=mu(f);if(b.length===0||!Jl(b.map(U=>U.blockId)))return null;const A=f.target,E=b.length===1?mo(b[0].blockId,A?.story):void 0;return{select:{type:"text",pattern:v,mode:"contains",caseSensitive:!0},...E?{within:E}:{},require:"any"}},ys=f=>{const v=y()?.query;if(typeof v?.match!="function")return null;const b=jo(f);if(!b)return null;const{value:A}=Yn(`query:${Un(f)}`,Ft(),()=>v.match(b),E=>E&&typeof E=="object"?E:null);return oA(A,f)},fl=f=>{const v=T(),b=new Set(Rr(f));if(b.size===0)return{};const A=v?.readMountedProjectionBlocksByIds,E=v?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof E!="function")return{};const U=Tt(()=>{if(typeof A!="function")return E.call(v);const Ue=oa(f);return Ue?A.call(v,[...b],Ue):A.call(v,[...b])},null);if(!Array.isArray(U))return{};const Q=K0(U),re=Ue=>{const je={},rt=G0(Ue.fontFamily);rt&&(je.fontFamily=rt);const $e=wH(Ue.fontSize);return $e&&(je.fontSize=$e),typeof Ue.color=="string"&&Ue.color.trim()!==""&&(je.color=Ue.color.trim().toUpperCase()),typeof Ue.highlight=="string"&&Ue.highlight.trim()!==""&&(je.highlight=Ue.highlight.trim().toUpperCase()),je},ye=$a(f),Re=ye&&typeof ye.range?.start=="number"?ye.range.start:null;if(ye&&Re!==null&&b.has(ye.blockId)){const Ue=Q.find(rt=>ec(rt,ye.blockId)),je=Ue&&Array.isArray(Ue.runs)?Ue.runs:null;if(je&&je.length>0&&je.every(rt=>rt?.kind==="text"||rt?.kind==="tab")){let rt=0,$e=null;for(const Bt of je){const Xt=typeof Bt.text=="string"?Bt.text.length:0;if(Re>=rt&&Re<rt+Xt){$e=Bt;break}rt+=Xt}if(!$e){for(let Bt=je.length-1;Bt>=0&&!$e;Bt-=1)je[Bt]?.kind==="text"&&($e=je[Bt]);$e??=je[je.length-1]??null}return $e?re($e):{}}}const ze=mu(f);if(ze.length>0){const Ue=new Set,je=new Set;let rt=!1,$e=!0;for(const Bt of ze){const Xt=Q.find(Jr=>ec(Jr,Bt.blockId));if(!Xt)return{};const Nn=Array.isArray(Xt.runs)?Xt.runs:[];if(Nn.length===0)continue;if(!Nn.every(Jr=>Jr?.kind==="text"||Jr?.kind==="tab")){$e=!1;break}let Gn=0;for(const Jr of Nn){const Vr=typeof Jr.text=="string"?Jr.text.length:0,Lr=Gn,Ar=Gn+Vr;if(Lr<Bt.end&&Ar>Bt.start){rt=!0;const Wo=re(Jr);Wo.fontFamily&&Ue.add(Wo.fontFamily),Wo.fontSize&&je.add(Wo.fontSize)}Gn=Ar}}if($e&&rt){const Bt={};return Ue.size===1&&(Bt.fontFamily=[...Ue][0]),je.size===1&&(Bt.fontSize=[...je][0]),Bt}}const Ye=new Set,Be=new Set;let Ze=!1;for(const Ue of Q){if(![...b].some(rt=>ec(Ue,rt)))continue;const je=Array.isArray(Ue.runs)?Ue.runs:[];for(const rt of je){if(rt?.kind!=="text")continue;Ze=!0;const $e=re(rt);$e.fontFamily&&Ye.add($e.fontFamily),$e.fontSize&&Be.add($e.fontSize)}}if(!Ze)return{};const He={};return Ye.size===1&&(He.fontFamily=[...Ye][0]),Be.size===1&&(He.fontSize=[...Be][0]),He},tc=f=>{const v=T(),b=new Set(Rr(f));if(b.size===0)return{};const A=v?.readMountedProjectionBlocksByIds,E=v?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof E!="function")return{};const U=Tt(()=>{if(typeof A!="function")return E.call(v);const He=oa(f);return He?A.call(v,[...b],He):A.call(v,[...b])},null);if(!Array.isArray(U))return{};const Q=K0(U),re=He=>({bold:He.bold===!0,italic:He.italic===!0,underline:He.underline!=null,strikethrough:He.strike===!0}),ye=He=>{const Ue={};for(const je of Af){const rt=He[je];rt.size===1&&(Ue[je]=[...rt][0])}return Ue},Re=$a(f),ze=Re&&typeof Re.range?.start=="number"?Re.range.start:null;if(Re&&ze!==null&&b.has(Re.blockId)){const He=Q.find(je=>ec(je,Re.blockId)),Ue=He&&Array.isArray(He.runs)?He.runs:null;if(Ue&&Ue.length>0&&Ue.every(je=>je?.kind==="text"||je?.kind==="tab")){let je=0,rt=null;for(const $e of Ue){const Bt=typeof $e.text=="string"?$e.text.length:0;if(ze>=je&&ze<je+Bt){rt=$e;break}je+=Bt}if(!rt){for(let $e=Ue.length-1;$e>=0&&!rt;$e-=1)Ue[$e]?.kind==="text"&&(rt=Ue[$e]);rt??=Ue[Ue.length-1]??null}return rt?re(rt):{}}}const Ye=mu(f);if(Ye.length>0){const He={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ue=!1,je=!0;for(const rt of Ye){const $e=Q.find(Nn=>ec(Nn,rt.blockId));if(!$e)return{};const Bt=Array.isArray($e.runs)?$e.runs:[];if(Bt.length===0)continue;if(!Bt.every(Nn=>Nn?.kind==="text"||Nn?.kind==="tab")){je=!1;break}let Xt=0;for(const Nn of Bt){const Gn=typeof Nn.text=="string"?Nn.text.length:0,Jr=Xt,Vr=Xt+Gn;if(Jr<rt.end&&Vr>rt.start){Ue=!0;const Lr=re(Nn);for(const Ar of Af)He[Ar].add(Lr[Ar])}Xt=Vr}}if(je&&Ue)return ye(He)}const Be={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ze=!1;for(const He of Q){if(![...b].some(je=>ec(He,je)))continue;const Ue=Array.isArray(He.runs)?He.runs:[];for(const je of Ue){if(je?.kind!=="text")continue;Ze=!0;const rt=re(je);for(const $e of Af)Be[$e].add(rt[$e])}}return Ze?ye(Be):{}},ua=(f,v)=>{if(v.fontFamily!==void 0&&v.fontSize!==void 0&&v.color!==void 0&&v.highlight!==void 0)return{values:v,effectiveUniformityStatus:"ready"};const b=fl(f),A={...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}:{},...v};if(!f.empty&&(A.fontFamily===void 0||A.fontSize===void 0)){const E=Au(f);return E.values&&(A.fontFamily===void 0&&E.values.fontFamily!==void 0&&(A.fontFamily=E.values.fontFamily),A.fontSize===void 0&&E.values.fontSize!==void 0&&(A.fontSize=E.values.fontSize)),{values:A,effectiveUniformityStatus:E.status}}return{values:A,effectiveUniformityStatus:"ready"}},Yi=["fontFamily","fontSize","bold","italic","underline","strikethrough"],hl=f=>{const v=f.selectionTarget;if(!v)return{value:null,status:"ready"};const b=gr(y(),"format.readEffectiveInlineUniformity");return b?Yn(`effInline:${rA(f)??Un(f)}`,Ft(),()=>b({target:v,offsetSpace:"selection",keys:Yi}),A=>A&&typeof A=="object"?A:null):{value:null,status:"ready"}},Au=f=>{const{value:v,status:b}=hl(f);if(!v||v.success!==!0)return{values:null,status:b};const A=v.values,E=U=>{const Q=A?.[U];if(!(!Q||Q.state!=="uniform"||typeof Q.value!="string"))return U==="fontFamily"?G0(Q.value):Q.value};return{values:{fontFamily:E("fontFamily"),fontSize:E("fontSize")},status:b}},nc=f=>{const{value:v,status:b}=hl(f);if(!v||v.success!==!0)return{values:null,status:b};const A=v.values,E={};for(const U of Af){const Q=A?.[U];Q?.state==="uniform"&&(Q.value==="true"||Q.value==="false")&&(E[U]=Q.value==="true")}return{values:E,status:b}},xf=(f,v)=>{const b=f.activeMark;if(!b||!Af.includes(b))return null;const A=b,E=tc(v)[A];if(E!==void 0)return E;const{values:U}=nc(v),Q=U?.[A];return Q!==void 0?Q:null},Tf=async f=>{const v=f.selectionTarget;if(!v)return null;const b=gr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const A=await Promise.resolve(b({target:v,offsetSpace:"selection"}));return A&&typeof A=="object"&&A.success===!0?A:null}catch{return null}},rc=(f,v,b)=>{const A=b.values;for(const E of["fontFamily","fontSize"]){if(v[E]!==void 0)continue;const U=A?.[E];U?.state==="uniform"&&typeof U.value=="string"?f[E]=E==="fontFamily"?G0(U.value):U.value:delete f[E]}},bs=f=>ua(f,iA(ys(f),f)),pl=f=>bs(f).values,Iu=async f=>{const v=y()?.query,b=jo(f);if(typeof v?.match!="function"||!b)return pl(f);try{const A=await Promise.resolve(v.match(b)),E=iA(oA(A&&typeof A=="object"?A:null,f),f),U=ua(f,E);if(U.effectiveUniformityStatus!=="ready"&&(E.fontFamily===void 0||E.fontSize===void 0)){const Q=await Tf(f);Q&&rc(U.values,E,Q)}return U.values}catch{return pl(f)}},da=async f=>{const v=y();if(v)return typeof v.getNode=="function"?await Promise.resolve(v.getNode(f)):await Promise.resolve(v.getNodeById?.({nodeId:f.nodeId,nodeType:f.nodeType}))},ml=f=>{const v=y()?.query;if(typeof v?.match!="function")return"ready";const b=jo(f);if(!b)return"ready";const{status:A}=Yn(`query:${Un(f)}`,Ft(),()=>v.match(b),E=>E&&typeof E=="object"?E:null);return A},Eu=f=>{const v=bs(f),b=v.values;if(f.empty)return v;const A=ia(f);return A?f.status==="ready"&&ml(f)==="ready"&&v.effectiveUniformityStatus==="ready"?(w={key:A,values:b},v):w&&w.key===A?{...v,values:{...w.values,...b}}:v:v},oc=f=>{const v=y(),b=Eu(f),A=b.values;f.status==="ready"&&!f.empty&&ml(f)==="ready"&&b.effectiveUniformityStatus==="ready"&&(g=A,k=`${Ql(f)}:${Ft()}`);const E=v?.contentControls,{lockModesById:U}=vs(E,f),Q={};for(const re of it())Q[re]=Ru(re,v,f,A,U);return Q},Mi=f=>f?at.operationUnavailable:S()?at.documentApiUnavailable:at.notReady,xu=f=>f==="contentLocked"||f==="sdtContentLocked",Xi=f=>{for(const v of f.values())if(xu(v))return at.contentControlLocked},Rf=(f,v,b,A,E)=>{if(!v)return f.scope==="all"?at.bulkDecisionsDisabled:Mi(E);if(b)return at.documentReadonly;if(f.scope!=="all"&&A.activeChangeIds.length===0)return at.selectionRequired},Tu=f=>{const v=T(),b=Tt(typeof v?.getCapabilities=="function"?()=>v.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(A=>A?.command===f||A?.id===f)??null;if(b&&typeof b=="object"){const A=b[f];return A&&typeof A=="object"?A:null}return null},ic=(f,v)=>{if(f.scope!=="all"||typeof v?.[`${f.kind}All`]=="function")return;const b=Tu(`trackedChanges.${f.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return at.bulkDecisionsDisabled},Ru=(f,v,b,A,E=new Map)=>{if(he.has(f))return tn({supported:!0,enabled:!0,...Tt(he.get(f).getState?()=>he.get(f).getState(Ki(void 0)):void 0,{})},"custom");const U=br()==="viewing",Q=Yk(f);if(Q&&typeof I()?.lists?.apply=="function"){const Ze=Y(),He=typeof Ze?.shippedStatus=="string"?Ze.shippedStatus:null,Ue=He!=="not-shipped"&&He!=="disabled";return tn({enabled:Ue&&(typeof Ze?.enabled=="boolean"?Ze.enabled:!0),active:(Ue?te(Ze):null)===Q,supported:Ue,value:Ze?.value},"builtin")}const re=rm(f);if(re){const Ze=v?.trackChanges,He=typeof Ze?.decide=="function"||typeof Ze?.[re.kind]=="function",Ue=typeof Ze?.decide=="function"||typeof Ze?.[`${re.kind}All`]=="function",je=re.scope==="all"?Ue:He,rt=ic(re,Ze)??Rf(re,je,bi(),b,v);return tn({enabled:rt==null,active:!1,supported:je,reason:rt},"builtin")}if(f==="copy-format")return br()==="viewing"?tn({supported:!0,enabled:!1,active:!1},"builtin"):S()?tn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):tn({supported:!0,enabled:!1,active:!1,reason:at.notReady},"builtin");const ye=uu(f);if(!ye)return tn({enabled:!1,active:!1,supported:!1,reason:at.commandUnsupported},"unsupported");if(ye.disposition!=="routed")return tn({enabled:!1,active:!1,supported:!1,reason:ye.reason??at.commandUnsupported},ye.disposition==="unsupported"?"unsupported":"builtin");if(ye.instanceRoute)return Xe(ye);if(ye.table)return st(ye,v,U);if(ye.inline?.kind==="clear"){if(ye.mutates&&U)return tn({enabled:!1,active:!1,supported:!0,reason:at.documentReadonly},"builtin");const Ze=Xi(E);if(Ze)return tn({enabled:!1,active:!1,supported:!0,reason:Ze},"builtin");const He=Rr(b).length>0||vu(b)!=null;return tn({enabled:He,active:!1,supported:!0,reason:He?void 0:at.selectionRequired},"builtin")}const Re=ye.docRoute;if(!Re)return tn({enabled:!1,active:!1,supported:!1,reason:at.commandUnsupported},"unsupported");if(gr(v,Re)==null)return tn({enabled:!1,active:!1,supported:!1,reason:Mi(v)},"builtin");const ze=le(f);if(ze){const Ze=ze.shippedStatus,He=Ze!=="not-shipped"&&Ze!=="disabled",Ue=typeof ze.enabled=="boolean"?ze.enabled:!0,je=f==="undo"||f==="redo",rt=je&&ze.historyResolved===!1,$e=je&&He&&Ue===!1&&ze.reason===null&&!rt,Bt=ze.reason===void 0?void 0:$e?at.historyEmpty:rt?at.notReady:z0(ze.reason,at.commandUnsupported);return ye.mutates&&U?tn({enabled:!1,active:!1,supported:He,reason:at.documentReadonly},"builtin"):tn({enabled:He&&Ue,active:!1,supported:He,reason:Bt},"builtin")}const Ye=ha(ye,v,b),Be=Lu(ye,v,b,A);if(ye.list?.mode==="indent"||ye.list?.mode==="outdent")return pe(ye,v,U,b,Ye,Be);if(ye.list?.mode==="toggle-seed")return ve(ye,v,U,b,Ye,Be);if(ye.mutates&&U)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:at.documentReadonly},"builtin");if(ye.inline&&!vu(b)){const Ze=Xi(E);return tn(Ze?{enabled:!1,active:Ye,supported:!0,value:Be,reason:Ze}:Rr(b).length>0&&typeof T()?.setPendingInlineFormat=="function"?{enabled:!0,active:Ye,supported:!0,value:Be}:{enabled:!1,active:Ye,supported:!0,value:Be,reason:at.rangeSelectionRequired},"builtin")}if((ye.blockParagraph||ye.list)&&Rr(b).length===0)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:at.selectionRequired},"builtin");if(ye.link&&!Ye&&V0(b).length===0&&!$a(b))return tn({enabled:!1,active:Ye,supported:!0,reason:at.rangeSelectionRequired},"builtin");if(ye.inline){const Ze=Xi(E);if(Ze)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:Ze},"builtin")}return tn({enabled:!0,active:Ye,supported:!0,value:Be},"builtin")};function Mu(f,v){const b=f.address?.anchor,A=b?.start,E=b?.end,U=typeof A?.blockId=="string"?A.blockId:null,Q=typeof E?.blockId=="string"?E.blockId:null;if(!U||!Q)return!1;const re=typeof A?.offset=="number"?A.offset:null,ye=typeof E?.offset=="number"?E.offset:null;if(re==null||ye==null)return!1;const Re=v.target,ze=Re&&Array.isArray(Re.segments)?Re.segments:[];for(const Ye of ze){const Be=typeof Ye?.blockId=="string"?Ye.blockId:null;if(!Be)continue;const Ze=Ye.range,He=typeof Ze?.start=="number"?Ze.start:null,Ue=typeof Ze?.end=="number"?Ze.end:null;if(!(He==null||Ue==null)){if(U!==Q){if(Be===U&&Ue>re||Be===Q&&He<ye)return!0;continue}if(Be===U){if(He===Ue){if(He>=re&&He<=ye)return!0;continue}if(Math.max(He,re)<Math.min(Ue,ye))return!0}}}return!1}const fa=(f,v)=>{const b=f?.hyperlinks;if(!b||typeof b.list!="function")return null;const A=Rr(v);if(!Jl(A))return null;for(const E of A){const U={kind:"block",nodeType:"paragraph",nodeId:E},{value:Q}=Yn(`hyperlinks:${E}`,Ft(),()=>b.list({within:U}),ye=>ye&&typeof ye=="object"?ye:null),re=(Q&&Array.isArray(Q.items)?Q.items:[]).find(ye=>Mu(ye,v));if(re)return re}return null},ha=(f,v,b)=>{if(f.link)return fa(v,b)!=null;if(f.list?.mode==="toggle-seed"&&f.list.seed)return ei(v,b)===f.list.seed;const A=H(f);if(A!==null)return A;const E=r.get(f.id),U=ia(b);if(U&&E?.selectionSignature===U)return E.active;const Q=xf(f,b);return Q!==null?Q:zH(f,b)},Lu=(f,v,b,A)=>{if(f.inline&&j0(f.inline.key)){const E=B(f);if(E!==void 0)return E;const U=A[f.inline.key];if(U!==void 0)return U;const Q=ia(b),re=Q?n.get(f.inline.key):void 0;if(Q&&re?.selectionSignature===Q)return re.value}if(f.id==="linked-style"){const{style:E}=yo(b,Fn().cache);return!E.styleId||E.mixed?void 0:{styleId:E.styleId,styleName:E.styleName}}if(f.id==="text-align")return x(v,b);if(f.id==="link")return qe(v,b)??void 0},gl=(f,v,b)=>{const A=f?.lists;if(!A)return{value:null,status:"ready"};const E=b.storyType==="body",U=typeof A.getStateInStory=="function"?()=>A.getStateInStory({target:ra(v),story:b}):E&&typeof A.getState=="function"?()=>A.getState({target:ra(v)}):null;if(!U)return{value:null,status:"ready"};const{value:Q,status:re}=Yn(`lists:${xo(b)}:${v}`,Ft(),U,ye=>ye&&typeof ye=="object"?ye:null);return{value:Q?.success===!0?Q:null,status:re}},Mf=(f,v,b)=>gl(f,v,b).value,sc=(f,v,b)=>{const A=Mf(f,v,b);return!A||A.isListItem!==!0?null:A.seed==="bullet"||A.seed==="ordered"?A.seed:null},ac=(f,v,b)=>{const A=gl(f,v,b),E=A.value;return{value:E&&typeof E.isListItem=="boolean"?E.isListItem:null,status:A.status}},ei=(f,v)=>{const b=Rr(v);if(b.length===0||!Jl(b))return null;const A=na(v),E=sc(f,b[0],A);if(E!=="bullet"&&E!=="ordered")return null;for(const U of b.slice(1))if(sc(f,U,A)!==E)return null;return E},Qi=(f,v,b)=>{if(!f)return{value:null,status:"ready",refreshing:!1};const A=xo(b),E=A==="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 U=`node:${A}:${v}`,Q=Ft(),re=Yn(U,Q,()=>E?f.getNodeById({nodeId:v,nodeType:"paragraph"}):f.getNode(mo(v,b)),Re=>Re&&typeof Re=="object"?Re:null),ye=Le.get(U);return{...re,refreshing:re.status==="stale"&&ye?.inflightToken===Q&&ye.failedToken!==Q}},Br=f=>f==="left"||f==="center"||f==="right"||f==="justify"?f:void 0,Lf=f=>f==="start"||f==="end"||f==="distributed"||f==="numTab"||f==="lowKashida"||f==="mediumKashida"||f==="highKashida"||f==="thaiDistribute",Df=(f,v)=>{const b=T(),A=b?.readMountedProjectionBlocksByIds;if(typeof A!="function")return null;const E=oa(f),U=Tt(()=>E?A.call(b,[...v],E):A.call(b,[...v]),null);if(!Array.isArray(U))return new Map;const Q=K0(U),re=new Map;for(const ye of v){const Re=Q.find(Ze=>ec(Ze,ye));if(!Re)continue;const ze=Re.attrs,Ye=Br(ze?.alignment),Be=o9(ze);re.set(ye,Ye??(Be==="rtl"?"right":"left"))}return re},pa=(f,v,b,A)=>{const{value:E,status:U,refreshing:Q}=Qi(f,v,b),re=A?.get(v);if(U==="pending")return re?{status:"uniform",value:re}:{status:"pending"};if(U==="stale"&&!Q)return{status:"pending"};if(U==="stale"&&re)return{status:"uniform",value:re};if(U==="stale"&&A&&!re)return{status:"unavailable"};if(!E)return{status:"unavailable"};const ye=E.node;if(!ye)return{status:"unavailable"};const Re=ye.kind;if(Re!=="paragraph"&&Re!=="heading")return{status:"unavailable"};const ze=ye[Re];if(!ze||typeof ze!="object")return{status:"unavailable"};const Ye=ze.props?.alignment;if(Ye==null)return re?{status:"uniform",value:re}:{status:"unavailable"};const Be=Br(Ye);return Be?{status:"uniform",value:Be}:Lf(Ye)&&re?{status:"uniform",value:re}:{status:"unavailable"}},lc=(f,v)=>{const b=Rr(v);if(b.length===0||!Jl(b))return{status:"unavailable"};const A=na(v),E=Df(v,b),U=pa(f,b[0],A,E);if(U.status!=="uniform")return U;for(const Q of b.slice(1)){const re=pa(f,Q,A,E);if(re.status!=="uniform")return re;if(re.value!==U.value)return{status:"mixed"}}return U},Du=f=>{const v=Rr(f);return v.length===0?null:`${xo(na(f))}:${v.join(",")}`},x=(f,v)=>{const b=lc(f,v),A=b.status==="uniform"?b.value:void 0,E=o;if(!E)return A;const U=Du(v);return U&&U!==E.selectionSignature?(o=null,A):!U||!E.settled?E.value:b.status!=="pending"?(o=null,A):E.value},D=(f,v)=>{const b=Br(v),A=Du(f),E=Rr(f);if(!b||!A||E.length===0)return null;const U=++i;return o={selectionSignature:A,value:b,generation:U,settled:!1,canReconcile:Jl(E)},jt(),U},ee=(f,v)=>{if(f==null)return;const b=o;if(!(!b||b.generation!==f)){if(!No(v)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},ie=async(f,v,b)=>{const A=f?.lists;if(!A)return null;try{const E=b.storyType==="body",U=typeof A.getStateInStory=="function"?await A.getStateInStory({target:ra(v),story:b}):E&&typeof A.getState=="function"?await A.getState({target:ra(v)}):null,Q=U&&typeof U=="object"?U:null;return!Q||Q.success!==!0||typeof Q.isListItem!="boolean"?null:Q.isListItem}catch{return null}},se=(f,v,b)=>{const A={resolved:!1,seed:null},E=f?.lists;if(!E)return A;const U=b.storyType==="body",Q=typeof E.getStateInStory=="function"?()=>E.getStateInStory({target:ra(v),story:b}):U&&typeof E.getState=="function"?()=>E.getState({target:ra(v)}):null;if(!Q)return A;const re=ye=>{const Re=ye&&typeof ye=="object"?ye:null;return!Re||Re.success!==!0||typeof Re.isListItem!="boolean"?A:{resolved:!0,seed:Re.isListItem===!0&&(Re.seed==="bullet"||Re.seed==="ordered")?Re.seed:null}};try{const ye=Q();return Or(ye)?Promise.resolve(ye).then(re,()=>A):re(ye)}catch{return A}},de=async(f,v,b)=>{if(!f)return null;try{const A=!b||b.storyType==="body",E=b&&typeof f.getNode=="function"?await f.getNode(mo(v,b)):A&&typeof f.getNodeById=="function"?await f.getNodeById({nodeId:v,nodeType:"paragraph"}):null;return dH(E&&typeof E=="object"?E:null)}catch{return null}},pe=(f,v,b,A,E,U)=>{if(f.mutates&&b)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.documentReadonly},"builtin");const Q=Rr(A);if(Q.length===0)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.selectionRequired},"builtin");const re=f.docRoute?gr(v,f.docRoute):null,ye=gr(v,"format.paragraph.setIndentation"),Re=gr(v,"format.paragraph.clearIndentation"),ze=f.list?.mode,Ye=ze==="indent"?ye!=null:ye!=null||Re!=null,Be=na(A);let Ze=null;if(Be.storyType!=="body"){Ze=[];for(const He of Q){const{value:Ue,status:je}=ac(v,He,Be);if(Ue===null)return je!=="ready"&&(re!=null||Ye)?tn({enabled:!0,active:E,supported:!0,value:U},"builtin"):tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin");Ze.push(Ue)}}if(Ze?.some(He=>He===!0)){const He=ze==="indent"?"lists.indentRange":"lists.outdentRange",Ue=br()!=="suggesting"&&Ze.every(rt=>rt===!0)&&gr(v,He)!=null,je=ze==="outdent"&&gr(v,"lists.outdentInStory")!=null;if(!Ue&&!je)return tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")}for(const[He,Ue]of Q.entries()){const je=Ze?{value:Ze[He]??null,status:"ready"}:ac(v,Ue,Be),rt=je.value;if(rt===!0){if(re!=null)return tn({enabled:!0,active:E,supported:!0,value:U},"builtin");continue}if(rt===!1&&Ye){if(Be.storyType!=="body"&&typeof v?.getNode!="function")continue;return tn({enabled:!0,active:E,supported:!0,value:U},"builtin")}if(rt===null)return je.status!=="ready"&&(re!=null||Ye)?tn({enabled:!0,active:E,supported:!0,value:U},"builtin"):tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")}return tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")},ve=(f,v,b,A,E,U)=>{if(f.mutates&&b)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.documentReadonly},"builtin");const Q=Rr(A);if(Q.length===0)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.selectionRequired},"builtin");const re=na(A),ye=v?.lists;if(!(typeof ye?.getStateInStory=="function"||re.storyType==="body"&&typeof ye?.getState=="function"))return tn({enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");if(!Jl(Q))return tn(re.storyType==="body"&&gr(v,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const Re=Q.map(Ze=>gl(v,Ze,re));if(Re.some(({status:Ze})=>Ze!=="ready"))return tn({enabled:!0,active:E,supported:!0,value:U},"builtin");if(Re.some(({value:Ze})=>Ze===null))return tn({enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const ze=f.list?.seed,Ye=Re.every(({value:Ze})=>Ze?.isListItem===!0&&Ze.seed===ze);if(re.storyType==="body")return tn(!Ye||gr(v,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const Be=gr(v,"lists.removeInStory");return tn(Ye&&Be?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin")},qe=(f,v)=>{const b=fa(f,v)?.properties?.href;return typeof b=="string"?b:null},Xe=f=>{if(!S())return tn({enabled:!1,active:!1,supported:!1,reason:at.notReady},"builtin");const v=f.instanceRoute;return typeof t?.[v]!="function"?tn({enabled:!1,active:!1,supported:!1,reason:at.operationUnavailable},"builtin"):tn({enabled:!0,active:et(f),supported:!0,value:yt(f)},"builtin")},et=f=>{const v=t?.config??void 0;return f.valueFrom==="ruler"?!!v?.rulers:f.valueFrom==="formattingMarks"?!!v?.layoutEngineOptions?.showFormattingMarks:!1},st=(f,v,b)=>{if(b)return tn({enabled:!1,active:!1,supported:!0,reason:at.documentReadonly},"builtin");const A=Ne();return A!=null&&(!f.table.requiresCell||A.cellNodeId!=null)?(f.docRoute?gr(v,f.docRoute):null)==null?tn({enabled:!1,active:!1,supported:!1,reason:Mi(v)},"builtin"):tn({enabled:!0,active:!1,supported:!0},"builtin"):tn({enabled:!1,active:!1,supported:!0,reason:at.tableContextUnavailable},"builtin")},yt=f=>{if(f.valueFrom==="zoom")return qi().value;if(f.valueFrom==="documentMode")return br();if(f.valueFrom==="measurementUnit")return Su();if(f.valueFrom==="ruler"||f.valueFrom==="formattingMarks")return et(f)},gt=(f,v)=>f.id==="zoom"?typeof v=="number"&&Number.isFinite(v)&&v>0:f.id==="document-mode"?v==="editing"||v==="suggesting"||v==="viewing":f.id==="measurement-unit"?v==="in"||v==="cm":!0,it=()=>[...new Set([...$F,...he.keys()])],on="Normal",nn={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},Dn=f=>{const v=y()?.styles;return!v||typeof v.getCatalog!="function"?{value:null,status:"ready"}:Yn(`styles:catalog:${JSON.stringify(f??{})}`,Ft(),()=>v.getCatalog(f),b=>b&&typeof b=="object"?b:null)},Fn=()=>{const f=Dn({includePreview:!0});if(!f.value)return{cache:null,status:f.status};const v=Dn({view:"quickGallery",includePreview:!0}),b=v.value?v.value.items:f.value.styles.filter(E=>E.visibility.quickGallery),A=new Map;for(const E of f.value.styles)A.set(E.id,E);return{cache:{full:f.value,quickGallery:b,byId:A},status:hu(f.status,v.status)}},jn=(f,v,b)=>{const{value:A,status:E}=Qi(f,v,b);if(!A)return{ok:!1,styleRef:null,status:E};const U=A.node;if(!U||typeof U!="object")return{ok:!1,styleRef:null,status:E};const Q=U.kind,re=typeof Q=="string"?U[Q]:void 0,ye=re&&typeof re=="object"?re.styleRef:void 0;return{ok:!0,styleRef:typeof ye=="string"&&ye.length>0?ye:null,status:E}},yo=(f,v)=>{const b=[],A=y();if(!A)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=Rr(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(!Jl(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 U=v?.full.defaults.paragraphStyleId??(v?on:null),Q=new Set;let re=0,ye=0,Re=0,ze="ready";const Ye=na(f);for(const He of E){const Ue=jn(A,He,Ye);if(ze=hu(ze,Ue.status),!Ue.ok){ye+=1;continue}if(!Ue.styleRef&&!U){Re+=1;continue}const je=Ue.styleRef??U;if(!je){Re+=1;continue}re+=1,Q.add(je)}if(re===0){const He=Re>0&&ye===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:ze}}const Be=ye+Re;if(Be>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${re} of ${re+Be} selected blocks; ${Be} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:ze};if(Q.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:ze};const Ze=[...Q][0];return{style:{styleId:Ze,styleName:v?.byId.get(Ze)?.name??null,mixed:!1,diagnostics:b},status:ze}},er=f=>{if(!S())return nn;const{cache:v,status:b}=Fn(),{style:A,status:E}=yo(f,v);let U;return v?U=A.diagnostics.length===0?v.full.diagnostics:[...v.full.diagnostics,...A.diagnostics]:U=[{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)."},...A.diagnostics],{ready:!0,status:hu(b,E,f.status),catalogRevision:v?.full.revision??null,quickGallery:v?.quickGallery??[],activeParagraphStyleId:A.styleId,activeParagraphStyleName:A.styleName,mixedSelection:A.mixed,sourceStatus:v?.full.sourceStatus??null,diagnostics:U}},En=()=>{const f=br(),v=bu();v.status==="ready"&&aa(v),N(v);const b=ia(v);for(const[A,E]of r)(!b||E.selectionSignature!==b||E.settled&&v.status==="ready")&&r.delete(A);return{ready:S()!=null,documentMode:f,document:ku(),selection:v,toolbar:{context:f,commands:oc(v),copyFormatActive:h.mode!=="idle"},comments:_u(v),trackChanges:ul(v),contentControls:Ef(v),zoom:qi(),fonts:Do(),styles:er(v)}},ur=f=>{const v=ia(f);v&&a&&v!==a&&(n.clear(),r.clear()),v&&(a=v)};let mt=null,Lt=null,Pn=null,Nr=null,wr=!1;const vl=()=>{if(be||wr)return;wr=!0;const f=()=>{wr&&(wr=!1,!be&&jt())};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},yl=()=>{const f=I();if(f!==Pn&&(Nr&&(Nr(),Nr=null),Pn=f,!(!f||typeof f.subscribe!="function")))try{const v=f.subscribe(()=>vl());typeof v=="function"&&(Nr=v)}catch{Pn=null}};let zr=null,ti=null,Li=null,wi=null,ma=null,Mr=null;const ws=()=>{const f=S()?.host,v=Tt(f?.getHandles?()=>f.getHandles():void 0,null)?.editing?.selection;return v&&typeof v.subscribe=="function"?v:null},Di=()=>{const f=ws();if(f!==mt&&(Lt&&(Lt(),Lt=null),mt=f,!!f))try{const v=f.subscribe(b=>{kt+=1,Cu(b),jt()});typeof v=="function"&&(Lt=v)}catch{mt=null}},Cs=()=>{const f=S()?.host,v=Tt(f?.getHandles?()=>f.getHandles():void 0,null)?.review;return v&&typeof v.subscribe=="function"?v:null},Pi=f=>f?typeof f.getActiveReviewTarget=="function"?Tt(()=>f.getActiveReviewTarget(),null):typeof f.getSnapshot=="function"?Tt(()=>f.getSnapshot(),null)?.activeReviewTarget??null:null:null;let ao=0;const Po=(f,v)=>{const b=(v&&typeof v=="object"?v:null)?.lastInteractionRejection;if(ao>0&&f==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const A=f&&typeof f=="object"?f:null;let E=null;if(A?.entityType==="trackedChange"&&typeof A.entityId=="string"&&A.entityId.length>0){const U=A.story&&xo(A.story)!==xo(null)?A.story:void 0;E={id:A.entityId,...U?{story:U}:{},...typeof A.paintedEntityId=="string"&&A.paintedEntityId.length>0?{paintedEntityId:A.paintedEntityId}:{}}}return Te(ae,E)?!1:(Je(E),!0)},cc=()=>{const f=Cs();if(f===zr)return;if(ti&&(ti(),ti=null),zr=f,!f){Po(null);return}let v=!0;try{const b=f.subscribe(A=>{const E=A&&typeof A=="object"?A:null;!Po(E&&Object.prototype.hasOwnProperty.call(E,"activeReviewTarget")?E.activeReviewTarget:Pi(f),A)||v||jt()});typeof b=="function"&&(ti=b),Po(Pi(f))}catch{zr=null}finally{v=!1}},ga=()=>{if(mt||br()!=="viewing")return null;const f=S()?.mount?.container,v=(f&&typeof f=="object"&&"ownerDocument"in f?f.ownerDocument??null:null)??globalThis.document??null;return v&&typeof v.addEventListener=="function"?v:null},uc=()=>{const f=ga();if(f===ma||(Mr&&(Mr(),Mr=null),ma=f,!f))return;const v=()=>{kt+=1,jt()};f.addEventListener("selectionchange",v),f.addEventListener("pointerup",v,!0),f.addEventListener("mouseup",v,!0),Mr=()=>{f.removeEventListener("selectionchange",v),f.removeEventListener("pointerup",v,!0),f.removeEventListener("mouseup",v,!0)}};Mo(),Po(Pi(Cs()));let bt=En();a=ia(bt.selection);const va=()=>{const f=S()?.host?.events,v=f&&typeof f.subscribe=="function"?f:null;if(v!==Li&&(wi&&(wi(),wi=null),Li=v,!!v))try{const b=v.subscribe(A=>{const E=A?.type;if(E==="source:complete"||E==="source:signals-complete"){pt!==null&&(ln(),Yt.onRender(!0));return}if((E==="mutation:committed"||E==="collaboration:remote-changed")&&(rl=Date.now()),E==="mutation:committed"&&(ln(),Kt={}),E==="mutation:committed"||E==="save:completed"||E==="collaboration:remote-changed"){const U=E==="mutation:committed"?b_(A):null,Q=E==="mutation:committed"&&Yt.getPendingIds().size>0;U?.removedIds.size&&Oe(new Set(U.removedIds),A.receipt);const re=U?.reconcileMode==="authoritative"&&U.upsertIds.size>0;if(re&&(Xr(),ln(),pt=Ft(),jt()),U?.upsertIds.size||Q){const Ye=A.origin==="history"?null:A.receipt,Be=S()?.documentMutationReadiness,Ze=typeof Ye?.txId=="string"&&Ye.txId.length>0&&typeof Be?.whenPainted=="function",He=A.origin==="history"&&typeof Be?.getRenderEpoch=="function"?Tt(()=>Be.getRenderEpoch.call(Be),null):null,Ue=A.origin==="history"&&typeof Be?.whenPainted=="function",je={upsertIds:U?.upsertIds??new Set,removedIds:new Set,reconcileMode:U?.reconcileMode==="authoritative"?"authoritative":"targeted"};Ze?Yt.enqueueAfterPaint(je,()=>Be.whenPainted.call(Be,Ye)):Ue?Yt.enqueueAfterPaint(je,()=>Be.whenPainted.call(Be,typeof He=="number"?{afterEpoch:He}:void 0)):(Yt.enqueue(je),Yt.onRender(Q))}if(re)return;const ye=E==="mutation:committed"&&Ti(A)||E==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0;if(ye&&(gs=Date.now()),E==="mutation:committed"&&ye){vi();return}if(U?.removedIds.size&&U.upsertIds.size===0)return;(E==="collaboration:remote-changed"||E==="mutation:committed"&&!ye)&&Yr();const Re=E==="collaboration:remote-changed"&&Array.isArray(A.changedPartUris)&&A.changedPartUris.some(Ye=>typeof Ye=="string"&&tH.has(Ye)),ze=E==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0&&To();Re&&!ye&&(Ho=!0),Xr(),(Re||ze)&&yr("comments"),jt()}});typeof b=="function"&&(wi=b)}catch{Li=null}},jt=()=>{if(be)return;wr=!1,Mo(),Di(),yl(),cc(),uc(),va();const f=En();ur(f.selection),bt=f;for(const v of[..._t])v(bt)},_s=[],Pu=[],Ou=f=>{for(const v of f)try{v()}catch{}},Fu=()=>Ou(_s),Zt=()=>Ou(Pu),Mn=[];((f,v)=>{if(!(!f||typeof f.on!="function"))for(const b of v){const A=b==="active-editor-change"?()=>{Fu(),Zt(),jt()}:b==="document-replaced"?E=>{const U=E&&typeof E=="object"?E:null,Q=U?.editor,re=U?.host,ye=!!Q&&Q===S(),Re=!!re&&re===T();!ye&&!Re||(Zt(),Le.clear(),Xr(),jt())}:()=>jt();try{f.on(b,A),Mn.push(()=>{try{typeof f.off=="function"&&f.off(b,A)}catch{}})}catch{}}})(t,Xz),Di(),yl(),cc(),uc(),va();const Go=(f,v=Oz)=>({get:()=>f(bt),subscribe:b=>{let A=f(bt);const E=U=>{const Q=f(U);v(A,Q)||(A=Q,b(Q))};return _t.add(E),()=>_t.delete(E)}}),lo=f=>Go(f),Qr=f=>{const v=b=>{const A=U=>{try{b(U)}catch{}},E=f.subscribe(A);return A(f.get()),E};return{get:()=>f.get(),getSnapshot:()=>f.get(),observe:v,subscribe:b=>v(A=>b({snapshot:A}))}};function bl(f){return f&&typeof f=="object"&&typeof f.id=="string"?String(f.id):null}function wl(f){if(f.empty)return null;const v=f.selectionTarget,b=v?.start,A=v?.end;if(v?.kind!=="selection"||b?.kind!=="text"||A?.kind!=="text"||typeof b.blockId!="string"||b.blockId!==A.blockId||!Number.isInteger(b.offset)||!Number.isInteger(A.offset)||b.offset<0||A.offset<0||b.offset===A.offset)return null;const E=Math.min(b.offset,A.offset),U=Math.max(b.offset,A.offset),Q=oa(f);return{kind:"range",coordinateSpace:v.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...Q?{story:Q}:{},segments:[{blockId:b.blockId,range:{start:E,end:U}}]}}}function Z0(){const f=bt.selection.activeChangeIds[0];if(!f)return"unavailable";const v=Lo();if(!v)return"unavailable";const b=oa(bt.selection),A=v.find(Q=>Ja(Q,f,b));if(!A)return"unavailable";const E=tm(A).type,U=tm(A).grouping;return(E==="insertion"||E==="deletion"||E==="insert"||E==="delete")&&U==="standalone"?"range":"id"}function J0(f,v){if(f.scope==="all")return{target:{scope:"all"},changeId:null};if(typeof v=="string"&&v.length>0)return{target:{kind:"id",id:v},changeId:v};if(v&&typeof v=="object"){const A=v;if(A.target&&typeof A.target=="object")return{target:A.target,changeId:bl(A.target)};const E=typeof A.changeId=="string"?A.changeId:A.id;if(typeof E=="string"&&E.length>0)return{target:{kind:"id",id:E},changeId:E}}const b=bt.selection.activeChangeIds[0];return b?{target:{kind:"id",id:b},changeId:b}:null}function O(f,v){if(f.scope==="id"&&v==null){if(bt.selection.activeChangeIds.length>1)return Nu(f.kind,{kind:"ids",ids:bt.selection.activeChangeIds},null);if(bt.selection.activeChangeIds.length===1&&!bt.selection.empty&&bt.selection.selectionTarget){const A=Z0();if(A==="unavailable")return!1;if(A==="range"){const E=wl(bt.selection);return E?Nu(f.kind,E,null):!1}}}const b=J0(f,v);return b?Nu(f.kind,b.target,b.changeId):!1}function q(f,v){const b=I()?.lists,A=b?.apply;if(typeof A!="function")return!1;const{behavior:E,preset:U,continuity:Q}=typeof v=="string"?Jz(v):v&&typeof v=="object"?v:{},re={kind:f,behavior:E??"toggle"};U!==void 0&&(re.preset=U),Q!==void 0&&(re.continuity=Q);try{return co(A.call(b,re))}catch{return!1}}let Se=Promise.resolve(!1),Pe=null,ht=Promise.resolve(!1);const sn=async f=>{if(!nm(f))return f;const v=S()?.documentMutationReadiness,b=v?.whenPainted;if(typeof b!="function")return f;const A=typeof f.txId=="string"?f.txId:void 0;try{await b.call(v,A?{txId:A}:void 0)}catch{}return f},un=f=>{if(Or(f)){const b=Promise.resolve(f);return{immediate:!0,committed:b.then(A=>el(A),()=>!1),settled:b.then(A=>sn(el(A)),()=>!1)}}const v=el(f);return{immediate:v,committed:Promise.resolve(v),settled:sn(v)}},dr=()=>{const f=s.shift();if(!f){u=!1,d?.(),d=null;return}try{f.resolve(be?!1:f.mutate())}catch{f.resolve(!1)}},Bn=()=>{let f=!1;return()=>{f||(f=!0,dr())}},fr=(f,v)=>{if(!u){u=!0,c=new Promise(U=>{d=U});try{return{result:v(),release:Bn()}}catch(U){throw u=!1,d?.(),d=null,U}}const b=s.find(U=>U.key===f);if(b)return b.mutate=v,{result:b.result,release:()=>{}};let A;const E=new Promise(U=>{A=U});return s.push({key:f,mutate:v,result:E,resolve:A}),{result:E,release:Bn()}},kn=new Set(["create.tableOfContents"]),bo=f=>ar(`Tracked authoring is not supported for ${f}.`),Hr=f=>{if(br()==="suggesting")return kn.has(f)?bo(f):{changeMode:"tracked"}},ya=()=>br()==="suggesting"?xH:Y0,hr=(f,v,b)=>{const A=Hr(f);return A&&A.success===!1?A:A?v(b,A):v(b)},ni=(f,v,b,A)=>{const E=f.inline;if(!E)return;const U=el(A);if(U===!1||typeof U=="object"&&U&&U.success===!1)return;if(E.kind==="clear"){n.clear();return}if(E.kind==="toggle"||!j0(E.key))return;const Q=ia(v);if(!Q)return;const re=mH(E.key,b.value);if(re==null){n.delete(E.key);return}n.set(E.key,{selectionSignature:Q,value:re})},Cl=(f,v,b,A)=>!f.inline||f.inline.kind==="toggle"?A:Or(A)?Promise.resolve(A).then(E=>(ni(f,v,b,E),E)):A,_l=(f,v,b,A)=>{if(f.inline?.kind!=="toggle"||!No(el(A))||typeof b.value!="boolean"&&b.value!==null)return null;const E=ia(v);if(!E)return null;const U=++l;return r.set(f.id,{selectionSignature:E,active:b.value===!0,generation:U,settled:!1}),jt(),U},$0=(f,v,b)=>{if(v==null)return;const A=r.get(f.id);if(!(!A||A.generation!==v)){if(!No(b)){r.delete(f.id);return}A.settled=!0}},dc=(f,v)=>f.then(b=>(v?.(b),Xr(),jt(),b),()=>(v?.(!1),Xr(),jt(),!1)),co=(f,v)=>{const b=Pe;if(Pe=null,b)return Se=dc(b,v),el(f);if(Or(f))return Se=dc(un(f).settled,v),!0;const A=el(f);return nm(A)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(Se=dc(sn(A),v),A):(v?.(A),Se=Promise.resolve(A),Xr(),jt(),A)},eb=(f,v)=>!f||typeof f!="object"?v:f,ba=(f,v=ar("Document API operation failed."))=>{if(Or(f))return Promise.resolve(f).then(A=>ba(A,v),()=>v);const b=eb(f,v);return Xr(),nm(b)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(dc(sn(b)),jt(),b):(jt(),b)},Pf=(f,v,b,A)=>{const E=[],U=[];for(const Q of b){const re=A(Q);if(re)try{const ye=un(hr(f,v,re));E.push(ye.immediate),U.push(ye.settled)}catch{E.push(!1),U.push(Promise.resolve(!1))}}return Pe=U.length?Promise.all(U).then(Q=>fi(Q)):null,fi(E)},Xn=(f,v,b,A)=>{const E=[],U=[];for(const Q of b){const re=A(Q);if(re)try{const ye=un(hr(f,v,re));E.push(ye.immediate),U.push(ye.settled)}catch{E.push(!1),U.push(Promise.resolve(!1))}}return Pe=U.length?Promise.all(U).then(Q=>fi(Q)):null,fi(E)},Of=(f,v,b,A=bt.selection)=>{const E=Hr(f);return E&&E.success===!1?E:A.selectionTarget?v(b,{...E??{},offsetSpace:"selection"}):E?v(b,E):v(b)},sm=(f,v,b,A)=>{const E=mo(v,A);switch(f.kind){case"alignment":{const U=b;return U!=="left"&&U!=="center"&&U!=="right"&&U!=="justify"?null:{target:E,alignment:U}}case"spacing-line":{const U=typeof b=="number"?b:Number(b);return!Number.isFinite(U)||U<=0?null:{target:E,line:U,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const U=b.role;if(U&&typeof U=="object")return{target:E,role:U}}return typeof b!="string"||b.trim()===""?null:{target:E,styleId:b};case"direction":{const U=f.fixedValue;return U!=="ltr"&&U!=="rtl"?null:{target:E,direction:U}}default:return null}},am=(f,v)=>{const b=f.inline,A=q0(f),E=T();if(!b||typeof E?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return X(),!0;if(!A)return!1;let U;if(b.kind==="toggle")U=!ha(f,y(),bt.selection);else{const Q=v&&typeof v=="object"&&"value"in v?v.value:v;if(b.kind==="value-number"){const re=typeof Q=="number"?Q:Number(Q);U=Number.isFinite(re)&&re>0?re:null}else U=typeof Q=="string"&&Q.trim()!==""?Q:null;if(U===null)return z(A,null),!0}return z(A,U),!0},tb=()=>{const f=y(),{lockModesById:v}=vs(f?.contentControls,bt.selection);if(Xi(v))return!1;const b=[],A=[],E=Ze=>{const He=un(Ze);b.push(He.immediate),A.push(He.settled)},U=(Ze,He,Ue)=>{try{E(Ue?Ze(He,Ue):Ze(He))}catch{b.push(!1),A.push(Promise.resolve(!1))}},Q=Fn().cache?.full.defaults.paragraphStyleId??on,re=vu(bt.selection);if(re){const Ze=gr(f,"format.apply");if(Ze)try{E(Of("format.apply",Ze,{target:re,inline:{...ya()}}))}catch{b.push(!1),A.push(Promise.resolve(!1))}}const ye=gr(f,"format.paragraph.resetDirectFormatting"),Re=gr(f,"styles.paragraph.setStyleRef"),ze=oa(bt.selection),Ye=!ze||ze.storyType==="body",Be=gr(f,Ye?"lists.remove":"lists.removeInStory");for(const Ze of Rr(bt.selection)){const He=mo(Ze,ze);if(ye&&U(ye,{target:He}),Be)try{const Ue=ra(Ze),je=un(Be(Ye?{target:Ue}:{target:Ue,story:ze}));A.push(je.settled.then(rt=>No(rt)?rt:!0))}catch{}Re&&U(Re,{target:He,styleId:Q})}if(!re&&br()!=="suggesting"){const Ze=gr(f,"format.paragraph.setMarkRunProps");if(Ze)for(const He of Rr(bt.selection))U(Ze,{target:mo(He,ze),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return Pe=A.length?Promise.all(A).then(Ze=>fi(Ze)):null,fi(b.length?b:[!1])},lm=(f,v,b)=>{const A=Rr(bt.selection);if(A.length===0)return!1;const E=oa(bt.selection);return Pf(f.docRoute,v,A,U=>sm(f.blockParagraph,U,b,E))},cm=(f,v,b)=>{const A=y(),E=gr(A,"format.paragraph.setIndentation"),U=gr(A,"format.paragraph.clearIndentation"),Q=f.list?.mode,re=na(bt.selection),ye=oa(bt.selection),Re=async ze=>{const Ye=await ie(A,ze,re);if(Ye===!0)return{kind:"list",routeToCall:f.docRoute,opToCall:v,input:{target:eA(ze)}};if(Ye===null||ye&&ye.storyType!=="body"&&typeof A?.getNode!="function")return null;const Be=await de(A,ze,ye),Ze={};if(Be?.right!=null&&(Ze.right=Be.right),Be?.firstLine!=null&&(Ze.firstLine=Be.firstLine),Be?.hanging!=null&&(Ze.hanging=Be.hanging),Q==="indent")return E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),left:Math.max(0,Be?.left??0)+tA,...Ze}}:null;const He=Math.max(0,(Be?.left??0)-tA);return He>0&&(Ze.left=He),Object.keys(Ze).length===0?U?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:U,input:{target:mo(ze,ye)}}:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),left:0}}:null:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),...Ze}}:null};return Pe=(async()=>{const ze=await Promise.all(b.map(He=>Re(He).catch(()=>null)));if(ze.length===b.length&&ze.every(He=>He?.kind==="list")&&br()!=="suggesting"){const He=Q==="indent"?"lists.indentRange":"lists.outdentRange",Ue=gr(A,He);if(Ue)try{return await un(hr(He,Ue,{paraIds:b,story:re})).settled}catch{return!1}}const Ye=re.storyType!=="body"&&ze.some(He=>He?.kind==="list"),Be=Ye&&Q==="outdent"?gr(A,"lists.outdentInStory"):null;if(Ye&&!Be)return!1;const Ze=ze.map(He=>{if(!He)return Promise.resolve(!1);try{return He.kind==="list"&&Be?un(hr("lists.outdentInStory",Be,{target:He.input.target,story:re})).settled:un(hr(He.routeToCall,He.opToCall,He.input)).settled}catch{return Promise.resolve(!1)}});return fi(await Promise.all(Ze))})(),!0},um=(f,v)=>{const b=f.list,A=y(),E=Rr(bt.selection);if(E.length===0)return!1;const U=na(bt.selection),Q=U.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return cm(f,v,E);const re=b.seed,ye=Ye=>{if(Ye.some(rt=>!rt.resolved))return{immediate:!1,settled:null};const Be=Ye.every(rt=>rt.seed===re);if(!Be&&!Q)return{immediate:!1,settled:null};const Ze=Be?Q?"lists.remove":"lists.removeInStory":f.docRoute,He=Be?gr(A,Ze):v;if(!He)return{immediate:!1,settled:null};const Ue=[],je=[];return E.forEach((rt,$e)=>{if(!Be&&Ye[$e]?.seed===re)return;const Bt=Be?{target:ra(rt),...Q?{}:{story:U}}:{target:ra(rt),seed:re};try{const Xt=un(hr(Ze,He,Bt));Ue.push(Xt.immediate),je.push(Xt.settled)}catch{Ue.push(!1),je.push(Promise.resolve(!1))}}),{immediate:fi(Ue),settled:je.length?Promise.all(je).then(rt=>fi(rt)):null}},Re=E.map(Ye=>se(A,Ye,U));if(Re.some(Or))return Pe=Promise.all(Re).then(async Ye=>{const Be=ye(Ye);return Be.settled?await Be.settled:Be.immediate}),!0;const ze=ye(Re);return Pe=ze.settled,ze.immediate};function fc(f){return f&&typeof f=="object"?f:{}}function dm(f){if(typeof f=="string")return f;const v=fc(f);if(Object.prototype.hasOwnProperty.call(v,"href"))return v.href;if(Object.prototype.hasOwnProperty.call(v,"value"))return v.value}function hc(f,v){const b=fc(f).text;return typeof b=="string"&&b.trim()!==""?b:v}function pc(f){const v=fc(f),b=v.capture&&typeof v.capture=="object"?v.capture:null;return v.target??b?.target??b?.selectionTarget??v.selectionTarget??v.textTarget??null}const Ff=f=>{const v=y(),b=v?.hyperlinks;if(!b)return!1;const A=fc(f),E=dm(f),U=pc(f),Q=typeof A.text=="string"?A.text:void 0,re=typeof A.currentText=="string"?A.currentText:void 0,ye=gu(A.hyperlinkTarget)?A.hyperlinkTarget:null,Re=gu(A.textTarget)?A.textTarget:null,ze=fa(v,bt.selection),Ye=typeof ye?.storyId=="string"&&typeof ye?.hyperlinkNodeId=="string";if(Ye&&E===null){const Be=b.remove;if(typeof Be!="function")return!1;try{return hr("hyperlinks.remove",Be,{storyId:ye.storyId,hyperlinkNodeId:ye.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(ze&&E===null){const Be=b.remove;if(typeof Be!="function")return!1;try{return hr("hyperlinks.remove",Be,{target:ze.address,mode:"unwrap"})}catch{return!1}}if((ze||ye)&&typeof E=="string"&&E.trim()!==""){const Be=b.patch,Ze=b.updateTarget;if(!(!Ye&&ze&&typeof Be=="function")&&!(Ye&&typeof Ze=="function"))return!1;const He=typeof Q=="string"&&Q!==(Ye?re:ze?.text??re),Ue=v?.text?.replace,je=He?Ye?Re:_H(ze?.address):null,rt=He&&!!je&&typeof Ue=="function";if(He&&!rt)return!1;const $e=[],Bt=[];let Xt=null,Nn=null,Gn=null,Jr=!1;try{if(Ye){if(typeof Ze!="function")return!1;const Vr=hr("hyperlinks.updateTarget",Ze,{storyId:ye.storyId,hyperlinkNodeId:ye.hyperlinkNodeId,newTarget:SH(E)});Jr=Or(Vr);const Lr=un(Vr);if(!No(Lr.immediate))return!1;$e.push(Lr.immediate),Bt.push(Lr.settled),Xt=Lr.immediate,Nn=Lr.committed,Gn=Lr.settled}else if(ze){if(typeof Be!="function")return!1;const Vr=hr("hyperlinks.patch",Be,{target:ze.address,patch:{href:E}});Jr=Or(Vr);const Lr=un(Vr);if(!No(Lr.immediate))return!1;$e.push(Lr.immediate),Bt.push(Lr.settled),Xt=Lr.immediate,Nn=Lr.committed,Gn=Lr.settled}}catch{return!1}if(rt){const Vr=(Ar,Wo)=>No(Wo)?fi([Ar,Wo]):No(Ar)?Sf(Ar,Wo):Wo,Lr=Ar=>{if(!No(Ar))return Ar;try{const Wo=un(hr("text.replace",Ue,{target:je,text:Q}));return No(Wo.immediate)?Promise.all([Gn??Promise.resolve(Ar),Wo.settled]).then(([cb,OU])=>Vr(cb,OU)):Sf(Ar,Wo.immediate)}catch{return Sf(Ar,!1)}};if(Jr)return Pe=(Nn??Promise.resolve(Xt??!1)).then(Lr),fi($e);try{const Ar=un(hr("text.replace",Ue,{target:je,text:Q}));if(!No(Ar.immediate))return Xt?Sf(Xt,Ar.immediate):Ar.immediate;$e.push(Ar.immediate),Bt.push(Ar.settled),Pe=Promise.all([Gn??Promise.resolve(Xt??!1),Ar.settled]).then(([Wo,cb])=>Vr(Wo,cb))}catch{return Xt?Sf(Xt,!1):!1}}return!rt&&Bt.length>0&&(Pe=Promise.all(Bt).then(Vr=>fi(Vr))),fi($e)}if(typeof E=="string"&&E.trim()!==""){const Be=E.trim(),Ze=b.wrap,He=fH(U),Ue=He.length>0?He:V0(bt.selection);if(Ue.length>0){if(typeof Ze!="function")return!1;try{return Xn("hyperlinks.wrap",Ze,Ue,Bt=>({target:Bt,link:{destination:{href:Be}}}))}catch{return!1}}const je=b.insert,rt=hc(f,Be);if(typeof je!="function"||rt.trim()==="")return!1;const $e=kf(U)??$a(bt.selection);if(!$e)return!1;try{return hr("hyperlinks.insert",je,{target:$e,text:rt,link:{destination:{href:Be}}})}catch{return!1}}return!1},At=(f,v,b)=>{const A=f.create.kind,E=b&&typeof b=="object"?b:{};if(A==="table"){const Q=Number(E.rows??E.rowCount),re=Number(E.columns??E.cols??E.colCount);if(!Number.isInteger(Q)||Q<1||!Number.isInteger(re)||re<1)return!1;const ye=$a(bt.selection),Re=ye&&typeof ye.blockId=="string"?{kind:"inParagraph",target:mo(ye.blockId),offset:ye.range?.start??0}:W0(bt.selection,"nodeId");try{return hr(f.docRoute,v,{rows:Q,columns:re,at:Re})}catch{return!1}}if(A==="image"){const Q=E.src??E.value;if(typeof Q!="string"||Q.trim()==="")return!1;const re=$a(bt.selection),ye=na(bt.selection),Re=ye.storyType==="body"?null:ye;let ze;re&&typeof re.blockId=="string"?ze={kind:"inParagraph",target:mo(re.blockId,Re),offset:re.range?.start??0}:(ze=W0(bt.selection,"target"),Re&&ze.kind==="after"&&(ze={...ze,target:{...ze.target,story:Re}}));const Ye={src:Q,at:ze};Re&&(Ye.in=ze.kind==="inParagraph"?R(Re)??Re:Re),typeof E.alt=="string"&&(Ye.alt=E.alt),typeof E.title=="string"&&(Ye.title=E.title),E.size&&typeof E.size=="object"&&(Ye.size=E.size);try{return hr(f.docRoute,v,Ye)}catch{return!1}}const U={at:W0(bt.selection,"target")};typeof E.instruction=="string"&&(U.instruction=E.instruction),E.config&&typeof E.config=="object"&&(U.config=E.config);try{return hr(f.docRoute,v,U)}catch{return!1}},Gt=(f,v)=>{const b=f.table,A=Ne();if(!A||b.requiresCell&&!A.cellNodeId)return!1;const E=MH(b.action,A);if(!E)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const U=T(),Q=(typeof U?.getHandles=="function"?U.getHandles():null)?.editing?.tables;if(typeof Q?.insertRow!="function")return!1;const re=Hr(f.docRoute);return re&&re.success===!1?re:re?Q.insertRow(E,re):Q.insertRow(E)}return hr(f.docRoute,v,E)}catch{return!1}},vn=f=>!f||f.disposition!=="routed"?!1:!!(f.inline||f.blockParagraph||f.list||f.link||f.create),Cr=f=>{const v=fc(f);return!!(pc(f)||gu(v.hyperlinkTarget)||gu(v.textTarget))},Ur=(f,v,b)=>bt.selection.status!=="ready"?!1:rm(f)?.scope==="id"||!v||v.disposition!=="routed"?!0:v.inline?.kind==="clear"?Rr(bt.selection).length>0||vu(bt.selection)!=null:v.inline?vu(bt.selection)!=null||Rr(bt.selection).length>0:v.blockParagraph||v.list?Rr(bt.selection).length>0:v.link?Cr(b)||V0(bt.selection).length>0||$a(bt.selection)!=null||ha(v,y(),bt.selection):!0,uo=(f,v)=>{const b=rm(f),A=uu(f);return b?.scope!=="id"&&!vn(A)?!1:!Ur(f,A,v)},Ci=(f,v)=>uo(f,v)?ca().then(()=>{}):null,ri=(f,v,b)=>{if(Pe=null,Se=Promise.resolve(!1),be)return!1;const A=he.get(f);if(A)try{return co(A.execute(Ki(v,b)))}catch{return!1}const E=Yk(f);if(E&&typeof I()?.lists?.apply=="function")return q(E,v);const U=rm(f);if(U)return O(U,v);if(f==="copy-format")return co(sU());const Q=uu(f);if(!Q||Q.disposition!=="routed")return!1;const re=Q.normalizePayload?Q.normalizePayload(v):v;if(Q.instanceRoute){if(!S()||!gt(Q,re))return!1;const Ye=t?.[Q.instanceRoute];if(typeof Ye!="function")return!1;try{const Be=Q.fixedArg!==void 0?Q.fixedArg:re;return co(Ye.call(t,Be))}catch{return!1}}if(Q.inline?.kind==="clear")return Q.mutates&&br()==="viewing"?!1:co(tb());const ye=Q.docRoute;if(!ye||Q.mutates&&br()==="viewing")return!1;const Re=y(),ze=gr(Re,ye);if(!ze)return!1;if(Q.inline){const{lockModesById:Ye}=vs(Re?.contentControls,bt.selection);if(Xi(Ye))return!1;const Be=vu(bt.selection);if(!Be)return bt.selection.empty===!1?co(!1):co(am(Q,re));const Ze=ha(Q,Re,bt.selection),He=TH(Q.inline,Be,re,Ze);if(!He)return!1;let Ue=null;try{const je=S(),rt=br(),$e=()=>S()!==je||y()!==Re||br()!==rt?!1:Of(ye,ze,He),Bt=ia(bt.selection)??Ql(bt.selection),Xt=Q.inline.kind==="toggle"?fr(`${Q.id}:${Bt}`,$e):null;Ue=Xt?.release??null;const Nn=Xt?Xt.result:$e(),Gn=_l(Q,bt.selection,He,Nn),Jr=co(Cl(Q,bt.selection,He,Nn),Vr=>{$0(Q,Gn,Vr),Ue?.(),Ue=null});return Q.inline.kind==="toggle"&&(ht=Se),Jr}catch{return Ue?.(),!1}}if(Q.blockParagraph){const Ye=lm(Q,ze,re),Be=Q.blockParagraph.kind==="alignment"&&No(Ye)?D(bt.selection,re):null;return co(Ye,Ze=>{ee(Be,Ze)})}if(Q.list)return co(um(Q,ze));if(Q.link)return co(Ff(re));if(Q.create)return co(At(Q,ze,re));if(Q.table)return co(Gt(Q,ze));try{return co(Q.mutates?hr(ye,ze,re):ze(re))}catch{return!1}},wa=()=>{m+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const f of p)f("idle");jt()},sU=async()=>{const f=["bold","italic","underline","strikethrough"].filter(ze=>bt.toolbar.commands[ze]?.active===!0),v=await ht;await c;const b=No(v)?f:[],A=500,E=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&E-h.lastClickAt<A){h={...h,mode:"persistent",lastClickAt:E};for(const ze of p)ze("persistent");return jt(),!0}return wa(),!1}const U=E-h.lastClickAt<A,Q=++m;h={...h,lastClickAt:E};const re=await ca(),ye=`${Ql(re)}:${Ft()}`,Re=await aU(null,re,ye&&ye===k?g:void 0,b);if(Q!==m)return!0;h={...h,mode:U?"persistent":"armed",snapshot:Re,sourceSelectionKey:Ql(re),lastClickAt:E};for(const ze of p)ze(h.mode);return jt(),!0},aU=async(f,v,b,A=[])=>{const E=v?.target??f?.target;if(!E||E.kind!=="text")return null;const U=Array.isArray(E.segments)?E.segments:[];if(U.length===0)return null;const Q=y();if(!Q)return null;const re=E.story;let ye=null;for(const He of U){const Ue=(await da(mo(He.blockId,re)))?.node??null;if(!Ue)continue;const je=nb(Ue),rt=lU(Array.isArray(je?.inlines)?je.inlines:[],He.range);ye?ye=fA(ye,rt):ye=rt}const Re=ye?Fz(ye):{},ze={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},Ye=new Set([...v?.activeMarks??(Array.isArray(f?.activeMarks)?f.activeMarks:[]),...A]);for(const[He,Ue]of Object.entries(ze))Ye.has(He)&&(Re[Ue]=!0);const Be=b??await Iu(v??la(f,"ready"));if(Be.fontFamily&&(Re.fontFamily=Be.fontFamily),Be.color&&(Re.color=Be.color),Be.highlight&&(Re.highlight=Be.highlight),Be.fontSize){const He=Number.parseFloat(Be.fontSize);Number.isNaN(He)||(Re.fontSize=He)}let Ze=null;if(U.length===1){const He=U[0],Ue=(await da(mo(He.blockId,re)))?.node??null;Ue&&nb(Ue)&&(Ze=await cU(Ue,He.blockId,Q,re))}return{story:re??null,inline:Re,paragraph:Ze}},nb=f=>f?f.kind==="paragraph"?f.paragraph??null:f.kind==="heading"?f.heading??null:null:null,lU=(f,v)=>{const b=Q=>{const re=Q.run;return typeof re?.text=="string"?re.text:""},A=Q=>Q.run?.props;if(v.start===v.end){let Q=0;for(const re of f){const ye=b(re),Re=Q,ze=Q+ye.length;if(Q=ze,v.start>=Re&&v.start<=ze){const Ye=A(re);return Ye?{...Ye}:{}}}return{}}let E=0;const U=[];for(const Q of f){const re=b(Q),ye=E,Re=E+re.length;if(E=Re,Re<=v.start||ye>=v.end)continue;const ze=A(Q);ze&&U.push(ze)}return U.length===0?{}:U.length===1?{...U[0]}:fA(U[0],...U.slice(1))},fA=(f,...v)=>{const b={...f};for(const A of v)for(const E of Object.keys(b)){if(!(E in A)){delete b[E];continue}const U=b[E],Q=A[E];(typeof U!=typeof Q||JSON.stringify(U)!==JSON.stringify(Q))&&delete b[E]}return b},cU=async(f,v,b,A)=>{const E=nb(f),U=E.props??{},Q=E.styleRef??null,re=U.alignment??null,ye=U.spacing??null,Re=U.indent??null,ze=Re?{...Re.left!=null?{left:Re.left}:{},...Re.right!=null?{right:Re.right}:{},...Re.firstLine!=null?{firstLine:Re.firstLine}:{},...Re.hanging!=null?{hanging:Re.hanging}:{}}:null,Ye=U.markRunProps??null,Be=U.numbering?.numId,Ze=typeof Be=="string"?parseInt(Be,10):typeof Be=="number"?Be:NaN,He=U.numbering?.level,Ue=isNaN(Ze)?null:{numId:Ze,...He!=null?{level:He}:{}};let je=null;if(Ue&&typeof b.lists?.getState=="function")try{const rt=await b.lists.getState({target:mo(v,A)});rt&&typeof b.lists?.getStyle=="function"&&(je=await b.lists.getStyle(rt)??null)}catch{}return{styleId:Q,alignment:re,spacing:ye,indentation:ze,markRunProps:Ye,numbering:Ue,listStyle:je}},hA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const f=y()?.selection,v=async()=>Ri(typeof f?.current=="function"?await Promise.resolve(f.current({includeText:!0})):ll().value),b=()=>new Promise(Q=>setTimeout(Q,16)),A=8;let E=null,U="";for(let Q=0;Q<A;Q+=1){if(Q>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(E=await v(),!(!E||E.empty)&&(U=Ql(E),U!==h.sourceSelectionKey))break}if(E&&!E.empty&&U!==h.sourceSelectionKey){await pA(E);return}if(h.snapshot?.paragraph){const Q=await v();if(!Q||Ql(Q)===h.sourceSelectionKey)return;await pA(Q)}},pA=async f=>{const v=h.snapshot;if(!v){h.mode==="armed"&&wa();return}const b=y();if(!b)return;const A=la(f,"ready"),{lockModesById:E}=vs(b.contentControls,A);if(Xi(E)){jt();return}const U=f.target,Q=f.selectionTarget;if(f.empty!==!0&&Object.keys(v.inline).length>0){const re=gr(b,"format.apply");if(re&&Q)try{if(!No(el(await Promise.resolve(Of("format.apply",re,{target:Q,inline:v.inline},f))))){jt();return}}catch{jt();return}}if(v.paragraph){const re=Array.isArray(U?.segments)?U.segments:[],ye=U?.story;for(const Re of re){const ze=mo(Re.blockId,ye),Ye=await da(ze),Be=Ye?.node??null,Ze=Ye?.address??null;if(!Be)continue;const He={kind:"block",nodeType:Ze?.nodeType??Be.kind??"paragraph",nodeId:Re.blockId,...ye&&typeof ye=="object"?{story:ye}:{}},{styleId:Ue,alignment:je,spacing:rt,indentation:$e,markRunProps:Bt,numbering:Xt,listStyle:Nn}=v.paragraph;if(Ue&&await b.styles?.paragraph?.setStyle?.({target:He,styleId:Ue}),je&&await b.format?.paragraph?.setAlignment?.({target:He,alignment:je}),rt){const Gn=rt,Jr=Gn.lineRule??"auto",Vr=new Set(["auto","exact","atLeast"]).has(Jr)?Jr:"auto",Lr={...Gn.before!=null?{before:Math.round(Gn.before*20)}:{},...Gn.after!=null?{after:Math.round(Gn.after*20)}:{},...Gn.line!=null?{line:Math.round(Vr==="auto"?Gn.line*240:Gn.line*20),lineRule:Vr}:{}};await b.format?.paragraph?.setSpacing?.({target:He,...Lr})}if($e){const Gn={...$e.left!=null?{left:ms($e.left)}:{},...$e.right!=null?{right:ms($e.right)}:{},...$e.firstLine!=null?{firstLine:ms($e.firstLine)}:{},...$e.hanging!=null?{hanging:ms($e.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:He,...Gn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:He,markRunProps:Bt}),Xt&&await b.format?.paragraph?.setNumbering?.({target:He,...Xt}),Nn&&((await da(ze))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:eA(Re.blockId,ye),style:Nn}):Xt&&await b.format?.paragraph?.setNumbering?.({target:He,...Xt}))}}h.mode==="armed"&&wa(),jt()},fm=(f,v,b)=>{const A=Ci(f,v),E=A?A.then(()=>(ri(f,v,b),Se)):(ri(f,v,b),Se);return uu(f)?.inline?.kind==="toggle"&&(ht=E),E},mA=f=>({id:f,getState:()=>bt.toolbar.commands[f]??Ru(f,y(),bt.selection,pl(bt.selection)),observe:v=>Go(b=>b.toolbar.commands[f]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:at.commandUnsupported}).subscribe(v),execute:v=>ri(f,v),executeAsync:v=>fm(f,v)}),uU=f=>{he.set(f.id,f),jt();const v=()=>{he.delete(f.id),jt()};return Object.assign(v,{handle:mA(f.id),unregister:v})},hm=lo(f=>f.selection),pm=Qr(hm),gA=()=>{const f=T();if(typeof f?.getHandles!="function")return{reason:at.hostCapabilityUnavailable};let v=null;try{v=f.getHandles()}catch(A){const E=A?.reason;return{reason:E==="host-not-ready"||E==="host-disposed"||E==="editing-mount-required"?at.notReady:at.hostCapabilityUnavailable}}const b=v?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:at.hostCapabilityUnavailable}:{helper:b}},vA={get:pm.get,getSnapshot:pm.getSnapshot,subscribe:pm.subscribe,observe:pm.observe,current:()=>ll().value,capture:()=>{const f=hm.get();return f.empty||!f.target&&!f.selectionTarget?null:{...f,capturedAt:Date.now()}},restore:f=>{const v=E=>(jt(),{...E,success:E.ok});if(!f||typeof f!="object")return v({ok:!1,reason:at.targetUnresolved});if(!S())return v({ok:!1,reason:at.notReady});const b=EH(f);if(!b)return v({ok:!1,reason:at.targetUnresolved});const A=gA();if(!("helper"in A))return v({ok:!1,reason:A.reason});try{return v(qk(A.helper.apply(b)))}catch{return v({ok:!1,reason:at.hostCapabilityUnavailable})}},apply:f=>{if(!S())return{ok:!1,reason:at.notReady};const v=gA();if(!("helper"in v))return{ok:!1,reason:v.reason};try{const b=v.helper.apply(f);return jt(),qk(b)}catch{return{ok:!1,reason:at.hostCapabilityUnavailable}}},getAnchorRect:f=>{const v=T();if(typeof v?.getSelectionAnchorRect=="function"){const b=Tt(()=>v.getSelectionAnchorRect(f),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:f=>{const v=hm.get(),b=v.selectionTarget??v.target;if(v.empty||!b)return[];const A=km.getRect({target:b,relativeTo:f?.relativeTo});return A.found?A.rects:[]}},dU={get ids(){return it()},has:f=>uu(f)!=null||he.has(f),get:f=>mA(f),execute:ri,executeAsync:fm,register:uU,getContextMenuItems:f=>{const v=[];for(const b of he.values()){const A=b.contextMenu;A&&Tt(A.when?()=>A.when(f):void 0,!0)&&v.push({id:b.id,label:A.label,group:A.group,order:A.order,invoke:()=>ri(b.id,void 0,f)})}return v.sort((b,A)=>(b.order??0)-(A.order??0)||b.label.localeCompare(A.label))}},rb=Qr(lo(f=>f.toolbar)),fU={get:rb.get,getSnapshot:()=>bt.toolbar,subscribe:rb.subscribe,observe:rb.observe,execute:ri,executeAsync:fm},mc=async(f,v)=>{if(!S())return{success:!1,ok:!1,reason:at.notReady};if(!f)return{success:!1,ok:!1,reason:at.targetUnresolved};const b=T(),A=b?.scrollTargetIntoView;if(typeof A!="function")return{success:!1,ok:!1,reason:at.hostCapabilityUnavailable};try{const E=await Promise.resolve(A.call(b,{target:f,block:v?.block??"center",behavior:v?.behavior??"smooth"}));return E&&typeof E=="object"&&E.success===!1?{success:!1,ok:!1,reason:z0(E.reason,at.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:at.hostCapabilityUnavailable}}},mm=async(f,v,b,A)=>{const E=f==="trackChanges"?A?.story:void 0,U=ze=>{if(!E||!ze||typeof ze!="object")return ze;const Ye=ze,Be=Ye.address&&typeof Ye.address=="object"?Ye.address:null;return Ye.story||Be?.story?ze:{...Ye,story:E}},Q=H0(b.find(ze=>Ja(ze,v,E)));if(Q)return U(Q);const re=y()?.[f],ye=f==="comments"?{commentId:v}:{id:v,...E?{story:E}:{}},Re=re?.get;if(typeof Re!="function")return null;try{return U(H0(await Promise.resolve(Re.call(re,ye))))}catch{return null}};function yA(f,v){if(bi())return ar("Comments are read-only.","DOCUMENT_READONLY");if(yu())return ar("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,A=b?.patch;if(typeof A!="function")return ar("comments.patch is unavailable.");const E=ar("comments.patch failed.");return Tt(()=>ba(A.call(b,{commentId:f,status:v}),E),E)}const gm=()=>bi()?ar("Comments are read-only.","DOCUMENT_READONLY"):null,bA=(f,v)=>{const b=v&&typeof v=="object"?v:null;let A=Array.from(f);b?.includeResolved===!1&&(A=A.filter(ye=>ye.status!=="resolved"));const E=Number(b?.offset),U=Number.isInteger(E)&&E>0?E:0,Q=Number(b?.limit),re=Number.isInteger(Q)&&Q>=0?U+Q:void 0;return A.slice(U,re)},Bu=lo(f=>f.comments),vm=Qr(Bu),hU={get:vm.get,getSnapshot:vm.getSnapshot,subscribe:vm.subscribe,observe:vm.observe,list:f=>{const v=Bu.get();if(v.status!=="pending")return bA(v.items,f);const b=y()?.comments,A=Tt(b?.list?()=>b.list(f):void 0,null);return Or(A)?[]:bA(Array.isArray(A?.items)?A.items:[],f)},getById:f=>{const v=Bu.get().items.find(E=>Hn(E)===f)??null;if(v)return v;const b=y()?.comments,A=Tt(b?.get?()=>b.get({commentId:f}):void 0,null);return Or(A)?null:A},createFromCapture:(f,v)=>{const b=gm();if(b)return b;const A=y()?.comments,E=A?.create;if(typeof E!="function")return ar("comments.create is unavailable.");const U=ar("comments.create failed.");return Tt(()=>ba(E.call(A,{target:f.target??f.selectionTarget,text:v.text}),U),U)},createFromSelection:f=>{const v=gm();if(v)return v;const b=y()?.comments,A=b?.create;if(typeof A!="function")return ar("comments.create is unavailable.");const E=hm.get(),U=E.target??E.selectionTarget;if(E.empty||!U)return ar("A range selection is required to comment.","NO_SELECTION");const Q=ar("comments.create failed.");return Tt(()=>ba(A.call(b,{target:U,text:f.text}),Q),Q)},reply:(f,v)=>{const b=gm();if(b)return b;const A=y()?.comments,E=A?.reply??A?.create;if(typeof E!="function")return ar("comments.reply is unavailable.");const U=ar("comments.reply failed.");return Tt(()=>ba(E===A?.reply?E.call(A,{parentCommentId:f,text:v.text}):E.call(A,{parentCommentId:f,text:v.text}),U),U)},resolve:f=>yA(f,"resolved"),reopen:f=>yA(f,"active"),delete:f=>{const v=gm();if(v)return v;const b=y()?.comments,A=b?.delete??b?.remove;if(typeof A!="function")return ar("comments.delete is unavailable.");const E=ar("comments.delete failed.");return Tt(()=>ba(A.call(b,{commentId:f}),E),E)},setActive:f=>{if(f==null)return ge=null,jt(),!0;if(!S())return!1;const v=Bu.get();if(v.listStatus!=="ready")return!1;const b=lH(v.items,f);return!b||!v.items.some(A=>Hn(A)===b)?!1:(ge=b,jt(),!0)},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:S()?at.documentApiUnavailable:at.notReady};const v=await mm("comments",f,Bu.get().items);return v?mc(v):{success:!1,ok:!1,reason:at.targetUnresolved}}},Ca=lo(f=>f.trackChanges),ob=(f,v)=>{const b=Ca.get().items.filter(Re=>Hn(Re)!==null);if(b.length===0)return null;const A=bt.trackChanges.activeId,E=ae?.id===A?ae.story:void 0;let U=A?b.findIndex(Re=>Ja(Re,A,E)):-1;U===-1&&A&&E&&(U=b.findIndex(Re=>Ja(Re,A)));const Q=b[U===-1?f>0?0:b.length-1:(U+f+b.length)%b.length],re=Hn(Q),ye=Qk(Q);return Je(ye?{id:re,story:ye}:{id:re},v),jt(),re};let wA=Promise.resolve();const pU=f=>{const v=oe;return wA.catch(()=>{}).then(()=>mU(f,v))},mU=async(f,v)=>{if(oe!==v)return{success:!1};const b=ae,A=ob(f,{invalidateQueuedNavigation:!1});if(A==null)return{success:!1};const E=ae,U=_e,Q=()=>ae===E&&_e===U,re=()=>{Q()&&(Je(b,{invalidateQueuedNavigation:!1}),jt())},ye=await mm("trackChanges",A,Ca.get().items,E?.story?{story:E.story}:void 0);if(!Q())return{success:!1};if(!ye)return re(),{success:!1};ao+=1;try{const Re=await mc(ye,{behavior:"auto"});return Q()?(!Re.ok&&Re.reason!==at.targetNotVisible?(re(),Ge(b)):Ge(E),{success:Re.ok}):{success:!1}}finally{ao=Math.max(0,ao-1),ao===0&&(Q()?zr&&Po(Pi(zr)):Ge(ae))}},CA=f=>{const v=pU(f);return wA=v.then(()=>{},()=>{}),v},ym=Qr(Ca),gU={get:()=>(Fr(),ym.get()),getSnapshot:()=>(Fr(),ym.getSnapshot()),subscribe:f=>(Fr(),ym.subscribe(f)),observe:f=>(Fr(),ym.observe(f)),list:()=>(Fr(),Ca.get().items),accept:f=>_A("accept",f),reject:f=>_A("reject",f),acceptAll:()=>Nu("accept",{scope:"all"},null),rejectAll:()=>Nu("reject",{scope:"all"},null),next:()=>ob(1),previous:()=>ob(-1),navigateNext:()=>CA(1),navigatePrevious:()=>CA(-1),getAt:f=>{if(!f||typeof f!="object"||typeof f.x!="number"||typeof f.y!="number")return null;const v=sb(f);if(v.length===0)return null;const b=Ca.get().items;let A;for(const E of v){if(E.type!=="trackedChange")continue;let U;if(E.story){if(A===void 0&&(A=Lo()),!A)continue;U=A}else U=b;const Q=U.find(re=>Ja(re,E.id,E.story));if(Q)return E.story?{id:Q.id,item:Q,story:E.story}:{id:Q.id,item:Q}}return null},setActive:f=>{if(f==null)return Je(null),Ge(null),jt(),!0;if(!S())return!1;const v=typeof f=="string"?{id:f}:{id:f.id,story:f.story};if(typeof v.id!="string"||v.id.length===0)return!1;const b=v.id;if(v.story){const A=Lo();if(!A)return!1;const E=$k(A,v.story).toPublicId(v.id)??v.id;if(!A.some(U=>Ja(U,E,v.story)))return!1;v.id=E}else{const A=Ca.get().items,E=em(A).toPublicId(v.id)??v.id;if(!A.some(U=>Hn(U)===E))return!1;v.id=E}return b!==v.id&&(v.paintedEntityId=b),Je(v),Ge(v),jt(),!0},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:S()?at.documentApiUnavailable:at.notReady};const v=Ca.get().items,b=Qk(v.find(ze=>Hn(ze)===f)),A=await mm("trackChanges",f,v,b?{story:b}:void 0);if(!A)return{success:!1,ok:!1,reason:at.targetUnresolved};const E=ae,U=b?{id:f,story:b}:{id:f};Je(U),jt();const Q=ae,re=_e,ye=()=>ae===Q&&_e===re,Re=()=>{ye()&&(Je(E,{invalidateQueuedNavigation:!1}),jt())};ao+=1;try{const ze=await mc(A,{behavior:"auto"});return ye()?(!ze.ok&&ze.reason!==at.targetNotVisible?(Re(),Ge(E)):Ge(U),ze):{success:!1,ok:!1}}finally{ao=Math.max(0,ao-1),ao===0&&(ye()?zr&&Po(Pi(zr)):Ge(ae))}}},_A=(f,v)=>{const{id:b,story:A}=typeof v=="string"?{id:v,story:void 0}:v;return Nu(f,{kind:"id",id:b,...A?{story:A}:{}},b,A)},Nu=(f,v,b,A)=>{try{return co(vU(f,v,b,A))}catch{return!1}},vU=(f,v,b,A)=>{if(bi())return!1;const E=y()?.trackChanges,U=v.scope==="all",Q=v.kind==="range",re=v.kind==="ids";if(ic({kind:f,scope:U?"all":"id"},E))return!1;const ye=U?`${f}All`:f,Re=!Q&&!re&&!A&&E&&typeof E[ye]=="function"?E[ye]:null,ze=E&&typeof E.decide=="function"?E.decide:null;return!Re&&!ze?!1:Re?Re.call(E,b??{}):ze.call(E,{decision:f,target:v})},ib=lo(f=>f.contentControls),Bf=f=>ib.get().items.find(v=>v?.id===f)??null,bm=Qr(ib),yU=(f=>{if(f===void 0)return bm.get();const v=$p(f);return v?Bf(v):null}),bU={get:(f=>(f!==void 0&&cn("api"),yU(f))),getSnapshot:bm.getSnapshot,subscribe:bm.subscribe,observe:bm.observe,list:()=>(cn("api"),ib.get().items),getById:f=>(cn("api"),Bf(f)),getRect:f=>{const v=$p(f);if(!v)return tl("unresolved");cn("panel");const b=Bf(v);if(!b)return tl("unresolved");const A=U0(b);return A?km.getRect({target:A}):tl("unavailable")},scrollIntoView:async f=>{const v=$p(f);if(!v)return{success:!1};cn("panel");const b=Bf(v);if(!b)return{success:!1};const A=U0(b);return A?{success:(await mc(A,{block:f.block,behavior:f.behavior})).ok}:{success:!1}},focus:async f=>{const v=$p(f);if(!v)return{success:!1,reason:"invalid-id"};if(!S())return{success:!1,reason:"not-ready"};cn("panel");const b=Bf(v);if(!b)return{success:!1,reason:"not-found"};const A=U0(b);if(!A)return{success:!1,reason:"not-reachable"};if(!(await mc(A,{block:f.block,behavior:f.behavior})).ok)return{success:!1,reason:"not-reachable"};const E=iH(A);if(!E)return{success:!1,reason:"not-reachable"};const U=vA.apply(E);return!U.ok&&U.reason!==at.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:{success:!0}}},wm=Qr(lo(f=>f.fonts)),wU={get:wm.get,getSnapshot:wm.getSnapshot,subscribe:wm.subscribe,observe:wm.observe,getFamilyOptions:()=>bt.fonts.options,getSizeOptions:()=>bt.fonts.sizeOptions},Cm=Qr(lo(f=>f.zoom)),CU={get:Cm.get,getSnapshot:Cm.getSnapshot,subscribe:Cm.subscribe,observe:Cm.observe,set:f=>{if(typeof t?.setZoom=="function")try{t.setZoom(f),jt()}catch{}},setMode:f=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(f),jt()}catch{}}},_m=Qr(lo(f=>f.document)),_U={get:_m.get,getSnapshot:_m.getSnapshot,subscribe:_m.subscribe,observe:_m.observe,setMode:f=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(f),jt()}catch{}},export:f=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(f))}catch{return}},getText:()=>{const f=y(),v=Tt(f?.getText?()=>f.getText({}):void 0,null);return typeof v=="string"?v:v&&typeof v=="object"&&typeof v.text=="string"?v.text:null},replaceFile:f=>{const v=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof v=="function")try{return Promise.resolve(v.call(t,f))}catch{return}}},SA=()=>{if(typeof HTMLElement>"u")return null;const f=S()?.mount?.container;if(f instanceof HTMLElement)return f;const v=t?.element;return v instanceof HTMLElement?v:null},SU=(f,v)=>{if(typeof f!="number"||typeof v!="number"||!Number.isFinite(f)||!Number.isFinite(v))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const A=SA();if(!A)return[];const E=b.elementFromPoint(f,v);if(!E||!A.contains(E))return[];const U=[E],Q=$e=>{$e&&A.contains($e)&&!U.includes($e)&&U.push($e)},re=b.elementsFromPoint;if(typeof re=="function"){let $e=[];try{$e=re.call(b,f,v)??[]}catch{$e=[]}for(const Bt of $e)Q(Bt)}const ye=[],Re=$e=>{$e&&A.contains($e)&&!ye.includes($e)&&!U.includes($e)&&ye.push($e)},ze=$e=>{const Bt=$e.getBoundingClientRect;if(typeof Bt!="function")return!1;let Xt;try{Xt=Bt.call($e)}catch{return!1}return Xt!=null&&f>=Xt.left&&f<=Xt.right&&v>=Xt.top&&v<=Xt.bottom};for(const $e of U){const Bt=$e.querySelectorAll;if(typeof Bt!="function")continue;let Xt;try{Xt=Bt.call($e,"[data-track-change-marker]")}catch{continue}for(let Nn=0;Nn<Xt.length;Nn+=1)ze(Xt[Nn])&&Re(Xt[Nn])}ye.reverse();const Ye=[...ye,...U],Be=Wk(Ye[0],A);for(let $e=1;$e<Ye.length;$e+=1)for(const Bt of Wk(Ye[$e],A))Be.push(Bt);if(Be.length===0)return Be;const Ze=Ca.get().items,He=em(Ze);let Ue;const je=new Set,rt=[];for(const $e of Be){if($e.type!=="trackedChange"){const Gn=`${$e.type}:${$e.id}`;if(je.has(Gn))continue;je.add(Gn),rt.push($e);continue}const Bt=oH($e.storyKey)??rH($e.story);let Xt;if(Bt){if(Ue===void 0&&(Ue=Lo()),!Ue||(Xt=$k(Ue,Bt).toPublicId($e.id),!Xt||!Ue.some(Gn=>Ja(Gn,Xt,Bt))))continue}else if(Xt=He.toPublicId($e.id),!Xt)continue;const Nn=`trackedChange:${Xt}`;je.has(Nn)||(je.add(Nn),rt.push(Bt?{type:"trackedChange",id:Xt,story:Bt}:{type:"trackedChange",id:Xt}))}return rt};function sb(f,v){return typeof f=="object"?SU(f?.x,f?.y):null}const zu=new Set;let ab=!1;const kA=f=>{const v=T();if(typeof v?.observeGeometry!="function")return;let b=!1;const A=Tt(()=>{const E=v.observeGeometry(()=>f.schedule());return b=!0,E},null);f.detach=typeof A=="function"?A:null,f.boundHost=b?v:null},Sm=f=>{if(f.detach){try{f.detach()}catch{}f.detach=null}f.boundHost=null},AA=()=>{if(ab=!1,!(be||T()))for(const f of zu)Sm(f)},kU=()=>{if(!ab){if(ab=!0,typeof queueMicrotask=="function"){queueMicrotask(AA);return}Promise.resolve().then(AA)}},AU=()=>{const f=T();if(!f){kU();return}for(const v of zu)v.boundHost&&v.boundHost===f||(Sm(v),kA(v),v.schedule())};_s.push(AU);const km={getRect:f=>{const v=T(),b=v?.getTargetRects;if(typeof b=="function"){const A=Tt(()=>b.call(v,{target:f.target}),null);return A&&typeof A=="object"?A.success===!0&&Array.isArray(A.rects)?AH(kH(A.rects.filter(E=>E!=null&&typeof E=="object")),f.relativeTo):tl(typeof A.reason=="string"?A.reason:"unresolved"):tl("unresolved")}return tl("unavailable")},observe:f=>{const v=[];let b=0;const A=typeof requestAnimationFrame=="function",E=()=>{if(!A){f();return}b||(b=requestAnimationFrame(()=>{b=0,f()}))},U=Go(re=>({ready:re.ready,selection:re.selection,zoom:re.zoom}));v.push(U.subscribe(()=>E()));const Q={schedule:E,detach:null,boundHost:null};return kA(Q),zu.add(Q),()=>{zu.delete(Q),Sm(Q),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const re of v.splice(0))try{re()}catch{}}},getHost:()=>SA(),entityAt:sb,contextAt:f=>{const v=!!f&&typeof f.x=="number"&&typeof f.y=="number",b=v?f.x:0,A=v?f.y:0;return{point:{x:b,y:A},entities:v?sb({x:b,y:A}):[],selection:bt.selection,position:null,insideSelection:!1}},scrollIntoView:async f=>{const v=f?.target;if(!v)return{success:!1};let b=null;if(v.kind==="entity"){const A=v.entityType==="comment"?"comments":"trackChanges",E=A==="comments"?Bu.get().items:Ca.get().items,U=v.entityType==="trackedChange"&&v.story?{story:v.story}:void 0;b=await mm(A,v.entityId,E,U)}else{const A=v,E=v,U=Array.isArray(A.segments)&&A.segments.length>0?A.segments:E.blockId&&E.range?[{blockId:E.blockId,range:E.range}]:null;if(U){const Q=v.story;b={kind:"text",segments:U,...Q?{story:Q}:{}}}}return b?{success:(await mc(b,{block:f.block??"center",behavior:f.behavior??"smooth"})).ok}:{success:!1}}},IA=f=>{const v=(f&&typeof f=="object"?f:null)?.target;return v&&typeof v=="object"?v:null},EA=f=>`metadata:resolve:${f}`,IU=f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return null;const{value:b}=Yn(EA(f),Ft(),()=>v.resolve({id:f}),IA);return b},EU=async f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return null;try{const b=Ft(),A=await Promise.resolve(v.resolve({id:f}));if(b!==Ft())return null;const E=IA(A);return Le.set(EA(f),{token:b,value:E,hasSettled:!0,inflightToken:null}),E}catch{return null}},xU={getRect:f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return tl("unavailable");const b=IU(f.id);return b?km.getRect({target:b}):tl("unresolved")},scrollIntoView:async f=>{const v=await EU(f.id);return v?{success:(await mc(v,{block:f.block,behavior:f.behavior})).ok}:{success:!1}}},TU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},RU={getContext:()=>{const f=Ne();if(!f)return{...TU};const v=fe()?.table;return{inTable:!0,tableNodeId:f.tableNodeId,rowIndex:f.rowIndex,columnIndex:f.columnIndex,cellNodeId:f.cellNodeId,rows:typeof v?.rows=="number"?v.rows:null,columns:typeof v?.columns=="number"?v.columns:null}},isInTable:()=>Ne()!=null},Am={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:at.searchUnavailable};let xn={...Am};const Im=new Set,_a=()=>{const f=T()?.search;return f&&typeof f=="object"?f:null},Ss=()=>{const f=I()?.search;return f&&typeof f=="object"?f:null},Nf=()=>{const f=_a();if(f&&typeof f.setSession=="function")return!0;const v=Ss();return!!v&&typeof v.query=="function"&&typeof v.getState=="function"},Zi=()=>{for(const f of[...Im])try{f(xn)}catch{}},oi=f=>(xn={...xn,...f},Zi(),xn);let Zr=0,gc=null;const xA=()=>{const f=gc;gc=null,f&&Tt(()=>(f(),null),null)},MU=()=>{Zr+=1,xA();const f=Nf();xn={...Am,available:f,reason:f?void 0:at.searchUnavailable},Zi()};Pu.push(MU);const LU=f=>{if(!f)return!1;const v=f.queryError;if(v&&typeof v=="object"&&v.code==="invalid-pattern")return!0;const b=f.rejection;return f.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},lb=(f,v=!1)=>{const b=f&&typeof f=="object"?f:null;if(!b)return null;const A=Array.isArray(b.matches)?b.matches:[],E=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:A.length,U=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:E,activeIndex:U,canReplace:b.canReplace===!0||v,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...LU(b)?{invalidPattern:!0}:{}}},wo=()=>{const f=L("find.replace"),v=L("find.replaceAll");return f?.enabled===!0||v?.enabled===!0},Co=(f,v=!1)=>{const b=lb(f,v);if(!b){oi({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}oi({...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?at.searchInvalidPattern:void 0})},Sa=()=>{const f=_a();if(f&&typeof f.getState!="function")return xn={...xn,available:Nf(),reason:Nf()?void 0:at.searchUnavailable},xn;if(!f){const b=Ss();if(b&&typeof b.getState=="function"){const A=lb(Tt(()=>b.getState(),null),wo());if(A)return xn={...xn,...A.query!==void 0?{query:A.query}:{},total:A.total,activeIndex:A.activeIndex,canReplace:A.canReplace,available:!0,reason:A.invalidPattern?at.searchInvalidPattern:void 0,open:xn.open||!!A.query},xn}return xn={...Am,query:xn.query,caseSensitive:xn.caseSensitive,includeDeletedText:xn.includeDeletedText},xn}const v=lb(Tt(()=>f.getState(),null));return v&&(xn={...xn,...v.query!==void 0?{query:v.query}:{},total:v.total,activeIndex:v.activeIndex,canReplace:v.canReplace,...v.includeDeletedText!==void 0?{includeDeletedText:v.includeDeletedText}:{},...v.regex!==void 0?{regex:v.regex}:{},available:!0,reason:v.invalidPattern?at.searchInvalidPattern:void 0,open:xn.open||!!v.query}),xn},Hu=f=>{const v=f&&typeof f=="object"?f:null;if(v?.status==="committed")return{ok:!0};if(v?.status==="rejected"&&v.reason==="read-only")return{ok:!1,reason:at.documentReadonly};const b=v?.rejection;return v?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:at.documentReadonly}:{ok:!1,reason:at.operationUnavailable}},Em=Qr({get:()=>Sa(),subscribe:f=>(Im.add(f),()=>Im.delete(f))}),DU={get:Em.get,getSnapshot:Em.getSnapshot,subscribe:Em.subscribe,observe:Em.observe,open:()=>Nf()?(oi({available:!0,open:!0,reason:void 0}),{ok:!0}):(oi({available:!1,open:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}),close:()=>{if(Zr+=1,gc)xA();else{const f=_a();if(f&&typeof f.clear=="function")Tt(()=>f.clear(),null);else{const v=Ss();v&&typeof v.query=="function"&&Tt(()=>v.query({query:""}),null)}}xn={...Am,available:Nf(),reason:void 0},xn.available||(xn.reason=at.searchUnavailable),Zi()},search:(f,v)=>{const b=_a(),A=!!v?.caseSensitive,E=v?.includeDeletedText===!0,U=v?.regex===!0,Q=++Zr;if(!b||typeof b.setSession!="function"){const re=Ss();if(re&&typeof re.query=="function"&&typeof re.getState=="function"){oi({query:f,caseSensitive:A,includeDeletedText:E,regex:U,available:!0,open:!0,reason:void 0}),gc=()=>{re.query({query:""})};const ye=Tt(()=>re.query({query:f,caseSensitive:A,includeDeletedText:E,regex:U}),null);return Or(ye)?Promise.resolve(ye).then(Re=>{Q===Zr&&Co(Re,wo())},()=>{Q===Zr&&oi({available:!1,reason:at.searchUnavailable})}):Co(ye,wo()),Co(Tt(()=>re.getState(),null),wo()),xn}return oi({query:f,total:0,activeIndex:-1,available:!1,caseSensitive:A,includeDeletedText:E,regex:U,reason:at.searchUnavailable})}if(oi({query:f,caseSensitive:A,includeDeletedText:E,regex:U,available:!0,open:!0,reason:void 0}),gc=()=>{typeof b.clear=="function"&&b.clear()},Co(Tt(()=>b.setSession(f,{caseSensitive:A,includeDeletedText:E,...U?{regex:!0}:{},highlight:!0}),null)),f.length>0&&xn.total===0&&xn.reason!==at.searchInvalidPattern){const re=Ss();if(re&&typeof re.query=="function"&&typeof re.getState=="function"){const ye=gc;gc=()=>{ye?.(),re.query({query:""})};const Re=Tt(()=>re.query({query:f,caseSensitive:A,includeDeletedText:E,regex:U}),null);Or(Re)?Promise.resolve(Re).then(ze=>{Q===Zr&&Co(ze,wo())},()=>{Q===Zr&&oi({available:!1,reason:at.searchUnavailable})}):Co(Re,wo()),Co(Tt(()=>re.getState(),null),wo())}}return xn},next:()=>{const f=_a();if(!f||typeof f.next!="function"){const v=Ss();if(!v||typeof v.next!="function"||typeof v.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(xn.total===0)return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.next(),null);if(Or(b)){const A=Zr;Promise.resolve(b).then(E=>{A===Zr&&Co(E,wo())}).catch(()=>{A===Zr&&oi({available:!1,reason:at.searchUnavailable})})}else Co(b,wo());return Co(Tt(()=>v.getState(),null),wo()),{ok:!0}}return xn.total===0?{ok:!1,reason:at.operationUnavailable}:(Co(Tt(()=>f.next(),null)),{ok:!0})},previous:()=>{const f=_a();if(!f||typeof f.previous!="function"){const v=Ss();if(!v||typeof v.previous!="function"||typeof v.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(xn.total===0)return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.previous(),null);if(Or(b)){const A=Zr;Promise.resolve(b).then(E=>{A===Zr&&Co(E,wo())}).catch(()=>{A===Zr&&oi({available:!1,reason:at.searchUnavailable})})}else Co(b,wo());return Co(Tt(()=>v.getState(),null),wo()),{ok:!0}}return xn.total===0?{ok:!1,reason:at.operationUnavailable}:(Co(Tt(()=>f.previous(),null)),{ok:!0})},clear:()=>{Zr+=1;const f=_a();if(f&&typeof f.clear=="function"&&Tt(()=>f.clear(),null),!f||typeof f.clear!="function"){const v=Ss();v&&typeof v.query=="function"&&Tt(()=>v.query({query:""}),null)}oi({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:f=>{const v=_a();if(!v){const A=Ss();if(!A||typeof A.replace!="function"||typeof A.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(!wo())return{ok:!1,reason:at.operationUnavailable};const E=Tt(()=>A.replace({replacement:typeof f=="string"?f:""}),null);if(Or(E)){const U=Zr;Sa(),Zi();const Q=()=>U===Zr;return Promise.resolve(E).then(re=>(Q()&&(Co(re,wo()),Sa(),Zi()),Hu(re)),()=>(Q()&&oi({available:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}))}return Sa(),Zi(),Hu(E)}if(typeof v.replaceCurrent!="function")return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.replaceCurrent(typeof f=="string"?f:""),null);return Sa(),Zi(),Hu(b)},replaceAll:f=>{const v=_a();if(!v){const A=Ss();if(!A||typeof A.replaceAll!="function"||typeof A.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(!wo())return{ok:!1,reason:at.operationUnavailable};const E=Tt(()=>A.replaceAll({replacement:typeof f=="string"?f:""}),null);if(Or(E)){const U=Zr;Sa(),Zi();const Q=()=>U===Zr;return Promise.resolve(E).then(re=>(Q()&&(Co(re,wo()),Sa(),Zi()),Hu(re)),()=>(Q()&&oi({available:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}))}return Sa(),Zi(),Hu(E)}if(typeof v.replaceAll!="function")return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.replaceAll(typeof f=="string"?f:""),null);return Sa(),Zi(),Hu(b)}},TA=lo(f=>f.styles),xm=Qr(TA),PU={get:xm.get,getSnapshot:xm.getSnapshot,subscribe:xm.subscribe,observe:xm.observe,getCatalog:f=>Dn(f).value,getQuickGallery:()=>TA.get().quickGallery,getActiveParagraphStyle:()=>yo(bt.selection,Fn().cache).style},RA={select:Go,get state(){return bt},selection:vA,commands:dU,toolbar:fU,comments:hU,trackChanges:gU,contentControls:bU,fonts:wU,zoom:CU,document:_U,viewport:km,metadata:xU,tables:RU,search:DU,styles:PU,formatPainter:{setPointerSelecting(f){be||(h={...h,pointerSelecting:f})},notifyPointerUp(){be||(h={...h,pointerSelecting:!1},hA())},setKeyboardSelecting(f){be||(h={...h,keyboardSelecting:f})},notifyKeyUp(){be||(h={...h,keyboardSelecting:!1},hA())},cancel(){be||wa()},onModeChange(f){return be?()=>{}:(p.add(f),()=>p.delete(f))}},createScope:()=>{const f=[];return{select:(v,b)=>{const A=Go(v,b);return{get:A.get,subscribe:E=>{const U=A.subscribe(E);return f.push(U),U}}},dispose:()=>{for(const v of f.splice(0))v()}}},destroy:()=>{if(!be){be=!0,Yt.reset(),ln(),G&&(clearTimeout(G),G=null),j&&(clearTimeout(j),j=null,V=0),$?.timer&&(clearTimeout($.timer),$.timer=null),$=null,W&&(clearTimeout(W),W=null),qr&&(clearTimeout(qr),qr=null),ft&&ft(),ft=null,Fe=null,lr.clear(),J.clear();for(const f of Mn.splice(0))f();Lt&&Lt(),Lt=null,mt=null,Nr&&Nr(),Nr=null,Pn=null,ti&&ti(),ti=null,zr=null,wi&&wi(),wi=null,Li=null,Mr&&Mr(),Mr=null,ma=null;for(const f of zu)Sm(f);zu.clear(),_t.clear(),Im.clear(),m+=1,p.clear(),Zr+=1,he.clear()}}};return Ve=RA,RA}var DH=[{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 PH(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 OH(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"?PH(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 FH(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 BH(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:DH;for(const s of i)o(s);return n}var NH=[{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 zH(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}It();var HH=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 UH(e,t){const n=new Z5.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function X0(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function aA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function VH(e,t){if(!e)return()=>{};if(X0(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=()=>{aA(e),s()},l=u=>{u!==!1&&(u===!0||X0(e))&&(aA(e),s())};return n("synced",a),n("sync",l),X0(e)&&s(),i}function Jo(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function jH(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 lA(e){return typeof e=="string"&&e.length>0?e:null}function Q0(e){return e?Jo(e)?lA(e.documentId??e.options?.documentId??null):lA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function GH(e){if(!e||Jo(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function Wi(e){if(!e)return null;if(Jo(e))return e.fonts??null;const t=GH(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 om=class extends Rm.default{static{this.allowedTypes=[Tr,Nl,Ph]}#t=!1;#n=!1;#e=null;#i=null;#s=null;#a=null;#u=null;#d=null;#l=wk({});get uiConfig(){return this.#l}#f=Ck({});get interactionConfig(){return this.#f}#m=Sk({});get surfacesConfig(){return this.#m}#o;#r=new GF;#p=null;#y=!1;constructor(e){if(super(),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,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},!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.#o=new DF({getModuleConfig:()=>this.#m}),this.#w(e,t)}async#w(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),HF(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.#ve(),this.config.user=UF(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=v9(this.config.modules.comments),this.#l=wk(this.config),this.#f=Ck(this.config),this.#m=Sk(this.config),this.config.disableContextMenu=!this.#l.contextMenu.enabled,this.#l.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#l.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#f.comments)}if(this.config.colors=i6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.0.0-next.50",this.#b("🦋 [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||Ji(),this.colors=this.config.colors??[],this.#x(),await uT(),this.#t)return;if(await this.#T(this.config.modules),this.#t){this.#le();return}this.config.cspNonce&&this.#E(),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.#p||(this.#p=this.#r.subscribe(i=>{this.#be(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.#u=o,this.#L(),this.#S(),this.#we(),this.#_()}#_(){if(this.#M(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#u)}#S(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new sP({Renderer:RF,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#h("requiredNumberOfEditors").documents.filter(e=>e.type===Tr).length}get ui(){return this.#d||(this.#d=LH({superdoc:this}),this.#t&&this.#d.destroy()),this.#d}get state(){return{documents:this.#h("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}#E(){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}}#x(){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=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}else if(n)this.config.documents=[{id:Ji(),type:Tr,url:this.config.document,name:"document.docx"}];else if(r){const s=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}else if(o){const s=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Pd(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||Ji()}}))}#M(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=YD({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.#o),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&&X8(this),this.#ae()}#c(e,t){t&&this.on(e,t)}#L(){this.#c("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#c("editorCreate",this.config.onEditorCreate),this.#c("editorDestroy",this.config.onEditorDestroy),this.#c("source:complete",this.config.onSourceComplete),this.#c("source:signals-complete",this.config.onSourceSignalsComplete),this.#c("ready",this.config.onReady),this.#c("comments-update",this.config.onCommentsUpdate),this.#c("content-control:active-change",this.config.onContentControlActiveChange),this.#c("content-control:click",this.config.onContentControlClick),this.#c("awareness-update",this.config.onAwarenessUpdate),this.#c("locked",this.config.onLocked),this.#c("pdf:document-ready",this.config.onPdfDocumentReady),this.#c("sidebar-toggle",this.config.onSidebarToggle),this.#c("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#j(e?.editor??null)),this.#c("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#c("exception",this.config.onException),this.#c("list-definitions-change",this.config.onListDefinitionsChange),this.#c("pagination-update",this.config.onPaginationUpdate),this.#c("fonts-resolved",this.config.onFontsResolved),this.#c("fonts-changed",this.config.onFontsChanged),this.#c("zoomChange",this.config.onZoomChange),this.#c("viewport-change",this.config.onViewportChange)}async#T({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:Ji(),type:Tr,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}#D(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=Gr(e),this.provider=Gr(t),this.#W();const n=this.config;this._cleanupAwareness=G8(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#k(){this.#a=null,this.#g(),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})}#g(){if(this.#i){try{this.#i()}catch{}this.#i=null}if(this.#s){try{this.#s()}catch{}this.#s=null}}#j(e){this.#g(),Jo(e)&&(this.#G(e),this.#P(e))}#G(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=nP(()=>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.#i=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#P(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#t||this.#C(!!r.isLocked,this.#O(r.lockedBy??null))};try{if(this.#a&&typeof t.setLocked=="function"){const o=this.#a;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#a=null}const r=t.getSnapshot?.();r&&n(r),this.#s=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#O(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#F(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#C(e,t){this.isLocked===e&&this.#F(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#b("🦋 [superdoc] Locking superdoc:",e,t,`
102
+ `;It();var ps=e=>{e.expand.value=!1};function F0(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function zk(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 kz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function Hk(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Az(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function Iz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}const Ez=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=wn({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),u=(r??bN).map(IN),c=wn({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:u,onActivate:({fontFamily:Ke}={},kt=!1)=>{if(kt){c.label.value="",c.selectedValue.value="";return}if(!Ke)return;Ke=Ke.split(",")[0],c.label.value=Ke;const Ut=u.find(Ot=>Ot.label===c.defaultLabel.value),Ft=u.find(Ot=>Ot.label===Ke);Ft?c.selectedValue.value=Ft.key:Ut?c.selectedValue.value=Ut.key:c.selectedValue.value=""},onDeactivate:()=>{c.label.value=c.defaultLabel.value;const Ke=u.find(kt=>kt.label===c.defaultLabel.value);Ke?c.selectedValue.value=Ke.key:c.selectedValue.value=""}}),d=wn({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(Ke){const kt=Hk(e),Ut=kt?.selectionTarget??zk(kt?.target),Ft=kt?.empty?"":kz(kt),Ot=Iz(e),hn=()=>ps(Ke),yn=()=>{const De=e.pendingSelectionCapture;De&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(De)};return Dr("div",{},[Dr($N,{handleClose:hn,selectedText:Ft,target:Ut,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Ot?.apiKey||e.config?.aiApiKey||"",endpoint:Ot?.endpoint||e.config?.aiEndpoint||"",restoreSelection:yn})])}const m=CN,p=wn({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:m,onActivate:({fontSize:Ke},kt=!1)=>{if(kt){p.label.value="",p.selectedValue.value="";return}const Ut=m.find(yn=>yn.label===String(p.defaultLabel.value));if(!Ke){p.label.value=p.defaultLabel.value,Ut?p.selectedValue.value=Ut.key:p.selectedValue.value="";return}let Ft=cB(Ke,12);Ft<8&&(Ft=8),Ft>96&&(Ft=96);let Ot=String(Ft);const hn=m.find(yn=>yn.label===Ot||yn.key===Ot);hn?p.selectedValue.value=hn.key:p.selectedValue.value="",p.label.value=Ot},onDeactivate:()=>{p.label.value=p.defaultLabel.value;const Ke=m.find(kt=>kt.label===String(p.defaultLabel.value));Ke?p.selectedValue.value=Ke.key:p.selectedValue.value=""}}),g=wn({type:"separator",name:"separator",isNarrow:!0}),k=wn({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),w=wn({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),S=wn({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=wn({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:()=>O0(e,y,[],!0)}],onActivate:({color:Ke})=>{y.iconColor.value=Ke||""},onDeactivate:()=>y.iconColor.value=""}),C=wn({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:()=>O0(e,C)}],onActivate:({color:Ke})=>{C.iconColor.value=Ke},onDeactivate:()=>C.iconColor.value="#000"}),T=wn({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),R=wn({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>M(R)}],onActivate:({href:Ke})=>{R.attributes.value=F0(R.attributes.value,Ke)},onDeactivate:()=>{R.attributes.value=F0(R.attributes.value,null),R.expand.value=!1}});function M(Ke){const kt=Hk(e),Ut=kt?.selectionTarget??zk(kt?.target),Ft=()=>{const Ot=e.pendingSelectionCapture;Ot&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Ot)};return Dr("div",{},[Dr(uS,{ui:e.ui,linkItem:Ke,textTarget:Ut,restoreSelection:Ft,closePopover:()=>ps(Ke),goToAnchor:()=>{ps(Ke);const Ot=Ke.attributes.value?.href;if(!Ot)return;const hn=Ot.slice(1),yn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${hn}']`);yn&&$d(yn)}})])}const H=wn({type:"options",name:"linkInput",command:"toggleLink",active:!1});R.childItem=H,H.parentItem=R;const B=wn({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),z=wn({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),X=wn({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:()=>P(X)}]});function P(Ke){return Dr("div",{},[Dr(mz,{onSelect:Ut=>{e.emitCommand({item:Ke,argument:Ut}),ps(Ke),P0(e)}})])}const N=wn({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>L(N)}]}),I=[{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 L(Ke){return Dr(_z,{options:I,onSelect:kt=>{ps(Ke);const{command:Ut}=kt;e.emitCommand({item:Ke,argument:{command:Ut}})}})}const Y=wn({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:()=>Dr("div",{},[Dr(TN,{onSelect:kt=>{ps(Y);const Ut={...Y,command:"setTextAlign"};Ut.command="setTextAlign",e.emitCommand({item:Ut,argument:kt}),te(Y,kt)}})]),key:"alignment"}],onActivate:({textAlign:Ke})=>{te(Y,Ke)},onDeactivate:()=>{te(Y,"left")}}),te=(Ke,kt)=>{let Ut=kt==="both"?"justify":kt,Ft={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Ot=Ft[Ut]??Ft.left;Ke.icon.value=Ot},le=wn({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 Ke=kt=>{ps(le);const Ut={...le,command:"toggleBulletListStyle"};e.emitCommand({item:Ut,argument:kt})};return Dr(Bk,{buttons:LN,iconSize:25,selectedStyle:le.selectedValue.value,onSelect:Ke})}}]}),fe=wn({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 Ke=kt=>{ps(fe);const Ut={...fe,command:"toggleOrderedListStyle"};e.emitCommand({item:Ut,argument:kt})};return Dr(Bk,{buttons:DN,iconSize:30,selectedStyle:fe.selectedValue.value,onSelect:Ke})}}]}),Ne=wn({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),he=wn({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ge=wn({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ae=wn({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:Ke})=>{Ke&&(ae.label.value=Ke)}}),_e=wn({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:Ke})=>{Ke&&(_e.label.value=Ke)}}),oe=wn({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Te=wn({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),Ge=wn({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),Je=wn({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),_t=wn({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),be=wn({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),Ve=(Ke,kt)=>Ke==="editor"?kt:Ke==="suggester"?kt.filter(Ut=>Ut.value==="suggesting"):kt.filter(Ut=>Ut.value==="viewing"),Le=Ke=>Ke==="editor"?"Editing":Ke==="suggester"?"Suggesting":"Viewing",J=wn({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:Le(s),label:Le(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:()=>$(J)}]}),_=[{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 $(Ke){return Dr(UN,{options:Ve(s,_),onSelect:kt=>{const Ut=e.superdoc?.activeEditor??e.activeEditor;ps(Ke);const{label:Ft,icon:Ot,value:hn}=kt;J.label.value=Ft,J.icon.value=Ot,e.emitCommand({item:J,argument:hn}),P0(e,Ut)}})}const F=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),j=["search","ruler","undo","overflow","documentMode"],V=wn({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),G=wn({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),Z=wn({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 Ke=Ut=>{ps(Z);const Ft=typeof Ut=="string"?Ut:Ut?.id??null;if(!Ft)return;const Ot={...Z,command:"setLinkedStyle"};e.emitCommand({item:Ot,argument:Ft})},kt=e.getActiveLinkedStyleId?.()??null;return Dr("div",{},[Dr(WN,{styles:e.getLinkedStyleOptions?.()??[],onSelect:Ke,selectedOption:kt})])}}],onActivate:({styleId:Ke,styleName:kt})=>{const Ut=kt||Ke;Z.label.value=Ke&&Ke!=="Normal"?String(Ut):n.formatText,Z.disabled.value=!1},onDeactivate:()=>{Z.disabled.value=!0,Z.label.value=n.formatText}}),W=(Ke,kt)=>{if(kt.value==Ke)return Dr("div",{innerHTML:Sz,class:"dropdown-select-icon"})},K=wn({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(Ke=>({label:Ke.toFixed(2),key:Ke,icon:()=>W(Ke,K.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),ue=20,we=32,Ce=j.reduce((Ke,kt)=>Ke+(F.get(kt)||F.get("default")),0),xe=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],ot=["zoom","fontFamily","fontSize","redo"],tt=i<=_f.lg,Ct=e.config?.showFormattingMarksButton===!0,Kt=e.config?.showTableOfContentsButton===!0;tt&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),tt&&(Z.attributes.value={...Z.attributes.value,className:`${Z.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let pt=[oe,Te,Ge,Je,T,ae,c,g,p,g,l,k,w,S,C,y,g,R,B,...Kt?[z]:[],X,N,g,Y,le,fe,Ne,he,K,g,Z,g,V,_e,...Ct?[G]:[],be,_t,...Az(e)?[d]:[],ge,J];if(i<=_f.md&&o&&(pt=pt.filter(Ke=>Ke.type!=="separator")),e.config.mode!=="docx"){const Ke=pt.findIndex(Ut=>Ut.name.value==="linkedStyles");pt.splice(Ke-1,2);const kt=["ruler","zoom","undo","redo"];pt=pt.filter(Ut=>!kt.includes(Ut.name.value))}const Mt=[];a||(s==="viewer"&&Mt.push(Ge,Je),pt=pt.filter(Ke=>!Mt.includes(Ke)));const zt=Ke=>j.includes(Ke.name.value),ln=[],$n=[];let Ht=we+Ce;return pt.forEach(Ke=>{const kt=F.get(Ke.name.value)||F.get("default");if(i<_f.xl+ue&&xe.includes(Ke.name.value)&&o){if(ln.push(Ke),Ke.name.value==="linkedStyles"){const Ut=pt.findIndex(Ft=>Ft.name.value==="linkedStyles");pt.splice(Ut+1,1)}return}if(i<_f.sm&&ot.includes(Ke.name.value)&&o){ln.push(Ke);return}if(zt(Ke)){$n.push(Ke),Ht+=kt;return}Ht<i||!o?($n.push(Ke),Ht+=kt):ln.push(Ke)}),{defaultItems:$n,overflowItems:ln.filter(Ke=>Ke.type!=="separator")}},Uk={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"},xz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;It();function Vk(e){return tB(e)??D0[e]??null}function Yp(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 Tz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Rz=new Set(["list","numberedlist"]);function Mz(e,t){if(e==="fontFamily"||e==="fontSize"||Rz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Tz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function jk(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Lz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var Dz=class extends Rm.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...Zn},texts:{...Uk},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={...Zn,...e.icons},this.config.texts={...Uk,...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._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=xz(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.#u(),this.#l(),this.#s(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Bl(AN),this.app.directive("click-outside",Dv),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.#D():this.#k()}))}#i(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#k();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#s(){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.#m()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#a(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#u(){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}#d(e){return e||wN(this.superdoc?.fonts?.getFontFamilyOptions?.()??[])}#l(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=Ez({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#d(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=o.map(l=>this.#f(l));o.length&&n.push(...i);let s=[...n.map(l=>l.name.value),...r.map(l=>l.name.value)];if(t){const l=Object.values(this.config.groups).flatMap(d=>d),u=new Set(Object.keys(this.config.groups)),c=i.filter(d=>u.has(d.group?.value||"center")).map(d=>d.name.value);s=[...new Set([...l,...c])]}const a=n.filter(l=>s.includes(l.name.value)).filter(l=>!this.config.excludeItems.includes(l.name.value));if(t)for(const[l,u]of Object.entries(this.config.groups))for(const c of a)u.includes(c.name.value)&&(c.group.value=l);this.toolbarItems=a,this.overflowItems=r.filter(l=>s.includes(l.name.value))}#f(e){const t=wn({...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}#m(){this.#l(),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.#r().find(t=>t.name.value===e)}#r(){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.#m()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#l(),this.updateToolbarState()};#p(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#y(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#w(){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)}#_(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>O0(this,e,[],!0)};e.nestedOptions.value=[t]}#S(e){return!!e?.active&&e?.value==null}#E(e){return!!e&&e.disabled===!1&&e.value==null}#x(e){const t=e.name.value;if(t==="tableActions"){const i=Fk.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(M0(t)?.disposition==="host-routed")return e.setDisabled(!this.#y(t)),this.#p(t)?e.activate():e.deactivate(),!0;const n=Vk(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];Mz(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.#w()},link:()=>{e.active.value=!!r?.active,e.attributes.value=F0(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#E(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#S(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.#w(),this.#_();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#M(),this.#r().forEach(n=>{n.allowWithoutEditor?.value&&this.#x(n)})):this.#r().forEach(n=>{n.resetDisabled(),this.#x(n)});const t=this.getToolbarItemByName("copyFormat");t&&(this.snapshot?.copyFormatActive?t.activate():t.deactivate()),this.emit("toolbar-state-change")}#M(){this.#r().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#c(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}#L(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#g(i,n)};if(n==="image"&&t==null)return this.#T();if(n==="tableActions"){const i=Ok[t?.command];return i?Yp(this.ui,i,void 0,r):!1}if(M0(n)?.disposition==="unsupported")return!0;const o=Vk(n);return o?Yp(this.ui,o,t,r):!1}#T(){return this.snapshot?.commands?.image?.disabled||(this.#t||(this.#t=lB({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await sB(e,this.superdoc?.config?.handleImageUpload);Yp(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#g(n,"image")})},onError:e=>this.#g(e,"image")})),this.#t.open()),!0}#D(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{jk(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!jk(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Lz(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)}}#k(){this.#n&&(this.#n(),this.#n=null)}#g(e,t){const n=e instanceof Error?e:new Error(String(e));this.emit("exception",{error:n,originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null})}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(M0(r)?.disposition==="host-routed"){this.#c(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(!Yp(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#g(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#L(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#g(s,r)}}}destroy(){this.#k(),this.#t?.destroy(),this.#t=null,this.#a(),this.#i(),this.app?.unmount(),this.app=null,this.toolbar=null}};function Pz(e){return new Dz(e)}function Oz(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 Fz(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=Xp(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=Nz(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=Bz(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=zz(e.border);return i&&(t.border=i),t}function Xp(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function Bz(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 Nz(e){if(!e)return;const t={},n=Xp(e.fill);n!=null&&(t.fill=n);const r=Xp(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function zz(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=Xp(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function Ql(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}function Gk(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function Hz(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 Gk(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function Wk(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=Hz(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const m of a){const p=`trackedChange:${m}`;if(!r.has(p)){r.add(p);const g={type:"trackedChange",id:m};l&&(g.storyKey=l),n.push(g),o.push(g)}}const u=s.getAttribute("data-layout-story");if(u&&o.length>0){for(const m of o)m.story=u;o=[]}const c=s.getAttribute("data-comment-ids");if(c)for(const m of Gk(c)){const p=`comment:${m}`;r.has(p)||(r.add(p),n.push({type:"comment",id:m}))}const d=s.getAttribute("data-sdt-type"),h=s.getAttribute("data-sdt-id");if(h&&d==="structuredContent"){const m=`contentControl:${h}`;if(!r.has(m)){r.add(m);const p=s.getAttribute("data-sdt-scope"),g=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:h};(p==="block"||p==="inline")&&(k.scope=p),g&&(k.tag=g),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}const B0={PAGE:"superdoc-page",FRAGMENT:"superdoc-fragment",LINE:"superdoc-line",INLINE_SDT_WRAPPER:"superdoc-structured-content-inline",INLINE_SDT_LABEL:"superdoc-structured-content-inline__label",BLOCK_SDT:"superdoc-structured-content-block",BLOCK_SDT_LABEL:"superdoc-structured-content__label",TABLE_FRAGMENT:"superdoc-table-fragment",DOCUMENT_SECTION:"superdoc-document-section",SDT_GROUP_HOVER:"sdt-group-hover",TOC_ENTRY:"superdoc-toc-entry",TOC_GROUP_HOVER:"toc-group-hover",IMAGE_FRAGMENT:"superdoc-image-fragment",INLINE_IMAGE:"superdoc-inline-image",LIST_MARKER:"superdoc-list-marker",INLINE_IMAGE_CLIP_WRAPPER:"superdoc-inline-image-clip-wrapper",ANNOTATION:"annotation",ANNOTATION_CONTENT:"annotation-content",ANNOTATION_CARET_ANCHOR:"annotation-caret-anchor"},Sj=[B0.INLINE_SDT_LABEL,B0.BLOCK_SDT_LABEL],Kk={PM_START:"data-pm-start",PM_END:"data-pm-end",LAYOUT_EPOCH:"data-layout-epoch",TABLE_BOUNDARIES:"data-table-boundaries",SDT_ID:"data-sdt-id",SDT_TYPE:"data-sdt-type",FIELD_ID:"data-field-id",FIELD_TYPE:"data-field-type",DRAGGABLE:"data-draggable",DISPLAY_LABEL:"data-display-label",VARIANT:"data-variant",TYPE:"data-type",LAYOUT_BOUNDARY_SCHEMA:"data-layout-boundary-schema",LAYOUT_FRAGMENT_ID:"data-layout-fragment-id",LAYOUT_STORY:"data-layout-story",LAYOUT_BLOCK_REF:"data-layout-block-ref"},Uz=e=>{if(!e)return{kind:"unknown"};if(e==="body")return{kind:"body"};const t=e.indexOf(":"),n=t===-1?e:e.slice(0,t),r=t===-1?void 0:e.slice(t+1);switch(n){case"body":case"header":case"footer":case"footnote":case"endnote":case"textbox":return r?{kind:n,id:r}:{kind:n};default:return{kind:"unknown"}}},kj=`.${B0.BLOCK_SDT}[${Kk.SDT_ID}]`,Aj=`[${Kk.DRAGGABLE}="true"]`;var io=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),Za=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),du=()=>({oneOf:[{type:"number"},{type:"null"}]}),fu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),Vz={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},jz={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},Gz=()=>({oneOf:[{type:"boolean"},{type:"null"},Vz]}),Wz=()=>({oneOf:[{type:"array",items:jz,minItems:1},{type:"null"}]});function Qp(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function Kz(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var N0=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:Qp(n),schema:io()}),Zl=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:Qp("textStyle",o??e),schema:r}),Ln=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:Kz(o??e),schema:r});const Zp=[N0("bold","w:b","bold"),N0("italic","w:i","italic"),N0("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:Qp("underline"),schema:Gz()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:Qp("highlight"),schema:Za()},Zl("color","string","w:color",Za()),Zl("fontSize","number","w:sz",du()),Zl("fontFamily","string","w:rFonts",Za()),Zl("letterSpacing","number","w:spacing",du()),Zl("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),Zl("position","number","w:position",du()),Ln("dstrike","boolean","w:dstrike",io()),Ln("smallCaps","boolean","w:smallCaps",io()),Zl("caps","boolean","w:caps",io(),"textTransform"),Ln("shading","object","w:shd",fu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("border","object","w:bdr",fu({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"),Ln("outline","boolean","w:outline",io()),Ln("shadow","boolean","w:shadow",io()),Ln("emboss","boolean","w:emboss",io()),Ln("imprint","boolean","w:imprint",io()),Ln("charScale","number","w:w",du(),"w"),Ln("kerning","number","w:kern",du(),"kern"),Ln("vanish","boolean","w:vanish",io()),Ln("webHidden","boolean","w:webHidden",io()),Ln("specVanish","boolean","w:specVanish",io()),Ln("rtl","boolean","w:rtl",io()),Ln("cs","boolean","w:cs",io()),Ln("bCs","boolean","w:bCs",io(),"boldCs"),Ln("iCs","boolean","w:iCs",io(),"italicCs"),Ln("eastAsianLayout","object","w:eastAsianLayout",fu({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"}]}})),Ln("em","string","w:em",Za()),Ln("fitText","object","w:fitText",fu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("snapToGrid","boolean","w:snapToGrid",io()),Ln("lang","object","w:lang",fu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Ln("oMath","boolean","w:oMath",io()),Ln("rStyle","string","w:rStyle",Za(),"styleId"),Ln("rFonts","object","w:rFonts",fu({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"),Ln("fontSizeCs","number","w:szCs",du()),Ln("ligatures","string","w14:ligatures",Za()),Ln("numForm","string","w14:numForm",Za()),Ln("numSpacing","string","w14:numSpacing",Za()),Ln("stylisticSets","array","w14:stylisticSets",Wz()),Ln("contextualAlternates","boolean","w14:cntxtAlts",io())],Ij=new Set(Zp.map(e=>e.key)),qz=Object.fromEntries(Zp.map(e=>[e.key,e])),Ej={mark:Zp.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:Zp.filter(e=>e.storage==="runAttribute").map(e=>e.key)};var Yz=new Set(Object.values(at));function z0(e,t){return typeof e=="string"&&Yz.has(e)?e:t}function qk(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:at.notReady}:{ok:!1,reason:z0(t,at.targetUnresolved)}}return{ok:!0}}var Xz=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],Qz={[kk.bulletList]:"bullet",[kk.numberedList]:"ordered"};function Yk(e){return Qz[e]??null}var Zz={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 Jz(e){const t=Zz[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var $z={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""};const eH=[{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: body tracked-changes list; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: all-story tracked-changes list; consumers already fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}];var tH=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function nH(e){return eH.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var Xk={ready:0,stale:1,pending:2};function hu(...e){let t="ready";for(const n of e)Xk[n]>Xk[t]&&(t=n);return t}function Tt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Or(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function gr(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 ar(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Sf(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 H0(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function xo(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 Jp(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=H0(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 Ja(e,t,n){return Hn(e)!==t?!1:n?xo(Jp(e))===xo(n):!0}function Qk(e){const t=Jp(e);if(!(!t||xo(t)===xo(null)))return t}function rH(e){if(typeof e!="string"||e.length===0)return;const t=Uz(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 oH(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 U0(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function $p(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function iH(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 Hn(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 sH(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 Zk=new WeakMap;function aH(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 u=s.replacement;if(u&&typeof u=="object")for(const d of[u.inserted,u.deleted])d&&typeof d=="object"&&(n(d.id),n(d.wordId));const c=s.move;if(c&&typeof c=="object")for(const d of[c.source,c.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 em(e){const t=Zk.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=Hn(i);if(s){n.add(s);for(const a of aH(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 Zk.set(e,o),o}var Jk=new WeakMap;function $k(e,t){const n=xo(t);let r=Jk.get(e);r||(r=new Map,Jk.set(e,r));const o=r.get(n);if(o)return o;const i=em(e.filter(s=>xo(Jp(s))===n));return r.set(n,i),i}function lH(e,t){const n=e.find(r=>Hn(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??Hn(n)??t:null}function cH(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,u=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:u??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 Rr(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 uH=64;function Jl(e){return e.length<=uH}function na(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 mo(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function ra(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function eA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var tA=720;function ms(e){return Math.round(e*20)}function pu(e){return typeof e=="number"&&Number.isFinite(e)}function dH(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=pu(i.left)?ms(i.left):pu(i.start)?ms(i.start):void 0,a=pu(i.right)?ms(i.right):pu(i.end)?ms(i.end):void 0,l=pu(i.firstLine)?ms(i.firstLine):void 0,u=pu(i.hanging)?ms(i.hanging):void 0;return s==null&&a==null&&l==null&&u==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...u!=null?{hanging:u}:{}}}function V0(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 fH(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 kf(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 $a(e){return kf(e.target)??kf(e.selectionTarget)}var nA=["fontFamily","fontSize","color","highlight"],hH={undo:"history.undo",redo:"history.redo"},Af=["bold","italic","underline","strikethrough"];function j0(e){return nA.includes(e)}function mu(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,u,c)=>{typeof l!="string"||typeof u!="number"||typeof c!="number"||r.push({blockId:l,start:Math.min(u,c),end:Math.max(u,c)})};for(const l of n){const u=l?.range;o(l?.blockId,u?.start,u?.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 oa(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 pH(e){const t=oa(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 ia(e){const t=mu(e);return t.length===0?null:[pH(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function rA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:Ql({selectionTarget:t})}function mH(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 gH(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function vH(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 yH(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 oA(e,t){const n=mu(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=>yH(n,vH(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 bH(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 G0(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 wH(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 CH(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function iA(e,t){if(!e)return{};const n=new Map;for(const i of mu(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 nA){const s=new Map;let a=!1,l=!1;for(const u of r){const c=typeof u?.blockId=="string"?u.blockId:null;if(!c)continue;const d=n.get(c);if(!d?.length)continue;const h=Array.isArray(u?.runs)?u.runs:[];for(const m of h){const p=m?.range,g=typeof p?.start=="number"?p.start:null,k=typeof p?.end=="number"?p.end:null;if(g==null||k==null||!d.some(y=>gH(y,{start:g,end:k})))continue;a=!0;const w=bH(m?.styles,i);if(w===void 0){l=!0;continue}const S=CH(i,w);if(s.has(S)||s.set(S,w),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function W0(e,t){const n=Rr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:mo(n)}:{kind:"documentEnd"}}function tn(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 $l(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 tm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function el(e){if(Or(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 nm(e){return!!e&&typeof e=="object"&&e.success===!0}function No(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function gu(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function K0(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 u of l.blocks)n(u);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function ec(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function fi(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!No(i)&&n===null&&(n=i),nm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function _H(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 SH(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function rm(e){return uu(e)?.trackDecision??null}function kH(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function tl(e){return{found:!1,success:!1,rects:[],reason:e}}function AH(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 IH(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 sA(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(IH))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 EH(e){return e.selectionTarget?e.selectionTarget:sA(e.target)}function vu(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=sA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function q0(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var Y0={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},xH=Object.fromEntries(Object.entries(Y0).filter(([e])=>qz[e]?.tracked===!0));function TH(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:{...Y0}};default:return null}}function RH(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 MH(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 LH(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,u=!1,c=Promise.resolve(),d=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},m=0;const p=new Set;let g={},k="",w=null;const S=()=>{const f=t?.activeEditor;return f&&typeof f=="object"?f:null},y=()=>{const f=S()?.doc;return f&&typeof f=="object"?f:null},C=()=>{const f=S()?.v2TrackedChanges;return f&&typeof f=="object"?f:null},T=()=>{const f=S()?.host;return f&&typeof f=="object"?f:null},R=f=>{if(f.storyType!=="headerFooterPart"||typeof f.refId!="string")return null;const v=S(),b=T(),A=v?.pageLayout??b?.pageLayout;if(!A||typeof A!="object")return null;const E=A.getActiveRulerContext,U=b?.resolveHeaderFooterEditTarget;if(typeof E!="function"||typeof U!="function")return null;const Q=Tt(()=>E.call(A),null);if(!Q||typeof Q.pageIndex!="number")return null;for(const re of["header","footer"]){const ye=Tt(()=>U.call(b,{pageIndex:Q.pageIndex,kind:re}),null);if(!(ye?.status!=="ready"||ye.refId!==f.refId||typeof ye.sectionId!="string"||!["default","first","even"].includes(String(ye.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:ye.sectionId},headerFooterKind:re,variant:ye.slotVariant}}return null},M=()=>{const f=T(),v=f?.getPendingInlineFormat;if(typeof v!="function")return null;const b=Tt(()=>v.call(f),null);return b&&typeof b=="object"?b:null},H=f=>{const v=q0(f);if(!v)return null;const b=M();if(!b||!(v in b))return null;const A=b[v];return f.inline?.kind==="toggle"?A===!0:A!=null&&A!==""},B=f=>{const v=q0(f);if(!v)return;const b=M();if(!b||!(v in b))return;const A=b[v];if(typeof A=="string"&&A!=="")return A;if(typeof A=="number"&&Number.isFinite(A))return String(A)},z=(f,v)=>{const b=T(),A=b?.setPendingInlineFormat;typeof A=="function"&&Tt(()=>A.call(b,f,v),void 0)},X=f=>{const v=T(),b=v?.clearPendingInlineFormat;typeof b=="function"&&Tt(()=>b.call(v,f),void 0)},P=new Set(["bold","italic","underline","strikethrough"]),N=f=>{const v=M();if(!v)return;const b=Array.isArray(f.activeMarks)?f.activeMarks:[];let A=null;for(const E of Object.keys(v)){const U=v[E];let Q;if(P.has(E))Q=b.includes(E)===(U===!0);else if(j0(E)){if(U==null)continue;A||(A=pl(f)),Q=A[E]===U}else Q=!1;Q&&X(E)}},I=()=>{const f=S()?.editCommands;return f&&typeof f=="object"?f:null},L=f=>{const v=I();if(!v||typeof v.getSnapshot!="function")return null;const b=Tt(()=>v.getSnapshot(),null)?.commands?.[f];return b&&typeof b=="object"?b:null},Y=()=>L("lists.apply"),te=f=>{const v=f?.value?.seed;return v==="bullet"||v==="ordered"?v:null},le=f=>{const v=hH[f];return v?L(v):null},fe=()=>{const f=T();if(!f||typeof f.getTableContext!="function")return null;const v=Tt(()=>f.getTableContext(),null);return v&&typeof v=="object"?v:null},Ne=()=>{const f=fe();if(!f||f.inTable!==!0)return null;const v=f.table,b=typeof v?.nodeId=="string"&&v.nodeId.length>0?v.nodeId:null;if(!b)return null;const A=f.row,E=f.column,U=f.cell,Q=typeof A?.index=="number"&&Number.isInteger(A.index)?A.index:null,re=typeof E?.index=="number"&&Number.isInteger(E.index)?E.index:null;if(Q==null||re==null)return null;const ye=typeof U?.nodeId=="string"&&U.nodeId.length>0?U.nodeId:null,Re=f.cellRange;return{tableNodeId:b,rowIndex:Q,columnIndex:re,cellNodeId:ye,mergeRange:RH(Re)}},he=new Map;let ge=null,ae=null,_e=0,oe=0;const Te=(f,v)=>f===v?!0:!f||!v?!1:f.id===v.id&&f.paintedEntityId===v.paintedEntityId&&xo(f.story)===xo(v.story),Ge=f=>{const v=T();if(typeof v?.getHandles!="function")return;const b=Tt(()=>v.getHandles(),null),A=b?.review;if(A){if(f){if(typeof A.setActiveReviewTarget!="function")return;const E=b?.layout;Tt(()=>A.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 A.getActiveReviewTarget!="function"||typeof A.clearActiveReviewTarget!="function"||Tt(()=>A.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Tt(()=>A.clearActiveReviewTarget(),void 0)}},Je=(f,v)=>{ae=f,_e+=1,v?.invalidateQueuedNavigation!==!1&&(oe+=1)},_t=new Set;let be=!1,Ve=null;const Le=new Map,J=new Set;let _=null,$=null,F=!1,j=null,V=0,G=null,Z=null,W=null;const K=()=>{if(F||be)return;F=!0;const f=()=>{F=!1,be||jt()};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},ue=250,we=5e3,Ce=f=>{be||j&&V<=f||(j&&clearTimeout(j),V=f,j=setTimeout(()=>{j=null,V=0,be||jt()},Math.max(0,f-Date.now())))},xe=new WeakMap;let ot=0;const tt=f=>{if(!f)return"none";let v=xe.get(f);return v==null&&(v=ot+=1,xe.set(f,v)),`e${v}`};let Ct=0,Kt={},pt=null,Mt=null,zt=0;const ln=()=>{Mt&&clearTimeout(Mt),Mt=null,zt=0};let $n=f=>{},Ht=null,Ke=new Set,kt=0,Ut=null;const Ft=()=>`${tt(S())}|m${Ct}`,Ot=()=>{Ht=null,Ke=new Set},hn=f=>{for(const v of["trackChanges","trackChanges:all"]){const b=Le.get(v);if(!b?.hasSettled||!Array.isArray(b.value))continue;const A=b.value.filter(E=>{const U=Hn(E);return!U||!f.has(U)});A.length!==b.value.length&&Le.set(v,{...b,value:A})}},yn=f=>{const v=()=>{if(!be)for(const U of[..._t])U(bt)},b=gu(f)?f:null,A=S()?.documentMutationReadiness,E=()=>{const U=globalThis.requestAnimationFrame;return typeof U!="function"?Promise.resolve():new Promise(Q=>{let re=!1;const ye=()=>{re||(re=!0,clearTimeout(Re),Q())},Re=setTimeout(ye,250);U(()=>U(()=>setTimeout(ye,0)))})};if(b?.success===!0&&typeof b.txId=="string"&&b.txId.length>0&&typeof A?.whenPainted=="function")try{Promise.resolve(A.whenPainted.call(A,b)).then(E,()=>{}).then(v,v);return}catch{}v()},De=(f,v)=>{const b=bt.trackChanges,A=b.items.filter(Q=>{const re=Hn(Q);return!re||!f.has(re)});if(A.length===b.items.length)return;ae&&f.has(ae.id)&&Je(null);const E=new Set;for(const Q of A){const re=tm(Q),ye=Q,Re=re.author??re.authorEmail??ye.author??ye.authorEmail;typeof Re=="string"&&E.add(Re)}const U=b.items.length-A.length;bt={...bt,trackChanges:{...b,items:A,total:Math.max(A.length,b.total-U),activeId:b.activeId&&f.has(b.activeId)?null:b.activeId,authors:[...E]}},yn(v)},Oe=(f,v)=>{if(f.size===0)return;const b=Ft(),A=Ht===b?Ke:new Set,E=new Set([...f].filter(U=>!A.has(U)));E.size!==0&&(Ht=b,Ke=new Set([...A,...E]),hn(Ke),De(E,v))},Qe=f=>Ht===f&&Ke.size>0?Ke:null,nt=(f,v=[])=>{const b=f.map($l).filter(E=>E!=null&&Hn(E)!=null);if(b.length===0)return;const A=v.map($l).map(E=>E==null?null:Hn(E)).filter(E=>E!=null);for(const E of["trackChanges","trackChanges:all"]){const U=Le.get(E),Q=U?.hasSettled&&Array.isArray(U.value)?[...U.value]:[],re=new Set;let ye=!1;for(const Re of b){const ze=Hn(Re);if(!ze)continue;const Ye=Q.findIndex(Be=>Hn(Be)===ze);if(Ye<0)Q.push(Re),re.add(ze);else{const Be=Q[Ye];Q[Ye]=gu(Be)?{...Be,...Re}:Re}ye=!0}if(E==="trackChanges"&&re.size>0&&A.length>0){const Re=new Set(A.filter(Be=>re.has(Be))),ze=new Map(Q.filter(Be=>Re.has(Hn(Be)??"")).map(Be=>[Hn(Be),Be])),Ye=Q.filter(Be=>!Re.has(Hn(Be)??""));for(const[Be,Ze]of A.entries()){if(!Re.has(Ze))continue;const He=ze.get(Ze);if(!He)continue;const Ue=A.slice(Be+1).map(rt=>Ye.findIndex($e=>Hn($e)===rt)).find(rt=>rt>=0);if(Ue!=null){Ye.splice(Ue,0,He);continue}const je=A.slice(0,Be).reverse().map(rt=>Ye.findIndex($e=>Hn($e)===rt)).find(rt=>rt>=0);Ye.splice(je==null?Ye.length:je+1,0,He)}Q.splice(0,Q.length,...Ye)}ye&&Le.set(E,{token:U?.token??null,value:Q,hasSettled:!0,inflightToken:null})}},Dt=f=>{const v=Ft(),b=Qe(v),A=f.map($l).filter(E=>{if(E==null)return!1;const U=Hn(E);return U!=null&&!b?.has(U)});for(const E of["trackChanges","trackChanges:all"])Le.set(E,{token:v,value:[...A],hasSettled:!0,inflightToken:null})},Et=async(f,v)=>{try{const b=f.v2TrackedChanges?.listTrackedChanges;if(typeof b=="function"){const U=await Promise.resolve(b.call(f.v2TrackedChanges,{mode:v.trackedChangesListMode,refreshReason:v.refreshReason,blocking:v.blocking,...v.targetIds?.length?{targetIds:v.targetIds}:{}})),Q=v.trackedChangesListMode==="all"&&v.refreshReason==="mutation-history-render-reconcile"?U?.ok===!0:U?.ok!==!1;return{ok:Q,items:Q&&Array.isArray(U?.items)?U.items:[],...typeof U?.complete=="boolean"?{complete:U.complete}:{},...typeof U?.sourceCoverageComplete=="boolean"?{sourceCoverageComplete:U.sourceCoverageComplete}:{}}}const A=f.docTrackChanges?.list;if(typeof A!="function")return{ok:!1,items:[]};const E=await Promise.resolve(A.call(f.docTrackChanges));return{ok:!0,items:Array.isArray(E?.items)?E.items:[]}}catch(b){return{ok:!1,items:[],failures:[b]}}},Yt=w_({getContext:()=>{const f=S();if(!f)return null;const v=C(),b=y()?.trackChanges??null,A=v??b;if(!A)return null;const E=f.documentId??v?.documentId;return{editor:f,adapter:A,documentId:E==null?null:String(E),reconcileToken:Kt,v2TrackedChanges:v,docTrackChanges:b}},reconcile:async(f,v)=>{v.removedIds.size>0&&Oe(new Set(v.removedIds));const b=[...new Set(v.upsertIds)];if(b.length===0)return{ok:!0,items:[],resolvedIds:[],unresolvedIds:[]};const A=Le.get("trackChanges"),E=A?.hasSettled&&Array.isArray(A.value)?A.value:null,U=new Set(E?E.map(Hn).filter(je=>je!=null):[]),Q=E?.length===0&&Vn()==="complete",re=new Set(b.filter(je=>!U.has(je))),ye=f.v2TrackedChanges?.getTrackedChange,Re=f.docTrackChanges?.get;if(typeof ye!="function"&&typeof Re!="function")return{ok:!1,items:[],resolvedIds:[],unresolvedIds:b};const ze=await Promise.all(b.map(async je=>{try{if(typeof ye=="function"){const $e=await Promise.resolve(ye.call(f.v2TrackedChanges,je));return{id:je,ok:$e?.ok!==!1,items:$e?.ok!==!1&&Array.isArray($e?.items)?$e.items:[],result:$e}}const rt=await Promise.resolve(Re.call(f.docTrackChanges,{id:je}));return{id:je,ok:!0,items:rt&&typeof rt=="object"?[rt]:[],result:rt}}catch(rt){return{id:je,ok:!1,items:[],result:rt}}})),Ye=[],Be=[],Ze=[];for(const je of ze){const rt=je.items.filter($e=>{const Bt=$l($e);return Bt!=null&&Hn(Bt)===je.id});je.ok&&rt.length>0?(Ye.push(...rt),Be.push(je.id)):Ze.push(je.id)}let He;const Ue=Be.filter(je=>re.has(je));if(Ue.length>0&&!Q){const je=await Et(f,{trackedChangesListMode:"interaction-prime",refreshReason:"mutation-render-reconcile",blocking:!1,targetIds:Ue});je.ok&&(He=je.items)}return{ok:Ze.length===0,items:Ye,orderedItems:He,resolvedIds:Be,unresolvedIds:Ze,failures:ze.filter(je=>!je.ok).map(je=>je.result)}},hydrate:Et,onReconciled:(f,v,b)=>{if(b?.reconcileMode==="authoritative"){if(f.reconcileToken!==Kt)return;b.ok===!0&&b.complete===!0&&b.sourceCoverageComplete===!0?(ln(),Dt(b.items??[]),pt=null):b.ok===!0?(ln(),nt(b.items??[])):$n(f.reconcileToken),jt();return}nt((b?.items??[]).filter(A=>{const E=$l(A),U=E==null?null:Hn(E);return U!=null&&v.has(U)}),b?.orderedItems??b?.items??[]),jt()}});$n=f=>{if(be||Mt)return;const v=Math.min(ue*2**zt,we);zt+=1,Mt=setTimeout(()=>{Mt=null,!(be||pt===null||f!==Kt)&&Yt.onRender(!0)},v)};const xt=()=>`${Ft()}|m${br()}|s${kt}`,Un=f=>JSON.stringify({t:f.target??null,s:f.selectionTarget??null}),so=["contentControls:inRange:","query:","effInline:"],zo=120,rn=180,Vn=()=>{const f=T(),v=f?.getDocumentLoadingSnapshot;if(typeof v!="function")return"unknown";const b=Tt(()=>v.call(f),null)?.sourceStage;return b==="opening"||b==="ready-window"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},lr=new Map,yr=f=>{const v=Ft();lr.get(f)!==v&&(lr.set(f,v),K())},To=()=>{const f=Le.get("comments");return f?.hasSettled?Array.isArray(f.value)&&f.value.length>0:f?.inflightToken!=null},$t=(f,v)=>lr.get(f)===v,cn=f=>{yr("contentControls")},Fr=()=>{const f=Le.get("trackChanges");f?.hasSettled||f?.inflightToken!=null||yr("trackChanges")},go=6500,nl=8e3,sa=250;let rl=0,gs=0,Ho=!1,$o=0,hi=!1,qr=null;const Ee=()=>{if(be||qr)return;const f=$o||Date.now(),v=()=>{if(qr=null,be)return;const b=Date.now()-rl,A=bn()||b<go;if(A&&Date.now()-f<nl){qr=setTimeout(v,sa);return}Ho=!1,hi=A;try{jt()}finally{hi=!1,$o=0}};qr=setTimeout(v,0)};let Fe=null,ft=null;const lt=()=>{const f=T();if(!f||Fe===f)return;ft&&(ft(),ft=null),Fe=f;const v=f.subscribeDocumentLoading;if(typeof v!="function"){Fe=null,cr(go);return}try{const b=U=>{const Q=U?.sourceStage;(Q==="source-complete"||Q==="source-failed"||Q==="source-cancelled")&&Ee()},A=v.call(f,b);typeof A=="function"&&(ft=A);const E=f.getDocumentLoadingSnapshot;typeof E=="function"&&b(Tt(()=>E.call(f),null))}catch{Fe=null,cr(go)}},Cn=()=>{const f=S()?.host,v=f?.getForegroundMutationState;if(typeof v!="function")return null;const b=Tt(()=>v.call(f),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},bn=()=>{const f=Cn();return!!(f&&(f.active>0||f.pending>0))},cr=(f=zo)=>{be||G||(G=setTimeout(()=>{if(G=null,be)return;if(Z&&bn()){cr(),jt();return}const v=Z;Z=null,v===xt()&&Ro("selection",v,cl,Ri),jt()},f))},Uo=(f,v)=>{if(!Cn())return!1;const b=`${f}\0${v}`;return J.has(b)?!1:(J.add(b),cr(rn),!0)},pi=f=>{if(_==null||f===_)return $?.timer&&clearTimeout($.timer),$=null,_=f,!1;if($?.key===f)return $.ready?($=null,_=f,!1):!0;$?.timer&&clearTimeout($.timer);const v={key:f,ready:!1,timer:null};return v.timer=setTimeout(()=>{be||$!==v||(v.timer=null,v.ready=!0,jt())},rn),$=v,!0},Ti=f=>C_(f),ol=()=>{Xr(),jt()};let Vo=null,mi=!1,gi=0;const vo=()=>{Vo=null,mi=!1,gi+=1},Yr=()=>{const f=S(),v=f?.documentMutationReadiness;if(!f||typeof v?.whenPainted!="function"||(Vo={editor:f,readiness:v,afterEpoch:typeof v.getRenderEpoch=="function"?Tt(()=>v.getRenderEpoch.call(v),null):null},mi))return;mi=!0;const b=gi;(async()=>{for(;!be&&b===gi;){const E=Vo;if(Vo=null,!E){mi=!1;return}let U=!1;try{await E.readiness.whenPainted.call(E.readiness,typeof E.afterEpoch=="number"?{afterEpoch:E.afterEpoch}:void 0),U=!0}catch{}if(be||b!==gi)return;if(S()!==E.editor){vo();return}U&&ol()}})()},vi=()=>{W&&clearTimeout(W),W=setTimeout(()=>{W=null,be||ol()},500)},Ro=(f,v,b,A)=>{let E;try{E=b()}catch{E=void 0}if(!Or(E)){const re={token:v,value:A(E),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return Le.set(f,re),re}const U=Le.get(f),Q=U?.failedToken===v;return Le.set(f,{token:U?.token??null,value:U?.value??null,hasSettled:U?.hasSettled??!1,inflightToken:v,failedToken:Q?v:null,failureCount:Q?U.failureCount??0:0,retryAtMs:0}),Promise.resolve(E).then(re=>{const ye=Le.get(f);!ye||ye.inflightToken!==v||(Le.set(f,{token:v,value:A(re),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0}),K())},()=>{const re=Le.get(f);if(!re||re.inflightToken!==v)return;const ye=re.failedToken===v?(re.failureCount??0)+1:1,Re=Math.min(we,ue*2**Math.min(ye-1,8)),ze=Date.now()+Re;Le.set(f,{...re,inflightToken:null,failedToken:v,failureCount:ye,retryAtMs:ze}),Ce(ze)}),null},Yn=(f,v,b,A)=>{const E=Le.get(f);if(E&&E.token===v&&E.hasSettled)return{value:E.value,status:"ready"};if(nH(f)&&!$t(f,v)){if(Vn()==="loading")return Ho=!0,lt(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(Ho&&!hi)return Ee(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!hi){const Q=Date.now();if(Q-gs<go&&(!$o||Q-$o<nl))return $o||($o=Q),Ho=!0,Ee(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};$o=0}}if(bn())return cr(),E?.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(E?.failedToken===v&&E.inflightToken==null&&(E.retryAtMs??0)>Date.now())return Ce(E.retryAtMs),E.hasSettled?{value:E.value,status:"stale"}:{value:null,status:"pending"};if(!E&&f.startsWith("effInline:")&&pi(f))return{value:null,status:"pending"};if(!E&&Uo(f,v))return{value:null,status:"pending"};if(!E||E.inflightToken!==v){const Q=Ro(f,v,b,A);if(Q)return{value:Q.value,status:"ready"}}const U=Le.get(f);return U?.hasSettled?{value:U.value,status:"stale"}:{value:null,status:"pending"}},il=f=>{for(const v of Le.keys())f(v)&&Le.delete(v)},If=f=>{const v=Un(f),b=rA(f);return new Set([`contentControls:inRange:${v}`,`query:${v}`,...b?[`effInline:${b}`]:[]])},aa=f=>{const v=If(f);il(b=>so.some(A=>b.startsWith(A))&&!v.has(b));for(const b of J){const A=b.split("\0",1)[0];so.some(E=>A.startsWith(E))&&!v.has(A)&&J.delete(b)}},Mo=()=>{const f=S();f!==Ut&&(vo(),Yt.reset(),Kt={},Ut=f,Le.clear(),pt=null,ln(),j&&clearTimeout(j),j=null,V=0,$?.timer&&clearTimeout($.timer),$=null,_=null,w=null,o=null,Z=null,J.clear(),lr.clear(),Ho=!1,$o=0,ft&&ft(),ft=null,Fe=null,Ot())},Xr=()=>{const f=pt!==null;Ct+=1,f&&(pt=Ft()),Ot()},sl=f=>{if(typeof f!="string"||f.length===0)return ar("insertText requires a non-empty string.","INVALID_INPUT");if(br()==="viewing")return ar("The document is read-only.","DOCUMENT_READONLY");const v=y(),b=v?.insert;if(!v||typeof b!="function")return ar("insert is unavailable.");const A=v.selection?.current;if(typeof A!="function")return ar("selection.current is unavailable.");const E=Q=>{const re=Q&&typeof Q=="object"?Q:null,ye=re?.selectionTarget??re?.target??null;return!ye||typeof ye!="object"?ar("insertText requires a live selection target.","PRECONDITION_FAILED"):Tt(()=>ba(b.call(v,{type:"text",value:f,target:ye}),ar("insert failed.")),ar("insert failed."))};let U;try{U=A.call(v.selection)}catch{return ar("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Or(U)?Promise.resolve(U).then(E,()=>ar("insertText could not resolve the live selection.","PRECONDITION_FAILED")):E(U)},Ki=(f,v)=>({payload:f,state:bt,editor:S(),superdoc:t,context:v,ui:Ve,execute:(b,A)=>ri(b,A),executeAsync:(b,A)=>fm(b,A),doc:y(),selection:bt.selection,documentMode:br(),insertText:sl}),al=f=>f==="editing"||f==="suggesting"||f==="viewing"?f:null,br=()=>{const f=S(),v=t&&typeof t=="object"?t:null,b=al(v?.config?.documentMode),A=al(Tt(typeof v?.getActiveRuntime=="function"?()=>{const U=v.getActiveRuntime();return typeof U?.getSnapshot=="function"?U.getSnapshot():null}:void 0,null)?.documentMode),E=al(f?.options?.documentMode);return b&&A&&b!==A?b:A??b??E},yi=()=>{const f=t&&typeof t=="object"?t:null,v=f?.interactionConfig?.comments;if(v&&typeof v.readOnly=="boolean")return v.readOnly===!0;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},yu=()=>{const f=t&&typeof t=="object"?t:null,v=f?.interactionConfig?.comments;if(v&&typeof v.allowResolve=="boolean")return v.allowResolve===!1;const b=f?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},bi=()=>br()==="viewing"||yi(),Ri=f=>f&&typeof f=="object"?f:null,la=(f,v)=>{if(!f)return{...$z,status:v};const b=f.target??null,A=typeof f.text=="string"?f.text:"";return{status:v,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:A}},ll=()=>{const f=y()?.selection;return Yn("selection",xt(),()=>f?.current?f.current({includeText:!0}):void 0,Ri)},bu=()=>{const{value:f,status:v}=ll();return la(f,v)},cl=()=>{const f=y()?.selection;return f?.current?f.current({includeText:!0}):void 0},wu=f=>{if(f.empty!==!0)return!1;const v=f.selectionTarget,b=v?.start,A=v?.end;return b?.kind==="text"&&A?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===A.blockId&&typeof b.offset=="number"&&b.offset===A.offset},Cu=f=>{const v=T(),b=v?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const A=Ri(Tt(()=>b.call(v),null));if(!A||!wu(A))return;const E=xt(),U=Cn(),Q=!!(U&&(U.active>0||U.pending>0));if(Q)Z=E,cr();else if(Z=null,Ro("selection",E,cl,Ri))return;const re=Le.get("selection"),ye=Array.isArray(A.activeMarks)&&A.activeMarks.length>0?A.activeMarks:Array.isArray(bt.selection.activeMarks)?bt.selection.activeMarks:[],Re=Array.isArray(A.activeCommentIds)?A.activeCommentIds:[],ze=sH(f),Ye=$a(bt.selection),Be=kf(A.selectionTarget)??kf(A.target),Ze=Ye?.range,He=Be?.range,Ue=!!(U&&U.active>0&&Ye&&Be&&Ye.blockId===Be.blockId&&xo(Ye.story)===xo(Be.story)&&typeof Ze?.start=="number"&&typeof He?.start=="number"&&Math.abs(He.start-Ze.start)<=2),je=ze!=null||Ue?bt.selection.activeChangeIds.filter($e=>ze==null||em(bt.trackChanges.items).aliasesFor($e).includes(ze)):[],rt=Array.isArray(A.activeChangeIds)&&A.activeChangeIds.length>0?A.activeChangeIds:je;Le.set("selection",{token:E,value:{...A,activeMarks:ye,activeCommentIds:Re,activeChangeIds:rt},hasSettled:!0,inflightToken:Q?null:re?.inflightToken??null})},ca=async(f=0)=>{const v=y()?.selection,b=v?.current,A=xt();if(typeof b!="function")return Le.set("selection",{token:A,value:null,hasSettled:!0,inflightToken:null}),jt(),bt.selection;let E;try{E=b.call(v,{includeText:!0}),Or(E)&&(E=await Promise.resolve(E))}catch{E=null}return be?la(null,"pending"):xt()!==A?f<1?ca(f+1):bt.selection:(Le.set("selection",{token:A,value:Ri(E),hasSettled:!0,inflightToken:null}),jt(),bt.selection)},_u=f=>{const v=y()?.comments,{value:b,status:A}=Yn("comments",Ft(),()=>v?.list?v.list():void 0,re=>re&&Array.isArray(re.items)?re.items:[]),E=b??[],U=f.activeCommentIds;ge&&!E.some(re=>Hn(re)===ge)&&(ge=null);const Q=ge??U[0]??null;return{status:hu(A,f.status),listStatus:A,items:E,total:E.length,activeIds:U,activeId:Q}},Lo=()=>{const f=y()?.trackChanges,v=Ft(),b=Le.get("trackChanges:all"),{value:A,status:E}=pt===v?{value:b?.hasSettled?b.value:null,status:b?.hasSettled?"stale":"pending"}:Yn("trackChanges:all",v,()=>f?.list?f.list({in:"all"}):void 0,U=>(U&&Array.isArray(U.items)?U.items:[]).map($l).filter(Q=>Q!=null));return E==="ready"?A:null},ul=f=>{const v=y()?.trackChanges,b=C(),A=typeof b?.listTrackedChanges=="function"?b.listTrackedChanges:null,E=Ft(),U=Qe(E),Q=Le.get("trackChanges"),{value:re,status:ye}=pt===E?{value:Q?.hasSettled?Q.value:null,status:Q?.hasSettled?"stale":"pending"}:Yn("trackChanges",E,()=>A?A.call(b):v?.list?v.list():void 0,Ue=>Ue&&Array.isArray(Ue.items)?Ue.items.filter(je=>!A||xo(Jp(je))==="story:body"):[]),Re=(re??[]).map($l).filter(Ue=>Ue!=null).filter(Ue=>{const je=Hn(Ue);return!je||!U?.has(je)}),ze=new Set;for(const Ue of Re){const je=tm(Ue),rt=Ue,$e=je.author??je.authorEmail??rt.author??rt.authorEmail;typeof $e=="string"&&ze.add($e)}const Ye=v?.list?Lo():null,Be=ae;Be&&(Be.story?Ye&&!Ye.some(Ue=>Ja(Ue,Be.id,Be.story))&&Je(null):Re.some(Ue=>Hn(Ue)===Be.id)||Je(null));const Ze=U?f.activeChangeIds.filter(Ue=>!U.has(Ue)):f.activeChangeIds,He=ae?.id??Ze[0]??null;return{status:hu(ye,f.status),items:Re,total:Re.length,activeId:He,authors:[...ze]}},Ef=f=>{const v=y()?.contentControls,{value:b,status:A}=Yn("contentControls",Ft(),()=>v?.list?v.list():void 0,re=>re&&Array.isArray(re.items)?re.items:[]),E=b??[],{ids:U,status:Q}=dl(v,f);return{status:hu(A,Q,f.status),items:E,total:E.length,activeId:U[0]??null,activeIds:U}},vs=(f,v)=>{if(!f||typeof f.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=cH(v);if(!b)return{lockModesById:new Map,status:"ready"};const{value:A,status:E}=Yn(`contentControls:inRange:${Un(v)}`,Ft(),()=>f.listInRange(b),re=>re&&Array.isArray(re.items)?re.items:[]),U=A??[],Q=new Map;for(const re of U)typeof re?.id=="string"&&Q.set(re.id,typeof re.lockMode=="string"?re.lockMode:"unlocked");return{lockModesById:Q,status:E}},dl=(f,v)=>{const{lockModesById:b,status:A}=vs(f,v);return{ids:[...b.keys()],status:A}},Do=()=>{const f=t?.fonts;return{options:BH(OH(Tt(f?.getDocumentFontOptions?()=>f.getDocumentFontOptions():void 0,[])),FH(Tt(f?.getFontFamilyOptions?()=>f.getFontFamilyOptions():void 0,[]))),sizeOptions:NH}},qi=()=>{const f=Tt(t?.getZoomState?()=>t.getZoomState():void 0,null),v=typeof f?.value=="number"?f.value:100,b=f?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:v,min:typeof f?.min=="number"?f.min:10,max:typeof f?.max=="number"?f.max:100}},Su=()=>Tt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",ku=()=>{const f=S();return{ready:f!=null,mode:br(),dirty:f?!!f.isDirty:!1}},jo=f=>{const v=f.quotedText;if(typeof v!="string"||v.length===0)return null;const b=mu(f);if(b.length===0||!Jl(b.map(U=>U.blockId)))return null;const A=f.target,E=b.length===1?mo(b[0].blockId,A?.story):void 0;return{select:{type:"text",pattern:v,mode:"contains",caseSensitive:!0},...E?{within:E}:{},require:"any"}},ys=f=>{const v=y()?.query;if(typeof v?.match!="function")return null;const b=jo(f);if(!b)return null;const{value:A}=Yn(`query:${Un(f)}`,Ft(),()=>v.match(b),E=>E&&typeof E=="object"?E:null);return oA(A,f)},fl=f=>{const v=T(),b=new Set(Rr(f));if(b.size===0)return{};const A=v?.readMountedProjectionBlocksByIds,E=v?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof E!="function")return{};const U=Tt(()=>{if(typeof A!="function")return E.call(v);const Ue=oa(f);return Ue?A.call(v,[...b],Ue):A.call(v,[...b])},null);if(!Array.isArray(U))return{};const Q=K0(U),re=Ue=>{const je={},rt=G0(Ue.fontFamily);rt&&(je.fontFamily=rt);const $e=wH(Ue.fontSize);return $e&&(je.fontSize=$e),typeof Ue.color=="string"&&Ue.color.trim()!==""&&(je.color=Ue.color.trim().toUpperCase()),typeof Ue.highlight=="string"&&Ue.highlight.trim()!==""&&(je.highlight=Ue.highlight.trim().toUpperCase()),je},ye=$a(f),Re=ye&&typeof ye.range?.start=="number"?ye.range.start:null;if(ye&&Re!==null&&b.has(ye.blockId)){const Ue=Q.find(rt=>ec(rt,ye.blockId)),je=Ue&&Array.isArray(Ue.runs)?Ue.runs:null;if(je&&je.length>0&&je.every(rt=>rt?.kind==="text"||rt?.kind==="tab")){let rt=0,$e=null;for(const Bt of je){const Xt=typeof Bt.text=="string"?Bt.text.length:0;if(Re>=rt&&Re<rt+Xt){$e=Bt;break}rt+=Xt}if(!$e){for(let Bt=je.length-1;Bt>=0&&!$e;Bt-=1)je[Bt]?.kind==="text"&&($e=je[Bt]);$e??=je[je.length-1]??null}return $e?re($e):{}}}const ze=mu(f);if(ze.length>0){const Ue=new Set,je=new Set;let rt=!1,$e=!0;for(const Bt of ze){const Xt=Q.find(Jr=>ec(Jr,Bt.blockId));if(!Xt)return{};const Nn=Array.isArray(Xt.runs)?Xt.runs:[];if(Nn.length===0)continue;if(!Nn.every(Jr=>Jr?.kind==="text"||Jr?.kind==="tab")){$e=!1;break}let Gn=0;for(const Jr of Nn){const Vr=typeof Jr.text=="string"?Jr.text.length:0,Lr=Gn,Ar=Gn+Vr;if(Lr<Bt.end&&Ar>Bt.start){rt=!0;const Wo=re(Jr);Wo.fontFamily&&Ue.add(Wo.fontFamily),Wo.fontSize&&je.add(Wo.fontSize)}Gn=Ar}}if($e&&rt){const Bt={};return Ue.size===1&&(Bt.fontFamily=[...Ue][0]),je.size===1&&(Bt.fontSize=[...je][0]),Bt}}const Ye=new Set,Be=new Set;let Ze=!1;for(const Ue of Q){if(![...b].some(rt=>ec(Ue,rt)))continue;const je=Array.isArray(Ue.runs)?Ue.runs:[];for(const rt of je){if(rt?.kind!=="text")continue;Ze=!0;const $e=re(rt);$e.fontFamily&&Ye.add($e.fontFamily),$e.fontSize&&Be.add($e.fontSize)}}if(!Ze)return{};const He={};return Ye.size===1&&(He.fontFamily=[...Ye][0]),Be.size===1&&(He.fontSize=[...Be][0]),He},tc=f=>{const v=T(),b=new Set(Rr(f));if(b.size===0)return{};const A=v?.readMountedProjectionBlocksByIds,E=v?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof E!="function")return{};const U=Tt(()=>{if(typeof A!="function")return E.call(v);const He=oa(f);return He?A.call(v,[...b],He):A.call(v,[...b])},null);if(!Array.isArray(U))return{};const Q=K0(U),re=He=>({bold:He.bold===!0,italic:He.italic===!0,underline:He.underline!=null,strikethrough:He.strike===!0}),ye=He=>{const Ue={};for(const je of Af){const rt=He[je];rt.size===1&&(Ue[je]=[...rt][0])}return Ue},Re=$a(f),ze=Re&&typeof Re.range?.start=="number"?Re.range.start:null;if(Re&&ze!==null&&b.has(Re.blockId)){const He=Q.find(je=>ec(je,Re.blockId)),Ue=He&&Array.isArray(He.runs)?He.runs:null;if(Ue&&Ue.length>0&&Ue.every(je=>je?.kind==="text"||je?.kind==="tab")){let je=0,rt=null;for(const $e of Ue){const Bt=typeof $e.text=="string"?$e.text.length:0;if(ze>=je&&ze<je+Bt){rt=$e;break}je+=Bt}if(!rt){for(let $e=Ue.length-1;$e>=0&&!rt;$e-=1)Ue[$e]?.kind==="text"&&(rt=Ue[$e]);rt??=Ue[Ue.length-1]??null}return rt?re(rt):{}}}const Ye=mu(f);if(Ye.length>0){const He={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ue=!1,je=!0;for(const rt of Ye){const $e=Q.find(Nn=>ec(Nn,rt.blockId));if(!$e)return{};const Bt=Array.isArray($e.runs)?$e.runs:[];if(Bt.length===0)continue;if(!Bt.every(Nn=>Nn?.kind==="text"||Nn?.kind==="tab")){je=!1;break}let Xt=0;for(const Nn of Bt){const Gn=typeof Nn.text=="string"?Nn.text.length:0,Jr=Xt,Vr=Xt+Gn;if(Jr<rt.end&&Vr>rt.start){Ue=!0;const Lr=re(Nn);for(const Ar of Af)He[Ar].add(Lr[Ar])}Xt=Vr}}if(je&&Ue)return ye(He)}const Be={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ze=!1;for(const He of Q){if(![...b].some(je=>ec(He,je)))continue;const Ue=Array.isArray(He.runs)?He.runs:[];for(const je of Ue){if(je?.kind!=="text")continue;Ze=!0;const rt=re(je);for(const $e of Af)Be[$e].add(rt[$e])}}return Ze?ye(Be):{}},ua=(f,v)=>{if(v.fontFamily!==void 0&&v.fontSize!==void 0&&v.color!==void 0&&v.highlight!==void 0)return{values:v,effectiveUniformityStatus:"ready"};const b=fl(f),A={...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}:{},...v};if(!f.empty&&(A.fontFamily===void 0||A.fontSize===void 0)){const E=Au(f);return E.values&&(A.fontFamily===void 0&&E.values.fontFamily!==void 0&&(A.fontFamily=E.values.fontFamily),A.fontSize===void 0&&E.values.fontSize!==void 0&&(A.fontSize=E.values.fontSize)),{values:A,effectiveUniformityStatus:E.status}}return{values:A,effectiveUniformityStatus:"ready"}},Yi=["fontFamily","fontSize","bold","italic","underline","strikethrough"],hl=f=>{const v=f.selectionTarget;if(!v)return{value:null,status:"ready"};const b=gr(y(),"format.readEffectiveInlineUniformity");return b?Yn(`effInline:${rA(f)??Un(f)}`,Ft(),()=>b({target:v,offsetSpace:"selection",keys:Yi}),A=>A&&typeof A=="object"?A:null):{value:null,status:"ready"}},Au=f=>{const{value:v,status:b}=hl(f);if(!v||v.success!==!0)return{values:null,status:b};const A=v.values,E=U=>{const Q=A?.[U];if(!(!Q||Q.state!=="uniform"||typeof Q.value!="string"))return U==="fontFamily"?G0(Q.value):Q.value};return{values:{fontFamily:E("fontFamily"),fontSize:E("fontSize")},status:b}},nc=f=>{const{value:v,status:b}=hl(f);if(!v||v.success!==!0)return{values:null,status:b};const A=v.values,E={};for(const U of Af){const Q=A?.[U];Q?.state==="uniform"&&(Q.value==="true"||Q.value==="false")&&(E[U]=Q.value==="true")}return{values:E,status:b}},xf=(f,v)=>{const b=f.activeMark;if(!b||!Af.includes(b))return null;const A=b,E=tc(v)[A];if(E!==void 0)return E;const{values:U}=nc(v),Q=U?.[A];return Q!==void 0?Q:null},Tf=async f=>{const v=f.selectionTarget;if(!v)return null;const b=gr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const A=await Promise.resolve(b({target:v,offsetSpace:"selection"}));return A&&typeof A=="object"&&A.success===!0?A:null}catch{return null}},rc=(f,v,b)=>{const A=b.values;for(const E of["fontFamily","fontSize"]){if(v[E]!==void 0)continue;const U=A?.[E];U?.state==="uniform"&&typeof U.value=="string"?f[E]=E==="fontFamily"?G0(U.value):U.value:delete f[E]}},bs=f=>ua(f,iA(ys(f),f)),pl=f=>bs(f).values,Iu=async f=>{const v=y()?.query,b=jo(f);if(typeof v?.match!="function"||!b)return pl(f);try{const A=await Promise.resolve(v.match(b)),E=iA(oA(A&&typeof A=="object"?A:null,f),f),U=ua(f,E);if(U.effectiveUniformityStatus!=="ready"&&(E.fontFamily===void 0||E.fontSize===void 0)){const Q=await Tf(f);Q&&rc(U.values,E,Q)}return U.values}catch{return pl(f)}},da=async f=>{const v=y();if(v)return typeof v.getNode=="function"?await Promise.resolve(v.getNode(f)):await Promise.resolve(v.getNodeById?.({nodeId:f.nodeId,nodeType:f.nodeType}))},ml=f=>{const v=y()?.query;if(typeof v?.match!="function")return"ready";const b=jo(f);if(!b)return"ready";const{status:A}=Yn(`query:${Un(f)}`,Ft(),()=>v.match(b),E=>E&&typeof E=="object"?E:null);return A},Eu=f=>{const v=bs(f),b=v.values;if(f.empty)return v;const A=ia(f);return A?f.status==="ready"&&ml(f)==="ready"&&v.effectiveUniformityStatus==="ready"?(w={key:A,values:b},v):w&&w.key===A?{...v,values:{...w.values,...b}}:v:v},oc=f=>{const v=y(),b=Eu(f),A=b.values;f.status==="ready"&&!f.empty&&ml(f)==="ready"&&b.effectiveUniformityStatus==="ready"&&(g=A,k=`${Ql(f)}:${Ft()}`);const E=v?.contentControls,{lockModesById:U}=vs(E,f),Q={};for(const re of it())Q[re]=Ru(re,v,f,A,U);return Q},Mi=f=>f?at.operationUnavailable:S()?at.documentApiUnavailable:at.notReady,xu=f=>f==="contentLocked"||f==="sdtContentLocked",Xi=f=>{for(const v of f.values())if(xu(v))return at.contentControlLocked},Rf=(f,v,b,A,E)=>{if(!v)return f.scope==="all"?at.bulkDecisionsDisabled:Mi(E);if(b)return at.documentReadonly;if(f.scope!=="all"&&A.activeChangeIds.length===0)return at.selectionRequired},Tu=f=>{const v=T(),b=Tt(typeof v?.getCapabilities=="function"?()=>v.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(A=>A?.command===f||A?.id===f)??null;if(b&&typeof b=="object"){const A=b[f];return A&&typeof A=="object"?A:null}return null},ic=(f,v)=>{if(f.scope!=="all"||typeof v?.[`${f.kind}All`]=="function")return;const b=Tu(`trackedChanges.${f.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return at.bulkDecisionsDisabled},Ru=(f,v,b,A,E=new Map)=>{if(he.has(f))return tn({supported:!0,enabled:!0,...Tt(he.get(f).getState?()=>he.get(f).getState(Ki(void 0)):void 0,{})},"custom");const U=br()==="viewing",Q=Yk(f);if(Q&&typeof I()?.lists?.apply=="function"){const Ze=Y(),He=typeof Ze?.shippedStatus=="string"?Ze.shippedStatus:null,Ue=He!=="not-shipped"&&He!=="disabled";return tn({enabled:Ue&&(typeof Ze?.enabled=="boolean"?Ze.enabled:!0),active:(Ue?te(Ze):null)===Q,supported:Ue,value:Ze?.value},"builtin")}const re=rm(f);if(re){const Ze=v?.trackChanges,He=typeof Ze?.decide=="function"||typeof Ze?.[re.kind]=="function",Ue=typeof Ze?.decide=="function"||typeof Ze?.[`${re.kind}All`]=="function",je=re.scope==="all"?Ue:He,rt=ic(re,Ze)??Rf(re,je,bi(),b,v);return tn({enabled:rt==null,active:!1,supported:je,reason:rt},"builtin")}if(f==="copy-format")return br()==="viewing"?tn({supported:!0,enabled:!1,active:!1},"builtin"):S()?tn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):tn({supported:!0,enabled:!1,active:!1,reason:at.notReady},"builtin");const ye=uu(f);if(!ye)return tn({enabled:!1,active:!1,supported:!1,reason:at.commandUnsupported},"unsupported");if(ye.disposition!=="routed")return tn({enabled:!1,active:!1,supported:!1,reason:ye.reason??at.commandUnsupported},ye.disposition==="unsupported"?"unsupported":"builtin");if(ye.instanceRoute)return Xe(ye);if(ye.table)return st(ye,v,U);if(ye.inline?.kind==="clear"){if(ye.mutates&&U)return tn({enabled:!1,active:!1,supported:!0,reason:at.documentReadonly},"builtin");const Ze=Xi(E);if(Ze)return tn({enabled:!1,active:!1,supported:!0,reason:Ze},"builtin");const He=Rr(b).length>0||vu(b)!=null;return tn({enabled:He,active:!1,supported:!0,reason:He?void 0:at.selectionRequired},"builtin")}const Re=ye.docRoute;if(!Re)return tn({enabled:!1,active:!1,supported:!1,reason:at.commandUnsupported},"unsupported");if(gr(v,Re)==null)return tn({enabled:!1,active:!1,supported:!1,reason:Mi(v)},"builtin");const ze=le(f);if(ze){const Ze=ze.shippedStatus,He=Ze!=="not-shipped"&&Ze!=="disabled",Ue=typeof ze.enabled=="boolean"?ze.enabled:!0,je=f==="undo"||f==="redo",rt=je&&ze.historyResolved===!1,$e=je&&He&&Ue===!1&&ze.reason===null&&!rt,Bt=ze.reason===void 0?void 0:$e?at.historyEmpty:rt?at.notReady:z0(ze.reason,at.commandUnsupported);return ye.mutates&&U?tn({enabled:!1,active:!1,supported:He,reason:at.documentReadonly},"builtin"):tn({enabled:He&&Ue,active:!1,supported:He,reason:Bt},"builtin")}const Ye=ha(ye,v,b),Be=Lu(ye,v,b,A);if(ye.list?.mode==="indent"||ye.list?.mode==="outdent")return pe(ye,v,U,b,Ye,Be);if(ye.list?.mode==="toggle-seed")return ve(ye,v,U,b,Ye,Be);if(ye.mutates&&U)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:at.documentReadonly},"builtin");if(ye.inline&&!vu(b)){const Ze=Xi(E);return tn(Ze?{enabled:!1,active:Ye,supported:!0,value:Be,reason:Ze}:Rr(b).length>0&&typeof T()?.setPendingInlineFormat=="function"?{enabled:!0,active:Ye,supported:!0,value:Be}:{enabled:!1,active:Ye,supported:!0,value:Be,reason:at.rangeSelectionRequired},"builtin")}if((ye.blockParagraph||ye.list)&&Rr(b).length===0)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:at.selectionRequired},"builtin");if(ye.link&&!Ye&&V0(b).length===0&&!$a(b))return tn({enabled:!1,active:Ye,supported:!0,reason:at.rangeSelectionRequired},"builtin");if(ye.inline){const Ze=Xi(E);if(Ze)return tn({enabled:!1,active:Ye,supported:!0,value:Be,reason:Ze},"builtin")}return tn({enabled:!0,active:Ye,supported:!0,value:Be},"builtin")};function Mu(f,v){const b=f.address?.anchor,A=b?.start,E=b?.end,U=typeof A?.blockId=="string"?A.blockId:null,Q=typeof E?.blockId=="string"?E.blockId:null;if(!U||!Q)return!1;const re=typeof A?.offset=="number"?A.offset:null,ye=typeof E?.offset=="number"?E.offset:null;if(re==null||ye==null)return!1;const Re=v.target,ze=Re&&Array.isArray(Re.segments)?Re.segments:[];for(const Ye of ze){const Be=typeof Ye?.blockId=="string"?Ye.blockId:null;if(!Be)continue;const Ze=Ye.range,He=typeof Ze?.start=="number"?Ze.start:null,Ue=typeof Ze?.end=="number"?Ze.end:null;if(!(He==null||Ue==null)){if(U!==Q){if(Be===U&&Ue>re||Be===Q&&He<ye)return!0;continue}if(Be===U){if(He===Ue){if(He>=re&&He<=ye)return!0;continue}if(Math.max(He,re)<Math.min(Ue,ye))return!0}}}return!1}const fa=(f,v)=>{const b=f?.hyperlinks;if(!b||typeof b.list!="function")return null;const A=Rr(v);if(!Jl(A))return null;for(const E of A){const U={kind:"block",nodeType:"paragraph",nodeId:E},{value:Q}=Yn(`hyperlinks:${E}`,Ft(),()=>b.list({within:U}),ye=>ye&&typeof ye=="object"?ye:null),re=(Q&&Array.isArray(Q.items)?Q.items:[]).find(ye=>Mu(ye,v));if(re)return re}return null},ha=(f,v,b)=>{if(f.link)return fa(v,b)!=null;if(f.list?.mode==="toggle-seed"&&f.list.seed)return ei(v,b)===f.list.seed;const A=H(f);if(A!==null)return A;const E=r.get(f.id),U=ia(b);if(U&&E?.selectionSignature===U)return E.active;const Q=xf(f,b);return Q!==null?Q:zH(f,b)},Lu=(f,v,b,A)=>{if(f.inline&&j0(f.inline.key)){const E=B(f);if(E!==void 0)return E;const U=A[f.inline.key];if(U!==void 0)return U;const Q=ia(b),re=Q?n.get(f.inline.key):void 0;if(Q&&re?.selectionSignature===Q)return re.value}if(f.id==="linked-style"){const{style:E}=yo(b,Fn().cache);return!E.styleId||E.mixed?void 0:{styleId:E.styleId,styleName:E.styleName}}if(f.id==="text-align")return x(v,b);if(f.id==="link")return qe(v,b)??void 0},gl=(f,v,b)=>{const A=f?.lists;if(!A)return{value:null,status:"ready"};const E=b.storyType==="body",U=typeof A.getStateInStory=="function"?()=>A.getStateInStory({target:ra(v),story:b}):E&&typeof A.getState=="function"?()=>A.getState({target:ra(v)}):null;if(!U)return{value:null,status:"ready"};const{value:Q,status:re}=Yn(`lists:${xo(b)}:${v}`,Ft(),U,ye=>ye&&typeof ye=="object"?ye:null);return{value:Q?.success===!0?Q:null,status:re}},Mf=(f,v,b)=>gl(f,v,b).value,sc=(f,v,b)=>{const A=Mf(f,v,b);return!A||A.isListItem!==!0?null:A.seed==="bullet"||A.seed==="ordered"?A.seed:null},ac=(f,v,b)=>{const A=gl(f,v,b),E=A.value;return{value:E&&typeof E.isListItem=="boolean"?E.isListItem:null,status:A.status}},ei=(f,v)=>{const b=Rr(v);if(b.length===0||!Jl(b))return null;const A=na(v),E=sc(f,b[0],A);if(E!=="bullet"&&E!=="ordered")return null;for(const U of b.slice(1))if(sc(f,U,A)!==E)return null;return E},Qi=(f,v,b)=>{if(!f)return{value:null,status:"ready",refreshing:!1};const A=xo(b),E=A==="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 U=`node:${A}:${v}`,Q=Ft(),re=Yn(U,Q,()=>E?f.getNodeById({nodeId:v,nodeType:"paragraph"}):f.getNode(mo(v,b)),Re=>Re&&typeof Re=="object"?Re:null),ye=Le.get(U);return{...re,refreshing:re.status==="stale"&&ye?.inflightToken===Q&&ye.failedToken!==Q}},Br=f=>f==="left"||f==="center"||f==="right"||f==="justify"?f:void 0,Lf=f=>f==="start"||f==="end"||f==="distributed"||f==="numTab"||f==="lowKashida"||f==="mediumKashida"||f==="highKashida"||f==="thaiDistribute",Df=(f,v)=>{const b=T(),A=b?.readMountedProjectionBlocksByIds;if(typeof A!="function")return null;const E=oa(f),U=Tt(()=>E?A.call(b,[...v],E):A.call(b,[...v]),null);if(!Array.isArray(U))return new Map;const Q=K0(U),re=new Map;for(const ye of v){const Re=Q.find(Ze=>ec(Ze,ye));if(!Re)continue;const ze=Re.attrs,Ye=Br(ze?.alignment),Be=o9(ze);re.set(ye,Ye??(Be==="rtl"?"right":"left"))}return re},pa=(f,v,b,A)=>{const{value:E,status:U,refreshing:Q}=Qi(f,v,b),re=A?.get(v);if(U==="pending")return re?{status:"uniform",value:re}:{status:"pending"};if(U==="stale"&&!Q)return{status:"pending"};if(U==="stale"&&re)return{status:"uniform",value:re};if(U==="stale"&&A&&!re)return{status:"unavailable"};if(!E)return{status:"unavailable"};const ye=E.node;if(!ye)return{status:"unavailable"};const Re=ye.kind;if(Re!=="paragraph"&&Re!=="heading")return{status:"unavailable"};const ze=ye[Re];if(!ze||typeof ze!="object")return{status:"unavailable"};const Ye=ze.props?.alignment;if(Ye==null)return re?{status:"uniform",value:re}:{status:"unavailable"};const Be=Br(Ye);return Be?{status:"uniform",value:Be}:Lf(Ye)&&re?{status:"uniform",value:re}:{status:"unavailable"}},lc=(f,v)=>{const b=Rr(v);if(b.length===0||!Jl(b))return{status:"unavailable"};const A=na(v),E=Df(v,b),U=pa(f,b[0],A,E);if(U.status!=="uniform")return U;for(const Q of b.slice(1)){const re=pa(f,Q,A,E);if(re.status!=="uniform")return re;if(re.value!==U.value)return{status:"mixed"}}return U},Du=f=>{const v=Rr(f);return v.length===0?null:`${xo(na(f))}:${v.join(",")}`},x=(f,v)=>{const b=lc(f,v),A=b.status==="uniform"?b.value:void 0,E=o;if(!E)return A;const U=Du(v);return U&&U!==E.selectionSignature?(o=null,A):!U||!E.settled?E.value:b.status!=="pending"?(o=null,A):E.value},D=(f,v)=>{const b=Br(v),A=Du(f),E=Rr(f);if(!b||!A||E.length===0)return null;const U=++i;return o={selectionSignature:A,value:b,generation:U,settled:!1,canReconcile:Jl(E)},jt(),U},ee=(f,v)=>{if(f==null)return;const b=o;if(!(!b||b.generation!==f)){if(!No(v)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},ie=async(f,v,b)=>{const A=f?.lists;if(!A)return null;try{const E=b.storyType==="body",U=typeof A.getStateInStory=="function"?await A.getStateInStory({target:ra(v),story:b}):E&&typeof A.getState=="function"?await A.getState({target:ra(v)}):null,Q=U&&typeof U=="object"?U:null;return!Q||Q.success!==!0||typeof Q.isListItem!="boolean"?null:Q.isListItem}catch{return null}},se=(f,v,b)=>{const A={resolved:!1,seed:null},E=f?.lists;if(!E)return A;const U=b.storyType==="body",Q=typeof E.getStateInStory=="function"?()=>E.getStateInStory({target:ra(v),story:b}):U&&typeof E.getState=="function"?()=>E.getState({target:ra(v)}):null;if(!Q)return A;const re=ye=>{const Re=ye&&typeof ye=="object"?ye:null;return!Re||Re.success!==!0||typeof Re.isListItem!="boolean"?A:{resolved:!0,seed:Re.isListItem===!0&&(Re.seed==="bullet"||Re.seed==="ordered")?Re.seed:null}};try{const ye=Q();return Or(ye)?Promise.resolve(ye).then(re,()=>A):re(ye)}catch{return A}},de=async(f,v,b)=>{if(!f)return null;try{const A=!b||b.storyType==="body",E=b&&typeof f.getNode=="function"?await f.getNode(mo(v,b)):A&&typeof f.getNodeById=="function"?await f.getNodeById({nodeId:v,nodeType:"paragraph"}):null;return dH(E&&typeof E=="object"?E:null)}catch{return null}},pe=(f,v,b,A,E,U)=>{if(f.mutates&&b)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.documentReadonly},"builtin");const Q=Rr(A);if(Q.length===0)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.selectionRequired},"builtin");const re=f.docRoute?gr(v,f.docRoute):null,ye=gr(v,"format.paragraph.setIndentation"),Re=gr(v,"format.paragraph.clearIndentation"),ze=f.list?.mode,Ye=ze==="indent"?ye!=null:ye!=null||Re!=null,Be=na(A);let Ze=null;if(Be.storyType!=="body"){Ze=[];for(const He of Q){const{value:Ue,status:je}=ac(v,He,Be);if(Ue===null)return je!=="ready"&&(re!=null||Ye)?tn({enabled:!0,active:E,supported:!0,value:U},"builtin"):tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin");Ze.push(Ue)}}if(Ze?.some(He=>He===!0)){const He=ze==="indent"?"lists.indentRange":"lists.outdentRange",Ue=br()!=="suggesting"&&Ze.every(rt=>rt===!0)&&gr(v,He)!=null,je=ze==="outdent"&&gr(v,"lists.outdentInStory")!=null;if(!Ue&&!je)return tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")}for(const[He,Ue]of Q.entries()){const je=Ze?{value:Ze[He]??null,status:"ready"}:ac(v,Ue,Be),rt=je.value;if(rt===!0){if(re!=null)return tn({enabled:!0,active:E,supported:!0,value:U},"builtin");continue}if(rt===!1&&Ye){if(Be.storyType!=="body"&&typeof v?.getNode!="function")continue;return tn({enabled:!0,active:E,supported:!0,value:U},"builtin")}if(rt===null)return je.status!=="ready"&&(re!=null||Ye)?tn({enabled:!0,active:E,supported:!0,value:U},"builtin"):tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")}return tn({enabled:!1,active:E,supported:!1,value:U,reason:Mi(v)},"builtin")},ve=(f,v,b,A,E,U)=>{if(f.mutates&&b)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.documentReadonly},"builtin");const Q=Rr(A);if(Q.length===0)return tn({enabled:!1,active:E,supported:!0,value:U,reason:at.selectionRequired},"builtin");const re=na(A),ye=v?.lists;if(!(typeof ye?.getStateInStory=="function"||re.storyType==="body"&&typeof ye?.getState=="function"))return tn({enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");if(!Jl(Q))return tn(re.storyType==="body"&&gr(v,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const Re=Q.map(Ze=>gl(v,Ze,re));if(Re.some(({status:Ze})=>Ze!=="ready"))return tn({enabled:!0,active:E,supported:!0,value:U},"builtin");if(Re.some(({value:Ze})=>Ze===null))return tn({enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const ze=f.list?.seed,Ye=Re.every(({value:Ze})=>Ze?.isListItem===!0&&Ze.seed===ze);if(re.storyType==="body")return tn(!Ye||gr(v,"lists.remove")!=null?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin");const Be=gr(v,"lists.removeInStory");return tn(Ye&&Be?{enabled:!0,active:E,supported:!0,value:U}:{enabled:!1,active:E,supported:!1,value:U,reason:at.operationUnavailable},"builtin")},qe=(f,v)=>{const b=fa(f,v)?.properties?.href;return typeof b=="string"?b:null},Xe=f=>{if(!S())return tn({enabled:!1,active:!1,supported:!1,reason:at.notReady},"builtin");const v=f.instanceRoute;return typeof t?.[v]!="function"?tn({enabled:!1,active:!1,supported:!1,reason:at.operationUnavailable},"builtin"):tn({enabled:!0,active:et(f),supported:!0,value:yt(f)},"builtin")},et=f=>{const v=t?.config??void 0;return f.valueFrom==="ruler"?!!v?.rulers:f.valueFrom==="formattingMarks"?!!v?.layoutEngineOptions?.showFormattingMarks:!1},st=(f,v,b)=>{if(b)return tn({enabled:!1,active:!1,supported:!0,reason:at.documentReadonly},"builtin");const A=Ne();return A!=null&&(!f.table.requiresCell||A.cellNodeId!=null)?(f.docRoute?gr(v,f.docRoute):null)==null?tn({enabled:!1,active:!1,supported:!1,reason:Mi(v)},"builtin"):tn({enabled:!0,active:!1,supported:!0},"builtin"):tn({enabled:!1,active:!1,supported:!0,reason:at.tableContextUnavailable},"builtin")},yt=f=>{if(f.valueFrom==="zoom")return qi().value;if(f.valueFrom==="documentMode")return br();if(f.valueFrom==="measurementUnit")return Su();if(f.valueFrom==="ruler"||f.valueFrom==="formattingMarks")return et(f)},gt=(f,v)=>f.id==="zoom"?typeof v=="number"&&Number.isFinite(v)&&v>0:f.id==="document-mode"?v==="editing"||v==="suggesting"||v==="viewing":f.id==="measurement-unit"?v==="in"||v==="cm":!0,it=()=>[...new Set([...$F,...he.keys()])],on="Normal",nn={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},Dn=f=>{const v=y()?.styles;return!v||typeof v.getCatalog!="function"?{value:null,status:"ready"}:Yn(`styles:catalog:${JSON.stringify(f??{})}`,Ft(),()=>v.getCatalog(f),b=>b&&typeof b=="object"?b:null)},Fn=()=>{const f=Dn({includePreview:!0});if(!f.value)return{cache:null,status:f.status};const v=Dn({view:"quickGallery",includePreview:!0}),b=v.value?v.value.items:f.value.styles.filter(E=>E.visibility.quickGallery),A=new Map;for(const E of f.value.styles)A.set(E.id,E);return{cache:{full:f.value,quickGallery:b,byId:A},status:hu(f.status,v.status)}},jn=(f,v,b)=>{const{value:A,status:E}=Qi(f,v,b);if(!A)return{ok:!1,styleRef:null,status:E};const U=A.node;if(!U||typeof U!="object")return{ok:!1,styleRef:null,status:E};const Q=U.kind,re=typeof Q=="string"?U[Q]:void 0,ye=re&&typeof re=="object"?re.styleRef:void 0;return{ok:!0,styleRef:typeof ye=="string"&&ye.length>0?ye:null,status:E}},yo=(f,v)=>{const b=[],A=y();if(!A)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=Rr(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(!Jl(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 U=v?.full.defaults.paragraphStyleId??(v?on:null),Q=new Set;let re=0,ye=0,Re=0,ze="ready";const Ye=na(f);for(const He of E){const Ue=jn(A,He,Ye);if(ze=hu(ze,Ue.status),!Ue.ok){ye+=1;continue}if(!Ue.styleRef&&!U){Re+=1;continue}const je=Ue.styleRef??U;if(!je){Re+=1;continue}re+=1,Q.add(je)}if(re===0){const He=Re>0&&ye===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:ze}}const Be=ye+Re;if(Be>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${re} of ${re+Be} selected blocks; ${Be} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:ze};if(Q.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:ze};const Ze=[...Q][0];return{style:{styleId:Ze,styleName:v?.byId.get(Ze)?.name??null,mixed:!1,diagnostics:b},status:ze}},er=f=>{if(!S())return nn;const{cache:v,status:b}=Fn(),{style:A,status:E}=yo(f,v);let U;return v?U=A.diagnostics.length===0?v.full.diagnostics:[...v.full.diagnostics,...A.diagnostics]:U=[{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)."},...A.diagnostics],{ready:!0,status:hu(b,E,f.status),catalogRevision:v?.full.revision??null,quickGallery:v?.quickGallery??[],activeParagraphStyleId:A.styleId,activeParagraphStyleName:A.styleName,mixedSelection:A.mixed,sourceStatus:v?.full.sourceStatus??null,diagnostics:U}},En=()=>{const f=br(),v=bu();v.status==="ready"&&aa(v),N(v);const b=ia(v);for(const[A,E]of r)(!b||E.selectionSignature!==b||E.settled&&v.status==="ready")&&r.delete(A);return{ready:S()!=null,documentMode:f,document:ku(),selection:v,toolbar:{context:f,commands:oc(v),copyFormatActive:h.mode!=="idle"},comments:_u(v),trackChanges:ul(v),contentControls:Ef(v),zoom:qi(),fonts:Do(),styles:er(v)}},ur=f=>{const v=ia(f);v&&a&&v!==a&&(n.clear(),r.clear()),v&&(a=v)};let mt=null,Lt=null,Pn=null,Nr=null,wr=!1;const vl=()=>{if(be||wr)return;wr=!0;const f=()=>{wr&&(wr=!1,!be&&jt())};typeof queueMicrotask=="function"?queueMicrotask(f):Promise.resolve().then(f)},yl=()=>{const f=I();if(f!==Pn&&(Nr&&(Nr(),Nr=null),Pn=f,!(!f||typeof f.subscribe!="function")))try{const v=f.subscribe(()=>vl());typeof v=="function"&&(Nr=v)}catch{Pn=null}};let zr=null,ti=null,Li=null,wi=null,ma=null,Mr=null;const ws=()=>{const f=S()?.host,v=Tt(f?.getHandles?()=>f.getHandles():void 0,null)?.editing?.selection;return v&&typeof v.subscribe=="function"?v:null},Di=()=>{const f=ws();if(f!==mt&&(Lt&&(Lt(),Lt=null),mt=f,!!f))try{const v=f.subscribe(b=>{kt+=1,Cu(b),jt()});typeof v=="function"&&(Lt=v)}catch{mt=null}},Cs=()=>{const f=S()?.host,v=Tt(f?.getHandles?()=>f.getHandles():void 0,null)?.review;return v&&typeof v.subscribe=="function"?v:null},Pi=f=>f?typeof f.getActiveReviewTarget=="function"?Tt(()=>f.getActiveReviewTarget(),null):typeof f.getSnapshot=="function"?Tt(()=>f.getSnapshot(),null)?.activeReviewTarget??null:null:null;let ao=0;const Po=(f,v)=>{const b=(v&&typeof v=="object"?v:null)?.lastInteractionRejection;if(ao>0&&f==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const A=f&&typeof f=="object"?f:null;let E=null;if(A?.entityType==="trackedChange"&&typeof A.entityId=="string"&&A.entityId.length>0){const U=A.story&&xo(A.story)!==xo(null)?A.story:void 0;E={id:A.entityId,...U?{story:U}:{},...typeof A.paintedEntityId=="string"&&A.paintedEntityId.length>0?{paintedEntityId:A.paintedEntityId}:{}}}return Te(ae,E)?!1:(Je(E),!0)},cc=()=>{const f=Cs();if(f===zr)return;if(ti&&(ti(),ti=null),zr=f,!f){Po(null);return}let v=!0;try{const b=f.subscribe(A=>{const E=A&&typeof A=="object"?A:null;!Po(E&&Object.prototype.hasOwnProperty.call(E,"activeReviewTarget")?E.activeReviewTarget:Pi(f),A)||v||jt()});typeof b=="function"&&(ti=b),Po(Pi(f))}catch{zr=null}finally{v=!1}},ga=()=>{if(mt||br()!=="viewing")return null;const f=S()?.mount?.container,v=(f&&typeof f=="object"&&"ownerDocument"in f?f.ownerDocument??null:null)??globalThis.document??null;return v&&typeof v.addEventListener=="function"?v:null},uc=()=>{const f=ga();if(f===ma||(Mr&&(Mr(),Mr=null),ma=f,!f))return;const v=()=>{kt+=1,jt()};f.addEventListener("selectionchange",v),f.addEventListener("pointerup",v,!0),f.addEventListener("mouseup",v,!0),Mr=()=>{f.removeEventListener("selectionchange",v),f.removeEventListener("pointerup",v,!0),f.removeEventListener("mouseup",v,!0)}};Mo(),Po(Pi(Cs()));let bt=En();a=ia(bt.selection);const va=()=>{const f=S()?.host?.events,v=f&&typeof f.subscribe=="function"?f:null;if(v!==Li&&(wi&&(wi(),wi=null),Li=v,!!v))try{const b=v.subscribe(A=>{const E=A?.type;if(E==="source:complete"||E==="source:signals-complete"){pt!==null&&(ln(),Yt.onRender(!0));return}if((E==="mutation:committed"||E==="collaboration:remote-changed")&&(rl=Date.now()),E==="mutation:committed"&&(ln(),Kt={}),E==="mutation:committed"||E==="save:completed"||E==="collaboration:remote-changed"){const U=E==="mutation:committed"?b_(A):null,Q=E==="mutation:committed"&&Yt.getPendingIds().size>0;U?.removedIds.size&&Oe(new Set(U.removedIds),A.receipt);const re=U?.reconcileMode==="authoritative"&&U.upsertIds.size>0;if(re&&(Xr(),ln(),pt=Ft(),jt()),U?.upsertIds.size||Q){const Ye=A.origin==="history"?null:A.receipt,Be=S()?.documentMutationReadiness,Ze=typeof Ye?.txId=="string"&&Ye.txId.length>0&&typeof Be?.whenPainted=="function",He=A.origin==="history"&&typeof Be?.getRenderEpoch=="function"?Tt(()=>Be.getRenderEpoch.call(Be),null):null,Ue=A.origin==="history"&&typeof Be?.whenPainted=="function",je={upsertIds:U?.upsertIds??new Set,removedIds:new Set,reconcileMode:U?.reconcileMode==="authoritative"?"authoritative":"targeted"};Ze?Yt.enqueueAfterPaint(je,()=>Be.whenPainted.call(Be,Ye)):Ue?Yt.enqueueAfterPaint(je,()=>Be.whenPainted.call(Be,typeof He=="number"?{afterEpoch:He}:void 0)):(Yt.enqueue(je),Yt.onRender(Q))}if(re)return;const ye=E==="mutation:committed"&&Ti(A)||E==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0;if(ye&&(gs=Date.now()),E==="mutation:committed"&&ye){vi();return}if(U?.removedIds.size&&U.upsertIds.size===0)return;(E==="collaboration:remote-changed"||E==="mutation:committed"&&!ye)&&Yr();const Re=E==="collaboration:remote-changed"&&Array.isArray(A.changedPartUris)&&A.changedPartUris.some(Ye=>typeof Ye=="string"&&tH.has(Ye)),ze=E==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0&&To();Re&&!ye&&(Ho=!0),Xr(),(Re||ze)&&yr("comments"),jt()}});typeof b=="function"&&(wi=b)}catch{Li=null}},jt=()=>{if(be)return;wr=!1,Mo(),Di(),yl(),cc(),uc(),va();const f=En();ur(f.selection),bt=f;for(const v of[..._t])v(bt)},_s=[],Pu=[],Ou=f=>{for(const v of f)try{v()}catch{}},Fu=()=>Ou(_s),Zt=()=>Ou(Pu),Mn=[];((f,v)=>{if(!(!f||typeof f.on!="function"))for(const b of v){const A=b==="active-editor-change"?()=>{Fu(),Zt(),jt()}:b==="document-replaced"?E=>{const U=E&&typeof E=="object"?E:null,Q=U?.editor,re=U?.host,ye=!!Q&&Q===S(),Re=!!re&&re===T();!ye&&!Re||(Zt(),Le.clear(),Xr(),jt())}:()=>jt();try{f.on(b,A),Mn.push(()=>{try{typeof f.off=="function"&&f.off(b,A)}catch{}})}catch{}}})(t,Xz),Di(),yl(),cc(),uc(),va();const Go=(f,v=Oz)=>({get:()=>f(bt),subscribe:b=>{let A=f(bt);const E=U=>{const Q=f(U);v(A,Q)||(A=Q,b(Q))};return _t.add(E),()=>_t.delete(E)}}),lo=f=>Go(f),Qr=f=>{const v=b=>{const A=U=>{try{b(U)}catch{}},E=f.subscribe(A);return A(f.get()),E};return{get:()=>f.get(),getSnapshot:()=>f.get(),observe:v,subscribe:b=>v(A=>b({snapshot:A}))}};function bl(f){return f&&typeof f=="object"&&typeof f.id=="string"?String(f.id):null}function wl(f){if(f.empty)return null;const v=f.selectionTarget,b=v?.start,A=v?.end;if(v?.kind!=="selection"||b?.kind!=="text"||A?.kind!=="text"||typeof b.blockId!="string"||b.blockId!==A.blockId||!Number.isInteger(b.offset)||!Number.isInteger(A.offset)||b.offset<0||A.offset<0||b.offset===A.offset)return null;const E=Math.min(b.offset,A.offset),U=Math.max(b.offset,A.offset),Q=oa(f);return{kind:"range",coordinateSpace:v.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...Q?{story:Q}:{},segments:[{blockId:b.blockId,range:{start:E,end:U}}]}}}function Z0(){const f=bt.selection.activeChangeIds[0];if(!f)return"unavailable";const v=Lo();if(!v)return"unavailable";const b=oa(bt.selection),A=v.find(Q=>Ja(Q,f,b));if(!A)return"unavailable";const E=tm(A).type,U=tm(A).grouping;return E==="replacement"&&U==="replacement-pair"||(E==="insertion"||E==="deletion"||E==="insert"||E==="delete")&&U==="standalone"?"range":"id"}function J0(f,v){if(f.scope==="all")return{target:{scope:"all"},changeId:null};if(typeof v=="string"&&v.length>0)return{target:{kind:"id",id:v},changeId:v};if(v&&typeof v=="object"){const A=v;if(A.target&&typeof A.target=="object")return{target:A.target,changeId:bl(A.target)};const E=typeof A.changeId=="string"?A.changeId:A.id;if(typeof E=="string"&&E.length>0)return{target:{kind:"id",id:E},changeId:E}}const b=bt.selection.activeChangeIds[0];return b?{target:{kind:"id",id:b},changeId:b}:null}function O(f,v){if(f.scope==="id"&&v==null){if(bt.selection.activeChangeIds.length>1)return Nu(f.kind,{kind:"ids",ids:bt.selection.activeChangeIds},null);if(bt.selection.activeChangeIds.length===1&&!bt.selection.empty&&bt.selection.selectionTarget){const A=Z0();if(A==="unavailable")return!1;if(A==="range"){const E=wl(bt.selection);return E?Nu(f.kind,E,null):!1}}}const b=J0(f,v);return b?Nu(f.kind,b.target,b.changeId):!1}function q(f,v){const b=I()?.lists,A=b?.apply;if(typeof A!="function")return!1;const{behavior:E,preset:U,continuity:Q}=typeof v=="string"?Jz(v):v&&typeof v=="object"?v:{},re={kind:f,behavior:E??"toggle"};U!==void 0&&(re.preset=U),Q!==void 0&&(re.continuity=Q);try{return co(A.call(b,re))}catch{return!1}}let Se=Promise.resolve(!1),Pe=null,ht=Promise.resolve(!1);const sn=async f=>{if(!nm(f))return f;const v=S()?.documentMutationReadiness,b=v?.whenPainted;if(typeof b!="function")return f;const A=typeof f.txId=="string"?f.txId:void 0;try{await b.call(v,A?{txId:A}:void 0)}catch{}return f},un=f=>{if(Or(f)){const b=Promise.resolve(f);return{immediate:!0,committed:b.then(A=>el(A),()=>!1),settled:b.then(A=>sn(el(A)),()=>!1)}}const v=el(f);return{immediate:v,committed:Promise.resolve(v),settled:sn(v)}},dr=()=>{const f=s.shift();if(!f){u=!1,d?.(),d=null;return}try{f.resolve(be?!1:f.mutate())}catch{f.resolve(!1)}},Bn=()=>{let f=!1;return()=>{f||(f=!0,dr())}},fr=(f,v)=>{if(!u){u=!0,c=new Promise(U=>{d=U});try{return{result:v(),release:Bn()}}catch(U){throw u=!1,d?.(),d=null,U}}const b=s.find(U=>U.key===f);if(b)return b.mutate=v,{result:b.result,release:()=>{}};let A;const E=new Promise(U=>{A=U});return s.push({key:f,mutate:v,result:E,resolve:A}),{result:E,release:Bn()}},kn=new Set(["create.tableOfContents"]),bo=f=>ar(`Tracked authoring is not supported for ${f}.`),Hr=f=>{if(br()==="suggesting")return kn.has(f)?bo(f):{changeMode:"tracked"}},ya=()=>br()==="suggesting"?xH:Y0,hr=(f,v,b)=>{const A=Hr(f);return A&&A.success===!1?A:A?v(b,A):v(b)},ni=(f,v,b,A)=>{const E=f.inline;if(!E)return;const U=el(A);if(U===!1||typeof U=="object"&&U&&U.success===!1)return;if(E.kind==="clear"){n.clear();return}if(E.kind==="toggle"||!j0(E.key))return;const Q=ia(v);if(!Q)return;const re=mH(E.key,b.value);if(re==null){n.delete(E.key);return}n.set(E.key,{selectionSignature:Q,value:re})},Cl=(f,v,b,A)=>!f.inline||f.inline.kind==="toggle"?A:Or(A)?Promise.resolve(A).then(E=>(ni(f,v,b,E),E)):A,_l=(f,v,b,A)=>{if(f.inline?.kind!=="toggle"||!No(el(A))||typeof b.value!="boolean"&&b.value!==null)return null;const E=ia(v);if(!E)return null;const U=++l;return r.set(f.id,{selectionSignature:E,active:b.value===!0,generation:U,settled:!1}),jt(),U},$0=(f,v,b)=>{if(v==null)return;const A=r.get(f.id);if(!(!A||A.generation!==v)){if(!No(b)){r.delete(f.id);return}A.settled=!0}},dc=(f,v)=>f.then(b=>(v?.(b),Xr(),jt(),b),()=>(v?.(!1),Xr(),jt(),!1)),co=(f,v)=>{const b=Pe;if(Pe=null,b)return Se=dc(b,v),el(f);if(Or(f))return Se=dc(un(f).settled,v),!0;const A=el(f);return nm(A)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(Se=dc(sn(A),v),A):(v?.(A),Se=Promise.resolve(A),Xr(),jt(),A)},eb=(f,v)=>!f||typeof f!="object"?v:f,ba=(f,v=ar("Document API operation failed."))=>{if(Or(f))return Promise.resolve(f).then(A=>ba(A,v),()=>v);const b=eb(f,v);return Xr(),nm(b)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(dc(sn(b)),jt(),b):(jt(),b)},Pf=(f,v,b,A)=>{const E=[],U=[];for(const Q of b){const re=A(Q);if(re)try{const ye=un(hr(f,v,re));E.push(ye.immediate),U.push(ye.settled)}catch{E.push(!1),U.push(Promise.resolve(!1))}}return Pe=U.length?Promise.all(U).then(Q=>fi(Q)):null,fi(E)},Xn=(f,v,b,A)=>{const E=[],U=[];for(const Q of b){const re=A(Q);if(re)try{const ye=un(hr(f,v,re));E.push(ye.immediate),U.push(ye.settled)}catch{E.push(!1),U.push(Promise.resolve(!1))}}return Pe=U.length?Promise.all(U).then(Q=>fi(Q)):null,fi(E)},Of=(f,v,b,A=bt.selection)=>{const E=Hr(f);return E&&E.success===!1?E:A.selectionTarget?v(b,{...E??{},offsetSpace:"selection"}):E?v(b,E):v(b)},sm=(f,v,b,A)=>{const E=mo(v,A);switch(f.kind){case"alignment":{const U=b;return U!=="left"&&U!=="center"&&U!=="right"&&U!=="justify"?null:{target:E,alignment:U}}case"spacing-line":{const U=typeof b=="number"?b:Number(b);return!Number.isFinite(U)||U<=0?null:{target:E,line:U,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const U=b.role;if(U&&typeof U=="object")return{target:E,role:U}}return typeof b!="string"||b.trim()===""?null:{target:E,styleId:b};case"direction":{const U=f.fixedValue;return U!=="ltr"&&U!=="rtl"?null:{target:E,direction:U}}default:return null}},am=(f,v)=>{const b=f.inline,A=q0(f),E=T();if(!b||typeof E?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return X(),!0;if(!A)return!1;let U;if(b.kind==="toggle")U=!ha(f,y(),bt.selection);else{const Q=v&&typeof v=="object"&&"value"in v?v.value:v;if(b.kind==="value-number"){const re=typeof Q=="number"?Q:Number(Q);U=Number.isFinite(re)&&re>0?re:null}else U=typeof Q=="string"&&Q.trim()!==""?Q:null;if(U===null)return z(A,null),!0}return z(A,U),!0},tb=()=>{const f=y(),{lockModesById:v}=vs(f?.contentControls,bt.selection);if(Xi(v))return!1;const b=[],A=[],E=Ze=>{const He=un(Ze);b.push(He.immediate),A.push(He.settled)},U=(Ze,He,Ue)=>{try{E(Ue?Ze(He,Ue):Ze(He))}catch{b.push(!1),A.push(Promise.resolve(!1))}},Q=Fn().cache?.full.defaults.paragraphStyleId??on,re=vu(bt.selection);if(re){const Ze=gr(f,"format.apply");if(Ze)try{E(Of("format.apply",Ze,{target:re,inline:{...ya()}}))}catch{b.push(!1),A.push(Promise.resolve(!1))}}const ye=gr(f,"format.paragraph.resetDirectFormatting"),Re=gr(f,"styles.paragraph.setStyleRef"),ze=oa(bt.selection),Ye=!ze||ze.storyType==="body",Be=gr(f,Ye?"lists.remove":"lists.removeInStory");for(const Ze of Rr(bt.selection)){const He=mo(Ze,ze);if(ye&&U(ye,{target:He}),Be)try{const Ue=ra(Ze),je=un(Be(Ye?{target:Ue}:{target:Ue,story:ze}));A.push(je.settled.then(rt=>No(rt)?rt:!0))}catch{}Re&&U(Re,{target:He,styleId:Q})}if(!re&&br()!=="suggesting"){const Ze=gr(f,"format.paragraph.setMarkRunProps");if(Ze)for(const He of Rr(bt.selection))U(Ze,{target:mo(He,ze),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return Pe=A.length?Promise.all(A).then(Ze=>fi(Ze)):null,fi(b.length?b:[!1])},lm=(f,v,b)=>{const A=Rr(bt.selection);if(A.length===0)return!1;const E=oa(bt.selection);return Pf(f.docRoute,v,A,U=>sm(f.blockParagraph,U,b,E))},cm=(f,v,b)=>{const A=y(),E=gr(A,"format.paragraph.setIndentation"),U=gr(A,"format.paragraph.clearIndentation"),Q=f.list?.mode,re=na(bt.selection),ye=oa(bt.selection),Re=async ze=>{const Ye=await ie(A,ze,re);if(Ye===!0)return{kind:"list",routeToCall:f.docRoute,opToCall:v,input:{target:eA(ze)}};if(Ye===null||ye&&ye.storyType!=="body"&&typeof A?.getNode!="function")return null;const Be=await de(A,ze,ye),Ze={};if(Be?.right!=null&&(Ze.right=Be.right),Be?.firstLine!=null&&(Ze.firstLine=Be.firstLine),Be?.hanging!=null&&(Ze.hanging=Be.hanging),Q==="indent")return E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),left:Math.max(0,Be?.left??0)+tA,...Ze}}:null;const He=Math.max(0,(Be?.left??0)-tA);return He>0&&(Ze.left=He),Object.keys(Ze).length===0?U?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:U,input:{target:mo(ze,ye)}}:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),left:0}}:null:E?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:E,input:{target:mo(ze,ye),...Ze}}:null};return Pe=(async()=>{const ze=await Promise.all(b.map(He=>Re(He).catch(()=>null)));if(ze.length===b.length&&ze.every(He=>He?.kind==="list")&&br()!=="suggesting"){const He=Q==="indent"?"lists.indentRange":"lists.outdentRange",Ue=gr(A,He);if(Ue)try{return await un(hr(He,Ue,{paraIds:b,story:re})).settled}catch{return!1}}const Ye=re.storyType!=="body"&&ze.some(He=>He?.kind==="list"),Be=Ye&&Q==="outdent"?gr(A,"lists.outdentInStory"):null;if(Ye&&!Be)return!1;const Ze=ze.map(He=>{if(!He)return Promise.resolve(!1);try{return He.kind==="list"&&Be?un(hr("lists.outdentInStory",Be,{target:He.input.target,story:re})).settled:un(hr(He.routeToCall,He.opToCall,He.input)).settled}catch{return Promise.resolve(!1)}});return fi(await Promise.all(Ze))})(),!0},um=(f,v)=>{const b=f.list,A=y(),E=Rr(bt.selection);if(E.length===0)return!1;const U=na(bt.selection),Q=U.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return cm(f,v,E);const re=b.seed,ye=Ye=>{if(Ye.some(rt=>!rt.resolved))return{immediate:!1,settled:null};const Be=Ye.every(rt=>rt.seed===re);if(!Be&&!Q)return{immediate:!1,settled:null};const Ze=Be?Q?"lists.remove":"lists.removeInStory":f.docRoute,He=Be?gr(A,Ze):v;if(!He)return{immediate:!1,settled:null};const Ue=[],je=[];return E.forEach((rt,$e)=>{if(!Be&&Ye[$e]?.seed===re)return;const Bt=Be?{target:ra(rt),...Q?{}:{story:U}}:{target:ra(rt),seed:re};try{const Xt=un(hr(Ze,He,Bt));Ue.push(Xt.immediate),je.push(Xt.settled)}catch{Ue.push(!1),je.push(Promise.resolve(!1))}}),{immediate:fi(Ue),settled:je.length?Promise.all(je).then(rt=>fi(rt)):null}},Re=E.map(Ye=>se(A,Ye,U));if(Re.some(Or))return Pe=Promise.all(Re).then(async Ye=>{const Be=ye(Ye);return Be.settled?await Be.settled:Be.immediate}),!0;const ze=ye(Re);return Pe=ze.settled,ze.immediate};function fc(f){return f&&typeof f=="object"?f:{}}function dm(f){if(typeof f=="string")return f;const v=fc(f);if(Object.prototype.hasOwnProperty.call(v,"href"))return v.href;if(Object.prototype.hasOwnProperty.call(v,"value"))return v.value}function hc(f,v){const b=fc(f).text;return typeof b=="string"&&b.trim()!==""?b:v}function pc(f){const v=fc(f),b=v.capture&&typeof v.capture=="object"?v.capture:null;return v.target??b?.target??b?.selectionTarget??v.selectionTarget??v.textTarget??null}const Ff=f=>{const v=y(),b=v?.hyperlinks;if(!b)return!1;const A=fc(f),E=dm(f),U=pc(f),Q=typeof A.text=="string"?A.text:void 0,re=typeof A.currentText=="string"?A.currentText:void 0,ye=gu(A.hyperlinkTarget)?A.hyperlinkTarget:null,Re=gu(A.textTarget)?A.textTarget:null,ze=fa(v,bt.selection),Ye=typeof ye?.storyId=="string"&&typeof ye?.hyperlinkNodeId=="string";if(Ye&&E===null){const Be=b.remove;if(typeof Be!="function")return!1;try{return hr("hyperlinks.remove",Be,{storyId:ye.storyId,hyperlinkNodeId:ye.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(ze&&E===null){const Be=b.remove;if(typeof Be!="function")return!1;try{return hr("hyperlinks.remove",Be,{target:ze.address,mode:"unwrap"})}catch{return!1}}if((ze||ye)&&typeof E=="string"&&E.trim()!==""){const Be=b.patch,Ze=b.updateTarget;if(!(!Ye&&ze&&typeof Be=="function")&&!(Ye&&typeof Ze=="function"))return!1;const He=typeof Q=="string"&&Q!==(Ye?re:ze?.text??re),Ue=v?.text?.replace,je=He?Ye?Re:_H(ze?.address):null,rt=He&&!!je&&typeof Ue=="function";if(He&&!rt)return!1;const $e=[],Bt=[];let Xt=null,Nn=null,Gn=null,Jr=!1;try{if(Ye){if(typeof Ze!="function")return!1;const Vr=hr("hyperlinks.updateTarget",Ze,{storyId:ye.storyId,hyperlinkNodeId:ye.hyperlinkNodeId,newTarget:SH(E)});Jr=Or(Vr);const Lr=un(Vr);if(!No(Lr.immediate))return!1;$e.push(Lr.immediate),Bt.push(Lr.settled),Xt=Lr.immediate,Nn=Lr.committed,Gn=Lr.settled}else if(ze){if(typeof Be!="function")return!1;const Vr=hr("hyperlinks.patch",Be,{target:ze.address,patch:{href:E}});Jr=Or(Vr);const Lr=un(Vr);if(!No(Lr.immediate))return!1;$e.push(Lr.immediate),Bt.push(Lr.settled),Xt=Lr.immediate,Nn=Lr.committed,Gn=Lr.settled}}catch{return!1}if(rt){const Vr=(Ar,Wo)=>No(Wo)?fi([Ar,Wo]):No(Ar)?Sf(Ar,Wo):Wo,Lr=Ar=>{if(!No(Ar))return Ar;try{const Wo=un(hr("text.replace",Ue,{target:je,text:Q}));return No(Wo.immediate)?Promise.all([Gn??Promise.resolve(Ar),Wo.settled]).then(([cb,OU])=>Vr(cb,OU)):Sf(Ar,Wo.immediate)}catch{return Sf(Ar,!1)}};if(Jr)return Pe=(Nn??Promise.resolve(Xt??!1)).then(Lr),fi($e);try{const Ar=un(hr("text.replace",Ue,{target:je,text:Q}));if(!No(Ar.immediate))return Xt?Sf(Xt,Ar.immediate):Ar.immediate;$e.push(Ar.immediate),Bt.push(Ar.settled),Pe=Promise.all([Gn??Promise.resolve(Xt??!1),Ar.settled]).then(([Wo,cb])=>Vr(Wo,cb))}catch{return Xt?Sf(Xt,!1):!1}}return!rt&&Bt.length>0&&(Pe=Promise.all(Bt).then(Vr=>fi(Vr))),fi($e)}if(typeof E=="string"&&E.trim()!==""){const Be=E.trim(),Ze=b.wrap,He=fH(U),Ue=He.length>0?He:V0(bt.selection);if(Ue.length>0){if(typeof Ze!="function")return!1;try{return Xn("hyperlinks.wrap",Ze,Ue,Bt=>({target:Bt,link:{destination:{href:Be}}}))}catch{return!1}}const je=b.insert,rt=hc(f,Be);if(typeof je!="function"||rt.trim()==="")return!1;const $e=kf(U)??$a(bt.selection);if(!$e)return!1;try{return hr("hyperlinks.insert",je,{target:$e,text:rt,link:{destination:{href:Be}}})}catch{return!1}}return!1},At=(f,v,b)=>{const A=f.create.kind,E=b&&typeof b=="object"?b:{};if(A==="table"){const Q=Number(E.rows??E.rowCount),re=Number(E.columns??E.cols??E.colCount);if(!Number.isInteger(Q)||Q<1||!Number.isInteger(re)||re<1)return!1;const ye=$a(bt.selection),Re=ye&&typeof ye.blockId=="string"?{kind:"inParagraph",target:mo(ye.blockId),offset:ye.range?.start??0}:W0(bt.selection,"nodeId");try{return hr(f.docRoute,v,{rows:Q,columns:re,at:Re})}catch{return!1}}if(A==="image"){const Q=E.src??E.value;if(typeof Q!="string"||Q.trim()==="")return!1;const re=$a(bt.selection),ye=na(bt.selection),Re=ye.storyType==="body"?null:ye;let ze;re&&typeof re.blockId=="string"?ze={kind:"inParagraph",target:mo(re.blockId,Re),offset:re.range?.start??0}:(ze=W0(bt.selection,"target"),Re&&ze.kind==="after"&&(ze={...ze,target:{...ze.target,story:Re}}));const Ye={src:Q,at:ze};Re&&(Ye.in=ze.kind==="inParagraph"?R(Re)??Re:Re),typeof E.alt=="string"&&(Ye.alt=E.alt),typeof E.title=="string"&&(Ye.title=E.title),E.size&&typeof E.size=="object"&&(Ye.size=E.size);try{return hr(f.docRoute,v,Ye)}catch{return!1}}const U={at:W0(bt.selection,"target")};typeof E.instruction=="string"&&(U.instruction=E.instruction),E.config&&typeof E.config=="object"&&(U.config=E.config);try{return hr(f.docRoute,v,U)}catch{return!1}},Gt=(f,v)=>{const b=f.table,A=Ne();if(!A||b.requiresCell&&!A.cellNodeId)return!1;const E=MH(b.action,A);if(!E)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const U=T(),Q=(typeof U?.getHandles=="function"?U.getHandles():null)?.editing?.tables;if(typeof Q?.insertRow!="function")return!1;const re=Hr(f.docRoute);return re&&re.success===!1?re:re?Q.insertRow(E,re):Q.insertRow(E)}return hr(f.docRoute,v,E)}catch{return!1}},vn=f=>!f||f.disposition!=="routed"?!1:!!(f.inline||f.blockParagraph||f.list||f.link||f.create),Cr=f=>{const v=fc(f);return!!(pc(f)||gu(v.hyperlinkTarget)||gu(v.textTarget))},Ur=(f,v,b)=>bt.selection.status!=="ready"?!1:rm(f)?.scope==="id"||!v||v.disposition!=="routed"?!0:v.inline?.kind==="clear"?Rr(bt.selection).length>0||vu(bt.selection)!=null:v.inline?vu(bt.selection)!=null||Rr(bt.selection).length>0:v.blockParagraph||v.list?Rr(bt.selection).length>0:v.link?Cr(b)||V0(bt.selection).length>0||$a(bt.selection)!=null||ha(v,y(),bt.selection):!0,uo=(f,v)=>{const b=rm(f),A=uu(f);return b?.scope!=="id"&&!vn(A)?!1:!Ur(f,A,v)},Ci=(f,v)=>uo(f,v)?ca().then(()=>{}):null,ri=(f,v,b)=>{if(Pe=null,Se=Promise.resolve(!1),be)return!1;const A=he.get(f);if(A)try{return co(A.execute(Ki(v,b)))}catch{return!1}const E=Yk(f);if(E&&typeof I()?.lists?.apply=="function")return q(E,v);const U=rm(f);if(U)return O(U,v);if(f==="copy-format")return co(sU());const Q=uu(f);if(!Q||Q.disposition!=="routed")return!1;const re=Q.normalizePayload?Q.normalizePayload(v):v;if(Q.instanceRoute){if(!S()||!gt(Q,re))return!1;const Ye=t?.[Q.instanceRoute];if(typeof Ye!="function")return!1;try{const Be=Q.fixedArg!==void 0?Q.fixedArg:re;return co(Ye.call(t,Be))}catch{return!1}}if(Q.inline?.kind==="clear")return Q.mutates&&br()==="viewing"?!1:co(tb());const ye=Q.docRoute;if(!ye||Q.mutates&&br()==="viewing")return!1;const Re=y(),ze=gr(Re,ye);if(!ze)return!1;if(Q.inline){const{lockModesById:Ye}=vs(Re?.contentControls,bt.selection);if(Xi(Ye))return!1;const Be=vu(bt.selection);if(!Be)return bt.selection.empty===!1?co(!1):co(am(Q,re));const Ze=ha(Q,Re,bt.selection),He=TH(Q.inline,Be,re,Ze);if(!He)return!1;let Ue=null;try{const je=S(),rt=br(),$e=()=>S()!==je||y()!==Re||br()!==rt?!1:Of(ye,ze,He),Bt=ia(bt.selection)??Ql(bt.selection),Xt=Q.inline.kind==="toggle"?fr(`${Q.id}:${Bt}`,$e):null;Ue=Xt?.release??null;const Nn=Xt?Xt.result:$e(),Gn=_l(Q,bt.selection,He,Nn),Jr=co(Cl(Q,bt.selection,He,Nn),Vr=>{$0(Q,Gn,Vr),Ue?.(),Ue=null});return Q.inline.kind==="toggle"&&(ht=Se),Jr}catch{return Ue?.(),!1}}if(Q.blockParagraph){const Ye=lm(Q,ze,re),Be=Q.blockParagraph.kind==="alignment"&&No(Ye)?D(bt.selection,re):null;return co(Ye,Ze=>{ee(Be,Ze)})}if(Q.list)return co(um(Q,ze));if(Q.link)return co(Ff(re));if(Q.create)return co(At(Q,ze,re));if(Q.table)return co(Gt(Q,ze));try{return co(Q.mutates?hr(ye,ze,re):ze(re))}catch{return!1}},wa=()=>{m+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const f of p)f("idle");jt()},sU=async()=>{const f=["bold","italic","underline","strikethrough"].filter(ze=>bt.toolbar.commands[ze]?.active===!0),v=await ht;await c;const b=No(v)?f:[],A=500,E=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&E-h.lastClickAt<A){h={...h,mode:"persistent",lastClickAt:E};for(const ze of p)ze("persistent");return jt(),!0}return wa(),!1}const U=E-h.lastClickAt<A,Q=++m;h={...h,lastClickAt:E};const re=await ca(),ye=`${Ql(re)}:${Ft()}`,Re=await aU(null,re,ye&&ye===k?g:void 0,b);if(Q!==m)return!0;h={...h,mode:U?"persistent":"armed",snapshot:Re,sourceSelectionKey:Ql(re),lastClickAt:E};for(const ze of p)ze(h.mode);return jt(),!0},aU=async(f,v,b,A=[])=>{const E=v?.target??f?.target;if(!E||E.kind!=="text")return null;const U=Array.isArray(E.segments)?E.segments:[];if(U.length===0)return null;const Q=y();if(!Q)return null;const re=E.story;let ye=null;for(const He of U){const Ue=(await da(mo(He.blockId,re)))?.node??null;if(!Ue)continue;const je=nb(Ue),rt=lU(Array.isArray(je?.inlines)?je.inlines:[],He.range);ye?ye=fA(ye,rt):ye=rt}const Re=ye?Fz(ye):{},ze={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},Ye=new Set([...v?.activeMarks??(Array.isArray(f?.activeMarks)?f.activeMarks:[]),...A]);for(const[He,Ue]of Object.entries(ze))Ye.has(He)&&(Re[Ue]=!0);const Be=b??await Iu(v??la(f,"ready"));if(Be.fontFamily&&(Re.fontFamily=Be.fontFamily),Be.color&&(Re.color=Be.color),Be.highlight&&(Re.highlight=Be.highlight),Be.fontSize){const He=Number.parseFloat(Be.fontSize);Number.isNaN(He)||(Re.fontSize=He)}let Ze=null;if(U.length===1){const He=U[0],Ue=(await da(mo(He.blockId,re)))?.node??null;Ue&&nb(Ue)&&(Ze=await cU(Ue,He.blockId,Q,re))}return{story:re??null,inline:Re,paragraph:Ze}},nb=f=>f?f.kind==="paragraph"?f.paragraph??null:f.kind==="heading"?f.heading??null:null:null,lU=(f,v)=>{const b=Q=>{const re=Q.run;return typeof re?.text=="string"?re.text:""},A=Q=>Q.run?.props;if(v.start===v.end){let Q=0;for(const re of f){const ye=b(re),Re=Q,ze=Q+ye.length;if(Q=ze,v.start>=Re&&v.start<=ze){const Ye=A(re);return Ye?{...Ye}:{}}}return{}}let E=0;const U=[];for(const Q of f){const re=b(Q),ye=E,Re=E+re.length;if(E=Re,Re<=v.start||ye>=v.end)continue;const ze=A(Q);ze&&U.push(ze)}return U.length===0?{}:U.length===1?{...U[0]}:fA(U[0],...U.slice(1))},fA=(f,...v)=>{const b={...f};for(const A of v)for(const E of Object.keys(b)){if(!(E in A)){delete b[E];continue}const U=b[E],Q=A[E];(typeof U!=typeof Q||JSON.stringify(U)!==JSON.stringify(Q))&&delete b[E]}return b},cU=async(f,v,b,A)=>{const E=nb(f),U=E.props??{},Q=E.styleRef??null,re=U.alignment??null,ye=U.spacing??null,Re=U.indent??null,ze=Re?{...Re.left!=null?{left:Re.left}:{},...Re.right!=null?{right:Re.right}:{},...Re.firstLine!=null?{firstLine:Re.firstLine}:{},...Re.hanging!=null?{hanging:Re.hanging}:{}}:null,Ye=U.markRunProps??null,Be=U.numbering?.numId,Ze=typeof Be=="string"?parseInt(Be,10):typeof Be=="number"?Be:NaN,He=U.numbering?.level,Ue=isNaN(Ze)?null:{numId:Ze,...He!=null?{level:He}:{}};let je=null;if(Ue&&typeof b.lists?.getState=="function")try{const rt=await b.lists.getState({target:mo(v,A)});rt&&typeof b.lists?.getStyle=="function"&&(je=await b.lists.getStyle(rt)??null)}catch{}return{styleId:Q,alignment:re,spacing:ye,indentation:ze,markRunProps:Ye,numbering:Ue,listStyle:je}},hA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const f=y()?.selection,v=async()=>Ri(typeof f?.current=="function"?await Promise.resolve(f.current({includeText:!0})):ll().value),b=()=>new Promise(Q=>setTimeout(Q,16)),A=8;let E=null,U="";for(let Q=0;Q<A;Q+=1){if(Q>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(E=await v(),!(!E||E.empty)&&(U=Ql(E),U!==h.sourceSelectionKey))break}if(E&&!E.empty&&U!==h.sourceSelectionKey){await pA(E);return}if(h.snapshot?.paragraph){const Q=await v();if(!Q||Ql(Q)===h.sourceSelectionKey)return;await pA(Q)}},pA=async f=>{const v=h.snapshot;if(!v){h.mode==="armed"&&wa();return}const b=y();if(!b)return;const A=la(f,"ready"),{lockModesById:E}=vs(b.contentControls,A);if(Xi(E)){jt();return}const U=f.target,Q=f.selectionTarget;if(f.empty!==!0&&Object.keys(v.inline).length>0){const re=gr(b,"format.apply");if(re&&Q)try{if(!No(el(await Promise.resolve(Of("format.apply",re,{target:Q,inline:v.inline},f))))){jt();return}}catch{jt();return}}if(v.paragraph){const re=Array.isArray(U?.segments)?U.segments:[],ye=U?.story;for(const Re of re){const ze=mo(Re.blockId,ye),Ye=await da(ze),Be=Ye?.node??null,Ze=Ye?.address??null;if(!Be)continue;const He={kind:"block",nodeType:Ze?.nodeType??Be.kind??"paragraph",nodeId:Re.blockId,...ye&&typeof ye=="object"?{story:ye}:{}},{styleId:Ue,alignment:je,spacing:rt,indentation:$e,markRunProps:Bt,numbering:Xt,listStyle:Nn}=v.paragraph;if(Ue&&await b.styles?.paragraph?.setStyle?.({target:He,styleId:Ue}),je&&await b.format?.paragraph?.setAlignment?.({target:He,alignment:je}),rt){const Gn=rt,Jr=Gn.lineRule??"auto",Vr=new Set(["auto","exact","atLeast"]).has(Jr)?Jr:"auto",Lr={...Gn.before!=null?{before:Math.round(Gn.before*20)}:{},...Gn.after!=null?{after:Math.round(Gn.after*20)}:{},...Gn.line!=null?{line:Math.round(Vr==="auto"?Gn.line*240:Gn.line*20),lineRule:Vr}:{}};await b.format?.paragraph?.setSpacing?.({target:He,...Lr})}if($e){const Gn={...$e.left!=null?{left:ms($e.left)}:{},...$e.right!=null?{right:ms($e.right)}:{},...$e.firstLine!=null?{firstLine:ms($e.firstLine)}:{},...$e.hanging!=null?{hanging:ms($e.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:He,...Gn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:He,markRunProps:Bt}),Xt&&await b.format?.paragraph?.setNumbering?.({target:He,...Xt}),Nn&&((await da(ze))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:eA(Re.blockId,ye),style:Nn}):Xt&&await b.format?.paragraph?.setNumbering?.({target:He,...Xt}))}}h.mode==="armed"&&wa(),jt()},fm=(f,v,b)=>{const A=Ci(f,v),E=A?A.then(()=>(ri(f,v,b),Se)):(ri(f,v,b),Se);return uu(f)?.inline?.kind==="toggle"&&(ht=E),E},mA=f=>({id:f,getState:()=>bt.toolbar.commands[f]??Ru(f,y(),bt.selection,pl(bt.selection)),observe:v=>Go(b=>b.toolbar.commands[f]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:at.commandUnsupported}).subscribe(v),execute:v=>ri(f,v),executeAsync:v=>fm(f,v)}),uU=f=>{he.set(f.id,f),jt();const v=()=>{he.delete(f.id),jt()};return Object.assign(v,{handle:mA(f.id),unregister:v})},hm=lo(f=>f.selection),pm=Qr(hm),gA=()=>{const f=T();if(typeof f?.getHandles!="function")return{reason:at.hostCapabilityUnavailable};let v=null;try{v=f.getHandles()}catch(A){const E=A?.reason;return{reason:E==="host-not-ready"||E==="host-disposed"||E==="editing-mount-required"?at.notReady:at.hostCapabilityUnavailable}}const b=v?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:at.hostCapabilityUnavailable}:{helper:b}},vA={get:pm.get,getSnapshot:pm.getSnapshot,subscribe:pm.subscribe,observe:pm.observe,current:()=>ll().value,capture:()=>{const f=hm.get();return f.empty||!f.target&&!f.selectionTarget?null:{...f,capturedAt:Date.now()}},restore:f=>{const v=E=>(jt(),{...E,success:E.ok});if(!f||typeof f!="object")return v({ok:!1,reason:at.targetUnresolved});if(!S())return v({ok:!1,reason:at.notReady});const b=EH(f);if(!b)return v({ok:!1,reason:at.targetUnresolved});const A=gA();if(!("helper"in A))return v({ok:!1,reason:A.reason});try{return v(qk(A.helper.apply(b)))}catch{return v({ok:!1,reason:at.hostCapabilityUnavailable})}},apply:f=>{if(!S())return{ok:!1,reason:at.notReady};const v=gA();if(!("helper"in v))return{ok:!1,reason:v.reason};try{const b=v.helper.apply(f);return jt(),qk(b)}catch{return{ok:!1,reason:at.hostCapabilityUnavailable}}},getAnchorRect:f=>{const v=T();if(typeof v?.getSelectionAnchorRect=="function"){const b=Tt(()=>v.getSelectionAnchorRect(f),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:f=>{const v=hm.get(),b=v.selectionTarget??v.target;if(v.empty||!b)return[];const A=km.getRect({target:b,relativeTo:f?.relativeTo});return A.found?A.rects:[]}},dU={get ids(){return it()},has:f=>uu(f)!=null||he.has(f),get:f=>mA(f),execute:ri,executeAsync:fm,register:uU,getContextMenuItems:f=>{const v=[];for(const b of he.values()){const A=b.contextMenu;A&&Tt(A.when?()=>A.when(f):void 0,!0)&&v.push({id:b.id,label:A.label,group:A.group,order:A.order,invoke:()=>ri(b.id,void 0,f)})}return v.sort((b,A)=>(b.order??0)-(A.order??0)||b.label.localeCompare(A.label))}},rb=Qr(lo(f=>f.toolbar)),fU={get:rb.get,getSnapshot:()=>bt.toolbar,subscribe:rb.subscribe,observe:rb.observe,execute:ri,executeAsync:fm},mc=async(f,v)=>{if(!S())return{success:!1,ok:!1,reason:at.notReady};if(!f)return{success:!1,ok:!1,reason:at.targetUnresolved};const b=T(),A=b?.scrollTargetIntoView;if(typeof A!="function")return{success:!1,ok:!1,reason:at.hostCapabilityUnavailable};try{const E=await Promise.resolve(A.call(b,{target:f,block:v?.block??"center",behavior:v?.behavior??"smooth"}));return E&&typeof E=="object"&&E.success===!1?{success:!1,ok:!1,reason:z0(E.reason,at.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:at.hostCapabilityUnavailable}}},mm=async(f,v,b,A)=>{const E=f==="trackChanges"?A?.story:void 0,U=ze=>{if(!E||!ze||typeof ze!="object")return ze;const Ye=ze,Be=Ye.address&&typeof Ye.address=="object"?Ye.address:null;return Ye.story||Be?.story?ze:{...Ye,story:E}},Q=H0(b.find(ze=>Ja(ze,v,E)));if(Q)return U(Q);const re=y()?.[f],ye=f==="comments"?{commentId:v}:{id:v,...E?{story:E}:{}},Re=re?.get;if(typeof Re!="function")return null;try{return U(H0(await Promise.resolve(Re.call(re,ye))))}catch{return null}};function yA(f,v){if(bi())return ar("Comments are read-only.","DOCUMENT_READONLY");if(yu())return ar("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,A=b?.patch;if(typeof A!="function")return ar("comments.patch is unavailable.");const E=ar("comments.patch failed.");return Tt(()=>ba(A.call(b,{commentId:f,status:v}),E),E)}const gm=()=>bi()?ar("Comments are read-only.","DOCUMENT_READONLY"):null,bA=(f,v)=>{const b=v&&typeof v=="object"?v:null;let A=Array.from(f);b?.includeResolved===!1&&(A=A.filter(ye=>ye.status!=="resolved"));const E=Number(b?.offset),U=Number.isInteger(E)&&E>0?E:0,Q=Number(b?.limit),re=Number.isInteger(Q)&&Q>=0?U+Q:void 0;return A.slice(U,re)},Bu=lo(f=>f.comments),vm=Qr(Bu),hU={get:vm.get,getSnapshot:vm.getSnapshot,subscribe:vm.subscribe,observe:vm.observe,list:f=>{const v=Bu.get();if(v.status!=="pending")return bA(v.items,f);const b=y()?.comments,A=Tt(b?.list?()=>b.list(f):void 0,null);return Or(A)?[]:bA(Array.isArray(A?.items)?A.items:[],f)},getById:f=>{const v=Bu.get().items.find(E=>Hn(E)===f)??null;if(v)return v;const b=y()?.comments,A=Tt(b?.get?()=>b.get({commentId:f}):void 0,null);return Or(A)?null:A},createFromCapture:(f,v)=>{const b=gm();if(b)return b;const A=y()?.comments,E=A?.create;if(typeof E!="function")return ar("comments.create is unavailable.");const U=ar("comments.create failed.");return Tt(()=>ba(E.call(A,{target:f.target??f.selectionTarget,text:v.text}),U),U)},createFromSelection:f=>{const v=gm();if(v)return v;const b=y()?.comments,A=b?.create;if(typeof A!="function")return ar("comments.create is unavailable.");const E=hm.get(),U=E.target??E.selectionTarget;if(E.empty||!U)return ar("A range selection is required to comment.","NO_SELECTION");const Q=ar("comments.create failed.");return Tt(()=>ba(A.call(b,{target:U,text:f.text}),Q),Q)},reply:(f,v)=>{const b=gm();if(b)return b;const A=y()?.comments,E=A?.reply??A?.create;if(typeof E!="function")return ar("comments.reply is unavailable.");const U=ar("comments.reply failed.");return Tt(()=>ba(E===A?.reply?E.call(A,{parentCommentId:f,text:v.text}):E.call(A,{parentCommentId:f,text:v.text}),U),U)},resolve:f=>yA(f,"resolved"),reopen:f=>yA(f,"active"),delete:f=>{const v=gm();if(v)return v;const b=y()?.comments,A=b?.delete??b?.remove;if(typeof A!="function")return ar("comments.delete is unavailable.");const E=ar("comments.delete failed.");return Tt(()=>ba(A.call(b,{commentId:f}),E),E)},setActive:f=>{if(f==null)return ge=null,jt(),!0;if(!S())return!1;const v=Bu.get();if(v.listStatus!=="ready")return!1;const b=lH(v.items,f);return!b||!v.items.some(A=>Hn(A)===b)?!1:(ge=b,jt(),!0)},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:S()?at.documentApiUnavailable:at.notReady};const v=await mm("comments",f,Bu.get().items);return v?mc(v):{success:!1,ok:!1,reason:at.targetUnresolved}}},Ca=lo(f=>f.trackChanges),ob=(f,v)=>{const b=Ca.get().items.filter(Re=>Hn(Re)!==null);if(b.length===0)return null;const A=bt.trackChanges.activeId,E=ae?.id===A?ae.story:void 0;let U=A?b.findIndex(Re=>Ja(Re,A,E)):-1;U===-1&&A&&E&&(U=b.findIndex(Re=>Ja(Re,A)));const Q=b[U===-1?f>0?0:b.length-1:(U+f+b.length)%b.length],re=Hn(Q),ye=Qk(Q);return Je(ye?{id:re,story:ye}:{id:re},v),jt(),re};let wA=Promise.resolve();const pU=f=>{const v=oe;return wA.catch(()=>{}).then(()=>mU(f,v))},mU=async(f,v)=>{if(oe!==v)return{success:!1};const b=ae,A=ob(f,{invalidateQueuedNavigation:!1});if(A==null)return{success:!1};const E=ae,U=_e,Q=()=>ae===E&&_e===U,re=()=>{Q()&&(Je(b,{invalidateQueuedNavigation:!1}),jt())},ye=await mm("trackChanges",A,Ca.get().items,E?.story?{story:E.story}:void 0);if(!Q())return{success:!1};if(!ye)return re(),{success:!1};ao+=1;try{const Re=await mc(ye,{behavior:"auto"});return Q()?(!Re.ok&&Re.reason!==at.targetNotVisible?(re(),Ge(b)):Ge(E),{success:Re.ok}):{success:!1}}finally{ao=Math.max(0,ao-1),ao===0&&(Q()?zr&&Po(Pi(zr)):Ge(ae))}},CA=f=>{const v=pU(f);return wA=v.then(()=>{},()=>{}),v},ym=Qr(Ca),gU={get:()=>(Fr(),ym.get()),getSnapshot:()=>(Fr(),ym.getSnapshot()),subscribe:f=>(Fr(),ym.subscribe(f)),observe:f=>(Fr(),ym.observe(f)),list:()=>(Fr(),Ca.get().items),accept:f=>_A("accept",f),reject:f=>_A("reject",f),acceptAll:()=>Nu("accept",{scope:"all"},null),rejectAll:()=>Nu("reject",{scope:"all"},null),next:()=>ob(1),previous:()=>ob(-1),navigateNext:()=>CA(1),navigatePrevious:()=>CA(-1),getAt:f=>{if(!f||typeof f!="object"||typeof f.x!="number"||typeof f.y!="number")return null;const v=sb(f);if(v.length===0)return null;const b=Ca.get().items;let A;for(const E of v){if(E.type!=="trackedChange")continue;let U;if(E.story){if(A===void 0&&(A=Lo()),!A)continue;U=A}else U=b;const Q=U.find(re=>Ja(re,E.id,E.story));if(Q)return E.story?{id:Q.id,item:Q,story:E.story}:{id:Q.id,item:Q}}return null},setActive:f=>{if(f==null)return Je(null),Ge(null),jt(),!0;if(!S())return!1;const v=typeof f=="string"?{id:f}:{id:f.id,story:f.story};if(typeof v.id!="string"||v.id.length===0)return!1;const b=v.id;if(v.story){const A=Lo();if(!A)return!1;const E=$k(A,v.story).toPublicId(v.id)??v.id;if(!A.some(U=>Ja(U,E,v.story)))return!1;v.id=E}else{const A=Ca.get().items,E=em(A).toPublicId(v.id)??v.id;if(!A.some(U=>Hn(U)===E))return!1;v.id=E}return b!==v.id&&(v.paintedEntityId=b),Je(v),Ge(v),jt(),!0},scrollTo:async f=>{if(!y())return{success:!1,ok:!1,reason:S()?at.documentApiUnavailable:at.notReady};const v=Ca.get().items,b=Qk(v.find(ze=>Hn(ze)===f)),A=await mm("trackChanges",f,v,b?{story:b}:void 0);if(!A)return{success:!1,ok:!1,reason:at.targetUnresolved};const E=ae,U=b?{id:f,story:b}:{id:f};Je(U),jt();const Q=ae,re=_e,ye=()=>ae===Q&&_e===re,Re=()=>{ye()&&(Je(E,{invalidateQueuedNavigation:!1}),jt())};ao+=1;try{const ze=await mc(A,{behavior:"auto"});return ye()?(!ze.ok&&ze.reason!==at.targetNotVisible?(Re(),Ge(E)):Ge(U),ze):{success:!1,ok:!1}}finally{ao=Math.max(0,ao-1),ao===0&&(ye()?zr&&Po(Pi(zr)):Ge(ae))}}},_A=(f,v)=>{const{id:b,story:A}=typeof v=="string"?{id:v,story:void 0}:v;return Nu(f,{kind:"id",id:b,...A?{story:A}:{}},b,A)},Nu=(f,v,b,A)=>{try{return co(vU(f,v,b,A))}catch{return!1}},vU=(f,v,b,A)=>{if(bi())return!1;const E=y()?.trackChanges,U=v.scope==="all",Q=v.kind==="range",re=v.kind==="ids";if(ic({kind:f,scope:U?"all":"id"},E))return!1;const ye=U?`${f}All`:f,Re=!Q&&!re&&!A&&E&&typeof E[ye]=="function"?E[ye]:null,ze=E&&typeof E.decide=="function"?E.decide:null;return!Re&&!ze?!1:Re?Re.call(E,b??{}):ze.call(E,{decision:f,target:v})},ib=lo(f=>f.contentControls),Bf=f=>ib.get().items.find(v=>v?.id===f)??null,bm=Qr(ib),yU=(f=>{if(f===void 0)return bm.get();const v=$p(f);return v?Bf(v):null}),bU={get:(f=>(f!==void 0&&cn("api"),yU(f))),getSnapshot:bm.getSnapshot,subscribe:bm.subscribe,observe:bm.observe,list:()=>(cn("api"),ib.get().items),getById:f=>(cn("api"),Bf(f)),getRect:f=>{const v=$p(f);if(!v)return tl("unresolved");cn("panel");const b=Bf(v);if(!b)return tl("unresolved");const A=U0(b);return A?km.getRect({target:A}):tl("unavailable")},scrollIntoView:async f=>{const v=$p(f);if(!v)return{success:!1};cn("panel");const b=Bf(v);if(!b)return{success:!1};const A=U0(b);return A?{success:(await mc(A,{block:f.block,behavior:f.behavior})).ok}:{success:!1}},focus:async f=>{const v=$p(f);if(!v)return{success:!1,reason:"invalid-id"};if(!S())return{success:!1,reason:"not-ready"};cn("panel");const b=Bf(v);if(!b)return{success:!1,reason:"not-found"};const A=U0(b);if(!A)return{success:!1,reason:"not-reachable"};if(!(await mc(A,{block:f.block,behavior:f.behavior})).ok)return{success:!1,reason:"not-reachable"};const E=iH(A);if(!E)return{success:!1,reason:"not-reachable"};const U=vA.apply(E);return!U.ok&&U.reason!==at.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:{success:!0}}},wm=Qr(lo(f=>f.fonts)),wU={get:wm.get,getSnapshot:wm.getSnapshot,subscribe:wm.subscribe,observe:wm.observe,getFamilyOptions:()=>bt.fonts.options,getSizeOptions:()=>bt.fonts.sizeOptions},Cm=Qr(lo(f=>f.zoom)),CU={get:Cm.get,getSnapshot:Cm.getSnapshot,subscribe:Cm.subscribe,observe:Cm.observe,set:f=>{if(typeof t?.setZoom=="function")try{t.setZoom(f),jt()}catch{}},setMode:f=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(f),jt()}catch{}}},_m=Qr(lo(f=>f.document)),_U={get:_m.get,getSnapshot:_m.getSnapshot,subscribe:_m.subscribe,observe:_m.observe,setMode:f=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(f),jt()}catch{}},export:f=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(f))}catch{return}},getText:()=>{const f=y(),v=Tt(f?.getText?()=>f.getText({}):void 0,null);return typeof v=="string"?v:v&&typeof v=="object"&&typeof v.text=="string"?v.text:null},replaceFile:f=>{const v=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof v=="function")try{return Promise.resolve(v.call(t,f))}catch{return}}},SA=()=>{if(typeof HTMLElement>"u")return null;const f=S()?.mount?.container;if(f instanceof HTMLElement)return f;const v=t?.element;return v instanceof HTMLElement?v:null},SU=(f,v)=>{if(typeof f!="number"||typeof v!="number"||!Number.isFinite(f)||!Number.isFinite(v))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const A=SA();if(!A)return[];const E=b.elementFromPoint(f,v);if(!E||!A.contains(E))return[];const U=[E],Q=$e=>{$e&&A.contains($e)&&!U.includes($e)&&U.push($e)},re=b.elementsFromPoint;if(typeof re=="function"){let $e=[];try{$e=re.call(b,f,v)??[]}catch{$e=[]}for(const Bt of $e)Q(Bt)}const ye=[],Re=$e=>{$e&&A.contains($e)&&!ye.includes($e)&&!U.includes($e)&&ye.push($e)},ze=$e=>{const Bt=$e.getBoundingClientRect;if(typeof Bt!="function")return!1;let Xt;try{Xt=Bt.call($e)}catch{return!1}return Xt!=null&&f>=Xt.left&&f<=Xt.right&&v>=Xt.top&&v<=Xt.bottom};for(const $e of U){const Bt=$e.querySelectorAll;if(typeof Bt!="function")continue;let Xt;try{Xt=Bt.call($e,"[data-track-change-marker]")}catch{continue}for(let Nn=0;Nn<Xt.length;Nn+=1)ze(Xt[Nn])&&Re(Xt[Nn])}ye.reverse();const Ye=[...ye,...U],Be=Wk(Ye[0],A);for(let $e=1;$e<Ye.length;$e+=1)for(const Bt of Wk(Ye[$e],A))Be.push(Bt);if(Be.length===0)return Be;const Ze=Ca.get().items,He=em(Ze);let Ue;const je=new Set,rt=[];for(const $e of Be){if($e.type!=="trackedChange"){const Gn=`${$e.type}:${$e.id}`;if(je.has(Gn))continue;je.add(Gn),rt.push($e);continue}const Bt=oH($e.storyKey)??rH($e.story);let Xt;if(Bt){if(Ue===void 0&&(Ue=Lo()),!Ue||(Xt=$k(Ue,Bt).toPublicId($e.id),!Xt||!Ue.some(Gn=>Ja(Gn,Xt,Bt))))continue}else if(Xt=He.toPublicId($e.id),!Xt)continue;const Nn=`trackedChange:${Xt}`;je.has(Nn)||(je.add(Nn),rt.push(Bt?{type:"trackedChange",id:Xt,story:Bt}:{type:"trackedChange",id:Xt}))}return rt};function sb(f,v){return typeof f=="object"?SU(f?.x,f?.y):null}const zu=new Set;let ab=!1;const kA=f=>{const v=T();if(typeof v?.observeGeometry!="function")return;let b=!1;const A=Tt(()=>{const E=v.observeGeometry(()=>f.schedule());return b=!0,E},null);f.detach=typeof A=="function"?A:null,f.boundHost=b?v:null},Sm=f=>{if(f.detach){try{f.detach()}catch{}f.detach=null}f.boundHost=null},AA=()=>{if(ab=!1,!(be||T()))for(const f of zu)Sm(f)},kU=()=>{if(!ab){if(ab=!0,typeof queueMicrotask=="function"){queueMicrotask(AA);return}Promise.resolve().then(AA)}},AU=()=>{const f=T();if(!f){kU();return}for(const v of zu)v.boundHost&&v.boundHost===f||(Sm(v),kA(v),v.schedule())};_s.push(AU);const km={getRect:f=>{const v=T(),b=v?.getTargetRects;if(typeof b=="function"){const A=Tt(()=>b.call(v,{target:f.target}),null);return A&&typeof A=="object"?A.success===!0&&Array.isArray(A.rects)?AH(kH(A.rects.filter(E=>E!=null&&typeof E=="object")),f.relativeTo):tl(typeof A.reason=="string"?A.reason:"unresolved"):tl("unresolved")}return tl("unavailable")},observe:f=>{const v=[];let b=0;const A=typeof requestAnimationFrame=="function",E=()=>{if(!A){f();return}b||(b=requestAnimationFrame(()=>{b=0,f()}))},U=Go(re=>({ready:re.ready,selection:re.selection,zoom:re.zoom}));v.push(U.subscribe(()=>E()));const Q={schedule:E,detach:null,boundHost:null};return kA(Q),zu.add(Q),()=>{zu.delete(Q),Sm(Q),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const re of v.splice(0))try{re()}catch{}}},getHost:()=>SA(),entityAt:sb,contextAt:f=>{const v=!!f&&typeof f.x=="number"&&typeof f.y=="number",b=v?f.x:0,A=v?f.y:0;return{point:{x:b,y:A},entities:v?sb({x:b,y:A}):[],selection:bt.selection,position:null,insideSelection:!1}},scrollIntoView:async f=>{const v=f?.target;if(!v)return{success:!1};let b=null;if(v.kind==="entity"){const A=v.entityType==="comment"?"comments":"trackChanges",E=A==="comments"?Bu.get().items:Ca.get().items,U=v.entityType==="trackedChange"&&v.story?{story:v.story}:void 0;b=await mm(A,v.entityId,E,U)}else{const A=v,E=v,U=Array.isArray(A.segments)&&A.segments.length>0?A.segments:E.blockId&&E.range?[{blockId:E.blockId,range:E.range}]:null;if(U){const Q=v.story;b={kind:"text",segments:U,...Q?{story:Q}:{}}}}return b?{success:(await mc(b,{block:f.block??"center",behavior:f.behavior??"smooth"})).ok}:{success:!1}}},IA=f=>{const v=(f&&typeof f=="object"?f:null)?.target;return v&&typeof v=="object"?v:null},EA=f=>`metadata:resolve:${f}`,IU=f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return null;const{value:b}=Yn(EA(f),Ft(),()=>v.resolve({id:f}),IA);return b},EU=async f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return null;try{const b=Ft(),A=await Promise.resolve(v.resolve({id:f}));if(b!==Ft())return null;const E=IA(A);return Le.set(EA(f),{token:b,value:E,hasSettled:!0,inflightToken:null}),E}catch{return null}},xU={getRect:f=>{const v=y()?.metadata;if(!v||typeof v.resolve!="function")return tl("unavailable");const b=IU(f.id);return b?km.getRect({target:b}):tl("unresolved")},scrollIntoView:async f=>{const v=await EU(f.id);return v?{success:(await mc(v,{block:f.block,behavior:f.behavior})).ok}:{success:!1}}},TU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},RU={getContext:()=>{const f=Ne();if(!f)return{...TU};const v=fe()?.table;return{inTable:!0,tableNodeId:f.tableNodeId,rowIndex:f.rowIndex,columnIndex:f.columnIndex,cellNodeId:f.cellNodeId,rows:typeof v?.rows=="number"?v.rows:null,columns:typeof v?.columns=="number"?v.columns:null}},isInTable:()=>Ne()!=null},Am={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:at.searchUnavailable};let xn={...Am};const Im=new Set,_a=()=>{const f=T()?.search;return f&&typeof f=="object"?f:null},Ss=()=>{const f=I()?.search;return f&&typeof f=="object"?f:null},Nf=()=>{const f=_a();if(f&&typeof f.setSession=="function")return!0;const v=Ss();return!!v&&typeof v.query=="function"&&typeof v.getState=="function"},Zi=()=>{for(const f of[...Im])try{f(xn)}catch{}},oi=f=>(xn={...xn,...f},Zi(),xn);let Zr=0,gc=null;const xA=()=>{const f=gc;gc=null,f&&Tt(()=>(f(),null),null)},MU=()=>{Zr+=1,xA();const f=Nf();xn={...Am,available:f,reason:f?void 0:at.searchUnavailable},Zi()};Pu.push(MU);const LU=f=>{if(!f)return!1;const v=f.queryError;if(v&&typeof v=="object"&&v.code==="invalid-pattern")return!0;const b=f.rejection;return f.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},lb=(f,v=!1)=>{const b=f&&typeof f=="object"?f:null;if(!b)return null;const A=Array.isArray(b.matches)?b.matches:[],E=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:A.length,U=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:E,activeIndex:U,canReplace:b.canReplace===!0||v,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...LU(b)?{invalidPattern:!0}:{}}},wo=()=>{const f=L("find.replace"),v=L("find.replaceAll");return f?.enabled===!0||v?.enabled===!0},Co=(f,v=!1)=>{const b=lb(f,v);if(!b){oi({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}oi({...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?at.searchInvalidPattern:void 0})},Sa=()=>{const f=_a();if(f&&typeof f.getState!="function")return xn={...xn,available:Nf(),reason:Nf()?void 0:at.searchUnavailable},xn;if(!f){const b=Ss();if(b&&typeof b.getState=="function"){const A=lb(Tt(()=>b.getState(),null),wo());if(A)return xn={...xn,...A.query!==void 0?{query:A.query}:{},total:A.total,activeIndex:A.activeIndex,canReplace:A.canReplace,available:!0,reason:A.invalidPattern?at.searchInvalidPattern:void 0,open:xn.open||!!A.query},xn}return xn={...Am,query:xn.query,caseSensitive:xn.caseSensitive,includeDeletedText:xn.includeDeletedText},xn}const v=lb(Tt(()=>f.getState(),null));return v&&(xn={...xn,...v.query!==void 0?{query:v.query}:{},total:v.total,activeIndex:v.activeIndex,canReplace:v.canReplace,...v.includeDeletedText!==void 0?{includeDeletedText:v.includeDeletedText}:{},...v.regex!==void 0?{regex:v.regex}:{},available:!0,reason:v.invalidPattern?at.searchInvalidPattern:void 0,open:xn.open||!!v.query}),xn},Hu=f=>{const v=f&&typeof f=="object"?f:null;if(v?.status==="committed")return{ok:!0};if(v?.status==="rejected"&&v.reason==="read-only")return{ok:!1,reason:at.documentReadonly};const b=v?.rejection;return v?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:at.documentReadonly}:{ok:!1,reason:at.operationUnavailable}},Em=Qr({get:()=>Sa(),subscribe:f=>(Im.add(f),()=>Im.delete(f))}),DU={get:Em.get,getSnapshot:Em.getSnapshot,subscribe:Em.subscribe,observe:Em.observe,open:()=>Nf()?(oi({available:!0,open:!0,reason:void 0}),{ok:!0}):(oi({available:!1,open:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}),close:()=>{if(Zr+=1,gc)xA();else{const f=_a();if(f&&typeof f.clear=="function")Tt(()=>f.clear(),null);else{const v=Ss();v&&typeof v.query=="function"&&Tt(()=>v.query({query:""}),null)}}xn={...Am,available:Nf(),reason:void 0},xn.available||(xn.reason=at.searchUnavailable),Zi()},search:(f,v)=>{const b=_a(),A=!!v?.caseSensitive,E=v?.includeDeletedText===!0,U=v?.regex===!0,Q=++Zr;if(!b||typeof b.setSession!="function"){const re=Ss();if(re&&typeof re.query=="function"&&typeof re.getState=="function"){oi({query:f,caseSensitive:A,includeDeletedText:E,regex:U,available:!0,open:!0,reason:void 0}),gc=()=>{re.query({query:""})};const ye=Tt(()=>re.query({query:f,caseSensitive:A,includeDeletedText:E,regex:U}),null);return Or(ye)?Promise.resolve(ye).then(Re=>{Q===Zr&&Co(Re,wo())},()=>{Q===Zr&&oi({available:!1,reason:at.searchUnavailable})}):Co(ye,wo()),Co(Tt(()=>re.getState(),null),wo()),xn}return oi({query:f,total:0,activeIndex:-1,available:!1,caseSensitive:A,includeDeletedText:E,regex:U,reason:at.searchUnavailable})}if(oi({query:f,caseSensitive:A,includeDeletedText:E,regex:U,available:!0,open:!0,reason:void 0}),gc=()=>{typeof b.clear=="function"&&b.clear()},Co(Tt(()=>b.setSession(f,{caseSensitive:A,includeDeletedText:E,...U?{regex:!0}:{},highlight:!0}),null)),f.length>0&&xn.total===0&&xn.reason!==at.searchInvalidPattern){const re=Ss();if(re&&typeof re.query=="function"&&typeof re.getState=="function"){const ye=gc;gc=()=>{ye?.(),re.query({query:""})};const Re=Tt(()=>re.query({query:f,caseSensitive:A,includeDeletedText:E,regex:U}),null);Or(Re)?Promise.resolve(Re).then(ze=>{Q===Zr&&Co(ze,wo())},()=>{Q===Zr&&oi({available:!1,reason:at.searchUnavailable})}):Co(Re,wo()),Co(Tt(()=>re.getState(),null),wo())}}return xn},next:()=>{const f=_a();if(!f||typeof f.next!="function"){const v=Ss();if(!v||typeof v.next!="function"||typeof v.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(xn.total===0)return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.next(),null);if(Or(b)){const A=Zr;Promise.resolve(b).then(E=>{A===Zr&&Co(E,wo())}).catch(()=>{A===Zr&&oi({available:!1,reason:at.searchUnavailable})})}else Co(b,wo());return Co(Tt(()=>v.getState(),null),wo()),{ok:!0}}return xn.total===0?{ok:!1,reason:at.operationUnavailable}:(Co(Tt(()=>f.next(),null)),{ok:!0})},previous:()=>{const f=_a();if(!f||typeof f.previous!="function"){const v=Ss();if(!v||typeof v.previous!="function"||typeof v.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(xn.total===0)return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.previous(),null);if(Or(b)){const A=Zr;Promise.resolve(b).then(E=>{A===Zr&&Co(E,wo())}).catch(()=>{A===Zr&&oi({available:!1,reason:at.searchUnavailable})})}else Co(b,wo());return Co(Tt(()=>v.getState(),null),wo()),{ok:!0}}return xn.total===0?{ok:!1,reason:at.operationUnavailable}:(Co(Tt(()=>f.previous(),null)),{ok:!0})},clear:()=>{Zr+=1;const f=_a();if(f&&typeof f.clear=="function"&&Tt(()=>f.clear(),null),!f||typeof f.clear!="function"){const v=Ss();v&&typeof v.query=="function"&&Tt(()=>v.query({query:""}),null)}oi({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:f=>{const v=_a();if(!v){const A=Ss();if(!A||typeof A.replace!="function"||typeof A.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(!wo())return{ok:!1,reason:at.operationUnavailable};const E=Tt(()=>A.replace({replacement:typeof f=="string"?f:""}),null);if(Or(E)){const U=Zr;Sa(),Zi();const Q=()=>U===Zr;return Promise.resolve(E).then(re=>(Q()&&(Co(re,wo()),Sa(),Zi()),Hu(re)),()=>(Q()&&oi({available:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}))}return Sa(),Zi(),Hu(E)}if(typeof v.replaceCurrent!="function")return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.replaceCurrent(typeof f=="string"?f:""),null);return Sa(),Zi(),Hu(b)},replaceAll:f=>{const v=_a();if(!v){const A=Ss();if(!A||typeof A.replaceAll!="function"||typeof A.getState!="function")return{ok:!1,reason:at.searchUnavailable};if(!wo())return{ok:!1,reason:at.operationUnavailable};const E=Tt(()=>A.replaceAll({replacement:typeof f=="string"?f:""}),null);if(Or(E)){const U=Zr;Sa(),Zi();const Q=()=>U===Zr;return Promise.resolve(E).then(re=>(Q()&&(Co(re,wo()),Sa(),Zi()),Hu(re)),()=>(Q()&&oi({available:!1,reason:at.searchUnavailable}),{ok:!1,reason:at.searchUnavailable}))}return Sa(),Zi(),Hu(E)}if(typeof v.replaceAll!="function")return{ok:!1,reason:at.operationUnavailable};const b=Tt(()=>v.replaceAll(typeof f=="string"?f:""),null);return Sa(),Zi(),Hu(b)}},TA=lo(f=>f.styles),xm=Qr(TA),PU={get:xm.get,getSnapshot:xm.getSnapshot,subscribe:xm.subscribe,observe:xm.observe,getCatalog:f=>Dn(f).value,getQuickGallery:()=>TA.get().quickGallery,getActiveParagraphStyle:()=>yo(bt.selection,Fn().cache).style},RA={select:Go,get state(){return bt},selection:vA,commands:dU,toolbar:fU,comments:hU,trackChanges:gU,contentControls:bU,fonts:wU,zoom:CU,document:_U,viewport:km,metadata:xU,tables:RU,search:DU,styles:PU,formatPainter:{setPointerSelecting(f){be||(h={...h,pointerSelecting:f})},notifyPointerUp(){be||(h={...h,pointerSelecting:!1},hA())},setKeyboardSelecting(f){be||(h={...h,keyboardSelecting:f})},notifyKeyUp(){be||(h={...h,keyboardSelecting:!1},hA())},cancel(){be||wa()},onModeChange(f){return be?()=>{}:(p.add(f),()=>p.delete(f))}},createScope:()=>{const f=[];return{select:(v,b)=>{const A=Go(v,b);return{get:A.get,subscribe:E=>{const U=A.subscribe(E);return f.push(U),U}}},dispose:()=>{for(const v of f.splice(0))v()}}},destroy:()=>{if(!be){be=!0,Yt.reset(),ln(),G&&(clearTimeout(G),G=null),j&&(clearTimeout(j),j=null,V=0),$?.timer&&(clearTimeout($.timer),$.timer=null),$=null,W&&(clearTimeout(W),W=null),qr&&(clearTimeout(qr),qr=null),ft&&ft(),ft=null,Fe=null,lr.clear(),J.clear();for(const f of Mn.splice(0))f();Lt&&Lt(),Lt=null,mt=null,Nr&&Nr(),Nr=null,Pn=null,ti&&ti(),ti=null,zr=null,wi&&wi(),wi=null,Li=null,Mr&&Mr(),Mr=null,ma=null;for(const f of zu)Sm(f);zu.clear(),_t.clear(),Im.clear(),m+=1,p.clear(),Zr+=1,he.clear()}}};return Ve=RA,RA}var DH=[{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 PH(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 OH(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"?PH(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 FH(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 BH(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:DH;for(const s of i)o(s);return n}var NH=[{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 zH(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}It();var HH=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 UH(e,t){const n=new Z5.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function X0(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function aA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function VH(e,t){if(!e)return()=>{};if(X0(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=()=>{aA(e),s()},l=u=>{u!==!1&&(u===!0||X0(e))&&(aA(e),s())};return n("synced",a),n("sync",l),X0(e)&&s(),i}function Jo(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function jH(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 lA(e){return typeof e=="string"&&e.length>0?e:null}function Q0(e){return e?Jo(e)?lA(e.documentId??e.options?.documentId??null):lA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function GH(e){if(!e||Jo(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function Wi(e){if(!e)return null;if(Jo(e))return e.fonts??null;const t=GH(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 om=class extends Rm.default{static{this.allowedTypes=[Tr,Nl,Ph]}#t=!1;#n=!1;#e=null;#i=null;#s=null;#a=null;#u=null;#d=null;#l=wk({});get uiConfig(){return this.#l}#f=Ck({});get interactionConfig(){return this.#f}#m=Sk({});get surfacesConfig(){return this.#m}#o;#r=new GF;#p=null;#y=!1;constructor(e){if(super(),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,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},!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.#o=new DF({getModuleConfig:()=>this.#m}),this.#w(e,t)}async#w(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),HF(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.#ve(),this.config.user=UF(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=v9(this.config.modules.comments),this.#l=wk(this.config),this.#f=Ck(this.config),this.#m=Sk(this.config),this.config.disableContextMenu=!this.#l.contextMenu.enabled,this.#l.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#l.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#f.comments)}if(this.config.colors=i6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.0.0-next.51",this.#b("🦋 [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||Ji(),this.colors=this.config.colors??[],this.#x(),await uT(),this.#t)return;if(await this.#T(this.config.modules),this.#t){this.#le();return}this.config.cspNonce&&this.#E(),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.#p||(this.#p=this.#r.subscribe(i=>{this.#be(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.#u=o,this.#L(),this.#S(),this.#we(),this.#_()}#_(){if(this.#M(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#u)}#S(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new sP({Renderer:RF,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#h("requiredNumberOfEditors").documents.filter(e=>e.type===Tr).length}get ui(){return this.#d||(this.#d=LH({superdoc:this}),this.#t&&this.#d.destroy()),this.#d}get state(){return{documents:this.#h("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}#E(){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}}#x(){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=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}else if(n)this.config.documents=[{id:Ji(),type:Tr,url:this.config.document,name:"document.docx"}];else if(r){const s=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}else if(o){const s=Pd(this.config.document);this.config.documents=[{id:Ji(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Pd(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||Ji()}}))}#M(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=YD({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.#o),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&&X8(this),this.#ae()}#c(e,t){t&&this.on(e,t)}#L(){this.#c("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#c("editorCreate",this.config.onEditorCreate),this.#c("editorDestroy",this.config.onEditorDestroy),this.#c("source:complete",this.config.onSourceComplete),this.#c("source:signals-complete",this.config.onSourceSignalsComplete),this.#c("ready",this.config.onReady),this.#c("comments-update",this.config.onCommentsUpdate),this.#c("content-control:active-change",this.config.onContentControlActiveChange),this.#c("content-control:click",this.config.onContentControlClick),this.#c("awareness-update",this.config.onAwarenessUpdate),this.#c("locked",this.config.onLocked),this.#c("pdf:document-ready",this.config.onPdfDocumentReady),this.#c("sidebar-toggle",this.config.onSidebarToggle),this.#c("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#j(e?.editor??null)),this.#c("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#c("exception",this.config.onException),this.#c("list-definitions-change",this.config.onListDefinitionsChange),this.#c("pagination-update",this.config.onPaginationUpdate),this.#c("fonts-resolved",this.config.onFontsResolved),this.#c("fonts-changed",this.config.onFontsChanged),this.#c("zoomChange",this.config.onZoomChange),this.#c("viewport-change",this.config.onViewportChange)}async#T({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:Ji(),type:Tr,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}#D(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=Gr(e),this.provider=Gr(t),this.#W();const n=this.config;this._cleanupAwareness=G8(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#k(){this.#a=null,this.#g(),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})}#g(){if(this.#i){try{this.#i()}catch{}this.#i=null}if(this.#s){try{this.#s()}catch{}this.#s=null}}#j(e){this.#g(),Jo(e)&&(this.#G(e),this.#P(e))}#G(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=nP(()=>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.#i=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#P(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#t||this.#C(!!r.isLocked,this.#O(r.lockedBy??null))};try{if(this.#a&&typeof t.setLocked=="function"){const o=this.#a;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#a=null}const r=t.getSnapshot?.();r&&n(r),this.#s=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#O(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#F(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#C(e,t){this.isLocked===e&&this.#F(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#b("🦋 [superdoc] Locking superdoc:",e,t,`
103
103
 
104
104
 
105
105
  `),this.emit("locked",{isLocked:e,lockedBy:t}))}#W(){const e=this.config.user;if(!e||e.color)return;const t=this.colors.length>0?this.colors:HH,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.#he(e);this.#n=!0;try{const r=await this.#de(),o=this.#v(),i=this.#K();this.#B();let s=null;try{this.#a=i,s=this.#fe(n);const a=this.#ce(t,r);await s,this.#ue(a,t),this.#a=null}catch(a){if(s&&this.#e){const l=this.#e;this.#e=null,l(),await s.catch(()=>{})}throw this.#A(o),a}}finally{this.#e=null,this.#n=!1}}#K(){return{isLocked:this.isLocked,lockedBy:this.lockedBy?{...this.lockedBy}:null}}#v(){const e=this.config.documents.find(r=>r.type===Tr),t=this.superdocStore?.documents.find(r=>r.id===e.id)??null,n=t?pn(t):null;return{isCollaborative:this.isCollaborative,configV2Collaboration:e.v2Collaboration??null,configData:e.data,storeDoc:t,storeV2Collaboration:this.#X(n),storeData:t?.data}}#A(e){this.#a=null;const t=this.config.documents.find(n=>n.type===Tr);t.v2Collaboration=e.configV2Collaboration,t.data=e.configData,this.isCollaborative=e.isCollaborative,e.storeDoc&&(e.storeDoc.data=e.storeData,this.#I(e.storeDoc,e.storeV2Collaboration),this.#N(e.storeDoc))}#B(){if(this.#t)throw new Error("SuperDoc: instance was destroyed during upgrade")}#h(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}#q(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.`)}#Y(e,t){const n=this.superdocStore?.documents;if(Array.isArray(n))for(const r of n){const o=pn(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)}}#X(e){if(!e)return null;const t=e.v2Collaboration;return t&&typeof t=="object"&&"value"in t?t.value:t??null}#I(e,t){const n=pn(e).v2Collaboration;if(n&&typeof n=="object"&&"value"in n){n.value=t;return}e.v2Collaboration=t}#N(e){const t=pn(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}#z(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}:{}}}#ce(e,t){const n=this.config.documents.find(i=>i.type===Tr),r=this.#h("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.#z({...e,roomMode:"create"});return n.data=t,n.v2Collaboration=o,r.data=t,this.#I(r,o),this.isCollaborative=!0,this.readyEditors=0,this.#N(r),{configDoc:n,storeDoc:r}}#ue(e,t){const n=this.#z({...t,roomMode:"join"});e.configDoc.v2Collaboration=n,this.#I(e.storeDoc,n)}async#de(){const e=this.activeEditor;if(Jo(e)&&typeof e.save=="function"){const r=await e.save();return this.#Q(r)}const t=this.config.documents.find(r=>r.type===Tr),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.#Q(n);throw new Error("SuperDoc: upgradeToCollaboration() requires a live v2 editor save or DOCX Blob source")}#Q(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:Tr})}if(e instanceof ArrayBuffer)return new Blob([e],{type:Tr});throw new Error("SuperDoc: active v2 editor returned an unsupported DOCX save payload")}#$(e,t){const n=Q0(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.#Q(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.#I(s,i))}#ke(){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}#Ae(){this.#k(),this.#Y(null,null)}#Ie(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))})}#fe(e){return new Promise((n,r)=>{let o=!1;const i=()=>{o||(o=!0,clearTimeout(a),this.off("collaboration-ready",s))},s=l=>{const u=l?.editor;Jo(u)&&Q0(u)===e&&(!u.presence&&!u.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"))}})}#Ee(e){return new Promise((n,r)=>{let o,i=!1,s=()=>{};const a=()=>{i=!0,clearTimeout(o),s()};s=VH(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")))}})}#he(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===Tr);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(!Jo(this.#me()))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=TS({v2Collaboration:e.v2Collaboration??this.#pe(r.v2Collaboration)??i?.v2Collaboration??i?.v2??null,legacyCollaboration:s,documentType:Tr,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}}#pe(e){return e&&typeof e=="object"&&"value"in e?e.value:e}#me(){const e=this.config.documents.find(n=>n.type===Tr),t=this.#h("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=Nc({actor:e});t&&this.users.some(n=>Nc({actor:n})===t)||this.users.push(e)}removeSharedUser(e){this.#R("removeSharedUser");const t=typeof e=="string"?Mv(e):"",n=typeof e=="string"?`email:${t}`:Nc({actor:e});this.users=this.users.filter(r=>{const o=Nc({actor:r});return n?o!==n:t?Mv(r.email)!==t:!0})}onContentError({error:e,editor:t}){const n=t.options?.documentId,r=this.#h("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:dk(e)})}broadcastEditorCreate(e){this.readyEditors++,this.broadcastReady(),this.#ge(e),this.emit("editorCreate",{editor:dk(e)})}broadcastSourceComplete(){this.emit("source:complete")}broadcastSourceSignalsComplete(){this.emit("source:signals-complete")}#ee=new WeakSet;#ge(e){if(!e||typeof e.on!="function"||this.#ee.has(e))return;this.#ee.add(e),e.on("fonts-changed",n=>{this.#te(e)&&this.#H(n)});const t=(e.documentRenderer??e.presentationEditor)?.getLastFontsChangedPayload?.();t&&this.#te(e)&&this.#H(t)}#te(e){return!this.activeEditor||e===this.activeEditor}#ne=null;#H(e){this.#ne=e,this.emit("fonts-changed",e)}broadcastEditorDestroy(){this.emit("editorDestroy")}broadcastSidebarToggle(e){this.emit("sidebar-toggle",e)}#ve(){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.")}#b(...e){(console.debug?console.debug:console.log)("🦋 🦸‍♀️ [superdoc]",...e)}#Z=null;get fonts(){return this.#Z||(this.#Z={getReport:()=>Wi(this.activeEditor)?.getReport()??[],getMissingFonts:()=>Wi(this.activeEditor)?.getMissingFonts()??[],getDocumentFontOptions:()=>Wi(this.activeEditor)?.getDocumentFontOptions()??[],getFontFamilyOptions:()=>Wi(this.activeEditor)?.getFontFamilyOptions()??[],getDocumentFonts:()=>Wi(this.activeEditor)?.getDocumentFonts()??[],onReport:e=>{const t=this.activeEditor,n=t?Wi(t)?.getLastFontsChangedPayload?.()??null:this.#ne??null;return n&&e(n),this.on("fonts-changed",e),()=>this.off("fonts-changed",e)},map:e=>{const t=Wi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.map requires an active editor");t.map(e)},unmap:e=>{const t=Wi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.unmap requires an active editor");t.unmap(e)},add:e=>{const t=Wi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.add requires an active editor");t.add(e)},preload:e=>{const t=Wi(this.activeEditor);if(!t)throw new Error("superdoc.fonts.preload requires an active editor");return t.preload(e)}}),this.#Z}#U(){const e=this.activeEditor!==null;this.#re(),this.activeEditor=null,this.toolbar?.setActiveEditor?this.toolbar.setActiveEditor(null):this.toolbar&&(this.toolbar.activeEditor=null),e&&this.emit("active-editor-change")}#V=null;#re(){if(this.#V){try{this.#V()}catch{}this.#V=null}}#ye(e){this.#re();const t=Wi(e);if(!t?.onChanged)return;const n=t.getLastFontsChangedPayload?.();n&&this.#H(n),this.#V=t.onChanged(r=>this.#H(r))}#be(e,t){this.#y=!0;try{if(e===null){this.#U();return}this.#r.get(e)?.kind==="v2"&&Jo(t)?this.#oe(t):this.#U()}finally{this.#y=!1}}#oe(e){if(Jo(e)){!this.#y&&this.#r.getActive()&&this.#r.setActive(null,"set-active-v2-facade");const t=this.activeEditor;this.activeEditor=e,this.#ye(e),this.toolbar?.setActiveEditor?.(e),t!==this.activeEditor&&this.emit("active-editor-change");return}this.#U()}setActiveEditor(e){this.#oe(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:"not-shipped",reason:"bulk-tracked-change-decisions-omitted: acceptAll/rejectAll are matrix-disabled by default in the v2 host"},{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.#r.register(e)}unregisterEditorRuntime(e){return this.#r.unregister(e)}getActiveRuntime(){return this.#r.getActive()}setActiveRuntime(e,t){this.#r.setActive(e,t)}resolveRuntimeFromEventTarget(e){return this.#r.resolveFromEventTarget(e)}activateRuntimeFromEventTarget(e,t){const n=this.#r.resolveFromEventTarget(e);return n?(this.#r.setActive(n.id,t),!0):!1}toggleRuler(){const e=this.#h("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 Zs(e,t,n,{superdoc:this,currentUser:this.config.user,comment:i??null,trackedChange:o??null})}#we(){const e=this.config.modules?.toolbar,t=e&&typeof e=="object"?e:{},n=this.#l.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=Pz({...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 xR(this.config.modules?.comments,this),this.config.onCommentsListChange&&this.config.onCommentsListChange({isRendered:!0}))}removeCommentsList(){this.commentsList&&(this.commentsList.close(),this.commentsList=null,this.config.onCommentsListChange&&this.config.onCommentsListChange({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.#l.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.#ae();const t={viewing:()=>this.#se(),editing:()=>this.#Ce(),suggesting:()=>this.#ie()};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.#r.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)})}#Ce(){if(this.config.role!=="editor")return this.#ie();const e=this.#h("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")})}#ie(){if(!["editor","suggester"].includes(this.config.role??""))return this.#se();const e=this.#h("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")})}#se(){const e=this.#h("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")})}#ae(){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=c_(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(Jo(t)&&typeof t.lock?.setLocked=="function"){t.lock.setLocked(e,e?{...this.user}:null);const n=t.lock.getSnapshot?.();n&&this.#C(!!n.isLocked,this.#O(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.#C(e,e?this.user:null)}getHTML(e={}){const t=[];return this.#h("getHTML").documents.forEach(n=>{const r=n.getEditor?.();r&&t.push(r)}),t.map(n=>n.getHTML(e))}lockSuperdoc(e=!1,t=null){this.#C(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=JS(n||this.config.title),u=await this.exportEditorsToDOCX({commentsType:t,isFinalDoc:i,fieldsHighlightColor:a}),c=[...r],d=[...o];if(e.includes("docx")&&u.forEach(m=>{c.push(m),d.push(`${l}.docx`)}),c.length===1)return s?ZS(c[0],l,e[0]):c[0];const h=await UH(c,d);return s?ZS(h,l,"zip"):h}async replaceFile(e){const t=this.activeEditor;if(Jo(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.#$(t,e),this.emit("document-replaced",{editor:t,host:t?.host})),r}const n=t&&!Jo(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.#$(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=u=>{"editor"in u&&u.error&&typeof u.error=="object"&&a.add(u.error)};this.on("exception",l);try{const u=this.#h("exportEditorsToDOCX").documents.map(async c=>{if(!c||c.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")return null;const d=typeof c.getEditor=="function"?c.getEditor():null,h=()=>!c.data||c.data.type&&c.data.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?null:c.data;if(!d||typeof d.exportDocx!="function")return h();const m=d.editorVersion===2;try{const p=await d.exportDocx(m?{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:c}),m&&(e==="clean"||jH(p)))throw p}return h()});return(await Promise.all(u)).filter(c=>c!=null)}finally{this.off("exception",l)}}async#_e(){this.#b("🦋 [superdoc] Triggering collaboration saves");const e=this.#h("save");return new Promise(t=>{e.documents.forEach((n,r)=>{if(this.#b(`Before reset - Doc ${r}: pending = ${this.pendingCollaborationSaves}`),this.pendingCollaborationSaves=0,n.ydoc){this.pendingCollaborationSaves++,this.#b(`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.#b(`FINAL pending = ${this.pendingCollaborationSaves}, but we have ${e.documents.filter(n=>n.ydoc).length} docs!`)})}async save(){const e=[this.#_e()];this.#b("🦋 [superdoc] Saving superdoc"),await Promise.all(e),this.#b("🦋 [superdoc] Save complete")}#Se(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?.()}#le(){this.#a=null,this.#g(),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.#o.open(e)}closeSurface(e){this.#o.close(e)}async removeDocument(e){const t=typeof e=="string"?e:String(e??"");if(!t)return!1;const n=this.#h("removeDocument"),r=this.activeEditor,o=Q0(r);for(const s of this.#r.getAllByDocumentId(t))this.#r.unregister(s.id);o===t&&r!==null&&this.#U();const i=n.removeDocument(t);return i?(this.#Se(i,n.documents),await St(),!0):!1}destroy(){this.#t=!0,this.#e&&(this.#e(),this.#e=null),this.#o&&this.#o.destroy(),this.toolbar?.destroy?.(),this.app&&(this.#b("[superdoc] Unmounting app"),this.superdocStore?.reset(),this.app.unmount(),this.removeAllListeners(),delete this.app.config.globalProperties.$config,delete this.app.config.globalProperties.$superdoc),this.#d?.destroy(),this.#le(),this.#p?.(),this.#p=null,this.#r.clear(),this.#u&&(this.#u.remove(),this.#u=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?Jo(this.activeEditor)?this.activeEditor.focus?.(e):this.activeEditor.focus?.():this.#h("focus").documents.find(n=>{const r=n.getEditor?.();return r?(Jo(r)?r.focus?.(e):r.focus?.(),!0):!1})}setHighContrastMode(e){this.activeEditor&&(this.activeEditor.setHighContrastMode?.(e),this.highContrastModeStore?.setHighContrastMode(e))}};It();const cA="__SUPERDOC_V2_BROWSER_RUNTIME__";function WH(e=globalThis){const t=e[cA];return t&&typeof t=="object"?t:null}function KH(e={},t=globalThis){const n=WH(t)??{},r={...n,...e,vue:e.vue??n.vue??Y5};return t[cA]=r,r}KH();var qH={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"},YH=0;function uA(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-${++YH}`}`,l=[];if(i)for(const[u,c]of Object.entries(i)){if(c==null)continue;const d=qH[u];d&&l.push(` ${d}: ${c};`)}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[u,c]of Object.entries(s))c!=null&&l.push(` ${u}: ${c};`);return{className:a,css:l.length>0?`.${a} {
106
106
  ${l.join(`
107
107
  `)}
108
- }`:""}}function XH(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 QH(e){const{className:t,css:n}=uA(e);return XH(t,n),t}function ZH(e){return uA(e)}function JH(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 $H=Vu({BlankDOCX:()=>HC,DOCX:()=>Tr,HTML:()=>Ph,PDF:()=>Nl,SuperDoc:()=>om,buildTheme:()=>ZH,compareVersions:()=>n6,createTheme:()=>QH,defineSuperDocExtension:()=>JH,getFileObject:()=>Lv},1),eU="SUPERDOC_ENGINE_CDN_BASE_URL",dA=Symbol.for("superdoc.docx-engine.cdn-load-state"),im="superdocDocxEngineStatus";function tU(e,t,n=null){const r=e?.[eU],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return nU(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 nU(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 rU({engineVersion:e,buildBaseUrl:t}){lT(()=>{const n=tU(globalThis,e,t),r=globalThis[dA],o=r instanceof Map?r:new Map;if(globalThis[dA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),oU(`${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 oU(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[im]==="loaded")return Promise.resolve();const r=n?.dataset[im]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const u=(m,p)=>{a||(a=!0,l?.disconnect(),s.dataset[im]=m,p())},c=()=>u("loaded",o),d=()=>u("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||u("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",c,{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[im]="loading",document.head.appendChild(s))})}rU({engineVersion:"0.2.0-next.21",buildBaseUrl:null});for(const[e,t]of Object.entries($H))e==="SuperDoc"||e==="default"||Object.prototype.hasOwnProperty.call(om,e)||(om[e]=t);var iU=om;return iU})();
108
+ }`:""}}function XH(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 QH(e){const{className:t,css:n}=uA(e);return XH(t,n),t}function ZH(e){return uA(e)}function JH(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 $H=Vu({BlankDOCX:()=>HC,DOCX:()=>Tr,HTML:()=>Ph,PDF:()=>Nl,SuperDoc:()=>om,buildTheme:()=>ZH,compareVersions:()=>n6,createTheme:()=>QH,defineSuperDocExtension:()=>JH,getFileObject:()=>Lv},1),eU="SUPERDOC_ENGINE_CDN_BASE_URL",dA=Symbol.for("superdoc.docx-engine.cdn-load-state"),im="superdocDocxEngineStatus";function tU(e,t,n=null){const r=e?.[eU],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return nU(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 nU(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 rU({engineVersion:e,buildBaseUrl:t}){lT(()=>{const n=tU(globalThis,e,t),r=globalThis[dA],o=r instanceof Map?r:new Map;if(globalThis[dA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),oU(`${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 oU(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[im]==="loaded")return Promise.resolve();const r=n?.dataset[im]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const u=(m,p)=>{a||(a=!0,l?.disconnect(),s.dataset[im]=m,p())},c=()=>u("loaded",o),d=()=>u("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||u("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",c,{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[im]="loading",document.head.appendChild(s))})}rU({engineVersion:"0.2.0-next.22",buildBaseUrl:null});for(const[e,t]of Object.entries($H))e==="SuperDoc"||e==="default"||Object.prototype.hasOwnProperty.call(om,e)||(om[e]=t);var iU=om;return iU})();