superdoc 2.7.0 β†’ 2.7.1-next.2

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
  `,C_=()=>{if(typeof document>"u")throw new Error(kD)},rs=class lI{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 lI(this.m)}copyInto(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}point(t){const n=this.m;return{x:n[0]*t.x+n[2]*t.y+n[4],y:n[1]*t.x+n[3]*t.y+n[5]}}translate(t,n){return this.m[4]+=this.m[0]*t+this.m[2]*n,this.m[5]+=this.m[1]*t+this.m[3]*n,this}scale(t,n){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=n,this.m[3]*=n,this}rotate(t){const n=Math.cos(t),r=Math.sin(t),o=this.m[0]*n+this.m[2]*r,i=this.m[1]*n+this.m[3]*r,s=this.m[0]*-r+this.m[2]*n,a=this.m[1]*-r+this.m[3]*n;return this.m[0]=o,this.m[1]=i,this.m[2]=s,this.m[3]=a,this}getTranslation(){return{x:this.m[4],y:this.m[5]}}skew(t,n){const r=this.m[0]+this.m[2]*n,o=this.m[1]+this.m[3]*n,i=this.m[2]+this.m[0]*t,s=this.m[3]+this.m[1]*t;return this.m[0]=r,this.m[1]=o,this.m[2]=i,this.m[3]=s,this}multiply(t){const n=this.m[0]*t.m[0]+this.m[2]*t.m[1],r=this.m[1]*t.m[0]+this.m[3]*t.m[1],o=this.m[0]*t.m[2]+this.m[2]*t.m[3],i=this.m[1]*t.m[2]+this.m[3]*t.m[3],s=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=n,this.m[1]=r,this.m[2]=o,this.m[3]=i,this.m[4]=s,this.m[5]=a,this}invert(){const t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),n=this.m[3]*t,r=-this.m[1]*t,o=-this.m[2]*t,i=this.m[0]*t,s=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=n,this.m[1]=r,this.m[2]=o,this.m[3]=i,this.m[4]=s,this.m[5]=a,this}getMatrix(){return this.m}decompose(){const t=this.m[0],n=this.m[1],r=this.m[2],o=this.m[3],i=this.m[4],s=this.m[5],a=t*o-n*r,l={x:i,y:s,rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(t!=0||n!=0){const c=Math.sqrt(t*t+n*n);l.rotation=n>0?Math.acos(t/c):-Math.acos(t/c),l.scaleX=c,l.scaleY=a/c,l.skewX=(t*r+n*o)/a,l.skewY=0}else if(r!=0||o!=0){const c=Math.sqrt(r*r+o*o);l.rotation=Math.PI/2-(o>0?Math.acos(-r/c):-Math.acos(r/c)),l.scaleX=a/c,l.scaleY=c,l.skewX=0,l.skewY=(t*r+n*o)/a}return l.rotation=Re._getRotation(l.rotation),l}},SD="[object Array]",_D="[object Number]",AD="[object String]",ID="[object Boolean]",xD=Math.PI/180,ED=180/Math.PI,hf="#",TD="",RD="0",MD="Konva warning: ",k_="Konva error: ",LD="rgb(",k0={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]},PD=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,zp=[],pf=null,DD=typeof requestAnimationFrame<"u"&&requestAnimationFrame||function(e){setTimeout(e,16)},Re={_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)===SD},_isNumber(e){return Object.prototype.toString.call(e)===_D&&!isNaN(e)&&isFinite(e)},_isString(e){return Object.prototype.toString.call(e)===AD},_isBoolean(e){return Object.prototype.toString.call(e)===ID},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){zp.push(e),zp.length===1&&DD(function(){const t=zp;zp=[],t.forEach(function(n){n()})})},createCanvasElement(){C_();const e=document.createElement("canvas");try{e.style=e.style||{}}catch{}return e},createImageElement(){return C_(),document.createElement("img")},_isInDocument(e){for(;e=e.parentNode;)if(e==document)return!0;return!1},_urlToImage(e,t){const n=Re.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(hf,TD);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=RD+e;return hf+e},isCanvasFarblingActive(){if(pf!==null)return pf;if(typeof document>"u")return pf=!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 pf=r,this.releaseCanvas(e),pf},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),hf+this._rgbToHex(e,t,n)},getSnappedHexColor(e){const t=this._hexToRgb(e);return hf+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 k0?(t=k0[e],{r:t[0],g:t[1],b:t[2]}):e[0]===hf?this._hexToRgb(e.substring(1)):e.substr(0,4)===LD?(t=PD.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",Re._namedColorToRBA(e)||Re._hex3ColorToRGBA(e)||Re._hex4ColorToRGBA(e)||Re._hex6ColorToRGBA(e)||Re._hex8ColorToRGBA(e)||Re._rgbColorToRGBA(e)||Re._rgbaColorToRGBA(e)||Re._hslColorToRGBA(e)},_namedColorToRBA(e){const t=k0[e.toLowerCase()];return t?{r:t[0],g:t[1],b:t[2],a:1}:null},_rgbColorToRGBA(e){if(e.indexOf("rgb(")===0){e=e.match(/rgb\(([^)]+)\)/)[1];const t=e.split(/ *, */).map(Number);return{r:t[0],g:t[1],b:t[2],a:1}}},_rgbaColorToRGBA(e){if(e.indexOf("rgba(")===0){e=e.match(/rgba\(([^)]+)\)/)[1];const t=e.split(/ *, */).map((n,r)=>n.slice(-1)==="%"?r===3?parseInt(n)/100:parseInt(n)/100*255:Number(n));return{r:t[0],g:t[1],b:t[2],a:t[3]}}},_hex8ColorToRGBA(e){if(e[0]==="#"&&e.length===9)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:parseInt(e.slice(7,9),16)/255}},_hex6ColorToRGBA(e){if(e[0]==="#"&&e.length===7)return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:1}},_hex4ColorToRGBA(e){if(e[0]==="#"&&e.length===5)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:parseInt(e[4]+e[4],16)/255}},_hex3ColorToRGBA(e){if(e[0]==="#"&&e.length===4)return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:1}},_hslColorToRGBA(e){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(e)){const[t,...n]=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(e),r=Number(n[0])/360,o=Number(n[1])/100,i=Number(n[2])/100;let s,a,l;if(o===0)return l=i*255,{r:Math.round(l),g:Math.round(l),b:Math.round(l),a:1};i<.5?s=i*(1+o):s=i+o-i*o;const c=2*i-s,d=[0,0,0];for(let f=0;f<3;f++)a=r+1/3*-(f-1),a<0&&a++,a>1&&a--,6*a<1?l=c+(s-c)*6*a:2*a<1?l=s:3*a<2?l=c+(s-c)*(2/3-a)*6:l=c,d[f]=l*255;return{r:Math.round(d[0]),g:Math.round(d[1]),b:Math.round(d[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*xD},radToDeg(e){return e*ED},_degToRad(e){return Re.warn("Util._degToRad is removed. Please use public Util.degToRad instead."),Re.degToRad(e)},_radToDeg(e){return Re.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead."),Re.radToDeg(e)},_getRotation(e){return St.angleDeg?Re.radToDeg(e):e},_capitalize(e){return e.charAt(0).toUpperCase()+e.slice(1)},throw(e){throw new Error(k_+e)},error(e){console.error(k_+e)},warn(e){St.showWarnings&&console.warn(MD+e)},each(e,t){for(const n in e)t(n,e[n])},_inRange(e,t,n){return t<=e&&e<n},_getProjectionToSegment(e,t,n,r,o,i){let s,a,l;const c=(e-n)*(e-n)+(t-r)*(t-r);if(c==0)s=e,a=t,l=(o-n)*(o-n)+(i-r)*(i-r);else{const d=((o-e)*(n-e)+(i-t)*(r-t))/c;d<0?(s=e,a=t,l=(e-o)*(e-o)+(t-i)*(t-i)):d>1?(s=n,a=r,l=(n-o)*(n-o)+(r-i)*(r-i)):(s=e+d*(n-e),a=t+d*(r-t),l=(s-o)*(s-o)+(a-i)*(a-i))}return[s,a,l]},_getProjectionToLine(e,t,n){const r=Re.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=Re._getProjectionToSegment(i.x,i.y,a.x,a.y,e.x,e.y),c=l[0],d=l[1],f=l[2];f<o&&(r.x=c,r.y=d,o=f)}),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=Re._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||Re._isElement(e[n]))if(t.configurable)delete e[n];else return null;else if(Re._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){St.releaseCanvasOnDestroy&&e.forEach(t=>{t.width=0,t.height=0})},drawRoundedRectPath(e,t,n,r){let o=t<0?t:0,i=n<0?n:0;t=Math.abs(t),n=Math.abs(n);let s=0,a=0,l=0,c=0;typeof r=="number"?s=a=l=c=Math.min(r,t/2,n/2):(s=Math.min(r[0]||0,t/2,n/2),a=Math.min(r[1]||0,t/2,n/2),c=Math.min(r[2]||0,t/2,n/2),l=Math.min(r[3]||0,t/2,n/2)),e.moveTo(o+s,i),e.lineTo(o+t-a,i),e.arc(o+t-a,i+a,a,Math.PI*3/2,0,!1),e.lineTo(o+t,i+n-c),e.arc(o+t-c,i+n-c,c,0,Math.PI/2,!1),e.lineTo(o+l,i+n),e.arc(o+l,i+n-l,l,Math.PI/2,Math.PI,!1),e.lineTo(o,i+s),e.arc(o+s,i+s,s,Math.PI,Math.PI*3/2,!1)},drawRoundedPolygonPath(e,t,n,r,o){r=Math.abs(r);for(let i=0;i<n;i++){const s=t[(i-1+n)%n],a=t[i],l=t[(i+1)%n],c={x:a.x-s.x,y:a.y-s.y},d={x:l.x-a.x,y:l.y-a.y},f=Math.hypot(c.x,c.y),h=Math.hypot(d.x,d.y);let g;typeof o=="number"?g=o:g=i<o.length?o[i]:0,g=r*Math.cos(Math.PI/n)*Math.min(1,g/r*2);const m={x:c.x/f,y:c.y/f},v={x:d.x/h,y:d.y/h},_={x:a.x-m.x*g,y:a.y-m.y*g},k={x:a.x+v.x*g,y:a.y+v.y*g};i===0?e.moveTo(_.x,_.y):e.lineTo(_.x,_.y),e.arcTo(a.x,a.y,k.x,k.y,g)}}};function OD(e){const t=[],n=e.length,r=Re;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 S_=",",FD="(",ND=")",BD="([",zD="])",VD=";",jD="()",UD="=",__=["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"],HD=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","letterSpacing","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","direction","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled","filter"],$D=100,Vp=null;function A_(){if(Vp!==null)return Vp;try{const e=Re.createCanvasElement().getContext("2d");return e?!!e&&"filter"in e:(Vp=!1,!1)}catch{return Vp=!1,!1}}var jp=class{constructor(e){this.canvas=e,St.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+=jD:Re._isArray(l[0])?o+=BD+l.join(S_)+zD:(t&&(l=l.map(c=>typeof c=="number"?Math.floor(c):c)),o+=FD+l.join(S_)+ND)):(o+=s.property,e||(o+=UD+s.val)),o+=VD;return o}clearTrace(){this.traceArr=[]}_trace(e){let t=this.traceArr,n;t.push(e),n=t.length,n>=$D&&t.shift()}reset(){const e=this.getCanvas().getPixelRatio();this.setTransform(1*e,0,0,1*e,0,0)}getCanvas(){return this.canvas}clear(e){const t=this.getCanvas();e?this.clearRect(e.x||0,e.y||0,e.width||0,e.height||0):this.clearRect(0,0,t.getWidth()/t.pixelRatio,t.getHeight()/t.pixelRatio)}_applyLineCap(e){const t=e.attrs.lineCap;t&&this.setAttr("lineCap",t)}_applyOpacity(e){const t=e.getAbsoluteOpacity();t!==1&&this.setAttr("globalAlpha",t)}_applyLineJoin(e){const t=e.attrs.lineJoin;t&&this.setAttr("lineJoin",t)}_applyMiterLimit(e){const t=e.attrs.miterLimit;t!=null&&this.setAttr("miterLimit",t)}setAttr(e,t){this._context[e]=t}arc(e,t,n,r,o,i){this._context.arc(e,t,n,r,o,i)}arcTo(e,t,n,r,o){this._context.arcTo(e,t,n,r,o)}beginPath(){this._context.beginPath()}bezierCurveTo(e,t,n,r,o,i){this._context.bezierCurveTo(e,t,n,r,o,i)}clearRect(e,t,n,r){this._context.clearRect(e,t,n,r)}clip(...e){this._context.clip.apply(this._context,e)}closePath(){this._context.closePath()}createImageData(e,t){const n=arguments;if(n.length===2)return this._context.createImageData(e,t);if(n.length===1)return this._context.createImageData(e)}createLinearGradient(e,t,n,r){return this._context.createLinearGradient(e,t,n,r)}createPattern(e,t){return this._context.createPattern(e,t)}createRadialGradient(e,t,n,r,o,i){return this._context.createRadialGradient(e,t,n,r,o,i)}drawImage(e,t,n,r,o,i,s,a,l){const c=arguments,d=this._context;c.length===3?d.drawImage(e,t,n):c.length===5?d.drawImage(e,t,n,r,o):c.length===9&&d.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=__.length,n=this.setAttr,r,o;const i=function(s){let a=e[s],l;e[s]=function(){return o=OD(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(__[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)}};HD.forEach(function(e){Object.defineProperty(jp.prototype,e,{get(){return this._context[e]},set(t){this._context[e]=t}})});var GD=class extends jp{constructor(e,{willReadFrequently:t=!1}={}){super(e),this._context=e._canvas.getContext("2d",{willReadFrequently:t})}_fillColor(e){const t=e.fill();this.setAttr("fillStyle",t),e._fillFunc(this)}_fillPattern(e){this.setAttr("fillStyle",e._getFillPattern()),e._fillFunc(this)}_fillLinearGradient(e){const t=e._getLinearGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fillRadialGradient(e){const t=e._getRadialGradient();t&&(this.setAttr("fillStyle",t),e._fillFunc(this))}_fill(e){const t=e.fill(),n=e.getFillPriority();if(t&&n==="color"){this._fillColor(e);return}const r=e.getFillPatternImage();if(r&&n==="pattern"){this._fillPattern(e);return}const o=e.getFillLinearGradientColorStops();if(o&&n==="linear-gradient"){this._fillLinearGradient(e);return}const i=e.getFillRadialGradientColorStops();if(i&&n==="radial-gradient"){this._fillRadialGradient(e);return}t?this._fillColor(e):r?this._fillPattern(e):o?this._fillLinearGradient(e):i&&this._fillRadialGradient(e)}_strokeLinearGradient(e){const t=e.getStrokeLinearGradientStartPoint(),n=e.getStrokeLinearGradientEndPoint(),r=e.getStrokeLinearGradientColorStops(),o=this.createLinearGradient(t.x,t.y,n.x,n.y);if(r){for(let i=0;i<r.length;i+=2)o.addColorStop(r[i],r[i+1]);this.setAttr("strokeStyle",o)}}_stroke(e){const t=e.dash(),n=e.getStrokeScaleEnabled();if(e.hasStroke()){if(!n){this.save();const r=this.getCanvas().getPixelRatio();this.setTransform(r,0,0,r,0,0)}this._applyLineCap(e),t&&e.dashEnabled()&&(this.setLineDash(t),this.setAttr("lineDashOffset",e.dashOffset())),this.setAttr("lineWidth",e.strokeWidth()),e.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),e.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(e):this.setAttr("strokeStyle",e.stroke()),e._strokeFunc(this),n||this.restore()}}_applyShadow(e){var t,n,r;const o=(t=e.getShadowRGBA())!==null&&t!==void 0?t:"black",i=(n=e.getShadowBlur())!==null&&n!==void 0?n:5,s=(r=e.getShadowOffset())!==null&&r!==void 0?r:{x:0,y:0},a=e.getAbsoluteScale(),l=this.canvas.getPixelRatio(),c=a.x*l,d=a.y*l;this.setAttr("shadowColor",o),this.setAttr("shadowBlur",i*Math.min(Math.abs(c),Math.abs(d))),this.setAttr("shadowOffsetX",s.x*c),this.setAttr("shadowOffsetY",s.y*d)}},WD=class extends jp{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()}}},Up;function KD(){if(Up)return Up;const e=Re.createCanvasElement(),t=e.getContext("2d");return Up=(function(){return(St._global.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)})(),Re.releaseCanvas(e),Up}var S0=class{constructor(e){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;const t=(e||{}).pixelRatio||St.pixelRatio||KD();this.pixelRatio=t,this._canvas=Re.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 Re.error("Unable to get data URL. "+r.message+" For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."),""}}}},dl=class extends S0{constructor(e={width:0,height:0,willReadFrequently:!1}){super(e),this.context=new GD(this,{willReadFrequently:e.willReadFrequently}),this.setSize(e.width,e.height)}},_0=class extends S0{constructor(e={width:0,height:0}){super(e),this.hitCanvas=!0,this.context=new WD(this),this.setSize(e.width,e.height)}},On={get isDragging(){let e=!1;return On._dragElements.forEach(t=>{t.dragStatus==="dragging"&&(e=!0)}),e},justDragged:!1,get node(){let e;return On._dragElements.forEach(t=>{e=t.node}),e},_dragElements:new Map,_drag(e){const t=[];On._dragElements.forEach((n,r)=>{const{node:o}=n,i=o.getStage();i.setPointersPositions(e),n.pointerId===void 0&&(n.pointerId=Re._getFirstPointerId(e));const s=i._changedPointerPositions.find(a=>a.id===n.pointerId);if(s){if(n.dragStatus!=="dragging"){const a=o.dragDistance();if(Math.max(Math.abs(s.x-n.startPointerPos.x),Math.abs(s.y-n.startPointerPos.y))<a||(o.startDrag({evt:e}),!o.isDragging()))return}o._setDragPosition(e,n),t.push(o)}}),t.forEach(n=>{n.getStage()&&n.fire("dragmove",{type:"dragmove",target:n,evt:e},!0)})},_endDragBefore(e){const t=[];On._dragElements.forEach(n=>{const{node:r}=n,o=r.getStage();if(e&&o.setPointersPositions(e),!o._changedPointerPositions.find(s=>s.id===n.pointerId))return;(n.dragStatus==="dragging"||n.dragStatus==="stopped")&&(On.justDragged=!0,St._mouseListenClick=!1,St._touchListenClick=!1,St._pointerListenClick=!1,n.dragStatus="stopped");const i=n.node.getLayer()||n.node instanceof St.Stage&&n.node;i&&t.indexOf(i)===-1&&t.push(i)}),t.forEach(n=>{n.draw()})},_endDragAfter(e){On._dragElements.forEach((t,n)=>{t.dragStatus==="stopped"&&t.node.fire("dragend",{type:"dragend",target:t.node,evt:e},!0),t.dragStatus!=="dragging"&&On._dragElements.delete(n)})}};St.isBrowser&&(window.addEventListener("mouseup",On._endDragBefore,!0),window.addEventListener("touchend",On._endDragBefore,!0),window.addEventListener("touchcancel",On._endDragBefore,!0),window.addEventListener("mousemove",On._drag),window.addEventListener("touchmove",On._drag),window.addEventListener("mouseup",On._endDragAfter,!1),window.addEventListener("touchend",On._endDragAfter,!1),window.addEventListener("touchcancel",On._endDragAfter,!1));function fl(e){return Re._isString(e)?'"'+e+'"':Object.prototype.toString.call(e)==="[object Number]"||Re._isBoolean(e)?e:Object.prototype.toString.call(e)}function I_(e){return e>255?255:e<0?0:Math.round(e)}function bt(){if(St.isUnminified)return function(e,t){return Re._isNumber(e)||Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a number.'),e}}function Hp(e){if(St.isUnminified)return function(t,n){let r=Re._isNumber(t),o=Re._isArray(t)&&t.length==e;return!r&&!o&&Re.warn(fl(t)+' is a not valid value for "'+n+'" attribute. The value should be a number or Array<number>('+e+")"),t}}function A0(){if(St.isUnminified)return function(e,t){return Re._isNumber(e)||e==="auto"||Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a number or "auto".'),e}}function sc(){if(St.isUnminified)return function(e,t){return Re._isString(e)||Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a string.'),e}}function x_(){if(St.isUnminified)return function(e,t){const n=Re._isString(e),r=Object.prototype.toString.call(e)==="[object CanvasGradient]"||e&&e.addColorStop;return n||r||Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a string or a native gradient.'),e}}function qD(){if(St.isUnminified)return function(e,t){const n=Int8Array?Object.getPrototypeOf(Int8Array):null;return n&&e instanceof n||(Re._isArray(e)?e.forEach(function(r){Re._isNumber(r)||Re.warn('"'+t+'" attribute has non numeric element '+r+". Make sure that all elements are numbers.")}):Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a array of numbers.')),e}}function os(){if(St.isUnminified)return function(e,t){return e===!0||e===!1||Re.warn(fl(e)+' is a not valid value for "'+t+'" attribute. The value should be a boolean.'),e}}function YD(e){if(St.isUnminified)return function(t,n){return t==null||Re.isObject(t)||Re.warn(fl(t)+' is a not valid value for "'+n+'" attribute. The value should be an object with properties '+e),t}}var mf="get",gf="set",he={addGetterSetter(e,t,n,r,o){he.addGetter(e,t,n),he.addSetter(e,t,r,o),he.addOverloadedGetterSetter(e,t)},addGetter(e,t,n){const r=mf+Re._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=gf+Re._capitalize(t);e.prototype[o]||he.overWriteSetter(e,t,n,r)},overWriteSetter(e,t,n,r){const o=gf+Re._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=Re._capitalize,a=mf+s(t),l=gf+s(t);e.prototype[a]=function(){const d={};for(let f=0;f<i;f++){const h=n[f];d[h]=this.getAttr(t+s(h))}return d};const c=YD(n);e.prototype[l]=function(d){const f=this.attrs[t];r&&(d=r.call(this,d,t)),c&&c.call(this,d,t);for(const h in d)d.hasOwnProperty(h)&&this._setAttr(t+s(h),d[h]);return d||n.forEach(h=>{this._setAttr(t+s(h),void 0)}),this._fireChangeEvent(t,f,d),o&&o.call(this),this},he.addOverloadedGetterSetter(e,t)},addOverloadedGetterSetter(e,t){const n=Re._capitalize(t),r=gf+n,o=mf+n;e.prototype[t]=function(){return arguments.length?(this[r](arguments[0]),this):this[o]()}},addDeprecatedGetterSetter(e,t,n,r){Re.error("Adding deprecated "+t);const o=mf+Re._capitalize(t),i=t+" property is deprecated and will be removed soon. Look at Konva change log for more information.";e.prototype[o]=function(){Re.error(i);const s=this.attrs[t];return s===void 0?n:s},he.addSetter(e,t,r,function(){Re.error(i)}),he.addOverloadedGetterSetter(e,t)},backCompat(e,t){Re.each(t,function(n,r){const o=e.prototype[r],i=mf+Re._capitalize(n),s=gf+Re._capitalize(n);function a(){o.apply(this,arguments),Re.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 XD(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=St.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=St.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=St.Filters;l&&l.Contrast&&l.Contrast.call(this,s)}}case"grayscale":return function(i){const s=St.Filters;s&&s.Grayscale&&s.Grayscale.call(this,i)};case"sepia":return function(i){const s=St.Filters;s&&s.Sepia&&s.Sepia.call(this,i)};case"invert":return function(i){const s=St.Filters;s&&s.Invert&&s.Invert.call(this,i)};default:Re.warn(`CSS filter "${r}" is not supported in fallback mode. Consider using function filters for better compatibility.`)}}return()=>{}}var $p="absoluteOpacity",E_="allEventListeners",wa="absoluteTransform",T_="absoluteScale",ac="canvas",ZD="Change",QD="children",JD="konva",I0="listening",eO="mouseenter",tO="mouseleave",nO="pointerenter",rO="pointerleave",oO="touchenter",iO="touchleave",R_="set",M_="Shape",Gp=" ",L_="stage",hl="transform",sO="Stage",x0="visible",aO=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(Gp),lO=1,_t=class eh{constructor(t){this._id=lO++,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===hl||t===wa)&&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===hl||t===wa)&&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(Gp);this.on(o,()=>{this._clearCache(t)}),this._attachedDepsListeners.set(t,!0)}return this._getCache(t,r)}_getCanvasCache(){return this._cache.get(ac)}_clearSelfAndDescendantCache(t){this._clearCache(t),t===wa&&this.fire("absoluteTransformChange")}clearCache(){if(this._cache.has(ac)){const{scene:t,filter:n,hit:r}=this._cache.get(ac);Re.releaseCanvas(t._canvas,n._canvas,r._canvas),this._cache.delete(ac)}return this._clearSelfAndDescendantCache(),this._requestDraw(),this}cache(t){const n=t||{};let r={};(n.x===void 0||n.y===void 0||n.width===void 0||n.height===void 0)&&(r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()||void 0}));let o=Math.ceil(n.width||r.width),i=Math.ceil(n.height||r.height),s=n.pixelRatio,a=n.x===void 0?Math.floor(r.x):n.x,l=n.y===void 0?Math.floor(r.y):n.y,c=n.offset||0,d=n.drawBorder||!1,f=n.hitCanvasPixelRatio||1;if(!o||!i){Re.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");return}const h=Math.abs(Math.round(r.x)-a)>.5?1:0,g=Math.abs(Math.round(r.y)-l)>.5?1:0;o+=c*2+h,i+=c*2+g,a-=c,l-=c;const m=new dl({pixelRatio:s,width:o,height:i}),v=new dl({pixelRatio:s,width:0,height:0,willReadFrequently:!0}),_=new _0({pixelRatio:f,width:o,height:i}),k=m.getContext(),S=_.getContext(),y=new dl({width:m.width/m.pixelRatio+Math.abs(a),height:m.height/m.pixelRatio+Math.abs(l),pixelRatio:m.pixelRatio}),w=y.getContext();return _.isCache=!0,m.isCache=!0,this._cache.delete(ac),this._filterUpToDate=!1,n.imageSmoothingEnabled===!1&&(m.getContext()._context.imageSmoothingEnabled=!1,v.getContext()._context.imageSmoothingEnabled=!1),k.save(),S.save(),w.save(),k.translate(-a,-l),S.translate(-a,-l),w.translate(-a,-l),y.x=a,y.y=l,this._isUnderCache=!0,this._clearSelfAndDescendantCache($p),this._clearSelfAndDescendantCache(T_),this.drawScene(m,this,y),this.drawHit(_,this),this._isUnderCache=!1,k.restore(),S.restore(),d&&(k.save(),k.beginPath(),k.rect(0,0,o,i),k.closePath(),k.setAttr("strokeStyle","red"),k.setAttr("lineWidth",5),k.stroke(),k.restore()),Re.releaseCanvas(y._canvas),this._cache.set(ac,{scene:m,filter:v,hit:_,x:a,y:l}),this._requestDraw(),this}isCached(){return this._cache.has(ac)}getClientRect(t){throw new Error('abstract "getClientRect" method call')}_transformedRect(t,n){const r=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let o=1/0,i=1/0,s=-1/0,a=-1/0;const l=this.getAbsoluteTransform(n);return r.forEach(function(c){const d=l.point(c);o===void 0&&(o=s=d.x,i=a=d.y),o=Math.min(o,d.x),i=Math.min(i,d.y),s=Math.max(s,d.x),a=Math.max(a,d.y)}),{x:o,y:i,width:s-o,height:a-i}}_drawCachedSceneCanvas(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);const n=this._getCanvasCache();t.translate(n.x,n.y);const r=this._getCachedSceneCanvas(),o=r.pixelRatio;t.drawImage(r._canvas,0,0,r.width/o,r.height/o),t.restore()}_drawCachedHitCanvas(t){const n=this._getCanvasCache(),r=n.hit;t.save(),t.translate(n.x,n.y),t.drawImage(r._canvas,0,0,r.width/r.pixelRatio,r.height/r.pixelRatio),t.restore()}_getCachedSceneCanvas(){let t=this.filters(),n=this._getCanvasCache(),r=n.scene,o=n.filter,i=o.getContext(),s,a,l,c;if(!t||t.length===0)return r;if(this._filterUpToDate)return o;let d=!0;for(let h=0;h<t.length;h++)if(typeof t[h]=="string"&&A_(),typeof t[h]!="string"||!A_()){d=!1;break}const f=r.pixelRatio;if(o.setSize(r.width/r.pixelRatio,r.height/r.pixelRatio),d){const h=t.join(" ");return i.save(),i.setAttr("filter",h),i.drawImage(r._canvas,0,0,r.getWidth()/f,r.getHeight()/f),i.restore(),this._filterUpToDate=!0,o}try{for(s=t.length,i.clear(),i.drawImage(r._canvas,0,0,r.getWidth()/f,r.getHeight()/f),a=i.getImageData(0,0,o.getWidth(),o.getHeight()),l=0;l<s;l++)c=t[l],typeof c=="string"&&(c=XD(c)),c.call(this,a),i.putImageData(a,0,0)}catch(h){Re.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(E_),t.length===3)return this._delegate.apply(this,t);const o=n.split(Gp);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(Gp),o=r.length,i,s,a,l,c,d;if(this._cache&&this._cache.delete(E_),!t)for(s in this.eventListeners)this._off(s);for(i=0;i<o;i++)if(a=r[i],l=a.split("."),c=l[0],d=l[1],c)this.eventListeners[c]&&this._off(c,d,n);else for(s in this.eventListeners)this._off(s,d,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=Re.cloneObject(i),i.currentTarget=s[a],r.call(s[a],i)}),this}remove(){return this.isDragging()&&this.stopDrag(),On._dragElements.delete(this._id),On._dragElements.forEach((t,n)=>{this.isAncestorOf(t.node)&&On._dragElements.delete(n)}),this._remove(),this}_clearCaches(){this._clearSelfAndDescendantCache(wa),this._clearSelfAndDescendantCache($p),this._clearSelfAndDescendantCache(T_),this._clearSelfAndDescendantCache(L_),this._clearSelfAndDescendantCache(x0),this._clearSelfAndDescendantCache(I0)}_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"+Re._capitalize(t);return Re._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!==QD&&(r=R_+Re._capitalize(n),Re._isFunction(this[r])?this[r](t[n]):this._setAttr(n,t[n]))}),this}isListening(){return this._getCache(I0,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(x0,this._isVisible)}_isVisible(t){if(!this.visible())return!1;const n=this.getParent();return n&&n!==t&&this!==t?n._isVisible(t):!0}shouldDrawHit(t,n=!1){if(t)return this._isVisible(t)&&this._isListening(t);const r=this.getLayer();let o=!1;On._dragElements.forEach(s=>{s.dragStatus==="dragging"&&(s.node.nodeType==="Stage"||s.node.getLayer()===r)&&(o=!0)});const i=!n&&!St.hitOnDragEnabled&&(o||St.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(d){for(o=[],i=d.length,s=0;s<i;s++)a=d[s],r++,a.nodeType!==M_&&(o=o.concat(a.getChildren().slice())),a._id===n._id&&(s=i);o.length>0&&o[0].getDepth()<=t&&l(o)}const c=this.getStage();return n.nodeType!==sO&&c&&l(c.getChildren()),r}getDepth(){let t=0,n=this.parent;for(;n;)t++,n=n.parent;return t}_batchTransformChanges(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(hl),this._clearSelfAndDescendantCache(wa)),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 rs,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(hl);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(hl),this._clearSelfAndDescendantCache(wa),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 Re.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 Re.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 Re.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 Re.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 Re.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&Re.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($p,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=Re.isObject(r)&&!Re._isPlainObject(r)&&!Re._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 Re._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],Re.isValidSelector(i)||(Re.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Re.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Re.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(L_,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(wa,this._getAbsoluteTransform)}_getAbsoluteTransform(t){let n;if(t)return n=new rs,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(wa)||new rs,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(hl,this._getTransform)}_getTransform(){var t,n;const r=this._cache.get(hl)||new rs;r.reset();const o=this.x(),i=this.y(),s=St.getAngle(this.rotation()),a=(t=this.attrs.scaleX)!==null&&t!==void 0?t:1,l=(n=this.attrs.scaleY)!==null&&n!==void 0?n:1,c=this.attrs.skewX||0,d=this.attrs.skewY||0,f=this.attrs.offsetX||0,h=this.attrs.offsetY||0;return(o!==0||i!==0)&&r.translate(o,i),s!==0&&r.rotate(s),(c!==0||d!==0)&&r.skew(c,d),(a!==1||l!==1)&&r.scale(a,l),(f!==0||h!==0)&&r.translate(-1*f,-1*h),r.dirty=!1,r}clone(t){let n=Re.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(JD)<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 dl({width:t.width||Math.ceil(n.width)||(r?r.width():0),height:t.height||Math.ceil(n.height)||(r?r.height():0),pixelRatio:s}),l=a.getContext(),c=new dl({width:a.width/a.pixelRatio+Math.abs(o),height:a.height/a.pixelRatio+Math.abs(i),pixelRatio:a.pixelRatio});return t.imageSmoothingEnabled===!1&&(l._context.imageSmoothingEnabled=!1),l.save(),(o||i)&&l.translate(-1*o,-1*i),this.drawScene(a,void 0,c),l.restore(),a}toCanvas(t){return this._toKonvaCanvas(t)._canvas}toDataURL(t){t=t||{};const n=t.mimeType||null,r=t.quality||null,o=this._toKonvaCanvas(t).toDataURL(n,r);return t.callback&&t.callback(o),o}toImage(t){return new Promise((n,r)=>{try{const o=t?.callback;o&&delete t.callback,Re._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():St.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+ZD,{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[R_+Re._capitalize(t)];return Re._isFunction(r)?r.call(this,n):this._setAttr(t,n),this}_requestDraw(){if(St.autoDrawEnabled){const t=this.getLayer()||this.getStage();t?.batchDraw()}}_setAttr(t,n){const r=this.attrs[t];r===n&&!Re.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===M_&&(n.target=this);const o=[eO,tO,nO,rO,oO,iO];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=eh.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,eh.protoListenerMap.set(o,i)}return s}_fire(t,n){n=n||{},n.currentTarget=this,n.type=t;const r=this._getProtoListeners(t);if(r){const i=r.slice();for(let s=0;s<i.length;s++)i[s].handler.call(this,n)}const o=this.eventListeners[t];if(o){const i=o.slice(),s=i.length;for(let l=0;l<i.length;l++)i[l].handler.call(this,n);const a=this.eventListeners[t];if(a)for(let l=s;l<a.length;l++)a[l].handler.call(this,n)}}draw(){return this.drawScene(),this.drawHit(),this}_createDragElement(t){const n=t?t.pointerId:void 0,r=this.getStage(),o=this.getAbsolutePosition();if(!r)return;const i=r._getPointerById(n)||r._changedPointerPositions[0]||o;On._dragElements.set(this._id,{node:this,startPointerPos:i,offset:{x:i.x-o.x,y:i.y-o.y},dragStatus:"ready",pointerId:n,startEvent:t})}startDrag(t,n=!0){On._dragElements.has(this._id)||this._createDragElement(t);const r=On._dragElements.get(this._id);r.dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:r.startEvent&&r.startEvent.evt||t&&t.evt},n)}_setDragPosition(t,n){const r=this.getStage()._getPointerById(n.pointerId);if(!r)return;let o={x:r.x-n.offset.x,y:r.y-n.offset.y};const i=this.dragBoundFunc();if(i!==void 0){const s=i.call(this,o,t);s?o=s:Re.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this._lastPos.x!==o.x||this._lastPos.y!==o.y)&&(this.setAbsolutePosition(o),this._requestDraw()),this._lastPos=o}stopDrag(t){const n=On._dragElements.get(this._id);n&&(n.dragStatus="stopped"),On._endDragBefore(t),On._endDragAfter(t)}setDraggable(t){this._setAttr("draggable",t),this._dragChange()}isDragging(){const t=On._dragElements.get(this._id);return t?t.dragStatus==="dragging":!1}_listenDrag(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",function(t){if(!(t.evt.button===void 0||St.dragButtons.indexOf(t.evt.button)>=0)||this.isDragging())return;let n=!1;On._dragElements.forEach(r=>{this.isAncestorOf(r.node)&&(n=!0)}),n||this._createDragElement(t)})}_dragChange(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;const t=On._dragElements.get(this._id),n=t&&t.dragStatus==="dragging",r=t&&t.dragStatus==="ready";n?this.stopDrag():r&&On._dragElements.delete(this._id)}}_dragCleanup(){this.off("mousedown.konva"),this.off("touchstart.konva")}isClientRectOnScreen(t={x:0,y:0}){const n=this.getStage();if(!n)return!1;const r={x:-t.x,y:-t.y,width:n.width()+2*t.x,height:n.height()+2*t.y};return Re.haveIntersection(r,this.getClientRect())}static create(t,n){return Re._isString(t)&&(t=JSON.parse(t)),this._createNode(t,n)}static _createNode(t,n){let r=eh.prototype.getClassName.call(t),o=t.children,i,s,a;n&&(t.attrs.container=n),St[r]||(Re.warn('Can not find a node with class name "'+r+'". Fallback to "Shape".'),r="Shape");const l=St[r];if(i=new l(t.attrs),o)for(s=o.length,a=0;a<s;a++)i.add(eh._createNode(o[a]));return i}};_t.protoListenerMap=new Map,_t.prototype.nodeType="Node",_t.prototype._attrsAffectingSize=[],_t.prototype.eventListeners={},_t.prototype.on(aO,function(){if(this._batchingTransformChange){this._needClearTransformCache=!0;return}this._clearCache(hl),this._clearSelfAndDescendantCache(wa)}),_t.prototype.on("visibleChange.konva",function(){this._clearSelfAndDescendantCache(x0)}),_t.prototype.on("listeningChange.konva",function(){this._clearSelfAndDescendantCache(I0)}),_t.prototype.on("opacityChange.konva",function(){this._clearSelfAndDescendantCache($p)});var Qn=he.addGetterSetter;Qn(_t,"zIndex"),Qn(_t,"absolutePosition"),Qn(_t,"position"),Qn(_t,"x",0,bt()),Qn(_t,"y",0,bt()),Qn(_t,"globalCompositeOperation","source-over",sc()),Qn(_t,"opacity",1,bt()),Qn(_t,"name","",sc()),Qn(_t,"id","",sc()),Qn(_t,"rotation",0,bt()),he.addComponentsGetterSetter(_t,"scale",["x","y"]),Qn(_t,"scaleX",1,bt()),Qn(_t,"scaleY",1,bt()),he.addComponentsGetterSetter(_t,"skew",["x","y"]),Qn(_t,"skewX",0,bt()),Qn(_t,"skewY",0,bt()),he.addComponentsGetterSetter(_t,"offset",["x","y"]),Qn(_t,"offsetX",0,bt()),Qn(_t,"offsetY",0,bt()),Qn(_t,"dragDistance",void 0,bt()),Qn(_t,"width",0,bt()),Qn(_t,"height",0,bt()),Qn(_t,"listening",!0,os()),Qn(_t,"preventDefault",!0,os()),Qn(_t,"filters",void 0,function(e){return this._filterUpToDate=!1,e}),Qn(_t,"visible",!0,os()),Qn(_t,"transformsEnabled","all",sc()),Qn(_t,"size"),Qn(_t,"dragBoundFunc"),Qn(_t,"draggable",!1,os()),he.backCompat(_t,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"});var Ci=class extends _t{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=_t.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=_t.prototype.clone.call(this,e);return this.getChildren().forEach(function(n){t.add(n.clone())}),t}getAllIntersections(e){const t=[];return this.find("Shape").forEach(n=>{n.isVisible()&&n.intersects(e)&&t.push(n)}),t}_clearSelfAndDescendantCache(e){var t;super._clearSelfAndDescendantCache(e),!this.isCached()&&((t=this.children)===null||t===void 0||t.forEach(function(n){n._clearSelfAndDescendantCache(e)}))}_setChildrenIndices(){var e;(e=this.children)===null||e===void 0||e.forEach(function(t,n){t.index=n}),this._requestDraw()}drawScene(e,t,n){const r=this.getLayer(),o=e||r&&r.getCanvas(),i=o&&o.getContext(),s=this._getCanvasCache(),a=s&&s.scene,l=o&&o.isCache;if(!this.isVisible()&&!l)return this;if(a){i.save();const c=this.getAbsoluteTransform(t).getMatrix();i.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(i),i.restore()}else this._drawChildren("drawScene",o,t,n);return this}drawHit(e,t){if(!this.shouldDrawHit(t))return this;const n=this.getLayer(),r=e||n&&n.hitCanvas,o=r&&r.getContext(),i=this._getCanvasCache();if(i&&i.hit){o.save();const s=this.getAbsoluteTransform(t).getMatrix();o.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._drawCachedHitCanvas(o),o.restore()}else this._drawChildren("drawHit",r,t);return this}_drawChildren(e,t,n,r){var o;const i=t&&t.getContext(),s=this.clipWidth(),a=this.clipHeight(),l=this.clipFunc(),c=typeof s=="number"&&typeof a=="number"||l,d=n===this;if(c){i.save();const h=this.getAbsoluteTransform(n);let g=h.getMatrix();i.transform(g[0],g[1],g[2],g[3],g[4],g[5]),i.beginPath();let m;if(l)m=l.call(this,i,this);else{const v=this.clipX(),_=this.clipY();i.rect(v||0,_||0,s,a)}i.clip.apply(i,m),g=h.copy().invert().getMatrix(),i.transform(g[0],g[1],g[2],g[3],g[4],g[5])}const f=!d&&this.globalCompositeOperation()!=="source-over"&&e==="drawScene";f&&(i.save(),i._applyGlobalCompositeOperation(this)),(o=this.children)===null||o===void 0||o.forEach(function(h){h[e](t,n,r)}),f&&i.restore(),c&&i.restore()}getClientRect(e={}){var t;const n=e.skipTransform,r=e.relativeTo;let o,i,s,a,l={x:1/0,y:1/0,width:0,height:0};const c=this;(t=this.children)===null||t===void 0||t.forEach(function(h){if(!h.visible())return;const g=h.getClientRect({relativeTo:c,skipShadow:e.skipShadow,skipStroke:e.skipStroke});g.width===0&&g.height===0||(o===void 0?(o=g.x,i=g.y,s=g.x+g.width,a=g.y+g.height):(o=Math.min(o,g.x),i=Math.min(i,g.y),s=Math.max(s,g.x+g.width),a=Math.max(a,g.y+g.height)))});const d=this.find("Shape");let f=!1;for(let h=0;h<d.length;h++)if(d[h]._isVisible(this)){f=!0;break}return f&&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)}};he.addComponentsGetterSetter(Ci,"clip",["x","y","width","height"]),he.addGetterSetter(Ci,"clipX",void 0,bt()),he.addGetterSetter(Ci,"clipY",void 0,bt()),he.addGetterSetter(Ci,"clipWidth",void 0,bt()),he.addGetterSetter(Ci,"clipHeight",void 0,bt()),he.addGetterSetter(Ci,"clipFunc");var vf=new Map,P_=St._global.PointerEvent!==void 0;function E0(e){return vf.get(e)}function T0(e){return{evt:e,pointerId:e.pointerId}}function D_(e,t){return vf.get(e)===t}function O_(e,t){yf(e),t.getStage()&&(vf.set(e,t),P_&&t._fire("gotpointercapture",T0(new PointerEvent("gotpointercapture"))))}function yf(e,t){const n=vf.get(e);if(!n)return;const r=n.getStage();r&&r.content,vf.delete(e),P_&&n._fire("lostpointercapture",T0(new PointerEvent("lostpointercapture")))}var cO="Stage",uO="string",F_="px",dO="mouseout",N_="mouseleave",B_="mouseover",z_="mouseenter",V_="mousemove",j_="mousedown",U_="mouseup",bf="pointermove",wf="pointerdown",yu="pointerup",Cf="pointercancel",fO="lostpointercapture",Wp="pointerout",kf="pointerleave",Kp="pointerover",qp="pointerenter",R0="contextmenu",H_="touchstart",$_="touchend",G_="touchmove",W_="touchcancel",M0="wheel",hO=5,pO=[[z_,"_pointerenter"],[j_,"_pointerdown"],[V_,"_pointermove"],[U_,"_pointerup"],[N_,"_pointerleave"],[H_,"_pointerdown"],[G_,"_pointermove"],[$_,"_pointerup"],[W_,"_pointercancel"],[B_,"_pointerover"],[M0,"_wheel"],[R0,"_contextmenu"],[wf,"_pointerdown"],[bf,"_pointermove"],[yu,"_pointerup"],[Cf,"_pointercancel"],[kf,"_pointerleave"],[fO,"_lostpointercapture"]],L0={mouse:{[Wp]:dO,[kf]:N_,[Kp]:B_,[qp]:z_,[bf]:V_,[wf]:j_,[yu]:U_,[Cf]:"mousecancel",pointerclick:"click",pointerdblclick:"dblclick"},touch:{[Wp]:"touchout",[kf]:"touchleave",[Kp]:"touchover",[qp]:"touchenter",[bf]:G_,[wf]:H_,[yu]:$_,[Cf]:W_,pointerclick:"tap",pointerdblclick:"dbltap"},pointer:{[Wp]:Wp,[kf]:kf,[Kp]:Kp,[qp]:qp,[bf]:bf,[wf]:wf,[yu]:yu,[Cf]:Cf,pointerclick:"pointerclick",pointerdblclick:"pointerdblclick"}},Sf=e=>e.indexOf("pointer")>=0?"pointer":e.indexOf("touch")>=0?"touch":"mouse",bu=e=>{const t=Sf(e);if(t==="pointer")return St.pointerEventsEnabled&&L0.pointer;if(t==="touch")return L0.touch;if(t==="mouse")return L0.mouse};function K_(e={}){return(e.clipFunc||e.clipWidth||e.clipHeight)&&Re.warn("Stage does not support clipping. Please use clip for Layers or Groups."),e}var mO="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);",_f=[],Yp=class extends Ci{constructor(e){super(K_(e)),this._pointerPositions=[],this._changedPointerPositions=[],this._buildDOM(),this._bindContentEvents(),_f.push(this),this.on("widthChange.konva heightChange.konva",this._resizeDOM),this.on("visibleChange.konva",this._checkVisibility),this.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",()=>{K_(this.attrs)}),this._checkVisibility()}_validateAdd(e){const t=e.getType()==="Layer",n=e.getType()==="FastLayer";t||n||Re.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===uO){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"),Ci.prototype.clone.call(this,e)}destroy(){super.destroy();const e=this.content;e&&Re._isInDocument(e)&&this.container().removeChild(e);const t=_f.indexOf(this);return t>-1&&_f.splice(t,1),Re.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}:(Re.warn(mO),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 dl({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+F_,this.content.style.height=t+F_),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>hO&&Re.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(),St.isBrowser&&this.content.appendChild(e.canvas._canvas),this}getParent(){return null}getLayer(){return null}hasPointerCapture(e){return D_(e,this)}setPointerCapture(e){O_(e,this)}releaseCapture(e){yf(e,this)}getLayers(){return this.children}_bindContentEvents(){St.isBrowser&&pO.forEach(([e,t])=>{this.content.addEventListener(e,n=>{this[t](n)},{passive:!1})})}_pointerenter(e){this.setPointersPositions(e);const t=bu(e.type);t&&this._fire(t.pointerenter,{evt:e,target:this,currentTarget:this})}_pointerover(e){this.setPointersPositions(e);const t=bu(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=bu(e.type),n=Sf(e.type);if(!t)return;this.setPointersPositions(e);const r=this._getTargetShape(n),o=!(St.isDragging()||St.isTransforming())||St.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=bu(e.type),n=Sf(e.type);if(!t)return;this.setPointersPositions(e);let r=!1;this._changedPointerPositions.forEach(o=>{const i=this.getIntersection(o);if(On.justDragged=!1,St["_"+n+"ListenClick"]=!0,!i||!i.isListening()){this[n+"ClickStartShape"]=void 0;return}St.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=bu(e.type),n=Sf(e.type);if(!t)return;const r=e.type.indexOf("touch")>=0||e.pointerType==="touch";if(St.isDragging()&&On.node.preventDefault()&&e.cancelable&&r&&e.preventDefault(),this.setPointersPositions(e),!(!(St.isDragging()||St.isTransforming())||St.hitOnDragEnabled))return;const o={};let i=!1;const s=this._getTargetShape(n);this._changedPointerPositions.forEach(a=>{const l=E0(a.id)||this.getIntersection(a),c=a.id,d={evt:e,pointerId:c},f=s!==l;if(f&&s&&(s._fireAndBubble(t.pointerout,{...d},l),s._fireAndBubble(t.pointerleave,{...d},l)),l){if(o[l._id])return;o[l._id]=!0}l&&l.isListening()?(i=!0,f&&(l._fireAndBubble(t.pointerover,{...d},s),l._fireAndBubble(t.pointerenter,{...d},s),this[n+"targetShape"]=l),l._fireAndBubble(t.pointermove,{...d})):s&&(this._fire(t.pointerover,{evt:e,target:this,currentTarget:this,pointerId:c}),this[n+"targetShape"]=null)}),i||this._fire(t.pointermove,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}_pointerup(e){const t=bu(e.type),n=Sf(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=E0(a.id)||this.getIntersection(a);if(l){if(l.releaseCapture(a.id),i[l._id])return;i[l._id]=!0}const c=a.id,d={evt:e,pointerId:c};let f=!1;St["_"+n+"InDblClickWindow"]?(f=!0,clearTimeout(this[n+"DblTimeout"])):On.justDragged||(St["_"+n+"InDblClickWindow"]=!0,clearTimeout(this[n+"DblTimeout"])),this[n+"DblTimeout"]=setTimeout(function(){St["_"+n+"InDblClickWindow"]=!1},St.dblClickWindow),l&&l.isListening()?(s=!0,this[n+"ClickEndShape"]=l,l._fireAndBubble(t.pointerup,{...d}),St["_"+n+"ListenClick"]&&r&&r===l&&(l._fireAndBubble(t.pointerclick,{...d}),f&&o&&o===l&&l._fireAndBubble(t.pointerdblclick,{...d}))):(this[n+"ClickEndShape"]=null,s||(this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),s=!0),St["_"+n+"ListenClick"]&&this._fire(t.pointerclick,{evt:e,target:this,currentTarget:this,pointerId:c}),f&&this._fire(t.pointerdblclick,{evt:e,target:this,currentTarget:this,pointerId:c}))}),s||this._fire(t.pointerup,{evt:e,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),St["_"+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(R0,{evt:e}):this._fire(R0,{evt:e,target:this,currentTarget:this})}_wheel(e){this.setPointersPositions(e);const t=this.getIntersection(this.getPointerPosition());t&&t.isListening()?t._fireAndBubble(M0,{evt:e}):this._fire(M0,{evt:e,target:this,currentTarget:this})}_pointercancel(e){this.setPointersPositions(e);const t=E0(e.pointerId)||this.getIntersection(this.getPointerPosition());t&&t._fireAndBubble(yu,T0(e)),yf(e.pointerId)}_lostpointercapture(e){yf(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:Re._getFirstPointerId(e)}],this._changedPointerPositions=[{x:n,y:r,id:Re._getFirstPointerId(e)}])}_setPointerPosition(e){Re.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 dl({width:this.width(),height:this.height()}),this.bufferHitCanvas=new _0({pixelRatio:1,width:this.width(),height:this.height()}),!St.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 Re.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}};Yp.prototype.nodeType=cO,br(Yp),he.addGetterSetter(Yp,"container"),St.isBrowser&&document.addEventListener("visibilitychange",()=>{_f.forEach(e=>{e.batchDraw()})});var q_="hasShadow",Y_="shadowRGBA",X_="patternImage",Z_="linearGradient",Q_="radialGradient",Xp;function P0(){return Xp||(Xp=Re.createCanvasElement().getContext("2d"),Xp)}var Af={};function gO(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function vO(e){e.stroke()}function yO(e){const t=this.attrs.fillRule;t?e.fill(t):e.fill()}function bO(e){e.stroke()}function wO(){this._clearCache(q_)}function CO(){this._clearCache(Y_)}function kO(){this._clearCache(X_)}function SO(){this._clearCache(Z_)}function _O(){this._clearCache(Q_)}var vt=class extends _t{constructor(e){super(e);let t,n=0;for(;t=Re.getHitColor(),!(t&&!(t in Af));)if(n++,n>=1e4){Re.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=Re.getRandomColor();break}this.colorKey=t,Af[t]=this}getContext(){return Re.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}getCanvas(){return Re.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(q_,this._hasShadow)}_hasShadow(){return this.shadowEnabled()&&this.shadowOpacity()!==0&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}_getFillPattern(){return this._getCache(X_,this.__getFillPattern)}__getFillPattern(){if(this.fillPatternImage()){const e=P0().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(e&&e.setTransform){const t=new rs;t.translate(this.fillPatternX(),this.fillPatternY()),t.rotate(St.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(Z_,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(Q_,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(Y_,this._getShadowRGBA)}_getShadowRGBA(){if(!this.hasShadow())return;const e=Re.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 _t.prototype.destroy.call(this),delete Af[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){Re.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),e?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}getStrokeHitEnabled(){return this.hitStrokeWidth()!==0}getSelfRect(){const e=this.size();return{x:this._centroid?-e.width/2:0,y:this._centroid?-e.height/2:0,width:e.width,height:e.height}}getClientRect(e={}){let t=!1,n=this.getParent();for(;n;){if(n.isCached()){t=!0;break}n=n.getParent()}const r=e.skipTransform,o=e.relativeTo||t&&this.getStage()||void 0,i=this.getSelfRect(),s=!e.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=i.width+s,l=i.height+s,c=!e.skipShadow&&this.hasShadow(),d=c?this.shadowOffsetX():0,f=c?this.shadowOffsetY():0,h=a+Math.abs(d),g=l+Math.abs(f),m=c&&this.shadowBlur()||0,v={width:h+m*2,height:g+m*2,x:-(s/2+m)+Math.min(d,0)+i.x,y:-(s/2+m)+Math.min(f,0)+i.y};return r?v:this._transformedRect(v,o)}drawScene(e,t,n){const r=this.getLayer(),o=(e||r.getCanvas()).getContext(),i=this._getCanvasCache(),s=this.getSceneFunc(),a=this.hasShadow();let l;const c=t===this;if(!this.isVisible()&&!c)return this;if(i){o.save();const d=this.getAbsoluteTransform(t).getMatrix();return o.transform(d[0],d[1],d[2],d[3],d[4],d[5]),this._drawCachedSceneCanvas(o),o.restore(),this}if(!s)return this;if(o.save(),this._useBufferCanvas()){l=this.getStage();const d=n||l.bufferCanvas,f=d.getContext();n?(f.save(),f.setTransform(1,0,0,1,0,0),f.clearRect(0,0,d.width,d.height),f.restore()):f.clear(),f.save(),f._applyLineJoin(this),f._applyMiterLimit(this);const h=this.getAbsoluteTransform(t).getMatrix();f.transform(h[0],h[1],h[2],h[3],h[4],h[5]),s.call(this,f,this),f.restore();const g=d.pixelRatio;a&&o._applyShadow(this),c||(o._applyOpacity(this),o._applyGlobalCompositeOperation(this)),o.drawImage(d._canvas,d.x||0,d.y||0,d.width/g,d.height/g)}else{if(o._applyLineJoin(this),o._applyMiterLimit(this),!c){const d=this.getAbsoluteTransform(t).getMatrix();o.transform(d[0],d[1],d[2],d[3],d[4],d[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||Re.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){i.save();const c=this.getAbsoluteTransform(t).getMatrix();return i.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedHitCanvas(i),i.restore(),this}if(!s)return this;if(i.save(),i._applyLineJoin(this),i._applyMiterLimit(this),this!==t){const c=this.getAbsoluteTransform(t).getMatrix();i.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return s.call(this,i,this),i.restore(),this}drawHitFromCache(e=0){const t=this._getCanvasCache(),n=this._getCachedSceneCanvas(),r=t.hit,o=r.getContext(),i=r.getWidth(),s=r.getHeight();o.clear(),o.drawImage(n._canvas,0,0,i,s);try{const a=o.getImageData(0,0,i,s),l=a.data,c=l.length,d=Re._hexToRgb(this.colorKey);for(let f=0;f<c;f+=4)l[f+3]>e?(l[f]=d.r,l[f+1]=d.g,l[f+2]=d.b,l[f+3]=255):l[f+3]=0;o.putImageData(a,0,0)}catch(a){Re.error("Unable to draw hit graph from cached scene canvas. "+a.message)}return this}hasPointerCapture(e){return D_(e,this)}setPointerCapture(e){O_(e,this)}releaseCapture(e){yf(e,this)}};vt.prototype._fillFunc=gO,vt.prototype._strokeFunc=vO,vt.prototype._fillFuncHit=yO,vt.prototype._strokeFuncHit=bO,vt.prototype._centroid=!1,vt.prototype.nodeType="Shape",br(vt),vt.prototype.eventListeners={},vt.prototype.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",wO),vt.prototype.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",CO),vt.prototype.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",kO),vt.prototype.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",SO),vt.prototype.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",_O),he.addGetterSetter(vt,"stroke",void 0,x_()),he.addGetterSetter(vt,"strokeWidth",2,bt()),he.addGetterSetter(vt,"fillAfterStrokeEnabled",!1),he.addGetterSetter(vt,"hitStrokeWidth","auto",A0()),he.addGetterSetter(vt,"strokeHitEnabled",!0,os()),he.addGetterSetter(vt,"perfectDrawEnabled",!0,os()),he.addGetterSetter(vt,"shadowForStrokeEnabled",!0,os()),he.addGetterSetter(vt,"lineJoin"),he.addGetterSetter(vt,"lineCap"),he.addGetterSetter(vt,"miterLimit"),he.addGetterSetter(vt,"sceneFunc"),he.addGetterSetter(vt,"hitFunc"),he.addGetterSetter(vt,"dash"),he.addGetterSetter(vt,"dashOffset",0,bt()),he.addGetterSetter(vt,"shadowColor",void 0,sc()),he.addGetterSetter(vt,"shadowBlur",0,bt()),he.addGetterSetter(vt,"shadowOpacity",1,bt()),he.addComponentsGetterSetter(vt,"shadowOffset",["x","y"]),he.addGetterSetter(vt,"shadowOffsetX",0,bt()),he.addGetterSetter(vt,"shadowOffsetY",0,bt()),he.addGetterSetter(vt,"fillPatternImage"),he.addGetterSetter(vt,"fill",void 0,x_()),he.addGetterSetter(vt,"fillPatternX",0,bt()),he.addGetterSetter(vt,"fillPatternY",0,bt()),he.addGetterSetter(vt,"fillLinearGradientColorStops"),he.addGetterSetter(vt,"strokeLinearGradientColorStops"),he.addGetterSetter(vt,"fillRadialGradientStartRadius",0),he.addGetterSetter(vt,"fillRadialGradientEndRadius",0),he.addGetterSetter(vt,"fillRadialGradientColorStops"),he.addGetterSetter(vt,"fillPatternRepeat","repeat"),he.addGetterSetter(vt,"fillEnabled",!0),he.addGetterSetter(vt,"strokeEnabled",!0),he.addGetterSetter(vt,"shadowEnabled",!0),he.addGetterSetter(vt,"dashEnabled",!0),he.addGetterSetter(vt,"strokeScaleEnabled",!0),he.addGetterSetter(vt,"fillPriority","color"),he.addComponentsGetterSetter(vt,"fillPatternOffset",["x","y"]),he.addGetterSetter(vt,"fillPatternOffsetX",0,bt()),he.addGetterSetter(vt,"fillPatternOffsetY",0,bt()),he.addComponentsGetterSetter(vt,"fillPatternScale",["x","y"]),he.addGetterSetter(vt,"fillPatternScaleX",1,bt()),he.addGetterSetter(vt,"fillPatternScaleY",1,bt()),he.addComponentsGetterSetter(vt,"fillLinearGradientStartPoint",["x","y"]),he.addComponentsGetterSetter(vt,"strokeLinearGradientStartPoint",["x","y"]),he.addGetterSetter(vt,"fillLinearGradientStartPointX",0),he.addGetterSetter(vt,"strokeLinearGradientStartPointX",0),he.addGetterSetter(vt,"fillLinearGradientStartPointY",0),he.addGetterSetter(vt,"strokeLinearGradientStartPointY",0),he.addComponentsGetterSetter(vt,"fillLinearGradientEndPoint",["x","y"]),he.addComponentsGetterSetter(vt,"strokeLinearGradientEndPoint",["x","y"]),he.addGetterSetter(vt,"fillLinearGradientEndPointX",0),he.addGetterSetter(vt,"strokeLinearGradientEndPointX",0),he.addGetterSetter(vt,"fillLinearGradientEndPointY",0),he.addGetterSetter(vt,"strokeLinearGradientEndPointY",0),he.addComponentsGetterSetter(vt,"fillRadialGradientStartPoint",["x","y"]),he.addGetterSetter(vt,"fillRadialGradientStartPointX",0),he.addGetterSetter(vt,"fillRadialGradientStartPointY",0),he.addComponentsGetterSetter(vt,"fillRadialGradientEndPoint",["x","y"]),he.addGetterSetter(vt,"fillRadialGradientEndPointX",0),he.addGetterSetter(vt,"fillRadialGradientEndPointY",0),he.addGetterSetter(vt,"fillPatternRotation",0),he.addGetterSetter(vt,"fillRule",void 0,sc()),he.backCompat(vt,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"});var AO="beforeDraw",IO="draw",J_=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],xO=J_.length,lc=class extends Ci{constructor(e){super(e),this.canvas=new dl,this.hitCanvas=new _0({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(){_t.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(!_t.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(_t.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(_t.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 _t.prototype.remove.call(this),e&&e.parentNode&&Re._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"&&Re.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(),_t.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(){Re.warn('Can not change width of layer. Use "stage.width(value)" function instead.')}getHeight(){if(this.parent)return this.parent.height()}setHeight(){Re.warn('Can not change height of layer. Use "stage.height(value)" function instead.')}batchDraw(){return this._waitingForDraw||(this._waitingForDraw=!0,Re.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<xO;r++){const o=J_[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=Re.getHitColorKey(n[0],n[1],n[2]),i=Af[o];return i?{shape:i}:{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(AO,{node:this}),this.clearBeforeDraw()&&o.getContext().clear(),Ci.prototype.drawScene.call(this,o,t,n),this._fire(IO,{node:this}),this}drawHit(e,t){const n=this.getLayer(),r=e||n&&n.hitCanvas;return n&&n.clearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Ci.prototype.drawHit.call(this,r,t),this}enableHitGraph(){return this.hitGraphEnabled(!0),this}disableHitGraph(){return this.hitGraphEnabled(!1),this}setHitGraphEnabled(e){Re.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(e)}getHitGraphEnabled(e){return Re.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 Re.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),super.destroy()}};lc.prototype.nodeType="Layer",br(lc),he.addGetterSetter(lc,"imageSmoothingEnabled",!0),he.addGetterSetter(lc,"clearBeforeDraw",!0),he.addGetterSetter(lc,"hitGraphEnabled",!0,os());var D0=class extends lc{constructor(e){super(e),this.listening(!1),Re.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.')}};D0.prototype.nodeType="FastLayer",br(D0);var wu=class extends Ci{_validateAdd(e){const t=e.getType();t!=="Group"&&t!=="Shape"&&Re.throw("You may only add groups and shapes to groups.")}};wu.prototype.nodeType="Group",br(wu);var O0=(function(){return ic.performance&&ic.performance.now?function(){return ic.performance.now()}:function(){return new Date().getTime()}})(),Cu=class ed{constructor(t,n){this.id=ed.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:O0(),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=ed.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=O0(),ed._addAnimation(this),this}stop(){return ed._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(O0());const a=i.length;let l;if(s?l=s.call(o,o.frame)!==!1:l=!0,!!l)for(let c=0;c<a;c++){const d=i[c];d._id!==void 0&&(t[d._id]=d)}}for(const r in t)t.hasOwnProperty(r)&&t[r].batchDraw()}static _animationLoop(){const t=ed;t.animations.length?(t._runFrames(),Re.requestAnimFrame(t._animationLoop)):t.animRunning=!1}static _handleAnimation(){this.animRunning||(this.animRunning=!0,Re.requestAnimFrame(this._animationLoop))}};Cu.animations=[],Cu.animIdCounter=0,Cu.animRunning=!1;var EO={node:1,duration:1,easing:1,onFinish:1,yoyo:1},TO=1,e4=2,t4=3,n4=["fill","stroke","shadowColor"],RO=0,MO=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=e4,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}reverse(){this.state=t4,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===e4?this.setTime(e):this.state===t4&&this.setTime(this.duration-e)}pause(){this.state=TO,this.fire("onPause")}getTimer(){return new Date().getTime()}},Zp=class Fr{constructor(t){const n=this,r=t.node,o=r._id,i=t.easing||If.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=RO++;const c=r.getLayer()||(r instanceof St.Stage?r.getLayers():null);c||Re.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Cu(function(){n.tween.onEnterFrame()},c),this.tween=new MO(l,function(d){n._tweenFunc(d)},i,0,1,a*1e3,s),this._addListeners(),Fr.attrs[o]||(Fr.attrs[o]={}),Fr.attrs[o][this._id]||(Fr.attrs[o][this._id]={}),Fr.tweens[o]||(Fr.tweens[o]={});for(l in t)EO[l]===void 0&&this._addAttr(l,t[l]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset,this.onUpdate=t.onUpdate}_addAttr(t,n){const r=this.node,o=r._id;let i,s,a,l,c;const d=Fr.tweens[o][t];d&&delete Fr.attrs[o][d][t];let f=r.getAttr(t);if(Re._isArray(n))if(i=[],s=Math.max(n.length,f.length),t==="points"&&n.length!==f.length&&(n.length>f.length?(l=f,f=Re._prepareArrayForTween(f,n,r.closed())):(a=n,n=Re._prepareArrayForTween(n,f,r.closed()))),t.indexOf("fill")===0)for(let h=0;h<s;h++)if(h%2===0)i.push(n[h]-f[h]);else{const g=Re.colorToRGBA(f[h]);c=Re.colorToRGBA(n[h]),f[h]=g,i.push({r:c.r-g.r,g:c.g-g.g,b:c.b-g.b,a:c.a-g.a})}else for(let h=0;h<s;h++)i.push(n[h]-f[h]);else n4.indexOf(t)!==-1?(f=Re.colorToRGBA(f),c=Re.colorToRGBA(n),i={r:c.r-f.r,g:c.g-f.g,b:c.b-f.b,a:c.a-f.a}):i=n-f;Fr.attrs[o][this._id][t]={start:f,diff:i,end:n,trueEnd:a,trueStart:l},Fr.tweens[o][t]=this._id}_tweenFunc(t){const n=this.node,r=Fr.attrs[n._id][this._id];let o,i,s,a,l,c,d,f;for(o in r){if(i=r[o],s=i.start,a=i.diff,f=i.end,Re._isArray(s))if(l=[],d=Math.max(s.length,f.length),o.indexOf("fill")===0)for(c=0;c<d;c++)c%2===0?l.push((s[c]||0)+a[c]*t):l.push("rgba("+Math.round(s[c].r+a[c].r*t)+","+Math.round(s[c].g+a[c].g*t)+","+Math.round(s[c].b+a[c].b*t)+","+(s[c].a+a[c].a*t)+")");else for(c=0;c<d;c++)l.push((s[c]||0)+a[c]*t);else n4.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=Fr.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=Fr.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=Fr.tweens[t];this.pause(),this.anim&&this.anim.stop();for(const o in r)delete Fr.tweens[t][o];delete Fr.attrs[t][n],Fr.tweens[t]&&(Object.keys(Fr.tweens[t]).length===0&&delete Fr.tweens[t],Object.keys(Fr.attrs[t]).length===0&&delete Fr.attrs[t])}};Zp.attrs={},Zp.tweens={},_t.prototype.to=function(e){const t=e.onFinish;e.node=this,e.onFinish=function(){this.destroy(),t&&t()},new Zp(e).play()};var If={BackEaseIn(e,t,n,r){return n*(e/=r)*e*(2.70158*e-1.70158)+t},BackEaseOut(e,t,n,r){return n*((e=e/r-1)*e*(2.70158*e+1.70158)+1)+t},BackEaseInOut(e,t,n,r){let o=1.70158;return(e/=r/2)<1?n/2*(e*e*(((o*=1.525)+1)*e-o))+t:n/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+t},ElasticEaseIn(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r)===1?t+n:(i||(i=r*.3),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),-(o*Math.pow(2,10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i))+t)},ElasticEaseOut(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r)===1?t+n:(i||(i=r*.3),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),o*Math.pow(2,-10*e)*Math.sin((e*r-s)*(2*Math.PI)/i)+n+t)},ElasticEaseInOut(e,t,n,r,o,i){let s=0;return e===0?t:(e/=r/2)===2?t+n:(i||(i=r*(.3*1.5)),!o||o<Math.abs(n)?(o=n,s=i/4):s=i/(2*Math.PI)*Math.asin(n/o),e<1?-.5*(o*Math.pow(2,10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i))+t:o*Math.pow(2,-10*(e-=1))*Math.sin((e*r-s)*(2*Math.PI)/i)*.5+n+t)},BounceEaseOut(e,t,n,r){return(e/=r)<1/2.75?n*(7.5625*e*e)+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t},BounceEaseIn(e,t,n,r){return n-If.BounceEaseOut(r-e,0,n,r)+t},BounceEaseInOut(e,t,n,r){return e<r/2?If.BounceEaseIn(e*2,0,n,r)*.5+t:If.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}},r4=Re._assign(St,{Util:Re,Transform:rs,Node:_t,Container:Ci,Stage:Yp,stages:_f,Layer:lc,FastLayer:D0,Group:wu,DD:On,Shape:vt,shapes:Af,Animation:Cu,Tween:Zp,Easings:If,Context:jp,Canvas:S0}),Ca=class extends vt{_sceneFunc(e){const t=St.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=St.getAngle(n?360-this.angle():this.angle()),o=Math.cos(Math.min(r,Math.PI)),i=1,s=Math.sin(Math.min(Math.max(Math.PI,r),3*Math.PI/2)),a=Math.sin(Math.min(r,Math.PI/2)),l=o*(o>0?e:t),c=i*t,d=s*(s>0?e:t),f=a*(a>0?t:e);return{x:l,y:n?-1*f:d,width:c-l,height:f-d}}};Ca.prototype._centroid=!0,Ca.prototype.className="Arc",Ca.prototype._attrsAffectingSize=["innerRadius","outerRadius","angle","clockwise"],br(Ca),he.addGetterSetter(Ca,"innerRadius",0,bt()),he.addGetterSetter(Ca,"outerRadius",0,bt()),he.addGetterSetter(Ca,"angle",0,bt()),he.addGetterSetter(Ca,"clockwise",!1,os());function F0(e,t,n,r,o,i,s){const a=Math.sqrt(Math.pow(n-e,2)+Math.pow(r-t,2)),l=Math.sqrt(Math.pow(o-n,2)+Math.pow(i-r,2)),c=s*a/(a+l),d=s*l/(a+l);return[n-c*(o-e),r-c*(i-t),n+d*(o-e),r+d*(i-t)]}function o4(e,t){const n=e.length,r=[];for(let o=2;o<n-2;o+=2){const i=F0(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 LO(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 ka=class extends vt{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():o4(this.points(),this.tension())}_getTensionPointsClosed(){const e=this.points(),t=e.length,n=this.tension(),r=F0(e[t-2],e[t-1],e[0],e[1],e[2],e[3],n),o=F0(e[t-4],e[t-3],e[t-2],e[t-1],e[0],e[1],n),i=o4(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],...LO(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}}};ka.prototype.className="Line",ka.prototype._attrsAffectingSize=["points","bezier","tension"],br(ka),he.addGetterSetter(ka,"closed",!1),he.addGetterSetter(ka,"bezier",!1),he.addGetterSetter(ka,"tension",0,bt()),he.addGetterSetter(ka,"points",[],qD());var PO=[[],[],[-.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]],DO=[[],[],[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]],OO=[[1],[1,1],[1,2,1],[1,3,3,1]],i4=(e,t,n)=>{let r,o;const s=n/2;r=0;for(let a=0;a<20;a++)o=s*PO[20][a]+s,r+=DO[20][a]*FO(e,t,o);return s*r},s4=(e,t,n)=>{n===void 0&&(n=1);const r=e[0]-2*e[1]+e[2],o=t[0]-2*t[1]+t[2],i=2*e[1]-2*e[0],s=2*t[1]-2*t[0],a=4*(r*r+o*o),l=4*(r*i+o*s),c=i*i+s*s;if(a===0)return n*Math.sqrt(Math.pow(e[2]-e[0],2)+Math.pow(t[2]-t[0],2));const d=l/(2*a),f=c/a,h=n+d,g=f-d*d,m=h*h+g>0?Math.sqrt(h*h+g):0,v=d*d+g>0?Math.sqrt(d*d+g):0,_=d+Math.sqrt(d*d+g)!==0?g*Math.log(Math.abs((h+m)/(d+v))):0;return Math.sqrt(a)/2*(h*m-d*v+_)};function FO(e,t,n){const r=N0(1,n,e),o=N0(1,n,t),i=r*r+o*o;return Math.sqrt(i)}var N0=(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+=OO[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 N0(e-1,t,o)}},a4=(e,t,n)=>{let r=1,o=e/t,i=(e-n(o))/t,s=0;for(;r>.001;){const a=n(o+i),l=Math.abs(e-a)/t;if(l<r)r=l,o+=i;else{const c=n(o-i),d=Math.abs(e-c)/t;d<r?(r=d,o-=i):i/=2}if(s++,s>500)break}return o},Fi=class mi extends vt{constructor(t){super(t),this.dataArray=[],this.pathLength=0,this._readDataAttribute(),this.on("dataChange.konva",function(){this._readDataAttribute()})}_readDataAttribute(){this.dataArray=mi.parsePathData(this.data()),this.pathLength=mi.getPathLength(this.dataArray)}_sceneFunc(t){const n=this.dataArray;t.beginPath();let r=!1;for(let o=0;o<n.length;o++){const i=n[o].command,s=n[o].points;switch(i){case"L":t.lineTo(s[0],s[1]);break;case"M":t.moveTo(s[0],s[1]);break;case"C":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"Q":t.quadraticCurveTo(s[0],s[1],s[2],s[3]);break;case"A":const a=s[0],l=s[1],c=s[2],d=s[3],f=s[4],h=s[5],g=s[6],m=s[7],v=c>d?c:d,_=c>d?1:c/d,k=c>d?d/c:1;t.translate(a,l),t.rotate(g),t.scale(_,k),t.arc(0,0,v,f,f+h,1-m),t.scale(1/_,1/k),t.rotate(-g),t.translate(-a,-l);break;case"z":r=!0,t.closePath()}}!r&&!this.hasFill()?t.strokeShape(this):t.fillStrokeShape(this)}getSelfRect(){let t=[];this.dataArray.forEach(function(l){if(l.command==="A"){const c=l.points[4],d=l.points[5],f=l.points[4]+d;let h=Math.PI/180;if(Math.abs(c-f)<h&&(h=Math.abs(c-f)),d<0)for(let g=c-h;g>f;g-=h){const m=mi.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],g,0);t.push(m.x,m.y)}else for(let g=c+h;g<f;g+=h){const m=mi.getPointOnEllipticalArc(l.points[0],l.points[1],l.points[2],l.points[3],g,0);t.push(m.x,m.y)}}else if(l.command==="C")for(let c=0;c<=1;c+=.01){const d=mi.getPointOnCubicBezier(c,l.start.x,l.start.y,l.points[0],l.points[1],l.points[2],l.points[3],l.points[4],l.points[5]);t.push(d.x,d.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 mi.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 mi.getPointOnLine(t,s.start.x,s.start.y,a[0],a[1]);case"C":return mi.getPointOnCubicBezier(a4(t,mi.getPathLength(n),v=>i4([s.start.x,a[0],a[2],a[4]],[s.start.y,a[1],a[3],a[5]],v)),s.start.x,s.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return mi.getPointOnQuadraticBezier(a4(t,mi.getPathLength(n),v=>s4([s.start.x,a[0],a[2]],[s.start.y,a[1],a[3]],v)),s.start.x,s.start.y,a[0],a[1],a[2],a[3]);case"A":const l=a[0],c=a[1],d=a[2],f=a[3],h=a[5],g=a[6];let m=a[4];return m+=h*t/s.pathLength,mi.getPointOnEllipticalArc(l,c,d,f,m,g)}return null}static getPointOnLine(t,n,r,o,i,s,a){s=s??n,a=a??r;const l=this.getLineLength(n,r,o,i);if(l<1e-10)return{x:n,y:r};if(o===n)return{x:s,y:a+(i>r?t:-t)};const c=(i-r)/(o-n),d=Math.sqrt(t*t/(1+c*c))*(o<n?-1:1),f=c*d;if(Math.abs(a-r-c*(s-n))<1e-10)return{x:s+d,y:a+f};const h=((s-n)*(o-n)+(a-r)*(i-r))/(l*l),g=n+h*(o-n),m=r+h*(i-r),v=this.getLineLength(s,a,g,m),_=Math.sqrt(t*t-v*v),k=Math.sqrt(_*_/(1+c*c))*(o<n?-1:1),S=c*k;return{x:g+k,y:m+S}}static getPointOnCubicBezier(t,n,r,o,i,s,a,l,c){function d(m){return m*m*m}function f(m){return 3*m*m*(1-m)}function h(m){return 3*m*(1-m)*(1-m)}function g(m){return(1-m)*(1-m)*(1-m)}return{x:l*d(t)+s*f(t)+o*h(t)+n*g(t),y:c*d(t)+a*f(t)+i*h(t)+r*g(t)}}static getPointOnQuadraticBezier(t,n,r,o,i,s,a){function l(f){return f*f}function c(f){return 2*f*(1-f)}function d(f){return(1-f)*(1-f)}return{x:s*l(t)+o*c(t)+n*d(t),y:a*l(t)+i*c(t)+r*d(t)}}static getPointOnEllipticalArc(t,n,r,o,i,s){const a=Math.cos(s),l=Math.sin(s),c={x:r*Math.cos(i),y:o*Math.sin(i)};return{x:t+(c.x*a-c.y*l),y:n+(c.x*l+c.y*a)}}static parsePathData(t){if(!t)return[];let n=t;const r=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];n=n.replace(new RegExp(" ","g"),",");for(let f=0;f<r.length;f++)n=n.replace(new RegExp(r[f],"g"),"|"+r[f]);const o=n.split("|"),i=[],s=[];let a=0,l=0;const c=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;let d;for(let f=1;f<o.length;f++){let h=o[f],g=h.charAt(0);for(h=h.slice(1),s.length=0;d=c.exec(h);)s.push(d[0]);let m=[],v=g==="A"||g==="a"?0:-1;for(let _=0,k=s.length;_<k;_++){const S=s[_];if(S==="00"){m.push(0,0),v>=0&&(v+=2,v>=7&&(v-=7));continue}if(v>=0){if(v===3){if(/^[01]{2}\d+(?:\.\d+)?$/.test(S)){m.push(parseInt(S[0],10)),m.push(parseInt(S[1],10)),m.push(parseFloat(S.slice(2))),v+=3,v>=7&&(v-=7);continue}if(S==="11"||S==="10"||S==="01"){m.push(parseInt(S[0],10)),m.push(parseInt(S[1],10)),v+=2,v>=7&&(v-=7);continue}if(S==="0"||S==="1"){m.push(parseInt(S,10)),v+=1,v>=7&&(v-=7);continue}}else if(v===4){if(/^[01]\d+(?:\.\d+)?$/.test(S)){m.push(parseInt(S[0],10)),m.push(parseFloat(S.slice(1))),v+=2,v>=7&&(v-=7);continue}if(S==="0"||S==="1"){m.push(parseInt(S,10)),v+=1,v>=7&&(v-=7);continue}}const y=parseFloat(S);isNaN(y)?m.push(0):m.push(y),v+=1,v>=7&&(v-=7)}else{const y=parseFloat(S);isNaN(y)?m.push(0):m.push(y)}}for(;m.length>0&&!isNaN(m[0]);){let _="",k=[];const S=a,y=l;let w,T,L,O,U,P,B,z,R,H;switch(g){case"l":a+=m.shift(),l+=m.shift(),_="L",k.push(a,l);break;case"L":a=m.shift(),l=m.shift(),k.push(a,l);break;case"m":const E=m.shift(),$=m.shift();if(a+=E,l+=$,_="M",i.length>2&&i[i.length-1].command==="z"){for(let Q=i.length-2;Q>=0;Q--)if(i[Q].command==="M"){a=i[Q].points[0]+E,l=i[Q].points[1]+$;break}}k.push(a,l),g="l";break;case"M":a=m.shift(),l=m.shift(),_="M",k.push(a,l),g="L";break;case"h":a+=m.shift(),_="L",k.push(a,l);break;case"H":a=m.shift(),_="L",k.push(a,l);break;case"v":l+=m.shift(),_="L",k.push(a,l);break;case"V":l=m.shift(),_="L",k.push(a,l);break;case"C":k.push(m.shift(),m.shift(),m.shift(),m.shift()),a=m.shift(),l=m.shift(),k.push(a,l);break;case"c":k.push(a+m.shift(),l+m.shift(),a+m.shift(),l+m.shift()),a+=m.shift(),l+=m.shift(),_="C",k.push(a,l);break;case"S":T=a,L=l,w=i[i.length-1],w.command==="C"&&(T=a+(a-w.points[2]),L=l+(l-w.points[3])),k.push(T,L,m.shift(),m.shift()),a=m.shift(),l=m.shift(),_="C",k.push(a,l);break;case"s":T=a,L=l,w=i[i.length-1],w.command==="C"&&(T=a+(a-w.points[2]),L=l+(l-w.points[3])),k.push(T,L,a+m.shift(),l+m.shift()),a+=m.shift(),l+=m.shift(),_="C",k.push(a,l);break;case"Q":k.push(m.shift(),m.shift()),a=m.shift(),l=m.shift(),k.push(a,l);break;case"q":k.push(a+m.shift(),l+m.shift()),a+=m.shift(),l+=m.shift(),_="Q",k.push(a,l);break;case"T":T=a,L=l,w=i[i.length-1],w.command==="Q"&&(T=a+(a-w.points[0]),L=l+(l-w.points[1])),a=m.shift(),l=m.shift(),_="Q",k.push(T,L,a,l);break;case"t":T=a,L=l,w=i[i.length-1],w.command==="Q"&&(T=a+(a-w.points[0]),L=l+(l-w.points[1])),a+=m.shift(),l+=m.shift(),_="Q",k.push(T,L,a,l);break;case"A":O=m.shift(),U=m.shift(),P=m.shift(),B=m.shift(),z=m.shift(),R=a,H=l,a=m.shift(),l=m.shift(),_="A",k=this.convertEndpointToCenterParameterization(R,H,a,l,B,z,O,U,P);break;case"a":O=m.shift(),U=m.shift(),P=m.shift(),B=m.shift(),z=m.shift(),R=a,H=l,a+=m.shift(),l+=m.shift(),_="A",k=this.convertEndpointToCenterParameterization(R,H,a,l,B,z,O,U,P)}i.push({command:_||g,points:k,start:{x:S,y},pathLength:this.calcLength(S,y,_||g,k)})}(g==="z"||g==="Z")&&i.push({command:"z",points:[],start:void 0,pathLength:0})}return i}static calcLength(t,n,r,o){let i,s,a,l;const c=mi;switch(r){case"L":return c.getLineLength(t,n,o[0],o[1]);case"C":return i4([t,o[0],o[2],o[4]],[n,o[1],o[3],o[5]],1);case"Q":return s4([t,o[0],o[2]],[n,o[1],o[3]],1);case"A":i=0;const d=o[4],f=o[5],h=o[4]+f;let g=Math.PI/180;if(Math.abs(d-h)<g&&(g=Math.abs(d-h)),s=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],d,0),f<0)for(l=d-g;l>h;l-=g)a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),s=a;else for(l=d+g;l<h;l+=g)a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],l,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),s=a;return a=c.getPointOnEllipticalArc(o[0],o[1],o[2],o[3],h,0),i+=c.getLineLength(s.x,s.y,a.x,a.y),i}return 0}static convertEndpointToCenterParameterization(t,n,r,o,i,s,a,l,c){const d=c*(Math.PI/180),f=Math.cos(d)*(t-r)/2+Math.sin(d)*(n-o)/2,h=-1*Math.sin(d)*(t-r)/2+Math.cos(d)*(n-o)/2,g=f*f/(a*a)+h*h/(l*l);g>1&&(a*=Math.sqrt(g),l*=Math.sqrt(g));let m=Math.sqrt((a*a*(l*l)-a*a*(h*h)-l*l*(f*f))/(a*a*(h*h)+l*l*(f*f)));i===s&&(m*=-1),isNaN(m)&&(m=0);const v=m*a*h/l,_=m*-l*f/a,k=(t+r)/2+Math.cos(d)*v-Math.sin(d)*_,S=(n+o)/2+Math.sin(d)*v+Math.cos(d)*_,y=function(B){return Math.sqrt(B[0]*B[0]+B[1]*B[1])},w=function(B,z){return(B[0]*z[0]+B[1]*z[1])/(y(B)*y(z))},T=function(B,z){return(B[0]*z[1]<B[1]*z[0]?-1:1)*Math.acos(w(B,z))},L=T([1,0],[(f-v)/a,(h-_)/l]),O=[(f-v)/a,(h-_)/l],U=[(-1*f-v)/a,(-1*h-_)/l];let P=T(O,U);return w(O,U)<=-1&&(P=Math.PI),w(O,U)>=1&&(P=0),s===0&&P>0&&(P=P-2*Math.PI),s===1&&P<0&&(P=P+2*Math.PI),[k,S,a,l,L,P,d,s]}};Fi.prototype.className="Path",Fi.prototype._attrsAffectingSize=["data"],br(Fi),he.addGetterSetter(Fi,"data");var cc=class extends ka{_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 f=[r[r.length-4],r[r.length-3],r[r.length-2],r[r.length-1],n[s-2],n[s-1]],h=Fi.calcLength(r[r.length-4],r[r.length-3],"C",f),g=Fi.getPointOnQuadraticBezier(Math.min(1,1-i/h),f[0],f[1],f[2],f[3],f[4],f[5]);a=n[s-2]-g.x,l=n[s-1]-g.y}else a=n[s-2]-n[s-4],l=n[s-1]-n[s-3];const c=(Math.atan2(l,a)+t)%t,d=this.pointerWidth();this.pointerAtEnding()&&(e.save(),e.beginPath(),e.translate(n[s-2],n[s-1]),e.rotate(c),e.moveTo(0,0),e.lineTo(-i,d/2),e.lineTo(-i,-d/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,d/2),e.lineTo(-i,-d/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}}};cc.prototype.className="Arrow",br(cc),he.addGetterSetter(cc,"pointerLength",10,bt()),he.addGetterSetter(cc,"pointerWidth",10,bt()),he.addGetterSetter(cc,"pointerAtBeginning",!1),he.addGetterSetter(cc,"pointerAtEnding",!0);var ku=class extends vt{_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)}};ku.prototype._centroid=!0,ku.prototype.className="Circle",ku.prototype._attrsAffectingSize=["radius"],br(ku),he.addGetterSetter(ku,"radius",0,bt());var pl=class extends vt{_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)}};pl.prototype.className="Ellipse",pl.prototype._centroid=!0,pl.prototype._attrsAffectingSize=["radiusX","radiusY"],br(pl),he.addComponentsGetterSetter(pl,"radius",["x","y"]),he.addGetterSetter(pl,"radiusX",0,bt()),he.addGetterSetter(pl,"radiusY",0,bt());var is=class cI extends vt{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?Re.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?Re.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=Re.createImageElement();o.onload=function(){n(new cI({image:o}))},o.onerror=r,o.crossOrigin="Anonymous",o.src=t}};is.prototype.className="Image",is.prototype._attrsAffectingSize=["image"],br(is),he.addGetterSetter(is,"cornerRadius",0,Hp(4)),he.addGetterSetter(is,"image"),he.addComponentsGetterSetter(is,"crop",["x","y","width","height"]),he.addGetterSetter(is,"cropX",0,bt()),he.addGetterSetter(is,"cropY",0,bt()),he.addGetterSetter(is,"cropWidth",0,bt()),he.addGetterSetter(is,"cropHeight",0,bt());var l4=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width","height","pointerDirection","pointerWidth","pointerHeight"],NO="Change.konva",BO="none",B0="up",z0="right",V0="down",j0="left",zO=l4.length,U0=class extends wu{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<zO;n++)e.on(l4[n]+NO,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 z0:s=n+i,a=r/2;break;case V0:s=n/2,a=r+l;break;case j0:s=-1*i,a=r/2}t.setAttrs({x:-1*s,y:-1*a,width:n,height:r}),e.setAttrs({x:-1*s,y:-1*a})}}};U0.prototype.className="Label",br(U0);var uc=class extends vt{_sceneFunc(e){const t=this.width(),n=this.height(),r=this.pointerDirection(),o=this.pointerWidth(),i=this.pointerHeight(),s=this.cornerRadius();let a=0,l=0,c=0,d=0;typeof s=="number"?a=l=c=d=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),d=Math.min(s[2]||0,t/2,n/2),c=Math.min(s[3]||0,t/2,n/2)),e.beginPath(),e.moveTo(a,0),r===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===z0&&(e.lineTo(t,(n-i)/2),e.lineTo(t+o,n/2),e.lineTo(t,(n+i)/2)),e.lineTo(t,n-d),e.arc(t-d,n-d,d,0,Math.PI/2,!1),r===V0&&(e.lineTo((t+o)/2,n),e.lineTo(t/2,n+i),e.lineTo((t-o)/2,n)),e.lineTo(c,n),e.arc(c,n-c,c,Math.PI/2,Math.PI,!1),r===j0&&(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===V0?s+=r:o===j0?(e-=n*1.5,i+=n):o===z0&&(i+=n*1.5),{x:e,y:t,width:i,height:s}}};uc.prototype.className="Tag",br(uc),he.addGetterSetter(uc,"pointerDirection",BO),he.addGetterSetter(uc,"pointerWidth",0,bt()),he.addGetterSetter(uc,"pointerHeight",0,bt()),he.addGetterSetter(uc,"cornerRadius",0,Hp(4));var xf=class extends vt{_sceneFunc(e){const t=this.cornerRadius(),n=this.width(),r=this.height();e.beginPath(),t?Re.drawRoundedRectPath(e,n,r,t):e.rect(0,0,n,r),e.closePath(),e.fillStrokeShape(this)}};xf.prototype.className="Rect",br(xf),he.addGetterSetter(xf,"cornerRadius",0,Hp(4));var ml=class extends vt{_sceneFunc(e){const t=this._getPoints(),n=this.radius(),r=this.sides(),o=this.cornerRadius();if(e.beginPath(),o)Re.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)}};ml.prototype.className="RegularPolygon",ml.prototype._centroid=!0,ml.prototype._attrsAffectingSize=["radius"],br(ml),he.addGetterSetter(ml,"radius",0,bt()),he.addGetterSetter(ml,"sides",0,bt()),he.addGetterSetter(ml,"cornerRadius",0,Hp(4));var c4=Math.PI*2,dc=class extends vt{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.innerRadius(),0,c4,!1),e.moveTo(this.outerRadius(),0),e.arc(0,0,this.outerRadius(),c4,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)}};dc.prototype.className="Ring",dc.prototype._centroid=!0,dc.prototype._attrsAffectingSize=["innerRadius","outerRadius"],br(dc),he.addGetterSetter(dc,"innerRadius",0,bt()),he.addGetterSetter(dc,"outerRadius",0,bt());var Fs=class extends vt{constructor(e){super(e),this._updated=!0,this.anim=new Cu(()=>{const t=this._updated;return this._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())})}_sceneFunc(e){const t=this.animation(),n=this.frameIndex(),r=n*4,o=this.animations()[t],i=this.frameOffsets(),s=o[r+0],a=o[r+1],l=o[r+2],c=o[r+3],d=this.image();if((this.hasFill()||this.hasStroke())&&(e.beginPath(),e.rect(0,0,l,c),e.closePath(),e.fillStrokeShape(this)),d)if(i){const f=i[t],h=n*2;e.drawImage(d,s,a,l,c,f[h+0],f[h+1],l,c)}else e.drawImage(d,s,a,l,c,0,0,l,c)}_hitFunc(e){const t=this.animation(),n=this.frameIndex(),r=n*4,o=this.animations()[t],i=this.frameOffsets(),s=o[r+2],a=o[r+3];if(e.beginPath(),i){const l=i[t],c=n*2;e.rect(l[c+0],l[c+1],s,a)}else e.rect(0,0,s,a);e.closePath(),e.fillShape(this)}_useBufferCanvas(){return super._useBufferCanvas(!0)}_setInterval(){const e=this;this.interval=setInterval(function(){e._updateIndex()},1e3/this.frameRate())}start(){if(this.isRunning())return;const e=this.getLayer();this.anim.setLayers(e),this._setInterval(),this.anim.start()}stop(){this.anim.stop(),clearInterval(this.interval)}isRunning(){return this.anim.isRunning()}_updateIndex(){const e=this.frameIndex(),t=this.animation();e<this.animations()[t].length/4-1?this.frameIndex(e+1):this.frameIndex(0)}};Fs.prototype.className="Sprite",br(Fs),he.addGetterSetter(Fs,"animation"),he.addGetterSetter(Fs,"animations"),he.addGetterSetter(Fs,"frameOffsets"),he.addGetterSetter(Fs,"image"),he.addGetterSetter(Fs,"frameIndex",0,bt()),he.addGetterSetter(Fs,"frameRate",17,bt()),he.backCompat(Fs,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"});var gl=class extends vt{_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)}};gl.prototype.className="Star",gl.prototype._centroid=!0,gl.prototype._attrsAffectingSize=["innerRadius","outerRadius"],br(gl),he.addGetterSetter(gl,"numPoints",5,bt()),he.addGetterSetter(gl,"innerRadius",0,bt()),he.addGetterSetter(gl,"outerRadius",0,bt());function vl(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 Su="auto",VO="center",u4="inherit",Ef="justify",jO="Change.konva",d4="2d",f4="-",h4="left",UO="text",HO="Text",$O="top",GO="bottom",p4="middle",m4="normal",WO="px ",Qp=" ",KO="right",g4="rtl",qO="word",YO="char",v4="none",H0="…",y4=["direction","fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],XO=y4.length,Tf=null;function ZO(){if(Tf!==null)return Tf;Tf=!1;try{const e=document.createElement("canvas");e.width=10,e.height=10;const t=e.getContext(d4);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){Tf=!0;break}}}catch{}return Tf}function QO(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 Jp;function $0(){return Jp||(Jp=Re.createCanvasElement().getContext(d4),Jp)}function JO(e){e.fillText(this._partialText,this._partialTextX,this._partialTextY)}function eF(e){e.setAttr("miterLimit",2),e.strokeText(this._partialText,this._partialTextX,this._partialTextY)}function tF(e){return e=e||{},!e.fillLinearGradientColorStops&&!e.fillRadialGradientColorStops&&!e.fillPatternImage&&(e.fill=e.fill||"black"),e}var or=class extends vt{constructor(e){super(tF(e)),this._partialTextX=0,this._partialTextY=0;for(let t=0;t<XO;t++)this.on(y4[t]+jO,this._setTextData);this._setTextData()}_sceneFunc(e){var t,n;const r=this.textArr,o=r.length;if(!this.text())return;let i=this.padding(),s=this.fontSize(),a=this.lineHeight()*s,l=this.verticalAlign(),c=this.direction(),d=0,f=this.align(),h=this.getWidth(),g=this.letterSpacing(),m=this.charRenderFunc(),v=this.fill(),_=this.textDecoration(),k=this.underlineOffset(),S=_.indexOf("underline")!==-1,y=_.indexOf("line-through")!==-1,w;c=c===u4?e.direction:c;let T=a/2,L=p4;if(!St.legacyTextRendering){const O=this.measureSize("M");L="alphabetic",T=(((t=O.fontBoundingBoxAscent)!==null&&t!==void 0?t:O.actualBoundingBoxAscent)-((n=O.fontBoundingBoxDescent)!==null&&n!==void 0?n:O.actualBoundingBoxDescent))/2+a/2}for(c===g4&&e.setAttr("direction",c),e.setAttr("font",this._getContextFont()),e.setAttr("textBaseline",L),e.setAttr("textAlign",h4),l===p4?d=(this.getHeight()-o*a-i*2)/2:l===GO&&(d=this.getHeight()-o*a-i*2),e.translate(i,d+i),w=0;w<o;w++){let O=0,U=0;const P=r[w],B=P.text,z=P.width,R=P.lastInParagraph;if(e.save(),f===KO?O+=h-z-i*2:f===VO&&(O+=(h-z-i*2)/2),S){e.save(),e.beginPath();const E=k??(St.legacyTextRendering?Math.round(s/2):Math.round(s/4)),$=O,Q=T+U+E;e.moveTo($,Q);const ie=f===Ef&&!R?h-i*2:z;e.lineTo($+Math.round(ie),Q),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||v,e.stroke(),e.restore()}const H=O;if(c!==g4&&(g!==0||f===Ef||m)){const E=B.split(" ").length-1,$=vl(B);for(let Q=0;Q<$.length;Q++){const ie=$[Q];if(ie===" "&&!R&&f===Ef&&(O+=(h-i*2-z)/E),this._partialTextX=O,this._partialTextY=T+U,this._partialText=ie,m){e.save();const ee=r.slice(0,w).reduce((ne,Ie)=>ne+vl(Ie.text).length,0);m({char:ie,index:Q+ee,x:O,y:T+U,lineIndex:w,column:Q,isLastInLine:R,width:this.measureSize(ie).width,context:e})}e.fillStrokeShape(this),m&&e.restore(),O+=this.measureSize(ie).width+g}}else g!==0&&e.setAttr("letterSpacing",`${g}px`),this._partialTextX=O,this._partialTextY=T+U,this._partialText=B,e.fillStrokeShape(this);if(y){e.save(),e.beginPath();const E=St.legacyTextRendering?0:-Math.round(s/4),$=H;e.moveTo($,T+U+E);const Q=f===Ef&&!R?h-i*2:z;e.lineTo($+Math.round(Q),T+U+E),e.lineWidth=s/15,e.strokeStyle=this._getLinearGradient()||v,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=Re._isString(e)?e:e==null?"":e+"";return this._setAttr(UO,t),this}getWidth(){return this.attrs.width===Su||this.attrs.width===void 0?this.getTextWidth()+this.padding()*2:this.attrs.width}getHeight(){return this.attrs.height===Su||this.attrs.height===void 0?this.fontSize()*this.textArr.length*this.lineHeight()+this.padding()*2:this.attrs.height}getTextWidth(){return this.textWidth}getTextHeight(){return Re.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}measureSize(e){var t,n,r,o,i,s,a,l,c,d,f;let h=$0(),g=this.fontSize(),m;h.save(),h.font=this._getContextFont(),m=h.measureText(e),h.restore();const v=g/100;return{actualBoundingBoxAscent:(t=m.actualBoundingBoxAscent)!==null&&t!==void 0?t:71.58203125*v,actualBoundingBoxDescent:(n=m.actualBoundingBoxDescent)!==null&&n!==void 0?n:0,actualBoundingBoxLeft:(r=m.actualBoundingBoxLeft)!==null&&r!==void 0?r:-7.421875*v,actualBoundingBoxRight:(o=m.actualBoundingBoxRight)!==null&&o!==void 0?o:75.732421875*v,alphabeticBaseline:(i=m.alphabeticBaseline)!==null&&i!==void 0?i:0,emHeightAscent:(s=m.emHeightAscent)!==null&&s!==void 0?s:100*v,emHeightDescent:(a=m.emHeightDescent)!==null&&a!==void 0?a:-20*v,fontBoundingBoxAscent:(l=m.fontBoundingBoxAscent)!==null&&l!==void 0?l:91*v,fontBoundingBoxDescent:(c=m.fontBoundingBoxDescent)!==null&&c!==void 0?c:21*v,hangingBaseline:(d=m.hangingBaseline)!==null&&d!==void 0?d:72.80000305175781*v,ideographicBaseline:(f=m.ideographicBaseline)!==null&&f!==void 0?f:-21*v,width:m.width,height:g}}_getContextFont(){return this.fontStyle()+Qp+this.fontVariant()+Qp+(this.fontSize()+WO)+QO(this.fontFamily())}_addTextLine(e){this.align()===Ef&&(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 $0().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!==Su&&o!==void 0,a=i!==Su&&i!==void 0,l=this.padding(),c=o-l*2,d=i-l*2,f=0,h=this.wrap(),g=h!==YO&&h!==v4,m=this.ellipsis();this.textArr=[],$0().font=this._getContextFont();const v=m?this._getTextWidth(H0):0;for(let _=0,k=e.length;_<k;++_){let S=e[_],y=this._getTextWidth(S);if(s&&y>c)for(;S.length>0;){let w=0,T=vl(S).length,L="",O=0;for(;w<T;){const U=w+T>>>1,P=vl(S).slice(0,U+1).join(""),B=this._getTextWidth(P);(m&&a&&f+r>d?B+v:B)<=c?(w=U+1,L=P,O=B):T=U}if(L){if(g){const U=vl(S),P=vl(L),B=U[P.length],z=B===Qp||B===f4;let R;if(z&&O<=c)R=P.length;else{const H=P.lastIndexOf(Qp),E=P.lastIndexOf(f4);R=Math.max(H,E)+1}R>0&&(w=R,L=U.slice(0,w).join(""),O=this._getTextWidth(L))}if(L=L.trimRight(),this._addTextLine(L),n=Math.max(n,O),f+=r,this._shouldHandleEllipsis(f)){this._tryToAddEllipsisToLastLine();break}if(S=vl(S).slice(w).join("").trimLeft(),S.length>0&&(y=this._getTextWidth(S),y<=c)){this._addTextLine(S),f+=r,n=Math.max(n,y);break}}else break}else this._addTextLine(S),f+=r,n=Math.max(n,y),this._shouldHandleEllipsis(f)&&_<k-1&&this._tryToAddEllipsisToLastLine();if(this.textArr[this.textArr.length-1]&&(this.textArr[this.textArr.length-1].lastInParagraph=!0),a&&f+r>d)break}this.textHeight=t,this.textWidth=n}_shouldHandleEllipsis(e){const t=+this.fontSize(),n=this.lineHeight()*t,r=this.attrs.height,o=r!==Su&&r!==void 0,i=r-this.padding()*2;return this.wrap()===v4||o&&e+n>i}_tryToAddEllipsisToLastLine(){const e=this.attrs.width,t=e!==Su&&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+H0)<n||(o.text=o.text.slice(0,o.text.length-3))),this.textArr.splice(this.textArr.length-1,1),this._addTextLine(o.text+H0))}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&&ZO()?!0:super._useBufferCanvas()}};or.prototype._fillFunc=JO,or.prototype._strokeFunc=eF,or.prototype.className=HO,or.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight","letterSpacing"],br(or),he.overWriteSetter(or,"width",A0()),he.overWriteSetter(or,"height",A0()),he.addGetterSetter(or,"direction",u4),he.addGetterSetter(or,"fontFamily","Arial"),he.addGetterSetter(or,"fontSize",12,bt()),he.addGetterSetter(or,"fontStyle",m4),he.addGetterSetter(or,"fontVariant",m4),he.addGetterSetter(or,"padding",0,bt()),he.addGetterSetter(or,"align",h4),he.addGetterSetter(or,"verticalAlign",$O),he.addGetterSetter(or,"lineHeight",1,bt()),he.addGetterSetter(or,"wrap",qO),he.addGetterSetter(or,"ellipsis",!1,os()),he.addGetterSetter(or,"letterSpacing",0,bt()),he.addGetterSetter(or,"text","",sc()),he.addGetterSetter(or,"textDecoration",""),he.addGetterSetter(or,"underlineOffset",void 0,bt()),he.addGetterSetter(or,"charRenderFunc",void 0);var nF="",b4="normal";function w4(e){e.fillText(this.partialText,0,0)}function C4(e){e.strokeText(this.partialText,0,0)}var no=class extends vt{constructor(e){super(e),this.dummyCanvas=Re.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 Fi.getPathLength(this.dataArray)}_getPointAtLength(e){return!this.attrs.data||e>this.pathLength?null:Fi.getPointAtLengthOfDataArray(e,this.dataArray)}_readDataAttribute(){this.dataArray=Fi.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 Re.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}setText(e){return or.prototype.setText.call(this,e)}_getContextFont(){return or.prototype._getContextFont.call(this)}_getTextSize(e){const t=this.dummyCanvas.getContext("2d");t.save(),t.font=this._getContextFont();const n=t.measureText(e);return t.restore(),{width:n.width,height:parseInt(`${this.fontSize()}`,10)}}_setTextData(){const e=vl(this.text()),t=[];let n=0;for(let h=0;h<e.length;h++)t.push({char:e[h],width:this._getTextSize(e[h]).width}),n+=t[h].width;const{width:r,height:o}=this._getTextSize(this.attrs.text);if(this.textWidth=n,this.textHeight=o,this.glyphInfo=[],!this.attrs.data)return null;const i=this.letterSpacing(),s=this.align(),a=this.kerningFunc(),l=Math.max(0,n-r),c=Math.max(this.textWidth+((this.attrs.text||"").length-1)*i,0);let d=0;s==="center"&&(d=Math.max(0,this.pathLength/2-c/2)),s==="right"&&(d=Math.max(0,this.pathLength-c));let f=d;for(let h=0;h<t.length;h++){const g=this._getPointAtLength(f);if(!g)return;const m=t[h].char;let v=t[h].width+i;if(m===" "&&s==="justify"){const L=this.text().split(" ").length-1;v+=(this.pathLength-c)/L}const _=f+v,k=this._getPointAtLength(_>this.pathLength&&_-this.pathLength<=l?this.pathLength:_);if(!k)return;const S=Fi.getLineLength(g.x,g.y,k.x,k.y);let y=0;if(a)try{y=a(t[h-1].char,m)*this.fontSize()}catch{y=0}g.x+=y,k.x+=y,this.textWidth+=y;const w=Fi.getPointOnLine(y+S/2,g.x,g.y,k.x,k.y),T=Math.atan2(k.y-g.y,k.x-g.x);this.glyphInfo.push({transposeX:w.x,transposeY:w.y,text:e[h],rotation:T,p0:g,p1:k,width:S}),f+=v}}getSelfRect(){if(!this.glyphInfo.length)return{x:0,y:0,width:0,height:0};const e=[];this.glyphInfo.forEach(function(l){e.push(l.p0.x),e.push(l.p0.y),e.push(l.p1.x),e.push(l.p1.y)});let t=e[0]||0,n=e[0]||0,r=e[1]||0,o=e[1]||0,i,s;for(let l=0;l<e.length/2;l++)i=e[l*2],s=e[l*2+1],t=Math.min(t,i),n=Math.max(n,i),r=Math.min(r,s),o=Math.max(o,s);const a=this.fontSize();return{x:t-a/2,y:r-a/2,width:n-t+a,height:o-r+a}}destroy(){return Re.releaseCanvas(this.dummyCanvas),super.destroy()}};no.prototype._fillFunc=w4,no.prototype._strokeFunc=C4,no.prototype._fillFuncHit=w4,no.prototype._strokeFuncHit=C4,no.prototype.className="TextPath",no.prototype._attrsAffectingSize=["text","fontSize","data"],br(no),he.addGetterSetter(no,"data"),he.addGetterSetter(no,"fontFamily","Arial"),he.addGetterSetter(no,"fontSize",12,bt()),he.addGetterSetter(no,"fontStyle",b4),he.addGetterSetter(no,"align","left"),he.addGetterSetter(no,"letterSpacing",0,bt()),he.addGetterSetter(no,"textBaseline","middle"),he.addGetterSetter(no,"fontVariant",b4),he.addGetterSetter(no,"text",nF),he.addGetterSetter(no,"textDecoration",""),he.addGetterSetter(no,"kerningFunc",void 0);var k4="tr-konva",rF=["resizeEnabledChange","rotateAnchorOffsetChange","rotateAnchorAngleChange","rotateEnabledChange","enabledAnchorsChange","anchorSizeChange","borderEnabledChange","borderStrokeChange","borderStrokeWidthChange","borderDashChange","anchorStrokeChange","anchorStrokeWidthChange","anchorFillChange","anchorCornerRadiusChange","ignoreStrokeChange","anchorStyleFuncChange"].map(e=>e+`.${k4}`).join(" "),S4="nodesRect",oF=["widthChange","heightChange","scaleXChange","scaleYChange","skewXChange","skewYChange","rotationChange","offsetXChange","offsetYChange","transformsEnabledChange","strokeWidthChange","draggableChange"],iF={"top-left":-45,"top-center":0,"top-right":45,"middle-right":-90,"middle-left":90,"bottom-left":-135,"bottom-center":180,"bottom-right":135},sF="ontouchstart"in St._global;function aF(e,t,n){if(e==="rotater")return n;t+=Re.degToRad(iF[e]||0);const r=(Re.radToDeg(t)%360+360)%360;return Re._inRange(r,337.5,360)||Re._inRange(r,0,22.5)?"ns-resize":Re._inRange(r,22.5,67.5)?"nesw-resize":Re._inRange(r,67.5,112.5)?"ew-resize":Re._inRange(r,112.5,157.5)?"nwse-resize":Re._inRange(r,157.5,202.5)?"ns-resize":Re._inRange(r,202.5,247.5)?"nesw-resize":Re._inRange(r,247.5,292.5)?"ew-resize":Re._inRange(r,292.5,337.5)?"nwse-resize":(Re.error("Transformer has unknown angle for cursor detection: "+r),"pointer")}var em=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"];function lF(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 _4(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 cF(e,t){return _4(e,t,lF(e))}function uF(e,t,n){let r=t;for(let o=0;o<e.length;o++){const i=St.getAngle(e[o]),s=Math.abs(i-t)%(Math.PI*2);Math.min(s,Math.PI*2-s)<n&&(r=i)}return r}var G0=0,Tn=class extends wu{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(rF,this.update),this.getNode()&&this.update()}attachTo(e){return this.setNode(e),this}setNode(e){return Re.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 k4+this._id}setNodes(e=[]){this._nodes&&this._nodes.length&&this.detach();const t=e.filter(n=>n.isAncestorOf(this)?(Re.error("Konva.Transformer cannot be an a child of the node you are trying to attach"),!1):!0);return this._nodes=e=t,e.length===1&&this.useSingleNodeRotation()?this.rotation(e[0].getAbsoluteRotation()):this.rotation(0),this._nodes.forEach(n=>{const r=()=>{this.nodes().length===1&&this.useSingleNodeRotation()&&this.rotation(this.nodes()[0].getAbsoluteRotation()),this._resetTransformCache(),!this._transforming&&!this.isDragging()&&this.update()};if(n._attrsAffectingSize.length){const o=n._attrsAffectingSize.map(i=>i+"Change."+this._getEventNamespace()).join(" ");n.on(o,r)}n.on(oF.map(o=>o+`.${this._getEventNamespace()}`).join(" "),r),n.on(`absoluteTransformChange.${this._getEventNamespace()}`,r),this._proxyDrag(n)}),this._resetTransformCache(),this.findOne(".top-left")&&this.update(),this}_proxyDrag(e){let t;e.on(`dragstart.${this._getEventNamespace()}`,n=>{t=e.getAbsolutePosition(),!this.isDragging()&&e!==this.findOne(".back")&&this.startDrag(n,!1)}),e.on(`dragmove.${this._getEventNamespace()}`,n=>{if(!t)return;const r=e.getAbsolutePosition(),o=r.x-t.x,i=r.y-t.y;this.nodes().forEach(s=>{if(s===e||s.isDragging())return;const a=s.getAbsolutePosition();s.setAbsolutePosition({x:a.x+o,y:a.y+i}),s.startDrag(n)}),t=null})}getNodes(){return this._nodes||[]}getActiveAnchor(){return this._movingAnchorName}detach(){this._nodes&&this._nodes.forEach(e=>{e.off("."+this._getEventNamespace())}),this._nodes=[],this._resetTransformCache()}_resetTransformCache(){this._clearCache(S4),this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform")}_getNodeRect(){return this._getCache(S4,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=(St.getAngle(e.getAbsoluteRotation())+Math.PI*2)%(Math.PI*2);return _4({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},-St.getAngle(t),{x:0,y:0})}__getNodeRect(){if(!this.getNode())return{x:-1e8,y:-1e8,width:0,height:0,rotation:0};const e=[];this.nodes().map(a=>{const l=a.getClientRect({skipTransform:!0,skipShadow:!0,skipStroke:this.ignoreStroke()}),c=[{x:l.x,y:l.y},{x:l.x+l.width,y:l.y},{x:l.x+l.width,y:l.y+l.height},{x:l.x,y:l.y+l.height}],d=a.getAbsoluteTransform();c.forEach(function(f){const h=d.point(f);e.push(h)})});const t=new rs;t.rotate(-St.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:St.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(),em.forEach(e=>{this._createAnchor(e)}),this._createAnchor("rotater"),this._elementsCreated=!0}_createAnchor(e){const t=new xf({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:e+" _anchor",dragDistance:0,draggable:!0,hitStrokeWidth:sF?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=aF(e,St.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 vt({name:"back",width:0,height:0,sceneFunc(t,n){const r=n.getParent(),o=r.padding(),i=n.width(),s=n.height();if(t.beginPath(),t.rect(-o,-o,i+o*2,s+o*2),r.rotateEnabled()&&r.rotateLineVisible()){const a=r.rotateAnchorAngle(),l=r.rotateAnchorOffset(),c=Re.degToRad(a),d=Math.sin(c),f=-Math.cos(c),h=i/2,g=s/2;let m=1/0;f<0?m=Math.min(m,-g/f):f>0&&(m=Math.min(m,(s-g)/f)),d<0?m=Math.min(m,-h/d):d>0&&(m=Math.min(m,(i-h)/d));const v=h+d*m,_=g+f*m,k=Re._sign(s),S=v+d*l*k,y=_+f*l*k;t.moveTo(v,_),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},G0++,this._fire("transformstart",{evt:e.evt,target:this.getNode()}),this._nodes.forEach(a=>{a._fire("transformstart",{evt:e.evt,target:a})})}_handleMouseMove(e){let t,n,r;const o=this.findOne("."+this._movingAnchorName),i=o.getStage();i.setPointersPositions(e);const s=i.getPointerPosition();let a={x:s.x-this._anchorDragOffset.x,y:s.y-this._anchorDragOffset.y};const l=o.getAbsolutePosition();this.anchorDragBoundFunc()&&(a=this.anchorDragBoundFunc()(l,a,e)),o.setAbsolutePosition(a);const c=o.getAbsolutePosition();if(l.x===c.x&&l.y===c.y)return;if(this._movingAnchorName==="rotater"){const k=this._getNodeRect();t=o.x()-k.width/2,n=-o.y()+k.height/2;const S=St.getAngle(this.rotateAnchorAngle());let y=Math.atan2(-n,t)+Math.PI/2-S;k.height<0&&(y-=Math.PI);const w=St.getAngle(this.rotation())+y,T=St.getAngle(this.rotationSnapTolerance()),L=cF(k,uF(this.rotationSnaps(),w,T)-k.rotation);this._fitNodesInto(L,e);return}const d=this.shiftBehavior();let f;d==="inverted"?f=this.keepRatio()&&!e.shiftKey:d==="none"?f=this.keepRatio():f=this.keepRatio()||e.shiftKey;let h=this.centeredScaling()||e.altKey;if(this._movingAnchorName==="top-left"){if(f){const k=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(k.x-o.x(),2)+Math.pow(k.y-o.y(),2));const S=this.findOne(".top-left").x()>k.x?-1:1,y=this.findOne(".top-left").y()>k.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".top-left").x(k.x-t),this.findOne(".top-left").y(k.y-n)}}else if(this._movingAnchorName==="top-center")this.findOne(".top-left").y(o.y());else if(this._movingAnchorName==="top-right"){if(f){const k=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()-k.x,2)+Math.pow(k.y-o.y(),2));const S=this.findOne(".top-right").x()<k.x?-1:1,y=this.findOne(".top-right").y()>k.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".top-right").x(k.x+t),this.findOne(".top-right").y(k.y-n)}var g=o.position();this.findOne(".top-left").y(g.y),this.findOne(".bottom-right").x(g.x)}else if(this._movingAnchorName==="middle-left")this.findOne(".top-left").x(o.x());else if(this._movingAnchorName==="middle-right")this.findOne(".bottom-right").x(o.x());else if(this._movingAnchorName==="bottom-left"){if(f){const k=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(k.x-o.x(),2)+Math.pow(o.y()-k.y,2));const S=k.x<o.x()?-1:1,y=o.y()<k.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,o.x(k.x-t),o.y(k.y+n)}g=o.position(),this.findOne(".top-left").x(g.x),this.findOne(".bottom-right").y(g.y)}else if(this._movingAnchorName==="bottom-center")this.findOne(".bottom-right").y(o.y());else if(this._movingAnchorName==="bottom-right"){if(f){const k=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()-k.x,2)+Math.pow(o.y()-k.y,2));const S=this.findOne(".bottom-right").x()<k.x?-1:1,y=this.findOne(".bottom-right").y()<k.y?-1:1;t=r*this.cos*S,n=r*this.sin*y,this.findOne(".bottom-right").x(k.x+t),this.findOne(".bottom-right").y(k.y+n)}}else console.error(new Error("Wrong position argument of selection resizer: "+this._movingAnchorName));if(h=this.centeredScaling()||e.altKey,h){const k=this.findOne(".top-left"),S=this.findOne(".bottom-right"),y=k.x(),w=k.y(),T=this.getWidth()-S.x(),L=this.getHeight()-S.y();S.move({x:-y,y:-w}),k.move({x:T,y:L})}const m=this.findOne(".top-left").getAbsolutePosition();t=m.x,n=m.y;const v=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),_=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodesInto({x:t,y:n,width:v,height:_,rotation:St.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();G0--,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(Re._inRange(e.width,-this.padding()*2-r,r)){this.update();return}if(Re._inRange(e.height,-this.padding()*2-r,r)){this.update();return}const o=new rs;if(o.rotate(St.getAngle(this.rotation())),this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("left")>=0){const f=o.point({x:-this.padding()*2,y:0});e.x+=f.x,e.y+=f.y,e.width+=this.padding()*2,this._movingAnchorName=this._movingAnchorName.replace("left","right"),this._anchorDragOffset.x-=f.x,this._anchorDragOffset.y-=f.y}else if(this._movingAnchorName&&e.width<0&&this._movingAnchorName.indexOf("right")>=0){const f=o.point({x:this.padding()*2,y:0});this._movingAnchorName=this._movingAnchorName.replace("right","left"),this._anchorDragOffset.x-=f.x,this._anchorDragOffset.y-=f.y,e.width+=this.padding()*2}if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("top")>=0){const f=o.point({x:0,y:-this.padding()*2});e.x+=f.x,e.y+=f.y,this._movingAnchorName=this._movingAnchorName.replace("top","bottom"),this._anchorDragOffset.x-=f.x,this._anchorDragOffset.y-=f.y,e.height+=this.padding()*2}else if(this._movingAnchorName&&e.height<0&&this._movingAnchorName.indexOf("bottom")>=0){const f=o.point({x:0,y:this.padding()*2});this._movingAnchorName=this._movingAnchorName.replace("bottom","top"),this._anchorDragOffset.x-=f.x,this._anchorDragOffset.y-=f.y,e.height+=this.padding()*2}if(this.boundBoxFunc()){const f=this.boundBoxFunc()(n,e);f?e=f:Re.warn("boundBoxFunc returned falsy. You should return new bound rect from it!")}const i=1e7,s=new rs;s.translate(n.x,n.y),s.rotate(n.rotation),s.scale(n.width/i,n.height/i);const a=new rs,l=e.width/i,c=e.height/i;this.flipEnabled()===!1?(a.translate(e.x,e.y),a.rotate(e.rotation),a.translate(e.width<0?e.width:0,e.height<0?e.height:0),a.scale(Math.abs(l),Math.abs(c))):(a.translate(e.x,e.y),a.rotate(e.rotation),a.scale(l,c));const d=a.multiply(s.invert());this._nodes.forEach(f=>{var h;if(!f.getStage())return;const g=f.getParent().getAbsoluteTransform(),m=f.getTransform().copy();m.translate(f.offsetX(),f.offsetY());const v=new rs;v.multiply(g.copy().invert()).multiply(d).multiply(g).multiply(m);const _=v.decompose();f.setAttrs(_),(h=f.getLayer())===null||h===void 0||h.batchDraw()}),this.rotation(Re._getRotation(e.rotation)),this._nodes.forEach(f=>{this._fire("transform",{evt:t,target:f}),f._fire("transform",{evt:t,target:f})}),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(Re._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 c=this.rotateAnchorAngle(),d=this.rotateAnchorOffset(),f=Re.degToRad(c),h=Math.sin(f),g=-Math.cos(f),m=n/2,v=r/2;let _=1/0;g<0?_=Math.min(_,-v/g):g>0&&(_=Math.min(_,(r-v)/g)),h<0?_=Math.min(_,-m/h):h>0&&(_=Math.min(_,(n-m)/h));const k=m+h*_,S=v+g*_,y=Re._sign(r);this._batchChangeChild(".rotater",{x:k+h*d*y,y:S+g*d*y-s*g,visible:this.rotateEnabled()}),this._batchChangeChild(".back",{width:n,height:r,visible:this.borderEnabled(),stroke:this.borderStroke(),strokeWidth:this.borderStrokeWidth(),dash:this.borderDash(),draggable:this.nodes().some(T=>T.draggable()),x:0,y:0});const w=this.anchorStyleFunc();w&&l.forEach(T=>{w(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=""),wu.prototype.destroy.call(this),this.detach(),this._removeEvents(),this}add(...e){return this._elementsCreated?(Re.error("You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead."),this):super.add(...e)}toObject(){return _t.prototype.toObject.call(this)}clone(e){return _t.prototype.clone.call(this,e)}getClientRect(){return this.nodes().length>0?super.getClientRect():{x:0,y:0,width:0,height:0}}};Tn.isTransforming=()=>G0>0;function dF(e){return e instanceof Array||Re.warn("enabledAnchors value should be an array"),e instanceof Array&&e.forEach(function(t){em.indexOf(t)===-1&&Re.warn("Unknown anchor name: "+t+". Available names are: "+em.join(", "))}),e||[]}Tn.prototype.className="Transformer",br(Tn),he.addGetterSetter(Tn,"enabledAnchors",em,dF),he.addGetterSetter(Tn,"flipEnabled",!0,os()),he.addGetterSetter(Tn,"resizeEnabled",!0),he.addGetterSetter(Tn,"anchorSize",10,bt()),he.addGetterSetter(Tn,"rotateEnabled",!0),he.addGetterSetter(Tn,"rotateLineVisible",!0),he.addGetterSetter(Tn,"rotationSnaps",[]),he.addGetterSetter(Tn,"rotateAnchorOffset",50,bt()),he.addGetterSetter(Tn,"rotateAnchorAngle",0,bt()),he.addGetterSetter(Tn,"rotateAnchorCursor","crosshair"),he.addGetterSetter(Tn,"rotationSnapTolerance",5,bt()),he.addGetterSetter(Tn,"borderEnabled",!0),he.addGetterSetter(Tn,"anchorStroke","rgb(0, 161, 255)"),he.addGetterSetter(Tn,"anchorStrokeWidth",1,bt()),he.addGetterSetter(Tn,"anchorFill","white"),he.addGetterSetter(Tn,"anchorCornerRadius",0,bt()),he.addGetterSetter(Tn,"borderStroke","rgb(0, 161, 255)"),he.addGetterSetter(Tn,"borderStrokeWidth",1,bt()),he.addGetterSetter(Tn,"borderDash"),he.addGetterSetter(Tn,"keepRatio",!0),he.addGetterSetter(Tn,"shiftBehavior","default"),he.addGetterSetter(Tn,"centeredScaling",!1),he.addGetterSetter(Tn,"ignoreStroke",!1),he.addGetterSetter(Tn,"padding",0,bt()),he.addGetterSetter(Tn,"nodes"),he.addGetterSetter(Tn,"node"),he.addGetterSetter(Tn,"boundBoxFunc"),he.addGetterSetter(Tn,"anchorDragBoundFunc"),he.addGetterSetter(Tn,"anchorStyleFunc"),he.addGetterSetter(Tn,"shouldOverdrawWholeArea",!1),he.addGetterSetter(Tn,"useSingleNodeRotation",!0),he.backCompat(Tn,{lineEnabled:"borderEnabled",rotateHandlerOffset:"rotateAnchorOffset",enabledHandlers:"enabledAnchors"});var Sa=class extends vt{_sceneFunc(e){e.beginPath(),e.arc(0,0,this.radius(),0,St.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)}};Sa.prototype.className="Wedge",Sa.prototype._centroid=!0,Sa.prototype._attrsAffectingSize=["radius"],br(Sa),he.addGetterSetter(Sa,"radius",0,bt()),he.addGetterSetter(Sa,"angle",0,bt()),he.addGetterSetter(Sa,"clockwise",!1),he.backCompat(Sa,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"});function A4(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var fF=[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],hF=[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 pF(e,t){const n=e.data,r=e.width,o=e.height;let i,s,a,l,c,d,f,h,g,m,v,_,k,S,y,w,T,L,O,U;const P=t+t+1,B=r-1,z=o-1,R=t+1,H=R*(R+1)/2,E=new A4,$=fF[t],Q=hF[t];let ie=null,ee=E,ne=null,Ie=null;for(let pe=1;pe<P;pe++)ee=ee.next=new A4,pe===R&&(ie=ee);ee.next=E,a=s=0;for(let pe=0;pe<o;pe++){_=k=S=y=l=c=d=f=0,h=R*(w=n[s]),g=R*(T=n[s+1]),m=R*(L=n[s+2]),v=R*(O=n[s+3]),l+=H*w,c+=H*T,d+=H*L,f+=H*O,ee=E;for(let ye=0;ye<R;ye++)ee.r=w,ee.g=T,ee.b=L,ee.a=O,ee=ee.next;for(let ye=1;ye<R;ye++)i=s+((B<ye?B:ye)<<2),l+=(ee.r=w=n[i])*(U=R-ye),c+=(ee.g=T=n[i+1])*U,d+=(ee.b=L=n[i+2])*U,f+=(ee.a=O=n[i+3])*U,_+=w,k+=T,S+=L,y+=O,ee=ee.next;ne=E,Ie=ie;for(let ye=0;ye<r;ye++)n[s+3]=O=f*$>>Q,O!==0?(O=255/O,n[s]=(l*$>>Q)*O,n[s+1]=(c*$>>Q)*O,n[s+2]=(d*$>>Q)*O):n[s]=n[s+1]=n[s+2]=0,l-=h,c-=g,d-=m,f-=v,h-=ne.r,g-=ne.g,m-=ne.b,v-=ne.a,i=a+((i=ye+t+1)<B?i:B)<<2,_+=ne.r=n[i],k+=ne.g=n[i+1],S+=ne.b=n[i+2],y+=ne.a=n[i+3],l+=_,c+=k,d+=S,f+=y,ne=ne.next,h+=w=Ie.r,g+=T=Ie.g,m+=L=Ie.b,v+=O=Ie.a,_-=w,k-=T,S-=L,y-=O,Ie=Ie.next,s+=4;a+=r}for(let pe=0;pe<r;pe++){k=S=y=_=c=d=f=l=0,s=pe<<2,h=R*(w=n[s]),g=R*(T=n[s+1]),m=R*(L=n[s+2]),v=R*(O=n[s+3]),l+=H*w,c+=H*T,d+=H*L,f+=H*O,ee=E;for(let ve=0;ve<R;ve++)ee.r=w,ee.g=T,ee.b=L,ee.a=O,ee=ee.next;let ye=r;for(let ve=1;ve<=t;ve++)s=ye+pe<<2,l+=(ee.r=w=n[s])*(U=R-ve),c+=(ee.g=T=n[s+1])*U,d+=(ee.b=L=n[s+2])*U,f+=(ee.a=O=n[s+3])*U,_+=w,k+=T,S+=L,y+=O,ee=ee.next,ve<z&&(ye+=r);s=pe,ne=E,Ie=ie;for(let ve=0;ve<o;ve++)i=s<<2,n[i+3]=O=f*$>>Q,O>0?(O=255/O,n[i]=(l*$>>Q)*O,n[i+1]=(c*$>>Q)*O,n[i+2]=(d*$>>Q)*O):n[i]=n[i+1]=n[i+2]=0,l-=h,c-=g,d-=m,f-=v,h-=ne.r,g-=ne.g,m-=ne.b,v-=ne.a,i=pe+((i=ve+R)<z?i:z)*r<<2,l+=_+=ne.r=n[i],c+=k+=ne.g=n[i+1],d+=S+=ne.b=n[i+2],f+=y+=ne.a=n[i+3],ne=ne.next,h+=w=Ie.r,g+=T=Ie.g,m+=L=Ie.b,v+=O=Ie.a,_-=w,k-=T,S-=L,y-=O,Ie=Ie.next,s+=r}}var mF=function(t){const n=Math.round(this.blurRadius());n>0&&pF(t,n)};he.addGetterSetter(_t,"blurRadius",0,bt(),he.afterSetFilter);var gF=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};he.addGetterSetter(_t,"brightness",0,bt(),he.afterSetFilter);var vF=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)},yF=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};he.addGetterSetter(_t,"contrast",0,bt(),he.afterSetFilter);var bF=function(e){var t,n,r,o,i,s,a,l,c;const d=e.data,f=e.width,h=e.height,g=Math.min(1,Math.max(0,(n=(t=this.embossStrength)===null||t===void 0?void 0:t.call(this))!==null&&n!==void 0?n:.5)),m=Math.min(1,Math.max(0,(o=(r=this.embossWhiteLevel)===null||r===void 0?void 0:r.call(this))!==null&&o!==void 0?o:.5)),v=(a={"top-left":315,top:270,"top-right":225,right:180,"bottom-right":135,bottom:90,"bottom-left":45,left:0}[(s=(i=this.embossDirection)===null||i===void 0?void 0:i.call(this))!==null&&s!==void 0?s:"top-left"])!==null&&a!==void 0?a:315,_=!!((c=(l=this.embossBlend)===null||l===void 0?void 0:l.call(this))!==null&&c!==void 0&&c),k=g*10,S=m*255,y=v*Math.PI/180,w=Math.cos(y),T=Math.sin(y),L=128/1020*k,O=new Uint8ClampedArray(d),U=new Float32Array(f*h);for(let H=0,E=0;E<d.length;E+=4,H++)U[H]=.2126*O[E]+.7152*O[E+1]+.0722*O[E+2];const P=[-1,0,1,-2,0,2,-1,0,1],B=[-1,-2,-1,0,0,0,1,2,1],z=[-f-1,-f,-f+1,-1,0,1,f-1,f,f+1],R=H=>H<0?0:H>255?255:H;for(let H=1;H<h-1;H++)for(let E=1;E<f-1;E++){const $=H*f+E;let Q=0,ie=0;Q+=U[$+z[0]]*P[0],ie+=U[$+z[0]]*B[0],Q+=U[$+z[1]]*P[1],ie+=U[$+z[1]]*B[1],Q+=U[$+z[2]]*P[2],ie+=U[$+z[2]]*B[2],Q+=U[$+z[3]]*P[3],ie+=U[$+z[3]]*B[3],Q+=U[$+z[5]]*P[5],ie+=U[$+z[5]]*B[5],Q+=U[$+z[6]]*P[6],ie+=U[$+z[6]]*B[6],Q+=U[$+z[7]]*P[7],ie+=U[$+z[7]]*B[7],Q+=U[$+z[8]]*P[8],ie+=U[$+z[8]]*B[8];const ee=R(S+(w*Q+T*ie)*L),ne=$*4;if(_){const Ie=ee-S;d[ne]=R(O[ne]+Ie),d[ne+1]=R(O[ne+1]+Ie),d[ne+2]=R(O[ne+2]+Ie),d[ne+3]=O[ne+3]}else d[ne]=d[ne+1]=d[ne+2]=ee,d[ne+3]=O[ne+3]}for(let H=0;H<f;H++){let E=H*4,$=((h-1)*f+H)*4;d[E]=O[E],d[E+1]=O[E+1],d[E+2]=O[E+2],d[E+3]=O[E+3],d[$]=O[$],d[$+1]=O[$+1],d[$+2]=O[$+2],d[$+3]=O[$+3]}for(let H=1;H<h-1;H++){let E=H*f*4,$=(H*f+(f-1))*4;d[E]=O[E],d[E+1]=O[E+1],d[E+2]=O[E+2],d[E+3]=O[E+3],d[$]=O[$],d[$+1]=O[$+1],d[$+2]=O[$+2],d[$+3]=O[$+3]}return e};he.addGetterSetter(_t,"embossStrength",.5,bt(),he.afterSetFilter),he.addGetterSetter(_t,"embossWhiteLevel",.5,bt(),he.afterSetFilter),he.addGetterSetter(_t,"embossDirection","top-left",void 0,he.afterSetFilter),he.addGetterSetter(_t,"embossBlend",!1,void 0,he.afterSetFilter);function W0(e,t,n,r,o){const i=n-t,s=o-r;if(i===0)return r+s/2;if(s===0)return r;let a=(e-t)/i;return a=s*a+r,a}var wF=function(e){const t=e.data,n=t.length;let r=t[0],o=r,i,s=t[1],a=s,l,c=t[2],d=c,f;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),f=t[y+2],f<c?c=f:f>d&&(d=f);o===r&&(o=255,r=0),a===s&&(a=255,s=0),d===c&&(d=255,c=0);let g,m,v,_,k,S;if(h>0)g=o+h*(255-o),m=r-h*(r-0),v=a+h*(255-a),_=s-h*(s-0),k=d+h*(255-d),S=c-h*(c-0);else{const y=(o+r)*.5;g=o+h*(o-y),m=r+h*(r-y);const w=(a+s)*.5;v=a+h*(a-w),_=s+h*(s-w);const T=(d+c)*.5;k=d+h*(d-T),S=c+h*(c-T)}for(let y=0;y<n;y+=4)t[y+0]=W0(t[y+0],r,o,m,g),t[y+1]=W0(t[y+1],s,a,_,v),t[y+2]=W0(t[y+2],c,d,S,k)};he.addGetterSetter(_t,"enhance",0,bt(),he.afterSetFilter);var CF=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}};he.addGetterSetter(_t,"hue",0,bt(),he.afterSetFilter),he.addGetterSetter(_t,"saturation",0,bt(),he.afterSetFilter),he.addGetterSetter(_t,"luminance",0,bt(),he.afterSetFilter);var kF=function(e){const t=e.data,n=t.length,r=1,o=Math.pow(2,this.saturation()),i=Math.abs(this.hue()+360)%360,s=this.luminance()*127,a=r*o*Math.cos(i*Math.PI/180),l=r*o*Math.sin(i*Math.PI/180),c=.299*r+.701*a+.167*l,d=.587*r-.587*a+.33*l,f=.114*r-.114*a-.497*l,h=.299*r-.299*a-.328*l,g=.587*r+.413*a+.035*l,m=.114*r-.114*a+.293*l,v=.299*r-.3*a+1.25*l,_=.587*r-.586*a-1.05*l,k=.114*r+.886*a-.2*l;let S,y,w,T;for(let L=0;L<n;L+=4)S=t[L+0],y=t[L+1],w=t[L+2],T=t[L+3],t[L+0]=c*S+d*y+f*w+s,t[L+1]=h*S+g*y+m*w+s,t[L+2]=v*S+_*y+k*w+s,t[L+3]=T},SF=function(e){const t=e.data,n=t.length,r=Math.pow(2,this.value()),o=Math.pow(2,this.saturation()),i=Math.abs(this.hue()+360)%360,s=r*o*Math.cos(i*Math.PI/180),a=r*o*Math.sin(i*Math.PI/180),l=.299*r+.701*s+.167*a,c=.587*r-.587*s+.33*a,d=.114*r-.114*s-.497*a,f=.299*r-.299*s-.328*a,h=.587*r+.413*s+.035*a,g=.114*r-.114*s+.293*a,m=.299*r-.3*s+1.25*a,v=.587*r-.586*s-1.05*a,_=.114*r+.886*s-.2*a;for(let k=0;k<n;k+=4){const S=t[k+0],y=t[k+1],w=t[k+2],T=t[k+3];t[k+0]=l*S+c*y+d*w,t[k+1]=f*S+h*y+g*w,t[k+2]=m*S+v*y+_*w,t[k+3]=T}};he.addGetterSetter(_t,"hue",0,bt(),he.afterSetFilter),he.addGetterSetter(_t,"saturation",0,bt(),he.afterSetFilter),he.addGetterSetter(_t,"value",0,bt(),he.afterSetFilter);var _F=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]},AF=function(e,t,n){const r=e.data,o=t.data,i=e.width,s=e.height,a=n.polarCenterX||i/2,l=n.polarCenterY||s/2;let c=Math.sqrt(a*a+l*l),d=i-a,f=s-l;const h=Math.sqrt(d*d+f*f);c=h>c?h:c;const g=s,m=i,v=360/m*Math.PI/180;for(let _=0;_<m;_+=1){const k=Math.sin(_*v),S=Math.cos(_*v);for(let y=0;y<g;y+=1){d=Math.floor(a+c*y/g*S),f=Math.floor(l+c*y/g*k);let w=(f*i+d)*4;const T=r[w+0],L=r[w+1],O=r[w+2],U=r[w+3];w=(_+y*i)*4,o[w+0]=T,o[w+1]=L,o[w+2]=O,o[w+3]=U}}},IF=function(e,t,n){const r=e.data,o=t.data,i=e.width,s=e.height,a=n.polarCenterX||i/2,l=n.polarCenterY||s/2;let c=Math.sqrt(a*a+l*l),d=i-a,f=s-l;const h=Math.sqrt(d*d+f*f);c=h>c?h:c;const g=s,m=i,v=n.polarRotation||0;let _,k;for(d=0;d<i;d+=1)for(f=0;f<s;f+=1){const S=d-a,y=f-l,w=Math.sqrt(S*S+y*y)*g/c;let T=(Math.atan2(y,S)*180/Math.PI+360+v)%360;T=T*m/360,_=Math.floor(T),k=Math.floor(w);let L=(k*i+_)*4;const O=r[L+0],U=r[L+1],P=r[L+2],B=r[L+3];L=(f*i+d)*4,o[L+0]=O,o[L+1]=U,o[L+2]=P,o[L+3]=B}},xF=function(e){const t=e.width,n=e.height;let r,o,i,s,a,l,c,d,f,h,g=Math.round(this.kaleidoscopePower());const m=Math.round(this.kaleidoscopeAngle()),v=Math.floor(t*(m%360)/360);if(g<1)return;const _=Re.createCanvasElement();_.width=t,_.height=n;const k=_.getContext("2d").getImageData(0,0,t,n);Re.releaseCanvas(_),AF(e,k,{polarCenterX:t/2,polarCenterY:n/2});let S=t/Math.pow(2,g);for(;S<=8;)S=S*2,g-=1;S=Math.ceil(S);let y=S,w=0,T=y,L=1;for(v+S>t&&(w=y,T=0,L=-1),o=0;o<n;o+=1)for(r=w;r!==T;r+=L)i=Math.round(r+v)%t,f=(t*o+i)*4,a=k.data[f+0],l=k.data[f+1],c=k.data[f+2],d=k.data[f+3],h=(t*o+r)*4,k.data[h+0]=a,k.data[h+1]=l,k.data[h+2]=c,k.data[h+3]=d;for(o=0;o<n;o+=1)for(y=Math.floor(S),s=0;s<g;s+=1){for(r=0;r<y+1;r+=1)f=(t*o+r)*4,a=k.data[f+0],l=k.data[f+1],c=k.data[f+2],d=k.data[f+3],h=(t*o+y*2-r-1)*4,k.data[h+0]=a,k.data[h+1]=l,k.data[h+2]=c,k.data[h+3]=d;y*=2}IF(k,e,{polarRotation:0})};he.addGetterSetter(_t,"kaleidoscopePower",2,bt(),he.afterSetFilter),he.addGetterSetter(_t,"kaleidoscopeAngle",0,bt(),he.afterSetFilter);function tm(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 Rf(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 EF(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 TF(e,t){const n=tm(e,0,0),r=tm(e,e.width-1,0),o=tm(e,0,e.height-1),i=tm(e,e.width-1,e.height-1),s=t||10;if(Rf(n,r)<s&&Rf(r,i)<s&&Rf(i,o)<s&&Rf(o,n)<s){const a=EF([r,n,i,o]),l=[];for(let c=0;c<e.width*e.height;c++){const d=Rf(a,[e.data[c*4],e.data[c*4+1],e.data[c*4+2]]);l[c]=d<s?0:255}return l}}function RF(e,t){for(let n=0;n<e.width*e.height;n++)e.data[4*n+3]=t[n]}function MF(e,t,n){const r=[1,1,1,1,0,1,1,1,1],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let d=0;for(let f=0;f<o;f++)for(let h=0;h<o;h++){const g=a+f-i,m=l+h-i;if(g>=0&&g<n&&m>=0&&m<t){const v=g*t+m,_=r[f*o+h];d+=e[v]*_}}s[c]=d===2040?255:0}return s}function LF(e,t,n){const r=[1,1,1,1,1,1,1,1,1],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let d=0;for(let f=0;f<o;f++)for(let h=0;h<o;h++){const g=a+f-i,m=l+h-i;if(g>=0&&g<n&&m>=0&&m<t){const v=g*t+m,_=r[f*o+h];d+=e[v]*_}}s[c]=d>=1020?255:0}return s}function PF(e,t,n){const r=[.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111,.1111111111111111],o=Math.round(Math.sqrt(r.length)),i=Math.floor(o/2),s=[];for(let a=0;a<n;a++)for(let l=0;l<t;l++){const c=a*t+l;let d=0;for(let f=0;f<o;f++)for(let h=0;h<o;h++){const g=a+f-i,m=l+h-i;if(g>=0&&g<n&&m>=0&&m<t){const v=g*t+m,_=r[f*o+h];d+=e[v]*_}}s[c]=d}return s}var DF=function(e){let t=TF(e,this.threshold());return t&&(t=MF(t,e.width,e.height),t=LF(t,e.width,e.height),t=PF(t,e.width,e.height),RF(e,t)),e};he.addGetterSetter(_t,"threshold",0,bt(),he.afterSetFilter);var OF=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()};he.addGetterSetter(_t,"noise",.2,bt(),he.afterSetFilter);var FF=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){Re.error("pixelSize value can not be <= 0");return}for(let a=0;a<o;a+=1)for(let l=0;l<i;l+=1){let c=0,d=0,f=0,h=0;const g=a*t,m=g+t,v=l*t,_=v+t;let k=0;for(let S=g;S<m;S+=1)if(!(S>=n))for(let y=v;y<_;y+=1){if(y>=r)continue;const w=(n*y+S)*4;c+=s[w+0],d+=s[w+1],f+=s[w+2],h+=s[w+3],k+=1}c=c/k,d=d/k,f=f/k,h=h/k;for(let S=g;S<m;S+=1)if(!(S>=n))for(let y=v;y<_;y+=1){if(y>=r)continue;const w=(n*y+S)*4;s[w+0]=c,s[w+1]=d,s[w+2]=f,s[w+3]=h}}};he.addGetterSetter(_t,"pixelSize",8,bt(),he.afterSetFilter);var NF=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};he.addGetterSetter(_t,"levels",.5,bt(),he.afterSetFilter);var BF=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]}};he.addGetterSetter(_t,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),he.addGetterSetter(_t,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),he.addGetterSetter(_t,"blue",0,I_,he.afterSetFilter);var zF=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}};he.addGetterSetter(_t,"red",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),he.addGetterSetter(_t,"green",0,function(e){return this._filterUpToDate=!1,e>255?255:e<0?0:Math.round(e)}),he.addGetterSetter(_t,"blue",0,I_,he.afterSetFilter),he.addGetterSetter(_t,"alpha",1,function(e){return this._filterUpToDate=!1,e>1?1:e<0?0:e});var VF=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)}},jF=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},UF=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};he.addGetterSetter(_t,"threshold",.5,bt(),he.afterSetFilter);var HF=r4.Util._assign(r4,{Arc:Ca,Arrow:cc,Circle:ku,Ellipse:pl,Image:is,Label:U0,Tag:uc,Line:ka,Path:Fi,Rect:xf,RegularPolygon:ml,Ring:dc,Sprite:Fs,Star:gl,Text:or,TextPath:no,Transformer:Tn,Wedge:Sa,Filters:{Blur:mF,Brightness:vF,Brighten:gF,Contrast:yF,Emboss:bF,Enhance:wF,Grayscale:CF,HSL:kF,HSV:SF,Invert:_F,Kaleidoscope:xF,Mask:DF,Noise:OF,Pixelate:FF,Posterize:NF,RGB:BF,RGBA:zF,Sepia:VF,Solarize:jF,Threshold:UF}}),$F=HF;xt();var GF=["dialog","floating"],I4=["top-right","top-left","bottom-right","bottom-left","top-center","bottom-center"];function WF(e){if(!e||typeof e!="object")throw new Error("SurfaceManager: request must be a non-null object.");if(!GF.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&&!I4.includes(e.floating.placement))throw new Error(`SurfaceManager: floating.placement must be one of ${I4.join(", ")}, got "${e.floating.placement}".`)}var KF=class{activeDialog=Gr(null);activeFloating=Gr(null);#e=!1;#n=1;#t;constructor({getModuleConfig:e}){this.#t=e}open(e){if(this.#e)return this.#f(e);WF(e);const t=this.#d(e),{component:n,props:r,render:o}=this.#h(t);let i,s=!1;const a=new Promise(g=>{i=m=>s?!1:(s=!0,g(m),!0)});let l;const c=g=>{i({status:"submitted",data:g})&&this.#i(l)},d=g=>{i({status:"closed",reason:g})&&this.#i(l)};l={id:t.id,mode:t.mode,request:t,component:n,props:r,render:o,resolve:c,close:d,settle:g=>i(g),get settled(){return s}};const f=t.mode==="dialog"?"activeDialog":"activeFloating",h=this[f].value;return h&&!h.settled&&h.settle({status:"replaced",replacedBy:t.id}),this[f].value=l,{id:t.id,mode:t.mode,close:g=>this.#r(l,g),result:a}}close(e,t){if(e!=null){const o=this.#s(e);o&&this.#r(o,t);return}const n=this.activeDialog.value;if(n&&!n.settled){this.#r(n,t);return}const r=this.activeFloating.value;r&&!r.settled&&this.#r(r,t)}settleAll(e){for(const t of[this.activeDialog,this.activeFloating]){const n=t.value;n&&!n.settled&&n.settle(e),t.value=null}}destroy(){this.#e=!0,this.settleAll({status:"destroyed"})}#r(e,t){e.settled||(e.settle({status:"closed",reason:t}),this.#i(e))}#i(e){const t=e.mode==="dialog"?this.activeDialog:this.activeFloating;t.value===e&&(t.value=null)}#s(e){return this.activeDialog.value?.id===e?this.activeDialog.value:this.activeFloating.value?.id===e?this.activeFloating.value:null}#d(e){const t=e.id??`surface-${this.#n++}`,n=this.#t()??{},r=e.mode==="dialog"?n.dialog:n.floating,o=e.mode==="dialog"?{maxWidth:r?.maxWidth,...e.dialog}:e.dialog,i=e.mode==="floating"?{placement:r?.placement??"top-right",width:r?.width,maxWidth:r?.maxWidth,maxHeight:r?.maxHeight,autoFocus:r?.autoFocus??!0,closeOnOutsidePointerDown:r?.closeOnOutsidePointerDown??!1,...e.floating}:e.floating;return{...e,id:t,closeOnEscape:e.closeOnEscape??r?.closeOnEscape??!0,closeOnBackdrop:e.mode==="dialog"?e.closeOnBackdrop??r?.closeOnBackdrop??!0:!1,dialog:o,floating:i}}#h(e){if("component"in e&&e.component!=null)return{component:e.component,props:e.props};if("render"in e&&typeof e.render=="function")return{render:e.render};const t=this.#t()?.resolver;if(typeof t=="function"){const n=t(e);if(n!=null){if(n.type==="none")throw new Error(`SurfaceManager: resolver explicitly suppressed surface for kind "${e.kind}".`);if(n.type==="custom")return{component:n.component,props:n.props};if(n.type==="external")return{render:n.render}}}throw new Error(`SurfaceManager: no renderer resolved for kind "${e.kind}". Provide a resolver via surfaces.resolver, or use a direct-render request.`)}#f(e){return{id:e?.id??`surface-${this.#n++}`,mode:e?.mode??"dialog",close:()=>{},result:Promise.resolve({status:"destroyed"})}}},qF="https://docs.superdoc.dev/guides/migration/document-api",x4=new Set;function YF(e,t){x4.has(e)||(x4.add(e),console.warn(t))}var XF={state:"editor.state",view:"editor.view",schema:"editor.schema",commands:"editor.commands",chain:"editor.chain()",can:"editor.can()",dispatch:"editor.dispatch()"},E4=Symbol.for("superdoc:rawEditor"),T4=new WeakMap;function R4(e){return!e||e[E4]?e:new Proxy(e,{get(t,n){if(n===E4)return t;const r=XF[n];r&&YF(`deprecated:${String(n)}`,`[SuperDoc] ${r} is deprecated and will be removed in a future version. Use the Document API (editor.doc) instead. See ${qF}`);const o=Reflect.get(t,n,t);if(typeof o=="function"){let i=T4.get(t);return i||(i=new Map,T4.set(t,i)),i.has(n)||i.set(n,o.bind(t)),i.get(n)}return o}})}var M4=["review","original","final","off"],ZF=["paired","independent"],L4=Symbol.for("@superdoc/trackChanges:normalized"),P4=new Set;function D4(e,t){P4.has(e)||(P4.add(e),console.warn(`[SuperDoc] ${e} is deprecated β€” use ${t} instead.`))}function O4(e,t,n){return typeof e=="boolean"?e:typeof t=="boolean"?t:n}function QF(e,t,n){return typeof e=="string"&&M4.includes(e)?e:typeof t=="string"&&M4.includes(t)?t:n}function JF(e){return typeof e=="string"&&ZF.includes(e)?e:null}function fc(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function eN(e){const t=e[L4]===!0;fc(e.modules)||(e.modules={});const n=fc(e.modules.trackChanges),r=fc(e.trackChanges),o=fc(e.layoutEngineOptions?.trackedChanges);t||(r&&D4("config.trackChanges","config.modules.trackChanges"),o&&D4("config.layoutEngineOptions.trackedChanges","config.modules.trackChanges"));const i=O4(n?.visible,r?.visible,!1),s=O4(n?.enabled,o?.enabled,!0),a=JF(n?.replacements)??"paired",l=fc(n?.authorColors)?n.authorColors:void 0,c=fc(n?.semanticColors)?n.semanticColors:void 0,d=e.documentMode==="viewing"?i?"review":"original":"review",f=QF(n?.mode,o?.mode,d),h={visible:i,mode:f,enabled:s,replacements:a};return l&&(h.authorColors=l),c&&(h.semanticColors=c),e.modules.trackChanges=h,e.trackChanges={visible:i},fc(e.layoutEngineOptions)||(e.layoutEngineOptions={}),e.layoutEngineOptions.trackedChanges={mode:f,enabled:s},Object.defineProperty(e,L4,{value:!0,writable:!0,configurable:!0,enumerable:!1}),h}var K0=Object.freeze({id:null,name:"Default SuperDoc user",email:null});function tN(e){return!e||typeof e!="object"?{...K0}:{...K0,...e}}var F4=Object.freeze({toolbar:!0,comments:!0,contextMenu:!0,loading:!0,search:!1,linkPopover:!1,ruler:!1,contentControls:!0}),nN=Object.freeze(["left","center","right"]),jH=Object.freeze(Object.keys(F4)),_u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function N4(e,t){const n=e?.[t];return n===!1?!1:n===void 0?F4[t]:!0}function rN(e,t){const n=e?.[t];return _u(n)?n:{}}var B4=Object.freeze(["readOnly","allowResolve","permissionResolver"]);function oN(e){if(!B4.some(n=>n in e))return e;const t={...e};for(const n of B4)delete t[n];return t}function z4(e={}){const t=e.ui,n=t===!1,r=_u(t)?t:void 0,o=B=>!n&&N4(r,B),i=B=>n?!1:r?.[B]===void 0?void 0:N4(r,B),s=B=>n?{}:rN(r,B),a=n||i("ruler")===!1,l=n||i("linkPopover")===!1,c=l?void 0:p0(s("linkPopover").popoverResolver,e.modules?.links?.popoverResolver),d=i("contentControls")??(!n&&e.modules?.contentControls?.chrome!=="none"),f=e.modules?.contentControls?.chrome==="none"?void 0:e.modules?.contentControls?.chrome,h=s("toolbar"),g=e.modules?.toolbar,m=_u(g)?g:{},v=e.modules?.contextMenu??e.modules?.slashMenu,_=_u(v)?v:{},k=e.modules?.surfaces?.findReplace,S=_u(k)?k:{},y=[h.groups,m.groups],w=y.find(_u),T=y.find(Array.isArray),L=p0(T,m.toolbarGroups,e.toolbarGroups),O=Array.isArray(L)?L:null,U=(B,z)=>Object.prototype.hasOwnProperty.call(B,z),P=w&&O?Object.fromEntries([...O.filter(B=>U(w,B)),...Object.keys(w).filter(B=>!nN.includes(B))].map(B=>[B,w[B]])):w;return{enabled:!n,toolbar:{enabled:o("toolbar"),container:n?null:p0(h.container,m.selector,e.toolbar)??null,options:n?{}:{...Os(m,h),groups:P,toolbarGroups:L,icons:Os(e.toolbarIcons,m.icons,h.icons),texts:Os(e.toolbarTexts,m.texts,h.texts)}},comments:{enabled:i("comments")??(!n&&e.modules?.comments!==!1),options:n?{}:Fk(oN(s("comments")))},contextMenu:{enabled:i("contextMenu")??(!n&&e.disableContextMenu!==!0),suppressed:n||i("contextMenu")===!1,options:n?{}:Os(_,s("contextMenu"))},loading:{enabled:o("loading")},search:{enabled:i("search")??(!n&&!!e.modules?.surfaces?.findReplace),options:n?{}:Os(S,s("search"))},linkPopover:{enabled:typeof c=="function",suppressed:l,options:Os(s("linkPopover"),{popoverResolver:c})},ruler:{enabled:i("ruler")??(!n&&!!e.rulers),suppressed:a,container:a?null:s("ruler").container??e.rulerContainer??null},contentControls:{enabled:d,options:d?Os({chrome:f},s("contentControls")):{chrome:"none"}}}}var q0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function V4(e={}){const t=q0(e.interaction)?e.interaction:{},n=q0(t.comments)?t.comments:{},r=q0(e.modules?.comments)?e.modules.comments:{};return{comments:{readOnly:(n.readOnly??r.readOnly??!1)===!0,allowResolve:(n.allowResolve??r.allowResolve??!0)!==!1}}}var j4=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function U4(e={}){const t=j4(e.surfaces)?e.surfaces:{},n=j4(e.modules?.surfaces)?e.modules.surfaces:{},r=t.resolver===void 0?n.resolver:t.resolver;return{resolver:typeof r=="function"?r:null,dialog:Os(n.dialog,t.dialog),floating:Os(n.floating,t.floating)}}var iN=class{#e=new Map;#n=new Map;#t=null;#r=new Set;register(e){if(this.#e.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.#e.set(e.id,e),t&&this.#n.set(t,e.id)}unregister(e){const t=this.#e.get(e);return t?(this.#e.delete(e),t.root&&this.#n.delete(t.root),this.#t===e&&(this.#t=null,this.#i({previousRuntimeId:e,nextRuntimeId:null,reason:"active-runtime-unregistered",legacyEditorProjection:null})),!0):!1}get(e){return this.#e.get(e)??null}getAll(){return Array.from(this.#e.values())}getAllByDocumentId(e){const t=[];for(const n of this.#e.values())n.documentId===e&&t.push(n);return t}getActive(){return this.#t===null?null:this.#e.get(this.#t)}getActiveId(){return this.#t}setActive(e,t){if(e!==null&&!this.#e.has(e))throw new Error(`EditorRuntimeRegistry: cannot activate unknown runtime "${e}"`);if(e===this.#t)return;const n=this.#t;this.#t=e;let r=null;e!==null&&(r=this.#e.get(e).getLegacyEditorProjection?.()??null),this.#i({previousRuntimeId:n,nextRuntimeId:e,reason:t,legacyEditorProjection:r})}resolveFromEventTarget(e){const t=e instanceof Element?e:e instanceof Node?e.parentElement:null;if(!t)return null;const n=t.closest(`[${Op}]`);if(!n)return null;const r=n.getAttribute(Op),o=r?this.get(r):null;return o&&o.root===n?o:null}subscribe(e){return this.#r.add(e),()=>{this.#r.delete(e)}}clear(){this.#e.clear(),this.#n.clear(),this.#t=null,this.#r.clear()}#i(e){for(const t of Array.from(this.#r))try{t(e)}catch{}}},ut={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"},H4={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 $4(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 sN(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 aN(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 G4(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 Y0(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 lN(e){const t=Y0(e,["alignment","value"]);if(typeof t!="string")return t;const n=t.trim().toLowerCase();return n==="justified"||n==="both"?"justify":n}function cN(e){const t=Y0(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 uN(e){if(e&&typeof e=="object"&&"role"in e)return e;const t=Y0(e,["styleId","value","style"]);return typeof t=="string"?t.trim():t}function dN(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 fN=ut.commandUnsupported,Ns=ut.tableContextUnavailable,W4=[{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:$4,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:$4,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:sN},{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:dN},{id:"measurement-unit",family:"measurement",disposition:"routed",mutates:!1,instanceRoute:"setMeasurementUnit",valueFrom:"measurementUnit",normalizePayload:aN},{id:"text-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.color",inline:{key:"color",kind:"value-string"},normalizePayload:G4},{id:"highlight-color",family:"color",disposition:"routed",mutates:!0,docRoute:"format.highlight",inline:{key:"highlight",kind:"value-string"},normalizePayload:G4},{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:lN},{id:"line-height",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"format.paragraph.setSpacing",blockParagraph:{kind:"spacing-line"},normalizePayload:cN},{id:"linked-style",family:"paragraph",disposition:"routed",mutates:!0,docRoute:"styles.paragraph.setStyle",blockParagraph:{kind:"style"},normalizePayload:uN},{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:Ns},{id:"table-add-row-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertRow",table:{action:"insert-row-after",op:"insertRow"},reason:Ns},{id:"table-delete-row",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteRow",table:{action:"delete-row",op:"deleteRow"},reason:Ns},{id:"table-add-column-before",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-before",op:"insertColumn"},reason:Ns},{id:"table-add-column-after",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.insertColumn",table:{action:"insert-column-after",op:"insertColumn"},reason:Ns},{id:"table-delete-column",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.deleteColumn",table:{action:"delete-column",op:"deleteColumn"},reason:Ns},{id:"table-delete",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.delete",table:{action:"delete-table",op:"delete"},reason:Ns},{id:"table-merge-cells",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.mergeCells",table:{action:"merge-cells",op:"mergeCells"},reason:Ns},{id:"table-split-cell",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.splitCell",table:{action:"split-cell",op:"splitCell",requiresCell:!0},reason:Ns},{id:"table-remove-borders",family:"tables",disposition:"routed",mutates:!0,docRoute:"tables.setBorders",table:{action:"remove-borders",op:"setBorders"},reason:Ns},{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:fN}],hN=new Map(W4.map(e=>[e.id,e])),pN=W4.map(e=>e.id);function Au(e){return hN.get(e)??null}var mN=["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"],K4=[{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:mN,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"}],q4=new Map(K4.map(e=>[e.name,e])),UH=K4.map(e=>e.name);function X0(e){return q4.get(e)??null}function gN(e){const t=q4.get(e);return t?.disposition==="controller-routed"?t.commandId:null}var vN=".png,.jpg,.jpeg,image/png,image/jpeg",Y4=new Set(["image/png","image/jpeg","image/jpg"]),yN=/\.(png|jpe?g)$/i;function bN(e){if(!e)return!1;const t=typeof e.type=="string"?e.type.toLowerCase():"";return t?Y4.has(t):yN.test(String(e.name??""))}function X4(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(wN(String(r.result),e)),r.onerror=()=>n(r.error??new Error("image-read-failed")),r.readAsDataURL(e)})}function wN(e,t){const n=/^data:([^;,]*);base64,/.exec(e);if(!n)return e;const r=n[1].toLowerCase();if(Y4.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 CN(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:kN(n,e)}return X4(e)}async function kN(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 X4(o?Object.assign(r,{name:o}):r)}function SN({ownerDocument:e=document,onPick:t,onError:n}={}){const r=e.createElement("input");return r.type="file",r.accept=vN,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(!bN(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 _N=(e,t)=>{let n=e.replace(/[^0-9.]/g,"");return n=parseFloat(n),isNaN(n)&&(n=t),n=parseFloat(n),n},AN=(e,t,n)=>{let r,o,i,s=0;n||(n={});const a=()=>{s=n.leading===!1?0:Date.now(),r=null,i=e(...o),r||(o=null)},l=(...c)=>{const d=Date.now();!s&&n.leading===!1&&(s=d);const f=t-(d-s);return o=c,f<=0||f>t?(r&&(clearTimeout(r),r=null),s=d,i=e(...c),r||(o=null)):!r&&n.trailing!==!1&&(r=setTimeout(a,f)),i};return l.cancel=function(){clearTimeout(r),s=0,r=o=null},l};xt(),mn();var IN={class:"sd-toolbar-icon"},xN=["innerHTML"],EN={__name:"ToolbarButtonIcon",props:{name:{type:String,required:!0},color:{type:String,default:null},icon:{type:String,default:null}},setup(e){const t=e,n=Ce(()=>{if(t.name==="color")return{backgroundColor:t.color||"#111111"};if(t.name==="highlight")return{backgroundColor:t.color||"#D6D6D6"}}),r=Ce(()=>["color","highlight"].includes(t.name));return(o,i)=>(ge(),Ee("div",IN,[Ne("div",{class:on(["sd-toolbar-icon__icon",[`sd-toolbar-icon__icon--${t.name}`]]),innerHTML:e.icon},null,10,xN),r.value?(ge(),Ee("div",{key:0,class:"color-bar",style:bn(n.value)},null,4)):gt("",!0)]))}},Z4=fn(EN,[["__scopeId","data-v-d7d79424"]]);xt(),mn();var TN=["role","aria-label","aria-disabled"],RN=["data-item"],MN=["data-item"],LN={key:1,class:"sd-button-label"},PN=["data-item","aria-label"],DN=["innerHTML"],ON={key:2},FN=["onKeydown","id"],NN=["placeholder","onKeydown","id","data-item"],BN=["data-item","innerHTML"],zN={"aria-live":"polite",class:"sd-visually-hidden"},VN={__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}=lr(),o=e,{name:i,active:s,icon:a,label:l,hideLabel:c,iconColor:d,hasCaret:f,splitButton:h,disabled:g,expand:m,inlineTextInputVisible:v,hasInlineTextInput:_,minWidth:k,style:S,attributes:y}=o.toolbarItem,w=Ce(()=>!!h?.value&&!!f?.value),T=Ce(()=>i?.value??""),L=te(""),O=te(null),{isHighContrastMode:U}=ts();Nt(()=>l?.value,Se=>{document.activeElement!==O.value&&(L.value=Se==null?"":String(Se))},{immediate:!0});const P=()=>{_&&At(()=>{O.value?.focus(),O.value?.select()}),n("buttonClick")},B=Se=>{g?.value||(Se?.stopPropagation(),n("mainClick"))},z=()=>{w.value||P()},R=Se=>{if(w.value){B(Se);return}P()},H=Se=>{o.allowEnterPropagation||Se.stopPropagation(),R(Se)},E=Se=>{const le=o.toolbarItem?.nestedOptions?.value??[],Oe=Se.trim();if(!Oe)return"";const He=le.find(it=>typeof it?.label=="string"&&it.label.toLowerCase()===Oe.toLowerCase());return He?.label?He.label:le.find(it=>typeof it?.label=="string"&&it.label.toLowerCase().startsWith(Oe.toLowerCase()))?.label??Oe},$=()=>{const Se=String(L.value??"").trim();let le=Se;if(T.value==="fontSize"){const Oe=Number.parseFloat(Se);le=Se.match(/^\d+(\.5)?$/)?Se:Number.isFinite(Oe)?Math.floor(Oe).toString():""}else T.value==="fontFamily"&&(le=E(Se));return le?(n("textSubmit",le),L.value=le,!0):!1},Q=Se=>{const le=Se?.currentTarget;le instanceof HTMLInputElement&&(le.focus({preventScroll:!0}),le.select())},ie=Se=>{requestAnimationFrame(()=>{const le=document.getElementById(`inlineTextInput-${Se}`);le instanceof HTMLInputElement&&(le.focus({preventScroll:!0}),le.select())})},ee=()=>{const Se=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return Se instanceof HTMLElement?(Se.focus({preventScroll:!0}),!0):!1},ne=()=>{const Se=r?.$toolbar?.pendingSelectionCapture,le=()=>{Se&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(Se)};if(ee()){le();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),le())},Ie=()=>{$()&&ne()},pe=Se=>{if($(),Se.shiftKey){T.value==="fontSize"&&(Se.preventDefault(),At(()=>ie("fontFamily")));return}if(Se.preventDefault(),T.value==="fontFamily"){At(()=>ie("fontSize"));return}T.value==="fontSize"&&At(ne)},ye=Ce(()=>S.value?S.value:{minWidth:o.minWidth}),ve=Ce(()=>m?.value?rr.dropdownCaretUp:rr.dropdownCaretDown);return(Se,le)=>(ge(),Ee("div",{class:on(["sd-toolbar-item",qe(y).className]),style:bn(ye.value),role:e.isOverflowItem?"menuitem":"button","aria-label":qe(y).ariaLabel,"aria-disabled":qe(g)?"true":void 0,"data-sd-part":"toolbar-item",onClick:z,onKeydown:le[9]||(le[9]=ni(Oe=>H(Oe),["enter"])),tabindex:"0"},[Ne("div",{class:on(["sd-toolbar-button",{"sd-active":qe(s),"sd-disabled":qe(g),narrow:e.isNarrow,wide:e.isWide,split:w.value,"has-inline-text-input":qe(_),"high-contrast":qe(U)}]),"data-item":`btn-${qe(i)||""}`},[w.value?(ge(),Ee("div",{key:0,class:"sd-toolbar-button__main","data-item":`btn-${qe(i)||""}-main`,onClick:le[0]||(le[0]=Oe=>B(Oe))},[qe(a)?(ge(),ln(Z4,{key:0,color:qe(d),class:"sd-toolbar-icon",icon:qe(a),name:qe(i)},null,8,["color","icon","name"])):gt("",!0),qe(l)&&!qe(c)&&!qe(v)?(ge(),Ee("div",LN,Ht(qe(l)),1)):gt("",!0)],8,MN)):gt("",!0),w.value?(ge(),Ee("div",{key:1,class:"sd-toolbar-button__caret","data-item":`btn-${qe(i)||""}-caret`,"aria-label":`${qe(y).ariaLabel} options`,role:"button"},[Ne("div",{class:"sd-dropdown-caret",innerHTML:ve.value,style:bn({opacity:qe(g)?.6:1})},null,12,DN)],8,PN)):(ge(),Ee(Kt,{key:2},[qe(a)?(ge(),ln(Z4,{key:0,color:qe(d),class:"sd-toolbar-icon",icon:qe(a),name:qe(i)},null,8,["color","icon","name"])):gt("",!0),qe(l)&&!qe(c)&&(!qe(v)||T.value==="fontFamily")?(ge(),Ee("div",{key:1,class:on(["sd-button-label",{"sd-visually-hidden":qe(v)&&T.value==="fontFamily"}])},Ht(qe(l)),3)):gt("",!0),qe(v)?(ge(),Ee("span",ON,[qe(i)==="fontSize"?na((ge(),Ee("input",{key:0,"onUpdate:modelValue":le[1]||(le[1]=Oe=>L.value=Oe),onKeydown:[ni(tn(Ie,["stop","prevent"]),["enter"]),le[2]||(le[2]=ni(Oe=>pe(Oe),["tab"]))],onClick:le[3]||(le[3]=tn(Oe=>Q(Oe),["stop"])),onFocus:le[4]||(le[4]=Oe=>Q(Oe)),type:"text",class:on(["button-text-input button-text-input--font-size",{"high-contrast":qe(U)}]),id:"inlineTextInput-"+qe(i),autocomplete:"off",ref_key:"inlineInput",ref:O},null,42,FN)),[[Di,L.value]]):na((ge(),Ee("input",{key:1,"onUpdate:modelValue":le[5]||(le[5]=Oe=>L.value=Oe),placeholder:qe(l),onKeydown:[ni(tn(Ie,["stop","prevent"]),["enter"]),le[6]||(le[6]=ni(Oe=>pe(Oe),["tab"]))],onClick:le[7]||(le[7]=tn(Oe=>Q(Oe),["stop"])),onFocus:le[8]||(le[8]=Oe=>Q(Oe)),type:"text",class:on(["button-text-input",{"button-text-input--font-family":T.value==="fontFamily","high-contrast":qe(U)}]),id:"inlineTextInput-"+qe(i),"data-item":T.value==="fontFamily"?`btn-${qe(i)}-input`:void 0,autocomplete:"off",ref_key:"inlineInput",ref:O},null,42,NN)),[[Di,L.value]])])):gt("",!0),qe(f)?(ge(),Ee("div",{key:3,class:"sd-dropdown-caret","data-item":`btn-${qe(i)||""}-toggle`,innerHTML:ve.value,style:bn({opacity:qe(g)?.6:1})},null,12,BN)):gt("",!0)],64)),Ne("div",zN,Ht(`${qe(y).ariaLabel} ${qe(s)?"selected":"unset"}`),1)],10,RN)],46,TN))}},Z0=fn(VN,[["__scopeId","data-v-22817fa7"]]);xt(),mn();var jN={class:"toolbar-separator",role:"separator","aria-label":"Toolbar separator"},UN={__name:"ToolbarSeparator",props:{active:{type:Boolean,default:!1}},emits:["command"],setup(e,{emit:t}){const{isHighContrastMode:n}=ts(),r=()=>n.value?"#000":"var(--sd-ui-border, #dbdbdb)";return(o,i)=>(ge(),Ee("div",jN,[Ne("div",{class:"separator-inner",style:bn({backgroundColor:r()})},null,4)]))}},HN=fn(UN,[["__scopeId","data-v-cb82253a"]]);xt(),mn();var $N={class:"overflow-menu"},GN={class:"overflow-menu-trigger"},WN={key:0,class:"overflow-menu_items",role:"group"},KN={__name:"OverflowMenu",props:{toolbarItem:{type:Object,required:!0},overflowItems:{type:Array,required:!0}},emits:["buttonClick","close"],setup(e,{emit:t}){const{proxy:n}=lr(),r=t,o=e,i=Ce(()=>o.toolbarItem.expand.value),s=te(!1),a=Ce(()=>({...o.toolbarItem,active:i.value})),l=()=>{r("buttonClick",o.toolbarItem)},c=({item:f,argument:h})=>{n.$toolbar.emitCommand({item:f,argument:h})},d=f=>{f.key==="Escape"&&i.value&&!s.value&&(f.preventDefault(),r("close"))};return Dn(()=>{document.addEventListener("keydown",d,!0)}),nr(()=>{document.removeEventListener("keydown",d,!0)}),(f,h)=>(ge(),Ee("div",$N,[Ne("div",GN,[Yt(Z0,{"toolbar-item":a.value,onButtonClick:l},null,8,["toolbar-item"])]),i.value?(ge(),Ee("div",WN,[Yt(im,{class:"superdoc-toolbar-overflow","toolbar-items":e.overflowItems,"from-overflow":"",onCommand:c,onDropdownUpdateShow:h[0]||(h[0]=g=>s.value=g)},null,8,["toolbar-items"])])):gt("",!0)]))}},qN=fn(KN,[["__scopeId","data-v-504ecd05"]]);xt(),mn();var YN={class:"toolbar-dropdown"},XN=["onClick"],ZN={key:0,class:"toolbar-dropdown-option__icon"},QN={class:"toolbar-dropdown-option__label"},nm='button, [href], input, select, textarea, [role="button"], [tabindex]:not([tabindex="-1"])',JN={__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=te(null),i=te(null),s=te({top:"0px",left:"0px",maxHeight:"none"}),a=te([]),l=te(-1),c=Ce(()=>!!n.show),d=Ce(()=>n.options.some(le=>le?.type==="render")),f=Ce(()=>typeof n.menuProps!="function"?{}:n.menuProps()||{}),h=Ce(()=>{const{class:le,style:Oe,...He}=f.value;return He}),g=Ce(()=>["toolbar-dropdown-menu",f.value.class,{"toolbar-dropdown-menu--render-only":n.options.length>0&&n.options.every(le=>le&&le.type==="render")}]),m=Ce(()=>{const le=f.value.style||{};return{...n.contentStyle,...le}}),v=Ce(()=>({...m.value,position:"fixed",top:s.value.top,left:s.value.left,maxHeight:s.value.maxHeight,zIndex:2e3})),_=le=>{r("update:show",le)},k=()=>{c.value&&_(!1)},S=()=>{if(!o.value)return;const le=o.value.getBoundingClientRect(),Oe=i.value,He=Oe?.offsetWidth??0,it=Oe?.scrollHeight??Oe?.offsetHeight??0,yt=window.innerWidth||document.documentElement.clientWidth||0,De=window.innerHeight||document.documentElement.clientHeight||0,$e=8,Ye=4,J=le.bottom+Ye,C=le.top-Ye,re=Math.max(0,De-J-$e),V=Math.max(0,C-$e),D=re<it&&V>re,j=D?V:re,W=D?Math.max($e,C-(it?Math.min(it,j):j)):J;let Y=le.left;n.placement==="bottom-end"&&(Y=le.right-He);const Z=Math.max($e,yt-He-$e);Y=Math.min(Math.max($e,Y),Z),s.value={top:`${W}px`,left:`${Y}px`,maxHeight:`${j}px`}},y=()=>{n.disabled||_(!c.value)},w=le=>typeof n.nodeProps!="function"?{}:n.nodeProps(le)||{},T=le=>{le?.disabled||le?.type!=="render"&&(r("select",le?.key,le),k())},L=le=>le?.type==="render",O=le=>!le?.disabled&&le?.type!=="render",U=le=>typeof le?.icon=="function"||!!le?.icon,P=le=>typeof le?.icon=="function"?le.icon(le):le?.icon||null,B=le=>le?typeof le=="string"?le.split(/\s+/).includes("sd-selected"):Array.isArray(le)?le.some(B):typeof le=="object"?!!le["sd-selected"]:!1:!1,z=le=>B(le?.props?.class)||B(le?.class),R=()=>n.options.map((le,Oe)=>O(le)?Oe:-1).filter(le=>le>=0),H=()=>{const le=n.options.findIndex(Oe=>O(Oe)&&z(Oe));return le>=0?le:R()[0]??-1},E=(le,Oe)=>{if(!le){delete a.value[Oe];return}a.value[Oe]=le},$=()=>{a.value.forEach((Oe,He)=>{Oe&&Oe.setAttribute("tabindex",He===l.value?"0":"-1")});const le=a.value[l.value];le&&typeof le.focus=="function"&&(le.focus(),le.scrollIntoView?.({block:"nearest",inline:"nearest"}))},Q=le=>{const Oe=R();if(!Oe.length){l.value=-1;return}const He=Oe.indexOf(l.value);if(He<0){l.value=le>0?Oe[0]:Oe[Oe.length-1];return}const it=(He+le+Oe.length)%Oe.length;l.value=Oe[it]},ie=()=>{let le=n.options[l.value];if(!O(le)){const Oe=R()[0];le=Oe===void 0?null:n.options[Oe]}le&&T(le)},ee=Gl({name:"ToolbarDropdownRenderOption",props:{option:{type:Object,required:!0}},setup(le){return()=>typeof le.option.render!="function"?null:le.option.render()}}),ne=Gl({name:"ToolbarDropdownOptionIcon",props:{option:{type:Object,required:!0}},setup(le){return()=>P(le.option)}}),Ie=le=>{if(!c.value)return;const Oe=le.target;if(!(Oe instanceof Element))return;const He=o.value?.contains(Oe),it=i.value?.contains(Oe);He||it||k()},pe=te(null),ye=()=>{const le=o.value,Oe=document.activeElement;if(le&&Oe instanceof HTMLElement&&le.contains(Oe)){pe.value=Oe;return}pe.value=le?.matches?.(nm)?le:le?.querySelector(nm)},ve=()=>{const le=pe.value;if(le instanceof HTMLElement&&document.contains(le)){le.focus();return}const Oe=o.value;if(!Oe)return;const He=Oe.matches?.(nm)?Oe:Oe.querySelector(nm);if(He instanceof HTMLElement){He.focus();return}Oe.setAttribute("tabindex","-1"),Oe.focus()},Se=le=>{if(!c.value)return;const{key:Oe}=le;if(["Escape","ArrowDown","ArrowUp","Enter"].includes(Oe)){if(Oe==="Escape"){le.preventDefault(),k(),At(()=>{requestAnimationFrame(ve)});return}if(!d.value){if(le.preventDefault(),Oe==="ArrowDown"){Q(1),$();return}if(Oe==="ArrowUp"){Q(-1),$();return}Oe==="Enter"&&ie()}}};return Nt(c,async le=>{if(!le){l.value=-1,a.value=[];return}ye(),await At(),S(),!d.value&&(l.value=H(),await At(),$())},{immediate:!0}),Nt(c,le=>{le?(document.addEventListener("pointerdown",Ie,!0),document.addEventListener("keydown",Se,!0),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0)):(document.removeEventListener("pointerdown",Ie,!0),document.removeEventListener("keydown",Se,!0),window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0))},{immediate:!0}),nr(()=>{document.removeEventListener("pointerdown",Ie,!0),document.removeEventListener("keydown",Se,!0),window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}),(le,Oe)=>(ge(),Ee("div",YN,[Ne("div",{ref_key:"triggerRef",ref:o,class:"toolbar-dropdown-trigger","data-sd-part":"dropdown-trigger",onClick:y},[_d(le.$slots,"trigger",{},void 0,!0)],512),(ge(),ln(Za,{to:"body"},[Yt($h,{name:"fade-in-scale-up-transition"},{default:Fo(()=>[c.value?(ge(),Ee("div",Ss({key:0,ref_key:"menuRef",ref:i,"data-sd-part":"dropdown-menu",class:g.value,style:v.value},h.value),[(ge(!0),Ee(Kt,null,tr(e.options,(He,it)=>(ge(),Ee("div",Ss({key:He.key,ref_for:!0,ref:yt=>E(yt,it),class:["toolbar-dropdown-option",[He.class,He.props?.class,{"sd-disabled":He.disabled,"sd-render":L(He)}]],tabindex:"-1",onClick:yt=>T(He)},{ref_for:!0},{...He.props,...w(He)}),[L(He)?(ge(),ln(qe(ee),{key:0,option:He},null,8,["option"])):(ge(),Ee(Kt,{key:1},[U(He)?(ge(),Ee("span",ZN,[Yt(qe(ne),{option:He},null,8,["option"])])):gt("",!0),Ne("span",QN,Ht(He.label),1)],64))],16,XN))),128))],16)):gt("",!0)]),_:1})]))]))}},eB=fn(JN,[["__scopeId","data-v-fef410f7"]]),Q4=e=>String(e??"").trim().toLowerCase(),rm=(e,t)=>{const n=Q4(e);if(!n)return-1;for(let r=0;r<t.length;r+=1)if(Q4(t[r]).startsWith(n))return r;return-1},tB=(e,t,{autocomplete:n=!0}={})=>{const r=String(e??""),o=rm(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}},nB=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},rB=e=>e<=31||e===127,oB=e=>e===32||e===160||e===65279,iB=e=>Array.from(String(e)).filter(t=>!rB(t.charCodeAt(0))).join(""),sB=e=>{let t="",n=!1;for(const r of String(e)){if(oB(r.charCodeAt(0))){n=t.length>0;continue}n&&(t+=" "),n=!1,t+=r}return t},aB=e=>{const t=String(e??"").split(",")[0]??"",n=iB(t);return sB(nB(n)).trim()},lB=1,cB=1638,uB=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<lB?"":String(Math.min(r,cB))};xt(),mn();var dB=["data-item"],fB=["id","value","disabled","aria-label","aria-expanded","aria-controls","aria-activedescendant","data-item"],hB=["data-item","aria-label","disabled"],pB=["innerHTML"],mB=["id","aria-label"],gB=["id","aria-selected","aria-label","onMousedown","onMouseenter"],vB={class:"toolbar-dropdown-option__label"},yB={class:"sd-button-label sd-font-combobox__legacy-label","aria-hidden":"true"},bB={__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}=ts(),i=te(null),s=te(null),a=te(null),l=te([]),c=te(!1),d=te(!1),f=te(-1),h=te(""),g=te(""),m=te(!1),v=te({top:"0px",left:"0px",minWidth:"0px",maxHeight:"none"}),_=Ce(()=>n.item.nestedOptions?.value??[]),k=Ce(()=>_.value.map(Z=>String(Z?.label??""))),S=Ce(()=>String(n.item.label?.value??"")),y=Ce(()=>!!n.item.disabled?.value),w=Ce(()=>String(n.item.name?.value??"")),T=Ce(()=>n.item.attributes?.value?.ariaLabel??"Font family"),L=Ce(()=>c.value?g.value:S.value),O=Ce(()=>`sd-${w.value||"combobox"}-listbox-${n.item.id?.value??"default"}`),U=Z=>`${O.value}-option-${Z}`,P=Ce(()=>d.value&&f.value>=0?U(f.value):void 0),B=Ce(()=>d.value?rr.dropdownCaretUp:rr.dropdownCaretDown),z=Z=>{const q=String(Z??"").trim().toLowerCase();return _.value.find(me=>String(me?.label??"").trim().toLowerCase()===q)?.props?.style?.fontFamily||Z||n.uiFontFamily},R=Ce(()=>n.showPreview?{fontFamily:z(c.value?g.value:S.value)}:{fontFamily:n.uiFontFamily}),H=()=>{const Z=n.item.selectedValue?.value;if(Z){const q=_.value.findIndex(me=>me?.key===Z);if(q>=0)return q}return k.value.findIndex(q=>q.toLowerCase()===S.value.toLowerCase())},E=(Z,q)=>{const me=i.value;if(!(!me||typeof me.setSelectionRange!="function"))try{me.setSelectionRange(Z,q)}catch{}},$=()=>{l.value[f.value]?.scrollIntoView?.({block:"nearest",inline:"nearest"})},Q=()=>{l.value[f.value]?.focus?.()},ie=()=>{const Z=s.value;if(!Z)return;const q=Z.getBoundingClientRect(),me=a.value,Te=me?.scrollHeight??me?.offsetHeight??0,_e=window.innerHeight||document.documentElement.clientHeight||0,xe=window.innerWidth||document.documentElement.clientWidth||0,We=8,tt=4,at=q.bottom+tt,Ut=q.top-tt,Ct=Math.max(0,_e-at-We),Je=Math.max(0,Ut-We),Vt=Ct<Te&&Je>Ct,nn=Vt?Je:Ct,Ln=Vt?Math.max(We,Ut-(Te?Math.min(Te,nn):nn)):at,Zt=Math.min(Math.max(We,q.left),Math.max(We,xe-q.width-We));v.value={top:`${Ln}px`,left:`${Zt}px`,minWidth:`${q.width}px`,maxHeight:`${nn}px`}},ee=Ce(()=>({position:"fixed",top:v.value.top,left:v.value.left,minWidth:v.value.minWidth,maxHeight:v.value.maxHeight,fontFamily:n.uiFontFamily,zIndex:2e3})),ne=Z=>{n.item.expand&&typeof n.item.expand=="object"&&"value"in n.item.expand&&(n.item.expand.value=Z)},Ie=(Z,{focusInput:q=!1,focusOption:me=!1}={})=>{if(y.value||!_.value.length){ne(!1);return}d.value=!0,ne(!0),f.value=Z??-1,q&&(c.value=!0,g.value=S.value,i.value?.focus()),At(()=>{ie(),$(),me&&Q()})},pe=({syncItem:Z=!0}={})=>{d.value=!1,f.value=-1,Z&&ne(!1)},ye=()=>{pe(),c.value=!1,h.value="",g.value=S.value},ve=()=>{y.value||(d.value||r("item-clicked"),c.value=!0,h.value="",g.value=S.value,At(()=>E(0,g.value.length)))},Se=Z=>{if(y.value)return;const q=document.activeElement===i.value;if(r("item-clicked"),c.value=!0,q||(h.value="",g.value=S.value,Z.preventDefault(),i.value?.focus({preventScroll:!0}),E(0,S.value.length)),!d.value){const me=H();Ie(me>=0?me:0)}},le=Z=>{const q=Z.relatedTarget;q instanceof Node&&s.value?.contains(q)||q instanceof Node&&a.value?.contains(q)||ye()},Oe=Z=>{if(m.value)return;const q=Z.target,me=q.value,Te=typeof q.selectionStart=="number"?q.selectionStart:me.length,_e=typeof q.selectionEnd=="number"?q.selectionEnd:Te,xe=typeof Z.inputType=="string"&&Z.inputType.startsWith("delete"),We=Te===me.length&&_e===me.length;h.value=me;const tt=tB(me,k.value,{autocomplete:!xe&&We});g.value=tt.display,q.value=tt.display,tt.display===me&&!We?E(Te,_e):E(tt.selectionStart,tt.selectionEnd),d.value&&(f.value=tt.matchIndex,At($))},He=Z=>{m.value=!1,Oe(Z)},it=Z=>{if(!_.value.length)return;const q=_.value.length,me=f.value<0?Z>0?-1:0:f.value;f.value=(me+Z+q)%q,At($)},yt=(Z,q)=>{r("item-clicked"),r("command",{item:n.item,argument:Z,option:q}),q&&(n.item.selectedValue.value=q.key)},De=Z=>{Z&&(yt(Z.label,Z),c.value=!1,h.value="",g.value=Z.label,pe())},$e=()=>{if(d.value&&f.value>=0)return De(_.value[f.value]),!0;const Z=rm(h.value,k.value);if(Z>=0)return De(_.value[Z]),!0;const q=n.normalizeValue(h.value);return q?(yt(q,null),c.value=!1,h.value="",g.value=q,pe(),!0):!1},Ye=Z=>{if(!(Z.isComposing||m.value||Z.keyCode===229)&&!(Z.ctrlKey||Z.metaKey||Z.altKey))switch(Z.key){case"ArrowDown":if(Z.preventDefault(),d.value)Q();else{const q=rm(h.value,k.value),me=q>=0?q:H();Ie(me>=0?me:0,{focusOption:!0})}break;case"ArrowUp":if(Z.preventDefault(),d.value)Q();else{const q=rm(h.value,k.value),me=q>=0?q:H();Ie(me>=0?me:_.value.length-1,{focusOption:!0})}break;case"Enter":Z.preventDefault(),$e()&&r("editor-handoff"),i.value?.blur();break;case"Tab":Z.preventDefault(),$e(),pe(),i.value?.blur(),r("tab-out",Z);break;case"Escape":Z.preventDefault(),ye(),At(()=>i.value?.focus())}},J=Z=>{if(Z.preventDefault(),!y.value)if(r("item-clicked"),d.value)pe(),i.value?.focus();else{const q=H();Ie(q>=0?q:0,{focusOption:!0})}},C=(Z,q)=>{Z.preventDefault(),De(q),r("editor-handoff"),i.value?.blur()},re=Z=>{f.value=Z},V=Z=>{if(!(Z.ctrlKey||Z.metaKey||Z.altKey))switch(Z.key){case"ArrowDown":Z.preventDefault(),it(1),Q();break;case"ArrowUp":Z.preventDefault(),it(-1),Q();break;case"Enter":Z.preventDefault(),f.value>=0&&(De(_.value[f.value]),r("editor-handoff"));break;case"Escape":Z.preventDefault(),ye(),At(()=>i.value?.focus());break;case"Tab":Z.preventDefault(),f.value>=0?De(_.value[f.value]):pe(),r("tab-out",{shiftKey:Z.shiftKey,target:i.value})}},D=Z=>{if(!d.value)return;const q=Z.target;q instanceof Element&&(s.value?.contains(q)||a.value?.contains(q)||ye())};Nt(d,Z=>{Z?(document.addEventListener("pointerdown",D,!0),window.addEventListener("resize",ie),window.addEventListener("scroll",ie,!0)):(document.removeEventListener("pointerdown",D,!0),window.removeEventListener("resize",ie),window.removeEventListener("scroll",ie,!0),l.value=[])},{immediate:!0}),nr(()=>{document.removeEventListener("pointerdown",D,!0),window.removeEventListener("resize",ie),window.removeEventListener("scroll",ie,!0)});const j=(Z,q)=>{if(!Z){delete l.value[q];return}l.value[q]=Z},W=Z=>Z===f.value,Y=Z=>Z?.key&&Z.key===n.item.selectedValue?.value;return Nt(S,Z=>{c.value||(g.value=Z)}),Nt(()=>!!n.item.expand?.value,Z=>{if(Z&&!d.value){const q=H();Ie(q>=0?q:0,{focusInput:!0});return}!Z&&d.value&&pe({syncItem:!1})}),(Z,q)=>(ge(),Ee("div",{ref_key:"rootRef",ref:s,class:on(["sd-font-combobox sd-toolbar-split-field",{"sd-disabled":y.value,"high-contrast":qe(o)}]),style:bn(n.item.style?.value),"data-item":`btn-${w.value}`},[Ne("span",{class:"sd-font-combobox__field sd-toolbar-split-field__main",onMousedown:Se},[Ne("input",{ref_key:"inputRef",ref:i,id:`inlineTextInput-${w.value}`,class:"button-text-input sd-font-combobox__input",type:"text",role:"combobox",autocomplete:"off",spellcheck:"false",value:L.value,style:bn(R.value),disabled:y.value,"aria-label":T.value,"aria-expanded":d.value?"true":"false","aria-controls":O.value,"aria-activedescendant":P.value,"aria-haspopup":"listbox","aria-autocomplete":"both","data-item":`btn-${w.value}-input`,onFocus:ve,onBlur:le,onInput:Oe,onKeydown:Ye,onCompositionstart:q[0]||(q[0]=me=>m.value=!0),onCompositionend:He},null,44,fB)],32),Ne("button",{type:"button",class:"sd-font-combobox__caret sd-toolbar-split-field__caret","data-item":`btn-${w.value}-toggle`,tabindex:"-1","aria-label":`${T.value} options`,disabled:y.value,onMousedown:J},[Ne("span",{class:"sd-dropdown-caret",innerHTML:B.value},null,8,pB)],40,hB),(ge(),ln(Za,{to:"body"},[d.value?(ge(),Ee("div",{key:0,ref_key:"popupRef",ref:a,role:"listbox",id:O.value,"aria-label":T.value,class:on(["sd-font-combobox__listbox",{"high-contrast":qe(o)}]),style:bn(ee.value)},[(ge(!0),Ee(Kt,null,tr(_.value,(me,Te)=>(ge(),Ee("div",Ss({key:me.key,ref_for:!0,ref:_e=>j(_e,Te),id:U(Te),role:"option",tabindex:"-1",class:["toolbar-dropdown-option sd-font-combobox__option",{"sd-active":W(Te),"sd-selected":Y(me)}],"aria-selected":Y(me)?"true":"false","aria-label":`${T.value} - ${me.label}`},{ref_for:!0},me.props,{onMousedown:_e=>C(_e,me),onMouseenter:_e=>re(Te),onKeydown:V}),[Ne("span",vB,Ht(me.label),1)],16,gB))),128))],14,mB)):gt("",!0)])),Ne("span",yB,Ht(S.value),1)],14,dB))}},J4=fn(bB,[["__scopeId","data-v-99070b63"]]);xt();var wB={__name:"FontFamilyCombobox",props:{item:{type:Object,required:!0},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"}},emits:["command","item-clicked","tab-out","editor-handoff"],setup(e,{emit:t}){const n=e,r=t;return(o,i)=>(ge(),ln(J4,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!0,"normalize-value":qe(aB),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"]))}};xt();var CB={__name:"FontSizeCombobox",props:{item:{type:Object,required:!0},uiFontFamily:{type:String,default:"Arial, Helvetica, sans-serif"}},emits:["command","item-clicked","tab-out","editor-handoff"],setup(e,{emit:t}){const n=e,r=t;return(o,i)=>(ge(),ln(J4,{item:n.item,"ui-font-family":n.uiFontFamily,"show-preview":!1,"normalize-value":qe(uB),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"]))}};xt(),mn();var kB=2500,SB=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=X1(),r=te(!1),o=te(null),i=te(null),s=te({top:"0px",left:"0px"});let a=null,l=null,c=null;const d=Ce(()=>["sd-tooltip-content",n.class]),f=Ce(()=>({...t.contentStyle,...n.style||{},position:"fixed",top:s.value.top,left:s.value.left,zIndex:2100})),h=()=>{a&&(window.clearTimeout(a),a=null)},g=()=>{l&&(window.clearTimeout(l),l=null)},m=()=>{c&&(window.clearTimeout(c),c=null)},v=()=>{m(),c=window.setTimeout(()=>{c=null,S()},kB)},_=()=>{if(!o.value||!i.value)return;const B=o.value.getBoundingClientRect(),z=i.value.offsetWidth,R=i.value.offsetHeight,H=window.innerWidth||document.documentElement.clientWidth||0,E=8;let $=B.left+B.width/2-z/2;$=Math.max(E,Math.min($,H-z-E)),s.value={top:`${B.top-R-10}px`,left:`${$}px`}},k=async()=>{t.disabled||(h(),g(),!r.value&&(r.value=!0,v(),await At(),_()))},S=()=>{g(),h(),m(),r.value&&(r.value=!1)},y=()=>{if(h(),g(),!r.value){if(t.delay===0){k();return}l=window.setTimeout(()=>{l=null,k()},t.delay)}},w=()=>{if(g(),h(),!!r.value){if(t.duration===0){S();return}a=window.setTimeout(()=>{a=null,S()},t.duration)}},T=()=>{t.trigger==="hover"&&y()},L=()=>{t.trigger==="hover"&&w()},O=()=>{g(),h()},U=()=>{w()},P=B=>{B.key==="Escape"&&S()};return Nt(()=>t.disabled,B=>{B&&S()}),Nt(r,B=>{B?(window.addEventListener("resize",_),window.addEventListener("scroll",_,!0),document.addEventListener("keydown",P,!0)):(window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0),document.removeEventListener("keydown",P,!0))}),nr(()=>{g(),h(),m(),window.removeEventListener("resize",_),window.removeEventListener("scroll",_,!0),document.removeEventListener("keydown",P,!0)}),(B,z)=>(ge(),Ee(Kt,null,[Ne("span",{ref_key:"triggerRef",ref:o,class:"sd-tooltip-trigger",onMouseenter:T,onMouseleave:L,onFocusin:T,onFocusout:L},[_d(B.$slots,"trigger",{},void 0,!0)],544),(ge(),ln(Za,{to:"body"},[Yt($h,{name:"fade-in-scale-up-transition"},{default:Fo(()=>[r.value&&!e.disabled?(ge(),Ee("div",{key:0,ref_key:"contentRef",ref:i,class:on(d.value),style:bn(f.value),onMouseenter:O,onMouseleave:U},[z[0]||(z[0]=Ne("span",{class:"sd-tooltip-arrow","aria-hidden":"true"},null,-1)),_d(B.$slots,"default",{},void 0,!0)],38)):gt("",!0)]),_:3})]))],64))}}),om=fn(SB,[["__scopeId","data-v-2a872eae"]]),hc=(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})};xt(),mn();var _B=["onKeydown","tabindex","data-item-id"],AB={key:0},IB={key:0},xB={key:0},EB={key:0},TB={key:0},RB={__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}=lr(),o=te([]),i=te(null),s=e,a=te(null),{isHighContrastMode:l}=ts(),c=window.matchMedia("(max-width: 768px)").matches,d=Ce(()=>s.position==="left"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-start"}:s.position==="right"?{minWidth:s.compactSideGroups?"auto":"120px",justifyContent:"flex-end"}:{flexGrow:c?0:1,justifyContent:"center"}),f=De=>De.type==="button",h=De=>De.type==="dropdown",g=De=>De.type==="dropdown"&&De.name?.value==="fontFamily",m=De=>De.type==="dropdown"&&De.name?.value==="fontSize",v=De=>De.type==="separator",_=De=>De.type==="overflow",k=De=>!!De.nestedOptions?.value?.length,S=De=>{if(!De)return!1;const $e=De.expand;return typeof $e=="object"&&$e!==null&&"value"in $e?!!$e.value:!!$e},y=(De,$e)=>{De?.expand&&(De.expand.value=$e)},w=(De,$e=void 0)=>{if(De.disabled.value)return;if(_(De)){const J=!S(De);J&&O(),y(De,J),a.value=J?De:null,n("item-clicked");return}if(h(De))return;a.value&&h(a.value)&&S(a.value)&&O(),n("item-clicked");const Ye=$e!==void 0?$e:De.argument?.value;n("command",Ye===void 0?{item:De}:{item:De,argument:Ye})},T=(De,$e)=>{De.disabled.value||(a.value=null,n("command",{item:De,argument:$e}))},L=De=>{if(De.disabled.value)return;O();const $e=De.splitButtonCommand,Ye=De.command,J=$e||Ye;if(!J)return;const C={...De,command:J};n("item-clicked"),n("command",{item:C})},O=()=>{const De=r?.$toolbar?.toolbarItems||[],$e=r?.$toolbar?.overflowItems||[],Ye=[...De,...$e];(Ye.length?Ye:s.toolbarItems).forEach(J=>{const C=_(J)&&!s.fromOverflow;(h(J)||C)&&y(J,!1)}),a.value=null},U=(De,$e)=>{O();const Ye=De.dropdownValueKey.value?$e[De.dropdownValueKey.value]:$e.label;n("command",{item:De,argument:Ye,option:$e}),De.selectedValue.value=$e.key,De.restoreEditorFocus&&hc(r?.$toolbar)},P=De=>{n("command",De)},B=()=>{O(),n("item-clicked")},z=()=>{const De=document.querySelector('[role="textbox"][aria-label*="SuperDoc body"], .ProseMirror');return De instanceof HTMLElement?(De.focus({preventScroll:!0}),!0):!1},R=()=>{const De=r?.$toolbar?.pendingSelectionCapture,$e=()=>{De&&typeof r?.$toolbar?.ui?.selection?.restore=="function"&&r.$toolbar.ui.selection.restore(De)};if(z()){$e();return}typeof r?.$toolbar?.superdoc?.focus=="function"&&(r.$toolbar.superdoc.focus(),$e())},H=De=>!(De instanceof HTMLElement)||De.classList.contains("sd-disabled")?null:De.querySelector("input:not([disabled]), textarea:not([disabled]), select:not([disabled])")||De.querySelector('button:not([disabled]), [role="button"]:not(.sd-disabled), [tabindex]:not([tabindex="-1"])'),E=(De,$e)=>{const Ye=De?.target?.closest?.(".sd-toolbar-item-ctn");if(!(Ye instanceof HTMLElement))return!1;let J=$e>0?Ye.nextElementSibling:Ye.previousElementSibling;for(;J;){const C=H(J);if(C instanceof HTMLElement)return Ye.setAttribute("tabindex","-1"),J.setAttribute("tabindex","0"),C.focus(),!0;J=$e>0?J.nextElementSibling:J.previousElementSibling}return!1},$=De=>{O();const $e=De?.shiftKey?-1:1;E(De,$e)||R()},Q=De=>{if(O(),De?.shiftKey){E(De,-1)||R();return}R()},ie=()=>{R()},ee=De=>De.nestedOptions?.value?.length?De.nestedOptions.value.map($e=>{const Ye=$e?.type!=="render"&&De.selectedValue.value===$e.key;return{...$e,props:{...$e.props,class:Ye?"sd-selected":""}}}):[],ne=(De,$e)=>({role:"menuitem",ariaLabel:`${$e.attributes.value.ariaLabel} - ${De.label}`}),Ie=De=>{const $e=De.target,Ye=De.target.closest(".sd-toolbar-item-ctn").nextElementSibling;Ye&&($e.setAttribute("tabindex","-1"),Ye.setAttribute("tabindex","0"),Ye.focus())},pe=De=>{const $e=De.target,Ye=De.target.closest(".sd-toolbar-item-ctn").previousElementSibling;Ye&&($e.setAttribute("tabindex","-1"),Ye.setAttribute("tabindex","0"),Ye.focus())},ye=De=>{const $e=De.target.closest(".button-group").nextElementSibling;if($e)$e.setAttribute("tabindex","0"),$e.focus();else{const Ye=document.querySelector(".ProseMirror");Ye&&Ye.focus()}},ve=De=>{const $e=De.target.closest(".button-group").previousElementSibling;$e&&($e.setAttribute("tabindex","0"),$e.focus())},Se=De=>{if(!De.disabled.value){if(h(De)){He(!S(De),De);return}w(De)}},le=(De,$e)=>{const Ye=De.target.nodeName==="INPUT"||De.target.nodeName==="TEXTAREA",J=$e.name.value==="fontSize"||$e.name.value==="fontFamily";if(!(Ye&&J)&&["Enter"," ","Spacebar","Escape","ArrowRight","ArrowLeft","Tab"].includes(De.key))switch(De.preventDefault(),De.key){case"Enter":case" ":case"Spacebar":Se($e);break;case"Escape":O();break;case"ArrowRight":O(),Ie(De);break;case"ArrowLeft":O(),pe(De);break;case"Tab":De.shiftKey?ve(De):ye(De)}},Oe=De=>{const $e=o.value.find(Ye=>!Ye.classList.contains("sd-disabled"));$e&&($e.setAttribute("tabindex","0"),$e.focus())},He=(De,$e)=>{if(n("item-clicked"),!De){O(),n("dropdown-update-show",!1);return}O(),a.value=$e,y($e,!0),n("dropdown-update-show",!0)},it=De=>{if(!a.value)return;const $e=De.target;$e instanceof Element&&($e.closest(".sd-toolbar-dropdown-menu")||i.value?.contains($e)||O())};return Nt(()=>S(a.value),De=>{De?document.addEventListener("pointerdown",it,!0):document.removeEventListener("pointerdown",it,!0)},{immediate:!0}),nr(()=>{document.removeEventListener("pointerdown",it,!0)}),(De,$e)=>(ge(),Ee("div",{style:bn(d.value),class:"button-group",role:"group",onFocus:Oe,ref_key:"buttonGroupRef",ref:i},[(ge(!0),Ee(Kt,null,tr(e.toolbarItems,(Ye,J)=>(ge(),Ee("div",{key:Ye.id.value,class:on([{narrow:Ye.isNarrow.value,wide:Ye.isWide.value,"sd-disabled":Ye.disabled.value},"sd-toolbar-item-ctn"]),onKeydown:C=>le(C,Ye),ref_for:!0,ref_key:"toolbarItemRefs",ref:o,tabindex:J===0?0:-1,"data-item-id":Ye.id.value},[v(Ye)?(ge(),ln(HN,{key:0,style:{width:"20px"}})):gt("",!0),g(Ye)&&k(Ye)?(ge(),ln(om,{key:1,trigger:"hover",disabled:!Ye.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:Fo(()=>[Yt(wB,{item:Ye,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:P,onItemClicked:B,onTabOut:$e[0]||($e[0]=C=>$(C)),onEditorHandoff:ie},null,8,["item","ui-font-family"])]),default:Fo(()=>[Ne("div",null,[Zi(Ht(Ye.tooltip)+" ",1),Ye.disabled.value?(ge(),Ee("span",AB,"(disabled)")):gt("",!0)])]),_:2},1032,["disabled","content-style"])):m(Ye)&&k(Ye)?(ge(),ln(om,{key:2,trigger:"hover",disabled:!Ye.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:Fo(()=>[Yt(CB,{item:Ye,"ui-font-family":s.uiFontFamily,class:"sd-toolbar-button sd-editor-toolbar-dropdown",onCommand:P,onItemClicked:B,onTabOut:$e[1]||($e[1]=C=>Q(C)),onEditorHandoff:ie},null,8,["item","ui-font-family"])]),default:Fo(()=>[Ne("div",null,[Zi(Ht(Ye.tooltip)+" ",1),Ye.disabled.value?(ge(),Ee("span",IB,"(disabled)")):gt("",!0)])]),_:2},1032,["disabled","content-style"])):h(Ye)&&Ye.nestedOptions?.value?.length?(ge(),ln(eB,{key:3,options:ee(Ye),disabled:Ye.disabled.value,show:S(Ye),"content-style":{fontFamily:s.uiFontFamily},placement:"bottom-start",class:"sd-toolbar-button sd-editor-toolbar-dropdown",onSelect:(C,re)=>U(Ye,re),"onUpdate:show":C=>He(C,Ye),style:bn(Ye.dropdownStyles.value),"menu-props":()=>({role:"menu",style:{fontFamily:s.uiFontFamily},class:["sd-toolbar-dropdown-menu",{"high-contrast":qe(l)}]}),"node-props":C=>ne(C,Ye)},{trigger:Fo(()=>[Yt(om,{trigger:"hover",disabled:!Ye.tooltip?.value,"content-style":{fontFamily:s.uiFontFamily}},{trigger:Fo(()=>[Yt(Z0,{"toolbar-item":Ye,disabled:Ye.disabled.value,"allow-enter-propagation":!0,onTextSubmit:C=>T(Ye,C),onMainClick:C=>L(Ye)},null,8,["toolbar-item","disabled","onTextSubmit","onMainClick"])]),default:Fo(()=>[Ne("div",null,[Zi(Ht(Ye.tooltip)+" ",1),Ye.disabled.value?(ge(),Ee("span",xB,"(disabled)")):gt("",!0)])]),_:2},1032,["disabled","content-style"])]),_:2},1032,["options","disabled","show","content-style","onSelect","onUpdate:show","style","menu-props","node-props"])):f(Ye)?(ge(),ln(om,{key:4,trigger:"hover",class:"sd-editor-toolbar-tooltip","content-style":{fontFamily:s.uiFontFamily}},{trigger:Fo(()=>[Yt(Z0,{"toolbar-item":Ye,"is-overflow-item":e.fromOverflow,onTextSubmit:C=>T(Ye,C),onButtonClick:C=>w(Ye)},null,8,["toolbar-item","is-overflow-item","onTextSubmit","onButtonClick"])]),default:Fo(()=>[Ye.tooltip?(ge(),Ee("div",EB,[Zi(Ht(Ye.tooltip)+" ",1),Ye.disabled.value?(ge(),Ee("span",TB,"(disabled)")):gt("",!0)])):gt("",!0)]),_:2},1032,["content-style"])):gt("",!0),_(Ye)&&e.overflowItems.length?(ge(),ln(qN,{key:5,"toolbar-item":Ye,onButtonClick:C=>w(Ye),"overflow-items":e.overflowItems,onClose:O},null,8,["toolbar-item","onButtonClick","overflow-items"])):gt("",!0)],42,_B))),128))],36))}},im=fn(RB,[["__scopeId","data-v-2bc00f65"]]),MB=[["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"]],LB=MB.map(([e,t])=>({label:e,key:e,props:{style:{fontFamily:`${e}, ${t}`},"data-item":"btn-fontFamily-option"}}));function PB(e){if(e?.length)return e.map(t=>({label:t.label,key:t.value,props:{style:{fontFamily:t.previewFamily||t.label},"data-item":"btn-fontFamily-option"}}))}var DB=[{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"}}],Mf={sm:768,md:1024,lg:1280,xl:1410},Q0={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"},eA={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"},tA=Object.values(eA),HH=[...new Set([...Object.values(Q0),...tA])],OB=new Set(["link"]),$H=new Set(Object.keys(Q0).filter(e=>!OB.has(e)));xt(),mn();var FB="Arial, Helvetica, sans-serif",NB={__name:"Toolbar",emits:["command","toggle","select"],setup(e,{emit:t}){const{proxy:n}=lr();let r=te(1);const o=te(0),i=te(!1);let s=null,a=null;const l=Ce(()=>{const U=n?.$toolbar?.config?.uiDisplayFallbackFont;return typeof U=="string"&&U.trim()?U.trim():FB}),c=n.$toolbar.config?.toolbarGroups?.includes("left"),d=n.$toolbar.config?.toolbarGroups?.includes("right"),f=n.$toolbar.config?.toolbarButtonsExclude||[],h=U=>(o.value,n.$toolbar.getToolbarItemByGroup(U).filter(P=>!f.includes(P.name.value))),g=()=>{i.value=n.$toolbar.getAvailableWidth()<=Mf.lg},v=AN(async()=>{await n.$toolbar.onToolbarResize(),g(),r.value+=1},300),_=()=>{r.value+=1},k=()=>{o.value+=1};function S(){window.removeEventListener("resize",v),n.$toolbar.off?.("toolbar-items-changed",_),n.$toolbar.off?.("toolbar-state-change",k),s?.disconnect(),s=null}function y(){S(),window.addEventListener("resize",v),n.$toolbar.on?.("toolbar-items-changed",_),n.$toolbar.on?.("toolbar-state-change",k),typeof ResizeObserver<"u"&&n.$toolbar.config?.responsiveToContainer&&n.$toolbar.toolbarContainer&&(s=new ResizeObserver(()=>{v()}),s.observe(n.$toolbar.toolbarContainer)),g()}Dn(y),Tg(y),Rg(S),nr(S);const w=()=>{if(!n.$toolbar.activeEditor){a=null,n.$toolbar.pendingSelectionCapture=null;return}a=n.$toolbar.ui?.selection?.capture?.()??null,n.$toolbar.pendingSelectionCapture=a},T=({item:U,argument:P,option:B})=>{L(),n.$toolbar.emitCommand({item:U,argument:P,option:B})},L=()=>{const U=n.$toolbar.activeEditor;if(!U)return;const P=n.$toolbar.pendingSelectionCapture??a;if(P&&typeof n.$toolbar.ui?.selection?.restore=="function"){n.$toolbar.ui.selection.restore(P);return}U.commands?.restoreSelection?.()},O=U=>{w(),!U.target.closest('input, textarea, [contenteditable="true"]')&&U.preventDefault()};return(U,P)=>(ge(),Ee("div",{class:"superdoc-toolbar",key:qe(r),role:"toolbar","aria-label":"Toolbar","data-sd-part":"toolbar","data-editor-ui-surface":"",onMousedown:O},[qe(c)?(ge(),ln(im,{key:0,tabindex:"0","toolbar-items":h("left"),"overflow-items":qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"left",onCommand:T,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):gt("",!0),Yt(im,{tabindex:"0","toolbar-items":h("center"),"overflow-items":qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"center",onCommand:T},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"]),qe(d)?(ge(),ln(im,{key:1,tabindex:"0","toolbar-items":h("right"),"overflow-items":qe(n).$toolbar.overflowItems,"compact-side-groups":i.value,"ui-font-family":l.value,position:"right",onCommand:T,class:"superdoc-toolbar-group-side"},null,8,["toolbar-items","overflow-items","compact-side-groups","ui-font-family"])):gt("",!0)],32))}},BB=fn(NB,[["__scopeId","data-v-55b5af7a"]]),zB=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"}}};xt();var In=e=>{if(!["button","options","separator","dropdown","overflow"].includes(e.type))throw new Error("Invalid toolbar item type - "+e.type);if(e.type==="button"&&!e.defaultLabel&&!e.icon)throw new Error(`Toolbar button item needs either "icon" or "defaultLabel" - ${e.name}. "label" is the live label and is not a substitute for "defaultLabel".`);if(!e.name)throw new Error("Invalid toolbar item name - "+e.name);const t=te(ys()),n=e.type,r=te(e.name),o=e.command,i=e.noArgumentCommand,s=te(e.icon),a=te(e.group||"center"),l=te(e.allowWithoutEditor),c=te(e.attributes||{}),d=e.disabled||!1,f=te(e.disabled),h=te(!1),g=te(!1),m=te(e.style),v=te(e.isNarrow),_=te(e.isWide),k=te(e.minWidth),S=te(e.suppressActiveHighlight||!1),y=te(e.argument),w=te(null),T=te(null),L=te(e.iconColor),O=te(e.hasCaret),U=te(!!e.splitButton),P=e.splitButtonCommand,B=!!e.restoreEditorFocus,z=te(e.dropdownStyles),R=te(e.tooltip),H=te(e.tooltipVisible),E=te(e.tooltipTimeout),$=te(e.defaultLabel),Q=te(e.label),ie=te(e.hideLabel),ee=te(e.inlineTextInputVisible),ne=te(e.hasInlineTextInput),Ie=te(e.markName),pe=te(e.labelAttr),ye=te(e.selectedValue),ve=te(e.dropdownValueKey),Se=te(e.inputRef||null),le=te([]);if(e.options){if(!Array.isArray(e.options))throw new Error("Invalid toolbar item options - "+e.options);let C=0;for(let re=0;re<e.options.length;re+=1){const V=e.options[re];(!V||typeof V!="object")&&(C+=1)}if(C)throw new Error(`Toolbar item options must all be objects - ${e.name}. ${C} row(s) are not, so this item is skipped.`);le.value?.push(...e.options)}const Oe=(C={},...re)=>{De(C,...re),!S.value&&(h.value=!0)},He=()=>{$e(),h.value=!1},it=C=>{f.value=C},yt=()=>{f.value=d},De=e.onActivate||(()=>null),$e=e.onDeactivate||(()=>null),Ye=()=>{const C={};return Object.keys(J).forEach(re=>{J[re].value!==void 0&&(C[re]=J[re].value)}),C},J={id:t,name:r,type:n,command:o,noArgumentCommand:i,icon:s,tooltip:R,group:a,attributes:c,disabled:f,active:h,expand:g,nestedOptions:le,style:m,isNarrow:v,isWide:_,minWidth:k,argument:y,parentItem:T,iconColor:L,hasCaret:O,splitButton:U,splitButtonCommand:P,dropdownStyles:z,tooltipVisible:H,tooltipTimeout:E,defaultLabel:$,label:Q,hideLabel:ie,inlineTextInputVisible:ee,hasInlineTextInput:ne,restoreEditorFocus:B,markName:Ie,labelAttr:pe,childItem:w,allowWithoutEditor:l,dropdownValueKey:ve,selectedValue:ye,inputRef:Se};return{...J,unref:Ye,activate:Oe,deactivate:He,setDisabled:it,resetDisabled:yt,onActivate:De,onDeactivate:$e}};xt(),mn();var VB=["onClick","innerHTML","aria-label","onKeydown"],jB={__name:"AlignmentButtons",emits:["select"],setup(e,{emit:t}){const{isHighContrastMode:n}=ts(),r=t,o=te([]),i=[{key:"left",ariaLabel:"Align left",icon:rr.alignLeft},{key:"center",ariaLabel:"Align center",icon:rr.alignCenter},{key:"right",ariaLabel:"Align right",icon:rr.alignRight},{key:"justify",ariaLabel:"Justify",icon:rr.alignJustify}],s=d=>{r("select",d)},a=d=>{if(d===o.value.length-1)return;const f=o.value[d+1];f&&(f.setAttribute("tabindex","0"),f.focus())},l=d=>{if(d===0)return;const f=o.value[d-1];f&&(f.setAttribute("tabindex","0"),f.focus())},c=(d,f)=>{switch(d.key){case"ArrowLeft":l(f);break;case"ArrowRight":a(f);break;case"Enter":s(i[f].key)}};return Dn(()=>{const d=o.value[0];d&&(d.setAttribute("tabindex","0"),d.focus())}),(d,f)=>(ge(),Ee("div",{class:on(["alignment-buttons",{"high-contrast":qe(n)}])},[(ge(),Ee(Kt,null,tr(i,(h,g)=>Ne("div",{key:h.key,class:"sd-button-icon",onClick:m=>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:tn(m=>c(m,g),["prevent"])},null,40,VB)),64))],2))}},UB=fn(jB,[["__scopeId","data-v-13e5f7a4"]]);xt(),mn();var HB=["onClick","innerHTML","aria-label","onKeydown"],$B={__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}=ts(),r=t,o=e,i=te([]),s=Ce(()=>({width:`${o.iconSize}px`,height:`${o.iconSize}px`})),a=f=>{r("select",f)},l=f=>{if(f===i.value.length-1)return;const h=i.value[f+1];h&&(h.setAttribute("tabindex","0"),h.focus())},c=f=>{if(f===0)return;const h=i.value[f-1];h&&(h.setAttribute("tabindex","0"),h.focus())},d=(f,h)=>{switch(f.key){case"ArrowLeft":c(h);break;case"ArrowRight":l(h);break;case"Enter":a(o.buttons[h].key)}};return Dn(()=>{const f=i.value[0];f&&(f.setAttribute("tabindex","0"),f.focus())}),(f,h)=>(ge(),Ee("div",{class:on(["style-buttons-list",{"high-contrast":qe(n)}])},[(ge(!0),Ee(Kt,null,tr(o.buttons,(g,m)=>(ge(),Ee("div",{key:g.key,class:on(["sd-button-icon",{"sd-selected":o.selectedStyle===g.key}]),style:bn(s.value),onClick:v=>a(g.key),innerHTML:g.icon,role:"menuitem","aria-label":g.ariaLabel,ref_for:!0,ref_key:"buttonRefs",ref:i,onKeydown:tn(v=>d(v,m),["prevent"])},null,46,HB))),128))],2))}},nA=fn($B,[["__scopeId","data-v-44f37ff6"]]),GB=[{key:"disc",icon:rr.bulletListDisc,ariaLabel:"Opaque circle"},{key:"circle",icon:rr.bulletListCircle,ariaLabel:"Outline circle"},{key:"square",icon:rr.bulletListSquare,ariaLabel:"Opaque square"}],WB=[{key:"decimal",icon:rr.numberedListDecimal,ariaLabel:"1. 2. 3."},{key:"decimal-paren",icon:rr.numberedListDecimalParen,ariaLabel:"1) 2) 3)"},{key:"upper-roman",icon:rr.numberedListUpperRoman,ariaLabel:"I. II. III."},{key:"lower-roman",icon:rr.numberedListLowerRoman,ariaLabel:"i. ii. iii."},{key:"upper-alpha",icon:rr.numberedListUpperAlpha,ariaLabel:"A. B. C."},{key:"upper-alpha-paren",icon:rr.numberedListUpperAlphaParen,ariaLabel:"A) B) C)"},{key:"lower-alpha",icon:rr.numberedListLowerAlpha,ariaLabel:"a. b. c."},{key:"lower-alpha-paren",icon:rr.numberedListLowerAlphaParen,ariaLabel:"a) b) c)"}];xt(),mn();var KB=["onClick","onKeydown"],qB={class:"document-mode-column icon-column"},YB=["innerHTML"],XB={class:"document-mode-column text-column"},ZB={class:"document-mode-type"},QB={class:"document-mode-description"},JB={__name:"DocumentMode",props:{options:{type:Array}},emits:["select"],setup(e,{emit:t}){const n=t,r=te([]),{isHighContrastMode:o}=ts(),i=e,s=d=>{n("select",d)},a=d=>{if(d===r.value.length-1)return;const f=r.value[d+1];f&&(f.setAttribute("tabindex","0"),f.focus())},l=d=>{if(d===0)return;const f=r.value[d-1];f&&(f.setAttribute("tabindex","0"),f.focus())},c=(d,f)=>{switch(d.key){case"ArrowDown":a(f);break;case"ArrowUp":l(f);break;case"Enter":s(i.options[f])}};return Dn(()=>{r.value[0].setAttribute("tabindex","0"),r.value[0].focus()}),(d,f)=>(ge(),Ee("div",{class:on(["document-mode",{"high-contrast":qe(o)}])},[(ge(!0),Ee(Kt,null,tr(e.options,(h,g)=>(ge(),Ee("div",{class:on(["sd-option-item",{"sd-disabled":h.disabled}]),onClick:m=>s(h),"data-item":"btn-documentMode-option",role:"menuitem",ref_for:!0,ref_key:"documentModeRefs",ref:r,onKeydown:tn(m=>c(m,g),["prevent"])},[Ne("div",qB,[Ne("div",{class:"icon-column__icon",innerHTML:h.icon},null,8,YB)]),Ne("div",XB,[Ne("div",ZB,Ht(h.label),1),Ne("div",QB,Ht(h.description),1)])],42,KB))),256))],2))}},ez=fn(JB,[["__scopeId","data-v-bee14d7a"]]);xt(),mn();var tz={class:"linked-style-buttons","data-editor-ui-surface":""},nz=["onClick","onKeydown","aria-label"],rz={__name:"LinkedStyle",props:{styles:{type:Array,default:()=>[]},selectedOption:{type:String,default:null}},emits:["select"],setup(e,{emit:t}){const n=t,r=te([]),o=e,i=f=>{n("select",f)},s=f=>{if(f===r.value.length-1)return;const h=r.value[f+1];h.setAttribute("tabindex","0"),h.focus()},a=f=>{if(f===0)return;const h=r.value[f-1];h.setAttribute("tabindex","0"),h.focus()},l=(f,h,g)=>{switch(f.key){case"ArrowDown":s(h);break;case"ArrowUp":a(h);break;case"Enter":f.preventDefault(),i(g)}},c=f=>f?.name??f?.id??"",d=f=>{const h=f?.preview?.css;return h&&typeof h=="object"?h:void 0};return Dn(()=>{r.value[0]&&(r.value[0].setAttribute("tabindex","0"),r.value[0].focus())}),(f,h)=>(ge(),Ee("div",tz,[(ge(!0),Ee(Kt,null,tr(o.styles,(g,m)=>(ge(),Ee("div",{key:g.id??m,class:on(["style-item",{selected:e.selectedOption===g.id}]),onClick:v=>i(g),onKeydown:v=>l(v,m,g),"aria-label":`Linked style - ${g.id??c(g)}`,ref_for:!0,ref_key:"styleRefs",ref:r},[Ne("div",{class:"style-name","data-item":"btn-linkedStyles-option",style:bn(d(g))},Ht(c(g)),5)],42,nz))),128))]))}},oz=fn(rz,[["__scopeId","data-v-43b5dcca"]]);xt(),mn();var iz=["placeholder"],sz={class:"sd-ai-writer__footer"},az={key:0,class:"sd-ai-writer__error",role:"alert"},lz=["disabled"],cz="https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights",uz="You are an expert copywriter and you are immersed in a document editor. Only write what is asked for.",dz={__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=te(""),r=te(!1),o=te(""),i=te(null),s=Ce(()=>t.selectedText?"Insert prompt to update text":"Insert prompt to generate text"),a=Ce(()=>n.value.trim().length>0&&!r.value);Dn(()=>{At(()=>{i.value?.focus()})});function l(m){if(typeof m=="string")return m;if(!m||typeof m!="object")return"";const v=m.custom_prompt;if(Array.isArray(v)){const _=v[0];if(_&&typeof _.value=="string")return _.value}return v&&typeof v=="object"&&typeof v.value=="string"?v.value:typeof m.value=="string"?m.value:typeof m.text=="string"?m.text:""}async function c(m){const v={"Content-Type":"application/json"};t.apiKey&&(v["x-api-key"]=t.apiKey);const _=t.selectedText.trim(),k=_?`Rewrite the following text: "${_}" using these instructions: ${m}`:`Generate text based on the following prompt: ${m}`,S=await fetch(t.endpoint||cz,{method:"POST",headers:v,body:JSON.stringify({stream:!1,context:uz,insights:[{type:"custom_prompt",name:_?"text_rewrite":"text_generation",message:k,format:[{value:""}]}]})});if(!S.ok){const w=await S.text().catch(()=>"");throw new Error(w||`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 d(m){return!m||typeof m!="object"?!0:!(m.success===!1||m.ok===!1)}function f(m){const v=t.doc;if(!v)throw new Error("Document API is unavailable.");t.restoreSelection?.();let _=null,k=!1;if(t.selectedText&&t.target&&typeof v.replace=="function"?(_=v.replace({target:t.target,text:m}),k=!0):t.target&&typeof v.insert=="function"?(_=v.insert({target:t.target,value:m,type:"text"}),k=!0):typeof v.insert=="function"&&(_=v.insert({value:m,type:"text"}),k=!0),!k)throw new Error("Document text insertion is unavailable.");if(!d(_))throw new Error("Unable to insert generated text.")}async function h(){if(a.value){o.value="",r.value=!0;try{f(await c(n.value.trim())),t.handleClose()}catch(m){o.value=m instanceof Error?m.message:String(m)}finally{r.value=!1}}}function g(m){m.key!=="Enter"||m.shiftKey||(m.preventDefault(),h())}return(m,v)=>(ge(),Ee("form",{class:"sd-ai-writer","data-item":"ai-writer",onSubmit:tn(h,["prevent"])},[na(Ne("textarea",{ref_key:"textareaRef",ref:i,"onUpdate:modelValue":v[0]||(v[0]=_=>n.value=_),class:"sd-ai-writer__input",placeholder:s.value,rows:"4",onKeydown:g},null,40,iz),[[Di,n.value]]),Ne("div",sz,[o.value?(ge(),Ee("p",az,Ht(o.value),1)):gt("",!0),Ne("button",{class:"sd-ai-writer__submit",type:"submit",disabled:!a.value},Ht(r.value?"Generating":"Generate"),9,lz)])],32))}},fz=fn(dz,[["__scopeId","data-v-67f6c6f7"]]);xt(),mn();var hz=["aria-label","onClick","onKeydown"],pz=["innerHTML"],mz=["innerHTML"],sm=7,gz={__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=Ce(()=>m=>r.activeColor.value?r.activeColor.value.toUpperCase()===m.value:!1),i=(m,v)=>v===5||["#FFFFFF","#FAFF09"].includes(m)?{color:"#000"}:{color:"#FFF"},s=m=>{n("select",m.value)},a=te([]),l=te([]);Dn(()=>{if(!r.icons.every(v=>Array.isArray(v)))throw new Error("icon props must be 2d array");const m=l.value[0];m&&(m.setAttribute("tabindex","0"),m.focus({preventScroll:!0}))});const c=(m,v)=>{const _=sm*m+v+1,k=l.value[_];k&&(k.setAttribute("tabindex","0"),k.focus({preventScroll:!0}))},d=(m,v)=>{const _=sm*m+v-1,k=l.value[_];k&&(k.setAttribute("tabindex","0"),k.focus({preventScroll:!0}))},f=(m,v)=>{const _=v+sm*(m+1),k=l.value[_];k&&(k.setAttribute("tabindex","0"),k.focus({preventScroll:!0}))},h=(m,v)=>{const _=v+sm*(m-1),k=l.value[_];k&&(k.setAttribute("tabindex","0"),k.focus({preventScroll:!0}))},g=(m,v,_,k)=>{switch(m.key){case"ArrowRight":c(v,_);break;case"ArrowLeft":d(v,_);break;case"ArrowDown":f(v,_);break;case"ArrowUp":h(v,_);break;case"Enter":s(k);break;case"Escape":n("clickoutside")}};return(m,v)=>(ge(!0),Ee(Kt,null,tr(e.icons,(_,k)=>(ge(),Ee("div",{class:"sd-option-row",key:k,role:"group",ref_for:!0,ref_key:"rowRefs",ref:a},[(ge(!0),Ee(Kt,null,tr(_,(S,y)=>(ge(),Ee("div",{class:"sd-option",key:y,"aria-label":S.label,role:"menuitem",ref_for:!0,ref_key:"iconRefs",ref:l,onClick:tn(w=>s(S),["stop","prevent"]),onKeydown:tn(w=>g(w,k,y,S),["prevent"])},[Ne("div",{class:"sd-option__icon",innerHTML:S.icon,style:bn(S.style)},null,12,pz),o.value(S)?(ge(),Ee("div",{key:0,class:"sd-option__check",innerHTML:qe(rr).colorOptionCheck,style:bn(i(S.value,y))},null,12,mz)):gt("",!0)],40,hz))),128))]))),128))}},rA=fn(gz,[["__scopeId","data-v-05eb02fc"]]),vz=`<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
  `;xt(),mn();var yz={class:"options-grid-wrap"},bz=["innerHTML"],wz={class:"option-grid-ctn"},Cz={__name:"IconGrid",props:{icons:{type:Array,required:!0},customIcons:{type:Array,required:!1},activeColor:{type:Object,required:!1},hasNoneIcon:{type:Boolean,required:!1}},emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=o=>{n("select",o)};return(o,i)=>(ge(),Ee("div",yz,[e.hasNoneIcon?(ge(),Ee("div",{key:0,class:"none-option",role:"menuitem","aria-label":"Clear color selection",onClick:i[0]||(i[0]=s=>r("none"))},[Ne("span",{innerHTML:qe(vz),class:"none-icon"},null,8,bz),i[1]||(i[1]=Zi(" None ",-1))])):gt("",!0),Ne("div",wz,[Yt(rA,{icons:e.icons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"]),e.customIcons.flat().length?(ge(),Ee(Kt,{key:0},[i[2]||(i[2]=Ne("span",{class:"option-grid-ctn__subtitle"},"Custom colors",-1)),Yt(rA,{icons:e.customIcons,"active-color":e.activeColor,onSelect:r},null,8,["icons","active-color"])],64)):gt("",!0)])]))}},kz=fn(Cz,[["__scopeId","data-v-52b0283a"]]);xt();var Sz=e=>{e.expand.value=!1},Gt=(e,t=null)=>({label:t,icon:rr.colorOption,value:e,style:{color:e,boxShadow:"0 0 5px 1px rgba(0, 0, 0, 0.1)",borderRadius:"50%"}}),J0=(e,t,n=[],r=!1)=>{const o=i=>{t.iconColor.value=i,e.emitCommand({item:t,argument:i}),Sz(t),hc(e)};return Wr("div",{},[Wr(kz,{icons:_z,customIcons:n,activeColor:t.iconColor,hasNoneIcon:r,onSelect:o})])},_z=[[Gt("#111111","black"),Gt("#333333","dark gray"),Gt("#5C5C5C","medium gray"),Gt("#858585","light gray"),Gt("#ADADAD","very light gray"),Gt("#D6D6D6","transparent gray"),Gt("#FFFFFF","white")],[Gt("#860028","dark red"),Gt("#D2003F","red"),Gt("#DB3365","coral red"),Gt("#E4668C","light red"),Gt("#ED99B2","pale pink"),Gt("#F6CCD9","transparent pink"),Gt("#FF004D","bright pink")],[Gt("#83015E","dark purple"),Gt("#CD0194","purple"),Gt("#D734A9","orchid"),Gt("#E167BF","light purple"),Gt("#EB99D4","lavender"),Gt("#F5CCEA","transparent pink"),Gt("#FF00A8","neon pink")],[Gt("#8E220A","maroon"),Gt("#DD340F","red-orange"),Gt("#E45C3F","burnt orange"),Gt("#EB856F","peach"),Gt("#F1AE9F","pale peach"),Gt("#F8D6CF","transparent peach"),Gt("#FF7A00","orange")],[Gt("#947D02","olive"),Gt("#E7C302","mustard yellow"),Gt("#ECCF35","yellow"),Gt("#F1DB67","light yellow"),Gt("#F5E79A","very pale yellow"),Gt("#FAF3CC","transparent yellow"),Gt("#FAFF09","neon yellow")],[Gt("#055432","forest green"),Gt("#07834F","green"),Gt("#399C72","medium green"),Gt("#6AB595","light green"),Gt("#9CCDB9","mint"),Gt("#CDE6DC","transparent mint"),Gt("#05F38F","bright teal")],[Gt("#063E7E","navy blue"),Gt("#0A60C5","blue"),Gt("#3B80D1","sky blue"),Gt("#6CA0DC","cornflower blue"),Gt("#9DBFE8","light blue"),Gt("#CEDFF3","very light blue"),Gt("#21c8ce","cyan")],[Gt("#3E027A","deep purple"),Gt("#6103BF","indigo"),Gt("#8136CC","violet"),Gt("#A068D9","lavender pink"),Gt("#C09AE6","light lilac"),Gt("#DFCDF2","transparent lilac"),Gt("#A91DFF","neon purple")]];xt(),mn();var Az=["data-cols","data-rows","onKeydown","onClick"],Iz=["aria-valuetext"],am=5,xz={__name:"TableGrid",emits:["select","clickoutside"],setup(e,{emit:t}){const n=t,r=te(0),o=te(0),{isHighContrastMode:i}=ts(),s=te([]),a=f=>{let h=f.target;if(h.dataset.grid)return;let g=[...h.parentElement.querySelectorAll("[data-item]")],m=parseInt(h.dataset.cols,10),v=parseInt(h.dataset.rows,10);l(g,m,v)},l=(f,h,g)=>{o.value=h,r.value=g;for(let m=0;m<f.length;m++){let v=f[m],_=parseInt(v.dataset.cols,10),k=parseInt(v.dataset.rows,10);_<=h&&k<=g?v.classList.add("sd-selected"):v.classList.remove("sd-selected")}},c=({cols:f,rows:h})=>{n("select",{cols:f,rows:h})},d=(f,h,g)=>{let m=h-1,v=g-1;switch(f.key){case"ArrowRight":{if(m>=4)return;const _=v*am;s.value[_+m+1].setAttribute("tabindex","0"),s.value[_+m+1].focus(),l(s.value,h+1,g);break}case"ArrowLeft":{if(m<=0)return;const _=v*am;s.value[_+m-1].setAttribute("tabindex","0"),s.value[_+m-1].focus(),l(s.value,h-1,g);break}case"ArrowDown":{if(v>=4)return;const _=(v+1)*am;s.value[_+m].setAttribute("tabindex","0"),s.value[_+m].focus(),l(s.value,h,g+1);break}case"ArrowUp":{if(v<=0)return;const _=(v-1)*am;s.value[_+m].setAttribute("tabindex","0"),s.value[_+m].focus(),l(s.value,h,g-1);break}case"Enter":c({cols:h,rows:g})}};return Dn(()=>{s.value[0].setAttribute("tabindex","0"),s.value[0].focus(),l(s.value,1,1)}),(f,h)=>(ge(),Ee("div",{class:on(["toolbar-table-grid-wrapper",{"high-contrast":qe(i)}])},[Ne("div",{class:"toolbar-table-grid",onMouseover:a,"data-grid":"true"},[(ge(),Ee(Kt,null,tr(5,g=>(ge(),Ee(Kt,{key:g},[(ge(),Ee(Kt,null,tr(5,m=>Ne("div",{class:"toolbar-table-grid__item",key:`${g}_${m}`,"data-cols":m,"data-rows":g,"data-item":"true",ref_for:!0,ref_key:"tableGridItems",ref:s,onKeydown:tn(v=>d(v,m,g),["prevent"]),onClick:tn(v=>c({cols:m,rows:g}),["stop","prevent"])},null,40,Az)),64))],64))),64))],32),Ne("div",{class:"toolbar-table-grid-value","aria-valuetext":`${r.value} x ${o.value}`},Ht(r.value)+" x "+Ht(o.value),9,Iz)],2))}},Ez=fn(xz,[["__scopeId","data-v-b87d6ca2"]]);xt(),mn();var Tz={class:"toolbar-table-actions"},Rz=["onClick","data-item","ariaLabel"],Mz={class:"toolbar-table-actions__icon"},Lz=["innerHTML"],Pz={class:"toolbar-table-actions__label"},Dz={__name:"TableActions",props:{options:{type:Array}},emits:["select"],setup(e,{emit:t}){const n=t,r=o=>{n("select",{command:o.command})};return(o,i)=>(ge(),Ee("div",Tz,[(ge(!0),Ee(Kt,null,tr(e.options,s=>(ge(),Ee("div",{class:on(["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"},[Ne("div",Mz,[Ne("div",{class:"toolbar-table-actions__icon-wrapper",innerHTML:s.icon},null,8,Lz)]),Ne("div",Pz,Ht(s.label),1)],10,Rz))),256))]))}},Oz=fn(Dz,[["__scopeId","data-v-0cdad084"]]),Fz=`<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
- `;xt();var Bs=e=>{e.expand.value=!1};function e2(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function oA(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 Nz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function iA(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Bz(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function zz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}var Vz=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=In({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),c=(r??LB).map(zB),d=In({type:"dropdown",name:"fontFamily",tooltip:n.fontFamily,command:"setFontFamily",defaultLabel:"Arial",label:"Arial",markName:"textStyle",labelAttr:"fontFamily",hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,isWide:!0,style:{width:"116px"},suppressActiveHighlight:!0,attributes:{ariaLabel:"Font family"},options:c,onActivate:({fontFamily:nt}={},Rt=!1)=>{if(Rt){d.label.value="",d.selectedValue.value="";return}if(!nt)return;nt=nt.split(",")[0],d.label.value=nt;const jt=c.find(Qt=>Qt.label===d.defaultLabel.value),$t=c.find(Qt=>Qt.label===nt);$t?d.selectedValue.value=$t.key:jt?d.selectedValue.value=jt.key:d.selectedValue.value=""},onDeactivate:()=>{d.label.value=d.defaultLabel.value;const nt=c.find(Rt=>Rt.label===d.defaultLabel.value);nt?d.selectedValue.value=nt.key:d.selectedValue.value=""}}),f=In({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(f)}]});function h(nt){const Rt=iA(e),jt=Rt?.selectionTarget??oA(Rt?.target),$t=Rt?.empty?"":Nz(Rt),Qt=zz(e),Fn=()=>Bs(nt),kn=()=>{const Vo=e.pendingSelectionCapture;Vo&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Vo)};return Wr("div",{},[Wr(fz,{handleClose:Fn,selectedText:$t,target:jt,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Qt?.apiKey||e.config?.aiApiKey||"",endpoint:Qt?.endpoint||e.config?.aiEndpoint||"",restoreSelection:kn})])}const g=DB,m=In({type:"dropdown",name:"fontSize",defaultLabel:"12",label:"12",style:{width:"56px"},markName:"textStyle",labelAttr:"fontSize",tooltip:n.fontSize,hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,suppressActiveHighlight:!0,isWide:!0,command:"setFontSize",attributes:{ariaLabel:"Font size"},options:g,onActivate:({fontSize:nt},Rt=!1)=>{if(Rt){m.label.value="",m.selectedValue.value="";return}const jt=g.find(kn=>kn.label===String(m.defaultLabel.value));if(!nt){m.label.value=m.defaultLabel.value,jt?m.selectedValue.value=jt.key:m.selectedValue.value="";return}let $t=_N(nt,12);$t<8&&($t=8),$t>96&&($t=96);let Qt=String($t);const Fn=g.find(kn=>kn.label===Qt||kn.key===Qt);Fn?m.selectedValue.value=Fn.key:m.selectedValue.value="",m.label.value=Qt},onDeactivate:()=>{m.label.value=m.defaultLabel.value;const nt=g.find(Rt=>Rt.label===String(m.defaultLabel.value));nt?m.selectedValue.value=nt.key:m.selectedValue.value=""}}),v=In({type:"separator",name:"separator",isNarrow:!0}),_=In({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),k=In({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),S=In({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=In({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:()=>J0(e,y,[],!0)}],onActivate:({color:nt})=>{y.iconColor.value=nt||""},onDeactivate:()=>y.iconColor.value=""}),w=In({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:()=>J0(e,w)}],onActivate:({color:nt})=>{w.iconColor.value=nt},onDeactivate:()=>w.iconColor.value="#000"}),T=In({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),L=In({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>O(L)}],onActivate:({href:nt})=>{L.attributes.value=e2(L.attributes.value,nt)},onDeactivate:()=>{L.attributes.value=e2(L.attributes.value,null),L.expand.value=!1}});function O(nt){const Rt=iA(e),jt=Rt?.selectionTarget??oA(Rt?.target),$t=()=>{const Qt=e.pendingSelectionCapture;Qt&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Qt)};return Wr("div",{},[Wr(TS,{ui:e.ui,linkItem:nt,textTarget:jt,restoreSelection:$t,closePopover:()=>{Bs(nt),hc(e)},goToAnchor:()=>{Bs(nt);const Qt=nt.attributes.value?.href;if(!Qt)return;const Fn=Qt.slice(1),kn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${Fn}']`);kn&&RS(kn)}})])}const U=In({type:"options",name:"linkInput",command:"toggleLink",active:!1});L.childItem=U,U.parentItem=L;const P=In({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),B=In({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),z=In({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:()=>R(z)}]});function R(nt){return Wr("div",{},[Wr(Ez,{onSelect:jt=>{e.emitCommand({item:nt,argument:jt}),Bs(nt),hc(e)}})])}const H=In({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>$(H)}]}),E=[{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 $(nt){return Wr(Oz,{options:E,onSelect:Rt=>{Bs(nt);const{command:jt}=Rt;e.emitCommand({item:nt,argument:{command:jt}}),hc(e)}})}const Q=In({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:()=>Wr("div",{},[Wr(UB,{onSelect:Rt=>{Bs(Q);const jt={...Q,command:"setTextAlign"};jt.command="setTextAlign",e.emitCommand({item:jt,argument:Rt}),ie(Q,Rt),hc(e)}})]),key:"alignment"}],onActivate:({textAlign:nt})=>{ie(Q,nt)},onDeactivate:()=>{ie(Q,"left")}}),ie=(nt,Rt)=>{let jt=Rt==="both"?"justify":Rt,$t={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Qt=$t[jt]??$t.left;nt.icon.value=Qt},ee=In({type:"dropdown",name:"list",command:"toggleBulletListStyle",splitButton:!0,splitButtonCommand:"toggleBulletList",icon:t.bulletList,hasCaret:!0,tooltip:n.bulletList,restoreEditorFocus:!0,attributes:{ariaLabel:"Bullet list"},options:[{type:"render",key:"bullet-style-buttons",render:()=>{const nt=Rt=>{Bs(ee);const jt={...ee,command:"toggleBulletListStyle"};e.emitCommand({item:jt,argument:Rt})};return Wr(nA,{buttons:GB,iconSize:25,selectedStyle:ee.selectedValue.value,onSelect:nt})}}]}),ne=In({type:"dropdown",name:"numberedlist",command:"toggleOrderedListStyle",splitButton:!0,splitButtonCommand:"toggleOrderedList",icon:t.numberedList,hasCaret:!0,tooltip:n.numberedList,restoreEditorFocus:!0,attributes:{ariaLabel:"Numbered list"},options:[{type:"render",key:"numbered-style-buttons",render:()=>{const nt=Rt=>{Bs(ne);const jt={...ne,command:"toggleOrderedListStyle"};e.emitCommand({item:jt,argument:Rt})};return Wr(nA,{buttons:WB,iconSize:30,selectedStyle:ne.selectedValue.value,onSelect:nt})}}]}),Ie=In({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),pe=In({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ye=In({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ve=In({type:"dropdown",name:"zoom",allowWithoutEditor:!0,tooltip:n.zoom,defaultLabel:"100%",label:"100%",hasCaret:!0,command:"setZoom",isWide:!0,style:{width:"71px",minWidth:"71px"},inlineTextInputVisible:!1,hasInlineTextInput:!0,attributes:{ariaLabel:"Zoom"},options:[{label:"50%",key:.5,props:{"data-item":"btn-zoom-option"}},{label:"75%",key:.75,props:{"data-item":"btn-zoom-option"}},{label:"90%",key:.9,props:{"data-item":"btn-zoom-option"}},{label:"100%",key:1,props:{"data-item":"btn-zoom-option"}},{label:"125%",key:1.25,props:{"data-item":"btn-zoom-option"}},{label:"150%",key:1.5,props:{"data-item":"btn-zoom-option"}},{label:"200%",key:2,props:{"data-item":"btn-zoom-option"}}],onActivate:({zoom:nt})=>{nt&&(ve.label.value=nt)}}),Se=In({type:"dropdown",name:"measurementUnit",allowWithoutEditor:!0,tooltip:n.measurementUnit,defaultLabel:"in",label:"in",hasCaret:!0,command:"setMeasurementUnit",group:"right",style:{width:"52px",minWidth:"52px"},inlineTextInputVisible:!1,hasInlineTextInput:!1,attributes:{ariaLabel:"Measurement unit"},options:[{label:"Inches",key:"in",props:{"data-item":"btn-measurement-unit-option"}},{label:"Centimeters",key:"cm",props:{"data-item":"btn-measurement-unit-option"}}],onActivate:({measurementUnit:nt})=>{nt&&(Se.label.value=nt)}}),le=In({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Oe=In({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),He=In({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),it=In({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),yt=In({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),De=In({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),$e=(nt,Rt)=>nt==="editor"?Rt:nt==="suggester"?Rt.filter(jt=>jt.value==="suggesting"):Rt.filter(jt=>jt.value==="viewing"),Ye=nt=>nt==="editor"?"Editing":nt==="suggester"?"Suggesting":"Viewing",J=In({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:Ye(s),label:Ye(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:()=>re(J)}]}),C=[{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 re(nt){const Rt=$e(s,C);return Wr(ez,{options:Rt,onSelect:jt=>{const $t=e.superdoc?.activeEditor??e.activeEditor;Bs(nt);const{label:Qt,icon:Fn,value:kn}=jt;J.label.value=Qt,J.icon.value=Fn,e.emitCommand({item:J,argument:kn}),hc(e,$t)}})}const V=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),D=["search","ruler","undo","overflow","documentMode"],j=In({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),W=In({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),Y=In({type:"dropdown",name:"linkedStyles",command:"setLinkedStyle",tooltip:n.linkedStyles,icon:t.paintbrush,defaultLabel:n.formatText,label:n.formatText,hasCaret:!0,isWide:!0,style:{width:"140px"},suppressActiveHighlight:!0,disabled:!1,attributes:{className:"sd-toolbar-item--linked-styles",ariaLabel:"Linked styles"},options:[{type:"render",key:"linkedStyle",render:()=>{const nt=jt=>{Bs(Y);const $t=typeof jt=="string"?jt:jt?.id??null;if(!$t)return;const Qt={...Y,command:"setLinkedStyle"};e.emitCommand({item:Qt,argument:$t})},Rt=e.getActiveLinkedStyleId?.()??null;return Wr("div",{},[Wr(oz,{styles:e.getLinkedStyleOptions?.()??[],onSelect:nt,selectedOption:Rt})])}}],onActivate:({styleId:nt,styleName:Rt})=>{const jt=Rt||nt;Y.label.value=nt&&nt!=="Normal"?String(jt):n.formatText,Y.disabled.value=!1},onDeactivate:()=>{Y.disabled.value=!0,Y.label.value=n.formatText}}),Z=(nt,Rt)=>{if(Rt.value==nt)return Wr("div",{innerHTML:Fz,class:"dropdown-select-icon"})},q=In({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,restoreEditorFocus:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(nt=>({label:nt.toFixed(2),key:nt,icon:()=>Z(nt,q.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),me=20,Te=32,_e=D.reduce((nt,Rt)=>nt+(V.get(Rt)||V.get("default")),0),xe=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],We=["zoom","fontFamily","fontSize","redo"],tt=i<=Mf.lg,at=e.config?.showFormattingMarksButton===!0,Ut=e.config?.showTableOfContentsButton===!0;tt&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),tt&&(Y.attributes.value={...Y.attributes.value,className:`${Y.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let Ct=[le,Oe,He,it,T,ve,d,v,m,v,l,_,k,S,w,y,v,L,P,...Ut?[B]:[],z,H,v,Q,ee,ne,Ie,pe,q,v,Y,v,j,Se,...at?[W]:[],De,yt,...Bz(e)?[f]:[],ye,J];if(i<=Mf.md&&o&&(Ct=Ct.filter(nt=>nt.type!=="separator")),e.config.mode!=="docx"){const nt=Ct.findIndex(jt=>jt.name.value==="linkedStyles");Ct.splice(nt-1,2);const Rt=["ruler","zoom","undo","redo"];Ct=Ct.filter(jt=>!Rt.includes(jt.name.value))}const Je=[];a||(s==="viewer"&&Je.push(He,it),Ct=Ct.filter(nt=>!Je.includes(nt)));const Vt=nt=>D.includes(nt.name.value),nn=[],Ln=[];let Zt=Te+_e;return Ct.forEach(nt=>{const Rt=V.get(nt.name.value)||V.get("default");if(i<Mf.xl+me&&xe.includes(nt.name.value)&&o){if(nn.push(nt),nt.name.value==="linkedStyles"){const jt=Ct.findIndex($t=>$t.name.value==="linkedStyles");Ct.splice(jt+1,1)}return}if(i<Mf.sm&&We.includes(nt.name.value)&&o){nn.push(nt);return}if(Vt(nt)){Ln.push(nt),Zt+=Rt;return}Zt<i||!o?(Ln.push(nt),Zt+=Rt):nn.push(nt)}),{defaultItems:Ln,overflowItems:nn.filter(nt=>nt.type!=="separator")}},sA={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"},jz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;xt();function aA(e){return gN(e)??Q0[e]??null}function lm(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 Uz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Hz=new Set(["list","numberedlist"]);function $z(e,t){if(e==="fontFamily"||e==="fontSize"||Hz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Uz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function lA(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Gz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var Wz=class extends Km.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...rr},texts:{...sA},fonts:null,hideButtons:!0,responsiveToContainer:!1,mode:"docx",excludeItems:[],groups:null,customButtons:[],showFormattingMarksButton:!1,showTableOfContentsButton:!1};toolbarItems=[];overflowItems=[];#e=null;#n=null;isDev=!1;role="editor";superdoc;toolbarContainer=null;toolbar=null;_detachFontsChanged=null;constructor(e={}){if(super(),this.config={...this.config,...e},this.toolbarItems=[],this.overflowItems=[],this.isDev=e.isDev||!1,this.superdoc=e.superdoc,this.role=e.role||"editor",this.toolbarContainer=null,this.config.icons={...rr,...e.icons},this.config.texts={...sA,...e.texts},this.config.hideButtons=e.hideButtons??!0,this.config.responsiveToContainer=e.responsiveToContainer??!1,this.activeEditor=e.editor??this.superdoc?.activeEditor??null,this.ui=null,this.snapshot=null,this._unsubscribeController=null,this._detachFormatPainterModeChange=null,this._customCommandRegs=new Map,this._reportedInvalidCustomItems=new Set,this._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=jz(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.#t(),this.#d(),this.#f(),this.#i(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Jl(BB),this.app.directive("click-outside",Xv),this.app.config.globalProperties.$toolbar=this,this.toolbar=this.app.mount(this.toolbarContainer),this.updateToolbarState()}catch(t){try{this.destroy()}catch{}throw t}}#t(){this.ui=this.superdoc?.ui??null,this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot(),this._unsubscribeController=this.ui.toolbar.subscribe(()=>{this.snapshot=this.ui.toolbar.getSnapshot(),this.updateToolbarState()}),this._detachFormatPainterModeChange=this.ui.formatPainter.onModeChange(e=>{e==="armed"||e==="persistent"?this.#a():this.#S()}))}#r(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#S();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#i(){if(!this.superdoc||typeof this.superdoc.on!="function"||typeof this.superdoc.off!="function")return;const e=()=>{const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#s(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#d(){if(Array.isArray(this.config.groups)){this.config.toolbarGroups=this.config.groups,this.config.groups=null;return}this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length&&(this.config.toolbarGroups=Object.keys(this.config.groups))}getAvailableWidth(){const e=document.documentElement.clientWidth,t=this.toolbarContainer?.offsetWidth??0;return this.config.responsiveToContainer?t:e}#h(e){if(e)return e;const t=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return PB(t)}#f(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=Vz({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#h(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=new Set([...n,...r].map(c=>c.name?.value).filter(Boolean)),s=o.map((c,d)=>{try{if(c?.name&&i.has(c.name))throw new Error(`Toolbar item name "${c.name}" is already taken by another item, so this entry is skipped.`);const f=this.#c(c);return i.add(f.name?.value),f}catch(f){const h=`${c?.name??`<unnamed@${d}>`}::${f?.message??String(f)}`;return this._reportedInvalidCustomItems.has(h)||(this._reportedInvalidCustomItems.add(h),this.#b(f,c?.name??null)),null}}).filter(Boolean);s.length&&n.push(...s);let a=[...n.map(c=>c.name.value),...r.map(c=>c.name.value)];if(t){const c=Object.values(this.config.groups).flatMap(h=>h),d=new Set(Object.keys(this.config.groups)),f=s.filter(h=>d.has(h.group?.value||"center")).map(h=>h.name.value);a=[...new Set([...c,...f])]}const l=n.filter(c=>a.includes(c.name.value)).filter(c=>!this.config.excludeItems.includes(c.name.value));if(t)for(const[c,d]of Object.entries(this.config.groups))for(const f of l)d.includes(f.name.value)&&(f.group.value=c);this.toolbarItems=l,this.overflowItems=r.filter(c=>a.includes(c.name.value))}#c(e){const t=In({...e});t.isCustomToolbarItem=!0;const n=e.command;if(typeof n=="function"&&this.ui?.commands?.register){const r=`__builtin_toolbar__${e.name}`;if(!this._customCommandRegs.has(r)){const o=this.ui.commands.register({id:r,execute:i=>{const s=i?.payload&&typeof i.payload=="object"?i.payload:{};return n({...i,item:t,argument:s.argument,option:s.option})}});this._customCommandRegs.set(r,o)}}return t}#p(){this.#f(),this.emit("toolbar-items-changed")}#o(){if(this.config.fonts)return"custom-fonts";const e=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return JSON.stringify(e.map(t=>[t.label,t.value,t.previewFamily]))}getToolbarItemByGroup(e){return this.toolbarItems.filter(t=>(t.group?.value||"center")===e)}getToolbarItemByName(e){return this.#l().find(t=>t.name.value===e)}#l(){return[...this.toolbarItems,...this.overflowItems]}getLinkedStyleOptions(){return this.ui?.styles?.getQuickGallery?.()??[]}getActiveLinkedStyleId(){return this.ui?.styles?.getActiveParagraphStyle?.()?.styleId??null}setActiveEditor(e){this.activeEditor=e;const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#f(),this.updateToolbarState()};#g(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#u(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#y(){const e=this.getToolbarItemByName("documentMode");if(!e)return;const t=(this.snapshot?.commands?.["document-mode"]?.value||"editing").toLowerCase(),n=this.config.texts||{},r=this.config.icons||{},o={editing:{label:n.documentEditingMode||"Editing",icon:r.documentEditingMode||r.documentMode},suggesting:{label:n.documentSuggestingMode||"Suggesting",icon:r.documentSuggestingMode||r.documentMode},viewing:{label:n.documentViewingMode||"Viewing",icon:r.documentViewingMode||r.documentMode}},i=o[t]||o.editing;e.label?.value!==void 0&&(e.label.value=i.label),e.defaultLabel?.value!==void 0&&(e.defaultLabel.value=i.label),e.icon?.value!==void 0&&i.icon&&(e.icon.value=i.icon)}#w(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>J0(this,e,[],!0)};e.nestedOptions.value=[t]}#k(e){return!!e?.active&&e?.value==null}#I(e){return!!e&&e.disabled===!1&&e.value==null}#x(e){const t=e.name.value;if(t==="tableActions"){const i=tA.map(s=>this.snapshot?.commands?.[s]).some(s=>s&&!s.disabled);return e.setDisabled(!i),!0}if(t==="search")return e.setDisabled(this.superdoc?.uiConfig?.search?.enabled!==!0),!0;if(X0(t)?.disposition==="host-routed")return e.setDisabled(!this.#u(t)),this.#g(t)?e.activate():e.deactivate(),!0;const n=aA(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];$z(t,r)?e.setDisabled(!1):e.setDisabled(!!r?.disabled);const o={textAlign:()=>{r?.value?e.activate({textAlign:r.value}):e.deactivate()},lineHeight:()=>{e.selectedValue.value=r?.value!=null?r.value:""},zoom:()=>{if(r?.value!=null){const i=typeof r.value=="number"?`${r.value}%`:String(r.value);e.onActivate({zoom:i})}},measurementUnit:()=>{r?.value!=null&&e.onActivate({measurementUnit:String(r.value)})},documentMode:()=>{this.#y()},link:()=>{e.active.value=!!r?.active,e.attributes.value=e2(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#I(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#k(r)){e.activate({},!0);return}e.deactivate()},color:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},highlight:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},linkedStyles:()=>{const i=r?.value,s=typeof i=="string"?i:i?.styleId,a=i&&typeof i=="object"?i.styleName:null;s?e.activate({styleId:s,styleName:a}):e.label.value=this.config.texts?.formatText||"Format text"},list:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},numberedlist:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},default:()=>{r?.active?e.activate():e.deactivate()}};return(o[t]??o.default)(),!0}updateToolbarState(){this.#y(),this.#w();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#L(),this.#l().forEach(n=>{n.allowWithoutEditor?.value&&this.#x(n)})):this.#l().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")}#L(){this.#l().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#P(e,t){const n=this.superdoc;if(e==="ruler")return typeof n?.toggleRuler=="function"?(n.toggleRuler(),!0):!1;if(e==="formattingMarks"){if(typeof t=="boolean"&&typeof n?.setShowFormattingMarks=="function")return n.setShowFormattingMarks(t),!0;if(typeof n?.toggleFormattingMarks=="function")return n.toggleFormattingMarks(),!0}return!1}#D(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#b(i,n)};if(n==="image"&&t==null)return this.#E();if(n==="tableActions"){const i=eA[t?.command];return i?lm(this.ui,i,void 0,r):!1}if(X0(n)?.disposition==="unsupported")return!0;const o=aA(n);return o?lm(this.ui,o,t,r):!1}#E(){return this.snapshot?.commands?.image?.disabled||(this.#e||(this.#e=SN({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await CN(e,this.superdoc?.config?.handleImageUpload);lm(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#b(n,"image")})},onError:e=>this.#b(e,"image")})),this.#e.open()),!0}#a(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{lA(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!lA(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Gz(i)&&this.ui.formatPainter.setKeyboardSelecting(!0)},o=()=>{this.ui.formatPainter.setKeyboardSelecting(!1),this.ui.formatPainter.notifyKeyUp()};e.addEventListener("pointerdown",t),e.addEventListener("pointerup",n),e.addEventListener("keydown",r),e.addEventListener("keyup",o),this.#n=()=>{e.removeEventListener("pointerdown",t),e.removeEventListener("pointerup",n),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}}#S(){this.#n&&(this.#n(),this.#n=null)}#b(e,t){const n={error:e instanceof Error?e:new Error(String(e)),originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null},r={...n};this.emit("exception",n),this.superdoc?.emit?.("exception",r)}emitCommand({item:e,argument:t,option:n}){const r=e?.name?.value,{command:o}=e,i=t!=null;if(!(e?.type==="dropdown"&&!i&&(o==="setFontFamily"||o==="setFontSize"))){if(r==="search"){this.superdoc?.emit?.("search:open");return}try{if(X0(r)?.disposition==="host-routed"){this.#P(r,t),this.updateToolbarState();return}if(typeof o=="function"){const s=`__builtin_toolbar__${r}`;this._customCommandRegs.has(s)&&this.ui?.commands?.execute?this.ui.commands.execute(s,{argument:t,option:n}):o({item:e,argument:t,option:n,ui:this.ui,superdoc:this.superdoc}),this.updateToolbarState();return}if(e?.isCustomToolbarItem&&typeof o=="string"){if(!lm(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#b(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#D(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#b(s,r)}}}destroy(){this.#S(),this.#e?.destroy(),this.#e=null,this.#s(),this.#r(),this.app?.unmount(),this.app=null,this.toolbar=null}};function Kz(e){return new Wz(e)}function qz(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 Yz(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=cm(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=Zz(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=Xz(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=Qz(e.border);return i&&(t.border=i),t}function cm(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function Xz(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 Zz(e){if(!e)return;const t={},n=cm(e.fill);n!=null&&(t.fill=n);const r=cm(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function Qz(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=cm(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function pc(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}var Jz=new Set(["insert-text","replace-text","plain-text-paste","delete-backward","delete-forward","text.insert","text.replace","text.pastePlain","text.deleteBackward","text.deleteForward","structural.enter","structural:enter-split-paragraph","structural:enter-insert-paragraph-before","structural:enter-insert-paragraph-after","structural:shift-enter-line-break","structural:backspace-boundary-merge-with-previous","structural:delete-boundary-merge-with-next","backspace:boundary-merge-with-previous","backspace:list-remove","backspace:list-outdent"]),eV=e=>e?.type!=="mutation:committed"||e.origin!=="command"?!1:Jz.has(e.editableCommandKind);function cA(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function tV(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 cA(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function uA(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=tV(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const m of a){const v=`trackedChange:${m}`;if(!r.has(v)){r.add(v);const _={type:"trackedChange",id:m};l&&(_.storyKey=l),n.push(_),o.push(_)}}const c=s.getAttribute("data-layout-story");if(c&&o.length>0){for(const m of o)m.story=c;o=[]}const d=s.getAttribute("data-citation-id");if(d){const m=`citation:${d}`;r.has(m)||(r.add(m),n.push({type:"citation",id:d}))}const f=s.getAttribute("data-comment-ids");if(f)for(const m of cA(f)){const v=`comment:${m}`;r.has(v)||(r.add(v),n.push({type:"comment",id:m}))}const h=s.getAttribute("data-sdt-type"),g=s.getAttribute("data-sdt-id");if(g&&h==="structuredContent"){const m=`contentControl:${g}`;if(!r.has(m)){r.add(m);const v=s.getAttribute("data-sdt-scope"),_=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:g};(v==="block"||v==="inline")&&(k.scope=v),_&&(k.tag=_),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}var po=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),yl=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),Iu=()=>({oneOf:[{type:"number"},{type:"null"}]}),xu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),nV={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},rV={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},oV=()=>({oneOf:[{type:"boolean"},{type:"null"},nV]}),iV=()=>({oneOf:[{type:"array",items:rV,minItems:1},{type:"null"}]});function um(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function sV(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var t2=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:um(n),schema:po()}),mc=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:um("textStyle",o??e),schema:r}),Un=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:sV(o??e),schema:r}),dm=[t2("bold","w:b","bold"),t2("italic","w:i","italic"),t2("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:um("underline"),schema:oV()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:um("highlight"),schema:yl()},mc("color","string","w:color",yl()),mc("fontSize","number","w:sz",Iu()),mc("fontFamily","string","w:rFonts",yl()),mc("letterSpacing","number","w:spacing",Iu()),mc("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),mc("position","number","w:position",Iu()),Un("dstrike","boolean","w:dstrike",po()),Un("smallCaps","boolean","w:smallCaps",po()),mc("caps","boolean","w:caps",po(),"textTransform"),Un("shading","object","w:shd",xu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("border","object","w:bdr",xu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},sz:{oneOf:[{type:"number"},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},space:{oneOf:[{type:"number"},{type:"null"}]}}),"borders"),Un("outline","boolean","w:outline",po()),Un("shadow","boolean","w:shadow",po()),Un("emboss","boolean","w:emboss",po()),Un("imprint","boolean","w:imprint",po()),Un("charScale","number","w:w",Iu(),"w"),Un("kerning","number","w:kern",Iu(),"kern"),Un("vanish","boolean","w:vanish",po()),Un("webHidden","boolean","w:webHidden",po()),Un("specVanish","boolean","w:specVanish",po()),Un("rtl","boolean","w:rtl",po()),Un("cs","boolean","w:cs",po()),Un("bCs","boolean","w:bCs",po(),"boldCs"),Un("iCs","boolean","w:iCs",po(),"italicCs"),Un("eastAsianLayout","object","w:eastAsianLayout",xu({id:{oneOf:[{type:"string",minLength:1},{type:"null"}]},combine:{oneOf:[{type:"boolean"},{type:"null"}]},combineBrackets:{oneOf:[{type:"string",minLength:1},{type:"null"}]},vert:{oneOf:[{type:"boolean"},{type:"null"}]},vertCompress:{oneOf:[{type:"boolean"},{type:"null"}]}})),Un("em","string","w:em",yl()),Un("fitText","object","w:fitText",xu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("snapToGrid","boolean","w:snapToGrid",po()),Un("lang","object","w:lang",xu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("oMath","boolean","w:oMath",po()),Un("rStyle","string","w:rStyle",yl(),"styleId"),Un("rFonts","object","w:rFonts",xu({ascii:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsi:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},cs:{oneOf:[{type:"string",minLength:1},{type:"null"}]},asciiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsiaTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},csTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hint:{oneOf:[{type:"string",minLength:1},{type:"null"}]}}),"fontFamily"),Un("fontSizeCs","number","w:szCs",Iu()),Un("ligatures","string","w14:ligatures",yl()),Un("numForm","string","w14:numForm",yl()),Un("numSpacing","string","w14:numSpacing",yl()),Un("stylisticSets","array","w14:stylisticSets",iV()),Un("contextualAlternates","boolean","w14:cntxtAlts",po())],GH=new Set(dm.map(e=>e.key)),aV=Object.fromEntries(dm.map(e=>[e.key,e])),WH={mark:dm.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:dm.filter(e=>e.storage==="runAttribute").map(e=>e.key)};function _a(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function fm(){const e=globalThis;return{sink:typeof e.__superdocV2BenchPipelineTiming=="function"?e.__superdocV2BenchPipelineTiming:null,workerContext:e.__superdocV2BenchWorkerMessageContext??null}}function n2(e){const{sink:t}=fm();if(t)try{t(e)}catch{}}var r2=new WeakMap;function lV(e){let t=r2.get(e);return t||(t={refCount:0,generation:0,abortController:new AbortController,inFlight:null,activeMutationTokens:new Set},r2.set(e,t)),t.refCount+=1,t}function cV(e,t){t.refCount=Math.max(0,t.refCount-1),!(t.refCount>0)&&(t.abortController.abort("ui-controller-destroyed"),t.inFlight=null,t.activeMutationTokens.clear(),r2.delete(e))}var uV=new Set(Object.values(ut));function o2(e,t){return typeof e=="string"&&uV.has(e)?e:t}function dA(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:ut.notReady}:{ok:!1,reason:o2(t,ut.targetUnresolved)}}return{ok:!0}}var dV=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],fV={[H4.bulletList]:"bullet",[H4.numberedList]:"ordered"};function fA(e){return fV[e]??null}var hV={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 pV(e){const t=hV[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var mV={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""},gV=[{key:"contentControls",match:"exact",note:"full-document SDT catalog parse (the measured during-load cliff)"},{key:"contentControls:inRange:",match:"prefix",note:"same adapter load() as the catalog, issued per settled selection"},{key:"hyperlinks:",match:"prefix",note:"per-block hyperlink list over the loading story"},{key:"styles:catalog:",match:"prefix",note:"WordStyleModel recompile from package bytes"},{key:"comments",match:"exact",note:"audited: full comments list; stale-served during load"},{key:"trackChanges",match:"exact",note:"audited: shared all-story tracked-changes catalog; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: current-token validation over the shared all-story catalog; consumers fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}],vV=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function yV(e){return gV.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var hA={ready:0,stale:1,pending:2};function bl(...e){let t="ready";for(const n of e)hA[n]>hA[t]&&(t=n);return t}function Mt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Ir(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function pr(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 Kn(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Lf(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 Pf(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function i2(e){if(!e||typeof e!="object")return!1;const t=e,n=i=>{if(!i||typeof i!="object")return!1;const s=i;return s.kind==="text"&&typeof s.blockId=="string"&&typeof s.offset=="number"},r=i=>{if(!i||typeof i!="object")return!1;const s=i,a=s.range;return typeof s.blockId=="string"&&typeof a?.start=="number"&&typeof a.end=="number"};if(Array.isArray(t.segments)){const i=t.segments[0],s=t.segments[t.segments.length-1];return r(i)&&r(s)}if(t.kind==="selection")return n(t.start)&&n(t.end);if(t.kind!=="text"||typeof t.blockId!="string")return!1;const o=t.range;return typeof o?.start=="number"&&typeof o.end=="number"}function pA(e,t){if(!e||typeof e!="object")return null;const n=Pf(e),r=e,o=r.navigationTarget&&typeof r.navigationTarget=="object"?r.navigationTarget:null;if(o?.kind==="block"&&typeof o.blockId=="string"&&o.blockId.length>0){const i={kind:"text",blockId:o.blockId,range:{start:0,end:0},...o.story&&typeof o.story=="object"?{story:o.story}:{},...r.address&&typeof r.address=="object"?{address:r.address}:{}};if(t?.preferStableBlock||!i2(n))return i}return n}function wr(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 Df(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=Pf(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 Ni(e,t,n){return ro(e)!==t?!1:n?wr(Df(e))===wr(n):!0}function hm(e){const t=Df(e);if(!(!t||wr(t)===wr(null)))return t}function bV(e){if(typeof e!="string"||e.length===0)return;const t=I6(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 wV(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 s2(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function pm(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function CV(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 ro(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 kV(e){if(!e||typeof e!="object")return null;const t=e,n=t.anchor,r=t.focus,o=n?.visualCaret,i=r?.visualCaret,s=o?.trackChangeId,a=i?.trackChangeId;return typeof s=="string"&&s.length>0&&s===a?s:null}var mA=new WeakMap;function gA(e){const t=[],n=i=>{typeof i=="string"&&i.length>0&&!t.includes(i)&&t.push(i)},r=i=>{if(!i||typeof i!="object")return;const s=i,a=s.sourceIds;if(a&&typeof a=="object"&&(n(a.wordIdInsert),n(a.wordIdDelete),Array.isArray(a.wordIdOther)))for(const f of a.wordIdOther)n(f);const l=s.wordRevisionIds;l&&typeof l=="object"&&(n(l.insert),n(l.delete),n(l.format));const c=s.replacement;if(c&&typeof c=="object")for(const f of[c.inserted,c.deleted])f&&typeof f=="object"&&(n(f.id),n(f.wordId));const d=s.move;if(d&&typeof d=="object")for(const f of[d.source,d.destination])f&&typeof f=="object"&&(n(f.id),n(f.wordId))};r(e);const o=e?.change;return o&&o!==e&&r(o),t}function zs(e){const t=mA.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=ro(i);if(s){n.add(s);for(const a of gA(i)){r.has(a)||r.set(a,s);const l=`imported:${a}`;r.has(l)||r.set(l,s)}}}const o={toPublicId(i){if(n.has(i))return i;const s=r.get(i);return s!=null&&n.has(s)?s:null},aliasesFor(i){const s=[i];for(const[a,l]of r)l===i&&!s.includes(a)&&s.push(a);return s}};return mA.set(e,o),o}var vA=new WeakMap,yA=new WeakMap;function gc(e,t){const n=wr(t);let r=vA.get(e);r||(r=new Map,vA.set(e,r));const o=r.get(n);if(o)return o;const i=zs(e.filter(s=>wr(Df(s))===n));return r.set(n,i),i}function SV(e){return!!e&&typeof e=="object"&&e.storyType==="textbox"}function _V(e,t){const n=t.filter(o=>e.some(i=>ro(i)===o&&Df(i)==null));if(n.length===0)return null;if(n.length===1)return n[0];const r=new Set;for(const o of n){const i=e.find(s=>ro(s)===o);if(i)for(const s of gA(i)){if(r.has(s))return null;r.add(s)}}return n[0]}function AV(e){const t=yA.get(e);if(t)return t;const n=e.filter(o=>Df(o)!=null),r=n.length===e.length?e:n;return yA.set(e,r),r}function IV(e){const{selectionIds:t,publicIds:n,selection:r,bodyItems:o,allStoryItems:i}=e;if(t.length===0)return null;const s=c=>{for(const d of t){const f=c.toPublicId(d);if(f)return f}return null},a=ss(r),l=wr(a)===wr(null);if(i){const c=l?AV(i):i,d=s(gc(c,a));if(d)return d;const f=n?.find(h=>c.some(g=>Ni(g,h,a)));return f||(l?s(zs(o)):SV(a)?_V(i,t):null)}return l?s(zs(o))??t[0]??null:null}function xV(e,t){const n=e.find(r=>ro(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??ro(n)??t:null}function EV(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,c=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:c??l}}const n=e.target,r=n&&Array.isArray(n.segments)?n.segments:[],o=r[0]?.blockId,i=r[r.length-1]?.blockId;return typeof o=="string"?{startBlockId:o,endBlockId:typeof i=="string"?i:o}:null}function Vr(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 TV=64;function vc(e){return e.length<=TV}function ss(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 Ao(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function Aa(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function bA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var wA=720;function Vs(e){return Math.round(e*20)}function Eu(e){return typeof e=="number"&&Number.isFinite(e)}function RV(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=Eu(i.left)?Vs(i.left):Eu(i.start)?Vs(i.start):void 0,a=Eu(i.right)?Vs(i.right):Eu(i.end)?Vs(i.end):void 0,l=Eu(i.firstLine)?Vs(i.firstLine):void 0,c=Eu(i.hanging)?Vs(i.hanging):void 0;return s==null&&a==null&&l==null&&c==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...c!=null?{hanging:c}:{}}}function a2(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 MV(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 Of(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 wl(e){return Of(e.target)??Of(e.selectionTarget)}var CA=["fontFamily","fontSize","color","highlight"],LV={undo:"history.undo",redo:"history.redo"},Ff=["bold","italic","underline","strikethrough"];function l2(e){return CA.includes(e)}function Tu(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,c,d)=>{typeof l!="string"||typeof c!="number"||typeof d!="number"||r.push({blockId:l,start:Math.min(c,d),end:Math.max(c,d)})};for(const l of n){const c=l?.range;o(l?.blockId,c?.start,c?.end)}if(r.length>0)return r;const i=e.selectionTarget,s=i?.start,a=i?.end;return!s||!a||s.blockId!==a.blockId||o(s.blockId,s.offset,a.offset),r}function as(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 PV(e){const t=as(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=Tu(e);return t.length===0?null:[PV(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function kA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:pc({selectionTarget:t})}function DV(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 OV(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function FV(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 NV(e,t){return e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return o?.blockId===n.blockId&&o?.start===n.start&&o?.end===n.end})}function SA(e,t){const n=Tu(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=>NV(n,FV(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 BV(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 c2(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 zV(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 VV(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function _A(e,t){if(!e)return{};const n=new Map;for(const i of Tu(t)){const s=n.get(i.blockId)??[];s.push({start:i.start,end:i.end}),n.set(i.blockId,s)}if(n.size===0)return{};const r=Array.isArray(e.blocks)?e.blocks:[],o={};for(const i of CA){const s=new Map;let a=!1,l=!1;for(const c of r){const d=typeof c?.blockId=="string"?c.blockId:null;if(!d)continue;const f=n.get(d);if(!f?.length)continue;const h=Array.isArray(c?.runs)?c.runs:[];for(const g of h){const m=g?.range,v=typeof m?.start=="number"?m.start:null,_=typeof m?.end=="number"?m.end:null;if(v==null||_==null||!f.some(y=>OV(y,{start:v,end:_})))continue;a=!0;const k=BV(g?.styles,i);if(k===void 0){l=!0;continue}const S=VV(i,k);if(s.has(S)||s.set(S,k),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function u2(e,t){const n=Vr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:Ao(n)}:{kind:"documentEnd"}}function sn(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 Nf(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 mm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function js(e){if(Ir(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 gm(e){return!!e&&typeof e=="object"&&e.success===!0}function Io(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function Bf(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function d2(e){const t=[],n=r=>{if(!r||typeof r!="object")return;const o=r;if(Array.isArray(o.runs)&&t.push(o),Array.isArray(o.rows))for(const i of o.rows){const s=i?.cells;if(Array.isArray(s))for(const a of s){const l=a;if(Array.isArray(l?.blocks))for(const c of l.blocks)n(c);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function yc(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function vm(e){return e.trackedChange?.kind==="delete"?0:typeof e.text=="string"?e.text.length:0}function ki(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!Io(i)&&n===null&&(n=i),gm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function jV(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 UV(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function ym(e){return Au(e)?.trackDecision??null}function HV(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function Cl(e){return{found:!1,success:!1,rects:[],reason:e}}function $V(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 GV(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.blockId!="string"||!t.range||typeof t.range!="object")return!1;const n=t.range;return Number.isInteger(n.start)&&Number.isInteger(n.end)&&n.start>=0&&n.start<=n.end}function AA(e){if(!e||e.kind!=="text"||!Array.isArray(e.segments)||e.segments.length===0)return null;const t=Array.from(e.segments);if(!t.every(GV))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 WV(e){return e.selectionTarget?e.selectionTarget:AA(e.target)}function Ru(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=AA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function f2(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var h2={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},KV=Object.fromEntries(Object.entries(h2).filter(([e])=>aV[e]?.tracked===!0));function qV(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:{...h2}};default:return null}}function YV(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 XV(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 ZV(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,c=!1,d=Promise.resolve(),f=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},g=0;const m=new Set;let v={},_="",k=null;const S=()=>{const u=t?.activeEditor;return u&&typeof u=="object"?u:null},y=()=>{const u=S()?.doc;return u&&typeof u=="object"?u:null},w=()=>{const u=S()?.v2TrackedChanges;return u&&typeof u=="object"?u:null},T=()=>{const u=S();if(u?.editorVersion!==2)return null;const p=u.reviewWindow;return p&&typeof p=="object"?p:null},L=()=>{const u=T();return!u||typeof u.getSnapshot!="function"?null:Mt(()=>u.getSnapshot(),null)},O=()=>typeof T()?.getSnapshot=="function",U=u=>{const p=u?.status;return p==="ready"||p==="stale"?p:"pending"},P=()=>{const u=S()?.host;return u&&typeof u=="object"?u:null},B=u=>{if(u.storyType!=="headerFooterPart"||typeof u.refId!="string")return null;const p=S(),b=P(),A=p?.pageLayout??b?.pageLayout;if(!A||typeof A!="object")return null;const x=A.getActiveRulerContext,N=b?.resolveHeaderFooterEditTarget;if(typeof x!="function"||typeof N!="function")return null;const G=Mt(()=>x.call(A),null);if(!G||typeof G.pageIndex!="number")return null;for(const oe of["header","footer"]){const fe=Mt(()=>N.call(b,{pageIndex:G.pageIndex,kind:oe}),null);if(!(fe?.status!=="ready"||fe.refId!==u.refId||typeof fe.sectionId!="string"||!["default","first","even"].includes(String(fe.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:fe.sectionId},headerFooterKind:oe,variant:fe.slotVariant}}return null},z=()=>{const u=P(),p=u?.getPendingInlineFormat;if(typeof p!="function")return null;const b=Mt(()=>p.call(u),null);return b&&typeof b=="object"?b:null},R=u=>{const p=f2(u);if(!p)return null;const b=z();if(!b||!(p in b))return null;const A=b[p];return u.inline?.kind==="toggle"?A===!0:A!=null&&A!==""},H=u=>{const p=f2(u);if(!p)return;const b=z();if(!b||!(p in b))return;const A=b[p];if(typeof A=="string"&&A!=="")return A;if(typeof A=="number"&&Number.isFinite(A))return String(A)},E=(u,p)=>{const b=P(),A=b?.setPendingInlineFormat;typeof A=="function"&&Mt(()=>A.call(b,u,p),void 0)},$=u=>{const p=P(),b=p?.clearPendingInlineFormat;typeof b=="function"&&Mt(()=>b.call(p,u),void 0)},Q=new Set(["bold","italic","underline","strikethrough"]),ie=u=>{const p=z();if(!p)return;const b=Array.isArray(u.activeMarks)?u.activeMarks:[];let A=null;for(const x of Object.keys(p)){const N=p[x];let G;if(Q.has(x))G=b.includes(x)===(N===!0);else if(l2(x)){if(N==null)continue;A||(A=Ml(u)),G=A[x]===N}else G=!1;G&&$(x)}},ee=()=>{const u=S()?.editCommands;return u&&typeof u=="object"?u:null},ne=u=>{const p=ee();if(!p||typeof p.getSnapshot!="function")return null;const b=Mt(()=>p.getSnapshot(),null)?.commands?.[u];return b&&typeof b=="object"?b:null},Ie=()=>ne("lists.apply"),pe=u=>{const p=u?.value?.seed;return p==="bullet"||p==="ordered"?p:null},ye=u=>{const p=LV[u];return p?ne(p):null},ve=()=>{const u=P();if(!u||typeof u.getTableContext!="function")return null;const p=Mt(()=>u.getTableContext(),null);return p&&typeof p=="object"?p:null},Se=()=>{const u=ve();if(!u||u.inTable!==!0)return null;const p=u.table,b=typeof p?.nodeId=="string"&&p.nodeId.length>0?p.nodeId:null;if(!b)return null;const A=u.row,x=u.column,N=u.cell,G=typeof A?.index=="number"&&Number.isInteger(A.index)?A.index:null,oe=typeof x?.index=="number"&&Number.isInteger(x.index)?x.index:null;if(G==null||oe==null)return null;const fe=typeof N?.nodeId=="string"&&N.nodeId.length>0?N.nodeId:null,Me=u.cellRange;return{tableNodeId:b,rowIndex:G,columnIndex:oe,cellNodeId:fe,mergeRange:YV(Me)}},le=new Map;let Oe=null,He=null,it=0,yt=0,De=0;const $e=new Set,Ye=(u,p)=>u===p?!0:!u||!p?!1:u.id===p.id&&u.paintedEntityId===p.paintedEntityId&&wr(u.story)===wr(p.story),J=u=>Array.from($e).some(p=>Ye(p,u)),C=u=>{const p=P();if(typeof p?.getHandles!="function")return;const b=Mt(()=>p.getHandles(),null),A=b?.review;if(A){if(u){if(typeof A.setActiveReviewTarget!="function")return;const x=b?.layout;Mt(()=>A.setActiveReviewTarget({entityType:"trackedChange",entityId:u.id,...u.paintedEntityId?{paintedEntityId:u.paintedEntityId}:{},origin:"panel",layoutEpoch:typeof x?.generation=="number"?x.generation:0,story:u.story??{kind:"story",storyType:"body"}}),null);return}typeof A.getActiveReviewTarget!="function"||typeof A.clearActiveReviewTarget!="function"||Mt(()=>A.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Mt(()=>A.clearActiveReviewTarget(),void 0)}},re=(u,p)=>{He=u,it+=1,De+=1,p?.invalidateQueuedNavigation!==!1&&(yt+=1)},V=new Set;let D,j=!1,W=null;const Y=new Map,Z=new Set;let q=null,me=null,Te=!1,_e=null,xe=0,We=null,tt=null,at=null;const Ut=[],Ct=()=>{if(Te||j)return;Te=!0;const u=()=>{Te=!1,j||Ot("async-read-settled")};typeof queueMicrotask=="function"?queueMicrotask(u):Promise.resolve().then(u)},Je=250,Vt=5e3,nn=u=>{j||_e&&xe<=u||(_e&&clearTimeout(_e),xe=u,_e=setTimeout(()=>{_e=null,xe=0,j||Ot()},Math.max(0,u-Date.now())))},Ln=new WeakMap;let Zt=0;const nt=u=>{if(!u)return"none";let p=Ln.get(u);return p==null&&(p=Zt+=1,Ln.set(u,p)),`e${p}`};let Rt=0;const jt=e.superdoc,$t=lV(jt),Qt=()=>{$t.abortController.abort("review-mutation-started"),$t.inFlight=null},Fn=()=>{$t.generation+=1,$t.abortController=new AbortController,$t.inFlight=null},kn=u=>{const p=$t.activeMutationTokens;if(typeof u!="string"||u.length===0||p.has(u))return;const b=p.size===0;p.add(u),b&&Qt()},Vo=u=>{const p=$t.activeMutationTokens;typeof u!="string"||!p.delete(u)||p.size===0&&Fn()},xr=u=>{const p=w(),b=p?.listTrackedChanges;if(typeof b!="function")return S()?.editorVersion===2?Promise.reject(new Error("v2-tracked-changes-bridge-pending")):u();if($t.activeMutationTokens.size>0)return Promise.reject(new Error("ui-review-catalog-superseded"));const A=$t.generation,x=$t.inFlight;if(x?.generation===A)return x.promise;const N=$t.abortController.signal,G=Me=>{if(N.aborted||A!==$t.generation||Me?.reason==="review-hydration-superseded")throw new Error("ui-review-catalog-superseded");return Me},oe=b.call(p,{blocking:!1,signal:N});if(!Ir(oe))return G(oe);const fe=Promise.resolve(oe).then(G);return $t.inFlight={generation:A,promise:fe},fe.then(()=>{$t.inFlight?.promise===fe&&($t.inFlight=null)},()=>{$t.inFlight?.promise===fe&&($t.inFlight=null)}),fe};let Jn=null,wn=new Set,qn=null,jo=0,jr=null;const ke=()=>`${nt(S())}|m${Rt}`,Ue=()=>{Jn=null,wn=new Set},et=u=>{for(const p of["trackChanges","trackChanges:all"]){const b=Y.get(p);if(!b?.hasSettled||!Array.isArray(b.value))continue;const A=b.value.filter(x=>{const N=ro(x);return!N||!u.has(N)});A.length!==b.value.length&&Y.set(p,{...b,value:A})}},lt=u=>{const p=()=>{if(!j)for(const N of[...V])N(D)},b=Bf(u)?u:null,A=S()?.documentMutationReadiness,x=()=>{const N=globalThis.requestAnimationFrame;return typeof N!="function"?Promise.resolve():new Promise(G=>{let oe=!1;const fe=()=>{oe||(oe=!0,clearTimeout(Me),G())},Me=setTimeout(fe,250);N(()=>N(()=>setTimeout(fe,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(x,()=>{}).then(p,p);return}catch{}p()},Dt=(u,p)=>{const b=D.trackChanges,A=b.items.filter(G=>{const oe=ro(G);return!oe||!u.has(oe)});if(A.length===b.items.length)return;He&&u.has(He.id)&&re(null);const x=new Set;for(const G of A){const oe=mm(G),fe=G,Me=oe.author??oe.authorEmail??fe.author??fe.authorEmail;typeof Me=="string"&&x.add(Me)}const N=b.items.length-A.length;D={...D,trackChanges:{...b,items:A,total:Math.max(A.length,b.total-N),activeId:b.activeId&&u.has(b.activeId)?null:b.activeId,authors:[...x]}},lt(p)},Pt=u=>{const p=D.trackChanges,b=p.items.length>0||p.total!==0||p.activeId!==null||p.authors.length>0;qn=ke(),He!==null&&re(null),D={...D,trackChanges:{...p,items:[],total:0,activeId:null,authors:[]}},b&&lt(u)},an=(u,p)=>{if(u.size===0)return;const b=ke(),A=Jn===b?wn:new Set,x=new Set([...u].filter(N=>!A.has(N)));x.size!==0&&(Jn=b,wn=new Set([...A,...x]),et(wn),Dt(x,p))},Lt=u=>Jn===u&&wn.size>0?wn:null,dr=u=>{const p=ke(),b=Lt(p),A=u.map(Nf).filter(x=>{if(x==null)return!1;const N=ro(x);return N!=null&&!b?.has(N)});for(const x of["trackChanges","trackChanges:all"])Y.set(x,{token:p,value:[...A],hasSettled:!0,inflightToken:null})},Ur=()=>`${ke()}|m${vr()}|s${jo}`,mo=u=>JSON.stringify({t:u.target??null,s:u.selectionTarget??null}),Si=["contentControls:inRange:","query:","effInline:"],rn=120,Cn=180,Yn=()=>{const u=P(),p=u?.getDocumentLoadingSnapshot;if(typeof p!="function")return"unknown";const b=Mt(()=>p.call(u),null)?.sourceStage;return b==="opening"||b==="bootstrap-ready"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},mr=new Map,qt=new Map,Pn=new Map;let Hr=null,go=0,ii=0;const _i=u=>{const p=ke();mr.get(u)!==p&&(mr.set(u,p),Ct())},kl=()=>{const u=Y.get("comments");return u?.hasSettled?Array.isArray(u.value)&&u.value.length>0:u?.inflightToken!=null},Bi=(u,p)=>mr.get(u)===p,xa=()=>{const u=ke();let p=!1;for(const[b,A]of qt){if(A!==u){qt.delete(b);continue}if(Pn.get(b)===u)continue;const x=Y.get(b);!x?.hasSettled||x.token!==u||x.inflightToken!=null||(Y.set(b,{...x,token:null,inflightToken:null}),Pn.set(b,u),p=!0)}p&&Ct()},Er=u=>{u==="comments"?go+=1:ii+=1,_i(u);let p=!1;return()=>{p||(p=!0,u==="comments"?go=Math.max(0,go-1):ii=Math.max(0,ii-1),(u==="comments"?go:ii)===0&&mr.get(u)===ke()&&mr.delete(u),Ct())}},oo=u=>{_i("contentControls")},zi=()=>{const u=Y.get("trackChanges");u?.hasSettled||u?.inflightToken!=null||_i("trackChanges")},be=()=>{const u=Y.get("comments");u?.hasSettled||u?.inflightToken!=null||_i("comments")},ze=6500,kt=250;let ct=0,Rn=0,xn=!1,Tr=null;const Rr=()=>{if(j||Tr)return;const u=()=>{if(Tr=null,j)return;const p=Date.now()-ct;if(gr()||p<ze){Tr=setTimeout(u,kt);return}xn=!1,Ot()};Tr=setTimeout(u,0)};let xo=null,Mr=null;const $r=()=>{const u=P();if(!u||xo===u)return;Mr&&(Mr(),Mr=null),xo=u;const p=u.subscribeDocumentLoading;if(typeof p!="function"){xo=null,Uo(ze);return}try{const b=N=>{const G=N?.sourceStage;(G==="source-complete"||G==="source-failed"||G==="source-cancelled")&&(Hr=ke(),xa(),ct=Math.max(ct,Date.now()),Rr())},A=p.call(u,b);typeof A=="function"&&(Mr=A);const x=u.getDocumentLoadingSnapshot;typeof x=="function"&&b(Mt(()=>x.call(u),null))}catch{xo=null,Uo(ze)}},vo=()=>{const u=S()?.host,p=u?.getForegroundMutationState;if(typeof p!="function")return null;const b=Mt(()=>p.call(u),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},gr=()=>{const u=vo();return!!(u&&(u.active>0||u.pending>0))},Uo=(u=rn)=>{j||We||(We=setTimeout(()=>{if(We=null,j)return;if(tt&&gr()){Uo(),Ot();return}const p=tt;tt=null,p===Ur()&&Vi("selection",p,Il,Hi),Ot()},u))},cs=(u,p)=>{if(!vo())return!1;const b=`${u}\0${p}`;return Z.has(b)?!1:(Z.add(b),Uo(Cn),!0)},si=u=>{if(q==null||u===q)return me?.timer&&clearTimeout(me.timer),me=null,q=u,!1;if(me?.key===u)return me.ready?(me=null,q=u,!1):!0;me?.timer&&clearTimeout(me.timer);const p={key:u,ready:!1,timer:null};return p.timer=setTimeout(()=>{j||me!==p||(p.timer=null,p.ready=!0,Ot())},Cn),me=p,!0},bc=u=>eV(u),ai=()=>{Us(),Ot()};let Eo=null,Ai=!1,us=0;const Ea=()=>{Eo=null,Ai=!1,us+=1},Sl=()=>{const u=S(),p=u?.documentMutationReadiness;if(!u||typeof p?.whenPainted!="function"||(Eo={editor:u,readiness:p,afterEpoch:typeof p.getRenderEpoch=="function"?Mt(()=>p.getRenderEpoch.call(p),null):null},Ai))return;Ai=!0;const b=us;(async()=>{for(;!j&&b===us;){const x=Eo;if(Eo=null,!x){Ai=!1;return}let N=!1;try{await x.readiness.whenPainted.call(x.readiness,typeof x.afterEpoch=="number"?{afterEpoch:x.afterEpoch}:void 0),N=!0}catch{}if(j||b!==us)return;if(S()!==x.editor){Ea();return}N&&ai()}})()},Mu=()=>{at&&clearTimeout(at),at=setTimeout(()=>{at=null,j||ai()},500)},Vi=(u,p,b,A)=>{let x;try{x=b()}catch{x=void 0}if(!Ir(x)){const oe={token:p,value:A(x),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return Y.set(u,oe),oe}const N=Y.get(u),G=N?.failedToken===p;return Y.set(u,{token:N?.token??null,value:N?.value??null,hasSettled:N?.hasSettled??!1,inflightToken:p,failedToken:G?p:null,failureCount:G?N.failureCount??0:0,retryAtMs:0}),Promise.resolve(x).then(oe=>{const fe=Y.get(u);if(!fe||fe.inflightToken!==p)return;Y.set(u,{token:p,value:A(oe),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0});const{sink:Me,workerContext:Ve}=fm();if(Me){const je=_a();Ut.push({key:u,settledAtMs:je,commandId:Ve?.commandId??null,commandKind:Ve?.commandKind??null}),n2({stage:"superdoc-ui-async-read-settled",atMs:je,key:u,settledAtMs:je,commandId:Ve?.commandId??null,commandKind:Ve?.commandKind??null})}Ct()},()=>{const oe=Y.get(u);if(!oe||oe.inflightToken!==p)return;const fe=oe.failedToken===p?(oe.failureCount??0)+1:1,Me=Math.min(Vt,Je*2**Math.min(fe-1,8)),Ve=Date.now()+Me;Y.set(u,{...oe,inflightToken:null,failedToken:p,failureCount:fe,retryAtMs:Ve}),nn(Ve)}),null},To=(u,p,b,A)=>{const x=Y.get(u);if(x&&x.token===p&&x.hasSettled)return{value:x.value,status:"ready"};if(yV(u)&&!Bi(u,p)){if(Yn()==="loading")return xn=!0,$r(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(xn)return Rr(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(Date.now()-Rn<ze)return xn=!0,Rr(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"}}if(gr())return Uo(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(x?.failedToken===p&&x.inflightToken==null&&(x.retryAtMs??0)>Date.now())return nn(x.retryAtMs),x.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(!x&&u.startsWith("effInline:")&&si(u))return{value:null,status:"pending"};if(!x&&cs(u,p))return{value:null,status:"pending"};if(!x||x.inflightToken!==p){const G=Vi(u,p,b,A);if(G)return{value:G.value,status:"ready"}}const N=Y.get(u);return N?.hasSettled?{value:N.value,status:"stale"}:{value:null,status:"pending"}},_l=u=>{for(const p of Y.keys())u(p)&&Y.delete(p)},zf=u=>{const p=mo(u),b=kA(u);return new Set([`contentControls:inRange:${p}`,`query:${p}`,...b?[`effInline:${b}`]:[]])},ji=u=>{const p=zf(u);_l(b=>Si.some(A=>b.startsWith(A))&&!p.has(b));for(const b of Z){const A=b.split("\0",1)[0];Si.some(x=>A.startsWith(x))&&!p.has(A)&&Z.delete(b)}},Ta=()=>{const u=S();u!==jr&&(Ea(),jr=u,Y.clear(),_e&&clearTimeout(_e),_e=null,xe=0,me?.timer&&clearTimeout(me.timer),me=null,q=null,k=null,o=null,tt=null,Z.clear(),mr.clear(),qt.clear(),Pn.clear(),Hr=null,xn=!1,Mr&&Mr(),Mr=null,xo=null,Ue(),qn=null)},Us=()=>{Rt+=1,qt.clear(),Pn.clear(),Hr=null,Ue()},Al=()=>{const u=qn===ke();Us(),u&&(dr([]),qn=ke()),Ot()},Vf=u=>{if(typeof u!="string"||u.length===0)return Kn("insertText requires a non-empty string.","INVALID_INPUT");if(vr()==="viewing")return Kn("The document is read-only.","DOCUMENT_READONLY");const p=y(),b=p?.insert;if(!p||typeof b!="function")return Kn("insert is unavailable.");const A=p.selection?.current;if(typeof A!="function")return Kn("selection.current is unavailable.");const x=G=>{const oe=G&&typeof G=="object"?G:null,fe=oe?.selectionTarget??oe?.target??null;return!fe||typeof fe!="object"?Kn("insertText requires a live selection target.","PRECONDITION_FAILED"):Mt(()=>Bl(b.call(p,{type:"text",value:u,target:fe}),Kn("insert failed.")),Kn("insert failed."))};let N;try{N=A.call(p.selection)}catch{return Kn("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Ir(N)?Promise.resolve(N).then(x,()=>Kn("insertText could not resolve the live selection.","PRECONDITION_FAILED")):x(N)},Ui=(u,p)=>({payload:u,state:D,editor:S(),superdoc:t,context:p,ui:W,execute:(b,A)=>Tc(b,A),executeAsync:(b,A)=>Rm(b,A),doc:y(),selection:D.selection,documentMode:vr(),insertText:Vf}),Ra=u=>u==="editing"||u==="suggesting"||u==="viewing"?u:null,vr=()=>{const u=S(),p=t&&typeof t=="object"?t:null,b=Ra(p?.config?.documentMode),A=Mt(typeof p?.getActiveRuntime=="function"?()=>{const G=p.getActiveRuntime();return typeof G?.getSnapshot=="function"?G.getSnapshot():null}:void 0,null),x=Ra(A?.documentMode),N=Ra(u?.options?.documentMode);return b&&x&&b!==x?b:x??b??N},ds=()=>{const u=t&&typeof t=="object"?t:null,p=u?.interactionConfig?.comments;if(p&&typeof p.readOnly=="boolean")return p.readOnly===!0;const b=u?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},Ma=()=>{const u=t&&typeof t=="object"?t:null,p=u?.interactionConfig?.comments;if(p&&typeof p.allowResolve=="boolean")return p.allowResolve===!1;const b=u?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},La=()=>vr()==="viewing"||ds(),Hi=u=>u&&typeof u=="object"?u:null,Ii=(u,p)=>{if(!u)return{...mV,status:p};const b=u.target??null,A=typeof u.text=="string"?u.text:"";return{status:p,empty:u.empty===!0,target:b,selectionTarget:u.selectionTarget??null,activeMarks:Array.isArray(u.activeMarks)?u.activeMarks:[],activeCommentIds:Array.isArray(u.activeCommentIds)?u.activeCommentIds:[],activeChangeIds:Array.isArray(u.activeChangeIds)?u.activeChangeIds:[],quotedText:A}},Pa=()=>{const u=y()?.selection;return To("selection",Ur(),()=>u?.current?u.current({includeText:!0}):void 0,Hi)},Lu=()=>{const{value:u,status:p}=Pa();return Ii(u,p)},Il=()=>{const u=y()?.selection;return u?.current?u.current({includeText:!0}):void 0},xl=u=>{if(u.empty!==!0)return!1;const p=u.selectionTarget,b=p?.start,A=p?.end;return b?.kind==="text"&&A?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===A.blockId&&typeof b.offset=="number"&&b.offset===A.offset},Hs=u=>{const p=P(),b=p?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const A=Hi(Mt(()=>b.call(p),null));if(!A||!xl(A))return;const x=Ur(),N=vo(),G=!!(N&&(N.active>0||N.pending>0));if(G)tt=x,Uo();else if(tt=null,Vi("selection",x,Il,Hi))return;const oe=Y.get("selection"),fe=Array.isArray(A.activeMarks)&&A.activeMarks.length>0?A.activeMarks:Array.isArray(D.selection.activeMarks)?D.selection.activeMarks:[],Me=Array.isArray(A.activeCommentIds)?A.activeCommentIds:[],Ve=kV(u),je=wl(D.selection),Ke=Of(A.selectionTarget)??Of(A.target),Ze=je?.range,Ge=Ke?.range,Qe=!!(N&&N.active>0&&je&&Ke&&je.blockId===Ke.blockId&&wr(je.story)===wr(Ke.story)&&typeof Ze?.start=="number"&&typeof Ge?.start=="number"&&Math.abs(Ge.start-Ze.start)<=2),ht=Ve!=null||Qe?D.selection.activeChangeIds.filter(ot=>Ve==null||zs(D.trackChanges.items).aliasesFor(ot).includes(Ve)):[],dt=Array.isArray(A.activeChangeIds)&&A.activeChangeIds.length>0?A.activeChangeIds:ht;Y.set("selection",{token:x,value:{...A,activeMarks:fe,activeCommentIds:Me,activeChangeIds:dt},hasSettled:!0,inflightToken:G?null:oe?.inflightToken??null})},wc=async(u=0)=>{const p=y()?.selection,b=p?.current,A=Ur();if(typeof b!="function")return Y.set("selection",{token:A,value:null,hasSettled:!0,inflightToken:null}),Ot(),D.selection;let x;try{x=b.call(p,{includeText:!0}),Ir(x)&&(x=await Promise.resolve(x))}catch{x=null}return j?Ii(null,"pending"):Ur()!==A?u<1?wc(u+1):D.selection:(Y.set("selection",{token:A,value:Hi(x),hasSettled:!0,inflightToken:null}),Ot(),D.selection)},Cc=()=>{const u=y()?.comments;return To("comments",ke(),()=>u?.list?u.list():void 0,p=>p&&Array.isArray(p.items)?p.items:[])},$s=(u="trackChanges")=>{const p=ke(),b=y()?.trackChanges,A=w(),x=typeof A?.listTrackedChanges=="function"?A.listTrackedChanges:null,N=To(u,p,()=>x?xr(()=>b?.list?.({in:"all"})):b?.list?b.list({in:"all"}):void 0,G=>{const oe=G&&typeof G=="object"?G:null;if(oe?.complete===!1||oe?.sourceCoverageComplete===!1){if(qt.set(u,p),$r(),Hr===p||Yn()==="complete"){const fe=()=>{j||xa()};typeof queueMicrotask=="function"?queueMicrotask(fe):Promise.resolve().then(fe)}}else qt.get(u)===p&&qt.delete(u);return oe&&Array.isArray(oe.items)?oe.items:[]});return qt.get(u)===p&&N.status==="ready"?{...N,status:"stale"}:N},jf=u=>{const p=L(),b=O(),A=b?null:Cc(),x=b&&Array.isArray(p?.commentItems)?p.commentItems:null,N=b?x:A.value,G=b?U(p):A.status,oe=N??[],fe=u.activeCommentIds,Me=Y.get("comments"),Ve=Me?.token===ke()&&Me.hasSettled&&Array.isArray(Me.value)?Me.value:null,je=go>0?Ve:oe;Oe&&je&&!je.some(Ze=>ro(Ze)===Oe)&&(Oe=null);const Ke=Oe??fe[0]??null;return{status:bl(G,u.status),listStatus:G,items:oe,total:oe.length,activeIds:fe,activeId:Ke}},kc=new WeakMap,$i=u=>{const p=kc.get(u);if(p)return p;const b=u.map(Nf).filter(A=>A!=null);return kc.set(u,b),b},El=new WeakMap,Da=(u,p)=>{const b=El.get(u);if(b?.suppressedIds===p)return b.value;const A=p?u.filter(x=>{const N=ro(x);return!N||!p.has(N)}):u;return El.set(u,{suppressedIds:p,value:A}),A},Lr=new WeakMap,Sc=u=>{const p=Lr.get(u);if(p)return p;const b=new Set;for(const x of u){const N=mm(x),G=x,oe=N.author??N.authorEmail??G.author??G.authorEmail;typeof oe=="string"&&b.add(oe)}const A=[...b];return Lr.set(u,A),A},li=()=>{const u=ke();if(O()){const A=Y.get("trackChanges"),x=A?.token===u&&A.hasSettled&&Array.isArray(A.value)?A.value:L()?.trackedChangeItems;return Array.isArray(x)?$i(x):null}const{value:p,status:b}=$s("trackChanges:all");return b==="ready"?$i(p??[]):null},_c=u=>{const p=ke(),b=Lt(p),A=L(),x=O(),N=x?null:$s(),G=x&&Array.isArray(A?.trackedChangeItems)?A.trackedChangeItems:null,oe=x?G:N.value,fe=x?U(A):N.status,Me=Da($i(oe??[]),b),Ve=li(),je=He;if(je&&!$e.has(je)){const zt=Y.get("trackChanges"),$n=zt?.token===p&&zt.hasSettled&&Array.isArray(zt.value)?Da($i(zt.value),b):null,Gn=ii>0?$n:je.story?Ve:Me;Gn&&!Gn.some(Qr=>Ni(Qr,je.id,je.story))&&re(null)}const Ke=Ve??Me,Ze=gc(Ke,ss(u)),Ge=qn===p?[]:b?u.activeChangeIds.filter(zt=>!b.has(zt)):u.activeChangeIds,Qe=Ge.map(zt=>Ze.toPublicId(zt)??zt),ht=He?.story?gc(Ke,He.story):zs(Ke),dt=He?ht.toPublicId(He.id)??He.id:null,ot=IV({selectionIds:Ge,publicIds:Qe,selection:u,bodyItems:Me,allStoryItems:Ve}),Bt=dt??ot;return{status:bl(fe,u.status),items:Me,total:Me.length,activeId:Bt,authors:Sc(Me)}},Pu=(u,p)=>{if(!O())return p;_i("comments");const b=Cc(),A=b.value??p.items;return{status:bl(b.status,u.status),listStatus:b.status,items:A,total:A.length,activeIds:u.activeCommentIds,activeId:Oe??u.activeCommentIds[0]??null}},Gi=(u,p)=>{if(!O())return p;_i("trackChanges");const b=$s(),A=Lt(ke()),x=Da($i(b.value??p.items),A),N=He?.story?gc(x,He.story):zs(x),G=He?N.toPublicId(He.id)??He.id:p.activeId;return{status:bl(b.status,u.status),items:x,total:x.length,activeId:G,authors:Sc(x)}},Ac=u=>{const p=y()?.contentControls,{value:b,status:A}=To("contentControls",ke(),()=>p?.list?p.list():void 0,oe=>oe&&Array.isArray(oe.items)?oe.items:[]),x=b??[],{ids:N,status:G}=Uf(p,u);return{status:bl(A,G,u.status),items:x,total:x.length,activeId:N[0]??null,activeIds:N}},Gs=(u,p)=>{if(!u||typeof u.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=EV(p);if(!b)return{lockModesById:new Map,status:"ready"};const{value:A,status:x}=To(`contentControls:inRange:${mo(p)}`,ke(),()=>u.listInRange(b),oe=>oe&&Array.isArray(oe.items)?oe.items:[]),N=A??[],G=new Map;for(const oe of N)typeof oe?.id=="string"&&G.set(oe.id,typeof oe.lockMode=="string"?oe.lockMode:"unlocked");return{lockModesById:G,status:x}},Uf=(u,p)=>{const{lockModesById:b,status:A}=Gs(u,p);return{ids:[...b.keys()],status:A}},Du=()=>{const u=t?.fonts;return{options:nj(ej(Mt(u?.getDocumentFontOptions?()=>u.getDocumentFontOptions():void 0,[])),tj(Mt(u?.getFontFamilyOptions?()=>u.getFontFamilyOptions():void 0,[]))),sizeOptions:rj}},Ic=()=>{const u=Mt(t?.getZoomState?()=>t.getZoomState():void 0,null),p=typeof u?.value=="number"?u.value:100,b=u?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:p,min:typeof u?.min=="number"?u.min:10,max:typeof u?.max=="number"?u.max:100}},Ou=()=>Mt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",Hf=()=>{const u=S();return{ready:u!=null,mode:vr(),dirty:u?!!u.isDirty:!1}},Tl=u=>{const p=u.quotedText;if(typeof p!="string"||p.length===0)return null;const b=Tu(u);if(b.length===0||!vc(b.map(N=>N.blockId)))return null;const A=u.target,x=b.length===1?Ao(b[0].blockId,A?.story):void 0;return{select:{type:"text",pattern:p,mode:"contains",caseSensitive:!0},...x?{within:x}:{},require:"any"}},$f=u=>{const p=y()?.query;if(typeof p?.match!="function")return null;const b=Tl(u);if(!b)return null;const{value:A}=To(`query:${mo(u)}`,ke(),()=>p.match(b),x=>x&&typeof x=="object"?x:null);return SA(A,u)},Fu=u=>{const p=P(),b=new Set(Vr(u));if(b.size===0)return{};const A=p?.readMountedProjectionBlocksByIds,x=p?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof x!="function")return{};const N=Mt(()=>{if(typeof A!="function")return x.call(p);const Qe=as(u);return Qe?A.call(p,[...b],Qe):A.call(p,[...b])},null);if(!Array.isArray(N))return{};const G=d2(N),oe=Qe=>{const ht={},dt=c2(Qe.fontFamily);dt&&(ht.fontFamily=dt);const ot=zV(Qe.fontSize);return ot&&(ht.fontSize=ot),typeof Qe.color=="string"&&Qe.color.trim()!==""&&(ht.color=Qe.color.trim().toUpperCase()),typeof Qe.highlight=="string"&&Qe.highlight.trim()!==""&&(ht.highlight=Qe.highlight.trim().toUpperCase()),ht},fe=wl(u),Me=fe&&typeof fe.range?.start=="number"?fe.range.start:null;if(fe&&Me!==null&&b.has(fe.blockId)){const Qe=G.find(dt=>yc(dt,fe.blockId)),ht=Qe&&Array.isArray(Qe.runs)?Qe.runs:null;if(ht&&ht.length>0&&ht.every(dt=>dt?.kind==="text"||dt?.kind==="tab")){let dt=0,ot=null;for(const Bt of ht){const zt=vm(Bt);if(Me>=dt&&Me<dt+zt){ot=Bt;break}dt+=zt}if(!ot){for(let Bt=ht.length-1;Bt>=0&&!ot;Bt-=1)ht[Bt]?.kind==="text"&&(ot=ht[Bt]);ot??=ht[ht.length-1]??null}return ot?oe(ot):{}}}const Ve=Tu(u);if(Ve.length>0){const Qe=new Set,ht=new Set;let dt=!1,ot=!0;for(const Bt of Ve){const zt=G.find(Qr=>yc(Qr,Bt.blockId));if(!zt)return{};const $n=Array.isArray(zt.runs)?zt.runs:[];if($n.length===0)continue;if(!$n.every(Qr=>Qr?.kind==="text"||Qr?.kind==="tab")){ot=!1;break}let Gn=0;for(const Qr of $n){const Jr=vm(Qr),kr=Gn,Or=Gn+Jr;if(kr<Bt.end&&Or>Bt.start){dt=!0;const Zo=oe(Qr);Zo.fontFamily&&Qe.add(Zo.fontFamily),Zo.fontSize&&ht.add(Zo.fontSize)}Gn=Or}}if(ot&&dt){const Bt={};return Qe.size===1&&(Bt.fontFamily=[...Qe][0]),ht.size===1&&(Bt.fontSize=[...ht][0]),Bt}}const je=new Set,Ke=new Set;let Ze=!1;for(const Qe of G){if(![...b].some(dt=>yc(Qe,dt)))continue;const ht=Array.isArray(Qe.runs)?Qe.runs:[];for(const dt of ht){if(dt?.kind!=="text")continue;Ze=!0;const ot=oe(dt);ot.fontFamily&&je.add(ot.fontFamily),ot.fontSize&&Ke.add(ot.fontSize)}}if(!Ze)return{};const Ge={};return je.size===1&&(Ge.fontFamily=[...je][0]),Ke.size===1&&(Ge.fontSize=[...Ke][0]),Ge},Nu=u=>{const p=P(),b=new Set(Vr(u));if(b.size===0)return{};const A=p?.readMountedProjectionBlocksByIds,x=p?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof x!="function")return{};const N=Mt(()=>{if(typeof A!="function")return x.call(p);const Ge=as(u);return Ge?A.call(p,[...b],Ge):A.call(p,[...b])},null);if(!Array.isArray(N))return{};const G=d2(N),oe=Ge=>({bold:Ge.bold===!0,italic:Ge.italic===!0,underline:Ge.underline!=null,strikethrough:Ge.strike===!0}),fe=Ge=>{const Qe={};for(const ht of Ff){const dt=Ge[ht];dt.size===1&&(Qe[ht]=[...dt][0])}return Qe},Me=wl(u),Ve=Me&&typeof Me.range?.start=="number"?Me.range.start:null;if(Me&&Ve!==null&&b.has(Me.blockId)){const Ge=G.find(ht=>yc(ht,Me.blockId)),Qe=Ge&&Array.isArray(Ge.runs)?Ge.runs:null;if(Qe&&Qe.length>0&&Qe.every(ht=>ht?.kind==="text"||ht?.kind==="tab")){let ht=0,dt=null;for(const ot of Qe){const Bt=vm(ot);if(Ve>=ht&&Ve<ht+Bt){dt=ot;break}ht+=Bt}if(!dt){for(let ot=Qe.length-1;ot>=0&&!dt;ot-=1)Qe[ot]?.kind==="text"&&(dt=Qe[ot]);dt??=Qe[Qe.length-1]??null}return dt?oe(dt):{}}}const je=Tu(u);if(je.length>0){const Ge={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Qe=!1,ht=!0;for(const dt of je){const ot=G.find($n=>yc($n,dt.blockId));if(!ot)return{};const Bt=Array.isArray(ot.runs)?ot.runs:[];if(Bt.length===0)continue;if(!Bt.every($n=>$n?.kind==="text"||$n?.kind==="tab")){ht=!1;break}let zt=0;for(const $n of Bt){const Gn=vm($n),Qr=zt,Jr=zt+Gn;if(Qr<dt.end&&Jr>dt.start){Qe=!0;const kr=oe($n);for(const Or of Ff)Ge[Or].add(kr[Or])}zt=Jr}}if(ht&&Qe)return fe(Ge)}const Ke={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ze=!1;for(const Ge of G){if(![...b].some(ht=>yc(Ge,ht)))continue;const Qe=Array.isArray(Ge.runs)?Ge.runs:[];for(const ht of Qe){if(ht?.kind!=="text")continue;Ze=!0;const dt=oe(ht);for(const ot of Ff)Ke[ot].add(dt[ot])}}return Ze?fe(Ke):{}},Bu=(u,p)=>{if(p.fontFamily!==void 0&&p.fontSize!==void 0&&p.color!==void 0&&p.highlight!==void 0)return{values:p,effectiveUniformityStatus:"ready"};const b=Fu(u),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}:{},...p};if(!u.empty&&(A.fontFamily===void 0||A.fontSize===void 0)){const x=ci(u);return x.values&&(A.fontFamily===void 0&&x.values.fontFamily!==void 0&&(A.fontFamily=x.values.fontFamily),A.fontSize===void 0&&x.values.fontSize!==void 0&&(A.fontSize=x.values.fontSize)),{values:A,effectiveUniformityStatus:x.status}}return{values:A,effectiveUniformityStatus:"ready"}},zu=["fontFamily","fontSize","bold","italic","underline","strikethrough"],Vu=u=>{const p=u.selectionTarget;if(!p)return{value:null,status:"ready"};const b=pr(y(),"format.readEffectiveInlineUniformity");if(!b)return{value:null,status:"ready"};const A=kA(u)??mo(u);return To(`effInline:${A}`,ke(),()=>b({target:p,offsetSpace:"selection",keys:zu}),x=>x&&typeof x=="object"?x:null)},ci=u=>{const{value:p,status:b}=Vu(u);if(!p||p.success!==!0)return{values:null,status:b};const A=p.values,x=N=>{const G=A?.[N];if(!(!G||G.state!=="uniform"||typeof G.value!="string"))return N==="fontFamily"?c2(G.value):G.value};return{values:{fontFamily:x("fontFamily"),fontSize:x("fontSize")},status:b}},xc=u=>{const{value:p,status:b}=Vu(u);if(!p||p.success!==!0)return{values:null,status:b};const A=p.values,x={};for(const N of Ff){const G=A?.[N];G?.state==="uniform"&&(G.value==="true"||G.value==="false")&&(x[N]=G.value==="true")}return{values:x,status:b}},Rl=(u,p)=>{const b=u.activeMark;if(!b||!Ff.includes(b))return null;const A=b,x=Nu(p)[A];if(x!==void 0)return x;const{values:N}=xc(p),G=N?.[A];return G!==void 0?G:null},Gf=async u=>{const p=u.selectionTarget;if(!p)return null;const b=pr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const A=await Promise.resolve(b({target:p,offsetSpace:"selection"}));return A&&typeof A=="object"&&A.success===!0?A:null}catch{return null}},Wf=(u,p,b)=>{const A=b.values;for(const x of["fontFamily","fontSize"]){if(p[x]!==void 0)continue;const N=A?.[x];N?.state==="uniform"&&typeof N.value=="string"?u[x]=x==="fontFamily"?c2(N.value):N.value:delete u[x]}},Ws=u=>Bu(u,_A($f(u),u)),Ml=u=>Ws(u).values,Kf=async u=>{const p=y()?.query,b=Tl(u);if(typeof p?.match!="function"||!b)return Ml(u);try{const A=await Promise.resolve(p.match(b)),x=_A(SA(A&&typeof A=="object"?A:null,u),u),N=Bu(u,x);if(N.effectiveUniformityStatus!=="ready"&&(x.fontFamily===void 0||x.fontSize===void 0)){const G=await Gf(u);G&&Wf(N.values,x,G)}return N.values}catch{return Ml(u)}},Ll=async u=>{const p=y();if(p)return typeof p.getNode=="function"?await Promise.resolve(p.getNode(u)):await Promise.resolve(p.getNodeById?.({nodeId:u.nodeId,nodeType:u.nodeType}))},Ec=u=>{const p=y()?.query;if(typeof p?.match!="function")return"ready";const b=Tl(u);if(!b)return"ready";const{status:A}=To(`query:${mo(u)}`,ke(),()=>p.match(b),x=>x&&typeof x=="object"?x:null);return A},ju=u=>{const p=Ws(u),b=p.values;if(u.empty)return p;const A=Ia(u);return A?u.status==="ready"&&Ec(u)==="ready"&&p.effectiveUniformityStatus==="ready"?(k={key:A,values:b},p):k&&k.key===A?{...p,values:{...k.values,...b}}:p:p},Uu=u=>{const p=y(),b=ju(u),A=b.values;u.status==="ready"&&!u.empty&&Ec(u)==="ready"&&b.effectiveUniformityStatus==="ready"&&(v=A,_=`${pc(u)}:${ke()}`);const x=p?.contentControls,{lockModesById:N}=Gs(x,u),G={};for(const oe of Pr())G[oe]=Gu(oe,p,u,A,N);return G},Ho=u=>u?ut.operationUnavailable:S()?ut.documentApiUnavailable:ut.notReady,Oa=u=>u==="contentLocked"||u==="sdtContentLocked",fs=u=>{for(const p of u.values())if(Oa(p))return ut.contentControlLocked},Hu=(u,p,b,A,x)=>{if(!p)return u.scope==="all"?ut.bulkDecisionsDisabled:Ho(x);if(b)return ut.documentReadonly;if(u.scope!=="all"&&A.activeChangeIds.length===0)return ut.selectionRequired},qf=u=>{const p=P(),b=Mt(typeof p?.getCapabilities=="function"?()=>p.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(A=>A?.command===u||A?.id===u)??null;if(b&&typeof b=="object"){const A=b[u];return A&&typeof A=="object"?A:null}return null},$u=(u,p)=>{if(u.scope!=="all"||typeof p?.[`${u.kind}All`]=="function")return;const b=qf(`trackedChanges.${u.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return ut.bulkDecisionsDisabled},Gu=(u,p,b,A,x=new Map)=>{if(le.has(u))return sn({supported:!0,enabled:!0,...Mt(le.get(u).getState?()=>le.get(u).getState(Ui(void 0)):void 0,{})},"custom");const N=vr()==="viewing",G=fA(u);if(G&&typeof ee()?.lists?.apply=="function"){const Ze=Ie(),Ge=typeof Ze?.shippedStatus=="string"?Ze.shippedStatus:null,Qe=Ge!=="not-shipped"&&Ge!=="disabled",ht=Qe&&(typeof Ze?.enabled=="boolean"?Ze.enabled:!0),dt=Qe?pe(Ze):null;return sn(N?{enabled:!1,active:dt===G,supported:Qe,value:Ze?.value,reason:ut.documentReadonly}:{enabled:ht,active:dt===G,supported:Qe,value:Ze?.value},"builtin")}const oe=ym(u);if(oe){const Ze=p?.trackChanges,Ge=typeof Ze?.decide=="function"||typeof Ze?.[oe.kind]=="function",Qe=typeof Ze?.decide=="function"||typeof Ze?.[`${oe.kind}All`]=="function",ht=oe.scope==="all"?Qe:Ge,dt=$u(oe,Ze)??Hu(oe,ht,La(),b,p);return sn({enabled:dt==null,active:!1,supported:ht,reason:dt},"builtin")}if(u==="copy-format")return vr()==="viewing"?sn({supported:!0,enabled:!1,active:!1},"builtin"):S()?sn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):sn({supported:!0,enabled:!1,active:!1,reason:ut.notReady},"builtin");const fe=Au(u);if(!fe)return sn({enabled:!1,active:!1,supported:!1,reason:ut.commandUnsupported},"unsupported");if(fe.disposition!=="routed")return sn({enabled:!1,active:!1,supported:!1,reason:fe.reason??ut.commandUnsupported},fe.disposition==="unsupported"?"unsupported":"builtin");if(fe.instanceRoute)return rt(fe);if(fe.table)return mt(fe,p,N);if(fe.inline?.kind==="clear"){if(fe.mutates&&N)return sn({enabled:!1,active:!1,supported:!0,reason:ut.documentReadonly},"builtin");const Ze=fs(x);if(Ze)return sn({enabled:!1,active:!1,supported:!0,reason:Ze},"builtin");const Ge=Vr(b).length>0||Ru(b)!=null;return sn({enabled:Ge,active:!1,supported:!0,reason:Ge?void 0:ut.selectionRequired},"builtin")}const Me=fe.docRoute;if(!Me)return sn({enabled:!1,active:!1,supported:!1,reason:ut.commandUnsupported},"unsupported");if(pr(p,Me)==null)return sn({enabled:!1,active:!1,supported:!1,reason:Ho(p)},"builtin");const Ve=ye(u);if(Ve){const Ze=Ve.shippedStatus,Ge=Ze!=="not-shipped"&&Ze!=="disabled",Qe=typeof Ve.enabled=="boolean"?Ve.enabled:!0,ht=u==="undo"||u==="redo",dt=ht&&Ve.historyResolved===!1,ot=ht&&Ge&&Qe===!1&&Ve.reason===null&&!dt,Bt=Ve.reason===void 0?void 0:ot?ut.historyEmpty:dt?ut.notReady:o2(Ve.reason,ut.commandUnsupported);return fe.mutates&&N?sn({enabled:!1,active:!1,supported:Ge,reason:ut.documentReadonly},"builtin"):sn({enabled:Ge&&Qe,active:!1,supported:Ge,reason:Bt},"builtin")}const je=Pl(fe,p,b),Ke=hs(fe,p,b,A);if(fe.list?.mode==="indent"||fe.list?.mode==="outdent")return Pe(fe,p,N,b,je,Ke);if(fe.list?.mode==="toggle-seed")return Xe(fe,p,N,b,je,Ke);if(fe.mutates&&N)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:ut.documentReadonly},"builtin");if(fe.inline&&!Ru(b)){const Ze=fs(x);return sn(Ze?{enabled:!1,active:je,supported:!0,value:Ke,reason:Ze}:Vr(b).length>0&&typeof P()?.setPendingInlineFormat=="function"?{enabled:!0,active:je,supported:!0,value:Ke}:{enabled:!1,active:je,supported:!0,value:Ke,reason:ut.rangeSelectionRequired},"builtin")}if((fe.blockParagraph||fe.list)&&Vr(b).length===0)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:ut.selectionRequired},"builtin");if(fe.link&&!je&&a2(b).length===0&&!wl(b))return sn({enabled:!1,active:je,supported:!0,reason:ut.rangeSelectionRequired},"builtin");if(fe.inline){const Ze=fs(x);if(Ze)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:Ze},"builtin")}return sn({enabled:!0,active:je,supported:!0,value:Ke},"builtin")};function Fa(u,p){const b=u.address?.anchor,A=b?.start,x=b?.end,N=typeof A?.blockId=="string"?A.blockId:null,G=typeof x?.blockId=="string"?x.blockId:null;if(!N||!G)return!1;const oe=typeof A?.offset=="number"?A.offset:null,fe=typeof x?.offset=="number"?x.offset:null;if(oe==null||fe==null)return!1;const Me=p.target,Ve=Me&&Array.isArray(Me.segments)?Me.segments:[];for(const je of Ve){const Ke=typeof je?.blockId=="string"?je.blockId:null;if(!Ke)continue;const Ze=je.range,Ge=typeof Ze?.start=="number"?Ze.start:null,Qe=typeof Ze?.end=="number"?Ze.end:null;if(!(Ge==null||Qe==null)){if(N!==G){if(Ke===N&&Qe>oe||Ke===G&&Ge<fe)return!0;continue}if(Ke===N){if(Ge===Qe){if(Ge>=oe&&Ge<=fe)return!0;continue}if(Math.max(Ge,oe)<Math.min(Qe,fe))return!0}}}return!1}const Na=(u,p)=>{const b=u?.hyperlinks;if(!b||typeof b.list!="function")return null;const A=Vr(p);if(!vc(A))return null;for(const x of A){const N={kind:"block",nodeType:"paragraph",nodeId:x},{value:G}=To(`hyperlinks:${x}`,ke(),()=>b.list({within:N}),fe=>fe&&typeof fe=="object"?fe:null),oe=(G&&Array.isArray(G.items)?G.items:[]).find(fe=>Fa(fe,p));if(oe)return oe}return null},Pl=(u,p,b)=>{if(u.link)return Na(p,b)!=null;if(u.list?.mode==="toggle-seed"&&u.list.seed)return Wu(p,b)===u.list.seed;const A=R(u);if(A!==null)return A;const x=r.get(u.id),N=Ia(b);if(N&&x?.selectionSignature===N)return x.active;const G=Rl(u,b);return G!==null?G:oj(u,b)},hs=(u,p,b,A)=>{if(u.inline&&l2(u.inline.key)){const x=H(u);if(x!==void 0)return x;const N=A[u.inline.key];if(N!==void 0)return N;const G=Ia(b),oe=G?n.get(u.inline.key):void 0;if(G&&oe?.selectionSignature===G)return oe.value}if(u.id==="linked-style"){const{style:x}=Yr(b,ir().cache);return!x.styleId||x.mixed?void 0:{styleId:x.styleId,styleName:x.styleName}}if(u.id==="text-align")return ue(p,b);if(u.id==="link")return ft(p,b)??void 0},qr=(u,p,b)=>{const A=u?.lists;if(!A)return{value:null,status:"ready"};const x=b.storyType==="body",N=typeof A.getStateInStory=="function"?()=>A.getStateInStory({target:Aa(p),story:b}):x&&typeof A.getState=="function"?()=>A.getState({target:Aa(p)}):null;if(!N)return{value:null,status:"ready"};const{value:G,status:oe}=To(`lists:${wr(b)}:${p}`,ke(),N,fe=>fe&&typeof fe=="object"?fe:null);return{value:G?.success===!0?G:null,status:oe}},Ba=(u,p,b)=>qr(u,p,b).value,Dl=(u,p,b)=>{const A=Ba(u,p,b);return!A||A.isListItem!==!0?null:A.seed==="bullet"||A.seed==="ordered"?A.seed:null},za=(u,p,b)=>{const A=qr(u,p,b),x=A.value;return{value:x&&typeof x.isListItem=="boolean"?x.isListItem:null,status:A.status}},Wu=(u,p)=>{const b=Vr(p);if(b.length===0||!vc(b))return null;const A=ss(p),x=Dl(u,b[0],A);if(x!=="bullet"&&x!=="ordered")return null;for(const N of b.slice(1))if(Dl(u,N,A)!==x)return null;return x},Va=(u,p,b)=>{if(!u)return{value:null,status:"ready",refreshing:!1};const A=wr(b),x=A==="story:body";if(x&&typeof u.getNodeById!="function")return{value:null,status:"ready",refreshing:!1};if(!x&&typeof u.getNode!="function")return{value:null,status:"ready",refreshing:!1};const N=`node:${A}:${p}`,G=ke(),oe=To(N,G,()=>x?u.getNodeById({nodeId:p,nodeType:"paragraph"}):u.getNode(Ao(p,b)),Me=>Me&&typeof Me=="object"?Me:null),fe=Y.get(N);return{...oe,refreshing:oe.status==="stale"&&fe?.inflightToken===G&&fe.failedToken!==G}},Ol=u=>u==="left"||u==="center"||u==="right"||u==="justify"?u:void 0,I=u=>u==="start"||u==="end"||u==="distributed"||u==="numTab"||u==="lowKashida"||u==="mediumKashida"||u==="highKashida"||u==="thaiDistribute",M=(u,p)=>{const b=P(),A=b?.readMountedProjectionBlocksByIds;if(typeof A!="function")return null;const x=as(u),N=Mt(()=>x?A.call(b,[...p],x):A.call(b,[...p]),null);if(!Array.isArray(N))return new Map;const G=d2(N),oe=new Map;for(const fe of p){const Me=G.find(Ze=>yc(Ze,fe));if(!Me)continue;const Ve=Me.attrs,je=Ol(Ve?.alignment),Ke=b9(Ve);oe.set(fe,je??(Ke==="rtl"?"right":"left"))}return oe},X=(u,p,b,A)=>{const{value:x,status:N,refreshing:G}=Va(u,p,b),oe=A?.get(p);if(N==="pending")return oe?{status:"uniform",value:oe}:{status:"pending"};if(N==="stale"&&!G)return{status:"pending"};if(N==="stale"&&oe)return{status:"uniform",value:oe};if(N==="stale"&&A&&!oe)return{status:"unavailable"};if(!x)return{status:"unavailable"};const fe=x.node;if(!fe)return{status:"unavailable"};const Me=fe.kind;if(Me!=="paragraph"&&Me!=="heading")return{status:"unavailable"};const Ve=fe[Me];if(!Ve||typeof Ve!="object")return{status:"unavailable"};const je=Ve.props?.alignment;if(je==null)return oe?{status:"uniform",value:oe}:{status:"unavailable"};const Ke=Ol(je);return Ke?{status:"uniform",value:Ke}:I(je)&&oe?{status:"uniform",value:oe}:{status:"unavailable"}},ae=(u,p)=>{const b=Vr(p);if(b.length===0||!vc(b))return{status:"unavailable"};const A=ss(p),x=M(p,b),N=X(u,b[0],A,x);if(N.status!=="uniform")return N;for(const G of b.slice(1)){const oe=X(u,G,A,x);if(oe.status!=="uniform")return oe;if(oe.value!==N.value)return{status:"mixed"}}return N},se=u=>{const p=Vr(u);return p.length===0?null:`${wr(ss(u))}:${p.join(",")}`},ue=(u,p)=>{const b=ae(u,p),A=b.status==="uniform"?b.value:void 0,x=o;if(!x)return A;const N=se(p);return N&&N!==x.selectionSignature?(o=null,A):!N||!x.settled?x.value:b.status!=="pending"?(o=null,A):x.value},ce=(u,p)=>{const b=Ol(p),A=se(u),x=Vr(u);if(!b||!A||x.length===0)return null;const N=++i;return o={selectionSignature:A,value:b,generation:N,settled:!1,canReconcile:vc(x)},Ot(),N},de=(u,p)=>{if(u==null)return;const b=o;if(!(!b||b.generation!==u)){if(!Io(p)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},we=async(u,p,b)=>{const A=u?.lists;if(!A)return null;try{const x=b.storyType==="body",N=typeof A.getStateInStory=="function"?await A.getStateInStory({target:Aa(p),story:b}):x&&typeof A.getState=="function"?await A.getState({target:Aa(p)}):null,G=N&&typeof N=="object"?N:null;return!G||G.success!==!0||typeof G.isListItem!="boolean"?null:G.isListItem}catch{return null}},Le=(u,p,b)=>{const A={resolved:!1,seed:null},x=u?.lists;if(!x)return A;const N=b.storyType==="body",G=typeof x.getStateInStory=="function"?()=>x.getStateInStory({target:Aa(p),story:b}):N&&typeof x.getState=="function"?()=>x.getState({target:Aa(p)}):null;if(!G)return A;const oe=fe=>{const Me=fe&&typeof fe=="object"?fe:null;return!Me||Me.success!==!0||typeof Me.isListItem!="boolean"?A:{resolved:!0,seed:Me.isListItem===!0&&(Me.seed==="bullet"||Me.seed==="ordered")?Me.seed:null}};try{const fe=G();return Ir(fe)?Promise.resolve(fe).then(oe,()=>A):oe(fe)}catch{return A}},Fe=async(u,p,b)=>{if(!u)return null;try{const A=!b||b.storyType==="body",x=b&&typeof u.getNode=="function"?await u.getNode(Ao(p,b)):A&&typeof u.getNodeById=="function"?await u.getNodeById({nodeId:p,nodeType:"paragraph"}):null;return RV(x&&typeof x=="object"?x:null)}catch{return null}},Pe=(u,p,b,A,x,N)=>{if(u.mutates&&b)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.documentReadonly},"builtin");const G=Vr(A);if(G.length===0)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.selectionRequired},"builtin");const oe=u.docRoute?pr(p,u.docRoute):null,fe=pr(p,"format.paragraph.setIndentation"),Me=pr(p,"format.paragraph.clearIndentation"),Ve=u.list?.mode,je=Ve==="indent"?fe!=null:fe!=null||Me!=null,Ke=ss(A);let Ze=null;if(Ke.storyType!=="body"){Ze=[];for(const Ge of G){const{value:Qe,status:ht}=za(p,Ge,Ke);if(Qe===null)return ht!=="ready"&&(oe!=null||je)?sn({enabled:!0,active:x,supported:!0,value:N},"builtin"):sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin");Ze.push(Qe)}}if(Ze?.some(Ge=>Ge===!0)){const Ge=Ve==="indent"?"lists.indentRange":"lists.outdentRange",Qe=vr()!=="suggesting"&&Ze.every(dt=>dt===!0)&&pr(p,Ge)!=null,ht=Ve==="outdent"&&pr(p,"lists.outdentInStory")!=null;if(!Qe&&!ht)return sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")}for(const[Ge,Qe]of G.entries()){const ht=Ze?{value:Ze[Ge]??null,status:"ready"}:za(p,Qe,Ke),dt=ht.value;if(dt===!0){if(oe!=null)return sn({enabled:!0,active:x,supported:!0,value:N},"builtin");continue}if(dt===!1&&je){if(Ke.storyType!=="body"&&typeof p?.getNode!="function")continue;return sn({enabled:!0,active:x,supported:!0,value:N},"builtin")}if(dt===null)return ht.status!=="ready"&&(oe!=null||je)?sn({enabled:!0,active:x,supported:!0,value:N},"builtin"):sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")}return sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")},Xe=(u,p,b,A,x,N)=>{if(u.mutates&&b)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.documentReadonly},"builtin");const G=Vr(A);if(G.length===0)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.selectionRequired},"builtin");const oe=ss(A),fe=p?.lists;if(!(typeof fe?.getStateInStory=="function"||oe.storyType==="body"&&typeof fe?.getState=="function"))return sn({enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");if(!vc(G))return sn(oe.storyType==="body"&&pr(p,"lists.remove")!=null?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Me=G.map(Ze=>qr(p,Ze,oe));if(Me.some(({status:Ze})=>Ze!=="ready"))return sn({enabled:!0,active:x,supported:!0,value:N},"builtin");if(Me.some(({value:Ze})=>Ze===null))return sn({enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Ve=u.list?.seed,je=Me.every(({value:Ze})=>Ze?.isListItem===!0&&Ze.seed===Ve);if(oe.storyType==="body")return sn(!je||pr(p,"lists.remove")!=null?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Ke=pr(p,"lists.removeInStory");return sn(je&&Ke?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin")},ft=(u,p)=>{const b=Na(u,p)?.properties?.href;return typeof b=="string"?b:null},rt=u=>{if(!S())return sn({enabled:!1,active:!1,supported:!1,reason:ut.notReady},"builtin");const p=u.instanceRoute;return typeof t?.[p]!="function"?sn({enabled:!1,active:!1,supported:!1,reason:ut.operationUnavailable},"builtin"):sn({enabled:!0,active:pt(u),supported:!0,value:Wt(u)},"builtin")},pt=u=>{const p=t?.config??void 0;return u.valueFrom==="ruler"?!!p?.rulers:u.valueFrom==="formattingMarks"?!!p?.layoutEngineOptions?.showFormattingMarks:!1},mt=(u,p,b)=>{if(b)return sn({enabled:!1,active:!1,supported:!0,reason:ut.documentReadonly},"builtin");const A=Se();return A!=null&&(!u.table.requiresCell||A.cellNodeId!=null)?(u.docRoute?pr(p,u.docRoute):null)==null?sn({enabled:!1,active:!1,supported:!1,reason:Ho(p)},"builtin"):sn({enabled:!0,active:!1,supported:!0},"builtin"):sn({enabled:!1,active:!1,supported:!0,reason:ut.tableContextUnavailable},"builtin")},Wt=u=>{if(u.valueFrom==="zoom")return Ic().value;if(u.valueFrom==="documentMode")return vr();if(u.valueFrom==="measurementUnit")return Ou();if(u.valueFrom==="ruler"||u.valueFrom==="formattingMarks")return pt(u)},_n=(u,p)=>u.id==="zoom"?typeof p=="number"&&Number.isFinite(p)&&p>0:u.id==="document-mode"?p==="editing"||p==="suggesting"||p==="viewing":u.id==="measurement-unit"?p==="in"||p==="cm":!0,Pr=()=>[...new Set([...pN,...le.keys()])],Jt="Normal",Mn={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},gn=u=>{const p=y()?.styles;return!p||typeof p.getCatalog!="function"?{value:null,status:"ready"}:To(`styles:catalog:${JSON.stringify(u??{})}`,ke(),()=>p.getCatalog(u),b=>b&&typeof b=="object"?b:null)},ir=()=>{const u=gn({includePreview:!0});if(!u.value)return{cache:null,status:u.status};const p=gn({view:"quickGallery",includePreview:!0}),b=p.value?p.value.items:u.value.styles.filter(x=>x.visibility.quickGallery),A=new Map;for(const x of u.value.styles)A.set(x.id,x);return{cache:{full:u.value,quickGallery:b,byId:A},status:bl(u.status,p.status)}},io=(u,p,b)=>{const{value:A,status:x}=Va(u,p,b);if(!A)return{ok:!1,styleRef:null,status:x};const N=A.node;if(!N||typeof N!="object")return{ok:!1,styleRef:null,status:x};const G=N.kind,oe=typeof G=="string"?N[G]:void 0,fe=oe&&typeof oe=="object"?oe.styleRef:void 0;return{ok:!0,styleRef:typeof fe=="string"&&fe.length>0?fe:null,status:x}},Yr=(u,p)=>{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 x=Vr(u);if(x.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(!vc(x))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 N=p?.full.defaults.paragraphStyleId??(p?Jt:null),G=new Set;let oe=0,fe=0,Me=0,Ve="ready";const je=ss(u);for(const Ge of x){const Qe=io(A,Ge,je);if(Ve=bl(Ve,Qe.status),!Qe.ok){fe+=1;continue}if(!Qe.styleRef&&!N){Me+=1;continue}const ht=Qe.styleRef??N;if(!ht){Me+=1;continue}oe+=1,G.add(ht)}if(oe===0){const Ge=Me>0&&fe===0;return b.push({severity:"warning",code:Ge?"active-style-default-unavailable":"active-style-read-failed",message:Ge?"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:Ve}}const Ke=fe+Me;if(Ke>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${oe} of ${oe+Ke} selected blocks; ${Ke} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ve};if(G.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:Ve};const Ze=[...G][0];return{style:{styleId:Ze,styleName:p?.byId.get(Ze)?.name??null,mixed:!1,diagnostics:b},status:Ve}},Wi=u=>{if(!S())return Mn;const{cache:p,status:b}=ir(),{style:A,status:x}=Yr(u,p);let N;return p?N=A.diagnostics.length===0?p.full.diagnostics:[...p.full.diagnostics,...A.diagnostics]:N=[{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:bl(b,x,u.status),catalogRevision:p?.full.revision??null,quickGallery:p?.quickGallery??[],activeParagraphStyleId:A.styleId,activeParagraphStyleName:A.styleName,mixedSelection:A.mixed,sourceStatus:p?.full.sourceStatus??null,diagnostics:N}},ui=(u="direct")=>{const{sink:p}=fm(),b=p?_a():0,A={},x=(Me,Ve)=>{if(!p)return Ve();const je=_a();try{return Ve()}finally{A[Me]=_a()-je}},N=x("documentMode",vr),G=x("selection",Lu);G.status==="ready"&&ji(G),ie(G);const oe=Ia(G);for(const[Me,Ve]of r)(!oe||Ve.selectionSignature!==oe||Ve.settled&&G.status==="ready")&&r.delete(Me);const fe={ready:S()!=null,documentMode:N,document:x("document",Hf),selection:G,toolbar:{context:N,commands:x("toolbarCommands",()=>Uu(G)),copyFormatActive:h.mode!=="idle"},comments:x("comments",()=>jf(G)),trackChanges:x("trackChanges",()=>_c(G)),contentControls:x("contentControls",()=>Ac(G)),zoom:x("zoom",Ic),fonts:x("fonts",Du),styles:x("styles",()=>Wi(G))};if(p){const Me=_a();n2({stage:"superdoc-ui-compute-state",atMs:Me,reason:u,startedAtMs:b,completedAtMs:Me,durationMs:Me-b,phaseMs:A,asyncReadSettlements:Ut.splice(0)})}return fe},st=u=>{const p=Ia(u);p&&a&&p!==a&&(n.clear(),r.clear()),p&&(a=p)};let cn=null,Cr=null,ps=null,Ki=null,yo=null,Yo=null,qi=!1;const Ks=()=>{if(j||qi)return;qi=!0;const u=()=>{qi&&(qi=!1,!j&&Ot())};typeof queueMicrotask=="function"?queueMicrotask(u):Promise.resolve().then(u)},Fl=()=>{const u=ee();if(u!==ps&&(Ki&&(Ki(),Ki=null),ps=u,!(!u||typeof u.subscribe!="function")))try{const p=u.subscribe(()=>Ks());typeof p=="function"&&(Ki=p)}catch{ps=null}},Nl=()=>{const u=T();if(u!==yo&&(Yo&&(Yo(),Yo=null),yo=u,!(!u||typeof u.subscribe!="function")))try{const p=u.subscribe(()=>Ot());typeof p=="function"&&(Yo=p)}catch{yo=null}};let di=null,$o=null,Yi=null,fi=null,F=null,K=null;const Ae=()=>{const u=S()?.host,p=Mt(u?.getHandles?()=>u.getHandles():void 0,null)?.editing?.selection;return p&&typeof p.subscribe=="function"?p:null},Be=()=>{const u=Ae();if(u!==cn&&(Cr&&(Cr(),Cr=null),cn=u,!!u))try{const p=u.subscribe(b=>{jo+=1,Hs(b),Ot("host-selection")});typeof p=="function"&&(Cr=p)}catch{cn=null}},wt=()=>{const u=S()?.host,p=Mt(u?.getHandles?()=>u.getHandles():void 0,null)?.review;return p&&typeof p.subscribe=="function"?p:null},en=u=>u?typeof u.getActiveReviewTarget=="function"?Mt(()=>u.getActiveReviewTarget(),null):typeof u.getSnapshot=="function"?Mt(()=>u.getSnapshot(),null)?.activeReviewTarget??null:null:null;let dn=0;const An=(u,p)=>{const b=(p&&typeof p=="object"?p:null)?.lastInteractionRejection;if(dn>0&&u==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const A=u&&typeof u=="object"?u:null;let x=null;if(A?.entityType==="trackedChange"&&typeof A.entityId=="string"&&A.entityId.length>0){const N=A.story&&typeof A.story=="object"?A.story:void 0,G=N&&wr(N)!==wr(null)?N:void 0,oe=typeof A.paintedEntityId=="string"&&A.paintedEntityId.length>0?A.paintedEntityId:null,fe=oe??A.entityId,Me=(()=>{if(G){const Ke=li(),Ze=Ke?gc(Ke,G):null;return Ze?.toPublicId(fe)??Ze?.toPublicId(A.entityId)??A.entityId}const je=zs(Array.isArray(D?.trackChanges.items)?D.trackChanges.items:[]);return je.toPublicId(fe)??je.toPublicId(A.entityId)??A.entityId})(),Ve=oe??(fe!==Me?fe:null);x={id:Me,...G?{story:G}:{},...Ve&&Ve!==Me?{paintedEntityId:Ve}:{}}}return u==null&&x==null&&He!=null&&J(He)||Ye(He,x)?!1:(re(x),!0)},Sn=()=>{const u=wt();if(u===di)return;if($o&&($o(),$o=null),di=u,!u){An(null);return}let p=!0;try{const b=u.subscribe(A=>{const x=A&&typeof A=="object"?A:null,N=x&&Object.prototype.hasOwnProperty.call(x,"activeReviewTarget")?x.activeReviewTarget:en(u);!An(N,A)||p||Ot()});typeof b=="function"&&($o=b),An(en(u))}catch{di=null}finally{p=!1}},Nn=()=>{if(cn||vr()!=="viewing")return null;const u=S()?.mount?.container,p=(u&&typeof u=="object"&&"ownerDocument"in u?u.ownerDocument??null:null)??globalThis.document??null;return p&&typeof p.addEventListener=="function"?p:null},un=()=>{const u=Nn();if(u===F||(K&&(K(),K=null),F=u,!u))return;const p=()=>{jo+=1,Ot()};u.addEventListener("selectionchange",p),u.addEventListener("pointerup",p,!0),u.addEventListener("mouseup",p,!0),K=()=>{u.removeEventListener("selectionchange",p),u.removeEventListener("pointerup",p,!0),u.removeEventListener("mouseup",p,!0)}};Ta(),An(en(wt())),D=ui("initial"),a=Ia(D.selection);const Dr=()=>{const u=S()?.host?.events,p=u&&typeof u.subscribe=="function"?u:null;if(p!==Yi&&(fi&&(fi(),fi=null),Yi=p,!!p))try{const b=p.subscribe(A=>{const x=A?.type;if(x==="review-mutation:started"){kn(A.reviewMutation?.token);return}if(x==="review-mutation:aborted"){Vo(A.reviewMutation?.token),Ct();return}if(x==="mutation:rejected"&&A.reviewMutation&&(Vo(A.reviewMutation.token),Ct()),x==="mutation:committed"&&A.reviewMutation&&Vo(A.reviewMutation.token),x==="source:complete"||x==="source:signals-complete"){Hr=ke(),xa();return}if((x==="mutation:committed"||x==="collaboration:remote-changed")&&(ct=Date.now()),x==="mutation:committed"||x==="save:completed"||x==="collaboration:remote-changed"){const N=x==="mutation:committed"?jk(A):null;if(N?.allResolved){dr([]),Pt(A.receipt);return}N?.removedIds.size&&an(new Set(N.removedIds),A.receipt);const G=x==="mutation:committed"&&bc(A)||x==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0;if(G&&(Rn=Date.now()),x==="mutation:committed"&&G){Mu();return}if(N?.removedIds.size&&N.upsertIds.size===0)return;(x==="collaboration:remote-changed"||x==="mutation:committed"&&!G)&&Sl();const oe=x==="collaboration:remote-changed"&&Array.isArray(A.changedPartUris)&&A.changedPartUris.some(Me=>typeof Me=="string"&&vV.has(Me)),fe=x==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0&&kl();oe&&!G&&(xn=!0),Us(),oe&&!G?_i("comments"):fe&&(xn=!0,Rr()),Ot()}});typeof b=="function"&&(fi=b)}catch{Yi=null}},Ot=(u="unspecified")=>{if(j)return;const{sink:p}=fm(),b=p?_a():0;qi=!1,Ta(),Be(),Fl(),Nl(),Sn(),un(),Dr();const A=ui(u);st(A.selection),D=A;let x=0,N=0;for(const G of[...V]){if(!p){G(D);continue}const oe=_a();G(D);const fe=_a()-oe;x+=fe,N=Math.max(N,fe)}if(p){const G=_a();n2({stage:"superdoc-ui-recompute",atMs:G,reason:u,startedAtMs:b,completedAtMs:G,durationMs:G-b,listenerCount:V.size,listenerTotalMs:x,listenerMaxMs:N})}},xi=[],Et=[],vn=u=>{for(const p of u)try{p()}catch{}},sr=()=>vn(xi),Bn=()=>vn(Et),Xr=[];((u,p)=>{if(!(!u||typeof u.on!="function"))for(const b of p){const A=b==="active-editor-change"?()=>{sr(),Bn(),Ot()}:b==="document-replaced"?x=>{const N=x&&typeof x=="object"?x:null,G=N?.editor,oe=N?.host,fe=!!G&&G===S(),Me=!!oe&&oe===P();!fe&&!Me||(Bn(),Y.clear(),Us(),Ot())}:()=>Ot();try{u.on(b,A),Xr.push(()=>{try{typeof u.off=="function"&&u.off(b,A)}catch{}})}catch{}}})(t,dV),Be(),Fl(),Nl(),Sn(),un(),Dr();const Go=(u,p=qz)=>({get:()=>u(D),subscribe:b=>{let A=u(D);const x=N=>{const G=u(N);p(A,G)||(A=G,b(G))};return V.add(x),()=>V.delete(x)}}),bo=u=>Go(u),Xo=u=>{const p=b=>{const A=N=>{try{b(N)}catch{}},x=u.subscribe(A);return A(u.get()),x};return{get:()=>u.get(),getSnapshot:()=>u.get(),observe:p,subscribe:b=>p(A=>b({snapshot:A}))}},ja=(u,p,b)=>{const A=Xo(u),x=Xo(p),N=G=>{const oe=Er(b);Ot();const fe=x.observe(G);return()=>{fe(),oe()}};return{get:A.get,getSnapshot:A.getSnapshot,observe:N,subscribe:G=>N(oe=>G({snapshot:oe}))}};function Ku(u){return u&&typeof u=="object"&&typeof u.id=="string"?String(u.id):null}function Ua(u){const p=as(u);return p&&wr(p)!==wr(null)?p:void 0}function Hn(u,p){return{kind:"id",id:u,...p?{story:p}:{}}}function m2(u){if(u.empty)return null;const p=u.selectionTarget,b=p?.start,A=p?.end;if(p?.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 x=Math.min(b.offset,A.offset),N=Math.max(b.offset,A.offset),G=as(u);return{kind:"range",coordinateSpace:p.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...G?{story:G}:{},segments:[{blockId:b.blockId,range:{start:x,end:N}}]}}}function Cm(u,p){if(wr(p)!==wr(null))return;const b=y()?.trackChanges,A=b?.list;if(typeof A!="function")return;const x=Mt(()=>A.call(b),null);if(Ir(x)||!x||typeof x!="object")return;const N=x.items;if(Array.isArray(N))return N.map(Nf).find(G=>G!=null&&Ni(G,u,p))}function km(u,p){const b=Sm(u.quotedText);if(!b)return!1;const A=mm(p);return[A.insertedText,A.deletedText,A.excerpt].some(x=>Sm(x)===b)}function Sm(u){return typeof u=="string"?u.replace(/\s+/g," ").trim():""}function _m(){const u=D.selection.activeChangeIds[0];if(!u)return"unavailable";const p=as(D.selection),b=(D.trackChanges.status==="ready"?D.trackChanges.items.find(G=>Ni(G,u,p)):void 0)??Cm(u,p)??li()?.find(G=>Ni(G,u,p));if(!b)return"unavailable";const A=mm(b),x=A.type,N=A.grouping;return km(D.selection,b)?"id":x==="replacement"&&N==="replacement-pair"||(x==="insertion"||x==="deletion"||x==="insert"||x==="delete")&&N==="standalone"?"range":"id"}function Am(u,p,b,A){const x=()=>k2(u,Hn(b,A),b,A);try{const N=k2(u,p,null);if(Ir(N))return Mo(Promise.resolve(N).then(oe=>Io(js(oe))?oe:x()));const G=js(N);return Mo(Io(G)?N:x())}catch{return!1}}function Im(u,p){if(u.scope==="all")return{target:{kind:"all"},changeId:null};if(typeof p=="string"&&p.length>0)return{target:{kind:"id",id:p},changeId:p};if(p&&typeof p=="object"){const x=p;if(x.target&&typeof x.target=="object"){const G=x.target;return{target:G,changeId:Ku(G),story:G.story}}const N=typeof x.changeId=="string"?x.changeId:x.id;if(typeof N=="string"&&N.length>0)return{target:Hn(N,x.story),changeId:N,story:x.story}}const b=D.selection.activeChangeIds[0],A=Ua(D.selection);return b?{target:Hn(b,A),changeId:b,story:A}:null}function g2(u,p){if(u.scope==="id"&&p==null){if(D.selection.activeChangeIds.length>1)return Zf(u.kind,{kind:"ids",ids:D.selection.activeChangeIds},null);if(D.selection.activeChangeIds.length===1&&!D.selection.empty&&D.selection.selectionTarget){const A=_m();if(A==="unavailable")return!1;if(A==="range"){const x=m2(D.selection),N=Ua(D.selection);return x?Am(u.kind,x,D.selection.activeChangeIds[0],N):!1}if(A==="id"){const x=D.selection.activeChangeIds[0],N=as(D.selection),G=N&&wr(N)!==wr(null)?N:void 0;return C2(u.kind,G?{id:x,story:G}:x)}}}const b=Im(u,p);return b?Zf(u.kind,b.target,b.changeId,b.story):!1}function xm(u,p){const b=ee()?.lists,A=b?.apply;if(typeof A!="function")return!1;const{behavior:x,preset:N,continuity:G}=typeof p=="string"?pV(p):p&&typeof p=="object"?p:{},oe={kind:u,behavior:x??"toggle"};N!==void 0&&(oe.preset=N),G!==void 0&&(oe.continuity=G);try{return Mo(A.call(b,oe))}catch{return!1}}let hi=Promise.resolve(!1),Ro=null,qu=Promise.resolve(!1);const It=async u=>{if(!gm(u))return u;const p=S()?.documentMutationReadiness,b=p?.whenPainted;if(typeof b!="function")return u;const A=typeof u.txId=="string"?u.txId:void 0;try{await b.call(p,A?{txId:A}:void 0)}catch{}return u},Tt=u=>{if(Ir(u)){const b=Promise.resolve(u);return{immediate:!0,committed:b.then(A=>js(A),()=>!1),settled:b.then(A=>It(js(A)),()=>!1)}}const p=js(u);return{immediate:p,committed:Promise.resolve(p),settled:It(p)}},yn=()=>{const u=s.shift();if(!u){c=!1,f?.(),f=null;return}try{u.resolve(j?!1:u.mutate())}catch{u.resolve(!1)}},yr=()=>{let u=!1;return()=>{u||(u=!0,yn())}},Zr=(u,p)=>{if(!c){c=!0,d=new Promise(N=>{f=N});try{return{result:p(),release:yr()}}catch(N){throw c=!1,f?.(),f=null,N}}const b=s.find(N=>N.key===u);if(b)return b.mutate=p,{result:b.result,release:()=>{}};let A;const x=new Promise(N=>{A=N});return s.push({key:u,mutate:p,result:x,resolve:A}),{result:x,release:yr()}},wo=new Set(["create.tableOfContents"]),Ei=u=>Kn(`Tracked authoring is not supported for ${u}.`),Ti=u=>{if(vr()==="suggesting")return wo.has(u)?Ei(u):{changeMode:"tracked"}},Yu=()=>vr()==="suggesting"?KV:h2,Co=(u,p,b)=>{const A=Ti(u);return A&&A.success===!1?A:A?p(b,A):p(b)},Tj=(u,p,b,A)=>{const x=u.inline;if(!x)return;const N=js(A);if(N===!1||typeof N=="object"&&N&&N.success===!1)return;if(x.kind==="clear"){n.clear();return}if(x.kind==="toggle"||!l2(x.key))return;const G=Ia(p);if(!G)return;const oe=DV(x.key,b.value);if(oe==null){n.delete(x.key);return}n.set(x.key,{selectionSignature:G,value:oe})},Rj=(u,p,b,A)=>!u.inline||u.inline.kind==="toggle"?A:Ir(A)?Promise.resolve(A).then(x=>(Tj(u,p,b,x),x)):A,Mj=(u,p,b,A)=>{if(u.inline?.kind!=="toggle"||!Io(js(A))||typeof b.value!="boolean"&&b.value!==null)return null;const x=Ia(p);if(!x)return null;const N=++l;return r.set(u.id,{selectionSignature:x,active:b.value===!0,generation:N,settled:!1}),Ot(),N},Lj=(u,p,b)=>{if(p==null)return;const A=r.get(u.id);if(!(!A||A.generation!==p)){if(!Io(b)){r.delete(u.id);return}A.settled=!0}},Em=(u,p)=>u.then(b=>(p?.(b),Al(),b),()=>(p?.(!1),Al(),!1)),Mo=(u,p)=>{const b=Ro;if(Ro=null,b)return hi=Em(b,p),js(u);if(Ir(u))return hi=Em(Tt(u).settled,p),!0;const A=js(u);return gm(A)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(hi=Em(It(A),p),A):(p?.(A),hi=Promise.resolve(A),Al(),A)},Pj=(u,p)=>!u||typeof u!="object"?p:u,Bl=(u,p=Kn("Document API operation failed."))=>{if(Ir(u))return Promise.resolve(u).then(A=>Bl(A,p),()=>p);const b=Pj(u,p);return Us(),gm(b)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(Em(It(b)),Ot(),b):(Ot(),b)},Dj=(u,p,b,A)=>{const x=[],N=[];for(const G of b){const oe=A(G);if(oe)try{const fe=Tt(Co(u,p,oe));x.push(fe.immediate),N.push(fe.settled)}catch{x.push(!1),N.push(Promise.resolve(!1))}}return Ro=N.length?Promise.all(N).then(G=>ki(G)):null,ki(x)},Oj=(u,p,b,A)=>{const x=[],N=[];for(const G of b){const oe=A(G);if(oe)try{const fe=Tt(Co(u,p,oe));x.push(fe.immediate),N.push(fe.settled)}catch{x.push(!1),N.push(Promise.resolve(!1))}}return Ro=N.length?Promise.all(N).then(G=>ki(G)):null,ki(x)},v2=(u,p,b,A=D.selection)=>{const x=Ti(u);return x&&x.success===!1?x:A.selectionTarget?p(b,{...x,offsetSpace:"selection"}):x?p(b,x):p(b)},Fj=(u,p,b,A)=>{const x=Ao(p,A);switch(u.kind){case"alignment":{const N=b;return N!=="left"&&N!=="center"&&N!=="right"&&N!=="justify"?null:{target:x,alignment:N}}case"spacing-line":{const N=typeof b=="number"?b:Number(b);return!Number.isFinite(N)||N<=0?null:{target:x,line:N,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const N=b.role;if(N&&typeof N=="object")return{target:x,role:N}}return typeof b!="string"||b.trim()===""?null:{target:x,styleId:b};case"direction":{const N=u.fixedValue;return N!=="ltr"&&N!=="rtl"?null:{target:x,direction:N}}default:return null}},Nj=(u,p)=>{const b=u.inline,A=f2(u),x=P();if(!b||typeof x?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return $(),!0;if(!A)return!1;let N;if(b.kind==="toggle")N=!Pl(u,y(),D.selection);else{const G=p&&typeof p=="object"&&"value"in p?p.value:p;if(b.kind==="value-number"){const oe=typeof G=="number"?G:Number(G);N=Number.isFinite(oe)&&oe>0?oe:null}else N=typeof G=="string"&&G.trim()!==""?G:null;if(N===null)return E(A,null),!0}return E(A,N),!0},Bj=()=>{const u=y(),{lockModesById:p}=Gs(u?.contentControls,D.selection);if(fs(p))return!1;const b=[],A=[],x=Ze=>{const Ge=Tt(Ze);b.push(Ge.immediate),A.push(Ge.settled)},N=(Ze,Ge,Qe)=>{try{x(Qe?Ze(Ge,Qe):Ze(Ge))}catch{b.push(!1),A.push(Promise.resolve(!1))}},G=ir().cache?.full.defaults.paragraphStyleId??Jt,oe=Ru(D.selection);if(oe){const Ze=pr(u,"format.apply");if(Ze)try{x(v2("format.apply",Ze,{target:oe,inline:{...Yu()}}))}catch{b.push(!1),A.push(Promise.resolve(!1))}}const fe=pr(u,"format.paragraph.resetDirectFormatting"),Me=pr(u,"styles.paragraph.setStyleRef"),Ve=as(D.selection),je=!Ve||Ve.storyType==="body",Ke=pr(u,je?"lists.remove":"lists.removeInStory");for(const Ze of Vr(D.selection)){const Ge=Ao(Ze,Ve);if(fe&&N(fe,{target:Ge}),Ke)try{const Qe=Aa(Ze),ht=Tt(Ke(je?{target:Qe}:{target:Qe,story:Ve}));A.push(ht.settled.then(dt=>Io(dt)?dt:!0))}catch{}Me&&N(Me,{target:Ge,styleId:G})}if(!oe&&vr()!=="suggesting"){const Ze=pr(u,"format.paragraph.setMarkRunProps");if(Ze)for(const Ge of Vr(D.selection))N(Ze,{target:Ao(Ge,Ve),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return Ro=A.length?Promise.all(A).then(Ze=>ki(Ze)):null,ki(b.length?b:[!1])},zj=(u,p,b)=>{const A=Vr(D.selection);if(A.length===0)return!1;const x=as(D.selection);return Dj(u.docRoute,p,A,N=>Fj(u.blockParagraph,N,b,x))},Vj=(u,p,b)=>{const A=y(),x=pr(A,"format.paragraph.setIndentation"),N=pr(A,"format.paragraph.clearIndentation"),G=u.list?.mode,oe=ss(D.selection),fe=as(D.selection),Me=async Ve=>{const je=await we(A,Ve,oe);if(je===!0)return{kind:"list",routeToCall:u.docRoute,opToCall:p,input:{target:bA(Ve)}};if(je===null||fe&&fe.storyType!=="body"&&typeof A?.getNode!="function")return null;const Ke=await Fe(A,Ve,fe),Ze={};if(Ke?.right!=null&&(Ze.right=Ke.right),Ke?.firstLine!=null&&(Ze.firstLine=Ke.firstLine),Ke?.hanging!=null&&(Ze.hanging=Ke.hanging),G==="indent")return x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),left:Math.max(0,Ke?.left??0)+wA,...Ze}}:null;const Ge=Math.max(0,(Ke?.left??0)-wA);return Ge>0&&(Ze.left=Ge),Object.keys(Ze).length===0?N?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:N,input:{target:Ao(Ve,fe)}}:x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),left:0}}:null:x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),...Ze}}:null};return Ro=(async()=>{const Ve=await Promise.all(b.map(Ge=>Me(Ge).catch(()=>null)));if(Ve.length===b.length&&Ve.every(Ge=>Ge?.kind==="list")&&vr()!=="suggesting"){const Ge=G==="indent"?"lists.indentRange":"lists.outdentRange",Qe=pr(A,Ge);if(Qe)try{return await Tt(Co(Ge,Qe,{paraIds:b,story:oe})).settled}catch{return!1}}const je=oe.storyType!=="body"&&Ve.some(Ge=>Ge?.kind==="list"),Ke=je&&G==="outdent"?pr(A,"lists.outdentInStory"):null;if(je&&!Ke)return!1;const Ze=Ve.map(Ge=>{if(!Ge)return Promise.resolve(!1);try{return Ge.kind==="list"&&Ke?Tt(Co("lists.outdentInStory",Ke,{target:Ge.input.target,story:oe})).settled:Tt(Co(Ge.routeToCall,Ge.opToCall,Ge.input)).settled}catch{return Promise.resolve(!1)}});return ki(await Promise.all(Ze))})(),!0},jj=(u,p)=>{const b=u.list,A=y(),x=Vr(D.selection);if(x.length===0)return!1;const N=ss(D.selection),G=N.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return Vj(u,p,x);const oe=b.seed,fe=je=>{if(je.some(dt=>!dt.resolved))return{immediate:!1,settled:null};const Ke=je.every(dt=>dt.seed===oe);if(!Ke&&!G)return{immediate:!1,settled:null};const Ze=Ke?G?"lists.remove":"lists.removeInStory":u.docRoute,Ge=Ke?pr(A,Ze):p;if(!Ge)return{immediate:!1,settled:null};const Qe=[],ht=[];return x.forEach((dt,ot)=>{if(!Ke&&je[ot]?.seed===oe)return;const Bt=Ke?{target:Aa(dt),...G?{}:{story:N}}:{target:Aa(dt),seed:oe};try{const zt=Tt(Co(Ze,Ge,Bt));Qe.push(zt.immediate),ht.push(zt.settled)}catch{Qe.push(!1),ht.push(Promise.resolve(!1))}}),{immediate:ki(Qe),settled:ht.length?Promise.all(ht).then(dt=>ki(dt)):null}},Me=x.map(je=>Le(A,je,N));if(Me.some(Ir))return Ro=Promise.all(Me).then(async je=>{const Ke=fe(je);return Ke.settled?await Ke.settled:Ke.immediate}),!0;const Ve=fe(Me);return Ro=Ve.settled,Ve.immediate};function Yf(u){return u&&typeof u=="object"?u:{}}function Uj(u){if(typeof u=="string")return u;const p=Yf(u);if(Object.prototype.hasOwnProperty.call(p,"href"))return p.href;if(Object.prototype.hasOwnProperty.call(p,"value"))return p.value}function Hj(u,p){const b=Yf(u).text;return typeof b=="string"&&b.trim()!==""?b:p}function LA(u){const p=Yf(u),b=p.capture&&typeof p.capture=="object"?p.capture:null;return p.target??b?.target??b?.selectionTarget??p.selectionTarget??p.textTarget??null}const $j=u=>{const p=y(),b=p?.hyperlinks;if(!b)return!1;const A=Yf(u),x=Uj(u),N=LA(u),G=typeof A.text=="string"?A.text:void 0,oe=typeof A.currentText=="string"?A.currentText:void 0,fe=Bf(A.hyperlinkTarget)?A.hyperlinkTarget:null,Me=Bf(A.textTarget)?A.textTarget:null,Ve=Na(p,D.selection),je=typeof fe?.storyId=="string"&&typeof fe?.hyperlinkNodeId=="string";if(je&&x===null){const Ke=b.remove;if(typeof Ke!="function")return!1;try{return Co("hyperlinks.remove",Ke,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(Ve&&x===null){const Ke=b.remove;if(typeof Ke!="function")return!1;try{return Co("hyperlinks.remove",Ke,{target:Ve.address,mode:"unwrap"})}catch{return!1}}if((Ve||fe)&&typeof x=="string"&&x.trim()!==""){const Ke=b.patch,Ze=b.updateTarget;if(!(!je&&Ve&&typeof Ke=="function")&&!(je&&typeof Ze=="function"))return!1;const Ge=typeof G=="string"&&G!==(je?oe:Ve?.text??oe),Qe=p?.text?.replace,ht=Ge?je?Me:jV(Ve?.address):null,dt=Ge&&!!ht&&typeof Qe=="function";if(Ge&&!dt)return!1;const ot=[],Bt=[];let zt=null,$n=null,Gn=null,Qr=!1;try{if(je){if(typeof Ze!="function")return!1;const Jr=Co("hyperlinks.updateTarget",Ze,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,newTarget:UV(x)});Qr=Ir(Jr);const kr=Tt(Jr);if(!Io(kr.immediate))return!1;ot.push(kr.immediate),Bt.push(kr.settled),zt=kr.immediate,$n=kr.committed,Gn=kr.settled}else if(Ve){if(typeof Ke!="function")return!1;const Jr=Co("hyperlinks.patch",Ke,{target:Ve.address,patch:{href:x}});Qr=Ir(Jr);const kr=Tt(Jr);if(!Io(kr.immediate))return!1;ot.push(kr.immediate),Bt.push(kr.settled),zt=kr.immediate,$n=kr.committed,Gn=kr.settled}}catch{return!1}if(dt){const Jr=(Or,Zo)=>Io(Zo)?ki([Or,Zo]):Io(Or)?Lf(Or,Zo):Zo,kr=Or=>{if(!Io(Or))return Or;try{const Zo=Tt(Co("text.replace",Qe,{target:ht,text:G}));return Io(Zo.immediate)?Promise.all([Gn??Promise.resolve(Or),Zo.settled]).then(([x2,EU])=>Jr(x2,EU)):Lf(Or,Zo.immediate)}catch{return Lf(Or,!1)}};if(Qr)return Ro=($n??Promise.resolve(zt??!1)).then(kr),ki(ot);try{const Or=Tt(Co("text.replace",Qe,{target:ht,text:G}));if(!Io(Or.immediate))return zt?Lf(zt,Or.immediate):Or.immediate;ot.push(Or.immediate),Bt.push(Or.settled),Ro=Promise.all([Gn??Promise.resolve(zt??!1),Or.settled]).then(([Zo,x2])=>Jr(Zo,x2))}catch{return zt?Lf(zt,!1):!1}}return!dt&&Bt.length>0&&(Ro=Promise.all(Bt).then(Jr=>ki(Jr))),ki(ot)}if(typeof x=="string"&&x.trim()!==""){const Ke=x.trim(),Ze=b.wrap,Ge=MV(N),Qe=Ge.length>0?Ge:a2(D.selection);if(Qe.length>0){if(typeof Ze!="function")return!1;try{return Oj("hyperlinks.wrap",Ze,Qe,Bt=>({target:Bt,link:{destination:{href:Ke}}}))}catch{return!1}}const ht=b.insert,dt=Hj(u,Ke);if(typeof ht!="function"||dt.trim()==="")return!1;const ot=Of(N)??wl(D.selection);if(!ot)return!1;try{return Co("hyperlinks.insert",ht,{target:ot,text:dt,link:{destination:{href:Ke}}})}catch{return!1}}return!1},Gj=(u,p,b)=>{const A=u.create.kind,x=b&&typeof b=="object"?b:{};if(A==="table"){const G=Number(x.rows??x.rowCount),oe=Number(x.columns??x.cols??x.colCount);if(!Number.isInteger(G)||G<1||!Number.isInteger(oe)||oe<1)return!1;const fe=wl(D.selection),Me=fe&&typeof fe.blockId=="string"?{kind:"inParagraph",target:Ao(fe.blockId),offset:fe.range?.start??0}:u2(D.selection,"nodeId");try{return Co(u.docRoute,p,{rows:G,columns:oe,at:Me})}catch{return!1}}if(A==="image"){const G=x.src??x.value;if(typeof G!="string"||G.trim()==="")return!1;const oe=wl(D.selection),fe=ss(D.selection),Me=fe.storyType==="body"?null:fe;let Ve;oe&&typeof oe.blockId=="string"?Ve={kind:"inParagraph",target:Ao(oe.blockId,Me),offset:oe.range?.start??0}:(Ve=u2(D.selection,"target"),Me&&Ve.kind==="after"&&(Ve={...Ve,target:{...Ve.target,story:Me}}));const je={src:G,at:Ve};Me&&(je.in=Ve.kind==="inParagraph"?B(Me)??Me:Me),typeof x.alt=="string"&&(je.alt=x.alt),typeof x.title=="string"&&(je.title=x.title),x.size&&typeof x.size=="object"&&(je.size=x.size);try{return Co(u.docRoute,p,je)}catch{return!1}}const N={at:u2(D.selection,"target")};typeof x.instruction=="string"&&(N.instruction=x.instruction),x.config&&typeof x.config=="object"&&(N.config=x.config);try{return Co(u.docRoute,p,N)}catch{return!1}},Wj=(u,p)=>{const b=u.table,A=Se();if(!A||b.requiresCell&&!A.cellNodeId)return!1;const x=XV(b.action,A);if(!x)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const N=P(),G=(typeof N?.getHandles=="function"?N.getHandles():null)?.editing?.tables;if(typeof G?.insertRow!="function")return!1;const oe=Ti(u.docRoute);return oe&&oe.success===!1?oe:oe?G.insertRow(x,oe):G.insertRow(x)}if(b.action==="insert-column-before"||b.action==="insert-column-after"){const N=P(),G=(typeof N?.getHandles=="function"?N.getHandles():null)?.editing?.tables;if(typeof G?.insertColumn!="function")return!1;const oe=Ti(u.docRoute);return oe&&oe.success===!1?oe:oe?G.insertColumn(x,A.rowIndex,oe):G.insertColumn(x,A.rowIndex)}return Co(u.docRoute,p,x)}catch{return!1}},Kj=u=>!u||u.disposition!=="routed"?!1:!!(u.inline||u.blockParagraph||u.list||u.link||u.create),qj=u=>{const p=Yf(u);return!!(LA(u)||Bf(p.hyperlinkTarget)||Bf(p.textTarget))},Yj=(u,p,b)=>D.selection.status!=="ready"?!1:ym(u)?.scope==="id"||!p||p.disposition!=="routed"?!0:p.inline?.kind==="clear"?Vr(D.selection).length>0||Ru(D.selection)!=null:p.inline?Ru(D.selection)!=null||Vr(D.selection).length>0:p.blockParagraph||p.list?Vr(D.selection).length>0:p.link?qj(b)||a2(D.selection).length>0||wl(D.selection)!=null||Pl(p,y(),D.selection):!0,Xj=(u,p)=>{const b=ym(u),A=Au(u);return b?.scope!=="id"&&!Kj(A)?!1:!Yj(u,A,p)},Zj=(u,p)=>Xj(u,p)?wc().then(()=>{}):null,Tc=(u,p,b)=>{if(Ro=null,hi=Promise.resolve(!1),j)return!1;const A=le.get(u);if(A)try{const je=A.execute(Ui(p,b));return Mo(je)}catch{return!1}const x=fA(u);if(x){if(vr()==="viewing")return!1;if(typeof ee()?.lists?.apply=="function")return xm(x,p)}const N=ym(u);if(N)return g2(N,p);if(u==="copy-format")return Mo(Qj());const G=Au(u);if(!G||G.disposition!=="routed")return!1;const oe=G.normalizePayload?G.normalizePayload(p):p;if(G.instanceRoute){if(!S()||!_n(G,oe))return!1;const je=t?.[G.instanceRoute];if(typeof je!="function")return!1;try{const Ke=G.fixedArg!==void 0?G.fixedArg:oe,Ze=je.call(t,Ke);return Mo(Ze)}catch{return!1}}if(G.inline?.kind==="clear")return G.mutates&&vr()==="viewing"?!1:Mo(Bj());const fe=G.docRoute;if(!fe||G.mutates&&vr()==="viewing")return!1;const Me=y(),Ve=pr(Me,fe);if(!Ve)return!1;if(G.inline){const{lockModesById:je}=Gs(Me?.contentControls,D.selection);if(fs(je))return!1;const Ke=Ru(D.selection);if(!Ke)return D.selection.empty===!1?Mo(!1):Mo(Nj(G,oe));const Ze=Pl(G,Me,D.selection),Ge=qV(G.inline,Ke,oe,Ze);if(!Ge)return!1;let Qe=null;try{const ht=S(),dt=vr(),ot=()=>S()!==ht||y()!==Me||vr()!==dt?!1:v2(fe,Ve,Ge),Bt=Ia(D.selection)??pc(D.selection),zt=G.inline.kind==="toggle"?Zr(`${G.id}:${Bt}`,ot):null;Qe=zt?.release??null;const $n=zt?zt.result:ot(),Gn=Mj(G,D.selection,Ge,$n),Qr=Rj(G,D.selection,Ge,$n),Jr=Mo(Qr,kr=>{Lj(G,Gn,kr),Qe?.(),Qe=null});return G.inline.kind==="toggle"&&(qu=hi),Jr}catch{return Qe?.(),!1}}if(G.blockParagraph){const je=zj(G,Ve,oe),Ke=G.blockParagraph.kind==="alignment"&&Io(je)?ce(D.selection,oe):null;return Mo(je,Ze=>{de(Ke,Ze)})}if(G.list){const je=jj(G,Ve);return Mo(je)}if(G.link){const je=$j(oe);return Mo(je)}if(G.create){const je=Gj(G,Ve,oe);return Mo(je)}if(G.table){const je=Wj(G,Ve);return Mo(je)}try{return Mo(G.mutates?Co(fe,Ve,oe):Ve(oe))}catch{return!1}},Tm=()=>{g+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const u of m)u("idle");Ot()},Qj=async()=>{const u=["bold","italic","underline","strikethrough"].filter(Ve=>D.toolbar.commands[Ve]?.active===!0),p=await qu;await d;const b=Io(p)?u:[],A=500,x=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&x-h.lastClickAt<A){h={...h,mode:"persistent",lastClickAt:x};for(const Ve of m)Ve("persistent");return Ot(),!0}return Tm(),!1}const N=x-h.lastClickAt<A,G=++g;h={...h,lastClickAt:x};const oe=await wc(),fe=`${pc(oe)}:${ke()}`,Me=await Jj(null,oe,fe&&fe===_?v:void 0,b);if(G!==g)return!0;h={...h,mode:N?"persistent":"armed",snapshot:Me,sourceSelectionKey:pc(oe),lastClickAt:x};for(const Ve of m)Ve(h.mode);return Ot(),!0},Jj=async(u,p,b,A=[])=>{const x=p?.target??u?.target;if(!x||x.kind!=="text")return null;const N=Array.isArray(x.segments)?x.segments:[];if(N.length===0)return null;const G=y();if(!G)return null;const oe=x.story;let fe=null;for(const Ge of N){const Qe=(await Ll(Ao(Ge.blockId,oe)))?.node??null;if(!Qe)continue;const ht=y2(Qe),dt=Array.isArray(ht?.inlines)?ht.inlines:[],ot=eU(dt,Ge.range);fe?fe=PA(fe,ot):fe=ot}const Me=fe?Yz(fe):{},Ve={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},je=new Set([...p?.activeMarks??(Array.isArray(u?.activeMarks)?u.activeMarks:[]),...A]);for(const[Ge,Qe]of Object.entries(Ve))je.has(Ge)&&(Me[Qe]=!0);const Ke=b??await Kf(p??Ii(u,"ready"));if(Ke.fontFamily&&(Me.fontFamily=Ke.fontFamily),Ke.color&&(Me.color=Ke.color),Ke.highlight&&(Me.highlight=Ke.highlight),Ke.fontSize){const Ge=Number.parseFloat(Ke.fontSize);Number.isNaN(Ge)||(Me.fontSize=Ge)}let Ze=null;if(N.length===1){const Ge=N[0],Qe=(await Ll(Ao(Ge.blockId,oe)))?.node??null;Qe&&y2(Qe)&&(Ze=await tU(Qe,Ge.blockId,G,oe))}return{story:oe??null,inline:Me,paragraph:Ze}},y2=u=>u?u.kind==="paragraph"?u.paragraph??null:u.kind==="heading"?u.heading??null:null:null,eU=(u,p)=>{const b=G=>{const oe=G.run;return typeof oe?.text=="string"?oe.text:""},A=G=>G.run?.props;if(p.start===p.end){let G=0;for(const oe of u){const fe=b(oe),Me=G,Ve=G+fe.length;if(G=Ve,p.start>=Me&&p.start<=Ve){const je=A(oe);return je?{...je}:{}}}return{}}let x=0;const N=[];for(const G of u){const oe=b(G),fe=x,Me=x+oe.length;if(x=Me,Me<=p.start||fe>=p.end)continue;const Ve=A(G);Ve&&N.push(Ve)}return N.length===0?{}:N.length===1?{...N[0]}:PA(N[0],...N.slice(1))},PA=(u,...p)=>{const b={...u};for(const A of p)for(const x of Object.keys(b)){if(!(x in A)){delete b[x];continue}const N=b[x],G=A[x];(typeof N!=typeof G||JSON.stringify(N)!==JSON.stringify(G))&&delete b[x]}return b},tU=async(u,p,b,A)=>{const x=y2(u),N=x.props??{},G=x.styleRef??null,oe=N.alignment??null,fe=N.spacing??null,Me=N.indent??null,Ve=Me?{...Me.left!=null?{left:Me.left}:{},...Me.right!=null?{right:Me.right}:{},...Me.firstLine!=null?{firstLine:Me.firstLine}:{},...Me.hanging!=null?{hanging:Me.hanging}:{}}:null,je=N.markRunProps??null,Ke=N.numbering?.numId,Ze=typeof Ke=="string"?parseInt(Ke,10):typeof Ke=="number"?Ke:NaN,Ge=N.numbering?.level,Qe=isNaN(Ze)?null:{numId:Ze,...Ge!=null?{level:Ge}:{}};let ht=null;if(Qe&&typeof b.lists?.getState=="function")try{const dt=await b.lists.getState({target:Ao(p,A)});dt&&typeof b.lists?.getStyle=="function"&&(ht=await b.lists.getStyle(dt)??null)}catch{}return{styleId:G,alignment:oe,spacing:fe,indentation:Ve,markRunProps:je,numbering:Qe,listStyle:ht}},DA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const u=y()?.selection,p=async()=>{const G=typeof u?.current=="function"?await Promise.resolve(u.current({includeText:!0})):Pa().value;return Hi(G)},b=()=>new Promise(G=>setTimeout(G,16)),A=8;let x=null,N="";for(let G=0;G<A;G+=1){if(G>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(x=await p(),!(!x||x.empty)&&(N=pc(x),N!==h.sourceSelectionKey))break}if(x&&!x.empty&&N!==h.sourceSelectionKey){await OA(x);return}if(h.snapshot?.paragraph){const G=await p();if(!G||pc(G)===h.sourceSelectionKey)return;await OA(G)}},OA=async u=>{const p=h.snapshot;if(!p){h.mode==="armed"&&Tm();return}const b=y();if(!b)return;const A=Ii(u,"ready"),{lockModesById:x}=Gs(b.contentControls,A);if(fs(x)){Ot();return}const N=u.target,G=u.selectionTarget;if(u.empty!==!0&&Object.keys(p.inline).length>0){const oe=pr(b,"format.apply");if(oe&&G)try{if(!Io(js(await Promise.resolve(v2("format.apply",oe,{target:G,inline:p.inline},u))))){Ot();return}}catch{Ot();return}}if(p.paragraph){const oe=Array.isArray(N?.segments)?N.segments:[],fe=N?.story;for(const Me of oe){const Ve=Ao(Me.blockId,fe),je=await Ll(Ve),Ke=je?.node??null,Ze=je?.address??null;if(!Ke)continue;const Ge={kind:"block",nodeType:Ze?.nodeType??Ke.kind??"paragraph",nodeId:Me.blockId,...fe&&typeof fe=="object"?{story:fe}:{}},{styleId:Qe,alignment:ht,spacing:dt,indentation:ot,markRunProps:Bt,numbering:zt,listStyle:$n}=p.paragraph;if(Qe&&await b.styles?.paragraph?.setStyle?.({target:Ge,styleId:Qe}),ht&&await b.format?.paragraph?.setAlignment?.({target:Ge,alignment:ht}),dt){const Gn=dt,Qr=Gn.lineRule??"auto",Jr=new Set(["auto","exact","atLeast"]).has(Qr)?Qr:"auto",kr={...Gn.before!=null?{before:Math.round(Gn.before*20)}:{},...Gn.after!=null?{after:Math.round(Gn.after*20)}:{},...Gn.line!=null?{line:Math.round(Jr==="auto"?Gn.line*240:Gn.line*20),lineRule:Jr}:{}};await b.format?.paragraph?.setSpacing?.({target:Ge,...kr})}if(ot){const Gn={...ot.left!=null?{left:Vs(ot.left)}:{},...ot.right!=null?{right:Vs(ot.right)}:{},...ot.firstLine!=null?{firstLine:Vs(ot.firstLine)}:{},...ot.hanging!=null?{hanging:Vs(ot.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:Ge,...Gn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:Ge,markRunProps:Bt}),zt&&await b.format?.paragraph?.setNumbering?.({target:Ge,...zt}),$n&&((await Ll(Ve))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:bA(Me.blockId,fe),style:$n}):zt&&await b.format?.paragraph?.setNumbering?.({target:Ge,...zt}))}}h.mode==="armed"&&Tm(),Ot()},Rm=(u,p,b)=>{const A=Zj(u,p),x=A?A.then(()=>(Tc(u,p,b),hi)):(Tc(u,p,b),hi);return Au(u)?.inline?.kind==="toggle"&&(qu=x),x},FA=u=>({id:u,getState:()=>D.toolbar.commands[u]??Gu(u,y(),D.selection,Ml(D.selection)),observe:p=>Go(b=>b.toolbar.commands[u]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:ut.commandUnsupported}).subscribe(p),execute:p=>Tc(u,p),executeAsync:p=>Rm(u,p)}),nU=u=>{le.set(u.id,u),Ot();const p=()=>{le.delete(u.id),Ot()};return Object.assign(p,{handle:FA(u.id),unregister:p})},Mm=bo(u=>u.selection),Lm=Xo(Mm),NA=()=>{const u=P();if(typeof u?.getHandles!="function")return{reason:ut.hostCapabilityUnavailable};let p=null;try{p=u.getHandles()}catch(A){const x=A?.reason;return{reason:x==="host-not-ready"||x==="host-disposed"||x==="editing-mount-required"?ut.notReady:ut.hostCapabilityUnavailable}}const b=p?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:ut.hostCapabilityUnavailable}:{helper:b}},rU=u=>{const p=P();if(typeof p?.getHandles=="function")try{const b=p.getHandles()?.editing?.contentControls;typeof b?.activate=="function"&&b.activate({id:u})}catch{}},BA={get:Lm.get,getSnapshot:Lm.getSnapshot,subscribe:Lm.subscribe,observe:Lm.observe,current:()=>Pa().value,capture:()=>{const u=Mm.get();return u.empty||!u.target&&!u.selectionTarget?null:{...u,capturedAt:Date.now()}},restore:u=>{const p=x=>(Ot(),{...x,success:x.ok});if(!u||typeof u!="object")return p({ok:!1,reason:ut.targetUnresolved});if(!S())return p({ok:!1,reason:ut.notReady});const b=WV(u);if(!b)return p({ok:!1,reason:ut.targetUnresolved});const A=NA();if(!("helper"in A))return p({ok:!1,reason:A.reason});try{return p(dA(A.helper.apply(b)))}catch{return p({ok:!1,reason:ut.hostCapabilityUnavailable})}},apply:u=>{if(!S())return{ok:!1,reason:ut.notReady};const p=NA();if(!("helper"in p))return{ok:!1,reason:p.reason};try{const b=p.helper.apply(u);return Ot(),dA(b)}catch{return{ok:!1,reason:ut.hostCapabilityUnavailable}}},getAnchorRect:u=>{const p=P();if(typeof p?.getSelectionAnchorRect=="function"){const b=Mt(()=>p.getSelectionAnchorRect(u),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:u=>{const p=Mm.get(),b=p.selectionTarget??p.target;if(p.empty||!b)return[];const A=jm.getRect({target:b,relativeTo:u?.relativeTo});return A.found?A.rects:[]}},oU={get ids(){return Pr()},has:u=>Au(u)!=null||le.has(u),get:u=>FA(u),execute:Tc,executeAsync:Rm,register:nU,getContextMenuItems:u=>{const p=[];for(const b of le.values()){const A=b.contextMenu;A&&Mt(A.when?()=>A.when(u):void 0,!0)&&p.push({id:b.id,label:A.label,group:A.group,order:A.order,invoke:()=>Tc(b.id,void 0,u)})}return p.sort((b,A)=>(b.order??0)-(A.order??0)||b.label.localeCompare(A.label))}},b2=Xo(bo(u=>u.toolbar)),iU={get:b2.get,getSnapshot:()=>D.toolbar,subscribe:b2.subscribe,observe:b2.observe,execute:Tc,executeAsync:Rm},Xu=async(u,p)=>{if(!S())return{success:!1,ok:!1,reason:ut.notReady};if(!u)return{success:!1,ok:!1,reason:ut.targetUnresolved};const b=P(),A=b?.scrollTargetIntoView;if(typeof A!="function")return{success:!1,ok:!1,reason:ut.hostCapabilityUnavailable};try{const x={target:u,block:p?.block??"center",behavior:p?.behavior??"smooth"},N=await Promise.resolve(p?.shouldContinue?A.call(b,x,p.shouldContinue):A.call(b,x));return N&&typeof N=="object"&&N.success===!1?{success:!1,ok:!1,reason:o2(N.reason,ut.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:ut.hostCapabilityUnavailable}}},zA=u=>{if(!u||typeof u!="object")return null;const p=u,b=p.wordRevisionIds&&typeof p.wordRevisionIds=="object"?p.wordRevisionIds:null,A=p.sourceIds&&typeof p.sourceIds=="object"?p.sourceIds:null,x=Array.isArray(A?.wordIdOther)?A.wordIdOther:void 0,N=b?.insert??b?.delete??b?.format??A?.wordIdInsert??A?.wordIdDelete??x?.[0];return typeof N=="string"&&N.length>0?N:null},VA=async(u,p,b,A,x)=>{const N=await Xu(p,x);if(N.ok)return N;const G=w(),oe=G?.focusTrackedChange;if(typeof oe!="function")return N;const fe=b||A?{commentId:u,...b?{trackedChangeStory:b}:{},...A?{importedId:A}:{}}:u;try{const Me=await Promise.resolve(oe.call(G,fe));if(Me&&typeof Me=="object"&&Me.ok===!0)return{success:!0,ok:!0}}catch{}return N},Pm=async(u,p,b,A)=>{const x=u==="trackChanges"?A?.story:void 0,N=dt=>{if(!x||!dt||typeof dt!="object")return dt;const ot=dt,Bt=ot.address&&typeof ot.address=="object"?ot.address:null;return ot.story||Bt?.story?dt:{...ot,story:x}},G=u==="trackChanges"?pA:Pf,oe=b.find(dt=>Ni(dt,p,x)),fe=oe&&typeof oe=="object"?oe:null,Me=u==="trackChanges"&&fe?.type==="move"&&(fe.subtype==="move-to"||fe.subtype==="move-from")?fe.subtype:null,Ve=Me&&typeof fe?.trackedChangeCanonicalId=="string"?fe.trackedChangeCanonicalId:p,je=dt=>{if(!Me)return u==="trackChanges"?pA(dt,{preferStableBlock:!0}):G(dt);const ot=Pf(dt);if(ot?.kind!=="move")return null;const Bt=Me==="move-to"?ot.destination:ot.source;return i2(Bt)?Bt:null},Ke=G(oe),Ze=u!=="trackChanges"||!Me&&i2(Pf(oe));if(Ke&&Ze)return N(Ke);const Ge=y()?.[u],Qe=u==="comments"?{commentId:p}:{id:Ve,...x?{story:x}:{}},ht=Ge?.get;if(typeof ht!="function")return N(Ke);try{return N(je(await Promise.resolve(ht.call(Ge,Qe)))??Ke)}catch{return N(Ke)}};function jA(u,p){if(La())return Kn("Comments are read-only.","DOCUMENT_READONLY");if(Ma())return Kn("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,A=b?.patch;if(typeof A!="function")return Kn("comments.patch is unavailable.");const x=Kn("comments.patch failed.");return Mt(()=>Bl(A.call(b,{commentId:u,status:p}),x),x)}const Xf=()=>La()?Kn("Comments are read-only.","DOCUMENT_READONLY"):null,sU=(u,p)=>{const b=p&&typeof p=="object"?p:null;let A=Array.from(u);b?.includeResolved===!1&&(A=A.filter(fe=>fe.status!=="resolved"));const x=Number(b?.offset),N=Number.isInteger(x)&&x>0?x:0,G=Number(b?.limit),oe=Number.isInteger(G)&&G>=0?N+G:void 0;return A.slice(N,oe)},Zu=bo(u=>u.comments),Dm=ja(Zu,Go(u=>Pu(u.selection,u.comments)),"comments"),aU={get:Dm.get,getSnapshot:Dm.getSnapshot,subscribe:Dm.subscribe,observe:Dm.observe,list:u=>{be();const p=Cc();return sU(p.value??Zu.get().items,u)},getById:u=>{const p=Zu.get().items.find(x=>ro(x)===u)??null;if(p)return p;const b=y()?.comments,A=Mt(b?.get?()=>b.get({commentId:u}):void 0,null);return Ir(A)?null:A},createFromCapture:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.create;if(typeof x!="function")return Kn("comments.create is unavailable.");const N=Kn("comments.create failed.");return Mt(()=>{const G=u&&typeof u=="object"?u.target??u.selectionTarget:null;return G==null?Kn("A range selection is required to comment.","NO_SELECTION"):Bl(x.call(A,{target:G,text:p.text}),N)},N)},createFromSelection:u=>{const p=Xf();if(p)return p;const b=y()?.comments,A=b?.create;if(typeof A!="function")return Kn("comments.create is unavailable.");const x=Mm.get(),N=x.target??x.selectionTarget;if(x.empty||!N)return Kn("A range selection is required to comment.","NO_SELECTION");const G=Kn("comments.create failed.");return Mt(()=>Bl(A.call(b,{target:N,text:u.text}),G),G)},reply:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.reply??A?.create;if(typeof x!="function")return Kn("comments.reply is unavailable.");const N=Kn("comments.reply failed.");return Mt(()=>Bl(x===A?.reply?x.call(A,{parentCommentId:u,text:p.text}):x.call(A,{parentCommentId:u,text:p.text}),N),N)},edit:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.patch;if(typeof x!="function")return Kn("comments.patch is unavailable.");const N=Kn("comments.patch failed.");return Mt(()=>Bl(x.call(A,{commentId:u,text:p.text}),N),N)},resolve:u=>jA(u,"resolved"),reopen:u=>jA(u,"active"),delete:u=>{const p=Xf();if(p)return p;const b=y()?.comments,A=b?.delete??b?.remove;if(typeof A!="function")return Kn("comments.delete is unavailable.");const x=Kn("comments.delete failed.");return Mt(()=>Bl(A.call(b,{commentId:u}),x),x)},setActive:u=>{if(u==null)return Oe=null,Ot(),!0;if(!S())return!1;const p=Zu.get(),b=Y.get("comments"),A=b?.token===ke()&&b.hasSettled&&Array.isArray(b.value)?b.value:null,x=A??p.items;if(!A&&p.listStatus!=="ready")return!1;const N=xV(x,u);return!N||!x.some(G=>ro(G)===N)?!1:(Oe=N,Ot(),!0)},scrollTo:async u=>{if(!y())return{success:!1,ok:!1,reason:S()?ut.documentApiUnavailable:ut.notReady};const p=await Pm("comments",u,Zu.get().items);return p?Xu(p):{success:!1,ok:!1,reason:ut.targetUnresolved}}},gs=bo(u=>u.trackChanges),w2=(u,p)=>{zi();const b=($s().value??gs.get().items).map(Nf).filter(je=>je!=null&&ro(je)!==null);if(b.length===0)return null;const A=D.trackChanges.activeId,x=He?.id===A?He.story:void 0,N=b.filter(je=>hm(je)==null),G=x||N.length===0?b:N;let oe=A?G.findIndex(je=>Ni(je,A,x)):-1;oe===-1&&A&&x&&(oe=G.findIndex(je=>Ni(je,A)));const fe=G[oe===-1?u>0?0:G.length-1:(oe+u+G.length)%G.length],Me=ro(fe),Ve=hm(fe);return re(Ve?{id:Me,story:Ve}:{id:Me},p),Ot(),Me},UA=async u=>{const p=w(),b=p?.listTrackedChanges;if(typeof b=="function")try{await Promise.resolve(b.call(p,{mode:"visible-window",targetIds:[u],refreshReason:"ui-track-change-reveal-restamp",blocking:!0}))}catch{}};let HA=Promise.resolve();const lU=u=>{const p=yt;return HA.catch(()=>{}).then(()=>cU(u,p))},cU=async(u,p)=>{if(yt!==p)return{success:!1};const b=He,A=w2(u,{invalidateQueuedNavigation:!1});if(A==null)return{success:!1};const x=He,N=it,G=()=>yt===p&&He===x&&it===N,oe=()=>{G()&&(re(b,{invalidateQueuedNavigation:!1}),Ot())};x&&$e.add(x);try{const fe=await Pm("trackChanges",A,gs.get().items,x?.story?{story:x.story}:void 0);if(!G())return{success:!1};if(!fe)return oe(),{success:!1};const Me=gs.get().items.find(je=>Ni(je,A,x?.story))??gs.get().items.find(je=>ro(je)===A),Ve=zA(Me);dn+=1;try{const je=await VA(A,fe,x?.story,Ve,{behavior:"auto",shouldContinue:G});if(!G())return{success:!1};if(!je.ok&&je.reason!==ut.targetNotVisible)oe(),C(b);else{if(je.ok&&await UA(A),!G())return{success:!1};C(x)}return{success:je.ok}}finally{dn=Math.max(0,dn-1),dn===0&&(G()?di&&An(en(di)):C(He))}}finally{x&&$e.delete(x)}},$A=u=>{const p=lU(u);return HA=p.then(()=>{},()=>{}),p},Om=ja(gs,Go(u=>Gi(u.selection,u.trackChanges)),"trackChanges"),uU={get:Om.get,getSnapshot:Om.getSnapshot,subscribe:Om.subscribe,observe:Om.observe,list:()=>{zi();const u=$s().value??gs.get().items,p=Lt(ke());return u.map(Nf).filter(b=>b!=null).filter(b=>{const A=ro(b);return!A||!p?.has(A)})},accept:u=>C2("accept",u),reject:u=>C2("reject",u),acceptAll:()=>Zf("accept",{kind:"all"},null),rejectAll:()=>Zf("reject",{kind:"all"},null),next:()=>w2(1),previous:()=>w2(-1),navigateNext:()=>$A(1),navigatePrevious:()=>$A(-1),getAt:u=>{if(!u||typeof u!="object"||typeof u.x!="number"||typeof u.y!="number")return null;const p=_2(u);if(p.length===0)return null;const b=gs.get().items;let A;for(const x of p){if(x.type!=="trackedChange")continue;let N;if(x.story){if(A===void 0&&(A=li()),!A)continue;N=A}else N=b;const G=N.find(oe=>Ni(oe,x.id,x.story));if(G)return x.story?{id:G.id,item:G,story:x.story}:{id:G.id,item:G}}return null},setActive:u=>{if(u==null)return re(null),C(null),Ot(),!0;if(!S())return!1;const p=typeof u=="string"?{id:u}:{id:u.id,story:u.story};if(typeof p.id!="string"||p.id.length===0)return!1;const b=p.id;if(p.story){const A=li();if(!A)return!1;const x=gc(A,p.story).toPublicId(p.id)??p.id;if(!A.some(N=>Ni(N,x,p.story)))return!1;p.id=x}else{const A=li()??gs.get().items,x=zs(A).toPublicId(p.id)??p.id,N=A.find(G=>ro(G)===x);if(!N)return!1;p.id=x,p.story=hm(N)}return b!==p.id&&(p.paintedEntityId=b),re(p),C(p),Ot(),!0},scrollTo:async u=>{if(!y())return{success:!1,ok:!1,reason:S()?ut.documentApiUnavailable:ut.notReady};yt+=1,De+=1;const p=De,b=gs.get().items,A=zs(b).toPublicId(u)??u,x=b.find(Me=>ro(Me)===A),N=hm(x),G=zA(x),oe=He,fe={id:A,...N?{story:N}:{},...A!==u?{paintedEntityId:u}:{}};$e.add(fe);try{const Me=await Pm("trackChanges",A,b,N?{story:N}:void 0);if(De!==p)return{success:!1,ok:!1};if(!Me)return{success:!1,ok:!1,reason:ut.targetUnresolved};re(fe);const Ve=De,je=He,Ke=it,Ze=()=>De===Ve&&He===je&&it===Ke,Ge=()=>{Ze()&&(re(oe,{invalidateQueuedNavigation:!1}),Ot())};Ot(),dn+=1;try{const Qe=await VA(A,Me,N,G,{behavior:"auto",shouldContinue:Ze});if(!Ze())return{success:!1,ok:!1};if(!Qe.ok&&Qe.reason!==ut.targetNotVisible)Ge(),C(oe);else{if(Qe.ok&&await UA(A),!Ze())return{success:!1,ok:!1};C(fe)}return Qe}finally{dn=Math.max(0,dn-1),dn===0&&(Ze()?di&&An(en(di)):C(He))}}finally{$e.delete(fe)}}},C2=(u,p)=>{const{id:b,story:A}=typeof p=="string"?{id:p,story:void 0}:p,x={kind:"id",id:b,...A?{story:A}:{}};return Zf(u,x,b,A)},Zf=(u,p,b,A)=>{try{return Mo(k2(u,p,b,A))}catch{return!1}},k2=(u,p,b,A)=>{if(La())return!1;const x=y()?.trackChanges,N=p.kind==="all"||p.scope==="all",G=p.kind==="range",oe=p.kind==="ids";if($u({kind:u,scope:N?"all":"id"},x))return!1;const fe=N?`${u}All`:u,Me=!G&&!oe&&!A&&x&&typeof x[fe]=="function"?x[fe]:null,Ve=x&&typeof x.decide=="function"?x.decide:null;return!Me&&!Ve?!1:Me?Me.call(x,b??{}):Ve.call(x,{decision:u,target:p})},S2=bo(u=>u.contentControls),Qf=u=>S2.get().items.find(p=>p?.id===u)??null,Fm=Xo(S2),dU=(u=>{if(u===void 0)return Fm.get();const p=pm(u);return p?Qf(p):null}),fU={get:(u=>(u!==void 0&&oo("api"),dU(u))),getSnapshot:Fm.getSnapshot,subscribe:Fm.subscribe,observe:Fm.observe,list:()=>(oo("api"),S2.get().items),getById:u=>(oo("api"),Qf(u)),getRect:u=>{const p=pm(u);if(!p)return Cl("unresolved");oo("panel");const b=Qf(p);if(!b)return Cl("unresolved");const A=s2(b);return A?jm.getRect({target:A}):Cl("unavailable")},scrollIntoView:async u=>{const p=pm(u);if(!p)return{success:!1};oo("panel");const b=Qf(p);if(!b)return{success:!1};const A=s2(b);return A?{success:(await Xu(A,{block:u.block,behavior:u.behavior})).ok}:{success:!1}},focus:async u=>{const p=pm(u);if(!p)return{success:!1,reason:"invalid-id"};if(!S())return{success:!1,reason:"not-ready"};oo("panel");const b=Qf(p);if(!b)return{success:!1,reason:"not-found"};const A=s2(b);if(!A)return{success:!1,reason:"not-reachable"};if(!(await Xu(A,{block:u.block,behavior:u.behavior})).ok)return{success:!1,reason:"not-reachable"};const x=CV(A);if(!x)return{success:!1,reason:"not-reachable"};const N=BA.apply(x);return!N.ok&&N.reason!==ut.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:(rU(p),{success:!0})}},Nm=Xo(bo(u=>u.fonts)),hU={get:Nm.get,getSnapshot:Nm.getSnapshot,subscribe:Nm.subscribe,observe:Nm.observe,getFamilyOptions:()=>D.fonts.options,getSizeOptions:()=>D.fonts.sizeOptions},Bm=Xo(bo(u=>u.zoom)),pU={get:Bm.get,getSnapshot:Bm.getSnapshot,subscribe:Bm.subscribe,observe:Bm.observe,set:u=>{if(typeof t?.setZoom=="function")try{t.setZoom(u),Ot()}catch{}},setMode:u=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(u),Ot()}catch{}}},zm=Xo(bo(u=>u.document)),mU={get:zm.get,getSnapshot:zm.getSnapshot,subscribe:zm.subscribe,observe:zm.observe,setMode:u=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(u),Ot()}catch{}},export:u=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(u))}catch{return}},getText:()=>{const u=y(),p=Mt(u?.getText?()=>u.getText({}):void 0,null);return typeof p=="string"?p:p&&typeof p=="object"&&typeof p.text=="string"?p.text:null},replaceFile:u=>{const p=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof p=="function")try{return Promise.resolve(p.call(t,u))}catch{return}}},GA=()=>{if(typeof HTMLElement>"u")return null;const u=S()?.mount?.container;if(u instanceof HTMLElement)return u;const p=t?.element;return p instanceof HTMLElement?p:null},gU=(u,p)=>{if(typeof u!="number"||typeof p!="number"||!Number.isFinite(u)||!Number.isFinite(p))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const A=GA();if(!A)return[];const x=b.elementFromPoint(u,p);if(!x||!A.contains(x))return[];const N=[x],G=ot=>{ot&&A.contains(ot)&&!N.includes(ot)&&N.push(ot)},oe=b.elementsFromPoint;if(typeof oe=="function"){let ot=[];try{ot=oe.call(b,u,p)??[]}catch{ot=[]}for(const Bt of ot)G(Bt)}const fe=[],Me=ot=>{ot&&A.contains(ot)&&!fe.includes(ot)&&!N.includes(ot)&&fe.push(ot)},Ve=ot=>{const Bt=ot.getBoundingClientRect;if(typeof Bt!="function")return!1;let zt;try{zt=Bt.call(ot)}catch{return!1}return zt!=null&&u>=zt.left&&u<=zt.right&&p>=zt.top&&p<=zt.bottom};for(const ot of N){const Bt=ot.querySelectorAll;if(typeof Bt!="function")continue;let zt;try{zt=Bt.call(ot,"[data-track-change-marker]")}catch{continue}for(let $n=0;$n<zt.length;$n+=1)Ve(zt[$n])&&Me(zt[$n])}fe.reverse();const je=[...fe,...N],Ke=uA(je[0],A);for(let ot=1;ot<je.length;ot+=1)for(const Bt of uA(je[ot],A))Ke.push(Bt);if(Ke.length===0)return Ke;const Ze=gs.get().items,Ge=zs(Ze);let Qe;const ht=new Set,dt=[];for(const ot of Ke){if(ot.type!=="trackedChange"){const Gn=`${ot.type}:${ot.id}`;if(ht.has(Gn))continue;ht.add(Gn),dt.push(ot);continue}const Bt=wV(ot.storyKey)??bV(ot.story);let zt;if(Bt){if(Qe===void 0&&(Qe=li()),!Qe||(zt=gc(Qe,Bt).toPublicId(ot.id),!zt||!Qe.some(Gn=>Ni(Gn,zt,Bt))))continue}else if(zt=Ge.toPublicId(ot.id),!zt)continue;const $n=`trackedChange:${zt}`;ht.has($n)||(ht.add($n),dt.push(Bt?{type:"trackedChange",id:zt,story:Bt}:{type:"trackedChange",id:zt}))}return dt};function _2(u,p){return typeof u=="object"?gU(u?.x,u?.y):null}const Qu=new Set;let A2=!1;const WA=u=>{const p=P();if(typeof p?.observeGeometry!="function")return;let b=!1;const A=Mt(()=>{const x=p.observeGeometry(()=>u.schedule());return b=!0,x},null);u.detach=typeof A=="function"?A:null,u.boundHost=b?p:null},Vm=u=>{if(u.detach){try{u.detach()}catch{}u.detach=null}u.boundHost=null},KA=()=>{if(A2=!1,!(j||P()))for(const u of Qu)Vm(u)},vU=()=>{if(!A2){if(A2=!0,typeof queueMicrotask=="function"){queueMicrotask(KA);return}Promise.resolve().then(KA)}},yU=()=>{const u=P();if(!u){vU();return}for(const p of Qu)p.boundHost&&p.boundHost===u||(Vm(p),WA(p),p.schedule())};xi.push(yU);const jm={getRect:u=>{const p=P(),b=p?.getTargetRects;if(typeof b=="function"){const A=Mt(()=>b.call(p,{target:u.target}),null);return A&&typeof A=="object"?A.success===!0&&Array.isArray(A.rects)?$V(HV(A.rects.filter(x=>x!=null&&typeof x=="object")),u.relativeTo):Cl(typeof A.reason=="string"?A.reason:"unresolved"):Cl("unresolved")}return Cl("unavailable")},observe:u=>{const p=[];let b=0;const A=typeof requestAnimationFrame=="function",x=()=>{if(!A){u();return}b||(b=requestAnimationFrame(()=>{b=0,u()}))},N=Go(oe=>({ready:oe.ready,selection:oe.selection,zoom:oe.zoom}));p.push(N.subscribe(()=>x()));const G={schedule:x,detach:null,boundHost:null};return WA(G),Qu.add(G),()=>{Qu.delete(G),Vm(G),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const oe of p.splice(0))try{oe()}catch{}}},getHost:()=>GA(),entityAt:_2,contextAt:u=>{const p=!!u&&typeof u.x=="number"&&typeof u.y=="number",b=p?u.x:0,A=p?u.y:0;return{point:{x:b,y:A},entities:p?_2({x:b,y:A}):[],selection:D.selection,position:null,insideSelection:!1}},scrollIntoView:async u=>{const p=u?.target;if(!p)return{success:!1};let b=null;if(p.kind==="entity"){const A=p.entityType==="comment"?"comments":"trackChanges",x=A==="comments"?Zu.get().items:gs.get().items,N=p.entityType==="trackedChange"&&p.story?{story:p.story}:void 0;b=await Pm(A,p.entityId,x,N)}else{const A=p,x=p,N=Array.isArray(A.segments)&&A.segments.length>0?A.segments:x.blockId&&x.range?[{blockId:x.blockId,range:x.range}]:null;if(N){const G=p.story;b={kind:"text",segments:N,...G?{story:G}:{}}}}return b?{success:(await Xu(b,{block:u.block??"center",behavior:u.behavior??"smooth"})).ok}:{success:!1}}},qA=u=>{const p=(u&&typeof u=="object"?u:null)?.target;return p&&typeof p=="object"?p:null},YA=u=>`metadata:resolve:${u}`,bU=u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return null;const{value:b}=To(YA(u),ke(),()=>p.resolve({id:u}),qA);return b},wU=async u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return null;try{const b=ke(),A=await Promise.resolve(p.resolve({id:u}));if(b!==ke())return null;const x=qA(A);return Y.set(YA(u),{token:b,value:x,hasSettled:!0,inflightToken:null}),x}catch{return null}},CU={getRect:u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return Cl("unavailable");const b=bU(u.id);return b?jm.getRect({target:b}):Cl("unresolved")},scrollIntoView:async u=>{const p=await wU(u.id);return p?{success:(await Xu(p,{block:u.block,behavior:u.behavior})).ok}:{success:!1}}},kU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},SU={getContext:()=>{const u=Se();if(!u)return{...kU};const p=ve()?.table;return{inTable:!0,tableNodeId:u.tableNodeId,rowIndex:u.rowIndex,columnIndex:u.columnIndex,cellNodeId:u.cellNodeId,rows:typeof p?.rows=="number"?p.rows:null,columns:typeof p?.columns=="number"?p.columns:null}},isInTable:()=>Se()!=null},Um={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:ut.searchUnavailable};let zn={...Um};const Hm=new Set,Ha=()=>{const u=P()?.search;return u&&typeof u=="object"?u:null},qs=()=>{const u=ee()?.search;return u&&typeof u=="object"?u:null},Jf=()=>{const u=Ha();if(u&&typeof u.setSession=="function")return!0;const p=qs();return!!p&&typeof p.query=="function"&&typeof p.getState=="function"},vs=()=>{for(const u of[...Hm])try{u(zn)}catch{}},pi=u=>(zn={...zn,...u},vs(),zn);let so=0,Rc=null;const XA=()=>{const u=Rc;Rc=null,u&&Mt(()=>(u(),null),null)},_U=()=>{so+=1,XA();const u=Jf();zn={...Um,available:u,reason:u?void 0:ut.searchUnavailable},vs()};Et.push(_U);const AU=u=>{if(!u)return!1;const p=u.queryError;if(p&&typeof p=="object"&&p.code==="invalid-pattern")return!0;const b=u.rejection;return u.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},I2=(u,p=!1)=>{const b=u&&typeof u=="object"?u:null;if(!b)return null;const A=Array.isArray(b.matches)?b.matches:[],x=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:A.length,N=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:x,activeIndex:N,canReplace:b.canReplace===!0||p,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...AU(b)?{invalidPattern:!0}:{}}},Lo=()=>{const u=ne("find.replace"),p=ne("find.replaceAll");return u?.enabled===!0||p?.enabled===!0},Po=(u,p=!1)=>{const b=I2(u,p);if(!b){pi({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}pi({...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?ut.searchInvalidPattern:void 0})},$a=()=>{const u=Ha();if(u&&typeof u.getState!="function")return zn={...zn,available:Jf(),reason:Jf()?void 0:ut.searchUnavailable},zn;if(!u){const b=qs();if(b&&typeof b.getState=="function"){const A=I2(Mt(()=>b.getState(),null),Lo());if(A)return zn={...zn,...A.query!==void 0?{query:A.query}:{},total:A.total,activeIndex:A.activeIndex,canReplace:A.canReplace,available:!0,reason:A.invalidPattern?ut.searchInvalidPattern:void 0,open:zn.open||!!A.query},zn}return zn={...Um,query:zn.query,caseSensitive:zn.caseSensitive,includeDeletedText:zn.includeDeletedText},zn}const p=I2(Mt(()=>u.getState(),null));return p&&(zn={...zn,...p.query!==void 0?{query:p.query}:{},total:p.total,activeIndex:p.activeIndex,canReplace:p.canReplace,...p.includeDeletedText!==void 0?{includeDeletedText:p.includeDeletedText}:{},...p.regex!==void 0?{regex:p.regex}:{},available:!0,reason:p.invalidPattern?ut.searchInvalidPattern:void 0,open:zn.open||!!p.query}),zn},Ju=u=>{const p=u&&typeof u=="object"?u:null;if(p?.status==="committed")return{ok:!0};if(p?.status==="rejected"&&p.reason==="read-only")return{ok:!1,reason:ut.documentReadonly};const b=p?.rejection;return p?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:ut.documentReadonly}:{ok:!1,reason:ut.operationUnavailable}},$m=Xo({get:()=>$a(),subscribe:u=>(Hm.add(u),()=>Hm.delete(u))}),IU={get:$m.get,getSnapshot:$m.getSnapshot,subscribe:$m.subscribe,observe:$m.observe,open:()=>Jf()?(pi({available:!0,open:!0,reason:void 0}),{ok:!0}):(pi({available:!1,open:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}),close:()=>{if(so+=1,Rc)XA();else{const u=Ha();if(u&&typeof u.clear=="function")Mt(()=>u.clear(),null);else{const p=qs();p&&typeof p.query=="function"&&Mt(()=>p.query({query:""}),null)}}zn={...Um,available:Jf(),reason:void 0},zn.available||(zn.reason=ut.searchUnavailable),vs()},search:(u,p)=>{const b=Ha(),A=!!p?.caseSensitive,x=p?.includeDeletedText===!0,N=p?.regex===!0,G=++so;if(!b||typeof b.setSession!="function"){const fe=qs();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){pi({query:u,caseSensitive:A,includeDeletedText:x,regex:N,available:!0,open:!0,reason:void 0}),Rc=()=>{fe.query({query:""})};const Me=Mt(()=>fe.query({query:u,caseSensitive:A,includeDeletedText:x,regex:N}),null);return Ir(Me)?Promise.resolve(Me).then(Ve=>{G===so&&Po(Ve,Lo())},()=>{G===so&&pi({available:!1,reason:ut.searchUnavailable})}):Po(Me,Lo()),Po(Mt(()=>fe.getState(),null),Lo()),zn}return pi({query:u,total:0,activeIndex:-1,available:!1,caseSensitive:A,includeDeletedText:x,regex:N,reason:ut.searchUnavailable})}pi({query:u,caseSensitive:A,includeDeletedText:x,regex:N,available:!0,open:!0,reason:void 0}),Rc=()=>{typeof b.clear=="function"&&b.clear()};const oe=Mt(()=>b.setSession(u,{caseSensitive:A,includeDeletedText:x,...N?{regex:!0}:{},highlight:!0}),null);if(Po(oe),u.length>0&&zn.total===0&&zn.reason!==ut.searchInvalidPattern){const fe=qs();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){const Me=Rc;Rc=()=>{Me?.(),fe.query({query:""})};const Ve=Mt(()=>fe.query({query:u,caseSensitive:A,includeDeletedText:x,regex:N}),null);Ir(Ve)?Promise.resolve(Ve).then(je=>{G===so&&Po(je,Lo())},()=>{G===so&&pi({available:!1,reason:ut.searchUnavailable})}):Po(Ve,Lo()),Po(Mt(()=>fe.getState(),null),Lo())}}return zn},next:()=>{const u=Ha();if(!u||typeof u.next!="function"){const p=qs();if(!p||typeof p.next!="function"||typeof p.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(zn.total===0)return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.next(),null);if(Ir(b)){const A=so;Promise.resolve(b).then(x=>{A===so&&Po(x,Lo())}).catch(()=>{A===so&&pi({available:!1,reason:ut.searchUnavailable})})}else Po(b,Lo());return Po(Mt(()=>p.getState(),null),Lo()),{ok:!0}}return zn.total===0?{ok:!1,reason:ut.operationUnavailable}:(Po(Mt(()=>u.next(),null)),{ok:!0})},previous:()=>{const u=Ha();if(!u||typeof u.previous!="function"){const p=qs();if(!p||typeof p.previous!="function"||typeof p.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(zn.total===0)return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.previous(),null);if(Ir(b)){const A=so;Promise.resolve(b).then(x=>{A===so&&Po(x,Lo())}).catch(()=>{A===so&&pi({available:!1,reason:ut.searchUnavailable})})}else Po(b,Lo());return Po(Mt(()=>p.getState(),null),Lo()),{ok:!0}}return zn.total===0?{ok:!1,reason:ut.operationUnavailable}:(Po(Mt(()=>u.previous(),null)),{ok:!0})},clear:()=>{so+=1;const u=Ha();if(u&&typeof u.clear=="function"&&Mt(()=>u.clear(),null),!u||typeof u.clear!="function"){const p=qs();p&&typeof p.query=="function"&&Mt(()=>p.query({query:""}),null)}pi({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:u=>{const p=Ha();if(!p){const A=qs();if(!A||typeof A.replace!="function"||typeof A.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(!Lo())return{ok:!1,reason:ut.operationUnavailable};const x=Mt(()=>A.replace({replacement:typeof u=="string"?u:""}),null);if(Ir(x)){const N=so;$a(),vs();const G=()=>N===so;return Promise.resolve(x).then(oe=>(G()&&(Po(oe,Lo()),$a(),vs()),Ju(oe)),()=>(G()&&pi({available:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}))}return $a(),vs(),Ju(x)}if(typeof p.replaceCurrent!="function")return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.replaceCurrent(typeof u=="string"?u:""),null);return $a(),vs(),Ju(b)},replaceAll:u=>{const p=Ha();if(!p){const A=qs();if(!A||typeof A.replaceAll!="function"||typeof A.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(!Lo())return{ok:!1,reason:ut.operationUnavailable};const x=Mt(()=>A.replaceAll({replacement:typeof u=="string"?u:""}),null);if(Ir(x)){const N=so;$a(),vs();const G=()=>N===so;return Promise.resolve(x).then(oe=>(G()&&(Po(oe,Lo()),$a(),vs()),Ju(oe)),()=>(G()&&pi({available:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}))}return $a(),vs(),Ju(x)}if(typeof p.replaceAll!="function")return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.replaceAll(typeof u=="string"?u:""),null);return $a(),vs(),Ju(b)}},ZA=bo(u=>u.styles),Gm=Xo(ZA),xU={get:Gm.get,getSnapshot:Gm.getSnapshot,subscribe:Gm.subscribe,observe:Gm.observe,getCatalog:u=>gn(u).value,getQuickGallery:()=>ZA.get().quickGallery,getActiveParagraphStyle:()=>Yr(D.selection,ir().cache).style},QA={select:Go,get state(){return D},selection:BA,commands:oU,toolbar:iU,comments:aU,trackChanges:uU,contentControls:fU,fonts:hU,zoom:pU,document:mU,viewport:jm,metadata:CU,tables:SU,search:IU,styles:xU,formatPainter:{setPointerSelecting(u){j||(h={...h,pointerSelecting:u})},notifyPointerUp(){j||(h={...h,pointerSelecting:!1},DA())},setKeyboardSelecting(u){j||(h={...h,keyboardSelecting:u})},notifyKeyUp(){j||(h={...h,keyboardSelecting:!1},DA())},cancel(){j||Tm()},onModeChange(u){return j?()=>{}:(m.add(u),()=>m.delete(u))}},createScope:()=>{const u=[];return{select:(p,b)=>{const A=Go(p,b);return{get:A.get,subscribe:x=>{const N=A.subscribe(x);return u.push(N),N}}},dispose:()=>{for(const p of u.splice(0))p()}}},destroy:()=>{if(!j){j=!0,cV(jt,$t),We&&(clearTimeout(We),We=null),_e&&(clearTimeout(_e),_e=null,xe=0),me?.timer&&(clearTimeout(me.timer),me.timer=null),me=null,at&&(clearTimeout(at),at=null),Tr&&(clearTimeout(Tr),Tr=null),Mr&&Mr(),Mr=null,xo=null,go=0,ii=0,mr.clear(),qt.clear(),Pn.clear(),Hr=null,Z.clear();for(const u of Xr.splice(0))u();Cr&&Cr(),Cr=null,cn=null,Ki&&Ki(),Ki=null,ps=null,Yo&&Yo(),Yo=null,yo=null,$o&&$o(),$o=null,di=null,fi&&fi(),fi=null,Yi=null,K&&K(),K=null,F=null;for(const u of Qu)Vm(u);Qu.clear(),V.clear(),Hm.clear(),g+=1,m.clear(),so+=1,le.clear()}}};return W=QA,QA}var QV=[{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 JV(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 ej(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"?JV(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 tj(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 nj(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:QV;for(const s of i)o(s);return n}var rj=[{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 oj(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}xt();var ij=['[data-sdt-type="structuredContent"][data-sdt-id]','[data-sdt-type="structuredContent"][data-sdt-container-id]','[data-sdt-container-type="structuredContent"][data-sdt-container-id]'].join(", "),sj=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 aj(e,t){const n=new v6.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function p2(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function IA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function lj(e,t){if(!e)return()=>{};if(p2(e))return t(),()=>{};const n=typeof e.on=="function"?e.on.bind(e):null,r=typeof e.off=="function"?e.off.bind(e):null;if(!n)return t(),()=>{};let o=!1;const i=()=>{o||(o=!0,r?.("synced",a),r?.("sync",l))},s=()=>{o||(i(),t())},a=()=>{IA(e),s()},l=c=>{c!==!1&&(c===!0||p2(e))&&(IA(e),s())};return n("synced",a),n("sync",l),p2(e)&&s(),i}function cj(e,t){const n=e.composedPath();if(!n.includes(t))return null;const r=n.find(a=>a instanceof HTMLElement&&a.matches(ij));if(!r)return null;const o=n.some(a=>a instanceof HTMLElement&&a.classList.contains(Jh.BLOCK_SDT_LABEL)),i=r.getAttribute("data-sdt-container-id")?.trim()||null,s=r.getAttribute("data-sdt-id")?.trim()||null;return o?i??s:s??i}function uj(e){if(!e||typeof e!="object")return[];const t=e.items;return Array.isArray(t)?t:[]}function dj(e){if(!e||typeof e.id!="string"||e.kind!=="inline"&&e.kind!=="block"||typeof e.controlType!="string")return null;const t=e.properties?.tag,n=e.properties?.alias;return{id:e.id,controlType:e.controlType,scope:e.kind,...typeof t=="string"&&t?{tag:t}:{},...typeof n=="string"&&n?{alias:n}:{}}}function oi(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function fj(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 xA(e){return typeof e=="string"&&e.length>0?e:null}function EA(e){return e?oi(e)?xA(e.documentId??e.options?.documentId??null):xA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function hj(e){if(!e||oi(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function ls(e){if(!e)return null;if(oi(e))return e.fonts??null;const t=hj(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 bm=class extends Km.default{static{this.allowedTypes=[zr,ec,Yh]}#e;#n;#t;#r;#i;#s;#d;#h;#f;#c;#p;get uiConfig(){return this.#p}#o;get interactionConfig(){return this.#o}#l;get surfacesConfig(){return this.#l}#g;#u;#y;#w;constructor(e){if(super(),this.#e=!1,this.#n=!1,this.#t=null,this.#r=null,this.#i=null,this.#s=null,this.#d=null,this.#h=null,this.#f=n=>{this.#k(n)},this.#c=null,this.#p=z4({}),this.#o=V4({}),this.#l=U4({}),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,this.#u=new iN,this.#y=null,this.#w=!1,this.config={selector:"#superdoc",documentMode:"editing",allowSelectionInViewMode:!1,role:"editor",document:{},documents:[],editorExtensions:[],colors:[],users:[],user:{...K0},layoutEngineOptions:{},modules:{},licenseKey:void 0,telemetry:{enabled:!0},title:"SuperDoc",conversations:[],isInternal:!1,comments:{visible:!1},toolbarGroups:["left","center","right"],toolbarIcons:{},toolbarTexts:{},uiDisplayFallbackFont:"Arial, Helvetica, sans-serif",isDev:!1,disablePiniaDevtools:!1,onEditorBeforeCreate:()=>null,onEditorCreate:()=>null,onEditorDestroy:()=>null,onSourceComplete:()=>null,onSourceSignalsComplete:()=>null,onContentError:()=>null,onReady:()=>null,onCommentsUpdate:()=>null,onContentControlActiveChange:()=>null,onContentControlClick:()=>null,onAwarenessUpdate:()=>null,onLocked:()=>null,onPdfDocumentReady:()=>null,onSidebarToggle:()=>null,onCollaborationReady:()=>null,onEditorUpdate:()=>null,onCommentsListChange:()=>null,onException:()=>null,onListDefinitionsChange:()=>null,onPaginationUpdate:()=>null,onTransaction:()=>null,disableContextMenu:!1,viewOptions:{layout:"print"},useLayoutEngine:!0},this.#Z=new WeakSet,this.#Q=null,this.#j=null,this.#M=null,!e.selector)throw new Error("SuperDoc: selector is required");const t=typeof e.selector=="string"?document.querySelector(e.selector):e.selector;if(!(t instanceof HTMLElement))throw new Error("SuperDoc: selector must be a valid CSS selector string or DOM element");this.#g=new KF({getModuleConfig:()=>this.#l}),this.#h=t,t.addEventListener("click",this.#f,!0),this.#I(e,t)}async#k(e){const t=this.#h;if(!t)return;const n=cj(e,t),r=this.activeEditor?.doc?.contentControls?.list;if(!(!n||typeof r!="function"))try{const o=await r();if(this.#e)return;const i=dj(uj(o).find(s=>s.id===n));i&&this.emit("content-control:click",{target:i,source:"pointer"})}catch{return}}async#I(e,t){this.config={...this.config,...e},!this.config.comments||typeof this.config.comments!="object"?this.config.comments={visible:!1}:typeof this.config.comments.visible!="boolean"&&(this.config.comments.visible=!1),eN(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&&r&&(console.warn("[SuperDoc] flowMode 'semantic' is only valid with web layout. Coercing to 'paginated'."),this.config.layoutEngineOptions.flowMode="paginated"),this.editorVersion=2,this.#ye(),this.config.user=tN(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=Fk(this.config.modules.comments),this.#p=z4(this.config),this.#o=V4(this.config),this.#l=U4(this.config),this.config.disableContextMenu=!this.#p.contextMenu.enabled,this.config.rulers=this.#p.ruler.enabled,this.#p.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#p.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#o.comments)}if(this.config.colors=A6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.7.0",this.#C("πŸ¦‹ [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||ys(),this.colors=this.config.colors??[],this.#D(),await v8(),this.#e)return;if(await this.#b(this.config.modules),this.#e){this.#ue();return}this.config.cspNonce&&this.#P(),this.user=this.config.user,this.users=this.config.users||[],this.socket=null,this.isDev=this.config.isDev||!1,this.activeEditor=null,this.comments=[],this.#y||(this.#y=this.#u.subscribe(i=>{this.#we(i.nextRuntimeId,i.legacyEditorProjection)})),this.isLocked=this.config.isLocked||!1,this.lockedBy=this.config.lockedBy||null;const o=document.createElement("div");o.style.display="contents",t.appendChild(o),this.#d=o,this.#S(),this.#L(),this.#Ce(),this.#x()}#x(){if(this.#E(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#d)}#L(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new bD({Renderer:$F,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#m("requiredNumberOfEditors").documents.filter(e=>e.type===zr).length}get ui(){return this.#c||(this.#c=ZV({superdoc:this}),this.#e&&this.#c.destroy()),this.#c}get state(){return{documents:this.#m("state").documents,users:this.users}}getDocumentRuntimeForDocument(e){return typeof e!="string"||e.length===0?null:(this.superdocStore?.documents??[]).find(t=>t?.getEditor?.()?.options?.documentId===e)?.getDocumentRuntime?.()??null}getComment(e){return typeof e!="string"||e.length===0?null:this.commentsStore?.getComment?.(e)??null}get element(){return typeof this.config.selector=="string"?document.querySelector(this.config.selector):this.config.selector}#P(){const e=this.config.cspNonce,t=document.createElement;document.createElement=function(n){const r=t.call(this,n);return n.toLowerCase()==="style"&&r.setAttribute("nonce",e),r}}#D(){const e=this.config.document,t=!!e&&typeof e=="object"&&Object.keys(e)?.length,n=!!e&&typeof e=="string"&&e.length>0,r=!!e&&typeof File=="function"&&e instanceof File,o=!!e&&e instanceof Blob&&!(e instanceof File),i=this.config.documents&&this.config.documents?.length;if(t&&i&&console.warn("πŸ¦‹ [superdoc] You can only provide one of document or documents"),t){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}else if(n)this.config.documents=[{id:ys(),type:zr,url:this.config.document,name:"document.docx"}];else if(r){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}else if(o){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Kd(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||ys()}}))}#E(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=aD({disablePiniaDevtools:!!this.config.disablePiniaDevtools});this.app=e,this.pinia=t,this.app.config.globalProperties.$config=this.config,this.app.config.globalProperties.$documentMode=this.config.documentMode,this.app.config.globalProperties.$superdoc=this,this.app.provide("surfaceManager",this.#g),this.superdocStore=n,this.commentsStore=r,this.highContrastModeStore=o,typeof this.superdocStore.setExceptionHandler=="function"&&this.superdocStore.setExceptionHandler(s=>this.emit("exception",s)),this.superdocStore.init(this.config);const i=this.config.modules.comments;this.commentsStore.init(i||{}),this.isCollaborative&&n8(this),this.#ce()}#a(e,t){t&&this.on(e,t)}#S(){this.#a("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#a("editorCreate",this.config.onEditorCreate),this.#a("editorDestroy",this.config.onEditorDestroy),this.#a("source:complete",this.config.onSourceComplete),this.#a("source:signals-complete",this.config.onSourceSignalsComplete),this.#a("ready",this.config.onReady),this.#a("comments-update",this.config.onCommentsUpdate),this.#a("content-control:active-change",this.config.onContentControlActiveChange),this.#a("content-control:click",this.config.onContentControlClick),this.#a("awareness-update",this.config.onAwarenessUpdate),this.#a("locked",this.config.onLocked),this.#a("pdf:document-ready",this.config.onPdfDocumentReady),this.#a("sidebar-toggle",this.config.onSidebarToggle),this.#a("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#$(e?.editor??null)),this.#a("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#a("exception",this.config.onException),this.#a("list-definitions-change",this.config.onListDefinitionsChange),this.#a("pagination-update",this.config.onPaginationUpdate),this.#a("fonts-resolved",this.config.onFontsResolved),this.#a("fonts-changed",this.config.onFontsChanged),this.#a("zoomChange",this.config.onZoomChange),this.#a("viewport-change",this.config.onViewportChange)}async#b({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:ys(),type:zr,name:"document.docx"}]),this.config.v2CollaborationPreflightFailure={code:"collaboration-v1-config-unsupported",message:"SuperDoc v2 cannot use modules.collaboration because it is the SuperDoc v1 collaboration API. SuperDoc did not attach the provider or change the document. Configure Document.v2Collaboration with a v2 room instead."},this.config.documents):this.config.documents}#ee(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=to(e),this.provider=to(t),this.#_();const n=this.config;this._cleanupAwareness=ZT(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#H(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null),this.isCollaborative=!1,this._commentsCollabInitialized=!1,this.ydoc=void 0,this.provider=void 0;const e=this.config;delete e.modules.collaboration,e.documents.forEach(t=>{delete t.ydoc,delete t.provider})}#A(){if(this.#r){try{this.#r()}catch{}this.#r=null}if(this.#i){try{this.#i()}catch{}this.#i=null}}#$(e){this.#A(),oi(e)&&(this.#O(e),this.#T(e))}#O(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=mD(()=>this.user),r=o=>{if(this.#e)return;const i=n.next(o);this.emit("awareness-update",{...i,superdoc:this})};try{const o=t.getSnapshot?.();o&&r(o),this.#r=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#T(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#e||this.#v(!!r.isLocked,this.#F(r.lockedBy??null))};try{if(this.#s&&typeof t.setLocked=="function"){const o=this.#s;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#s=null}const r=t.getSnapshot?.();r&&n(r),this.#i=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#F(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#G(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#v(e,t){this.isLocked===e&&this.#G(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#C("πŸ¦‹ [superdoc] Locking superdoc:",e,t,`
102
+ `;xt();var Bs=e=>{e.expand.value=!1};function e2(e,t){const n={...e??{}};return t?n.href=t:delete n.href,n}function oA(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 Nz(e){return typeof e?.quotedText=="string"?e.quotedText:typeof e?.text=="string"?e.text:""}function iA(e){return e.ui?.selection?.get?.()??e.ui?.selection?.current?.()??null}function Bz(e){return!!(e.config?.superdoc?.config?.modules?.ai||e.superdoc?.config?.modules?.ai)}function zz(e){return e.config?.superdoc?.config?.modules?.ai??e.superdoc?.config?.modules?.ai??{}}var Vz=({superToolbar:e,toolbarIcons:t,toolbarTexts:n,toolbarFonts:r,hideButtons:o,availableWidth:i,role:s,isDev:a=!1}={})=>{const l=In({type:"button",name:"bold",command:"toggleBold",icon:t.bold,tooltip:n.bold,attributes:{ariaLabel:"Bold"}}),c=(r??LB).map(zB),d=In({type:"dropdown",name:"fontFamily",tooltip:n.fontFamily,command:"setFontFamily",defaultLabel:"Arial",label:"Arial",markName:"textStyle",labelAttr:"fontFamily",hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,isWide:!0,style:{width:"116px"},suppressActiveHighlight:!0,attributes:{ariaLabel:"Font family"},options:c,onActivate:({fontFamily:nt}={},Rt=!1)=>{if(Rt){d.label.value="",d.selectedValue.value="";return}if(!nt)return;nt=nt.split(",")[0],d.label.value=nt;const jt=c.find(Qt=>Qt.label===d.defaultLabel.value),$t=c.find(Qt=>Qt.label===nt);$t?d.selectedValue.value=$t.key:jt?d.selectedValue.value=jt.key:d.selectedValue.value=""},onDeactivate:()=>{d.label.value=d.defaultLabel.value;const nt=c.find(Rt=>Rt.label===d.defaultLabel.value);nt?d.selectedValue.value=nt.key:d.selectedValue.value=""}}),f=In({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(f)}]});function h(nt){const Rt=iA(e),jt=Rt?.selectionTarget??oA(Rt?.target),$t=Rt?.empty?"":Nz(Rt),Qt=zz(e),Fn=()=>Bs(nt),kn=()=>{const Vo=e.pendingSelectionCapture;Vo&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Vo)};return Wr("div",{},[Wr(fz,{handleClose:Fn,selectedText:$t,target:jt,doc:e.superdoc?.activeEditor?.doc??null,apiKey:Qt?.apiKey||e.config?.aiApiKey||"",endpoint:Qt?.endpoint||e.config?.aiEndpoint||"",restoreSelection:kn})])}const g=DB,m=In({type:"dropdown",name:"fontSize",defaultLabel:"12",label:"12",style:{width:"56px"},markName:"textStyle",labelAttr:"fontSize",tooltip:n.fontSize,hasCaret:!0,hasInlineTextInput:!0,inlineTextInputVisible:!0,suppressActiveHighlight:!0,isWide:!0,command:"setFontSize",attributes:{ariaLabel:"Font size"},options:g,onActivate:({fontSize:nt},Rt=!1)=>{if(Rt){m.label.value="",m.selectedValue.value="";return}const jt=g.find(kn=>kn.label===String(m.defaultLabel.value));if(!nt){m.label.value=m.defaultLabel.value,jt?m.selectedValue.value=jt.key:m.selectedValue.value="";return}let $t=_N(nt,12);$t<8&&($t=8),$t>96&&($t=96);let Qt=String($t);const Fn=g.find(kn=>kn.label===Qt||kn.key===Qt);Fn?m.selectedValue.value=Fn.key:m.selectedValue.value="",m.label.value=Qt},onDeactivate:()=>{m.label.value=m.defaultLabel.value;const nt=g.find(Rt=>Rt.label===String(m.defaultLabel.value));nt?m.selectedValue.value=nt.key:m.selectedValue.value=""}}),v=In({type:"separator",name:"separator",isNarrow:!0}),_=In({type:"button",name:"italic",command:"toggleItalic",icon:t.italic,active:!1,tooltip:n.italic,attributes:{ariaLabel:"Italic"}}),k=In({type:"button",name:"underline",command:"toggleUnderline",icon:t.underline,active:!1,tooltip:n.underline,attributes:{ariaLabel:"Underline"}}),S=In({type:"button",name:"strike",command:"toggleStrike",icon:t.strikethrough,active:!1,tooltip:n.strikethrough,attributes:{ariaLabel:"Strikethrough"}}),y=In({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:()=>J0(e,y,[],!0)}],onActivate:({color:nt})=>{y.iconColor.value=nt||""},onDeactivate:()=>y.iconColor.value=""}),w=In({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:()=>J0(e,w)}],onActivate:({color:nt})=>{w.iconColor.value=nt},onDeactivate:()=>w.iconColor.value="#000"}),T=In({type:"button",name:"search",allowWithoutEditor:!0,active:!1,icon:t.search,tooltip:n.search,group:"right",attributes:{ariaLabel:"Search"}}),L=In({type:"dropdown",name:"link",markName:"link",icon:t.link,active:!1,tooltip:n.link,attributes:{ariaLabel:"Link dropdown"},options:[{type:"render",key:"linkDropdown",render:()=>O(L)}],onActivate:({href:nt})=>{L.attributes.value=e2(L.attributes.value,nt)},onDeactivate:()=>{L.attributes.value=e2(L.attributes.value,null),L.expand.value=!1}});function O(nt){const Rt=iA(e),jt=Rt?.selectionTarget??oA(Rt?.target),$t=()=>{const Qt=e.pendingSelectionCapture;Qt&&typeof e.ui?.selection?.restore=="function"&&e.ui.selection.restore(Qt)};return Wr("div",{},[Wr(TS,{ui:e.ui,linkItem:nt,textTarget:jt,restoreSelection:$t,closePopover:()=>{Bs(nt),hc(e)},goToAnchor:()=>{Bs(nt);const Qt=nt.attributes.value?.href;if(!Qt)return;const Fn=Qt.slice(1),kn=(e.ui?.viewport?.getHost?.()??null)?.querySelector?.(`a[name='${Fn}']`);kn&&RS(kn)}})])}const U=In({type:"options",name:"linkInput",command:"toggleLink",active:!1});L.childItem=U,U.parentItem=L;const P=In({type:"button",name:"image",command:"startImageUpload",icon:t.image,active:!1,tooltip:n.image,disabled:!1,attributes:{ariaLabel:"Image"}}),B=In({type:"button",name:"tableOfContents",command:"insertTableOfContents",icon:t.tableOfContents,active:!1,tooltip:n.tableOfContents,disabled:!1,attributes:{ariaLabel:"Table of contents"}}),z=In({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:()=>R(z)}]});function R(nt){return Wr("div",{},[Wr(Ez,{onSelect:jt=>{e.emitCommand({item:nt,argument:jt}),Bs(nt),hc(e)}})])}const H=In({type:"dropdown",name:"tableActions",command:"executeTableCommand",tooltip:n.tableActions,icon:t.tableActions,hideLabel:!0,disabled:!0,attributes:{ariaLabel:"Table actions"},options:[{type:"render",render:()=>$(H)}]}),E=[{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 $(nt){return Wr(Oz,{options:E,onSelect:Rt=>{Bs(nt);const{command:jt}=Rt;e.emitCommand({item:nt,argument:{command:jt}}),hc(e)}})}const Q=In({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:()=>Wr("div",{},[Wr(UB,{onSelect:Rt=>{Bs(Q);const jt={...Q,command:"setTextAlign"};jt.command="setTextAlign",e.emitCommand({item:jt,argument:Rt}),ie(Q,Rt),hc(e)}})]),key:"alignment"}],onActivate:({textAlign:nt})=>{ie(Q,nt)},onDeactivate:()=>{ie(Q,"left")}}),ie=(nt,Rt)=>{let jt=Rt==="both"?"justify":Rt,$t={left:t.alignLeft,right:t.alignRight,center:t.alignCenter,justify:t.alignJustify},Qt=$t[jt]??$t.left;nt.icon.value=Qt},ee=In({type:"dropdown",name:"list",command:"toggleBulletListStyle",splitButton:!0,splitButtonCommand:"toggleBulletList",icon:t.bulletList,hasCaret:!0,tooltip:n.bulletList,restoreEditorFocus:!0,attributes:{ariaLabel:"Bullet list"},options:[{type:"render",key:"bullet-style-buttons",render:()=>{const nt=Rt=>{Bs(ee);const jt={...ee,command:"toggleBulletListStyle"};e.emitCommand({item:jt,argument:Rt})};return Wr(nA,{buttons:GB,iconSize:25,selectedStyle:ee.selectedValue.value,onSelect:nt})}}]}),ne=In({type:"dropdown",name:"numberedlist",command:"toggleOrderedListStyle",splitButton:!0,splitButtonCommand:"toggleOrderedList",icon:t.numberedList,hasCaret:!0,tooltip:n.numberedList,restoreEditorFocus:!0,attributes:{ariaLabel:"Numbered list"},options:[{type:"render",key:"numbered-style-buttons",render:()=>{const nt=Rt=>{Bs(ne);const jt={...ne,command:"toggleOrderedListStyle"};e.emitCommand({item:jt,argument:Rt})};return Wr(nA,{buttons:WB,iconSize:30,selectedStyle:ne.selectedValue.value,onSelect:nt})}}]}),Ie=In({type:"button",name:"indentleft",command:"decreaseTextIndent",icon:t.indentLeft,active:!1,tooltip:n.indentLeft,disabled:!1,attributes:{ariaLabel:"Left indent"}}),pe=In({type:"button",name:"indentright",command:"increaseTextIndent",icon:t.indentRight,active:!1,tooltip:n.indentRight,disabled:!1,attributes:{ariaLabel:"Right indent"}}),ye=In({type:"overflow",name:"overflow",command:null,icon:t.overflow,active:!1,disabled:!1,attributes:{ariaLabel:"Overflow items"}}),ve=In({type:"dropdown",name:"zoom",allowWithoutEditor:!0,tooltip:n.zoom,defaultLabel:"100%",label:"100%",hasCaret:!0,command:"setZoom",isWide:!0,style:{width:"71px",minWidth:"71px"},inlineTextInputVisible:!1,hasInlineTextInput:!0,attributes:{ariaLabel:"Zoom"},options:[{label:"50%",key:.5,props:{"data-item":"btn-zoom-option"}},{label:"75%",key:.75,props:{"data-item":"btn-zoom-option"}},{label:"90%",key:.9,props:{"data-item":"btn-zoom-option"}},{label:"100%",key:1,props:{"data-item":"btn-zoom-option"}},{label:"125%",key:1.25,props:{"data-item":"btn-zoom-option"}},{label:"150%",key:1.5,props:{"data-item":"btn-zoom-option"}},{label:"200%",key:2,props:{"data-item":"btn-zoom-option"}}],onActivate:({zoom:nt})=>{nt&&(ve.label.value=nt)}}),Se=In({type:"dropdown",name:"measurementUnit",allowWithoutEditor:!0,tooltip:n.measurementUnit,defaultLabel:"in",label:"in",hasCaret:!0,command:"setMeasurementUnit",group:"right",style:{width:"52px",minWidth:"52px"},inlineTextInputVisible:!1,hasInlineTextInput:!1,attributes:{ariaLabel:"Measurement unit"},options:[{label:"Inches",key:"in",props:{"data-item":"btn-measurement-unit-option"}},{label:"Centimeters",key:"cm",props:{"data-item":"btn-measurement-unit-option"}}],onActivate:({measurementUnit:nt})=>{nt&&(Se.label.value=nt)}}),le=In({type:"button",name:"undo",disabled:!0,tooltip:n.undo,command:"undo",icon:t.undo,group:"left",attributes:{ariaLabel:"Undo"}}),Oe=In({type:"button",disabled:!0,name:"redo",tooltip:n.redo,command:"redo",icon:t.redo,group:"left",attributes:{ariaLabel:"Redo"}}),He=In({type:"button",disabled:!1,name:"acceptTrackedChangeBySelection",tooltip:n.trackChangesAccept,command:"acceptTrackedChangeFromToolbar",icon:t.trackChangesAccept,group:"left",attributes:{ariaLabel:"Accept tracked changes"}}),it=In({type:"button",disabled:!1,name:"rejectTrackedChangeOnSelection",tooltip:n.trackChangesReject,command:"rejectTrackedChangeFromToolbar",icon:t.trackChangesReject,group:"left",attributes:{ariaLabel:"Reject tracked changes"}}),yt=In({type:"button",name:"clearFormatting",command:"clearFormat",tooltip:n.clearFormatting,icon:t.clearFormatting,attributes:{ariaLabel:"Clear formatting"}}),De=In({type:"button",name:"copyFormat",tooltip:n.copyFormat,icon:t.copyFormat,command:"copyFormat",active:!1,attributes:{ariaLabel:"Copy formatting"}}),$e=(nt,Rt)=>nt==="editor"?Rt:nt==="suggester"?Rt.filter(jt=>jt.value==="suggesting"):Rt.filter(jt=>jt.value==="viewing"),Ye=nt=>nt==="editor"?"Editing":nt==="suggester"?"Suggesting":"Viewing",J=In({type:"dropdown",name:"documentMode",command:"setDocumentMode",allowWithoutEditor:!0,icon:t.documentMode,defaultLabel:Ye(s),label:Ye(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:()=>re(J)}]}),C=[{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 re(nt){const Rt=$e(s,C);return Wr(ez,{options:Rt,onSelect:jt=>{const $t=e.superdoc?.activeEditor??e.activeEditor;Bs(nt);const{label:Qt,icon:Fn,value:kn}=jt;J.label.value=Qt,J.icon.value=Fn,e.emitCommand({item:J,argument:kn}),hc(e,$t)}})}const V=new Map([["separator",20],["zoom",71],["measurementUnit",52],["fontFamily",118],["fontSize",57],["textAlign",40],["linkedStyles",142],["documentMode",47],["default",32]]),D=["search","ruler","undo","overflow","documentMode"],j=In({type:"button",name:"ruler",command:"toggleRuler",allowWithoutEditor:!0,icon:t.ruler,active:!1,tooltip:n.ruler,attributes:{ariaLabel:"Ruler"}}),W=In({type:"button",name:"formattingMarks",command:"toggleFormattingMarks",allowWithoutEditor:!0,icon:t.formattingMarks,active:!1,tooltip:n.formattingMarks,attributes:{ariaLabel:"Formatting marks"}}),Y=In({type:"dropdown",name:"linkedStyles",command:"setLinkedStyle",tooltip:n.linkedStyles,icon:t.paintbrush,defaultLabel:n.formatText,label:n.formatText,hasCaret:!0,isWide:!0,style:{width:"140px"},suppressActiveHighlight:!0,disabled:!1,attributes:{className:"sd-toolbar-item--linked-styles",ariaLabel:"Linked styles"},options:[{type:"render",key:"linkedStyle",render:()=>{const nt=jt=>{Bs(Y);const $t=typeof jt=="string"?jt:jt?.id??null;if(!$t)return;const Qt={...Y,command:"setLinkedStyle"};e.emitCommand({item:Qt,argument:$t})},Rt=e.getActiveLinkedStyleId?.()??null;return Wr("div",{},[Wr(oz,{styles:e.getLinkedStyleOptions?.()??[],onSelect:nt,selectedOption:Rt})])}}],onActivate:({styleId:nt,styleName:Rt})=>{const jt=Rt||nt;Y.label.value=nt&&nt!=="Normal"?String(jt):n.formatText,Y.disabled.value=!1},onDeactivate:()=>{Y.disabled.value=!0,Y.label.value=n.formatText}}),Z=(nt,Rt)=>{if(Rt.value==nt)return Wr("div",{innerHTML:Fz,class:"dropdown-select-icon"})},q=In({type:"dropdown",name:"lineHeight",tooltip:n.lineHeight,icon:t.lineHeight,hasCaret:!1,hasInlineTextInput:!1,hideLabel:!0,inlineTextInputVisible:!1,suppressActiveHighlight:!0,restoreEditorFocus:!0,isWide:!1,command:"setLineHeight",dropdownValueKey:"key",selectedValue:"1",attributes:{ariaLabel:"Line height"},options:[1,1.15,1.5,2,2.5,3].map(nt=>({label:nt.toFixed(2),key:nt,icon:()=>Z(nt,q.selectedValue),props:{"data-item":"btn-lineHeight-option"}}))}),me=20,Te=32,_e=D.reduce((nt,Rt)=>nt+(V.get(Rt)||V.get("default")),0),xe=["linkedStyles","clearFormatting","copyFormat","formattingMarks"],We=["zoom","fontFamily","fontSize","redo"],tt=i<=Mf.lg,at=e.config?.showFormattingMarksButton===!0,Ut=e.config?.showTableOfContentsButton===!0;tt&&(J.attributes.value={...J.attributes.value,className:`${J.attributes.value.className} sd-toolbar-item--doc-mode-compact`}),tt&&(Y.attributes.value={...Y.attributes.value,className:`${Y.attributes.value.className} sd-toolbar-item--linked-styles-compact`});let Ct=[le,Oe,He,it,T,ve,d,v,m,v,l,_,k,S,w,y,v,L,P,...Ut?[B]:[],z,H,v,Q,ee,ne,Ie,pe,q,v,Y,v,j,Se,...at?[W]:[],De,yt,...Bz(e)?[f]:[],ye,J];if(i<=Mf.md&&o&&(Ct=Ct.filter(nt=>nt.type!=="separator")),e.config.mode!=="docx"){const nt=Ct.findIndex(jt=>jt.name.value==="linkedStyles");Ct.splice(nt-1,2);const Rt=["ruler","zoom","undo","redo"];Ct=Ct.filter(jt=>!Rt.includes(jt.name.value))}const Je=[];a||(s==="viewer"&&Je.push(He,it),Ct=Ct.filter(nt=>!Je.includes(nt)));const Vt=nt=>D.includes(nt.name.value),nn=[],Ln=[];let Zt=Te+_e;return Ct.forEach(nt=>{const Rt=V.get(nt.name.value)||V.get("default");if(i<Mf.xl+me&&xe.includes(nt.name.value)&&o){if(nn.push(nt),nt.name.value==="linkedStyles"){const jt=Ct.findIndex($t=>$t.name.value==="linkedStyles");Ct.splice(jt+1,1)}return}if(i<Mf.sm&&We.includes(nt.name.value)&&o){nn.push(nt);return}if(Vt(nt)){Ln.push(nt),Zt+=Rt;return}Zt<i||!o?(Ln.push(nt),Zt+=Rt):nn.push(nt)}),{defaultItems:Ln,overflowItems:nn.filter(nt=>nt.type!=="separator")}},sA={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"},jz=e=>e?typeof e!="string"?e instanceof HTMLElement?e:null:e.startsWith("#")||e.startsWith(".")?document.querySelector(e):document.getElementById(e):null;xt();function aA(e){return gN(e)??Q0[e]??null}function lm(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 Uz=new Set(["bold","italic","underline","strike","color","highlight","link","clearFormatting","textAlign","list","numberedlist","indentleft","indentright","lineHeight","linkedStyles"]),Hz=new Set(["list","numberedlist"]);function $z(e,t){if(e==="fontFamily"||e==="fontSize"||Hz.has(e)&&t?.disabled&&t?.supported!==!1&&t?.reason==null)return!0;if(!Uz.has(e))return!1;const n=t?.reason;return n==="range-selection-required"||n==="selection-required"}function lA(e){return!!e?.closest?.("[data-editor-ui-surface], .toolbar-dropdown-menu, .sd-toolbar-dropdown-menu, .sd-tooltip-content")}function Gz(e){return["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(e.key)}var Wz=class extends Km.default{config={selector:null,toolbarGroups:["left","center","right"],role:"editor",icons:{...rr},texts:{...sA},fonts:null,hideButtons:!0,responsiveToContainer:!1,mode:"docx",excludeItems:[],groups:null,customButtons:[],showFormattingMarksButton:!1,showTableOfContentsButton:!1};toolbarItems=[];overflowItems=[];#e=null;#n=null;isDev=!1;role="editor";superdoc;toolbarContainer=null;toolbar=null;_detachFontsChanged=null;constructor(e={}){if(super(),this.config={...this.config,...e},this.toolbarItems=[],this.overflowItems=[],this.isDev=e.isDev||!1,this.superdoc=e.superdoc,this.role=e.role||"editor",this.toolbarContainer=null,this.config.icons={...rr,...e.icons},this.config.texts={...sA,...e.texts},this.config.hideButtons=e.hideButtons??!0,this.config.responsiveToContainer=e.responsiveToContainer??!1,this.activeEditor=e.editor??this.superdoc?.activeEditor??null,this.ui=null,this.snapshot=null,this._unsubscribeController=null,this._detachFormatPainterModeChange=null,this._customCommandRegs=new Map,this._reportedInvalidCustomItems=new Set,this._lastFontOptionsSignature="",!this.config.selector&&this.config.element&&(this.config.selector=this.config.element),this.toolbarContainer=jz(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.#t(),this.#d(),this.#f(),this.#i(),this._lastFontOptionsSignature=this.#o(),!this.toolbarContainer){this.updateToolbarState();return}this.app=Jl(BB),this.app.directive("click-outside",Xv),this.app.config.globalProperties.$toolbar=this,this.toolbar=this.app.mount(this.toolbarContainer),this.updateToolbarState()}catch(t){try{this.destroy()}catch{}throw t}}#t(){this.ui=this.superdoc?.ui??null,this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot(),this._unsubscribeController=this.ui.toolbar.subscribe(()=>{this.snapshot=this.ui.toolbar.getSnapshot(),this.updateToolbarState()}),this._detachFormatPainterModeChange=this.ui.formatPainter.onModeChange(e=>{e==="armed"||e==="persistent"?this.#a():this.#S()}))}#r(){this._unsubscribeController?.(),this._unsubscribeController=null,this._detachFormatPainterModeChange?.(),this._detachFormatPainterModeChange=null,this.#S();for(const e of this._customCommandRegs.values())try{e.unregister?.()}catch{}this._customCommandRegs.clear(),this.ui=null,this.snapshot=null}#i(){if(!this.superdoc||typeof this.superdoc.on!="function"||typeof this.superdoc.off!="function")return;const e=()=>{const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.updateToolbarState()};this.superdoc.on("fonts-changed",e),this._detachFontsChanged=()=>{this.superdoc?.off?.("fonts-changed",e)}}#s(){this._detachFontsChanged?.(),this._detachFontsChanged=null}#d(){if(Array.isArray(this.config.groups)){this.config.toolbarGroups=this.config.groups,this.config.groups=null;return}this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length&&(this.config.toolbarGroups=Object.keys(this.config.groups))}getAvailableWidth(){const e=document.documentElement.clientWidth,t=this.toolbarContainer?.offsetWidth??0;return this.config.responsiveToContainer?t:e}#h(e){if(e)return e;const t=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return PB(t)}#f(){const e=this.getAvailableWidth(),t=this.config.groups&&!Array.isArray(this.config.groups)&&Object.keys(this.config.groups).length>0,{defaultItems:n,overflowItems:r}=Vz({superToolbar:this,toolbarIcons:this.config.icons,toolbarTexts:this.config.texts,toolbarFonts:this.#h(this.config.fonts),hideButtons:this.config.hideButtons,availableWidth:e,role:this.role,isDev:this.isDev}),o=this.config.customButtons||[],i=new Set([...n,...r].map(c=>c.name?.value).filter(Boolean)),s=o.map((c,d)=>{try{if(c?.name&&i.has(c.name))throw new Error(`Toolbar item name "${c.name}" is already taken by another item, so this entry is skipped.`);const f=this.#c(c);return i.add(f.name?.value),f}catch(f){const h=`${c?.name??`<unnamed@${d}>`}::${f?.message??String(f)}`;return this._reportedInvalidCustomItems.has(h)||(this._reportedInvalidCustomItems.add(h),this.#b(f,c?.name??null)),null}}).filter(Boolean);s.length&&n.push(...s);let a=[...n.map(c=>c.name.value),...r.map(c=>c.name.value)];if(t){const c=Object.values(this.config.groups).flatMap(h=>h),d=new Set(Object.keys(this.config.groups)),f=s.filter(h=>d.has(h.group?.value||"center")).map(h=>h.name.value);a=[...new Set([...c,...f])]}const l=n.filter(c=>a.includes(c.name.value)).filter(c=>!this.config.excludeItems.includes(c.name.value));if(t)for(const[c,d]of Object.entries(this.config.groups))for(const f of l)d.includes(f.name.value)&&(f.group.value=c);this.toolbarItems=l,this.overflowItems=r.filter(c=>a.includes(c.name.value))}#c(e){const t=In({...e});t.isCustomToolbarItem=!0;const n=e.command;if(typeof n=="function"&&this.ui?.commands?.register){const r=`__builtin_toolbar__${e.name}`;if(!this._customCommandRegs.has(r)){const o=this.ui.commands.register({id:r,execute:i=>{const s=i?.payload&&typeof i.payload=="object"?i.payload:{};return n({...i,item:t,argument:s.argument,option:s.option})}});this._customCommandRegs.set(r,o)}}return t}#p(){this.#f(),this.emit("toolbar-items-changed")}#o(){if(this.config.fonts)return"custom-fonts";const e=this.superdoc?.fonts?.getFontFamilyOptions?.()??[];return JSON.stringify(e.map(t=>[t.label,t.value,t.previewFamily]))}getToolbarItemByGroup(e){return this.toolbarItems.filter(t=>(t.group?.value||"center")===e)}getToolbarItemByName(e){return this.#l().find(t=>t.name.value===e)}#l(){return[...this.toolbarItems,...this.overflowItems]}getLinkedStyleOptions(){return this.ui?.styles?.getQuickGallery?.()??[]}getActiveLinkedStyleId(){return this.ui?.styles?.getActiveParagraphStyle?.()?.styleId??null}setActiveEditor(e){this.activeEditor=e;const t=this.#o();t!==this._lastFontOptionsSignature&&(this._lastFontOptionsSignature=t,this.#p()),this.ui&&(this.snapshot=this.ui.toolbar.getSnapshot()),this.updateToolbarState()}onToolbarResize=()=>{this.#f(),this.updateToolbarState()};#g(e){return e==="ruler"?!!this.superdoc?.config?.rulers:e==="formattingMarks"?!!this.superdoc?.config?.layoutEngineOptions?.showFormattingMarks:!1}#u(e){return e==="ruler"?typeof this.superdoc?.toggleRuler=="function":e==="formattingMarks"?typeof this.superdoc?.toggleFormattingMarks=="function"||typeof this.superdoc?.setShowFormattingMarks=="function":!1}#y(){const e=this.getToolbarItemByName("documentMode");if(!e)return;const t=(this.snapshot?.commands?.["document-mode"]?.value||"editing").toLowerCase(),n=this.config.texts||{},r=this.config.icons||{},o={editing:{label:n.documentEditingMode||"Editing",icon:r.documentEditingMode||r.documentMode},suggesting:{label:n.documentSuggestingMode||"Suggesting",icon:r.documentSuggestingMode||r.documentMode},viewing:{label:n.documentViewingMode||"Viewing",icon:r.documentViewingMode||r.documentMode}},i=o[t]||o.editing;e.label?.value!==void 0&&(e.label.value=i.label),e.defaultLabel?.value!==void 0&&(e.defaultLabel.value=i.label),e.icon?.value!==void 0&&i.icon&&(e.icon.value=i.icon)}#w(){const e=this.toolbarItems.find(n=>n.name.value==="highlight");if(!e)return;const t={key:"color",type:"render",render:()=>J0(this,e,[],!0)};e.nestedOptions.value=[t]}#k(e){return!!e?.active&&e?.value==null}#I(e){return!!e&&e.disabled===!1&&e.value==null}#x(e){const t=e.name.value;if(t==="tableActions"){const i=tA.map(s=>this.snapshot?.commands?.[s]).some(s=>s&&!s.disabled);return e.setDisabled(!i),!0}if(t==="search")return e.setDisabled(this.superdoc?.uiConfig?.search?.enabled!==!0),!0;if(X0(t)?.disposition==="host-routed")return e.setDisabled(!this.#u(t)),this.#g(t)?e.activate():e.deactivate(),!0;const n=aA(t);if(!n)return!1;const r=this.snapshot?.commands?.[n];$z(t,r)?e.setDisabled(!1):e.setDisabled(!!r?.disabled);const o={textAlign:()=>{r?.value?e.activate({textAlign:r.value}):e.deactivate()},lineHeight:()=>{e.selectedValue.value=r?.value!=null?r.value:""},zoom:()=>{if(r?.value!=null){const i=typeof r.value=="number"?`${r.value}%`:String(r.value);e.onActivate({zoom:i})}},measurementUnit:()=>{r?.value!=null&&e.onActivate({measurementUnit:String(r.value)})},documentMode:()=>{this.#y()},link:()=>{e.active.value=!!r?.active,e.attributes.value=e2(e.attributes.value,r?.value??null)},fontFamily:()=>{if(r?.value!=null){e.activate({fontFamily:r.value});return}if(this.#I(r)){e.activate({},!0);return}e.deactivate()},fontSize:()=>{if(r?.value!=null){e.activate({fontSize:r.value});return}if(this.#k(r)){e.activate({},!0);return}e.deactivate()},color:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},highlight:()=>{r?.value!=null?e.activate({color:r.value}):e.deactivate()},linkedStyles:()=>{const i=r?.value,s=typeof i=="string"?i:i?.styleId,a=i&&typeof i=="object"?i.styleName:null;s?e.activate({styleId:s,styleName:a}):e.label.value=this.config.texts?.formatText||"Format text"},list:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},numberedlist:()=>{r?.active?(e.activate(),e.selectedValue.value=r.value):(e.deactivate(),e.selectedValue.value=null)},default:()=>{r?.active?e.activate():e.deactivate()}};return(o[t]??o.default)(),!0}updateToolbarState(){this.#y(),this.#w();const e=this.snapshot?.commands?.["document-mode"]?.value||"editing";!(this.snapshot&&(this.superdoc?.activeEditor??this.activeEditor))||e==="viewing"?(this.#L(),this.#l().forEach(n=>{n.allowWithoutEditor?.value&&this.#x(n)})):this.#l().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")}#L(){this.#l().forEach(e=>{const{allowWithoutEditor:t}=e;t?.value||e.setDisabled(!0)})}#P(e,t){const n=this.superdoc;if(e==="ruler")return typeof n?.toggleRuler=="function"?(n.toggleRuler(),!0):!1;if(e==="formattingMarks"){if(typeof t=="boolean"&&typeof n?.setShowFormattingMarks=="function")return n.setShowFormattingMarks(t),!0;if(typeof n?.toggleFormattingMarks=="function")return n.toggleFormattingMarks(),!0}return!1}#D(e,t){const n=e?.name?.value;if(!n)return!1;const r={onSettled:()=>this.updateToolbarState(),onError:i=>this.#b(i,n)};if(n==="image"&&t==null)return this.#E();if(n==="tableActions"){const i=eA[t?.command];return i?lm(this.ui,i,void 0,r):!1}if(X0(n)?.disposition==="unsupported")return!0;const o=aA(n);return o?lm(this.ui,o,t,r):!1}#E(){return this.snapshot?.commands?.image?.disabled||(this.#e||(this.#e=SN({ownerDocument:this.toolbarContainer?.ownerDocument??document,onPick:async e=>{const t=await CN(e,this.superdoc?.config?.handleImageUpload);lm(this.ui,"image",{src:t},{onSettled:()=>this.updateToolbarState(),onError:n=>this.#b(n,"image")})},onError:e=>this.#b(e,"image")})),this.#e.open()),!0}#a(){if(this.#n)return;const e=this.superdoc?.activeEditor?.container??document,t=i=>{lA(i.target)||this.ui.formatPainter.setPointerSelecting(!0)},n=i=>{this.ui.formatPainter.setPointerSelecting(!1),!lA(i.target)&&this.ui.formatPainter.notifyPointerUp()},r=i=>{if(i.key==="Escape"){this.ui.formatPainter.cancel();return}Gz(i)&&this.ui.formatPainter.setKeyboardSelecting(!0)},o=()=>{this.ui.formatPainter.setKeyboardSelecting(!1),this.ui.formatPainter.notifyKeyUp()};e.addEventListener("pointerdown",t),e.addEventListener("pointerup",n),e.addEventListener("keydown",r),e.addEventListener("keyup",o),this.#n=()=>{e.removeEventListener("pointerdown",t),e.removeEventListener("pointerup",n),e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}}#S(){this.#n&&(this.#n(),this.#n=null)}#b(e,t){const n={error:e instanceof Error?e:new Error(String(e)),originalError:e,itemName:t??null,editor:this.superdoc?.activeEditor??this.activeEditor??null},r={...n};this.emit("exception",n),this.superdoc?.emit?.("exception",r)}emitCommand({item:e,argument:t,option:n}){const r=e?.name?.value,{command:o}=e,i=t!=null;if(!(e?.type==="dropdown"&&!i&&(o==="setFontFamily"||o==="setFontSize"))){if(r==="search"){this.superdoc?.emit?.("search:open");return}try{if(X0(r)?.disposition==="host-routed"){this.#P(r,t),this.updateToolbarState();return}if(typeof o=="function"){const s=`__builtin_toolbar__${r}`;this._customCommandRegs.has(s)&&this.ui?.commands?.execute?this.ui.commands.execute(s,{argument:t,option:n}):o({item:e,argument:t,option:n,ui:this.ui,superdoc:this.superdoc}),this.updateToolbarState();return}if(e?.isCustomToolbarItem&&typeof o=="string"){if(!lm(this.ui,o,t,{onSettled:()=>this.updateToolbarState(),onError:s=>this.#b(s,r)}))throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState();return}if(!this.#D(e,t)&&o)throw new Error(`[superdoc toolbar] Command not handled: ${String(o)}`);this.updateToolbarState()}catch(s){this.#b(s,r)}}}destroy(){this.#S(),this.#e?.destroy(),this.#e=null,this.#s(),this.#r(),this.app?.unmount(),this.app=null,this.toolbar=null}};function Kz(e){return new Wz(e)}function qz(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 Yz(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=cm(e.color);n!=null&&(t.color=n),e.highlight!=null&&(t.highlight=e.highlight);const r=Zz(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=Xz(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=Qz(e.border);return i&&(t.border=i),t}function cm(e){if(e){if(typeof e=="string")return e;if(e.model==="rgb")return e.value;if(e.model==="auto")return"auto"}}function Xz(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 Zz(e){if(!e)return;const t={},n=cm(e.fill);n!=null&&(t.fill=n);const r=cm(e.color);return r!=null&&(t.color=r),e.pattern!=null&&(t.val=e.pattern),Object.keys(t).length>0?t:void 0}function Qz(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=cm(e.color);return n!=null&&(t.color=n),Object.keys(t).length>0?t:void 0}function pc(e){const t=e?.selectionTarget??e?.target;if(!e||!t)return"";try{return JSON.stringify(t)}catch{return String(t)}}var Jz=new Set(["insert-text","replace-text","plain-text-paste","delete-backward","delete-forward","text.insert","text.replace","text.pastePlain","text.deleteBackward","text.deleteForward","structural.enter","structural:enter-split-paragraph","structural:enter-insert-paragraph-before","structural:enter-insert-paragraph-after","structural:shift-enter-line-break","structural:backspace-boundary-merge-with-previous","structural:delete-boundary-merge-with-next","backspace:boundary-merge-with-previous","backspace:list-remove","backspace:list-outdent"]),eV=e=>e?.type!=="mutation:committed"||e.origin!=="command"?!1:Jz.has(e.editableCommandKind);function cA(e){return e.split(",").map(t=>t.trim()).filter(Boolean)}function tV(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 cA(r))n(o);return n(e.getAttribute("data-track-change-id")),t}function uA(e,t){if(!e||typeof e.getAttribute!="function")return[];const n=[],r=new Set;let o=[],i=e;for(;i;){const s=i,a=tV(s),l=a.length>0?s.getAttribute("data-story-key"):null;for(const m of a){const v=`trackedChange:${m}`;if(!r.has(v)){r.add(v);const _={type:"trackedChange",id:m};l&&(_.storyKey=l),n.push(_),o.push(_)}}const c=s.getAttribute("data-layout-story");if(c&&o.length>0){for(const m of o)m.story=c;o=[]}const d=s.getAttribute("data-citation-id");if(d){const m=`citation:${d}`;r.has(m)||(r.add(m),n.push({type:"citation",id:d}))}const f=s.getAttribute("data-comment-ids");if(f)for(const m of cA(f)){const v=`comment:${m}`;r.has(v)||(r.add(v),n.push({type:"comment",id:m}))}const h=s.getAttribute("data-sdt-type"),g=s.getAttribute("data-sdt-id");if(g&&h==="structuredContent"){const m=`contentControl:${g}`;if(!r.has(m)){r.add(m);const v=s.getAttribute("data-sdt-scope"),_=s.getAttribute("data-sdt-tag"),k={type:"contentControl",id:g};(v==="block"||v==="inline")&&(k.scope=v),_&&(k.tag=_),n.push(k)}}if(t&&i===t)break;i=i.parentElement}return n}var po=()=>({oneOf:[{type:"boolean"},{type:"null"}]}),yl=()=>({oneOf:[{type:"string",minLength:1},{type:"null"}]}),Iu=()=>({oneOf:[{type:"number"},{type:"null"}]}),xu=e=>({oneOf:[{type:"object",properties:e,additionalProperties:!1,minProperties:1},{type:"null"}]}),nV={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},rV={type:"object",properties:{id:{type:"number"},val:{type:"boolean"}},required:["id"],additionalProperties:!1},oV=()=>({oneOf:[{type:"boolean"},{type:"null"},nV]}),iV=()=>({oneOf:[{type:"array",items:rV,minItems:1},{type:"null"}]});function um(e,t){return{storage:"mark",markName:e,textStyleAttr:t}}function sV(e){return{storage:"runAttribute",nodeName:"run",runPropertyKey:e}}var t2=(e,t,n)=>({key:e,type:"boolean",ooxmlElement:t,storage:"mark",tracked:!0,carrier:um(n),schema:po()}),mc=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"mark",tracked:!0,carrier:um("textStyle",o??e),schema:r}),Un=(e,t,n,r,o)=>({key:e,type:t,ooxmlElement:n,storage:"runAttribute",tracked:!1,carrier:sV(o??e),schema:r}),dm=[t2("bold","w:b","bold"),t2("italic","w:i","italic"),t2("strike","w:strike","strike"),{key:"underline",type:"object",ooxmlElement:"w:u",storage:"mark",tracked:!0,carrier:um("underline"),schema:oV()},{key:"highlight",type:"string",ooxmlElement:"w:highlight",storage:"mark",tracked:!0,carrier:um("highlight"),schema:yl()},mc("color","string","w:color",yl()),mc("fontSize","number","w:sz",Iu()),mc("fontFamily","string","w:rFonts",yl()),mc("letterSpacing","number","w:spacing",Iu()),mc("vertAlign","string","w:vertAlign",{oneOf:[{enum:["superscript","subscript","baseline"]},{type:"null"}]}),mc("position","number","w:position",Iu()),Un("dstrike","boolean","w:dstrike",po()),Un("smallCaps","boolean","w:smallCaps",po()),mc("caps","boolean","w:caps",po(),"textTransform"),Un("shading","object","w:shd",xu({fill:{oneOf:[{type:"string",minLength:1},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},val:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("border","object","w:bdr",xu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},sz:{oneOf:[{type:"number"},{type:"null"}]},color:{oneOf:[{type:"string",minLength:1},{type:"null"}]},space:{oneOf:[{type:"number"},{type:"null"}]}}),"borders"),Un("outline","boolean","w:outline",po()),Un("shadow","boolean","w:shadow",po()),Un("emboss","boolean","w:emboss",po()),Un("imprint","boolean","w:imprint",po()),Un("charScale","number","w:w",Iu(),"w"),Un("kerning","number","w:kern",Iu(),"kern"),Un("vanish","boolean","w:vanish",po()),Un("webHidden","boolean","w:webHidden",po()),Un("specVanish","boolean","w:specVanish",po()),Un("rtl","boolean","w:rtl",po()),Un("cs","boolean","w:cs",po()),Un("bCs","boolean","w:bCs",po(),"boldCs"),Un("iCs","boolean","w:iCs",po(),"italicCs"),Un("eastAsianLayout","object","w:eastAsianLayout",xu({id:{oneOf:[{type:"string",minLength:1},{type:"null"}]},combine:{oneOf:[{type:"boolean"},{type:"null"}]},combineBrackets:{oneOf:[{type:"string",minLength:1},{type:"null"}]},vert:{oneOf:[{type:"boolean"},{type:"null"}]},vertCompress:{oneOf:[{type:"boolean"},{type:"null"}]}})),Un("em","string","w:em",yl()),Un("fitText","object","w:fitText",xu({val:{oneOf:[{type:"number"},{type:"null"}]},id:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("snapToGrid","boolean","w:snapToGrid",po()),Un("lang","object","w:lang",xu({val:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},bidi:{oneOf:[{type:"string",minLength:1},{type:"null"}]}})),Un("oMath","boolean","w:oMath",po()),Un("rStyle","string","w:rStyle",yl(),"styleId"),Un("rFonts","object","w:rFonts",xu({ascii:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsi:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsia:{oneOf:[{type:"string",minLength:1},{type:"null"}]},cs:{oneOf:[{type:"string",minLength:1},{type:"null"}]},asciiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hAnsiTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},eastAsiaTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},csTheme:{oneOf:[{type:"string",minLength:1},{type:"null"}]},hint:{oneOf:[{type:"string",minLength:1},{type:"null"}]}}),"fontFamily"),Un("fontSizeCs","number","w:szCs",Iu()),Un("ligatures","string","w14:ligatures",yl()),Un("numForm","string","w14:numForm",yl()),Un("numSpacing","string","w14:numSpacing",yl()),Un("stylisticSets","array","w14:stylisticSets",iV()),Un("contextualAlternates","boolean","w14:cntxtAlts",po())],GH=new Set(dm.map(e=>e.key)),aV=Object.fromEntries(dm.map(e=>[e.key,e])),WH={mark:dm.filter(e=>e.storage==="mark").map(e=>e.key),runAttribute:dm.filter(e=>e.storage==="runAttribute").map(e=>e.key)};function _a(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function fm(){const e=globalThis;return{sink:typeof e.__superdocV2BenchPipelineTiming=="function"?e.__superdocV2BenchPipelineTiming:null,workerContext:e.__superdocV2BenchWorkerMessageContext??null}}function n2(e){const{sink:t}=fm();if(t)try{t(e)}catch{}}var r2=new WeakMap;function lV(e){let t=r2.get(e);return t||(t={refCount:0,generation:0,abortController:new AbortController,inFlight:null,activeMutationTokens:new Set},r2.set(e,t)),t.refCount+=1,t}function cV(e,t){t.refCount=Math.max(0,t.refCount-1),!(t.refCount>0)&&(t.abortController.abort("ui-controller-destroyed"),t.inFlight=null,t.activeMutationTokens.clear(),r2.delete(e))}var uV=new Set(Object.values(ut));function o2(e,t){return typeof e=="string"&&uV.has(e)?e:t}function dA(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:ut.notReady}:{ok:!1,reason:o2(t,ut.targetUnresolved)}}return{ok:!0}}var dV=["document-replaced","editorCreate","active-editor-change","document-mode-change","zoomChange","measurement-unit-change","viewport-change","fonts-changed"],fV={[H4.bulletList]:"bullet",[H4.numberedList]:"ordered"};function fA(e){return fV[e]??null}var hV={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 pV(e){const t=hV[e];return t?{preset:t,behavior:"toggleStyle"}:{}}var mV={status:"ready",empty:!0,target:null,selectionTarget:null,activeMarks:[],activeCommentIds:[],activeChangeIds:[],quotedText:""},gV=[{key:"contentControls",match:"exact",note:"full-document SDT catalog parse (the measured during-load cliff)"},{key:"contentControls:inRange:",match:"prefix",note:"same adapter load() as the catalog, issued per settled selection"},{key:"hyperlinks:",match:"prefix",note:"per-block hyperlink list over the loading story"},{key:"styles:catalog:",match:"prefix",note:"WordStyleModel recompile from package bytes"},{key:"comments",match:"exact",note:"audited: full comments list; stale-served during load"},{key:"trackChanges",match:"exact",note:"audited: shared all-story tracked-changes catalog; stale-served during load"},{key:"trackChanges:all",match:"exact",note:"audited: current-token validation over the shared all-story catalog; consumers fail closed on non-ready"},{key:"tables",match:"exact",note:"reserved: full tables catalog"},{key:"sections",match:"exact",note:"reserved: full sections list"}],vV=new Set(["/word/comments.xml","/word/commentsExtended.xml","/word/commentsIds.xml"]);function yV(e){return gV.some(t=>t.match==="exact"?t.key===e:e.startsWith(t.key))}var hA={ready:0,stale:1,pending:2};function bl(...e){let t="ready";for(const n of e)hA[n]>hA[t]&&(t=n);return t}function Mt(e,t){if(typeof e!="function")return t;try{const n=e();return n===void 0?t:n}catch{return t}}function Ir(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function pr(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 Kn(e,t="CAPABILITY_UNAVAILABLE"){return{success:!1,failure:{code:t,message:e}}}function Lf(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 Pf(e){if(!e||typeof e!="object")return null;const t=e.target;return t&&typeof t=="object"?t:null}function i2(e){if(!e||typeof e!="object")return!1;const t=e,n=i=>{if(!i||typeof i!="object")return!1;const s=i;return s.kind==="text"&&typeof s.blockId=="string"&&typeof s.offset=="number"},r=i=>{if(!i||typeof i!="object")return!1;const s=i,a=s.range;return typeof s.blockId=="string"&&typeof a?.start=="number"&&typeof a.end=="number"};if(Array.isArray(t.segments)){const i=t.segments[0],s=t.segments[t.segments.length-1];return r(i)&&r(s)}if(t.kind==="selection")return n(t.start)&&n(t.end);if(t.kind!=="text"||typeof t.blockId!="string")return!1;const o=t.range;return typeof o?.start=="number"&&typeof o.end=="number"}function pA(e,t){if(!e||typeof e!="object")return null;const n=Pf(e),r=e,o=r.navigationTarget&&typeof r.navigationTarget=="object"?r.navigationTarget:null;if(o?.kind==="block"&&typeof o.blockId=="string"&&o.blockId.length>0){const i={kind:"text",blockId:o.blockId,range:{start:0,end:0},...o.story&&typeof o.story=="object"?{story:o.story}:{},...r.address&&typeof r.address=="object"?{address:r.address}:{}};if(t?.preferStableBlock||!i2(n))return i}return n}function wr(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 Df(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=Pf(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 Ni(e,t,n){return ro(e)!==t?!1:n?wr(Df(e))===wr(n):!0}function hm(e){const t=Df(e);if(!(!t||wr(t)===wr(null)))return t}function bV(e){if(typeof e!="string"||e.length===0)return;const t=I6(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 wV(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 s2(e){if(!e||typeof e!="object")return null;const t=e.selectionTarget;return t&&typeof t=="object"?t:null}function pm(e){if(!e||typeof e!="object")return null;const t=e.id;return typeof t=="string"&&t.length>0?t:null}function CV(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 ro(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 kV(e){if(!e||typeof e!="object")return null;const t=e,n=t.anchor,r=t.focus,o=n?.visualCaret,i=r?.visualCaret,s=o?.trackChangeId,a=i?.trackChangeId;return typeof s=="string"&&s.length>0&&s===a?s:null}var mA=new WeakMap;function gA(e){const t=[],n=i=>{typeof i=="string"&&i.length>0&&!t.includes(i)&&t.push(i)},r=i=>{if(!i||typeof i!="object")return;const s=i,a=s.sourceIds;if(a&&typeof a=="object"&&(n(a.wordIdInsert),n(a.wordIdDelete),Array.isArray(a.wordIdOther)))for(const f of a.wordIdOther)n(f);const l=s.wordRevisionIds;l&&typeof l=="object"&&(n(l.insert),n(l.delete),n(l.format));const c=s.replacement;if(c&&typeof c=="object")for(const f of[c.inserted,c.deleted])f&&typeof f=="object"&&(n(f.id),n(f.wordId));const d=s.move;if(d&&typeof d=="object")for(const f of[d.source,d.destination])f&&typeof f=="object"&&(n(f.id),n(f.wordId))};r(e);const o=e?.change;return o&&o!==e&&r(o),t}function zs(e){const t=mA.get(e);if(t)return t;const n=new Set,r=new Map;for(const i of e){const s=ro(i);if(s){n.add(s);for(const a of gA(i)){r.has(a)||r.set(a,s);const l=`imported:${a}`;r.has(l)||r.set(l,s)}}}const o={toPublicId(i){if(n.has(i))return i;const s=r.get(i);return s!=null&&n.has(s)?s:null},aliasesFor(i){const s=[i];for(const[a,l]of r)l===i&&!s.includes(a)&&s.push(a);return s}};return mA.set(e,o),o}var vA=new WeakMap,yA=new WeakMap;function gc(e,t){const n=wr(t);let r=vA.get(e);r||(r=new Map,vA.set(e,r));const o=r.get(n);if(o)return o;const i=zs(e.filter(s=>wr(Df(s))===n));return r.set(n,i),i}function SV(e){return!!e&&typeof e=="object"&&e.storyType==="textbox"}function _V(e,t){const n=t.filter(o=>e.some(i=>ro(i)===o&&Df(i)==null));if(n.length===0)return null;if(n.length===1)return n[0];const r=new Set;for(const o of n){const i=e.find(s=>ro(s)===o);if(i)for(const s of gA(i)){if(r.has(s))return null;r.add(s)}}return n[0]}function AV(e){const t=yA.get(e);if(t)return t;const n=e.filter(o=>Df(o)!=null),r=n.length===e.length?e:n;return yA.set(e,r),r}function IV(e){const{selectionIds:t,publicIds:n,selection:r,bodyItems:o,allStoryItems:i}=e;if(t.length===0)return null;const s=c=>{for(const d of t){const f=c.toPublicId(d);if(f)return f}return null},a=ss(r),l=wr(a)===wr(null);if(i){const c=l?AV(i):i,d=s(gc(c,a));if(d)return d;const f=n?.find(h=>c.some(g=>Ni(g,h,a)));return f||(l?s(zs(o)):SV(a)?_V(i,t):null)}return l?s(zs(o))??t[0]??null:null}function xV(e,t){const n=e.find(r=>ro(r)===t||r.importedId===t);return n?n.rootCommentId??n.parentCommentId??ro(n)??t:null}function EV(e){const t=e.selectionTarget;if(t){const s=t.start,a=t.end,l=typeof s?.blockId=="string"?s.blockId:void 0,c=typeof a?.blockId=="string"?a.blockId:l;if(l)return{startBlockId:l,endBlockId:c??l}}const n=e.target,r=n&&Array.isArray(n.segments)?n.segments:[],o=r[0]?.blockId,i=r[r.length-1]?.blockId;return typeof o=="string"?{startBlockId:o,endBlockId:typeof i=="string"?i:o}:null}function Vr(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 TV=64;function vc(e){return e.length<=TV}function ss(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 Ao(e,t){return{kind:"block",nodeType:"paragraph",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}function Aa(e){return{kind:"block",nodeType:"paragraph",nodeId:e}}function bA(e,t){return{kind:"block",nodeType:"listItem",nodeId:e,...t&&typeof t=="object"?{story:t}:{}}}var wA=720;function Vs(e){return Math.round(e*20)}function Eu(e){return typeof e=="number"&&Number.isFinite(e)}function RV(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=Eu(i.left)?Vs(i.left):Eu(i.start)?Vs(i.start):void 0,a=Eu(i.right)?Vs(i.right):Eu(i.end)?Vs(i.end):void 0,l=Eu(i.firstLine)?Vs(i.firstLine):void 0,c=Eu(i.hanging)?Vs(i.hanging):void 0;return s==null&&a==null&&l==null&&c==null?null:{...s!=null?{left:s}:{},...a!=null?{right:a}:{},...l!=null?{firstLine:l}:{},...c!=null?{hanging:c}:{}}}function a2(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 MV(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 Of(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 wl(e){return Of(e.target)??Of(e.selectionTarget)}var CA=["fontFamily","fontSize","color","highlight"],LV={undo:"history.undo",redo:"history.redo"},Ff=["bold","italic","underline","strikethrough"];function l2(e){return CA.includes(e)}function Tu(e){const t=e.target,n=t&&Array.isArray(t.segments)?t.segments:[],r=[],o=(l,c,d)=>{typeof l!="string"||typeof c!="number"||typeof d!="number"||r.push({blockId:l,start:Math.min(c,d),end:Math.max(c,d)})};for(const l of n){const c=l?.range;o(l?.blockId,c?.start,c?.end)}if(r.length>0)return r;const i=e.selectionTarget,s=i?.start,a=i?.end;return!s||!a||s.blockId!==a.blockId||o(s.blockId,s.offset,a.offset),r}function as(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 PV(e){const t=as(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=Tu(e);return t.length===0?null:[PV(e),...t.map(n=>`${n.blockId}:${n.start}-${n.end}`)].join("|")}function kA(e){const t=e.selectionTarget;return!t||typeof t!="object"?null:pc({selectionTarget:t})}function DV(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 OV(e,t){return Math.max(e.start,t.start)<Math.min(e.end,t.end)}function FV(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 NV(e,t){return e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return o?.blockId===n.blockId&&o?.start===n.start&&o?.end===n.end})}function SA(e,t){const n=Tu(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=>NV(n,FV(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 BV(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 c2(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 zV(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 VV(e,t){return e==="fontFamily"?t.toLowerCase():e==="color"||e==="highlight"?t.toUpperCase():t}function _A(e,t){if(!e)return{};const n=new Map;for(const i of Tu(t)){const s=n.get(i.blockId)??[];s.push({start:i.start,end:i.end}),n.set(i.blockId,s)}if(n.size===0)return{};const r=Array.isArray(e.blocks)?e.blocks:[],o={};for(const i of CA){const s=new Map;let a=!1,l=!1;for(const c of r){const d=typeof c?.blockId=="string"?c.blockId:null;if(!d)continue;const f=n.get(d);if(!f?.length)continue;const h=Array.isArray(c?.runs)?c.runs:[];for(const g of h){const m=g?.range,v=typeof m?.start=="number"?m.start:null,_=typeof m?.end=="number"?m.end:null;if(v==null||_==null||!f.some(y=>OV(y,{start:v,end:_})))continue;a=!0;const k=BV(g?.styles,i);if(k===void 0){l=!0;continue}const S=VV(i,k);if(s.has(S)||s.set(S,k),s.size>1)break}if(s.size>1)break}a&&!l&&s.size===1&&(o[i]=[...s.values()][0])}return o}function u2(e,t){const n=Vr(e)[0];return n?t==="nodeId"?{kind:"after",nodeId:n}:{kind:"after",target:Ao(n)}:{kind:"documentEnd"}}function sn(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 Nf(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 mm(e){const t=e,n=t.change;return n&&typeof n=="object"?n:t}function js(e){if(Ir(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 gm(e){return!!e&&typeof e=="object"&&e.success===!0}function Io(e){return!(e===!1||e&&typeof e=="object"&&e.success===!1)}function Bf(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function d2(e){const t=[],n=r=>{if(!r||typeof r!="object")return;const o=r;if(Array.isArray(o.runs)&&t.push(o),Array.isArray(o.rows))for(const i of o.rows){const s=i?.cells;if(Array.isArray(s))for(const a of s){const l=a;if(Array.isArray(l?.blocks))for(const c of l.blocks)n(c);l?.paragraph&&n(l.paragraph)}}};if(Array.isArray(e))for(const r of e)n(r);return t}function yc(e,t){return e.sourceAnchor?.sourceNodeId===t?!0:e.id===t}function vm(e){return e.trackedChange?.kind==="delete"?0:typeof e.text=="string"?e.text.length:0}function ki(e){let t=!1,n=null,r=null,o=null;for(const i of e)t=i,!Io(i)&&n===null&&(n=i),gm(i)&&(o=i),i!==!1&&(r=i);return n??o??r??t}function jV(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 UV(e){return e.startsWith("#")?{kind:"anchor",anchor:e.slice(1)}:{kind:"external",url:e}}function ym(e){return Au(e)?.trackDecision??null}function HV(e){return{found:e.length>0,success:e.length>0,rects:e,rect:e[0]}}function Cl(e){return{found:!1,success:!1,rects:[],reason:e}}function $V(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 GV(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.blockId!="string"||!t.range||typeof t.range!="object")return!1;const n=t.range;return Number.isInteger(n.start)&&Number.isInteger(n.end)&&n.start>=0&&n.start<=n.end}function AA(e){if(!e||e.kind!=="text"||!Array.isArray(e.segments)||e.segments.length===0)return null;const t=Array.from(e.segments);if(!t.every(GV))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 WV(e){return e.selectionTarget?e.selectionTarget:AA(e.target)}function Ru(e){if(e.empty)return null;if(e.selectionTarget)return e.selectionTarget;const t=AA(e.target);return t&&t.start.kind==="text"&&t.end.kind==="text"&&t.start.blockId!==t.end.blockId?null:t}function f2(e){return!e.inline||typeof e.docRoute!="string"?null:e.docRoute.startsWith("format.")?e.docRoute.slice(7):null}var h2={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},KV=Object.fromEntries(Object.entries(h2).filter(([e])=>aV[e]?.tracked===!0));function qV(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:{...h2}};default:return null}}function YV(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 XV(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 ZV(e){const t=e.superdoc,n=new Map,r=new Map;let o=null,i=0;const s=[];let a=null,l=0,c=!1,d=Promise.resolve(),f=null,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:0,pointerSelecting:!1,keyboardSelecting:!1},g=0;const m=new Set;let v={},_="",k=null;const S=()=>{const u=t?.activeEditor;return u&&typeof u=="object"?u:null},y=()=>{const u=S()?.doc;return u&&typeof u=="object"?u:null},w=()=>{const u=S()?.v2TrackedChanges;return u&&typeof u=="object"?u:null},T=()=>{const u=S();if(u?.editorVersion!==2)return null;const p=u.reviewWindow;return p&&typeof p=="object"?p:null},L=()=>{const u=T();return!u||typeof u.getSnapshot!="function"?null:Mt(()=>u.getSnapshot(),null)},O=()=>typeof T()?.getSnapshot=="function",U=u=>{const p=u?.status;return p==="ready"||p==="stale"?p:"pending"},P=()=>{const u=S()?.host;return u&&typeof u=="object"?u:null},B=u=>{if(u.storyType!=="headerFooterPart"||typeof u.refId!="string")return null;const p=S(),b=P(),A=p?.pageLayout??b?.pageLayout;if(!A||typeof A!="object")return null;const x=A.getActiveRulerContext,N=b?.resolveHeaderFooterEditTarget;if(typeof x!="function"||typeof N!="function")return null;const G=Mt(()=>x.call(A),null);if(!G||typeof G.pageIndex!="number")return null;for(const oe of["header","footer"]){const fe=Mt(()=>N.call(b,{pageIndex:G.pageIndex,kind:oe}),null);if(!(fe?.status!=="ready"||fe.refId!==u.refId||typeof fe.sectionId!="string"||!["default","first","even"].includes(String(fe.slotVariant))))return{kind:"story",storyType:"headerFooterSlot",section:{kind:"section",sectionId:fe.sectionId},headerFooterKind:oe,variant:fe.slotVariant}}return null},z=()=>{const u=P(),p=u?.getPendingInlineFormat;if(typeof p!="function")return null;const b=Mt(()=>p.call(u),null);return b&&typeof b=="object"?b:null},R=u=>{const p=f2(u);if(!p)return null;const b=z();if(!b||!(p in b))return null;const A=b[p];return u.inline?.kind==="toggle"?A===!0:A!=null&&A!==""},H=u=>{const p=f2(u);if(!p)return;const b=z();if(!b||!(p in b))return;const A=b[p];if(typeof A=="string"&&A!=="")return A;if(typeof A=="number"&&Number.isFinite(A))return String(A)},E=(u,p)=>{const b=P(),A=b?.setPendingInlineFormat;typeof A=="function"&&Mt(()=>A.call(b,u,p),void 0)},$=u=>{const p=P(),b=p?.clearPendingInlineFormat;typeof b=="function"&&Mt(()=>b.call(p,u),void 0)},Q=new Set(["bold","italic","underline","strikethrough"]),ie=u=>{const p=z();if(!p)return;const b=Array.isArray(u.activeMarks)?u.activeMarks:[];let A=null;for(const x of Object.keys(p)){const N=p[x];let G;if(Q.has(x))G=b.includes(x)===(N===!0);else if(l2(x)){if(N==null)continue;A||(A=Ml(u)),G=A[x]===N}else G=!1;G&&$(x)}},ee=()=>{const u=S()?.editCommands;return u&&typeof u=="object"?u:null},ne=u=>{const p=ee();if(!p||typeof p.getSnapshot!="function")return null;const b=Mt(()=>p.getSnapshot(),null)?.commands?.[u];return b&&typeof b=="object"?b:null},Ie=()=>ne("lists.apply"),pe=u=>{const p=u?.value?.seed;return p==="bullet"||p==="ordered"?p:null},ye=u=>{const p=LV[u];return p?ne(p):null},ve=()=>{const u=P();if(!u||typeof u.getTableContext!="function")return null;const p=Mt(()=>u.getTableContext(),null);return p&&typeof p=="object"?p:null},Se=()=>{const u=ve();if(!u||u.inTable!==!0)return null;const p=u.table,b=typeof p?.nodeId=="string"&&p.nodeId.length>0?p.nodeId:null;if(!b)return null;const A=u.row,x=u.column,N=u.cell,G=typeof A?.index=="number"&&Number.isInteger(A.index)?A.index:null,oe=typeof x?.index=="number"&&Number.isInteger(x.index)?x.index:null;if(G==null||oe==null)return null;const fe=typeof N?.nodeId=="string"&&N.nodeId.length>0?N.nodeId:null,Me=u.cellRange;return{tableNodeId:b,rowIndex:G,columnIndex:oe,cellNodeId:fe,mergeRange:YV(Me)}},le=new Map;let Oe=null,He=null,it=0,yt=0,De=0;const $e=new Set,Ye=(u,p)=>u===p?!0:!u||!p?!1:u.id===p.id&&u.paintedEntityId===p.paintedEntityId&&wr(u.story)===wr(p.story),J=u=>Array.from($e).some(p=>Ye(p,u)),C=u=>{const p=P();if(typeof p?.getHandles!="function")return;const b=Mt(()=>p.getHandles(),null),A=b?.review;if(A){if(u){if(typeof A.setActiveReviewTarget!="function")return;const x=b?.layout;Mt(()=>A.setActiveReviewTarget({entityType:"trackedChange",entityId:u.id,...u.paintedEntityId?{paintedEntityId:u.paintedEntityId}:{},origin:"panel",layoutEpoch:typeof x?.generation=="number"?x.generation:0,story:u.story??{kind:"story",storyType:"body"}}),null);return}typeof A.getActiveReviewTarget!="function"||typeof A.clearActiveReviewTarget!="function"||Mt(()=>A.getActiveReviewTarget(),null)?.entityType==="trackedChange"&&Mt(()=>A.clearActiveReviewTarget(),void 0)}},re=(u,p)=>{He=u,it+=1,De+=1,p?.invalidateQueuedNavigation!==!1&&(yt+=1)},V=new Set;let D,j=!1,W=null;const Y=new Map,Z=new Set;let q=null,me=null,Te=!1,_e=null,xe=0,We=null,tt=null,at=null;const Ut=[],Ct=()=>{if(Te||j)return;Te=!0;const u=()=>{Te=!1,j||Ot("async-read-settled")};typeof queueMicrotask=="function"?queueMicrotask(u):Promise.resolve().then(u)},Je=250,Vt=5e3,nn=u=>{j||_e&&xe<=u||(_e&&clearTimeout(_e),xe=u,_e=setTimeout(()=>{_e=null,xe=0,j||Ot()},Math.max(0,u-Date.now())))},Ln=new WeakMap;let Zt=0;const nt=u=>{if(!u)return"none";let p=Ln.get(u);return p==null&&(p=Zt+=1,Ln.set(u,p)),`e${p}`};let Rt=0;const jt=e.superdoc,$t=lV(jt),Qt=()=>{$t.abortController.abort("review-mutation-started"),$t.inFlight=null},Fn=()=>{$t.generation+=1,$t.abortController=new AbortController,$t.inFlight=null},kn=u=>{const p=$t.activeMutationTokens;if(typeof u!="string"||u.length===0||p.has(u))return;const b=p.size===0;p.add(u),b&&Qt()},Vo=u=>{const p=$t.activeMutationTokens;typeof u!="string"||!p.delete(u)||p.size===0&&Fn()},xr=u=>{const p=w(),b=p?.listTrackedChanges;if(typeof b!="function")return S()?.editorVersion===2?Promise.reject(new Error("v2-tracked-changes-bridge-pending")):u();if($t.activeMutationTokens.size>0)return Promise.reject(new Error("ui-review-catalog-superseded"));const A=$t.generation,x=$t.inFlight;if(x?.generation===A)return x.promise;const N=$t.abortController.signal,G=Me=>{if(N.aborted||A!==$t.generation||Me?.reason==="review-hydration-superseded")throw new Error("ui-review-catalog-superseded");return Me},oe=b.call(p,{blocking:!1,signal:N});if(!Ir(oe))return G(oe);const fe=Promise.resolve(oe).then(G);return $t.inFlight={generation:A,promise:fe},fe.then(()=>{$t.inFlight?.promise===fe&&($t.inFlight=null)},()=>{$t.inFlight?.promise===fe&&($t.inFlight=null)}),fe};let Jn=null,wn=new Set,qn=null,jo=0,jr=null;const ke=()=>`${nt(S())}|m${Rt}`,Ue=()=>{Jn=null,wn=new Set},et=u=>{for(const p of["trackChanges","trackChanges:all"]){const b=Y.get(p);if(!b?.hasSettled||!Array.isArray(b.value))continue;const A=b.value.filter(x=>{const N=ro(x);return!N||!u.has(N)});A.length!==b.value.length&&Y.set(p,{...b,value:A})}},lt=u=>{const p=()=>{if(!j)for(const N of[...V])N(D)},b=Bf(u)?u:null,A=S()?.documentMutationReadiness,x=()=>{const N=globalThis.requestAnimationFrame;return typeof N!="function"?Promise.resolve():new Promise(G=>{let oe=!1;const fe=()=>{oe||(oe=!0,clearTimeout(Me),G())},Me=setTimeout(fe,250);N(()=>N(()=>setTimeout(fe,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(x,()=>{}).then(p,p);return}catch{}p()},Dt=(u,p)=>{const b=D.trackChanges,A=b.items.filter(G=>{const oe=ro(G);return!oe||!u.has(oe)});if(A.length===b.items.length)return;He&&u.has(He.id)&&re(null);const x=new Set;for(const G of A){const oe=mm(G),fe=G,Me=oe.author??oe.authorEmail??fe.author??fe.authorEmail;typeof Me=="string"&&x.add(Me)}const N=b.items.length-A.length;D={...D,trackChanges:{...b,items:A,total:Math.max(A.length,b.total-N),activeId:b.activeId&&u.has(b.activeId)?null:b.activeId,authors:[...x]}},lt(p)},Pt=u=>{const p=D.trackChanges,b=p.items.length>0||p.total!==0||p.activeId!==null||p.authors.length>0;qn=ke(),He!==null&&re(null),D={...D,trackChanges:{...p,items:[],total:0,activeId:null,authors:[]}},b&&lt(u)},an=(u,p)=>{if(u.size===0)return;const b=ke(),A=Jn===b?wn:new Set,x=new Set([...u].filter(N=>!A.has(N)));x.size!==0&&(Jn=b,wn=new Set([...A,...x]),et(wn),Dt(x,p))},Lt=u=>Jn===u&&wn.size>0?wn:null,dr=u=>{const p=ke(),b=Lt(p),A=u.map(Nf).filter(x=>{if(x==null)return!1;const N=ro(x);return N!=null&&!b?.has(N)});for(const x of["trackChanges","trackChanges:all"])Y.set(x,{token:p,value:[...A],hasSettled:!0,inflightToken:null})},Ur=()=>`${ke()}|m${vr()}|s${jo}`,mo=u=>JSON.stringify({t:u.target??null,s:u.selectionTarget??null}),Si=["contentControls:inRange:","query:","effInline:"],rn=120,Cn=180,Yn=()=>{const u=P(),p=u?.getDocumentLoadingSnapshot;if(typeof p!="function")return"unknown";const b=Mt(()=>p.call(u),null)?.sourceStage;return b==="opening"||b==="bootstrap-ready"||b==="source-loading"?"loading":b==="source-complete"||b==="source-failed"||b==="source-cancelled"?"complete":"unknown"},mr=new Map,qt=new Map,Pn=new Map;let Hr=null,go=0,ii=0;const _i=u=>{const p=ke();mr.get(u)!==p&&(mr.set(u,p),Ct())},kl=()=>{const u=Y.get("comments");return u?.hasSettled?Array.isArray(u.value)&&u.value.length>0:u?.inflightToken!=null},Bi=(u,p)=>mr.get(u)===p,xa=()=>{const u=ke();let p=!1;for(const[b,A]of qt){if(A!==u){qt.delete(b);continue}if(Pn.get(b)===u)continue;const x=Y.get(b);!x?.hasSettled||x.token!==u||x.inflightToken!=null||(Y.set(b,{...x,token:null,inflightToken:null}),Pn.set(b,u),p=!0)}p&&Ct()},Er=u=>{u==="comments"?go+=1:ii+=1,_i(u);let p=!1;return()=>{p||(p=!0,u==="comments"?go=Math.max(0,go-1):ii=Math.max(0,ii-1),(u==="comments"?go:ii)===0&&mr.get(u)===ke()&&mr.delete(u),Ct())}},oo=u=>{_i("contentControls")},zi=()=>{const u=Y.get("trackChanges");u?.hasSettled||u?.inflightToken!=null||_i("trackChanges")},be=()=>{const u=Y.get("comments");u?.hasSettled||u?.inflightToken!=null||_i("comments")},ze=6500,kt=250;let ct=0,Rn=0,xn=!1,Tr=null;const Rr=()=>{if(j||Tr)return;const u=()=>{if(Tr=null,j)return;const p=Date.now()-ct;if(gr()||p<ze){Tr=setTimeout(u,kt);return}xn=!1,Ot()};Tr=setTimeout(u,0)};let xo=null,Mr=null;const $r=()=>{const u=P();if(!u||xo===u)return;Mr&&(Mr(),Mr=null),xo=u;const p=u.subscribeDocumentLoading;if(typeof p!="function"){xo=null,Uo(ze);return}try{const b=N=>{const G=N?.sourceStage;(G==="source-complete"||G==="source-failed"||G==="source-cancelled")&&(Hr=ke(),xa(),ct=Math.max(ct,Date.now()),Rr())},A=p.call(u,b);typeof A=="function"&&(Mr=A);const x=u.getDocumentLoadingSnapshot;typeof x=="function"&&b(Mt(()=>x.call(u),null))}catch{xo=null,Uo(ze)}},vo=()=>{const u=S()?.host,p=u?.getForegroundMutationState;if(typeof p!="function")return null;const b=Mt(()=>p.call(u),null);return{active:typeof b?.active=="number"?b.active:0,pending:typeof b?.pending=="number"?b.pending:0}},gr=()=>{const u=vo();return!!(u&&(u.active>0||u.pending>0))},Uo=(u=rn)=>{j||We||(We=setTimeout(()=>{if(We=null,j)return;if(tt&&gr()){Uo(),Ot();return}const p=tt;tt=null,p===Ur()&&Vi("selection",p,Il,Hi),Ot()},u))},cs=(u,p)=>{if(!vo())return!1;const b=`${u}\0${p}`;return Z.has(b)?!1:(Z.add(b),Uo(Cn),!0)},si=u=>{if(q==null||u===q)return me?.timer&&clearTimeout(me.timer),me=null,q=u,!1;if(me?.key===u)return me.ready?(me=null,q=u,!1):!0;me?.timer&&clearTimeout(me.timer);const p={key:u,ready:!1,timer:null};return p.timer=setTimeout(()=>{j||me!==p||(p.timer=null,p.ready=!0,Ot())},Cn),me=p,!0},bc=u=>eV(u),ai=()=>{Us(),Ot()};let Eo=null,Ai=!1,us=0;const Ea=()=>{Eo=null,Ai=!1,us+=1},Sl=()=>{const u=S(),p=u?.documentMutationReadiness;if(!u||typeof p?.whenPainted!="function"||(Eo={editor:u,readiness:p,afterEpoch:typeof p.getRenderEpoch=="function"?Mt(()=>p.getRenderEpoch.call(p),null):null},Ai))return;Ai=!0;const b=us;(async()=>{for(;!j&&b===us;){const x=Eo;if(Eo=null,!x){Ai=!1;return}let N=!1;try{await x.readiness.whenPainted.call(x.readiness,typeof x.afterEpoch=="number"?{afterEpoch:x.afterEpoch}:void 0),N=!0}catch{}if(j||b!==us)return;if(S()!==x.editor){Ea();return}N&&ai()}})()},Mu=()=>{at&&clearTimeout(at),at=setTimeout(()=>{at=null,j||ai()},500)},Vi=(u,p,b,A)=>{let x;try{x=b()}catch{x=void 0}if(!Ir(x)){const oe={token:p,value:A(x),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0};return Y.set(u,oe),oe}const N=Y.get(u),G=N?.failedToken===p;return Y.set(u,{token:N?.token??null,value:N?.value??null,hasSettled:N?.hasSettled??!1,inflightToken:p,failedToken:G?p:null,failureCount:G?N.failureCount??0:0,retryAtMs:0}),Promise.resolve(x).then(oe=>{const fe=Y.get(u);if(!fe||fe.inflightToken!==p)return;Y.set(u,{token:p,value:A(oe),hasSettled:!0,inflightToken:null,failedToken:null,failureCount:0,retryAtMs:0});const{sink:Me,workerContext:Ve}=fm();if(Me){const je=_a();Ut.push({key:u,settledAtMs:je,commandId:Ve?.commandId??null,commandKind:Ve?.commandKind??null}),n2({stage:"superdoc-ui-async-read-settled",atMs:je,key:u,settledAtMs:je,commandId:Ve?.commandId??null,commandKind:Ve?.commandKind??null})}Ct()},()=>{const oe=Y.get(u);if(!oe||oe.inflightToken!==p)return;const fe=oe.failedToken===p?(oe.failureCount??0)+1:1,Me=Math.min(Vt,Je*2**Math.min(fe-1,8)),Ve=Date.now()+Me;Y.set(u,{...oe,inflightToken:null,failedToken:p,failureCount:fe,retryAtMs:Ve}),nn(Ve)}),null},To=(u,p,b,A)=>{const x=Y.get(u);if(x&&x.token===p&&x.hasSettled)return{value:x.value,status:"ready"};if(yV(u)&&!Bi(u,p)){if(Yn()==="loading")return xn=!0,$r(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(xn)return Rr(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(Date.now()-Rn<ze)return xn=!0,Rr(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"}}if(gr())return Uo(),x?.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(x?.failedToken===p&&x.inflightToken==null&&(x.retryAtMs??0)>Date.now())return nn(x.retryAtMs),x.hasSettled?{value:x.value,status:"stale"}:{value:null,status:"pending"};if(!x&&u.startsWith("effInline:")&&si(u))return{value:null,status:"pending"};if(!x&&cs(u,p))return{value:null,status:"pending"};if(!x||x.inflightToken!==p){const G=Vi(u,p,b,A);if(G)return{value:G.value,status:"ready"}}const N=Y.get(u);return N?.hasSettled?{value:N.value,status:"stale"}:{value:null,status:"pending"}},_l=u=>{for(const p of Y.keys())u(p)&&Y.delete(p)},zf=u=>{const p=mo(u),b=kA(u);return new Set([`contentControls:inRange:${p}`,`query:${p}`,...b?[`effInline:${b}`]:[]])},ji=u=>{const p=zf(u);_l(b=>Si.some(A=>b.startsWith(A))&&!p.has(b));for(const b of Z){const A=b.split("\0",1)[0];Si.some(x=>A.startsWith(x))&&!p.has(A)&&Z.delete(b)}},Ta=()=>{const u=S();u!==jr&&(Ea(),jr=u,Y.clear(),_e&&clearTimeout(_e),_e=null,xe=0,me?.timer&&clearTimeout(me.timer),me=null,q=null,k=null,o=null,tt=null,Z.clear(),mr.clear(),qt.clear(),Pn.clear(),Hr=null,xn=!1,Mr&&Mr(),Mr=null,xo=null,Ue(),qn=null)},Us=()=>{Rt+=1,qt.clear(),Pn.clear(),Hr=null,Ue()},Al=()=>{const u=qn===ke();Us(),u&&(dr([]),qn=ke()),Ot()},Vf=u=>{if(typeof u!="string"||u.length===0)return Kn("insertText requires a non-empty string.","INVALID_INPUT");if(vr()==="viewing")return Kn("The document is read-only.","DOCUMENT_READONLY");const p=y(),b=p?.insert;if(!p||typeof b!="function")return Kn("insert is unavailable.");const A=p.selection?.current;if(typeof A!="function")return Kn("selection.current is unavailable.");const x=G=>{const oe=G&&typeof G=="object"?G:null,fe=oe?.selectionTarget??oe?.target??null;return!fe||typeof fe!="object"?Kn("insertText requires a live selection target.","PRECONDITION_FAILED"):Mt(()=>Bl(b.call(p,{type:"text",value:u,target:fe}),Kn("insert failed.")),Kn("insert failed."))};let N;try{N=A.call(p.selection)}catch{return Kn("insertText could not resolve the live selection.","PRECONDITION_FAILED")}return Ir(N)?Promise.resolve(N).then(x,()=>Kn("insertText could not resolve the live selection.","PRECONDITION_FAILED")):x(N)},Ui=(u,p)=>({payload:u,state:D,editor:S(),superdoc:t,context:p,ui:W,execute:(b,A)=>Tc(b,A),executeAsync:(b,A)=>Rm(b,A),doc:y(),selection:D.selection,documentMode:vr(),insertText:Vf}),Ra=u=>u==="editing"||u==="suggesting"||u==="viewing"?u:null,vr=()=>{const u=S(),p=t&&typeof t=="object"?t:null,b=Ra(p?.config?.documentMode),A=Mt(typeof p?.getActiveRuntime=="function"?()=>{const G=p.getActiveRuntime();return typeof G?.getSnapshot=="function"?G.getSnapshot():null}:void 0,null),x=Ra(A?.documentMode),N=Ra(u?.options?.documentMode);return b&&x&&b!==x?b:x??b??N},ds=()=>{const u=t&&typeof t=="object"?t:null,p=u?.interactionConfig?.comments;if(p&&typeof p.readOnly=="boolean")return p.readOnly===!0;const b=u?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.readOnly===!0},Ma=()=>{const u=t&&typeof t=="object"?t:null,p=u?.interactionConfig?.comments;if(p&&typeof p.allowResolve=="boolean")return p.allowResolve===!1;const b=u?.config?.modules?.comments;return!!b&&typeof b=="object"&&b.allowResolve===!1},La=()=>vr()==="viewing"||ds(),Hi=u=>u&&typeof u=="object"?u:null,Ii=(u,p)=>{if(!u)return{...mV,status:p};const b=u.target??null,A=typeof u.text=="string"?u.text:"";return{status:p,empty:u.empty===!0,target:b,selectionTarget:u.selectionTarget??null,activeMarks:Array.isArray(u.activeMarks)?u.activeMarks:[],activeCommentIds:Array.isArray(u.activeCommentIds)?u.activeCommentIds:[],activeChangeIds:Array.isArray(u.activeChangeIds)?u.activeChangeIds:[],quotedText:A}},Pa=()=>{const u=y()?.selection;return To("selection",Ur(),()=>u?.current?u.current({includeText:!0}):void 0,Hi)},Lu=()=>{const{value:u,status:p}=Pa();return Ii(u,p)},Il=()=>{const u=y()?.selection;return u?.current?u.current({includeText:!0}):void 0},xl=u=>{if(u.empty!==!0)return!1;const p=u.selectionTarget,b=p?.start,A=p?.end;return b?.kind==="text"&&A?.kind==="text"&&typeof b.blockId=="string"&&b.blockId===A.blockId&&typeof b.offset=="number"&&b.offset===A.offset},Hs=u=>{const p=P(),b=p?.readLiveSelectionSyncSnapshot;if(typeof b!="function")return;const A=Hi(Mt(()=>b.call(p),null));if(!A||!xl(A))return;const x=Ur(),N=vo(),G=!!(N&&(N.active>0||N.pending>0));if(G)tt=x,Uo();else if(tt=null,Vi("selection",x,Il,Hi))return;const oe=Y.get("selection"),fe=Array.isArray(A.activeMarks)&&A.activeMarks.length>0?A.activeMarks:Array.isArray(D.selection.activeMarks)?D.selection.activeMarks:[],Me=Array.isArray(A.activeCommentIds)?A.activeCommentIds:[],Ve=kV(u),je=wl(D.selection),Ke=Of(A.selectionTarget)??Of(A.target),Ze=je?.range,Ge=Ke?.range,Qe=!!(N&&N.active>0&&je&&Ke&&je.blockId===Ke.blockId&&wr(je.story)===wr(Ke.story)&&typeof Ze?.start=="number"&&typeof Ge?.start=="number"&&Math.abs(Ge.start-Ze.start)<=2),ht=Ve!=null||Qe?D.selection.activeChangeIds.filter(ot=>Ve==null||zs(D.trackChanges.items).aliasesFor(ot).includes(Ve)):[],dt=Array.isArray(A.activeChangeIds)&&A.activeChangeIds.length>0?A.activeChangeIds:ht;Y.set("selection",{token:x,value:{...A,activeMarks:fe,activeCommentIds:Me,activeChangeIds:dt},hasSettled:!0,inflightToken:G?null:oe?.inflightToken??null})},wc=async(u=0)=>{const p=y()?.selection,b=p?.current,A=Ur();if(typeof b!="function")return Y.set("selection",{token:A,value:null,hasSettled:!0,inflightToken:null}),Ot(),D.selection;let x;try{x=b.call(p,{includeText:!0}),Ir(x)&&(x=await Promise.resolve(x))}catch{x=null}return j?Ii(null,"pending"):Ur()!==A?u<1?wc(u+1):D.selection:(Y.set("selection",{token:A,value:Hi(x),hasSettled:!0,inflightToken:null}),Ot(),D.selection)},Cc=()=>{const u=y()?.comments;return To("comments",ke(),()=>u?.list?u.list():void 0,p=>p&&Array.isArray(p.items)?p.items:[])},$s=(u="trackChanges")=>{const p=ke(),b=y()?.trackChanges,A=w(),x=typeof A?.listTrackedChanges=="function"?A.listTrackedChanges:null,N=To(u,p,()=>x?xr(()=>b?.list?.({in:"all"})):b?.list?b.list({in:"all"}):void 0,G=>{const oe=G&&typeof G=="object"?G:null;if(oe?.complete===!1||oe?.sourceCoverageComplete===!1){if(qt.set(u,p),$r(),Hr===p||Yn()==="complete"){const fe=()=>{j||xa()};typeof queueMicrotask=="function"?queueMicrotask(fe):Promise.resolve().then(fe)}}else qt.get(u)===p&&qt.delete(u);return oe&&Array.isArray(oe.items)?oe.items:[]});return qt.get(u)===p&&N.status==="ready"?{...N,status:"stale"}:N},jf=u=>{const p=L(),b=O(),A=b?null:Cc(),x=b&&Array.isArray(p?.commentItems)?p.commentItems:null,N=b?x:A.value,G=b?U(p):A.status,oe=N??[],fe=u.activeCommentIds,Me=Y.get("comments"),Ve=Me?.token===ke()&&Me.hasSettled&&Array.isArray(Me.value)?Me.value:null,je=go>0?Ve:oe;Oe&&je&&!je.some(Ze=>ro(Ze)===Oe)&&(Oe=null);const Ke=Oe??fe[0]??null;return{status:bl(G,u.status),listStatus:G,items:oe,total:oe.length,activeIds:fe,activeId:Ke}},kc=new WeakMap,$i=u=>{const p=kc.get(u);if(p)return p;const b=u.map(Nf).filter(A=>A!=null);return kc.set(u,b),b},El=new WeakMap,Da=(u,p)=>{const b=El.get(u);if(b?.suppressedIds===p)return b.value;const A=p?u.filter(x=>{const N=ro(x);return!N||!p.has(N)}):u;return El.set(u,{suppressedIds:p,value:A}),A},Lr=new WeakMap,Sc=u=>{const p=Lr.get(u);if(p)return p;const b=new Set;for(const x of u){const N=mm(x),G=x,oe=N.author??N.authorEmail??G.author??G.authorEmail;typeof oe=="string"&&b.add(oe)}const A=[...b];return Lr.set(u,A),A},li=()=>{const u=ke();if(O()){const A=Y.get("trackChanges"),x=A?.token===u&&A.hasSettled&&Array.isArray(A.value)?A.value:L()?.trackedChangeItems;return Array.isArray(x)?$i(x):null}const{value:p,status:b}=$s("trackChanges:all");return b==="ready"?$i(p??[]):null},_c=u=>{const p=ke(),b=Lt(p),A=L(),x=O(),N=x?null:$s(),G=x&&Array.isArray(A?.trackedChangeItems)?A.trackedChangeItems:null,oe=x?G:N.value,fe=x?U(A):N.status,Me=Da($i(oe??[]),b),Ve=li(),je=He;if(je&&!$e.has(je)){const zt=Y.get("trackChanges"),$n=zt?.token===p&&zt.hasSettled&&Array.isArray(zt.value)?Da($i(zt.value),b):null,Gn=ii>0?$n:je.story?Ve:Me;Gn&&!Gn.some(Qr=>Ni(Qr,je.id,je.story))&&re(null)}const Ke=Ve??Me,Ze=gc(Ke,ss(u)),Ge=qn===p?[]:b?u.activeChangeIds.filter(zt=>!b.has(zt)):u.activeChangeIds,Qe=Ge.map(zt=>Ze.toPublicId(zt)??zt),ht=He?.story?gc(Ke,He.story):zs(Ke),dt=He?ht.toPublicId(He.id)??He.id:null,ot=IV({selectionIds:Ge,publicIds:Qe,selection:u,bodyItems:Me,allStoryItems:Ve}),Bt=dt??ot;return{status:bl(fe,u.status),items:Me,total:Me.length,activeId:Bt,authors:Sc(Me)}},Pu=(u,p)=>{if(!O())return p;_i("comments");const b=Cc(),A=b.value??p.items;return{status:bl(b.status,u.status),listStatus:b.status,items:A,total:A.length,activeIds:u.activeCommentIds,activeId:Oe??u.activeCommentIds[0]??null}},Gi=(u,p)=>{if(!O())return p;_i("trackChanges");const b=$s(),A=Lt(ke()),x=Da($i(b.value??p.items),A),N=He?.story?gc(x,He.story):zs(x),G=He?N.toPublicId(He.id)??He.id:p.activeId;return{status:bl(b.status,u.status),items:x,total:x.length,activeId:G,authors:Sc(x)}},Ac=u=>{const p=y()?.contentControls,{value:b,status:A}=To("contentControls",ke(),()=>p?.list?p.list():void 0,oe=>oe&&Array.isArray(oe.items)?oe.items:[]),x=b??[],{ids:N,status:G}=Uf(p,u);return{status:bl(A,G,u.status),items:x,total:x.length,activeId:N[0]??null,activeIds:N}},Gs=(u,p)=>{if(!u||typeof u.listInRange!="function")return{lockModesById:new Map,status:"ready"};const b=EV(p);if(!b)return{lockModesById:new Map,status:"ready"};const{value:A,status:x}=To(`contentControls:inRange:${mo(p)}`,ke(),()=>u.listInRange(b),oe=>oe&&Array.isArray(oe.items)?oe.items:[]),N=A??[],G=new Map;for(const oe of N)typeof oe?.id=="string"&&G.set(oe.id,typeof oe.lockMode=="string"?oe.lockMode:"unlocked");return{lockModesById:G,status:x}},Uf=(u,p)=>{const{lockModesById:b,status:A}=Gs(u,p);return{ids:[...b.keys()],status:A}},Du=()=>{const u=t?.fonts;return{options:nj(ej(Mt(u?.getDocumentFontOptions?()=>u.getDocumentFontOptions():void 0,[])),tj(Mt(u?.getFontFamilyOptions?()=>u.getFontFamilyOptions():void 0,[]))),sizeOptions:rj}},Ic=()=>{const u=Mt(t?.getZoomState?()=>t.getZoomState():void 0,null),p=typeof u?.value=="number"?u.value:100,b=u?.mode;return{mode:b==="manual"||b==="fit-width"?b:b==="fixed"?"manual":null,value:p,min:typeof u?.min=="number"?u.min:10,max:typeof u?.max=="number"?u.max:100}},Ou=()=>Mt(t?.getMeasurementUnit?()=>t.getMeasurementUnit():void 0,"in")==="cm"?"cm":"in",Hf=()=>{const u=S();return{ready:u!=null,mode:vr(),dirty:u?!!u.isDirty:!1}},Tl=u=>{const p=u.quotedText;if(typeof p!="string"||p.length===0)return null;const b=Tu(u);if(b.length===0||!vc(b.map(N=>N.blockId)))return null;const A=u.target,x=b.length===1?Ao(b[0].blockId,A?.story):void 0;return{select:{type:"text",pattern:p,mode:"contains",caseSensitive:!0},...x?{within:x}:{},require:"any"}},$f=u=>{const p=y()?.query;if(typeof p?.match!="function")return null;const b=Tl(u);if(!b)return null;const{value:A}=To(`query:${mo(u)}`,ke(),()=>p.match(b),x=>x&&typeof x=="object"?x:null);return SA(A,u)},Fu=u=>{const p=P(),b=new Set(Vr(u));if(b.size===0)return{};const A=p?.readMountedProjectionBlocksByIds,x=p?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof x!="function")return{};const N=Mt(()=>{if(typeof A!="function")return x.call(p);const Qe=as(u);return Qe?A.call(p,[...b],Qe):A.call(p,[...b])},null);if(!Array.isArray(N))return{};const G=d2(N),oe=Qe=>{const ht={},dt=c2(Qe.fontFamily);dt&&(ht.fontFamily=dt);const ot=zV(Qe.fontSize);return ot&&(ht.fontSize=ot),typeof Qe.color=="string"&&Qe.color.trim()!==""&&(ht.color=Qe.color.trim().toUpperCase()),typeof Qe.highlight=="string"&&Qe.highlight.trim()!==""&&(ht.highlight=Qe.highlight.trim().toUpperCase()),ht},fe=wl(u),Me=fe&&typeof fe.range?.start=="number"?fe.range.start:null;if(fe&&Me!==null&&b.has(fe.blockId)){const Qe=G.find(dt=>yc(dt,fe.blockId)),ht=Qe&&Array.isArray(Qe.runs)?Qe.runs:null;if(ht&&ht.length>0&&ht.every(dt=>dt?.kind==="text"||dt?.kind==="tab")){let dt=0,ot=null;for(const Bt of ht){const zt=vm(Bt);if(Me>=dt&&Me<dt+zt){ot=Bt;break}dt+=zt}if(!ot){for(let Bt=ht.length-1;Bt>=0&&!ot;Bt-=1)ht[Bt]?.kind==="text"&&(ot=ht[Bt]);ot??=ht[ht.length-1]??null}return ot?oe(ot):{}}}const Ve=Tu(u);if(Ve.length>0){const Qe=new Set,ht=new Set;let dt=!1,ot=!0;for(const Bt of Ve){const zt=G.find(Qr=>yc(Qr,Bt.blockId));if(!zt)return{};const $n=Array.isArray(zt.runs)?zt.runs:[];if($n.length===0)continue;if(!$n.every(Qr=>Qr?.kind==="text"||Qr?.kind==="tab")){ot=!1;break}let Gn=0;for(const Qr of $n){const Jr=vm(Qr),kr=Gn,Or=Gn+Jr;if(kr<Bt.end&&Or>Bt.start){dt=!0;const Zo=oe(Qr);Zo.fontFamily&&Qe.add(Zo.fontFamily),Zo.fontSize&&ht.add(Zo.fontSize)}Gn=Or}}if(ot&&dt){const Bt={};return Qe.size===1&&(Bt.fontFamily=[...Qe][0]),ht.size===1&&(Bt.fontSize=[...ht][0]),Bt}}const je=new Set,Ke=new Set;let Ze=!1;for(const Qe of G){if(![...b].some(dt=>yc(Qe,dt)))continue;const ht=Array.isArray(Qe.runs)?Qe.runs:[];for(const dt of ht){if(dt?.kind!=="text")continue;Ze=!0;const ot=oe(dt);ot.fontFamily&&je.add(ot.fontFamily),ot.fontSize&&Ke.add(ot.fontSize)}}if(!Ze)return{};const Ge={};return je.size===1&&(Ge.fontFamily=[...je][0]),Ke.size===1&&(Ge.fontSize=[...Ke][0]),Ge},Nu=u=>{const p=P(),b=new Set(Vr(u));if(b.size===0)return{};const A=p?.readMountedProjectionBlocksByIds,x=p?.readMountedProjectionBlocks;if(typeof A!="function"&&typeof x!="function")return{};const N=Mt(()=>{if(typeof A!="function")return x.call(p);const Ge=as(u);return Ge?A.call(p,[...b],Ge):A.call(p,[...b])},null);if(!Array.isArray(N))return{};const G=d2(N),oe=Ge=>({bold:Ge.bold===!0,italic:Ge.italic===!0,underline:Ge.underline!=null,strikethrough:Ge.strike===!0}),fe=Ge=>{const Qe={};for(const ht of Ff){const dt=Ge[ht];dt.size===1&&(Qe[ht]=[...dt][0])}return Qe},Me=wl(u),Ve=Me&&typeof Me.range?.start=="number"?Me.range.start:null;if(Me&&Ve!==null&&b.has(Me.blockId)){const Ge=G.find(ht=>yc(ht,Me.blockId)),Qe=Ge&&Array.isArray(Ge.runs)?Ge.runs:null;if(Qe&&Qe.length>0&&Qe.every(ht=>ht?.kind==="text"||ht?.kind==="tab")){let ht=0,dt=null;for(const ot of Qe){const Bt=vm(ot);if(Ve>=ht&&Ve<ht+Bt){dt=ot;break}ht+=Bt}if(!dt){for(let ot=Qe.length-1;ot>=0&&!dt;ot-=1)Qe[ot]?.kind==="text"&&(dt=Qe[ot]);dt??=Qe[Qe.length-1]??null}return dt?oe(dt):{}}}const je=Tu(u);if(je.length>0){const Ge={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Qe=!1,ht=!0;for(const dt of je){const ot=G.find($n=>yc($n,dt.blockId));if(!ot)return{};const Bt=Array.isArray(ot.runs)?ot.runs:[];if(Bt.length===0)continue;if(!Bt.every($n=>$n?.kind==="text"||$n?.kind==="tab")){ht=!1;break}let zt=0;for(const $n of Bt){const Gn=vm($n),Qr=zt,Jr=zt+Gn;if(Qr<dt.end&&Jr>dt.start){Qe=!0;const kr=oe($n);for(const Or of Ff)Ge[Or].add(kr[Or])}zt=Jr}}if(ht&&Qe)return fe(Ge)}const Ke={bold:new Set,italic:new Set,underline:new Set,strikethrough:new Set};let Ze=!1;for(const Ge of G){if(![...b].some(ht=>yc(Ge,ht)))continue;const Qe=Array.isArray(Ge.runs)?Ge.runs:[];for(const ht of Qe){if(ht?.kind!=="text")continue;Ze=!0;const dt=oe(ht);for(const ot of Ff)Ke[ot].add(dt[ot])}}return Ze?fe(Ke):{}},Bu=(u,p)=>{if(p.fontFamily!==void 0&&p.fontSize!==void 0&&p.color!==void 0&&p.highlight!==void 0)return{values:p,effectiveUniformityStatus:"ready"};const b=Fu(u),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}:{},...p};if(!u.empty&&(A.fontFamily===void 0||A.fontSize===void 0)){const x=ci(u);return x.values&&(A.fontFamily===void 0&&x.values.fontFamily!==void 0&&(A.fontFamily=x.values.fontFamily),A.fontSize===void 0&&x.values.fontSize!==void 0&&(A.fontSize=x.values.fontSize)),{values:A,effectiveUniformityStatus:x.status}}return{values:A,effectiveUniformityStatus:"ready"}},zu=["fontFamily","fontSize","bold","italic","underline","strikethrough"],Vu=u=>{const p=u.selectionTarget;if(!p)return{value:null,status:"ready"};const b=pr(y(),"format.readEffectiveInlineUniformity");if(!b)return{value:null,status:"ready"};const A=kA(u)??mo(u);return To(`effInline:${A}`,ke(),()=>b({target:p,offsetSpace:"selection",keys:zu}),x=>x&&typeof x=="object"?x:null)},ci=u=>{const{value:p,status:b}=Vu(u);if(!p||p.success!==!0)return{values:null,status:b};const A=p.values,x=N=>{const G=A?.[N];if(!(!G||G.state!=="uniform"||typeof G.value!="string"))return N==="fontFamily"?c2(G.value):G.value};return{values:{fontFamily:x("fontFamily"),fontSize:x("fontSize")},status:b}},xc=u=>{const{value:p,status:b}=Vu(u);if(!p||p.success!==!0)return{values:null,status:b};const A=p.values,x={};for(const N of Ff){const G=A?.[N];G?.state==="uniform"&&(G.value==="true"||G.value==="false")&&(x[N]=G.value==="true")}return{values:x,status:b}},Rl=(u,p)=>{const b=u.activeMark;if(!b||!Ff.includes(b))return null;const A=b,x=Nu(p)[A];if(x!==void 0)return x;const{values:N}=xc(p),G=N?.[A];return G!==void 0?G:null},Gf=async u=>{const p=u.selectionTarget;if(!p)return null;const b=pr(y(),"format.readEffectiveInlineUniformity");if(!b)return null;try{const A=await Promise.resolve(b({target:p,offsetSpace:"selection"}));return A&&typeof A=="object"&&A.success===!0?A:null}catch{return null}},Wf=(u,p,b)=>{const A=b.values;for(const x of["fontFamily","fontSize"]){if(p[x]!==void 0)continue;const N=A?.[x];N?.state==="uniform"&&typeof N.value=="string"?u[x]=x==="fontFamily"?c2(N.value):N.value:delete u[x]}},Ws=u=>Bu(u,_A($f(u),u)),Ml=u=>Ws(u).values,Kf=async u=>{const p=y()?.query,b=Tl(u);if(typeof p?.match!="function"||!b)return Ml(u);try{const A=await Promise.resolve(p.match(b)),x=_A(SA(A&&typeof A=="object"?A:null,u),u),N=Bu(u,x);if(N.effectiveUniformityStatus!=="ready"&&(x.fontFamily===void 0||x.fontSize===void 0)){const G=await Gf(u);G&&Wf(N.values,x,G)}return N.values}catch{return Ml(u)}},Ll=async u=>{const p=y();if(p)return typeof p.getNode=="function"?await Promise.resolve(p.getNode(u)):await Promise.resolve(p.getNodeById?.({nodeId:u.nodeId,nodeType:u.nodeType}))},Ec=u=>{const p=y()?.query;if(typeof p?.match!="function")return"ready";const b=Tl(u);if(!b)return"ready";const{status:A}=To(`query:${mo(u)}`,ke(),()=>p.match(b),x=>x&&typeof x=="object"?x:null);return A},ju=u=>{const p=Ws(u),b=p.values;if(u.empty)return p;const A=Ia(u);return A?u.status==="ready"&&Ec(u)==="ready"&&p.effectiveUniformityStatus==="ready"?(k={key:A,values:b},p):k&&k.key===A?{...p,values:{...k.values,...b}}:p:p},Uu=u=>{const p=y(),b=ju(u),A=b.values;u.status==="ready"&&!u.empty&&Ec(u)==="ready"&&b.effectiveUniformityStatus==="ready"&&(v=A,_=`${pc(u)}:${ke()}`);const x=p?.contentControls,{lockModesById:N}=Gs(x,u),G={};for(const oe of Pr())G[oe]=Gu(oe,p,u,A,N);return G},Ho=u=>u?ut.operationUnavailable:S()?ut.documentApiUnavailable:ut.notReady,Oa=u=>u==="contentLocked"||u==="sdtContentLocked",fs=u=>{for(const p of u.values())if(Oa(p))return ut.contentControlLocked},Hu=(u,p,b,A,x)=>{if(!p)return u.scope==="all"?ut.bulkDecisionsDisabled:Ho(x);if(b)return ut.documentReadonly;if(u.scope!=="all"&&A.activeChangeIds.length===0)return ut.selectionRequired},qf=u=>{const p=P(),b=Mt(typeof p?.getCapabilities=="function"?()=>p.getCapabilities():void 0,null)?.editableSubset?.commands;if(Array.isArray(b))return b.find(A=>A?.command===u||A?.id===u)??null;if(b&&typeof b=="object"){const A=b[u];return A&&typeof A=="object"?A:null}return null},$u=(u,p)=>{if(u.scope!=="all"||typeof p?.[`${u.kind}All`]=="function")return;const b=qf(`trackedChanges.${u.kind}All`);if(!(b&&(b.status==="supported"||b.enabled===!0)))return ut.bulkDecisionsDisabled},Gu=(u,p,b,A,x=new Map)=>{if(le.has(u))return sn({supported:!0,enabled:!0,...Mt(le.get(u).getState?()=>le.get(u).getState(Ui(void 0)):void 0,{})},"custom");const N=vr()==="viewing",G=fA(u);if(G&&typeof ee()?.lists?.apply=="function"){const Ze=Ie(),Ge=typeof Ze?.shippedStatus=="string"?Ze.shippedStatus:null,Qe=Ge!=="not-shipped"&&Ge!=="disabled",ht=Qe&&(typeof Ze?.enabled=="boolean"?Ze.enabled:!0),dt=Qe?pe(Ze):null;return sn(N?{enabled:!1,active:dt===G,supported:Qe,value:Ze?.value,reason:ut.documentReadonly}:{enabled:ht,active:dt===G,supported:Qe,value:Ze?.value},"builtin")}const oe=ym(u);if(oe){const Ze=p?.trackChanges,Ge=typeof Ze?.decide=="function"||typeof Ze?.[oe.kind]=="function",Qe=typeof Ze?.decide=="function"||typeof Ze?.[`${oe.kind}All`]=="function",ht=oe.scope==="all"?Qe:Ge,dt=$u(oe,Ze)??Hu(oe,ht,La(),b,p);return sn({enabled:dt==null,active:!1,supported:ht,reason:dt},"builtin")}if(u==="copy-format")return vr()==="viewing"?sn({supported:!0,enabled:!1,active:!1},"builtin"):S()?sn({supported:!0,enabled:!0,active:h.mode!=="idle"},"builtin"):sn({supported:!0,enabled:!1,active:!1,reason:ut.notReady},"builtin");const fe=Au(u);if(!fe)return sn({enabled:!1,active:!1,supported:!1,reason:ut.commandUnsupported},"unsupported");if(fe.disposition!=="routed")return sn({enabled:!1,active:!1,supported:!1,reason:fe.reason??ut.commandUnsupported},fe.disposition==="unsupported"?"unsupported":"builtin");if(fe.instanceRoute)return rt(fe);if(fe.table)return mt(fe,p,N);if(fe.inline?.kind==="clear"){if(fe.mutates&&N)return sn({enabled:!1,active:!1,supported:!0,reason:ut.documentReadonly},"builtin");const Ze=fs(x);if(Ze)return sn({enabled:!1,active:!1,supported:!0,reason:Ze},"builtin");const Ge=Vr(b).length>0||Ru(b)!=null;return sn({enabled:Ge,active:!1,supported:!0,reason:Ge?void 0:ut.selectionRequired},"builtin")}const Me=fe.docRoute;if(!Me)return sn({enabled:!1,active:!1,supported:!1,reason:ut.commandUnsupported},"unsupported");if(pr(p,Me)==null)return sn({enabled:!1,active:!1,supported:!1,reason:Ho(p)},"builtin");const Ve=ye(u);if(Ve){const Ze=Ve.shippedStatus,Ge=Ze!=="not-shipped"&&Ze!=="disabled",Qe=typeof Ve.enabled=="boolean"?Ve.enabled:!0,ht=u==="undo"||u==="redo",dt=ht&&Ve.historyResolved===!1,ot=ht&&Ge&&Qe===!1&&Ve.reason===null&&!dt,Bt=Ve.reason===void 0?void 0:ot?ut.historyEmpty:dt?ut.notReady:o2(Ve.reason,ut.commandUnsupported);return fe.mutates&&N?sn({enabled:!1,active:!1,supported:Ge,reason:ut.documentReadonly},"builtin"):sn({enabled:Ge&&Qe,active:!1,supported:Ge,reason:Bt},"builtin")}const je=Pl(fe,p,b),Ke=hs(fe,p,b,A);if(fe.list?.mode==="indent"||fe.list?.mode==="outdent")return Pe(fe,p,N,b,je,Ke);if(fe.list?.mode==="toggle-seed")return Xe(fe,p,N,b,je,Ke);if(fe.mutates&&N)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:ut.documentReadonly},"builtin");if(fe.inline&&!Ru(b)){const Ze=fs(x);return sn(Ze?{enabled:!1,active:je,supported:!0,value:Ke,reason:Ze}:Vr(b).length>0&&typeof P()?.setPendingInlineFormat=="function"?{enabled:!0,active:je,supported:!0,value:Ke}:{enabled:!1,active:je,supported:!0,value:Ke,reason:ut.rangeSelectionRequired},"builtin")}if((fe.blockParagraph||fe.list)&&Vr(b).length===0)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:ut.selectionRequired},"builtin");if(fe.link&&!je&&a2(b).length===0&&!wl(b))return sn({enabled:!1,active:je,supported:!0,reason:ut.rangeSelectionRequired},"builtin");if(fe.inline){const Ze=fs(x);if(Ze)return sn({enabled:!1,active:je,supported:!0,value:Ke,reason:Ze},"builtin")}return sn({enabled:!0,active:je,supported:!0,value:Ke},"builtin")};function Fa(u,p){const b=u.address?.anchor,A=b?.start,x=b?.end,N=typeof A?.blockId=="string"?A.blockId:null,G=typeof x?.blockId=="string"?x.blockId:null;if(!N||!G)return!1;const oe=typeof A?.offset=="number"?A.offset:null,fe=typeof x?.offset=="number"?x.offset:null;if(oe==null||fe==null)return!1;const Me=p.target,Ve=Me&&Array.isArray(Me.segments)?Me.segments:[];for(const je of Ve){const Ke=typeof je?.blockId=="string"?je.blockId:null;if(!Ke)continue;const Ze=je.range,Ge=typeof Ze?.start=="number"?Ze.start:null,Qe=typeof Ze?.end=="number"?Ze.end:null;if(!(Ge==null||Qe==null)){if(N!==G){if(Ke===N&&Qe>oe||Ke===G&&Ge<fe)return!0;continue}if(Ke===N){if(Ge===Qe){if(Ge>=oe&&Ge<=fe)return!0;continue}if(Math.max(Ge,oe)<Math.min(Qe,fe))return!0}}}return!1}const Na=(u,p)=>{const b=u?.hyperlinks;if(!b||typeof b.list!="function")return null;const A=Vr(p);if(!vc(A))return null;for(const x of A){const N={kind:"block",nodeType:"paragraph",nodeId:x},{value:G}=To(`hyperlinks:${x}`,ke(),()=>b.list({within:N}),fe=>fe&&typeof fe=="object"?fe:null),oe=(G&&Array.isArray(G.items)?G.items:[]).find(fe=>Fa(fe,p));if(oe)return oe}return null},Pl=(u,p,b)=>{if(u.link)return Na(p,b)!=null;if(u.list?.mode==="toggle-seed"&&u.list.seed)return Wu(p,b)===u.list.seed;const A=R(u);if(A!==null)return A;const x=r.get(u.id),N=Ia(b);if(N&&x?.selectionSignature===N)return x.active;const G=Rl(u,b);return G!==null?G:oj(u,b)},hs=(u,p,b,A)=>{if(u.inline&&l2(u.inline.key)){const x=H(u);if(x!==void 0)return x;const N=A[u.inline.key];if(N!==void 0)return N;const G=Ia(b),oe=G?n.get(u.inline.key):void 0;if(G&&oe?.selectionSignature===G)return oe.value}if(u.id==="linked-style"){const{style:x}=Yr(b,ir().cache);return!x.styleId||x.mixed?void 0:{styleId:x.styleId,styleName:x.styleName}}if(u.id==="text-align")return ue(p,b);if(u.id==="link")return ft(p,b)??void 0},qr=(u,p,b)=>{const A=u?.lists;if(!A)return{value:null,status:"ready"};const x=b.storyType==="body",N=typeof A.getStateInStory=="function"?()=>A.getStateInStory({target:Aa(p),story:b}):x&&typeof A.getState=="function"?()=>A.getState({target:Aa(p)}):null;if(!N)return{value:null,status:"ready"};const{value:G,status:oe}=To(`lists:${wr(b)}:${p}`,ke(),N,fe=>fe&&typeof fe=="object"?fe:null);return{value:G?.success===!0?G:null,status:oe}},Ba=(u,p,b)=>qr(u,p,b).value,Dl=(u,p,b)=>{const A=Ba(u,p,b);return!A||A.isListItem!==!0?null:A.seed==="bullet"||A.seed==="ordered"?A.seed:null},za=(u,p,b)=>{const A=qr(u,p,b),x=A.value;return{value:x&&typeof x.isListItem=="boolean"?x.isListItem:null,status:A.status}},Wu=(u,p)=>{const b=Vr(p);if(b.length===0||!vc(b))return null;const A=ss(p),x=Dl(u,b[0],A);if(x!=="bullet"&&x!=="ordered")return null;for(const N of b.slice(1))if(Dl(u,N,A)!==x)return null;return x},Va=(u,p,b)=>{if(!u)return{value:null,status:"ready",refreshing:!1};const A=wr(b),x=A==="story:body";if(x&&typeof u.getNodeById!="function")return{value:null,status:"ready",refreshing:!1};if(!x&&typeof u.getNode!="function")return{value:null,status:"ready",refreshing:!1};const N=`node:${A}:${p}`,G=ke(),oe=To(N,G,()=>x?u.getNodeById({nodeId:p,nodeType:"paragraph"}):u.getNode(Ao(p,b)),Me=>Me&&typeof Me=="object"?Me:null),fe=Y.get(N);return{...oe,refreshing:oe.status==="stale"&&fe?.inflightToken===G&&fe.failedToken!==G}},Ol=u=>u==="left"||u==="center"||u==="right"||u==="justify"?u:void 0,I=u=>u==="start"||u==="end"||u==="distributed"||u==="numTab"||u==="lowKashida"||u==="mediumKashida"||u==="highKashida"||u==="thaiDistribute",M=(u,p)=>{const b=P(),A=b?.readMountedProjectionBlocksByIds;if(typeof A!="function")return null;const x=as(u),N=Mt(()=>x?A.call(b,[...p],x):A.call(b,[...p]),null);if(!Array.isArray(N))return new Map;const G=d2(N),oe=new Map;for(const fe of p){const Me=G.find(Ze=>yc(Ze,fe));if(!Me)continue;const Ve=Me.attrs,je=Ol(Ve?.alignment),Ke=b9(Ve);oe.set(fe,je??(Ke==="rtl"?"right":"left"))}return oe},X=(u,p,b,A)=>{const{value:x,status:N,refreshing:G}=Va(u,p,b),oe=A?.get(p);if(N==="pending")return oe?{status:"uniform",value:oe}:{status:"pending"};if(N==="stale"&&!G)return{status:"pending"};if(N==="stale"&&oe)return{status:"uniform",value:oe};if(N==="stale"&&A&&!oe)return{status:"unavailable"};if(!x)return{status:"unavailable"};const fe=x.node;if(!fe)return{status:"unavailable"};const Me=fe.kind;if(Me!=="paragraph"&&Me!=="heading")return{status:"unavailable"};const Ve=fe[Me];if(!Ve||typeof Ve!="object")return{status:"unavailable"};const je=Ve.props?.alignment;if(je==null)return oe?{status:"uniform",value:oe}:{status:"unavailable"};const Ke=Ol(je);return Ke?{status:"uniform",value:Ke}:I(je)&&oe?{status:"uniform",value:oe}:{status:"unavailable"}},ae=(u,p)=>{const b=Vr(p);if(b.length===0||!vc(b))return{status:"unavailable"};const A=ss(p),x=M(p,b),N=X(u,b[0],A,x);if(N.status!=="uniform")return N;for(const G of b.slice(1)){const oe=X(u,G,A,x);if(oe.status!=="uniform")return oe;if(oe.value!==N.value)return{status:"mixed"}}return N},se=u=>{const p=Vr(u);return p.length===0?null:`${wr(ss(u))}:${p.join(",")}`},ue=(u,p)=>{const b=ae(u,p),A=b.status==="uniform"?b.value:void 0,x=o;if(!x)return A;const N=se(p);return N&&N!==x.selectionSignature?(o=null,A):!N||!x.settled?x.value:b.status!=="pending"?(o=null,A):x.value},ce=(u,p)=>{const b=Ol(p),A=se(u),x=Vr(u);if(!b||!A||x.length===0)return null;const N=++i;return o={selectionSignature:A,value:b,generation:N,settled:!1,canReconcile:vc(x)},Ot(),N},de=(u,p)=>{if(u==null)return;const b=o;if(!(!b||b.generation!==u)){if(!Io(p)){o=null;return}if(!b.canReconcile){o=null;return}b.settled=!0}},we=async(u,p,b)=>{const A=u?.lists;if(!A)return null;try{const x=b.storyType==="body",N=typeof A.getStateInStory=="function"?await A.getStateInStory({target:Aa(p),story:b}):x&&typeof A.getState=="function"?await A.getState({target:Aa(p)}):null,G=N&&typeof N=="object"?N:null;return!G||G.success!==!0||typeof G.isListItem!="boolean"?null:G.isListItem}catch{return null}},Le=(u,p,b)=>{const A={resolved:!1,seed:null},x=u?.lists;if(!x)return A;const N=b.storyType==="body",G=typeof x.getStateInStory=="function"?()=>x.getStateInStory({target:Aa(p),story:b}):N&&typeof x.getState=="function"?()=>x.getState({target:Aa(p)}):null;if(!G)return A;const oe=fe=>{const Me=fe&&typeof fe=="object"?fe:null;return!Me||Me.success!==!0||typeof Me.isListItem!="boolean"?A:{resolved:!0,seed:Me.isListItem===!0&&(Me.seed==="bullet"||Me.seed==="ordered")?Me.seed:null}};try{const fe=G();return Ir(fe)?Promise.resolve(fe).then(oe,()=>A):oe(fe)}catch{return A}},Fe=async(u,p,b)=>{if(!u)return null;try{const A=!b||b.storyType==="body",x=b&&typeof u.getNode=="function"?await u.getNode(Ao(p,b)):A&&typeof u.getNodeById=="function"?await u.getNodeById({nodeId:p,nodeType:"paragraph"}):null;return RV(x&&typeof x=="object"?x:null)}catch{return null}},Pe=(u,p,b,A,x,N)=>{if(u.mutates&&b)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.documentReadonly},"builtin");const G=Vr(A);if(G.length===0)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.selectionRequired},"builtin");const oe=u.docRoute?pr(p,u.docRoute):null,fe=pr(p,"format.paragraph.setIndentation"),Me=pr(p,"format.paragraph.clearIndentation"),Ve=u.list?.mode,je=Ve==="indent"?fe!=null:fe!=null||Me!=null,Ke=ss(A);let Ze=null;if(Ke.storyType!=="body"){Ze=[];for(const Ge of G){const{value:Qe,status:ht}=za(p,Ge,Ke);if(Qe===null)return ht!=="ready"&&(oe!=null||je)?sn({enabled:!0,active:x,supported:!0,value:N},"builtin"):sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin");Ze.push(Qe)}}if(Ze?.some(Ge=>Ge===!0)){const Ge=Ve==="indent"?"lists.indentRange":"lists.outdentRange",Qe=vr()!=="suggesting"&&Ze.every(dt=>dt===!0)&&pr(p,Ge)!=null,ht=Ve==="outdent"&&pr(p,"lists.outdentInStory")!=null;if(!Qe&&!ht)return sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")}for(const[Ge,Qe]of G.entries()){const ht=Ze?{value:Ze[Ge]??null,status:"ready"}:za(p,Qe,Ke),dt=ht.value;if(dt===!0){if(oe!=null)return sn({enabled:!0,active:x,supported:!0,value:N},"builtin");continue}if(dt===!1&&je){if(Ke.storyType!=="body"&&typeof p?.getNode!="function")continue;return sn({enabled:!0,active:x,supported:!0,value:N},"builtin")}if(dt===null)return ht.status!=="ready"&&(oe!=null||je)?sn({enabled:!0,active:x,supported:!0,value:N},"builtin"):sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")}return sn({enabled:!1,active:x,supported:!1,value:N,reason:Ho(p)},"builtin")},Xe=(u,p,b,A,x,N)=>{if(u.mutates&&b)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.documentReadonly},"builtin");const G=Vr(A);if(G.length===0)return sn({enabled:!1,active:x,supported:!0,value:N,reason:ut.selectionRequired},"builtin");const oe=ss(A),fe=p?.lists;if(!(typeof fe?.getStateInStory=="function"||oe.storyType==="body"&&typeof fe?.getState=="function"))return sn({enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");if(!vc(G))return sn(oe.storyType==="body"&&pr(p,"lists.remove")!=null?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Me=G.map(Ze=>qr(p,Ze,oe));if(Me.some(({status:Ze})=>Ze!=="ready"))return sn({enabled:!0,active:x,supported:!0,value:N},"builtin");if(Me.some(({value:Ze})=>Ze===null))return sn({enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Ve=u.list?.seed,je=Me.every(({value:Ze})=>Ze?.isListItem===!0&&Ze.seed===Ve);if(oe.storyType==="body")return sn(!je||pr(p,"lists.remove")!=null?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin");const Ke=pr(p,"lists.removeInStory");return sn(je&&Ke?{enabled:!0,active:x,supported:!0,value:N}:{enabled:!1,active:x,supported:!1,value:N,reason:ut.operationUnavailable},"builtin")},ft=(u,p)=>{const b=Na(u,p)?.properties?.href;return typeof b=="string"?b:null},rt=u=>{if(!S())return sn({enabled:!1,active:!1,supported:!1,reason:ut.notReady},"builtin");const p=u.instanceRoute;return typeof t?.[p]!="function"?sn({enabled:!1,active:!1,supported:!1,reason:ut.operationUnavailable},"builtin"):sn({enabled:!0,active:pt(u),supported:!0,value:Wt(u)},"builtin")},pt=u=>{const p=t?.config??void 0;return u.valueFrom==="ruler"?!!p?.rulers:u.valueFrom==="formattingMarks"?!!p?.layoutEngineOptions?.showFormattingMarks:!1},mt=(u,p,b)=>{if(b)return sn({enabled:!1,active:!1,supported:!0,reason:ut.documentReadonly},"builtin");const A=Se();return A!=null&&(!u.table.requiresCell||A.cellNodeId!=null)?(u.docRoute?pr(p,u.docRoute):null)==null?sn({enabled:!1,active:!1,supported:!1,reason:Ho(p)},"builtin"):sn({enabled:!0,active:!1,supported:!0},"builtin"):sn({enabled:!1,active:!1,supported:!0,reason:ut.tableContextUnavailable},"builtin")},Wt=u=>{if(u.valueFrom==="zoom")return Ic().value;if(u.valueFrom==="documentMode")return vr();if(u.valueFrom==="measurementUnit")return Ou();if(u.valueFrom==="ruler"||u.valueFrom==="formattingMarks")return pt(u)},_n=(u,p)=>u.id==="zoom"?typeof p=="number"&&Number.isFinite(p)&&p>0:u.id==="document-mode"?p==="editing"||p==="suggesting"||p==="viewing":u.id==="measurement-unit"?p==="in"||p==="cm":!0,Pr=()=>[...new Set([...pN,...le.keys()])],Jt="Normal",Mn={ready:!1,status:"ready",catalogRevision:null,quickGallery:[],activeParagraphStyleId:null,activeParagraphStyleName:null,mixedSelection:!1,sourceStatus:null,diagnostics:[]},gn=u=>{const p=y()?.styles;return!p||typeof p.getCatalog!="function"?{value:null,status:"ready"}:To(`styles:catalog:${JSON.stringify(u??{})}`,ke(),()=>p.getCatalog(u),b=>b&&typeof b=="object"?b:null)},ir=()=>{const u=gn({includePreview:!0});if(!u.value)return{cache:null,status:u.status};const p=gn({view:"quickGallery",includePreview:!0}),b=p.value?p.value.items:u.value.styles.filter(x=>x.visibility.quickGallery),A=new Map;for(const x of u.value.styles)A.set(x.id,x);return{cache:{full:u.value,quickGallery:b,byId:A},status:bl(u.status,p.status)}},io=(u,p,b)=>{const{value:A,status:x}=Va(u,p,b);if(!A)return{ok:!1,styleRef:null,status:x};const N=A.node;if(!N||typeof N!="object")return{ok:!1,styleRef:null,status:x};const G=N.kind,oe=typeof G=="string"?N[G]:void 0,fe=oe&&typeof oe=="object"?oe.styleRef:void 0;return{ok:!0,styleRef:typeof fe=="string"&&fe.length>0?fe:null,status:x}},Yr=(u,p)=>{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 x=Vr(u);if(x.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(!vc(x))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 N=p?.full.defaults.paragraphStyleId??(p?Jt:null),G=new Set;let oe=0,fe=0,Me=0,Ve="ready";const je=ss(u);for(const Ge of x){const Qe=io(A,Ge,je);if(Ve=bl(Ve,Qe.status),!Qe.ok){fe+=1;continue}if(!Qe.styleRef&&!N){Me+=1;continue}const ht=Qe.styleRef??N;if(!ht){Me+=1;continue}oe+=1,G.add(ht)}if(oe===0){const Ge=Me>0&&fe===0;return b.push({severity:"warning",code:Ge?"active-style-default-unavailable":"active-style-read-failed",message:Ge?"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:Ve}}const Ke=fe+Me;if(Ke>0)return b.push({severity:"warning",code:"active-style-partial",message:`Active paragraph style resolved from ${oe} of ${oe+Ke} selected blocks; ${Ke} could not be read, so the active style is unavailable.`}),{style:{styleId:null,styleName:null,mixed:!1,diagnostics:b},status:Ve};if(G.size>1)return{style:{styleId:null,styleName:null,mixed:!0,diagnostics:b},status:Ve};const Ze=[...G][0];return{style:{styleId:Ze,styleName:p?.byId.get(Ze)?.name??null,mixed:!1,diagnostics:b},status:Ve}},Wi=u=>{if(!S())return Mn;const{cache:p,status:b}=ir(),{style:A,status:x}=Yr(u,p);let N;return p?N=A.diagnostics.length===0?p.full.diagnostics:[...p.full.diagnostics,...A.diagnostics]:N=[{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:bl(b,x,u.status),catalogRevision:p?.full.revision??null,quickGallery:p?.quickGallery??[],activeParagraphStyleId:A.styleId,activeParagraphStyleName:A.styleName,mixedSelection:A.mixed,sourceStatus:p?.full.sourceStatus??null,diagnostics:N}},ui=(u="direct")=>{const{sink:p}=fm(),b=p?_a():0,A={},x=(Me,Ve)=>{if(!p)return Ve();const je=_a();try{return Ve()}finally{A[Me]=_a()-je}},N=x("documentMode",vr),G=x("selection",Lu);G.status==="ready"&&ji(G),ie(G);const oe=Ia(G);for(const[Me,Ve]of r)(!oe||Ve.selectionSignature!==oe||Ve.settled&&G.status==="ready")&&r.delete(Me);const fe={ready:S()!=null,documentMode:N,document:x("document",Hf),selection:G,toolbar:{context:N,commands:x("toolbarCommands",()=>Uu(G)),copyFormatActive:h.mode!=="idle"},comments:x("comments",()=>jf(G)),trackChanges:x("trackChanges",()=>_c(G)),contentControls:x("contentControls",()=>Ac(G)),zoom:x("zoom",Ic),fonts:x("fonts",Du),styles:x("styles",()=>Wi(G))};if(p){const Me=_a();n2({stage:"superdoc-ui-compute-state",atMs:Me,reason:u,startedAtMs:b,completedAtMs:Me,durationMs:Me-b,phaseMs:A,asyncReadSettlements:Ut.splice(0)})}return fe},st=u=>{const p=Ia(u);p&&a&&p!==a&&(n.clear(),r.clear()),p&&(a=p)};let cn=null,Cr=null,ps=null,Ki=null,yo=null,Yo=null,qi=!1;const Ks=()=>{if(j||qi)return;qi=!0;const u=()=>{qi&&(qi=!1,!j&&Ot())};typeof queueMicrotask=="function"?queueMicrotask(u):Promise.resolve().then(u)},Fl=()=>{const u=ee();if(u!==ps&&(Ki&&(Ki(),Ki=null),ps=u,!(!u||typeof u.subscribe!="function")))try{const p=u.subscribe(()=>Ks());typeof p=="function"&&(Ki=p)}catch{ps=null}},Nl=()=>{const u=T();if(u!==yo&&(Yo&&(Yo(),Yo=null),yo=u,!(!u||typeof u.subscribe!="function")))try{const p=u.subscribe(()=>Ot());typeof p=="function"&&(Yo=p)}catch{yo=null}};let di=null,$o=null,Yi=null,fi=null,F=null,K=null;const Ae=()=>{const u=S()?.host,p=Mt(u?.getHandles?()=>u.getHandles():void 0,null)?.editing?.selection;return p&&typeof p.subscribe=="function"?p:null},Be=()=>{const u=Ae();if(u!==cn&&(Cr&&(Cr(),Cr=null),cn=u,!!u))try{const p=u.subscribe(b=>{jo+=1,Hs(b),Ot("host-selection")});typeof p=="function"&&(Cr=p)}catch{cn=null}},wt=()=>{const u=S()?.host,p=Mt(u?.getHandles?()=>u.getHandles():void 0,null)?.review;return p&&typeof p.subscribe=="function"?p:null},en=u=>u?typeof u.getActiveReviewTarget=="function"?Mt(()=>u.getActiveReviewTarget(),null):typeof u.getSnapshot=="function"?Mt(()=>u.getSnapshot(),null)?.activeReviewTarget??null:null:null;let dn=0;const An=(u,p)=>{const b=(p&&typeof p=="object"?p:null)?.lastInteractionRejection;if(dn>0&&u==null&&b&&typeof b=="object"&&b.code==="review-target-invalidated"&&b.detail==="not-painted")return!1;const A=u&&typeof u=="object"?u:null;let x=null;if(A?.entityType==="trackedChange"&&typeof A.entityId=="string"&&A.entityId.length>0){const N=A.story&&typeof A.story=="object"?A.story:void 0,G=N&&wr(N)!==wr(null)?N:void 0,oe=typeof A.paintedEntityId=="string"&&A.paintedEntityId.length>0?A.paintedEntityId:null,fe=oe??A.entityId,Me=(()=>{if(G){const Ke=li(),Ze=Ke?gc(Ke,G):null;return Ze?.toPublicId(fe)??Ze?.toPublicId(A.entityId)??A.entityId}const je=zs(Array.isArray(D?.trackChanges.items)?D.trackChanges.items:[]);return je.toPublicId(fe)??je.toPublicId(A.entityId)??A.entityId})(),Ve=oe??(fe!==Me?fe:null);x={id:Me,...G?{story:G}:{},...Ve&&Ve!==Me?{paintedEntityId:Ve}:{}}}return u==null&&x==null&&He!=null&&J(He)||Ye(He,x)?!1:(re(x),!0)},Sn=()=>{const u=wt();if(u===di)return;if($o&&($o(),$o=null),di=u,!u){An(null);return}let p=!0;try{const b=u.subscribe(A=>{const x=A&&typeof A=="object"?A:null,N=x&&Object.prototype.hasOwnProperty.call(x,"activeReviewTarget")?x.activeReviewTarget:en(u);!An(N,A)||p||Ot()});typeof b=="function"&&($o=b),An(en(u))}catch{di=null}finally{p=!1}},Nn=()=>{if(cn||vr()!=="viewing")return null;const u=S()?.mount?.container,p=(u&&typeof u=="object"&&"ownerDocument"in u?u.ownerDocument??null:null)??globalThis.document??null;return p&&typeof p.addEventListener=="function"?p:null},un=()=>{const u=Nn();if(u===F||(K&&(K(),K=null),F=u,!u))return;const p=()=>{jo+=1,Ot()};u.addEventListener("selectionchange",p),u.addEventListener("pointerup",p,!0),u.addEventListener("mouseup",p,!0),K=()=>{u.removeEventListener("selectionchange",p),u.removeEventListener("pointerup",p,!0),u.removeEventListener("mouseup",p,!0)}};Ta(),An(en(wt())),D=ui("initial"),a=Ia(D.selection);const Dr=()=>{const u=S()?.host?.events,p=u&&typeof u.subscribe=="function"?u:null;if(p!==Yi&&(fi&&(fi(),fi=null),Yi=p,!!p))try{const b=p.subscribe(A=>{const x=A?.type;if(x==="review-mutation:started"){kn(A.reviewMutation?.token);return}if(x==="review-mutation:aborted"){Vo(A.reviewMutation?.token),Ct();return}if(x==="mutation:rejected"&&A.reviewMutation&&(Vo(A.reviewMutation.token),Ct()),x==="mutation:committed"&&A.reviewMutation&&Vo(A.reviewMutation.token),x==="source:complete"||x==="source:signals-complete"){Hr=ke(),xa();return}if((x==="mutation:committed"||x==="collaboration:remote-changed")&&(ct=Date.now()),x==="mutation:committed"||x==="save:completed"||x==="collaboration:remote-changed"){const N=x==="mutation:committed"?jk(A):null;if(N?.allResolved){dr([]),Pt(A.receipt);return}N?.removedIds.size&&an(new Set(N.removedIds),A.receipt);const G=x==="mutation:committed"&&bc(A)||x==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0;if(G&&(Rn=Date.now()),x==="mutation:committed"&&G){Mu();return}if(N?.removedIds.size&&N.upsertIds.size===0)return;(x==="collaboration:remote-changed"||x==="mutation:committed"&&!G)&&Sl();const oe=x==="collaboration:remote-changed"&&Array.isArray(A.changedPartUris)&&A.changedPartUris.some(Me=>typeof Me=="string"&&vV.has(Me)),fe=x==="collaboration:remote-changed"&&Array.isArray(A.changedStoryIds)&&A.changedStoryIds.length>0&&kl();oe&&!G&&(xn=!0),Us(),oe&&!G?_i("comments"):fe&&(xn=!0,Rr()),Ot()}});typeof b=="function"&&(fi=b)}catch{Yi=null}},Ot=(u="unspecified")=>{if(j)return;const{sink:p}=fm(),b=p?_a():0;qi=!1,Ta(),Be(),Fl(),Nl(),Sn(),un(),Dr();const A=ui(u);st(A.selection),D=A;let x=0,N=0;for(const G of[...V]){if(!p){G(D);continue}const oe=_a();G(D);const fe=_a()-oe;x+=fe,N=Math.max(N,fe)}if(p){const G=_a();n2({stage:"superdoc-ui-recompute",atMs:G,reason:u,startedAtMs:b,completedAtMs:G,durationMs:G-b,listenerCount:V.size,listenerTotalMs:x,listenerMaxMs:N})}},xi=[],Et=[],vn=u=>{for(const p of u)try{p()}catch{}},sr=()=>vn(xi),Bn=()=>vn(Et),Xr=[];((u,p)=>{if(!(!u||typeof u.on!="function"))for(const b of p){const A=b==="active-editor-change"?()=>{sr(),Bn(),Ot()}:b==="document-replaced"?x=>{const N=x&&typeof x=="object"?x:null,G=N?.editor,oe=N?.host,fe=!!G&&G===S(),Me=!!oe&&oe===P();!fe&&!Me||(Bn(),Y.clear(),Us(),Ot())}:()=>Ot();try{u.on(b,A),Xr.push(()=>{try{typeof u.off=="function"&&u.off(b,A)}catch{}})}catch{}}})(t,dV),Be(),Fl(),Nl(),Sn(),un(),Dr();const Go=(u,p=qz)=>({get:()=>u(D),subscribe:b=>{let A=u(D);const x=N=>{const G=u(N);p(A,G)||(A=G,b(G))};return V.add(x),()=>V.delete(x)}}),bo=u=>Go(u),Xo=u=>{const p=b=>{const A=N=>{try{b(N)}catch{}},x=u.subscribe(A);return A(u.get()),x};return{get:()=>u.get(),getSnapshot:()=>u.get(),observe:p,subscribe:b=>p(A=>b({snapshot:A}))}},ja=(u,p,b)=>{const A=Xo(u),x=Xo(p),N=G=>{const oe=Er(b);Ot();const fe=x.observe(G);return()=>{fe(),oe()}};return{get:A.get,getSnapshot:A.getSnapshot,observe:N,subscribe:G=>N(oe=>G({snapshot:oe}))}};function Ku(u){return u&&typeof u=="object"&&typeof u.id=="string"?String(u.id):null}function Ua(u){const p=as(u);return p&&wr(p)!==wr(null)?p:void 0}function Hn(u,p){return{kind:"id",id:u,...p?{story:p}:{}}}function m2(u){if(u.empty)return null;const p=u.selectionTarget,b=p?.start,A=p?.end;if(p?.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 x=Math.min(b.offset,A.offset),N=Math.max(b.offset,A.offset),G=as(u);return{kind:"range",coordinateSpace:p.coordinateSpace==="tracked"?"tracked":"visible",range:{kind:"text",...G?{story:G}:{},segments:[{blockId:b.blockId,range:{start:x,end:N}}]}}}function Cm(u,p){if(wr(p)!==wr(null))return;const b=y()?.trackChanges,A=b?.list;if(typeof A!="function")return;const x=Mt(()=>A.call(b),null);if(Ir(x)||!x||typeof x!="object")return;const N=x.items;if(Array.isArray(N))return N.map(Nf).find(G=>G!=null&&Ni(G,u,p))}function km(u,p){const b=Sm(u.quotedText);if(!b)return!1;const A=mm(p);return[A.insertedText,A.deletedText,A.excerpt].some(x=>Sm(x)===b)}function Sm(u){return typeof u=="string"?u.replace(/\s+/g," ").trim():""}function _m(){const u=D.selection.activeChangeIds[0];if(!u)return"unavailable";const p=as(D.selection),b=(D.trackChanges.status==="ready"?D.trackChanges.items.find(G=>Ni(G,u,p)):void 0)??Cm(u,p)??li()?.find(G=>Ni(G,u,p));if(!b)return"unavailable";const A=mm(b),x=A.type,N=A.grouping;return km(D.selection,b)?"id":x==="replacement"&&N==="replacement-pair"||(x==="insertion"||x==="deletion"||x==="insert"||x==="delete")&&N==="standalone"?"range":"id"}function Am(u,p,b,A){const x=()=>k2(u,Hn(b,A),b,A);try{const N=k2(u,p,null);if(Ir(N))return Mo(Promise.resolve(N).then(oe=>Io(js(oe))?oe:x()));const G=js(N);return Mo(Io(G)?N:x())}catch{return!1}}function Im(u,p){if(u.scope==="all")return{target:{kind:"all"},changeId:null};if(typeof p=="string"&&p.length>0)return{target:{kind:"id",id:p},changeId:p};if(p&&typeof p=="object"){const x=p;if(x.target&&typeof x.target=="object"){const G=x.target;return{target:G,changeId:Ku(G),story:G.story}}const N=typeof x.changeId=="string"?x.changeId:x.id;if(typeof N=="string"&&N.length>0)return{target:Hn(N,x.story),changeId:N,story:x.story}}const b=D.selection.activeChangeIds[0],A=Ua(D.selection);return b?{target:Hn(b,A),changeId:b,story:A}:null}function g2(u,p){if(u.scope==="id"&&p==null){if(D.selection.activeChangeIds.length>1)return Zf(u.kind,{kind:"ids",ids:D.selection.activeChangeIds},null);if(D.selection.activeChangeIds.length===1&&!D.selection.empty&&D.selection.selectionTarget){const A=_m();if(A==="unavailable")return!1;if(A==="range"){const x=m2(D.selection),N=Ua(D.selection);return x?Am(u.kind,x,D.selection.activeChangeIds[0],N):!1}if(A==="id"){const x=D.selection.activeChangeIds[0],N=as(D.selection),G=N&&wr(N)!==wr(null)?N:void 0;return C2(u.kind,G?{id:x,story:G}:x)}}}const b=Im(u,p);return b?Zf(u.kind,b.target,b.changeId,b.story):!1}function xm(u,p){const b=ee()?.lists,A=b?.apply;if(typeof A!="function")return!1;const{behavior:x,preset:N,continuity:G}=typeof p=="string"?pV(p):p&&typeof p=="object"?p:{},oe={kind:u,behavior:x??"toggle"};N!==void 0&&(oe.preset=N),G!==void 0&&(oe.continuity=G);try{return Mo(A.call(b,oe))}catch{return!1}}let hi=Promise.resolve(!1),Ro=null,qu=Promise.resolve(!1);const It=async u=>{if(!gm(u))return u;const p=S()?.documentMutationReadiness,b=p?.whenPainted;if(typeof b!="function")return u;const A=typeof u.txId=="string"?u.txId:void 0;try{await b.call(p,A?{txId:A}:void 0)}catch{}return u},Tt=u=>{if(Ir(u)){const b=Promise.resolve(u);return{immediate:!0,committed:b.then(A=>js(A),()=>!1),settled:b.then(A=>It(js(A)),()=>!1)}}const p=js(u);return{immediate:p,committed:Promise.resolve(p),settled:It(p)}},yn=()=>{const u=s.shift();if(!u){c=!1,f?.(),f=null;return}try{u.resolve(j?!1:u.mutate())}catch{u.resolve(!1)}},yr=()=>{let u=!1;return()=>{u||(u=!0,yn())}},Zr=(u,p)=>{if(!c){c=!0,d=new Promise(N=>{f=N});try{return{result:p(),release:yr()}}catch(N){throw c=!1,f?.(),f=null,N}}const b=s.find(N=>N.key===u);if(b)return b.mutate=p,{result:b.result,release:()=>{}};let A;const x=new Promise(N=>{A=N});return s.push({key:u,mutate:p,result:x,resolve:A}),{result:x,release:yr()}},wo=new Set(["create.tableOfContents"]),Ei=u=>Kn(`Tracked authoring is not supported for ${u}.`),Ti=u=>{if(vr()==="suggesting")return wo.has(u)?Ei(u):{changeMode:"tracked"}},Yu=()=>vr()==="suggesting"?KV:h2,Co=(u,p,b)=>{const A=Ti(u);return A&&A.success===!1?A:A?p(b,A):p(b)},Tj=(u,p,b,A)=>{const x=u.inline;if(!x)return;const N=js(A);if(N===!1||typeof N=="object"&&N&&N.success===!1)return;if(x.kind==="clear"){n.clear();return}if(x.kind==="toggle"||!l2(x.key))return;const G=Ia(p);if(!G)return;const oe=DV(x.key,b.value);if(oe==null){n.delete(x.key);return}n.set(x.key,{selectionSignature:G,value:oe})},Rj=(u,p,b,A)=>!u.inline||u.inline.kind==="toggle"?A:Ir(A)?Promise.resolve(A).then(x=>(Tj(u,p,b,x),x)):A,Mj=(u,p,b,A)=>{if(u.inline?.kind!=="toggle"||!Io(js(A))||typeof b.value!="boolean"&&b.value!==null)return null;const x=Ia(p);if(!x)return null;const N=++l;return r.set(u.id,{selectionSignature:x,active:b.value===!0,generation:N,settled:!1}),Ot(),N},Lj=(u,p,b)=>{if(p==null)return;const A=r.get(u.id);if(!(!A||A.generation!==p)){if(!Io(b)){r.delete(u.id);return}A.settled=!0}},Em=(u,p)=>u.then(b=>(p?.(b),Al(),b),()=>(p?.(!1),Al(),!1)),Mo=(u,p)=>{const b=Ro;if(Ro=null,b)return hi=Em(b,p),js(u);if(Ir(u))return hi=Em(Tt(u).settled,p),!0;const A=js(u);return gm(A)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(hi=Em(It(A),p),A):(p?.(A),hi=Promise.resolve(A),Al(),A)},Pj=(u,p)=>!u||typeof u!="object"?p:u,Bl=(u,p=Kn("Document API operation failed."))=>{if(Ir(u))return Promise.resolve(u).then(A=>Bl(A,p),()=>p);const b=Pj(u,p);return Us(),gm(b)&&typeof S()?.documentMutationReadiness?.whenPainted=="function"?(Em(It(b)),Ot(),b):(Ot(),b)},Dj=(u,p,b,A)=>{const x=[],N=[];for(const G of b){const oe=A(G);if(oe)try{const fe=Tt(Co(u,p,oe));x.push(fe.immediate),N.push(fe.settled)}catch{x.push(!1),N.push(Promise.resolve(!1))}}return Ro=N.length?Promise.all(N).then(G=>ki(G)):null,ki(x)},Oj=(u,p,b,A)=>{const x=[],N=[];for(const G of b){const oe=A(G);if(oe)try{const fe=Tt(Co(u,p,oe));x.push(fe.immediate),N.push(fe.settled)}catch{x.push(!1),N.push(Promise.resolve(!1))}}return Ro=N.length?Promise.all(N).then(G=>ki(G)):null,ki(x)},v2=(u,p,b,A=D.selection)=>{const x=Ti(u);return x&&x.success===!1?x:A.selectionTarget?p(b,{...x,offsetSpace:"selection"}):x?p(b,x):p(b)},Fj=(u,p,b,A)=>{const x=Ao(p,A);switch(u.kind){case"alignment":{const N=b;return N!=="left"&&N!=="center"&&N!=="right"&&N!=="justify"?null:{target:x,alignment:N}}case"spacing-line":{const N=typeof b=="number"?b:Number(b);return!Number.isFinite(N)||N<=0?null:{target:x,line:N,lineRule:"auto"}}case"style":if(b&&typeof b=="object"){const N=b.role;if(N&&typeof N=="object")return{target:x,role:N}}return typeof b!="string"||b.trim()===""?null:{target:x,styleId:b};case"direction":{const N=u.fixedValue;return N!=="ltr"&&N!=="rtl"?null:{target:x,direction:N}}default:return null}},Nj=(u,p)=>{const b=u.inline,A=f2(u),x=P();if(!b||typeof x?.setPendingInlineFormat!="function")return!1;if(b.kind==="clear")return $(),!0;if(!A)return!1;let N;if(b.kind==="toggle")N=!Pl(u,y(),D.selection);else{const G=p&&typeof p=="object"&&"value"in p?p.value:p;if(b.kind==="value-number"){const oe=typeof G=="number"?G:Number(G);N=Number.isFinite(oe)&&oe>0?oe:null}else N=typeof G=="string"&&G.trim()!==""?G:null;if(N===null)return E(A,null),!0}return E(A,N),!0},Bj=()=>{const u=y(),{lockModesById:p}=Gs(u?.contentControls,D.selection);if(fs(p))return!1;const b=[],A=[],x=Ze=>{const Ge=Tt(Ze);b.push(Ge.immediate),A.push(Ge.settled)},N=(Ze,Ge,Qe)=>{try{x(Qe?Ze(Ge,Qe):Ze(Ge))}catch{b.push(!1),A.push(Promise.resolve(!1))}},G=ir().cache?.full.defaults.paragraphStyleId??Jt,oe=Ru(D.selection);if(oe){const Ze=pr(u,"format.apply");if(Ze)try{x(v2("format.apply",Ze,{target:oe,inline:{...Yu()}}))}catch{b.push(!1),A.push(Promise.resolve(!1))}}const fe=pr(u,"format.paragraph.resetDirectFormatting"),Me=pr(u,"styles.paragraph.setStyleRef"),Ve=as(D.selection),je=!Ve||Ve.storyType==="body",Ke=pr(u,je?"lists.remove":"lists.removeInStory");for(const Ze of Vr(D.selection)){const Ge=Ao(Ze,Ve);if(fe&&N(fe,{target:Ge}),Ke)try{const Qe=Aa(Ze),ht=Tt(Ke(je?{target:Qe}:{target:Qe,story:Ve}));A.push(ht.settled.then(dt=>Io(dt)?dt:!0))}catch{}Me&&N(Me,{target:Ge,styleId:G})}if(!oe&&vr()!=="suggesting"){const Ze=pr(u,"format.paragraph.setMarkRunProps");if(Ze)for(const Ge of Vr(D.selection))N(Ze,{target:Ao(Ge,Ve),markRunProps:{bold:!1,italic:!1,strikethrough:!1,doubleStrikethrough:!1,smallCaps:!1,caps:!1,verticalAlign:"baseline"}})}return Ro=A.length?Promise.all(A).then(Ze=>ki(Ze)):null,ki(b.length?b:[!1])},zj=(u,p,b)=>{const A=Vr(D.selection);if(A.length===0)return!1;const x=as(D.selection);return Dj(u.docRoute,p,A,N=>Fj(u.blockParagraph,N,b,x))},Vj=(u,p,b)=>{const A=y(),x=pr(A,"format.paragraph.setIndentation"),N=pr(A,"format.paragraph.clearIndentation"),G=u.list?.mode,oe=ss(D.selection),fe=as(D.selection),Me=async Ve=>{const je=await we(A,Ve,oe);if(je===!0)return{kind:"list",routeToCall:u.docRoute,opToCall:p,input:{target:bA(Ve)}};if(je===null||fe&&fe.storyType!=="body"&&typeof A?.getNode!="function")return null;const Ke=await Fe(A,Ve,fe),Ze={};if(Ke?.right!=null&&(Ze.right=Ke.right),Ke?.firstLine!=null&&(Ze.firstLine=Ke.firstLine),Ke?.hanging!=null&&(Ze.hanging=Ke.hanging),G==="indent")return x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),left:Math.max(0,Ke?.left??0)+wA,...Ze}}:null;const Ge=Math.max(0,(Ke?.left??0)-wA);return Ge>0&&(Ze.left=Ge),Object.keys(Ze).length===0?N?{kind:"paragraph",routeToCall:"format.paragraph.clearIndentation",opToCall:N,input:{target:Ao(Ve,fe)}}:x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),left:0}}:null:x?{kind:"paragraph",routeToCall:"format.paragraph.setIndentation",opToCall:x,input:{target:Ao(Ve,fe),...Ze}}:null};return Ro=(async()=>{const Ve=await Promise.all(b.map(Ge=>Me(Ge).catch(()=>null)));if(Ve.length===b.length&&Ve.every(Ge=>Ge?.kind==="list")&&vr()!=="suggesting"){const Ge=G==="indent"?"lists.indentRange":"lists.outdentRange",Qe=pr(A,Ge);if(Qe)try{return await Tt(Co(Ge,Qe,{paraIds:b,story:oe})).settled}catch{return!1}}const je=oe.storyType!=="body"&&Ve.some(Ge=>Ge?.kind==="list"),Ke=je&&G==="outdent"?pr(A,"lists.outdentInStory"):null;if(je&&!Ke)return!1;const Ze=Ve.map(Ge=>{if(!Ge)return Promise.resolve(!1);try{return Ge.kind==="list"&&Ke?Tt(Co("lists.outdentInStory",Ke,{target:Ge.input.target,story:oe})).settled:Tt(Co(Ge.routeToCall,Ge.opToCall,Ge.input)).settled}catch{return Promise.resolve(!1)}});return ki(await Promise.all(Ze))})(),!0},jj=(u,p)=>{const b=u.list,A=y(),x=Vr(D.selection);if(x.length===0)return!1;const N=ss(D.selection),G=N.storyType==="body";if(b.mode==="indent"||b.mode==="outdent")return Vj(u,p,x);const oe=b.seed,fe=je=>{if(je.some(dt=>!dt.resolved))return{immediate:!1,settled:null};const Ke=je.every(dt=>dt.seed===oe);if(!Ke&&!G)return{immediate:!1,settled:null};const Ze=Ke?G?"lists.remove":"lists.removeInStory":u.docRoute,Ge=Ke?pr(A,Ze):p;if(!Ge)return{immediate:!1,settled:null};const Qe=[],ht=[];return x.forEach((dt,ot)=>{if(!Ke&&je[ot]?.seed===oe)return;const Bt=Ke?{target:Aa(dt),...G?{}:{story:N}}:{target:Aa(dt),seed:oe};try{const zt=Tt(Co(Ze,Ge,Bt));Qe.push(zt.immediate),ht.push(zt.settled)}catch{Qe.push(!1),ht.push(Promise.resolve(!1))}}),{immediate:ki(Qe),settled:ht.length?Promise.all(ht).then(dt=>ki(dt)):null}},Me=x.map(je=>Le(A,je,N));if(Me.some(Ir))return Ro=Promise.all(Me).then(async je=>{const Ke=fe(je);return Ke.settled?await Ke.settled:Ke.immediate}),!0;const Ve=fe(Me);return Ro=Ve.settled,Ve.immediate};function Yf(u){return u&&typeof u=="object"?u:{}}function Uj(u){if(typeof u=="string")return u;const p=Yf(u);if(Object.prototype.hasOwnProperty.call(p,"href"))return p.href;if(Object.prototype.hasOwnProperty.call(p,"value"))return p.value}function Hj(u,p){const b=Yf(u).text;return typeof b=="string"&&b.trim()!==""?b:p}function LA(u){const p=Yf(u),b=p.capture&&typeof p.capture=="object"?p.capture:null;return p.target??b?.target??b?.selectionTarget??p.selectionTarget??p.textTarget??null}const $j=u=>{const p=y(),b=p?.hyperlinks;if(!b)return!1;const A=Yf(u),x=Uj(u),N=LA(u),G=typeof A.text=="string"?A.text:void 0,oe=typeof A.currentText=="string"?A.currentText:void 0,fe=Bf(A.hyperlinkTarget)?A.hyperlinkTarget:null,Me=Bf(A.textTarget)?A.textTarget:null,Ve=Na(p,D.selection),je=typeof fe?.storyId=="string"&&typeof fe?.hyperlinkNodeId=="string";if(je&&x===null){const Ke=b.remove;if(typeof Ke!="function")return!1;try{return Co("hyperlinks.remove",Ke,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,keepText:!0})}catch{return!1}}if(Ve&&x===null){const Ke=b.remove;if(typeof Ke!="function")return!1;try{return Co("hyperlinks.remove",Ke,{target:Ve.address,mode:"unwrap"})}catch{return!1}}if((Ve||fe)&&typeof x=="string"&&x.trim()!==""){const Ke=b.patch,Ze=b.updateTarget;if(!(!je&&Ve&&typeof Ke=="function")&&!(je&&typeof Ze=="function"))return!1;const Ge=typeof G=="string"&&G!==(je?oe:Ve?.text??oe),Qe=p?.text?.replace,ht=Ge?je?Me:jV(Ve?.address):null,dt=Ge&&!!ht&&typeof Qe=="function";if(Ge&&!dt)return!1;const ot=[],Bt=[];let zt=null,$n=null,Gn=null,Qr=!1;try{if(je){if(typeof Ze!="function")return!1;const Jr=Co("hyperlinks.updateTarget",Ze,{storyId:fe.storyId,hyperlinkNodeId:fe.hyperlinkNodeId,newTarget:UV(x)});Qr=Ir(Jr);const kr=Tt(Jr);if(!Io(kr.immediate))return!1;ot.push(kr.immediate),Bt.push(kr.settled),zt=kr.immediate,$n=kr.committed,Gn=kr.settled}else if(Ve){if(typeof Ke!="function")return!1;const Jr=Co("hyperlinks.patch",Ke,{target:Ve.address,patch:{href:x}});Qr=Ir(Jr);const kr=Tt(Jr);if(!Io(kr.immediate))return!1;ot.push(kr.immediate),Bt.push(kr.settled),zt=kr.immediate,$n=kr.committed,Gn=kr.settled}}catch{return!1}if(dt){const Jr=(Or,Zo)=>Io(Zo)?ki([Or,Zo]):Io(Or)?Lf(Or,Zo):Zo,kr=Or=>{if(!Io(Or))return Or;try{const Zo=Tt(Co("text.replace",Qe,{target:ht,text:G}));return Io(Zo.immediate)?Promise.all([Gn??Promise.resolve(Or),Zo.settled]).then(([x2,EU])=>Jr(x2,EU)):Lf(Or,Zo.immediate)}catch{return Lf(Or,!1)}};if(Qr)return Ro=($n??Promise.resolve(zt??!1)).then(kr),ki(ot);try{const Or=Tt(Co("text.replace",Qe,{target:ht,text:G}));if(!Io(Or.immediate))return zt?Lf(zt,Or.immediate):Or.immediate;ot.push(Or.immediate),Bt.push(Or.settled),Ro=Promise.all([Gn??Promise.resolve(zt??!1),Or.settled]).then(([Zo,x2])=>Jr(Zo,x2))}catch{return zt?Lf(zt,!1):!1}}return!dt&&Bt.length>0&&(Ro=Promise.all(Bt).then(Jr=>ki(Jr))),ki(ot)}if(typeof x=="string"&&x.trim()!==""){const Ke=x.trim(),Ze=b.wrap,Ge=MV(N),Qe=Ge.length>0?Ge:a2(D.selection);if(Qe.length>0){if(typeof Ze!="function")return!1;try{return Oj("hyperlinks.wrap",Ze,Qe,Bt=>({target:Bt,link:{destination:{href:Ke}}}))}catch{return!1}}const ht=b.insert,dt=Hj(u,Ke);if(typeof ht!="function"||dt.trim()==="")return!1;const ot=Of(N)??wl(D.selection);if(!ot)return!1;try{return Co("hyperlinks.insert",ht,{target:ot,text:dt,link:{destination:{href:Ke}}})}catch{return!1}}return!1},Gj=(u,p,b)=>{const A=u.create.kind,x=b&&typeof b=="object"?b:{};if(A==="table"){const G=Number(x.rows??x.rowCount),oe=Number(x.columns??x.cols??x.colCount);if(!Number.isInteger(G)||G<1||!Number.isInteger(oe)||oe<1)return!1;const fe=wl(D.selection),Me=fe&&typeof fe.blockId=="string"?{kind:"inParagraph",target:Ao(fe.blockId),offset:fe.range?.start??0}:u2(D.selection,"nodeId");try{return Co(u.docRoute,p,{rows:G,columns:oe,at:Me})}catch{return!1}}if(A==="image"){const G=x.src??x.value;if(typeof G!="string"||G.trim()==="")return!1;const oe=wl(D.selection),fe=ss(D.selection),Me=fe.storyType==="body"?null:fe;let Ve;oe&&typeof oe.blockId=="string"?Ve={kind:"inParagraph",target:Ao(oe.blockId,Me),offset:oe.range?.start??0}:(Ve=u2(D.selection,"target"),Me&&Ve.kind==="after"&&(Ve={...Ve,target:{...Ve.target,story:Me}}));const je={src:G,at:Ve};Me&&(je.in=Ve.kind==="inParagraph"?B(Me)??Me:Me),typeof x.alt=="string"&&(je.alt=x.alt),typeof x.title=="string"&&(je.title=x.title),x.size&&typeof x.size=="object"&&(je.size=x.size);try{return Co(u.docRoute,p,je)}catch{return!1}}const N={at:u2(D.selection,"target")};typeof x.instruction=="string"&&(N.instruction=x.instruction),x.config&&typeof x.config=="object"&&(N.config=x.config);try{return Co(u.docRoute,p,N)}catch{return!1}},Wj=(u,p)=>{const b=u.table,A=Se();if(!A||b.requiresCell&&!A.cellNodeId)return!1;const x=XV(b.action,A);if(!x)return!1;try{if(b.action==="insert-row-before"||b.action==="insert-row-after"){const N=P(),G=(typeof N?.getHandles=="function"?N.getHandles():null)?.editing?.tables;if(typeof G?.insertRow!="function")return!1;const oe=Ti(u.docRoute);return oe&&oe.success===!1?oe:oe?G.insertRow(x,oe):G.insertRow(x)}if(b.action==="insert-column-before"||b.action==="insert-column-after"){const N=P(),G=(typeof N?.getHandles=="function"?N.getHandles():null)?.editing?.tables;if(typeof G?.insertColumn!="function")return!1;const oe=Ti(u.docRoute);return oe&&oe.success===!1?oe:oe?G.insertColumn(x,A.rowIndex,oe):G.insertColumn(x,A.rowIndex)}return Co(u.docRoute,p,x)}catch{return!1}},Kj=u=>!u||u.disposition!=="routed"?!1:!!(u.inline||u.blockParagraph||u.list||u.link||u.create),qj=u=>{const p=Yf(u);return!!(LA(u)||Bf(p.hyperlinkTarget)||Bf(p.textTarget))},Yj=(u,p,b)=>D.selection.status!=="ready"?!1:ym(u)?.scope==="id"||!p||p.disposition!=="routed"?!0:p.inline?.kind==="clear"?Vr(D.selection).length>0||Ru(D.selection)!=null:p.inline?Ru(D.selection)!=null||Vr(D.selection).length>0:p.blockParagraph||p.list?Vr(D.selection).length>0:p.link?qj(b)||a2(D.selection).length>0||wl(D.selection)!=null||Pl(p,y(),D.selection):!0,Xj=(u,p)=>{const b=ym(u),A=Au(u);return b?.scope!=="id"&&!Kj(A)?!1:!Yj(u,A,p)},Zj=(u,p)=>Xj(u,p)?wc().then(()=>{}):null,Tc=(u,p,b)=>{if(Ro=null,hi=Promise.resolve(!1),j)return!1;const A=le.get(u);if(A)try{const je=A.execute(Ui(p,b));return Mo(je)}catch{return!1}const x=fA(u);if(x){if(vr()==="viewing")return!1;if(typeof ee()?.lists?.apply=="function")return xm(x,p)}const N=ym(u);if(N)return g2(N,p);if(u==="copy-format")return Mo(Qj());const G=Au(u);if(!G||G.disposition!=="routed")return!1;const oe=G.normalizePayload?G.normalizePayload(p):p;if(G.instanceRoute){if(!S()||!_n(G,oe))return!1;const je=t?.[G.instanceRoute];if(typeof je!="function")return!1;try{const Ke=G.fixedArg!==void 0?G.fixedArg:oe,Ze=je.call(t,Ke);return Mo(Ze)}catch{return!1}}if(G.inline?.kind==="clear")return G.mutates&&vr()==="viewing"?!1:Mo(Bj());const fe=G.docRoute;if(!fe||G.mutates&&vr()==="viewing")return!1;const Me=y(),Ve=pr(Me,fe);if(!Ve)return!1;if(G.inline){const{lockModesById:je}=Gs(Me?.contentControls,D.selection);if(fs(je))return!1;const Ke=Ru(D.selection);if(!Ke)return D.selection.empty===!1?Mo(!1):Mo(Nj(G,oe));const Ze=Pl(G,Me,D.selection),Ge=qV(G.inline,Ke,oe,Ze);if(!Ge)return!1;let Qe=null;try{const ht=S(),dt=vr(),ot=()=>S()!==ht||y()!==Me||vr()!==dt?!1:v2(fe,Ve,Ge),Bt=Ia(D.selection)??pc(D.selection),zt=G.inline.kind==="toggle"?Zr(`${G.id}:${Bt}`,ot):null;Qe=zt?.release??null;const $n=zt?zt.result:ot(),Gn=Mj(G,D.selection,Ge,$n),Qr=Rj(G,D.selection,Ge,$n),Jr=Mo(Qr,kr=>{Lj(G,Gn,kr),Qe?.(),Qe=null});return G.inline.kind==="toggle"&&(qu=hi),Jr}catch{return Qe?.(),!1}}if(G.blockParagraph){const je=zj(G,Ve,oe),Ke=G.blockParagraph.kind==="alignment"&&Io(je)?ce(D.selection,oe):null;return Mo(je,Ze=>{de(Ke,Ze)})}if(G.list){const je=jj(G,Ve);return Mo(je)}if(G.link){const je=$j(oe);return Mo(je)}if(G.create){const je=Gj(G,Ve,oe);return Mo(je)}if(G.table){const je=Wj(G,Ve);return Mo(je)}try{return Mo(G.mutates?Co(fe,Ve,oe):Ve(oe))}catch{return!1}},Tm=()=>{g+=1,h={mode:"idle",snapshot:null,sourceSelectionKey:null,lastClickAt:h.lastClickAt,pointerSelecting:!1,keyboardSelecting:!1};for(const u of m)u("idle");Ot()},Qj=async()=>{const u=["bold","italic","underline","strikethrough"].filter(Ve=>D.toolbar.commands[Ve]?.active===!0),p=await qu;await d;const b=Io(p)?u:[],A=500,x=Date.now();if(h.mode!=="idle"){if(h.mode==="armed"&&x-h.lastClickAt<A){h={...h,mode:"persistent",lastClickAt:x};for(const Ve of m)Ve("persistent");return Ot(),!0}return Tm(),!1}const N=x-h.lastClickAt<A,G=++g;h={...h,lastClickAt:x};const oe=await wc(),fe=`${pc(oe)}:${ke()}`,Me=await Jj(null,oe,fe&&fe===_?v:void 0,b);if(G!==g)return!0;h={...h,mode:N?"persistent":"armed",snapshot:Me,sourceSelectionKey:pc(oe),lastClickAt:x};for(const Ve of m)Ve(h.mode);return Ot(),!0},Jj=async(u,p,b,A=[])=>{const x=p?.target??u?.target;if(!x||x.kind!=="text")return null;const N=Array.isArray(x.segments)?x.segments:[];if(N.length===0)return null;const G=y();if(!G)return null;const oe=x.story;let fe=null;for(const Ge of N){const Qe=(await Ll(Ao(Ge.blockId,oe)))?.node??null;if(!Qe)continue;const ht=y2(Qe),dt=Array.isArray(ht?.inlines)?ht.inlines:[],ot=eU(dt,Ge.range);fe?fe=PA(fe,ot):fe=ot}const Me=fe?Yz(fe):{},Ve={bold:"bold",italic:"italic",underline:"underline",strikethrough:"strike"},je=new Set([...p?.activeMarks??(Array.isArray(u?.activeMarks)?u.activeMarks:[]),...A]);for(const[Ge,Qe]of Object.entries(Ve))je.has(Ge)&&(Me[Qe]=!0);const Ke=b??await Kf(p??Ii(u,"ready"));if(Ke.fontFamily&&(Me.fontFamily=Ke.fontFamily),Ke.color&&(Me.color=Ke.color),Ke.highlight&&(Me.highlight=Ke.highlight),Ke.fontSize){const Ge=Number.parseFloat(Ke.fontSize);Number.isNaN(Ge)||(Me.fontSize=Ge)}let Ze=null;if(N.length===1){const Ge=N[0],Qe=(await Ll(Ao(Ge.blockId,oe)))?.node??null;Qe&&y2(Qe)&&(Ze=await tU(Qe,Ge.blockId,G,oe))}return{story:oe??null,inline:Me,paragraph:Ze}},y2=u=>u?u.kind==="paragraph"?u.paragraph??null:u.kind==="heading"?u.heading??null:null:null,eU=(u,p)=>{const b=G=>{const oe=G.run;return typeof oe?.text=="string"?oe.text:""},A=G=>G.run?.props;if(p.start===p.end){let G=0;for(const oe of u){const fe=b(oe),Me=G,Ve=G+fe.length;if(G=Ve,p.start>=Me&&p.start<=Ve){const je=A(oe);return je?{...je}:{}}}return{}}let x=0;const N=[];for(const G of u){const oe=b(G),fe=x,Me=x+oe.length;if(x=Me,Me<=p.start||fe>=p.end)continue;const Ve=A(G);Ve&&N.push(Ve)}return N.length===0?{}:N.length===1?{...N[0]}:PA(N[0],...N.slice(1))},PA=(u,...p)=>{const b={...u};for(const A of p)for(const x of Object.keys(b)){if(!(x in A)){delete b[x];continue}const N=b[x],G=A[x];(typeof N!=typeof G||JSON.stringify(N)!==JSON.stringify(G))&&delete b[x]}return b},tU=async(u,p,b,A)=>{const x=y2(u),N=x.props??{},G=x.styleRef??null,oe=N.alignment??null,fe=N.spacing??null,Me=N.indent??null,Ve=Me?{...Me.left!=null?{left:Me.left}:{},...Me.right!=null?{right:Me.right}:{},...Me.firstLine!=null?{firstLine:Me.firstLine}:{},...Me.hanging!=null?{hanging:Me.hanging}:{}}:null,je=N.markRunProps??null,Ke=N.numbering?.numId,Ze=typeof Ke=="string"?parseInt(Ke,10):typeof Ke=="number"?Ke:NaN,Ge=N.numbering?.level,Qe=isNaN(Ze)?null:{numId:Ze,...Ge!=null?{level:Ge}:{}};let ht=null;if(Qe&&typeof b.lists?.getState=="function")try{const dt=await b.lists.getState({target:Ao(p,A)});dt&&typeof b.lists?.getStyle=="function"&&(ht=await b.lists.getStyle(dt)??null)}catch{}return{styleId:G,alignment:oe,spacing:fe,indentation:Ve,markRunProps:je,numbering:Qe,listStyle:ht}},DA=async()=>{if(h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;const u=y()?.selection,p=async()=>{const G=typeof u?.current=="function"?await Promise.resolve(u.current({includeText:!0})):Pa().value;return Hi(G)},b=()=>new Promise(G=>setTimeout(G,16)),A=8;let x=null,N="";for(let G=0;G<A;G+=1){if(G>0&&await b(),h.mode==="idle"||h.pointerSelecting||h.keyboardSelecting)return;if(x=await p(),!(!x||x.empty)&&(N=pc(x),N!==h.sourceSelectionKey))break}if(x&&!x.empty&&N!==h.sourceSelectionKey){await OA(x);return}if(h.snapshot?.paragraph){const G=await p();if(!G||pc(G)===h.sourceSelectionKey)return;await OA(G)}},OA=async u=>{const p=h.snapshot;if(!p){h.mode==="armed"&&Tm();return}const b=y();if(!b)return;const A=Ii(u,"ready"),{lockModesById:x}=Gs(b.contentControls,A);if(fs(x)){Ot();return}const N=u.target,G=u.selectionTarget;if(u.empty!==!0&&Object.keys(p.inline).length>0){const oe=pr(b,"format.apply");if(oe&&G)try{if(!Io(js(await Promise.resolve(v2("format.apply",oe,{target:G,inline:p.inline},u))))){Ot();return}}catch{Ot();return}}if(p.paragraph){const oe=Array.isArray(N?.segments)?N.segments:[],fe=N?.story;for(const Me of oe){const Ve=Ao(Me.blockId,fe),je=await Ll(Ve),Ke=je?.node??null,Ze=je?.address??null;if(!Ke)continue;const Ge={kind:"block",nodeType:Ze?.nodeType??Ke.kind??"paragraph",nodeId:Me.blockId,...fe&&typeof fe=="object"?{story:fe}:{}},{styleId:Qe,alignment:ht,spacing:dt,indentation:ot,markRunProps:Bt,numbering:zt,listStyle:$n}=p.paragraph;if(Qe&&await b.styles?.paragraph?.setStyle?.({target:Ge,styleId:Qe}),ht&&await b.format?.paragraph?.setAlignment?.({target:Ge,alignment:ht}),dt){const Gn=dt,Qr=Gn.lineRule??"auto",Jr=new Set(["auto","exact","atLeast"]).has(Qr)?Qr:"auto",kr={...Gn.before!=null?{before:Math.round(Gn.before*20)}:{},...Gn.after!=null?{after:Math.round(Gn.after*20)}:{},...Gn.line!=null?{line:Math.round(Jr==="auto"?Gn.line*240:Gn.line*20),lineRule:Jr}:{}};await b.format?.paragraph?.setSpacing?.({target:Ge,...kr})}if(ot){const Gn={...ot.left!=null?{left:Vs(ot.left)}:{},...ot.right!=null?{right:Vs(ot.right)}:{},...ot.firstLine!=null?{firstLine:Vs(ot.firstLine)}:{},...ot.hanging!=null?{hanging:Vs(ot.hanging)}:{}};await b.format?.paragraph?.setIndentation?.({target:Ge,...Gn})}Bt&&await b.format?.paragraph?.setMarkRunProps?.({target:Ge,markRunProps:Bt}),zt&&await b.format?.paragraph?.setNumbering?.({target:Ge,...zt}),$n&&((await Ll(Ve))?.address?.nodeType==="listItem"?await b.lists?.applyStyle?.({target:bA(Me.blockId,fe),style:$n}):zt&&await b.format?.paragraph?.setNumbering?.({target:Ge,...zt}))}}h.mode==="armed"&&Tm(),Ot()},Rm=(u,p,b)=>{const A=Zj(u,p),x=A?A.then(()=>(Tc(u,p,b),hi)):(Tc(u,p,b),hi);return Au(u)?.inline?.kind==="toggle"&&(qu=x),x},FA=u=>({id:u,getState:()=>D.toolbar.commands[u]??Gu(u,y(),D.selection,Ml(D.selection)),observe:p=>Go(b=>b.toolbar.commands[u]??{enabled:!1,active:!1,supported:!1,source:"unsupported",reason:ut.commandUnsupported}).subscribe(p),execute:p=>Tc(u,p),executeAsync:p=>Rm(u,p)}),nU=u=>{le.set(u.id,u),Ot();const p=()=>{le.delete(u.id),Ot()};return Object.assign(p,{handle:FA(u.id),unregister:p})},Mm=bo(u=>u.selection),Lm=Xo(Mm),NA=()=>{const u=P();if(typeof u?.getHandles!="function")return{reason:ut.hostCapabilityUnavailable};let p=null;try{p=u.getHandles()}catch(A){const x=A?.reason;return{reason:x==="host-not-ready"||x==="host-disposed"||x==="editing-mount-required"?ut.notReady:ut.hostCapabilityUnavailable}}const b=p?.editing?.selectionTargets;return typeof b?.apply!="function"?{reason:ut.hostCapabilityUnavailable}:{helper:b}},rU=u=>{const p=P();if(typeof p?.getHandles=="function")try{const b=p.getHandles()?.editing?.contentControls;typeof b?.activate=="function"&&b.activate({id:u})}catch{}},BA={get:Lm.get,getSnapshot:Lm.getSnapshot,subscribe:Lm.subscribe,observe:Lm.observe,current:()=>Pa().value,capture:()=>{const u=Mm.get();return u.empty||!u.target&&!u.selectionTarget?null:{...u,capturedAt:Date.now()}},restore:u=>{const p=x=>(Ot(),{...x,success:x.ok});if(!u||typeof u!="object")return p({ok:!1,reason:ut.targetUnresolved});if(!S())return p({ok:!1,reason:ut.notReady});const b=WV(u);if(!b)return p({ok:!1,reason:ut.targetUnresolved});const A=NA();if(!("helper"in A))return p({ok:!1,reason:A.reason});try{return p(dA(A.helper.apply(b)))}catch{return p({ok:!1,reason:ut.hostCapabilityUnavailable})}},apply:u=>{if(!S())return{ok:!1,reason:ut.notReady};const p=NA();if(!("helper"in p))return{ok:!1,reason:p.reason};try{const b=p.helper.apply(u);return Ot(),dA(b)}catch{return{ok:!1,reason:ut.hostCapabilityUnavailable}}},getAnchorRect:u=>{const p=P();if(typeof p?.getSelectionAnchorRect=="function"){const b=Mt(()=>p.getSelectionAnchorRect(u),null);return b&&typeof b=="object"&&(Number(b.width)>0||Number(b.height)>0)?b:null}return null},getRects:u=>{const p=Mm.get(),b=p.selectionTarget??p.target;if(p.empty||!b)return[];const A=jm.getRect({target:b,relativeTo:u?.relativeTo});return A.found?A.rects:[]}},oU={get ids(){return Pr()},has:u=>Au(u)!=null||le.has(u),get:u=>FA(u),execute:Tc,executeAsync:Rm,register:nU,getContextMenuItems:u=>{const p=[];for(const b of le.values()){const A=b.contextMenu;A&&Mt(A.when?()=>A.when(u):void 0,!0)&&p.push({id:b.id,label:A.label,group:A.group,order:A.order,invoke:()=>Tc(b.id,void 0,u)})}return p.sort((b,A)=>(b.order??0)-(A.order??0)||b.label.localeCompare(A.label))}},b2=Xo(bo(u=>u.toolbar)),iU={get:b2.get,getSnapshot:()=>D.toolbar,subscribe:b2.subscribe,observe:b2.observe,execute:Tc,executeAsync:Rm},Xu=async(u,p)=>{if(!S())return{success:!1,ok:!1,reason:ut.notReady};if(!u)return{success:!1,ok:!1,reason:ut.targetUnresolved};const b=P(),A=b?.scrollTargetIntoView;if(typeof A!="function")return{success:!1,ok:!1,reason:ut.hostCapabilityUnavailable};try{const x={target:u,block:p?.block??"center",behavior:p?.behavior??"smooth"},N=await Promise.resolve(p?.shouldContinue?A.call(b,x,p.shouldContinue):A.call(b,x));return N&&typeof N=="object"&&N.success===!1?{success:!1,ok:!1,reason:o2(N.reason,ut.targetUnresolved)}:{success:!0,ok:!0}}catch{return{success:!1,ok:!1,reason:ut.hostCapabilityUnavailable}}},zA=u=>{if(!u||typeof u!="object")return null;const p=u,b=p.wordRevisionIds&&typeof p.wordRevisionIds=="object"?p.wordRevisionIds:null,A=p.sourceIds&&typeof p.sourceIds=="object"?p.sourceIds:null,x=Array.isArray(A?.wordIdOther)?A.wordIdOther:void 0,N=b?.insert??b?.delete??b?.format??A?.wordIdInsert??A?.wordIdDelete??x?.[0];return typeof N=="string"&&N.length>0?N:null},VA=async(u,p,b,A,x)=>{const N=await Xu(p,x);if(N.ok)return N;const G=w(),oe=G?.focusTrackedChange;if(typeof oe!="function")return N;const fe=b||A?{commentId:u,...b?{trackedChangeStory:b}:{},...A?{importedId:A}:{}}:u;try{const Me=await Promise.resolve(oe.call(G,fe));if(Me&&typeof Me=="object"&&Me.ok===!0)return{success:!0,ok:!0}}catch{}return N},Pm=async(u,p,b,A)=>{const x=u==="trackChanges"?A?.story:void 0,N=dt=>{if(!x||!dt||typeof dt!="object")return dt;const ot=dt,Bt=ot.address&&typeof ot.address=="object"?ot.address:null;return ot.story||Bt?.story?dt:{...ot,story:x}},G=u==="trackChanges"?pA:Pf,oe=b.find(dt=>Ni(dt,p,x)),fe=oe&&typeof oe=="object"?oe:null,Me=u==="trackChanges"&&fe?.type==="move"&&(fe.subtype==="move-to"||fe.subtype==="move-from")?fe.subtype:null,Ve=Me&&typeof fe?.trackedChangeCanonicalId=="string"?fe.trackedChangeCanonicalId:p,je=dt=>{if(!Me)return u==="trackChanges"?pA(dt,{preferStableBlock:!0}):G(dt);const ot=Pf(dt);if(ot?.kind!=="move")return null;const Bt=Me==="move-to"?ot.destination:ot.source;return i2(Bt)?Bt:null},Ke=G(oe),Ze=u!=="trackChanges"||!Me&&i2(Pf(oe));if(Ke&&Ze)return N(Ke);const Ge=y()?.[u],Qe=u==="comments"?{commentId:p}:{id:Ve,...x?{story:x}:{}},ht=Ge?.get;if(typeof ht!="function")return N(Ke);try{return N(je(await Promise.resolve(ht.call(Ge,Qe)))??Ke)}catch{return N(Ke)}};function jA(u,p){if(La())return Kn("Comments are read-only.","DOCUMENT_READONLY");if(Ma())return Kn("Resolving comments is disabled.","DOCUMENT_READONLY");const b=y()?.comments,A=b?.patch;if(typeof A!="function")return Kn("comments.patch is unavailable.");const x=Kn("comments.patch failed.");return Mt(()=>Bl(A.call(b,{commentId:u,status:p}),x),x)}const Xf=()=>La()?Kn("Comments are read-only.","DOCUMENT_READONLY"):null,sU=(u,p)=>{const b=p&&typeof p=="object"?p:null;let A=Array.from(u);b?.includeResolved===!1&&(A=A.filter(fe=>fe.status!=="resolved"));const x=Number(b?.offset),N=Number.isInteger(x)&&x>0?x:0,G=Number(b?.limit),oe=Number.isInteger(G)&&G>=0?N+G:void 0;return A.slice(N,oe)},Zu=bo(u=>u.comments),Dm=ja(Zu,Go(u=>Pu(u.selection,u.comments)),"comments"),aU={get:Dm.get,getSnapshot:Dm.getSnapshot,subscribe:Dm.subscribe,observe:Dm.observe,list:u=>{be();const p=Cc();return sU(p.value??Zu.get().items,u)},getById:u=>{const p=Zu.get().items.find(x=>ro(x)===u)??null;if(p)return p;const b=y()?.comments,A=Mt(b?.get?()=>b.get({commentId:u}):void 0,null);return Ir(A)?null:A},createFromCapture:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.create;if(typeof x!="function")return Kn("comments.create is unavailable.");const N=Kn("comments.create failed.");return Mt(()=>{const G=u&&typeof u=="object"?u.target??u.selectionTarget:null;return G==null?Kn("A range selection is required to comment.","NO_SELECTION"):Bl(x.call(A,{target:G,text:p.text}),N)},N)},createFromSelection:u=>{const p=Xf();if(p)return p;const b=y()?.comments,A=b?.create;if(typeof A!="function")return Kn("comments.create is unavailable.");const x=Mm.get(),N=x.target??x.selectionTarget;if(x.empty||!N)return Kn("A range selection is required to comment.","NO_SELECTION");const G=Kn("comments.create failed.");return Mt(()=>Bl(A.call(b,{target:N,text:u.text}),G),G)},reply:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.reply??A?.create;if(typeof x!="function")return Kn("comments.reply is unavailable.");const N=Kn("comments.reply failed.");return Mt(()=>Bl(x===A?.reply?x.call(A,{parentCommentId:u,text:p.text}):x.call(A,{parentCommentId:u,text:p.text}),N),N)},edit:(u,p)=>{const b=Xf();if(b)return b;const A=y()?.comments,x=A?.patch;if(typeof x!="function")return Kn("comments.patch is unavailable.");const N=Kn("comments.patch failed.");return Mt(()=>Bl(x.call(A,{commentId:u,text:p.text}),N),N)},resolve:u=>jA(u,"resolved"),reopen:u=>jA(u,"active"),delete:u=>{const p=Xf();if(p)return p;const b=y()?.comments,A=b?.delete??b?.remove;if(typeof A!="function")return Kn("comments.delete is unavailable.");const x=Kn("comments.delete failed.");return Mt(()=>Bl(A.call(b,{commentId:u}),x),x)},setActive:u=>{if(u==null)return Oe=null,Ot(),!0;if(!S())return!1;const p=Zu.get(),b=Y.get("comments"),A=b?.token===ke()&&b.hasSettled&&Array.isArray(b.value)?b.value:null,x=A??p.items;if(!A&&p.listStatus!=="ready")return!1;const N=xV(x,u);return!N||!x.some(G=>ro(G)===N)?!1:(Oe=N,Ot(),!0)},scrollTo:async u=>{if(!y())return{success:!1,ok:!1,reason:S()?ut.documentApiUnavailable:ut.notReady};const p=await Pm("comments",u,Zu.get().items);return p?Xu(p):{success:!1,ok:!1,reason:ut.targetUnresolved}}},gs=bo(u=>u.trackChanges),w2=(u,p)=>{zi();const b=($s().value??gs.get().items).map(Nf).filter(je=>je!=null&&ro(je)!==null);if(b.length===0)return null;const A=D.trackChanges.activeId,x=He?.id===A?He.story:void 0,N=b.filter(je=>hm(je)==null),G=x||N.length===0?b:N;let oe=A?G.findIndex(je=>Ni(je,A,x)):-1;oe===-1&&A&&x&&(oe=G.findIndex(je=>Ni(je,A)));const fe=G[oe===-1?u>0?0:G.length-1:(oe+u+G.length)%G.length],Me=ro(fe),Ve=hm(fe);return re(Ve?{id:Me,story:Ve}:{id:Me},p),Ot(),Me},UA=async u=>{const p=w(),b=p?.listTrackedChanges;if(typeof b=="function")try{await Promise.resolve(b.call(p,{mode:"visible-window",targetIds:[u],refreshReason:"ui-track-change-reveal-restamp",blocking:!0}))}catch{}};let HA=Promise.resolve();const lU=u=>{const p=yt;return HA.catch(()=>{}).then(()=>cU(u,p))},cU=async(u,p)=>{if(yt!==p)return{success:!1};const b=He,A=w2(u,{invalidateQueuedNavigation:!1});if(A==null)return{success:!1};const x=He,N=it,G=()=>yt===p&&He===x&&it===N,oe=()=>{G()&&(re(b,{invalidateQueuedNavigation:!1}),Ot())};x&&$e.add(x);try{const fe=await Pm("trackChanges",A,gs.get().items,x?.story?{story:x.story}:void 0);if(!G())return{success:!1};if(!fe)return oe(),{success:!1};const Me=gs.get().items.find(je=>Ni(je,A,x?.story))??gs.get().items.find(je=>ro(je)===A),Ve=zA(Me);dn+=1;try{const je=await VA(A,fe,x?.story,Ve,{behavior:"auto",shouldContinue:G});if(!G())return{success:!1};if(!je.ok&&je.reason!==ut.targetNotVisible)oe(),C(b);else{if(je.ok&&await UA(A),!G())return{success:!1};C(x)}return{success:je.ok}}finally{dn=Math.max(0,dn-1),dn===0&&(G()?di&&An(en(di)):C(He))}}finally{x&&$e.delete(x)}},$A=u=>{const p=lU(u);return HA=p.then(()=>{},()=>{}),p},Om=ja(gs,Go(u=>Gi(u.selection,u.trackChanges)),"trackChanges"),uU={get:Om.get,getSnapshot:Om.getSnapshot,subscribe:Om.subscribe,observe:Om.observe,list:()=>{zi();const u=$s().value??gs.get().items,p=Lt(ke());return u.map(Nf).filter(b=>b!=null).filter(b=>{const A=ro(b);return!A||!p?.has(A)})},accept:u=>C2("accept",u),reject:u=>C2("reject",u),acceptAll:()=>Zf("accept",{kind:"all"},null),rejectAll:()=>Zf("reject",{kind:"all"},null),next:()=>w2(1),previous:()=>w2(-1),navigateNext:()=>$A(1),navigatePrevious:()=>$A(-1),getAt:u=>{if(!u||typeof u!="object"||typeof u.x!="number"||typeof u.y!="number")return null;const p=_2(u);if(p.length===0)return null;const b=gs.get().items;let A;for(const x of p){if(x.type!=="trackedChange")continue;let N;if(x.story){if(A===void 0&&(A=li()),!A)continue;N=A}else N=b;const G=N.find(oe=>Ni(oe,x.id,x.story));if(G)return x.story?{id:G.id,item:G,story:x.story}:{id:G.id,item:G}}return null},setActive:u=>{if(u==null)return re(null),C(null),Ot(),!0;if(!S())return!1;const p=typeof u=="string"?{id:u}:{id:u.id,story:u.story};if(typeof p.id!="string"||p.id.length===0)return!1;const b=p.id;if(p.story){const A=li();if(!A)return!1;const x=gc(A,p.story).toPublicId(p.id)??p.id;if(!A.some(N=>Ni(N,x,p.story)))return!1;p.id=x}else{const A=li()??gs.get().items,x=zs(A).toPublicId(p.id)??p.id,N=A.find(G=>ro(G)===x);if(!N)return!1;p.id=x,p.story=hm(N)}return b!==p.id&&(p.paintedEntityId=b),re(p),C(p),Ot(),!0},scrollTo:async u=>{if(!y())return{success:!1,ok:!1,reason:S()?ut.documentApiUnavailable:ut.notReady};yt+=1,De+=1;const p=De,b=gs.get().items,A=zs(b).toPublicId(u)??u,x=b.find(Me=>ro(Me)===A),N=hm(x),G=zA(x),oe=He,fe={id:A,...N?{story:N}:{},...A!==u?{paintedEntityId:u}:{}};$e.add(fe);try{const Me=await Pm("trackChanges",A,b,N?{story:N}:void 0);if(De!==p)return{success:!1,ok:!1};if(!Me)return{success:!1,ok:!1,reason:ut.targetUnresolved};re(fe);const Ve=De,je=He,Ke=it,Ze=()=>De===Ve&&He===je&&it===Ke,Ge=()=>{Ze()&&(re(oe,{invalidateQueuedNavigation:!1}),Ot())};Ot(),dn+=1;try{const Qe=await VA(A,Me,N,G,{behavior:"auto",shouldContinue:Ze});if(!Ze())return{success:!1,ok:!1};if(!Qe.ok&&Qe.reason!==ut.targetNotVisible)Ge(),C(oe);else{if(Qe.ok&&await UA(A),!Ze())return{success:!1,ok:!1};C(fe)}return Qe}finally{dn=Math.max(0,dn-1),dn===0&&(Ze()?di&&An(en(di)):C(He))}}finally{$e.delete(fe)}}},C2=(u,p)=>{const{id:b,story:A}=typeof p=="string"?{id:p,story:void 0}:p,x={kind:"id",id:b,...A?{story:A}:{}};return Zf(u,x,b,A)},Zf=(u,p,b,A)=>{try{return Mo(k2(u,p,b,A))}catch{return!1}},k2=(u,p,b,A)=>{if(La())return!1;const x=y()?.trackChanges,N=p.kind==="all"||p.scope==="all",G=p.kind==="range",oe=p.kind==="ids";if($u({kind:u,scope:N?"all":"id"},x))return!1;const fe=N?`${u}All`:u,Me=!G&&!oe&&!A&&x&&typeof x[fe]=="function"?x[fe]:null,Ve=x&&typeof x.decide=="function"?x.decide:null;return!Me&&!Ve?!1:Me?Me.call(x,b??{}):Ve.call(x,{decision:u,target:p})},S2=bo(u=>u.contentControls),Qf=u=>S2.get().items.find(p=>p?.id===u)??null,Fm=Xo(S2),dU=(u=>{if(u===void 0)return Fm.get();const p=pm(u);return p?Qf(p):null}),fU={get:(u=>(u!==void 0&&oo("api"),dU(u))),getSnapshot:Fm.getSnapshot,subscribe:Fm.subscribe,observe:Fm.observe,list:()=>(oo("api"),S2.get().items),getById:u=>(oo("api"),Qf(u)),getRect:u=>{const p=pm(u);if(!p)return Cl("unresolved");oo("panel");const b=Qf(p);if(!b)return Cl("unresolved");const A=s2(b);return A?jm.getRect({target:A}):Cl("unavailable")},scrollIntoView:async u=>{const p=pm(u);if(!p)return{success:!1};oo("panel");const b=Qf(p);if(!b)return{success:!1};const A=s2(b);return A?{success:(await Xu(A,{block:u.block,behavior:u.behavior})).ok}:{success:!1}},focus:async u=>{const p=pm(u);if(!p)return{success:!1,reason:"invalid-id"};if(!S())return{success:!1,reason:"not-ready"};oo("panel");const b=Qf(p);if(!b)return{success:!1,reason:"not-found"};const A=s2(b);if(!A)return{success:!1,reason:"not-reachable"};if(!(await Xu(A,{block:u.block,behavior:u.behavior})).ok)return{success:!1,reason:"not-reachable"};const x=CV(A);if(!x)return{success:!1,reason:"not-reachable"};const N=BA.apply(x);return!N.ok&&N.reason!==ut.hostCapabilityUnavailable?{success:!1,reason:"not-reachable"}:(rU(p),{success:!0})}},Nm=Xo(bo(u=>u.fonts)),hU={get:Nm.get,getSnapshot:Nm.getSnapshot,subscribe:Nm.subscribe,observe:Nm.observe,getFamilyOptions:()=>D.fonts.options,getSizeOptions:()=>D.fonts.sizeOptions},Bm=Xo(bo(u=>u.zoom)),pU={get:Bm.get,getSnapshot:Bm.getSnapshot,subscribe:Bm.subscribe,observe:Bm.observe,set:u=>{if(typeof t?.setZoom=="function")try{t.setZoom(u),Ot()}catch{}},setMode:u=>{if(typeof t?.setZoomMode=="function")try{t.setZoomMode(u),Ot()}catch{}}},zm=Xo(bo(u=>u.document)),mU={get:zm.get,getSnapshot:zm.getSnapshot,subscribe:zm.subscribe,observe:zm.observe,setMode:u=>{if(typeof t?.setDocumentMode=="function")try{t.setDocumentMode(u),Ot()}catch{}},export:u=>{if(typeof t?.export=="function")try{return Promise.resolve(t.export(u))}catch{return}},getText:()=>{const u=y(),p=Mt(u?.getText?()=>u.getText({}):void 0,null);return typeof p=="string"?p:p&&typeof p=="object"&&typeof p.text=="string"?p.text:null},replaceFile:u=>{const p=t?.replaceFile??t?.loadDocument??t?.reload;if(typeof p=="function")try{return Promise.resolve(p.call(t,u))}catch{return}}},GA=()=>{if(typeof HTMLElement>"u")return null;const u=S()?.mount?.container;if(u instanceof HTMLElement)return u;const p=t?.element;return p instanceof HTMLElement?p:null},gU=(u,p)=>{if(typeof u!="number"||typeof p!="number"||!Number.isFinite(u)||!Number.isFinite(p))return[];const b=globalThis.document;if(!b||typeof b.elementFromPoint!="function")return[];const A=GA();if(!A)return[];const x=b.elementFromPoint(u,p);if(!x||!A.contains(x))return[];const N=[x],G=ot=>{ot&&A.contains(ot)&&!N.includes(ot)&&N.push(ot)},oe=b.elementsFromPoint;if(typeof oe=="function"){let ot=[];try{ot=oe.call(b,u,p)??[]}catch{ot=[]}for(const Bt of ot)G(Bt)}const fe=[],Me=ot=>{ot&&A.contains(ot)&&!fe.includes(ot)&&!N.includes(ot)&&fe.push(ot)},Ve=ot=>{const Bt=ot.getBoundingClientRect;if(typeof Bt!="function")return!1;let zt;try{zt=Bt.call(ot)}catch{return!1}return zt!=null&&u>=zt.left&&u<=zt.right&&p>=zt.top&&p<=zt.bottom};for(const ot of N){const Bt=ot.querySelectorAll;if(typeof Bt!="function")continue;let zt;try{zt=Bt.call(ot,"[data-track-change-marker]")}catch{continue}for(let $n=0;$n<zt.length;$n+=1)Ve(zt[$n])&&Me(zt[$n])}fe.reverse();const je=[...fe,...N],Ke=uA(je[0],A);for(let ot=1;ot<je.length;ot+=1)for(const Bt of uA(je[ot],A))Ke.push(Bt);if(Ke.length===0)return Ke;const Ze=gs.get().items,Ge=zs(Ze);let Qe;const ht=new Set,dt=[];for(const ot of Ke){if(ot.type!=="trackedChange"){const Gn=`${ot.type}:${ot.id}`;if(ht.has(Gn))continue;ht.add(Gn),dt.push(ot);continue}const Bt=wV(ot.storyKey)??bV(ot.story);let zt;if(Bt){if(Qe===void 0&&(Qe=li()),!Qe||(zt=gc(Qe,Bt).toPublicId(ot.id),!zt||!Qe.some(Gn=>Ni(Gn,zt,Bt))))continue}else if(zt=Ge.toPublicId(ot.id),!zt)continue;const $n=`trackedChange:${zt}`;ht.has($n)||(ht.add($n),dt.push(Bt?{type:"trackedChange",id:zt,story:Bt}:{type:"trackedChange",id:zt}))}return dt};function _2(u,p){return typeof u=="object"?gU(u?.x,u?.y):null}const Qu=new Set;let A2=!1;const WA=u=>{const p=P();if(typeof p?.observeGeometry!="function")return;let b=!1;const A=Mt(()=>{const x=p.observeGeometry(()=>u.schedule());return b=!0,x},null);u.detach=typeof A=="function"?A:null,u.boundHost=b?p:null},Vm=u=>{if(u.detach){try{u.detach()}catch{}u.detach=null}u.boundHost=null},KA=()=>{if(A2=!1,!(j||P()))for(const u of Qu)Vm(u)},vU=()=>{if(!A2){if(A2=!0,typeof queueMicrotask=="function"){queueMicrotask(KA);return}Promise.resolve().then(KA)}},yU=()=>{const u=P();if(!u){vU();return}for(const p of Qu)p.boundHost&&p.boundHost===u||(Vm(p),WA(p),p.schedule())};xi.push(yU);const jm={getRect:u=>{const p=P(),b=p?.getTargetRects;if(typeof b=="function"){const A=Mt(()=>b.call(p,{target:u.target}),null);return A&&typeof A=="object"?A.success===!0&&Array.isArray(A.rects)?$V(HV(A.rects.filter(x=>x!=null&&typeof x=="object")),u.relativeTo):Cl(typeof A.reason=="string"?A.reason:"unresolved"):Cl("unresolved")}return Cl("unavailable")},observe:u=>{const p=[];let b=0;const A=typeof requestAnimationFrame=="function",x=()=>{if(!A){u();return}b||(b=requestAnimationFrame(()=>{b=0,u()}))},N=Go(oe=>({ready:oe.ready,selection:oe.selection,zoom:oe.zoom}));p.push(N.subscribe(()=>x()));const G={schedule:x,detach:null,boundHost:null};return WA(G),Qu.add(G),()=>{Qu.delete(G),Vm(G),b&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(b);for(const oe of p.splice(0))try{oe()}catch{}}},getHost:()=>GA(),entityAt:_2,contextAt:u=>{const p=!!u&&typeof u.x=="number"&&typeof u.y=="number",b=p?u.x:0,A=p?u.y:0;return{point:{x:b,y:A},entities:p?_2({x:b,y:A}):[],selection:D.selection,position:null,insideSelection:!1}},scrollIntoView:async u=>{const p=u?.target;if(!p)return{success:!1};let b=null;if(p.kind==="entity"){const A=p.entityType==="comment"?"comments":"trackChanges",x=A==="comments"?Zu.get().items:gs.get().items,N=p.entityType==="trackedChange"&&p.story?{story:p.story}:void 0;b=await Pm(A,p.entityId,x,N)}else{const A=p,x=p,N=Array.isArray(A.segments)&&A.segments.length>0?A.segments:x.blockId&&x.range?[{blockId:x.blockId,range:x.range}]:null;if(N){const G=p.story;b={kind:"text",segments:N,...G?{story:G}:{}}}}return b?{success:(await Xu(b,{block:u.block??"center",behavior:u.behavior??"smooth"})).ok}:{success:!1}}},qA=u=>{const p=(u&&typeof u=="object"?u:null)?.target;return p&&typeof p=="object"?p:null},YA=u=>`metadata:resolve:${u}`,bU=u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return null;const{value:b}=To(YA(u),ke(),()=>p.resolve({id:u}),qA);return b},wU=async u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return null;try{const b=ke(),A=await Promise.resolve(p.resolve({id:u}));if(b!==ke())return null;const x=qA(A);return Y.set(YA(u),{token:b,value:x,hasSettled:!0,inflightToken:null}),x}catch{return null}},CU={getRect:u=>{const p=y()?.metadata;if(!p||typeof p.resolve!="function")return Cl("unavailable");const b=bU(u.id);return b?jm.getRect({target:b}):Cl("unresolved")},scrollIntoView:async u=>{const p=await wU(u.id);return p?{success:(await Xu(p,{block:u.block,behavior:u.behavior})).ok}:{success:!1}}},kU={inTable:!1,tableNodeId:null,rowIndex:null,columnIndex:null,cellNodeId:null,rows:null,columns:null},SU={getContext:()=>{const u=Se();if(!u)return{...kU};const p=ve()?.table;return{inTable:!0,tableNodeId:u.tableNodeId,rowIndex:u.rowIndex,columnIndex:u.columnIndex,cellNodeId:u.cellNodeId,rows:typeof p?.rows=="number"?p.rows:null,columns:typeof p?.columns=="number"?p.columns:null}},isInTable:()=>Se()!=null},Um={query:"",total:0,activeIndex:-1,open:!1,available:!1,caseSensitive:!1,includeDeletedText:!1,regex:!1,canReplace:!1,reason:ut.searchUnavailable};let zn={...Um};const Hm=new Set,Ha=()=>{const u=P()?.search;return u&&typeof u=="object"?u:null},qs=()=>{const u=ee()?.search;return u&&typeof u=="object"?u:null},Jf=()=>{const u=Ha();if(u&&typeof u.setSession=="function")return!0;const p=qs();return!!p&&typeof p.query=="function"&&typeof p.getState=="function"},vs=()=>{for(const u of[...Hm])try{u(zn)}catch{}},pi=u=>(zn={...zn,...u},vs(),zn);let so=0,Rc=null;const XA=()=>{const u=Rc;Rc=null,u&&Mt(()=>(u(),null),null)},_U=()=>{so+=1,XA();const u=Jf();zn={...Um,available:u,reason:u?void 0:ut.searchUnavailable},vs()};Et.push(_U);const AU=u=>{if(!u)return!1;const p=u.queryError;if(p&&typeof p=="object"&&p.code==="invalid-pattern")return!0;const b=u.rejection;return u.status==="rejected"&&!!b&&typeof b=="object"&&b.code==="invalid-pattern"},I2=(u,p=!1)=>{const b=u&&typeof u=="object"?u:null;if(!b)return null;const A=Array.isArray(b.matches)?b.matches:[],x=typeof b.total=="number"&&Number.isFinite(b.total)?b.total:A.length,N=typeof b.activeMatchIndex=="number"?b.activeMatchIndex:typeof b.activeIndex=="number"?b.activeIndex:-1;return{...typeof b.query=="string"?{query:b.query}:{},total:x,activeIndex:N,canReplace:b.canReplace===!0||p,...b.includeDeletedText===!0?{includeDeletedText:!0}:{},...b.regex===!0?{regex:!0}:{},...AU(b)?{invalidPattern:!0}:{}}},Lo=()=>{const u=ne("find.replace"),p=ne("find.replaceAll");return u?.enabled===!0||p?.enabled===!0},Po=(u,p=!1)=>{const b=I2(u,p);if(!b){pi({total:0,activeIndex:-1,canReplace:!1,reason:void 0});return}pi({...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?ut.searchInvalidPattern:void 0})},$a=()=>{const u=Ha();if(u&&typeof u.getState!="function")return zn={...zn,available:Jf(),reason:Jf()?void 0:ut.searchUnavailable},zn;if(!u){const b=qs();if(b&&typeof b.getState=="function"){const A=I2(Mt(()=>b.getState(),null),Lo());if(A)return zn={...zn,...A.query!==void 0?{query:A.query}:{},total:A.total,activeIndex:A.activeIndex,canReplace:A.canReplace,available:!0,reason:A.invalidPattern?ut.searchInvalidPattern:void 0,open:zn.open||!!A.query},zn}return zn={...Um,query:zn.query,caseSensitive:zn.caseSensitive,includeDeletedText:zn.includeDeletedText},zn}const p=I2(Mt(()=>u.getState(),null));return p&&(zn={...zn,...p.query!==void 0?{query:p.query}:{},total:p.total,activeIndex:p.activeIndex,canReplace:p.canReplace,...p.includeDeletedText!==void 0?{includeDeletedText:p.includeDeletedText}:{},...p.regex!==void 0?{regex:p.regex}:{},available:!0,reason:p.invalidPattern?ut.searchInvalidPattern:void 0,open:zn.open||!!p.query}),zn},Ju=u=>{const p=u&&typeof u=="object"?u:null;if(p?.status==="committed")return{ok:!0};if(p?.status==="rejected"&&p.reason==="read-only")return{ok:!1,reason:ut.documentReadonly};const b=p?.rejection;return p?.status==="rejected"&&b&&typeof b=="object"&&b.code==="read-only-document"?{ok:!1,reason:ut.documentReadonly}:{ok:!1,reason:ut.operationUnavailable}},$m=Xo({get:()=>$a(),subscribe:u=>(Hm.add(u),()=>Hm.delete(u))}),IU={get:$m.get,getSnapshot:$m.getSnapshot,subscribe:$m.subscribe,observe:$m.observe,open:()=>Jf()?(pi({available:!0,open:!0,reason:void 0}),{ok:!0}):(pi({available:!1,open:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}),close:()=>{if(so+=1,Rc)XA();else{const u=Ha();if(u&&typeof u.clear=="function")Mt(()=>u.clear(),null);else{const p=qs();p&&typeof p.query=="function"&&Mt(()=>p.query({query:""}),null)}}zn={...Um,available:Jf(),reason:void 0},zn.available||(zn.reason=ut.searchUnavailable),vs()},search:(u,p)=>{const b=Ha(),A=!!p?.caseSensitive,x=p?.includeDeletedText===!0,N=p?.regex===!0,G=++so;if(!b||typeof b.setSession!="function"){const fe=qs();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){pi({query:u,caseSensitive:A,includeDeletedText:x,regex:N,available:!0,open:!0,reason:void 0}),Rc=()=>{fe.query({query:""})};const Me=Mt(()=>fe.query({query:u,caseSensitive:A,includeDeletedText:x,regex:N}),null);return Ir(Me)?Promise.resolve(Me).then(Ve=>{G===so&&Po(Ve,Lo())},()=>{G===so&&pi({available:!1,reason:ut.searchUnavailable})}):Po(Me,Lo()),Po(Mt(()=>fe.getState(),null),Lo()),zn}return pi({query:u,total:0,activeIndex:-1,available:!1,caseSensitive:A,includeDeletedText:x,regex:N,reason:ut.searchUnavailable})}pi({query:u,caseSensitive:A,includeDeletedText:x,regex:N,available:!0,open:!0,reason:void 0}),Rc=()=>{typeof b.clear=="function"&&b.clear()};const oe=Mt(()=>b.setSession(u,{caseSensitive:A,includeDeletedText:x,...N?{regex:!0}:{},highlight:!0}),null);if(Po(oe),u.length>0&&zn.total===0&&zn.reason!==ut.searchInvalidPattern){const fe=qs();if(fe&&typeof fe.query=="function"&&typeof fe.getState=="function"){const Me=Rc;Rc=()=>{Me?.(),fe.query({query:""})};const Ve=Mt(()=>fe.query({query:u,caseSensitive:A,includeDeletedText:x,regex:N}),null);Ir(Ve)?Promise.resolve(Ve).then(je=>{G===so&&Po(je,Lo())},()=>{G===so&&pi({available:!1,reason:ut.searchUnavailable})}):Po(Ve,Lo()),Po(Mt(()=>fe.getState(),null),Lo())}}return zn},next:()=>{const u=Ha();if(!u||typeof u.next!="function"){const p=qs();if(!p||typeof p.next!="function"||typeof p.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(zn.total===0)return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.next(),null);if(Ir(b)){const A=so;Promise.resolve(b).then(x=>{A===so&&Po(x,Lo())}).catch(()=>{A===so&&pi({available:!1,reason:ut.searchUnavailable})})}else Po(b,Lo());return Po(Mt(()=>p.getState(),null),Lo()),{ok:!0}}return zn.total===0?{ok:!1,reason:ut.operationUnavailable}:(Po(Mt(()=>u.next(),null)),{ok:!0})},previous:()=>{const u=Ha();if(!u||typeof u.previous!="function"){const p=qs();if(!p||typeof p.previous!="function"||typeof p.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(zn.total===0)return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.previous(),null);if(Ir(b)){const A=so;Promise.resolve(b).then(x=>{A===so&&Po(x,Lo())}).catch(()=>{A===so&&pi({available:!1,reason:ut.searchUnavailable})})}else Po(b,Lo());return Po(Mt(()=>p.getState(),null),Lo()),{ok:!0}}return zn.total===0?{ok:!1,reason:ut.operationUnavailable}:(Po(Mt(()=>u.previous(),null)),{ok:!0})},clear:()=>{so+=1;const u=Ha();if(u&&typeof u.clear=="function"&&Mt(()=>u.clear(),null),!u||typeof u.clear!="function"){const p=qs();p&&typeof p.query=="function"&&Mt(()=>p.query({query:""}),null)}pi({query:"",total:0,activeIndex:-1,canReplace:!1})},replace:u=>{const p=Ha();if(!p){const A=qs();if(!A||typeof A.replace!="function"||typeof A.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(!Lo())return{ok:!1,reason:ut.operationUnavailable};const x=Mt(()=>A.replace({replacement:typeof u=="string"?u:""}),null);if(Ir(x)){const N=so;$a(),vs();const G=()=>N===so;return Promise.resolve(x).then(oe=>(G()&&(Po(oe,Lo()),$a(),vs()),Ju(oe)),()=>(G()&&pi({available:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}))}return $a(),vs(),Ju(x)}if(typeof p.replaceCurrent!="function")return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.replaceCurrent(typeof u=="string"?u:""),null);return $a(),vs(),Ju(b)},replaceAll:u=>{const p=Ha();if(!p){const A=qs();if(!A||typeof A.replaceAll!="function"||typeof A.getState!="function")return{ok:!1,reason:ut.searchUnavailable};if(!Lo())return{ok:!1,reason:ut.operationUnavailable};const x=Mt(()=>A.replaceAll({replacement:typeof u=="string"?u:""}),null);if(Ir(x)){const N=so;$a(),vs();const G=()=>N===so;return Promise.resolve(x).then(oe=>(G()&&(Po(oe,Lo()),$a(),vs()),Ju(oe)),()=>(G()&&pi({available:!1,reason:ut.searchUnavailable}),{ok:!1,reason:ut.searchUnavailable}))}return $a(),vs(),Ju(x)}if(typeof p.replaceAll!="function")return{ok:!1,reason:ut.operationUnavailable};const b=Mt(()=>p.replaceAll(typeof u=="string"?u:""),null);return $a(),vs(),Ju(b)}},ZA=bo(u=>u.styles),Gm=Xo(ZA),xU={get:Gm.get,getSnapshot:Gm.getSnapshot,subscribe:Gm.subscribe,observe:Gm.observe,getCatalog:u=>gn(u).value,getQuickGallery:()=>ZA.get().quickGallery,getActiveParagraphStyle:()=>Yr(D.selection,ir().cache).style},QA={select:Go,get state(){return D},selection:BA,commands:oU,toolbar:iU,comments:aU,trackChanges:uU,contentControls:fU,fonts:hU,zoom:pU,document:mU,viewport:jm,metadata:CU,tables:SU,search:IU,styles:xU,formatPainter:{setPointerSelecting(u){j||(h={...h,pointerSelecting:u})},notifyPointerUp(){j||(h={...h,pointerSelecting:!1},DA())},setKeyboardSelecting(u){j||(h={...h,keyboardSelecting:u})},notifyKeyUp(){j||(h={...h,keyboardSelecting:!1},DA())},cancel(){j||Tm()},onModeChange(u){return j?()=>{}:(m.add(u),()=>m.delete(u))}},createScope:()=>{const u=[];return{select:(p,b)=>{const A=Go(p,b);return{get:A.get,subscribe:x=>{const N=A.subscribe(x);return u.push(N),N}}},dispose:()=>{for(const p of u.splice(0))p()}}},destroy:()=>{if(!j){j=!0,cV(jt,$t),We&&(clearTimeout(We),We=null),_e&&(clearTimeout(_e),_e=null,xe=0),me?.timer&&(clearTimeout(me.timer),me.timer=null),me=null,at&&(clearTimeout(at),at=null),Tr&&(clearTimeout(Tr),Tr=null),Mr&&Mr(),Mr=null,xo=null,go=0,ii=0,mr.clear(),qt.clear(),Pn.clear(),Hr=null,Z.clear();for(const u of Xr.splice(0))u();Cr&&Cr(),Cr=null,cn=null,Ki&&Ki(),Ki=null,ps=null,Yo&&Yo(),Yo=null,yo=null,$o&&$o(),$o=null,di=null,fi&&fi(),fi=null,Yi=null,K&&K(),K=null,F=null;for(const u of Qu)Vm(u);Qu.clear(),V.clear(),Hm.clear(),g+=1,m.clear(),so+=1,le.clear()}}};return W=QA,QA}var QV=[{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 JV(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 ej(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"?JV(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 tj(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 nj(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:QV;for(const s of i)o(s);return n}var rj=[{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 oj(e,t){return e.activeMark?t.activeMarks.includes(e.activeMark):!1}xt();var ij=['[data-sdt-type="structuredContent"][data-sdt-id]','[data-sdt-type="structuredContent"][data-sdt-container-id]','[data-sdt-container-type="structuredContent"][data-sdt-container-id]'].join(", "),sj=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 aj(e,t){const n=new v6.default;return e.forEach((r,o)=>{n.file(t[o],r)}),n.generateAsync({type:"blob",compression:"DEFLATE"})}function p2(e){return!!(e&&(e.synced===!0||e.isSynced===!0))}function IA(e){try{e.synced=!0}catch{}try{e.isSynced=!0}catch{}}function lj(e,t){if(!e)return()=>{};if(p2(e))return t(),()=>{};const n=typeof e.on=="function"?e.on.bind(e):null,r=typeof e.off=="function"?e.off.bind(e):null;if(!n)return t(),()=>{};let o=!1;const i=()=>{o||(o=!0,r?.("synced",a),r?.("sync",l))},s=()=>{o||(i(),t())},a=()=>{IA(e),s()},l=c=>{c!==!1&&(c===!0||p2(e))&&(IA(e),s())};return n("synced",a),n("sync",l),p2(e)&&s(),i}function cj(e,t){const n=e.composedPath();if(!n.includes(t))return null;const r=n.find(a=>a instanceof HTMLElement&&a.matches(ij));if(!r)return null;const o=n.some(a=>a instanceof HTMLElement&&a.classList.contains(Jh.BLOCK_SDT_LABEL)),i=r.getAttribute("data-sdt-container-id")?.trim()||null,s=r.getAttribute("data-sdt-id")?.trim()||null;return o?i??s:s??i}function uj(e){if(!e||typeof e!="object")return[];const t=e.items;return Array.isArray(t)?t:[]}function dj(e){if(!e||typeof e.id!="string"||e.kind!=="inline"&&e.kind!=="block"||typeof e.controlType!="string")return null;const t=e.properties?.tag,n=e.properties?.alias;return{id:e.id,controlType:e.controlType,scope:e.kind,...typeof t=="string"&&t?{tag:t}:{},...typeof n=="string"&&n?{alias:n}:{}}}function oi(e){return!!(e&&typeof e=="object"&&e.editorVersion===2)}function fj(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 xA(e){return typeof e=="string"&&e.length>0?e:null}function EA(e){return e?oi(e)?xA(e.documentId??e.options?.documentId??null):xA(typeof e.getDocumentId=="function"?e.getDocumentId():e.options?.documentId):null}function hj(e){if(!e||oi(e))return null;const t=e;return t.documentRenderer??t.presentationEditor??null}function ls(e){if(!e)return null;if(oi(e))return e.fonts??null;const t=hj(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 bm=class extends Km.default{static{this.allowedTypes=[zr,ec,Yh]}#e;#n;#t;#r;#i;#s;#d;#h;#f;#c;#p;get uiConfig(){return this.#p}#o;get interactionConfig(){return this.#o}#l;get surfacesConfig(){return this.#l}#g;#u;#y;#w;constructor(e){if(super(),this.#e=!1,this.#n=!1,this.#t=null,this.#r=null,this.#i=null,this.#s=null,this.#d=null,this.#h=null,this.#f=n=>{this.#k(n)},this.#c=null,this.#p=z4({}),this.#o=V4({}),this.#l=U4({}),this.version="0.0.0",this.users=[],this.whiteboard=null,this.colors=[],this.readyEditors=0,this.pendingCollaborationSaves=0,this.#u=new iN,this.#y=null,this.#w=!1,this.config={selector:"#superdoc",documentMode:"editing",allowSelectionInViewMode:!1,role:"editor",document:{},documents:[],editorExtensions:[],colors:[],users:[],user:{...K0},layoutEngineOptions:{},modules:{},licenseKey:void 0,telemetry:{enabled:!0},title:"SuperDoc",conversations:[],isInternal:!1,comments:{visible:!1},toolbarGroups:["left","center","right"],toolbarIcons:{},toolbarTexts:{},uiDisplayFallbackFont:"Arial, Helvetica, sans-serif",isDev:!1,disablePiniaDevtools:!1,onEditorBeforeCreate:()=>null,onEditorCreate:()=>null,onEditorDestroy:()=>null,onSourceComplete:()=>null,onSourceSignalsComplete:()=>null,onContentError:()=>null,onReady:()=>null,onCommentsUpdate:()=>null,onContentControlActiveChange:()=>null,onContentControlClick:()=>null,onAwarenessUpdate:()=>null,onLocked:()=>null,onPdfDocumentReady:()=>null,onSidebarToggle:()=>null,onCollaborationReady:()=>null,onEditorUpdate:()=>null,onCommentsListChange:()=>null,onException:()=>null,onListDefinitionsChange:()=>null,onPaginationUpdate:()=>null,onTransaction:()=>null,disableContextMenu:!1,viewOptions:{layout:"print"},useLayoutEngine:!0},this.#Z=new WeakSet,this.#Q=null,this.#j=null,this.#M=null,!e.selector)throw new Error("SuperDoc: selector is required");const t=typeof e.selector=="string"?document.querySelector(e.selector):e.selector;if(!(t instanceof HTMLElement))throw new Error("SuperDoc: selector must be a valid CSS selector string or DOM element");this.#g=new KF({getModuleConfig:()=>this.#l}),this.#h=t,t.addEventListener("click",this.#f,!0),this.#I(e,t)}async#k(e){const t=this.#h;if(!t)return;const n=cj(e,t),r=this.activeEditor?.doc?.contentControls?.list;if(!(!n||typeof r!="function"))try{const o=await r();if(this.#e)return;const i=dj(uj(o).find(s=>s.id===n));i&&this.emit("content-control:click",{target:i,source:"pointer"})}catch{return}}async#I(e,t){this.config={...this.config,...e},!this.config.comments||typeof this.config.comments!="object"?this.config.comments={visible:!1}:typeof this.config.comments.visible!="boolean"&&(this.config.comments.visible=!1),eN(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&&r&&(console.warn("[SuperDoc] flowMode 'semantic' is only valid with web layout. Coercing to 'paginated'."),this.config.layoutEngineOptions.flowMode="paginated"),this.editorVersion=2,this.#ye(),this.config.user=tN(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=Fk(this.config.modules.comments),this.#p=z4(this.config),this.#o=V4(this.config),this.#l=U4(this.config),this.config.disableContextMenu=!this.#p.contextMenu.enabled,this.config.rulers=this.#p.ruler.enabled,this.#p.comments.enabled?this.config.modules.comments===!1&&(this.config.modules.comments={}):this.config.modules.comments=!1,this.#p.comments.enabled){this.config.modules.comments===!0&&(this.config.modules.comments={});const i=this.config.modules.comments;i&&Object.assign(i,this.#o.comments)}if(this.config.colors=A6(this.config.colors),this.userColorMap=new Map,this.colorIndex=0,this.version="2.7.1-next.2",this.#C("πŸ¦‹ [superdoc] Using SuperDoc version:",this.version),this.superdocId=e.superdocId||ys(),this.colors=this.config.colors??[],this.#D(),await v8(),this.#e)return;if(await this.#b(this.config.modules),this.#e){this.#ue();return}this.config.cspNonce&&this.#P(),this.user=this.config.user,this.users=this.config.users||[],this.socket=null,this.isDev=this.config.isDev||!1,this.activeEditor=null,this.comments=[],this.#y||(this.#y=this.#u.subscribe(i=>{this.#we(i.nextRuntimeId,i.legacyEditorProjection)})),this.isLocked=this.config.isLocked||!1,this.lockedBy=this.config.lockedBy||null;const o=document.createElement("div");o.style.display="contents",t.appendChild(o),this.#d=o,this.#S(),this.#L(),this.#Ce(),this.#x()}#x(){if(this.#E(),this.readyEditors=0,!this.app)throw new Error("SuperDoc: #startRuntime called before #initVueApp populated this.app");this.app.mount(this.#d)}#L(){const e=this.config.modules?.whiteboard,t=e!==!1&&(e?.enabled??!1);this.whiteboard=new bD({Renderer:$F,superdoc:this,enabled:t}),this.emit("whiteboard:init",{whiteboard:this.whiteboard})}get requiredNumberOfEditors(){return this.#m("requiredNumberOfEditors").documents.filter(e=>e.type===zr).length}get ui(){return this.#c||(this.#c=ZV({superdoc:this}),this.#e&&this.#c.destroy()),this.#c}get state(){return{documents:this.#m("state").documents,users:this.users}}getDocumentRuntimeForDocument(e){return typeof e!="string"||e.length===0?null:(this.superdocStore?.documents??[]).find(t=>t?.getEditor?.()?.options?.documentId===e)?.getDocumentRuntime?.()??null}getComment(e){return typeof e!="string"||e.length===0?null:this.commentsStore?.getComment?.(e)??null}get element(){return typeof this.config.selector=="string"?document.querySelector(this.config.selector):this.config.selector}#P(){const e=this.config.cspNonce,t=document.createElement;document.createElement=function(n){const r=t.call(this,n);return n.toLowerCase()==="style"&&r.setAttribute("nonce",e),r}}#D(){const e=this.config.document,t=!!e&&typeof e=="object"&&Object.keys(e)?.length,n=!!e&&typeof e=="string"&&e.length>0,r=!!e&&typeof File=="function"&&e instanceof File,o=!!e&&e instanceof Blob&&!(e instanceof File),i=this.config.documents&&this.config.documents?.length;if(t&&i&&console.warn("πŸ¦‹ [superdoc] You can only provide one of document or documents"),t){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}else if(n)this.config.documents=[{id:ys(),type:zr,url:this.config.document,name:"document.docx"}];else if(r){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}else if(o){const s=Kd(this.config.document);this.config.documents=[{id:ys(),...s}]}Array.isArray(this.config.documents)&&this.config.documents.length>0&&(this.config.documents=this.config.documents.map(s=>{const a=Kd(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||ys()}}))}#E(){const{app:e,pinia:t,superdocStore:n,commentsStore:r,highContrastModeStore:o}=aD({disablePiniaDevtools:!!this.config.disablePiniaDevtools});this.app=e,this.pinia=t,this.app.config.globalProperties.$config=this.config,this.app.config.globalProperties.$documentMode=this.config.documentMode,this.app.config.globalProperties.$superdoc=this,this.app.provide("surfaceManager",this.#g),this.superdocStore=n,this.commentsStore=r,this.highContrastModeStore=o,typeof this.superdocStore.setExceptionHandler=="function"&&this.superdocStore.setExceptionHandler(s=>this.emit("exception",s)),this.superdocStore.init(this.config);const i=this.config.modules.comments;this.commentsStore.init(i||{}),this.isCollaborative&&n8(this),this.#ce()}#a(e,t){t&&this.on(e,t)}#S(){this.#a("editorBeforeCreate",this.config.onEditorBeforeCreate),this.#a("editorCreate",this.config.onEditorCreate),this.#a("editorDestroy",this.config.onEditorDestroy),this.#a("source:complete",this.config.onSourceComplete),this.#a("source:signals-complete",this.config.onSourceSignalsComplete),this.#a("ready",this.config.onReady),this.#a("comments-update",this.config.onCommentsUpdate),this.#a("content-control:active-change",this.config.onContentControlActiveChange),this.#a("content-control:click",this.config.onContentControlClick),this.#a("awareness-update",this.config.onAwarenessUpdate),this.#a("locked",this.config.onLocked),this.#a("pdf:document-ready",this.config.onPdfDocumentReady),this.#a("sidebar-toggle",this.config.onSidebarToggle),this.#a("collaboration-ready",this.config.onCollaborationReady),this.on("collaboration-ready",e=>this.#$(e?.editor??null)),this.#a("editor-update",this.config.onEditorUpdate),this.on("content-error",this.onContentError),this.#a("exception",this.config.onException),this.#a("list-definitions-change",this.config.onListDefinitionsChange),this.#a("pagination-update",this.config.onPaginationUpdate),this.#a("fonts-resolved",this.config.onFontsResolved),this.#a("fonts-changed",this.config.onFontsChanged),this.#a("zoomChange",this.config.onZoomChange),this.#a("viewport-change",this.config.onViewportChange)}async#b({collaboration:e}={}){return e?(this.isCollaborative=!1,this.config.documents.length===0&&(this.config.documents=[{id:ys(),type:zr,name:"document.docx"}]),this.config.v2CollaborationPreflightFailure={code:"collaboration-v1-config-unsupported",message:"SuperDoc v2 cannot use modules.collaboration because it is the SuperDoc v1 collaboration API. SuperDoc did not attach the provider or change the document. Configure Document.v2Collaboration with a v2 room instead."},this.config.documents):this.config.documents}#ee(e,t){this.isCollaborative=!0,this._commentsCollabInitialized=!1,this.ydoc=to(e),this.provider=to(t),this.#_();const n=this.config;this._cleanupAwareness=ZT(t,this,n.user),n.documents.forEach(r=>{r.ydoc=e,r.provider=t,r.role=this.config.role})}#H(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null),this.isCollaborative=!1,this._commentsCollabInitialized=!1,this.ydoc=void 0,this.provider=void 0;const e=this.config;delete e.modules.collaboration,e.documents.forEach(t=>{delete t.ydoc,delete t.provider})}#A(){if(this.#r){try{this.#r()}catch{}this.#r=null}if(this.#i){try{this.#i()}catch{}this.#i=null}}#$(e){this.#A(),oi(e)&&(this.#O(e),this.#T(e))}#O(e){const t=e.presence;if(!t||typeof t.subscribe!="function")return;const n=mD(()=>this.user),r=o=>{if(this.#e)return;const i=n.next(o);this.emit("awareness-update",{...i,superdoc:this})};try{const o=t.getSnapshot?.();o&&r(o),this.#r=t.subscribe(r)}catch(o){console.warn("[SuperDoc] v2 awareness bridge failed to subscribe",o)}}#T(e){const t=e.lock;if(!t||typeof t.subscribe!="function")return;const n=r=>{this.#e||this.#v(!!r.isLocked,this.#F(r.lockedBy??null))};try{if(this.#s&&typeof t.setLocked=="function"){const o=this.#s;t.setLocked(o.isLocked,o.isLocked?o.lockedBy:null),this.#s=null}const r=t.getSnapshot?.();r&&n(r),this.#i=t.subscribe(n)}catch(r){console.warn("[SuperDoc] v2 lock bridge failed to subscribe",r)}}#F(e){return!e||typeof e!="object"||Array.isArray(e)?null:{...e}}#G(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}#v(e,t){this.isLocked===e&&this.#G(this.lockedBy,t)||(this.isLocked=e,this.lockedBy=t,this.#C("πŸ¦‹ [superdoc] Locking superdoc:",e,t,`
103
103
 
104
104
 
105
105
  `),this.emit("locked",{isLocked:e,lockedBy:t}))}#_(){const e=this.config.user;if(!e||e.color)return;const t=this.colors.length>0?this.colors:sj,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}=this.#pe(e);this.#n=!0;try{const n=await this.#he(),r=this.#W(),o=this.#N();this.#K();try{this.#s=o;const i=await this.#de(t,n);this.#fe(i,t),this.#s=null}catch(i){throw this.#B(r),i}}finally{this.#t=null,this.#n=!1}}#N(){return{isLocked:this.isLocked,lockedBy:this.lockedBy?{...this.lockedBy}:null}}#W(){const e=this.config.documents.find(r=>r.type===zr),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.#Y(n),storeData:t?.data}}#B(e){this.#s=null;const t=this.config.documents.find(n=>n.type===zr);t.v2Collaboration=e.configV2Collaboration,t.data=e.configData,this.isCollaborative=e.isCollaborative,e.storeDoc&&(e.storeDoc.data=e.storeData,this.#z(e.storeDoc,e.storeV2Collaboration))}#K(){if(this.#e)throw new Error("SuperDoc: instance was destroyed during upgrade")}#m(e){if(!this.superdocStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`);return this.superdocStore}#te(e){if(!this.commentsStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`);return this.commentsStore}#R(e){if(!this.superdocStore)throw new Error(`SuperDoc: ${e} requires the instance to be ready; wait for the "ready" event before calling.`)}#q(e,t){const n=this.superdocStore?.documents;if(Array.isArray(n))for(const r of n){const o=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)}}#Y(e){if(!e)return null;const t=e.v2Collaboration;return t&&typeof t=="object"&&"value"in t?t.value:t??null}#z(e,t){const n=pn(e).v2Collaboration;if(n&&typeof n=="object"&&"value"in n){n.value=t;return}e.v2Collaboration=t}#ne(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}:{}}}async#de(e,t){const n=this.config.documents.find(s=>s.type===zr),r=this.#m("upgradeToCollaboration").documents.find(s=>s.id===n.id);if(!r)throw new Error("SuperDoc: source document store entry is not available for upgrade");const o=r.getEditor?.();if(!oi(o)||typeof o.upgradeToCollaboration!="function")throw new Error("SuperDoc: live v2 editor cannot attach collaboration in place");const i=this.#ne({...e,roomMode:"create"});return n.v2Collaboration=i,this.#z(r,i),this.isCollaborative=!0,await o.upgradeToCollaboration(t,i),n.data=t,r.data=t,{configDoc:n,storeDoc:r}}#fe(e,t){const n=this.#ne({...t,roomMode:"join"});e.configDoc.v2Collaboration=n,this.#z(e.storeDoc,n)}async#he(){const e=this.activeEditor;if(oi(e)&&typeof e.save=="function"){const r=await e.save();return this.#X(r)}const t=this.config.documents.find(r=>r.type===zr),n=(this.superdocStore?.documents.find(r=>r.id===t.id)??null)?.data??t.data;if(n instanceof Blob)return n;if(n instanceof Uint8Array||n instanceof ArrayBuffer)return this.#X(n);throw new Error("SuperDoc: upgradeToCollaboration() requires a live v2 editor save or DOCX Blob source")}#X(e){if(e instanceof Blob)return e;if(e instanceof Uint8Array){const t=new Uint8Array(e.byteLength);return t.set(e),new Blob([t],{type:zr})}if(e instanceof ArrayBuffer)return new Blob([e],{type:zr});throw new Error("SuperDoc: active v2 editor returned an unsupported DOCX save payload")}#re(e,t){const n=EA(e),r=(n?this.config.documents.find(a=>a.id===n):null)??this.config.documents.find(a=>a.type==="application/vnd.openxmlformats-officedocument.wordprocessingml.document");if(!r)return;const o=this.#X(t),i=r.v2Collaboration&&typeof r.v2Collaboration=="object"&&r.v2Collaboration.roomMode==="create"?{...r.v2Collaboration,roomMode:"join"}:null;r.data=o,i&&(r.v2Collaboration=i);const s=this.superdocStore?.documents.find(a=>a.id===r.id)??null;s&&(s.data=o,i&&this.#z(s,i))}#Ae(){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}#Ie(){this.#H(),this.#q(null,null)}#xe(e){const n=e.editor??e;return n.options?.collaborationIsReady?Promise.resolve():new Promise(r=>{let o=!1;const i=()=>{o||(o=!0,clearTimeout(s),typeof n.off=="function"&&n.off("collaborationReady",a))},s=setTimeout(()=>{i(),console.warn("[SuperDoc] collaborationReady did not fire within 10 s after collaboration attach. Continuing β€” collaboration is active but cursor/presence setup may be delayed."),r(void 0)},1e4),a=()=>{i(),r(void 0)};this.#t=()=>{i(),r(void 0)},typeof n.on=="function"?n.on("collaborationReady",a):(i(),r(void 0))})}#Ee(e){return new Promise((n,r)=>{let o,i=!1,s=()=>{};const a=()=>{i=!0,clearTimeout(o),s()};s=lj(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.#t=()=>{i||(a(),r(new Error("SuperDoc: instance was destroyed during upgrade")))}})}#pe(e){if(this.#e)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(c=>c.type===zr);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(!oi(this.#ge()))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=e.v2Collaboration??this.#me(r.v2Collaboration)??i?.v2Collaboration??i?.v2??null,l=qS({v2Collaboration:a,legacyCollaboration:s,documentType:zr,documentCount:t.documents.length,...typeof window<"u"?{authEndpointBaseUrl:window.location.href}:{}});if(!l.ok)throw new Error(`SuperDoc: upgradeToCollaboration() ${l.reason}: ${l.message}`);return{target:l.target}}#me(e){return e&&typeof e=="object"&&"value"in e?e.value:e}#ge(){const e=this.config.documents.find(n=>n.type===zr),t=this.#m("upgradeToCollaboration").documents.find(n=>n.id===e.id)?.getEditor?.();if(!t)throw new Error("SuperDoc: source editor not yet created β€” wait for the ready event before upgrading");return t}addSharedUser(e){this.#R("addSharedUser");const t=Qc({actor:e});t&&this.users.some(n=>Qc({actor:n})===t)||this.users.push(e)}removeSharedUser(e){this.#R("removeSharedUser");const t=typeof e=="string"?qv(e):"",n=typeof e=="string"?`email:${t}`:Qc({actor:e});this.users=this.users.filter(r=>{const o=Qc({actor:r});return n?o!==n:t?qv(r.email)!==t:!0})}onContentError({error:e,editor:t}){const n=t.options?.documentId,r=this.#m("onContentError").documents.find(i=>i.id===n),o=typeof r?.id=="string"?r.id:typeof n=="string"?n:"";this.config.onContentError?.({error:e,editor:t,documentId:o,file:r?.data})}broadcastPdfDocumentReady(){this.emit("pdf:document-ready")}broadcastReady(){this.readyEditors===this.requiredNumberOfEditors&&this.emit("ready",{superdoc:this})}broadcastEditorBeforeCreate(e){this.emit("editorBeforeCreate",{editor:R4(e)})}broadcastEditorCreate(e){this.readyEditors++,this.broadcastReady(),this.#ve(e),this.emit("editorCreate",{editor:R4(e)})}broadcastSourceComplete(){this.emit("source:complete")}broadcastSourceSignalsComplete(){this.emit("source:signals-complete")}#Z;#ve(e){if(!e||typeof e.on!="function"||this.#Z.has(e))return;this.#Z.add(e),e.on("fonts-changed",n=>{this.#oe(e)&&this.#V(n)});const t=(e.documentRenderer??e.presentationEditor)?.getLastFontsChangedPayload?.();t&&this.#oe(e)&&this.#V(t)}#oe(e){return!this.activeEditor||e===this.activeEditor}#Q;#V(e){this.#Q=e,this.emit("fonts-changed",e)}broadcastEditorDestroy(){this.emit("editorDestroy")}broadcastSidebarToggle(e){this.emit("sidebar-toggle",e)}#ye(){Array.isArray(this.config.editorExtensions)&&this.config.editorExtensions.length>0&&console.warn("[SuperDoc] `editorExtensions` is a legacy ProseMirror concept and is ignored by superdoc@2. Use `extensions` with `defineSuperDocExtension`; legacy ProseMirror extensions (Node.create, Mark.create, addPmPlugins, custom schema) do not run in v2.")}#C(...e){(console.debug?console.debug:console.log)("πŸ¦‹ πŸ¦Έβ€β™€οΈ [superdoc]",...e)}#j;get fonts(){return this.#j||(this.#j={getReport:()=>ls(this.activeEditor)?.getReport()??[],getMissingFonts:()=>ls(this.activeEditor)?.getMissingFonts()??[],getDocumentFontOptions:()=>ls(this.activeEditor)?.getDocumentFontOptions()??[],getFontFamilyOptions:()=>ls(this.activeEditor)?.getFontFamilyOptions()??[],getDocumentFonts:()=>ls(this.activeEditor)?.getDocumentFonts()??[],onReport:e=>{const t=this.activeEditor,n=t?ls(t)?.getLastFontsChangedPayload?.()??null:this.#Q??null;return n&&e(n),this.on("fonts-changed",e),()=>this.off("fonts-changed",e)},map:e=>{const t=ls(this.activeEditor);if(!t)throw new Error("superdoc.fonts.map requires an active editor");t.map(e)},unmap:e=>{const t=ls(this.activeEditor);if(!t)throw new Error("superdoc.fonts.unmap requires an active editor");t.unmap(e)},add:e=>{const t=ls(this.activeEditor);if(!t)throw new Error("superdoc.fonts.add requires an active editor");t.add(e)},preload:e=>{const t=ls(this.activeEditor);if(!t)throw new Error("superdoc.fonts.preload requires an active editor");return t.preload(e)}}),this.#j}#U(){const e=this.activeEditor!==null;this.#ie(),this.activeEditor=null,this.toolbar?.setActiveEditor?this.toolbar.setActiveEditor(null):this.toolbar&&(this.toolbar.activeEditor=null),e&&this.emit("active-editor-change")}#M;#ie(){if(this.#M){try{this.#M()}catch{}this.#M=null}}#be(e){this.#ie();const t=ls(e);if(!t?.onChanged)return;const n=t.getLastFontsChangedPayload?.();n&&this.#V(n),this.#M=t.onChanged(r=>this.#V(r))}#we(e,t){this.#w=!0;try{if(e===null){this.#U();return}this.#u.get(e)?.kind==="v2"&&oi(t)?this.#se(t):this.#U()}finally{this.#w=!1}}#se(e){if(oi(e)){!this.#w&&this.#u.getActive()&&this.#u.setActive(null,"set-active-v2-facade");const t=this.activeEditor;this.activeEditor=e,this.#be(e),this.toolbar?.setActiveEditor?.(e),t!==this.activeEditor&&this.emit("active-editor-change");return}this.#U()}setActiveEditor(e){this.#se(e)}getV2FeatureMatrix(){return[{feature:"source.docx-bytes",status:"supported",reason:"SuperDoc normalizes File/Blob/ArrayBuffer/Uint8Array DOCX inputs for the separate DOCX Engine dependency"},{feature:"source.url",status:"supported",reason:"shell-owned source normalization resolves URL-backed DOCX inputs before opening the injected v2 editor"},{feature:"source.blank",status:"supported",reason:"shell-owned blank-document seeding resolves to DOCX bytes before mounting the injected v2 editor"},{feature:"execution.browser-worker",status:"supported",reason:"the shipped public v2 shell opens DOCX documents through the browser-worker path by default when collaboration is not active"},{feature:"distribution.cdn-iife",status:"supported",reason:"the CDN/IIFE distribution ships the public bundle plus the emitted v2 browser-worker asset and opens DOCX documents through the worker-backed v2 runtime"},{feature:"docx.open-render",status:"supported",reason:"superdoc@2 opens and renders DOCX documents through its DOCX Engine dependency"},{feature:"docx.review-handles",status:"supported",reason:"Comment/tracked-change list + decide via v2 host handles"},{feature:"shell.toolbar",status:"supported",reason:"new SuperDoc({ toolbar }) mounts the rendered built-in toolbar shell and the superdoc.toolbar handle, both backed by the V2 command controller and the internal compatibility catalog. Explicit item-level limits stay fail-closed in the shared command matrix (for example search replace and copyFormat)."},{feature:"shell.rich-formatting",status:"supported",reason:"Rich inline, paragraph, and list formatting route through the V2 command controller and public Document API (format.* / styles.* / lists.*): bold, italic, underline, strikethrough, font family/size, text/highlight color, alignment, line spacing, linked styles, bullet/numbered lists, indent, and clear formatting."},{feature:"shell.comments-sidebar",status:"supported",reason:"ui-phase3-002: v2 comments adapter routes create/reply/edit/resolve/delete through V2EditorHost.dispatch"},{feature:"shell.comments-sidebar.reopen",status:"supported",reason:'ui-phase3-002: v2 comments sidebar reopens resolved threads through the v2 comments adapter (activeEditor.doc.comments.patch({ status: "active" }))'},{feature:"shell.tracked-change-sidebar",status:"supported",reason:"SD-3722: v2 tracked-change adapter lists and decides exact body, header/footer-part, and note targets"},{feature:"shell.tracked-change-sidebar.bulk",status:"supported",reason:"SD-4039/SD-4040: the shipped v2 command posture exposes all-story Accept All and Reject All through the canonical doc.trackChanges.decide({ target: { kind: 'all' } }) mutation"},{feature:"shell.tracked-change-sidebar.non-body",status:"supported",reason:"SD-3722: public v2 shell hydrates and targets header/footer-part and note tracked changes"},{feature:"shell.comments-sidebar.persistence",status:"supported",reason:"ui-phase3-004: comment create/reply/edit/resolve/delete persist through SuperDoc.export() β†’ re-mount via the v2 host save bridge"},{feature:"shell.tracked-change-sidebar.persistence",status:"supported",reason:"ui-phase3-004: tracked-change accept/reject persist through SuperDoc.export() β†’ re-mount via the v2 host save bridge"},{feature:"shell.comments-sidebar.author-required",status:"supported",reason:"ui-phase3-004: v2 comments adapter surfaces commentCommandsReason=author-required from the host capability matrix; write controls disable and forced dispatch reports ok:false"},{feature:"shell.find-replace",status:"supported",reason:"Ctrl/Cmd+F opens the SuperDoc find/replace surface in v2; find/navigation/replace/replaceAll route through the single host search session (host.search) via ui.search, with replace failing closed in viewing/read-only mode"},{feature:"shell.ai-writer",status:"supported",reason:"built-in toolbar renders the modules.ai-gated AI writer and applies generated text through the public Document API facade"},{feature:"shell.collaboration",status:"supported",reason:"v2 single-doc y-websocket collaboration is wired through document.v2Collaboration, including collaboration-ready, awareness-update, and locked event bridges; arbitrary external { ydoc, provider } adapters remain unsupported"},{feature:"shell.context-menu",status:"supported",reason:"v2 renders the built-in right-click and slash context menu, forwards ui.contextMenu custom items, and honors ui.contextMenu: false for application-owned replacements"},{feature:"shell.page-metrics",status:"supported",reason:"ui-phase4-001: v2 page metrics snapshot (editorVersion: 2, documentId, renderEpoch, layoutGeneration, zoom, pages[], capabilities) available via superdoc.activeEditor.pageMetrics.{ getSnapshot, subscribe, setZoom, scrollToPage, revealBodyTarget, pageIndexForBodyTarget }"},{feature:"shell.zoom",status:"supported",reason:"ui-phase4-001: SuperDoc.setZoom routes to V2EditorHost.setZoom in v2 mode; single CSS-transform wrapper applies scale to the painted document, page metrics viewport coords scale with the same zoom value"},{feature:"shell.ruler-page-margins",status:"supported",reason:"ui-phase4-002: v2 ruler renders against the V2PageMetricsSnapshot and dispatches margin drags through a narrow v2 page-layout bridge (`activeEditor.pageLayout.setMargins(...)`) backed by `doc.sections.setPageMargins(...)`. The v2 page metrics snapshot now reports `capabilities.marginEdit = { supported: true }`"},{feature:"shell.custom-extensions",status:"supported",reason:"superdoc@2 supports customer extensions through `extensions` + `defineSuperDocExtension`; command execution and diagnostics are exposed through the narrow `activeEditor.extensions` facet. Legacy ProseMirror `editorExtensions` are ignored in v2."},{feature:"pdf.viewer",status:"supported",reason:"editorVersion ignored for PDF documents"},{feature:"html.viewer",status:"supported",reason:"editorVersion ignored for HTML documents"}]}get v2(){return this.editorVersion!==2?null:{version:2,featureMatrix:this.getV2FeatureMatrix()}}registerEditorRuntime(e){this.#u.register(e)}unregisterEditorRuntime(e){return this.#u.unregister(e)}getActiveRuntime(){return this.#u.getActive()}setActiveRuntime(e,t){this.#u.setActive(e,t)}resolveRuntimeFromEventTarget(e){return this.#u.resolveFromEventTarget(e)}activateRuntimeFromEventTarget(e,t){const n=this.#u.resolveFromEventTarget(e);return n?(this.#u.setActive(n.id,t),!0):!1}toggleRuler(){const e=this.#m("toggleRuler");this.config.rulers=!this.config.rulers,e.documents.forEach(t=>{t.rulers=this.config.rulers}),this.toolbar?.updateToolbarState?.()}canPerformPermission({permission:e,role:t=this.config.role,isInternal:n=this.config.isInternal,comment:r=null,trackedChange:o=null}={}){if(!e)return!1;let i=r??o?.comment??null;const s=o?.commentId||o?.id;if(!i&&s&&this.commentsStore?.getComment){const l=this.commentsStore.getComment(s),c=l?.getValues;i=typeof c=="function"?c.call(l):l}const a={superdoc:this,currentUser:this.config.user,comment:i??null,trackedChange:o??null};return ba(e,t,n,a)}#Ce(){const e=this.config.modules?.toolbar,t=e&&typeof e=="object"?e:{},n=this.#p.toolbar;this.toolbarElement=n.container??void 0;const r=this.config.ui,o=typeof r=="object"&&r!==null&&r.toolbar!==void 0;if(!(n.enabled&&(n.container||e===!0||e!=null&&typeof e=="object"||o))){this.toolbar=null;return}try{this.toolbar=Kz({...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"||(this.commentsList?.close(),e&&(this.config.modules.comments.element=e),this.commentsList=new $R(this.config.modules?.comments,this),this.config.onCommentsListChange&&this.config.onCommentsListChange({isRendered:!0}),this.emit("comments-list-change",{isRendered:!0}))}removeCommentsList(){this.commentsList&&(this.commentsList.close(),this.commentsList=null,this.config.onCommentsListChange&&this.config.onCommentsListChange({isRendered:!1}),this.emit("comments-list-change",{isRendered:!1}))}scrollToComment(e,t={}){if(!this.config?.modules?.comments||!e||typeof e!="string")return!1;const n=this.element||document,r=globalThis.CSS?.escape?globalThis.CSS.escape(e):e.replace(/"/g,'\\"'),o=n.querySelector(`[data-comment-ids*="${r}"]`);if(!o)return!1;const{behavior:i="smooth",block:s="start"}=t??{};return o.scrollIntoView({behavior:i,block:s}),this.commentsStore?.setActiveComment?.(this,e),!0}async navigateTo(e){const t=this.superdocStore?.documents;if(!t?.length)return!1;const n=t[0].getDocumentRuntime?.();return n?.navigateTo?n.navigateTo(e):!1}async scrollToElement(e){const t=this.superdocStore?.documents;if(!t?.length)return!1;const n=t[0].getDocumentRuntime?.();return n?.scrollToElement?n.scrollToElement(e):!1}setDisableContextMenu(e=!0){if(!e&&this.#p.contextMenu.suppressed)return;const t=!!e;this.config.disableContextMenu!==t&&(this.config.disableContextMenu=t,this.superdocStore?.documents?.forEach(n=>{const r=n.getDocumentRuntime?.();r?.setContextMenuDisabled&&r.setContextMenuDisabled(t);const o=n.getEditor?.();o?.setOptions&&o.setOptions({disableContextMenu:t})}))}setShowBookmarks(e=!0){const t=!!e,n=this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};n.showBookmarks!==t&&(n.showBookmarks=t,this.superdocStore?.documents?.forEach(r=>{r.getDocumentRuntime?.()?.setShowBookmarks?.(t)}))}setShowFormattingMarks(e=!0){const t=!!e,n=this.config.layoutEngineOptions=this.config.layoutEngineOptions||{};n.showFormattingMarks!==t&&(n.showFormattingMarks=t,this.superdocStore?.documents?.forEach(r=>{r.getDocumentRuntime?.()?.setShowFormattingMarks?.(t)}),this.emit("formatting-marks-change",{showFormattingMarks:t,superdoc:this}),this.toolbar?.updateToolbarState?.())}toggleFormattingMarks(){const e=!!this.config.layoutEngineOptions?.showFormattingMarks;this.setShowFormattingMarks(!e)}setDocumentMode(e){if(!e)return;this.#R("setDocumentMode"),e=e.toLowerCase(),this.config.documentMode=e,this.#ce();const t={viewing:()=>this.#le(),editing:()=>this.#ke(),suggesting:()=>this.#ae()};t[e]&&(t[e](),this.emit("document-mode-change",{documentMode:e}))}#J(e,t){const n=typeof e.id=="string"&&e.id.length>0?e.id:null;if(n){const i=this.#u.getAllByDocumentId(n);if(i.length>0){for(const s of i)s.setDocumentMode(t);return}}const r=typeof e.getDocumentRuntime=="function"?e.getDocumentRuntime():null;if(typeof r?.setDocumentMode=="function"){r.setDocumentMode(t);return}const o=typeof e.getEditor=="function"?e.getEditor():null;o&&typeof o.setDocumentMode=="function"&&o.setDocumentMode(t)}setTrackedChangesPreferences(e){const t=e&&Object.keys(e).length?{...e}:void 0;this.config.layoutEngineOptions||(this.config.layoutEngineOptions={}),this.config.layoutEngineOptions.trackedChanges=t,this.superdocStore?.documents?.forEach(n=>{const r=typeof n.getDocumentRuntime=="function"?n.getDocumentRuntime():null;r?.setTrackedChangesOverrides&&r.setTrackedChangesOverrides(t)})}#ke(){if(this.config.role!=="editor")return this.#ae();const e=this.#m("setDocumentMode");if(e.documents.length>0){const t=e.documents[0]?.getEditor();t&&this.setActiveEditor(t)}this.setTrackedChangesPreferences({mode:"review",enabled:!0}),e.documents.forEach(t=>{t.restoreComments?.(),this.#J(t,"editing")})}#ae(){if(!["editor","suggester"].includes(this.config.role??""))return this.#le();const e=this.#m("setDocumentMode");if(e.documents.length>0){const t=e.documents[0]?.getEditor();t&&this.setActiveEditor(t)}this.setTrackedChangesPreferences({mode:"review",enabled:!0}),e.documents.forEach(t=>{t.restoreComments?.(),this.#J(t,"suggesting")})}#le(){const e=this.#m("setDocumentMode");this.toolbar?.setActiveEditor?this.toolbar.setActiveEditor(null):this.toolbar&&(this.toolbar.activeEditor=null);const t=this.config.comments?.visible===!0,n=this.config.trackChanges?.visible===!0;this.setTrackedChangesPreferences(n?{mode:"review",enabled:!0}:{mode:"original",enabled:!0}),!t&&!n&&this.commentsStore?.clearEditorCommentPositions?.(),e.documents.forEach(r=>{t||n?r.restoreComments?.():r.removeComments?.(),this.#J(r,"viewing")})}#ce(){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=Rk(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(oi(t)&&typeof t.lock?.setLocked=="function"){t.lock.setLocked(e,e?{...this.user}:null);const n=t.lock.getSnapshot?.();n&&this.#v(!!n.isLocked,this.#F(n.lockedBy??null));return}this.config.documents.forEach(n=>{const r=n.ydoc;if(!r)return;const o=r.getMap("meta");r.transact(()=>{o.set("locked",e),e?o.set("lockedBy",this.user):o.delete("lockedBy")})}),this.#v(e,e?this.user:null)}getHTML(e={}){const t=[];return this.#m("getHTML").documents.forEach(n=>{const r=n.getEditor?.();r&&t.push(r)}),t.map(n=>n.getHTML(e))}lockSuperdoc(e=!1,t=null){this.#v(e,t)}async export({exportType:e=["docx"],commentsType:t="external",exportedName:n,additionalFiles:r=[],additionalFileNames:o=[],isFinalDoc:i=!1,triggerDownload:s=!0,fieldsHighlightColor:a=null}={}){const l=y_(n||this.config.title),c=await this.exportEditorsToDOCX({commentsType:t,isFinalDoc:i,fieldsHighlightColor:a}),d=[...r],f=[...o];if(e.includes("docx")&&c.forEach(g=>{d.push(g),f.push(`${l}.docx`)}),d.length===1)return s?v_(d[0],l,e[0]):d[0];const h=await aj(d,f);return s?v_(h,l,"zip"):h}async replaceFile(e){const t=this.activeEditor;if(oi(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.#re(t,e),this.emit("document-replaced",{editor:t,host:t?.host})),r}const n=t&&!oi(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.#re(t,e),this.emit("document-replaced",{editor:t,host:t?.host})),r}throw new Error("SuperDoc: replaceFile is unavailable for the active editor")}async exportEditorsToDOCX({commentsType:e,isFinalDoc:t,fieldsHighlightColor:n}={}){const r=this.config?.modules?.comments!==!1;let o,i=!1;const s=()=>(i||(i=!0,e==="clean"?o=[]:r&&this.commentsStore&&typeof this.commentsStore.translateCommentsForExport=="function"&&(o=this.commentsStore.translateCommentsForExport(),Array.isArray(o)||(o=[]))),o),a=new WeakSet,l=c=>{"editor"in c&&c.error&&typeof c.error=="object"&&a.add(c.error)};this.on("exception",l);try{const c=this.#m("exportEditorsToDOCX").documents.map(async d=>{if(!d||d.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")return null;const f=typeof d.getEditor=="function"?d.getEditor():null,h=()=>!d.data||d.data.type&&d.data.type!=="application/vnd.openxmlformats-officedocument.wordprocessingml.document"?null:d.data;if(!f||typeof f.exportDocx!="function")return h();const g=f.editorVersion===2;try{const m=await f.exportDocx(g?{isFinalDoc:t,commentsType:e,fieldsHighlightColor:n}:{isFinalDoc:t,comments:s(),commentsType:e,fieldsHighlightColor:n});if(m)return m}catch(m){if((!m||typeof m!="object"||!a.has(m))&&this.emit("exception",{error:m,document:d}),g&&(e==="clean"||fj(m)))throw m}return h()});return(await Promise.all(c)).filter(d=>d!=null)}finally{this.off("exception",l)}}async#Se(){this.#C("πŸ¦‹ [superdoc] Triggering collaboration saves");const e=this.#m("save");return new Promise(t=>{e.documents.forEach((n,r)=>{if(this.#C(`Before reset - Doc ${r}: pending = ${this.pendingCollaborationSaves}`),this.pendingCollaborationSaves=0,n.ydoc){this.pendingCollaborationSaves++,this.#C(`After increment - Doc ${r}: pending = ${this.pendingCollaborationSaves}`);const o=n.ydoc.getMap("meta");o.observe(i=>{i.changes.keys.has("immediate-save-finished")&&(this.pendingCollaborationSaves--,this.pendingCollaborationSaves<=0&&t())}),o.set("immediate-save",!0)}}),this.#C(`FINAL pending = ${this.pendingCollaborationSaves}, but we have ${e.documents.filter(n=>n.ydoc).length} docs!`)})}async save(){const e=[this.#Se()];this.#C("πŸ¦‹ [superdoc] Saving superdoc"),await Promise.all(e),this.#C("πŸ¦‹ [superdoc] Save complete")}#_e(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?.()}#ue(){this.#s=null,this.#A(),typeof this._cleanupAwareness=="function"&&(this._cleanupAwareness(),this._cleanupAwareness=null);const e=this.config;e.socket?.cancelWebsocketRetry?.(),e.socket?.disconnect(),e.socket?.destroy(),this.ydoc?.destroy(),this.provider?.disconnect?.(),this.provider?.destroy?.(),e.documents.forEach(t=>{t.provider?.disconnect?.(),t.provider?.destroy?.(),t.ydoc?.destroy()})}openSurface(e){return this.#g.open(e)}closeSurface(e){this.#g.close(e)}async removeDocument(e){const t=typeof e=="string"?e:String(e??"");if(!t)return!1;const n=this.#m("removeDocument"),r=this.activeEditor,o=EA(r);for(const s of this.#u.getAllByDocumentId(t))this.#u.unregister(s.id);o===t&&r!==null&&this.#U();const i=n.removeDocument(t);return i?(this.#_e(i,n.documents),await At(),!0):!1}destroy(){this.#e=!0,this.#h?.removeEventListener("click",this.#f,!0),this.#h=null,this.#t&&(this.#t(),this.#t=null),this.#g&&this.#g.destroy(),this.toolbar?.destroy?.(),this.commentsList?.close(),this.commentsList=null,this.app&&(this.#C("[superdoc] Unmounting app"),this.superdocStore?.reset(),this.app.unmount(),this.removeAllListeners(),delete this.app.config.globalProperties.$config,delete this.app.config.globalProperties.$superdoc),this.#c?.destroy(),this.#ue(),this.#y?.(),this.#y=null,this.#u.clear(),this.#d&&(this.#d.remove(),this.#d=null)}focus(e={}){const t=this.getActiveRuntime();if(t?.getCapabilities().lifecycle.canFocus){t.focus(e).catch(n=>{console.warn("[SuperDoc] active editor runtime focus failed",n)});return}this.activeEditor?oi(this.activeEditor)?this.activeEditor.focus?.(e):this.activeEditor.focus?.():this.#m("focus").documents.find(n=>{const r=n.getEditor?.();return r?(oi(r)?r.focus?.(e):r.focus?.(),!0):!1})}setHighContrastMode(e){this.activeEditor&&(this.activeEditor.setHighContrastMode?.(e),this.highContrastModeStore?.setHighContrastMode(e))}};xt();var TA="__SUPERDOC_V2_BROWSER_RUNTIME__";function pj(e=globalThis){const t=e[TA];return t&&typeof t=="object"?t:null}function mj(e={},t=globalThis){const n=pj(t)??{},r={...n,...e,vue:e.vue??n.vue??p6};return t[TA]=r,r}mj();var gj={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"},vj=0;function RA(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-${++vj}`}`,l=[];if(i)for(const[c,d]of Object.entries(i)){if(d==null)continue;const f=gj[c];f&&l.push(` ${f}: ${d};`)}if(n!=null&&l.push(` --sd-ui-font-family: ${n};`),r!=null&&l.push(` --sd-ui-radius: ${r};`),o!=null&&l.push(` --sd-ui-shadow: ${o};`),s)for(const[c,d]of Object.entries(s))d!=null&&l.push(` ${c}: ${d};`);return{className:a,css:l.length>0?`.${a} {
106
106
  ${l.join(`
107
107
  `)}
108
- }`:""}}function yj(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 bj(e){const{className:t,css:n}=RA(e);return yj(t,n),t}function wj(e){return RA(e)}function Cj(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 kj=td({BlankDOCX:()=>sk,DOCX:()=>zr,HTML:()=>Yh,PDF:()=>ec,SuperDoc:()=>bm,buildTheme:()=>wj,compareVersions:()=>k6,createTheme:()=>bj,defineSuperDocExtension:()=>Cj,getFileObject:()=>Yv}),Sj="SUPERDOC_ENGINE_CDN_BASE_URL",MA=Symbol.for("superdoc.docx-engine.cdn-load-state"),wm="superdocDocxEngineStatus";function _j(e,t,n=null){const r=e?.[Sj],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return Aj(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 Aj(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 Ij({engineVersion:e,buildBaseUrl:t}){m8(()=>{const n=_j(globalThis,e,t),r=globalThis[MA],o=r instanceof Map?r:new Map;if(globalThis[MA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),xj(`${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 xj(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[wm]==="loaded")return Promise.resolve();const r=n?.dataset[wm]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const c=(g,m)=>{a||(a=!0,l?.disconnect(),s.dataset[wm]=g,m())},d=()=>c("loaded",o),f=()=>c("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||c("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",d,{once:!0}),s.addEventListener("error",f,{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[wm]="loading",document.head.appendChild(s))})}Ij({engineVersion:"0.6.0",buildBaseUrl:null});for(const[e,t]of Object.entries(kj))e==="SuperDoc"||e==="default"||Object.prototype.hasOwnProperty.call(bm,e)||(bm[e]=t);var Ej=bm;return Ej})();
108
+ }`:""}}function yj(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 bj(e){const{className:t,css:n}=RA(e);return yj(t,n),t}function wj(e){return RA(e)}function Cj(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 kj=td({BlankDOCX:()=>sk,DOCX:()=>zr,HTML:()=>Yh,PDF:()=>ec,SuperDoc:()=>bm,buildTheme:()=>wj,compareVersions:()=>k6,createTheme:()=>bj,defineSuperDocExtension:()=>Cj,getFileObject:()=>Yv}),Sj="SUPERDOC_ENGINE_CDN_BASE_URL",MA=Symbol.for("superdoc.docx-engine.cdn-load-state"),wm="superdocDocxEngineStatus";function _j(e,t,n=null){const r=e?.[Sj],o=typeof r=="string"&&r.trim()?r:n;if(typeof o=="string"&&o.trim())return Aj(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 Aj(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 Ij({engineVersion:e,buildBaseUrl:t}){m8(()=>{const n=_j(globalThis,e,t),r=globalThis[MA],o=r instanceof Map?r:new Map;if(globalThis[MA]=o,!o.has(n)){const i=Promise.all([import(`${n}/dist-cdn/docx-engine.es.js`),xj(`${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 xj(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[wm]==="loaded")return Promise.resolve();const r=n?.dataset[wm]==="loading";return n&&!r&&n.remove(),new Promise((o,i)=>{const s=r?n:document.createElement("link");let a=!1,l;const c=(g,m)=>{a||(a=!0,l?.disconnect(),s.dataset[wm]=g,m())},d=()=>c("loaded",o),f=()=>c("error",()=>i(new Error(`SuperDoc: failed to load DOCX Engine styles from ${t}`))),h=()=>{s.isConnected||c("error",()=>i(new Error(`SuperDoc: DOCX Engine stylesheet was removed while loading from ${t}`)))};s.addEventListener("load",d,{once:!0}),s.addEventListener("error",f,{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[wm]="loading",document.head.appendChild(s))})}Ij({engineVersion:"0.6.1-next.1",buildBaseUrl:null});for(const[e,t]of Object.entries(kj))e==="SuperDoc"||e==="default"||Object.prototype.hasOwnProperty.call(bm,e)||(bm[e]=t);var Ej=bm;return Ej})();