@woven-canvas/vue 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +9730 -20845
- package/build/index.umd.cjs +28 -96
- package/package.json +4 -4
package/build/index.umd.cjs
CHANGED
|
@@ -1,84 +1,16 @@
|
|
|
1
|
-
(function(P,at){typeof exports=="object"&&typeof module<"u"?at(exports,require("@woven-ecs/canvas-store"),require("@woven-canvas/core"),require("@woven-canvas/math"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@woven-ecs/canvas-store","@woven-canvas/core","@woven-canvas/math","vue"],at):(P=typeof globalThis<"u"?globalThis:P||self,at(P.Vue={},P.WovenEcsCanvasStore,P.WovenCanvasCore,P.WovenCanvasMath,P.Vue))})(this,function(P,at,h,E,d){"use strict";var le;(function(t){t.assertEqual=o=>o;function e(o){}t.assertIs=e;function n(o){throw new Error}t.assertNever=n,t.arrayToEnum=o=>{const s={};for(const i of o)s[i]=i;return s},t.getValidEnumValues=o=>{const s=t.objectKeys(o).filter(a=>typeof o[o[a]]!="number"),i={};for(const a of s)i[a]=o[a];return t.objectValues(i)},t.objectValues=o=>t.objectKeys(o).map(function(s){return o[s]}),t.objectKeys=typeof Object.keys=="function"?o=>Object.keys(o):o=>{const s=[];for(const i in o)Object.prototype.hasOwnProperty.call(o,i)&&s.push(i);return s},t.find=(o,s)=>{for(const i of o)if(s(i))return i},t.isInteger=typeof Number.isInteger=="function"?o=>Number.isInteger(o):o=>typeof o=="number"&&isFinite(o)&&Math.floor(o)===o;function r(o,s=" | "){return o.map(i=>typeof i=="string"?`'${i}'`:i).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(o,s)=>typeof s=="bigint"?s.toString():s})(le||(le={}));var Wa;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Wa||(Wa={}));const F=le.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),en=t=>{switch(typeof t){case"undefined":return F.undefined;case"string":return F.string;case"number":return isNaN(t)?F.nan:F.number;case"boolean":return F.boolean;case"function":return F.function;case"bigint":return F.bigint;case"symbol":return F.symbol;case"object":return Array.isArray(t)?F.array:t===null?F.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?F.promise:typeof Map<"u"&&t instanceof Map?F.map:typeof Set<"u"&&t instanceof Set?F.set:typeof Date<"u"&&t instanceof Date?F.date:F.object;default:return F.unknown}},O=le.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Gk=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class lt extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(s){return s.message},r={_errors:[]},o=s=>{for(const i of s.issues)if(i.code==="invalid_union")i.unionErrors.map(o);else if(i.code==="invalid_return_type")o(i.returnTypeError);else if(i.code==="invalid_arguments")o(i.argumentsError);else if(i.path.length===0)r._errors.push(n(i));else{let a=r,l=0;for(;l<i.path.length;){const c=i.path[l];l===i.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(i))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return o(this),r}static assert(e){if(!(e instanceof lt))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,le.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const o of this.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(e(o))):r.push(e(o));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}lt.create=t=>new lt(t);const $r=(t,e)=>{let n;switch(t.code){case O.invalid_type:t.received===F.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case O.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,le.jsonStringifyReplacer)}`;break;case O.unrecognized_keys:n=`Unrecognized key(s) in object: ${le.joinValues(t.keys,", ")}`;break;case O.invalid_union:n="Invalid input";break;case O.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${le.joinValues(t.options)}`;break;case O.invalid_enum_value:n=`Invalid enum value. Expected ${le.joinValues(t.options)}, received '${t.received}'`;break;case O.invalid_arguments:n="Invalid function arguments";break;case O.invalid_return_type:n="Invalid function return type";break;case O.invalid_date:n="Invalid date";break;case O.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:le.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case O.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case O.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case O.custom:n="Invalid input";break;case O.invalid_intersection_types:n="Intersection results could not be merged";break;case O.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case O.not_finite:n="Number must be finite";break;default:n=e.defaultError,le.assertNever(t)}return{message:n}};let uu=$r;function Yk(t){uu=t}function Vs(){return uu}const Ls=t=>{const{data:e,path:n,errorMaps:r,issueData:o}=t,s=[...n,...o.path||[]],i={...o,path:s};if(o.message!==void 0)return{...o,path:s,message:o.message};let a="";const l=r.filter(c=>!!c).slice().reverse();for(const c of l)a=c(i,{data:e,defaultError:a}).message;return{...o,path:s,message:a}},Xk=[];function z(t,e){const n=Vs(),r=Ls({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===$r?void 0:$r].filter(o=>!!o)});t.common.issues.push(r)}class Ue{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const o of n){if(o.status==="aborted")return ee;o.status==="dirty"&&e.dirty(),r.push(o.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const o of n){const s=await o.key,i=await o.value;r.push({key:s,value:i})}return Ue.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const o of n){const{key:s,value:i}=o;if(s.status==="aborted"||i.status==="aborted")return ee;s.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof i.value<"u"||o.alwaysSet)&&(r[s.value]=i.value)}return{status:e.value,value:r}}}const ee=Object.freeze({status:"aborted"}),Vr=t=>({status:"dirty",value:t}),Ge=t=>({status:"valid",value:t}),Za=t=>t.status==="aborted",Ua=t=>t.status==="dirty",Yn=t=>t.status==="valid",_o=t=>typeof Promise<"u"&&t instanceof Promise;function Fs(t,e,n,r){if(typeof e=="function"?t!==e||!0:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(t)}function fu(t,e,n,r,o){if(typeof e=="function"?t!==e||!0:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}typeof SuppressedError=="function"&&SuppressedError;var W;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(W||(W={}));var Eo,To;class Vt{constructor(e,n,r,o){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=o}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const hu=(t,e)=>{if(Yn(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new lt(t.common.issues);return this._error=n,this._error}}};function ne(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:o}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:o}:{errorMap:(i,a)=>{var l,c;const{message:u}=t;return i.code==="invalid_enum_value"?{message:u??a.defaultError}:typeof a.data>"u"?{message:(l=u??r)!==null&&l!==void 0?l:a.defaultError}:i.code!=="invalid_type"?{message:a.defaultError}:{message:(c=u??n)!==null&&c!==void 0?c:a.defaultError}},description:o}}let oe=class{get description(){return this._def.description}_getType(e){return en(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:en(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Ue,ctx:{common:e.parent.common,data:e.data,parsedType:en(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(_o(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){var r;const o={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:en(e)},s=this._parseSync({data:e,path:o.path,parent:o});return hu(o,s)}"~validate"(e){var n,r;const o={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:en(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:o});return Yn(s)?{value:s.value}:{issues:o.common.issues}}catch(s){!((r=(n=s==null?void 0:s.message)===null||n===void 0?void 0:n.toLowerCase())===null||r===void 0)&&r.includes("encountered")&&(this["~standard"].async=!0),o.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:o}).then(s=>Yn(s)?{value:s.value}:{issues:o.common.issues})}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:en(e)},o=this._parse({data:e,path:r.path,parent:r}),s=await(_o(o)?o:Promise.resolve(o));return hu(r,s)}refine(e,n){const r=o=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(o):n;return this._refinement((o,s)=>{const i=e(o),a=()=>s.addIssue({code:O.custom,...r(o)});return typeof Promise<"u"&&i instanceof Promise?i.then(l=>l?!0:(a(),!1)):i?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,o)=>e(r)?!0:(o.addIssue(typeof n=="function"?n(r,o):n),!1))}_refinement(e){return new xt({schema:this,typeName:Q.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Ft.create(this,this._def)}nullable(){return wn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return er.create(this)}promise(){return Hr.create(this,this._def)}or(e){return Oo.create([this,e],this._def)}and(e){return Io.create(this,e,this._def)}transform(e){return new xt({...ne(this._def),schema:this,typeName:Q.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Vo({...ne(this._def),innerType:this,defaultValue:n,typeName:Q.ZodDefault})}brand(){return new qa({typeName:Q.ZodBranded,type:this,...ne(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new Lo({...ne(this._def),innerType:this,catchValue:n,typeName:Q.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Fo.create(this,e)}readonly(){return jo.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}};const Qk=/^c[^\s-]{8,}$/i,ew=/^[0-9a-z]+$/,tw=/^[0-9A-HJKMNP-TV-Z]{26}$/i,nw=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,rw=/^[a-z0-9_-]{21}$/i,ow=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,sw=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,iw=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,aw="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ka;const lw=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,cw=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,dw=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,uw=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fw=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,hw=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,pu="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",pw=new RegExp(`^${pu}$`);function mu(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function mw(t){return new RegExp(`^${mu(t)}$`)}function gu(t){let e=`${pu}T${mu(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function gw(t,e){return!!((e==="v4"||!e)&&lw.test(t)||(e==="v6"||!e)&&dw.test(t))}function yw(t,e){if(!ow.test(t))return!1;try{const[n]=t.split("."),r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),o=JSON.parse(atob(r));return!(typeof o!="object"||o===null||!o.typ||!o.alg||e&&o.alg!==e)}catch{return!1}}function kw(t,e){return!!((e==="v4"||!e)&&cw.test(t)||(e==="v6"||!e)&&uw.test(t))}class Ct extends oe{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==F.string){const s=this._getOrReturnCtx(e);return z(s,{code:O.invalid_type,expected:F.string,received:s.parsedType}),ee}const r=new Ue;let o;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(o=this._getOrReturnCtx(e,o),z(o,{code:O.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")e.data.length>s.value&&(o=this._getOrReturnCtx(e,o),z(o,{code:O.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const i=e.data.length>s.value,a=e.data.length<s.value;(i||a)&&(o=this._getOrReturnCtx(e,o),i?z(o,{code:O.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):a&&z(o,{code:O.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")iw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"email",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")Ka||(Ka=new RegExp(aw,"u")),Ka.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"emoji",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")nw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"uuid",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")rw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"nanoid",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")Qk.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"cuid",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")ew.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"cuid2",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")tw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"ulid",code:O.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{o=this._getOrReturnCtx(e,o),z(o,{validation:"url",code:O.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"regex",code:O.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?gu(s).test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?pw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?mw(s).test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{code:O.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?sw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"duration",code:O.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?gw(e.data,s.version)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"ip",code:O.invalid_string,message:s.message}),r.dirty()):s.kind==="jwt"?yw(e.data,s.alg)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"jwt",code:O.invalid_string,message:s.message}),r.dirty()):s.kind==="cidr"?kw(e.data,s.version)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"cidr",code:O.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?fw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"base64",code:O.invalid_string,message:s.message}),r.dirty()):s.kind==="base64url"?hw.test(e.data)||(o=this._getOrReturnCtx(e,o),z(o,{validation:"base64url",code:O.invalid_string,message:s.message}),r.dirty()):le.assertNever(s);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(o=>e.test(o),{validation:n,code:O.invalid_string,...W.errToObj(r)})}_addCheck(e){return new Ct({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...W.errToObj(e)})}url(e){return this._addCheck({kind:"url",...W.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...W.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...W.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...W.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...W.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...W.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...W.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...W.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...W.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...W.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...W.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...W.errToObj(e)})}datetime(e){var n,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(n=e==null?void 0:e.offset)!==null&&n!==void 0?n:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...W.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...W.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...W.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...W.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...W.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...W.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...W.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...W.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...W.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...W.errToObj(n)})}nonempty(e){return this.min(1,W.errToObj(e))}trim(){return new Ct({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Ct({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Ct({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Ct.create=t=>{var e;return new Ct({checks:[],typeName:Q.ZodString,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...ne(t)})};function ww(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,o=n>r?n:r,s=parseInt(t.toFixed(o).replace(".","")),i=parseInt(e.toFixed(o).replace(".",""));return s%i/Math.pow(10,o)}let Mo=class au extends oe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==F.number){const s=this._getOrReturnCtx(e);return z(s,{code:O.invalid_type,expected:F.number,received:s.parsedType}),ee}let r;const o=new Ue;for(const s of this._def.checks)s.kind==="int"?le.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:O.invalid_type,expected:"integer",received:"float",message:s.message}),o.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),o.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),o.dirty()):s.kind==="multipleOf"?ww(e.data,s.value)!==0&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.not_multiple_of,multipleOf:s.value,message:s.message}),o.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),z(r,{code:O.not_finite,message:s.message}),o.dirty()):le.assertNever(s);return{status:o.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,W.toString(n))}gt(e,n){return this.setLimit("min",e,!1,W.toString(n))}lte(e,n){return this.setLimit("max",e,!0,W.toString(n))}lt(e,n){return this.setLimit("max",e,!1,W.toString(n))}setLimit(e,n,r,o){return new au({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:W.toString(o)}]})}_addCheck(e){return new au({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:W.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:W.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:W.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:W.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:W.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:W.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:W.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:W.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:W.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&le.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}};Mo.create=t=>new Mo({checks:[],typeName:Q.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...ne(t)});class kn extends oe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==F.bigint)return this._getInvalidInput(e);let r;const o=new Ue;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),o.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),o.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),z(r,{code:O.not_multiple_of,multipleOf:s.value,message:s.message}),o.dirty()):le.assertNever(s);return{status:o.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return z(n,{code:O.invalid_type,expected:F.bigint,received:n.parsedType}),ee}gte(e,n){return this.setLimit("min",e,!0,W.toString(n))}gt(e,n){return this.setLimit("min",e,!1,W.toString(n))}lte(e,n){return this.setLimit("max",e,!0,W.toString(n))}lt(e,n){return this.setLimit("max",e,!1,W.toString(n))}setLimit(e,n,r,o){return new kn({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:W.toString(o)}]})}_addCheck(e){return new kn({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:W.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:W.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:W.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:W.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:W.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}kn.create=t=>{var e;return new kn({checks:[],typeName:Q.ZodBigInt,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...ne(t)})};class Ao extends oe{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==F.boolean){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.boolean,received:r.parsedType}),ee}return Ge(e.data)}}Ao.create=t=>new Ao({typeName:Q.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...ne(t)});class Xn extends oe{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==F.date){const s=this._getOrReturnCtx(e);return z(s,{code:O.invalid_type,expected:F.date,received:s.parsedType}),ee}if(isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return z(s,{code:O.invalid_date}),ee}const r=new Ue;let o;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(o=this._getOrReturnCtx(e,o),z(o,{code:O.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(o=this._getOrReturnCtx(e,o),z(o,{code:O.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):le.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Xn({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:W.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:W.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}Xn.create=t=>new Xn({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:Q.ZodDate,...ne(t)});class js extends oe{_parse(e){if(this._getType(e)!==F.symbol){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.symbol,received:r.parsedType}),ee}return Ge(e.data)}}js.create=t=>new js({typeName:Q.ZodSymbol,...ne(t)});class No extends oe{_parse(e){if(this._getType(e)!==F.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.undefined,received:r.parsedType}),ee}return Ge(e.data)}}No.create=t=>new No({typeName:Q.ZodUndefined,...ne(t)});class Bo extends oe{_parse(e){if(this._getType(e)!==F.null){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.null,received:r.parsedType}),ee}return Ge(e.data)}}Bo.create=t=>new Bo({typeName:Q.ZodNull,...ne(t)});class Lr extends oe{constructor(){super(...arguments),this._any=!0}_parse(e){return Ge(e.data)}}Lr.create=t=>new Lr({typeName:Q.ZodAny,...ne(t)});let Qn=class extends oe{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ge(e.data)}};Qn.create=t=>new Qn({typeName:Q.ZodUnknown,...ne(t)});let tn=class extends oe{_parse(e){const n=this._getOrReturnCtx(e);return z(n,{code:O.invalid_type,expected:F.never,received:n.parsedType}),ee}};tn.create=t=>new tn({typeName:Q.ZodNever,...ne(t)});class Hs extends oe{_parse(e){if(this._getType(e)!==F.undefined){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.void,received:r.parsedType}),ee}return Ge(e.data)}}Hs.create=t=>new Hs({typeName:Q.ZodVoid,...ne(t)});let er=class Ha extends oe{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),o=this._def;if(n.parsedType!==F.array)return z(n,{code:O.invalid_type,expected:F.array,received:n.parsedType}),ee;if(o.exactLength!==null){const i=n.data.length>o.exactLength.value,a=n.data.length<o.exactLength.value;(i||a)&&(z(n,{code:i?O.too_big:O.too_small,minimum:a?o.exactLength.value:void 0,maximum:i?o.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:o.exactLength.message}),r.dirty())}if(o.minLength!==null&&n.data.length<o.minLength.value&&(z(n,{code:O.too_small,minimum:o.minLength.value,type:"array",inclusive:!0,exact:!1,message:o.minLength.message}),r.dirty()),o.maxLength!==null&&n.data.length>o.maxLength.value&&(z(n,{code:O.too_big,maximum:o.maxLength.value,type:"array",inclusive:!0,exact:!1,message:o.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((i,a)=>o.type._parseAsync(new Vt(n,i,n.path,a)))).then(i=>Ue.mergeArray(r,i));const s=[...n.data].map((i,a)=>o.type._parseSync(new Vt(n,i,n.path,a)));return Ue.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new Ha({...this._def,minLength:{value:e,message:W.toString(n)}})}max(e,n){return new Ha({...this._def,maxLength:{value:e,message:W.toString(n)}})}length(e,n){return new Ha({...this._def,exactLength:{value:e,message:W.toString(n)}})}nonempty(e){return this.min(1,e)}};er.create=(t,e)=>new er({type:t,minLength:null,maxLength:null,exactLength:null,typeName:Q.ZodArray,...ne(e)});function Fr(t){if(t instanceof ft){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=Ft.create(Fr(r))}return new ft({...t._def,shape:()=>e})}else return t instanceof er?new er({...t._def,type:Fr(t.element)}):t instanceof Ft?Ft.create(Fr(t.unwrap())):t instanceof wn?wn.create(Fr(t.unwrap())):t instanceof Lt?Lt.create(t.items.map(e=>Fr(e))):t}let ft=class $t extends oe{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=le.objectKeys(e);return this._cached={shape:e,keys:n}}_parse(e){if(this._getType(e)!==F.object){const c=this._getOrReturnCtx(e);return z(c,{code:O.invalid_type,expected:F.object,received:c.parsedType}),ee}const{status:r,ctx:o}=this._processInputParams(e),{shape:s,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof tn&&this._def.unknownKeys==="strip"))for(const c in o.data)i.includes(c)||a.push(c);const l=[];for(const c of i){const u=s[c],f=o.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new Vt(o,f,o.path,c)),alwaysSet:c in o.data})}if(this._def.catchall instanceof tn){const c=this._def.unknownKeys;if(c==="passthrough")for(const u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:o.data[u]}});else if(c==="strict")a.length>0&&(z(o,{code:O.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const u of a){const f=o.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new Vt(o,f,o.path,u)),alwaysSet:u in o.data})}}return o.common.async?Promise.resolve().then(async()=>{const c=[];for(const u of l){const f=await u.key,p=await u.value;c.push({key:f,value:p,alwaysSet:u.alwaysSet})}return c}).then(c=>Ue.mergeObjectSync(r,c)):Ue.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return W.errToObj,new $t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var o,s,i,a;const l=(i=(s=(o=this._def).errorMap)===null||s===void 0?void 0:s.call(o,n,r).message)!==null&&i!==void 0?i:r.defaultError;return n.code==="unrecognized_keys"?{message:(a=W.errToObj(e).message)!==null&&a!==void 0?a:l}:{message:l}}}:{}})}strip(){return new $t({...this._def,unknownKeys:"strip"})}passthrough(){return new $t({...this._def,unknownKeys:"passthrough"})}extend(e){return new $t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new $t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:Q.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new $t({...this._def,catchall:e})}pick(e){const n={};return le.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new $t({...this._def,shape:()=>n})}omit(e){const n={};return le.objectKeys(this.shape).forEach(r=>{e[r]||(n[r]=this.shape[r])}),new $t({...this._def,shape:()=>n})}deepPartial(){return Fr(this)}partial(e){const n={};return le.objectKeys(this.shape).forEach(r=>{const o=this.shape[r];e&&!e[r]?n[r]=o:n[r]=o.optional()}),new $t({...this._def,shape:()=>n})}required(e){const n={};return le.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof Ft;)s=s._def.innerType;n[r]=s}}),new $t({...this._def,shape:()=>n})}keyof(){return yu(le.objectKeys(this.shape))}};ft.create=(t,e)=>new ft({shape:()=>t,unknownKeys:"strip",catchall:tn.create(),typeName:Q.ZodObject,...ne(e)}),ft.strictCreate=(t,e)=>new ft({shape:()=>t,unknownKeys:"strict",catchall:tn.create(),typeName:Q.ZodObject,...ne(e)}),ft.lazycreate=(t,e)=>new ft({shape:t,unknownKeys:"strip",catchall:tn.create(),typeName:Q.ZodObject,...ne(e)});let Oo=class extends oe{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function o(s){for(const a of s)if(a.result.status==="valid")return a.result;for(const a of s)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const i=s.map(a=>new lt(a.ctx.common.issues));return z(n,{code:O.invalid_union,unionErrors:i}),ee}if(n.common.async)return Promise.all(r.map(async s=>{const i={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(o);{let s;const i=[];for(const l of r){const c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:c}),c.common.issues.length&&i.push(c.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const a=i.map(l=>new lt(l));return z(n,{code:O.invalid_union,unionErrors:a}),ee}}get options(){return this._def.options}};Oo.create=(t,e)=>new Oo({options:t,typeName:Q.ZodUnion,...ne(e)});const nn=t=>t instanceof Ro?nn(t.schema):t instanceof xt?nn(t.innerType()):t instanceof Do?[t.value]:t instanceof zo?t.options:t instanceof $o?le.objectValues(t.enum):t instanceof Vo?nn(t._def.innerType):t instanceof No?[void 0]:t instanceof Bo?[null]:t instanceof Ft?[void 0,...nn(t.unwrap())]:t instanceof wn?[null,...nn(t.unwrap())]:t instanceof qa||t instanceof jo?nn(t.unwrap()):t instanceof Lo?nn(t._def.innerType):[];class Ws extends oe{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==F.object)return z(n,{code:O.invalid_type,expected:F.object,received:n.parsedType}),ee;const r=this.discriminator,o=n.data[r],s=this.optionsMap.get(o);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(z(n,{code:O.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),ee)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){const o=new Map;for(const s of n){const i=nn(s.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const a of i){if(o.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);o.set(a,s)}}return new Ws({typeName:Q.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:o,...ne(r)})}}function Ja(t,e){const n=en(t),r=en(e);if(t===e)return{valid:!0,data:t};if(n===F.object&&r===F.object){const o=le.objectKeys(e),s=le.objectKeys(t).filter(a=>o.indexOf(a)!==-1),i={...t,...e};for(const a of s){const l=Ja(t[a],e[a]);if(!l.valid)return{valid:!1};i[a]=l.data}return{valid:!0,data:i}}else if(n===F.array&&r===F.array){if(t.length!==e.length)return{valid:!1};const o=[];for(let s=0;s<t.length;s++){const i=t[s],a=e[s],l=Ja(i,a);if(!l.valid)return{valid:!1};o.push(l.data)}return{valid:!0,data:o}}else return n===F.date&&r===F.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}let Io=class extends oe{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),o=(s,i)=>{if(Za(s)||Za(i))return ee;const a=Ja(s.value,i.value);return a.valid?((Ua(s)||Ua(i))&&n.dirty(),{status:n.value,value:a.data}):(z(r,{code:O.invalid_intersection_types}),ee)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,i])=>o(s,i)):o(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}};Io.create=(t,e,n)=>new Io({left:t,right:e,typeName:Q.ZodIntersection,...ne(n)});class Lt extends oe{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==F.array)return z(r,{code:O.invalid_type,expected:F.array,received:r.parsedType}),ee;if(r.data.length<this._def.items.length)return z(r,{code:O.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),ee;!this._def.rest&&r.data.length>this._def.items.length&&(z(r,{code:O.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((i,a)=>{const l=this._def.items[a]||this._def.rest;return l?l._parse(new Vt(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(s).then(i=>Ue.mergeArray(n,i)):Ue.mergeArray(n,s)}get items(){return this._def.items}rest(e){return new Lt({...this._def,rest:e})}}Lt.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Lt({items:t,typeName:Q.ZodTuple,rest:null,...ne(e)})};class Po extends oe{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==F.object)return z(r,{code:O.invalid_type,expected:F.object,received:r.parsedType}),ee;const o=[],s=this._def.keyType,i=this._def.valueType;for(const a in r.data)o.push({key:s._parse(new Vt(r,a,r.path,a)),value:i._parse(new Vt(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?Ue.mergeObjectAsync(n,o):Ue.mergeObjectSync(n,o)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof oe?new Po({keyType:e,valueType:n,typeName:Q.ZodRecord,...ne(r)}):new Po({keyType:Ct.create(),valueType:e,typeName:Q.ZodRecord,...ne(n)})}}class Zs extends oe{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==F.map)return z(r,{code:O.invalid_type,expected:F.map,received:r.parsedType}),ee;const o=this._def.keyType,s=this._def.valueType,i=[...r.data.entries()].map(([a,l],c)=>({key:o._parse(new Vt(r,a,r.path,[c,"key"])),value:s._parse(new Vt(r,l,r.path,[c,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const l of i){const c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return ee;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const l of i){const c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return ee;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}}Zs.create=(t,e,n)=>new Zs({valueType:e,keyType:t,typeName:Q.ZodMap,...ne(n)});class tr extends oe{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==F.set)return z(r,{code:O.invalid_type,expected:F.set,received:r.parsedType}),ee;const o=this._def;o.minSize!==null&&r.data.size<o.minSize.value&&(z(r,{code:O.too_small,minimum:o.minSize.value,type:"set",inclusive:!0,exact:!1,message:o.minSize.message}),n.dirty()),o.maxSize!==null&&r.data.size>o.maxSize.value&&(z(r,{code:O.too_big,maximum:o.maxSize.value,type:"set",inclusive:!0,exact:!1,message:o.maxSize.message}),n.dirty());const s=this._def.valueType;function i(l){const c=new Set;for(const u of l){if(u.status==="aborted")return ee;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}const a=[...r.data.values()].map((l,c)=>s._parse(new Vt(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>i(l)):i(a)}min(e,n){return new tr({...this._def,minSize:{value:e,message:W.toString(n)}})}max(e,n){return new tr({...this._def,maxSize:{value:e,message:W.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}tr.create=(t,e)=>new tr({valueType:t,minSize:null,maxSize:null,typeName:Q.ZodSet,...ne(e)});class jr extends oe{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==F.function)return z(n,{code:O.invalid_type,expected:F.function,received:n.parsedType}),ee;function r(a,l){return Ls({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Vs(),$r].filter(c=>!!c),issueData:{code:O.invalid_arguments,argumentsError:l}})}function o(a,l){return Ls({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Vs(),$r].filter(c=>!!c),issueData:{code:O.invalid_return_type,returnTypeError:l}})}const s={errorMap:n.common.contextualErrorMap},i=n.data;if(this._def.returns instanceof Hr){const a=this;return Ge(async function(...l){const c=new lt([]),u=await a._def.args.parseAsync(l,s).catch(m=>{throw c.addIssue(r(l,m)),c}),f=await Reflect.apply(i,this,u);return await a._def.returns._def.type.parseAsync(f,s).catch(m=>{throw c.addIssue(o(f,m)),c})})}else{const a=this;return Ge(function(...l){const c=a._def.args.safeParse(l,s);if(!c.success)throw new lt([r(l,c.error)]);const u=Reflect.apply(i,this,c.data),f=a._def.returns.safeParse(u,s);if(!f.success)throw new lt([o(u,f.error)]);return f.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new jr({...this._def,args:Lt.create(e).rest(Qn.create())})}returns(e){return new jr({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new jr({args:e||Lt.create([]).rest(Qn.create()),returns:n||Qn.create(),typeName:Q.ZodFunction,...ne(r)})}}class Ro extends oe{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Ro.create=(t,e)=>new Ro({getter:t,typeName:Q.ZodLazy,...ne(e)});class Do extends oe{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return z(n,{received:n.data,code:O.invalid_literal,expected:this._def.value}),ee}return{status:"valid",value:e.data}}get value(){return this._def.value}}Do.create=(t,e)=>new Do({value:t,typeName:Q.ZodLiteral,...ne(e)});function yu(t,e){return new zo({values:t,typeName:Q.ZodEnum,...ne(e)})}let zo=class lu extends oe{constructor(){super(...arguments),Eo.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{expected:le.joinValues(r),received:n.parsedType,code:O.invalid_type}),ee}if(Fs(this,Eo)||fu(this,Eo,new Set(this._def.values)),!Fs(this,Eo).has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return z(n,{received:n.data,code:O.invalid_enum_value,options:r}),ee}return Ge(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return lu.create(e,{...this._def,...n})}exclude(e,n=this._def){return lu.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}};Eo=new WeakMap,zo.create=yu;class $o extends oe{constructor(){super(...arguments),To.set(this,void 0)}_parse(e){const n=le.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==F.string&&r.parsedType!==F.number){const o=le.objectValues(n);return z(r,{expected:le.joinValues(o),received:r.parsedType,code:O.invalid_type}),ee}if(Fs(this,To)||fu(this,To,new Set(le.getValidEnumValues(this._def.values))),!Fs(this,To).has(e.data)){const o=le.objectValues(n);return z(r,{received:r.data,code:O.invalid_enum_value,options:o}),ee}return Ge(e.data)}get enum(){return this._def.values}}To=new WeakMap,$o.create=(t,e)=>new $o({values:t,typeName:Q.ZodNativeEnum,...ne(e)});class Hr extends oe{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==F.promise&&n.common.async===!1)return z(n,{code:O.invalid_type,expected:F.promise,received:n.parsedType}),ee;const r=n.parsedType===F.promise?n.data:Promise.resolve(n.data);return Ge(r.then(o=>this._def.type.parseAsync(o,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Hr.create=(t,e)=>new Hr({type:t,typeName:Q.ZodPromise,...ne(e)});class xt extends oe{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Q.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),o=this._def.effect||null,s={addIssue:i=>{z(r,i),i.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),o.type==="preprocess"){const i=o.transform(r.data,s);if(r.common.async)return Promise.resolve(i).then(async a=>{if(n.value==="aborted")return ee;const l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?ee:l.status==="dirty"||n.value==="dirty"?Vr(l.value):l});{if(n.value==="aborted")return ee;const a=this._def.schema._parseSync({data:i,path:r.path,parent:r});return a.status==="aborted"?ee:a.status==="dirty"||n.value==="dirty"?Vr(a.value):a}}if(o.type==="refinement"){const i=a=>{const l=o.refinement(a,s);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?ee:(a.status==="dirty"&&n.dirty(),i(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?ee:(a.status==="dirty"&&n.dirty(),i(a.value).then(()=>({status:n.value,value:a.value}))))}if(o.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Yn(i))return i;const a=o.transform(i.value,s);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Yn(i)?Promise.resolve(o.transform(i.value,s)).then(a=>({status:n.value,value:a})):i);le.assertNever(o)}}xt.create=(t,e,n)=>new xt({schema:t,typeName:Q.ZodEffects,effect:e,...ne(n)}),xt.createWithPreprocess=(t,e,n)=>new xt({schema:e,effect:{type:"preprocess",transform:t},typeName:Q.ZodEffects,...ne(n)});let Ft=class extends oe{_parse(e){return this._getType(e)===F.undefined?Ge(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};Ft.create=(t,e)=>new Ft({innerType:t,typeName:Q.ZodOptional,...ne(e)});let wn=class extends oe{_parse(e){return this._getType(e)===F.null?Ge(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};wn.create=(t,e)=>new wn({innerType:t,typeName:Q.ZodNullable,...ne(e)});let Vo=class extends oe{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===F.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};Vo.create=(t,e)=>new Vo({innerType:t,typeName:Q.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...ne(e)});let Lo=class extends oe{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},o=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return _o(o)?o.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})})):{status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};Lo.create=(t,e)=>new Lo({innerType:t,typeName:Q.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...ne(e)});class Us extends oe{_parse(e){if(this._getType(e)!==F.nan){const r=this._getOrReturnCtx(e);return z(r,{code:O.invalid_type,expected:F.nan,received:r.parsedType}),ee}return{status:"valid",value:e.data}}}Us.create=t=>new Us({typeName:Q.ZodNaN,...ne(t)});const vw=Symbol("zod_brand");class qa extends oe{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Fo extends oe{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?ee:s.status==="dirty"?(n.dirty(),Vr(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const o=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?ee:o.status==="dirty"?(n.dirty(),{status:"dirty",value:o.value}):this._def.out._parseSync({data:o.value,path:r.path,parent:r})}}static create(e,n){return new Fo({in:e,out:n,typeName:Q.ZodPipeline})}}let jo=class extends oe{_parse(e){const n=this._def.innerType._parse(e),r=o=>(Yn(o)&&(o.value=Object.freeze(o.value)),o);return _o(n)?n.then(o=>r(o)):r(n)}unwrap(){return this._def.innerType}};jo.create=(t,e)=>new jo({innerType:t,typeName:Q.ZodReadonly,...ne(e)});function ku(t,e){const n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function wu(t,e={},n){return t?Lr.create().superRefine((r,o)=>{var s,i;const a=t(r);if(a instanceof Promise)return a.then(l=>{var c,u;if(!l){const f=ku(e,r),p=(u=(c=f.fatal)!==null&&c!==void 0?c:n)!==null&&u!==void 0?u:!0;o.addIssue({code:"custom",...f,fatal:p})}});if(!a){const l=ku(e,r),c=(i=(s=l.fatal)!==null&&s!==void 0?s:n)!==null&&i!==void 0?i:!0;o.addIssue({code:"custom",...l,fatal:c})}}):Lr.create()}const bw={object:ft.lazycreate};var Q;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(Q||(Q={}));const Sw=(t,e={message:`Input not instance of ${t.name}`})=>wu(n=>n instanceof t,e),vu=Ct.create,bu=Mo.create,Cw=Us.create,xw=kn.create,Su=Ao.create,_w=Xn.create,Ew=js.create,Tw=No.create,Mw=Bo.create,Aw=Lr.create,Nw=Qn.create,Bw=tn.create,Ow=Hs.create,Iw=er.create,Pw=ft.create,Rw=ft.strictCreate,Dw=Oo.create,zw=Ws.create,$w=Io.create,Vw=Lt.create,Lw=Po.create,Fw=Zs.create,jw=tr.create,Hw=jr.create,Ww=Ro.create,Zw=Do.create,Uw=zo.create,Kw=$o.create,Jw=Hr.create,Cu=xt.create,qw=Ft.create,Gw=wn.create,Yw=xt.createWithPreprocess,Xw=Fo.create;var rn=Object.freeze({__proto__:null,defaultErrorMap:$r,setErrorMap:Yk,getErrorMap:Vs,makeIssue:Ls,EMPTY_PATH:Xk,addIssueToContext:z,ParseStatus:Ue,INVALID:ee,DIRTY:Vr,OK:Ge,isAborted:Za,isDirty:Ua,isValid:Yn,isAsync:_o,get util(){return le},get objectUtil(){return Wa},ZodParsedType:F,getParsedType:en,ZodType:oe,datetimeRegex:gu,ZodString:Ct,ZodNumber:Mo,ZodBigInt:kn,ZodBoolean:Ao,ZodDate:Xn,ZodSymbol:js,ZodUndefined:No,ZodNull:Bo,ZodAny:Lr,ZodUnknown:Qn,ZodNever:tn,ZodVoid:Hs,ZodArray:er,ZodObject:ft,ZodUnion:Oo,ZodDiscriminatedUnion:Ws,ZodIntersection:Io,ZodTuple:Lt,ZodRecord:Po,ZodMap:Zs,ZodSet:tr,ZodFunction:jr,ZodLazy:Ro,ZodLiteral:Do,ZodEnum:zo,ZodNativeEnum:$o,ZodPromise:Hr,ZodEffects:xt,ZodTransformer:xt,ZodOptional:Ft,ZodNullable:wn,ZodDefault:Vo,ZodCatch:Lo,ZodNaN:Us,BRAND:vw,ZodBranded:qa,ZodPipeline:Fo,ZodReadonly:jo,custom:wu,Schema:oe,ZodSchema:oe,late:bw,get ZodFirstPartyTypeKind(){return Q},coerce:{string:t=>Ct.create({...t,coerce:!0}),number:t=>Mo.create({...t,coerce:!0}),boolean:t=>Ao.create({...t,coerce:!0}),bigint:t=>kn.create({...t,coerce:!0}),date:t=>Xn.create({...t,coerce:!0})},any:Aw,array:Iw,bigint:xw,boolean:Su,date:_w,discriminatedUnion:zw,effect:Cu,enum:Uw,function:Hw,instanceof:Sw,intersection:$w,lazy:Ww,literal:Zw,map:Fw,nan:Cw,nativeEnum:Kw,never:Bw,null:Mw,nullable:Gw,number:bu,object:Pw,oboolean:()=>Su().optional(),onumber:()=>bu().optional(),optional:qw,ostring:()=>vu().optional(),pipeline:Xw,preprocess:Yw,promise:Jw,record:Lw,set:jw,strictObject:Rw,string:vu,symbol:Ew,transformer:Cu,tuple:Vw,undefined:Tw,union:Dw,unknown:Nw,void:Ow,NEVER:ee,ZodIssueCode:O,quotelessJson:Gk,ZodError:lt});function Qw(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function e1(){const t=Qw();if(t.__xstate__)return t.__xstate__}const t1=t=>{if(typeof window>"u")return;const e=e1();e&&e.register(t)};class xu{constructor(e){this._process=e,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(e){const n={value:e,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const e=this._current;this._process(e.value),this._current=e.next}this._last=null}}const _u=".",n1="",Eu="",r1="#",o1="*",Tu="xstate.init",s1="xstate.error",Ga="xstate.stop";function i1(t,e){return{type:`xstate.after.${t}.${e}`}}function Ya(t,e){return{type:`xstate.done.state.${t}`,output:e}}function a1(t,e){return{type:`xstate.done.actor.${t}`,output:e,actorId:t}}function Mu(t,e){return{type:`xstate.error.actor.${t}`,error:e,actorId:t}}function Au(t){return{type:Tu,input:t}}function jt(t){setTimeout(()=>{throw t})}const l1=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Nu(t,e){const n=Bu(t),r=Bu(e);return typeof r=="string"?typeof n=="string"?r===n:!1:typeof n=="string"?n in r:Object.keys(n).every(o=>o in r?Nu(n[o],r[o]):!1)}function Xa(t){if(Pu(t))return t;const e=[];let n="";for(let r=0;r<t.length;r++){switch(t.charCodeAt(r)){case 92:n+=t[r+1],r++;continue;case 46:e.push(n),n="";continue}n+=t[r]}return e.push(n),e}function Bu(t){if(Z1(t))return t.value;if(typeof t!="string")return t;const e=Xa(t);return c1(e)}function c1(t){if(t.length===1)return t[0];const e={};let n=e;for(let r=0;r<t.length-1;r++)if(r===t.length-2)n[t[r]]=t[r+1];else{const o=n;n={},o[t[r]]=n}return e}function Ou(t,e){const n={},r=Object.keys(t);for(let o=0;o<r.length;o++){const s=r[o];n[s]=e(t[s],s,t,o)}return n}function Iu(t){return Pu(t)?t:[t]}function vn(t){return t===void 0?[]:Iu(t)}function Qa(t,e,n,r){return typeof t=="function"?t({context:e,event:n,self:r}):t}function Pu(t){return Array.isArray(t)}function d1(t){return t.type.startsWith("xstate.error.actor")}function Wr(t){return Iu(t).map(e=>typeof e>"u"||typeof e=="string"?{target:e}:e)}function Ru(t){if(!(t===void 0||t===n1))return vn(t)}function el(t,e,n){var s,i,a;const r=typeof t=="object",o=r?t:void 0;return{next:(s=r?t.next:t)==null?void 0:s.bind(o),error:(i=r?t.error:e)==null?void 0:i.bind(o),complete:(a=r?t.complete:n)==null?void 0:a.bind(o)}}function Du(t,e){return`${e}.${t}`}function tl(t,e){const n=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return t.implementations.actors[e];const[,r,o]=n,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[r]:i).src}function u1(t,e){if(e===t||e===o1)return!0;if(!e.endsWith(".*"))return!1;const n=e.split("."),r=t.split(".");for(let o=0;o<n.length;o++){const s=n[o],i=r[o];if(s==="*")return o===n.length-1;if(s!==i)return!1}return!0}function zu(t,e){return`${t.sessionId}.${e}`}let f1=0;function h1(t,e){const n=new Map,r=new Map,o=new WeakMap,s=new Set,i={},{clock:a,logger:l}=e,c={schedule:(p,m,g,y,k=Math.random().toString(36).slice(2))=>{const w={source:p,target:m,event:g,delay:y,id:k,startedAt:Date.now()},v=zu(p,k);f._snapshot._scheduledEvents[v]=w;const b=a.setTimeout(()=>{delete i[v],delete f._snapshot._scheduledEvents[v],f._relay(p,m,g)},y);i[v]=b},cancel:(p,m)=>{const g=zu(p,m),y=i[g];delete i[g],delete f._snapshot._scheduledEvents[g],y!==void 0&&a.clearTimeout(y)},cancelAll:p=>{for(const m in f._snapshot._scheduledEvents){const g=f._snapshot._scheduledEvents[m];g.source===p&&c.cancel(p,g.id)}}},u=p=>{if(!s.size)return;const m={...p,rootId:t.sessionId};s.forEach(g=>{var y;return(y=g.next)==null?void 0:y.call(g,m)})},f={_snapshot:{_scheduledEvents:((e==null?void 0:e.snapshot)&&e.snapshot.scheduler)??{}},_bookId:()=>`x:${f1++}`,_register:(p,m)=>(n.set(p,m),p),_unregister:p=>{n.delete(p.sessionId);const m=o.get(p);m!==void 0&&(r.delete(m),o.delete(p))},get:p=>r.get(p),getAll:()=>Object.fromEntries(r.entries()),_set:(p,m)=>{const g=r.get(p);if(g&&g!==m)throw new Error(`Actor with system ID '${p}' already exists.`);r.set(p,m),o.set(m,p)},inspect:p=>{const m=el(p);return s.add(m),{unsubscribe(){s.delete(m)}}},_sendInspectionEvent:u,_relay:(p,m,g)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:p,actorRef:m,event:g}),m._send(g)},scheduler:c,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const p=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const m in p){const{source:g,target:y,event:k,delay:w,id:v}=p[m];c.schedule(g,y,k,w,v)}},_clock:a,_logger:l};return f}let nl=!1;const rl=1;let rt=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const p1={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class m1{constructor(e,n){this.logic=e,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new xu(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=rt.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const r={...p1,...n},{clock:o,logger:s,parent:i,syncSnapshot:a,id:l,systemId:c,inspect:u}=r;this.system=i?i.system:h1(this,{clock:o,logger:s}),u&&!i&&this.system.inspect(el(u)),this.sessionId=this.system._bookId(),this.id=l??this.sessionId,this.logger=(n==null?void 0:n.logger)??this.system._logger,this.clock=(n==null?void 0:n.clock)??this.system._clock,this._parent=i,this._syncSnapshot=a,this.options=r,this.src=r.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:f=>{this._deferred.push(f)},system:this.system,stopChild:f=>{if(f._parent!==this)throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);f._stop()},emit:f=>{const p=this.eventListeners.get(f.type),m=this.eventListeners.get("*");if(!p&&!m)return;const g=[...p?p.values():[],...m?m.values():[]];for(const y of g)try{y(f)}catch(k){jt(k)}},actionExecutor:f=>{const p=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:f.type,params:f.params}}),!f.exec)return;const m=nl;try{nl=!0,f.exec(f.info,f.params)}finally{nl=m}};this._processingStatus===rt.Running?p():this._deferred.push(p)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this.systemId=c,this.system._set(c,this)),this._initState((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),c&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(e){var n;try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(r){this._snapshot={status:"error",output:void 0,error:r}}}update(e,n){var o,s;this._snapshot=e;let r;for(;r=this._deferred.shift();)try{r()}catch(i){this._deferred.length=0,this._snapshot={...e,status:"error",error:i}}switch(this._snapshot.status){case"active":for(const i of this.observers)try{(o=i.next)==null||o.call(i,e)}catch(a){jt(a)}break;case"done":for(const i of this.observers)try{(s=i.next)==null||s.call(i,e)}catch(a){jt(a)}this._stopProcedure(),this._complete(),this._doneEvent=a1(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:n,snapshot:e})}subscribe(e,n,r){var s;const o=el(e,n,r);if(this._processingStatus!==rt.Stopped)this.observers.add(o);else switch(this._snapshot.status){case"done":try{(s=o.complete)==null||s.call(o)}catch(i){jt(i)}break;case"error":{const i=this._snapshot.error;if(!o.error)jt(i);else try{o.error(i)}catch(a){jt(a)}break}}return{unsubscribe:()=>{this.observers.delete(o)}}}on(e,n){let r=this.eventListeners.get(e);r||(r=new Set,this.eventListeners.set(e,r));const o=n.bind(void 0);return r.add(o),{unsubscribe:()=>{r.delete(o)}}}start(){if(this._processingStatus===rt.Running)return this;this._syncSnapshot&&this.subscribe({next:r=>{r.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:r})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=rt.Running;const e=Au(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case"done":return this.update(this._snapshot,e),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(r){return this._snapshot={...this._snapshot,status:"error",error:r},this._error(r),this}return this.update(this._snapshot,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let n,r;try{n=this.logic.transition(this._snapshot,e,this._actorScope)}catch(o){r={err:o}}if(r){const{err:o}=r;this._snapshot={...this._snapshot,status:"error",error:o},this._error(o);return}this.update(n,e),e.type===Ga&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===rt.Stopped?this:(this.mailbox.clear(),this._processingStatus===rt.NotStarted?(this._processingStatus=rt.Stopped,this):(this.mailbox.enqueue({type:Ga}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var e;for(const n of this.observers)try{(e=n.complete)==null||e.call(n)}catch(r){jt(r)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||jt(e),this.eventListeners.clear();return}let n=!1;for(const r of this.observers){const o=r.error;n||(n=!o);try{o==null||o(e)}catch(s){jt(s)}}this.observers.clear(),this.eventListeners.clear(),n&&jt(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,Mu(this.id,e))}_stopProcedure(){return this._processingStatus!==rt.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new xu(this._process.bind(this)),this._processingStatus=rt.Stopped,this.system._unregister(this),this)}_send(e){this._processingStatus!==rt.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){const{devTools:e}=this.options;e&&(typeof e=="function"?e:t1)(this)}toJSON(){return{xstate$$type:rl,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[l1](){return this}getSnapshot(){return this._snapshot}}function Ks(t,...[e]){return new m1(t,e)}function g1(t,e,n,r,{sendId:o}){const s=typeof o=="function"?o(n,r):o;return[e,{sendId:s},void 0]}function y1(t,e){t.defer(()=>{t.system.scheduler.cancel(t.self,e.sendId)})}function ol(t){function e(n,r){}return e.type="xstate.cancel",e.sendId=t,e.resolve=g1,e.execute=y1,e}function k1(t,e,n,r,{id:o,systemId:s,src:i,input:a,syncSnapshot:l}){const c=typeof i=="string"?tl(e.machine,i):i,u=typeof o=="function"?o(n):o;let f,p;return c&&(p=typeof a=="function"?a({context:e.context,event:n.event,self:t.self}):a,f=Ks(c,{id:u,src:i,parent:t.self,syncSnapshot:l,systemId:s,input:p})),[or(e,{children:{...e.children,[u]:f}}),{id:o,systemId:s,actorRef:f,src:i,input:p},void 0]}function w1(t,{actorRef:e}){e&&t.defer(()=>{e._processingStatus!==rt.Stopped&&e.start()})}function sl(...[t,{id:e,systemId:n,input:r,syncSnapshot:o=!1}={}]){function s(i,a){}return s.type="xstate.spawnChild",s.id=e,s.systemId=n,s.src=t,s.input=r,s.syncSnapshot=o,s.resolve=k1,s.execute=w1,s}function v1(t,e,n,r,{actorRef:o}){const s=typeof o=="function"?o(n,r):o,i=typeof s=="string"?e.children[s]:s;let a=e.children;return i&&(a={...a},delete a[i.id]),[or(e,{children:a}),i,void 0]}function $u(t,e){const n=e.getSnapshot();if(n&&"children"in n)for(const r of Object.values(n.children))$u(t,r);t.system._unregister(e)}function b1(t,e){if(e){if($u(t,e),e._processingStatus!==rt.Running){t.stopChild(e);return}t.defer(()=>{t.stopChild(e)})}}function Js(t){function e(n,r){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=v1,e.execute=b1,e}function S1(t,{context:e,event:n},{guards:r}){return!Zr(r[0],e,n,t)}function nr(t){function e(n,r){return!1}return e.check=S1,e.guards=[t],e}function C1(t,{context:e,event:n},{guards:r}){return r.every(o=>Zr(o,e,n,t))}function Ho(t){function e(n,r){return!1}return e.check=C1,e.guards=t,e}function Zr(t,e,n,r){const{machine:o}=r,s=typeof t=="function",i=s?t:o.implementations.guards[typeof t=="string"?t:t.type];if(!s&&!i)throw new Error(`Guard '${typeof t=="string"?t:t.type}' is not implemented.'.`);if(typeof i!="function")return Zr(i,e,n,r);const a={context:e,event:n},l=s||typeof t=="string"?void 0:"params"in t?typeof t.params=="function"?t.params({context:e,event:n}):t.params:void 0;return"check"in i?i.check(r,a,i):i(a,l)}function il(t){return t.type==="atomic"||t.type==="final"}function Ur(t){return Object.values(t.states).filter(e=>e.type!=="history")}function Wo(t,e){const n=[];if(e===t)return n;let r=t.parent;for(;r&&r!==e;)n.push(r),r=r.parent;return n}function qs(t){const e=new Set(t),n=Lu(e);for(const r of e)if(r.type==="compound"&&(!n.get(r)||!n.get(r).length))Hu(r).forEach(o=>e.add(o));else if(r.type==="parallel"){for(const o of Ur(r))if(o.type!=="history"&&!e.has(o)){const s=Hu(o);for(const i of s)e.add(i)}}for(const r of e){let o=r.parent;for(;o;)e.add(o),o=o.parent}return e}function Vu(t,e){const n=e.get(t);if(!n)return{};if(t.type==="compound"){const o=n[0];if(o){if(il(o))return o.key}else return{}}const r={};for(const o of n)r[o.key]=Vu(o,e);return r}function Lu(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function Fu(t,e){const n=qs(e);return Vu(t,Lu(n))}function al(t,e){return e.type==="compound"?Ur(e).some(n=>n.type==="final"&&t.has(n)):e.type==="parallel"?Ur(e).every(n=>al(t,n)):e.type==="final"}const Gs=t=>t[0]===r1;function x1(t,e){return t.transitions.get(e)||[...t.transitions.keys()].filter(r=>u1(e,r)).sort((r,o)=>o.length-r.length).flatMap(r=>t.transitions.get(r))}function _1(t){const e=t.config.after;if(!e)return[];const n=o=>{const s=i1(o,t.id),i=s.type;return t.entry.push(ei(s,{id:i,delay:o})),t.exit.push(ol(i)),i};return Object.keys(e).flatMap(o=>{const s=e[o],i=typeof s=="string"?{target:s}:s,a=Number.isNaN(+o)?o:+o,l=n(a);return vn(i).map(c=>({...c,event:l,delay:a}))}).map(o=>{const{delay:s}=o;return{...bn(t,o.event,o),delay:s}})}function bn(t,e,n){const r=Ru(n.target),o=n.reenter??!1,s=A1(t,r),i={...n,actions:vn(n.actions),guard:n.guard,target:s,source:t,reenter:o,eventType:e,toJSON:()=>({...i,source:`#${t.id}`,target:s?s.map(a=>`#${a.id}`):void 0})};return i}function E1(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===Eu)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const r=t.config.on[n];e.set(n,Wr(r).map(o=>bn(t,n,o)))}if(t.config.onDone){const n=`xstate.done.state.${t.id}`;e.set(n,Wr(t.config.onDone).map(r=>bn(t,n,r)))}for(const n of t.invoke){if(n.onDone){const r=`xstate.done.actor.${n.id}`;e.set(r,Wr(n.onDone).map(o=>bn(t,r,o)))}if(n.onError){const r=`xstate.error.actor.${n.id}`;e.set(r,Wr(n.onError).map(o=>bn(t,r,o)))}if(n.onSnapshot){const r=`xstate.snapshot.${n.id}`;e.set(r,Wr(n.onSnapshot).map(o=>bn(t,r,o)))}}for(const n of t.after){let r=e.get(n.eventType);r||(r=[],e.set(n.eventType,r)),r.push(n)}return e}function T1(t){const e=[],n=r=>{Object.values(r).forEach(o=>{if(o.config.route&&o.config.id){const s=o.config.id,i=o.config.route.guard,a=(c,u)=>c.event.to!==`#${s}`?!1:i&&typeof i=="function"?i(c,u):!0,l={...o.config.route,guard:a,target:`#${s}`};e.push(bn(t,"xstate.route",l))}o.states&&n(o.states)})};n(t.states),e.length>0&&t.transitions.set("xstate.route",e)}function M1(t,e){const n=typeof e=="string"?t.states[e]:e?t.states[e.target]:void 0;if(!n&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const r={source:t,actions:!e||typeof e=="string"?[]:vn(e.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...r,source:`#${t.id}`,target:n?[`#${n.id}`]:[]})};return r}function A1(t,e){if(e!==void 0)return e.map(n=>{if(typeof n!="string")return n;if(Gs(n))return t.machine.getStateNodeById(n);const r=n[0]===_u;if(r&&!t.parent)return Ys(t,n.slice(1));const o=r?t.key+n:n;if(t.parent)try{return Ys(t.parent,o)}catch(s){throw new Error(`Invalid transition definition for state node '${t.id}':
|
|
2
|
-
${s.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function ju(t){const e=Ru(t.config.target);return e?{target:e.map(n=>typeof n=="string"?Ys(t.parent,n):n)}:t.parent.initial}function rr(t){return t.type==="history"}function Hu(t){const e=Wu(t);for(const n of e)for(const r of Wo(n,t))e.add(r);return e}function Wu(t){const e=new Set;function n(r){if(!e.has(r)){if(e.add(r),r.type==="compound")n(r.initial.target[0]);else if(r.type==="parallel")for(const o of Ur(r))n(o)}}return n(t),e}function Kr(t,e){if(Gs(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function Ys(t,e){if(typeof e=="string"&&Gs(e))try{return t.machine.getStateNodeById(e)}catch{}const n=Xa(e).slice();let r=t;for(;n.length;){const o=n.shift();if(!o.length)break;r=Kr(r,o)}return r}function Xs(t,e){if(typeof e=="string"){const o=t.states[e];if(!o)throw new Error(`State '${e}' does not exist on '${t.id}'`);return[t,o]}const n=Object.keys(e),r=n.map(o=>Kr(t,o)).filter(Boolean);return[t.machine.root,t].concat(r,n.reduce((o,s)=>{const i=Kr(t,s);if(!i)return o;const a=Xs(i,e[s]);return o.concat(a)},[]))}function N1(t,e,n,r){const s=Kr(t,e).next(n,r);return!s||!s.length?t.next(n,r):s}function B1(t,e,n,r){const o=Object.keys(e),s=Kr(t,o[0]),i=ll(s,e[o[0]],n,r);return!i||!i.length?t.next(n,r):i}function O1(t,e,n,r){const o=[];for(const s of Object.keys(e)){const i=e[s];if(!i)continue;const a=Kr(t,s),l=ll(a,i,n,r);l&&o.push(...l)}return o.length?o:t.next(n,r)}function ll(t,e,n,r){return typeof e=="string"?N1(t,e,n,r):Object.keys(e).length===1?B1(t,e,n,r):O1(t,e,n,r)}function I1(t){return Object.keys(t.states).map(e=>t.states[e]).filter(e=>e.type==="history")}function Sn(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function P1(t,e){const n=new Set(t),r=new Set(e);for(const o of n)if(r.has(o))return!0;for(const o of r)if(n.has(o))return!0;return!1}function Zu(t,e,n){const r=new Set;for(const o of t){let s=!1;const i=new Set;for(const a of r)if(P1(dl([o],e,n),dl([a],e,n)))if(Sn(o.source,a.source))i.add(a);else{s=!0;break}if(!s){for(const a of i)r.delete(a);r.add(o)}}return Array.from(r)}function R1(t){const[e,...n]=t;for(const r of Wo(e,void 0))if(n.every(o=>Sn(o,r)))return r}function cl(t,e){if(!t.target)return[];const n=new Set;for(const r of t.target)if(rr(r))if(e[r.id])for(const o of e[r.id])n.add(o);else for(const o of cl(ju(r),e))n.add(o);else n.add(r);return[...n]}function Uu(t,e){const n=cl(t,e);if(!n)return;if(!t.reenter&&n.every(o=>o===t.source||Sn(o,t.source)))return t.source;const r=R1(n.concat(t.source));if(r)return r;if(!t.reenter)return t.source.machine.root}function dl(t,e,n){var o;const r=new Set;for(const s of t)if((o=s.target)!=null&&o.length){const i=Uu(s,n);s.reenter&&s.source===i&&r.add(i);for(const a of e)Sn(a,i)&&r.add(a)}return[...r]}function D1(t,e){if(t.length!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}function z1(t,e,n,r,o){return ul([{target:[...Wu(t)],source:t,reenter:!0,actions:[],eventType:null,toJSON:null}],e,n,r,!0,o)}function ul(t,e,n,r,o,s){const i=[];if(!t.length)return[e,i];const a=n.actionExecutor;n.actionExecutor=l=>{i.push(l),a(l)};try{const l=new Set(e._nodes);let c=e.historyValue;const u=Zu(t,l,c);let f=e;o||([f,c]=F1(f,r,n,u,l,c,s,n.actionExecutor)),f=qr(f,r,n,u.flatMap(m=>m.actions),s,void 0),f=V1(f,r,n,u,l,s,c,o);const p=[...l];f.status==="done"&&(f=qr(f,r,n,p.sort((m,g)=>g.order-m.order).flatMap(m=>m.exit),s,void 0));try{return c===e.historyValue&&D1(e._nodes,l)?[f,i]:[or(f,{_nodes:p,historyValue:c}),i]}catch(m){throw m}}finally{n.actionExecutor=a}}function $1(t,e,n,r,o){if(r.output===void 0)return;const s=Ya(o.id,o.output!==void 0&&o.parent?Qa(o.output,t.context,e,n.self):void 0);return Qa(r.output,t.context,s,n.self)}function V1(t,e,n,r,o,s,i,a){let l=t;const c=new Set,u=new Set;L1(r,i,u,c),a&&u.add(t.machine.root);const f=new Set;for(const p of[...c].sort((m,g)=>m.order-g.order)){o.add(p);const m=[];m.push(...p.entry);for(const g of p.invoke)m.push(sl(g.src,{...g,syncSnapshot:!!g.onSnapshot}));if(u.has(p)){const g=p.initial.actions;m.push(...g)}if(l=qr(l,e,n,m,s,p.invoke.map(g=>g.id)),p.type==="final"){const g=p.parent;let y=(g==null?void 0:g.type)==="parallel"?g:g==null?void 0:g.parent,k=y||p;for((g==null?void 0:g.type)==="compound"&&s.push(Ya(g.id,p.output!==void 0?Qa(p.output,l.context,e,n.self):void 0));(y==null?void 0:y.type)==="parallel"&&!f.has(y)&&al(o,y);)f.add(y),s.push(Ya(y.id)),k=y,y=y.parent;if(y)continue;l=or(l,{status:"done",output:$1(l,e,n,l.machine.root,k)})}}return l}function L1(t,e,n,r){for(const o of t){const s=Uu(o,e);for(const a of o.target||[])!rr(a)&&(o.source!==a||o.source!==s||o.reenter)&&(r.add(a),n.add(a)),Jr(a,e,n,r);const i=cl(o,e);for(const a of i){const l=Wo(a,s);(s==null?void 0:s.type)==="parallel"&&l.push(s),Ku(r,e,n,l,!o.source.parent&&o.reenter?void 0:s)}}}function Jr(t,e,n,r){var o;if(rr(t))if(e[t.id]){const s=e[t.id];for(const i of s)r.add(i),Jr(i,e,n,r);for(const i of s)fl(i,t.parent,r,e,n)}else{const s=ju(t);for(const i of s.target)r.add(i),s===((o=t.parent)==null?void 0:o.initial)&&n.add(t.parent),Jr(i,e,n,r);for(const i of s.target)fl(i,t.parent,r,e,n)}else if(t.type==="compound"){const[s]=t.initial.target;rr(s)||(r.add(s),n.add(s)),Jr(s,e,n,r),fl(s,t,r,e,n)}else if(t.type==="parallel")for(const s of Ur(t).filter(i=>!rr(i)))[...r].some(i=>Sn(i,s))||(rr(s)||(r.add(s),n.add(s)),Jr(s,e,n,r))}function Ku(t,e,n,r,o){for(const s of r)if((!o||Sn(s,o))&&t.add(s),s.type==="parallel")for(const i of Ur(s).filter(a=>!rr(a)))[...t].some(a=>Sn(a,i))||(t.add(i),Jr(i,e,n,t))}function fl(t,e,n,r,o){Ku(n,r,o,Wo(t,e))}function F1(t,e,n,r,o,s,i,a){let l=t;const c=dl(r,o,s);c.sort((f,p)=>p.order-f.order);let u;for(const f of c)for(const p of I1(f)){let m;p.history==="deep"?m=g=>il(g)&&Sn(g,f):m=g=>g.parent===f,u??(u={...s}),u[p.id]=Array.from(o).filter(m)}for(const f of c)l=qr(l,e,n,[...f.exit,...f.invoke.map(p=>Js(p.id))],i,void 0),o.delete(f);return[l,u||s]}function j1(t,e){return t.implementations.actions[e]}function Ju(t,e,n,r,o,s){const{machine:i}=t;let a=t;for(const l of r){const c=typeof l=="function",u=c?l:j1(i,typeof l=="string"?l:l.type),f={context:a.context,event:e,self:n.self,system:n.system},p=c||typeof l=="string"?void 0:"params"in l?typeof l.params=="function"?l.params({context:a.context,event:e}):l.params:void 0;if(!u||!("resolve"in u)){n.actionExecutor({type:typeof l=="string"?l:typeof l=="object"?l.type:l.name||"(anonymous)",info:f,params:p,exec:u});continue}const m=u,[g,y,k]=m.resolve(n,a,f,p,u,o);a=g,"retryResolve"in m&&(s==null||s.push([m,y])),"execute"in m&&n.actionExecutor({type:m.type,info:f,params:y,exec:m.execute.bind(null,n,y)}),k&&(a=Ju(a,e,n,k,o,s))}return a}function qr(t,e,n,r,o,s){const i=s?[]:void 0,a=Ju(t,e,n,r,{internalQueue:o,deferredActorIds:s},i);return i==null||i.forEach(([l,c])=>{l.retryResolve(n,a,c)}),a}function hl(t,e,n,r){let o=t;const s=[];function i(c,u,f){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:u,snapshot:c[0],_transitions:f}),s.push(c)}if(e.type===Ga)return o=or(qu(o,e,n),{status:"stopped"}),i([o,[]],e,[]),{snapshot:o,microsteps:s};let a=e;if(a.type!==Tu){const c=a,u=d1(c),f=Gu(c,o);if(u&&!f.length)return o=or(t,{status:"error",error:c.error}),i([o,[]],c,[]),{snapshot:o,microsteps:s};const p=ul(f,t,n,a,!1,r);o=p[0],i(p,c,f)}let l=!0;for(;o.status==="active";){let c=l?H1(o,a):[];const u=c.length?o:void 0;if(!c.length){if(!r.length)break;a=r.shift(),c=Gu(a,o)}const f=ul(c,o,n,a,!1,r);o=f[0],l=o!==u,i(f,a,c)}return o.status!=="active"&&qu(o,a,n),{snapshot:o,microsteps:s}}function qu(t,e,n){return qr(t,e,n,Object.values(t.children).map(r=>Js(r)),[],void 0)}function Gu(t,e){return e.machine.getTransitionData(e,t)}function H1(t,e){const n=new Set,r=t._nodes.filter(il);for(const o of r)e:for(const s of[o].concat(Wo(o,void 0)))if(s.always){for(const i of s.always)if(i.guard===void 0||Zr(i.guard,t.context,e,t)){n.add(i);break e}}return Zu(Array.from(n),new Set(t._nodes),t.historyValue)}function W1(t,e){const n=qs(Xs(t,e));return Fu(t,[...n])}function Z1(t){return!!t&&typeof t=="object"&&"machine"in t&&"value"in t}const U1=function(e){return Nu(e,this.value)},K1=function(e){return this.tags.has(e)},J1=function(e){const n=this.machine.getTransitionData(this,e);return!!(n!=null&&n.length)&&n.some(r=>r.target!==void 0||r.actions.length)},q1=function(){const{_nodes:e,tags:n,machine:r,getMeta:o,toJSON:s,can:i,hasTag:a,matches:l,...c}=this;return{...c,tags:Array.from(n)}},G1=function(){return this._nodes.reduce((e,n)=>(n.meta!==void 0&&(e[n.id]=n.meta),e),{})};function Qs(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:Fu(e.root,t._nodes),tags:new Set(t._nodes.flatMap(n=>n.tags)),children:t.children,historyValue:t.historyValue||{},matches:U1,hasTag:K1,can:J1,getMeta:G1,toJSON:q1}}function or(t,e={}){return Qs({...t,...e},t.machine)}function Y1(t){if(typeof t!="object"||t===null)return{};const e={};for(const n in t){const r=t[n];Array.isArray(r)&&(e[n]=r.map(o=>({id:o.id})))}return e}function X1(t,e){const{_nodes:n,tags:r,machine:o,children:s,context:i,can:a,hasTag:l,matches:c,getMeta:u,toJSON:f,...p}=t,m={};for(const y in s){const k=s[y];m[y]={snapshot:k.getPersistedSnapshot(e),src:k.src,systemId:k.systemId,syncSnapshot:k._syncSnapshot}}return{...p,context:Yu(i),children:m,historyValue:Y1(p.historyValue)}}function Yu(t){let e;for(const n in t){const r=t[n];if(r&&typeof r=="object")if("sessionId"in r&&"send"in r&&"ref"in r)e??(e=Array.isArray(t)?t.slice():{...t}),e[n]={xstate$$type:rl,id:r.id};else{const o=Yu(r);o!==r&&(e??(e=Array.isArray(t)?t.slice():{...t}),e[n]=o)}}return e??t}function Q1(t,e,n,r,{event:o,id:s,delay:i},{internalQueue:a}){const l=e.machine.implementations.delays;if(typeof o=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const c=typeof o=="function"?o(n,r):o;let u;if(typeof i=="string"){const f=l&&l[i];u=typeof f=="function"?f(n,r):f}else u=typeof i=="function"?i(n,r):i;return typeof u!="number"&&a.push(c),[e,{event:c,id:s,delay:u},void 0]}function ev(t,e){const{event:n,delay:r,id:o}=e;if(typeof r=="number"){t.defer(()=>{const s=t.self;t.system.scheduler.schedule(s,s,n,r,o)});return}}function ei(t,e){function n(r,o){}return n.type="xstate.raise",n.event=t,n.id=e==null?void 0:e.id,n.delay=e==null?void 0:e.delay,n.resolve=Q1,n.execute=ev,n}function tv(t,{machine:e,context:n},r,o){const s=(i,a)=>{if(typeof i=="string"){const l=tl(e,i);if(!l)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const c=Ks(l,{id:a==null?void 0:a.id,parent:t.self,syncSnapshot:a==null?void 0:a.syncSnapshot,input:typeof(a==null?void 0:a.input)=="function"?a.input({context:n,event:r,self:t.self}):a==null?void 0:a.input,src:i,systemId:a==null?void 0:a.systemId});return o[c.id]=c,c}else return Ks(i,{id:a==null?void 0:a.id,parent:t.self,syncSnapshot:a==null?void 0:a.syncSnapshot,input:a==null?void 0:a.input,src:i,systemId:a==null?void 0:a.systemId})};return(i,a)=>{const l=s(i,a);return o[l.id]=l,t.defer(()=>{l._processingStatus!==rt.Stopped&&l.start()}),l}}function nv(t,e,n,r,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const s={},i={context:e.context,event:n.event,spawn:tv(t,e,n.event,s),self:t.self,system:t.system};let a={};if(typeof o=="function")a=o(i,r);else for(const c of Object.keys(o)){const u=o[c];a[c]=typeof u=="function"?u(i,r):u}const l=Object.assign({},e.context,a);return[or(e,{context:l,children:Object.keys(s).length?{...e.children,...s}:e.children}),void 0,void 0]}function we(t){function e(n,r){}return e.type="xstate.assign",e.assignment=t,e.resolve=nv,e}const Xu=new WeakMap;function Gr(t,e,n){let r=Xu.get(t);return r?e in r||(r[e]=n()):(r={[e]:n()},Xu.set(t,r)),r[e]}const rv={},Zo=t=>typeof t=="string"?{type:t}:typeof t=="function"?"resolve"in t?{type:t.type}:{type:t.name}:t;class ti{constructor(e,n){if(this.config=e,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(_u),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Ou(this.config.states,(r,o)=>new ti(r,{_parent:this,_key:o,_machine:this.machine})):rv,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=vn(this.config.entry).slice(),this.exit=vn(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=vn(e.tags).slice()}_initialize(){this.transitions=E1(this),this.config.always&&(this.always=Wr(this.config.always).map(e=>bn(this,Eu,e))),Object.keys(this.states).forEach(e=>{this.states[e]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(Zo),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Zo),eventType:null})}:void 0,history:this.history,states:Ou(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(Zo)})),entry:this.entry.map(Zo),exit:this.exit.map(Zo),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return Gr(this,"invoke",()=>vn(this.config.invoke).map((e,n)=>{const{src:r,systemId:o}=e,s=e.id??Du(this.id,n),i=typeof r=="string"?r:`xstate.invoke.${Du(this.id,n)}`;return{...e,src:i,id:s,systemId:o,toJSON(){const{onDone:a,onError:l,...c}=e;return{...c,type:"xstate.invoke",src:i,id:s}}}}))}get on(){return Gr(this,"on",()=>[...this.transitions].flatMap(([n,r])=>r.map(o=>[n,o])).reduce((n,[r,o])=>(n[r]=n[r]||[],n[r].push(o),n),{}))}get after(){return Gr(this,"delayedTransitions",()=>_1(this))}get initial(){return Gr(this,"initial",()=>M1(this,this.config.initial))}next(e,n){const r=n.type,o=[];let s;const i=Gr(this,`candidates-${r}`,()=>x1(this,r));for(const a of i){const{guard:l}=a,c=e.context;let u=!1;try{u=!l||Zr(l,c,n,e)}catch(f){const p=typeof l=="string"?l:typeof l=="object"?l.type:void 0;throw new Error(`Unable to evaluate guard ${p?`'${p}' `:""}in transition for event '${r}' in state node '${this.id}':
|
|
3
|
-
|
|
4
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33.94 33.94">
|
|
5
|
-
<g fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
|
6
|
-
<path d="M25.46,14.14l2.83,2.83-2.83,2.83"/>
|
|
7
|
-
<path d="M19.8,16.97h8.49"/>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<path d="M14.14,25.46l2.83,2.83,2.83-2.83"/>
|
|
11
|
-
|
|
12
|
-
<path d="M19.8,8.49l-2.83-2.83-2.83,2.83"/>
|
|
13
|
-
<path d="M16.97,5.66v15.14"/>
|
|
14
|
-
</g>
|
|
15
|
-
</svg>`;function oi(t){return`
|
|
16
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
|
|
17
|
-
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
18
|
-
<g transform="rotate(${t*180/Math.PI} 12 12)">
|
|
19
|
-
<path d="M8 7l4 -4l4 4"/>
|
|
20
|
-
<path d="M8 17l4 4l4 -4"/>
|
|
21
|
-
<path d="M12 3l0 18"/>
|
|
22
|
-
</g>
|
|
23
|
-
</svg>`}function si(t){return`
|
|
24
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 34 34"
|
|
25
|
-
fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
|
26
|
-
<g transform="rotate(${t*180/Math.PI} 8 8)">
|
|
27
|
-
<path d="M1,14.76l4,4,4-4"/>
|
|
28
|
-
<path d="M14.61,1l4,4-4,4"/>
|
|
29
|
-
<path d="M18.61,5h-6.02c-4.19,0-7.59,3.4-7.59,7.59v6.17"/>
|
|
30
|
-
</g>
|
|
31
|
-
</svg>`}var Sv={drag:{makeSvg:()=>bv,hotspot:[12,12],rotationOffset:0},ns:{makeSvg:oi,hotspot:[12,12],rotationOffset:0},ew:{makeSvg:oi,hotspot:[12,12],rotationOffset:Math.PI/2},nwse:{makeSvg:oi,hotspot:[12,12],rotationOffset:-Math.PI/4},nesw:{makeSvg:oi,hotspot:[12,12],rotationOffset:Math.PI/4},rotateNW:{makeSvg:si,hotspot:[16,16],rotationOffset:0},rotateNE:{makeSvg:si,hotspot:[16,16],rotationOffset:Math.PI/2},rotateSW:{makeSvg:si,hotspot:[16,16],rotationOffset:-Math.PI/2},rotateSE:{makeSvg:si,hotspot:[16,16],rotationOffset:-Math.PI}},de={Idle:"idle",Pointing:"pointing",Dragging:"dragging",SelectionBoxPointing:"selectionBoxPointing",SelectionBoxDragging:"selectionBoxDragging"},_t={None:"none",Idle:"idle",Editing:"editing"},Et={Scale:"scale",Stretch:"stretch",Rotate:"rotate"},ht={Idle:"idle",Waiting:"waiting",Scrolling:"scrolling"},wf=rn.object({enabled:rn.boolean().default(!0),edgeSizePx:rn.number().default(10),edgeScrollSpeedPxPerFrame:rn.number().default(15),edgeScrollDelayMs:rn.number().default(250)}),Cv=rn.object({edgeScrolling:wf.default(wf.parse({}))}),ve=h.defineCanvasComponent({name:"transformHandle"},{kind:h.field.string().max(16).default(Et.Scale),vectorX:h.field.int8().default(0),vectorY:h.field.int8().default(0),transformBox:h.field.ref(),cursorKind:h.field.string().max(16).default("drag")}),vf="selection";function xv(t,e,n){var o;const r={...n};for(const[s,i]of Object.entries(e))if(((o=i==null?void 0:i.def)==null?void 0:o.type)==="ref"){const a=n[s];r[s]=_v(t,a)}return r}function _v(t,e){return e==null||!h.hasComponent(t,e,h.Synced)?null:h.Synced.read(t,e).id}function Ev(t){var n;const e=[];for(const[r,o]of Object.entries(t))((n=o==null?void 0:o.def)==null?void 0:n.type)==="ref"&&e.push(r);return e}function Tv(t,e,n,r,o){var i;const s=n.write(t,e);for(const[a,l]of Object.entries(n.schema))if(((i=l==null?void 0:l.def)==null?void 0:i.type)==="ref"){const c=r[a];c!=null&&(s[a]=o.get(c)??null)}}var Mv=h.defineQuery(t=>t.with(Ie));h.defineQuery(t=>t.with(h.Block));function Qr(t,e){if(h.hasComponent(t,e,Ie)||h.isHeldByRemote(t,e))return;const{sessionId:n}=h.getResources(t);h.addComponent(t,e,Ie,{}),h.hasComponent(t,e,h.Held)||h.addComponent(t,e,h.Held,{sessionId:n})}function Jo(t,e){h.hasComponent(t,e,Ie)&&(h.removeComponent(t,e,Ie),h.removeComponent(t,e,h.Held))}function bf(t){for(const e of Mv.current(t))Jo(t,e)}function Av(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e)}var Nv=class{constructor(t){this.seed=typeof t=="string"?Av(t):t}next(){return this.seed=(this.seed*9301+49297)%233280,this.seed/233280}nextInt(t,e){return Math.floor(this.next()*(e-t+1))+t}nextHex(){return this.nextInt(0,15).toString(16)}};function Sl(t,e){const n=t+e,r=new Nv(n);let o="";for(let s=0;s<32;s++)(s===8||s===12||s===16||s===20)&&(o+="-"),s===12?o+="4":s===16?o+=["8","9","a","b"][r.nextInt(0,3)]:o+=r.nextHex();return o}var Sf={};Yr(Sf,{Clipboard:()=>qo,ScrollEdgesStateSingleton:()=>Cl,SelectionStateSingleton:()=>Tt,TransformBoxStateSingleton:()=>xl});var Bv={count:h.field.uint32().default(0),center:h.field.tuple(h.field.float64(),2).default([0,0])},ii=new WeakMap,Ov=class extends h.CanvasSingletonDef{constructor(){super({name:"clipboard"},Bv)}setEntities(t,e){const{editor:n}=h.getResources(t);ii.set(n,e)}getEntities(t){const{editor:e}=h.getResources(t);return ii.get(e)??[]}clearEntities(t){const{editor:e}=h.getResources(t);ii.delete(e)}hasContent(t){const{editor:e}=h.getResources(t),n=ii.get(e);return n!==void 0&&n.length>0}},qo=new Ov,Cl=h.defineEditorState("scrollEdgesState",{state:h.field.enum(ht).default(ht.Idle),edgeEnterStartTime:h.field.float64().default(0)}),Tt=h.defineEditorState("selectionState",{state:h.field.enum(de).default(de.Idle),dragStart:h.field.tuple(h.field.float64(),2).default([0,0]),pointingStartClient:h.field.tuple(h.field.float64(),2).default([0,0]),pointingStartWorld:h.field.tuple(h.field.float64(),2).default([0,0]),draggedEntityStart:h.field.tuple(h.field.float64(),2).default([0,0]),draggedEntity:h.field.ref(),cloneGeneratorSeed:h.field.string().max(36).default(""),isCloning:h.field.boolean()}),xl=h.defineEditorState("transformBoxState",{state:h.field.string().max(32).default(_t.None),transformBoxId:h.field.ref()}),Cf={};Yr(Cf,{hoverCursorSystem:()=>Pv,scrollEdgesSystem:()=>Dv,transformBoxSystem:()=>Vv});var _l=h.defineQuery(t=>t.with(h.Hovered,ve).tracking(h.Hovered)),Iv=h.defineQuery(t=>t.with(h.Block,Ye).tracking(h.Block)),Pv=h.defineEditorSystem({phase:"capture"},t=>{const e=_l.added(t),n=_l.removed(t),r=_l.current(t),o=Iv.changed(t);if(r.length===0&&n.length>0){h.Cursor.clearContextCursor(t);return}if((e.length>0||o.length>0)&&r.length>0){const i=r[0],a=ve.read(t,i);if(a.transformBox===null)return;const l=h.Block.read(t,a.transformBox),c=h.Cursor.read(t);(a.cursorKind!==c.contextCursorKind||l.rotateZ!==c.contextRotation)&&h.Cursor.setContextCursor(t,a.cursorKind,l.rotateZ)}});function ai(t){return h.getPluginResources(t,vf).edgeScrolling}var Rv=on({guards:{isPointerNearEdge:({event:t})=>{const{edgeSizePx:e}=ai(t.ctx),n=h.Screen.read(t.ctx),r=n.width,o=n.height,s=t.screenPosition[0],i=t.screenPosition[1];return s<e||s>r-e||i<e||i>o-e},isEdgeScrollDelayPassed:({context:t,event:e})=>{const{edgeScrollDelayMs:n}=ai(e.ctx);return performance.now()-t.edgeEnterStartTime>=n}},actions:{setEdgeEnterStartTime:we({edgeEnterStartTime:()=>performance.now()}),moveCamera:({event:t})=>{const{edgeSizePx:e,edgeScrollSpeedPxPerFrame:n}=ai(t.ctx),r=h.Screen.read(t.ctx),o=h.Camera.read(t.ctx),s=r.width,i=r.height,a=t.screenPosition[0],l=t.screenPosition[1];let c=0,u=0;const f=n/o.zoom;if(a<e?c=-f:a>s-e&&(c=f),l<e?u=-f:l>i-e&&(u=f),c===0&&u===0)return;const p=h.Camera.write(t.ctx);p.left+=c,p.top+=u},resetContext:we({edgeEnterStartTime:0})}}).createMachine({id:"scrollEdges",initial:ht.Idle,context:{edgeEnterStartTime:0},states:{[ht.Idle]:{entry:"resetContext",on:{pointerMove:{guard:"isPointerNearEdge",target:ht.Waiting}}},[ht.Waiting]:{entry:"setEdgeEnterStartTime",on:{pointerMove:{guard:nr("isPointerNearEdge"),target:ht.Idle},frame:{guard:"isEdgeScrollDelayPassed",target:ht.Scrolling}}},[ht.Scrolling]:{on:{frame:[{guard:nr("isPointerNearEdge"),target:ht.Idle},{actions:"moveCamera"}]}}}}),Dv=h.defineEditorSystem({phase:"capture"},t=>{if(!ai(t).enabled)return;const e=Tt.read(t).state;if(e!==de.Dragging&&e!==de.SelectionBoxDragging)return;const n=Cl.read(t).state,r=n===ht.Waiting||n===ht.Scrolling,o=h.Controls.getButtons(t,"select"),s=h.getPointerInput(t,o,{includeFrameEvent:r});s.length!==0&&Cl.run(t,Rv,s)}),li=h.defineQuery(t=>t.with(h.Block).tracking(Ie)),zv=on({guards:{isSelectionEditable:({event:t})=>$v(t.ctx),isOverTransformBox:({event:t})=>!("intersects"in t)||t.intersects.length===0?!1:h.hasComponent(t.ctx,t.intersects[0],Ye),isOverTransformHandle:({event:t})=>!("intersects"in t)||t.intersects.length===0?!1:h.hasComponent(t.ctx,t.intersects[0],ve),selectionIsTransformable:({event:t})=>{if(t.type!=="selectionChanged")return!1;if(t.selectedEntityIds.length>1)return!0;if(t.selectedEntityIds.length===0)return!1;const e=t.selectedEntityIds[0];return h.getBlockResizeMode(t.ctx,e)!==h.ResizeMode.GroupOnly},hasEditAfterPlacing:({event:t})=>t.type!=="selectionChanged"||t.selectedEntityIds.length!==1?!1:h.hasComponent(t.ctx,t.selectedEntityIds[0],Ko)},actions:{addTransformBox:we(({context:t,event:e},n)=>{t.transformBoxId!==null&&bl.spawn(e.ctx,{transformBoxId:t.transformBoxId});const r=h.createEntity(e.ctx);return pf.spawn(e.ctx,{transformBoxId:r,skipHandles:n==null?void 0:n.skipHandles}),{transformBoxId:r}}),updateTransformBox:({context:t,event:e})=>{t.transformBoxId!==null&&vl.spawn(e.ctx,{transformBoxId:t.transformBoxId})},hideTransformBox:({context:t,event:e})=>{t.transformBoxId!==null&&mf.spawn(e.ctx,{transformBoxId:t.transformBoxId})},showTransformBox:({context:t,event:e})=>{t.transformBoxId!==null&&gf.spawn(e.ctx,{transformBoxId:t.transformBoxId})},removeTransformBox:({context:t,event:e})=>{t.transformBoxId!==null&&bl.spawn(e.ctx,{transformBoxId:t.transformBoxId})},clearTransformBoxId:we({transformBoxId:()=>null}),startTransformBoxEdit:({context:t,event:e})=>{t.transformBoxId!==null&&yf.spawn(e.ctx,{transformBoxId:t.transformBoxId})},removeEditAfterPlacing:({event:t})=>{if(t.type==="selectionChanged")for(const e of t.selectedEntityIds)h.hasComponent(t.ctx,e,Ko)&&h.removeComponent(t.ctx,e,Ko)}}}).createMachine({id:"transformBox",initial:_t.None,context:{transformBoxId:null},states:{[_t.None]:{entry:["removeTransformBox","clearTransformBoxId"],on:{selectionChanged:[{guard:Ho(["hasEditAfterPlacing","selectionIsTransformable","isSelectionEditable"]),actions:[{type:"addTransformBox",params:{skipHandles:!0}},"removeEditAfterPlacing"],target:_t.Editing},{guard:"selectionIsTransformable",target:_t.Idle}]}},[_t.Idle]:{entry:["addTransformBox"],on:{selectionChanged:[{guard:nr("selectionIsTransformable"),target:_t.None},{guard:"selectionIsTransformable",actions:"showTransformBox"},{actions:"updateTransformBox"}],pointerDown:{actions:"hideTransformBox"},pointerUp:{actions:"showTransformBox"},click:{guard:Ho(["isOverTransformBox","isSelectionEditable"]),target:_t.Editing}}},[_t.Editing]:{entry:["hideTransformBox","startTransformBoxEdit"],on:{pointerDown:{guard:Ho([nr("isOverTransformBox"),nr("isOverTransformHandle")]),target:_t.None},selectionChanged:{target:_t.None,actions:ei(({event:t})=>t)}}}}});function $v(t){const e=li.current(t);if(e.length!==1)return!1;const n=e[0],r=h.Block.read(t,n);return h.canBlockEdit(t,r.tag)}var Vv=h.defineEditorSystem({phase:"capture"},t=>{const e=[],n=li.added(t),r=li.removed(t);if(n.length>0||r.length>0){const i=[...li.current(t)],a={type:"selectionChanged",ctx:t,selectedEntityIds:i};e.push(a)}const o=h.Controls.getButtons(t,"select"),s=h.getPointerInput(t,o);e.push(...s),e.length!==0&&xl.run(t,zv,e)}),xf={};Yr(xf,{transformBoxSystem:()=>Wv});var ci=h.defineQuery(t=>t.with(h.Block,Ie)),Lv=h.defineQuery(t=>t.with(h.Block,h.Edited)),Fv="a",jv="b",_f="c",Hv="d",Wv=h.defineEditorSystem({phase:"update",priority:-100},t=>{h.on(t,bl,(e,{transformBoxId:n})=>{Zv(e,n)}),h.on(t,pf,(e,{transformBoxId:n,skipHandles:r})=>{Uv(e,n,r)}),h.on(t,vl,(e,{transformBoxId:n})=>{El(e,n)}),h.on(t,mf,(e,{transformBoxId:n})=>{Jv(e,n)}),h.on(t,gf,(e,{transformBoxId:n})=>{qv(e,n)}),h.on(t,yf,(e,{transformBoxId:n})=>{Gv(e,n)}),h.on(t,vv,Tl)});function Zv(t,e){if(!h.hasComponent(t,e,Ye)){Tl(t);return}const n=h.getBackrefs(t,e,ve,"transformBox");for(const r of n)h.removeEntity(t,r);h.removeEntity(t,e),Tl(t)}function Uv(t,e,n){h.addComponent(t,e,h.Block,{tag:"transform-box",position:[0,0],size:[0,0],rotateZ:0,rank:Fv}),h.addComponent(t,e,Ye,{}),h.addComponent(t,e,Ae,{position:[0,0],size:[0,0],rotateZ:0,fontSize:16}),n||El(t,e)}function El(t,e){if(!h.isAlive(t,e))return;const n=ci.current(t);if(n.length===0)return;let r=0;r=h.Block.read(t,n[0]).rotateZ;for(let c=1;c<n.length;c++){const u=h.Block.read(t,n[c]);if(Math.abs(r-u.rotateZ)>.01){r=0;break}}if(n.length===0)return;const s=[];for(const c of n){const u=h.Block.getCorners(t,c);s.push(...u)}if(s.length===0)return;const i=h.Block.write(t,e);if(i.rotateZ=r,E.Rect.boundPoints(i.position,i.size,r,s),!(Tt.read(t).state===de.Dragging)){if(h.hasComponent(t,e,Ae)){const c=Ae.write(t,e);c.position=i.position,c.size=i.size,c.rotateZ=r}for(const c of n){const u=h.Block.read(t,c),f=h.hasComponent(t,c,h.Text)?h.Text.read(t,c).fontSizePx:16;if(!h.hasComponent(t,c,Ae))h.addComponent(t,c,Ae,{position:u.position,size:u.size,rotateZ:u.rotateZ,flip:u.flip,fontSize:f});else{const p=Ae.write(t,c);p.position=u.position,p.size=u.size,p.rotateZ=u.rotateZ,p.flip=u.flip,p.fontSize=f}}}Kv(t,e)}function Kv(t,e){const n=h.Block.read(t,e),{position:r,size:o,rotateZ:s}=n,i=r[0],a=r[1],l=o[0],c=o[1],u=[i+l/2,a+c/2],f=12,p=2*f,m=1.25*f,g=[],y=["rotateNW","rotateNE","rotateSW","rotateSE"],k=ci.current(t);let w=h.ResizeMode.Scale;k.length===1?w=h.getBlockResizeMode(t,k[0]):k.length>1&&k.every($=>h.getBlockResizeMode(t,$)===h.ResizeMode.Free)&&(w=h.ResizeMode.Free);const v=k.every(M=>{const $=h.Block.read(t,M);return h.getBlockDef(t,$.tag).canRotate}),b=k.every(M=>{const $=h.Block.read(t,M);return h.getBlockDef(t,$.tag).canScale});let S;switch(w){case"scale":case"text":S=Et.Scale;break;case"free":S=Et.Stretch;break;default:S=Et.Scale;break}const C=h.Camera.read(t),_=l*C.zoom,x=c*C.zoom,T=Math.min(_,x),N=15;for(let M=0;M<2;M++)for(let $=0;$<2;$++)M+$!==1&&T<N/2||M+$===1&&x<N||(b&&g.push({tag:"transform-handle",kind:S,vectorX:M*2-1,vectorY:$*2-1,left:i+l*M-f/2,top:a+c*$-f/2,width:f,height:f,rotateZ:s,rank:Hv,cursorKind:M+$===1?"nesw":"nwse",scaleMultiplier:[1,1],anchor:[.5,.5]}),v&&g.push({tag:"transform-rotate",kind:Et.Rotate,vectorX:M*2-1,vectorY:$*2-1,left:i+M*l-(1-M)*p,top:a+$*c-(1-$)*p,width:p,height:p,rotateZ:s,rank:jv,cursorKind:y[M+$*2],scaleMultiplier:[.5,.5],anchor:[1-M,1-$]}));if(b)for(let M=0;M<2;M++)g.push({tag:"transform-edge",kind:S,vectorX:0,vectorY:M*2-1,left:i,top:a+c*M-m/2,width:l,height:m,rotateZ:s,rank:_f,cursorKind:"ns",scaleMultiplier:[0,1],anchor:[.5,.5]});if(b||w===h.ResizeMode.Text)for(let M=0;M<2;M++)g.push({tag:"transform-edge",kind:w===h.ResizeMode.Text?Et.Stretch:S,vectorX:M*2-1,vectorY:0,left:i+l*M-m/2,top:a,width:m,height:c,rotateZ:s,rank:_f,cursorKind:"ew",scaleMultiplier:[1,0],anchor:[.5,.5]});const I=h.getBackrefs(t,e,ve,"transformBox"),V=new Map;for(const M of I){const $=ve.read(t,M),Z=`${$.kind}-${$.vectorX}-${$.vectorY}`;V.set(Z,M)}const K=new Set;for(const M of g){const $=`${M.kind}-${M.vectorX}-${M.vectorY}`;let Z=V.get($);const ae=[M.left+M.width/2,M.top+M.height/2],X=E.Vec2.clone(ae);E.Vec2.rotateAround(X,u,s);const j=X[0]-M.width/2,q=X[1]-M.height/2;Z||(Z=h.createEntity(t),h.addComponent(t,Z,h.Block),h.addComponent(t,Z,ve),h.addComponent(t,Z,Ae),h.addComponent(t,Z,h.ScaleWithZoom));const te=h.Block.write(t,Z);te.tag=M.tag,te.position=[j,q],te.size=[M.width,M.height],te.rotateZ=M.rotateZ,te.rank=M.rank;const fe=ve.write(t,Z);fe.transformBox=e,fe.kind=M.kind,fe.vectorX=M.vectorX,fe.vectorY=M.vectorY,fe.cursorKind=M.cursorKind;const ce=Ae.write(t,Z);ce.position=[j,q],ce.size=[M.width,M.height],ce.rotateZ=M.rotateZ;const Se=h.ScaleWithZoom.write(t,Z);Se.startPosition=[j,q],Se.startSize=[M.width,M.height],E.Vec2.copy(Se.scaleMultiplier,M.scaleMultiplier),E.Vec2.copy(Se.anchor,M.anchor),K.add(Z)}for(const M of I)K.has(M)||h.removeEntity(t,M)}function Jv(t,e){if(!h.hasComponent(t,e,Ye))return;if(!h.hasComponent(t,e,h.Opacity))h.addComponent(t,e,h.Opacity,{value:0});else{const r=h.Opacity.write(t,e);r.value=0}const n=h.getBackrefs(t,e,ve,"transformBox");for(const r of n)if(!h.hasComponent(t,r,h.Opacity))h.addComponent(t,r,h.Opacity,{value:0});else{const o=h.Opacity.write(t,r);o.value=0}}function qv(t,e){if(!h.hasComponent(t,e,Ye))return;const n=ci.current(t);if(n.length===0||n.length===1&&h.getBlockResizeMode(t,n[0])===h.ResizeMode.GroupOnly)return;h.hasComponent(t,e,h.Opacity)&&h.removeComponent(t,e,h.Opacity);const r=h.getBackrefs(t,e,ve,"transformBox");for(const o of r)h.hasComponent(t,o,h.Opacity)&&h.removeComponent(t,o,h.Opacity);El(t,e)}function Gv(t,e){if(h.hasComponent(t,e,Ye)){const n=h.getBackrefs(t,e,ve,"transformBox");for(const r of n)h.removeEntity(t,r)}for(const n of ci.current(t))h.hasComponent(t,n,h.Edited)||h.addComponent(t,n,h.Edited,{})}function Tl(t){for(const e of Lv.current(t))h.hasComponent(t,e,h.Edited)&&h.removeComponent(t,e,h.Edited)}var Ef={};Yr(Ef,{selectSystem:()=>eb});var Yv=4,Tf=h.defineQuery(t=>t.with(h.Block,Ie,h.Synced)),Xv=h.defineQuery(t=>t.with(h.Block,h.Edited)),Qv=on({guards:{isThresholdReached:({context:t,event:e})=>E.Vec2.distance(t.pointingStartClient,e.screenPosition)>=Yv,isOverBlock:({event:t})=>t.intersects.length>0,isOverSyncedBlock:({event:t})=>{const e=t.ctx;for(const n of t.intersects)if(h.hasComponent(e,n,h.Synced))return!0;return!1},isNotHeldByRemote:({event:t})=>{const e=t.ctx,n=t.intersects[0];return n?!h.isHeldByRemote(e,n):!0},hasEditedBlocks:({event:t})=>Xv.current(t.ctx).length>0},actions:{setPointingStart:we({pointingStartClient:({event:t})=>t.screenPosition,pointingStartWorld:({event:t})=>t.worldPosition}),setDragStart:we({dragStart:({event:t})=>t.worldPosition}),addHeldToDragged:({context:t,event:e})=>{t.draggedEntity!==null&&ff.spawn(e.ctx,{entityId:t.draggedEntity})},removeHeldFromDragged:({context:t,event:e})=>{t.draggedEntity!==null&&hf.spawn(e.ctx,{entityId:t.draggedEntity})},setDragCursor:({event:t,context:e})=>{if(e.draggedEntity)if(h.hasComponent(t.ctx,e.draggedEntity,ve)){const n=ve.read(t.ctx,e.draggedEntity),r=n.transformBox!==null?h.Block.read(t.ctx,n.transformBox):void 0;ni.spawn(t.ctx,{contextCursorKind:n.cursorKind,contextRotation:(r==null?void 0:r.rotateZ)??0})}else ni.spawn(t.ctx,{contextCursorKind:"drag",contextRotation:0})},unsetDragCursor:({event:t})=>{ni.spawn(t.ctx,{contextCursorKind:""})},setDraggedEntity:we({draggedEntity:({event:t})=>t.intersects[0]??null,draggedEntityStart:({event:t})=>{if(!t.intersects.length)return[0,0];const e=t.intersects[0],n=h.Block.read(t.ctx,e);return[n.position[0],n.position[1]]}}),resetDragged:({context:t,event:e})=>{t.draggedEntity!==null&&(Uo.spawn(e.ctx,{entityId:t.draggedEntity,position:t.draggedEntityStart}),t.isCloning&&kl.spawn(e.ctx,{entityIds:[t.draggedEntity],seed:t.cloneGeneratorSeed}))},resetContext:we({dragStart:()=>[0,0],pointingStartClient:()=>[0,0],pointingStartWorld:()=>[0,0],draggedEntityStart:()=>[0,0],draggedEntity:()=>null,cloneGeneratorSeed:()=>crypto.randomUUID(),isCloning:()=>!1}),createSelectionBox:({event:t})=>{cf.spawn(t.ctx,void 0)},removeSelectionBox:({event:t})=>{uf.spawn(t.ctx,void 0)},updateDragged:we({isCloning:({context:t,event:e})=>{const n=e.ctx;if(t.draggedEntity===null)return!1;let r=t.draggedEntityStart[0]+e.worldPosition[0]-t.dragStart[0],o=t.draggedEntityStart[1]+e.worldPosition[1]-t.dragStart[1];const s=h.hasComponent(n,t.draggedEntity,h.Synced)||h.hasComponent(n,t.draggedEntity,Ye);if(e.shiftDown&&s){const a=Math.abs(e.worldPosition[0]-t.dragStart[0]),l=Math.abs(e.worldPosition[1]-t.dragStart[1]);a>l?o=t.draggedEntityStart[1]:r=t.draggedEntityStart[0]}s&&(r=h.Grid.snapX(n,r),o=h.Grid.snapY(n,o)),Uo.spawn(n,{entityId:t.draggedEntity,position:[r,o]});let i=t.isCloning;if(e.altDown&&s&&!t.isCloning){const a=t.draggedEntityStart[0]-r,l=t.draggedEntityStart[1]-o;i=!0;const u=h.hasComponent(n,t.draggedEntity,Ye)?Array.from(Tf.current(n)):[t.draggedEntity];nf.spawn(n,{entityIds:u,offset:[a,l],seed:t.cloneGeneratorSeed})}else if(!e.altDown&&t.isCloning){const l=h.hasComponent(n,t.draggedEntity,Ye)?Array.from(Tf.current(n)):[t.draggedEntity];kl.spawn(n,{entityIds:l,seed:t.cloneGeneratorSeed}),i=!1}return i}}),resizeSelectionBox:({context:t,event:e})=>{const n=Math.min(t.pointingStartWorld[0],e.worldPosition[0]),r=Math.min(t.pointingStartWorld[1],e.worldPosition[1]),o=Math.max(t.pointingStartWorld[0],e.worldPosition[0]),s=Math.max(t.pointingStartWorld[1],e.worldPosition[1]);df.spawn(e.ctx,{bounds:[n,r,o,s],deselectOthers:!e.shiftDown})},selectIntersect:({event:t})=>{const e=t.ctx;let n;for(const r of t.intersects)if(h.hasComponent(e,r,h.Synced)){n=r;break}n!==void 0&&(t.shiftDown?af.spawn(e,{entityId:n}):wl.spawn(e,{entityId:n,deselectOthers:!0}))},selectDragged:({context:t,event:e})=>{t.draggedEntity!==null&&h.hasComponent(e.ctx,t.draggedEntity,h.Synced)&&wl.spawn(e.ctx,{entityId:t.draggedEntity,deselectOthers:!0})},deselectAllIfShiftNotDown:({event:t})=>{t.shiftDown||Xr.spawn(t.ctx,void 0)},deselectAllIfDraggedNotSelected:({context:t,event:e})=>{t.draggedEntity!==null&&(h.hasComponent(e.ctx,t.draggedEntity,Ie)||h.hasComponent(e.ctx,t.draggedEntity,Ye)||h.hasComponent(e.ctx,t.draggedEntity,ve)||Xr.spawn(e.ctx,void 0))}}}).createMachine({id:"selection",initial:de.Idle,context:{dragStart:[0,0],pointingStartClient:[0,0],pointingStartWorld:[0,0],draggedEntityStart:[0,0],draggedEntity:null,cloneGeneratorSeed:crypto.randomUUID(),isCloning:!1},states:{[de.Idle]:{entry:["resetContext"],on:{pointerDown:[{guard:Ho(["isOverBlock","isNotHeldByRemote"]),target:de.Pointing},{actions:"deselectAllIfShiftNotDown",target:de.SelectionBoxPointing}]}},[de.Pointing]:{entry:["setPointingStart","setDraggedEntity"],on:{pointerMove:{guard:Ho(["isThresholdReached",nr("hasEditedBlocks")]),target:de.Dragging},pointerUp:[{guard:"isOverSyncedBlock",actions:"selectIntersect",target:de.Idle},{actions:"deselectAllIfShiftNotDown",target:de.Idle}],cancel:{target:de.Idle}}},[de.Dragging]:{entry:["setDragStart","addHeldToDragged","setDragCursor","deselectAllIfDraggedNotSelected"],exit:["unsetDragCursor"],on:{pointerMove:{actions:"updateDragged"},pointerUp:{actions:"selectDragged",target:de.Idle},cancel:{actions:["resetDragged","removeHeldFromDragged"],target:de.Idle}}},[de.SelectionBoxPointing]:{entry:["setPointingStart"],on:{pointerMove:{guard:"isThresholdReached",target:de.SelectionBoxDragging},pointerUp:{target:de.Idle},cancel:{target:de.Idle}}},[de.SelectionBoxDragging]:{entry:["setDragStart","createSelectionBox"],exit:"removeSelectionBox",on:{pointerMove:{actions:"resizeSelectionBox"},pointerUp:{target:de.Idle},cancel:{target:de.Idle}}}}}),eb=h.defineEditorSystem({phase:"capture",priority:100},t=>{let e=h.Controls.getButtons(t,"select");Tt.read(t).state===de.Dragging&&e.length===0&&(e=["left"]);const r=h.getPointerInput(t,e);r.length!==0&&Tt.run(t,Qv,r)}),Mf={};Yr(Mf,{blockSystem:()=>tb,dragHandlerSystem:()=>ab,selectSystem:()=>pb});var eo=h.defineQuery(t=>t.with(h.Block,Ie)),Af=h.defineQuery(t=>t.with(h.Block,h.Synced)),tb=h.defineEditorSystem({phase:"update"},t=>{h.on(t,Uo,(e,{entityId:n,position:r})=>{if(!h.hasComponent(e,n,h.Block))return;const o=h.Block.write(e,n);o.position=r}),h.on(t,wl,(e,{entityId:n,deselectOthers:r})=>{r&&Ml(e),Qr(e,n)}),h.on(t,wv,(e,{entityId:n})=>{Jo(e,n)}),h.on(t,af,(e,{entityId:n})=>{h.hasComponent(e,n,Ie)?Jo(e,n):Qr(e,n)}),h.on(t,Xr,Ml),h.on(t,ff,(e,{entityId:n})=>{if(!h.hasComponent(e,n,h.Synced)||h.hasComponent(e,n,h.Held))return;const{sessionId:r}=h.getResources(e);h.addComponent(e,n,h.Held,{sessionId:r})}),h.on(t,hf,(e,{entityId:n})=>{h.hasComponent(e,n,Ie)||h.hasComponent(e,n,h.Held)&&h.removeComponent(e,n,h.Held)}),h.on(t,lf,e=>{for(const n of Af.current(e))Qr(e,n)}),h.on(t,kv,(e,{entityId:n})=>{h.removeEntity(e,n)}),h.on(t,yl,e=>{for(const n of eo.current(e))h.removeEntity(e,n)}),h.on(t,ef,nb),h.on(t,tf,rb),h.on(t,ni,(e,n)=>{n.cursorKind!==void 0&&h.Cursor.setCursor(e,n.cursorKind,n.rotation??0),n.contextCursorKind!==void 0&&h.Cursor.setContextCursor(e,n.contextCursorKind,n.contextRotation??0),n.contextCursorKind===""&&h.Cursor.clearContextCursor(e)}),h.on(t,of,e=>{Nf(e)}),h.on(t,rf,e=>{Nf(e);for(const n of eo.current(e))h.removeEntity(e,n)}),h.on(t,sf,(e,n)=>{ob(e,n==null?void 0:n.position)}),h.on(t,nf,(e,{entityIds:n,offset:r,seed:o})=>{sb(e,n,r,o)}),h.on(t,kl,(e,{entityIds:n,seed:r})=>{ib(e,n,r)})});function Ml(t){for(const e of eo.current(t))Jo(t,e)}function nb(t){const e=[...eo.current(t)];if(e.length!==0){e.sort((n,r)=>{const o=h.Block.read(t,n),s=h.Block.read(t,r);return!o.rank&&!s.rank?0:o.rank?s.rank?o.rank<s.rank?-1:o.rank>s.rank?1:0:1:-1});for(const n of e){const r=h.Block.write(t,n);r.rank=h.RankBounds.genNext(t)}}}function rb(t){const e=[...eo.current(t)];if(e.length!==0){e.sort((n,r)=>{const o=h.Block.read(t,n),s=h.Block.read(t,r);return!o.rank&&!s.rank?0:o.rank?!s.rank||s.rank<o.rank?-1:s.rank>o.rank?1:0:1});for(const n of e){const r=h.Block.write(t,n);r.rank=h.RankBounds.genPrev(t)}}}function Nf(t){const e=[...eo.current(t)];if(e.length===0)return;const{componentsById:n}=h.getResources(t),r=new Map([...n].filter(([,c])=>c.sync==="document")),o=[],s=E.Aabb.zero();let i=!1;const a=h.Synced._getComponentId(t);for(const c of e){const u=new Map;h.hasComponent(t,c,h.Synced)&&u.set(a,h.Synced.snapshot(t,c));for(const f of t.entityBuffer.getComponentIds(c)){if(f===a)continue;const p=r.get(f);if(p){const m=p.snapshot(t,c),g=xv(t,p.schema,m);u.set(f,g)}}if(o.push(u),h.hasComponent(t,c,h.Aabb)){const{value:f}=h.Aabb.read(t,c);i?E.Aabb.union(s,f):(E.Aabb.copy(s,f),i=!0)}}qo.setEntities(t,o);const l=qo.write(t);l.count=o.length,l.center=E.Aabb.center(s)}function ob(t,e){const n=qo.getEntities(t);if(n.length===0)return;const{componentsById:r}=h.getResources(t),o=new Map([...r].filter(([,p])=>p.sync==="document")),s=qo.read(t),i=h.Synced._getComponentId(t),a=h.Block._getComponentId(t);let l;if(e)l=E.Vec2.clone(e),E.Vec2.sub(l,s.center);else{const p=h.Camera.getWorldCenter(t);l=E.Vec2.clone(p),E.Vec2.sub(l,s.center),h.Grid.snapPosition(t,l)}const c=[...n].sort((p,m)=>{const g=p.get(a),y=m.get(a),k=(g==null?void 0:g.rank)??"",w=(y==null?void 0:y.rank)??"";return k<w?-1:k>w?1:0});Ml(t);const u=new Map,f=[];for(const p of c){const m=h.createEntity(t),g=p.get(i);g!=null&&g.id&&u.set(g.id,m),h.addComponent(t,m,h.Synced,{id:crypto.randomUUID()});for(const[y,k]of p){if(y===i)continue;const w=o.get(y);if(!w)continue;const v={...k};if(y===a){const S=E.Vec2.clone(v.position);E.Vec2.add(S,l),v.position=S,v.rank=h.RankBounds.genNext(t)}const b=Ev(w.schema);if(b.length>0){for(const S of b)delete v[S];f.push({entityId:m,componentDef:w,componentData:k})}h.addComponent(t,m,w,v)}Qr(t,m)}for(const{entityId:p,componentDef:m,componentData:g}of f)Tv(t,p,m,g,u)}function sb(t,e,n,r){const{componentsById:o}=h.getResources(t),s=new Map([...o].filter(([,c])=>c.sync==="document")),i=h.Synced._getComponentId(t),a=h.Block._getComponentId(t),l=new Map;for(const c of e){if(!h.hasComponent(t,c,h.Synced))continue;const u=h.Synced.read(t,c),f=Sl(u.id,r),p=h.createEntity(t);l.set(c,p),h.addComponent(t,p,h.Synced,{id:f});for(const m of t.entityBuffer.getComponentIds(c)){if(m===i)continue;const g=s.get(m);if(!g)continue;const y={...g.snapshot(t,c)};if(m===a){const k=E.Vec2.clone(y.position);E.Vec2.add(k,n),y.position=k,y.rank=h.RankBounds.genPrev(t)}h.addComponent(t,p,g,y)}}Bf(t,l)}function ib(t,e,n){const r=new Set;for(const i of e){if(!h.hasComponent(t,i,h.Synced))continue;const a=h.Synced.read(t,i);r.add(Sl(a.id,n))}const o=[];for(const i of Af.current(t)){const a=h.Synced.read(t,i);r.has(a.id)&&o.push(i)}const s=new Map;for(const i of o){const a=h.Synced.read(t,i).id;for(const l of e){if(!h.hasComponent(t,l,h.Synced))continue;const c=h.Synced.read(t,l).id;if(Sl(c,n)===a){s.set(i,l);break}}}Bf(t,s);for(const i of o)h.removeEntity(t,i)}function Bf(t,e){for(const[n,r]of e){for(const o of h.getBackrefs(t,n,h.Connector,"startBlock"))h.Connector.write(t,o).startBlock=r;for(const o of h.getBackrefs(t,n,h.Connector,"endBlock"))h.Connector.write(t,o).endBlock=r}}var Al=h.defineQuery(t=>t.with(h.Block,Ie)),Of=h.defineQuery(t=>t.with(h.Block,Ye,Ae)),ab=h.defineEditorSystem({phase:"update"},t=>{h.on(t,Uo,(e,{entityId:n,position:r})=>{if(h.hasComponent(e,n,Ye)){lb(e,n,r);return}if(h.hasComponent(e,n,ve)){cb(e,n,r);return}})});function lb(t,e,n){const r=Ae.read(t,e),o=n[0]-r.position[0],s=n[1]-r.position[1];for(const i of Al.current(t)){if(!h.hasComponent(t,i,Ae))continue;const a=Ae.read(t,i),l=h.Block.write(t,i);l.position=[a.position[0]+o,a.position[1]+s],h.Grid.snapPosition(t,l.position)}}function cb(t,e,n){const r=ve.read(t,e);r.kind===Et.Rotate?db(t,e,n):r.kind===Et.Scale?If(t,e,n,!0):r.kind===Et.Stretch&&If(t,e,n,!1)}function db(t,e,n){const r=Of.current(t);if(r.length===0){console.warn("No transform box found for rotation");return}const o=r[0],s=h.Block.write(t,o),i=h.Block.getCenter(t,o),a=h.Block.read(t,e),l=[n[0]+a.size[0]/2,n[1]+a.size[1]/2],c=E.Vec2.angleTo(i,l),u=Ae.read(t,o),f=ve.read(t,e),p=E.Vec2.angle([s.size[0]*f.vectorX,s.size[1]*f.vectorY])+u.rotateZ;let m=c-p;const g=h.Grid.read(t),y=h.Keyboard.read(t);let k=0;if(y.shiftDown?k=g.shiftSnapAngleRad:g.enabled&&(k=g.snapAngleRad),k>0){const w=u.rotateZ%k;m=Math.round(m/k)*k-w}s.rotateZ=E.Scalar.normalizeAngle(u.rotateZ+m);for(const w of Al.current(t)){if(!h.hasComponent(t,w,Ae))continue;const v=Ae.read(t,w),b=h.Block.write(t,w);b.rotateZ=E.Scalar.normalizeAngle(v.rotateZ+m);const S=[v.position[0]+v.size[0]/2,v.position[1]+v.size[1]/2],C=E.Vec2.distance(i,S),_=E.Vec2.angleTo(i,S)+m,x=E.Vec2.fromPolar(C,_,i);b.position=[x[0]-b.size[0]/2,x[1]-b.size[1]/2],g.strict&&h.Grid.snapPosition(t,b.position)}}function If(t,e,n,r){const o=Of.current(t);if(o.length===0){console.warn("No transform box found for scaling");return}const s=o[0],i=Ae.read(t,s),a=ve.read(t,e),l=h.Block.read(t,e),c=[n[0]+l.size[0]/2,n[1]+l.size[1]/2];h.Grid.snapPosition(t,c);const u=i.rotateZ,f=[i.position[0]+i.size[0]/2,i.position[1]+i.size[1]/2],p=[-a.vectorX*i.size[0]/2,-a.vectorY*i.size[1]/2];E.Vec2.rotate(p,u);const m=[f[0]+p[0],f[1]+p[1]],g=[c[0]-m[0],c[1]-m[1]],y=E.Vec2.clone(g);E.Vec2.rotate(y,-u);let k=a.vectorX,w=a.vectorY,v=!1,b=!1;Math.sign(y[0])!==k&&k!==0&&(k=-k,v=!0),Math.sign(y[1])!==w&&w!==0&&(w=-w,b=!0);let S=Math.max(Math.abs(y[0]),1),C=Math.max(Math.abs(y[1]),1);if(r){const K=i.size[0]/i.size[1];S/C>K?C=S/K:S=C*K}else a.vectorX===0?S=i.size[0]:a.vectorY===0&&(C=i.size[1]);const _=i.size[0]>0?S/i.size[0]:1,x=i.size[1]>0?C/i.size[1]:1,T=h.Grid.read(t),N=E.Vec2.create(k*S,w*C);E.Vec2.rotate(N,u),E.Vec2.scale(N,.5);const I=E.Vec2.clone(m);E.Vec2.add(I,N);const V=[_,x];for(const K of Al.current(t)){if(!h.hasComponent(t,K,Ae))continue;const M=Ae.read(t,K),$=h.Block.write(t,K),Z=E.Vec2.clone(M.position);E.Vec2.add(Z,[M.size[0]/2,M.size[1]/2]);const ae=E.Vec2.clone(Z);E.Vec2.sub(ae,f),E.Vec2.rotate(ae,-u),E.Vec2.multiply(ae,V),v&&(ae[0]=-ae[0]),b&&(ae[1]=-ae[1]),E.Vec2.rotate(ae,u);const X=E.Vec2.clone(I);E.Vec2.add(X,ae);const j=E.Vec2.clone(M.size);E.Vec2.multiply(j,V);const q=h.getBlockResizeMode(t,K)===h.ResizeMode.Text;if(T.strict)if(q&&r){j[1]=Math.max(T.rowHeight,h.Grid.snapY(t,j[1]));const te=M.size[0]/M.size[1];j[0]=j[1]*te}else h.Grid.snapSize(t,j);if(E.Vec2.copy($.position,X),E.Vec2.sub($.position,[j[0]/2,j[1]/2]),T.strict&&h.Grid.snapPosition(t,$.position),!r&&a.vectorY===0?$.size[0]=j[0]:!r&&a.vectorX===0?$.size[1]=j[1]:E.Vec2.copy($.size,j),h.hasComponent(t,K,h.Text)){const te=a.kind===Et.Stretch,fe=h.Text.write(t,K);if(te)fe.constrainWidth=!0;else{const ce=M.size[1]>0?j[1]/M.size[1]:1;fe.fontSizePx=M.fontSize*ce}}$.flip=[v!==M.flip[0],b!==M.flip[1]]}}var ub=h.defineQuery(t=>t.with(h.Block,Ie)),Pf=h.defineQuery(t=>t.with(h.Block,ri)),fb=h.defineQuery(t=>t.with(h.Block,h.Synced,h.Aabb)),hb="z",pb=h.defineEditorSystem({phase:"update"},t=>{h.on(t,cf,e=>{const n=h.createEntity(e);h.addComponent(e,n,h.Block,{tag:"selection-box",position:[0,0],size:[0,0],rotateZ:0,rank:hb}),h.addComponent(e,n,ri,{})}),h.on(t,df,(e,{bounds:n,deselectOthers:r})=>{const o=Pf.current(e);if(o.length===0){console.warn("Can't update selection box: not found");return}const s=o[0],i=h.Block.write(e,s),a=n[0],l=n[1],c=n[2]-n[0],u=n[3]-n[1];i.position=[a,l],i.size=[c,u];const f=h.intersectAabb(e,n,fb.current(e));if(r)for(const p of ub.current(e))!f.includes(p)&&Jo(e,p);for(const p of f)Qr(e,p)}),h.on(t,uf,e=>{const n=Pf.current(e);if(n.length===0){console.warn("Can't remove selection box: not found");return}const r=n[0];h.removeEntity(e,r)})}),di=t=>Object.values(t).filter(e=>typeof e=="object"&&e!==null&&"_system"in e&&"phase"in e);function mb(t={}){return{name:vf,resources:Cv.parse(t),components:Object.values(kf).filter(e=>e instanceof h.CanvasComponentDef),singletons:Object.values(Sf).filter(e=>e instanceof h.CanvasSingletonDef),blockDefs:[{tag:"selection-box",stratum:"overlay",canRotate:!1,canScale:!1,components:[ri]},{tag:"transform-box",stratum:"overlay",canRotate:!1,canScale:!1,components:[Ye]},{tag:"transform-handle",stratum:"overlay",canRotate:!1,canScale:!1,components:[ve]},{tag:"transform-edge",stratum:"overlay",canRotate:!1,canScale:!1,components:[ve]},{tag:"transform-rotate",stratum:"overlay",canRotate:!1,canScale:!1,components:[ve]}],systems:[...di(Ef),...di(Cf),...di(Mf),...di(xf)],keybinds:[{command:rf.name,key:h.Key.X,mod:!0},{command:of.name,key:h.Key.C,mod:!0},{command:sf.name,key:h.Key.V,mod:!0},{command:yl.name,key:h.Key.Delete},{command:lf.name,key:h.Key.A,mod:!0},{command:ef.name,key:h.Key.BracketRight},{command:tf.name,key:h.Key.BracketLeft}],cursors:Sv}}function gb(t){const e=yb(t.chars),n=kb(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),o=wb(r,e.length);return{chars:t.chars,byChar:e.byChar,byCode:e.byCode,length:e.length,first:e.byCode[0],last:e.byCode[e.length-1],firstPositive:n.firstPositive,mostPositive:n.mostPositive,firstNegative:n.firstNegative,mostNegative:n.mostNegative,jitterRange:r,paddingDict:o}}function yb(t){const e={},n={},r=t.length;for(let o=0;o<r;o++){const s=t[o];e[o]=s,n[s]=o}return{byCode:e,byChar:n,length:r}}function kb(t,e,n,r){const o=t.byChar[e],s=t.byChar[n],i=t.byChar[r];if(o===void 0||s===void 0||i===void 0)throw new Error("invalid charSet");if(s-o<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(o-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:t.byCode[o],mostPositive:t.byCode[s],firstNegative:t.byCode[o-1],mostNegative:t.byCode[i]}}function wb(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var Nl=null;function Rf(){return Nl||(Nl=gb({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Cn(t,e,n){const r=n.byChar[t],o=n.byChar[e];return Math.abs(r-o)}function Bl(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Cn(n,e.firstPositive,e)+1+ui(t.slice(1),"positive",e):n===e.mostNegative?Cn(n,e.firstNegative,e)+1+ui(t.slice(1),"negative",e):n>=e.firstPositive?Cn(n,e.firstPositive,e)+2:Cn(n,e.firstNegative,e)+2}function ui(t,e,n){const r=t[0];if(r>n.mostPositive||r<n.mostNegative)throw new Error("invalid firstChar on key");return r===n.mostPositive&&e==="positive"?Cn(r,n.mostNegative,n)+1+ui(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Cn(r,n.mostPositive,n)+1+ui(t.slice(1),e,n):e==="positive"?Cn(r,n.mostNegative,n)+2:Cn(r,n.mostPositive,n)+2}function Ol(t,e,n,r,o){const s=Math.max(t.length,e.length);return n==="start"?[t.padStart(s,r),e.padStart(s,r)]:[t.padEnd(s,r),e.padEnd(s,r)]}function vb(t,e,n){const[r,o]=Ol(t,e,"end",n.first).sort(),s=zf(o,r,n);return Sb(s,n)}function Df(t,e,n){const r=n.length,[o,s]=Ol(t,e,"start",n.first),i=[];let a=0;for(let l=o.length-1;l>=0;l--){const c=n.byChar[o[l]],u=n.byChar[s[l]],f=c+u+a;a=Math.floor(f/r);const p=f%r;i.unshift(n.byCode[p])}return a>0&&i.unshift(n.byCode[a]),i.join("")}function zf(t,e,n,r=!0){const o=n.length,[s,i]=Ol(t,e,"start",n.first),a=[];let l=0;for(let c=s.length-1;c>=0;c--){let u=n.byChar[s[c]];const f=n.byChar[i[c]]+l;u<f?(l=1,u+=o):l=0;const p=u-f;a.unshift(n.byCode[p])}if(l>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;r&&a.length>1&&a[0]===n.first;)a.shift();return a.join("")}function $f(t,e){return Df(t,e.byCode[1],e)}function Il(t,e){return zf(t,e.byCode[1],e,!1)}function bb(t,e){if(t===0)return e.byCode[0];let n="";const r=e.length;for(;t>0;)n=e.byCode[t%r]+n,t=Math.floor(t/r);return n}function Sb(t,e){let n=0;const r=t.length,o=e.length;for(let s=0;s<r;s++)n+=e.byChar[t[s]]*Math.pow(o,r-s-1);return n}function Cb(t){return t.firstPositive+t.byCode[0]}function xb(t,e){return Bl(t,e)===t.length}function _b(t,e){fi(t,e)}function fi(t,e){const n=Ff(t,e),r=Bl(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function Vf(t,e){if(!xb(t,e))throw new Error("invalid integer length: "+t)}function Lf(t,e){Vf(t,e);const[n,r]=jf(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=$f(r,e);return n+i}const s=Tb(n,e);return Hf(s,"lower",e)}function Eb(t,e){Vf(t,e);const[n,r]=jf(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Il(r,e);return n+i}const s=Mb(n,e);return Hf(s,"upper",e)}function Ff(t,e){let n=0;if(t[0]===e.mostPositive)for(;t[n]===e.mostPositive;)n=n+1;if(t[0]===e.mostNegative)for(;t[n]===e.mostNegative;)n=n+1;return t.slice(0,n+1)}function jf(t,e){const n=Ff(t,e),r=t.slice(n.length);return[n,r]}function Tb(t,e){const n=t>=e.firstPositive,r=$f(t,e),o=t[t.length-1]===e.mostPositive,s=r[r.length-1]===e.mostPositive;return n&&s?r+e.mostNegative:!n&&o?t.slice(0,t.length-1):r}function Mb(t,e){const n=t>=e.firstPositive,r=t[t.length-1]===e.mostNegative;if(n&&r){const o=t.slice(0,t.length-1);return Il(o,e)}return!n&&r?t+e.mostPositive:Il(t,e)}function Hf(t,e,n){const r=Bl(t,n),o=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+o.repeat(r-t.length)}function Wf(t,e){const n=bb(Math.floor(Math.random()*e.jitterRange),e);return Df(t,n,e)}function Ab(t,e,n){const r=t.padEnd(t.length+e,n.first);return Wf(r,n)}function Nb(t,e,n){const r=fi(t,n),o=Lf(r,n);let s=0;const i=vb(t,o,n);return i<n.jitterRange+1&&(s=Math.max(s,Bb(i,n))),s}function Bb(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([o,s])=>s>n);return r?parseInt(r[0]):0}function Ob(t,e,n=Rf()){if(t!==null&&_b(t,n),t===null&&e===null)return Cb(n);if(t===null){const r=fi(e,n);return Eb(r,n)}{const r=fi(t,n);return Lf(r,n)}}function Ib(t,e,n=Rf()){const r=Ob(t,e,n),o=Nb(r,e,n);return o?Ab(r,o,n):Wf(r,n)}var Pb=Object.defineProperty,Zf=(t,e)=>{for(var n in e)Pb(t,n,{get:e[n],enumerable:!0})},Uf={};Zf(Uf,{ArcArrow:()=>ue,ArrowHandle:()=>At,ArrowTerminal:()=>Go,ElbowArrow:()=>he});var Rb="arrows",Kf="zzzzz",Db=24,Jf=50,Pl=4,zb=4,Rl=24,xn=24,qf=40,Mt={Idle:"idle",Pointing:"pointing",Dragging:"dragging"},to={None:"none",Idle:"idle"},ge={Start:"start",Middle:"middle",End:"end"},pe={None:"none",V:"v",Delta:"delta",Circle:"circle",Diamond:"diamond"},sr={Arc:"arc",Elbow:"elbow"},hi=0,pi=1,mi=2,gi=3,yi=4,ki=5,Dl=6,$b={value:h.field.tuple(h.field.float64(),7).default([0,0,.5,.5,1,1,Pl]),startArrowHead:h.field.enum(pe).default(pe.None),endArrowHead:h.field.enum(pe).default(pe.V),trimStart:h.field.float64().default(0),trimEnd:h.field.float64().default(1)},Vb=class extends h.CanvasComponentDef{constructor(){super({name:"arcArrow",sync:"document"},$b)}getA(t,e){const{value:n}=this.read(t,e);return[n[hi],n[pi]]}getB(t,e){const{value:n}=this.read(t,e);return[n[mi],n[gi]]}getC(t,e){const{value:n}=this.read(t,e);return[n[yi],n[ki]]}getThickness(t,e){const{value:n}=this.read(t,e);return n[Dl]}setA(t,e,n){const{value:r}=this.write(t,e);r[hi]=n[0],r[pi]=n[1]}setB(t,e,n){const{value:r}=this.write(t,e);r[mi]=n[0],r[gi]=n[1]}setC(t,e,n){const{value:r}=this.write(t,e);r[yi]=n[0],r[ki]=n[1]}setThickness(t,e,n){const{value:r}=this.write(t,e);r[Dl]=n}getWorldArc(t,e){const{value:n}=this.read(t,e),r=h.Block.uvToWorld(t,e,[n[hi],n[pi]]),o=h.Block.uvToWorld(t,e,[n[mi],n[gi]]),s=h.Block.uvToWorld(t,e,[n[yi],n[ki]]);return[r[0],r[1],o[0],o[1],s[0],s[1],n[Dl]]}getWorldPoints(t,e){const{value:n}=this.read(t,e);return{a:h.Block.uvToWorld(t,e,[n[hi],n[pi]]),b:h.Block.uvToWorld(t,e,[n[mi],n[gi]]),c:h.Block.uvToWorld(t,e,[n[yi],n[ki]])}}isCurved(t,e){const{value:n}=this.read(t,e);return!E.Arc.isCollinear(n)}directionAt(t,e,n){const r=this.getWorldArc(t,e);return E.Arc.directionAt(r,n)}pointAt(t,e,n){const r=this.getWorldArc(t,e);return E.Arc.parametricToPoint(r,n)}length(t,e){const n=this.getWorldArc(t,e);return E.Arc.length(n)}containsPoint(t,e,n){const r=this.getWorldArc(t,e);return E.Arc.containsPoint(r,n)}},ue=new Vb,At=h.defineCanvasComponent({name:"arrowHandle"},{kind:h.field.enum(ge).default(ge.Start),arrowEntity:h.field.ref()}),Go=h.defineCanvasComponent({name:"arrowTerminal"},{blockEntity:h.field.ref(),terminalIndex:h.field.uint8().default(0)}),Lb={points:h.field.buffer(h.field.float64()).size(Rl*2),pointCount:h.field.uint8().default(0),thickness:h.field.float32().default(Pl),startArrowHead:h.field.enum(pe).default(pe.None),endArrowHead:h.field.enum(pe).default(pe.V),trimStart:h.field.float64().default(0),trimEnd:h.field.float64().default(1)},Fb=class extends h.CanvasComponentDef{constructor(){super({name:"elbowArrow",sync:"document"},Lb)}snapshot(t,e){const n=super.snapshot(t,e);return n.points=n.points.slice(0,n.pointCount*2),n}getPoint(t,e,n){const{points:r}=this.read(t,e);return[r[n*2],r[n*2+1]]}setPoint(t,e,n,r){const{points:o}=this.write(t,e);o[n*2]=r[0],o[n*2+1]=r[1]}getPoints(t,e){const{points:n,pointCount:r}=this.read(t,e),o=[];for(let s=0;s<r;s++)o.push([n[s*2],n[s*2+1]]);return o}setPoints(t,e,n){if(n.length>Rl)throw new Error(`ElbowArrow points exceed capacity of ${Rl}`);const r=this.write(t,e);for(let o=0;o<n.length;o++)r.points[o*2]=n[o][0],r.points[o*2+1]=n[o][1];r.pointCount=n.length}getStartWorld(t,e){const n=this.getPoint(t,e,0);return h.Block.uvToWorld(t,e,n)}getEndWorld(t,e){const{pointCount:n}=this.read(t,e),r=this.getPoint(t,e,n-1);return h.Block.uvToWorld(t,e,r)}getWorldPoints(t,e){return this.getPoints(t,e).map(r=>h.Block.uvToWorld(t,e,r))}getThickness(t,e){const{thickness:n}=this.read(t,e);return n}},he=new Fb,Gf={};Zf(Gf,{ArrowDrawState:()=>zl,ArrowTransformState:()=>Yf});var zl=h.defineEditorState("arrowDrawState",{state:h.field.string().max(16).default(Mt.Idle),activeArrow:h.field.ref(),kind:h.field.enum(sr).default(sr.Elbow),pointingStartClient:h.field.tuple(h.field.int32(),2).default([0,0]),pointingStartWorld:h.field.tuple(h.field.float64(),2).default([0,0])}),Yf=h.defineEditorState("arrowTransformState",{state:h.field.string().max(16).default(to.None),activeArrow:h.field.ref()}),Xf=h.defineCommand("arrows-add-arrow");h.defineCommand("arrows-draw-arrow");var Qf=h.defineCommand("arrows-remove-arrow");h.defineCommand("arrows-complete-arrow");var eh=h.defineCommand("arrows-add-or-update-transform-handles"),th=h.defineCommand("arrows-remove-transform-handles"),nh=h.defineCommand("arrows-hide-transform-handles"),rh=h.defineCommand("arrows-show-transform-handles"),jb=on({guards:{isThresholdReached:({context:t,event:e})=>E.Vec2.distance(t.pointingStartClient,e.screenPosition)>=zb},actions:{setPointingStart:we({pointingStartClient:({event:t})=>[t.screenPosition[0],t.screenPosition[1]],pointingStartWorld:({event:t})=>[t.worldPosition[0],t.worldPosition[1]]}),resetContext:we({pointingStartClient:()=>[0,0],pointingStartWorld:()=>[0,0],activeArrow:()=>null}),addArrow:we({activeArrow:({context:t,event:e})=>{const n=t.kind,r=t.pointingStartWorld,o=h.createEntity(e.ctx);return Xf.spawn(e.ctx,{entityId:o,position:r,kind:n}),o}}),removeArrow:we({activeArrow:({context:t,event:e})=>(t.activeArrow&&Qf.spawn(e.ctx,{entityId:t.activeArrow}),null)}),exitArrowControl:({event:t})=>{const e=h.Controls.write(t.ctx);e.leftMouseTool="select";const n=h.Cursor.write(t.ctx);n.cursorKind="select"},deselectAll:({event:t})=>{Xr.spawn(t.ctx)}}}).createMachine({id:"arrowDraw",initial:Mt.Idle,context:{activeArrow:null,kind:sr.Elbow,pointingStartClient:[0,0],pointingStartWorld:[0,0]},states:{[Mt.Idle]:{entry:"resetContext",on:{pointerDown:[{actions:"deselectAll",target:Mt.Pointing}]}},[Mt.Pointing]:{entry:"setPointingStart",on:{pointerMove:{guard:"isThresholdReached",target:Mt.Dragging},pointerUp:{target:Mt.Idle},cancel:{target:Mt.Idle}}},[Mt.Dragging]:{entry:"addArrow",exit:"exitArrowControl",on:{pointerUp:{target:Mt.Idle},cancel:{actions:"removeArrow",target:Mt.Idle}}}}}),Hb=h.defineEditorSystem({phase:"capture",priority:100},t=>{const e=h.Controls.getButtons(t,"arc-arrow","elbow-arrow");if(e.length===0)return;const n=h.getPointerInput(t,e);if(n.length===0)return;const r=h.Controls.read(t).leftMouseTool,o=zl.write(t);o.kind=r==="elbow-arrow"?sr.Elbow:sr.Arc,zl.run(t,jb,n)}),$l=h.defineQuery(t=>t.with(h.Block).tracking(Ie)),Wb=on({guards:{selectingSingleArrow:({event:t})=>{if(!("selectedEntities"in t)||t.selectedEntities.length!==1)return!1;const e=t.selectedEntities[0];return h.hasComponent(t.ctx,e,ue)||h.hasComponent(t.ctx,e,he)}},actions:{setActiveArrow:we({activeArrow:({event:t})=>!("selectedEntities"in t)||t.selectedEntities.length===0?null:t.selectedEntities[0]}),addOrUpdateTransformHandles:({context:t,event:e})=>{t.activeArrow&&eh.spawn(e.ctx,{arrowEntityId:t.activeArrow})},removeTransformHandles:({event:t})=>{th.spawn(t.ctx,{})},hideTransformHandles:({event:t})=>{nh.spawn(t.ctx,{})},showTransformHandles:({event:t})=>{rh.spawn(t.ctx,{})}}}).createMachine({id:"arrowTransform",initial:to.None,context:{activeArrow:null},states:{[to.None]:{entry:"removeTransformHandles",on:{selectionChanged:[{guard:"selectingSingleArrow",actions:"setActiveArrow",target:to.Idle}]}},[to.Idle]:{entry:"addOrUpdateTransformHandles",on:{selectionChanged:[{guard:nr("selectingSingleArrow"),target:to.None},{actions:["setActiveArrow","addOrUpdateTransformHandles"]}],pointerDown:{actions:"hideTransformHandles"},pointerUp:{actions:"showTransformHandles"}}}}}),Zb=h.defineEditorSystem({phase:"capture",priority:99},t=>{const e=Ub(t);e.length!==0&&Yf.run(t,Wb,e)});function Ub(t){const e=[],n=$l.added(t),r=$l.removed(t);if(n.length>0||r.length>0){const i=[...$l.current(t)];e.push({type:"selectionChanged",ctx:t,selectedEntities:i})}const o=h.Controls.getButtons(t,"select"),s=h.getPointerInput(t,o);return e.push(...s),e}var Kb=class{constructor(){this.heap=[],this.positions=new Map}parent(t){return Math.floor((t-1)/2)}leftChild(t){return 2*t+1}rightChild(t){return 2*t+2}swap(t,e){this.positions.set(this.heap[t].id,e),this.positions.set(this.heap[e].id,t),[this.heap[t],this.heap[e]]=[this.heap[e],this.heap[t]]}bubbleUp(t){for(;t>0&&this.heap[this.parent(t)].distance>this.heap[t].distance;)this.swap(t,this.parent(t)),t=this.parent(t)}bubbleDown(t){let e=t;const n=this.leftChild(t);n<this.heap.length&&this.heap[n].distance<this.heap[e].distance&&(e=n);const r=this.rightChild(t);r<this.heap.length&&this.heap[r].distance<this.heap[e].distance&&(e=r),t!==e&&(this.swap(t,e),this.bubbleDown(e))}insert(t,e){this.heap.push({id:t,distance:e});const n=this.heap.length-1;this.positions.set(t,n),this.bubbleUp(n)}extractMin(){if(this.heap.length===0)return null;const t=this.heap[0],e=this.heap.pop();return this.positions.delete(t.id),this.heap.length>0&&(this.heap[0]=e,this.positions.set(e.id,0),this.bubbleDown(0)),t}decreaseKey(t,e){const n=this.positions.get(t);n!==void 0&&(this.heap[n].distance=e,this.bubbleUp(n))}isEmpty(){return this.heap.length===0}contains(t){return this.positions.has(t)}};function Jb(t,e,n,r,o,s,i){return new qb(t,e,n,s,i).calculate(r,o)}var qb=class{constructor(t,e,n,r,o){this.ctx=t,this.padding=r,this.rotation=o;const s=E.Vec2.midPoint(e,n);this.toLocal=E.Mat2.fromTranslation(-s[0],-s[1]),E.Mat2.rotate(this.toLocal,-o),this.toWorld=E.Mat2.fromRotation(o),E.Mat2.translate(this.toWorld,s[0],s[1]),this.localStart=this.transformToLocal(e),this.localEnd=this.transformToLocal(n)}transformToLocal(t){const e=E.Vec2.clone(t);return E.Mat2.transformPoint(this.toLocal,e),e}transformToWorld(t){const e=E.Vec2.clone(t);return E.Mat2.transformPoint(this.toWorld,e),e}calculate(t,e){const n=this.calculateRay(this.localStart,this.localEnd,t),r=this.calculateRay(this.localEnd,this.localStart,e);let o;if(t&&e){const s=this.isPointInsideBlockMargin(this.localStart,e),i=this.isPointInsideBlockMargin(this.localEnd,t);s||i?o=Yo(E.Ray.origin(n),E.Ray.origin(r)):o=this.routeBlockToBlock(t,e,n,r)}else t&&!e?this.isPointInsideBlockMargin(this.localEnd,t)?o=Yo(E.Ray.origin(n),this.localEnd):o=this.routeBlockToPoint(t,n,this.localEnd):!t&&e?this.isPointInsideBlockMargin(this.localStart,e)?o=Yo(this.localStart,E.Ray.origin(r)):o=this.routeBlockToPoint(e,r,this.localStart).reverse():o=Yo(E.Ray.origin(n),this.localEnd);for(let s=0;s<o.length;s++)o[s]=this.transformToWorld(o[s]);return o}getBlockAabb(t){const e=h.Block.read(this.ctx,t),n=[e.position[0]+e.size[0]/2,e.position[1]+e.size[1]/2],r=this.transformToLocal(n),o=(e.rotateZ||0)-this.rotation,s=[r[0]-e.size[0]/2,r[1]-e.size[1]/2],i=[0,0,0,0];return E.Rect.getAabb(s,e.size,o,i),i}isPointInsideBlockMargin(t,e){const n=this.getBlockAabb(e);return E.Aabb.pad(n,this.padding),E.Aabb.containsPoint(n,t)}routeBlockToBlock(t,e,n,r){const o=this.getBlockAabb(t),s=this.getBlockAabb(e);E.Aabb.pad(o,this.padding),E.Aabb.pad(s,this.padding),Qb(o,s);const i=eS(o,s),a=wi(n,i),l=wi(r,i),c=E.Ray.origin(n),u=E.Ray.origin(r);if(a===null||l===null)return console.warn("[routeBlockToBlock] Failed to add start or end node to graph"),[c,u];const f=ah(i,a,l);if(f===null)return[c,u];const p=[c];for(const m of f){const g=i.find(y=>y.id===m);g&&p.push(g.coords)}return p.push(u),Gb(p),oh(p),Yb(p),p}routeBlockToPoint(t,e,n){const r=E.Ray.origin(e),o=E.Ray.direction(e),s=vi(r,n);if(o[0]===s[0]&&o[1]===s[1])return Yo(r,n);const i=this.getBlockAabb(t);E.Aabb.pad(i,this.padding);const a=E.Ray.fromPoints(n,[-s[0],-s[1]]),l=E.Ray.intersectAabb(a,i);l.length===0&&E.Aabb.expand(i,n);const c=E.Aabb.corners(i),u=sh(c),f=wi(a,u),p=wi(e,u);if(p===null||f===null)return[r,n];const m=ah(u,p,f);if(m===null)return[r,n];const g=[r];for(const y of m){const k=u.find(w=>w.id===y);k&&g.push(k.coords)}return l.length>0&&g.push(n),oh(g),g}calculateRay(t,e,n){let r;return n?r=this.exitClosestSide(t,n).direction:r=vi(t,e),E.Ray.fromPoints(t,r)}exitClosestSide(t,e){const n=h.Block.read(this.ctx,e),r=h.Block.getCenter(this.ctx,e),o=this.transformToWorld(t),s=E.Vec2.clone(o),i=E.Vec2.clone(r);E.Vec2.sub(i,o),E.Vec2.scale(i,.01),E.Vec2.add(s,i);const a=[[0,-1],[1,0],[0,1],[-1,0]],l=a.map(g=>{const y=E.Vec2.clone(g);return E.Vec2.rotate(y,this.rotation),y}),c=[];for(let g=0;g<l.length;g++){const y=l[g],k=E.Ray.fromPoints(s,y),w=E.Ray.intersectRect(k,n.position,n.size,n.rotateZ);w.length!==0&&c.push({direction:a[g],distance:w[0].distance})}if(c.length===0)return console.error("[exitClosestSide] No valid exit direction found!",{point:t,nudgedPoint:s,blockPosition:n.position,blockSize:n.size,blockRotateZ:n.rotateZ,center:r}),{direction:[0,-1],distance:0};c.sort((g,y)=>g.distance-y.distance);const u=c[0],f=(o[0]-n.position[0])/n.size[0],p=(o[1]-n.position[1])/n.size[1],m=.2;if(Math.abs(f-.5)<m&&Math.abs(p-.5)<m){const g=vi(t,this.localEnd),y=c.find(k=>k.direction[0]===g[0]&&k.direction[1]===g[1]);if(y)return y}return u}};function Yo(t,e){const n=[];n.push(t);const r=e[0]-t[0],o=e[1]-t[1];if(E.Scalar.approxEqual(o,0)||E.Scalar.approxEqual(r,0))return n.push(e),n;const s=vi(t,e);let i;s[0]===1?i=r:s[0]===-1?i=-r:s[1]===1?i=o:i=-o;const a=[t[0]+s[0]*i/2,t[1]+s[1]*i/2];return n.push(a),s[0]===0?n.push([e[0],a[1]]):n.push([a[0],e[1]]),n.push(e),n}function Gb(t){if(t.length<2)return;const e=[t[0]];for(let n=1;n<t.length;n++){const r=e[e.length-1],o=t[n],s=E.Scalar.approxEqual(r[0],o[0]),i=E.Scalar.approxEqual(r[1],o[1]);(!s||!i)&&e.push(o)}t.length=0,t.push(...e)}function oh(t){if(t.length<3)return;const e=[];for(let n=1;n<t.length-1;n++){const r=t[n-1],o=t[n],s=t[n+1],i=E.Scalar.approxEqual(r[0],o[0])&&E.Scalar.approxEqual(o[0],s[0]),a=E.Scalar.approxEqual(r[1],o[1])&&E.Scalar.approxEqual(o[1],s[1]);(i||a)&&e.push(n)}for(let n=e.length-1;n>=0;n--)t.splice(e[n],1)}function Yb(t){if(t.length<3)return;const e=[];for(let r=1;r<t.length-1;r++){const o=t[r-1],s=t[r],i=t[r+1],a=Xb(o,s,i);e.push(a)}const n=[];for(let r=1;r<e.length-1;r++){const o=e[r-1],s=e[r],i=e[r+1];if(o==="left"&&s==="right"&&i==="left"||o==="right"&&s==="left"&&i==="right"){const l=Math.abs(t[r+1][0]-t[r][0])<1e-6,c=Math.abs(t[r+1][1]-t[r][1])<1e-6;if(l)t[r+1][0]=t[r+2][0],t[r+1][1]=t[r][1];else if(c)t[r+1][0]=t[r][0],t[r+1][1]=t[r+2][1];else continue;n.push(r),n.push(r+2)}}for(let r=n.length-1;r>=0;r--)t.splice(n[r],1)}function Xb(t,e,n){return(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0])>0?"left":"right"}function Qb(t,e){if(!E.Aabb.intersects(t,e)){if(t[2]<e[0]){const n=(t[2]+e[0])/2;t[2]=n,e[0]=n}else if(e[2]<t[0]){const n=(e[2]+t[0])/2;e[2]=n,t[0]=n}if(t[3]<e[1]){const n=(t[3]+e[1])/2;t[3]=n,e[1]=n}else if(e[3]<t[1]){const n=(e[3]+t[1])/2;e[3]=n,t[1]=n}}}function sh(t){const e=t.map((n,r)=>({id:r,connections:[],distances:{},coords:n}));return ih(e,0),ih(e,1),e}function ih(t,e){const n={},r=1-e;for(const o of t){const s=Math.round(o.coords[e]);n[s]||(n[s]=[]),n[s].push(o)}for(const o of Object.values(n)){o.sort((s,i)=>s.coords[r]-i.coords[r]);for(let s=0;s<o.length-1;s++){const i=o[s],a=o[s+1];i.connections.push(a.id),a.connections.push(i.id);const l=Math.abs(a.coords[r]-i.coords[r]);i.distances[a.id]=l,a.distances[i.id]=l}}}function eS(t,e){if(!E.Aabb.intersects(t,e))return[];const n=[],r=E.Aabb.corners(t),o=E.Aabb.corners(e);for(const c of r)E.Aabb.containsPoint(e,c,!1)||n.push(c);for(const c of o)E.Aabb.containsPoint(t,c,!1)||n.push(c);const s=E.Aabb.clone(t);E.Aabb.intersection(s,e);const i=E.Aabb.corners(s);for(const c of i)E.Aabb.containsPoint(t,c,!1)||E.Aabb.containsPoint(e,c,!1)||n.push(c);const a=[],l=new Set;for(const c of n){const u=c.map(Math.round).join(",");l.has(u)||(a.push(c),l.add(u))}return sh(a)}function wi(t,e){const n=E.Ray.origin(t),r=e.find(m=>m.coords[0]===n[0]&&m.coords[1]===n[1]);if(r)return r.id;let o=null,s=-1,i=-1;for(const m of e)for(const g of m.connections){if(m.id>=g)continue;const y=e.find(w=>w.id===g);if(!y)continue;const k=E.Ray.intersectSegment(t,m.coords,y.coords);k&&(o===null||k.distance<o.distance)&&(o=k,s=m.id,i=g)}if(!o||s===-1||i===-1)return console.warn("[intersectRayAndAddNode] No intersection found for ray",t,o,s,i),null;const a=e.length,l={id:a,connections:[],distances:{},coords:o.point},c=e[s],u=e[i],f=Math.hypot(o.point[0]-c.coords[0],o.point[1]-c.coords[1]),p=Math.hypot(o.point[0]-u.coords[0],o.point[1]-u.coords[1]);return l.connections.push(s,i),l.distances[s]=f,l.distances[i]=p,c.connections.push(a),c.distances[a]=f,u.connections.push(a),u.distances[a]=p,c.connections=c.connections.filter(m=>m!==i),delete c.distances[i],u.connections=u.connections.filter(m=>m!==s),delete u.distances[s],e.push(l),a}function ah(t,e,n){const r={},o={},s=new Kb;for(const i of t)r[i.id]=Number.POSITIVE_INFINITY,o[i.id]=null;for(r[e]=0,s.insert(e,0);!s.isEmpty();){const i=s.extractMin();if(!i)break;const a=i.id;if(a===n){const c=[];let u=n;for(;u!==null;)c.unshift(u),u=o[u];return c}const l=t.find(c=>c.id===a);if(l)for(const c of l.connections){const u=r[a]+(l.distances[c]||1);u<r[c]&&(r[c]=u,o[c]=a,s.contains(c)?s.decreaseKey(c,u):s.insert(c,u))}}return null}function vi(t,e){const n=e[0]-t[0],r=e[1]-t[1];return Math.abs(n)>Math.abs(r)?[Math.sign(n),0]:[0,Math.sign(r)]}function lh(t,e){if(t.length===0)return null;let n=t[0],r=E.Vec2.distanceSq(t[0],e);for(let o=1;o<t.length;o++){const s=E.Vec2.distanceSq(t[o],e);s<r&&(r=s,n=t[o])}return n}function tS(t,e,n){const r=[t[0]-n[0],t[1]-n[1]],o=[e[0]-n[0],e[1]-n[1]],s=Math.atan2(r[1],r[0]);let a=Math.atan2(o[1],o[0])-s;a>Math.PI&&(a-=2*Math.PI),a<-Math.PI&&(a+=2*Math.PI);const l=Math.hypot(r[0],r[1]),u=Math.hypot(o[0],o[1])-l;return{angle:a,distance:u}}function nS(t,e,n,r){const o=Math.atan2(t[1]-r[1],t[0]-r[0])+e,s=Math.hypot(t[0]-r[0],t[1]-r[1])+n;return[r[0]+Math.cos(o)*s,r[1]+Math.sin(o)*s]}var ch=20,rS=h.defineQuery(t=>t.tracking(ue,h.Connector)),oS=h.defineQuery(t=>t.tracking(he,h.Connector)),sS=h.defineEditorSystem({phase:"update",priority:-10},t=>{for(const e of rS.addedOrChanged(t))iS(t,e);for(const e of oS.addedOrChanged(t))aS(t,e)});function iS(t,e){h.hasComponent(t,e,h.HitGeometry)||h.addComponent(t,e,h.HitGeometry,{});const n=ue.read(t,e),r=E.Arc.clone(n.value);r[6]=Math.max(r[6],ch),h.HitGeometry.clear(t,e),h.HitGeometry.addArc(t,e,r),lS(t,e)}function aS(t,e){h.hasComponent(t,e,h.HitGeometry)||h.addComponent(t,e,h.HitGeometry,{});const n=he.read(t,e),r=Math.max(n.thickness,ch),o=he.getPoints(t,e),s=h.HitGeometry.write(t,e),i=Math.min(o.length-1,h.MAX_HIT_CAPSULES);s.capsuleCount=i,s.arcCount=0;for(let a=0;a<i;a++){const l=o[a],c=o[a+1],u=E.Capsule.create(l[0],l[1],c[0],c[1],r/2);h.HitGeometry.setCapsuleAt(t,e,a,u)}cS(t,e)}function lS(t,e){const n=h.Connector.read(t,e),r=ue.getWorldArc(t,e),{a:o,c:s}=ue.getWorldPoints(t,e);let i=dh(t,n.startBlock,r,o),a=dh(t,n.endBlock,r,s);1-a-i<.1&&(i=0,a=0);const l=ue.read(t,e);if(!E.Scalar.approxEqual(l.trimStart,i)||!E.Scalar.approxEqual(l.trimEnd,a)){const u=ue.write(t,e);u.trimStart=i,u.trimEnd=a}const c=h.HitGeometry.read(t,e);for(let u=0;u<c.arcCount;u++){const f=h.HitGeometry.getArcAt(t,e,u);E.Arc.trim(f,i,1-a),h.HitGeometry.setArcAt(t,e,u,f)}}function dh(t,e,n,r){if(!e)return 0;const o=h.Block.getCorners(t,e),s=E.Arc.intersectRect(n,o);if(s.length===0)return 0;const i=lh(s,r);return i?E.Arc.pointToParametric(n,i)??0:0}function cS(t,e){const n=h.Connector.read(t,e),r=he.getWorldPoints(t,e),o=r.length-1;if(o<1)return;const s=r[0],i=r[r.length-1],a=r[1],l=r[r.length-2],c=uh(t,n.startBlock,s,a),u=uh(t,n.endBlock,i,l),f=he.read(t,e);if(!E.Scalar.approxEqual(f.trimStart,c)||!E.Scalar.approxEqual(f.trimEnd,u)){const y=he.write(t,e);y.trimStart=c,y.trimEnd=u}const p=h.HitGeometry.getCapsuleAt(t,e,0);E.Capsule.trim(p,c,1),h.HitGeometry.setCapsuleAt(t,e,0,p);const m=o-1,g=h.HitGeometry.getCapsuleAt(t,e,m);E.Capsule.trim(g,0,1-u),h.HitGeometry.setCapsuleAt(t,e,m,g)}function uh(t,e,n,r){if(!e)return 0;const o=h.Block.getCorners(t,e),s=[];for(let f=0;f<4;f++){const p=o[f],m=o[(f+1)%4],g=dS(n,r,p,m);g&&s.push(g)}if(s.length===0)return 0;const i=lh(s,n);if(!i)return 0;const a=r[0]-n[0],l=r[1]-n[1],c=Math.hypot(a,l);if(c<.001)return 0;const u=((i[0]-n[0])*a+(i[1]-n[1])*l)/(c*c);return Math.max(0,Math.min(1,u))}function dS(t,e,n,r){const o=e[0]-t[0],s=e[1]-t[1],i=r[0]-n[0],a=r[1]-n[1],l=o*a-s*i;if(Math.abs(l)<1e-10)return null;const c=n[0]-t[0],u=n[1]-t[1],f=(c*a-u*i)/l,p=(c*s-u*o)/l;return f>=0&&f<=1&&p>=0&&p<=1?[t[0]+f*o,t[1]+f*s]:null}var bi=h.defineQuery(t=>t.with(At,h.Block)),uS=h.defineQuery(t=>t.with(h.Synced,h.Aabb).tracking(h.Block)),fh=h.defineQuery(t=>t.with(Go,h.Block)),fS=h.defineEditorSystem({phase:"update"},t=>{h.on(t,Xf,(e,{entityId:n,position:r,kind:o})=>{pS(e,n,r,o)}),h.on(t,Qf,(e,{entityId:n})=>{mS(e,n)}),h.on(t,eh,(e,{arrowEntityId:n})=>{Vl(e,n)}),h.on(t,th,e=>{vS(e)}),h.on(t,nh,e=>{Ll(e)}),h.on(t,rh,e=>{bS(e)}),h.on(t,Uo,(e,{entityId:n,position:r})=>{gS(e,n,r)}),hS(t)});function hS(t){const e=uS.addedOrChangedOrRemoved(t);if(e.length===0)return;const n=new Set;for(const r of e){const o=h.getBackrefs(t,r,h.Connector,"startBlock",!1);for(const i of o)n.has(i)||(n.add(i),hh(t,i));const s=h.getBackrefs(t,r,h.Connector,"endBlock",!1);for(const i of s)n.has(i)||(n.add(i),hh(t,i))}}function hh(t,e){const n=h.Connector.read(t,e);if(h.hasComponent(t,e,ue)){const{a:r,c:o}=ue.getWorldPoints(t,e);let s=r,i=o;n.startBlock!==null&&(s=h.Block.uvToWorld(t,n.startBlock,n.startBlockUv),Fl(t,e,ge.Start,s)),n.endBlock!==null&&(i=h.Block.uvToWorld(t,n.endBlock,n.endBlockUv),Fl(t,e,ge.End,i))}else if(h.hasComponent(t,e,he)){if(n.startBlock!==null){const r=h.Block.uvToWorld(t,n.startBlock,n.startBlockUv);jl(t,e,ge.Start,r)}if(n.endBlock!==null){const r=h.Block.uvToWorld(t,n.endBlock,n.endBlockUv);jl(t,e,ge.End,r)}}}function pS(t,e,n,r){const o=Pl,s=r===sr.Elbow?"elbow-arrow":"arc-arrow",a=h.Intersect.getAll(t).find(p=>h.hasComponent(t,p,h.Synced)&&Hl(t,p))??null;let l=n,c=[0,0];if(a!==null){const p=Wl(t,a,n);p!==null?(l=p.position,c=p.uv):(l=h.Block.uvToWorld(t,a,[.5,.5]),c=[.5,.5])}h.addComponent(t,e,h.Block,{tag:s,rank:h.RankBounds.genNext(t),position:l,size:[o,o]}),h.addComponent(t,e,h.Synced,{id:crypto.randomUUID()}),r===sr.Arc?h.addComponent(t,e,ue,{value:[0,0,.5,.5,1,1,o],startArrowHead:pe.None,endArrowHead:pe.V}):h.addComponent(t,e,he,{points:[0,0,.5,0,.5,1,1,1],pointCount:4,thickness:o,startArrowHead:pe.None,endArrowHead:pe.V}),h.addComponent(t,e,h.Connector,{startBlock:a,startBlockUv:c}),Qr(t,e);const f=Vl(t,e).find(p=>At.read(t,p).kind===ge.End);if(f){const p=h.Block.read(t,f),m=Tt.write(t);m.state=de.Dragging,m.draggedEntity=f,m.dragStart=l,m.draggedEntityStart=[p.position[0],p.position[1]],Ll(t)}}function mS(t,e){h.removeEntity(t,e)}function gS(t,e,n){h.hasComponent(t,e,ue)?yS(t,e):h.hasComponent(t,e,he)?kS(t,e):h.hasComponent(t,e,At)&&wS(t,e,n)}function yS(t,e){const n=h.Connector.read(t,e);if(n.startBlock!==null){const{a:r}=ue.getWorldPoints(t,e);Xo(t,e,ge.Start,r)}if(n.endBlock!==null){const{c:r}=ue.getWorldPoints(t,e);Xo(t,e,ge.End,r)}}function kS(t,e){const n=h.Connector.read(t,e);if(n.startBlock!==null){const r=he.getStartWorld(t,e);Xo(t,e,ge.Start,r)}if(n.endBlock!==null){const r=he.getEndWorld(t,e);Xo(t,e,ge.End,r)}}function wS(t,e,n){const r=At.read(t,e),o=r.arrowEntity;if(!o)return;const s=h.Block.read(t,e);let i=[n[0]+s.size[0]/2,n[1]+s.size[1]/2];if(r.kind!==ge.Middle){const a=ES(t,o,r.kind,i);a!==null&&(i=a)}h.hasComponent(t,o,ue)?Fl(t,o,r.kind,i):h.hasComponent(t,o,he)&&jl(t,o,r.kind,i),r.kind!==ge.Middle&&Xo(t,o,r.kind,i)}function Vl(t,e){const n=Db,r=[ge.Start,ge.End];h.hasComponent(t,e,ue)&&r.push(ge.Middle);const o=Array.from(bi.current(t)),s=new Map;for(const l of o){const c=At.read(t,l);s.set(c.kind,l)}const i=new Set;for(const l of r){const c=SS(t,e,l),u=c[0]-n/2,f=c[1]-n/2;let p=s.get(l);p||(p=h.createEntity(t),h.addComponent(t,p,At),h.addComponent(t,p,h.Block),h.addComponent(t,p,h.ScaleWithZoom),h.addComponent(t,p,ve,{kind:"arrow"}));const m=At.write(t,p);m.kind=l,m.arrowEntity=e;const g=h.Block.write(t,p);g.tag="arrow-handle",g.rank=Kf,g.position=[u,f],g.size=[n,n];const y=h.ScaleWithZoom.write(t,p);y.startPosition=[u,f],y.startSize=[n,n],i.add(p)}for(const l of o)i.has(l)||h.removeEntity(t,l);const a=Tt.read(t);return a.state===de.Dragging&&a.draggedEntity!==null&&h.hasComponent(t,a.draggedEntity,At)&&Ll(t),Array.from(i)}function vS(t){for(const e of bi.current(t))h.removeEntity(t,e);Si(t)}function Ll(t){for(const e of bi.current(t))if(!h.hasComponent(t,e,h.Opacity))h.addComponent(t,e,h.Opacity,{value:0});else{const n=h.Opacity.write(t,e);n.value=0}}function bS(t){const e=bi.current(t);for(const n of e)h.hasComponent(t,n,h.Opacity)&&h.removeComponent(t,n,h.Opacity);if(e.length>0){const n=At.read(t,e[0]);n.arrowEntity&&Vl(t,n.arrowEntity)}Si(t)}function SS(t,e,n){if(h.hasComponent(t,e,ue)){const{a:r,b:o,c:s}=ue.getWorldPoints(t,e);switch(n){case ge.Start:return r;case ge.Middle:return o;case ge.End:return s}}if(h.hasComponent(t,e,he))switch(n){case ge.Start:return he.getStartWorld(t,e);case ge.End:return he.getEndWorld(t,e)}return console.warn("Arrow entity has no recognized arrow component"),[0,0]}function Fl(t,e,n,r){const{a:o,b:s,c:i}=ue.getWorldPoints(t,e);let a=o,l=s,c=i,u=[0,0],f=[0,0];if(n===ge.Start?(u=o,f=i,a=r):n===ge.Middle?l=r:(u=i,f=o,c=r),n!==ge.Middle){const{angle:w,distance:v}=tS(u,r,f);l=nS(s,w,.5*v,f)}const p=h.Block.write(t,e),m=Math.min(a[0],l[0],c[0]),g=Math.min(a[1],l[1],c[1]),y=Math.max(a[0],l[0],c[0]),k=Math.max(a[1],l[1],c[1]);p.position=[m,g],p.size=[y-m||1,k-g||1],ue.setA(t,e,h.Block.worldToUv(t,e,a)),ue.setB(t,e,h.Block.worldToUv(t,e,l)),ue.setC(t,e,h.Block.worldToUv(t,e,c))}function jl(t,e,n,r){const o=h.Connector.read(t,e);let s,i;n===ge.Start?(s=r,o.endBlock!==null?i=h.Block.uvToWorld(t,o.endBlock,o.endBlockUv):i=he.getEndWorld(t,e)):(o.startBlock!==null?s=h.Block.uvToWorld(t,o.startBlock,o.startBlockUv):s=he.getStartWorld(t,e),i=r);const l=h.Block.read(t,e).rotateZ||0,c=Jb(t,s,i,o.startBlock,o.endBlock,Jf,l),u=h.Block.write(t,e),f=[0,0],p=[1,1];E.Rect.boundPoints(f,p,l,c),u.position=f,u.size=[Math.max(p[0],1),Math.max(p[1],1)];const m=c.map(g=>h.Block.worldToUv(t,e,g));he.setPoints(t,e,m)}function Xo(t,e,n,r){let s=h.Intersect.getAll(t).find(l=>l!==e&&h.hasComponent(t,l,h.Synced)&&!h.hasComponent(t,l,h.Connector)&&Hl(t,l))??null;const i=h.Connector.write(t,e);if(s!==null){const l=n===ge.Start?i.endBlock:i.startBlock;s===l&&(s=null)}s!==null?_S(t,s):Si(t);let a=[0,0];if(s!==null){const l=Wl(t,s,r,qf);l!==null?a=l.uv:a=h.Block.worldToUv(t,s,r)}n===ge.Start?(i.startBlock=s,i.startBlockUv=a):(i.endBlock=s,i.endBlockUv=a),CS(t,e)}function CS(t,e){const n=h.Connector.read(t,e);let r=null;for(const s of[n.startBlock,n.endBlock]){if(s===null)continue;const i=h.Block.read(t,s).rank;(r===null||i>r)&&(r=i)}const o=h.Block.read(t,e).rank;if(r!==null&&o<r){const s=h.Block.write(t,e);s.rank=Ib(r,null)}}function Hl(t,e){const n=h.Block.read(t,e).tag;return h.getBlockDef(t,n).connectors.enabled}function xS(t){const e=fh.current(t);return e.length===0?null:Go.read(t,e[0]).blockEntity}function _S(t,e){if(xS(t)===e)return;Si(t);const n=h.Block.read(t,e).tag,r=h.getBlockDef(t,n);if(!r.connectors.enabled)return;const o=r.connectors.terminals;for(let s=0;s<o.length;s++){const i=o[s],a=h.Block.uvToWorld(t,e,i),l=h.createEntity(t);h.addComponent(t,l,Go,{blockEntity:e,terminalIndex:s}),h.addComponent(t,l,h.Block,{tag:"arrow-terminal",rank:Kf,position:[a[0]-xn/2,a[1]-xn/2],size:[xn,xn]}),h.addComponent(t,l,h.ScaleWithZoom,{startPosition:[a[0]-xn/2,a[1]-xn/2],startSize:[xn,xn]})}}function Si(t){for(const e of fh.current(t))h.removeEntity(t,e)}function Wl(t,e,n,r){const o=h.Block.read(t,e).tag,s=h.getBlockDef(t,o);if(!s.connectors.enabled)return null;const i=s.connectors.terminals;if(i.length===0)return null;let a=null,l=r??1/0;for(const c of i){const u=h.Block.uvToWorld(t,e,c),f=u[0]-n[0],p=u[1]-n[1],m=Math.sqrt(f*f+p*p);m<l&&(l=m,a={position:u,uv:c})}return a}function ES(t,e,n,r){const s=h.Intersect.getAll(t).find(c=>c!==e&&h.hasComponent(t,c,h.Synced)&&!h.hasComponent(t,c,h.Connector)&&Hl(t,c))??null;if(s===null)return null;const i=h.Connector.read(t,e),a=n===ge.Start?i.endBlock:i.startBlock;if(s===a)return null;const l=Wl(t,s,r,qf);return l===null?null:l.position}function TS(t={}){return{name:Rb,components:Object.values(Uf).filter(e=>e instanceof h.CanvasComponentDef),singletons:Object.values(Gf).filter(e=>e instanceof h.CanvasSingletonDef),blockDefs:[{tag:"arc-arrow",resizeMode:h.ResizeMode.GroupOnly,components:[ue,h.Connector,h.Color],connectors:{enabled:!1}},{tag:"elbow-arrow",resizeMode:h.ResizeMode.GroupOnly,components:[he,h.Connector,h.Color],connectors:{enabled:!1}},{tag:"arrow-handle",stratum:"overlay",canRotate:!1,canScale:!1,components:[At],connectors:{enabled:!1}},{tag:"arrow-terminal",stratum:"overlay",canRotate:!1,canScale:!1,components:[Go],connectors:{enabled:!1}}],systems:[Hb,Zb,fS,sS],resources:{elbowArrowPadding:t.elbowArrowPadding??Jf}}}const Zl=[{kind:pe.None,label:"None",gap:0,svg:""},{kind:pe.V,label:"Arrow",gap:15,svg:'<polyline points="-10,-7 -1,0 -10,7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />'},{kind:pe.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:pe.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:pe.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function no(t){return Zl.find(e=>e.kind===t)}const ph=Symbol.for("__woven_canvas_dropdown_active__"),mh=Symbol.for("__woven_canvas_dropdown_level__"),gh=Symbol.for("__woven_canvas_floating_menu__"),Ul=Symbol.for("__woven_canvas_toolbar__"),yh=Symbol.for("__woven_canvas_tooltip__"),pt=Symbol.for("__woven_canvas__");function Pe(t,e){const n=d.inject(pt);if(!n)throw new Error("useComponent must be used within a WovenCanvas component");const r=d.shallowRef(null),o=n.getEditor();if(o){const i=o._getContext();h.hasComponent(i,t,e)&&(r.value=e.snapshot(i,t))}const s=n.subscribeComponent(t,e.name,i=>{r.value=i});return d.onUnmounted(()=>{s()}),r}const MS={key:0},AS=["x1","y1","x2","y2","stroke","stroke-width"],NS=["x1","y1","x2","y2","stroke","stroke-width"],BS=["points","fill"],OS=["cx","cy","r","fill"],IS=["points","fill"],PS=15,RS=2,sn=d.defineComponent({__name:"ArrowHead",props:{position:{},direction:{},thickness:{},color:{},arrowThickness:{},kind:{}},setup(t){const e=t,n=d.computed(()=>{const a=Math.hypot(e.direction[0],e.direction[1]);if(a===0)return null;const l=(e.arrowThickness/RS)**.33,c=PS*l,u=[e.direction[0]/a,e.direction[1]/a],f=[-u[1],u[0]];return{unitDir:u,perpDir:f,size:c}}),r=d.computed(()=>{if(!n.value)return null;const{unitDir:a,perpDir:l,size:c}=n.value,u=c,f=c,p=[e.position[0]-a[0]*u+l[0]*(f/2),e.position[1]-a[1]*u+l[1]*(f/2)],m=[e.position[0]-a[0]*u-l[0]*(f/2),e.position[1]-a[1]*u-l[1]*(f/2)];return{p1:p,p2:m}}),o=d.computed(()=>{if(!n.value)return null;const{unitDir:a,perpDir:l,size:c}=n.value,u=c,f=c,p=[a[0]*(c*.4),a[1]*(c*.4)],m=[e.position[0]-a[0]*u+p[0],e.position[1]-a[1]*u+p[1]],g=[m[0]+l[0]*(f/2),m[1]+l[1]*(f/2)],y=[m[0]-l[0]*(f/2),m[1]-l[1]*(f/2)],k=[e.position[0]+p[0],e.position[1]+p[1]];return`${k[0]},${k[1]} ${g[0]},${g[1]} ${y[0]},${y[1]}`}),s=d.computed(()=>{if(!n.value)return null;const{unitDir:a,size:l}=n.value,c=l*.8,u=[a[0]*c,a[1]*c];return{center:[e.position[0]-a[0]*c+u[0],e.position[1]-a[1]*c+u[1]],radius:c}}),i=d.computed(()=>{if(!n.value)return null;const{unitDir:a,perpDir:l,size:c}=n.value,u=1.6*c,f=1.6*c,p=[a[0]*(c*.8),a[1]*(c*.8)],m=[e.position[0]-a[0]*(u/2)+p[0],e.position[1]-a[1]*(u/2)+p[1]],g=[e.position[0]-a[0]*u+p[0],e.position[1]-a[1]*u+p[1]],y=[m[0]+l[0]*(f/2),m[1]+l[1]*(f/2)],k=[m[0]-l[0]*(f/2),m[1]-l[1]*(f/2)],w=[e.position[0]+p[0],e.position[1]+p[1]];return`${w[0]},${w[1]} ${y[0]},${y[1]} ${g[0]},${g[1]} ${k[0]},${k[1]}`});return(a,l)=>n.value?(d.openBlock(),d.createElementBlock("g",MS,[t.kind===d.unref(pe).V&&r.value?(d.openBlock(),d.createElementBlock(d.Fragment,{key:0},[d.createElementVNode("line",{x1:r.value.p1[0],y1:r.value.p1[1],x2:t.position[0],y2:t.position[1],stroke:t.color,"stroke-width":t.thickness,"stroke-linecap":"round"},null,8,AS),d.createElementVNode("line",{x1:r.value.p2[0],y1:r.value.p2[1],x2:t.position[0],y2:t.position[1],stroke:t.color,"stroke-width":t.thickness,"stroke-linecap":"round"},null,8,NS)],64)):t.kind===d.unref(pe).Delta&&o.value?(d.openBlock(),d.createElementBlock("polygon",{key:1,points:o.value,fill:t.color},null,8,BS)):t.kind===d.unref(pe).Circle&&s.value?(d.openBlock(),d.createElementBlock("circle",{key:2,cx:s.value.center[0],cy:s.value.center[1],r:s.value.radius,fill:t.color},null,8,OS)):t.kind===d.unref(pe).Diamond&&i.value?(d.openBlock(),d.createElementBlock("polygon",{key:3,points:i.value,fill:t.color},null,8,IS)):d.createCommentVNode("",!0)])):d.createCommentVNode("",!0)}}),DS={class:"arrow-svg",preserveAspectRatio:"none"},zS=["d","stroke","stroke-width"],$S=["x1","y1","x2","y2","stroke","stroke-width"],VS=["d"],LS=["x1","y1","x2","y2"],FS=d.defineComponent({__name:"ArcArrow",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=d.ref(null),r=d.ref(0),o=d.ref(0),s=Pe(e.entityId,h.Color),i=Pe(e.entityId,ue);let a=null;d.onMounted(()=>{n.value&&(a=new ResizeObserver(()=>{n.value&&(r.value=n.value.clientWidth,o.value=n.value.clientHeight)}),a.observe(n.value),r.value=n.value.clientWidth,o.value=n.value.clientHeight)}),d.onUnmounted(()=>{a==null||a.disconnect()});const l=d.computed(()=>{if(!s.value)return"#000000";const b=s.value.red.toString(16).padStart(2,"0"),S=s.value.green.toString(16).padStart(2,"0"),C=s.value.blue.toString(16).padStart(2,"0");return`#${b}${S}${C}`}),c=d.computed(()=>{var b;return((b=i.value)==null?void 0:b.value[6])??2}),u=d.computed(()=>`${c.value}px`),f=d.computed(()=>e.hovered||e.selected),p=d.computed(()=>{if(!i.value)return!1;const b=i.value.value,S=E.Arc.create(b[0],b[1],b[2],b[3],b[4],b[5],b[6]);return!E.Arc.isCollinear(S)}),m=d.computed(()=>{if(!i.value)return null;const b=i.value.value,S=r.value,C=o.value;return E.Arc.create(b[0]*S,b[1]*C,b[2]*S,b[3]*C,b[4]*S,b[5]*C,b[6])}),g=d.computed(()=>!m.value||!p.value?null:E.Arc.compute(m.value)),y=d.computed(()=>{var $,Z,ae,X;if(!i.value||!m.value)return null;const b=m.value,S=i.value.startArrowHead,C=i.value.endArrowHead,_=E.Arc.length(b);let x=i.value.trimStart;if(($=e.connector)!=null&&$.startBlock&&S!=="none"){const j=((Z=no(S))==null?void 0:Z.gap)??0,q=_>0?j/_:0;x+=q}let T=i.value.trimEnd;if((ae=e.connector)!=null&&ae.endBlock&&C!=="none"){const j=((X=no(C))==null?void 0:X.gap)??0,q=_>0?j/_:0;T+=q}const N=1-T,I=E.Arc.parametricToPoint(b,x),V=E.Arc.parametricToPoint(b,N),K=v(E.Arc.directionAt(b,x)),M=E.Arc.directionAt(b,N);return{start:I,end:V,startDir:K,endDir:M,tStart:x,tEnd:N,startHead:S,endHead:C}}),k=d.computed(()=>{if(!y.value||!g.value||!p.value)return"";const{start:b,end:S,tStart:C,tEnd:_}=y.value,{radius:x,clockwise:T,arcAngle:N}=g.value,V=N*(_-C)>Math.PI?1:0,K=T?0:1;return`M ${b[0]} ${b[1]} A ${x} ${x} 0 ${V} ${K} ${S[0]} ${S[1]}`}),w=d.computed(()=>!y.value||p.value?null:{x1:y.value.start[0],y1:y.value.start[1],x2:y.value.end[0],y2:y.value.end[1]});function v(b){return[-b[0],-b[1]]}return(b,S)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:n,class:"wov-arc-arrow"},[(d.openBlock(),d.createElementBlock("svg",DS,[p.value&&k.value?(d.openBlock(),d.createElementBlock("path",{key:0,d:k.value,stroke:l.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,zS)):w.value?(d.openBlock(),d.createElementBlock("line",{key:1,x1:w.value.x1,y1:w.value.y1,x2:w.value.x2,y2:w.value.y2,stroke:l.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,$S)):d.createCommentVNode("",!0),y.value?(d.openBlock(),d.createElementBlock(d.Fragment,{key:2},[y.value.startHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:0,position:y.value.start,direction:y.value.startDir,thickness:u.value,"arrow-thickness":c.value,color:l.value,kind:y.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):d.createCommentVNode("",!0),y.value.endHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:1,position:y.value.end,direction:y.value.endDir,thickness:u.value,"arrow-thickness":c.value,color:l.value,kind:y.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):d.createCommentVNode("",!0),f.value?(d.openBlock(),d.createElementBlock(d.Fragment,{key:2},[p.value&&k.value?(d.openBlock(),d.createElementBlock("path",{key:0,d:k.value,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,VS)):w.value?(d.openBlock(),d.createElementBlock("line",{key:1,x1:w.value.x1,y1:w.value.y1,x2:w.value.x2,y2:w.value.y2,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,LS)):d.createCommentVNode("",!0),y.value.startHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:2,position:y.value.start,direction:y.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":c.value,color:"var(--wov-highlighted-block-outline-color)",kind:y.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):d.createCommentVNode("",!0),y.value.endHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:3,position:y.value.end,direction:y.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":c.value,color:"var(--wov-highlighted-block-outline-color)",kind:y.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):d.createCommentVNode("",!0)],64)):d.createCommentVNode("",!0)],64)):d.createCommentVNode("",!0)]))],512))}}),ir=(t,e)=>{const n=t.__vccOpts||t;for(const[r,o]of e)n[r]=o;return n},kh=ir(FS,[["__scopeId","data-v-bcf5b4f3"]]),jS={},HS={class:"wov-arrow-handle"};function WS(t,e){return d.openBlock(),d.createElementBlock("div",HS,[...e[0]||(e[0]=[d.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const wh=ir(jS,[["render",WS]]),ZS={},US={class:"wov-arrow-terminal"};function KS(t,e){return d.openBlock(),d.createElementBlock("div",US,[...e[0]||(e[0]=[d.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[d.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const vh=ir(ZS,[["render",KS]]),JS={class:"arrow-svg",preserveAspectRatio:"none"},qS=["x1","y1","x2","y2"],GS=["x1","y1","x2","y2","stroke","stroke-width"],YS=["x1","y1","x2","y2"],bh=ir(d.defineComponent({__name:"ElbowArrow",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=d.ref(null),r=d.ref(0),o=d.ref(0),s=Pe(e.entityId,h.Color),i=Pe(e.entityId,he),a=d.computed(()=>e.hovered||e.selected);let l=null;d.onMounted(()=>{n.value&&(l=new ResizeObserver(()=>{n.value&&(r.value=n.value.clientWidth,o.value=n.value.clientHeight)}),l.observe(n.value),r.value=n.value.clientWidth,o.value=n.value.clientHeight)}),d.onUnmounted(()=>{l==null||l.disconnect()});const c=d.computed(()=>{if(!s.value)return"#000000";const y=s.value.red.toString(16).padStart(2,"0"),k=s.value.green.toString(16).padStart(2,"0"),w=s.value.blue.toString(16).padStart(2,"0");return`#${y}${k}${w}`}),u=d.computed(()=>{var y;return((y=i.value)==null?void 0:y.thickness)??2}),f=d.computed(()=>`${u.value}px`),p=d.computed(()=>{if(!i.value)return[];const y=i.value,k=r.value,w=o.value,v=[];for(let b=0;b<y.pointCount;b++){const S=y.points[b*2]*k,C=y.points[b*2+1]*w;v.push([S,C])}return v}),m=d.computed(()=>{const y=p.value;if(y.length<2)return[];const k=[];for(let w=0;w<y.length-1;w++)k.push({start:y[w],end:y[w+1]});return k}),g=d.computed(()=>{var N,I,V,K;if(!i.value||p.value.length<2)return null;const y=i.value,k=[...p.value.map(M=>[...M])],w=y.startArrowHead,v=y.endArrowHead,b=[k[1][0]-k[0][0],k[1][1]-k[0][1]],S=[k[k.length-1][0]-k[k.length-2][0],k[k.length-1][1]-k[k.length-2][1]];let C=y.trimStart;if((N=e.connector)!=null&&N.startBlock&&w!=="none"){const M=Math.hypot(b[0],b[1]),$=((I=no(w))==null?void 0:I.gap)??0,Z=M>0?$/M:0;C+=Z}let _=y.trimEnd;if((V=e.connector)!=null&&V.endBlock&&v!=="none"){const M=Math.hypot(S[0],S[1]),$=((K=no(v))==null?void 0:K.gap)??0,Z=M>0?$/M:0;_+=Z}k[0]=[k[0][0]+(k[1][0]-k[0][0])*C,k[0][1]+(k[1][1]-k[0][1])*C];const x=k.length-1;k[x]=[k[x-1][0]+(k[x][0]-k[x-1][0])*(1-_),k[x-1][1]+(k[x][1]-k[x-1][1])*(1-_)];const T=[];for(let M=0;M<k.length-1;M++)T.push({start:k[M],end:k[M+1]});return E.Vec2.scale(b,-1),{points:k,lines:T,startPos:k[0],endPos:k[k.length-1],startDir:b,endDir:S,startHead:w,endHead:v}});return(y,k)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:n,class:"wov-elbow-arrow"},[(d.openBlock(),d.createElementBlock("svg",JS,[a.value&&m.value.length>0?(d.openBlock(!0),d.createElementBlock(d.Fragment,{key:0},d.renderList(m.value,(w,v)=>(d.openBlock(),d.createElementBlock("line",{key:"bg-"+v,x1:w.start[0],y1:w.start[1],x2:w.end[0],y2:w.end[1],class:"highlight-bg",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))","stroke-dasharray":"calc(12px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,qS))),128)):d.createCommentVNode("",!0),g.value?(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(g.value.lines,(w,v)=>(d.openBlock(),d.createElementBlock("line",{key:v,x1:w.start[0],y1:w.start[1],x2:w.end[0],y2:w.end[1],stroke:c.value,fill:"none","stroke-width":f.value,"stroke-linecap":"round"},null,8,GS))),128)),g.value.startHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:0,position:g.value.startPos,direction:g.value.startDir,thickness:f.value,"arrow-thickness":u.value,color:c.value,kind:g.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):d.createCommentVNode("",!0),g.value.endHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:1,position:g.value.endPos,direction:g.value.endDir,thickness:f.value,"arrow-thickness":u.value,color:c.value,kind:g.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):d.createCommentVNode("",!0),a.value?(d.openBlock(),d.createElementBlock(d.Fragment,{key:2},[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(g.value.lines,(w,v)=>(d.openBlock(),d.createElementBlock("line",{key:"hl-"+v,x1:w.start[0],y1:w.start[1],x2:w.end[0],y2:w.end[1],class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,YS))),128)),g.value.startHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:0,position:g.value.startPos,direction:g.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):d.createCommentVNode("",!0),g.value.endHead!=="none"?(d.openBlock(),d.createBlock(sn,{key:1,position:g.value.endPos,direction:g.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):d.createCommentVNode("",!0)],64)):d.createCommentVNode("",!0)],64)):d.createCommentVNode("",!0)]))],512))}}),[["__scopeId","data-v-b2719db1"]]);function J(t,e,n){function r(a,l){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:l,constr:i,traits:new Set},enumerable:!1}),a._zod.traits.has(t))return;a._zod.traits.add(t),e(a,l);const c=i.prototype,u=Object.keys(c);for(let f=0;f<u.length;f++){const p=u[f];p in a||(a[p]=c[p].bind(a))}}const o=(n==null?void 0:n.Parent)??Object;class s extends o{}Object.defineProperty(s,"name",{value:t});function i(a){var l;const c=n!=null&&n.Parent?new s:this;r(c,a),(l=c._zod).deferred??(l.deferred=[]);for(const u of c._zod.deferred)u();return c}return Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:a=>{var l,c;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(c=(l=a==null?void 0:a._zod)==null?void 0:l.traits)==null?void 0:c.has(t)}}),Object.defineProperty(i,"name",{value:t}),i}class ro extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Sh extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Ch={};function ar(t){return Ch}function xh(t){const e=Object.values(t).filter(r=>typeof r=="number");return Object.entries(t).filter(([r,o])=>e.indexOf(+r)===-1).map(([r,o])=>o)}function Kl(t,e){return typeof e=="bigint"?e.toString():e}function Jl(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function ql(t){return t==null}function Gl(t){const e=t.startsWith("^")?1:0,n=t.endsWith("$")?t.length-1:t.length;return t.slice(e,n)}function XS(t,e){const n=(t.toString().split(".")[1]||"").length,r=e.toString();let o=(r.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(r)){const l=r.match(/\d?e-(\d?)/);l!=null&&l[1]&&(o=Number.parseInt(l[1]))}const s=n>o?n:o,i=Number.parseInt(t.toFixed(s).replace(".","")),a=Number.parseInt(e.toFixed(s).replace(".",""));return i%a/10**s}const _h=Symbol("evaluating");function me(t,e,n){let r;Object.defineProperty(t,e,{get(){if(r!==_h)return r===void 0&&(r=_h,r=n()),r},set(o){Object.defineProperty(t,e,{value:o})},configurable:!0})}function lr(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0,configurable:!0})}function _n(...t){const e={};for(const n of t){const r=Object.getOwnPropertyDescriptors(n);Object.assign(e,r)}return Object.defineProperties({},e)}function Eh(t){return JSON.stringify(t)}const Th="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function Ci(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const QS=Jl(()=>{var t;if(typeof navigator<"u"&&((t=navigator==null?void 0:navigator.userAgent)!=null&&t.includes("Cloudflare")))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Qo(t){if(Ci(t)===!1)return!1;const e=t.constructor;if(e===void 0||typeof e!="function")return!0;const n=e.prototype;return!(Ci(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Mh(t){return Qo(t)?{...t}:Array.isArray(t)?[...t]:t}const eC=new Set(["string","number","symbol"]);function tC(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function En(t,e,n){const r=new t._zod.constr(e??t._zod.def);return(!e||n!=null&&n.parent)&&(r._zod.parent=t),r}function _e(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if((e==null?void 0:e.message)!==void 0){if((e==null?void 0:e.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function nC(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const rC={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function oC(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=_n(t._zod.def,{get shape(){const i={};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(i[a]=n.shape[a])}return lr(this,"shape",i),i},checks:[]});return En(t,s)}function sC(t,e){const n=t._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=_n(t._zod.def,{get shape(){const i={...t._zod.def.shape};for(const a in e){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete i[a]}return lr(this,"shape",i),i},checks:[]});return En(t,s)}function iC(t,e){if(!Qo(e))throw new Error("Invalid input to extend: expected a plain object");const n=t._zod.def.checks;if(n&&n.length>0){const s=t._zod.def.shape;for(const i in e)if(Object.getOwnPropertyDescriptor(s,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const o=_n(t._zod.def,{get shape(){const s={...t._zod.def.shape,...e};return lr(this,"shape",s),s}});return En(t,o)}function aC(t,e){if(!Qo(e))throw new Error("Invalid input to safeExtend: expected a plain object");const n=_n(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e};return lr(this,"shape",r),r}});return En(t,n)}function lC(t,e){const n=_n(t._zod.def,{get shape(){const r={...t._zod.def.shape,...e._zod.def.shape};return lr(this,"shape",r),r},get catchall(){return e._zod.def.catchall},checks:[]});return En(t,n)}function cC(t,e,n){const o=e._zod.def.checks;if(o&&o.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const i=_n(e._zod.def,{get shape(){const a=e._zod.def.shape,l={...a};if(n)for(const c in n){if(!(c in a))throw new Error(`Unrecognized key: "${c}"`);n[c]&&(l[c]=t?new t({type:"optional",innerType:a[c]}):a[c])}else for(const c in a)l[c]=t?new t({type:"optional",innerType:a[c]}):a[c];return lr(this,"shape",l),l},checks:[]});return En(e,i)}function dC(t,e,n){const r=_n(e._zod.def,{get shape(){const o=e._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new t({type:"nonoptional",innerType:o[i]}))}else for(const i in o)s[i]=new t({type:"nonoptional",innerType:o[i]});return lr(this,"shape",s),s}});return En(e,r)}function oo(t,e=0){var n;if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(((n=t.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function Ah(t,e){return e.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(t),n})}function xi(t){return typeof t=="string"?t:t==null?void 0:t.message}function cr(t,e,n){var o,s,i,a,l,c;const r={...t,path:t.path??[]};if(!t.message){const u=xi((i=(s=(o=t.inst)==null?void 0:o._zod.def)==null?void 0:s.error)==null?void 0:i.call(s,t))??xi((a=e==null?void 0:e.error)==null?void 0:a.call(e,t))??xi((l=n.customError)==null?void 0:l.call(n,t))??xi((c=n.localeError)==null?void 0:c.call(n,t))??"Invalid input";r.message=u}return delete r.inst,delete r.continue,e!=null&&e.reportInput||delete r.input,r}function Yl(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function es(...t){const[e,n,r]=t;return typeof e=="string"?{message:e,code:"custom",input:n,inst:r}:{...e}}const Nh=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,Kl,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Bh=J("$ZodError",Nh),Oh=J("$ZodError",Nh,{Parent:Error});function uC(t,e=n=>n.message){const n={},r=[];for(const o of t.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(e(o))):r.push(e(o));return{formErrors:r,fieldErrors:n}}function fC(t,e=n=>n.message){const n={_errors:[]},r=o=>{for(const s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>r({issues:i}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(e(s));else{let i=n,a=0;for(;a<s.path.length;){const l=s.path[a];a===s.path.length-1?(i[l]=i[l]||{_errors:[]},i[l]._errors.push(e(s))):i[l]=i[l]||{_errors:[]},i=i[l],a++}}};return r(t),n}const Xl=t=>(e,n,r,o)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new ro;if(i.issues.length){const a=new((o==null?void 0:o.Err)??t)(i.issues.map(l=>cr(l,s,ar())));throw Th(a,o==null?void 0:o.callee),a}return i.value},Ql=t=>async(e,n,r,o)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=e._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const a=new((o==null?void 0:o.Err)??t)(i.issues.map(l=>cr(l,s,ar())));throw Th(a,o==null?void 0:o.callee),a}return i.value},_i=t=>(e,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=e._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new ro;return s.issues.length?{success:!1,error:new(t??Bh)(s.issues.map(i=>cr(i,o,ar())))}:{success:!0,data:s.value}},hC=_i(Oh),Ei=t=>async(e,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=e._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new t(s.issues.map(i=>cr(i,o,ar())))}:{success:!0,data:s.value}},pC=Ei(Oh),mC=t=>(e,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Xl(t)(e,n,o)},gC=t=>(e,n,r)=>Xl(t)(e,n,r),yC=t=>async(e,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ql(t)(e,n,o)},kC=t=>async(e,n,r)=>Ql(t)(e,n,r),wC=t=>(e,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return _i(t)(e,n,o)},vC=t=>(e,n,r)=>_i(t)(e,n,r),bC=t=>async(e,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ei(t)(e,n,o)},SC=t=>async(e,n,r)=>Ei(t)(e,n,r),CC=/^-?\d+$/,xC=/^-?\d+(?:\.\d+)?$/,Ht=J("$ZodCheck",(t,e)=>{var n;t._zod??(t._zod={}),t._zod.def=e,(n=t._zod).onattach??(n.onattach=[])}),Ih={number:"number",bigint:"bigint",object:"date"},Ph=J("$ZodCheckLessThan",(t,e)=>{Ht.init(t,e);const n=Ih[typeof e.value];t._zod.onattach.push(r=>{const o=r._zod.bag,s=(e.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<s&&(e.inclusive?o.maximum=e.value:o.exclusiveMaximum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value<=e.value:r.value<e.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Rh=J("$ZodCheckGreaterThan",(t,e)=>{Ht.init(t,e);const n=Ih[typeof e.value];t._zod.onattach.push(r=>{const o=r._zod.bag,s=(e.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>s&&(e.inclusive?o.minimum=e.value:o.exclusiveMinimum=e.value)}),t._zod.check=r=>{(e.inclusive?r.value>=e.value:r.value>e.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof e.value=="object"?e.value.getTime():e.value,input:r.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),_C=J("$ZodCheckMultipleOf",(t,e)=>{Ht.init(t,e),t._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=e.value)}),t._zod.check=n=>{if(typeof n.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%e.value===BigInt(0):XS(n.value,e.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:e.value,input:n.value,inst:t,continue:!e.abort})}}),EC=J("$ZodCheckNumberFormat",(t,e)=>{var i;Ht.init(t,e),e.format=e.format||"float64";const n=(i=e.format)==null?void 0:i.includes("int"),r=n?"int":"number",[o,s]=rC[e.format];t._zod.onattach.push(a=>{const l=a._zod.bag;l.format=e.format,l.minimum=o,l.maximum=s,n&&(l.pattern=CC)}),t._zod.check=a=>{const l=a.value;if(n){if(!Number.isInteger(l)){a.issues.push({expected:r,format:e.format,code:"invalid_type",continue:!1,input:l,inst:t});return}if(!Number.isSafeInteger(l)){l>0?a.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort}):a.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:r,inclusive:!0,continue:!e.abort});return}}l<o&&a.issues.push({origin:"number",input:l,code:"too_small",minimum:o,inclusive:!0,inst:t,continue:!e.abort}),l>s&&a.issues.push({origin:"number",input:l,code:"too_big",maximum:s,inclusive:!0,inst:t,continue:!e.abort})}}),TC=J("$ZodCheckMaxLength",(t,e)=>{var n;Ht.init(t,e),(n=t._zod.def).when??(n.when=r=>{const o=r.value;return!ql(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<o&&(r._zod.bag.maximum=e.maximum)}),t._zod.check=r=>{const o=r.value;if(o.length<=e.maximum)return;const i=Yl(o);r.issues.push({origin:i,code:"too_big",maximum:e.maximum,inclusive:!0,input:o,inst:t,continue:!e.abort})}}),MC=J("$ZodCheckMinLength",(t,e)=>{var n;Ht.init(t,e),(n=t._zod.def).when??(n.when=r=>{const o=r.value;return!ql(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>o&&(r._zod.bag.minimum=e.minimum)}),t._zod.check=r=>{const o=r.value;if(o.length>=e.minimum)return;const i=Yl(o);r.issues.push({origin:i,code:"too_small",minimum:e.minimum,inclusive:!0,input:o,inst:t,continue:!e.abort})}}),AC=J("$ZodCheckLengthEquals",(t,e)=>{var n;Ht.init(t,e),(n=t._zod.def).when??(n.when=r=>{const o=r.value;return!ql(o)&&o.length!==void 0}),t._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=e.length,o.maximum=e.length,o.length=e.length}),t._zod.check=r=>{const o=r.value,s=o.length;if(s===e.length)return;const i=Yl(o),a=s>e.length;r.issues.push({origin:i,...a?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:r.value,inst:t,continue:!e.abort})}}),NC=J("$ZodCheckOverwrite",(t,e)=>{Ht.init(t,e),t._zod.check=n=>{n.value=e.tx(n.value)}});class BC{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const r=e.split(`
|
|
32
|
-
`).filter(i=>i),o=Math.min(...r.map(i=>i.length-i.trimStart().length)),s=r.map(i=>i.slice(o)).map(i=>" ".repeat(this.indent*2)+i);for(const i of s)this.content.push(i)}compile(){const e=Function,n=this==null?void 0:this.args,o=[...((this==null?void 0:this.content)??[""]).map(s=>` ${s}`)];return new e(...n,o.join(`
|
|
33
|
-
`))}}const OC={major:4,minor:3,patch:6},Ne=J("$ZodType",(t,e)=>{var o;var n;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=OC;const r=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&r.unshift(t);for(const s of r)for(const i of s._zod.onattach)i(t);if(r.length===0)(n=t._zod).deferred??(n.deferred=[]),(o=t._zod.deferred)==null||o.push(()=>{t._zod.run=t._zod.parse});else{const s=(a,l,c)=>{let u=oo(a),f;for(const p of l){if(p._zod.def.when){if(!p._zod.def.when(a))continue}else if(u)continue;const m=a.issues.length,g=p._zod.check(a);if(g instanceof Promise&&(c==null?void 0:c.async)===!1)throw new ro;if(f||g instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await g,a.issues.length!==m&&(u||(u=oo(a,m)))});else{if(a.issues.length===m)continue;u||(u=oo(a,m))}}return f?f.then(()=>a):a},i=(a,l,c)=>{if(oo(a))return a.aborted=!0,a;const u=s(l,r,c);if(u instanceof Promise){if(c.async===!1)throw new ro;return u.then(f=>t._zod.parse(f,c))}return t._zod.parse(u,c)};t._zod.run=(a,l)=>{if(l.skipChecks)return t._zod.parse(a,l);if(l.direction==="backward"){const u=t._zod.parse({value:a.value,issues:[]},{...l,skipChecks:!0});return u instanceof Promise?u.then(f=>i(f,a,l)):i(u,a,l)}const c=t._zod.parse(a,l);if(c instanceof Promise){if(l.async===!1)throw new ro;return c.then(u=>s(u,r,l))}return s(c,r,l)}}me(t,"~standard",()=>({validate:s=>{var i;try{const a=hC(t,s);return a.success?{value:a.data}:{issues:(i=a.error)==null?void 0:i.issues}}catch{return pC(t,s).then(l=>{var c;return l.success?{value:l.data}:{issues:(c=l.error)==null?void 0:c.issues}})}},vendor:"zod",version:1}))}),Dh=J("$ZodNumber",(t,e)=>{Ne.init(t,e),t._zod.pattern=t._zod.bag.pattern??xC,t._zod.parse=(n,r)=>{if(e.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:t,...s?{received:s}:{}}),n}}),IC=J("$ZodNumberFormat",(t,e)=>{EC.init(t,e),Dh.init(t,e)}),PC=J("$ZodUnknown",(t,e)=>{Ne.init(t,e),t._zod.parse=n=>n}),RC=J("$ZodNever",(t,e)=>{Ne.init(t,e),t._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:t}),n)});function zh(t,e,n){t.issues.length&&e.issues.push(...Ah(n,t.issues)),e.value[n]=t.value}const DC=J("$ZodArray",(t,e)=>{Ne.init(t,e),t._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:t}),n;n.value=Array(o.length);const s=[];for(let i=0;i<o.length;i++){const a=o[i],l=e.element._zod.run({value:a,issues:[]},r);l instanceof Promise?s.push(l.then(c=>zh(c,n,i))):zh(l,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function Ti(t,e,n,r,o){if(t.issues.length){if(o&&!(n in r))return;e.issues.push(...Ah(n,t.issues))}t.value===void 0?n in r&&(e.value[n]=void 0):e.value[n]=t.value}function $h(t){var r,o,s,i;const e=Object.keys(t.shape);for(const a of e)if(!((i=(s=(o=(r=t.shape)==null?void 0:r[a])==null?void 0:o._zod)==null?void 0:s.traits)!=null&&i.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=nC(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}}function Vh(t,e,n,r,o,s){const i=[],a=o.keySet,l=o.catchall._zod,c=l.def.type,u=l.optout==="optional";for(const f in e){if(a.has(f))continue;if(c==="never"){i.push(f);continue}const p=l.run({value:e[f],issues:[]},r);p instanceof Promise?t.push(p.then(m=>Ti(m,n,f,e,u))):Ti(p,n,f,e,u)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:e,inst:s}),t.length?Promise.all(t).then(()=>n):n}const zC=J("$ZodObject",(t,e)=>{Ne.init(t,e);const n=Object.getOwnPropertyDescriptor(e,"shape");if(!(n!=null&&n.get)){const a=e.shape;Object.defineProperty(e,"shape",{get:()=>{const l={...a};return Object.defineProperty(e,"shape",{value:l}),l}})}const r=Jl(()=>$h(e));me(t._zod,"propValues",()=>{const a=e.shape,l={};for(const c in a){const u=a[c]._zod;if(u.values){l[c]??(l[c]=new Set);for(const f of u.values)l[c].add(f)}}return l});const o=Ci,s=e.catchall;let i;t._zod.parse=(a,l)=>{i??(i=r.value);const c=a.value;if(!o(c))return a.issues.push({expected:"object",code:"invalid_type",input:c,inst:t}),a;a.value={};const u=[],f=i.shape;for(const p of i.keys){const m=f[p],g=m._zod.optout==="optional",y=m._zod.run({value:c[p],issues:[]},l);y instanceof Promise?u.push(y.then(k=>Ti(k,a,p,c,g))):Ti(y,a,p,c,g)}return s?Vh(u,c,a,l,r.value,t):u.length?Promise.all(u).then(()=>a):a}}),$C=J("$ZodObjectJIT",(t,e)=>{zC.init(t,e);const n=t._zod.parse,r=Jl(()=>$h(e)),o=p=>{var b;const m=new BC(["shape","payload","ctx"]),g=r.value,y=S=>{const C=Eh(S);return`shape[${C}]._zod.run({ value: input[${C}], issues: [] }, ctx)`};m.write("const input = payload.value;");const k=Object.create(null);let w=0;for(const S of g.keys)k[S]=`key_${w++}`;m.write("const newResult = {};");for(const S of g.keys){const C=k[S],_=Eh(S),x=p[S],T=((b=x==null?void 0:x._zod)==null?void 0:b.optout)==="optional";m.write(`const ${C} = ${y(S)};`),T?m.write(`
|
|
34
|
-
if (${C}.issues.length) {
|
|
35
|
-
if (${_} in input) {
|
|
36
|
-
payload.issues = payload.issues.concat(${C}.issues.map(iss => ({
|
|
37
|
-
...iss,
|
|
38
|
-
path: iss.path ? [${_}, ...iss.path] : [${_}]
|
|
39
|
-
})));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (${C}.value === undefined) {
|
|
44
|
-
if (${_} in input) {
|
|
45
|
-
newResult[${_}] = undefined;
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
newResult[${_}] = ${C}.value;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
`):m.write(`
|
|
52
|
-
if (${C}.issues.length) {
|
|
53
|
-
payload.issues = payload.issues.concat(${C}.issues.map(iss => ({
|
|
54
|
-
...iss,
|
|
55
|
-
path: iss.path ? [${_}, ...iss.path] : [${_}]
|
|
56
|
-
})));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (${C}.value === undefined) {
|
|
60
|
-
if (${_} in input) {
|
|
61
|
-
newResult[${_}] = undefined;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
newResult[${_}] = ${C}.value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
`)}m.write("payload.value = newResult;"),m.write("return payload;");const v=m.compile();return(S,C)=>v(p,S,C)};let s;const i=Ci,a=!Ch.jitless,c=a&&QS.value,u=e.catchall;let f;t._zod.parse=(p,m)=>{f??(f=r.value);const g=p.value;return i(g)?a&&c&&(m==null?void 0:m.async)===!1&&m.jitless!==!0?(s||(s=o(e.shape)),p=s(p,m),u?Vh([],g,p,m,f,t):p):n(p,m):(p.issues.push({expected:"object",code:"invalid_type",input:g,inst:t}),p)}});function Lh(t,e,n,r){for(const s of t)if(s.issues.length===0)return e.value=s.value,e;const o=t.filter(s=>!oo(s));return o.length===1?(e.value=o[0].value,o[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:n,errors:t.map(s=>s.issues.map(i=>cr(i,r,ar())))}),e)}const VC=J("$ZodUnion",(t,e)=>{Ne.init(t,e),me(t._zod,"optin",()=>e.options.some(o=>o._zod.optin==="optional")?"optional":void 0),me(t._zod,"optout",()=>e.options.some(o=>o._zod.optout==="optional")?"optional":void 0),me(t._zod,"values",()=>{if(e.options.every(o=>o._zod.values))return new Set(e.options.flatMap(o=>Array.from(o._zod.values)))}),me(t._zod,"pattern",()=>{if(e.options.every(o=>o._zod.pattern)){const o=e.options.map(s=>s._zod.pattern);return new RegExp(`^(${o.map(s=>Gl(s.source)).join("|")})$`)}});const n=e.options.length===1,r=e.options[0]._zod.run;t._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const a=[];for(const l of e.options){const c=l._zod.run({value:o.value,issues:[]},s);if(c instanceof Promise)a.push(c),i=!0;else{if(c.issues.length===0)return c;a.push(c)}}return i?Promise.all(a).then(l=>Lh(l,o,t,s)):Lh(a,o,t,s)}}),LC=J("$ZodIntersection",(t,e)=>{Ne.init(t,e),t._zod.parse=(n,r)=>{const o=n.value,s=e.left._zod.run({value:o,issues:[]},r),i=e.right._zod.run({value:o,issues:[]},r);return s instanceof Promise||i instanceof Promise?Promise.all([s,i]).then(([l,c])=>Fh(n,l,c)):Fh(n,s,i)}});function ec(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(Qo(t)&&Qo(e)){const n=Object.keys(e),r=Object.keys(t).filter(s=>n.indexOf(s)!==-1),o={...t,...e};for(const s of r){const i=ec(t[s],e[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<t.length;r++){const o=t[r],s=e[r],i=ec(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Fh(t,e,n){const r=new Map;let o;for(const a of e.issues)if(a.code==="unrecognized_keys"){o??(o=a);for(const l of a.keys)r.has(l)||r.set(l,{}),r.get(l).l=!0}else t.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const l of a.keys)r.has(l)||r.set(l,{}),r.get(l).r=!0;else t.issues.push(a);const s=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(s.length&&o&&t.issues.push({...o,keys:s}),oo(t))return t;const i=ec(e.value,n.value);if(!i.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(i.mergeErrorPath)}`);return t.value=i.data,t}const FC=J("$ZodEnum",(t,e)=>{Ne.init(t,e);const n=xh(e.entries),r=new Set(n);t._zod.values=r,t._zod.pattern=new RegExp(`^(${n.filter(o=>eC.has(typeof o)).map(o=>typeof o=="string"?tC(o):o.toString()).join("|")})$`),t._zod.parse=(o,s)=>{const i=o.value;return r.has(i)||o.issues.push({code:"invalid_value",values:n,input:i,inst:t}),o}}),jC=J("$ZodTransform",(t,e)=>{Ne.init(t,e),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Sh(t.constructor.name);const o=e.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(i=>(n.value=i,n));if(o instanceof Promise)throw new ro;return n.value=o,n}});function jh(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Hh=J("$ZodOptional",(t,e)=>{Ne.init(t,e),t._zod.optin="optional",t._zod.optout="optional",me(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),me(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Gl(n.source)})?$`):void 0}),t._zod.parse=(n,r)=>{if(e.innerType._zod.optin==="optional"){const o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>jh(s,n.value)):jh(o,n.value)}return n.value===void 0?n:e.innerType._zod.run(n,r)}}),HC=J("$ZodExactOptional",(t,e)=>{Hh.init(t,e),me(t._zod,"values",()=>e.innerType._zod.values),me(t._zod,"pattern",()=>e.innerType._zod.pattern),t._zod.parse=(n,r)=>e.innerType._zod.run(n,r)}),WC=J("$ZodNullable",(t,e)=>{Ne.init(t,e),me(t._zod,"optin",()=>e.innerType._zod.optin),me(t._zod,"optout",()=>e.innerType._zod.optout),me(t._zod,"pattern",()=>{const n=e.innerType._zod.pattern;return n?new RegExp(`^(${Gl(n.source)}|null)$`):void 0}),me(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(n,r)=>n.value===null?n:e.innerType._zod.run(n,r)}),ZC=J("$ZodDefault",(t,e)=>{Ne.init(t,e),t._zod.optin="optional",me(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);if(n.value===void 0)return n.value=e.defaultValue,n;const o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>Wh(s,e)):Wh(o,e)}});function Wh(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const UC=J("$ZodPrefault",(t,e)=>{Ne.init(t,e),t._zod.optin="optional",me(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=e.defaultValue),e.innerType._zod.run(n,r))}),KC=J("$ZodNonOptional",(t,e)=>{Ne.init(t,e),me(t._zod,"values",()=>{const n=e.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),t._zod.parse=(n,r)=>{const o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>Zh(s,t)):Zh(o,t)}});function Zh(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const JC=J("$ZodCatch",(t,e)=>{Ne.init(t,e),me(t._zod,"optin",()=>e.innerType._zod.optin),me(t._zod,"optout",()=>e.innerType._zod.optout),me(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>(n.value=s.value,s.issues.length&&(n.value=e.catchValue({...n,error:{issues:s.issues.map(i=>cr(i,r,ar()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=e.catchValue({...n,error:{issues:o.issues.map(s=>cr(s,r,ar()))},input:n.value}),n.issues=[]),n)}}),qC=J("$ZodPipe",(t,e)=>{Ne.init(t,e),me(t._zod,"values",()=>e.in._zod.values),me(t._zod,"optin",()=>e.in._zod.optin),me(t._zod,"optout",()=>e.out._zod.optout),me(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=e.out._zod.run(n,r);return s instanceof Promise?s.then(i=>Mi(i,e.in,r)):Mi(s,e.in,r)}const o=e.in._zod.run(n,r);return o instanceof Promise?o.then(s=>Mi(s,e.out,r)):Mi(o,e.out,r)}});function Mi(t,e,n){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},n)}const GC=J("$ZodReadonly",(t,e)=>{Ne.init(t,e),me(t._zod,"propValues",()=>e.innerType._zod.propValues),me(t._zod,"values",()=>e.innerType._zod.values),me(t._zod,"optin",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optin}),me(t._zod,"optout",()=>{var n,r;return(r=(n=e.innerType)==null?void 0:n._zod)==null?void 0:r.optout}),t._zod.parse=(n,r)=>{if(r.direction==="backward")return e.innerType._zod.run(n,r);const o=e.innerType._zod.run(n,r);return o instanceof Promise?o.then(Uh):Uh(o)}});function Uh(t){return t.value=Object.freeze(t.value),t}const YC=J("$ZodCustom",(t,e)=>{Ht.init(t,e),Ne.init(t,e),t._zod.parse=(n,r)=>n,t._zod.check=n=>{const r=n.value,o=e.fn(r);if(o instanceof Promise)return o.then(s=>Kh(s,n,r,t));Kh(o,n,r,t)}});function Kh(t,e,n,r){if(!t){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),e.issues.push(es(o))}}var Jh;class XC{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...n){const r=n[0];return this._map.set(e,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const n=this._map.get(e);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(e),this}get(e){const n=e._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function QC(){return new XC}(Jh=globalThis).__zod_globalRegistry??(Jh.__zod_globalRegistry=QC());const ts=globalThis.__zod_globalRegistry;function ex(t,e){return new t({type:"number",checks:[],..._e(e)})}function tx(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",..._e(e)})}function nx(t){return new t({type:"unknown"})}function rx(t,e){return new t({type:"never",..._e(e)})}function qh(t,e){return new Ph({check:"less_than",..._e(e),value:t,inclusive:!1})}function tc(t,e){return new Ph({check:"less_than",..._e(e),value:t,inclusive:!0})}function Gh(t,e){return new Rh({check:"greater_than",..._e(e),value:t,inclusive:!1})}function nc(t,e){return new Rh({check:"greater_than",..._e(e),value:t,inclusive:!0})}function Yh(t,e){return new _C({check:"multiple_of",..._e(e),value:t})}function ox(t,e){return new TC({check:"max_length",..._e(e),maximum:t})}function Xh(t,e){return new MC({check:"min_length",..._e(e),minimum:t})}function sx(t,e){return new AC({check:"length_equals",..._e(e),length:t})}function ix(t){return new NC({check:"overwrite",tx:t})}function ax(t,e,n){return new t({type:"array",element:e,..._e(n)})}function lx(t,e,n){return new t({type:"custom",check:"custom",fn:e,..._e(n)})}function cx(t){const e=dx(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(es(r,n.value,e._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),o.continue??(o.continue=!e._zod.def.abort),n.issues.push(es(o))}},t(n.value,n)));return e}function dx(t,e){const n=new Ht({check:"custom",..._e(e)});return n._zod.check=t,n}function Qh(t){let e=(t==null?void 0:t.target)??"draft-2020-12";return e==="draft-4"&&(e="draft-04"),e==="draft-7"&&(e="draft-07"),{processors:t.processors??{},metadataRegistry:(t==null?void 0:t.metadata)??ts,target:e,unrepresentable:(t==null?void 0:t.unrepresentable)??"throw",override:(t==null?void 0:t.override)??(()=>{}),io:(t==null?void 0:t.io)??"output",counter:0,seen:new Map,cycles:(t==null?void 0:t.cycles)??"ref",reused:(t==null?void 0:t.reused)??"inline",external:(t==null?void 0:t.external)??void 0}}function Ve(t,e,n={path:[],schemaPath:[]}){var u,f;var r;const o=t._zod.def,s=e.seen.get(t);if(s)return s.count++,n.schemaPath.includes(t)&&(s.cycle=n.path),s.schema;const i={schema:{},count:1,cycle:void 0,path:n.path};e.seen.set(t,i);const a=(f=(u=t._zod).toJSONSchema)==null?void 0:f.call(u);if(a)i.schema=a;else{const p={...n,schemaPath:[...n.schemaPath,t],path:n.path};if(t._zod.processJSONSchema)t._zod.processJSONSchema(e,i.schema,p);else{const g=i.schema,y=e.processors[o.type];if(!y)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);y(t,e,g,p)}const m=t._zod.parent;m&&(i.ref||(i.ref=m),Ve(m,e,p),e.seen.get(m).isParent=!0)}const l=e.metadataRegistry.get(t);return l&&Object.assign(i.schema,l),e.io==="input"&&Xe(t)&&(delete i.schema.examples,delete i.schema.default),e.io==="input"&&i.schema._prefault&&((r=i.schema).default??(r.default=i.schema._prefault)),delete i.schema._prefault,e.seen.get(t).schema}function ep(t,e){var i,a,l,c;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const u of t.seen.entries()){const f=(i=t.metadataRegistry.get(u[0]))==null?void 0:i.id;if(f){const p=r.get(f);if(p&&p!==u[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(f,u[0])}}const o=u=>{var y;const f=t.target==="draft-2020-12"?"$defs":"definitions";if(t.external){const k=(y=t.external.registry.get(u[0]))==null?void 0:y.id,w=t.external.uri??(b=>b);if(k)return{ref:w(k)};const v=u[1].defId??u[1].schema.id??`schema${t.counter++}`;return u[1].defId=v,{defId:v,ref:`${w("__shared")}#/${f}/${v}`}}if(u[1]===n)return{ref:"#"};const m=`#/${f}/`,g=u[1].schema.id??`__schema${t.counter++}`;return{defId:g,ref:m+g}},s=u=>{if(u[1].schema.$ref)return;const f=u[1],{ref:p,defId:m}=o(u);f.def={...f.schema},m&&(f.defId=m);const g=f.schema;for(const y in g)delete g[y];g.$ref=p};if(t.cycles==="throw")for(const u of t.seen.entries()){const f=u[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
|
|
68
|
-
|
|
69
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const u of t.seen.entries()){const f=u[1];if(e===u[0]){s(u);continue}if(t.external){const m=(l=t.external.registry.get(u[0]))==null?void 0:l.id;if(e!==u[0]&&m){s(u);continue}}if((c=t.metadataRegistry.get(u[0]))==null?void 0:c.id){s(u);continue}if(f.cycle){s(u);continue}if(f.count>1&&t.reused==="ref"){s(u);continue}}}function tp(t,e){var i,a,l;const n=t.seen.get(e);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=c=>{const u=t.seen.get(c);if(u.ref===null)return;const f=u.def??u.schema,p={...f},m=u.ref;if(u.ref=null,m){r(m);const y=t.seen.get(m),k=y.schema;if(k.$ref&&(t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(k)):Object.assign(f,k),Object.assign(f,p),c._zod.parent===m)for(const v in f)v==="$ref"||v==="allOf"||v in p||delete f[v];if(k.$ref&&y.def)for(const v in f)v==="$ref"||v==="allOf"||v in y.def&&JSON.stringify(f[v])===JSON.stringify(y.def[v])&&delete f[v]}const g=c._zod.parent;if(g&&g!==m){r(g);const y=t.seen.get(g);if(y!=null&&y.schema.$ref&&(f.$ref=y.schema.$ref,y.def))for(const k in f)k==="$ref"||k==="allOf"||k in y.def&&JSON.stringify(f[k])===JSON.stringify(y.def[k])&&delete f[k]}t.override({zodSchema:c,jsonSchema:f,path:u.path??[]})};for(const c of[...t.seen.entries()].reverse())r(c[0]);const o={};if(t.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":t.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":t.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":t.target,(i=t.external)!=null&&i.uri){const c=(a=t.external.registry.get(e))==null?void 0:a.id;if(!c)throw new Error("Schema is missing an `id` property");o.$id=t.external.uri(c)}Object.assign(o,n.def??n.schema);const s=((l=t.external)==null?void 0:l.defs)??{};for(const c of t.seen.entries()){const u=c[1];u.def&&u.defId&&(s[u.defId]=u.def)}t.external||Object.keys(s).length>0&&(t.target==="draft-2020-12"?o.$defs=s:o.definitions=s);try{const c=JSON.parse(JSON.stringify(o));return Object.defineProperty(c,"~standard",{value:{...e["~standard"],jsonSchema:{input:Ai(e,"input",t.processors),output:Ai(e,"output",t.processors)}},enumerable:!1,writable:!1}),c}catch{throw new Error("Error converting schema to JSON.")}}function Xe(t,e){const n=e??{seen:new Set};if(n.seen.has(t))return!1;n.seen.add(t);const r=t._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return Xe(r.element,n);if(r.type==="set")return Xe(r.valueType,n);if(r.type==="lazy")return Xe(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return Xe(r.innerType,n);if(r.type==="intersection")return Xe(r.left,n)||Xe(r.right,n);if(r.type==="record"||r.type==="map")return Xe(r.keyType,n)||Xe(r.valueType,n);if(r.type==="pipe")return Xe(r.in,n)||Xe(r.out,n);if(r.type==="object"){for(const o in r.shape)if(Xe(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(Xe(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(Xe(o,n))return!0;return!!(r.rest&&Xe(r.rest,n))}return!1}const ux=(t,e={})=>n=>{const r=Qh({...n,processors:e});return Ve(t,r),ep(r,t),tp(r,t)},Ai=(t,e,n={})=>r=>{const{libraryOptions:o,target:s}=r??{},i=Qh({...o??{},target:s,io:e,processors:n});return Ve(t,i),ep(i,t),tp(i,t)},fx=(t,e,n,r)=>{const o=n,{minimum:s,maximum:i,format:a,multipleOf:l,exclusiveMaximum:c,exclusiveMinimum:u}=t._zod.bag;typeof a=="string"&&a.includes("int")?o.type="integer":o.type="number",typeof u=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(o.minimum=u,o.exclusiveMinimum=!0):o.exclusiveMinimum=u),typeof s=="number"&&(o.minimum=s,typeof u=="number"&&e.target!=="draft-04"&&(u>=s?delete o.minimum:delete o.exclusiveMinimum)),typeof c=="number"&&(e.target==="draft-04"||e.target==="openapi-3.0"?(o.maximum=c,o.exclusiveMaximum=!0):o.exclusiveMaximum=c),typeof i=="number"&&(o.maximum=i,typeof c=="number"&&e.target!=="draft-04"&&(c<=i?delete o.maximum:delete o.exclusiveMaximum)),typeof l=="number"&&(o.multipleOf=l)},hx=(t,e,n,r)=>{n.not={}},px=(t,e,n,r)=>{},mx=(t,e,n,r)=>{const o=t._zod.def,s=xh(o.entries);s.every(i=>typeof i=="number")&&(n.type="number"),s.every(i=>typeof i=="string")&&(n.type="string"),n.enum=s},gx=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},yx=(t,e,n,r)=>{if(e.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},kx=(t,e,n,r)=>{const o=n,s=t._zod.def,{minimum:i,maximum:a}=t._zod.bag;typeof i=="number"&&(o.minItems=i),typeof a=="number"&&(o.maxItems=a),o.type="array",o.items=Ve(s.element,e,{...r,path:[...r.path,"items"]})},wx=(t,e,n,r)=>{var c;const o=n,s=t._zod.def;o.type="object",o.properties={};const i=s.shape;for(const u in i)o.properties[u]=Ve(i[u],e,{...r,path:[...r.path,"properties",u]});const a=new Set(Object.keys(i)),l=new Set([...a].filter(u=>{const f=s.shape[u]._zod;return e.io==="input"?f.optin===void 0:f.optout===void 0}));l.size>0&&(o.required=Array.from(l)),((c=s.catchall)==null?void 0:c._zod.def.type)==="never"?o.additionalProperties=!1:s.catchall?s.catchall&&(o.additionalProperties=Ve(s.catchall,e,{...r,path:[...r.path,"additionalProperties"]})):e.io==="output"&&(o.additionalProperties=!1)},vx=(t,e,n,r)=>{const o=t._zod.def,s=o.inclusive===!1,i=o.options.map((a,l)=>Ve(a,e,{...r,path:[...r.path,s?"oneOf":"anyOf",l]}));s?n.oneOf=i:n.anyOf=i},bx=(t,e,n,r)=>{const o=t._zod.def,s=Ve(o.left,e,{...r,path:[...r.path,"allOf",0]}),i=Ve(o.right,e,{...r,path:[...r.path,"allOf",1]}),a=c=>"allOf"in c&&Object.keys(c).length===1,l=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];n.allOf=l},Sx=(t,e,n,r)=>{const o=t._zod.def,s=Ve(o.innerType,e,r),i=e.seen.get(t);e.target==="openapi-3.0"?(i.ref=o.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},Cx=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType},xx=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))},_x=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType,e.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))},Ex=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType;let i;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i},Tx=(t,e,n,r)=>{const o=t._zod.def,s=e.io==="input"?o.in._zod.def.type==="transform"?o.out:o.in:o.out;Ve(s,e,r);const i=e.seen.get(t);i.ref=s},Mx=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType,n.readOnly=!0},np=(t,e,n,r)=>{const o=t._zod.def;Ve(o.innerType,e,r);const s=e.seen.get(t);s.ref=o.innerType},mt=J("ZodError",(t,e)=>{Bh.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:n=>fC(t,n)},flatten:{value:n=>uC(t,n)},addIssue:{value:n=>{t.issues.push(n),t.message=JSON.stringify(t.issues,Kl,2)}},addIssues:{value:n=>{t.issues.push(...n),t.message=JSON.stringify(t.issues,Kl,2)}},isEmpty:{get(){return t.issues.length===0}}})},{Parent:Error}),Ax=Xl(mt),Nx=Ql(mt),Bx=_i(mt),Ox=Ei(mt),Ix=mC(mt),Px=gC(mt),Rx=yC(mt),Dx=kC(mt),zx=wC(mt),$x=vC(mt),Vx=bC(mt),Lx=SC(mt),Be=J("ZodType",(t,e)=>(Ne.init(t,e),Object.assign(t["~standard"],{jsonSchema:{input:Ai(t,"input"),output:Ai(t,"output")}}),t.toJSONSchema=ux(t,{}),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...n)=>t.clone(_n(e,{checks:[...e.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),t.with=t.check,t.clone=(n,r)=>En(t,n,r),t.brand=()=>t,t.register=(n,r)=>(n.add(t,r),t),t.parse=(n,r)=>Ax(t,n,r,{callee:t.parse}),t.safeParse=(n,r)=>Bx(t,n,r),t.parseAsync=async(n,r)=>Nx(t,n,r,{callee:t.parseAsync}),t.safeParseAsync=async(n,r)=>Ox(t,n,r),t.spa=t.safeParseAsync,t.encode=(n,r)=>Ix(t,n,r),t.decode=(n,r)=>Px(t,n,r),t.encodeAsync=async(n,r)=>Rx(t,n,r),t.decodeAsync=async(n,r)=>Dx(t,n,r),t.safeEncode=(n,r)=>zx(t,n,r),t.safeDecode=(n,r)=>$x(t,n,r),t.safeEncodeAsync=async(n,r)=>Vx(t,n,r),t.safeDecodeAsync=async(n,r)=>Lx(t,n,r),t.refine=(n,r)=>t.check(g_(n,r)),t.superRefine=n=>t.check(y_(n)),t.overwrite=n=>t.check(ix(n)),t.optional=()=>lp(t),t.exactOptional=()=>r_(t),t.nullable=()=>cp(t),t.nullish=()=>lp(cp(t)),t.nonoptional=n=>c_(t,n),t.array=()=>Ux(t),t.or=n=>Gx([t,n]),t.and=n=>Xx(t,n),t.transform=n=>up(t,t_(n)),t.default=n=>i_(t,n),t.prefault=n=>l_(t,n),t.catch=n=>u_(t,n),t.pipe=n=>up(t,n),t.readonly=()=>p_(t),t.describe=n=>{const r=t.clone();return ts.add(r,{description:n}),r},Object.defineProperty(t,"description",{get(){var n;return(n=ts.get(t))==null?void 0:n.description},configurable:!0}),t.meta=(...n)=>{if(n.length===0)return ts.get(t);const r=t.clone();return ts.add(r,n[0]),r},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t.apply=n=>n(t),t)),rp=J("ZodNumber",(t,e)=>{Dh.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(r,o,s)=>fx(t,r,o),t.gt=(r,o)=>t.check(Gh(r,o)),t.gte=(r,o)=>t.check(nc(r,o)),t.min=(r,o)=>t.check(nc(r,o)),t.lt=(r,o)=>t.check(qh(r,o)),t.lte=(r,o)=>t.check(tc(r,o)),t.max=(r,o)=>t.check(tc(r,o)),t.int=r=>t.check(sp(r)),t.safe=r=>t.check(sp(r)),t.positive=r=>t.check(Gh(0,r)),t.nonnegative=r=>t.check(nc(0,r)),t.negative=r=>t.check(qh(0,r)),t.nonpositive=r=>t.check(tc(0,r)),t.multipleOf=(r,o)=>t.check(Yh(r,o)),t.step=(r,o)=>t.check(Yh(r,o)),t.finite=()=>t;const n=t._zod.bag;t.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),t.isFinite=!0,t.format=n.format??null});function op(t){return ex(rp,t)}const Fx=J("ZodNumberFormat",(t,e)=>{IC.init(t,e),rp.init(t,e)});function sp(t){return tx(Fx,t)}const jx=J("ZodUnknown",(t,e)=>{PC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>px()});function ip(){return nx(jx)}const Hx=J("ZodNever",(t,e)=>{RC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>hx(t,n,r)});function Wx(t){return rx(Hx,t)}const Zx=J("ZodArray",(t,e)=>{DC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>kx(t,n,r,o),t.element=e.element,t.min=(n,r)=>t.check(Xh(n,r)),t.nonempty=n=>t.check(Xh(1,n)),t.max=(n,r)=>t.check(ox(n,r)),t.length=(n,r)=>t.check(sx(n,r)),t.unwrap=()=>t.element});function Ux(t,e){return ax(Zx,t,e)}const Kx=J("ZodObject",(t,e)=>{$C.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>wx(t,n,r,o),me(t,"shape",()=>e.shape),t.keyof=()=>Qx(Object.keys(t._zod.def.shape)),t.catchall=n=>t.clone({...t._zod.def,catchall:n}),t.passthrough=()=>t.clone({...t._zod.def,catchall:ip()}),t.loose=()=>t.clone({...t._zod.def,catchall:ip()}),t.strict=()=>t.clone({...t._zod.def,catchall:Wx()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=n=>iC(t,n),t.safeExtend=n=>aC(t,n),t.merge=n=>lC(t,n),t.pick=n=>oC(t,n),t.omit=n=>sC(t,n),t.partial=(...n)=>cC(ap,t,n[0]),t.required=(...n)=>dC(dp,t,n[0])});function Jx(t,e){const n={type:"object",shape:t??{},..._e(e)};return new Kx(n)}const qx=J("ZodUnion",(t,e)=>{VC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>vx(t,n,r,o),t.options=e.options});function Gx(t,e){return new qx({type:"union",options:t,..._e(e)})}const Yx=J("ZodIntersection",(t,e)=>{LC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>bx(t,n,r,o)});function Xx(t,e){return new Yx({type:"intersection",left:t,right:e})}const rc=J("ZodEnum",(t,e)=>{FC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(r,o,s)=>mx(t,r,o),t.enum=e.entries,t.options=Object.values(e.entries);const n=new Set(Object.keys(e.entries));t.extract=(r,o)=>{const s={};for(const i of r)if(n.has(i))s[i]=e.entries[i];else throw new Error(`Key ${i} not found in enum`);return new rc({...e,checks:[],..._e(o),entries:s})},t.exclude=(r,o)=>{const s={...e.entries};for(const i of r)if(n.has(i))delete s[i];else throw new Error(`Key ${i} not found in enum`);return new rc({...e,checks:[],..._e(o),entries:s})}});function Qx(t,e){const n=Array.isArray(t)?Object.fromEntries(t.map(r=>[r,r])):t;return new rc({type:"enum",entries:n,..._e(e)})}const e_=J("ZodTransform",(t,e)=>{jC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>yx(t,n),t._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Sh(t.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(es(s,n.value,e));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=t),n.issues.push(es(i))}};const o=e.transform(n.value,n);return o instanceof Promise?o.then(s=>(n.value=s,n)):(n.value=o,n)}});function t_(t){return new e_({type:"transform",transform:t})}const ap=J("ZodOptional",(t,e)=>{Hh.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>np(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function lp(t){return new ap({type:"optional",innerType:t})}const n_=J("ZodExactOptional",(t,e)=>{HC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>np(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function r_(t){return new n_({type:"optional",innerType:t})}const o_=J("ZodNullable",(t,e)=>{WC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>Sx(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function cp(t){return new o_({type:"nullable",innerType:t})}const s_=J("ZodDefault",(t,e)=>{ZC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>xx(t,n,r,o),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function i_(t,e){return new s_({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():Mh(e)}})}const a_=J("ZodPrefault",(t,e)=>{UC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>_x(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function l_(t,e){return new a_({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():Mh(e)}})}const dp=J("ZodNonOptional",(t,e)=>{KC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>Cx(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function c_(t,e){return new dp({type:"nonoptional",innerType:t,..._e(e)})}const d_=J("ZodCatch",(t,e)=>{JC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>Ex(t,n,r,o),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function u_(t,e){return new d_({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const f_=J("ZodPipe",(t,e)=>{qC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>Tx(t,n,r,o),t.in=e.in,t.out=e.out});function up(t,e){return new f_({type:"pipe",in:t,out:e})}const h_=J("ZodReadonly",(t,e)=>{GC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>Mx(t,n,r,o),t.unwrap=()=>t._zod.def.innerType});function p_(t){return new h_({type:"readonly",innerType:t})}const m_=J("ZodCustom",(t,e)=>{YC.init(t,e),Be.init(t,e),t._zod.processJSONSchema=(n,r,o)=>gx(t,n)});function g_(t,e={}){return lx(m_,t,e)}function y_(t){return cx(t)}var k_=Object.defineProperty,oc=(t,e)=>{for(var n in e)k_(t,n,{get:e[n],enumerable:!0})},fp=h.defineCommand("start-eraser-stroke"),hp=h.defineCommand("add-eraser-stroke-point"),pp=h.defineCommand("complete-eraser-stroke"),mp=h.defineCommand("cancel-eraser-stroke");h.defineCommand("mark-as-erased");var gp={};oc(gp,{Erased:()=>dr,EraserStroke:()=>ns});var dr=h.defineCanvasComponent({name:"erased"},{eraserStrokeId:h.field.ref()}),so=8,w_="eraser",Wt=20,ns=h.defineCanvasComponent({name:"eraserStroke"},{points:h.field.buffer(h.field.float32()).size(Wt*2),pointCount:h.field.uint32().default(0),firstPointIndex:h.field.uint32().default(0),radius:h.field.float32().default(8)}),yp={};oc(yp,{EraserStateSingleton:()=>sc});var ur={Idle:"idle",Erasing:"erasing"},sc=h.defineEditorState("eraserState",{state:h.field.string().max(16).default(ur.Idle),activeStroke:h.field.ref(),lastWorldPosition:h.field.tuple(h.field.float64(),2).default([0,0])}),kp={};oc(kp,{captureEraserSystem:()=>b_,updateEraserSystem:()=>x_});var v_=on({guards:{},actions:{startStroke:({event:t})=>{fp.spawn(t.ctx,{worldPosition:t.worldPosition})},addPoint:we({lastWorldPosition:({event:t,context:e})=>e.activeStroke?(hp.spawn(t.ctx,{strokeId:e.activeStroke,worldPosition:t.worldPosition}),[t.worldPosition[0],t.worldPosition[1]]):e.lastWorldPosition}),completeStroke:({event:t,context:e})=>{e.activeStroke&&pp.spawn(t.ctx,{strokeId:e.activeStroke})},cancelStroke:({event:t,context:e})=>{e.activeStroke&&mp.spawn(t.ctx,{strokeId:e.activeStroke})},resetContext:we({activeStroke:()=>null,lastWorldPosition:()=>[0,0]})}}).createMachine({id:"eraser",initial:ur.Idle,context:{activeStroke:null,lastWorldPosition:[0,0]},states:{[ur.Idle]:{entry:["resetContext"],on:{pointerDown:{target:ur.Erasing,actions:["startStroke"]}}},[ur.Erasing]:{on:{pointerMove:{actions:["addPoint"]},frame:{actions:["addPoint"]},pointerUp:{target:ur.Idle,actions:["completeStroke"]},cancel:{target:ur.Idle,actions:["cancelStroke"]}}}}}),b_=h.defineEditorSystem({phase:"capture",priority:100},t=>{const e=h.Controls.getButtons(t,"eraser"),n=h.getPointerInput(t,e,{includeFrameEvent:!0});n.length!==0&&sc.run(t,v_,n)}),S_=h.defineQuery(t=>t.with(h.Block,h.Synced,h.Aabb)),C_=h.defineQuery(t=>t.with(dr)),x_=h.defineEditorSystem({phase:"update"},t=>{h.on(t,fp,(e,{worldPosition:n})=>{__(e,n)}),h.on(t,hp,(e,{strokeId:n,worldPosition:r})=>{E_(e,n,r)}),h.on(t,pp,(e,{strokeId:n})=>{A_(e,n)}),h.on(t,mp,(e,{strokeId:n})=>{N_(e,n)})});function __(t,e){const n=h.createEntity(t);h.addComponent(t,n,h.Block,{tag:"eraser",rank:h.RankBounds.genNext(t),position:[e[0]-so,e[1]-so],size:[so*2,so*2]}),h.addComponent(t,n,ns,{points:e,pointCount:1,firstPointIndex:0,radius:so});const r=sc.write(t);r.activeStroke=n,r.lastWorldPosition=e}function E_(t,e,n){const r=ns.write(t,e),o=r.pointCount,s=(o-1)%Wt*2,i=r.points[s],a=r.points[s+1],l=o%Wt*2;if(r.points[l]=n[0],r.points[l+1]=n[1],r.pointCount++,r.pointCount>Wt&&(r.firstPointIndex=(r.pointCount-Wt)%Wt),!h.Aabb.containsPoint(t,e,n)){h.Aabb.expandByPoint(t,e,n);const{value:y}=h.Aabb.read(t,e),k=h.Block.write(t,e);E.Vec2.set(k.position,E.Aabb.left(y),E.Aabb.top(y)),E.Vec2.set(k.size,E.Aabb.width(y),E.Aabb.height(y))}const c=n[0]-i,u=n[1]-a;if(c*c+u*u<1)return;const p=E.Capsule.create(i,a,n[0],n[1],so),m=T_(t,S_.current(t)),g=h.intersectCapsule(t,p,m);for(const y of g)M_(t,y,e)}function*T_(t,e){for(const n of e)h.hasComponent(t,n,dr)||(yield n)}function M_(t,e,n){h.addComponent(t,e,dr,{eraserStrokeId:n}),h.addComponent(t,e,h.Opacity,{value:80})}function A_(t,e){const n=h.getBackrefs(t,e,dr,"eraserStrokeId");for(const r of n)h.removeEntity(t,r);h.removeEntity(t,e)}function N_(t,e){const n=[];for(const r of C_.current(t))dr.read(t,r).eraserStrokeId===e&&n.push(r);for(const r of n)h.removeComponent(t,r,dr),h.removeComponent(t,r,h.Opacity);h.removeEntity(t,e)}var B_=t=>Object.values(t).filter(e=>typeof e=="object"&&e!==null&&"_system"in e&&"phase"in e),O_=Jx({tailRadius:op().positive().optional(),tailLength:op().int().min(1).max(Wt).optional()});function I_(t={}){const e=O_.parse(t);return{name:w_,components:Object.values(gp).filter(n=>n instanceof h.CanvasComponentDef),singletons:Object.values(yp).filter(n=>n instanceof h.CanvasSingletonDef),blockDefs:[{tag:"eraser-stroke",stratum:"overlay",canRotate:!1,canScale:!1,components:[ns]}],systems:B_(kp),resources:{tailRadius:e.tailRadius??8,tailLength:e.tailLength??Wt}}}const{PI:P_}=Math,rs=P_+1e-4,wp=.5,vp=[1,1];function bp(t,e,n,r=o=>o){return t*r(.5-e*(.5-n))}const{min:ic}=Math;function Sp(t,e,n){let r=ic(1,e/n);return ic(1,t+(ic(1,1-r)-t)*(r*.275))}function R_(t){return[-t[0],-t[1]]}function Zt(t,e){return[t[0]+e[0],t[1]+e[1]]}function Cp(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t}function Tn(t,e){return[t[0]-e[0],t[1]-e[1]]}function ac(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t}function Mn(t,e){return[t[0]*e,t[1]*e]}function lc(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t}function D_(t,e){return[t[0]/e,t[1]/e]}function xp(t){return[t[1],-t[0]]}function cc(t,e){let n=e[0];return t[0]=e[1],t[1]=-n,t}function _p(t,e){return t[0]*e[0]+t[1]*e[1]}function z_(t,e){return t[0]===e[0]&&t[1]===e[1]}function $_(t){return Math.hypot(t[0],t[1])}function Ep(t,e){let n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r}function Tp(t){return D_(t,$_(t))}function V_(t,e){return Math.hypot(t[1]-e[1],t[0]-e[0])}function dc(t,e,n){let r=Math.sin(n),o=Math.cos(n),s=t[0]-e[0],i=t[1]-e[1],a=s*o-i*r,l=s*r+i*o;return[a+e[0],l+e[1]]}function Mp(t,e,n,r){let o=Math.sin(r),s=Math.cos(r),i=e[0]-n[0],a=e[1]-n[1],l=i*s-a*o,c=i*o+a*s;return t[0]=l+n[0],t[1]=c+n[1],t}function Ap(t,e,n){return Zt(t,Mn(Tn(e,t),n))}function L_(t,e,n,r){let o=n[0]-e[0],s=n[1]-e[1];return t[0]=e[0]+o*r,t[1]=e[1]+s*r,t}function Np(t,e,n){return Zt(t,Mn(e,n))}const Le=[0,0],An=[0,0],Nn=[0,0];function F_(t,e){let n=Np(t,Tp(xp(Tn(t,Zt(t,[1,1])))),-e),r=[],o=1/13;for(let s=o;s<=1;s+=o)r.push(dc(n,t,rs*2*s));return r}function j_(t,e,n){let r=[],o=1/n;for(let s=o;s<=1;s+=o)r.push(dc(e,t,rs*s));return r}function H_(t,e,n){let r=Tn(e,n),o=Mn(r,.5),s=Mn(r,.51);return[Tn(t,o),Tn(t,s),Zt(t,s),Zt(t,o)]}function W_(t,e,n,r){let o=[],s=Np(t,e,n),i=1/r;for(let a=i;a<1;a+=i)o.push(dc(s,t,rs*3*a));return o}function Z_(t,e,n){return[Zt(t,Mn(e,n)),Zt(t,Mn(e,n*.99)),Tn(t,Mn(e,n*.99)),Tn(t,Mn(e,n))]}function Bp(t,e,n){return t===!1||t===void 0?0:t===!0?Math.max(e,n):t}function U_(t,e,n){return t.slice(0,10).reduce((r,o)=>{let s=o.pressure;return e&&(s=Sp(r,o.distance,n)),(r+s)/2},t[0].pressure)}function K_(t,e={}){let{size:n=16,smoothing:r=.5,thinning:o=.5,simulatePressure:s=!0,easing:i=X=>X,start:a={},end:l={},last:c=!1}=e,{cap:u=!0,easing:f=X=>X*(2-X)}=a,{cap:p=!0,easing:m=X=>--X*X*X+1}=l;if(t.length===0||n<=0)return[];let g=t[t.length-1].runningLength,y=Bp(a.taper,n,g),k=Bp(l.taper,n,g),w=(n*r)**2,v=[],b=[],S=U_(t,s,n),C=bp(n,o,t[t.length-1].pressure,i),_,x=t[0].vector,T=t[0].point,N=T,I=T,V=N,K=!1;for(let X=0;X<t.length;X++){let{pressure:j}=t[X],{point:q,vector:te,distance:fe,runningLength:ce}=t[X],Se=X===t.length-1;if(!Se&&g-ce<3)continue;o?(s&&(j=Sp(S,fe,n)),C=bp(n,o,j,i)):C=n/2,_===void 0&&(_=C);let Dt=ce<y?f(ce/y):1,gn=g-ce<k?m((g-ce)/k):1;C=Math.max(.01,C*Math.min(Dt,gn));let Dr=(Se?t[X]:t[X+1]).vector,qn=Se?1:_p(te,Dr),ja=_p(te,x)<0&&!K,xo=qn!==null&&qn<0;if(ja||xo){cc(Le,x),lc(Le,Le,C);for(let Gn=0;Gn<=1;Gn+=.07692307692307693)ac(An,q,Le),Mp(An,An,q,rs*Gn),I=[An[0],An[1]],v.push(I),Cp(Nn,q,Le),Mp(Nn,Nn,q,rs*-Gn),V=[Nn[0],Nn[1]],b.push(V);T=I,N=V,xo&&(K=!0);continue}if(K=!1,Se){cc(Le,te),lc(Le,Le,C),v.push(Tn(q,Le)),b.push(Zt(q,Le));continue}L_(Le,Dr,te,qn),cc(Le,Le),lc(Le,Le,C),ac(An,q,Le),I=[An[0],An[1]],(X<=1||Ep(T,I)>w)&&(v.push(I),T=I),Cp(Nn,q,Le),V=[Nn[0],Nn[1]],(X<=1||Ep(N,V)>w)&&(b.push(V),N=V),S=j,x=te}let M=[t[0].point[0],t[0].point[1]],$=t.length>1?[t[t.length-1].point[0],t[t.length-1].point[1]]:Zt(t[0].point,[1,1]),Z=[],ae=[];if(t.length===1){if(!(y||k)||c)return F_(M,_||C)}else{y||k&&t.length===1||(u?Z.push(...j_(M,b[0],13)):Z.push(...H_(M,v[0],b[0])));let X=xp(R_(t[t.length-1].vector));k||y&&t.length===1?ae.push($):p?ae.push(...W_($,X,C,29)):ae.push(...Z_($,X,C))}return v.concat(ae,b.reverse(),Z)}const Op=[0,0];function Ip(t){return t!=null&&t>=0}function J_(t,e={}){var p;let{streamline:n=.5,size:r=16,last:o=!1}=e;if(t.length===0)return[];let s=.15+(1-n)*.85,i=Array.isArray(t[0])?t:t.map(({x:m,y:g,pressure:y=wp})=>[m,g,y]);if(i.length===2){let m=i[1];i=i.slice(0,-1);for(let g=1;g<5;g++)i.push(Ap(i[0],m,g/4))}i.length===1&&(i=[...i,[...Zt(i[0],vp),...i[0].slice(2)]]);let a=[{point:[i[0][0],i[0][1]],pressure:Ip(i[0][2])?i[0][2]:.25,vector:[...vp],distance:0,runningLength:0}],l=!1,c=0,u=a[0],f=i.length-1;for(let m=1;m<i.length;m++){let g=o&&m===f?[i[m][0],i[m][1]]:Ap(u.point,i[m],s);if(z_(u.point,g))continue;let y=V_(g,u.point);if(c+=y,m<f&&!l){if(c<r)continue;l=!0}ac(Op,u.point,g),u={point:g,pressure:Ip(i[m][2])?i[m][2]:wp,vector:Tp(Op),distance:y,runningLength:c},a.push(u)}return a[0].vector=((p=a[1])==null?void 0:p.vector)||[0,0],a}function uc(t,e={}){return K_(J_(t,e),e)}const q_={class:"wov-eraser-stroke"},G_={preserveAspectRatio:"none"},Y_=["d"],X_="#88888833",Pp=d.defineComponent({__name:"Eraser",props:{entityId:{}},setup(t){const e=t,n=Pe(e.entityId,ns),r=Pe(e.entityId,h.Block),o=d.shallowRef("");function s(a,l){return(a+l)/2}function i(a,l,c,u,f,p){if(a<=4)return"";const m=[],g=Math.min(a,Wt);for(let S=0;S<g;S++){const C=(l+S)%Wt*2;m.push([c[C]-f,c[C+1]-p])}const y=uc(m,{size:u,start:{taper:66,cap:!0}});if(y.length<3)return"";let k=y[0],w=y[1];const v=y[2];let b=`M${k[0].toFixed(2)},${k[1].toFixed(2)} Q${w[0].toFixed(2)},${w[1].toFixed(2)} ${s(w[0],v[0]).toFixed(2)},${s(w[1],v[1]).toFixed(2)} T`;for(let S=2;S<y.length-1;S++)k=y[S],w=y[S+1],b+=`${s(k[0],w[0]).toFixed(2)},${s(k[1],w[1]).toFixed(2)} `;return b+=`${w[0].toFixed(2)},${w[1].toFixed(2)} `,b+="Z",b}return d.watch([n,r],([a,l])=>{if(!a||!l){o.value="";return}const c=a.radius??8,[u,f]=l.position;o.value=i(a.pointCount,a.firstPointIndex,a.points,2*c,u,f)},{immediate:!0}),(a,l)=>(d.openBlock(),d.createElementBlock("div",q_,[(d.openBlock(),d.createElementBlock("svg",G_,[d.createElementVNode("path",{d:o.value,fill:X_},null,8,Y_)]))]))}}),Q_={class:"wov-image-block"},eE={key:0,class:"wov-image-placeholder"},tE={key:1,class:"wov-image-placeholder wov-image-error"},nE=["src","alt"],rE={key:3,class:"wov-image-upload-overlay"},oE={class:"wov-image-upload-status"},Rp=d.defineComponent({__name:"ImageBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=d.inject(pt);if(!n)throw new Error("ImageBlock must be used within a WovenCanvas component");const r=n,o=Pe(e.entityId,h.Asset),s=Pe(e.entityId,h.Image),i=d.ref(null),a=d.ref(!0),l=d.ref(!1);let c=!0;d.onUnmounted(()=>{c=!1});async function u(){const m=r.getAssetManager();if(!m){a.value=!1,l.value=!0;return}const g=o.value;if(!g){a.value=!1;return}try{a.value=!0,l.value=!1;const y=await m.getDisplayUrl(g.identifier);if(!c)return;y?(i.value=y,a.value=!1):g.uploadState===h.UploadState.Failed&&(l.value=!0,a.value=!1)}catch(y){if(!c)return;console.error("Failed to get display URL:",y),l.value=!0,a.value=!1}}d.watch(()=>o.value,()=>{u()},{immediate:!0}),d.onMounted(()=>{u()});const f=d.computed(()=>{const m=o.value;if(!m)return null;switch(m.uploadState){case h.UploadState.Pending:return"Loading...";case h.UploadState.Uploading:return"Loading...";case h.UploadState.Failed:return"Failed";default:return null}}),p=d.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(m,g)=>{var y;return d.openBlock(),d.createElementBlock("div",Q_,[a.value&&!i.value?(d.openBlock(),d.createElementBlock("div",eE,[...g[0]||(g[0]=[d.createElementVNode("span",null,"Loading...",-1)])])):l.value?(d.openBlock(),d.createElementBlock("div",tE,[...g[1]||(g[1]=[d.createElementVNode("span",null,"Failed to load image",-1)])])):i.value?(d.openBlock(),d.createElementBlock("img",{key:2,src:i.value,alt:((y=d.unref(s))==null?void 0:y.alt)||"",style:d.normalizeStyle(p.value),draggable:"false"},null,12,nE)):d.createCommentVNode("",!0),f.value?(d.openBlock(),d.createElementBlock("div",rE,[d.createElementVNode("span",oE,d.toDisplayString(f.value),1)])):d.createCommentVNode("",!0)])}}});function sE(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Dp={exports:{}};(function(t){(function(){function e(a,l){var c=a.x-l.x,u=a.y-l.y;return c*c+u*u}function n(a,l,c){var u=l.x,f=l.y,p=c.x-u,m=c.y-f;if(p!==0||m!==0){var g=((a.x-u)*p+(a.y-f)*m)/(p*p+m*m);g>1?(u=c.x,f=c.y):g>0&&(u+=p*g,f+=m*g)}return p=a.x-u,m=a.y-f,p*p+m*m}function r(a,l){for(var c=a[0],u=[c],f,p=1,m=a.length;p<m;p++)f=a[p],e(f,c)>l&&(u.push(f),c=f);return c!==f&&u.push(f),u}function o(a,l,c,u,f){for(var p=u,m,g=l+1;g<c;g++){var y=n(a[g],a[l],a[c]);y>p&&(m=g,p=y)}p>u&&(m-l>1&&o(a,l,m,u,f),f.push(a[m]),c-m>1&&o(a,m,c,u,f))}function s(a,l){var c=a.length-1,u=[a[0]];return o(a,0,c,l,u),u.push(a[c]),u}function i(a,l,c){if(a.length<=2)return a;var u=l!==void 0?l*l:1;return a=c?a:r(a,u),a=s(a,u),a}t.exports=i,t.exports.default=i})()})(Dp);var iE=Dp.exports;const zp=sE(iE);var aE=Object.defineProperty,fc=(t,e)=>{for(var n in e)aE(t,n,{get:e[n],enumerable:!0})},$p=h.defineCommand("start-pen-stroke"),Vp=h.defineCommand("add-pen-stroke-point"),Lp=h.defineCommand("complete-pen-stroke"),Fp=h.defineCommand("remove-pen-stroke"),jp={};fc(jp,{POINTS_CAPACITY:()=>Ni,PenStroke:()=>Nt});var Ni=256,lE={points:h.field.buffer(h.field.float32()).size(Ni*2),pressures:h.field.buffer(h.field.float32()).size(Ni),pointCount:h.field.uint32().default(0),thickness:h.field.float32().default(8),originalLeft:h.field.float32().default(0),originalTop:h.field.float32().default(0),originalWidth:h.field.float32().default(0),originalHeight:h.field.float32().default(0),isComplete:h.field.boolean().default(!1),hasPressure:h.field.boolean().default(!1)},cE=class extends h.CanvasComponentDef{constructor(){super({name:"penStroke",sync:"document"},lE)}snapshot(t,e){const n=super.snapshot(t,e),r=n.pointCount;return n.points=n.points.slice(0,r*2),n.pressures=n.hasPressure?n.pressures.slice(0,r):new Float32Array(0),n}},Nt=new cE,dE=8,uE="pen",Hp={};fc(Hp,{PenStateSingleton:()=>hc});var fr={Idle:"idle",Drawing:"drawing"},hc=h.defineEditorState("penState",{state:h.field.string().max(16).default(fr.Idle),activeStroke:h.field.ref(),lastWorldPosition:h.field.tuple(h.field.float64(),2).default([0,0])}),Wp={};fc(Wp,{capturePenSystem:()=>hE,updatePenSystem:()=>mE});var fE=on({guards:{},actions:{startStroke:({event:t})=>{const e=t.pointerType===h.PointerType.Pen?t.pressure:null;$p.spawn(t.ctx,{worldPosition:t.worldPosition,pressure:e,thickness:dE})},addPoint:we({lastWorldPosition:({event:t,context:e})=>{if(!e.activeStroke)return e.lastWorldPosition;const n=t.pointerType===h.PointerType.Pen?t.pressure:null;return Vp.spawn(t.ctx,{strokeId:e.activeStroke,worldPosition:t.worldPosition,pressure:n}),t.worldPosition}}),completeStroke:({event:t,context:e})=>{e.activeStroke&&Lp.spawn(t.ctx,{strokeId:e.activeStroke})},removeStroke:({event:t,context:e})=>{e.activeStroke&&Fp.spawn(t.ctx,{strokeId:e.activeStroke})},resetContext:we({activeStroke:()=>null,lastWorldPosition:()=>[0,0]})}}).createMachine({id:"pen",initial:fr.Idle,context:{activeStroke:null,lastWorldPosition:[0,0]},states:{[fr.Idle]:{entry:["resetContext"],on:{pointerDown:{target:fr.Drawing,actions:["startStroke"]}}},[fr.Drawing]:{on:{pointerMove:{actions:["addPoint"]},pointerUp:{target:fr.Idle,actions:["completeStroke"]},cancel:{target:fr.Idle,actions:["removeStroke"]}}}}}),hE=h.defineEditorSystem({phase:"capture",priority:100},t=>{const e=h.Controls.getButtons(t,"pen"),n=h.getPointerInput(t,e);n.length!==0&&hc.run(t,fE,n)}),pE=h.defineQuery(t=>t.tracking(Nt)),mE=h.defineEditorSystem({phase:"update"},t=>{h.on(t,$p,(e,{worldPosition:n,pressure:r,thickness:o})=>{gE(e,n,r,o)}),h.on(t,Vp,(e,{strokeId:n,worldPosition:r,pressure:o})=>{yE(e,n,r,o)}),h.on(t,Lp,(e,{strokeId:n})=>{kE(e,n)}),h.on(t,Fp,(e,{strokeId:n})=>{wE(e,n)});for(const e of pE.addedOrChanged(t))Nt.read(t,e).isComplete&&Zp(t,e)});function gE(t,e,n,r){const o=r/2,s=h.createEntity(t);h.addComponent(t,s,h.Synced,{id:crypto.randomUUID()}),h.addComponent(t,s,h.Block,{tag:"pen-stroke",rank:h.RankBounds.genNext(t),position:[e[0]-o,e[1]-o],size:[o*2,o*2]}),h.addComponent(t,s,h.Color,{});const{sessionId:i}=h.getResources(t);h.addComponent(t,s,h.Held,{sessionId:i});const a=n!==null,l=a?n:.5;h.addComponent(t,s,Nt,{points:e,pressures:[l],pointCount:1,thickness:r,originalLeft:e[0]-o,originalTop:e[1]-o,originalWidth:o*2,originalHeight:o*2,isComplete:!1,hasPressure:a});const c=hc.write(t);c.activeStroke=s,c.lastWorldPosition=e}function yE(t,e,n,r){const o=Nt.write(t,e),s=o.pointCount;if(!(s>=Ni)&&(o.points[s*2]=n[0],o.points[s*2+1]=n[1],r!==null?o.pressures[s]=r:o.pressures[s]=.5,o.pointCount++,!h.Aabb.containsPoint(t,e,n))){h.Aabb.expandByPoint(t,e,n);const{value:i}=h.Aabb.read(t,e),a=h.Block.write(t,e);E.Vec2.set(a.position,E.Aabb.left(i),E.Aabb.top(i)),E.Vec2.set(a.size,E.Aabb.width(i),E.Aabb.height(i)),o.originalLeft=a.position[0],o.originalTop=a.position[1],o.originalWidth=a.size[0],o.originalHeight=a.size[1]}}function kE(t,e){const n=Nt.write(t,e);n.isComplete=!0,h.removeComponent(t,e,h.Held),Zp(t,e)}function wE(t,e){h.removeEntity(t,e)}function Zp(t,e){const n=Nt.read(t,e),r=[];for(let u=0;u<n.pointCount;u++)r.push({x:n.points[u*2],y:n.points[u*2+1]});let o=n.thickness,s=zp(r,o,!1);for(;s.length-1>h.MAX_HIT_CAPSULES;)o*=2,s=zp(r,o,!1);if(s.length===1){const u=s[0];s.push({x:u.x,y:u.y})}h.hasComponent(t,e,h.HitGeometry)?h.HitGeometry.clear(t,e):h.addComponent(t,e,h.HitGeometry,{});const{originalLeft:i,originalTop:a,originalWidth:l,originalHeight:c}=n;for(let u=0;u<s.length-1;u++){const f=s[u],p=s[u+1],m=[(f.x-i)/l,(f.y-a)/c],g=[(p.x-i)/l,(p.y-a)/c];h.HitGeometry.addCapsuleUv(t,e,m,g,n.thickness)}}var vE=t=>Object.values(t).filter(e=>typeof e=="object"&&e!==null&&"_system"in e&&"phase"in e);function bE(){return{name:uE,components:Object.values(jp).filter(t=>t instanceof h.CanvasComponentDef),singletons:Object.values(Hp).filter(t=>t instanceof h.CanvasSingletonDef),blockDefs:[{tag:"pen-stroke",resizeMode:h.ResizeMode.Free,components:[Nt,h.Color],connectors:{enabled:!1}}],systems:vE(Wp),resources:{}}}const SE=["data-complete"],CE={preserveAspectRatio:"none"},xE=["d","fill"],_E={key:0,class:"highlight",preserveAspectRatio:"none"},EE=["d"],Up=ir(d.defineComponent({__name:"PenStroke",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=Pe(e.entityId,Nt),r=Pe(e.entityId,h.Block),o=Pe(e.entityId,h.Color),s=d.shallowRef(""),i=d.shallowRef("");function a(f,p){return(f+p)/2}function l(f,p,m){if(p<=4||f.length<3){const v=m/2;return`M ${v},0 a ${v},${v} 0 1 0 0.0001 0`}let g=f[0],y=f[1];const k=f[2];let w=`M${g[0].toFixed(2)},${g[1].toFixed(2)} Q${y[0].toFixed(2)},${y[1].toFixed(2)} ${a(y[0],k[0]).toFixed(2)},${a(y[1],k[1]).toFixed(2)} T`;for(let v=2;v<f.length-1;v++)g=f[v],y=f[v+1],w+=`${a(g[0],y[0]).toFixed(2)},${a(g[1],y[1]).toFixed(2)} `;return w+=`${y[0].toFixed(2)},${y[1].toFixed(2)} `,w+="Z",w}d.watch([n,r],([f,p])=>{if(!f||!p){s.value="",i.value="";return}if(!f.originalWidth||!f.originalHeight){s.value="",i.value="";return}const m=p.size[0]/f.originalWidth,g=p.size[1]/f.originalHeight,y=[];for(let w=0;w<f.pointCount;w++){const v=f.points[w*2],b=f.points[w*2+1],S=(v-f.originalLeft)*m,C=(b-f.originalTop)*g;f.hasPressure?y.push([S,C,f.pressures[w]]):y.push([S,C])}const k=uc(y,{last:f.isComplete,size:f.thickness,simulatePressure:!f.hasPressure});if(s.value=l(k,f.pointCount,f.thickness),f.isComplete){const w=y.length===1?f.thickness:1,v=uc(y,{last:!0,size:w,simulatePressure:!f.hasPressure});i.value=l(v,f.pointCount,w)}},{immediate:!0});const c=d.computed(()=>o.value?`rgb(${o.value.red}, ${o.value.green}, ${o.value.blue})`:"#000000"),u=d.computed(()=>e.selected||e.hovered);return(f,p)=>{var m;return d.openBlock(),d.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((m=d.unref(n))==null?void 0:m.isComplete)||void 0},[(d.openBlock(),d.createElementBlock("svg",CE,[d.createElementVNode("path",{d:s.value,fill:c.value},null,8,xE)])),u.value?(d.openBlock(),d.createElementBlock("svg",_E,[d.createElementVNode("path",{d:i.value,stroke:"var(--wov-highlighted-block-outline-color)",style:{"stroke-width":"calc(1px / var(--wov-zoom))"},fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},null,8,EE)])):d.createCommentVNode("",!0)],8,SE)}}}),[["__scopeId","data-v-9b41c649"]]);function Ee(){const t=d.inject(pt);if(!t)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>t.getEditor(),nextEditorTick(e){return new Promise(n=>{const r=t.getEditor();r&&r.nextTick(o=>{e==null||e(o),n(o)})})}}}const ss={rectangle:"M0,0 L100,0 L100,100 L0,100 Z",ellipse:"M50,0 A50,50 0 1,1 50,100 A50,50 0 1,1 50,0",triangle:"M50,0 L100,100 L0,100 Z",diamond:"M50,0 L100,50 L50,100 L0,50 Z",pentagon:"M50,0 L100,38.2 L80.9,100 L19.1,100 L0,38.2 Z",hexagon:"M50,0 L100,25 L100,75 L50,100 L0,75 L0,25 Z",star:"M50,0 L61.8,38.2 L100,38.2 L69.1,61.8 L80.9,100 L50,76.4 L19.1,100 L30.9,61.8 L0,38.2 L38.2,38.2 Z",heart:"M50,16 C44,7 37,0 26,0 11,0 0,12 0,28 0,60 16,65 50,100 84,65 100,60 100,28 100,12 89,0 74,0 63,0 56,7 50,16 Z",arrow:"M0,35 L60,35 L60,0 L100,50 L60,100 L60,65 L0,65 Z"};function Fe(t){this.content=t}Fe.prototype={constructor:Fe,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,o=r.find(t),s=r.content.slice();return o==-1?s.push(n||t,e):(s[o+1]=e,n&&(s[o]=n)),new Fe(s)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Fe(n)},addToStart:function(t,e){return new Fe([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Fe(n)},addBefore:function(t,e,n){var r=this.remove(e),o=r.content.slice(),s=r.find(t);return o.splice(s==-1?o.length:s,0,e,n),new Fe(o)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Fe.from(t),t.size?new Fe(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Fe.from(t),t.size?new Fe(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Fe.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}},Fe.from=function(t){if(t instanceof Fe)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Fe(e)};function Kp(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let o=t.child(r),s=e.child(r);if(o==s){n+=o.nodeSize;continue}if(!o.sameMarkup(s))return n;if(o.isText&&o.text!=s.text){for(let i=0;o.text[i]==s.text[i];i++)n++;return n}if(o.content.size||s.content.size){let i=Kp(o.content,s.content,n+1);if(i!=null)return i}n+=o.nodeSize}}function Jp(t,e,n,r){for(let o=t.childCount,s=e.childCount;;){if(o==0||s==0)return o==s?null:{a:n,b:r};let i=t.child(--o),a=e.child(--s),l=i.nodeSize;if(i==a){n-=l,r-=l;continue}if(!i.sameMarkup(a))return{a:n,b:r};if(i.isText&&i.text!=a.text){let c=0,u=Math.min(i.text.length,a.text.length);for(;c<u&&i.text[i.text.length-c-1]==a.text[a.text.length-c-1];)c++,n--,r--;return{a:n,b:r}}if(i.content.size||a.content.size){let c=Jp(i.content,a.content,n-1,r-1);if(c)return c}n-=l,r-=l}}class B{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,o=0,s){for(let i=0,a=0;a<n;i++){let l=this.content[i],c=a+l.nodeSize;if(c>e&&r(l,o+a,s||null,i)!==!1&&l.content.size){let u=a+1;l.nodesBetween(Math.max(0,e-u),Math.min(l.content.size,n-u),r,o+u)}a=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,o){let s="",i=!0;return this.nodesBetween(e,n,(a,l)=>{let c=a.isText?a.text.slice(Math.max(e,l)-l,n-l):a.isLeaf?o?typeof o=="function"?o(a):o:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&c||a.isTextblock)&&r&&(i?i=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,o=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(o[o.length-1]=n.withText(n.text+r.text),s=1);s<e.content.length;s++)o.push(e.content[s]);return new B(o,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],o=0;if(n>e)for(let s=0,i=0;i<n;s++){let a=this.content[s],l=i+a.nodeSize;l>e&&((i<e||l>n)&&(a.isText?a=a.cut(Math.max(0,e-i),Math.min(a.text.length,n-i)):a=a.cut(Math.max(0,e-i-1),Math.min(a.content.size,n-i-1))),r.push(a),o+=a.nodeSize),i=l}return new B(r,o)}cutByIndex(e,n){return e==n?B.empty:e==0&&n==this.content.length?this:new B(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let o=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return o[e]=n,new B(o,s)}addToStart(e){return new B([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new B(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let o=this.content[n];e(o,r,n),r+=o.nodeSize}}findDiffStart(e,n=0){return Kp(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return Jp(this,e,n,r)}findIndex(e){if(e==0)return Bi(0,e);if(e==this.size)return Bi(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let o=this.child(n),s=r+o.nodeSize;if(s>=e)return s==e?Bi(n+1,s):Bi(n,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return B.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new B(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return B.empty;let n,r=0;for(let o=0;o<e.length;o++){let s=e[o];r+=s.nodeSize,o&&s.isText&&e[o-1].sameMarkup(s)?(n||(n=e.slice(0,o)),n[n.length-1]=s.withText(n[n.length-1].text+s.text)):n&&n.push(s)}return new B(n||e,r)}static from(e){if(!e)return B.empty;if(e instanceof B)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new B([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}B.empty=new B([],0);const pc={index:0,offset:0};function Bi(t,e){return pc.index=t,pc.offset=e,pc}function Oi(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!Oi(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!Oi(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}let ye=class cu{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let o=0;o<e.length;o++){let s=e[o];if(this.eq(s))return e;if(this.type.excludes(s.type))n||(n=e.slice(0,o));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(n||(n=e.slice(0,o)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Oi(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);let o=r.create(n.attrs);return r.checkAttrs(o.attrs),o}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return cu.none;if(e instanceof cu)return[e];let n=e.slice();return n.sort((r,o)=>r.type.rank-o.type.rank),n}};ye.none=[];class Ii extends Error{}class L{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=Gp(this.content,e+this.openStart,n);return r&&new L(r,this.openStart,this.openEnd)}removeBetween(e,n){return new L(qp(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return L.empty;let r=n.openStart||0,o=n.openEnd||0;if(typeof r!="number"||typeof o!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new L(B.fromJSON(e,n.content),r,o)}static maxOpen(e,n=!0){let r=0,o=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)o++;return new L(e,r,o)}}L.empty=new L(B.empty,0,0);function qp(t,e,n){let{index:r,offset:o}=t.findIndex(e),s=t.maybeChild(r),{index:i,offset:a}=t.findIndex(n);if(o==e||s.isText){if(a!=n&&!t.child(i).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=i)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(qp(s.content,e-o-1,n-o-1)))}function Gp(t,e,n,r){let{index:o,offset:s}=t.findIndex(e),i=t.maybeChild(o);if(s==e||i.isText)return r&&!r.canReplace(o,o,n)?null:t.cut(0,e).append(n).append(t.cut(e));let a=Gp(i.content,e-s-1,n,i);return a&&t.replaceChild(o,i.copy(a))}function TE(t,e,n){if(n.openStart>t.depth)throw new Ii("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Ii("Inconsistent open depths");return Yp(t,e,n,0)}function Yp(t,e,n,r){let o=t.index(r),s=t.node(r);if(o==e.index(r)&&r<t.depth-n.openStart){let i=Yp(t,e,n,r+1);return s.copy(s.content.replaceChild(o,i))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==r&&e.depth==r){let i=t.parent,a=i.content;return pr(i,a.cut(0,t.parentOffset).append(n.content).append(a.cut(e.parentOffset)))}else{let{start:i,end:a}=ME(n,t);return pr(s,Qp(t,i,a,e,r))}else return pr(s,Pi(t,e,r))}function Xp(t,e){if(!e.type.compatibleContent(t.type))throw new Ii("Cannot join "+e.type.name+" onto "+t.type.name)}function mc(t,e,n){let r=t.node(n);return Xp(r,e.node(n)),r}function hr(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function is(t,e,n,r){let o=(e||t).node(n),s=0,i=e?e.index(n):o.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(hr(t.nodeAfter,r),s++));for(let a=s;a<i;a++)hr(o.child(a),r);e&&e.depth==n&&e.textOffset&&hr(e.nodeBefore,r)}function pr(t,e){return t.type.checkContent(e),t.copy(e)}function Qp(t,e,n,r,o){let s=t.depth>o&&mc(t,e,o+1),i=r.depth>o&&mc(n,r,o+1),a=[];return is(null,t,o,a),s&&i&&e.index(o)==n.index(o)?(Xp(s,i),hr(pr(s,Qp(t,e,n,r,o+1)),a)):(s&&hr(pr(s,Pi(t,e,o+1)),a),is(e,n,o,a),i&&hr(pr(i,Pi(n,r,o+1)),a)),is(r,null,o,a),new B(a)}function Pi(t,e,n){let r=[];if(is(null,t,n,r),t.depth>n){let o=mc(t,e,n+1);hr(pr(o,Pi(t,e,n+1)),r)}return is(e,null,n,r),new B(r)}function ME(t,e){let n=e.depth-t.openStart,o=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)o=e.node(s).copy(B.from(o));return{start:o.resolveNoCache(t.openStart+n),end:o.resolveNoCache(o.content.size-t.openEnd-n)}}class as{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],o=e.child(n);return r?e.child(n).cut(r):o}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],o=n==0?0:this.path[n*3-1]+1;for(let s=0;s<e;s++)o+=r.child(s).nodeSize;return o}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return ye.none;if(this.textOffset)return e.child(n).marks;let r=e.maybeChild(n-1),o=e.maybeChild(n);if(!r){let a=r;r=o,o=a}let s=r.marks;for(var i=0;i<s.length;i++)s[i].type.spec.inclusive===!1&&(!o||!s[i].isInSet(o.marks))&&(s=s[i--].removeFromSet(s));return s}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let r=n.marks,o=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!o||!r[s].isInSet(o.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new Ri(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],o=0,s=n;for(let i=e;;){let{index:a,offset:l}=i.content.findIndex(s),c=s-l;if(r.push(i,a,o+l),!c||(i=i.child(a),i.isText))break;s=c-1,o+=l+1}return new as(n,r,s)}static resolveCached(e,n){let r=em.get(e);if(r)for(let s=0;s<r.elts.length;s++){let i=r.elts[s];if(i.pos==n)return i}else em.set(e,r=new AE);let o=r.elts[r.i]=as.resolve(e,n);return r.i=(r.i+1)%NE,o}}class AE{constructor(){this.elts=[],this.i=0}}const NE=12,em=new WeakMap;class Ri{constructor(e,n,r){this.$from=e,this.$to=n,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const BE=Object.create(null);let an=class du{constructor(e,n,r,o=ye.none){this.type=e,this.attrs=n,this.marks=o,this.content=r||B.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,r,o=0){this.content.nodesBetween(e,n,r,o,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,r,o){return this.content.textBetween(e,n,r,o)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,r){return this.type==e&&Oi(this.attrs,n||e.defaultAttrs||BE)&&ye.sameSet(this.marks,r||ye.none)}copy(e=null){return e==this.content?this:new du(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new du(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,r=!1){if(e==n)return L.empty;let o=this.resolve(e),s=this.resolve(n),i=r?0:o.sharedDepth(n),a=o.start(i),c=o.node(i).content.cut(o.pos-a,s.pos-a);return new L(c,o.depth-i,s.depth-i)}replace(e,n,r){return TE(this.resolve(e),this.resolve(n),r)}nodeAt(e){for(let n=this;;){let{index:r,offset:o}=n.content.findIndex(e);if(n=n.maybeChild(r),!n)return null;if(o==e||n.isText)return n;e-=o+1}}childAfter(e){let{index:n,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(n),index:n,offset:r};let o=this.content.child(n-1);return{node:o,index:n-1,offset:r-o.nodeSize}}resolve(e){return as.resolveCached(this,e)}resolveNoCache(e){return as.resolve(this,e)}rangeHasMark(e,n,r){let o=!1;return n>e&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(o=!0),!o)),o}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),tm(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=B.empty,o=0,s=r.childCount){let i=this.contentMatchAt(e).matchFragment(r,o,s),a=i&&i.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let l=o;l<s;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,n,r,o){if(o&&!this.type.allowsMarks(o))return!1;let s=this.contentMatchAt(e).matchType(r),i=s&&s.matchFragment(this.content,n);return i?i.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=ye.none;for(let n=0;n<this.marks.length;n++){let r=this.marks[n];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!ye.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let o=B.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,o,r);return s.type.checkAttrs(s.attrs),s}};an.prototype.text=void 0;class Di extends an{constructor(e,n,r,o){if(super(e,n,null,o),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):tm(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Di(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Di(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function tm(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class mr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new OE(e,n);if(r.next==null)return mr.empty;let o=nm(r);r.next&&r.err("Unexpected trailing text");let s=VE($E(o));return LE(s,r),s}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,r=e.childCount){let o=this;for(let s=n;o&&s<r;s++)o=o.matchType(e.child(s).type);return o}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let r=0;r<e.next.length;r++)if(this.next[n].type==e.next[r].type)return!0;return!1}fillBefore(e,n=!1,r=0){let o=[this];function s(i,a){let l=i.matchFragment(e,r);if(l&&(!n||l.validEnd))return B.from(a.map(c=>c.createAndFill()));for(let c=0;c<i.next.length;c++){let{type:u,next:f}=i.next[c];if(!(u.isText||u.hasRequiredAttrs())&&o.indexOf(f)==-1){o.push(f);let p=s(f,a.concat(u));if(p)return p}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let o=r.shift(),s=o.match;if(s.matchType(e)){let i=[];for(let a=o;a.type;a=a.via)i.push(a.type);return i.reverse()}for(let i=0;i<s.next.length;i++){let{type:a,next:l}=s.next[i];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in n)&&(!o.type||l.validEnd)&&(r.push({match:a.contentMatch,type:a,via:o}),n[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let o=0;o<r.next.length;o++)e.indexOf(r.next[o].next)==-1&&n(r.next[o].next)}return n(this),e.map((r,o)=>{let s=o+(r.validEnd?"*":" ")+" ";for(let i=0;i<r.next.length;i++)s+=(i?", ":"")+r.next[i].type.name+"->"+e.indexOf(r.next[i].next);return s}).join(`
|
|
70
|
-
`)}}mr.empty=new mr(!0);class OE{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function nm(t){let e=[];do e.push(IE(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function IE(t){let e=[];do e.push(PE(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function PE(t){let e=zE(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=RE(t,e);else break;return e}function rm(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function RE(t,e){let n=rm(t),r=n;return t.eat(",")&&(t.next!="}"?r=rm(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function DE(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let o=[];for(let s in n){let i=n[s];i.isInGroup(e)&&o.push(i)}return o.length==0&&t.err("No node type or group '"+e+"' found"),o}function zE(t){if(t.eat("(")){let e=nm(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=DE(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function $E(t){let e=[[]];return o(s(t,0),n()),e;function n(){return e.push([])-1}function r(i,a,l){let c={term:l,to:a};return e[i].push(c),c}function o(i,a){i.forEach(l=>l.to=a)}function s(i,a){if(i.type=="choice")return i.exprs.reduce((l,c)=>l.concat(s(c,a)),[]);if(i.type=="seq")for(let l=0;;l++){let c=s(i.exprs[l],a);if(l==i.exprs.length-1)return c;o(c,a=n())}else if(i.type=="star"){let l=n();return r(a,l),o(s(i.expr,l),l),[r(l)]}else if(i.type=="plus"){let l=n();return o(s(i.expr,a),l),o(s(i.expr,l),l),[r(l)]}else{if(i.type=="opt")return[r(a)].concat(s(i.expr,a));if(i.type=="range"){let l=a;for(let c=0;c<i.min;c++){let u=n();o(s(i.expr,l),u),l=u}if(i.max==-1)o(s(i.expr,l),l);else for(let c=i.min;c<i.max;c++){let u=n();r(l,u),o(s(i.expr,l),u),l=u}return[r(l)]}else{if(i.type=="name")return[r(a,void 0,i.value)];throw new Error("Unknown expr type")}}}}function om(t,e){return e-t}function sm(t,e){let n=[];return r(e),n.sort(om);function r(o){let s=t[o];if(s.length==1&&!s[0].term)return r(s[0].to);n.push(o);for(let i=0;i<s.length;i++){let{term:a,to:l}=s[i];!a&&n.indexOf(l)==-1&&r(l)}}}function VE(t){let e=Object.create(null);return n(sm(t,0));function n(r){let o=[];r.forEach(i=>{t[i].forEach(({term:a,to:l})=>{if(!a)return;let c;for(let u=0;u<o.length;u++)o[u][0]==a&&(c=o[u][1]);sm(t,l).forEach(u=>{c||o.push([a,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[r.join(",")]=new mr(r.indexOf(t.length-1)>-1);for(let i=0;i<o.length;i++){let a=o[i][1].sort(om);s.next.push({type:o[i][0],next:e[a.join(",")]||n(a)})}return s}}function LE(t,e){for(let n=0,r=[t];n<r.length;n++){let o=r[n],s=!o.validEnd,i=[];for(let a=0;a<o.next.length;a++){let{type:l,next:c}=o.next[a];i.push(l.name),s&&!(l.isText||l.hasRequiredAttrs())&&(s=!1),r.indexOf(c)==-1&&r.push(c)}s&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function im(t){let e=Object.create(null);for(let n in t){let r=t[n];if(!r.hasDefault)return null;e[n]=r.default}return e}function am(t,e){let n=Object.create(null);for(let r in t){let o=e&&e[r];if(o===void 0){let s=t[r];if(s.hasDefault)o=s.default;else throw new RangeError("No value supplied for attribute "+r)}n[r]=o}return n}function lm(t,e,n,r){for(let o in e)if(!(o in t))throw new RangeError(`Unsupported attribute ${o} for ${n} of type ${o}`);for(let o in t){let s=t[o];s.validate&&s.validate(e[o])}}function cm(t,e){let n=Object.create(null);if(e)for(let r in e)n[r]=new jE(t,r,e[r]);return n}let dm=class Zk{constructor(e,n,r){this.name=e,this.schema=n,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=cm(e,r.attrs),this.defaultAttrs=im(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==mr.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:am(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new an(this,this.computeAttrs(e),B.from(n),ye.setFrom(r))}createChecked(e=null,n,r){return n=B.from(n),this.checkContent(n),new an(this,this.computeAttrs(e),n,ye.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=B.from(n),n.size){let i=this.contentMatch.fillBefore(n);if(!i)return null;n=i.append(n)}let o=this.contentMatch.matchFragment(n),s=o&&o.fillBefore(B.empty,!0);return s?new an(this,e,n.append(s),ye.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){lm(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?n&&n.push(e[r]):n||(n=e.slice(0,r));return n?n.length?n:ye.none:e}static compile(e,n){let r=Object.create(null);e.forEach((s,i)=>r[s]=new Zk(s,n,i));let o=n.spec.topNode||"doc";if(!r[o])throw new RangeError("Schema is missing its top node type ('"+o+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function FE(t,e,n){let r=n.split("|");return o=>{let s=o===null?"null":typeof o;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class jE{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?FE(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class zi{constructor(e,n,r,o){this.name=e,this.rank=n,this.schema=r,this.spec=o,this.attrs=cm(e,o.attrs),this.excluded=null;let s=im(this.attrs);this.instance=s?new ye(this,s):null}create(e=null){return!e&&this.instance?this.instance:new ye(this,am(this.attrs,e))}static compile(e,n){let r=Object.create(null),o=0;return e.forEach((s,i)=>r[s]=new zi(s,o++,n,i)),r}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){lm(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class um{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let o in e)n[o]=e[o];n.nodes=Fe.from(e.nodes),n.marks=Fe.from(e.marks||{}),this.nodes=dm.compile(this.spec.nodes,this),this.marks=zi.compile(this.spec.marks,this);let r=Object.create(null);for(let o in this.nodes){if(o in this.marks)throw new RangeError(o+" can not be both a node and a mark");let s=this.nodes[o],i=s.spec.content||"",a=s.spec.marks;if(s.contentMatch=r[i]||(r[i]=mr.parse(i,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=a=="_"?null:a?fm(this,a.split(" ")):a==""||!s.inlineContent?[]:null}for(let o in this.marks){let s=this.marks[o],i=s.spec.excludes;s.excluded=i==null?[s]:i==""?[]:fm(this,i.split(" "))}this.nodeFromJSON=o=>an.fromJSON(this,o),this.markFromJSON=o=>ye.fromJSON(this,o),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,o){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof dm){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,o)}text(e,n){let r=this.nodes.text;return new Di(r,r.defaultAttrs,e,ye.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function fm(t,e){let n=[];for(let r=0;r<e.length;r++){let o=e[r],s=t.marks[o],i=s;if(s)n.push(s);else for(let a in t.marks){let l=t.marks[a];(o=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(o)>-1)&&n.push(i=l)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function HE(t){return t.tag!=null}function WE(t){return t.style!=null}class ln{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(o=>{if(HE(o))this.tags.push(o);else if(WE(o)){let s=/[^=]*/.exec(o.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(o)}}),this.normalizeLists=!this.tags.some(o=>{if(!/^(ul|ol)\b/.test(o.tag)||!o.node)return!1;let s=e.nodes[o.node];return s.contentMatch.matchType(s)})}parse(e,n={}){let r=new gm(this,n,!1);return r.addAll(e,ye.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new gm(this,n,!0);return r.addAll(e,ye.none,n.from,n.to),L.maxOpen(r.finish())}matchTag(e,n,r){for(let o=r?this.tags.indexOf(r)+1:0;o<this.tags.length;o++){let s=this.tags[o];if(KE(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||n.matchesContext(s.context))){if(s.getAttrs){let i=s.getAttrs(e);if(i===!1)continue;s.attrs=i||void 0}return s}}}matchStyle(e,n,r,o){for(let s=o?this.styles.indexOf(o)+1:0;s<this.styles.length;s++){let i=this.styles[s],a=i.style;if(!(a.indexOf(e)!=0||i.context&&!r.matchesContext(i.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(i.getAttrs){let l=i.getAttrs(n);if(l===!1)continue;i.attrs=l||void 0}return i}}}static schemaRules(e){let n=[];function r(o){let s=o.priority==null?50:o.priority,i=0;for(;i<n.length;i++){let a=n[i];if((a.priority==null?50:a.priority)<s)break}n.splice(i,0,o)}for(let o in e.marks){let s=e.marks[o].spec.parseDOM;s&&s.forEach(i=>{r(i=ym(i)),i.mark||i.ignore||i.clearMark||(i.mark=o)})}for(let o in e.nodes){let s=e.nodes[o].spec.parseDOM;s&&s.forEach(i=>{r(i=ym(i)),i.node||i.ignore||i.mark||(i.node=o)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new ln(e,ln.schemaRules(e)))}}const hm={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},ZE={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},pm={ol:!0,ul:!0},ls=1,gc=2,cs=4;function mm(t,e,n){return e!=null?(e?ls:0)|(e==="full"?gc:0):t&&t.whitespace=="pre"?ls|gc:n&~cs}class $i{constructor(e,n,r,o,s,i){this.type=e,this.attrs=n,this.marks=r,this.solid=o,this.options=i,this.content=[],this.activeMarks=ye.none,this.match=s||(i&cs?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(B.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,o;return(o=r.findWrapping(e.type))?(this.match=r,o):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&ls)){let r=this.content[this.content.length-1],o;if(r&&r.isText&&(o=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==o[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-o[0].length))}}let n=B.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(B.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!hm.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class gm{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let o=n.topNode,s,i=mm(null,n.preserveWhitespace,0)|(r?cs:0);o?s=new $i(o.type,o.attrs,ye.none,!0,n.topMatch||o.type.contentMatch,i):r?s=new $i(null,null,ye.none,!0,null,i):s=new $i(e.schema.topNodeType,null,ye.none,!0,null,i),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,o=this.top,s=o.options&gc?"full":this.localPreserveWS||(o.options&ls)>0,{schema:i}=this.parser;if(s==="full"||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,`
|
|
71
|
-
`);else if(i.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(i.linebreakReplacement.create())){let a=r.split(/\r?\n|\r/);for(let l=0;l<a.length;l++)l&&this.insertNode(i.linebreakReplacement.create(),n,!0),a[l]&&this.insertNode(i.text(a[l]),n,!/\S/.test(a[l]));r=""}else r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let a=o.content[o.content.length-1],l=e.previousSibling;(!a||l&&l.nodeName=="BR"||a.isText&&/[ \t\r\n\u000c]$/.test(a.text))&&(r=r.slice(1))}r&&this.insertNode(i.text(r),n,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,n,r){let o=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i=e.nodeName.toLowerCase(),a;pm.hasOwnProperty(i)&&this.parser.normalizeLists&&UE(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,r));e:if(l?l.ignore:ZE.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,n);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let c,u=this.needsBlock;if(hm.hasOwnProperty(i))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let f=l&&l.skip?n:this.readStyles(e,n);f&&this.addAll(e,f),c&&this.sync(s),this.needsBlock=u}else{let c=this.readStyles(e,n);c&&this.addElementByRule(e,l,c,l.consuming===!1?a:void 0)}this.localPreserveWS=o}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
72
|
-
`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let o=0;o<this.parser.matchedStyles.length;o++){let s=this.parser.matchedStyles[o],i=r.getPropertyValue(s);if(i)for(let a=void 0;;){let l=this.parser.matchStyle(s,i,this,a);if(!l)break;if(l.ignore)return null;if(l.clearMark?n=n.filter(c=>!l.clearMark(c)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)a=l;else break}}return n}addElementByRule(e,n,r,o){let s,i;if(n.node)if(i=this.parser.schema.nodes[n.node],i.isLeaf)this.insertNode(i.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(i,n.attrs||null,r,n.preserveWhitespace);l&&(s=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let a=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,r,o);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}s&&this.sync(a)&&this.open--}addAll(e,n,r,o){let s=r||0;for(let i=r?e.childNodes[r]:e.firstChild,a=o==null?null:e.childNodes[o];i!=a;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,n);this.findAtPoint(e,s)}findPlace(e,n,r){let o,s;for(let i=this.open,a=0;i>=0;i--){let l=this.nodes[i],c=l.findWrapping(e);if(c&&(!o||o.length>c.length+a)&&(o=c,s=l,!c.length))break;if(l.solid){if(r)break;a+=2}}if(!o)return null;this.sync(s);for(let i=0;i<o.length;i++)n=this.enterInner(o[i],null,n,!1);return n}insertNode(e,n,r){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(n=this.enterInner(s,null,n))}let o=this.findPlace(e,n,r);if(o){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let i=ye.none;for(let a of o.concat(e.marks))(s.type?s.type.allowsMarkType(a.type):km(a.type,e.type))&&(i=a.addToSet(i));return s.content.push(e.mark(i)),!0}return!1}enter(e,n,r,o){let s=this.findPlace(e.create(n),r,!1);return s&&(s=this.enterInner(e,n,r,!0,o)),s}enterInner(e,n,r,o=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let a=mm(e,s,i.options);i.options&cs&&i.content.length==0&&(a|=cs);let l=ye.none;return r=r.filter(c=>(i.type?i.type.allowsMarkType(c.type):km(c.type,e))?(l=c.addToSet(l),!1):!0),this.nodes.push(new $i(e,n,l,o,null,a)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=ls)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let o=r.length-1;o>=0;o--)e+=r[o].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let o=0;o<this.find.length;o++)this.find[o].pos==null&&e.nodeType==1&&e.contains(this.find[o].node)&&n.compareDocumentPosition(this.find[o].node)&(r?2:4)&&(this.find[o].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,o=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(o?0:1),i=(a,l)=>{for(;a>=0;a--){let c=n[a];if(c==""){if(a==n.length-1||a==0)continue;for(;l>=s;l--)if(i(a-1,l))return!0;return!1}else{let u=l>0||l==0&&o?this.nodes[l].type:r&&l>=s?r.node(l-s).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;l--}}return!0};return i(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function UE(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&pm.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function KE(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function ym(t){let e={};for(let n in t)e[n]=t[n];return e}function km(t,e){let n=e.schema.nodes;for(let r in n){let o=n[r];if(!o.allowsMarkType(t))continue;let s=[],i=a=>{s.push(a);for(let l=0;l<a.edgeCount;l++){let{type:c,next:u}=a.edge(l);if(c==e||s.indexOf(u)<0&&i(u))return!0}};if(i(o.contentMatch))return!0}}class gr{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},r){r||(r=yc(n).createDocumentFragment());let o=r,s=[];return e.forEach(i=>{if(s.length||i.marks.length){let a=0,l=0;for(;a<s.length&&l<i.marks.length;){let c=i.marks[l];if(!this.marks[c.type.name]){l++;continue}if(!c.eq(s[a][0])||c.type.spec.spanning===!1)break;a++,l++}for(;a<s.length;)o=s.pop()[1];for(;l<i.marks.length;){let c=i.marks[l++],u=this.serializeMark(c,i.isInline,n);u&&(s.push([c,o]),o.appendChild(u.dom),o=u.contentDOM||u.dom)}}o.appendChild(this.serializeNodeInner(i,n))}),r}serializeNodeInner(e,n){let{dom:r,contentDOM:o}=Vi(yc(n),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,o)}return r}serializeNode(e,n={}){let r=this.serializeNodeInner(e,n);for(let o=e.marks.length-1;o>=0;o--){let s=this.serializeMark(e.marks[o],e.isInline,n);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,n,r={}){let o=this.marks[e.type.name];return o&&Vi(yc(r),o(e,n),null,e.attrs)}static renderSpec(e,n,r=null,o){return Vi(e,n,r,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new gr(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=wm(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return wm(e.marks)}}function wm(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function yc(t){return t.document||window.document}const vm=new WeakMap;function JE(t){let e=vm.get(t);return e===void 0&&vm.set(t,e=qE(t)),e}function qE(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let o=0;o<r.length;o++)n(r[o]);else for(let o in r)n(r[o])}return n(t),e}function Vi(t,e,n,r){if(typeof e=="string")return{dom:t.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let o=e[0],s;if(typeof o!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=JE(r))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let i=o.indexOf(" ");i>0&&(n=o.slice(0,i),o=o.slice(i+1));let a,l=n?t.createElementNS(n,o):t.createElement(o),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let p=f.indexOf(" ");p>0?l.setAttributeNS(f.slice(0,p),f.slice(p+1),c[f]):f=="style"&&l.style?l.style.cssText=c[f]:l.setAttribute(f,c[f])}}for(let f=u;f<e.length;f++){let p=e[f];if(p===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:m,contentDOM:g}=Vi(t,p,n,r);if(l.appendChild(m),g){if(a)throw new RangeError("Multiple content holes");a=g}}}return{dom:l,contentDOM:a}}const bm=65535,Sm=Math.pow(2,16);function GE(t,e){return t+e*Sm}function Cm(t){return t&bm}function YE(t){return(t-(t&bm))/Sm}const xm=1,_m=2,Li=4,Em=8;class kc{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Em)>0}get deletedBefore(){return(this.delInfo&(xm|Li))>0}get deletedAfter(){return(this.delInfo&(_m|Li))>0}get deletedAcross(){return(this.delInfo&Li)>0}}class ct{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ct.empty)return ct.empty}recover(e){let n=0,r=Cm(e);if(!this.inverted)for(let o=0;o<r;o++)n+=this.ranges[o*3+2]-this.ranges[o*3+1];return this.ranges[r*3]+n+YE(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let o=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?o:0);if(l>e)break;let c=this.ranges[a+s],u=this.ranges[a+i],f=l+c;if(e<=f){let p=c?e==l?-1:e==f?1:n:n,m=l+o+(p<0?0:u);if(r)return m;let g=e==(n<0?l:f)?null:GE(a/3,e-l),y=e==l?_m:e==f?xm:Li;return(n<0?e!=l:e!=f)&&(y|=Em),new kc(m,y,g)}o+=u-c}return r?e+o:new kc(e+o,0,null)}touches(e,n){let r=0,o=Cm(n),s=this.inverted?2:1,i=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let l=this.ranges[a]-(this.inverted?r:0);if(l>e)break;let c=this.ranges[a+s],u=l+c;if(e<=u&&a==o*3)return!0;r+=this.ranges[a+i]-c}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let o=0,s=0;o<this.ranges.length;o+=3){let i=this.ranges[o],a=i-(this.inverted?s:0),l=i+(this.inverted?0:s),c=this.ranges[o+n],u=this.ranges[o+r];e(a,a+c,l,l+u),s+=u-c}}invert(){return new ct(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?ct.empty:new ct(e<0?[0,-e,0]:[0,0,e])}}ct.empty=new ct([]);class ds{constructor(e,n,r=0,o=e?e.length:0){this.mirror=n,this.from=r,this.to=o,this._maps=e||[],this.ownData=!(e||n)}get maps(){return this._maps}slice(e=0,n=this.maps.length){return new ds(this._maps,this.mirror,e,n)}appendMap(e,n){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),n!=null&&this.setMirror(this._maps.length-1,n)}appendMapping(e){for(let n=0,r=this._maps.length;n<e._maps.length;n++){let o=e.getMirror(n);this.appendMap(e._maps[n],o!=null&&o<n?r+o:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,r=this._maps.length+e._maps.length;n>=0;n--){let o=e.getMirror(n);this.appendMap(e._maps[n].invert(),o!=null&&o>n?r-o-1:void 0)}}invert(){let e=new ds;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,r){let o=0;for(let s=this.from;s<this.to;s++){let i=this._maps[s],a=i.mapResult(e,n);if(a.recover!=null){let l=this.getMirror(s);if(l!=null&&l>s&&l<this.to){s=l,e=this._maps[l].recover(a.recover);continue}}o|=a.delInfo,e=a.pos}return r?e:new kc(e,o,null)}}const wc=Object.create(null);class Ke{getMap(){return ct.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=wc[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in wc)throw new RangeError("Duplicate use of step JSON ID "+e);return wc[e]=n,n.prototype.jsonID=e,n}}class Te{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new Te(e,null)}static fail(e){return new Te(null,e)}static fromReplace(e,n,r,o){try{return Te.ok(e.replace(n,r,o))}catch(s){if(s instanceof Ii)return Te.fail(s.message);throw s}}}function vc(t,e,n){let r=[];for(let o=0;o<t.childCount;o++){let s=t.child(o);s.content.size&&(s=s.copy(vc(s.content,e,s))),s.isInline&&(s=e(s,n,o)),r.push(s)}return B.fromArray(r)}class Bn extends Ke{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),o=r.node(r.sharedDepth(this.to)),s=new L(vc(n.content,(i,a)=>!i.isAtom||!a.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),o),n.openStart,n.openEnd);return Te.fromReplace(e,this.from,this.to,s)}invert(){return new Bt(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Bn(n.pos,r.pos,this.mark)}merge(e){return e instanceof Bn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Bn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Bn(n.from,n.to,e.markFromJSON(n.mark))}}Ke.jsonID("addMark",Bn);class Bt extends Ke{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new L(vc(n.content,o=>o.mark(this.mark.removeFromSet(o.marks)),e),n.openStart,n.openEnd);return Te.fromReplace(e,this.from,this.to,r)}invert(){return new Bn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Bt(n.pos,r.pos,this.mark)}merge(e){return e instanceof Bt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Bt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Bt(n.from,n.to,e.markFromJSON(n.mark))}}Ke.jsonID("removeMark",Bt);class On extends Ke{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Te.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Te.fromReplace(e,this.pos,this.pos+1,new L(B.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let o=0;o<n.marks.length;o++)if(!n.marks[o].isInSet(r))return new On(this.pos,n.marks[o]);return new On(this.pos,this.mark)}}return new yr(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new On(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new On(n.pos,e.markFromJSON(n.mark))}}Ke.jsonID("addNodeMark",On);class yr extends Ke{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Te.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return Te.fromReplace(e,this.pos,this.pos+1,new L(B.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new On(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new yr(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new yr(n.pos,e.markFromJSON(n.mark))}}Ke.jsonID("removeNodeMark",yr);class Re extends Ke{constructor(e,n,r,o=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=o}apply(e){return this.structure&&bc(e,this.from,this.to)?Te.fail("Structure replace would overwrite content"):Te.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ct([this.from,this.to-this.from,this.slice.size])}invert(e){return new Re(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new Re(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Re)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?L.empty:new L(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Re(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?L.empty:new L(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Re(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Re(n.from,n.to,L.fromJSON(e,n.slice),!!n.structure)}}Ke.jsonID("replace",Re);class De extends Ke{constructor(e,n,r,o,s,i,a=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=o,this.slice=s,this.insert=i,this.structure=a}apply(e){if(this.structure&&(bc(e,this.from,this.gapFrom)||bc(e,this.gapTo,this.to)))return Te.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return Te.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?Te.fromReplace(e,this.from,this.to,r):Te.fail("Content does not fit in gap")}getMap(){return new ct([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new De(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),o=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||o<n.pos||s>r.pos?null:new De(n.pos,r.pos,o,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new De(n.from,n.to,n.gapFrom,n.gapTo,L.fromJSON(e,n.slice),n.insert,!!n.structure)}}Ke.jsonID("replaceAround",De);function bc(t,e,n){let r=t.resolve(e),o=n-e,s=r.depth;for(;o>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,o--;if(o>0){let i=r.node(s).maybeChild(r.indexAfter(s));for(;o>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,o--}}return!1}function XE(t,e,n,r){let o=[],s=[],i,a;t.doc.nodesBetween(e,n,(l,c,u)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let p=Math.max(c,e),m=Math.min(c+l.nodeSize,n),g=r.addToSet(f);for(let y=0;y<f.length;y++)f[y].isInSet(g)||(i&&i.to==p&&i.mark.eq(f[y])?i.to=m:o.push(i=new Bt(p,m,f[y])));a&&a.to==p?a.to=m:s.push(a=new Bn(p,m,r))}}),o.forEach(l=>t.step(l)),s.forEach(l=>t.step(l))}function QE(t,e,n,r){let o=[],s=0;t.doc.nodesBetween(e,n,(i,a)=>{if(!i.isInline)return;s++;let l=null;if(r instanceof zi){let c=i.marks,u;for(;u=r.isInSet(c);)(l||(l=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(i.marks)&&(l=[r]):l=i.marks;if(l&&l.length){let c=Math.min(a+i.nodeSize,n);for(let u=0;u<l.length;u++){let f=l[u],p;for(let m=0;m<o.length;m++){let g=o[m];g.step==s-1&&f.eq(o[m].style)&&(p=g)}p?(p.to=c,p.step=s):o.push({style:f,from:Math.max(a,e),to:c,step:s})}}}),o.forEach(i=>t.step(new Bt(i.from,i.to,i.style)))}function Sc(t,e,n,r=n.contentMatch,o=!0){let s=t.doc.nodeAt(e),i=[],a=e+1;for(let l=0;l<s.childCount;l++){let c=s.child(l),u=a+c.nodeSize,f=r.matchType(c.type);if(!f)i.push(new Re(a,u,L.empty));else{r=f;for(let p=0;p<c.marks.length;p++)n.allowsMarkType(c.marks[p].type)||t.step(new Bt(a,u,c.marks[p]));if(o&&c.isText&&n.whitespace!="pre"){let p,m=/\r?\n|\r/g,g;for(;p=m.exec(c.text);)g||(g=new L(B.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),i.push(new Re(a+p.index,a+p.index+p[0].length,g))}}a=u}if(!r.validEnd){let l=r.fillBefore(B.empty,!0);t.replace(a,a,new L(l,0,0))}for(let l=i.length-1;l>=0;l--)t.step(i[l])}function eT(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function io(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,o=0,s=0;;--r){let i=t.$from.node(r),a=t.$from.index(r)+o,l=t.$to.indexAfter(r)-s;if(r<t.depth&&i.canReplace(a,l,n))return r;if(r==0||i.type.spec.isolating||!eT(i,a,l))break;a&&(o=1),l<i.childCount&&(s=1)}return null}function tT(t,e,n){let{$from:r,$to:o,depth:s}=e,i=r.before(s+1),a=o.after(s+1),l=i,c=a,u=B.empty,f=0;for(let g=s,y=!1;g>n;g--)y||r.index(g)>0?(y=!0,u=B.from(r.node(g).copy(u)),f++):l--;let p=B.empty,m=0;for(let g=s,y=!1;g>n;g--)y||o.after(g+1)<o.end(g)?(y=!0,p=B.from(o.node(g).copy(p)),m++):c++;t.step(new De(l,c,i,a,new L(u.append(p),f,m),u.size-f,!0))}function Tm(t,e,n=null,r=t){let o=nT(t,e),s=o&&rT(r,e);return s?o.map(Mm).concat({type:e,attrs:n}).concat(s.map(Mm)):null}function Mm(t){return{type:t,attrs:null}}function nT(t,e){let{parent:n,startIndex:r,endIndex:o}=t,s=n.contentMatchAt(r).findWrapping(e);if(!s)return null;let i=s.length?s[0]:e;return n.canReplaceWith(r,o,i)?s:null}function rT(t,e){let{parent:n,startIndex:r,endIndex:o}=t,s=n.child(r),i=e.contentMatch.findWrapping(s.type);if(!i)return null;let l=(i.length?i[i.length-1]:e).contentMatch;for(let c=r;l&&c<o;c++)l=l.matchType(n.child(c).type);return!l||!l.validEnd?null:i}function oT(t,e,n){let r=B.empty;for(let i=n.length-1;i>=0;i--){if(r.size){let a=n[i].type.contentMatch.matchFragment(r);if(!a||!a.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=B.from(n[i].type.create(n[i].attrs,r))}let o=e.start,s=e.end;t.step(new De(o,s,o,s,new L(r,0,0),n.length,!0))}function sT(t,e,n,r,o){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=t.steps.length;t.doc.nodesBetween(e,n,(i,a)=>{let l=typeof o=="function"?o(i):o;if(i.isTextblock&&!i.hasMarkup(r,l)&&iT(t.doc,t.mapping.slice(s).map(a),r)){let c=null;if(r.schema.linebreakReplacement){let m=r.whitespace=="pre",g=!!r.contentMatch.matchType(r.schema.linebreakReplacement);m&&!g?c=!1:!m&&g&&(c=!0)}c===!1&&Nm(t,i,a,s),Sc(t,t.mapping.slice(s).map(a,1),r,void 0,c===null);let u=t.mapping.slice(s),f=u.map(a,1),p=u.map(a+i.nodeSize,1);return t.step(new De(f,p,f+1,p-1,new L(B.from(r.create(l,null,i.marks)),0,0),1,!0)),c===!0&&Am(t,i,a,s),!1}})}function Am(t,e,n,r){e.forEach((o,s)=>{if(o.isText){let i,a=/\r?\n|\r/g;for(;i=a.exec(o.text);){let l=t.mapping.slice(r).map(n+1+s+i.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function Nm(t,e,n,r){e.forEach((o,s)=>{if(o.type==o.type.schema.linebreakReplacement){let i=t.mapping.slice(r).map(n+1+s);t.replaceWith(i,i+1,e.type.schema.text(`
|
|
73
|
-
`))}})}function iT(t,e,n){let r=t.resolve(e),o=r.index();return r.parent.canReplaceWith(o,o+1,n)}function aT(t,e,n,r,o){let s=t.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let i=n.create(r,null,o||s.marks);if(s.isLeaf)return t.replaceWith(e,e+s.nodeSize,i);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new De(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new L(B.from(i),0,0),1,!0))}function cn(t,e,n=1,r){let o=t.resolve(e),s=o.depth-n,i=r&&r[r.length-1]||o.parent;if(s<0||o.parent.type.spec.isolating||!o.parent.canReplace(o.index(),o.parent.childCount)||!i.type.validContent(o.parent.content.cutByIndex(o.index(),o.parent.childCount)))return!1;for(let c=o.depth-1,u=n-2;c>s;c--,u--){let f=o.node(c),p=o.index(c);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(p,f.childCount),g=r&&r[u+1];g&&(m=m.replaceChild(0,g.type.create(g.attrs)));let y=r&&r[u]||f;if(!f.canReplace(p+1,f.childCount)||!y.type.validContent(m))return!1}let a=o.indexAfter(s),l=r&&r[0];return o.node(s).canReplaceWith(a,a,l?l.type:o.node(s+1).type)}function lT(t,e,n=1,r){let o=t.doc.resolve(e),s=B.empty,i=B.empty;for(let a=o.depth,l=o.depth-n,c=n-1;a>l;a--,c--){s=B.from(o.node(a).copy(s));let u=r&&r[c];i=B.from(u?u.type.create(u.attrs,i):o.node(a).copy(i))}t.step(new Re(e,e,new L(s.append(i),n,n),!0))}function kr(t,e){let n=t.resolve(e),r=n.index();return Bm(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function cT(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let o=0;o<e.childCount;o++){let s=e.child(o),i=s.type==r?t.type.schema.nodes.text:s.type;if(n=n.matchType(i),!n||!t.type.allowsMarks(s.marks))return!1}return n.validEnd}function Bm(t,e){return!!(t&&e&&!t.isLeaf&&cT(t,e))}function Fi(t,e,n=-1){let r=t.resolve(e);for(let o=r.depth;;o--){let s,i,a=r.index(o);if(o==r.depth?(s=r.nodeBefore,i=r.nodeAfter):n>0?(s=r.node(o+1),a++,i=r.node(o).maybeChild(a)):(s=r.node(o).maybeChild(a-1),i=r.node(o+1)),s&&!s.isTextblock&&Bm(s,i)&&r.node(o).canReplace(a,a+1))return e;if(o==0)break;e=n<0?r.before(o):r.after(o)}}function dT(t,e,n){let r=null,{linebreakReplacement:o}=t.doc.type.schema,s=t.doc.resolve(e-n),i=s.node().type;if(o&&i.inlineContent){let u=i.whitespace=="pre",f=!!i.contentMatch.matchType(o);u&&!f?r=!1:!u&&f&&(r=!0)}let a=t.steps.length;if(r===!1){let u=t.doc.resolve(e+n);Nm(t,u.node(),u.before(),a)}i.inlineContent&&Sc(t,e+n-1,i,s.node().contentMatchAt(s.index()),r==null);let l=t.mapping.slice(a),c=l.map(e-n);if(t.step(new Re(c,l.map(e+n,-1),L.empty,!0)),r===!0){let u=t.doc.resolve(c);Am(t,u.node(),u.before(),t.steps.length)}return t}function uT(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let o=r.depth-1;o>=0;o--){let s=r.index(o);if(r.node(o).canReplaceWith(s,s,n))return r.before(o+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let o=r.depth-1;o>=0;o--){let s=r.indexAfter(o);if(r.node(o).canReplaceWith(s,s,n))return r.after(o+1);if(s<r.node(o).childCount)return null}return null}function Om(t,e,n){let r=t.resolve(e);if(!n.content.size)return e;let o=n.content;for(let s=0;s<n.openStart;s++)o=o.firstChild.content;for(let s=1;s<=(n.openStart==0&&n.size?2:1);s++)for(let i=r.depth;i>=0;i--){let a=i==r.depth?0:r.pos<=(r.start(i+1)+r.end(i+1))/2?-1:1,l=r.index(i)+(a>0?1:0),c=r.node(i),u=!1;if(s==1)u=c.canReplace(l,l,o);else{let f=c.contentMatchAt(l).findWrapping(o.firstChild.type);u=f&&c.canReplaceWith(l,l,f[0])}if(u)return a==0?r.pos:a<0?r.before(i+1):r.after(i+1)}return null}function ji(t,e,n=e,r=L.empty){if(e==n&&!r.size)return null;let o=t.resolve(e),s=t.resolve(n);return Im(o,s,r)?new Re(e,n,r):new fT(o,s,r).fit()}function Im(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class fT{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=B.empty;for(let o=0;o<=e.depth;o++){let s=e.node(o);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(o))})}for(let o=e.depth;o>0;o--)this.placed=B.from(e.node(o).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,o=this.close(e<0?this.$to:r.doc.resolve(e));if(!o)return null;let s=this.placed,i=r.depth,a=o.depth;for(;i&&a&&s.childCount==1;)s=s.firstChild.content,i--,a--;let l=new L(s,i,a);return e>-1?new De(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new Re(r.pos,o.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,o=this.unplaced.openEnd;r<e;r++){let s=n.firstChild;if(n.childCount>1&&(o=0),s.type.spec.isolating&&o<=r){e=r;break}n=s.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let o,s=null;r?(s=Cc(this.unplaced.content,r-1).firstChild,o=s.content):o=this.unplaced.content;let i=o.firstChild;for(let a=this.depth;a>=0;a--){let{type:l,match:c}=this.frontier[a],u,f=null;if(n==1&&(i?c.matchType(i.type)||(f=c.fillBefore(B.from(i),!1)):s&&l.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:a,parent:s,inject:f};if(n==2&&i&&(u=c.findWrapping(i.type)))return{sliceDepth:r,frontierDepth:a,parent:s,wrap:u};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,o=Cc(e,n);return!o.childCount||o.firstChild.isLeaf?!1:(this.unplaced=new L(e,n+1,Math.max(r,o.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,o=Cc(e,n);if(o.childCount<=1&&n>0){let s=e.size-n<=n+o.size;this.unplaced=new L(us(e,n-1,1),n-1,s?n-1:r)}else this.unplaced=new L(us(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:o,wrap:s}){for(;this.depth>n;)this.closeFrontierNode();if(s)for(let y=0;y<s.length;y++)this.openFrontierNode(s[y]);let i=this.unplaced,a=r?r.content:i.content,l=i.openStart-e,c=0,u=[],{match:f,type:p}=this.frontier[n];if(o){for(let y=0;y<o.childCount;y++)u.push(o.child(y));f=f.matchFragment(o)}let m=a.size+e-(i.content.size-i.openEnd);for(;c<a.childCount;){let y=a.child(c),k=f.matchType(y.type);if(!k)break;c++,(c>1||l==0||y.content.size)&&(f=k,u.push(Pm(y.mark(p.allowedMarks(y.marks)),c==1?l:0,c==a.childCount?m:-1)))}let g=c==a.childCount;g||(m=-1),this.placed=fs(this.placed,n,B.from(u)),this.frontier[n].match=f,g&&m<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,k=a;y<m;y++){let w=k.lastChild;this.frontier.push({type:w.type,match:w.contentMatchAt(w.childCount)}),k=w.content}this.unplaced=g?e==0?L.empty:new L(us(i.content,e-1,1),e-1,m<0?i.openEnd:e-1):new L(us(i.content,e,c),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],n;if(!e.type.isTextblock||!xc(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(n=this.findCloseLevel(this.$to))&&n.depth==this.depth)return-1;let{depth:r}=this.$to,o=this.$to.after(r);for(;r>1&&o==this.$to.end(--r);)++o;return o}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:o}=this.frontier[n],s=n<e.depth&&e.end(n+1)==e.pos+(e.depth-(n+1)),i=xc(e,n,o,r,s);if(i){for(let a=n-1;a>=0;a--){let{match:l,type:c}=this.frontier[a],u=xc(e,a,c,l,!0);if(!u||u.childCount)continue e}return{depth:n,fit:i,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=fs(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let o=e.node(r),s=o.type.contentMatch.fillBefore(o.content,!0,e.index(r));this.openFrontierNode(o.type,o.attrs,s)}return e}openFrontierNode(e,n=null,r){let o=this.frontier[this.depth];o.match=o.match.matchType(e),this.placed=fs(this.placed,this.depth,B.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(B.empty,!0);n.childCount&&(this.placed=fs(this.placed,this.frontier.length,n))}}function us(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(us(t.firstChild.content,e-1,n)))}function fs(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(fs(t.lastChild.content,e-1,n)))}function Cc(t,e){for(let n=0;n<e;n++)t=t.firstChild.content;return t}function Pm(t,e,n){if(e<=0)return t;let r=t.content;return e>1&&(r=r.replaceChild(0,Pm(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(B.empty,!0)))),t.copy(r)}function xc(t,e,n,r,o){let s=t.node(e),i=o?t.indexAfter(e):t.index(e);if(i==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,i);return a&&!hT(n,s.content,i)?a:null}function hT(t,e,n){for(let r=n;r<e.childCount;r++)if(!t.allowsMarks(e.child(r).marks))return!0;return!1}function pT(t){return t.spec.defining||t.spec.definingForContent}function mT(t,e,n,r){if(!r.size)return t.deleteRange(e,n);let o=t.doc.resolve(e),s=t.doc.resolve(n);if(Im(o,s,r))return t.step(new Re(e,n,r));let i=Dm(o,s);i[i.length-1]==0&&i.pop();let a=-(o.depth+1);i.unshift(a);for(let p=o.depth,m=o.pos-1;p>0;p--,m--){let g=o.node(p).type.spec;if(g.defining||g.definingAsContext||g.isolating)break;i.indexOf(p)>-1?a=p:o.before(p)==m&&i.splice(1,0,-p)}let l=i.indexOf(a),c=[],u=r.openStart;for(let p=r.content,m=0;;m++){let g=p.firstChild;if(c.push(g),m==r.openStart)break;p=g.content}for(let p=u-1;p>=0;p--){let m=c[p],g=pT(m.type);if(g&&!m.sameMarkup(o.node(Math.abs(a)-1)))u=p;else if(g||!m.type.isTextblock)break}for(let p=r.openStart;p>=0;p--){let m=(p+u+1)%(r.openStart+1),g=c[m];if(g)for(let y=0;y<i.length;y++){let k=i[(y+l)%i.length],w=!0;k<0&&(w=!1,k=-k);let v=o.node(k-1),b=o.index(k-1);if(v.canReplaceWith(b,b,g.type,g.marks))return t.replace(o.before(k),w?s.after(k):n,new L(Rm(r.content,0,r.openStart,m),m,r.openEnd))}}let f=t.steps.length;for(let p=i.length-1;p>=0&&(t.replace(e,n,r),!(t.steps.length>f));p--){let m=i[p];m<0||(e=o.before(m),n=s.after(m))}}function Rm(t,e,n,r,o){if(e<n){let s=t.firstChild;t=t.replaceChild(0,s.copy(Rm(s.content,e+1,n,r,s)))}if(e>r){let s=o.contentMatchAt(0),i=s.fillBefore(t).append(t);t=i.append(s.matchFragment(i).fillBefore(B.empty,!0))}return t}function gT(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let o=uT(t.doc,e,r.type);o!=null&&(e=n=o)}t.replaceRange(e,n,new L(B.from(r),0,0))}function yT(t,e,n){let r=t.doc.resolve(e),o=t.doc.resolve(n),s=Dm(r,o);for(let i=0;i<s.length;i++){let a=s[i],l=i==s.length-1;if(l&&a==0||r.node(a).type.contentMatch.validEnd)return t.delete(r.start(a),o.end(a));if(a>0&&(l||r.node(a-1).canReplace(r.index(a-1),o.indexAfter(a-1))))return t.delete(r.before(a),o.after(a))}for(let i=1;i<=r.depth&&i<=o.depth;i++)if(e-r.start(i)==r.depth-i&&n>r.end(i)&&o.end(i)-n!=o.depth-i&&r.start(i-1)==o.start(i-1)&&r.node(i-1).canReplace(r.index(i-1),o.index(i-1)))return t.delete(r.before(i),n);t.delete(e,n)}function Dm(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let o=r;o>=0;o--){let s=t.start(o);if(s<t.pos-(t.depth-o)||e.end(o)>e.pos+(e.depth-o)||t.node(o).type.spec.isolating||e.node(o).type.spec.isolating)break;(s==e.start(o)||o==t.depth&&o==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&o&&e.start(o-1)==s-1)&&n.push(o)}return n}class ao extends Ke{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Te.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let o=n.type.create(r,null,n.marks);return Te.fromReplace(e,this.pos,this.pos+1,new L(B.from(o),0,n.isLeaf?0:1))}getMap(){return ct.empty}invert(e){return new ao(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new ao(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new ao(n.pos,n.attr,n.value)}}Ke.jsonID("attr",ao);class hs extends Ke{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let o in e.attrs)n[o]=e.attrs[o];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Te.ok(r)}getMap(){return ct.empty}invert(e){return new hs(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new hs(n.attr,n.value)}}Ke.jsonID("docAttr",hs);let lo=class extends Error{};lo=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},lo.prototype=Object.create(Error.prototype),lo.prototype.constructor=lo,lo.prototype.name="TransformError";class zm{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ds}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new lo(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r<this.mapping.maps.length;r++){let o=this.mapping.maps[r];r&&(e=o.map(e,1),n=o.map(n,-1)),o.forEach((s,i,a,l)=>{e=Math.min(e,a),n=Math.max(n,l)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=L.empty){let o=ji(this.doc,e,n,r);return o&&this.step(o),this}replaceWith(e,n,r){return this.replace(e,n,new L(B.from(r),0,0))}delete(e,n){return this.replace(e,n,L.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return mT(this,e,n,r),this}replaceRangeWith(e,n,r){return gT(this,e,n,r),this}deleteRange(e,n){return yT(this,e,n),this}lift(e,n){return tT(this,e,n),this}join(e,n=1){return dT(this,e,n),this}wrap(e,n){return oT(this,e,n),this}setBlockType(e,n=e,r,o=null){return sT(this,e,n,r,o),this}setNodeMarkup(e,n,r=null,o){return aT(this,e,n,r,o),this}setNodeAttribute(e,n,r){return this.step(new ao(e,n,r)),this}setDocAttribute(e,n){return this.step(new hs(e,n)),this}addNodeMark(e,n){return this.step(new On(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof ye)n.isInSet(r.marks)&&this.step(new yr(e,n));else{let o=r.marks,s,i=[];for(;s=n.isInSet(o);)i.push(new yr(e,s)),o=s.removeFromSet(o);for(let a=i.length-1;a>=0;a--)this.step(i[a])}return this}split(e,n=1,r){return lT(this,e,n,r),this}addMark(e,n,r){return XE(this,e,n,r),this}removeMark(e,n,r){return QE(this,e,n,r),this}clearIncompatible(e,n,r){return Sc(this,e,n,r),this}}const _c=Object.create(null);class ie{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new kT(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n<e.length;n++)if(e[n].$from.pos!=e[n].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,n=L.empty){let r=n.content.lastChild,o=null;for(let a=0;a<n.openEnd;a++)o=r,r=r.lastChild;let s=e.steps.length,i=this.ranges;for(let a=0;a<i.length;a++){let{$from:l,$to:c}=i[a],u=e.mapping.slice(s);e.replaceRange(u.map(l.pos),u.map(c.pos),a?L.empty:n),a==0&&Lm(e,s,(r?r.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,n){let r=e.steps.length,o=this.ranges;for(let s=0;s<o.length;s++){let{$from:i,$to:a}=o[s],l=e.mapping.slice(r),c=l.map(i.pos),u=l.map(a.pos);s?e.deleteRange(c,u):(e.replaceRangeWith(c,u,n),Lm(e,r,n.isInline?-1:1))}}static findFrom(e,n,r=!1){let o=e.parent.inlineContent?new re(e):co(e.node(0),e.parent,e.pos,e.index(),n,r);if(o)return o;for(let s=e.depth-1;s>=0;s--){let i=n<0?co(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):co(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(i)return i}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new dt(e.node(0))}static atStart(e){return co(e,e,0,0,1)||new dt(e)}static atEnd(e){return co(e,e,e.content.size,e.childCount,-1)||new dt(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=_c[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in _c)throw new RangeError("Duplicate use of selection JSON ID "+e);return _c[e]=n,n.prototype.jsonID=e,n}getBookmark(){return re.between(this.$anchor,this.$head).getBookmark()}}ie.prototype.visible=!0;class kT{constructor(e,n){this.$from=e,this.$to=n}}let $m=!1;function Vm(t){!$m&&!t.parent.inlineContent&&($m=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class re extends ie{constructor(e,n=e){Vm(e),Vm(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return ie.near(r);let o=e.resolve(n.map(this.anchor));return new re(o.parent.inlineContent?o:r,r)}replace(e,n=L.empty){if(super.replace(e,n),n==L.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof re&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Hi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new re(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let o=e.resolve(n);return new this(o,r==n?o:e.resolve(r))}static between(e,n,r){let o=e.pos-n.pos;if((!r||o)&&(r=o>=0?1:-1),!n.parent.inlineContent){let s=ie.findFrom(n,r,!0)||ie.findFrom(n,-r,!0);if(s)n=s.$head;else return ie.near(n,r)}return e.parent.inlineContent||(o==0?e=n:(e=(ie.findFrom(e,-r,!0)||ie.findFrom(e,r,!0)).$anchor,e.pos<n.pos!=o<0&&(e=n))),new re(e,n)}}ie.jsonID("text",re);class Hi{constructor(e,n){this.anchor=e,this.head=n}map(e){return new Hi(e.map(this.anchor),e.map(this.head))}resolve(e){return re.between(e.resolve(this.anchor),e.resolve(this.head))}}class G extends ie{constructor(e){let n=e.nodeAfter,r=e.node(0).resolve(e.pos+n.nodeSize);super(e,r),this.node=n}map(e,n){let{deleted:r,pos:o}=n.mapResult(this.anchor),s=e.resolve(o);return r?ie.near(s):new G(s)}content(){return new L(B.from(this.node),0,0)}eq(e){return e instanceof G&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ec(this.anchor)}static fromJSON(e,n){if(typeof n.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new G(e.resolve(n.anchor))}static create(e,n){return new G(e.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}G.prototype.visible=!1,ie.jsonID("node",G);class Ec{constructor(e){this.anchor=e}map(e){let{deleted:n,pos:r}=e.mapResult(this.anchor);return n?new Hi(r,r):new Ec(r)}resolve(e){let n=e.resolve(this.anchor),r=n.nodeAfter;return r&&G.isSelectable(r)?new G(n):ie.near(n)}}class dt extends ie{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,n=L.empty){if(n==L.empty){e.delete(0,e.doc.content.size);let r=ie.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,n)}toJSON(){return{type:"all"}}static fromJSON(e){return new dt(e)}map(e){return new dt(e)}eq(e){return e instanceof dt}getBookmark(){return wT}}ie.jsonID("all",dt);const wT={map(){return this},resolve(t){return new dt(t)}};function co(t,e,n,r,o,s=!1){if(e.inlineContent)return re.create(t,n);for(let i=r-(o>0?0:1);o>0?i<e.childCount:i>=0;i+=o){let a=e.child(i);if(a.isAtom){if(!s&&G.isSelectable(a))return G.create(t,n-(o<0?a.nodeSize:0))}else{let l=co(t,a,n+o,o<0?a.childCount:0,o,s);if(l)return l}n+=a.nodeSize*o}return null}function Lm(t,e,n){let r=t.steps.length-1;if(r<e)return;let o=t.steps[r];if(!(o instanceof Re||o instanceof De))return;let s=t.mapping.maps[r],i;s.forEach((a,l,c,u)=>{i==null&&(i=u)}),t.setSelection(ie.near(t.doc.resolve(i),n))}const Fm=1,Wi=2,jm=4;class vT extends zm{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Fm)&~Wi,this.storedMarks=null,this}get selectionSet(){return(this.updated&Fm)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Wi,this}ensureMarks(e){return ye.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Wi)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~Wi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||ye.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let o=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(o.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let i=this.doc.resolve(n);s=r==n?i.marks():i.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,o.text(e,s)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(ie.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=jm,this}get scrolledIntoView(){return(this.updated&jm)>0}}function Hm(t,e){return!e||!t?t:t.bind(e)}class ps{constructor(e,n,r){this.name=e,this.init=Hm(n.init,r),this.apply=Hm(n.apply,r)}}const bT=[new ps("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new ps("selection",{init(t,e){return t.selection||ie.atStart(e.doc)},apply(t){return t.selection}}),new ps("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new ps("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class Tc{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=bT.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new ps(r.key,r.spec.state,r))})}}class uo{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;r<this.config.plugins.length;r++)if(r!=n){let o=this.config.plugins[r];if(o.spec.filterTransaction&&!o.spec.filterTransaction.call(o,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let n=[e],r=this.applyInner(e),o=null;for(;;){let s=!1;for(let i=0;i<this.config.plugins.length;i++){let a=this.config.plugins[i];if(a.spec.appendTransaction){let l=o?o[i].n:0,c=o?o[i].state:this,u=l<n.length&&a.spec.appendTransaction.call(a,l?n.slice(l):n,c,r);if(u&&r.filterTransaction(u,i)){if(u.setMeta("appendedTransaction",e),!o){o=[];for(let f=0;f<this.config.plugins.length;f++)o.push(f<i?{state:r,n:n.length}:{state:this,n:0})}n.push(u),r=r.applyInner(u),s=!0}o&&(o[i]={state:r,n:n.length})}}if(!s)return{state:r,transactions:n}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let n=new uo(this.config),r=this.config.fields;for(let o=0;o<r.length;o++){let s=r[o];n[s.name]=s.apply(e,this[s.name],this,n)}return n}get tr(){return new vT(this)}static create(e){let n=new Tc(e.doc?e.doc.type.schema:e.schema,e.plugins),r=new uo(n);for(let o=0;o<n.fields.length;o++)r[n.fields[o].name]=n.fields[o].init(e,r);return r}reconfigure(e){let n=new Tc(this.schema,e.plugins),r=n.fields,o=new uo(n);for(let s=0;s<r.length;s++){let i=r[s].name;o[i]=this.hasOwnProperty(i)?this[i]:r[s].init(e,o)}return o}toJSON(e){let n={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(n.storedMarks=this.storedMarks.map(r=>r.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let o=e[r],s=o.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(o,this[o.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let o=new Tc(e.schema,e.plugins),s=new uo(o);return o.fields.forEach(i=>{if(i.name=="doc")s.doc=an.fromJSON(e.schema,n.doc);else if(i.name=="selection")s.selection=ie.fromJSON(s.doc,n.selection);else if(i.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let a in r){let l=r[a],c=l.spec.state;if(l.key==i.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){s[i.name]=c.fromJSON.call(l,e,n[a],s);return}}s[i.name]=i.init(e,s)}}),s}}function Wm(t,e,n){for(let r in t){let o=t[r];o instanceof Function?o=o.bind(e):r=="handleDOMEvents"&&(o=Wm(o,e,{})),n[r]=o}return n}class Oe{constructor(e){this.spec=e,this.props={},e.props&&Wm(e.props,this,this.props),this.key=e.key?e.key.key:Zm("plugin")}getState(e){return e[this.key]}}const Mc=Object.create(null);function Zm(t){return t in Mc?t+"$"+ ++Mc[t]:(Mc[t]=0,t+"$")}class Qe{constructor(e="key"){this.key=Zm(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ac=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function Um(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const Km=(t,e,n)=>{let r=Um(t,n);if(!r)return!1;let o=Nc(r);if(!o){let i=r.blockRange(),a=i&&io(i);return a==null?!1:(e&&e(t.tr.lift(i,a).scrollIntoView()),!0)}let s=o.nodeBefore;if(ng(t,o,e,-1))return!0;if(r.parent.content.size==0&&(fo(s,"end")||G.isSelectable(s)))for(let i=r.depth;;i--){let a=ji(t.doc,r.before(i),r.after(i),L.empty);if(a&&a.slice.size<a.to-a.from){if(e){let l=t.tr.step(a);l.setSelection(fo(s,"end")?ie.findFrom(l.doc.resolve(l.mapping.map(o.pos,-1)),-1):G.create(l.doc,o.pos-s.nodeSize)),e(l.scrollIntoView())}return!0}if(i==1||r.node(i-1).childCount>1)break}return s.isAtom&&o.depth==r.depth-1?(e&&e(t.tr.delete(o.pos-s.nodeSize,o.pos).scrollIntoView()),!0):!1},ST=(t,e,n)=>{let r=Um(t,n);if(!r)return!1;let o=Nc(r);return o?Jm(t,o,e):!1},CT=(t,e,n)=>{let r=Gm(t,n);if(!r)return!1;let o=Bc(r);return o?Jm(t,o,e):!1};function Jm(t,e,n){let r=e.nodeBefore,o=r,s=e.pos-1;for(;!o.isTextblock;s--){if(o.type.spec.isolating)return!1;let u=o.lastChild;if(!u)return!1;o=u}let i=e.nodeAfter,a=i,l=e.pos+1;for(;!a.isTextblock;l++){if(a.type.spec.isolating)return!1;let u=a.firstChild;if(!u)return!1;a=u}let c=ji(t.doc,s,l,L.empty);if(!c||c.from!=s||c instanceof Re&&c.slice.size>=l-s)return!1;if(n){let u=t.tr.step(c);u.setSelection(re.create(u.doc,s)),n(u.scrollIntoView())}return!0}function fo(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}const qm=(t,e,n)=>{let{$head:r,empty:o}=t.selection,s=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;s=Nc(r)}let i=s&&s.nodeBefore;return!i||!G.isSelectable(i)?!1:(e&&e(t.tr.setSelection(G.create(t.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function Nc(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function Gm(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset<n.parent.content.size)?null:n}const Ym=(t,e,n)=>{let r=Gm(t,n);if(!r)return!1;let o=Bc(r);if(!o)return!1;let s=o.nodeAfter;if(ng(t,o,e,1))return!0;if(r.parent.content.size==0&&(fo(s,"start")||G.isSelectable(s))){let i=ji(t.doc,r.before(),r.after(),L.empty);if(i&&i.slice.size<i.to-i.from){if(e){let a=t.tr.step(i);a.setSelection(fo(s,"start")?ie.findFrom(a.doc.resolve(a.mapping.map(o.pos)),1):G.create(a.doc,a.mapping.map(o.pos))),e(a.scrollIntoView())}return!0}}return s.isAtom&&o.depth==r.depth-1?(e&&e(t.tr.delete(o.pos,o.pos+s.nodeSize).scrollIntoView()),!0):!1},Xm=(t,e,n)=>{let{$head:r,empty:o}=t.selection,s=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset<r.parent.content.size)return!1;s=Bc(r)}let i=s&&s.nodeAfter;return!i||!G.isSelectable(i)?!1:(e&&e(t.tr.setSelection(G.create(t.doc,s.pos)).scrollIntoView()),!0)};function Bc(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){let n=t.node(e);if(t.index(e)+1<n.childCount)return t.doc.resolve(t.after(e+1));if(n.type.spec.isolating)break}return null}const xT=(t,e)=>{let n=t.selection,r=n instanceof G,o;if(r){if(n.node.isTextblock||!kr(t.doc,n.from))return!1;o=n.from}else if(o=Fi(t.doc,n.from,-1),o==null)return!1;if(e){let s=t.tr.join(o);r&&s.setSelection(G.create(s.doc,o-t.doc.resolve(o).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},_T=(t,e)=>{let n=t.selection,r;if(n instanceof G){if(n.node.isTextblock||!kr(t.doc,n.to))return!1;r=n.to}else if(r=Fi(t.doc,n.to,1),r==null)return!1;return e&&e(t.tr.join(r).scrollIntoView()),!0},ET=(t,e)=>{let{$from:n,$to:r}=t.selection,o=n.blockRange(r),s=o&&io(o);return s==null?!1:(e&&e(t.tr.lift(o,s).scrollIntoView()),!0)},Qm=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(`
|
|
74
|
-
`).scrollIntoView()),!0)};function Oc(t){for(let e=0;e<t.edgeCount;e++){let{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}const TT=(t,e)=>{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let o=n.node(-1),s=n.indexAfter(-1),i=Oc(o.contentMatchAt(s));if(!i||!o.canReplaceWith(s,s,i))return!1;if(e){let a=n.after(),l=t.tr.replaceWith(a,a,i.createAndFill());l.setSelection(ie.near(l.doc.resolve(a),1)),e(l.scrollIntoView())}return!0},eg=(t,e)=>{let n=t.selection,{$from:r,$to:o}=n;if(n instanceof dt||r.parent.inlineContent||o.parent.inlineContent)return!1;let s=Oc(o.parent.contentMatchAt(o.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let i=(!r.parentOffset&&o.index()<o.parent.childCount?r:o).pos,a=t.tr.insert(i,s.createAndFill());a.setSelection(re.create(a.doc,i+1)),e(a.scrollIntoView())}return!0},tg=(t,e)=>{let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let s=n.before();if(cn(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let r=n.blockRange(),o=r&&io(r);return o==null?!1:(e&&e(t.tr.lift(r,o).scrollIntoView()),!0)};function MT(t){return(e,n)=>{let{$from:r,$to:o}=e.selection;if(e.selection instanceof G&&e.selection.node.isBlock)return!r.parentOffset||!cn(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],i,a,l=!1,c=!1;for(let m=r.depth;;m--)if(r.node(m).isBlock){l=r.end(m)==r.pos+(r.depth-m),c=r.start(m)==r.pos-(r.depth-m),a=Oc(r.node(m-1).contentMatchAt(r.indexAfter(m-1))),s.unshift(l&&a?{type:a}:null),i=m;break}else{if(m==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof re||e.selection instanceof dt)&&u.deleteSelection();let f=u.mapping.map(r.pos),p=cn(u.doc,f,s.length,s);if(p||(s[0]=a?{type:a}:null,p=cn(u.doc,f,s.length,s)),!p)return!1;if(u.split(f,s.length,s),!l&&c&&r.node(i).type!=a){let m=u.mapping.map(r.before(i)),g=u.doc.resolve(m);a&&r.node(i-1).canReplaceWith(g.index(),g.index()+1,a)&&u.setNodeMarkup(u.mapping.map(r.before(i)),a)}return n&&n(u.scrollIntoView()),!0}}const AT=MT(),NT=(t,e)=>{let{$from:n,to:r}=t.selection,o,s=n.sharedDepth(r);return s==0?!1:(o=n.before(s),e&&e(t.tr.setSelection(G.create(t.doc,o))),!0)};function BT(t,e,n){let r=e.nodeBefore,o=e.nodeAfter,s=e.index();return!r||!o||!r.type.compatibleContent(o.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(o.isTextblock||kr(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function ng(t,e,n,r){let o=e.nodeBefore,s=e.nodeAfter,i,a,l=o.type.spec.isolating||s.type.spec.isolating;if(!l&&BT(t,e,n))return!0;let c=!l&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(i=(a=o.contentMatchAt(o.childCount)).findWrapping(s.type))&&a.matchType(i[0]||s.type).validEnd){if(n){let m=e.pos+s.nodeSize,g=B.empty;for(let w=i.length-1;w>=0;w--)g=B.from(i[w].create(null,g));g=B.from(o.copy(g));let y=t.tr.step(new De(e.pos-1,m,e.pos,m,new L(g,1,0),i.length,!0)),k=y.doc.resolve(m+2*i.length);k.nodeAfter&&k.nodeAfter.type==o.type&&kr(y.doc,k.pos)&&y.join(k.pos),n(y.scrollIntoView())}return!0}let u=s.type.spec.isolating||r>0&&l?null:ie.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),p=f&&io(f);if(p!=null&&p>=e.depth)return n&&n(t.tr.lift(f,p).scrollIntoView()),!0;if(c&&fo(s,"start",!0)&&fo(o,"end")){let m=o,g=[];for(;g.push(m),!m.isTextblock;)m=m.lastChild;let y=s,k=1;for(;!y.isTextblock;y=y.firstChild)k++;if(m.canReplace(m.childCount,m.childCount,y.content)){if(n){let w=B.empty;for(let b=g.length-1;b>=0;b--)w=B.from(g[b].copy(w));let v=t.tr.step(new De(e.pos-g.length,e.pos+s.nodeSize,e.pos+k,e.pos+s.nodeSize-k,new L(w,g.length,0),0,!0));n(v.scrollIntoView())}return!0}}return!1}function rg(t){return function(e,n){let r=e.selection,o=t<0?r.$from:r.$to,s=o.depth;for(;o.node(s).isInline;){if(!s)return!1;s--}return o.node(s).isTextblock?(n&&n(e.tr.setSelection(re.create(e.doc,t<0?o.start(s):o.end(s)))),!0):!1}}const OT=rg(-1),IT=rg(1);function PT(t,e=null){return function(n,r){let{$from:o,$to:s}=n.selection,i=o.blockRange(s),a=i&&Tm(i,t,e);return a?(r&&r(n.tr.wrap(i,a).scrollIntoView()),!0):!1}}function og(t,e=null){return function(n,r){let o=!1;for(let s=0;s<n.selection.ranges.length&&!o;s++){let{$from:{pos:i},$to:{pos:a}}=n.selection.ranges[s];n.doc.nodesBetween(i,a,(l,c)=>{if(o)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)o=!0;else{let u=n.doc.resolve(c),f=u.index();o=u.parent.canReplaceWith(f,f+1,t)}})}if(!o)return!1;if(r){let s=n.tr;for(let i=0;i<n.selection.ranges.length;i++){let{$from:{pos:a},$to:{pos:l}}=n.selection.ranges[i];s.setBlockType(a,l,t,e)}r(s.scrollIntoView())}return!0}}function Ic(...t){return function(e,n,r){for(let o=0;o<t.length;o++)if(t[o](e,n,r))return!0;return!1}}Ic(Ac,Km,qm),Ic(Ac,Ym,Xm),Ic(Qm,eg,tg,AT),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function RT(t,e=null){return function(n,r){let{$from:o,$to:s}=n.selection,i=o.blockRange(s);if(!i)return!1;let a=r?n.tr:null;return DT(a,i,t,e)?(r&&r(a.scrollIntoView()),!0):!1}}function DT(t,e,n,r=null){let o=!1,s=e,i=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let l=i.resolve(e.start-2);s=new Ri(l,l,e.depth),e.endIndex<e.parent.childCount&&(e=new Ri(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),o=!0}let a=Tm(s,n,r,e);return a?(t&&zT(t,e,a,o,n),!0):!1}function zT(t,e,n,r,o){let s=B.empty;for(let u=n.length-1;u>=0;u--)s=B.from(n[u].type.create(n[u].attrs,s));t.step(new De(e.start-(r?2:0),e.end,e.start,e.end,new L(s,0,0),n.length,!0));let i=0;for(let u=0;u<n.length;u++)n[u].type==o&&(i=u+1);let a=n.length-i,l=e.start+n.length-(r?2:0),c=e.parent;for(let u=e.startIndex,f=e.endIndex,p=!0;u<f;u++,p=!1)!p&&cn(t.doc,l,a)&&(t.split(l,a),l+=2*a),l+=c.child(u).nodeSize;return t}function $T(t){return function(e,n){let{$from:r,$to:o}=e.selection,s=r.blockRange(o,i=>i.childCount>0&&i.firstChild.type==t);return s?n?r.node(s.depth-1).type==t?VT(e,n,t,s):LT(e,n,s):!0:!1}}function VT(t,e,n,r){let o=t.tr,s=r.end,i=r.$to.end(r.depth);s<i&&(o.step(new De(s-1,i,s,i,new L(B.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new Ri(o.doc.resolve(r.$from.pos),o.doc.resolve(i),r.depth));const a=io(r);if(a==null)return!1;o.lift(r,a);let l=o.doc.resolve(o.mapping.map(s,-1)-1);return kr(o.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&o.join(l.pos),e(o.scrollIntoView()),!0}function LT(t,e,n){let r=t.tr,o=n.parent;for(let m=n.end,g=n.endIndex-1,y=n.startIndex;g>y;g--)m-=o.child(g).nodeSize,r.delete(m-1,m+1);let s=r.doc.resolve(n.start),i=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=n.startIndex==0,l=n.endIndex==o.childCount,c=s.node(-1),u=s.index(-1);if(!c.canReplace(u+(a?0:1),u+1,i.content.append(l?B.empty:B.from(o))))return!1;let f=s.pos,p=f+i.nodeSize;return r.step(new De(f-(a?1:0),p+(l?1:0),f+1,p-1,new L((a?B.empty:B.from(o.copy(B.empty))).append(l?B.empty:B.from(o.copy(B.empty))),a?0:1,l?0:1),a?0:1)),e(r.scrollIntoView()),!0}function FT(t){return function(e,n){let{$from:r,$to:o}=e.selection,s=r.blockRange(o,c=>c.childCount>0&&c.firstChild.type==t);if(!s)return!1;let i=s.startIndex;if(i==0)return!1;let a=s.parent,l=a.child(i-1);if(l.type!=t)return!1;if(n){let c=l.lastChild&&l.lastChild.type==a.type,u=B.from(c?t.create():null),f=new L(B.from(t.create(null,B.from(a.type.create(null,u)))),c?3:1,0),p=s.start,m=s.end;n(e.tr.step(new De(p-(c?3:1),m,p,m,f,1,!0)).scrollIntoView())}return!0}}const je=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},ho=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let Pc=null;const dn=function(t,e,n){let r=Pc||(Pc=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},jT=function(){Pc=null},wr=function(t,e,n,r){return n&&(sg(t,e,n,r,-1)||sg(t,e,n,r,1))},HT=/^(img|br|input|textarea|hr)$/i;function sg(t,e,n,r,o){for(var s;;){if(t==n&&e==r)return!0;if(e==(o<0?0:gt(t))){let i=t.parentNode;if(!i||i.nodeType!=1||ms(t)||HT.test(t.nodeName)||t.contentEditable=="false")return!1;e=je(t)+(o<0?0:1),t=i}else if(t.nodeType==1){let i=t.childNodes[e+(o<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false")if(!((s=i.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=o;else return!1;else t=i,e=o<0?gt(t):0}else return!1}}function gt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function WT(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=gt(t)}else if(t.parentNode&&!ms(t))e=je(t),t=t.parentNode;else return null}}function ZT(t,e){for(;;){if(t.nodeType==3&&e<t.nodeValue.length)return t;if(t.nodeType==1&&e<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[e],e=0}else if(t.parentNode&&!ms(t))e=je(t)+1,t=t.parentNode;else return null}}function UT(t,e,n){for(let r=e==0,o=e==gt(t);r||o;){if(t==n)return!0;let s=je(t);if(t=t.parentNode,!t)return!1;r=r&&s==0,o=o&&s==gt(t)}}function ms(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const Zi=function(t){return t.focusNode&&wr(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function vr(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}function KT(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function JT(t,e,n){if(t.caretPositionFromPoint)try{let r=t.caretPositionFromPoint(e,n);if(r)return{node:r.offsetNode,offset:Math.min(gt(r.offsetNode),r.offset)}}catch{}if(t.caretRangeFromPoint){let r=t.caretRangeFromPoint(e,n);if(r)return{node:r.startContainer,offset:Math.min(gt(r.startContainer),r.startOffset)}}}const Ut=typeof navigator<"u"?navigator:null,ig=typeof document<"u"?document:null,In=Ut&&Ut.userAgent||"",Rc=/Edge\/(\d+)/.exec(In),ag=/MSIE \d/.exec(In),Dc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(In),ot=!!(ag||Dc||Rc),Pn=ag?document.documentMode:Dc?+Dc[1]:Rc?+Rc[1]:0,yt=!ot&&/gecko\/(\d+)/i.test(In);yt&&+(/Firefox\/(\d+)/.exec(In)||[0,0])[1];const zc=!ot&&/Chrome\/(\d+)/.exec(In),He=!!zc,lg=zc?+zc[1]:0,Je=!ot&&!!Ut&&/Apple Computer/.test(Ut.vendor),po=Je&&(/Mobile\/\w+/.test(In)||!!Ut&&Ut.maxTouchPoints>2),kt=po||(Ut?/Mac/.test(Ut.platform):!1),cg=Ut?/Win/.test(Ut.platform):!1,un=/Android \d/.test(In),gs=!!ig&&"webkitFontSmoothing"in ig.documentElement.style,qT=gs?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function GT(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function fn(t,e){return typeof t=="number"?t:t[e]}function YT(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function dg(t,e,n){let r=t.someProp("scrollThreshold")||0,o=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let i=n||t.dom;i;){if(i.nodeType!=1){i=ho(i);continue}let a=i,l=a==s.body,c=l?GT(s):YT(a),u=0,f=0;if(e.top<c.top+fn(r,"top")?f=-(c.top-e.top+fn(o,"top")):e.bottom>c.bottom-fn(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+fn(o,"top")-c.top:e.bottom-c.bottom+fn(o,"bottom")),e.left<c.left+fn(r,"left")?u=-(c.left-e.left+fn(o,"left")):e.right>c.right-fn(r,"right")&&(u=e.right-c.right+fn(o,"right")),u||f)if(l)s.defaultView.scrollBy(u,f);else{let m=a.scrollLeft,g=a.scrollTop;f&&(a.scrollTop+=f),u&&(a.scrollLeft+=u);let y=a.scrollLeft-m,k=a.scrollTop-g;e={left:e.left-y,top:e.top-k,right:e.right-y,bottom:e.bottom-k}}let p=l?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(p))break;i=p=="absolute"?i.offsetParent:ho(i)}}function XT(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,o;for(let s=(e.left+e.right)/2,i=n+1;i<Math.min(innerHeight,e.bottom);i+=5){let a=t.root.elementFromPoint(s,i);if(!a||a==t.dom||!t.dom.contains(a))continue;let l=a.getBoundingClientRect();if(l.top>=n-20){r=a,o=l.top;break}}return{refDOM:r,refTop:o,stack:ug(t.dom)}}function ug(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=ho(r));return e}function QT({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;fg(n,r==0?0:r-e)}function fg(t,e){for(let n=0;n<t.length;n++){let{dom:r,top:o,left:s}=t[n];r.scrollTop!=o+e&&(r.scrollTop=o+e),r.scrollLeft!=s&&(r.scrollLeft=s)}}let mo=null;function e2(t){if(t.setActive)return t.setActive();if(mo)return t.focus(mo);let e=ug(t);t.focus(mo==null?{get preventScroll(){return mo={preventScroll:!0},!0}}:void 0),mo||(mo=!1,fg(e,0))}function hg(t,e){let n,r=2e8,o,s=0,i=e.top,a=e.top,l,c;for(let u=t.firstChild,f=0;u;u=u.nextSibling,f++){let p;if(u.nodeType==1)p=u.getClientRects();else if(u.nodeType==3)p=dn(u).getClientRects();else continue;for(let m=0;m<p.length;m++){let g=p[m];if(g.top<=i&&g.bottom>=a){i=Math.max(g.bottom,i),a=Math.min(g.top,a);let y=g.left>e.left?g.left-e.left:g.right<e.left?e.left-g.right:0;if(y<r){n=u,r=y,o=y&&n.nodeType==3?{left:g.right<e.left?g.right:g.left,top:e.top}:e,u.nodeType==1&&y&&(s=f+(e.left>=(g.left+g.right)/2?1:0));continue}}else g.top>e.top&&!l&&g.left<=e.left&&g.right>=e.left&&(l=u,c={left:Math.max(g.left,Math.min(g.right,e.left)),top:g.top});!n&&(e.left>=g.right&&e.top>=g.top||e.left>=g.left&&e.top>=g.bottom)&&(s=f+1)}}return!n&&l&&(n=l,o=c,r=0),n&&n.nodeType==3?t2(n,o):!n||r&&n.nodeType==1?{node:t,offset:s}:hg(n,o)}function t2(t,e){let n=t.nodeValue.length,r=document.createRange(),o;for(let s=0;s<n;s++){r.setEnd(t,s+1),r.setStart(t,s);let i=Rn(r,1);if(i.top!=i.bottom&&$c(e,i)){o={node:t,offset:s+(e.left>=(i.left+i.right)/2?1:0)};break}}return r.detach(),o||{node:t,offset:0}}function $c(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function n2(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left<t.getBoundingClientRect().left?n:t}function r2(t,e,n){let{node:r,offset:o}=hg(e,n),s=-1;if(r.nodeType==1&&!r.firstChild){let i=r.getBoundingClientRect();s=i.left!=i.right&&n.left>(i.left+i.right)/2?1:-1}return t.docView.posFromDOM(r,o,s)}function o2(t,e,n,r){let o=-1;for(let s=e,i=!1;s!=t.dom;){let a=t.docView.nearestDesc(s,!0),l;if(!a)return null;if(a.dom.nodeType==1&&(a.node.isBlock&&a.parent||!a.contentDOM)&&((l=a.dom.getBoundingClientRect()).width||l.height)&&(a.node.isBlock&&a.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(a.dom.nodeName)&&(!i&&l.left>r.left||l.top>r.top?o=a.posBefore:(!i&&l.right<r.left||l.bottom<r.top)&&(o=a.posAfter),i=!0),!a.contentDOM&&o<0&&!a.node.isText))return(a.node.isBlock?r.top<(l.top+l.bottom)/2:r.left<(l.left+l.right)/2)?a.posBefore:a.posAfter;s=a.dom.parentNode}return o>-1?o:t.docView.posFromDOM(e,n,-1)}function pg(t,e,n){let r=t.childNodes.length;if(r&&n.top<n.bottom)for(let o=Math.max(0,Math.min(r-1,Math.floor(r*(e.top-n.top)/(n.bottom-n.top))-2)),s=o;;){let i=t.childNodes[s];if(i.nodeType==1){let a=i.getClientRects();for(let l=0;l<a.length;l++){let c=a[l];if($c(e,c))return pg(i,e,c)}}if((s=(s+1)%r)==o)break}return t}function s2(t,e){let n=t.dom.ownerDocument,r,o=0,s=JT(n,e.left,e.top);s&&({node:r,offset:o}=s);let i=(t.root.elementFromPoint?t.root:n).elementFromPoint(e.left,e.top),a;if(!i||!t.dom.contains(i.nodeType!=1?i.parentNode:i)){let c=t.dom.getBoundingClientRect();if(!$c(e,c)||(i=pg(t.dom,e,c),!i))return null}if(Je)for(let c=i;r&&c;c=ho(c))c.draggable&&(r=void 0);if(i=n2(i,e),r){if(yt&&r.nodeType==1&&(o=Math.min(o,r.childNodes.length),o<r.childNodes.length)){let u=r.childNodes[o],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&o++}let c;gs&&o&&r.nodeType==1&&(c=r.childNodes[o-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&o--,r==t.dom&&o==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?a=t.state.doc.content.size:(o==0||r.nodeType!=1||r.childNodes[o-1].nodeName!="BR")&&(a=o2(t,r,o,e))}a==null&&(a=r2(t,i,e));let l=t.docView.nearestDesc(i,!0);return{pos:a,inside:l?l.posAtStart-l.border:-1}}function mg(t){return t.top<t.bottom||t.left<t.right}function Rn(t,e){let n=t.getClientRects();if(n.length){let r=n[e<0?0:n.length-1];if(mg(r))return r}return Array.prototype.find.call(n,mg)||t.getBoundingClientRect()}const i2=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function gg(t,e,n){let{node:r,offset:o,atom:s}=t.docView.domFromPos(e,n<0?-1:1),i=gs||yt;if(r.nodeType==3)if(i&&(i2.test(r.nodeValue)||(n<0?!o:o==r.nodeValue.length))){let l=Rn(dn(r,o,o),n);if(yt&&o&&/\s/.test(r.nodeValue[o-1])&&o<r.nodeValue.length){let c=Rn(dn(r,o-1,o-1),-1);if(c.top==l.top){let u=Rn(dn(r,o,o+1),-1);if(u.top!=l.top)return ys(u,u.left<c.left)}}return l}else{let l=o,c=o,u=n<0?1:-1;return n<0&&!o?(c++,u=-1):n>=0&&o==r.nodeValue.length?(l--,u=1):n<0?l--:c++,ys(Rn(dn(r,l,c),u),u<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&o&&(n<0||o==gt(r))){let l=r.childNodes[o-1];if(l.nodeType==1)return Vc(l.getBoundingClientRect(),!1)}if(s==null&&o<gt(r)){let l=r.childNodes[o];if(l.nodeType==1)return Vc(l.getBoundingClientRect(),!0)}return Vc(r.getBoundingClientRect(),n>=0)}if(s==null&&o&&(n<0||o==gt(r))){let l=r.childNodes[o-1],c=l.nodeType==3?dn(l,gt(l)-(i?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(c)return ys(Rn(c,1),!1)}if(s==null&&o<gt(r)){let l=r.childNodes[o];for(;l.pmViewDesc&&l.pmViewDesc.ignoreForCoords;)l=l.nextSibling;let c=l?l.nodeType==3?dn(l,0,i?0:1):l.nodeType==1?l:null:null;if(c)return ys(Rn(c,-1),!0)}return ys(Rn(r.nodeType==3?dn(r):r,-n),n>=0)}function ys(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Vc(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function yg(t,e,n){let r=t.state,o=t.root.activeElement;r!=e&&t.updateState(e),o!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),o!=t.dom&&o&&o.focus()}}function a2(t,e,n){let r=e.selection,o=n=="up"?r.$from:r.$to;return yg(t,e,()=>{let{node:s}=t.docView.domFromPos(o.pos,n=="up"?-1:1);for(;;){let a=t.docView.nearestDesc(s,!0);if(!a)break;if(a.node.isBlock){s=a.contentDOM||a.dom;break}s=a.dom.parentNode}let i=gg(t,o.pos,1);for(let a=s.firstChild;a;a=a.nextSibling){let l;if(a.nodeType==1)l=a.getClientRects();else if(a.nodeType==3)l=dn(a,0,a.nodeValue.length).getClientRects();else continue;for(let c=0;c<l.length;c++){let u=l[c];if(u.bottom>u.top+1&&(n=="up"?i.top-u.top>(u.bottom-i.top)*2:u.bottom-i.bottom>(i.bottom-u.top)*2))return!1}}return!0})}const l2=/[\u0590-\u08ac]/;function c2(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let o=r.parentOffset,s=!o,i=o==r.parent.content.size,a=t.domSelection();return a?!l2.test(r.parent.textContent)||!a.modify?n=="left"||n=="backward"?s:i:yg(t,e,()=>{let{focusNode:l,focusOffset:c,anchorNode:u,anchorOffset:f}=t.domSelectionRange(),p=a.caretBidiLevel;a.modify("move",n,"character");let m=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:g,focusOffset:y}=t.domSelectionRange(),k=g&&!m.contains(g.nodeType==1?g:g.parentNode)||l==g&&c==y;try{a.collapse(u,f),l&&(l!=u||c!=f)&&a.extend&&a.extend(l,c)}catch{}return p!=null&&(a.caretBidiLevel=p),k}):r.pos==r.start()||r.pos==r.end()}let kg=null,wg=null,vg=!1;function d2(t,e,n){return kg==e&&wg==n?vg:(kg=e,wg=n,vg=n=="up"||n=="down"?a2(t,e,n):c2(t,e,n))}const wt=0,bg=1,br=2,Kt=3;class ks{constructor(e,n,r,o){this.parent=e,this.children=n,this.dom=r,this.contentDOM=o,this.dirty=wt,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;n<this.children.length;n++)e+=this.children[n].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let n=0,r=this.posAtStart;;n++){let o=this.children[n];if(o==e)return r;r+=o.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,n,r){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(r<0){let s,i;if(e==this.contentDOM)s=e.childNodes[n-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(i)+i.size:this.posAtStart}else{let s,i;if(e==this.contentDOM)s=e.childNodes[n];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(i):this.posAtEnd}let o;if(e==this.dom&&this.contentDOM)o=n>je(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))o=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let s=e;;s=s.parentNode){if(s==this.dom){o=!1;break}if(s.previousSibling)break}if(o==null&&n==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){o=!0;break}if(s.nextSibling)break}}return o??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,o=e;o;o=o.parentNode){let s=this.getDesc(o),i;if(s&&(!n||s.node))if(r&&(i=s.nodeDOM)&&!(i.nodeType==1?i.contains(e.nodeType==1?e:e.parentNode):i==e))r=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let o=e;o;o=o.parentNode){let s=this.getDesc(o);if(s)return s.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],s=r+o.size;if(r==e&&s!=r){for(;!o.border&&o.children.length;)for(let i=0;i<o.children.length;i++){let a=o.children[i];if(a.size){o=a;break}}return o}if(e<s)return o.descAt(e-r-o.border);r=s}}domFromPos(e,n){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let r=0,o=0;for(let s=0;r<this.children.length;r++){let i=this.children[r],a=s+i.size;if(a>e||i instanceof xg){o=e-s;break}s=a}if(o)return this.children[r].domFromPos(o-this.children[r].border,n);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Sg&&s.side>=0;r--);if(n<=0){let s,i=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,i=!1);return s&&n&&i&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?je(s.dom)+1:0}}else{let s,i=!0;for(;s=r<this.children.length?this.children[r]:null,!(!s||s.dom.parentNode==this.contentDOM);r++,i=!1);return s&&i&&!s.border&&!s.domAtom?s.domFromPos(0,n):{node:this.contentDOM,offset:s?je(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,n,r=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:n,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let o=-1,s=-1;for(let i=r,a=0;;a++){let l=this.children[a],c=i+l.size;if(o==-1&&e<=c){let u=i+l.border;if(e>=u&&n<=c-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,u);e=i;for(let f=a;f>0;f--){let p=this.children[f-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){o=je(p.dom)+1;break}e-=p.size}o==-1&&(o=0)}if(o>-1&&(c>n||a==this.children.length-1)){n=c;for(let u=a+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=je(f.dom);break}n+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}i=c}return{node:this.contentDOM,from:e,to:n,fromOffset:o,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let n=this.children[e<0?0:this.children.length-1];return n.size==0||n.emptyChildAt(e)}domAfterPos(e){let{node:n,offset:r}=this.domFromPos(e,0);if(n.nodeType!=1||r==n.childNodes.length)throw new RangeError("No node after pos "+e);return n.childNodes[r]}setSelection(e,n,r,o=!1){let s=Math.min(e,n),i=Math.max(e,n);for(let m=0,g=0;m<this.children.length;m++){let y=this.children[m],k=g+y.size;if(s>g&&i<k)return y.setSelection(e-g-y.border,n-g-y.border,r,o);g=k}let a=this.domFromPos(e,e?-1:1),l=n==e?a:this.domFromPos(n,n?-1:1),c=r.root.getSelection(),u=r.domSelectionRange(),f=!1;if((yt||Je)&&e==n){let{node:m,offset:g}=a;if(m.nodeType==3){if(f=!!(g&&m.nodeValue[g-1]==`
|
|
75
|
-
`),f&&g==m.nodeValue.length)for(let y=m,k;y;y=y.parentNode){if(k=y.nextSibling){k.nodeName=="BR"&&(a=l={node:k.parentNode,offset:je(k)+1});break}let w=y.pmViewDesc;if(w&&w.node&&w.node.isBlock)break}}else{let y=m.childNodes[g-1];f=y&&(y.nodeName=="BR"||y.contentEditable=="false")}}if(yt&&u.focusNode&&u.focusNode!=l.node&&u.focusNode.nodeType==1){let m=u.focusNode.childNodes[u.focusOffset];m&&m.contentEditable=="false"&&(o=!0)}if(!(o||f&&Je)&&wr(a.node,a.offset,u.anchorNode,u.anchorOffset)&&wr(l.node,l.offset,u.focusNode,u.focusOffset))return;let p=!1;if((c.extend||e==n)&&!(f&&yt)){c.collapse(a.node,a.offset);try{e!=n&&c.extend(l.node,l.offset),p=!0}catch{}}if(!p){if(e>n){let g=a;a=l,l=g}let m=document.createRange();m.setEnd(l.node,l.offset),m.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(m)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,o=0;o<this.children.length;o++){let s=this.children[o],i=r+s.size;if(r==i?e<=i&&n>=r:e<i&&n>r){let a=r+s.border,l=i-s.border;if(e>=a&&n<=l){this.dirty=e==r||n==i?br:bg,e==a&&n==l&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Kt:s.markDirty(e-a,n-a);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?br:Kt}r=i}this.dirty=br}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?br:bg;n.dirty<r&&(n.dirty=r)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Sg extends ks{constructor(e,n,r,o){let s,i=n.type.toDOM;if(typeof i=="function"&&(i=i(r,()=>{if(!s)return o;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(i.nodeType!=1){let a=document.createElement("span");a.appendChild(i),i=a}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==wt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class u2 extends ks{constructor(e,n,r,o){super(e,[],n,null),this.textDOM=r,this.text=o}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Sr extends ks{constructor(e,n,r,o,s){super(e,[],r,o),this.mark=n,this.spec=s}static create(e,n,r,o){let s=o.nodeViews[n.type.name],i=s&&s(n,o,r);return(!i||!i.dom)&&(i=gr.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Sr(e,n,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&Kt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Kt&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=wt){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty<this.dirty&&(r.dirty=this.dirty),this.dirty=wt}}slice(e,n,r){let o=Sr.create(this.parent,this.mark,!0,r),s=this.children,i=this.size;n<i&&(s=Fc(s,n,i,r)),e>0&&(s=Fc(s,0,e,r));for(let a=0;a<s.length;a++)s[a].parent=o;return o.children=s,o}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Dn extends ks{constructor(e,n,r,o,s,i,a,l,c){super(e,[],s,i),this.node=n,this.outerDeco=r,this.innerDeco=o,this.nodeDOM=a}static create(e,n,r,o,s,i){let a=s.nodeViews[n.type.name],l,c=a&&a(n,s,()=>{if(!l)return i;if(l.parent)return l.parent.posBeforeChild(l)},r,o),u=c&&c.dom,f=c&&c.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=gr.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),n.type.spec.draggable&&(u.draggable=!0));let p=u;return u=Tg(u,r,n),c?l=new f2(e,n,r,o,u,f||null,p,c,s,i+1):n.isText?new Ui(e,n,r,o,u,p,s):new Dn(e,n,r,o,u,f||null,p,s,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>B.empty)}return e}matchesNode(e,n,r){return this.dirty==wt&&e.eq(this.node)&&Ki(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,o=n,s=e.composing?this.localCompositionInfo(e,n):null,i=s&&s.pos>-1?s:null,a=s&&s.pos<0,l=new p2(this,i&&i.node,e);y2(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?l.syncToMarks(c.spec.marks,r,e,u):c.type.side>=0&&!f&&l.syncToMarks(u==this.node.childCount?ye.none:this.node.child(u).marks,r,e,u),l.placeWidget(c,e,o)},(c,u,f,p)=>{l.syncToMarks(c.marks,r,e,p);let m;l.findNodeMatch(c,u,f,p)||a&&e.state.selection.from>o&&e.state.selection.to<o+c.nodeSize&&(m=l.findIndexWithChild(s.node))>-1&&l.updateNodeAt(c,u,f,m,e)||l.updateNextNode(c,u,f,e,p,o)||l.addNode(c,u,f,e,o),o+=c.nodeSize}),l.syncToMarks([],r,e,0),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==br)&&(i&&this.protectLocalComposition(e,i),_g(this.contentDOM,this.children,e),po&&k2(this.dom))}localCompositionInfo(e,n){let{from:r,to:o}=e.state.selection;if(!(e.state.selection instanceof re)||r<n||o>n+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let i=s.nodeValue,a=w2(this.node.content,i,r-n,o-n);return a<0?null:{node:s,pos:a,text:i}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:o}){if(this.getDesc(n))return;let s=n;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let i=new u2(this,s,n,o);e.input.compositionNodes.push(i),this.children=Fc(this.children,r,r+o.length,e,i)}update(e,n,r,o){return this.dirty==Kt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,o),!0)}updateInner(e,n,r,o){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(o,this.posAtStart),this.dirty=wt}updateOuterDeco(e){if(Ki(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Eg(this.dom,this.nodeDOM,Lc(this.outerDeco,this.node,n),Lc(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Cg(t,e,n,r,o){Tg(r,e,t);let s=new Dn(void 0,t,e,n,r,r,r,o,0);return s.contentDOM&&s.updateChildren(o,0),s}class Ui extends Dn{constructor(e,n,r,o,s,i,a){super(e,n,r,o,s,null,i,a,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,o){return this.dirty==Kt||this.dirty!=wt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=wt||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,o.trackWrites==this.nodeDOM&&(o.trackWrites=null)),this.node=e,this.dirty=wt,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let o=this.node.cut(e,n),s=document.createTextNode(o.text);return new Ui(this.parent,o,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Kt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class xg extends ks{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==wt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class f2 extends Dn{constructor(e,n,r,o,s,i,a,l,c,u){super(e,n,r,o,s,i,a,c,u),this.spec=l}update(e,n,r,o){if(this.dirty==Kt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,o),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,o)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,o){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,o)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function _g(t,e,n){let r=t.firstChild,o=!1;for(let s=0;s<e.length;s++){let i=e[s],a=i.dom;if(a.parentNode==t){for(;a!=r;)r=Mg(r),o=!0;r=r.nextSibling}else o=!0,t.insertBefore(a,r);if(i instanceof Sr){let l=r?r.previousSibling:t.lastChild;_g(i.contentDOM,i.children,n),r=l?l.nextSibling:t.firstChild}}for(;r;)r=Mg(r),o=!0;o&&n.trackWrites==t&&(n.trackWrites=null)}const ws=function(t){t&&(this.nodeName=t)};ws.prototype=Object.create(null);const Cr=[new ws];function Lc(t,e,n){if(t.length==0)return Cr;let r=n?Cr[0]:new ws,o=[r];for(let s=0;s<t.length;s++){let i=t[s].type.attrs;if(i){i.nodeName&&o.push(r=new ws(i.nodeName));for(let a in i){let l=i[a];l!=null&&(n&&o.length==1&&o.push(r=new ws(e.isInline?"span":"div")),a=="class"?r.class=(r.class?r.class+" ":"")+l:a=="style"?r.style=(r.style?r.style+";":"")+l:a!="nodeName"&&(r[a]=l))}}}return o}function Eg(t,e,n,r){if(n==Cr&&r==Cr)return e;let o=e;for(let s=0;s<r.length;s++){let i=r[s],a=n[s];if(s){let l;a&&a.nodeName==i.nodeName&&o!=t&&(l=o.parentNode)&&l.nodeName.toLowerCase()==i.nodeName||(l=document.createElement(i.nodeName),l.pmIsDeco=!0,l.appendChild(o),a=Cr[0]),o=l}h2(o,a||Cr[0],i)}return o}function h2(t,e,n){for(let r in e)r!="class"&&r!="style"&&r!="nodeName"&&!(r in n)&&t.removeAttribute(r);for(let r in n)r!="class"&&r!="style"&&r!="nodeName"&&n[r]!=e[r]&&t.setAttribute(r,n[r]);if(e.class!=n.class){let r=e.class?e.class.split(" ").filter(Boolean):[],o=n.class?n.class.split(" ").filter(Boolean):[];for(let s=0;s<r.length;s++)o.indexOf(r[s])==-1&&t.classList.remove(r[s]);for(let s=0;s<o.length;s++)r.indexOf(o[s])==-1&&t.classList.add(o[s]);t.classList.length==0&&t.removeAttribute("class")}if(e.style!=n.style){if(e.style){let r=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,o;for(;o=r.exec(e.style);)t.style.removeProperty(o[1])}n.style&&(t.style.cssText+=n.style)}}function Tg(t,e,n){return Eg(t,t,Cr,Lc(e,n,t.nodeType!=1))}function Ki(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].type.eq(e[n].type))return!1;return!0}function Mg(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}class p2{constructor(e,n,r){this.lock=n,this.view=r,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=m2(e.node.content,e)}destroyBetween(e,n){if(e!=n){for(let r=e;r<n;r++)this.top.children[r].destroy();this.top.children.splice(e,n-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,n,r,o){let s=0,i=this.stack.length>>1,a=Math.min(i,e.length);for(;s<a&&(s==i-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<i;)this.destroyRest(),this.top.dirty=wt,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let l=-1,c=this.top.children.length;o<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let u=this.index;u<c;u++){let f=this.top.children[u];if(f.matchesMark(e[i])&&!this.isLocked(f.dom)){l=u;break}}if(l>-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let u=Sr.create(this.top,e[i],n,r);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,i++}}findNodeMatch(e,n,r,o){let s=-1,i;if(o>=this.preMatch.index&&(i=this.preMatch.matches[o-this.preMatch.index]).parent==this.top&&i.matchesNode(e,n,r))s=this.top.children.indexOf(i,this.index);else for(let a=this.index,l=Math.min(this.top.children.length,a+5);a<l;a++){let c=this.top.children[a];if(c.matchesNode(e,n,r)&&!this.preMatch.matched.has(c)){s=a;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,n,r,o,s){let i=this.top.children[o];return i.dirty==Kt&&i.dom==i.contentDOM&&(i.dirty=br),i.update(e,n,r,s)?(this.destroyBetween(this.index,o),this.index++,!0):!1}findIndexWithChild(e){for(;;){let n=e.parentNode;if(!n)return-1;if(n==this.top.contentDOM){let r=e.pmViewDesc;if(r){for(let o=this.index;o<this.top.children.length;o++)if(this.top.children[o]==r)return o}return-1}e=n}}updateNextNode(e,n,r,o,s,i){for(let a=this.index;a<this.top.children.length;a++){let l=this.top.children[a];if(l instanceof Dn){let c=this.preMatch.matched.get(l);if(c!=null&&c!=s)return!1;let u=l.dom,f,p=this.isLocked(u)&&!(e.isText&&l.node&&l.node.isText&&l.nodeDOM.nodeValue==e.text&&l.dirty!=Kt&&Ki(n,l.outerDeco));if(!p&&l.update(e,n,r,o))return this.destroyBetween(this.index,a),l.dom!=u&&(this.changed=!0),this.index++,!0;if(!p&&(f=this.recreateWrapper(l,e,n,r,o,i)))return this.destroyBetween(this.index,a),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=br,f.updateChildren(o,i+1),f.dirty=wt),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,n,r,o,s,i){if(e.dirty||n.isAtom||!e.children.length||!e.node.content.eq(n.content)||!Ki(r,e.outerDeco)||!o.eq(e.innerDeco))return null;let a=Dn.create(this.top,n,r,o,s,i);if(a.contentDOM){a.children=e.children,e.children=[];for(let l of a.children)l.parent=a}return e.destroy(),a}addNode(e,n,r,o,s){let i=Dn.create(this.top,e,n,r,o,s);i.contentDOM&&i.updateChildren(o,s+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,n,r){let o=this.index<this.top.children.length?this.top.children[this.index]:null;if(o&&o.matchesWidget(e)&&(e==o.widget||!o.widget.type.toDOM.parentNode))this.index++;else{let s=new Sg(this.top,e,n,r);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],n=this.top;for(;e instanceof Sr;)n=e,e=n.children[n.children.length-1];(!e||!(e instanceof Ui)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Je||He)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",n),this.addHackNode("BR",this.top))}addHackNode(e,n){if(n==this.top&&this.index<n.children.length&&n.children[this.index].matchesHack(e))this.index++;else{let r=document.createElement(e);e=="IMG"&&(r.className="ProseMirror-separator",r.alt=""),e=="BR"&&(r.className="ProseMirror-trailingBreak");let o=new xg(this.top,[],r,null);n!=this.top?n.children.push(o):n.children.splice(this.index++,0,o),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function m2(t,e){let n=e,r=n.children.length,o=t.childCount,s=new Map,i=[];e:for(;o>0;){let a;for(;;)if(r){let c=n.children[r-1];if(c instanceof Sr)n=c,r=c.children.length;else{a=c,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=a.node;if(l){if(l!=t.child(o-1))break;--o,s.set(a,o),i.push(a)}}return{index:o,matched:s,matches:i.reverse()}}function g2(t,e){return t.type.side-e.type.side}function y2(t,e,n,r){let o=e.locals(t),s=0;if(o.length==0){for(let c=0;c<t.childCount;c++){let u=t.child(c);r(u,o,e.forChild(s,u),c),s+=u.nodeSize}return}let i=0,a=[],l=null;for(let c=0;;){let u,f;for(;i<o.length&&o[i].to==s;){let k=o[i++];k.widget&&(u?(f||(f=[u])).push(k):u=k)}if(u)if(f){f.sort(g2);for(let k=0;k<f.length;k++)n(f[k],c,!!l)}else n(u,c,!!l);let p,m;if(l)m=-1,p=l,l=null;else if(c<t.childCount)m=c,p=t.child(c++);else break;for(let k=0;k<a.length;k++)a[k].to<=s&&a.splice(k--,1);for(;i<o.length&&o[i].from<=s&&o[i].to>s;)a.push(o[i++]);let g=s+p.nodeSize;if(p.isText){let k=g;i<o.length&&o[i].from<k&&(k=o[i].from);for(let w=0;w<a.length;w++)a[w].to<k&&(k=a[w].to);k<g&&(l=p.cut(k-s),p=p.cut(0,k-s),g=k,m=-1)}else for(;i<o.length&&o[i].to<g;)i++;let y=p.isInline&&!p.isLeaf?a.filter(k=>!k.inline):a.slice();r(p,y,e.forChild(s,p),m),s=g}}function k2(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function w2(t,e,n,r){for(let o=0,s=0;o<t.childCount&&s<=r;){let i=t.child(o++),a=s;if(s+=i.nodeSize,!i.isText)continue;let l=i.text;for(;o<t.childCount;){let c=t.child(o++);if(s+=c.nodeSize,!c.isText)break;l+=c.text}if(s>=n){if(s>=r&&l.slice(r-e.length-a,r-a)==e)return r-e.length;let c=a<r?l.lastIndexOf(e,r-a-1):-1;if(c>=0&&c+e.length+a>=n)return a+c;if(n==r&&l.length>=r+e.length-a&&l.slice(r-a,r-a+e.length)==e)return r}}return-1}function Fc(t,e,n,r,o){let s=[];for(let i=0,a=0;i<t.length;i++){let l=t[i],c=a,u=a+=l.size;c>=n||u<=e?s.push(l):(c<e&&s.push(l.slice(0,e-c,r)),o&&(s.push(o),o=void 0),u>n&&s.push(l.slice(n-c,l.size,r)))}return s}function jc(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let o=t.docView.nearestDesc(n.focusNode),s=o&&o.size==0,i=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(i<0)return null;let a=r.resolve(i),l,c;if(Zi(n)){for(l=i;o&&!o.node;)o=o.parent;let f=o.node;if(o&&f.isAtom&&G.isSelectable(f)&&o.parent&&!(f.isInline&&UT(n.focusNode,n.focusOffset,o.dom))){let p=o.posBefore;c=new G(i==p?a:r.resolve(p))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=i,p=i;for(let m=0;m<n.rangeCount;m++){let g=n.getRangeAt(m);f=Math.min(f,t.docView.posFromDOM(g.startContainer,g.startOffset,1)),p=Math.max(p,t.docView.posFromDOM(g.endContainer,g.endOffset,-1))}if(f<0)return null;[l,i]=p==t.state.selection.anchor?[p,f]:[f,p],a=r.resolve(i)}else l=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let u=r.resolve(l);if(!c){let f=e=="pointer"||t.state.selection.head<a.pos&&!s?1:-1;c=Wc(t,u,a,f)}return c}function Ag(t){return t.editable?t.hasFocus():Dg(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function hn(t,e=!1){let n=t.state.selection;if(Ig(t,n),!!Ag(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&He){let r=t.domSelectionRange(),o=t.domObserver.currentSelection;if(r.anchorNode&&o.anchorNode&&wr(r.anchorNode,r.anchorOffset,o.anchorNode,o.anchorOffset)){t.input.mouseDown.delayedSelectionSync=!0,t.domObserver.setCurSelection();return}}if(t.domObserver.disconnectSelection(),t.cursorWrapper)b2(t);else{let{anchor:r,head:o}=n,s,i;Ng&&!(n instanceof re)&&(n.$from.parent.inlineContent||(s=Bg(t,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(i=Bg(t,n.to))),t.docView.setSelection(r,o,t,e),Ng&&(s&&Og(s),i&&Og(i)),n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&v2(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const Ng=Je||He&&lg<63;function Bg(t,e){let{node:n,offset:r}=t.docView.domFromPos(e,0),o=r<n.childNodes.length?n.childNodes[r]:null,s=r?n.childNodes[r-1]:null;if(Je&&o&&o.contentEditable=="false")return Hc(o);if((!o||o.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(o)return Hc(o);if(s)return Hc(s)}}function Hc(t){return t.contentEditable="true",Je&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function Og(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function v2(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let n=t.domSelectionRange(),r=n.anchorNode,o=n.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=o)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Ag(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function b2(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,je(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&ot&&Pn<=11&&(n.disabled=!0,n.disabled=!1)}function Ig(t,e){if(e instanceof G){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Pg(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Pg(t)}function Pg(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Wc(t,e,n,r){return t.someProp("createSelectionBetween",o=>o(t,e,n))||re.between(e,n,r)}function Rg(t){return t.editable&&!t.hasFocus()?!1:Dg(t)}function Dg(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function S2(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return wr(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Zc(t,e){let{$anchor:n,$head:r}=t.selection,o=e>0?n.max(r):n.min(r),s=o.parent.inlineContent?o.depth?t.doc.resolve(e>0?o.after():o.before()):null:o;return s&&ie.findFrom(s,e)}function zn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function zg(t,e,n){let r=t.state.selection;if(r instanceof re)if(n.indexOf("s")>-1){let{$head:o}=r,s=o.textOffset?null:e<0?o.nodeBefore:o.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=t.state.doc.resolve(o.pos+s.nodeSize*(e<0?-1:1));return zn(t,new re(r.$anchor,i))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let o=Zc(t.state,e);return o&&o instanceof G?zn(t,o):!1}else if(!(kt&&n.indexOf("m")>-1)){let o=r.$head,s=o.textOffset?null:e<0?o.nodeBefore:o.nodeAfter,i;if(!s||s.isText)return!1;let a=e<0?o.pos-s.nodeSize:o.pos;return s.isAtom||(i=t.docView.descAt(a))&&!i.contentDOM?G.isSelectable(s)?zn(t,new G(e<0?t.state.doc.resolve(o.pos-s.nodeSize):o)):gs?zn(t,new re(t.state.doc.resolve(e<0?a:a+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof G&&r.node.isInline)return zn(t,new re(e>0?r.$to:r.$from));{let o=Zc(t.state,e);return o?zn(t,o):!1}}}function Ji(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function vs(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function go(t,e){return e<0?C2(t):x2(t)}function C2(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o,s,i=!1;for(yt&&n.nodeType==1&&r<Ji(n)&&vs(n.childNodes[r],-1)&&(i=!0);;)if(r>0){if(n.nodeType!=1)break;{let a=n.childNodes[r-1];if(vs(a,-1))o=n,s=--r;else if(a.nodeType==3)n=a,r=n.nodeValue.length;else break}}else{if($g(n))break;{let a=n.previousSibling;for(;a&&vs(a,-1);)o=n.parentNode,s=je(a),a=a.previousSibling;if(a)n=a,r=Ji(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}i?Uc(t,n,r):o&&Uc(t,o,s)}function x2(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o=Ji(n),s,i;for(;;)if(r<o){if(n.nodeType!=1)break;let a=n.childNodes[r];if(vs(a,1))s=n,i=++r;else break}else{if($g(n))break;{let a=n.nextSibling;for(;a&&vs(a,1);)s=a.parentNode,i=je(a)+1,a=a.nextSibling;if(a)n=a,r=0,o=Ji(n);else{if(n=n.parentNode,n==t.dom)break;r=o=0}}}s&&Uc(t,s,i)}function $g(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function _2(t,e){for(;t&&e==t.childNodes.length&&!ms(t);)e=je(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let n=t.childNodes[e];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=0}}function E2(t,e){for(;t&&!e&&!ms(t);)e=je(t),t=t.parentNode;for(;t&&e;){let n=t.childNodes[e-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable=="false")break;t=n,e=t.childNodes.length}}function Uc(t,e,n){if(e.nodeType!=3){let s,i;(i=_2(e,n))?(e=i,n=0):(s=E2(e,n))&&(e=s,n=s.nodeValue.length)}let r=t.domSelection();if(!r)return;if(Zi(r)){let s=document.createRange();s.setEnd(e,n),s.setStart(e,n),r.removeAllRanges(),r.addRange(s)}else r.extend&&r.extend(e,n);t.domObserver.setCurSelection();let{state:o}=t;setTimeout(()=>{t.state==o&&hn(t)},50)}function Vg(t,e){let n=t.state.doc.resolve(e);if(!(He||cg)&&n.parent.inlineContent){let o=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),i=(s.top+s.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(s.left-o.left)>1)return s.left<o.left?"ltr":"rtl"}if(e<n.end()){let s=t.coordsAtPos(e+1),i=(s.top+s.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(s.left-o.left)>1)return s.left>o.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function Lg(t,e,n){let r=t.state.selection;if(r instanceof re&&!r.empty||n.indexOf("s")>-1||kt&&n.indexOf("m")>-1)return!1;let{$from:o,$to:s}=r;if(!o.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let i=Zc(t.state,e);if(i&&i instanceof G)return zn(t,i)}if(!o.parent.inlineContent){let i=e<0?o:s,a=r instanceof dt?ie.near(i,e):ie.findFrom(i,e);return a?zn(t,a):!1}return!1}function Fg(t,e){if(!(t.state.selection instanceof re))return!0;let{$head:n,$anchor:r,empty:o}=t.state.selection;if(!n.sameParent(r))return!0;if(!o)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let i=t.state.tr;return e<0?i.delete(n.pos-s.nodeSize,n.pos):i.delete(n.pos,n.pos+s.nodeSize),t.dispatch(i),!0}return!1}function jg(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function T2(t){if(!Je||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;jg(t,r,"true"),setTimeout(()=>jg(t,r,"false"),20)}return!1}function M2(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function A2(t,e){let n=e.keyCode,r=M2(e);if(n==8||kt&&n==72&&r=="c")return Fg(t,-1)||go(t,-1);if(n==46&&!e.shiftKey||kt&&n==68&&r=="c")return Fg(t,1)||go(t,1);if(n==13||n==27)return!0;if(n==37||kt&&n==66&&r=="c"){let o=n==37?Vg(t,t.state.selection.from)=="ltr"?-1:1:-1;return zg(t,o,r)||go(t,o)}else if(n==39||kt&&n==70&&r=="c"){let o=n==39?Vg(t,t.state.selection.from)=="ltr"?1:-1:1;return zg(t,o,r)||go(t,o)}else{if(n==38||kt&&n==80&&r=="c")return Lg(t,-1,r)||go(t,-1);if(n==40||kt&&n==78&&r=="c")return T2(t)||Lg(t,1,r)||go(t,1);if(r==(kt?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function Kc(t,e){t.someProp("transformCopied",m=>{e=m(e,t)});let n=[],{content:r,openStart:o,openEnd:s}=e;for(;o>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){o--,s--;let m=r.firstChild;n.push(m.type.name,m.attrs!=m.type.defaultAttrs?m.attrs:null),r=m.content}let i=t.someProp("clipboardSerializer")||gr.fromSchema(t.state.schema),a=Gg(),l=a.createElement("div");l.appendChild(i.serializeFragment(r,{document:a}));let c=l.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=Jg[c.nodeName.toLowerCase()]);){for(let m=u.length-1;m>=0;m--){let g=a.createElement(u[m]);for(;l.firstChild;)g.appendChild(l.firstChild);l.appendChild(g),f++}c=l.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${o} ${s}${f?` -${f}`:""} ${JSON.stringify(n)}`);let p=t.someProp("clipboardTextSerializer",m=>m(e,t))||e.content.textBetween(0,e.content.size,`
|
|
76
|
-
|
|
77
|
-
`);return{dom:l,text:p,slice:e}}function Hg(t,e,n,r,o){let s=o.parent.type.spec.code,i,a;if(!n&&!e)return null;let l=!!e&&(r||s||!n);if(l){if(t.someProp("transformPastedText",p=>{e=p(e,s||r,t)}),s)return a=new L(B.from(t.state.schema.text(e.replace(/\r\n?/g,`
|
|
78
|
-
`))),0,0),t.someProp("transformPasted",p=>{a=p(a,t,!0)}),a;let f=t.someProp("clipboardTextParser",p=>p(e,o,r,t));if(f)a=f;else{let p=o.marks(),{schema:m}=t.state,g=gr.fromSchema(m);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(y=>{let k=i.appendChild(document.createElement("p"));y&&k.appendChild(g.serializeNode(m.text(y,p)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),i=I2(n),gs&&P2(i);let c=i&&i.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let p=i.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;i=p}if(a||(a=(t.someProp("clipboardParser")||t.someProp("domParser")||ln.fromSchema(t.state.schema)).parseSlice(i,{preserveWhitespace:!!(l||u),context:o,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!N2.test(p.parentNode.nodeName)?{ignore:!0}:null}})),u)a=R2(Kg(a,+u[1],+u[2]),u[4]);else if(a=L.maxOpen(B2(a.content,o),!0),a.openStart||a.openEnd){let f=0,p=0;for(let m=a.content.firstChild;f<a.openStart&&!m.type.spec.isolating;f++,m=m.firstChild);for(let m=a.content.lastChild;p<a.openEnd&&!m.type.spec.isolating;p++,m=m.lastChild);a=Kg(a,f,p)}return t.someProp("transformPasted",f=>{a=f(a,t,l)}),a}const N2=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function B2(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let o=e.node(n).contentMatchAt(e.index(n)),s,i=[];if(t.forEach(a=>{if(!i)return;let l=o.findWrapping(a.type),c;if(!l)return i=null;if(c=i.length&&s.length&&Zg(l,s,a,i[i.length-1],0))i[i.length-1]=c;else{i.length&&(i[i.length-1]=Ug(i[i.length-1],s.length));let u=Wg(a,l);i.push(u),o=o.matchType(u.type),s=l}}),i)return B.from(i)}return t}function Wg(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,B.from(t));return t}function Zg(t,e,n,r,o){if(o<t.length&&o<e.length&&t[o]==e[o]){let s=Zg(t,e,n,r.lastChild,o+1);if(s)return r.copy(r.content.replaceChild(r.childCount-1,s));if(r.contentMatchAt(r.childCount).matchType(o==t.length-1?n.type:t[o+1]))return r.copy(r.content.append(B.from(Wg(n,t,o+1))))}}function Ug(t,e){if(e==0)return t;let n=t.content.replaceChild(t.childCount-1,Ug(t.lastChild,e-1)),r=t.contentMatchAt(t.childCount).fillBefore(B.empty,!0);return t.copy(n.append(r))}function Jc(t,e,n,r,o,s){let i=e<0?t.firstChild:t.lastChild,a=i.content;return t.childCount>1&&(s=0),o<r-1&&(a=Jc(a,e,n,r,o+1,s)),o>=n&&(a=e<0?i.contentMatchAt(0).fillBefore(a,s<=o).append(a):a.append(i.contentMatchAt(i.childCount).fillBefore(B.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,i.copy(a))}function Kg(t,e,n){return e<t.openStart&&(t=new L(Jc(t.content,-1,e,t.openStart,0,t.openEnd),e,t.openEnd)),n<t.openEnd&&(t=new L(Jc(t.content,1,n,t.openEnd,0,0),t.openStart,n)),t}const Jg={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let qg=null;function Gg(){return qg||(qg=document.implementation.createHTMLDocument("title"))}let qc=null;function O2(t){let e=window.trustedTypes;return e?(qc||(qc=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:n=>n})),qc.createHTML(t)):t}function I2(t){let e=/^(\s*<meta [^>]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Gg().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),o;if((o=r&&Jg[r[1].toLowerCase()])&&(t=o.map(s=>"<"+s+">").join("")+t+o.map(s=>"</"+s+">").reverse().join("")),n.innerHTML=O2(t),o)for(let s=0;s<o.length;s++)n=n.querySelector(o[s])||n;return n}function P2(t){let e=t.querySelectorAll(He?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<e.length;n++){let r=e[n];r.childNodes.length==1&&r.textContent==" "&&r.parentNode&&r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "),r)}}function R2(t,e){if(!t.size)return t;let n=t.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return t}let{content:o,openStart:s,openEnd:i}=t;for(let a=r.length-2;a>=0;a-=2){let l=n.nodes[r[a]];if(!l||l.hasRequiredAttrs())break;o=B.from(l.create(r[a+1],o)),s++,i++}return new L(o,s,i)}const et={},tt={},D2={touchstart:!0,touchmove:!0};class z2{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function $2(t){for(let e in et){let n=et[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{L2(t,r)&&!Yc(t,r)&&(t.editable||!(r.type in tt))&&n(t,r)},D2[e]?{passive:!0}:void 0)}Je&&t.dom.addEventListener("input",()=>null),Gc(t)}function $n(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function V2(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function Gc(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>Yc(t,r))})}function Yc(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function L2(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function F2(t,e){!Yc(t,e)&&et[e.type]&&(t.editable||!(e.type in tt))&&et[e.type](t,e)}tt.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!Xg(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(un&&He&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),po&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",o=>o(t,vr(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||A2(t,n)?n.preventDefault():$n(t,"key")},tt.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)},tt.keypress=(t,e)=>{let n=e;if(Xg(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||kt&&n.metaKey)return;if(t.someProp("handleKeyPress",o=>o(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof re)||!r.$from.sameParent(r.$to)){let o=String.fromCharCode(n.charCode),s=()=>t.state.tr.insertText(o).scrollIntoView();!/[\r\n]/.test(o)&&!t.someProp("handleTextInput",i=>i(t,r.$from.pos,r.$to.pos,o,s))&&t.dispatch(s()),n.preventDefault()}};function qi(t){return{left:t.clientX,top:t.clientY}}function j2(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function Xc(t,e,n,r,o){if(r==-1)return!1;let s=t.state.doc.resolve(r);for(let i=s.depth+1;i>0;i--)if(t.someProp(e,a=>i>s.depth?a(t,n,s.nodeAfter,s.before(i),o,!0):a(t,n,s.node(i),s.before(i),o,!1)))return!0;return!1}function yo(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",!0),t.dispatch(r)}function H2(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&G.isSelectable(r)?(yo(t,new G(n)),!0):!1}function W2(t,e){if(e==-1)return!1;let n=t.state.selection,r,o;n instanceof G&&(r=n.node);let s=t.state.doc.resolve(e);for(let i=s.depth+1;i>0;i--){let a=i>s.depth?s.nodeAfter:s.node(i);if(G.isSelectable(a)){r&&n.$from.depth>0&&i>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?o=s.before(n.$from.depth):o=s.before(i);break}}return o!=null?(yo(t,G.create(t.state.doc,o)),!0):!1}function Z2(t,e,n,r,o){return Xc(t,"handleClickOn",e,n,r)||t.someProp("handleClick",s=>s(t,e,r))||(o?W2(t,n):H2(t,n))}function U2(t,e,n,r){return Xc(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",o=>o(t,e,r))}function K2(t,e,n,r){return Xc(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",o=>o(t,e,r))||J2(t,n,r)}function J2(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(yo(t,re.create(r,0,r.content.size)),!0):!1;let o=r.resolve(e);for(let s=o.depth+1;s>0;s--){let i=s>o.depth?o.nodeAfter:o.node(s),a=o.before(s);if(i.inlineContent)yo(t,re.create(r,a+1,a+1+i.content.size));else if(G.isSelectable(i))yo(t,G.create(r,a));else continue;return!0}}function Qc(t){return Gi(t)}const Yg=kt?"metaKey":"ctrlKey";et.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=Qc(t),o=Date.now(),s="singleClick";o-t.input.lastClick.time<500&&j2(n,t.input.lastClick)&&!n[Yg]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?s="doubleClick":t.input.lastClick.type=="doubleClick"&&(s="tripleClick")),t.input.lastClick={time:o,x:n.clientX,y:n.clientY,type:s,button:n.button};let i=t.posAtCoords(qi(n));i&&(s=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new q2(t,i,n,!!r)):(s=="doubleClick"?U2:K2)(t,i.pos,i.inside,n)?n.preventDefault():$n(t,"pointer"))};class q2{constructor(e,n,r,o){this.view=e,this.pos=n,this.event=r,this.flushed=o,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Yg],this.allowDefault=r.shiftKey;let s,i;if(n.inside>-1)s=e.state.doc.nodeAt(n.inside),i=n.inside;else{let u=e.state.doc.resolve(n.pos);s=u.parent,i=u.depth?u.before():0}const a=o?null:r.target,l=a?e.docView.nearestDesc(a,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:c}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof G&&c.from<=i&&c.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&yt&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),$n(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>hn(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(qi(e))),this.updateAllowDefault(e),this.allowDefault||!n?$n(this.view,"pointer"):Z2(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Je&&this.mightDrag&&!this.mightDrag.node.isAtom||He&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(yo(this.view,ie.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):$n(this.view,"pointer")}move(e){this.updateAllowDefault(e),$n(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}et.touchstart=t=>{t.input.lastTouch=Date.now(),Qc(t),$n(t,"pointer")},et.touchmove=t=>{t.input.lastTouch=Date.now(),$n(t,"pointer")},et.contextmenu=t=>Qc(t);function Xg(t,e){return t.composing?!0:Je&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const G2=un?5e3:-1;tt.compositionstart=tt.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof re&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||He&&cg&&Y2(t)))t.markCursor=t.state.storedMarks||n.marks(),Gi(t,!0),t.markCursor=null;else if(Gi(t,!e.selection.empty),yt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let o=r.focusNode,s=r.focusOffset;o&&o.nodeType==1&&s!=0;){let i=s<0?o.lastChild:o.childNodes[s-1];if(!i)break;if(i.nodeType==3){let a=t.domSelection();a&&a.collapse(i,i.nodeValue.length);break}else o=i,s=-1}}t.input.composing=!0}Qg(t,G2)};function Y2(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}tt.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Qg(t,20))};function Qg(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>Gi(t),e))}function ey(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Q2());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function X2(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=WT(e.focusNode,e.focusOffset),r=ZT(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let o=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(n==s||r==s)return s;if(!o||!o.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let i=n.pmViewDesc;if(!(!i||!i.isText(n.nodeValue)))return r}}return n||r}function Q2(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function Gi(t,e=!1){if(!(un&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),ey(t),e||t.docView&&t.docView.dirty){let n=jc(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function eM(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),o=document.createRange();o.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(o),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const bs=ot&&Pn<15||po&&qT<604;et.copy=tt.cut=(t,e)=>{let n=e,r=t.state.selection,o=n.type=="cut";if(r.empty)return;let s=bs?null:n.clipboardData,i=r.content(),{dom:a,text:l}=Kc(t,i);s?(n.preventDefault(),s.clearData(),s.setData("text/html",a.innerHTML),s.setData("text/plain",l)):eM(t,a),o&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function tM(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function nM(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let o=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Ss(t,r.value,null,o,e):Ss(t,r.textContent,r.innerHTML,o,e)},50)}function Ss(t,e,n,r,o){let s=Hg(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,o,s||L.empty)))return!0;if(!s)return!1;let i=tM(s),a=i?t.state.tr.replaceSelectionWith(i,r):t.state.tr.replaceSelection(s);return t.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ty(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}tt.paste=(t,e)=>{let n=e;if(t.composing&&!un)return;let r=bs?null:n.clipboardData,o=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&Ss(t,ty(r),r.getData("text/html"),o,n)?n.preventDefault():nM(t,n)};class ny{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const rM=kt?"altKey":"ctrlKey";function ry(t,e){let n=t.someProp("dragCopies",r=>!r(e));return n??!e[rM]}et.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let o=t.state.selection,s=o.empty?null:t.posAtCoords(qi(n)),i;if(!(s&&s.pos>=o.from&&s.pos<=(o instanceof G?o.to-1:o.to))){if(r&&r.mightDrag)i=G.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(i=G.create(t.state.doc,f.posBefore))}}let a=(i||t.state.selection).content(),{dom:l,text:c,slice:u}=Kc(t,a);(!n.dataTransfer.files.length||!He||lg>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(bs?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",bs||n.dataTransfer.setData("text/plain",c),t.dragging=new ny(u,ry(t,n),i)},et.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)},tt.dragover=tt.dragenter=(t,e)=>e.preventDefault(),tt.drop=(t,e)=>{try{oM(t,e,t.dragging)}finally{t.dragging=null}};function oM(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(qi(e));if(!r)return;let o=t.state.doc.resolve(r.pos),s=n&&n.slice;s?t.someProp("transformPasted",m=>{s=m(s,t,!1)}):s=Hg(t,ty(e.dataTransfer),bs?null:e.dataTransfer.getData("text/html"),!1,o);let i=!!(n&&ry(t,e));if(t.someProp("handleDrop",m=>m(t,e,s||L.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let a=s?Om(t.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let l=t.state.tr;if(i){let{node:m}=n;m?m.replace(l):l.deleteSelection()}let c=l.mapping.map(a),u=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=l.doc;if(u?l.replaceRangeWith(c,c,s.content.firstChild):l.replaceRange(c,c,s),l.doc.eq(f))return;let p=l.doc.resolve(c);if(u&&G.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new G(p));else{let m=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((g,y,k,w)=>m=w),l.setSelection(Wc(t,p,l.doc.resolve(m)))}t.focus(),t.dispatch(l.setMeta("uiEvent","drop"))}et.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&hn(t)},20))},et.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)},et.beforeinput=(t,e)=>{if(He&&un&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",s=>s(t,vr(8,"Backspace")))))return;let{$cursor:o}=t.state.selection;o&&o.pos>0&&t.dispatch(t.state.tr.delete(o.pos-1,o.pos).scrollIntoView())},50)}};for(let t in tt)et[t]=tt[t];function Cs(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class Yi{constructor(e,n){this.toDOM=e,this.spec=n||xr,this.side=this.spec.side||0}map(e,n,r,o){let{pos:s,deleted:i}=e.mapResult(n.from+o,this.side<0?-1:1);return i?null:new nt(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof Yi&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Cs(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Vn{constructor(e,n){this.attrs=e,this.spec=n||xr}map(e,n,r,o){let s=e.map(n.from+o,this.spec.inclusiveStart?-1:1)-r,i=e.map(n.to+o,this.spec.inclusiveEnd?1:-1)-r;return s>=i?null:new nt(s,i,this)}valid(e,n){return n.from<n.to}eq(e){return this==e||e instanceof Vn&&Cs(this.attrs,e.attrs)&&Cs(this.spec,e.spec)}static is(e){return e.type instanceof Vn}destroy(){}}class ed{constructor(e,n){this.attrs=e,this.spec=n||xr}map(e,n,r,o){let s=e.mapResult(n.from+o,1);if(s.deleted)return null;let i=e.mapResult(n.to+o,-1);return i.deleted||i.pos<=s.pos?null:new nt(s.pos-r,i.pos-r,this)}valid(e,n){let{index:r,offset:o}=e.content.findIndex(n.from),s;return o==n.from&&!(s=e.child(r)).isText&&o+s.nodeSize==n.to}eq(e){return this==e||e instanceof ed&&Cs(this.attrs,e.attrs)&&Cs(this.spec,e.spec)}destroy(){}}class nt{constructor(e,n,r){this.from=e,this.to=n,this.type=r}copy(e,n){return new nt(e,n,this.type)}eq(e,n=0){return this.type.eq(e.type)&&this.from+n==e.from&&this.to+n==e.to}map(e,n,r){return this.type.map(e,this,n,r)}static widget(e,n,r){return new nt(e,e,new Yi(n,r))}static inline(e,n,r,o){return new nt(e,n,new Vn(r,o))}static node(e,n,r,o){return new nt(e,n,new ed(r,o))}get spec(){return this.type.spec}get inline(){return this.type instanceof Vn}get widget(){return this.type instanceof Yi}}const ko=[],xr={};class Ce{constructor(e,n){this.local=e.length?e:ko,this.children=n.length?n:ko}static create(e,n){return n.length?Xi(n,e,0,xr):qe}find(e,n,r){let o=[];return this.findInner(e??0,n??1e9,o,0,r),o}findInner(e,n,r,o,s){for(let i=0;i<this.local.length;i++){let a=this.local[i];a.from<=n&&a.to>=e&&(!s||s(a.spec))&&r.push(a.copy(a.from+o,a.to+o))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<n&&this.children[i+1]>e){let a=this.children[i]+1;this.children[i+2].findInner(e-a,n-a,r,o+a,s)}}map(e,n,r){return this==qe||e.maps.length==0?this:this.mapInner(e,n,0,0,r||xr)}mapInner(e,n,r,o,s){let i;for(let a=0;a<this.local.length;a++){let l=this.local[a].map(e,r,o);l&&l.type.valid(n,l)?(i||(i=[])).push(l):s.onRemove&&s.onRemove(this.local[a].spec)}return this.children.length?sM(this.children,i||[],e,n,r,o,s):i?new Ce(i.sort(_r),ko):qe}add(e,n){return n.length?this==qe?Ce.create(e,n):this.addInner(e,n,0):this}addInner(e,n,r){let o,s=0;e.forEach((a,l)=>{let c=l+r,u;if(u=sy(n,a,c)){for(o||(o=this.children.slice());s<o.length&&o[s]<l;)s+=3;o[s]==l?o[s+2]=o[s+2].addInner(a,u,c+1):o.splice(s,0,l,l+a.nodeSize,Xi(u,a,c+1,xr)),s+=3}});let i=oy(s?iy(n):n,-r);for(let a=0;a<i.length;a++)i[a].type.valid(e,i[a])||i.splice(a--,1);return new Ce(i.length?this.local.concat(i).sort(_r):this.local,o||this.children)}remove(e){return e.length==0||this==qe?this:this.removeInner(e,0)}removeInner(e,n){let r=this.children,o=this.local;for(let s=0;s<r.length;s+=3){let i,a=r[s]+n,l=r[s+1]+n;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>a&&f.to<l&&(e[u]=null,(i||(i=[])).push(f));if(!i)continue;r==this.children&&(r=this.children.slice());let c=r[s+2].removeInner(i,a+1);c!=qe?r[s+2]=c:(r.splice(s,3),s-=3)}if(o.length){for(let s=0,i;s<e.length;s++)if(i=e[s])for(let a=0;a<o.length;a++)o[a].eq(i,n)&&(o==this.local&&(o=this.local.slice()),o.splice(a--,1))}return r==this.children&&o==this.local?this:o.length||r.length?new Ce(o,r):qe}forChild(e,n){if(this==qe)return this;if(n.isLeaf)return Ce.empty;let r,o;for(let a=0;a<this.children.length;a+=3)if(this.children[a]>=e){this.children[a]==e&&(r=this.children[a+2]);break}let s=e+1,i=s+n.content.size;for(let a=0;a<this.local.length;a++){let l=this.local[a];if(l.from<i&&l.to>s&&l.type instanceof Vn){let c=Math.max(s,l.from)-s,u=Math.min(i,l.to)-s;c<u&&(o||(o=[])).push(l.copy(c,u))}}if(o){let a=new Ce(o.sort(_r),ko);return r?new Ln([a,r]):a}return r||qe}eq(e){if(this==e)return!0;if(!(e instanceof Ce)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let n=0;n<this.local.length;n++)if(!this.local[n].eq(e.local[n]))return!1;for(let n=0;n<this.children.length;n+=3)if(this.children[n]!=e.children[n]||this.children[n+1]!=e.children[n+1]||!this.children[n+2].eq(e.children[n+2]))return!1;return!0}locals(e){return td(this.localsInner(e))}localsInner(e){if(this==qe)return ko;if(e.inlineContent||!this.local.some(Vn.is))return this.local;let n=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Vn||n.push(this.local[r]);return n}forEachSet(e){e(this)}}Ce.empty=new Ce([],[]),Ce.removeOverlap=td;const qe=Ce.empty;class Ln{constructor(e){this.members=e}map(e,n){const r=this.members.map(o=>o.map(e,n,xr));return Ln.from(r)}forChild(e,n){if(n.isLeaf)return Ce.empty;let r=[];for(let o=0;o<this.members.length;o++){let s=this.members[o].forChild(e,n);s!=qe&&(s instanceof Ln?r=r.concat(s.members):r.push(s))}return Ln.from(r)}eq(e){if(!(e instanceof Ln)||e.members.length!=this.members.length)return!1;for(let n=0;n<this.members.length;n++)if(!this.members[n].eq(e.members[n]))return!1;return!0}locals(e){let n,r=!0;for(let o=0;o<this.members.length;o++){let s=this.members[o].localsInner(e);if(s.length)if(!n)n=s;else{r&&(n=n.slice(),r=!1);for(let i=0;i<s.length;i++)n.push(s[i])}}return n?td(r?n:n.sort(_r)):ko}static from(e){switch(e.length){case 0:return qe;case 1:return e[0];default:return new Ln(e.every(n=>n instanceof Ce)?e:e.reduce((n,r)=>n.concat(r instanceof Ce?r:r.members),[]))}}forEachSet(e){for(let n=0;n<this.members.length;n++)this.members[n].forEachSet(e)}}function sM(t,e,n,r,o,s,i){let a=t.slice();for(let c=0,u=s;c<n.maps.length;c++){let f=0;n.maps[c].forEach((p,m,g,y)=>{let k=y-g-(m-p);for(let w=0;w<a.length;w+=3){let v=a[w+1];if(v<0||p>v+u-f)continue;let b=a[w]+u-f;m>=b?a[w+1]=p<=b?-2:-1:p>=u&&k&&(a[w]+=k,a[w+1]+=k)}f+=k}),u=n.maps[c].map(u,-1)}let l=!1;for(let c=0;c<a.length;c+=3)if(a[c+1]<0){if(a[c+1]==-2){l=!0,a[c+1]=-1;continue}let u=n.map(t[c]+s),f=u-o;if(f<0||f>=r.content.size){l=!0;continue}let p=n.map(t[c+1]+s,-1),m=p-o,{index:g,offset:y}=r.content.findIndex(f),k=r.maybeChild(g);if(k&&y==f&&y+k.nodeSize==m){let w=a[c+2].mapInner(n,k,u+1,t[c]+s+1,i);w!=qe?(a[c]=f,a[c+1]=m,a[c+2]=w):(a[c+1]=-2,l=!0)}else l=!0}if(l){let c=iM(a,t,e,n,o,s,i),u=Xi(c,r,0,i);e=u.local;for(let f=0;f<a.length;f+=3)a[f+1]<0&&(a.splice(f,3),f-=3);for(let f=0,p=0;f<u.children.length;f+=3){let m=u.children[f];for(;p<a.length&&a[p]<m;)p+=3;a.splice(p,0,u.children[f],u.children[f+1],u.children[f+2])}}return new Ce(e.sort(_r),a)}function oy(t,e){if(!e||!t.length)return t;let n=[];for(let r=0;r<t.length;r++){let o=t[r];n.push(new nt(o.from+e,o.to+e,o.type))}return n}function iM(t,e,n,r,o,s,i){function a(l,c){for(let u=0;u<l.local.length;u++){let f=l.local[u].map(r,o,c);f?n.push(f):i.onRemove&&i.onRemove(l.local[u].spec)}for(let u=0;u<l.children.length;u+=3)a(l.children[u+2],l.children[u]+c+1)}for(let l=0;l<t.length;l+=3)t[l+1]==-1&&a(t[l+2],e[l]+s+1);return n}function sy(t,e,n){if(e.isLeaf)return null;let r=n+e.nodeSize,o=null;for(let s=0,i;s<t.length;s++)(i=t[s])&&i.from>n&&i.to<r&&((o||(o=[])).push(i),t[s]=null);return o}function iy(t){let e=[];for(let n=0;n<t.length;n++)t[n]!=null&&e.push(t[n]);return e}function Xi(t,e,n,r){let o=[],s=!1;e.forEach((a,l)=>{let c=sy(t,a,l+n);if(c){s=!0;let u=Xi(c,a,n+l+1,r);u!=qe&&o.push(l,l+a.nodeSize,u)}});let i=oy(s?iy(t):t,-n).sort(_r);for(let a=0;a<i.length;a++)i[a].type.valid(e,i[a])||(r.onRemove&&r.onRemove(i[a].spec),i.splice(a--,1));return i.length||o.length?new Ce(i,o):qe}function _r(t,e){return t.from-e.from||t.to-e.to}function td(t){let e=t;for(let n=0;n<e.length-1;n++){let r=e[n];if(r.from!=r.to)for(let o=n+1;o<e.length;o++){let s=e[o];if(s.from==r.from){s.to!=r.to&&(e==t&&(e=t.slice()),e[o]=s.copy(s.from,r.to),ay(e,o+1,s.copy(r.to,s.to)));continue}else{s.from<r.to&&(e==t&&(e=t.slice()),e[n]=r.copy(r.from,s.from),ay(e,o,r.copy(s.from,r.to)));break}}}return e}function ay(t,e,n){for(;e<t.length&&_r(n,t[e])>0;)e++;t.splice(e,0,n)}function nd(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=qe&&e.push(r)}),t.cursorWrapper&&e.push(Ce.create(t.state.doc,[t.cursorWrapper.deco])),Ln.from(e)}const aM={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},lM=ot&&Pn<=11;class cM{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class dM{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new cM,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let o=0;o<r.length;o++)this.queue.push(r[o]);ot&&Pn<=11&&r.some(o=>o.type=="childList"&&o.removedNodes.length||o.type=="characterData"&&o.oldValue.length>o.target.nodeValue.length)?this.flushSoon():Je&&e.composing&&r.some(o=>o.type=="childList"&&o.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),lM&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,aM)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let n=0;n<e.length;n++)this.queue.push(e[n]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Rg(this.view)){if(this.suppressingSelectionUpdates)return hn(this.view);if(ot&&Pn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&wr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let n=new Set,r;for(let s=e.focusNode;s;s=ho(s))n.add(s);for(let s=e.anchorNode;s;s=ho(s))if(n.has(s)){r=s;break}let o=r&&this.view.docView.nearestDesc(r);if(o&&o.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),o=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Rg(e)&&!this.ignoreSelectionChange(r),s=-1,i=-1,a=!1,l=[];if(e.editable)for(let u=0;u<n.length;u++){let f=this.registerMutation(n[u],l);f&&(s=s<0?f.from:Math.min(f.from,s),i=i<0?f.to:Math.max(f.to,i),f.typeOver&&(a=!0))}if(l.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of l)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(yt&&l.length){let u=l.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,p]=u;f.parentNode&&f.parentNode.parentNode==p.parentNode?p.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let p of u){let m=p.parentNode;m&&m.nodeName=="LI"&&(!f||hM(e,f)!=m)&&p.remove()}}}let c=null;s<0&&o&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Zi(r)&&(c=jc(e))&&c.eq(ie.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,hn(e),this.currentSelection.set(r),e.scrollToSelection()):(s>-1||o)&&(s>-1&&(e.docView.markDirty(s,i),uM(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,pM(e,l)),this.handleDOMChange(s,i,a,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||hn(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];n.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let o=e.previousSibling,s=e.nextSibling;if(ot&&Pn<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:p}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(o=f),(!p||Array.prototype.indexOf.call(e.addedNodes,p)<0)&&(s=p)}let i=o&&o.parentNode==e.target?je(o)+1:0,a=r.localPosFromDOM(e.target,i,-1),l=s&&s.parentNode==e.target?je(s):e.target.childNodes.length,c=r.localPosFromDOM(e.target,l,1);return{from:a,to:c}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let ly=new WeakMap,cy=!1;function uM(t){if(!ly.has(t)&&(ly.set(t,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace)!==-1)){if(t.requiresGeckoHackNode=yt,cy)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),cy=!0}}function dy(t,e){let n=e.startContainer,r=e.startOffset,o=e.endContainer,s=e.endOffset,i=t.domAtPos(t.state.selection.anchor);return wr(i.node,i.offset,o,s)&&([n,r,o,s]=[o,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:s}}function fM(t,e){if(e.getComposedRanges){let o=e.getComposedRanges(t.root)[0];if(o)return dy(t,o)}let n;function r(o){o.preventDefault(),o.stopImmediatePropagation(),n=o.getTargetRanges()[0]}return t.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),t.dom.removeEventListener("beforeinput",r,!0),n?dy(t,n):null}function hM(t,e){for(let n=e.parentNode;n&&n!=t.dom;n=n.parentNode){let r=t.docView.nearestDesc(n,!0);if(r&&r.node.isBlock)return n}return null}function pM(t,e){var n;let{focusNode:r,focusOffset:o}=t.domSelectionRange();for(let s of e)if(((n=s.parentNode)===null||n===void 0?void 0:n.nodeName)=="TR"){let i=s.nextSibling;for(;i&&i.nodeName!="TD"&&i.nodeName!="TH";)i=i.nextSibling;if(i){let a=i;for(;;){let l=a.firstChild;if(!l||l.nodeType!=1||l.contentEditable=="false"||/^(BR|IMG)$/.test(l.nodeName))break;a=l}a.insertBefore(s,a.firstChild),r==s&&t.domSelection().collapse(s,o)}else s.parentNode.removeChild(s)}}function mM(t,e,n){let{node:r,fromOffset:o,toOffset:s,from:i,to:a}=t.docView.parseRange(e,n),l=t.domSelectionRange(),c,u=l.anchorNode;if(u&&t.dom.contains(u.nodeType==1?u:u.parentNode)&&(c=[{node:u,offset:l.anchorOffset}],Zi(l)||c.push({node:l.focusNode,offset:l.focusOffset})),He&&t.input.lastKeyCode===8)for(let k=s;k>o;k--){let w=r.childNodes[k-1],v=w.pmViewDesc;if(w.nodeName=="BR"&&!v){s=k;break}if(!v||v.size)break}let f=t.state.doc,p=t.someProp("domParser")||ln.fromSchema(t.state.schema),m=f.resolve(i),g=null,y=p.parse(r,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:o,to:s,preserveWhitespace:m.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:gM,context:m});if(c&&c[0].pos!=null){let k=c[0].pos,w=c[1]&&c[1].pos;w==null&&(w=k),g={anchor:k+i,head:w+i}}return{doc:y,sel:g,from:i,to:a}}function gM(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Je&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Je&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const yM=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function kM(t,e,n,r,o){let s=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let x=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,T=jc(t,x);if(T&&!t.state.selection.eq(T)){if(He&&un&&t.input.lastKeyCode===13&&Date.now()-100<t.input.lastKeyCodeTime&&t.someProp("handleKeyDown",I=>I(t,vr(13,"Enter"))))return;let N=t.state.tr.setSelection(T);x=="pointer"?N.setMeta("pointer",!0):x=="key"&&N.scrollIntoView(),s&&N.setMeta("composition",s),t.dispatch(N)}return}let i=t.state.doc.resolve(e),a=i.sharedDepth(n);e=i.before(a+1),n=t.state.doc.resolve(n).after(a+1);let l=t.state.selection,c=mM(t,e,n),u=t.state.doc,f=u.slice(c.from,c.to),p,m;t.input.lastKeyCode===8&&Date.now()-100<t.input.lastKeyCodeTime?(p=t.state.selection.to,m="end"):(p=t.state.selection.from,m="start"),t.input.lastKeyCode=null;let g=bM(f.content,c.doc.content,c.from,p,m);if(g&&t.input.domChangeCount++,(po&&t.input.lastIOSEnter>Date.now()-225||un)&&o.some(x=>x.nodeType==1&&!yM.test(x.nodeName))&&(!g||g.endA>=g.endB)&&t.someProp("handleKeyDown",x=>x(t,vr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!g)if(r&&l instanceof re&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))g={start:l.from,endA:l.to,endB:l.to};else{if(c.sel){let x=uy(t,t.state.doc,c.sel);if(x&&!x.eq(t.state.selection)){let T=t.state.tr.setSelection(x);s&&T.setMeta("composition",s),t.dispatch(T)}}return}t.state.selection.from<t.state.selection.to&&g.start==g.endB&&t.state.selection instanceof re&&(g.start>t.state.selection.from&&g.start<=t.state.selection.from+2&&t.state.selection.from>=c.from?g.start=t.state.selection.from:g.endA<t.state.selection.to&&g.endA>=t.state.selection.to-2&&t.state.selection.to<=c.to&&(g.endB+=t.state.selection.to-g.endA,g.endA=t.state.selection.to)),ot&&Pn<=11&&g.endB==g.start+1&&g.endA==g.start&&g.start>c.from&&c.doc.textBetween(g.start-c.from-1,g.start-c.from+1)==" "&&(g.start--,g.endA--,g.endB--);let y=c.doc.resolveNoCache(g.start-c.from),k=c.doc.resolveNoCache(g.endB-c.from),w=u.resolve(g.start),v=y.sameParent(k)&&y.parent.inlineContent&&w.end()>=g.endA;if((po&&t.input.lastIOSEnter>Date.now()-225&&(!v||o.some(x=>x.nodeName=="DIV"||x.nodeName=="P"))||!v&&y.pos<c.doc.content.size&&(!y.sameParent(k)||!y.parent.inlineContent)&&y.pos<k.pos&&!/\S/.test(c.doc.textBetween(y.pos,k.pos,"","")))&&t.someProp("handleKeyDown",x=>x(t,vr(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>g.start&&vM(u,g.start,g.endA,y,k)&&t.someProp("handleKeyDown",x=>x(t,vr(8,"Backspace")))){un&&He&&t.domObserver.suppressSelectionUpdates();return}He&&g.endB==g.start&&(t.input.lastChromeDelete=Date.now()),un&&!v&&y.start()!=k.start()&&k.parentOffset==0&&y.depth==k.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==g.endA&&(g.endB-=2,k=c.doc.resolveNoCache(g.endB-c.from),setTimeout(()=>{t.someProp("handleKeyDown",function(x){return x(t,vr(13,"Enter"))})},20));let b=g.start,S=g.endA,C=x=>{let T=x||t.state.tr.replace(b,S,c.doc.slice(g.start-c.from,g.endB-c.from));if(c.sel){let N=uy(t,T.doc,c.sel);N&&!(He&&t.composing&&N.empty&&(g.start!=g.endB||t.input.lastChromeDelete<Date.now()-100)&&(N.head==b||N.head==T.mapping.map(S)-1)||ot&&N.empty&&N.head==b)&&T.setSelection(N)}return s&&T.setMeta("composition",s),T.scrollIntoView()},_;if(v)if(y.pos==k.pos){ot&&Pn<=11&&y.parentOffset==0&&(t.domObserver.suppressSelectionUpdates(),setTimeout(()=>hn(t),20));let x=C(t.state.tr.delete(b,S)),T=u.resolve(g.start).marksAcross(u.resolve(g.endA));T&&x.ensureMarks(T),t.dispatch(x)}else if(g.endA==g.endB&&(_=wM(y.parent.content.cut(y.parentOffset,k.parentOffset),w.parent.content.cut(w.parentOffset,g.endA-w.start())))){let x=C(t.state.tr);_.type=="add"?x.addMark(b,S,_.mark):x.removeMark(b,S,_.mark),t.dispatch(x)}else if(y.parent.child(y.index()).isText&&y.index()==k.index()-(k.textOffset?0:1)){let x=y.parent.textBetween(y.parentOffset,k.parentOffset),T=()=>C(t.state.tr.insertText(x,b,S));t.someProp("handleTextInput",N=>N(t,b,S,x,T))||t.dispatch(T())}else t.dispatch(C());else t.dispatch(C())}function uy(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:Wc(t,e.resolve(n.anchor),e.resolve(n.head))}function wM(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,o=n,s=r,i,a,l;for(let u=0;u<r.length;u++)o=r[u].removeFromSet(o);for(let u=0;u<n.length;u++)s=n[u].removeFromSet(s);if(o.length==1&&s.length==0)a=o[0],i="add",l=u=>u.mark(a.addToSet(u.marks));else if(o.length==0&&s.length==1)a=s[0],i="remove",l=u=>u.mark(a.removeFromSet(u.marks));else return null;let c=[];for(let u=0;u<e.childCount;u++)c.push(l(e.child(u)));if(B.from(c).eq(t))return{mark:a,type:i}}function vM(t,e,n,r,o){if(n-e<=o.pos-r.pos||rd(r,!0,!1)<o.pos)return!1;let s=t.resolve(e);if(!r.parent.isTextblock){let a=s.nodeAfter;return a!=null&&n==e+a.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let i=t.resolve(rd(s,!0,!0));return!i.parent.isTextblock||i.pos>n||rd(i,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(i.parent.content)}function rd(t,e,n){let r=t.depth,o=e?t.end():t.pos;for(;r>0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,o++,e=!1;if(n){let s=t.node(r).maybeChild(t.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,o++}return o}function bM(t,e,n,r,o){let s=t.findDiffStart(e,n);if(s==null)return null;let{a:i,b:a}=t.findDiffEnd(e,n+t.size,n+e.size);if(o=="end"){let l=Math.max(0,s-Math.min(i,a));r-=i+l-s}if(i<s&&t.size<e.size){let l=r<=s&&r>=i?s-r:0;s-=l,s&&s<e.size&&fy(e.textBetween(s-1,s+1))&&(s+=l?1:-1),a=s+(a-i),i=s}else if(a<s){let l=r<=s&&r>=a?s-r:0;s-=l,s&&s<t.size&&fy(t.textBetween(s-1,s+1))&&(s+=l?1:-1),i=s+(i-a),a=s}return{start:s,endA:i,endB:a}}function fy(t){if(t.length!=2)return!1;let e=t.charCodeAt(0),n=t.charCodeAt(1);return e>=56320&&e<=57343&&n>=55296&&n<=56319}class hy{constructor(e,n){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new z2,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(ky),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=gy(this),my(this),this.nodeViews=yy(this),this.docView=Cg(this.state.doc,py(this),nd(this),this.dom,this),this.domObserver=new dM(this,(r,o,s,i)=>kM(this,r,o,s,i)),this.domObserver.start(),$2(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Gc(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ky),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let o=this.state,s=!1,i=!1;e.storedMarks&&this.composing&&(ey(this),i=!0),this.state=e;let a=o.plugins!=e.plugins||this._props.plugins!=n.plugins;if(a||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let m=yy(this);CM(m,this.nodeViews)&&(this.nodeViews=m,s=!0)}(a||n.handleDOMEvents!=this._props.handleDOMEvents)&&Gc(this),this.editable=gy(this),my(this);let l=nd(this),c=py(this),u=o.plugins!=e.plugins&&!o.doc.eq(e.doc)?"reset":e.scrollToSelection>o.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,c,l);(f||!e.selection.eq(o.selection))&&(i=!0);let p=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&XT(this);if(i){this.domObserver.stop();let m=f&&(ot||He)&&!this.composing&&!o.selection.empty&&!e.selection.empty&&SM(o.selection,e.selection);if(f){let g=He?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=X2(this)),(s||!this.docView.update(e.doc,c,l,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Cg(e.doc,c,l,this.dom,this)),g&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(m=!0)}m||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&S2(this))?hn(this,m):(Ig(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(o),!((r=this.dragging)===null||r===void 0)&&r.node&&!o.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,o),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():p&&QT(p)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof G){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&dg(this,n.getBoundingClientRect(),e)}else dg(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let n=0;n<this.directPlugins.length;n++){let r=this.directPlugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let n=0;n<this.state.plugins.length;n++){let r=this.state.plugins[n];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let n=0;n<this.pluginViews.length;n++){let r=this.pluginViews[n];r.update&&r.update(this,e)}}updateDraggedNode(e,n){let r=e.node,o=-1;if(this.state.doc.nodeAt(r.from)==r.node)o=r.from;else{let s=r.from+(this.state.doc.content.size-n.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==r.node&&(o=s)}this.dragging=new ny(e.slice,e.move,o<0?void 0:G.create(this.state.doc,o))}someProp(e,n){let r=this._props&&this._props[e],o;if(r!=null&&(o=n?n(r):r))return o;for(let i=0;i<this.directPlugins.length;i++){let a=this.directPlugins[i].props[e];if(a!=null&&(o=n?n(a):a))return o}let s=this.state.plugins;if(s)for(let i=0;i<s.length;i++){let a=s[i].props[e];if(a!=null&&(o=n?n(a):a))return o}}hasFocus(){if(ot){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&e2(this.dom),hn(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let n=this.dom.parentNode;n;n=n.parentNode)if(n.nodeType==9||n.nodeType==11&&n.host)return n.getSelection||(Object.getPrototypeOf(n).getSelection=()=>n.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return s2(this,e)}coordsAtPos(e,n=1){return gg(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let o=this.docView.posFromDOM(e,n,r);if(o==null)throw new RangeError("DOM position not inside the editor");return o}endOfTextblock(e,n){return d2(this,n||this.state,e)}pasteHTML(e,n){return Ss(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return Ss(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return Kc(this,e)}destroy(){this.docView&&(V2(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],nd(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,jT())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return F2(this,e)}domSelectionRange(){let e=this.domSelection();return e?Je&&this.root.nodeType===11&&KT(this.dom.ownerDocument)==this.dom&&fM(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}hy.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function py(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[nt.node(0,t.state.doc.content.size,e)]}function my(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:nt.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function gy(t){return!t.someProp("editable",e=>e(t.state)===!1)}function SM(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function yy(t){let e=Object.create(null);function n(r){for(let o in r)Object.prototype.hasOwnProperty.call(e,o)||(e[o]=r[o])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function CM(t,e){let n=0,r=0;for(let o in t){if(t[o]!=e[o])return!0;n++}for(let o in e)r++;return n!=r}function ky(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var Fn={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Qi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},xM=typeof navigator<"u"&&/Mac/.test(navigator.platform),_M=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),We=0;We<10;We++)Fn[48+We]=Fn[96+We]=String(We);for(var We=1;We<=24;We++)Fn[We+111]="F"+We;for(var We=65;We<=90;We++)Fn[We]=String.fromCharCode(We+32),Qi[We]=String.fromCharCode(We);for(var od in Fn)Qi.hasOwnProperty(od)||(Qi[od]=Fn[od]);function EM(t){var e=xM&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||_M&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?Qi:Fn)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}const TM=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),MM=typeof navigator<"u"&&/Win/.test(navigator.platform);function AM(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,o,s,i;for(let a=0;a<e.length-1;a++){let l=e[a];if(/^(cmd|meta|m)$/i.test(l))i=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))o=!0;else if(/^s(hift)?$/i.test(l))s=!0;else if(/^mod$/i.test(l))TM?i=!0:o=!0;else throw new Error("Unrecognized modifier name: "+l)}return r&&(n="Alt-"+n),o&&(n="Ctrl-"+n),i&&(n="Meta-"+n),s&&(n="Shift-"+n),n}function NM(t){let e=Object.create(null);for(let n in t)e[AM(n)]=t[n];return e}function sd(t,e,n=!0){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n&&e.shiftKey&&(t="Shift-"+t),t}function BM(t){return new Oe({props:{handleKeyDown:wy(t)}})}function wy(t){let e=NM(t);return function(n,r){let o=EM(r),s,i=e[sd(o,r)];if(i&&i(n.state,n.dispatch,n))return!0;if(o.length==1&&o!=" "){if(r.shiftKey){let a=e[sd(o,r,!1)];if(a&&a(n.state,n.dispatch,n))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(MM&&r.ctrlKey&&r.altKey)&&(s=Fn[r.keyCode])&&s!=o){let a=e[sd(s,r)];if(a&&a(n.state,n.dispatch,n))return!0}}return!1}}var OM=Object.defineProperty,id=(t,e)=>{for(var n in e)OM(t,n,{get:e[n],enumerable:!0})};function ea(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:o}=n,{storedMarks:s}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return o},get tr(){return r=n.selection,o=n.doc,s=n.storedMarks,n}}}var ta=class{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:e,state:n}=this,{view:r}=e,{tr:o}=n,s=this.buildProps(o);return Object.fromEntries(Object.entries(t).map(([i,a])=>[i,(...c)=>{const u=a(...c)(s);return!o.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(o),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,e=!0){const{rawCommands:n,editor:r,state:o}=this,{view:s}=r,i=[],a=!!t,l=t||o.tr,c=()=>(!a&&e&&!l.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(l),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(n).map(([f,p])=>[f,(...g)=>{const y=this.buildProps(l,e),k=p(...g)(y);return i.push(k),u}])),run:c};return u}createCan(t){const{rawCommands:e,state:n}=this,r=!1,o=t||n.tr,s=this.buildProps(o,r);return{...Object.fromEntries(Object.entries(e).map(([a,l])=>[a,(...c)=>l(...c)({...s,dispatch:void 0})])),chain:()=>this.createChain(o,r)}}buildProps(t,e=!0){const{rawCommands:n,editor:r,state:o}=this,{view:s}=r,i={tr:t,editor:r,view:s,state:ea({state:o,transaction:t}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(t,e),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(n).map(([a,l])=>[a,(...c)=>l(...c)(i)]))}};return i}},vy={};id(vy,{blur:()=>IM,clearContent:()=>PM,clearNodes:()=>RM,command:()=>DM,createParagraphNear:()=>zM,cut:()=>$M,deleteCurrentNode:()=>VM,deleteNode:()=>LM,deleteRange:()=>FM,deleteSelection:()=>jM,enter:()=>HM,exitCode:()=>WM,extendMarkRange:()=>ZM,first:()=>UM,focus:()=>JM,forEach:()=>qM,insertContent:()=>GM,insertContentAt:()=>QM,joinBackward:()=>nA,joinDown:()=>tA,joinForward:()=>rA,joinItemBackward:()=>oA,joinItemForward:()=>sA,joinTextblockBackward:()=>iA,joinTextblockForward:()=>aA,joinUp:()=>eA,keyboardShortcut:()=>cA,lift:()=>dA,liftEmptyBlock:()=>uA,liftListItem:()=>fA,newlineInCode:()=>hA,resetAttributes:()=>pA,scrollIntoView:()=>mA,selectAll:()=>gA,selectNodeBackward:()=>yA,selectNodeForward:()=>kA,selectParentNode:()=>wA,selectTextblockEnd:()=>vA,selectTextblockStart:()=>bA,setContent:()=>SA,setMark:()=>FA,setMeta:()=>jA,setNode:()=>HA,setNodeSelection:()=>WA,setTextDirection:()=>ZA,setTextSelection:()=>UA,sinkListItem:()=>KA,splitBlock:()=>JA,splitListItem:()=>qA,toggleList:()=>GA,toggleMark:()=>YA,toggleNode:()=>XA,toggleWrap:()=>QA,undoInputRule:()=>eN,unsetAllMarks:()=>tN,unsetMark:()=>nN,unsetTextDirection:()=>rN,updateAttributes:()=>oN,wrapIn:()=>sN,wrapInList:()=>iN});var IM=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),PM=(t=!0)=>({commands:e})=>e.setContent("",{emitUpdate:t}),RM=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:o}=r;return n&&o.forEach(({$from:s,$to:i})=>{t.doc.nodesBetween(s.pos,i.pos,(a,l)=>{if(a.type.isText)return;const{doc:c,mapping:u}=e,f=c.resolve(u.map(l)),p=c.resolve(u.map(l+a.nodeSize)),m=f.blockRange(p);if(!m)return;const g=io(m);if(a.type.isTextblock){const{defaultType:y}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(m.start,y)}(g||g===0)&&e.lift(m,g)})}),!0},DM=t=>e=>t(e),zM=()=>({state:t,dispatch:e})=>eg(t,e),$M=(t,e)=>({editor:n,tr:r})=>{const{state:o}=n,s=o.doc.slice(t.from,t.to);r.deleteRange(t.from,t.to);const i=r.mapping.map(e);return r.insert(i,s.content),r.setSelection(new re(r.doc.resolve(Math.max(i-1,0)))),!0},VM=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const o=t.selection.$anchor;for(let s=o.depth;s>0;s-=1)if(o.node(s).type===r.type){if(e){const a=o.before(s),l=o.after(s);t.delete(a,l).scrollIntoView()}return!0}return!1};function ze(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}var LM=t=>({tr:e,state:n,dispatch:r})=>{const o=ze(t,n.schema),s=e.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===o){if(r){const l=s.before(i),c=s.after(i);e.delete(l,c).scrollIntoView()}return!0}return!1},FM=t=>({tr:e,dispatch:n})=>{const{from:r,to:o}=t;return n&&e.delete(r,o),!0},jM=()=>({state:t,dispatch:e})=>Ac(t,e),HM=()=>({commands:t})=>t.keyboardShortcut("Enter"),WM=()=>({state:t,dispatch:e})=>TT(t,e);function ad(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function na(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(o=>n.strict?e[o]===t[o]:ad(e[o])?e[o].test(t[o]):e[o]===t[o]):!0}function by(t,e,n={}){return t.find(r=>r.type===e&&na(Object.fromEntries(Object.keys(n).map(o=>[o,r.attrs[o]])),n))}function Sy(t,e,n={}){return!!by(t,e,n)}function ld(t,e,n){var r;if(!t||!e)return;let o=t.parent.childAfter(t.parentOffset);if((!o.node||!o.node.marks.some(u=>u.type===e))&&(o=t.parent.childBefore(t.parentOffset)),!o.node||!o.node.marks.some(u=>u.type===e)||(n=n||((r=o.node.marks[0])==null?void 0:r.attrs),!by([...o.node.marks],e,n)))return;let i=o.index,a=t.start()+o.offset,l=i+1,c=a+o.node.nodeSize;for(;i>0&&Sy([...t.parent.child(i-1).marks],e,n);)i-=1,a-=t.parent.child(i).nodeSize;for(;l<t.parent.childCount&&Sy([...t.parent.child(l).marks],e,n);)c+=t.parent.child(l).nodeSize,l+=1;return{from:a,to:c}}function pn(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}var ZM=(t,e={})=>({tr:n,state:r,dispatch:o})=>{const s=pn(t,r.schema),{doc:i,selection:a}=n,{$from:l,from:c,to:u}=a;if(o){const f=ld(l,s,e);if(f&&f.from<=c&&f.to>=u){const p=re.create(i,f.from,f.to);n.setSelection(p)}}return!0},UM=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function Cy(t){return t instanceof re}function Er(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function xy(t,e=null){if(!e)return null;const n=ie.atStart(t),r=ie.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const o=n.from,s=r.to;return e==="all"?re.create(t,Er(0,o,s),Er(t.content.size,o,s)):re.create(t,Er(e,o,s),Er(e,o,s))}function _y(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function ra(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function KM(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var JM=(t=null,e={})=>({editor:n,view:r,tr:o,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(ra()||_y())&&r.dom.focus(),KM()&&!ra()&&!_y()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&t===null||t===!1)return!0}catch{return!1}if(s&&t===null&&!Cy(n.state.selection))return i(),!0;const a=xy(o.doc,t)||n.state.selection,l=n.state.selection.eq(a);return s&&(l||o.setSelection(a),l&&o.storedMarks&&o.setStoredMarks(o.storedMarks),i()),!0},qM=(t,e)=>n=>t.every((r,o)=>e(r,{...n,index:o})),GM=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),Ey=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const r=e[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?t.removeChild(r):r.nodeType===1&&Ey(r)}return t};function xs(t){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`<body>${t}</body>`,n=new window.DOMParser().parseFromString(e,"text/html").body;return Ey(n)}function _s(t,e,n){if(t instanceof an||t instanceof B)return t;n={slice:!0,parseOptions:{},...n};const r=typeof t=="object"&&t!==null,o=typeof t=="string";if(r)try{if(Array.isArray(t)&&t.length>0)return B.fromArray(t.map(a=>e.nodeFromJSON(a)));const i=e.nodeFromJSON(t);return n.errorOnInvalidContent&&i.check(),i}catch(s){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",s),_s("",e,n)}if(o){if(n.errorOnInvalidContent){let i=!1,a="";const l=new um({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(i=!0,a=typeof c=="string"?c:c.outerHTML,null)}]}})});if(n.slice?ln.fromSchema(l).parseSlice(xs(t),n.parseOptions):ln.fromSchema(l).parse(xs(t),n.parseOptions),n.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${a}`)})}const s=ln.fromSchema(e);return n.slice?s.parseSlice(xs(t),n.parseOptions).content:s.parse(xs(t),n.parseOptions)}return _s("",e,n)}function YM(t,e,n){const r=t.steps.length-1;if(r<e)return;const o=t.steps[r];if(!(o instanceof Re||o instanceof De))return;const s=t.mapping.maps[r];let i=0;s.forEach((a,l,c,u)=>{i===0&&(i=u)}),t.setSelection(ie.near(t.doc.resolve(i),n))}var XM=t=>!("type"in t),QM=(t,e,n)=>({tr:r,dispatch:o,editor:s})=>{var i;if(o){n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let a;const l=k=>{s.emit("contentError",{editor:s,error:k,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{_s(e,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(k){l(k)}try{a=_s(e,s.schema,{parseOptions:c,errorOnInvalidContent:(i=n.errorOnInvalidContent)!=null?i:s.options.enableContentCheck})}catch(k){return l(k),!1}let{from:u,to:f}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},p=!0,m=!0;if((XM(a)?a:[a]).forEach(k=>{k.check(),p=p?k.isText&&k.marks.length===0:!1,m=m?k.isBlock:!1}),u===f&&m){const{parent:k}=r.doc.resolve(u);k.isTextblock&&!k.type.spec.code&&!k.childCount&&(u-=1,f+=1)}let y;if(p){if(Array.isArray(e))y=e.map(k=>k.text||"").join("");else if(e instanceof B){let k="";e.forEach(w=>{w.text&&(k+=w.text)}),y=k}else typeof e=="object"&&e&&e.text?y=e.text:y=e;r.insertText(y,u,f)}else{y=a;const k=r.doc.resolve(u),w=k.node(),v=k.parentOffset===0,b=w.isText||w.isTextblock,S=w.content.size>0;v&&b&&S&&(u=Math.max(0,u-1)),r.replaceWith(u,f,y)}n.updateSelection&&YM(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:u,text:y}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:u,text:y})}return!0},eA=()=>({state:t,dispatch:e})=>xT(t,e),tA=()=>({state:t,dispatch:e})=>_T(t,e),nA=()=>({state:t,dispatch:e})=>Km(t,e),rA=()=>({state:t,dispatch:e})=>Ym(t,e),oA=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Fi(t.doc,t.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},sA=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Fi(t.doc,t.selection.$from.pos,1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},iA=()=>({state:t,dispatch:e})=>ST(t,e),aA=()=>({state:t,dispatch:e})=>CT(t,e);function Ty(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function lA(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,o,s,i;for(let a=0;a<e.length-1;a+=1){const l=e[a];if(/^(cmd|meta|m)$/i.test(l))i=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))o=!0;else if(/^s(hift)?$/i.test(l))s=!0;else if(/^mod$/i.test(l))ra()||Ty()?i=!0:o=!0;else throw new Error(`Unrecognized modifier name: ${l}`)}return r&&(n=`Alt-${n}`),o&&(n=`Ctrl-${n}`),i&&(n=`Meta-${n}`),s&&(n=`Shift-${n}`),n}var cA=t=>({editor:e,view:n,tr:r,dispatch:o})=>{const s=lA(t).split(/-(?!$)/),i=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),a=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=e.captureTransaction(()=>{n.someProp("handleKeyDown",c=>c(n,a))});return l==null||l.steps.forEach(c=>{const u=c.map(r.mapping);u&&o&&r.maybeStep(u)}),!0};function Es(t,e,n={}){const{from:r,to:o,empty:s}=t.selection,i=e?ze(e,t.schema):null,a=[];t.doc.nodesBetween(r,o,(f,p)=>{if(f.isText)return;const m=Math.max(r,p),g=Math.min(o,p+f.nodeSize);a.push({node:f,from:m,to:g})});const l=o-r,c=a.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>na(f.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((f,p)=>f+p.to-p.from,0)>=l}var dA=(t,e={})=>({state:n,dispatch:r})=>{const o=ze(t,n.schema);return Es(n,o,e)?ET(n,r):!1},uA=()=>({state:t,dispatch:e})=>tg(t,e),fA=t=>({state:e,dispatch:n})=>{const r=ze(t,e.schema);return $T(r)(e,n)},hA=()=>({state:t,dispatch:e})=>Qm(t,e);function oa(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function My(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,o)=>(n.includes(o)||(r[o]=t[o]),r),{})}var pA=(t,e)=>({tr:n,state:r,dispatch:o})=>{let s=null,i=null;const a=oa(typeof t=="string"?t:t.name,r.schema);if(!a)return!1;a==="node"&&(s=ze(t,r.schema)),a==="mark"&&(i=pn(t,r.schema));let l=!1;return n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(u,f)=>{s&&s===u.type&&(l=!0,o&&n.setNodeMarkup(f,void 0,My(u.attrs,e))),i&&u.marks.length&&u.marks.forEach(p=>{i===p.type&&(l=!0,o&&n.addMark(f,f+u.nodeSize,i.create(My(p.attrs,e))))})})}),l},mA=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),gA=()=>({tr:t,dispatch:e})=>{if(e){const n=new dt(t.doc);t.setSelection(n)}return!0},yA=()=>({state:t,dispatch:e})=>qm(t,e),kA=()=>({state:t,dispatch:e})=>Xm(t,e),wA=()=>({state:t,dispatch:e})=>NT(t,e),vA=()=>({state:t,dispatch:e})=>IT(t,e),bA=()=>({state:t,dispatch:e})=>OT(t,e);function cd(t,e,n={},r={}){return _s(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var SA=(t,{errorOnInvalidContent:e,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:o,tr:s,dispatch:i,commands:a})=>{const{doc:l}=s;if(r.preserveWhitespace!=="full"){const c=cd(t,o.schema,r,{errorOnInvalidContent:e??o.options.enableContentCheck});return i&&s.replaceWith(0,l.content.size,c).setMeta("preventUpdate",!n),!0}return i&&s.setMeta("preventUpdate",!n),a.insertContentAt({from:0,to:l.content.size},t,{parseOptions:r,errorOnInvalidContent:e??o.options.enableContentCheck})};function Ay(t,e){const n=pn(e,t.schema),{from:r,to:o,empty:s}=t.selection,i=[];s?(t.storedMarks&&i.push(...t.storedMarks),i.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,o,l=>{i.push(...l.marks)});const a=i.find(l=>l.type.name===n.name);return a?{...a.attrs}:{}}function CA(t,e){const n=new zm(t);return e.forEach(r=>{r.steps.forEach(o=>{n.step(o)})}),n}function xA(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function _A(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function dd(t){return e=>_A(e.$from,t)}function U(t,e,n){return t.config[e]===void 0&&t.parent?U(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?U(t.parent,e,n):null}):t.config[e]}function ud(t){return t.map(e=>{const n={name:e.name,options:e.options,storage:e.storage},r=U(e,"addExtensions",n);return r?[e,...ud(r())]:e}).flat(10)}function sa(t,e){const n=gr.fromSchema(e).serializeFragment(t),o=document.implementation.createHTMLDocument().createElement("div");return o.appendChild(n),o.innerHTML}function Ny(t){return typeof t=="function"}function ke(t,e=void 0,...n){return Ny(t)?e?t.bind(e)(...n):t(...n):t}function EA(t={}){return Object.keys(t).length===0&&t.constructor===Object}function wo(t){const e=t.filter(o=>o.type==="extension"),n=t.filter(o=>o.type==="node"),r=t.filter(o=>o.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function By(t){const e=[],{nodeExtensions:n,markExtensions:r}=wo(t),o=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},i=n.filter(c=>c.name!=="text").map(c=>c.name),a=r.map(c=>c.name),l=[...i,...a];return t.forEach(c=>{const u={name:c.name,options:c.options,storage:c.storage,extensions:o},f=U(c,"addGlobalAttributes",u);if(!f)return;f().forEach(m=>{let g;Array.isArray(m.types)?g=m.types:m.types==="*"?g=l:m.types==="nodes"?g=i:m.types==="marks"?g=a:g=[],g.forEach(y=>{Object.entries(m.attributes).forEach(([k,w])=>{e.push({type:y,name:k,attribute:{...s,...w}})})})})}),o.forEach(c=>{const u={name:c.name,options:c.options,storage:c.storage},f=U(c,"addAttributes",u);if(!f)return;const p=f();Object.entries(p).forEach(([m,g])=>{const y={...s,...g};typeof(y==null?void 0:y.default)=="function"&&(y.default=y.default()),y!=null&&y.isRequired&&(y==null?void 0:y.default)===void 0&&delete y.default,e.push({type:c.name,name:m,attribute:y})})}),e}function vo(...t){return t.filter(e=>!!e).reduce((e,n)=>{const r={...e};return Object.entries(n).forEach(([o,s])=>{if(!r[o]){r[o]=s;return}if(o==="class"){const a=s?String(s).split(" "):[],l=r[o]?r[o].split(" "):[],c=a.filter(u=>!l.includes(u));r[o]=[...l,...c].join(" ")}else if(o==="style"){const a=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],l=r[o]?r[o].split(";").map(u=>u.trim()).filter(Boolean):[],c=new Map;l.forEach(u=>{const[f,p]=u.split(":").map(m=>m.trim());c.set(f,p)}),a.forEach(u=>{const[f,p]=u.split(":").map(m=>m.trim());c.set(f,p)}),r[o]=Array.from(c.entries()).map(([u,f])=>`${u}: ${f}`).join("; ")}else r[o]=s}),r},{})}function ia(t,e){return e.filter(n=>n.type===t.type.name).filter(n=>n.attribute.rendered).map(n=>n.attribute.renderHTML?n.attribute.renderHTML(t.attrs)||{}:{[n.name]:t.attrs[n.name]}).reduce((n,r)=>vo(n,r),{})}function TA(t){return typeof t!="string"?t:t.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(t):t==="true"?!0:t==="false"?!1:t}function Oy(t,e){return"style"in t?t:{...t,getAttrs:n=>{const r=t.getAttrs?t.getAttrs(n):t.attrs;if(r===!1)return!1;const o=e.reduce((s,i)=>{const a=i.attribute.parseHTML?i.attribute.parseHTML(n):TA(n.getAttribute(i.name));return a==null?s:{...s,[i.name]:a}},{});return{...r,...o}}}}function Iy(t){return Object.fromEntries(Object.entries(t).filter(([e,n])=>e==="attrs"&&EA(n)?!1:n!=null))}function Py(t){var e,n;const r={};return!((e=t==null?void 0:t.attribute)!=null&&e.isRequired)&&"default"in((t==null?void 0:t.attribute)||{})&&(r.default=t.attribute.default),((n=t==null?void 0:t.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=t.attribute.validate),[t.name,r]}function Ry(t,e){var n;const r=By(t),{nodeExtensions:o,markExtensions:s}=wo(t),i=(n=o.find(c=>U(c,"topNode")))==null?void 0:n.name,a=Object.fromEntries(o.map(c=>{const u=r.filter(w=>w.type===c.name),f={name:c.name,options:c.options,storage:c.storage,editor:e},p=t.reduce((w,v)=>{const b=U(v,"extendNodeSchema",f);return{...w,...b?b(c):{}}},{}),m=Iy({...p,content:ke(U(c,"content",f)),marks:ke(U(c,"marks",f)),group:ke(U(c,"group",f)),inline:ke(U(c,"inline",f)),atom:ke(U(c,"atom",f)),selectable:ke(U(c,"selectable",f)),draggable:ke(U(c,"draggable",f)),code:ke(U(c,"code",f)),whitespace:ke(U(c,"whitespace",f)),linebreakReplacement:ke(U(c,"linebreakReplacement",f)),defining:ke(U(c,"defining",f)),isolating:ke(U(c,"isolating",f)),attrs:Object.fromEntries(u.map(Py))}),g=ke(U(c,"parseHTML",f));g&&(m.parseDOM=g.map(w=>Oy(w,u)));const y=U(c,"renderHTML",f);y&&(m.toDOM=w=>y({node:w,HTMLAttributes:ia(w,u)}));const k=U(c,"renderText",f);return k&&(m.toText=k),[c.name,m]})),l=Object.fromEntries(s.map(c=>{const u=r.filter(k=>k.type===c.name),f={name:c.name,options:c.options,storage:c.storage,editor:e},p=t.reduce((k,w)=>{const v=U(w,"extendMarkSchema",f);return{...k,...v?v(c):{}}},{}),m=Iy({...p,inclusive:ke(U(c,"inclusive",f)),excludes:ke(U(c,"excludes",f)),group:ke(U(c,"group",f)),spanning:ke(U(c,"spanning",f)),code:ke(U(c,"code",f)),attrs:Object.fromEntries(u.map(Py))}),g=ke(U(c,"parseHTML",f));g&&(m.parseDOM=g.map(k=>Oy(k,u)));const y=U(c,"renderHTML",f);return y&&(m.toDOM=k=>y({mark:k,HTMLAttributes:ia(k,u)})),[c.name,m]}));return new um({topNode:i,nodes:a,marks:l})}function MA(t){const e=t.filter((n,r)=>t.indexOf(n)!==r);return Array.from(new Set(e))}function Ts(t){return t.sort((n,r)=>{const o=U(n,"priority")||100,s=U(r,"priority")||100;return o>s?-1:o<s?1:0})}function fd(t){const e=Ts(ud(t)),n=MA(e.map(r=>r.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(r=>`'${r}'`).join(", ")}]. This can lead to issues.`),e}function Dy(t,e){const n=fd(t);return Ry(n,e)}function aa(t,e){const n=Dy(e),r=an.fromJSON(n,t);return sa(r.content,n)}function jn(t,e){const n=Dy(e),r=xs(t);return ln.fromSchema(n).parse(r).toJSON()}function zy(t,e,n){const{from:r,to:o}=e,{blockSeparator:s=`
|
|
79
|
-
|
|
80
|
-
`,textSerializers:i={}}=n||{};let a="";return t.nodesBetween(r,o,(l,c,u,f)=>{var p;l.isBlock&&c>r&&(a+=s);const m=i==null?void 0:i[l.type.name];if(m)return u&&(a+=m({node:l,pos:c,parent:u,index:f,range:e})),!1;l.isText&&(a+=(p=l==null?void 0:l.text)==null?void 0:p.slice(Math.max(r,c)-c,o-c))}),a}function AA(t,e){const n={from:0,to:t.content.size};return zy(t,n,e)}function $y(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}function NA(t,e){const n=ze(e,t.schema),{from:r,to:o}=t.selection,s=[];t.doc.nodesBetween(r,o,a=>{s.push(a)});const i=s.reverse().find(a=>a.type.name===n.name);return i?{...i.attrs}:{}}function BA(t,e){const n=oa(typeof e=="string"?e:e.name,t.schema);return n==="node"?NA(t,e):n==="mark"?Ay(t,e):{}}function OA(t,e=JSON.stringify){const n={};return t.filter(r=>{const o=e(r);return Object.prototype.hasOwnProperty.call(n,o)?!1:n[o]=!0})}function IA(t){const e=OA(t);return e.length===1?e:e.filter((n,r)=>!e.filter((s,i)=>i!==r).some(s=>n.oldRange.from>=s.oldRange.from&&n.oldRange.to<=s.oldRange.to&&n.newRange.from>=s.newRange.from&&n.newRange.to<=s.newRange.to))}function PA(t){const{mapping:e,steps:n}=t,r=[];return e.maps.forEach((o,s)=>{const i=[];if(o.ranges.length)o.forEach((a,l)=>{i.push({from:a,to:l})});else{const{from:a,to:l}=n[s];if(a===void 0||l===void 0)return;i.push({from:a,to:l})}i.forEach(({from:a,to:l})=>{const c=e.slice(s).map(a,-1),u=e.slice(s).map(l),f=e.invert().map(c,-1),p=e.invert().map(u);r.push({oldRange:{from:f,to:p},newRange:{from:c,to:u}})})}),IA(r)}function Vy(t,e,n){const r=[];return t===e?n.resolve(t).marks().forEach(o=>{const s=n.resolve(t),i=ld(s,o.type);i&&r.push({mark:o,...i})}):n.nodesBetween(t,e,(o,s)=>{!o||(o==null?void 0:o.nodeSize)===void 0||r.push(...o.marks.map(i=>({from:s,to:s+o.nodeSize,mark:i})))}),r}function Ms(t,e){return e.nodes[t]||e.marks[t]||null}function la(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const o=t.find(s=>s.type===e&&s.name===r);return o?o.attribute.keepOnSplit:!1}))}var RA=(t,e=500)=>{let n="";const r=t.parentOffset;return t.parent.nodesBetween(Math.max(0,r-e),r,(o,s,i,a)=>{var l,c;const u=((c=(l=o.type.spec).toText)==null?void 0:c.call(l,{node:o,pos:s,parent:i,index:a}))||o.textContent||"%leaf%";n+=o.isAtom&&!o.isText?u:u.slice(0,Math.max(0,r-s))}),n};function hd(t,e,n={}){const{empty:r,ranges:o}=t.selection,s=e?pn(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>na(f.attrs,n,{strict:!1}));let i=0;const a=[];if(o.forEach(({$from:f,$to:p})=>{const m=f.pos,g=p.pos;t.doc.nodesBetween(m,g,(y,k)=>{if(s&&y.inlineContent&&!y.type.allowsMarkType(s))return!1;if(!y.isText&&!y.marks.length)return;const w=Math.max(m,k),v=Math.min(g,k+y.nodeSize),b=v-w;i+=b,a.push(...y.marks.map(S=>({mark:S,from:w,to:v})))})}),i===0)return!1;const l=a.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>na(f.mark.attrs,n,{strict:!1})).reduce((f,p)=>f+p.to-p.from,0),c=a.filter(f=>s?f.mark.type!==s&&f.mark.type.excludes(s):!0).reduce((f,p)=>f+p.to-p.from,0);return(l>0?l+c:l)>=i}function DA(t,e,n={}){if(!e)return Es(t,null,n)||hd(t,null,n);const r=oa(e,t.schema);return r==="node"?Es(t,e,n):r==="mark"?hd(t,e,n):!1}function Ly(t,e){return Array.isArray(e)?e.some(n=>(typeof n=="string"?n:n.name)===t.name):e}function Fy(t,e){const{nodeExtensions:n}=wo(e),r=n.find(i=>i.name===t);if(!r)return!1;const o={name:r.name,options:r.options,storage:r.storage},s=ke(U(r,"group",o));return typeof s!="string"?!1:s.split(" ").includes("list")}function ca(t,{checkChildren:e=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if(t.type.name==="hardBreak")return!0;if(t.isText)return/^\s*$/m.test((r=t.text)!=null?r:"")}if(t.isText)return!t.text;if(t.isAtom||t.isLeaf)return!1;if(t.content.childCount===0)return!0;if(e){let o=!0;return t.content.forEach(s=>{o!==!1&&(ca(s,{ignoreWhitespace:n,checkChildren:e})||(o=!1))}),o}return!1}function zA(t){return t instanceof G}var jy=class Uk{constructor(e){this.position=e}static fromJSON(e){return new Uk(e.position)}toJSON(){return{position:this.position}}};function $A(t,e){const n=e.mapping.mapResult(t.position);return{position:new jy(n.pos),mapResult:n}}function VA(t){return new jy(t)}function LA(t,e,n){var r;const{selection:o}=e;let s=null;if(Cy(o)&&(s=o.$cursor),s){const a=(r=t.storedMarks)!=null?r:s.marks();return s.parent.type.allowsMarkType(n)&&(!!n.isInSet(a)||!a.some(c=>c.type.excludes(n)))}const{ranges:i}=o;return i.some(({$from:a,$to:l})=>{let c=a.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(a.pos,l.pos,(u,f,p)=>{if(c)return!1;if(u.isInline){const m=!p||p.type.allowsMarkType(n),g=!!n.isInSet(u.marks)||!u.marks.some(y=>y.type.excludes(n));c=m&&g}return!c}),c})}var FA=(t,e={})=>({tr:n,state:r,dispatch:o})=>{const{selection:s}=n,{empty:i,ranges:a}=s,l=pn(t,r.schema);if(o)if(i){const c=Ay(r,l);n.addStoredMark(l.create({...c,...e}))}else a.forEach(c=>{const u=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(u,f,(p,m)=>{const g=Math.max(m,u),y=Math.min(m+p.nodeSize,f);p.marks.find(w=>w.type===l)?p.marks.forEach(w=>{l===w.type&&n.addMark(g,y,l.create({...w.attrs,...e}))}):n.addMark(g,y,l.create(e))})});return LA(r,n,l)},jA=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),HA=(t,e={})=>({state:n,dispatch:r,chain:o})=>{const s=ze(t,n.schema);let i;return n.selection.$anchor.sameParent(n.selection.$head)&&(i=n.selection.$anchor.parent.attrs),s.isTextblock?o().command(({commands:a})=>og(s,{...i,...e})(n)?!0:a.clearNodes()).command(({state:a})=>og(s,{...i,...e})(a,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},WA=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,o=Er(t,0,r.content.size),s=G.create(r,o);e.setSelection(s)}return!0},ZA=(t,e)=>({tr:n,state:r,dispatch:o})=>{const{selection:s}=r;let i,a;return typeof e=="number"?(i=e,a=e):e&&"from"in e&&"to"in e?(i=e.from,a=e.to):(i=s.from,a=s.to),o&&n.doc.nodesBetween(i,a,(l,c)=>{l.isText||n.setNodeMarkup(c,void 0,{...l.attrs,dir:t})}),!0},UA=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:o,to:s}=typeof t=="number"?{from:t,to:t}:t,i=re.atStart(r).from,a=re.atEnd(r).to,l=Er(o,i,a),c=Er(s,i,a),u=re.create(r,l,c);e.setSelection(u)}return!0},KA=t=>({state:e,dispatch:n})=>{const r=ze(t,e.schema);return FT(r)(e,n)};function Hy(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(o=>e==null?void 0:e.includes(o.type.name));t.tr.ensureMarks(r)}}var JA=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:o})=>{const{selection:s,doc:i}=e,{$from:a,$to:l}=s,c=o.extensionManager.attributes,u=la(c,a.node().type.name,a.node().attrs);if(s instanceof G&&s.node.isBlock)return!a.parentOffset||!cn(i,a.pos)?!1:(r&&(t&&Hy(n,o.extensionManager.splittableMarks),e.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;const f=l.parentOffset===l.parent.content.size,p=a.depth===0?void 0:xA(a.node(-1).contentMatchAt(a.indexAfter(-1)));let m=f&&p?[{type:p,attrs:u}]:void 0,g=cn(e.doc,e.mapping.map(a.pos),1,m);if(!m&&!g&&cn(e.doc,e.mapping.map(a.pos),1,p?[{type:p}]:void 0)&&(g=!0,m=p?[{type:p,attrs:u}]:void 0),r){if(g&&(s instanceof re&&e.deleteSelection(),e.split(e.mapping.map(a.pos),1,m),p&&!f&&!a.parentOffset&&a.parent.type!==p)){const y=e.mapping.map(a.before()),k=e.doc.resolve(y);a.node(-1).canReplaceWith(k.index(),k.index()+1,p)&&e.setNodeMarkup(e.mapping.map(a.before()),p)}t&&Hy(n,o.extensionManager.splittableMarks),e.scrollIntoView()}return g},qA=(t,e={})=>({tr:n,state:r,dispatch:o,editor:s})=>{var i;const a=ze(t,r.schema),{$from:l,$to:c}=r.selection,u=r.selection.node;if(u&&u.isBlock||l.depth<2||!l.sameParent(c))return!1;const f=l.node(-1);if(f.type!==a)return!1;const p=s.extensionManager.attributes;if(l.parent.content.size===0&&l.node(-1).childCount===l.indexAfter(-1)){if(l.depth===2||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(o){let w=B.empty;const v=l.index(-1)?1:l.index(-2)?2:3;for(let T=l.depth-v;T>=l.depth-3;T-=1)w=B.from(l.node(T).copy(w));const b=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,S={...la(p,l.node().type.name,l.node().attrs),...e},C=((i=a.contentMatch.defaultType)==null?void 0:i.createAndFill(S))||void 0;w=w.append(B.from(a.createAndFill(null,C)||void 0));const _=l.before(l.depth-(v-1));n.replace(_,l.after(-b),new L(w,4-v,0));let x=-1;n.doc.nodesBetween(_,n.doc.content.size,(T,N)=>{if(x>-1)return!1;T.isTextblock&&T.content.size===0&&(x=N+1)}),x>-1&&n.setSelection(re.near(n.doc.resolve(x))),n.scrollIntoView()}return!0}const m=c.pos===l.end()?f.contentMatchAt(0).defaultType:null,g={...la(p,f.type.name,f.attrs),...e},y={...la(p,l.node().type.name,l.node().attrs),...e};n.delete(l.pos,c.pos);const k=m?[{type:a,attrs:g},{type:m,attrs:y}]:[{type:a,attrs:g}];if(!cn(n.doc,l.pos,2))return!1;if(o){const{selection:w,storedMarks:v}=r,{splittableMarks:b}=s.extensionManager,S=v||w.$to.parentOffset&&w.$from.marks();if(n.split(l.pos,2,k).scrollIntoView(),!S||!o)return!0;const C=S.filter(_=>b.includes(_.type.name));n.ensureMarks(C)}return!0},pd=(t,e)=>{const n=dd(i=>i.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const o=t.doc.nodeAt(r);return n.node.type===(o==null?void 0:o.type)&&kr(t.doc,n.pos)&&t.join(n.pos),!0},md=(t,e)=>{const n=dd(i=>i.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const o=t.doc.nodeAt(r);return n.node.type===(o==null?void 0:o.type)&&kr(t.doc,r)&&t.join(r),!0},GA=(t,e,n,r={})=>({editor:o,tr:s,state:i,dispatch:a,chain:l,commands:c,can:u})=>{const{extensions:f,splittableMarks:p}=o.extensionManager,m=ze(t,i.schema),g=ze(e,i.schema),{selection:y,storedMarks:k}=i,{$from:w,$to:v}=y,b=w.blockRange(v),S=k||y.$to.parentOffset&&y.$from.marks();if(!b)return!1;const C=dd(_=>Fy(_.type.name,f))(y);if(b.depth>=1&&C&&b.depth-C.depth<=1){if(C.node.type===m)return c.liftListItem(g);if(Fy(C.node.type.name,f)&&m.validContent(C.node.content)&&a)return l().command(()=>(s.setNodeMarkup(C.pos,m),!0)).command(()=>pd(s,m)).command(()=>md(s,m)).run()}return!n||!S||!a?l().command(()=>u().wrapInList(m,r)?!0:c.clearNodes()).wrapInList(m,r).command(()=>pd(s,m)).command(()=>md(s,m)).run():l().command(()=>{const _=u().wrapInList(m,r),x=S.filter(T=>p.includes(T.type.name));return s.ensureMarks(x),_?!0:c.clearNodes()}).wrapInList(m,r).command(()=>pd(s,m)).command(()=>md(s,m)).run()},YA=(t,e={},n={})=>({state:r,commands:o})=>{const{extendEmptyMarkRange:s=!1}=n,i=pn(t,r.schema);return hd(r,i,e)?o.unsetMark(i,{extendEmptyMarkRange:s}):o.setMark(i,e)},XA=(t,e,n={})=>({state:r,commands:o})=>{const s=ze(t,r.schema),i=ze(e,r.schema),a=Es(r,s,n);let l;return r.selection.$anchor.sameParent(r.selection.$head)&&(l=r.selection.$anchor.parent.attrs),a?o.setNode(i,l):o.setNode(s,{...l,...n})},QA=(t,e={})=>({state:n,commands:r})=>{const o=ze(t,n.schema);return Es(n,o,e)?r.lift(o):r.wrapIn(o,e)},eN=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const o=n[r];let s;if(o.spec.isInputRules&&(s=o.getState(t))){if(e){const i=t.tr,a=s.transform;for(let l=a.steps.length-1;l>=0;l-=1)i.step(a.steps[l].invert(a.docs[l]));if(s.text){const l=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,t.schema.text(s.text,l))}else i.delete(s.from,s.to)}return!0}}return!1},tN=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:o}=n;return r||e&&o.forEach(s=>{t.removeMark(s.$from.pos,s.$to.pos)}),!0},nN=(t,e={})=>({tr:n,state:r,dispatch:o})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:a}=n,l=pn(t,r.schema),{$from:c,empty:u,ranges:f}=a;if(!o)return!0;if(u&&i){let{from:p,to:m}=a;const g=(s=c.marks().find(k=>k.type===l))==null?void 0:s.attrs,y=ld(c,l,g);y&&(p=y.from,m=y.to),n.removeMark(p,m,l)}else f.forEach(p=>{n.removeMark(p.$from.pos,p.$to.pos,l)});return n.removeStoredMark(l),!0},rN=t=>({tr:e,state:n,dispatch:r})=>{const{selection:o}=n;let s,i;return typeof t=="number"?(s=t,i=t):t&&"from"in t&&"to"in t?(s=t.from,i=t.to):(s=o.from,i=o.to),r&&e.doc.nodesBetween(s,i,(a,l)=>{if(a.isText)return;const c={...a.attrs};delete c.dir,e.setNodeMarkup(l,void 0,c)}),!0},oN=(t,e={})=>({tr:n,state:r,dispatch:o})=>{let s=null,i=null;const a=oa(typeof t=="string"?t:t.name,r.schema);if(!a)return!1;a==="node"&&(s=ze(t,r.schema)),a==="mark"&&(i=pn(t,r.schema));let l=!1;return n.selection.ranges.forEach(c=>{const u=c.$from.pos,f=c.$to.pos;let p,m,g,y;n.selection.empty?r.doc.nodesBetween(u,f,(k,w)=>{s&&s===k.type&&(l=!0,g=Math.max(w,u),y=Math.min(w+k.nodeSize,f),p=w,m=k)}):r.doc.nodesBetween(u,f,(k,w)=>{w<u&&s&&s===k.type&&(l=!0,g=Math.max(w,u),y=Math.min(w+k.nodeSize,f),p=w,m=k),w>=u&&w<=f&&(s&&s===k.type&&(l=!0,o&&n.setNodeMarkup(w,void 0,{...k.attrs,...e})),i&&k.marks.length&&k.marks.forEach(v=>{if(i===v.type&&(l=!0,o)){const b=Math.max(w,u),S=Math.min(w+k.nodeSize,f);n.addMark(b,S,i.create({...v.attrs,...e}))}}))}),m&&(p!==void 0&&o&&n.setNodeMarkup(p,void 0,{...m.attrs,...e}),i&&m.marks.length&&m.marks.forEach(k=>{i===k.type&&o&&n.addMark(g,y,i.create({...k.attrs,...e}))}))}),l},sN=(t,e={})=>({state:n,dispatch:r})=>{const o=ze(t,n.schema);return PT(o,e)(n,r)},iN=(t,e={})=>({state:n,dispatch:r})=>{const o=ze(t,n.schema);return RT(o,e)(n,r)},aN=class{constructor(){this.callbacks={}}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),this}emit(t,...e){const n=this.callbacks[t];return n&&n.forEach(r=>r.apply(this,e)),this}off(t,e){const n=this.callbacks[t];return n&&(e?this.callbacks[t]=n.filter(r=>r!==e):delete this.callbacks[t]),this}once(t,e){const n=(...r)=>{this.off(t,n),e.apply(this,r)};return this.on(t,n)}removeAllListeners(){this.callbacks={}}},lN=class{constructor(t){var e;this.find=t.find,this.handler=t.handler,this.undoable=(e=t.undoable)!=null?e:!0}},cN=(t,e)=>{if(ad(e))return e.exec(t);const n=e(t);if(!n)return null;const r=[n.text];return r.index=n.index,r.input=t,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r};function da(t){var e;const{editor:n,from:r,to:o,text:s,rules:i,plugin:a}=t,{view:l}=n;if(l.composing)return!1;const c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(e=c.nodeBefore||c.nodeAfter)!=null&&e.marks.find(p=>p.type.spec.code))return!1;let u=!1;const f=RA(c)+s;return i.forEach(p=>{if(u)return;const m=cN(f,p.find);if(!m)return;const g=l.state.tr,y=ea({state:l.state,transaction:g}),k={from:r-(m[0].length-s.length),to:o},{commands:w,chain:v,can:b}=new ta({editor:n,state:y});p.handler({state:y,range:k,match:m,commands:w,chain:v,can:b})===null||!g.steps.length||(p.undoable&&g.setMeta(a,{transform:g,from:r,to:o,text:s}),l.dispatch(g),u=!0)}),u}function dN(t){const{editor:e,rules:n}=t,r=new Oe({state:{init(){return null},apply(o,s,i){const a=o.getMeta(r);if(a)return a;const l=o.getMeta("applyInputRules");return!!l&&setTimeout(()=>{let{text:u}=l;typeof u=="string"?u=u:u=sa(B.from(u),i.schema);const{from:f}=l,p=f+u.length;da({editor:e,from:f,to:p,text:u,rules:n,plugin:r})}),o.selectionSet||o.docChanged?null:s}},props:{handleTextInput(o,s,i,a){return da({editor:e,from:s,to:i,text:a,rules:n,plugin:r})},handleDOMEvents:{compositionend:o=>(setTimeout(()=>{const{$cursor:s}=o.state.selection;s&&da({editor:e,from:s.pos,to:s.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(o,s){if(s.key!=="Enter")return!1;const{$cursor:i}=o.state.selection;return i?da({editor:e,from:i.pos,to:i.pos,text:`
|
|
81
|
-
`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function uN(t){return Object.prototype.toString.call(t).slice(8,-1)}function ua(t){return uN(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function Wy(t,e){const n={...t};return ua(t)&&ua(e)&&Object.keys(e).forEach(r=>{ua(e[r])&&ua(t[r])?n[r]=Wy(t[r],e[r]):n[r]=e[r]}),n}var gd=class{constructor(t={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...t},this.name=this.config.name}get options(){return{...ke(U(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...ke(U(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(t={}){const e=this.extend({...this.config,addOptions:()=>Wy(this.options,t)});return e.name=this.name,e.parent=this.parent,e}extend(t={}){const e=new this.constructor({...this.config,...t});return e.parent=this,this.child=e,e.name="name"in t?t.name:e.parent.name,e}},As=class Kk extends gd{constructor(){super(...arguments),this.type="mark"}static create(e={}){const n=typeof e=="function"?e():e;return new Kk(n)}static handleExit({editor:e,mark:n}){const{tr:r}=e.state,o=e.state.selection.$from;if(o.pos===o.end()){const i=o.marks();if(!!!i.find(c=>(c==null?void 0:c.type.name)===n.name))return!1;const l=i.find(c=>(c==null?void 0:c.type.name)===n.name);return l&&r.removeStoredMark(l),r.insertText(" ",o.pos),e.view.dispatch(r),!0}return!1}configure(e){return super.configure(e)}extend(e){const n=typeof e=="function"?e():e;return super.extend(n)}};function fN(t){return typeof t=="number"}var hN=class{constructor(t){this.find=t.find,this.handler=t.handler}},pN=(t,e,n)=>{if(ad(e))return[...t.matchAll(e)];const r=e(t,n);return r?r.map(o=>{const s=[o.text];return s.index=o.index,s.input=t,s.data=o.data,o.replaceWith&&(o.text.includes(o.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(o.replaceWith)),s}):[]};function mN(t){const{editor:e,state:n,from:r,to:o,rule:s,pasteEvent:i,dropEvent:a}=t,{commands:l,chain:c,can:u}=new ta({editor:e,state:n}),f=[];return n.doc.nodesBetween(r,o,(m,g)=>{var y,k,w,v,b;if((k=(y=m.type)==null?void 0:y.spec)!=null&&k.code||!(m.isText||m.isTextblock||m.isInline))return;const S=(b=(v=(w=m.content)==null?void 0:w.size)!=null?v:m.nodeSize)!=null?b:0,C=Math.max(r,g),_=Math.min(o,g+S);if(C>=_)return;const x=m.isText?m.text||"":m.textBetween(C-g,_-g,void 0,"");pN(x,s.find,i).forEach(N=>{if(N.index===void 0)return;const I=C+N.index+1,V=I+N[0].length,K={from:n.tr.mapping.map(I),to:n.tr.mapping.map(V)},M=s.handler({state:n,range:K,match:N,commands:l,chain:c,can:u,pasteEvent:i,dropEvent:a});f.push(M)})}),f.every(m=>m!==null)}var fa=null,gN=t=>{var e;const n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=n.clipboardData)==null||e.setData("text/html",t),n};function yN(t){const{editor:e,rules:n}=t;let r=null,o=!1,s=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,a;try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}const l=({state:u,from:f,to:p,rule:m,pasteEvt:g})=>{const y=u.tr,k=ea({state:u,transaction:y});if(!(!mN({editor:e,state:k,from:Math.max(f-1,0),to:p.b-1,rule:m,pasteEvent:g,dropEvent:a})||!y.steps.length)){try{a=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{a=null}return i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,y}};return n.map(u=>new Oe({view(f){const p=g=>{var y;r=(y=f.dom.parentElement)!=null&&y.contains(g.target)?f.dom.parentElement:null,r&&(fa=e)},m=()=>{fa&&(fa=null)};return window.addEventListener("dragstart",p),window.addEventListener("dragend",m),{destroy(){window.removeEventListener("dragstart",p),window.removeEventListener("dragend",m)}}},props:{handleDOMEvents:{drop:(f,p)=>{if(s=r===f.dom.parentElement,a=p,!s){const m=fa;m!=null&&m.isEditable&&setTimeout(()=>{const g=m.state.selection;g&&m.commands.deleteRange({from:g.from,to:g.to})},10)}return!1},paste:(f,p)=>{var m;const g=(m=p.clipboardData)==null?void 0:m.getData("text/html");return i=p,o=!!(g!=null&&g.includes("data-pm-slice")),!1}}},appendTransaction:(f,p,m)=>{const g=f[0],y=g.getMeta("uiEvent")==="paste"&&!o,k=g.getMeta("uiEvent")==="drop"&&!s,w=g.getMeta("applyPasteRules"),v=!!w;if(!y&&!k&&!v)return;if(v){let{text:C}=w;typeof C=="string"?C=C:C=sa(B.from(C),m.schema);const{from:_}=w,x=_+C.length,T=gN(C);return l({rule:u,state:m,from:_,to:{b:x},pasteEvt:T})}const b=p.doc.content.findDiffStart(m.doc.content),S=p.doc.content.findDiffEnd(m.doc.content);if(!(!fN(b)||!S||b===S.b))return l({rule:u,state:m,from:b,to:S,pasteEvt:i})}}))}var ha=class{constructor(t,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=t,this.extensions=fd(t),this.schema=Ry(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((t,e)=>{const n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ms(e.name,this.schema)},r=U(e,"addCommands",n);return r?{...t,...r()}:t},{})}get plugins(){const{editor:t}=this;return Ts([...this.extensions].reverse()).flatMap(r=>{const o={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:t,type:Ms(r.name,this.schema)},s=[],i=U(r,"addKeyboardShortcuts",o);let a={};if(r.type==="mark"&&U(r,"exitable",o)&&(a.ArrowRight=()=>As.handleExit({editor:t,mark:r})),i){const p=Object.fromEntries(Object.entries(i()).map(([m,g])=>[m,()=>g({editor:t})]));a={...a,...p}}const l=BM(a);s.push(l);const c=U(r,"addInputRules",o);if(Ly(r,t.options.enableInputRules)&&c){const p=c();if(p&&p.length){const m=dN({editor:t,rules:p}),g=Array.isArray(m)?m:[m];s.push(...g)}}const u=U(r,"addPasteRules",o);if(Ly(r,t.options.enablePasteRules)&&u){const p=u();if(p&&p.length){const m=yN({editor:t,rules:p});s.push(...m)}}const f=U(r,"addProseMirrorPlugins",o);if(f){const p=f();s.push(...p)}return s})}get attributes(){return By(this.extensions)}get nodeViews(){const{editor:t}=this,{nodeExtensions:e}=wo(this.extensions);return Object.fromEntries(e.filter(n=>!!U(n,"addNodeView")).map(n=>{const r=this.attributes.filter(l=>l.type===n.name),o={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:ze(n.name,this.schema)},s=U(n,"addNodeView",o);if(!s)return[];const i=s();if(!i)return[];const a=(l,c,u,f,p)=>{const m=ia(l,r);return i({node:l,view:c,getPos:u,decorations:f,innerDecorations:p,editor:t,extension:n,HTMLAttributes:m})};return[n.name,a]}))}dispatchTransaction(t){const{editor:e}=this;return Ts([...this.extensions].reverse()).reduceRight((r,o)=>{const s={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:e,type:Ms(o.name,this.schema)},i=U(o,"dispatchTransaction",s);return i?a=>{i.call(s,{transaction:a,next:r})}:r},t)}transformPastedHTML(t){const{editor:e}=this;return Ts([...this.extensions]).reduce((r,o)=>{const s={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:e,type:Ms(o.name,this.schema)},i=U(o,"transformPastedHTML",s);return i?(a,l)=>{const c=r(a,l);return i.call(s,c)}:r},t||(r=>r))}get markViews(){const{editor:t}=this,{markExtensions:e}=wo(this.extensions);return Object.fromEntries(e.filter(n=>!!U(n,"addMarkView")).map(n=>{const r=this.attributes.filter(a=>a.type===n.name),o={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:pn(n.name,this.schema)},s=U(n,"addMarkView",o);if(!s)return[];const i=(a,l,c)=>{const u=ia(a,r);return s()({mark:a,view:l,inline:c,editor:t,extension:n,HTMLAttributes:u,updateAttributes:f=>{BN(a,t,f)}})};return[n.name,i]}))}setupExtensions(){const t=this.extensions;this.editor.extensionStorage=Object.fromEntries(t.map(e=>[e.name,e.storage])),t.forEach(e=>{var n;const r={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ms(e.name,this.schema)};e.type==="mark"&&((n=ke(U(e,"keepOnSplit",r)))==null||n)&&this.splittableMarks.push(e.name);const o=U(e,"onBeforeCreate",r),s=U(e,"onCreate",r),i=U(e,"onUpdate",r),a=U(e,"onSelectionUpdate",r),l=U(e,"onTransaction",r),c=U(e,"onFocus",r),u=U(e,"onBlur",r),f=U(e,"onDestroy",r);o&&this.editor.on("beforeCreate",o),s&&this.editor.on("create",s),i&&this.editor.on("update",i),a&&this.editor.on("selectionUpdate",a),l&&this.editor.on("transaction",l),c&&this.editor.on("focus",c),u&&this.editor.on("blur",u),f&&this.editor.on("destroy",f)})}};ha.resolve=fd,ha.sort=Ts,ha.flatten=ud;var kN={};id(kN,{ClipboardTextSerializer:()=>Zy,Commands:()=>Uy,Delete:()=>Ky,Drop:()=>Jy,Editable:()=>qy,FocusEvents:()=>Yy,Keymap:()=>Xy,Paste:()=>Qy,Tabindex:()=>e0,TextDirection:()=>t0,focusEventsPluginKey:()=>Gy});var be=class Jk extends gd{constructor(){super(...arguments),this.type="extension"}static create(e={}){const n=typeof e=="function"?e():e;return new Jk(n)}configure(e){return super.configure(e)}extend(e){const n=typeof e=="function"?e():e;return super.extend(n)}},Zy=be.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Oe({key:new Qe("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:o}=e,{ranges:s}=o,i=Math.min(...s.map(u=>u.$from.pos)),a=Math.max(...s.map(u=>u.$to.pos)),l=$y(n);return zy(r,{from:i,to:a},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),Uy=be.create({name:"commands",addCommands(){return{...vy}}}),Ky=be.create({name:"delete",onUpdate({transaction:t,appendedTransactions:e}){var n,r,o;const s=()=>{var i,a,l,c;if((c=(l=(a=(i=this.editor.options.coreExtensionOptions)==null?void 0:i.delete)==null?void 0:a.filterTransaction)==null?void 0:l.call(a,t))!=null?c:t.getMeta("y-sync$"))return;const u=CA(t.before,[t,...e]);PA(u).forEach(m=>{u.mapping.mapResult(m.oldRange.from).deletedAfter&&u.mapping.mapResult(m.oldRange.to).deletedBefore&&u.before.nodesBetween(m.oldRange.from,m.oldRange.to,(g,y)=>{const k=y+g.nodeSize-2,w=m.oldRange.from<=y&&k<=m.oldRange.to;this.editor.emit("delete",{type:"node",node:g,from:y,to:k,newFrom:u.mapping.map(y),newTo:u.mapping.map(k),deletedRange:m.oldRange,newRange:m.newRange,partial:!w,editor:this.editor,transaction:t,combinedTransform:u})})});const p=u.mapping;u.steps.forEach((m,g)=>{var y,k;if(m instanceof Bt){const w=p.slice(g).map(m.from,-1),v=p.slice(g).map(m.to),b=p.invert().map(w,-1),S=p.invert().map(v),C=(y=u.doc.nodeAt(w-1))==null?void 0:y.marks.some(x=>x.eq(m.mark)),_=(k=u.doc.nodeAt(v))==null?void 0:k.marks.some(x=>x.eq(m.mark));this.editor.emit("delete",{type:"mark",mark:m.mark,from:m.from,to:m.to,deletedRange:{from:b,to:S},newRange:{from:w,to:v},partial:!!(_||C),editor:this.editor,transaction:t,combinedTransform:u})}})};(o=(r=(n=this.editor.options.coreExtensionOptions)==null?void 0:n.delete)==null?void 0:r.async)==null||o?setTimeout(s,0):s()}}),Jy=be.create({name:"drop",addProseMirrorPlugins(){return[new Oe({key:new Qe("tiptapDrop"),props:{handleDrop:(t,e,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:r})}}})]}}),qy=be.create({name:"editable",addProseMirrorPlugins(){return[new Oe({key:new Qe("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Gy=new Qe("focusEvents"),Yy=be.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Oe({key:Gy,props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),Xy=be.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:a})=>{const{selection:l,doc:c}=a,{empty:u,$anchor:f}=l,{pos:p,parent:m}=f,g=f.parent.isTextblock&&p>0?a.doc.resolve(p-1):f,y=g.parent.type.spec.isolating,k=f.pos-f.parentOffset,w=y&&g.parent.childCount===1?k===f.pos:ie.atStart(c).from===p;return!u||!m.type.isTextblock||m.textContent.length||!w||w&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},o={...r},s={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return ra()||Ty()?s:o},addProseMirrorPlugins(){return[new Oe({key:new Qe("clearDocument"),appendTransaction:(t,e,n)=>{if(t.some(y=>y.getMeta("composition")))return;const r=t.some(y=>y.docChanged)&&!e.doc.eq(n.doc),o=t.some(y=>y.getMeta("preventClearDocument"));if(!r||o)return;const{empty:s,from:i,to:a}=e.selection,l=ie.atStart(e.doc).from,c=ie.atEnd(e.doc).to;if(s||!(i===l&&a===c)||!ca(n.doc))return;const p=n.tr,m=ea({state:n,transaction:p}),{commands:g}=new ta({editor:this.editor,state:m});if(g.clearNodes(),!!p.steps.length)return p}})]}}),Qy=be.create({name:"paste",addProseMirrorPlugins(){return[new Oe({key:new Qe("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}}),e0=be.create({name:"tabindex",addProseMirrorPlugins(){return[new Oe({key:new Qe("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),t0=be.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:t}=wo(this.extensions);return[{types:t.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const n=e.getAttribute("dir");return n&&(n==="ltr"||n==="rtl"||n==="auto")?n:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new Oe({key:new Qe("textDirection"),props:{attributes:()=>{const t=this.options.direction;return t?{dir:t}:{}}}})]}}),wN=class $s{constructor(e,n,r=!1,o=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=n,this.currentNode=o}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!=null?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let n=this.from,r=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}n=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:n,to:r},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(e);return new $s(n,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new $s(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new $s(e,this.editor)}get children(){const e=[];return this.node.content.forEach((n,r)=>{const o=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,i=n.isInline,a=this.pos+r+(s?0:1);if(a<0||a>this.resolvedPos.doc.nodeSize-2)return;const l=this.resolvedPos.doc.resolve(a);if(!o&&!i&&l.depth<=this.depth)return;const c=new $s(l,this.editor,o,o||i?n:null);o&&(c.actualDepth=this.depth+1),e.push(c)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,n={}){let r=null,o=this.parent;for(;o&&!r;){if(o.node.type.name===e)if(Object.keys(n).length>0){const s=o.node.attrs,i=Object.keys(n);for(let a=0;a<i.length;a+=1){const l=i[a];if(s[l]!==n[l])break}}else r=o;o=o.parent}return r}querySelector(e,n={}){return this.querySelectorAll(e,n,!0)[0]||null}querySelectorAll(e,n={},r=!1){let o=[];if(!this.children||this.children.length===0)return o;const s=Object.keys(n);return this.children.forEach(i=>{r&&o.length>0||(i.node.type.name===e&&s.every(l=>n[l]===i.node.attrs[l])&&o.push(i),!(r&&o.length>0)&&(o=o.concat(i.querySelectorAll(e,n,r))))}),o}setAttribute(e){const{tr:n}=this.editor.state;n.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(n)}},vN=`.ProseMirror {
|
|
1
|
+
(function(A,Re){typeof exports=="object"&&typeof module<"u"?Re(exports,require("@woven-ecs/canvas-store"),require("@woven-canvas/plugin-arrows"),require("vue"),require("@woven-canvas/core"),require("@woven-canvas/math"),require("@woven-canvas/plugin-eraser"),require("@woven-canvas/plugin-pen"),require("@woven-canvas/plugin-selection"),require("@woven-canvas/plugin-canvas-controls")):typeof define=="function"&&define.amd?define(["exports","@woven-ecs/canvas-store","@woven-canvas/plugin-arrows","vue","@woven-canvas/core","@woven-canvas/math","@woven-canvas/plugin-eraser","@woven-canvas/plugin-pen","@woven-canvas/plugin-selection","@woven-canvas/plugin-canvas-controls"],Re):(A=typeof globalThis<"u"?globalThis:A||self,Re(A.Vue={},A.WovenEcsCanvasStore,A.WovenCanvasPluginArrows,A.Vue,A.WovenCanvasCore,A.WovenCanvasMath,A.WovenCanvasPluginEraser,A.WovenCanvasPluginPen,A.WovenCanvasPluginSelection,A.WovenCanvasPluginCanvasControls))})(this,function(A,Re,Y,c,x,Me,po,mo,oe,tf){"use strict";const Tr=[{kind:Y.ArrowHeadKind.None,label:"None",gap:0,svg:""},{kind:Y.ArrowHeadKind.V,label:"Arrow",gap:15,svg:'<polyline points="-10,-7 -1,0 -10,7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />'},{kind:Y.ArrowHeadKind.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:Y.ArrowHeadKind.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:Y.ArrowHeadKind.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function mn(n){return Tr.find(e=>e.kind===n)}const Ni=Symbol.for("__woven_canvas_dropdown_active__"),Bi=Symbol.for("__woven_canvas_dropdown_level__"),Ai=Symbol.for("__woven_canvas_floating_menu__"),Nr=Symbol.for("__woven_canvas_toolbar__"),Ii=Symbol.for("__woven_canvas_tooltip__"),$e=Symbol.for("__woven_canvas__");function fe(n,e){const t=c.inject($e);if(!t)throw new Error("useComponent must be used within a WovenCanvas component");const o=c.shallowRef(null),r=t.getEditor();if(r){const i=r._getContext();x.hasComponent(i,n,e)&&(o.value=e.snapshot(i,n))}const s=t.subscribeComponent(n,e.name,i=>{o.value=i});return c.onUnmounted(()=>{s()}),o}const nf={key:0},of=["x1","y1","x2","y2","stroke","stroke-width"],rf=["x1","y1","x2","y2","stroke","stroke-width"],sf=["points","fill"],lf=["cx","cy","r","fill"],af=["points","fill"],cf=15,df=2,at=c.defineComponent({__name:"ArrowHead",props:{position:{},direction:{},thickness:{},color:{},arrowThickness:{},kind:{}},setup(n){const e=n,t=c.computed(()=>{const l=Math.hypot(e.direction[0],e.direction[1]);if(l===0)return null;const a=(e.arrowThickness/df)**.33,d=cf*a,u=[e.direction[0]/l,e.direction[1]/l],f=[-u[1],u[0]];return{unitDir:u,perpDir:f,size:d}}),o=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=d,f=d,p=[e.position[0]-l[0]*u+a[0]*(f/2),e.position[1]-l[1]*u+a[1]*(f/2)],h=[e.position[0]-l[0]*u-a[0]*(f/2),e.position[1]-l[1]*u-a[1]*(f/2)];return{p1:p,p2:h}}),r=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=d,f=d,p=[l[0]*(d*.4),l[1]*(d*.4)],h=[e.position[0]-l[0]*u+p[0],e.position[1]-l[1]*u+p[1]],m=[h[0]+a[0]*(f/2),h[1]+a[1]*(f/2)],g=[h[0]-a[0]*(f/2),h[1]-a[1]*(f/2)],y=[e.position[0]+p[0],e.position[1]+p[1]];return`${y[0]},${y[1]} ${m[0]},${m[1]} ${g[0]},${g[1]}`}),s=c.computed(()=>{if(!t.value)return null;const{unitDir:l,size:a}=t.value,d=a*.8,u=[l[0]*d,l[1]*d];return{center:[e.position[0]-l[0]*d+u[0],e.position[1]-l[1]*d+u[1]],radius:d}}),i=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=1.6*d,f=1.6*d,p=[l[0]*(d*.8),l[1]*(d*.8)],h=[e.position[0]-l[0]*(u/2)+p[0],e.position[1]-l[1]*(u/2)+p[1]],m=[e.position[0]-l[0]*u+p[0],e.position[1]-l[1]*u+p[1]],g=[h[0]+a[0]*(f/2),h[1]+a[1]*(f/2)],y=[h[0]-a[0]*(f/2),h[1]-a[1]*(f/2)],k=[e.position[0]+p[0],e.position[1]+p[1]];return`${k[0]},${k[1]} ${g[0]},${g[1]} ${m[0]},${m[1]} ${y[0]},${y[1]}`});return(l,a)=>t.value?(c.openBlock(),c.createElementBlock("g",nf,[n.kind===c.unref(Y.ArrowHeadKind).V&&o.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:0},[c.createElementVNode("line",{x1:o.value.p1[0],y1:o.value.p1[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,of),c.createElementVNode("line",{x1:o.value.p2[0],y1:o.value.p2[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,rf)],64)):n.kind===c.unref(Y.ArrowHeadKind).Delta&&r.value?(c.openBlock(),c.createElementBlock("polygon",{key:1,points:r.value,fill:n.color},null,8,sf)):n.kind===c.unref(Y.ArrowHeadKind).Circle&&s.value?(c.openBlock(),c.createElementBlock("circle",{key:2,cx:s.value.center[0],cy:s.value.center[1],r:s.value.radius,fill:n.color},null,8,lf)):n.kind===c.unref(Y.ArrowHeadKind).Diamond&&i.value?(c.openBlock(),c.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,af)):c.createCommentVNode("",!0)])):c.createCommentVNode("",!0)}}),uf={class:"arrow-svg",preserveAspectRatio:"none"},ff=["d","stroke","stroke-width"],hf=["x1","y1","x2","y2","stroke","stroke-width"],pf=["d"],mf=["x1","y1","x2","y2"],gf=c.defineComponent({__name:"ArcArrow",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=c.ref(null),o=c.ref(0),r=c.ref(0),s=fe(e.entityId,x.Color),i=fe(e.entityId,Y.ArcArrow);let l=null;c.onMounted(()=>{t.value&&(l=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),l.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),c.onUnmounted(()=>{l==null||l.disconnect()});const a=c.computed(()=>{if(!s.value)return"#000000";const b=s.value.red.toString(16).padStart(2,"0"),S=s.value.green.toString(16).padStart(2,"0"),v=s.value.blue.toString(16).padStart(2,"0");return`#${b}${S}${v}`}),d=c.computed(()=>{var b;return((b=i.value)==null?void 0:b.value[6])??2}),u=c.computed(()=>`${d.value}px`),f=c.computed(()=>e.hovered||e.selected),p=c.computed(()=>{if(!i.value)return!1;const b=i.value.value,S=Me.Arc.create(b[0],b[1],b[2],b[3],b[4],b[5],b[6]);return!Me.Arc.isCollinear(S)}),h=c.computed(()=>{if(!i.value)return null;const b=i.value.value,S=o.value,v=r.value;return Me.Arc.create(b[0]*S,b[1]*v,b[2]*S,b[3]*v,b[4]*S,b[5]*v,b[6])}),m=c.computed(()=>!h.value||!p.value?null:Me.Arc.compute(h.value)),g=c.computed(()=>{var K,G,te,W;if(!i.value||!h.value)return null;const b=h.value,S=i.value.startArrowHead,v=i.value.endArrowHead,E=Me.Arc.length(b);let C=i.value.trimStart;if((K=e.connector)!=null&&K.startBlock&&S!=="none"){const L=((G=mn(S))==null?void 0:G.gap)??0,F=E>0?L/E:0;C+=F}let M=i.value.trimEnd;if((te=e.connector)!=null&&te.endBlock&&v!=="none"){const L=((W=mn(v))==null?void 0:W.gap)??0,F=E>0?L/E:0;M+=F}const B=1-M,I=Me.Arc.parametricToPoint(b,C),_=Me.Arc.parametricToPoint(b,B),j=w(Me.Arc.directionAt(b,C)),H=Me.Arc.directionAt(b,B);return{start:I,end:_,startDir:j,endDir:H,tStart:C,tEnd:B,startHead:S,endHead:v}}),y=c.computed(()=>{if(!g.value||!m.value||!p.value)return"";const{start:b,end:S,tStart:v,tEnd:E}=g.value,{radius:C,clockwise:M,arcAngle:B}=m.value,_=B*(E-v)>Math.PI?1:0,j=M?0:1;return`M ${b[0]} ${b[1]} A ${C} ${C} 0 ${_} ${j} ${S[0]} ${S[1]}`}),k=c.computed(()=>!g.value||p.value?null:{x1:g.value.start[0],y1:g.value.start[1],x2:g.value.end[0],y2:g.value.end[1]});function w(b){return[-b[0],-b[1]]}return(b,S)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(c.openBlock(),c.createElementBlock("svg",uf,[p.value&&y.value?(c.openBlock(),c.createElementBlock("path",{key:0,d:y.value,stroke:a.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,ff)):k.value?(c.openBlock(),c.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,stroke:a.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,hf)):c.createCommentVNode("",!0),g.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[g.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{key:0,position:g.value.start,direction:g.value.startDir,thickness:u.value,"arrow-thickness":d.value,color:a.value,kind:g.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),g.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{key:1,position:g.value.end,direction:g.value.endDir,thickness:u.value,"arrow-thickness":d.value,color:a.value,kind:g.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),f.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[p.value&&y.value?(c.openBlock(),c.createElementBlock("path",{key:0,d:y.value,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,pf)):k.value?(c.openBlock(),c.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,mf)):c.createCommentVNode("",!0),g.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{key:2,position:g.value.start,direction:g.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):c.createCommentVNode("",!0),g.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{key:3,position:g.value.end,direction:g.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)]))],512))}}),Wt=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},Oi=Wt(gf,[["__scopeId","data-v-bcf5b4f3"]]),yf={},kf={class:"wov-arrow-handle"};function wf(n,e){return c.openBlock(),c.createElementBlock("div",kf,[...e[0]||(e[0]=[c.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const Di=Wt(yf,[["render",wf]]),bf={},xf={class:"wov-arrow-terminal"};function Sf(n,e){return c.openBlock(),c.createElementBlock("div",xf,[...e[0]||(e[0]=[c.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[c.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const Ri=Wt(bf,[["render",Sf]]),Cf={class:"arrow-svg",preserveAspectRatio:"none"},vf=["x1","y1","x2","y2"],Ef=["x1","y1","x2","y2","stroke","stroke-width"],Mf=["x1","y1","x2","y2"],_i=Wt(c.defineComponent({__name:"ElbowArrow",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=c.ref(null),o=c.ref(0),r=c.ref(0),s=fe(e.entityId,x.Color),i=fe(e.entityId,Y.ElbowArrow),l=c.computed(()=>e.hovered||e.selected);let a=null;c.onMounted(()=>{t.value&&(a=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),c.onUnmounted(()=>{a==null||a.disconnect()});const d=c.computed(()=>{if(!s.value)return"#000000";const g=s.value.red.toString(16).padStart(2,"0"),y=s.value.green.toString(16).padStart(2,"0"),k=s.value.blue.toString(16).padStart(2,"0");return`#${g}${y}${k}`}),u=c.computed(()=>{var g;return((g=i.value)==null?void 0:g.thickness)??2}),f=c.computed(()=>`${u.value}px`),p=c.computed(()=>{if(!i.value)return[];const g=i.value,y=o.value,k=r.value,w=[];for(let b=0;b<g.pointCount;b++){const S=g.points[b*2]*y,v=g.points[b*2+1]*k;w.push([S,v])}return w}),h=c.computed(()=>{const g=p.value;if(g.length<2)return[];const y=[];for(let k=0;k<g.length-1;k++)y.push({start:g[k],end:g[k+1]});return y}),m=c.computed(()=>{var B,I,_,j;if(!i.value||p.value.length<2)return null;const g=i.value,y=[...p.value.map(H=>[...H])],k=g.startArrowHead,w=g.endArrowHead,b=[y[1][0]-y[0][0],y[1][1]-y[0][1]],S=[y[y.length-1][0]-y[y.length-2][0],y[y.length-1][1]-y[y.length-2][1]];let v=g.trimStart;if((B=e.connector)!=null&&B.startBlock&&k!=="none"){const H=Math.hypot(b[0],b[1]),K=((I=mn(k))==null?void 0:I.gap)??0,G=H>0?K/H:0;v+=G}let E=g.trimEnd;if((_=e.connector)!=null&&_.endBlock&&w!=="none"){const H=Math.hypot(S[0],S[1]),K=((j=mn(w))==null?void 0:j.gap)??0,G=H>0?K/H:0;E+=G}y[0]=[y[0][0]+(y[1][0]-y[0][0])*v,y[0][1]+(y[1][1]-y[0][1])*v];const C=y.length-1;y[C]=[y[C-1][0]+(y[C][0]-y[C-1][0])*(1-E),y[C-1][1]+(y[C][1]-y[C-1][1])*(1-E)];const M=[];for(let H=0;H<y.length-1;H++)M.push({start:y[H],end:y[H+1]});return Me.Vec2.scale(b,-1),{points:y,lines:M,startPos:y[0],endPos:y[y.length-1],startDir:b,endDir:S,startHead:k,endHead:w}});return(g,y)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(c.openBlock(),c.createElementBlock("svg",Cf,[l.value&&h.value.length>0?(c.openBlock(!0),c.createElementBlock(c.Fragment,{key:0},c.renderList(h.value,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:"bg-"+w,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-bg",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))","stroke-dasharray":"calc(12px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,vf))),128)):c.createCommentVNode("",!0),m.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(m.value.lines,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:w,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],stroke:d.value,fill:"none","stroke-width":f.value,"stroke-linecap":"round"},null,8,Ef))),128)),m.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),m.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),l.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(m.value.lines,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:"hl-"+w,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,Mf))),128)),m.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):c.createCommentVNode("",!0),m.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)]))],512))}}),[["__scopeId","data-v-b2719db1"]]),{PI:Tf}=Math,Rn=Tf+1e-4,Pi=.5,Vi=[1,1];function $i(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:Br}=Math;function Li(n,e,t){let o=Br(1,e/t);return Br(1,n+(Br(1,1-o)-n)*(o*.275))}function Nf(n){return[-n[0],-n[1]]}function Qe(n,e){return[n[0]+e[0],n[1]+e[1]]}function zi(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function wt(n,e){return[n[0]-e[0],n[1]-e[1]]}function Ar(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function bt(n,e){return[n[0]*e,n[1]*e]}function Ir(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function Bf(n,e){return[n[0]/e,n[1]/e]}function Fi(n){return[n[1],-n[0]]}function Or(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function Hi(n,e){return n[0]*e[0]+n[1]*e[1]}function Af(n,e){return n[0]===e[0]&&n[1]===e[1]}function If(n){return Math.hypot(n[0],n[1])}function Wi(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function ji(n){return Bf(n,If(n))}function Of(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function Dr(n,e,t){let o=Math.sin(t),r=Math.cos(t),s=n[0]-e[0],i=n[1]-e[1],l=s*r-i*o,a=s*o+i*r;return[l+e[0],a+e[1]]}function Ui(n,e,t,o){let r=Math.sin(o),s=Math.cos(o),i=e[0]-t[0],l=e[1]-t[1],a=i*s-l*r,d=i*r+l*s;return n[0]=a+t[0],n[1]=d+t[1],n}function Ki(n,e,t){return Qe(n,bt(wt(e,n),t))}function Df(n,e,t,o){let r=t[0]-e[0],s=t[1]-e[1];return n[0]=e[0]+r*o,n[1]=e[1]+s*o,n}function qi(n,e,t){return Qe(n,bt(e,t))}const ye=[0,0],xt=[0,0],St=[0,0];function Rf(n,e){let t=qi(n,ji(Fi(wt(n,Qe(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(Dr(t,n,Rn*2*s));return o}function _f(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(Dr(e,n,Rn*s));return o}function Pf(n,e,t){let o=wt(e,t),r=bt(o,.5),s=bt(o,.51);return[wt(n,r),wt(n,s),Qe(n,s),Qe(n,r)]}function Vf(n,e,t,o){let r=[],s=qi(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(Dr(s,n,Rn*3*l));return r}function $f(n,e,t){return[Qe(n,bt(e,t)),Qe(n,bt(e,t*.99)),wt(n,bt(e,t*.99)),wt(n,bt(e,t))]}function Ji(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function Lf(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=Li(o,r.distance,t)),(o+s)/2},n[0].pressure)}function zf(n,e={}){let{size:t=16,smoothing:o=.5,thinning:r=.5,simulatePressure:s=!0,easing:i=W=>W,start:l={},end:a={},last:d=!1}=e,{cap:u=!0,easing:f=W=>W*(2-W)}=l,{cap:p=!0,easing:h=W=>--W*W*W+1}=a;if(n.length===0||t<=0)return[];let m=n[n.length-1].runningLength,g=Ji(l.taper,t,m),y=Ji(a.taper,t,m),k=(t*o)**2,w=[],b=[],S=Lf(n,s,t),v=$i(t,r,n[n.length-1].pressure,i),E,C=n[0].vector,M=n[0].point,B=M,I=M,_=B,j=!1;for(let W=0;W<n.length;W++){let{pressure:L}=n[W],{point:F,vector:X,distance:ie,runningLength:Q}=n[W],ce=W===n.length-1;if(!ce&&m-Q<3)continue;r?(s&&(L=Li(S,ie,t)),v=$i(t,r,L,i)):v=t/2,E===void 0&&(E=v);let Xe=Q<g?f(Q/g):1,yt=m-Q<y?h((m-Q)/y):1;v=Math.max(.01,v*Math.min(Xe,yt));let hn=(ce?n[W]:n[W+1]).vector,Ft=ce?1:Hi(X,hn),Mr=Hi(X,C)<0&&!j,Dn=Ft!==null&&Ft<0;if(Mr||Dn){Or(ye,C),Ir(ye,ye,v);for(let Ht=0;Ht<=1;Ht+=.07692307692307693)Ar(xt,F,ye),Ui(xt,xt,F,Rn*Ht),I=[xt[0],xt[1]],w.push(I),zi(St,F,ye),Ui(St,St,F,Rn*-Ht),_=[St[0],St[1]],b.push(_);M=I,B=_,Dn&&(j=!0);continue}if(j=!1,ce){Or(ye,X),Ir(ye,ye,v),w.push(wt(F,ye)),b.push(Qe(F,ye));continue}Df(ye,hn,X,Ft),Or(ye,ye),Ir(ye,ye,v),Ar(xt,F,ye),I=[xt[0],xt[1]],(W<=1||Wi(M,I)>k)&&(w.push(I),M=I),zi(St,F,ye),_=[St[0],St[1]],(W<=1||Wi(B,_)>k)&&(b.push(_),B=_),S=L,C=X}let H=[n[0].point[0],n[0].point[1]],K=n.length>1?[n[n.length-1].point[0],n[n.length-1].point[1]]:Qe(n[0].point,[1,1]),G=[],te=[];if(n.length===1){if(!(g||y)||d)return Rf(H,E||v)}else{g||y&&n.length===1||(u?G.push(..._f(H,b[0],13)):G.push(...Pf(H,w[0],b[0])));let W=Fi(Nf(n[n.length-1].vector));y||g&&n.length===1?te.push(K):p?te.push(...Vf(K,W,v,29)):te.push(...$f(K,W,v))}return w.concat(te,b.reverse(),G)}const Gi=[0,0];function Yi(n){return n!=null&&n>=0}function Ff(n,e={}){var p;let{streamline:t=.5,size:o=16,last:r=!1}=e;if(n.length===0)return[];let s=.15+(1-t)*.85,i=Array.isArray(n[0])?n:n.map(({x:h,y:m,pressure:g=Pi})=>[h,m,g]);if(i.length===2){let h=i[1];i=i.slice(0,-1);for(let m=1;m<5;m++)i.push(Ki(i[0],h,m/4))}i.length===1&&(i=[...i,[...Qe(i[0],Vi),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Yi(i[0][2])?i[0][2]:.25,vector:[...Vi],distance:0,runningLength:0}],a=!1,d=0,u=l[0],f=i.length-1;for(let h=1;h<i.length;h++){let m=r&&h===f?[i[h][0],i[h][1]]:Ki(u.point,i[h],s);if(Af(u.point,m))continue;let g=Of(m,u.point);if(d+=g,h<f&&!a){if(d<o)continue;a=!0}Ar(Gi,u.point,m),u={point:m,pressure:Yi(i[h][2])?i[h][2]:Pi,vector:ji(Gi),distance:g,runningLength:d},l.push(u)}return l[0].vector=((p=l[1])==null?void 0:p.vector)||[0,0],l}function Rr(n,e={}){return zf(Ff(n,e),e)}const Hf={class:"wov-eraser-stroke"},Wf={preserveAspectRatio:"none"},jf=["d"],Uf="#88888833",Xi=c.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=fe(e.entityId,po.EraserStroke),o=fe(e.entityId,x.Block),r=c.shallowRef("");function s(l,a){return(l+a)/2}function i(l,a,d,u,f,p){if(l<=4)return"";const h=[],m=Math.min(l,po.POINTS_CAPACITY);for(let S=0;S<m;S++){const v=(a+S)%po.POINTS_CAPACITY*2;h.push([d[v]-f,d[v+1]-p])}const g=Rr(h,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const w=g[2];let b=`M${y[0].toFixed(2)},${y[1].toFixed(2)} Q${k[0].toFixed(2)},${k[1].toFixed(2)} ${s(k[0],w[0]).toFixed(2)},${s(k[1],w[1]).toFixed(2)} T`;for(let S=2;S<g.length-1;S++)y=g[S],k=g[S+1],b+=`${s(y[0],k[0]).toFixed(2)},${s(y[1],k[1]).toFixed(2)} `;return b+=`${k[0].toFixed(2)},${k[1].toFixed(2)} `,b+="Z",b}return c.watch([t,o],([l,a])=>{if(!l||!a){r.value="";return}const d=l.radius??8,[u,f]=a.position;r.value=i(l.pointCount,l.firstPointIndex,l.points,2*d,u,f)},{immediate:!0}),(l,a)=>(c.openBlock(),c.createElementBlock("div",Hf,[(c.openBlock(),c.createElementBlock("svg",Wf,[c.createElementVNode("path",{d:r.value,fill:Uf},null,8,jf)]))]))}}),Kf={class:"wov-image-block"},qf={key:0,class:"wov-image-placeholder"},Jf={key:1,class:"wov-image-placeholder wov-image-error"},Gf=["src","alt"],Yf={key:3,class:"wov-image-upload-overlay"},Xf={class:"wov-image-upload-status"},Zi=c.defineComponent({__name:"ImageBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=c.inject($e);if(!t)throw new Error("ImageBlock must be used within a WovenCanvas component");const o=t,r=fe(e.entityId,x.Asset),s=fe(e.entityId,x.Image),i=c.ref(null),l=c.ref(!0),a=c.ref(!1);let d=!0;c.onUnmounted(()=>{d=!1});async function u(){const h=o.getAssetManager();if(!h){l.value=!1,a.value=!0;return}const m=r.value;if(!m){l.value=!1;return}try{l.value=!0,a.value=!1;const g=await h.getDisplayUrl(m.identifier);if(!d)return;g?(i.value=g,l.value=!1):m.uploadState===x.UploadState.Failed&&(a.value=!0,l.value=!1)}catch(g){if(!d)return;console.error("Failed to get display URL:",g),a.value=!0,l.value=!1}}c.watch(()=>r.value,()=>{u()},{immediate:!0}),c.onMounted(()=>{u()});const f=c.computed(()=>{const h=r.value;if(!h)return null;switch(h.uploadState){case x.UploadState.Pending:return"Loading...";case x.UploadState.Uploading:return"Loading...";case x.UploadState.Failed:return"Failed";default:return null}}),p=c.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(h,m)=>{var g;return c.openBlock(),c.createElementBlock("div",Kf,[l.value&&!i.value?(c.openBlock(),c.createElementBlock("div",qf,[...m[0]||(m[0]=[c.createElementVNode("span",null,"Loading...",-1)])])):a.value?(c.openBlock(),c.createElementBlock("div",Jf,[...m[1]||(m[1]=[c.createElementVNode("span",null,"Failed to load image",-1)])])):i.value?(c.openBlock(),c.createElementBlock("img",{key:2,src:i.value,alt:((g=c.unref(s))==null?void 0:g.alt)||"",style:c.normalizeStyle(p.value),draggable:"false"},null,12,Gf)):c.createCommentVNode("",!0),f.value?(c.openBlock(),c.createElementBlock("div",Yf,[c.createElementVNode("span",Xf,c.toDisplayString(f.value),1)])):c.createCommentVNode("",!0)])}}}),Zf=["data-complete"],Qf={preserveAspectRatio:"none"},eh=["d","fill"],th={key:0,class:"highlight",preserveAspectRatio:"none"},nh=["d"],Qi=Wt(c.defineComponent({__name:"PenStroke",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,mo.PenStroke),o=fe(e.entityId,x.Block),r=fe(e.entityId,x.Color),s=c.shallowRef(""),i=c.shallowRef("");function l(f,p){return(f+p)/2}function a(f,p,h){if(p<=4||f.length<3){const w=h/2;return`M ${w},0 a ${w},${w} 0 1 0 0.0001 0`}let m=f[0],g=f[1];const y=f[2];let k=`M${m[0].toFixed(2)},${m[1].toFixed(2)} Q${g[0].toFixed(2)},${g[1].toFixed(2)} ${l(g[0],y[0]).toFixed(2)},${l(g[1],y[1]).toFixed(2)} T`;for(let w=2;w<f.length-1;w++)m=f[w],g=f[w+1],k+=`${l(m[0],g[0]).toFixed(2)},${l(m[1],g[1]).toFixed(2)} `;return k+=`${g[0].toFixed(2)},${g[1].toFixed(2)} `,k+="Z",k}c.watch([t,o],([f,p])=>{if(!f||!p){s.value="",i.value="";return}if(!f.originalWidth||!f.originalHeight){s.value="",i.value="";return}const h=p.size[0]/f.originalWidth,m=p.size[1]/f.originalHeight,g=[];for(let k=0;k<f.pointCount;k++){const w=f.points[k*2],b=f.points[k*2+1],S=(w-f.originalLeft)*h,v=(b-f.originalTop)*m;f.hasPressure?g.push([S,v,f.pressures[k]]):g.push([S,v])}const y=Rr(g,{last:f.isComplete,size:f.thickness,simulatePressure:!f.hasPressure});if(s.value=a(y,f.pointCount,f.thickness),f.isComplete){const k=g.length===1?f.thickness:1,w=Rr(g,{last:!0,size:k,simulatePressure:!f.hasPressure});i.value=a(w,f.pointCount,k)}},{immediate:!0});const d=c.computed(()=>r.value?`rgb(${r.value.red}, ${r.value.green}, ${r.value.blue})`:"#000000"),u=c.computed(()=>e.selected||e.hovered);return(f,p)=>{var h;return c.openBlock(),c.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((h=c.unref(t))==null?void 0:h.isComplete)||void 0},[(c.openBlock(),c.createElementBlock("svg",Qf,[c.createElementVNode("path",{d:s.value,fill:d.value},null,8,eh)])),u.value?(c.openBlock(),c.createElementBlock("svg",th,[c.createElementVNode("path",{d:i.value,stroke:"var(--wov-highlighted-block-outline-color)",style:{"stroke-width":"calc(1px / var(--wov-zoom))"},fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},null,8,nh)])):c.createCommentVNode("",!0)],8,Zf)}}}),[["__scopeId","data-v-9b41c649"]]);function le(){const n=c.inject($e);if(!n)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>n.getEditor(),nextEditorTick(e){return new Promise(t=>{const o=n.getEditor();o&&o.nextTick(r=>{e==null||e(r),t(r)})})}}}const _n={rectangle:"M0,0 L100,0 L100,100 L0,100 Z",ellipse:"M50,0 A50,50 0 1,1 50,100 A50,50 0 1,1 50,0",triangle:"M50,0 L100,100 L0,100 Z",diamond:"M50,0 L100,50 L50,100 L0,50 Z",pentagon:"M50,0 L100,38.2 L80.9,100 L19.1,100 L0,38.2 Z",hexagon:"M50,0 L100,25 L100,75 L50,100 L0,75 L0,25 Z",star:"M50,0 L61.8,38.2 L100,38.2 L69.1,61.8 L80.9,100 L50,76.4 L19.1,100 L30.9,61.8 L0,38.2 L38.2,38.2 Z",heart:"M50,16 C44,7 37,0 26,0 11,0 0,12 0,28 0,60 16,65 50,100 84,65 100,60 100,28 100,12 89,0 74,0 63,0 56,7 50,16 Z",arrow:"M0,35 L60,35 L60,0 L100,50 L60,100 L60,65 L0,65 Z"};function ke(n){this.content=n}ke.prototype={constructor:ke,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var o=t&&t!=n?this.remove(t):this,r=o.find(n),s=o.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new ke(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new ke(t)},addToStart:function(n,e){return new ke([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new ke(t)},addBefore:function(n,e,t){var o=this.remove(e),r=o.content.slice(),s=o.find(n);return r.splice(s==-1?r.length:s,0,e,t),new ke(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=ke.from(n),n.size?new ke(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=ke.from(n),n.size?new ke(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=ke.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}},ke.from=function(n){if(n instanceof ke)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ke(e)};function el(n,e,t){for(let o=0;;o++){if(o==n.childCount||o==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(o),s=e.child(o);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let i=0;r.text[i]==s.text[i];i++)t++;return t}if(r.content.size||s.content.size){let i=el(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function tl(n,e,t,o){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:o};let i=n.child(--r),l=e.child(--s),a=i.nodeSize;if(i==l){t-=a,o-=a;continue}if(!i.sameMarkup(l))return{a:t,b:o};if(i.isText&&i.text!=l.text){let d=0,u=Math.min(i.text.length,l.text.length);for(;d<u&&i.text[i.text.length-d-1]==l.text[l.text.length-d-1];)d++,t--,o--;return{a:t,b:o}}if(i.content.size||l.content.size){let d=tl(i.content,l.content,t-1,o-1);if(d)return d}t-=a,o-=a}}class N{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let o=0;o<e.length;o++)this.size+=e[o].nodeSize}nodesBetween(e,t,o,r=0,s){for(let i=0,l=0;l<t;i++){let a=this.content[i],d=l+a.nodeSize;if(d>e&&o(a,r+l,s||null,i)!==!1&&a.content.size){let u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),o,r+u)}l=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,o,r){let s="",i=!0;return this.nodesBetween(e,t,(l,a)=>{let d=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&d||l.isTextblock)&&o&&(i?i=!1:s+=o),s+=d},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,o=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(o)&&(r[r.length-1]=t.withText(t.text+o.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new N(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let o=[],r=0;if(t>e)for(let s=0,i=0;i<t;s++){let l=this.content[s],a=i+l.nodeSize;a>e&&((i<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-i),Math.min(l.text.length,t-i)):l=l.cut(Math.max(0,e-i-1),Math.min(l.content.size,t-i-1))),o.push(l),r+=l.nodeSize),i=a}return new N(o,r)}cutByIndex(e,t){return e==t?N.empty:e==0&&t==this.content.length?this:new N(this.content.slice(e,t))}replaceChild(e,t){let o=this.content[e];if(o==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-o.nodeSize;return r[e]=t,new N(r,s)}addToStart(e){return new N([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new N(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,o=0;t<this.content.length;t++){let r=this.content[t];e(r,o,t),o+=r.nodeSize}}findDiffStart(e,t=0){return el(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return tl(this,e,t,o)}findIndex(e){if(e==0)return go(0,e);if(e==this.size)return go(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,o=0;;t++){let r=this.child(t),s=o+r.nodeSize;if(s>=e)return s==e?go(t+1,s):go(t,o);o=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return N.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new N(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return N.empty;let t,o=0;for(let r=0;r<e.length;r++){let s=e[r];o+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new N(t||e,o)}static from(e){if(!e)return N.empty;if(e instanceof N)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new N([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}N.empty=new N([],0);const _r={index:0,offset:0};function go(n,e){return _r.index=n,_r.offset=e,_r}function yo(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let o=0;o<n.length;o++)if(!yo(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!yo(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let Z=class Mi{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,o=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!o&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),o=!0),t&&t.push(s)}}return t||(t=e.slice()),o||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&yo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let o=e.marks[t.type];if(!o)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=o.create(t.attrs);return o.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let o=0;o<e.length;o++)if(!e[o].eq(t[o]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Mi.none;if(e instanceof Mi)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};Z.none=[];class ko extends Error{}class R{constructor(e,t,o){this.content=e,this.openStart=t,this.openEnd=o}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let o=ol(this.content,e+this.openStart,t);return o&&new R(o,this.openStart,this.openEnd)}removeBetween(e,t){return new R(nl(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return R.empty;let o=t.openStart||0,r=t.openEnd||0;if(typeof o!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new R(N.fromJSON(e,t.content),o,r)}static maxOpen(e,t=!0){let o=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)o++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new R(e,o,r)}}R.empty=new R(N.empty,0,0);function nl(n,e,t){let{index:o,offset:r}=n.findIndex(e),s=n.maybeChild(o),{index:i,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(i).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(o!=i)throw new RangeError("Removing non-flat range");return n.replaceChild(o,s.copy(nl(s.content,e-r-1,t-r-1)))}function ol(n,e,t,o){let{index:r,offset:s}=n.findIndex(e),i=n.maybeChild(r);if(s==e||i.isText)return o&&!o.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ol(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function oh(n,e,t){if(t.openStart>n.depth)throw new ko("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new ko("Inconsistent open depths");return rl(n,e,t,0)}function rl(n,e,t,o){let r=n.index(o),s=n.node(o);if(r==e.index(o)&&o<n.depth-t.openStart){let i=rl(n,e,t,o+1);return s.copy(s.content.replaceChild(r,i))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==o&&e.depth==o){let i=n.parent,l=i.content;return Ut(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=rh(t,n);return Ut(s,il(n,i,l,e,o))}else return Ut(s,wo(n,e,o))}function sl(n,e){if(!e.type.compatibleContent(n.type))throw new ko("Cannot join "+e.type.name+" onto "+n.type.name)}function Pr(n,e,t){let o=n.node(t);return sl(o,e.node(t)),o}function jt(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Pn(n,e,t,o){let r=(e||n).node(t),s=0,i=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(jt(n.nodeAfter,o),s++));for(let l=s;l<i;l++)jt(r.child(l),o);e&&e.depth==t&&e.textOffset&&jt(e.nodeBefore,o)}function Ut(n,e){return n.type.checkContent(e),n.copy(e)}function il(n,e,t,o,r){let s=n.depth>r&&Pr(n,e,r+1),i=o.depth>r&&Pr(t,o,r+1),l=[];return Pn(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(sl(s,i),jt(Ut(s,il(n,e,t,o,r+1)),l)):(s&&jt(Ut(s,wo(n,e,r+1)),l),Pn(e,t,r,l),i&&jt(Ut(i,wo(t,o,r+1)),l)),Pn(o,null,r,l),new N(l)}function wo(n,e,t){let o=[];if(Pn(null,n,t,o),n.depth>t){let r=Pr(n,e,t+1);jt(Ut(r,wo(n,e,t+1)),o)}return Pn(e,null,t,o),new N(o)}function rh(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(N.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class Vn{constructor(e,t,o){this.pos=e,this.path=t,this.parentOffset=o,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let o=this.pos-this.path[this.path.length-1],r=e.child(t);return o?e.child(t).cut(o):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let o=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=o.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Z.none;if(this.textOffset)return e.child(t).marks;let o=e.maybeChild(t-1),r=e.maybeChild(t);if(!o){let l=o;o=r,r=l}let s=o.marks;for(var i=0;i<s.length;i++)s[i].type.spec.inclusive===!1&&(!r||!s[i].isInSet(r.marks))&&(s=s[i--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let o=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<o.length;s++)o[s].type.spec.inclusive===!1&&(!r||!o[s].isInSet(r.marks))&&(o=o[s--].removeFromSet(o));return o}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let o=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);o>=0;o--)if(e.pos<=this.end(o)&&(!t||t(this.node(o))))return new bo(this,e,o);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let o=[],r=0,s=t;for(let i=e;;){let{index:l,offset:a}=i.content.findIndex(s),d=s-a;if(o.push(i,l,r+a),!d||(i=i.child(l),i.isText))break;s=d-1,r+=a+1}return new Vn(t,o,s)}static resolveCached(e,t){let o=ll.get(e);if(o)for(let s=0;s<o.elts.length;s++){let i=o.elts[s];if(i.pos==t)return i}else ll.set(e,o=new sh);let r=o.elts[o.i]=Vn.resolve(e,t);return o.i=(o.i+1)%ih,r}}class sh{constructor(){this.elts=[],this.i=0}}const ih=12,ll=new WeakMap;class bo{constructor(e,t,o){this.$from=e,this.$to=t,this.depth=o}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const lh=Object.create(null);let ct=class Ti{constructor(e,t,o,r=Z.none){this.type=e,this.attrs=t,this.marks=r,this.content=o||N.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,o,r=0){this.content.nodesBetween(e,t,o,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,o,r){return this.content.textBetween(e,t,o,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,o){return this.type==e&&yo(this.attrs,t||e.defaultAttrs||lh)&&Z.sameSet(this.marks,o||Z.none)}copy(e=null){return e==this.content?this:new Ti(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Ti(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,o=!1){if(e==t)return R.empty;let r=this.resolve(e),s=this.resolve(t),i=o?0:r.sharedDepth(t),l=r.start(i),d=r.node(i).content.cut(r.pos-l,s.pos-l);return new R(d,r.depth-i,s.depth-i)}replace(e,t,o){return oh(this.resolve(e),this.resolve(t),o)}nodeAt(e){for(let t=this;;){let{index:o,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(o),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:o}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:o}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:o}=this.content.findIndex(e);if(o<e)return{node:this.content.child(t),index:t,offset:o};let r=this.content.child(t-1);return{node:r,index:t-1,offset:o-r.nodeSize}}resolve(e){return Vn.resolveCached(this,e)}resolveNoCache(e){return Vn.resolve(this,e)}rangeHasMark(e,t,o){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(o.isInSet(s.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),al(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,o=N.empty,r=0,s=o.childCount){let i=this.contentMatchAt(e).matchFragment(o,r,s),l=i&&i.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=r;a<s;a++)if(!this.type.allowsMarks(o.child(a).marks))return!1;return!0}canReplaceWith(e,t,o,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(o),i=s&&s.matchFragment(this.content,t);return i?i.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=Z.none;for(let t=0;t<this.marks.length;t++){let o=this.marks[t];o.type.checkAttrs(o.attrs),e=o.addToSet(e)}if(!Z.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let o;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");o=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,o)}let r=N.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,o);return s.type.checkAttrs(s.attrs),s}};ct.prototype.text=void 0;class xo extends ct{constructor(e,t,o,r){if(super(e,t,null,r),!o)throw new RangeError("Empty text nodes are not allowed");this.text=o}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):al(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new xo(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new xo(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function al(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Kt{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new ah(e,t);if(o.next==null)return Kt.empty;let r=cl(o);o.next&&o.err("Unexpected trailing text");let s=mh(ph(r));return gh(s,o),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,o=e.childCount){let r=this;for(let s=t;r&&s<o;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let o=0;o<e.next.length;o++)if(this.next[t].type==e.next[o].type)return!0;return!1}fillBefore(e,t=!1,o=0){let r=[this];function s(i,l){let a=i.matchFragment(e,o);if(a&&(!t||a.validEnd))return N.from(l.map(d=>d.createAndFill()));for(let d=0;d<i.next.length;d++){let{type:u,next:f}=i.next[d];if(!(u.isText||u.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let p=s(f,l.concat(u));if(p)return p}}return null}return s(this,[])}findWrapping(e){for(let o=0;o<this.wrapCache.length;o+=2)if(this.wrapCache[o]==e)return this.wrapCache[o+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),o=[{match:this,type:null,via:null}];for(;o.length;){let r=o.shift(),s=r.match;if(s.matchType(e)){let i=[];for(let l=r;l.type;l=l.via)i.push(l.type);return i.reverse()}for(let i=0;i<s.next.length;i++){let{type:l,next:a}=s.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||a.validEnd)&&(o.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(o){e.push(o);for(let r=0;r<o.next.length;r++)e.indexOf(o.next[r].next)==-1&&t(o.next[r].next)}return t(this),e.map((o,r)=>{let s=r+(o.validEnd?"*":" ")+" ";for(let i=0;i<o.next.length;i++)s+=(i?", ":"")+o.next[i].type.name+"->"+e.indexOf(o.next[i].next);return s}).join(`
|
|
2
|
+
`)}}Kt.empty=new Kt(!0);class ah{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function cl(n){let e=[];do e.push(ch(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ch(n){let e=[];do e.push(dh(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function dh(n){let e=hh(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=uh(n,e);else break;return e}function dl(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function uh(n,e){let t=dl(n),o=t;return n.eat(",")&&(n.next!="}"?o=dl(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function fh(n,e){let t=n.nodeTypes,o=t[e];if(o)return[o];let r=[];for(let s in t){let i=t[s];i.isInGroup(e)&&r.push(i)}return r.length==0&&n.err("No node type or group '"+e+"' found"),r}function hh(n){if(n.eat("(")){let e=cl(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=fh(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function ph(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function o(i,l,a){let d={term:a,to:l};return e[i].push(d),d}function r(i,l){i.forEach(a=>a.to=l)}function s(i,l){if(i.type=="choice")return i.exprs.reduce((a,d)=>a.concat(s(d,l)),[]);if(i.type=="seq")for(let a=0;;a++){let d=s(i.exprs[a],l);if(a==i.exprs.length-1)return d;r(d,l=t())}else if(i.type=="star"){let a=t();return o(l,a),r(s(i.expr,a),a),[o(a)]}else if(i.type=="plus"){let a=t();return r(s(i.expr,l),a),r(s(i.expr,a),a),[o(a)]}else{if(i.type=="opt")return[o(l)].concat(s(i.expr,l));if(i.type=="range"){let a=l;for(let d=0;d<i.min;d++){let u=t();r(s(i.expr,a),u),a=u}if(i.max==-1)r(s(i.expr,a),a);else for(let d=i.min;d<i.max;d++){let u=t();o(a,u),r(s(i.expr,a),u),a=u}return[o(a)]}else{if(i.type=="name")return[o(l,void 0,i.value)];throw new Error("Unknown expr type")}}}}function ul(n,e){return e-n}function fl(n,e){let t=[];return o(e),t.sort(ul);function o(r){let s=n[r];if(s.length==1&&!s[0].term)return o(s[0].to);t.push(r);for(let i=0;i<s.length;i++){let{term:l,to:a}=s[i];!l&&t.indexOf(a)==-1&&o(a)}}}function mh(n){let e=Object.create(null);return t(fl(n,0));function t(o){let r=[];o.forEach(i=>{n[i].forEach(({term:l,to:a})=>{if(!l)return;let d;for(let u=0;u<r.length;u++)r[u][0]==l&&(d=r[u][1]);fl(n,a).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new Kt(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(ul);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function gh(n,e){for(let t=0,o=[n];t<o.length;t++){let r=o[t],s=!r.validEnd,i=[];for(let l=0;l<r.next.length;l++){let{type:a,next:d}=r.next[l];i.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),o.indexOf(d)==-1&&o.push(d)}s&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function hl(n){let e=Object.create(null);for(let t in n){let o=n[t];if(!o.hasDefault)return null;e[t]=o.default}return e}function pl(n,e){let t=Object.create(null);for(let o in n){let r=e&&e[o];if(r===void 0){let s=n[o];if(s.hasDefault)r=s.default;else throw new RangeError("No value supplied for attribute "+o)}t[o]=r}return t}function ml(n,e,t,o){for(let r in e)if(!(r in n))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${r}`);for(let r in n){let s=n[r];s.validate&&s.validate(e[r])}}function gl(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new kh(n,o,e[o]);return t}let yl=class Yu{constructor(e,t,o){this.name=e,this.schema=t,this.spec=o,this.markSet=null,this.groups=o.group?o.group.split(" "):[],this.attrs=gl(e,o.attrs),this.defaultAttrs=hl(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(o.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Kt.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:pl(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ct(this,this.computeAttrs(e),N.from(t),Z.setFrom(o))}createChecked(e=null,t,o){return t=N.from(t),this.checkContent(t),new ct(this,this.computeAttrs(e),t,Z.setFrom(o))}createAndFill(e=null,t,o){if(e=this.computeAttrs(e),t=N.from(t),t.size){let i=this.contentMatch.fillBefore(t);if(!i)return null;t=i.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(N.empty,!0);return s?new ct(this,e,t.append(s),Z.setFrom(o)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let o=0;o<e.childCount;o++)if(!this.allowsMarks(e.child(o).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){ml(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let o=0;o<e.length;o++)this.allowsMarkType(e[o].type)?t&&t.push(e[o]):t||(t=e.slice(0,o));return t?t.length?t:Z.none:e}static compile(e,t){let o=Object.create(null);e.forEach((s,i)=>o[s]=new Yu(s,t,i));let r=t.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let s in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};function yh(n,e,t){let o=t.split("|");return r=>{let s=r===null?"null":typeof r;if(o.indexOf(s)<0)throw new RangeError(`Expected value of type ${o} for attribute ${e} on type ${n}, got ${s}`)}}class kh{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?yh(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class So{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=gl(e,r.attrs),this.excluded=null;let s=hl(this.attrs);this.instance=s?new Z(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Z(this,pl(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new So(s,r++,t,i)),o}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){ml(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class kl{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=ke.from(e.nodes),t.marks=ke.from(e.marks||{}),this.nodes=yl.compile(this.spec.nodes,this),this.marks=So.compile(this.spec.marks,this);let o=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],i=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=o[i]||(o[i]=Kt.parse(i,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?wl(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],i=s.spec.excludes;s.excluded=i==null?[s]:i==""?[]:wl(this,i.split(" "))}this.nodeFromJSON=r=>ct.fromJSON(this,r),this.markFromJSON=r=>Z.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,o,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof yl){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,o,r)}text(e,t){let o=this.nodes.text;return new xo(o,o.defaultAttrs,e,Z.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function wl(n,e){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=n.marks[r],i=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(r=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(r)>-1)&&t.push(i=a)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[o]+"'")}return t}function wh(n){return n.tag!=null}function bh(n){return n.style!=null}class dt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(wh(r))this.tags.push(r);else if(bh(r)){let s=/[^=]*/.exec(r.style)[0];o.indexOf(s)<0&&o.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let o=new Cl(this,t,!1);return o.addAll(e,Z.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new Cl(this,t,!0);return o.addAll(e,Z.none,t.from,t.to),R.maxOpen(o.finish())}matchTag(e,t,o){for(let r=o?this.tags.indexOf(o)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(Ch(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let i=s.getAttrs(e);if(i===!1)continue;s.attrs=i||void 0}return s}}}matchStyle(e,t,o,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let i=this.styles[s],l=i.style;if(!(l.indexOf(e)!=0||i.context&&!o.matchesContext(i.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(i.getAttrs){let a=i.getAttrs(t);if(a===!1)continue;i.attrs=a||void 0}return i}}}static schemaRules(e){let t=[];function o(r){let s=r.priority==null?50:r.priority,i=0;for(;i<t.length;i++){let l=t[i];if((l.priority==null?50:l.priority)<s)break}t.splice(i,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(i=>{o(i=vl(i)),i.mark||i.ignore||i.clearMark||(i.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(i=>{o(i=vl(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new dt(e,dt.schemaRules(e)))}}const bl={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},xh={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xl={ol:!0,ul:!0},$n=1,Vr=2,Ln=4;function Sl(n,e,t){return e!=null?(e?$n:0)|(e==="full"?Vr:0):n&&n.whitespace=="pre"?$n|Vr:t&~Ln}class Co{constructor(e,t,o,r,s,i){this.type=e,this.attrs=t,this.marks=o,this.solid=r,this.options=i,this.content=[],this.activeMarks=Z.none,this.match=s||(i&Ln?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(N.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let o=this.type.contentMatch,r;return(r=o.findWrapping(e.type))?(this.match=o,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&$n)){let o=this.content[this.content.length-1],r;if(o&&o.isText&&(r=/[ \t\r\n\u000c]+$/.exec(o.text))){let s=o;o.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=N.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(N.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!bl.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Cl{constructor(e,t,o){this.parser=e,this.options=t,this.isOpen=o,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,i=Sl(null,t.preserveWhitespace,0)|(o?Ln:0);r?s=new Co(r.type,r.attrs,Z.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new Co(null,null,Z.none,!0,null,i):s=new Co(e.schema.topNodeType,null,Z.none,!0,null,i),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let o=e.nodeValue,r=this.top,s=r.options&Vr?"full":this.localPreserveWS||(r.options&$n)>0,{schema:i}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(o)){if(s)if(s==="full")o=o.replace(/\r\n?/g,`
|
|
3
|
+
`);else if(i.linebreakReplacement&&/[\r\n]/.test(o)&&this.top.findWrapping(i.linebreakReplacement.create())){let l=o.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(i.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(i.text(l[a]),t,!/\S/.test(l[a]));o=""}else o=o.replace(/\r?\n|\r/g," ");else if(o=o.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(o)&&this.open==this.nodes.length-1){let l=r.content[r.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(o=o.slice(1))}o&&this.insertNode(i.text(o),t,!/\S/.test(o)),this.findInText(e)}else this.findInside(e)}addElement(e,t,o){let r=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i=e.nodeName.toLowerCase(),l;xl.hasOwnProperty(i)&&this.parser.normalizeLists&&Sh(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,o));e:if(a?a.ignore:xh.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let d,u=this.needsBlock;if(bl.hasOwnProperty(i))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),d=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=a&&a.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),d&&this.sync(s),this.needsBlock=u}else{let d=this.readStyles(e,t);d&&this.addElementByRule(e,a,d,a.consuming===!1?l:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
4
|
+
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let o=e.style;if(o&&o.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],i=o.getPropertyValue(s);if(i)for(let l=void 0;;){let a=this.parser.matchStyle(s,i,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(d=>!a.clearMark(d)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,o,r){let s,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),o,e.nodeName=="BR")||this.leafFallback(e,o);else{let a=this.enter(i,t.attrs||null,o,t.preserveWhitespace);a&&(s=!0,o=a)}else{let a=this.parser.schema.marks[t.mark];o=o.concat(a.create(t.attrs))}let l=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,o,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,o,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,o),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,o,r){let s=o||0;for(let i=o?e.childNodes[o]:e.firstChild,l=r==null?null:e.childNodes[r];i!=l;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,t);this.findAtPoint(e,s)}findPlace(e,t,o){let r,s;for(let i=this.open,l=0;i>=0;i--){let a=this.nodes[i],d=a.findWrapping(e);if(d&&(!r||r.length>d.length+l)&&(r=d,s=a,!d.length))break;if(a.solid){if(o)break;l+=2}}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t,o){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,o);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let i=Z.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):El(l.type,e.type))&&(i=l.addToSet(i));return s.content.push(e.mark(i)),!0}return!1}enter(e,t,o,r){let s=this.findPlace(e.create(t),o,!1);return s&&(s=this.enterInner(e,t,o,!0,r)),s}enterInner(e,t,o,r=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let l=Sl(e,s,i.options);i.options&Ln&&i.content.length==0&&(l|=Ln);let a=Z.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):El(d.type,e))?(a=d.addToSet(a),!1):!0),this.nodes.push(new Co(e,t,a,r,null,l)),this.open++,o}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=$n)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let o=this.nodes[t].content;for(let r=o.length-1;r>=0;r--)e+=o[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let o=0;o<this.find.length;o++)this.find[o].node==e&&this.find[o].offset==t&&(this.find[o].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,o){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(o?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),o=this.options.context,r=!this.isOpen&&(!o||o.parent.type==this.nodes[0].type),s=-(o?o.depth+1:0)+(r?0:1),i=(l,a)=>{for(;l>=0;l--){let d=t[l];if(d==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(i(l-1,a))return!0;return!1}else{let u=a>0||a==0&&r?this.nodes[a].type:o&&a>=s?o.node(a-s).type:null;if(!u||u.name!=d&&!u.isInGroup(d))return!1;a--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let o=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(o&&o.isTextblock&&o.defaultAttrs)return o}for(let t in this.parser.schema.nodes){let o=this.parser.schema.nodes[t];if(o.isTextblock&&o.defaultAttrs)return o}}}function Sh(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&xl.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function Ch(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function vl(n){let e={};for(let t in n)e[t]=n[t];return e}function El(n,e){let t=e.schema.nodes;for(let o in t){let r=t[o];if(!r.allowsMarkType(n))continue;let s=[],i=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:d,next:u}=l.edge(a);if(d==e||s.indexOf(u)<0&&i(u))return!0}};if(i(r.contentMatch))return!0}}class qt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=$r(t).createDocumentFragment());let r=o,s=[];return e.forEach(i=>{if(s.length||i.marks.length){let l=0,a=0;for(;l<s.length&&a<i.marks.length;){let d=i.marks[a];if(!this.marks[d.type.name]){a++;continue}if(!d.eq(s[l][0])||d.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<i.marks.length;){let d=i.marks[a++],u=this.serializeMark(d,i.isInline,t);u&&(s.push([d,r]),r.appendChild(u.dom),r=u.contentDOM||u.dom)}}r.appendChild(this.serializeNodeInner(i,t))}),o}serializeNodeInner(e,t){let{dom:o,contentDOM:r}=vo($r(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return o}serializeNode(e,t={}){let o=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(o),o=s.dom)}return o}serializeMark(e,t,o={}){let r=this.marks[e.type.name];return r&&vo($r(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return vo(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new qt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Ml(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return Ml(e.marks)}}function Ml(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function $r(n){return n.document||window.document}const Tl=new WeakMap;function vh(n){let e=Tl.get(n);return e===void 0&&Tl.set(n,e=Eh(n)),e}function Eh(n){let e=null;function t(o){if(o&&typeof o=="object")if(Array.isArray(o))if(typeof o[0]=="string")e||(e=[]),e.push(o);else for(let r=0;r<o.length;r++)t(o[r]);else for(let r in o)t(o[r])}return t(n),e}function vo(n,e,t,o){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(o&&(s=vh(o))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let i=r.indexOf(" ");i>0&&(t=r.slice(0,i),r=r.slice(i+1));let l,a=t?n.createElementNS(t,r):n.createElement(r),d=e[1],u=1;if(d&&typeof d=="object"&&d.nodeType==null&&!Array.isArray(d)){u=2;for(let f in d)if(d[f]!=null){let p=f.indexOf(" ");p>0?a.setAttributeNS(f.slice(0,p),f.slice(p+1),d[f]):f=="style"&&a.style?a.style.cssText=d[f]:a.setAttribute(f,d[f])}}for(let f=u;f<e.length;f++){let p=e[f];if(p===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:m}=vo(n,p,t,o);if(a.appendChild(h),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:a,contentDOM:l}}const Nl=65535,Bl=Math.pow(2,16);function Mh(n,e){return n+e*Bl}function Al(n){return n&Nl}function Th(n){return(n-(n&Nl))/Bl}const Il=1,Ol=2,Eo=4,Dl=8;class Lr{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&Dl)>0}get deletedBefore(){return(this.delInfo&(Il|Eo))>0}get deletedAfter(){return(this.delInfo&(Ol|Eo))>0}get deletedAcross(){return(this.delInfo&Eo)>0}}class _e{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&_e.empty)return _e.empty}recover(e){let t=0,o=Al(e);if(!this.inverted)for(let r=0;r<o;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[o*3]+t+Th(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,o){let r=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let d=this.ranges[l+s],u=this.ranges[l+i],f=a+d;if(e<=f){let p=d?e==a?-1:e==f?1:t:t,h=a+r+(p<0?0:u);if(o)return h;let m=e==(t<0?a:f)?null:Mh(l/3,e-a),g=e==a?Ol:e==f?Il:Eo;return(t<0?e!=a:e!=f)&&(g|=Dl),new Lr(h,g,m)}r+=u-d}return o?e+r:new Lr(e+r,0,null)}touches(e,t){let o=0,r=Al(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?o:0);if(a>e)break;let d=this.ranges[l+s],u=a+d;if(e<=u&&l==r*3)return!0;o+=this.ranges[l+i]-d}return!1}forEach(e){let t=this.inverted?2:1,o=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let i=this.ranges[r],l=i-(this.inverted?s:0),a=i+(this.inverted?0:s),d=this.ranges[r+t],u=this.ranges[r+o];e(l,l+d,a,a+u),s+=u-d}}invert(){return new _e(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?_e.empty:new _e(e<0?[0,-e,0]:[0,0,e])}}_e.empty=new _e([]);class zn{constructor(e,t,o=0,r=e?e.length:0){this.mirror=t,this.from=o,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new zn(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,o=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?o+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,o=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?o-r-1:void 0)}}invert(){let e=new zn;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let o=this.from;o<this.to;o++)e=this._maps[o].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,o){let r=0;for(let s=this.from;s<this.to;s++){let i=this._maps[s],l=i.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return o?e:new Lr(e,r,null)}}const zr=Object.create(null);class Ce{getMap(){return _e.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=zr[t.stepType];if(!o)throw new RangeError(`No step type ${t.stepType} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in zr)throw new RangeError("Duplicate use of step JSON ID "+e);return zr[e]=t,t.prototype.jsonID=e,t}}class ae{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new ae(e,null)}static fail(e){return new ae(null,e)}static fromReplace(e,t,o,r){try{return ae.ok(e.replace(t,o,r))}catch(s){if(s instanceof ko)return ae.fail(s.message);throw s}}}function Fr(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(Fr(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return N.fromArray(o)}class Ct extends Ce{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=e.resolve(this.from),r=o.node(o.sharedDepth(this.to)),s=new R(Fr(t.content,(i,l)=>!i.isAtom||!l.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),r),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,s)}invert(){return new Ke(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new Ct(t.pos,o.pos,this.mark)}merge(e){return e instanceof Ct&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ct(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Ct(t.from,t.to,e.markFromJSON(t.mark))}}Ce.jsonID("addMark",Ct);class Ke extends Ce{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=new R(Fr(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,o)}invert(){return new Ct(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new Ke(t.pos,o.pos,this.mark)}merge(e){return e instanceof Ke&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ke(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ke(t.from,t.to,e.markFromJSON(t.mark))}}Ce.jsonID("removeMark",Ke);class vt extends Ce{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new R(N.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let o=this.mark.addToSet(t.marks);if(o.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(o))return new vt(this.pos,t.marks[r]);return new vt(this.pos,this.mark)}}return new Jt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new vt(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new vt(t.pos,e.markFromJSON(t.mark))}}Ce.jsonID("addNodeMark",vt);class Jt extends Ce{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new R(N.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new vt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Jt(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Jt(t.pos,e.markFromJSON(t.mark))}}Ce.jsonID("removeNodeMark",Jt);class he extends Ce{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&Hr(e,this.from,this.to)?ae.fail("Structure replace would overwrite content"):ae.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new _e([this.from,this.to-this.from,this.slice.size])}invert(e){return new he(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deletedAcross&&o.deletedAcross?null:new he(t.pos,Math.max(t.pos,o.pos),this.slice,this.structure)}merge(e){if(!(e instanceof he)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?R.empty:new R(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new he(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?R.empty:new R(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new he(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new he(t.from,t.to,R.fromJSON(e,t.slice),!!t.structure)}}Ce.jsonID("replace",he);class pe extends Ce{constructor(e,t,o,r,s,i,l=!1){super(),this.from=e,this.to=t,this.gapFrom=o,this.gapTo=r,this.slice=s,this.insert=i,this.structure=l}apply(e){if(this.structure&&(Hr(e,this.from,this.gapFrom)||Hr(e,this.gapTo,this.to)))return ae.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return ae.fail("Gap is not a flat range");let o=this.slice.insertAt(this.insert,t.content);return o?ae.fromReplace(e,this.from,this.to,o):ae.fail("Content does not fit in gap")}getMap(){return new _e([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new pe(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?o.pos:e.map(this.gapTo,1);return t.deletedAcross&&o.deletedAcross||r<t.pos||s>o.pos?null:new pe(t.pos,o.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new pe(t.from,t.to,t.gapFrom,t.gapTo,R.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ce.jsonID("replaceAround",pe);function Hr(n,e,t){let o=n.resolve(e),r=t-e,s=o.depth;for(;r>0&&s>0&&o.indexAfter(s)==o.node(s).childCount;)s--,r--;if(r>0){let i=o.node(s).maybeChild(o.indexAfter(s));for(;r>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,r--}}return!1}function Nh(n,e,t,o){let r=[],s=[],i,l;n.doc.nodesBetween(e,t,(a,d,u)=>{if(!a.isInline)return;let f=a.marks;if(!o.isInSet(f)&&u.type.allowsMarkType(o.type)){let p=Math.max(d,e),h=Math.min(d+a.nodeSize,t),m=o.addToSet(f);for(let g=0;g<f.length;g++)f[g].isInSet(m)||(i&&i.to==p&&i.mark.eq(f[g])?i.to=h:r.push(i=new Ke(p,h,f[g])));l&&l.to==p?l.to=h:s.push(l=new Ct(p,h,o))}}),r.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function Bh(n,e,t,o){let r=[],s=0;n.doc.nodesBetween(e,t,(i,l)=>{if(!i.isInline)return;s++;let a=null;if(o instanceof So){let d=i.marks,u;for(;u=o.isInSet(d);)(a||(a=[])).push(u),d=u.removeFromSet(d)}else o?o.isInSet(i.marks)&&(a=[o]):a=i.marks;if(a&&a.length){let d=Math.min(l+i.nodeSize,t);for(let u=0;u<a.length;u++){let f=a[u],p;for(let h=0;h<r.length;h++){let m=r[h];m.step==s-1&&f.eq(r[h].style)&&(p=m)}p?(p.to=d,p.step=s):r.push({style:f,from:Math.max(l,e),to:d,step:s})}}}),r.forEach(i=>n.step(new Ke(i.from,i.to,i.style)))}function Wr(n,e,t,o=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),i=[],l=e+1;for(let a=0;a<s.childCount;a++){let d=s.child(a),u=l+d.nodeSize,f=o.matchType(d.type);if(!f)i.push(new he(l,u,R.empty));else{o=f;for(let p=0;p<d.marks.length;p++)t.allowsMarkType(d.marks[p].type)||n.step(new Ke(l,u,d.marks[p]));if(r&&d.isText&&t.whitespace!="pre"){let p,h=/\r?\n|\r/g,m;for(;p=h.exec(d.text);)m||(m=new R(N.from(t.schema.text(" ",t.allowedMarks(d.marks))),0,0)),i.push(new he(l+p.index,l+p.index+p[0].length,m))}}l=u}if(!o.validEnd){let a=o.fillBefore(N.empty,!0);n.replace(l,l,new R(a,0,0))}for(let a=i.length-1;a>=0;a--)n.step(i[a])}function Ah(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function gn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let o=n.depth,r=0,s=0;;--o){let i=n.$from.node(o),l=n.$from.index(o)+r,a=n.$to.indexAfter(o)-s;if(o<n.depth&&i.canReplace(l,a,t))return o;if(o==0||i.type.spec.isolating||!Ah(i,l,a))break;l&&(r=1),a<i.childCount&&(s=1)}return null}function Ih(n,e,t){let{$from:o,$to:r,depth:s}=e,i=o.before(s+1),l=r.after(s+1),a=i,d=l,u=N.empty,f=0;for(let m=s,g=!1;m>t;m--)g||o.index(m)>0?(g=!0,u=N.from(o.node(m).copy(u)),f++):a--;let p=N.empty,h=0;for(let m=s,g=!1;m>t;m--)g||r.after(m+1)<r.end(m)?(g=!0,p=N.from(r.node(m).copy(p)),h++):d++;n.step(new pe(a,d,i,l,new R(u.append(p),f,h),u.size-f,!0))}function Rl(n,e,t=null,o=n){let r=Oh(n,e),s=r&&Dh(o,e);return s?r.map(_l).concat({type:e,attrs:t}).concat(s.map(_l)):null}function _l(n){return{type:n,attrs:null}}function Oh(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.contentMatchAt(o).findWrapping(e);if(!s)return null;let i=s.length?s[0]:e;return t.canReplaceWith(o,r,i)?s:null}function Dh(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.child(o),i=e.contentMatch.findWrapping(s.type);if(!i)return null;let a=(i.length?i[i.length-1]:e).contentMatch;for(let d=o;a&&d<r;d++)a=a.matchType(t.child(d).type);return!a||!a.validEnd?null:i}function Rh(n,e,t){let o=N.empty;for(let i=t.length-1;i>=0;i--){if(o.size){let l=t[i].type.contentMatch.matchFragment(o);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=N.from(t[i].type.create(t[i].attrs,o))}let r=e.start,s=e.end;n.step(new pe(r,s,r,s,new R(o,0,0),t.length,!0))}function _h(n,e,t,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(i,l)=>{let a=typeof r=="function"?r(i):r;if(i.isTextblock&&!i.hasMarkup(o,a)&&Ph(n.doc,n.mapping.slice(s).map(l),o)){let d=null;if(o.schema.linebreakReplacement){let h=o.whitespace=="pre",m=!!o.contentMatch.matchType(o.schema.linebreakReplacement);h&&!m?d=!1:!h&&m&&(d=!0)}d===!1&&Vl(n,i,l,s),Wr(n,n.mapping.slice(s).map(l,1),o,void 0,d===null);let u=n.mapping.slice(s),f=u.map(l,1),p=u.map(l+i.nodeSize,1);return n.step(new pe(f,p,f+1,p-1,new R(N.from(o.create(a,null,i.marks)),0,0),1,!0)),d===!0&&Pl(n,i,l,s),!1}})}function Pl(n,e,t,o){e.forEach((r,s)=>{if(r.isText){let i,l=/\r?\n|\r/g;for(;i=l.exec(r.text);){let a=n.mapping.slice(o).map(t+1+s+i.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Vl(n,e,t,o){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let i=n.mapping.slice(o).map(t+1+s);n.replaceWith(i,i+1,e.type.schema.text(`
|
|
5
|
+
`))}})}function Ph(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function Vh(n,e,t,o,r){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let i=t.create(o,null,r||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,i);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new pe(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new R(N.from(i),0,0),1,!0))}function ut(n,e,t=1,o){let r=n.resolve(e),s=r.depth-t,i=o&&o[o.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!i.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let d=r.depth-1,u=t-2;d>s;d--,u--){let f=r.node(d),p=r.index(d);if(f.type.spec.isolating)return!1;let h=f.content.cutByIndex(p,f.childCount),m=o&&o[u+1];m&&(h=h.replaceChild(0,m.type.create(m.attrs)));let g=o&&o[u]||f;if(!f.canReplace(p+1,f.childCount)||!g.type.validContent(h))return!1}let l=r.indexAfter(s),a=o&&o[0];return r.node(s).canReplaceWith(l,l,a?a.type:r.node(s+1).type)}function $h(n,e,t=1,o){let r=n.doc.resolve(e),s=N.empty,i=N.empty;for(let l=r.depth,a=r.depth-t,d=t-1;l>a;l--,d--){s=N.from(r.node(l).copy(s));let u=o&&o[d];i=N.from(u?u.type.create(u.attrs,i):r.node(l).copy(i))}n.step(new he(e,e,new R(s.append(i),t,t),!0))}function Gt(n,e){let t=n.resolve(e),o=t.index();return $l(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function Lh(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:o}=n.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),i=s.type==o?n.type.schema.nodes.text:s.type;if(t=t.matchType(i),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function $l(n,e){return!!(n&&e&&!n.isLeaf&&Lh(n,e))}function Mo(n,e,t=-1){let o=n.resolve(e);for(let r=o.depth;;r--){let s,i,l=o.index(r);if(r==o.depth?(s=o.nodeBefore,i=o.nodeAfter):t>0?(s=o.node(r+1),l++,i=o.node(r).maybeChild(l)):(s=o.node(r).maybeChild(l-1),i=o.node(r+1)),s&&!s.isTextblock&&$l(s,i)&&o.node(r).canReplace(l,l+1))return e;if(r==0)break;e=t<0?o.before(r):o.after(r)}}function zh(n,e,t){let o=null,{linebreakReplacement:r}=n.doc.type.schema,s=n.doc.resolve(e-t),i=s.node().type;if(r&&i.inlineContent){let u=i.whitespace=="pre",f=!!i.contentMatch.matchType(r);u&&!f?o=!1:!u&&f&&(o=!0)}let l=n.steps.length;if(o===!1){let u=n.doc.resolve(e+t);Vl(n,u.node(),u.before(),l)}i.inlineContent&&Wr(n,e+t-1,i,s.node().contentMatchAt(s.index()),o==null);let a=n.mapping.slice(l),d=a.map(e-t);if(n.step(new he(d,a.map(e+t,-1),R.empty,!0)),o===!0){let u=n.doc.resolve(d);Pl(n,u.node(),u.before(),n.steps.length)}return n}function Fh(n,e,t){let o=n.resolve(e);if(o.parent.canReplaceWith(o.index(),o.index(),t))return e;if(o.parentOffset==0)for(let r=o.depth-1;r>=0;r--){let s=o.index(r);if(o.node(r).canReplaceWith(s,s,t))return o.before(r+1);if(s>0)return null}if(o.parentOffset==o.parent.content.size)for(let r=o.depth-1;r>=0;r--){let s=o.indexAfter(r);if(o.node(r).canReplaceWith(s,s,t))return o.after(r+1);if(s<o.node(r).childCount)return null}return null}function Ll(n,e,t){let o=n.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let i=o.depth;i>=0;i--){let l=i==o.depth?0:o.pos<=(o.start(i+1)+o.end(i+1))/2?-1:1,a=o.index(i)+(l>0?1:0),d=o.node(i),u=!1;if(s==1)u=d.canReplace(a,a,r);else{let f=d.contentMatchAt(a).findWrapping(r.firstChild.type);u=f&&d.canReplaceWith(a,a,f[0])}if(u)return l==0?o.pos:l<0?o.before(i+1):o.after(i+1)}return null}function To(n,e,t=e,o=R.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return zl(r,s,o)?new he(e,t,o):new Hh(r,s,o).fit()}function zl(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class Hh{constructor(e,t,o){this.$from=e,this.$to=t,this.unplaced=o,this.frontier=[],this.placed=N.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=N.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let d=this.findFittable();d?this.placeNodes(d):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,o=this.$from,r=this.close(e<0?this.$to:o.doc.resolve(e));if(!r)return null;let s=this.placed,i=o.depth,l=r.depth;for(;i&&l&&s.childCount==1;)s=s.firstChild.content,i--,l--;let a=new R(s,i,l);return e>-1?new pe(o.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||o.pos!=this.$to.pos?new he(o.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,o=0,r=this.unplaced.openEnd;o<e;o++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=o){e=o;break}t=s.content}for(let t=1;t<=2;t++)for(let o=t==1?e:this.unplaced.openStart;o>=0;o--){let r,s=null;o?(s=jr(this.unplaced.content,o-1).firstChild,r=s.content):r=this.unplaced.content;let i=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:d}=this.frontier[l],u,f=null;if(t==1&&(i?d.matchType(i.type)||(f=d.fillBefore(N.from(i),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:o,frontierDepth:l,parent:s,inject:f};if(t==2&&i&&(u=d.findWrapping(i.type)))return{sliceDepth:o,frontierDepth:l,parent:s,wrap:u};if(s&&d.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=jr(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new R(e,t+1,Math.max(o,r.size+t>=e.size-o?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=jr(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new R(Fn(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new R(Fn(e,t,1),t,o)}placeNodes({sliceDepth:e,frontierDepth:t,parent:o,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let g=0;g<s.length;g++)this.openFrontierNode(s[g]);let i=this.unplaced,l=o?o.content:i.content,a=i.openStart-e,d=0,u=[],{match:f,type:p}=this.frontier[t];if(r){for(let g=0;g<r.childCount;g++)u.push(r.child(g));f=f.matchFragment(r)}let h=l.size+e-(i.content.size-i.openEnd);for(;d<l.childCount;){let g=l.child(d),y=f.matchType(g.type);if(!y)break;d++,(d>1||a==0||g.content.size)&&(f=y,u.push(Fl(g.mark(p.allowedMarks(g.marks)),d==1?a:0,d==l.childCount?h:-1)))}let m=d==l.childCount;m||(h=-1),this.placed=Hn(this.placed,t,N.from(u)),this.frontier[t].match=f,m&&h<0&&o&&o.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=l;g<h;g++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=m?e==0?R.empty:new R(Fn(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new R(Fn(i.content,e,d),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!Ur(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:o}=this.$to,r=this.$to.after(o);for(;o>1&&r==this.$to.end(--o);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:o,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=Ur(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:a,type:d}=this.frontier[l],u=Ur(e,l,d,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:i,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Hn(this.placed,t.depth,t.fit)),e=t.move;for(let o=t.depth+1;o<=e.depth;o++){let r=e.node(o),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(o));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,o){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Hn(this.placed,this.depth,N.from(e.create(t,o))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(N.empty,!0);t.childCount&&(this.placed=Hn(this.placed,this.frontier.length,t))}}function Fn(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Fn(n.firstChild.content,e-1,t)))}function Hn(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Hn(n.lastChild.content,e-1,t)))}function jr(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function Fl(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,Fl(o.firstChild,e-1,o.childCount==1?t-1:0))),e>0&&(o=n.type.contentMatch.fillBefore(o).append(o),t<=0&&(o=o.append(n.type.contentMatch.matchFragment(o).fillBefore(N.empty,!0)))),n.copy(o)}function Ur(n,e,t,o,r){let s=n.node(e),i=r?n.indexAfter(e):n.index(e);if(i==s.childCount&&!t.compatibleContent(s.type))return null;let l=o.fillBefore(s.content,!0,i);return l&&!Wh(t,s.content,i)?l:null}function Wh(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function jh(n){return n.spec.defining||n.spec.definingForContent}function Uh(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if(zl(r,s,o))return n.step(new he(e,t,o));let i=Wl(r,s);i[i.length-1]==0&&i.pop();let l=-(r.depth+1);i.unshift(l);for(let p=r.depth,h=r.pos-1;p>0;p--,h--){let m=r.node(p).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;i.indexOf(p)>-1?l=p:r.before(p)==h&&i.splice(1,0,-p)}let a=i.indexOf(l),d=[],u=o.openStart;for(let p=o.content,h=0;;h++){let m=p.firstChild;if(d.push(m),h==o.openStart)break;p=m.content}for(let p=u-1;p>=0;p--){let h=d[p],m=jh(h.type);if(m&&!h.sameMarkup(r.node(Math.abs(l)-1)))u=p;else if(m||!h.type.isTextblock)break}for(let p=o.openStart;p>=0;p--){let h=(p+u+1)%(o.openStart+1),m=d[h];if(m)for(let g=0;g<i.length;g++){let y=i[(g+a)%i.length],k=!0;y<0&&(k=!1,y=-y);let w=r.node(y-1),b=r.index(y-1);if(w.canReplaceWith(b,b,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new R(Hl(o.content,0,o.openStart,h),h,o.openEnd))}}let f=n.steps.length;for(let p=i.length-1;p>=0&&(n.replace(e,t,o),!(n.steps.length>f));p--){let h=i[p];h<0||(e=r.before(h),t=s.after(h))}}function Hl(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(Hl(s.content,e+1,t,o,s)))}if(e>o){let s=r.contentMatchAt(0),i=s.fillBefore(n).append(n);n=i.append(s.matchFragment(i).fillBefore(N.empty,!0))}return n}function Kh(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=Fh(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new R(N.from(o),0,0))}function qh(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=Wl(o,r);for(let i=0;i<s.length;i++){let l=s[i],a=i==s.length-1;if(a&&l==0||o.node(l).type.contentMatch.validEnd)return n.delete(o.start(l),r.end(l));if(l>0&&(a||o.node(l-1).canReplace(o.index(l-1),r.indexAfter(l-1))))return n.delete(o.before(l),r.after(l))}for(let i=1;i<=o.depth&&i<=r.depth;i++)if(e-o.start(i)==o.depth-i&&t>o.end(i)&&r.end(i)-t!=r.depth-i&&o.start(i-1)==r.start(i-1)&&o.node(i-1).canReplace(o.index(i-1),r.index(i-1)))return n.delete(o.before(i),t);n.delete(e,t)}function Wl(n,e){let t=[],o=Math.min(n.depth,e.depth);for(let r=o;r>=0;r--){let s=n.start(r);if(s<n.pos-(n.depth-r)||e.end(r)>e.pos+(e.depth-r)||n.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==n.depth&&r==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class yn extends Ce{constructor(e,t,o){super(),this.pos=e,this.attr=t,this.value=o}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at attribute step's position");let o=Object.create(null);for(let s in t.attrs)o[s]=t.attrs[s];o[this.attr]=this.value;let r=t.type.create(o,null,t.marks);return ae.fromReplace(e,this.pos,this.pos+1,new R(N.from(r),0,t.isLeaf?0:1))}getMap(){return _e.empty}invert(e){return new yn(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new yn(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new yn(t.pos,t.attr,t.value)}}Ce.jsonID("attr",yn);class Wn extends Ce{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let o=e.type.create(t,e.content,e.marks);return ae.ok(o)}getMap(){return _e.empty}invert(e){return new Wn(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Wn(t.attr,t.value)}}Ce.jsonID("docAttr",Wn);let kn=class extends Error{};kn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},kn.prototype=Object.create(Error.prototype),kn.prototype.constructor=kn,kn.prototype.name="TransformError";class jl{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new zn}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new kn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let o=0;o<this.mapping.maps.length;o++){let r=this.mapping.maps[o];o&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,i,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,o=R.empty){let r=To(this.doc,e,t,o);return r&&this.step(r),this}replaceWith(e,t,o){return this.replace(e,t,new R(N.from(o),0,0))}delete(e,t){return this.replace(e,t,R.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,o){return Uh(this,e,t,o),this}replaceRangeWith(e,t,o){return Kh(this,e,t,o),this}deleteRange(e,t){return qh(this,e,t),this}lift(e,t){return Ih(this,e,t),this}join(e,t=1){return zh(this,e,t),this}wrap(e,t){return Rh(this,e,t),this}setBlockType(e,t=e,o,r=null){return _h(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return Vh(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new yn(e,t,o)),this}setDocAttribute(e,t){return this.step(new Wn(e,t)),this}addNodeMark(e,t){return this.step(new vt(e,t)),this}removeNodeMark(e,t){let o=this.doc.nodeAt(e);if(!o)throw new RangeError("No node at position "+e);if(t instanceof Z)t.isInSet(o.marks)&&this.step(new Jt(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new Jt(e,s)),r=s.removeFromSet(r);for(let l=i.length-1;l>=0;l--)this.step(i[l])}return this}split(e,t=1,o){return $h(this,e,t,o),this}addMark(e,t,o){return Nh(this,e,t,o),this}removeMark(e,t,o){return Bh(this,e,t,o),this}clearIncompatible(e,t,o){return Wr(this,e,t,o),this}}const Kr=Object.create(null);class J{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new Jh(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=R.empty){let o=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=o,o=o.lastChild;let s=e.steps.length,i=this.ranges;for(let l=0;l<i.length;l++){let{$from:a,$to:d}=i[l],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(d.pos),l?R.empty:t),l==0&&ql(e,s,(o?o.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let o=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:i,$to:l}=r[s],a=e.mapping.slice(o),d=a.map(i.pos),u=a.map(l.pos);s?e.deleteRange(d,u):(e.replaceRangeWith(d,u,t),ql(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new U(e):wn(e.node(0),e.parent,e.pos,e.index(),t,o);if(r)return r;for(let s=e.depth-1;s>=0;s--){let i=t<0?wn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):wn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,o);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Pe(e.node(0))}static atStart(e){return wn(e,e,0,0,1)||new Pe(e)}static atEnd(e){return wn(e,e,e.content.size,e.childCount,-1)||new Pe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=Kr[t.type];if(!o)throw new RangeError(`No selection type ${t.type} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in Kr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Kr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return U.between(this.$anchor,this.$head).getBookmark()}}J.prototype.visible=!0;class Jh{constructor(e,t){this.$from=e,this.$to=t}}let Ul=!1;function Kl(n){!Ul&&!n.parent.inlineContent&&(Ul=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class U extends J{constructor(e,t=e){Kl(e),Kl(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let o=e.resolve(t.map(this.head));if(!o.parent.inlineContent)return J.near(o);let r=e.resolve(t.map(this.anchor));return new U(r.parent.inlineContent?r:o,o)}replace(e,t=R.empty){if(super.replace(e,t),t==R.empty){let o=this.$from.marksAcross(this.$to);o&&e.ensureMarks(o)}}eq(e){return e instanceof U&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new No(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new U(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,o=t){let r=e.resolve(t);return new this(r,o==t?r:e.resolve(o))}static between(e,t,o){let r=e.pos-t.pos;if((!o||r)&&(o=r>=0?1:-1),!t.parent.inlineContent){let s=J.findFrom(t,o,!0)||J.findFrom(t,-o,!0);if(s)t=s.$head;else return J.near(t,o)}return e.parent.inlineContent||(r==0?e=t:(e=(J.findFrom(e,-o,!0)||J.findFrom(e,o,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new U(e,t)}}J.jsonID("text",U);class No{constructor(e,t){this.anchor=e,this.head=t}map(e){return new No(e.map(this.anchor),e.map(this.head))}resolve(e){return U.between(e.resolve(this.anchor),e.resolve(this.head))}}class $ extends J{constructor(e){let t=e.nodeAfter,o=e.node(0).resolve(e.pos+t.nodeSize);super(e,o),this.node=t}map(e,t){let{deleted:o,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return o?J.near(s):new $(s)}content(){return new R(N.from(this.node),0,0)}eq(e){return e instanceof $&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new qr(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new $(e.resolve(t.anchor))}static create(e,t){return new $(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}$.prototype.visible=!1,J.jsonID("node",$);class qr{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new No(o,o):new qr(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&$.isSelectable(o)?new $(t):J.near(t)}}class Pe extends J{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=R.empty){if(t==R.empty){e.delete(0,e.doc.content.size);let o=J.atStart(e.doc);o.eq(e.selection)||e.setSelection(o)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Pe(e)}map(e){return new Pe(e)}eq(e){return e instanceof Pe}getBookmark(){return Gh}}J.jsonID("all",Pe);const Gh={map(){return this},resolve(n){return new Pe(n)}};function wn(n,e,t,o,r,s=!1){if(e.inlineContent)return U.create(n,t);for(let i=o-(r>0?0:1);r>0?i<e.childCount:i>=0;i+=r){let l=e.child(i);if(l.isAtom){if(!s&&$.isSelectable(l))return $.create(n,t-(r<0?l.nodeSize:0))}else{let a=wn(n,l,t+r,r<0?l.childCount:0,r,s);if(a)return a}t+=l.nodeSize*r}return null}function ql(n,e,t){let o=n.steps.length-1;if(o<e)return;let r=n.steps[o];if(!(r instanceof he||r instanceof pe))return;let s=n.mapping.maps[o],i;s.forEach((l,a,d,u)=>{i==null&&(i=u)}),n.setSelection(J.near(n.doc.resolve(i),t))}const Jl=1,Bo=2,Gl=4;class Yh extends jl{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Jl)&~Bo,this.storedMarks=null,this}get selectionSet(){return(this.updated&Jl)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Bo,this}ensureMarks(e){return Z.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Bo)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Bo,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let o=this.selection;return t&&(e=e.mark(this.storedMarks||(o.empty?o.$from.marks():o.$from.marksAcross(o.$to)||Z.none))),o.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,o){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(o==null&&(o=t),!e)return this.deleteRange(t,o);let s=this.storedMarks;if(!s){let i=this.doc.resolve(t);s=o==t?i.marks():i.marksAcross(this.doc.resolve(o))}return this.replaceRangeWith(t,o,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(J.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Gl,this}get scrolledIntoView(){return(this.updated&Gl)>0}}function Yl(n,e){return!e||!n?n:n.bind(e)}class jn{constructor(e,t,o){this.name=e,this.init=Yl(t.init,o),this.apply=Yl(t.apply,o)}}const Xh=[new jn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new jn("selection",{init(n,e){return n.selection||J.atStart(e.doc)},apply(n){return n.selection}}),new jn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new jn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Jr{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Xh.slice(),t&&t.forEach(o=>{if(this.pluginsByKey[o.key])throw new RangeError("Adding different instances of a keyed plugin ("+o.key+")");this.plugins.push(o),this.pluginsByKey[o.key]=o,o.spec.state&&this.fields.push(new jn(o.key,o.spec.state,o))})}}class bn{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let o=0;o<this.config.plugins.length;o++)if(o!=t){let r=this.config.plugins[o];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],o=this.applyInner(e),r=null;for(;;){let s=!1;for(let i=0;i<this.config.plugins.length;i++){let l=this.config.plugins[i];if(l.spec.appendTransaction){let a=r?r[i].n:0,d=r?r[i].state:this,u=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,d,o);if(u&&o.filterTransaction(u,i)){if(u.setMeta("appendedTransaction",e),!r){r=[];for(let f=0;f<this.config.plugins.length;f++)r.push(f<i?{state:o,n:t.length}:{state:this,n:0})}t.push(u),o=o.applyInner(u),s=!0}r&&(r[i]={state:o,n:t.length})}}if(!s)return{state:o,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new bn(this.config),o=this.config.fields;for(let r=0;r<o.length;r++){let s=o[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Yh(this)}static create(e){let t=new Jr(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new bn(t);for(let r=0;r<t.fields.length;r++)o[t.fields[r].name]=t.fields[r].init(e,o);return o}reconfigure(e){let t=new Jr(this.schema,e.plugins),o=t.fields,r=new bn(t);for(let s=0;s<o.length;s++){let i=o[s].name;r[i]=this.hasOwnProperty(i)?this[i]:o[s].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(o=>o.toJSON())),e&&typeof e=="object")for(let o in e){if(o=="doc"||o=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[o],s=r.spec.state;s&&s.toJSON&&(t[o]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,o){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new Jr(e.schema,e.plugins),s=new bn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=ct.fromJSON(e.schema,t.doc);else if(i.name=="selection")s.selection=J.fromJSON(s.doc,t.selection);else if(i.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(o)for(let l in o){let a=o[l],d=a.spec.state;if(a.key==i.name&&d&&d.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[i.name]=d.fromJSON.call(a,e,t[l],s);return}}s[i.name]=i.init(e,s)}}),s}}function Xl(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=Xl(r,e,{})),t[o]=r}return t}class ue{constructor(e){this.spec=e,this.props={},e.props&&Xl(e.props,this,this.props),this.key=e.key?e.key.key:Zl("plugin")}getState(e){return e[this.key]}}const Gr=Object.create(null);function Zl(n){return n in Gr?n+"$"+ ++Gr[n]:(Gr[n]=0,n+"$")}class Te{constructor(e="key"){this.key=Zl(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Yr=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ql(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const ea=(n,e,t)=>{let o=Ql(n,t);if(!o)return!1;let r=Xr(o);if(!r){let i=o.blockRange(),l=i&&gn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(ca(n,r,e,-1))return!0;if(o.parent.content.size==0&&(xn(s,"end")||$.isSelectable(s)))for(let i=o.depth;;i--){let l=To(n.doc,o.before(i),o.after(i),R.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=n.tr.step(l);a.setSelection(xn(s,"end")?J.findFrom(a.doc.resolve(a.mapping.map(r.pos,-1)),-1):$.create(a.doc,r.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(i==1||o.node(i-1).childCount>1)break}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},Zh=(n,e,t)=>{let o=Ql(n,t);if(!o)return!1;let r=Xr(o);return r?ta(n,r,e):!1},Qh=(n,e,t)=>{let o=oa(n,t);if(!o)return!1;let r=Zr(o);return r?ta(n,r,e):!1};function ta(n,e,t){let o=e.nodeBefore,r=o,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let u=r.lastChild;if(!u)return!1;r=u}let i=e.nodeAfter,l=i,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let d=To(n.doc,s,a,R.empty);if(!d||d.from!=s||d instanceof he&&d.slice.size>=a-s)return!1;if(t){let u=n.tr.step(d);u.setSelection(U.create(u.doc,s)),t(u.scrollIntoView())}return!0}function xn(n,e,t=!1){for(let o=n;o;o=e=="start"?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(t&&o.childCount!=1)return!1}return!1}const na=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):o.parentOffset>0)return!1;s=Xr(o)}let i=s&&s.nodeBefore;return!i||!$.isSelectable(i)?!1:(e&&e(n.tr.setSelection($.create(n.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function Xr(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function oa(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const ra=(n,e,t)=>{let o=oa(n,t);if(!o)return!1;let r=Zr(o);if(!r)return!1;let s=r.nodeAfter;if(ca(n,r,e,1))return!0;if(o.parent.content.size==0&&(xn(s,"start")||$.isSelectable(s))){let i=To(n.doc,o.before(),o.after(),R.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=n.tr.step(i);l.setSelection(xn(s,"start")?J.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):$.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},sa=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):o.parentOffset<o.parent.content.size)return!1;s=Zr(o)}let i=s&&s.nodeAfter;return!i||!$.isSelectable(i)?!1:(e&&e(n.tr.setSelection($.create(n.doc,s.pos)).scrollIntoView()),!0)};function Zr(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const ep=(n,e)=>{let t=n.selection,o=t instanceof $,r;if(o){if(t.node.isTextblock||!Gt(n.doc,t.from))return!1;r=t.from}else if(r=Mo(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);o&&s.setSelection($.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},tp=(n,e)=>{let t=n.selection,o;if(t instanceof $){if(t.node.isTextblock||!Gt(n.doc,t.to))return!1;o=t.to}else if(o=Mo(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},np=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&gn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},ia=(n,e)=>{let{$head:t,$anchor:o}=n.selection;return!t.parent.type.spec.code||!t.sameParent(o)?!1:(e&&e(n.tr.insertText(`
|
|
6
|
+
`).scrollIntoView()),!0)};function Qr(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const op=(n,e)=>{let{$head:t,$anchor:o}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(o))return!1;let r=t.node(-1),s=t.indexAfter(-1),i=Qr(r.contentMatchAt(s));if(!i||!r.canReplaceWith(s,s,i))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,i.createAndFill());a.setSelection(J.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},la=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof Pe||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=Qr(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let i=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,l=n.tr.insert(i,s.createAndFill());l.setSelection(U.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},aa=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(ut(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&gn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function rp(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof $&&e.selection.node.isBlock)return!o.parentOffset||!ut(e.doc,o.pos)?!1:(t&&t(e.tr.split(o.pos).scrollIntoView()),!0);if(!o.depth)return!1;let s=[],i,l,a=!1,d=!1;for(let h=o.depth;;h--)if(o.node(h).isBlock){a=o.end(h)==o.pos+(o.depth-h),d=o.start(h)==o.pos-(o.depth-h),l=Qr(o.node(h-1).contentMatchAt(o.indexAfter(h-1))),s.unshift(a&&l?{type:l}:null),i=h;break}else{if(h==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof U||e.selection instanceof Pe)&&u.deleteSelection();let f=u.mapping.map(o.pos),p=ut(u.doc,f,s.length,s);if(p||(s[0]=l?{type:l}:null,p=ut(u.doc,f,s.length,s)),!p)return!1;if(u.split(f,s.length,s),!a&&d&&o.node(i).type!=l){let h=u.mapping.map(o.before(i)),m=u.doc.resolve(h);l&&o.node(i-1).canReplaceWith(m.index(),m.index()+1,l)&&u.setNodeMarkup(u.mapping.map(o.before(i)),l)}return t&&t(u.scrollIntoView()),!0}}const sp=rp(),ip=(n,e)=>{let{$from:t,to:o}=n.selection,r,s=t.sharedDepth(o);return s==0?!1:(r=t.before(s),e&&e(n.tr.setSelection($.create(n.doc,r))),!0)};function lp(n,e,t){let o=e.nodeBefore,r=e.nodeAfter,s=e.index();return!o||!r||!o.type.compatibleContent(r.type)?!1:!o.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-o.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||Gt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function ca(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,a=r.type.spec.isolating||s.type.spec.isolating;if(!a&&lp(n,e,t))return!0;let d=!a&&e.parent.canReplace(e.index(),e.index()+1);if(d&&(i=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(i[0]||s.type).validEnd){if(t){let h=e.pos+s.nodeSize,m=N.empty;for(let k=i.length-1;k>=0;k--)m=N.from(i[k].create(null,m));m=N.from(r.copy(m));let g=n.tr.step(new pe(e.pos-1,h,e.pos,h,new R(m,1,0),i.length,!0)),y=g.doc.resolve(h+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&Gt(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=s.type.spec.isolating||o>0&&a?null:J.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),p=f&&gn(f);if(p!=null&&p>=e.depth)return t&&t(n.tr.lift(f,p).scrollIntoView()),!0;if(d&&xn(s,"start",!0)&&xn(r,"end")){let h=r,m=[];for(;m.push(h),!h.isTextblock;)h=h.lastChild;let g=s,y=1;for(;!g.isTextblock;g=g.firstChild)y++;if(h.canReplace(h.childCount,h.childCount,g.content)){if(t){let k=N.empty;for(let b=m.length-1;b>=0;b--)k=N.from(m[b].copy(k));let w=n.tr.step(new pe(e.pos-m.length,e.pos+s.nodeSize,e.pos+y,e.pos+s.nodeSize-y,new R(k,m.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function da(n){return function(e,t){let o=e.selection,r=n<0?o.$from:o.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(U.create(e.doc,n<0?r.start(s):r.end(s)))),!0):!1}}const ap=da(-1),cp=da(1);function dp(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&Rl(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function ua(n,e=null){return function(t,o){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:i},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(i,l,(a,d)=>{if(r)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)r=!0;else{let u=t.doc.resolve(d),f=u.index();r=u.parent.canReplaceWith(f,f+1,n)}})}if(!r)return!1;if(o){let s=t.tr;for(let i=0;i<t.selection.ranges.length;i++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[i];s.setBlockType(l,a,n,e)}o(s.scrollIntoView())}return!0}}function es(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}es(Yr,ea,na),es(Yr,ra,sa),es(ia,la,aa,sp),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function up(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s);if(!i)return!1;let l=o?t.tr:null;return fp(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function fp(n,e,t,o=null){let r=!1,s=e,i=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=i.resolve(e.start-2);s=new bo(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new bo(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=Rl(s,t,o,e);return l?(n&&hp(n,e,l,r,t),!0):!1}function hp(n,e,t,o,r){let s=N.empty;for(let u=t.length-1;u>=0;u--)s=N.from(t[u].type.create(t[u].attrs,s));n.step(new pe(e.start-(o?2:0),e.end,e.start,e.end,new R(s,0,0),t.length,!0));let i=0;for(let u=0;u<t.length;u++)t[u].type==r&&(i=u+1);let l=t.length-i,a=e.start+t.length-(o?2:0),d=e.parent;for(let u=e.startIndex,f=e.endIndex,p=!0;u<f;u++,p=!1)!p&&ut(n.doc,a,l)&&(n.split(a,l),a+=2*l),a+=d.child(u).nodeSize;return n}function pp(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,i=>i.childCount>0&&i.firstChild.type==n);return s?t?o.node(s.depth-1).type==n?mp(e,t,n,s):gp(e,t,s):!0:!1}}function mp(n,e,t,o){let r=n.tr,s=o.end,i=o.$to.end(o.depth);s<i&&(r.step(new pe(s-1,i,s,i,new R(N.from(t.create(null,o.parent.copy())),1,0),1,!0)),o=new bo(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=gn(o);if(l==null)return!1;r.lift(o,l);let a=r.doc.resolve(r.mapping.map(s,-1)-1);return Gt(r.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&r.join(a.pos),e(r.scrollIntoView()),!0}function gp(n,e,t){let o=n.tr,r=t.parent;for(let h=t.end,m=t.endIndex-1,g=t.startIndex;m>g;m--)h-=r.child(m).nodeSize,o.delete(h-1,h+1);let s=o.doc.resolve(t.start),i=s.nodeAfter;if(o.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==r.childCount,d=s.node(-1),u=s.index(-1);if(!d.canReplace(u+(l?0:1),u+1,i.content.append(a?N.empty:N.from(r))))return!1;let f=s.pos,p=f+i.nodeSize;return o.step(new pe(f-(l?1:0),p+(a?1:0),f+1,p-1,new R((l?N.empty:N.from(r.copy(N.empty))).append(a?N.empty:N.from(r.copy(N.empty))),l?0:1,a?0:1),l?0:1)),e(o.scrollIntoView()),!0}function yp(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,d=>d.childCount>0&&d.firstChild.type==n);if(!s)return!1;let i=s.startIndex;if(i==0)return!1;let l=s.parent,a=l.child(i-1);if(a.type!=n)return!1;if(t){let d=a.lastChild&&a.lastChild.type==l.type,u=N.from(d?n.create():null),f=new R(N.from(n.create(null,N.from(l.type.create(null,u)))),d?3:1,0),p=s.start,h=s.end;t(e.tr.step(new pe(p-(d?3:1),h,p,h,f,1,!0)).scrollIntoView())}return!0}}const we=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Sn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let ts=null;const ft=function(n,e,t){let o=ts||(ts=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},kp=function(){ts=null},Yt=function(n,e,t,o){return t&&(fa(n,e,t,o,-1)||fa(n,e,t,o,1))},wp=/^(img|br|input|textarea|hr)$/i;function fa(n,e,t,o,r){for(var s;;){if(n==t&&e==o)return!0;if(e==(r<0?0:Le(n))){let i=n.parentNode;if(!i||i.nodeType!=1||Un(n)||wp.test(n.nodeName)||n.contentEditable=="false")return!1;e=we(n)+(r<0?0:1),n=i}else if(n.nodeType==1){let i=n.childNodes[e+(r<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false")if(!((s=i.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else n=i,e=r<0?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function bp(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Le(n)}else if(n.parentNode&&!Un(n))e=we(n),n=n.parentNode;else return null}}function xp(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!Un(n))e=we(n)+1,n=n.parentNode;else return null}}function Sp(n,e,t){for(let o=e==0,r=e==Le(n);o||r;){if(n==t)return!0;let s=we(n);if(n=n.parentNode,!n)return!1;o=o&&s==0,r=r&&s==Le(n)}}function Un(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Ao=function(n){return n.focusNode&&Yt(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Xt(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Cp(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function vp(n,e,t){if(n.caretPositionFromPoint)try{let o=n.caretPositionFromPoint(e,t);if(o)return{node:o.offsetNode,offset:Math.min(Le(o.offsetNode),o.offset)}}catch{}if(n.caretRangeFromPoint){let o=n.caretRangeFromPoint(e,t);if(o)return{node:o.startContainer,offset:Math.min(Le(o.startContainer),o.startOffset)}}}const et=typeof navigator<"u"?navigator:null,ha=typeof document<"u"?document:null,Et=et&&et.userAgent||"",ns=/Edge\/(\d+)/.exec(Et),pa=/MSIE \d/.exec(Et),rs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Et),Ie=!!(pa||rs||ns),Mt=pa?document.documentMode:rs?+rs[1]:ns?+ns[1]:0,ze=!Ie&&/gecko\/(\d+)/i.test(Et);ze&&+(/Firefox\/(\d+)/.exec(Et)||[0,0])[1];const ss=!Ie&&/Chrome\/(\d+)/.exec(Et),be=!!ss,ma=ss?+ss[1]:0,ve=!Ie&&!!et&&/Apple Computer/.test(et.vendor),Cn=ve&&(/Mobile\/\w+/.test(Et)||!!et&&et.maxTouchPoints>2),Fe=Cn||(et?/Mac/.test(et.platform):!1),ga=et?/Win/.test(et.platform):!1,ht=/Android \d/.test(Et),Kn=!!ha&&"webkitFontSmoothing"in ha.documentElement.style,Ep=Kn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Mp(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function pt(n,e){return typeof n=="number"?n:n[e]}function Tp(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,o=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*o}}function ya(n,e,t){let o=n.someProp("scrollThreshold")||0,r=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let i=t||n.dom;i;){if(i.nodeType!=1){i=Sn(i);continue}let l=i,a=l==s.body,d=a?Mp(s):Tp(l),u=0,f=0;if(e.top<d.top+pt(o,"top")?f=-(d.top-e.top+pt(r,"top")):e.bottom>d.bottom-pt(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+pt(r,"top")-d.top:e.bottom-d.bottom+pt(r,"bottom")),e.left<d.left+pt(o,"left")?u=-(d.left-e.left+pt(r,"left")):e.right>d.right-pt(o,"right")&&(u=e.right-d.right+pt(r,"right")),u||f)if(a)s.defaultView.scrollBy(u,f);else{let h=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-h,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let p=a?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(p))break;i=p=="absolute"?i.offsetParent:Sn(i)}}function Np(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),o,r;for(let s=(e.left+e.right)/2,i=t+1;i<Math.min(innerHeight,e.bottom);i+=5){let l=n.root.elementFromPoint(s,i);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){o=l,r=a.top;break}}return{refDOM:o,refTop:r,stack:ka(n.dom)}}function ka(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=Sn(o));return e}function Bp({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;wa(t,o==0?0:o-e)}function wa(n,e){for(let t=0;t<n.length;t++){let{dom:o,top:r,left:s}=n[t];o.scrollTop!=r+e&&(o.scrollTop=r+e),o.scrollLeft!=s&&(o.scrollLeft=s)}}let vn=null;function Ap(n){if(n.setActive)return n.setActive();if(vn)return n.focus(vn);let e=ka(n);n.focus(vn==null?{get preventScroll(){return vn={preventScroll:!0},!0}}:void 0),vn||(vn=!1,wa(e,0))}function ba(n,e){let t,o=2e8,r,s=0,i=e.top,l=e.top,a,d;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let p;if(u.nodeType==1)p=u.getClientRects();else if(u.nodeType==3)p=ft(u).getClientRects();else continue;for(let h=0;h<p.length;h++){let m=p[h];if(m.top<=i&&m.bottom>=l){i=Math.max(m.bottom,i),l=Math.min(m.top,l);let g=m.left>e.left?m.left-e.left:m.right<e.left?e.left-m.right:0;if(g<o){t=u,o=g,r=g&&t.nodeType==3?{left:m.right<e.left?m.right:m.left,top:e.top}:e,u.nodeType==1&&g&&(s=f+(e.left>=(m.left+m.right)/2?1:0));continue}}else m.top>e.top&&!a&&m.left<=e.left&&m.right>=e.left&&(a=u,d={left:Math.max(m.left,Math.min(m.right,e.left)),top:m.top});!t&&(e.left>=m.right&&e.top>=m.top||e.left>=m.left&&e.top>=m.bottom)&&(s=f+1)}}return!t&&a&&(t=a,r=d,o=0),t&&t.nodeType==3?Ip(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:ba(t,r)}function Ip(n,e){let t=n.nodeValue.length,o=document.createRange(),r;for(let s=0;s<t;s++){o.setEnd(n,s+1),o.setStart(n,s);let i=Tt(o,1);if(i.top!=i.bottom&&is(e,i)){r={node:n,offset:s+(e.left>=(i.left+i.right)/2?1:0)};break}}return o.detach(),r||{node:n,offset:0}}function is(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Op(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function Dp(n,e,t){let{node:o,offset:r}=ba(e,t),s=-1;if(o.nodeType==1&&!o.firstChild){let i=o.getBoundingClientRect();s=i.left!=i.right&&t.left>(i.left+i.right)/2?1:-1}return n.docView.posFromDOM(o,r,s)}function Rp(n,e,t,o){let r=-1;for(let s=e,i=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!i&&a.left>o.left||a.top>o.top?r=l.posBefore:(!i&&a.right<o.left||a.bottom<o.top)&&(r=l.posAfter),i=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?o.top<(a.top+a.bottom)/2:o.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:n.docView.posFromDOM(e,t,-1)}function xa(n,e,t){let o=n.childNodes.length;if(o&&t.top<t.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let i=n.childNodes[s];if(i.nodeType==1){let l=i.getClientRects();for(let a=0;a<l.length;a++){let d=l[a];if(is(e,d))return xa(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function _p(n,e){let t=n.dom.ownerDocument,o,r=0,s=vp(t,e.left,e.top);s&&({node:o,offset:r}=s);let i=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!i||!n.dom.contains(i.nodeType!=1?i.parentNode:i)){let d=n.dom.getBoundingClientRect();if(!is(e,d)||(i=xa(n.dom,e,d),!i))return null}if(ve)for(let d=i;o&&d;d=Sn(d))d.draggable&&(o=void 0);if(i=Op(i,e),o){if(ze&&o.nodeType==1&&(r=Math.min(r,o.childNodes.length),r<o.childNodes.length)){let u=o.childNodes[r],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&r++}let d;Kn&&r&&o.nodeType==1&&(d=o.childNodes[r-1]).nodeType==1&&d.contentEditable=="false"&&d.getBoundingClientRect().top>=e.top&&r--,o==n.dom&&r==o.childNodes.length-1&&o.lastChild.nodeType==1&&e.top>o.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(r==0||o.nodeType!=1||o.childNodes[r-1].nodeName!="BR")&&(l=Rp(n,o,r,e))}l==null&&(l=Dp(n,i,e));let a=n.docView.nearestDesc(i,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Sa(n){return n.top<n.bottom||n.left<n.right}function Tt(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(Sa(o))return o}return Array.prototype.find.call(t,Sa)||n.getBoundingClientRect()}const Pp=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Ca(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=Kn||ze;if(o.nodeType==3)if(i&&(Pp.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let a=Tt(ft(o,r,r),t);if(ze&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Tt(ft(o,r-1,r-1),-1);if(d.top==a.top){let u=Tt(ft(o,r,r+1),-1);if(u.top!=a.top)return qn(u,u.left<d.left)}}return a}else{let a=r,d=r,u=t<0?1:-1;return t<0&&!r?(d++,u=-1):t>=0&&r==o.nodeValue.length?(a--,u=1):t<0?a--:d++,qn(Tt(ft(o,a,d),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Le(o))){let a=o.childNodes[r-1];if(a.nodeType==1)return ls(a.getBoundingClientRect(),!1)}if(s==null&&r<Le(o)){let a=o.childNodes[r];if(a.nodeType==1)return ls(a.getBoundingClientRect(),!0)}return ls(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Le(o))){let a=o.childNodes[r-1],d=a.nodeType==3?ft(a,Le(a)-(i?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(d)return qn(Tt(d,1),!1)}if(s==null&&r<Le(o)){let a=o.childNodes[r];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let d=a?a.nodeType==3?ft(a,0,i?0:1):a.nodeType==1?a:null:null;if(d)return qn(Tt(d,-1),!0)}return qn(Tt(o.nodeType==3?ft(o):o,-t),t>=0)}function qn(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function ls(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function va(n,e,t){let o=n.state,r=n.root.activeElement;o!=e&&n.updateState(e),r!=n.dom&&n.focus();try{return t()}finally{o!=e&&n.updateState(o),r!=n.dom&&r&&r.focus()}}function Vp(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return va(n,e,()=>{let{node:s}=n.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let i=Ca(n,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=ft(l,0,l.nodeValue.length).getClientRects();else continue;for(let d=0;d<a.length;d++){let u=a[d];if(u.bottom>u.top+1&&(t=="up"?i.top-u.top>(u.bottom-i.top)*2:u.bottom-i.bottom>(i.bottom-u.top)*2))return!1}}return!0})}const $p=/[\u0590-\u08ac]/;function Lp(n,e,t){let{$head:o}=e.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,s=!r,i=r==o.parent.content.size,l=n.domSelection();return l?!$p.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:va(n,e,()=>{let{focusNode:a,focusOffset:d,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),p=l.caretBidiLevel;l.modify("move",t,"character");let h=o.depth?n.docView.domAfterPos(o.before()):n.dom,{focusNode:m,focusOffset:g}=n.domSelectionRange(),y=m&&!h.contains(m.nodeType==1?m:m.parentNode)||a==m&&d==g;try{l.collapse(u,f),a&&(a!=u||d!=f)&&l.extend&&l.extend(a,d)}catch{}return p!=null&&(l.caretBidiLevel=p),y}):o.pos==o.start()||o.pos==o.end()}let Ea=null,Ma=null,Ta=!1;function zp(n,e,t){return Ea==e&&Ma==t?Ta:(Ea=e,Ma=t,Ta=t=="up"||t=="down"?Vp(n,e,t):Lp(n,e,t))}const He=0,Na=1,Zt=2,tt=3;class Jn{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=He,o.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,o){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,o=this.posAtStart;;t++){let r=this.children[t];if(r==e)return o;o+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,o){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(o<0){let s,i;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(i)+i.size:this.posAtStart}else{let s,i;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(i):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>we(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??o>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let o=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),i;if(s&&(!t||s.node))if(o&&(i=s.nodeDOM)&&!(i.nodeType==1?i.contains(e.nodeType==1?e:e.parentNode):i==e))o=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let o=t;o;o=o.parent)if(o==this)return t}posFromDOM(e,t,o){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,o)}return-1}descAt(e){for(let t=0,o=0;t<this.children.length;t++){let r=this.children[t],s=o+r.size;if(o==e&&s!=o){for(;!r.border&&r.children.length;)for(let i=0;i<r.children.length;i++){let l=r.children[i];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-o-r.border);o=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let o=0,r=0;for(let s=0;o<this.children.length;o++){let i=this.children[o],l=s+i.size;if(l>e||i instanceof Ia){r=e-s;break}s=l}if(r)return this.children[o].domFromPos(r-this.children[o].border,t);for(let s;o&&!(s=this.children[o-1]).size&&s instanceof Ba&&s.side>=0;o--);if(t<=0){let s,i=!0;for(;s=o?this.children[o-1]:null,!(!s||s.dom.parentNode==this.contentDOM);o--,i=!1);return s&&t&&i&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?we(s.dom)+1:0}}else{let s,i=!0;for(;s=o<this.children.length?this.children[o]:null,!(!s||s.dom.parentNode==this.contentDOM);o++,i=!1);return s&&i&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?we(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,o=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let i=o,l=0;;l++){let a=this.children[l],d=i+a.size;if(r==-1&&e<=d){let u=i+a.border;if(e>=u&&t<=d-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=i;for(let f=l;f>0;f--){let p=this.children[f-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){r=we(p.dom)+1;break}e-=p.size}r==-1&&(r=0)}if(r>-1&&(d>t||l==this.children.length-1)){t=d;for(let u=l+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=we(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}i=d}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:o}=this.domFromPos(e,0);if(t.nodeType!=1||o==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[o]}setSelection(e,t,o,r=!1){let s=Math.min(e,t),i=Math.max(e,t);for(let h=0,m=0;h<this.children.length;h++){let g=this.children[h],y=m+g.size;if(s>m&&i<y)return g.setSelection(e-m-g.border,t-m-g.border,o,r);m=y}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),d=o.root.getSelection(),u=o.domSelectionRange(),f=!1;if((ze||ve)&&e==t){let{node:h,offset:m}=l;if(h.nodeType==3){if(f=!!(m&&h.nodeValue[m-1]==`
|
|
7
|
+
`),f&&m==h.nodeValue.length)for(let g=h,y;g;g=g.parentNode){if(y=g.nextSibling){y.nodeName=="BR"&&(l=a={node:y.parentNode,offset:we(y)+1});break}let k=g.pmViewDesc;if(k&&k.node&&k.node.isBlock)break}}else{let g=h.childNodes[m-1];f=g&&(g.nodeName=="BR"||g.contentEditable=="false")}}if(ze&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(r=!0)}if(!(r||f&&ve)&&Yt(l.node,l.offset,u.anchorNode,u.anchorOffset)&&Yt(a.node,a.offset,u.focusNode,u.focusOffset))return;let p=!1;if((d.extend||e==t)&&!(f&&ze)){d.collapse(l.node,l.offset);try{e!=t&&d.extend(a.node,a.offset),p=!0}catch{}}if(!p){if(e>t){let m=l;l=a,a=m}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),d.removeAllRanges(),d.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let o=0,r=0;r<this.children.length;r++){let s=this.children[r],i=o+s.size;if(o==i?e<=i&&t>=o:e<i&&t>o){let l=o+s.border,a=i-s.border;if(e>=l&&t<=a){this.dirty=e==o||t==i?Zt:Na,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=tt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Zt:tt}o=i}this.dirty=Zt}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?Zt:Na;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Ba extends Jn{constructor(e,t,o,r){let s,i=t.type.toDOM;if(typeof i=="function"&&(i=i(o,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(i.nodeType!=1){let l=document.createElement("span");l.appendChild(i),i=l}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==He&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class Fp extends Jn{constructor(e,t,o,r){super(e,[],t,null),this.textDOM=o,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Qt extends Jn{constructor(e,t,o,r,s){super(e,[],o,r),this.mark=t,this.spec=s}static create(e,t,o,r){let s=r.nodeViews[t.type.name],i=s&&s(t,r,o);return(!i||!i.dom)&&(i=qt.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new Qt(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&tt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=tt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=He){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=He}}slice(e,t,o){let r=Qt.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=cs(s,t,i,o)),e>0&&(s=cs(s,0,e,o));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Nt extends Jn{constructor(e,t,o,r,s,i,l,a,d){super(e,[],s,i),this.node=t,this.outerDeco=o,this.innerDeco=r,this.nodeDOM=l}static create(e,t,o,r,s,i){let l=s.nodeViews[t.type.name],a,d=l&&l(t,s,()=>{if(!a)return i;if(a.parent)return a.parent.posBeforeChild(a)},o,r),u=d&&d.dom,f=d&&d.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=qt.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let p=u;return u=Ra(u,o,t),d?a=new Hp(e,t,o,r,u,f||null,p,d,s,i+1):t.isText?new Io(e,t,o,r,u,p,s):new Nt(e,t,o,r,u,f||null,p,s,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let o=this.children[t];if(this.dom.contains(o.dom.parentNode)){e.contentElement=o.dom.parentNode;break}}e.contentElement||(e.getContent=()=>N.empty)}return e}matchesNode(e,t,o){return this.dirty==He&&e.eq(this.node)&&Oo(t,this.outerDeco)&&o.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let o=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,i=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new jp(this,i&&i.node,e);qp(this.node,this.innerDeco,(d,u,f)=>{d.spec.marks?a.syncToMarks(d.spec.marks,o,e,u):d.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?Z.none:this.node.child(u).marks,o,e,u),a.placeWidget(d,e,r)},(d,u,f,p)=>{a.syncToMarks(d.marks,o,e,p);let h;a.findNodeMatch(d,u,f,p)||l&&e.state.selection.from>r&&e.state.selection.to<r+d.nodeSize&&(h=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(d,u,f,h,e)||a.updateNextNode(d,u,f,e,p,r)||a.addNode(d,u,f,e,r),r+=d.nodeSize}),a.syncToMarks([],o,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Zt)&&(i&&this.protectLocalComposition(e,i),Oa(this.contentDOM,this.children,e),Cn&&Jp(this.dom))}localCompositionInfo(e,t){let{from:o,to:r}=e.state.selection;if(!(e.state.selection instanceof U)||o<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let i=s.nodeValue,l=Gp(this.node.content,i,o-t,r-t);return l<0?null:{node:s,pos:l,text:i}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:o,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let i=new Fp(this,s,t,r);e.input.compositionNodes.push(i),this.children=cs(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==tt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,o,r),!0)}updateInner(e,t,o,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=o,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=He}updateOuterDeco(e){if(Oo(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=Da(this.dom,this.nodeDOM,as(this.outerDeco,this.node,t),as(e,this.node,t)),this.dom!=o&&(o.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Aa(n,e,t,o,r){Ra(o,e,n);let s=new Nt(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class Io extends Nt{constructor(e,t,o,r,s,i,l){super(e,t,o,r,s,null,i,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,o,r){return this.dirty==tt||this.dirty!=He&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=He||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=He,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,o){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,o)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,o){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new Io(this.parent,r,this.outerDeco,this.innerDeco,s,s,o)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=tt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Ia extends Jn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==He&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Hp extends Nt{constructor(e,t,o,r,s,i,l,a,d,u){super(e,t,o,r,s,i,l,d,u),this.spec=a}update(e,t,o,r){if(this.dirty==tt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,o);return s&&this.updateInner(e,t,o,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,o,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,o,r){this.spec.setSelection?this.spec.setSelection(e,t,o.root):super.setSelection(e,t,o,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Oa(n,e,t){let o=n.firstChild,r=!1;for(let s=0;s<e.length;s++){let i=e[s],l=i.dom;if(l.parentNode==n){for(;l!=o;)o=_a(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof Qt){let a=o?o.previousSibling:n.lastChild;Oa(i.contentDOM,i.children,t),o=a?a.nextSibling:n.firstChild}}for(;o;)o=_a(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Gn=function(n){n&&(this.nodeName=n)};Gn.prototype=Object.create(null);const en=[new Gn];function as(n,e,t){if(n.length==0)return en;let o=t?en[0]:new Gn,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new Gn(i.nodeName));for(let l in i){let a=i[l];a!=null&&(t&&r.length==1&&r.push(o=new Gn(e.isInline?"span":"div")),l=="class"?o.class=(o.class?o.class+" ":"")+a:l=="style"?o.style=(o.style?o.style+";":"")+a:l!="nodeName"&&(o[l]=a))}}}return r}function Da(n,e,t,o){if(t==en&&o==en)return e;let r=e;for(let s=0;s<o.length;s++){let i=o[s],l=t[s];if(s){let a;l&&l.nodeName==i.nodeName&&r!=n&&(a=r.parentNode)&&a.nodeName.toLowerCase()==i.nodeName||(a=document.createElement(i.nodeName),a.pmIsDeco=!0,a.appendChild(r),l=en[0]),r=a}Wp(r,l||en[0],i)}return r}function Wp(n,e,t){for(let o in e)o!="class"&&o!="style"&&o!="nodeName"&&!(o in t)&&n.removeAttribute(o);for(let o in t)o!="class"&&o!="style"&&o!="nodeName"&&t[o]!=e[o]&&n.setAttribute(o,t[o]);if(e.class!=t.class){let o=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<o.length;s++)r.indexOf(o[s])==-1&&n.classList.remove(o[s]);for(let s=0;s<r.length;s++)o.indexOf(r[s])==-1&&n.classList.add(r[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=o.exec(e.style);)n.style.removeProperty(r[1])}t.style&&(n.style.cssText+=t.style)}}function Ra(n,e,t){return Da(n,n,en,as(e,t,n.nodeType!=1))}function Oo(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function _a(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class jp{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Up(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let o=e;o<t;o++)this.top.children[o].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,o,r){let s=0,i=this.stack.length>>1,l=Math.min(i,e.length);for(;s<l&&(s==i-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<i;)this.destroyRest(),this.top.dirty=He,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let a=-1,d=this.top.children.length;r<this.preMatch.index&&(d=Math.min(this.index+3,d));for(let u=this.index;u<d;u++){let f=this.top.children[u];if(f.matchesMark(e[i])&&!this.isLocked(f.dom)){a=u;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=Qt.create(this.top,e[i],t,o);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,o,r){let s=-1,i;if(r>=this.preMatch.index&&(i=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,o))s=this.top.children.indexOf(i,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let d=this.top.children[l];if(d.matchesNode(e,t,o)&&!this.preMatch.matched.has(d)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,o,r,s){let i=this.top.children[r];return i.dirty==tt&&i.dom==i.contentDOM&&(i.dirty=Zt),i.update(e,t,o,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let o=e.pmViewDesc;if(o){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==o)return r}return-1}e=t}}updateNextNode(e,t,o,r,s,i){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Nt){let d=this.preMatch.matched.get(a);if(d!=null&&d!=s)return!1;let u=a.dom,f,p=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=tt&&Oo(t,a.outerDeco));if(!p&&a.update(e,t,o,r))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!p&&(f=this.recreateWrapper(a,e,t,o,r,i)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Zt,f.updateChildren(r,i+1),f.dirty=He),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,o,r,s,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Oo(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Nt.create(this.top,t,o,r,s,i);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,o,r,s){let i=Nt.create(this.top,e,t,o,r,s);i.contentDOM&&i.updateChildren(r,s+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,o){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let s=new Ba(this.top,e,t,o);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Qt;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Io)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((ve||be)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let o=document.createElement(e);e=="IMG"&&(o.className="ProseMirror-separator",o.alt=""),e=="BR"&&(o.className="ProseMirror-trailingBreak");let r=new Ia(this.top,[],o,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function Up(n,e){let t=e,o=t.children.length,r=n.childCount,s=new Map,i=[];e:for(;r>0;){let l;for(;;)if(o){let d=t.children[o-1];if(d instanceof Qt)t=d,o=d.children.length;else{l=d,o--;break}}else{if(t==e)break e;o=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(r-1))break;--r,s.set(l,r),i.push(l)}}return{index:r,matched:s,matches:i.reverse()}}function Kp(n,e){return n.type.side-e.type.side}function qp(n,e,t,o){let r=e.locals(n),s=0;if(r.length==0){for(let d=0;d<n.childCount;d++){let u=n.child(d);o(u,r,e.forChild(s,u),d),s+=u.nodeSize}return}let i=0,l=[],a=null;for(let d=0;;){let u,f;for(;i<r.length&&r[i].to==s;){let y=r[i++];y.widget&&(u?(f||(f=[u])).push(y):u=y)}if(u)if(f){f.sort(Kp);for(let y=0;y<f.length;y++)t(f[y],d,!!a)}else t(u,d,!!a);let p,h;if(a)h=-1,p=a,a=null;else if(d<n.childCount)h=d,p=n.child(d++);else break;for(let y=0;y<l.length;y++)l[y].to<=s&&l.splice(y--,1);for(;i<r.length&&r[i].from<=s&&r[i].to>s;)l.push(r[i++]);let m=s+p.nodeSize;if(p.isText){let y=m;i<r.length&&r[i].from<y&&(y=r[i].from);for(let k=0;k<l.length;k++)l[k].to<y&&(y=l[k].to);y<m&&(a=p.cut(y-s),p=p.cut(0,y-s),m=y,h=-1)}else for(;i<r.length&&r[i].to<m;)i++;let g=p.isInline&&!p.isLeaf?l.filter(y=>!y.inline):l.slice();o(p,g,e.forChild(s,p),h),s=m}}function Jp(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Gp(n,e,t,o){for(let r=0,s=0;r<n.childCount&&s<=o;){let i=n.child(r++),l=s;if(s+=i.nodeSize,!i.isText)continue;let a=i.text;for(;r<n.childCount;){let d=n.child(r++);if(s+=d.nodeSize,!d.isText)break;a+=d.text}if(s>=t){if(s>=o&&a.slice(o-e.length-l,o-l)==e)return o-e.length;let d=l<o?a.lastIndexOf(e,o-l-1):-1;if(d>=0&&d+e.length+l>=t)return l+d;if(t==o&&a.length>=o+e.length-l&&a.slice(o-l,o-l+e.length)==e)return o}}return-1}function cs(n,e,t,o,r){let s=[];for(let i=0,l=0;i<n.length;i++){let a=n[i],d=l,u=l+=a.size;d>=t||u<=e?s.push(a):(d<e&&s.push(a.slice(0,e-d,o)),r&&(s.push(r),r=void 0),u>t&&s.push(a.slice(t-d,a.size,o)))}return s}function ds(n,e=null){let t=n.domSelectionRange(),o=n.state.doc;if(!t.focusNode)return null;let r=n.docView.nearestDesc(t.focusNode),s=r&&r.size==0,i=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(i<0)return null;let l=o.resolve(i),a,d;if(Ao(t)){for(a=i;r&&!r.node;)r=r.parent;let f=r.node;if(r&&f.isAtom&&$.isSelectable(f)&&r.parent&&!(f.isInline&&Sp(t.focusNode,t.focusOffset,r.dom))){let p=r.posBefore;d=new $(i==p?l:o.resolve(p))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=i,p=i;for(let h=0;h<t.rangeCount;h++){let m=t.getRangeAt(h);f=Math.min(f,n.docView.posFromDOM(m.startContainer,m.startOffset,1)),p=Math.max(p,n.docView.posFromDOM(m.endContainer,m.endOffset,-1))}if(f<0)return null;[a,i]=p==n.state.selection.anchor?[p,f]:[f,p],l=o.resolve(i)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=o.resolve(a);if(!d){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;d=fs(n,u,l,f)}return d}function Pa(n){return n.editable?n.hasFocus():Wa(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function mt(n,e=!1){let t=n.state.selection;if(za(n,t),!!Pa(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&be){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&Yt(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Xp(n);else{let{anchor:o,head:r}=t,s,i;Va&&!(t instanceof U)&&(t.$from.parent.inlineContent||(s=$a(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=$a(n,t.to))),n.docView.setSelection(o,r,n,e),Va&&(s&&La(s),i&&La(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Yp(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const Va=ve||be&&ma<63;function $a(n,e){let{node:t,offset:o}=n.docView.domFromPos(e,0),r=o<t.childNodes.length?t.childNodes[o]:null,s=o?t.childNodes[o-1]:null;if(ve&&r&&r.contentEditable=="false")return us(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return us(r);if(s)return us(s)}}function us(n){return n.contentEditable="true",ve&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function La(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Yp(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),o=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=o||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Pa(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Xp(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,o=t.nodeName=="IMG";o?e.collapse(t.parentNode,we(t)+1):e.collapse(t,0),!o&&!n.state.selection.visible&&Ie&&Mt<=11&&(t.disabled=!0,t.disabled=!1)}function za(n,e){if(e instanceof $){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Fa(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Fa(n)}function Fa(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function fs(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||U.between(e,t,o)}function Ha(n){return n.editable&&!n.hasFocus()?!1:Wa(n)}function Wa(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Zp(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Yt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function hs(n,e){let{$anchor:t,$head:o}=n.selection,r=e>0?t.max(o):t.min(o),s=r.parent.inlineContent?r.depth?n.doc.resolve(e>0?r.after():r.before()):null:r;return s&&J.findFrom(s,e)}function Bt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ja(n,e,t){let o=n.state.selection;if(o instanceof U)if(t.indexOf("s")>-1){let{$head:r}=o,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=n.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return Bt(n,new U(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=hs(n.state,e);return r&&r instanceof $?Bt(n,r):!1}else if(!(Fe&&t.indexOf("m")>-1)){let r=o.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,i;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(i=n.docView.descAt(l))&&!i.contentDOM?$.isSelectable(s)?Bt(n,new $(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):Kn?Bt(n,new U(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(o instanceof $&&o.node.isInline)return Bt(n,new U(e>0?o.$to:o.$from));{let r=hs(n.state,e);return r?Bt(n,r):!1}}}function Do(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Yn(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function En(n,e){return e<0?Qp(n):em(n)}function Qp(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(ze&&t.nodeType==1&&o<Do(t)&&Yn(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(Yn(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Ua(t))break;{let l=t.previousSibling;for(;l&&Yn(l,-1);)r=t.parentNode,s=we(l),l=l.previousSibling;if(l)t=l,o=Do(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?ps(n,t,o):r&&ps(n,r,s)}function em(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=Do(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(Yn(l,1))s=t,i=++o;else break}else{if(Ua(t))break;{let l=t.nextSibling;for(;l&&Yn(l,1);)s=l.parentNode,i=we(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=Do(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&ps(n,s,i)}function Ua(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function tm(n,e){for(;n&&e==n.childNodes.length&&!Un(n);)e=we(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function nm(n,e){for(;n&&!e&&!Un(n);)e=we(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function ps(n,e,t){if(e.nodeType!=3){let s,i;(i=tm(e,t))?(e=i,t=0):(s=nm(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(Ao(o)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),o.removeAllRanges(),o.addRange(s)}else o.extend&&o.extend(e,t);n.domObserver.setCurSelection();let{state:r}=n;setTimeout(()=>{n.state==r&&mt(n)},50)}function Ka(n,e){let t=n.state.doc.resolve(e);if(!(be||ga)&&t.parent.inlineContent){let r=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left<r.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left>r.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function qa(n,e,t){let o=n.state.selection;if(o instanceof U&&!o.empty||t.indexOf("s")>-1||Fe&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=hs(n.state,e);if(i&&i instanceof $)return Bt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof Pe?J.near(i,e):J.findFrom(i,e);return l?Bt(n,l):!1}return!1}function Ja(n,e){if(!(n.state.selection instanceof U))return!0;let{$head:t,$anchor:o,empty:r}=n.state.selection;if(!t.sameParent(o))return!0;if(!r)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let i=n.state.tr;return e<0?i.delete(t.pos-s.nodeSize,t.pos):i.delete(t.pos,t.pos+s.nodeSize),n.dispatch(i),!0}return!1}function Ga(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function om(n){if(!ve||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let o=e.firstChild;Ga(n,o,"true"),setTimeout(()=>Ga(n,o,"false"),20)}return!1}function rm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function sm(n,e){let t=e.keyCode,o=rm(e);if(t==8||Fe&&t==72&&o=="c")return Ja(n,-1)||En(n,-1);if(t==46&&!e.shiftKey||Fe&&t==68&&o=="c")return Ja(n,1)||En(n,1);if(t==13||t==27)return!0;if(t==37||Fe&&t==66&&o=="c"){let r=t==37?Ka(n,n.state.selection.from)=="ltr"?-1:1:-1;return ja(n,r,o)||En(n,r)}else if(t==39||Fe&&t==70&&o=="c"){let r=t==39?Ka(n,n.state.selection.from)=="ltr"?1:-1:1;return ja(n,r,o)||En(n,r)}else{if(t==38||Fe&&t==80&&o=="c")return qa(n,-1,o)||En(n,-1);if(t==40||Fe&&t==78&&o=="c")return om(n)||qa(n,1,o)||En(n,1);if(o==(Fe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function ms(n,e){n.someProp("transformCopied",h=>{e=h(e,n)});let t=[],{content:o,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&o.childCount==1&&o.firstChild.childCount==1;){r--,s--;let h=o.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),o=h.content}let i=n.someProp("clipboardSerializer")||qt.fromSchema(n.state.schema),l=oc(),a=l.createElement("div");a.appendChild(i.serializeFragment(o,{document:l}));let d=a.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=tc[d.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let m=l.createElement(u[h]);for(;a.firstChild;)m.appendChild(a.firstChild);a.appendChild(m),f++}d=a.firstChild}d&&d.nodeType==1&&d.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let p=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,`
|
|
8
|
+
|
|
9
|
+
`);return{dom:a,text:p,slice:e}}function Ya(n,e,t,o,r){let s=r.parent.type.spec.code,i,l;if(!t&&!e)return null;let a=!!e&&(o||s||!t);if(a){if(n.someProp("transformPastedText",p=>{e=p(e,s||o,n)}),s)return l=new R(N.from(n.state.schema.text(e.replace(/\r\n?/g,`
|
|
10
|
+
`))),0,0),n.someProp("transformPasted",p=>{l=p(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",p=>p(e,r,o,n));if(f)l=f;else{let p=r.marks(),{schema:h}=n.state,m=qt.fromSchema(h);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let y=i.appendChild(document.createElement("p"));g&&y.appendChild(m.serializeNode(h.text(g,p)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),i=cm(t),Kn&&dm(i);let d=i&&i.querySelector("[data-pm-slice]"),u=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let p=i.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;i=p}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||dt.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(a||u),context:r,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!im.test(p.parentNode.nodeName)?{ignore:!0}:null}})),u)l=um(ec(l,+u[1],+u[2]),u[4]);else if(l=R.maxOpen(lm(l.content,r),!0),l.openStart||l.openEnd){let f=0,p=0;for(let h=l.content.firstChild;f<l.openStart&&!h.type.spec.isolating;f++,h=h.firstChild);for(let h=l.content.lastChild;p<l.openEnd&&!h.type.spec.isolating;p++,h=h.lastChild);l=ec(l,f,p)}return n.someProp("transformPasted",f=>{l=f(l,n,a)}),l}const im=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function lm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,i=[];if(n.forEach(l=>{if(!i)return;let a=r.findWrapping(l.type),d;if(!a)return i=null;if(d=i.length&&s.length&&Za(a,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=Qa(i[i.length-1],s.length));let u=Xa(l,a);i.push(u),r=r.matchType(u.type),s=a}}),i)return N.from(i)}return n}function Xa(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,N.from(n));return n}function Za(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=Za(n,e,t,o.lastChild,r+1);if(s)return o.copy(o.content.replaceChild(o.childCount-1,s));if(o.contentMatchAt(o.childCount).matchType(r==n.length-1?t.type:n[r+1]))return o.copy(o.content.append(N.from(Xa(t,n,r+1))))}}function Qa(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Qa(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(N.empty,!0);return n.copy(t.append(o))}function gs(n,e,t,o,r,s){let i=e<0?n.firstChild:n.lastChild,l=i.content;return n.childCount>1&&(s=0),r<o-1&&(l=gs(l,e,t,o,r+1,s)),r>=t&&(l=e<0?i.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(i.contentMatchAt(i.childCount).fillBefore(N.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(l))}function ec(n,e,t){return e<n.openStart&&(n=new R(gs(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new R(gs(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const tc={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let nc=null;function oc(){return nc||(nc=document.implementation.createHTMLDocument("title"))}let ys=null;function am(n){let e=window.trustedTypes;return e?(ys||(ys=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),ys.createHTML(n)):n}function cm(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=oc().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&tc[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=am(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function dm(n){let e=n.querySelectorAll(be?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let o=e[t];o.childNodes.length==1&&o.textContent==" "&&o.parentNode&&o.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),o)}}function um(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,o;try{o=JSON.parse(e)}catch{return n}let{content:r,openStart:s,openEnd:i}=n;for(let l=o.length-2;l>=0;l-=2){let a=t.nodes[o[l]];if(!a||a.hasRequiredAttrs())break;r=N.from(a.create(o[l+1],r)),s++,i++}return new R(r,s,i)}const Ne={},Be={},fm={touchstart:!0,touchmove:!0};class hm{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function pm(n){for(let e in Ne){let t=Ne[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{gm(n,o)&&!ws(n,o)&&(n.editable||!(o.type in Be))&&t(n,o)},fm[e]?{passive:!0}:void 0)}ve&&n.dom.addEventListener("input",()=>null),ks(n)}function At(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function mm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ks(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>ws(n,o))})}function ws(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function gm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function ym(n,e){!ws(n,e)&&Ne[e.type]&&(n.editable||!(e.type in Be))&&Ne[e.type](n,e)}Be.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!sc(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(ht&&be&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Cn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let o=Date.now();n.input.lastIOSEnter=o,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==o&&(n.someProp("handleKeyDown",r=>r(n,Xt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||sm(n,t)?t.preventDefault():At(n,"key")},Be.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},Be.keypress=(n,e)=>{let t=e;if(sc(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Fe&&t.metaKey)return;if(n.someProp("handleKeyPress",r=>r(n,t))){t.preventDefault();return}let o=n.state.selection;if(!(o instanceof U)||!o.$from.sameParent(o.$to)){let r=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!n.someProp("handleTextInput",i=>i(n,o.$from.pos,o.$to.pos,r,s))&&n.dispatch(s()),t.preventDefault()}};function Ro(n){return{left:n.clientX,top:n.clientY}}function km(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function bs(n,e,t,o,r){if(o==-1)return!1;let s=n.state.doc.resolve(o);for(let i=s.depth+1;i>0;i--)if(n.someProp(e,l=>i>s.depth?l(n,t,s.nodeAfter,s.before(i),r,!0):l(n,t,s.node(i),s.before(i),r,!1)))return!0;return!1}function Mn(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let o=n.state.tr.setSelection(e);o.setMeta("pointer",!0),n.dispatch(o)}function wm(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&$.isSelectable(o)?(Mn(n,new $(t)),!0):!1}function bm(n,e){if(e==-1)return!1;let t=n.state.selection,o,r;t instanceof $&&(o=t.node);let s=n.state.doc.resolve(e);for(let i=s.depth+1;i>0;i--){let l=i>s.depth?s.nodeAfter:s.node(i);if($.isSelectable(l)){o&&t.$from.depth>0&&i>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(i);break}}return r!=null?(Mn(n,$.create(n.state.doc,r)),!0):!1}function xm(n,e,t,o,r){return bs(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?bm(n,t):wm(n,t))}function Sm(n,e,t,o){return bs(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function Cm(n,e,t,o){return bs(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||vm(n,t,o)}function vm(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(Mn(n,U.create(o,0,o.content.size)),!0):!1;let r=o.resolve(e);for(let s=r.depth+1;s>0;s--){let i=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(i.inlineContent)Mn(n,U.create(o,l+1,l+1+i.content.size));else if($.isSelectable(i))Mn(n,$.create(o,l));else continue;return!0}}function xs(n){return _o(n)}const rc=Fe?"metaKey":"ctrlKey";Ne.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=xs(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&km(t,n.input.lastClick)&&!t[rc]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button};let i=n.posAtCoords(Ro(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Em(n,i,t,!!o)):(s=="doubleClick"?Sm:Cm)(n,i.pos,i.inside,t)?t.preventDefault():At(n,"pointer"))};class Em{constructor(e,t,o,r){this.view=e,this.pos=t,this.event=o,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!o[rc],this.allowDefault=o.shiftKey;let s,i;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),i=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,i=u.depth?u.before():0}const l=r?null:o.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:d}=e.state;(o.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||d instanceof $&&d.from<=i&&d.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ze&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),At(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>mt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Ro(e))),this.updateAllowDefault(e),this.allowDefault||!t?At(this.view,"pointer"):xm(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ve&&this.mightDrag&&!this.mightDrag.node.isAtom||be&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Mn(this.view,J.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):At(this.view,"pointer")}move(e){this.updateAllowDefault(e),At(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ne.touchstart=n=>{n.input.lastTouch=Date.now(),xs(n),At(n,"pointer")},Ne.touchmove=n=>{n.input.lastTouch=Date.now(),At(n,"pointer")},Ne.contextmenu=n=>xs(n);function sc(n,e){return n.composing?!0:ve&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const Mm=ht?5e3:-1;Be.compositionstart=Be.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof U&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(o=>o.type.spec.inclusive===!1)||be&&ga&&Tm(n)))n.markCursor=n.state.storedMarks||t.marks(),_o(n,!0),n.markCursor=null;else if(_o(n,!e.selection.empty),ze&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let o=n.domSelectionRange();for(let r=o.focusNode,s=o.focusOffset;r&&r.nodeType==1&&s!=0;){let i=s<0?r.lastChild:r.childNodes[s-1];if(!i)break;if(i.nodeType==3){let l=n.domSelection();l&&l.collapse(i,i.nodeValue.length);break}else r=i,s=-1}}n.input.composing=!0}ic(n,Mm)};function Tm(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let o=e.childNodes[t];return o.nodeType==1&&o.contentEditable=="false"}Be.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,ic(n,20))};function ic(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>_o(n),e))}function lc(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Bm());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Nm(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=bp(e.focusNode,e.focusOffset),o=xp(e.focusNode,e.focusOffset);if(t&&o&&t!=o){let r=o.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||o==s)return s;if(!r||!r.isText(o.nodeValue))return o;if(n.input.compositionNode==o){let i=t.pmViewDesc;if(!(!i||!i.isText(t.nodeValue)))return o}}return t||o}function Bm(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function _o(n,e=!1){if(!(ht&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),lc(n),e||n.docView&&n.docView.dirty){let t=ds(n),o=n.state.selection;return t&&!t.eq(o)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function Am(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let o=getSelection(),r=document.createRange();r.selectNodeContents(e),n.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const Xn=Ie&&Mt<15||Cn&&Ep<604;Ne.copy=Be.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=Xn?null:t.clipboardData,i=o.content(),{dom:l,text:a}=ms(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Am(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Im(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Om(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,o=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),o.parentNode&&o.parentNode.removeChild(o),t?Zn(n,o.value,null,r,e):Zn(n,o.textContent,o.innerHTML,r,e)},50)}function Zn(n,e,t,o,r){let s=Ya(n,e,t,o,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,r,s||R.empty)))return!0;if(!s)return!1;let i=Im(s),l=i?n.state.tr.replaceSelectionWith(i,o):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function ac(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}Be.paste=(n,e)=>{let t=e;if(n.composing&&!ht)return;let o=Xn?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&Zn(n,ac(o),o.getData("text/html"),r,t)?t.preventDefault():Om(n,t)};class cc{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const Dm=Fe?"altKey":"ctrlKey";function dc(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[Dm]}Ne.dragstart=(n,e)=>{let t=e,o=n.input.mouseDown;if(o&&o.done(),!t.dataTransfer)return;let r=n.state.selection,s=r.empty?null:n.posAtCoords(Ro(t)),i;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof $?r.to-1:r.to))){if(o&&o.mightDrag)i=$.create(n.state.doc,o.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(i=$.create(n.state.doc,f.posBefore))}}let l=(i||n.state.selection).content(),{dom:a,text:d,slice:u}=ms(n,l);(!t.dataTransfer.files.length||!be||ma>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Xn?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Xn||t.dataTransfer.setData("text/plain",d),n.dragging=new cc(u,dc(n,t),i)},Ne.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},Be.dragover=Be.dragenter=(n,e)=>e.preventDefault(),Be.drop=(n,e)=>{try{Rm(n,e,n.dragging)}finally{n.dragging=null}};function Rm(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(Ro(e));if(!o)return;let r=n.state.doc.resolve(o.pos),s=t&&t.slice;s?n.someProp("transformPasted",h=>{s=h(s,n,!1)}):s=Ya(n,ac(e.dataTransfer),Xn?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&dc(n,e));if(n.someProp("handleDrop",h=>h(n,e,s||R.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Ll(n.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let a=n.state.tr;if(i){let{node:h}=t;h?h.replace(a):a.deleteSelection()}let d=a.mapping.map(l),u=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(u?a.replaceRangeWith(d,d,s.content.firstChild):a.replaceRange(d,d,s),a.doc.eq(f))return;let p=a.doc.resolve(d);if(u&&$.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new $(p));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,k)=>h=k),a.setSelection(fs(n,p,a.doc.resolve(h)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Ne.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&mt(n)},20))},Ne.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)},Ne.beforeinput=(n,e)=>{if(be&&ht&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:o}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=o||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,Xt(8,"Backspace")))))return;let{$cursor:r}=n.state.selection;r&&r.pos>0&&n.dispatch(n.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let n in Be)Ne[n]=Be[n];function Qn(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class Po{constructor(e,t){this.toDOM=e,this.spec=t||tn,this.side=this.spec.side||0}map(e,t,o,r){let{pos:s,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Ae(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof Po&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Qn(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class It{constructor(e,t){this.attrs=e,this.spec=t||tn}map(e,t,o,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-o,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-o;return s>=i?null:new Ae(s,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof It&&Qn(this.attrs,e.attrs)&&Qn(this.spec,e.spec)}static is(e){return e.type instanceof It}destroy(){}}class Ss{constructor(e,t){this.attrs=e,this.spec=t||tn}map(e,t,o,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let i=e.mapResult(t.to+r,-1);return i.deleted||i.pos<=s.pos?null:new Ae(s.pos-o,i.pos-o,this)}valid(e,t){let{index:o,offset:r}=e.content.findIndex(t.from),s;return r==t.from&&!(s=e.child(o)).isText&&r+s.nodeSize==t.to}eq(e){return this==e||e instanceof Ss&&Qn(this.attrs,e.attrs)&&Qn(this.spec,e.spec)}destroy(){}}class Ae{constructor(e,t,o){this.from=e,this.to=t,this.type=o}copy(e,t){return new Ae(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,o){return this.type.map(e,this,t,o)}static widget(e,t,o){return new Ae(e,e,new Po(t,o))}static inline(e,t,o,r){return new Ae(e,t,new It(o,r))}static node(e,t,o,r){return new Ae(e,t,new Ss(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof It}get widget(){return this.type instanceof Po}}const Tn=[],tn={};class re{constructor(e,t){this.local=e.length?e:Tn,this.children=t.length?t:Tn}static create(e,t){return t.length?Vo(t,e,0,tn):Ee}find(e,t,o){let r=[];return this.findInner(e??0,t??1e9,r,0,o),r}findInner(e,t,o,r,s){for(let i=0;i<this.local.length;i++){let l=this.local[i];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&o.push(l.copy(l.from+r,l.to+r))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let l=this.children[i]+1;this.children[i+2].findInner(e-l,t-l,o,r+l,s)}}map(e,t,o){return this==Ee||e.maps.length==0?this:this.mapInner(e,t,0,0,o||tn)}mapInner(e,t,o,r,s){let i;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,o,r);a&&a.type.valid(t,a)?(i||(i=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?_m(this.children,i||[],e,t,o,r,s):i?new re(i.sort(nn),Tn):Ee}add(e,t){return t.length?this==Ee?re.create(e,t):this.addInner(e,t,0):this}addInner(e,t,o){let r,s=0;e.forEach((l,a)=>{let d=a+o,u;if(u=fc(t,l,d)){for(r||(r=this.children.slice());s<r.length&&r[s]<a;)s+=3;r[s]==a?r[s+2]=r[s+2].addInner(l,u,d+1):r.splice(s,0,a,a+l.nodeSize,Vo(u,l,d+1,tn)),s+=3}});let i=uc(s?hc(t):t,-o);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||i.splice(l--,1);return new re(i.length?this.local.concat(i).sort(nn):this.local,r||this.children)}remove(e){return e.length==0||this==Ee?this:this.removeInner(e,0)}removeInner(e,t){let o=this.children,r=this.local;for(let s=0;s<o.length;s+=3){let i,l=o[s]+t,a=o[s+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<a&&(e[u]=null,(i||(i=[])).push(f));if(!i)continue;o==this.children&&(o=this.children.slice());let d=o[s+2].removeInner(i,l+1);d!=Ee?o[s+2]=d:(o.splice(s,3),s-=3)}if(r.length){for(let s=0,i;s<e.length;s++)if(i=e[s])for(let l=0;l<r.length;l++)r[l].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return o==this.children&&r==this.local?this:r.length||o.length?new re(r,o):Ee}forChild(e,t){if(this==Ee)return this;if(t.isLeaf)return re.empty;let o,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(o=this.children[l+2]);break}let s=e+1,i=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<i&&a.to>s&&a.type instanceof It){let d=Math.max(s,a.from)-s,u=Math.min(i,a.to)-s;d<u&&(r||(r=[])).push(a.copy(d,u))}}if(r){let l=new re(r.sort(nn),Tn);return o?new Ot([l,o]):l}return o||Ee}eq(e){if(this==e)return!0;if(!(e instanceof re)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return Cs(this.localsInner(e))}localsInner(e){if(this==Ee)return Tn;if(e.inlineContent||!this.local.some(It.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof It||t.push(this.local[o]);return t}forEachSet(e){e(this)}}re.empty=new re([],[]),re.removeOverlap=Cs;const Ee=re.empty;class Ot{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,tn));return Ot.from(o)}forChild(e,t){if(t.isLeaf)return re.empty;let o=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=Ee&&(s instanceof Ot?o=o.concat(s.members):o.push(s))}return Ot.from(o)}eq(e){if(!(e instanceof Ot)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,o=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{o&&(t=t.slice(),o=!1);for(let i=0;i<s.length;i++)t.push(s[i])}}return t?Cs(o?t:t.sort(nn)):Tn}static from(e){switch(e.length){case 0:return Ee;case 1:return e[0];default:return new Ot(e.every(t=>t instanceof re)?e:e.reduce((t,o)=>t.concat(o instanceof re?o:o.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function _m(n,e,t,o,r,s,i){let l=n.slice();for(let d=0,u=s;d<t.maps.length;d++){let f=0;t.maps[d].forEach((p,h,m,g)=>{let y=g-m-(h-p);for(let k=0;k<l.length;k+=3){let w=l[k+1];if(w<0||p>w+u-f)continue;let b=l[k]+u-f;h>=b?l[k+1]=p<=b?-2:-1:p>=u&&y&&(l[k]+=y,l[k+1]+=y)}f+=y}),u=t.maps[d].map(u,-1)}let a=!1;for(let d=0;d<l.length;d+=3)if(l[d+1]<0){if(l[d+1]==-2){a=!0,l[d+1]=-1;continue}let u=t.map(n[d]+s),f=u-r;if(f<0||f>=o.content.size){a=!0;continue}let p=t.map(n[d+1]+s,-1),h=p-r,{index:m,offset:g}=o.content.findIndex(f),y=o.maybeChild(m);if(y&&g==f&&g+y.nodeSize==h){let k=l[d+2].mapInner(t,y,u+1,n[d]+s+1,i);k!=Ee?(l[d]=f,l[d+1]=h,l[d+2]=k):(l[d+1]=-2,a=!0)}else a=!0}if(a){let d=Pm(l,n,e,t,r,s,i),u=Vo(d,o,0,i);e=u.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,p=0;f<u.children.length;f+=3){let h=u.children[f];for(;p<l.length&&l[p]<h;)p+=3;l.splice(p,0,u.children[f],u.children[f+1],u.children[f+2])}}return new re(e.sort(nn),l)}function uc(n,e){if(!e||!n.length)return n;let t=[];for(let o=0;o<n.length;o++){let r=n[o];t.push(new Ae(r.from+e,r.to+e,r.type))}return t}function Pm(n,e,t,o,r,s,i){function l(a,d){for(let u=0;u<a.local.length;u++){let f=a.local[u].map(o,r,d);f?t.push(f):i.onRemove&&i.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+d+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+s+1);return t}function fc(n,e,t){if(e.isLeaf)return null;let o=t+e.nodeSize,r=null;for(let s=0,i;s<n.length;s++)(i=n[s])&&i.from>t&&i.to<o&&((r||(r=[])).push(i),n[s]=null);return r}function hc(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Vo(n,e,t,o){let r=[],s=!1;e.forEach((l,a)=>{let d=fc(n,l,a+t);if(d){s=!0;let u=Vo(d,l,t+a+1,o);u!=Ee&&r.push(a,a+l.nodeSize,u)}});let i=uc(s?hc(n):n,-t).sort(nn);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||(o.onRemove&&o.onRemove(i[l].spec),i.splice(l--,1));return i.length||r.length?new re(i,r):Ee}function nn(n,e){return n.from-e.from||n.to-e.to}function Cs(n){let e=n;for(let t=0;t<e.length-1;t++){let o=e[t];if(o.from!=o.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==o.from){s.to!=o.to&&(e==n&&(e=n.slice()),e[r]=s.copy(s.from,o.to),pc(e,r+1,s.copy(o.to,s.to)));continue}else{s.from<o.to&&(e==n&&(e=n.slice()),e[t]=o.copy(o.from,s.from),pc(e,r,o.copy(s.from,o.to)));break}}}return e}function pc(n,e,t){for(;e<n.length&&nn(t,n[e])>0;)e++;n.splice(e,0,t)}function vs(n){let e=[];return n.someProp("decorations",t=>{let o=t(n.state);o&&o!=Ee&&e.push(o)}),n.cursorWrapper&&e.push(re.create(n.state.doc,[n.cursorWrapper.deco])),Ot.from(e)}const Vm={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},$m=Ie&&Mt<=11;class Lm{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class zm{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Lm,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(o=>{for(let r=0;r<o.length;r++)this.queue.push(o[r]);Ie&&Mt<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():ve&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),$m&&(this.onCharData=o=>{this.queue.push({target:o.target,type:"characterData",oldValue:o.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Vm)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Ha(this.view)){if(this.suppressingSelectionUpdates)return mt(this.view);if(Ie&&Mt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Yt(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,o;for(let s=e.focusNode;s;s=Sn(s))t.add(s);for(let s=e.anchorNode;s;s=Sn(s))if(t.has(s)){o=s;break}let r=o&&this.view.docView.nearestDesc(o);if(r&&r.ignoreMutation({type:"selection",target:o.nodeType==3?o.parentNode:o}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let o=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(o)&&Ha(e)&&!this.ignoreSelectionChange(o),s=-1,i=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],a);f&&(s=s<0?f.from:Math.min(f.from,s),i=i<0?f.to:Math.max(f.to,i),f.typeOver&&(l=!0))}if(a.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of a)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(ze&&a.length){let u=a.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,p]=u;f.parentNode&&f.parentNode.parentNode==p.parentNode?p.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let p of u){let h=p.parentNode;h&&h.nodeName=="LI"&&(!f||Wm(e,f)!=h)&&p.remove()}}}let d=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ao(o)&&(d=ds(e))&&d.eq(J.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,mt(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),Fm(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,jm(e,a)),this.handleDOMChange(s,i,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||mt(e),this.currentSelection.set(o))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let o=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(o==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!o||o.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(o.contentDOM&&o.contentDOM!=o.dom&&!o.contentDOM.contains(e.target))return{from:o.posBefore,to:o.posAfter};let r=e.previousSibling,s=e.nextSibling;if(Ie&&Mt<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:p}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!p||Array.prototype.indexOf.call(e.addedNodes,p)<0)&&(s=p)}let i=r&&r.parentNode==e.target?we(r)+1:0,l=o.localPosFromDOM(e.target,i,-1),a=s&&s.parentNode==e.target?we(s):e.target.childNodes.length,d=o.localPosFromDOM(e.target,a,1);return{from:l,to:d}}else return e.type=="attributes"?{from:o.posAtStart-o.border,to:o.posAtEnd+o.border}:(this.lastChangedTextNode=e.target,{from:o.posAtStart,to:o.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let mc=new WeakMap,gc=!1;function Fm(n){if(!mc.has(n)&&(mc.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=ze,gc)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),gc=!0}}function yc(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return Yt(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function Hm(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return yc(n,r)}let t;function o(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",o,!0),t?yc(n,t):null}function Wm(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let o=n.docView.nearestDesc(t,!0);if(o&&o.node.isBlock)return t}return null}function jm(n,e){var t;let{focusNode:o,focusOffset:r}=n.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let i=s.nextSibling;for(;i&&i.nodeName!="TD"&&i.nodeName!="TH";)i=i.nextSibling;if(i){let l=i;for(;;){let a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),o==s&&n.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function Um(n,e,t){let{node:o,fromOffset:r,toOffset:s,from:i,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),d,u=a.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(d=[{node:u,offset:a.anchorOffset}],Ao(a)||d.push({node:a.focusNode,offset:a.focusOffset})),be&&n.input.lastKeyCode===8)for(let y=s;y>r;y--){let k=o.childNodes[y-1],w=k.pmViewDesc;if(k.nodeName=="BR"&&!w){s=y;break}if(!w||w.size)break}let f=n.state.doc,p=n.someProp("domParser")||dt.fromSchema(n.state.schema),h=f.resolve(i),m=null,g=p.parse(o,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:r,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:d,ruleFromNode:Km,context:h});if(d&&d[0].pos!=null){let y=d[0].pos,k=d[1]&&d[1].pos;k==null&&(k=y),m={anchor:y+i,head:k+i}}return{doc:g,sel:m,from:i,to:l}}function Km(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(ve&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||ve&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const qm=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Jm(n,e,t,o,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let C=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,M=ds(n,C);if(M&&!n.state.selection.eq(M)){if(be&&ht&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",I=>I(n,Xt(13,"Enter"))))return;let B=n.state.tr.setSelection(M);C=="pointer"?B.setMeta("pointer",!0):C=="key"&&B.scrollIntoView(),s&&B.setMeta("composition",s),n.dispatch(B)}return}let i=n.state.doc.resolve(e),l=i.sharedDepth(t);e=i.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,d=Um(n,e,t),u=n.state.doc,f=u.slice(d.from,d.to),p,h;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(p=n.state.selection.to,h="end"):(p=n.state.selection.from,h="start"),n.input.lastKeyCode=null;let m=Xm(f.content,d.doc.content,d.from,p,h);if(m&&n.input.domChangeCount++,(Cn&&n.input.lastIOSEnter>Date.now()-225||ht)&&r.some(C=>C.nodeType==1&&!qm.test(C.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",C=>C(n,Xt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(o&&a instanceof U&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(d.sel&&d.sel.anchor!=d.sel.head))m={start:a.from,endA:a.to,endB:a.to};else{if(d.sel){let C=kc(n,n.state.doc,d.sel);if(C&&!C.eq(n.state.selection)){let M=n.state.tr.setSelection(C);s&&M.setMeta("composition",s),n.dispatch(M)}}return}n.state.selection.from<n.state.selection.to&&m.start==m.endB&&n.state.selection instanceof U&&(m.start>n.state.selection.from&&m.start<=n.state.selection.from+2&&n.state.selection.from>=d.from?m.start=n.state.selection.from:m.endA<n.state.selection.to&&m.endA>=n.state.selection.to-2&&n.state.selection.to<=d.to&&(m.endB+=n.state.selection.to-m.endA,m.endA=n.state.selection.to)),Ie&&Mt<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>d.from&&d.doc.textBetween(m.start-d.from-1,m.start-d.from+1)==" "&&(m.start--,m.endA--,m.endB--);let g=d.doc.resolveNoCache(m.start-d.from),y=d.doc.resolveNoCache(m.endB-d.from),k=u.resolve(m.start),w=g.sameParent(y)&&g.parent.inlineContent&&k.end()>=m.endA;if((Cn&&n.input.lastIOSEnter>Date.now()-225&&(!w||r.some(C=>C.nodeName=="DIV"||C.nodeName=="P"))||!w&&g.pos<d.doc.content.size&&(!g.sameParent(y)||!g.parent.inlineContent)&&g.pos<y.pos&&!/\S/.test(d.doc.textBetween(g.pos,y.pos,"","")))&&n.someProp("handleKeyDown",C=>C(n,Xt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&Ym(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",C=>C(n,Xt(8,"Backspace")))){ht&&be&&n.domObserver.suppressSelectionUpdates();return}be&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),ht&&!w&&g.start()!=y.start()&&y.parentOffset==0&&g.depth==y.depth&&d.sel&&d.sel.anchor==d.sel.head&&d.sel.head==m.endA&&(m.endB-=2,y=d.doc.resolveNoCache(m.endB-d.from),setTimeout(()=>{n.someProp("handleKeyDown",function(C){return C(n,Xt(13,"Enter"))})},20));let b=m.start,S=m.endA,v=C=>{let M=C||n.state.tr.replace(b,S,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let B=kc(n,M.doc,d.sel);B&&!(be&&n.composing&&B.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(B.head==b||B.head==M.mapping.map(S)-1)||Ie&&B.empty&&B.head==b)&&M.setSelection(B)}return s&&M.setMeta("composition",s),M.scrollIntoView()},E;if(w)if(g.pos==y.pos){Ie&&Mt<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>mt(n),20));let C=v(n.state.tr.delete(b,S)),M=u.resolve(m.start).marksAcross(u.resolve(m.endA));M&&C.ensureMarks(M),n.dispatch(C)}else if(m.endA==m.endB&&(E=Gm(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let C=v(n.state.tr);E.type=="add"?C.addMark(b,S,E.mark):C.removeMark(b,S,E.mark),n.dispatch(C)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let C=g.parent.textBetween(g.parentOffset,y.parentOffset),M=()=>v(n.state.tr.insertText(C,b,S));n.someProp("handleTextInput",B=>B(n,b,S,C,M))||n.dispatch(M())}else n.dispatch(v());else n.dispatch(v())}function kc(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:fs(n,e.resolve(t.anchor),e.resolve(t.head))}function Gm(n,e){let t=n.firstChild.marks,o=e.firstChild.marks,r=t,s=o,i,l,a;for(let u=0;u<o.length;u++)r=o[u].removeFromSet(r);for(let u=0;u<t.length;u++)s=t[u].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],i="add",a=u=>u.mark(l.addToSet(u.marks));else if(r.length==0&&s.length==1)l=s[0],i="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let d=[];for(let u=0;u<e.childCount;u++)d.push(a(e.child(u)));if(N.from(d).eq(n))return{mark:l,type:i}}function Ym(n,e,t,o,r){if(t-e<=r.pos-o.pos||Es(o,!0,!1)<r.pos)return!1;let s=n.resolve(e);if(!o.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let i=n.resolve(Es(s,!0,!0));return!i.parent.isTextblock||i.pos>t||Es(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function Es(n,e,t){let o=n.depth,r=e?n.end():n.pos;for(;o>0&&(e||n.indexAfter(o)==n.node(o).childCount);)o--,r++,e=!1;if(t){let s=n.node(o).maybeChild(n.indexAfter(o));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function Xm(n,e,t,o,r){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:i,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(r=="end"){let a=Math.max(0,s-Math.min(i,l));o-=i+a-s}if(i<s&&n.size<e.size){let a=o<=s&&o>=i?s-o:0;s-=a,s&&s<e.size&&wc(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-i),i=s}else if(l<s){let a=o<=s&&o>=l?s-o:0;s-=a,s&&s<n.size&&wc(n.textBetween(s-1,s+1))&&(s+=a?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function wc(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class bc{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new hm,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ec),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Cc(this),Sc(this),this.nodeViews=vc(this),this.docView=Aa(this.state.doc,xc(this),vs(this),this.dom,this),this.domObserver=new zm(this,(o,r,s,i)=>Jm(this,o,r,s,i)),this.domObserver.start(),pm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ks(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ec),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let o in this._props)t[o]=this._props[o];t.state=this.state;for(let o in e)t[o]=e[o];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var o;let r=this.state,s=!1,i=!1;e.storedMarks&&this.composing&&(lc(this),i=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let h=vc(this);Qm(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ks(this),this.editable=Cc(this),Sc(this);let a=vs(this),d=xc(this),u=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,d,a);(f||!e.selection.eq(r.selection))&&(i=!0);let p=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&Np(this);if(i){this.domObserver.stop();let h=f&&(Ie||be)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&Zm(r.selection,e.selection);if(f){let m=be?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Nm(this)),(s||!this.docView.update(e.doc,d,a,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=Aa(e.doc,d,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Zp(this))?mt(this,h):(za(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((o=this.dragging)===null||o===void 0)&&o.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():p&&Bp(p)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof $){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&ya(this,t.getBoundingClientRect(),e)}else ya(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let o=this.directPlugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let o=this.state.plugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let o=this.pluginViews[t];o.update&&o.update(this,e)}}updateDraggedNode(e,t){let o=e.node,r=-1;if(this.state.doc.nodeAt(o.from)==o.node)r=o.from;else{let s=o.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==o.node&&(r=s)}this.dragging=new cc(e.slice,e.move,r<0?void 0:$.create(this.state.doc,r))}someProp(e,t){let o=this._props&&this._props[e],r;if(o!=null&&(r=t?t(o):o))return r;for(let i=0;i<this.directPlugins.length;i++){let l=this.directPlugins[i].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let i=0;i<s.length;i++){let l=s[i].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(Ie){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&Ap(this.dom),mt(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return _p(this,e)}coordsAtPos(e,t=1){return Ca(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,o=-1){let r=this.docView.posFromDOM(e,t,o);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return zp(this,t||this.state,e)}pasteHTML(e,t){return Zn(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Zn(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ms(this,e)}destroy(){this.docView&&(mm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],vs(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,kp())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ym(this,e)}domSelectionRange(){let e=this.domSelection();return e?ve&&this.root.nodeType===11&&Cp(this.dom.ownerDocument)==this.dom&&Hm(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}bc.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function xc(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let o in t)o=="class"?e.class+=" "+t[o]:o=="style"?e.style=(e.style?e.style+";":"")+t[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(t[o]))}),e.translate||(e.translate="no"),[Ae.node(0,n.state.doc.content.size,e)]}function Sc(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Ae.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Cc(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Zm(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function vc(n){let e=Object.create(null);function t(o){for(let r in o)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=o[r])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Qm(n,e){let t=0,o=0;for(let r in n){if(n[r]!=e[r])return!0;t++}for(let r in e)o++;return t!=o}function Ec(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var Dt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},$o={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},eg=typeof navigator<"u"&&/Mac/.test(navigator.platform),tg=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),xe=0;xe<10;xe++)Dt[48+xe]=Dt[96+xe]=String(xe);for(var xe=1;xe<=24;xe++)Dt[xe+111]="F"+xe;for(var xe=65;xe<=90;xe++)Dt[xe]=String.fromCharCode(xe+32),$o[xe]=String.fromCharCode(xe);for(var Ms in Dt)$o.hasOwnProperty(Ms)||($o[Ms]=Dt[Ms]);function ng(n){var e=eg&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||tg&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?$o:Dt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const og=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),rg=typeof navigator<"u"&&/Win/.test(navigator.platform);function sg(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))i=!0;else if(/^a(lt)?$/i.test(a))o=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))og?i=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return o&&(t="Alt-"+t),r&&(t="Ctrl-"+t),i&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function ig(n){let e=Object.create(null);for(let t in n)e[sg(t)]=n[t];return e}function Ts(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function lg(n){return new ue({props:{handleKeyDown:Mc(n)}})}function Mc(n){let e=ig(n);return function(t,o){let r=ng(o),s,i=e[Ts(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[Ts(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(rg&&o.ctrlKey&&o.altKey)&&(s=Dt[o.keyCode])&&s!=r){let l=e[Ts(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var ag=Object.defineProperty,Ns=(n,e)=>{for(var t in e)ag(n,t,{get:e[t],enumerable:!0})};function Lo(n){const{state:e,transaction:t}=n;let{selection:o}=t,{doc:r}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return o},get doc(){return r},get tr(){return o=t.selection,r=t.doc,s=t.storedMarks,t}}}var zo=class{constructor(n){this.editor=n.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=n.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:n,editor:e,state:t}=this,{view:o}=e,{tr:r}=t,s=this.buildProps(r);return Object.fromEntries(Object.entries(n).map(([i,l])=>[i,(...d)=>{const u=l(...d)(s);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(r),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i=[],l=!!n,a=n||r.tr,d=()=>(!l&&e&&!a.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(a),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(t).map(([f,p])=>[f,(...m)=>{const g=this.buildProps(a,e),y=p(...m)(g);return i.push(y),u}])),run:d};return u}createCan(n){const{rawCommands:e,state:t}=this,o=!1,r=n||t.tr,s=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...d)=>a(...d)({...s,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i={tr:n,editor:o,view:s,state:Lo({state:r,transaction:n}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(n,e),can:()=>this.createCan(n),get commands(){return Object.fromEntries(Object.entries(t).map(([l,a])=>[l,(...d)=>a(...d)(i)]))}};return i}},Tc={};Ns(Tc,{blur:()=>cg,clearContent:()=>dg,clearNodes:()=>ug,command:()=>fg,createParagraphNear:()=>hg,cut:()=>pg,deleteCurrentNode:()=>mg,deleteNode:()=>gg,deleteRange:()=>yg,deleteSelection:()=>kg,enter:()=>wg,exitCode:()=>bg,extendMarkRange:()=>xg,first:()=>Sg,focus:()=>vg,forEach:()=>Eg,insertContent:()=>Mg,insertContentAt:()=>Bg,joinBackward:()=>Og,joinDown:()=>Ig,joinForward:()=>Dg,joinItemBackward:()=>Rg,joinItemForward:()=>_g,joinTextblockBackward:()=>Pg,joinTextblockForward:()=>Vg,joinUp:()=>Ag,keyboardShortcut:()=>Lg,lift:()=>zg,liftEmptyBlock:()=>Fg,liftListItem:()=>Hg,newlineInCode:()=>Wg,resetAttributes:()=>jg,scrollIntoView:()=>Ug,selectAll:()=>Kg,selectNodeBackward:()=>qg,selectNodeForward:()=>Jg,selectParentNode:()=>Gg,selectTextblockEnd:()=>Yg,selectTextblockStart:()=>Xg,setContent:()=>Zg,setMark:()=>y0,setMeta:()=>k0,setNode:()=>w0,setNodeSelection:()=>b0,setTextDirection:()=>x0,setTextSelection:()=>S0,sinkListItem:()=>C0,splitBlock:()=>v0,splitListItem:()=>E0,toggleList:()=>M0,toggleMark:()=>T0,toggleNode:()=>N0,toggleWrap:()=>B0,undoInputRule:()=>A0,unsetAllMarks:()=>I0,unsetMark:()=>O0,unsetTextDirection:()=>D0,updateAttributes:()=>R0,wrapIn:()=>_0,wrapInList:()=>P0});var cg=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),dg=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),ug=()=>({state:n,tr:e,dispatch:t})=>{const{selection:o}=e,{ranges:r}=o;return t&&r.forEach(({$from:s,$to:i})=>{n.doc.nodesBetween(s.pos,i.pos,(l,a)=>{if(l.type.isText)return;const{doc:d,mapping:u}=e,f=d.resolve(u.map(a)),p=d.resolve(u.map(a+l.nodeSize)),h=f.blockRange(p);if(!h)return;const m=gn(h);if(l.type.isTextblock){const{defaultType:g}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(h.start,g)}(m||m===0)&&e.lift(h,m)})}),!0},fg=n=>e=>n(e),hg=()=>({state:n,dispatch:e})=>la(n,e),pg=(n,e)=>({editor:t,tr:o})=>{const{state:r}=t,s=r.doc.slice(n.from,n.to);o.deleteRange(n.from,n.to);const i=o.mapping.map(e);return o.insert(i,s.content),o.setSelection(new U(o.doc.resolve(Math.max(i-1,0)))),!0},mg=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,o=t.$anchor.node();if(o.content.size>0)return!1;const r=n.selection.$anchor;for(let s=r.depth;s>0;s-=1)if(r.node(s).type===o.type){if(e){const l=r.before(s),a=r.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1};function me(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}var gg=n=>({tr:e,state:t,dispatch:o})=>{const r=me(n,t.schema),s=e.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===r){if(o){const a=s.before(i),d=s.after(i);e.delete(a,d).scrollIntoView()}return!0}return!1},yg=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},kg=()=>({state:n,dispatch:e})=>Yr(n,e),wg=()=>({commands:n})=>n.keyboardShortcut("Enter"),bg=()=>({state:n,dispatch:e})=>op(n,e);function Bs(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function Fo(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:Bs(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function Nc(n,e,t={}){return n.find(o=>o.type===e&&Fo(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function Bc(n,e,t={}){return!!Nc(n,e,t)}function As(n,e,t){var o;if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if((!r.node||!r.node.marks.some(u=>u.type===e))&&(r=n.parent.childBefore(n.parentOffset)),!r.node||!r.node.marks.some(u=>u.type===e)||(t=t||((o=r.node.marks[0])==null?void 0:o.attrs),!Nc([...r.node.marks],e,t)))return;let i=r.index,l=n.start()+r.offset,a=i+1,d=l+r.node.nodeSize;for(;i>0&&Bc([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;a<n.parent.childCount&&Bc([...n.parent.child(a).marks],e,t);)d+=n.parent.child(a).nodeSize,a+=1;return{from:l,to:d}}function gt(n,e){if(typeof n=="string"){if(!e.marks[n])throw Error(`There is no mark type named '${n}'. Maybe you forgot to add the extension?`);return e.marks[n]}return n}var xg=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=gt(n,o.schema),{doc:i,selection:l}=t,{$from:a,from:d,to:u}=l;if(r){const f=As(a,s,e);if(f&&f.from<=d&&f.to>=u){const p=U.create(i,f.from,f.to);t.setSelection(p)}}return!0},Sg=n=>e=>{const t=typeof n=="function"?n(e):n;for(let o=0;o<t.length;o+=1)if(t[o](e))return!0;return!1};function Ac(n){return n instanceof U}function on(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function Ic(n,e=null){if(!e)return null;const t=J.atStart(n),o=J.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return o;const r=t.from,s=o.to;return e==="all"?U.create(n,on(0,r,s),on(n.content.size,r,s)):U.create(n,on(e,r,s),on(e,r,s))}function Oc(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function Ho(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function Cg(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var vg=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(Ho()||Oc())&&o.dom.focus(),Cg()&&!Ho()&&!Oc()&&o.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{t.isDestroyed||(o.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};try{if(o.hasFocus()&&n===null||n===!1)return!0}catch{return!1}if(s&&n===null&&!Ac(t.state.selection))return i(),!0;const l=Ic(r.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},Eg=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),Mg=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),Dc=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const o=e[t];o.nodeType===3&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?n.removeChild(o):o.nodeType===1&&Dc(o)}return n};function eo(n){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return Dc(t)}function to(n,e,t){if(n instanceof ct||n instanceof N)return n;t={slice:!0,parseOptions:{},...t};const o=typeof n=="object"&&n!==null,r=typeof n=="string";if(o)try{if(Array.isArray(n)&&n.length>0)return N.fromArray(n.map(l=>e.nodeFromJSON(l)));const i=e.nodeFromJSON(n);return t.errorOnInvalidContent&&i.check(),i}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),to("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const a=new kl({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:d=>(i=!0,l=typeof d=="string"?d:d.outerHTML,null)}]}})});if(t.slice?dt.fromSchema(a).parseSlice(eo(n),t.parseOptions):dt.fromSchema(a).parse(eo(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=dt.fromSchema(e);return t.slice?s.parseSlice(eo(n),t.parseOptions).content:s.parse(eo(n),t.parseOptions)}return to("",e,t)}function Tg(n,e,t){const o=n.steps.length-1;if(o<e)return;const r=n.steps[o];if(!(r instanceof he||r instanceof pe))return;const s=n.mapping.maps[o];let i=0;s.forEach((l,a,d,u)=>{i===0&&(i=u)}),n.setSelection(J.near(n.doc.resolve(i),t))}var Ng=n=>!("type"in n),Bg=(n,e,t)=>({tr:o,dispatch:r,editor:s})=>{var i;if(r){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;const a=y=>{s.emit("contentError",{editor:s,error:y,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},d={preserveWhitespace:"full",...t.parseOptions};if(!t.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{to(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){a(y)}try{l=to(e,s.schema,{parseOptions:d,errorOnInvalidContent:(i=t.errorOnInvalidContent)!=null?i:s.options.enableContentCheck})}catch(y){return a(y),!1}let{from:u,to:f}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},p=!0,h=!0;if((Ng(l)?l:[l]).forEach(y=>{y.check(),p=p?y.isText&&y.marks.length===0:!1,h=h?y.isBlock:!1}),u===f&&h){const{parent:y}=o.doc.resolve(u);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(u-=1,f+=1)}let g;if(p){if(Array.isArray(e))g=e.map(y=>y.text||"").join("");else if(e instanceof N){let y="";e.forEach(k=>{k.text&&(y+=k.text)}),g=y}else typeof e=="object"&&e&&e.text?g=e.text:g=e;o.insertText(g,u,f)}else{g=l;const y=o.doc.resolve(u),k=y.node(),w=y.parentOffset===0,b=k.isText||k.isTextblock,S=k.content.size>0;w&&b&&S&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&Tg(o,o.steps.length-1,-1),t.applyInputRules&&o.setMeta("applyInputRules",{from:u,text:g}),t.applyPasteRules&&o.setMeta("applyPasteRules",{from:u,text:g})}return!0},Ag=()=>({state:n,dispatch:e})=>ep(n,e),Ig=()=>({state:n,dispatch:e})=>tp(n,e),Og=()=>({state:n,dispatch:e})=>ea(n,e),Dg=()=>({state:n,dispatch:e})=>ra(n,e),Rg=()=>({state:n,dispatch:e,tr:t})=>{try{const o=Mo(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},_g=()=>({state:n,dispatch:e,tr:t})=>{try{const o=Mo(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},Pg=()=>({state:n,dispatch:e})=>Zh(n,e),Vg=()=>({state:n,dispatch:e})=>Qh(n,e);function Rc(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function $g(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l+=1){const a=e[l];if(/^(cmd|meta|m)$/i.test(a))i=!0;else if(/^a(lt)?$/i.test(a))o=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Ho()||Rc()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${a}`)}return o&&(t=`Alt-${t}`),r&&(t=`Ctrl-${t}`),i&&(t=`Meta-${t}`),s&&(t=`Shift-${t}`),t}var Lg=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=$g(n).split(/-(?!$)/),i=s.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),l=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",d=>d(t,l))});return a==null||a.steps.forEach(d=>{const u=d.map(o.mapping);u&&r&&o.maybeStep(u)}),!0};function no(n,e,t={}){const{from:o,to:r,empty:s}=n.selection,i=e?me(e,n.schema):null,l=[];n.doc.nodesBetween(o,r,(f,p)=>{if(f.isText)return;const h=Math.max(o,p),m=Math.min(r,p+f.nodeSize);l.push({node:f,from:h,to:m})});const a=r-o,d=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>Fo(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,p)=>f+p.to-p.from,0)>=a}var zg=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return no(t,r,e)?np(t,o):!1},Fg=()=>({state:n,dispatch:e})=>aa(n,e),Hg=n=>({state:e,dispatch:t})=>{const o=me(n,e.schema);return pp(o)(e,t)},Wg=()=>({state:n,dispatch:e})=>ia(n,e);function Wo(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function _c(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((o,r)=>(t.includes(r)||(o[r]=n[r]),o),{})}var jg=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Wo(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=me(n,o.schema)),l==="mark"&&(i=gt(n,o.schema));let a=!1;return t.selection.ranges.forEach(d=>{o.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,f)=>{s&&s===u.type&&(a=!0,r&&t.setNodeMarkup(f,void 0,_c(u.attrs,e))),i&&u.marks.length&&u.marks.forEach(p=>{i===p.type&&(a=!0,r&&t.addMark(f,f+u.nodeSize,i.create(_c(p.attrs,e))))})})}),a},Ug=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Kg=()=>({tr:n,dispatch:e})=>{if(e){const t=new Pe(n.doc);n.setSelection(t)}return!0},qg=()=>({state:n,dispatch:e})=>na(n,e),Jg=()=>({state:n,dispatch:e})=>sa(n,e),Gg=()=>({state:n,dispatch:e})=>ip(n,e),Yg=()=>({state:n,dispatch:e})=>cp(n,e),Xg=()=>({state:n,dispatch:e})=>ap(n,e);function Is(n,e,t={},o={}){return to(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var Zg=(n,{errorOnInvalidContent:e,emitUpdate:t=!0,parseOptions:o={}}={})=>({editor:r,tr:s,dispatch:i,commands:l})=>{const{doc:a}=s;if(o.preserveWhitespace!=="full"){const d=Is(n,r.schema,o,{errorOnInvalidContent:e??r.options.enableContentCheck});return i&&s.replaceWith(0,a.content.size,d).setMeta("preventUpdate",!t),!0}return i&&s.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:a.content.size},n,{parseOptions:o,errorOnInvalidContent:e??r.options.enableContentCheck})};function Pc(n,e){const t=gt(e,n.schema),{from:o,to:r,empty:s}=n.selection,i=[];s?(n.storedMarks&&i.push(...n.storedMarks),i.push(...n.selection.$head.marks())):n.doc.nodesBetween(o,r,a=>{i.push(...a.marks)});const l=i.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function Qg(n,e){const t=new jl(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function e0(n){for(let e=0;e<n.edgeCount;e+=1){const{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function t0(n,e){for(let t=n.depth;t>0;t-=1){const o=n.node(t);if(e(o))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:o}}}function Os(n){return e=>t0(e.$from,n)}function V(n,e,t){return n.config[e]===void 0&&n.parent?V(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?V(n.parent,e,t):null}):n.config[e]}function Ds(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=V(e,"addExtensions",t);return o?[e,...Ds(o())]:e}).flat(10)}function jo(n,e){const t=qt.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function Vc(n){return typeof n=="function"}function ee(n,e=void 0,...t){return Vc(n)?e?n.bind(e)(...t):n(...t):n}function n0(n={}){return Object.keys(n).length===0&&n.constructor===Object}function Nn(n){const e=n.filter(r=>r.type==="extension"),t=n.filter(r=>r.type==="node"),o=n.filter(r=>r.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:o}}function $c(n){const e=[],{nodeExtensions:t,markExtensions:o}=Nn(n),r=[...t,...o],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},i=t.filter(d=>d.name!=="text").map(d=>d.name),l=o.map(d=>d.name),a=[...i,...l];return n.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage,extensions:r},f=V(d,"addGlobalAttributes",u);if(!f)return;f().forEach(h=>{let m;Array.isArray(h.types)?m=h.types:h.types==="*"?m=a:h.types==="nodes"?m=i:h.types==="marks"?m=l:m=[],m.forEach(g=>{Object.entries(h.attributes).forEach(([y,k])=>{e.push({type:g,name:y,attribute:{...s,...k}})})})})}),r.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage},f=V(d,"addAttributes",u);if(!f)return;const p=f();Object.entries(p).forEach(([h,m])=>{const g={...s,...m};typeof(g==null?void 0:g.default)=="function"&&(g.default=g.default()),g!=null&&g.isRequired&&(g==null?void 0:g.default)===void 0&&delete g.default,e.push({type:d.name,name:h,attribute:g})})}),e}function Bn(...n){return n.filter(e=>!!e).reduce((e,t)=>{const o={...e};return Object.entries(t).forEach(([r,s])=>{if(!o[r]){o[r]=s;return}if(r==="class"){const l=s?String(s).split(" "):[],a=o[r]?o[r].split(" "):[],d=l.filter(u=>!a.includes(u));o[r]=[...a,...d].join(" ")}else if(r==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],a=o[r]?o[r].split(";").map(u=>u.trim()).filter(Boolean):[],d=new Map;a.forEach(u=>{const[f,p]=u.split(":").map(h=>h.trim());d.set(f,p)}),l.forEach(u=>{const[f,p]=u.split(":").map(h=>h.trim());d.set(f,p)}),o[r]=Array.from(d.entries()).map(([u,f])=>`${u}: ${f}`).join("; ")}else o[r]=s}),o},{})}function Uo(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,o)=>Bn(t,o),{})}function o0(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function Lc(n,e){return"style"in n?n:{...n,getAttrs:t=>{const o=n.getAttrs?n.getAttrs(t):n.attrs;if(o===!1)return!1;const r=e.reduce((s,i)=>{const l=i.attribute.parseHTML?i.attribute.parseHTML(t):o0(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function zc(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&n0(t)?!1:t!=null))}function Fc(n){var e,t;const o={};return!((e=n==null?void 0:n.attribute)!=null&&e.isRequired)&&"default"in((n==null?void 0:n.attribute)||{})&&(o.default=n.attribute.default),((t=n==null?void 0:n.attribute)==null?void 0:t.validate)!==void 0&&(o.validate=n.attribute.validate),[n.name,o]}function Hc(n,e){var t;const o=$c(n),{nodeExtensions:r,markExtensions:s}=Nn(n),i=(t=r.find(d=>V(d,"topNode")))==null?void 0:t.name,l=Object.fromEntries(r.map(d=>{const u=o.filter(k=>k.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},p=n.reduce((k,w)=>{const b=V(w,"extendNodeSchema",f);return{...k,...b?b(d):{}}},{}),h=zc({...p,content:ee(V(d,"content",f)),marks:ee(V(d,"marks",f)),group:ee(V(d,"group",f)),inline:ee(V(d,"inline",f)),atom:ee(V(d,"atom",f)),selectable:ee(V(d,"selectable",f)),draggable:ee(V(d,"draggable",f)),code:ee(V(d,"code",f)),whitespace:ee(V(d,"whitespace",f)),linebreakReplacement:ee(V(d,"linebreakReplacement",f)),defining:ee(V(d,"defining",f)),isolating:ee(V(d,"isolating",f)),attrs:Object.fromEntries(u.map(Fc))}),m=ee(V(d,"parseHTML",f));m&&(h.parseDOM=m.map(k=>Lc(k,u)));const g=V(d,"renderHTML",f);g&&(h.toDOM=k=>g({node:k,HTMLAttributes:Uo(k,u)}));const y=V(d,"renderText",f);return y&&(h.toText=y),[d.name,h]})),a=Object.fromEntries(s.map(d=>{const u=o.filter(y=>y.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},p=n.reduce((y,k)=>{const w=V(k,"extendMarkSchema",f);return{...y,...w?w(d):{}}},{}),h=zc({...p,inclusive:ee(V(d,"inclusive",f)),excludes:ee(V(d,"excludes",f)),group:ee(V(d,"group",f)),spanning:ee(V(d,"spanning",f)),code:ee(V(d,"code",f)),attrs:Object.fromEntries(u.map(Fc))}),m=ee(V(d,"parseHTML",f));m&&(h.parseDOM=m.map(y=>Lc(y,u)));const g=V(d,"renderHTML",f);return g&&(h.toDOM=y=>g({mark:y,HTMLAttributes:Uo(y,u)})),[d.name,h]}));return new kl({topNode:i,nodes:l,marks:a})}function r0(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function oo(n){return n.sort((t,o)=>{const r=V(t,"priority")||100,s=V(o,"priority")||100;return r>s?-1:r<s?1:0})}function Rs(n){const e=oo(Ds(n)),t=r0(e.map(o=>o.name));return t.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${t.map(o=>`'${o}'`).join(", ")}]. This can lead to issues.`),e}function Wc(n,e){const t=Rs(n);return Hc(t,e)}function Ko(n,e){const t=Wc(e),o=ct.fromJSON(t,n);return jo(o.content,t)}function Rt(n,e){const t=Wc(e),o=eo(n);return dt.fromSchema(t).parse(o).toJSON()}function jc(n,e,t){const{from:o,to:r}=e,{blockSeparator:s=`
|
|
11
|
+
|
|
12
|
+
`,textSerializers:i={}}=t||{};let l="";return n.nodesBetween(o,r,(a,d,u,f)=>{var p;a.isBlock&&d>o&&(l+=s);const h=i==null?void 0:i[a.type.name];if(h)return u&&(l+=h({node:a,pos:d,parent:u,index:f,range:e})),!1;a.isText&&(l+=(p=a==null?void 0:a.text)==null?void 0:p.slice(Math.max(o,d)-d,r-d))}),l}function s0(n,e){const t={from:0,to:n.content.size};return jc(n,t,e)}function Uc(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function i0(n,e){const t=me(e,n.schema),{from:o,to:r}=n.selection,s=[];n.doc.nodesBetween(o,r,l=>{s.push(l)});const i=s.reverse().find(l=>l.type.name===t.name);return i?{...i.attrs}:{}}function l0(n,e){const t=Wo(typeof e=="string"?e:e.name,n.schema);return t==="node"?i0(n,e):t==="mark"?Pc(n,e):{}}function a0(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function c0(n){const e=a0(n);return e.length===1?e:e.filter((t,o)=>!e.filter((s,i)=>i!==o).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function d0(n){const{mapping:e,steps:t}=n,o=[];return e.maps.forEach((r,s)=>{const i=[];if(r.ranges.length)r.forEach((l,a)=>{i.push({from:l,to:a})});else{const{from:l,to:a}=t[s];if(l===void 0||a===void 0)return;i.push({from:l,to:a})}i.forEach(({from:l,to:a})=>{const d=e.slice(s).map(l,-1),u=e.slice(s).map(a),f=e.invert().map(d,-1),p=e.invert().map(u);o.push({oldRange:{from:f,to:p},newRange:{from:d,to:u}})})}),c0(o)}function Kc(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=As(s,r.type);i&&o.push({mark:r,...i})}):t.nodesBetween(n,e,(r,s)=>{!r||(r==null?void 0:r.nodeSize)===void 0||o.push(...r.marks.map(i=>({from:s,to:s+r.nodeSize,mark:i})))}),o}function ro(n,e){return e.nodes[n]||e.marks[n]||null}function qo(n,e,t){return Object.fromEntries(Object.entries(t).filter(([o])=>{const r=n.find(s=>s.type===e&&s.name===o);return r?r.attribute.keepOnSplit:!1}))}var u0=(n,e=500)=>{let t="";const o=n.parentOffset;return n.parent.nodesBetween(Math.max(0,o-e),o,(r,s,i,l)=>{var a,d;const u=((d=(a=r.type.spec).toText)==null?void 0:d.call(a,{node:r,pos:s,parent:i,index:l}))||r.textContent||"%leaf%";t+=r.isAtom&&!r.isText?u:u.slice(0,Math.max(0,o-s))}),t};function _s(n,e,t={}){const{empty:o,ranges:r}=n.selection,s=e?gt(e,n.schema):null;if(o)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>Fo(f.attrs,t,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:p})=>{const h=f.pos,m=p.pos;n.doc.nodesBetween(h,m,(g,y)=>{if(s&&g.inlineContent&&!g.type.allowsMarkType(s))return!1;if(!g.isText&&!g.marks.length)return;const k=Math.max(h,y),w=Math.min(m,y+g.nodeSize),b=w-k;i+=b,l.push(...g.marks.map(S=>({mark:S,from:k,to:w})))})}),i===0)return!1;const a=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>Fo(f.mark.attrs,t,{strict:!1})).reduce((f,p)=>f+p.to-p.from,0),d=l.filter(f=>s?f.mark.type!==s&&f.mark.type.excludes(s):!0).reduce((f,p)=>f+p.to-p.from,0);return(a>0?a+d:a)>=i}function f0(n,e,t={}){if(!e)return no(n,null,t)||_s(n,null,t);const o=Wo(e,n.schema);return o==="node"?no(n,e,t):o==="mark"?_s(n,e,t):!1}function qc(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Jc(n,e){const{nodeExtensions:t}=Nn(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=ee(V(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function Jo(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var o;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((o=n.text)!=null?o:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let r=!0;return n.content.forEach(s=>{r!==!1&&(Jo(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function h0(n){return n instanceof $}var Gc=class Xu{constructor(e){this.position=e}static fromJSON(e){return new Xu(e.position)}toJSON(){return{position:this.position}}};function p0(n,e){const t=e.mapping.mapResult(n.position);return{position:new Gc(t.pos),mapResult:t}}function m0(n){return new Gc(n)}function g0(n,e,t){var o;const{selection:r}=e;let s=null;if(Ac(r)&&(s=r.$cursor),s){const l=(o=n.storedMarks)!=null?o:s.marks();return s.parent.type.allowsMarkType(t)&&(!!t.isInSet(l)||!l.some(d=>d.type.excludes(t)))}const{ranges:i}=r;return i.some(({$from:l,$to:a})=>{let d=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(u,f,p)=>{if(d)return!1;if(u.isInline){const h=!p||p.type.allowsMarkType(t),m=!!t.isInSet(u.marks)||!u.marks.some(g=>g.type.excludes(t));d=h&&m}return!d}),d})}var y0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,a=gt(n,o.schema);if(r)if(i){const d=Pc(o,a);t.addStoredMark(a.create({...d,...e}))}else l.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;o.doc.nodesBetween(u,f,(p,h)=>{const m=Math.max(h,u),g=Math.min(h+p.nodeSize,f);p.marks.find(k=>k.type===a)?p.marks.forEach(k=>{a===k.type&&t.addMark(m,g,a.create({...k.attrs,...e}))}):t.addMark(m,g,a.create(e))})});return g0(o,t,a)},k0=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),w0=(n,e={})=>({state:t,dispatch:o,chain:r})=>{const s=me(n,t.schema);let i;return t.selection.$anchor.sameParent(t.selection.$head)&&(i=t.selection.$anchor.parent.attrs),s.isTextblock?r().command(({commands:l})=>ua(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>ua(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},b0=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=on(n,0,o.content.size),s=$.create(o,r);e.setSelection(s)}return!0},x0=(n,e)=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=o;let i,l;return typeof e=="number"?(i=e,l=e):e&&"from"in e&&"to"in e?(i=e.from,l=e.to):(i=s.from,l=s.to),r&&t.doc.nodesBetween(i,l,(a,d)=>{a.isText||t.setNodeMarkup(d,void 0,{...a.attrs,dir:n})}),!0},S0=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,{from:r,to:s}=typeof n=="number"?{from:n,to:n}:n,i=U.atStart(o).from,l=U.atEnd(o).to,a=on(r,i,l),d=on(s,i,l),u=U.create(o,a,d);e.setSelection(u)}return!0},C0=n=>({state:e,dispatch:t})=>{const o=me(n,e.schema);return yp(o)(e,t)};function Yc(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const o=t.filter(r=>e==null?void 0:e.includes(r.type.name));n.tr.ensureMarks(o)}}var v0=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:o,editor:r})=>{const{selection:s,doc:i}=e,{$from:l,$to:a}=s,d=r.extensionManager.attributes,u=qo(d,l.node().type.name,l.node().attrs);if(s instanceof $&&s.node.isBlock)return!l.parentOffset||!ut(i,l.pos)?!1:(o&&(n&&Yc(t,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=a.parentOffset===a.parent.content.size,p=l.depth===0?void 0:e0(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=f&&p?[{type:p,attrs:u}]:void 0,m=ut(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!m&&ut(e.doc,e.mapping.map(l.pos),1,p?[{type:p}]:void 0)&&(m=!0,h=p?[{type:p,attrs:u}]:void 0),o){if(m&&(s instanceof U&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),p&&!f&&!l.parentOffset&&l.parent.type!==p)){const g=e.mapping.map(l.before()),y=e.doc.resolve(g);l.node(-1).canReplaceWith(y.index(),y.index()+1,p)&&e.setNodeMarkup(e.mapping.map(l.before()),p)}n&&Yc(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},E0=(n,e={})=>({tr:t,state:o,dispatch:r,editor:s})=>{var i;const l=me(n,o.schema),{$from:a,$to:d}=o.selection,u=o.selection.node;if(u&&u.isBlock||a.depth<2||!a.sameParent(d))return!1;const f=a.node(-1);if(f.type!==l)return!1;const p=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let k=N.empty;const w=a.index(-1)?1:a.index(-2)?2:3;for(let M=a.depth-w;M>=a.depth-3;M-=1)k=N.from(a.node(M).copy(k));const b=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,S={...qo(p,a.node().type.name,a.node().attrs),...e},v=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(S))||void 0;k=k.append(N.from(l.createAndFill(null,v)||void 0));const E=a.before(a.depth-(w-1));t.replace(E,a.after(-b),new R(k,4-w,0));let C=-1;t.doc.nodesBetween(E,t.doc.content.size,(M,B)=>{if(C>-1)return!1;M.isTextblock&&M.content.size===0&&(C=B+1)}),C>-1&&t.setSelection(U.near(t.doc.resolve(C))),t.scrollIntoView()}return!0}const h=d.pos===a.end()?f.contentMatchAt(0).defaultType:null,m={...qo(p,f.type.name,f.attrs),...e},g={...qo(p,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,d.pos);const y=h?[{type:l,attrs:m},{type:h,attrs:g}]:[{type:l,attrs:m}];if(!ut(t.doc,a.pos,2))return!1;if(r){const{selection:k,storedMarks:w}=o,{splittableMarks:b}=s.extensionManager,S=w||k.$to.parentOffset&&k.$from.marks();if(t.split(a.pos,2,y).scrollIntoView(),!S||!r)return!0;const v=S.filter(E=>b.includes(E.type.name));t.ensureMarks(v)}return!0},Ps=(n,e)=>{const t=Os(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&Gt(n.doc,t.pos)&&n.join(t.pos),!0},Vs=(n,e)=>{const t=Os(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(t.start).after(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&Gt(n.doc,o)&&n.join(o),!0},M0=(n,e,t,o={})=>({editor:r,tr:s,state:i,dispatch:l,chain:a,commands:d,can:u})=>{const{extensions:f,splittableMarks:p}=r.extensionManager,h=me(n,i.schema),m=me(e,i.schema),{selection:g,storedMarks:y}=i,{$from:k,$to:w}=g,b=k.blockRange(w),S=y||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;const v=Os(E=>Jc(E.type.name,f))(g);if(b.depth>=1&&v&&b.depth-v.depth<=1){if(v.node.type===h)return d.liftListItem(m);if(Jc(v.node.type.name,f)&&h.validContent(v.node.content)&&l)return a().command(()=>(s.setNodeMarkup(v.pos,h),!0)).command(()=>Ps(s,h)).command(()=>Vs(s,h)).run()}return!t||!S||!l?a().command(()=>u().wrapInList(h,o)?!0:d.clearNodes()).wrapInList(h,o).command(()=>Ps(s,h)).command(()=>Vs(s,h)).run():a().command(()=>{const E=u().wrapInList(h,o),C=S.filter(M=>p.includes(M.type.name));return s.ensureMarks(C),E?!0:d.clearNodes()}).wrapInList(h,o).command(()=>Ps(s,h)).command(()=>Vs(s,h)).run()},T0=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=gt(n,o.schema);return _s(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},N0=(n,e,t={})=>({state:o,commands:r})=>{const s=me(n,o.schema),i=me(e,o.schema),l=no(o,s,t);let a;return o.selection.$anchor.sameParent(o.selection.$head)&&(a=o.selection.$anchor.parent.attrs),l?r.setNode(i,a):r.setNode(s,{...a,...t})},B0=(n,e={})=>({state:t,commands:o})=>{const r=me(n,t.schema);return no(t,r,e)?o.lift(r):o.wrapIn(r,e)},A0=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let o=0;o<t.length;o+=1){const r=t[o];let s;if(r.spec.isInputRules&&(s=r.getState(n))){if(e){const i=n.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a-=1)i.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,n.schema.text(s.text,a))}else i.delete(s.from,s.to)}return!0}}return!1},I0=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:o,ranges:r}=t;return o||e&&r.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},O0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,a=gt(n,o.schema),{$from:d,empty:u,ranges:f}=l;if(!r)return!0;if(u&&i){let{from:p,to:h}=l;const m=(s=d.marks().find(y=>y.type===a))==null?void 0:s.attrs,g=As(d,a,m);g&&(p=g.from,h=g.to),t.removeMark(p,h,a)}else f.forEach(p=>{t.removeMark(p.$from.pos,p.$to.pos,a)});return t.removeStoredMark(a),!0},D0=n=>({tr:e,state:t,dispatch:o})=>{const{selection:r}=t;let s,i;return typeof n=="number"?(s=n,i=n):n&&"from"in n&&"to"in n?(s=n.from,i=n.to):(s=r.from,i=r.to),o&&e.doc.nodesBetween(s,i,(l,a)=>{if(l.isText)return;const d={...l.attrs};delete d.dir,e.setNodeMarkup(a,void 0,d)}),!0},R0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Wo(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=me(n,o.schema)),l==="mark"&&(i=gt(n,o.schema));let a=!1;return t.selection.ranges.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;let p,h,m,g;t.selection.empty?o.doc.nodesBetween(u,f,(y,k)=>{s&&s===y.type&&(a=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),p=k,h=y)}):o.doc.nodesBetween(u,f,(y,k)=>{k<u&&s&&s===y.type&&(a=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),p=k,h=y),k>=u&&k<=f&&(s&&s===y.type&&(a=!0,r&&t.setNodeMarkup(k,void 0,{...y.attrs,...e})),i&&y.marks.length&&y.marks.forEach(w=>{if(i===w.type&&(a=!0,r)){const b=Math.max(k,u),S=Math.min(k+y.nodeSize,f);t.addMark(b,S,i.create({...w.attrs,...e}))}}))}),h&&(p!==void 0&&r&&t.setNodeMarkup(p,void 0,{...h.attrs,...e}),i&&h.marks.length&&h.marks.forEach(y=>{i===y.type&&r&&t.addMark(m,g,i.create({...y.attrs,...e}))}))}),a},_0=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return dp(r,e)(t,o)},P0=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return up(r,e)(t,o)},V0=class{constructor(){this.callbacks={}}on(n,e){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(e),this}emit(n,...e){const t=this.callbacks[n];return t&&t.forEach(o=>o.apply(this,e)),this}off(n,e){const t=this.callbacks[n];return t&&(e?this.callbacks[n]=t.filter(o=>o!==e):delete this.callbacks[n]),this}once(n,e){const t=(...o)=>{this.off(n,t),e.apply(this,o)};return this.on(n,t)}removeAllListeners(){this.callbacks={}}},$0=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},L0=(n,e)=>{if(Bs(e))return e.exec(n);const t=e(n);if(!t)return null;const o=[t.text];return o.index=t.index,o.input=n,o.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),o.push(t.replaceWith)),o};function Go(n){var e;const{editor:t,from:o,to:r,text:s,rules:i,plugin:l}=n,{view:a}=t;if(a.composing)return!1;const d=a.state.doc.resolve(o);if(d.parent.type.spec.code||(e=d.nodeBefore||d.nodeAfter)!=null&&e.marks.find(p=>p.type.spec.code))return!1;let u=!1;const f=u0(d)+s;return i.forEach(p=>{if(u)return;const h=L0(f,p.find);if(!h)return;const m=a.state.tr,g=Lo({state:a.state,transaction:m}),y={from:o-(h[0].length-s.length),to:r},{commands:k,chain:w,can:b}=new zo({editor:t,state:g});p.handler({state:g,range:y,match:h,commands:k,chain:w,can:b})===null||!m.steps.length||(p.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),a.dispatch(m),u=!0)}),u}function z0(n){const{editor:e,rules:t}=n,o=new ue({state:{init(){return null},apply(r,s,i){const l=r.getMeta(o);if(l)return l;const a=r.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:u}=a;typeof u=="string"?u=u:u=jo(N.from(u),i.schema);const{from:f}=a,p=f+u.length;Go({editor:e,from:f,to:p,text:u,rules:t,plugin:o})}),r.selectionSet||r.docChanged?null:s}},props:{handleTextInput(r,s,i,l){return Go({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&Go({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:o})}),!1)},handleKeyDown(r,s){if(s.key!=="Enter")return!1;const{$cursor:i}=r.state.selection;return i?Go({editor:e,from:i.pos,to:i.pos,text:`
|
|
13
|
+
`,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function F0(n){return Object.prototype.toString.call(n).slice(8,-1)}function Yo(n){return F0(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Xc(n,e){const t={...n};return Yo(n)&&Yo(e)&&Object.keys(e).forEach(o=>{Yo(e[o])&&Yo(n[o])?t[o]=Xc(n[o],e[o]):t[o]=e[o]}),t}var $s=class{constructor(n={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...n},this.name=this.config.name}get options(){return{...ee(V(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...ee(V(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Xc(this.options,n)});return e.name=this.name,e.parent=this.parent,e}extend(n={}){const e=new this.constructor({...this.config,...n});return e.parent=this,this.child=e,e.name="name"in n?n.name:e.parent.name,e}},so=class Zu extends $s{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new Zu(t)}static handleExit({editor:e,mark:t}){const{tr:o}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){const i=r.marks();if(!!!i.find(d=>(d==null?void 0:d.type.name)===t.name))return!1;const a=i.find(d=>(d==null?void 0:d.type.name)===t.name);return a&&o.removeStoredMark(a),o.insertText(" ",r.pos),e.view.dispatch(o),!0}return!1}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function H0(n){return typeof n=="number"}var W0=class{constructor(n){this.find=n.find,this.handler=n.handler}},j0=(n,e,t)=>{if(Bs(e))return[...n.matchAll(e)];const o=e(n,t);return o?o.map(r=>{const s=[r.text];return s.index=r.index,s.input=n,s.data=r.data,r.replaceWith&&(r.text.includes(r.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(r.replaceWith)),s}):[]};function U0(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:a,chain:d,can:u}=new zo({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(h,m)=>{var g,y,k,w,b;if((y=(g=h.type)==null?void 0:g.spec)!=null&&y.code||!(h.isText||h.isTextblock||h.isInline))return;const S=(b=(w=(k=h.content)==null?void 0:k.size)!=null?w:h.nodeSize)!=null?b:0,v=Math.max(o,m),E=Math.min(r,m+S);if(v>=E)return;const C=h.isText?h.text||"":h.textBetween(v-m,E-m,void 0,"");j0(C,s.find,i).forEach(B=>{if(B.index===void 0)return;const I=v+B.index+1,_=I+B[0].length,j={from:t.tr.mapping.map(I),to:t.tr.mapping.map(_)},H=s.handler({state:t,range:j,match:B,commands:a,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(H)})}),f.every(h=>h!==null)}var Xo=null,K0=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function q0(n){const{editor:e,rules:t}=n;let o=null,r=!1,s=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const a=({state:u,from:f,to:p,rule:h,pasteEvt:m})=>{const g=u.tr,y=Lo({state:u,transaction:g});if(!(!U0({editor:e,state:y,from:Math.max(f-1,0),to:p.b-1,rule:h,pasteEvent:m,dropEvent:l})||!g.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,g}};return t.map(u=>new ue({view(f){const p=m=>{var g;o=(g=f.dom.parentElement)!=null&&g.contains(m.target)?f.dom.parentElement:null,o&&(Xo=e)},h=()=>{Xo&&(Xo=null)};return window.addEventListener("dragstart",p),window.addEventListener("dragend",h),{destroy(){window.removeEventListener("dragstart",p),window.removeEventListener("dragend",h)}}},props:{handleDOMEvents:{drop:(f,p)=>{if(s=o===f.dom.parentElement,l=p,!s){const h=Xo;h!=null&&h.isEditable&&setTimeout(()=>{const m=h.state.selection;m&&h.commands.deleteRange({from:m.from,to:m.to})},10)}return!1},paste:(f,p)=>{var h;const m=(h=p.clipboardData)==null?void 0:h.getData("text/html");return i=p,r=!!(m!=null&&m.includes("data-pm-slice")),!1}}},appendTransaction:(f,p,h)=>{const m=f[0],g=m.getMeta("uiEvent")==="paste"&&!r,y=m.getMeta("uiEvent")==="drop"&&!s,k=m.getMeta("applyPasteRules"),w=!!k;if(!g&&!y&&!w)return;if(w){let{text:v}=k;typeof v=="string"?v=v:v=jo(N.from(v),h.schema);const{from:E}=k,C=E+v.length,M=K0(v);return a({rule:u,state:h,from:E,to:{b:C},pasteEvt:M})}const b=p.doc.content.findDiffStart(h.doc.content),S=p.doc.content.findDiffEnd(h.doc.content);if(!(!H0(b)||!S||b===S.b))return a({rule:u,state:h,from:b,to:S,pasteEvt:i})}}))}var Zo=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Rs(n),this.schema=Hc(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((n,e)=>{const t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:ro(e.name,this.schema)},o=V(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return oo([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:ro(o.name,this.schema)},s=[],i=V(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&V(o,"exitable",r)&&(l.ArrowRight=()=>so.handleExit({editor:n,mark:o})),i){const p=Object.fromEntries(Object.entries(i()).map(([h,m])=>[h,()=>m({editor:n})]));l={...l,...p}}const a=lg(l);s.push(a);const d=V(o,"addInputRules",r);if(qc(o,n.options.enableInputRules)&&d){const p=d();if(p&&p.length){const h=z0({editor:n,rules:p}),m=Array.isArray(h)?h:[h];s.push(...m)}}const u=V(o,"addPasteRules",r);if(qc(o,n.options.enablePasteRules)&&u){const p=u();if(p&&p.length){const h=q0({editor:n,rules:p});s.push(...h)}}const f=V(o,"addProseMirrorPlugins",r);if(f){const p=f();s.push(...p)}return s})}get attributes(){return $c(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=Nn(this.extensions);return Object.fromEntries(e.filter(t=>!!V(t,"addNodeView")).map(t=>{const o=this.attributes.filter(a=>a.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:me(t.name,this.schema)},s=V(t,"addNodeView",r);if(!s)return[];const i=s();if(!i)return[];const l=(a,d,u,f,p)=>{const h=Uo(a,o);return i({node:a,view:d,getPos:u,decorations:f,innerDecorations:p,editor:n,extension:t,HTMLAttributes:h})};return[t.name,l]}))}dispatchTransaction(n){const{editor:e}=this;return oo([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:ro(r.name,this.schema)},i=V(r,"dispatchTransaction",s);return i?l=>{i.call(s,{transaction:l,next:o})}:o},n)}transformPastedHTML(n){const{editor:e}=this;return oo([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:ro(r.name,this.schema)},i=V(r,"transformPastedHTML",s);return i?(l,a)=>{const d=o(l,a);return i.call(s,d)}:o},n||(o=>o))}get markViews(){const{editor:n}=this,{markExtensions:e}=Nn(this.extensions);return Object.fromEntries(e.filter(t=>!!V(t,"addMarkView")).map(t=>{const o=this.attributes.filter(l=>l.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:gt(t.name,this.schema)},s=V(t,"addMarkView",r);if(!s)return[];const i=(l,a,d)=>{const u=Uo(l,o);return s()({mark:l,view:a,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{ly(l,n,f)}})};return[t.name,i]}))}setupExtensions(){const n=this.extensions;this.editor.extensionStorage=Object.fromEntries(n.map(e=>[e.name,e.storage])),n.forEach(e=>{var t;const o={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:ro(e.name,this.schema)};e.type==="mark"&&((t=ee(V(e,"keepOnSplit",o)))==null||t)&&this.splittableMarks.push(e.name);const r=V(e,"onBeforeCreate",o),s=V(e,"onCreate",o),i=V(e,"onUpdate",o),l=V(e,"onSelectionUpdate",o),a=V(e,"onTransaction",o),d=V(e,"onFocus",o),u=V(e,"onBlur",o),f=V(e,"onDestroy",o);r&&this.editor.on("beforeCreate",r),s&&this.editor.on("create",s),i&&this.editor.on("update",i),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),d&&this.editor.on("focus",d),u&&this.editor.on("blur",u),f&&this.editor.on("destroy",f)})}};Zo.resolve=Rs,Zo.sort=oo,Zo.flatten=Ds;var J0={};Ns(J0,{ClipboardTextSerializer:()=>Zc,Commands:()=>Qc,Delete:()=>ed,Drop:()=>td,Editable:()=>nd,FocusEvents:()=>rd,Keymap:()=>sd,Paste:()=>id,Tabindex:()=>ld,TextDirection:()=>ad,focusEventsPluginKey:()=>od});var ne=class Qu extends $s{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new Qu(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},Zc=ne.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new ue({key:new Te("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:o,selection:r}=e,{ranges:s}=r,i=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),a=Uc(t);return jc(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),Qc=ne.create({name:"commands",addCommands(){return{...Tc}}}),ed=ne.create({name:"delete",onUpdate({transaction:n,appendedTransactions:e}){var t,o,r;const s=()=>{var i,l,a,d;if((d=(a=(l=(i=this.editor.options.coreExtensionOptions)==null?void 0:i.delete)==null?void 0:l.filterTransaction)==null?void 0:a.call(l,n))!=null?d:n.getMeta("y-sync$"))return;const u=Qg(n.before,[n,...e]);d0(u).forEach(h=>{u.mapping.mapResult(h.oldRange.from).deletedAfter&&u.mapping.mapResult(h.oldRange.to).deletedBefore&&u.before.nodesBetween(h.oldRange.from,h.oldRange.to,(m,g)=>{const y=g+m.nodeSize-2,k=h.oldRange.from<=g&&y<=h.oldRange.to;this.editor.emit("delete",{type:"node",node:m,from:g,to:y,newFrom:u.mapping.map(g),newTo:u.mapping.map(y),deletedRange:h.oldRange,newRange:h.newRange,partial:!k,editor:this.editor,transaction:n,combinedTransform:u})})});const p=u.mapping;u.steps.forEach((h,m)=>{var g,y;if(h instanceof Ke){const k=p.slice(m).map(h.from,-1),w=p.slice(m).map(h.to),b=p.invert().map(k,-1),S=p.invert().map(w),v=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(C=>C.eq(h.mark)),E=(y=u.doc.nodeAt(w))==null?void 0:y.marks.some(C=>C.eq(h.mark));this.editor.emit("delete",{type:"mark",mark:h.mark,from:h.from,to:h.to,deletedRange:{from:b,to:S},newRange:{from:k,to:w},partial:!!(E||v),editor:this.editor,transaction:n,combinedTransform:u})}})};(r=(o=(t=this.editor.options.coreExtensionOptions)==null?void 0:t.delete)==null?void 0:o.async)==null||r?setTimeout(s,0):s()}}),td=ne.create({name:"drop",addProseMirrorPlugins(){return[new ue({key:new Te("tiptapDrop"),props:{handleDrop:(n,e,t,o)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:o})}}})]}}),nd=ne.create({name:"editable",addProseMirrorPlugins(){return[new ue({key:new Te("editable"),props:{editable:()=>this.editor.options.editable}})]}}),od=new Te("focusEvents"),rd=ne.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ue({key:od,props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const o=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1},blur:(e,t)=>{n.isFocused=!1;const o=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1}}}})]}}),sd=ne.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:a,doc:d}=l,{empty:u,$anchor:f}=a,{pos:p,parent:h}=f,m=f.parent.isTextblock&&p>0?l.doc.resolve(p-1):f,g=m.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=g&&m.parent.childCount===1?y===f.pos:J.atStart(d).from===p;return!u||!h.type.isTextblock||h.textContent.length||!k||k&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),o={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},r={...o},s={...o,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Ho()||Rc()?s:r},addProseMirrorPlugins(){return[new ue({key:new Te("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(g=>g.getMeta("composition")))return;const o=n.some(g=>g.docChanged)&&!e.doc.eq(t.doc),r=n.some(g=>g.getMeta("preventClearDocument"));if(!o||r)return;const{empty:s,from:i,to:l}=e.selection,a=J.atStart(e.doc).from,d=J.atEnd(e.doc).to;if(s||!(i===a&&l===d)||!Jo(t.doc))return;const p=t.tr,h=Lo({state:t,transaction:p}),{commands:m}=new zo({editor:this.editor,state:h});if(m.clearNodes(),!!p.steps.length)return p}})]}}),id=ne.create({name:"paste",addProseMirrorPlugins(){return[new ue({key:new Te("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),ld=ne.create({name:"tabindex",addProseMirrorPlugins(){return[new ue({key:new Te("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),ad=ne.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=Nn(this.extensions);return[{types:n.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const t=e.getAttribute("dir");return t&&(t==="ltr"||t==="rtl"||t==="auto")?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new ue({key:new Te("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),G0=class ho{constructor(e,t,o=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=o,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!=null?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,o=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,o=this.to-1}this.editor.commands.insertContentAt({from:t,to:o},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new ho(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new ho(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new ho(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,o)=>{const r=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,i=t.isInline,l=this.pos+o+(s?0:1);if(l<0||l>this.resolvedPos.doc.nodeSize-2)return;const a=this.resolvedPos.doc.resolve(l);if(!r&&!i&&a.depth<=this.depth)return;const d=new ho(a,this.editor,r,r||i?t:null);r&&(d.actualDepth=this.depth+1),e.push(d)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let o=null,r=this.parent;for(;r&&!o;){if(r.node.type.name===e)if(Object.keys(t).length>0){const s=r.node.attrs,i=Object.keys(t);for(let l=0;l<i.length;l+=1){const a=i[l];if(s[a]!==t[a])break}}else o=r;r=r.parent}return o}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},o=!1){let r=[];if(!this.children||this.children.length===0)return r;const s=Object.keys(t);return this.children.forEach(i=>{o&&r.length>0||(i.node.type.name===e&&s.every(a=>t[a]===i.node.attrs[a])&&r.push(i),!(o&&r.length>0)&&(r=r.concat(i.querySelectorAll(e,t,o))))}),r}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Y0=`.ProseMirror {
|
|
82
14
|
position: relative;
|
|
83
15
|
}
|
|
84
16
|
|
|
@@ -148,24 +80,24 @@ img.ProseMirror-separator {
|
|
|
148
80
|
|
|
149
81
|
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
150
82
|
display: block;
|
|
151
|
-
}`;function
|
|
83
|
+
}`;function X0(n,e,t){const o=document.querySelector("style[data-tiptap-style]");if(o!==null)return o;const r=document.createElement("style");return e&&r.setAttribute("nonce",e),r.setAttribute("data-tiptap-style",""),r.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(r),r}var Z0=class extends V0{constructor(e={}){super(),this.css=null,this.className="tiptap",this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<"u"?document.createElement("div"):null,content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:r})=>{throw r},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:p0,createMappablePosition:m0},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("mount",this.options.onMount),this.on("unmount",this.options.onUnmount),this.on("contentError",this.options.onContentError),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:r,slice:s,moved:i})=>this.options.onDrop(r,s,i)),this.on("paste",({event:r,slice:s})=>this.options.onPaste(r,s)),this.on("delete",this.options.onDelete);const t=this.createDoc(),o=Ic(t,this.options.autofocus);this.editorState=bn.create({doc:t,schema:this.schema,selection:o||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>"u")throw new Error("[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.");this.createView(e),this.emit("mount",{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){const e=this.editorView.dom;e!=null&&e.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove=="function"?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn("Failed to remove CSS element:",e)}this.css=null,this.emit("unmount",{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<"u"&&(this.css=X0(Y0,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t==="state")return this.editorState;if(t in e)return Reflect.get(e,t);throw new Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){const o=Vc(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:o});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let o=t;if([].concat(e).forEach(s=>{const i=typeof s=="string"?`${s}$`:s.key;o=o.filter(l=>!l.key.startsWith(i))}),t.length===o.length)return;const r=this.state.reconfigure({plugins:o});return this.view.updateState(r),r}createExtensionManager(){var e,t;const r=[...this.options.enableCoreExtensions?[nd,Zc.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)==null?void 0:e.clipboardTextSerializer)==null?void 0:t.blockSeparator}),Qc,rd,sd,ld,td,id,ed,ad.configure({direction:this.options.textDirection})].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s==null?void 0:s.type));this.extensionManager=new Zo(r,this)}createCommandManager(){this.commandManager=new zo({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=Is(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(t.message))throw t;this.emit("contentError",{editor:this,error:t,disableCollaboration:()=>{"collaboration"in this.storage&&typeof this.storage.collaboration=="object"&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(o=>o.name!=="collaboration"),this.createExtensionManager()}}),e=Is(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){const{editorProps:t,enableExtensionDispatchTransaction:o}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),s=o?this.extensionManager.dispatchTransaction(r):r,i=t.transformPastedHTML,l=this.extensionManager.transformPastedHTML(i);this.editorView=new bc(e,{...t,attributes:{role:"textbox",...t==null?void 0:t.attributes},dispatchTransaction:s,transformPastedHTML:l,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});const a=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(a),this.prependClass(),this.injectCSS();const d=this.view.dom;d.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(u=>{var f;return(f=this.capturedTransaction)==null?void 0:f.step(u)});return}const{state:t,transactions:o}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),s=o.includes(e),i=this.state;if(this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),!s)return;this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e,appendedTransactions:o.slice(1)}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const l=o.findLast(u=>u.getMeta("focus")||u.getMeta("blur")),a=l==null?void 0:l.getMeta("focus"),d=l==null?void 0:l.getMeta("blur");a&&this.emit("focus",{editor:this,event:a.event,transaction:l}),d&&this.emit("blur",{editor:this,event:d.event,transaction:l}),!(e.getMeta("preventUpdate")||!o.some(u=>u.docChanged)||i.doc.eq(t.doc))&&this.emit("update",{editor:this,transaction:e,appendedTransactions:o.slice(1)})}getAttributes(e){return l0(this.state,e)}isActive(e,t){const o=typeof e=="string"?e:null,r=typeof e=="string"?t:e;return f0(this.state,o,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return jo(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
|
|
152
84
|
|
|
153
|
-
`,textSerializers:
|
|
85
|
+
`,textSerializers:o={}}=e||{};return s0(this.state.doc,{blockSeparator:t,textSerializers:{...Uc(this.schema),...o}})}get isEmpty(){return Jo(this.state.doc)}destroy(){this.emit("destroy"),this.unmount(),this.removeAllListeners()}get isDestroyed(){var e,t;return(t=(e=this.editorView)==null?void 0:e.isDestroyed)!=null?t:!0}$node(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelector(e,t))||null}$nodes(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new G0(t,this)}get $doc(){return this.$pos(0)}};function Qo(n){return new $0({find:n.find,handler:({state:e,range:t,match:o})=>{const r=ee(n.getAttributes,void 0,o);if(r===!1||r===null)return null;const{tr:s}=e,i=o[o.length-1],l=o[0];if(i){const a=l.search(/\S/),d=t.from+l.indexOf(i),u=d+i.length;if(Kc(t.from,t.to,e.doc).filter(h=>h.mark.type.excluded.find(g=>g===n.type&&g!==h.mark.type)).filter(h=>h.to>d).length)return null;u<t.to&&s.delete(u,t.to),d>t.from&&s.delete(t.from+a,d);const p=t.from+a+i.length;s.addMark(t.from+a,p,n.type.create(r||{})),s.removeStoredMark(n.type)}},undoable:n.undoable})}var Q0={};Ns(Q0,{createAtomBlockMarkdownSpec:()=>ey,createBlockMarkdownSpec:()=>ty,createInlineMarkdownSpec:()=>ry,parseAttributes:()=>Ls,parseIndentedBlocks:()=>sy,renderNestedMarkdownContent:()=>iy,serializeAttributes:()=>zs});function Ls(n){if(!(n!=null&&n.trim()))return{};const e={},t=[],o=n.replace(/["']([^"']*)["']/g,d=>(t.push(d),`__QUOTED_${t.length-1}__`)),r=o.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);if(r){const d=r.map(u=>u.trim().slice(1));e.class=d.join(" ")}const s=o.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);s&&(e.id=s[1]);const i=/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;Array.from(o.matchAll(i)).forEach(([,d,u])=>{var f;const p=parseInt(((f=u.match(/__QUOTED_(\d+)__/))==null?void 0:f[1])||"0",10),h=t[p];h&&(e[d]=h.slice(1,-1))});const a=o.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,"").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,"").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,"").trim();return a&&a.split(/\s+/).filter(Boolean).forEach(u=>{u.match(/^[a-zA-Z][\w-]*$/)&&(e[u]=!0)}),e}function zs(n){if(!n||Object.keys(n).length===0)return"";const e=[];return n.class&&String(n.class).split(/\s+/).filter(Boolean).forEach(o=>e.push(`.${o}`)),n.id&&e.push(`#${n.id}`),Object.entries(n).forEach(([t,o])=>{t==="class"||t==="id"||(o===!0?e.push(t):o!==!1&&o!=null&&e.push(`${t}="${String(o)}"`))}),e.join(" ")}function ey(n){const{nodeName:e,name:t,parseAttributes:o=Ls,serializeAttributes:r=zs,defaultAttributes:s={},requiredAttributes:i=[],allowedAttributes:l}=n,a=t||e,d=u=>{if(!l)return u;const f={};return l.forEach(p=>{p in u&&(f[p]=u[p])}),f};return{parseMarkdown:(u,f)=>{const p={...s,...u.attributes};return f.createNode(e,p,[])},markdownTokenizer:{name:e,level:"block",start(u){var f;const p=new RegExp(`^:::${a}(?:\\s|$)`,"m"),h=(f=u.match(p))==null?void 0:f.index;return h!==void 0?h:-1},tokenize(u,f,p){const h=new RegExp(`^:::${a}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),m=u.match(h);if(!m)return;const g=m[1]||"",y=o(g);if(!i.find(w=>!(w in y)))return{type:e,raw:m[0],attributes:y}}},renderMarkdown:u=>{const f=d(u.attrs||{}),p=r(f),h=p?` {${p}}`:"";return`:::${a}${h} :::`}}}function ty(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=Ls,serializeAttributes:s=zs,defaultAttributes:i={},content:l="block",allowedAttributes:a}=n,d=t||e,u=f=>{if(!a)return f;const p={};return a.forEach(h=>{h in f&&(p[h]=f[h])}),p};return{parseMarkdown:(f,p)=>{let h;if(o){const g=o(f);h=typeof g=="string"?[{type:"text",text:g}]:g}else l==="block"?h=p.parseChildren(f.tokens||[]):h=p.parseInline(f.tokens||[]);const m={...i,...f.attributes};return p.createNode(e,m,h)},markdownTokenizer:{name:e,level:"block",start(f){var p;const h=new RegExp(`^:::${d}`,"m"),m=(p=f.match(h))==null?void 0:p.index;return m!==void 0?m:-1},tokenize(f,p,h){var m;const g=new RegExp(`^:::${d}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),y=f.match(g);if(!y)return;const[k,w=""]=y,b=r(w);let S=1;const v=k.length;let E="";const C=/^:::([\w-]*)(\s.*)?/gm,M=f.slice(v);for(C.lastIndex=0;;){const B=C.exec(M);if(B===null)break;const I=B.index,_=B[1];if(!((m=B[2])!=null&&m.endsWith(":::"))){if(_)S+=1;else if(S-=1,S===0){const j=M.slice(0,I);E=j.trim();const H=f.slice(0,v+I+B[0].length);let K=[];if(E)if(l==="block")for(K=h.blockTokens(j),K.forEach(G=>{G.text&&(!G.tokens||G.tokens.length===0)&&(G.tokens=h.inlineTokens(G.text))});K.length>0;){const G=K[K.length-1];if(G.type==="paragraph"&&(!G.text||G.text.trim()===""))K.pop();else break}else K=h.inlineTokens(E);return{type:e,raw:H,attributes:b,content:E,tokens:K}}}}}},renderMarkdown:(f,p)=>{const h=u(f.attrs||{}),m=s(h),g=m?` {${m}}`:"",y=p.renderChildren(f.content||[],`
|
|
154
86
|
|
|
155
|
-
`);return`:::${
|
|
87
|
+
`);return`:::${d}${g}
|
|
156
88
|
|
|
157
|
-
${
|
|
89
|
+
${y}
|
|
158
90
|
|
|
159
|
-
:::`}}}function
|
|
160
|
-
`),
|
|
161
|
-
`;continue}else return}const
|
|
162
|
-
`;const
|
|
163
|
-
`,u+=1;continue}else break}if((((i=(s=
|
|
164
|
-
`,u+=1;else break}let
|
|
165
|
-
`);
|
|
91
|
+
:::`}}}function ny(n){if(!n.trim())return{};const e={},t=/(\w+)=(?:"([^"]*)"|'([^']*)')/g;let o=t.exec(n);for(;o!==null;){const[,r,s,i]=o;e[r]=s||i,o=t.exec(n)}return e}function oy(n){return Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(" ")}function ry(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=ny,serializeAttributes:s=oy,defaultAttributes:i={},selfClosing:l=!1,allowedAttributes:a}=n,d=t||e,u=p=>{if(!a)return p;const h={};return a.forEach(m=>{const g=typeof m=="string"?m:m.name,y=typeof m=="string"?void 0:m.skipIfDefault;if(g in p){const k=p[g];if(y!==void 0&&k===y)return;h[g]=k}}),h},f=d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return{parseMarkdown:(p,h)=>{const m={...i,...p.attributes};if(l)return h.createNode(e,m);const g=o?o(p):p.content||"";return g?h.createNode(e,m,[h.createTextNode(g)]):h.createNode(e,m,[])},markdownTokenizer:{name:e,level:"inline",start(p){const h=l?new RegExp(`\\[${f}\\s*[^\\]]*\\]`):new RegExp(`\\[${f}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${f}\\]`),m=p.match(h),g=m==null?void 0:m.index;return g!==void 0?g:-1},tokenize(p,h,m){const g=l?new RegExp(`^\\[${f}\\s*([^\\]]*)\\]`):new RegExp(`^\\[${f}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${f}\\]`),y=p.match(g);if(!y)return;let k="",w="";if(l){const[,S]=y;w=S}else{const[,S,v]=y;w=S,k=v||""}const b=r(w.trim());return{type:e,raw:y[0],content:k.trim(),attributes:b}}},renderMarkdown:p=>{let h="";o?h=o(p):p.content&&p.content.length>0&&(h=p.content.filter(k=>k.type==="text").map(k=>k.text).join(""));const m=u(p.attrs||{}),g=s(m),y=g?` ${g}`:"";return l?`[${d}${y}]`:`[${d}${y}]${h}[/${d}]`}}}function sy(n,e,t){var o,r,s,i;const l=n.split(`
|
|
92
|
+
`),a=[];let d="",u=0;const f=e.baseIndentSize||2;for(;u<l.length;){const p=l[u],h=p.match(e.itemPattern);if(!h){if(a.length>0)break;if(p.trim()===""){u+=1,d=`${d}${p}
|
|
93
|
+
`;continue}else return}const m=e.extractItemData(h),{indentLevel:g,mainContent:y}=m;d=`${d}${p}
|
|
94
|
+
`;const k=[y];for(u+=1;u<l.length;){const v=l[u];if(v.trim()===""){const C=l.slice(u+1).findIndex(I=>I.trim()!=="");if(C===-1)break;if((((r=(o=l[u+1+C].match(/^(\s*)/))==null?void 0:o[1])==null?void 0:r.length)||0)>g){k.push(v),d=`${d}${v}
|
|
95
|
+
`,u+=1;continue}else break}if((((i=(s=v.match(/^(\s*)/))==null?void 0:s[1])==null?void 0:i.length)||0)>g)k.push(v),d=`${d}${v}
|
|
96
|
+
`,u+=1;else break}let w;const b=k.slice(1);if(b.length>0){const v=b.map(E=>E.slice(g+f)).join(`
|
|
97
|
+
`);v.trim()&&(e.customNestedParser?w=e.customNestedParser(v):w=t.blockTokens(v))}const S=e.createToken(m,w);a.push(S)}if(a.length!==0)return{items:a,raw:d}}function iy(n,e,t,o){if(!n||!Array.isArray(n.content))return"";const r=typeof t=="function"?t(o):t,[s,...i]=n.content,l=e.renderChildren([s]),a=[`${r}${l}`];return i&&i.length>0&&i.forEach(d=>{const u=e.renderChildren([d]);if(u){const f=u.split(`
|
|
166
98
|
`).map(p=>p?e.indent(p):"").join(`
|
|
167
|
-
`);
|
|
168
|
-
`)}function
|
|
99
|
+
`);a.push(f)}}),a.join(`
|
|
100
|
+
`)}function ly(n,e,t={}){const{state:o}=e,{doc:r,tr:s}=o,i=n;r.descendants((l,a)=>{const d=s.mapping.map(a),u=s.mapping.map(a)+l.nodeSize;let f=null;if(l.marks.forEach(h=>{if(h!==i)return!1;f=h}),!f)return;let p=!1;if(Object.keys(t).forEach(h=>{t[h]!==f.attrs[h]&&(p=!0)}),p){const h=n.type.create({...n.attrs,...t});s.removeMark(d,u,n.type),s.addMark(d,u,h)}}),s.docChanged&&e.view.dispatch(s)}var Fs=class ef extends $s{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new ef(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function er(n){return new W0({find:n.find,handler:({state:e,range:t,match:o,pasteEvent:r})=>{const s=ee(n.getAttributes,void 0,o,r);if(s===!1||s===null)return null;const{tr:i}=e,l=o[o.length-1],a=o[0];let d=t.to;if(l){const u=a.search(/\S/),f=t.from+a.indexOf(l),p=f+l.length;if(Kc(t.from,t.to,e.doc).filter(m=>m.mark.type.excluded.find(y=>y===n.type&&y!==m.mark.type)).filter(m=>m.to>f).length)return null;p<t.to&&i.delete(p,t.to),f>t.from&&i.delete(t.from+u,f),d=t.from+u+l.length,i.addMark(t.from+u,d,n.type.create(s||{})),i.removeStoredMark(n.type)}}})}function cd(n){return c.customRef((e,t)=>({get(){return e(),n},set(o){n=o,requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})}}))}var ay=class extends Z0{constructor(n={}){return super(n),this.contentComponent=null,this.appContext=null,this.reactiveState=cd(this.view.state),this.reactiveExtensionStorage=cd(this.extensionStorage),this.on("beforeTransaction",({nextState:e})=>{this.reactiveState.value=e,this.reactiveExtensionStorage.value=this.extensionStorage}),c.markRaw(this)}get state(){return this.reactiveState?this.reactiveState.value:this.view.state}get storage(){return this.reactiveExtensionStorage?this.reactiveExtensionStorage.value:super.storage}registerPlugin(n,e){const t=super.registerPlugin(n,e);return this.reactiveState&&(this.reactiveState.value=t),t}unregisterPlugin(n){const e=super.unregisterPlugin(n);return this.reactiveState&&e&&(this.reactiveState.value=e),e}},cy=c.defineComponent({name:"EditorContent",props:{editor:{default:null,type:Object}},setup(n){const e=c.ref(),t=c.getCurrentInstance();return c.watchEffect(()=>{const o=n.editor;o&&o.options.element&&e.value&&c.nextTick(()=>{var r;if(!e.value||!((r=o.view.dom)!=null&&r.parentNode))return;const s=c.unref(e.value);e.value.append(...o.view.dom.parentNode.childNodes),o.contentComponent=t.ctx._,t&&(o.appContext={...t.appContext,provides:t.provides}),o.setOptions({element:s}),o.createNodeViews()})}),c.onBeforeUnmount(()=>{const o=n.editor;o&&(o.contentComponent=null,o.appContext=null)}),{rootEl:e}},render(){return c.h("div",{ref:n=>{this.rootEl=n}})}});c.defineComponent({name:"NodeViewContent",props:{as:{type:String,default:"div"}},render(){return c.h(this.as,{style:{whiteSpace:"pre-wrap"},"data-node-view-content":""})}}),c.defineComponent({name:"NodeViewWrapper",props:{as:{type:String,default:"div"}},inject:["onDragStart","decorationClasses"],render(){var n,e;return c.h(this.as,{class:this.decorationClasses,style:{whiteSpace:"normal"},"data-node-view-wrapper":"",onDragstart:this.onDragStart},(e=(n=this.$slots).default)==null?void 0:e.call(n))}}),c.defineComponent({name:"MarkViewContent",props:{as:{type:String,default:"span"}},render(){return c.h(this.as,{style:{whiteSpace:"inherit"},"data-mark-view-content":""})}});var dy=Fs.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
|
|
169
101
|
|
|
170
|
-
`):""}),r0=PN,o0=" ",RN=" ",DN=wd.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",vo(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];if(n.length===1&&n[0].type==="image")return e.parseChildren([n[0]]);const r=e.parseInline(n);return r.length===1&&r[0].type==="text"&&(r[0].text===o0||r[0].text===RN)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,r)},renderMarkdown:(t,e)=>{if(!t)return"";const n=Array.isArray(t.content)?t.content:[];return n.length===0?o0:e.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),s0=DN,zN=wd.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),i0=zN,a0=(t,e)=>{if(t==="slot")return 0;if(t instanceof Function)return t(e);const{children:n,...r}=e??{};if(t==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[t,r,n]},$N=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,VN=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,LN=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,FN=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,jN=As.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:t=>t.type.name===this.name},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}]},renderHTML({HTMLAttributes:t}){return a0("strong",{...vo(this.options.HTMLAttributes,t),children:a0("slot",{})})},markdownTokenName:"strong",parseMarkdown:(t,e)=>e.applyMark("bold",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`**${e.renderChildren(t)}**`,addCommands(){return{setBold:()=>({commands:t})=>t.setMark(this.name),toggleBold:()=>({commands:t})=>t.toggleMark(this.name),unsetBold:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[pa({find:$N,type:this.type}),pa({find:LN,type:this.type})]},addPasteRules(){return[ma({find:VN,type:this.type}),ma({find:FN,type:this.type})]}}),l0=jN,HN=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,WN=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,ZN=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,UN=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,KN=As.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:t=>t.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:t=>t.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:t}){return["em",vo(this.options.HTMLAttributes,t),0]},addCommands(){return{setItalic:()=>({commands:t})=>t.setMark(this.name),toggleItalic:()=>({commands:t})=>t.toggleMark(this.name),unsetItalic:()=>({commands:t})=>t.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(t,e)=>e.applyMark("italic",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`*${e.renderChildren(t)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[pa({find:HN,type:this.type}),pa({find:ZN,type:this.type})]},addPasteRules(){return[ma({find:WN,type:this.type}),ma({find:UN,type:this.type})]}}),c0=KN,JN=As.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",vo(this.options.HTMLAttributes,t),0]},parseMarkdown(t,e){return e.applyMark(this.name||"underline",e.parseInline(t.tokens||[]))},renderMarkdown(t,e){return`++${e.renderChildren(t)}++`},markdownTokenizer:{name:"underline",level:"inline",start(t){return t.indexOf("++")},tokenize(t,e,n){const o=/^(\+\+)([\s\S]+?)(\+\+)/.exec(t);if(!o)return;const s=o[2].trim();return{type:"underline",raw:o[0],text:s,tokens:n.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),d0=JN,qN=be.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:t=>{const e=t.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:t=>t.textAlign?{style:`text-align: ${t.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:t=>({commands:e})=>this.options.alignments.includes(t)?this.options.types.map(n=>e.updateAttributes(n,{textAlign:t})).some(n=>n):!1,unsetTextAlign:()=>({commands:t})=>this.options.types.map(e=>t.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:t=>({editor:e,commands:n})=>this.options.alignments.includes(t)?e.isActive({textAlign:t})?n.unsetTextAlign():n.setTextAlign(t):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),u0=qN,GN=20,f0=(t,e=0)=>{const n=[];return!t.children.length||e>GN||Array.from(t.children).forEach(r=>{r.tagName==="SPAN"?n.push(r):r.children.length&&n.push(...f0(r,e+1))}),n},YN=t=>{if(!t.children.length)return;const e=f0(t);e&&e.forEach(n=>{var r,o;const s=n.getAttribute("style"),i=(o=(r=n.parentElement)==null?void 0:r.closest("span"))==null?void 0:o.getAttribute("style");n.setAttribute("style",`${i};${s}`)})},vd=As.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:t=>t.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&YN(t),{}):!1}]},renderHTML({HTMLAttributes:t}){return["span",vo(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleTextStyle:t=>({commands:e})=>e.toggleMark(this.name,t),removeEmptyTextStyle:()=>({tr:t})=>{const{selection:e}=t;return t.doc.nodesBetween(e.from,e.to,(n,r)=>{if(n.isTextblock)return!0;n.marks.filter(o=>o.type===this.type).some(o=>Object.values(o.attrs).some(s=>!!s))||t.removeMark(r,r+n.nodeSize,this.type)}),!0}}}}),XN=be.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const r=n.split(";").map(o=>o.trim()).filter(Boolean);for(let o=r.length-1;o>=0;o-=1){const s=r[o].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),a=s.slice(1).join(":").trim();if(i==="background-color")return a.replace(/['"]+/g,"")}}}return(e=t.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.backgroundColor?{style:`background-color: ${t.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:t=>({chain:e})=>e().setMark("textStyle",{backgroundColor:t}).run(),unsetBackgroundColor:()=>({chain:t})=>t().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),h0=be.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:t=>{var e;const n=t.getAttribute("style");if(n){const r=n.split(";").map(o=>o.trim()).filter(Boolean);for(let o=r.length-1;o>=0;o-=1){const s=r[o].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),a=s.slice(1).join(":").trim();if(i==="color")return a.replace(/['"]+/g,"")}}}return(e=t.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:t=>t.color?{style:`color: ${t.color}`}:{}}}}]},addCommands(){return{setColor:t=>({chain:e})=>e().setMark("textStyle",{color:t}).run(),unsetColor:()=>({chain:t})=>t().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),QN=be.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:t=>t.style.fontFamily,renderHTML:t=>t.fontFamily?{style:`font-family: ${t.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:t=>({chain:e})=>e().setMark("textStyle",{fontFamily:t}).run(),unsetFontFamily:()=>({chain:t})=>t().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),eB=be.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:t=>t.style.fontSize,renderHTML:t=>t.fontSize?{style:`font-size: ${t.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:t=>({chain:e})=>e().setMark("textStyle",{fontSize:t}).run(),unsetFontSize:()=>({chain:t})=>t().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),tB=be.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:t=>t.style.lineHeight,renderHTML:t=>t.lineHeight?{style:`line-height: ${t.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:t=>({chain:e})=>e().setMark("textStyle",{lineHeight:t}).run(),unsetLineHeight:()=>({chain:t})=>t().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});be.create({name:"textStyleKit",addExtensions(){const t=[];return this.options.backgroundColor!==!1&&t.push(XN.configure(this.options.backgroundColor)),this.options.color!==!1&&t.push(h0.configure(this.options.color)),this.options.fontFamily!==!1&&t.push(QN.configure(this.options.fontFamily)),this.options.fontSize!==!1&&t.push(eB.configure(this.options.fontSize)),this.options.lineHeight!==!1&&t.push(tB.configure(this.options.lineHeight)),this.options.textStyle!==!1&&t.push(vd.configure(this.options.textStyle)),t}});var p0=h0;function nB(t={}){return new Oe({view(e){return new rB(e,t)}})}class rB{constructor(e,n){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=n.width)!==null&&r!==void 0?r:1,this.color=n.color===!1?void 0:n.color||"black",this.class=n.class,this.handlers=["dragover","dragend","drop","dragleave"].map(o=>{let s=i=>{this[o](i)};return e.dom.addEventListener(o,s),{name:o,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:n})=>this.editorView.dom.removeEventListener(e,n))}update(e,n){this.cursorPos!=null&&n.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),n=!e.parent.inlineContent,r,o=this.editorView.dom,s=o.getBoundingClientRect(),i=s.width/o.offsetWidth,a=s.height/o.offsetHeight;if(n){let f=e.nodeBefore,p=e.nodeAfter;if(f||p){let m=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(m){let g=m.getBoundingClientRect(),y=f?g.bottom:g.top;f&&p&&(y=(y+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let k=this.width/2*a;r={left:g.left,right:g.right,top:y-k,bottom:y+k}}}}if(!r){let f=this.editorView.coordsAtPos(this.cursorPos),p=this.width/2*i;r={left:f.left-p,right:f.left+p,top:f.top,bottom:f.bottom}}let l=this.editorView.dom.offsetParent;this.element||(this.element=l.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n);let c,u;if(!l||l==document.body&&getComputedStyle(l).position=="static")c=-pageXOffset,u=-pageYOffset;else{let f=l.getBoundingClientRect(),p=f.width/l.offsetWidth,m=f.height/l.offsetHeight;c=f.left-l.scrollLeft*p,u=f.top-l.scrollTop*m}this.element.style.left=(r.left-c)/i+"px",this.element.style.top=(r.top-u)/a+"px",this.element.style.width=(r.right-r.left)/i+"px",this.element.style.height=(r.bottom-r.top)/a+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let n=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=n&&n.inside>=0&&this.editorView.state.doc.nodeAt(n.inside),o=r&&r.type.spec.disableDropCursor,s=typeof o=="function"?o(this.editorView,n,e):o;if(n&&!s){let i=n.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let a=Om(this.editorView.state.doc,i,this.editorView.dragging.slice);a!=null&&(i=a)}this.setCursor(i),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class xe extends ie{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return xe.valid(r)?new xe(r):ie.near(r)}content(){return L.empty}eq(e){return e instanceof xe&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new xe(e.resolve(n.pos))}getBookmark(){return new bd(this.anchor)}static valid(e){let n=e.parent;if(n.isTextblock||!oB(e)||!sB(e))return!1;let r=n.type.spec.allowGapCursor;if(r!=null)return r;let o=n.contentMatchAt(e.index()).defaultType;return o&&o.isTextblock}static findGapCursorFrom(e,n,r=!1){e:for(;;){if(!r&&xe.valid(e))return e;let o=e.pos,s=null;for(let i=e.depth;;i--){let a=e.node(i);if(n>0?e.indexAfter(i)<a.childCount:e.index(i)>0){s=a.child(n>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;o+=n;let l=e.doc.resolve(o);if(xe.valid(l))return l}for(;;){let i=n>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!G.isSelectable(s)){e=e.doc.resolve(o+s.nodeSize*n),r=!1;continue e}break}s=i,o+=n;let a=e.doc.resolve(o);if(xe.valid(a))return a}return null}}}xe.prototype.visible=!1,xe.findFrom=xe.findGapCursorFrom,ie.jsonID("gapcursor",xe);class bd{constructor(e){this.pos=e}map(e){return new bd(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return xe.valid(n)?new xe(n):ie.near(n)}}function m0(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function oB(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),r=t.node(e);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let o=r.child(n-1);;o=o.lastChild){if(o.childCount==0&&!o.inlineContent||m0(o.type))return!0;if(o.inlineContent)return!1}}return!0}function sB(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),r=t.node(e);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let o=r.child(n);;o=o.firstChild){if(o.childCount==0&&!o.inlineContent||m0(o.type))return!0;if(o.inlineContent)return!1}}return!0}function iB(){return new Oe({props:{decorations:dB,createSelectionBetween(t,e,n){return e.pos==n.pos&&xe.valid(n)?new xe(n):null},handleClick:lB,handleKeyDown:aB,handleDOMEvents:{beforeinput:cB}}})}const aB=wy({ArrowLeft:ga("horiz",-1),ArrowRight:ga("horiz",1),ArrowUp:ga("vert",-1),ArrowDown:ga("vert",1)});function ga(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,o,s){let i=r.selection,a=e>0?i.$to:i.$from,l=i.empty;if(i instanceof re){if(!s.endOfTextblock(n)||a.depth==0)return!1;l=!1,a=r.doc.resolve(e>0?a.after():a.before())}let c=xe.findGapCursorFrom(a,e,l);return c?(o&&o(r.tr.setSelection(new xe(c))),!0):!1}}function lB(t,e,n){if(!t||!t.editable)return!1;let r=t.state.doc.resolve(e);if(!xe.valid(r))return!1;let o=t.posAtCoords({left:n.clientX,top:n.clientY});return o&&o.inside>-1&&G.isSelectable(t.state.doc.nodeAt(o.inside))?!1:(t.dispatch(t.state.tr.setSelection(new xe(r))),!0)}function cB(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof xe))return!1;let{$from:n}=t.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!r)return!1;let o=B.empty;for(let i=r.length-1;i>=0;i--)o=B.from(r[i].createAndFill(null,o));let s=t.state.tr.replace(n.pos,n.pos,new L(o,0,0));return s.setSelection(re.near(s.doc.resolve(n.pos+1))),t.dispatch(s),!1}function dB(t){if(!(t.selection instanceof xe))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",Ce.create(t.doc,[nt.widget(t.selection.head,e,{key:"gapcursor"})])}var ya=200,$e=function(){};$e.prototype.append=function(e){return e.length?(e=$e.from(e),!this.length&&e||e.length<ya&&this.leafAppend(e)||this.length<ya&&e.leafPrepend(this)||this.appendInner(e)):this},$e.prototype.prepend=function(e){return e.length?$e.from(e).append(this):this},$e.prototype.appendInner=function(e){return new uB(this,e)},$e.prototype.slice=function(e,n){return e===void 0&&(e=0),n===void 0&&(n=this.length),e>=n?$e.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))},$e.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},$e.prototype.forEach=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length),n<=r?this.forEachInner(e,n,r,0):this.forEachInvertedInner(e,n,r,0)},$e.prototype.map=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length);var o=[];return this.forEach(function(s,i){return o.push(e(s,i))},n,r),o},$e.from=function(e){return e instanceof $e?e:e&&e.length?new g0(e):$e.empty};var g0=function(t){function e(r){t.call(this),this.values=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(o,s){return o==0&&s==this.length?this:new e(this.values.slice(o,s))},e.prototype.getInner=function(o){return this.values[o]},e.prototype.forEachInner=function(o,s,i,a){for(var l=s;l<i;l++)if(o(this.values[l],a+l)===!1)return!1},e.prototype.forEachInvertedInner=function(o,s,i,a){for(var l=s-1;l>=i;l--)if(o(this.values[l],a+l)===!1)return!1},e.prototype.leafAppend=function(o){if(this.length+o.length<=ya)return new e(this.values.concat(o.flatten()))},e.prototype.leafPrepend=function(o){if(this.length+o.length<=ya)return new e(o.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e}($e);$e.empty=new g0([]);var uB=function(t){function e(n,r){t.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return r<this.left.length?this.left.get(r):this.right.get(r-this.left.length)},e.prototype.forEachInner=function(r,o,s,i){var a=this.left.length;if(o<a&&this.left.forEachInner(r,o,Math.min(s,a),i)===!1||s>a&&this.right.forEachInner(r,Math.max(o-a,0),Math.min(this.length,s)-a,i+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,o,s,i){var a=this.left.length;if(o>a&&this.right.forEachInvertedInner(r,o-a,Math.max(s,a)-a,i+a)===!1||s<a&&this.left.forEachInvertedInner(r,Math.min(o,a),s,i)===!1)return!1},e.prototype.sliceInner=function(r,o){if(r==0&&o==this.length)return this;var s=this.left.length;return o<=s?this.left.slice(r,o):r>=s?this.right.slice(r-s,o-s):this.left.slice(r,s).append(this.right.slice(0,o-s))},e.prototype.leafAppend=function(r){var o=this.right.leafAppend(r);if(o)return new e(this.left,o)},e.prototype.leafPrepend=function(r){var o=this.left.leafPrepend(r);if(o)return new e(o,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}($e);const fB=500;class Ot{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let o,s;n&&(o=this.remapping(r,this.items.length),s=o.maps.length);let i=e.tr,a,l,c=[],u=[];return this.items.forEach((f,p)=>{if(!f.step){o||(o=this.remapping(r,p+1),s=o.maps.length),s--,u.push(f);return}if(o){u.push(new Jt(f.map));let m=f.step.map(o.slice(s)),g;m&&i.maybeStep(m).doc&&(g=i.mapping.maps[i.mapping.maps.length-1],c.push(new Jt(g,void 0,void 0,c.length+u.length))),s--,g&&o.appendMap(g,s)}else i.maybeStep(f.step);if(f.selection)return a=o?f.selection.map(o.slice(s)):f.selection,l=new Ot(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:l,transform:i,selection:a}}addTransform(e,n,r,o){let s=[],i=this.eventCount,a=this.items,l=!o&&a.length?a.get(a.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),p=new Jt(e.mapping.maps[u],f,n),m;(m=l&&l.merge(p))&&(p=m,u?s.pop():a=a.slice(0,a.length-1)),s.push(p),n&&(i++,n=void 0),o||(l=p)}let c=i-r.depth;return c>pB&&(a=hB(a,c),i-=c),new Ot(a.append(s),i)}remapping(e,n){let r=new ds;return this.items.forEach((o,s)=>{let i=o.mirrorOffset!=null&&s-o.mirrorOffset>=e?r.maps.length-o.mirrorOffset:void 0;r.appendMap(o.map,i)},e,n),r}addMaps(e){return this.eventCount==0?this:new Ot(this.items.append(e.map(n=>new Jt(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let r=[],o=Math.max(0,this.items.length-n),s=e.mapping,i=e.steps.length,a=this.eventCount;this.items.forEach(p=>{p.selection&&a--},o);let l=n;this.items.forEach(p=>{let m=s.getMirror(--l);if(m==null)return;i=Math.min(i,m);let g=s.maps[m];if(p.step){let y=e.steps[m].invert(e.docs[m]),k=p.selection&&p.selection.map(s.slice(l+1,m));k&&a++,r.push(new Jt(g,y,k))}else r.push(new Jt(g))},o);let c=[];for(let p=n;p<i;p++)c.push(new Jt(s.maps[p]));let u=this.items.slice(0,o).append(c).append(r),f=new Ot(u,a);return f.emptyItemCount()>fB&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),r=n.maps.length,o=[],s=0;return this.items.forEach((i,a)=>{if(a>=e)o.push(i),i.selection&&s++;else if(i.step){let l=i.step.map(n.slice(r)),c=l&&l.getMap();if(r--,c&&n.appendMap(c,r),l){let u=i.selection&&i.selection.map(n.slice(r));u&&s++;let f=new Jt(c.invert(),l,u),p,m=o.length-1;(p=o.length&&o[m].merge(f))?o[m]=p:o.push(f)}}else i.map&&r--},this.items.length,0),new Ot($e.from(o.reverse()),s)}}Ot.empty=new Ot($e.empty,0);function hB(t,e){let n;return t.forEach((r,o)=>{if(r.selection&&e--==0)return n=o,!1}),t.slice(n)}class Jt{constructor(e,n,r,o){this.map=e,this.step=n,this.selection=r,this.mirrorOffset=o}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new Jt(n.getMap().invert(),n,this.selection)}}}class Hn{constructor(e,n,r,o,s){this.done=e,this.undone=n,this.prevRanges=r,this.prevTime=o,this.prevComposition=s}}const pB=20;function mB(t,e,n,r){let o=n.getMeta(Tr),s;if(o)return o.historyState;n.getMeta(kB)&&(t=new Hn(t.done,t.undone,null,0,-1));let i=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(i&&i.getMeta(Tr))return i.getMeta(Tr).redo?new Hn(t.done.addTransform(n,void 0,r,ka(e)),t.undone,y0(n.mapping.maps),t.prevTime,t.prevComposition):new Hn(t.done,t.undone.addTransform(n,void 0,r,ka(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let a=n.getMeta("composition"),l=t.prevTime==0||!i&&t.prevComposition!=a&&(t.prevTime<(n.time||0)-r.newGroupDelay||!gB(n,t.prevRanges)),c=i?Sd(t.prevRanges,n.mapping):y0(n.mapping.maps);return new Hn(t.done.addTransform(n,l?e.selection.getBookmark():void 0,r,ka(e)),Ot.empty,c,n.time,a??t.prevComposition)}else return(s=n.getMeta("rebased"))?new Hn(t.done.rebased(n,s),t.undone.rebased(n,s),Sd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new Hn(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),Sd(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function gB(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((r,o)=>{for(let s=0;s<e.length;s+=2)r<=e[s+1]&&o>=e[s]&&(n=!0)}),n}function y0(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((r,o,s,i)=>e.push(s,i));return e}function Sd(t,e){if(!t)return null;let n=[];for(let r=0;r<t.length;r+=2){let o=e.map(t[r],1),s=e.map(t[r+1],-1);o<=s&&n.push(o,s)}return n}function yB(t,e,n){let r=ka(e),o=Tr.get(e).spec.config,s=(n?t.undone:t.done).popEvent(e,r);if(!s)return null;let i=s.selection.resolve(s.transform.doc),a=(n?t.done:t.undone).addTransform(s.transform,e.selection.getBookmark(),o,r),l=new Hn(n?a:s.remaining,n?s.remaining:a,null,0,-1);return s.transform.setSelection(i).setMeta(Tr,{redo:n,historyState:l})}let Cd=!1,k0=null;function ka(t){let e=t.plugins;if(k0!=e){Cd=!1,k0=e;for(let n=0;n<e.length;n++)if(e[n].spec.historyPreserveItems){Cd=!0;break}}return Cd}const Tr=new Qe("history"),kB=new Qe("closeHistory");function wB(t={}){return t={depth:t.depth||100,newGroupDelay:t.newGroupDelay||500},new Oe({key:Tr,state:{init(){return new Hn(Ot.empty,Ot.empty,null,0,-1)},apply(e,n,r){return mB(n,r,e,t)}},config:t,props:{handleDOMEvents:{beforeinput(e,n){let r=n.inputType,o=r=="historyUndo"?v0:r=="historyRedo"?b0:null;return!o||!e.editable?!1:(n.preventDefault(),o(e.state,e.dispatch))}}}})}function w0(t,e){return(n,r)=>{let o=Tr.getState(n);if(!o||(t?o.undone:o.done).eventCount==0)return!1;if(r){let s=yB(o,n,t);s&&r(e?s.scrollIntoView():s)}return!0}}const v0=w0(!1,!0),b0=w0(!0,!0);be.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:t=>t.length,wordCounter:t=>t.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc;if(((t==null?void 0:t.mode)||this.options.mode)==="textSize"){const r=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(r)}return e.nodeSize},this.storage.words=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc,n=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let t=!1;return[new Oe({key:new Qe("characterCount"),appendTransaction:(e,n,r)=>{if(t)return;const o=this.options.limit;if(o==null||o===0){t=!0;return}const s=this.storage.characters({node:r.doc});if(s>o){const i=s-o,a=0,l=i;console.warn(`[CharacterCount] Initial content exceeded limit of ${o} characters. Content was automatically trimmed.`);const c=r.tr.deleteRange(a,l);return t=!0,c}t=!0},filterTransaction:(e,n)=>{const r=this.options.limit;if(!e.docChanged||r===0||r===null||r===void 0)return!0;const o=this.storage.characters({node:n.doc}),s=this.storage.characters({node:e.doc});if(s<=r||o>r&&s>r&&s<=o)return!0;if(o>r&&s>r&&s>o||!e.getMeta("paste"))return!1;const a=e.selection.$head.pos,l=s-r,c=a-l,u=a;return e.deleteRange(c,u),!(this.storage.characters({node:e.doc})>r)}})]}}),be.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[nB(this.options)]}}),be.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new Oe({key:new Qe("focus"),props:{decorations:({doc:t,selection:e})=>{const{isEditable:n,isFocused:r}=this.editor,{anchor:o}=e,s=[];if(!n||!r)return Ce.create(t,[]);let i=0;this.options.mode==="deepest"&&t.descendants((l,c)=>{if(l.isText)return;if(!(o>=c&&o<=c+l.nodeSize-1))return!1;i+=1});let a=0;return t.descendants((l,c)=>{if(l.isText||!(o>=c&&o<=c+l.nodeSize-1))return!1;if(a+=1,this.options.mode==="deepest"&&i-a>0||this.options.mode==="shallowest"&&a>1)return this.options.mode==="deepest";s.push(nt.node(c,c+l.nodeSize,{class:this.options.className}))}),Ce.create(t,s)}}})]}}),be.create({name:"gapCursor",addProseMirrorPlugins(){return[iB()]},extendNodeSchema(t){var e;const n={name:t.name,options:t.options,storage:t.storage};return{allowGapCursor:(e=ke(U(t,"allowGapCursor",n)))!=null?e:null}}});var S0="placeholder";function vB(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}be.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:S0,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const t=this.options.dataAttribute?`data-${vB(this.options.dataAttribute)}`:`data-${S0}`;return[new Oe({key:new Qe("placeholder"),props:{decorations:({doc:e,selection:n})=>{const r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:o}=n,s=[];if(!r)return null;const i=this.editor.isEmpty;return e.descendants((a,l)=>{const c=o>=l&&o<=l+a.nodeSize,u=!a.isLeaf&&ca(a);if((c||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const p=nt.node(l,l+a.nodeSize,{class:f.join(" "),[t]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:a,pos:l,hasAnchor:c}):this.options.placeholder});s.push(p)}return this.options.includeChildren}),Ce.create(e,s)}}})]}}),be.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:t,options:e}=this;return[new Oe({key:new Qe("selection"),props:{decorations(n){return n.selection.empty||t.isFocused||!t.isEditable||zA(n.selection)||t.view.dragging?null:Ce.create(n.doc,[nt.inline(n.selection.from,n.selection.to,{class:e.className})])}}})]}});function C0({types:t,node:e}){return e&&Array.isArray(t)&&t.includes(e.type)||(e==null?void 0:e.type)===t}be.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var t;const e=new Qe(this.name),n=this.options.node||((t=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:t.name)||"paragraph",r=Object.entries(this.editor.schema.nodes).map(([,o])=>o).filter(o=>(this.options.notAfter||[]).concat(n).includes(o.name));return[new Oe({key:e,appendTransaction:(o,s,i)=>{const{doc:a,tr:l,schema:c}=i,u=e.getState(i),f=a.content.size,p=c.nodes[n];if(u)return l.insert(f,p.create())},state:{init:(o,s)=>{const i=s.tr.doc.lastChild;return!C0({node:i,types:r})},apply:(o,s)=>{if(!o.docChanged||o.getMeta("__uniqueIDTransaction"))return s;const i=o.doc.lastChild;return!C0({node:i,types:r})}}})]}});var bB=be.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>v0(t,e),redo:()=>({state:t,dispatch:e})=>b0(t,e)}},addProseMirrorPlugins(){return[wB(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});function Wn(t,e){const n=d.inject(pt);if(!n)throw new Error("useComponents must be used within a WovenCanvas component");const r=d.shallowRef(new Map),o=new Map;function s(a){if(o.has(a))return;const l=n.getEditor();if(l){const u=l._getContext();if(h.hasComponent(u,a,e)){const f=new Map(r.value);f.set(a,e.snapshot(u,a)),r.value=f}else{const f=new Map(r.value);f.set(a,null),r.value=f}}const c=n.subscribeComponent(a,e.name,u=>{const f=new Map(r.value);f.set(a,u),r.value=f});o.set(a,c)}function i(a){const l=o.get(a);if(l){l(),o.delete(a);const c=new Map(r.value);c.delete(a),r.value=c}}return d.watch(()=>d.toValue(t),(a,l)=>{const c=new Set(a),u=new Set(l??[]);for(const f of u)c.has(f)||i(f);for(const f of c)u.has(f)||s(f)},{immediate:!0}),d.onUnmounted(()=>{for(const a of o.values())a();o.clear()}),r}function x0(){const t=d.inject(pt);if(!t)throw new Error("useImageCreation must be used within a WovenCanvas component");const{nextEditorTick:e}=Ee();function n(s){return new Promise((i,a)=>{const l=new window.Image;l.onload=()=>{i({width:l.naturalWidth,height:l.naturalHeight}),URL.revokeObjectURL(l.src)},l.onerror=()=>{a(new Error("Failed to load image")),URL.revokeObjectURL(l.src)},l.src=URL.createObjectURL(s)})}async function r(s,i,a,l={}){const{maxSize:c=400}=l,u=await n(s),f=await e(),p=Math.min(1,c/Math.max(u.width,u.height));let m=Math.round(u.width*p),g=Math.round(u.height*p);const y=h.Grid.read(f);y.enabled&&(m=Math.max(y.colWidth,Math.round(m/y.colWidth)*y.colWidth),g=Math.max(y.rowHeight,Math.round(g/y.rowHeight)*y.rowHeight));const k=h.createEntity(f);h.addComponent(f,k,h.Block);const w=h.Block.write(f,k);w.tag="image",w.position[0]=i-m/2,w.position[1]=a-g/2,w.size[0]=m,w.size[1]=g,h.Grid.snapPosition(f,w.position);const v=crypto.randomUUID();h.addComponent(f,k,h.Asset);const b=h.Asset.write(f,k);b.identifier=v,b.uploadState=h.UploadState.Pending,h.addComponent(f,k,h.Image);const S=h.Image.write(f,k);return S.width=u.width,S.height=u.height,S.alt=s.name,h.addComponent(f,k,at.Synced,{id:crypto.randomUUID()}),(t==null?void 0:t.getAssetManager())&&o(k,v,s),k}async function o(s,i,a){const l=t==null?void 0:t.getAssetManager();if(l)try{await l.upload(i,a,{filename:a.name,mimeType:a.type});const c=await e(),u=h.Asset.write(c,s);u.uploadState=h.UploadState.Complete}catch{const c=await e(),u=h.Asset.write(c,s);u.uploadState=h.UploadState.Failed}}return{getImageDimensions:n,createImageBlock:r}}function _0(t){const e=d.inject(pt);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const n=d.shallowRef([]),r=h.defineQuery(f=>f.with(...t)),o=new Map;let s=!1;function i(f){const p=e.getEditor();if(!p)return{refs:{},unsubscribes:[]};const m=p._getContext(),g={},y=[];for(const k of t){const w=d.shallowRef(k.snapshot(m,f));g[k.name]=w;const v=e.subscribeComponent(f,k.name,b=>{w.value=b});y.push(v)}return{refs:g,unsubscribes:y}}function a(f){const p=o.get(f);if(p){for(const m of p.unsubscribes)m();o.delete(f)}}function l(){const f=[];for(const[p,m]of o)f.push({entityId:p,...m.refs});return f}function c(f){if(!s){const y=r.current(f);for(const k of y)o.set(k,i(k));n.value=l(),s=!0;return}const p=r.added(f),m=r.removed(f);let g=!1;for(const y of m)a(y),g=!0;for(const y of p)o.has(y)||(o.set(y,i(y)),g=!0);g&&(n.value=l())}const u=e.registerTickCallback(c);return d.onUnmounted(()=>{u();for(const f of o.keys())a(f)}),n}function Ze(t){const e=d.inject(pt);if(!e)throw new Error("useSingleton must be used within a WovenCanvas component");const n=d.shallowRef(t.default()),r=e.getEditor();if(r){const i=r._getContext();n.value=t.snapshot(i)}const o=e.subscribeSingleton(t.name,i=>{n.value=i??{}});let s=null;return r||(s=e.registerTickCallback(()=>{const i=e.getEditor();if(i){const a=i._getContext();n.value=t.snapshot(a),s==null||s(),s=null}})),d.onUnmounted(()=>{o(),s==null||s()}),n}function xd(t,e,n){if(!t.closest(".wov-block")){const m=t.getBoundingClientRect();return{width:m.width,height:m.height,left:0,top:0}}const o=t.getBoundingClientRect(),s=n.value.left,i=n.value.top,a=new DOMPoint(o.left+o.width/2-s,o.top+o.height/2-i),l=e.value.zoom,c=new DOMMatrix;c.translateSelf(-e.value.left*l,-e.value.top*l),c.scaleSelf(l,l),c.invertSelf();const u=c.transformPoint(a),f=t.offsetWidth,p=t.offsetHeight;return{width:f,height:p,left:u.x-f/2,top:u.y-p/2}}function E0(t){if(t.startsWith("#"))return t.toUpperCase();const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(e){const n=parseInt(e[1],10).toString(16).padStart(2,"0"),r=parseInt(e[2],10).toString(16).padStart(2,"0"),o=parseInt(e[3],10).toString(16).padStart(2,"0");return`#${n}${r}${o}`.toUpperCase()}return t}function Ns(t){const e=Math.round(t.red),n=Math.round(t.green),r=Math.round(t.blue),o=Math.round(t.alpha);return o<255?"#"+[e,n,r,o].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join(""):"#"+[e,n,r].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join("")}function _d(t){t=t.replace(/^#/,"");let e,n,r,o=255;if(t.length===6)e=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);else if(t.length===8)e=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16),o=parseInt(t.slice(6,8),16);else return null;return{red:e,green:n,blue:r,alpha:o}}function T0(t){const e=_d(t);if(!e)return{h:0,s:100,v:100,a:255};const n=e.red/255,r=e.green/255,o=e.blue/255,s=Math.max(n,r,o),i=Math.min(n,r,o),a=s-i;let l=0;const c=s===0?0:a/s*100,u=s*100;if(a!==0)switch(s){case n:l=((r-o)/a+(r<o?6:0))*60;break;case r:l=((o-n)/a+2)*60;break;case o:l=((n-r)/a+4)*60;break}return{h:l,s:c,v:u,a:e.alpha}}function M0(t){const e=t.h/360,n=t.s/100,r=t.v/100;let o=0,s=0,i=0;const a=Math.floor(e*6),l=e*6-a,c=r*(1-n),u=r*(1-l*n),f=r*(1-(1-l)*n);switch(a%6){case 0:o=r,s=f,i=c;break;case 1:o=u,s=r,i=c;break;case 2:o=c,s=r,i=f;break;case 3:o=c,s=u,i=r;break;case 4:o=f,s=c,i=r;break;case 5:o=r,s=c,i=u;break}const p=m=>Math.round(m*255).toString(16).padStart(2,"0");return`#${p(o)}${p(s)}${p(i)}`}function A0(t){const e=t.h/360,n=t.s/100,r=t.v/100;let o=0,s=0,i=0;const a=Math.floor(e*6),l=e*6-a,c=r*(1-n),u=r*(1-l*n),f=r*(1-(1-l)*n);switch(a%6){case 0:o=r,s=f,i=c;break;case 1:o=u,s=r,i=c;break;case 2:o=c,s=r,i=f;break;case 3:o=c,s=u,i=r;break;case 4:o=f,s=c,i=r;break;case 5:o=r,s=c,i=u;break}const p=g=>Math.round(g*255).toString(16).padStart(2,"0"),m=Math.round(t.a).toString(16).padStart(2,"0");return t.a<255?`#${p(o)}${p(s)}${p(i)}${m}`:`#${p(o)}${p(s)}${p(i)}`}const st=d.shallowRef(null),Ed=d.shallowRef(null),Td=d.shallowRef(null),Zn=d.ref(0);function Bs(){const t={hasEditor:d.computed(()=>st.value!==null),isBold:d.computed(()=>{var o;return Zn.value,((o=st.value)==null?void 0:o.isActive("bold"))??!1}),isItalic:d.computed(()=>{var o;return Zn.value,((o=st.value)==null?void 0:o.isActive("italic"))??!1}),isUnderline:d.computed(()=>{var o;return Zn.value,((o=st.value)==null?void 0:o.isActive("underline"))??!1}),alignment:d.computed(()=>{Zn.value;const o=st.value;return o?o.isActive({textAlign:"center"})?"center":o.isActive({textAlign:"right"})?"right":o.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:d.computed(()=>{Zn.value;const o=st.value;if(!o)return null;const i=o.getAttributes("textStyle").color??null;return i?E0(i):null})},e={toggleBold(){const o=st.value;if(!o)return;const{from:s,to:i}=o.state.selection,a=s===i;let l=o.chain().focus();a&&(l=l.selectAll()),l=l.toggleBold(),a&&(l=l.setTextSelection(i)),l.run()},toggleItalic(){const o=st.value;if(!o)return;const{from:s,to:i}=o.state.selection,a=s===i;let l=o.chain().focus();a&&(l=l.selectAll()),l=l.toggleItalic(),a&&(l=l.setTextSelection(i)),l.run()},toggleUnderline(){const o=st.value;if(!o)return;const{from:s,to:i}=o.state.selection,a=s===i;let l=o.chain().focus();a&&(l=l.selectAll()),l=l.toggleUnderline(),a&&(l=l.setTextSelection(i)),l.run()},setAlignment(o){const s=st.value;s&&s.chain().selectAll().setTextAlign(o).run()},setColor(o){const s=st.value;if(!s)return;const{from:i,to:a}=s.state.selection;i===a?s.chain().focus().selectAll().setColor(o).setTextSelection(a).run():s.chain().focus().setColor(o).run()}};function n(o,s,i){st.value=o,Td.value=s,Ed.value=i,o.on("selectionUpdate",()=>{Zn.value++}),o.on("transaction",()=>{Zn.value++})}function r(){st.value=null,Td.value=null,Ed.value=null}return{editor:st,blockElement:Ed,textElement:Td,state:t,commands:e,updateCounter:Zn,register:n,unregister:r}}const vt=[r0,s0,i0,vd,p0,l0,c0,d0,u0.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function SB(t){return t.type==="text"&&typeof t.text=="string"}function Mr(t,e){if(SB(t)){e(t);return}if(t.content)for(const n of t.content)Mr(n,e)}function Md(t,e){if(t.type==="paragraph"){e(t);return}if(t.content)for(const n of t.content)Md(n,e)}function CB(t,e){var n;return((n=t.marks)==null?void 0:n.some(r=>r.type===e))??!1}function xB(t){var r,o;const e=(r=t.marks)==null?void 0:r.find(s=>s.type==="textStyle"),n=((o=e==null?void 0:e.attrs)==null?void 0:o.color)??null;return n?E0(n):null}function _B(t,e){if(!t.trim())return!1;const n=jn(t,vt);let r=!1,o=!0,s=0;return Mr(n,i=>{s++,CB(i,e)?r=!0:o=!1}),s===0?!1:o?!0:r?null:!1}function EB(t){if(!t.trim())return"left";const e=jn(t,vt);let n="left";return Md(e,r=>{var s;const o=(s=r.attrs)==null?void 0:s.textAlign;o&&(n=o)}),n}function TB(t){if(!t.trim())return null;const e=jn(t,vt);let n=null;return Mr(e,r=>{n===null&&(n=xB(r))}),n}function Ad(t,e){if(!t.trim())return t;const n=jn(t,vt);return Mr(n,r=>{const o=r.marks??[];o.findIndex(i=>i.type===e)===-1&&(r.marks=[...o,{type:e}])}),aa(n,vt)}function Nd(t,e){if(!t.trim())return t;const n=jn(t,vt);return Mr(n,r=>{const o=r.marks??[];r.marks=o.filter(s=>s.type!==e)}),aa(n,vt)}function MB(t,e){if(!t.trim())return t;const n=jn(t,vt);return Md(n,r=>{r.attrs={...r.attrs,textAlign:e}}),aa(n,vt)}function AB(t,e){if(!t.trim())return t;const n=jn(t,vt);return Mr(n,r=>{const o=r.marks??[],s=o.findIndex(i=>i.type==="textStyle");s!==-1?(o[s]={...o[s],attrs:{...o[s].attrs,color:e}},r.marks=o):r.marks=[...o,{type:"textStyle",attrs:{color:e}}]}),aa(n,vt)}function N0(t){const e=document.querySelector(`[data-entity-id="${t}"]`);if(!e)return null;const n=e.firstElementChild;return n||e.querySelector(".wov-editable-text")}function B0(t,e,n,r){var l;const o=t.cloneNode(!0);o.style.position="absolute",o.style.visibility="hidden",o.style.pointerEvents="none",o.style.top="0",o.style.left="0";const s=o.classList.contains("wov-editable-text")?o:o.querySelector(".wov-editable-text");s&&(s.style.fontSize=`${r.fontSizePx}px`,s.style.fontFamily=r.fontFamily);const i=o.querySelector(".ProseMirror, .tiptap");i?i.innerHTML=r.content:s?s.innerHTML=r.content:o.innerHTML=r.content,(l=t.parentElement)==null||l.appendChild(o);const a=xd(o,e,n);return o.remove(),a}function O0(t){const{nextEditorTick:e}=Ee(),n=Wn(t,h.Text),r=Ze(h.Camera),o=Ze(h.Screen),s=Bs(),i={hasTextEntities:d.computed(()=>{for(const p of n.value.values())if(p)return!0;return!1}),hasTextContent:d.computed(()=>{for(const p of n.value.values()){if(!p)continue;const m=p.content?jn(p.content,vt):null;if(m){let g=!1;if(Mr(m,y=>{var k;(k=y.text)!=null&&k.trim()&&(g=!0)}),g)return!0}}return!1}),isBold:d.computed(()=>a("bold")),isItalic:d.computed(()=>a("italic")),isUnderline:d.computed(()=>a("underline")),alignment:d.computed(()=>{let p=null;for(const m of n.value.values()){if(!m)continue;const g=EB(m.content);if(p===null)p=g;else if(p!==g)return null}return p??"left"}),color:d.computed(()=>{let p=null,m=!1;for(const g of n.value.values()){if(!g)continue;const y=TB(g.content);if(!m)p=y,m=!0;else if(p!==y)return null}return p}),fontSize:d.computed(()=>{let p=null,m=!1;for(const g of n.value.values())if(g){if(!m)p=g.fontSizePx,m=!0;else if(p!==g.fontSizePx)return null}return p}),fontFamily:d.computed(()=>{let p=null,m=!1;for(const g of n.value.values())if(g){if(!m)p=g.fontFamily,m=!0;else if(p!==g.fontFamily)return null}return p})};function a(p){let m=null,g=!1;for(const y of n.value.values()){if(!y)continue;const k=_B(y.content,p);if(!g)m=k,g=!0;else if(m!==k)return null}return m}const l={toggleBold(){u(p=>i.isBold.value?Nd(p,"bold"):Ad(p,"bold"))},toggleItalic(){u(p=>i.isItalic.value?Nd(p,"italic"):Ad(p,"italic"))},toggleUnderline(){u(p=>i.isUnderline.value?Nd(p,"underline"):Ad(p,"underline"))},setAlignment(p){f(m=>MB(m,p))},setColor(p){f(m=>AB(m,p))},setFontSize(p){c(m=>({...m,fontSizePx:p}),m=>{m.fontSizePx=p})},setFontFamily(p){c(m=>({...m,fontFamily:p}),m=>{m.fontFamily=p})}};function c(p,m){const g=d.toValue(t),y=[];for(const k of g){const w=n.value.get(k);if(!w)continue;const v=N0(k);if(v){const b=B0(v,r,o,p(w));y.push({entityId:k,...b})}}e(k=>{for(const w of g)m(h.Text.write(k,w));for(const{entityId:w,width:v,height:b,left:S,top:C}of y){const _=h.Block.write(k,w);_.size=[v,b],_.position=[S,C]}d.nextTick(()=>{s.updateCounter.value++})})}function u(p){const m=d.toValue(t),g=[];for(const y of m){const k=n.value.get(y);if(!k)continue;const w=p(k.content),v=N0(y);if(v){const b=B0(v,r,o,{...k,content:w});g.push({entityId:y,content:w,...b})}else g.push({entityId:y,content:w,width:0,height:0,left:0,top:0})}e(y=>{for(const{entityId:k,content:w,width:v,height:b,left:S,top:C}of g){const _=h.Text.write(y,k);if(_.content=w,v>0&&b>0){const x=h.Block.write(y,k);x.size=[v,b],x.position=[S,C]}}})}function f(p){const m=d.toValue(t);e(g=>{for(const y of m){const k=h.Text.write(g,y);k.content=p(k.content)}})}return{state:i,commands:l}}function qt(t){const e=Bs(),n=O0(t),r=e.state.hasEditor;return{state:d.reactive({hasTextToFormat:d.computed(()=>r.value||n.state.hasTextEntities.value),hasEditor:r,hasTextContent:d.computed(()=>n.state.hasTextContent.value),showTextMenuButtons:d.computed(()=>r.value||n.state.hasTextContent.value),isBold:d.computed(()=>r.value?e.state.isBold.value:n.state.isBold.value===!0),isItalic:d.computed(()=>r.value?e.state.isItalic.value:n.state.isItalic.value===!0),isUnderline:d.computed(()=>r.value?e.state.isUnderline.value:n.state.isUnderline.value===!0),alignment:d.computed(()=>r.value?e.state.alignment.value:n.state.alignment.value??"left"),color:d.computed(()=>r.value?e.state.color.value:n.state.color.value),fontSize:d.computed(()=>n.state.fontSize.value),fontFamily:d.computed(()=>n.state.fontFamily.value)}),commands:{toggleBold(){r.value?e.commands.toggleBold():n.commands.toggleBold()},toggleItalic(){r.value?e.commands.toggleItalic():n.commands.toggleItalic()},toggleUnderline(){r.value?e.commands.toggleUnderline():n.commands.toggleUnderline()},setAlignment(i){r.value?e.commands.setAlignment(i):n.commands.setAlignment(i)},setColor(i){r.value?e.commands.setColor(i):n.commands.setColor(i)},setFontSize(i){n.commands.setFontSize(i)},setFontFamily(i){n.commands.setFontFamily(i)}}}}function Bd(t){const e=Ze(h.Camera),n=Ze(h.Screen),r=Ze(xl),o=Ze(Tt),{nextEditorTick:s}=Ee();let i=!1,a=null;function l(u,f){const{entityId:p}=d.toValue(t.blockData),m=d.toValue(t.minWidth)??0,g=d.toValue(t.minHeight)??0,y=Math.max(f.width,m),k=Math.max(f.height,g),w=h.Block.read(u,p),v=Math.abs(w.size[0]-y)>.5,b=Math.abs(w.size[1]-k)>.5;if(!v&&!b)return;const S=h.Block.write(u,p);S.size=[y,k],S.position=[f.left,f.top],r.value.transformBoxId!==null&&vl.spawn(u,{transformBoxId:r.value.transformBoxId})}d.watch(()=>o.value,()=>{s(u=>{const f=NB(u);if(i&&!f){const p=t.containerRef.value;if(!p)return;a=xd(p,e,n),l(u,a),a=null}i=f})},{flush:"sync"});function c(u){const{content:f,...p}=u;s(m=>{const{entityId:g}=d.toValue(t.blockData);if(h.Text.read(m,g).content!==f){const k=h.Text.write(m,g);k.content=f}l(m,p)})}return{handleEditEnd:c}}function NB(t){const e=Tt.read(t);return e.state===de.Dragging&&e.draggedEntity!==null&&h.hasComponent(t,e.draggedEntity,ve)&&ve.read(t,e.draggedEntity).kind===Et.Stretch}function Od(){const t=d.inject(Ul);if(!t)throw new Error("useToolbar must be used within a Toolbar component");return{activeTool:t.activeTool,heldTool:t.heldTool,setTool:t.setTool,dragOutTool:t.dragOutTool,onToolPointerDown:t.onToolPointerDown,onToolPointerUp:t.onToolPointerUp,isActive:e=>d.computed(()=>t.activeTool.value===e)}}const BB=500,OB=1500;function I0(){const t=d.ref(null),e=d.ref(!1),n=d.ref(!1);let r=null,o=null;function s(){r&&(clearTimeout(r),r=null),o&&(clearTimeout(o),o=null)}function i(c,u){s(),t.value={text:c,anchor:u},n.value?e.value=!0:r=setTimeout(()=>{e.value=!0,n.value=!0,r=null},BB)}function a(){s(),e.value=!1,t.value=null,n.value&&(o=setTimeout(()=>{n.value=!1,o=null},OB))}function l(){s(),e.value=!1,t.value=null,n.value=!1}return{activeTooltip:d.readonly(t),isVisible:d.readonly(e),isWarmedUp:d.readonly(n),show:i,hide:a,reset:l}}function Un(){const t=d.inject(yh);if(!t)throw new Error("useTooltipSingleton must be used within a WovenCanvas component");return t}const IB={key:1},PB=["innerHTML"],RB=50,DB=300,wa=d.defineComponent({__name:"EditableText",props:{blockElement:{},entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},emits:["editEnd"],setup(t,{expose:e,emit:n}){var C;const r=t,o=n,s=Pe(r.entityId,h.Text),i=Ze(h.Camera),a=Ze(h.Screen),l=Bs(),{nextEditorTick:c}=Ee(),u=Ze(h.Mouse),f=d.ref(null);e({editableTextRef:f});const p=d.ref(((C=s.value)==null?void 0:C.content)??""),m=d.shallowRef(null);function g(_,x){var I;const T=s.value;return!T||T.constrainWidth||(((I=x.clipboardData)==null?void 0:I.getData("text/plain"))??"").length>RB&&c(V=>{const K=h.Text.write(V,r.entityId);K.constrainWidth=!0;const M=h.Block.read(V,r.entityId),$=Math.max(M.size[0],DB),Z=h.Block.write(V,r.entityId);Z.size=[$,M.size[1]],h.ResetKeyboard.spawn(V),Xr.spawn(V)}),!1}function y(){var _,x;return new ON({extensions:[r0,s0,i0,vd,p0,l0,c0,d0,u0.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((_=s.value)==null?void 0:_.defaultAlignment)??"left"}),bB],content:((x=s.value)==null?void 0:x.content)??"",editable:!0,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:g}})}d.watch(()=>r.edited,async _=>{if(_&&f.value){if(m.value=y(),await k(m.value),!r.blockElement)return;l.register(m.value,f.value,r.blockElement)}else m.value&&(l.unregister(),w(m.value),m.value.destroy(),m.value=null)},{immediate:!0});async function k(_){var I;const x=(I=u.value)==null?void 0:I.position,T=a.value;await d.nextTick(),await new Promise(V=>requestAnimationFrame(V));const N=f.value;if(x&&T&&N){const V=x[0]+T.left,K=x[1]+T.top,M=_.view.posAtCoords({left:V,top:K});if(M){_.chain().focus().setTextSelection(M.pos).run();return}}_.commands.focus("start")}function w(_){let x=_.getHTML();const N=x.replace(/<[^>]*>/g,"").trim().length>0;N||(x=""),p.value=x,c(I=>{var Z,ae;const V=h.getBlockDef(I,r.block.tag);if(!N&&((Z=V.editOptions)!=null&&Z.removeWhenTextEmpty)){h.removeEntity(I,r.entityId);return}const K=(ae=f.value)==null?void 0:ae.closest(".wov-block"),M=(K==null?void 0:K.firstElementChild)??f.value;if(!M){console.warn("EditableText: no element to measure");return}const $=xd(M,i,a);o("editEnd",{content:x,...$})})}d.watch(()=>{var _;return(_=s.value)==null?void 0:_.content},_=>{_!==void 0&&(m.value?m.value.getHTML()!==_&&m.value.commands.setContent(_,{emitUpdate:!1}):p.value=_)});const v=d.computed(()=>{const _=s.value;if(!_)return{};const[x,T]=r.block.flip,N=x?-1:1,I=T?-1:1,V=x||T;return{fontFamily:_.fontFamily,fontSize:`${_.fontSizePx}px`,lineHeight:_.lineHeight,letterSpacing:`${_.letterSpacingEm}em`,width:_.constrainWidth?"100%":"fit-content",whiteSpace:_.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:r.edited?"auto":"none",userSelect:r.edited?"auto":"none",transform:V?`scale(${N}, ${I})`:void 0}});function b(_){_.key==="Control"||_.key==="Meta"||_.stopPropagation()}function S(_){r.edited&&_.stopPropagation()}return d.onUnmounted(()=>{m.value&&(l.unregister(),m.value.destroy(),m.value=null)}),(_,x)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"editableTextRef",ref:f,class:"wov-editable-text",style:d.normalizeStyle(v.value),onKeydown:b,onPointerdown:S,onPointermove:S,onPointerup:S},[m.value?(d.openBlock(),d.createBlock(d.unref(IN),{key:0,editor:m.value},null,8,["editor"])):(d.openBlock(),d.createElementBlock("div",IB,[d.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:p.value},null,8,PB)]))],36))}}),zB={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},$B=["d","fill","stroke","stroke-width","stroke-dasharray"],P0=d.defineComponent({__name:"ShapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=Pe(e.entityId,h.Shape),r=Pe(e.entityId,h.VerticalAlign),o=d.ref(null),s={[h.VerticalAlignment.Top]:"flex-start",[h.VerticalAlignment.Center]:"center",[h.VerticalAlignment.Bottom]:"flex-end"},i=d.computed(()=>n.value?`rgba(${n.value.fillRed}, ${n.value.fillGreen}, ${n.value.fillBlue}, ${(n.value.fillAlpha??255)/255})`:"rgba(0, 0, 0, 0)"),a=d.computed(()=>n.value?n.value.strokeKind===h.StrokeKind.None?"none":`rgba(${n.value.strokeRed}, ${n.value.strokeGreen}, ${n.value.strokeBlue}, ${n.value.strokeAlpha/255})`:"rgba(0, 0, 0, 1)"),l=d.computed(()=>{var y;return((y=n.value)==null?void 0:y.strokeWidth)??2}),c=d.computed(()=>{var y;return((y=n.value)==null?void 0:y.strokeKind)??h.StrokeKind.Solid}),u=d.computed(()=>{var y;return ss[((y=n.value)==null?void 0:y.kind)??"rectangle"]??ss.rectangle}),f=d.computed(()=>{const y=l.value;switch(c.value){case h.StrokeKind.Dashed:return`${y*3} ${y*3}`;case h.StrokeKind.None:return"";case h.StrokeKind.Solid:default:return""}}),p=d.computed(()=>{var y;return{overflow:e.edited?"visible":"hidden",alignItems:s[((y=r.value)==null?void 0:y.value)??h.VerticalAlignment.Top]}}),{nextEditorTick:m}=Ee();function g(y){m(k=>{if(h.Text.read(k,e.entityId).content===y.content)return;const v=h.Text.write(k,e.entityId);v.content=y.content})}return(y,k)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:o,class:"wov-shape-block"},[(d.openBlock(),d.createElementBlock("svg",zB,[d.createElementVNode("path",{d:u.value,fill:i.value,stroke:a.value,"stroke-width":l.value,"stroke-dasharray":f.value,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":"non-scaling-stroke"},null,8,$B)])),d.createElementVNode("div",{class:"wov-shape-content",style:d.normalizeStyle(p.value)},[d.createVNode(wa,d.mergeProps(e,{"block-element":o.value,onEditEnd:g}),null,16,["block-element"])],4)],512))}}),VB=["data-text-empty"],R0=d.defineComponent({__name:"TextBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=d.ref(null),r=Pe(e.entityId,h.Text),o=d.computed(()=>{var c;return(((c=r.value)==null?void 0:c.content)??"").replace(/<[^>]*>/g,"").trim().length===0}),s=d.computed(()=>{var a;return((a=r.value)==null?void 0:a.constrainWidth)??!1}),{handleEditEnd:i}=Bd({blockData:e,containerRef:n});return(a,l)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:n,class:"wov-text-block","data-text-empty":o.value||void 0,style:d.normalizeStyle({width:s.value?"100%":"fit-content"})},[d.createVNode(wa,d.mergeProps(e,{"block-element":n.value,onEditEnd:d.unref(i)}),null,16,["block-element","onEditEnd"])],12,VB))}}),va=Math.min,Ar=Math.max,ba=Math.round,Sa=Math.floor,Gt=t=>({x:t,y:t}),LB={left:"right",right:"left",bottom:"top",top:"bottom"},FB={start:"end",end:"start"};function D0(t,e,n){return Ar(t,va(e,n))}function Ca(t,e){return typeof t=="function"?t(e):t}function Nr(t){return t.split("-")[0]}function xa(t){return t.split("-")[1]}function z0(t){return t==="x"?"y":"x"}function $0(t){return t==="y"?"height":"width"}const jB=new Set(["top","bottom"]);function Kn(t){return jB.has(Nr(t))?"y":"x"}function V0(t){return z0(Kn(t))}function HB(t,e,n){n===void 0&&(n=!1);const r=xa(t),o=V0(t),s=$0(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=_a(i)),[i,_a(i)]}function WB(t){const e=_a(t);return[Id(t),e,Id(e)]}function Id(t){return t.replace(/start|end/g,e=>FB[e])}const L0=["left","right"],F0=["right","left"],ZB=["top","bottom"],UB=["bottom","top"];function KB(t,e,n){switch(t){case"top":case"bottom":return n?e?F0:L0:e?L0:F0;case"left":case"right":return e?ZB:UB;default:return[]}}function JB(t,e,n,r){const o=xa(t);let s=KB(Nr(t),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),e&&(s=s.concat(s.map(Id)))),s}function _a(t){return t.replace(/left|right|bottom|top/g,e=>LB[e])}function qB(t){return{top:0,right:0,bottom:0,left:0,...t}}function GB(t){return typeof t!="number"?qB(t):{top:t,right:t,bottom:t,left:t}}function Ea(t){const{x:e,y:n,width:r,height:o}=t;return{width:r,height:o,top:n,left:e,right:e+r,bottom:n+o,x:e,y:n}}function j0(t,e,n){let{reference:r,floating:o}=t;const s=Kn(e),i=V0(e),a=$0(i),l=Nr(e),c=s==="y",u=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let m;switch(l){case"top":m={x:u,y:r.y-o.height};break;case"bottom":m={x:u,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:f};break;case"left":m={x:r.x-o.width,y:f};break;default:m={x:r.x,y:r.y}}switch(xa(e)){case"start":m[i]-=p*(n&&c?-1:1);break;case"end":m[i]+=p*(n&&c?-1:1);break}return m}async function YB(t,e){var n;e===void 0&&(e={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:p=!1,padding:m=0}=Ca(e,t),g=GB(m),k=a[p?f==="floating"?"reference":"floating":f],w=Ea(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(k)))==null||n?k:k.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),v=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),S=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Ea(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:b,strategy:l}):v);return{top:(w.top-C.top+g.top)/S.y,bottom:(C.bottom-w.bottom+g.bottom)/S.y,left:(w.left-C.left+g.left)/S.x,right:(C.right-w.right+g.right)/S.x}}const XB=async(t,e,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:t,floating:e,strategy:o}),{x:u,y:f}=j0(c,r,l),p=r,m={},g=0;for(let k=0;k<a.length;k++){var y;const{name:w,fn:v}=a[k],{x:b,y:S,data:C,reset:_}=await v({x:u,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:m,rects:c,platform:{...i,detectOverflow:(y=i.detectOverflow)!=null?y:YB},elements:{reference:t,floating:e}});u=b??u,f=S??f,m={...m,[w]:{...m[w],...C}},_&&g<=50&&(g++,typeof _=="object"&&(_.placement&&(p=_.placement),_.rects&&(c=_.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:o}):_.rects),{x:u,y:f}=j0(c,p,l)),k=-1)}return{x:u,y:f,placement:p,strategy:o,middlewareData:m}},QB=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...k}=Ca(t,e);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=Nr(o),v=Kn(a),b=Nr(a)===a,S=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=p||(b||!y?[_a(a)]:WB(a)),_=g!=="none";!p&&_&&C.push(...JB(a,y,g,S));const x=[a,...C],T=await l.detectOverflow(e,k),N=[];let I=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&N.push(T[w]),f){const $=HB(o,i,S);N.push(T[$[0]],T[$[1]])}if(I=[...I,{placement:o,overflows:N}],!N.every($=>$<=0)){var V,K;const $=(((V=s.flip)==null?void 0:V.index)||0)+1,Z=x[$];if(Z&&(!(f==="alignment"?v!==Kn(Z):!1)||I.every(j=>Kn(j.placement)===v?j.overflows[0]>0:!0)))return{data:{index:$,overflows:I},reset:{placement:Z}};let ae=(K=I.filter(X=>X.overflows[0]<=0).sort((X,j)=>X.overflows[1]-j.overflows[1])[0])==null?void 0:K.placement;if(!ae)switch(m){case"bestFit":{var M;const X=(M=I.filter(j=>{if(_){const q=Kn(j.placement);return q===v||q==="y"}return!0}).map(j=>[j.placement,j.overflows.filter(q=>q>0).reduce((q,te)=>q+te,0)]).sort((j,q)=>j[1]-q[1])[0])==null?void 0:M[0];X&&(ae=X);break}case"initialPlacement":ae=a;break}if(o!==ae)return{reset:{placement:ae}}}return{}}}},eO=new Set(["left","top"]);async function tO(t,e){const{placement:n,platform:r,elements:o}=t,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Nr(n),a=xa(n),l=Kn(n)==="y",c=eO.has(i)?-1:1,u=s&&l?-1:1,f=Ca(e,t);let{mainAxis:p,crossAxis:m,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof g=="number"&&(m=a==="end"?g*-1:g),l?{x:m*u,y:p*c}:{x:p*c,y:m*u}}const nO=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=e,l=await tO(e,t);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},rO=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:o,platform:s}=e,{mainAxis:i=!0,crossAxis:a=!1,limiter:l={fn:w=>{let{x:v,y:b}=w;return{x:v,y:b}}},...c}=Ca(t,e),u={x:n,y:r},f=await s.detectOverflow(e,c),p=Kn(Nr(o)),m=z0(p);let g=u[m],y=u[p];if(i){const w=m==="y"?"top":"left",v=m==="y"?"bottom":"right",b=g+f[w],S=g-f[v];g=D0(b,g,S)}if(a){const w=p==="y"?"top":"left",v=p==="y"?"bottom":"right",b=y+f[w],S=y-f[v];y=D0(b,y,S)}const k=l.fn({...e,[m]:g,[p]:y});return{...k,data:{x:k.x-n,y:k.y-r,enabled:{[m]:i,[p]:a}}}}}};function Ta(){return typeof window<"u"}function Br(t){return Pd(t)?(t.nodeName||"").toLowerCase():"#document"}function ut(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Yt(t){var e;return(e=(Pd(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Pd(t){return Ta()?t instanceof Node||t instanceof ut(t).Node:!1}function It(t){return Ta()?t instanceof Element||t instanceof ut(t).Element:!1}function Xt(t){return Ta()?t instanceof HTMLElement||t instanceof ut(t).HTMLElement:!1}function H0(t){return!Ta()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof ut(t).ShadowRoot}const oO=new Set(["inline","contents"]);function Os(t){const{overflow:e,overflowX:n,overflowY:r,display:o}=Pt(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!oO.has(o)}const sO=new Set(["table","td","th"]);function iO(t){return sO.has(Br(t))}const aO=[":popover-open",":modal"];function Ma(t){return aO.some(e=>{try{return t.matches(e)}catch{return!1}})}const lO=["transform","translate","scale","rotate","perspective"],cO=["transform","translate","scale","rotate","perspective","filter"],dO=["paint","layout","strict","content"];function Rd(t){const e=Dd(),n=It(t)?Pt(t):t;return lO.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||cO.some(r=>(n.willChange||"").includes(r))||dO.some(r=>(n.contain||"").includes(r))}function uO(t){let e=Jn(t);for(;Xt(e)&&!bo(e);){if(Rd(e))return e;if(Ma(e))return null;e=Jn(e)}return null}function Dd(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const fO=new Set(["html","body","#document"]);function bo(t){return fO.has(Br(t))}function Pt(t){return ut(t).getComputedStyle(t)}function Aa(t){return It(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function Jn(t){if(Br(t)==="html")return t;const e=t.assignedSlot||t.parentNode||H0(t)&&t.host||Yt(t);return H0(e)?e.host:e}function W0(t){const e=Jn(t);return bo(e)?t.ownerDocument?t.ownerDocument.body:t.body:Xt(e)&&Os(e)?e:W0(e)}function Is(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const o=W0(t),s=o===((r=t.ownerDocument)==null?void 0:r.body),i=ut(o);if(s){const a=zd(i);return e.concat(i,i.visualViewport||[],Os(o)?o:[],a&&n?Is(a):[])}return e.concat(o,Is(o,[],n))}function zd(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Z0(t){const e=Pt(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const o=Xt(t),s=o?t.offsetWidth:n,i=o?t.offsetHeight:r,a=ba(n)!==s||ba(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function $d(t){return It(t)?t:t.contextElement}function So(t){const e=$d(t);if(!Xt(e))return Gt(1);const n=e.getBoundingClientRect(),{width:r,height:o,$:s}=Z0(e);let i=(s?ba(n.width):n.width)/r,a=(s?ba(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const hO=Gt(0);function U0(t){const e=ut(t);return!Dd()||!e.visualViewport?hO:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function pO(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==ut(t)?!1:e}function Or(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const o=t.getBoundingClientRect(),s=$d(t);let i=Gt(1);e&&(r?It(r)&&(i=So(r)):i=So(t));const a=pO(s,n,r)?U0(s):Gt(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const p=ut(s),m=r&&It(r)?ut(r):r;let g=p,y=zd(g);for(;y&&r&&m!==g;){const k=So(y),w=y.getBoundingClientRect(),v=Pt(y),b=w.left+(y.clientLeft+parseFloat(v.paddingLeft))*k.x,S=w.top+(y.clientTop+parseFloat(v.paddingTop))*k.y;l*=k.x,c*=k.y,u*=k.x,f*=k.y,l+=b,c+=S,g=ut(y),y=zd(g)}}return Ea({width:u,height:f,x:l,y:c})}function Na(t,e){const n=Aa(t).scrollLeft;return e?e.left+n:Or(Yt(t)).left+n}function K0(t,e){const n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-Na(t,n),o=n.top+e.scrollTop;return{x:r,y:o}}function mO(t){let{elements:e,rect:n,offsetParent:r,strategy:o}=t;const s=o==="fixed",i=Yt(r),a=e?Ma(e.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Gt(1);const u=Gt(0),f=Xt(r);if((f||!f&&!s)&&((Br(r)!=="body"||Os(i))&&(l=Aa(r)),Xt(r))){const m=Or(r);c=So(r),u.x=m.x+r.clientLeft,u.y=m.y+r.clientTop}const p=i&&!f&&!s?K0(i,l):Gt(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+p.x,y:n.y*c.y-l.scrollTop*c.y+u.y+p.y}}function gO(t){return Array.from(t.getClientRects())}function yO(t){const e=Yt(t),n=Aa(t),r=t.ownerDocument.body,o=Ar(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),s=Ar(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Na(t);const a=-n.scrollTop;return Pt(r).direction==="rtl"&&(i+=Ar(e.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const J0=25;function kO(t,e){const n=ut(t),r=Yt(t),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const u=Dd();(!u||u&&e==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=Na(r);if(c<=0){const u=r.ownerDocument,f=u.body,p=getComputedStyle(f),m=u.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,g=Math.abs(r.clientWidth-f.clientWidth-m);g<=J0&&(s-=g)}else c<=J0&&(s+=c);return{width:s,height:i,x:a,y:l}}const wO=new Set(["absolute","fixed"]);function vO(t,e){const n=Or(t,!0,e==="fixed"),r=n.top+t.clientTop,o=n.left+t.clientLeft,s=Xt(t)?So(t):Gt(1),i=t.clientWidth*s.x,a=t.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function q0(t,e,n){let r;if(e==="viewport")r=kO(t,n);else if(e==="document")r=yO(Yt(t));else if(It(e))r=vO(e,n);else{const o=U0(t);r={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return Ea(r)}function G0(t,e){const n=Jn(t);return n===e||!It(n)||bo(n)?!1:Pt(n).position==="fixed"||G0(n,e)}function bO(t,e){const n=e.get(t);if(n)return n;let r=Is(t,[],!1).filter(a=>It(a)&&Br(a)!=="body"),o=null;const s=Pt(t).position==="fixed";let i=s?Jn(t):t;for(;It(i)&&!bo(i);){const a=Pt(i),l=Rd(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&wO.has(o.position)||Os(i)&&!l&&G0(t,i))?r=r.filter(u=>u!==i):o=a,i=Jn(i)}return e.set(t,r),r}function SO(t){let{element:e,boundary:n,rootBoundary:r,strategy:o}=t;const i=[...n==="clippingAncestors"?Ma(e)?[]:bO(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const f=q0(e,u,o);return c.top=Ar(f.top,c.top),c.right=va(f.right,c.right),c.bottom=va(f.bottom,c.bottom),c.left=Ar(f.left,c.left),c},q0(e,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function CO(t){const{width:e,height:n}=Z0(t);return{width:e,height:n}}function xO(t,e,n){const r=Xt(e),o=Yt(e),s=n==="fixed",i=Or(t,!0,s,e);let a={scrollLeft:0,scrollTop:0};const l=Gt(0);function c(){l.x=Na(o)}if(r||!r&&!s)if((Br(e)!=="body"||Os(o))&&(a=Aa(e)),r){const m=Or(e,!0,s,e);l.x=m.x+e.clientLeft,l.y=m.y+e.clientTop}else o&&c();s&&!r&&o&&c();const u=o&&!r&&!s?K0(o,a):Gt(0),f=i.left+a.scrollLeft-l.x-u.x,p=i.top+a.scrollTop-l.y-u.y;return{x:f,y:p,width:i.width,height:i.height}}function Vd(t){return Pt(t).position==="static"}function Y0(t,e){if(!Xt(t)||Pt(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Yt(t)===n&&(n=n.ownerDocument.body),n}function X0(t,e){const n=ut(t);if(Ma(t))return n;if(!Xt(t)){let o=Jn(t);for(;o&&!bo(o);){if(It(o)&&!Vd(o))return o;o=Jn(o)}return n}let r=Y0(t,e);for(;r&&iO(r)&&Vd(r);)r=Y0(r,e);return r&&bo(r)&&Vd(r)&&!Rd(r)?n:r||uO(t)||n}const _O=async function(t){const e=this.getOffsetParent||X0,n=this.getDimensions,r=await n(t.floating);return{reference:xO(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function EO(t){return Pt(t).direction==="rtl"}const TO={convertOffsetParentRelativeRectToViewportRelativeRect:mO,getDocumentElement:Yt,getClippingRect:SO,getOffsetParent:X0,getElementRects:_O,getClientRects:gO,getDimensions:CO,getScale:So,isElement:It,isRTL:EO};function Q0(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function MO(t,e){let n=null,r;const o=Yt(t);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=t.getBoundingClientRect(),{left:u,top:f,width:p,height:m}=c;if(a||e(),!p||!m)return;const g=Sa(f),y=Sa(o.clientWidth-(u+p)),k=Sa(o.clientHeight-(f+m)),w=Sa(u),b={rootMargin:-g+"px "+-y+"px "+-k+"px "+-w+"px",threshold:Ar(0,va(1,l))||1};let S=!0;function C(_){const x=_[0].intersectionRatio;if(x!==l){if(!S)return i();x?i(!1,x):r=setTimeout(()=>{i(!1,1e-7)},1e3)}x===1&&!Q0(c,t.getBoundingClientRect())&&i(),S=!1}try{n=new IntersectionObserver(C,{...b,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,b)}n.observe(t)}return i(!0),s}function ek(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=$d(t),u=o||s?[...c?Is(c):[],...Is(e)]:[];u.forEach(w=>{o&&w.addEventListener("scroll",n,{passive:!0}),s&&w.addEventListener("resize",n)});const f=c&&a?MO(c,n):null;let p=-1,m=null;i&&(m=new ResizeObserver(w=>{let[v]=w;v&&v.target===c&&m&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=m)==null||b.observe(e)})),n()}),c&&!l&&m.observe(c),m.observe(e));let g,y=l?Or(t):null;l&&k();function k(){const w=Or(t);y&&!Q0(y,w)&&n(),y=w,g=requestAnimationFrame(k)}return n(),()=>{var w;u.forEach(v=>{o&&v.removeEventListener("scroll",n),s&&v.removeEventListener("resize",n)}),f==null||f(),(w=m)==null||w.disconnect(),m=null,l&&cancelAnimationFrame(g)}}const Ba=nO,Oa=rO,Ia=QB,AO=(t,e,n)=>{const r=new Map,o={platform:TO,...n},s={...o.platform,_c:r};return XB(t,e,{...o,platform:s})};function NO(t){return t!=null&&typeof t=="object"&&"$el"in t}function tk(t){if(NO(t)){const e=t.$el;return Pd(e)&&Br(e)==="#comment"?null:e}return t}function Ps(t){return typeof t=="function"?t():d.unref(t)}function nk(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function rk(t,e){const n=nk(t);return Math.round(e*n)/n}function Pa(t,e,n){n===void 0&&(n={});const r=n.whileElementsMounted,o=d.computed(()=>{var x;return(x=Ps(n.open))!=null?x:!0}),s=d.computed(()=>Ps(n.middleware)),i=d.computed(()=>{var x;return(x=Ps(n.placement))!=null?x:"bottom"}),a=d.computed(()=>{var x;return(x=Ps(n.strategy))!=null?x:"absolute"}),l=d.computed(()=>{var x;return(x=Ps(n.transform))!=null?x:!0}),c=d.computed(()=>tk(t.value)),u=d.computed(()=>tk(e.value)),f=d.ref(0),p=d.ref(0),m=d.ref(a.value),g=d.ref(i.value),y=d.shallowRef({}),k=d.ref(!1),w=d.computed(()=>{const x={position:m.value,left:"0",top:"0"};if(!u.value)return x;const T=rk(u.value,f.value),N=rk(u.value,p.value);return l.value?{...x,transform:"translate("+T+"px, "+N+"px)",...nk(u.value)>=1.5&&{willChange:"transform"}}:{position:m.value,left:T+"px",top:N+"px"}});let v;function b(){if(c.value==null||u.value==null)return;const x=o.value;AO(c.value,u.value,{middleware:s.value,placement:i.value,strategy:a.value}).then(T=>{f.value=T.x,p.value=T.y,m.value=T.strategy,g.value=T.placement,y.value=T.middlewareData,k.value=x!==!1})}function S(){typeof v=="function"&&(v(),v=void 0)}function C(){if(S(),r===void 0){b();return}if(c.value!=null&&u.value!=null){v=r(c.value,u.value,b);return}}function _(){o.value||(k.value=!1)}return d.watch([s,i,a,o],b,{flush:"sync"}),d.watch([c,u],C,{flush:"sync"}),d.watch(o,_,{flush:"sync"}),d.getCurrentScope()&&d.onScopeDispose(S),{x:d.shallowReadonly(f),y:d.shallowReadonly(p),strategy:d.shallowReadonly(m),placement:d.shallowReadonly(g),middlewareData:d.shallowReadonly(y),isPositioned:d.shallowReadonly(k),floatingStyles:w,update:b}}const BO=["menu-open"],bt=d.defineComponent({__name:"MenuDropdown",props:{title:{},disabled:{type:Boolean},placement:{default:"top"},offsetPx:{default:8}},emits:["open","close"],setup(t,{emit:e}){const n=t,r=e,o=d.inject("containerRef"),s=d.inject(ph,null),i=d.inject(mh,0),a=Math.random().toString(36).slice(2);d.provide(mh,i+1);const{show:l,hide:c}=Un(),u=d.ref(!1);s&&d.watch(()=>s.value.get(i),b=>{b!==void 0&&b!==a&&u.value&&(u.value=!1)});const f=d.ref(null),p=d.ref(null),{floatingStyles:m}=Pa(f,p,{placement:n.placement,middleware:[Ba(n.offsetPx),Ia(),Oa({padding:8})],whileElementsMounted:ek});function g(){n.disabled||(u.value=!u.value)}function y(){u.value=!1}function k(b){var T,N,I;const S=b.target,C=(T=f.value)==null?void 0:T.contains(S),_=(N=p.value)==null?void 0:N.contains(S),x=(I=S.closest)==null?void 0:I.call(S,".wov-menu-dropdown");!C&&!_&&!x&&y()}function w(){n.title&&f.value&&!u.value&&l(n.title,f.value)}function v(){c()}return d.watch(u,b=>{b?(c(),document.addEventListener("click",k,!0),s&&(s.value.set(i,a),s.value=new Map(s.value)),r("open")):(document.removeEventListener("click",k,!0),(s==null?void 0:s.value.get(i))===a&&(s.value.delete(i),s.value=new Map(s.value)),r("close"))}),d.onUnmounted(()=>{document.removeEventListener("click",k,!0)}),(b,S)=>(d.openBlock(),d.createElementBlock(d.Fragment,null,[d.createElementVNode("div",{ref_key:"buttonRef",ref:f,class:d.normalizeClass(["wov-menu-dropdown-trigger",{"is-open":u.value}]),"menu-open":u.value||void 0,onMousedown:S[0]||(S[0]=d.withModifiers(()=>{},["prevent"])),onClick:g,onMouseenter:w,onMouseleave:v},[d.renderSlot(b.$slots,"button",{isOpen:u.value})],42,BO),d.unref(o)?(d.openBlock(),d.createBlock(d.Teleport,{key:0,to:d.unref(o)},[u.value?(d.openBlock(),d.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:p,class:"wov-menu-dropdown",style:d.normalizeStyle(d.unref(m))},[d.renderSlot(b.$slots,"dropdown",{close:y})],4)):d.createCommentVNode("",!0)],8,["to"])):d.createCommentVNode("",!0)],64))}}),OO={},IO={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function PO(t,e){return d.openBlock(),d.createElementBlock("svg",IO,[...e[0]||(e[0]=[d.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"},null,-1)])])}const St=ir(OO,[["render",PO]]),RO={class:"wov-menu-button"},DO=["innerHTML"],zO=["onClick"],$O=["innerHTML"],Ld=d.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),r=d.shallowRef(null),o=d.computed(()=>{const a=r.value??(e.side==="start"?pe.None:pe.V);return no(a)});n(a=>{let l=null;for(const c of e.entityIds){if(h.hasComponent(a,c,he)){const u=he.read(a,c),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(l===null)l=f;else if(f!==l){r.value=e.side==="start"?pe.None:pe.V;return}}if(h.hasComponent(a,c,ue)){const u=ue.read(a,c),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(l===null)l=f;else if(f!==l){r.value=e.side==="start"?pe.None:pe.V;return}}}r.value=l});function s(a){r.value=a,n(l=>{for(const c of e.entityIds){if(h.hasComponent(l,c,he)){const u=he.write(l,c);e.side==="start"?u.startArrowHead=a:u.endArrowHead=a}if(h.hasComponent(l,c,ue)){const u=ue.write(l,c);e.side==="start"?u.startArrowHead=a:u.endArrowHead=a}}})}function i(a){if(!a)return"";const l=e.side==="start";return`<line x1="${l?8:4}" y1="12" x2="${l?20:16}" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round" /><g transform="${`translate(${l?4:20}, 12) scale(${l?"-0.8, 0.8":"0.8"})`}">${a.svg}</g>`}return(a,l)=>(d.openBlock(),d.createBlock(bt,{title:t.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:d.withCtx(()=>[d.createElementVNode("div",RO,[(d.openBlock(),d.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",innerHTML:i(o.value)},null,8,DO)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(d.unref(Zl),c=>(d.openBlock(),d.createElementBlock("button",{key:c.kind,class:d.normalizeClass(["wov-menu-option",{"is-active":r.value===c.kind}]),onClick:u=>s(c.kind)},[(d.openBlock(),d.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",innerHTML:i(c)},null,8,$O))],10,zO))),128))]),_:1},8,["title"]))}}),VO={class:"wov-menu-button"},LO=["onClick"],ok=d.defineComponent({__name:"ArrowThicknessButton",props:{entityIds:{}},setup(t){const e=[{label:"S",value:2},{label:"M",value:4},{label:"L",value:8}],n=t,{nextEditorTick:r}=Ee(),o=d.shallowRef(null);r(i=>{let a=null;for(const l of n.entityIds){if(h.hasComponent(i,l,he)){const c=he.read(i,l);if(a===null)a=c.thickness;else if(c.thickness!==a){o.value=null;return}}if(h.hasComponent(i,l,ue)){const c=ue.getThickness(i,l);if(a===null)a=c;else if(c!==a){o.value=null;return}}}o.value=a});function s(i){o.value=i,r(a=>{for(const l of n.entityIds){if(h.hasComponent(a,l,he)){const c=he.write(a,l);c.thickness=i}h.hasComponent(a,l,ue)&&ue.setThickness(a,l,i)}})}return(i,a)=>(d.openBlock(),d.createBlock(bt,{title:"Thickness"},{button:d.withCtx(()=>[d.createElementVNode("div",VO,[a[0]||(a[0]=d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[d.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),d.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),d.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[(d.openBlock(),d.createElementBlock(d.Fragment,null,d.renderList(e,l=>d.createElementVNode("button",{key:l.value,class:d.normalizeClass(["wov-menu-option wov-arrow-thickness-option",{"is-active":o.value===l.value}]),onClick:c=>s(l.value)},d.toDisplayString(l.label),11,LO)),64))]),_:1}))}}),FO=["value"],jO=d.defineComponent({__name:"ColorInput",props:{modelValue:{}},emits:["update:modelValue"],setup(t,{emit:e}){const n=t,r=e,o=d.ref(n.modelValue??"");d.watch(()=>n.modelValue,u=>{u&&u!==o.value&&(o.value=u)});function s(u){const f=u.startsWith("#")?u:`#${u}`;return/^#[0-9A-Fa-f]{6}$/.test(f)}function i(u){return(u.startsWith("#")?u:`#${u}`).toLowerCase()}function a(u){let p=u.target.value;if((p.length===6||p.length===7)&&s(p)){const m=i(p);o.value=m,r("update:modelValue",m)}}function l(u){const p=u.target.value;if(p&&s(p)){const m=i(p);o.value=m,r("update:modelValue",m)}else n.modelValue&&(o.value=n.modelValue)}function c(u){if(u.stopPropagation(),u.key==="Enter"){const f=u.target,p=f.value;if(p&&s(p)){const m=i(p);o.value=m,r("update:modelValue",m),setTimeout(()=>f.select())}}}return(u,f)=>(d.openBlock(),d.createElementBlock("input",{id:"wov-color-input",class:"wov-color-input",type:"text",size:"1","aria-label":"Hex color value",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",value:o.value,onInput:a,onChange:l,onKeydown:c},null,40,FO))}}),sk=d.defineComponent({__name:"ColorSlider",props:{modelValue:{},thumbColor:{},background:{}},emits:["update:modelValue"],setup(t,{expose:e,emit:n}){const r=n,o=d.ref(null),s=d.ref(!1);function i(c){s.value=!0,a(c),window.addEventListener("pointermove",a),window.addEventListener("pointerup",l)}function a(c){if(!o.value)return;const u=o.value.getBoundingClientRect(),f=Math.max(0,Math.min(100,(c.clientY-u.top)/u.height*100));r("update:modelValue",f)}function l(){s.value=!1,window.removeEventListener("pointermove",a),window.removeEventListener("pointerup",l)}return e({isDragging:s}),(c,u)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"sliderRef",ref:o,class:"wov-color-slider",onPointerdown:d.withModifiers(i,["prevent"])},[t.background?(d.openBlock(),d.createElementBlock("div",{key:0,class:"wov-color-slider-gradient",style:d.normalizeStyle({background:t.background})},null,4)):d.createCommentVNode("",!0),d.createElementVNode("div",{class:"wov-color-slider-thumb",style:d.normalizeStyle({top:`${t.modelValue}%`,backgroundColor:t.thumbColor})},null,4)],544))}}),HO={class:"wov-color-picker"},WO={class:"wov-color-picker-area"},ZO={class:"wov-color-picker-selector-gradient"},UO="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",ik=d.defineComponent({__name:"ColorPicker",props:{modelValue:{},withOpacity:{type:Boolean}},emits:["update:modelValue"],setup(t,{emit:e}){const n=t,r=e,o=d.ref(null),s=d.ref(null),i=d.ref(null),a=d.ref({x:100,y:0}),l=d.ref(0),c=d.ref(0),u=d.ref(!1),f=d.computed(()=>{var _,x;return u.value||((_=o.value)==null?void 0:_.isDragging)||((x=s.value)==null?void 0:x.isDragging)}),p=d.computed(()=>({h:l.value/100*360,s:a.value.x,v:100-a.value.y,a:(100-c.value)/100*255})),m=d.computed(()=>M0({h:p.value.h,s:100,v:100})),g=d.computed(()=>M0({h:p.value.h,s:p.value.s,v:p.value.v})),y=d.computed(()=>n.withOpacity?A0(p.value):g.value),k=d.computed(()=>`linear-gradient(to top, transparent 0%, ${g.value} 100%)`);function w(_){if(_){const x=T0(_);a.value={x:x.s,y:100-x.v},l.value=x.h/360*100,c.value=100-x.a/255*100}}function v(_){w(_),r("update:modelValue",n.withOpacity?A0(T0(_)):_)}w(n.modelValue),d.watch(()=>n.modelValue,_=>{f.value||w(_)}),d.watch([a,l,c],()=>{f.value&&r("update:modelValue",y.value)});function b(_){u.value=!0,S(_),window.addEventListener("pointermove",S),window.addEventListener("pointerup",C)}function S(_){if(!i.value)return;const x=i.value.getBoundingClientRect(),T=Math.max(0,Math.min(100,(_.clientX-x.left)/x.width*100)),N=Math.max(0,Math.min(100,(_.clientY-x.top)/x.height*100));a.value={x:T,y:N}}function C(){u.value=!1,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",C)}return(_,x)=>(d.openBlock(),d.createElementBlock("div",HO,[d.createVNode(jO,{modelValue:y.value,"onUpdate:modelValue":v},null,8,["modelValue"]),d.createElementVNode("div",WO,[d.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:d.normalizeStyle({backgroundColor:m.value}),onPointerdown:d.withModifiers(b,["prevent"])},[d.createElementVNode("div",ZO,[d.createElementVNode("div",{class:"wov-color-picker-selector-thumb",style:d.normalizeStyle({left:`${a.value.x}%`,top:`${a.value.y}%`,backgroundColor:g.value})},null,4)])],36),d.createVNode(sk,{ref_key:"hueSliderRef",ref:o,modelValue:l.value,"onUpdate:modelValue":x[0]||(x[0]=T=>l.value=T),thumbColor:m.value,background:UO},null,8,["modelValue","thumbColor"]),t.withOpacity?(d.openBlock(),d.createBlock(sk,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:c.value,"onUpdate:modelValue":x[1]||(x[1]=T=>c.value=T),thumbColor:g.value,background:k.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):d.createCommentVNode("",!0)])]))}}),KO={class:"wov-color-bubbles-container"},JO={key:1,class:"wov-color-bubbles"},qO=["onClick"],Ra=d.defineComponent({__name:"ColorBubbles",props:{currentColor:{},palette:{},hideHighlight:{type:Boolean},withPicker:{type:Boolean},withOpacity:{type:Boolean}},emits:["change","picker-open"],setup(t,{emit:e}){const n=t,r=e,o=["#000000","#374151","#6B7280","#9CA3AF","#D1D5DB","#FFFFFF","#EF4444","#F97316","#EAB308","#22C55E","#14B8A6","#3B82F6","#8B5CF6","#EC4899"],s=d.computed(()=>{const g=n.palette??o,y=n.withPicker,k=g.length%2===1;return y&&!k||!y&&k?g.slice(0,-1):g}),i=d.ref(!1),a=d.ref(n.currentColor??"#ff0000");function l(g,y){const k=w=>{const v=w.replace(/^#/,"").toLowerCase();return v.length===6?v+"ff":v};return k(g)===k(y)}function c(g){return n.hideHighlight||!n.currentColor?!1:l(n.currentColor,g)}function u(){return n.hideHighlight||!n.currentColor?!1:!s.value.some(g=>l(n.currentColor,g))}function f(g){const y=_d(g);y&&r("change",y)}function p(){!i.value&&n.currentColor&&(a.value=n.currentColor),i.value=!i.value,r("picker-open",i.value)}function m(g){a.value=g;const y=_d(g);y&&r("change",y)}return(g,y)=>(d.openBlock(),d.createElementBlock("div",KO,[i.value?(d.openBlock(),d.createBlock(ik,{key:0,modelValue:a.value,"onUpdate:modelValue":[y[0]||(y[0]=k=>a.value=k),m],withOpacity:t.withOpacity},null,8,["modelValue","withOpacity"])):(d.openBlock(),d.createElementBlock("div",JO,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(s.value,k=>(d.openBlock(),d.createElementBlock("div",{key:k,class:d.normalizeClass(["wov-color-bubble",{selected:c(k)}]),style:d.normalizeStyle({backgroundColor:k}),onMousedown:y[1]||(y[1]=d.withModifiers(()=>{},["prevent"])),onClick:w=>f(k)},null,46,qO))),128)),t.withPicker?(d.openBlock(),d.createElementBlock("div",{key:0,class:d.normalizeClass(["wov-color-bubble wov-rainbow-bubble",{selected:u()}]),onMousedown:y[2]||(y[2]=d.withModifiers(()=>{},["prevent"])),onClick:p},null,34)):d.createCommentVNode("",!0)]))]))}}),GO={class:"wov-color-button"},ak=d.defineComponent({__name:"ColorButton",props:{entityIds:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),r=Wn(()=>e.entityIds,h.Color),o=d.computed(()=>{const c=new Set;for(const u of r.value.values())if(u){const f=Ns(u);c.add(f)}return Array.from(c)}),s=d.computed(()=>o.value.length>1),i=d.computed(()=>o.value[0]??null),a=d.computed(()=>{if(o.value.length===0)return{backgroundColor:"#000"};if(o.value.length>=2){const c=o.value[0],u=o.value[1];return{background:`linear-gradient(45deg, ${c} 0%, ${c} 50%, ${u} 50%, ${u} 100%)`}}return{backgroundColor:o.value[0]}});function l(c){const u=Ns(c);n(f=>{for(const p of e.entityIds)h.Color.fromHex(f,p,u)})}return(c,u)=>(d.openBlock(),d.createBlock(bt,{title:"Color"},{button:d.withCtx(()=>[d.createElementVNode("div",GO,[d.createElementVNode("div",{class:"wov-color-swatch",style:d.normalizeStyle(a.value)},null,4),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createVNode(Ra,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,onChange:l},null,8,["currentColor","hideHighlight"])]),_:1}))}}),Co=d.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(t,{emit:e}){const n=t,r=e,o=d.ref(null),{show:s,hide:i}=Un();function a(u){r("click",u)}function l(){n.title&&o.value&&s(n.title,o.value)}function c(){i()}return(u,f)=>(d.openBlock(),d.createElementBlock("button",{ref_key:"buttonRef",ref:o,class:"wov-menu-button",onClick:a,onMouseenter:l,onMouseleave:c},[d.renderSlot(u.$slots,"default")],544))}}),Fd=d.defineComponent({__name:"MenuTooltip",setup(t){const{activeTooltip:e,isVisible:n}=Un(),r=d.inject("containerRef"),o=d.ref(null),s=d.computed(()=>{var l;return((l=e.value)==null?void 0:l.anchor)??null}),{floatingStyles:i}=Pa(s,o,{placement:"top",middleware:[Ba(8),Ia({fallbackPlacements:["bottom"]}),Oa({padding:8})]}),a=d.computed(()=>{var l;return n.value&&((l=e.value)==null?void 0:l.text)});return(l,c)=>d.unref(r)?(d.openBlock(),d.createBlock(d.Teleport,{key:0,to:d.unref(r)},[d.createVNode(d.Transition,{name:"wov-tooltip-fade"},{default:d.withCtx(()=>{var u;return[a.value?(d.openBlock(),d.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:o,class:"wov-menu-tooltip",style:d.normalizeStyle(d.unref(i))},d.toDisplayString((u=d.unref(e))==null?void 0:u.text),5)):d.createCommentVNode("",!0)]}),_:1})],8,["to"])):d.createCommentVNode("",!0)}}),YO={class:"wov-menu-button"},XO=["onClick"],lk=d.defineComponent({__name:"PenStrokeThicknessButton",props:{entityIds:{}},setup(t){const e=[{label:"S",value:4},{label:"M",value:8},{label:"L",value:16}],n=t,{nextEditorTick:r}=Ee(),o=Wn(()=>n.entityIds,Nt),s=d.computed(()=>{let a=null;for(const l of o.value.values())if(l){if(a===null)a=l.thickness;else if(l.thickness!==a)return null}return a});function i(a){r(l=>{for(const c of n.entityIds){const u=Nt.write(l,c);u.thickness=a}})}return(a,l)=>(d.openBlock(),d.createBlock(bt,{title:"Thickness"},{button:d.withCtx(()=>[d.createElementVNode("div",YO,[l[0]||(l[0]=d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[d.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),d.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),d.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[(d.openBlock(),d.createElementBlock(d.Fragment,null,d.renderList(e,c=>d.createElementVNode("button",{key:c.value,class:d.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":s.value===c.value}]),onClick:u=>i(c.value)},d.toDisplayString(c.label),11,XO)),64))]),_:1}))}}),QO={class:"wov-fill-color-button"},eI={class:"wov-fill-dropdown"},tI={key:0,class:"wov-fill-mode-section"},nI=["title","onClick"],rI={viewBox:"0 0 24 24",fill:"none"},oI=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],ck=d.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),r=Wn(()=>e.entityIds,h.Shape),o=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],s=d.computed(()=>{const m=r.value.values().next().value,g=(m==null?void 0:m.fillAlpha)??255;return g===0?"none":g<200?"faded":"solid"}),i=d.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=g.fillAlpha??255;y===0?m.add("none"):y<200?m.add("faded"):m.add("solid")}return m.size>1});function a(m){n(g=>{for(const y of e.entityIds){const k=h.Shape.write(g,y);k.fillAlpha=m}})}const l=d.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=Ns({red:g.fillRed,green:g.fillGreen,blue:g.fillBlue,alpha:g.fillAlpha??255});m.add(y)}return Array.from(m)}),c=d.computed(()=>l.value.length>1),u=d.computed(()=>l.value[0]??"#4a90d9");function f(m){n(g=>{for(const y of e.entityIds){const k=h.Shape.write(g,y);k.fillRed=m.red,k.fillGreen=m.green,k.fillBlue=m.blue,k.fillAlpha=m.alpha}})}const p=d.ref(!1);return(m,g)=>(d.openBlock(),d.createBlock(bt,{title:"Fill Color"},{button:d.withCtx(()=>[d.createElementVNode("div",QO,[g[1]||(g[1]=d.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-fill-color-icon",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},[d.createElementVNode("path",{d:"M5.879,2.625L14.121,2.625C15.906,2.625 17.375,4.094 17.375,5.879L17.375,14.121C17.375,15.906 15.906,17.375 14.121,17.375L5.88,17.375C4.095,17.375 2.626,15.906 2.626,14.121L2.626,5.88C2.626,4.095 4.095,2.626 5.88,2.626L5.879,2.625Z","stroke-width":"1.25"}),d.createElementVNode("path",{d:"M2.779,14.655L14.543,2.871M10.238,17.308L17.318,10.229M2.876,9.577L9.853,2.6M5.397,17.239L17.16,5.476","stroke-width":"1.25"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",eI,[p.value?d.createCommentVNode("",!0):(d.openBlock(),d.createElementBlock("div",tI,[(d.openBlock(),d.createElementBlock(d.Fragment,null,d.renderList(o,y=>d.createElementVNode("button",{key:y.mode,class:d.normalizeClass(["wov-fill-mode-option",{"is-active":!i.value&&y.mode===s.value}]),title:y.label,onClick:k=>a(y.alpha)},[(d.openBlock(),d.createElementBlock("svg",rI,[d.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:y.mode==="none"?"none":"currentColor","fill-opacity":y.mode==="faded"?.4:1,stroke:y.mode==="none"?"currentColor":"none","stroke-width":y.mode==="none"?1.5:0,"stroke-dasharray":y.mode==="none"?"3 3":""},null,8,oI)])),d.createElementVNode("span",null,d.toDisplayString(y.label),1)],10,nI)),64))])),d.createVNode(Ra,{currentColor:u.value,hideHighlight:c.value,withPicker:!0,withOpacity:!0,onChange:f,onPickerOpen:g[0]||(g[0]=y=>p.value=y)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),sI={class:"wov-shape-kind-button"},iI={class:"wov-shape-kind-dropdown"},aI=["onClick"],lI={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},cI=["d"],dk=d.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),r=Wn(()=>e.entityIds,h.Shape),o=d.computed(()=>{const l=r.value.values().next().value;return(l==null?void 0:l.kind)??"rectangle"}),s=d.computed(()=>{const l=new Set;for(const c of r.value.values())c&&l.add(c.kind);return l.size>1}),i=d.computed(()=>Object.keys(ss).map(l=>({kind:l,label:l.charAt(0).toUpperCase()+l.slice(1)})));function a(l){n(c=>{for(const u of e.entityIds){const f=h.Shape.write(c,u);f.kind=l}})}return(l,c)=>(d.openBlock(),d.createBlock(bt,{title:"Shape Type"},{button:d.withCtx(()=>[d.createElementVNode("div",sI,[c[0]||(c[0]=d.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-shape-kind-icon",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[d.createElementVNode("circle",{cx:"6",cy:"6",r:"5"}),d.createElementVNode("rect",{x:"6",y:"6",width:"10",height:"10",fill:"var(--wov-gray-600)"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",iI,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(i.value,u=>(d.openBlock(),d.createElementBlock("button",{key:u.kind,class:d.normalizeClass(["wov-shape-kind-option",{"is-selected":!s.value&&u.kind===o.value}]),onClick:f=>a(u.kind)},[(d.openBlock(),d.createElementBlock("svg",lI,[d.createElementVNode("path",{d:d.unref(ss)[u.kind],transform:"translate(2, 2) scale(0.16)"},null,8,cI)])),d.createElementVNode("span",null,d.toDisplayString(u.label),1)],10,aI))),128))])]),_:1}))}}),dI={class:"wov-stroke-style-section"},uI=["title","onClick"],fI={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},hI=["stroke-dasharray","stroke-opacity"],pI=d.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(t,{emit:e}){const n=e,r=[{kind:h.StrokeKind.Solid,label:"Solid"},{kind:h.StrokeKind.Dashed,label:"Dashed"},{kind:h.StrokeKind.None,label:"None"}];function o(i){switch(i){case h.StrokeKind.Dashed:return"6 6";case h.StrokeKind.None:return"";case h.StrokeKind.Solid:default:return""}}function s(i){n("change",i)}return(i,a)=>(d.openBlock(),d.createElementBlock("div",dI,[(d.openBlock(),d.createElementBlock(d.Fragment,null,d.renderList(r,l=>d.createElementVNode("button",{key:l.kind,class:d.normalizeClass(["wov-stroke-style-option",{"is-active":!t.hasMultipleStyles&&l.kind===t.currentStyle}]),title:l.label,onClick:c=>s(l.kind)},[(d.openBlock(),d.createElementBlock("svg",fI,[d.createElementVNode("line",{x1:"2",y1:"4",x2:"22",y2:"4","stroke-linecap":"round","stroke-dasharray":o(l.kind),"stroke-opacity":l.kind===d.unref(h.StrokeKind).None?.3:1},null,8,hI)])),d.createElementVNode("span",null,d.toDisplayString(l.label),1)],10,uI)),64))]))}}),mI={class:"wov-stroke-color-button"},gI={class:"wov-stroke-dropdown"},yI={key:1,class:"wov-stroke-divider"},uk=d.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),r=Wn(()=>e.entityIds,h.Shape),o=d.ref(!1),s=d.computed(()=>{const p=new Set;for(const m of r.value.values())if(m){const g=Ns({red:m.strokeRed,green:m.strokeGreen,blue:m.strokeBlue,alpha:255});p.add(g)}return Array.from(p)}),i=d.computed(()=>s.value.length>1),a=d.computed(()=>s.value[0]??"#000000"),l=d.computed(()=>{const p=r.value.values().next().value;return(p==null?void 0:p.strokeKind)??h.StrokeKind.Solid}),c=d.computed(()=>{const p=new Set;for(const m of r.value.values())m&&p.add(m.strokeKind);return p.size>1});function u(p){n(m=>{for(const g of e.entityIds){const y=h.Shape.write(m,g);y.strokeRed=p.red,y.strokeGreen=p.green,y.strokeBlue=p.blue}})}function f(p){n(m=>{for(const g of e.entityIds){const y=h.Shape.write(m,g);y.strokeKind=p}})}return(p,m)=>(d.openBlock(),d.createBlock(bt,{title:"Stroke Color"},{button:d.withCtx(()=>[d.createElementVNode("div",mI,[m[1]||(m[1]=d.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-stroke-color-icon",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round"},[d.createElementVNode("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43","stroke-width":"1.25"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",gI,[o.value?d.createCommentVNode("",!0):(d.openBlock(),d.createBlock(pI,{key:0,currentStyle:l.value,hasMultipleStyles:c.value,onChange:f},null,8,["currentStyle","hasMultipleStyles"])),o.value?d.createCommentVNode("",!0):(d.openBlock(),d.createElementBlock("div",yI)),d.createVNode(Ra,{currentColor:a.value,hideHighlight:i.value,withPicker:!0,onChange:u,onPickerOpen:m[0]||(m[0]=g=>o.value=g)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),kI={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},wI={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},vI={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},bI={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},jd=d.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds),o=[h.TextAlignment.Left,h.TextAlignment.Center,h.TextAlignment.Right,h.TextAlignment.Justify];function s(){const i=o.indexOf(n.alignment),a=o[(i+1)%o.length];r.setAlignment(a)}return(i,a)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(Co,{key:0,title:"Text Align",onClick:s},{default:d.withCtx(()=>[d.unref(n).alignment===d.unref(h.TextAlignment).Left?(d.openBlock(),d.createElementBlock("svg",kI,[...a[0]||(a[0]=[d.createElementVNode("path",{d:"M288 64c0 17.7-14.3 32-32 32L32 96C14.3 96 0 81.7 0 64S14.3 32 32 32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32L32 352c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):d.unref(n).alignment===d.unref(h.TextAlignment).Center?(d.openBlock(),d.createElementBlock("svg",wI,[...a[1]||(a[1]=[d.createElementVNode("path",{d:"M352 64c0-17.7-14.3-32-32-32L128 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32zm96 128c0-17.7-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 448c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32zM352 320c0-17.7-14.3-32-32-32l-192 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32z"},null,-1)])])):d.unref(n).alignment===d.unref(h.TextAlignment).Right?(d.openBlock(),d.createElementBlock("svg",vI,[...a[2]||(a[2]=[d.createElementVNode("path",{d:"M448 64c0 17.7-14.3 32-32 32L192 96c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32l-224 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):(d.openBlock(),d.createElementBlock("svg",bI,[...a[3]||(a[3]=[d.createElementVNode("path",{d:"M448 64c0-17.7-14.3-32-32-32L32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l384 0c17.7 0 32-14.3 32-32zm0 256c0-17.7-14.3-32-32-32L32 288c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 192c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32zM448 448c0-17.7-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32z"},null,-1)])]))]),_:1})):d.createCommentVNode("",!0)}}),Hd=d.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds);return(o,s)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(Co,{key:0,title:"Bold",class:d.normalizeClass({"wov-active":d.unref(n).isBold}),onClick:d.unref(r).toggleBold},{default:d.withCtx(()=>[...s[0]||(s[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[d.createElementVNode("path",{d:"M0 64C0 46.3 14.3 32 32 32l48 0 16 0 128 0c70.7 0 128 57.3 128 128c0 31.3-11.3 60.1-30 82.3c37.1 22.4 62 63.1 62 109.7c0 70.7-57.3 128-128 128L96 480l-16 0-48 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l16 0 0-160L48 96 32 96C14.3 96 0 81.7 0 64zM224 224c35.3 0 64-28.7 64-64s-28.7-64-64-64L112 96l0 128 112 0zM112 288l0 128 144 0c35.3 0 64-28.7 64-64s-28.7-64-64-64l-32 0-112 0z"})],-1)])]),_:1},8,["class","onClick"])):d.createCommentVNode("",!0)}});function SI(t,e){return d.getCurrentScope()?(d.onScopeDispose(t,e),!0):!1}const CI=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const xI=Object.prototype.toString,_I=t=>xI.call(t)==="[object Object]",Da=()=>{};function za(t){return Array.isArray(t)?t:[t]}function EI(t){return d.getCurrentInstance()}function TI(t,e=!0,n){EI()?d.onMounted(t,n):e?t():d.nextTick(t)}function MI(t,e,n){return d.watch(t,e,{...n,immediate:!0})}const $a=CI?window:void 0;function Rt(t){var e;const n=d.toValue(t);return(e=n==null?void 0:n.$el)!==null&&e!==void 0?e:n}function Wd(...t){const e=(r,o,s,i)=>(r.addEventListener(o,s,i),()=>r.removeEventListener(o,s,i)),n=d.computed(()=>{const r=za(d.toValue(t[0])).filter(o=>o!=null);return r.every(o=>typeof o!="string")?r:void 0});return MI(()=>{var r,o;return[(r=(o=n.value)===null||o===void 0?void 0:o.map(s=>Rt(s)))!==null&&r!==void 0?r:[$a].filter(s=>s!=null),za(d.toValue(n.value?t[1]:t[0])),za(d.unref(n.value?t[2]:t[1])),d.toValue(n.value?t[3]:t[2])]},([r,o,s,i],a,l)=>{if(!(r!=null&&r.length)||!(o!=null&&o.length)||!(s!=null&&s.length))return;const c=_I(i)?{...i}:i,u=r.flatMap(f=>o.flatMap(p=>s.map(m=>e(f,p,m,c))));l(()=>{u.forEach(f=>f())})},{flush:"post"})}function AI(t,e,n={}){const{window:r=$a,ignore:o=[],capture:s=!0,detectIframe:i=!1,controls:a=!1}=n;if(!r)return a?{stop:Da,cancel:Da,trigger:Da}:Da;let l=!0;const c=k=>d.toValue(o).some(w=>{if(typeof w=="string")return Array.from(r.document.querySelectorAll(w)).some(v=>v===k.target||k.composedPath().includes(v));{const v=Rt(w);return v&&(k.target===v||k.composedPath().includes(v))}});function u(k){const w=d.toValue(k);return w&&w.$.subTree.shapeFlag===16}function f(k,w){const v=d.toValue(k),b=v.$.subTree&&v.$.subTree.children;return b==null||!Array.isArray(b)?!1:b.some(S=>S.el===w.target||w.composedPath().includes(S.el))}const p=k=>{const w=Rt(t);if(k.target!=null&&!(!(w instanceof Element)&&u(t)&&f(t,k))&&!(!w||w===k.target||k.composedPath().includes(w))){if("detail"in k&&k.detail===0&&(l=!c(k)),!l){l=!0;return}e(k)}};let m=!1;const g=[Wd(r,"click",k=>{m||(m=!0,setTimeout(()=>{m=!1},0),p(k))},{passive:!0,capture:s}),Wd(r,"pointerdown",k=>{const w=Rt(t);l=!c(k)&&!!(w&&!k.composedPath().includes(w))},{passive:!0}),i&&Wd(r,"blur",k=>{setTimeout(()=>{var w;const v=Rt(t);((w=r.document.activeElement)===null||w===void 0?void 0:w.tagName)==="IFRAME"&&!(v!=null&&v.contains(r.document.activeElement))&&e(k)},0)},{passive:!0})].filter(Boolean),y=()=>g.forEach(k=>k());return a?{stop:y,cancel:()=>{l=!1},trigger:k=>{l=!0,p(k),l=!1}}:y}function NI(){const t=d.shallowRef(!1),e=d.getCurrentInstance();return e&&d.onMounted(()=>{t.value=!0},e),t}function BI(t){const e=NI();return d.computed(()=>(e.value,!!t()))}function OI(t,e,n={}){const{window:r=$a,...o}=n;let s;const i=BI(()=>r&&"ResizeObserver"in r),a=()=>{s&&(s.disconnect(),s=void 0)},l=d.watch(d.computed(()=>{const u=d.toValue(t);return Array.isArray(u)?u.map(f=>Rt(f)):[Rt(u)]}),u=>{if(a(),i.value&&r){s=new ResizeObserver(e);for(const f of u)f&&s.observe(f,o)}},{immediate:!0,flush:"post"}),c=()=>{a(),l()};return SI(c),{isSupported:i,stop:c}}function fk(t,e={width:0,height:0},n={}){const{window:r=$a,box:o="content-box"}=n,s=d.computed(()=>{var f;return(f=Rt(t))===null||f===void 0||(f=f.namespaceURI)===null||f===void 0?void 0:f.includes("svg")}),i=d.shallowRef(e.width),a=d.shallowRef(e.height),{stop:l}=OI(t,([f])=>{const p=o==="border-box"?f.borderBoxSize:o==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(r&&s.value){const m=Rt(t);if(m){const g=m.getBoundingClientRect();i.value=g.width,a.value=g.height}}else if(p){const m=za(p);i.value=m.reduce((g,{inlineSize:y})=>g+y,0),a.value=m.reduce((g,{blockSize:y})=>g+y,0)}else i.value=f.contentRect.width,a.value=f.contentRect.height},n);TI(()=>{const f=Rt(t);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,a.value="offsetHeight"in f?f.offsetHeight:e.height)});const c=d.watch(()=>Rt(t),f=>{i.value=f?e.width:0,a.value=f?e.height:0});function u(){l(),c()}return{width:i,height:a,stop:u}}function hk(){const t=d.inject(pt);if(!t)throw new Error("useFonts must be used within a WovenCanvas component");return d.computed(()=>{const e=t.getEditor();return e?e.fonts.filter(n=>n.selectable):[]})}const II={class:"wov-font-family-button"},PI={class:"wov-font-family-label"},RI={class:"wov-font-list"},DI=["onClick"],zI=["src","alt"],Zd=d.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds),o=hk(),s=d.computed(()=>o.value.map(u=>({name:u.name,displayName:u.displayName,previewImage:u.previewImage}))),i=d.computed(()=>n.fontFamily),a=d.computed(()=>{const u=i.value;if(u===null)return"Mixed";const f=s.value.find(p=>p.name===u);return(f==null?void 0:f.displayName)??u});function l(u){r.setFontFamily(u)}function c(u){u.stopPropagation()}return(u,f)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(bt,{key:0,title:"Font Family"},{button:d.withCtx(()=>[d.createElementVNode("div",II,[d.createElementVNode("span",PI,d.toDisplayString(a.value),1),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",{class:"wov-font-family-menu",onWheel:c,onClick:f[0]||(f[0]=d.withModifiers(()=>{},["stop"]))},[d.createElementVNode("div",RI,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(s.value,p=>(d.openBlock(),d.createElementBlock("div",{key:p.name,class:d.normalizeClass(["wov-font-item",{active:i.value===p.name}]),onClick:m=>l(p.name)},[p.previewImage?(d.openBlock(),d.createElementBlock("img",{key:0,class:"wov-font-preview",src:p.previewImage,alt:p.name},null,8,zI)):(d.openBlock(),d.createElementBlock("span",{key:1,class:"wov-font-name",style:d.normalizeStyle({fontFamily:p.name})},d.toDisplayString(p.displayName),5))],10,DI))),128))])],32)]),_:1})):d.createCommentVNode("",!0)}}),$I={class:"wov-font-size-button"},VI={class:"wov-font-size-label"},LI=["onClick"],FI={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},jI={class:"wov-input-container"},HI=["value"],Ud=d.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds),o=[{label:"Small",value:16,displayValue:10},{label:"Medium",value:24,displayValue:12},{label:"Large",value:40,displayValue:16},{label:"Huge",value:96,displayValue:20}],s=d.computed(()=>n.fontSize),i=d.computed(()=>{const p=s.value;if(p===null)return"Mixed";const m=o.find(g=>g.value===p);return m?m.label:`${+p.toFixed(1)} px`}),a=d.computed(()=>{const p=s.value;return p===null?"":String(+p.toFixed(1))});function l(p){r.setFontSize(p)}function c(p){const m=p.target,g=Number.parseFloat(m.value);!Number.isNaN(g)&&g>0&&l(g)}function u(p){p.key==="Enter"&&p.target.blur()}function f(p){p.stopPropagation()}return(p,m)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(bt,{key:0,title:"Font Size"},{button:d.withCtx(()=>[d.createElementVNode("div",$I,[d.createElementVNode("span",VI,d.toDisplayString(i.value),1),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",{class:"wov-font-size-menu",onWheel:f,onClick:m[0]||(m[0]=d.withModifiers(()=>{},["stop"]))},[(d.openBlock(),d.createElementBlock(d.Fragment,null,d.renderList(o,g=>d.createElementVNode("div",{key:g.value,class:d.normalizeClass(["wov-font-size-option",{active:s.value===g.value}]),onClick:y=>l(g.value)},[s.value===g.value?(d.openBlock(),d.createElementBlock("svg",FI,[...m[1]||(m[1]=[d.createElementVNode("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"},null,-1)])])):d.createCommentVNode("",!0),d.createElementVNode("span",{class:"wov-option-label",style:d.normalizeStyle({fontSize:`${g.displayValue}px`})},d.toDisplayString(g.label),5)],10,LI)),64)),m[3]||(m[3]=d.createElementVNode("div",{class:"wov-separator"},null,-1)),d.createElementVNode("div",jI,[d.createElementVNode("input",{class:"wov-custom-input",value:a.value,onInput:c,onKeydown:u,placeholder:"Custom size"},null,40,HI),m[2]||(m[2]=d.createElementVNode("span",{class:"wov-px-suffix"},"px",-1))])],32)]),_:1})):d.createCommentVNode("",!0)}}),Kd=d.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds);return(o,s)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(Co,{key:0,title:"Italic",class:d.normalizeClass({"wov-active":d.unref(n).isItalic}),onClick:d.unref(r).toggleItalic},{default:d.withCtx(()=>[...s[0]||(s[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[d.createElementVNode("path",{d:"M128 64c0-17.7 14.3-32 32-32l192 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-58.7 0L160 416l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l58.7 0L224 96l-64 0c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):d.createCommentVNode("",!0)}}),Jd=d.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds);return(o,s)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(Co,{key:0,title:"Underline",class:d.normalizeClass({"wov-active":d.unref(n).isUnderline}),onClick:d.unref(r).toggleUnderline},{default:d.withCtx(()=>[...s[0]||(s[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[d.createElementVNode("path",{d:"M16 64c0-17.7 14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 53 43 96 96 96s96-43 96-96l0-128-16 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 88.4-71.6 160-160 160s-160-71.6-160-160L64 96 48 96C30.3 96 16 81.7 16 64zM0 448c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):d.createCommentVNode("",!0)}}),WI={class:"wov-text-color-button"},ZI={class:"wov-text-icon-container"},qd=d.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(t){const e=t,{state:n,commands:r}=qt(()=>e.entityIds),o=d.computed(()=>n.color??"#000000"),s=d.computed(()=>({backgroundColor:o.value}));function i(a){r.setColor(Ns(a))}return(a,l)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createBlock(bt,{key:0,title:"Text Color"},{button:d.withCtx(()=>[d.createElementVNode("div",WI,[d.createElementVNode("div",ZI,[l[0]||(l[0]=d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-icon"},[d.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),d.createElementVNode("div",{class:"wov-color-underline",style:d.normalizeStyle(s.value)},null,4)]),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createVNode(Ra,{currentColor:o.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):d.createCommentVNode("",!0)}}),UI={key:0,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-start-icon lucide-align-vertical-justify-start"},KI={key:1,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-center-icon lucide-align-vertical-justify-center"},JI={key:2,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-end-icon lucide-align-vertical-justify-end"},pk=d.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(t){const e=t,{nextEditorTick:n}=Ee(),{state:r}=qt(()=>e.entityIds),o=[h.VerticalAlignment.Top,h.VerticalAlignment.Center,h.VerticalAlignment.Bottom],s=Wn(()=>e.entityIds,h.VerticalAlign),i=d.computed(()=>{let l=null;for(const c of s.value.values()){const u=(c==null?void 0:c.value)??h.VerticalAlignment.Top;if(l===null)l=u;else if(l!==u)return null}return l});function a(){const l=i.value??h.VerticalAlignment.Top,c=o.indexOf(l),u=o[(c+1)%o.length];n(f=>{for(const p of e.entityIds){const m=h.VerticalAlign.write(f,p);m.value=u}})}return(l,c)=>d.unref(r).showTextMenuButtons?(d.openBlock(),d.createBlock(Co,{key:0,title:"Vertical Align",onClick:a},{default:d.withCtx(()=>[i.value===d.unref(h.VerticalAlignment).Top||i.value===null?(d.openBlock(),d.createElementBlock("svg",UI,[...c[0]||(c[0]=[d.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),d.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"},null,-1),d.createElementVNode("path",{d:"M2 2h20"},null,-1)])])):i.value===d.unref(h.VerticalAlignment).Center?(d.openBlock(),d.createElementBlock("svg",KI,[...c[1]||(c[1]=[d.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),d.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),d.createElementVNode("path",{d:"M2 12h20"},null,-1)])])):(d.openBlock(),d.createElementBlock("svg",JI,[...c[2]||(c[2]=[d.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"},null,-1),d.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),d.createElementVNode("path",{d:"M2 22h20"},null,-1)])]))]),_:1})):d.createCommentVNode("",!0)}}),qI={class:"wov-text-group-button"},GI={class:"wov-text-group-dropdown"},YI={class:"wov-text-group-row wov-text-group-row-full"},XI={class:"wov-text-group-row"},QI=d.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean}},setup(t){const e=t,{state:n}=qt(()=>e.entityIds),r=d.inject("containerRef"),{width:o}=fk(r),s=d.computed(()=>o.value>0&&o.value<600),i=d.ref(new Map);return d.provide(ph,i),(a,l)=>d.unref(n).showTextMenuButtons?(d.openBlock(),d.createElementBlock(d.Fragment,{key:0},[s.value?(d.openBlock(),d.createBlock(bt,{key:0,title:"Text Formatting",placement:"top"},{button:d.withCtx(()=>[d.createElementVNode("div",qI,[l[0]||(l[0]=d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-group-icon"},[d.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),d.createVNode(St,{class:"wov-chevron-down"})])]),dropdown:d.withCtx(()=>[d.createElementVNode("div",GI,[d.createElementVNode("div",YI,[d.createVNode(Zd,{entityIds:t.entityIds},null,8,["entityIds"]),l[1]||(l[1]=d.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),d.createVNode(Ud,{entityIds:t.entityIds},null,8,["entityIds"])]),d.createElementVNode("div",XI,[d.createVNode(Hd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(Kd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(Jd,{entityIds:t.entityIds},null,8,["entityIds"]),l[2]||(l[2]=d.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),d.createVNode(qd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(jd,{entityIds:t.entityIds},null,8,["entityIds"]),t.showVerticalAlign?(d.openBlock(),d.createBlock(pk,{key:0,entityIds:t.entityIds},null,8,["entityIds"])):d.createCommentVNode("",!0)])])]),_:1})):(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},[d.createVNode(Zd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(Ud,{entityIds:t.entityIds},null,8,["entityIds"]),l[3]||(l[3]=d.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),d.createVNode(Hd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(Kd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(Jd,{entityIds:t.entityIds},null,8,["entityIds"]),l[4]||(l[4]=d.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),d.createVNode(qd,{entityIds:t.entityIds},null,8,["entityIds"]),d.createVNode(jd,{entityIds:t.entityIds},null,8,["entityIds"]),t.showVerticalAlign?(d.openBlock(),d.createBlock(pk,{key:0,entityIds:t.entityIds},null,8,["entityIds"])):d.createCommentVNode("",!0)],64))],64)):d.createCommentVNode("",!0)}}),mk=d.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(t){const e=t,n=Ze(h.Camera),r=Ze(h.Grid),o=d.inject("containerRef"),s=d.ref({width:0,height:0});let i=null;const a=d.ref(null);let l=null;typeof document<"u"&&(l=document.createElement("canvas"));function c(k,w,v,b){const S=b/2;k.beginPath(),k.arc(w,v,S,0,Math.PI*2),k.fill()}function u(k,w,v){if(!l)return null;const b=v.dotSize??2,S=k*v.subdivisionStep,C=w*v.subdivisionStep;if(S<=0||C<=0)return null;l.width=S,l.height=C;const _=l.getContext("2d");if(!_)return null;if(_.clearRect(0,0,S,C),_.fillStyle=v.strokeColor,v.subdivisionStep===1)c(_,S/2,C/2,b);else for(let x=0;x<v.subdivisionStep;x++)for(let T=0;T<v.subdivisionStep;T++){const N=(x+.5)*(S/v.subdivisionStep),I=(T+.5)*(C/v.subdivisionStep),K=x===0&&T===0?2*b:b;c(_,N,I,K)}return _.createPattern(l,"repeat")}function f(k,w,v,b,S,C){k.lineWidth=C,k.beginPath(),k.moveTo(w,v),k.lineTo(b,S),k.stroke()}function p(k,w,v){if(!l)return null;const b=v.gridSize??1,S=k*v.subdivisionStep,C=w*v.subdivisionStep;if(S<=0||C<=0)return null;l.width=S,l.height=C;const _=l.getContext("2d");if(!_)return null;if(_.clearRect(0,0,S,C),_.strokeStyle=v.strokeColor,v.subdivisionStep===1)f(_,0,0,S,0,b),f(_,0,0,0,C,b);else{const x=S/v.subdivisionStep,T=C/v.subdivisionStep;for(let N=0;N<=v.subdivisionStep;N++){const I=N*x,V=N%v.subdivisionStep===0;f(_,I,0,I,C,V?3*b:b)}for(let N=0;N<=v.subdivisionStep;N++){const I=N*T,V=N%v.subdivisionStep===0;f(_,0,I,S,I,V?3*b:b)}}return _.createPattern(l,"repeat")}function m(k){let w=r.value.colWidth,v=r.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,C=s.value.height,_=n.value.left,x=n.value.top,T=_+S/n.value.zoom,N=x+C/n.value.zoom;let I=w*b,V=v*b,K=0,M=0,$=Number.POSITIVE_INFINITY,Z=Number.POSITIVE_INFINITY;for(;;){I=b*w,V=b*v,K=Math.floor(_/I)*I,M=Math.floor(x/V)*V;const Se=Math.ceil(T/I)*I,Dt=Math.ceil(N/V)*V;if(Z=Math.round((Se-K)/w),$=Math.round((Dt-M)/v),Math.max(Z,$)>200)w*=2,v*=2;else break}const ae=w*n.value.zoom,X=v*n.value.zoom,j=Math.round(ae),q=Math.round(X),te=u(j,q,e.background);if(!te)return;te.setTransform(new DOMMatrix().scale(ae/j,X/q));const fe=(K-_-w/2)*n.value.zoom,ce=(M-x-v/2)*n.value.zoom;k.save(),k.translate(fe,ce),k.fillStyle=te,k.fillRect(0,0,S+I*n.value.zoom,C+V*n.value.zoom),k.restore()}function g(k){let w=r.value.colWidth,v=r.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,C=s.value.height,_=n.value.left,x=n.value.top,T=_+S/n.value.zoom,N=x+C/n.value.zoom;let I=w*b,V=v*b,K=0,M=0,$=Number.POSITIVE_INFINITY,Z=Number.POSITIVE_INFINITY;for(;;){I=b*w,V=b*v,K=Math.floor(_/I)*I,M=Math.floor(x/V)*V;const Se=Math.ceil(T/I)*I,Dt=Math.ceil(N/V)*V;if(Z=Math.round((Se-K)/w),$=Math.round((Dt-M)/v),Math.max(Z,$)>200)w*=2,v*=2;else break}const ae=w*n.value.zoom,X=v*n.value.zoom,j=Math.round(ae),q=Math.round(X),te=p(j,q,e.background);if(!te)return;te.setTransform(new DOMMatrix().scale(ae/j,X/q));const fe=(K-_)*n.value.zoom,ce=(M-x)*n.value.zoom;k.save(),k.translate(fe,ce),k.fillStyle=te,k.fillRect(0,0,S+I*n.value.zoom,C+V*n.value.zoom),k.restore()}function y(){const k=a.value;if(!k)return;const w=k.getContext("2d");if(!w)return;const{width:v,height:b}=s.value;v===0||b===0||(k.width=v,k.height=b,w.clearRect(0,0,v,b),w.fillStyle=e.background.color,w.fillRect(0,0,v,b),e.background.kind==="dots"?m(w):e.background.kind==="grid"&&g(w))}return d.watch(()=>[e.background,n.value,r.value,s.value],()=>{y()},{deep:!0}),d.onMounted(()=>{const k=o==null?void 0:o.value;if(k){const w=()=>{s.value={width:k.clientWidth,height:k.clientHeight}};w(),i=new ResizeObserver(w),i.observe(k)}y()}),d.onUnmounted(()=>{i==null||i.disconnect()}),(k,w)=>(d.openBlock(),d.createElementBlock("canvas",{ref_key:"canvasRef",ref:a,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}});function gk(t,e){if(e.length===0)return new Set;const n=e[0].tag,r=t.blockDefs[n];if(!r)return new Set;const o=new Set(r.components.map(s=>s.name));for(let s=1;s<e.length;s++){const i=e[s].tag,a=t.blockDefs[i];if(!a){o.clear();break}const l=new Set(a.components.map(c=>c.name));for(const c of o)l.has(c)||o.delete(c)}return o}const yk=d.defineComponent({__name:"FloatingMenuBar",setup(t){const e=d.useSlots(),{reset:n}=Un(),r=d.inject(gh),{selectedIds:o,commonComponents:s}=r,i=new Set(["color","text","verticalAlign","penStroke","elbowArrow","arcArrow","shape"]),a=d.computed(()=>{const c=[];for(const u of s.value){const f=`button:${u}`;!i.has(u)&&e[f]&&c.push(u)}return c});function l(){n()}return d.onUnmounted(()=>{n()}),(c,u)=>(d.openBlock(),d.createElementBlock("div",{class:"wov-floating-menu-bar",onMouseleave:l},[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(a.value,f=>d.renderSlot(c.$slots,`button:${f}`,{key:f,entityIds:d.unref(o)})),128)),d.renderSlot(c.$slots,"button:color",{entityIds:d.unref(o)},()=>[d.unref(s).has("color")?(d.openBlock(),d.createBlock(ak,{key:0,entityIds:d.unref(o)},null,8,["entityIds"])):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:shape",{entityIds:d.unref(o)},()=>[d.unref(s).has("shape")?(d.openBlock(),d.createElementBlock(d.Fragment,{key:0},[d.createVNode(dk,{entityIds:d.unref(o)},null,8,["entityIds"]),d.createVNode(ck,{entityIds:d.unref(o)},null,8,["entityIds"]),d.createVNode(uk,{entityIds:d.unref(o)},null,8,["entityIds"])],64)):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:penStroke",{entityIds:d.unref(o)},()=>[d.unref(s).has("penStroke")?(d.openBlock(),d.createBlock(lk,{key:0,entityIds:d.unref(o)},null,8,["entityIds"])):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:arrowThickness",{entityIds:d.unref(o)},()=>[d.unref(s).has("elbowArrow")||d.unref(s).has("arcArrow")?(d.openBlock(),d.createBlock(ok,{key:0,entityIds:d.unref(o)},null,8,["entityIds"])):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:arrowHeadStart",{entityIds:d.unref(o)},()=>[d.unref(s).has("elbowArrow")||d.unref(s).has("arcArrow")?(d.openBlock(),d.createBlock(Ld,{key:0,entityIds:d.unref(o),side:"start"},null,8,["entityIds"])):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:arrowHeadEnd",{entityIds:d.unref(o)},()=>[d.unref(s).has("elbowArrow")||d.unref(s).has("arcArrow")?(d.openBlock(),d.createBlock(Ld,{key:0,entityIds:d.unref(o),side:"end"},null,8,["entityIds"])):d.createCommentVNode("",!0)]),d.renderSlot(c.$slots,"button:text",{entityIds:d.unref(o)},()=>[d.unref(s).has("text")?(d.openBlock(),d.createBlock(QI,{key:0,entityIds:d.unref(o),showVerticalAlign:d.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])):d.createCommentVNode("",!0)]),d.createVNode(Fd)],32))}}),eP={class:"wov-floating-menu-inner"},kk=d.defineComponent({__name:"FloatingMenu",setup(t){const e=d.inject(pt),n=_0([h.Block,Ie]),r=Ze(h.Camera),o=Ze(h.Screen),s=Ze(Tt),i=Bs(),a=d.computed(()=>n.value.map(S=>S.entityId)),l=d.computed(()=>{const S=e==null?void 0:e.getEditor();if(!S||n.value.length===0)return new Set;const C=n.value.map(_=>({tag:_.block.value.tag}));return gk(S,C)});d.provide(gh,{selectedIds:a,commonComponents:l});const c=[0,0,0,0];function u(...S){let C=1/0,_=1/0,x=-1/0,T=-1/0,N=!1;for(const I of S){if(!I)continue;const V=I.getBoundingClientRect();V.width<=0||(N=!0,C=Math.min(C,V.left),_=Math.min(_,V.top),x=Math.max(x,V.right),T=Math.max(T,V.bottom))}return N?{x:C,y:_,left:C,top:_,right:x,bottom:T,width:x-C,height:T-_,toJSON:()=>({})}:null}const f=d.computed(()=>{if(n.value.length===0)return null;const S=r.value;if(!S)return null;let C=null;for(const _ of n.value){const x=_.block.value;E.Rect.getAabb(x.position,x.size,x.rotateZ,c),E.Aabb.translate(c,[-S.left,-S.top]),E.Aabb.scale(c,S.zoom),C===null?C=E.Aabb.clone(c):E.Aabb.union(C,c)}return C}),p=d.inject("containerRef"),m=d.computed(()=>{const S=p==null?void 0:p.value;if(!S)return null;r.value,i.updateCounter.value;const C=i.blockElement.value,_=i.textElement.value,x=u(C,_);if(x)return{getBoundingClientRect:()=>x};const T=f.value;if(!T)return null;const N=S.getBoundingClientRect();return{getBoundingClientRect(){return{x:N.left+T[0],y:N.top+T[1],width:T[2]-T[0],height:T[3]-T[1],top:N.top+T[1],left:N.left+T[0],right:N.left+T[2],bottom:N.top+T[3]}}}}),g=d.ref(null),y={name:"clampToViewport",fn({y:S,rects:C}){const T=window.innerHeight-C.floating.height-8;return{y:Math.max(8,Math.min(S,T))}}},{floatingStyles:k}=Pa(m,g,{placement:"top",middleware:[Ba(12),Ia({fallbackPlacements:["bottom"]}),Oa({padding:8}),y]}),w=d.computed(()=>{const S=f.value,C=o.value;return!S||!C?!0:S[2]<0||S[0]>C.width||S[3]<0||S[1]>C.height}),v=[de.Dragging,de.SelectionBoxDragging],b=d.computed(()=>n.value.length>0&&!w.value&&!v.includes(s.value.state));return(S,C)=>(d.openBlock(),d.createBlock(d.Transition,{name:"wov-fade"},{default:d.withCtx(()=>[b.value?(d.openBlock(),d.createElementBlock("div",{key:0,ref_key:"floatingRef",ref:g,class:"wov-floating-menu",style:d.normalizeStyle(d.unref(k))},[d.createElementVNode("div",eP,[d.renderSlot(S.$slots,"default",{},()=>[d.createVNode(yk)])])],4)):d.createCommentVNode("",!0)]),_:3}))}}),tP={key:0,class:"wov-loading-overlay"},nP={class:"wov-loading-spinner"},wk=d.defineComponent({__name:"LoadingOverlay",props:{isLoading:{type:Boolean}},setup(t){const e=d.ref("|"),n=["|","/","-","\\"];let r=null;return d.onMounted(()=>{r=setInterval(()=>{const o=n.indexOf(e.value);e.value=n[(o+1)%n.length]},100)}),d.onUnmounted(()=>{r!==null&&clearInterval(r)}),(o,s)=>(d.openBlock(),d.createBlock(d.Transition,{name:"wov-loading-fade"},{default:d.withCtx(()=>[t.isLoading?(d.openBlock(),d.createElementBlock("div",tP,[d.createElementVNode("div",nP,d.toDisplayString(e.value),1)])):d.createCommentVNode("",!0)]),_:1}))}}),rP={class:"wov-action-bar"},oP=d.defineComponent({__name:"ActionBar",setup(t){const{getEditor:e}=Ee(),n=d.inject(pt),r=d.ref(!1),o=d.ref(!1);if(n){const l=n.registerTickCallback(c=>{const{store:u}=h.getPluginResources(c,"editing");r.value=u.canUndo(),o.value=u.canRedo()});d.onUnmounted(l)}function s(){const l=e();l==null||l.command(h.Undo)}function i(){const l=e();l==null||l.command(h.Redo)}function a(){const l=e();l==null||l.command(yl)}return(l,c)=>(d.openBlock(),d.createElementBlock("div",rP,[d.createElementVNode("button",{class:"wov-action-button",onClick:s,"aria-label":"Undo"},[...c[0]||(c[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-undo-icon lucide-undo"},[d.createElementVNode("path",{d:"M3 7v6h6"}),d.createElementVNode("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})],-1)])]),d.createElementVNode("button",{class:"wov-action-button",onClick:i,"aria-label":"Redo"},[...c[1]||(c[1]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-redo-icon lucide-redo"},[d.createElementVNode("path",{d:"M21 7v6h-6"}),d.createElementVNode("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"})],-1)])]),d.createElementVNode("button",{class:"wov-action-button",onClick:a,"aria-label":"Delete"},[...c[2]||(c[2]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-trash-icon lucide-trash"},[d.createElementVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}),d.createElementVNode("path",{d:"M3 6h18"}),d.createElementVNode("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})],-1)])])]))}}),Qt=d.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},cursor:{default:"crosshair"}},setup(t){const e=t,n=d.inject(Ul);if(!n)throw new Error("ToolbarButton must be used within a Toolbar component");const r=n,o=d.ref(null),{show:s,hide:i}=Un(),a=d.computed(()=>r.activeTool.value===e.name);function l(){r.setTool(e.name,e.placementSnapshot,e.cursor)}function c(){r.onToolPointerDown(e.name,e.dragOutSnapshot)}function u(){r.onToolPointerUp()}function f(){e.tooltip&&o.value&&s(e.tooltip,o.value)}function p(){i()}return(m,g)=>(d.openBlock(),d.createElementBlock("button",{ref_key:"buttonRef",ref:o,class:d.normalizeClass(["wov-toolbar-button",{selected:a.value}]),onClick:l,onPointerdown:c,onPointerup:u,onMouseenter:f,onMouseleave:p},[d.renderSlot(m.$slots,"default")],34))}}),sP='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.35 4.75" width="20" height="20"><defs><style>.cls-1{stroke:#fff;stroke-miterlimit:10;stroke-width:.25px;}</style></defs><path class="cls-1" d="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z"/></svg>',iP='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.08 4.75" width="24" height="24"><defs><style>.cls-1{fill:#fff;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:.25px;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;stroke-width:.51px;}</style></defs><path class="cls-1" d="M.89,2.25v.63M.89,2.25V.75c0-.21.17-.38.38-.38s.38.17.38.38M.89,2.25c0-.21-.17-.37-.38-.37s-.38.17-.38.37v.5c0,1.04.86,1.87,1.91,1.87s1.91-.84,1.91-1.87v-1.25c0-.21-.17-.38-.38-.38s-.38.17.38.38M1.66.75v1.38M1.66.75v-.25c0-.21.17-.38.38-.38s.38.17.38.38v.25M2.42.75v1.38M2.42.75c0-.21.17-.38.38-.38s.38.17.38.38v.75M3.19,1.5v.63"/><line class="cls-2" x1="2.8" y1=".77" x2="2.8" y2="2.03"/><line class="cls-2" x1="2.04" y1=".64" x2="2.04" y2="2.02"/><line class="cls-2" x1="1.27" y1=".84" x2="1.27" y2="2.29"/></svg>',aP='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 8v-2a2 2 0 0 1 2 -2h2" /><path d="M4 16v2a2 2 0 0 0 2 2h2" /><path d="M16 4h2a2 2 0 0 1 2 2v2" /><path d="M16 20h2a2 2 0 0 0 2 -2v-2" /><path d="M9 12l6 0" /><path d="M12 9l0 6" /></svg>',Ir={Select:"select",Hand:"hand",Crosshair:"crosshair"},vk={[Ir.Select]:{makeSvg:()=>sP,hotspot:[1,0],rotationOffset:0},[Ir.Hand]:{makeSvg:()=>iP,hotspot:[12,12],rotationOffset:0},[Ir.Crosshair]:{makeSvg:()=>aP,hotspot:[12,12],rotationOffset:0}},lP={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},bk=d.defineComponent({__name:"SelectTool",setup(t){const{nextEditorTick:e}=Ee(),{activeTool:n}=Od();return d.watch(n,(r,o)=>{o==="select"&&e(s=>{Xr.spawn(s)})}),(r,o)=>(d.openBlock(),d.createBlock(Qt,{name:"select",tooltip:"Select",cursor:d.unref(Ir).Select},{default:d.withCtx(()=>[(d.openBlock(),d.createElementBlock("svg",lP,[...o[0]||(o[0]=[d.createElementVNode("g",{transform:"matrix(4.21053,0,0,4.21053,0.842105,0)"},[d.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-width":"0.5",d:"M2.39,2.88C2.38,2.885 2.34,2.9 2.33,2.91C2.32,2.91 2.298,2.939 2.28,2.97L1.51,4.41C1.44,4.54 1.41,4.6 1.37,4.61C1.34,4.62 1.3,4.61 1.27,4.6C1.24,4.58 1.22,4.51 1.18,4.37L0.16,0.41C0.13,0.28 0.11,0.22 0.13,0.18C0.15,0.15 0.17,0.13 0.21,0.12C0.25,0.12 0.31,0.14 0.42,0.2L4.01,2.14C4.14,2.21 4.2,2.24 4.21,2.28C4.22,2.31 4.21,2.35 4.2,2.38C4.18,2.41 4.11,2.43 3.97,2.47L2.39,2.88Z"})],-1)])]))]),_:1},8,["cursor"]))}}),Sk=d.defineComponent({__name:"HandTool",setup(t){return(e,n)=>(d.openBlock(),d.createBlock(Qt,{name:"hand",tooltip:"Hand",cursor:d.unref(Ir).Hand},{default:d.withCtx(()=>[...n[0]||(n[0]=[d.createElementVNode("svg",{viewBox:"0 0 20.56 24"},[d.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4.47,11.39v3.18M4.47,11.39V3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92M4.47,11.39c0-1.06-.86-1.87-1.92-1.87s-1.92.86-1.92,1.87v2.53c0,5.25,4.35,9.45,9.65,9.45s9.65-4.24,9.65-9.45v-6.32c0-1.06-.86-1.92-1.92-1.92s-1.92.86-1.92,1.92M8.36,3.81v6.97M8.36,3.81v-1.26c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v1.26M12.2,3.81v6.97M12.2,3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v3.79M16.09,7.6v3.18"})],-1)])]),_:1},8,["cursor"]))}}),Ck=d.defineComponent({__name:"StickyNoteTool",setup(t){const e=JSON.stringify({block:{tag:"sticky-note",size:[200,200]},color:{red:255,green:242,blue:117},text:{defaultAlignment:h.TextAlignment.Center},verticalAlign:{value:h.VerticalAlignment.Center}});return(n,r)=>(d.openBlock(),d.createBlock(Qt,{name:"sticky-note",tooltip:"Sticky Note","drag-out-snapshot":d.unref(e),"placement-snapshot":d.unref(e)},{default:d.withCtx(()=>[...r[0]||(r[0]=[d.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[d.createElementVNode("path",{d:"M4 4h12v12H4z"}),d.createElementVNode("path",{d:"M7 8h6M7 11h4"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),xk=d.defineComponent({__name:"ShapeTool",setup(t){const e=JSON.stringify({block:{tag:"shape",size:[200,200]},shape:{kind:"rectangle",strokeKind:h.StrokeKind.Solid,strokeWidth:2,strokeRed:0,strokeGreen:0,strokeBlue:0,strokeAlpha:255,fillRed:255,fillGreen:255,fillBlue:255,fillAlpha:0},text:{defaultAlignment:h.TextAlignment.Center},verticalAlign:{value:h.VerticalAlignment.Center}});return(n,r)=>(d.openBlock(),d.createBlock(Qt,{name:"shape",tooltip:"Shape","drag-out-snapshot":d.unref(e),"placement-snapshot":d.unref(e)},{default:d.withCtx(()=>[...r[0]||(r[0]=[d.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[d.createElementVNode("rect",{x:"3",y:"3",width:"14",height:"14",rx:"2"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),_k=d.defineComponent({__name:"EraserTool",setup(t){return(e,n)=>(d.openBlock(),d.createBlock(Qt,{name:"eraser",tooltip:"Eraser"},{default:d.withCtx(()=>[...n[0]||(n[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor"},[d.createElementVNode("path",{d:"M210.5 480L333.5 480L398.8 414.7L225.3 241.2L98.6 367.9L210.6 479.9zM256 544L210.5 544C193.5 544 177.2 537.3 165.2 525.3L49 409C38.1 398.1 32 383.4 32 368C32 352.6 38.1 337.9 49 327L295 81C305.9 70.1 320.6 64 336 64C351.4 64 366.1 70.1 377 81L559 263C569.9 273.9 576 288.6 576 304C576 319.4 569.9 334.1 559 345L424 480L544 480C561.7 480 576 494.3 576 512C576 529.7 561.7 544 544 544L256 544z"})],-1)])]),_:1}))}}),Ek=d.defineComponent({__name:"PenTool",setup(t){return(e,n)=>(d.openBlock(),d.createBlock(Qt,{name:"pen",tooltip:"Pen"},{default:d.withCtx(()=>[...n[0]||(n[0]=[d.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[d.createElementVNode("path",{d:"M13.586 3.586a2 2 0 1 1 2.828 2.828l-8.793 8.793-3.536.707.707-3.536 8.794-8.792Z","stroke-linecap":"round","stroke-linejoin":"round"}),d.createElementVNode("path",{d:"M12 5l3 3","stroke-linecap":"round"})],-1)])]),_:1}))}}),Tk=d.defineComponent({__name:"TextTool",setup(t){const e=JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24}}),n=JSON.stringify({block:{tag:"text",size:[36,29]},text:{content:"text",constrainWidth:!1,fontSizePx:24}});return(r,o)=>(d.openBlock(),d.createBlock(Qt,{name:"text",tooltip:"Text","drag-out-snapshot":d.unref(n),"placement-snapshot":d.unref(e)},{default:d.withCtx(()=>[...o[0]||(o[0]=[d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-type-icon lucide-type"},[d.createElementVNode("path",{d:"M12 4v16"}),d.createElementVNode("path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}),d.createElementVNode("path",{d:"M9 20h6"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Mk=d.defineComponent({__name:"ElbowArrowTool",setup(t){const e=JSON.stringify({block:{tag:"elbow-arrow",size:[200,200]},elbowArrow:{points:[0,0,.5,0,.5,1,1,1],pointCount:4,startArrowHead:pe.None,endArrowHead:pe.V},connector:{}});return(n,r)=>(d.openBlock(),d.createBlock(Qt,{name:"elbow-arrow",tooltip:"Elbow Arrow",cursor:"crosshair","drag-out-snapshot":d.unref(e)},{default:d.withCtx(()=>[...r[0]||(r[0]=[d.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[d.createElementVNode("path",{d:"M4 6 L10 6 L10 14 L16 14"}),d.createElementVNode("path",{d:"M13 11 L16 14 L13 17"})],-1)])]),_:1},8,["drag-out-snapshot"]))}}),Ak=d.defineComponent({__name:"ImageTool",setup(t){const{nextEditorTick:e}=Ee(),{show:n,hide:r}=Un(),{setTool:o}=Od(),{createImageBlock:s}=x0(),i=d.ref(null),a=d.ref(null);function l(){var p;(p=a.value)==null||p.click()}async function c(p){var S;const m=p.target,g=(S=m.files)==null?void 0:S[0];if(!g)return;if(m.value="",!g.type.startsWith("image/")){console.warn("Selected file is not an image");return}const y=await e(),k=h.Camera.read(y),w=h.Screen.read(y),v=k.left+w.width/k.zoom/2,b=k.top+w.height/k.zoom/2;await s(g,v,b),o("select",void 0,Ir.Select)}function u(){i.value&&n("Image",i.value)}function f(){r()}return(p,m)=>(d.openBlock(),d.createElementBlock("button",{ref_key:"buttonRef",ref:i,class:"wov-toolbar-button",onClick:l,onMouseenter:u,onMouseleave:f},[m[0]||(m[0]=d.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[d.createElementVNode("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),d.createElementVNode("circle",{cx:"9",cy:"9",r:"2"}),d.createElementVNode("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})],-1)),d.createElementVNode("input",{ref_key:"fileInputRef",ref:a,type:"file",accept:"image/*",style:{display:"none"},onChange:c},null,544)],544))}}),cP={class:"wov-toolbar-container"},Nk=d.defineComponent({__name:"Toolbar",setup(t){const e=d.useSlots(),{reset:n}=Un(),{nextEditorTick:r}=Ee(),o=d.ref(null),s=d.ref(null),i=Ze(h.Controls),a=d.computed(()=>i.value.leftMouseTool),l=[bk,Sk,Tk,Ak,xk,Mk,Ck,Ek,_k],c=d.inject("containerRef"),u=d.ref(null),f=d.ref(!1),p=d.ref(null),m=d.ref(null),g=d.ref(1/0),y=d.ref(0),k=d.ref([]),w=d.ref(8),v=d.ref(48),{width:b}=fk(c);function S(){return p.value?Array.from(p.value.children).filter(j=>!j.classList.contains("wov-overflow-button")&&!j.classList.contains("wov-menu-tooltip")):[]}function C(){var fe;const j=S();if(j.length===0)return;y.value=j.length;const q=getComputedStyle(p.value);w.value=parseFloat(q.gap)||8;const te=((fe=m.value)==null?void 0:fe.offsetWidth)||40;v.value=te+w.value,k.value=j.map(ce=>ce.offsetWidth)}function _(){if(k.value.length===0)return;const te=b.value-40-20,fe=w.value,ce=v.value;let Se=0,Dt=0;for(let gn=0;gn<k.value.length;gn++){const Dr=k.value[gn],qn=Se>0?Dr+fe:Dr,Gn=k.value.length-gn-1>0?ce:0;if(Se+qn+Gn<=te)Se+=qn,Dt++;else break}g.value=Math.max(1,Dt)}d.watch(b,()=>{k.value.length>0&&_()}),d.onMounted(()=>{d.nextTick(()=>{C(),_()})});const x=d.computed(()=>g.value<y.value);d.watchEffect(()=>{S().forEach((q,te)=>{q.style.display=te<g.value?"":"none"})}),d.watchEffect(()=>{if(!u.value)return;Array.from(u.value.children).forEach((q,te)=>{q.style.display=te>=g.value?"":"none"})});const{floatingStyles:T}=Pa(m,u,{placement:"top",middleware:[Ba(16),Ia(),Oa({padding:8})],whileElementsMounted:ek});function N(){f.value=!f.value}function I(){f.value=!1}function V(j){const q=j.target;m.value&&!m.value.contains(q)&&u.value&&!u.value.contains(q)&&I()}d.watch(f,j=>{j?document.addEventListener("click",V,!0):document.removeEventListener("click",V,!0)}),d.watch(x,j=>{j||I()});function K(j,q,te){s.value=q??null,r(fe=>{const ce=h.Controls.write(fe);ce.leftMouseTool=j,ce.heldSnapshot=q??"",te&&h.Cursor.setCursor(fe,te)})}function M(j){r(q=>{const te=h.Controls.write(q);te.leftMouseTool="drag-out",te.heldSnapshot=j})}function $(j,q){o.value=j,s.value=q??null}function Z(){o.value=null,s.value=null}function ae(){n(),o.value&&s.value&&M(s.value),o.value=null,s.value=null}const X={activeTool:a,heldTool:o,setTool:K,dragOutTool:M,onToolPointerDown:$,onToolPointerUp:Z};return d.provide(Ul,X),(j,q)=>(d.openBlock(),d.createElementBlock("div",cP,[d.createVNode(oP),d.createElementVNode("div",{ref_key:"toolsContainerRef",ref:p,class:"wov-toolbar",onMouseleave:ae},[d.unref(e).default?d.renderSlot(j.$slots,"default",{key:0}):(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},d.renderList(l,(te,fe)=>d.createVNode(d.resolveDynamicComponent(te),{key:fe})),64)),x.value?(d.openBlock(),d.createElementBlock("button",{key:2,ref_key:"overflowBtnRef",ref:m,class:d.normalizeClass(["wov-toolbar-button wov-overflow-button",{"menu-open":f.value}]),onClick:N},[...q[0]||(q[0]=[d.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[d.createElementVNode("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),d.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"})],-1)])],2)):d.createCommentVNode("",!0),d.createVNode(Fd)],544),d.unref(c)?(d.openBlock(),d.createBlock(d.Teleport,{key:0,to:d.unref(c)},[f.value&&x.value?(d.openBlock(),d.createElementBlock("div",{key:0,ref_key:"overflowMenuRef",ref:u,class:"wov-toolbar-overflow-menu",style:d.normalizeStyle(d.unref(T))},[d.unref(e).default?d.renderSlot(j.$slots,"default",{key:0}):(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},d.renderList(l,(te,fe)=>d.createVNode(d.resolveDynamicComponent(te),{key:fe})),64))],4)):d.createCommentVNode("",!0)],8,["to"])):d.createCommentVNode("",!0)]))}}),dP=d.defineComponent({__name:"ArcArrowTool",setup(t){return(e,n)=>(d.openBlock(),d.createBlock(Qt,{name:"arc-arrow",tooltip:"Arc Arrow",cursor:"crosshair"},{default:d.withCtx(()=>[...n[0]||(n[0]=[d.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[d.createElementVNode("path",{d:"M4 14 Q 10 4, 16 14"}),d.createElementVNode("path",{d:"M13 11 L16 14 L12.5 15.5"})],-1)])]),_:1}))}}),uP={class:"wov-user-presence-avatars"},fP=["src","alt"],hP={class:"wov-user-presence-list"},pP=["src","alt"],mP={class:"wov-user-presence-name"},gP=4,Bk=d.defineComponent({__name:"UserPresence",props:{users:{}},setup(t){const e=t,n=d.ref(!1),r=d.ref(null);AI(r,()=>{n.value=!1});function o(a){if(!a)return"?";const l=a.trim().split(/\s+/);return l.length>=2?(l[0][0]+l[1][0]).toUpperCase():a.slice(0,2).toUpperCase()}const s=d.computed(()=>e.users.map(a=>({sessionId:a.sessionId,name:a.name,color:a.color,avatar:a.avatar,initials:o(a.name)}))),i=d.computed(()=>s.value.slice(0,gP));return(a,l)=>t.users.length>1?(d.openBlock(),d.createElementBlock("div",{key:0,ref_key:"containerRef",ref:r,class:"wov-user-presence"},[d.createElementVNode("button",{class:d.normalizeClass(["wov-user-presence-trigger",{"is-open":n.value}]),onClick:l[0]||(l[0]=c=>n.value=!n.value)},[d.createElementVNode("div",uP,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(i.value,c=>(d.openBlock(),d.createElementBlock("div",{key:c.sessionId,class:"wov-user-avatar",style:d.normalizeStyle({backgroundColor:c.avatar?"transparent":c.color})},[c.avatar?(d.openBlock(),d.createElementBlock("img",{key:0,src:c.avatar,alt:c.name,class:"wov-user-avatar-img"},null,8,fP)):(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},[d.createTextVNode(d.toDisplayString(c.initials),1)],64))],4))),128))])],2),n.value?(d.openBlock(),d.createElementBlock("div",{key:0,class:"wov-user-presence-dropdown",onWheel:l[1]||(l[1]=d.withModifiers(()=>{},["stop"]))},[d.createElementVNode("div",hP,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(s.value,c=>(d.openBlock(),d.createElementBlock("div",{key:c.sessionId,class:"wov-user-presence-item"},[d.createElementVNode("div",{class:"wov-user-avatar wov-user-avatar-small",style:d.normalizeStyle({backgroundColor:c.avatar?"transparent":c.color})},[c.avatar?(d.openBlock(),d.createElementBlock("img",{key:0,src:c.avatar,alt:c.name,class:"wov-user-avatar-img"},null,8,pP)):(d.openBlock(),d.createElementBlock(d.Fragment,{key:1},[d.createTextVNode(d.toDisplayString(c.initials),1)],64))],4),d.createElementVNode("span",mP,d.toDisplayString(c.name),1)]))),128))])],32)):d.createCommentVNode("",!0)],512)):d.createCommentVNode("",!0)}}),Gd=(t,e)=>e.some(n=>t instanceof n);let Ok,Ik;function yP(){return Ok||(Ok=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function kP(){return Ik||(Ik=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Yd=new WeakMap,Xd=new WeakMap,Va=new WeakMap;function wP(t){const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("success",s),t.removeEventListener("error",i)},s=()=>{n(Pr(t.result)),o()},i=()=>{r(t.error),o()};t.addEventListener("success",s),t.addEventListener("error",i)});return Va.set(e,t),e}function vP(t){if(Yd.has(t))return;const e=new Promise((n,r)=>{const o=()=>{t.removeEventListener("complete",s),t.removeEventListener("error",i),t.removeEventListener("abort",i)},s=()=>{n(),o()},i=()=>{r(t.error||new DOMException("AbortError","AbortError")),o()};t.addEventListener("complete",s),t.addEventListener("error",i),t.addEventListener("abort",i)});Yd.set(t,e)}let Qd={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return Yd.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Pr(t[e])},set(t,e,n){return t[e]=n,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function Pk(t){Qd=t(Qd)}function bP(t){return kP().includes(t)?function(...e){return t.apply(eu(this),e),Pr(this.request)}:function(...e){return Pr(t.apply(eu(this),e))}}function SP(t){return typeof t=="function"?bP(t):(t instanceof IDBTransaction&&vP(t),Gd(t,yP())?new Proxy(t,Qd):t)}function Pr(t){if(t instanceof IDBRequest)return wP(t);if(Xd.has(t))return Xd.get(t);const e=SP(t);return e!==t&&(Xd.set(t,e),Va.set(e,t)),e}const eu=t=>Va.get(t);function CP(t,e,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(t,e),a=Pr(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Pr(i.result),l.oldVersion,l.newVersion,Pr(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}const xP=["get","getKey","getAll","getAllKeys","count"],_P=["put","add","delete","clear"],tu=new Map;function Rk(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(tu.get(e))return tu.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,o=_P.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||xP.includes(n)))return;const s=async function(i,...a){const l=this.transaction(i,o?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),o&&l.done]))[0]};return tu.set(e,s),s}Pk(t=>({...t,get:(e,n,r)=>Rk(e,n)||t.get(e,n,r),has:(e,n)=>!!Rk(e,n)||t.has(e,n)}));const EP=["continue","continuePrimaryKey","advance"],Dk={},nu=new WeakMap,zk=new WeakMap,TP={get(t,e){if(!EP.includes(e))return t[e];let n=Dk[e];return n||(n=Dk[e]=function(...r){nu.set(this,zk.get(this)[e](...r))}),n}};async function*MP(...t){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...t)),!e)return;e=e;const n=new Proxy(e,TP);for(zk.set(n,e),Va.set(n,eu(e));e;)yield n,e=await(nu.get(n)||e.continue()),nu.delete(n)}function $k(t,e){return e===Symbol.asyncIterator&&Gd(t,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&Gd(t,[IDBIndex,IDBObjectStore])}Pk(t=>({...t,get(e,n,r){return $k(e,n)?MP:t.get(e,n,r)},has(e,n){return $k(e,n)||t.has(e,n)}}));async function ru(t,e){const n=await CP(t,1,{upgrade(r){r.objectStoreNames.contains(e)||r.createObjectStore(e)}});return new AP(n,e)}var AP=class{constructor(t,e){this.db=t,this.storeName=e}async get(t){return this.db.get(this.storeName,t)}async put(t,e){await this.db.put(this.storeName,e,t)}async delete(t){await this.db.delete(this.storeName,t)}async getAllEntries(){const e=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName),n=await e.getAllKeys(),r=await e.getAll(),o=[];for(let s=0;s<n.length;s++)o.push([n[s],r[s]]);return o}async clear(){const t=this.db.transaction(this.storeName,"readwrite");t.objectStore(this.storeName).clear(),await t.done}close(){this.db.close()}},NP=class{constructor(t){this.jobsStore=null,this.binariesStore=null,this.blobUrls=new Map,this.uploading=new Set,this.uploadPromises=new Map,this.provider=t.provider,this.documentId=t.documentId,this.maxRetries=t.provider.maxRetries??3,this.retryDelay=t.provider.retryDelay??5e3}async init(){const t=`wovencanvas-assets-${this.documentId}`,[e,n]=await Promise.all([ru(`${t}-jobs`,"jobs"),ru(`${t}-binaries`,"binaries")]);this.jobsStore=e,this.binariesStore=n}async upload(t,e,n){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");await this.binariesStore.put(t,e);const r={identifier:t,metadata:n,createdAt:Date.now(),retryCount:0};await this.jobsStore.put(t,r);const o=URL.createObjectURL(e);return this.blobUrls.set(t,o),new Promise((s,i)=>{this.uploadPromises.set(t,{resolve:s,reject:i}),this.startUpload(t)})}async getDisplayUrl(t){const e=this.blobUrls.get(t);if(e)return e;try{return await this.provider.resolveUrl(t)}catch(n){return console.error(`Failed to resolve URL for ${t}:`,n),null}}async resumePendingUploads(){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const t=await this.jobsStore.getAllEntries();for(const[e]of t){const n=await this.binariesStore.get(e);if(n){const r=URL.createObjectURL(n);this.blobUrls.set(e,r)}this.startUpload(e)}}hasPendingUpload(t){return this.blobUrls.has(t)}isUploading(t){return this.uploading.has(t)}async cancelUpload(t){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(t);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(t)),await this.jobsStore.delete(t),await this.binariesStore.delete(t),this.uploading.delete(t);const n=this.uploadPromises.get(t);n&&(n.reject(new Error("Upload cancelled")),this.uploadPromises.delete(t))}close(){var t,e;for(const n of this.blobUrls.values())URL.revokeObjectURL(n);this.blobUrls.clear(),(t=this.jobsStore)==null||t.close(),(e=this.binariesStore)==null||e.close(),this.jobsStore=null,this.binariesStore=null}async startUpload(t){if(!this.jobsStore||!this.binariesStore||this.uploading.has(t))return;this.uploading.add(t);const e=await this.jobsStore.get(t),n=await this.binariesStore.get(t);if(!e||!n){this.uploading.delete(t);return}try{await this.provider.upload(n,t,e.metadata),await this.onUploadSuccess(t)}catch(r){await this.onUploadError(t,e,r)}}async onUploadSuccess(t){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(t);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(t)),await this.jobsStore.delete(t),await this.binariesStore.delete(t),this.uploading.delete(t);const n=this.uploadPromises.get(t);n&&(n.resolve(),this.uploadPromises.delete(t))}async onUploadError(t,e,n){if(!this.jobsStore)return;const r=n instanceof Error?n.message:"Unknown error";if(console.error(`Upload failed for ${t}:`,r),this.uploading.delete(t),e.retryCount<this.maxRetries){const o={...e,retryCount:e.retryCount+1};await this.jobsStore.put(t,o),setTimeout(()=>{this.startUpload(t)},this.retryDelay*2**e.retryCount)}else{const o=this.uploadPromises.get(t);o&&(o.reject(new Error(r)),this.uploadPromises.delete(t))}}},BP="wovencanvas-assets",OP="blobs",IP=class{constructor(){this.store=null,this.initPromise=null,this.maxRetries=3,this.retryDelay=5e3}async upload(t,e,n){return await(await this.getStore()).put(e,{blob:t,metadata:n}),{}}async resolveUrl(t){const n=await(await this.getStore()).get(t);if(!n)throw new Error(`Asset not found: ${t}`);return URL.createObjectURL(n.blob)}async delete(t){await(await this.getStore()).delete(t)}close(){this.store&&(this.store.close(),this.store=null,this.initPromise=null)}getStore(){return this.store?Promise.resolve(this.store):(this.initPromise||(this.initPromise=ru(BP,OP).then(t=>(this.store=t,t))),this.initPromise)}},Vk=rn.object({minZoom:rn.number().default(.05),maxZoom:rn.number().default(2.7)});Vk.parse({});var Rs=h.defineEditorState("panState",{state:h.field.string().max(16).default("idle"),panStartX:h.field.float64().default(0),panStartY:h.field.float64().default(0),velocityX:h.field.float64().default(0),velocityY:h.field.float64().default(0),targetX:h.field.float64().default(0),targetY:h.field.float64().default(0),expectedLeft:h.field.float64().default(0),expectedTop:h.field.float64().default(0)}),Rr=h.defineCanvasSingleton({name:"pinchState"},{active:h.field.boolean().default(!1),prevDistance:h.field.float64().default(0),prevCenter:h.field.tuple(h.field.float64(),2).default([0,0])}),mn=[0,0],La=[0,0],Ds=[0,0],ou=[0,0],su=[0,0];function PP(t,e,n,r,o,s){r=Math.max(1e-4,r);const i=2/r,a=i*s,l=1/(1+a+.48*a*a+.235*a*a*a);E.Vec2.copy(mn,t),E.Vec2.sub(mn,e);const c=o*r,u=c*c,f=E.Vec2.lengthSq(mn);f>u&&E.Vec2.scale(mn,c/Math.sqrt(f)),E.Vec2.copy(La,t),E.Vec2.sub(La,mn),E.Vec2.set(Ds,(n[0]+i*mn[0])*s,(n[1]+i*mn[1])*s);const p=[(n[0]-i*Ds[0])*l,(n[1]-i*Ds[1])*l],m=[La[0]+(mn[0]+Ds[0])*l,La[1]+(mn[1]+Ds[1])*l];return E.Vec2.copy(ou,e),E.Vec2.sub(ou,t),E.Vec2.copy(su,m),E.Vec2.sub(su,e),E.Vec2.dot(ou,su)>0&&(m[0]=e[0],m[1]=e[1],p[0]=(m[0]-e[0])/s,p[1]=(m[1]-e[1])/s),{position:m,velocity:p}}var iu=.1,Lk=.1,RP=on({guards:{hasVelocity:({event:t})=>{if(t.type!=="pointerUp")return!1;const e=t.velocity;return Math.hypot(e[0],e[1])>Lk},isGlideComplete:({context:t})=>Math.hypot(t.velocityX,t.velocityY)<Lk,cameraWasMoved:({context:t,event:e})=>{const n=h.Camera.read(e.ctx);return n.left!==t.expectedLeft||n.top!==t.expectedTop},isEscapeKey:({event:t})=>t.key===h.Key.Escape},actions:{setDragStart:we({panStartX:({event:t})=>t.worldPosition[0],panStartY:({event:t})=>t.worldPosition[1]}),moveCamera:({context:t,event:e})=>{const n=e,{ctx:r}=n,o=n.worldPosition[0]-t.panStartX,s=n.worldPosition[1]-t.panStartY,i=h.Camera.write(r);i.left-=o,i.top-=s},startGlide:we(({event:t})=>{const e=t,{ctx:n}=e,r=h.Camera.read(n),o=e.cameraZoom,s=-e.velocity[0]/o,i=-e.velocity[1]/o;return{velocityX:s,velocityY:i,targetX:r.left+s*iu,targetY:r.top+i*iu,expectedLeft:r.left,expectedTop:r.top}}),animateGlide:we(({context:t,event:e})=>{const n=e,{ctx:r,delta:o}=n,s=h.Camera.read(r),{position:i,velocity:a}=PP([s.left,s.top],[t.targetX,t.targetY],[t.velocityX,t.velocityY],iu,Number.POSITIVE_INFINITY,o),l=h.Camera.write(r);return l.left=i[0],l.top=i[1],{velocityX:a[0],velocityY:a[1],expectedLeft:i[0],expectedTop:i[1]}}),resetContext:we({panStartX:0,panStartY:0,velocityX:0,velocityY:0,targetX:0,targetY:0,expectedLeft:0,expectedTop:0})}}).createMachine({id:"pan",initial:"idle",context:{panStartX:0,panStartY:0,velocityX:0,velocityY:0,targetX:0,targetY:0,expectedLeft:0,expectedTop:0},states:{idle:{on:{pointerDown:{actions:"setDragStart",target:"panning"}}},panning:{entry:"moveCamera",on:{pointerMove:{actions:"moveCamera"},pointerUp:[{guard:"hasVelocity",actions:"startGlide",target:"gliding"},{target:"idle"}],keyDown:{guard:"isEscapeKey",target:"idle"}}},gliding:{on:{frame:[{guard:"cameraWasMoved",actions:"resetContext",target:"idle"},{guard:"isGlideComplete",actions:"resetContext",target:"idle"},{actions:"animateGlide"}],pointerDown:{actions:["resetContext","setDragStart"],target:"panning"}}}}}),DP=h.defineEditorSystem({phase:"input",priority:-100},t=>{const e=Rs.read(t).state;if(Rr.read(t).active){e!=="idle"&&Rs.copy(t,Rs.default());return}const r=h.Controls.getButtons(t,"hand"),s=[...h.getPointerInput(t,r)];e==="gliding"&&s.push(h.getFrameInput(t)),s.push(...h.getKeyboardInput(t,[h.Key.Escape])),s.length!==0&&Rs.run(t,RP,s)}),zP=h.defineQuery(t=>t.with(h.Pointer)),$P=h.defineEditorSystem({phase:"input",priority:-100},t=>{const e=h.getPluginResources(t,"controls"),n=zP.current(t),r=[];for(let g=0;g<n.length;g++){const y=n[g],k=h.Pointer.read(t,y);k.pointerType===h.PointerType.Touch&&r.push(k.position)}if(r.length!==2){if(Rr.read(t).active){const y=Rr.write(t);y.active=!1}return}const[o,s]=r,i=E.Vec2.distance(o,s),a=E.Vec2.midPoint(o,s),l=Rr.read(t);if(!l.active){const g=Rr.write(t);g.prevDistance=i,g.prevCenter=a,g.active=!0;return}const c=h.Camera.read(t),u=h.Screen.read(t);if(l.prevDistance>0&&i>0){const g=i/l.prevDistance;let y=c.zoom*g;y=Math.min(e.maxZoom,Math.max(e.minZoom,y));const k=u.width/c.zoom,w=u.height/c.zoom,v=u.width/y,b=u.height/y,S=v-k,C=b-w,_=a[0]/u.width,x=a[1]/u.height,T=h.Camera.write(t);T.left-=_*S,T.top-=x*C,T.zoom=y}const f=a[0]-l.prevCenter[0],p=a[1]-l.prevCenter[1];if(f!==0||p!==0){const g=h.Camera.write(t);g.left-=f/g.zoom,g.top-=p/g.zoom}const m=Rr.write(t);m.prevDistance=i,m.prevCenter=a}),VP=h.defineEditorSystem({phase:"input",priority:-100},t=>{const e=h.Keyboard.read(t);if(!h.Controls.wheelActive(t,"scroll",e.modDown))return;const r=h.getMouseInput(t).find(l=>l.type==="wheel");if(!r)return;const o=h.Camera.read(t),s=o.left+r.wheelDeltaX/o.zoom,i=o.top+r.wheelDeltaY/o.zoom,a=h.Camera.write(t);a.left=s,a.top=i}),LP=h.defineEditorSystem({phase:"input",priority:-100},t=>{const e=h.getPluginResources(t,"controls"),n=h.Keyboard.read(t);if(!h.Controls.wheelActive(t,"zoom",n.modDown))return;const o=h.getMouseInput(t).find(S=>S.type==="wheel");if(!o)return;const s=h.Camera.read(t),i=h.Screen.read(t),a=h.Mouse.read(t);let l=2**(-.8*o.wheelDeltaY/500)*s.zoom;l=Math.min(e.maxZoom,Math.max(e.minZoom,l));const c=i.width/s.zoom,u=i.height/s.zoom,f=i.width/l,p=i.height/l,m=f-c,g=p-u,y=a.position[0]/i.width,k=a.position[1]/i.height,w=s.left-y*m,v=s.top-k*g,b=h.Camera.write(t);b.left=w,b.top=v,b.zoom=l});function FP(t={}){return{name:"controls",resources:Vk.parse(t),singletons:[Rs,Rr],systems:[LP,VP,DP,$P]}}var jP=(t={})=>FP(t);const HP={class:"wov-selection-box"},WP=d.defineComponent({__name:"SelectionBox",setup(t){return(e,n)=>(d.openBlock(),d.createElementBlock("div",HP))}}),ZP={class:"wov-transform-box"},UP=d.defineComponent({__name:"TransformBox",setup(t){return(e,n)=>(d.openBlock(),d.createElementBlock("div",ZP))}}),KP={},JP={class:"wov-transform-handle"};function qP(t,e){return d.openBlock(),d.createElementBlock("div",JP)}const GP=ir(KP,[["render",qP]]),YP=d.defineComponent({__name:"StickyNote",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(t){const e=t,n=Pe(e.entityId,h.Color),r=Pe(e.entityId,h.VerticalAlign),o=d.ref(null),s={[h.VerticalAlignment.Top]:"flex-start",[h.VerticalAlignment.Center]:"center",[h.VerticalAlignment.Bottom]:"flex-end"},i=d.computed(()=>{var l;return{backgroundColor:n.value?`rgb(${n.value.red}, ${n.value.green}, ${n.value.blue})`:void 0,minHeight:`${e.block.size[0]}px`,alignItems:s[((l=r.value)==null?void 0:l.value)??h.VerticalAlignment.Top]}}),{handleEditEnd:a}=Bd({blockData:e,containerRef:o,minWidth:()=>e.block.size[0],minHeight:()=>e.block.size[0]});return(l,c)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:o,class:"wov-sticky-note",style:d.normalizeStyle(i.value)},[d.createVNode(wa,d.mergeProps(e,{"block-element":o.value,onEditEnd:d.unref(a)}),null,16,["block-element","onEditEnd"])],4))}}),Fa=at.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:h.field.string().default("").max(36)}),Fk=h.defineQuery(t=>t.with(h.Edited));function XP(t){var e;if(!t)return null;try{const n=JSON.parse(t);return(e=n.block)!=null&&e.tag?n:(console.warn("Block snapshot missing required tag:",n),null)}catch{return console.warn("Invalid block snapshot JSON:",t),null}}function QP(t,e,n){const r=h.getBlockDef(t,e.block.tag);if(!r)throw new Error(`Block placement: block definition for tag "${e.block.tag}" not found`);const o=e.block.size??[100,100],s=n[0]-o[0]/2,i=n[1]-o[1]/2,a=e.block.rank??h.RankBounds.genNext(t),l=h.createEntity(t);"synced"in e||h.addComponent(t,l,h.Synced,{id:crypto.randomUUID()});const c=Object.assign({},e.block,{position:[s,i],size:o,rank:a});h.addComponent(t,l,h.Block,c);for(const f of r.components)if(!(f.name in e))h.addComponent(t,l,f);else{const p=e[f.name];h.addComponent(t,l,f,p)}const{sessionId:u}=h.getResources(t);return h.addComponent(t,l,h.Held,{sessionId:u}),l}function jk(t,e,n,r,o){const s=QP(t,e,n),i=h.Block.read(t,s);if(h.canBlockEdit(t,e.block.tag)&&(h.addComponent(t,s,Ko,{}),o==="placement")){const{store:u}=h.getPluginResources(t,"editing"),f=u.createCheckpoint();if(f){const p=Fa.write(t);p.editedCheckpoint=f}}const a=Tt.write(t);a.state=o==="dragOut"?de.Dragging:de.Pointing,a.dragStart=n,a.draggedEntity=s,a.draggedEntityStart=i.position,a.pointingStartClient=r,a.pointingStartWorld=n,a.isCloning=!1;const l=h.Controls.write(t);l.leftMouseTool="select",l.heldSnapshot="";const c=h.Cursor.write(t);c.cursorKind="select",c.rotation=0}function eR(t){const e=Fa.read(t);if(e.editedCheckpoint){const n=e.editedCheckpoint;Fa.write(t).editedCheckpoint="";const{store:r}=h.getPluginResources(t,"editing");r.onSettled(()=>r.squashToCheckpoint(n),{frames:5})}}const tR=h.defineEditorSystem({phase:"capture"},t=>{Fk.removed(t).length>0&&Fk.current(t).length===0&&eR(t);const e=h.Controls.read(t);if(!e.heldSnapshot)return;const n=h.getPointerInput(t,[h.PointerButton.Left]);if(n.length===0)return;const r=XP(e.heldSnapshot);if(!r)return;if(e.leftMouseTool==="drag-out"){const s=n.find(i=>i.type==="pointerMove"&&!i.obscured);if(!s)return;jk(t,r,s.worldPosition,s.screenPosition,"dragOut")}else{const s=n.find(i=>i.type==="pointerDown"&&!i.obscured);if(!s)return;jk(t,r,s.worldPosition,s.screenPosition,"placement")}}),nR=h.defineEditorSystem({phase:"update"},t=>{const{store:e}=h.getPluginResources(t,"editing");h.on(t,h.Undo,()=>{e.canUndo()&&(bf(t),e.undo())}),h.on(t,h.Redo,()=>{e.canRedo()&&(bf(t),e.redo())})}),rR=[{name:"Figtree",displayName:"Figtree",url:"https://fonts.googleapis.com/css2?family=Figtree",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/Figtree.png"},{name:"Shantell Sans",displayName:"Shantell Sans",url:"https://fonts.googleapis.com/css2?family=Shantell+Sans",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/ShantellSans.png"},{name:"Courier Prime",displayName:"Courier Prime",url:"https://fonts.googleapis.com/css2?family=Courier+Prime",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/CourierPrime.png"},{name:"EB Garamond",displayName:"EB Garamond",url:"https://fonts.googleapis.com/css2?family=EB+Garamond",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/EBGaramond.png"}];function Hk(t){return{name:"editing",resources:{store:t.store},singletons:[Fa],systems:[tR,nR],cursors:vk,fonts:rR,keybinds:[{command:h.Undo.name,key:h.Key.Z,mod:!0},{command:h.Redo.name,key:h.Key.Y,mod:!0},{command:h.Redo.name,key:h.Key.Z,mod:!0,shift:!0}]}}const oR=d.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(t){const e=t,{nextEditorTick:n}=Ee(),{createImageBlock:r}=x0(),o=d.ref(!1);let s=0;const i=d.inject("containerRef");function a(v){var b;(b=v.dataTransfer)!=null&&b.types.some(S=>S==="Files"||S==="text/uri-list"||S==="text/html")&&(s++,s===1&&(o.value=!0))}function l(){s--,s===0&&(o.value=!1)}function c(){s=0,o.value=!1}d.onMounted(()=>{const v=i==null?void 0:i.value;v&&(v.addEventListener("dragenter",a),v.addEventListener("dragleave",l),v.addEventListener("drop",c))}),d.onUnmounted(()=>{const v=i==null?void 0:i.value;v&&(v.removeEventListener("dragenter",a),v.removeEventListener("dragleave",l),v.removeEventListener("drop",c))});function u(v){v.preventDefault(),v.dataTransfer&&(v.dataTransfer.dropEffect="copy")}function f(v){v.preventDefault()}function p(v){v.preventDefault()}async function m(v){if(v.preventDefault(),!v.dataTransfer)return;const b=v.clientX,S=v.clientY,C=Array.from(v.dataTransfer.files).filter(x=>x.type.startsWith("image/"));if(C.length>0){for(const x of C)await k(x,b,S);return}const _=g(v.dataTransfer);_&&await w(_,b,S)}function g(v){const b=v.getData("text/uri-list");if(b){const x=b.split(`
|
|
171
|
-
`).filter(T=>!T.startsWith("#")).find(T=>y(T));if(x)return x}const S=v.getData("text/html");if(S){const _=S.match(/<img[^>]+src=["']([^"']+)["']/i);if(_!=null&&_[1])return _[1]}const C=v.getData("text/plain");return C&&y(C)?C:null}function y(v){try{const S=new URL(v).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(S)||v.startsWith("data:image/"),!0}catch{return!1}}async function k(v,b,S){const C=await n(),_=h.Camera.read(C),x=h.Screen.read(C),T=_.left+(b-x.left)/_.zoom,N=_.top+(S-x.top)/_.zoom;await r(v,T,N,{maxSize:e.maxSize})}async function w(v,b,S){try{const C=await fetch(v);if(!C.ok){console.warn("Failed to fetch image from URL:",v);return}const _=await C.blob();if(!_.type.startsWith("image/")){console.warn("URL did not return an image:",v);return}const T=new URL(v).pathname.split("/").pop()||"image",N=new File([_],T,{type:_.type});await k(N,b,S)}catch(C){console.warn("Failed to load image from URL:",v,C)}}return(v,b)=>(d.openBlock(),d.createElementBlock("div",{class:d.normalizeClass(["wov-image-drop-zone",{"wov-drag-over":o.value}]),onDragover:u,onDragenter:f,onDragleave:p,onDrop:m},null,34))}}),sR={class:"wov-user-cursors"},iR={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},aR=["fill"],lR="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z",cR=d.defineComponent({__name:"UserCursors",props:{users:{},currentSessionId:{},camera:{}},setup(t){const e=t,n=d.computed(()=>e.users.filter(r=>r.sessionId!==e.currentSessionId).map(r=>({...r,screenX:(r.position[0]-e.camera.left)*e.camera.zoom,screenY:(r.position[1]-e.camera.top)*e.camera.zoom})));return(r,o)=>(d.openBlock(),d.createElementBlock("div",sR,[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(n.value,s=>(d.openBlock(),d.createElementBlock("div",{key:s.sessionId,class:"wov-user-cursor",style:d.normalizeStyle({transform:`translate(${s.screenX}px, ${s.screenY}px)`})},[(d.openBlock(),d.createElementBlock("svg",iR,[d.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:lR},null,8,aR)])),d.createElementVNode("span",{class:"wov-cursor-label",style:d.normalizeStyle({backgroundColor:s.color})},d.toDisplayString(s.name),5)],4))),128))]))}}),dR={key:0,class:"wov-offline-indicator"},uR=d.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(t){return(e,n)=>t.isOnline?d.createCommentVNode("",!0):(d.openBlock(),d.createElementBlock("div",dR,"Working Offline"))}}),fR={key:0,class:"wov-version-mismatch-overlay"},hR=d.defineComponent({__name:"VersionMismatch",props:{versionMismatch:{type:Boolean}},setup(t){function e(){window.location.reload()}return(n,r)=>t.versionMismatch?(d.openBlock(),d.createElementBlock("div",fR,[d.createElementVNode("div",{class:"wov-version-mismatch-dialog"},[r[0]||(r[0]=d.createElementVNode("p",null,"A new version is available.",-1)),r[1]||(r[1]=d.createElementVNode("p",null,"Please refresh the page to continue.",-1)),d.createElementVNode("button",{onClick:e},"Refresh")])])):d.createCommentVNode("",!0)}}),pR=d.defineComponent({__name:"BackToContentButton",setup(t){const{nextEditorTick:e}=Ee(),n=Ze(h.Camera),r=h.defineQuery(l=>l.with(h.Synced,h.Block,h.Aabb)),o=d.ref(0),s=d.inject(pt);if(s){const l=s.registerTickCallback(c=>{r.addedOrRemoved(c).length>0&&(o.value=r.current(c).length)});d.onUnmounted(l)}const i=d.ref(!1);d.watchEffect(()=>{i.value=!n.value.canSeeBlocks&&o.value>0});function a(){e(l=>{const c=r.current(l);if(c.length===0)return;let u=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,m=Number.NEGATIVE_INFINITY;for(const _ of c){const x=h.Aabb.read(l,_);u=Math.min(u,x.value[0]),f=Math.min(f,x.value[1]),p=Math.max(p,x.value[2]),m=Math.max(m,x.value[3])}const g=h.Screen.read(l),y=h.Camera.read(l);let k=Math.min(g.width/(p-u),g.height/(m-f));k/=1.1,k=Math.min(k,y.zoom);const w=(u+p)/2,v=(f+m)/2,b=w-g.width/k/2,S=v-g.height/k/2,C=h.Camera.write(l);C.left=b,C.top=S,C.zoom=k})}return(l,c)=>i.value?(d.openBlock(),d.createElementBlock("button",{key:0,class:"wov-back-to-content",onClick:a},[...c[0]||(c[0]=[d.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[d.createElementVNode("path",{d:"M10 12L6 8L10 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1),d.createTextVNode(" Back to content ",-1)])])):d.createCommentVNode("",!0)}}),mR=["data-entity-id","data-selected","data-held-by-other","data-hovered"],gR=d.defineComponent({__name:"WovenCanvas",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{}},emits:["ready"],setup(t,{emit:e}){var Wk;const n=h.defineQuery(A=>A.tracking(h.Block)),r=h.defineQuery(A=>A.with(h.Block).tracking(h.Connector)),o=h.defineQuery(A=>A.with(h.Block).tracking(Ie)),s=h.defineQuery(A=>A.with(h.Block).tracking(h.Held)),i=h.defineQuery(A=>A.with(h.Block).tracking(h.Hovered)),a=h.defineQuery(A=>A.with(h.Block).tracking(h.Edited)),l=h.defineQuery(A=>A.with(h.Block).tracking(h.Opacity)),c=h.defineQuery(A=>A.tracking(h.User)),u=t,f=e,p=d.ref(null),m=d.shallowRef(null),g=h.UserData.parse(((Wk=u.editor)==null?void 0:Wk.user)??{}),y=new Set,k=new Map,w=d.shallowRef([]),v=new Map,b=new Map,S=new Set,C=new Map,_=d.shallowRef([]),x=d.ref(!0),T=d.ref(!1),N=d.ref(!0),I=d.shallowRef(h.Camera.default());function V(A,se,D){let Y=v.get(A);Y||(Y=new Map,v.set(A,Y));let H=Y.get(se);return H||(H=new Set,Y.set(se,H)),H.add(D),()=>{H.delete(D),H.size===0&&(Y.delete(se),Y.size===0&&v.delete(A))}}function K(A,se,D,Y=!1){const H=v.get(se);if(!H)return;const R=H.get(D.name);if(!R||R.size===0)return;let Me=null;Y||(Me=D.snapshot(A,se));for(const zt of R)zt(Me)}function M(A,se){let D=b.get(A);return D||(D=new Set,b.set(A,D)),D.add(se),()=>{D.delete(se),D.size===0&&b.delete(A)}}function $(A,se){const D=b.get(se.name);if(!D||D.size===0)return;const Y=se.snapshot(A);for(const H of D)H(Y)}function Z(A){return S.add(A),()=>{S.delete(A)}}function ae(){return g.sessionId}function X(A){return k.get(A)??null}const j={hasEntity:A=>y.has(A),getEditor:()=>m.value,getAssetManager:()=>Se,getSessionId:ae,getUserBySessionId:X,subscribeComponent:V,subscribeSingleton:M,registerTickCallback:Z};d.provide(pt,j),d.provide("containerRef",p);const q=I0();d.provide(yh,q);let te=0,fe=null,ce=null,Se=null;async function Dt(){!m.value||!ce||(m.value.nextTick(A=>{Dr(A),qn(A);for(const se of S)se(A);ce&&ce.sync(A)}),await m.value.tick(),fe=requestAnimationFrame(Dt))}let gn=null;d.onMounted(async()=>{var zt,it;if(!p.value)return;gn=()=>{var zr;(zr=p.value)==null||zr.scrollTo(0,0)},p.value.addEventListener("scroll",gn);const A=u.store??{},se={history:!0,...A};A.websocket&&(se.websocket={...A.websocket,onVersionMismatch:zr=>{var yn,zs;T.value=!0,(zs=(yn=A.websocket)==null?void 0:yn.onVersionMismatch)==null||zs.call(yn,zr)},onConnectivityChange:zr=>{var yn,zs;x.value=zr,(zs=(yn=A.websocket)==null?void 0:yn.onConnectivityChange)==null||zs.call(yn,zr)}}),ce=new at.CanvasStore(se);const D=[],Y=u.pluginOptions;(Y==null?void 0:Y.controls)!==!1&&D.push(jP((Y==null?void 0:Y.controls)??{})),(Y==null?void 0:Y.selection)!==!1&&D.push(mb((Y==null?void 0:Y.selection)||void 0)),(Y==null?void 0:Y.eraser)!==!1&&D.push(I_((Y==null?void 0:Y.eraser)||void 0)),(Y==null?void 0:Y.pen)!==!1&&D.push(bE()),(Y==null?void 0:Y.arrows)!==!1&&D.push(TS((Y==null?void 0:Y.arrows)||void 0)),D.push(Hk({store:ce})),(zt=u.editor)!=null&&zt.plugins&&D.push(...u.editor.plugins);const H={...u.editor,user:g,plugins:D,controls:u.controls},R=new h.Editor(p.value,H);await R.initialize(),await ce.initialize({components:R.components,singletons:R.singletons});const Me=((it=A.persistence)==null?void 0:it.documentId)??"default";Se=new NP({provider:u.assetProvider??new IP,documentId:Me}),await Se.init(),await Se.resumePendingUploads(),m.value=R,fe=requestAnimationFrame(Dt),N.value=!1,f("ready",R,ce)}),d.onUnmounted(()=>{var A;fe!==null&&cancelAnimationFrame(fe),Se==null||Se.close(),ce==null||ce.close(),(A=m.value)==null||A.dispose()});function Dr(A){const{events:se,newIndex:D}=A.eventBuffer.readEvents(te);if(te=D,se.length===0)return;const{componentsById:Y,singletonsById:H}=h.getResources(A);for(const{entityId:R,eventType:Me,componentId:zt}of se){if(R===h.SINGLETON_ENTITY_ID){if(Me===h.EventType.CHANGED){const it=H.get(zt);it&&$(A,it)}continue}if(Me===h.EventType.ADDED)y.add(R);else if(Me===h.EventType.REMOVED)y.delete(R),v.delete(R);else if(Me===h.EventType.COMPONENT_ADDED){y.add(R);const it=Y.get(zt);it&&K(A,R,it)}else if(Me===h.EventType.COMPONENT_REMOVED){const it=Y.get(zt);it&&K(A,R,it,!0)}else if(Me===h.EventType.CHANGED){const it=Y.get(zt);it&&K(A,R,it)}}}function qn(A){var Y;let se=!1;for(const H of n.added(A)){const R=h.Block.snapshot(A,H),Me=(Y=m.value)==null?void 0:Y.blockDefs[R.tag],zt=(Me==null?void 0:Me.stratum)??"content";C.set(H,d.ref({entityId:H,block:R,stratum:zt,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),se=!0}for(const H of n.removed(A))C.delete(H),se=!0;for(const H of n.changed(A)){const R=C.get(H);if(R){const Me=h.Block.snapshot(A,H);R.value.block.rank!==Me.rank&&(se=!0),R.value.block=Me}}let D=!1;for(const H of c.addedOrChanged(A)){const R=h.User.snapshot(A,H);k.set(R.sessionId,R),D=!0}for(const H of c.removed(A)){const R=h.User.read(A,H);k.delete(R.sessionId),D=!0}D&&(w.value=Array.from(k.values()));for(const H of o.added(A)){const R=C.get(H);R&&!R.value.selected&&(R.value.selected=!0)}for(const H of o.removed(A)){const R=C.get(H);R&&R.value.selected&&(R.value.selected=!1)}for(const H of s.addedOrChanged(A)){const R=C.get(H);R&&(R.value.held=h.Held.snapshot(A,H))}for(const H of s.removed(A)){const R=C.get(H);R&&R.value.held!==null&&(R.value.held=null)}for(const H of i.added(A)){const R=C.get(H);R&&!R.value.hovered&&(R.value.hovered=!0)}for(const H of i.removed(A)){const R=C.get(H);R&&R.value.hovered&&(R.value.hovered=!1)}for(const H of a.added(A)){const R=C.get(H);R&&!R.value.edited&&(R.value.edited=!0)}for(const H of a.removed(A)){const R=C.get(H);R&&R.value.edited&&(R.value.edited=!1)}for(const H of l.addedOrChanged(A)){const R=C.get(H);R&&(R.value.opacity=h.Opacity.snapshot(A,H))}for(const H of l.removed(A)){const R=C.get(H);R&&R.value.opacity!==null&&(R.value.opacity=null)}for(const H of r.addedOrChanged(A)){const R=C.get(H);R&&(R.value.connector=h.Connector.snapshot(A,H))}for(const H of r.removed(A)){const R=C.get(H);R&&R.value.connector!==null&&(R.value.connector=null)}if(se){const H=Array.from(C.values());H.sort((R,Me)=>R.value.block.rank>Me.value.block.rank?1:-1),_.value=H}}M(h.Camera.name,A=>{A&&(I.value=A)});function ja(A){const se=A.rotateZ!==0,D=A.flip[0],Y=A.flip[1];if(!se&&!D&&!Y)return;const H=[];return se&&H.push(`rotate(${A.rotateZ}rad)`),D&&H.push("scaleX(-1)"),Y&&H.push("scaleY(-1)"),H.join(" ")}function xo(A){const{held:se}=A;if(!se||!se.sessionId||se.sessionId===g.sessionId)return null;const D=X(se.sessionId);return(D==null?void 0:D.color)??null}function Gn(A){const{block:se,stratum:D,opacity:Y}=A,H=xo(A),R=Y!==null?Y.value/255:1;return{position:"absolute",left:`${se.position[0]}px`,top:`${se.position[1]}px`,width:`${se.size[0]}px`,height:`${se.size[1]}px`,zIndex:h.STRATUM_ORDER[D]*1e3,transform:ja(se),opacity:R,pointerEvents:"none",userSelect:"none","--wov-held-by-color":H??void 0,transition:R===1?"opacity 0ms 32ms":void 0}}return(A,se)=>(d.openBlock(),d.createElementBlock("div",{ref_key:"containerRef",ref:p,class:"wov-root",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"}},[t.background?d.renderSlot(A.$slots,"background",{key:0,background:t.background},()=>[d.createVNode(mk,{background:t.background},null,8,["background"])]):d.createCommentVNode("",!0),d.createElementVNode("div",{class:"wov-canvas",style:d.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:`scale(${I.value.zoom}) translate(${-I.value.left}px, ${-I.value.top}px)`,"--wov-zoom":I.value.zoom})},[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(_.value,D=>(d.openBlock(),d.createElementBlock("div",{key:D.value.entityId,"data-entity-id":D.value.entityId,style:d.normalizeStyle(Gn(D.value)),"data-selected":D.value.selected||void 0,"data-held-by-other":xo(D.value)!==null||void 0,"data-hovered":D.value.hovered||void 0,class:"wov-block"},[d.renderSlot(A.$slots,`block:${D.value.block.tag}`,d.mergeProps({ref_for:!0},D.value),()=>[D.value.block.tag==="selection-box"?(d.openBlock(),d.createBlock(WP,d.mergeProps({key:0,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-box"?(d.openBlock(),d.createBlock(UP,d.mergeProps({key:1,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-handle"?(d.openBlock(),d.createBlock(GP,d.mergeProps({key:2,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-handle"?(d.openBlock(),d.createBlock(wh,d.mergeProps({key:3,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-terminal"?(d.openBlock(),d.createBlock(vh,d.mergeProps({key:4,ref_for:!0},D.value),null,16)):D.value.block.tag==="sticky-note"?(d.openBlock(),d.createBlock(YP,d.mergeProps({key:5,ref_for:!0},D.value),null,16)):D.value.block.tag==="eraser"?(d.openBlock(),d.createBlock(Pp,d.mergeProps({key:6,ref_for:!0},D.value),null,16)):D.value.block.tag==="pen-stroke"?(d.openBlock(),d.createBlock(Up,d.mergeProps({key:7,ref_for:!0},D.value),null,16)):D.value.block.tag==="arc-arrow"?(d.openBlock(),d.createBlock(kh,d.mergeProps({key:8,ref_for:!0},D.value),null,16)):D.value.block.tag==="elbow-arrow"?(d.openBlock(),d.createBlock(bh,d.mergeProps({key:9,ref_for:!0},D.value),null,16)):D.value.block.tag==="text"?(d.openBlock(),d.createBlock(R0,d.mergeProps({key:10,ref_for:!0},D.value),null,16)):D.value.block.tag==="image"?(d.openBlock(),d.createBlock(Rp,d.mergeProps({key:11,ref_for:!0},D.value),null,16)):D.value.block.tag==="shape"?(d.openBlock(),d.createBlock(P0,d.mergeProps({key:12,ref_for:!0},D.value),null,16)):d.createCommentVNode("",!0)])],12,mR))),128))],4),m.value?d.renderSlot(A.$slots,"user-cursors",{key:1,users:w.value,currentSessionId:d.unref(g).sessionId,camera:I.value},()=>[d.createVNode(cR,{users:w.value,"current-session-id":d.unref(g).sessionId,camera:I.value},null,8,["users","current-session-id","camera"])]):d.createCommentVNode("",!0),m.value?(d.openBlock(),d.createBlock(kk,{key:2},{default:d.withCtx(D=>[d.renderSlot(A.$slots,"floating-menu",d.normalizeProps(d.guardReactiveProps(D)))]),_:3})):d.createCommentVNode("",!0),m.value?d.renderSlot(A.$slots,"user-presence",{key:3,users:w.value},()=>[d.createVNode(Bk,{users:w.value},null,8,["users"])]):d.createCommentVNode("",!0),m.value?d.renderSlot(A.$slots,"toolbar",{key:4},()=>[d.createVNode(Nk)]):d.createCommentVNode("",!0),m.value?d.renderSlot(A.$slots,"default",{key:5}):d.createCommentVNode("",!0),d.renderSlot(A.$slots,"offline-indicator",{isOnline:x.value},()=>[d.createVNode(uR,{"is-online":x.value},null,8,["is-online"])]),d.renderSlot(A.$slots,"version-mismatch",{versionMismatch:T.value},()=>[d.createVNode(hR,{"version-mismatch":T.value},null,8,["version-mismatch"])]),d.renderSlot(A.$slots,"back-to-content",{},()=>[d.createVNode(pR)]),d.renderSlot(A.$slots,"loading",{isLoading:N.value},()=>[d.createVNode(wk,{"is-loading":N.value},null,8,["is-loading"])]),m.value?d.renderSlot(A.$slots,"file-drop-zone",{key:6},()=>[d.createVNode(oR)]):d.createCommentVNode("",!0)],512))}});Object.defineProperty(P,"CanvasComponentDef",{enumerable:!0,get:()=>at.CanvasComponentDef}),Object.defineProperty(P,"CanvasSingletonDef",{enumerable:!0,get:()=>at.CanvasSingletonDef}),Object.defineProperty(P,"CanvasStore",{enumerable:!0,get:()=>at.CanvasStore}),Object.defineProperty(P,"Synced",{enumerable:!0,get:()=>at.Synced}),Object.defineProperty(P,"defineCanvasComponent",{enumerable:!0,get:()=>at.defineCanvasComponent}),Object.defineProperty(P,"defineCanvasSingleton",{enumerable:!0,get:()=>at.defineCanvasSingleton}),P.ARROW_HEADS=Zl,P.ArcArrow=kh,P.ArcArrowTool=dP,P.ArrowHandle=wh,P.ArrowHead=sn,P.ArrowHeadButton=Ld,P.ArrowTerminal=vh,P.ArrowThicknessButton=ok,P.CURSORS=vk,P.CanvasBackground=mk,P.ColorButton=ak,P.ColorPicker=ik,P.CursorKind=Ir,P.EditableText=wa,P.EditingPlugin=Hk,P.ElbowArrow=bh,P.ElbowArrowTool=Mk,P.Eraser=Pp,P.EraserTool=_k,P.FloatingMenu=kk,P.FloatingMenuBar=yk,P.HandTool=Sk,P.IconChevronDown=St,P.ImageBlock=Rp,P.ImageTool=Ak,P.LoadingOverlay=wk,P.MenuButton=Co,P.MenuDropdown=bt,P.MenuTooltip=Fd,P.PenStroke=Up,P.PenStrokeThicknessButton=lk,P.PenTool=Ek,P.SHAPES=ss,P.SelectTool=bk,P.ShapeBlock=P0,P.ShapeFillColorButton=ck,P.ShapeKindButton=dk,P.ShapeStrokeColorButton=uk,P.ShapeTool=xk,P.StickyNoteTool=Ck,P.TextAlignmentButton=jd,P.TextBlock=R0,P.TextBoldButton=Hd,P.TextColorButton=qd,P.TextFontFamilyButton=Zd,P.TextFontSizeButton=Ud,P.TextItalicButton=Kd,P.TextTool=Tk,P.TextUnderlineButton=Jd,P.Toolbar=Nk,P.ToolbarButton=Qt,P.UserPresence=Bk,P.WovenCanvas=gR,P.computeCommonComponents=gk,P.createTooltipContext=I0,P.getArrowHead=no,P.useComponent=Pe,P.useComponents=Wn,P.useEditorContext=Ee,P.useFonts=hk,P.useQuery=_0,P.useSingleton=Ze,P.useTextBatchController=O0,P.useTextEditorController=Bs,P.useTextFormatting=qt,P.useTextStretchBehavior=Bd,P.useToolbar=Od,P.useTooltipSingleton=Un,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
|
102
|
+
`):""}),dd=dy,ud=" ",uy=" ",fy=Fs.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Bn(this.options.HTMLAttributes,n),0]},parseMarkdown:(n,e)=>{const t=n.tokens||[];if(t.length===1&&t[0].type==="image")return e.parseChildren([t[0]]);const o=e.parseInline(t);return o.length===1&&o[0].type==="text"&&(o[0].text===ud||o[0].text===uy)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,o)},renderMarkdown:(n,e)=>{if(!n)return"";const t=Array.isArray(n.content)?n.content:[];return t.length===0?ud:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),fd=fy,hy=Fs.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),hd=hy,pd=(n,e)=>{if(n==="slot")return 0;if(n instanceof Function)return n(e);const{children:t,...o}=e??{};if(n==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[n,o,t]},py=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,my=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,gy=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,yy=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,ky=so.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return pd("strong",{...Bn(this.options.HTMLAttributes,n),children:pd("slot",{})})},markdownTokenName:"strong",parseMarkdown:(n,e)=>e.applyMark("bold",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`**${e.renderChildren(n)}**`,addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Qo({find:py,type:this.type}),Qo({find:gy,type:this.type})]},addPasteRules(){return[er({find:my,type:this.type}),er({find:yy,type:this.type})]}}),md=ky,wy=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,by=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,xy=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Sy=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Cy=so.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",Bn(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(n,e)=>e.applyMark("italic",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`*${e.renderChildren(n)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Qo({find:wy,type:this.type}),Qo({find:xy,type:this.type})]},addPasteRules(){return[er({find:by,type:this.type}),er({find:Sy,type:this.type})]}}),gd=Cy,vy=so.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["u",Bn(this.options.HTMLAttributes,n),0]},parseMarkdown(n,e){return e.applyMark(this.name||"underline",e.parseInline(n.tokens||[]))},renderMarkdown(n,e){return`++${e.renderChildren(n)}++`},markdownTokenizer:{name:"underline",level:"inline",start(n){return n.indexOf("++")},tokenize(n,e,t){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(n);if(!r)return;const s=r[2].trim();return{type:"underline",raw:r[0],text:s,tokens:t.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:n})=>n.setMark(this.name),toggleUnderline:()=>({commands:n})=>n.toggleMark(this.name),unsetUnderline:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),yd=vy,Ey=ne.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:n=>{const e=n.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:n=>n.textAlign?{style:`text-align: ${n.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:n=>({commands:e})=>this.options.alignments.includes(n)?this.options.types.map(t=>e.updateAttributes(t,{textAlign:n})).some(t=>t):!1,unsetTextAlign:()=>({commands:n})=>this.options.types.map(e=>n.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:n=>({editor:e,commands:t})=>this.options.alignments.includes(n)?e.isActive({textAlign:n})?t.unsetTextAlign():t.setTextAlign(n):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),kd=Ey,My=20,wd=(n,e=0)=>{const t=[];return!n.children.length||e>My||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...wd(o,e+1))}),t},Ty=n=>{if(!n.children.length)return;const e=wd(n);e&&e.forEach(t=>{var o,r;const s=t.getAttribute("style"),i=(r=(o=t.parentElement)==null?void 0:o.closest("span"))==null?void 0:r.getAttribute("style");t.setAttribute("style",`${i};${s}`)})},Hs=so.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:n=>n.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&Ty(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",Bn(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleTextStyle:n=>({commands:e})=>e.toggleMark(this.name,n),removeEmptyTextStyle:()=>({tr:n})=>{const{selection:e}=n;return n.doc.nodesBetween(e.from,e.to,(t,o)=>{if(t.isTextblock)return!0;t.marks.filter(r=>r.type===this.type).some(r=>Object.values(r.attrs).some(s=>!!s))||n.removeMark(o,o+t.nodeSize,this.type)}),!0}}}}),Ny=ne.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="background-color")return l.replace(/['"]+/g,"")}}}return(e=n.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.backgroundColor?{style:`background-color: ${n.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:n=>({chain:e})=>e().setMark("textStyle",{backgroundColor:n}).run(),unsetBackgroundColor:()=>({chain:n})=>n().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),bd=ne.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="color")return l.replace(/['"]+/g,"")}}}return(e=n.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.color?{style:`color: ${n.color}`}:{}}}}]},addCommands(){return{setColor:n=>({chain:e})=>e().setMark("textStyle",{color:n}).run(),unsetColor:()=>({chain:n})=>n().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),By=ne.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:n=>n.style.fontFamily,renderHTML:n=>n.fontFamily?{style:`font-family: ${n.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:n=>({chain:e})=>e().setMark("textStyle",{fontFamily:n}).run(),unsetFontFamily:()=>({chain:n})=>n().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),Ay=ne.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:n=>n.style.fontSize,renderHTML:n=>n.fontSize?{style:`font-size: ${n.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:n=>({chain:e})=>e().setMark("textStyle",{fontSize:n}).run(),unsetFontSize:()=>({chain:n})=>n().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),Iy=ne.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:n=>n.style.lineHeight,renderHTML:n=>n.lineHeight?{style:`line-height: ${n.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:n=>({chain:e})=>e().setMark("textStyle",{lineHeight:n}).run(),unsetLineHeight:()=>({chain:n})=>n().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});ne.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(Ny.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push(bd.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(By.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(Ay.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(Iy.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(Hs.configure(this.options.textStyle)),n}});var xd=bd;function Oy(n={}){return new ue({view(e){return new Dy(e,n)}})}class Dy{constructor(e,t){var o;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(o=t.width)!==null&&o!==void 0?o:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let s=i=>{this[r](i)};return e.dom.addEventListener(r,s),{name:r,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,o,r=this.editorView.dom,s=r.getBoundingClientRect(),i=s.width/r.offsetWidth,l=s.height/r.offsetHeight;if(t){let f=e.nodeBefore,p=e.nodeAfter;if(f||p){let h=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(h){let m=h.getBoundingClientRect(),g=f?m.bottom:m.top;f&&p&&(g=(g+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*l;o={left:m.left,right:m.right,top:g-y,bottom:g+y}}}}if(!o){let f=this.editorView.coordsAtPos(this.cursorPos),p=this.width/2*i;o={left:f.left-p,right:f.left+p,top:f.top,bottom:f.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let d,u;if(!a||a==document.body&&getComputedStyle(a).position=="static")d=-pageXOffset,u=-pageYOffset;else{let f=a.getBoundingClientRect(),p=f.width/a.offsetWidth,h=f.height/a.offsetHeight;d=f.left-a.scrollLeft*p,u=f.top-a.scrollTop*h}this.element.style.left=(o.left-d)/i+"px",this.element.style.top=(o.top-u)/l+"px",this.element.style.width=(o.right-o.left)/i+"px",this.element.style.height=(o.bottom-o.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),o=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=o&&o.type.spec.disableDropCursor,s=typeof r=="function"?r(this.editorView,t,e):r;if(t&&!s){let i=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Ll(this.editorView.state.doc,i,this.editorView.dragging.slice);l!=null&&(i=l)}this.setCursor(i),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class se extends J{constructor(e){super(e,e)}map(e,t){let o=e.resolve(t.map(this.head));return se.valid(o)?new se(o):J.near(o)}content(){return R.empty}eq(e){return e instanceof se&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new se(e.resolve(t.pos))}getBookmark(){return new Ws(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Ry(e)||!_y(e))return!1;let o=t.type.spec.allowGapCursor;if(o!=null)return o;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,o=!1){e:for(;;){if(!o&&se.valid(e))return e;let r=e.pos,s=null;for(let i=e.depth;;i--){let l=e.node(i);if(t>0?e.indexAfter(i)<l.childCount:e.index(i)>0){s=l.child(t>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;r+=t;let a=e.doc.resolve(r);if(se.valid(a))return a}for(;;){let i=t>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!$.isSelectable(s)){e=e.doc.resolve(r+s.nodeSize*t),o=!1;continue e}break}s=i,r+=t;let l=e.doc.resolve(r);if(se.valid(l))return l}return null}}}se.prototype.visible=!1,se.findFrom=se.findGapCursorFrom,J.jsonID("gapcursor",se);class Ws{constructor(e){this.pos=e}map(e){return new Ws(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return se.valid(t)?new se(t):J.near(t)}}function Sd(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function Ry(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),o=n.node(e);if(t==0){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||Sd(r.type))return!0;if(r.inlineContent)return!1}}return!0}function _y(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),o=n.node(e);if(t==o.childCount){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||Sd(r.type))return!0;if(r.inlineContent)return!1}}return!0}function Py(){return new ue({props:{decorations:zy,createSelectionBetween(n,e,t){return e.pos==t.pos&&se.valid(t)?new se(t):null},handleClick:$y,handleKeyDown:Vy,handleDOMEvents:{beforeinput:Ly}}})}const Vy=Mc({ArrowLeft:tr("horiz",-1),ArrowRight:tr("horiz",1),ArrowUp:tr("vert",-1),ArrowDown:tr("vert",1)});function tr(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(o,r,s){let i=o.selection,l=e>0?i.$to:i.$from,a=i.empty;if(i instanceof U){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=o.doc.resolve(e>0?l.after():l.before())}let d=se.findGapCursorFrom(l,e,a);return d?(r&&r(o.tr.setSelection(new se(d))),!0):!1}}function $y(n,e,t){if(!n||!n.editable)return!1;let o=n.state.doc.resolve(e);if(!se.valid(o))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&$.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new se(o))),!0)}function Ly(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof se))return!1;let{$from:t}=n.state.selection,o=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!o)return!1;let r=N.empty;for(let i=o.length-1;i>=0;i--)r=N.from(o[i].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new R(r,0,0));return s.setSelection(U.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function zy(n){if(!(n.selection instanceof se))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",re.create(n.doc,[Ae.widget(n.selection.head,e,{key:"gapcursor"})])}var nr=200,ge=function(){};ge.prototype.append=function(e){return e.length?(e=ge.from(e),!this.length&&e||e.length<nr&&this.leafAppend(e)||this.length<nr&&e.leafPrepend(this)||this.appendInner(e)):this},ge.prototype.prepend=function(e){return e.length?ge.from(e).append(this):this},ge.prototype.appendInner=function(e){return new Fy(this,e)},ge.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ge.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},ge.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},ge.prototype.forEach=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length),t<=o?this.forEachInner(e,t,o,0):this.forEachInvertedInner(e,t,o,0)},ge.prototype.map=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length);var r=[];return this.forEach(function(s,i){return r.push(e(s,i))},t,o),r},ge.from=function(e){return e instanceof ge?e:e&&e.length?new Cd(e):ge.empty};var Cd=function(n){function e(o){n.call(this),this.values=o}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,s){return r==0&&s==this.length?this:new e(this.values.slice(r,s))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,s,i,l){for(var a=s;a<i;a++)if(r(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,i,l){for(var a=s-1;a>=i;a--)if(r(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=nr)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=nr)return new e(r.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(ge);ge.empty=new Cd([]);var Fy=function(n){function e(t,o){n.call(this),this.left=t,this.right=o,this.length=t.length+o.length,this.depth=Math.max(t.depth,o.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(o){return o<this.left.length?this.left.get(o):this.right.get(o-this.left.length)},e.prototype.forEachInner=function(o,r,s,i){var l=this.left.length;if(r<l&&this.left.forEachInner(o,r,Math.min(s,l),i)===!1||s>l&&this.right.forEachInner(o,Math.max(r-l,0),Math.min(this.length,s)-l,i+l)===!1)return!1},e.prototype.forEachInvertedInner=function(o,r,s,i){var l=this.left.length;if(r>l&&this.right.forEachInvertedInner(o,r-l,Math.max(s,l)-l,i+l)===!1||s<l&&this.left.forEachInvertedInner(o,Math.min(r,l),s,i)===!1)return!1},e.prototype.sliceInner=function(o,r){if(o==0&&r==this.length)return this;var s=this.left.length;return r<=s?this.left.slice(o,r):o>=s?this.right.slice(o-s,r-s):this.left.slice(o,s).append(this.right.slice(0,r-s))},e.prototype.leafAppend=function(o){var r=this.right.leafAppend(o);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(o){var r=this.left.leafPrepend(o);if(r)return new e(r,this.right)},e.prototype.appendInner=function(o){return this.left.depth>=Math.max(this.right.depth,o.depth)+1?new e(this.left,new e(this.right,o)):new e(this,o)},e}(ge);const Hy=500;class qe{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let o=this.items.length;for(;;o--)if(this.items.get(o-1).selection){--o;break}let r,s;t&&(r=this.remapping(o,this.items.length),s=r.maps.length);let i=e.tr,l,a,d=[],u=[];return this.items.forEach((f,p)=>{if(!f.step){r||(r=this.remapping(o,p+1),s=r.maps.length),s--,u.push(f);return}if(r){u.push(new nt(f.map));let h=f.step.map(r.slice(s)),m;h&&i.maybeStep(h).doc&&(m=i.mapping.maps[i.mapping.maps.length-1],d.push(new nt(m,void 0,void 0,d.length+u.length))),s--,m&&r.appendMap(m,s)}else i.maybeStep(f.step);if(f.selection)return l=r?f.selection.map(r.slice(s)):f.selection,a=new qe(this.items.slice(0,o).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:i,selection:l}}addTransform(e,t,o,r){let s=[],i=this.eventCount,l=this.items,a=!r&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),p=new nt(e.mapping.maps[u],f,t),h;(h=a&&a.merge(p))&&(p=h,u?s.pop():l=l.slice(0,l.length-1)),s.push(p),t&&(i++,t=void 0),r||(a=p)}let d=i-o.depth;return d>jy&&(l=Wy(l,d),i-=d),new qe(l.append(s),i)}remapping(e,t){let o=new zn;return this.items.forEach((r,s)=>{let i=r.mirrorOffset!=null&&s-r.mirrorOffset>=e?o.maps.length-r.mirrorOffset:void 0;o.appendMap(r.map,i)},e,t),o}addMaps(e){return this.eventCount==0?this:new qe(this.items.append(e.map(t=>new nt(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let o=[],r=Math.max(0,this.items.length-t),s=e.mapping,i=e.steps.length,l=this.eventCount;this.items.forEach(p=>{p.selection&&l--},r);let a=t;this.items.forEach(p=>{let h=s.getMirror(--a);if(h==null)return;i=Math.min(i,h);let m=s.maps[h];if(p.step){let g=e.steps[h].invert(e.docs[h]),y=p.selection&&p.selection.map(s.slice(a+1,h));y&&l++,o.push(new nt(m,g,y))}else o.push(new nt(m))},r);let d=[];for(let p=t;p<i;p++)d.push(new nt(s.maps[p]));let u=this.items.slice(0,r).append(d).append(o),f=new qe(u,l);return f.emptyItemCount()>Hy&&(f=f.compress(this.items.length-o.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),o=t.maps.length,r=[],s=0;return this.items.forEach((i,l)=>{if(l>=e)r.push(i),i.selection&&s++;else if(i.step){let a=i.step.map(t.slice(o)),d=a&&a.getMap();if(o--,d&&t.appendMap(d,o),a){let u=i.selection&&i.selection.map(t.slice(o));u&&s++;let f=new nt(d.invert(),a,u),p,h=r.length-1;(p=r.length&&r[h].merge(f))?r[h]=p:r.push(f)}}else i.map&&o--},this.items.length,0),new qe(ge.from(r.reverse()),s)}}qe.empty=new qe(ge.empty,0);function Wy(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class nt{constructor(e,t,o,r){this.map=e,this.step=t,this.selection=o,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new nt(t.getMap().invert(),t,this.selection)}}}class _t{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const jy=20;function Uy(n,e,t,o){let r=t.getMeta(rn),s;if(r)return r.historyState;t.getMeta(Jy)&&(n=new _t(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(rn))return i.getMeta(rn).redo?new _t(n.done.addTransform(t,void 0,o,or(e)),n.undone,vd(t.mapping.maps),n.prevTime,n.prevComposition):new _t(n.done,n.undone.addTransform(t,void 0,o,or(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!i&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-o.newGroupDelay||!Ky(t,n.prevRanges)),d=i?js(n.prevRanges,t.mapping):vd(t.mapping.maps);return new _t(n.done.addTransform(t,a?e.selection.getBookmark():void 0,o,or(e)),qe.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new _t(n.done.rebased(t,s),n.undone.rebased(t,s),js(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new _t(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),js(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Ky(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((o,r)=>{for(let s=0;s<e.length;s+=2)o<=e[s+1]&&r>=e[s]&&(t=!0)}),t}function vd(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((o,r,s,i)=>e.push(s,i));return e}function js(n,e){if(!n)return null;let t=[];for(let o=0;o<n.length;o+=2){let r=e.map(n[o],1),s=e.map(n[o+1],-1);r<=s&&t.push(r,s)}return t}function qy(n,e,t){let o=or(e),r=rn.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,o);if(!s)return null;let i=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),r,o),a=new _t(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(rn,{redo:t,historyState:a})}let Us=!1,Ed=null;function or(n){let e=n.plugins;if(Ed!=e){Us=!1,Ed=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Us=!0;break}}return Us}const rn=new Te("history"),Jy=new Te("closeHistory");function Gy(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ue({key:rn,state:{init(){return new _t(qe.empty,qe.empty,null,0,-1)},apply(e,t,o){return Uy(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Td:o=="historyRedo"?Nd:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function Md(n,e){return(t,o)=>{let r=rn.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=qy(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Td=Md(!1,!0),Nd=Md(!0,!0);ne.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:n=>n.length,wordCounter:n=>n.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc;if(((n==null?void 0:n.mode)||this.options.mode)==="textSize"){const o=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(o)}return e.nodeSize},this.storage.words=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let n=!1;return[new ue({key:new Te("characterCount"),appendTransaction:(e,t,o)=>{if(n)return;const r=this.options.limit;if(r==null||r===0){n=!0;return}const s=this.storage.characters({node:o.doc});if(s>r){const i=s-r,l=0,a=i;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const d=o.tr.deleteRange(l,a);return n=!0,d}n=!0},filterTransaction:(e,t)=>{const o=this.options.limit;if(!e.docChanged||o===0||o===null||o===void 0)return!0;const r=this.storage.characters({node:t.doc}),s=this.storage.characters({node:e.doc});if(s<=o||r>o&&s>o&&s<=r)return!0;if(r>o&&s>o&&s>r||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=s-o,d=l-a,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>o)}})]}}),ne.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[Oy(this.options)]}}),ne.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new ue({key:new Te("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:o}=this.editor,{anchor:r}=e,s=[];if(!t||!o)return re.create(n,[]);let i=0;this.options.mode==="deepest"&&n.descendants((a,d)=>{if(a.isText)return;if(!(r>=d&&r<=d+a.nodeSize-1))return!1;i+=1});let l=0;return n.descendants((a,d)=>{if(a.isText||!(r>=d&&r<=d+a.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&i-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";s.push(Ae.node(d,d+a.nodeSize,{class:this.options.className}))}),re.create(n,s)}}})]}}),ne.create({name:"gapCursor",addProseMirrorPlugins(){return[Py()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=ee(V(n,"allowGapCursor",t)))!=null?e:null}}});var Bd="placeholder";function Yy(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}ne.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Bd,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${Yy(this.options.dataAttribute)}`:`data-${Bd}`;return[new ue({key:new Te("placeholder"),props:{decorations:({doc:e,selection:t})=>{const o=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(!o)return null;const i=this.editor.isEmpty;return e.descendants((l,a)=>{const d=r>=a&&r<=a+l.nodeSize,u=!l.isLeaf&&Jo(l);if((d||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const p=Ae.node(a,a+l.nodeSize,{class:f.join(" "),[n]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:a,hasAnchor:d}):this.options.placeholder});s.push(p)}return this.options.includeChildren}),re.create(e,s)}}})]}}),ne.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new ue({key:new Te("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||h0(t.selection)||n.view.dragging?null:re.create(t.doc,[Ae.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Ad({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}ne.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new Te(this.name),t=this.options.node||((n=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:n.name)||"paragraph",o=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(t).includes(r.name));return[new ue({key:e,appendTransaction:(r,s,i)=>{const{doc:l,tr:a,schema:d}=i,u=e.getState(i),f=l.content.size,p=d.nodes[t];if(u)return a.insert(f,p.create())},state:{init:(r,s)=>{const i=s.tr.doc.lastChild;return!Ad({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Ad({node:i,types:o})}}})]}});var Xy=ne.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Td(n,e),redo:()=>({state:n,dispatch:e})=>Nd(n,e)}},addProseMirrorPlugins(){return[Gy(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});function Pt(n,e){const t=c.inject($e);if(!t)throw new Error("useComponents must be used within a WovenCanvas component");const o=c.shallowRef(new Map),r=new Map;function s(l){if(r.has(l))return;const a=t.getEditor();if(a){const u=a._getContext();if(x.hasComponent(u,l,e)){const f=new Map(o.value);f.set(l,e.snapshot(u,l)),o.value=f}else{const f=new Map(o.value);f.set(l,null),o.value=f}}const d=t.subscribeComponent(l,e.name,u=>{const f=new Map(o.value);f.set(l,u),o.value=f});r.set(l,d)}function i(l){const a=r.get(l);if(a){a(),r.delete(l);const d=new Map(o.value);d.delete(l),o.value=d}}return c.watch(()=>c.toValue(n),(l,a)=>{const d=new Set(l),u=new Set(a??[]);for(const f of u)d.has(f)||i(f);for(const f of d)u.has(f)||s(f)},{immediate:!0}),c.onUnmounted(()=>{for(const l of r.values())l();r.clear()}),o}function Id(){const n=c.inject($e);if(!n)throw new Error("useImageCreation must be used within a WovenCanvas component");const{nextEditorTick:e}=le();function t(s){return new Promise((i,l)=>{const a=new window.Image;a.onload=()=>{i({width:a.naturalWidth,height:a.naturalHeight}),URL.revokeObjectURL(a.src)},a.onerror=()=>{l(new Error("Failed to load image")),URL.revokeObjectURL(a.src)},a.src=URL.createObjectURL(s)})}async function o(s,i,l,a={}){const{maxSize:d=400}=a,u=await t(s),f=await e(),p=Math.min(1,d/Math.max(u.width,u.height));let h=Math.round(u.width*p),m=Math.round(u.height*p);const g=x.Grid.read(f);g.enabled&&(h=Math.max(g.colWidth,Math.round(h/g.colWidth)*g.colWidth),m=Math.max(g.rowHeight,Math.round(m/g.rowHeight)*g.rowHeight));const y=x.createEntity(f);x.addComponent(f,y,x.Block);const k=x.Block.write(f,y);k.tag="image",k.position[0]=i-h/2,k.position[1]=l-m/2,k.size[0]=h,k.size[1]=m,x.Grid.snapPosition(f,k.position);const w=crypto.randomUUID();x.addComponent(f,y,x.Asset);const b=x.Asset.write(f,y);b.identifier=w,b.uploadState=x.UploadState.Pending,x.addComponent(f,y,x.Image);const S=x.Image.write(f,y);return S.width=u.width,S.height=u.height,S.alt=s.name,x.addComponent(f,y,Re.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,w,s),y}async function r(s,i,l){const a=n==null?void 0:n.getAssetManager();if(a)try{await a.upload(i,l,{filename:l.name,mimeType:l.type});const d=await e(),u=x.Asset.write(d,s);u.uploadState=x.UploadState.Complete}catch{const d=await e(),u=x.Asset.write(d,s);u.uploadState=x.UploadState.Failed}}return{getImageDimensions:t,createImageBlock:o}}function Od(n){const e=c.inject($e);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const t=c.shallowRef([]),o=x.defineQuery(f=>f.with(...n)),r=new Map;let s=!1;function i(f){const p=e.getEditor();if(!p)return{refs:{},unsubscribes:[]};const h=p._getContext(),m={},g=[];for(const y of n){const k=c.shallowRef(y.snapshot(h,f));m[y.name]=k;const w=e.subscribeComponent(f,y.name,b=>{k.value=b});g.push(w)}return{refs:m,unsubscribes:g}}function l(f){const p=r.get(f);if(p){for(const h of p.unsubscribes)h();r.delete(f)}}function a(){const f=[];for(const[p,h]of r)f.push({entityId:p,...h.refs});return f}function d(f){if(!s){const g=o.current(f);for(const y of g)r.set(y,i(y));t.value=a(),s=!0;return}const p=o.added(f),h=o.removed(f);let m=!1;for(const g of h)l(g),m=!0;for(const g of p)r.has(g)||(r.set(g,i(g)),m=!0);m&&(t.value=a())}const u=e.registerTickCallback(d);return c.onUnmounted(()=>{u();for(const f of r.keys())l(f)}),t}function Se(n){const e=c.inject($e);if(!e)throw new Error("useSingleton must be used within a WovenCanvas component");const t=c.shallowRef(n.default()),o=e.getEditor();if(o){const i=o._getContext();t.value=n.snapshot(i)}const r=e.subscribeSingleton(n.name,i=>{t.value=i??{}});let s=null;return o||(s=e.registerTickCallback(()=>{const i=e.getEditor();if(i){const l=i._getContext();t.value=n.snapshot(l),s==null||s(),s=null}})),c.onUnmounted(()=>{r(),s==null||s()}),t}function Ks(n,e,t){if(!n.closest(".wov-block")){const h=n.getBoundingClientRect();return{width:h.width,height:h.height,left:0,top:0}}const r=n.getBoundingClientRect(),s=t.value.left,i=t.value.top,l=new DOMPoint(r.left+r.width/2-s,r.top+r.height/2-i),a=e.value.zoom,d=new DOMMatrix;d.translateSelf(-e.value.left*a,-e.value.top*a),d.scaleSelf(a,a),d.invertSelf();const u=d.transformPoint(l),f=n.offsetWidth,p=n.offsetHeight;return{width:f,height:p,left:u.x-f/2,top:u.y-p/2}}function Dd(n){if(n.startsWith("#"))return n.toUpperCase();const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(e){const t=parseInt(e[1],10).toString(16).padStart(2,"0"),o=parseInt(e[2],10).toString(16).padStart(2,"0"),r=parseInt(e[3],10).toString(16).padStart(2,"0");return`#${t}${o}${r}`.toUpperCase()}return n}function io(n){const e=Math.round(n.red),t=Math.round(n.green),o=Math.round(n.blue),r=Math.round(n.alpha);return r<255?"#"+[e,t,o,r].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join(""):"#"+[e,t,o].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join("")}function qs(n){n=n.replace(/^#/,"");let e,t,o,r=255;if(n.length===6)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);else if(n.length===8)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16),r=parseInt(n.slice(6,8),16);else return null;return{red:e,green:t,blue:o,alpha:r}}function Rd(n){const e=qs(n);if(!e)return{h:0,s:100,v:100,a:255};const t=e.red/255,o=e.green/255,r=e.blue/255,s=Math.max(t,o,r),i=Math.min(t,o,r),l=s-i;let a=0;const d=s===0?0:l/s*100,u=s*100;if(l!==0)switch(s){case t:a=((o-r)/l+(o<r?6:0))*60;break;case o:a=((r-t)/l+2)*60;break;case r:a=((t-o)/l+4)*60;break}return{h:a,s:d,v:u,a:e.alpha}}function _d(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),a=e*6-l,d=o*(1-t),u=o*(1-a*t),f=o*(1-(1-a)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const p=h=>Math.round(h*255).toString(16).padStart(2,"0");return`#${p(r)}${p(s)}${p(i)}`}function Pd(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),a=e*6-l,d=o*(1-t),u=o*(1-a*t),f=o*(1-(1-a)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const p=m=>Math.round(m*255).toString(16).padStart(2,"0"),h=Math.round(n.a).toString(16).padStart(2,"0");return n.a<255?`#${p(r)}${p(s)}${p(i)}${h}`:`#${p(r)}${p(s)}${p(i)}`}const Oe=c.shallowRef(null),Js=c.shallowRef(null),Gs=c.shallowRef(null),Vt=c.ref(0);function lo(){const n={hasEditor:c.computed(()=>Oe.value!==null),isBold:c.computed(()=>{var r;return Vt.value,((r=Oe.value)==null?void 0:r.isActive("bold"))??!1}),isItalic:c.computed(()=>{var r;return Vt.value,((r=Oe.value)==null?void 0:r.isActive("italic"))??!1}),isUnderline:c.computed(()=>{var r;return Vt.value,((r=Oe.value)==null?void 0:r.isActive("underline"))??!1}),alignment:c.computed(()=>{Vt.value;const r=Oe.value;return r?r.isActive({textAlign:"center"})?"center":r.isActive({textAlign:"right"})?"right":r.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:c.computed(()=>{Vt.value;const r=Oe.value;if(!r)return null;const i=r.getAttributes("textStyle").color??null;return i?Dd(i):null})},e={toggleBold(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleBold(),l&&(a=a.setTextSelection(i)),a.run()},toggleItalic(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleItalic(),l&&(a=a.setTextSelection(i)),a.run()},toggleUnderline(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleUnderline(),l&&(a=a.setTextSelection(i)),a.run()},setAlignment(r){const s=Oe.value;s&&s.chain().selectAll().setTextAlign(r).run()},setColor(r){const s=Oe.value;if(!s)return;const{from:i,to:l}=s.state.selection;i===l?s.chain().focus().selectAll().setColor(r).setTextSelection(l).run():s.chain().focus().setColor(r).run()}};function t(r,s,i){Oe.value=r,Gs.value=s,Js.value=i,r.on("selectionUpdate",()=>{Vt.value++}),r.on("transaction",()=>{Vt.value++})}function o(){Oe.value=null,Gs.value=null,Js.value=null}return{editor:Oe,blockElement:Js,textElement:Gs,state:n,commands:e,updateCounter:Vt,register:t,unregister:o}}const We=[dd,fd,hd,Hs,xd,md,gd,yd,kd.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function Zy(n){return n.type==="text"&&typeof n.text=="string"}function sn(n,e){if(Zy(n)){e(n);return}if(n.content)for(const t of n.content)sn(t,e)}function Ys(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)Ys(t,e)}function Qy(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function e1(n){var o,r;const e=(o=n.marks)==null?void 0:o.find(s=>s.type==="textStyle"),t=((r=e==null?void 0:e.attrs)==null?void 0:r.color)??null;return t?Dd(t):null}function t1(n,e){if(!n.trim())return!1;const t=Rt(n,We);let o=!1,r=!0,s=0;return sn(t,i=>{s++,Qy(i,e)?o=!0:r=!1}),s===0?!1:r?!0:o?null:!1}function n1(n){if(!n.trim())return"left";const e=Rt(n,We);let t="left";return Ys(e,o=>{var s;const r=(s=o.attrs)==null?void 0:s.textAlign;r&&(t=r)}),t}function o1(n){if(!n.trim())return null;const e=Rt(n,We);let t=null;return sn(e,o=>{t===null&&(t=e1(o))}),t}function Xs(n,e){if(!n.trim())return n;const t=Rt(n,We);return sn(t,o=>{const r=o.marks??[];r.findIndex(i=>i.type===e)===-1&&(o.marks=[...r,{type:e}])}),Ko(t,We)}function Zs(n,e){if(!n.trim())return n;const t=Rt(n,We);return sn(t,o=>{const r=o.marks??[];o.marks=r.filter(s=>s.type!==e)}),Ko(t,We)}function r1(n,e){if(!n.trim())return n;const t=Rt(n,We);return Ys(t,o=>{o.attrs={...o.attrs,textAlign:e}}),Ko(t,We)}function s1(n,e){if(!n.trim())return n;const t=Rt(n,We);return sn(t,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type==="textStyle");s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,color:e}},o.marks=r):o.marks=[...r,{type:"textStyle",attrs:{color:e}}]}),Ko(t,We)}function Vd(n){const e=document.querySelector(`[data-entity-id="${n}"]`);if(!e)return null;const t=e.firstElementChild;return t||e.querySelector(".wov-editable-text")}function $d(n,e,t,o){var a;const r=n.cloneNode(!0);r.style.position="absolute",r.style.visibility="hidden",r.style.pointerEvents="none",r.style.top="0",r.style.left="0";const s=r.classList.contains("wov-editable-text")?r:r.querySelector(".wov-editable-text");s&&(s.style.fontSize=`${o.fontSizePx}px`,s.style.fontFamily=o.fontFamily);const i=r.querySelector(".ProseMirror, .tiptap");i?i.innerHTML=o.content:s?s.innerHTML=o.content:r.innerHTML=o.content,(a=n.parentElement)==null||a.appendChild(r);const l=Ks(r,e,t);return r.remove(),l}function Ld(n){const{nextEditorTick:e}=le(),t=Pt(n,x.Text),o=Se(x.Camera),r=Se(x.Screen),s=lo(),i={hasTextEntities:c.computed(()=>{for(const p of t.value.values())if(p)return!0;return!1}),hasTextContent:c.computed(()=>{for(const p of t.value.values()){if(!p)continue;const h=p.content?Rt(p.content,We):null;if(h){let m=!1;if(sn(h,g=>{var y;(y=g.text)!=null&&y.trim()&&(m=!0)}),m)return!0}}return!1}),isBold:c.computed(()=>l("bold")),isItalic:c.computed(()=>l("italic")),isUnderline:c.computed(()=>l("underline")),alignment:c.computed(()=>{let p=null;for(const h of t.value.values()){if(!h)continue;const m=n1(h.content);if(p===null)p=m;else if(p!==m)return null}return p??"left"}),color:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values()){if(!m)continue;const g=o1(m.content);if(!h)p=g,h=!0;else if(p!==g)return null}return p}),fontSize:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values())if(m){if(!h)p=m.fontSizePx,h=!0;else if(p!==m.fontSizePx)return null}return p}),fontFamily:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values())if(m){if(!h)p=m.fontFamily,h=!0;else if(p!==m.fontFamily)return null}return p})};function l(p){let h=null,m=!1;for(const g of t.value.values()){if(!g)continue;const y=t1(g.content,p);if(!m)h=y,m=!0;else if(h!==y)return null}return h}const a={toggleBold(){u(p=>i.isBold.value?Zs(p,"bold"):Xs(p,"bold"))},toggleItalic(){u(p=>i.isItalic.value?Zs(p,"italic"):Xs(p,"italic"))},toggleUnderline(){u(p=>i.isUnderline.value?Zs(p,"underline"):Xs(p,"underline"))},setAlignment(p){f(h=>r1(h,p))},setColor(p){f(h=>s1(h,p))},setFontSize(p){d(h=>({...h,fontSizePx:p}),h=>{h.fontSizePx=p})},setFontFamily(p){d(h=>({...h,fontFamily:p}),h=>{h.fontFamily=p})}};function d(p,h){const m=c.toValue(n),g=[];for(const y of m){const k=t.value.get(y);if(!k)continue;const w=Vd(y);if(w){const b=$d(w,o,r,p(k));g.push({entityId:y,...b})}}e(y=>{for(const k of m)h(x.Text.write(y,k));for(const{entityId:k,width:w,height:b,left:S,top:v}of g){const E=x.Block.write(y,k);E.size=[w,b],E.position=[S,v]}c.nextTick(()=>{s.updateCounter.value++})})}function u(p){const h=c.toValue(n),m=[];for(const g of h){const y=t.value.get(g);if(!y)continue;const k=p(y.content),w=Vd(g);if(w){const b=$d(w,o,r,{...y,content:k});m.push({entityId:g,content:k,...b})}else m.push({entityId:g,content:k,width:0,height:0,left:0,top:0})}e(g=>{for(const{entityId:y,content:k,width:w,height:b,left:S,top:v}of m){const E=x.Text.write(g,y);if(E.content=k,w>0&&b>0){const C=x.Block.write(g,y);C.size=[w,b],C.position=[S,v]}}})}function f(p){const h=c.toValue(n);e(m=>{for(const g of h){const y=x.Text.write(m,g);y.content=p(y.content)}})}return{state:i,commands:a}}function ot(n){const e=lo(),t=Ld(n),o=e.state.hasEditor;return{state:c.reactive({hasTextToFormat:c.computed(()=>o.value||t.state.hasTextEntities.value),hasEditor:o,hasTextContent:c.computed(()=>t.state.hasTextContent.value),showTextMenuButtons:c.computed(()=>o.value||t.state.hasTextContent.value),isBold:c.computed(()=>o.value?e.state.isBold.value:t.state.isBold.value===!0),isItalic:c.computed(()=>o.value?e.state.isItalic.value:t.state.isItalic.value===!0),isUnderline:c.computed(()=>o.value?e.state.isUnderline.value:t.state.isUnderline.value===!0),alignment:c.computed(()=>o.value?e.state.alignment.value:t.state.alignment.value??"left"),color:c.computed(()=>o.value?e.state.color.value:t.state.color.value),fontSize:c.computed(()=>t.state.fontSize.value),fontFamily:c.computed(()=>t.state.fontFamily.value)}),commands:{toggleBold(){o.value?e.commands.toggleBold():t.commands.toggleBold()},toggleItalic(){o.value?e.commands.toggleItalic():t.commands.toggleItalic()},toggleUnderline(){o.value?e.commands.toggleUnderline():t.commands.toggleUnderline()},setAlignment(i){o.value?e.commands.setAlignment(i):t.commands.setAlignment(i)},setColor(i){o.value?e.commands.setColor(i):t.commands.setColor(i)},setFontSize(i){t.commands.setFontSize(i)},setFontFamily(i){t.commands.setFontFamily(i)}}}}function Qs(n){const e=Se(x.Camera),t=Se(x.Screen),o=Se(oe.TransformBoxStateSingleton),r=Se(oe.SelectionStateSingleton),{nextEditorTick:s}=le();let i=!1,l=null;function a(u,f){const{entityId:p}=c.toValue(n.blockData),h=c.toValue(n.minWidth)??0,m=c.toValue(n.minHeight)??0,g=Math.max(f.width,h),y=Math.max(f.height,m),k=x.Block.read(u,p),w=Math.abs(k.size[0]-g)>.5,b=Math.abs(k.size[1]-y)>.5;if(!w&&!b)return;const S=x.Block.write(u,p);S.size=[g,y],S.position=[f.left,f.top],o.value.transformBoxId!==null&&oe.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}c.watch(()=>r.value,()=>{s(u=>{const f=i1(u);if(i&&!f){const p=n.containerRef.value;if(!p)return;l=Ks(p,e,t),a(u,l),l=null}i=f})},{flush:"sync"});function d(u){const{content:f,...p}=u;s(h=>{const{entityId:m}=c.toValue(n.blockData);if(x.Text.read(h,m).content!==f){const y=x.Text.write(h,m);y.content=f}a(h,p)})}return{handleEditEnd:d}}function i1(n){const e=oe.SelectionStateSingleton.read(n);return e.state===oe.SelectionState.Dragging&&e.draggedEntity!==null&&x.hasComponent(n,e.draggedEntity,oe.TransformHandle)&&oe.TransformHandle.read(n,e.draggedEntity).kind===oe.TransformHandleKind.Stretch}function ei(){const n=c.inject(Nr);if(!n)throw new Error("useToolbar must be used within a Toolbar component");return{activeTool:n.activeTool,heldTool:n.heldTool,setTool:n.setTool,dragOutTool:n.dragOutTool,onToolPointerDown:n.onToolPointerDown,onToolPointerUp:n.onToolPointerUp,isActive:e=>c.computed(()=>n.activeTool.value===e)}}const l1=500,a1=1500;function zd(){const n=c.ref(null),e=c.ref(!1),t=c.ref(!1);let o=null,r=null;function s(){o&&(clearTimeout(o),o=null),r&&(clearTimeout(r),r=null)}function i(d,u){s(),n.value={text:d,anchor:u},t.value?e.value=!0:o=setTimeout(()=>{e.value=!0,t.value=!0,o=null},l1)}function l(){s(),e.value=!1,n.value=null,t.value&&(r=setTimeout(()=>{t.value=!1,r=null},a1))}function a(){s(),e.value=!1,n.value=null,t.value=!1}return{activeTooltip:c.readonly(n),isVisible:c.readonly(e),isWarmedUp:c.readonly(t),show:i,hide:l,reset:a}}function $t(){const n=c.inject(Ii);if(!n)throw new Error("useTooltipSingleton must be used within a WovenCanvas component");return n}const c1={key:1},d1=["innerHTML"],u1=50,f1=300,rr=c.defineComponent({__name:"EditableText",props:{blockElement:{},entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},emits:["editEnd"],setup(n,{expose:e,emit:t}){var v;const o=n,r=t,s=fe(o.entityId,x.Text),i=Se(x.Camera),l=Se(x.Screen),a=lo(),{nextEditorTick:d}=le(),u=Se(x.Mouse),f=c.ref(null);e({editableTextRef:f});const p=c.ref(((v=s.value)==null?void 0:v.content)??""),h=c.shallowRef(null);function m(E,C){var I;const M=s.value;return!M||M.constrainWidth||(((I=C.clipboardData)==null?void 0:I.getData("text/plain"))??"").length>u1&&d(_=>{const j=x.Text.write(_,o.entityId);j.constrainWidth=!0;const H=x.Block.read(_,o.entityId),K=Math.max(H.size[0],f1),G=x.Block.write(_,o.entityId);G.size=[K,H.size[1]],x.ResetKeyboard.spawn(_),oe.DeselectAll.spawn(_)}),!1}function g(){var E,C;return new ay({extensions:[dd,fd,hd,Hs,xd,md,gd,yd,kd.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((E=s.value)==null?void 0:E.defaultAlignment)??"left"}),Xy],content:((C=s.value)==null?void 0:C.content)??"",editable:!0,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:m}})}c.watch(()=>o.edited,async E=>{if(E&&f.value){if(h.value=g(),await y(h.value),!o.blockElement)return;a.register(h.value,f.value,o.blockElement)}else h.value&&(a.unregister(),k(h.value),h.value.destroy(),h.value=null)},{immediate:!0});async function y(E){var I;const C=(I=u.value)==null?void 0:I.position,M=l.value;await c.nextTick(),await new Promise(_=>requestAnimationFrame(_));const B=f.value;if(C&&M&&B){const _=C[0]+M.left,j=C[1]+M.top,H=E.view.posAtCoords({left:_,top:j});if(H){E.chain().focus().setTextSelection(H.pos).run();return}}E.commands.focus("start")}function k(E){let C=E.getHTML();const B=C.replace(/<[^>]*>/g,"").trim().length>0;B||(C=""),p.value=C,d(I=>{var G,te;const _=x.getBlockDef(I,o.block.tag);if(!B&&((G=_.editOptions)!=null&&G.removeWhenTextEmpty)){x.removeEntity(I,o.entityId);return}const j=(te=f.value)==null?void 0:te.closest(".wov-block"),H=(j==null?void 0:j.firstElementChild)??f.value;if(!H){console.warn("EditableText: no element to measure");return}const K=Ks(H,i,l);r("editEnd",{content:C,...K})})}c.watch(()=>{var E;return(E=s.value)==null?void 0:E.content},E=>{E!==void 0&&(h.value?h.value.getHTML()!==E&&h.value.commands.setContent(E,{emitUpdate:!1}):p.value=E)});const w=c.computed(()=>{const E=s.value;if(!E)return{};const[C,M]=o.block.flip,B=C?-1:1,I=M?-1:1,_=C||M;return{fontFamily:E.fontFamily,fontSize:`${E.fontSizePx}px`,lineHeight:E.lineHeight,letterSpacing:`${E.letterSpacingEm}em`,width:E.constrainWidth?"100%":"fit-content",whiteSpace:E.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:o.edited?"auto":"none",userSelect:o.edited?"auto":"none",transform:_?`scale(${B}, ${I})`:void 0}});function b(E){E.key==="Control"||E.key==="Meta"||E.stopPropagation()}function S(E){o.edited&&E.stopPropagation()}return c.onUnmounted(()=>{h.value&&(a.unregister(),h.value.destroy(),h.value=null)}),(E,C)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"editableTextRef",ref:f,class:"wov-editable-text",style:c.normalizeStyle(w.value),onKeydown:b,onPointerdown:S,onPointermove:S,onPointerup:S},[h.value?(c.openBlock(),c.createBlock(c.unref(cy),{key:0,editor:h.value},null,8,["editor"])):(c.openBlock(),c.createElementBlock("div",c1,[c.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:p.value},null,8,d1)]))],36))}}),h1={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},p1=["d","fill","stroke","stroke-width","stroke-dasharray"],Fd=c.defineComponent({__name:"ShapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,x.Shape),o=fe(e.entityId,x.VerticalAlign),r=c.ref(null),s={[x.VerticalAlignment.Top]:"flex-start",[x.VerticalAlignment.Center]:"center",[x.VerticalAlignment.Bottom]:"flex-end"},i=c.computed(()=>t.value?`rgba(${t.value.fillRed}, ${t.value.fillGreen}, ${t.value.fillBlue}, ${(t.value.fillAlpha??255)/255})`:"rgba(0, 0, 0, 0)"),l=c.computed(()=>t.value?t.value.strokeKind===x.StrokeKind.None?"none":`rgba(${t.value.strokeRed}, ${t.value.strokeGreen}, ${t.value.strokeBlue}, ${t.value.strokeAlpha/255})`:"rgba(0, 0, 0, 1)"),a=c.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeWidth)??2}),d=c.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeKind)??x.StrokeKind.Solid}),u=c.computed(()=>{var g;return _n[((g=t.value)==null?void 0:g.kind)??"rectangle"]??_n.rectangle}),f=c.computed(()=>{const g=a.value;switch(d.value){case x.StrokeKind.Dashed:return`${g*3} ${g*3}`;case x.StrokeKind.None:return"";case x.StrokeKind.Solid:default:return""}}),p=c.computed(()=>{var g;return{overflow:e.edited?"visible":"hidden",alignItems:s[((g=o.value)==null?void 0:g.value)??x.VerticalAlignment.Top]}}),{nextEditorTick:h}=le();function m(g){h(y=>{if(x.Text.read(y,e.entityId).content===g.content)return;const w=x.Text.write(y,e.entityId);w.content=g.content})}return(g,y)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-shape-block"},[(c.openBlock(),c.createElementBlock("svg",h1,[c.createElementVNode("path",{d:u.value,fill:i.value,stroke:l.value,"stroke-width":a.value,"stroke-dasharray":f.value,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":"non-scaling-stroke"},null,8,p1)])),c.createElementVNode("div",{class:"wov-shape-content",style:c.normalizeStyle(p.value)},[c.createVNode(rr,c.mergeProps(e,{"block-element":r.value,onEditEnd:m}),null,16,["block-element"])],4)],512))}}),m1=["data-text-empty"],Hd=c.defineComponent({__name:"TextBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=c.ref(null),o=fe(e.entityId,x.Text),r=c.computed(()=>{var d;return(((d=o.value)==null?void 0:d.content)??"").replace(/<[^>]*>/g,"").trim().length===0}),s=c.computed(()=>{var l;return((l=o.value)==null?void 0:l.constrainWidth)??!1}),{handleEditEnd:i}=Qs({blockData:e,containerRef:t});return(l,a)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-text-block","data-text-empty":r.value||void 0,style:c.normalizeStyle({width:s.value?"100%":"fit-content"})},[c.createVNode(rr,c.mergeProps(e,{"block-element":t.value,onEditEnd:c.unref(i)}),null,16,["block-element","onEditEnd"])],12,m1))}}),sr=Math.min,ln=Math.max,ir=Math.round,lr=Math.floor,rt=n=>({x:n,y:n}),g1={left:"right",right:"left",bottom:"top",top:"bottom"},y1={start:"end",end:"start"};function Wd(n,e,t){return ln(n,sr(e,t))}function ar(n,e){return typeof n=="function"?n(e):n}function an(n){return n.split("-")[0]}function cr(n){return n.split("-")[1]}function jd(n){return n==="x"?"y":"x"}function Ud(n){return n==="y"?"height":"width"}const k1=new Set(["top","bottom"]);function Lt(n){return k1.has(an(n))?"y":"x"}function Kd(n){return jd(Lt(n))}function w1(n,e,t){t===void 0&&(t=!1);const o=cr(n),r=Kd(n),s=Ud(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=dr(i)),[i,dr(i)]}function b1(n){const e=dr(n);return[ti(n),e,ti(e)]}function ti(n){return n.replace(/start|end/g,e=>y1[e])}const qd=["left","right"],Jd=["right","left"],x1=["top","bottom"],S1=["bottom","top"];function C1(n,e,t){switch(n){case"top":case"bottom":return t?e?Jd:qd:e?qd:Jd;case"left":case"right":return e?x1:S1;default:return[]}}function v1(n,e,t,o){const r=cr(n);let s=C1(an(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(ti)))),s}function dr(n){return n.replace(/left|right|bottom|top/g,e=>g1[e])}function E1(n){return{top:0,right:0,bottom:0,left:0,...n}}function M1(n){return typeof n!="number"?E1(n):{top:n,right:n,bottom:n,left:n}}function ur(n){const{x:e,y:t,width:o,height:r}=n;return{width:o,height:r,top:t,left:e,right:e+o,bottom:t+r,x:e,y:t}}function Gd(n,e,t){let{reference:o,floating:r}=n;const s=Lt(e),i=Kd(e),l=Ud(i),a=an(e),d=s==="y",u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,p=o[l]/2-r[l]/2;let h;switch(a){case"top":h={x:u,y:o.y-r.height};break;case"bottom":h={x:u,y:o.y+o.height};break;case"right":h={x:o.x+o.width,y:f};break;case"left":h={x:o.x-r.width,y:f};break;default:h={x:o.x,y:o.y}}switch(cr(e)){case"start":h[i]-=p*(t&&d?-1:1);break;case"end":h[i]+=p*(t&&d?-1:1);break}return h}async function T1(n,e){var t;e===void 0&&(e={});const{x:o,y:r,platform:s,rects:i,elements:l,strategy:a}=n,{boundary:d="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=ar(e,n),m=M1(h),y=l[p?f==="floating"?"reference":"floating":f],k=ur(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(y)))==null||t?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:u,strategy:a})),w=f==="floating"?{x:o,y:r,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),S=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},v=ur(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:b,strategy:a}):w);return{top:(k.top-v.top+m.top)/S.y,bottom:(v.bottom-k.bottom+m.bottom)/S.y,left:(k.left-v.left+m.left)/S.x,right:(v.right-k.right+m.right)/S.x}}const N1=async(n,e,t)=>{const{placement:o="bottom",strategy:r="absolute",middleware:s=[],platform:i}=t,l=s.filter(Boolean),a=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:n,floating:e,strategy:r}),{x:u,y:f}=Gd(d,o,a),p=o,h={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:w}=l[y],{x:b,y:S,data:v,reset:E}=await w({x:u,y:f,initialPlacement:o,placement:p,strategy:r,middlewareData:h,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:T1},elements:{reference:n,floating:e}});u=b??u,f=S??f,h={...h,[k]:{...h[k],...v}},E&&m<=50&&(m++,typeof E=="object"&&(E.placement&&(p=E.placement),E.rects&&(d=E.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):E.rects),{x:u,y:f}=Gd(d,p,a)),y=-1)}return{x:u,y:f,placement:p,strategy:r,middlewareData:h}},B1=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,o;const{placement:r,middlewareData:s,rects:i,initialPlacement:l,platform:a,elements:d}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=ar(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=an(r),w=Lt(l),b=an(l)===l,S=await(a.isRTL==null?void 0:a.isRTL(d.floating)),v=p||(b||!g?[dr(l)]:b1(l)),E=m!=="none";!p&&E&&v.push(...v1(l,g,m,S));const C=[l,...v],M=await a.detectOverflow(e,y),B=[];let I=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&B.push(M[k]),f){const K=w1(r,i,S);B.push(M[K[0]],M[K[1]])}if(I=[...I,{placement:r,overflows:B}],!B.every(K=>K<=0)){var _,j;const K=(((_=s.flip)==null?void 0:_.index)||0)+1,G=C[K];if(G&&(!(f==="alignment"?w!==Lt(G):!1)||I.every(L=>Lt(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:K,overflows:I},reset:{placement:G}};let te=(j=I.filter(W=>W.overflows[0]<=0).sort((W,L)=>W.overflows[1]-L.overflows[1])[0])==null?void 0:j.placement;if(!te)switch(h){case"bestFit":{var H;const W=(H=I.filter(L=>{if(E){const F=Lt(L.placement);return F===w||F==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(F=>F>0).reduce((F,X)=>F+X,0)]).sort((L,F)=>L[1]-F[1])[0])==null?void 0:H[0];W&&(te=W);break}case"initialPlacement":te=l;break}if(r!==te)return{reset:{placement:te}}}return{}}}},A1=new Set(["left","top"]);async function I1(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=an(t),l=cr(t),a=Lt(t)==="y",d=A1.has(i)?-1:1,u=s&&a?-1:1,f=ar(e,n);let{mainAxis:p,crossAxis:h,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof m=="number"&&(h=l==="end"?m*-1:m),a?{x:h*u,y:p*d}:{x:p*d,y:h*u}}const O1=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,o;const{x:r,y:s,placement:i,middlewareData:l}=e,a=await I1(e,n);return i===((t=l.offset)==null?void 0:t.placement)&&(o=l.arrow)!=null&&o.alignmentOffset?{}:{x:r+a.x,y:s+a.y,data:{...a,placement:i}}}}},D1=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:o,placement:r,platform:s}=e,{mainAxis:i=!0,crossAxis:l=!1,limiter:a={fn:k=>{let{x:w,y:b}=k;return{x:w,y:b}}},...d}=ar(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),p=Lt(an(r)),h=jd(p);let m=u[h],g=u[p];if(i){const k=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+f[k],S=m-f[w];m=Wd(b,m,S)}if(l){const k=p==="y"?"top":"left",w=p==="y"?"bottom":"right",b=g+f[k],S=g-f[w];g=Wd(b,g,S)}const y=a.fn({...e,[h]:m,[p]:g});return{...y,data:{x:y.x-t,y:y.y-o,enabled:{[h]:i,[p]:l}}}}}};function fr(){return typeof window<"u"}function cn(n){return ni(n)?(n.nodeName||"").toLowerCase():"#document"}function Ve(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function st(n){var e;return(e=(ni(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function ni(n){return fr()?n instanceof Node||n instanceof Ve(n).Node:!1}function Je(n){return fr()?n instanceof Element||n instanceof Ve(n).Element:!1}function it(n){return fr()?n instanceof HTMLElement||n instanceof Ve(n).HTMLElement:!1}function Yd(n){return!fr()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Ve(n).ShadowRoot}const R1=new Set(["inline","contents"]);function ao(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=Ge(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!R1.has(r)}const _1=new Set(["table","td","th"]);function P1(n){return _1.has(cn(n))}const V1=[":popover-open",":modal"];function hr(n){return V1.some(e=>{try{return n.matches(e)}catch{return!1}})}const $1=["transform","translate","scale","rotate","perspective"],L1=["transform","translate","scale","rotate","perspective","filter"],z1=["paint","layout","strict","content"];function oi(n){const e=ri(),t=Je(n)?Ge(n):n;return $1.some(o=>t[o]?t[o]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||L1.some(o=>(t.willChange||"").includes(o))||z1.some(o=>(t.contain||"").includes(o))}function F1(n){let e=zt(n);for(;it(e)&&!An(e);){if(oi(e))return e;if(hr(e))return null;e=zt(e)}return null}function ri(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const H1=new Set(["html","body","#document"]);function An(n){return H1.has(cn(n))}function Ge(n){return Ve(n).getComputedStyle(n)}function pr(n){return Je(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function zt(n){if(cn(n)==="html")return n;const e=n.assignedSlot||n.parentNode||Yd(n)&&n.host||st(n);return Yd(e)?e.host:e}function Xd(n){const e=zt(n);return An(e)?n.ownerDocument?n.ownerDocument.body:n.body:it(e)&&ao(e)?e:Xd(e)}function co(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Xd(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=Ve(r);if(s){const l=si(i);return e.concat(i,i.visualViewport||[],ao(r)?r:[],l&&t?co(l):[])}return e.concat(r,co(r,[],t))}function si(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Zd(n){const e=Ge(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=it(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=ir(t)!==s||ir(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function ii(n){return Je(n)?n:n.contextElement}function In(n){const e=ii(n);if(!it(e))return rt(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=Zd(e);let i=(s?ir(t.width):t.width)/o,l=(s?ir(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const W1=rt(0);function Qd(n){const e=Ve(n);return!ri()||!e.visualViewport?W1:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function j1(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Ve(n)?!1:e}function dn(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=ii(n);let i=rt(1);e&&(o?Je(o)&&(i=In(o)):i=In(n));const l=j1(s,t,o)?Qd(s):rt(0);let a=(r.left+l.x)/i.x,d=(r.top+l.y)/i.y,u=r.width/i.x,f=r.height/i.y;if(s){const p=Ve(s),h=o&&Je(o)?Ve(o):o;let m=p,g=si(m);for(;g&&o&&h!==m;){const y=In(g),k=g.getBoundingClientRect(),w=Ge(g),b=k.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,S=k.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;a*=y.x,d*=y.y,u*=y.x,f*=y.y,a+=b,d+=S,m=Ve(g),g=si(m)}}return ur({width:u,height:f,x:a,y:d})}function mr(n,e){const t=pr(n).scrollLeft;return e?e.left+t:dn(st(n)).left+t}function eu(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-mr(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function U1(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=st(o),l=e?hr(e.floating):!1;if(o===i||l&&s)return t;let a={scrollLeft:0,scrollTop:0},d=rt(1);const u=rt(0),f=it(o);if((f||!f&&!s)&&((cn(o)!=="body"||ao(i))&&(a=pr(o)),it(o))){const h=dn(o);d=In(o),u.x=h.x+o.clientLeft,u.y=h.y+o.clientTop}const p=i&&!f&&!s?eu(i,a):rt(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-a.scrollLeft*d.x+u.x+p.x,y:t.y*d.y-a.scrollTop*d.y+u.y+p.y}}function K1(n){return Array.from(n.getClientRects())}function q1(n){const e=st(n),t=pr(n),o=n.ownerDocument.body,r=ln(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=ln(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+mr(n);const l=-t.scrollTop;return Ge(o).direction==="rtl"&&(i+=ln(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const tu=25;function J1(n,e){const t=Ve(n),o=st(n),r=t.visualViewport;let s=o.clientWidth,i=o.clientHeight,l=0,a=0;if(r){s=r.width,i=r.height;const u=ri();(!u||u&&e==="fixed")&&(l=r.offsetLeft,a=r.offsetTop)}const d=mr(o);if(d<=0){const u=o.ownerDocument,f=u.body,p=getComputedStyle(f),h=u.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(o.clientWidth-f.clientWidth-h);m<=tu&&(s-=m)}else d<=tu&&(s+=d);return{width:s,height:i,x:l,y:a}}const G1=new Set(["absolute","fixed"]);function Y1(n,e){const t=dn(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=it(n)?In(n):rt(1),i=n.clientWidth*s.x,l=n.clientHeight*s.y,a=r*s.x,d=o*s.y;return{width:i,height:l,x:a,y:d}}function nu(n,e,t){let o;if(e==="viewport")o=J1(n,t);else if(e==="document")o=q1(st(n));else if(Je(e))o=Y1(e,t);else{const r=Qd(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return ur(o)}function ou(n,e){const t=zt(n);return t===e||!Je(t)||An(t)?!1:Ge(t).position==="fixed"||ou(t,e)}function X1(n,e){const t=e.get(n);if(t)return t;let o=co(n,[],!1).filter(l=>Je(l)&&cn(l)!=="body"),r=null;const s=Ge(n).position==="fixed";let i=s?zt(n):n;for(;Je(i)&&!An(i);){const l=Ge(i),a=oi(i);!a&&l.position==="fixed"&&(r=null),(s?!a&&!r:!a&&l.position==="static"&&!!r&&G1.has(r.position)||ao(i)&&!a&&ou(n,i))?o=o.filter(u=>u!==i):r=l,i=zt(i)}return e.set(n,o),o}function Z1(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?hr(e)?[]:X1(e,this._c):[].concat(t),o],l=i[0],a=i.reduce((d,u)=>{const f=nu(e,u,r);return d.top=ln(f.top,d.top),d.right=sr(f.right,d.right),d.bottom=sr(f.bottom,d.bottom),d.left=ln(f.left,d.left),d},nu(e,l,r));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function Q1(n){const{width:e,height:t}=Zd(n);return{width:e,height:t}}function ek(n,e,t){const o=it(e),r=st(e),s=t==="fixed",i=dn(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const a=rt(0);function d(){a.x=mr(r)}if(o||!o&&!s)if((cn(e)!=="body"||ao(r))&&(l=pr(e)),o){const h=dn(e,!0,s,e);a.x=h.x+e.clientLeft,a.y=h.y+e.clientTop}else r&&d();s&&!o&&r&&d();const u=r&&!o&&!s?eu(r,l):rt(0),f=i.left+l.scrollLeft-a.x-u.x,p=i.top+l.scrollTop-a.y-u.y;return{x:f,y:p,width:i.width,height:i.height}}function li(n){return Ge(n).position==="static"}function ru(n,e){if(!it(n)||Ge(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return st(n)===t&&(t=t.ownerDocument.body),t}function su(n,e){const t=Ve(n);if(hr(n))return t;if(!it(n)){let r=zt(n);for(;r&&!An(r);){if(Je(r)&&!li(r))return r;r=zt(r)}return t}let o=ru(n,e);for(;o&&P1(o)&&li(o);)o=ru(o,e);return o&&An(o)&&li(o)&&!oi(o)?t:o||F1(n)||t}const tk=async function(n){const e=this.getOffsetParent||su,t=this.getDimensions,o=await t(n.floating);return{reference:ek(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function nk(n){return Ge(n).direction==="rtl"}const ok={convertOffsetParentRelativeRectToViewportRelativeRect:U1,getDocumentElement:st,getClippingRect:Z1,getOffsetParent:su,getElementRects:tk,getClientRects:K1,getDimensions:Q1,getScale:In,isElement:Je,isRTL:nk};function iu(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function rk(n,e){let t=null,o;const r=st(n);function s(){var l;clearTimeout(o),(l=t)==null||l.disconnect(),t=null}function i(l,a){l===void 0&&(l=!1),a===void 0&&(a=1),s();const d=n.getBoundingClientRect(),{left:u,top:f,width:p,height:h}=d;if(l||e(),!p||!h)return;const m=lr(f),g=lr(r.clientWidth-(u+p)),y=lr(r.clientHeight-(f+h)),k=lr(u),b={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:ln(0,sr(1,a))||1};let S=!0;function v(E){const C=E[0].intersectionRatio;if(C!==a){if(!S)return i();C?i(!1,C):o=setTimeout(()=>{i(!1,1e-7)},1e3)}C===1&&!iu(d,n.getBoundingClientRect())&&i(),S=!1}try{t=new IntersectionObserver(v,{...b,root:r.ownerDocument})}catch{t=new IntersectionObserver(v,b)}t.observe(n)}return i(!0),s}function lu(n,e,t,o){o===void 0&&(o={});const{ancestorScroll:r=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:a=!1}=o,d=ii(n),u=r||s?[...d?co(d):[],...co(e)]:[];u.forEach(k=>{r&&k.addEventListener("scroll",t,{passive:!0}),s&&k.addEventListener("resize",t)});const f=d&&l?rk(d,t):null;let p=-1,h=null;i&&(h=new ResizeObserver(k=>{let[w]=k;w&&w.target===d&&h&&(h.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=h)==null||b.observe(e)})),t()}),d&&!a&&h.observe(d),h.observe(e));let m,g=a?dn(n):null;a&&y();function y(){const k=dn(n);g&&!iu(g,k)&&t(),g=k,m=requestAnimationFrame(y)}return t(),()=>{var k;u.forEach(w=>{r&&w.removeEventListener("scroll",t),s&&w.removeEventListener("resize",t)}),f==null||f(),(k=h)==null||k.disconnect(),h=null,a&&cancelAnimationFrame(m)}}const gr=O1,yr=D1,kr=B1,sk=(n,e,t)=>{const o=new Map,r={platform:ok,...t},s={...r.platform,_c:o};return N1(n,e,{...r,platform:s})};function ik(n){return n!=null&&typeof n=="object"&&"$el"in n}function au(n){if(ik(n)){const e=n.$el;return ni(e)&&cn(e)==="#comment"?null:e}return n}function uo(n){return typeof n=="function"?n():c.unref(n)}function cu(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function du(n,e){const t=cu(n);return Math.round(e*t)/t}function wr(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=c.computed(()=>{var C;return(C=uo(t.open))!=null?C:!0}),s=c.computed(()=>uo(t.middleware)),i=c.computed(()=>{var C;return(C=uo(t.placement))!=null?C:"bottom"}),l=c.computed(()=>{var C;return(C=uo(t.strategy))!=null?C:"absolute"}),a=c.computed(()=>{var C;return(C=uo(t.transform))!=null?C:!0}),d=c.computed(()=>au(n.value)),u=c.computed(()=>au(e.value)),f=c.ref(0),p=c.ref(0),h=c.ref(l.value),m=c.ref(i.value),g=c.shallowRef({}),y=c.ref(!1),k=c.computed(()=>{const C={position:h.value,left:"0",top:"0"};if(!u.value)return C;const M=du(u.value,f.value),B=du(u.value,p.value);return a.value?{...C,transform:"translate("+M+"px, "+B+"px)",...cu(u.value)>=1.5&&{willChange:"transform"}}:{position:h.value,left:M+"px",top:B+"px"}});let w;function b(){if(d.value==null||u.value==null)return;const C=r.value;sk(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(M=>{f.value=M.x,p.value=M.y,h.value=M.strategy,m.value=M.placement,g.value=M.middlewareData,y.value=C!==!1})}function S(){typeof w=="function"&&(w(),w=void 0)}function v(){if(S(),o===void 0){b();return}if(d.value!=null&&u.value!=null){w=o(d.value,u.value,b);return}}function E(){r.value||(y.value=!1)}return c.watch([s,i,l,r],b,{flush:"sync"}),c.watch([d,u],v,{flush:"sync"}),c.watch(r,E,{flush:"sync"}),c.getCurrentScope()&&c.onScopeDispose(S),{x:c.shallowReadonly(f),y:c.shallowReadonly(p),strategy:c.shallowReadonly(h),placement:c.shallowReadonly(m),middlewareData:c.shallowReadonly(g),isPositioned:c.shallowReadonly(y),floatingStyles:k,update:b}}const lk=["menu-open"],je=c.defineComponent({__name:"MenuDropdown",props:{title:{},disabled:{type:Boolean},placement:{default:"top"},offsetPx:{default:8}},emits:["open","close"],setup(n,{emit:e}){const t=n,o=e,r=c.inject("containerRef"),s=c.inject(Ni,null),i=c.inject(Bi,0),l=Math.random().toString(36).slice(2);c.provide(Bi,i+1);const{show:a,hide:d}=$t(),u=c.ref(!1);s&&c.watch(()=>s.value.get(i),b=>{b!==void 0&&b!==l&&u.value&&(u.value=!1)});const f=c.ref(null),p=c.ref(null),{floatingStyles:h}=wr(f,p,{placement:t.placement,middleware:[gr(t.offsetPx),kr(),yr({padding:8})],whileElementsMounted:lu});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(b){var M,B,I;const S=b.target,v=(M=f.value)==null?void 0:M.contains(S),E=(B=p.value)==null?void 0:B.contains(S),C=(I=S.closest)==null?void 0:I.call(S,".wov-menu-dropdown");!v&&!E&&!C&&g()}function k(){t.title&&f.value&&!u.value&&a(t.title,f.value)}function w(){d()}return c.watch(u,b=>{b?(d(),document.addEventListener("click",y,!0),s&&(s.value.set(i,l),s.value=new Map(s.value)),o("open")):(document.removeEventListener("click",y,!0),(s==null?void 0:s.value.get(i))===l&&(s.value.delete(i),s.value=new Map(s.value)),o("close"))}),c.onUnmounted(()=>{document.removeEventListener("click",y,!0)}),(b,S)=>(c.openBlock(),c.createElementBlock(c.Fragment,null,[c.createElementVNode("div",{ref_key:"buttonRef",ref:f,class:c.normalizeClass(["wov-menu-dropdown-trigger",{"is-open":u.value}]),"menu-open":u.value||void 0,onMousedown:S[0]||(S[0]=c.withModifiers(()=>{},["prevent"])),onClick:m,onMouseenter:k,onMouseleave:w},[c.renderSlot(b.$slots,"button",{isOpen:u.value})],42,lk),c.unref(r)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(r)},[u.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:p,class:"wov-menu-dropdown",style:c.normalizeStyle(c.unref(h))},[c.renderSlot(b.$slots,"dropdown",{close:g})],4)):c.createCommentVNode("",!0)],8,["to"])):c.createCommentVNode("",!0)],64))}}),ak={},ck={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function dk(n,e){return c.openBlock(),c.createElementBlock("svg",ck,[...e[0]||(e[0]=[c.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"},null,-1)])])}const Ue=Wt(ak,[["render",dk]]),uk={class:"wov-menu-button"},fk=["innerHTML"],hk=["onClick"],pk=["innerHTML"],ai=c.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=c.shallowRef(null),r=c.computed(()=>{const l=o.value??(e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V);return mn(l)});t(l=>{let a=null;for(const d of e.entityIds){if(x.hasComponent(l,d,Y.ElbowArrow)){const u=Y.ElbowArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(a===null)a=f;else if(f!==a){o.value=e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V;return}}if(x.hasComponent(l,d,Y.ArcArrow)){const u=Y.ArcArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(a===null)a=f;else if(f!==a){o.value=e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V;return}}}o.value=a});function s(l){o.value=l,t(a=>{for(const d of e.entityIds){if(x.hasComponent(a,d,Y.ElbowArrow)){const u=Y.ElbowArrow.write(a,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(x.hasComponent(a,d,Y.ArcArrow)){const u=Y.ArcArrow.write(a,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}}})}function i(l){if(!l)return"";const a=e.side==="start";return`<line x1="${a?8:4}" y1="12" x2="${a?20:16}" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round" /><g transform="${`translate(${a?4:20}, 12) scale(${a?"-0.8, 0.8":"0.8"})`}">${l.svg}</g>`}return(l,a)=>(c.openBlock(),c.createBlock(je,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:c.withCtx(()=>[c.createElementVNode("div",uk,[(c.openBlock(),c.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",innerHTML:i(r.value)},null,8,fk)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(c.unref(Tr),d=>(c.openBlock(),c.createElementBlock("button",{key:d.kind,class:c.normalizeClass(["wov-menu-option",{"is-active":o.value===d.kind}]),onClick:u=>s(d.kind)},[(c.openBlock(),c.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",innerHTML:i(d)},null,8,pk))],10,hk))),128))]),_:1},8,["title"]))}}),mk={class:"wov-menu-button"},gk=["onClick"],uu=c.defineComponent({__name:"ArrowThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:2},{label:"M",value:4},{label:"L",value:8}],t=n,{nextEditorTick:o}=le(),r=c.shallowRef(null);o(i=>{let l=null;for(const a of t.entityIds){if(x.hasComponent(i,a,Y.ElbowArrow)){const d=Y.ElbowArrow.read(i,a);if(l===null)l=d.thickness;else if(d.thickness!==l){r.value=null;return}}if(x.hasComponent(i,a,Y.ArcArrow)){const d=Y.ArcArrow.getThickness(i,a);if(l===null)l=d;else if(d!==l){r.value=null;return}}}r.value=l});function s(i){r.value=i,o(l=>{for(const a of t.entityIds){if(x.hasComponent(l,a,Y.ElbowArrow)){const d=Y.ElbowArrow.write(l,a);d.thickness=i}x.hasComponent(l,a,Y.ArcArrow)&&Y.ArcArrow.setThickness(l,a,i)}})}return(i,l)=>(c.openBlock(),c.createBlock(je,{title:"Thickness"},{button:c.withCtx(()=>[c.createElementVNode("div",mk,[l[0]||(l[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[c.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),c.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),c.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(e,a=>c.createElementVNode("button",{key:a.value,class:c.normalizeClass(["wov-menu-option wov-arrow-thickness-option",{"is-active":r.value===a.value}]),onClick:d=>s(a.value)},c.toDisplayString(a.label),11,gk)),64))]),_:1}))}}),yk=["value"],kk=c.defineComponent({__name:"ColorInput",props:{modelValue:{}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(t.modelValue??"");c.watch(()=>t.modelValue,u=>{u&&u!==r.value&&(r.value=u)});function s(u){const f=u.startsWith("#")?u:`#${u}`;return/^#[0-9A-Fa-f]{6}$/.test(f)}function i(u){return(u.startsWith("#")?u:`#${u}`).toLowerCase()}function l(u){let p=u.target.value;if((p.length===6||p.length===7)&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h)}}function a(u){const p=u.target.value;if(p&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h)}else t.modelValue&&(r.value=t.modelValue)}function d(u){if(u.stopPropagation(),u.key==="Enter"){const f=u.target,p=f.value;if(p&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h),setTimeout(()=>f.select())}}}return(u,f)=>(c.openBlock(),c.createElementBlock("input",{id:"wov-color-input",class:"wov-color-input",type:"text",size:"1","aria-label":"Hex color value",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",value:r.value,onInput:l,onChange:a,onKeydown:d},null,40,yk))}}),fu=c.defineComponent({__name:"ColorSlider",props:{modelValue:{},thumbColor:{},background:{}},emits:["update:modelValue"],setup(n,{expose:e,emit:t}){const o=t,r=c.ref(null),s=c.ref(!1);function i(d){s.value=!0,l(d),window.addEventListener("pointermove",l),window.addEventListener("pointerup",a)}function l(d){if(!r.value)return;const u=r.value.getBoundingClientRect(),f=Math.max(0,Math.min(100,(d.clientY-u.top)/u.height*100));o("update:modelValue",f)}function a(){s.value=!1,window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",a)}return e({isDragging:s}),(d,u)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"sliderRef",ref:r,class:"wov-color-slider",onPointerdown:c.withModifiers(i,["prevent"])},[n.background?(c.openBlock(),c.createElementBlock("div",{key:0,class:"wov-color-slider-gradient",style:c.normalizeStyle({background:n.background})},null,4)):c.createCommentVNode("",!0),c.createElementVNode("div",{class:"wov-color-slider-thumb",style:c.normalizeStyle({top:`${n.modelValue}%`,backgroundColor:n.thumbColor})},null,4)],544))}}),wk={class:"wov-color-picker"},bk={class:"wov-color-picker-area"},xk={class:"wov-color-picker-selector-gradient"},Sk="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",hu=c.defineComponent({__name:"ColorPicker",props:{modelValue:{},withOpacity:{type:Boolean}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(null),s=c.ref(null),i=c.ref(null),l=c.ref({x:100,y:0}),a=c.ref(0),d=c.ref(0),u=c.ref(!1),f=c.computed(()=>{var E,C;return u.value||((E=r.value)==null?void 0:E.isDragging)||((C=s.value)==null?void 0:C.isDragging)}),p=c.computed(()=>({h:a.value/100*360,s:l.value.x,v:100-l.value.y,a:(100-d.value)/100*255})),h=c.computed(()=>_d({h:p.value.h,s:100,v:100})),m=c.computed(()=>_d({h:p.value.h,s:p.value.s,v:p.value.v})),g=c.computed(()=>t.withOpacity?Pd(p.value):m.value),y=c.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(E){if(E){const C=Rd(E);l.value={x:C.s,y:100-C.v},a.value=C.h/360*100,d.value=100-C.a/255*100}}function w(E){k(E),o("update:modelValue",t.withOpacity?Pd(Rd(E)):E)}k(t.modelValue),c.watch(()=>t.modelValue,E=>{f.value||k(E)}),c.watch([l,a,d],()=>{f.value&&o("update:modelValue",g.value)});function b(E){u.value=!0,S(E),window.addEventListener("pointermove",S),window.addEventListener("pointerup",v)}function S(E){if(!i.value)return;const C=i.value.getBoundingClientRect(),M=Math.max(0,Math.min(100,(E.clientX-C.left)/C.width*100)),B=Math.max(0,Math.min(100,(E.clientY-C.top)/C.height*100));l.value={x:M,y:B}}function v(){u.value=!1,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",v)}return(E,C)=>(c.openBlock(),c.createElementBlock("div",wk,[c.createVNode(kk,{modelValue:g.value,"onUpdate:modelValue":w},null,8,["modelValue"]),c.createElementVNode("div",bk,[c.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:c.normalizeStyle({backgroundColor:h.value}),onPointerdown:c.withModifiers(b,["prevent"])},[c.createElementVNode("div",xk,[c.createElementVNode("div",{class:"wov-color-picker-selector-thumb",style:c.normalizeStyle({left:`${l.value.x}%`,top:`${l.value.y}%`,backgroundColor:m.value})},null,4)])],36),c.createVNode(fu,{ref_key:"hueSliderRef",ref:r,modelValue:a.value,"onUpdate:modelValue":C[0]||(C[0]=M=>a.value=M),thumbColor:h.value,background:Sk},null,8,["modelValue","thumbColor"]),n.withOpacity?(c.openBlock(),c.createBlock(fu,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:d.value,"onUpdate:modelValue":C[1]||(C[1]=M=>d.value=M),thumbColor:m.value,background:y.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):c.createCommentVNode("",!0)])]))}}),Ck={class:"wov-color-bubbles-container"},vk={key:1,class:"wov-color-bubbles"},Ek=["onClick"],br=c.defineComponent({__name:"ColorBubbles",props:{currentColor:{},palette:{},hideHighlight:{type:Boolean},withPicker:{type:Boolean},withOpacity:{type:Boolean}},emits:["change","picker-open"],setup(n,{emit:e}){const t=n,o=e,r=["#000000","#374151","#6B7280","#9CA3AF","#D1D5DB","#FFFFFF","#EF4444","#F97316","#EAB308","#22C55E","#14B8A6","#3B82F6","#8B5CF6","#EC4899"],s=c.computed(()=>{const m=t.palette??r,g=t.withPicker,y=m.length%2===1;return g&&!y||!g&&y?m.slice(0,-1):m}),i=c.ref(!1),l=c.ref(t.currentColor??"#ff0000");function a(m,g){const y=k=>{const w=k.replace(/^#/,"").toLowerCase();return w.length===6?w+"ff":w};return y(m)===y(g)}function d(m){return t.hideHighlight||!t.currentColor?!1:a(t.currentColor,m)}function u(){return t.hideHighlight||!t.currentColor?!1:!s.value.some(m=>a(t.currentColor,m))}function f(m){const g=qs(m);g&&o("change",g)}function p(){!i.value&&t.currentColor&&(l.value=t.currentColor),i.value=!i.value,o("picker-open",i.value)}function h(m){l.value=m;const g=qs(m);g&&o("change",g)}return(m,g)=>(c.openBlock(),c.createElementBlock("div",Ck,[i.value?(c.openBlock(),c.createBlock(hu,{key:0,modelValue:l.value,"onUpdate:modelValue":[g[0]||(g[0]=y=>l.value=y),h],withOpacity:n.withOpacity},null,8,["modelValue","withOpacity"])):(c.openBlock(),c.createElementBlock("div",vk,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,y=>(c.openBlock(),c.createElementBlock("div",{key:y,class:c.normalizeClass(["wov-color-bubble",{selected:d(y)}]),style:c.normalizeStyle({backgroundColor:y}),onMousedown:g[1]||(g[1]=c.withModifiers(()=>{},["prevent"])),onClick:k=>f(y)},null,46,Ek))),128)),n.withPicker?(c.openBlock(),c.createElementBlock("div",{key:0,class:c.normalizeClass(["wov-color-bubble wov-rainbow-bubble",{selected:u()}]),onMousedown:g[2]||(g[2]=c.withModifiers(()=>{},["prevent"])),onClick:p},null,34)):c.createCommentVNode("",!0)]))]))}}),Mk={class:"wov-color-button"},pu=c.defineComponent({__name:"ColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Pt(()=>e.entityIds,x.Color),r=c.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=io(u);d.add(f)}return Array.from(d)}),s=c.computed(()=>r.value.length>1),i=c.computed(()=>r.value[0]??null),l=c.computed(()=>{if(r.value.length===0)return{backgroundColor:"#000"};if(r.value.length>=2){const d=r.value[0],u=r.value[1];return{background:`linear-gradient(45deg, ${d} 0%, ${d} 50%, ${u} 50%, ${u} 100%)`}}return{backgroundColor:r.value[0]}});function a(d){const u=io(d);t(f=>{for(const p of e.entityIds)x.Color.fromHex(f,p,u)})}return(d,u)=>(c.openBlock(),c.createBlock(je,{title:"Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Mk,[c.createElementVNode("div",{class:"wov-color-swatch",style:c.normalizeStyle(l.value)},null,4),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createVNode(br,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,onChange:a},null,8,["currentColor","hideHighlight"])]),_:1}))}}),On=c.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(null),{show:s,hide:i}=$t();function l(u){o("click",u)}function a(){t.title&&r.value&&s(t.title,r.value)}function d(){i()}return(u,f)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:"wov-menu-button",onClick:l,onMouseenter:a,onMouseleave:d},[c.renderSlot(u.$slots,"default")],544))}}),ci=c.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=$t(),o=c.inject("containerRef"),r=c.ref(null),s=c.computed(()=>{var a;return((a=e.value)==null?void 0:a.anchor)??null}),{floatingStyles:i}=wr(s,r,{placement:"top",middleware:[gr(8),kr({fallbackPlacements:["bottom"]}),yr({padding:8})]}),l=c.computed(()=>{var a;return t.value&&((a=e.value)==null?void 0:a.text)});return(a,d)=>c.unref(o)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(o)},[c.createVNode(c.Transition,{name:"wov-tooltip-fade"},{default:c.withCtx(()=>{var u;return[l.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:r,class:"wov-menu-tooltip",style:c.normalizeStyle(c.unref(i))},c.toDisplayString((u=c.unref(e))==null?void 0:u.text),5)):c.createCommentVNode("",!0)]}),_:1})],8,["to"])):c.createCommentVNode("",!0)}}),Tk={class:"wov-menu-button"},Nk=["onClick"],mu=c.defineComponent({__name:"PenStrokeThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:4},{label:"M",value:8},{label:"L",value:16}],t=n,{nextEditorTick:o}=le(),r=Pt(()=>t.entityIds,mo.PenStroke),s=c.computed(()=>{let l=null;for(const a of r.value.values())if(a){if(l===null)l=a.thickness;else if(a.thickness!==l)return null}return l});function i(l){o(a=>{for(const d of t.entityIds){const u=mo.PenStroke.write(a,d);u.thickness=l}})}return(l,a)=>(c.openBlock(),c.createBlock(je,{title:"Thickness"},{button:c.withCtx(()=>[c.createElementVNode("div",Tk,[a[0]||(a[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[c.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),c.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),c.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(e,d=>c.createElementVNode("button",{key:d.value,class:c.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":s.value===d.value}]),onClick:u=>i(d.value)},c.toDisplayString(d.label),11,Nk)),64))]),_:1}))}}),Bk={class:"wov-fill-color-button"},Ak={class:"wov-fill-dropdown"},Ik={key:0,class:"wov-fill-mode-section"},Ok=["title","onClick"],Dk={viewBox:"0 0 24 24",fill:"none"},Rk=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],gu=c.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Pt(()=>e.entityIds,x.Shape),r=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],s=c.computed(()=>{const h=o.value.values().next().value,m=(h==null?void 0:h.fillAlpha)??255;return m===0?"none":m<200?"faded":"solid"}),i=c.computed(()=>{const h=new Set;for(const m of o.value.values())if(m){const g=m.fillAlpha??255;g===0?h.add("none"):g<200?h.add("faded"):h.add("solid")}return h.size>1});function l(h){t(m=>{for(const g of e.entityIds){const y=x.Shape.write(m,g);y.fillAlpha=h}})}const a=c.computed(()=>{const h=new Set;for(const m of o.value.values())if(m){const g=io({red:m.fillRed,green:m.fillGreen,blue:m.fillBlue,alpha:m.fillAlpha??255});h.add(g)}return Array.from(h)}),d=c.computed(()=>a.value.length>1),u=c.computed(()=>a.value[0]??"#4a90d9");function f(h){t(m=>{for(const g of e.entityIds){const y=x.Shape.write(m,g);y.fillRed=h.red,y.fillGreen=h.green,y.fillBlue=h.blue,y.fillAlpha=h.alpha}})}const p=c.ref(!1);return(h,m)=>(c.openBlock(),c.createBlock(je,{title:"Fill Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Bk,[m[1]||(m[1]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-fill-color-icon",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M5.879,2.625L14.121,2.625C15.906,2.625 17.375,4.094 17.375,5.879L17.375,14.121C17.375,15.906 15.906,17.375 14.121,17.375L5.88,17.375C4.095,17.375 2.626,15.906 2.626,14.121L2.626,5.88C2.626,4.095 4.095,2.626 5.88,2.626L5.879,2.625Z","stroke-width":"1.25"}),c.createElementVNode("path",{d:"M2.779,14.655L14.543,2.871M10.238,17.308L17.318,10.229M2.876,9.577L9.853,2.6M5.397,17.239L17.16,5.476","stroke-width":"1.25"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Ak,[p.value?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",Ik,[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(r,g=>c.createElementVNode("button",{key:g.mode,class:c.normalizeClass(["wov-fill-mode-option",{"is-active":!i.value&&g.mode===s.value}]),title:g.label,onClick:y=>l(g.alpha)},[(c.openBlock(),c.createElementBlock("svg",Dk,[c.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:g.mode==="none"?"none":"currentColor","fill-opacity":g.mode==="faded"?.4:1,stroke:g.mode==="none"?"currentColor":"none","stroke-width":g.mode==="none"?1.5:0,"stroke-dasharray":g.mode==="none"?"3 3":""},null,8,Rk)])),c.createElementVNode("span",null,c.toDisplayString(g.label),1)],10,Ok)),64))])),c.createVNode(br,{currentColor:u.value,hideHighlight:d.value,withPicker:!0,withOpacity:!0,onChange:f,onPickerOpen:m[0]||(m[0]=g=>p.value=g)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),_k={class:"wov-shape-kind-button"},Pk={class:"wov-shape-kind-dropdown"},Vk=["onClick"],$k={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},Lk=["d"],yu=c.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Pt(()=>e.entityIds,x.Shape),r=c.computed(()=>{const a=o.value.values().next().value;return(a==null?void 0:a.kind)??"rectangle"}),s=c.computed(()=>{const a=new Set;for(const d of o.value.values())d&&a.add(d.kind);return a.size>1}),i=c.computed(()=>Object.keys(_n).map(a=>({kind:a,label:a.charAt(0).toUpperCase()+a.slice(1)})));function l(a){t(d=>{for(const u of e.entityIds){const f=x.Shape.write(d,u);f.kind=a}})}return(a,d)=>(c.openBlock(),c.createBlock(je,{title:"Shape Type"},{button:c.withCtx(()=>[c.createElementVNode("div",_k,[d[0]||(d[0]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-shape-kind-icon",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("circle",{cx:"6",cy:"6",r:"5"}),c.createElementVNode("rect",{x:"6",y:"6",width:"10",height:"10",fill:"var(--wov-gray-600)"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Pk,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(i.value,u=>(c.openBlock(),c.createElementBlock("button",{key:u.kind,class:c.normalizeClass(["wov-shape-kind-option",{"is-selected":!s.value&&u.kind===r.value}]),onClick:f=>l(u.kind)},[(c.openBlock(),c.createElementBlock("svg",$k,[c.createElementVNode("path",{d:c.unref(_n)[u.kind],transform:"translate(2, 2) scale(0.16)"},null,8,Lk)])),c.createElementVNode("span",null,c.toDisplayString(u.label),1)],10,Vk))),128))])]),_:1}))}}),zk={class:"wov-stroke-style-section"},Fk=["title","onClick"],Hk={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},Wk=["stroke-dasharray","stroke-opacity"],jk=c.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(n,{emit:e}){const t=e,o=[{kind:x.StrokeKind.Solid,label:"Solid"},{kind:x.StrokeKind.Dashed,label:"Dashed"},{kind:x.StrokeKind.None,label:"None"}];function r(i){switch(i){case x.StrokeKind.Dashed:return"6 6";case x.StrokeKind.None:return"";case x.StrokeKind.Solid:default:return""}}function s(i){t("change",i)}return(i,l)=>(c.openBlock(),c.createElementBlock("div",zk,[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(o,a=>c.createElementVNode("button",{key:a.kind,class:c.normalizeClass(["wov-stroke-style-option",{"is-active":!n.hasMultipleStyles&&a.kind===n.currentStyle}]),title:a.label,onClick:d=>s(a.kind)},[(c.openBlock(),c.createElementBlock("svg",Hk,[c.createElementVNode("line",{x1:"2",y1:"4",x2:"22",y2:"4","stroke-linecap":"round","stroke-dasharray":r(a.kind),"stroke-opacity":a.kind===c.unref(x.StrokeKind).None?.3:1},null,8,Wk)])),c.createElementVNode("span",null,c.toDisplayString(a.label),1)],10,Fk)),64))]))}}),Uk={class:"wov-stroke-color-button"},Kk={class:"wov-stroke-dropdown"},qk={key:1,class:"wov-stroke-divider"},ku=c.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Pt(()=>e.entityIds,x.Shape),r=c.ref(!1),s=c.computed(()=>{const p=new Set;for(const h of o.value.values())if(h){const m=io({red:h.strokeRed,green:h.strokeGreen,blue:h.strokeBlue,alpha:255});p.add(m)}return Array.from(p)}),i=c.computed(()=>s.value.length>1),l=c.computed(()=>s.value[0]??"#000000"),a=c.computed(()=>{const p=o.value.values().next().value;return(p==null?void 0:p.strokeKind)??x.StrokeKind.Solid}),d=c.computed(()=>{const p=new Set;for(const h of o.value.values())h&&p.add(h.strokeKind);return p.size>1});function u(p){t(h=>{for(const m of e.entityIds){const g=x.Shape.write(h,m);g.strokeRed=p.red,g.strokeGreen=p.green,g.strokeBlue=p.blue}})}function f(p){t(h=>{for(const m of e.entityIds){const g=x.Shape.write(h,m);g.strokeKind=p}})}return(p,h)=>(c.openBlock(),c.createBlock(je,{title:"Stroke Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Uk,[h[1]||(h[1]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-stroke-color-icon",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43","stroke-width":"1.25"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Kk,[r.value?c.createCommentVNode("",!0):(c.openBlock(),c.createBlock(jk,{key:0,currentStyle:a.value,hasMultipleStyles:d.value,onChange:f},null,8,["currentStyle","hasMultipleStyles"])),r.value?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",qk)),c.createVNode(br,{currentColor:l.value,hideHighlight:i.value,withPicker:!0,onChange:u,onPickerOpen:h[0]||(h[0]=m=>r.value=m)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),Jk={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Gk={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Yk={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Xk={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},di=c.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=[x.TextAlignment.Left,x.TextAlignment.Center,x.TextAlignment.Right,x.TextAlignment.Justify];function s(){const i=r.indexOf(t.alignment),l=r[(i+1)%r.length];o.setAlignment(l)}return(i,l)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Text Align",onClick:s},{default:c.withCtx(()=>[c.unref(t).alignment===c.unref(x.TextAlignment).Left?(c.openBlock(),c.createElementBlock("svg",Jk,[...l[0]||(l[0]=[c.createElementVNode("path",{d:"M288 64c0 17.7-14.3 32-32 32L32 96C14.3 96 0 81.7 0 64S14.3 32 32 32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32L32 352c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):c.unref(t).alignment===c.unref(x.TextAlignment).Center?(c.openBlock(),c.createElementBlock("svg",Gk,[...l[1]||(l[1]=[c.createElementVNode("path",{d:"M352 64c0-17.7-14.3-32-32-32L128 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32zm96 128c0-17.7-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 448c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32zM352 320c0-17.7-14.3-32-32-32l-192 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32z"},null,-1)])])):c.unref(t).alignment===c.unref(x.TextAlignment).Right?(c.openBlock(),c.createElementBlock("svg",Yk,[...l[2]||(l[2]=[c.createElementVNode("path",{d:"M448 64c0 17.7-14.3 32-32 32L192 96c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32l-224 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):(c.openBlock(),c.createElementBlock("svg",Xk,[...l[3]||(l[3]=[c.createElementVNode("path",{d:"M448 64c0-17.7-14.3-32-32-32L32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l384 0c17.7 0 32-14.3 32-32zm0 256c0-17.7-14.3-32-32-32L32 288c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 192c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32zM448 448c0-17.7-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32z"},null,-1)])]))]),_:1})):c.createCommentVNode("",!0)}}),ui=c.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Bold",class:c.normalizeClass({"wov-active":c.unref(t).isBold}),onClick:c.unref(o).toggleBold},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[c.createElementVNode("path",{d:"M0 64C0 46.3 14.3 32 32 32l48 0 16 0 128 0c70.7 0 128 57.3 128 128c0 31.3-11.3 60.1-30 82.3c37.1 22.4 62 63.1 62 109.7c0 70.7-57.3 128-128 128L96 480l-16 0-48 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l16 0 0-160L48 96 32 96C14.3 96 0 81.7 0 64zM224 224c35.3 0 64-28.7 64-64s-28.7-64-64-64L112 96l0 128 112 0zM112 288l0 128 144 0c35.3 0 64-28.7 64-64s-28.7-64-64-64l-32 0-112 0z"})],-1)])]),_:1},8,["class","onClick"])):c.createCommentVNode("",!0)}});function Zk(n,e){return c.getCurrentScope()?(c.onScopeDispose(n,e),!0):!1}const Qk=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ew=Object.prototype.toString,tw=n=>ew.call(n)==="[object Object]",xr=()=>{};function Sr(n){return Array.isArray(n)?n:[n]}function nw(n){return c.getCurrentInstance()}function ow(n,e=!0,t){nw()?c.onMounted(n,t):e?n():c.nextTick(n)}function rw(n,e,t){return c.watch(n,e,{...t,immediate:!0})}const Cr=Qk?window:void 0;function Ye(n){var e;const t=c.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function fi(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=c.computed(()=>{const o=Sr(c.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return rw(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>Ye(s)))!==null&&o!==void 0?o:[Cr].filter(s=>s!=null),Sr(c.toValue(t.value?n[1]:n[0])),Sr(c.unref(t.value?n[2]:n[1])),c.toValue(t.value?n[3]:n[2])]},([o,r,s,i],l,a)=>{if(!(o!=null&&o.length)||!(r!=null&&r.length)||!(s!=null&&s.length))return;const d=tw(i)?{...i}:i,u=o.flatMap(f=>r.flatMap(p=>s.map(h=>e(f,p,h,d))));a(()=>{u.forEach(f=>f())})},{flush:"post"})}function sw(n,e,t={}){const{window:o=Cr,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:xr,cancel:xr,trigger:xr}:xr;let a=!0;const d=y=>c.toValue(r).some(k=>{if(typeof k=="string")return Array.from(o.document.querySelectorAll(k)).some(w=>w===y.target||y.composedPath().includes(w));{const w=Ye(k);return w&&(y.target===w||y.composedPath().includes(w))}});function u(y){const k=c.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const w=c.toValue(y),b=w.$.subTree&&w.$.subTree.children;return b==null||!Array.isArray(b)?!1:b.some(S=>S.el===k.target||k.composedPath().includes(S.el))}const p=y=>{const k=Ye(n);if(y.target!=null&&!(!(k instanceof Element)&&u(n)&&f(n,y))&&!(!k||k===y.target||y.composedPath().includes(k))){if("detail"in y&&y.detail===0&&(a=!d(y)),!a){a=!0;return}e(y)}};let h=!1;const m=[fi(o,"click",y=>{h||(h=!0,setTimeout(()=>{h=!1},0),p(y))},{passive:!0,capture:s}),fi(o,"pointerdown",y=>{const k=Ye(n);a=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&fi(o,"blur",y=>{setTimeout(()=>{var k;const w=Ye(n);((k=o.document.activeElement)===null||k===void 0?void 0:k.tagName)==="IFRAME"&&!(w!=null&&w.contains(o.document.activeElement))&&e(y)},0)},{passive:!0})].filter(Boolean),g=()=>m.forEach(y=>y());return l?{stop:g,cancel:()=>{a=!1},trigger:y=>{a=!0,p(y),a=!1}}:g}function iw(){const n=c.shallowRef(!1),e=c.getCurrentInstance();return e&&c.onMounted(()=>{n.value=!0},e),n}function lw(n){const e=iw();return c.computed(()=>(e.value,!!n()))}function aw(n,e,t={}){const{window:o=Cr,...r}=t;let s;const i=lw(()=>o&&"ResizeObserver"in o),l=()=>{s&&(s.disconnect(),s=void 0)},a=c.watch(c.computed(()=>{const u=c.toValue(n);return Array.isArray(u)?u.map(f=>Ye(f)):[Ye(u)]}),u=>{if(l(),i.value&&o){s=new ResizeObserver(e);for(const f of u)f&&s.observe(f,r)}},{immediate:!0,flush:"post"}),d=()=>{l(),a()};return Zk(d),{isSupported:i,stop:d}}function wu(n,e={width:0,height:0},t={}){const{window:o=Cr,box:r="content-box"}=t,s=c.computed(()=>{var f;return(f=Ye(n))===null||f===void 0||(f=f.namespaceURI)===null||f===void 0?void 0:f.includes("svg")}),i=c.shallowRef(e.width),l=c.shallowRef(e.height),{stop:a}=aw(n,([f])=>{const p=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const h=Ye(n);if(h){const m=h.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(p){const h=Sr(p);i.value=h.reduce((m,{inlineSize:g})=>m+g,0),l.value=h.reduce((m,{blockSize:g})=>m+g,0)}else i.value=f.contentRect.width,l.value=f.contentRect.height},t);ow(()=>{const f=Ye(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=c.watch(()=>Ye(n),f=>{i.value=f?e.width:0,l.value=f?e.height:0});function u(){a(),d()}return{width:i,height:l,stop:u}}function bu(){const n=c.inject($e);if(!n)throw new Error("useFonts must be used within a WovenCanvas component");return c.computed(()=>{const e=n.getEditor();return e?e.fonts.filter(t=>t.selectable):[]})}const cw={class:"wov-font-family-button"},dw={class:"wov-font-family-label"},uw={class:"wov-font-list"},fw=["onClick"],hw=["src","alt"],hi=c.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=bu(),s=c.computed(()=>r.value.map(u=>({name:u.name,displayName:u.displayName,previewImage:u.previewImage}))),i=c.computed(()=>t.fontFamily),l=c.computed(()=>{const u=i.value;if(u===null)return"Mixed";const f=s.value.find(p=>p.name===u);return(f==null?void 0:f.displayName)??u});function a(u){o.setFontFamily(u)}function d(u){u.stopPropagation()}return(u,f)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Font Family"},{button:c.withCtx(()=>[c.createElementVNode("div",cw,[c.createElementVNode("span",dw,c.toDisplayString(l.value),1),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",{class:"wov-font-family-menu",onWheel:d,onClick:f[0]||(f[0]=c.withModifiers(()=>{},["stop"]))},[c.createElementVNode("div",uw,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,p=>(c.openBlock(),c.createElementBlock("div",{key:p.name,class:c.normalizeClass(["wov-font-item",{active:i.value===p.name}]),onClick:h=>a(p.name)},[p.previewImage?(c.openBlock(),c.createElementBlock("img",{key:0,class:"wov-font-preview",src:p.previewImage,alt:p.name},null,8,hw)):(c.openBlock(),c.createElementBlock("span",{key:1,class:"wov-font-name",style:c.normalizeStyle({fontFamily:p.name})},c.toDisplayString(p.displayName),5))],10,fw))),128))])],32)]),_:1})):c.createCommentVNode("",!0)}}),pw={class:"wov-font-size-button"},mw={class:"wov-font-size-label"},gw=["onClick"],yw={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},kw={class:"wov-input-container"},ww=["value"],pi=c.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=[{label:"Small",value:16,displayValue:10},{label:"Medium",value:24,displayValue:12},{label:"Large",value:40,displayValue:16},{label:"Huge",value:96,displayValue:20}],s=c.computed(()=>t.fontSize),i=c.computed(()=>{const p=s.value;if(p===null)return"Mixed";const h=r.find(m=>m.value===p);return h?h.label:`${+p.toFixed(1)} px`}),l=c.computed(()=>{const p=s.value;return p===null?"":String(+p.toFixed(1))});function a(p){o.setFontSize(p)}function d(p){const h=p.target,m=Number.parseFloat(h.value);!Number.isNaN(m)&&m>0&&a(m)}function u(p){p.key==="Enter"&&p.target.blur()}function f(p){p.stopPropagation()}return(p,h)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Font Size"},{button:c.withCtx(()=>[c.createElementVNode("div",pw,[c.createElementVNode("span",mw,c.toDisplayString(i.value),1),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",{class:"wov-font-size-menu",onWheel:f,onClick:h[0]||(h[0]=c.withModifiers(()=>{},["stop"]))},[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(r,m=>c.createElementVNode("div",{key:m.value,class:c.normalizeClass(["wov-font-size-option",{active:s.value===m.value}]),onClick:g=>a(m.value)},[s.value===m.value?(c.openBlock(),c.createElementBlock("svg",yw,[...h[1]||(h[1]=[c.createElementVNode("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"},null,-1)])])):c.createCommentVNode("",!0),c.createElementVNode("span",{class:"wov-option-label",style:c.normalizeStyle({fontSize:`${m.displayValue}px`})},c.toDisplayString(m.label),5)],10,gw)),64)),h[3]||(h[3]=c.createElementVNode("div",{class:"wov-separator"},null,-1)),c.createElementVNode("div",kw,[c.createElementVNode("input",{class:"wov-custom-input",value:l.value,onInput:d,onKeydown:u,placeholder:"Custom size"},null,40,ww),h[2]||(h[2]=c.createElementVNode("span",{class:"wov-px-suffix"},"px",-1))])],32)]),_:1})):c.createCommentVNode("",!0)}}),mi=c.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Italic",class:c.normalizeClass({"wov-active":c.unref(t).isItalic}),onClick:c.unref(o).toggleItalic},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[c.createElementVNode("path",{d:"M128 64c0-17.7 14.3-32 32-32l192 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-58.7 0L160 416l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l58.7 0L224 96l-64 0c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):c.createCommentVNode("",!0)}}),gi=c.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Underline",class:c.normalizeClass({"wov-active":c.unref(t).isUnderline}),onClick:c.unref(o).toggleUnderline},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[c.createElementVNode("path",{d:"M16 64c0-17.7 14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 53 43 96 96 96s96-43 96-96l0-128-16 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 88.4-71.6 160-160 160s-160-71.6-160-160L64 96 48 96C30.3 96 16 81.7 16 64zM0 448c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):c.createCommentVNode("",!0)}}),bw={class:"wov-text-color-button"},xw={class:"wov-text-icon-container"},yi=c.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=c.computed(()=>t.color??"#000000"),s=c.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(io(l))}return(l,a)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Text Color"},{button:c.withCtx(()=>[c.createElementVNode("div",bw,[c.createElementVNode("div",xw,[a[0]||(a[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-icon"},[c.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),c.createElementVNode("div",{class:"wov-color-underline",style:c.normalizeStyle(s.value)},null,4)]),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createVNode(br,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):c.createCommentVNode("",!0)}}),Sw={key:0,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-start-icon lucide-align-vertical-justify-start"},Cw={key:1,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-center-icon lucide-align-vertical-justify-center"},vw={key:2,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-end-icon lucide-align-vertical-justify-end"},xu=c.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),{state:o}=ot(()=>e.entityIds),r=[x.VerticalAlignment.Top,x.VerticalAlignment.Center,x.VerticalAlignment.Bottom],s=Pt(()=>e.entityIds,x.VerticalAlign),i=c.computed(()=>{let a=null;for(const d of s.value.values()){const u=(d==null?void 0:d.value)??x.VerticalAlignment.Top;if(a===null)a=u;else if(a!==u)return null}return a});function l(){const a=i.value??x.VerticalAlignment.Top,d=r.indexOf(a),u=r[(d+1)%r.length];t(f=>{for(const p of e.entityIds){const h=x.VerticalAlign.write(f,p);h.value=u}})}return(a,d)=>c.unref(o).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Vertical Align",onClick:l},{default:c.withCtx(()=>[i.value===c.unref(x.VerticalAlignment).Top||i.value===null?(c.openBlock(),c.createElementBlock("svg",Sw,[...d[0]||(d[0]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 2h20"},null,-1)])])):i.value===c.unref(x.VerticalAlignment).Center?(c.openBlock(),c.createElementBlock("svg",Cw,[...d[1]||(d[1]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 12h20"},null,-1)])])):(c.openBlock(),c.createElementBlock("svg",vw,[...d[2]||(d[2]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 22h20"},null,-1)])]))]),_:1})):c.createCommentVNode("",!0)}}),Ew={class:"wov-text-group-button"},Mw={class:"wov-text-group-dropdown"},Tw={class:"wov-text-group-row wov-text-group-row-full"},Nw={class:"wov-text-group-row"},Bw=c.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean}},setup(n){const e=n,{state:t}=ot(()=>e.entityIds),o=c.inject("containerRef"),{width:r}=wu(o),s=c.computed(()=>r.value>0&&r.value<600),i=c.ref(new Map);return c.provide(Ni,i),(l,a)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createElementBlock(c.Fragment,{key:0},[s.value?(c.openBlock(),c.createBlock(je,{key:0,title:"Text Formatting",placement:"top"},{button:c.withCtx(()=>[c.createElementVNode("div",Ew,[a[0]||(a[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-group-icon"},[c.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Mw,[c.createElementVNode("div",Tw,[c.createVNode(hi,{entityIds:n.entityIds},null,8,["entityIds"]),a[1]||(a[1]=c.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),c.createVNode(pi,{entityIds:n.entityIds},null,8,["entityIds"])]),c.createElementVNode("div",Nw,[c.createVNode(ui,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(mi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(gi,{entityIds:n.entityIds},null,8,["entityIds"]),a[2]||(a[2]=c.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),c.createVNode(yi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(di,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(c.openBlock(),c.createBlock(xu,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):c.createCommentVNode("",!0)])])]),_:1})):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createVNode(hi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(pi,{entityIds:n.entityIds},null,8,["entityIds"]),a[3]||(a[3]=c.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),c.createVNode(ui,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(mi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(gi,{entityIds:n.entityIds},null,8,["entityIds"]),a[4]||(a[4]=c.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),c.createVNode(yi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(di,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(c.openBlock(),c.createBlock(xu,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):c.createCommentVNode("",!0)],64))],64)):c.createCommentVNode("",!0)}}),Su=c.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t=Se(x.Camera),o=Se(x.Grid),r=c.inject("containerRef"),s=c.ref({width:0,height:0});let i=null;const l=c.ref(null);let a=null;typeof document<"u"&&(a=document.createElement("canvas"));function d(y,k,w,b){const S=b/2;y.beginPath(),y.arc(k,w,S,0,Math.PI*2),y.fill()}function u(y,k,w){if(!a)return null;const b=w.dotSize??2,S=y*w.subdivisionStep,v=k*w.subdivisionStep;if(S<=0||v<=0)return null;a.width=S,a.height=v;const E=a.getContext("2d");if(!E)return null;if(E.clearRect(0,0,S,v),E.fillStyle=w.strokeColor,w.subdivisionStep===1)d(E,S/2,v/2,b);else for(let C=0;C<w.subdivisionStep;C++)for(let M=0;M<w.subdivisionStep;M++){const B=(C+.5)*(S/w.subdivisionStep),I=(M+.5)*(v/w.subdivisionStep),j=C===0&&M===0?2*b:b;d(E,B,I,j)}return E.createPattern(a,"repeat")}function f(y,k,w,b,S,v){y.lineWidth=v,y.beginPath(),y.moveTo(k,w),y.lineTo(b,S),y.stroke()}function p(y,k,w){if(!a)return null;const b=w.gridSize??1,S=y*w.subdivisionStep,v=k*w.subdivisionStep;if(S<=0||v<=0)return null;a.width=S,a.height=v;const E=a.getContext("2d");if(!E)return null;if(E.clearRect(0,0,S,v),E.strokeStyle=w.strokeColor,w.subdivisionStep===1)f(E,0,0,S,0,b),f(E,0,0,0,v,b);else{const C=S/w.subdivisionStep,M=v/w.subdivisionStep;for(let B=0;B<=w.subdivisionStep;B++){const I=B*C,_=B%w.subdivisionStep===0;f(E,I,0,I,v,_?3*b:b)}for(let B=0;B<=w.subdivisionStep;B++){const I=B*M,_=B%w.subdivisionStep===0;f(E,0,I,S,I,_?3*b:b)}}return E.createPattern(a,"repeat")}function h(y){let k=o.value.colWidth,w=o.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,v=s.value.height,E=t.value.left,C=t.value.top,M=E+S/t.value.zoom,B=C+v/t.value.zoom;let I=k*b,_=w*b,j=0,H=0,K=Number.POSITIVE_INFINITY,G=Number.POSITIVE_INFINITY;for(;;){I=b*k,_=b*w,j=Math.floor(E/I)*I,H=Math.floor(C/_)*_;const ce=Math.ceil(M/I)*I,Xe=Math.ceil(B/_)*_;if(G=Math.round((ce-j)/k),K=Math.round((Xe-H)/w),Math.max(G,K)>200)k*=2,w*=2;else break}const te=k*t.value.zoom,W=w*t.value.zoom,L=Math.round(te),F=Math.round(W),X=u(L,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(te/L,W/F));const ie=(j-E-k/2)*t.value.zoom,Q=(H-C-w/2)*t.value.zoom;y.save(),y.translate(ie,Q),y.fillStyle=X,y.fillRect(0,0,S+I*t.value.zoom,v+_*t.value.zoom),y.restore()}function m(y){let k=o.value.colWidth,w=o.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,v=s.value.height,E=t.value.left,C=t.value.top,M=E+S/t.value.zoom,B=C+v/t.value.zoom;let I=k*b,_=w*b,j=0,H=0,K=Number.POSITIVE_INFINITY,G=Number.POSITIVE_INFINITY;for(;;){I=b*k,_=b*w,j=Math.floor(E/I)*I,H=Math.floor(C/_)*_;const ce=Math.ceil(M/I)*I,Xe=Math.ceil(B/_)*_;if(G=Math.round((ce-j)/k),K=Math.round((Xe-H)/w),Math.max(G,K)>200)k*=2,w*=2;else break}const te=k*t.value.zoom,W=w*t.value.zoom,L=Math.round(te),F=Math.round(W),X=p(L,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(te/L,W/F));const ie=(j-E)*t.value.zoom,Q=(H-C)*t.value.zoom;y.save(),y.translate(ie,Q),y.fillStyle=X,y.fillRect(0,0,S+I*t.value.zoom,v+_*t.value.zoom),y.restore()}function g(){const y=l.value;if(!y)return;const k=y.getContext("2d");if(!k)return;const{width:w,height:b}=s.value;w===0||b===0||(y.width=w,y.height=b,k.clearRect(0,0,w,b),k.fillStyle=e.background.color,k.fillRect(0,0,w,b),e.background.kind==="dots"?h(k):e.background.kind==="grid"&&m(k))}return c.watch(()=>[e.background,t.value,o.value,s.value],()=>{g()},{deep:!0}),c.onMounted(()=>{const y=r==null?void 0:r.value;if(y){const k=()=>{s.value={width:y.clientWidth,height:y.clientHeight}};k(),i=new ResizeObserver(k),i.observe(y)}g()}),c.onUnmounted(()=>{i==null||i.disconnect()}),(y,k)=>(c.openBlock(),c.createElementBlock("canvas",{ref_key:"canvasRef",ref:l,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}});function Cu(n,e){if(e.length===0)return new Set;const t=e[0].tag,o=n.blockDefs[t];if(!o)return new Set;const r=new Set(o.components.map(s=>s.name));for(let s=1;s<e.length;s++){const i=e[s].tag,l=n.blockDefs[i];if(!l){r.clear();break}const a=new Set(l.components.map(d=>d.name));for(const d of r)a.has(d)||r.delete(d)}return r}const vu=c.defineComponent({__name:"FloatingMenuBar",setup(n){const e=c.useSlots(),{reset:t}=$t(),o=c.inject(Ai),{selectedIds:r,commonComponents:s}=o,i=new Set(["color","text","verticalAlign","penStroke","elbowArrow","arcArrow","shape"]),l=c.computed(()=>{const d=[];for(const u of s.value){const f=`button:${u}`;!i.has(u)&&e[f]&&d.push(u)}return d});function a(){t()}return c.onUnmounted(()=>{t()}),(d,u)=>(c.openBlock(),c.createElementBlock("div",{class:"wov-floating-menu-bar",onMouseleave:a},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(l.value,f=>c.renderSlot(d.$slots,`button:${f}`,{key:f,entityIds:c.unref(r)})),128)),c.renderSlot(d.$slots,"button:color",{entityIds:c.unref(r)},()=>[c.unref(s).has("color")?(c.openBlock(),c.createBlock(pu,{key:0,entityIds:c.unref(r)},null,8,["entityIds"])):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:shape",{entityIds:c.unref(r)},()=>[c.unref(s).has("shape")?(c.openBlock(),c.createElementBlock(c.Fragment,{key:0},[c.createVNode(yu,{entityIds:c.unref(r)},null,8,["entityIds"]),c.createVNode(gu,{entityIds:c.unref(r)},null,8,["entityIds"]),c.createVNode(ku,{entityIds:c.unref(r)},null,8,["entityIds"])],64)):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:penStroke",{entityIds:c.unref(r)},()=>[c.unref(s).has("penStroke")?(c.openBlock(),c.createBlock(mu,{key:0,entityIds:c.unref(r)},null,8,["entityIds"])):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:arrowThickness",{entityIds:c.unref(r)},()=>[c.unref(s).has("elbowArrow")||c.unref(s).has("arcArrow")?(c.openBlock(),c.createBlock(uu,{key:0,entityIds:c.unref(r)},null,8,["entityIds"])):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:arrowHeadStart",{entityIds:c.unref(r)},()=>[c.unref(s).has("elbowArrow")||c.unref(s).has("arcArrow")?(c.openBlock(),c.createBlock(ai,{key:0,entityIds:c.unref(r),side:"start"},null,8,["entityIds"])):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:arrowHeadEnd",{entityIds:c.unref(r)},()=>[c.unref(s).has("elbowArrow")||c.unref(s).has("arcArrow")?(c.openBlock(),c.createBlock(ai,{key:0,entityIds:c.unref(r),side:"end"},null,8,["entityIds"])):c.createCommentVNode("",!0)]),c.renderSlot(d.$slots,"button:text",{entityIds:c.unref(r)},()=>[c.unref(s).has("text")?(c.openBlock(),c.createBlock(Bw,{key:0,entityIds:c.unref(r),showVerticalAlign:c.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])):c.createCommentVNode("",!0)]),c.createVNode(ci)],32))}}),Aw={class:"wov-floating-menu-inner"},Eu=c.defineComponent({__name:"FloatingMenu",setup(n){const e=c.inject($e),t=Od([x.Block,oe.Selected]),o=Se(x.Camera),r=Se(x.Screen),s=Se(oe.SelectionStateSingleton),i=lo(),l=c.computed(()=>t.value.map(S=>S.entityId)),a=c.computed(()=>{const S=e==null?void 0:e.getEditor();if(!S||t.value.length===0)return new Set;const v=t.value.map(E=>({tag:E.block.value.tag}));return Cu(S,v)});c.provide(Ai,{selectedIds:l,commonComponents:a});const d=[0,0,0,0];function u(...S){let v=1/0,E=1/0,C=-1/0,M=-1/0,B=!1;for(const I of S){if(!I)continue;const _=I.getBoundingClientRect();_.width<=0||(B=!0,v=Math.min(v,_.left),E=Math.min(E,_.top),C=Math.max(C,_.right),M=Math.max(M,_.bottom))}return B?{x:v,y:E,left:v,top:E,right:C,bottom:M,width:C-v,height:M-E,toJSON:()=>({})}:null}const f=c.computed(()=>{if(t.value.length===0)return null;const S=o.value;if(!S)return null;let v=null;for(const E of t.value){const C=E.block.value;Me.Rect.getAabb(C.position,C.size,C.rotateZ,d),Me.Aabb.translate(d,[-S.left,-S.top]),Me.Aabb.scale(d,S.zoom),v===null?v=Me.Aabb.clone(d):Me.Aabb.union(v,d)}return v}),p=c.inject("containerRef"),h=c.computed(()=>{const S=p==null?void 0:p.value;if(!S)return null;o.value,i.updateCounter.value;const v=i.blockElement.value,E=i.textElement.value,C=u(v,E);if(C)return{getBoundingClientRect:()=>C};const M=f.value;if(!M)return null;const B=S.getBoundingClientRect();return{getBoundingClientRect(){return{x:B.left+M[0],y:B.top+M[1],width:M[2]-M[0],height:M[3]-M[1],top:B.top+M[1],left:B.left+M[0],right:B.left+M[2],bottom:B.top+M[3]}}}}),m=c.ref(null),g={name:"clampToViewport",fn({y:S,rects:v}){const M=window.innerHeight-v.floating.height-8;return{y:Math.max(8,Math.min(S,M))}}},{floatingStyles:y}=wr(h,m,{placement:"top",middleware:[gr(12),kr({fallbackPlacements:["bottom"]}),yr({padding:8}),g]}),k=c.computed(()=>{const S=f.value,v=r.value;return!S||!v?!0:S[2]<0||S[0]>v.width||S[3]<0||S[1]>v.height}),w=[oe.SelectionState.Dragging,oe.SelectionState.SelectionBoxDragging],b=c.computed(()=>t.value.length>0&&!k.value&&!w.includes(s.value.state));return(S,v)=>(c.openBlock(),c.createBlock(c.Transition,{name:"wov-fade"},{default:c.withCtx(()=>[b.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"floatingRef",ref:m,class:"wov-floating-menu",style:c.normalizeStyle(c.unref(y))},[c.createElementVNode("div",Aw,[c.renderSlot(S.$slots,"default",{},()=>[c.createVNode(vu)])])],4)):c.createCommentVNode("",!0)]),_:3}))}}),Iw={key:0,class:"wov-loading-overlay"},Ow={class:"wov-loading-spinner"},Mu=c.defineComponent({__name:"LoadingOverlay",props:{isLoading:{type:Boolean}},setup(n){const e=c.ref("|"),t=["|","/","-","\\"];let o=null;return c.onMounted(()=>{o=setInterval(()=>{const r=t.indexOf(e.value);e.value=t[(r+1)%t.length]},100)}),c.onUnmounted(()=>{o!==null&&clearInterval(o)}),(r,s)=>(c.openBlock(),c.createBlock(c.Transition,{name:"wov-loading-fade"},{default:c.withCtx(()=>[n.isLoading?(c.openBlock(),c.createElementBlock("div",Iw,[c.createElementVNode("div",Ow,c.toDisplayString(e.value),1)])):c.createCommentVNode("",!0)]),_:1}))}}),Dw={class:"wov-action-bar"},Rw=c.defineComponent({__name:"ActionBar",setup(n){const{getEditor:e}=le(),t=c.inject($e),o=c.ref(!1),r=c.ref(!1);if(t){const a=t.registerTickCallback(d=>{const{store:u}=x.getPluginResources(d,"editing");o.value=u.canUndo(),r.value=u.canRedo()});c.onUnmounted(a)}function s(){const a=e();a==null||a.command(x.Undo)}function i(){const a=e();a==null||a.command(x.Redo)}function l(){const a=e();a==null||a.command(oe.RemoveSelected)}return(a,d)=>(c.openBlock(),c.createElementBlock("div",Dw,[c.createElementVNode("button",{class:"wov-action-button",onClick:s,"aria-label":"Undo"},[...d[0]||(d[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-undo-icon lucide-undo"},[c.createElementVNode("path",{d:"M3 7v6h6"}),c.createElementVNode("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})],-1)])]),c.createElementVNode("button",{class:"wov-action-button",onClick:i,"aria-label":"Redo"},[...d[1]||(d[1]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-redo-icon lucide-redo"},[c.createElementVNode("path",{d:"M21 7v6h-6"}),c.createElementVNode("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"})],-1)])]),c.createElementVNode("button",{class:"wov-action-button",onClick:l,"aria-label":"Delete"},[...d[2]||(d[2]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-trash-icon lucide-trash"},[c.createElementVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}),c.createElementVNode("path",{d:"M3 6h18"}),c.createElementVNode("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})],-1)])])]))}}),lt=c.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},cursor:{default:"crosshair"}},setup(n){const e=n,t=c.inject(Nr);if(!t)throw new Error("ToolbarButton must be used within a Toolbar component");const o=t,r=c.ref(null),{show:s,hide:i}=$t(),l=c.computed(()=>o.activeTool.value===e.name);function a(){o.setTool(e.name,e.placementSnapshot,e.cursor)}function d(){o.onToolPointerDown(e.name,e.dragOutSnapshot)}function u(){o.onToolPointerUp()}function f(){e.tooltip&&r.value&&s(e.tooltip,r.value)}function p(){i()}return(h,m)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:c.normalizeClass(["wov-toolbar-button",{selected:l.value}]),onClick:a,onPointerdown:d,onPointerup:u,onMouseenter:f,onMouseleave:p},[c.renderSlot(h.$slots,"default")],34))}}),_w='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.35 4.75" width="20" height="20"><defs><style>.cls-1{stroke:#fff;stroke-miterlimit:10;stroke-width:.25px;}</style></defs><path class="cls-1" d="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z"/></svg>',Pw='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.08 4.75" width="24" height="24"><defs><style>.cls-1{fill:#fff;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:.25px;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;stroke-width:.51px;}</style></defs><path class="cls-1" d="M.89,2.25v.63M.89,2.25V.75c0-.21.17-.38.38-.38s.38.17.38.38M.89,2.25c0-.21-.17-.37-.38-.37s-.38.17-.38.37v.5c0,1.04.86,1.87,1.91,1.87s1.91-.84,1.91-1.87v-1.25c0-.21-.17-.38-.38-.38s-.38.17.38.38M1.66.75v1.38M1.66.75v-.25c0-.21.17-.38.38-.38s.38.17.38.38v.25M2.42.75v1.38M2.42.75c0-.21.17-.38.38-.38s.38.17.38.38v.75M3.19,1.5v.63"/><line class="cls-2" x1="2.8" y1=".77" x2="2.8" y2="2.03"/><line class="cls-2" x1="2.04" y1=".64" x2="2.04" y2="2.02"/><line class="cls-2" x1="1.27" y1=".84" x2="1.27" y2="2.29"/></svg>',Vw='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 8v-2a2 2 0 0 1 2 -2h2" /><path d="M4 16v2a2 2 0 0 0 2 2h2" /><path d="M16 4h2a2 2 0 0 1 2 2v2" /><path d="M16 20h2a2 2 0 0 0 2 -2v-2" /><path d="M9 12l6 0" /><path d="M12 9l0 6" /></svg>',un={Select:"select",Hand:"hand",Crosshair:"crosshair"},Tu={[un.Select]:{makeSvg:()=>_w,hotspot:[1,0],rotationOffset:0},[un.Hand]:{makeSvg:()=>Pw,hotspot:[12,12],rotationOffset:0},[un.Crosshair]:{makeSvg:()=>Vw,hotspot:[12,12],rotationOffset:0}},$w={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},Nu=c.defineComponent({__name:"SelectTool",setup(n){const{nextEditorTick:e}=le(),{activeTool:t}=ei();return c.watch(t,(o,r)=>{r==="select"&&e(s=>{oe.DeselectAll.spawn(s)})}),(o,r)=>(c.openBlock(),c.createBlock(lt,{name:"select",tooltip:"Select",cursor:c.unref(un).Select},{default:c.withCtx(()=>[(c.openBlock(),c.createElementBlock("svg",$w,[...r[0]||(r[0]=[c.createElementVNode("g",{transform:"matrix(4.21053,0,0,4.21053,0.842105,0)"},[c.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-width":"0.5",d:"M2.39,2.88C2.38,2.885 2.34,2.9 2.33,2.91C2.32,2.91 2.298,2.939 2.28,2.97L1.51,4.41C1.44,4.54 1.41,4.6 1.37,4.61C1.34,4.62 1.3,4.61 1.27,4.6C1.24,4.58 1.22,4.51 1.18,4.37L0.16,0.41C0.13,0.28 0.11,0.22 0.13,0.18C0.15,0.15 0.17,0.13 0.21,0.12C0.25,0.12 0.31,0.14 0.42,0.2L4.01,2.14C4.14,2.21 4.2,2.24 4.21,2.28C4.22,2.31 4.21,2.35 4.2,2.38C4.18,2.41 4.11,2.43 3.97,2.47L2.39,2.88Z"})],-1)])]))]),_:1},8,["cursor"]))}}),Bu=c.defineComponent({__name:"HandTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"hand",tooltip:"Hand",cursor:c.unref(un).Hand},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20.56 24"},[c.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4.47,11.39v3.18M4.47,11.39V3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92M4.47,11.39c0-1.06-.86-1.87-1.92-1.87s-1.92.86-1.92,1.87v2.53c0,5.25,4.35,9.45,9.65,9.45s9.65-4.24,9.65-9.45v-6.32c0-1.06-.86-1.92-1.92-1.92s-1.92.86-1.92,1.92M8.36,3.81v6.97M8.36,3.81v-1.26c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v1.26M12.2,3.81v6.97M12.2,3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v3.79M16.09,7.6v3.18"})],-1)])]),_:1},8,["cursor"]))}}),Au=c.defineComponent({__name:"StickyNoteTool",setup(n){const e=JSON.stringify({block:{tag:"sticky-note",size:[200,200]},color:{red:255,green:242,blue:117},text:{defaultAlignment:x.TextAlignment.Center},verticalAlign:{value:x.VerticalAlignment.Center}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"sticky-note",tooltip:"Sticky Note","drag-out-snapshot":c.unref(e),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("path",{d:"M4 4h12v12H4z"}),c.createElementVNode("path",{d:"M7 8h6M7 11h4"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Iu=c.defineComponent({__name:"ShapeTool",setup(n){const e=JSON.stringify({block:{tag:"shape",size:[200,200]},shape:{kind:"rectangle",strokeKind:x.StrokeKind.Solid,strokeWidth:2,strokeRed:0,strokeGreen:0,strokeBlue:0,strokeAlpha:255,fillRed:255,fillGreen:255,fillBlue:255,fillAlpha:0},text:{defaultAlignment:x.TextAlignment.Center},verticalAlign:{value:x.VerticalAlignment.Center}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"shape",tooltip:"Shape","drag-out-snapshot":c.unref(e),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("rect",{x:"3",y:"3",width:"14",height:"14",rx:"2"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Ou=c.defineComponent({__name:"EraserTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"eraser",tooltip:"Eraser"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor"},[c.createElementVNode("path",{d:"M210.5 480L333.5 480L398.8 414.7L225.3 241.2L98.6 367.9L210.6 479.9zM256 544L210.5 544C193.5 544 177.2 537.3 165.2 525.3L49 409C38.1 398.1 32 383.4 32 368C32 352.6 38.1 337.9 49 327L295 81C305.9 70.1 320.6 64 336 64C351.4 64 366.1 70.1 377 81L559 263C569.9 273.9 576 288.6 576 304C576 319.4 569.9 334.1 559 345L424 480L544 480C561.7 480 576 494.3 576 512C576 529.7 561.7 544 544 544L256 544z"})],-1)])]),_:1}))}}),Du=c.defineComponent({__name:"PenTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"pen",tooltip:"Pen"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("path",{d:"M13.586 3.586a2 2 0 1 1 2.828 2.828l-8.793 8.793-3.536.707.707-3.536 8.794-8.792Z","stroke-linecap":"round","stroke-linejoin":"round"}),c.createElementVNode("path",{d:"M12 5l3 3","stroke-linecap":"round"})],-1)])]),_:1}))}}),Ru=c.defineComponent({__name:"TextTool",setup(n){const e=JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24}}),t=JSON.stringify({block:{tag:"text",size:[36,29]},text:{content:"text",constrainWidth:!1,fontSizePx:24}});return(o,r)=>(c.openBlock(),c.createBlock(lt,{name:"text",tooltip:"Text","drag-out-snapshot":c.unref(t),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...r[0]||(r[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-type-icon lucide-type"},[c.createElementVNode("path",{d:"M12 4v16"}),c.createElementVNode("path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}),c.createElementVNode("path",{d:"M9 20h6"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),_u=c.defineComponent({__name:"ElbowArrowTool",setup(n){const e=JSON.stringify({block:{tag:"elbow-arrow",size:[200,200]},elbowArrow:{points:[0,0,.5,0,.5,1,1,1],pointCount:4,startArrowHead:Y.ArrowHeadKind.None,endArrowHead:Y.ArrowHeadKind.V},connector:{}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"elbow-arrow",tooltip:"Elbow Arrow",cursor:"crosshair","drag-out-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M4 6 L10 6 L10 14 L16 14"}),c.createElementVNode("path",{d:"M13 11 L16 14 L13 17"})],-1)])]),_:1},8,["drag-out-snapshot"]))}}),Pu=c.defineComponent({__name:"ImageTool",setup(n){const{nextEditorTick:e}=le(),{show:t,hide:o}=$t(),{setTool:r}=ei(),{createImageBlock:s}=Id(),i=c.ref(null),l=c.ref(null);function a(){var p;(p=l.value)==null||p.click()}async function d(p){var S;const h=p.target,m=(S=h.files)==null?void 0:S[0];if(!m)return;if(h.value="",!m.type.startsWith("image/")){console.warn("Selected file is not an image");return}const g=await e(),y=x.Camera.read(g),k=x.Screen.read(g),w=y.left+k.width/y.zoom/2,b=y.top+k.height/y.zoom/2;await s(m,w,b),r("select",void 0,un.Select)}function u(){i.value&&t("Image",i.value)}function f(){o()}return(p,h)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:i,class:"wov-toolbar-button",onClick:a,onMouseenter:u,onMouseleave:f},[h[0]||(h[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),c.createElementVNode("circle",{cx:"9",cy:"9",r:"2"}),c.createElementVNode("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})],-1)),c.createElementVNode("input",{ref_key:"fileInputRef",ref:l,type:"file",accept:"image/*",style:{display:"none"},onChange:d},null,544)],544))}}),Lw={class:"wov-toolbar-container"},Vu=c.defineComponent({__name:"Toolbar",setup(n){const e=c.useSlots(),{reset:t}=$t(),{nextEditorTick:o}=le(),r=c.ref(null),s=c.ref(null),i=Se(x.Controls),l=c.computed(()=>i.value.leftMouseTool),a=[Nu,Bu,Ru,Pu,Iu,_u,Au,Du,Ou],d=c.inject("containerRef"),u=c.ref(null),f=c.ref(!1),p=c.ref(null),h=c.ref(null),m=c.ref(1/0),g=c.ref(0),y=c.ref([]),k=c.ref(8),w=c.ref(48),{width:b}=wu(d);function S(){return p.value?Array.from(p.value.children).filter(L=>!L.classList.contains("wov-overflow-button")&&!L.classList.contains("wov-menu-tooltip")):[]}function v(){var ie;const L=S();if(L.length===0)return;g.value=L.length;const F=getComputedStyle(p.value);k.value=parseFloat(F.gap)||8;const X=((ie=h.value)==null?void 0:ie.offsetWidth)||40;w.value=X+k.value,y.value=L.map(Q=>Q.offsetWidth)}function E(){if(y.value.length===0)return;const X=b.value-40-20,ie=k.value,Q=w.value;let ce=0,Xe=0;for(let yt=0;yt<y.value.length;yt++){const hn=y.value[yt],Ft=ce>0?hn+ie:hn,Ht=y.value.length-yt-1>0?Q:0;if(ce+Ft+Ht<=X)ce+=Ft,Xe++;else break}m.value=Math.max(1,Xe)}c.watch(b,()=>{y.value.length>0&&E()}),c.onMounted(()=>{c.nextTick(()=>{v(),E()})});const C=c.computed(()=>m.value<g.value);c.watchEffect(()=>{S().forEach((F,X)=>{F.style.display=X<m.value?"":"none"})}),c.watchEffect(()=>{if(!u.value)return;Array.from(u.value.children).forEach((F,X)=>{F.style.display=X>=m.value?"":"none"})});const{floatingStyles:M}=wr(h,u,{placement:"top",middleware:[gr(16),kr(),yr({padding:8})],whileElementsMounted:lu});function B(){f.value=!f.value}function I(){f.value=!1}function _(L){const F=L.target;h.value&&!h.value.contains(F)&&u.value&&!u.value.contains(F)&&I()}c.watch(f,L=>{L?document.addEventListener("click",_,!0):document.removeEventListener("click",_,!0)}),c.watch(C,L=>{L||I()});function j(L,F,X){s.value=F??null,o(ie=>{const Q=x.Controls.write(ie);Q.leftMouseTool=L,Q.heldSnapshot=F??"",X&&x.Cursor.setCursor(ie,X)})}function H(L){o(F=>{const X=x.Controls.write(F);X.leftMouseTool="drag-out",X.heldSnapshot=L})}function K(L,F){r.value=L,s.value=F??null}function G(){r.value=null,s.value=null}function te(){t(),r.value&&s.value&&H(s.value),r.value=null,s.value=null}const W={activeTool:l,heldTool:r,setTool:j,dragOutTool:H,onToolPointerDown:K,onToolPointerUp:G};return c.provide(Nr,W),(L,F)=>(c.openBlock(),c.createElementBlock("div",Lw,[c.createVNode(Rw),c.createElementVNode("div",{ref_key:"toolsContainerRef",ref:p,class:"wov-toolbar",onMouseleave:te},[c.unref(e).default?c.renderSlot(L.$slots,"default",{key:0}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},c.renderList(a,(X,ie)=>c.createVNode(c.resolveDynamicComponent(X),{key:ie})),64)),C.value?(c.openBlock(),c.createElementBlock("button",{key:2,ref_key:"overflowBtnRef",ref:h,class:c.normalizeClass(["wov-toolbar-button wov-overflow-button",{"menu-open":f.value}]),onClick:B},[...F[0]||(F[0]=[c.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[c.createElementVNode("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"})],-1)])],2)):c.createCommentVNode("",!0),c.createVNode(ci)],544),c.unref(d)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(d)},[f.value&&C.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"overflowMenuRef",ref:u,class:"wov-toolbar-overflow-menu",style:c.normalizeStyle(c.unref(M))},[c.unref(e).default?c.renderSlot(L.$slots,"default",{key:0}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},c.renderList(a,(X,ie)=>c.createVNode(c.resolveDynamicComponent(X),{key:ie})),64))],4)):c.createCommentVNode("",!0)],8,["to"])):c.createCommentVNode("",!0)]))}}),zw=c.defineComponent({__name:"ArcArrowTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"arc-arrow",tooltip:"Arc Arrow",cursor:"crosshair"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M4 14 Q 10 4, 16 14"}),c.createElementVNode("path",{d:"M13 11 L16 14 L12.5 15.5"})],-1)])]),_:1}))}}),Fw={class:"wov-user-presence-avatars"},Hw=["src","alt"],Ww={class:"wov-user-presence-list"},jw=["src","alt"],Uw={class:"wov-user-presence-name"},Kw=4,$u=c.defineComponent({__name:"UserPresence",props:{users:{}},setup(n){const e=n,t=c.ref(!1),o=c.ref(null);sw(o,()=>{t.value=!1});function r(l){if(!l)return"?";const a=l.trim().split(/\s+/);return a.length>=2?(a[0][0]+a[1][0]).toUpperCase():l.slice(0,2).toUpperCase()}const s=c.computed(()=>e.users.map(l=>({sessionId:l.sessionId,name:l.name,color:l.color,avatar:l.avatar,initials:r(l.name)}))),i=c.computed(()=>s.value.slice(0,Kw));return(l,a)=>n.users.length>1?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"containerRef",ref:o,class:"wov-user-presence"},[c.createElementVNode("button",{class:c.normalizeClass(["wov-user-presence-trigger",{"is-open":t.value}]),onClick:a[0]||(a[0]=d=>t.value=!t.value)},[c.createElementVNode("div",Fw,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(i.value,d=>(c.openBlock(),c.createElementBlock("div",{key:d.sessionId,class:"wov-user-avatar",style:c.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(c.openBlock(),c.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,Hw)):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createTextVNode(c.toDisplayString(d.initials),1)],64))],4))),128))])],2),t.value?(c.openBlock(),c.createElementBlock("div",{key:0,class:"wov-user-presence-dropdown",onWheel:a[1]||(a[1]=c.withModifiers(()=>{},["stop"]))},[c.createElementVNode("div",Ww,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,d=>(c.openBlock(),c.createElementBlock("div",{key:d.sessionId,class:"wov-user-presence-item"},[c.createElementVNode("div",{class:"wov-user-avatar wov-user-avatar-small",style:c.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(c.openBlock(),c.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,jw)):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createTextVNode(c.toDisplayString(d.initials),1)],64))],4),c.createElementVNode("span",Uw,c.toDisplayString(d.name),1)]))),128))])],32)):c.createCommentVNode("",!0)],512)):c.createCommentVNode("",!0)}}),ki=(n,e)=>e.some(t=>n instanceof t);let Lu,zu;function qw(){return Lu||(Lu=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Jw(){return zu||(zu=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const wi=new WeakMap,bi=new WeakMap,vr=new WeakMap;function Gw(n){const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("success",s),n.removeEventListener("error",i)},s=()=>{t(fn(n.result)),r()},i=()=>{o(n.error),r()};n.addEventListener("success",s),n.addEventListener("error",i)});return vr.set(e,n),e}function Yw(n){if(wi.has(n))return;const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("complete",s),n.removeEventListener("error",i),n.removeEventListener("abort",i)},s=()=>{t(),r()},i=()=>{o(n.error||new DOMException("AbortError","AbortError")),r()};n.addEventListener("complete",s),n.addEventListener("error",i),n.addEventListener("abort",i)});wi.set(n,e)}let xi={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return wi.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return fn(n[e])},set(n,e,t){return n[e]=t,!0},has(n,e){return n instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in n}};function Fu(n){xi=n(xi)}function Xw(n){return Jw().includes(n)?function(...e){return n.apply(Si(this),e),fn(this.request)}:function(...e){return fn(n.apply(Si(this),e))}}function Zw(n){return typeof n=="function"?Xw(n):(n instanceof IDBTransaction&&Yw(n),ki(n,qw())?new Proxy(n,xi):n)}function fn(n){if(n instanceof IDBRequest)return Gw(n);if(bi.has(n))return bi.get(n);const e=Zw(n);return e!==n&&(bi.set(n,e),vr.set(e,n)),e}const Si=n=>vr.get(n);function Qw(n,e,{blocked:t,upgrade:o,blocking:r,terminated:s}={}){const i=indexedDB.open(n,e),l=fn(i);return o&&i.addEventListener("upgradeneeded",a=>{o(fn(i.result),a.oldVersion,a.newVersion,fn(i.transaction),a)}),t&&i.addEventListener("blocked",a=>t(a.oldVersion,a.newVersion,a)),l.then(a=>{s&&a.addEventListener("close",()=>s()),r&&a.addEventListener("versionchange",d=>r(d.oldVersion,d.newVersion,d))}).catch(()=>{}),l}const eb=["get","getKey","getAll","getAllKeys","count"],tb=["put","add","delete","clear"],Ci=new Map;function Hu(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(Ci.get(e))return Ci.get(e);const t=e.replace(/FromIndex$/,""),o=e!==t,r=tb.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(r||eb.includes(t)))return;const s=async function(i,...l){const a=this.transaction(i,r?"readwrite":"readonly");let d=a.store;return o&&(d=d.index(l.shift())),(await Promise.all([d[t](...l),r&&a.done]))[0]};return Ci.set(e,s),s}Fu(n=>({...n,get:(e,t,o)=>Hu(e,t)||n.get(e,t,o),has:(e,t)=>!!Hu(e,t)||n.has(e,t)}));const nb=["continue","continuePrimaryKey","advance"],Wu={},vi=new WeakMap,ju=new WeakMap,ob={get(n,e){if(!nb.includes(e))return n[e];let t=Wu[e];return t||(t=Wu[e]=function(...o){vi.set(this,ju.get(this)[e](...o))}),t}};async function*rb(...n){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...n)),!e)return;e=e;const t=new Proxy(e,ob);for(ju.set(t,e),vr.set(t,Si(e));e;)yield t,e=await(vi.get(t)||e.continue()),vi.delete(t)}function Uu(n,e){return e===Symbol.asyncIterator&&ki(n,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&ki(n,[IDBIndex,IDBObjectStore])}Fu(n=>({...n,get(e,t,o){return Uu(e,t)?rb:n.get(e,t,o)},has(e,t){return Uu(e,t)||n.has(e,t)}}));async function Ei(n,e){const t=await Qw(n,1,{upgrade(o){o.objectStoreNames.contains(e)||o.createObjectStore(e)}});return new sb(t,e)}var sb=class{constructor(n,e){this.db=n,this.storeName=e}async get(n){return this.db.get(this.storeName,n)}async put(n,e){await this.db.put(this.storeName,e,n)}async delete(n){await this.db.delete(this.storeName,n)}async getAllEntries(){const e=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName),t=await e.getAllKeys(),o=await e.getAll(),r=[];for(let s=0;s<t.length;s++)r.push([t[s],o[s]]);return r}async clear(){const n=this.db.transaction(this.storeName,"readwrite");n.objectStore(this.storeName).clear(),await n.done}close(){this.db.close()}},ib=class{constructor(n){this.jobsStore=null,this.binariesStore=null,this.blobUrls=new Map,this.uploading=new Set,this.uploadPromises=new Map,this.provider=n.provider,this.documentId=n.documentId,this.maxRetries=n.provider.maxRetries??3,this.retryDelay=n.provider.retryDelay??5e3}async init(){const n=`wovencanvas-assets-${this.documentId}`,[e,t]=await Promise.all([Ei(`${n}-jobs`,"jobs"),Ei(`${n}-binaries`,"binaries")]);this.jobsStore=e,this.binariesStore=t}async upload(n,e,t){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");await this.binariesStore.put(n,e);const o={identifier:n,metadata:t,createdAt:Date.now(),retryCount:0};await this.jobsStore.put(n,o);const r=URL.createObjectURL(e);return this.blobUrls.set(n,r),new Promise((s,i)=>{this.uploadPromises.set(n,{resolve:s,reject:i}),this.startUpload(n)})}async getDisplayUrl(n){const e=this.blobUrls.get(n);if(e)return e;try{return await this.provider.resolveUrl(n)}catch(t){return console.error(`Failed to resolve URL for ${n}:`,t),null}}async resumePendingUploads(){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const n=await this.jobsStore.getAllEntries();for(const[e]of n){const t=await this.binariesStore.get(e);if(t){const o=URL.createObjectURL(t);this.blobUrls.set(e,o)}this.startUpload(e)}}hasPendingUpload(n){return this.blobUrls.has(n)}isUploading(n){return this.uploading.has(n)}async cancelUpload(n){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(n);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(n)),await this.jobsStore.delete(n),await this.binariesStore.delete(n),this.uploading.delete(n);const t=this.uploadPromises.get(n);t&&(t.reject(new Error("Upload cancelled")),this.uploadPromises.delete(n))}close(){var n,e;for(const t of this.blobUrls.values())URL.revokeObjectURL(t);this.blobUrls.clear(),(n=this.jobsStore)==null||n.close(),(e=this.binariesStore)==null||e.close(),this.jobsStore=null,this.binariesStore=null}async startUpload(n){if(!this.jobsStore||!this.binariesStore||this.uploading.has(n))return;this.uploading.add(n);const e=await this.jobsStore.get(n),t=await this.binariesStore.get(n);if(!e||!t){this.uploading.delete(n);return}try{await this.provider.upload(t,n,e.metadata),await this.onUploadSuccess(n)}catch(o){await this.onUploadError(n,e,o)}}async onUploadSuccess(n){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(n);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(n)),await this.jobsStore.delete(n),await this.binariesStore.delete(n),this.uploading.delete(n);const t=this.uploadPromises.get(n);t&&(t.resolve(),this.uploadPromises.delete(n))}async onUploadError(n,e,t){if(!this.jobsStore)return;const o=t instanceof Error?t.message:"Unknown error";if(console.error(`Upload failed for ${n}:`,o),this.uploading.delete(n),e.retryCount<this.maxRetries){const r={...e,retryCount:e.retryCount+1};await this.jobsStore.put(n,r),setTimeout(()=>{this.startUpload(n)},this.retryDelay*2**e.retryCount)}else{const r=this.uploadPromises.get(n);r&&(r.reject(new Error(o)),this.uploadPromises.delete(n))}}},lb="wovencanvas-assets",ab="blobs",cb=class{constructor(){this.store=null,this.initPromise=null,this.maxRetries=3,this.retryDelay=5e3}async upload(n,e,t){return await(await this.getStore()).put(e,{blob:n,metadata:t}),{}}async resolveUrl(n){const t=await(await this.getStore()).get(n);if(!t)throw new Error(`Asset not found: ${n}`);return URL.createObjectURL(t.blob)}async delete(n){await(await this.getStore()).delete(n)}close(){this.store&&(this.store.close(),this.store=null,this.initPromise=null)}getStore(){return this.store?Promise.resolve(this.store):(this.initPromise||(this.initPromise=Ei(lb,ab).then(n=>(this.store=n,n))),this.initPromise)}};const db={class:"wov-selection-box"},ub=c.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(c.openBlock(),c.createElementBlock("div",db))}}),fb={class:"wov-transform-box"},hb=c.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(c.openBlock(),c.createElementBlock("div",fb))}}),pb={},mb={class:"wov-transform-handle"};function gb(n,e){return c.openBlock(),c.createElementBlock("div",mb)}const yb=Wt(pb,[["render",gb]]),kb=c.defineComponent({__name:"StickyNote",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,x.Color),o=fe(e.entityId,x.VerticalAlign),r=c.ref(null),s={[x.VerticalAlignment.Top]:"flex-start",[x.VerticalAlignment.Center]:"center",[x.VerticalAlignment.Bottom]:"flex-end"},i=c.computed(()=>{var a;return{backgroundColor:t.value?`rgb(${t.value.red}, ${t.value.green}, ${t.value.blue})`:void 0,minHeight:`${e.block.size[0]}px`,alignItems:s[((a=o.value)==null?void 0:a.value)??x.VerticalAlignment.Top]}}),{handleEditEnd:l}=Qs({blockData:e,containerRef:r,minWidth:()=>e.block.size[0],minHeight:()=>e.block.size[0]});return(a,d)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-sticky-note",style:c.normalizeStyle(i.value)},[c.createVNode(rr,c.mergeProps(e,{"block-element":r.value,onEditEnd:c.unref(l)}),null,16,["block-element","onEditEnd"])],4))}}),Er=Re.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:x.field.string().default("").max(36)}),Ku=x.defineQuery(n=>n.with(x.Edited));function wb(n){var e;if(!n)return null;try{const t=JSON.parse(n);return(e=t.block)!=null&&e.tag?t:(console.warn("Block snapshot missing required tag:",t),null)}catch{return console.warn("Invalid block snapshot JSON:",n),null}}function bb(n,e,t){const o=x.getBlockDef(n,e.block.tag);if(!o)throw new Error(`Block placement: block definition for tag "${e.block.tag}" not found`);const r=e.block.size??[100,100],s=t[0]-r[0]/2,i=t[1]-r[1]/2,l=e.block.rank??x.RankBounds.genNext(n),a=x.createEntity(n);"synced"in e||x.addComponent(n,a,x.Synced,{id:crypto.randomUUID()});const d=Object.assign({},e.block,{position:[s,i],size:r,rank:l});x.addComponent(n,a,x.Block,d);for(const f of o.components)if(!(f.name in e))x.addComponent(n,a,f);else{const p=e[f.name];x.addComponent(n,a,f,p)}const{sessionId:u}=x.getResources(n);return x.addComponent(n,a,x.Held,{sessionId:u}),a}function qu(n,e,t,o,r){const s=bb(n,e,t),i=x.Block.read(n,s);if(x.canBlockEdit(n,e.block.tag)&&(x.addComponent(n,s,oe.EditAfterPlacing,{}),r==="placement")){const{store:u}=x.getPluginResources(n,"editing"),f=u.createCheckpoint();if(f){const p=Er.write(n);p.editedCheckpoint=f}}const l=oe.SelectionStateSingleton.write(n);l.state=r==="dragOut"?oe.SelectionState.Dragging:oe.SelectionState.Pointing,l.dragStart=t,l.draggedEntity=s,l.draggedEntityStart=i.position,l.pointingStartClient=o,l.pointingStartWorld=t,l.isCloning=!1;const a=x.Controls.write(n);a.leftMouseTool="select",a.heldSnapshot="";const d=x.Cursor.write(n);d.cursorKind="select",d.rotation=0}function xb(n){const e=Er.read(n);if(e.editedCheckpoint){const t=e.editedCheckpoint;Er.write(n).editedCheckpoint="";const{store:o}=x.getPluginResources(n,"editing");o.onSettled(()=>o.squashToCheckpoint(t),{frames:5})}}const Sb=x.defineEditorSystem({phase:"capture"},n=>{Ku.removed(n).length>0&&Ku.current(n).length===0&&xb(n);const e=x.Controls.read(n);if(!e.heldSnapshot)return;const t=x.getPointerInput(n,[x.PointerButton.Left]);if(t.length===0)return;const o=wb(e.heldSnapshot);if(!o)return;if(e.leftMouseTool==="drag-out"){const s=t.find(i=>i.type==="pointerMove"&&!i.obscured);if(!s)return;qu(n,o,s.worldPosition,s.screenPosition,"dragOut")}else{const s=t.find(i=>i.type==="pointerDown"&&!i.obscured);if(!s)return;qu(n,o,s.worldPosition,s.screenPosition,"placement")}}),Cb=x.defineEditorSystem({phase:"update"},n=>{const{store:e}=x.getPluginResources(n,"editing");x.on(n,x.Undo,()=>{e.canUndo()&&(oe.deselectAll(n),e.undo())}),x.on(n,x.Redo,()=>{e.canRedo()&&(oe.deselectAll(n),e.redo())})}),vb=[{name:"Figtree",displayName:"Figtree",url:"https://fonts.googleapis.com/css2?family=Figtree",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/Figtree.png"},{name:"Shantell Sans",displayName:"Shantell Sans",url:"https://fonts.googleapis.com/css2?family=Shantell+Sans",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/ShantellSans.png"},{name:"Courier Prime",displayName:"Courier Prime",url:"https://fonts.googleapis.com/css2?family=Courier+Prime",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/CourierPrime.png"},{name:"EB Garamond",displayName:"EB Garamond",url:"https://fonts.googleapis.com/css2?family=EB+Garamond",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/EBGaramond.png"}];function Ju(n){return{name:"editing",resources:{store:n.store},singletons:[Er],systems:[Sb,Cb],cursors:Tu,fonts:vb,keybinds:[{command:x.Undo.name,key:x.Key.Z,mod:!0},{command:x.Redo.name,key:x.Key.Y,mod:!0},{command:x.Redo.name,key:x.Key.Z,mod:!0,shift:!0}]}}const Eb=c.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t}=le(),{createImageBlock:o}=Id(),r=c.ref(!1);let s=0;const i=c.inject("containerRef");function l(w){var b;(b=w.dataTransfer)!=null&&b.types.some(S=>S==="Files"||S==="text/uri-list"||S==="text/html")&&(s++,s===1&&(r.value=!0))}function a(){s--,s===0&&(r.value=!1)}function d(){s=0,r.value=!1}c.onMounted(()=>{const w=i==null?void 0:i.value;w&&(w.addEventListener("dragenter",l),w.addEventListener("dragleave",a),w.addEventListener("drop",d))}),c.onUnmounted(()=>{const w=i==null?void 0:i.value;w&&(w.removeEventListener("dragenter",l),w.removeEventListener("dragleave",a),w.removeEventListener("drop",d))});function u(w){w.preventDefault(),w.dataTransfer&&(w.dataTransfer.dropEffect="copy")}function f(w){w.preventDefault()}function p(w){w.preventDefault()}async function h(w){if(w.preventDefault(),!w.dataTransfer)return;const b=w.clientX,S=w.clientY,v=Array.from(w.dataTransfer.files).filter(C=>C.type.startsWith("image/"));if(v.length>0){for(const C of v)await y(C,b,S);return}const E=m(w.dataTransfer);E&&await k(E,b,S)}function m(w){const b=w.getData("text/uri-list");if(b){const C=b.split(`
|
|
103
|
+
`).filter(M=>!M.startsWith("#")).find(M=>g(M));if(C)return C}const S=w.getData("text/html");if(S){const E=S.match(/<img[^>]+src=["']([^"']+)["']/i);if(E!=null&&E[1])return E[1]}const v=w.getData("text/plain");return v&&g(v)?v:null}function g(w){try{const S=new URL(w).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(S)||w.startsWith("data:image/"),!0}catch{return!1}}async function y(w,b,S){const v=await t(),E=x.Camera.read(v),C=x.Screen.read(v),M=E.left+(b-C.left)/E.zoom,B=E.top+(S-C.top)/E.zoom;await o(w,M,B,{maxSize:e.maxSize})}async function k(w,b,S){try{const v=await fetch(w);if(!v.ok){console.warn("Failed to fetch image from URL:",w);return}const E=await v.blob();if(!E.type.startsWith("image/")){console.warn("URL did not return an image:",w);return}const M=new URL(w).pathname.split("/").pop()||"image",B=new File([E],M,{type:E.type});await y(B,b,S)}catch(v){console.warn("Failed to load image from URL:",w,v)}}return(w,b)=>(c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(["wov-image-drop-zone",{"wov-drag-over":r.value}]),onDragover:u,onDragenter:f,onDragleave:p,onDrop:h},null,34))}}),Mb={class:"wov-user-cursors"},Tb={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},Nb=["fill"],Bb="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z",Ab=c.defineComponent({__name:"UserCursors",props:{users:{},currentSessionId:{},camera:{}},setup(n){const e=n,t=c.computed(()=>e.users.filter(o=>o.sessionId!==e.currentSessionId).map(o=>({...o,screenX:(o.position[0]-e.camera.left)*e.camera.zoom,screenY:(o.position[1]-e.camera.top)*e.camera.zoom})));return(o,r)=>(c.openBlock(),c.createElementBlock("div",Mb,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(t.value,s=>(c.openBlock(),c.createElementBlock("div",{key:s.sessionId,class:"wov-user-cursor",style:c.normalizeStyle({transform:`translate(${s.screenX}px, ${s.screenY}px)`})},[(c.openBlock(),c.createElementBlock("svg",Tb,[c.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:Bb},null,8,Nb)])),c.createElementVNode("span",{class:"wov-cursor-label",style:c.normalizeStyle({backgroundColor:s.color})},c.toDisplayString(s.name),5)],4))),128))]))}}),Ib={key:0,class:"wov-offline-indicator"},Ob=c.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",Ib,"Working Offline"))}}),Db={key:0,class:"wov-version-mismatch-overlay"},Rb=c.defineComponent({__name:"VersionMismatch",props:{versionMismatch:{type:Boolean}},setup(n){function e(){window.location.reload()}return(t,o)=>n.versionMismatch?(c.openBlock(),c.createElementBlock("div",Db,[c.createElementVNode("div",{class:"wov-version-mismatch-dialog"},[o[0]||(o[0]=c.createElementVNode("p",null,"A new version is available.",-1)),o[1]||(o[1]=c.createElementVNode("p",null,"Please refresh the page to continue.",-1)),c.createElementVNode("button",{onClick:e},"Refresh")])])):c.createCommentVNode("",!0)}}),_b=c.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=le(),t=Se(x.Camera),o=x.defineQuery(a=>a.with(x.Synced,x.Block,x.Aabb)),r=c.ref(0),s=c.inject($e);if(s){const a=s.registerTickCallback(d=>{o.addedOrRemoved(d).length>0&&(r.value=o.current(d).length)});c.onUnmounted(a)}const i=c.ref(!1);c.watchEffect(()=>{i.value=!t.value.canSeeBlocks&&r.value>0});function l(){e(a=>{const d=o.current(a);if(d.length===0)return;let u=Number.POSITIVE_INFINITY,f=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(const E of d){const C=x.Aabb.read(a,E);u=Math.min(u,C.value[0]),f=Math.min(f,C.value[1]),p=Math.max(p,C.value[2]),h=Math.max(h,C.value[3])}const m=x.Screen.read(a),g=x.Camera.read(a);let y=Math.min(m.width/(p-u),m.height/(h-f));y/=1.1,y=Math.min(y,g.zoom);const k=(u+p)/2,w=(f+h)/2,b=k-m.width/y/2,S=w-m.height/y/2,v=x.Camera.write(a);v.left=b,v.top=S,v.zoom=y})}return(a,d)=>i.value?(c.openBlock(),c.createElementBlock("button",{key:0,class:"wov-back-to-content",onClick:l},[...d[0]||(d[0]=[c.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[c.createElementVNode("path",{d:"M10 12L6 8L10 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1),c.createTextVNode(" Back to content ",-1)])])):c.createCommentVNode("",!0)}}),Pb=["data-entity-id","data-selected","data-held-by-other","data-hovered"],Vb=c.defineComponent({__name:"WovenCanvas",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{}},emits:["ready"],setup(n,{emit:e}){var Gu;const t=x.defineQuery(T=>T.tracking(x.Block)),o=x.defineQuery(T=>T.with(x.Block).tracking(x.Connector)),r=x.defineQuery(T=>T.with(x.Block).tracking(oe.Selected)),s=x.defineQuery(T=>T.with(x.Block).tracking(x.Held)),i=x.defineQuery(T=>T.with(x.Block).tracking(x.Hovered)),l=x.defineQuery(T=>T.with(x.Block).tracking(x.Edited)),a=x.defineQuery(T=>T.with(x.Block).tracking(x.Opacity)),d=x.defineQuery(T=>T.tracking(x.User)),u=n,f=e,p=c.ref(null),h=c.shallowRef(null),m=x.UserData.parse(((Gu=u.editor)==null?void 0:Gu.user)??{}),g=new Set,y=new Map,k=c.shallowRef([]),w=new Map,b=new Map,S=new Set,v=new Map,E=c.shallowRef([]),C=c.ref(!0),M=c.ref(!1),B=c.ref(!0),I=c.shallowRef(x.Camera.default());function _(T,q,D){let z=w.get(T);z||(z=new Map,w.set(T,z));let P=z.get(q);return P||(P=new Set,z.set(q,P)),P.add(D),()=>{P.delete(D),P.size===0&&(z.delete(q),z.size===0&&w.delete(T))}}function j(T,q,D,z=!1){const P=w.get(q);if(!P)return;const O=P.get(D.name);if(!O||O.size===0)return;let de=null;z||(de=D.snapshot(T,q));for(const Ze of O)Ze(de)}function H(T,q){let D=b.get(T);return D||(D=new Set,b.set(T,D)),D.add(q),()=>{D.delete(q),D.size===0&&b.delete(T)}}function K(T,q){const D=b.get(q.name);if(!D||D.size===0)return;const z=q.snapshot(T);for(const P of D)P(z)}function G(T){return S.add(T),()=>{S.delete(T)}}function te(){return m.sessionId}function W(T){return y.get(T)??null}const L={hasEntity:T=>g.has(T),getEditor:()=>h.value,getAssetManager:()=>ce,getSessionId:te,getUserBySessionId:W,subscribeComponent:_,subscribeSingleton:H,registerTickCallback:G};c.provide($e,L),c.provide("containerRef",p);const F=zd();c.provide(Ii,F);let X=0,ie=null,Q=null,ce=null;async function Xe(){!h.value||!Q||(h.value.nextTick(T=>{hn(T),Ft(T);for(const q of S)q(T);Q&&Q.sync(T)}),await h.value.tick(),ie=requestAnimationFrame(Xe))}let yt=null;c.onMounted(async()=>{var Ze,De;if(!p.value)return;yt=()=>{var pn;(pn=p.value)==null||pn.scrollTo(0,0)},p.value.addEventListener("scroll",yt);const T=u.store??{},q={history:!0,...T};T.websocket&&(q.websocket={...T.websocket,onVersionMismatch:pn=>{var kt,fo;M.value=!0,(fo=(kt=T.websocket)==null?void 0:kt.onVersionMismatch)==null||fo.call(kt,pn)},onConnectivityChange:pn=>{var kt,fo;C.value=pn,(fo=(kt=T.websocket)==null?void 0:kt.onConnectivityChange)==null||fo.call(kt,pn)}}),Q=new Re.CanvasStore(q);const D=[],z=u.pluginOptions;(z==null?void 0:z.controls)!==!1&&D.push(tf.CanvasControlsPlugin((z==null?void 0:z.controls)??{})),(z==null?void 0:z.selection)!==!1&&D.push(oe.createSelectionPlugin((z==null?void 0:z.selection)||void 0)),(z==null?void 0:z.eraser)!==!1&&D.push(po.createEraserPlugin((z==null?void 0:z.eraser)||void 0)),(z==null?void 0:z.pen)!==!1&&D.push(mo.createPenPlugin()),(z==null?void 0:z.arrows)!==!1&&D.push(Y.createArrowsPlugin((z==null?void 0:z.arrows)||void 0)),D.push(Ju({store:Q})),(Ze=u.editor)!=null&&Ze.plugins&&D.push(...u.editor.plugins);const P={...u.editor,user:m,plugins:D,controls:u.controls},O=new x.Editor(p.value,P);await O.initialize(),await Q.initialize({components:O.components,singletons:O.singletons});const de=((De=T.persistence)==null?void 0:De.documentId)??"default";ce=new ib({provider:u.assetProvider??new cb,documentId:de}),await ce.init(),await ce.resumePendingUploads(),h.value=O,ie=requestAnimationFrame(Xe),B.value=!1,f("ready",O,Q)}),c.onUnmounted(()=>{var T;ie!==null&&cancelAnimationFrame(ie),ce==null||ce.close(),Q==null||Q.close(),(T=h.value)==null||T.dispose()});function hn(T){const{events:q,newIndex:D}=T.eventBuffer.readEvents(X);if(X=D,q.length===0)return;const{componentsById:z,singletonsById:P}=x.getResources(T);for(const{entityId:O,eventType:de,componentId:Ze}of q){if(O===x.SINGLETON_ENTITY_ID){if(de===x.EventType.CHANGED){const De=P.get(Ze);De&&K(T,De)}continue}if(de===x.EventType.ADDED)g.add(O);else if(de===x.EventType.REMOVED)g.delete(O),w.delete(O);else if(de===x.EventType.COMPONENT_ADDED){g.add(O);const De=z.get(Ze);De&&j(T,O,De)}else if(de===x.EventType.COMPONENT_REMOVED){const De=z.get(Ze);De&&j(T,O,De,!0)}else if(de===x.EventType.CHANGED){const De=z.get(Ze);De&&j(T,O,De)}}}function Ft(T){var z;let q=!1;for(const P of t.added(T)){const O=x.Block.snapshot(T,P),de=(z=h.value)==null?void 0:z.blockDefs[O.tag],Ze=(de==null?void 0:de.stratum)??"content";v.set(P,c.ref({entityId:P,block:O,stratum:Ze,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),q=!0}for(const P of t.removed(T))v.delete(P),q=!0;for(const P of t.changed(T)){const O=v.get(P);if(O){const de=x.Block.snapshot(T,P);O.value.block.rank!==de.rank&&(q=!0),O.value.block=de}}let D=!1;for(const P of d.addedOrChanged(T)){const O=x.User.snapshot(T,P);y.set(O.sessionId,O),D=!0}for(const P of d.removed(T)){const O=x.User.read(T,P);y.delete(O.sessionId),D=!0}D&&(k.value=Array.from(y.values()));for(const P of r.added(T)){const O=v.get(P);O&&!O.value.selected&&(O.value.selected=!0)}for(const P of r.removed(T)){const O=v.get(P);O&&O.value.selected&&(O.value.selected=!1)}for(const P of s.addedOrChanged(T)){const O=v.get(P);O&&(O.value.held=x.Held.snapshot(T,P))}for(const P of s.removed(T)){const O=v.get(P);O&&O.value.held!==null&&(O.value.held=null)}for(const P of i.added(T)){const O=v.get(P);O&&!O.value.hovered&&(O.value.hovered=!0)}for(const P of i.removed(T)){const O=v.get(P);O&&O.value.hovered&&(O.value.hovered=!1)}for(const P of l.added(T)){const O=v.get(P);O&&!O.value.edited&&(O.value.edited=!0)}for(const P of l.removed(T)){const O=v.get(P);O&&O.value.edited&&(O.value.edited=!1)}for(const P of a.addedOrChanged(T)){const O=v.get(P);O&&(O.value.opacity=x.Opacity.snapshot(T,P))}for(const P of a.removed(T)){const O=v.get(P);O&&O.value.opacity!==null&&(O.value.opacity=null)}for(const P of o.addedOrChanged(T)){const O=v.get(P);O&&(O.value.connector=x.Connector.snapshot(T,P))}for(const P of o.removed(T)){const O=v.get(P);O&&O.value.connector!==null&&(O.value.connector=null)}if(q){const P=Array.from(v.values());P.sort((O,de)=>O.value.block.rank>de.value.block.rank?1:-1),E.value=P}}H(x.Camera.name,T=>{T&&(I.value=T)});function Mr(T){const q=T.rotateZ!==0,D=T.flip[0],z=T.flip[1];if(!q&&!D&&!z)return;const P=[];return q&&P.push(`rotate(${T.rotateZ}rad)`),D&&P.push("scaleX(-1)"),z&&P.push("scaleY(-1)"),P.join(" ")}function Dn(T){const{held:q}=T;if(!q||!q.sessionId||q.sessionId===m.sessionId)return null;const D=W(q.sessionId);return(D==null?void 0:D.color)??null}function Ht(T){const{block:q,stratum:D,opacity:z}=T,P=Dn(T),O=z!==null?z.value/255:1;return{position:"absolute",left:`${q.position[0]}px`,top:`${q.position[1]}px`,width:`${q.size[0]}px`,height:`${q.size[1]}px`,zIndex:x.STRATUM_ORDER[D]*1e3,transform:Mr(q),opacity:O,pointerEvents:"none",userSelect:"none","--wov-held-by-color":P??void 0,transition:O===1?"opacity 0ms 32ms":void 0}}return(T,q)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:p,class:"wov-root",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"}},[n.background?c.renderSlot(T.$slots,"background",{key:0,background:n.background},()=>[c.createVNode(Su,{background:n.background},null,8,["background"])]):c.createCommentVNode("",!0),c.createElementVNode("div",{class:"wov-canvas",style:c.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:`scale(${I.value.zoom}) translate(${-I.value.left}px, ${-I.value.top}px)`,"--wov-zoom":I.value.zoom})},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(E.value,D=>(c.openBlock(),c.createElementBlock("div",{key:D.value.entityId,"data-entity-id":D.value.entityId,style:c.normalizeStyle(Ht(D.value)),"data-selected":D.value.selected||void 0,"data-held-by-other":Dn(D.value)!==null||void 0,"data-hovered":D.value.hovered||void 0,class:"wov-block"},[c.renderSlot(T.$slots,`block:${D.value.block.tag}`,c.mergeProps({ref_for:!0},D.value),()=>[D.value.block.tag==="selection-box"?(c.openBlock(),c.createBlock(ub,c.mergeProps({key:0,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-box"?(c.openBlock(),c.createBlock(hb,c.mergeProps({key:1,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-handle"?(c.openBlock(),c.createBlock(yb,c.mergeProps({key:2,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-handle"?(c.openBlock(),c.createBlock(Di,c.mergeProps({key:3,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-terminal"?(c.openBlock(),c.createBlock(Ri,c.mergeProps({key:4,ref_for:!0},D.value),null,16)):D.value.block.tag==="sticky-note"?(c.openBlock(),c.createBlock(kb,c.mergeProps({key:5,ref_for:!0},D.value),null,16)):D.value.block.tag==="eraser"?(c.openBlock(),c.createBlock(Xi,c.mergeProps({key:6,ref_for:!0},D.value),null,16)):D.value.block.tag==="pen-stroke"?(c.openBlock(),c.createBlock(Qi,c.mergeProps({key:7,ref_for:!0},D.value),null,16)):D.value.block.tag==="arc-arrow"?(c.openBlock(),c.createBlock(Oi,c.mergeProps({key:8,ref_for:!0},D.value),null,16)):D.value.block.tag==="elbow-arrow"?(c.openBlock(),c.createBlock(_i,c.mergeProps({key:9,ref_for:!0},D.value),null,16)):D.value.block.tag==="text"?(c.openBlock(),c.createBlock(Hd,c.mergeProps({key:10,ref_for:!0},D.value),null,16)):D.value.block.tag==="image"?(c.openBlock(),c.createBlock(Zi,c.mergeProps({key:11,ref_for:!0},D.value),null,16)):D.value.block.tag==="shape"?(c.openBlock(),c.createBlock(Fd,c.mergeProps({key:12,ref_for:!0},D.value),null,16)):c.createCommentVNode("",!0)])],12,Pb))),128))],4),h.value?c.renderSlot(T.$slots,"user-cursors",{key:1,users:k.value,currentSessionId:c.unref(m).sessionId,camera:I.value},()=>[c.createVNode(Ab,{users:k.value,"current-session-id":c.unref(m).sessionId,camera:I.value},null,8,["users","current-session-id","camera"])]):c.createCommentVNode("",!0),h.value?(c.openBlock(),c.createBlock(Eu,{key:2},{default:c.withCtx(D=>[c.renderSlot(T.$slots,"floating-menu",c.normalizeProps(c.guardReactiveProps(D)))]),_:3})):c.createCommentVNode("",!0),h.value?c.renderSlot(T.$slots,"user-presence",{key:3,users:k.value},()=>[c.createVNode($u,{users:k.value},null,8,["users"])]):c.createCommentVNode("",!0),h.value?c.renderSlot(T.$slots,"toolbar",{key:4},()=>[c.createVNode(Vu)]):c.createCommentVNode("",!0),h.value?c.renderSlot(T.$slots,"default",{key:5}):c.createCommentVNode("",!0),c.renderSlot(T.$slots,"offline-indicator",{isOnline:C.value},()=>[c.createVNode(Ob,{"is-online":C.value},null,8,["is-online"])]),c.renderSlot(T.$slots,"version-mismatch",{versionMismatch:M.value},()=>[c.createVNode(Rb,{"version-mismatch":M.value},null,8,["version-mismatch"])]),c.renderSlot(T.$slots,"back-to-content",{},()=>[c.createVNode(_b)]),c.renderSlot(T.$slots,"loading",{isLoading:B.value},()=>[c.createVNode(Mu,{"is-loading":B.value},null,8,["is-loading"])]),h.value?c.renderSlot(T.$slots,"file-drop-zone",{key:6},()=>[c.createVNode(Eb)]):c.createCommentVNode("",!0)],512))}});Object.defineProperty(A,"CanvasComponentDef",{enumerable:!0,get:()=>Re.CanvasComponentDef}),Object.defineProperty(A,"CanvasSingletonDef",{enumerable:!0,get:()=>Re.CanvasSingletonDef}),Object.defineProperty(A,"CanvasStore",{enumerable:!0,get:()=>Re.CanvasStore}),Object.defineProperty(A,"Synced",{enumerable:!0,get:()=>Re.Synced}),Object.defineProperty(A,"defineCanvasComponent",{enumerable:!0,get:()=>Re.defineCanvasComponent}),Object.defineProperty(A,"defineCanvasSingleton",{enumerable:!0,get:()=>Re.defineCanvasSingleton}),A.ARROW_HEADS=Tr,A.ArcArrow=Oi,A.ArcArrowTool=zw,A.ArrowHandle=Di,A.ArrowHead=at,A.ArrowHeadButton=ai,A.ArrowTerminal=Ri,A.ArrowThicknessButton=uu,A.CURSORS=Tu,A.CanvasBackground=Su,A.ColorButton=pu,A.ColorPicker=hu,A.CursorKind=un,A.EditableText=rr,A.EditingPlugin=Ju,A.ElbowArrow=_i,A.ElbowArrowTool=_u,A.Eraser=Xi,A.EraserTool=Ou,A.FloatingMenu=Eu,A.FloatingMenuBar=vu,A.HandTool=Bu,A.IconChevronDown=Ue,A.ImageBlock=Zi,A.ImageTool=Pu,A.LoadingOverlay=Mu,A.MenuButton=On,A.MenuDropdown=je,A.MenuTooltip=ci,A.PenStroke=Qi,A.PenStrokeThicknessButton=mu,A.PenTool=Du,A.SHAPES=_n,A.SelectTool=Nu,A.ShapeBlock=Fd,A.ShapeFillColorButton=gu,A.ShapeKindButton=yu,A.ShapeStrokeColorButton=ku,A.ShapeTool=Iu,A.StickyNoteTool=Au,A.TextAlignmentButton=di,A.TextBlock=Hd,A.TextBoldButton=ui,A.TextColorButton=yi,A.TextFontFamilyButton=hi,A.TextFontSizeButton=pi,A.TextItalicButton=mi,A.TextTool=Ru,A.TextUnderlineButton=gi,A.Toolbar=Vu,A.ToolbarButton=lt,A.UserPresence=$u,A.WovenCanvas=Vb,A.computeCommonComponents=Cu,A.createTooltipContext=zd,A.getArrowHead=mn,A.useComponent=fe,A.useComponents=Pt,A.useEditorContext=le,A.useFonts=bu,A.useQuery=Od,A.useSingleton=Se,A.useTextBatchController=Ld,A.useTextEditorController=lo,A.useTextFormatting=ot,A.useTextStretchBehavior=Qs,A.useToolbar=ei,A.useTooltipSingleton=$t,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|