@eastgatesystems/tbx-reader 0.1.4 → 0.1.7

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.
@@ -1,7 +1,7 @@
1
1
  var TbxDocument=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{get text(){return this._text}set text(e){this._text=e}get isRichText(){return this._isRichText}set isRichText(e){this._isRichText=e}constructor(e,t,n,r,i,a,o,s,c,l,u=!1){this.id=e,this.name=t,this.attributes=i,this.father=a,this.son=o,this.brother=s,this.elderBrother=c,this.ht=l,this.isAdornment=u,this.isAlias=!1,this.isAgent=!1,this.aliases=[],this._text=``,this._isRichText=!1,this.html=``,this._text=n,this._isRichText=r}getOriginal(){return this}unhook(){this.father?.son===this&&(this.father.son=this.brother),this.elderBrother&&(this.elderBrother.brother=this.brother),this.brother&&(this.brother.elderBrother=this.elderBrother),this.father=null,this.brother=null,this.elderBrother=null}getNumber(e){let t=parseFloat(this.get(e));return isNaN(t)?0:t}getBoolean(e){let t=this.get(e);return t!==``&&t!==`false`&&t!==`0`}getColor(e,t){let n=this.get(e);return!n||n===`transparent`?t:this.ht.colors.resolve(n)??t}get(e){let t=this.ht.getAttribute(e);return t?t.getValue(this):this.attributes.get(e)??``}get wordCount(){return this.text.trim()===``?0:this.text.trim().split(/\s+/).length}get children(){let e=[],t=this.son;for(;t;)e.push(t),t=t.brother;return e}get path(){let e=[],t=this;for(;t!==null&&t.father!==null;)e.unshift(t.name),t=t.father;return`/`+e.join(`/`)}isDescendantOf(e){let t=this;for(;t;){if(t===e)return!0;t=t.father}return!1}outboundLinks(){return this.ht.links.filter(e=>e.src===this&&!e.isPrototype()&&!e.isUrlLink())}outboundPlainLinks(){return this.ht.links.filter(e=>e.src===this&&e.srcSpan===null&&!e.isPrototype()&&!e.isUrlLink())}},n=class extends t{constructor(e,t,n,r,i,a,o){super(t,e.name,``,!1,n,r,null,null,null,o),this.original=e,this.isAlias=!0,this.brother=i,this.elderBrother=a}getOriginal(){return this.original}get text(){return this.original.text}get isRichText(){return this.original.isRichText}get html(){return this.original.html}set html(e){}get(e){let t=this.ht.getAttribute(e);return t?.canInherit?this.original.get(e):t?.getValue(this)??this.attributes.get(e)??``}},r=class extends t{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,s,c,l,!1),this.isAgent=!0}},i=function(e){return e[e.String=0]=`String`,e[e.Color=1]=`Color`,e[e.Number=2]=`Number`,e[e.File=3]=`File`,e[e.Boolean=4]=`Boolean`,e[e.Date=5]=`Date`,e[e.Alias=6]=`Alias`,e[e.Action=7]=`Action`,e[e.Set=8]=`Set`,e[e.URL=9]=`URL`,e[e.List=10]=`List`,e[e.Font=11]=`Font`,e[e.Interval=12]=`Interval`,e[e.Dictionary=13]=`Dictionary`,e[e.WindowPlace=100]=`WindowPlace`,e}({}),a=class{constructor(e){this.name=e.name,this.parent=e.parent,this.type=e.type,this.editable=e.editable,this.visibleInEditor=e.visibleInEditor,this.canInherit=e.canInherit,this.default=e.default,this.lines=e.lines}getValue(e){return this.resolve(e,new Set([e]))}resolve(e,t){let n=e.attributes.get(this.name);if(n!==void 0)return n;if(this.canInherit){let n=e.attributes.get(`Prototype`);if(n){let r=e.ht.findNoteByName(n);if(r&&!t.has(r))return t.add(r),this.resolve(r,t)}}return this.default}},o=class extends a{resolve(e,t){return String(e.text.length)}},s=class extends a{resolve(e,t){return String(e.wordCount)}};function c(e){if(e.son)return e.son;if(e.brother)return e.brother;let t=e.father;for(;t!==null&&t.father!==null;){if(t.brother)return t.brother;t=t.father}return null}var l=class extends a{resolve(e,t){let n=e;for(;n.father!==null;)n=n.father;let r=n,i=0;for(;r!==null;){if(r===e)return String(i);i++,r=c(r)}return this.default}},u=class extends a{resolve(e,t){if(e.father===null)return this.default;let n=1,r=e.father.son;for(;r!==null&&r!==e;)n++,r=r.brother;return String(n)}},d=class extends a{resolve(e,t){return e.attributes.get(`Name`)??e.name}},f=class extends a{resolve(e,t){return e.path}},p=class extends a{resolve(e,t){return e.father===null?``:e.father.path}},m=class extends a{resolve(e,t){let n=e.ht.links.filter(t=>t.dest===e&&!t.isPrototype()).length;return String(n)}},h=class extends a{resolve(e,t){let n=e.ht.links.filter(t=>t.src===e&&!t.isPrototype()&&!t.isUrlLink()).length;return String(n)}},g=class extends a{resolve(e,t){return String(e.ht.links.filter(t=>t.src===e&&t.isUrlLink()).length)}},_=class extends a{resolve(e,t){return String(e.ht.links.filter(t=>t.src===e&&t.srcSpan!==null).length)}},v=class extends a{resolve(e,t){return String(e.ht.links.filter(t=>t.src===e&&t.srcSpan===null).length)}},y=class extends a{resolve(e,t){let n=0,r=e;for(;r!==null&&r.father!==null;)n++,r=r.father;return String(n)}},b=class extends a{resolve(e,t){let n=0,r=e.son;for(;r!==null;)n++,r=r.brother;return String(n)}};function x(e){let t=0,n=e.son;for(;n!==null;)t+=1+x(n),n=n.brother;return t}var S={Name:d,TextLength:o,WordCount:s,OutlineOrder:l,SiblingOrder:u,Path:f,Container:p,InboundLinkCount:m,OutboundLinkCount:h,WebLinkCount:g,TextLinkCount:_,PlainLinkCount:v,OutlineDepth:y,ChildCount:b,DescendantCount:class extends a{resolve(e,t){return String(x(e))}}},C=class e{static hexToRgb(e){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}static rgbToHex(e,t,n){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);return`#${r(e)}${r(t)}${r(n)}`}static{this.MODIFIERS=[`lightest`,`lighter`,`light`,`darkest`,`darker`,`dark`,`muted`,`warmer`,`cooler`,`pale`]}static{this.MODIFIER_SET=new Set(e.MODIFIERS)}static{this.BLACK=new e(`#000000`)}static{this.WHITE=new e(`#ffffff`)}constructor(e){this.hex=e}toString(){return this.hex}static parse(t){if(/^#[0-9a-f]{6}$/i.test(t))return new e(t);let n=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(t);if(n)return new e(`#${n[1]}${n[1]}${n[2]}${n[2]}${n[3]}${n[3]}`);let r=/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i.exec(t);if(r)return new e(e.rgbToHex(Math.max(0,Math.min(255,parseInt(r[1],10))),Math.max(0,Math.min(255,parseInt(r[2],10))),Math.max(0,Math.min(255,parseInt(r[3],10)))));let i=/^hsv\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec(t);return i?new w(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3])).toTbxColor():null}get luma(){let t=e.hexToRgb(this.hex);if(!t)return 0;let n=t[0]/255,r=t[1]/255,i=t[2]/255;return Math.sqrt(.299*n*n+.587*r*r+.114*i*i)}get automaticBorderColor(){let t=e.hexToRgb(this.hex);if(!t)return e.BLACK;let n=w.from(this).v>50?0:255;return new e(e.rgbToHex(Math.round(.75*t[0]+.25*n),Math.round(.75*t[1]+.25*n),Math.round(.75*t[2]+.25*n)))}get contrastingTextColor(){let t=this.luma;return t>.7?e.BLACK:t>.55?new e(`#ffff00`):e.WHITE}},w=class e{constructor(e,t,n){this.h=e,this.s=t,this.v=n}static from(t){let n=C.hexToRgb(t.hex);if(!n)return new e(0,0,0);let[r,i,a]=n,o=r/255,s=i/255,c=a/255,l=Math.max(o,s,c),u=l-Math.min(o,s,c),d=l*100,f=l===0?0:u/l*100,p=0;return u!==0&&(p=o===l?(s-c)/u*60:s===l?(2+(c-o)/u)*60:(4+(o-s)/u)*60,p<0&&(p+=360)),new e(p,f,d)}toTbxColor(){let{h:e,s:t,v:n}=this,r=t/100,i=n/100;for(;e>360;)e-=360;for(;e<0;)e+=360;if(r===0){let e=Math.round(i*255);return new C(C.rgbToHex(e,e,e))}let a=e/60,o=Math.floor(a),s=a-o,c=i*(1-r),l=i*(1-r*s),u=i*(1-r*(1-s)),d,f,p;switch(o%6){case 0:d=i,f=u,p=c;break;case 1:d=l,f=i,p=c;break;case 2:d=c,f=i,p=u;break;case 3:d=c,f=l,p=i;break;case 4:d=u,f=c,p=i;break;default:d=i,f=c,p=l;break}let m=Math.max(1,d,f,p);return new C(C.rgbToHex(Math.round(d/m*255),Math.round(f/m*255),Math.round(p/m*255)))}darker(t){let n=t*.5;return new e(this.h,100-(100-this.s)/(1+n),this.v/(1+n))}lighter(t){return new e(this.h,this.s/(1+t),100-(100-this.v)/(1+t))}desaturate(){return new e(this.h,this.s/4,this.v)}warmer(){let t=this.h-10;return new e(t<0?t+360:t,this.s,this.v)}cooler(){return new e(this.h+10,this.s,this.v)}},T=class{constructor(e){this.map=new Map(e)}splitModifier(e){let t=e.indexOf(` `);if(t===-1)return{mod:null,base:e};let n=e.slice(0,t);return C.MODIFIER_SET.has(n)?{mod:n,base:e.slice(t+1).trim()}:{mod:null,base:e}}applyModifier(e,t){let n=w.from(e);switch(t){case`dark`:n=n.darker(1);break;case`darker`:n=n.darker(2);break;case`darkest`:n=n.darker(3);break;case`light`:n=n.lighter(1);break;case`lighter`:n=n.lighter(2);break;case`lightest`:n=n.lighter(3);break;case`muted`:n=n.desaturate();break;case`warmer`:n=n.warmer();break;case`cooler`:n=n.cooler();break;case`pale`:break}return n.toTbxColor()}resolve(e,t){let n=this.map.get(e);if(n)return new C(n);let r=C.parse(e);if(r)return r;let{mod:i,base:a}=this.splitModifier(e);if(i){let e=this.map.get(a)?new C(this.map.get(a)):C.parse(a);if(e)return this.applyModifier(e,i)}return t}};function E(e){return/\s/.test(e)}function D(e){return e>=`0`&&e<=`9`}function O(e){return/[a-zA-Z_]/.test(e)}function k(e){return/[a-zA-Z0-9_]/.test(e)}var A=new Set([`|=`,`&=`,`+=`,`-=`,`==`,`!=`,`<=`,`>=`]),ee=class{constructor(e){this.input=e,this.i=0,this.tokens=[]}lexAttrRef(){this.i++;let e=``;for(;this.i<this.input.length&&k(this.input[this.i]);)e+=this.input[this.i++];this.tokens.push({kind:`attrRef`,value:e})}lexQuotedString(e){this.i++;let t=``;for(;this.i<this.input.length&&this.input[this.i]!==e;)if(this.input[this.i]===`\\`&&this.i+1<this.input.length){this.i++;let e=this.input[this.i++];e===`"`?t+=`"`:e===`'`?t+=`'`:e===`\\`?t+=`\\`:e===`n`?t+=`
2
2
  `:e===`t`?t+=` `:t+=e}else t+=this.input[this.i++];this.i<this.input.length&&this.i++,this.tokens.push({kind:`string`,value:t})}lexNumber(){let e=``;for(;this.i<this.input.length&&D(this.input[this.i]);)e+=this.input[this.i++];if(this.i<this.input.length&&this.input[this.i]===`.`&&this.i+1<this.input.length&&D(this.input[this.i+1]))for(e+=this.input[this.i++];this.i<this.input.length&&D(this.input[this.i]);)e+=this.input[this.i++];this.tokens.push({kind:`number`,value:e})}lexIdent(){let e=``;for(;this.i<this.input.length&&k(this.input[this.i]);)e+=this.input[this.i++];this.tokens.push({kind:`ident`,value:e})}tokenize(){for(;this.i<this.input.length;){if(E(this.input[this.i])){this.i++;continue}let e=this.input[this.i];if(e===`$`){this.lexAttrRef();continue}if(e===`"`||e===`'`){this.lexQuotedString(e);continue}if(D(e)){this.lexNumber();continue}if(O(e)){this.lexIdent();continue}if(e===`.`&&this.i+1<this.input.length&&this.input[this.i+1]===`.`){this.tokens.push({kind:`ident`,value:`..`}),this.i+=2;continue}if(this.i+1<this.input.length){let t=e+this.input[this.i+1];if(A.has(t)){this.tokens.push({kind:`op`,value:t}),this.i+=2;continue}}switch(e){case`=`:this.tokens.push({kind:`op`,value:`=`});break;case`+`:this.tokens.push({kind:`op`,value:`+`});break;case`-`:this.tokens.push({kind:`op`,value:`-`});break;case`*`:this.tokens.push({kind:`op`,value:`*`});break;case`/`:this.tokens.push({kind:`op`,value:`/`});break;case`<`:this.tokens.push({kind:`op`,value:`<`});break;case`>`:this.tokens.push({kind:`op`,value:`>`});break;case`&`:this.tokens.push({kind:`op`,value:`&`});break;case`|`:this.tokens.push({kind:`op`,value:`|`});break;case`!`:this.tokens.push({kind:`op`,value:`!`});break;case`(`:this.tokens.push({kind:`lparen`,value:`(`});break;case`)`:this.tokens.push({kind:`rparen`,value:`)`});break;case`{`:this.tokens.push({kind:`lbrace`,value:`{`});break;case`}`:this.tokens.push({kind:`rbrace`,value:`}`});break;case`[`:this.tokens.push({kind:`lbracket`,value:`[`});break;case`]`:this.tokens.push({kind:`rbracket`,value:`]`});break;case`;`:this.tokens.push({kind:`semi`,value:`;`});break;case`,`:this.tokens.push({kind:`comma`,value:`,`});break;case`.`:this.tokens.push({kind:`dot`,value:`.`});break;case`:`:this.tokens.push({kind:`colon`,value:`:`});break}this.i++}return this.tokens.push({kind:`eof`,value:``}),this.tokens}};function te(e){return new ee(e).tokenize()}var ne={"|":10,"&":20,"==":30,"!=":30,"<":40,"<=":40,">":40,">=":40,"+":50,"-":50,"*":60,"/":60},re=class{constructor(e){this.tokens=e,this.pos=0}peek(){return this.tokens[this.pos]??{kind:`eof`,value:``}}consume(){return this.tokens[this.pos++]??{kind:`eof`,value:``}}expect(e){let t=this.consume();if(t.kind!==e)throw Error(`Expected ${e}, got ${t.kind} ("${t.value}") at token ${this.pos}`);return t}at(e){return this.peek().kind===e}lbp(e){return e.kind===`dot`||e.kind===`lbracket`?80:e.kind===`op`?ne[e.value]??0:0}nud(e){switch(e.kind){case`string`:return{kind:`literal`,litKind:`string`,value:e.value};case`number`:return{kind:`literal`,litKind:`number`,value:e.value};case`attrRef`:{let t=null;return this.at(`lparen`)&&(this.consume(),t=this.parseExpr(0),this.expect(`rparen`)),{kind:`attrRef`,name:e.value,designator:t}}case`ident`:{let t=e.value;if(t===`true`)return{kind:`literal`,litKind:`boolean`,value:`true`};if(t===`false`)return{kind:`literal`,litKind:`boolean`,value:`false`};if(this.at(`lparen`)){this.consume();let e=this.parseArgList();return this.expect(`rparen`),{kind:`call`,name:t,args:e}}return{kind:`ident`,name:t}}case`op`:if(e.value===`-`)return{kind:`unary`,op:`-`,arg:this.parseExpr(70)};if(e.value===`!`)return{kind:`unary`,op:`!`,arg:this.parseExpr(70)};throw Error(`Unexpected operator in expression prefix: "${e.value}"`);case`lparen`:{let e=this.parseExpr(0);return this.expect(`rparen`),e}case`dot`:return{kind:`ident`,name:`.`};default:throw Error(`Unexpected token in expression: ${e.kind} ("${e.value}")`)}}led(e,t){if(e.kind===`dot`){let e=this.consume();if(e.kind!==`ident`)throw Error(`Expected method name after dot, got ${e.kind} ("${e.value}")`);let n=e.value;if(n===`eachLine`){this.expect(`lparen`);let e=this.consume();if(e.kind!==`ident`)throw Error(`Expected variable name in eachLine`);let n=e.value,r;return this.at(`colon`)&&(this.consume(),r=this.parseExpr(0)),this.expect(`rparen`),{kind:`dotEachLine`,left:t,loopVar:n,pred:r}}if(n===`try`||n===`thenTry`)return{kind:`dotBlock`,left:t,method:n};let r=[];return this.at(`lparen`)&&(this.consume(),r=this.parseArgList(),this.expect(`rparen`)),{kind:`dot`,left:t,method:n,args:r}}if(e.kind===`lbracket`){let e=this.parseExpr(0);return this.expect(`rbracket`),{kind:`subscript`,left:t,key:e}}if(e.kind===`op`){let n=e.value,r=ne[n]??0;return{kind:`binary`,op:n,left:t,right:this.parseExpr(r)}}throw Error(`Unexpected token in infix position: ${e.kind} ("${e.value}")`)}parseExpr(e=0){let t=this.consume(),n=this.nud(t);for(;;){let t=this.peek();if(this.lbp(t)<=e)break;this.consume(),n=this.led(t,n)}return n}parseArgList(){let e=[];if(this.at(`rparen`))return e;for(e.push(this.parseExpr(0));this.at(`comma`);)this.consume(),e.push(this.parseExpr(0));return e}};function ie(e){return new re(te(e)).parseExpr(0)}var ae=class{constructor(e,t,n,r){this.x=e,this.y=t,this.w=n,this.h=r}intersects(e){return this.x<e.x+e.w&&e.x<this.x+this.w&&this.y<e.y+e.h&&e.y<this.y+this.h}};function oe(e){return new ae(parseFloat(e.attributes.get(`Xpos`)??`0`),parseFloat(e.attributes.get(`Ypos`)??`0`),parseFloat(e.attributes.get(`Width`)??`0`),parseFloat(e.attributes.get(`Height`)??`0`))}var se=`__failed__`;function ce(e){return e?.get(se)===`true`}function j(e,t=!0){e.set(se,t?`true`:`false`)}function le(e){let t=[];function n(e){for(let r of e.children)r.isAdornment||(t.push(r),n(r))}return n(e),t}function ue(e){return e.father?e.father.children.filter(t=>t!==e&&!t.isAdornment):[]}function de(e){let t=[],n=e.father;for(;n!==null&&n.father!==null;)t.push(n),n=n.father;return t}function fe(e){if(e.son)return e.son;if(e.brother)return e.brother;let t=e.father;for(;t!==null&&t.father!==null;){if(t.brother)return t.brother;t=t.father}return null}function pe(e){let t=e.elderBrother;if(t){let e=t;for(;;){let t=e.children.filter(e=>!e.isAdornment);if(t.length===0)break;e=t[t.length-1]}return e}let n=e.father;return!n||n.father===null?null:n}function me(e){let t=new Map;if(e===``)return t;for(let n of e.split(`;`)){let e=n.indexOf(`:`);e===-1?t.set(n,``):t.set(n.slice(0,e),n.slice(e+1))}return t}function M(e,t){if(e.kind===`ident`)switch(e.name){case`children`:return t.children.filter(e=>!e.isAdornment);case`descendants`:return le(t);case`siblings`:return ue(t);case`ancestor`:case`ancestors`:return de(t);case`all`:return t.ht.root?le(t.ht.root):[]}let n=L(e,t),r=t.ht.findNoteByName(P(n));return r?[r]:[]}function N(e,t=2){return String(e).padStart(t,`0`)}function he(e){return`${e.getFullYear()}-${N(e.getMonth()+1)}-${N(e.getDate())} ${N(e.getHours())}:${N(e.getMinutes())}:${N(e.getSeconds())}`}function ge(e){if(!e)return new Date(0);let t=e.replace(` `,`T`),n=new Date(t);return isNaN(n.getTime())?new Date(0):n}var _e=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],ve=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function ye(e,t){return t.replace(`%Y`,String(e.getFullYear())).replace(`%m`,N(e.getMonth()+1)).replace(`%d`,N(e.getDate())).replace(`%H`,N(e.getHours())).replace(`%M`,N(e.getMinutes())).replace(`%S`,N(e.getSeconds())).replace(`%A`,_e[e.getDay()]).replace(`%B`,ve[e.getMonth()])}function P(e){switch(e.kind){case`string`:return e.value;case`number`:return be(e.value);case`boolean`:return e.value?`true`:`false`;case`date`:return he(e.value);case`list`:return e.value.join(`;`);case`dict`:return[...e.value.entries()].map(([e,t])=>`${e}:${t}`).join(`;`);case`color`:return e.value;case`interval`:return String(e.value)}}function be(e){return String(e)}function F(e){switch(e.kind){case`number`:return e.value;case`string`:return parseFloat(e.value)||0;case`boolean`:return+!!e.value;default:return 0}}function xe(e){switch(e.kind){case`boolean`:return e.value;case`number`:return e.value!==0;case`string`:return e.value!==``&&e.value!==`false`&&e.value!==`0`;default:return!1}}function I(e){if(e.kind===`number`)return e.value;if(e.kind===`string`){if(e.value===``)return null;let t=parseFloat(e.value);return isNaN(t)?null:t}return null}function Se(e,t,n){if(e.kind===`ident`)switch(e.name){case`parent`:return t.father;case`firstChild`:return t.son;case`lastChild`:{let e=t.children.filter(e=>!e.isAdornment);return e.length>0?e[e.length-1]:null}case`nextSibling`:case`nextSiblingItem`:return t.brother;case`prevSibling`:case`previousSibling`:case`prevSiblingItem`:case`previousSiblingItem`:return t.elderBrother;case`.`:case`this`:return t;case`..`:return t.father;case`grandparent`:{let e=t.father;if(!e||e.father===null)return null;let n=e.father;return!n||n.father===null?null:n}case`child`:return t.son;case`firstSibling`:return t.father?t.father.son:null;case`lastSibling`:{if(!t.father)return null;let e=t.father.children.filter(e=>!e.isAdornment);return e.length>0?e[e.length-1]:null}case`cover`:return t.ht.root?t.ht.root.son:null;case`next`:return fe(t);case`nextItem`:return fe(t);case`previous`:return pe(t);case`previousItem`:return pe(t);case`randomChild`:case`randomchild`:{let e=t.children.filter(e=>!e.isAdornment);return e.length===0?t:e[Math.floor(Math.random()*e.length)]}case`that`:{let e=n?.get(`__that__`);return e===void 0?null:t.ht.findNoteById(parseInt(e,10))}case`agent`:{let e=n?.get(`__agent__`);return!e||!t?null:t.ht.findNoteById(parseInt(e,10))}default:return t.ht.findNoteByName(e.name)}if(e.kind===`literal`&&e.litKind===`string`)return t.ht.findNoteByName(e.value);let r=L(e,t,n);return t.ht.findNoteByName(P(r))}function L(e,t,n){switch(e.kind){case`literal`:switch(e.litKind){case`string`:return{kind:`string`,value:e.value};case`number`:return{kind:`number`,value:parseFloat(e.value)};case`boolean`:return{kind:`boolean`,value:e.value===`true`}}case`attrRef`:{if(!t)return{kind:`string`,value:``};let r=e.designator?Se(e.designator,t,n):t;if(!r)return{kind:`string`,value:``};let a=r.get(e.name),o=r.ht.getAttribute(e.name)?.type;return o===i.Set||o===i.List?{kind:`list`,value:a===``?[]:a.split(`;`)}:o===i.Dictionary?{kind:`dict`,value:me(a)}:{kind:`string`,value:a}}case`ident`:if(e.name===`now`)return{kind:`date`,value:new Date};if(e.name===`today`){let e=new Date;return e.setHours(0,0,0,0),{kind:`date`,value:e}}return n?.has(e.name)?{kind:`string`,value:n.get(e.name)}:t?{kind:`string`,value:t.get(e.name)}:{kind:`string`,value:e.name};case`unary`:{let r=L(e.arg,t,n);switch(e.op){case`-`:return{kind:`number`,value:-F(r)};case`!`:return{kind:`boolean`,value:!xe(r)};default:throw Error(`Unknown unary operator: ${e.op}`)}}case`binary`:{let r=L(e.left,t,n),i=L(e.right,t,n);switch(e.op){case`+`:{if(r.kind===`list`&&i.kind===`list`)return{kind:`list`,value:[...r.value,...i.value]};if(r.kind===`date`&&i.kind===`interval`)return{kind:`date`,value:new Date(r.value.getTime()+i.value*1e3)};let e=I(r),t=I(i);return e!==null&&t!==null?{kind:`number`,value:e+t}:{kind:`string`,value:P(r)+P(i)}}case`-`:return r.kind===`date`&&i.kind===`interval`?{kind:`date`,value:new Date(r.value.getTime()-i.value*1e3)}:r.kind===`date`&&i.kind===`date`?{kind:`interval`,value:(r.value.getTime()-i.value.getTime())/1e3}:{kind:`number`,value:F(r)-F(i)};case`*`:return{kind:`number`,value:F(r)*F(i)};case`/`:return{kind:`number`,value:F(r)/F(i)};case`<`:case`<=`:case`>`:case`>=`:{let t=I(r),n=I(i),a=t!==null&&n!==null?t-n:P(r).localeCompare(P(i));return{kind:`boolean`,value:Ce(e.op,a)}}case`==`:{let e=I(r),t=I(i);return e!==null&&t!==null?{kind:`boolean`,value:e===t}:{kind:`boolean`,value:P(r)===P(i)}}case`!=`:{let e=I(r),t=I(i);return e!==null&&t!==null?{kind:`boolean`,value:e!==t}:{kind:`boolean`,value:P(r)!==P(i)}}case`&`:return{kind:`boolean`,value:xe(r)&&xe(i)};case`|`:return{kind:`boolean`,value:xe(r)||xe(i)};default:throw Error(`Unknown binary operator: ${e.op}`)}}case`call`:return Ne(e.name,e.args,t,n);case`dot`:return Pe(L(e.left,t,n),e.method,e.args,t,n);case`subscript`:{let r=L(e.left,t,n),i=P(L(e.key,t,n));if(r.kind===`dict`)return{kind:`string`,value:r.value.get(i)??``};if(r.kind===`list`){let e=parseInt(i,10);return{kind:`string`,value:r.value[e]??``}}return{kind:`string`,value:``}}case`dotEachLine`:case`dotBlock`:return{kind:`string`,value:``}}}function Ce(e,t){switch(e){case`<`:return t<0;case`<=`:return t<=0;case`>`:return t>0;case`>=`:return t>=0;default:return!1}}function we(e,t){let n=new Map(t);return n.set(`__that__`,String(e.id)),n}function Te(e){return e.kind===`ident`&&(e.name===`children`||e.name===`descendants`||e.name===`siblings`||e.name===`ancestor`||e.name===`ancestors`||e.name===`all`)}function Ee(e){switch(e){case i.String:return`string`;case i.Color:return`color`;case i.Number:return`number`;case i.File:return`file`;case i.Boolean:return`boolean`;case i.Date:return`date`;case i.Alias:return`alias`;case i.Action:return`action`;case i.Set:return`set`;case i.URL:return`url`;case i.List:return`list`;case i.Font:return`font`;case i.Interval:return`interval`;case i.Dictionary:return`dictionary`;default:return`string`}}function De(e){let t=e.id;function n(e){for(let r of e.children)r.id>t&&(t=r.id),n(r)}return n(e),t}function Oe(e,t){let n=e.children;if(n.length===0)e.son=t;else{let e=n[n.length-1];e.brother=t,t.elderBrother=e}}function ke(e,t,n,r){if(!t||e.length<1)return{kind:`string`,value:``};let i=n.str(e[0]);if(!i)return{kind:`string`,value:``};let a,o;if(e.length>=2)o=i,a=R(n.str(e[1]),t);else if(i.startsWith(`/`)){let e=i.lastIndexOf(`/`);o=i.slice(e+1),a=R(i.slice(0,e)||`/`,t)}else o=i,a=t;if(!a||!o)return{kind:`string`,value:``};let s=a.children.find(e=>e.name===o);if(s)return{kind:`string`,value:s.get(`Path`)};let c=r(De(t.ht.root)+1,o,a,t.ht);return Oe(a,c),{kind:`string`,value:c.get(`Path`)}}function Ae(e){if(!e.isAlias)for(let t of[...e.aliases])Ae(t);for(let t of[...e.children])Ae(t);if(e.ht.links=e.ht.links.filter(t=>t.src!==e&&t.dest!==e),e.isAlias){let t=e.original;t.aliases=t.aliases.filter(t=>t!==e)}e.unhook()}function R(e,t){if(!e)return null;if(e.startsWith(`/`)){let n=e.slice(1).split(`/`).filter(e=>e!==``);if(n.length===0)return t.ht.root;let r=t.ht.root;for(let e of n)r=r?r.children.find(t=>t.name===e)??null:null;return r}return t.ht.findNoteByName(e)}function je(e,t){return!e||e.father!==t.father||e.isAdornment?!1:oe(e).intersects(oe(t))}var Me=class e{constructor(e,t){this.note=e,this.locals=t}eval(e){return L(e,this.note,this.locals)}str(e){return P(this.eval(e))}num(e){return F(this.eval(e))}bool(e){return xe(this.eval(e))}bind(t){return new e(t,this.locals)}inner(){return this.note?new e(this.note,we(this.note,this.locals)):this}};function Ne(e,i,a,o){let s=new Me(a,o);switch(e){case`count`:return a?{kind:`number`,value:M(i[0],a).length}:{kind:`number`,value:0};case`sum`:{if(!a)return{kind:`number`,value:0};let e=M(i[0],a),t=s.inner();return{kind:`number`,value:e.reduce((e,n)=>e+t.bind(n).num(i[1]),0)}}case`avg`:{if(!a)return{kind:`number`,value:0};let e=M(i[0],a);if(e.length===0)return{kind:`number`,value:0};let t=s.inner();return{kind:`number`,value:e.reduce((e,n)=>e+t.bind(n).num(i[1]),0)/e.length}}case`min`:{if(!Te(i[0]))return{kind:`number`,value:Math.min(s.num(i[0]),s.num(i[1]))};if(!a)return{kind:`number`,value:0};let e=M(i[0],a);if(e.length===0)return{kind:`number`,value:0};let t=s.inner();return{kind:`number`,value:Math.min(...e.map(e=>t.bind(e).num(i[1])))}}case`max`:{if(!Te(i[0]))return{kind:`number`,value:Math.max(s.num(i[0]),s.num(i[1]))};if(!a)return{kind:`number`,value:0};let e=M(i[0],a);if(e.length===0)return{kind:`number`,value:0};let t=s.inner();return{kind:`number`,value:Math.max(...e.map(e=>t.bind(e).num(i[1])))}}case`collect`:{if(!a)return{kind:`list`,value:[]};let e=s.inner();return{kind:`list`,value:M(i[0],a).map(t=>e.bind(t).str(i[1]))}}case`collect_if`:{if(!a)return{kind:`list`,value:[]};let e=s.inner();return{kind:`list`,value:M(i[0],a).filter(t=>e.bind(t).bool(i[1])).map(t=>e.bind(t).str(i[2]))}}case`count_if`:{if(!a)return{kind:`number`,value:0};let e=s.inner();return{kind:`number`,value:M(i[0],a).filter(t=>e.bind(t).bool(i[1])).length}}case`sum_if`:{if(!a)return{kind:`number`,value:0};let e=s.inner();return{kind:`number`,value:M(i[0],a).filter(t=>e.bind(t).bool(i[1])).reduce((t,n)=>t+e.bind(n).num(i[2]),0)}}case`every`:{if(!a)return{kind:`boolean`,value:!0};let e=s.inner();return{kind:`boolean`,value:M(i[0],a).every(t=>e.bind(t).bool(i[1]))}}case`any`:{if(!a)return{kind:`boolean`,value:!1};let e=s.inner();return{kind:`boolean`,value:M(i[0],a).some(t=>e.bind(t).bool(i[1]))}}case`abs`:return{kind:`number`,value:Math.abs(s.num(i[0]))};case`round`:return{kind:`number`,value:Math.round(s.num(i[0]))};case`floor`:return{kind:`number`,value:Math.floor(s.num(i[0]))};case`ceil`:return{kind:`number`,value:Math.ceil(s.num(i[0]))};case`sqrt`:return{kind:`number`,value:Math.sqrt(s.num(i[0]))};case`log`:return{kind:`number`,value:Math.log(s.num(i[0]))};case`exp`:return{kind:`number`,value:Math.exp(s.num(i[0]))};case`rand`:return{kind:`number`,value:Math.random()};case`pow`:return{kind:`number`,value:s.num(i[0])**+s.num(i[1])};case`mod`:return{kind:`number`,value:s.num(i[0])%s.num(i[1])};case`now`:return{kind:`date`,value:new Date};case`today`:{let e=new Date;return e.setHours(0,0,0,0),{kind:`date`,value:e}}case`date`:return i.length>=3?{kind:`date`,value:new Date(s.num(i[0]),s.num(i[1])-1,s.num(i[2]),i.length>=5?s.num(i[3]):0,i.length>=5?s.num(i[4]):0,0)}:{kind:`date`,value:ge(s.str(i[0]))};case`seconds`:return{kind:`interval`,value:s.num(i[0])};case`minutes`:return{kind:`interval`,value:s.num(i[0])*60};case`hours`:return{kind:`interval`,value:s.num(i[0])*3600};case`days`:return{kind:`interval`,value:s.num(i[0])*86400};case`weeks`:return{kind:`interval`,value:s.num(i[0])*604800};case`years`:return{kind:`interval`,value:s.num(i[0])*365*86400};case`attribute`:{if(!a)return{kind:`dict`,value:new Map};let e=s.str(i[0]),t=a.ht.getAttribute(e);return t?{kind:`dict`,value:new Map([[`type`,Ee(t.type)],[`default`,t.default],[`category`,t.parent],[`suggested`,``],[`description`,``],[`sequential`,``],[`lines`,`1`],[`readonly`,``]])}:{kind:`dict`,value:new Map}}case`number`:return{kind:`number`,value:s.num(i[0])};case`string`:return{kind:`string`,value:s.str(i[0])};case`boolean`:return{kind:`boolean`,value:s.bool(i[0])};case`find`:{if(!a)return{kind:`list`,value:[]};let e=a.ht.root;if(!e)return{kind:`list`,value:[]};let t=s.inner();return{kind:`list`,value:le(e).filter(e=>t.bind(e).bool(i[0])).map(e=>e.get(`Path`))}}case`format`:{if(i.length===0)return{kind:`string`,value:``};let e=s.eval(i[0]);if(e.kind===`date`)return i.length<2?{kind:`string`,value:``}:{kind:`string`,value:ye(e.value,s.str(i[1]))};if(e.kind===`list`){let t=e.value;if(i.length>=5){let e=s.str(i[1]),n=s.str(i[2]),r=s.str(i[3]),a=s.str(i[4]);return{kind:`string`,value:e+t.map(e=>n+e+r).join(``)+a}}return i.length>=2?{kind:`string`,value:t.join(s.str(i[1]))}:{kind:`string`,value:t.join(`;`)}}let t=F(e);if(i.length<2)return{kind:`string`,value:String(t)};let n=s.str(i[1]);if(n===`X`)return{kind:`string`,value:Fe(Math.floor(t))};if(n===`l`||n===`L`)return{kind:`string`,value:t.toLocaleString()};if(n===`$`)return{kind:`string`,value:t.toLocaleString(void 0,{style:`currency`,currency:`USD`})};let r=parseInt(n,10);if(isNaN(r))return{kind:`string`,value:String(t)};let a=t.toFixed(r);if(i.length>=3){let e=Math.round(s.num(i[2])),t=i.length>=4?s.str(i[3])[0]??` `:` `;return{kind:`string`,value:a.padStart(e,t)}}return{kind:`string`,value:a}}case`create`:return ke(i,a,s,(e,n,r,i)=>new t(e,n,``,!1,new Map,r,null,null,null,i));case`createAgent`:return ke(i,a,s,(e,t,n,i)=>new r(e,t,``,!1,new Map,n,null,null,null,i));case`createAdornment`:return ke(i,a,s,(e,n,r,i)=>new t(e,n,``,!1,new Map,r,null,null,null,i,!0));case`delete`:{if(!a||i.length<1)return{kind:`string`,value:``};let e=s.str(i[0]);if(!e)return{kind:`string`,value:``};let t;if(i.length>=2){let n=R(e,a),r=s.str(i[1]);t=n?.children.find(e=>e.name===r)??null}else t=R(e,a);return!t||t===a.ht.root||Ae(t),{kind:`string`,value:``}}case`inside`:{if(!a||i.length<1)return{kind:`boolean`,value:!1};let e=R(s.str(i[0]),a);if(!e||e===a)return{kind:`boolean`,value:!1};if(e.isAdornment)return{kind:`boolean`,value:je(a,e)||je(a.getOriginal(),e)};if(a.father===e)return{kind:`boolean`,value:!0};let t=a.getOriginal();return t.father===e||t.aliases.some(t=>t.father===e)?{kind:`boolean`,value:!0}:{kind:`boolean`,value:!1}}case`createAlias`:{if(!a||i.length<2)return{kind:`string`,value:``};let e=s.str(i[0]),t=s.str(i[1]),r=R(e,a);if(!r)return{kind:`string`,value:``};let o=R(t,a);if(!o)return{kind:`string`,value:``};o=o.getOriginal();let c=r.children.find(e=>e.isAlias&&e.original===o);if(c)return{kind:`string`,value:c.get(`Path`)};let l=new n(o,De(a.ht.root)+1,new Map,r,null,null,a.ht);return Oe(r,l),o.aliases.push(l),{kind:`string`,value:l.get(`Path`)}}default:return{kind:`string`,value:``}}}function Pe(e,t,n,r,i){let a=new Me(r,i);if(e.kind===`date`){let r=e.value;switch(t){case`year`:return{kind:`number`,value:r.getFullYear()};case`month`:return{kind:`number`,value:r.getMonth()+1};case`day`:return{kind:`number`,value:r.getDate()};case`hour`:return{kind:`number`,value:r.getHours()};case`minute`:return{kind:`number`,value:r.getMinutes()};case`second`:return{kind:`number`,value:r.getSeconds()};case`weekday`:return{kind:`number`,value:r.getDay()};case`format`:return{kind:`string`,value:ye(r,a.str(n[0]))};default:return{kind:`string`,value:``}}}if(e.kind===`list`)switch(t){case`count`:return{kind:`number`,value:e.value.length};case`contains`:return{kind:`boolean`,value:e.value.includes(a.str(n[0]))};case`sort`:return{kind:`list`,value:[...e.value].sort()};case`unique`:{let t=new Set;return{kind:`list`,value:e.value.filter(e=>t.has(e)?!1:(t.add(e),!0))}}default:return{kind:`string`,value:``}}if(e.kind===`dict`)switch(t){case`count`:return{kind:`number`,value:e.value.size};case`contains`:return{kind:`boolean`,value:e.value.has(a.str(n[0]))};case`keys`:return{kind:`list`,value:[...e.value.keys()]};case`values`:return{kind:`list`,value:[...e.value.values()]};default:return{kind:`string`,value:``}}let o=P(e);switch(t){case`failed`:return{kind:`boolean`,value:ce(i)};case`size`:return{kind:`number`,value:o.length};case`uppercase`:return{kind:`string`,value:o.toUpperCase()};case`lowercase`:return{kind:`string`,value:o.toLowerCase()};case`capitalize`:return{kind:`string`,value:o.length===0?``:o[0].toUpperCase()+o.slice(1)};case`trim`:return{kind:`string`,value:o.trim()};case`wordCount`:{let e=o.trim();return{kind:`number`,value:e===``?0:e.split(/\s+/).length}}case`contains`:{let e=a.str(n[0]);try{return{kind:`boolean`,value:new RegExp(e).test(o)}}catch{return{kind:`boolean`,value:o.includes(e)}}}case`icontains`:{let e=a.str(n[0]);try{return{kind:`boolean`,value:new RegExp(e,`i`).test(o)}}catch{return{kind:`boolean`,value:o.toLowerCase().includes(e.toLowerCase())}}}case`beginsWith`:return{kind:`boolean`,value:o.startsWith(a.str(n[0]))};case`endsWith`:return{kind:`boolean`,value:o.endsWith(a.str(n[0]))};case`split`:return{kind:`list`,value:o.split(a.str(n[0]))};case`substr`:{let e=o.length,t=a.num(n[0]);if(t<0&&(t=e+t),t<0&&(t=0),t>e&&(t=e),n.length>=2){let r=a.num(n[1]);return r<0&&(r=e-t+r),r+t>e&&(r=e-t),r<0&&(r=0),{kind:`string`,value:o.slice(t,t+r)}}return{kind:`string`,value:o.slice(t)}}case`indexOf`:return{kind:`number`,value:o.indexOf(a.str(n[0]))};case`at`:{let e=a.num(n[0]),t=o.length,r=e<0?t+e:e;return r<0||r>=t?{kind:`string`,value:``}:{kind:`string`,value:o[r]}}case`replace`:{let e=a.str(n[0]),t=a.str(n[1]);try{return{kind:`string`,value:o.replace(new RegExp(e,`g`),t)}}catch{return{kind:`string`,value:``}}}case`replaceAll`:{let e=a.str(n[0]),t=a.str(n[1]),r=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{kind:`string`,value:o.replace(new RegExp(r,`g`),t)}}case`format`:return{kind:`string`,value:Ie(o,a.eval(n[0]))};case`skipWhitespace`:{let e=o.search(/\S/);return{kind:`string`,value:e===-1?``:o.slice(e)}}case`skipLine`:{if(o.length===0)return i&&j(i),{kind:`string`,value:``};let e=o.indexOf(`
3
3
  `);return{kind:`string`,value:e===-1?``:o.slice(e+1)}}case`skip`:{let e=Math.round(a.num(n[0]));return e>o.length?(i&&j(i),{kind:`string`,value:``}):{kind:`string`,value:o.slice(e)}}case`skipTo`:{let e=a.str(n[0]),t=o.indexOf(e);return t===-1?(i&&j(i),{kind:`string`,value:``}):{kind:`string`,value:o.slice(t+e.length)}}case`skipToNumber`:{let e=o.match(/[0-9]/);if(!e||e.index===void 0)return i&&j(i),{kind:`string`,value:``};let t=e.index;return t>0&&(o[t-1]===`-`||o[t-1]===`+`)&&t--,{kind:`string`,value:o.slice(t)}}case`expect`:{let e=a.str(n[0]);return o.startsWith(e)?{kind:`string`,value:o.slice(e.length)}:(i&&j(i),{kind:`string`,value:``})}case`expectWhitespace`:{if(o.length===0||!/^\s/.test(o))return i&&j(i),{kind:`string`,value:``};let e=o.search(/\S/);return{kind:`string`,value:e===-1?``:o.slice(e)}}case`expectNumber`:{let e=o.match(/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/);return e?{kind:`string`,value:o.slice(e[0].length)}:(i&&j(i),{kind:`string`,value:``})}case`expectWord`:{if(o.length===0||/^[\s\d\p{P}]/u.test(o))return i&&j(i),{kind:`string`,value:``};let e=o.match(/[\s\d\p{P}]/u)?.index??o.length;return{kind:`string`,value:o.slice(e)}}case`captureRest`:return B(z(n[0]),o,r,i),{kind:`string`,value:``};case`captureLine`:{if(o.length===0)return i&&j(i),{kind:`string`,value:``};let e=o.indexOf(`
4
- `),t=z(n[0]);return e===-1?(B(t,o,r,i),{kind:`string`,value:``}):(B(t,o.slice(0,e),r,i),{kind:`string`,value:o.slice(e+1)})}case`captureWord`:{if(o.length===0||/^[\s\d\p{P}]/u.test(o))return i&&j(i),{kind:`string`,value:``};let e=o.match(/[\s\d\p{P}]/u)?.index??o.length;return B(z(n[0]),o.slice(0,e),r,i),{kind:`string`,value:o.slice(e)}}case`captureNumber`:{let e=o.match(/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/);return e?(B(z(n[0]),e[0],r,i),{kind:`string`,value:o.slice(e[0].length)}):(i&&j(i),{kind:`string`,value:``})}case`captureToken`:{if(o.length===0)return i&&j(i),{kind:`string`,value:``};let e=o.match(/\s/)?.index??o.length;return B(z(n[0]),o.slice(0,e),r,i),{kind:`string`,value:o.slice(e)}}case`captureTo`:{let e=a.str(n[0]),t=z(n[1]),s=-1;for(let t=0;t<o.length;t++)if(e.includes(o[t])){s=t;break}return s===-1?(B(t,o,r,i),{kind:`string`,value:``}):(B(t,o.slice(0,s),r,i),{kind:`string`,value:o.slice(s+1)})}default:return{kind:`string`,value:``}}}function z(e){return e.kind===`attrRef`||e.kind===`ident`?e.name:``}function B(e,t,n,r){r?.has(e)?r.set(e,t):n&&n.attributes.set(e,t)}function Fe(e){if(e<=0)return``;let t=[1e3,900,500,400,100,90,50,40,10,9,5,4,1],n=[`M`,`CM`,`D`,`CD`,`C`,`XC`,`L`,`XL`,`X`,`IX`,`V`,`IV`,`I`],r=``;for(let i=0;i<t.length;i++)for(;e>=t[i];)r+=n[i],e-=t[i];return r}function Ie(e,t){return e.replace(/%(\.\d+)?([dfs])/g,(e,n,r)=>{switch(r){case`d`:return String(Math.trunc(F(t)));case`f`:{let e=F(t);if(n){let t=parseInt(n.slice(1),10);return e.toFixed(t)}return String(e)}case`s`:return P(t);default:return e}})}var Le=class extends a{resolve(e,t){let n=(e.attributes.get(`DisplayExpression`)??``).trim();if(!n)return e.get(`Name`);try{return P(L(ie(n),e))}catch{return e.get(`Name`)}}};S.DisplayName=Le;var Re=class{constructor(e=null,t=new Map,n=[],r=new T([]),i=new Map,a=new Map){this.root=e,this.links=n,this.colors=r,this.linkTypes=i,this.preferences=a,this.attributes=this.initSystemAttributes();for(let[e,n]of t)this.attributes.set(e,n)}initSystemAttributes(){let e=new Map,t=(t,n,r=a)=>e.set(t,new r({name:t,parent:``,type:n,editable:!1,visibleInEditor:!0,canInherit:!1,default:``,lines:1}));t(`Name`,i.String),t(`AgentQuery`,i.Action),t(`AgentAction`,i.Action),t(`IsAgent`,i.Boolean),t(`DisplayExpression`,i.Action),t(`DisplayName`,i.String,Le);for(let[e,n]of Object.entries(S))t(e,i.String,n);return e}getAttribute(e){return this.attributes.get(e)}findNoteById(e,t=this.root){return t?t.id===e?t:this.findNoteById(e,t.son)??this.findNoteById(e,t.brother):null}findNoteByName(e,t=this.root?.son??null){return t?t.name===e?t:this.findNoteByName(e,t.son)??this.findNoteByName(e,t.brother):null}findNote(e){return e.startsWith(`/`)?this.findNoteByPath(e)??this.findNoteByName(e):this.findNoteByName(e)}findNoteByPath(e){let t=e.replace(/^\//,``).split(`/`).filter(Boolean);if(t.length===0)return null;let n=this.root?.son??null,r=null;for(let e of t){r=null;let t=n;for(;t;){if(t.name===e){r=t;break}t=t.brother}if(!r)return null;n=r.son}return r}};function ze(e){let t=e.trim();return t===``?{kind:`always`}:t.startsWith(`guard(`)&&t.endsWith(`)`)?new He(t.slice(6,-1)).parseExpr():t.startsWith(`unvisited`)||t.startsWith(`visited`)?Be(t):{kind:`always`}}function Be(e){let t=e.indexOf(`(`),n,r;if(t===-1)n=e,r=null;else{if(!e.endsWith(`)`))return{kind:`always`};n=e.slice(0,t).trim(),r=e.slice(t+1,-1).trim()}if(n!==`unvisited`&&n!==`visited`)return{kind:`always`};let i;return i=!r||r===`destination`?{kind:`visited-dest`}:r.startsWith(`"`)&&r.endsWith(`"`)?{kind:`visited`,name:r.slice(1,-1)}:{kind:`visited`,name:r.startsWith(`/`)?r.slice(1):r},n===`visited`?i:{kind:`not`,expr:i}}var Ve=new Set([...`&|~()"`]),He=class{constructor(e){this.s=e,this.pos=0}parseExpr(){let e=this.parseTerm();for(;this.skip(),!(this.pos>=this.s.length||this.s[this.pos]!==`|`);)this.pos++,e={kind:`or`,left:e,right:this.parseTerm()};return e}parseTerm(){let e=this.parseFactor();for(;this.skip(),!(this.pos>=this.s.length||this.s[this.pos]!==`&`);)this.pos++,e={kind:`and`,left:e,right:this.parseFactor()};return e}parseFactor(){return this.skip(),this.s[this.pos]===`~`?(this.pos++,{kind:`not`,expr:this.parseFactor()}):this.parsePrimary()}parsePrimary(){this.skip();let e=this.s[this.pos];if(e===`(`){this.pos++;let e=this.parseExpr();return this.skip(),this.s[this.pos]===`)`&&this.pos++,e}return e===`?`?(this.pos++,{kind:`random`}):e===`*`?(this.pos++,{kind:`always`}):e===`"`?this.parseQuoted():this.parseBareWord()}parseQuoted(){this.pos++;let e=this.pos;for(;this.pos<this.s.length&&this.s[this.pos]!==`"`;)this.pos++;let t=this.s.slice(e,this.pos);return this.s[this.pos]===`"`&&this.pos++,{kind:`visited`,name:t}}parseBareWord(){let e=this.pos;for(;this.pos<this.s.length&&!Ve.has(this.s[this.pos]);)this.pos++;let t=this.s.slice(e,this.pos).trim();return t?{kind:`word`,name:t}:{kind:`always`}}skip(){for(;this.pos<this.s.length&&(this.s[this.pos]===` `||this.s[this.pos]===` `);)this.pos++}};function Ue(e,t,n,r=null){let i=e=>[...n].some(t=>t.name===e),a=e=>Ue(e,t,n,r);switch(e.kind){case`always`:return!0;case`random`:return Math.random()<.5;case`visited`:return i(e.name);case`word`:return r===`\0wildcard`||e.name===r;case`visited-dest`:return i(t);case`not`:return!a(e.expr);case`and`:return a(e.left)&&a(e.right);case`or`:return a(e.left)||a(e.right)}}var We=class{constructor(e,t,n,r,i,a,o,s){this.src=e,this.dest=t,this.name=n,this.srcSpan=r,this.destSpan=i,this.guard=a,this.url=o,this.title=s}destNote(){return this.dest}destName(){return this.dest?.name??``}isPrototype(){return this.name===`prototype`}isUrlLink(){return this.url!==``}guardSatisfied(e,t){return this.dest?Ue(ze(this.guard),this.dest.name,t,e):!1}};function Ge(e){return new DOMParser().parseFromString(e,`text/xml`)}function Ke(e,t){for(let n of e.children)if(n.tagName===t)return n;return null}function qe(e,t,n,r){for(let i of e.children)if(i.tagName===t&&i.getAttribute(n)===r)return i;return null}function Je(e){return qe(e,`attribute`,`name`,`Name`)?.textContent??``}function Ye(e){let t=new Map;for(let n of e.children)if(n.tagName===`attribute`){let e=n.getAttribute(`name`),r=n.textContent??``;e&&r!==`normal`&&t.set(e,r)}let n=e.getAttribute(`proto`);return n&&t.set(`Prototype`,n),t}function Xe(e){let t=atob(e.replace(/\s/g,``)),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);let r=[],i=n.length,a=0;for(;a<i-12;)if(n[a]===137&&n[a+1]===80&&n[a+2]===78&&n[a+3]===71&&n[a+4]===13&&n[a+5]===10&&n[a+6]===26&&n[a+7]===10){let e=a,t=a+8;for(;t<=i-12;){if(n[t]===0&&n[t+1]===0&&n[t+2]===0&&n[t+3]===0&&n[t+4]===73&&n[t+5]===69&&n[t+6]===78&&n[t+7]===68&&n[t+8]===174&&n[t+9]===66&&n[t+10]===96&&n[t+11]===130){let i=t+12,o=``;for(let t=e;t<i;t++)o+=String.fromCharCode(n[t]);r.push(btoa(o)),a=i;break}t++}if(t>i-12)break}else a++;return r}function Ze(e,t){if(!e.includes(`tbx-picture:`))return e;let n=Xe(t);return e.replace(/src="tbx-picture:(\d+)"/g,(e,t)=>{let r=parseInt(t,10);return r<n.length?`src="data:image/png;base64,${n[r]}"`:e})}function Qe(e){let t=Ke(e,`rtfd`),n=Ke(e,`html`)?.textContent??``;n&&t?.textContent&&(n=Ze(n,t.textContent));let r=Ke(e,`text`);return r?.textContent?{text:r.textContent,isRichText:!1,html:n}:t?{text:``,isRichText:!0,html:n}:{text:``,isRichText:!1,html:n}}function $e(e){return parseInt(e.getAttribute(`ID`)??`0`,10)}function et(e,n,r){let{text:i,isRichText:a,html:o}=Qe(e),s=new t($e(e),Je(e),i,a,Ye(e),n,null,null,null,r,!0);return s.html=o,s}function tt(e,n,i){let{text:a,isRichText:o,html:s}=Qe(e),c=Ye(e),l=c.get(`IsAgent`)===`true`?new r($e(e),Je(e),a,o,c,n,null,null,null,i):new t($e(e),Je(e),a,o,c,n,null,null,null,i);l.html=s;let u=Array.from(e.children).filter(e=>e.tagName===`item`||e.tagName===`adornment`),d=null;for(let e of u){let t=e.tagName===`adornment`?et(e,l,i):tt(e,l,i);d===null?l.son=t:(d.brother=t,t.elderBrother=d),d=t}return l}function nt(e,t=new Re){let n=e.querySelector(`item`);return n?tt(n,null,t):null}function rt(e){let t=new Map;for(let n of e.querySelectorAll(`attrib`)){let e=n.getAttribute(`Name`);if(!e)continue;let r=parseInt(n.getAttribute(`type`)??`0`,10),o=S[e]??a;t.set(e,new o({name:e,parent:n.getAttribute(`parent`)??``,type:r in i?r:i.String,editable:n.getAttribute(`editable`)!==`0`,visibleInEditor:n.getAttribute(`visibleInEditor`)!==`0`,canInherit:n.getAttribute(`canInherit`)!==`0`,default:n.getAttribute(`default`)??``,lines:Math.max(1,parseInt(n.getAttribute(`lines`)??`1`,10)||1)}))}return t}function it(e,t){let n=parseInt(e??`-1`,10);return n<0?null:{start:n,length:parseInt(t??`0`,10)}}function at(e){let t=[];for(let n of e.querySelectorAll(`colors > color`)){let e=n.getAttribute(`name`),r=n.getAttribute(`color`);e&&r&&t.push([e,r])}return new T(t)}function ot(e){let t=new Map;for(let n of e.querySelectorAll(`linkTypes > linkType`)){let e=n.getAttribute(`name`);e&&t.set(e,{name:e,visible:n.getAttribute(`visible`)!==`0`,color:n.getAttribute(`colorString`)||`black`,style:parseInt(n.getAttribute(`style`)??`0`,10),arrowType:parseInt(n.getAttribute(`arrowType`)??`0`,10),dotted:!!(parseInt(n.getAttribute(`style`)??`0`,10)&8),dashed:!!(parseInt(n.getAttribute(`style`)??`0`,10)&16)})}return t}function st(e){let t=new Map,n=e.querySelector(`preferences`);if(n)for(let e of n.children){let n=e.textContent;n!==null&&t.set(e.tagName,n.trim())}return t}function ct(e){let t=[];function r(e){for(;e;)e.attributes.has(`Alias`)&&t.push(e),r(e.son),e=e.brother}e.root&&r(e.root.son);for(let r of t){let t=parseInt(r.attributes.get(`Alias`)??`0`,10);if(!t)continue;let i=e.findNoteById(t);if(!i)continue;let a=new Map(r.attributes);a.delete(`Alias`);let o=new n(i,r.id,a,r.father,r.brother,r.elderBrother,e);r.father?.son===r&&(r.father.son=o),r.elderBrother&&(r.elderBrother.brother=o),r.brother&&(r.brother.elderBrother=o),i.aliases.push(o)}}function lt(e){let t=new Re(null,rt(e),[],at(e),ot(e),st(e));t.root=nt(e,t),ct(t);for(let n of e.querySelectorAll(`links > link`)){let e=t.findNoteById(parseInt(n.getAttribute(`sourceid`)??`0`,10));if(!e)continue;let r=t.findNoteById(parseInt(n.getAttribute(`destid`)??`0`,10));t.links.push(new We(e,r,n.getAttribute(`name`)??``,it(n.getAttribute(`sstart`),n.getAttribute(`slen`)),it(n.getAttribute(`dstart`),n.getAttribute(`dlen`)),n.getAttribute(`guard`)??``,n.getAttribute(`URL`)??``,n.getAttribute(`title`)??``))}return t}var ut=class{constructor(e){this.onShow=e,this.currentNote=null,this.history=[],this.visitedNotes=new Set,this.clickedWord=null}show(e){this.currentNote=e,this.visitedNotes.add(e),this.onShow(e)}navigateTo(e){this.currentNote!==null&&this.history.push(this.currentNote),this.show(e)}goBack(){let e=this.history.pop();e&&this.show(e)}reset(){this.currentNote=null,this.history=[],this.visitedNotes.clear(),this.clickedWord=null}recordWord(e){this.clickedWord=e.replace(/ /g,` `),this.followGuardLink()}enterKey(){this.clickedWord=``,this.followGuardLink()}followGuardLink(){if(this.currentNote){for(let e of this.currentNote.outboundPlainLinks())if(e.guardSatisfied(this.clickedWord,this.visitedNotes)){this.navigateTo(e.destNote());return}}}truncateVisitedAt(e){let t=[...this.visitedNotes],n=t.indexOf(e);if(n!==-1)for(let e=n+1;e<t.length;e++)this.visitedNotes.delete(t[e]);this.history=this.history.filter(e=>this.visitedNotes.has(e))}},dt=class{constructor(e){this.currentNote=null,this.viewRoot=null,this.container=e}get el(){return this.container}willRender(e){}scrollToSelected(){}onArrow(e){return!1}getViewRoot(){return this.viewRoot}hoistTo(e,t){this.viewRoot=e,this.render(t)}};function V(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function ft(e){return e.ht.links.filter(t=>t.src===e&&t.srcSpan!==null).flatMap(e=>{let t={start:e.srcSpan.start,length:e.srcSpan.length};if(e.url)return[{...t,type:`url`,href:e.url,title:e.title}];let n=e.dest?.path??``;return n?[{...t,type:`note`,destPath:n}]:[]})}function pt(e,t){let n=0;for(;n<=e.length-t.length;)if(e[n]===`<`){let t=e.indexOf(`>`,n);n=t===-1?e.length:t+1}else if(e.startsWith(t,n))return n;else n++;return-1}function mt(e,t,n){if(!n.length)return e;let r=[...n].sort((e,t)=>t.start-e.start);for(let n of r){let r=t.slice(n.start,n.start+n.length).replace(/<[^>]+>/g,``);if(!r)continue;let i=V(r),a=pt(e,i);if(a===-1)continue;let o;o=n.type===`url`?`<a href="${V(n.href)}" target="_blank" class="tbx-url"${n.title?` title="${V(n.title)}"`:``}>`:`<a data-dest="${V(n.destPath)}">`,e=e.slice(0,a)+o+i+`</a>`+e.slice(a+i.length)}return e}function ht(e,t){let n=[...t].sort((e,t)=>e.start-t.start),r=[[]],i=0;function a(e,t){e.split(`
4
+ `),t=z(n[0]);return e===-1?(B(t,o,r,i),{kind:`string`,value:``}):(B(t,o.slice(0,e),r,i),{kind:`string`,value:o.slice(e+1)})}case`captureWord`:{if(o.length===0||/^[\s\d\p{P}]/u.test(o))return i&&j(i),{kind:`string`,value:``};let e=o.match(/[\s\d\p{P}]/u)?.index??o.length;return B(z(n[0]),o.slice(0,e),r,i),{kind:`string`,value:o.slice(e)}}case`captureNumber`:{let e=o.match(/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/);return e?(B(z(n[0]),e[0],r,i),{kind:`string`,value:o.slice(e[0].length)}):(i&&j(i),{kind:`string`,value:``})}case`captureToken`:{if(o.length===0)return i&&j(i),{kind:`string`,value:``};let e=o.match(/\s/)?.index??o.length;return B(z(n[0]),o.slice(0,e),r,i),{kind:`string`,value:o.slice(e)}}case`captureTo`:{let e=a.str(n[0]),t=z(n[1]),s=-1;for(let t=0;t<o.length;t++)if(e.includes(o[t])){s=t;break}return s===-1?(B(t,o,r,i),{kind:`string`,value:``}):(B(t,o.slice(0,s),r,i),{kind:`string`,value:o.slice(s+1)})}default:return{kind:`string`,value:``}}}function z(e){return e.kind===`attrRef`||e.kind===`ident`?e.name:``}function B(e,t,n,r){r?.has(e)?r.set(e,t):n&&n.attributes.set(e,t)}function Fe(e){if(e<=0)return``;let t=[1e3,900,500,400,100,90,50,40,10,9,5,4,1],n=[`M`,`CM`,`D`,`CD`,`C`,`XC`,`L`,`XL`,`X`,`IX`,`V`,`IV`,`I`],r=``;for(let i=0;i<t.length;i++)for(;e>=t[i];)r+=n[i],e-=t[i];return r}function Ie(e,t){return e.replace(/%(\.\d+)?([dfs])/g,(e,n,r)=>{switch(r){case`d`:return String(Math.trunc(F(t)));case`f`:{let e=F(t);if(n){let t=parseInt(n.slice(1),10);return e.toFixed(t)}return String(e)}case`s`:return P(t);default:return e}})}var Le=class extends a{resolve(e,t){let n=(e.attributes.get(`DisplayExpression`)??``).trim();if(!n)return e.get(`Name`);try{return P(L(ie(n),e))}catch{return e.get(`Name`)}}};S.DisplayName=Le;var Re=class{constructor(e=null,t=new Map,n=[],r=new T([]),i=new Map,a=new Map){this.root=e,this.links=n,this.colors=r,this.linkTypes=i,this.preferences=a,this.attributes=this.initSystemAttributes();for(let[e,n]of t)this.attributes.set(e,n)}initSystemAttributes(){let e=new Map,t=(t,n,r=a)=>e.set(t,new r({name:t,parent:``,type:n,editable:!1,visibleInEditor:!0,canInherit:!1,default:``,lines:1}));t(`Name`,i.String),t(`AgentQuery`,i.Action),t(`AgentAction`,i.Action),t(`IsAgent`,i.Boolean),t(`DisplayExpression`,i.Action),t(`DisplayName`,i.String,Le);for(let[e,n]of Object.entries(S))t(e,i.String,n);return e}getAttribute(e){return this.attributes.get(e)}findNoteById(e,t=this.root){return t?t.id===e?t:this.findNoteById(e,t.son)??this.findNoteById(e,t.brother):null}findNoteByName(e,t=this.root?.son??null){return t?t.name===e?t:this.findNoteByName(e,t.son)??this.findNoteByName(e,t.brother):null}findNote(e){return e.startsWith(`/`)?this.findNoteByPath(e)??this.findNoteByName(e):this.findNoteByName(e)}findNoteByPath(e){let t=e.replace(/^\//,``).split(`/`).filter(Boolean);if(t.length===0)return null;let n=this.root?.son??null,r=null;for(let e of t){r=null;let t=n;for(;t;){if(t.name===e){r=t;break}t=t.brother}if(!r)return null;n=r.son}return r}};function ze(e){let t=e.trim();return t===``?{kind:`always`}:t.startsWith(`guard(`)&&t.endsWith(`)`)?new He(t.slice(6,-1)).parseExpr():t.startsWith(`unvisited`)||t.startsWith(`visited`)?Be(t):{kind:`always`}}function Be(e){let t=e.indexOf(`(`),n,r;if(t===-1)n=e,r=null;else{if(!e.endsWith(`)`))return{kind:`always`};n=e.slice(0,t).trim(),r=e.slice(t+1,-1).trim()}if(n!==`unvisited`&&n!==`visited`)return{kind:`always`};let i;return i=!r||r===`destination`?{kind:`visited-dest`}:r.startsWith(`"`)&&r.endsWith(`"`)?{kind:`visited`,name:r.slice(1,-1)}:{kind:`visited`,name:r.startsWith(`/`)?r.slice(1):r},n===`visited`?i:{kind:`not`,expr:i}}var Ve=new Set([...`&|~()"`]),He=class{constructor(e){this.s=e,this.pos=0}parseExpr(){let e=this.parseTerm();for(;this.skip(),!(this.pos>=this.s.length||this.s[this.pos]!==`|`);)this.pos++,e={kind:`or`,left:e,right:this.parseTerm()};return e}parseTerm(){let e=this.parseFactor();for(;this.skip(),!(this.pos>=this.s.length||this.s[this.pos]!==`&`);)this.pos++,e={kind:`and`,left:e,right:this.parseFactor()};return e}parseFactor(){return this.skip(),this.s[this.pos]===`~`?(this.pos++,{kind:`not`,expr:this.parseFactor()}):this.parsePrimary()}parsePrimary(){this.skip();let e=this.s[this.pos];if(e===`(`){this.pos++;let e=this.parseExpr();return this.skip(),this.s[this.pos]===`)`&&this.pos++,e}return e===`?`?(this.pos++,{kind:`random`}):e===`*`?(this.pos++,{kind:`always`}):e===`"`?this.parseQuoted():this.parseBareWord()}parseQuoted(){this.pos++;let e=this.pos;for(;this.pos<this.s.length&&this.s[this.pos]!==`"`;)this.pos++;let t=this.s.slice(e,this.pos);return this.s[this.pos]===`"`&&this.pos++,{kind:`visited`,name:t}}parseBareWord(){let e=this.pos;for(;this.pos<this.s.length&&!Ve.has(this.s[this.pos]);)this.pos++;let t=this.s.slice(e,this.pos).trim();return t?{kind:`word`,name:t}:{kind:`always`}}skip(){for(;this.pos<this.s.length&&(this.s[this.pos]===` `||this.s[this.pos]===` `);)this.pos++}};function Ue(e,t,n,r=null){let i=e=>[...n].some(t=>t.name===e),a=e=>Ue(e,t,n,r);switch(e.kind){case`always`:return!0;case`random`:return Math.random()<.5;case`visited`:return i(e.name);case`word`:return r===`\0wildcard`||e.name===r;case`visited-dest`:return i(t);case`not`:return!a(e.expr);case`and`:return a(e.left)&&a(e.right);case`or`:return a(e.left)||a(e.right)}}var We=class{constructor(e,t,n,r,i,a,o,s){this.src=e,this.dest=t,this.name=n,this.srcSpan=r,this.destSpan=i,this.guard=a,this.url=o,this.title=s}destNote(){return this.dest}destName(){return this.dest?.name??``}isPrototype(){return this.name===`prototype`}isUrlLink(){return this.url!==``}guardSatisfied(e,t){return this.dest?Ue(ze(this.guard),this.dest.name,t,e):!1}};function Ge(e){return new DOMParser().parseFromString(e,`text/xml`)}function Ke(e,t){for(let n of e.children)if(n.tagName===t)return n;return null}function qe(e,t,n,r){for(let i of e.children)if(i.tagName===t&&i.getAttribute(n)===r)return i;return null}function Je(e){return qe(e,`attribute`,`name`,`Name`)?.textContent??``}function Ye(e){let t=new Map;for(let n of e.children)if(n.tagName===`attribute`){let e=n.getAttribute(`name`),r=n.textContent??``;e&&r!==`normal`&&t.set(e,r)}let n=e.getAttribute(`proto`);return n&&t.set(`Prototype`,n),t}function Xe(e){let t=atob(e.replace(/\s/g,``)),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);let r=[],i=n.length,a=0;for(;a<i-12;)if(n[a]===137&&n[a+1]===80&&n[a+2]===78&&n[a+3]===71&&n[a+4]===13&&n[a+5]===10&&n[a+6]===26&&n[a+7]===10){let e=a,t=a+8;for(;t<=i-12;){if(n[t]===0&&n[t+1]===0&&n[t+2]===0&&n[t+3]===0&&n[t+4]===73&&n[t+5]===69&&n[t+6]===78&&n[t+7]===68&&n[t+8]===174&&n[t+9]===66&&n[t+10]===96&&n[t+11]===130){let i=t+12,o=``;for(let t=e;t<i;t++)o+=String.fromCharCode(n[t]);r.push(btoa(o)),a=i;break}t++}if(t>i-12)break}else a++;return r}function Ze(e,t){if(!e.includes(`tbx-picture:`))return e;let n=Xe(t);return e.replace(/src="tbx-picture:(\d+)"/g,(e,t)=>{let r=parseInt(t,10);return r<n.length?`src="data:image/png;base64,${n[r]}"`:e})}function Qe(e){let t=Ke(e,`rtfd`),n=Ke(e,`html`)?.textContent??``;n&&t?.textContent&&(n=Ze(n,t.textContent));let r=Ke(e,`text`);return r?.textContent?{text:r.textContent,isRichText:!1,html:n}:t?{text:``,isRichText:!0,html:n}:{text:``,isRichText:!1,html:n}}function $e(e){return parseInt(e.getAttribute(`ID`)??`0`,10)}function et(e,n,r){let{text:i,isRichText:a,html:o}=Qe(e),s=new t($e(e),Je(e),i,a,Ye(e),n,null,null,null,r,!0);return s.html=o,s}function tt(e,n,i){let{text:a,isRichText:o,html:s}=Qe(e),c=Ye(e),l=c.get(`IsAgent`)===`true`?new r($e(e),Je(e),a,o,c,n,null,null,null,i):new t($e(e),Je(e),a,o,c,n,null,null,null,i);l.html=s;let u=Array.from(e.children).filter(e=>e.tagName===`item`||e.tagName===`adornment`),d=null;for(let e of u){let t=e.tagName===`adornment`?et(e,l,i):tt(e,l,i);d===null?l.son=t:(d.brother=t,t.elderBrother=d),d=t}return l}function nt(e,t=new Re){let n=e.querySelector(`item`);return n?tt(n,null,t):null}function rt(e){let t=new Map;for(let n of e.querySelectorAll(`attrib`)){let e=n.getAttribute(`Name`);if(!e)continue;let r=parseInt(n.getAttribute(`type`)??`0`,10),o=S[e]??a;t.set(e,new o({name:e,parent:n.getAttribute(`parent`)??``,type:r in i?r:i.String,editable:n.getAttribute(`editable`)!==`0`,visibleInEditor:n.getAttribute(`visibleInEditor`)!==`0`,canInherit:n.getAttribute(`canInherit`)!==`0`,default:n.getAttribute(`default`)??``,lines:Math.max(1,parseInt(n.getAttribute(`lines`)??`1`,10)||1)}))}return t}function it(e,t){let n=parseInt(e??`-1`,10);return n<0?null:{start:n,length:parseInt(t??`0`,10)}}function at(e){let t=[];for(let n of e.querySelectorAll(`colors > color`)){let e=n.getAttribute(`name`),r=n.getAttribute(`color`);e&&r&&t.push([e,r])}return new T(t)}function ot(e){let t=new Map;for(let n of e.querySelectorAll(`linkTypes > linkType`)){let e=n.getAttribute(`name`);e&&t.set(e,{name:e,visible:n.getAttribute(`visible`)!==`0`,color:n.getAttribute(`colorString`)||`black`,style:parseInt(n.getAttribute(`style`)??`0`,10),arrowType:parseInt(n.getAttribute(`arrowType`)??`0`,10),dotted:!!(parseInt(n.getAttribute(`style`)??`0`,10)&8),dashed:!!(parseInt(n.getAttribute(`style`)??`0`,10)&16)})}return t}function st(e){let t=new Map,n=e.querySelector(`preferences`);if(n)for(let e of n.children){let n=e.textContent;n!==null&&t.set(e.tagName,n.trim())}return t}function ct(e){let t=[];function r(e){for(;e;)e.attributes.has(`Alias`)&&t.push(e),r(e.son),e=e.brother}e.root&&r(e.root.son);for(let r of t){let t=parseInt(r.attributes.get(`Alias`)??`0`,10);if(!t)continue;let i=e.findNoteById(t);if(!i)continue;let a=new Map(r.attributes);a.delete(`Alias`);let o=new n(i,r.id,a,r.father,r.brother,r.elderBrother,e);r.father?.son===r&&(r.father.son=o),r.elderBrother&&(r.elderBrother.brother=o),r.brother&&(r.brother.elderBrother=o),i.aliases.push(o)}}function lt(e){let t=new Re(null,rt(e),[],at(e),ot(e),st(e));t.root=nt(e,t),ct(t);for(let n of e.querySelectorAll(`links > link`)){let e=t.findNoteById(parseInt(n.getAttribute(`sourceid`)??`0`,10));if(!e)continue;let r=t.findNoteById(parseInt(n.getAttribute(`destid`)??`0`,10));t.links.push(new We(e,r,n.getAttribute(`name`)??``,it(n.getAttribute(`sstart`),n.getAttribute(`slen`)),it(n.getAttribute(`dstart`),n.getAttribute(`dlen`)),n.getAttribute(`guard`)??``,n.getAttribute(`URL`)??``,n.getAttribute(`title`)??``))}return t}var ut=class{constructor(e){this.onShow=e,this.currentNote=null,this.history=[],this.visitedNotes=new Set,this.clickedWord=null}show(e){this.currentNote=e,this.visitedNotes.add(e),this.onShow(e)}navigateTo(e){this.currentNote!==null&&this.history.push(this.currentNote),this.show(e)}goBack(){let e=this.history.pop();e&&this.show(e)}reset(){this.currentNote=null,this.history=[],this.visitedNotes.clear(),this.clickedWord=null}recordWord(e){this.clickedWord=e.replace(/ /g,` `),this.followGuardLink()}enterKey(){this.clickedWord=``,this.followGuardLink()}followGuardLink(){if(this.currentNote){for(let e of this.currentNote.outboundPlainLinks())if(e.guardSatisfied(this.clickedWord,this.visitedNotes)){this.navigateTo(e.destNote());return}}}truncateVisitedAt(e){let t=[...this.visitedNotes],n=t.indexOf(e);if(n!==-1)for(let e=n+1;e<t.length;e++)this.visitedNotes.delete(t[e]);this.history=this.history.filter(e=>this.visitedNotes.has(e))}},dt=class{constructor(e){this.currentNote=null,this.viewRoot=null,this.container=e}get el(){return this.container}willRender(e){}suspend(){}scrollToSelected(){}onArrow(e){return!1}getViewRoot(){return this.viewRoot}hoistTo(e,t){this.viewRoot=e,this.render(t)}};function V(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function ft(e){return e.ht.links.filter(t=>t.src===e&&t.srcSpan!==null).flatMap(e=>{let t={start:e.srcSpan.start,length:e.srcSpan.length};if(e.url)return[{...t,type:`url`,href:e.url,title:e.title}];let n=e.dest?.path??``;return n?[{...t,type:`note`,destPath:n}]:[]})}function pt(e,t){let n=0;for(;n<=e.length-t.length;)if(e[n]===`<`){let t=e.indexOf(`>`,n);n=t===-1?e.length:t+1}else if(e.startsWith(t,n))return n;else n++;return-1}function mt(e,t,n){if(!n.length)return e;let r=[...n].sort((e,t)=>t.start-e.start);for(let n of r){let r=t.slice(n.start,n.start+n.length).replace(/<[^>]+>/g,``);if(!r)continue;let i=V(r),a=pt(e,i);if(a===-1)continue;let o;o=n.type===`url`?`<a href="${V(n.href)}" target="_blank" class="tbx-url"${n.title?` title="${V(n.title)}"`:``}>`:`<a data-dest="${V(n.destPath)}">`,e=e.slice(0,a)+o+i+`</a>`+e.slice(a+i.length)}return e}function ht(e,t){let n=[...t].sort((e,t)=>e.start-t.start),r=[[]],i=0;function a(e,t){e.split(`
5
5
  `).forEach((e,n)=>{if(n>0&&r.push([]),!e)return;let i=V(e).split(`\u2028`).join(`<br>`);r[r.length-1].push(t?t(i):i)})}for(let t of n){t.start>i&&a(e.slice(i,t.start));let n=e.slice(t.start,t.start+t.length);if(t.type===`note`){let e=V(t.destPath);a(n,t=>`<a data-dest="${e}">${t}</a>`)}else{let e=V(t.href),r=t.title?` title="${V(t.title)}"`:``;a(n,t=>`<a href="${e}" target="_blank" class="tbx-url"${r}>${t}</a>`)}i=t.start+t.length}return a(e.slice(i)),r.map(e=>e.join(``)).filter(e=>e!==``).map(e=>`<p>${e}</p>`).join(``)}var gt=`
6
6
  #tbx-content { flex: 1; min-height: 8em; padding: 24px 24px 0; overflow-y: auto; }
7
7
  #tbx-content * { line-height: 1.4 !important; }
@@ -71,7 +71,7 @@ var TbxDocument=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`
71
71
  .tbx-hyp-node { cursor: pointer; }
72
72
  .tbx-hyp-node:hover rect { filter: brightness(1.1); }
73
73
  .tbx-hyp-node.tbx-hyp-current rect { stroke: var(--tbx-accent, #2266cc); stroke-width: 3; animation: tbx-svg-pulse 500ms ease-in-out infinite alternate; }
74
- `,Dn=class e extends dt{static{this.BOX_SIZES=[[96,32],[82,28],[70,24],[60,20],[52,18]]}static boxSize(t){return e.BOX_SIZES[Math.min(t,e.BOX_SIZES.length-1)]}constructor(e,t){let n=document.createElement(`div`);n.id=`tbx-hyp-pane`,n.style.cssText=`display:none; overflow:auto;`,e.appendChild(n),super(n),this.focusNote=null,this.selectedNote=null,this.viewCenter=zt,this.dragPx=0,this.layout=null,this.animFrameId=null,this.sim=null,this.clickTimer=null,this.pendingNote=null,this.onNavigate=t,this.container.addEventListener(`click`,e=>this.handleClick(e)),this.container.addEventListener(`mousedown`,e=>this.handleMouseDown(e))}getViewRoot(){return null}hoistTo(e,t){}render(e){if(this.currentNote=e,!e){this.sim?.stop(),this.sim=null,this.cancelPending(),this.container.innerHTML=``;return}if(e===this.selectedNote&&(this.animFrameId!==null||this.clickTimer!==null))return;this.cancelPending();let t=cn(this.layout,e);if(t){this.selectedNote=e,this.doRender(),e!==this.focusNote&&this.animateTo(this.viewCenter,t.pos,450,()=>this.refocus(e));return}this.selectedNote=e,this.focusNote=e,this.viewCenter=zt,this.layout=sn(e),this.startSim(),this.doRender()}isDoubleClickOn(e){return this.clickTimer!==null&&this.pendingNote===e}clearClickTimer(){this.clickTimer!==null&&(clearTimeout(this.clickTimer),this.clickTimer=null,this.pendingNote=null)}cancelPending(){this.cancelAnim(),this.clearClickTimer()}refocus(e){this.cancelAnim();let t=cn(this.layout,e),n=t?Jt(t.pos,this.viewCenter):zt;this.selectedNote=e,this.focusNote=e,this.layout=sn(e),this.startSim();let r=Kt(n,-1);this.viewCenter=r,this.animateTo(r,zt,450)}cancelAnim(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}startSim(){this.sim?.stop(),this.layout&&(this.sim=new yn(this.layout,()=>this.doRender()),this.sim.start())}animateTo(e,t,n,r){let i=performance.now(),a=o=>{let s=Math.min((o-i)/n,1),c=s*s*(3-2*s);this.viewCenter=[e[0]+(t[0]-e[0])*c,e[1]+(t[1]-e[1])*c],this.doRender(),s<1?this.animFrameId=requestAnimationFrame(a):(this.viewCenter=t,this.animFrameId=null,r?.())};this.animFrameId=requestAnimationFrame(a)}toSvgV(e){let t=Jt(e,this.viewCenter);return[Cn+t[0]*Sn,wn+t[1]*Sn]}clientToDisk(e,t){let n=this.container.querySelector(`svg`)?.getBoundingClientRect();if(!n)return null;let r=n.width/2,i=n.height/2,a=(e-n.left-r)/(r*xn),o=(t-n.top-i)/(i*xn);return a*a+o*o>=.999?null:[a,o]}doRender(){if(!this.layout||!this.currentNote)return;let e=`tbx-hyp-clip`,t=`<defs><clipPath id="${e}"><circle cx="${Cn}" cy="${wn}" r="${Sn}"/></clipPath></defs>`,n=`<circle cx="${Cn}" cy="${wn}" r="${Sn}" fill="#f5f5f0" stroke="#ccc" stroke-width="1"/>`;this.container.innerHTML=`<svg class="tbx-hyp-svg" width="100%" viewBox="0 0 ${bn} ${bn}">`+t+n+`<g clip-path="url(#${e})">${this.renderEdges()}</g>`+this.renderNodes()+`</svg>`}renderEdges(){let e=e=>this.toSvgV(e);return un(this.layout).map(([t,n])=>`<path d="${nn(t.pos,n.pos,e)}" stroke="#aaa" stroke-width="0.8" fill="none"/>`).join(``)}renderNodes(){return ln(this.layout).map(e=>this.renderNode(e)).join(``)}renderNode(t){let[n,r]=e.boxSize(t.depth),[i,a]=this.toSvgV(t.pos),o=i-n/2,s=a-r/2,c=t.note===this.focusNote,l=t.note===this.selectedNote,u=t.note===this.currentNote,d=c?`#c8c8b8`:l?`#d8eeff`:`#e8e8e0`,f=l?`#2266cc`:`#888`,p=l?2:1,m=u?`tbx-hyp-node tbx-hyp-current`:`tbx-hyp-node`,h=Math.max(8,Math.min(13,r*.45));return`<g class="${m}" data-id="${t.note.id}"><rect x="${o.toFixed(1)}" y="${s.toFixed(1)}" width="${n.toFixed(1)}" height="${r.toFixed(1)}" rx="3" fill="${d}" stroke="${f}" stroke-width="${p}"/><foreignObject x="${(o+1).toFixed(1)}" y="${s.toFixed(1)}" width="${(n-2).toFixed(1)}" height="${r.toFixed(1)}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:${h}px;font-family:Helvetica,Arial,sans-serif;padding:0 2px;box-sizing:border-box;display:flex;align-items:center;">`+V(t.note.get(`DisplayName`))+`</div></foreignObject></g>`}handleMouseDown(e){if(this.dragPx=0,this.sim?.stop(),document.addEventListener(`mouseup`,()=>this.sim?.start(),{once:!0}),e.target.closest(`[data-id]`))return;let t=this.clientToDisk(e.clientX,e.clientY);if(!t)return;this.cancelPending(),e.preventDefault();let n=this.viewCenter,r=this.container.querySelector(`svg`);r?.classList.add(`tbx-hyp-dragging`),this.dragPx=0;let i=e=>{let r=this.clientToDisk(e.clientX,e.clientY);r&&(this.dragPx+=Math.hypot(e.movementX,e.movementY),this.viewCenter=en(t,r,n),this.doRender())},a=()=>{r?.classList.remove(`tbx-hyp-dragging`),document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a)};document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}onArrow(e){if(!this.layout||!this.selectedNote)return!1;let t={ArrowRight:[1,0],ArrowLeft:[-1,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[e.key];if(!t)return!1;let[n,r]=t,i=cn(this.layout,this.selectedNote);if(!i)return!1;let[a,o]=this.toSvgV(i.pos),s=this.selectedNote,c=new Set,l=[];for(let e of s.ht.links){if(e.isPrototype()||e.isUrlLink())continue;let t=e.src===s&&e.dest!==s?e.dest:e.dest===s&&e.src!==s?e.src:null;if(!t||c.has(t.id))continue;c.add(t.id);let n=cn(this.layout,t);n&&l.push(n)}let u=null,d=-1/0;for(let e of l){let[t,i]=this.toSvgV(e.pos),s=t-a,c=i-o,l=s*n+c*r;if(l<=0)continue;let f=l/(s*s+c*c);f>d&&(d=f,u=e.note)}return u?(this.onNavigate(u),!0):!1}handleClick(e){if(this.dragPx>5)return;let t=e.target.closest(`[data-id]`);if(!t)return;let n=parseInt(t.getAttribute(`data-id`),10),r=this.layout?.byId.get(n)?.note;if(r){if(this.isDoubleClickOn(r)){this.clearClickTimer(),this.refocus(r);return}this.cancelPending(),this.selectedNote=r,this.pendingNote=r,this.layout&&dn(this.layout,r),this.sim?.wakeUp(),this.doRender(),this.clickTimer=setTimeout(()=>{this.clickTimer=null,this.pendingNote=null;let e=this.layout?.byId.get(n);e&&this.animateTo(this.viewCenter,e.pos,450)},Tn),this.onNavigate(r)}}};function On(e){let t=new Map;kn(e,t);let n=t.get(e.id);return n.weight=1,An(e,t),t}function kn(e,t){let n=e.children.filter(e=>!e.isAdornment);if(n.length===0)return t.set(e.id,{rawWeight:1,weight:1}),1;let r=0;for(let e of n)r+=kn(e,t);return t.set(e.id,{rawWeight:r,weight:1}),r}function An(e,t){let n=e.children.filter(e=>!e.isAdornment);if(n.length===0)return;let r=n.reduce((e,n)=>e+t.get(n.id).rawWeight,0),i=r===0?1:r;for(let e of n)t.get(e.id).weight=t.get(e.id).rawWeight/i,An(e,t)}function jn(e){return Math.floor((e-1)/2)}function Mn(e){return e.w>=e.h}function K(e,t){return t.get(e.id)?.weight??0}function Nn(e,t,n){let r=e.reduce((e,t)=>e+K(t,n),0);return t&&(r+=K(t,n)),r}function Pn(e,t,n,r){let i=K(e,r)+K(t,r),a=i===0?.5:K(e,r)/i;return Mn(n)?{pivotrect:{x:n.x,y:n.y,w:n.w*a,h:n.h},otherrect:{x:n.x+n.w*a,y:n.y,w:n.w*(1-a),h:n.h}}:{pivotrect:{x:n.x,y:n.y,w:n.w,h:n.h*a},otherrect:{x:n.x,y:n.y+n.h*a,w:n.w,h:n.h*(1-a)}}}function Fn(e,t,n,r,i){let a=K(t,i),o=K(e,i),s=K(n,i),c=a+o+s||1,l=a/c,u=o/c;return r.h<r.w/1.6?{lrect:{x:r.x,y:r.y,w:r.w*l,h:r.h},pivotrect:{x:r.x+r.w*l,y:r.y,w:r.w*u,h:r.h},rrect:{x:r.x+r.w*(l+u),y:r.y,w:r.w*(1-l-u),h:r.h}}:{lrect:{x:r.x,y:r.y,w:r.w,h:r.h*l},pivotrect:{x:r.x,y:r.y+r.h*l,w:r.w,h:r.h*u},rrect:{x:r.x,y:r.y+r.h*(l+u),w:r.w,h:r.h*(1-l-u)}}}function In(e,t,n,r,i,a){let o=Nn(t,null,a),s=Nn(n,e,a),c=Nn(r,null,a),l=o+s+c||1,u=o/l,d=s/l,f=Mn(i),p,m,h;f?(p={x:i.x,y:i.y,w:i.w*u,h:i.h},m={x:i.x+i.w*u,y:i.y,w:i.w*d,h:i.h},h={x:i.x+i.w*(u+d),y:i.y,w:i.w*(1-u-d),h:i.h}):(p={x:i.x,y:i.y,w:i.w,h:i.h*u},m={x:i.x,y:i.y+i.h*u,w:i.w,h:i.h*d},h={x:i.x,y:i.y+i.h*(u+d),w:i.w,h:i.h*(1-u-d)});let g=s===0?1:K(e,a)/s,_;return f?(_={...m,h:m.h*g},m={...m,y:m.y+m.h*g,h:m.h*(1-g)}):(_={...m,w:m.w*g},m={...m,x:m.x+m.w*g,w:m.w*(1-g)}),{lrect:p,mrect:m,rrect:h,pivotrect:_}}function Ln(e){if(e.w===0)return 0;let t=e.h/e.w-.6;return t*t}function Rn(e,t,n,r,i,a,o){if(t.length===0&&n.length===0&&r.length===0){q(e,i,a,o);return}if(t.length===0&&r.length===0&&n.length===1){let{pivotrect:t,otherrect:r}=Pn(e,n[0],i,a);q(e,t,a,o),q(n[0],r,a,o);return}if(t.length===1&&r.length===0&&n.length===1){let{lrect:r,pivotrect:s,rrect:c}=Fn(e,t[0],n[0],i,a);q(t[0],r,a,o),q(e,s,a,o),q(n[0],c,a,o);return}let s=In(e,t,n,r,i,a);for(;n.length>1;){let o=Ln(s.pivotrect);if(r.unshift(n.pop()),s=In(e,t,n,r,i,a),Ln(s.pivotrect)>=o){n.push(r.shift()),s=In(e,t,n,r,i,a);break}}q(e,s.pivotrect,a,o),zn(t,s.lrect,a,o),zn(n,s.mrect,a,o),zn(r,s.rrect,a,o)}function zn(e,t,n,r){if(e.length===0)return;if(e.length===1){q(e[0],t,n,r);return}let i=jn(e.length),a=e[i];Rn(a,e.slice(0,i),e.slice(i+1),[],t,n,r)}function q(e,t,n,r){r.set(e.id,t);let i=e.children.filter(e=>!e.isAdornment);if(i.length===0||t.w<=8||t.h<=20)return;let a={x:t.x+4,y:t.y+4+12,w:t.w-8,h:t.h-8-12};a.w<=0||a.h<=0||zn(i,a,n,r)}function Bn(e,t){let n=new Map,r=On(e);return zn(e.children.filter(e=>!e.isAdornment),t,r,n),n}var Vn=`
74
+ `,Dn=class e extends dt{static{this.BOX_SIZES=[[96,32],[82,28],[70,24],[60,20],[52,18]]}static boxSize(t){return e.BOX_SIZES[Math.min(t,e.BOX_SIZES.length-1)]}constructor(e,t){let n=document.createElement(`div`);n.id=`tbx-hyp-pane`,n.style.cssText=`display:none; overflow:auto;`,e.appendChild(n),super(n),this.focusNote=null,this.selectedNote=null,this.viewCenter=zt,this.dragPx=0,this.layout=null,this.animFrameId=null,this.sim=null,this.clickTimer=null,this.pendingNote=null,this.onNavigate=t,this.container.addEventListener(`click`,e=>this.handleClick(e)),this.container.addEventListener(`mousedown`,e=>this.handleMouseDown(e))}getViewRoot(){return null}hoistTo(e,t){}suspend(){this.sim?.stop()}render(e){if(this.currentNote=e,!e){this.sim?.stop(),this.sim=null,this.cancelPending(),this.container.innerHTML=``;return}if(e===this.selectedNote&&(this.animFrameId!==null||this.clickTimer!==null))return;this.cancelPending();let t=cn(this.layout,e);if(t){this.selectedNote=e,this.doRender(),e!==this.focusNote&&this.animateTo(this.viewCenter,t.pos,450,()=>this.refocus(e));return}this.selectedNote=e,this.focusNote=e,this.viewCenter=zt,this.layout=sn(e),this.startSim(),this.doRender()}isDoubleClickOn(e){return this.clickTimer!==null&&this.pendingNote===e}clearClickTimer(){this.clickTimer!==null&&(clearTimeout(this.clickTimer),this.clickTimer=null,this.pendingNote=null)}cancelPending(){this.cancelAnim(),this.clearClickTimer()}refocus(e){this.cancelAnim();let t=cn(this.layout,e),n=t?Jt(t.pos,this.viewCenter):zt;this.selectedNote=e,this.focusNote=e,this.layout=sn(e),this.startSim();let r=Kt(n,-1);this.viewCenter=r,this.animateTo(r,zt,450)}cancelAnim(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}startSim(){this.sim?.stop(),this.layout&&(this.sim=new yn(this.layout,()=>this.doRender()),this.sim.start())}animateTo(e,t,n,r){let i=performance.now(),a=o=>{let s=Math.min((o-i)/n,1),c=s*s*(3-2*s);this.viewCenter=[e[0]+(t[0]-e[0])*c,e[1]+(t[1]-e[1])*c],this.doRender(),s<1?this.animFrameId=requestAnimationFrame(a):(this.viewCenter=t,this.animFrameId=null,r?.())};this.animFrameId=requestAnimationFrame(a)}toSvgV(e){let t=Jt(e,this.viewCenter);return[Cn+t[0]*Sn,wn+t[1]*Sn]}clientToDisk(e,t){let n=this.container.querySelector(`svg`)?.getBoundingClientRect();if(!n)return null;let r=n.width/2,i=n.height/2,a=(e-n.left-r)/(r*xn),o=(t-n.top-i)/(i*xn);return a*a+o*o>=.999?null:[a,o]}doRender(){if(!this.layout||!this.currentNote)return;let e=`tbx-hyp-clip`,t=`<defs><clipPath id="${e}"><circle cx="${Cn}" cy="${wn}" r="${Sn}"/></clipPath></defs>`,n=`<circle cx="${Cn}" cy="${wn}" r="${Sn}" fill="#f5f5f0" stroke="#ccc" stroke-width="1"/>`;this.container.innerHTML=`<svg class="tbx-hyp-svg" width="100%" viewBox="0 0 ${bn} ${bn}">`+t+n+`<g clip-path="url(#${e})">${this.renderEdges()}</g>`+this.renderNodes()+`</svg>`}renderEdges(){let e=e=>this.toSvgV(e);return un(this.layout).map(([t,n])=>`<path d="${nn(t.pos,n.pos,e)}" stroke="#aaa" stroke-width="0.8" fill="none"/>`).join(``)}renderNodes(){return ln(this.layout).map(e=>this.renderNode(e)).join(``)}renderNode(t){let[n,r]=e.boxSize(t.depth),[i,a]=this.toSvgV(t.pos),o=i-n/2,s=a-r/2,c=t.note===this.focusNote,l=t.note===this.selectedNote,u=t.note===this.currentNote,d=c?`#c8c8b8`:l?`#d8eeff`:`#e8e8e0`,f=l?`#2266cc`:`#888`,p=l?2:1,m=u?`tbx-hyp-node tbx-hyp-current`:`tbx-hyp-node`,h=Math.max(8,Math.min(13,r*.45));return`<g class="${m}" data-id="${t.note.id}"><rect x="${o.toFixed(1)}" y="${s.toFixed(1)}" width="${n.toFixed(1)}" height="${r.toFixed(1)}" rx="3" fill="${d}" stroke="${f}" stroke-width="${p}"/><foreignObject x="${(o+1).toFixed(1)}" y="${s.toFixed(1)}" width="${(n-2).toFixed(1)}" height="${r.toFixed(1)}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:${h}px;font-family:Helvetica,Arial,sans-serif;padding:0 2px;box-sizing:border-box;display:flex;align-items:center;">`+V(t.note.get(`DisplayName`))+`</div></foreignObject></g>`}handleMouseDown(e){if(this.dragPx=0,this.sim?.stop(),document.addEventListener(`mouseup`,()=>this.sim?.start(),{once:!0}),e.target.closest(`[data-id]`))return;let t=this.clientToDisk(e.clientX,e.clientY);if(!t)return;this.cancelPending(),e.preventDefault();let n=this.viewCenter,r=this.container.querySelector(`svg`);r?.classList.add(`tbx-hyp-dragging`),this.dragPx=0;let i=e=>{let r=this.clientToDisk(e.clientX,e.clientY);r&&(this.dragPx+=Math.hypot(e.movementX,e.movementY),this.viewCenter=en(t,r,n),this.doRender())},a=()=>{r?.classList.remove(`tbx-hyp-dragging`),document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a)};document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}onArrow(e){if(!this.layout||!this.selectedNote)return!1;let t={ArrowRight:[1,0],ArrowLeft:[-1,0],ArrowDown:[0,1],ArrowUp:[0,-1]}[e.key];if(!t)return!1;let[n,r]=t,i=cn(this.layout,this.selectedNote);if(!i)return!1;let[a,o]=this.toSvgV(i.pos),s=this.selectedNote,c=new Set,l=[];for(let e of s.ht.links){if(e.isPrototype()||e.isUrlLink())continue;let t=e.src===s&&e.dest!==s?e.dest:e.dest===s&&e.src!==s?e.src:null;if(!t||c.has(t.id))continue;c.add(t.id);let n=cn(this.layout,t);n&&l.push(n)}let u=null,d=-1/0;for(let e of l){let[t,i]=this.toSvgV(e.pos),s=t-a,c=i-o,l=s*n+c*r;if(l<=0)continue;let f=l/(s*s+c*c);f>d&&(d=f,u=e.note)}return u?(this.onNavigate(u),!0):!1}handleClick(e){if(this.dragPx>5)return;let t=e.target.closest(`[data-id]`);if(!t)return;let n=parseInt(t.getAttribute(`data-id`),10),r=this.layout?.byId.get(n)?.note;if(r){if(this.isDoubleClickOn(r)){this.clearClickTimer(),this.refocus(r);return}this.cancelPending(),this.selectedNote=r,this.pendingNote=r,this.layout&&dn(this.layout,r),this.sim?.wakeUp(),this.doRender(),this.clickTimer=setTimeout(()=>{this.clickTimer=null,this.pendingNote=null;let e=this.layout?.byId.get(n);e&&this.animateTo(this.viewCenter,e.pos,450)},Tn),this.onNavigate(r)}}};function On(e){let t=new Map;kn(e,t);let n=t.get(e.id);return n.weight=1,An(e,t),t}function kn(e,t){let n=e.children.filter(e=>!e.isAdornment);if(n.length===0)return t.set(e.id,{rawWeight:1,weight:1}),1;let r=0;for(let e of n)r+=kn(e,t);return t.set(e.id,{rawWeight:r,weight:1}),r}function An(e,t){let n=e.children.filter(e=>!e.isAdornment);if(n.length===0)return;let r=n.reduce((e,n)=>e+t.get(n.id).rawWeight,0),i=r===0?1:r;for(let e of n)t.get(e.id).weight=t.get(e.id).rawWeight/i,An(e,t)}function jn(e){return Math.floor((e-1)/2)}function Mn(e){return e.w>=e.h}function K(e,t){return t.get(e.id)?.weight??0}function Nn(e,t,n){let r=e.reduce((e,t)=>e+K(t,n),0);return t&&(r+=K(t,n)),r}function Pn(e,t,n,r){let i=K(e,r)+K(t,r),a=i===0?.5:K(e,r)/i;return Mn(n)?{pivotrect:{x:n.x,y:n.y,w:n.w*a,h:n.h},otherrect:{x:n.x+n.w*a,y:n.y,w:n.w*(1-a),h:n.h}}:{pivotrect:{x:n.x,y:n.y,w:n.w,h:n.h*a},otherrect:{x:n.x,y:n.y+n.h*a,w:n.w,h:n.h*(1-a)}}}function Fn(e,t,n,r,i){let a=K(t,i),o=K(e,i),s=K(n,i),c=a+o+s||1,l=a/c,u=o/c;return r.h<r.w/1.6?{lrect:{x:r.x,y:r.y,w:r.w*l,h:r.h},pivotrect:{x:r.x+r.w*l,y:r.y,w:r.w*u,h:r.h},rrect:{x:r.x+r.w*(l+u),y:r.y,w:r.w*(1-l-u),h:r.h}}:{lrect:{x:r.x,y:r.y,w:r.w,h:r.h*l},pivotrect:{x:r.x,y:r.y+r.h*l,w:r.w,h:r.h*u},rrect:{x:r.x,y:r.y+r.h*(l+u),w:r.w,h:r.h*(1-l-u)}}}function In(e,t,n,r,i,a){let o=Nn(t,null,a),s=Nn(n,e,a),c=Nn(r,null,a),l=o+s+c||1,u=o/l,d=s/l,f=Mn(i),p,m,h;f?(p={x:i.x,y:i.y,w:i.w*u,h:i.h},m={x:i.x+i.w*u,y:i.y,w:i.w*d,h:i.h},h={x:i.x+i.w*(u+d),y:i.y,w:i.w*(1-u-d),h:i.h}):(p={x:i.x,y:i.y,w:i.w,h:i.h*u},m={x:i.x,y:i.y+i.h*u,w:i.w,h:i.h*d},h={x:i.x,y:i.y+i.h*(u+d),w:i.w,h:i.h*(1-u-d)});let g=s===0?1:K(e,a)/s,_;return f?(_={...m,h:m.h*g},m={...m,y:m.y+m.h*g,h:m.h*(1-g)}):(_={...m,w:m.w*g},m={...m,x:m.x+m.w*g,w:m.w*(1-g)}),{lrect:p,mrect:m,rrect:h,pivotrect:_}}function Ln(e){if(e.w===0)return 0;let t=e.h/e.w-.6;return t*t}function Rn(e,t,n,r,i,a,o){if(t.length===0&&n.length===0&&r.length===0){q(e,i,a,o);return}if(t.length===0&&r.length===0&&n.length===1){let{pivotrect:t,otherrect:r}=Pn(e,n[0],i,a);q(e,t,a,o),q(n[0],r,a,o);return}if(t.length===1&&r.length===0&&n.length===1){let{lrect:r,pivotrect:s,rrect:c}=Fn(e,t[0],n[0],i,a);q(t[0],r,a,o),q(e,s,a,o),q(n[0],c,a,o);return}let s=In(e,t,n,r,i,a);for(;n.length>1;){let o=Ln(s.pivotrect);if(r.unshift(n.pop()),s=In(e,t,n,r,i,a),Ln(s.pivotrect)>=o){n.push(r.shift()),s=In(e,t,n,r,i,a);break}}q(e,s.pivotrect,a,o),zn(t,s.lrect,a,o),zn(n,s.mrect,a,o),zn(r,s.rrect,a,o)}function zn(e,t,n,r){if(e.length===0)return;if(e.length===1){q(e[0],t,n,r);return}let i=jn(e.length),a=e[i];Rn(a,e.slice(0,i),e.slice(i+1),[],t,n,r)}function q(e,t,n,r){r.set(e.id,t);let i=e.children.filter(e=>!e.isAdornment);if(i.length===0||t.w<=8||t.h<=20)return;let a={x:t.x+4,y:t.y+4+12,w:t.w-8,h:t.h-8-12};a.w<=0||a.h<=0||zn(i,a,n,r)}function Bn(e,t){let n=new Map,r=On(e);return zn(e.children.filter(e=>!e.isAdornment),t,r,n),n}var Vn=`
75
75
  .tbx-tm-wrap { display: flex; flex-direction: column; width: 100%; height: 100%; }
76
76
  .tbx-tm-canvas { position: relative; flex: 1; }
77
77
  .tbx-tm-note {
@@ -164,7 +164,7 @@ var TbxDocument=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`
164
164
  #tbx-gaudi-pane.tbx-gaudi-dragging,
165
165
  #tbx-gaudi-pane.tbx-gaudi-dragging path { cursor: grabbing; }
166
166
  #tbx-gaudi-pane .tbx-gaudi-sel { stroke: var(--tbx-accent, #2266cc); stroke-width: 4; animation: tbx-svg-pulse 500ms ease-in-out infinite alternate; }
167
- `,Rr=/[ \t\r\n\f\v.,;:!?()\[\]{}"]/;function zr(e){return!Rr.test(e)}function Br(e,t){if(t<0||t>e.length)return null;let n=Math.min(t,e.length-1);if(!zr(e[n]))return null;let r=n;for(;r>0&&zr(e[r-1]);)r--;let i=n+1;for(;i<e.length&&zr(e[i]);)i++;return e.slice(r,i)||null}function Vr(e,t,n){if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r?.startContainer.nodeType===Node.TEXT_NODE)return{node:r.startContainer,offset:r.startOffset}}if(e.caretPositionFromPoint){let r=e.caretPositionFromPoint(t,n);if(r?.offsetNode?.nodeType===Node.TEXT_NODE)return{node:r.offsetNode,offset:r.offset}}return null}function Hr(e,t,n){let r=Vr(n.ownerDocument,e,t);if(r&&n.contains(r.node))return Br(r.node.textContent??``,r.offset);let i=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),a;for(;a=i.nextNode();){let n=a.textContent??``;if(!n)continue;let r=document.createRange();r.selectNodeContents(a);let i=[...r.getClientRects()];if(i.length>0){for(let r of i)if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom){(r.top+r.bottom)/2;let t=0,i=n.length-1;for(;t<i;){let n=t+i>>1,o=document.createRange();o.setStart(a,n),o.setEnd(a,n+1);let s=o.getBoundingClientRect(),c=(s.top+s.bottom)/2;c<r.top?t=n+1:c>=r.bottom?i=n:s.right<=e?t=n+1:i=n}return Br(n,t)}continue}let o=a.parentElement;if(!o)continue;let s=o.getBoundingClientRect();if(!(t<s.top||t>s.bottom))return Br(n,Ur(o,n,e-s.left))}return null}function Ur(e,t,n){let r=window.getComputedStyle(e),i=document.createElement(`canvas`).getContext(`2d`);if(!i)return 0;i.font=`${r.fontStyle} ${r.fontWeight} ${r.fontSize} ${r.fontFamily}`;for(let e=1;e<=t.length;e++)if(i.measureText(t.slice(0,e)).width>=n)return e-1;return t.length-1}function Wr(e){return[`map`,`outline`,`treemap`,`gaudi`,`hyperbolic`].includes(e)}var Gr=class{constructor(e,t,n,r,i){this.panes=e,this._mode=t,this.leftColEl=n,this.outlineEl=r,this.getToolbarLeft=i}connectBreadcrumbs(e){this.updateBreadcrumbsFn=e;for(let{view:t}of this.panes.values())t.onViewRootChange=e}updateBreadcrumbs(){this.updateBreadcrumbsFn?.()}get mode(){return this._mode}get activeView(){return this.panes.get(this._mode).view}switchTo(e){this._mode=e}updateVisibility(){let{wide:e,fillHeight:t}=this.panes.get(this._mode);this.leftColEl.style.width=e?`50%`:``,this.outlineEl.style.overflowX=e?`auto`:`hidden`,this.outlineEl.style.paddingRight=e?`0`:``,this.outlineEl.style.height=t?`100%`:``;let n=this.getToolbarLeft();n&&(n.style.width=e?`${this.leftColEl.offsetWidth}px`:``);for(let[e,{view:t}]of this.panes)t.el.style.display=e===this._mode?``:`none`}renderCurrent(e){this.activeView.render(e)}scrollToSelected(){this.activeView.scrollToSelected()}onArrow(e){return this.activeView.onArrow(e)}getViewRoot(){return this.activeView.getViewRoot()}hoistTo(e,t){this.activeView.hoistTo(e,t)}renderOnSwitch(e){this.activeView.willRender(e),this.activeView.render(e)}switchView(e,t){this.switchTo(e),this.updateVisibility(),this.updateBreadcrumbs(),t&&(this.renderOnSwitch(t),this.scrollToSelected())}},Kr=`
167
+ `,Rr=/[ \t\r\n\f\v.,;:!?()\[\]{}"]/;function zr(e){return!Rr.test(e)}function Br(e,t){if(t<0||t>e.length)return null;let n=Math.min(t,e.length-1);if(!zr(e[n]))return null;let r=n;for(;r>0&&zr(e[r-1]);)r--;let i=n+1;for(;i<e.length&&zr(e[i]);)i++;return e.slice(r,i)||null}function Vr(e,t,n){if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r?.startContainer.nodeType===Node.TEXT_NODE)return{node:r.startContainer,offset:r.startOffset}}if(e.caretPositionFromPoint){let r=e.caretPositionFromPoint(t,n);if(r?.offsetNode?.nodeType===Node.TEXT_NODE)return{node:r.offsetNode,offset:r.offset}}return null}function Hr(e,t,n){let r=Vr(n.ownerDocument,e,t);if(r&&n.contains(r.node))return Br(r.node.textContent??``,r.offset);let i=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),a;for(;a=i.nextNode();){let n=a.textContent??``;if(!n)continue;let r=document.createRange();r.selectNodeContents(a);let i=[...r.getClientRects()];if(i.length>0){for(let r of i)if(e>=r.left&&e<=r.right&&t>=r.top&&t<=r.bottom){(r.top+r.bottom)/2;let t=0,i=n.length-1;for(;t<i;){let n=t+i>>1,o=document.createRange();o.setStart(a,n),o.setEnd(a,n+1);let s=o.getBoundingClientRect(),c=(s.top+s.bottom)/2;c<r.top?t=n+1:c>=r.bottom?i=n:s.right<=e?t=n+1:i=n}return Br(n,t)}continue}let o=a.parentElement;if(!o)continue;let s=o.getBoundingClientRect();if(!(t<s.top||t>s.bottom))return Br(n,Ur(o,n,e-s.left))}return null}function Ur(e,t,n){let r=window.getComputedStyle(e),i=document.createElement(`canvas`).getContext(`2d`);if(!i)return 0;i.font=`${r.fontStyle} ${r.fontWeight} ${r.fontSize} ${r.fontFamily}`;for(let e=1;e<=t.length;e++)if(i.measureText(t.slice(0,e)).width>=n)return e-1;return t.length-1}function Wr(e){return[`map`,`outline`,`treemap`,`gaudi`,`hyperbolic`].includes(e)}var Gr=class{constructor(e,t,n,r,i){this.panes=e,this._mode=t,this.leftColEl=n,this.outlineEl=r,this.getToolbarLeft=i}connectBreadcrumbs(e){this.updateBreadcrumbsFn=e;for(let{view:t}of this.panes.values())t.onViewRootChange=e}updateBreadcrumbs(){this.updateBreadcrumbsFn?.()}get mode(){return this._mode}get activeView(){return this.panes.get(this._mode).view}switchTo(e){this._mode=e}updateVisibility(){let{wide:e,fillHeight:t}=this.panes.get(this._mode);this.leftColEl.style.width=e?`var(--tbx-map-width, 50%)`:``,this.outlineEl.style.overflowX=e?`auto`:`hidden`,this.outlineEl.style.paddingRight=e?`0`:``,this.outlineEl.style.height=t?`100%`:``;let n=this.getToolbarLeft();n&&(n.style.width=e?`${this.leftColEl.offsetWidth}px`:``);for(let[e,{view:t}]of this.panes)t.el.style.display=e===this._mode?``:`none`}renderCurrent(e){this.activeView.render(e)}scrollToSelected(){this.activeView.scrollToSelected()}onArrow(e){return this.activeView.onArrow(e)}getViewRoot(){return this.activeView.getViewRoot()}hoistTo(e,t){this.activeView.hoistTo(e,t)}renderOnSwitch(e){this.activeView.willRender(e),this.activeView.render(e)}switchView(e,t){this.activeView.suspend(),this.switchTo(e),this.updateVisibility(),this.updateBreadcrumbs(),t&&(this.renderOnSwitch(t),this.scrollToSelected())}},Kr=`
168
168
  #tbx-breadcrumbs {
169
169
  flex-shrink: 0;
170
170
  height: 26px;
@@ -2623,6 +2623,7 @@ var ut = class {
2623
2623
  return this.container;
2624
2624
  }
2625
2625
  willRender(e) {}
2626
+ suspend() {}
2626
2627
  scrollToSelected() {}
2627
2628
  onArrow(e) {
2628
2629
  return !1;
@@ -3544,6 +3545,9 @@ var _n = [0, 0], vn = 2 * rn, yn = class {
3544
3545
  return null;
3545
3546
  }
3546
3547
  hoistTo(e, t) {}
3548
+ suspend() {
3549
+ this.sim?.stop();
3550
+ }
3547
3551
  render(e) {
3548
3552
  if (this.currentNote = e, !e) {
3549
3553
  this.sim?.stop(), this.sim = null, this.cancelPending(), this.container.innerHTML = "";
@@ -5098,7 +5102,7 @@ var Wr = class {
5098
5102
  }
5099
5103
  updateVisibility() {
5100
5104
  let { wide: e, fillHeight: t } = this.panes.get(this._mode);
5101
- this.leftColEl.style.width = e ? "50%" : "", this.outlineEl.style.overflowX = e ? "auto" : "hidden", this.outlineEl.style.paddingRight = e ? "0" : "", this.outlineEl.style.height = t ? "100%" : "";
5105
+ this.leftColEl.style.width = e ? "var(--tbx-map-width, 50%)" : "", this.outlineEl.style.overflowX = e ? "auto" : "hidden", this.outlineEl.style.paddingRight = e ? "0" : "", this.outlineEl.style.height = t ? "100%" : "";
5102
5106
  let n = this.getToolbarLeft();
5103
5107
  n && (n.style.width = e ? `${this.leftColEl.offsetWidth}px` : "");
5104
5108
  for (let [e, { view: t }] of this.panes) t.el.style.display = e === this._mode ? "" : "none";
@@ -5122,7 +5126,7 @@ var Wr = class {
5122
5126
  this.activeView.willRender(e), this.activeView.render(e);
5123
5127
  }
5124
5128
  switchView(e, t) {
5125
- this.switchTo(e), this.updateVisibility(), this.updateBreadcrumbs(), t && (this.renderOnSwitch(t), this.scrollToSelected());
5129
+ this.activeView.suspend(), this.switchTo(e), this.updateVisibility(), this.updateBreadcrumbs(), t && (this.renderOnSwitch(t), this.scrollToSelected());
5126
5130
  }
5127
5131
  }, Gr = "\n #tbx-breadcrumbs {\n flex-shrink: 0;\n height: 26px;\n display: flex;\n align-items: stretch;\n overflow: hidden;\n background: linear-gradient(to bottom, #d4d4d4, #b8b8b8);\n border-bottom: 1px solid rgba(0,0,0,0.28);\n font-family: var(--tbx-outline-font-family, Helvetica, Arial, sans-serif);\n font-size: 0.85em;\n transition: height 0.22s ease-out, border-bottom-width 0.22s ease-out;\n }\n #tbx-breadcrumbs.tbx-bc-hidden { height: 0; border-bottom-width: 0; }\n .tbx-bc-crumb {\n flex: 0 1 auto;\n display: flex;\n align-items: center;\n padding: 0 1.2em 0 0.6em;\n white-space: nowrap;\n overflow: hidden;\n color: #484848;\n cursor: pointer;\n /* Horizontal gradient: light left face → dark right edge, suggesting\n depth at the chevron tip without relying on drop-shadow. */\n background: linear-gradient(to right, #f6f6f6,#e6e6e6, #cccccc);\n /* All crumbs: flat left + right-pointing chevron (9 px depth). */\n clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%);\n margin-right: -5px;\n }\n .tbx-bc-crumb:hover {\n color: #1a1a1a;\n background: linear-gradient(to right, #ffffff, #d8d8d8);\n }\n .tbx-bc-sep { display: none; }\n";
5128
5132
  function Kr(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eastgatesystems/tbx-reader",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "Web component reader for Tinderbox and Storyspace .tbx hypertext documents",
5
5
  "main": "dist/tbx-document.iife.js",
6
6
  "module": "dist/tbx-document.mjs",