@dineug/erd-editor 3.7.0 → 3.9.0
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/README.md +1 -1
- package/dist/components/erd/automatic-table-placement/AutomaticTablePlacement.d.ts +0 -15
- package/dist/components/erd/automatic-table-placement/runElkPlacement.d.ts +11 -0
- package/dist/components/erd/canvas/CanvasScene.d.ts +3 -3
- package/dist/components/erd/canvas/column-drag-ghost/ColumnDragGhost.d.ts +10 -0
- package/dist/components/erd/canvas/column-drag-ghost/columnDragPointer.d.ts +28 -0
- package/dist/components/erd/canvas/entityDrag.d.ts +5 -4
- package/dist/components/erd/canvas/highlightTransition.d.ts +35 -0
- package/dist/components/erd/canvas/memo/useMoveMemo.d.ts +3 -1
- package/dist/components/erd/canvas/mixColor.d.ts +7 -0
- package/dist/components/erd/canvas/relationship-group/RelationshipGroup.d.ts +2 -0
- package/dist/components/erd/canvas/relationship-group/relationship/Relationship.d.ts +2 -0
- package/dist/components/erd/canvas/relationship-group/relationship/Relationship.template.d.ts +3 -3
- package/dist/components/erd/canvas/sceneHit.d.ts +7 -6
- package/dist/components/erd/canvas/sceneTokens.d.ts +58 -6
- package/dist/components/erd/canvas/table/Table.d.ts +7 -0
- package/dist/components/erd/canvas/table/cellLayout.d.ts +50 -20
- package/dist/components/erd/canvas/table/colorEdge.d.ts +10 -0
- package/dist/components/erd/canvas/table/column/Column.d.ts +35 -0
- package/dist/components/erd/canvas/table/goToErd.d.ts +18 -0
- package/dist/components/erd/canvas/table/useMoveTable.d.ts +3 -1
- package/dist/components/erd/canvas/table/useViewPin.d.ts +19 -0
- package/dist/components/erd/canvas/useMoveEntity.d.ts +15 -2
- package/dist/components/erd/content-compass/ContentCompass.d.ts +1 -1
- package/dist/components/erd/content-compass/compassGeometry.d.ts +27 -4
- package/dist/components/erd/diff-viewer/diff.d.ts +9 -2
- package/dist/components/erd/diff-viewer/diffContext.d.ts +9 -0
- package/dist/components/erd/floating-toolbar/FloatingToolbar.d.ts +3 -3
- package/dist/components/erd/floating-toolbar/FloatingToolbar.styles.d.ts +3 -0
- package/dist/components/erd/floating-toolbar/ToolbarCompass.template.d.ts +14 -0
- package/dist/components/erd/minimap/MinimapScene.d.ts +1 -1
- package/dist/components/erd/minimap/minimapGeometry.d.ts +4 -3
- package/dist/components/flowCenters.d.ts +10 -0
- package/dist/components/primitives/context-menu/context-menu-content/ContextMenuContent.d.ts +2 -0
- package/dist/components/primitives/context-menu/context-menu-content/fitMenu.d.ts +20 -0
- package/dist/components/primitives/icon/icons.d.ts +5 -2
- package/dist/components/sceneSourceContext.d.ts +10 -0
- package/dist/components/table-view/Table.styles.d.ts +6 -1
- package/dist/components/table-view/column/useColumnCell.d.ts +5 -0
- package/dist/components/theme-builder/ThemeBuilder.styles.d.ts +5 -0
- package/dist/components/visualization/Visualization.d.ts +3 -4
- package/dist/components/visualization/Visualization.styles.d.ts +4 -1
- package/dist/components/visualization/VisualizationFlow.d.ts +10 -0
- package/dist/components/visualization/VisualizationGraph.d.ts +10 -0
- package/dist/components/visualization/captureDrag.d.ts +14 -0
- package/dist/components/visualization/flowLayout.d.ts +29 -0
- package/dist/components/visualization/graphViewHandle.d.ts +33 -0
- package/dist/components/visualization/particles/ParticleLayer.d.ts +10 -0
- package/dist/components/visualization/particles/particleEdges.d.ts +15 -0
- package/dist/components/visualization/particles/particleLoop.d.ts +28 -0
- package/dist/components/visualization/particles/particlePath.d.ts +83 -0
- package/dist/components/visualization/useViewGestures.d.ts +24 -0
- package/dist/components/visualization/visualization-toolbar/VisualizationToolbar.d.ts +10 -0
- package/dist/components/visualization/visualization-toolbar/VisualizationToolbar.styles.d.ts +4 -0
- package/dist/components/visualization/visualizationView.d.ts +29 -5
- package/dist/components/visualization/zoomVisualization.d.ts +20 -0
- package/dist/constants/layout.d.ts +74 -1
- package/dist/constants/tablePlacement.d.ts +4 -3
- package/dist/constants/zoom.d.ts +7 -0
- package/dist/engine/actions.d.ts +6 -0
- package/dist/engine/index.js +12 -12
- package/dist/engine/modules/editor/actions.d.ts +60 -2
- package/dist/engine/modules/editor/atom.actions.d.ts +136 -0
- package/dist/engine/modules/editor/generator.actions.d.ts +19 -6
- package/dist/engine/modules/editor/state.d.ts +41 -0
- package/dist/engine/modules/editor/view.actions.d.ts +270 -0
- package/dist/engine/modules/editor/view.d.ts +28 -0
- package/dist/engine/modules/editor/view.generator.actions.d.ts +24 -0
- package/dist/engine/modules/settings/atom.actions.d.ts +17 -3
- package/dist/engine/modules/settings/generator.actions.d.ts +21 -4
- package/dist/engine/rx-operators/viewActionRedirect.d.ts +10 -0
- package/dist/engine/rx-operators/viewIgnoreFilter.d.ts +10 -0
- package/dist/engine/rx-store.d.ts +1 -0
- package/dist/engine/tag.d.ts +2 -0
- package/dist/erd-editor.umd.js +365 -314
- package/dist/hooks/usePinchZoom.d.ts +27 -0
- package/dist/index.js +6750 -5202
- package/dist/konva/scene/columnDropTarget.d.ts +12 -4
- package/dist/konva/scene/contentBounds.d.ts +12 -5
- package/dist/konva/scene/fitZoom.d.ts +16 -0
- package/dist/konva/scene/metrics.d.ts +6 -5
- package/dist/konva/scene/viewFreeze.d.ts +10 -7
- package/dist/konva/scene/viewLayout.d.ts +94 -0
- package/dist/konva/scene/viewport.d.ts +23 -4
- package/dist/{schemaGCService--wGet5O7.js → schemaGCService-CFiz1xOG.js} +3725 -3132
- package/dist/services/elk-layout/elkGraph.d.ts +40 -1
- package/dist/services/elk-layout/elkLayoutOptions.d.ts +22 -1
- package/dist/services/elk-layout/elkLayoutService.d.ts +5 -1
- package/dist/services/elk-layout/index.d.ts +10 -4
- package/dist/styles/elevation.styles.d.ts +7 -0
- package/dist/themes/radix-ui-theme.config.d.ts +12 -0
- package/dist/themes/tokens.d.ts +7 -0
- package/dist/utils/calcTable.d.ts +23 -1
- package/dist/utils/clickGesture.d.ts +19 -0
- package/dist/utils/domEvent.d.ts +8 -0
- package/dist/utils/draw-relationship/bezier.d.ts +32 -0
- package/dist/utils/draw-relationship/calc.d.ts +6 -1
- package/dist/utils/draw-relationship/geometrySource.d.ts +9 -0
- package/dist/utils/draw-relationship/incremental.d.ts +7 -1
- package/dist/utils/draw-relationship/index.d.ts +37 -11
- package/dist/utils/draw-relationship/pathFinding.d.ts +2 -1
- package/dist/utils/draw-relationship/route.d.ts +5 -3
- package/dist/utils/draw-relationship/sort.d.ts +2 -1
- package/dist/utils/draw-relationship/stub.d.ts +9 -4
- package/dist/utils/emitter.d.ts +4 -0
- package/dist/utils/keyboard-shortcut/index.d.ts +2 -1
- package/dist/utils/pinch.d.ts +34 -0
- package/dist/utils/validation.d.ts +1 -0
- package/dist/workers/elkLayout.shared-worker.js +1 -1
- package/dist/workers/exportPng.shared-worker.js +26 -26
- package/package.json +3 -3
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import*as e from"comlink";import{CHARSET as t,DECLARATION as n,IMPORT as r,LAYER as i,NAMESPACE as a,RULESET as o,alloc as s,dealloc as c,parse as l}from"stylis";import{Container as u}from"konva/lib/Container";import{Group as d}from"konva/lib/Group";import{Layer as f}from"konva/lib/Layer";import{Node as p}from"konva/lib/Node";import{Circle as m}from"konva/lib/shapes/Circle";import{Line as h}from"konva/lib/shapes/Line";import{Path as g}from"konva/lib/shapes/Path";import{Rect as ee}from"konva/lib/shapes/Rect";import{Text as _}from"konva/lib/shapes/Text";import{Stage as te}from"konva/lib/Stage";import{DD as ne}from"konva/lib/DragAndDrop";import{Konva as re}from"konva/lib/Global";import{camelCase as ie,clamp as ae,cloneDeep as oe,difference as se,groupBy as ce,head as le,isBoolean as ue,isFunction as de,isNil as v,isNotNil as fe,isNumber as y,isPlainObject as pe,isString as b,last as me,lowerFirst as he,noop as ge,omit as _e,pick as ve,range as ye,snakeCase as be,uniq as xe,upperFirst as Se}from"es-toolkit";import{Observable as Ce,Subject as we,animationFrames as Te,asapScheduler as Ee,buffer as De,debounceTime as Oe,defer as ke,filter as Ae,fromEvent as je,groupBy as Me,map as Ne,merge as Pe,mergeMap as Fe,observeOn as Ie,share as Le,takeUntil as Re,tap as ze,throttleTime as Be}from"rxjs";import{get as Ve,isEmpty as He,round as Ue}from"es-toolkit/compat";import{nanoid as x}from"nanoid";import We from"deepmerge";import{Kind as Ge,TokenKind as Ke,parse as qe}from"graphql";import Je,{getAccurateAgent as Ye}from"@egjs/agent";import{AlignHorizontalDistributeCenter as Xe,AlignVerticalDistributeCenter as Ze,ArrowRight as Qe,Atom as $e,Braces as et,Brackets as tt,CaseSensitive as nt,Check as rt,ChevronRight as it,Code as at,Contrast as ot,Copy as st,Database as ct,Diff as lt,Eye as ut,FileDiff as dt,FileImage as ft,FileInput as pt,FileOutput as mt,GripVertical as ht,Hand as gt,KeyRound as _t,Maximize as vt,Minimize as yt,Minus as bt,MoonStar as xt,MousePointer2 as St,Palette as Ct,Plus as wt,Redo2 as Tt,RefreshCw as Et,RotateCcwClock as Dt,Search as Ot,Settings as kt,Share2 as At,Spline as jt,StickyNote as Mt,Sun as Nt,Table as Pt,TableProperties as Ft,Undo2 as It,WandSparkles as Lt,Waypoints as Rt,Workflow as zt,X as Bt}from"lucide";import{amber as Vt,amberA as Ht,amberDark as Ut,amberDarkA as Wt,blue as Gt,blueA as Kt,blueDark as qt,blueDarkA as Jt,bronze as Yt,bronzeA as Xt,bronzeDark as Zt,bronzeDarkA as Qt,brown as $t,brownA as en,brownDark as tn,brownDarkA as nn,crimson as rn,crimsonA as an,crimsonDark as on,crimsonDarkA as sn,cyan as cn,cyanA as ln,cyanDark as un,cyanDarkA as dn,gold as fn,goldA as pn,goldDark as mn,goldDarkA as hn,grass as gn,grassA as _n,grassDark as vn,grassDarkA as yn,gray as bn,grayA as xn,grayDark as Sn,grayDarkA as Cn,green as wn,greenA as Tn,greenDark as En,greenDarkA as Dn,indigo as On,indigoA as kn,indigoDark as An,indigoDarkA as jn,iris as Mn,irisA as Nn,irisDark as Pn,irisDarkA as Fn,jade as In,jadeA as Ln,jadeDark as Rn,jadeDarkA as zn,lime as Bn,limeA as Vn,limeDark as Hn,limeDarkA as Un,mauve as Wn,mauveA as Gn,mauveDark as Kn,mauveDarkA as qn,mint as Jn,mintA as Yn,mintDark as Xn,mintDarkA as Zn,olive as Qn,oliveA as $n,oliveDark as er,oliveDarkA as tr,orange as nr,orangeA as rr,orangeDark as ir,orangeDarkA as ar,pink as or,pinkA as sr,pinkDark as cr,pinkDarkA as lr,plum as ur,plumA as dr,plumDark as fr,plumDarkA as pr,purple as mr,purpleA as hr,purpleDark as gr,purpleDarkA as _r,red as vr,redA as yr,redDark as br,redDarkA as xr,ruby as Sr,rubyA as Cr,rubyDark as wr,rubyDarkA as Tr,sage as Er,sageA as Dr,sageDark as Or,sageDarkA as kr,sand as Ar,sandA as jr,sandDark as Mr,sandDarkA as Nr,sky as Pr,skyA as Fr,skyDark as Ir,skyDarkA as Lr,slate as Rr,slateA as zr,slateDark as Br,slateDarkA as Vr,teal as Hr,tealA as Ur,tealDark as Wr,tealDarkA as Gr,tomato as Kr,tomatoA as qr,tomatoDark as Jr,tomatoDarkA as Yr,violet as Xr,violetA as Zr,violetDark as Qr,violetDarkA as $r,yellow as ei,yellowA as ti,yellowDark as ni,yellowDarkA as ri}from"@radix-ui/colors";import{layoutWithLines as ii,prepareWithSegments as ai}from"@chenglou/pretext";import{Easings as oi,Tween as si}from"konva/lib/Tween";function ci(e){"@babel/helpers - typeof";return ci=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},ci(e)}function li(e,t){if(ci(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(ci(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ui(e){var t=li(e,`string`);return ci(t)==`symbol`?t:t+``}function di(e,t,n){return(t=ui(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var fi=class extends EventTarget{constructor(...e){super(...e),di(this,`textContent`,``)}},pi=class{};function mi(){let e=new OffscreenCanvas(1,1);return e.style??={},e}typeof document>`u`&&(Reflect.set(globalThis,`document`,{createElement:e=>e===`canvas`?mi():new fi}),Reflect.set(globalThis,`Node`,pi),Reflect.set(globalThis,`HTMLElement`,pi));function hi(e,t){return Object.freeze({key:t??Symbol(),value:e})}var gi={subscribe:`@@r-html/context-subscribe`,unsubscribe:`@@r-html/context-unsubscribe`};function _i(e,t){function n(n,r){return new CustomEvent(e,{detail:n,...t,...r})}return n.toString=()=>`${e}`,n.type=e,n}var vi=_i(gi.subscribe,{bubbles:!0,composed:!0}),yi=_i(gi.unsubscribe,{bubbles:!0,composed:!0});function bi(e,t){let n=e=>{let n=e;t.dispatchEvent(vi(n.detail))},r=e=>{let n=e;t.dispatchEvent(yi(n.detail))};return e.addEventListener(vi.type,n),e.addEventListener(yi.type,r),()=>{e.removeEventListener(vi.type,n),e.removeEventListener(yi.type,r)}}function xi(e,...t){try{return e?.(...t)}catch(e){console.error(e)}}var Si=queueMicrotask??(e=>{Promise.resolve().then(e)}),Ci=e=>t=>typeof t===e,wi=Ci(`object`),Ti=Ci(`bigint`),Ei=Ci(`boolean`),Di=Ci(`function`),Oi=Ci(`number`),ki=Ci(`string`),Ai=Ci(`symbol`),ji=Ci(`undefined`),Mi=e=>e===null,{isArray:Ni}=Array,Pi=e=>wi(e)&&!Mi(e)&&!Ni(e),Fi=e=>Ti(e)||Ei(e)||Oi(e)||ki(e)||Ai(e)||ji(e)||Mi(e);function Ii(){let e=new Set,t=t=>(e.has(t)||e.add(t),()=>{e.delete(t)});return{subscribe:t,next:t=>{e.forEach(e=>e(t))},asReadonly:()=>({subscribe:t})}}var Li=`...`,Ri=`@@r-html-${Math.random().toString().substring(2,8)}`,zi=`${Li}${Ri}`,Bi=RegExp(`${Ri}_(\\d+)_`,`g`),Vi=RegExp(`^${Ri}_\\d+_$`),Hi=/^\n/,S=function(e){return e.attribute=`attribute`,e.boolean=`boolean`,e.event=`event`,e.property=`property`,e.spread=`spread`,e.directive=`directive`,e}({}),Ui=Symbol.for(`https://github.com/dineug/r-html#beforeMount`),Wi=Symbol.for(`https://github.com/dineug/r-html#mounted`),Gi=Symbol.for(`https://github.com/dineug/r-html#unmounted`),Ki=Symbol.for(`https://github.com/dineug/r-html#beforeFirstUpdate`),qi=Symbol.for(`https://github.com/dineug/r-html#beforeUpdate`),Ji=Symbol.for(`https://github.com/dineug/r-html#firstUpdated`),Yi=Symbol.for(`https://github.com/dineug/r-html#updated`),Xi=[Ui,Wi,Gi,Ki,qi,Ji,Yi],Zi=Symbol.for(`https://github.com/dineug/r-html#Directive`),Qi=Symbol.for(`https://github.com/dineug/r-html#TemplateLiterals`),$i=null;function ea(e){$i=e}var ta=e=>t=>{$i&&($i[e]??($i[e]=[])).push(t)},na=ta(Ui),ra=ta(Wi),ia=ta(Gi);function aa(e,t){let n=Reflect.get(e,t,e);Ni(n)&&n.forEach(xi)}function oa(e){Xi.forEach(t=>Reflect.set(e,t,null,e))}function sa(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function C(e,t,n){sa(e,t),t.set(e,n)}function ca(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}function w(e,t,n){return e.set(ca(e,t),n),n}function T(e,t){return e.get(ca(e,t))}var la=Ii(),ua=e=>e,da=e=>{var t,n;return t=new WeakMap,n=new WeakMap,class extends e{constructor(e,r,i,a){super(e,r,i,a),C(this,t,[]),C(this,n,null),this.hmr()}commit(e){let n=ua(e);super.commit(n),w(t,this,e)}hmr(){w(n,this,la.subscribe(e=>T(t,this).includes(e)&&this.commit(T(t,this))))}destroy(){T(n,this)?.call(this),super.destroy?.()}}},fa=new WeakMap,pa=new WeakMap,ma=new WeakMap,ha=new WeakMap,ga=new WeakMap,_a={shallow:!1},va=null;function ya(e){return va=e,xi(e),va=null,()=>ba(e)}function ba(e){Pa(e);let t=ga.get(e);if(t)for(let[n]of t.entries())pa.get(n)?.delete(e);t&&ga.delete(e)}function xa(e){if(!va)return;let t=pa.get(e);t?t.has(va)||t.add(va):pa.set(e,new Set([va]))}function Sa(e,t){if(!va)return;let n=ga.get(va);if(n){let r=n.get(e);r?r.has(t)||r.add(t):n.set(e,new Set([t]))}else ga.set(va,new Map([[e,new Set([t])]]))}var Ca=e=>e instanceof Node||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof RegExp||e instanceof Date||e instanceof Promise||(Ni(e)||Pi(e))&&Object.isFrozen(e);function wa(e,t={}){let{shallow:n}=Object.assign({},_a,t),r=new Proxy(e,{get(r,i,a){let o=Reflect.get(r,i,a);return Ca(o)?o:(xa(e),Sa(e,i),!n&&(Pi(o)||Ni(o))&&!ma.has(o)?fa.has(o)?fa.get(o):wa(o,t):o)},set(e,t,n,r){let i=Reflect.get(e,t,r),a=Reflect.set(e,t,n,r);return(!Ni(e)&&i!==n||t===`length`)&&(Fa(e,t),Ra(e,t)),a},deleteProperty(e,t){let n=Reflect.deleteProperty(e,t);return Fa(e,t),Ra(e,t),n}});return fa.set(e,r),ma.set(r,e),r}function Ta(e){return(ha.get(e)??ha.set(e,Ii()).get(e)).asReadonly()}var Ea=[],Da=new Map,Oa=new Map,ka=!0;function Aa(e,t,n){let r=ga.get(n);if(!r)return!1;let i=r.get(e);return i?i.has(t):!1}var ja=e=>t=>{let n=Da.get(t),r=()=>{},i=n?.promise?n.promise:new Promise(e=>{r=e});if(!n){let n={type:e,promise:i,fn:t,resolve:()=>{r()}};Ea.push(n),Da.set(t,n)}return ka&&=(Si(La),!1),i},Ma=ja(`observer`),Na=ja(`nextTick`);function Pa(e){let t=Da.get(e);if(!t)return;let n=Ea.indexOf(t);n===-1||Ea.splice(n,1),Da.delete(e),t.resolve()}var Fa=(e,t)=>pa.get(e)?.forEach(n=>Aa(e,t,n)&&Ma(n));function Ia(){let e=Ea.shift();if(e){if(Da.delete(e.fn),e.type===`observer`)ba(e.fn),ya(e.fn),e.resolve();else if(e.type===`nextTick`){let t=xi(e.fn);t instanceof Promise?t.finally(e.resolve):e.resolve()}}}function La(){for(;Ea.length;)Ia();ka=!0}function Ra(e,t){let n=fa.get(e);if(!n)return;let r=ha.get(n);if(!r)return;let i=Oa.get(n);i?i.has(t)||i.add(t):(Oa.set(n,new Set([t])),Na(()=>{let e=Oa.get(n);e&&(Oa.delete(n),e.forEach(e=>r.next(e)))}))}function za(e,t){let n=wa({value:t.value},{shallow:!0}),r=e=>{n.value=e},i=()=>e instanceof HTMLElement?e:e.parentElement??e.host,a=()=>{i().dispatchEvent(vi({context:t,observer:r}))};return a(),na(a),ia(()=>{i().dispatchEvent(yi({context:t,observer:r}))}),n}function Ba(e,t,n){let r=e instanceof HTMLElement?e:e.parentElement??e.host,i=Ii(),a=new Map,o=e=>{let r=e;r.detail?.context?.key===t.key&&(r.stopPropagation(),r.detail.observer(n),a.set(r.detail.observer,i.subscribe(r.detail.observer)))},s=e=>{let n=e;n.detail?.context?.key===t.key&&(n.stopPropagation(),a.get(n.detail.observer)?.(),a.delete(n.detail.observer))};return r.addEventListener(vi.type,o),r.addEventListener(yi.type,s),{set:e=>{i.next(e)},destroy:()=>{r.removeEventListener(vi.type,o),r.removeEventListener(yi.type,s);for(let e of a.values())e();a.clear()}}}var Va=function(e){return e.node=`node`,e.attribute=`attribute`,e}({});function Ha(e,t){return Reflect.set(t,Zi,e),t}function Ua(e,t,n){let r={startNode:e,endNode:t};return Reflect.defineProperty(r,"helper",{value:n}),r}function Wa(e,t){return(...n)=>Ha(Va.node,[e(...n),t])}var Ga=function(e){return e.html=`html`,e.svg=`svg`,e.css=`css`,e}({}),Ka=new Set(Object.values(Ga)),qa=Symbol.for(`https://github.com/dineug/r-html#CSSSource`),Ja=new WeakMap,Ya=new WeakMap,Xa=new Set([Ga.svg]),Za=e=>`${Ri}_${e}_`,Qa=e=>Ni(e)&&Ni(e.raw),$a=e=>Pi(e)&&Qa(e.strings)&&Ni(e.values)&&Ka.has(Reflect.get(e,Qi)??``),eo=e=>$a(e)&&e[Qi]===Ga.css,to=(e,t=!0,n=!1)=>r=>t?!!r?.trimStart().startsWith(e):n?!!r?.trimEnd().endsWith(e):new RegExp(e).test(r??``),no=to(zi),ro=to(`.`),io=to(`?`),ao=to(`@`),oo=to(`on`),so=to(Ri,!1),co=e=>so(e)&&Vi.test(e?.trim()??``),lo=({type:e,value:t})=>e===S.spread||e===S.directive||so(t),uo=e=>Xa.has(e),fo=e=>co(e)?S.directive:no(e)?S.spread:ro(e)?S.property:ao(e)||oo(e)?S.event:io(e)?S.boolean:S.attribute,po=e=>no(e)?e.substring(3):co(e)?e:ro(e)||ao(e)||io(e)?e.substring(1):oo(e)?e.substring(2):e;function mo(e){let t=[],n=Bi.exec(e);for(;n;){let r=Number(n[1]);t.push([n[0],Number.isInteger(r)?r:-1]),n=Bi.exec(e)}return t}var ho=Symbol(`https://github.com/dineug/r-html.git#hostBridge`);function go(e,t){if(t instanceof ShadowRoot){let n=t.host;Reflect.set(e,ho,n)}return()=>{Reflect.deleteProperty(e,ho)}}function _o(e){return Reflect.get(e,ho)??null}function vo(e){return Fi(e)&&!Mi(e)&&!ji(e)||eo(e)?String(e):``}var yo={createElement:(e,t=!1)=>t?document.createElementNS(`http://www.w3.org/2000/svg`,e):document.createElement(e),createText:e=>document.createTextNode(e),createMarker:e=>document.createComment(e),createFragment:()=>document.createDocumentFragment(),createEventBus:()=>document.createElement(`div`),insertBefore(e,t){let n=t.parentNode;n&&n.insertBefore(e,t)},appendChild(e,t){e.appendChild(t)},prependChild(e,t){e.prepend(t)},removeChild(e){e.parentNode?.removeChild(e)},parentOf:e=>e.parentNode,nextSiblingOf:e=>e.nextSibling,setText(e,t){e.data=t},setAttribute(e,t,n,r){e.setAttribute(t,r?vo(n).trim():n)},removeAttribute(e,t){e.removeAttribute(t)},isHostNode:e=>e instanceof Node,isMarker:e=>e instanceof Comment,isText:e=>e instanceof Text,isElement:e=>e instanceof Element,isFragment:e=>e instanceof DocumentFragment,addEventListener(e,t,n,r){e.addEventListener(t,n,r)},removeEventListener(e,t,n,r){e.removeEventListener(t,n,r)},getRoot:e=>e.getRootNode(),createComponentContext(e,t){let n={host:document.body,get parentElement(){return e.parentElement},dispatchEvent:e=>t.dispatchEvent(e)},r=e.getRootNode();if(r instanceof ShadowRoot)n.host=r.host;else if(r instanceof DocumentFragment){let e=_o(r);e&&(n.host=e)}return n},bridgeFragment(e,t){let n=bi(e,t),r=go(e,t);return()=>{n(),r()}}};function bo(e){"@babel/helpers - typeof";return bo=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},bo(e)}function xo(e,t){if(bo(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(bo(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function So(e){var t=xo(e,`string`);return bo(t)==`symbol`?t:t+``}function Co(e,t,n){return(t=So(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var wo,To=function(e){return e.element=`element`,e.text=`text`,e.comment=`comment`,e}({});wo=Symbol.iterator;var Eo=class{constructor(e={}){Co(this,`type`,`comment`),Co(this,`value`,``),Co(this,`attrs`,void 0),Co(this,`parent`,null),Co(this,`children`,void 0),Object.assign(this,e)}*iterParent(){yield this,this.parent&&(yield*this.parent.iterParent())}*[wo](){if(yield this,this.children)for(let e of this.children)yield*e}},Do=e=>!!e&&e!==`false`;function Oo(e){let t=({type:t,value:n},r=!1)=>t===To.element?e.createElement(n,r):t===To.text?e.createText(n):e.createMarker(n),n=(t,{type:n,name:r,value:i})=>{switch(n){case S.attribute:e.setAttribute(t,r,i??``,!1);break;case S.boolean:Do(i)&&e.setAttribute(t,r,``,!1);break;case S.property:Reflect.set(t,r,i,t)}},r=(t,n)=>{e.insertBefore(t,n)},i=(t,n)=>{let r=e.parentOf(n);if(!r)return;let i=e.nextSiblingOf(n);i?e.insertBefore(t,i):e.appendChild(r,t)},a=t=>e.parentOf(t)?(e.removeChild(t),t):null,o=(t,n)=>{let r=[],i=e.nextSiblingOf(t);for(;i&&i!==n;)r.push(i),i=e.nextSiblingOf(i);return r},s=(e,t)=>{o(e,t).forEach(a)};return{...e,createNode:t,setAttr:n,insertBeforeNode:r,insertAfterNode:i,removeNode:a,rangeNodes:o,removeRange:s}}var E=Oo(yo);E.setAttr,E.insertBeforeNode,E.insertAfterNode,E.removeNode,E.rangeNodes,E.removeRange;var ko=E.isHostNode;function Ao(e,{type:t,name:n,value:r}){switch(t){case S.attribute:case S.property:Reflect.set(e,n,r);break;case S.boolean:Reflect.set(e,n,Do(r))}}var jo=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function Mo(e,t){if(e===t)return!0;let n=Pi(e)?e:{},r=Pi(t)?t:{},i=Object.keys(n),a=Object.keys(r);return i.length===a.length&&a.every(e=>Reflect.get(n,e)===Reflect.get(r,e))}var No=e=>Ni(e)&&Di(e[0])&&(ji(e[1])||Ei(e[1])||Pi(e[1])),Po=()=>{},Fo=e=>e instanceof HTMLElement,Io=e=>e instanceof SVGElement,Lo=e=>e instanceof Promise,Ro=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,Ho=new WeakMap,Uo=new WeakMap,Wo=new WeakMap,Go=new WeakMap,Ko=new WeakMap,qo=class{constructor(e,{name:t,value:n},r=E){C(this,Ro,void 0),C(this,zo,void 0),C(this,Bo,void 0),C(this,Vo,void 0),C(this,Ho,[]),C(this,Uo,[]),C(this,Wo,void 0),C(this,Go,null),C(this,Ko,null),w(Ro,this,r),w(zo,this,e),w(Bo,this,t),w(Vo,this,n),w(Ho,this,mo(n??``)),w(Wo,this,T(Ho,this).length===1&&(n??``).trim()===T(Ho,this)[0][0])}commit(e){let t=T(Ho,this).map(([t,n])=>e[n]);if(jo(T(Uo,this),t))return;let n=t[t.length-1];if(T(Bo,this)===`class`)this.classCommit(n);else if(T(Bo,this)===`style`)this.styleCommit(n);else if(T(Wo,this))T(Ro,this).setAttribute(T(zo,this),T(Bo,this),t[0],!0);else{let e=t.reduce((e,t,n)=>e.replace(new RegExp(T(Ho,this)[n][0]),vo(t)),T(Vo,this)??``);T(Ro,this).setAttribute(T(zo,this),T(Bo,this),e.trim(),!1)}w(Uo,this,t)}classCommit(e){let t=T(zo,this);if(!Fo(t)&&!Io(t))return;let n=T(Uo,this)[T(Uo,this).length-1];if(n===e||Ni(n)&&Ni(e)&&jo(n,e)||Pi(n)&&Pi(e)&&Mo(n,e))return;let r=[...t.classList],i=Yo(e);if(Mi(T(Ko,this)))w(Ko,this,r);else{let e=T(Ko,this),n=r.filter(t=>!e.includes(t)&&!i.includes(t));t.classList.remove(...n)}t.classList.add(...i)}styleCommit(e){let t=T(zo,this);if(!Fo(t)&&!Io(t))return;let n=T(Uo,this)[T(Uo,this).length-1];if(Mo(n,e))return;let r=Jo(t),i=Pi(e)?e:{};if(Mi(T(Go,this)))w(Go,this,r);else{let e=T(Go,this);Object.keys(r).filter(t=>!e[t]&&!i[t]).forEach(e=>t.style.removeProperty(e))}for(let e of Object.keys(i))t.style.setProperty(e,i[e])}};function Jo(e){let t={};for(let n=0;n<e.style.length;n++){let r=e.style.item(n);t[r]=e.style.getPropertyValue(r)}return t}function Yo(e,t=[]){if(!e)return t;if(eo(e))return t.push(vo(e)),t;if(Fi(e))t.push(vo(e));else if(wi(e)){if(Ni(e))for(let n=0;n<e.length;n++)e[n]&&Yo(e[n],t);else for(let n in e)e[n]&&t.push(vo(n))}return t}var Xo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap,$o=new WeakMap,es=new WeakMap,ts=class{constructor(e,{name:t,value:n},r=E){C(this,Xo,void 0),C(this,Zo,void 0),C(this,Qo,void 0),C(this,$o,[]),C(this,es,[]),w(Xo,this,r),w(Zo,this,e),w(Qo,this,t),w($o,this,mo(n??``))}commit(e){let t=T($o,this).map(([t,n])=>e[n]);if(jo(T(es,this),t))return;let n=t[t.length-1];Do(n)?T(Xo,this).setAttribute(T(Zo,this),T(Qo,this),``,!1):T(Xo,this).removeAttribute(T(Zo,this),T(Qo,this)),w(es,this,t)}},ns=e=>Ni(e)&&Reflect.get(e,Zi)===Va.attribute,rs=new WeakMap,is=new WeakMap,as=new WeakMap,os=new WeakMap,ss=new WeakMap,cs=class{constructor(e,{name:t}){C(this,rs,void 0),C(this,is,void 0),C(this,as,null),C(this,os,null),C(this,ss,null),w(rs,this,e),w(is,this,mo(t)[0])}commit(e){let[,t]=T(is,this),n=e[t];if(!ns(n))return;let[r,i]=n;if(T(as,this)!==i)T(ss,this)?.call(this),w(os,this,i({node:T(rs,this)})),w(as,this,i),w(ss,this,T(os,this)?.call(this,r));else{let e=T(os,this)?.call(this,r);T(ss,this)!==e&&(T(ss,this)?.call(this),w(ss,this,e))}}destroy(){T(ss,this)?.call(this)}},ls=new WeakMap,us=new WeakMap,ds=new WeakMap,fs=new WeakMap,ps=new WeakMap,ms=class{constructor(e,{name:t,value:n},r=E){C(this,ls,void 0),C(this,us,void 0),C(this,ds,void 0),C(this,fs,[]),C(this,ps,[]),w(ls,this,r),w(us,this,e),w(ds,this,t),w(fs,this,mo(n??``))}commit(e){let t=T(fs,this).map(([t,n])=>e[n]).filter(e=>Di(e)||No(e));jo(T(ps,this),t)||(this.clear(),t.forEach(e=>{let[t,n]=hs(e);T(ls,this).addEventListener(T(us,this),T(ds,this),t,n)}),w(ps,this,t))}clear(){T(ps,this).forEach(e=>{let[t,n]=hs(e);T(ls,this).removeEventListener(T(us,this),T(ds,this),t,n)})}destroy(){this.clear()}};function hs(e){return Di(e)?[e,void 0]:e}var gs=new WeakMap,_s=new WeakMap,vs=new WeakMap,ys=new WeakMap,bs=class{constructor(e,{name:t,value:n}){C(this,gs,void 0),C(this,_s,void 0),C(this,vs,[]),C(this,ys,[]),w(gs,this,e),w(_s,this,t),w(vs,this,mo(n??``))}commit(e){let t=T(vs,this).map(([t,n])=>e[n]);if(jo(T(ys,this),t))return;let n=t[t.length-1];Reflect.set(T(gs,this),T(_s,this),n,T(gs,this)),w(ys,this,t)}},xs=new WeakMap,Ss=new WeakMap,Cs=new WeakMap,ws=class{constructor(e,{name:t}){C(this,xs,void 0),C(this,Ss,void 0),C(this,Cs,null),w(xs,this,e),w(Ss,this,mo(t)[0])}commit(e){let[,t]=T(Ss,this),n=e[t];!Pi(n)||Mo(T(Cs,this),n)||(Object.keys(n).forEach(e=>Reflect.set(T(xs,this),e,n[e],T(xs,this))),w(Cs,this,n))}},Ts=(e,t,n=E)=>t.type===S.attribute?new qo(e,t,n):t.type===S.boolean?new ts(e,t,n):t.type===S.event?new ms(e,t,n):t.type===S.property?new bs(e,t):t.type===S.spread?new ws(e,t):new cs(e,t),Es=new WeakMap,Ds=new WeakMap,Os=new WeakMap,ks=new WeakMap,As=new WeakMap,js=class{constructor(e,{value:t},n=E){C(this,Es,void 0),C(this,Ds,void 0),C(this,Os,void 0),C(this,ks,[]),C(this,As,[]),w(Es,this,n),w(Ds,this,e),w(Os,this,t),ki(t)&&w(ks,this,mo(t))}commit(e){let t=T(ks,this).map(([t,n])=>e[n]);if(jo(T(As,this),t))return;w(As,this,t);let n=T(As,this).reduce((e,t,n)=>e.replace(new RegExp(T(ks,this)[n][0]),Fi(t)&&!Mi(t)&&!ji(t)?String(t):``),T(Os,this)??``);T(Es,this).setText(T(Ds,this),n)}},Ms=new WeakMap,Ns=new WeakMap,Ps=new WeakMap,Fs=new WeakMap,Is=class{constructor(e,{name:t,value:n}){C(this,Ms,void 0),C(this,Ns,void 0),C(this,Ps,[]),C(this,Fs,[]),w(Ms,this,e),w(Ns,this,t),w(Ps,this,mo(n??``))}commit(e){let t=T(Ps,this).map(([t,n])=>e[n]);if(jo(T(Fs,this),t))return;let n=t[t.length-1];Reflect.set(T(Ms,this),T(Ns,this),n),w(Fs,this,t)}},Ls=function(e){return e.create=`create`,e.move=`move`,e}({});function Rs(e){let t=[],n=new Map;return e.forEach(({type:e,value:r},i)=>{let a={type:e,key:e===wc.templateLiterals?r.strings:r};t.push(a),n.set(a,i)}),{items:t,itemToIndex:n}}function zs(e){let t=[],n=new Map;return e.forEach((e,r)=>{let i=Pc(e),a={type:i,key:i===wc.templateLiterals?e.strings:e};t.push(a),n.set(a,r)}),{items:t,itemToIndex:n}}function Bs(e,t,n){let r=!!n?.strict,i={update:[],delete:[]},a=new Set,o=[],s=e.items,c=t.items;return s.forEach((e,t)=>{let n=c.findIndex((t,n)=>e.type===t.type&&e.key===t.key&&!a.has(n));n===-1?r?i.delete.push({from:t}):o.push(e):(a.add(n),i.update.push({action:`move`,from:t,to:n}))}),o.forEach(n=>{let r=e.itemToIndex.get(n),o=c.find((e,t)=>n.type===e.type&&!a.has(t));if(o){let e=t.itemToIndex.get(o);a.add(e),i.update.push({action:`move`,from:r,to:e})}else i.delete.push({from:r})}),c.forEach((e,n)=>{a.has(n)||i.update.push({action:`create`,from:-1,to:t.itemToIndex.get(e)})}),i.update.sort((e,t)=>e.to-t.to),i}var Vs=new WeakMap,Hs=new WeakMap,Us=new WeakMap,Ws=new WeakMap,Gs=class{constructor(e,t,n=E){C(this,Vs,void 0),C(this,Hs,void 0),C(this,Us,void 0),C(this,Ws,[]),w(Hs,this,e),w(Us,this,t),w(Vs,this,n)}commit(e){let t=Bs(Rs(T(Ws,this)),zs(e)),n={length:e.length};t.update.forEach(({action:t,from:r,to:i})=>{switch(t){case Ls.create:let t=T(Vs,this).createMarker(``);i===0?T(Vs,this).insertAfterNode(t,T(Hs,this)):T(Ws,this).length?T(Vs,this).insertAfterNode(t,n[i-1]?n[i-1].endNode:T(Ws,this)[i-1].endNode):T(Vs,this).insertBeforeNode(t,T(Us,this)),n[i]=new Js(t,e[i],T(Vs,this));break;case Ls.move:if(n[i]=T(Ws,this)[r],i===r)return;i===0?T(Ws,this)[r].insert(`after`,T(Hs,this)):T(Ws,this)[r].insert(`after`,n[i-1]?n[i-1].endNode:T(Ws,this)[i-1].endNode)}}),t.delete.forEach(({from:e})=>T(Ws,this)[e].destroy()),w(Ws,this,Array.from(n)),T(Ws,this).forEach((t,n)=>t.commit(e[n]))}destroy(){T(Ws,this).forEach(e=>e.destroy())}},Ks=new WeakMap,qs=new WeakMap,Js=class{constructor(e,t,n=E){C(this,Ks,void 0),C(this,qs,void 0),Co(this,`startNode`,void 0),Co(this,`endNode`,void 0),Co(this,`type`,void 0),Co(this,`value`,void 0),w(qs,this,n),this.startNode=n.createMarker(``),this.endNode=n.createMarker(``),n.insertBeforeNode(this.startNode,e),n.insertAfterNode(this.endNode,e),n.removeNode(e),this.value=t,this.type=Pc(t),w(Ks,this,Rc(this.type,this.startNode,this.endNode,n))}commit(e){T(Ks,this).commit(e),this.value=e}insert(e,t){let n=[this.startNode,...T(qs,this).rangeNodes(this.startNode,this.endNode),this.endNode];e===`before`?n.forEach(e=>T(qs,this).insertBeforeNode(e,t)):n.reverse().forEach(e=>T(qs,this).insertAfterNode(e,t))}destroy(){T(Ks,this).destroy?.(),T(qs,this).removeRange(this.startNode,this.endNode),T(qs,this).removeNode(this.startNode),T(qs,this).removeNode(this.endNode)}},Ys=new WeakMap,Xs=new WeakMap,Zs=new WeakMap,Qs=new WeakMap,$s=new WeakMap,ec=new WeakMap,tc=class{constructor(e,t,n=E){C(this,Ys,void 0),C(this,Xs,void 0),C(this,Zs,void 0),C(this,Qs,null),C(this,$s,null),C(this,ec,void 0),w(Xs,this,e),w(Zs,this,t),w(Ys,this,n)}commit(e){if(!Tc(e))return;let[t,n]=e;if(T(Qs,this)!==n)this.clear(),w($s,this,n(Ua(T(Xs,this),T(Zs,this),T(Ys,this)))),w(Qs,this,n),w(ec,this,T($s,this)?.call(this,t));else{let e=T($s,this)?.call(this,t);T(ec,this)!==e&&(this.clear(),w(ec,this,e))}}clear(){T(ec,this)?.call(this),T(Ys,this).removeRange(T(Xs,this),T(Zs,this))}destroy(){this.clear()}},nc=class{constructor(e,t){}commit(e){}},rc=new WeakMap,ic=new WeakMap,ac=new WeakMap,oc=class{constructor(e,t,n=E){C(this,rc,void 0),C(this,ic,void 0),C(this,ac,null),w(ic,this,t),w(rc,this,n)}commit(e){T(ac,this)!==e&&(T(ac,this)&&T(rc,this).removeNode(T(ac,this)),T(rc,this).insertBeforeNode(e,T(ic,this)),w(ac,this,e))}},sc=new WeakMap,cc=new WeakMap,lc=new WeakMap,uc=new WeakMap,dc=new WeakMap,fc=new WeakMap,pc=class{constructor(e,t,n=E){C(this,sc,void 0),C(this,cc,void 0),C(this,lc,void 0),C(this,uc,null),C(this,dc,null),C(this,fc,Po),w(cc,this,e),w(lc,this,t),w(sc,this,n)}commit(e){T(uc,this)!==e&&(this.clear(),Lo(e)&&this.promiseCommit(e))}promiseCommit(e){let[t,n]=mc(e);w(fc,this,n),t.then(e=>{let t=Pc(e);w(dc,this,Rc(t,T(cc,this),T(lc,this),T(sc,this))),T(dc,this)?.commit(e)}),w(uc,this,e)}partClear(){T(dc,this)?.destroy?.(),T(sc,this).removeRange(T(cc,this),T(lc,this))}clear(){T(fc,this).call(this),this.partClear(),w(fc,this,Po)}destroy(){this.clear()}};function mc(e){let t=Po,n=new Promise((e,n)=>t=n);return[Promise.race([n,e]),()=>t()]}var hc=new WeakMap,gc=new WeakMap,_c=new WeakMap,vc=class{constructor(e,t,n=E){C(this,hc,void 0),C(this,gc,void 0),C(this,_c,null),w(hc,this,n),w(gc,this,n.createText(``)),n.insertAfterNode(T(gc,this),e)}commit(e){T(_c,this)!==e&&(T(hc,this).setText(T(gc,this),Mi(e)||ji(e)?``:String(e)),w(_c,this,e))}},yc=new WeakMap,bc=new WeakMap,xc=new WeakMap,Sc=new WeakMap,Cc=class{constructor(e,t,n=E){C(this,yc,void 0),C(this,bc,void 0),C(this,xc,void 0),C(this,Sc,null),w(bc,this,e),w(xc,this,t),w(yc,this,n)}commit(e){let{strings:t,values:n}=e;T(Sc,this)&&!T(Sc,this).equalStrings(t)&&(T(Sc,this).destroy(),w(Sc,this,null)),T(Sc,this)||(w(Sc,this,new yl(e,T(bc,this),T(xc,this),T(yc,this))),T(Sc,this).insert(`before`,T(xc,this))),T(Sc,this).commit(n)}destroy(){T(Sc,this)?.destroy()}},wc=function(e){return e.primitive=`primitive`,e.templateLiterals=`templateLiterals`,e.array=`array`,e.node=`node`,e.object=`object`,e.function=`function`,e.directive=`directive`,e}({}),Tc=e=>Ni(e)&&Reflect.get(e,Zi)===Va.node,Ec=e=>t=>t instanceof e,Dc=Ec(vc),Oc=Ec(Cc),kc=Ec(Gs),Ac=Ec(oc),jc=Ec(pc),Mc=Ec(nc),Nc=Ec(tc),Pc=e=>Fi(e)?`primitive`:$a(e)?`templateLiterals`:Tc(e)?`directive`:Ni(e)?`array`:ko(e)?`node`:Di(e)?`function`:`object`,Fc={primitive:Dc,templateLiterals:Oc,array:kc,node:Ac,function:Mc,object:jc,directive:Nc},Ic={primitive:vc,templateLiterals:Cc,array:Gs,node:oc,function:nc,object:pc,directive:tc},Lc=(e,t)=>Fc[e](t),Rc=(e,t,n,r=E)=>new Ic[e](t,n,r),zc=new WeakMap,Bc=new WeakMap,Vc=new WeakMap,Hc=new WeakMap,Uc=new WeakMap,Wc=new WeakMap,Gc=new WeakMap,Kc=new WeakMap,qc=new WeakMap,Jc=new WeakMap,Yc=new WeakMap,Xc=new WeakMap,Zc=class{constructor(e,t,n,r,i=E){C(this,zc,void 0),C(this,Bc,void 0),C(this,Vc,void 0),C(this,Hc,void 0),C(this,Uc,void 0),C(this,Wc,[]),C(this,Gc,[]),C(this,Kc,null),C(this,qc,wa({},{shallow:!0})),C(this,Jc,null),C(this,Yc,null),C(this,Xc,void 0),w(zc,this,i),w(Xc,this,i.createEventBus()),w(Bc,this,e),w(Vc,this,t),w(Uc,this,n),w(Hc,this,mo(n.value)[0]),n.staticAttrs&&n.staticAttrs.forEach(e=>Ao(T(qc,this),e)),n.attrs?.forEach(e=>{e.type===S.directive?T(Wc,this).push(e):e.type===S.spread?r.push(new ws(T(qc,this),e)):e.type===S.event?r.push(new ms(T(Xc,this),e,i)):r.push(new Is(T(qc,this),e))})}createContext(){return T(zc,this).createComponentContext(T(Bc,this),T(Xc,this))}commit(e){let[,t]=T(Hc,this),n=e[t];if(!Di(n)||T(Jc,this)===n){T(Gc,this).forEach(t=>t.commit(e));return}let r=this.createContext();this.clear(),ea(this);let i=n.call(r,T(qc,this),r);ea(null),T(Wc,this).length&&T(Gc,this).push(...T(Wc,this).map(e=>new cs(r,e))),aa(this,Ui);let a=!1;w(Yc,this,ya(()=>{let e=i(),t=Pc(e);Lc(t,T(Kc,this))||(this.partClear(),w(Kc,this,Rc(t,T(Bc,this),T(Vc,this),T(zc,this)))),aa(this,a?qi:Ki),T(Kc,this)?.commit(e),a?aa(this,Yi):(aa(this,Ji),a=!0)})),T(Gc,this).forEach(t=>t.commit(e)),aa(this,Wi),w(Jc,this,n)}partClear(){T(Kc,this)?.destroy?.(),T(zc,this).removeRange(T(Bc,this),T(Vc,this))}clear(){T(zc,this).removeRange(T(Bc,this),T(Vc,this)),aa(this,Gi),T(Gc,this).forEach(e=>e.destroy?.()),T(Yc,this)?.call(this),w(Gc,this,[]),w(Yc,this,null),oa(this)}destroy(){this.clear(),this.partClear()}},Qc,$c,el,tl,nl=da((Qc=new WeakMap,$c=new WeakMap,el=new WeakMap,tl=new WeakMap,class{constructor(e,t,n,r=E){C(this,Qc,void 0),C(this,$c,void 0),C(this,el,void 0),C(this,tl,void 0),w(Qc,this,r),w($c,this,r.createMarker(``)),w(el,this,r.createMarker(``)),w(tl,this,new Zc(T($c,this),T(el,this),t,n,r)),r.insertBeforeNode(T($c,this),e),r.insertAfterNode(T(el,this),e),r.removeNode(e)}commit(e){T(tl,this).commit(e)}destroy(){T(tl,this).destroy?.(),T(Qc,this).removeNode(T($c,this)),T(Qc,this).removeNode(T(el,this))}})),rl=new WeakMap,il=new WeakMap,al=new WeakMap,ol=new WeakMap,sl=new WeakMap,cl=new WeakMap,ll=class{constructor(e,{value:t},n=E){C(this,rl,void 0),C(this,il,void 0),C(this,al,void 0),C(this,ol,void 0),C(this,sl,null),C(this,cl,null),w(rl,this,n),w(il,this,n.createMarker(``)),w(al,this,n.createMarker(``)),w(ol,this,mo(t)[0]),n.insertBeforeNode(T(il,this),e),n.insertAfterNode(T(al,this),e),n.removeNode(e)}commit(e){let[,t]=T(ol,this),n=e[t];if(T(sl,this)===n)return;let r=Pc(n);Lc(r,T(cl,this))||(Mi(T(cl,this))||this.clear(),w(cl,this,Rc(r,T(il,this),T(al,this),T(rl,this)))),T(cl,this)?.commit(n),w(sl,this,n)}clear(){T(cl,this)?.destroy?.(),T(rl,this).removeRange(T(il,this),T(al,this))}destroy(){this.clear(),T(rl,this).removeNode(T(il,this)),T(rl,this).removeNode(T(al,this))}};function ul(e=[],t,n=!1,r=[],i=E){return e.forEach(e=>{if(e.isComponent){let n=i.createMarker(``);i.appendChild(t,n),r.push(new nl(n,e,r,i));return}let a=i.createNode(e,e.isSvg||n);i.appendChild(t,a),i.isMarker(a)&&e.isMarker&&r.push(new js(a,e,i)),i.isText(a)&&e.isMarkerOnly&&r.push(new ll(a,e,i)),i.isElement(a)&&(e.staticAttrs&&e.staticAttrs.forEach(e=>i.setAttr(a,e)),e.attrs&&r.push(...e.attrs.map(e=>Ts(a,e,i))),e.children&&ul(e.children,a,e.isSvg||n,r,i))}),r}function dl(e,t=!1,n=E){let r=n.createFragment();return[r,ul(e.children,r,t,[],n)]}var fl=new WeakMap,pl=new WeakMap,ml=new WeakMap,hl=new WeakMap,gl=new WeakMap,_l=new WeakMap,vl=new WeakMap,yl=class{constructor(e,t,n,r=E){if(C(this,fl,void 0),C(this,pl,void 0),C(this,ml,void 0),C(this,hl,null),C(this,gl,[]),C(this,_l,void 0),C(this,vl,!1),w(fl,this,r),w(pl,this,r.createMarker(``)),w(ml,this,r.createMarker(``)),w(_l,this,e.strings),e[Qi]!==Ga.html&&e[Qi]!==Ga.svg)return;let[i,a]=dl(e.template.node,uo(e[Qi]),r);w(hl,this,i),w(gl,this,a),t&&n?(w(pl,this,t),w(ml,this,n),w(vl,this,!0)):(r.prependChild(i,T(pl,this)),r.appendChild(i,T(ml,this)))}equalStrings(e){return T(_l,this)===e}commit(e){T(gl,this).forEach(t=>t.commit(e))}insert(e,t){T(hl,this)&&(e===`before`?T(fl,this).insertBeforeNode(T(hl,this),t):e===`after`?T(fl,this).insertAfterNode(T(hl,this),t):T(fl,this).appendChild(t,T(hl,this)),w(hl,this,null))}destroy(){T(gl,this).forEach(e=>e.destroy?.()),T(fl,this).removeRange(T(pl,this),T(ml,this)),T(vl,this)||(T(fl,this).removeNode(T(pl,this)),T(fl,this).removeNode(T(ml,this)))}},bl=function(e){return e.string=`string`,e.whiteSpace=`whiteSpace`,e.lt=`lt`,e.gt=`gt`,e.slash=`slash`,e.equal=`equal`,e}({}),xl={doubleQuote:`"`,singleQuote:`'`,whiteSpace:/\s/,string:/\S/,breakString:/<|>|=/,lt:`<`,gt:`>`,slash:`/`,equal:`=`,hyphen:`-`,exclamationPoint:`!`},Sl=e=>t=>e===t,Cl=e=>t=>e.test(t),wl={doubleQuote:Sl(xl.doubleQuote),singleQuote:Sl(xl.singleQuote),whiteSpace:Cl(xl.whiteSpace),string:Cl(xl.string),breakString:Cl(xl.breakString),lt:Sl(xl.lt),gt:Sl(xl.gt),slash:Sl(xl.slash),equal:Sl(xl.equal),hyphen:Sl(xl.hyphen),exclamationPoint:Sl(xl.exclamationPoint)},Tl=e=>t=>wl.lt(e[t])&&wl.exclamationPoint(e[t+1])&&wl.hyphen(e[t+2])&&wl.hyphen(e[t+3]);function El(e){let t=[],n=0,r=()=>n<e.length,i=Tl(e),a=(o=`text`)=>{for(;r();){let s=e[n];if(wl.whiteSpace(s)){let i=``;for(;r()&&wl.whiteSpace(s);)i+=s,s=e[++n];o!==`element`&&t.push({type:`whiteSpace`,value:i});continue}if(o===`element`){if(wl.lt(s)){t.push({type:`lt`,value:s}),n++;continue}if(wl.gt(s)){t.push({type:`gt`,value:s}),n++;break}if(wl.slash(s)){t.push({type:`slash`,value:s}),n++;continue}if(wl.equal(s)){t.push({type:`equal`,value:s}),n++;continue}if(wl.doubleQuote(s)){let i=``;for(s=e[++n];r()&&!wl.doubleQuote(s);)i+=s,s=e[++n];t.push({type:`string`,value:i}),n++;continue}if(wl.singleQuote(s)){let i=``;for(s=e[++n];r()&&!wl.singleQuote(s);)i+=s,s=e[++n];t.push({type:`string`,value:i}),n++;continue}}else if(o===`comment`){if(wl.lt(s)){t.push({type:`lt`,value:s}),n++;continue}if(wl.gt(s)){t.push({type:`gt`,value:s}),n++;break}}else if(wl.lt(s)){a(i(n)?`comment`:`element`);continue}if(wl.string(s)){let i=``;for(;r()&&wl.string(s)&&!wl.breakString(s);)i+=s,s=e[++n];t.push({type:`string`,value:i});continue}n++}};return a(),t}var Dl=/^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i,Ol=e=>t=>n=>r=>n[r]?n[r][e]===t:!1,kl=Ol(`type`),Al=Ol(`value`),jl=kl(bl.lt),Ml=kl(bl.gt),Nl=kl(bl.slash),Pl=kl(bl.equal),Fl=kl(bl.string),Il=kl(bl.whiteSpace),Ll=Al(`!--`),Rl=Al(`--`),zl=e=>{let t=jl(e),n=Fl(e);return e=>t(e)&&n(e+1)},Bl=e=>{let t=jl(e),n=Nl(e),r=Fl(e),i=Ml(e);return e=>t(e)&&n(e+1)&&r(e+2)&&i(e+3)},Vl=e=>{let t=jl(e),n=Nl(e),r=Ml(e);return e=>t(e)&&n(e+1)&&n(e+2)&&r(e+3)},Hl=e=>{let t=Nl(e),n=Ml(e);return e=>t(e)&&n(e+1)},Ul=e=>Dl.test(e),Wl=e=>{let t=jl(e),n=Fl(e),r=Ll(e);return e=>t(e)&&n(e+1)&&r(e+1)},Gl=e=>{let t=Fl(e),n=Rl(e),r=Ml(e);return e=>t(e)&&n(e)&&r(e+1)},Kl=e=>t=>n=>{n&&(t[e]?t[e]?.push(n):t[e]=[n])},ql=Kl(`attrs`),Jl=Kl(`children`);function Yl(e){let t=new Eo({type:To.element,value:`template`,children:[]}),n=0,r=()=>n<e.length,i=zl(e),a=Bl(e),o=Vl(e),s=Hl(e),c=Wl(e),l=Gl(e),u=jl(e),d=Ml(e),f=Pl(e),p=Il(e),m=Fl(e),h=()=>{let t=e[n],r={name:t.value};return t=e[++n],f(n)&&(t=e[++n],m(n)&&(r.value=t.value,n++)),r},g=t=>{let f=e[n];if(p(n)||m(n)){let i=f.value;for(f=e[++n];r()&&!u(n);)i+=f.value,f=e[++n];return i=i.trim(),i.length?new Eo({parent:t,type:To.text,value:i}):null}if(c(n)){let i=``;for(n+=2,f=e[n];r()&&!l(n);)i+=f.value,f=e[++n];return l(n)&&(n+=2),new Eo({parent:t,type:To.comment,value:i})}if(i(n)){f=e[++n];let i=Ul(f.value),c=new Eo({parent:t,type:To.element,value:f.value.toLowerCase()});for(n++;r()&&!d(n)&&!s(n);){if(m(n)){ql(c)(h());continue}n++}if(s(n))return n+=2,c;for(f=e[++n];r()&&!a(n)&&!o(n)&&!i;)Jl(c)(g(c));return(a(n)||o(n))&&(n+=4),c}return n++,null};for(;r();)Jl(t)(g(t));return t}var Xl=e=>Yl(El(e)),Zl=(e,t)=>e.reduce((e,n)=>{let r=t(n),i=e[r];return i?i.push(n):e[r]=[n],e},Object.create(null)),Ql=Symbol.iterator,$l=class e{get isMarker(){return so(this.value)}get isMarkerOnly(){return co(this.value)}get isSvg(){return this.type===To.element&&/^svg$/i.test(this.value)}get isComponent(){return this.type===To.element&&this.isMarkerOnly}constructor(t,n=null){if(Co(this,`type`,To.comment),Co(this,`value`,``),Co(this,`staticAttrs`,void 0),Co(this,`attrs`,void 0),Co(this,`parent`,null),Co(this,`children`,void 0),this.type=t.type,this.value=t.value,this.parent=n,t.attrs){let[e,n]=nu(t.attrs);e.length&&(this.staticAttrs=e),n.length&&(this.attrs=n)}t.children&&(this.children=t.children.map(t=>new e(t,this)))}insert(e,t,n){if(this.children){let r=e===`before`?0:1;this.children.includes(n)&&this.children.splice(this.children.indexOf(n)+r,0,t)}else this.children=[t]}*iterParent(){yield this,this.parent&&(yield*this.parent.iterParent())}*[Ql](){if(yield this,this.children)for(let e of this.children)yield*e}};function eu(e){let t=new $l(e);for(let e of t)e.type===To.text&&!co(e.value)&&tu(e);return t}function tu(e){let t=mo(e.value);e.value.replace(Bi,Ri).split(Ri).reduce((n,r,i)=>(i<t.length?n.push(new $l(new Eo({type:To.text,value:r}),e.parent),new $l(new Eo({type:To.text,value:t[i][0]}),e.parent)):n.push(new $l(new Eo({type:To.text,value:r}),e.parent)),n),[]).filter(e=>e.value!==``&&!(!e.value.trim()&&Hi.test(e.value))).reverse().forEach((t,n,{length:r})=>n===r-1?e.value=t.value:e.parent&&e.parent.insert(`after`,t,e))}function nu(e=[]){let t=Zl(e,e=>po(e.name));return Object.keys(t).map(e=>t[e]).reduce((e,t)=>{let[n,r]=e,i=t[t.length-1],a=fo(i.name);if(a===S.event)r.push(...t.filter(e=>!!e.value).map(e=>({type:fo(e.name),name:po(e.name),value:e.value})));else if(a===S.attribute){let e=t.filter(e=>!!e.value).map(e=>e.value).join(` `),o={type:a,name:po(i.name)};e&&(o.value=e),lo(o)?r.push(o):n.push(o)}else{let e={type:a,name:po(i.name)};i.value&&(e.value=i.value),lo(e)?r.push(e):n.push(e)}return e},[[],[]])}var ru=e=>(t,...n)=>{let r={strings:t,values:n,[Qi]:e};if(Ja.has(t))return r.template=Ja.get(t),r;let i=eu(Xl(t.reduce((e,t,r)=>(r<n.length?e.push(t,Za(r)):e.push(t),e),[]).join(``)));return r.template=Object.freeze({node:i}),Ja.set(t,r.template),r},iu=ru(Ga.html),au=ru(Ga.svg);function ou(e){let t=Oo(e),n=new WeakMap;return{html:iu,svg:au,render:(e,r)=>{if(!$a(r)){n.has(e)&&(n.get(e)?.destroy(),n.delete(e));return}let{strings:i,values:a}=r,o=n.get(e);if(o?.equalStrings(i))o?.commit(a);else{let i=new yl(r,void 0,void 0,t);o?.destroy(),n.set(e,i),i.insert(`children`,e),i.commit(a)}}}}var su=Wa((e,t,n)=>(e.length,[e,t,n]),({startNode:e,endNode:t,helper:n=E})=>{let r=[],i=()=>{r.forEach(e=>e.destroy())};return([a,o,s])=>{let c=fu(a,o,s),l=c.values,u=Bs(du(r),c,{strict:!0}),d={length:l.length};return u.update.forEach(({action:i,from:a,to:o})=>{switch(i){case Ls.create:let i=n.createMarker(``);o===0?n.insertAfterNode(i,e):r.length?n.insertAfterNode(i,d[o-1]?d[o-1].endNode:r[o-1].endNode):n.insertBeforeNode(i,t),d[o]=new uu(i,l[o].value,l[o].key,n);break;case Ls.move:if(d[o]=r[a],o===a)return;o===0?r[a].insert(`after`,e):r[a].insert(`after`,d[o-1]?d[o-1].endNode:r[o-1].endNode)}}),u.delete.forEach(({from:e})=>r[e].destroy()),r=Array.from(d),r.forEach((e,t)=>e.commit(l[t].value)),i}}),cu=new WeakMap,lu=new WeakMap,uu=class{constructor(e,t,n,r=E){C(this,cu,void 0),C(this,lu,void 0),Co(this,`startNode`,void 0),Co(this,`endNode`,void 0),Co(this,`type`,void 0),Co(this,`key`,void 0),w(lu,this,r),this.startNode=r.createMarker(``),this.endNode=r.createMarker(``),r.insertBeforeNode(this.startNode,e),r.insertAfterNode(this.endNode,e),r.removeNode(e),this.key=n,this.type=Pc(t),w(cu,this,Rc(this.type,this.startNode,this.endNode,r))}commit(e){T(cu,this).commit(e)}insert(e,t){let n=[this.startNode,...T(lu,this).rangeNodes(this.startNode,this.endNode),this.endNode];e===`before`?n.forEach(e=>T(lu,this).insertBeforeNode(e,t)):n.reverse().forEach(e=>T(lu,this).insertAfterNode(e,t))}destroy(){T(cu,this).destroy?.(),T(lu,this).removeRange(this.startNode,this.endNode),T(lu,this).removeNode(this.startNode),T(lu,this).removeNode(this.endNode)}};function du(e){let t=[],n=new Map;return e.forEach(({type:e,key:r},i)=>{let a={type:e,key:r};t.push(a),n.set(a,i)}),{items:t,itemToIndex:n}}function fu(e,t,n){let r=[],i=new Map,a=[];return e.forEach((e,o,s)=>{let c={key:t(e),value:n(e,o,s)},l={type:Pc(c.value),key:c.key};a.push(c),r.push(l),i.set(l,o)}),{items:r,itemToIndex:i,values:a}}var pu={vCSSStyleSheetMap:new Map,hostContextMap:new Map,globalOrder:[],orderedSheets:null},mu=globalThis.ShadowRoot&&`adoptedStyleSheets`in Document.prototype&&`replace`in CSSStyleSheet.prototype,hu=null;function gu(){return hu===null&&(hu=_u()),hu}function _u(){try{let e=document.createElement(`div`).attachShadow({mode:`open`}),t=new CSSStyleSheet;return e.adoptedStyleSheets.push(t),e.adoptedStyleSheets.length===1&&e.adoptedStyleSheets[0]===t}catch{return!1}}function vu(){return pu}function yu(e){let t=vu(),{identifier:n,cssText:r,mode:i}=e;if(!r||t.vCSSStyleSheetMap.has(n))return n;let a=mu?new CSSStyleSheet:null,o=mu?null:document.createElement(`style`);a?a.replaceSync(r):o&&(o.textContent=r);let s={identifier:n,cssText:r,mode:i,sheet:a,styleElement:o};return t.vCSSStyleSheetMap.set(n,s),wu(s),n}function bu(e){let t=[],n=[];for(let r of e.vCSSStyleSheetMap.values())(r.mode===`global`?t:n).push(r);if(e.globalOrder.length>0){let n=({identifier:t})=>{let n=e.globalOrder.indexOf(t);return n===-1?e.globalOrder.length:n};t.sort((e,t)=>n(e)-n(t))}return[...t,...n]}function xu(e){return e.orderedSheets||=bu(e).map(({sheet:e})=>e).filter(Boolean),e.orderedSheets}function Su(e,t){e.adoptedStyleSheets=[...t]}function Cu(){let e=vu(),t=xu(e);e.hostContextMap.forEach((e,n)=>Su(n,t))}function wu(e){if(!mu){Tu();return}let t=vu(),{mode:n,sheet:r}=e,i=t.orderedSheets;if(!r||n===`global`||!i){t.orderedSheets=null,Cu();return}if(i.push(r),!gu()){Cu();return}t.hostContextMap.forEach((e,t)=>t.adoptedStyleSheets.push(r))}function Tu(){let e=vu(),t=bu(e);Array.from(e.hostContextMap).forEach(([e,{styleElements:n}])=>{t.forEach((r,i)=>{if(n.has(r)||!r.styleElement)return;let a=document.importNode(r.styleElement,!0),o=Eu(t,i+1,n);o?e.insertBefore(a,o):e.appendChild(a),n.set(r,a)})})}function Eu(e,t,n){for(let r=t;r<e.length;r++){let t=n.get(e[r]);if(t)return t}return null}function D(e){function t(t){return{type:e,payload:t}}return t.toString=()=>`${e}`,t.type=e,t}function*Du(e,t,n){for(let r of n)r?.[Symbol.iterator]?yield*Du(e,t,r):Di(r)?yield*Du(e,t,r(e,t)):yield r}var Ou=(e,t,n)=>[...Du(e,t,n)],ku=(...e)=>t=>e.reduce((e,t)=>t(e),t);function*Au(e){yield e}var ju=function*(e){for(let t of e)t.length&&(yield t)};function Mu({context:e,state:t,reducers:n,enableObservable:r=!0}){let i=r?wa(t):t,a=Ii(),o=Ii(),s=ku(ju),c=t=>{xi(Reflect.get(n,t.type,n),i,t,e)},l=(...t)=>{let n=Ou(i,e,t);a.next(n)},u=(...e)=>{Si(()=>l(...e))},d=a.subscribe(e=>{let t=s(Au(e));for(let e of t)o.next(e)}),f=o.subscribe(e=>e.forEach(c));return{context:e,state:i,dispatch:u,dispatchSync:l,subscribe:o.subscribe,pipe:(...e)=>(s=ku(...e,ju),()=>{s=ku(ju)}),destroy:()=>{d(),f()}}}var Nu=`__RHTML_CSS_DIAGNOSTICS__`,Pu=({line:e,column:t})=>e===void 0?``:` (${e}:${t??1})`,Fu=(e,t)=>{let n=`[r-html] ${t.mode===`global`?`css.global`:`css`} ${t.identifier}${Pu(e)} ${e.code}: ${e.message}`;e.severity===`error`?console.error(n):console.warn(n)},Iu;function Lu(){if(Iu!==void 0)return Iu;let e=Reflect.get(globalThis,Nu);return e?typeof e==`function`?e:Fu:null}function Ru(){return Lu()!==null}function zu(e,t){if(e.length===0)return;let n=Lu();if(n)for(let r of e)n(r,t)}var Bu=[``];function Vu(e){return{value:``,root:null,parent:null,type:o,props:e.slice(),children:[],line:1,column:1,length:0,return:``,siblings:[]}}function Hu(e,t={}){let n=t.rules??Bu,r=t.rules===void 0?null:Vu(n),i=s(e);return c(l(``,null,null,r??null,n,i,0,[0],i))}var Uu=`rhtml-scope`;function Wu(e,t){return e.split(Uu).join(t)}var Gu=/^(?::host\b|::slotted\()/;function Ku(e){return Gu.test(e.trim())}function qu(e){return e.type===o}function Ju(e){return e.type===n}function Yu(e){return e.type.charCodeAt(0)===64}function Xu(e){return Array.isArray(e.children)?e.children:[]}function Zu(e){return e.value.charCodeAt(e.value.length-1)===59?e.value.slice(0,-1):e.value}function Qu(e){let t=[];for(let n of Xu(e))Ju(n)&&t.push(Zu(n));return t}function $u(e){return Xu(e).filter(qu)}function ed(e){let t=e.charCodeAt(1);return t===100||t===109||t===115||t===99&&e.charCodeAt(3)===110?!0:t===99||t===108?e.charCodeAt(2)===97:!1}var td=new Set([r,t,a,i]);function nd(e,t,n){let i=[],a=new Set,o=!1,s=(e,t)=>{for(let n of e){if(qu(n)){o=!0,rd(n,t,i);continue}if(Yu(n)){if(Xu(n).length===0){if(!td.has(n.type))continue;i.push({code:`unsupported-at-rule`,severity:`error`,message:`\`${n.value}\` is not supported and was dropped. A constructed stylesheet strips \`@import\` by spec, and happy-dom discards the entire sheet when it sees any body-less at-rule — with one sheet per template that would erase the whole component. Move it to a \`<link>\`.`,line:n.line,column:n.column}),n.type===r&&o&&i.push({code:`import-after-rule`,severity:`warning`,message:`\`${n.value}\` follows a rule. Even where \`@import\` is supported it has to precede every rule in the sheet, so this one could not have applied.`,line:n.line,column:n.column});continue}if(o=!0,ed(n.type)){s(Xu(n),t);continue}$u(n).length>0&&id(n,a,i),s(Xu(n),!1)}}};s(e,n.scoped),!n.scoped&&e.some(Ju)&&i.push({code:`rule-without-selector`,severity:`warning`,message:`Declarations at the top level of a global block have no selector and were dropped. Wrap them in one.`}),ad(t,i);let c=sd(n.source);return c&&i.push(c),i}function rd(e,t,n){if(e.props.every(e=>e.length===0)){let t=Qu(e);t.length>0&&n.push({code:`rule-without-selector`,severity:`warning`,message:`A rule with no selector was dropped: \`{${t.join(`;`)}}\`.`,line:e.line,column:e.column})}if(t)for(let t of od(e.value)){let r=t.trim();if(Ku(r)){n.push({code:`shadow-boundary`,severity:`warning`,message:`\`${r}\` crosses a shadow boundary, but a scoped block prepends the component class to it, so it can never match. Use \`css.global\` for this rule.`,line:e.line,column:e.column});continue}r.charCodeAt(0)===58&&n.push({code:`implicit-descendant`,severity:`warning`,message:`\`${r}\` becomes a descendant of the scope, not a qualifier on it. Prefix it with \`&\` to attach it: \`&${r}\`.`,line:e.line,column:e.column})}}function id(e,t,n){if(t.has(e.value)){n.push({code:`duplicate-keyframes`,severity:`warning`,message:`\`${e.value}\` is defined more than once. The name is global and unscoped, so the last definition wins for every template that animates with it.`,line:e.line,column:e.column});return}t.add(e.value)}function ad(e,t){for(let n of e)for(let e of n.declarations)e.includes(`rhtml-scope`)&&t.push({code:`scope-in-declaration`,severity:`warning`,message:`\`${e}\` contains \`${Uu}\`. The sentinel is only substituted in selectors, so it will reach the browser as written.`})}function od(e){let t=[],n=0,r=0,i=0;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);r===0?o===34||o===39?r=o:o===40||o===91?n++:o===41||o===93?n--:o===44&&n===0&&(t.push(e.slice(i,a)),i=a+1):o===r&&e.charCodeAt(a-1)!==92&&(r=0)}return t.push(e.slice(i)),t}function sd(e){let t=1,n=1,r=0,i=()=>{e.charCodeAt(r)===10?(t++,n=1):n++,r++};for(;r<e.length;){let a=e.charCodeAt(r),o=e.charCodeAt(r+1);if(a===47&&o===42){let a=t,o=n;for(i(),i();r<e.length&&(e.charCodeAt(r)!==42||e.charCodeAt(r+1)!==47);)i();if(r>=e.length)return{code:`unterminated-comment`,severity:`warning`,message:`Unterminated block comment. The scanner consumed the rest of the source, so every rule after it was lost.`,line:a,column:o};i(),i();continue}if(a===47&&o===47){for(;r<e.length&&e.charCodeAt(r)!==10;)i();continue}if(a===34||a===39){let o=t,s=n;for(i();r<e.length&&e.charCodeAt(r)!==a;)e.charCodeAt(r)===92&&i(),i();if(r>=e.length)return{code:`unterminated-string`,severity:`warning`,message:`Unterminated string. The scanner consumed the rest of the source, so every rule after it was lost.`,line:o,column:s};i();continue}i()}return null}function cd(e,t={}){let n=``,r=[];for(let i of e){let{conditions:e}=i,a=0;for(;a<r.length&&a<e.length&&r[a]===e[a];)a++;for(let e=a;e<r.length;e++)n+=`}`;for(let t=a;t<e.length;t++)n+=`${e[t]}{`;r=e,n+=ld(i,t.scope)}for(let e=0;e<r.length;e++)n+=`}`;return n}function ld(e,t){return e.body===void 0?`${e.prelude??ud(e.selectors,t)}{${e.declarations.join(`;`)};}`:`${e.prelude}{${e.body}}`}function ud(e,t){return(t===void 0?e:e.map(e=>Wu(e,t))).join(`,`)}var dd=[],fd=e=>e.length>0;function pd(e,t){let n=[];return hd(e,dd,t.rules,n),(t.plugins??[]).reduce((e,t)=>e.flatMap(e=>t(e)),n).filter(md)}function md(e){let t=e.selectors.length>0||e.prelude!==void 0,n=e.declarations.length>0||!!e.body;return t&&n}function hd(e,t,n,r){let i=r.length,a=[];for(let i of e)Ju(i)?a.push(Zu(i)):qu(i)?gd(i,t,r):Yu(i)&&_d(i,t,n,r);if(a.length===0)return;let o=n.filter(fd);o.length!==0&&r.splice(i,0,{conditions:t,selectors:o,declarations:a})}function gd(e,t,n){let r=e.props.filter(fd);if(r.length===0)return;let i=Qu(e);i.length!==0&&n.push({conditions:t,selectors:r,declarations:i})}function _d(e,t,n,r){let i=Xu(e);if(i.length===0)return;if(ed(e.type)){let a=[];if(hd(i,[...t,e.value],n,a),a.length===0)return;for(let e of a)r.push(e);return}let a=$u(e);if(a.length>0){let n=[];for(let e of a)gd(e,dd,n);let i=cd(n);i&&r.push({conditions:t,selectors:[],prelude:e.value,declarations:[],body:i});return}let o=Qu(e);o.length!==0&&r.push({conditions:t,selectors:[],prelude:e.value,declarations:o})}function vd(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}var yd=7;function bd(e){return`_${vd(e).toString(36).padStart(yd,`0`)}`}var xd=[];function Sd(e,t={}){let n=t.mode!==`global`,r=n?[Uu]:[``],i=Hu(e,{rules:r}),a=pd(i,{rules:r,plugins:t.plugins}),o=cd(a),s=bd(o);return{rules:a,canonicalText:o,identifier:s,cssText:cd(a,{scope:`.${s}`}),diagnostics:t.dev?nd(i,a,{source:e,scoped:n}):xd}}function Cd(e){let t=/[;{}][^;{}]*$/.exec(e);return t?t[0].slice(1):e}function wd(e){let t=e.search(/[;}\n]/);return t===-1?e:e.slice(0,t)}function Td(e){let t=[];for(let n=0;n<e.length-1;n++){let r=Cd(e[n]),i=wd(e[n+1]),a=!r.includes(`:`)&&!i.includes(`{`)?`statement`:`inline`;t.push({kind:a,provable:r.trim().length===0})}return t}function Ed(e){let t=e.trimEnd();return!t||t.endsWith(`;`)||t.endsWith(`}`)?e:`${e};`}function Dd(e,t){return eo(e)?t===`statement`?Ed(e[qa]??``):`.${String(e)}`:Fi(e)&&!Mi(e)&&!ji(e)?String(e):``}function Od(e,t,n){if(eo(t)){e.kind===`statement`&&!e.provable&&console.error("[r-html] a css literal follows unterminated text, so it is spliced in as a statement. End the declaration in front of it with a `;`.");return}if(n.includes(`{`)||n.includes(`}`)){console.warn(`[r-html] interpolated value contains a brace and is substituted before compiling, so it can change the rule structure: ${n}`);return}(kd(n,`'`)||kd(n,`"`))&&console.warn(`[r-html] interpolated value has an unbalanced quote and is substituted before compiling: ${n}`)}function kd(e,t){let n=0;for(let r of e)r===t&&n++;return n%2==1}function Ad(e,t,n){let r=``;for(let i=0;i<e.length;i++){if(r+=e[i],i>=t.length)continue;let a=Dd(n[i],t[i].kind);Od(t[i],n[i],a),r+=a}return r}var jd=32,Md=`\0`;function Nd(e){return(t,...n)=>{let r=Fd(t,e),i=Id(r.node,n),a=yu(i);return{strings:t,values:n,template:r,[Qi]:Ga.css,[qa]:i.source,toString:()=>a}}}var Pd=Object.assign(Nd(`scoped`),{global:Nd(`global`)});function Fd(e,t){let n=Ya.get(e);if(n&&n.node.mode===t)return n;let r=e.raw,i={raw:r,slots:Td(r),mode:t,memo:new Map},a=Object.freeze({node:i});return Ya.set(e,a),a}function Id(e,t){let n=e.slots.map((e,n)=>Dd(t[n],e.kind)).join(Md),r=e.memo.get(n);if(r)return r;let i=Ad(e.raw,e.slots,t),{rules:a,canonicalText:o,identifier:s,cssText:c,diagnostics:l}=Sd(i,{mode:e.mode,dev:Ru()}),u={source:i,mode:e.mode,rules:a,canonicalText:o,identifier:s,cssText:c};if(zu(l,{source:i,identifier:s,mode:e.mode}),e.memo.set(n,u),e.memo.size>jd){let[t]=e.memo.keys();e.memo.delete(t)}return u}re.autoDrawEnabled=!1,Reflect.set(re,`DD`,ne);const Ld=new Set,Rd=new Set,zd=new Map,Bd=[],Vd=[],Hd=new Set;let Ud=!1,Wd=!1,Gd=0;function Kd(){return Gd}function qd(){Gd+=1;try{Hd.forEach(e=>e())}finally{Ud=!1,Wd=!1;for(let e of Ld){if(zd.has(e)){Rd.add(e);continue}e.getStage()instanceof te&&e.batchDraw()}Ld.clear(),Bd.splice(0).forEach(e=>e())}}function Jd(e){return Hd.add(e),()=>{Hd.delete(e)}}function Yd(){queueMicrotask(()=>{if(Wd){Wd=!1,Yd();return}qd()})}function Xd(){Wd=!0,!Ud&&(Ud=!0,Yd())}function Zd(e){if(zd.has(e)){Rd.add(e);return}Ld.add(e),Xd()}function Qd(e){zd.set(e,(zd.get(e)??0)+1)}function $d(e){let t=(zd.get(e)??0)-1;t>0?zd.set(e,t):zd.delete(e),Vd.splice(0).forEach(e=>e()),t<=0&&Rd.delete(e)&&Zd(e)}function ef(){return new Promise(e=>{Vd.push(()=>e())})}function tf(){return zd.size?ef().then(tf):Ud?new Promise(e=>{Bd.push(()=>e())}):Promise.resolve()}const nf=Symbol(`r-html/konva-slot`),rf=Symbol(`r-html/konva-ledger`),af=Symbol(`r-html/konva-virtual`),of=Symbol(`r-html/konva-fragment`),sf=new Set([`class`,`style`,`zIndex`]),cf={reconcile:0,scan:0,attach:0,drop:0,order:0,setZIndex:0},lf={"k-layer":()=>new f,"k-group":()=>new d,"k-rect":()=>new ee,"k-text":()=>new _,"k-path":()=>new g,"k-line":()=>new h,"k-circle":()=>new m};function uf(){}function df(){throw Error(`[konva-host] a DOM-only directive reached the konva host. innerHTML and vCSSStyleSheet read the DOM through the module helpers, which a konva node has nothing to answer with`)}function ff(e,t=``){let n={kind:e,data:t};return Reflect.set(n,af,e),Object.defineProperty(n,"nextSibling",{get:df}),Object.defineProperty(n,"parentNode",{get:df}),n}const pf=e=>e&&typeof e==`object`?Reflect.get(e,af)??null:null,mf=e=>e instanceof p,hf=e=>mf(e)&&Reflect.get(e,of)===!0,gf=e=>Reflect.get(e,nf);function _f(e){let t=gf(e);if(t)return t;let n={node:e,parent:null,prev:null,next:null,doomed:!1};return Reflect.set(e,nf,n),n}function vf(e){let t=Reflect.get(e,rf);if(t)return t;let n={first:null,last:null,dirty:!1,reconciledAt:-1};return Reflect.set(e,rf,n),n}const yf=e=>gf(e)?.parent??null,bf=e=>gf(e)?.next?.node??null,xf=new Set,Sf=new WeakMap;function Cf(e){let t=e;for(;t;){if(t instanceof f)return t;t=yf(t)}return null}function wf(e){let t=Cf(e);t&&Zd(t)}function Tf(e){vf(e).dirty=!0,xf.add(e),wf(e),Xd()}function Ef(e){let t=e.parent;if(!t)return;let n=vf(t);e.prev?e.prev.next=e.next:n.first=e.next,e.next?e.next.prev=e.prev:n.last=e.prev,e.parent=null,e.prev=null,e.next=null,Tf(t)}function Df(e,t,n){Ef(t);let r=vf(e);t.parent=e,t.doomed=!1,t.prev=n?n.prev:r.last,t.next=n,t.prev?t.prev.next=t:r.first=t,t.next?t.next.prev=t:r.last=t,Tf(e)}function Of(e,t){if(!(!mf(t)||hf(e))){if(e instanceof te){if(!(t instanceof f))throw Error(`[konva-host] a Stage holds layers only, so ${t.getClassName()} cannot sit at a template root. Make k-layer the root`);return}if(t instanceof f)throw Error(`[konva-host] k-layer nests in nothing but a Stage`);if(mf(e)&&!(e instanceof u))throw Error(`[konva-host] ${e.getClassName()} is a shape and holds no children`)}}function kf(e,t,n){if(t===n)return;let r=n?_f(n):null;if(!hf(t)){Of(e,t),Df(e,_f(t),r);return}let i=[];for(let e=vf(t).first;e;e=e.next)i.push(e);for(let t of i)Of(e,t.node),Df(e,t,r)}function Af(e){xf.delete(e),Reflect.deleteProperty(e,nf),Reflect.deleteProperty(e,rf),e.destroy()}function jf(e,t){let n=t.getParent();n!==e&&(n&&xf.has(n)&&If(n),cf.attach+=1,e.add(t))}function Mf(e,t){if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function Nf(e,t){t.forEach((t,n)=>{e.children[n]!==t&&(cf.setZIndex+=1,t.setZIndex(n))})}function Pf(e,t){let n=e.children;n.length=0;for(let e=0;e<t.length;e++){let r=t[e];n.push(r),r.index=e}}function Ff(e){if(cf.reconcile+=1,!(e instanceof u))return;let t=[];for(let n=vf(e).first;n;n=n.next)cf.scan+=1,mf(n.node)&&t.push(n.node);for(let n of t)jf(e,n);let n=new Set(t),r=e.children.filter(e=>!n.has(e));if(!(!r.length&&Mf(e.children,t))){cf.order+=1,e instanceof te?(r.forEach(e=>e.remove()),Nf(e,t)):(r.forEach(e=>{e.parent=null,e.index=0,e.remove()}),Pf(e,t));for(let e of r)cf.drop+=1,_f(e).doomed&&Af(e)}}function If(e){let t=vf(e);!t.dirty&&t.reconciledAt===Kd()||(t.dirty=!1,t.reconciledAt=Kd(),Ff(e))}Jd(()=>{for(let e of xf)If(e);xf.clear()});function Lf(e){let t=e,n=yf(t);for(;n;)t=n,n=yf(t);return Sf.get(t)??t}function Rf(e,t){if(!t)return;let n=Lf(e);if(mf(n)&&n.hasName(`minimap`))throw Error(`[konva-host] id "${t}" is not the minimap's to carry. Locate a minimap node by name plus a tableId attr`)}const zf=ou({createElement(e){let t=lf[e.toLowerCase()];if(!t)throw Error(`[konva-host] unknown konva tag <${e}>`);return t()},createText:e=>ff(`text`,e),createMarker:e=>ff(`marker`,e),createFragment(){let e=new d;return Reflect.set(e,of,!0),Reflect.set(e,`_validateAdd`,uf),e},createEventBus:()=>new EventTarget,insertBefore(e,t){let n=yf(t);n&&kf(n,e,t)},appendChild(e,t){kf(e,t,null)},prependChild(e,t){kf(e,t,vf(e).first?.node??null)},removeChild(e){let t=_f(e);Ef(t),mf(e)&&(t.doomed=!0,e.getParent()||Af(e))},parentOf:yf,nextSiblingOf:bf,setText(e,t){if(pf(e)!==`text`)throw Error(`[konva-host] a konva tree has no text node to write`);e.data=t},setAttribute(e,t,n,r){if(!mf(e))return;if(sf.has(t))throw Error(`[konva-host] "${t}" is not a konva attribute a template may write`);let i=r?n:String(n);t===`id`&&Rf(e,i),e.attrs[t]!==i&&(e.setAttrs({[t]:i}),wf(e))},removeAttribute(e,t){!mf(e)||e.attrs[t]===void 0||(e.setAttrs({[t]:void 0}),wf(e))},isHostNode:e=>mf(e)||pf(e)!==null,isMarker:e=>pf(e)===`marker`,isText:e=>pf(e)===`text`,isElement:e=>mf(e)&&!hf(e),isFragment:e=>hf(e),addEventListener(e,t,n,r){mf(e)?e.on(`${t}.rhtml`,n):e.addEventListener(t,n,r)},removeEventListener(e,t,n,r){mf(e)?e.off(`${t}.rhtml`,n):e.removeEventListener(t,n,r)},getRoot:Lf,createComponentContext(e,t){return{get host(){let n=Lf(e);return n instanceof te?n.container():t},get parentElement(){return null},dispatchEvent:e=>t.dispatchEvent(e)}},bridgeFragment(e,t){return Sf.set(e,t),()=>{Sf.delete(e)}}}),O=zf.html;function Bf(e,t){if(!(e instanceof te))throw Error(`[konva-host] a konva template renders into a Stage`);zf.render(e,t)}var Vf=(e,t)=>e*(1-t)/2;function Hf(e){return{originX:Ue(e.scrollLeft+Vf(e.width,e.zoomLevel),4),originY:Ue(e.scrollTop+Vf(e.height,e.zoomLevel),4)}}function k(e,t,n){return r=>{if(!n)return;let i=n[r];e(i)&&(t[r]=i)}}function Uf(e){return t=>b(t)&&e.includes(t)}function Wf(e){return t=>y(t)&&e.includes(t)}function Gf(e,t,n){return Reflect.get(e,t)??n}function Kf(){let e=Date.now();return{updateAt:e,createAt:e}}function qf(e,t){let n=k(y,e,t);n(`updateAt`),n(`createAt`)}var Jf=()=>({tableIds:[],relationshipIds:[],indexIds:[],memoIds:[]});function Yf(e){let t=Jf();if(!pe(e)||v(e))return t;let n=k(Array.isArray,t,e);return n(`tableIds`),n(`relationshipIds`),n(`indexIds`),n(`memoIds`),t}var Xf=()=>({id:``,name:``,tableId:``,indexColumnIds:[],seqIndexColumnIds:[],unique:!1,meta:Kf()});function Zf(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=Xf(),r=k(b,e,n),i=k(ue,e,n),a=k(Array.isArray,e,n);r(`id`),r(`name`),r(`tableId`),i(`unique`),a(`indexColumnIds`),a(`seqIndexColumnIds`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var Qf={ASC:1,DESC:2},$f=Object.values(Qf),ep=()=>({id:``,indexId:``,columnId:``,orderType:Qf.ASC,meta:Kf()});function tp(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=ep(),r=k(b,e,n);r(`id`),r(`indexId`),r(`columnId`),k(Wf($f),e,n)(`orderType`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var np=()=>({id:``,value:``,ui:{x:200,y:100,zIndex:2,width:116,height:100,color:``},meta:Kf()});function rp(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=np(),r=k(b,e,n),i=k(y,e.ui,n.ui),a=k(b,e.ui,n.ui);r(`id`),r(`value`),a(`color`),i(`x`),i(`y`),i(`zIndex`),i(`width`),i(`height`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var ip={ZeroOne:2,ZeroN:4,OneOnly:8,OneN:16},ap=Object.values(ip),op={ring:1,dash:2},sp=Object.values(op),cp={left:1,right:2,top:4,bottom:8},lp=Object.values(cp),up=()=>({id:``,identification:!1,relationshipType:ip.ZeroN,startRelationshipType:op.dash,start:{tableId:``,columnIds:[],x:0,y:0,direction:cp.bottom},end:{tableId:``,columnIds:[],x:0,y:0,direction:cp.bottom},meta:Kf()});function dp(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=up(),r=k(b,e,n),i=k(ue,e,n),a=k(y,e.start,n.start),o=k(b,e.start,n.start),s=k(y,e.end,n.end),c=k(b,e.end,n.end);r(`id`),i(`identification`),k(Wf(ap),e,n)(`relationshipType`),k(Wf(sp),e,n)(`startRelationshipType`),o(`tableId`),a(`x`),a(`y`),k(Wf(lp),e.start,n.start)(`direction`),k(Array.isArray,e.start,n.start)(`columnIds`),c(`tableId`),s(`x`),s(`y`),k(Wf(lp),e.end,n.end)(`direction`),k(Array.isArray,e.end,n.end)(`columnIds`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var fp={ERD:`ERD`,visualization:`@dineug/erd-editor/builtin-visualization`,schemaSQL:`@dineug/erd-editor/builtin-schema-sql`,generatorCode:`@dineug/erd-editor/builtin-generator-code`,settings:`settings`},pp=Object.values(fp),mp={tableComment:1,columnComment:2,columnDataType:4,columnDefault:8,columnAutoIncrement:16,columnPrimaryKey:32,columnUnique:64,columnNotNull:128,relationship:256},hp={columnName:1,columnDataType:2,columnNotNull:4,columnUnique:8,columnAutoIncrement:16,columnDefault:32,columnComment:64},gp=Object.values(hp),_p={MariaDB:1,MSSQL:2,MySQL:4,Oracle:8,PostgreSQL:16,SQLite:32,Databricks:64,Snowflake:128},vp=Object.values(_p),yp={GraphQL:1,csharp:2,Java:4,Kotlin:8,TypeScript:16,JPA:32,Scala:64,Go:128,SQLAlchemy:256,TypeORM:512,Sequelize:1024,Drizzle:2048,DBML:4096,AML:8192},bp=Object.values(yp),xp={none:1,camelCase:2,pascalCase:4,snakeCase:8},Sp=Object.values(xp),Cp={none:1,doubleQuote:2,singleQuote:4,backtick:8},wp=Object.values(Cp),Tp={scroll:1,zoomLevel:2},Ep=.1,Dp=1.5,Op=2e3,kp=2e4,Ap=mp.tableComment|mp.columnComment|mp.columnDataType|mp.columnDefault|mp.columnPrimaryKey|mp.columnNotNull|mp.relationship,jp=()=>({width:2e3,height:2e3,scrollTop:0,scrollLeft:0,originX:0,originY:0,zoomLevel:1,show:Ap,database:_p.MySQL,databaseName:``,canvasType:fp.ERD,language:yp.GraphQL,tableNameCase:xp.pascalCase,columnNameCase:xp.camelCase,bracketType:Cp.none,relationshipDataTypeSync:!0,relationshipOptimization:!1,columnOrder:[hp.columnName,hp.columnDataType,hp.columnNotNull,hp.columnUnique,hp.columnAutoIncrement,hp.columnDefault,hp.columnComment],maxWidthComment:-1,ignoreSaveSettings:0}),Mp=e=>ae(e,Op,kp),Np=e=>ae(e,Ep,Dp),Pp=e=>ae(e,60,200);function Fp(e){let t=jp();if(!pe(e)||v(e))return t;let n=k(y,t,e),r=k(b,t,e),i=k(ue,t,e);if(y(e.width)&&(t.width=Mp(e.width)),y(e.height)&&(t.height=Mp(e.height)),y(e.zoomLevel)&&(t.zoomLevel=Np(e.zoomLevel)),y(e.maxWidthComment)&&e.maxWidthComment!==-1&&(t.maxWidthComment=Pp(e.maxWidthComment)),n(`scrollTop`),n(`scrollLeft`),n(`show`),n(`ignoreSaveSettings`),r(`databaseName`),r(`canvasType`),i(`relationshipDataTypeSync`),i(`relationshipOptimization`),k(Wf(vp),t,e)(`database`),k(Wf(bp),t,e)(`language`),k(Wf(Sp),t,e)(`tableNameCase`),k(Wf(Sp),t,e)(`columnNameCase`),k(Wf(wp),t,e)(`bracketType`),Array.isArray(e.columnOrder)&&gp.length===e.columnOrder.length&&se(gp,e.columnOrder).length===0&&(t.columnOrder=e.columnOrder),y(e.originX)&&y(e.originY))t.originX=e.originX,t.originY=e.originY;else{let{originX:e,originY:n}=Hf(t);t.originX=e,t.originY=n}return t}var Ip=()=>({id:``,name:``,comment:``,columnIds:[],seqColumnIds:[],ui:{x:200,y:100,zIndex:2,widthName:60,widthComment:60,color:``},meta:Kf()});function Lp(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=Ip(),r=k(b,e,n),i=k(Array.isArray,e,n),a=k(y,e.ui,n.ui),o=k(b,e.ui,n.ui);r(`id`),r(`name`),r(`comment`),i(`columnIds`),i(`seqColumnIds`),o(`color`),a(`x`),a(`y`),a(`zIndex`),a(`widthName`),a(`widthComment`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var Rp=()=>({id:``,tableId:``,name:``,comment:``,dataType:``,default:``,options:0,ui:{keys:0,widthName:60,widthComment:60,widthDataType:60,widthDefault:60},meta:Kf()});function zp(e){let t={};if(!pe(e)||v(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=Rp(),r=k(b,e,n),i=k(y,e,n),a=k(y,e.ui,n.ui);r(`id`),r(`tableId`),r(`name`),r(`comment`),r(`dataType`),r(`default`),i(`options`),a(`keys`),a(`widthName`),a(`widthComment`),a(`widthDataType`),a(`widthDefault`),qf(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}function Bp(e){let t=e;return{$schema:`https://raw.githubusercontent.com/dineug/erd-editor/main/json-schema/schema.json`,version:`3.0.0`,settings:Fp(t.settings),doc:Yf(t.doc),collections:{tableEntities:Lp(t.collections?.tableEntities),tableColumnEntities:zp(t.collections?.tableColumnEntities),relationshipEntities:dp(t.collections?.relationshipEntities),indexEntities:Zf(t.collections?.indexEntities),indexColumnEntities:tp(t.collections?.indexColumnEntities),memoEntities:rp(t.collections?.memoEntities)}}}var A={CanvasType:fp,CanvasTypeList:pp,Show:mp,ColumnType:hp,ColumnTypeList:gp,Database:_p,DatabaseList:vp,Language:yp,LanguageList:bp,NameCase:xp,NameCaseList:Sp,BracketType:Cp,BracketTypeList:wp,RelationshipType:ip,RelationshipTypeList:ap,StartRelationshipType:op,StartRelationshipTypeList:sp,Direction:cp,DirectionList:lp,ColumnOption:{autoIncrement:1,primaryKey:2,unique:4,notNull:8},ColumnUIKey:{primaryKey:1,foreignKey:2},OrderType:Qf,OrderTypeList:$f,SaveSettingType:Tp,CANVAS_SIZE_MAX:kp,CANVAS_SIZE_MIN:Op,CANVAS_ZOOM_MAX:Dp,CANVAS_ZOOM_MIN:Ep};function Vp(e){return[e,-1,-1,{}]}function Hp(e,t,n){return e[t]||(e[t]=Vp(n),e[t])}function Up(e,t,n,r,i){let a=Hp(e,n,r),o=a[1],s=a[2];o<t&&(a[1]=t),s<t&&i()}function Wp(e,t,n,r,i){let a=Hp(e,n,r),o=a[2],s=a[1];o<t&&(a[2]=t),s<=t&&i()}function Gp(e,t,n,r,i,a){let o=Hp(e,n,r);(o[3][i]??-1)<=t&&(o[3][i]=t,a())}function Kp(e){"@babel/helpers - typeof";return Kp=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Kp(e)}function qp(e,t){if(Kp(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Kp(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Jp(e){var t=qp(e,`string`);return Kp(t)==`symbol`?t:t+``}function Yp(e,t,n){return(t=Jp(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Xp=class{constructor(e){Yp(this,`collections`,void 0),this.collections=e}collection(e){return new Zp(this.collections[e],e)}},Zp=class{constructor(e,t){Yp(this,`collection`,void 0),Yp(this,`collectionKey`,void 0),this.collection=e,this.collectionKey=t}selectById(e){return this.collection[e]}selectByIds(e){return e.length,e.map(e=>this.selectById(e)).filter(Boolean)}selectEntities(){return this.collection}selectAll(){return Object.values(this.collection)}setOne(e){return this.collection[e.id]=e,this}setMany(e){return e.forEach(e=>this.setOne(e)),this}setAll(e){return this.removeAll(),this.setMany(e),this}addOne(e){return this.selectById(e.id)||this.setOne(e),this}addMany(e){return e.forEach(e=>this.addOne(e)),this}removeOne(e){return this.selectById(e)&&Reflect.deleteProperty(this.collection,e),this}removeMany(e){return e.forEach(e=>this.removeOne(e)),this}removeAll(){return this.collection={},this}updateOne(e,t){let n=this.selectById(e);return n&&(t(n),n.meta.updateAt=Date.now()),this}updateMany(e,t){return e.forEach(e=>this.updateOne(e,t)),this}getOrCreate(e,t){let n=this.selectById(e);if(n)return n;let r=t(e);return this.setOne(r),this.selectById(e)}addOperator(e,t,n,r){return Up(e,t,n,this.collectionKey,r),this}removeOperator(e,t,n,r){return Wp(e,t,n,this.collectionKey,r),this}replaceOperator(e,t,n,r,i){return Gp(e,t,n,this.collectionKey,r,i),this}},j=e=>new Xp(e),Qp=Object.values({columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnDefault:`columnDefault`,columnComment:`columnComment`}),$p=Object.values({ERD:`ERD`,"@vuerd/builtin-sql-ddl":`@vuerd/builtin-sql-ddl`,"@vuerd/builtin-grid":`@vuerd/builtin-grid`,"@vuerd/builtin-generator-code":`@vuerd/builtin-generator-code`,"@vuerd/builtin-visualization":`@vuerd/builtin-visualization`}),em=Object.values({MariaDB:`MariaDB`,MSSQL:`MSSQL`,MySQL:`MySQL`,Oracle:`Oracle`,PostgreSQL:`PostgreSQL`,SQLite:`SQLite`}),tm=Object.values({GraphQL:`GraphQL`,"C#":`C#`,Java:`Java`,Kotlin:`Kotlin`,TypeScript:`TypeScript`,JPA:`JPA`,Scala:`Scala`}),nm=Object.values({none:`none`,camelCase:`camelCase`,pascalCase:`pascalCase`,snakeCase:`snakeCase`}),rm=Object.values({AtomOneDark:`AtomOneDark`,AtomOneLight:`AtomOneLight`,MonokaiSublime:`MonokaiSublime`,GithubGist:`GithubGist`,VS2015:`VS2015`}),im=Object.values({none:`none`,doubleQuote:`doubleQuote`,singleQuote:`singleQuote`,backtick:`backtick`}),am=.1,om=2e3,sm=2e4,cm=()=>({version:`2.2.11`,width:2e3,height:2e3,scrollTop:0,scrollLeft:0,zoomLevel:1,show:{tableComment:!0,columnComment:!0,columnDataType:!0,columnDefault:!0,columnAutoIncrement:!1,columnPrimaryKey:!0,columnUnique:!1,columnNotNull:!0,relationship:!0},database:`MySQL`,databaseName:``,canvasType:`ERD`,language:`GraphQL`,tableCase:`pascalCase`,columnCase:`camelCase`,highlightTheme:`VS2015`,bracketType:`none`,setting:{relationshipDataTypeSync:!0,relationshipOptimization:!1,columnOrder:[`columnName`,`columnDataType`,`columnNotNull`,`columnUnique`,`columnAutoIncrement`,`columnDefault`,`columnComment`]},pluginSerializationMap:{}}),lm=e=>ae(e,om,sm),um=e=>ae(e,am,1);function dm(e){let t=cm();if(v(e))return t;let n=k(y,t,e),r=k(b,t,e),i=k(ue,t.show,e.show),a=k(ue,t.setting,e.setting);if(y(e.width)&&(t.width=lm(e.width)),y(e.height)&&(t.height=lm(e.height)),y(e.zoomLevel)&&(t.zoomLevel=um(e.zoomLevel)),r(`version`),r(`databaseName`),n(`scrollTop`),n(`scrollLeft`),k(Uf(em),t,e)(`database`),k(Uf($p),t,e)(`canvasType`),k(Uf(tm),t,e)(`language`),k(Uf(nm),t,e)(`tableCase`),k(Uf(nm),t,e)(`columnCase`),k(Uf(rm),t,e)(`highlightTheme`),k(Uf(im),t,e)(`bracketType`),i(`tableComment`),i(`columnComment`),i(`columnDataType`),i(`columnDefault`),i(`columnAutoIncrement`),i(`columnPrimaryKey`),i(`columnUnique`),i(`columnNotNull`),i(`relationship`),a(`relationshipDataTypeSync`),a(`relationshipOptimization`),e.setting?.columnOrder&&Qp.length===e.setting.columnOrder.length&&se(Qp,e.setting.columnOrder).length===0&&(t.setting.columnOrder=e.setting.columnOrder),pe(e.pluginSerializationMap)){let n=e.pluginSerializationMap;for(let e of Object.keys(n)){let r=n[e];b(r)&&(t.pluginSerializationMap[e]=r)}}return t}var fm=()=>({memos:[]}),pm=()=>({id:``,value:``,ui:{active:!1,left:200,top:200,zIndex:2,width:127,height:127}});function mm(e){let t=fm();if(v(e)||!Array.isArray(e.memos))return t;for(let n of e.memos){let e=pm(),r=k(b,e,n),i=k(y,e.ui,n.ui),a=k(ue,e.ui,n.ui),o=k(b,e.ui,n.ui);r(`id`),r(`value`),a(`active`),o(`color`),i(`left`),i(`top`),i(`zIndex`),i(`width`),i(`height`),t.memos.push(e)}return t}var hm=[`ZeroOneN`,`One`,`N`],gm={ZeroOneN:`ZeroN`,One:`OneOnly`,N:`OneN`},_m=e=>hm.includes(e)?gm[e]:e,vm=Object.values({ZeroOneN:`ZeroOneN`,ZeroOne:`ZeroOne`,ZeroN:`ZeroN`,OneOnly:`OneOnly`,OneN:`OneN`,One:`One`,N:`N`}),ym=Object.values({Ring:`Ring`,Dash:`Dash`}),bm=Object.values({left:`left`,right:`right`,top:`top`,bottom:`bottom`}),xm=()=>({relationships:[]}),Sm=()=>({id:``,identification:!1,relationshipType:`ZeroN`,startRelationshipType:`Dash`,start:{tableId:``,columnIds:[],x:0,y:0,direction:`bottom`},end:{tableId:``,columnIds:[],x:0,y:0,direction:`bottom`},constraintName:``,visible:!0});function Cm(e){let t=xm();if(v(e)||!Array.isArray(e.relationships))return t;for(let n of e.relationships){let e=Sm(),r=k(b,e,n),i=k(ue,e,n),a=k(y,e.start,n.start),o=k(b,e.start,n.start),s=k(y,e.end,n.end),c=k(b,e.end,n.end);r(`id`),r(`constraintName`),i(`identification`),i(`visible`),k(Uf(vm),e,n)(`relationshipType`),e.relationshipType=_m(e.relationshipType),k(Uf(ym),e,n)(`startRelationshipType`),o(`tableId`),a(`x`),a(`y`),k(Uf(bm),e.start,n.start)(`direction`),Array.isArray(n.start?.columnIds)&&(e.start.columnIds=n.start?.columnIds.filter(b)),c(`tableId`),s(`x`),s(`y`),k(Uf(bm),e.end,n.end)(`direction`),Array.isArray(n.end?.columnIds)&&(e.end.columnIds=n.end?.columnIds.filter(b)),t.relationships.push(e)}return t}var wm={ASC:`ASC`,DESC:`DESC`},Tm=Object.values(wm),Em=()=>({tables:[],indexes:[]}),Dm=()=>({id:``,name:``,comment:``,columns:[],ui:{active:!1,left:200,top:100,zIndex:2,widthName:60,widthComment:60},visible:!0}),Om=()=>({id:``,name:``,comment:``,dataType:``,default:``,option:{autoIncrement:!1,primaryKey:!1,unique:!1,notNull:!1},ui:{active:!1,pk:!1,fk:!1,pfk:!1,widthName:60,widthComment:60,widthDataType:60,widthDefault:60}}),km=()=>({id:``,name:``,tableId:``,columns:[],unique:!1}),Am=()=>({id:``,orderType:wm.ASC});function jm(e){let t=Em();if(v(e))return t;if(Array.isArray(e.tables))for(let n of e.tables){let e=Dm(),r=k(b,e,n),i=k(ue,e,n),a=k(y,e.ui,n.ui),o=k(ue,e.ui,n.ui),s=k(b,e.ui,n.ui);if(r(`id`),r(`name`),r(`comment`),i(`visible`),o(`active`),s(`color`),a(`left`),a(`top`),a(`zIndex`),a(`widthName`),a(`widthComment`),Array.isArray(n.columns))for(let t of n.columns){let n=Om(),r=k(b,n,t),i=k(y,n.ui,t.ui),a=k(ue,n.ui,t.ui),o=k(ue,n.option,t.option);r(`id`),r(`name`),r(`comment`),r(`dataType`),r(`default`),o(`autoIncrement`),o(`primaryKey`),o(`unique`),o(`notNull`),a(`active`),a(`pk`),a(`fk`),a(`pfk`),i(`widthName`),i(`widthComment`),i(`widthDataType`),i(`widthDefault`),e.columns.push(n)}t.tables.push(e)}if(Array.isArray(e.indexes))for(let n of e.indexes){let e=km(),r=k(b,e,n),i=k(ue,e,n);if(r(`id`),r(`name`),r(`tableId`),i(`unique`),Array.isArray(n.columns))for(let t of n.columns){let n=Am();k(b,n,t)(`id`),k(Uf(Tm),n,t)(`orderType`),e.columns.push(n)}t.indexes.push(e)}return t}function Mm(e){let t=e;return{canvas:dm(t.canvas),table:jm(t.table),relationship:Cm(t.relationship),memo:mm(t.memo)}}function Nm(e){let t=Bp({});return Pm(t.settings,e.canvas),Fm(t,e.table),Im(t,e.memo),Lm(t,e.relationship),t}function Pm(e,t){e.width=t.width,e.height=t.height,e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft,e.zoomLevel=t.zoomLevel;let{originX:n,originY:r}=Hf(e);e.originX=n,e.originY=r,e.databaseName=t.databaseName,e.canvasType=A.CanvasType.ERD,e.show=Object.keys(t.show).reduce((e,n)=>Gf(t.show,n,!1)?e|Gf(A.Show,n,0):e,0),e.database=Reflect.get(A.Database,t.database)??A.Database.MySQL,e.language=t.language===`C#`?A.Language.csharp:Gf(A.Language,t.language,A.Language.GraphQL),e.tableNameCase=Gf(A.NameCase,t.tableCase,A.NameCase.pascalCase),e.columnNameCase=Gf(A.NameCase,t.columnCase,A.NameCase.camelCase),e.bracketType=Gf(A.BracketType,t.bracketType,A.BracketType.none),e.relationshipDataTypeSync=t.setting.relationshipDataTypeSync,e.relationshipOptimization=t.setting.relationshipOptimization;let i=t.setting.columnOrder.map(e=>A.ColumnType[e]);se(A.ColumnTypeList,i).length===0&&(e.columnOrder=i)}function Fm(e,t){let n=t.tables.filter(({id:e})=>!!e),r=t.indexes.filter(({id:e})=>!!e);e.doc.tableIds=n.map(({id:e})=>e),e.doc.indexIds=r.map(({id:e})=>e);for(let t of n){let n=Ip();n.id=t.id,n.name=t.name,n.comment=t.comment,n.columnIds=t.columns.map(({id:e})=>e),n.seqColumnIds=[...n.columnIds],n.ui.y=t.ui.top,n.ui.x=t.ui.left,n.ui.zIndex=t.ui.zIndex,n.ui.widthName=t.ui.widthName,n.ui.widthComment=t.ui.widthComment,n.ui.color=t.ui.color??``;for(let n of t.columns){let r=Rp();r.id=n.id,r.tableId=t.id,r.name=n.name,r.comment=n.comment,r.dataType=n.dataType,r.default=n.default,r.options=Object.keys(n.option).reduce((e,t)=>Gf(n.option,t,!1)?e|Gf(A.ColumnOption,t,0):e,0),r.ui.widthName=n.ui.widthName,r.ui.widthComment=n.ui.widthComment,r.ui.widthDataType=n.ui.widthDataType,r.ui.widthDefault=n.ui.widthDefault,n.ui.pfk?r.ui.keys=A.ColumnUIKey.primaryKey|A.ColumnUIKey.foreignKey:n.ui.pk?r.ui.keys=A.ColumnUIKey.primaryKey:n.ui.fk&&(r.ui.keys=A.ColumnUIKey.foreignKey),e.collections.tableColumnEntities[r.id]=r}e.collections.tableEntities[n.id]=n}for(let t of r){let n=Xf();n.id=t.id,n.name=t.name,n.tableId=t.tableId,n.unique=t.unique;for(let r of t.columns){let i=x(),a=ep();n.indexColumnIds.push(i),n.seqIndexColumnIds.push(i),a.id=i,a.indexId=t.id,a.columnId=r.id,a.orderType=Gf(A.OrderType,r.orderType,A.OrderType.ASC),e.collections.indexColumnEntities[a.id]=a}e.collections.indexEntities[n.id]=n}}function Im(e,t){let n=t.memos.filter(({id:e})=>!!e);e.doc.memoIds=n.map(({id:e})=>e);for(let t of n){let n=np();n.id=t.id,n.value=t.value,n.ui.y=t.ui.top,n.ui.x=t.ui.left,n.ui.width=t.ui.width,n.ui.height=t.ui.height,n.ui.zIndex=t.ui.zIndex,n.ui.color=t.ui.color??``,e.collections.memoEntities[n.id]=n}}function Lm(e,t){let n=t.relationships.filter(({id:e})=>!!e);e.doc.relationshipIds=n.map(({id:e})=>e);for(let t of n){let n=up();n.id=t.id,n.identification=t.identification,n.relationshipType=Gf(A.RelationshipType,t.relationshipType,A.RelationshipType.ZeroN),n.startRelationshipType=Gf(A.StartRelationshipType,t.startRelationshipType===`Ring`?`ring`:`dash`,A.StartRelationshipType.dash),n.start.tableId=t.start.tableId,n.start.columnIds=t.start.columnIds,n.start.x=t.start.x,n.start.y=t.start.y,n.start.direction=Gf(A.Direction,t.start.direction,A.Direction.bottom),n.end.tableId=t.end.tableId,n.end.columnIds=t.end.columnIds,n.end.x=t.end.x,n.end.y=t.end.y,n.end.direction=Gf(A.Direction,t.end.direction,A.Direction.bottom),e.collections.relationshipEntities[n.id]=n}}function Rm(e,t){return(e&t)===t}function zm(e){let t=JSON.parse(e);return Reflect.get(t,`version`)===`3.0.0`?Bp(t):Nm(Mm(t))}function Bm(e){let t=ve(e,[`$schema`,`version`,`settings`,`doc`,`collections`]),n={...t.settings};return t.settings=n,Rm(n.ignoreSaveSettings,A.SaveSettingType.scroll)&&(n.originX=0,n.originY=0),Rm(n.ignoreSaveSettings,A.SaveSettingType.zoomLevel)&&(n.zoomLevel=1),JSON.stringify(t,null,2)}const M={changeHasHistory:`editor.changeHasHistory`,selectAll:`editor.selectAll`,unselectAll:`editor.unselectAll`,select:`editor.select`,changeViewport:`editor.changeViewport`,clear:`editor.clear`,loadJson:`editor.loadJson`,initialClear:`editor.initialClear`,initialLoadJson:`editor.initialLoadJson`,focusTable:`editor.focusTable`,focusColumn:`editor.focusColumn`,focusTableEnd:`editor.focusTableEnd`,focusMoveTable:`editor.focusMoveTable`,editTable:`editor.editTable`,editTableEnd:`editor.editTableEnd`,editMemo:`editor.editMemo`,editMemoEnd:`editor.editMemoEnd`,scrollMemo:`editor.scrollMemo`,selectAllColumn:`editor.selectAllColumn`,drawStartRelationship:`editor.drawStartRelationship`,drawStartAddRelationship:`editor.drawStartAddRelationship`,drawEndRelationship:`editor.drawEndRelationship`,drawRelationship:`editor.drawRelationship`,hoverColumnMap:`editor.hoverColumnMap`,hoverRelationshipMap:`editor.hoverRelationshipMap`,changeOpenMap:`editor.changeOpenMap`,changeHandTool:`editor.changeHandTool`,changeZenMode:`editor.changeZenMode`,dragstartColumn:`editor.dragstartColumn`,dragendColumn:`editor.dragendColumn`,sharedMouseTracker:`editor.sharedMouseTracker`,sharedFocusTracker:`editor.sharedFocusTracker`,sharedSelectionTracker:`editor.sharedSelectionTracker`,sharedDragSelectTracker:`editor.sharedDragSelectTracker`,dragSelectRect:`editor.dragSelectRect`,validationIds:`editor.validationIds`,getLWW:`editor.getLWW`,mergeLWW:`editor.mergeLWW`},Vm=A.CanvasType,Hm=A.CanvasTypeList,N=A.Show,P=A.ColumnType,Um=A.ColumnTypeList,F=A.Database,Wm=A.DatabaseList;A.Language;const Gm=A.LanguageList;A.NameCase;const Km=A.NameCaseList,qm=A.BracketType,Jm=A.BracketTypeList,Ym=A.RelationshipType;A.RelationshipTypeList;const Xm=A.StartRelationshipType;A.StartRelationshipTypeList;const I=A.Direction;A.DirectionList;const L=A.ColumnOption,R=A.ColumnUIKey,Zm=A.OrderType;A.OrderTypeList,A.SaveSettingType;const Qm=A.CANVAS_SIZE_MAX,$m=A.CANVAS_SIZE_MIN,eh=A.CANVAS_ZOOM_MAX,th=A.CANVAS_ZOOM_MIN;qm.none,qm.backtick,qm.doubleQuote,qm.singleQuote,P.columnName,P.columnDataType,P.columnDefault,P.columnComment,P.columnAutoIncrement,P.columnUnique,P.columnNotNull;const nh={shared:1,changeOnly:2,following:4};function rh(e,t){return{...oe(t),tags:y(t.tags)&&Number.isInteger(t.tags)?t.tags|e:e}}function ih(e,t){return t.map(t=>rh(e,t))}(e=>(...t)=>function*(n,r){yield ih(e,Ou(n,r,t))})(nh.changeOnly);const ah=1200;function oh(e){return 9+e.ui.width+8+1}function sh(e){return 25+e.ui.height+8+1}function z(e,t){return(e&t)===t}const ch={Databricks:`Databricks`,MariaDB:`MariaDB`,MSSQL:`MSSQL`,MySQL:`MySQL`,Oracle:`Oracle`,PostgreSQL:`PostgreSQL`,Snowflake:`Snowflake`,SQLite:`SQLite`},lh=Object.values(ch);ch.Databricks,F.Databricks,ch.MariaDB,F.MariaDB,ch.MSSQL,F.MSSQL,ch.MySQL,F.MySQL,ch.Oracle,F.Oracle,ch.PostgreSQL,F.PostgreSQL,ch.Snowflake,F.Snowflake,ch.SQLite,F.SQLite;function B(e){let t=new Set(e);return e=>t.has(e)}const uh=/[^0-9]/g,dh=e=>e.replace(uh,``),fh=e=>ae(e,$m,Qm),ph=e=>ae(e,th,eh),mh=e=>ae(e,60,200);function hh(e){let t=b(e)?Number(dh(e)):e;return fh(t)}function gh(e){return Ue(ph(e),2)}const _h=B(Wm),vh=B(Km),yh=B(Jm),bh=B(Gm),xh=B(Um);B(lh);const Sh=B(Hm);function V(e){return Math.max(e,60)}function Ch(e){return b(e)?e.trim():``}function wh(e){return e<=.7}let Th=0;function Eh(){return Th}function Dh(){Th++}function Oh(e,{settings:{show:t,maxWidthComment:n},collections:r}){let i=e.ui.widthName+8;if(z(t,N.tableComment)){let t=n===-1?e.ui.widthComment:n<e.ui.widthComment?n:e.ui.widthComment;i+=t+8}let a=Ah(t);i<a&&(i=a);let o=jh(j(r).collection(`tableColumnEntities`).selectByIds(e.columnIds),t,n);return i<o.width&&(i=o.width),{...o,width:9+i+8+1}}const kh=[{key:N.columnComment,width:60},{key:N.columnDataType,width:60},{key:N.columnDefault,width:60},{key:N.columnNotNull,width:35},{key:N.columnAutoIncrement,width:15},{key:N.columnUnique,width:22}];function Ah(e){return kh.reduce((t,{key:n,width:r})=>z(e,n)?t+r+8:t,100)}function jh(e,t,n){let r={width:0,name:0,comment:0,dataType:0,default:0,notNull:0,autoIncrement:0,unique:0};for(let i of e)r.name<i.ui.widthName&&(r.name=i.ui.widthName),z(t,N.columnComment)&&r.comment<i.ui.widthComment&&(r.comment=n===-1?i.ui.widthComment:n<i.ui.widthComment?n:i.ui.widthComment),z(t,N.columnDataType)&&r.dataType<i.ui.widthDataType&&(r.dataType=i.ui.widthDataType),z(t,N.columnDefault)&&r.default<i.ui.widthDefault&&(r.default=i.ui.widthDefault);return z(t,N.columnNotNull)&&(r.notNull=35),z(t,N.columnAutoIncrement)&&(r.autoIncrement=15),z(t,N.columnUnique)&&(r.unique=22),r.width=Object.entries(r).reduce((e,[t,n])=>t===`width`||n===0?e:e+n+8,32),r}function Mh(e){return 47+e.columnIds.length*24+8+1}function Nh({doc:{tableIds:e},collections:t},{toWidth:n}){Dh();let r=j(t).collection(`tableEntities`).selectByIds(e),i=j(t).collection(`tableColumnEntities`);for(let e of r){e.ui.widthName=V(n(e.name)),e.ui.widthComment=V(n(e.comment));let t=i.selectByIds(e.columnIds);for(let e of t)e.ui.widthName=V(n(e.name)),e.ui.widthDataType=V(n(e.dataType)),e.ui.widthDefault=V(n(e.default)),e.ui.widthComment=V(n(e.comment))}}const Ph=new WeakMap;function Fh(e,t){let{settings:n}=e,r=`${Eh()}|${n.show}|${n.maxWidthComment}|${t.ui.widthName}|${t.ui.widthComment}|${t.columnIds.length}`,i=Ph.get(t);if(i?.key===r)return i;let a={key:r,width:Oh(t,e).width,height:Mh(t)};return Ph.set(t,a),a}function Ih(e,t){let{width:n,height:r}=Fh(e,t),{x:i,y:a}=t.ui;return{width:n,height:r,top:{x:i+n/2,y:a},bottom:{x:i+n/2,y:a+r},left:{x:i,y:a+r/2},right:{x:i+n,y:a+r/2},lt:{x:i,y:a},rt:{x:i+n,y:a},lb:{x:i,y:a+r},rb:{x:i+n,y:a+r}}}function Lh(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function Rh(e,t){let{width:n,height:r}=Ih(e,t),{x:i,y:a}=t.ui;return{x:i,y:a,width:n,height:r}}function zh(e,t){return Oh(t,e)}function Bh(e,t,n){let{x:r,y:i,width:a}=Rh(e,t);return{x:r+9,y:i+9+38+n*24,width:a-18,height:24}}function Vh(e){let{x:t,y:n}=e.ui;return{x:t,y:n,width:oh(e),height:sh(e)}}function Hh(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,width:Math.max(e.x+e.width,t.x+t.width)-n,height:Math.max(e.y+e.height,t.y+t.height)-r}}function Uh(e){return Gh(e,[])}function Wh(e,t=[]){let{doc:n,collections:r}=e,i=new Map(t.map(e=>[e.id,e])),a=j(r).collection(`tableEntities`).selectByIds(n.tableIds),o=j(r).collection(`memoEntities`).selectByIds(n.memoIds);return[...a.map(t=>{let n=i.get(t.id);return n?Rh(e,{...t,ui:{...t.ui,x:n.x,y:n.y}}):Rh(e,t)}),...o.map(Vh)]}function Gh(e,t){let n=Wh(e,t);return n.length?n.reduce(Hh):null}const Kh=wa({frozen:{}}),qh=e=>e.editor.id,Jh=e=>Kh.frozen[qh(e)]??null;function Yh(e){let{originX:t,originY:n}=e.settings;Kh.frozen[qh(e)]={content:Uh(e),origin:{x:t,y:n}}}function Xh(e){Reflect.deleteProperty(Kh.frozen,qh(e))}function Zh(e){let t=Jh(e);return t?t.content:Uh(e)}const H={changeDatabaseName:`settings.changeDatabaseName`,changeZoomLevel:`settings.changeZoomLevel`,streamZoomLevel:`settings.streamZoomLevel`,scrollTo:`settings.scrollTo`,streamScrollTo:`settings.streamScrollTo`,changeShow:`settings.changeShow`,changeDatabase:`settings.changeDatabase`,changeCanvasType:`settings.changeCanvasType`,changeLanguage:`settings.changeLanguage`,changeTableNameCase:`settings.changeTableNameCase`,changeColumnNameCase:`settings.changeColumnNameCase`,changeBracketType:`settings.changeBracketType`,changeRelationshipDataTypeSync:`settings.changeRelationshipDataTypeSync`,changeRelationshipOptimization:`settings.changeRelationshipOptimization`,changeColumnOrder:`settings.changeColumnOrder`,changeMaxWidthComment:`settings.changeMaxWidthComment`,changeIgnoreSaveSettings:`settings.changeIgnoreSaveSettings`},Qh=e=>e+0;function $h(e,t,n,r){let i=-t*r,a=n-e*r;return{min:Qh(Math.min(i,a)),max:Qh(Math.max(i,a))}}function eg(e,t,n,r,i){let{min:a,max:o}=$h(t,n,r,i);if(a<e&&e<o)return e;let s=Math.min(r,(n-t)*i);return Qh(Math.min(Math.max(e,a+s),o-s))}const tg=D(H.changeDatabaseName),ng=({settings:e,lww:t},{payload:{value:n},version:r},{clock:i})=>{Gp(t,r??i.getVersion(),`settings.databaseName`,`settings`,`databaseName`,()=>{e.databaseName=n})},rg=D(H.changeZoomLevel),ig=({settings:e},{payload:{value:t},tags:n})=>{!v(n)&&z(n,nh.following)||(e.zoomLevel=gh(t))},ag=D(H.streamZoomLevel),og=({settings:e},{payload:{value:t},tags:n})=>{!v(n)&&z(n,nh.following)||(e.zoomLevel=gh(e.zoomLevel+t))},sg=({width:e,height:t})=>e>0&&t>0;function cg(e){let{settings:{originX:t,originY:n,zoomLevel:r},editor:{viewport:i}}=e,a=Zh(e);return!a||!sg(i)?{x:t,y:n}:{x:eg(t,a.x,a.x+a.width,i.width,r),y:eg(n,a.y,a.y+a.height,i.height,r)}}const lg=D(H.scrollTo),ug=({settings:e},{payload:{originX:t,originY:n},tags:r})=>{!v(r)&&z(r,nh.following)||(e.originX=Ue(t,4),e.originY=Ue(n,4))},dg=D(H.streamScrollTo),fg=({settings:e},{payload:{movementX:t,movementY:n},tags:r})=>{!v(r)&&z(r,nh.following)||(e.originX=Ue(e.originX+t,4),e.originY=Ue(e.originY+n,4))},pg=D(H.changeShow),mg=({settings:e},{payload:{show:t,value:n}})=>{e.show=n?e.show|t:e.show&~t},hg=D(H.changeDatabase),gg=({settings:e},{payload:{value:t}})=>{_h(t)&&(e.database=t)},_g=D(H.changeCanvasType),vg=({settings:e},{payload:{value:t},tags:n})=>{!v(n)&&z(n,nh.following)||(e.canvasType=t)},yg=D(H.changeLanguage),bg=({settings:e},{payload:{value:t}})=>{bh(t)&&(e.language=t)},xg=D(H.changeTableNameCase),Sg=({settings:e},{payload:{value:t}})=>{vh(t)&&(e.tableNameCase=t)},Cg=D(H.changeColumnNameCase),wg=({settings:e},{payload:{value:t}})=>{vh(t)&&(e.columnNameCase=t)},Tg=D(H.changeBracketType),Eg=({settings:e},{payload:{value:t}})=>{yh(t)&&(e.bracketType=t)},Dg=D(H.changeRelationshipDataTypeSync),Og=({settings:e},{payload:{value:t}})=>{e.relationshipDataTypeSync=t},kg=D(H.changeRelationshipOptimization),Ag=({settings:e},{payload:{value:t}})=>{e.relationshipOptimization=t},jg=D(H.changeColumnOrder),Mg=({settings:e},{payload:{value:t,target:n}})=>{if(t===n||!xh(t)||!xh(n))return;let r=e.columnOrder.indexOf(t),i=e.columnOrder.indexOf(n);r!==-1&&i!==-1&&(e.columnOrder.splice(r,1),e.columnOrder.splice(i,0,t))},Ng=D(H.changeMaxWidthComment),Pg=({settings:e},{payload:{value:t}})=>{e.maxWidthComment=t===-1?t:mh(t)},Fg=D(H.changeIgnoreSaveSettings),Ig=({settings:e},{payload:{saveSettingType:t,value:n}})=>{e.ignoreSaveSettings=n?e.ignoreSaveSettings|t:e.ignoreSaveSettings&~t},Lg={[H.changeDatabaseName]:ng,[H.changeZoomLevel]:ig,[H.streamZoomLevel]:og,[H.scrollTo]:ug,[H.streamScrollTo]:fg,[H.changeShow]:mg,[H.changeDatabase]:gg,[H.changeCanvasType]:vg,[H.changeLanguage]:bg,[H.changeTableNameCase]:Sg,[H.changeColumnNameCase]:wg,[H.changeBracketType]:Eg,[H.changeRelationshipDataTypeSync]:Og,[H.changeRelationshipOptimization]:Ag,[H.changeColumnOrder]:Mg,[H.changeMaxWidthComment]:Pg,[H.changeIgnoreSaveSettings]:Ig},Rg={changeDatabaseNameAction:tg,changeZoomLevelAction:rg,streamZoomLevelAction:ag,scrollToAction:lg,streamScrollToAction:dg,changeShowAction:pg,changeDatabaseAction:hg,changeCanvasTypeAction:_g,changeLanguageAction:yg,changeTableNameCaseAction:xg,changeColumnNameCaseAction:Cg,changeBracketTypeAction:Tg,changeRelationshipDataTypeSyncAction:Dg,changeRelationshipOptimizationAction:kg,changeColumnOrderAction:jg,changeMaxWidthCommentAction:Ng,changeIgnoreSaveSettingsAction:Fg},U={left:`left`,right:`right`,top:`top`,bottom:`bottom`},zg=Object.values(U);B([U.top,U.bottom,U.left,U.right]);const Bg=[0,0],Vg=new WeakMap;function Hg(e,t){Vg.set(e,t)}function Ug(e){return Vg.get(e)??Bg}const Wg=new WeakMap;function Gg(e,t){Wg.set(e,{points:t,epoch:qg})}function Kg(e){return Wg.get(e)?.points}let qg=0;function Jg(){qg+=1}function Yg(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{x:a,y:o}of e)a<t&&(t=a),o<n&&(n=o),a>r&&(r=a),o>i&&(i=o);return{x:t,y:n,width:r-t,height:i-n}}function Xg({x:e,y:t,width:n,height:r},i){return{x:e-i,y:t-i,width:n+i*2,height:r+i*2}}function Zg(e,t=2){let{start:n,end:r}=e,i=Wg.get(e),a=i&&i.epoch===qg?i.points:null;return Xg(Yg(a?[...a,n,r]:[n,r]),25+t+(a?0:86))}function Qg({originX:e,originY:t}){return{x:e,y:t}}const $g=e=>e>0?e:1;function e_(e,t){let n=Qg(e);return{x:n.x+t.x*e.zoomLevel,y:n.y+t.y*e.zoomLevel}}function t_(e,t){let n=$g(e.zoomLevel),r=Qg({...e,zoomLevel:n});return{x:(t.x-r.x)/n,y:(t.y-r.y)/n}}function n_(e){let{viewportWidth:t,viewportHeight:n}=e,r=$g(e.zoomLevel),i=Qg({...e,zoomLevel:r}),a=(t>0?t:ah)/r,o=(n>0?n:675)/r;return{x:-i.x/r-a,y:-i.y/r-o,width:a*3,height:o*3}}function r_(e){let{settings:{originX:t,originY:n,zoomLevel:r},editor:{viewport:i}}=e;return n_({originX:t,originY:n,zoomLevel:r,viewportWidth:i.width,viewportHeight:i.height})}function i_(e,t){return!(t.x>e.x+e.width||t.x+t.width<e.x||t.y>e.y+e.height||t.y+t.height<e.y)}function a_(e,t,n){return i_(e,Rh(t,n))}function o_(e,t,n){return i_(e,Zg(t,n))}const s_={table:`table`,memo:`memo`},W={tableName:`tableName`,tableComment:`tableComment`,columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnDefault:`columnDefault`,columnComment:`columnComment`},c_={ArrowUp:`ArrowUp`,ArrowRight:`ArrowRight`,ArrowDown:`ArrowDown`,ArrowLeft:`ArrowLeft`,Tab:`Tab`};B(Object.values(c_));const l_=()=>({id:x(),selectedMap:{},hasUndo:!1,hasRedo:!1,viewport:{width:ah,height:675},scrollPullPending:!1,focusTable:null,editMemoId:null,memoScrollTopMap:{},drawRelationship:null,hoverColumnMap:{},hoverRelationshipMap:{},openMap:{},handTool:!1,zenMode:!1,draggableColumn:null,draggingColumnMap:{},sharedMouseTrackerMap:{},sharedFocusTrackerMap:{},sharedSelectionTrackerMap:{},sharedDragSelectTrackerMap:{},dragSelect:null}),u_=e=>e.ui.zIndex,d_=(e,t)=>Math.max(1,...e.map(u_),...t.map(u_))+1,f_=e=>t=>e.y===t.y&&e.x===t.x;function p_(e,t,n){let r=t_(e,{x:200,y:100}),i=[...t,...n].map(({ui:e})=>e);for(;i.some(f_(r));)r.x+=50,r.y+=50;return r}function m_(){let e=Date.now();return{updateAt:e,createAt:e}}function h_(e,t){return e<t?ye(e,t+1):ye(t,e+1)}function g_(e){return Se(ie(e??``))}function __(e,t){return xe([...e,t])}function v_(e,t,n){if(!t||t===n)return[n];let r=e.indexOf(t),i=e.indexOf(n);return r===-1?[n]:h_(r,i).map(t=>e[t])}function y_(e,t,n,r){return xe([...t,...v_(e,n,r)])}const b_={[P.columnName]:!0,[P.columnDataType]:N.columnDataType,[P.columnNotNull]:N.columnNotNull,[P.columnUnique]:N.columnUnique,[P.columnAutoIncrement]:N.columnAutoIncrement,[P.columnDefault]:N.columnDefault,[P.columnComment]:N.columnComment},x_={[P.columnName]:W.columnName,[P.columnDataType]:W.columnDataType,[P.columnNotNull]:W.columnNotNull,[P.columnUnique]:W.columnUnique,[P.columnAutoIncrement]:W.columnAutoIncrement,[P.columnDefault]:W.columnDefault,[P.columnComment]:W.columnComment},S_=[W.tableName,W.tableComment];function C_({settings:{show:e,columnOrder:t}}){return t.filter(t=>{let n=b_[t];return n===!0||z(e,n)}).map(e=>x_[e])}function w_({collections:e,editor:{focusTable:t}}){return t?!!j(e).collection(`tableEntities`).selectById(t.tableId)?.columnIds.length:!1}function T_(e){let{editor:{focusTable:t}}=e;if(!t)return!0;let n=C_(e);return n.indexOf(t.focusType)===n.length-1}function E_(e){let{editor:{focusTable:t}}=e;return!t||C_(e).indexOf(t.focusType)===0}function D_({collections:e,editor:{focusTable:t}}){if(!t?.columnId)return!0;let n=j(e).collection(`tableEntities`).selectById(t.tableId);return!n||n.columnIds.indexOf(t.columnId)===n.columnIds.length-1}function O_({collections:e,editor:{focusTable:t}}){if(!t?.columnId)return!0;let n=j(e).collection(`tableEntities`).selectById(t.tableId);return!n||n.columnIds.indexOf(t.columnId)===0}function k_(e){let t=C_(e);return t[t.length-1]}function A_(e){return C_(e)[0]}function j_(e){let{editor:{focusTable:t}}=e;if(!t)return W.columnName;let n=C_(e),r=n.indexOf(t.focusType);return T_(e)?n[0]:n[r+1]}function M_(e){let{editor:{focusTable:t}}=e;if(!t)return W.columnName;let n=C_(e),r=n.indexOf(t.focusType);return E_(e)?n[n.length-1]:n[r-1]}function N_(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r?.columnId)return null;let i=j(n).collection(`tableEntities`).selectById(r.tableId);if(!i)return null;let a=i.columnIds.indexOf(r.columnId);if(a<=0)return null;let o=null;for(let e=a;e>=0;e--){let n=i.columnIds[e];if(!t.includes(n)){o=n;break}}return o}function P_({settings:{show:e}}){return z(e,N.tableComment)?S_:[W.tableName]}function F_(e){let{editor:{focusTable:t}}=e;if(!t)return!0;let n=P_(e);return n.indexOf(t.focusType)===n.length-1}function I_(e){let{editor:{focusTable:t}}=e;return!t||P_(e).indexOf(t.focusType)===0}const L_=B(S_);function R_(e){let{editor:{focusTable:t}}=e;if(!t)return W.tableName;let n=P_(e),r=n.indexOf(t.focusType);return F_(e)?n[0]:n[r+1]}function z_(e){let{editor:{focusTable:t}}=e;if(!t)return W.tableName;let n=P_(e),r=n.indexOf(t.focusType);return I_(e)?n[n.length-1]:n[r-1]}function B_(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=j(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(L_(r.focusType)){if(w_(e)){let t=i.columnIds[i.columnIds.length-1];r.focusType=k_(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}}else if(O_(e))r.focusType=W.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let e=i.columnIds.indexOf(r.columnId),n=i.columnIds[e-1];r.columnId=n,r.prevSelectColumnId=n,r.selectColumnIds=t.shiftKey&&t.moveKey!==c_.Tab?__(r.selectColumnIds,n):[n]}}}function V_(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=j(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(L_(r.focusType)){if(w_(e)){let t=i.columnIds[0];r.focusType=A_(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}}else if(D_(e))r.focusType=W.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let e=i.columnIds.indexOf(r.columnId),n=i.columnIds[e+1];r.columnId=n,r.prevSelectColumnId=n,r.selectColumnIds=t.shiftKey&&t.moveKey!==c_.Tab?__(r.selectColumnIds,n):[n]}}}function H_(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=j(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(L_(r.focusType)){if(I_(e)){if(w_(e)){let t=i.columnIds[i.columnIds.length-1];r.focusType=k_(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}else r.focusType=z_(e)}else r.focusType=z_(e)}else if(E_(e)){if(O_(e))r.focusType=z(e.settings.show,N.tableComment)?W.tableComment:W.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let n=i.columnIds.indexOf(r.columnId),a=i.columnIds[n-1];r.focusType=k_(e),r.columnId=a,r.prevSelectColumnId=a,r.selectColumnIds=t.shiftKey&&t.moveKey!==c_.Tab?__(r.selectColumnIds,a):[a]}}else r.focusType=M_(e),!t.shiftKey&&r.columnId&&(r.prevSelectColumnId=r.columnId,r.selectColumnIds=[r.columnId])}}function U_(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=j(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(L_(r.focusType)){if(F_(e)){if(w_(e)){let t=i.columnIds[0];r.focusType=A_(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}else r.focusType=R_(e)}else r.focusType=R_(e)}else if(T_(e)){if(D_(e))r.focusType=W.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let n=i.columnIds.indexOf(r.columnId),a=i.columnIds[n+1];r.focusType=A_(e),r.columnId=a,r.prevSelectColumnId=a,r.selectColumnIds=t.shiftKey&&t.moveKey!==c_.Tab?__(r.selectColumnIds,a):[a]}}else r.focusType=j_(e),!t.shiftKey&&r.columnId&&(r.prevSelectColumnId=r.columnId,r.selectColumnIds=[r.columnId])}}const W_=3e4,G_=9e4,K_=3e3,q_=D(M.changeHasHistory),J_=({editor:e},{payload:{hasRedo:t,hasUndo:n}})=>{e.hasRedo=t,e.hasUndo=n},Y_=D(M.selectAll),X_=({editor:e,doc:t})=>{let n=t.tableIds.reduce((e,t)=>(e[t]=s_.table,e),{});e.selectedMap={...t.memoIds.reduce((e,t)=>(e[t]=s_.memo,e),{}),...n}},Z_=D(M.unselectAll),Q_=({editor:e})=>{Object.keys(e.selectedMap).forEach(t=>{Reflect.deleteProperty(e.selectedMap,t)})},$_=D(M.select),ev=({editor:e},{payload:t})=>{Object.assign(e.selectedMap,t)},tv=D(M.changeViewport),nv=(e,{payload:{width:t,height:n}})=>{e.editor.viewport.width=t,e.editor.viewport.height=n,e.editor.scrollPullPending&&av(e)},rv=D(M.clear),iv=e=>{let{doc:t,collections:n}=Bp({});e.doc=t,e.collections=n,e.editor.scrollPullPending=!1};function av(e){let{settings:t,editor:n}=e;if(!sg(n.viewport)){n.scrollPullPending=!0;return}let r=cg(e);t.originX=Ue(r.x,4),t.originY=Ue(r.y,4),n.scrollPullPending=!1}const ov=D(M.loadJson),sv=(e,{payload:{value:t}})=>{let{version:n,settings:r,doc:i,collections:a}=zm(t);Sh(r.canvasType)||(r.canvasType=Vm.ERD),Object.assign(e.settings,r),e.version=n,e.doc=i,e.collections=a,av(e)},cv=D(M.initialClear),lv=e=>{let{doc:t,collections:n}=Bp({});e.doc=t,e.collections=n,e.editor.scrollPullPending=!1},uv=D(M.initialLoadJson),dv=(e,{payload:{value:t}})=>{let{version:n,settings:r,doc:i,collections:a}=zm(t);Sh(r.canvasType)||(r.canvasType=Vm.ERD),Object.assign(e.settings,r),e.version=n,e.doc=i,e.collections=a,av(e)},fv=D(M.focusTable),pv=({editor:e,collections:t},{payload:n})=>{let r=j(t).collection(`tableEntities`);if(e.focusTable?.tableId===n.tableId&&n.focusType)e.focusTable.focusType=n.focusType,e.focusTable.columnId=null,e.focusTable.prevSelectColumnId=null,e.focusTable.selectColumnIds=[];else if(n.focusType){let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:n.focusType,columnId:null,prevSelectColumnId:null,selectColumnIds:[],edit:!1}}else if(e.focusTable?.tableId!==n.tableId){let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:W.tableName,columnId:null,prevSelectColumnId:null,selectColumnIds:[],edit:!1}}},mv=D(M.focusColumn),hv=({editor:e,collections:t},{payload:n})=>{let r=j(t).collection(`tableEntities`);if(e.focusTable?.tableId===n.tableId){let t=r.selectById(n.tableId);if(!t)return;let i=e.focusTable;i.columnId=n.columnId,i.focusType=n.focusType,i.selectColumnIds=n.$mod&&n.shiftKey?y_(t.columnIds,i.selectColumnIds,i.prevSelectColumnId,i.columnId):n.shiftKey?v_(t.columnIds,i.prevSelectColumnId,i.columnId):n.$mod?__(i.selectColumnIds,n.columnId):[n.columnId],i.prevSelectColumnId=n.columnId}else{let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:n.focusType,columnId:n.columnId,prevSelectColumnId:n.columnId,selectColumnIds:[n.columnId],edit:!1}}},gv=D(M.focusTableEnd),_v=({editor:e})=>{e.focusTable=null},vv=D(M.focusMoveTable),yv=(e,{payload:t})=>{let{editor:{focusTable:n}}=e;if(n)switch(n.edit=!1,t.moveKey){case c_.ArrowUp:B_(e,t);break;case c_.ArrowDown:V_(e,t);break;case c_.ArrowLeft:H_(e,t);break;case c_.ArrowRight:U_(e,t);break;case c_.Tab:t.shiftKey?H_(e,t):U_(e,t)}},bv=D(M.editTable),xv=({editor:{focusTable:e}})=>{e&&(e.edit=!0)},Sv=D(M.editTableEnd),Cv=({editor:{focusTable:e}})=>{e&&(e.edit=!1)},wv=D(M.editMemo),Tv=({editor:e},{payload:{id:t}})=>{e.editMemoId=t},Ev=D(M.editMemoEnd),Dv=({editor:e})=>{e.editMemoId=null},Ov=D(M.scrollMemo),kv=({editor:e},{payload:{id:t,scrollTop:n}})=>{e.memoScrollTopMap[t]=Number.isFinite(n)?Math.max(0,n):0},Av=D(M.selectAllColumn),jv=({collections:e,editor:{focusTable:t}})=>{if(!t)return;let n=j(e).collection(`tableEntities`).selectById(t.tableId);n&&(t.selectColumnIds=[...n.columnIds])},Mv=D(M.drawStartRelationship),Nv=({editor:e},{payload:{relationshipType:t}})=>{e.drawRelationship={relationshipType:t,start:null,end:{x:0,y:0}}},Pv=D(M.drawStartAddRelationship),Fv=({editor:{drawRelationship:e},collections:t},{payload:{tableId:n}})=>{if(!e)return;let r=j(t).collection(`tableEntities`).selectById(n);r&&(e.start={tableId:n,x:r.ui.x,y:r.ui.y})},Iv=D(M.drawEndRelationship),Lv=({editor:e})=>{e.drawRelationship=null},Rv=D(M.drawRelationship),zv=({editor:{drawRelationship:e},settings:t},{payload:{x:n,y:r}})=>{if(!e?.start)return;let i=t_(t,{x:n,y:r});e.end.x=i.x,e.end.y=i.y},Bv=D(M.hoverColumnMap),Vv=({editor:e},{payload:{columnIds:t}})=>{Object.keys(e.hoverColumnMap).forEach(t=>{Reflect.deleteProperty(e.hoverColumnMap,t)});for(let n of t)e.hoverColumnMap[n]=!0},Hv=D(M.hoverRelationshipMap),Uv=({editor:e},{payload:{relationshipIds:t}})=>{Object.keys(e.hoverRelationshipMap).forEach(t=>{Reflect.deleteProperty(e.hoverRelationshipMap,t)});for(let n of t)e.hoverRelationshipMap[n]=!0},Wv=D(M.changeOpenMap),Gv=({editor:e},{payload:t})=>{Object.assign(e.openMap,t)},Kv=D(M.changeHandTool),qv=({editor:e},{payload:{value:t}})=>{e.handTool=t,t&&(e.drawRelationship=null)},Jv=D(M.changeZenMode),Yv=({editor:e},{payload:{value:t}})=>{e.zenMode=t},Xv=D(M.dragstartColumn),Zv=({editor:e},{payload:t})=>{e.draggableColumn=t,t.columnIds.forEach(t=>{e.draggingColumnMap[t]=!0})},Qv=D(M.dragendColumn),$v=({editor:e})=>{e.draggableColumn=null,Object.keys(e.draggingColumnMap).forEach(t=>{Reflect.deleteProperty(e.draggingColumnMap,t)})},ey=D(M.sharedMouseTracker),ty=({editor:e},{payload:t,tags:n,meta:r})=>{if(v(n)||!z(n,nh.shared)||!b(r?.editorId)||e.id===r.editorId)return;let i=e.sharedMouseTrackerMap[r.editorId],a=!b(r.nickname)||He(r.nickname.trim())?`user`:r.nickname.trim();i?(i.x=t.x,i.y=t.y,i.nickname=a,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedMouseTrackerMap,r.editorId)},W_)):e.sharedMouseTrackerMap[r.editorId]={...t,id:r.editorId,nickname:a,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedMouseTrackerMap,r.editorId)},W_)}},ny=D(M.sharedFocusTracker),ry=({editor:e},{payload:{focus:t},tags:n,meta:r})=>{if(v(n)||!z(n,nh.shared)||!b(r?.editorId)||e.id===r.editorId)return;let i=e.sharedFocusTrackerMap[r.editorId];if(!t){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId));return}i?(i.tableId=t.tableId,i.columnId=t.columnId,i.focusType=t.focusType,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId)},G_)):e.sharedFocusTrackerMap[r.editorId]={...t,id:r.editorId,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId)},G_)}},iy=D(M.sharedSelectionTracker),ay=({editor:e},{payload:{selectedIds:t},tags:n,meta:r})=>{if(v(n)||!z(n,nh.shared)||!b(r?.editorId)||e.id===r.editorId)return;let i=e.sharedSelectionTrackerMap[r.editorId];if(!t.length){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId));return}i?(i.selectedIds=t,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId)},G_)):e.sharedSelectionTrackerMap[r.editorId]={id:r.editorId,selectedIds:t,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId)},G_)}},oy=D(M.sharedDragSelectTracker),sy=({editor:e},{payload:{rect:t},tags:n,meta:r})=>{if(v(n)||!z(n,nh.shared)||!b(r?.editorId)||e.id===r.editorId)return;let i=e.sharedDragSelectTrackerMap[r.editorId];if(!t){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId));return}i?(i.x=t.x,i.y=t.y,i.w=t.w,i.h=t.h,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId)},K_)):e.sharedDragSelectTrackerMap[r.editorId]={...t,id:r.editorId,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId)},K_)}},cy=D(M.dragSelectRect),ly=({editor:e},{payload:{rect:t}})=>{e.dragSelect=t},uy=D(M.validationIds),dy=({doc:e,collections:t})=>{let n=j(t).collection(`tableEntities`),r=j(t).collection(`tableColumnEntities`),i=j(t).collection(`indexEntities`),a=j(t).collection(`indexColumnEntities`),o=j(t).collection(`relationshipEntities`),s=j(t).collection(`memoEntities`),c=e.tableIds.filter(e=>!n.selectById(e)),l=e.relationshipIds.filter(e=>!o.selectById(e)),u=e.indexIds.filter(e=>!i.selectById(e)),d=e.memoIds.filter(e=>!s.selectById(e));e.tableIds=e.tableIds.filter(e=>!c.includes(e)),e.relationshipIds=e.relationshipIds.filter(e=>!l.includes(e)),e.indexIds=e.indexIds.filter(e=>!u.includes(e)),e.memoIds=e.memoIds.filter(e=>!d.includes(e)),n.selectAll().forEach(e=>{let t=e.columnIds.filter(e=>!r.selectById(e)),n=e.seqColumnIds.filter(e=>!r.selectById(e));e.columnIds=e.columnIds.filter(e=>!t.includes(e)),e.seqColumnIds=e.seqColumnIds.filter(e=>!n.includes(e))}),i.selectAll().forEach(e=>{let t=e.indexColumnIds.filter(e=>!a.selectById(e)),n=e.seqIndexColumnIds.filter(e=>!a.selectById(e));e.indexColumnIds=e.indexColumnIds.filter(e=>!t.includes(e)),e.seqIndexColumnIds=e.seqIndexColumnIds.filter(e=>!n.includes(e))})},fy=D(M.getLWW),py=ge,my=D(M.mergeLWW),hy=({lww:e},{payload:{lww:t}})=>{Object.entries(t).forEach(([t,[n,r,i,a]])=>{Up(e,r,t,n,ge),Wp(e,i,t,n,ge),Object.entries(a).forEach(([r,i])=>{Gp(e,i,t,n,r,ge)})})},gy={[M.changeHasHistory]:J_,[M.selectAll]:X_,[M.unselectAll]:Q_,[M.select]:ev,[M.changeViewport]:nv,[M.clear]:iv,[M.loadJson]:sv,[M.initialClear]:lv,[M.initialLoadJson]:dv,[M.focusTable]:pv,[M.focusColumn]:hv,[M.focusTableEnd]:_v,[M.focusMoveTable]:yv,[M.editTable]:xv,[M.editTableEnd]:Cv,[M.editMemo]:Tv,[M.editMemoEnd]:Dv,[M.scrollMemo]:kv,[M.selectAllColumn]:jv,[M.drawStartRelationship]:Nv,[M.drawStartAddRelationship]:Fv,[M.drawEndRelationship]:Lv,[M.drawRelationship]:zv,[M.hoverColumnMap]:Vv,[M.hoverRelationshipMap]:Uv,[M.changeOpenMap]:Gv,[M.changeHandTool]:qv,[M.changeZenMode]:Yv,[M.dragstartColumn]:Zv,[M.dragendColumn]:$v,[M.sharedMouseTracker]:ty,[M.sharedFocusTracker]:ry,[M.sharedSelectionTracker]:ay,[M.sharedDragSelectTracker]:sy,[M.dragSelectRect]:ly,[M.validationIds]:dy,[M.getLWW]:py,[M.mergeLWW]:hy},_y={changeHasHistoryAction:q_,selectAllAction:Y_,unselectAllAction:Z_,selectAction:$_,changeViewportAction:tv,clearAction:rv,loadJsonAction:ov,initialClearAction:cv,initialLoadJsonAction:uv,focusTableAction:fv,focusColumnAction:mv,focusTableEndAction:gv,focusMoveTableAction:vv,editTableAction:bv,editTableEndAction:Sv,editMemoAction:wv,editMemoEndAction:Ev,scrollMemoAction:Ov,selectAllColumnAction:Av,drawStartRelationshipAction:Mv,drawStartAddRelationshipAction:Pv,drawEndRelationshipAction:Iv,drawRelationshipAction:Rv,hoverColumnMapAction:Bv,hoverRelationshipMapAction:Hv,changeOpenMapAction:Wv,changeHandToolAction:Kv,changeZenModeAction:Jv,dragstartColumnAction:Xv,dragendColumnAction:Qv,sharedMouseTrackerAction:ey,sharedFocusTrackerAction:ny,sharedSelectionTrackerAction:iy,sharedDragSelectTrackerAction:oy,dragSelectRectAction:cy,validationIdsAction:uy,getLWWAction:fy,mergeLWWAction:my},vy=(e,t,n)=>{e.push(rv(),ov({value:Bm(n)}))},yy=(e,t,n)=>{e.push(ov({value:Bm(n)}))},by={[M.loadJson]:vy,[M.clear]:yy},xy={addIndex:`index.add`,removeIndex:`index.remove`,changeIndexName:`index.changeName`,changeIndexUnique:`index.changeUnique`},Sy=e=>We({id:x(),name:``,tableId:``,indexColumnIds:[],seqIndexColumnIds:[],unique:!1,meta:m_()},e??{}),Cy=D(xy.addIndex),wy=({doc:e,collections:t,lww:n},{payload:{id:r,tableId:i},version:a},{clock:o})=>{let s=a??o.getVersion();j(t).collection(`indexEntities`).addOne(Sy({id:r,tableId:i})).addOperator(n,s,r,()=>{B(e.indexIds)(r)||e.indexIds.push(r)})},Ty=D(xy.removeIndex),Ey=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();j(t).collection(`indexEntities`).removeOperator(n,o,r,()=>{let t=e.indexIds.indexOf(r);t!==-1&&e.indexIds.splice(t,1)})},Dy=D(xy.changeIndexName),Oy=({collections:e,lww:t},{payload:{id:n,tableId:r,value:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=j(e).collection(`indexEntities`);c.getOrCreate(n,e=>Sy({id:e,tableId:r})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=i})})},ky=D(xy.changeIndexUnique),Ay=({collections:e,lww:t},{payload:{id:n,tableId:r,value:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=j(e).collection(`indexEntities`);c.getOrCreate(n,e=>Sy({id:e,tableId:r})),c.replaceOperator(t,s,n,`unique`,()=>{c.updateOne(n,e=>{e.unique=i})})},jy={[xy.addIndex]:wy,[xy.removeIndex]:Ey,[xy.changeIndexName]:Oy,[xy.changeIndexUnique]:Ay},My={addIndexAction:Cy,removeIndexAction:Ty,changeIndexNameAction:Dy,changeIndexUniqueAction:ky},Ny=(e,{payload:{id:t}})=>{e.push(Ty({id:t}))},Py=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`indexEntities`).selectById(t);r&&e.push(Cy({id:t,tableId:r.tableId}))},Fy=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=j(r).collection(`indexEntities`).selectById(t);i&&e.push(Dy({id:t,tableId:n,value:i.name}))},Iy=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{j(i).collection(`indexEntities`).selectById(t)&&e.push(ky({id:t,tableId:n,value:!r}))},Ly={[xy.addIndex]:Ny,[xy.removeIndex]:Py,[xy.changeIndexName]:Fy,[xy.changeIndexUnique]:Iy},Ry={addIndexColumn:`indexColumn.add`,removeIndexColumn:`indexColumn.remove`,moveIndexColumn:`indexColumn.move`,changeIndexColumnOrderType:`indexColumn.changeOrderType`},zy=e=>We({id:x(),indexId:``,columnId:``,orderType:Zm.ASC,meta:m_()},e??{});function By(e,t,n){if(B(t)(n)){let r=t.reduce((e,t,n)=>(e[t]=n,e),{});e.push(n),e.sort((e,t)=>{let n=r[e],i=r[t];return n===void 0?1:i===void 0?-1:n-i})}else e.push(n),t.push(n)}const Vy=D(Ry.addIndexColumn),Hy=({collections:e,lww:t},{payload:{id:n,indexId:r,tableId:i,columnId:a},version:o},{clock:s})=>{let c=o??s.getVersion(),l=j(e).collection(`indexEntities`),u=l.getOrCreate(r,e=>Sy({id:e,tableId:i}));j(e).collection(`indexColumnEntities`).addOne(zy({id:n,indexId:r,columnId:a})).addOperator(t,c,n,()=>{B(u.indexColumnIds)(n)||l.updateOne(r,e=>{By(e.indexColumnIds,e.seqIndexColumnIds,n)})})},Uy=D(Ry.removeIndexColumn),Wy=({collections:e,lww:t},{payload:{id:n,indexId:r,tableId:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=j(e).collection(`indexEntities`),l=c.getOrCreate(r,e=>Sy({id:e,tableId:i}));j(e).collection(`indexColumnEntities`).removeOperator(t,s,n,()=>{let e=l.indexColumnIds.indexOf(n);e!==-1&&c.updateOne(r,t=>{t.indexColumnIds.splice(e,1)})})},Gy=D(Ry.moveIndexColumn),Ky=({collections:e},{payload:{id:t,indexId:n,tableId:r,targetId:i}})=>{if(t===i)return;let a=j(e).collection(`indexEntities`),o=a.getOrCreate(n,e=>Sy({id:e,tableId:r})),s=o.indexColumnIds.indexOf(t);if(s===-1)return;let c=o.indexColumnIds.indexOf(i);c!==-1&&a.updateOne(n,e=>{e.indexColumnIds.splice(s,1),e.indexColumnIds.splice(c,0,t);let n=e.seqIndexColumnIds.indexOf(t),r=e.seqIndexColumnIds.indexOf(i);n!==-1&&r!==-1&&(e.seqIndexColumnIds.splice(n,1),e.seqIndexColumnIds.splice(r,0,t))})},qy=D(Ry.changeIndexColumnOrderType),Jy=({collections:e,lww:t},{payload:{id:n,indexId:r,columnId:i,value:a},version:o},{clock:s})=>{let c=o??s.getVersion(),l=j(e).collection(`indexColumnEntities`);l.getOrCreate(n,e=>zy({id:e,indexId:r,columnId:i})),l.replaceOperator(t,c,n,`orderType`,()=>{l.updateOne(n,e=>{e.orderType=a})})},Yy={[Ry.addIndexColumn]:Hy,[Ry.removeIndexColumn]:Wy,[Ry.moveIndexColumn]:Ky,[Ry.changeIndexColumnOrderType]:Jy},Xy={addIndexColumnAction:Vy,removeIndexColumnAction:Uy,moveIndexColumnAction:Gy,changeIndexColumnOrderTypeAction:qy},Zy=(e,{payload:{id:t,indexId:n,tableId:r}})=>{e.push(Uy({id:t,indexId:n,tableId:r}))},Qy=(e,{payload:{id:t,indexId:n,tableId:r}},{collections:i})=>{let a=j(i).collection(`indexColumnEntities`).selectById(t);a&&e.push(Vy({id:t,indexId:n,tableId:r,columnId:a.columnId}))},$y=(e,{payload:{id:t,indexId:n,tableId:r,targetId:i}},{collections:a})=>{let o=j(a).collection(`indexEntities`).selectById(n);if(!o)return;let s=o.indexColumnIds.indexOf(t);if(s===-1)return;let c=o.indexColumnIds.indexOf(i);if(c===-1)return;let l=s<c?s+1:s-1,u=o.indexColumnIds[l];e.push(Gy({indexId:n,tableId:r,id:t,targetId:u}))},eb=(e,{payload:{id:t,indexId:n,columnId:r}},{collections:i})=>{let a=j(i).collection(`indexColumnEntities`).selectById(t);a&&e.push(qy({id:t,indexId:n,columnId:r,value:a.orderType}))},tb={[Ry.addIndexColumn]:Zy,[Ry.removeIndexColumn]:Qy,[Ry.moveIndexColumn]:$y,[Ry.changeIndexColumnOrderType]:eb},nb={addMemo:`memo.add`,moveMemo:`memo.move`,moveToMemo:`memo.moveTo`,removeMemo:`memo.remove`,changeMemoValue:`memo.changeValue`,changeMemoColor:`memo.changeColor`,resizeMemo:`memo.resize`,changeZIndex:`memo.changeZIndex`},rb=e=>We({id:x(),value:``,ui:{x:200,y:100,zIndex:2,width:116,height:100,color:``},meta:m_()},e??{}),ib=D(nb.addMemo),ab=({doc:e,collections:t,lww:n},{payload:{id:r,ui:i},version:a},{clock:o})=>{let s=a??o.getVersion();j(t).collection(`memoEntities`).addOne(rb({id:r,ui:i})).addOperator(n,s,r,()=>{B(e.memoIds)(r)||e.memoIds.push(r)})},ob=D(nb.moveMemo),sb=({collections:e},{payload:{ids:t,movementX:n,movementY:r}})=>{let i=j(e).collection(`memoEntities`);for(let e of t)i.getOrCreate(e,e=>rb({id:e}));i.updateMany(t,e=>{e.ui.x=Ue(e.ui.x+n,4),e.ui.y=Ue(e.ui.y+r,4)})},cb=D(nb.moveToMemo),lb=({collections:e},{payload:{id:t,x:n,y:r}})=>{let i=j(e).collection(`memoEntities`);i.getOrCreate(t,e=>rb({id:e})),i.updateOne(t,e=>{e.ui.x=n,e.ui.y=r})},ub=D(nb.removeMemo),db=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();j(t).collection(`memoEntities`).removeOperator(n,o,r,()=>{let t=e.memoIds.indexOf(r);t!==-1&&e.memoIds.splice(t,1)})},fb=D(nb.changeMemoValue),pb=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`memoEntities`);s.getOrCreate(n,e=>rb({id:e})),s.replaceOperator(t,o,n,`value`,()=>{s.updateOne(n,e=>{e.value=r})})},mb=D(nb.changeMemoColor),hb=({collections:e,lww:t},{payload:{id:n,color:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`memoEntities`);s.getOrCreate(n,e=>rb({id:e})),s.replaceOperator(t,o,n,`ui.color`,()=>{s.updateOne(n,e=>{e.ui.color=r})})},gb=D(nb.resizeMemo),_b=({collections:e},{payload:{id:t,x:n,y:r,width:i,height:a}})=>{let o=j(e).collection(`memoEntities`);o.getOrCreate(t,e=>rb({id:e})),o.updateOne(t,e=>{e.ui.x=n,e.ui.y=r,e.ui.width=i,e.ui.height=a})},vb=D(nb.changeZIndex),yb=({collections:e},{payload:{id:t,zIndex:n}})=>{let r=j(e).collection(`memoEntities`);r.getOrCreate(t,e=>rb({id:e})),r.updateOne(t,e=>{e.ui.zIndex=n})},bb={[nb.addMemo]:ab,[nb.moveMemo]:sb,[nb.moveToMemo]:lb,[nb.removeMemo]:db,[nb.changeMemoValue]:pb,[nb.changeMemoColor]:hb,[nb.resizeMemo]:_b,[nb.changeZIndex]:yb},xb={addMemoAction:ib,moveMemoAction:ob,moveToMemoAction:cb,removeMemoAction:ub,changeMemoValueAction:fb,changeMemoColorAction:mb,resizeMemoAction:gb,changeZIndexAction:vb},Sb=(e,{payload:{id:t}})=>{e.push(ub({id:t}))},Cb=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`memoEntities`).selectById(t);r&&e.push(ib({id:r.id,ui:ve(r.ui,[`x`,`y`,`zIndex`])}))},wb=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`memoEntities`).selectById(t);r&&e.push(fb({id:t,value:r.value}))},Tb=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`memoEntities`).selectById(t);r&&e.push(cb({id:t,x:r.ui.x,y:r.ui.y}))},Eb={[nb.addMemo]:Sb,[nb.removeMemo]:Cb,[nb.changeMemoValue]:wb,[nb.moveToMemo]:Tb},Db=(e,t,n)=>{let r=n.filter(e=>e.type===ob.type);if(!r.length)return;let i=ce(r,e=>e.payload.ids.join(`,`));for(let[,n]of Object.entries(i)){let{payload:{ids:r}}=le(n),{x:i,y:a}=n.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(ob({ids:r,movementX:-1*i,movementY:-1*a})),t.push(ob({ids:r,movementX:i,movementY:a})))}},Ob=(e,t,n)=>{let r=n.filter(({type:e})=>e===mb.type);if(!r.length)return;let i=ce(r,e=>e.payload.id);for(let[n,r]of Object.entries(i)){let i=le(r),a=me(r);e.push(mb({id:n,color:i.payload.prevColor,prevColor:a.payload.color})),t.push(mb({id:n,color:a.payload.color,prevColor:i.payload.prevColor}))}},kb=(e,t,n)=>{let r=n.filter(e=>e.type===gb.type);if(!r.length)return;let i=ce(r,e=>e.payload.id);for(let[,n]of Object.entries(i)){if(n.length<2)continue;let r=le(n),i=me(n);e.push(r),t.push(i)}},Ab={[nb.moveMemo]:Db,[nb.changeMemoColor]:Ob,[nb.resizeMemo]:kb},jb={addRelationship:`relationship.add`,removeRelationship:`relationship.remove`,changeRelationshipType:`relationship.changeType`},Mb=e=>We({id:x(),identification:!1,relationshipType:Ym.ZeroN,startRelationshipType:Xm.dash,start:{tableId:``,columnIds:[],x:0,y:0,direction:I.bottom},end:{tableId:``,columnIds:[],x:0,y:0,direction:I.bottom},meta:m_()},e??{}),Nb=D(jb.addRelationship),Pb=({doc:e,collections:t,lww:n},{payload:{id:r,relationshipType:i,start:a,end:o},version:s},{clock:c})=>{let l=s??c.getVersion();j(t).collection(`relationshipEntities`).addOne(Mb({id:r,relationshipType:i,start:{tableId:a.tableId,columnIds:a.columnIds},end:{tableId:o.tableId,columnIds:o.columnIds}})).addOperator(n,l,r,()=>{B(e.relationshipIds)(r)||e.relationshipIds.push(r)})},Fb=D(jb.removeRelationship),Ib=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();j(t).collection(`relationshipEntities`).removeOperator(n,o,r,()=>{let t=e.relationshipIds.indexOf(r);t!==-1&&e.relationshipIds.splice(t,1)})},Lb=D(jb.changeRelationshipType),Rb=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`relationshipEntities`);s.replaceOperator(t,o,n,`relationshipType`,()=>{s.updateOne(n,e=>{e.relationshipType=r})})},zb={[jb.addRelationship]:Pb,[jb.removeRelationship]:Ib,[jb.changeRelationshipType]:Rb},Bb={addRelationshipAction:Nb,removeRelationshipAction:Fb,changeRelationshipTypeAction:Lb},Vb=(e,{payload:{id:t}})=>{e.push(Fb({id:t}))},Hb=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`relationshipEntities`).selectById(t);r&&e.push(Nb({id:r.id,relationshipType:r.relationshipType,start:ve(r.start,[`tableId`,`columnIds`]),end:ve(r.end,[`tableId`,`columnIds`])}))},Ub=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`relationshipEntities`).selectById(t);r&&e.push(Lb({id:t,value:r.relationshipType}))},Wb={[jb.addRelationship]:Vb,[jb.removeRelationship]:Hb,[jb.changeRelationshipType]:Ub},Gb=(e,t,{settings:n})=>{e.push(lg({originX:n.originX,originY:n.originY}))},Kb=(e,{payload:{show:t,value:n}})=>{e.push(pg({show:t,value:!n}))},qb=(e,t,{settings:n})=>{e.push(rg({value:n.zoomLevel}))},Jb={[H.scrollTo]:Gb,[H.changeShow]:Kb,[H.changeZoomLevel]:qb},Yb=(e,t,n)=>{let r=n.filter(e=>e.type===dg.type);if(!r.length)return;let{x:i,y:a}=r.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(dg({movementX:-1*i,movementY:-1*a})),t.push(dg({movementX:i,movementY:a})))},Xb=(e,t,n)=>{let r=n.filter(e=>e.type===ag.type);if(!r.length)return;let i=r.reduce((e,{payload:{value:t}})=>e+t,0);e.push(ag({value:-1*i})),t.push(ag({value:i}))},Zb={[H.streamScrollTo]:Yb,[H.streamZoomLevel]:Xb},G={addTable:`table.add`,moveTable:`table.move`,moveToTable:`table.moveTo`,removeTable:`table.remove`,changeTableName:`table.changeName`,changeTableComment:`table.changeComment`,changeTableColor:`table.changeColor`,changeZIndex:`table.changeZIndex`,sortTable:`table.sort`},Qb=e=>We({id:x(),name:``,comment:``,columnIds:[],seqColumnIds:[],ui:{x:200,y:100,zIndex:2,widthName:60,widthComment:60,color:``},meta:m_()},e??{}),$b=D(G.addTable),ex=({doc:e,collections:t,lww:n},{payload:{id:r,ui:i},version:a},{clock:o})=>{let s=a??o.getVersion();j(t).collection(`tableEntities`).addOne(Qb({id:r,ui:i})).addOperator(n,s,r,()=>{B(e.tableIds)(r)||e.tableIds.push(r)})},tx=D(G.moveTable),nx=({collections:e},{payload:{ids:t,movementX:n,movementY:r}})=>{let i=j(e).collection(`tableEntities`);for(let e of t)i.getOrCreate(e,e=>Qb({id:e}));i.updateMany(t,e=>{e.ui.x=Ue(e.ui.x+n,4),e.ui.y=Ue(e.ui.y+r,4)})},rx=D(G.moveToTable),ix=({collections:e},{payload:{id:t,x:n,y:r}})=>{let i=j(e).collection(`tableEntities`);i.getOrCreate(t,e=>Qb({id:e})),i.updateOne(t,e=>{e.ui.x=n,e.ui.y=r})},ax=D(G.removeTable),ox=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();j(t).collection(`tableEntities`).removeOperator(n,o,r,()=>{let t=e.tableIds.indexOf(r);t!==-1&&e.tableIds.splice(t,1)})},sx=D(G.changeTableName),cx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableEntities`);c.getOrCreate(n,e=>Qb({id:e})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=r,e.ui.widthName=V(a(r))})})},lx=D(G.changeTableComment),ux=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableEntities`);c.getOrCreate(n,e=>Qb({id:e})),c.replaceOperator(t,s,n,`comment`,()=>{c.updateOne(n,e=>{e.comment=r,e.ui.widthComment=V(a(r))})})},dx=D(G.changeTableColor),fx=({collections:e,lww:t},{payload:{id:n,color:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableEntities`);s.getOrCreate(n,e=>Qb({id:e})),s.replaceOperator(t,o,n,`ui.color`,()=>{s.updateOne(n,e=>{e.ui.color=r})})},px=D(G.changeZIndex),mx=({collections:e},{payload:{id:t,zIndex:n}})=>{let r=j(e).collection(`tableEntities`);r.getOrCreate(t,e=>Qb({id:e})),r.updateOne(t,e=>{e.ui.zIndex=n})},hx=D(G.sortTable),gx=e=>{let{doc:t,settings:n,collections:r}=e,i=n.width,a=j(r).collection(`tableEntities`).selectByIds(t.tableIds);a.sort((e,t)=>e.columnIds.length-t.columnIds.length);let o=50,s=50,c=50;a.forEach(t=>{let n=Oh(t,e).width+80,r=Mh(t)+80;o+n>i&&(s+=c,c=0,o=50),c<r&&(c=r),t.ui.y=s,t.ui.x=o,o+=n})},_x={[G.addTable]:ex,[G.moveTable]:nx,[G.moveToTable]:ix,[G.removeTable]:ox,[G.changeTableName]:cx,[G.changeTableComment]:ux,[G.changeTableColor]:fx,[G.changeZIndex]:mx,[G.sortTable]:gx},vx={addTableAction:$b,moveTableAction:tx,moveToTableAction:rx,removeTableAction:ax,changeTableNameAction:sx,changeTableCommentAction:lx,changeTableColorAction:dx,changeZIndexAction:px,sortTableAction:hx},yx=(e,{payload:{id:t}})=>{e.push(ax({id:t}))},bx=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`tableEntities`).selectById(t);r&&e.push($b({id:r.id,ui:ve(r.ui,[`x`,`y`,`zIndex`])}))},xx=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`tableEntities`).selectById(t);r&&e.push(sx({id:t,value:r.name}))},Sx=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`tableEntities`).selectById(t);r&&e.push(lx({id:t,value:r.comment}))},Cx=(e,{payload:{id:t}},{collections:n})=>{let r=j(n).collection(`tableEntities`).selectById(t);r&&e.push(rx({id:t,x:r.ui.x,y:r.ui.y}))},wx=()=>{},Tx={[G.addTable]:yx,[G.removeTable]:bx,[G.changeTableName]:xx,[G.changeTableComment]:Sx,[G.moveToTable]:Cx,[G.sortTable]:wx},Ex=(e,t,n)=>{let r=n.filter(e=>e.type===tx.type);if(!r.length)return;let i=ce(r,e=>e.payload.ids.join(`,`));for(let[,n]of Object.entries(i)){let{payload:{ids:r}}=le(n),{x:i,y:a}=n.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(tx({ids:r,movementX:-1*i,movementY:-1*a})),t.push(tx({ids:r,movementX:i,movementY:a})))}},Dx=(e,t,n)=>{let r=n.filter(({type:e})=>e===dx.type);if(!r.length)return;let i=ce(r,e=>e.payload.id);for(let[n,r]of Object.entries(i)){let i=le(r),a=me(r);e.push(dx({id:n,color:i.payload.prevColor,prevColor:a.payload.color})),t.push(dx({id:n,color:a.payload.color,prevColor:i.payload.prevColor}))}},Ox={[G.moveTable]:Ex,[G.changeTableColor]:Dx},K={addColumn:`column.add`,removeColumn:`column.remove`,changeColumnName:`column.changeName`,changeColumnComment:`column.changeComment`,changeColumnDataType:`column.changeDataType`,changeColumnDefault:`column.changeDefault`,changeColumnAutoIncrement:`column.changeAutoIncrement`,changeColumnPrimaryKey:`column.changePrimaryKey`,changeColumnUnique:`column.changeUnique`,changeColumnNotNull:`column.changeNotNull`,moveColumn:`column.move`},kx=e=>We({id:x(),tableId:``,name:``,comment:``,dataType:``,default:``,options:0,ui:{keys:0,widthName:60,widthComment:60,widthDataType:60,widthDefault:60},meta:m_()},e??{}),Ax=D(K.addColumn),jx=({collections:e,lww:t},{payload:{id:n,tableId:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableEntities`),c=s.getOrCreate(r,e=>Qb({id:e}));j(e).collection(`tableColumnEntities`).addOne(kx({id:n,tableId:r})).addOperator(t,o,n,()=>{B(c.columnIds)(n)||s.updateOne(r,e=>{By(e.columnIds,e.seqColumnIds,n)})})},Mx=D(K.removeColumn),Nx=({collections:e,lww:t},{payload:{id:n,tableId:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableEntities`),c=s.getOrCreate(r,e=>Qb({id:e}));j(e).collection(`tableColumnEntities`).removeOperator(t,o,n,()=>{let e=c.columnIds.indexOf(n);e!==-1&&s.updateOne(r,t=>{t.columnIds.splice(e,1)})})},Px=D(K.changeColumnName),Fx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>kx({id:e})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=r,e.ui.widthName=V(a(r))})})},Ix=D(K.changeColumnComment),Lx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>kx({id:e})),c.replaceOperator(t,s,n,`comment`,()=>{c.updateOne(n,e=>{e.comment=r,e.ui.widthComment=V(a(r))})})},Rx=D(K.changeColumnDataType),zx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>kx({id:e})),c.replaceOperator(t,s,n,`dataType`,()=>{c.updateOne(n,e=>{e.dataType=r,e.ui.widthDataType=V(a(r))})})},Bx=D(K.changeColumnDefault),Vx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=j(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>kx({id:e})),c.replaceOperator(t,s,n,`default`,()=>{c.updateOne(n,e=>{e.default=r,e.ui.widthDefault=V(a(r))})})},Hx=D(K.changeColumnAutoIncrement),Ux=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>kx({id:e})),s.replaceOperator(t,o,n,`options(autoIncrement)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|L.autoIncrement:e.options&~L.autoIncrement})})},Wx=D(K.changeColumnPrimaryKey),Gx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>kx({id:e})),s.replaceOperator(t,o,n,`options(primaryKey)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|L.primaryKey:e.options&~L.primaryKey,e.ui.keys=r?e.ui.keys|R.primaryKey:e.ui.keys&~R.primaryKey})})},Kx=D(K.changeColumnUnique),qx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>kx({id:e})),s.replaceOperator(t,o,n,`options(unique)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|L.unique:e.options&~L.unique})})},Jx=D(K.changeColumnNotNull),Yx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=j(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>kx({id:e})),s.replaceOperator(t,o,n,`options(notNull)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|L.notNull:e.options&~L.notNull})})},Xx=D(K.moveColumn),Zx=({collections:e},{payload:{id:t,tableId:n,targetId:r}})=>{if(t===r)return;let i=j(e).collection(`tableEntities`),a=i.getOrCreate(n,e=>Qb({id:e})),o=a.columnIds.indexOf(t);if(o===-1)return;let s=a.columnIds.indexOf(r);s!==-1&&i.updateOne(n,e=>{e.columnIds.splice(o,1),e.columnIds.splice(s,0,t);let n=e.seqColumnIds.indexOf(t),i=e.seqColumnIds.indexOf(r);n!==-1&&i!==-1&&(e.seqColumnIds.splice(n,1),e.seqColumnIds.splice(i,0,t))})},Qx={[K.addColumn]:jx,[K.removeColumn]:Nx,[K.changeColumnName]:Fx,[K.changeColumnComment]:Lx,[K.changeColumnDataType]:zx,[K.changeColumnDefault]:Vx,[K.changeColumnAutoIncrement]:Ux,[K.changeColumnPrimaryKey]:Gx,[K.changeColumnUnique]:qx,[K.changeColumnNotNull]:Yx,[K.moveColumn]:Zx},$x={addColumnAction:Ax,removeColumnAction:Mx,changeColumnNameAction:Px,changeColumnCommentAction:Ix,changeColumnDataTypeAction:Rx,changeColumnDefaultAction:Bx,changeColumnAutoIncrementAction:Hx,changeColumnPrimaryKeyAction:Wx,changeColumnUniqueAction:Kx,changeColumnNotNullAction:Jx,moveColumnAction:Xx},eS=(e,{payload:{id:t,tableId:n}})=>{e.push(Mx({id:t,tableId:n}))},tS=(e,{payload:{id:t,tableId:n}})=>{e.push(Ax({id:t,tableId:n}))},nS=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=j(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(Px({id:t,tableId:n,value:i.name}))},rS=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=j(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(Rx({id:t,tableId:n,value:i.dataType}))},iS=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=j(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(Bx({id:t,tableId:n,value:i.default}))},aS=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=j(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(Ix({id:t,tableId:n,value:i.comment}))},oS=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{j(i).collection(`tableColumnEntities`).selectById(t)&&e.push(Hx({id:t,tableId:n,value:!r}))},sS=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{j(i).collection(`tableColumnEntities`).selectById(t)&&e.push(Jx({id:t,tableId:n,value:!r}))},cS=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{j(i).collection(`tableColumnEntities`).selectById(t)&&e.push(Wx({id:t,tableId:n,value:!r}))},lS=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{j(i).collection(`tableColumnEntities`).selectById(t)&&e.push(Kx({id:t,tableId:n,value:!r}))},uS=(e,{payload:{id:t,tableId:n,targetId:r}},{collections:i})=>{let a=j(i).collection(`tableEntities`).selectById(n);if(!a)return;let o=a.columnIds.indexOf(t);if(o===-1)return;let s=a.columnIds.indexOf(r);if(s===-1)return;let c=o<s?o+1:o-1,l=a.columnIds[c];e.push(Xx({id:t,tableId:n,targetId:l}))},dS={[K.addColumn]:eS,[K.removeColumn]:tS,[K.changeColumnName]:nS,[K.changeColumnDataType]:rS,[K.changeColumnDefault]:iS,[K.changeColumnComment]:aS,[K.changeColumnAutoIncrement]:oS,[K.changeColumnNotNull]:sS,[K.changeColumnPrimaryKey]:cS,[K.changeColumnUnique]:lS,[K.moveColumn]:uS};function fS(e,...t){try{return e?.(...t)}catch(e){console.error(e)}}const pS={...Tx,...dS,...Wb,...Eb,...Jb,...by,...Ly,...tb},mS={...Ox,...Ab,...Zb};function hS(e,t,n){let r=[],i=[];for(let t of n){let n=pS[t.type];n&&(n(r,t,e.state),i.push(oe(t)))}for(let e of Object.keys(mS))mS[e](r,i,n);!r.length||!i.length||t.push({undo:(e,t)=>{e(r.map(gS(t())))},redo:(e,t)=>{e(i.map(gS(t())))}})}function gS(e){return t=>({...oe(t),version:e})}const _S=(e,t)=>n=>{fS(hS,e,t,n)},vS=()=>function*({settings:e,doc:{tableIds:t,memoIds:n},collections:r}){let i=j(r).collection(`tableEntities`).selectByIds(t),a=j(r).collection(`memoEntities`).selectByIds(n),o=p_(e,i,a),s=x();yield dk(),yield $_({[s]:s_.memo}),yield ib({id:s,ui:{...o,zIndex:d_(i,a)}})},yS=e=>function*({editor:{selectedMap:t}}){if(e){yield ub({id:e});return}let n=Object.entries(t).filter(([,e])=>e===s_.memo);for(let[e]of n)yield ub({id:e})},bS=(e,t)=>function*({doc:{tableIds:n,memoIds:r},collections:i}){let a=j(i).collection(`tableEntities`).selectByIds(n),o=j(i).collection(`memoEntities`).selectByIds(r);t||(yield dk()),yield $_({[e]:s_.memo}),yield vb({id:e,zIndex:d_(a,o)})},xS={addMemoAction$:vS,removeMemoAction$:yS,selectMemoAction$:bS};B(Object.values({tables:`tables`,columns:`columns`}));const SS=({x:e,y:t})=>`${e},${t}`,CS=(e,t)=>e<t?-1:+(e>t),wS=e=>e.ui.zIndex??0;function TS({entities:e,offset:t,escapeCollision:n,settings:r,tables:i,memos:a,findSource:o}){let s=new Map;if(e.length===0)return s;let c=new Set([...i,...a].map(({ui:e})=>SS(e))),l=new Map,u=[];for(let n of e){let e=o(n.sourceId);e?l.set(n.sourceId,{x:e.ui.x+t.x,y:e.ui.y+t.y}):u.push(n)}if(u.length!==0){let e=p_(r,i,a),t=u.reduce((e,t)=>t.ui.x<e.ui.x||t.ui.x===e.ui.x&&t.ui.y<e.ui.y?t:e);for(let n of u)l.set(n.sourceId,{x:e.x+(n.ui.x-t.ui.x),y:e.y+(n.ui.y-t.ui.y)})}if(n){let t=[...e].sort((e,t)=>CS(e.sourceId,t.sourceId));for(let{sourceId:e}of t){let t=l.get(e);if(t){for(;c.has(SS(t));)t.x+=50,t.y+=50;c.add(SS(t))}}}let d=d_(i,a);return[...e].sort((e,t)=>wS(e)-wS(t)||CS(e.sourceId,t.sourceId)).forEach(({sourceId:e},t)=>{let n=l.get(e);n&&s.set(e,{x:n.x,y:n.y,zIndex:d+t})}),s}B(Object.values({columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnDefault:`columnDefault`,columnComment:`columnComment`}));function ES(e,t){return t.filter(t=>{switch(t){case P.columnName:return!0;case P.columnDataType:return z(e,N.columnDataType);case P.columnDefault:return z(e,N.columnDefault);case P.columnComment:return z(e,N.columnComment);case P.columnAutoIncrement:return z(e,N.columnAutoIncrement);case P.columnUnique:return z(e,N.columnUnique);case P.columnNotNull:return z(e,N.columnNotNull);default:return!1}})}const DS=()=>function*({settings:e,doc:{tableIds:t,memoIds:n},collections:r}){let i=j(r).collection(`tableEntities`).selectByIds(t),a=j(r).collection(`memoEntities`).selectByIds(n),o=p_(e,i,a),s=x();yield Z_(),yield $_({[s]:s_.table}),yield $b({id:s,ui:{...o,zIndex:d_(i,a)}}),yield fv({tableId:s})},OS=e=>function*({doc:{relationshipIds:t,indexIds:n},editor:{selectedMap:r},collections:i}){let a=j(i).collection(`relationshipEntities`).selectByIds(t),o=j(i).collection(`indexEntities`).selectByIds(n);if(e){let t=a.filter(({start:t,end:n})=>t.tableId===e||n.tableId===e),n=o.filter(({tableId:t})=>t===e);for(let{id:e}of n)yield Ty({id:e});for(let{id:e}of t)yield Fb({id:e});yield ax({id:e});return}let s=Object.entries(r).filter(([,e])=>e===s_.table).map(([e])=>e),c=B(s),l=a.filter(({start:e,end:t})=>c(e.tableId)||c(t.tableId)),u=o.filter(({tableId:e})=>c(e));for(let{id:e}of u)yield Ty({id:e});for(let{id:e}of l)yield Fb({id:e});for(let e of s)yield ax({id:e})},kS=(e,t)=>function*({doc:{tableIds:n,memoIds:r},collections:i,editor:{drawRelationship:a}}){let o=j(i).collection(`tableEntities`),s=o.selectByIds(n),c=j(i).collection(`memoEntities`).selectByIds(r);if(t||(yield Z_()),yield $_({[e]:s_.table}),yield px({id:e,zIndex:d_(s,c)}),yield fv({tableId:e}),a){if(a.start){let t=o.selectById(a.start.tableId),n=o.selectById(e);if(!t||!n)return;let r=j(i).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(({options:e})=>z(e,L.primaryKey));if(!r.length)return;let s=r.map(()=>x());for(let e=0;e<r.length;e++){let t=r[e],i={id:s[e],tableId:n.id};yield[Ax(i),Jx({...i,value:!0}),Px({...i,value:t.name}),Rx({...i,value:t.dataType}),Bx({...i,value:t.default}),Ix({...i,value:t.comment})]}yield Nb({id:x(),relationshipType:a.relationshipType,start:{tableId:t.id,columnIds:r.map(({id:e})=>e)},end:{tableId:n.id,columnIds:s}}),yield Iv()}else yield mk(e)}},AS={addTableAction$:DS,removeTableAction$:OS,selectTableAction$:kS,pasteTableAction$:e=>function*({editor:{selectedMap:t,focusTable:n},settings:{show:r,columnOrder:i},collections:a}){let o=n&&!L_(n.focusType),s=Object.entries(t).filter(([,e])=>e===s_.table).map(([e])=>e).filter(e=>!o||e!==n?.tableId);for(let t of s)for(let n of e){let e={id:x(),tableId:t};yield[Ax(e),Px({...e,value:n.name}),Rx({...e,value:n.dataType}),Bx({...e,value:n.default}),Ix({...e,value:n.comment}),Jx({...e,value:z(n.options,L.notNull)}),Kx({...e,value:z(n.options,L.unique)}),Hx({...e,value:z(n.options,L.autoIncrement)})]}if(!n||!o)return;let c=j(a).collection(`tableEntities`).selectById(n.tableId);if(!c)return;let l=c.columnIds.filter(B(n.selectColumnIds));if(l.length===0)return;let u=c.columnIds.slice(c.columnIds.indexOf(l[l.length-1])+1),d=[...l,...u],f=ES(r,i);yield gv();for(let t=0;t<d.length;t++){let r=d[t],i=e[t];if(!i)break;let a={id:r,tableId:c.id};yield[...f.map(e=>{switch(e){case P.columnName:return Px({...a,value:i.name});case P.columnDataType:return Rx({...a,value:i.dataType});case P.columnDefault:return Bx({...a,value:i.default});case P.columnComment:return Ix({...a,value:i.comment});case P.columnAutoIncrement:return Hx({...a,value:z(i.options,L.autoIncrement)});case P.columnUnique:return Kx({...a,value:z(i.options,L.unique)});case P.columnNotNull:return Jx({...a,value:z(i.options,L.notNull)});default:return null}}).filter(Boolean),mv({tableId:c.id,columnId:r,focusType:n.focusType,$mod:!0,shiftKey:!1})]}let p=e.slice(d.length);for(let e of p){let t=x(),r={id:t,tableId:c.id};yield[Ax(r),...f.map(t=>{switch(t){case P.columnName:return Px({...r,value:e.name});case P.columnDataType:return Rx({...r,value:e.dataType});case P.columnDefault:return Bx({...r,value:e.default});case P.columnComment:return Ix({...r,value:e.comment});case P.columnAutoIncrement:return Hx({...r,value:z(e.options,L.autoIncrement)});case P.columnUnique:return Kx({...r,value:z(e.options,L.unique)});case P.columnNotNull:return Jx({...r,value:z(e.options,L.notNull)});default:return null}}).filter(Boolean),mv({tableId:c.id,columnId:t,focusType:n.focusType,$mod:!0,shiftKey:!1})]}}};function jS(e,t,n,r=[]){let{doc:{relationshipIds:i},collections:a}=t,o=e.pop();return o&&(r.some(({id:e})=>e===o.id)||(r.push(o),j(a).collection(`relationshipEntities`).selectByIds(i).forEach(({start:t,end:r})=>{let i=t.columnIds.indexOf(o.id);if(i!==-1){let t=r.columnIds[i];e.push({id:t,tableId:r.tableId,value:n.value})}else{let i=r.columnIds.indexOf(o.id);if(i!==-1){let r=t.columnIds[i];e.push({id:r,tableId:t.tableId,value:n.value})}}})),jS(e,t,n,r)),r}const MS=B([W.columnNotNull,W.columnUnique,W.columnAutoIncrement]),NS=B([W.columnName,W.columnDataType,W.columnDefault,W.columnComment]),PS=e=>function*({editor:{selectedMap:t}}){if(e){let t=x();yield Ax({id:t,tableId:e}),yield mv({tableId:e,columnId:t,focusType:W.columnName,$mod:!1,shiftKey:!1});return}let n=Object.entries(t).filter(([,e])=>e===s_.table).map(([e])=>({tableId:e,id:x()}));for(let e of n)yield Ax(e);let r=me(n);r&&(yield mv({tableId:r.tableId,columnId:r.id,focusType:W.columnName,$mod:!1,shiftKey:!1}))},FS=(e,t)=>function*(n){let{doc:{relationshipIds:r,indexIds:i},editor:{focusTable:a},collections:o}=n;if(a?.columnId){let e=N_(n,t);e?yield mv({tableId:a.tableId,columnId:e,focusType:a.focusType,$mod:!1,shiftKey:!1}):yield fv({tableId:a.tableId,focusType:W.tableName})}let s=B(t),c=j(o).collection(`relationshipEntities`).selectByIds(r).filter(({start:t,end:n})=>t.tableId===e&&t.columnIds.some(s)||n.tableId===e&&n.columnIds.some(s)),l=j(o).collection(`indexEntities`).selectByIds(i).filter(t=>t.tableId===e&&j(o).collection(`indexColumnEntities`).selectByIds(t.indexColumnIds).map(({columnId:e})=>e).some(s));for(let{id:e}of l)yield Ty({id:e});for(let{id:e}of c)yield Fb({id:e});for(let n of t)yield Mx({id:n,tableId:e})},IS=(e,t,n)=>function*({collections:r}){if(!MS(e))return;let i=j(r).collection(`tableColumnEntities`).selectById(n);if(i)switch(e){case W.columnNotNull:yield Jx({id:n,tableId:t,value:!z(i.options,L.notNull)});break;case W.columnUnique:yield Kx({id:n,tableId:t,value:!z(i.options,L.unique)});break;case W.columnAutoIncrement:yield Hx({id:n,tableId:t,value:!z(i.options,L.autoIncrement)})}},LS=e=>function*(t){let{settings:{relationshipDataTypeSync:n}}=t,r=[e];n&&(r=jS([e],t,e)),yield r.map(Rx)},RS={addColumnAction$:PS,removeColumnAction$:FS,toggleColumnValueAction$:IS,changeColumnDataTypeAction$:LS,changeColumnValueAction$:(e,t,n,r)=>function*({collections:i}){if(!NS(e)||!j(i).collection(`tableColumnEntities`).selectById(n))return;let a={id:n,tableId:t,value:r};switch(e){case W.columnName:yield Px(a);break;case W.columnDataType:yield LS(a);break;case W.columnDefault:yield Bx(a);break;case W.columnComment:yield Ix(a)}},changeColumnPrimaryKeyAction$:(e,t)=>function*({collections:n}){let r=j(n).collection(`tableColumnEntities`).selectById(t);if(!r)return;let i=z(r.options,L.primaryKey);yield Wx({tableId:e,id:t,value:!i})}};function zS(e,t){return!(e.x>t.x+t.w||e.x+e.w<t.x||e.y>t.y+t.h||e.y+e.h<t.y)}function BS(e){return e.filter(({options:e})=>z(e,L.primaryKey))}function VS(e,t,n,r=1){let i=!0;for(let r of e)if(n===r.name&&r.id!==t&&n!==``){i=!1;break}return i?n:VS(e,t,n.replace(/[0-9]/g,``)+r,r+1)}function HS(e,t){for(let n of e)if(n.name.toUpperCase()===t.toUpperCase())return n;return null}const US={[F.MariaDB]:`VARCHAR(255)`,[F.MSSQL]:`varchar(255)`,[F.MySQL]:`VARCHAR(255)`,[F.Oracle]:`VARCHAR2(255)`,[F.PostgreSQL]:`varchar(255)`,[F.SQLite]:`TEXT`,[F.Databricks]:`STRING`,[F.Snowflake]:`VARCHAR(255)`};function WS(e,t,n,r=[]){let i=qS(e,n,r);return i.members?KS(i.members,t)??US[t]??i.typeName:i.typeName}function GS(e,t,n,r=[]){let{members:i}=qS(e,t,r);return!i||KS(i,n)!==void 0?``:` ${e}: ${i.join(` | `)}`}function KS(e,t){if(t===F.MySQL||t===F.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function qS(e,t,n){if(n.length)return{typeName:e,members:n};let r=new Set,i=e;for(;!r.has(i);){r.add(i);let e=JS(i,t);if(!e)break;if(e.values.length)return{typeName:i,members:e.values};if(!e.alias)break;i=e.alias}return{typeName:i,members:null}}function JS(e,t){let n=t.types[e];if(n)return n;let r=Object.keys(t.types).find(t=>t.slice(t.lastIndexOf(`.`)+1)===e);return r===void 0?void 0:t.types[r]}const YS={database:``,catalog:``,schema:``},XS=$S(YS);function ZS(e,t,n){let r=Bp({}),i=QS(e.entities),a=e.entities.map(a=>nC(r,t,e,n,a,i(a)));return aC(r,t,a,e,tC(e.entities,a)),uC(r,a),r}function QS(e){let t=new Set(e.map(e=>$S(e.namespace)));return e=>{let n=$S(e.namespace);return t.size>1&&n!==XS?`${eC(e.namespace)}_${e.name}`:e.name}}function $S({database:e,catalog:t,schema:n}){return`${e}.${t}.${n}`}function eC({database:e,catalog:t,schema:n}){return[e,t,n].filter(e=>e!==``).join(`_`)}function tC(e,t){let n=new Map,r=(e,t)=>{let r=e.toLowerCase();n.has(r)||n.set(r,t)};return e.forEach((e,n)=>{let i=t[n],a=$S(e.namespace);r(`${a}.${e.name}`,i),r(e.name,i),e.alias&&(r(e.alias,i),r(`${a}.${e.alias}`,i))}),e=>{let t=$S(e.namespace);return n.get(`${t}.${e.entityName}`.toLowerCase())??(t===XS?n.get(e.entityName.toLowerCase())??null:null)}}function nC({doc:e,collections:t},n,r,i,a,o){let{toWidth:s}=n,c=Ch(o),l=Ch(a.comment),u=Qb({name:c,comment:l,ui:{widthName:V(s(c)),widthComment:V(s(l))}}),d={source:a,table:u,columns:[]};return a.attributes.forEach(e=>{let n=Ch(e.path),a=WS(e.typeName,i,r,e.enumValues),o=`${Ch(e.comment)}${GS(e.typeName,r,i,e.enumValues)}`.trim(),c=Ch(e.default);iC(t,d,kx({tableId:u.id,name:n,comment:o,dataType:a,default:c,options:(e.autoIncrement?L.autoIncrement:0)|(e.primaryKey?L.primaryKey:0)|(rC(e)?L.unique:0)|(e.notNull?L.notNull:0),ui:{widthName:V(s(n)),widthComment:V(s(o)),widthDataType:V(s(a)),widthDefault:V(s(c)),keys:e.primaryKey?R.primaryKey:0}}))}),e.tableIds.push(u.id),j(t).collection(`tableEntities`).setOne(u),d}function rC(e){return e.indexes.some(e=>e.unique&&e.name===``)}function iC(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),j(e).collection(`tableColumnEntities`).setOne(n)}function aC(e,t,n,r,i){let a=new Set;r.relations.forEach(r=>{let o=i(r.src),s=i(r.ref);if(!o||!s)return;let c=oC(o,r.src),l=oC(s,r.ref);if(c.length!==0&&l.length!==0&&c.length===l.length){if(r.srcCardinality===`n`&&r.refCardinality===`n`){cC(e,t,n,o,s);return}sC(e,t,a,{parent:s,parentColumns:l,child:o,childColumns:c,toMany:r.refCardinality===`n`})}})}function oC(e,t){if(t.attributePaths.length===0)return BS(e.columns);let n=[];for(let r of t.attributePaths){let t=HS(e.columns,r);if(!t)return[];n.push(t)}return n}function sC({doc:e,collections:t},{toWidth:n},r,{parent:i,parentColumns:a,child:o,childColumns:s,toMany:c}){let l=`${i.table.id}:${o.table.id}:${s.map(e=>e.id).join(`,`)}`;if(r.has(l))return;r.add(l);let u=s.every(e=>z(e.options,L.notNull));s.forEach((e,t)=>{if(e.dataType===``){let{dataType:r}=a[t];e.dataType=r,e.ui.widthDataType=V(n(r))}e.ui.keys=z(e.ui.keys,R.primaryKey)?e.ui.keys|R.foreignKey:R.foreignKey});let d=Mb({identification:s.every(e=>z(e.ui.keys,R.primaryKey)&&z(e.ui.keys,R.foreignKey)),relationshipType:c?u?Ym.OneN:Ym.ZeroN:u?Ym.OneOnly:Ym.ZeroOne,start:{tableId:i.table.id,columnIds:a.map(e=>e.id)},end:{tableId:o.table.id,columnIds:s.map(e=>e.id)}});e.relationshipIds.push(d.id),j(t).collection(`relationshipEntities`).setOne(d)}function cC(e,t,n,r,i){let{doc:a,collections:o}=e,{toWidth:s}=t,c=BS(r.columns),l=BS(i.columns);if(!c.length||!l.length)return;let u=VS(n.map(e=>e.table),``,`${r.table.name}_${i.table.name}`),d=`Junction table inferred from ${r.table.name} <-> ${i.table.name}`,f=Qb({name:u,comment:d,ui:{widthName:V(s(u)),widthComment:V(s(d))}}),p={source:{namespace:YS,name:u,alias:``,comment:d,attributes:[]},table:f,columns:[]};a.tableIds.push(f.id),j(o).collection(`tableEntities`).setOne(f),n.push(p),lC(e,t,p,r,c),lC(e,t,p,i,l)}function lC(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=VS(n.columns,``,`${r.table.name}_${e.name}`),{dataType:a}=e,s=kx({tableId:n.table.id,name:i,dataType:a,options:L.primaryKey|L.notNull,ui:{keys:R.primaryKey|R.foreignKey,widthName:V(t(i)),widthDataType:V(t(a))}});return iC(o,n,s),s}),c=Mb({identification:!0,relationshipType:Ym.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),j(o).collection(`relationshipEntities`).setOne(c)}function uC({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{let a=new Map;n.attributes.forEach((e,t)=>{let n=i[t];n&&e.indexes.forEach((e,i)=>{if(e.unique&&e.name===``)return;let o=e.name===``?`b:${t}:${i}`:`n:${e.name}`,s=a.get(o)??{index:Sy({name:Ch(e.name),tableId:r.id}),indexColumns:[]};s.index.unique=s.index.unique||e.unique,s.indexColumns.push(zy({indexId:s.index.id,columnId:n.id,orderType:Zm.ASC})),a.set(o,s)})}),a.forEach(({index:n,indexColumns:r})=>{r.forEach(e=>{n.indexColumnIds.push(e.id),n.seqIndexColumnIds.push(e.id),j(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(n.id),j(t).collection(`indexEntities`).setOne(n)})})}const q={identifier:1,quoted:2,string:3,expression:4,number:5,punctuation:6,doc:7,comment:8,newline:9},dC=/[ \t\f\v]/,fC=/[0-9]/,pC=/[A-Za-z_\u0080-\uffff]/,mC=/[0-9A-Za-z_#\u0080-\uffff]/,hC=/^[ \t]*/,gC=/\\#/g,_C={n:`
|
|
2
|
-
`};function
|
|
1
|
+
import*as e from"comlink";import{CHARSET as t,DECLARATION as n,IMPORT as r,LAYER as i,NAMESPACE as a,RULESET as o,alloc as s,dealloc as c,parse as l}from"stylis";import{Container as u}from"konva/lib/Container";import{Group as d}from"konva/lib/Group";import{Layer as f}from"konva/lib/Layer";import{Node as p}from"konva/lib/Node";import{Circle as m}from"konva/lib/shapes/Circle";import{Line as h}from"konva/lib/shapes/Line";import{Path as g}from"konva/lib/shapes/Path";import{Rect as _}from"konva/lib/shapes/Rect";import{Text as v}from"konva/lib/shapes/Text";import{Stage as y}from"konva/lib/Stage";import{DD as ee}from"konva/lib/DragAndDrop";import{Konva as te}from"konva/lib/Global";import{camelCase as ne,clamp as re,cloneDeep as ie,difference as ae,groupBy as b,head as oe,isBoolean as se,isEqual as ce,isFunction as le,isNil as x,isNotNil as ue,isNumber as S,isPlainObject as de,isString as C,last as fe,lowerFirst as pe,noop as me,omit as he,pick as ge,range as _e,snakeCase as ve,uniq as ye,upperFirst as be}from"es-toolkit";import{Observable as xe,Subject as Se,animationFrames as Ce,asapScheduler as we,buffer as Te,debounceTime as Ee,defer as De,filter as Oe,fromEvent as ke,groupBy as Ae,map as je,merge as Me,mergeMap as Ne,observeOn as Pe,share as Fe,startWith as Ie,switchMap as Le,take as Re,takeUntil as ze,tap as Be,throttle as Ve,throttleTime as He,timer as Ue}from"rxjs";import{get as We,isEmpty as Ge,round as Ke}from"es-toolkit/compat";import{nanoid as qe}from"nanoid";import Je from"deepmerge";import{Kind as Ye,TokenKind as Xe,parse as Ze}from"graphql";import Qe,{getAccurateAgent as $e}from"@egjs/agent";import{ArrowRight as et,Atom as tt,Braces as nt,Brackets as rt,CaseSensitive as it,Check as at,ChevronDown as ot,ChevronRight as st,Code as ct,Contrast as lt,Copy as ut,Database as dt,Diff as ft,ExternalLink as pt,Eye as mt,FileDiff as ht,FileImage as gt,FileInput as _t,FileOutput as vt,Fullscreen as yt,GripVertical as bt,Hand as xt,KeyRound as St,Maximize as Ct,Minimize as wt,Minus as Tt,MoonStar as Et,MousePointer2 as Dt,Network as Ot,Palette as kt,Plus as At,Redo2 as jt,RefreshCw as Mt,RotateCcwClock as Nt,Search as Pt,Settings as Ft,Share2 as It,Spline as Lt,StickyNote as Rt,Sun as zt,Table as Bt,Table2 as Vt,TableProperties as Ht,Undo2 as Ut,WandSparkles as Wt,Waypoints as Gt,Workflow as Kt,X as qt}from"lucide";import{amber as Jt,amberA as Yt,amberDark as Xt,amberDarkA as Zt,blue as Qt,blueA as $t,blueDark as en,blueDarkA as tn,bronze as nn,bronzeA as rn,bronzeDark as an,bronzeDarkA as on,brown as sn,brownA as cn,brownDark as ln,brownDarkA as un,crimson as dn,crimsonA as fn,crimsonDark as pn,crimsonDarkA as mn,cyan as hn,cyanA as gn,cyanDark as _n,cyanDarkA as vn,gold as yn,goldA as bn,goldDark as xn,goldDarkA as Sn,grass as Cn,grassA as wn,grassDark as Tn,grassDarkA as En,gray as Dn,grayA as On,grayDark as kn,grayDarkA as An,green as jn,greenA as Mn,greenDark as Nn,greenDarkA as Pn,indigo as Fn,indigoA as In,indigoDark as Ln,indigoDarkA as Rn,iris as zn,irisA as Bn,irisDark as Vn,irisDarkA as Hn,jade as Un,jadeA as Wn,jadeDark as Gn,jadeDarkA as Kn,lime as qn,limeA as Jn,limeDark as Yn,limeDarkA as Xn,mauve as Zn,mauveA as Qn,mauveDark as $n,mauveDarkA as er,mint as tr,mintA as nr,mintDark as rr,mintDarkA as ir,olive as ar,oliveA as or,oliveDark as sr,oliveDarkA as cr,orange as lr,orangeA as ur,orangeDark as dr,orangeDarkA as fr,pink as pr,pinkA as mr,pinkDark as hr,pinkDarkA as gr,plum as _r,plumA as vr,plumDark as yr,plumDarkA as br,purple as xr,purpleA as Sr,purpleDark as Cr,purpleDarkA as wr,red as Tr,redA as Er,redDark as Dr,redDarkA as Or,ruby as kr,rubyA as Ar,rubyDark as jr,rubyDarkA as Mr,sage as Nr,sageA as Pr,sageDark as Fr,sageDarkA as Ir,sand as Lr,sandA as Rr,sandDark as zr,sandDarkA as Br,sky as Vr,skyA as Hr,skyDark as Ur,skyDarkA as Wr,slate as Gr,slateA as Kr,slateDark as qr,slateDarkA as Jr,teal as Yr,tealA as Xr,tealDark as Zr,tealDarkA as Qr,tomato as $r,tomatoA as ei,tomatoDark as ti,tomatoDarkA as ni,violet as ri,violetA as ii,violetDark as ai,violetDarkA as oi,yellow as si,yellowA as ci,yellowDark as li,yellowDarkA as ui}from"@radix-ui/colors";import{layoutWithLines as di,prepareWithSegments as fi}from"@chenglou/pretext";import{Easings as pi,Tween as mi}from"konva/lib/Tween";function hi(e){"@babel/helpers - typeof";return hi=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},hi(e)}function gi(e,t){if(hi(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(hi(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _i(e){var t=gi(e,`string`);return hi(t)==`symbol`?t:t+``}function vi(e,t,n){return(t=_i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var yi=class extends EventTarget{constructor(...e){super(...e),vi(this,`textContent`,``)}},bi=class{};function xi(){let e=new OffscreenCanvas(1,1);return e.style??={},e}typeof document>`u`&&(Reflect.set(globalThis,`document`,{querySelector:()=>null,querySelectorAll:()=>[],createElement:e=>e===`canvas`?xi():new yi}),Reflect.set(globalThis,`Node`,bi),Reflect.set(globalThis,`HTMLElement`,bi));function Si(e,t){return Object.freeze({key:t??Symbol(),value:e})}var Ci={subscribe:`@@r-html/context-subscribe`,unsubscribe:`@@r-html/context-unsubscribe`};function wi(e,t){function n(n,r){return new CustomEvent(e,{detail:n,...t,...r})}return n.toString=()=>`${e}`,n.type=e,n}var Ti=wi(Ci.subscribe,{bubbles:!0,composed:!0}),Ei=wi(Ci.unsubscribe,{bubbles:!0,composed:!0});function Di(e,t){let n=e=>{let n=e;t.dispatchEvent(Ti(n.detail))},r=e=>{let n=e;t.dispatchEvent(Ei(n.detail))};return e.addEventListener(Ti.type,n),e.addEventListener(Ei.type,r),()=>{e.removeEventListener(Ti.type,n),e.removeEventListener(Ei.type,r)}}function Oi(e,...t){try{return e?.(...t)}catch(e){console.error(e)}}var ki=queueMicrotask??(e=>{Promise.resolve().then(e)}),Ai=e=>t=>typeof t===e,ji=Ai(`object`),Mi=Ai(`bigint`),Ni=Ai(`boolean`),Pi=Ai(`function`),Fi=Ai(`number`),Ii=Ai(`string`),Li=Ai(`symbol`),Ri=Ai(`undefined`),zi=e=>e===null,{isArray:Bi}=Array,Vi=e=>ji(e)&&!zi(e)&&!Bi(e),Hi=e=>Mi(e)||Ni(e)||Fi(e)||Ii(e)||Li(e)||Ri(e)||zi(e);function Ui(){let e=new Set,t=t=>(e.has(t)||e.add(t),()=>{e.delete(t)});return{subscribe:t,next:t=>{e.forEach(e=>e(t))},asReadonly:()=>({subscribe:t})}}var Wi=`...`,Gi=`@@r-html-${Math.random().toString().substring(2,8)}`,Ki=`${Wi}${Gi}`,qi=RegExp(`${Gi}_(\\d+)_`,`g`),Ji=RegExp(`^${Gi}_\\d+_$`),Yi=/^\n/,Xi=function(e){return e.attribute=`attribute`,e.boolean=`boolean`,e.event=`event`,e.property=`property`,e.spread=`spread`,e.directive=`directive`,e}({}),Zi=Symbol.for(`https://github.com/dineug/r-html#beforeMount`),Qi=Symbol.for(`https://github.com/dineug/r-html#mounted`),$i=Symbol.for(`https://github.com/dineug/r-html#unmounted`),ea=Symbol.for(`https://github.com/dineug/r-html#beforeFirstUpdate`),ta=Symbol.for(`https://github.com/dineug/r-html#beforeUpdate`),na=Symbol.for(`https://github.com/dineug/r-html#firstUpdated`),ra=Symbol.for(`https://github.com/dineug/r-html#updated`),ia=[Zi,Qi,$i,ea,ta,na,ra],aa=Symbol.for(`https://github.com/dineug/r-html#Directive`),oa=Symbol.for(`https://github.com/dineug/r-html#TemplateLiterals`),sa=null;function ca(e){sa=e}var la=e=>t=>{sa&&(sa[e]??(sa[e]=[])).push(t)},ua=la(Zi),da=la(Qi),fa=la($i);function pa(e,t){let n=Reflect.get(e,t,e);Bi(n)&&n.forEach(Oi)}function ma(e){ia.forEach(t=>Reflect.set(e,t,null,e))}function ha(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function w(e,t,n){ha(e,t),t.set(e,n)}function ga(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}function T(e,t,n){return e.set(ga(e,t),n),n}function E(e,t){return e.get(ga(e,t))}var _a=Ui(),va=e=>e,ya=e=>{var t,n;return t=new WeakMap,n=new WeakMap,class extends e{constructor(e,r,i,a){super(e,r,i,a),w(this,t,[]),w(this,n,null),this.hmr()}commit(e){let n=va(e);super.commit(n),T(t,this,e)}hmr(){T(n,this,_a.subscribe(e=>E(t,this).includes(e)&&this.commit(E(t,this))))}destroy(){E(n,this)?.call(this),super.destroy?.()}}},ba=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Ca=new WeakMap,wa=new WeakMap,Ta={shallow:!1},Ea=null;function Da(e){return Ea=e,Oi(e),Ea=null,()=>Oa(e)}function Oa(e){Ha(e);let t=wa.get(e);if(t)for(let[n]of t.entries())xa.get(n)?.delete(e);t&&wa.delete(e)}function ka(e){if(!Ea)return;let t=xa.get(e);t?t.has(Ea)||t.add(Ea):xa.set(e,new Set([Ea]))}function Aa(e,t){if(!Ea)return;let n=wa.get(Ea);if(n){let r=n.get(e);r?r.has(t)||r.add(t):n.set(e,new Set([t]))}else wa.set(Ea,new Map([[e,new Set([t])]]))}var ja=e=>e instanceof Node||e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof RegExp||e instanceof Date||e instanceof Promise||(Bi(e)||Vi(e))&&Object.isFrozen(e);function Ma(e,t={}){let{shallow:n}=Object.assign({},Ta,t),r=new Proxy(e,{get(r,i,a){let o=Reflect.get(r,i,a);return ja(o)?o:(ka(e),Aa(e,i),!n&&(Vi(o)||Bi(o))&&!Sa.has(o)?ba.has(o)?ba.get(o):Ma(o,t):o)},set(e,t,n,r){let i=Reflect.get(e,t,r),a=Reflect.set(e,t,n,r);return(!Bi(e)&&i!==n||t===`length`)&&(Ua(e,t),Ka(e,t)),a},deleteProperty(e,t){let n=Reflect.deleteProperty(e,t);return Ua(e,t),Ka(e,t),n}});return ba.set(e,r),Sa.set(r,e),r}function Na(e){return(Ca.get(e)??Ca.set(e,Ui()).get(e)).asReadonly()}var Pa=[],Fa=new Map,Ia=new Map,La=!0;function Ra(e,t,n){let r=wa.get(n);if(!r)return!1;let i=r.get(e);return i?i.has(t):!1}var za=e=>t=>{let n=Fa.get(t),r=()=>{},i=n?.promise?n.promise:new Promise(e=>{r=e});if(!n){let n={type:e,promise:i,fn:t,resolve:()=>{r()}};Pa.push(n),Fa.set(t,n)}return La&&=(ki(Ga),!1),i},Ba=za(`observer`),Va=za(`nextTick`);function Ha(e){let t=Fa.get(e);if(!t)return;let n=Pa.indexOf(t);n===-1||Pa.splice(n,1),Fa.delete(e),t.resolve()}var Ua=(e,t)=>xa.get(e)?.forEach(n=>Ra(e,t,n)&&Ba(n));function Wa(){let e=Pa.shift();if(e){if(Fa.delete(e.fn),e.type===`observer`)Oa(e.fn),Da(e.fn),e.resolve();else if(e.type===`nextTick`){let t=Oi(e.fn);t instanceof Promise?t.finally(e.resolve):e.resolve()}}}function Ga(){for(;Pa.length;)Wa();La=!0}function Ka(e,t){let n=ba.get(e);if(!n)return;let r=Ca.get(n);if(!r)return;let i=Ia.get(n);i?i.has(t)||i.add(t):(Ia.set(n,new Set([t])),Va(()=>{let e=Ia.get(n);e&&(Ia.delete(n),e.forEach(e=>r.next(e)))}))}function qa(e,t){let n=Ma({value:t.value},{shallow:!0}),r=e=>{n.value=e},i=()=>e instanceof HTMLElement?e:e.parentElement??e.host,a=()=>{i().dispatchEvent(Ti({context:t,observer:r}))};return a(),ua(a),fa(()=>{i().dispatchEvent(Ei({context:t,observer:r}))}),n}function Ja(e,t,n){let r=e instanceof HTMLElement?e:e.parentElement??e.host,i=Ui(),a=new Map,o=e=>{let r=e;r.detail?.context?.key===t.key&&(r.stopPropagation(),r.detail.observer(n),a.set(r.detail.observer,i.subscribe(r.detail.observer)))},s=e=>{let n=e;n.detail?.context?.key===t.key&&(n.stopPropagation(),a.get(n.detail.observer)?.(),a.delete(n.detail.observer))};return r.addEventListener(Ti.type,o),r.addEventListener(Ei.type,s),{set:e=>{i.next(e)},destroy:()=>{r.removeEventListener(Ti.type,o),r.removeEventListener(Ei.type,s);for(let e of a.values())e();a.clear()}}}var Ya=function(e){return e.node=`node`,e.attribute=`attribute`,e}({});function Xa(e,t){return Reflect.set(t,aa,e),t}function Za(e,t,n){let r={startNode:e,endNode:t};return Reflect.defineProperty(r,"helper",{value:n}),r}function Qa(e,t){return(...n)=>Xa(Ya.node,[e(...n),t])}var $a=function(e){return e.html=`html`,e.svg=`svg`,e.css=`css`,e}({}),eo=new Set(Object.values($a)),to=Symbol.for(`https://github.com/dineug/r-html#CSSSource`),no=new WeakMap,ro=new WeakMap,io=new Set([$a.svg]),ao=e=>`${Gi}_${e}_`,oo=e=>Bi(e)&&Bi(e.raw),so=e=>Vi(e)&&oo(e.strings)&&Bi(e.values)&&eo.has(Reflect.get(e,oa)??``),co=e=>so(e)&&e[oa]===$a.css,lo=(e,t=!0,n=!1)=>r=>t?!!r?.trimStart().startsWith(e):n?!!r?.trimEnd().endsWith(e):new RegExp(e).test(r??``),uo=lo(Ki),fo=lo(`.`),po=lo(`?`),mo=lo(`@`),ho=lo(`on`),go=lo(Gi,!1),_o=e=>go(e)&&Ji.test(e?.trim()??``),vo=({type:e,value:t})=>e===Xi.spread||e===Xi.directive||go(t),yo=e=>io.has(e),bo=e=>_o(e)?Xi.directive:uo(e)?Xi.spread:fo(e)?Xi.property:mo(e)||ho(e)?Xi.event:po(e)?Xi.boolean:Xi.attribute,xo=e=>uo(e)?e.substring(3):_o(e)?e:fo(e)||mo(e)||po(e)?e.substring(1):ho(e)?e.substring(2):e;function So(e){let t=[],n=qi.exec(e);for(;n;){let r=Number(n[1]);t.push([n[0],Number.isInteger(r)?r:-1]),n=qi.exec(e)}return t}var Co=Symbol(`https://github.com/dineug/r-html.git#hostBridge`);function wo(e,t){if(t instanceof ShadowRoot){let n=t.host;Reflect.set(e,Co,n)}return()=>{Reflect.deleteProperty(e,Co)}}function To(e){return Reflect.get(e,Co)??null}function Eo(e){return Hi(e)&&!zi(e)&&!Ri(e)||co(e)?String(e):``}var Do={createElement:(e,t=!1)=>t?document.createElementNS(`http://www.w3.org/2000/svg`,e):document.createElement(e),createText:e=>document.createTextNode(e),createMarker:e=>document.createComment(e),createFragment:()=>document.createDocumentFragment(),createEventBus:()=>document.createElement(`div`),insertBefore(e,t){let n=t.parentNode;n&&n.insertBefore(e,t)},appendChild(e,t){e.appendChild(t)},prependChild(e,t){e.prepend(t)},removeChild(e){e.parentNode?.removeChild(e)},parentOf:e=>e.parentNode,nextSiblingOf:e=>e.nextSibling,setText(e,t){e.data=t},setAttribute(e,t,n,r){e.setAttribute(t,r?Eo(n).trim():n)},removeAttribute(e,t){e.removeAttribute(t)},isHostNode:e=>e instanceof Node,isMarker:e=>e instanceof Comment,isText:e=>e instanceof Text,isElement:e=>e instanceof Element,isFragment:e=>e instanceof DocumentFragment,addEventListener(e,t,n,r){e.addEventListener(t,n,r)},removeEventListener(e,t,n,r){e.removeEventListener(t,n,r)},getRoot:e=>e.getRootNode(),createComponentContext(e,t){let n={host:document.body,get parentElement(){return e.parentElement},dispatchEvent:e=>t.dispatchEvent(e)},r=e.getRootNode();if(r instanceof ShadowRoot)n.host=r.host;else if(r instanceof DocumentFragment){let e=To(r);e&&(n.host=e)}return n},bridgeFragment(e,t){let n=Di(e,t),r=wo(e,t);return()=>{n(),r()}}};function Oo(e){"@babel/helpers - typeof";return Oo=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Oo(e)}function ko(e,t){if(Oo(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Oo(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ao(e){var t=ko(e,`string`);return Oo(t)==`symbol`?t:t+``}function jo(e,t,n){return(t=Ao(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Mo,No=function(e){return e.element=`element`,e.text=`text`,e.comment=`comment`,e}({});Mo=Symbol.iterator;var Po=class{constructor(e={}){jo(this,`type`,`comment`),jo(this,`value`,``),jo(this,`attrs`,void 0),jo(this,`parent`,null),jo(this,`children`,void 0),Object.assign(this,e)}*iterParent(){yield this,this.parent&&(yield*this.parent.iterParent())}*[Mo](){if(yield this,this.children)for(let e of this.children)yield*e}},Fo=e=>!!e&&e!==`false`;function Io(e){let t=({type:t,value:n},r=!1)=>t===No.element?e.createElement(n,r):t===No.text?e.createText(n):e.createMarker(n),n=(t,{type:n,name:r,value:i})=>{switch(n){case Xi.attribute:e.setAttribute(t,r,i??``,!1);break;case Xi.boolean:Fo(i)&&e.setAttribute(t,r,``,!1);break;case Xi.property:Reflect.set(t,r,i,t)}},r=(t,n)=>{e.insertBefore(t,n)},i=(t,n)=>{let r=e.parentOf(n);if(!r)return;let i=e.nextSiblingOf(n);i?e.insertBefore(t,i):e.appendChild(r,t)},a=t=>e.parentOf(t)?(e.removeChild(t),t):null,o=(t,n)=>{let r=[],i=e.nextSiblingOf(t);for(;i&&i!==n;)r.push(i),i=e.nextSiblingOf(i);return r},s=(e,t)=>{o(e,t).forEach(a)};return{...e,createNode:t,setAttr:n,insertBeforeNode:r,insertAfterNode:i,removeNode:a,rangeNodes:o,removeRange:s}}var D=Io(Do);D.setAttr,D.insertBeforeNode,D.insertAfterNode,D.removeNode,D.rangeNodes,D.removeRange;var Lo=D.isHostNode;function Ro(e,{type:t,name:n,value:r}){switch(t){case Xi.attribute:case Xi.property:Reflect.set(e,n,r);break;case Xi.boolean:Reflect.set(e,n,Fo(r))}}var zo=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function Bo(e,t){if(e===t)return!0;let n=Vi(e)?e:{},r=Vi(t)?t:{},i=Object.keys(n),a=Object.keys(r);return i.length===a.length&&a.every(e=>Reflect.get(n,e)===Reflect.get(r,e))}var Vo=e=>Bi(e)&&Pi(e[0])&&(Ri(e[1])||Ni(e[1])||Vi(e[1])),Ho=()=>{},Uo=e=>e instanceof HTMLElement,Wo=e=>e instanceof SVGElement,Go=e=>e instanceof Promise,Ko=new WeakMap,qo=new WeakMap,Jo=new WeakMap,Yo=new WeakMap,Xo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap,$o=new WeakMap,es=new WeakMap,ts=class{constructor(e,{name:t,value:n},r=D){w(this,Ko,void 0),w(this,qo,void 0),w(this,Jo,void 0),w(this,Yo,void 0),w(this,Xo,[]),w(this,Zo,[]),w(this,Qo,void 0),w(this,$o,null),w(this,es,null),T(Ko,this,r),T(qo,this,e),T(Jo,this,t),T(Yo,this,n),T(Xo,this,So(n??``)),T(Qo,this,E(Xo,this).length===1&&(n??``).trim()===E(Xo,this)[0][0])}commit(e){let t=E(Xo,this).map(([t,n])=>e[n]);if(zo(E(Zo,this),t))return;let n=t[t.length-1];if(E(Jo,this)===`class`)this.classCommit(n);else if(E(Jo,this)===`style`)this.styleCommit(n);else if(E(Qo,this))E(Ko,this).setAttribute(E(qo,this),E(Jo,this),t[0],!0);else{let e=t.reduce((e,t,n)=>e.replace(new RegExp(E(Xo,this)[n][0]),Eo(t)),E(Yo,this)??``);E(Ko,this).setAttribute(E(qo,this),E(Jo,this),e.trim(),!1)}T(Zo,this,t)}classCommit(e){let t=E(qo,this);if(!Uo(t)&&!Wo(t))return;let n=E(Zo,this)[E(Zo,this).length-1];if(n===e||Bi(n)&&Bi(e)&&zo(n,e)||Vi(n)&&Vi(e)&&Bo(n,e))return;let r=[...t.classList],i=rs(e);if(zi(E(es,this)))T(es,this,r);else{let e=E(es,this),n=r.filter(t=>!e.includes(t)&&!i.includes(t));t.classList.remove(...n)}t.classList.add(...i)}styleCommit(e){let t=E(qo,this);if(!Uo(t)&&!Wo(t))return;let n=E(Zo,this)[E(Zo,this).length-1];if(Bo(n,e))return;let r=ns(t),i=Vi(e)?e:{};if(zi(E($o,this)))T($o,this,r);else{let e=E($o,this);Object.keys(r).filter(t=>!e[t]&&!i[t]).forEach(e=>t.style.removeProperty(e))}for(let e of Object.keys(i))t.style.setProperty(e,i[e])}};function ns(e){let t={};for(let n=0;n<e.style.length;n++){let r=e.style.item(n);t[r]=e.style.getPropertyValue(r)}return t}function rs(e,t=[]){if(!e)return t;if(co(e))return t.push(Eo(e)),t;if(Hi(e))t.push(Eo(e));else if(ji(e)){if(Bi(e))for(let n=0;n<e.length;n++)e[n]&&rs(e[n],t);else for(let n in e)e[n]&&t.push(Eo(n))}return t}var is=new WeakMap,as=new WeakMap,os=new WeakMap,ss=new WeakMap,cs=new WeakMap,ls=class{constructor(e,{name:t,value:n},r=D){w(this,is,void 0),w(this,as,void 0),w(this,os,void 0),w(this,ss,[]),w(this,cs,[]),T(is,this,r),T(as,this,e),T(os,this,t),T(ss,this,So(n??``))}commit(e){let t=E(ss,this).map(([t,n])=>e[n]);if(zo(E(cs,this),t))return;let n=t[t.length-1];Fo(n)?E(is,this).setAttribute(E(as,this),E(os,this),``,!1):E(is,this).removeAttribute(E(as,this),E(os,this)),T(cs,this,t)}},us=e=>Bi(e)&&Reflect.get(e,aa)===Ya.attribute,ds=new WeakMap,fs=new WeakMap,ps=new WeakMap,ms=new WeakMap,hs=new WeakMap,gs=class{constructor(e,{name:t}){w(this,ds,void 0),w(this,fs,void 0),w(this,ps,null),w(this,ms,null),w(this,hs,null),T(ds,this,e),T(fs,this,So(t)[0])}commit(e){let[,t]=E(fs,this),n=e[t];if(!us(n))return;let[r,i]=n;if(E(ps,this)!==i)E(hs,this)?.call(this),T(ms,this,i({node:E(ds,this)})),T(ps,this,i),T(hs,this,E(ms,this)?.call(this,r));else{let e=E(ms,this)?.call(this,r);E(hs,this)!==e&&(E(hs,this)?.call(this),T(hs,this,e))}}destroy(){E(hs,this)?.call(this)}},_s=new WeakMap,vs=new WeakMap,ys=new WeakMap,bs=new WeakMap,xs=new WeakMap,Ss=class{constructor(e,{name:t,value:n},r=D){w(this,_s,void 0),w(this,vs,void 0),w(this,ys,void 0),w(this,bs,[]),w(this,xs,[]),T(_s,this,r),T(vs,this,e),T(ys,this,t),T(bs,this,So(n??``))}commit(e){let t=E(bs,this).map(([t,n])=>e[n]).filter(e=>Pi(e)||Vo(e));zo(E(xs,this),t)||(this.clear(),t.forEach(e=>{let[t,n]=Cs(e);E(_s,this).addEventListener(E(vs,this),E(ys,this),t,n)}),T(xs,this,t))}clear(){E(xs,this).forEach(e=>{let[t,n]=Cs(e);E(_s,this).removeEventListener(E(vs,this),E(ys,this),t,n)})}destroy(){this.clear()}};function Cs(e){return Pi(e)?[e,void 0]:e}var ws=new WeakMap,Ts=new WeakMap,Es=new WeakMap,Ds=new WeakMap,Os=class{constructor(e,{name:t,value:n}){w(this,ws,void 0),w(this,Ts,void 0),w(this,Es,[]),w(this,Ds,[]),T(ws,this,e),T(Ts,this,t),T(Es,this,So(n??``))}commit(e){let t=E(Es,this).map(([t,n])=>e[n]);if(zo(E(Ds,this),t))return;let n=t[t.length-1];Reflect.set(E(ws,this),E(Ts,this),n,E(ws,this)),T(Ds,this,t)}},ks=new WeakMap,As=new WeakMap,js=new WeakMap,Ms=class{constructor(e,{name:t}){w(this,ks,void 0),w(this,As,void 0),w(this,js,null),T(ks,this,e),T(As,this,So(t)[0])}commit(e){let[,t]=E(As,this),n=e[t];!Vi(n)||Bo(E(js,this),n)||(Object.keys(n).forEach(e=>Reflect.set(E(ks,this),e,n[e],E(ks,this))),T(js,this,n))}},Ns=(e,t,n=D)=>t.type===Xi.attribute?new ts(e,t,n):t.type===Xi.boolean?new ls(e,t,n):t.type===Xi.event?new Ss(e,t,n):t.type===Xi.property?new Os(e,t):t.type===Xi.spread?new Ms(e,t):new gs(e,t),Ps=new WeakMap,Fs=new WeakMap,Is=new WeakMap,Ls=new WeakMap,Rs=new WeakMap,zs=class{constructor(e,{value:t},n=D){w(this,Ps,void 0),w(this,Fs,void 0),w(this,Is,void 0),w(this,Ls,[]),w(this,Rs,[]),T(Ps,this,n),T(Fs,this,e),T(Is,this,t),Ii(t)&&T(Ls,this,So(t))}commit(e){let t=E(Ls,this).map(([t,n])=>e[n]);if(zo(E(Rs,this),t))return;T(Rs,this,t);let n=E(Rs,this).reduce((e,t,n)=>e.replace(new RegExp(E(Ls,this)[n][0]),Hi(t)&&!zi(t)&&!Ri(t)?String(t):``),E(Is,this)??``);E(Ps,this).setText(E(Fs,this),n)}},Bs=new WeakMap,Vs=new WeakMap,Hs=new WeakMap,Us=new WeakMap,Ws=class{constructor(e,{name:t,value:n}){w(this,Bs,void 0),w(this,Vs,void 0),w(this,Hs,[]),w(this,Us,[]),T(Bs,this,e),T(Vs,this,t),T(Hs,this,So(n??``))}commit(e){let t=E(Hs,this).map(([t,n])=>e[n]);if(zo(E(Us,this),t))return;let n=t[t.length-1];Reflect.set(E(Bs,this),E(Vs,this),n),T(Us,this,t)}},Gs=function(e){return e.create=`create`,e.move=`move`,e}({});function Ks(e){let t=[],n=new Map;return e.forEach(({type:e,value:r},i)=>{let a={type:e,key:e===Mc.templateLiterals?r.strings:r};t.push(a),n.set(a,i)}),{items:t,itemToIndex:n}}function qs(e){let t=[],n=new Map;return e.forEach((e,r)=>{let i=Hc(e),a={type:i,key:i===Mc.templateLiterals?e.strings:e};t.push(a),n.set(a,r)}),{items:t,itemToIndex:n}}function Js(e,t,n){let r=!!n?.strict,i={update:[],delete:[]},a=new Set,o=[],s=e.items,c=t.items;return s.forEach((e,t)=>{let n=c.findIndex((t,n)=>e.type===t.type&&e.key===t.key&&!a.has(n));n===-1?r?i.delete.push({from:t}):o.push(e):(a.add(n),i.update.push({action:`move`,from:t,to:n}))}),o.forEach(n=>{let r=e.itemToIndex.get(n),o=c.find((e,t)=>n.type===e.type&&!a.has(t));if(o){let e=t.itemToIndex.get(o);a.add(e),i.update.push({action:`move`,from:r,to:e})}else i.delete.push({from:r})}),c.forEach((e,n)=>{a.has(n)||i.update.push({action:`create`,from:-1,to:t.itemToIndex.get(e)})}),i.update.sort((e,t)=>e.to-t.to),i}var Ys=new WeakMap,Xs=new WeakMap,Zs=new WeakMap,Qs=new WeakMap,$s=class{constructor(e,t,n=D){w(this,Ys,void 0),w(this,Xs,void 0),w(this,Zs,void 0),w(this,Qs,[]),T(Xs,this,e),T(Zs,this,t),T(Ys,this,n)}commit(e){let t=Js(Ks(E(Qs,this)),qs(e)),n={length:e.length};t.update.forEach(({action:t,from:r,to:i})=>{switch(t){case Gs.create:let t=E(Ys,this).createMarker(``);i===0?E(Ys,this).insertAfterNode(t,E(Xs,this)):E(Qs,this).length?E(Ys,this).insertAfterNode(t,n[i-1]?n[i-1].endNode:E(Qs,this)[i-1].endNode):E(Ys,this).insertBeforeNode(t,E(Zs,this)),n[i]=new nc(t,e[i],E(Ys,this));break;case Gs.move:if(n[i]=E(Qs,this)[r],i===r)return;i===0?E(Qs,this)[r].insert(`after`,E(Xs,this)):E(Qs,this)[r].insert(`after`,n[i-1]?n[i-1].endNode:E(Qs,this)[i-1].endNode)}}),t.delete.forEach(({from:e})=>E(Qs,this)[e].destroy()),T(Qs,this,Array.from(n)),E(Qs,this).forEach((t,n)=>t.commit(e[n]))}destroy(){E(Qs,this).forEach(e=>e.destroy())}},ec=new WeakMap,tc=new WeakMap,nc=class{constructor(e,t,n=D){w(this,ec,void 0),w(this,tc,void 0),jo(this,`startNode`,void 0),jo(this,`endNode`,void 0),jo(this,`type`,void 0),jo(this,`value`,void 0),T(tc,this,n),this.startNode=n.createMarker(``),this.endNode=n.createMarker(``),n.insertBeforeNode(this.startNode,e),n.insertAfterNode(this.endNode,e),n.removeNode(e),this.value=t,this.type=Hc(t),T(ec,this,Kc(this.type,this.startNode,this.endNode,n))}commit(e){E(ec,this).commit(e),this.value=e}insert(e,t){let n=[this.startNode,...E(tc,this).rangeNodes(this.startNode,this.endNode),this.endNode];e===`before`?n.forEach(e=>E(tc,this).insertBeforeNode(e,t)):n.reverse().forEach(e=>E(tc,this).insertAfterNode(e,t))}destroy(){E(ec,this).destroy?.(),E(tc,this).removeRange(this.startNode,this.endNode),E(tc,this).removeNode(this.startNode),E(tc,this).removeNode(this.endNode)}},rc=new WeakMap,ic=new WeakMap,ac=new WeakMap,oc=new WeakMap,sc=new WeakMap,cc=new WeakMap,lc=class{constructor(e,t,n=D){w(this,rc,void 0),w(this,ic,void 0),w(this,ac,void 0),w(this,oc,null),w(this,sc,null),w(this,cc,void 0),T(ic,this,e),T(ac,this,t),T(rc,this,n)}commit(e){if(!Nc(e))return;let[t,n]=e;if(E(oc,this)!==n)this.clear(),T(sc,this,n(Za(E(ic,this),E(ac,this),E(rc,this)))),T(oc,this,n),T(cc,this,E(sc,this)?.call(this,t));else{let e=E(sc,this)?.call(this,t);E(cc,this)!==e&&(this.clear(),T(cc,this,e))}}clear(){E(cc,this)?.call(this),E(rc,this).removeRange(E(ic,this),E(ac,this))}destroy(){this.clear()}},uc=class{constructor(e,t){}commit(e){}},dc=new WeakMap,fc=new WeakMap,pc=new WeakMap,mc=class{constructor(e,t,n=D){w(this,dc,void 0),w(this,fc,void 0),w(this,pc,null),T(fc,this,t),T(dc,this,n)}commit(e){E(pc,this)!==e&&(E(pc,this)&&E(dc,this).removeNode(E(pc,this)),E(dc,this).insertBeforeNode(e,E(fc,this)),T(pc,this,e))}},hc=new WeakMap,gc=new WeakMap,_c=new WeakMap,vc=new WeakMap,yc=new WeakMap,bc=new WeakMap,xc=class{constructor(e,t,n=D){w(this,hc,void 0),w(this,gc,void 0),w(this,_c,void 0),w(this,vc,null),w(this,yc,null),w(this,bc,Ho),T(gc,this,e),T(_c,this,t),T(hc,this,n)}commit(e){E(vc,this)!==e&&(this.clear(),Go(e)&&this.promiseCommit(e))}promiseCommit(e){let[t,n]=Sc(e);T(bc,this,n),t.then(e=>{let t=Hc(e);T(yc,this,Kc(t,E(gc,this),E(_c,this),E(hc,this))),E(yc,this)?.commit(e)}),T(vc,this,e)}partClear(){E(yc,this)?.destroy?.(),E(hc,this).removeRange(E(gc,this),E(_c,this))}clear(){E(bc,this).call(this),this.partClear(),T(bc,this,Ho)}destroy(){this.clear()}};function Sc(e){let t=Ho,n=new Promise((e,n)=>t=n);return[Promise.race([n,e]),()=>t()]}var Cc=new WeakMap,wc=new WeakMap,Tc=new WeakMap,Ec=class{constructor(e,t,n=D){w(this,Cc,void 0),w(this,wc,void 0),w(this,Tc,null),T(Cc,this,n),T(wc,this,n.createText(``)),n.insertAfterNode(E(wc,this),e)}commit(e){E(Tc,this)!==e&&(E(Cc,this).setText(E(wc,this),zi(e)||Ri(e)?``:String(e)),T(Tc,this,e))}},Dc=new WeakMap,Oc=new WeakMap,kc=new WeakMap,Ac=new WeakMap,jc=class{constructor(e,t,n=D){w(this,Dc,void 0),w(this,Oc,void 0),w(this,kc,void 0),w(this,Ac,null),T(Oc,this,e),T(kc,this,t),T(Dc,this,n)}commit(e){let{strings:t,values:n}=e;E(Ac,this)&&!E(Ac,this).equalStrings(t)&&(E(Ac,this).destroy(),T(Ac,this,null)),E(Ac,this)||(T(Ac,this,new Dl(e,E(Oc,this),E(kc,this),E(Dc,this))),E(Ac,this).insert(`before`,E(kc,this))),E(Ac,this).commit(n)}destroy(){E(Ac,this)?.destroy()}},Mc=function(e){return e.primitive=`primitive`,e.templateLiterals=`templateLiterals`,e.array=`array`,e.node=`node`,e.object=`object`,e.function=`function`,e.directive=`directive`,e}({}),Nc=e=>Bi(e)&&Reflect.get(e,aa)===Ya.node,Pc=e=>t=>t instanceof e,Fc=Pc(Ec),Ic=Pc(jc),Lc=Pc($s),Rc=Pc(mc),zc=Pc(xc),Bc=Pc(uc),Vc=Pc(lc),Hc=e=>Hi(e)?`primitive`:so(e)?`templateLiterals`:Nc(e)?`directive`:Bi(e)?`array`:Lo(e)?`node`:Pi(e)?`function`:`object`,Uc={primitive:Fc,templateLiterals:Ic,array:Lc,node:Rc,function:Bc,object:zc,directive:Vc},Wc={primitive:Ec,templateLiterals:jc,array:$s,node:mc,function:uc,object:xc,directive:lc},Gc=(e,t)=>Uc[e](t),Kc=(e,t,n,r=D)=>new Wc[e](t,n,r),qc=new WeakMap,Jc=new WeakMap,Yc=new WeakMap,Xc=new WeakMap,Zc=new WeakMap,Qc=new WeakMap,$c=new WeakMap,el=new WeakMap,tl=new WeakMap,nl=new WeakMap,rl=new WeakMap,il=new WeakMap,al=class{constructor(e,t,n,r,i=D){w(this,qc,void 0),w(this,Jc,void 0),w(this,Yc,void 0),w(this,Xc,void 0),w(this,Zc,void 0),w(this,Qc,[]),w(this,$c,[]),w(this,el,null),w(this,tl,Ma({},{shallow:!0})),w(this,nl,null),w(this,rl,null),w(this,il,void 0),T(qc,this,i),T(il,this,i.createEventBus()),T(Jc,this,e),T(Yc,this,t),T(Zc,this,n),T(Xc,this,So(n.value)[0]),n.staticAttrs&&n.staticAttrs.forEach(e=>Ro(E(tl,this),e)),n.attrs?.forEach(e=>{e.type===Xi.directive?E(Qc,this).push(e):e.type===Xi.spread?r.push(new Ms(E(tl,this),e)):e.type===Xi.event?r.push(new Ss(E(il,this),e,i)):r.push(new Ws(E(tl,this),e))})}createContext(){return E(qc,this).createComponentContext(E(Jc,this),E(il,this))}commit(e){let[,t]=E(Xc,this),n=e[t];if(!Pi(n)||E(nl,this)===n){E($c,this).forEach(t=>t.commit(e));return}let r=this.createContext();this.clear(),ca(this);let i=n.call(r,E(tl,this),r);ca(null),E(Qc,this).length&&E($c,this).push(...E(Qc,this).map(e=>new gs(r,e))),pa(this,Zi);let a=!1;T(rl,this,Da(()=>{let e=i(),t=Hc(e);Gc(t,E(el,this))||(this.partClear(),T(el,this,Kc(t,E(Jc,this),E(Yc,this),E(qc,this)))),pa(this,a?ta:ea),E(el,this)?.commit(e),a?pa(this,ra):(pa(this,na),a=!0)})),E($c,this).forEach(t=>t.commit(e)),pa(this,Qi),T(nl,this,n)}partClear(){E(el,this)?.destroy?.(),E(qc,this).removeRange(E(Jc,this),E(Yc,this))}clear(){E(qc,this).removeRange(E(Jc,this),E(Yc,this)),pa(this,$i),E($c,this).forEach(e=>e.destroy?.()),E(rl,this)?.call(this),T($c,this,[]),T(rl,this,null),ma(this)}destroy(){this.clear(),this.partClear()}},ol,sl,cl,ll,ul=ya((ol=new WeakMap,sl=new WeakMap,cl=new WeakMap,ll=new WeakMap,class{constructor(e,t,n,r=D){w(this,ol,void 0),w(this,sl,void 0),w(this,cl,void 0),w(this,ll,void 0),T(ol,this,r),T(sl,this,r.createMarker(``)),T(cl,this,r.createMarker(``)),T(ll,this,new al(E(sl,this),E(cl,this),t,n,r)),r.insertBeforeNode(E(sl,this),e),r.insertAfterNode(E(cl,this),e),r.removeNode(e)}commit(e){E(ll,this).commit(e)}destroy(){E(ll,this).destroy?.(),E(ol,this).removeNode(E(sl,this)),E(ol,this).removeNode(E(cl,this))}})),dl=new WeakMap,fl=new WeakMap,pl=new WeakMap,ml=new WeakMap,hl=new WeakMap,gl=new WeakMap,_l=class{constructor(e,{value:t},n=D){w(this,dl,void 0),w(this,fl,void 0),w(this,pl,void 0),w(this,ml,void 0),w(this,hl,null),w(this,gl,null),T(dl,this,n),T(fl,this,n.createMarker(``)),T(pl,this,n.createMarker(``)),T(ml,this,So(t)[0]),n.insertBeforeNode(E(fl,this),e),n.insertAfterNode(E(pl,this),e),n.removeNode(e)}commit(e){let[,t]=E(ml,this),n=e[t];if(E(hl,this)===n)return;let r=Hc(n);Gc(r,E(gl,this))||(zi(E(gl,this))||this.clear(),T(gl,this,Kc(r,E(fl,this),E(pl,this),E(dl,this)))),E(gl,this)?.commit(n),T(hl,this,n)}clear(){E(gl,this)?.destroy?.(),E(dl,this).removeRange(E(fl,this),E(pl,this))}destroy(){this.clear(),E(dl,this).removeNode(E(fl,this)),E(dl,this).removeNode(E(pl,this))}};function vl(e=[],t,n=!1,r=[],i=D){return e.forEach(e=>{if(e.isComponent){let n=i.createMarker(``);i.appendChild(t,n),r.push(new ul(n,e,r,i));return}let a=i.createNode(e,e.isSvg||n);i.appendChild(t,a),i.isMarker(a)&&e.isMarker&&r.push(new zs(a,e,i)),i.isText(a)&&e.isMarkerOnly&&r.push(new _l(a,e,i)),i.isElement(a)&&(e.staticAttrs&&e.staticAttrs.forEach(e=>i.setAttr(a,e)),e.attrs&&r.push(...e.attrs.map(e=>Ns(a,e,i))),e.children&&vl(e.children,a,e.isSvg||n,r,i))}),r}function yl(e,t=!1,n=D){let r=n.createFragment();return[r,vl(e.children,r,t,[],n)]}var bl=new WeakMap,xl=new WeakMap,Sl=new WeakMap,Cl=new WeakMap,wl=new WeakMap,Tl=new WeakMap,El=new WeakMap,Dl=class{constructor(e,t,n,r=D){if(w(this,bl,void 0),w(this,xl,void 0),w(this,Sl,void 0),w(this,Cl,null),w(this,wl,[]),w(this,Tl,void 0),w(this,El,!1),T(bl,this,r),T(xl,this,r.createMarker(``)),T(Sl,this,r.createMarker(``)),T(Tl,this,e.strings),e[oa]!==$a.html&&e[oa]!==$a.svg)return;let[i,a]=yl(e.template.node,yo(e[oa]),r);T(Cl,this,i),T(wl,this,a),t&&n?(T(xl,this,t),T(Sl,this,n),T(El,this,!0)):(r.prependChild(i,E(xl,this)),r.appendChild(i,E(Sl,this)))}equalStrings(e){return E(Tl,this)===e}commit(e){E(wl,this).forEach(t=>t.commit(e))}insert(e,t){E(Cl,this)&&(e===`before`?E(bl,this).insertBeforeNode(E(Cl,this),t):e===`after`?E(bl,this).insertAfterNode(E(Cl,this),t):E(bl,this).appendChild(t,E(Cl,this)),T(Cl,this,null))}destroy(){E(wl,this).forEach(e=>e.destroy?.()),E(bl,this).removeRange(E(xl,this),E(Sl,this)),E(El,this)||(E(bl,this).removeNode(E(xl,this)),E(bl,this).removeNode(E(Sl,this)))}},Ol=function(e){return e.string=`string`,e.whiteSpace=`whiteSpace`,e.lt=`lt`,e.gt=`gt`,e.slash=`slash`,e.equal=`equal`,e}({}),kl={doubleQuote:`"`,singleQuote:`'`,whiteSpace:/\s/,string:/\S/,breakString:/<|>|=/,lt:`<`,gt:`>`,slash:`/`,equal:`=`,hyphen:`-`,exclamationPoint:`!`},Al=e=>t=>e===t,jl=e=>t=>e.test(t),Ml={doubleQuote:Al(kl.doubleQuote),singleQuote:Al(kl.singleQuote),whiteSpace:jl(kl.whiteSpace),string:jl(kl.string),breakString:jl(kl.breakString),lt:Al(kl.lt),gt:Al(kl.gt),slash:Al(kl.slash),equal:Al(kl.equal),hyphen:Al(kl.hyphen),exclamationPoint:Al(kl.exclamationPoint)},Nl=e=>t=>Ml.lt(e[t])&&Ml.exclamationPoint(e[t+1])&&Ml.hyphen(e[t+2])&&Ml.hyphen(e[t+3]);function Pl(e){let t=[],n=0,r=()=>n<e.length,i=Nl(e),a=(o=`text`)=>{for(;r();){let s=e[n];if(Ml.whiteSpace(s)){let i=``;for(;r()&&Ml.whiteSpace(s);)i+=s,s=e[++n];o!==`element`&&t.push({type:`whiteSpace`,value:i});continue}if(o===`element`){if(Ml.lt(s)){t.push({type:`lt`,value:s}),n++;continue}if(Ml.gt(s)){t.push({type:`gt`,value:s}),n++;break}if(Ml.slash(s)){t.push({type:`slash`,value:s}),n++;continue}if(Ml.equal(s)){t.push({type:`equal`,value:s}),n++;continue}if(Ml.doubleQuote(s)){let i=``;for(s=e[++n];r()&&!Ml.doubleQuote(s);)i+=s,s=e[++n];t.push({type:`string`,value:i}),n++;continue}if(Ml.singleQuote(s)){let i=``;for(s=e[++n];r()&&!Ml.singleQuote(s);)i+=s,s=e[++n];t.push({type:`string`,value:i}),n++;continue}}else if(o===`comment`){if(Ml.lt(s)){t.push({type:`lt`,value:s}),n++;continue}if(Ml.gt(s)){t.push({type:`gt`,value:s}),n++;break}}else if(Ml.lt(s)){a(i(n)?`comment`:`element`);continue}if(Ml.string(s)){let i=``;for(;r()&&Ml.string(s)&&!Ml.breakString(s);)i+=s,s=e[++n];t.push({type:`string`,value:i});continue}n++}};return a(),t}var Fl=/^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i,Il=e=>t=>n=>r=>n[r]?n[r][e]===t:!1,Ll=Il(`type`),Rl=Il(`value`),zl=Ll(Ol.lt),Bl=Ll(Ol.gt),Vl=Ll(Ol.slash),Hl=Ll(Ol.equal),Ul=Ll(Ol.string),Wl=Ll(Ol.whiteSpace),Gl=Rl(`!--`),Kl=Rl(`--`),ql=e=>{let t=zl(e),n=Ul(e);return e=>t(e)&&n(e+1)},Jl=e=>{let t=zl(e),n=Vl(e),r=Ul(e),i=Bl(e);return e=>t(e)&&n(e+1)&&r(e+2)&&i(e+3)},Yl=e=>{let t=zl(e),n=Vl(e),r=Bl(e);return e=>t(e)&&n(e+1)&&n(e+2)&&r(e+3)},Xl=e=>{let t=Vl(e),n=Bl(e);return e=>t(e)&&n(e+1)},Zl=e=>Fl.test(e),Ql=e=>{let t=zl(e),n=Ul(e),r=Gl(e);return e=>t(e)&&n(e+1)&&r(e+1)},$l=e=>{let t=Ul(e),n=Kl(e),r=Bl(e);return e=>t(e)&&n(e)&&r(e+1)},eu=e=>t=>n=>{n&&(t[e]?t[e]?.push(n):t[e]=[n])},tu=eu(`attrs`),nu=eu(`children`);function ru(e){let t=new Po({type:No.element,value:`template`,children:[]}),n=0,r=()=>n<e.length,i=ql(e),a=Jl(e),o=Yl(e),s=Xl(e),c=Ql(e),l=$l(e),u=zl(e),d=Bl(e),f=Hl(e),p=Wl(e),m=Ul(e),h=()=>{let t=e[n],r={name:t.value};return t=e[++n],f(n)&&(t=e[++n],m(n)&&(r.value=t.value,n++)),r},g=t=>{let f=e[n];if(p(n)||m(n)){let i=f.value;for(f=e[++n];r()&&!u(n);)i+=f.value,f=e[++n];return i=i.trim(),i.length?new Po({parent:t,type:No.text,value:i}):null}if(c(n)){let i=``;for(n+=2,f=e[n];r()&&!l(n);)i+=f.value,f=e[++n];return l(n)&&(n+=2),new Po({parent:t,type:No.comment,value:i})}if(i(n)){f=e[++n];let i=Zl(f.value),c=new Po({parent:t,type:No.element,value:f.value.toLowerCase()});for(n++;r()&&!d(n)&&!s(n);){if(m(n)){tu(c)(h());continue}n++}if(s(n))return n+=2,c;for(f=e[++n];r()&&!a(n)&&!o(n)&&!i;)nu(c)(g(c));return(a(n)||o(n))&&(n+=4),c}return n++,null};for(;r();)nu(t)(g(t));return t}var iu=e=>ru(Pl(e)),au=(e,t)=>e.reduce((e,n)=>{let r=t(n),i=e[r];return i?i.push(n):e[r]=[n],e},Object.create(null)),ou=Symbol.iterator,su=class e{get isMarker(){return go(this.value)}get isMarkerOnly(){return _o(this.value)}get isSvg(){return this.type===No.element&&/^svg$/i.test(this.value)}get isComponent(){return this.type===No.element&&this.isMarkerOnly}constructor(t,n=null){if(jo(this,`type`,No.comment),jo(this,`value`,``),jo(this,`staticAttrs`,void 0),jo(this,`attrs`,void 0),jo(this,`parent`,null),jo(this,`children`,void 0),this.type=t.type,this.value=t.value,this.parent=n,t.attrs){let[e,n]=uu(t.attrs);e.length&&(this.staticAttrs=e),n.length&&(this.attrs=n)}t.children&&(this.children=t.children.map(t=>new e(t,this)))}insert(e,t,n){if(this.children){let r=e===`before`?0:1;this.children.includes(n)&&this.children.splice(this.children.indexOf(n)+r,0,t)}else this.children=[t]}*iterParent(){yield this,this.parent&&(yield*this.parent.iterParent())}*[ou](){if(yield this,this.children)for(let e of this.children)yield*e}};function cu(e){let t=new su(e);for(let e of t)e.type===No.text&&!_o(e.value)&&lu(e);return t}function lu(e){let t=So(e.value);e.value.replace(qi,Gi).split(Gi).reduce((n,r,i)=>(i<t.length?n.push(new su(new Po({type:No.text,value:r}),e.parent),new su(new Po({type:No.text,value:t[i][0]}),e.parent)):n.push(new su(new Po({type:No.text,value:r}),e.parent)),n),[]).filter(e=>e.value!==``&&!(!e.value.trim()&&Yi.test(e.value))).reverse().forEach((t,n,{length:r})=>n===r-1?e.value=t.value:e.parent&&e.parent.insert(`after`,t,e))}function uu(e=[]){let t=au(e,e=>xo(e.name));return Object.keys(t).map(e=>t[e]).reduce((e,t)=>{let[n,r]=e,i=t[t.length-1],a=bo(i.name);if(a===Xi.event)r.push(...t.filter(e=>!!e.value).map(e=>({type:bo(e.name),name:xo(e.name),value:e.value})));else if(a===Xi.attribute){let e=t.filter(e=>!!e.value).map(e=>e.value).join(` `),o={type:a,name:xo(i.name)};e&&(o.value=e),vo(o)?r.push(o):n.push(o)}else{let e={type:a,name:xo(i.name)};i.value&&(e.value=i.value),vo(e)?r.push(e):n.push(e)}return e},[[],[]])}var du=e=>(t,...n)=>{let r={strings:t,values:n,[oa]:e};if(no.has(t))return r.template=no.get(t),r;let i=cu(iu(t.reduce((e,t,r)=>(r<n.length?e.push(t,ao(r)):e.push(t),e),[]).join(``)));return r.template=Object.freeze({node:i}),no.set(t,r.template),r},fu=du($a.html),pu=du($a.svg);function mu(e){let t=Io(e),n=new WeakMap;return{html:fu,svg:pu,render:(e,r)=>{if(!so(r)){n.has(e)&&(n.get(e)?.destroy(),n.delete(e));return}let{strings:i,values:a}=r,o=n.get(e);if(o?.equalStrings(i))o?.commit(a);else{let i=new Dl(r,void 0,void 0,t);o?.destroy(),n.set(e,i),i.insert(`children`,e),i.commit(a)}}}}var hu=Qa((e,t,n)=>(e.length,[e,t,n]),({startNode:e,endNode:t,helper:n=D})=>{let r=[],i=()=>{r.forEach(e=>e.destroy())};return([a,o,s])=>{let c=bu(a,o,s),l=c.values,u=Js(yu(r),c,{strict:!0}),d={length:l.length};return u.update.forEach(({action:i,from:a,to:o})=>{switch(i){case Gs.create:let i=n.createMarker(``);o===0?n.insertAfterNode(i,e):r.length?n.insertAfterNode(i,d[o-1]?d[o-1].endNode:r[o-1].endNode):n.insertBeforeNode(i,t),d[o]=new vu(i,l[o].value,l[o].key,n);break;case Gs.move:if(d[o]=r[a],o===a)return;o===0?r[a].insert(`after`,e):r[a].insert(`after`,d[o-1]?d[o-1].endNode:r[o-1].endNode)}}),u.delete.forEach(({from:e})=>r[e].destroy()),r=Array.from(d),r.forEach((e,t)=>e.commit(l[t].value)),i}}),gu=new WeakMap,_u=new WeakMap,vu=class{constructor(e,t,n,r=D){w(this,gu,void 0),w(this,_u,void 0),jo(this,`startNode`,void 0),jo(this,`endNode`,void 0),jo(this,`type`,void 0),jo(this,`key`,void 0),T(_u,this,r),this.startNode=r.createMarker(``),this.endNode=r.createMarker(``),r.insertBeforeNode(this.startNode,e),r.insertAfterNode(this.endNode,e),r.removeNode(e),this.key=n,this.type=Hc(t),T(gu,this,Kc(this.type,this.startNode,this.endNode,r))}commit(e){E(gu,this).commit(e)}insert(e,t){let n=[this.startNode,...E(_u,this).rangeNodes(this.startNode,this.endNode),this.endNode];e===`before`?n.forEach(e=>E(_u,this).insertBeforeNode(e,t)):n.reverse().forEach(e=>E(_u,this).insertAfterNode(e,t))}destroy(){E(gu,this).destroy?.(),E(_u,this).removeRange(this.startNode,this.endNode),E(_u,this).removeNode(this.startNode),E(_u,this).removeNode(this.endNode)}};function yu(e){let t=[],n=new Map;return e.forEach(({type:e,key:r},i)=>{let a={type:e,key:r};t.push(a),n.set(a,i)}),{items:t,itemToIndex:n}}function bu(e,t,n){let r=[],i=new Map,a=[];return e.forEach((e,o,s)=>{let c={key:t(e),value:n(e,o,s)},l={type:Hc(c.value),key:c.key};a.push(c),r.push(l),i.set(l,o)}),{items:r,itemToIndex:i,values:a}}var xu={vCSSStyleSheetMap:new Map,hostContextMap:new Map,globalOrder:[],orderedSheets:null},Su=globalThis.ShadowRoot&&`adoptedStyleSheets`in Document.prototype&&`replace`in CSSStyleSheet.prototype,Cu=null;function wu(){return Cu===null&&(Cu=Tu()),Cu}function Tu(){try{let e=document.createElement(`div`).attachShadow({mode:`open`}),t=new CSSStyleSheet;return e.adoptedStyleSheets.push(t),e.adoptedStyleSheets.length===1&&e.adoptedStyleSheets[0]===t}catch{return!1}}function Eu(){return xu}function Du(e){let t=Eu(),{identifier:n,cssText:r,mode:i}=e;if(!r||t.vCSSStyleSheetMap.has(n))return n;let a=Su?new CSSStyleSheet:null,o=Su?null:document.createElement(`style`);a?a.replaceSync(r):o&&(o.textContent=r);let s={identifier:n,cssText:r,mode:i,sheet:a,styleElement:o};return t.vCSSStyleSheetMap.set(n,s),Mu(s),n}function Ou(e){let t=[],n=[];for(let r of e.vCSSStyleSheetMap.values())(r.mode===`global`?t:n).push(r);if(e.globalOrder.length>0){let n=({identifier:t})=>{let n=e.globalOrder.indexOf(t);return n===-1?e.globalOrder.length:n};t.sort((e,t)=>n(e)-n(t))}return[...t,...n]}function ku(e){return e.orderedSheets||=Ou(e).map(({sheet:e})=>e).filter(Boolean),e.orderedSheets}function Au(e,t){e.adoptedStyleSheets=[...t]}function ju(){let e=Eu(),t=ku(e);e.hostContextMap.forEach((e,n)=>Au(n,t))}function Mu(e){if(!Su){Nu();return}let t=Eu(),{mode:n,sheet:r}=e,i=t.orderedSheets;if(!r||n===`global`||!i){t.orderedSheets=null,ju();return}if(i.push(r),!wu()){ju();return}t.hostContextMap.forEach((e,t)=>t.adoptedStyleSheets.push(r))}function Nu(){let e=Eu(),t=Ou(e);Array.from(e.hostContextMap).forEach(([e,{styleElements:n}])=>{t.forEach((r,i)=>{if(n.has(r)||!r.styleElement)return;let a=document.importNode(r.styleElement,!0),o=Pu(t,i+1,n);o?e.insertBefore(a,o):e.appendChild(a),n.set(r,a)})})}function Pu(e,t,n){for(let r=t;r<e.length;r++){let t=n.get(e[r]);if(t)return t}return null}function O(e){function t(t){return{type:e,payload:t}}return t.toString=()=>`${e}`,t.type=e,t}function*Fu(e,t,n){for(let r of n)r?.[Symbol.iterator]?yield*Fu(e,t,r):Pi(r)?yield*Fu(e,t,r(e,t)):yield r}var Iu=(e,t,n)=>[...Fu(e,t,n)],Lu=(...e)=>t=>e.reduce((e,t)=>t(e),t);function*Ru(e){yield e}var zu=function*(e){for(let t of e)t.length&&(yield t)};function Bu({context:e,state:t,reducers:n,enableObservable:r=!0}){let i=r?Ma(t):t,a=Ui(),o=Ui(),s=Lu(zu),c=t=>{Oi(Reflect.get(n,t.type,n),i,t,e)},l=(...t)=>{let n=Iu(i,e,t);a.next(n)},u=(...e)=>{ki(()=>l(...e))},d=a.subscribe(e=>{let t=s(Ru(e));for(let e of t)o.next(e)}),f=o.subscribe(e=>e.forEach(c));return{context:e,state:i,dispatch:u,dispatchSync:l,subscribe:o.subscribe,pipe:(...e)=>(s=Lu(...e,zu),()=>{s=Lu(zu)}),destroy:()=>{d(),f()}}}var Vu=`__RHTML_CSS_DIAGNOSTICS__`,Hu=({line:e,column:t})=>e===void 0?``:` (${e}:${t??1})`,Uu=(e,t)=>{let n=`[r-html] ${t.mode===`global`?`css.global`:`css`} ${t.identifier}${Hu(e)} ${e.code}: ${e.message}`;e.severity===`error`?console.error(n):console.warn(n)},Wu;function Gu(){if(Wu!==void 0)return Wu;let e=Reflect.get(globalThis,Vu);return e?typeof e==`function`?e:Uu:null}function Ku(){return Gu()!==null}function qu(e,t){if(e.length===0)return;let n=Gu();if(n)for(let r of e)n(r,t)}var Ju=[``];function Yu(e){return{value:``,root:null,parent:null,type:o,props:e.slice(),children:[],line:1,column:1,length:0,return:``,siblings:[]}}function Xu(e,t={}){let n=t.rules??Ju,r=t.rules===void 0?null:Yu(n),i=s(e);return c(l(``,null,null,r??null,n,i,0,[0],i))}var Zu=`rhtml-scope`;function Qu(e,t){return e.split(Zu).join(t)}var $u=/^(?::host\b|::slotted\()/;function ed(e){return $u.test(e.trim())}function td(e){return e.type===o}function nd(e){return e.type===n}function rd(e){return e.type.charCodeAt(0)===64}function id(e){return Array.isArray(e.children)?e.children:[]}function ad(e){return e.value.charCodeAt(e.value.length-1)===59?e.value.slice(0,-1):e.value}function od(e){let t=[];for(let n of id(e))nd(n)&&t.push(ad(n));return t}function sd(e){return id(e).filter(td)}function cd(e){let t=e.charCodeAt(1);return t===100||t===109||t===115||t===99&&e.charCodeAt(3)===110?!0:t===99||t===108?e.charCodeAt(2)===97:!1}var ld=new Set([r,t,a,i]);function ud(e,t,n){let i=[],a=new Set,o=!1,s=(e,t)=>{for(let n of e){if(td(n)){o=!0,dd(n,t,i);continue}if(rd(n)){if(id(n).length===0){if(!ld.has(n.type))continue;i.push({code:`unsupported-at-rule`,severity:`error`,message:`\`${n.value}\` is not supported and was dropped. A constructed stylesheet strips \`@import\` by spec, and happy-dom discards the entire sheet when it sees any body-less at-rule — with one sheet per template that would erase the whole component. Move it to a \`<link>\`.`,line:n.line,column:n.column}),n.type===r&&o&&i.push({code:`import-after-rule`,severity:`warning`,message:`\`${n.value}\` follows a rule. Even where \`@import\` is supported it has to precede every rule in the sheet, so this one could not have applied.`,line:n.line,column:n.column});continue}if(o=!0,cd(n.type)){s(id(n),t);continue}sd(n).length>0&&fd(n,a,i),s(id(n),!1)}}};s(e,n.scoped),!n.scoped&&e.some(nd)&&i.push({code:`rule-without-selector`,severity:`warning`,message:`Declarations at the top level of a global block have no selector and were dropped. Wrap them in one.`}),pd(t,i);let c=hd(n.source);return c&&i.push(c),i}function dd(e,t,n){if(e.props.every(e=>e.length===0)){let t=od(e);t.length>0&&n.push({code:`rule-without-selector`,severity:`warning`,message:`A rule with no selector was dropped: \`{${t.join(`;`)}}\`.`,line:e.line,column:e.column})}if(t)for(let t of md(e.value)){let r=t.trim();if(ed(r)){n.push({code:`shadow-boundary`,severity:`warning`,message:`\`${r}\` crosses a shadow boundary, but a scoped block prepends the component class to it, so it can never match. Use \`css.global\` for this rule.`,line:e.line,column:e.column});continue}r.charCodeAt(0)===58&&n.push({code:`implicit-descendant`,severity:`warning`,message:`\`${r}\` becomes a descendant of the scope, not a qualifier on it. Prefix it with \`&\` to attach it: \`&${r}\`.`,line:e.line,column:e.column})}}function fd(e,t,n){if(t.has(e.value)){n.push({code:`duplicate-keyframes`,severity:`warning`,message:`\`${e.value}\` is defined more than once. The name is global and unscoped, so the last definition wins for every template that animates with it.`,line:e.line,column:e.column});return}t.add(e.value)}function pd(e,t){for(let n of e)for(let e of n.declarations)e.includes(`rhtml-scope`)&&t.push({code:`scope-in-declaration`,severity:`warning`,message:`\`${e}\` contains \`${Zu}\`. The sentinel is only substituted in selectors, so it will reach the browser as written.`})}function md(e){let t=[],n=0,r=0,i=0;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);r===0?o===34||o===39?r=o:o===40||o===91?n++:o===41||o===93?n--:o===44&&n===0&&(t.push(e.slice(i,a)),i=a+1):o===r&&e.charCodeAt(a-1)!==92&&(r=0)}return t.push(e.slice(i)),t}function hd(e){let t=1,n=1,r=0,i=()=>{e.charCodeAt(r)===10?(t++,n=1):n++,r++};for(;r<e.length;){let a=e.charCodeAt(r),o=e.charCodeAt(r+1);if(a===47&&o===42){let a=t,o=n;for(i(),i();r<e.length&&(e.charCodeAt(r)!==42||e.charCodeAt(r+1)!==47);)i();if(r>=e.length)return{code:`unterminated-comment`,severity:`warning`,message:`Unterminated block comment. The scanner consumed the rest of the source, so every rule after it was lost.`,line:a,column:o};i(),i();continue}if(a===47&&o===47){for(;r<e.length&&e.charCodeAt(r)!==10;)i();continue}if(a===34||a===39){let o=t,s=n;for(i();r<e.length&&e.charCodeAt(r)!==a;)e.charCodeAt(r)===92&&i(),i();if(r>=e.length)return{code:`unterminated-string`,severity:`warning`,message:`Unterminated string. The scanner consumed the rest of the source, so every rule after it was lost.`,line:o,column:s};i();continue}i()}return null}function gd(e,t={}){let n=``,r=[];for(let i of e){let{conditions:e}=i,a=0;for(;a<r.length&&a<e.length&&r[a]===e[a];)a++;for(let e=a;e<r.length;e++)n+=`}`;for(let t=a;t<e.length;t++)n+=`${e[t]}{`;r=e,n+=_d(i,t.scope)}for(let e=0;e<r.length;e++)n+=`}`;return n}function _d(e,t){return e.body===void 0?`${e.prelude??vd(e.selectors,t)}{${e.declarations.join(`;`)};}`:`${e.prelude}{${e.body}}`}function vd(e,t){return(t===void 0?e:e.map(e=>Qu(e,t))).join(`,`)}var yd=[],bd=e=>e.length>0;function xd(e,t){let n=[];return Cd(e,yd,t.rules,n),(t.plugins??[]).reduce((e,t)=>e.flatMap(e=>t(e)),n).filter(Sd)}function Sd(e){let t=e.selectors.length>0||e.prelude!==void 0,n=e.declarations.length>0||!!e.body;return t&&n}function Cd(e,t,n,r){let i=r.length,a=[];for(let i of e)nd(i)?a.push(ad(i)):td(i)?wd(i,t,r):rd(i)&&Td(i,t,n,r);if(a.length===0)return;let o=n.filter(bd);o.length!==0&&r.splice(i,0,{conditions:t,selectors:o,declarations:a})}function wd(e,t,n){let r=e.props.filter(bd);if(r.length===0)return;let i=od(e);i.length!==0&&n.push({conditions:t,selectors:r,declarations:i})}function Td(e,t,n,r){let i=id(e);if(i.length===0)return;if(cd(e.type)){let a=[];if(Cd(i,[...t,e.value],n,a),a.length===0)return;for(let e of a)r.push(e);return}let a=sd(e);if(a.length>0){let n=[];for(let e of a)wd(e,yd,n);let i=gd(n);i&&r.push({conditions:t,selectors:[],prelude:e.value,declarations:[],body:i});return}let o=od(e);o.length!==0&&r.push({conditions:t,selectors:[],prelude:e.value,declarations:o})}function Ed(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}var Dd=7;function Od(e){return`_${Ed(e).toString(36).padStart(Dd,`0`)}`}var kd=[];function Ad(e,t={}){let n=t.mode!==`global`,r=n?[Zu]:[``],i=Xu(e,{rules:r}),a=xd(i,{rules:r,plugins:t.plugins}),o=gd(a),s=Od(o);return{rules:a,canonicalText:o,identifier:s,cssText:gd(a,{scope:`.${s}`}),diagnostics:t.dev?ud(i,a,{source:e,scoped:n}):kd}}function jd(e){let t=/[;{}][^;{}]*$/.exec(e);return t?t[0].slice(1):e}function Md(e){let t=e.search(/[;}\n]/);return t===-1?e:e.slice(0,t)}function Nd(e){let t=[];for(let n=0;n<e.length-1;n++){let r=jd(e[n]),i=Md(e[n+1]),a=!r.includes(`:`)&&!i.includes(`{`)?`statement`:`inline`;t.push({kind:a,provable:r.trim().length===0})}return t}function Pd(e){let t=e.trimEnd();return!t||t.endsWith(`;`)||t.endsWith(`}`)?e:`${e};`}function Fd(e,t){return co(e)?t===`statement`?Pd(e[to]??``):`.${String(e)}`:Hi(e)&&!zi(e)&&!Ri(e)?String(e):``}function Id(e,t,n){if(co(t)){e.kind===`statement`&&!e.provable&&console.error("[r-html] a css literal follows unterminated text, so it is spliced in as a statement. End the declaration in front of it with a `;`.");return}if(n.includes(`{`)||n.includes(`}`)){console.warn(`[r-html] interpolated value contains a brace and is substituted before compiling, so it can change the rule structure: ${n}`);return}(Ld(n,`'`)||Ld(n,`"`))&&console.warn(`[r-html] interpolated value has an unbalanced quote and is substituted before compiling: ${n}`)}function Ld(e,t){let n=0;for(let r of e)r===t&&n++;return n%2==1}function Rd(e,t,n){let r=``;for(let i=0;i<e.length;i++){if(r+=e[i],i>=t.length)continue;let a=Fd(n[i],t[i].kind);Id(t[i],n[i],a),r+=a}return r}var zd=32,Bd=`\0`;function Vd(e){return(t,...n)=>{let r=Ud(t,e),i=Wd(r.node,n),a=Du(i);return{strings:t,values:n,template:r,[oa]:$a.css,[to]:i.source,toString:()=>a}}}var Hd=Object.assign(Vd(`scoped`),{global:Vd(`global`)});function Ud(e,t){let n=ro.get(e);if(n&&n.node.mode===t)return n;let r=e.raw,i={raw:r,slots:Nd(r),mode:t,memo:new Map},a=Object.freeze({node:i});return ro.set(e,a),a}function Wd(e,t){let n=e.slots.map((e,n)=>Fd(t[n],e.kind)).join(Bd),r=e.memo.get(n);if(r)return r;let i=Rd(e.raw,e.slots,t),{rules:a,canonicalText:o,identifier:s,cssText:c,diagnostics:l}=Ad(i,{mode:e.mode,dev:Ku()}),u={source:i,mode:e.mode,rules:a,canonicalText:o,identifier:s,cssText:c};if(qu(l,{source:i,identifier:s,mode:e.mode}),e.memo.set(n,u),e.memo.size>zd){let[t]=e.memo.keys();e.memo.delete(t)}return u}te.autoDrawEnabled=!1,Reflect.set(te,`DD`,ee);const Gd=new Set,Kd=new Set,qd=new Map,Jd=[],Yd=[],Xd=new Set;let Zd=!1,Qd=!1,$d=0;function ef(){return $d}function tf(){$d+=1;try{Xd.forEach(e=>e())}finally{Zd=!1,Qd=!1;for(let e of Gd){if(qd.has(e)){Kd.add(e);continue}e.getStage()instanceof y&&e.batchDraw()}Gd.clear(),Jd.splice(0).forEach(e=>e())}}function nf(e){return Xd.add(e),()=>{Xd.delete(e)}}function rf(){queueMicrotask(()=>{if(Qd){Qd=!1,rf();return}tf()})}function af(){Qd=!0,!Zd&&(Zd=!0,rf())}function of(e){if(qd.has(e)){Kd.add(e);return}Gd.add(e),af()}function sf(e){qd.set(e,(qd.get(e)??0)+1)}function cf(e){let t=(qd.get(e)??0)-1;t>0?qd.set(e,t):qd.delete(e),Yd.splice(0).forEach(e=>e()),t<=0&&Kd.delete(e)&&of(e)}function lf(){return new Promise(e=>{Yd.push(()=>e())})}function uf(){return qd.size?lf().then(uf):Zd?new Promise(e=>{Jd.push(()=>e())}):Promise.resolve()}const df=Symbol(`r-html/konva-slot`),ff=Symbol(`r-html/konva-ledger`),pf=Symbol(`r-html/konva-virtual`),mf=Symbol(`r-html/konva-fragment`),hf=new Set([`class`,`style`,`zIndex`]),gf={reconcile:0,scan:0,attach:0,drop:0,order:0,setZIndex:0},_f={"k-layer":()=>new f,"k-group":()=>new d,"k-rect":()=>new _,"k-text":()=>new v,"k-path":()=>new g,"k-line":()=>new h,"k-circle":()=>new m};function vf(){}function yf(){throw Error(`[konva-host] a DOM-only directive reached the konva host. innerHTML and vCSSStyleSheet read the DOM through the module helpers, which a konva node has nothing to answer with`)}function bf(e,t=``){let n={kind:e,data:t};return Reflect.set(n,pf,e),Object.defineProperty(n,"nextSibling",{get:yf}),Object.defineProperty(n,"parentNode",{get:yf}),n}const xf=e=>e&&typeof e==`object`?Reflect.get(e,pf)??null:null,Sf=e=>e instanceof p,Cf=e=>Sf(e)&&Reflect.get(e,mf)===!0,wf=e=>Reflect.get(e,df);function Tf(e){let t=wf(e);if(t)return t;let n={node:e,parent:null,prev:null,next:null,doomed:!1};return Reflect.set(e,df,n),n}function Ef(e){let t=Reflect.get(e,ff);if(t)return t;let n={first:null,last:null,dirty:!1,reconciledAt:-1};return Reflect.set(e,ff,n),n}const Df=e=>wf(e)?.parent??null,Of=e=>wf(e)?.next?.node??null,kf=new Set,Af=new WeakMap;function jf(e){let t=e;for(;t;){if(t instanceof f)return t;t=Df(t)}return null}function Mf(e){let t=jf(e);t&&of(t)}function Nf(e){Ef(e).dirty=!0,kf.add(e),Mf(e),af()}function Pf(e){let t=e.parent;if(!t)return;let n=Ef(t);e.prev?e.prev.next=e.next:n.first=e.next,e.next?e.next.prev=e.prev:n.last=e.prev,e.parent=null,e.prev=null,e.next=null,Nf(t)}function Ff(e,t,n){Pf(t);let r=Ef(e);t.parent=e,t.doomed=!1,t.prev=n?n.prev:r.last,t.next=n,t.prev?t.prev.next=t:r.first=t,t.next?t.next.prev=t:r.last=t,Nf(e)}function If(e,t){if(!(!Sf(t)||Cf(e))){if(e instanceof y){if(!(t instanceof f))throw Error(`[konva-host] a Stage holds layers only, so ${t.getClassName()} cannot sit at a template root. Make k-layer the root`);return}if(t instanceof f)throw Error(`[konva-host] k-layer nests in nothing but a Stage`);if(Sf(e)&&!(e instanceof u))throw Error(`[konva-host] ${e.getClassName()} is a shape and holds no children`)}}function Lf(e,t,n){if(t===n)return;let r=n?Tf(n):null;if(!Cf(t)){If(e,t),Ff(e,Tf(t),r);return}let i=[];for(let e=Ef(t).first;e;e=e.next)i.push(e);for(let t of i)If(e,t.node),Ff(e,t,r)}function Rf(e){kf.delete(e),Reflect.deleteProperty(e,df),Reflect.deleteProperty(e,ff),e.destroy()}function zf(e,t){let n=t.getParent();n!==e&&(n&&kf.has(n)&&Wf(n),gf.attach+=1,e.add(t))}function Bf(e,t){if(e.length!==t.length)return!1;for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function Vf(e,t){t.forEach((t,n)=>{e.children[n]!==t&&(gf.setZIndex+=1,t.setZIndex(n))})}function Hf(e,t){let n=e.children;n.length=0;for(let e=0;e<t.length;e++){let r=t[e];n.push(r),r.index=e}}function Uf(e){if(gf.reconcile+=1,!(e instanceof u))return;let t=[];for(let n=Ef(e).first;n;n=n.next)gf.scan+=1,Sf(n.node)&&t.push(n.node);for(let n of t)zf(e,n);let n=new Set(t),r=e.children.filter(e=>!n.has(e));if(!(!r.length&&Bf(e.children,t))){gf.order+=1,e instanceof y?(r.forEach(e=>e.remove()),Vf(e,t)):(r.forEach(e=>{e.parent=null,e.index=0,e.remove()}),Hf(e,t));for(let e of r)gf.drop+=1,Tf(e).doomed&&Rf(e)}}function Wf(e){let t=Ef(e);!t.dirty&&t.reconciledAt===ef()||(t.dirty=!1,t.reconciledAt=ef(),Uf(e))}nf(()=>{for(let e of kf)Wf(e);kf.clear()});function Gf(e){let t=e,n=Df(t);for(;n;)t=n,n=Df(t);return Af.get(t)??t}function Kf(e,t){if(!t)return;let n=Gf(e);if(Sf(n)&&n.hasName(`minimap`))throw Error(`[konva-host] id "${t}" is not the minimap's to carry. Locate a minimap node by name plus a tableId attr`)}const qf=mu({createElement(e){let t=_f[e.toLowerCase()];if(!t)throw Error(`[konva-host] unknown konva tag <${e}>`);return t()},createText:e=>bf(`text`,e),createMarker:e=>bf(`marker`,e),createFragment(){let e=new d;return Reflect.set(e,mf,!0),Reflect.set(e,`_validateAdd`,vf),e},createEventBus:()=>new EventTarget,insertBefore(e,t){let n=Df(t);n&&Lf(n,e,t)},appendChild(e,t){Lf(e,t,null)},prependChild(e,t){Lf(e,t,Ef(e).first?.node??null)},removeChild(e){let t=Tf(e);Pf(t),Sf(e)&&(t.doomed=!0,e.getParent()||Rf(e))},parentOf:Df,nextSiblingOf:Of,setText(e,t){if(xf(e)!==`text`)throw Error(`[konva-host] a konva tree has no text node to write`);e.data=t},setAttribute(e,t,n,r){if(!Sf(e))return;if(hf.has(t))throw Error(`[konva-host] "${t}" is not a konva attribute a template may write`);let i=r?n:String(n);t===`id`&&Kf(e,i),e.attrs[t]!==i&&(e.setAttrs({[t]:i}),Mf(e))},removeAttribute(e,t){!Sf(e)||e.attrs[t]===void 0||(e.setAttrs({[t]:void 0}),Mf(e))},isHostNode:e=>Sf(e)||xf(e)!==null,isMarker:e=>xf(e)===`marker`,isText:e=>xf(e)===`text`,isElement:e=>Sf(e)&&!Cf(e),isFragment:e=>Cf(e),addEventListener(e,t,n,r){Sf(e)?e.on(`${t}.rhtml`,n):e.addEventListener(t,n,r)},removeEventListener(e,t,n,r){Sf(e)?e.off(`${t}.rhtml`,n):e.removeEventListener(t,n,r)},getRoot:Gf,createComponentContext(e,t){return{get host(){let n=Gf(e);return n instanceof y?n.container():t},get parentElement(){return null},dispatchEvent:e=>t.dispatchEvent(e)}},bridgeFragment(e,t){return Af.set(e,t),()=>{Af.delete(e)}}}),k=qf.html;function Jf(e,t){if(!(e instanceof y))throw Error(`[konva-host] a konva template renders into a Stage`);qf.render(e,t)}var Yf=(e,t)=>e*(1-t)/2;function Xf(e){return{originX:Ke(e.scrollLeft+Yf(e.width,e.zoomLevel),4),originY:Ke(e.scrollTop+Yf(e.height,e.zoomLevel),4)}}function A(e,t,n){return r=>{if(!n)return;let i=n[r];e(i)&&(t[r]=i)}}function Zf(e){return t=>C(t)&&e.includes(t)}function Qf(e){return t=>S(t)&&e.includes(t)}function $f(e,t,n){return Reflect.get(e,t)??n}function ep(){let e=Date.now();return{updateAt:e,createAt:e}}function tp(e,t){let n=A(S,e,t);n(`updateAt`),n(`createAt`)}var np=()=>({tableIds:[],relationshipIds:[],indexIds:[],memoIds:[]});function rp(e){let t=np();if(!de(e)||x(e))return t;let n=A(Array.isArray,t,e);return n(`tableIds`),n(`relationshipIds`),n(`indexIds`),n(`memoIds`),t}var ip=()=>({id:``,name:``,tableId:``,indexColumnIds:[],seqIndexColumnIds:[],unique:!1,meta:ep()});function ap(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=ip(),r=A(C,e,n),i=A(se,e,n),a=A(Array.isArray,e,n);r(`id`),r(`name`),r(`tableId`),i(`unique`),a(`indexColumnIds`),a(`seqIndexColumnIds`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var op={ASC:1,DESC:2},sp=Object.values(op),cp=()=>({id:``,indexId:``,columnId:``,orderType:op.ASC,meta:ep()});function lp(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=cp(),r=A(C,e,n);r(`id`),r(`indexId`),r(`columnId`),A(Qf(sp),e,n)(`orderType`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var up=()=>({id:``,value:``,ui:{x:200,y:100,zIndex:2,width:116,height:100,color:``},meta:ep()});function dp(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=up(),r=A(C,e,n),i=A(S,e.ui,n.ui),a=A(C,e.ui,n.ui);r(`id`),r(`value`),a(`color`),i(`x`),i(`y`),i(`zIndex`),i(`width`),i(`height`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var fp={ZeroOne:2,ZeroN:4,OneOnly:8,OneN:16},pp=Object.values(fp),mp={ring:1,dash:2},hp=Object.values(mp),gp={left:1,right:2,top:4,bottom:8},_p=Object.values(gp),vp=()=>({id:``,identification:!1,relationshipType:fp.ZeroN,startRelationshipType:mp.dash,start:{tableId:``,columnIds:[],x:0,y:0,direction:gp.bottom},end:{tableId:``,columnIds:[],x:0,y:0,direction:gp.bottom},meta:ep()});function yp(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=vp(),r=A(C,e,n),i=A(se,e,n),a=A(S,e.start,n.start),o=A(C,e.start,n.start),s=A(S,e.end,n.end),c=A(C,e.end,n.end);r(`id`),i(`identification`),A(Qf(pp),e,n)(`relationshipType`),A(Qf(hp),e,n)(`startRelationshipType`),o(`tableId`),a(`x`),a(`y`),A(Qf(_p),e.start,n.start)(`direction`),A(Array.isArray,e.start,n.start)(`columnIds`),c(`tableId`),s(`x`),s(`y`),A(Qf(_p),e.end,n.end)(`direction`),A(Array.isArray,e.end,n.end)(`columnIds`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var bp={ERD:`ERD`,visualization:`@dineug/erd-editor/builtin-visualization`,schemaSQL:`@dineug/erd-editor/builtin-schema-sql`,generatorCode:`@dineug/erd-editor/builtin-generator-code`,settings:`settings`},xp=Object.values(bp),Sp={tableComment:1,columnComment:2,columnDataType:4,columnDefault:8,columnAutoIncrement:16,columnPrimaryKey:32,columnUnique:64,columnNotNull:128,relationship:256},Cp={columnName:1,columnDataType:2,columnNotNull:4,columnUnique:8,columnAutoIncrement:16,columnDefault:32,columnComment:64},wp=Object.values(Cp),Tp={MariaDB:1,MSSQL:2,MySQL:4,Oracle:8,PostgreSQL:16,SQLite:32,Databricks:64,Snowflake:128},Ep=Object.values(Tp),Dp={GraphQL:1,csharp:2,Java:4,Kotlin:8,TypeScript:16,JPA:32,Scala:64,Go:128,SQLAlchemy:256,TypeORM:512,Sequelize:1024,Drizzle:2048,DBML:4096,AML:8192},Op=Object.values(Dp),kp={none:1,camelCase:2,pascalCase:4,snakeCase:8},Ap=Object.values(kp),jp={none:1,doubleQuote:2,singleQuote:4,backtick:8},Mp=Object.values(jp),Np={scroll:1,zoomLevel:2},Pp=.1,Fp=1.5,Ip=2e3,Lp=2e4,Rp=Sp.tableComment|Sp.columnComment|Sp.columnDataType|Sp.columnDefault|Sp.columnPrimaryKey|Sp.columnNotNull|Sp.relationship,zp=()=>({width:2e3,height:2e3,scrollTop:0,scrollLeft:0,originX:0,originY:0,zoomLevel:1,show:Rp,database:Tp.MySQL,databaseName:``,canvasType:bp.ERD,language:Dp.GraphQL,tableNameCase:kp.pascalCase,columnNameCase:kp.camelCase,bracketType:jp.none,relationshipDataTypeSync:!0,relationshipOptimization:!1,columnOrder:[Cp.columnName,Cp.columnDataType,Cp.columnNotNull,Cp.columnUnique,Cp.columnAutoIncrement,Cp.columnDefault,Cp.columnComment],maxWidthComment:-1,ignoreSaveSettings:0}),Bp=e=>re(e,Ip,Lp),Vp=e=>re(e,Pp,Fp),Hp=e=>re(e,60,200);function Up(e){let t=zp();if(!de(e)||x(e))return t;let n=A(S,t,e),r=A(C,t,e),i=A(se,t,e);if(S(e.width)&&(t.width=Bp(e.width)),S(e.height)&&(t.height=Bp(e.height)),S(e.zoomLevel)&&(t.zoomLevel=Vp(e.zoomLevel)),S(e.maxWidthComment)&&e.maxWidthComment!==-1&&(t.maxWidthComment=Hp(e.maxWidthComment)),n(`scrollTop`),n(`scrollLeft`),n(`show`),n(`ignoreSaveSettings`),r(`databaseName`),r(`canvasType`),i(`relationshipDataTypeSync`),i(`relationshipOptimization`),A(Qf(Ep),t,e)(`database`),A(Qf(Op),t,e)(`language`),A(Qf(Ap),t,e)(`tableNameCase`),A(Qf(Ap),t,e)(`columnNameCase`),A(Qf(Mp),t,e)(`bracketType`),Array.isArray(e.columnOrder)&&wp.length===e.columnOrder.length&&ae(wp,e.columnOrder).length===0&&(t.columnOrder=e.columnOrder),S(e.originX)&&S(e.originY))t.originX=e.originX,t.originY=e.originY;else{let{originX:e,originY:n}=Xf(t);t.originX=e,t.originY=n}return t}var Wp=()=>({id:``,name:``,comment:``,columnIds:[],seqColumnIds:[],ui:{x:200,y:100,zIndex:2,widthName:60,widthComment:60,color:``},meta:ep()});function Gp(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=Wp(),r=A(C,e,n),i=A(Array.isArray,e,n),a=A(S,e.ui,n.ui),o=A(C,e.ui,n.ui);r(`id`),r(`name`),r(`comment`),i(`columnIds`),i(`seqColumnIds`),o(`color`),a(`x`),a(`y`),a(`zIndex`),a(`widthName`),a(`widthComment`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}var Kp=()=>({id:``,tableId:``,name:``,comment:``,dataType:``,default:``,options:0,ui:{keys:0,widthName:60,widthComment:60,widthDataType:60,widthDefault:60},meta:ep()});function qp(e){let t={};if(!de(e)||x(e))return t;for(let n of Object.values(e)){if(!n)continue;let e=Kp(),r=A(C,e,n),i=A(S,e,n),a=A(S,e.ui,n.ui);r(`id`),r(`tableId`),r(`name`),r(`comment`),r(`dataType`),r(`default`),i(`options`),a(`keys`),a(`widthName`),a(`widthComment`),a(`widthDataType`),a(`widthDefault`),tp(e.meta,n.meta),e.id&&(t[e.id]=e)}return t}function Jp(e){let t=e;return{$schema:`https://raw.githubusercontent.com/dineug/erd-editor/main/json-schema/schema.json`,version:`3.0.0`,settings:Up(t.settings),doc:rp(t.doc),collections:{tableEntities:Gp(t.collections?.tableEntities),tableColumnEntities:qp(t.collections?.tableColumnEntities),relationshipEntities:yp(t.collections?.relationshipEntities),indexEntities:ap(t.collections?.indexEntities),indexColumnEntities:lp(t.collections?.indexColumnEntities),memoEntities:dp(t.collections?.memoEntities)}}}var j={CanvasType:bp,CanvasTypeList:xp,Show:Sp,ColumnType:Cp,ColumnTypeList:wp,Database:Tp,DatabaseList:Ep,Language:Dp,LanguageList:Op,NameCase:kp,NameCaseList:Ap,BracketType:jp,BracketTypeList:Mp,RelationshipType:fp,RelationshipTypeList:pp,StartRelationshipType:mp,StartRelationshipTypeList:hp,Direction:gp,DirectionList:_p,ColumnOption:{autoIncrement:1,primaryKey:2,unique:4,notNull:8},ColumnUIKey:{primaryKey:1,foreignKey:2},OrderType:op,OrderTypeList:sp,SaveSettingType:Np,CANVAS_SIZE_MAX:Lp,CANVAS_SIZE_MIN:Ip,CANVAS_ZOOM_MAX:Fp,CANVAS_ZOOM_MIN:Pp};function Yp(e){return[e,-1,-1,{}]}function Xp(e,t,n){return e[t]||(e[t]=Yp(n),e[t])}function Zp(e,t,n,r,i){let a=Xp(e,n,r),o=a[1],s=a[2];o<t&&(a[1]=t),s<t&&i()}function Qp(e,t,n,r,i){let a=Xp(e,n,r),o=a[2],s=a[1];o<t&&(a[2]=t),s<=t&&i()}function $p(e,t,n,r,i,a){let o=Xp(e,n,r);(o[3][i]??-1)<=t&&(o[3][i]=t,a())}function em(e){"@babel/helpers - typeof";return em=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},em(e)}function tm(e,t){if(em(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(em(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function nm(e){var t=tm(e,`string`);return em(t)==`symbol`?t:t+``}function rm(e,t,n){return(t=nm(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var im=class{constructor(e){rm(this,`collections`,void 0),this.collections=e}collection(e){return new am(this.collections[e],e)}},am=class{constructor(e,t){rm(this,`collection`,void 0),rm(this,`collectionKey`,void 0),this.collection=e,this.collectionKey=t}selectById(e){return this.collection[e]}selectByIds(e){return e.length,e.map(e=>this.selectById(e)).filter(Boolean)}selectEntities(){return this.collection}selectAll(){return Object.values(this.collection)}setOne(e){return this.collection[e.id]=e,this}setMany(e){return e.forEach(e=>this.setOne(e)),this}setAll(e){return this.removeAll(),this.setMany(e),this}addOne(e){return this.selectById(e.id)||this.setOne(e),this}addMany(e){return e.forEach(e=>this.addOne(e)),this}removeOne(e){return this.selectById(e)&&Reflect.deleteProperty(this.collection,e),this}removeMany(e){return e.forEach(e=>this.removeOne(e)),this}removeAll(){return this.collection={},this}updateOne(e,t){let n=this.selectById(e);return n&&(t(n),n.meta.updateAt=Date.now()),this}updateMany(e,t){return e.forEach(e=>this.updateOne(e,t)),this}getOrCreate(e,t){let n=this.selectById(e);if(n)return n;let r=t(e);return this.setOne(r),this.selectById(e)}addOperator(e,t,n,r){return Zp(e,t,n,this.collectionKey,r),this}removeOperator(e,t,n,r){return Qp(e,t,n,this.collectionKey,r),this}replaceOperator(e,t,n,r,i){return $p(e,t,n,this.collectionKey,r,i),this}},M=e=>new im(e),om=Object.values({columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnDefault:`columnDefault`,columnComment:`columnComment`}),sm=Object.values({ERD:`ERD`,"@vuerd/builtin-sql-ddl":`@vuerd/builtin-sql-ddl`,"@vuerd/builtin-grid":`@vuerd/builtin-grid`,"@vuerd/builtin-generator-code":`@vuerd/builtin-generator-code`,"@vuerd/builtin-visualization":`@vuerd/builtin-visualization`}),cm=Object.values({MariaDB:`MariaDB`,MSSQL:`MSSQL`,MySQL:`MySQL`,Oracle:`Oracle`,PostgreSQL:`PostgreSQL`,SQLite:`SQLite`}),lm=Object.values({GraphQL:`GraphQL`,"C#":`C#`,Java:`Java`,Kotlin:`Kotlin`,TypeScript:`TypeScript`,JPA:`JPA`,Scala:`Scala`}),um=Object.values({none:`none`,camelCase:`camelCase`,pascalCase:`pascalCase`,snakeCase:`snakeCase`}),dm=Object.values({AtomOneDark:`AtomOneDark`,AtomOneLight:`AtomOneLight`,MonokaiSublime:`MonokaiSublime`,GithubGist:`GithubGist`,VS2015:`VS2015`}),fm=Object.values({none:`none`,doubleQuote:`doubleQuote`,singleQuote:`singleQuote`,backtick:`backtick`}),pm=.1,mm=2e3,hm=2e4,gm=()=>({version:`2.2.11`,width:2e3,height:2e3,scrollTop:0,scrollLeft:0,zoomLevel:1,show:{tableComment:!0,columnComment:!0,columnDataType:!0,columnDefault:!0,columnAutoIncrement:!1,columnPrimaryKey:!0,columnUnique:!1,columnNotNull:!0,relationship:!0},database:`MySQL`,databaseName:``,canvasType:`ERD`,language:`GraphQL`,tableCase:`pascalCase`,columnCase:`camelCase`,highlightTheme:`VS2015`,bracketType:`none`,setting:{relationshipDataTypeSync:!0,relationshipOptimization:!1,columnOrder:[`columnName`,`columnDataType`,`columnNotNull`,`columnUnique`,`columnAutoIncrement`,`columnDefault`,`columnComment`]},pluginSerializationMap:{}}),_m=e=>re(e,mm,hm),vm=e=>re(e,pm,1);function ym(e){let t=gm();if(x(e))return t;let n=A(S,t,e),r=A(C,t,e),i=A(se,t.show,e.show),a=A(se,t.setting,e.setting);if(S(e.width)&&(t.width=_m(e.width)),S(e.height)&&(t.height=_m(e.height)),S(e.zoomLevel)&&(t.zoomLevel=vm(e.zoomLevel)),r(`version`),r(`databaseName`),n(`scrollTop`),n(`scrollLeft`),A(Zf(cm),t,e)(`database`),A(Zf(sm),t,e)(`canvasType`),A(Zf(lm),t,e)(`language`),A(Zf(um),t,e)(`tableCase`),A(Zf(um),t,e)(`columnCase`),A(Zf(dm),t,e)(`highlightTheme`),A(Zf(fm),t,e)(`bracketType`),i(`tableComment`),i(`columnComment`),i(`columnDataType`),i(`columnDefault`),i(`columnAutoIncrement`),i(`columnPrimaryKey`),i(`columnUnique`),i(`columnNotNull`),i(`relationship`),a(`relationshipDataTypeSync`),a(`relationshipOptimization`),e.setting?.columnOrder&&om.length===e.setting.columnOrder.length&&ae(om,e.setting.columnOrder).length===0&&(t.setting.columnOrder=e.setting.columnOrder),de(e.pluginSerializationMap)){let n=e.pluginSerializationMap;for(let e of Object.keys(n)){let r=n[e];C(r)&&(t.pluginSerializationMap[e]=r)}}return t}var bm=()=>({memos:[]}),xm=()=>({id:``,value:``,ui:{active:!1,left:200,top:200,zIndex:2,width:127,height:127}});function Sm(e){let t=bm();if(x(e)||!Array.isArray(e.memos))return t;for(let n of e.memos){let e=xm(),r=A(C,e,n),i=A(S,e.ui,n.ui),a=A(se,e.ui,n.ui),o=A(C,e.ui,n.ui);r(`id`),r(`value`),a(`active`),o(`color`),i(`left`),i(`top`),i(`zIndex`),i(`width`),i(`height`),t.memos.push(e)}return t}var Cm=[`ZeroOneN`,`One`,`N`],wm={ZeroOneN:`ZeroN`,One:`OneOnly`,N:`OneN`},Tm=e=>Cm.includes(e)?wm[e]:e,Em=Object.values({ZeroOneN:`ZeroOneN`,ZeroOne:`ZeroOne`,ZeroN:`ZeroN`,OneOnly:`OneOnly`,OneN:`OneN`,One:`One`,N:`N`}),Dm=Object.values({Ring:`Ring`,Dash:`Dash`}),Om=Object.values({left:`left`,right:`right`,top:`top`,bottom:`bottom`}),km=()=>({relationships:[]}),Am=()=>({id:``,identification:!1,relationshipType:`ZeroN`,startRelationshipType:`Dash`,start:{tableId:``,columnIds:[],x:0,y:0,direction:`bottom`},end:{tableId:``,columnIds:[],x:0,y:0,direction:`bottom`},constraintName:``,visible:!0});function jm(e){let t=km();if(x(e)||!Array.isArray(e.relationships))return t;for(let n of e.relationships){let e=Am(),r=A(C,e,n),i=A(se,e,n),a=A(S,e.start,n.start),o=A(C,e.start,n.start),s=A(S,e.end,n.end),c=A(C,e.end,n.end);r(`id`),r(`constraintName`),i(`identification`),i(`visible`),A(Zf(Em),e,n)(`relationshipType`),e.relationshipType=Tm(e.relationshipType),A(Zf(Dm),e,n)(`startRelationshipType`),o(`tableId`),a(`x`),a(`y`),A(Zf(Om),e.start,n.start)(`direction`),Array.isArray(n.start?.columnIds)&&(e.start.columnIds=n.start?.columnIds.filter(C)),c(`tableId`),s(`x`),s(`y`),A(Zf(Om),e.end,n.end)(`direction`),Array.isArray(n.end?.columnIds)&&(e.end.columnIds=n.end?.columnIds.filter(C)),t.relationships.push(e)}return t}var Mm={ASC:`ASC`,DESC:`DESC`},Nm=Object.values(Mm),Pm=()=>({tables:[],indexes:[]}),Fm=()=>({id:``,name:``,comment:``,columns:[],ui:{active:!1,left:200,top:100,zIndex:2,widthName:60,widthComment:60},visible:!0}),Im=()=>({id:``,name:``,comment:``,dataType:``,default:``,option:{autoIncrement:!1,primaryKey:!1,unique:!1,notNull:!1},ui:{active:!1,pk:!1,fk:!1,pfk:!1,widthName:60,widthComment:60,widthDataType:60,widthDefault:60}}),Lm=()=>({id:``,name:``,tableId:``,columns:[],unique:!1}),Rm=()=>({id:``,orderType:Mm.ASC});function zm(e){let t=Pm();if(x(e))return t;if(Array.isArray(e.tables))for(let n of e.tables){let e=Fm(),r=A(C,e,n),i=A(se,e,n),a=A(S,e.ui,n.ui),o=A(se,e.ui,n.ui),s=A(C,e.ui,n.ui);if(r(`id`),r(`name`),r(`comment`),i(`visible`),o(`active`),s(`color`),a(`left`),a(`top`),a(`zIndex`),a(`widthName`),a(`widthComment`),Array.isArray(n.columns))for(let t of n.columns){let n=Im(),r=A(C,n,t),i=A(S,n.ui,t.ui),a=A(se,n.ui,t.ui),o=A(se,n.option,t.option);r(`id`),r(`name`),r(`comment`),r(`dataType`),r(`default`),o(`autoIncrement`),o(`primaryKey`),o(`unique`),o(`notNull`),a(`active`),a(`pk`),a(`fk`),a(`pfk`),i(`widthName`),i(`widthComment`),i(`widthDataType`),i(`widthDefault`),e.columns.push(n)}t.tables.push(e)}if(Array.isArray(e.indexes))for(let n of e.indexes){let e=Lm(),r=A(C,e,n),i=A(se,e,n);if(r(`id`),r(`name`),r(`tableId`),i(`unique`),Array.isArray(n.columns))for(let t of n.columns){let n=Rm();A(C,n,t)(`id`),A(Zf(Nm),n,t)(`orderType`),e.columns.push(n)}t.indexes.push(e)}return t}function Bm(e){let t=e;return{canvas:ym(t.canvas),table:zm(t.table),relationship:jm(t.relationship),memo:Sm(t.memo)}}function Vm(e){let t=Jp({});return Hm(t.settings,e.canvas),Um(t,e.table),Wm(t,e.memo),Gm(t,e.relationship),t}function Hm(e,t){e.width=t.width,e.height=t.height,e.scrollTop=t.scrollTop,e.scrollLeft=t.scrollLeft,e.zoomLevel=t.zoomLevel;let{originX:n,originY:r}=Xf(e);e.originX=n,e.originY=r,e.databaseName=t.databaseName,e.canvasType=j.CanvasType.ERD,e.show=Object.keys(t.show).reduce((e,n)=>$f(t.show,n,!1)?e|$f(j.Show,n,0):e,0),e.database=Reflect.get(j.Database,t.database)??j.Database.MySQL,e.language=t.language===`C#`?j.Language.csharp:$f(j.Language,t.language,j.Language.GraphQL),e.tableNameCase=$f(j.NameCase,t.tableCase,j.NameCase.pascalCase),e.columnNameCase=$f(j.NameCase,t.columnCase,j.NameCase.camelCase),e.bracketType=$f(j.BracketType,t.bracketType,j.BracketType.none),e.relationshipDataTypeSync=t.setting.relationshipDataTypeSync,e.relationshipOptimization=t.setting.relationshipOptimization;let i=t.setting.columnOrder.map(e=>j.ColumnType[e]);ae(j.ColumnTypeList,i).length===0&&(e.columnOrder=i)}function Um(e,t){let n=t.tables.filter(({id:e})=>!!e),r=t.indexes.filter(({id:e})=>!!e);e.doc.tableIds=n.map(({id:e})=>e),e.doc.indexIds=r.map(({id:e})=>e);for(let t of n){let n=Wp();n.id=t.id,n.name=t.name,n.comment=t.comment,n.columnIds=t.columns.map(({id:e})=>e),n.seqColumnIds=[...n.columnIds],n.ui.y=t.ui.top,n.ui.x=t.ui.left,n.ui.zIndex=t.ui.zIndex,n.ui.widthName=t.ui.widthName,n.ui.widthComment=t.ui.widthComment,n.ui.color=t.ui.color??``;for(let n of t.columns){let r=Kp();r.id=n.id,r.tableId=t.id,r.name=n.name,r.comment=n.comment,r.dataType=n.dataType,r.default=n.default,r.options=Object.keys(n.option).reduce((e,t)=>$f(n.option,t,!1)?e|$f(j.ColumnOption,t,0):e,0),r.ui.widthName=n.ui.widthName,r.ui.widthComment=n.ui.widthComment,r.ui.widthDataType=n.ui.widthDataType,r.ui.widthDefault=n.ui.widthDefault,n.ui.pfk?r.ui.keys=j.ColumnUIKey.primaryKey|j.ColumnUIKey.foreignKey:n.ui.pk?r.ui.keys=j.ColumnUIKey.primaryKey:n.ui.fk&&(r.ui.keys=j.ColumnUIKey.foreignKey),e.collections.tableColumnEntities[r.id]=r}e.collections.tableEntities[n.id]=n}for(let t of r){let n=ip();n.id=t.id,n.name=t.name,n.tableId=t.tableId,n.unique=t.unique;for(let r of t.columns){let i=qe(),a=cp();n.indexColumnIds.push(i),n.seqIndexColumnIds.push(i),a.id=i,a.indexId=t.id,a.columnId=r.id,a.orderType=$f(j.OrderType,r.orderType,j.OrderType.ASC),e.collections.indexColumnEntities[a.id]=a}e.collections.indexEntities[n.id]=n}}function Wm(e,t){let n=t.memos.filter(({id:e})=>!!e);e.doc.memoIds=n.map(({id:e})=>e);for(let t of n){let n=up();n.id=t.id,n.value=t.value,n.ui.y=t.ui.top,n.ui.x=t.ui.left,n.ui.width=t.ui.width,n.ui.height=t.ui.height,n.ui.zIndex=t.ui.zIndex,n.ui.color=t.ui.color??``,e.collections.memoEntities[n.id]=n}}function Gm(e,t){let n=t.relationships.filter(({id:e})=>!!e);e.doc.relationshipIds=n.map(({id:e})=>e);for(let t of n){let n=vp();n.id=t.id,n.identification=t.identification,n.relationshipType=$f(j.RelationshipType,t.relationshipType,j.RelationshipType.ZeroN),n.startRelationshipType=$f(j.StartRelationshipType,t.startRelationshipType===`Ring`?`ring`:`dash`,j.StartRelationshipType.dash),n.start.tableId=t.start.tableId,n.start.columnIds=t.start.columnIds,n.start.x=t.start.x,n.start.y=t.start.y,n.start.direction=$f(j.Direction,t.start.direction,j.Direction.bottom),n.end.tableId=t.end.tableId,n.end.columnIds=t.end.columnIds,n.end.x=t.end.x,n.end.y=t.end.y,n.end.direction=$f(j.Direction,t.end.direction,j.Direction.bottom),e.collections.relationshipEntities[n.id]=n}}function Km(e,t){return(e&t)===t}function qm(e){let t=JSON.parse(e);return Reflect.get(t,`version`)===`3.0.0`?Jp(t):Vm(Bm(t))}function Jm(e){let t=ge(e,[`$schema`,`version`,`settings`,`doc`,`collections`]),n={...t.settings};return t.settings=n,Km(n.ignoreSaveSettings,j.SaveSettingType.scroll)&&(n.originX=0,n.originY=0),Km(n.ignoreSaveSettings,j.SaveSettingType.zoomLevel)&&(n.zoomLevel=1),JSON.stringify(t,null,2)}const N={changeHasHistory:`editor.changeHasHistory`,selectAll:`editor.selectAll`,unselectAll:`editor.unselectAll`,select:`editor.select`,changeViewport:`editor.changeViewport`,clear:`editor.clear`,loadJson:`editor.loadJson`,initialClear:`editor.initialClear`,initialLoadJson:`editor.initialLoadJson`,focusTable:`editor.focusTable`,focusColumn:`editor.focusColumn`,focusTableEnd:`editor.focusTableEnd`,focusMoveTable:`editor.focusMoveTable`,editTable:`editor.editTable`,editTableEnd:`editor.editTableEnd`,editMemo:`editor.editMemo`,editMemoEnd:`editor.editMemoEnd`,scrollMemo:`editor.scrollMemo`,selectAllColumn:`editor.selectAllColumn`,drawStartRelationship:`editor.drawStartRelationship`,drawStartAddRelationship:`editor.drawStartAddRelationship`,drawEndRelationship:`editor.drawEndRelationship`,drawRelationship:`editor.drawRelationship`,hoverColumnMap:`editor.hoverColumnMap`,hoverRelationshipMap:`editor.hoverRelationshipMap`,changeOpenMap:`editor.changeOpenMap`,changeHandTool:`editor.changeHandTool`,changeZenMode:`editor.changeZenMode`,dragstartColumn:`editor.dragstartColumn`,dragendColumn:`editor.dragendColumn`,sharedMouseTracker:`editor.sharedMouseTracker`,sharedFocusTracker:`editor.sharedFocusTracker`,sharedSelectionTracker:`editor.sharedSelectionTracker`,sharedDragSelectTracker:`editor.sharedDragSelectTracker`,dragSelectRect:`editor.dragSelectRect`,validationIds:`editor.validationIds`,getLWW:`editor.getLWW`,mergeLWW:`editor.mergeLWW`,viewOpen:`editor.viewOpen`,viewClose:`editor.viewClose`,viewScrollTo:`editor.viewScrollTo`,viewStreamScrollTo:`editor.viewStreamScrollTo`,viewChangeZoomLevel:`editor.viewChangeZoomLevel`,viewStreamZoomLevel:`editor.viewStreamZoomLevel`,viewMoveTable:`editor.viewMoveTable`,viewSetLayout:`editor.viewSetLayout`,viewChangeShowMode:`editor.viewChangeShowMode`,viewSetCenters:`editor.viewSetCenters`,changeVisualizationMode:`editor.changeVisualizationMode`},Ym=j.CanvasType,Xm=j.CanvasTypeList,P=j.Show,F=j.ColumnType,Zm=j.ColumnTypeList,I=j.Database,Qm=j.DatabaseList;j.Language;const $m=j.LanguageList;j.NameCase;const eh=j.NameCaseList,th=j.BracketType,nh=j.BracketTypeList,rh=j.RelationshipType;j.RelationshipTypeList;const ih=j.StartRelationshipType;j.StartRelationshipTypeList;const L=j.Direction;j.DirectionList;const R=j.ColumnOption,z=j.ColumnUIKey,ah=j.OrderType;j.OrderTypeList,j.SaveSettingType;const oh=j.CANVAS_SIZE_MAX,sh=j.CANVAS_SIZE_MIN,ch=j.CANVAS_ZOOM_MAX,lh=j.CANVAS_ZOOM_MIN;th.none,th.backtick,th.doubleQuote,th.singleQuote,F.columnName,F.columnDataType,F.columnDefault,F.columnComment,F.columnAutoIncrement,F.columnUnique,F.columnNotNull;const uh=1200;function B(e){let t=new Set(e);return e=>t.has(e)}function dh(e){return 6.25*Math.sqrt(Math.max(e,0))}function fh(e){return e>=0?e/2:dh(-e)}function ph(e,t,n){let r=fh((n.x-e.x)*t.x+(n.y-e.y)*t.y);return{x:e.x+t.x*r,y:e.y+t.y*r}}function mh(e,t,n,r){return[ph(e,t,n),ph(n,r,e)]}function hh(e,t,n,r,i=24){let a=Math.max(1,Math.floor(i)),[o,s]=mh(e,t,n,r),c=[{x:e.x,y:e.y}];for(let t=1;t<=a;t++){let r=t/a;c.push({x:gh(e.x,o.x,s.x,n.x,r),y:gh(e.y,o.y,s.y,n.y,r)})}return c}function gh(e,t,n,r,i){let a=1-i;return a*a*a*e+3*a*a*i*t+3*a*i*i*n+i*i*i*r}const V={left:`left`,right:`right`,top:`top`,bottom:`bottom`},_h=Object.values(V);B([V.top,V.bottom,V.left,V.right]);const vh=[0,0];function yh({tableId:e,x:t,y:n,direction:r}){return{tableId:e,x:t,y:n,direction:r}}const bh=()=>({epoch:0,stubSlots:new WeakMap,routes:new WeakMap,anchors:new WeakMap}),xh={document:bh(),flow:bh()},Sh={flow:new WeakMap};function Ch(e,t){let n=Sh[t],r=n.get(e);return r||(r=Ma({version:0}),n.set(e,r)),r}function wh(e,t){return Ch(e,t).version}function Th(e,t){Ch(e,t).version+=1}function Eh(e,t=`document`){let n=xh[t];for(let r of e){let e=n.stubSlots.delete(r),i=n.routes.delete(r),a=n.anchors.delete(r);t!==`document`&&(e||i||a)&&Th(r,t)}}const Dh=(e,t)=>e[0]===t[0]&&e[1]===t[1],Oh=(e,t)=>e.x===t.x&&e.y===t.y&&e.direction===t.direction,kh=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n].x&&e.y===t[n].y);function Ah(e,t,n=`document`){let r=xh[n];n!==`document`&&!Dh(r.stubSlots.get(e)??vh,t)&&Th(e,n),r.stubSlots.set(e,t)}function jh(e,t=`document`){return t!==`document`&&wh(e,t),xh[t].stubSlots.get(e)??vh}function Mh(e,t,n=`document`){let r=xh[n];if(n!==`document`){let i=r.routes.get(e);(!i||!kh(i.points,t))&&Th(e,n)}r.routes.set(e,{points:t,epoch:r.epoch})}function Nh(e,t=`document`){return t!==`document`&&wh(e,t),xh[t].routes.get(e)?.points}function Ph(e=`document`){xh[e].epoch+=1}function Fh(e,t=`document`){return t===`document`?e:(wh(e,t),xh[t].anchors.get(e)??e)}function Ih(e,{start:t,end:n},r=`document`){if(r===`document`){e.start.direction=t.direction,e.start.x=t.x,e.start.y=t.y,e.end.direction=n.direction,e.end.x=n.x,e.end.y=n.y;return}let{anchors:i}=xh[r],a=i.get(e)??e;(!Oh(a.start,t)||!Oh(a.end,n))&&Th(e,r),i.set(e,{start:yh(t),end:yh(n)})}function Lh(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{x:a,y:o}of e)a<t&&(t=a),o<n&&(n=o),a>r&&(r=a),o>i&&(i=o);return{x:t,y:n,width:r-t,height:i-n}}function Rh({x:e,y:t,width:n,height:r},i){return{x:e-i,y:t-i,width:n+i*2,height:r+i*2}}function zh(e=`document`){return e===`document`?2:1}function Bh(e,t=2,n=`document`){let r=xh[n],{start:i,end:a}=Fh(e,n),o=r.routes.get(e),s=o&&o.epoch===r.epoch?o.points:null,c=s?0:86;if(n!==`document`){let e=Lh([...s?.length?[s[0],s[s.length-1]]:[],i,a]),n=dh(Math.max(e.width,e.height)+2*c);return Rh(e,25+t+c+n)}return Rh(Lh(s?[...s,i,a]:[i,a]),25+t+c)}const Vh={Databricks:`Databricks`,MariaDB:`MariaDB`,MSSQL:`MSSQL`,MySQL:`MySQL`,Oracle:`Oracle`,PostgreSQL:`PostgreSQL`,Snowflake:`Snowflake`,SQLite:`SQLite`},Hh=Object.values(Vh);Vh.Databricks,I.Databricks,Vh.MariaDB,I.MariaDB,Vh.MSSQL,I.MSSQL,Vh.MySQL,I.MySQL,Vh.Oracle,I.Oracle,Vh.PostgreSQL,I.PostgreSQL,Vh.Snowflake,I.Snowflake,Vh.SQLite,I.SQLite;const Uh=/[^0-9]/g,Wh=e=>e.replace(Uh,``),Gh=e=>re(e,sh,oh),Kh=e=>re(e,lh,ch),qh=e=>re(e,60,200);function Jh(e){let t=C(e)?Number(Wh(e)):e;return Gh(t)}function Yh(e){return Ke(Kh(e),2)}const Xh=B(Qm),Zh=B(eh),Qh=B(nh),$h=B($m),eg=B(Zm);B(Hh);const tg=B(Xm);function H(e){return Math.max(e,60)}function ng(e){return C(e)?e.trim():``}function rg(e){return e<=.7}const ig={table:`table`,memo:`memo`},ag={nameOnly:`nameOnly`,keysOnly:`keysOnly`,allFields:`allFields`},og={flow:`flow`},sg={graph:`graph`,flow:`flow`},U={tableName:`tableName`,tableComment:`tableComment`,columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnDefault:`columnDefault`,columnComment:`columnComment`},cg={ArrowUp:`ArrowUp`,ArrowRight:`ArrowRight`,ArrowDown:`ArrowDown`,ArrowLeft:`ArrowLeft`,Tab:`Tab`};B(Object.values(cg));const lg=()=>({id:qe(),selectedMap:{},hasUndo:!1,hasRedo:!1,viewport:{width:uh,height:675},scrollPullPending:!1,focusTable:null,editMemoId:null,memoScrollTopMap:{},drawRelationship:null,hoverColumnMap:{},hoverRelationshipMap:{},openMap:{},handTool:!1,zenMode:!1,draggableColumn:null,draggingColumnMap:{},sharedMouseTrackerMap:{},sharedFocusTrackerMap:{},sharedSelectionTrackerMap:{},sharedDragSelectTrackerMap:{},dragSelect:null,views:{flow:null},visualizationMode:sg.graph}),ug=e=>e.settings.canvasType===Ym.visualization&&e.editor.visualizationMode===sg.flow,dg=e=>ug(e)?e.editor.views.flow:null,fg=(e,t)=>e.editor.views[t]!==null&&ug(e),pg=(e,t)=>t===`document`?null:e.editor.views[t];function mg(e,t=[]){let n=[...t];return{kind:e,showMode:n.length?ag.keysOnly:ag.nameOnly,positions:{},originX:0,originY:0,zoomLevel:1,centerIds:n}}function hg({collections:e},t){Eh(M(e).collection(`relationshipEntities`).selectAll(),t)}const gg=(e,t)=>t?e.editor.views[t]:dg(e);function _g(e){e.views.flow=null}const vg=O(N.viewOpen),yg=(e,{payload:{kind:t,centerIds:n}})=>{hg(e,t),e.editor.views[t]=mg(t,n)},bg=O(N.viewClose),xg=(e,{payload:{kind:t}})=>{hg(e,t),e.editor.views[t]=null},Sg=O(N.viewScrollTo),Cg=(e,{payload:{originX:t,originY:n,kind:r}})=>{let i=gg(e,r);i&&(i.originX=Ke(t,4),i.originY=Ke(n,4))},wg=O(N.viewStreamScrollTo),Tg=(e,{payload:{movementX:t,movementY:n,kind:r}})=>{let i=gg(e,r);i&&(i.originX=Ke(i.originX+t,4),i.originY=Ke(i.originY+n,4))},Eg=O(N.viewChangeZoomLevel),Dg=(e,{payload:{value:t,kind:n}})=>{let r=gg(e,n);r&&(r.zoomLevel=Yh(t))},Og=O(N.viewStreamZoomLevel),kg=(e,{payload:{value:t,kind:n}})=>{let r=gg(e,n);r&&(r.zoomLevel=Yh(r.zoomLevel+t))},Ag=O(N.viewMoveTable),jg=(e,{payload:{ids:t,movementX:n,movementY:r,kind:i}})=>{let a=gg(e,i);if(a)for(let e of t){let t=a.positions[e];t&&(t.x=Ke(t.x+n,4),t.y=Ke(t.y+r,4))}},Mg=O(N.viewSetLayout),Ng=({editor:e},{payload:{kind:t,positions:n}})=>{let r=e.views[t];r&&(r.positions=Object.fromEntries(Object.entries(n).map(([e,{x:t,y:n}])=>[e,{x:t,y:n}])))},Pg=O(N.viewChangeShowMode),Fg=(e,{payload:{value:t,kind:n}})=>{let r=gg(e,n);r&&(r.showMode=t)},Ig=O(N.viewSetCenters),Lg=(e,{payload:{tableIds:t,kind:n}})=>{let r=gg(e,n);r&&(r.centerIds=[...t])},Rg=O(N.changeVisualizationMode),zg=({editor:e},{payload:{value:t}})=>{e.visualizationMode=t},Bg={[N.viewOpen]:yg,[N.viewClose]:xg,[N.viewScrollTo]:Cg,[N.viewStreamScrollTo]:Tg,[N.viewChangeZoomLevel]:Dg,[N.viewStreamZoomLevel]:kg,[N.viewMoveTable]:jg,[N.viewSetLayout]:Ng,[N.viewChangeShowMode]:Fg,[N.viewSetCenters]:Lg,[N.changeVisualizationMode]:zg},Vg={viewOpenAction:vg,viewCloseAction:bg,viewScrollToAction:Sg,viewStreamScrollToAction:wg,viewChangeZoomLevelAction:Eg,viewStreamZoomLevelAction:Og,viewMoveTableAction:Ag,viewSetLayoutAction:Mg,viewChangeShowModeAction:Pg,viewSetCentersAction:Ig,changeVisualizationModeAction:Rg},Hg={shared:1,changeOnly:2,following:4,drag:8};function Ug(e,t){return{...ie(t),tags:S(t.tags)&&Number.isInteger(t.tags)?t.tags|e:e}}function Wg(e,t){return t.map(t=>Ug(e,t))}(e=>(...t)=>function*(n,r){yield Wg(e,Iu(n,r,t))})(Hg.changeOnly);function W(e,t){return(e&t)===t}const Gg=Object.freeze({tableIds:[],memoIds:[],relationshipIds:[]});function Kg(e,t,n=`document`){let{x:r,y:i}=pg(e,n)?.positions[t.id]??t.ui;return{x:r,y:i}}const qg=e=>W(e,z.primaryKey)||W(e,z.foreignKey);function Jg(e,t){let n=M(e.collections).collection(`relationshipEntities`).selectByIds(e.doc.relationshipIds);for(let{start:e,end:r}of n)t(e.tableId,e.columnIds),t(r.tableId,r.columnIds)}function Yg(e,t){let n=new Set;return Jg(e,(e,r)=>{e===t.id&&r.forEach(e=>n.add(e))}),n}function Xg(e,t,n=`document`){let r=pg(e,n);if(!r||r.showMode===ag.allFields)return t.columnIds;if(r.showMode===ag.nameOnly)return[];let i=Yg(e,t);return M(e.collections).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(e=>qg(e.ui.keys)||i.has(e.id)).map(e=>e.id)}function Zg(e,t=`document`){let{doc:n,collections:r}=e;if(t===`document`)return{tableIds:n.tableIds,memoIds:n.memoIds,relationshipIds:n.relationshipIds};let i=pg(e,t);if(!i)return Gg;let a=M(r).collection(`relationshipEntities`).selectByIds(n.relationshipIds),o=new Set(Object.keys(i.positions)),s=n.tableIds.filter(e=>o.has(e)),c=new Set(s);return{tableIds:s,memoIds:[],relationshipIds:a.filter(({start:e,end:t})=>c.has(e.tableId)&&c.has(t.tableId)).map(e=>e.id)}}const Qg=Ma({tableId:{}}),$g=new Map;function e_(e){$g.delete(e),Reflect.deleteProperty(Qg.tableId,e)}function t_(e,t,n=`document`){let r=pg(e,n),{id:i}=e.editor;if(t===null||!r){$g.get(i)?.kind===n&&e_(i);return}$g.set(i,r),Qg.tableId[i]=t}function n_(e,t,n=`document`){let{id:r}=e.editor;Qg.tableId[r]===t&&$g.get(r)?.kind===n&&e_(r)}const r_=Ma({tableId:{}}),i_=new Map;function a_(e){i_.delete(e),Reflect.deleteProperty(r_.tableId,e)}function o_(e,t,n=`document`){let r=pg(e,n);if(!r)return;let{id:i}=e.editor;if((i_.get(i)===r?r_.tableId[i]:void 0)===t){a_(i);return}i_.set(i,r),r_.tableId[i]=t}function s_(e){return 9+e.ui.width+8+1}function c_(e){return 25+e.ui.height+8+1}let l_=0;function u_(){return l_}function d_(){l_++}function f_(e,{settings:{show:t,maxWidthComment:n},collections:r}){let i=20+e.ui.widthName+8;if(W(t,P.tableComment)){let t=n===-1?e.ui.widthComment:n<e.ui.widthComment?n:e.ui.widthComment;i+=t+8}i+=28;let a=m_(t);i<a&&(i=a);let o=g_(M(r).collection(`tableColumnEntities`).selectByIds(e.columnIds),t,n);return i<o.width&&(i=o.width),{...o,width:9+i+8+1}}const p_=[{key:P.columnComment,width:60},{key:P.columnDataType,width:60},{key:P.columnDefault,width:60},{key:P.columnNotNull,width:35},{key:P.columnAutoIncrement,width:15},{key:P.columnUnique,width:22}];function m_(e){return p_.reduce((t,{key:n,width:r})=>W(e,n)?t+r+8:t,100)}function h_(){return{width:0,name:0,comment:0,dataType:0,default:0,notNull:0,autoIncrement:0,unique:0}}function g_(e,t,n){let r=h_();for(let i of e)r.name<i.ui.widthName&&(r.name=i.ui.widthName),W(t,P.columnComment)&&r.comment<i.ui.widthComment&&(r.comment=n===-1?i.ui.widthComment:n<i.ui.widthComment?n:i.ui.widthComment),W(t,P.columnDataType)&&r.dataType<i.ui.widthDataType&&(r.dataType=i.ui.widthDataType),W(t,P.columnDefault)&&r.default<i.ui.widthDefault&&(r.default=i.ui.widthDefault);return W(t,P.columnNotNull)&&(r.notNull=35),W(t,P.columnAutoIncrement)&&(r.autoIncrement=15),W(t,P.columnUnique)&&(r.unique=22),r.width=Object.entries(r).reduce((e,[t,n])=>t===`width`||n===0?e:e+n+8,32),r}function __(e,t,n){let r=h_(),i=M(t.collections).collection(`tableColumnEntities`).selectByIds(n);for(let e of i)r.name=Math.max(r.name,e.ui.widthName),r.dataType=Math.max(r.dataType,e.ui.widthDataType);let a=i.length?22+r.name+8+r.dataType:0,o=Math.max(y_(e),a,154);return i.length&&(r.name+=o-a),r.width=18+o,r}function v_(e){return Math.ceil(e*1.1666666666666667*1.04)}function y_(e){return 20+v_(e.ui.widthName)+8+28}function b_(e=`document`){return e===`document`?20:24}function x_(e=`document`){return e===`document`?24:32}function S_(e,t=e.columnIds.length,n=`document`){return 9+b_(n)+t*x_(n)+1}function C_({doc:{tableIds:e},collections:t},{toWidth:n}){d_();let r=M(t).collection(`tableEntities`).selectByIds(e),i=M(t).collection(`tableColumnEntities`);for(let e of r){e.ui.widthName=H(n(e.name)),e.ui.widthComment=H(n(e.comment));let t=i.selectByIds(e.columnIds);for(let e of t)e.ui.widthName=H(n(e.name)),e.ui.widthDataType=H(n(e.dataType)),e.ui.widthDefault=H(n(e.default)),e.ui.widthComment=H(n(e.comment))}}const w_={document:new WeakMap,flow:new WeakMap};function T_(e,t,n){let r=w_[n],i=n===`document`?E_(e,t):D_(e,t,n),a=r.get(t);if(a?.key===i.key)return a;let o=i.measure();return r.set(t,o),o}function E_(e,t){let{settings:n}=e,r=`${u_()}|${n.show}|${n.maxWidthComment}|${t.ui.widthName}|${t.ui.widthComment}|${t.columnIds.length}`;return{key:r,measure:()=>({key:r,width:f_(t,e).width,height:S_(t)})}}function D_(e,t,n){let r=pg(e,n)?.showMode??ag.allFields,i=Xg(e,t,n),a=`${u_()}|${t.ui.widthName}|${t.columnIds.length}|${r}|${i.length}`;return{key:a,measure:()=>({key:a,width:__(t,e,i).width,height:S_(t,i.length,n)})}}function O_(e,t,n=`document`){let{width:r,height:i}=T_(e,t,n),{x:a,y:o}=Kg(e,t,n);return{width:r,height:i,top:{x:a+r/2,y:o},bottom:{x:a+r/2,y:o+i},left:{x:a,y:o+i/2},right:{x:a+r,y:o+i/2},lt:{x:a,y:o},rt:{x:a+r,y:o},lb:{x:a,y:o+i},rb:{x:a+r,y:o+i}}}function k_(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function A_(e,t,n=`document`){let{width:r,height:i}=O_(e,t,n),{x:a,y:o}=Kg(e,t,n);return{x:a,y:o,width:r,height:i}}function j_(e,t,n=`document`){return n===`document`?f_(t,e):__(t,e,Xg(e,t,n))}function M_(e,t,n,r=`document`){let{x:i,y:a,width:o}=A_(e,t,r),s=x_(r);return{x:i+9,y:a+9+b_(r)+n*s,width:o-18,height:s}}function N_(e){let{x:t,y:n}=e.ui;return{x:t,y:n,width:s_(e),height:c_(e)}}function P_(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,width:Math.max(e.x+e.width,t.x+t.width)-n,height:Math.max(e.y+e.height,t.y+t.height)-r}}function F_(e){return R_(e,[])}function I_(e,t=`document`){return R_(e,[],t)}function L_(e,t=[],n=`document`){let{collections:r,doc:i}=e,{tableIds:a,memoIds:o}=n===`document`?i:Zg(e,n),s=new Map(t.map(e=>[e.id,e])),c=M(r).collection(`tableEntities`).selectByIds(a),l=M(r).collection(`memoEntities`).selectByIds(o);return[...c.map(t=>{let r=A_(e,t,n),i=s.get(t.id);return i?{...r,x:i.x,y:i.y}:r}),...l.map(N_)]}function R_(e,t,n=`document`){let r=L_(e,t,n);return r.length?r.reduce(P_):null}function z_(e){return dg(e)??e.settings}function B_(e,t=`document`){return pg(e,t)??e.settings}function V_(e,t){return t?B_(e,t):z_(e)}function H_({originX:e,originY:t}){return{x:e,y:t}}const U_=e=>e>0?e:1;function W_(e,t){let n=H_(e);return{x:n.x+t.x*e.zoomLevel,y:n.y+t.y*e.zoomLevel}}function G_(e,t){let n=U_(e.zoomLevel),r=H_({...e,zoomLevel:n});return{x:(t.x-r.x)/n,y:(t.y-r.y)/n}}function K_(e,t,n){return{x:n.x-t.x*e,y:n.y-t.y*e}}function q_(e){let{viewportWidth:t,viewportHeight:n}=e,r=U_(e.zoomLevel),i=H_({...e,zoomLevel:r}),a=(t>0?t:uh)/r,o=(n>0?n:675)/r;return{x:-i.x/r-a,y:-i.y/r-o,width:a*3,height:o*3}}function J_(e,t=`document`){let{originX:n,originY:r,zoomLevel:i}=B_(e,t),{viewport:a}=e.editor;return q_({originX:n,originY:r,zoomLevel:i,viewportWidth:a.width,viewportHeight:a.height})}function Y_(e,t){return!(t.x>e.x+e.width||t.x+t.width<e.x||t.y>e.y+e.height||t.y+t.height<e.y)}function X_(e,t,n,r=`document`){return Y_(e,A_(t,n,r))}function Z_(e,t,n,r=`document`){return Y_(e,Bh(t,n,r))}const Q_=Ma({frozen:{}}),$_=(e,t)=>`${e.editor.id}:${t}`,ev=(e,t)=>Q_.frozen[$_(e,t)]??null;function tv(e,t=`document`){let{originX:n,originY:r}=B_(e,t);Q_.frozen[$_(e,t)]={content:I_(e,t),origin:{x:n,y:r}}}function nv(e,t=`document`){Reflect.deleteProperty(Q_.frozen,$_(e,t))}function rv(e,t=`document`){let n=ev(e,t);return n?n.content:I_(e,t)}const G={changeDatabaseName:`settings.changeDatabaseName`,changeZoomLevel:`settings.changeZoomLevel`,streamZoomLevel:`settings.streamZoomLevel`,scrollTo:`settings.scrollTo`,streamScrollTo:`settings.streamScrollTo`,changeShow:`settings.changeShow`,changeDatabase:`settings.changeDatabase`,changeCanvasType:`settings.changeCanvasType`,changeLanguage:`settings.changeLanguage`,changeTableNameCase:`settings.changeTableNameCase`,changeColumnNameCase:`settings.changeColumnNameCase`,changeBracketType:`settings.changeBracketType`,changeRelationshipDataTypeSync:`settings.changeRelationshipDataTypeSync`,changeRelationshipOptimization:`settings.changeRelationshipOptimization`,changeColumnOrder:`settings.changeColumnOrder`,changeMaxWidthComment:`settings.changeMaxWidthComment`,changeIgnoreSaveSettings:`settings.changeIgnoreSaveSettings`},iv=e=>e+0;function av(e,t,n,r){let i=-t*r,a=n-e*r;return{min:iv(Math.min(i,a)),max:iv(Math.max(i,a))}}function ov(e,t,n,r,i){let{min:a,max:o}=av(t,n,r,i);if(a<e&&e<o)return e;let s=Math.min(r,(n-t)*i);return iv(Math.min(Math.max(e,a+s),o-s))}const sv=O(G.changeDatabaseName),cv=({settings:e,lww:t},{payload:{value:n},version:r},{clock:i})=>{$p(t,r??i.getVersion(),`settings.databaseName`,`settings`,`databaseName`,()=>{e.databaseName=n})},lv=O(G.changeZoomLevel),uv=({settings:e},{payload:{value:t},tags:n})=>{!x(n)&&W(n,Hg.following)||(e.zoomLevel=Yh(t))},dv=O(G.streamZoomLevel),fv=({settings:e},{payload:{value:t},tags:n})=>{!x(n)&&W(n,Hg.following)||(e.zoomLevel=Yh(e.zoomLevel+t))},pv=({width:e,height:t})=>e>0&&t>0;function mv(e){let{settings:{originX:t,originY:n,zoomLevel:r},editor:{viewport:i}}=e,a=rv(e);return!a||!pv(i)?{x:t,y:n}:{x:ov(t,a.x,a.x+a.width,i.width,r),y:ov(n,a.y,a.y+a.height,i.height,r)}}const hv=O(G.scrollTo),gv=({settings:e},{payload:{originX:t,originY:n},tags:r})=>{!x(r)&&W(r,Hg.following)||(e.originX=Ke(t,4),e.originY=Ke(n,4))},_v=O(G.streamScrollTo),vv=({settings:e},{payload:{movementX:t,movementY:n},tags:r})=>{!x(r)&&W(r,Hg.following)||(e.originX=Ke(e.originX+t,4),e.originY=Ke(e.originY+n,4))},yv=O(G.changeShow),bv=({settings:e},{payload:{show:t,value:n}})=>{e.show=n?e.show|t:e.show&~t},xv=O(G.changeDatabase),Sv=({settings:e},{payload:{value:t}})=>{Xh(t)&&(e.database=t)},Cv=O(G.changeCanvasType),wv=({settings:e},{payload:{value:t},tags:n})=>{!x(n)&&W(n,Hg.following)||(e.canvasType=t)},Tv=O(G.changeLanguage),Ev=({settings:e},{payload:{value:t}})=>{$h(t)&&(e.language=t)},Dv=O(G.changeTableNameCase),Ov=({settings:e},{payload:{value:t}})=>{Zh(t)&&(e.tableNameCase=t)},kv=O(G.changeColumnNameCase),Av=({settings:e},{payload:{value:t}})=>{Zh(t)&&(e.columnNameCase=t)},jv=O(G.changeBracketType),Mv=({settings:e},{payload:{value:t}})=>{Qh(t)&&(e.bracketType=t)},Nv=O(G.changeRelationshipDataTypeSync),Pv=({settings:e},{payload:{value:t}})=>{e.relationshipDataTypeSync=t},Fv=O(G.changeRelationshipOptimization),Iv=({settings:e},{payload:{value:t}})=>{e.relationshipOptimization=t},Lv=O(G.changeColumnOrder),Rv=({settings:e},{payload:{value:t,target:n}})=>{if(t===n||!eg(t)||!eg(n))return;let r=e.columnOrder.indexOf(t),i=e.columnOrder.indexOf(n);r!==-1&&i!==-1&&(e.columnOrder.splice(r,1),e.columnOrder.splice(i,0,t))},zv=O(G.changeMaxWidthComment),Bv=({settings:e},{payload:{value:t}})=>{e.maxWidthComment=t===-1?t:qh(t)},Vv=O(G.changeIgnoreSaveSettings),Hv=({settings:e},{payload:{saveSettingType:t,value:n}})=>{e.ignoreSaveSettings=n?e.ignoreSaveSettings|t:e.ignoreSaveSettings&~t},Uv={[G.changeDatabaseName]:cv,[G.changeZoomLevel]:uv,[G.streamZoomLevel]:fv,[G.scrollTo]:gv,[G.streamScrollTo]:vv,[G.changeShow]:bv,[G.changeDatabase]:Sv,[G.changeCanvasType]:wv,[G.changeLanguage]:Ev,[G.changeTableNameCase]:Ov,[G.changeColumnNameCase]:Av,[G.changeBracketType]:Mv,[G.changeRelationshipDataTypeSync]:Pv,[G.changeRelationshipOptimization]:Iv,[G.changeColumnOrder]:Rv,[G.changeMaxWidthComment]:Bv,[G.changeIgnoreSaveSettings]:Hv},Wv={changeDatabaseNameAction:sv,changeZoomLevelAction:lv,streamZoomLevelAction:dv,scrollToAction:hv,streamScrollToAction:_v,changeShowAction:yv,changeDatabaseAction:xv,changeCanvasTypeAction:Cv,changeLanguageAction:Tv,changeTableNameCaseAction:Dv,changeColumnNameCaseAction:kv,changeBracketTypeAction:jv,changeRelationshipDataTypeSyncAction:Nv,changeRelationshipOptimizationAction:Fv,changeColumnOrderAction:Lv,changeMaxWidthCommentAction:zv,changeIgnoreSaveSettingsAction:Vv},Gv=e=>e.ui.zIndex,Kv=(e,t)=>Math.max(1,...e.map(Gv),...t.map(Gv))+1,qv=e=>t=>e.y===t.y&&e.x===t.x;function Jv(e,t,n){let r=G_(e,{x:200,y:100}),i=[...t,...n].map(({ui:e})=>e);for(;i.some(qv(r));)r.x+=50,r.y+=50;return r}function Yv(){let e=Date.now();return{updateAt:e,createAt:e}}function Xv(e,t){return e<t?_e(e,t+1):_e(t,e+1)}function Zv(e){return be(ne(e??``))}function Qv(e,t){return ye([...e,t])}function $v(e,t,n){if(!t||t===n)return[n];let r=e.indexOf(t),i=e.indexOf(n);return r===-1?[n]:Xv(r,i).map(t=>e[t])}function ey(e,t,n,r){return ye([...t,...$v(e,n,r)])}const ty={[F.columnName]:!0,[F.columnDataType]:P.columnDataType,[F.columnNotNull]:P.columnNotNull,[F.columnUnique]:P.columnUnique,[F.columnAutoIncrement]:P.columnAutoIncrement,[F.columnDefault]:P.columnDefault,[F.columnComment]:P.columnComment},ny={[F.columnName]:U.columnName,[F.columnDataType]:U.columnDataType,[F.columnNotNull]:U.columnNotNull,[F.columnUnique]:U.columnUnique,[F.columnAutoIncrement]:U.columnAutoIncrement,[F.columnDefault]:U.columnDefault,[F.columnComment]:U.columnComment},ry=[U.tableName,U.tableComment];function iy({settings:{show:e,columnOrder:t}}){return t.filter(t=>{let n=ty[t];return n===!0||W(e,n)}).map(e=>ny[e])}function ay({collections:e,editor:{focusTable:t}}){return t?!!M(e).collection(`tableEntities`).selectById(t.tableId)?.columnIds.length:!1}function oy(e){let{editor:{focusTable:t}}=e;if(!t)return!0;let n=iy(e);return n.indexOf(t.focusType)===n.length-1}function sy(e){let{editor:{focusTable:t}}=e;return!t||iy(e).indexOf(t.focusType)===0}function cy({collections:e,editor:{focusTable:t}}){if(!t?.columnId)return!0;let n=M(e).collection(`tableEntities`).selectById(t.tableId);return!n||n.columnIds.indexOf(t.columnId)===n.columnIds.length-1}function ly({collections:e,editor:{focusTable:t}}){if(!t?.columnId)return!0;let n=M(e).collection(`tableEntities`).selectById(t.tableId);return!n||n.columnIds.indexOf(t.columnId)===0}function uy(e){let t=iy(e);return t[t.length-1]}function dy(e){return iy(e)[0]}function fy(e){let{editor:{focusTable:t}}=e;if(!t)return U.columnName;let n=iy(e),r=n.indexOf(t.focusType);return oy(e)?n[0]:n[r+1]}function py(e){let{editor:{focusTable:t}}=e;if(!t)return U.columnName;let n=iy(e),r=n.indexOf(t.focusType);return sy(e)?n[n.length-1]:n[r-1]}function my(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r?.columnId)return null;let i=M(n).collection(`tableEntities`).selectById(r.tableId);if(!i)return null;let a=i.columnIds.indexOf(r.columnId);if(a<=0)return null;let o=null;for(let e=a;e>=0;e--){let n=i.columnIds[e];if(!t.includes(n)){o=n;break}}return o}function hy({settings:{show:e}}){return W(e,P.tableComment)?ry:[U.tableName]}function gy(e){let{editor:{focusTable:t}}=e;if(!t)return!0;let n=hy(e);return n.indexOf(t.focusType)===n.length-1}function _y(e){let{editor:{focusTable:t}}=e;return!t||hy(e).indexOf(t.focusType)===0}const vy=B(ry);function yy(e){let{editor:{focusTable:t}}=e;if(!t)return U.tableName;let n=hy(e),r=n.indexOf(t.focusType);return gy(e)?n[0]:n[r+1]}function by(e){let{editor:{focusTable:t}}=e;if(!t)return U.tableName;let n=hy(e),r=n.indexOf(t.focusType);return _y(e)?n[n.length-1]:n[r-1]}function xy(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=M(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(vy(r.focusType)){if(ay(e)){let t=i.columnIds[i.columnIds.length-1];r.focusType=uy(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}}else if(ly(e))r.focusType=U.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let e=i.columnIds.indexOf(r.columnId),n=i.columnIds[e-1];r.columnId=n,r.prevSelectColumnId=n,r.selectColumnIds=t.shiftKey&&t.moveKey!==cg.Tab?Qv(r.selectColumnIds,n):[n]}}}function Sy(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=M(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(vy(r.focusType)){if(ay(e)){let t=i.columnIds[0];r.focusType=dy(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}}else if(cy(e))r.focusType=U.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let e=i.columnIds.indexOf(r.columnId),n=i.columnIds[e+1];r.columnId=n,r.prevSelectColumnId=n,r.selectColumnIds=t.shiftKey&&t.moveKey!==cg.Tab?Qv(r.selectColumnIds,n):[n]}}}function Cy(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=M(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(vy(r.focusType)){if(_y(e)){if(ay(e)){let t=i.columnIds[i.columnIds.length-1];r.focusType=uy(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}else r.focusType=by(e)}else r.focusType=by(e)}else if(sy(e)){if(ly(e))r.focusType=W(e.settings.show,P.tableComment)?U.tableComment:U.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let n=i.columnIds.indexOf(r.columnId),a=i.columnIds[n-1];r.focusType=uy(e),r.columnId=a,r.prevSelectColumnId=a,r.selectColumnIds=t.shiftKey&&t.moveKey!==cg.Tab?Qv(r.selectColumnIds,a):[a]}}else r.focusType=py(e),!t.shiftKey&&r.columnId&&(r.prevSelectColumnId=r.columnId,r.selectColumnIds=[r.columnId])}}function wy(e,t){let{collections:n,editor:{focusTable:r}}=e;if(!r)return;let i=M(n).collection(`tableEntities`).selectById(r.tableId);if(i){if(vy(r.focusType)){if(gy(e)){if(ay(e)){let t=i.columnIds[0];r.focusType=dy(e),r.columnId=t,r.prevSelectColumnId=t,r.selectColumnIds=[t]}else r.focusType=yy(e)}else r.focusType=yy(e)}else if(oy(e)){if(cy(e))r.focusType=U.tableName,r.columnId=null,r.prevSelectColumnId=null,r.selectColumnIds=[];else if(r.columnId){let n=i.columnIds.indexOf(r.columnId),a=i.columnIds[n+1];r.focusType=dy(e),r.columnId=a,r.prevSelectColumnId=a,r.selectColumnIds=t.shiftKey&&t.moveKey!==cg.Tab?Qv(r.selectColumnIds,a):[a]}}else r.focusType=fy(e),!t.shiftKey&&r.columnId&&(r.prevSelectColumnId=r.columnId,r.selectColumnIds=[r.columnId])}}const Ty=3e4,Ey=9e4,Dy=3e3,Oy=O(N.changeHasHistory),ky=({editor:e},{payload:{hasRedo:t,hasUndo:n}})=>{e.hasRedo=t,e.hasUndo=n},Ay=O(N.selectAll),jy=({editor:e,doc:t})=>{let n=t.tableIds.reduce((e,t)=>(e[t]=ig.table,e),{});e.selectedMap={...t.memoIds.reduce((e,t)=>(e[t]=ig.memo,e),{}),...n}},My=O(N.unselectAll),Ny=({editor:e})=>{Object.keys(e.selectedMap).forEach(t=>{Reflect.deleteProperty(e.selectedMap,t)})},Py=O(N.select),Fy=({editor:e},{payload:t})=>{Object.assign(e.selectedMap,t)},Iy=O(N.changeViewport),Ly=(e,{payload:{width:t,height:n}})=>{e.editor.viewport.width=t,e.editor.viewport.height=n,e.editor.scrollPullPending&&By(e)},Ry=O(N.clear),zy=e=>{let{doc:t,collections:n}=Jp({});e.doc=t,e.collections=n,e.editor.scrollPullPending=!1,_g(e.editor)};function By(e){let{settings:t,editor:n}=e;if(!pv(n.viewport)){n.scrollPullPending=!0;return}let r=mv(e);t.originX=Ke(r.x,4),t.originY=Ke(r.y,4),n.scrollPullPending=!1}const Vy=O(N.loadJson),Hy=(e,{payload:{value:t}})=>{let{version:n,settings:r,doc:i,collections:a}=qm(t);tg(r.canvasType)||(r.canvasType=Ym.ERD),Object.assign(e.settings,r),e.version=n,e.doc=i,e.collections=a,_g(e.editor),By(e)},Uy=O(N.initialClear),Wy=e=>{let{doc:t,collections:n}=Jp({});e.doc=t,e.collections=n,e.editor.scrollPullPending=!1,_g(e.editor)},Gy=O(N.initialLoadJson),Ky=(e,{payload:{value:t}})=>{let{version:n,settings:r,doc:i,collections:a}=qm(t);tg(r.canvasType)||(r.canvasType=Ym.ERD),Object.assign(e.settings,r),e.version=n,e.doc=i,e.collections=a,_g(e.editor),By(e)},qy=O(N.focusTable),Jy=({editor:e,collections:t},{payload:n})=>{let r=M(t).collection(`tableEntities`);if(e.focusTable?.tableId===n.tableId&&n.focusType)e.focusTable.focusType=n.focusType,e.focusTable.columnId=null,e.focusTable.prevSelectColumnId=null,e.focusTable.selectColumnIds=[];else if(n.focusType){let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:n.focusType,columnId:null,prevSelectColumnId:null,selectColumnIds:[],edit:!1}}else if(e.focusTable?.tableId!==n.tableId){let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:U.tableName,columnId:null,prevSelectColumnId:null,selectColumnIds:[],edit:!1}}},Yy=O(N.focusColumn),Xy=({editor:e,collections:t},{payload:n})=>{let r=M(t).collection(`tableEntities`);if(e.focusTable?.tableId===n.tableId){let t=r.selectById(n.tableId);if(!t)return;let i=e.focusTable;i.columnId=n.columnId,i.focusType=n.focusType,i.selectColumnIds=n.$mod&&n.shiftKey?ey(t.columnIds,i.selectColumnIds,i.prevSelectColumnId,i.columnId):n.shiftKey?$v(t.columnIds,i.prevSelectColumnId,i.columnId):n.$mod?Qv(i.selectColumnIds,n.columnId):[n.columnId],i.prevSelectColumnId=n.columnId}else{let t=r.selectById(n.tableId);if(!t)return;e.focusTable={tableId:t.id,focusType:n.focusType,columnId:n.columnId,prevSelectColumnId:n.columnId,selectColumnIds:[n.columnId],edit:!1}}},Zy=O(N.focusTableEnd),Qy=({editor:e})=>{e.focusTable=null},$y=O(N.focusMoveTable),eb=(e,{payload:t})=>{let{editor:{focusTable:n}}=e;if(n)switch(n.edit=!1,t.moveKey){case cg.ArrowUp:xy(e,t);break;case cg.ArrowDown:Sy(e,t);break;case cg.ArrowLeft:Cy(e,t);break;case cg.ArrowRight:wy(e,t);break;case cg.Tab:t.shiftKey?Cy(e,t):wy(e,t)}},tb=O(N.editTable),nb=({editor:{focusTable:e}})=>{e&&(e.edit=!0)},rb=O(N.editTableEnd),ib=({editor:{focusTable:e}})=>{e&&(e.edit=!1)},ab=O(N.editMemo),ob=({editor:e},{payload:{id:t}})=>{e.editMemoId=t},sb=O(N.editMemoEnd),cb=({editor:e})=>{e.editMemoId=null},lb=O(N.scrollMemo),ub=({editor:e},{payload:{id:t,scrollTop:n}})=>{e.memoScrollTopMap[t]=Number.isFinite(n)?Math.max(0,n):0},db=O(N.selectAllColumn),fb=({collections:e,editor:{focusTable:t}})=>{if(!t)return;let n=M(e).collection(`tableEntities`).selectById(t.tableId);n&&(t.selectColumnIds=[...n.columnIds])},pb=O(N.drawStartRelationship),mb=({editor:e},{payload:{relationshipType:t}})=>{e.drawRelationship={relationshipType:t,start:null,end:{x:0,y:0}}},hb=O(N.drawStartAddRelationship),gb=({editor:{drawRelationship:e},collections:t},{payload:{tableId:n}})=>{if(!e)return;let r=M(t).collection(`tableEntities`).selectById(n);r&&(e.start={tableId:n,x:r.ui.x,y:r.ui.y})},_b=O(N.drawEndRelationship),vb=({editor:e})=>{e.drawRelationship=null},yb=O(N.drawRelationship),bb=({editor:{drawRelationship:e},settings:t},{payload:{x:n,y:r}})=>{if(!e?.start)return;let i=G_(t,{x:n,y:r});e.end.x=i.x,e.end.y=i.y},xb=O(N.hoverColumnMap),Sb=({editor:e},{payload:{columnIds:t}})=>{Object.keys(e.hoverColumnMap).forEach(t=>{Reflect.deleteProperty(e.hoverColumnMap,t)});for(let n of t)e.hoverColumnMap[n]=!0},Cb=O(N.hoverRelationshipMap),wb=({editor:e},{payload:{relationshipIds:t}})=>{Object.keys(e.hoverRelationshipMap).forEach(t=>{Reflect.deleteProperty(e.hoverRelationshipMap,t)});for(let n of t)e.hoverRelationshipMap[n]=!0},Tb=O(N.changeOpenMap),Eb=({editor:e},{payload:t})=>{Object.assign(e.openMap,t)},Db=O(N.changeHandTool),Ob=({editor:e},{payload:{value:t}})=>{e.handTool=t,t&&(e.drawRelationship=null)},kb=O(N.changeZenMode),Ab=({editor:e},{payload:{value:t}})=>{e.zenMode=t},jb=O(N.dragstartColumn),Mb=({editor:e},{payload:t})=>{e.draggableColumn=t,t.columnIds.forEach(t=>{e.draggingColumnMap[t]=!0})},Nb=O(N.dragendColumn),Pb=({editor:e})=>{e.draggableColumn=null,Object.keys(e.draggingColumnMap).forEach(t=>{Reflect.deleteProperty(e.draggingColumnMap,t)})},Fb=O(N.sharedMouseTracker),Ib=({editor:e},{payload:t,tags:n,meta:r})=>{if(x(n)||!W(n,Hg.shared)||!C(r?.editorId)||e.id===r.editorId)return;let i=e.sharedMouseTrackerMap[r.editorId],a=!C(r.nickname)||Ge(r.nickname.trim())?`user`:r.nickname.trim();i?(i.x=t.x,i.y=t.y,i.nickname=a,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedMouseTrackerMap,r.editorId)},Ty)):e.sharedMouseTrackerMap[r.editorId]={...t,id:r.editorId,nickname:a,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedMouseTrackerMap,r.editorId)},Ty)}},Lb=O(N.sharedFocusTracker),Rb=({editor:e},{payload:{focus:t},tags:n,meta:r})=>{if(x(n)||!W(n,Hg.shared)||!C(r?.editorId)||e.id===r.editorId)return;let i=e.sharedFocusTrackerMap[r.editorId];if(!t){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId));return}i?(i.tableId=t.tableId,i.columnId=t.columnId,i.focusType=t.focusType,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId)},Ey)):e.sharedFocusTrackerMap[r.editorId]={...t,id:r.editorId,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedFocusTrackerMap,r.editorId)},Ey)}},zb=O(N.sharedSelectionTracker),Bb=({editor:e},{payload:{selectedIds:t},tags:n,meta:r})=>{if(x(n)||!W(n,Hg.shared)||!C(r?.editorId)||e.id===r.editorId)return;let i=e.sharedSelectionTrackerMap[r.editorId];if(!t.length){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId));return}i?(i.selectedIds=t,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId)},Ey)):e.sharedSelectionTrackerMap[r.editorId]={id:r.editorId,selectedIds:t,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedSelectionTrackerMap,r.editorId)},Ey)}},Vb=O(N.sharedDragSelectTracker),Hb=({editor:e},{payload:{rect:t},tags:n,meta:r})=>{if(x(n)||!W(n,Hg.shared)||!C(r?.editorId)||e.id===r.editorId)return;let i=e.sharedDragSelectTrackerMap[r.editorId];if(!t){i&&(clearTimeout(i.timeoutId),Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId));return}i?(i.x=t.x,i.y=t.y,i.w=t.w,i.h=t.h,clearTimeout(i.timeoutId),i.timeoutId=setTimeout(()=>{Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId)},Dy)):e.sharedDragSelectTrackerMap[r.editorId]={...t,id:r.editorId,timeoutId:setTimeout(()=>{Reflect.deleteProperty(e.sharedDragSelectTrackerMap,r.editorId)},Dy)}},Ub=O(N.dragSelectRect),Wb=({editor:e},{payload:{rect:t}})=>{e.dragSelect=t},Gb=O(N.validationIds),Kb=({doc:e,collections:t})=>{let n=M(t).collection(`tableEntities`),r=M(t).collection(`tableColumnEntities`),i=M(t).collection(`indexEntities`),a=M(t).collection(`indexColumnEntities`),o=M(t).collection(`relationshipEntities`),s=M(t).collection(`memoEntities`),c=e.tableIds.filter(e=>!n.selectById(e)),l=e.relationshipIds.filter(e=>!o.selectById(e)),u=e.indexIds.filter(e=>!i.selectById(e)),d=e.memoIds.filter(e=>!s.selectById(e));e.tableIds=e.tableIds.filter(e=>!c.includes(e)),e.relationshipIds=e.relationshipIds.filter(e=>!l.includes(e)),e.indexIds=e.indexIds.filter(e=>!u.includes(e)),e.memoIds=e.memoIds.filter(e=>!d.includes(e)),n.selectAll().forEach(e=>{let t=e.columnIds.filter(e=>!r.selectById(e)),n=e.seqColumnIds.filter(e=>!r.selectById(e));e.columnIds=e.columnIds.filter(e=>!t.includes(e)),e.seqColumnIds=e.seqColumnIds.filter(e=>!n.includes(e))}),i.selectAll().forEach(e=>{let t=e.indexColumnIds.filter(e=>!a.selectById(e)),n=e.seqIndexColumnIds.filter(e=>!a.selectById(e));e.indexColumnIds=e.indexColumnIds.filter(e=>!t.includes(e)),e.seqIndexColumnIds=e.seqIndexColumnIds.filter(e=>!n.includes(e))})},qb=O(N.getLWW),Jb=me,Yb=O(N.mergeLWW),Xb=({lww:e},{payload:{lww:t}})=>{Object.entries(t).forEach(([t,[n,r,i,a]])=>{Zp(e,r,t,n,me),Qp(e,i,t,n,me),Object.entries(a).forEach(([r,i])=>{$p(e,i,t,n,r,me)})})},Zb={[N.changeHasHistory]:ky,[N.selectAll]:jy,[N.unselectAll]:Ny,[N.select]:Fy,[N.changeViewport]:Ly,[N.clear]:zy,[N.loadJson]:Hy,[N.initialClear]:Wy,[N.initialLoadJson]:Ky,[N.focusTable]:Jy,[N.focusColumn]:Xy,[N.focusTableEnd]:Qy,[N.focusMoveTable]:eb,[N.editTable]:nb,[N.editTableEnd]:ib,[N.editMemo]:ob,[N.editMemoEnd]:cb,[N.scrollMemo]:ub,[N.selectAllColumn]:fb,[N.drawStartRelationship]:mb,[N.drawStartAddRelationship]:gb,[N.drawEndRelationship]:vb,[N.drawRelationship]:bb,[N.hoverColumnMap]:Sb,[N.hoverRelationshipMap]:wb,[N.changeOpenMap]:Eb,[N.changeHandTool]:Ob,[N.changeZenMode]:Ab,[N.dragstartColumn]:Mb,[N.dragendColumn]:Pb,[N.sharedMouseTracker]:Ib,[N.sharedFocusTracker]:Rb,[N.sharedSelectionTracker]:Bb,[N.sharedDragSelectTracker]:Hb,[N.dragSelectRect]:Wb,[N.validationIds]:Kb,[N.getLWW]:Jb,[N.mergeLWW]:Xb,...Bg},Qb={changeHasHistoryAction:Oy,selectAllAction:Ay,unselectAllAction:My,selectAction:Py,changeViewportAction:Iy,clearAction:Ry,loadJsonAction:Vy,initialClearAction:Uy,initialLoadJsonAction:Gy,focusTableAction:qy,focusColumnAction:Yy,focusTableEndAction:Zy,focusMoveTableAction:$y,editTableAction:tb,editTableEndAction:rb,editMemoAction:ab,editMemoEndAction:sb,scrollMemoAction:lb,selectAllColumnAction:db,drawStartRelationshipAction:pb,drawStartAddRelationshipAction:hb,drawEndRelationshipAction:_b,drawRelationshipAction:yb,hoverColumnMapAction:xb,hoverRelationshipMapAction:Cb,changeOpenMapAction:Tb,changeHandToolAction:Db,changeZenModeAction:kb,dragstartColumnAction:jb,dragendColumnAction:Nb,sharedMouseTrackerAction:Fb,sharedFocusTrackerAction:Lb,sharedSelectionTrackerAction:zb,sharedDragSelectTrackerAction:Vb,dragSelectRectAction:Ub,validationIdsAction:Gb,getLWWAction:qb,mergeLWWAction:Yb,...Vg},$b=(e,t,n)=>{e.push(Ry(),Vy({value:Jm(n)}))},ex=(e,t,n)=>{e.push(Vy({value:Jm(n)}))},tx={[N.loadJson]:$b,[N.clear]:ex},nx={addIndex:`index.add`,removeIndex:`index.remove`,changeIndexName:`index.changeName`,changeIndexUnique:`index.changeUnique`},rx=e=>Je({id:qe(),name:``,tableId:``,indexColumnIds:[],seqIndexColumnIds:[],unique:!1,meta:Yv()},e??{}),ix=O(nx.addIndex),ax=({doc:e,collections:t,lww:n},{payload:{id:r,tableId:i},version:a},{clock:o})=>{let s=a??o.getVersion();M(t).collection(`indexEntities`).addOne(rx({id:r,tableId:i})).addOperator(n,s,r,()=>{B(e.indexIds)(r)||e.indexIds.push(r)})},ox=O(nx.removeIndex),sx=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();M(t).collection(`indexEntities`).removeOperator(n,o,r,()=>{let t=e.indexIds.indexOf(r);t!==-1&&e.indexIds.splice(t,1)})},cx=O(nx.changeIndexName),lx=({collections:e,lww:t},{payload:{id:n,tableId:r,value:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=M(e).collection(`indexEntities`);c.getOrCreate(n,e=>rx({id:e,tableId:r})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=i})})},ux=O(nx.changeIndexUnique),dx=({collections:e,lww:t},{payload:{id:n,tableId:r,value:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=M(e).collection(`indexEntities`);c.getOrCreate(n,e=>rx({id:e,tableId:r})),c.replaceOperator(t,s,n,`unique`,()=>{c.updateOne(n,e=>{e.unique=i})})},fx={[nx.addIndex]:ax,[nx.removeIndex]:sx,[nx.changeIndexName]:lx,[nx.changeIndexUnique]:dx},px={addIndexAction:ix,removeIndexAction:ox,changeIndexNameAction:cx,changeIndexUniqueAction:ux},mx=(e,{payload:{id:t}})=>{e.push(ox({id:t}))},hx=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`indexEntities`).selectById(t);r&&e.push(ix({id:t,tableId:r.tableId}))},gx=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=M(r).collection(`indexEntities`).selectById(t);i&&e.push(cx({id:t,tableId:n,value:i.name}))},_x=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{M(i).collection(`indexEntities`).selectById(t)&&e.push(ux({id:t,tableId:n,value:!r}))},vx={[nx.addIndex]:mx,[nx.removeIndex]:hx,[nx.changeIndexName]:gx,[nx.changeIndexUnique]:_x},yx={addIndexColumn:`indexColumn.add`,removeIndexColumn:`indexColumn.remove`,moveIndexColumn:`indexColumn.move`,changeIndexColumnOrderType:`indexColumn.changeOrderType`},bx=e=>Je({id:qe(),indexId:``,columnId:``,orderType:ah.ASC,meta:Yv()},e??{});function xx(e,t,n){if(B(t)(n)){let r=t.reduce((e,t,n)=>(e[t]=n,e),{});e.push(n),e.sort((e,t)=>{let n=r[e],i=r[t];return n===void 0?1:i===void 0?-1:n-i})}else e.push(n),t.push(n)}const Sx=O(yx.addIndexColumn),Cx=({collections:e,lww:t},{payload:{id:n,indexId:r,tableId:i,columnId:a},version:o},{clock:s})=>{let c=o??s.getVersion(),l=M(e).collection(`indexEntities`),u=l.getOrCreate(r,e=>rx({id:e,tableId:i}));M(e).collection(`indexColumnEntities`).addOne(bx({id:n,indexId:r,columnId:a})).addOperator(t,c,n,()=>{B(u.indexColumnIds)(n)||l.updateOne(r,e=>{xx(e.indexColumnIds,e.seqIndexColumnIds,n)})})},wx=O(yx.removeIndexColumn),Tx=({collections:e,lww:t},{payload:{id:n,indexId:r,tableId:i},version:a},{clock:o})=>{let s=a??o.getVersion(),c=M(e).collection(`indexEntities`),l=c.getOrCreate(r,e=>rx({id:e,tableId:i}));M(e).collection(`indexColumnEntities`).removeOperator(t,s,n,()=>{let e=l.indexColumnIds.indexOf(n);e!==-1&&c.updateOne(r,t=>{t.indexColumnIds.splice(e,1)})})},Ex=O(yx.moveIndexColumn),Dx=({collections:e},{payload:{id:t,indexId:n,tableId:r,targetId:i}})=>{if(t===i)return;let a=M(e).collection(`indexEntities`),o=a.getOrCreate(n,e=>rx({id:e,tableId:r})),s=o.indexColumnIds.indexOf(t);if(s===-1)return;let c=o.indexColumnIds.indexOf(i);c!==-1&&a.updateOne(n,e=>{e.indexColumnIds.splice(s,1),e.indexColumnIds.splice(c,0,t);let n=e.seqIndexColumnIds.indexOf(t),r=e.seqIndexColumnIds.indexOf(i);n!==-1&&r!==-1&&(e.seqIndexColumnIds.splice(n,1),e.seqIndexColumnIds.splice(r,0,t))})},Ox=O(yx.changeIndexColumnOrderType),kx=({collections:e,lww:t},{payload:{id:n,indexId:r,columnId:i,value:a},version:o},{clock:s})=>{let c=o??s.getVersion(),l=M(e).collection(`indexColumnEntities`);l.getOrCreate(n,e=>bx({id:e,indexId:r,columnId:i})),l.replaceOperator(t,c,n,`orderType`,()=>{l.updateOne(n,e=>{e.orderType=a})})},Ax={[yx.addIndexColumn]:Cx,[yx.removeIndexColumn]:Tx,[yx.moveIndexColumn]:Dx,[yx.changeIndexColumnOrderType]:kx},jx={addIndexColumnAction:Sx,removeIndexColumnAction:wx,moveIndexColumnAction:Ex,changeIndexColumnOrderTypeAction:Ox},Mx=(e,{payload:{id:t,indexId:n,tableId:r}})=>{e.push(wx({id:t,indexId:n,tableId:r}))},Nx=(e,{payload:{id:t,indexId:n,tableId:r}},{collections:i})=>{let a=M(i).collection(`indexColumnEntities`).selectById(t);a&&e.push(Sx({id:t,indexId:n,tableId:r,columnId:a.columnId}))},Px=(e,{payload:{id:t,indexId:n,tableId:r,targetId:i}},{collections:a})=>{let o=M(a).collection(`indexEntities`).selectById(n);if(!o)return;let s=o.indexColumnIds.indexOf(t);if(s===-1)return;let c=o.indexColumnIds.indexOf(i);if(c===-1)return;let l=s<c?s+1:s-1,u=o.indexColumnIds[l];e.push(Ex({indexId:n,tableId:r,id:t,targetId:u}))},Fx=(e,{payload:{id:t,indexId:n,columnId:r}},{collections:i})=>{let a=M(i).collection(`indexColumnEntities`).selectById(t);a&&e.push(Ox({id:t,indexId:n,columnId:r,value:a.orderType}))},Ix={[yx.addIndexColumn]:Mx,[yx.removeIndexColumn]:Nx,[yx.moveIndexColumn]:Px,[yx.changeIndexColumnOrderType]:Fx},Lx={addMemo:`memo.add`,moveMemo:`memo.move`,moveToMemo:`memo.moveTo`,removeMemo:`memo.remove`,changeMemoValue:`memo.changeValue`,changeMemoColor:`memo.changeColor`,resizeMemo:`memo.resize`,changeZIndex:`memo.changeZIndex`},Rx=e=>Je({id:qe(),value:``,ui:{x:200,y:100,zIndex:2,width:116,height:100,color:``},meta:Yv()},e??{}),zx=O(Lx.addMemo),Bx=({doc:e,collections:t,lww:n},{payload:{id:r,ui:i},version:a},{clock:o})=>{let s=a??o.getVersion();M(t).collection(`memoEntities`).addOne(Rx({id:r,ui:i})).addOperator(n,s,r,()=>{B(e.memoIds)(r)||e.memoIds.push(r)})},Vx=O(Lx.moveMemo),Hx=({collections:e},{payload:{ids:t,movementX:n,movementY:r}})=>{let i=M(e).collection(`memoEntities`);for(let e of t)i.getOrCreate(e,e=>Rx({id:e}));i.updateMany(t,e=>{e.ui.x=Ke(e.ui.x+n,4),e.ui.y=Ke(e.ui.y+r,4)})},Ux=O(Lx.moveToMemo),Wx=({collections:e},{payload:{id:t,x:n,y:r}})=>{let i=M(e).collection(`memoEntities`);i.getOrCreate(t,e=>Rx({id:e})),i.updateOne(t,e=>{e.ui.x=n,e.ui.y=r})},Gx=O(Lx.removeMemo),Kx=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();M(t).collection(`memoEntities`).removeOperator(n,o,r,()=>{let t=e.memoIds.indexOf(r);t!==-1&&e.memoIds.splice(t,1)})},qx=O(Lx.changeMemoValue),Jx=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`memoEntities`);s.getOrCreate(n,e=>Rx({id:e})),s.replaceOperator(t,o,n,`value`,()=>{s.updateOne(n,e=>{e.value=r})})},Yx=O(Lx.changeMemoColor),Xx=({collections:e,lww:t},{payload:{id:n,color:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`memoEntities`);s.getOrCreate(n,e=>Rx({id:e})),s.replaceOperator(t,o,n,`ui.color`,()=>{s.updateOne(n,e=>{e.ui.color=r})})},Zx=O(Lx.resizeMemo),Qx=({collections:e},{payload:{id:t,x:n,y:r,width:i,height:a}})=>{let o=M(e).collection(`memoEntities`);o.getOrCreate(t,e=>Rx({id:e})),o.updateOne(t,e=>{e.ui.x=n,e.ui.y=r,e.ui.width=i,e.ui.height=a})},$x=O(Lx.changeZIndex),eS=({collections:e},{payload:{id:t,zIndex:n}})=>{let r=M(e).collection(`memoEntities`);r.getOrCreate(t,e=>Rx({id:e})),r.updateOne(t,e=>{e.ui.zIndex=n})},tS={[Lx.addMemo]:Bx,[Lx.moveMemo]:Hx,[Lx.moveToMemo]:Wx,[Lx.removeMemo]:Kx,[Lx.changeMemoValue]:Jx,[Lx.changeMemoColor]:Xx,[Lx.resizeMemo]:Qx,[Lx.changeZIndex]:eS},nS={addMemoAction:zx,moveMemoAction:Vx,moveToMemoAction:Ux,removeMemoAction:Gx,changeMemoValueAction:qx,changeMemoColorAction:Yx,resizeMemoAction:Zx,changeZIndexAction:$x},rS=(e,{payload:{id:t}})=>{e.push(Gx({id:t}))},iS=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`memoEntities`).selectById(t);r&&e.push(zx({id:r.id,ui:ge(r.ui,[`x`,`y`,`zIndex`])}))},aS=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`memoEntities`).selectById(t);r&&e.push(qx({id:t,value:r.value}))},oS=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`memoEntities`).selectById(t);r&&e.push(Ux({id:t,x:r.ui.x,y:r.ui.y}))},sS={[Lx.addMemo]:rS,[Lx.removeMemo]:iS,[Lx.changeMemoValue]:aS,[Lx.moveToMemo]:oS},cS=(e,t,n)=>{let r=n.filter(e=>e.type===Vx.type);if(!r.length)return;let i=b(r,e=>e.payload.ids.join(`,`));for(let[,n]of Object.entries(i)){let{payload:{ids:r}}=oe(n),{x:i,y:a}=n.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(Vx({ids:r,movementX:-1*i,movementY:-1*a})),t.push(Vx({ids:r,movementX:i,movementY:a})))}},lS=(e,t,n)=>{let r=n.filter(({type:e})=>e===Yx.type);if(!r.length)return;let i=b(r,e=>e.payload.id);for(let[n,r]of Object.entries(i)){let i=oe(r),a=fe(r);e.push(Yx({id:n,color:i.payload.prevColor,prevColor:a.payload.color})),t.push(Yx({id:n,color:a.payload.color,prevColor:i.payload.prevColor}))}},uS=(e,t,n)=>{let r=n.filter(e=>e.type===Zx.type);if(!r.length)return;let i=b(r,e=>e.payload.id);for(let[,n]of Object.entries(i)){if(n.length<2)continue;let r=oe(n),i=fe(n);e.push(r),t.push(i)}},dS={[Lx.moveMemo]:cS,[Lx.changeMemoColor]:lS,[Lx.resizeMemo]:uS},fS={addRelationship:`relationship.add`,removeRelationship:`relationship.remove`,changeRelationshipType:`relationship.changeType`},pS=e=>Je({id:qe(),identification:!1,relationshipType:rh.ZeroN,startRelationshipType:ih.dash,start:{tableId:``,columnIds:[],x:0,y:0,direction:L.bottom},end:{tableId:``,columnIds:[],x:0,y:0,direction:L.bottom},meta:Yv()},e??{}),mS=O(fS.addRelationship),hS=({doc:e,collections:t,lww:n},{payload:{id:r,relationshipType:i,start:a,end:o},version:s},{clock:c})=>{let l=s??c.getVersion();M(t).collection(`relationshipEntities`).addOne(pS({id:r,relationshipType:i,start:{tableId:a.tableId,columnIds:a.columnIds},end:{tableId:o.tableId,columnIds:o.columnIds}})).addOperator(n,l,r,()=>{B(e.relationshipIds)(r)||e.relationshipIds.push(r)})},gS=O(fS.removeRelationship),_S=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();M(t).collection(`relationshipEntities`).removeOperator(n,o,r,()=>{let t=e.relationshipIds.indexOf(r);t!==-1&&e.relationshipIds.splice(t,1)})},vS=O(fS.changeRelationshipType),yS=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`relationshipEntities`);s.replaceOperator(t,o,n,`relationshipType`,()=>{s.updateOne(n,e=>{e.relationshipType=r})})},bS={[fS.addRelationship]:hS,[fS.removeRelationship]:_S,[fS.changeRelationshipType]:yS},xS={addRelationshipAction:mS,removeRelationshipAction:gS,changeRelationshipTypeAction:vS},SS=(e,{payload:{id:t}})=>{e.push(gS({id:t}))},CS=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`relationshipEntities`).selectById(t);r&&e.push(mS({id:r.id,relationshipType:r.relationshipType,start:ge(r.start,[`tableId`,`columnIds`]),end:ge(r.end,[`tableId`,`columnIds`])}))},wS=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`relationshipEntities`).selectById(t);r&&e.push(vS({id:t,value:r.relationshipType}))},TS={[fS.addRelationship]:SS,[fS.removeRelationship]:CS,[fS.changeRelationshipType]:wS},ES=(e,t,{settings:n})=>{e.push(hv({originX:n.originX,originY:n.originY}))},DS=(e,{payload:{show:t,value:n}})=>{e.push(yv({show:t,value:!n}))},OS=(e,t,{settings:n})=>{e.push(lv({value:n.zoomLevel}))},kS={[G.scrollTo]:ES,[G.changeShow]:DS,[G.changeZoomLevel]:OS},AS=(e,t,n)=>{let r=n.filter(e=>e.type===_v.type);if(!r.length)return;let{x:i,y:a}=r.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(_v({movementX:-1*i,movementY:-1*a})),t.push(_v({movementX:i,movementY:a})))},jS=(e,t,n)=>{let r=n.filter(e=>e.type===dv.type);if(!r.length)return;let i=r.reduce((e,{payload:{value:t}})=>e+t,0);e.push(dv({value:-1*i})),t.push(dv({value:i}))},MS={[G.streamScrollTo]:AS,[G.streamZoomLevel]:jS},K={addTable:`table.add`,moveTable:`table.move`,moveToTable:`table.moveTo`,removeTable:`table.remove`,changeTableName:`table.changeName`,changeTableComment:`table.changeComment`,changeTableColor:`table.changeColor`,changeZIndex:`table.changeZIndex`,sortTable:`table.sort`},NS=e=>Je({id:qe(),name:``,comment:``,columnIds:[],seqColumnIds:[],ui:{x:200,y:100,zIndex:2,widthName:60,widthComment:60,color:``},meta:Yv()},e??{}),PS=O(K.addTable),FS=({doc:e,collections:t,lww:n},{payload:{id:r,ui:i},version:a},{clock:o})=>{let s=a??o.getVersion();M(t).collection(`tableEntities`).addOne(NS({id:r,ui:i})).addOperator(n,s,r,()=>{B(e.tableIds)(r)||e.tableIds.push(r)})},IS=O(K.moveTable),LS=({collections:e},{payload:{ids:t,movementX:n,movementY:r}})=>{let i=M(e).collection(`tableEntities`);for(let e of t)i.getOrCreate(e,e=>NS({id:e}));i.updateMany(t,e=>{e.ui.x=Ke(e.ui.x+n,4),e.ui.y=Ke(e.ui.y+r,4)})},RS=O(K.moveToTable),zS=({collections:e},{payload:{id:t,x:n,y:r}})=>{let i=M(e).collection(`tableEntities`);i.getOrCreate(t,e=>NS({id:e})),i.updateOne(t,e=>{e.ui.x=n,e.ui.y=r})},BS=O(K.removeTable),VS=({doc:e,collections:t,lww:n},{payload:{id:r},version:i},{clock:a})=>{let o=i??a.getVersion();M(t).collection(`tableEntities`).removeOperator(n,o,r,()=>{let t=e.tableIds.indexOf(r);t!==-1&&e.tableIds.splice(t,1)})},HS=O(K.changeTableName),US=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableEntities`);c.getOrCreate(n,e=>NS({id:e})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=r,e.ui.widthName=H(a(r))})})},WS=O(K.changeTableComment),GS=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableEntities`);c.getOrCreate(n,e=>NS({id:e})),c.replaceOperator(t,s,n,`comment`,()=>{c.updateOne(n,e=>{e.comment=r,e.ui.widthComment=H(a(r))})})},KS=O(K.changeTableColor),qS=({collections:e,lww:t},{payload:{id:n,color:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableEntities`);s.getOrCreate(n,e=>NS({id:e})),s.replaceOperator(t,o,n,`ui.color`,()=>{s.updateOne(n,e=>{e.ui.color=r})})},JS=O(K.changeZIndex),YS=({collections:e},{payload:{id:t,zIndex:n}})=>{let r=M(e).collection(`tableEntities`);r.getOrCreate(t,e=>NS({id:e})),r.updateOne(t,e=>{e.ui.zIndex=n})},XS=O(K.sortTable),ZS=e=>{let{doc:t,settings:n,collections:r}=e,i=n.width,a=M(r).collection(`tableEntities`).selectByIds(t.tableIds);a.sort((e,t)=>e.columnIds.length-t.columnIds.length);let o=50,s=50,c=50;a.forEach(t=>{let n=f_(t,e).width+80,r=S_(t)+80;o+n>i&&(s+=c,c=0,o=50),c<r&&(c=r),t.ui.y=s,t.ui.x=o,o+=n})},QS={[K.addTable]:FS,[K.moveTable]:LS,[K.moveToTable]:zS,[K.removeTable]:VS,[K.changeTableName]:US,[K.changeTableComment]:GS,[K.changeTableColor]:qS,[K.changeZIndex]:YS,[K.sortTable]:ZS},$S={addTableAction:PS,moveTableAction:IS,moveToTableAction:RS,removeTableAction:BS,changeTableNameAction:HS,changeTableCommentAction:WS,changeTableColorAction:KS,changeZIndexAction:JS,sortTableAction:XS},eC=(e,{payload:{id:t}})=>{e.push(BS({id:t}))},tC=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`tableEntities`).selectById(t);r&&e.push(PS({id:r.id,ui:ge(r.ui,[`x`,`y`,`zIndex`])}))},nC=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`tableEntities`).selectById(t);r&&e.push(HS({id:t,value:r.name}))},rC=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`tableEntities`).selectById(t);r&&e.push(WS({id:t,value:r.comment}))},iC=(e,{payload:{id:t}},{collections:n})=>{let r=M(n).collection(`tableEntities`).selectById(t);r&&e.push(RS({id:t,x:r.ui.x,y:r.ui.y}))},aC=()=>{},oC={[K.addTable]:eC,[K.removeTable]:tC,[K.changeTableName]:nC,[K.changeTableComment]:rC,[K.moveToTable]:iC,[K.sortTable]:aC},sC=(e,t,n)=>{let r=n.filter(e=>e.type===IS.type);if(!r.length)return;let i=b(r,e=>e.payload.ids.join(`,`));for(let[,n]of Object.entries(i)){let{payload:{ids:r}}=oe(n),{x:i,y:a}=n.reduce((e,{payload:{movementX:t,movementY:n}})=>(e.x+=t,e.y+=n,e),{x:0,y:0});Math.abs(i)+Math.abs(a)<20||(e.push(IS({ids:r,movementX:-1*i,movementY:-1*a})),t.push(IS({ids:r,movementX:i,movementY:a})))}},cC=(e,t,n)=>{let r=n.filter(({type:e})=>e===KS.type);if(!r.length)return;let i=b(r,e=>e.payload.id);for(let[n,r]of Object.entries(i)){let i=oe(r),a=fe(r);e.push(KS({id:n,color:i.payload.prevColor,prevColor:a.payload.color})),t.push(KS({id:n,color:a.payload.color,prevColor:i.payload.prevColor}))}},lC={[K.moveTable]:sC,[K.changeTableColor]:cC},q={addColumn:`column.add`,removeColumn:`column.remove`,changeColumnName:`column.changeName`,changeColumnComment:`column.changeComment`,changeColumnDataType:`column.changeDataType`,changeColumnDefault:`column.changeDefault`,changeColumnAutoIncrement:`column.changeAutoIncrement`,changeColumnPrimaryKey:`column.changePrimaryKey`,changeColumnUnique:`column.changeUnique`,changeColumnNotNull:`column.changeNotNull`,moveColumn:`column.move`},uC=e=>Je({id:qe(),tableId:``,name:``,comment:``,dataType:``,default:``,options:0,ui:{keys:0,widthName:60,widthComment:60,widthDataType:60,widthDefault:60},meta:Yv()},e??{}),dC=O(q.addColumn),fC=({collections:e,lww:t},{payload:{id:n,tableId:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableEntities`),c=s.getOrCreate(r,e=>NS({id:e}));M(e).collection(`tableColumnEntities`).addOne(uC({id:n,tableId:r})).addOperator(t,o,n,()=>{B(c.columnIds)(n)||s.updateOne(r,e=>{xx(e.columnIds,e.seqColumnIds,n)})})},pC=O(q.removeColumn),mC=({collections:e,lww:t},{payload:{id:n,tableId:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableEntities`),c=s.getOrCreate(r,e=>NS({id:e}));M(e).collection(`tableColumnEntities`).removeOperator(t,o,n,()=>{let e=c.columnIds.indexOf(n);e!==-1&&s.updateOne(r,t=>{t.columnIds.splice(e,1)})})},hC=O(q.changeColumnName),gC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>uC({id:e})),c.replaceOperator(t,s,n,`name`,()=>{c.updateOne(n,e=>{e.name=r,e.ui.widthName=H(a(r))})})},_C=O(q.changeColumnComment),vC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>uC({id:e})),c.replaceOperator(t,s,n,`comment`,()=>{c.updateOne(n,e=>{e.comment=r,e.ui.widthComment=H(a(r))})})},yC=O(q.changeColumnDataType),bC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>uC({id:e})),c.replaceOperator(t,s,n,`dataType`,()=>{c.updateOne(n,e=>{e.dataType=r,e.ui.widthDataType=H(a(r))})})},xC=O(q.changeColumnDefault),SC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{toWidth:a,clock:o})=>{let s=i??o.getVersion(),c=M(e).collection(`tableColumnEntities`);c.getOrCreate(n,e=>uC({id:e})),c.replaceOperator(t,s,n,`default`,()=>{c.updateOne(n,e=>{e.default=r,e.ui.widthDefault=H(a(r))})})},CC=O(q.changeColumnAutoIncrement),wC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>uC({id:e})),s.replaceOperator(t,o,n,`options(autoIncrement)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|R.autoIncrement:e.options&~R.autoIncrement})})},TC=O(q.changeColumnPrimaryKey),EC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>uC({id:e})),s.replaceOperator(t,o,n,`options(primaryKey)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|R.primaryKey:e.options&~R.primaryKey,e.ui.keys=r?e.ui.keys|z.primaryKey:e.ui.keys&~z.primaryKey})})},DC=O(q.changeColumnUnique),OC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>uC({id:e})),s.replaceOperator(t,o,n,`options(unique)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|R.unique:e.options&~R.unique})})},kC=O(q.changeColumnNotNull),AC=({collections:e,lww:t},{payload:{id:n,value:r},version:i},{clock:a})=>{let o=i??a.getVersion(),s=M(e).collection(`tableColumnEntities`);s.getOrCreate(n,e=>uC({id:e})),s.replaceOperator(t,o,n,`options(notNull)`,()=>{s.updateOne(n,e=>{e.options=r?e.options|R.notNull:e.options&~R.notNull})})},jC=O(q.moveColumn),MC=({collections:e},{payload:{id:t,tableId:n,targetId:r}})=>{if(t===r)return;let i=M(e).collection(`tableEntities`),a=i.getOrCreate(n,e=>NS({id:e})),o=a.columnIds.indexOf(t);if(o===-1)return;let s=a.columnIds.indexOf(r);s!==-1&&i.updateOne(n,e=>{e.columnIds.splice(o,1),e.columnIds.splice(s,0,t);let n=e.seqColumnIds.indexOf(t),i=e.seqColumnIds.indexOf(r);n!==-1&&i!==-1&&(e.seqColumnIds.splice(n,1),e.seqColumnIds.splice(i,0,t))})},NC={[q.addColumn]:fC,[q.removeColumn]:mC,[q.changeColumnName]:gC,[q.changeColumnComment]:vC,[q.changeColumnDataType]:bC,[q.changeColumnDefault]:SC,[q.changeColumnAutoIncrement]:wC,[q.changeColumnPrimaryKey]:EC,[q.changeColumnUnique]:OC,[q.changeColumnNotNull]:AC,[q.moveColumn]:MC},PC={addColumnAction:dC,removeColumnAction:pC,changeColumnNameAction:hC,changeColumnCommentAction:_C,changeColumnDataTypeAction:yC,changeColumnDefaultAction:xC,changeColumnAutoIncrementAction:CC,changeColumnPrimaryKeyAction:TC,changeColumnUniqueAction:DC,changeColumnNotNullAction:kC,moveColumnAction:jC},FC=(e,{payload:{id:t,tableId:n}})=>{e.push(pC({id:t,tableId:n}))},IC=(e,{payload:{id:t,tableId:n}})=>{e.push(dC({id:t,tableId:n}))},LC=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=M(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(hC({id:t,tableId:n,value:i.name}))},RC=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=M(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(yC({id:t,tableId:n,value:i.dataType}))},zC=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=M(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(xC({id:t,tableId:n,value:i.default}))},BC=(e,{payload:{id:t,tableId:n}},{collections:r})=>{let i=M(r).collection(`tableColumnEntities`).selectById(t);i&&e.push(_C({id:t,tableId:n,value:i.comment}))},VC=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{M(i).collection(`tableColumnEntities`).selectById(t)&&e.push(CC({id:t,tableId:n,value:!r}))},HC=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{M(i).collection(`tableColumnEntities`).selectById(t)&&e.push(kC({id:t,tableId:n,value:!r}))},UC=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{M(i).collection(`tableColumnEntities`).selectById(t)&&e.push(TC({id:t,tableId:n,value:!r}))},WC=(e,{payload:{id:t,tableId:n,value:r}},{collections:i})=>{M(i).collection(`tableColumnEntities`).selectById(t)&&e.push(DC({id:t,tableId:n,value:!r}))},GC=(e,{payload:{id:t,tableId:n,targetId:r}},{collections:i})=>{let a=M(i).collection(`tableEntities`).selectById(n);if(!a)return;let o=a.columnIds.indexOf(t);if(o===-1)return;let s=a.columnIds.indexOf(r);if(s===-1)return;let c=o<s?o+1:o-1,l=a.columnIds[c];e.push(jC({id:t,tableId:n,targetId:l}))},KC={[q.addColumn]:FC,[q.removeColumn]:IC,[q.changeColumnName]:LC,[q.changeColumnDataType]:RC,[q.changeColumnDefault]:zC,[q.changeColumnComment]:BC,[q.changeColumnAutoIncrement]:VC,[q.changeColumnNotNull]:HC,[q.changeColumnPrimaryKey]:UC,[q.changeColumnUnique]:WC,[q.moveColumn]:GC};function qC(e,...t){try{return e?.(...t)}catch(e){console.error(e)}}const JC={...oC,...KC,...TS,...sS,...kS,...tx,...vx,...Ix},YC={...lC,...dS,...MS};function XC(e,t,n){let r=[],i=[];for(let t of n){let n=JC[t.type];n&&(n(r,t,e.state),i.push(ie(t)))}for(let e of Object.keys(YC))YC[e](r,i,n);!r.length||!i.length||t.push({undo:(e,t)=>{e(r.map(ZC(t())))},redo:(e,t)=>{e(i.map(ZC(t())))}})}function ZC(e){return t=>({...ie(t),version:e})}const QC=(e,t)=>n=>{qC(XC,e,t,n)},$C=()=>function*({settings:e,doc:{tableIds:t,memoIds:n},collections:r}){let i=M(r).collection(`tableEntities`).selectByIds(t),a=M(r).collection(`memoEntities`).selectByIds(n),o=Jv(e,i,a),s=qe();yield ej(),yield Py({[s]:ig.memo}),yield zx({id:s,ui:{...o,zIndex:Kv(i,a)}})},ew=e=>function*({editor:{selectedMap:t}}){if(e){yield Gx({id:e});return}let n=Object.entries(t).filter(([,e])=>e===ig.memo);for(let[e]of n)yield Gx({id:e})},tw=(e,t)=>function*({doc:{tableIds:n,memoIds:r},collections:i}){let a=M(i).collection(`tableEntities`).selectByIds(n),o=M(i).collection(`memoEntities`).selectByIds(r);t||(yield ej()),yield Py({[e]:ig.memo}),yield $x({id:e,zIndex:Kv(a,o)})},nw={addMemoAction$:$C,removeMemoAction$:ew,selectMemoAction$:tw};B(Object.values({tables:`tables`,columns:`columns`}));const rw=({x:e,y:t})=>`${e},${t}`,iw=(e,t)=>e<t?-1:+(e>t),aw=e=>e.ui.zIndex??0;function ow({entities:e,offset:t,escapeCollision:n,settings:r,tables:i,memos:a,findSource:o}){let s=new Map;if(e.length===0)return s;let c=new Set([...i,...a].map(({ui:e})=>rw(e))),l=new Map,u=[];for(let n of e){let e=o(n.sourceId);e?l.set(n.sourceId,{x:e.ui.x+t.x,y:e.ui.y+t.y}):u.push(n)}if(u.length!==0){let e=Jv(r,i,a),t=u.reduce((e,t)=>t.ui.x<e.ui.x||t.ui.x===e.ui.x&&t.ui.y<e.ui.y?t:e);for(let n of u)l.set(n.sourceId,{x:e.x+(n.ui.x-t.ui.x),y:e.y+(n.ui.y-t.ui.y)})}if(n){let t=[...e].sort((e,t)=>iw(e.sourceId,t.sourceId));for(let{sourceId:e}of t){let t=l.get(e);if(t){for(;c.has(rw(t));)t.x+=50,t.y+=50;c.add(rw(t))}}}let d=Kv(i,a);return[...e].sort((e,t)=>aw(e)-aw(t)||iw(e.sourceId,t.sourceId)).forEach(({sourceId:e},t)=>{let n=l.get(e);n&&s.set(e,{x:n.x,y:n.y,zIndex:d+t})}),s}B(Object.values({columnName:`columnName`,columnDataType:`columnDataType`,columnNotNull:`columnNotNull`,columnUnique:`columnUnique`,columnAutoIncrement:`columnAutoIncrement`,columnDefault:`columnDefault`,columnComment:`columnComment`}));function sw(e,t){return t.filter(t=>{switch(t){case F.columnName:return!0;case F.columnDataType:return W(e,P.columnDataType);case F.columnDefault:return W(e,P.columnDefault);case F.columnComment:return W(e,P.columnComment);case F.columnAutoIncrement:return W(e,P.columnAutoIncrement);case F.columnUnique:return W(e,P.columnUnique);case F.columnNotNull:return W(e,P.columnNotNull);default:return!1}})}const cw=()=>function*({settings:e,doc:{tableIds:t,memoIds:n},collections:r}){let i=M(r).collection(`tableEntities`).selectByIds(t),a=M(r).collection(`memoEntities`).selectByIds(n),o=Jv(e,i,a),s=qe();yield My(),yield Py({[s]:ig.table}),yield PS({id:s,ui:{...o,zIndex:Kv(i,a)}}),yield qy({tableId:s})},lw=e=>function*({doc:{relationshipIds:t,indexIds:n},editor:{selectedMap:r},collections:i}){let a=M(i).collection(`relationshipEntities`).selectByIds(t),o=M(i).collection(`indexEntities`).selectByIds(n);if(e){let t=a.filter(({start:t,end:n})=>t.tableId===e||n.tableId===e),n=o.filter(({tableId:t})=>t===e);for(let{id:e}of n)yield ox({id:e});for(let{id:e}of t)yield gS({id:e});yield BS({id:e});return}let s=Object.entries(r).filter(([,e])=>e===ig.table).map(([e])=>e),c=B(s),l=a.filter(({start:e,end:t})=>c(e.tableId)||c(t.tableId)),u=o.filter(({tableId:e})=>c(e));for(let{id:e}of u)yield ox({id:e});for(let{id:e}of l)yield gS({id:e});for(let e of s)yield BS({id:e})},uw=(e,t)=>function*({doc:{tableIds:n,memoIds:r},collections:i,editor:{drawRelationship:a}}){let o=M(i).collection(`tableEntities`),s=o.selectByIds(n),c=M(i).collection(`memoEntities`).selectByIds(r);if(t||(yield My()),yield Py({[e]:ig.table}),yield JS({id:e,zIndex:Kv(s,c)}),yield qy({tableId:e}),a){if(a.start){let t=o.selectById(a.start.tableId),n=o.selectById(e);if(!t||!n)return;let r=M(i).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(({options:e})=>W(e,R.primaryKey));if(!r.length)return;let s=r.map(()=>qe());for(let e=0;e<r.length;e++){let t=r[e],i={id:s[e],tableId:n.id};yield[dC(i),kC({...i,value:!0}),hC({...i,value:t.name}),yC({...i,value:t.dataType}),xC({...i,value:t.default}),_C({...i,value:t.comment})]}yield mS({id:qe(),relationshipType:a.relationshipType,start:{tableId:t.id,columnIds:r.map(({id:e})=>e)},end:{tableId:n.id,columnIds:s}}),yield _b()}else yield rj(e)}},dw={addTableAction$:cw,removeTableAction$:lw,selectTableAction$:uw,pasteTableAction$:e=>function*({editor:{selectedMap:t,focusTable:n},settings:{show:r,columnOrder:i},collections:a}){let o=n&&!vy(n.focusType),s=Object.entries(t).filter(([,e])=>e===ig.table).map(([e])=>e).filter(e=>!o||e!==n?.tableId);for(let t of s)for(let n of e){let e={id:qe(),tableId:t};yield[dC(e),hC({...e,value:n.name}),yC({...e,value:n.dataType}),xC({...e,value:n.default}),_C({...e,value:n.comment}),kC({...e,value:W(n.options,R.notNull)}),DC({...e,value:W(n.options,R.unique)}),CC({...e,value:W(n.options,R.autoIncrement)})]}if(!n||!o)return;let c=M(a).collection(`tableEntities`).selectById(n.tableId);if(!c)return;let l=c.columnIds.filter(B(n.selectColumnIds));if(l.length===0)return;let u=c.columnIds.slice(c.columnIds.indexOf(l[l.length-1])+1),d=[...l,...u],f=sw(r,i);yield Zy();for(let t=0;t<d.length;t++){let r=d[t],i=e[t];if(!i)break;let a={id:r,tableId:c.id};yield[...f.map(e=>{switch(e){case F.columnName:return hC({...a,value:i.name});case F.columnDataType:return yC({...a,value:i.dataType});case F.columnDefault:return xC({...a,value:i.default});case F.columnComment:return _C({...a,value:i.comment});case F.columnAutoIncrement:return CC({...a,value:W(i.options,R.autoIncrement)});case F.columnUnique:return DC({...a,value:W(i.options,R.unique)});case F.columnNotNull:return kC({...a,value:W(i.options,R.notNull)});default:return null}}).filter(Boolean),Yy({tableId:c.id,columnId:r,focusType:n.focusType,$mod:!0,shiftKey:!1})]}let p=e.slice(d.length);for(let e of p){let t=qe(),r={id:t,tableId:c.id};yield[dC(r),...f.map(t=>{switch(t){case F.columnName:return hC({...r,value:e.name});case F.columnDataType:return yC({...r,value:e.dataType});case F.columnDefault:return xC({...r,value:e.default});case F.columnComment:return _C({...r,value:e.comment});case F.columnAutoIncrement:return CC({...r,value:W(e.options,R.autoIncrement)});case F.columnUnique:return DC({...r,value:W(e.options,R.unique)});case F.columnNotNull:return kC({...r,value:W(e.options,R.notNull)});default:return null}}).filter(Boolean),Yy({tableId:c.id,columnId:t,focusType:n.focusType,$mod:!0,shiftKey:!1})]}}};function fw(e,t,n,r=[]){let{doc:{relationshipIds:i},collections:a}=t,o=e.pop();return o&&(r.some(({id:e})=>e===o.id)||(r.push(o),M(a).collection(`relationshipEntities`).selectByIds(i).forEach(({start:t,end:r})=>{let i=t.columnIds.indexOf(o.id);if(i!==-1){let t=r.columnIds[i];e.push({id:t,tableId:r.tableId,value:n.value})}else{let i=r.columnIds.indexOf(o.id);if(i!==-1){let r=t.columnIds[i];e.push({id:r,tableId:t.tableId,value:n.value})}}})),fw(e,t,n,r)),r}const pw=B([U.columnNotNull,U.columnUnique,U.columnAutoIncrement]),mw=B([U.columnName,U.columnDataType,U.columnDefault,U.columnComment]),hw=e=>function*({editor:{selectedMap:t}}){if(e){let t=qe();yield dC({id:t,tableId:e}),yield Yy({tableId:e,columnId:t,focusType:U.columnName,$mod:!1,shiftKey:!1});return}let n=Object.entries(t).filter(([,e])=>e===ig.table).map(([e])=>({tableId:e,id:qe()}));for(let e of n)yield dC(e);let r=fe(n);r&&(yield Yy({tableId:r.tableId,columnId:r.id,focusType:U.columnName,$mod:!1,shiftKey:!1}))},gw=(e,t)=>function*(n){let{doc:{relationshipIds:r,indexIds:i},editor:{focusTable:a},collections:o}=n;if(a?.columnId){let e=my(n,t);e?yield Yy({tableId:a.tableId,columnId:e,focusType:a.focusType,$mod:!1,shiftKey:!1}):yield qy({tableId:a.tableId,focusType:U.tableName})}let s=B(t),c=M(o).collection(`relationshipEntities`).selectByIds(r).filter(({start:t,end:n})=>t.tableId===e&&t.columnIds.some(s)||n.tableId===e&&n.columnIds.some(s)),l=M(o).collection(`indexEntities`).selectByIds(i).filter(t=>t.tableId===e&&M(o).collection(`indexColumnEntities`).selectByIds(t.indexColumnIds).map(({columnId:e})=>e).some(s));for(let{id:e}of l)yield ox({id:e});for(let{id:e}of c)yield gS({id:e});for(let n of t)yield pC({id:n,tableId:e})},_w=(e,t,n)=>function*({collections:r}){if(!pw(e))return;let i=M(r).collection(`tableColumnEntities`).selectById(n);if(i)switch(e){case U.columnNotNull:yield kC({id:n,tableId:t,value:!W(i.options,R.notNull)});break;case U.columnUnique:yield DC({id:n,tableId:t,value:!W(i.options,R.unique)});break;case U.columnAutoIncrement:yield CC({id:n,tableId:t,value:!W(i.options,R.autoIncrement)})}},vw=e=>function*(t){let{settings:{relationshipDataTypeSync:n}}=t,r=[e];n&&(r=fw([e],t,e)),yield r.map(yC)},yw={addColumnAction$:hw,removeColumnAction$:gw,toggleColumnValueAction$:_w,changeColumnDataTypeAction$:vw,changeColumnValueAction$:(e,t,n,r)=>function*({collections:i}){if(!mw(e)||!M(i).collection(`tableColumnEntities`).selectById(n))return;let a={id:n,tableId:t,value:r};switch(e){case U.columnName:yield hC(a);break;case U.columnDataType:yield vw(a);break;case U.columnDefault:yield xC(a);break;case U.columnComment:yield _C(a)}},changeColumnPrimaryKeyAction$:(e,t)=>function*({collections:n}){let r=M(n).collection(`tableColumnEntities`).selectById(t);if(!r)return;let i=W(r.options,R.primaryKey);yield TC({tableId:e,id:t,value:!i})}};function bw(e,t){return!(e.x>t.x+t.w||e.x+e.w<t.x||e.y>t.y+t.h||e.y+e.h<t.y)}function xw(e){return e.filter(({options:e})=>W(e,R.primaryKey))}function Sw(e,t,n,r=1){let i=!0;for(let r of e)if(n===r.name&&r.id!==t&&n!==``){i=!1;break}return i?n:Sw(e,t,n.replace(/[0-9]/g,``)+r,r+1)}function Cw(e,t){for(let n of e)if(n.name.toUpperCase()===t.toUpperCase())return n;return null}const ww={[I.MariaDB]:`VARCHAR(255)`,[I.MSSQL]:`varchar(255)`,[I.MySQL]:`VARCHAR(255)`,[I.Oracle]:`VARCHAR2(255)`,[I.PostgreSQL]:`varchar(255)`,[I.SQLite]:`TEXT`,[I.Databricks]:`STRING`,[I.Snowflake]:`VARCHAR(255)`};function Tw(e,t,n,r=[]){let i=Ow(e,n,r);return i.members?Dw(i.members,t)??ww[t]??i.typeName:i.typeName}function Ew(e,t,n,r=[]){let{members:i}=Ow(e,t,r);return!i||Dw(i,n)!==void 0?``:` ${e}: ${i.join(` | `)}`}function Dw(e,t){if(t===I.MySQL||t===I.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function Ow(e,t,n){if(n.length)return{typeName:e,members:n};let r=new Set,i=e;for(;!r.has(i);){r.add(i);let e=kw(i,t);if(!e)break;if(e.values.length)return{typeName:i,members:e.values};if(!e.alias)break;i=e.alias}return{typeName:i,members:null}}function kw(e,t){let n=t.types[e];if(n)return n;let r=Object.keys(t.types).find(t=>t.slice(t.lastIndexOf(`.`)+1)===e);return r===void 0?void 0:t.types[r]}const Aw={database:``,catalog:``,schema:``},jw=Pw(Aw);function Mw(e,t,n){let r=Jp({}),i=Nw(e.entities),a=e.entities.map(a=>Lw(r,t,e,n,a,i(a)));return Bw(r,t,a,e,Iw(e.entities,a)),Gw(r,a),r}function Nw(e){let t=new Set(e.map(e=>Pw(e.namespace)));return e=>{let n=Pw(e.namespace);return t.size>1&&n!==jw?`${Fw(e.namespace)}_${e.name}`:e.name}}function Pw({database:e,catalog:t,schema:n}){return`${e}.${t}.${n}`}function Fw({database:e,catalog:t,schema:n}){return[e,t,n].filter(e=>e!==``).join(`_`)}function Iw(e,t){let n=new Map,r=(e,t)=>{let r=e.toLowerCase();n.has(r)||n.set(r,t)};return e.forEach((e,n)=>{let i=t[n],a=Pw(e.namespace);r(`${a}.${e.name}`,i),r(e.name,i),e.alias&&(r(e.alias,i),r(`${a}.${e.alias}`,i))}),e=>{let t=Pw(e.namespace);return n.get(`${t}.${e.entityName}`.toLowerCase())??(t===jw?n.get(e.entityName.toLowerCase())??null:null)}}function Lw({doc:e,collections:t},n,r,i,a,o){let{toWidth:s}=n,c=ng(o),l=ng(a.comment),u=NS({name:c,comment:l,ui:{widthName:H(s(c)),widthComment:H(s(l))}}),d={source:a,table:u,columns:[]};return a.attributes.forEach(e=>{let n=ng(e.path),a=Tw(e.typeName,i,r,e.enumValues),o=`${ng(e.comment)}${Ew(e.typeName,r,i,e.enumValues)}`.trim(),c=ng(e.default);zw(t,d,uC({tableId:u.id,name:n,comment:o,dataType:a,default:c,options:(e.autoIncrement?R.autoIncrement:0)|(e.primaryKey?R.primaryKey:0)|(Rw(e)?R.unique:0)|(e.notNull?R.notNull:0),ui:{widthName:H(s(n)),widthComment:H(s(o)),widthDataType:H(s(a)),widthDefault:H(s(c)),keys:e.primaryKey?z.primaryKey:0}}))}),e.tableIds.push(u.id),M(t).collection(`tableEntities`).setOne(u),d}function Rw(e){return e.indexes.some(e=>e.unique&&e.name===``)}function zw(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),M(e).collection(`tableColumnEntities`).setOne(n)}function Bw(e,t,n,r,i){let a=new Set;r.relations.forEach(r=>{let o=i(r.src),s=i(r.ref);if(!o||!s)return;let c=Vw(o,r.src),l=Vw(s,r.ref);if(c.length!==0&&l.length!==0&&c.length===l.length){if(r.srcCardinality===`n`&&r.refCardinality===`n`){Uw(e,t,n,o,s);return}Hw(e,t,a,{parent:s,parentColumns:l,child:o,childColumns:c,toMany:r.refCardinality===`n`})}})}function Vw(e,t){if(t.attributePaths.length===0)return xw(e.columns);let n=[];for(let r of t.attributePaths){let t=Cw(e.columns,r);if(!t)return[];n.push(t)}return n}function Hw({doc:e,collections:t},{toWidth:n},r,{parent:i,parentColumns:a,child:o,childColumns:s,toMany:c}){let l=`${i.table.id}:${o.table.id}:${s.map(e=>e.id).join(`,`)}`;if(r.has(l))return;r.add(l);let u=s.every(e=>W(e.options,R.notNull));s.forEach((e,t)=>{if(e.dataType===``){let{dataType:r}=a[t];e.dataType=r,e.ui.widthDataType=H(n(r))}e.ui.keys=W(e.ui.keys,z.primaryKey)?e.ui.keys|z.foreignKey:z.foreignKey});let d=pS({identification:s.every(e=>W(e.ui.keys,z.primaryKey)&&W(e.ui.keys,z.foreignKey)),relationshipType:c?u?rh.OneN:rh.ZeroN:u?rh.OneOnly:rh.ZeroOne,start:{tableId:i.table.id,columnIds:a.map(e=>e.id)},end:{tableId:o.table.id,columnIds:s.map(e=>e.id)}});e.relationshipIds.push(d.id),M(t).collection(`relationshipEntities`).setOne(d)}function Uw(e,t,n,r,i){let{doc:a,collections:o}=e,{toWidth:s}=t,c=xw(r.columns),l=xw(i.columns);if(!c.length||!l.length)return;let u=Sw(n.map(e=>e.table),``,`${r.table.name}_${i.table.name}`),d=`Junction table inferred from ${r.table.name} <-> ${i.table.name}`,f=NS({name:u,comment:d,ui:{widthName:H(s(u)),widthComment:H(s(d))}}),p={source:{namespace:Aw,name:u,alias:``,comment:d,attributes:[]},table:f,columns:[]};a.tableIds.push(f.id),M(o).collection(`tableEntities`).setOne(f),n.push(p),Ww(e,t,p,r,c),Ww(e,t,p,i,l)}function Ww(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=Sw(n.columns,``,`${r.table.name}_${e.name}`),{dataType:a}=e,s=uC({tableId:n.table.id,name:i,dataType:a,options:R.primaryKey|R.notNull,ui:{keys:z.primaryKey|z.foreignKey,widthName:H(t(i)),widthDataType:H(t(a))}});return zw(o,n,s),s}),c=pS({identification:!0,relationshipType:rh.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),M(o).collection(`relationshipEntities`).setOne(c)}function Gw({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{let a=new Map;n.attributes.forEach((e,t)=>{let n=i[t];n&&e.indexes.forEach((e,i)=>{if(e.unique&&e.name===``)return;let o=e.name===``?`b:${t}:${i}`:`n:${e.name}`,s=a.get(o)??{index:rx({name:ng(e.name),tableId:r.id}),indexColumns:[]};s.index.unique=s.index.unique||e.unique,s.indexColumns.push(bx({indexId:s.index.id,columnId:n.id,orderType:ah.ASC})),a.set(o,s)})}),a.forEach(({index:n,indexColumns:r})=>{r.forEach(e=>{n.indexColumnIds.push(e.id),n.seqIndexColumnIds.push(e.id),M(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(n.id),M(t).collection(`indexEntities`).setOne(n)})})}const J={identifier:1,quoted:2,string:3,expression:4,number:5,punctuation:6,doc:7,comment:8,newline:9},Kw=/[ \t\f\v]/,qw=/[0-9]/,Jw=/[A-Za-z_\u0080-\uffff]/,Yw=/[0-9A-Za-z_#\u0080-\uffff]/,Xw=/^[ \t]*/,Zw=/\\#/g,Qw={n:`
|
|
2
|
+
`};function $w(e){let t=[],n=0,r=1,i=eT(e,0),a=(e,n)=>{t.push({kind:e,value:n,line:r,depth:i})};for(t.push({kind:J.newline,value:``,line:0,depth:i});n<e.length;){let t=e[n];if(Kw.test(t)){n+=1;continue}if(t===`\r`||t===`
|
|
3
3
|
`){t===`\r`&&e[n+1]===`
|
|
4
|
-
`&&(n+=1),n+=1,i=
|
|
4
|
+
`&&(n+=1),n+=1,i=eT(e,n),a(J.newline,`
|
|
5
5
|
`),r+=1;continue}if(t===`#`){let t=n+1;for(;t<e.length&&e[t]!==`
|
|
6
|
-
`&&e[t]!==`\r`;)t+=1;a(
|
|
7
|
-
`||t===`\r`)break;if(t!==` `&&e[n+1]===`#`){r.push(t,`#`),n+=2;continue}if(t===`#`)break;r.push(t),n+=1}return{value:
|
|
8
|
-
`).length-1}}function
|
|
9
|
-
`||t===`\r`))break;let c=e[o+1];if(r&&t===`\\`&&c!==void 0){a.push(
|
|
10
|
-
`&&(s+=1),a.push(t),o+=1}return{value:a.join(``),index:o,lines:s,terminated:!1}}function
|
|
6
|
+
`&&e[t]!==`\r`;)t+=1;a(J.comment,e.slice(n+1,t).trim()),n=t;continue}if(t===`|`){if(e.startsWith(`|||`,n)){let t=nT(e,n+3);a(J.doc,aT(t.value)),n=t.index,r+=t.lines;continue}let t=tT(e,n+1);a(J.doc,t.value),n=t.index;continue}if(t===`"`){let t=rT(e,n+1,`"`,!0,!1);a(J.quoted,t.value),n=t.index;continue}if(t===`'`){let t=rT(e,n+1,`'`,!0,!1);a(J.string,t.value),n=t.index;continue}if(t==="`"){let t=rT(e,n+1,"`",!1,!0);a(J.expression,t.value),n=t.index,r+=t.lines;continue}if(qw.test(t)){let t=n;for(;t<e.length&&qw.test(e[t]);)t+=1;if(e[t]===`.`&&qw.test(e[t+1]??``))for(t+=1;t<e.length&&qw.test(e[t]);)t+=1;a(J.number,e.slice(n,t)),n=t;continue}if(Jw.test(t)){let t=n+1;for(;t<e.length&&Yw.test(e[t]);)t+=1;for(;t>n&&e[t-1]===`#`;)--t;a(J.identifier,e.slice(n,t)),n=t;continue}a(J.punctuation,t),n+=1}return t}function eT(e,t){let n=0;for(let r=t;r<e.length;r++){let t=e[r];if(t===` `)n+=1;else if(t===` `)n+=.5;else break}return Math.round(n)-1}function tT(e,t){let n=t;for(;n<e.length&&Kw.test(e[n]);)n+=1;if(n>t&&e[n]===`"`){let t=rT(e,n+1,`"`,!0,!1);if(t.terminated)return{value:t.value,index:t.index}}let r=[];for(n=t;n<e.length;){let t=e[n];if(t===`
|
|
7
|
+
`||t===`\r`)break;if(t!==` `&&e[n+1]===`#`){r.push(t,`#`),n+=2;continue}if(t===`#`)break;r.push(t),n+=1}return{value:iT(r.join(``).trim().replace(Zw,`#`)),index:n}}function nT(e,t){let n=e.indexOf(`|||`,t),r=n===-1?e.length:n,i=e.slice(t,r);return{value:i,index:n===-1?e.length:n+3,lines:i.split(`
|
|
8
|
+
`).length-1}}function rT(e,t,n,r,i){let a=[],o=t,s=0;for(;o<e.length;){if(e.startsWith(n,o))return{value:a.join(``),index:o+n.length,lines:s,terminated:!0};let t=e[o];if(!i&&(t===`
|
|
9
|
+
`||t===`\r`))break;let c=e[o+1];if(r&&t===`\\`&&c!==void 0){a.push(Qw[c]??c),o+=2;continue}t===`
|
|
10
|
+
`&&(s+=1),a.push(t),o+=1}return{value:a.join(``),index:o,lines:s,terminated:!1}}function iT(e){let t=e[0];return e.length>1&&(t===`"`||t===`'`)&&e.endsWith(t)?e.slice(1,-1):e}function aT(e){let t=e.replace(/\r\n|\r/g,`
|
|
11
11
|
`).split(`
|
|
12
|
-
`);t[0]?.trim()===``&&t.shift(),t.length&&t[t.length-1].trim()===``&&t.pop();let n=t.filter(e=>e.trim()!==``).map(e=>(
|
|
13
|
-
`)}const TC=new Set([`as`,`check`,`false`,`fk`,`index`,`namespace`,`null`,`nullable`,`pk`,`rel`,`true`,`type`,`unique`]),EC=new Set([`false`,`null`,`true`]),DC=/^-?\d+$/;function OC(e){try{return{ok:!0,model:jC(kC(vC(e)))}}catch(e){return{ok:!1,message:e instanceof Error?e.message:`Invalid AML`}}}function kC(e){let t=[],n=null;return e.forEach(e=>{if(e.kind===q.newline){n={depth:e.depth,tokens:[]},t.push(n);return}n?.tokens.push(e)}),t}function AC(e){let t=0;return{peek:(n=0)=>e[t+n]??null,next:()=>e[t++]??null,atEnd:()=>t>=e.length}}function jC(e){let t={entities:[],relations:[],types:{},skipped:[]},n=new Set,r=e=>{e!==``&&!n.has(e)&&(n.add(e),t.skipped.push(e))},i=YS,a=null,o={path:[],depth:0};return e.forEach(e=>{let n=AC(e.tokens),s=n.peek();if(!s)return;if(e.depth>=0){a!==null&&NC(n,e.depth,a,o,t,r);return}let c=s.kind===q.identifier?s.value.toLowerCase():``;if(c===`namespace`){n.next(),i=JC(n);return}if(c===`rel`||c===`fk`){n.next();let e=zC(n,i,r);e&&t.relations.push(e);return}if(c===`type`){n.next(),qC(n,i,t,r);return}if(!sw(s))return;let l=MC(n,i,r);l&&(t.entities.push(l),a=l,o={path:[],depth:0})}),t}function MC(e,t,n){let r=YC(e);if(r.name===``)return null;let i=e.peek();i&&J(i,`*`)&&(e.next(),n(`view`));let a=ZC(e),o=QC(e,n);return{namespace:iw(t,r.namespace),name:r.name,alias:a,comment:o.doc||o.comment,attributes:[]}}function NC(e,t,n,r,i,a){let o=rw(e);if(o===``)return;let s=FC(e),c={path:PC(r,t,o),comment:``,typeName:s.typeName,enumValues:s.enumValues,notNull:!0,primaryKey:!1,indexes:[],default:s.default,autoIncrement:!1},l=e.peek();l&&cw(l,`nullable`)&&(e.next(),c.notNull=!1),IC(e,c,n,i,a);let u=QC(e,a);c.comment=u.doc||u.comment,c.autoIncrement=u.autoIncrement,n.attributes.push(c)}function PC(e,t,n){if(t===0||e.path.length===0)e.depth=0,e.path=[n];else if(t>e.depth)e.depth+=1,e.path=[...e.path,n];else{let r=e.depth-t;e.depth=t,e.path=[...e.path.slice(0,-(r+1)),n]}return e.path.join(`.`)}function FC(e){let t=rw(e);if(t===``)return{typeName:``,enumValues:[],default:``};let n=t,r=[],i=e.peek();if(i&&J(i,`(`)){e.next();let{values:i,numeric:a}=tw(e);i.length!==0&&i.length<=2&&a?n=`${t}(${i.join(`,`)})`:r=i}let a=e.peek();return a&&J(a,`=`)?(e.next(),{typeName:n,enumValues:r,default:nw(e)}):{typeName:n,enumValues:r,default:``}}function IC(e,t,n,r,i){let a=()=>{let i=BC(e);return i?(r.relations.push({src:{namespace:n.namespace,entityName:n.name,attributePaths:[t.path]},...i}),!0):!1};for(;!e.atEnd();){let n=e.peek();if(!n)return;if(n.kind===q.identifier){let r=n.value.toLowerCase();if(r===`pk`){e.next(),RC(e),t.primaryKey=!0;continue}if(r===`unique`||r===`index`){e.next(),t.indexes.push({name:RC(e),unique:r===`unique`});continue}if(r===`check`){e.next(),LC(e),i(`check`);continue}if(r===`fk`&&a())continue;return}if(!(lw(n)&&a()))return}}function LC(e){let t=e.peek();t&&J(t,`(`)&&(e.next(),ow(e,`(`,`)`)),RC(e)}function RC(e){let t=e.peek();return!t||!J(t,`=`)?``:(e.next(),rw(e))}function zC(e,t,n){let r=UC(e),i=BC(e);return QC(e,n),!i||r.entityName===``?null:{src:aw(r.namespace)?{...r,namespace:t}:r,...i}}function BC(e){let t=e.peek();if(t&&cw(t,`fk`)){e.next();let t=UC(e);return t.entityName===``?null:{ref:t,srcCardinality:`n`,refCardinality:`1`,polymorphic:!1}}let n=VC(e);if(n===null)return null;let r=HC(e);r&&(GC(e),e.next(),nw(e));let i=VC(e)??`n`,a=UC(e);return a.entityName===``?null:{ref:a,srcCardinality:i,refCardinality:n,polymorphic:r}}function VC(e){let t=e.peek();return!t||!lw(t)?null:(e.next(),t.value===`-`?`1`:`n`)}function HC(e){let t=0;for(;;){let n=e.peek(t);if(!n||!sw(n))return!1;t+=1;let r=e.peek(t);if(!r||!J(r,`.`))break;t+=1}let n=e.peek(t);return n!==null&&J(n,`=`)}function UC(e){let t=YC(e),n=e.peek();if(n&&J(n,`(`))return e.next(),{namespace:t.namespace,entityName:t.name,attributePaths:WC(e)};if(t.namespace.schema===``)return{namespace:YS,entityName:t.name,attributePaths:[]};let r=[t.name,...KC(e)].join(`.`);return{namespace:{database:``,catalog:``,schema:t.namespace.catalog},entityName:t.namespace.schema,attributePaths:[r]}}function WC(e){let t=[];for(;!e.atEnd();){let n=e.peek();if(!n||J(n,`)`)){e.next();break}if(sw(n)){t.push(GC(e));continue}e.next()}return t}function GC(e){let t=[rw(e)];for(;!e.atEnd();){let n=e.peek();if(!n||!J(n,`.`))break;e.next();let r=rw(e);if(r===``)break;t.push(r)}return t.join(`.`)}function KC(e){let t=[];for(;!e.atEnd();){let n=e.peek();if(!n||!J(n,`:`))break;e.next();let r=rw(e);if(r===``)break;t.push(r)}return t}function qC(e,t,n,r){let i=YC(e);if(i.name===``)return;let a={values:[],alias:``},o=e.peek();o&&J(o,`(`)?(e.next(),a.values=tw(e).values):o&&J(o,`{`)?(e.next(),ow(e,`{`,`}`),r(`struct type`)):o&&o.kind===q.expression?(e.next(),r(`custom type`)):o&&sw(o)&&(a.alias=rw(e)),QC(e,r);let s=iw(t,i.namespace),c=[s.database,s.catalog,s.schema,i.name].filter(e=>e!==``).join(`.`);n.types[c]=a,c!==i.name&&!(i.name in n.types)&&(n.types[i.name]=a)}function JC(e){let t=rw(e);if(t===``)return YS;let n=XC(e),r=XC(e);return n&&r?{database:t,catalog:n.name,schema:r.name}:n?{database:``,catalog:t,schema:n.name}:{database:``,catalog:``,schema:t}}function YC(e){let t=rw(e);if(t===``)return{namespace:YS,name:``};let n=XC(e),r=XC(e),i=XC(e);return n&&r&&i&&i.name!==``?{namespace:{database:t,catalog:n.name,schema:r.name},name:i.name}:n&&r&&r.name!==``?{namespace:{database:``,catalog:t,schema:n.name},name:r.name}:n&&n.name!==``?{namespace:{database:``,catalog:``,schema:t},name:n.name}:{namespace:YS,name:t}}function XC(e){let t=e.peek();return!t||!J(t,`.`)?null:(e.next(),{name:rw(e)})}function ZC(e){let t=e.peek();return!t||!cw(t,`as`)?``:(e.next(),rw(e))}function QC(e,t){let n={autoIncrement:!1,doc:``,comment:``};for(;!e.atEnd();){let r=e.next();if(!r)break;if(J(r,`{`)){$C(e,n,t);continue}if(r.kind===q.doc&&n.doc===``){n.doc=r.value;continue}r.kind===q.comment&&n.comment===``&&(n.comment=r.value)}return n}function $C(e,t,n){for(;!e.atEnd();){let r=e.next();if(!r||J(r,`}`))return;if(r.kind!==q.identifier&&r.kind!==q.quoted)continue;let i=e.peek();i&&(J(i,`:`)||J(i,`=`))&&(e.next(),ew(e)),r.value.toLowerCase()===`autoincrement`?t.autoIncrement=!0:n(r.value)}}function ew(e){let t=0;for(;!e.atEnd();){let n=e.peek();if(!n||t===0&&(J(n,`,`)||J(n,`}`)))return;e.next(),J(n,`[`)?t+=1:J(n,`]`)&&--t}}function tw(e){let t=[],n=!0;for(;!e.atEnd();){let r=e.peek();if(!r||J(r,`)`)){e.next();break}if(J(r,`,`)){e.next();continue}let i=nw(e);t.push(i),n=n&&r.kind!==q.quoted&&DC.test(i)}return{values:t,numeric:n}}function nw(e){let t=e.peek();if(!t)return``;if(J(t,`-`)&&e.peek(1)?.kind===q.number)return e.next(),`-${e.next()?.value??``}`;switch(e.next(),t.kind){case q.expression:return`\`${t.value}\``;case q.string:return`'${t.value}'`;case q.identifier:return EC.has(t.value.toLowerCase())?t.value.toLowerCase():t.value;default:return t.value}}function rw(e){let t=e.peek();return!t||!sw(t)?``:(e.next(),t.value)}function iw(e,t){return{database:t.database||e.database,catalog:t.catalog||e.catalog,schema:t.schema||e.schema}}function aw(e){return e.database===``&&e.catalog===``&&e.schema===``}function ow(e,t,n){let r=1;for(;!e.atEnd()&&r!==0;){let i=e.next();if(!i)break;J(i,t)?r+=1:J(i,n)&&--r}}function sw(e){return e.kind===q.quoted||e.kind===q.identifier&&!TC.has(e.value.toLowerCase())}function cw(e,t){return e.kind===q.identifier&&e.value.toLowerCase()===t}function lw(e){return e.kind===q.punctuation&&(e.value===`-`||e.value===`<`||e.value===`>`)}function J(e,t){return e.kind===q.punctuation&&e.value===t}const uw={entities:[],relations:[],types:{},skipped:[]};function dw(e,t,n){let r=OC(e),i=r.ok?r.model:uw,a=Bp({}),o=hh(i.entities.length*100);a.settings.width=o,a.settings.height=o;let{settings:s}=n?n(a):a,c=ZS(i,t,s.database);return c.settings=s,Bm(c)}const fw={[F.MariaDB]:`VARCHAR(255)`,[F.MSSQL]:`varchar(255)`,[F.MySQL]:`VARCHAR(255)`,[F.Oracle]:`VARCHAR2(255)`,[F.PostgreSQL]:`varchar(255)`,[F.SQLite]:`TEXT`,[F.Databricks]:`STRING`,[F.Snowflake]:`VARCHAR(255)`};function pw(e,t,n,r){let i=gw(e,t,r);return i?hw(i,n)??fw[n]??e:e}function mw(e,t,n,r){let i=gw(e,t,n);return!i||hw(i,r)!==void 0?``:` ${e}: ${i.join(` | `)}`}function hw(e,t){if(t===F.MySQL||t===F.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function gw(e,t,n){let r=t?`${t}.${e}`:``;return n.enums[r]??n.enums[e]??null}const _w=`public`;function vw(e,t,n){let r=Bp({}),i=yw(e.tables),a=e.tables.map(a=>Sw(r,t,e,n,a,i(a)));return ww(r,t,a,e,xw(e.tables,a)),kw(r,a),r}function yw(e){let t=new Set(e.map(e=>bw(e.schemaName)));return e=>{let n=bw(e.schemaName);return t.size>1&&n!==_w?`${n}_${e.name}`:e.name}}function bw(e){return e===``?_w:e}function xw(e,t){let n=new Map,r=(e,t)=>{let r=e.toLowerCase();n.has(r)||n.set(r,t)};return e.forEach((e,n)=>{let i=t[n],a=bw(e.schemaName);r(`${a}.${e.name}`,i),r(e.name,i),e.alias&&(r(e.alias,i),r(`${a}.${e.alias}`,i))}),e=>{let t=bw(e.schemaName);return n.get(`${t}.${e.tableName}`.toLowerCase())??(e.schemaName===``?n.get(e.tableName.toLowerCase())??null:null)}}function Sw({doc:e,collections:t},n,r,i,a,o){let{toWidth:s}=n,c=Ch(o),l=Ch(a.comment),u=Qb({name:c,comment:l,ui:{widthName:V(s(c)),widthComment:V(s(l))}}),d={source:a,table:u,columns:[]},f=new Set(a.indexes.filter(e=>e.primaryKey).flatMap(e=>e.columnNames).map(e=>e.toUpperCase()));return a.columns.forEach(e=>{let n=Ch(e.name),a=e.primaryKey||f.has(n.toUpperCase()),o=pw(e.typeName,e.typeSchemaName,i,r),c=`${Ch(e.comment)}${mw(e.typeName,e.typeSchemaName,r,i)}`.trim(),l=Ch(e.default);Cw(t,d,kx({tableId:u.id,name:n,comment:c,dataType:o,default:l,options:(e.autoIncrement?L.autoIncrement:0)|(a?L.primaryKey:0)|(e.unique?L.unique:0)|(e.notNull?L.notNull:0),ui:{widthName:V(s(n)),widthComment:V(s(c)),widthDataType:V(s(o)),widthDefault:V(s(l)),keys:a?R.primaryKey:0}}))}),e.tableIds.push(u.id),j(t).collection(`tableEntities`).setOne(u),d}function Cw(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),j(e).collection(`tableColumnEntities`).setOne(n)}function ww(e,t,n,r,i){let a=new Set,o=t=>Ew(e,a,t);n.forEach(r=>{r.source.columns.forEach((a,s)=>{let c=r.columns[s];c&&a.inlineRefs.forEach(a=>{let s=i(a.target);if(!s)return;let l=Tw(s,a.target);if(l.length!==1)return;if(a.operator===`<>`){Dw(e,t,n,r,s);return}let u=a.operator!==`<`;o(u?{parent:s,parentColumns:l,child:r,childColumns:[c],toMany:a.operator===`>`}:{parent:r,parentColumns:[c],child:s,childColumns:l,toMany:!0})})})}),r.refs.forEach(r=>{let a=i(r.left),s=i(r.right);if(!a||!s)return;let c=Tw(a,r.left),l=Tw(s,r.right);if(c.length===0||c.length!==r.left.columnNames.length||l.length!==r.right.columnNames.length||c.length!==l.length)return;if(r.operator===`<>`){Dw(e,t,n,a,s);return}let u=r.operator!==`>`;o({parent:u?a:s,parentColumns:u?c:l,child:u?s:a,childColumns:u?l:c,toMany:r.operator!==`-`})})}function Tw(e,t){let n=[];for(let r of t.columnNames){let t=HS(e.columns,r);if(!t)return[];n.push(t)}return n}function Ew({doc:e,collections:t},n,{parent:r,parentColumns:i,child:a,childColumns:o,toMany:s}){if(i.length===0||o.length===0)return;let c=`${r.table.id}:${a.table.id}:${o.map(e=>e.id).join(`,`)}`;if(n.has(c))return;n.add(c);let l=o.every(e=>z(e.options,L.notNull));o.forEach(e=>{e.ui.keys=z(e.ui.keys,R.primaryKey)?e.ui.keys|R.foreignKey:R.foreignKey});let u=Mb({identification:o.every(e=>z(e.ui.keys,R.primaryKey)&&z(e.ui.keys,R.foreignKey)),relationshipType:s?l?Ym.OneN:Ym.ZeroN:l?Ym.OneOnly:Ym.ZeroOne,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:a.table.id,columnIds:o.map(e=>e.id)}});e.relationshipIds.push(u.id),j(t).collection(`relationshipEntities`).setOne(u)}function Dw(e,t,n,r,i){let{doc:a,collections:o}=e,{toWidth:s}=t,c=BS(r.columns),l=BS(i.columns);if(!c.length||!l.length)return;let u=VS(n.map(e=>e.table),``,`${r.table.name}_${i.table.name}`),d=`Junction table inferred from ${r.table.name} <-> ${i.table.name}`,f=Qb({name:u,comment:d,ui:{widthName:V(s(u)),widthComment:V(s(d))}}),p={source:{schemaName:``,name:u,alias:``,comment:d,columns:[],indexes:[]},table:f,columns:[]};a.tableIds.push(f.id),j(o).collection(`tableEntities`).setOne(f),n.push(p),Ow(e,t,p,r,c),Ow(e,t,p,i,l)}function Ow(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=VS(n.columns,``,`${r.table.name}_${e.name}`),{dataType:a}=e,s=kx({tableId:n.table.id,name:i,dataType:a,options:L.primaryKey|L.notNull,ui:{keys:R.primaryKey|R.foreignKey,widthName:V(t(i)),widthDataType:V(t(a))}});return Cw(o,n,s),s}),c=Mb({identification:!0,relationshipType:Ym.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),j(o).collection(`relationshipEntities`).setOne(c)}function kw({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{n.indexes.forEach(n=>{if(n.primaryKey)return;let a=Sy({name:Ch(n.name),tableId:r.id,unique:n.unique}),o=[];n.columnNames.forEach(e=>{let t=HS(i,e);t&&o.push(zy({indexId:a.id,columnId:t.id,orderType:Zm.ASC}))}),o.length&&(o.forEach(e=>{a.indexColumnIds.push(e.id),a.seqIndexColumnIds.push(e.id),j(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(a.id),j(t).collection(`indexEntities`).setOne(a))})})}const Y={identifier:1,quoted:2,string:3,expression:4,number:5,punctuation:6,operator:7,newline:8},Aw=/[ \t\f\v]/,jw=/[0-9]/,Mw=/[A-Za-z_\u0080-\uffff]/,Nw=/[0-9A-Za-z_\u0080-\uffff]/,Pw=/^[ \t]*/,Fw={n:`
|
|
14
|
-
`,r:`\r`,t:` `,b:`\b`,f:`\f`,v:`\v`,0:`\0`};function
|
|
15
|
-
`)};for(;n<e.length;){let t=e[n];if(
|
|
12
|
+
`);t[0]?.trim()===``&&t.shift(),t.length&&t[t.length-1].trim()===``&&t.pop();let n=t.filter(e=>e.trim()!==``).map(e=>(Xw.exec(e)?.[0]??``).length),r=n.length?Math.min(...n):0;return t.map(e=>e.slice(r)).join(`
|
|
13
|
+
`)}const oT=new Set([`as`,`check`,`false`,`fk`,`index`,`namespace`,`null`,`nullable`,`pk`,`rel`,`true`,`type`,`unique`]),sT=new Set([`false`,`null`,`true`]),cT=/^-?\d+$/;function lT(e){try{return{ok:!0,model:fT(uT($w(e)))}}catch(e){return{ok:!1,message:e instanceof Error?e.message:`Invalid AML`}}}function uT(e){let t=[],n=null;return e.forEach(e=>{if(e.kind===J.newline){n={depth:e.depth,tokens:[]},t.push(n);return}n?.tokens.push(e)}),t}function dT(e){let t=0;return{peek:(n=0)=>e[t+n]??null,next:()=>e[t++]??null,atEnd:()=>t>=e.length}}function fT(e){let t={entities:[],relations:[],types:{},skipped:[]},n=new Set,r=e=>{e!==``&&!n.has(e)&&(n.add(e),t.skipped.push(e))},i=Aw,a=null,o={path:[],depth:0};return e.forEach(e=>{let n=dT(e.tokens),s=n.peek();if(!s)return;if(e.depth>=0){a!==null&&mT(n,e.depth,a,o,t,r);return}let c=s.kind===J.identifier?s.value.toLowerCase():``;if(c===`namespace`){n.next(),i=kT(n);return}if(c===`rel`||c===`fk`){n.next();let e=bT(n,i,r);e&&t.relations.push(e);return}if(c===`type`){n.next(),OT(n,i,t,r);return}if(!HT(s))return;let l=pT(n,i,r);l&&(t.entities.push(l),a=l,o={path:[],depth:0})}),t}function pT(e,t,n){let r=AT(e);if(r.name===``)return null;let i=e.peek();i&&Y(i,`*`)&&(e.next(),n(`view`));let a=MT(e),o=NT(e,n);return{namespace:zT(t,r.namespace),name:r.name,alias:a,comment:o.doc||o.comment,attributes:[]}}function mT(e,t,n,r,i,a){let o=RT(e);if(o===``)return;let s=gT(e),c={path:hT(r,t,o),comment:``,typeName:s.typeName,enumValues:s.enumValues,notNull:!0,primaryKey:!1,indexes:[],default:s.default,autoIncrement:!1},l=e.peek();l&&UT(l,`nullable`)&&(e.next(),c.notNull=!1),_T(e,c,n,i,a);let u=NT(e,a);c.comment=u.doc||u.comment,c.autoIncrement=u.autoIncrement,n.attributes.push(c)}function hT(e,t,n){if(t===0||e.path.length===0)e.depth=0,e.path=[n];else if(t>e.depth)e.depth+=1,e.path=[...e.path,n];else{let r=e.depth-t;e.depth=t,e.path=[...e.path.slice(0,-(r+1)),n]}return e.path.join(`.`)}function gT(e){let t=RT(e);if(t===``)return{typeName:``,enumValues:[],default:``};let n=t,r=[],i=e.peek();if(i&&Y(i,`(`)){e.next();let{values:i,numeric:a}=IT(e);i.length!==0&&i.length<=2&&a?n=`${t}(${i.join(`,`)})`:r=i}let a=e.peek();return a&&Y(a,`=`)?(e.next(),{typeName:n,enumValues:r,default:LT(e)}):{typeName:n,enumValues:r,default:``}}function _T(e,t,n,r,i){let a=()=>{let i=xT(e);return i?(r.relations.push({src:{namespace:n.namespace,entityName:n.name,attributePaths:[t.path]},...i}),!0):!1};for(;!e.atEnd();){let n=e.peek();if(!n)return;if(n.kind===J.identifier){let r=n.value.toLowerCase();if(r===`pk`){e.next(),yT(e),t.primaryKey=!0;continue}if(r===`unique`||r===`index`){e.next(),t.indexes.push({name:yT(e),unique:r===`unique`});continue}if(r===`check`){e.next(),vT(e),i(`check`);continue}if(r===`fk`&&a())continue;return}if(!(WT(n)&&a()))return}}function vT(e){let t=e.peek();t&&Y(t,`(`)&&(e.next(),VT(e,`(`,`)`)),yT(e)}function yT(e){let t=e.peek();return!t||!Y(t,`=`)?``:(e.next(),RT(e))}function bT(e,t,n){let r=wT(e),i=xT(e);return NT(e,n),!i||r.entityName===``?null:{src:BT(r.namespace)?{...r,namespace:t}:r,...i}}function xT(e){let t=e.peek();if(t&&UT(t,`fk`)){e.next();let t=wT(e);return t.entityName===``?null:{ref:t,srcCardinality:`n`,refCardinality:`1`,polymorphic:!1}}let n=ST(e);if(n===null)return null;let r=CT(e);r&&(ET(e),e.next(),LT(e));let i=ST(e)??`n`,a=wT(e);return a.entityName===``?null:{ref:a,srcCardinality:i,refCardinality:n,polymorphic:r}}function ST(e){let t=e.peek();return!t||!WT(t)?null:(e.next(),t.value===`-`?`1`:`n`)}function CT(e){let t=0;for(;;){let n=e.peek(t);if(!n||!HT(n))return!1;t+=1;let r=e.peek(t);if(!r||!Y(r,`.`))break;t+=1}let n=e.peek(t);return n!==null&&Y(n,`=`)}function wT(e){let t=AT(e),n=e.peek();if(n&&Y(n,`(`))return e.next(),{namespace:t.namespace,entityName:t.name,attributePaths:TT(e)};if(t.namespace.schema===``)return{namespace:Aw,entityName:t.name,attributePaths:[]};let r=[t.name,...DT(e)].join(`.`);return{namespace:{database:``,catalog:``,schema:t.namespace.catalog},entityName:t.namespace.schema,attributePaths:[r]}}function TT(e){let t=[];for(;!e.atEnd();){let n=e.peek();if(!n||Y(n,`)`)){e.next();break}if(HT(n)){t.push(ET(e));continue}e.next()}return t}function ET(e){let t=[RT(e)];for(;!e.atEnd();){let n=e.peek();if(!n||!Y(n,`.`))break;e.next();let r=RT(e);if(r===``)break;t.push(r)}return t.join(`.`)}function DT(e){let t=[];for(;!e.atEnd();){let n=e.peek();if(!n||!Y(n,`:`))break;e.next();let r=RT(e);if(r===``)break;t.push(r)}return t}function OT(e,t,n,r){let i=AT(e);if(i.name===``)return;let a={values:[],alias:``},o=e.peek();o&&Y(o,`(`)?(e.next(),a.values=IT(e).values):o&&Y(o,`{`)?(e.next(),VT(e,`{`,`}`),r(`struct type`)):o&&o.kind===J.expression?(e.next(),r(`custom type`)):o&&HT(o)&&(a.alias=RT(e)),NT(e,r);let s=zT(t,i.namespace),c=[s.database,s.catalog,s.schema,i.name].filter(e=>e!==``).join(`.`);n.types[c]=a,c!==i.name&&!(i.name in n.types)&&(n.types[i.name]=a)}function kT(e){let t=RT(e);if(t===``)return Aw;let n=jT(e),r=jT(e);return n&&r?{database:t,catalog:n.name,schema:r.name}:n?{database:``,catalog:t,schema:n.name}:{database:``,catalog:``,schema:t}}function AT(e){let t=RT(e);if(t===``)return{namespace:Aw,name:``};let n=jT(e),r=jT(e),i=jT(e);return n&&r&&i&&i.name!==``?{namespace:{database:t,catalog:n.name,schema:r.name},name:i.name}:n&&r&&r.name!==``?{namespace:{database:``,catalog:t,schema:n.name},name:r.name}:n&&n.name!==``?{namespace:{database:``,catalog:``,schema:t},name:n.name}:{namespace:Aw,name:t}}function jT(e){let t=e.peek();return!t||!Y(t,`.`)?null:(e.next(),{name:RT(e)})}function MT(e){let t=e.peek();return!t||!UT(t,`as`)?``:(e.next(),RT(e))}function NT(e,t){let n={autoIncrement:!1,doc:``,comment:``};for(;!e.atEnd();){let r=e.next();if(!r)break;if(Y(r,`{`)){PT(e,n,t);continue}if(r.kind===J.doc&&n.doc===``){n.doc=r.value;continue}r.kind===J.comment&&n.comment===``&&(n.comment=r.value)}return n}function PT(e,t,n){for(;!e.atEnd();){let r=e.next();if(!r||Y(r,`}`))return;if(r.kind!==J.identifier&&r.kind!==J.quoted)continue;let i=e.peek();i&&(Y(i,`:`)||Y(i,`=`))&&(e.next(),FT(e)),r.value.toLowerCase()===`autoincrement`?t.autoIncrement=!0:n(r.value)}}function FT(e){let t=0;for(;!e.atEnd();){let n=e.peek();if(!n||t===0&&(Y(n,`,`)||Y(n,`}`)))return;e.next(),Y(n,`[`)?t+=1:Y(n,`]`)&&--t}}function IT(e){let t=[],n=!0;for(;!e.atEnd();){let r=e.peek();if(!r||Y(r,`)`)){e.next();break}if(Y(r,`,`)){e.next();continue}let i=LT(e);t.push(i),n=n&&r.kind!==J.quoted&&cT.test(i)}return{values:t,numeric:n}}function LT(e){let t=e.peek();if(!t)return``;if(Y(t,`-`)&&e.peek(1)?.kind===J.number)return e.next(),`-${e.next()?.value??``}`;switch(e.next(),t.kind){case J.expression:return`\`${t.value}\``;case J.string:return`'${t.value}'`;case J.identifier:return sT.has(t.value.toLowerCase())?t.value.toLowerCase():t.value;default:return t.value}}function RT(e){let t=e.peek();return!t||!HT(t)?``:(e.next(),t.value)}function zT(e,t){return{database:t.database||e.database,catalog:t.catalog||e.catalog,schema:t.schema||e.schema}}function BT(e){return e.database===``&&e.catalog===``&&e.schema===``}function VT(e,t,n){let r=1;for(;!e.atEnd()&&r!==0;){let i=e.next();if(!i)break;Y(i,t)?r+=1:Y(i,n)&&--r}}function HT(e){return e.kind===J.quoted||e.kind===J.identifier&&!oT.has(e.value.toLowerCase())}function UT(e,t){return e.kind===J.identifier&&e.value.toLowerCase()===t}function WT(e){return e.kind===J.punctuation&&(e.value===`-`||e.value===`<`||e.value===`>`)}function Y(e,t){return e.kind===J.punctuation&&e.value===t}const GT={entities:[],relations:[],types:{},skipped:[]};function KT(e,t,n){let r=lT(e),i=r.ok?r.model:GT,a=Jp({}),o=Jh(i.entities.length*100);a.settings.width=o,a.settings.height=o;let{settings:s}=n?n(a):a,c=Mw(i,t,s.database);return c.settings=s,Jm(c)}const qT={[I.MariaDB]:`VARCHAR(255)`,[I.MSSQL]:`varchar(255)`,[I.MySQL]:`VARCHAR(255)`,[I.Oracle]:`VARCHAR2(255)`,[I.PostgreSQL]:`varchar(255)`,[I.SQLite]:`TEXT`,[I.Databricks]:`STRING`,[I.Snowflake]:`VARCHAR(255)`};function JT(e,t,n,r){let i=ZT(e,t,r);return i?XT(i,n)??qT[n]??e:e}function YT(e,t,n,r){let i=ZT(e,t,n);return!i||XT(i,r)!==void 0?``:` ${e}: ${i.join(` | `)}`}function XT(e,t){if(t===I.MySQL||t===I.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function ZT(e,t,n){let r=t?`${t}.${e}`:``;return n.enums[r]??n.enums[e]??null}const QT=`public`;function $T(e,t,n){let r=Jp({}),i=eE(e.tables),a=e.tables.map(a=>rE(r,t,e,n,a,i(a)));return aE(r,t,a,e,nE(e.tables,a)),uE(r,a),r}function eE(e){let t=new Set(e.map(e=>tE(e.schemaName)));return e=>{let n=tE(e.schemaName);return t.size>1&&n!==QT?`${n}_${e.name}`:e.name}}function tE(e){return e===``?QT:e}function nE(e,t){let n=new Map,r=(e,t)=>{let r=e.toLowerCase();n.has(r)||n.set(r,t)};return e.forEach((e,n)=>{let i=t[n],a=tE(e.schemaName);r(`${a}.${e.name}`,i),r(e.name,i),e.alias&&(r(e.alias,i),r(`${a}.${e.alias}`,i))}),e=>{let t=tE(e.schemaName);return n.get(`${t}.${e.tableName}`.toLowerCase())??(e.schemaName===``?n.get(e.tableName.toLowerCase())??null:null)}}function rE({doc:e,collections:t},n,r,i,a,o){let{toWidth:s}=n,c=ng(o),l=ng(a.comment),u=NS({name:c,comment:l,ui:{widthName:H(s(c)),widthComment:H(s(l))}}),d={source:a,table:u,columns:[]},f=new Set(a.indexes.filter(e=>e.primaryKey).flatMap(e=>e.columnNames).map(e=>e.toUpperCase()));return a.columns.forEach(e=>{let n=ng(e.name),a=e.primaryKey||f.has(n.toUpperCase()),o=JT(e.typeName,e.typeSchemaName,i,r),c=`${ng(e.comment)}${YT(e.typeName,e.typeSchemaName,r,i)}`.trim(),l=ng(e.default);iE(t,d,uC({tableId:u.id,name:n,comment:c,dataType:o,default:l,options:(e.autoIncrement?R.autoIncrement:0)|(a?R.primaryKey:0)|(e.unique?R.unique:0)|(e.notNull?R.notNull:0),ui:{widthName:H(s(n)),widthComment:H(s(c)),widthDataType:H(s(o)),widthDefault:H(s(l)),keys:a?z.primaryKey:0}}))}),e.tableIds.push(u.id),M(t).collection(`tableEntities`).setOne(u),d}function iE(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),M(e).collection(`tableColumnEntities`).setOne(n)}function aE(e,t,n,r,i){let a=new Set,o=t=>sE(e,a,t);n.forEach(r=>{r.source.columns.forEach((a,s)=>{let c=r.columns[s];c&&a.inlineRefs.forEach(a=>{let s=i(a.target);if(!s)return;let l=oE(s,a.target);if(l.length!==1)return;if(a.operator===`<>`){cE(e,t,n,r,s);return}let u=a.operator!==`<`;o(u?{parent:s,parentColumns:l,child:r,childColumns:[c],toMany:a.operator===`>`}:{parent:r,parentColumns:[c],child:s,childColumns:l,toMany:!0})})})}),r.refs.forEach(r=>{let a=i(r.left),s=i(r.right);if(!a||!s)return;let c=oE(a,r.left),l=oE(s,r.right);if(c.length===0||c.length!==r.left.columnNames.length||l.length!==r.right.columnNames.length||c.length!==l.length)return;if(r.operator===`<>`){cE(e,t,n,a,s);return}let u=r.operator!==`>`;o({parent:u?a:s,parentColumns:u?c:l,child:u?s:a,childColumns:u?l:c,toMany:r.operator!==`-`})})}function oE(e,t){let n=[];for(let r of t.columnNames){let t=Cw(e.columns,r);if(!t)return[];n.push(t)}return n}function sE({doc:e,collections:t},n,{parent:r,parentColumns:i,child:a,childColumns:o,toMany:s}){if(i.length===0||o.length===0)return;let c=`${r.table.id}:${a.table.id}:${o.map(e=>e.id).join(`,`)}`;if(n.has(c))return;n.add(c);let l=o.every(e=>W(e.options,R.notNull));o.forEach(e=>{e.ui.keys=W(e.ui.keys,z.primaryKey)?e.ui.keys|z.foreignKey:z.foreignKey});let u=pS({identification:o.every(e=>W(e.ui.keys,z.primaryKey)&&W(e.ui.keys,z.foreignKey)),relationshipType:s?l?rh.OneN:rh.ZeroN:l?rh.OneOnly:rh.ZeroOne,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:a.table.id,columnIds:o.map(e=>e.id)}});e.relationshipIds.push(u.id),M(t).collection(`relationshipEntities`).setOne(u)}function cE(e,t,n,r,i){let{doc:a,collections:o}=e,{toWidth:s}=t,c=xw(r.columns),l=xw(i.columns);if(!c.length||!l.length)return;let u=Sw(n.map(e=>e.table),``,`${r.table.name}_${i.table.name}`),d=`Junction table inferred from ${r.table.name} <-> ${i.table.name}`,f=NS({name:u,comment:d,ui:{widthName:H(s(u)),widthComment:H(s(d))}}),p={source:{schemaName:``,name:u,alias:``,comment:d,columns:[],indexes:[]},table:f,columns:[]};a.tableIds.push(f.id),M(o).collection(`tableEntities`).setOne(f),n.push(p),lE(e,t,p,r,c),lE(e,t,p,i,l)}function lE(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=Sw(n.columns,``,`${r.table.name}_${e.name}`),{dataType:a}=e,s=uC({tableId:n.table.id,name:i,dataType:a,options:R.primaryKey|R.notNull,ui:{keys:z.primaryKey|z.foreignKey,widthName:H(t(i)),widthDataType:H(t(a))}});return iE(o,n,s),s}),c=pS({identification:!0,relationshipType:rh.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),M(o).collection(`relationshipEntities`).setOne(c)}function uE({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{n.indexes.forEach(n=>{if(n.primaryKey)return;let a=rx({name:ng(n.name),tableId:r.id,unique:n.unique}),o=[];n.columnNames.forEach(e=>{let t=Cw(i,e);t&&o.push(bx({indexId:a.id,columnId:t.id,orderType:ah.ASC}))}),o.length&&(o.forEach(e=>{a.indexColumnIds.push(e.id),a.seqIndexColumnIds.push(e.id),M(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(a.id),M(t).collection(`indexEntities`).setOne(a))})})}const X={identifier:1,quoted:2,string:3,expression:4,number:5,punctuation:6,operator:7,newline:8},dE=/[ \t\f\v]/,fE=/[0-9]/,pE=/[A-Za-z_\u0080-\uffff]/,mE=/[0-9A-Za-z_\u0080-\uffff]/,hE=/^[ \t]*/,gE={n:`
|
|
14
|
+
`,r:`\r`,t:` `,b:`\b`,f:`\f`,v:`\v`,0:`\0`};function _E(e){let t=[],n=0,r=1,i=0,a=(e,n)=>{t.push({kind:e,value:n,line:r})},o=()=>{i===0&&a(X.newline,`
|
|
15
|
+
`)};for(;n<e.length;){let t=e[n];if(dE.test(t)){n+=1;continue}if(t===`\r`||t===`
|
|
16
16
|
`){t===`\r`&&e[n+1]===`
|
|
17
17
|
`&&(n+=1),n+=1,o(),r+=1;continue}if(t===`/`&&e[n+1]===`/`){for(n+=2;n<e.length&&e[n]!==`
|
|
18
18
|
`;)n+=1;continue}if(t===`/`&&e[n+1]===`*`){n+=2;let t=!1;for(;n<e.length;){if(e[n]===`*`&&e[n+1]===`/`){n+=2;break}e[n]===`
|
|
19
|
-
`&&(t=!0,r+=1),n+=1}t&&o();continue}if(t===`"`){let t=
|
|
20
|
-
`&&(o+=1),i.push(t),a+=1}return{value:i.join(``),index:a,lines:o}}function
|
|
19
|
+
`&&(t=!0,r+=1),n+=1}t&&o();continue}if(t===`"`){let t=yE(e,n+1,`"`,!0);n=t.index,r+=t.lines,a(X.quoted,t.value);continue}if(t===`'`){if(e.startsWith(`'''`,n)){let t=yE(e,n+3,`'''`,!0);n=t.index,r+=t.lines,a(X.string,bE(t.value));continue}let t=yE(e,n+1,`'`,!0);n=t.index,r+=t.lines,a(X.string,t.value);continue}if(t==="`"){let t=yE(e,n+1,"`",!1);n=t.index,r+=t.lines,a(X.expression,t.value);continue}if(fE.test(t)){let t=n;for(;t<e.length&&fE.test(e[t]);)t+=1;if(e[t]===`.`&&fE.test(e[t+1]??``))for(t+=1;t<e.length&&fE.test(e[t]);)t+=1;if((e[t]===`e`||e[t]===`E`)&&fE.test(e[t+1]??``))for(t+=2;t<e.length&&fE.test(e[t]);)t+=1;a(X.number,e.slice(n,t)),n=t;continue}if(pE.test(t)){let t=n+1;for(;t<e.length&&mE.test(e[t]);)t+=1;a(X.identifier,e.slice(n,t)),n=t;continue}let s=vE(e,n);if(s){a(X.operator,s),n+=s.length;continue}t===`[`||t===`(`?i+=1:(t===`]`||t===`)`)&&(i=Math.max(0,i-1)),a(X.punctuation,t),n+=1}return t}function vE(e,t){let n=e[t];if(n===`-`)return e[t+1]===`?`?`-?`:``;if(n!==`<`&&n!==`>`&&n!==`?`)return``;let r=/^\??(?:<>|<|>|-)\??/.exec(e.slice(t));return r&&/[<>-]/.test(r[0])?r[0]:``}function yE(e,t,n,r){let i=[],a=t,o=0;for(;a<e.length;){if(e.startsWith(n,a))return{value:i.join(``),index:a+n.length,lines:o};let t=e[a];if(r&&t===`\\`&&a+1<e.length){let t=e[a+1];i.push(gE[t]??t),a+=2;continue}t===`
|
|
20
|
+
`&&(o+=1),i.push(t),a+=1}return{value:i.join(``),index:a,lines:o}}function bE(e){let t=e.replace(/\r\n|\r/g,`
|
|
21
21
|
`).split(`
|
|
22
|
-
`);t[0]?.trim()===``&&t.shift(),t.length&&t[t.length-1].trim()===``&&t.pop();let n=t.filter(e=>e.trim()!==``).map(e=>(
|
|
23
|
-
`)}const Bw=/^[0-9a-z ]+$/,Vw=/'/g,Hw=/\?/g;function Uw(e){try{return{ok:!0,model:Gw(Iw(e))}}catch(e){return{ok:!1,message:e instanceof Error?e.message:`Invalid DBML`}}}function Ww(e){let t=0;return{peek:(n=0)=>e[t+n]??null,next:()=>e[t++]??null,atEnd:()=>t>=e.length}}function Gw(e){let t=Ww(e),n={tables:[],refs:[],enums:{},skipped:[]},r=new Map,i=new Set,a=e=>{i.has(e)||(i.add(e),n.skipped.push(e)),gT(t)};for(;!t.atEnd();){if(vT(t))continue;let e=t.peek();if(!e)break;if(!yT(e)){t.next();continue}let i=e.value.toLowerCase();if(i===`table`&&e.kind===Y.identifier){t.next();let e=Kw(t,r);e&&n.tables.push(e);continue}if(i===`tablepartial`&&e.kind===Y.identifier){t.next();let e=Kw(t,r);e&&r.set(e.name,e.columns);continue}if(i===`ref`&&e.kind===Y.identifier){t.next(),n.refs.push(...Qw(t));continue}if(i===`enum`&&e.kind===Y.identifier){t.next(),nT(t,n.enums);continue}a(i)}return n}function Kw(e,t){let{schemaName:n,name:r}=uT(e),i={schemaName:n,name:r,alias:``,comment:``,columns:[],indexes:[]},a=e.peek();if(a&&a.kind===Y.identifier&&a.value.toLowerCase()===`as`&&(e.next(),i.alias=dT(e)),oT(i,rT(e)),!mT(e))return r===``?null:i;for(;!e.atEnd();){if(vT(e))continue;let n=e.peek();if(!n)break;if(n.kind===Y.punctuation&&n.value===`}`){e.next();break}if(n.kind===Y.punctuation&&n.value===`~`){e.next();let n=t.get(dT(e));n&&i.columns.push(...n.map(e=>({...e})));continue}if(n.kind===Y.identifier){let t=n.value.toLowerCase(),r=e.peek(1);if(t===`note`&&r&&X(r,`:`)){e.next(),e.next(),i.comment=fT(e);continue}if(t===`note`&&r&&X(r,`{`)){e.next(),e.next(),i.comment=pT(e);continue}if(t===`indexes`&&r&&X(r,`{`)){e.next(),e.next(),i.indexes.push(...Xw(e));continue}if(r&&X(r,`{`)){e.next(),e.next(),hT(e);continue}}let r=qw(e);r&&i.columns.push(r)}return i}function qw(e){let t=e.peek();if(!t||!yT(t))return _T(e),null;e.next();let n={name:t.value,comment:``,typeName:``,typeSchemaName:``,primaryKey:!1,unique:!1,notNull:!1,autoIncrement:!1,default:``,inlineRefs:[]},r=Jw(e);return n.typeName=r.name,n.typeSchemaName=r.schemaName,iT(n,rT(e)),_T(e),n.typeName===``?null:n}function Jw(e){let{schemaName:t,name:n}=uT(e);if(n===``)return{name:``,schemaName:``};let r=[n],i=e.peek();i&&X(i,`(`)&&(e.next(),r.push(`(${Yw(e)})`));let a=e.peek(),o=e.peek(1);return a&&o&&X(a,`[`)&&X(o,`]`)&&(e.next(),e.next(),r.push(`[]`)),{name:r.join(``),schemaName:t}}function Yw(e){let t=[];for(;!e.atEnd();){let n=e.next();if(!n||X(n,`)`))break;n.kind!==Y.newline&&t.push(n.kind===Y.string?`'${n.value}'`:n.value)}return t.join(``)}function Xw(e){let t=[];for(;!e.atEnd();){if(vT(e))continue;let n=e.peek();if(!n)break;if(X(n,`}`)){e.next();break}let r={name:``,unique:!1,primaryKey:!1,columnNames:[]};X(n,`(`)?(e.next(),r.columnNames.push(...Zw(e))):yT(n)?(e.next(),r.columnNames.push(n.value)):e.next(),aT(r,rT(e)),_T(e),r.columnNames.length!==0&&t.push(r)}return t}function Zw(e){let t=[];for(;!e.atEnd();){let n=e.next();if(!n||X(n,`)`))break;yT(n)&&t.push(n.value)}return t}function Qw(e){let t=e.peek();if(t&&yT(t)){let t=e.peek(1);t&&(X(t,`:`)||X(t,`{`))&&e.next()}let n=e.peek();if(n&&X(n,`:`)){e.next();let t=$w(e);return _T(e),t?[t]:[]}if(!mT(e))return _T(e),[];let r=[];for(;!e.atEnd();){if(vT(e))continue;let t=e.peek();if(!t)break;if(X(t,`}`)){e.next();break}let n=$w(e);n?r.push(n):_T(e)}return r}function $w(e){let t=tT(e),n=eT(e);if(n===``)return null;let r=tT(e);return rT(e),t.tableName===``||r.tableName===``?null:{operator:n,left:t,right:r}}function eT(e){let t=e.peek();return t?t.kind===Y.operator?(e.next(),t.value.replace(Hw,``)):X(t,`-`)?(e.next(),`-`):``:``}function tT(e){let t=[],n=[];for(;!e.atEnd();){let r=e.peek();if(!r||!yT(r))break;e.next(),t.push(r.value);let i=e.peek();if(!i||!X(i,`.`))break;e.next();let a=e.peek();if(a&&X(a,`(`)){e.next(),n.push(...Zw(e));break}}n.length===0&&t.length!==0&&n.push(t.pop());let r=t.pop()??``;return{schemaName:t.pop()??``,tableName:r,columnNames:n}}function nT(e,t){let{schemaName:n,name:r}=uT(e);if(rT(e),!mT(e)){_T(e);return}let i=[];for(;!e.atEnd();){if(vT(e))continue;let t=e.peek();if(!t)break;if(X(t,`}`)){e.next();break}yT(t)?(e.next(),i.push(t.value),rT(e)):e.next(),_T(e)}r!==``&&(t[n?`${n}.${r}`:r]=i,n&&!(r in t)&&(t[r]=i))}function rT(e){let t=e.peek();if(!t||!X(t,`[`))return[];e.next();let n=[],r=[],i=[],a=!1,o=()=>{let e=r.join(` `).toLowerCase();(e!==``||i.length!==0)&&n.push({key:e,tokens:i}),r=[],i=[],a=!1};for(;!e.atEnd();){let t=e.next();if(!t||X(t,`]`))break;if(X(t,`,`)){o();continue}if(!a&&X(t,`:`)){a=!0;continue}if(a){i.push(t);continue}if(yT(t)&&Bw.test(t.value.toLowerCase())){r.push(t.value);continue}a=!0,i.push(t)}return o(),n}function iT(e,t){t.forEach(({key:t,tokens:n})=>{switch(t){case`pk`:case`primary key`:e.primaryKey=!0;break;case`unique`:e.unique=!0;break;case`not null`:e.notNull=!0;break;case`increment`:e.autoIncrement=!0;break;case`note`:e.comment=cT(n);break;case`default`:e.default=lT(n);break;case`ref`:{let t=sT(n);t&&e.inlineRefs.push(t);break}}})}function aT(e,t){t.forEach(({key:t,tokens:n})=>{switch(t){case`name`:e.name=cT(n);break;case`unique`:e.unique=!0;break;case`pk`:case`primary key`:e.primaryKey=!0}})}function oT(e,t){t.forEach(({key:t,tokens:n})=>{t===`note`&&(e.comment=cT(n))})}function sT(e){let t=Ww(e),n=eT(t);if(n===``)return null;let r=tT(t);return r.tableName===``?null:{operator:n,target:r}}function cT(e){let t=e.find(e=>e.kind===Y.string||e.kind===Y.quoted||e.kind===Y.identifier);return t?t.value:``}function lT(e){let t=e.filter(e=>e.kind!==Y.newline),n=t[0];if(!n)return``;if(X(n,`-`)&&t[1]?.kind===Y.number)return`-${t[1].value}`;switch(n.kind){case Y.string:return`'${n.value.replace(Vw,`''`)}'`;case Y.expression:case Y.number:case Y.identifier:case Y.quoted:return n.value;default:return t.map(e=>e.value).join(``)}}function uT(e){let t=dT(e);if(t===``)return{schemaName:``,name:``};let n=e.peek();return!n||!X(n,`.`)?{schemaName:``,name:t}:(e.next(),{schemaName:t,name:dT(e)})}function dT(e){let t=e.peek();return!t||!yT(t)?``:(e.next(),t.value)}function fT(e){let t=e.peek();return t&&(t.kind===Y.string||t.kind===Y.quoted)?(e.next(),t.value):``}function pT(e){let t=``;for(;!e.atEnd();){let n=e.next();if(!n||X(n,`}`))break;t===``&&n.kind===Y.string&&(t=n.value)}return t}function mT(e){let t=0;for(;e.peek(t)?.kind===Y.newline;)t+=1;let n=e.peek(t);if(!n||!X(n,`{`))return!1;for(let n=0;n<=t;n+=1)e.next();return!0}function hT(e){let t=1;for(;!e.atEnd()&&t!==0;){let n=e.next();if(!n)break;X(n,`{`)?t+=1:X(n,`}`)&&--t}}function gT(e){if(mT(e)){hT(e);return}for(;!e.atEnd();){let t=e.next();if(!t||t.kind===Y.newline)return;if(X(t,`{`)){hT(e);return}}}function _T(e){for(;!e.atEnd();){let t=e.peek();if(!t)return;if(t.kind===Y.newline){e.next();return}if(X(t,`}`))return;e.next()}}function vT(e){let t=e.peek();return t&&t.kind===Y.newline?(e.next(),!0):!1}function yT(e){return e.kind===Y.identifier||e.kind===Y.quoted}function X(e,t){return e.kind===Y.punctuation&&e.value===t}const bT={tables:[],refs:[],enums:{},skipped:[]};function xT(e,t,n){let r=Uw(e),i=r.ok?r.model:bT,a=Bp({}),o=hh(i.tables.length*100);a.settings.width=o,a.settings.height=o;let{settings:s}=n?n(a):a,c=vw(i,t,s.database);return c.settings=s,Bm(c)}const ST={[F.MariaDB]:`VARCHAR(255)`,[F.MSSQL]:`varchar(255)`,[F.MySQL]:`VARCHAR(255)`,[F.Oracle]:`VARCHAR2(255)`,[F.PostgreSQL]:`varchar(255)`,[F.SQLite]:`TEXT`,[F.Databricks]:`STRING`,[F.Snowflake]:`VARCHAR(255)`},CT={[F.MariaDB]:`INT`,[F.MSSQL]:`int`,[F.MySQL]:`INT`,[F.Oracle]:`INTEGER`,[F.PostgreSQL]:`integer`,[F.SQLite]:`INTEGER`,[F.Databricks]:`INT`,[F.Snowflake]:`INT`},wT={[F.MariaDB]:`SMALLINT`,[F.MSSQL]:`smallint`,[F.MySQL]:`SMALLINT`,[F.Oracle]:`SMALLINT`,[F.PostgreSQL]:`smallint`,[F.SQLite]:`SMALLINT`,[F.Databricks]:`SMALLINT`,[F.Snowflake]:`SMALLINT`},TT={[F.MariaDB]:`BIGINT`,[F.MSSQL]:`bigint`,[F.MySQL]:`BIGINT`,[F.Oracle]:`NUMBER(19)`,[F.PostgreSQL]:`bigint`,[F.SQLite]:`BIGINT`,[F.Databricks]:`BIGINT`,[F.Snowflake]:`BIGINT`},ET={[F.MariaDB]:`DOUBLE`,[F.MSSQL]:`float`,[F.MySQL]:`DOUBLE`,[F.Oracle]:`BINARY_DOUBLE`,[F.PostgreSQL]:`double precision`,[F.SQLite]:`REAL`,[F.Databricks]:`DOUBLE`,[F.Snowflake]:`FLOAT`},DT={[F.MariaDB]:`DECIMAL`,[F.MSSQL]:`decimal`,[F.MySQL]:`DECIMAL`,[F.Oracle]:`DECIMAL`,[F.PostgreSQL]:`numeric`,[F.SQLite]:`DECIMAL`,[F.Databricks]:`DECIMAL`,[F.Snowflake]:`DECIMAL`},OT={[F.MariaDB]:`BOOLEAN`,[F.MSSQL]:`bit`,[F.MySQL]:`BOOLEAN`,[F.Oracle]:`BOOLEAN`,[F.PostgreSQL]:`boolean`,[F.SQLite]:`BOOLEAN`,[F.Databricks]:`BOOLEAN`,[F.Snowflake]:`BOOLEAN`},kT={[F.MariaDB]:`DATE`,[F.MSSQL]:`date`,[F.MySQL]:`DATE`,[F.Oracle]:`DATE`,[F.PostgreSQL]:`date`,[F.SQLite]:`DATE`,[F.Databricks]:`DATE`,[F.Snowflake]:`DATE`},AT={[F.MariaDB]:`TIME`,[F.MSSQL]:`time`,[F.MySQL]:`TIME`,[F.Oracle]:`VARCHAR2(255)`,[F.PostgreSQL]:`time`,[F.SQLite]:`TEXT`,[F.Databricks]:`STRING`,[F.Snowflake]:`TIME`},jT={[F.MariaDB]:`DATETIME`,[F.MSSQL]:`datetime2`,[F.MySQL]:`DATETIME`,[F.Oracle]:`TIMESTAMP`,[F.PostgreSQL]:`timestamp`,[F.SQLite]:`DATETIME`,[F.Databricks]:`TIMESTAMP`,[F.Snowflake]:`TIMESTAMP_NTZ`},MT={[F.MariaDB]:`TIMESTAMP`,[F.MSSQL]:`datetimeoffset`,[F.MySQL]:`TIMESTAMP`,[F.Oracle]:`TIMESTAMP WITH TIME ZONE`,[F.PostgreSQL]:`timestamptz`,[F.SQLite]:`DATETIME`,[F.Databricks]:`TIMESTAMP`,[F.Snowflake]:`TIMESTAMP_TZ`},NT={[F.MariaDB]:`VARCHAR(255)`,[F.MSSQL]:`varchar(255)`,[F.MySQL]:`VARCHAR(255)`,[F.Oracle]:`INTERVAL DAY TO SECOND`,[F.PostgreSQL]:`interval`,[F.SQLite]:`TEXT`,[F.Databricks]:`INTERVAL DAY TO SECOND`,[F.Snowflake]:`VARCHAR(255)`},PT={[F.MariaDB]:`JSON`,[F.MSSQL]:`json`,[F.MySQL]:`JSON`,[F.Oracle]:`JSON`,[F.PostgreSQL]:`jsonb`,[F.SQLite]:`TEXT`,[F.Databricks]:`VARIANT`,[F.Snowflake]:`VARIANT`},FT={[F.MariaDB]:`UUID`,[F.MSSQL]:`uniqueidentifier`,[F.MySQL]:`CHAR(36)`,[F.Oracle]:`VARCHAR2(36)`,[F.PostgreSQL]:`uuid`,[F.SQLite]:`TEXT`,[F.Databricks]:`STRING`,[F.Snowflake]:`UUID`},IT={[F.MariaDB]:`BLOB`,[F.MSSQL]:`varbinary(max)`,[F.MySQL]:`BLOB`,[F.Oracle]:`BLOB`,[F.PostgreSQL]:`bytea`,[F.SQLite]:`BLOB`,[F.Databricks]:`BINARY`,[F.Snowflake]:`BINARY`},LT={id:ST,string:ST,boolean:OT,int:CT,float:ET,positiveint:CT,nonnegativeint:CT,unsignedint:CT,short:wT,smallint:wT,positivefloat:ET,nonnegativefloat:ET,bigint:TT,biginteger:TT,long:TT,int8:TT,safeint:TT,decimal:DT,bigdecimal:DT,numeric:DT,money:DT,datetime:jT,datetimeiso:jT,localdatetime:jT,timestamp:jT,timestamptz:MT,date:kT,localdate:kT,time:AT,localtime:AT,timetz:AT,duration:NT,iso8601duration:NT,interval:NT,json:PT,jsonb:PT,jsonobject:PT,uuid:FT,guid:FT,byte:IT,bytes:IT,bytea:IT,binary:IT,email:ST,emailaddress:ST,url:ST,uri:ST,void:ST};function RT(e,t,n){let r=ST[t]??``,i=HT(n.enums,e);return i?BT(i,t)??r:HT(n.unions,e)?r:LT[e.toLowerCase()]?.[t]??r}function zT(e,t,n){let r=HT(t.enums,e);if(r)return n!==void 0&&BT(r,n)!==void 0?``:VT(e,r);let i=HT(t.unions,e);return i?VT(e,i):``}function BT(e,t){if(t===F.MySQL||t===F.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function VT(e,t){return` ${e}: ${t.join(` | `)}`}function HT(e,t){let n=e[t];return Array.isArray(n)&&n.length?n:void 0}function UT(e,t,n){let r=Bp({}),i=WT(e.tables),a=new Set(e.skipped),o=e.tables.map(o=>GT(r,t,e,n,o,i,a));return XT(r,t,o),oE(r,o),r}function WT(e){let t=new Map,n=new Map;for(let r of e){t.set(r.name,r);let e=r.name.toLowerCase();n.has(e)||n.set(e,r)}return e=>t.get(e)??n.get(e.toLowerCase())??null}function GT({doc:e,collections:t},n,r,i,a,o,s){let{toWidth:c}=n,l=[],u=[];for(let e of a.fields){let{named:t}=e.typeRef;s.has(t)||(o(t)?u.push(e):l.push(e))}let d=new Set(KT(l)),f=Ch(a.name),p=Ch(a.comment),m=Qb({name:f,comment:p,ui:{widthName:V(c(f)),widthComment:V(c(p))}}),h={name:f,source:a,table:m,columns:[],referenceFields:u};return l.forEach(e=>{YT(t,h,qT(n,r,i,m.id,e,d.has(e)))}),e.tableIds.push(m.id),j(t).collection(`tableEntities`).setOne(m),h}function KT(e){let t=e.filter(e=>e.primaryKey);if(t.length)return t;let n=e.find(e=>e.typeRef.named===`ID`&&!e.typeRef.isList);if(n)return[n];let r=e.find(e=>e.name.toLowerCase()===`id`);return r?[r]:[]}function qT({toWidth:e},t,n,r,i,a){let{named:o,nonNull:s}=i.typeRef,c=Ch(i.name),l=Ch(i.dataType)||RT(o,n,t),u=Ch(i.default),d=JT(i,t,n);return kx({tableId:r,name:c,comment:d,dataType:l,default:u,options:(i.autoIncrement?L.autoIncrement:0)|(a?L.primaryKey:0)|(i.unique?L.unique:0)|(s?L.notNull:0),ui:{widthName:V(e(c)),widthComment:V(e(d)),widthDataType:V(e(l)),widthDefault:V(e(u)),keys:a?R.primaryKey:0}})}function JT(e,t,n){let{named:r,isList:i}=e.typeRef,a=[],o=Ch(e.comment);return o&&a.push(o),i&&a.push(`list of ${r}`),`${a.join(` `)}${zT(r,t,n)}`.trim()}function YT(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),j(e).collection(`tableColumnEntities`).setOne(n)}function XT(e,t,n){let r=WT(n),i=[];n.forEach(e=>{e.referenceFields.forEach(t=>{let n=r(t.typeRef.named);n&&i.push({source:e,target:n,field:t,consumed:!1})})});let a={claimedColumnIds:new Set,relationshipKeys:new Set},o=i.filter(e=>!e.field.typeRef.isList);[...o.filter(e=>e.field.relationFields.length),...o.filter(e=>!e.field.relationFields.length)].forEach(n=>{if(n.consumed)return;let r=ZT(i,n);n.consumed=!0,r&&(r.consumed=!0);let o=!!r?.field.typeRef.isList;$T(e,t,a,{parent:n.target,child:n.source,field:n.field,childSide:!0,relationshipType:n.field.typeRef.nonNull?o?Ym.OneN:Ym.OneOnly:o?Ym.ZeroN:Ym.ZeroOne})}),i.filter(e=>e.field.typeRef.isList).forEach(r=>{if(r.consumed)return;let o=QT(i,r);if(r.consumed=!0,o){o.consumed=!0,iE(e,t,n,r);return}$T(e,t,a,{parent:r.source,child:r.target,field:r.field,childSide:!1,relationshipType:r.field.typeRef.nonNull?Ym.OneN:Ym.ZeroN})})}function ZT(e,t){let n=e.filter(e=>e!==t&&!e.consumed&&e.source===t.target&&e.target===t.source);if(!n.length)return null;let{relationName:r}=t.field;if(r)return n.find(e=>e.field.relationName===r)??null;if(t.source===t.target)return n.length===1?n[0]:null;let i=e.filter(e=>!e.consumed&&e.source===t.source&&e.target===t.target);return n.length===1&&i.length===1?n[0]:null}function QT(e,t){if(e.some(e=>!e.field.typeRef.isList&&(e.source===t.source&&e.target===t.target||e.source===t.target&&e.target===t.source)))return null;let n=e.filter(e=>e!==t&&!e.consumed&&e.field.typeRef.isList&&e.source===t.target&&e.target===t.source);if(!n.length)return null;let{relationName:r}=t.field;return r?n.find(e=>e.field.relationName===r)??null:n[0]}function $T(e,t,n,r){let{doc:i,collections:a}=e,{parent:o,child:s,relationshipType:c}=r,l=BS(o.columns);if(!l.length)return;let{startColumns:u,endColumns:d}=eE(e,t,n,r,l);if(!d.length)return;let f=`${o.table.id}:${s.table.id}:${d.map(e=>e.id).join(`,`)}`;if(n.relationshipKeys.has(f))return;n.relationshipKeys.add(f),d.forEach(e=>{z(e.ui.keys,R.primaryKey)?e.ui.keys|=R.foreignKey:e.ui.keys=R.foreignKey,n.claimedColumnIds.add(e.id)});let p=Mb({identification:d.every(e=>z(e.ui.keys,R.primaryKey)&&z(e.ui.keys,R.foreignKey)),relationshipType:c,start:{tableId:o.table.id,columnIds:u.map(e=>e.id)},end:{tableId:s.table.id,columnIds:d.map(e=>e.id)}});i.relationshipIds.push(p.id),j(a).collection(`relationshipEntities`).setOne(p)}function eE(e,t,n,{parent:r,child:i,field:a,childSide:o},s){if(o&&a.relationFields.length){let e=[],t=[];if(a.relationFields.forEach((n,o)=>{let c=HS(i.columns,n),l=a.relationReferences[o],u=l?HS(r.columns,l):s[o]??null;!c||!u||(e.push(u),t.push(c))}),t.length)return{startColumns:e,endColumns:t}}let c=o?Ch(a.name):he(r.name),l=new Set,u=[],d=[];return s.forEach(o=>{let s=tE(c,r.name,o.name),f=nE(i.columns,s,e=>l.has(e)?!0:n.claimedColumnIds.has(e))??rE(e,t,i,a,o,s[0]);l.add(f.id),u.push(o),d.push(f)}),{startColumns:u,endColumns:d}}function tE(e,t,n){return[`${e}${g_(n)}`,`${be(e)}_${be(n)}`,`${t}${g_(n)}`,`${be(t)}_${be(n)}`,`${e}Id`,`${be(e)}_id`]}function nE(e,t,n){for(let r of t){let t=HS(e,r);if(t&&!n(t.id))return t}return null}function rE({collections:e},{toWidth:t},n,r,i,a){let o=VS(n.columns,``,a),{dataType:s}=i,c=kx({tableId:n.table.id,name:o,dataType:s,options:r.typeRef.nonNull?L.notNull:0,ui:{keys:R.foreignKey,widthName:V(t(o)),widthDataType:V(t(s))}});return YT(e,n,c),c}function iE(e,t,n,r){let{doc:i,collections:a}=e,{toWidth:o}=t,s=r.source,c=r.target,l=BS(s.columns),u=BS(c.columns);if(!l.length||!u.length)return;let d=VS(n.map(e=>e.table),``,`${s.name}_${c.name}`),f=`Junction table inferred from ${s.name} <-> ${c.name}`,p=Qb({name:d,comment:f,ui:{widthName:V(o(d)),widthComment:V(o(f))}}),m={name:d,source:{name:d,comment:f,fields:[],indexes:[]},table:p,columns:[],referenceFields:[]};i.tableIds.push(p.id),j(a).collection(`tableEntities`).setOne(p),n.push(m),aE(e,t,m,s,l),aE(e,t,m,c,u)}function aE(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=VS(n.columns,``,`${he(r.name)}${g_(e.name)}`),{dataType:a}=e,s=kx({tableId:n.table.id,name:i,dataType:a,options:L.primaryKey|L.notNull,ui:{keys:R.primaryKey|R.foreignKey,widthName:V(t(i)),widthDataType:V(t(a))}});return YT(o,n,s),s}),c=Mb({identification:!0,relationshipType:Ym.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),j(o).collection(`relationshipEntities`).setOne(c)}function oE({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{n.indexes.forEach(n=>{let a=Sy({name:Ch(n.name),tableId:r.id,unique:n.unique}),o=[];n.fieldNames.forEach(e=>{let t=HS(i,e);t&&o.push(zy({indexId:a.id,columnId:t.id,orderType:Zm.ASC}))}),o.length&&(o.forEach(e=>{a.indexColumnIds.push(e.id),a.seqIndexColumnIds.push(e.id),j(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(a.id),j(t).collection(`indexEntities`).setOne(a))})})}const sE=[`Query`,`Mutation`,`Subscription`],cE=[`PageInfo`],lE=[`Connection`,`Edge`],uE=[`_aggregate`,`_aggregate_fields`,`_mutation_response`,`_max_fields`,`_min_fields`,`_sum_fields`,`_avg_fields`,`_stddev_fields`,`_variance_fields`,`_bool_exp`,`_order_by`,`_insert_input`,`_set_input`,`_on_conflict`,`_constraint`,`_update_column`,`_select_column`],dE=[`_Service`,`_Entity`,`_Any`,`_FieldSet`],fE=[`autoincrement`,`autoincrement()`],pE=/[_A-Za-z]/,mE=/[_0-9A-Za-z]/;function hE(e){try{return{ok:!0,model:vE(gE(e))}}catch(e){return{ok:!1,message:_E(e)}}}function gE(e){try{return qe(e)}catch(t){let n=LE(e);if(n===e)throw t;try{return qe(n)}catch{throw t}}}function _E(e){let t=e instanceof Error?e.message:String(e),n=e?.locations?.[0];if(!n)return t;let r=t.replace(/^Syntax Error:\s*/,``);return`Syntax Error at line ${n.line}, column ${n.column}: ${r}`}function vE(e){let t={},n={},r=[],i=new Map,a=new Map,o=new Set;for(let s of e.definitions)switch(s.kind){case Ge.OBJECT_TYPE_DEFINITION:case Ge.OBJECT_TYPE_EXTENSION:bE(a,s);break;case Ge.INTERFACE_TYPE_DEFINITION:case Ge.INTERFACE_TYPE_EXTENSION:{let e=s.name.value,t=i.get(e)??[];t.push(...s.fields??[]),i.set(e,t);break}case Ge.SCHEMA_DEFINITION:case Ge.SCHEMA_EXTENSION:for(let e of s.operationTypes??[])o.add(e.type.name.value);break;case Ge.ENUM_TYPE_DEFINITION:t[s.name.value]=(s.values??[]).map(e=>e.name.value);break;case Ge.UNION_TYPE_DEFINITION:n[s.name.value]=(s.types??[]).map(e=>e.name.value);break;case Ge.SCALAR_TYPE_DEFINITION:r.push(s.name.value)}let s=o.size?o:new Set(sE),c=[],l=[],u=new Map;for(let e of a.values()){if(NE(e.name,s)){l.push(e.name);continue}let t=xE(e,i);if(!t.fields.length){l.push(e.name);continue}t.name!==e.name&&u.set(e.name,t.name),c.push(t)}return yE(c,u),{tables:c,enums:t,customScalars:r,unions:n,skipped:l}}function yE(e,t){if(t.size)for(let n of e)for(let e of n.fields){let n=t.get(e.typeRef.named);n&&(e.typeRef.named=n)}}function bE(e,t){let n=t.name.value,r=(t.interfaces??[]).map(e=>e.name.value),i=e.get(n);if(i){i.fieldNodes.push(...t.fields??[]),i.interfaceNames.push(...r),i.directives.push(...t.directives??[]),i.comment||=FE(t);return}e.set(n,{name:n,comment:FE(t),interfaceNames:r,fieldNodes:[...t.fields??[]],directives:[...t.directives??[]]})}function xE(e,t){let n=SE(e.fieldNodes),r=new Set(n.map(e=>e.name.value)),i=[];for(let n of e.interfaceNames)for(let e of t.get(n)??[]){let t=e.name.value;r.has(t)||(r.add(t),i.push(e))}let a={name:e.name,comment:e.comment,fields:[...i,...n].map(CE).filter(fe),indexes:[]};for(let t of e.directives)EE(a,t);return a}function SE(e){let t=new Set;return e.filter(e=>{let n=e.name.value;return!t.has(n)&&(t.add(n),!0)})}function CE(e){if(e.name.value.startsWith(`__`))return null;let t={name:e.name.value,comment:FE(e),typeRef:wE(e.type),primaryKey:!1,unique:!1,autoIncrement:!1,default:``,dataType:``,relationName:``,relationFields:[],relationReferences:[],hasArguments:(e.arguments??[]).length>0};for(let n of e.directives??[])TE(t,n);return t}function wE(e){let t=e.kind===Ge.NON_NULL_TYPE,n=t?e.type:e,r=n.kind===Ge.LIST_TYPE,i=r?n.type:n,a=r&&i.kind===Ge.NON_NULL_TYPE,o=i;for(;o.kind!==Ge.NAMED_TYPE;)o=o.type;return{named:o.name.value,nonNull:t,isList:r,itemNonNull:a}}function TE(e,t){let n=t.name.value;if(n.startsWith(`db_`)){e.dataType=DE(n,t);return}switch(n){case`id`:case`primaryKey`:e.primaryKey=!0;break;case`unique`:e.unique=!0;break;case`autoincrement`:case`autoIncrement`:e.autoIncrement=!0;break;case`default`:{let n=OE(t,`value`);if(!n)break;let r=jE(n);fE.includes(r.toLowerCase())?e.autoIncrement=!0:e.default=r;break}case`map`:{let n=kE(t,`name`)||kE(t,`value`);n&&(e.name=n);break}case`relation`:{let n=kE(t,`name`)||kE(t,`value`);n&&(e.relationName=n);let r=OE(t,`fields`);r&&(e.relationFields=ME(r));let i=OE(t,`references`);i&&(e.relationReferences=ME(i));break}case`column`:{let n=kE(t,`name`);n&&(e.name=n);let r=kE(t,`dataType`);r&&(e.dataType=r);let i=OE(t,`default`);i&&(e.default=jE(i));let a=AE(t,`autoIncrement`);a!==null&&(e.autoIncrement=a);let o=AE(t,`unique`);o!==null&&(e.unique=o);let s=AE(t,`primaryKey`);s!==null&&(e.primaryKey=s);break}}}function EE(e,t){switch(t.name.value){case`map`:{let n=kE(t,`name`)||kE(t,`value`);n&&(e.name=n);break}case`table`:{let n=kE(t,`name`);n&&(e.name=n);let r=OE(t,`comment`);r&&(e.comment=jE(r));break}case`index`:{let n=OE(t,`fields`),r=n?ME(n):[];if(!r.length)break;let i={name:kE(t,`name`),unique:AE(t,`unique`)??!1,fieldNames:r};e.indexes.push(i);break}}}function DE(e,t){let n=e.slice(3),r=t.arguments??[];return r.length?`${n}(${r.map(e=>jE(e.value)).join(`, `)})`:n}function OE(e,t){let n=(e.arguments??[]).find(e=>e.name.value===t);return n?n.value:null}function kE(e,t){let n=OE(e,t);return n?jE(n):``}function AE(e,t){let n=OE(e,t);return n?jE(n)===`true`:null}function jE(e){switch(e.kind){case Ge.STRING:case Ge.INT:case Ge.FLOAT:case Ge.ENUM:return e.value;case Ge.BOOLEAN:return e.value?`true`:`false`;case Ge.NULL:return`null`;case Ge.LIST:return e.values.map(jE).join(`, `);default:return``}}function ME(e){return(e.kind===Ge.LIST?e.values:[e]).map(jE).filter(e=>e!==``)}function NE(e,t){return t.has(e)||e.startsWith(`__`)||dE.includes(e)||cE.includes(e)||lE.some(t=>PE(e,t))||uE.some(t=>PE(e,t))}function PE(e,t){return e.length>t.length&&e.endsWith(t)}function FE(e){if(e.description)return IE(e.description.value);if(!e.loc)return``;let t=[],n=e.loc.startToken.line-1,r=e.loc.startToken.prev;for(;r&&r.kind===Ke.COMMENT&&r.line===n&&(!r.prev||r.prev.line<r.line);)t.unshift(r.value??``),--n,r=r.prev;return IE(t.join(` `))}function IE(e){return e.replace(/\s+/g,` `).trim()}function LE(e){let t=``,n=0,r=!1;for(;n<e.length;){let i=e[n];if(i===`#`){let r=BE(e,n);t+=e.slice(n,r),n=r;continue}if(i===`"`){let r=VE(e,n);t+=e.slice(n,r),n=r;continue}if(i!==`@`||!pE.test(e[n+1]??``)){t+=i,n+=1;continue}let a=zE(e,n+1),o=e.slice(n+1,a);for(;e[a]===`.`&&pE.test(e[a+1]??``);){let t=zE(e,a+1);o+=`_${e.slice(a+1,t)}`,a=t,r=!0}t+=`@${o}`,n=a;let s=UE(e,n);if(e[s]===`(`){t+=e.slice(n,s+1),n=s+1;for(let i=0;n<e.length;i++){let a=UE(e,n);if(t+=e.slice(n,a),n=a,e[n]===`)`||n>=e.length)break;let o=RE(e,n);o===-1?(t+=i===0?`value: `:`value${i}: `,r=!0):(t+=e.slice(n,o+1),n=o+1);let s=Math.max(HE(e,UE(e,n)),n+1);t+=e.slice(n,s),n=s}}}return r?t:e}function RE(e,t){if(!pE.test(e[t]??``))return-1;let n=UE(e,zE(e,t));return e[n]===`:`?n:-1}function zE(e,t){let n=t;for(;n<e.length&&mE.test(e[n]);)n+=1;return n}function BE(e,t){let n=e.indexOf(`
|
|
24
|
-
`,t);return n===-1?e.length:n}function
|
|
25
|
-
`)return n;if(t===`"`)return n+1;n+=1}return n}function
|
|
26
|
-
`,singleQuote:`'`,backtick:"`",whiteSpace:/\s/,string:/\S/,breakString:/;|,|\(|\)|\[|\]|\.|=/,equal:`=`,period:`.`,comma:`,`,semicolon:`;`,leftParent:`(`,rightParent:`)`,leftBracket:`[`,rightBracket:`]`},XE=e=>t=>e===t,ZE=e=>t=>e.test(t),Z={doubleQuote:XE(YE.doubleQuote),dash:XE(YE.dash),slash:XE(YE.slash),asterisk:XE(YE.asterisk),newLine:XE(YE.newLine),singleQuote:XE(YE.singleQuote),backtick:XE(YE.backtick),whiteSpace:ZE(YE.whiteSpace),string:ZE(YE.string),breakString:ZE(YE.breakString),equal:XE(YE.equal),period:XE(YE.period),comma:XE(YE.comma),semicolon:XE(YE.semicolon),leftParent:XE(YE.leftParent),rightParent:XE(YE.rightParent),leftBracket:XE(YE.leftBracket),rightBracket:XE(YE.rightBracket)};function QE(e){let t=[],n=0,r=()=>n<e.length;for(;r();){let i=e[n];if(Z.whiteSpace(i)){let t=``;for(;r()&&Z.whiteSpace(i);)t+=i,i=e[++n];continue}if(Z.dash(i)&&Z.dash(e[n+1])){for(;r()&&!Z.newLine(i);)i=e[++n];continue}if(Z.slash(i)&&Z.asterisk(e[n+1])){for(n+=2,i=e[n];r()&&!(Z.asterisk(i)&&Z.slash(e[n+1]));)i=e[++n];n+=2;continue}if(Z.leftParent(i)){t.push({type:JE.leftParent,value:i}),n++;continue}if(Z.rightParent(i)){t.push({type:JE.rightParent,value:i}),n++;continue}if(Z.comma(i)){t.push({type:JE.comma,value:i}),n++;continue}if(Z.period(i)){t.push({type:JE.period,value:i}),n++;continue}if(Z.equal(i)){t.push({type:JE.equal,value:i}),n++;continue}if(Z.semicolon(i)){t.push({type:JE.semicolon,value:i}),n++;continue}if(Z.rightBracket(i)){t.push({type:JE.rightBracket,value:i}),n++;continue}if(Z.leftBracket(i)){let a=``;for(i=e[++n];r()&&!Z.rightBracket(i);)a+=i,i=e[++n];t.push({type:JE.string,value:a,quoted:!0}),n++;continue}if(Z.doubleQuote(i)){let a=``;for(i=e[++n];r()&&!Z.doubleQuote(i);)a+=i,i=e[++n];t.push({type:JE.string,value:a,quoted:!0}),n++;continue}if(Z.singleQuote(i)){let a=``;for(i=e[++n];r()&&!Z.singleQuote(i);)a+=i,i=e[++n];t.push({type:JE.string,value:a,quoted:!0}),n++;continue}if(Z.backtick(i)){let a=``;for(i=e[++n];r()&&!Z.backtick(i);)a+=i,i=e[++n];t.push({type:JE.string,value:a,quoted:!0}),n++;continue}if(Z.string(i)){let a=``;for(;r()&&Z.string(i)&&!Z.breakString(i)&&!(Z.dash(i)&&Z.dash(e[n+1]))&&!(Z.slash(i)&&Z.asterisk(e[n+1]));)a+=i,i=e[++n];t.push({type:JE.string,value:a});continue}n++}return t}var $E=`ARRAY.BIGINT.BINARY.BOOLEAN.BYTE.CHAR.DATE.DEC.DECIMAL.DOUBLE.FLOAT.GEOGRAPHY.GEOMETRY.INT.INTEGER.INTERVAL DAY TO HOUR.INTERVAL DAY TO MINUTE.INTERVAL DAY TO SECOND.INTERVAL DAY.INTERVAL HOUR TO MINUTE.INTERVAL HOUR TO SECOND.INTERVAL HOUR.INTERVAL MINUTE TO SECOND.INTERVAL MINUTE.INTERVAL MONTH.INTERVAL SECOND.INTERVAL YEAR TO MONTH.INTERVAL YEAR.INTERVAL.LONG.MAP.NUMERIC.OBJECT.REAL.SHORT.SMALLINT.STRING.STRUCT.TIMESTAMP_LTZ.TIMESTAMP_NTZ.TIMESTAMP.TINYINT.VARCHAR.VARIANT.VOID`.split(`.`),eD=`BIGINT.BINARY.BIT.BLOB.BOOL.BOOLEAN.CHAR BYTE.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.CLOB.DATE.DATETIME.DEC.DECIMAL.DOUBLE PRECISION.DOUBLE.ENUM.FIXED.FLOAT.FLOAT4.FLOAT8.GEOMETRY.GEOMETRYCOLLECTION.INET4.INET6.INT.INT1.INT2.INT3.INT4.INT8.INTEGER.JSON.LINESTRING.LONG CHAR VARYING.LONG CHARACTER VARYING.LONG VARBINARY.LONG VARCHAR.LONG VARCHARACTER.LONG.LONGBLOB.LONGTEXT.MEDIUMBLOB.MEDIUMINT.MEDIUMTEXT.MIDDLEINT.MULTILINESTRING.MULTIPOINT.MULTIPOLYGON.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL VARCHAR.NATIONAL VARCHARACTER.NCHAR VARCHAR.NCHAR VARCHARACTER.NCHAR VARYING.NCHAR.NUMBER.NUMERIC.NVARCHAR.POINT.POLYGON.RAW.REAL.SERIAL.SET.SMALLINT.SQL_TSI_YEAR.TEXT.TIME.TIMESTAMP.TINYBLOB.TINYINT.TINYTEXT.UUID.VARBINARY.VARCHAR.VARCHAR2.VARCHARACTER.VECTOR.XMLTYPE.YEAR`.split(`.`),tD=`BIGINT.BINARY VARYING.BINARY.BIT.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.DATE.DATETIME.DATETIME2.DATETIMEOFFSET.DEC.DECIMAL.DOUBLE PRECISION.FLOAT.GEOGRAPHY.GEOMETRY.HIERARCHYID.IMAGE.INT.INTEGER.JSON.MONEY.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL TEXT.NCHAR.NTEXT.NUMERIC.NVARCHAR.REAL.ROWVERSION.SMALLDATETIME.SMALLINT.SMALLMONEY.SQL_VARIANT.TEXT.TIME.TIMESTAMP.TINYINT.UNIQUEIDENTIFIER.VARBINARY.VARCHAR.VECTOR.XML`.split(`.`),nD=`BIGINT.BINARY.BIT.BLOB.BOOL.BOOLEAN.CHAR BYTE.CHAR.CHARACTER VARYING.CHARACTER.DATE.DATETIME.DEC.DECIMAL.DOUBLE PRECISION.DOUBLE.ENUM.FIXED.FLOAT.FLOAT4.FLOAT8.GEOMCOLLECTION.GEOMETRY.GEOMETRYCOLLECTION.INT.INT1.INT2.INT3.INT4.INT8.INTEGER.JSON.LINESTRING.LONG VARBINARY.LONG VARCHAR.LONG.LONGBLOB.LONGTEXT.MEDIUMBLOB.MEDIUMINT.MEDIUMTEXT.MIDDLEINT.MULTILINESTRING.MULTIPOINT.MULTIPOLYGON.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL VARCHAR.NCHAR VARCHAR.NCHAR.NUMERIC.NVARCHAR.POINT.POLYGON.REAL.SERIAL.SET.SMALLINT.TEXT.TIME.TIMESTAMP.TINYBLOB.TINYINT.TINYTEXT.VARBINARY.VARCHAR.VARCHARACTER.YEAR`.split(`.`),rD=`ANYDATA.BFILE.BINARY_DOUBLE.BINARY_FLOAT.BLOB.BOOL.BOOLEAN.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.CLOB.DATE.DEC.DECIMAL.DOUBLE PRECISION.FLOAT.INT.INTEGER.INTERVAL DAY TO SECOND.INTERVAL YEAR TO MONTH.JSON.LONG RAW.LONG VARCHAR.LONG.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NCHAR VARYING.NCHAR.NCLOB.NUMBER.NUMERIC.NVARCHAR2.RAW.REAL.ROWID.SDO_GEOMETRY.SDO_GEORASTER.SDO_TOPO_GEOMETRY.SMALLINT.TIMESTAMP WITH LOCAL TIME ZONE.TIMESTAMP WITH TIME ZONE.TIMESTAMP.URIType.UROWID.VARCHAR.VARCHAR2.VECTOR.XMLType`.split(`.`),iD=`BIGINT.BIGSERIAL.BIT VARYING.BIT.BOOL.BOOLEAN.BOX.BPCHAR.BYTEA.CHAR.CHARACTER VARYING.CHARACTER.CID.CIDR.CIRCLE.DATE.DATEMULTIRANGE.DATERANGE.DECIMAL.DOUBLE PRECISION.FLOAT.FLOAT4.FLOAT8.INET.INT.INT2.INT4.INT4MULTIRANGE.INT4RANGE.INT8.INT8MULTIRANGE.INT8RANGE.INTEGER.INTERVAL DAY TO HOUR.INTERVAL DAY TO MINUTE.INTERVAL DAY TO SECOND.INTERVAL DAY.INTERVAL HOUR TO MINUTE.INTERVAL HOUR TO SECOND.INTERVAL HOUR.INTERVAL MINUTE TO SECOND.INTERVAL MINUTE.INTERVAL MONTH.INTERVAL SECOND.INTERVAL YEAR TO MONTH.INTERVAL YEAR.INTERVAL.JSON.JSONB.JSONPATH.LINE.LSEG.MACADDR.MACADDR8.MONEY.NAME.NUMERIC.NUMMULTIRANGE.NUMRANGE.OID.PATH.PG_LSN.PG_SNAPSHOT.POINT.POLYGON.REAL.REGCLASS.REGCOLLATION.REGCONFIG.REGDICTIONARY.REGNAMESPACE.REGOPER.REGOPERATOR.REGPROC.REGPROCEDURE.REGROLE.REGTYPE.SERIAL.SERIAL2.SERIAL4.SERIAL8.SMALLINT.SMALLSERIAL.TEXT.TID.TIME WITH TIME ZONE.TIME WITHOUT TIME ZONE.TIME.TIMESTAMP WITH TIME ZONE.TIMESTAMP WITHOUT TIME ZONE.TIMESTAMP.TIMESTAMPTZ.TIMETZ.TSMULTIRANGE.TSQUERY.TSRANGE.TSTZMULTIRANGE.TSTZRANGE.TSVECTOR.TXID_SNAPSHOT.UUID.VARBIT.VARCHAR.XID.XID8.XML`.split(`.`),aD=`ARRAY.BIGINT.BINARY.BOOLEAN.BYTEINT.CHAR VARYING.CHAR.CHARACTER.DATE.DATETIME.DEC.DECFLOAT.DECIMAL.DOUBLE PRECISION.DOUBLE.FILE.FLOAT.FLOAT4.FLOAT8.GEOGRAPHY.GEOMETRY.INT.INTEGER.MAP.NCHAR VARYING.NCHAR.NUMBER.NUMERIC.NVARCHAR.NVARCHAR2.OBJECT.REAL.SMALLINT.STRING.TEXT.TIME.TIMESTAMP WITH LOCAL TIME ZONE.TIMESTAMP WITH TIME ZONE.TIMESTAMP WITHOUT TIME ZONE.TIMESTAMP_LTZ.TIMESTAMP_NTZ.TIMESTAMP_TZ.TIMESTAMP.TIMESTAMPLTZ.TIMESTAMPNTZ.TIMESTAMPTZ.TINYINT.UNKNOWN.UUID.VARBINARY.VARCHAR.VARCHAR2.VARIANT.VECTOR`.split(`.`),oD=`BIGINT.BLOB.BOOLEAN.CHARACTER.CLOB.DATE.DATETIME.DECIMAL.DOUBLE PRECISION.DOUBLE.FLOAT.INT.INT2.INT8.INTEGER.MEDIUMINT.NATIVE CHARACTER.NCHAR.NUMERIC.NVARCHAR.REAL.SMALLINT.TEXT.TINYINT.UNSIGNED BIG INT.VARCHAR.VARYING CHARACTER`.split(`.`),sD=e=>t=>n=>t[n]?t[n].type===e:!1,Q=e=>{let t=e.toUpperCase();return e=>n=>{let r=e[n];return r?!r.quoted&&r.value.toUpperCase()===t:!1}},cD=sD(JE.string),lD=sD(JE.equal),uD=sD(JE.period),dD=sD(JE.comma),fD=sD(JE.semicolon),pD=sD(JE.leftParent),mD=sD(JE.rightParent);JE.leftBracket,JE.rightBracket;var hD=Q(`CREATE`),gD=Q(`ALTER`),_D=Q(`DROP`),vD=Q(`USE`),yD=Q(`RENAME`),bD=Q(`DELETE`),xD=Q(`SELECT`),SD=Q(`TABLE`),CD=Q(`INDEX`),wD=Q(`UNIQUE`),TD=Q(`ADD`),ED=Q(`PRIMARY`),DD=Q(`KEY`),OD=Q(`CONSTRAINT`),kD=Q(`FOREIGN`),AD=Q(`NOT`),jD=Q(`NULL`),MD=Q(`DEFAULT`),ND=Q(`COMMENT`),PD=Q(`REFERENCES`),FD=Q(`ASC`),ID=Q(`DESC`),LD=Q(`ON`),RD=Q(`AUTO_INCREMENT`),zD=Q(`AUTOINCREMENT`),BD=Q(`IF`),VD=Q(`EXISTS`),HD=Q(`ONLY`),UD=Q(`IS`),WD=Q(`COLUMN`),GD=Q(`CHARACTER`),KD=Q(`SET`),qD=Q(`COLLATE`),JD=Q(`ENFORCED`),YD=Q(`RELY`),XD=Q(`NORELY`),ZD=Q(`DEFERRABLE`),QD=Q(`INITIALLY`),$D=Q(`DEFERRED`),eO=Q(`IMMEDIATE`),tO=Q(`IDENTITY`),nO=Q(`FUNCTION`),rO=Q(`CLUSTER`),iO=Q(`BY`),aO=e=>{let t=JD(e),n=YD(e),r=XD(e),i=ZD(e),a=QD(e),o=$D(e),s=eO(e);return e=>t(e)||n(e)||r(e)||i(e)||a(e)||o(e)||s(e)},oO=[`ARRAY`,`MAP`,`STRUCT`],sO=e=>{let t=cD(e),n=e=>{let t=0;for(let n of e)n===`<`?t++:n===`>`&&t--;return t};return r=>{let i=e[r];if(!i||i.quoted||!t(r))return 0;let a=i.value.indexOf(`<`);if(a===-1||!oO.includes(i.value.slice(0,a).toUpperCase()))return 0;let o=0;for(let t=r;t<e.length;t++)if(o+=n(e[t].value),o<=0)return t-r+1;return e.length-r}},cO=e=>{let t=RD(e),n=zD(e),r=tO(e);return e=>t(e)||n(e)||r(e)},lO=e=>{let t=rO(e),n=iO(e);return e=>t(e)&&n(e+1)},uO=e=>{let t=ND(e),n=LD(e);return e=>t(e)&&n(e+1)},dO=e=>{let t=uO(e),n=SD(e);return e=>t(e)&&n(e+2)},fO=e=>{let t=uO(e),n=WD(e);return e=>t(e)&&n(e+2)},pO=e=>{let t=hD(e),n=gD(e),r=_D(e),i=vD(e),a=yD(e),o=bD(e),s=xD(e),c=uO(e);return e=>t(e)||n(e)||r(e)||i(e)||a(e)||o(e)||s(e)||c(e)},mO=[`OR`,`REPLACE`,`TRANSIENT`,`TEMPORARY`,`TEMP`,`LOCAL`,`GLOBAL`,`VOLATILE`,`UNLOGGED`,`HYBRID`,`ICEBERG`,`DYNAMIC`,`EXTERNAL`],hO=e=>{let t=hD(e),n=SD(e),r=cD(e),i=nO(e),a=BD(e),o=AD(e),s=VD(e);return c=>{if(!t(c))return 0;let l=c+1;for(;l<e.length&&!n(l);){let t=e[l];if(!r(l)||t.quoted||!mO.includes(t.value.toUpperCase()))return 0;l++}return!n(l)||i(l+1)?0:(l++,a(l)&&o(l+1)&&s(l+2)&&(l+=3),l-c)}},gO=e=>{let t=GD(e),n=KD(e);return e=>t(e)&&n(e+1)},_O=e=>{let t=hO(e);return e=>t(e)>0},vO=e=>{let t=hD(e),n=CD(e),r=wD(e);return e=>t(e)&&r(e+1)&&n(e+2)},yO=e=>{let t=hD(e),n=CD(e),r=vO(e);return e=>t(e)&&n(e+1)||r(e)},bO=e=>{let t=gD(e),n=SD(e);return e=>t(e)&&n(e+1)},xO=e=>{let t=cD(e),n=uD(e);return e=>{if(!t(e))return 0;let r=e+1;for(;n(r)&&t(r+1);)r+=2;return r-e}},SO=e=>{let t=bO(e),n=HD(e),r=TD(e),i=OD(e),a=cD(e),o=xO(e),s=(e,t)=>{let n=t,s=o(n);return!s||(n+=s,!r(n))?0:(n++,i(n)&&a(n+1)&&(n+=2),n-e)};return e=>{if(!t(e))return{length:0,only:!1};let r=e+2;if(n(r)){let t=s(e,r+1);if(t)return{length:t,only:!0}}return{length:s(e,r),only:!1}}},CO=e=>{let t=SO(e);return e=>t(e).length},wO=e=>{let t=SO(e);return e=>t(e).only},TO=e=>{let t=CO(e),n=ED(e),r=DD(e);return e=>{let i=t(e);return i>0&&n(e+i)&&r(e+i+1)}},EO=e=>{let t=CO(e),n=kD(e),r=DD(e);return e=>{let i=t(e);return i>0&&n(e+i)&&r(e+i+1)}},DO=e=>{let t=CO(e),n=wD(e);return e=>{let r=t(e);return r>0&&n(e+r)}},OO=Array.from(new Set([...$E,...eD,...tD,...nD,...rD,...iD,...aD,...oD].map(e=>e.toUpperCase()))),kO=(e=>{let t=new Map;for(let n of e){let e=n.split(` `),r=t.get(e[0])??[];r.push(e),t.set(e[0],r)}for(let e of t.values())e.sort((e,t)=>t.length-e.length);return t})(OO),AO=e=>{let t=cD(e),n=pD(e),r=mD(e),i=t=>{let i=0;for(let a=t;a<e.length;a++)if(n(a))i++;else if(r(a)&&(i--,i===0))return a+1;return e.length},a=(r,a)=>{let o=r;for(let[r,s]of a.entries()){let a=e[o];if(!a||!t(o)||r>0&&a.quoted||a.value.toUpperCase()!==s)return 0;o++,n(o)&&(o=i(o))}return o-r};return n=>{let r=e[n];if(!r||!t(n))return 0;let i=r.value.toUpperCase();for(let e of kO.get(i)??[]){let t=a(n,e);if(t)return t}return+!!OO.includes(i)}};function jO(e,t){let n=pO(e),r=cD(e),i=pD(e),a=mD(e),o=uD(e),s=fD(e),c=lD(e),l=ND(e),u=lO(e),d=hO(e),f=()=>t.value<e.length,p={type:KE.createTable,name:``,comment:``,columns:[],indexes:[],foreignKeys:[]},m=d(t.value);t.value+=m===0?2:m;let h=!1,g=!0;for(;f()&&!n(t.value);){let n=e[t.value];if(s(t.value)){t.value++;break}if(p.name&&u(t.value)){if(t.value+=2,r(t.value)&&i(t.value+1)&&t.value++,i(t.value)){let e=0;for(;f();){if(i(t.value))e++;else if(a(t.value)&&(e--,e===0)){t.value++;break}t.value++}}continue}if(i(t.value)){if(t.value++,h||!g){let e=1;for(;f()&&e>0;)i(t.value)?e++:a(t.value)&&e--,t.value++;continue}let{columns:n,indexes:r,foreignKeys:o}=MO(e,t);p.columns=n,p.indexes=r,p.foreignKeys=o,h=!0;continue}if(r(t.value)&&!p.name){for(p.name=n.value,g=!0,t.value++;o(t.value);){if(!r(t.value+1)){t.value++;break}p.name=e[t.value+1].value,t.value+=2}continue}if(l(t.value)){n=e[++t.value],c(t.value)&&(n=e[++t.value]),r(t.value)&&(p.comment=n.value,t.value++),g=!1;continue}g=!1,t.value++}return p}function MO(e,t){let n=cD(e),r=pD(e),i=mD(e),a=dD(e),o=OD(e),s=CD(e),c=ED(e),l=kD(e),u=cO(e),d=wD(e),f=jD(e),p=AD(e),m=MD(e),h=ND(e),g=ID(e),ee=FD(e),_=DD(e),te=lD(e),ne=gO(e),re=qD(e),ie=aO(e),ae=AO(e),oe=sO(e),se=()=>t.value<e.length,ce=[],le=[],ue=[],de=[],v=[],fe={name:``,dataType:``,default:``,comment:``,primaryKey:!1,autoIncrement:!1,unique:!1,nullable:!0};for(;se();){let y=e[t.value],pe=oe(t.value);if(pe){let n=t.value+pe,r=[];for(;t.value<n;)r.push(a(t.value)?`,`:e[t.value].value),t.value++;fe.dataType=r.reduce((e,t)=>!e||t===`,`?e+t:`${e} ${t}`,``);continue}if(n(t.value)&&!fe.name&&!o(t.value)&&!c(t.value)&&!l(t.value)&&!d(t.value)&&!s(t.value)&&!_(t.value)&&!p(t.value)&&!ie(t.value)){fe.name=y.value,t.value++;continue}if(r(t.value)){let e=0;for(;se();){if(r(t.value))e++;else if(i(t.value)&&(e--,e===0)){t.value++;break}t.value++}continue}if(o(t.value)){y=e[++t.value],n(t.value)&&t.value++;continue}if(c(t.value)){if(y=e[++t.value],_(t.value)){if(y=e[++t.value],r(t.value)){for(y=e[++t.value];se()&&!i(t.value);)n(t.value)&&de.push(y.value.toUpperCase()),y=e[++t.value];t.value++}else fe.primaryKey=!0}continue}if(l(t.value)){let n=NO(e,t);n&&ue.push(n);continue}if(s(t.value)||_(t.value)){if(y=e[++t.value],n(t.value)){let o=y.value,s=[];if(y=e[++t.value],r(t.value)){y=e[++t.value];let r={name:``,sort:qE.asc};for(;se()&&!i(t.value);)n(t.value)&&!g(t.value)&&!ee(t.value)&&(r.name=y.value),g(t.value)&&(r.sort=qE.desc),a(t.value)&&(s.push(r),r={name:``,sort:qE.asc}),y=e[++t.value];!s.includes(r)&&r.name!==``&&s.push(r),s.length&&le.push({name:o,unique:!1,columns:s}),t.value++}}continue}if(d(t.value)){if(y=e[++t.value],_(t.value)&&(y=e[++t.value]),n(t.value)&&(y=e[++t.value]),r(t.value)){for(y=e[++t.value];se()&&!i(t.value);)n(t.value)&&v.push(y.value.toUpperCase()),y=e[++t.value];t.value++}else fe.unique=!0;continue}if(p(t.value)){y=e[++t.value],f(t.value)?(fe.nullable=!1,t.value++):ie(t.value)&&t.value++;continue}if(ie(t.value)){t.value++;continue}if(m(t.value)){y=e[++t.value],n(t.value)&&(fe.default=y.value,t.value++);continue}if(h(t.value)){y=e[++t.value],te(t.value)&&(y=e[++t.value]),n(t.value)&&(fe.comment=y.value,t.value++);continue}if(u(t.value)){fe.autoIncrement=!0,t.value++;continue}if(ne(t.value)){t.value+=2,n(t.value)&&t.value++;continue}if(re(t.value)){t.value++,te(t.value)&&t.value++,n(t.value)&&t.value++;continue}let b=ae(t.value);if(b){let a=t.value+b,o=``,s=0;for(;t.value<a;)y=e[t.value],r(t.value)?(o+=`(`,s++):i(t.value)?(o+=`)`,s--):o+=s?n(t.value)&&(n(t.value-1)||i(t.value-1))?` ${y.value}`:y.value:o?` ${y.value}`:y.value,t.value++;for(;s>0;)o+=`)`,s--;fe.dataType=o;continue}if(a(t.value)){(fe.name||fe.dataType)&&ce.push(fe),fe={name:``,dataType:``,default:``,comment:``,primaryKey:!1,autoIncrement:!1,unique:!1,nullable:!0},t.value++;continue}if(i(t.value)){t.value++;break}t.value++}return!ce.includes(fe)&&(fe.name||fe.dataType)&&ce.push(fe),ce.forEach(e=>{de.includes(e.name.toUpperCase())&&(e.primaryKey=!0),v.includes(e.name.toUpperCase())&&(e.unique=!0)}),{columns:ce,indexes:le,foreignKeys:ue}}function NO(e,t){let n=cD(e),r=pD(e),i=mD(e),a=PD(e),o=uD(e),s=DD(e),c=()=>t.value<e.length,l={columnNames:[],refTableName:``,refColumnNames:[]},u=e[++t.value];if(s(t.value)){if(u=e[++t.value],r(t.value)){for(u=e[++t.value];c()&&!i(t.value);)n(t.value)&&l.columnNames.push(u.value),u=e[++t.value];u=e[++t.value]}if(a(t.value)&&(u=e[++t.value],n(t.value))){for(l.refTableName=u.value,t.value++;o(t.value);){if(!n(t.value+1)){t.value++;break}l.refTableName=e[t.value+1].value,t.value+=2}if(u=e[t.value],r(t.value)){for(u=e[++t.value];c()&&!i(t.value);)n(t.value)&&l.refColumnNames.push(u.value),u=e[++t.value];u=e[++t.value]}}if(l.columnNames.length&&l.columnNames.length===l.refColumnNames.length)return l}return null}function PO(e,t){let n=pO(e),r=fD(e),i=cD(e),a=OD(e),o=uD(e),s=SD(e),c=kD(e),l=wO(e)(t.value),u=()=>t.value<e.length,d={type:KE.alterTableAddForeignKey,name:``,columnNames:[],refTableName:``,refColumnNames:[]};for(t.value++;u()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(s(t.value)){if(n=e[++t.value],l&&(n=e[++t.value]),i(t.value))for(d.name=n.value,t.value++;o(t.value);){if(!i(t.value+1)){t.value++;break}d.name=e[t.value+1].value,t.value+=2}continue}if(a(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){let n=NO(e,t);n&&(d.columnNames=n.columnNames,d.refTableName=n.refTableName,d.refColumnNames=n.refColumnNames);continue}t.value++}return d}function FO(e,t){let n=pO(e),r=fD(e),i=cD(e),a=pD(e),o=mD(e),s=OD(e),c=ED(e),l=uD(e),u=DD(e),d=SD(e),f=wO(e)(t.value),p=()=>t.value<e.length,m={type:KE.alterTableAddPrimaryKey,name:``,columnNames:[]};for(t.value++;p()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(d(t.value)){if(n=e[++t.value],f&&(n=e[++t.value]),i(t.value))for(m.name=n.value,t.value++;l(t.value);){if(!i(t.value+1)){t.value++;break}m.name=e[t.value+1].value,t.value+=2}continue}if(s(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){if(n=e[++t.value],u(t.value)&&(n=e[++t.value],a(t.value))){for(n=e[++t.value];p()&&!o(t.value);)i(t.value)&&m.columnNames.push(n.value),n=e[++t.value];n=e[++t.value]}continue}t.value++}return m}function IO(e,t){let n=pO(e),r=fD(e),i=cD(e),a=OD(e),o=uD(e),s=SD(e),c=wD(e),l=pD(e),u=mD(e),d=wO(e)(t.value),f=()=>t.value<e.length,p={type:KE.alterTableAddUnique,name:``,columnNames:[]};for(t.value++;f()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(s(t.value)){if(n=e[++t.value],d&&(n=e[++t.value]),i(t.value))for(p.name=n.value,t.value++;o(t.value);){if(!i(t.value+1)){t.value++;break}p.name=e[t.value+1].value,t.value+=2}continue}if(a(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){if(n=e[++t.value],l(t.value)){for(n=e[++t.value];f()&&!u(t.value);)i(t.value)&&p.columnNames.push(n.value),n=e[++t.value];t.value++}continue}t.value++}return p}function LO(e,t){let n=pO(e),r=cD(e),i=uD(e),a=fD(e),o=UD(e),s=jD(e),c=()=>t.value<e.length,l={type:KE.commentOnColumn,tableName:``,columnName:``,comment:``};t.value+=3;let u=[],d=!1;for(;c()&&!n(t.value);){let n=e[t.value];if(a(t.value)){t.value++;break}if(o(t.value)){if(d=!0,n=e[++t.value],s(t.value)){t.value++;continue}r(t.value)&&(l.comment=n.value,t.value++);continue}if(i(t.value)){t.value++;continue}if(r(t.value)&&!d){u.push(n.value),t.value++;continue}t.value++}return l.columnName=u.length?u[u.length-1]:``,l.tableName=u.length>1?u[u.length-2]:``,l}function RO(e,t){let n=pO(e),r=cD(e),i=uD(e),a=fD(e),o=UD(e),s=jD(e),c=()=>t.value<e.length,l={type:KE.commentOnTable,name:``,comment:``};t.value+=3;let u=!1;for(;c()&&!n(t.value);){let n=e[t.value];if(a(t.value)){t.value++;break}if(o(t.value)){if(u=!0,n=e[++t.value],s(t.value)){t.value++;continue}r(t.value)&&(l.comment=n.value,t.value++);continue}if(i(t.value)){t.value++;continue}if(r(t.value)&&!u){l.name=n.value,t.value++;continue}t.value++}return l}function zO(e,t){let n=pO(e),r=fD(e),i=wD(e),a=cD(e),o=pD(e),s=mD(e),c=dD(e),l=CD(e),u=LD(e),d=ID(e),f=FD(e),p=vO(e),m=()=>t.value<e.length,h={type:KE.createIndex,name:``,unique:i(t.value+1),tableName:``,columns:[]};for(t.value+=p(t.value)?2:1;m()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(l(t.value)){n=e[++t.value],a(t.value)&&(h.name=n.value);continue}if(u(t.value)){if(n=e[++t.value],a(t.value)&&(h.tableName=n.value,n=e[++t.value],o(t.value))){n=e[++t.value];let r={name:``,sort:qE.asc};for(;m()&&!s(t.value);)a(t.value)&&!d(t.value)&&!f(t.value)&&(r.name=n.value),d(t.value)&&(r.sort=qE.desc),c(t.value)&&(h.columns.push(r),r={name:``,sort:qE.asc}),n=e[++t.value];!h.columns.includes(r)&&r.name!==``&&h.columns.push(r),t.value++}continue}t.value++}return h}function BO(e){let t=[],n={value:0},r=()=>n.value<e.length,i=_O(e),a=yO(e),o=TO(e),s=EO(e),c=DO(e),l=dO(e),u=fO(e);for(;r();){if(i(n.value)){t.push(jO(e,n));continue}if(a(n.value)){t.push(zO(e,n));continue}if(o(n.value)){t.push(FO(e,n));continue}if(s(n.value)){t.push(PO(e,n));continue}if(c(n.value)){t.push(IO(e,n));continue}if(l(n.value)){t.push(RO(e,n));continue}if(u(n.value)){t.push(LO(e,n));continue}n.value++}return t}var VO=e=>BO(QE(e));function HO(e,t,n){let r=Bp({}),i=WO(UO(VO(e))),a=hh(i.length*100);return r.settings.width=a,r.settings.height=a,i.forEach(e=>GO(r,e,t)),KO(r,i),qO(r,i),Bm(n?n(r):r)}function UO(e){let t={tables:[],indexes:[],primaryKeys:[],foreignKeys:[],uniques:[],tableComments:[],columnComments:[]};for(let n of e)switch(n.type){case KE.createTable:n.name&&t.tables.push(n);break;case KE.createIndex:n.tableName&&n.columns.length&&t.indexes.push(n);break;case KE.alterTableAddPrimaryKey:n.name&&n.columnNames.length&&t.primaryKeys.push(n);break;case KE.alterTableAddForeignKey:n.name&&n.columnNames.length&&n.refTableName&&n.refColumnNames.length&&n.columnNames.length===n.refColumnNames.length&&t.foreignKeys.push(n);break;case KE.alterTableAddUnique:n.name&&n.columnNames.length&&t.uniques.push(n);break;case KE.commentOnTable:n.name&&t.tableComments.push(n);break;case KE.commentOnColumn:n.tableName&&n.columnName&&t.columnComments.push(n)}return t}function WO({tables:e,indexes:t,primaryKeys:n,foreignKeys:r,uniques:i,tableComments:a,columnComments:o}){return t.forEach(t=>{let n=HS(e,t.tableName);n&&n.indexes.push({name:t.name,unique:t.unique,columns:t.columns})}),n.forEach(t=>{let n=HS(e,t.name);n&&t.columnNames.forEach(e=>{let t=HS(n.columns,e);t&&(t.primaryKey=!0)})}),i.forEach(t=>{let n=HS(e,t.name);n&&t.columnNames.forEach(e=>{let t=HS(n.columns,e);t&&(t.unique=!0)})}),r.forEach(t=>{let n=HS(e,t.name);n&&n.foreignKeys.push({columnNames:t.columnNames,refTableName:t.refTableName,refColumnNames:t.refColumnNames})}),a.forEach(({name:t,comment:n})=>{let r=HS(e,t);r&&(r.comment=n)}),o.forEach(({tableName:t,columnName:n,comment:r})=>{let i=HS(e,t);if(!i)return;let a=HS(i.columns,n);a&&(a.comment=r)}),e}function GO({doc:e,collections:t},n,{toWidth:r}){let i=Qb({name:n.name,comment:n.comment,ui:{widthName:V(r(n.name)),widthComment:V(r(n.comment))}});n.columns.forEach(e=>{let n=kx({tableId:i.id,name:e.name,comment:e.comment,dataType:e.dataType,default:e.default,options:(e.autoIncrement?L.autoIncrement:0)|(e.primaryKey?L.primaryKey:0)|(e.unique?L.unique:0)|(e.nullable?0:L.notNull),ui:{widthName:V(r(e.name)),widthComment:V(r(e.comment)),widthDataType:V(r(e.dataType)),widthDefault:V(r(e.default)),keys:e.primaryKey?R.primaryKey:0}});i.columnIds.push(n.id),i.seqColumnIds.push(n.id),j(t).collection(`tableColumnEntities`).setOne(n)}),e.tableIds.push(i.id),j(t).collection(`tableEntities`).setOne(i)}function KO({doc:e,collections:t},n){let r=j(t).collection(`tableEntities`).selectByIds(e.tableIds),i=j(t).collection(`tableColumnEntities`);n.forEach(n=>{if(!n.foreignKeys.length)return;let a=HS(r,n.name);if(!a)return;let o=i.selectByIds(a.columnIds);n.foreignKeys.forEach(n=>{let s=HS(r,n.refTableName);if(!s)return;let c=i.selectByIds(s.columnIds),l=[],u=[];n.refColumnNames.forEach(e=>{let t=HS(c,e);t&&l.push(t)}),n.columnNames.forEach(e=>{let t=HS(o,e);t&&(u.push(t),z(t.ui.keys,R.primaryKey)?t.ui.keys|=R.foreignKey:t.ui.keys=R.foreignKey)});let d=Mb({identification:!u.some(e=>!(z(e.ui.keys,R.primaryKey)&&z(e.ui.keys,R.foreignKey))),relationshipType:Ym.ZeroN,start:{tableId:s.id,columnIds:l.map(e=>e.id)},end:{tableId:a.id,columnIds:u.map(e=>e.id)}});e.relationshipIds.push(d.id),j(t).collection(`relationshipEntities`).setOne(d)})})}function qO({doc:e,collections:t},n){let r=j(t).collection(`tableEntities`).selectByIds(e.tableIds);n.forEach(n=>{n.indexes.forEach(i=>{let a=HS(r,n.name);if(!a)return;let o=j(t).collection(`tableColumnEntities`).selectByIds(a.columnIds),s=[],c=Sy({name:i.name,tableId:a.id,unique:i.unique});i.columns.forEach(e=>{let t=HS(o,e.name);if(!t)return;let n=zy({indexId:c.id,columnId:t.id,orderType:e.sort===qE.asc?Zm.ASC:Zm.DESC});s.push(n)}),s.length!==0&&(s.forEach(e=>{c.indexColumnIds.push(e.id),c.seqIndexColumnIds.push(e.id),j(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(c.id),j(t).collection(`indexEntities`).setOne(c))})})}function JO({doc:e,collections:t},n){let r=B(n);return j(t).collection(`relationshipEntities`).selectByIds(e.relationshipIds).filter(({start:e,end:t})=>r(e.tableId)&&r(t.tableId)).map(({relationshipType:e,start:t,end:n})=>({relationshipType:e,start:{tableId:t.tableId,columnIds:[...t.columnIds]},end:{tableId:n.tableId,columnIds:[...n.columnIds]}}))}function YO({doc:e,collections:t},n){let r=B(n),i=j(t).collection(`indexColumnEntities`),a=[];for(let n of j(t).collection(`indexEntities`).selectByIds(e.indexIds)){if(!r(n.tableId))continue;let e=[],t=!0;for(let r of n.indexColumnIds){let n=i.selectById(r);if(!n){t=!1;break}e.push({columnId:n.columnId,orderType:n.orderType})}t&&a.push({tableId:n.tableId,name:n.name,unique:n.unique,indexColumns:e})}return a}new TextEncoder;function XO({tables:e,columns:t,memos:n,relationships:r,indexes:i},a){let o=[],s=[],c=[],l=new Map(t.map(e=>[e.sourceId,e])),u=new Map,d=new Map;for(let t of e){let e=a.get(t.sourceId);if(!e)continue;let n=x();s.push(n),u.set(t.sourceId,n),o.push($b({id:n,ui:{x:e.x,y:e.y,zIndex:e.zIndex,color:t.ui.color}}),sx({id:n,value:t.name}),lx({id:n,value:t.comment}));for(let e of t.columnIds){let t=l.get(e);if(!t)continue;let r={id:x(),tableId:n};d.set(e,r.id),o.push(Ax(r),Px({...r,value:t.name}),Rx({...r,value:t.dataType}),Bx({...r,value:t.default}),Ix({...r,value:t.comment}),Wx({...r,value:z(t.options,L.primaryKey)}),Jx({...r,value:z(t.options,L.notNull)}),Kx({...r,value:z(t.options,L.unique)}),Hx({...r,value:z(t.options,L.autoIncrement)}))}}for(let e of r){let t=u.get(e.start.tableId),n=u.get(e.end.tableId);if(!t||!n)continue;let r=ZO(e.start.columnIds,d),i=ZO(e.end.columnIds,d);!r||!i||o.push(Nb({id:x(),relationshipType:e.relationshipType,start:{tableId:t,columnIds:r},end:{tableId:n,columnIds:i}}))}for(let e of i){let t=u.get(e.tableId);if(!t)continue;let n=ZO(e.indexColumns.map(({columnId:e})=>e),d);if(!n)continue;let r=x();o.push(Cy({id:r,tableId:t}),Dy({id:r,tableId:t,value:e.name}),ky({id:r,tableId:t,value:e.unique})),e.indexColumns.forEach(({orderType:e},i)=>{let a=x(),s=n[i];o.push(Vy({id:a,indexId:r,tableId:t,columnId:s}),qy({id:a,indexId:r,columnId:s,value:e}))})}for(let e of n){let t=a.get(e.sourceId);if(!t)continue;let n=x();c.push(n),o.push(ib({id:n,ui:{x:t.x,y:t.y,zIndex:t.zIndex,color:e.ui.color,width:e.ui.width,height:e.ui.height}}),fb({id:n,value:e.value}))}return{actions:o,tableIds:s,memoIds:c}}function ZO(e,t){let n=[];for(let r of e){let e=t.get(r);if(!e)return null;n.push(e)}return n}function QO(e,t,n=[]){let{doc:{relationshipIds:r},collections:i}=t,a=e.pop();return a&&(n.some(({columnId:e})=>e===a.columnId)||(n.push(a),j(i).collection(`relationshipEntities`).selectByIds(r).forEach(({id:t,start:n,end:r})=>{let i=n.columnIds.indexOf(a.columnId);if(i!==-1){let n=r.columnIds[i];e.push({columnId:n,relationshipIds:[t]})}else{let i=r.columnIds.indexOf(a.columnId);if(i!==-1){let r=n.columnIds[i];e.push({columnId:r,relationshipIds:[t]})}}})),QO(e,t,n)),n}function $O(e){return Object.entries(e).reduce((e,[t,n])=>(n===s_.table?e.tableIds.push(t):n===s_.memo&&e.memoIds.push(t),e),{tableIds:[],memoIds:[]})}const ek=e=>function*(){yield rv(),yield ov({value:e})},tk=e=>function*(){yield cv(),yield uv({value:e})},nk=(e,t)=>function*({editor:{selectedMap:n},settings:{zoomLevel:r}}){let{tableIds:i,memoIds:a}=$O(n),o=e/r,s=t/r;i.length&&(yield tx({ids:i,movementX:o,movementY:s})),a.length&&(yield ob({ids:a,movementX:o,movementY:s}))},rk=()=>function*(){yield OS(),yield yS()},ik=(e,t)=>function*(n){yield*ok(n,{input:{tables:e.tables,columns:e.columns,memos:e.memos,relationships:e.relationships??[],indexes:e.indexes??[]},offset:{x:50*t,y:50*t},escapeCollision:!0})},ak=({tableIds:e,memoIds:t,offset:n,escapeCollision:r})=>function*(i){yield*ok(i,{input:lk(i,{tableIds:e??[],memoIds:t??[]}),offset:{x:Ue(n.x,4),y:Ue(n.y,4)},escapeCollision:r})};function*ok(e,{input:t,offset:n,escapeCollision:r}){if(t.tables.length===0&&t.memos.length===0)return;let{settings:i,doc:{tableIds:a,memoIds:o},collections:s}=e,c=j(s).collection(`tableEntities`),l=j(s).collection(`memoEntities`),{actions:u,tableIds:d,memoIds:f}=XO(t,ck(TS({entities:[...t.tables.map(sk),...t.memos.map(sk)],offset:n,escapeCollision:r,settings:i,tables:c.selectByIds(a),memos:l.selectByIds(o),findSource:e=>c.selectById(e)??l.selectById(e)})));yield dk(),yield u,yield $_({...d.reduce((e,t)=>(e[t]=s_.table,e),{}),...f.reduce((e,t)=>(e[t]=s_.memo,e),{})})}const sk=({sourceId:e,ui:{x:t,y:n,zIndex:r}})=>({sourceId:e,ui:{x:t,y:n,zIndex:r}});function ck(e){return new Map(Array.from(e,([e,{x:t,y:n,zIndex:r}])=>[e,{x:Ue(t,4),y:Ue(n,4),zIndex:r}]))}function lk(e,{tableIds:t,memoIds:n}){let{collections:r}=e,i=j(r).collection(`tableEntities`).selectByIds(t),a=j(r).collection(`memoEntities`).selectByIds(n),o=i.flatMap(e=>j(r).collection(`tableColumnEntities`).selectByIds(e.columnIds)),s=i.map(({id:e})=>e);return{tables:i.map(e=>({sourceId:e.id,name:e.name,comment:e.comment,columnIds:[...e.columnIds],ui:{x:e.ui.x,y:e.ui.y,zIndex:e.ui.zIndex,widthName:e.ui.widthName,widthComment:e.ui.widthComment,color:e.ui.color}})),columns:o.map(e=>({sourceId:e.id,tableId:e.tableId,name:e.name,comment:e.comment,dataType:e.dataType,default:e.default,options:e.options,ui:{keys:e.ui.keys,widthName:e.ui.widthName,widthComment:e.ui.widthComment,widthDataType:e.ui.widthDataType,widthDefault:e.ui.widthDefault}})),memos:a.map(e=>({sourceId:e.id,value:e.value,ui:{x:e.ui.x,y:e.ui.y,width:e.ui.width,height:e.ui.height,zIndex:e.ui.zIndex,color:e.ui.color}})),relationships:JO(e,s),indexes:YO(e,s)}}const uk=e=>function*(t){let{doc:{tableIds:n,memoIds:r},collections:i}=t,a={...j(i).collection(`tableEntities`).selectByIds(n).reduce((n,r)=>{let i=Oh(r,t).width,a=Mh(r);return zS(e,{x:r.ui.x+i/2-15,y:r.ui.y+a/2-15,w:15,h:15})&&(n[r.id]=s_.table),n},{}),...j(i).collection(`memoEntities`).selectByIds(r).reduce((t,n)=>{let r=oh(n),i=sh(n);return zS(e,{x:n.ui.x+r/2-15,y:n.ui.y+i/2-15,w:15,h:15})&&(t[n.id]=s_.memo),t},{})};yield dk(),He(a)||(yield $_(a))},dk=()=>function*(){yield Z_(),yield gv()},fk=(e,t)=>function*(n){let{editor:{focusTable:r}}=n;r&&(e===c_.Tab&&!t&&(L_(r.focusType)&&F_(n)&&!w_(n)||!L_(r.focusType)&&T_(n)&&D_(n))?yield PS(r.tableId):yield vv({moveKey:e,shiftKey:t}))},pk=e=>function*({editor:t}){t.drawRelationship?.relationshipType===e?yield Iv():yield Mv({relationshipType:e})},mk=e=>function*({collections:t}){let n=j(t).collection(`tableEntities`).selectById(e);if(n){if(!j(t).collection(`tableColumnEntities`).selectByIds(n.columnIds).some(e=>z(e.options,L.primaryKey))){let t=x();yield Ax({tableId:e,id:t}),yield Wx({tableId:e,id:t,value:!0}),yield mv({tableId:e,columnId:t,focusType:W.columnName,$mod:!1,shiftKey:!1})}yield Pv({tableId:e})}},hk=e=>function*({editor:{selectedMap:t},collections:n}){let{tableIds:r,memoIds:i}=$O(t),a=j(n).collection(`tableEntities`).selectByIds(r),o=j(n).collection(`memoEntities`).selectByIds(i);yield a.map(t=>dx({id:t.id,color:e,prevColor:t.ui.color})),yield o.map(t=>mb({id:t.id,color:e,prevColor:t.ui.color}))},gk=e=>function*({settings:t},n){yield ek(HO(e,n,e=>(e.settings={...e.settings,..._e(oe(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield hx()},_k=e=>function*({settings:t},n){yield ek(GE(e,n,e=>(e.settings={...e.settings,..._e(oe(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield hx()},vk=e=>function*({settings:t},n){yield ek(xT(e,n,e=>(e.settings={...e.settings,..._e(oe(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield hx()},yk=e=>function*({settings:t},n){yield ek(dw(e,n,e=>(e.settings={...e.settings,..._e(oe(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield hx()},bk=e=>function*({editor:{focusTable:t}}){!t||!t.columnId||(yield Xv({tableId:t.tableId,columnIds:e?[...t.selectColumnIds]:[t.columnId]}))},xk=(e,t)=>function*({editor:{draggableColumn:n},collections:r}){if(!n||n.columnIds.length===0)return;let{tableId:i,columnIds:a}=n,o=j(r).collection(`tableEntities`),s=o.selectById(i);if(!s)return;if(t===i){let t=s.columnIds.indexOf(a[0]);if(t===-1)return;let n=s.columnIds.indexOf(e);if(n===-1)return;let r=a.map(t=>Xx({tableId:i,id:t,targetId:e}));t<n&&r.reverse(),yield r;return}if(!o.selectById(t))return;let c=j(r).collection(`tableColumnEntities`).selectByIds(a);if(c.length===0)return;yield FS(i,a);let l=c.map(()=>x());for(let n=0;n<c.length;n++){let r=c[n],i=l[n],a={id:i,tableId:t};yield[Ax(a),Px({...a,value:r.name}),Rx({...a,value:r.dataType}),Bx({...a,value:r.default}),Ix({...a,value:r.comment}),Wx({...a,value:z(r.options,L.primaryKey)}),Jx({...a,value:z(r.options,L.notNull)}),Kx({...a,value:z(r.options,L.unique)}),Hx({...a,value:z(r.options,L.autoIncrement)}),Xx({...a,targetId:e}),mv({tableId:t,columnId:i,focusType:W.columnName,$mod:!0,shiftKey:!1})]}yield Xv({tableId:t,columnIds:l})},Sk=e=>function*(t){let{columnIds:n,relationshipIds:r}=QO([{columnId:e,relationshipIds:[]}],t).reduce((e,{columnId:t,relationshipIds:n})=>(e.columnIds.push(t),e.relationshipIds.push(...n),e),{columnIds:[],relationshipIds:[]});yield Bv({columnIds:xe(n)}),yield Hv({relationshipIds:xe(r)})},Ck=()=>function*(){yield Bv({columnIds:[]}),yield Hv({relationshipIds:[]})},wk={loadJsonAction$:ek,initialLoadJsonAction$:tk,moveAllAction$:nk,removeSelectedAction$:rk,pasteEntitiesAction$:ik,duplicateAction$:ak,dragSelectAction$:uk,unselectAllAction$:dk,focusMoveTableAction$:fk,drawStartRelationshipAction$:pk,drawStartAddRelationshipAction$:mk,changeColorAllAction$:hk,loadSchemaSQLAction$:gk,loadSchemaGraphQLAction$:_k,loadSchemaDBMLAction$:vk,loadSchemaAMLAction$:yk,dragstartColumnAction$:bk,dragoverColumnAction$:xk,columnKeyHoverStartAction$:Sk,columnKeyHoverEndAction$:Ck},Tk={addIndexAction$:e=>function*(){yield Cy({id:x(),tableId:e})},changeIndexUniqueAction$:e=>function*({collections:t}){let n=j(t).collection(`indexEntities`).selectById(e);n&&(yield ky({id:e,tableId:n.tableId,value:!n.unique}))}},Ek={addIndexColumnAction$:(e,t)=>function*({collections:n}){let r=j(n).collection(`indexEntities`).selectById(e);if(!r)return;let i=j(n).collection(`indexColumnEntities`).selectByIds(r.seqIndexColumnIds).find(e=>e.columnId===t);i?yield Vy({id:i.id,indexId:e,tableId:r.tableId,columnId:t}):yield Vy({id:x(),indexId:e,tableId:r.tableId,columnId:t})},removeIndexColumnAction$:(e,t)=>function*({collections:n}){let r=j(n).collection(`indexEntities`).selectById(e);if(!r)return;let i=j(n).collection(`indexColumnEntities`).selectByIds(r.indexColumnIds).filter(e=>e.columnId===t);for(let t of i)yield Uy({id:t.id,indexId:e,tableId:r.tableId})},changeIndexColumnOrderTypeAction$:e=>function*({collections:t}){let n=j(t).collection(`indexColumnEntities`).selectById(e);n&&(yield qy({id:e,indexId:n.indexId,columnId:n.columnId,value:n.orderType===Zm.ASC?Zm.DESC:Zm.ASC}))},moveIndexColumnAction$:(e,t)=>function*({collections:n}){if(e===t)return;let r=j(n).collection(`indexColumnEntities`).selectById(e);if(!r)return;let i=j(n).collection(`indexEntities`).selectById(r.indexId);i&&(yield Gy({id:e,indexId:r.indexId,tableId:i.tableId,targetId:t}))}},Dk={};function Ok({editor:{viewport:e},settings:{originX:t,originY:n,zoomLevel:r}},i){let a={originX:t,originY:n,zoomLevel:r},o={x:e.width/2,y:e.height/2},s=t_(a,o),c=e_({...a,zoomLevel:i},s);return{movementX:Ue(o.x-c.x,4),movementY:Ue(o.y-c.y,4)}}const kk={changeZoomLevelAction$:e=>function*(t){let{settings:{originX:n,originY:r}}=t,{movementX:i,movementY:a}=Ok(t,gh(e));yield rg({value:e}),yield lg({originX:n+i,originY:r+a})},streamZoomLevelAction$:e=>function*(t){let{settings:{zoomLevel:n}}=t,{movementX:r,movementY:i}=Ok(t,gh(n+e));yield ag({value:e}),yield dg({movementX:r,movementY:i})}},Ak=Object.freeze({..._y,...wk,...My,...Tk,...Xy,...Ek,...xb,...xS,...Bb,...Dk,...Rg,...kk,...vx,...AS,...$x,...RS}),jk=`table.add,table.move,table.moveTo,table.remove,table.changeName,table.changeComment,table.changeColor,table.sort,column.add,column.remove,column.changeName,column.changeComment,column.changeDataType,column.changeDefault,column.changeAutoIncrement,column.changePrimaryKey,column.changeUnique,column.changeNotNull,column.move,relationship.add,relationship.remove,relationship.changeType,index.add,index.remove,index.changeName,index.changeUnique,indexColumn.add,indexColumn.remove,indexColumn.move,indexColumn.changeOrderType,memo.add,memo.move,memo.moveTo,memo.remove,memo.changeValue,memo.changeColor,memo.resize,settings.changeDatabaseName,settings.changeZoomLevel,settings.streamZoomLevel,settings.scrollTo,settings.streamScrollTo,settings.changeShow,settings.changeDatabase,settings.changeCanvasType,settings.changeLanguage,settings.changeTableNameCase,settings.changeColumnNameCase,settings.changeBracketType,settings.changeRelationshipDataTypeSync,settings.changeRelationshipOptimization,settings.changeColumnOrder,settings.changeMaxWidthComment,settings.changeIgnoreSaveSettings,editor.loadJson,editor.clear`.split(`,`),Mk=B([`settings.changeZoomLevel`,`settings.streamZoomLevel`,`settings.scrollTo`,`settings.streamScrollTo`,`settings.changeDatabase`,`settings.changeCanvasType`,`settings.changeLanguage`,`settings.changeTableNameCase`,`settings.changeColumnNameCase`,`settings.changeBracketType`]),Nk=[...jk.filter(e=>!Mk(e))],Pk=[`editor.sharedMouseTracker`,`editor.sharedFocusTracker`,`editor.sharedSelectionTracker`,`editor.sharedDragSelectTracker`];[...jk,...Pk];const Fk=[`table.move`,`memo.move`],Ik=[`table.changeColor`,`memo.changeColor`],Lk=[`settings.streamZoomLevel`,`settings.streamScrollTo`],Rk=[...Object.keys(mS)],zk=[...Object.keys(pS),...Rk];function Bk(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function Vk(e,t,n){Bk(e,t),t.set(e,n)}function Hk(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}function Uk(e,t){return e.get(Hk(e,t))}function Wk(e,t,n){return e.set(Hk(e,t),n),n}var Gk=new WeakMap,Kk=class{constructor(){Vk(this,Gk,0),di(this,`getVersion`,()=>Uk(Gk,this)),di(this,`getNextVersion`,()=>this.getVersion()+1),di(this,`merge`,e=>(!y(e)||!Number.isInteger(e)||this.getVersion()<e&&Wk(Gk,this,e),this))}};function qk(e){return{...e,clock:new Kk}}function Jk({notify:e,dispatch:t,getNextVersion:n},r){let i=r?.commands??[],a=r?.cursor??-1,o=r?.limit??0,s=!0,c=()=>a!==-1,l=()=>a<i.length-1,u=e=>o=e,d=()=>({hasRedo:l(),hasUndo:c()}),f=(e,r)=>{s=!1,e[r](t,n),s=!0};return Object.freeze({get cursor(){return a},get size(){return i.length},hasUndo:c,hasRedo:l,push:t=>{s&&(i.splice(a+1,i.length-a),i.push(t),o!==0&&i.length>o&&(i=i.slice(i.length-o,i.length)),a=i.length-1,e(d()))},undo:()=>{if(!c())return;let t=i[a];f(t,`undo`),a--,e(d())},redo:()=>{if(!l())return;let t=i[a+1];f(t,`redo`),a++,e(d())},clear:()=>{let t=i.length;i=[],a=-1,t>0&&e(d())},setLimit:u,clone:e=>Jk(e,{commands:[...i],cursor:a,limit:o})})}const Yk=Ae(e=>!!e.length),Xk=e=>{let t=B(e);return e=>new Ce(n=>e.subscribe({next:e=>n.next(e.filter(e=>t(e.type))),error:e=>n.error(e),complete:()=>n.complete()})).pipe(Yk)},Zk=`@@none-stream`,Qk=(e,t)=>n=>{let r=t.find(([,e])=>e(n));return r?r[0]:e(n)?n:Zk},$k=(e,t=[],n=Oe(200))=>{let r=B(e),i=t.map(([e,t])=>[e,B(t)]),a=Qk(r,i);return e=>new Ce(t=>e.subscribe({next:e=>{let n=e.reduce((e,t)=>{let n=a(t.type);return e[n]||(e[n]=[]),e[n].push(t),e},{});Object.values(n).forEach(e=>t.next(e))},error:e=>t.error(e),complete:()=>t.complete()})).pipe(Yk,Me(e=>a(e[0].type)),Fe(e=>e.key===Zk?e:e.pipe(De(e.pipe(n)),Ne(e=>e.flat()))))},eA=e=>{let t=t=>v(t.tags)||!e.some(e=>z(t.tags,e));return e=>new Ce(n=>e.subscribe({next:e=>n.next(e.filter(t)),error:e=>n.error(e),complete:()=>n.complete()})).pipe(Yk)};B(Rk),B(Pk);const tA=(e,t=[])=>{let n=B(Nk),r=e=>!v(e.tags)&&t.some(t=>z(e.tags,t))||!n(e.type);return t=>new Ce(n=>t.subscribe({next:t=>{n.next(e()?t.filter(r):t)},error:e=>n.error(e),complete:()=>n.complete()})).pipe(Yk)};function nA(e,t){return Mu({context:e,state:{...Bp({}),editor:l_(),lww:{}},reducers:{...gy,..._x,...Qx,...bb,...zb,...Lg,...jy,...Yy},enableObservable:t??!0})}const rA=new WeakMap;function iA(e){let t=rA.get(e);return t||(t={boxes:new Map,entries:new Map},rA.set(e,t)),t}function aA(e,t){return{left:e.left[t],top:e.top[t],right:e.right[t],bottom:e.bottom[t]}}function oA(e,t){return{left:Math.min(e.left,t.left),top:Math.min(e.top,t.top),right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom)}}function sA(e,t){return e.left===t.left&&e.top===t.top&&e.right===t.right&&e.bottom===t.bottom}function cA(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{x:a,y:o}of e)a<t&&(t=a),a>r&&(r=a),o<n&&(n=o),o>i&&(i=o);return{left:t,top:n,right:r,bottom:i}}function lA(e,t){return e.left<=t.right&&e.right>=t.left&&e.top<=t.bottom&&e.bottom>=t.top}function uA(e,t){let n={left:e.left-40,top:e.top-40,right:e.right+40,bottom:e.bottom+40};for(let e of t)if(lA(n,e))return!0;return!1}function dA(){let e=new Map,t=new Map,n=(n,r,i,a,o)=>{let s=n?e:t,c=Math.floor(Math.min(r,i)/64),l=Math.floor(Math.max(r,i)/64);for(let e=c;e<=l;e++){let t=s.get(e);t?t.push(r,i,a,o):s.set(e,[r,i,a,o])}};return{markSpan:n,markBox(e){n(!0,e.left,e.right,e.top,e.bottom),n(!1,e.top,e.bottom,e.left,e.right)},hits(n,r,i,a,o){let s=n?e:t;if(!s.size)return!1;let c=Math.min(r,i)-64,l=Math.max(r,i)+64,u=Math.floor(c/64),d=Math.floor(l/64);for(let e=u;e<=d;e++){let t=s.get(e);if(t){for(let e=0;e<t.length;e+=4)if(!(t[e+1]<c||t[e]>l)&&!(t[e+3]<a-16)&&!(t[e+2]>o+16))return!0}}return!1}}}function fA(e,t){for(let n=1;n<t.length;n++){let r=t[n-1],i=t[n];Math.abs(r.x-i.x)<.5?e.markSpan(!0,r.x,i.x,Math.min(r.y,i.y),Math.max(r.y,i.y)):e.markSpan(!1,r.y,i.y,Math.min(r.x,i.x),Math.max(r.x,i.x))}}function pA(e,t){let n=e.boxes,r=new Map,i=[],a=!1;for(let e=0;e<t.ids.length;e++){let o=t.ids[e],s=aA(t,e);if(r.set(o,s),a)continue;let c=n.get(o);c?sA(c,s)||i.push(oA(c,s)):i.push(s),i.length>64&&(a=!0)}if(!a){for(let[e,t]of n)if(!r.has(e)&&(i.push(t),i.length>64)){a=!0;break}}return e.boxes=r,a||n.size===0?null:i}function mA(e){return 50+e%4*12}function hA(e,t){return e.tableId===t.tableId?null:e.direction===I.right&&t.direction===I.left?t.x-e.x:e.direction===I.left&&t.direction===I.right?e.x-t.x:e.direction===I.bottom&&t.direction===I.top?t.y-e.y:e.direction===I.top&&t.direction===I.bottom?e.y-t.y:null}function gA(e,t){return t===null||t<=0?e:Math.max(36,Math.min(e,t/2-1))}function _A(e){return e===I.left||e===I.right}function vA(e){return e===I.right||e===I.bottom?1:-1}function yA(e,t,n){let r=vA(t);return _A(t)?{x:e.x+r*n,y:e.y}:{x:e.x,y:e.y+r*n}}function bA(e){let{start:t,end:n}=e,[r,i]=Ug(e),a=hA(t,n),o=gA(mA(r),a),s=gA(mA(i),a);return{m:yA(t,t.direction,o),l:yA(n,n.direction,s),startStub:o,endStub:s}}function xA(e){let{doc:{tableIds:t},collections:n}=e,r=j(n).collection(`tableEntities`).selectByIds(t),i=r.length,a={ids:Array(i),left:new Float64Array(i),top:new Float64Array(i),right:new Float64Array(i),bottom:new Float64Array(i)};return r.forEach((t,n)=>{let r=Ih(e,t);a.ids[n]=t.id,a.left[n]=r.lt.x+2,a.top[n]=r.lt.y+2,a.right[n]=r.rb.x-2,a.bottom[n]=r.rb.y-2}),a}function SA(e,t,n,r,i,a,o,s){let c=0,l=1,u=n-e,d=r-t,f=(e,t)=>{if(e===0)return t>=0;let n=t/e;if(e<0){if(n>l)return!1;n>c&&(c=n)}else{if(n<c)return!1;n<l&&(l=n)}return!0};return f(-u,e-i)&&f(u,o-e)&&f(-d,t-a)&&f(d,s-t)&&c<=l}function CA(e,t,n,r){let i=0,a=1/0,o=-1/0,s=1/0,c=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n.x<a&&(a=n.x),n.x>o&&(o=n.x),n.y<s&&(s=n.y),n.y>c&&(c=n.y)}for(let l=0;l<t.ids.length;l++){let u=t.left[l],d=t.right[l],f=t.top[l],p=t.bottom[l];if(o<u||a>d||c<f||s>p)continue;let m=t.ids[l];if(m!==n&&m!==r)for(let t=1;t<e.length;t++){let n=e[t-1],r=e[t];if(!(Math.max(n.x,r.x)<u||Math.min(n.x,r.x)>d)&&!(Math.max(n.y,r.y)<f||Math.min(n.y,r.y)>p)&&SA(n.x,n.y,r.x,r.y,u,f,d,p)){i++;break}}}return i}function wA(e){let t=0;for(let n=1;n<e.length;n++)t+=Math.abs(e[n].x-e[n-1].x)+Math.abs(e[n].y-e[n-1].y);return t}function TA(e,t,n,r,i,a){let o=(e+t)/2,s=n[r?`left`:`top`],c=n[r?`right`:`bottom`],l=n[r?`top`:`left`],u=n[r?`bottom`:`right`],d=[];for(let e=0;e<n.ids.length;e++)u[e]<i||l[e]>a||d.push(s[e]-16,c[e]+16);return d.sort((e,t)=>Math.abs(e-o)-Math.abs(t-o)),[o,...d.slice(0,6)]}function EA(e,t,n,r,i){let a=_A(t),o=_A(r),s=vA(t),c=vA(r),l=Math.min(e.x,n.x,e.y,n.y),u=Math.max(e.x,n.x,e.y,n.y),d=[],f=e=>{let t=[e[0]];for(let n=1;n<e.length;n++){let r=t[t.length-1],i=e[n];Math.abs(i.x-r.x)<.5&&Math.abs(i.y-r.y)<.5||t.push(i)}t.length<2||d.push({points:t,bends:t.length-2})};if(a&&o){let t=TA(e.x,n.x,i,!0,l,u);for(let r of t)(r-e.x)*s<0||(r-n.x)*c<0||f([e,{x:r,y:e.y},{x:r,y:n.y},n]);let r=TA(e.y,n.y,i,!1,l,u);for(let t of r){let r=e.x+s*16,i=n.x+c*16;f([e,{x:r,y:e.y},{x:r,y:t},{x:i,y:t},{x:i,y:n.y},n])}}else if(!a&&!o){let t=TA(e.y,n.y,i,!1,l,u);for(let r of t)(r-e.y)*s<0||(r-n.y)*c<0||f([e,{x:e.x,y:r},{x:n.x,y:r},n]);let r=TA(e.x,n.x,i,!0,l,u);for(let t of r){let r=e.y+s*16,i=n.y+c*16;f([e,{x:e.x,y:r},{x:t,y:r},{x:t,y:i},{x:n.x,y:i},n])}}else if(a){(n.x-e.x)*s>=0&&(e.y-n.y)*c>=0&&f([e,{x:n.x,y:e.y},n]);let t=TA(e.x,n.x,i,!0,l,u).filter(t=>(t-e.x)*s>=0).slice(0,4),r=TA(e.y,n.y,i,!1,l,u).filter(e=>(e-n.y)*c>=0).slice(0,4);for(let i of t)for(let t of r)f([e,{x:i,y:e.y},{x:i,y:t},{x:n.x,y:t},n])}else{(n.y-e.y)*s>=0&&(e.x-n.x)*c>=0&&f([e,{x:e.x,y:n.y},n]);let t=TA(e.y,n.y,i,!1,l,u).filter(t=>(t-e.y)*s>=0).slice(0,4),r=TA(e.x,n.x,i,!0,l,u).filter(e=>(e-n.x)*c>=0).slice(0,4);for(let i of t)for(let t of r)f([e,{x:e.x,y:i},{x:t,y:i},{x:t,y:n.y},n])}return d}function DA(e,t,n,r,i,a,o){let s=EA(e,t,n,r,i),c=null,l=1/0;for(let e of s){let t=CA(e.points,i,a,o)*1e5+e.bends*36+wA(e.points);t<l&&(l=t,c=e.points)}return c||(_A(t)?[e,{x:(e.x+n.x)/2,y:e.y},{x:(e.x+n.x)/2,y:n.y},n]:[e,{x:e.x,y:(e.y+n.y)/2},{x:n.x,y:(e.y+n.y)/2},n])}const OA=[10,7,4],kA=OA[OA.length-1]-.5;function AA(e){let t=[];for(let[n,r]of e)for(let e=0;e<r.length-1;e++){let i=r[e],a=r[e+1],o=Math.abs(i.x-a.x)<.5;o!==Math.abs(i.y-a.y)<.5&&t.push({relationshipId:n,points:r,index:e,movable:e>0&&e<r.length-2,vertical:o,coordinate:o?i.x:i.y,low:o?Math.min(i.y,a.y):Math.min(i.x,a.x),high:o?Math.max(i.y,a.y):Math.max(i.x,a.x)})}return t}function jA(e,t){return e.relationshipId===t.relationshipId?e.index-t.index:e.relationshipId<t.relationshipId?-1:1}function MA(e){let t=e.points[e.index-1];return e.vertical?t.y:t.x}function NA(e){for(let t of e){let e=t.points[t.index],n=t.points[t.index+1];t.low=t.vertical?Math.min(e.y,n.y):Math.min(e.x,n.x),t.high=t.vertical?Math.max(e.y,n.y):Math.max(e.x,n.x)}}function PA(e,t){let n=e.points[e.index],r=e.points[e.index+1];e.vertical?(n.x=t,r.x=t):(n.y=t,r.y=t)}function FA(e,t,n,r){let i=[],a=[];for(let t of AA(e))(t.vertical?i:a).push(t);for(let e of[i,a]){NA(e);let i=e.filter(e=>e.movable);if(i.length<2)continue;i.sort((e,t)=>e.coordinate-t.coordinate||jA(e,t));let a=[],o=()=>{a.length>1&&IA(a,e,t,n,r),a=[]};for(let e of i){let t=a[a.length-1];t&&e.coordinate-t.coordinate>10.5&&o(),a.push(e)}o()}}function IA(e,t,n,r,i){e.sort((e,t)=>e.low-t.low||jA(e,t));let a=[],o=-1/0,s=()=>{a.length>1&&HA(a,t,n,r,i),a=[],o=-1/0};for(let t of e)a.length&&t.low>=o&&s(),a.push(t),o=Math.max(o,t.high);s()}function LA(e,t){return e.high+10>t.low&&t.high+10>e.low}function RA(e,t){return Math.abs(e.coordinate-t.coordinate)>=kA?0:Math.max(0,Math.min(e.high,t.high)-Math.max(e.low,t.low))}function zA(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r];for(let t=r+1;t<e.length;t++)n+=RA(i,e[t]);for(let e of t)n+=RA(i,e)}return n}function BA(e,t){let n=new Set(e),r=1/0,i=-1/0;for(let t of e)t.coordinate<r&&(r=t.coordinate),t.coordinate>i&&(i=t.coordinate);let a=10*(e.length-1)/2+kA,o=[];for(let e of t)e.coordinate<r-a||e.coordinate>i+a||n.has(e)||o.push(e);return o}function VA(e){let t=[];for(let n of e){let e=t.find(e=>!LA(e[e.length-1],n));e?e.push(n):t.push([n])}return t}function HA(e,t,n,r,i){if(!i){UA(e,t,n,r);return}if(WA(e,i))return;let a=e.map(e=>e.coordinate);UA(e,t,n,r),GA(e,a,i)}function UA(e,t,n,r){let i=BA(e,t),a=zA(e,i);if(!a)return;let o=new Map,s=e.map(e=>(o.set(e,QA(e,n,r)),e.coordinate)),c=s.reduce((e,t)=>e+t,0)/s.length,l=KA(e),u=null,d=1/0;for(let t of OA){let a=null,f=1/0;for(let p of l){ZA(p,t,c,o,n,r);let l=zA(e,i);if(l)l<d&&(u=e.map(e=>e.coordinate),d=l);else{let t=YA(e,s);t<f&&(f=t,a=e.map(e=>e.coordinate))}XA(e,s)}if(a){XA(e,a);return}}u&&d<a&&XA(e,u)}function WA(e,t){let n=[];for(let r of e){if(t.dirty.has(r.relationshipId))return!1;let e=t.coordinate(r.relationshipId,r.index,r.vertical);if(e===void 0||t.lanes.hits(r.vertical,r.coordinate,e,r.low,r.high))return!1;n.push(e)}return XA(e,n),!0}function GA(e,t,n){e.forEach((e,r)=>{let i=t[r],a=e.coordinate;if(Math.abs(a-i)<.5)return;n.lanes.markSpan(e.vertical,i,a,e.low,e.high);let o=e.points[e.index],s=e.points[e.index+1],c=Math.min(i,a),l=Math.max(i,a),u=e.vertical?o.y:o.x,d=e.vertical?s.y:s.x;n.lanes.markSpan(!e.vertical,u,u,c,l),n.lanes.markSpan(!e.vertical,d,d,c,l)})}function KA(e){let t=VA(e),n=qA(t);return t.length===e.length?n:[...n,...qA(e.map(e=>[e]))]}function qA(e){let t=(e,t)=>e.reduce((e,n)=>e+t(n),0)/e.length,n=[...e].sort((e,n)=>t(e,MA)-t(n,MA)||t(e,JA)-t(n,JA)||jA(e[0],n[0])),r=[...e].sort((e,n)=>t(e,JA)-t(n,JA)||t(e,MA)-t(n,MA)||jA(e[0],n[0]));return n.every((e,t)=>e===r[t])?[n]:[n,r]}function JA(e){return e.coordinate}function YA(e,t){return e.reduce((e,n,r)=>e+Math.abs(n.coordinate-t[r]),0)}function XA(e,t){e.forEach((e,n)=>{PA(e,t[n]),e.coordinate=t[n]})}function ZA(e,t,n,r,i,a){let o=n-t*(e.length-1)/2,s=e.map(()=>[]);e.forEach((n,c)=>{for(let l of n){let n=r.get(l);if(!n)continue;let u=r=>{if(r<0||r>=e.length||s[r].some(e=>LA(l,e)))return!1;let c=o+r*t;return PA(l,c),nj(l,i,a,n)?(l.coordinate=c,s[r].push(l),!0):!1},d=!1;for(let e=0;e<=3&&!d;e++)d=u(c-e)||e>0&&u(c+e);d||PA(l,l.coordinate)}})}function QA(e,t,n){let r=n.get(e.relationshipId),i=[];for(let e=0;e<t.ids.length;e++){let n=t.ids[e];(n===r?.[0]||n===r?.[1])&&i.push(e)}return{blocked:CA(e.points,t,r?.[0]??``,r?.[1]??``),crossed:rj(e.points),own:i,intruded:tj(e.points,t,i),beforeDelta:$A(e,-1),afterDelta:$A(e,1)}}function $A(e,t){let n=e.points[t<0?e.index:e.index+1],r=e.points[t<0?e.index-1:e.index+2];return e.vertical?r.x-n.x:r.y-n.y}function ej(e,t){return Math.abs(t)>=.5&&e*t<=0}function tj(e,t,n){let r=0;for(let i of n){let n=t.left[i],a=t.top[i],o=t.right[i],s=t.bottom[i];for(let t=1;t<e.length;t++){let i=e[t-1],c=e[t];if(SA(i.x,i.y,c.x,c.y,n,a,o,s)){r++;break}}}return r}function nj(e,t,n,r){let i=e.points[e.index-1],a=e.points[e.index],o=e.points[e.index+1],s=e.points[e.index+2];if((e.vertical?Math.abs(i.x-a.x)<.5||Math.abs(s.x-o.x)<.5:Math.abs(i.y-a.y)<.5||Math.abs(s.y-o.y)<.5)||e.index===1&&ej($A(e,-1),r.beforeDelta)||e.index+2===e.points.length-1&&ej($A(e,1),r.afterDelta)||tj(e.points,t,r.own)>r.intruded||!r.crossed&&rj(e.points))return!1;let c=n.get(e.relationshipId);return CA(e.points,t,c?.[0]??``,c?.[1]??``)<=r.blocked}function rj(e){for(let t=0;t+1<e.length;t++)for(let n=t+2;n+1<e.length;n++)if(ij(e[t],e[t+1],e[n],e[n+1]))return!0;return!1}function ij(e,t,n,r){let i=Math.abs(e.x-t.x)<.5;if(i===Math.abs(n.x-r.x)<.5)return!1;let a=i?e:n,o=i?t:r,s=i?n:e,c=i?r:t;return a.x>Math.min(s.x,c.x)&&a.x<Math.max(s.x,c.x)&&s.y>Math.min(a.y,o.y)&&s.y<Math.max(a.y,o.y)}const aj={[U.top]:I.top,[U.bottom]:I.bottom,[U.left]:I.left,[U.right]:I.right},oj=Math.PI*2,sj=.15,cj={[U.top]:-Math.PI,[U.right]:-Math.PI/2,[U.bottom]:0,[U.left]:Math.PI/2},lj={[U.top]:!1,[U.right]:!1,[U.bottom]:!0,[U.left]:!0};function uj(e){Jg();let{doc:{tableIds:t,relationshipIds:n},collections:r}=e,i=B(t),a=j(r).collection(`tableEntities`),o=j(r).collection(`relationshipEntities`).selectByIds(n).filter(({start:e,end:t})=>i(e.tableId)&&i(t.tableId)),s=new Map,c=new Map,l=new Map,u=xj(o);for(let t of o){let n=bj(t),{start:r,end:i}=n,o=a.selectById(r.tableId),d=a.selectById(i.tableId);if(!(!o||!d)){if(c.set(t,n),l.set(n.id,[0,0]),r.tableId===i.tableId)gj(hj(e,s,o),n);else{let t=hj(e,s,o),a=hj(e,s,d),[c,l]=Tj(t.objectPoint,a.objectPoint,n);t[c].push({id:n.id,isStart:!0,point:r,angle:wj(c,t,a),tie:u.tieAt(n.id,r.tableId,i.tableId)}),a[l].push({id:n.id,isStart:!1,point:i,angle:wj(l,a,t),tie:u.tieAt(n.id,i.tableId,r.tableId)})}}}for(let e of s.values())for(let t of zg)Ej(t,e,l);for(let[e,t]of c.entries())Hg(e,l.get(t.id)??[0,0]),e.start.direction=t.start.direction,e.start.x=t.start.x,e.start.y=t.start.y,e.end.direction=t.end.direction,e.end.x=t.end.x,e.end.y=t.end.y;dj(e,c)}function dj(e,t){let n=xA(e),r=iA(e),i=pA(r,n),a=r.entries,o=new Map,s=new Set,c=dA();if(i)for(let e of i)c.markBox(e);let l=new Map,u=new Map,d=new Map;for(let e of t.keys()){let{start:t,end:r}=e;if(t.tableId===r.tableId)continue;let{m:f,l:p}=bA(e),m=a.get(e.id),h,g;i!==null&&m!==void 0&&mj(m,f,p,t,r)&&!uA(m.bounds,i)?(h=m.pristine,g=fj(h)):(g=DA(f,t.direction,p,r.direction,n,t.tableId,r.tableId),h=fj(g),s.add(e.id),m&&fA(c,m.nudged),fA(c,h)),l.set(e.id,g),u.set(e.id,[t.tableId,r.tableId]),d.set(e.id,e),o.set(e.id,{mx:f.x,my:f.y,mDirection:t.direction,lx:p.x,ly:p.y,lDirection:r.direction,startTableId:t.tableId,endTableId:r.tableId,pristine:h,nudged:g,bounds:cA(h)})}if(i)for(let[e,t]of a)o.has(e)||fA(c,t.nudged);FA(l,n,u,i===null?void 0:pj(a,s,c));for(let[e,t]of l){let n=d.get(e);n&&Gg(n,t)}r.entries=o}function fj(e){return e.map(({x:e,y:t})=>({x:e,y:t}))}function pj(e,t,n){return{dirty:t,lanes:n,coordinate(t,n,r){let i=e.get(t)?.nudged[n];if(i)return r?i.x:i.y}}}function mj(e,t,n,r,i){return e.mx===t.x&&e.my===t.y&&e.lx===n.x&&e.ly===n.y&&e.mDirection===r.direction&&e.lDirection===i.direction&&e.startTableId===r.tableId&&e.endTableId===i.tableId}function hj(e,t,n){let r=t.get(n.id);if(!r){let i=Ih(e,n);r={tableId:n.id,centerX:i.top.x,centerY:i.left.y,objectPoint:i,selfCount:0,top:[],bottom:[],left:[],right:[]},t.set(n.id,r)}return r}function gj(e,t){let{rt:n,width:r,height:i}=e.objectPoint,a=e.selfCount++,o=yj(Math.min(r,i)*sj,20,60)+a*14;t.start.direction=I.top,t.start.x=n.x-o,t.start.y=n.y,t.end.direction=I.right,t.end.x=n.x,t.end.y=n.y+o}function _j(e,t){let{width:n,height:r}=e.objectPoint;return yj(Math.min(n,r)*sj,20,60)+t*14}function vj(e){return e.selfCount?_j(e,e.selfCount-1)+8:0}function yj(e,t,n){return Math.min(Math.max(e,t),n)}function bj(e){return{id:e.id,start:{tableId:e.start.tableId,x:e.start.x,y:e.start.y,direction:e.start.direction},end:{tableId:e.end.tableId,x:e.end.x,y:e.end.y,direction:e.end.direction}}}function xj(e){let t=new Map;for(let{id:n,start:r,end:i}of e){let e=Sj(r.tableId,i.tableId),a=t.get(e);a?a.push(n):t.set(e,[n])}let n=new Map,r=new Map,i=!1;for(let e of t.values())e.length<2||(i=!0,e.sort(),e.forEach((t,i)=>{n.set(t,i),r.set(t,e.length)}));return{tieAt(e,t,a){if(!i)return 0;let o=n.get(e)??0;return t<=a?o:(r.get(e)??1)-1-o}}}function Sj(e,t){return e<t?`${e}|${t}`:`${t}|${e}`}function Cj(e){let t=e%oj;return t<0?t+oj:t}function wj(e,t,n){return Cj(Math.atan2(n.centerY-t.centerY,n.centerX-t.centerX)-cj[e])}function Tj(e,t,n){let r=[U.bottom,U.bottom],i=Lh(e.bottom,t.bottom);n.start.x=e.bottom.x,n.start.y=e.bottom.y,n.end.x=t.bottom.x,n.end.y=t.bottom.y,n.start.direction=I.bottom,n.end.direction=I.bottom;for(let a of zg)for(let o of zg){let s=a,c=o,l=Lh(e[s],t[c]);i<=l||(i=l,r[0]=s,r[1]=c,n.start.x=e[s].x,n.start.y=e[s].y,n.start.direction=aj[s],n.end.x=t[c].x,n.end.y=t[c].y,n.end.direction=aj[c])}return r}function Ej(e,t,n){let r=t[e];if(!r.length)return;r.sort((e,t)=>e.angle-t.angle||e.tie-t.tie||(e.id<t.id?-1:1));let{objectPoint:i}=t,a=e===U.top||e===U.bottom,o=(a?i.lt.x:i.lt.y)+12,s=(a?i.rb.x:i.rb.y)-12,c=vj(t);if(c&&(e===U.top?s-=c:e===U.right&&(o+=c)),s<o){let e=(o+s)/2;o=e,s=e}let l=s-o,u=(o+s)/2,d=r.length,f=d>1?Math.min(l/(d-1),120):0,p=u-f*(d-1)/2;r.forEach((t,r)=>{let o=lj[e]?d-1-r:r,s=p+o*f;a?(t.point.x=s,t.point.y=e===U.top?i.top.y:i.bottom.y):(t.point.y=s,t.point.x=e===U.left?i.left.x:i.right.x);let c=n.get(t.id);c&&(c[+!t.isStart]=r)})}const Dj=(e,t)=>e.pipe(Be(10,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let{doc:e,collections:n}=t(),r=j(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds);for(let e of r){let{end:t,identification:r}=e,i=j(n).collection(`tableEntities`).selectById(t.tableId);if(!i)continue;let a=B(i.columnIds),o=j(n).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(e=>a(e.id));if(!o.length)continue;let s=o.every(e=>z(e.options,L.primaryKey));s!==r&&(e.identification=s)}}),Oj=(e,t)=>e.pipe(Be(10,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let{doc:e,collections:n}=t(),r=j(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds);for(let e of r){let{end:t,startRelationshipType:r}=e,i=j(n).collection(`tableEntities`).selectById(t.tableId);if(!i)continue;let a=B(i.columnIds),o=j(n).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(e=>a(e.id));if(!o.length)continue;let s=o.every(e=>z(e.options,L.notNull))?Xm.dash:Xm.ring;s!==r&&(e.startRelationshipType=s)}}),kj=B([tx.type,rx.type,ob.type]),Aj=[[[Mx,Wx,ov,uv],Dj],[[Mx,Jx,ov,uv],Oj],[[pg,Ng,Nb,Fb,ob,$b,ax,tx,rx,sx,lx,Ax,Mx,Px,Ix,Rx,Bx,hx],(e,t)=>e.pipe(ze(e=>{kj(e.type)||Dh()}),Be(5,void 0,{leading:!1,trailing:!0})).subscribe(()=>{uj(t())})]],jj=[[[ov,uv],(e,t,n)=>e.pipe(Be(5,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let e=t();Nh(e,n),uj(e)})]],Mj=e=>e.pipe(Ie(Ee)),Nj=[[[Wx],(e,t)=>Mj(e).subscribe(({payload:{id:e}})=>{let{collections:n}=t(),r=j(n).collection(`tableColumnEntities`).selectById(e);r&&z(r.options,L.primaryKey)&&(z(r.options,L.notNull)||(r.options|=L.notNull))})],[[Nb],(e,t)=>Mj(e).subscribe(({payload:{id:e,end:n}})=>{let{doc:{relationshipIds:r},collections:i}=t();if(!r.includes(e))return;let a=j(i).collection(`tableColumnEntities`).selectByIds(n.columnIds);for(let e of a)e.ui.keys=e.ui.keys|R.foreignKey})],[[Fb],(e,t)=>Mj(e).subscribe(({payload:{id:e}})=>{let{doc:{relationshipIds:n},collections:r}=t();if(n.includes(e))return;let i=j(r).collection(`relationshipEntities`).selectById(e);if(!i)return;let a=j(r).collection(`tableColumnEntities`).selectByIds(i.end.columnIds);for(let e of a)e.ui.keys=e.ui.keys&~R.foreignKey})],[[ov,uv],(e,t)=>Mj(e).subscribe(()=>{let{doc:e,collections:n}=t(),r=j(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds),i=j(n).collection(`tableEntities`).selectByIds(e.tableIds),a=new Set,o=j(n).collection(`tableColumnEntities`);for(let{end:e}of r){let t=o.selectByIds(e.columnIds);for(let e of t)e.ui.keys=e.ui.keys|R.foreignKey,a.add(e.id)}for(let e of i){let t=o.selectByIds(e.columnIds);for(let e of t)z(e.ui.keys,R.foreignKey)&&!a.has(e.id)&&(e.ui.keys=e.ui.keys&~R.foreignKey)}})]],Pj=[...jj,...Nj,...Aj];function Fj(e){let t=()=>e.state,n=Pj.map(([n,r])=>{let i=new we;return{pattern:B(n.map(String)),action$:i,subscription:r(i,t,e.context)}}),r=e.subscribe(e=>{for(let t of e)for(let e of n)e.pattern(t.type)&&e.action$.next(t)});return{destroy:()=>{n.forEach(({action$:e,subscription:t})=>{t.unsubscribe(),e.complete()}),n.splice(0,n.length),r()}}}function Ij(e,{getReadonly:t=()=>!1,getHistory:n}={}){let r=new Set,i=nA(e),a=Fj(i),o={notify:e=>i.dispatch(q_(e)),dispatch:i.dispatchSync,getNextVersion:()=>e.clock.getNextVersion()},s=n?.(o)??Jk(o);s.setLimit(2048);let c=new we,l=c.pipe(Xk(zk),eA([nh.changeOnly,nh.shared]),tA(t),$k(Rk,[[`@@move`,Fk],[`@@scroll`,Lk],[`@@color`,Ik]])),u=new Ce(e=>i.subscribe(t=>e.next(t))).pipe(Xk(jk),tA(t,[nh.shared]),Oe(200)),d=(...t)=>{let n=e.clock.getNextVersion();return Ou(i.state,i.context,t).map(e=>(v(e.version)&&(e.version=n),e))},f=(...e)=>{let t=d(e);c.next(t)},p=(...e)=>{queueMicrotask(()=>f(e))},m=()=>{Array.from(r).forEach(e=>de(e)?e():e.unsubscribe()),r.clear(),i.destroy(),a.destroy(),s.clear(),c.complete()},h=()=>{t()||s.undo()},g=()=>{t()||s.redo()};return r.add(l.subscribe(_S(i,s))).add(c.pipe(tA(t,[nh.shared])).subscribe(i.dispatchSync)).add(i.subscribe(t=>{t.forEach(t=>e.clock.merge(t.version))})),Object.freeze({...i,dispatch:p,dispatchSync:f,destroy:m,undo:h,redo:g,history:s,change$:u})}const Lj={openColorPicker:`openColorPicker`,closeColorPicker:`closeColorPicker`,openToast:`openToast`,openTableProperties:`openTableProperties`,dragendColumnAll:`dragendColumnAll`,copy:`copy`,paste:`paste`,schemaGC:`schemaGC`,toggleSearch:`toggleSearch`,openThemeBuilder:`openThemeBuilder`,setThemeOptions:`setThemeOptions`,mouseTrackerStart:`mouseTrackerStart`,mouseTrackerEnd:`mouseTrackerEnd`,openDiffViewer:`openDiffViewer`,openAutomaticTablePlacement:`openAutomaticTablePlacement`,duplicateDragStart:`duplicateDragStart`,dragSelectStart:`dragSelectStart`};var Rj=new WeakMap,zj=class{constructor(){Vk(this,Rj,new Set)}on(e){return Uk(Rj,this).has(e)||Uk(Rj,this).add(e),()=>{Uk(Rj,this).delete(e)}}emit(e){Uk(Rj,this).forEach(t=>{fS(Reflect.get(t,e.type),e)})}clear(){Uk(Rj,this).clear()}};const Bj=D(Lj.openColorPicker);D(Lj.closeColorPicker),D(Lj.openToast),D(Lj.openTableProperties);const Vj=D(Lj.dragendColumnAll);D(Lj.copy),D(Lj.paste),D(Lj.schemaGC),D(Lj.toggleSearch),D(Lj.openThemeBuilder),D(Lj.setThemeOptions),D(Lj.mouseTrackerStart),D(Lj.mouseTrackerEnd),D(Lj.openDiffViewer),D(Lj.openAutomaticTablePlacement);const Hj=D(Lj.duplicateDragStart);D(Lj.dragSelectStart);const Uj=Je();let Wj=Uj.os.name===`mac`,Gj=Uj.os.name===`ios`;Uj.os.name,Uj.os.name,Uj.browser.name,Uj.browser.name,Uj.browser.name,Ye(e=>{Wj=e.os.name===`mac`,Gj=e.os.name===`ios`,e.os.name,e.os.name,e.browser.name,e.browser.name,e.browser.name});const Kj=()=>Wj||Gj,$={edit:`edit`,stop:`stop`,search:`search`,undo:`undo`,redo:`redo`,addTable:`addTable`,addColumn:`addColumn`,addMemo:`addMemo`,removeTable:`removeTable`,removeColumn:`removeColumn`,primaryKey:`primaryKey`,selectAllTable:`selectAllTable`,selectAllColumn:`selectAllColumn`,relationshipZeroOne:`relationshipZeroOne`,relationshipZeroN:`relationshipZeroN`,relationshipOneOnly:`relationshipOneOnly`,relationshipOneN:`relationshipOneN`,tableProperties:`tableProperties`,zoomIn:`zoomIn`,zoomOut:`zoomOut`,zoomReset:`zoomReset`,handTool:`handTool`,zenMode:`zenMode`};Object.values($);const qj=()=>({[$.edit]:[{shortcut:`Enter`}],[$.stop]:[{shortcut:`Escape`}],[$.search]:[{shortcut:`$mod+KeyK`,preventDefault:!0,stopPropagation:!0}],[$.undo]:[{shortcut:`$mod+KeyZ`,preventDefault:!0,stopPropagation:!0}],[$.redo]:[{shortcut:`$mod+Shift+KeyZ`,preventDefault:!0,stopPropagation:!0}],[$.addTable]:[{shortcut:`Alt+KeyN`,preventDefault:!0}],[$.addColumn]:[{shortcut:`Alt+Enter`,preventDefault:!0}],[$.addMemo]:[{shortcut:`Alt+KeyM`,preventDefault:!0}],[$.removeTable]:[{shortcut:`$mod+Backspace`,preventDefault:!0},{shortcut:`$mod+Delete`,preventDefault:!0}],[$.removeColumn]:[{shortcut:`Alt+Backspace`,preventDefault:!0},{shortcut:`Alt+Delete`,preventDefault:!0}],[$.primaryKey]:[{shortcut:`Alt+KeyK`,preventDefault:!0}],[$.selectAllTable]:[{shortcut:`$mod+KeyA`,preventDefault:!0},{shortcut:`$mod+Alt+KeyA`,preventDefault:!0}],[$.selectAllColumn]:[{shortcut:`Alt+KeyA`,preventDefault:!0}],[$.relationshipZeroOne]:[{shortcut:`$mod+Alt+Digit1`,preventDefault:!0}],[$.relationshipZeroN]:[{shortcut:`$mod+Alt+Digit2`,preventDefault:!0}],[$.relationshipOneOnly]:[{shortcut:`$mod+Alt+Digit3`,preventDefault:!0}],[$.relationshipOneN]:[{shortcut:`$mod+Alt+Digit4`,preventDefault:!0}],[$.tableProperties]:[{shortcut:`Alt+Space`,preventDefault:!0}],[$.zoomIn]:[{shortcut:`$mod+Equal`,preventDefault:!0,stopPropagation:!0}],[$.zoomOut]:[{shortcut:`$mod+Minus`,preventDefault:!0,stopPropagation:!0}],[$.zoomReset]:[{shortcut:`$mod+KeyO`,preventDefault:!0,stopPropagation:!0}],[$.handTool]:[{shortcut:`Space`,preventDefault:!0}],[$.zenMode]:[{shortcut:`Alt+KeyZ`,preventDefault:!0,stopPropagation:!0}]}),Jj={Shift:`Shift`,Meta:`Meta`,Alt:`Alt`,Control:`Control`};Jj.Shift,Jj.Meta,Jj.Alt,Jj.Control,Jj.Shift,Jj.Meta,Jj.Alt,Jj.Control;function Yj(e){return Kj()?e.metaKey:e.ctrlKey}function Xj(e,t){let{devtools:n=!0,...r}=t??{},i=qk(e),a=Ij(i,r),o=wa(qj(),{shallow:!0}),s=new we,c=new we,l=new zj;return Object.freeze({...i,actions:Ak,store:a,keyBindingMap:o,shortcut$:s,keydown$:c,emitter:l})}const Zj=hi({}),Qj=(e,t)=>za(e,{...Zj,value:t??Zj.value});function $j(e){e.store.dispatchSync(cv()),e.store.destroy(),e.keydown$.complete(),e.shortcut$.complete(),e.emitter.clear()}const eM=[`table`,`memo`,`relationship`],tM=e=>typeof e==`string`&&eM.includes(e);function nM(e){let t=e;if(typeof t.clientX==`number`)return{x:t.clientX,y:t.clientY};let n=e.touches?.[0];return n?{x:n.clientX,y:n.clientY}:null}const rM=(e,t)=>!!(e&&t&&e.x===t.x&&e.y===t.y),iM=new WeakMap,aM=`mousedown.sceneHit touchstart.sceneHit contextmenu.sceneHit`;function oM(e){return e.on(aM,t=>{let n=t.evt,r=nM(n),i=iM.get(e),a=t.target===e?null:cM(t.target),o=n.type===`contextmenu`&&rM(i?.point,r)?i?.hit??null:null;iM.set(e,{evt:n,hit:a??o,point:r})}),()=>{e.off(aM),iM.delete(e)}}function sM(e,t){let n=`${t}-`,r=e.id();if(r.startsWith(n))return r.slice(n.length);let[i,a=``]=e.name().split(/\s+/);return i===t?a:``}function cM(e){let t=e;for(;t;){let e=t.getAttr(`kind`);if(tM(e))return{kind:e,id:sM(t,e)};t=t.getParent()}return null}const lM=hi({}),uM=e=>za(e,lM);function dM({app:e,container:t,scene:n,width:r,height:i,theme:a}){let o=new te({container:t,width:r,height:i}),s={host:o.container(),parentElement:null},c=Ba(s,Zj,e),l=a?Ba(s,lM,a):null,u=oM(o);return Bf(o,n),{stage:o,destroy:()=>{u(),Bf(o,null),l?.destroy(),c.destroy(),o.destroy()}}}const fM=e=>new Promise(t=>setTimeout(t,e)),pM=32767;function mM(e,t,n){let r=Math.max(t,n),i=t*n;return r<=0||i<=0?e:Math.min(e,pM/r,16384/Math.sqrt(i))}function hM({x:e,y:t,width:n,height:r},i){return{x:e-i,y:t-i,width:n+i*2,height:r+i*2}}function gM(e){let{settings:{show:t},doc:{relationshipIds:n},collections:r}=e,i=Uh(e);if(z(t,N.relationship)){let e=j(r).collection(`relationshipEntities`).selectByIds(n);for(let t of e){let e=Zg(t);i=i?Hh(i,e):e}}return hM(i??{x:0,y:0,width:0,height:0},80)}function _M({width:e,height:t},n=1){let r=n>0?n:1,i=Math.max(e,t),a=e*t;return i<=0||a<=0?r:Math.min(r,pM/i,Math.sqrt(268435456/a))}const vM={"align-horizontal-distribute-center":Xe,"align-vertical-distribute-center":Ze,"arrow-right":Qe,atom:$e,braces:et,brackets:tt,"case-sensitive":nt,check:rt,"chevron-right":it,code:at,contrast:ot,copy:st,database:ct,diff:lt,eye:ut,"file-diff":dt,"file-image":ft,"file-input":pt,"file-output":mt,"grip-vertical":ht,hand:gt,"key-round":_t,maximize:vt,minimize:yt,minus:bt,"moon-star":xt,"mouse-pointer-2":St,palette:Ct,plus:wt,"redo-2":Tt,"refresh-cw":Et,"rotate-ccw-clock":Dt,search:Ot,settings:kt,"share-2":At,spline:jt,"sticky-note":Mt,sun:Nt,table:Pt,"table-properties":Ft,"undo-2":It,"wand-sparkles":Lt,waypoints:Rt,workflow:zt,x:Bt},yM={ZeroOneN:[[`circle`,{cx:`7`,cy:`12`,r:`5`}],[`path`,{d:`M12 12h10`}],[`path`,{d:`M15 6v12`}],[`path`,{d:`M16 12l6-6`}],[`path`,{d:`M16 12l6 6`}]],ZeroOne:[[`path`,{d:`M2 12h3`}],[`circle`,{cx:`10`,cy:`12`,r:`5`}],[`path`,{d:`M15 12h7`}],[`path`,{d:`M20 6v12`}]],ZeroN:[[`path`,{d:`M2 12h3`}],[`circle`,{cx:`10`,cy:`12`,r:`5`}],[`path`,{d:`M15 12h7`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]],OneOnly:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}],[`path`,{d:`M19 6v12`}]],OneN:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]],One:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}]],N:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]]},bM={};xM();function xM(){for(let e of Object.keys(vM))bM[e]={name:e,node:vM[e]};for(let e of Object.keys(yM))bM[e]={name:e,node:yM[e]}}function SM(e){return bM[e]}const CM=`-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Open Sans', system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'`;Pd.global`
|
|
22
|
+
`);t[0]?.trim()===``&&t.shift(),t.length&&t[t.length-1].trim()===``&&t.pop();let n=t.filter(e=>e.trim()!==``).map(e=>(hE.exec(e)?.[0]??``).length),r=n.length?Math.min(...n):0;return t.map(e=>e.slice(r)).join(`
|
|
23
|
+
`)}const xE=/^[0-9a-z ]+$/,SE=/'/g,CE=/\?/g;function wE(e){try{return{ok:!0,model:EE(_E(e))}}catch(e){return{ok:!1,message:e instanceof Error?e.message:`Invalid DBML`}}}function TE(e){let t=0;return{peek:(n=0)=>e[t+n]??null,next:()=>e[t++]??null,atEnd:()=>t>=e.length}}function EE(e){let t=TE(e),n={tables:[],refs:[],enums:{},skipped:[]},r=new Map,i=new Set,a=e=>{i.has(e)||(i.add(e),n.skipped.push(e)),ZE(t)};for(;!t.atEnd();){if($E(t))continue;let e=t.peek();if(!e)break;if(!eD(e)){t.next();continue}let i=e.value.toLowerCase();if(i===`table`&&e.kind===X.identifier){t.next();let e=DE(t,r);e&&n.tables.push(e);continue}if(i===`tablepartial`&&e.kind===X.identifier){t.next();let e=DE(t,r);e&&r.set(e.name,e.columns);continue}if(i===`ref`&&e.kind===X.identifier){t.next(),n.refs.push(...NE(t));continue}if(i===`enum`&&e.kind===X.identifier){t.next(),LE(t,n.enums);continue}a(i)}return n}function DE(e,t){let{schemaName:n,name:r}=GE(e),i={schemaName:n,name:r,alias:``,comment:``,columns:[],indexes:[]},a=e.peek();if(a&&a.kind===X.identifier&&a.value.toLowerCase()===`as`&&(e.next(),i.alias=KE(e)),VE(i,RE(e)),!YE(e))return r===``?null:i;for(;!e.atEnd();){if($E(e))continue;let n=e.peek();if(!n)break;if(n.kind===X.punctuation&&n.value===`}`){e.next();break}if(n.kind===X.punctuation&&n.value===`~`){e.next();let n=t.get(KE(e));n&&i.columns.push(...n.map(e=>({...e})));continue}if(n.kind===X.identifier){let t=n.value.toLowerCase(),r=e.peek(1);if(t===`note`&&r&&Z(r,`:`)){e.next(),e.next(),i.comment=qE(e);continue}if(t===`note`&&r&&Z(r,`{`)){e.next(),e.next(),i.comment=JE(e);continue}if(t===`indexes`&&r&&Z(r,`{`)){e.next(),e.next(),i.indexes.push(...jE(e));continue}if(r&&Z(r,`{`)){e.next(),e.next(),XE(e);continue}}let r=OE(e);r&&i.columns.push(r)}return i}function OE(e){let t=e.peek();if(!t||!eD(t))return QE(e),null;e.next();let n={name:t.value,comment:``,typeName:``,typeSchemaName:``,primaryKey:!1,unique:!1,notNull:!1,autoIncrement:!1,default:``,inlineRefs:[]},r=kE(e);return n.typeName=r.name,n.typeSchemaName=r.schemaName,zE(n,RE(e)),QE(e),n.typeName===``?null:n}function kE(e){let{schemaName:t,name:n}=GE(e);if(n===``)return{name:``,schemaName:``};let r=[n],i=e.peek();i&&Z(i,`(`)&&(e.next(),r.push(`(${AE(e)})`));let a=e.peek(),o=e.peek(1);return a&&o&&Z(a,`[`)&&Z(o,`]`)&&(e.next(),e.next(),r.push(`[]`)),{name:r.join(``),schemaName:t}}function AE(e){let t=[];for(;!e.atEnd();){let n=e.next();if(!n||Z(n,`)`))break;n.kind!==X.newline&&t.push(n.kind===X.string?`'${n.value}'`:n.value)}return t.join(``)}function jE(e){let t=[];for(;!e.atEnd();){if($E(e))continue;let n=e.peek();if(!n)break;if(Z(n,`}`)){e.next();break}let r={name:``,unique:!1,primaryKey:!1,columnNames:[]};Z(n,`(`)?(e.next(),r.columnNames.push(...ME(e))):eD(n)?(e.next(),r.columnNames.push(n.value)):e.next(),BE(r,RE(e)),QE(e),r.columnNames.length!==0&&t.push(r)}return t}function ME(e){let t=[];for(;!e.atEnd();){let n=e.next();if(!n||Z(n,`)`))break;eD(n)&&t.push(n.value)}return t}function NE(e){let t=e.peek();if(t&&eD(t)){let t=e.peek(1);t&&(Z(t,`:`)||Z(t,`{`))&&e.next()}let n=e.peek();if(n&&Z(n,`:`)){e.next();let t=PE(e);return QE(e),t?[t]:[]}if(!YE(e))return QE(e),[];let r=[];for(;!e.atEnd();){if($E(e))continue;let t=e.peek();if(!t)break;if(Z(t,`}`)){e.next();break}let n=PE(e);n?r.push(n):QE(e)}return r}function PE(e){let t=IE(e),n=FE(e);if(n===``)return null;let r=IE(e);return RE(e),t.tableName===``||r.tableName===``?null:{operator:n,left:t,right:r}}function FE(e){let t=e.peek();return t?t.kind===X.operator?(e.next(),t.value.replace(CE,``)):Z(t,`-`)?(e.next(),`-`):``:``}function IE(e){let t=[],n=[];for(;!e.atEnd();){let r=e.peek();if(!r||!eD(r))break;e.next(),t.push(r.value);let i=e.peek();if(!i||!Z(i,`.`))break;e.next();let a=e.peek();if(a&&Z(a,`(`)){e.next(),n.push(...ME(e));break}}n.length===0&&t.length!==0&&n.push(t.pop());let r=t.pop()??``;return{schemaName:t.pop()??``,tableName:r,columnNames:n}}function LE(e,t){let{schemaName:n,name:r}=GE(e);if(RE(e),!YE(e)){QE(e);return}let i=[];for(;!e.atEnd();){if($E(e))continue;let t=e.peek();if(!t)break;if(Z(t,`}`)){e.next();break}eD(t)?(e.next(),i.push(t.value),RE(e)):e.next(),QE(e)}r!==``&&(t[n?`${n}.${r}`:r]=i,n&&!(r in t)&&(t[r]=i))}function RE(e){let t=e.peek();if(!t||!Z(t,`[`))return[];e.next();let n=[],r=[],i=[],a=!1,o=()=>{let e=r.join(` `).toLowerCase();(e!==``||i.length!==0)&&n.push({key:e,tokens:i}),r=[],i=[],a=!1};for(;!e.atEnd();){let t=e.next();if(!t||Z(t,`]`))break;if(Z(t,`,`)){o();continue}if(!a&&Z(t,`:`)){a=!0;continue}if(a){i.push(t);continue}if(eD(t)&&xE.test(t.value.toLowerCase())){r.push(t.value);continue}a=!0,i.push(t)}return o(),n}function zE(e,t){t.forEach(({key:t,tokens:n})=>{switch(t){case`pk`:case`primary key`:e.primaryKey=!0;break;case`unique`:e.unique=!0;break;case`not null`:e.notNull=!0;break;case`increment`:e.autoIncrement=!0;break;case`note`:e.comment=UE(n);break;case`default`:e.default=WE(n);break;case`ref`:{let t=HE(n);t&&e.inlineRefs.push(t);break}}})}function BE(e,t){t.forEach(({key:t,tokens:n})=>{switch(t){case`name`:e.name=UE(n);break;case`unique`:e.unique=!0;break;case`pk`:case`primary key`:e.primaryKey=!0}})}function VE(e,t){t.forEach(({key:t,tokens:n})=>{t===`note`&&(e.comment=UE(n))})}function HE(e){let t=TE(e),n=FE(t);if(n===``)return null;let r=IE(t);return r.tableName===``?null:{operator:n,target:r}}function UE(e){let t=e.find(e=>e.kind===X.string||e.kind===X.quoted||e.kind===X.identifier);return t?t.value:``}function WE(e){let t=e.filter(e=>e.kind!==X.newline),n=t[0];if(!n)return``;if(Z(n,`-`)&&t[1]?.kind===X.number)return`-${t[1].value}`;switch(n.kind){case X.string:return`'${n.value.replace(SE,`''`)}'`;case X.expression:case X.number:case X.identifier:case X.quoted:return n.value;default:return t.map(e=>e.value).join(``)}}function GE(e){let t=KE(e);if(t===``)return{schemaName:``,name:``};let n=e.peek();return!n||!Z(n,`.`)?{schemaName:``,name:t}:(e.next(),{schemaName:t,name:KE(e)})}function KE(e){let t=e.peek();return!t||!eD(t)?``:(e.next(),t.value)}function qE(e){let t=e.peek();return t&&(t.kind===X.string||t.kind===X.quoted)?(e.next(),t.value):``}function JE(e){let t=``;for(;!e.atEnd();){let n=e.next();if(!n||Z(n,`}`))break;t===``&&n.kind===X.string&&(t=n.value)}return t}function YE(e){let t=0;for(;e.peek(t)?.kind===X.newline;)t+=1;let n=e.peek(t);if(!n||!Z(n,`{`))return!1;for(let n=0;n<=t;n+=1)e.next();return!0}function XE(e){let t=1;for(;!e.atEnd()&&t!==0;){let n=e.next();if(!n)break;Z(n,`{`)?t+=1:Z(n,`}`)&&--t}}function ZE(e){if(YE(e)){XE(e);return}for(;!e.atEnd();){let t=e.next();if(!t||t.kind===X.newline)return;if(Z(t,`{`)){XE(e);return}}}function QE(e){for(;!e.atEnd();){let t=e.peek();if(!t)return;if(t.kind===X.newline){e.next();return}if(Z(t,`}`))return;e.next()}}function $E(e){let t=e.peek();return t&&t.kind===X.newline?(e.next(),!0):!1}function eD(e){return e.kind===X.identifier||e.kind===X.quoted}function Z(e,t){return e.kind===X.punctuation&&e.value===t}const tD={tables:[],refs:[],enums:{},skipped:[]};function nD(e,t,n){let r=wE(e),i=r.ok?r.model:tD,a=Jp({}),o=Jh(i.tables.length*100);a.settings.width=o,a.settings.height=o;let{settings:s}=n?n(a):a,c=$T(i,t,s.database);return c.settings=s,Jm(c)}const rD={[I.MariaDB]:`VARCHAR(255)`,[I.MSSQL]:`varchar(255)`,[I.MySQL]:`VARCHAR(255)`,[I.Oracle]:`VARCHAR2(255)`,[I.PostgreSQL]:`varchar(255)`,[I.SQLite]:`TEXT`,[I.Databricks]:`STRING`,[I.Snowflake]:`VARCHAR(255)`},iD={[I.MariaDB]:`INT`,[I.MSSQL]:`int`,[I.MySQL]:`INT`,[I.Oracle]:`INTEGER`,[I.PostgreSQL]:`integer`,[I.SQLite]:`INTEGER`,[I.Databricks]:`INT`,[I.Snowflake]:`INT`},aD={[I.MariaDB]:`SMALLINT`,[I.MSSQL]:`smallint`,[I.MySQL]:`SMALLINT`,[I.Oracle]:`SMALLINT`,[I.PostgreSQL]:`smallint`,[I.SQLite]:`SMALLINT`,[I.Databricks]:`SMALLINT`,[I.Snowflake]:`SMALLINT`},oD={[I.MariaDB]:`BIGINT`,[I.MSSQL]:`bigint`,[I.MySQL]:`BIGINT`,[I.Oracle]:`NUMBER(19)`,[I.PostgreSQL]:`bigint`,[I.SQLite]:`BIGINT`,[I.Databricks]:`BIGINT`,[I.Snowflake]:`BIGINT`},sD={[I.MariaDB]:`DOUBLE`,[I.MSSQL]:`float`,[I.MySQL]:`DOUBLE`,[I.Oracle]:`BINARY_DOUBLE`,[I.PostgreSQL]:`double precision`,[I.SQLite]:`REAL`,[I.Databricks]:`DOUBLE`,[I.Snowflake]:`FLOAT`},cD={[I.MariaDB]:`DECIMAL`,[I.MSSQL]:`decimal`,[I.MySQL]:`DECIMAL`,[I.Oracle]:`DECIMAL`,[I.PostgreSQL]:`numeric`,[I.SQLite]:`DECIMAL`,[I.Databricks]:`DECIMAL`,[I.Snowflake]:`DECIMAL`},lD={[I.MariaDB]:`BOOLEAN`,[I.MSSQL]:`bit`,[I.MySQL]:`BOOLEAN`,[I.Oracle]:`BOOLEAN`,[I.PostgreSQL]:`boolean`,[I.SQLite]:`BOOLEAN`,[I.Databricks]:`BOOLEAN`,[I.Snowflake]:`BOOLEAN`},uD={[I.MariaDB]:`DATE`,[I.MSSQL]:`date`,[I.MySQL]:`DATE`,[I.Oracle]:`DATE`,[I.PostgreSQL]:`date`,[I.SQLite]:`DATE`,[I.Databricks]:`DATE`,[I.Snowflake]:`DATE`},dD={[I.MariaDB]:`TIME`,[I.MSSQL]:`time`,[I.MySQL]:`TIME`,[I.Oracle]:`VARCHAR2(255)`,[I.PostgreSQL]:`time`,[I.SQLite]:`TEXT`,[I.Databricks]:`STRING`,[I.Snowflake]:`TIME`},fD={[I.MariaDB]:`DATETIME`,[I.MSSQL]:`datetime2`,[I.MySQL]:`DATETIME`,[I.Oracle]:`TIMESTAMP`,[I.PostgreSQL]:`timestamp`,[I.SQLite]:`DATETIME`,[I.Databricks]:`TIMESTAMP`,[I.Snowflake]:`TIMESTAMP_NTZ`},pD={[I.MariaDB]:`TIMESTAMP`,[I.MSSQL]:`datetimeoffset`,[I.MySQL]:`TIMESTAMP`,[I.Oracle]:`TIMESTAMP WITH TIME ZONE`,[I.PostgreSQL]:`timestamptz`,[I.SQLite]:`DATETIME`,[I.Databricks]:`TIMESTAMP`,[I.Snowflake]:`TIMESTAMP_TZ`},mD={[I.MariaDB]:`VARCHAR(255)`,[I.MSSQL]:`varchar(255)`,[I.MySQL]:`VARCHAR(255)`,[I.Oracle]:`INTERVAL DAY TO SECOND`,[I.PostgreSQL]:`interval`,[I.SQLite]:`TEXT`,[I.Databricks]:`INTERVAL DAY TO SECOND`,[I.Snowflake]:`VARCHAR(255)`},hD={[I.MariaDB]:`JSON`,[I.MSSQL]:`json`,[I.MySQL]:`JSON`,[I.Oracle]:`JSON`,[I.PostgreSQL]:`jsonb`,[I.SQLite]:`TEXT`,[I.Databricks]:`VARIANT`,[I.Snowflake]:`VARIANT`},gD={[I.MariaDB]:`UUID`,[I.MSSQL]:`uniqueidentifier`,[I.MySQL]:`CHAR(36)`,[I.Oracle]:`VARCHAR2(36)`,[I.PostgreSQL]:`uuid`,[I.SQLite]:`TEXT`,[I.Databricks]:`STRING`,[I.Snowflake]:`UUID`},_D={[I.MariaDB]:`BLOB`,[I.MSSQL]:`varbinary(max)`,[I.MySQL]:`BLOB`,[I.Oracle]:`BLOB`,[I.PostgreSQL]:`bytea`,[I.SQLite]:`BLOB`,[I.Databricks]:`BINARY`,[I.Snowflake]:`BINARY`},vD={id:rD,string:rD,boolean:lD,int:iD,float:sD,positiveint:iD,nonnegativeint:iD,unsignedint:iD,short:aD,smallint:aD,positivefloat:sD,nonnegativefloat:sD,bigint:oD,biginteger:oD,long:oD,int8:oD,safeint:oD,decimal:cD,bigdecimal:cD,numeric:cD,money:cD,datetime:fD,datetimeiso:fD,localdatetime:fD,timestamp:fD,timestamptz:pD,date:uD,localdate:uD,time:dD,localtime:dD,timetz:dD,duration:mD,iso8601duration:mD,interval:mD,json:hD,jsonb:hD,jsonobject:hD,uuid:gD,guid:gD,byte:_D,bytes:_D,bytea:_D,binary:_D,email:rD,emailaddress:rD,url:rD,uri:rD,void:rD};function yD(e,t,n){let r=rD[t]??``,i=CD(n.enums,e);return i?xD(i,t)??r:CD(n.unions,e)?r:vD[e.toLowerCase()]?.[t]??r}function bD(e,t,n){let r=CD(t.enums,e);if(r)return n!==void 0&&xD(r,n)!==void 0?``:SD(e,r);let i=CD(t.unions,e);return i?SD(e,i):``}function xD(e,t){if(t===I.MySQL||t===I.MariaDB)return`ENUM(${e.map(e=>`'${e.replace(/'/g,`''`)}'`).join(`,`)})`}function SD(e,t){return` ${e}: ${t.join(` | `)}`}function CD(e,t){let n=e[t];return Array.isArray(n)&&n.length?n:void 0}function wD(e,t,n){let r=Jp({}),i=TD(e.tables),a=new Set(e.skipped),o=e.tables.map(o=>ED(r,t,e,n,o,i,a));return jD(r,t,o),VD(r,o),r}function TD(e){let t=new Map,n=new Map;for(let r of e){t.set(r.name,r);let e=r.name.toLowerCase();n.has(e)||n.set(e,r)}return e=>t.get(e)??n.get(e.toLowerCase())??null}function ED({doc:e,collections:t},n,r,i,a,o,s){let{toWidth:c}=n,l=[],u=[];for(let e of a.fields){let{named:t}=e.typeRef;s.has(t)||(o(t)?u.push(e):l.push(e))}let d=new Set(DD(l)),f=ng(a.name),p=ng(a.comment),m=NS({name:f,comment:p,ui:{widthName:H(c(f)),widthComment:H(c(p))}}),h={name:f,source:a,table:m,columns:[],referenceFields:u};return l.forEach(e=>{AD(t,h,OD(n,r,i,m.id,e,d.has(e)))}),e.tableIds.push(m.id),M(t).collection(`tableEntities`).setOne(m),h}function DD(e){let t=e.filter(e=>e.primaryKey);if(t.length)return t;let n=e.find(e=>e.typeRef.named===`ID`&&!e.typeRef.isList);if(n)return[n];let r=e.find(e=>e.name.toLowerCase()===`id`);return r?[r]:[]}function OD({toWidth:e},t,n,r,i,a){let{named:o,nonNull:s}=i.typeRef,c=ng(i.name),l=ng(i.dataType)||yD(o,n,t),u=ng(i.default),d=kD(i,t,n);return uC({tableId:r,name:c,comment:d,dataType:l,default:u,options:(i.autoIncrement?R.autoIncrement:0)|(a?R.primaryKey:0)|(i.unique?R.unique:0)|(s?R.notNull:0),ui:{widthName:H(e(c)),widthComment:H(e(d)),widthDataType:H(e(l)),widthDefault:H(e(u)),keys:a?z.primaryKey:0}})}function kD(e,t,n){let{named:r,isList:i}=e.typeRef,a=[],o=ng(e.comment);return o&&a.push(o),i&&a.push(`list of ${r}`),`${a.join(` `)}${bD(r,t,n)}`.trim()}function AD(e,t,n){t.table.columnIds.push(n.id),t.table.seqColumnIds.push(n.id),t.columns.push(n),M(e).collection(`tableColumnEntities`).setOne(n)}function jD(e,t,n){let r=TD(n),i=[];n.forEach(e=>{e.referenceFields.forEach(t=>{let n=r(t.typeRef.named);n&&i.push({source:e,target:n,field:t,consumed:!1})})});let a={claimedColumnIds:new Set,relationshipKeys:new Set},o=i.filter(e=>!e.field.typeRef.isList);[...o.filter(e=>e.field.relationFields.length),...o.filter(e=>!e.field.relationFields.length)].forEach(n=>{if(n.consumed)return;let r=MD(i,n);n.consumed=!0,r&&(r.consumed=!0);let o=!!r?.field.typeRef.isList;PD(e,t,a,{parent:n.target,child:n.source,field:n.field,childSide:!0,relationshipType:n.field.typeRef.nonNull?o?rh.OneN:rh.OneOnly:o?rh.ZeroN:rh.ZeroOne})}),i.filter(e=>e.field.typeRef.isList).forEach(r=>{if(r.consumed)return;let o=ND(i,r);if(r.consumed=!0,o){o.consumed=!0,zD(e,t,n,r);return}PD(e,t,a,{parent:r.source,child:r.target,field:r.field,childSide:!1,relationshipType:r.field.typeRef.nonNull?rh.OneN:rh.ZeroN})})}function MD(e,t){let n=e.filter(e=>e!==t&&!e.consumed&&e.source===t.target&&e.target===t.source);if(!n.length)return null;let{relationName:r}=t.field;if(r)return n.find(e=>e.field.relationName===r)??null;if(t.source===t.target)return n.length===1?n[0]:null;let i=e.filter(e=>!e.consumed&&e.source===t.source&&e.target===t.target);return n.length===1&&i.length===1?n[0]:null}function ND(e,t){if(e.some(e=>!e.field.typeRef.isList&&(e.source===t.source&&e.target===t.target||e.source===t.target&&e.target===t.source)))return null;let n=e.filter(e=>e!==t&&!e.consumed&&e.field.typeRef.isList&&e.source===t.target&&e.target===t.source);if(!n.length)return null;let{relationName:r}=t.field;return r?n.find(e=>e.field.relationName===r)??null:n[0]}function PD(e,t,n,r){let{doc:i,collections:a}=e,{parent:o,child:s,relationshipType:c}=r,l=xw(o.columns);if(!l.length)return;let{startColumns:u,endColumns:d}=FD(e,t,n,r,l);if(!d.length)return;let f=`${o.table.id}:${s.table.id}:${d.map(e=>e.id).join(`,`)}`;if(n.relationshipKeys.has(f))return;n.relationshipKeys.add(f),d.forEach(e=>{W(e.ui.keys,z.primaryKey)?e.ui.keys|=z.foreignKey:e.ui.keys=z.foreignKey,n.claimedColumnIds.add(e.id)});let p=pS({identification:d.every(e=>W(e.ui.keys,z.primaryKey)&&W(e.ui.keys,z.foreignKey)),relationshipType:c,start:{tableId:o.table.id,columnIds:u.map(e=>e.id)},end:{tableId:s.table.id,columnIds:d.map(e=>e.id)}});i.relationshipIds.push(p.id),M(a).collection(`relationshipEntities`).setOne(p)}function FD(e,t,n,{parent:r,child:i,field:a,childSide:o},s){if(o&&a.relationFields.length){let e=[],t=[];if(a.relationFields.forEach((n,o)=>{let c=Cw(i.columns,n),l=a.relationReferences[o],u=l?Cw(r.columns,l):s[o]??null;!c||!u||(e.push(u),t.push(c))}),t.length)return{startColumns:e,endColumns:t}}let c=o?ng(a.name):pe(r.name),l=new Set,u=[],d=[];return s.forEach(o=>{let s=ID(c,r.name,o.name),f=LD(i.columns,s,e=>l.has(e)?!0:n.claimedColumnIds.has(e))??RD(e,t,i,a,o,s[0]);l.add(f.id),u.push(o),d.push(f)}),{startColumns:u,endColumns:d}}function ID(e,t,n){return[`${e}${Zv(n)}`,`${ve(e)}_${ve(n)}`,`${t}${Zv(n)}`,`${ve(t)}_${ve(n)}`,`${e}Id`,`${ve(e)}_id`]}function LD(e,t,n){for(let r of t){let t=Cw(e,r);if(t&&!n(t.id))return t}return null}function RD({collections:e},{toWidth:t},n,r,i,a){let o=Sw(n.columns,``,a),{dataType:s}=i,c=uC({tableId:n.table.id,name:o,dataType:s,options:r.typeRef.nonNull?R.notNull:0,ui:{keys:z.foreignKey,widthName:H(t(o)),widthDataType:H(t(s))}});return AD(e,n,c),c}function zD(e,t,n,r){let{doc:i,collections:a}=e,{toWidth:o}=t,s=r.source,c=r.target,l=xw(s.columns),u=xw(c.columns);if(!l.length||!u.length)return;let d=Sw(n.map(e=>e.table),``,`${s.name}_${c.name}`),f=`Junction table inferred from ${s.name} <-> ${c.name}`,p=NS({name:d,comment:f,ui:{widthName:H(o(d)),widthComment:H(o(f))}}),m={name:d,source:{name:d,comment:f,fields:[],indexes:[]},table:p,columns:[],referenceFields:[]};i.tableIds.push(p.id),M(a).collection(`tableEntities`).setOne(p),n.push(m),BD(e,t,m,s,l),BD(e,t,m,c,u)}function BD(e,{toWidth:t},n,r,i){let{doc:a,collections:o}=e,s=i.map(e=>{let i=Sw(n.columns,``,`${pe(r.name)}${Zv(e.name)}`),{dataType:a}=e,s=uC({tableId:n.table.id,name:i,dataType:a,options:R.primaryKey|R.notNull,ui:{keys:z.primaryKey|z.foreignKey,widthName:H(t(i)),widthDataType:H(t(a))}});return AD(o,n,s),s}),c=pS({identification:!0,relationshipType:rh.ZeroN,start:{tableId:r.table.id,columnIds:i.map(e=>e.id)},end:{tableId:n.table.id,columnIds:s.map(e=>e.id)}});a.relationshipIds.push(c.id),M(o).collection(`relationshipEntities`).setOne(c)}function VD({doc:e,collections:t},n){n.forEach(({source:n,table:r,columns:i})=>{n.indexes.forEach(n=>{let a=rx({name:ng(n.name),tableId:r.id,unique:n.unique}),o=[];n.fieldNames.forEach(e=>{let t=Cw(i,e);t&&o.push(bx({indexId:a.id,columnId:t.id,orderType:ah.ASC}))}),o.length&&(o.forEach(e=>{a.indexColumnIds.push(e.id),a.seqIndexColumnIds.push(e.id),M(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(a.id),M(t).collection(`indexEntities`).setOne(a))})})}const HD=[`Query`,`Mutation`,`Subscription`],UD=[`PageInfo`],WD=[`Connection`,`Edge`],GD=[`_aggregate`,`_aggregate_fields`,`_mutation_response`,`_max_fields`,`_min_fields`,`_sum_fields`,`_avg_fields`,`_stddev_fields`,`_variance_fields`,`_bool_exp`,`_order_by`,`_insert_input`,`_set_input`,`_on_conflict`,`_constraint`,`_update_column`,`_select_column`],KD=[`_Service`,`_Entity`,`_Any`,`_FieldSet`],qD=[`autoincrement`,`autoincrement()`],JD=/[_A-Za-z]/,YD=/[_0-9A-Za-z]/;function XD(e){try{return{ok:!0,model:$D(ZD(e))}}catch(e){return{ok:!1,message:QD(e)}}}function ZD(e){try{return Ze(e)}catch(t){let n=vO(e);if(n===e)throw t;try{return Ze(n)}catch{throw t}}}function QD(e){let t=e instanceof Error?e.message:String(e),n=e?.locations?.[0];if(!n)return t;let r=t.replace(/^Syntax Error:\s*/,``);return`Syntax Error at line ${n.line}, column ${n.column}: ${r}`}function $D(e){let t={},n={},r=[],i=new Map,a=new Map,o=new Set;for(let s of e.definitions)switch(s.kind){case Ye.OBJECT_TYPE_DEFINITION:case Ye.OBJECT_TYPE_EXTENSION:tO(a,s);break;case Ye.INTERFACE_TYPE_DEFINITION:case Ye.INTERFACE_TYPE_EXTENSION:{let e=s.name.value,t=i.get(e)??[];t.push(...s.fields??[]),i.set(e,t);break}case Ye.SCHEMA_DEFINITION:case Ye.SCHEMA_EXTENSION:for(let e of s.operationTypes??[])o.add(e.type.name.value);break;case Ye.ENUM_TYPE_DEFINITION:t[s.name.value]=(s.values??[]).map(e=>e.name.value);break;case Ye.UNION_TYPE_DEFINITION:n[s.name.value]=(s.types??[]).map(e=>e.name.value);break;case Ye.SCALAR_TYPE_DEFINITION:r.push(s.name.value)}let s=o.size?o:new Set(HD),c=[],l=[],u=new Map;for(let e of a.values()){if(mO(e.name,s)){l.push(e.name);continue}let t=nO(e,i);if(!t.fields.length){l.push(e.name);continue}t.name!==e.name&&u.set(e.name,t.name),c.push(t)}return eO(c,u),{tables:c,enums:t,customScalars:r,unions:n,skipped:l}}function eO(e,t){if(t.size)for(let n of e)for(let e of n.fields){let n=t.get(e.typeRef.named);n&&(e.typeRef.named=n)}}function tO(e,t){let n=t.name.value,r=(t.interfaces??[]).map(e=>e.name.value),i=e.get(n);if(i){i.fieldNodes.push(...t.fields??[]),i.interfaceNames.push(...r),i.directives.push(...t.directives??[]),i.comment||=gO(t);return}e.set(n,{name:n,comment:gO(t),interfaceNames:r,fieldNodes:[...t.fields??[]],directives:[...t.directives??[]]})}function nO(e,t){let n=rO(e.fieldNodes),r=new Set(n.map(e=>e.name.value)),i=[];for(let n of e.interfaceNames)for(let e of t.get(n)??[]){let t=e.name.value;r.has(t)||(r.add(t),i.push(e))}let a={name:e.name,comment:e.comment,fields:[...i,...n].map(iO).filter(ue),indexes:[]};for(let t of e.directives)sO(a,t);return a}function rO(e){let t=new Set;return e.filter(e=>{let n=e.name.value;return!t.has(n)&&(t.add(n),!0)})}function iO(e){if(e.name.value.startsWith(`__`))return null;let t={name:e.name.value,comment:gO(e),typeRef:aO(e.type),primaryKey:!1,unique:!1,autoIncrement:!1,default:``,dataType:``,relationName:``,relationFields:[],relationReferences:[],hasArguments:(e.arguments??[]).length>0};for(let n of e.directives??[])oO(t,n);return t}function aO(e){let t=e.kind===Ye.NON_NULL_TYPE,n=t?e.type:e,r=n.kind===Ye.LIST_TYPE,i=r?n.type:n,a=r&&i.kind===Ye.NON_NULL_TYPE,o=i;for(;o.kind!==Ye.NAMED_TYPE;)o=o.type;return{named:o.name.value,nonNull:t,isList:r,itemNonNull:a}}function oO(e,t){let n=t.name.value;if(n.startsWith(`db_`)){e.dataType=cO(n,t);return}switch(n){case`id`:case`primaryKey`:e.primaryKey=!0;break;case`unique`:e.unique=!0;break;case`autoincrement`:case`autoIncrement`:e.autoIncrement=!0;break;case`default`:{let n=lO(t,`value`);if(!n)break;let r=fO(n);qD.includes(r.toLowerCase())?e.autoIncrement=!0:e.default=r;break}case`map`:{let n=uO(t,`name`)||uO(t,`value`);n&&(e.name=n);break}case`relation`:{let n=uO(t,`name`)||uO(t,`value`);n&&(e.relationName=n);let r=lO(t,`fields`);r&&(e.relationFields=pO(r));let i=lO(t,`references`);i&&(e.relationReferences=pO(i));break}case`column`:{let n=uO(t,`name`);n&&(e.name=n);let r=uO(t,`dataType`);r&&(e.dataType=r);let i=lO(t,`default`);i&&(e.default=fO(i));let a=dO(t,`autoIncrement`);a!==null&&(e.autoIncrement=a);let o=dO(t,`unique`);o!==null&&(e.unique=o);let s=dO(t,`primaryKey`);s!==null&&(e.primaryKey=s);break}}}function sO(e,t){switch(t.name.value){case`map`:{let n=uO(t,`name`)||uO(t,`value`);n&&(e.name=n);break}case`table`:{let n=uO(t,`name`);n&&(e.name=n);let r=lO(t,`comment`);r&&(e.comment=fO(r));break}case`index`:{let n=lO(t,`fields`),r=n?pO(n):[];if(!r.length)break;let i={name:uO(t,`name`),unique:dO(t,`unique`)??!1,fieldNames:r};e.indexes.push(i);break}}}function cO(e,t){let n=e.slice(3),r=t.arguments??[];return r.length?`${n}(${r.map(e=>fO(e.value)).join(`, `)})`:n}function lO(e,t){let n=(e.arguments??[]).find(e=>e.name.value===t);return n?n.value:null}function uO(e,t){let n=lO(e,t);return n?fO(n):``}function dO(e,t){let n=lO(e,t);return n?fO(n)===`true`:null}function fO(e){switch(e.kind){case Ye.STRING:case Ye.INT:case Ye.FLOAT:case Ye.ENUM:return e.value;case Ye.BOOLEAN:return e.value?`true`:`false`;case Ye.NULL:return`null`;case Ye.LIST:return e.values.map(fO).join(`, `);default:return``}}function pO(e){return(e.kind===Ye.LIST?e.values:[e]).map(fO).filter(e=>e!==``)}function mO(e,t){return t.has(e)||e.startsWith(`__`)||KD.includes(e)||UD.includes(e)||WD.some(t=>hO(e,t))||GD.some(t=>hO(e,t))}function hO(e,t){return e.length>t.length&&e.endsWith(t)}function gO(e){if(e.description)return _O(e.description.value);if(!e.loc)return``;let t=[],n=e.loc.startToken.line-1,r=e.loc.startToken.prev;for(;r&&r.kind===Xe.COMMENT&&r.line===n&&(!r.prev||r.prev.line<r.line);)t.unshift(r.value??``),--n,r=r.prev;return _O(t.join(` `))}function _O(e){return e.replace(/\s+/g,` `).trim()}function vO(e){let t=``,n=0,r=!1;for(;n<e.length;){let i=e[n];if(i===`#`){let r=xO(e,n);t+=e.slice(n,r),n=r;continue}if(i===`"`){let r=SO(e,n);t+=e.slice(n,r),n=r;continue}if(i!==`@`||!JD.test(e[n+1]??``)){t+=i,n+=1;continue}let a=bO(e,n+1),o=e.slice(n+1,a);for(;e[a]===`.`&&JD.test(e[a+1]??``);){let t=bO(e,a+1);o+=`_${e.slice(a+1,t)}`,a=t,r=!0}t+=`@${o}`,n=a;let s=wO(e,n);if(e[s]===`(`){t+=e.slice(n,s+1),n=s+1;for(let i=0;n<e.length;i++){let a=wO(e,n);if(t+=e.slice(n,a),n=a,e[n]===`)`||n>=e.length)break;let o=yO(e,n);o===-1?(t+=i===0?`value: `:`value${i}: `,r=!0):(t+=e.slice(n,o+1),n=o+1);let s=Math.max(CO(e,wO(e,n)),n+1);t+=e.slice(n,s),n=s}}}return r?t:e}function yO(e,t){if(!JD.test(e[t]??``))return-1;let n=wO(e,bO(e,t));return e[n]===`:`?n:-1}function bO(e,t){let n=t;for(;n<e.length&&YD.test(e[n]);)n+=1;return n}function xO(e,t){let n=e.indexOf(`
|
|
24
|
+
`,t);return n===-1?e.length:n}function SO(e,t){if(e.startsWith(`"""`,t)){let n=e.indexOf(`"""`,t+3);return n===-1?e.length:n+3}let n=t+1;for(;n<e.length;){let t=e[n];if(t===`\\`){n+=2;continue}if(t===`
|
|
25
|
+
`)return n;if(t===`"`)return n+1;n+=1}return n}function CO(e,t){let n=[],r=t;for(;r<e.length;){let t=e[r];if(t===`"`){r=SO(e,r);continue}if(t===`[`||t===`{`){n.push(t),r+=1;continue}if(t===`]`||t===`}`){if(!n.length)break;if(n.pop(),r+=1,!n.length)return r;continue}if(!n.length&&(t===`)`||t===`,`||t===`#`)||!n.length&&/\s/.test(t))break;r+=1}return r}function wO(e,t){let n=t;for(;n<e.length;){let t=e[n];if(t===`#`){n=xO(e,n);continue}if(!/[\s,]/.test(t))break;n+=1}return n}const TO={tables:[],enums:{},customScalars:[],unions:{},skipped:[]};function EO(e,t,n){let r=XD(e),i=r.ok?r.model:TO,a=Jp({}),o=Jh(i.tables.length*100);a.settings.width=o,a.settings.height=o;let{settings:s}=n?n(a):a,c=wD(i,t,s.database);return c.settings=s,Jm(c)}var DO={createTable:`create.table`,createIndex:`create.index`,alterTableAddUnique:`alter.table.add.unique`,alterTableAddPrimaryKey:`alter.table.add.primaryKey`,alterTableAddForeignKey:`alter.table.add.foreignKey`,commentOnTable:`comment.on.table`,commentOnColumn:`comment.on.column`},OO={asc:`ASC`,desc:`DESC`},kO={string:`string`,leftParent:`leftParent`,rightParent:`rightParent`,leftBracket:`leftBracket`,rightBracket:`rightBracket`,comma:`comma`,period:`period`,equal:`equal`,semicolon:`semicolon`},AO={doubleQuote:`"`,dash:`-`,slash:`/`,asterisk:`*`,newLine:`
|
|
26
|
+
`,singleQuote:`'`,backtick:"`",whiteSpace:/\s/,string:/\S/,breakString:/;|,|\(|\)|\[|\]|\.|=/,equal:`=`,period:`.`,comma:`,`,semicolon:`;`,leftParent:`(`,rightParent:`)`,leftBracket:`[`,rightBracket:`]`},jO=e=>t=>e===t,MO=e=>t=>e.test(t),Q={doubleQuote:jO(AO.doubleQuote),dash:jO(AO.dash),slash:jO(AO.slash),asterisk:jO(AO.asterisk),newLine:jO(AO.newLine),singleQuote:jO(AO.singleQuote),backtick:jO(AO.backtick),whiteSpace:MO(AO.whiteSpace),string:MO(AO.string),breakString:MO(AO.breakString),equal:jO(AO.equal),period:jO(AO.period),comma:jO(AO.comma),semicolon:jO(AO.semicolon),leftParent:jO(AO.leftParent),rightParent:jO(AO.rightParent),leftBracket:jO(AO.leftBracket),rightBracket:jO(AO.rightBracket)};function NO(e){let t=[],n=0,r=()=>n<e.length;for(;r();){let i=e[n];if(Q.whiteSpace(i)){let t=``;for(;r()&&Q.whiteSpace(i);)t+=i,i=e[++n];continue}if(Q.dash(i)&&Q.dash(e[n+1])){for(;r()&&!Q.newLine(i);)i=e[++n];continue}if(Q.slash(i)&&Q.asterisk(e[n+1])){for(n+=2,i=e[n];r()&&!(Q.asterisk(i)&&Q.slash(e[n+1]));)i=e[++n];n+=2;continue}if(Q.leftParent(i)){t.push({type:kO.leftParent,value:i}),n++;continue}if(Q.rightParent(i)){t.push({type:kO.rightParent,value:i}),n++;continue}if(Q.comma(i)){t.push({type:kO.comma,value:i}),n++;continue}if(Q.period(i)){t.push({type:kO.period,value:i}),n++;continue}if(Q.equal(i)){t.push({type:kO.equal,value:i}),n++;continue}if(Q.semicolon(i)){t.push({type:kO.semicolon,value:i}),n++;continue}if(Q.rightBracket(i)){t.push({type:kO.rightBracket,value:i}),n++;continue}if(Q.leftBracket(i)){let a=``;for(i=e[++n];r()&&!Q.rightBracket(i);)a+=i,i=e[++n];t.push({type:kO.string,value:a,quoted:!0}),n++;continue}if(Q.doubleQuote(i)){let a=``;for(i=e[++n];r()&&!Q.doubleQuote(i);)a+=i,i=e[++n];t.push({type:kO.string,value:a,quoted:!0}),n++;continue}if(Q.singleQuote(i)){let a=``;for(i=e[++n];r()&&!Q.singleQuote(i);)a+=i,i=e[++n];t.push({type:kO.string,value:a,quoted:!0}),n++;continue}if(Q.backtick(i)){let a=``;for(i=e[++n];r()&&!Q.backtick(i);)a+=i,i=e[++n];t.push({type:kO.string,value:a,quoted:!0}),n++;continue}if(Q.string(i)){let a=``;for(;r()&&Q.string(i)&&!Q.breakString(i)&&!(Q.dash(i)&&Q.dash(e[n+1]))&&!(Q.slash(i)&&Q.asterisk(e[n+1]));)a+=i,i=e[++n];t.push({type:kO.string,value:a});continue}n++}return t}var PO=`ARRAY.BIGINT.BINARY.BOOLEAN.BYTE.CHAR.DATE.DEC.DECIMAL.DOUBLE.FLOAT.GEOGRAPHY.GEOMETRY.INT.INTEGER.INTERVAL DAY TO HOUR.INTERVAL DAY TO MINUTE.INTERVAL DAY TO SECOND.INTERVAL DAY.INTERVAL HOUR TO MINUTE.INTERVAL HOUR TO SECOND.INTERVAL HOUR.INTERVAL MINUTE TO SECOND.INTERVAL MINUTE.INTERVAL MONTH.INTERVAL SECOND.INTERVAL YEAR TO MONTH.INTERVAL YEAR.INTERVAL.LONG.MAP.NUMERIC.OBJECT.REAL.SHORT.SMALLINT.STRING.STRUCT.TIMESTAMP_LTZ.TIMESTAMP_NTZ.TIMESTAMP.TINYINT.VARCHAR.VARIANT.VOID`.split(`.`),FO=`BIGINT.BINARY.BIT.BLOB.BOOL.BOOLEAN.CHAR BYTE.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.CLOB.DATE.DATETIME.DEC.DECIMAL.DOUBLE PRECISION.DOUBLE.ENUM.FIXED.FLOAT.FLOAT4.FLOAT8.GEOMETRY.GEOMETRYCOLLECTION.INET4.INET6.INT.INT1.INT2.INT3.INT4.INT8.INTEGER.JSON.LINESTRING.LONG CHAR VARYING.LONG CHARACTER VARYING.LONG VARBINARY.LONG VARCHAR.LONG VARCHARACTER.LONG.LONGBLOB.LONGTEXT.MEDIUMBLOB.MEDIUMINT.MEDIUMTEXT.MIDDLEINT.MULTILINESTRING.MULTIPOINT.MULTIPOLYGON.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL VARCHAR.NATIONAL VARCHARACTER.NCHAR VARCHAR.NCHAR VARCHARACTER.NCHAR VARYING.NCHAR.NUMBER.NUMERIC.NVARCHAR.POINT.POLYGON.RAW.REAL.SERIAL.SET.SMALLINT.SQL_TSI_YEAR.TEXT.TIME.TIMESTAMP.TINYBLOB.TINYINT.TINYTEXT.UUID.VARBINARY.VARCHAR.VARCHAR2.VARCHARACTER.VECTOR.XMLTYPE.YEAR`.split(`.`),IO=`BIGINT.BINARY VARYING.BINARY.BIT.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.DATE.DATETIME.DATETIME2.DATETIMEOFFSET.DEC.DECIMAL.DOUBLE PRECISION.FLOAT.GEOGRAPHY.GEOMETRY.HIERARCHYID.IMAGE.INT.INTEGER.JSON.MONEY.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL TEXT.NCHAR.NTEXT.NUMERIC.NVARCHAR.REAL.ROWVERSION.SMALLDATETIME.SMALLINT.SMALLMONEY.SQL_VARIANT.TEXT.TIME.TIMESTAMP.TINYINT.UNIQUEIDENTIFIER.VARBINARY.VARCHAR.VECTOR.XML`.split(`.`),LO=`BIGINT.BINARY.BIT.BLOB.BOOL.BOOLEAN.CHAR BYTE.CHAR.CHARACTER VARYING.CHARACTER.DATE.DATETIME.DEC.DECIMAL.DOUBLE PRECISION.DOUBLE.ENUM.FIXED.FLOAT.FLOAT4.FLOAT8.GEOMCOLLECTION.GEOMETRY.GEOMETRYCOLLECTION.INT.INT1.INT2.INT3.INT4.INT8.INTEGER.JSON.LINESTRING.LONG VARBINARY.LONG VARCHAR.LONG.LONGBLOB.LONGTEXT.MEDIUMBLOB.MEDIUMINT.MEDIUMTEXT.MIDDLEINT.MULTILINESTRING.MULTIPOINT.MULTIPOLYGON.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NATIONAL VARCHAR.NCHAR VARCHAR.NCHAR.NUMERIC.NVARCHAR.POINT.POLYGON.REAL.SERIAL.SET.SMALLINT.TEXT.TIME.TIMESTAMP.TINYBLOB.TINYINT.TINYTEXT.VARBINARY.VARCHAR.VARCHARACTER.YEAR`.split(`.`),RO=`ANYDATA.BFILE.BINARY_DOUBLE.BINARY_FLOAT.BLOB.BOOL.BOOLEAN.CHAR VARYING.CHAR.CHARACTER VARYING.CHARACTER.CLOB.DATE.DEC.DECIMAL.DOUBLE PRECISION.FLOAT.INT.INTEGER.INTERVAL DAY TO SECOND.INTERVAL YEAR TO MONTH.JSON.LONG RAW.LONG VARCHAR.LONG.NATIONAL CHAR VARYING.NATIONAL CHAR.NATIONAL CHARACTER VARYING.NATIONAL CHARACTER.NCHAR VARYING.NCHAR.NCLOB.NUMBER.NUMERIC.NVARCHAR2.RAW.REAL.ROWID.SDO_GEOMETRY.SDO_GEORASTER.SDO_TOPO_GEOMETRY.SMALLINT.TIMESTAMP WITH LOCAL TIME ZONE.TIMESTAMP WITH TIME ZONE.TIMESTAMP.URIType.UROWID.VARCHAR.VARCHAR2.VECTOR.XMLType`.split(`.`),zO=`BIGINT.BIGSERIAL.BIT VARYING.BIT.BOOL.BOOLEAN.BOX.BPCHAR.BYTEA.CHAR.CHARACTER VARYING.CHARACTER.CID.CIDR.CIRCLE.DATE.DATEMULTIRANGE.DATERANGE.DECIMAL.DOUBLE PRECISION.FLOAT.FLOAT4.FLOAT8.INET.INT.INT2.INT4.INT4MULTIRANGE.INT4RANGE.INT8.INT8MULTIRANGE.INT8RANGE.INTEGER.INTERVAL DAY TO HOUR.INTERVAL DAY TO MINUTE.INTERVAL DAY TO SECOND.INTERVAL DAY.INTERVAL HOUR TO MINUTE.INTERVAL HOUR TO SECOND.INTERVAL HOUR.INTERVAL MINUTE TO SECOND.INTERVAL MINUTE.INTERVAL MONTH.INTERVAL SECOND.INTERVAL YEAR TO MONTH.INTERVAL YEAR.INTERVAL.JSON.JSONB.JSONPATH.LINE.LSEG.MACADDR.MACADDR8.MONEY.NAME.NUMERIC.NUMMULTIRANGE.NUMRANGE.OID.PATH.PG_LSN.PG_SNAPSHOT.POINT.POLYGON.REAL.REGCLASS.REGCOLLATION.REGCONFIG.REGDICTIONARY.REGNAMESPACE.REGOPER.REGOPERATOR.REGPROC.REGPROCEDURE.REGROLE.REGTYPE.SERIAL.SERIAL2.SERIAL4.SERIAL8.SMALLINT.SMALLSERIAL.TEXT.TID.TIME WITH TIME ZONE.TIME WITHOUT TIME ZONE.TIME.TIMESTAMP WITH TIME ZONE.TIMESTAMP WITHOUT TIME ZONE.TIMESTAMP.TIMESTAMPTZ.TIMETZ.TSMULTIRANGE.TSQUERY.TSRANGE.TSTZMULTIRANGE.TSTZRANGE.TSVECTOR.TXID_SNAPSHOT.UUID.VARBIT.VARCHAR.XID.XID8.XML`.split(`.`),BO=`ARRAY.BIGINT.BINARY.BOOLEAN.BYTEINT.CHAR VARYING.CHAR.CHARACTER.DATE.DATETIME.DEC.DECFLOAT.DECIMAL.DOUBLE PRECISION.DOUBLE.FILE.FLOAT.FLOAT4.FLOAT8.GEOGRAPHY.GEOMETRY.INT.INTEGER.MAP.NCHAR VARYING.NCHAR.NUMBER.NUMERIC.NVARCHAR.NVARCHAR2.OBJECT.REAL.SMALLINT.STRING.TEXT.TIME.TIMESTAMP WITH LOCAL TIME ZONE.TIMESTAMP WITH TIME ZONE.TIMESTAMP WITHOUT TIME ZONE.TIMESTAMP_LTZ.TIMESTAMP_NTZ.TIMESTAMP_TZ.TIMESTAMP.TIMESTAMPLTZ.TIMESTAMPNTZ.TIMESTAMPTZ.TINYINT.UNKNOWN.UUID.VARBINARY.VARCHAR.VARCHAR2.VARIANT.VECTOR`.split(`.`),VO=`BIGINT.BLOB.BOOLEAN.CHARACTER.CLOB.DATE.DATETIME.DECIMAL.DOUBLE PRECISION.DOUBLE.FLOAT.INT.INT2.INT8.INTEGER.MEDIUMINT.NATIVE CHARACTER.NCHAR.NUMERIC.NVARCHAR.REAL.SMALLINT.TEXT.TINYINT.UNSIGNED BIG INT.VARCHAR.VARYING CHARACTER`.split(`.`),HO=e=>t=>n=>t[n]?t[n].type===e:!1,$=e=>{let t=e.toUpperCase();return e=>n=>{let r=e[n];return r?!r.quoted&&r.value.toUpperCase()===t:!1}},UO=HO(kO.string),WO=HO(kO.equal),GO=HO(kO.period),KO=HO(kO.comma),qO=HO(kO.semicolon),JO=HO(kO.leftParent),YO=HO(kO.rightParent);kO.leftBracket,kO.rightBracket;var XO=$(`CREATE`),ZO=$(`ALTER`),QO=$(`DROP`),$O=$(`USE`),ek=$(`RENAME`),tk=$(`DELETE`),nk=$(`SELECT`),rk=$(`TABLE`),ik=$(`INDEX`),ak=$(`UNIQUE`),ok=$(`ADD`),sk=$(`PRIMARY`),ck=$(`KEY`),lk=$(`CONSTRAINT`),uk=$(`FOREIGN`),dk=$(`NOT`),fk=$(`NULL`),pk=$(`DEFAULT`),mk=$(`COMMENT`),hk=$(`REFERENCES`),gk=$(`ASC`),_k=$(`DESC`),vk=$(`ON`),yk=$(`AUTO_INCREMENT`),bk=$(`AUTOINCREMENT`),xk=$(`IF`),Sk=$(`EXISTS`),Ck=$(`ONLY`),wk=$(`IS`),Tk=$(`COLUMN`),Ek=$(`CHARACTER`),Dk=$(`SET`),Ok=$(`COLLATE`),kk=$(`ENFORCED`),Ak=$(`RELY`),jk=$(`NORELY`),Mk=$(`DEFERRABLE`),Nk=$(`INITIALLY`),Pk=$(`DEFERRED`),Fk=$(`IMMEDIATE`),Ik=$(`IDENTITY`),Lk=$(`FUNCTION`),Rk=$(`CLUSTER`),zk=$(`BY`),Bk=$(`FULLTEXT`),Vk=$(`SPATIAL`),Hk=e=>{let t=kk(e),n=Ak(e),r=jk(e),i=Mk(e),a=Nk(e),o=Pk(e),s=Fk(e);return e=>t(e)||n(e)||r(e)||i(e)||a(e)||o(e)||s(e)},Uk=[[`SET`,`NULL`],[`SET`,`DEFAULT`],[`NO`,`ACTION`],[`CASCADE`],[`RESTRICT`]],Wk=[`FULL`,`PARTIAL`,`SIMPLE`],Gk=e=>{let t=t=>{let n=e[t];return n&&n.type===kO.string&&!n.quoted?n.value.toUpperCase():``};return e=>t(e)===`ON`&&[`DELETE`,`UPDATE`].includes(t(e+1))?2+(Uk.find(n=>n.every((n,r)=>t(e+2+r)===n))?.length??0):t(e)===`MATCH`&&Wk.includes(t(e+1))?2:0},Kk=e=>{let t=Bk(e),n=Vk(e),r=ik(e),i=ck(e);return e=>(t(e)||n(e))&&(r(e+1)||i(e+1))},qk=[`ARRAY`,`MAP`,`STRUCT`],Jk=e=>{let t=UO(e),n=e=>{let t=0;for(let n of e)n===`<`?t++:n===`>`&&t--;return t};return r=>{let i=e[r];if(!i||i.quoted||!t(r))return 0;let a=i.value.indexOf(`<`);if(a===-1||!qk.includes(i.value.slice(0,a).toUpperCase()))return 0;let o=0;for(let t=r;t<e.length;t++)if(o+=n(e[t].value),o<=0)return t-r+1;return e.length-r}},Yk=e=>{let t=yk(e),n=bk(e),r=Ik(e);return e=>t(e)||n(e)||r(e)},Xk=e=>{let t=Rk(e),n=zk(e);return e=>t(e)&&n(e+1)},Zk=e=>{let t=mk(e),n=vk(e);return e=>t(e)&&n(e+1)},Qk=e=>{let t=Zk(e),n=rk(e);return e=>t(e)&&n(e+2)},$k=e=>{let t=Zk(e),n=Tk(e);return e=>t(e)&&n(e+2)},eA=e=>{let t=XO(e),n=ZO(e),r=QO(e),i=$O(e),a=ek(e),o=tk(e),s=nk(e),c=Zk(e);return e=>t(e)||n(e)||r(e)||i(e)||a(e)||o(e)||s(e)||c(e)},tA=[`OR`,`REPLACE`,`TRANSIENT`,`TEMPORARY`,`TEMP`,`LOCAL`,`GLOBAL`,`VOLATILE`,`UNLOGGED`,`HYBRID`,`ICEBERG`,`DYNAMIC`,`EXTERNAL`],nA=e=>{let t=XO(e),n=rk(e),r=UO(e),i=Lk(e),a=xk(e),o=dk(e),s=Sk(e);return c=>{if(!t(c))return 0;let l=c+1;for(;l<e.length&&!n(l);){let t=e[l];if(!r(l)||t.quoted||!tA.includes(t.value.toUpperCase()))return 0;l++}return!n(l)||i(l+1)?0:(l++,a(l)&&o(l+1)&&s(l+2)&&(l+=3),l-c)}},rA=e=>{let t=Ek(e),n=Dk(e);return e=>t(e)&&n(e+1)},iA=e=>{let t=nA(e);return e=>t(e)>0},aA=e=>{let t=XO(e),n=ik(e),r=ak(e);return e=>t(e)&&r(e+1)&&n(e+2)},oA=e=>{let t=XO(e),n=ik(e),r=aA(e);return e=>t(e)&&n(e+1)||r(e)},sA=e=>{let t=ZO(e),n=rk(e);return e=>t(e)&&n(e+1)},cA=e=>{let t=UO(e),n=GO(e);return e=>{if(!t(e))return 0;let r=e+1;for(;n(r)&&t(r+1);)r+=2;return r-e}},lA=e=>{let t=sA(e),n=Ck(e),r=ok(e),i=lk(e),a=UO(e),o=cA(e),s=(e,t)=>{let n=t,s=o(n);return!s||(n+=s,!r(n))?0:(n++,i(n)&&a(n+1)&&(n+=2),n-e)};return e=>{if(!t(e))return{length:0,only:!1};let r=e+2;if(n(r)){let t=s(e,r+1);if(t)return{length:t,only:!0}}return{length:s(e,r),only:!1}}},uA=e=>{let t=lA(e);return e=>t(e).length},dA=e=>{let t=lA(e);return e=>t(e).only},fA=e=>{let t=uA(e),n=sk(e),r=ck(e);return e=>{let i=t(e);return i>0&&n(e+i)&&r(e+i+1)}},pA=e=>{let t=uA(e),n=uk(e),r=ck(e);return e=>{let i=t(e);return i>0&&n(e+i)&&r(e+i+1)}},mA=e=>{let t=uA(e),n=ak(e);return e=>{let r=t(e);return r>0&&n(e+r)}},hA=Array.from(new Set([...PO,...FO,...IO,...LO,...RO,...zO,...BO,...VO].map(e=>e.toUpperCase()))),gA=(e=>{let t=new Map;for(let n of e){let e=n.split(` `),r=t.get(e[0])??[];r.push(e),t.set(e[0],r)}for(let e of t.values())e.sort((e,t)=>t.length-e.length);return t})(hA),_A=e=>{let t=UO(e),n=JO(e),r=YO(e),i=t=>{let i=0;for(let a=t;a<e.length;a++)if(n(a))i++;else if(r(a)&&(i--,i===0))return a+1;return e.length},a=(r,a)=>{let o=r;for(let[r,s]of a.entries()){let a=e[o];if(!a||!t(o)||r>0&&a.quoted||a.value.toUpperCase()!==s)return 0;o++,n(o)&&(o=i(o))}return o-r};return n=>{let r=e[n];if(!r||!t(n))return 0;let i=r.value.toUpperCase();for(let e of gA.get(i)??[]){let t=a(n,e);if(t)return t}return+!!hA.includes(i)}};function vA(e,t){let n=eA(e),r=UO(e),i=JO(e),a=YO(e),o=GO(e),s=qO(e),c=WO(e),l=mk(e),u=Xk(e),d=nA(e),f=()=>t.value<e.length,p={type:DO.createTable,name:``,comment:``,columns:[],indexes:[],foreignKeys:[]},m=d(t.value);t.value+=m===0?2:m;let h=!1,g=!0;for(;f()&&!n(t.value);){let n=e[t.value];if(s(t.value)){t.value++;break}if(p.name&&u(t.value)){if(t.value+=2,r(t.value)&&i(t.value+1)&&t.value++,i(t.value)){let e=0;for(;f();){if(i(t.value))e++;else if(a(t.value)&&(e--,e===0)){t.value++;break}t.value++}}continue}if(i(t.value)){if(t.value++,h||!g){let e=1;for(;f()&&e>0;)i(t.value)?e++:a(t.value)&&e--,t.value++;continue}let{columns:n,indexes:r,foreignKeys:o}=yA(e,t);p.columns=n,p.indexes=r,p.foreignKeys=o,h=!0;continue}if(r(t.value)&&!p.name){for(p.name=n.value,g=!0,t.value++;o(t.value);){if(!r(t.value+1)){t.value++;break}p.name=e[t.value+1].value,t.value+=2}continue}if(l(t.value)){n=e[++t.value],c(t.value)&&(n=e[++t.value]),r(t.value)&&(p.comment=n.value,t.value++),g=!1;continue}g=!1,t.value++}return p}function yA(e,t){let n=UO(e),r=JO(e),i=YO(e),a=KO(e),o=lk(e),s=ik(e),c=sk(e),l=uk(e),u=Yk(e),d=ak(e),f=fk(e),p=dk(e),m=pk(e),h=mk(e),g=_k(e),_=gk(e),v=ck(e),y=WO(e),ee=rA(e),te=Ok(e),ne=Hk(e),re=_A(e),ie=Jk(e),ae=Gk(e),b=Kk(e),oe=()=>t.value<e.length,se=e=>o(e)||c(e)||l(e)||d(e)||s(e)||v(e)||b(e),ce=()=>{let o=[],s={name:``,sort:OO.asc},c=!1;for(t.value++;oe()&&!i(t.value);){if(r(t.value)){c||=!s.name;let e=0;for(;oe();){if(r(t.value))e++;else if(i(t.value)&&--e===0)break;t.value++}}n(t.value)&&!g(t.value)&&!_(t.value)&&(s.name=e[t.value].value),g(t.value)&&(s.sort=OO.desc),a(t.value)&&(o.push(s),s={name:``,sort:OO.asc}),t.value++}return s.name!==``&&o.push(s),t.value++,c?[]:o},le=[],x=[],ue=[],S=[],de=[],C={name:``,dataType:``,default:``,comment:``,primaryKey:!1,autoIncrement:!1,unique:!1,nullable:!0},fe=!1;for(;oe();){let g=e[t.value],_=ie(t.value);if(_){let n=t.value+_,r=[];for(;t.value<n;)r.push(a(t.value)?`,`:e[t.value].value),t.value++;C.dataType=r.reduce((e,t)=>!e||t===`,`?e+t:`${e} ${t}`,``);continue}let pe=ae(t.value);if(pe){t.value+=pe;continue}if(!C.name&&se(t.value)&&(fe=!0),fe&&b(t.value)){t.value++;continue}if(n(t.value)&&!fe&&!C.name&&!p(t.value)&&!ne(t.value)){C.name=g.value,t.value++;continue}if(r(t.value)){let e=0;for(;oe();){if(r(t.value))e++;else if(i(t.value)&&(e--,e===0)){t.value++;break}t.value++}continue}if(o(t.value)){g=e[++t.value],n(t.value)&&t.value++;continue}if(c(t.value)){if(g=e[++t.value],v(t.value)){if(g=e[++t.value],fe&&n(t.value)&&(g=e[++t.value]),r(t.value)){for(g=e[++t.value];oe()&&!i(t.value);)n(t.value)&&S.push(g.value.toUpperCase()),g=e[++t.value];t.value++}else C.primaryKey=!0}continue}if(l(t.value)){let n=bA(e,t);n&&ue.push(n);continue}if(s(t.value)||v(t.value)){if(g=e[++t.value],n(t.value)){let n=g.value;if(g=e[++t.value],r(t.value)){let e=ce();e.length&&x.push({name:n,unique:!1,columns:e})}}continue}if(d(t.value)){g=e[++t.value];let a=s(t.value);(v(t.value)||a)&&(g=e[++t.value]);let o=``;if(!C.name&&n(t.value)&&(o=g.value,g=e[++t.value]),a&&o&&r(t.value)){let e=ce();e.length>1?x.push({name:o,unique:!0,columns:e}):de.push(...e.map(e=>e.name.toUpperCase()));continue}if(r(t.value)){for(g=e[++t.value];oe()&&!i(t.value);)n(t.value)&&de.push(g.value.toUpperCase()),g=e[++t.value];t.value++}else C.unique=!0;continue}if(p(t.value)){g=e[++t.value],f(t.value)?(C.nullable=!1,t.value++):ne(t.value)&&t.value++;continue}if(ne(t.value)){t.value++;continue}if(m(t.value)){g=e[++t.value],n(t.value)&&(C.default=g.quoted?`'${g.value.replaceAll(`'`,`''`)}'`:g.value,t.value++);continue}if(h(t.value)){g=e[++t.value],y(t.value)&&(g=e[++t.value]),n(t.value)&&(C.comment=g.value,t.value++);continue}if(u(t.value)){C.autoIncrement=!0,t.value++;continue}if(ee(t.value)){t.value+=2,n(t.value)&&t.value++;continue}if(te(t.value)){t.value++,y(t.value)&&t.value++,n(t.value)&&t.value++;continue}let me=re(t.value);if(me&&(fe||C.dataType)){t.value+=me;continue}if(me){let a=t.value+me,o=``,s=0;for(;t.value<a;)g=e[t.value],r(t.value)?(o+=`(`,s++):i(t.value)?(o+=`)`,s--):o+=s?n(t.value)&&(n(t.value-1)||i(t.value-1))?` ${g.value}`:g.value:o?` ${g.value}`:g.value,t.value++;for(;s>0;)o+=`)`,s--;C.dataType=o;continue}if(a(t.value)){(C.name||C.dataType)&&le.push(C),C={name:``,dataType:``,default:``,comment:``,primaryKey:!1,autoIncrement:!1,unique:!1,nullable:!0},fe=!1,t.value++;continue}if(i(t.value)){t.value++;break}t.value++}return!le.includes(C)&&(C.name||C.dataType)&&le.push(C),le.forEach(e=>{S.includes(e.name.toUpperCase())&&(e.primaryKey=!0),de.includes(e.name.toUpperCase())&&(e.unique=!0)}),{columns:le,indexes:x,foreignKeys:ue}}function bA(e,t){let n=UO(e),r=JO(e),i=YO(e),a=hk(e),o=GO(e),s=ck(e),c=()=>t.value<e.length,l={columnNames:[],refTableName:``,refColumnNames:[]},u=e[++t.value];if(s(t.value)){if(u=e[++t.value],r(t.value)){for(u=e[++t.value];c()&&!i(t.value);)n(t.value)&&l.columnNames.push(u.value),u=e[++t.value];u=e[++t.value]}if(a(t.value)&&(u=e[++t.value],n(t.value))){for(l.refTableName=u.value,t.value++;o(t.value);){if(!n(t.value+1)){t.value++;break}l.refTableName=e[t.value+1].value,t.value+=2}if(u=e[t.value],r(t.value)){for(u=e[++t.value];c()&&!i(t.value);)n(t.value)&&l.refColumnNames.push(u.value),u=e[++t.value];u=e[++t.value]}}if(l.columnNames.length&&l.columnNames.length===l.refColumnNames.length)return l}return null}function xA(e,t){let n=eA(e),r=qO(e),i=UO(e),a=lk(e),o=GO(e),s=rk(e),c=uk(e),l=dA(e)(t.value),u=()=>t.value<e.length,d={type:DO.alterTableAddForeignKey,name:``,columnNames:[],refTableName:``,refColumnNames:[]};for(t.value++;u()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(s(t.value)){if(n=e[++t.value],l&&(n=e[++t.value]),i(t.value))for(d.name=n.value,t.value++;o(t.value);){if(!i(t.value+1)){t.value++;break}d.name=e[t.value+1].value,t.value+=2}continue}if(a(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){let n=bA(e,t);n&&(d.columnNames=n.columnNames,d.refTableName=n.refTableName,d.refColumnNames=n.refColumnNames);continue}t.value++}return d}function SA(e,t){let n=eA(e),r=qO(e),i=UO(e),a=JO(e),o=YO(e),s=lk(e),c=sk(e),l=GO(e),u=ck(e),d=rk(e),f=dA(e)(t.value),p=()=>t.value<e.length,m={type:DO.alterTableAddPrimaryKey,name:``,columnNames:[]};for(t.value++;p()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(d(t.value)){if(n=e[++t.value],f&&(n=e[++t.value]),i(t.value))for(m.name=n.value,t.value++;l(t.value);){if(!i(t.value+1)){t.value++;break}m.name=e[t.value+1].value,t.value+=2}continue}if(s(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){if(n=e[++t.value],u(t.value)&&(n=e[++t.value],a(t.value))){for(n=e[++t.value];p()&&!o(t.value);)i(t.value)&&m.columnNames.push(n.value),n=e[++t.value];n=e[++t.value]}continue}t.value++}return m}function CA(e,t){let n=eA(e),r=qO(e),i=UO(e),a=lk(e),o=GO(e),s=rk(e),c=ak(e),l=JO(e),u=YO(e),d=dA(e)(t.value),f=()=>t.value<e.length,p={type:DO.alterTableAddUnique,name:``,columnNames:[]};for(t.value++;f()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(s(t.value)){if(n=e[++t.value],d&&(n=e[++t.value]),i(t.value))for(p.name=n.value,t.value++;o(t.value);){if(!i(t.value+1)){t.value++;break}p.name=e[t.value+1].value,t.value+=2}continue}if(a(t.value)){n=e[++t.value],i(t.value)&&t.value++;continue}if(c(t.value)){if(n=e[++t.value],l(t.value)){for(n=e[++t.value];f()&&!u(t.value);)i(t.value)&&p.columnNames.push(n.value),n=e[++t.value];t.value++}continue}t.value++}return p}function wA(e,t){let n=eA(e),r=UO(e),i=GO(e),a=qO(e),o=wk(e),s=fk(e),c=()=>t.value<e.length,l={type:DO.commentOnColumn,tableName:``,columnName:``,comment:``};t.value+=3;let u=[],d=!1;for(;c()&&!n(t.value);){let n=e[t.value];if(a(t.value)){t.value++;break}if(o(t.value)){if(d=!0,n=e[++t.value],s(t.value)){t.value++;continue}r(t.value)&&(l.comment=n.value,t.value++);continue}if(i(t.value)){t.value++;continue}if(r(t.value)&&!d){u.push(n.value),t.value++;continue}t.value++}return l.columnName=u.length?u[u.length-1]:``,l.tableName=u.length>1?u[u.length-2]:``,l}function TA(e,t){let n=eA(e),r=UO(e),i=GO(e),a=qO(e),o=wk(e),s=fk(e),c=()=>t.value<e.length,l={type:DO.commentOnTable,name:``,comment:``};t.value+=3;let u=!1;for(;c()&&!n(t.value);){let n=e[t.value];if(a(t.value)){t.value++;break}if(o(t.value)){if(u=!0,n=e[++t.value],s(t.value)){t.value++;continue}r(t.value)&&(l.comment=n.value,t.value++);continue}if(i(t.value)){t.value++;continue}if(r(t.value)&&!u){l.name=n.value,t.value++;continue}t.value++}return l}function EA(e,t){let n=eA(e),r=qO(e),i=ak(e),a=UO(e),o=JO(e),s=YO(e),c=KO(e),l=ik(e),u=vk(e),d=_k(e),f=gk(e),p=aA(e),m=()=>t.value<e.length,h={type:DO.createIndex,name:``,unique:i(t.value+1),tableName:``,columns:[]};for(t.value+=p(t.value)?2:1;m()&&!n(t.value);){let n=e[t.value];if(r(t.value)){t.value++;break}if(l(t.value)){n=e[++t.value],a(t.value)&&(h.name=n.value);continue}if(u(t.value)){if(n=e[++t.value],a(t.value)&&(h.tableName=n.value,n=e[++t.value],o(t.value))){n=e[++t.value];let r={name:``,sort:OO.asc};for(;m()&&!s(t.value);)a(t.value)&&!d(t.value)&&!f(t.value)&&(r.name=n.value),d(t.value)&&(r.sort=OO.desc),c(t.value)&&(h.columns.push(r),r={name:``,sort:OO.asc}),n=e[++t.value];!h.columns.includes(r)&&r.name!==``&&h.columns.push(r),t.value++}continue}t.value++}return h}function DA(e){let t=[],n={value:0},r=()=>n.value<e.length,i=iA(e),a=oA(e),o=fA(e),s=pA(e),c=mA(e),l=Qk(e),u=$k(e);for(;r();){if(i(n.value)){t.push(vA(e,n));continue}if(a(n.value)){t.push(EA(e,n));continue}if(o(n.value)){t.push(SA(e,n));continue}if(s(n.value)){t.push(xA(e,n));continue}if(c(n.value)){t.push(CA(e,n));continue}if(l(n.value)){t.push(TA(e,n));continue}if(u(n.value)){t.push(wA(e,n));continue}n.value++}return t}var OA=e=>DA(NO(e));function kA(e,t,n){let r=Jp({}),i=jA(AA(OA(e))),a=Jh(i.length*100);return r.settings.width=a,r.settings.height=a,i.forEach(e=>MA(r,e,t)),NA(r,i),PA(r,i),Jm(n?n(r):r)}function AA(e){let t={tables:[],indexes:[],primaryKeys:[],foreignKeys:[],uniques:[],tableComments:[],columnComments:[]};for(let n of e)switch(n.type){case DO.createTable:n.name&&t.tables.push(n);break;case DO.createIndex:n.tableName&&n.columns.length&&t.indexes.push(n);break;case DO.alterTableAddPrimaryKey:n.name&&n.columnNames.length&&t.primaryKeys.push(n);break;case DO.alterTableAddForeignKey:n.name&&n.columnNames.length&&n.refTableName&&n.refColumnNames.length&&n.columnNames.length===n.refColumnNames.length&&t.foreignKeys.push(n);break;case DO.alterTableAddUnique:n.name&&n.columnNames.length&&t.uniques.push(n);break;case DO.commentOnTable:n.name&&t.tableComments.push(n);break;case DO.commentOnColumn:n.tableName&&n.columnName&&t.columnComments.push(n)}return t}function jA({tables:e,indexes:t,primaryKeys:n,foreignKeys:r,uniques:i,tableComments:a,columnComments:o}){return t.forEach(t=>{let n=Cw(e,t.tableName);n&&n.indexes.push({name:t.name,unique:t.unique,columns:t.columns})}),n.forEach(t=>{let n=Cw(e,t.name);n&&t.columnNames.forEach(e=>{let t=Cw(n.columns,e);t&&(t.primaryKey=!0)})}),i.forEach(t=>{let n=Cw(e,t.name);n&&t.columnNames.forEach(e=>{let t=Cw(n.columns,e);t&&(t.unique=!0)})}),r.forEach(t=>{let n=Cw(e,t.name);n&&n.foreignKeys.push({columnNames:t.columnNames,refTableName:t.refTableName,refColumnNames:t.refColumnNames})}),a.forEach(({name:t,comment:n})=>{let r=Cw(e,t);r&&(r.comment=n)}),o.forEach(({tableName:t,columnName:n,comment:r})=>{let i=Cw(e,t);if(!i)return;let a=Cw(i.columns,n);a&&(a.comment=r)}),e}function MA({doc:e,collections:t},n,{toWidth:r}){let i=NS({name:n.name,comment:n.comment,ui:{widthName:H(r(n.name)),widthComment:H(r(n.comment))}});n.columns.forEach(e=>{let n=uC({tableId:i.id,name:e.name,comment:e.comment,dataType:e.dataType,default:e.default,options:(e.autoIncrement?R.autoIncrement:0)|(e.primaryKey?R.primaryKey:0)|(e.unique?R.unique:0)|(e.nullable?0:R.notNull),ui:{widthName:H(r(e.name)),widthComment:H(r(e.comment)),widthDataType:H(r(e.dataType)),widthDefault:H(r(e.default)),keys:e.primaryKey?z.primaryKey:0}});i.columnIds.push(n.id),i.seqColumnIds.push(n.id),M(t).collection(`tableColumnEntities`).setOne(n)}),e.tableIds.push(i.id),M(t).collection(`tableEntities`).setOne(i)}function NA({doc:e,collections:t},n){let r=M(t).collection(`tableEntities`).selectByIds(e.tableIds),i=M(t).collection(`tableColumnEntities`);n.forEach(n=>{if(!n.foreignKeys.length)return;let a=Cw(r,n.name);if(!a)return;let o=i.selectByIds(a.columnIds);n.foreignKeys.forEach(n=>{let s=Cw(r,n.refTableName);if(!s)return;let c=i.selectByIds(s.columnIds),l=[],u=[];n.refColumnNames.forEach(e=>{let t=Cw(c,e);t&&l.push(t)}),n.columnNames.forEach(e=>{let t=Cw(o,e);t&&(u.push(t),W(t.ui.keys,z.primaryKey)?t.ui.keys|=z.foreignKey:t.ui.keys=z.foreignKey)});let d=pS({identification:!u.some(e=>!(W(e.ui.keys,z.primaryKey)&&W(e.ui.keys,z.foreignKey))),relationshipType:rh.ZeroN,start:{tableId:s.id,columnIds:l.map(e=>e.id)},end:{tableId:a.id,columnIds:u.map(e=>e.id)}});e.relationshipIds.push(d.id),M(t).collection(`relationshipEntities`).setOne(d)})})}function PA({doc:e,collections:t},n){let r=M(t).collection(`tableEntities`).selectByIds(e.tableIds);n.forEach(n=>{n.indexes.forEach(i=>{let a=Cw(r,n.name);if(!a)return;let o=M(t).collection(`tableColumnEntities`).selectByIds(a.columnIds),s=[],c=rx({name:i.name,tableId:a.id,unique:i.unique});i.columns.forEach(e=>{let t=Cw(o,e.name);if(!t)return;let n=bx({indexId:c.id,columnId:t.id,orderType:e.sort===OO.asc?ah.ASC:ah.DESC});s.push(n)}),s.length!==0&&(s.forEach(e=>{c.indexColumnIds.push(e.id),c.seqIndexColumnIds.push(e.id),M(t).collection(`indexColumnEntities`).setOne(e)}),e.indexIds.push(c.id),M(t).collection(`indexEntities`).setOne(c))})})}function FA({doc:e,collections:t},n){let r=B(n);return M(t).collection(`relationshipEntities`).selectByIds(e.relationshipIds).filter(({start:e,end:t})=>r(e.tableId)&&r(t.tableId)).map(({relationshipType:e,start:t,end:n})=>({relationshipType:e,start:{tableId:t.tableId,columnIds:[...t.columnIds]},end:{tableId:n.tableId,columnIds:[...n.columnIds]}}))}function IA({doc:e,collections:t},n){let r=B(n),i=M(t).collection(`indexColumnEntities`),a=[];for(let n of M(t).collection(`indexEntities`).selectByIds(e.indexIds)){if(!r(n.tableId))continue;let e=[],t=!0;for(let r of n.indexColumnIds){let n=i.selectById(r);if(!n){t=!1;break}e.push({columnId:n.columnId,orderType:n.orderType})}t&&a.push({tableId:n.tableId,name:n.name,unique:n.unique,indexColumns:e})}return a}new TextEncoder;function LA({tables:e,columns:t,memos:n,relationships:r,indexes:i},a){let o=[],s=[],c=[],l=new Map(t.map(e=>[e.sourceId,e])),u=new Map,d=new Map;for(let t of e){let e=a.get(t.sourceId);if(!e)continue;let n=qe();s.push(n),u.set(t.sourceId,n),o.push(PS({id:n,ui:{x:e.x,y:e.y,zIndex:e.zIndex,color:t.ui.color}}),HS({id:n,value:t.name}),WS({id:n,value:t.comment}));for(let e of t.columnIds){let t=l.get(e);if(!t)continue;let r={id:qe(),tableId:n};d.set(e,r.id),o.push(dC(r),hC({...r,value:t.name}),yC({...r,value:t.dataType}),xC({...r,value:t.default}),_C({...r,value:t.comment}),TC({...r,value:W(t.options,R.primaryKey)}),kC({...r,value:W(t.options,R.notNull)}),DC({...r,value:W(t.options,R.unique)}),CC({...r,value:W(t.options,R.autoIncrement)}))}}for(let e of r){let t=u.get(e.start.tableId),n=u.get(e.end.tableId);if(!t||!n)continue;let r=RA(e.start.columnIds,d),i=RA(e.end.columnIds,d);!r||!i||o.push(mS({id:qe(),relationshipType:e.relationshipType,start:{tableId:t,columnIds:r},end:{tableId:n,columnIds:i}}))}for(let e of i){let t=u.get(e.tableId);if(!t)continue;let n=RA(e.indexColumns.map(({columnId:e})=>e),d);if(!n)continue;let r=qe();o.push(ix({id:r,tableId:t}),cx({id:r,tableId:t,value:e.name}),ux({id:r,tableId:t,value:e.unique})),e.indexColumns.forEach(({orderType:e},i)=>{let a=qe(),s=n[i];o.push(Sx({id:a,indexId:r,tableId:t,columnId:s}),Ox({id:a,indexId:r,columnId:s,value:e}))})}for(let e of n){let t=a.get(e.sourceId);if(!t)continue;let n=qe();c.push(n),o.push(zx({id:n,ui:{x:t.x,y:t.y,zIndex:t.zIndex,color:e.ui.color,width:e.ui.width,height:e.ui.height}}),qx({id:n,value:e.value}))}return{actions:o,tableIds:s,memoIds:c}}function RA(e,t){let n=[];for(let r of e){let e=t.get(r);if(!e)return null;n.push(e)}return n}function zA(e,t,n=[]){let{doc:{relationshipIds:r},collections:i}=t,a=e.pop();return a&&(n.some(({columnId:e})=>e===a.columnId)||(n.push(a),M(i).collection(`relationshipEntities`).selectByIds(r).forEach(({id:t,start:n,end:r})=>{let i=n.columnIds.indexOf(a.columnId);if(i!==-1){let n=r.columnIds[i];e.push({columnId:n,relationshipIds:[t]})}else{let i=r.columnIds.indexOf(a.columnId);if(i!==-1){let r=n.columnIds[i];e.push({columnId:r,relationshipIds:[t]})}}})),zA(e,t,n)),n}const BA=og.flow,VA={focusFlowTableAction$:e=>function*({editor:t,settings:n}){e.length&&(n.canvasType!==Ym.visualization&&(yield Cv({value:Ym.visualization})),t.visualizationMode!==sg.flow&&(yield Rg({value:sg.flow})),yield t.views.flow?Ig({tableIds:e,kind:BA}):vg({kind:BA,centerIds:e}))}};function HA(e){return Object.entries(e).reduce((e,[t,n])=>(n===ig.table?e.tableIds.push(t):n===ig.memo&&e.memoIds.push(t),e),{tableIds:[],memoIds:[]})}const UA=e=>function*(){yield Ry(),yield Vy({value:e})},WA=e=>function*(){yield Uy(),yield Gy({value:e})},GA=(e,t,n=`document`)=>function*(r){let{tableIds:i,memoIds:a}=HA(r.editor.selectedMap),{zoomLevel:o}=B_(r,n),s=e/o,c=t/o;if(n!==`document`){i.length&&(yield Ug(Hg.drag,Ag({ids:i,movementX:s,movementY:c,kind:n})));return}i.length&&(yield Ug(Hg.drag,IS({ids:i,movementX:s,movementY:c}))),a.length&&(yield Ug(Hg.drag,Vx({ids:a,movementX:s,movementY:c})))},KA=()=>function*(){yield lw(),yield ew()},qA=(e,t)=>function*(n){yield*YA(n,{input:{tables:e.tables,columns:e.columns,memos:e.memos,relationships:e.relationships??[],indexes:e.indexes??[]},offset:{x:50*t,y:50*t},escapeCollision:!0})},JA=({tableIds:e,memoIds:t,offset:n,escapeCollision:r})=>function*(i){yield*YA(i,{input:QA(i,{tableIds:e??[],memoIds:t??[]}),offset:{x:Ke(n.x,4),y:Ke(n.y,4)},escapeCollision:r})};function*YA(e,{input:t,offset:n,escapeCollision:r}){if(t.tables.length===0&&t.memos.length===0)return;let{settings:i,doc:{tableIds:a,memoIds:o},collections:s}=e,c=M(s).collection(`tableEntities`),l=M(s).collection(`memoEntities`),{actions:u,tableIds:d,memoIds:f}=LA(t,ZA(ow({entities:[...t.tables.map(XA),...t.memos.map(XA)],offset:n,escapeCollision:r,settings:i,tables:c.selectByIds(a),memos:l.selectByIds(o),findSource:e=>c.selectById(e)??l.selectById(e)})));yield ej(),yield u,yield Py({...d.reduce((e,t)=>(e[t]=ig.table,e),{}),...f.reduce((e,t)=>(e[t]=ig.memo,e),{})})}const XA=({sourceId:e,ui:{x:t,y:n,zIndex:r}})=>({sourceId:e,ui:{x:t,y:n,zIndex:r}});function ZA(e){return new Map(Array.from(e,([e,{x:t,y:n,zIndex:r}])=>[e,{x:Ke(t,4),y:Ke(n,4),zIndex:r}]))}function QA(e,{tableIds:t,memoIds:n}){let{collections:r}=e,i=M(r).collection(`tableEntities`).selectByIds(t),a=M(r).collection(`memoEntities`).selectByIds(n),o=i.flatMap(e=>M(r).collection(`tableColumnEntities`).selectByIds(e.columnIds)),s=i.map(({id:e})=>e);return{tables:i.map(e=>({sourceId:e.id,name:e.name,comment:e.comment,columnIds:[...e.columnIds],ui:{x:e.ui.x,y:e.ui.y,zIndex:e.ui.zIndex,widthName:e.ui.widthName,widthComment:e.ui.widthComment,color:e.ui.color}})),columns:o.map(e=>({sourceId:e.id,tableId:e.tableId,name:e.name,comment:e.comment,dataType:e.dataType,default:e.default,options:e.options,ui:{keys:e.ui.keys,widthName:e.ui.widthName,widthComment:e.ui.widthComment,widthDataType:e.ui.widthDataType,widthDefault:e.ui.widthDefault}})),memos:a.map(e=>({sourceId:e.id,value:e.value,ui:{x:e.ui.x,y:e.ui.y,width:e.ui.width,height:e.ui.height,zIndex:e.ui.zIndex,color:e.ui.color}})),relationships:FA(e,s),indexes:IA(e,s)}}const $A=(e,t=`document`)=>function*(n){let{collections:r}=n,{tableIds:i,memoIds:a}=Zg(n,t),o={...M(r).collection(`tableEntities`).selectByIds(i).reduce((r,i)=>{let a=A_(n,i,t);return bw(e,{x:a.x+a.width/2-15,y:a.y+a.height/2-15,w:15,h:15})&&(r[i.id]=ig.table),r},{}),...M(r).collection(`memoEntities`).selectByIds(a).reduce((t,n)=>{let r=s_(n),i=c_(n);return bw(e,{x:n.ui.x+r/2-15,y:n.ui.y+i/2-15,w:15,h:15})&&(t[n.id]=ig.memo),t},{})};yield ej(),Ge(o)||(yield Py(o))},ej=()=>function*(){yield My(),yield Zy()},tj=(e,t)=>function*(n){let{editor:{focusTable:r}}=n;r&&(e===cg.Tab&&!t&&(vy(r.focusType)&&gy(n)&&!ay(n)||!vy(r.focusType)&&oy(n)&&cy(n))?yield hw(r.tableId):yield $y({moveKey:e,shiftKey:t}))},nj=e=>function*({editor:t}){t.drawRelationship?.relationshipType===e?yield _b():yield pb({relationshipType:e})},rj=e=>function*({collections:t}){let n=M(t).collection(`tableEntities`).selectById(e);if(n){if(!M(t).collection(`tableColumnEntities`).selectByIds(n.columnIds).some(e=>W(e.options,R.primaryKey))){let t=qe();yield dC({tableId:e,id:t}),yield TC({tableId:e,id:t,value:!0}),yield Yy({tableId:e,columnId:t,focusType:U.columnName,$mod:!1,shiftKey:!1})}yield hb({tableId:e})}},ij=e=>function*({editor:{selectedMap:t},collections:n}){let{tableIds:r,memoIds:i}=HA(t),a=M(n).collection(`tableEntities`).selectByIds(r),o=M(n).collection(`memoEntities`).selectByIds(i);yield a.map(t=>KS({id:t.id,color:e,prevColor:t.ui.color})),yield o.map(t=>Yx({id:t.id,color:e,prevColor:t.ui.color}))},aj=e=>function*({settings:t},n){yield UA(kA(e,n,e=>(e.settings={...e.settings,...he(ie(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield XS()},oj=e=>function*({settings:t},n){yield UA(EO(e,n,e=>(e.settings={...e.settings,...he(ie(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield XS()},sj=e=>function*({settings:t},n){yield UA(nD(e,n,e=>(e.settings={...e.settings,...he(ie(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield XS()},cj=e=>function*({settings:t},n){yield UA(KT(e,n,e=>(e.settings={...e.settings,...he(ie(t),[`width`,`height`,`originX`,`originY`,`scrollTop`,`scrollLeft`,`zoomLevel`])},e))),yield XS()},lj=e=>function*({editor:{focusTable:t}}){!t||!t.columnId||(yield jb({tableId:t.tableId,columnIds:e?[...t.selectColumnIds]:[t.columnId]}))};function uj(e,t,n){let r=[...t],i=[];for(let t of n){let n=r.indexOf(t);if(n===-1)return[];let a=r[r.length-1];t!==a&&(r.splice(n,1),r.push(t),i.push(jC({tableId:e,id:t,targetId:a})))}return ce(r,t)?[]:i}const dj=(e,t)=>function*({editor:{draggableColumn:n},collections:r}){if(!n||n.columnIds.length===0)return;let{tableId:i,columnIds:a}=n,o=M(r).collection(`tableEntities`),s=o.selectById(i);if(!s)return;if(t===i){let t=s.columnIds.indexOf(a[0]);if(t===-1)return;if(e===null){yield uj(i,s.columnIds,a);return}let n=s.columnIds.indexOf(e);if(n===-1)return;let r=a.map(t=>jC({tableId:i,id:t,targetId:e}));t<n&&r.reverse(),yield r;return}if(!o.selectById(t))return;let c=M(r).collection(`tableColumnEntities`).selectByIds(a);if(c.length===0)return;yield gw(i,a);let l=c.map(()=>qe());for(let n=0;n<c.length;n++){let r=c[n],i=l[n],a={id:i,tableId:t};yield[dC(a),hC({...a,value:r.name}),yC({...a,value:r.dataType}),xC({...a,value:r.default}),_C({...a,value:r.comment}),TC({...a,value:W(r.options,R.primaryKey)}),kC({...a,value:W(r.options,R.notNull)}),DC({...a,value:W(r.options,R.unique)}),CC({...a,value:W(r.options,R.autoIncrement)}),...e===null?[]:[jC({...a,targetId:e})],Yy({tableId:t,columnId:i,focusType:U.columnName,$mod:!0,shiftKey:!1})]}yield jb({tableId:t,columnIds:l})},fj=e=>function*(t){let{columnIds:n,relationshipIds:r}=zA([{columnId:e,relationshipIds:[]}],t).reduce((e,{columnId:t,relationshipIds:n})=>(e.columnIds.push(t),e.relationshipIds.push(...n),e),{columnIds:[],relationshipIds:[]});yield xb({columnIds:ye(n)}),yield Cb({relationshipIds:ye(r)})},pj=()=>function*(){yield xb({columnIds:[]}),yield Cb({relationshipIds:[]})},mj={loadJsonAction$:UA,initialLoadJsonAction$:WA,moveAllAction$:GA,removeSelectedAction$:KA,pasteEntitiesAction$:qA,duplicateAction$:JA,dragSelectAction$:$A,unselectAllAction$:ej,focusMoveTableAction$:tj,drawStartRelationshipAction$:nj,drawStartAddRelationshipAction$:rj,changeColorAllAction$:ij,loadSchemaSQLAction$:aj,loadSchemaGraphQLAction$:oj,loadSchemaDBMLAction$:sj,loadSchemaAMLAction$:cj,dragstartColumnAction$:lj,dragoverColumnAction$:dj,columnKeyHoverStartAction$:fj,columnKeyHoverEndAction$:pj,...VA},hj={addIndexAction$:e=>function*(){yield ix({id:qe(),tableId:e})},changeIndexUniqueAction$:e=>function*({collections:t}){let n=M(t).collection(`indexEntities`).selectById(e);n&&(yield ux({id:e,tableId:n.tableId,value:!n.unique}))}},gj={addIndexColumnAction$:(e,t)=>function*({collections:n}){let r=M(n).collection(`indexEntities`).selectById(e);if(!r)return;let i=M(n).collection(`indexColumnEntities`).selectByIds(r.seqIndexColumnIds).find(e=>e.columnId===t);i?yield Sx({id:i.id,indexId:e,tableId:r.tableId,columnId:t}):yield Sx({id:qe(),indexId:e,tableId:r.tableId,columnId:t})},removeIndexColumnAction$:(e,t)=>function*({collections:n}){let r=M(n).collection(`indexEntities`).selectById(e);if(!r)return;let i=M(n).collection(`indexColumnEntities`).selectByIds(r.indexColumnIds).filter(e=>e.columnId===t);for(let t of i)yield wx({id:t.id,indexId:e,tableId:r.tableId})},changeIndexColumnOrderTypeAction$:e=>function*({collections:t}){let n=M(t).collection(`indexColumnEntities`).selectById(e);n&&(yield Ox({id:e,indexId:n.indexId,columnId:n.columnId,value:n.orderType===ah.ASC?ah.DESC:ah.ASC}))},moveIndexColumnAction$:(e,t)=>function*({collections:n}){if(e===t)return;let r=M(n).collection(`indexColumnEntities`).selectById(e);if(!r)return;let i=M(n).collection(`indexEntities`).selectById(r.indexId);i&&(yield Ex({id:e,indexId:r.indexId,tableId:i.tableId,targetId:t}))}},_j={};function vj(e,t,n,r){let i=W_({...e,zoomLevel:t},n);return{movementX:Ke(r.x-i.x,4),movementY:Ke(r.y-i.y,4)}}function yj(e,t,n){let{viewport:r}=e.editor,i={x:r.width/2,y:r.height/2};return vj(t,n,G_(t,i),i)}const bj={changeZoomLevelAction$:(e,t)=>function*(n){let r=V_(n,t),{originX:i,originY:a}=r,{movementX:o,movementY:s}=yj(n,r,Yh(e)),c={originX:i+o,originY:a+s};if(t&&t!==`document`){yield Eg({value:e,kind:t}),yield Sg({...c,kind:t});return}yield lv({value:e}),yield hv(c)},streamZoomLevelAction$:(e,t)=>function*(n){let r=V_(n,t),i=yj(n,r,Yh(r.zoomLevel+e));if(t&&t!==`document`){yield Og({value:e,kind:t}),yield wg({...i,kind:t});return}yield dv({value:e}),yield _v(i)}},xj=Object.freeze({...Qb,...mj,...px,...hj,...jx,...gj,...nS,...nw,...xS,..._j,...Wv,...bj,...$S,...dw,...PC,...yw}),Sj=`table.add,table.move,table.moveTo,table.remove,table.changeName,table.changeComment,table.changeColor,table.sort,column.add,column.remove,column.changeName,column.changeComment,column.changeDataType,column.changeDefault,column.changeAutoIncrement,column.changePrimaryKey,column.changeUnique,column.changeNotNull,column.move,relationship.add,relationship.remove,relationship.changeType,index.add,index.remove,index.changeName,index.changeUnique,indexColumn.add,indexColumn.remove,indexColumn.move,indexColumn.changeOrderType,memo.add,memo.move,memo.moveTo,memo.remove,memo.changeValue,memo.changeColor,memo.resize,settings.changeDatabaseName,settings.changeZoomLevel,settings.streamZoomLevel,settings.scrollTo,settings.streamScrollTo,settings.changeShow,settings.changeDatabase,settings.changeCanvasType,settings.changeLanguage,settings.changeTableNameCase,settings.changeColumnNameCase,settings.changeBracketType,settings.changeRelationshipDataTypeSync,settings.changeRelationshipOptimization,settings.changeColumnOrder,settings.changeMaxWidthComment,settings.changeIgnoreSaveSettings,editor.loadJson,editor.clear`.split(`,`),Cj=B([`settings.changeZoomLevel`,`settings.streamZoomLevel`,`settings.scrollTo`,`settings.streamScrollTo`,`settings.changeDatabase`,`settings.changeCanvasType`,`settings.changeLanguage`,`settings.changeTableNameCase`,`settings.changeColumnNameCase`,`settings.changeBracketType`]),wj=[...Sj.filter(e=>!Cj(e))],Tj=B([`editor.loadJson`,`editor.clear`]),Ej=[...wj.filter(e=>!Tj(e))],Dj=[`editor.sharedMouseTracker`,`editor.sharedFocusTracker`,`editor.sharedSelectionTracker`,`editor.sharedDragSelectTracker`];[...Sj,...Dj];const Oj=[`table.move`,`memo.move`],kj=[`table.changeColor`,`memo.changeColor`],Aj=[`settings.streamZoomLevel`,`settings.streamScrollTo`],jj=[...Object.keys(YC)],Mj=[...Object.keys(JC),...jj];function Nj(e,t){if(t.has(e))throw TypeError(`Cannot initialize the same private elements twice on an object`)}function Pj(e,t,n){Nj(e,t),t.set(e,n)}function Fj(e,t,n){if(typeof e==`function`?e===t:e.has(t))return arguments.length<3?t:n;throw TypeError(`Private element is not present on this object`)}function Ij(e,t){return e.get(Fj(e,t))}function Lj(e,t,n){return e.set(Fj(e,t),n),n}var Rj=new WeakMap,zj=class{constructor(){Pj(this,Rj,0),vi(this,`getVersion`,()=>Ij(Rj,this)),vi(this,`getNextVersion`,()=>this.getVersion()+1),vi(this,`merge`,e=>(!S(e)||!Number.isInteger(e)||this.getVersion()<e&&Lj(Rj,this,e),this))}};function Bj(e){return{...e,clock:new zj}}function Vj({notify:e,dispatch:t,getNextVersion:n},r){let i=r?.commands??[],a=r?.cursor??-1,o=r?.limit??0,s=!0,c=()=>a!==-1,l=()=>a<i.length-1,u=e=>o=e,d=()=>({hasRedo:l(),hasUndo:c()}),f=(e,r)=>{s=!1,e[r](t,n),s=!0};return Object.freeze({get cursor(){return a},get size(){return i.length},hasUndo:c,hasRedo:l,push:t=>{s&&(i.splice(a+1,i.length-a),i.push(t),o!==0&&i.length>o&&(i=i.slice(i.length-o,i.length)),a=i.length-1,e(d()))},undo:()=>{if(!c())return;let t=i[a];f(t,`undo`),a--,e(d())},redo:()=>{if(!l())return;let t=i[a+1];f(t,`redo`),a++,e(d())},clear:()=>{let t=i.length;i=[],a=-1,t>0&&e(d())},setLimit:u,clone:e=>Vj(e,{commands:[...i],cursor:a,limit:o})})}const Hj=Oe(e=>!!e.length),Uj=e=>{let t=B(e);return e=>new xe(n=>e.subscribe({next:e=>n.next(e.filter(e=>t(e.type))),error:e=>n.error(e),complete:()=>n.complete()})).pipe(Hj)},Wj=`@@none-stream`,Gj=(e,t)=>n=>{let r=t.find(([,e])=>e(n));return r?r[0]:e(n)?n:Wj},Kj=(e,t=[],n=Ee(200))=>{let r=B(e),i=t.map(([e,t])=>[e,B(t)]),a=Gj(r,i);return e=>new xe(t=>e.subscribe({next:e=>{let n=e.reduce((e,t)=>{let n=a(t.type);return e[n]||(e[n]=[]),e[n].push(t),e},{});Object.values(n).forEach(e=>t.next(e))},error:e=>t.error(e),complete:()=>t.complete()})).pipe(Hj,Ae(e=>a(e[0].type)),Ne(e=>e.key===Wj?e:e.pipe(Te(e.pipe(n)),je(e=>e.flat()))))},qj=e=>{let t=t=>x(t.tags)||!e.some(e=>W(t.tags,e));return e=>new xe(n=>e.subscribe({next:e=>n.next(e.filter(t)),error:e=>n.error(e),complete:()=>n.complete()})).pipe(Hj)};B(jj),B(Dj);const Jj=(e,t=[])=>{let n=B(wj),r=e=>!x(e.tags)&&t.some(t=>W(e.tags,t))||!n(e.type);return t=>new xe(n=>t.subscribe({next:t=>{n.next(e()?t.filter(r):t)},error:e=>n.error(e),complete:()=>n.complete()})).pipe(Hj)},Yj={[G.scrollTo]:N.viewScrollTo,[G.streamScrollTo]:N.viewStreamScrollTo,[G.changeZoomLevel]:N.viewChangeZoomLevel,[G.streamZoomLevel]:N.viewStreamZoomLevel},Xj=({tags:e})=>!x(e)&&(W(e,Hg.shared)||W(e,Hg.following)),Zj=e=>{let t=Yj[e.type];return t&&!Xj(e)?{...e,type:t}:e},Qj=e=>t=>new xe(n=>t.subscribe({next:t=>{n.next(e()?t.map(Zj):t)},error:e=>n.error(e),complete:()=>n.complete()})),$j=(e,t=[])=>{let n=B(Ej),r=e=>!x(e.tags)&&t.some(t=>W(e.tags,t))||!n(e.type);return t=>new xe(n=>t.subscribe({next:t=>{n.next(e()?t.filter(r):t)},error:e=>n.error(e),complete:()=>n.complete()})).pipe(Hj)};function eM(e,t){return Bu({context:e,state:{...Jp({}),editor:lg(),lww:{}},reducers:{...Zb,...QS,...NC,...tS,...bS,...Uv,...fx,...Ax},enableObservable:t??!0})}const tM=new WeakMap,nM=()=>({boxes:new Map,entries:new Map});function rM(e,t=`document`){let n=tM.get(e);return n||(n={document:nM(),flow:nM()},tM.set(e,n)),n[t]}function iM(e,t){return{left:e.left[t],top:e.top[t],right:e.right[t],bottom:e.bottom[t]}}function aM(e,t){return{left:Math.min(e.left,t.left),top:Math.min(e.top,t.top),right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom)}}function oM(e,t){return e.left===t.left&&e.top===t.top&&e.right===t.right&&e.bottom===t.bottom}function sM(e){let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let{x:a,y:o}of e)a<t&&(t=a),a>r&&(r=a),o<n&&(n=o),o>i&&(i=o);return{left:t,top:n,right:r,bottom:i}}function cM(e,t){return e.left<=t.right&&e.right>=t.left&&e.top<=t.bottom&&e.bottom>=t.top}function lM(e,t){let n={left:e.left-40,top:e.top-40,right:e.right+40,bottom:e.bottom+40};for(let e of t)if(cM(n,e))return!0;return!1}function uM(){let e=new Map,t=new Map,n=(n,r,i,a,o)=>{let s=n?e:t,c=Math.floor(Math.min(r,i)/64),l=Math.floor(Math.max(r,i)/64);for(let e=c;e<=l;e++){let t=s.get(e);t?t.push(r,i,a,o):s.set(e,[r,i,a,o])}};return{markSpan:n,markBox(e){n(!0,e.left,e.right,e.top,e.bottom),n(!1,e.top,e.bottom,e.left,e.right)},hits(n,r,i,a,o){let s=n?e:t;if(!s.size)return!1;let c=Math.min(r,i)-64,l=Math.max(r,i)+64,u=Math.floor(c/64),d=Math.floor(l/64);for(let e=u;e<=d;e++){let t=s.get(e);if(t){for(let e=0;e<t.length;e+=4)if(!(t[e+1]<c||t[e]>l)&&!(t[e+3]<a-16)&&!(t[e+2]>o+16))return!0}}return!1}}}function dM(e,t){for(let n=1;n<t.length;n++){let r=t[n-1],i=t[n];Math.abs(r.x-i.x)<.5?e.markSpan(!0,r.x,i.x,Math.min(r.y,i.y),Math.max(r.y,i.y)):e.markSpan(!1,r.y,i.y,Math.min(r.x,i.x),Math.max(r.x,i.x))}}function fM(e,t){let n=e.boxes,r=new Map,i=[],a=!1;for(let e=0;e<t.ids.length;e++){let o=t.ids[e],s=iM(t,e);if(r.set(o,s),a)continue;let c=n.get(o);c?oM(c,s)||i.push(aM(c,s)):i.push(s),i.length>64&&(a=!0)}if(!a){for(let[e,t]of n)if(!r.has(e)&&(i.push(t),i.length>64)){a=!0;break}}return e.boxes=r,a||n.size===0?null:i}function pM(e){return 50+e%4*12}function mM(e,t){return e.tableId===t.tableId?null:e.direction===L.right&&t.direction===L.left?t.x-e.x:e.direction===L.left&&t.direction===L.right?e.x-t.x:e.direction===L.bottom&&t.direction===L.top?t.y-e.y:e.direction===L.top&&t.direction===L.bottom?e.y-t.y:null}function hM(e,t){return t===null||t<=0?e:Math.max(36,Math.min(e,t/2-1))}function gM(e){return e===L.left||e===L.right}function _M(e){return e===L.right||e===L.bottom?1:-1}function vM(e,t,n){let r=_M(t);return gM(t)?{x:e.x+r*n,y:e.y}:{x:e.x,y:e.y+r*n}}function yM({start:e,end:t},[n,r]){let i=mM(e,t),a=hM(pM(n),i),o=hM(pM(r),i);return{m:vM(e,e.direction,a),l:vM(t,t.direction,o),startStub:a,endStub:o}}function bM(e,t=`document`){let{tableIds:n}=Zg(e,t),r=M(e.collections).collection(`tableEntities`).selectByIds(n),i=r.length,a={ids:Array(i),left:new Float64Array(i),top:new Float64Array(i),right:new Float64Array(i),bottom:new Float64Array(i)};return r.forEach((n,r)=>{let i=O_(e,n,t);a.ids[r]=n.id,a.left[r]=i.lt.x+2,a.top[r]=i.lt.y+2,a.right[r]=i.rb.x-2,a.bottom[r]=i.rb.y-2}),a}function xM(e,t,n,r,i,a,o,s){let c=0,l=1,u=n-e,d=r-t,f=(e,t)=>{if(e===0)return t>=0;let n=t/e;if(e<0){if(n>l)return!1;n>c&&(c=n)}else{if(n<c)return!1;n<l&&(l=n)}return!0};return f(-u,e-i)&&f(u,o-e)&&f(-d,t-a)&&f(d,s-t)&&c<=l}function SM(e,t,n,r){let i=0,a=1/0,o=-1/0,s=1/0,c=-1/0;for(let t=0;t<e.length;t++){let n=e[t];n.x<a&&(a=n.x),n.x>o&&(o=n.x),n.y<s&&(s=n.y),n.y>c&&(c=n.y)}for(let l=0;l<t.ids.length;l++){let u=t.left[l],d=t.right[l],f=t.top[l],p=t.bottom[l];if(o<u||a>d||c<f||s>p)continue;let m=t.ids[l];if(m!==n&&m!==r)for(let t=1;t<e.length;t++){let n=e[t-1],r=e[t];if(!(Math.max(n.x,r.x)<u||Math.min(n.x,r.x)>d)&&!(Math.max(n.y,r.y)<f||Math.min(n.y,r.y)>p)&&xM(n.x,n.y,r.x,r.y,u,f,d,p)){i++;break}}}return i}function CM(e){let t=0;for(let n=1;n<e.length;n++)t+=Math.abs(e[n].x-e[n-1].x)+Math.abs(e[n].y-e[n-1].y);return t}function wM(e,t,n,r,i,a){let o=(e+t)/2,s=n[r?`left`:`top`],c=n[r?`right`:`bottom`],l=n[r?`top`:`left`],u=n[r?`bottom`:`right`],d=[];for(let e=0;e<n.ids.length;e++)u[e]<i||l[e]>a||d.push(s[e]-16,c[e]+16);return d.sort((e,t)=>Math.abs(e-o)-Math.abs(t-o)),[o,...d.slice(0,6)]}function TM(e,t,n,r,i){let a=gM(t),o=gM(r),s=_M(t),c=_M(r),l=Math.min(e.x,n.x,e.y,n.y),u=Math.max(e.x,n.x,e.y,n.y),d=[],f=e=>{let t=[e[0]];for(let n=1;n<e.length;n++){let r=t[t.length-1],i=e[n];Math.abs(i.x-r.x)<.5&&Math.abs(i.y-r.y)<.5||t.push(i)}t.length<2||d.push({points:t,bends:t.length-2})};if(a&&o){let t=wM(e.x,n.x,i,!0,l,u);for(let r of t)(r-e.x)*s<0||(r-n.x)*c<0||f([e,{x:r,y:e.y},{x:r,y:n.y},n]);let r=wM(e.y,n.y,i,!1,l,u);for(let t of r){let r=e.x+s*16,i=n.x+c*16;f([e,{x:r,y:e.y},{x:r,y:t},{x:i,y:t},{x:i,y:n.y},n])}}else if(!a&&!o){let t=wM(e.y,n.y,i,!1,l,u);for(let r of t)(r-e.y)*s<0||(r-n.y)*c<0||f([e,{x:e.x,y:r},{x:n.x,y:r},n]);let r=wM(e.x,n.x,i,!0,l,u);for(let t of r){let r=e.y+s*16,i=n.y+c*16;f([e,{x:e.x,y:r},{x:t,y:r},{x:t,y:i},{x:n.x,y:i},n])}}else if(a){(n.x-e.x)*s>=0&&(e.y-n.y)*c>=0&&f([e,{x:n.x,y:e.y},n]);let t=wM(e.x,n.x,i,!0,l,u).filter(t=>(t-e.x)*s>=0).slice(0,4),r=wM(e.y,n.y,i,!1,l,u).filter(e=>(e-n.y)*c>=0).slice(0,4);for(let i of t)for(let t of r)f([e,{x:i,y:e.y},{x:i,y:t},{x:n.x,y:t},n])}else{(n.y-e.y)*s>=0&&(e.x-n.x)*c>=0&&f([e,{x:e.x,y:n.y},n]);let t=wM(e.y,n.y,i,!1,l,u).filter(t=>(t-e.y)*s>=0).slice(0,4),r=wM(e.x,n.x,i,!0,l,u).filter(e=>(e-n.x)*c>=0).slice(0,4);for(let i of t)for(let t of r)f([e,{x:e.x,y:i},{x:t,y:i},{x:t,y:n.y},n])}return d}function EM(e,t,n,r,i,a,o){let s=TM(e,t,n,r,i),c=null,l=1/0;for(let e of s){let t=SM(e.points,i,a,o)*1e5+e.bends*36+CM(e.points);t<l&&(l=t,c=e.points)}return c||(gM(t)?[e,{x:(e.x+n.x)/2,y:e.y},{x:(e.x+n.x)/2,y:n.y},n]:[e,{x:e.x,y:(e.y+n.y)/2},{x:n.x,y:(e.y+n.y)/2},n])}const DM=[10,7,4],OM=DM[DM.length-1]-.5;function kM(e){let t=[];for(let[n,r]of e)for(let e=0;e<r.length-1;e++){let i=r[e],a=r[e+1],o=Math.abs(i.x-a.x)<.5;o!==Math.abs(i.y-a.y)<.5&&t.push({relationshipId:n,points:r,index:e,movable:e>0&&e<r.length-2,vertical:o,coordinate:o?i.x:i.y,low:o?Math.min(i.y,a.y):Math.min(i.x,a.x),high:o?Math.max(i.y,a.y):Math.max(i.x,a.x)})}return t}function AM(e,t){return e.relationshipId===t.relationshipId?e.index-t.index:e.relationshipId<t.relationshipId?-1:1}function jM(e){let t=e.points[e.index-1];return e.vertical?t.y:t.x}function MM(e){for(let t of e){let e=t.points[t.index],n=t.points[t.index+1];t.low=t.vertical?Math.min(e.y,n.y):Math.min(e.x,n.x),t.high=t.vertical?Math.max(e.y,n.y):Math.max(e.x,n.x)}}function NM(e,t){let n=e.points[e.index],r=e.points[e.index+1];e.vertical?(n.x=t,r.x=t):(n.y=t,r.y=t)}function PM(e,t,n,r){let i=[],a=[];for(let t of kM(e))(t.vertical?i:a).push(t);for(let e of[i,a]){MM(e);let i=e.filter(e=>e.movable);if(i.length<2)continue;i.sort((e,t)=>e.coordinate-t.coordinate||AM(e,t));let a=[],o=()=>{a.length>1&&FM(a,e,t,n,r),a=[]};for(let e of i){let t=a[a.length-1];t&&e.coordinate-t.coordinate>10.5&&o(),a.push(e)}o()}}function FM(e,t,n,r,i){e.sort((e,t)=>e.low-t.low||AM(e,t));let a=[],o=-1/0,s=()=>{a.length>1&&VM(a,t,n,r,i),a=[],o=-1/0};for(let t of e)a.length&&t.low>=o&&s(),a.push(t),o=Math.max(o,t.high);s()}function IM(e,t){return e.high+10>t.low&&t.high+10>e.low}function LM(e,t){return Math.abs(e.coordinate-t.coordinate)>=OM?0:Math.max(0,Math.min(e.high,t.high)-Math.max(e.low,t.low))}function RM(e,t){let n=0;for(let r=0;r<e.length;r++){let i=e[r];for(let t=r+1;t<e.length;t++)n+=LM(i,e[t]);for(let e of t)n+=LM(i,e)}return n}function zM(e,t){let n=new Set(e),r=1/0,i=-1/0;for(let t of e)t.coordinate<r&&(r=t.coordinate),t.coordinate>i&&(i=t.coordinate);let a=10*(e.length-1)/2+OM,o=[];for(let e of t)e.coordinate<r-a||e.coordinate>i+a||n.has(e)||o.push(e);return o}function BM(e){let t=[];for(let n of e){let e=t.find(e=>!IM(e[e.length-1],n));e?e.push(n):t.push([n])}return t}function VM(e,t,n,r,i){if(!i){HM(e,t,n,r);return}if(UM(e,i))return;let a=e.map(e=>e.coordinate);HM(e,t,n,r),WM(e,a,i)}function HM(e,t,n,r){let i=zM(e,t),a=RM(e,i);if(!a)return;let o=new Map,s=e.map(e=>(o.set(e,ZM(e,n,r)),e.coordinate)),c=s.reduce((e,t)=>e+t,0)/s.length,l=GM(e),u=null,d=1/0;for(let t of DM){let a=null,f=1/0;for(let p of l){XM(p,t,c,o,n,r);let l=RM(e,i);if(l)l<d&&(u=e.map(e=>e.coordinate),d=l);else{let t=JM(e,s);t<f&&(f=t,a=e.map(e=>e.coordinate))}YM(e,s)}if(a){YM(e,a);return}}u&&d<a&&YM(e,u)}function UM(e,t){let n=[];for(let r of e){if(t.dirty.has(r.relationshipId))return!1;let e=t.coordinate(r.relationshipId,r.index,r.vertical);if(e===void 0||t.lanes.hits(r.vertical,r.coordinate,e,r.low,r.high))return!1;n.push(e)}return YM(e,n),!0}function WM(e,t,n){e.forEach((e,r)=>{let i=t[r],a=e.coordinate;if(Math.abs(a-i)<.5)return;n.lanes.markSpan(e.vertical,i,a,e.low,e.high);let o=e.points[e.index],s=e.points[e.index+1],c=Math.min(i,a),l=Math.max(i,a),u=e.vertical?o.y:o.x,d=e.vertical?s.y:s.x;n.lanes.markSpan(!e.vertical,u,u,c,l),n.lanes.markSpan(!e.vertical,d,d,c,l)})}function GM(e){let t=BM(e),n=KM(t);return t.length===e.length?n:[...n,...KM(e.map(e=>[e]))]}function KM(e){let t=(e,t)=>e.reduce((e,n)=>e+t(n),0)/e.length,n=[...e].sort((e,n)=>t(e,jM)-t(n,jM)||t(e,qM)-t(n,qM)||AM(e[0],n[0])),r=[...e].sort((e,n)=>t(e,qM)-t(n,qM)||t(e,jM)-t(n,jM)||AM(e[0],n[0]));return n.every((e,t)=>e===r[t])?[n]:[n,r]}function qM(e){return e.coordinate}function JM(e,t){return e.reduce((e,n,r)=>e+Math.abs(n.coordinate-t[r]),0)}function YM(e,t){e.forEach((e,n)=>{NM(e,t[n]),e.coordinate=t[n]})}function XM(e,t,n,r,i,a){let o=n-t*(e.length-1)/2,s=e.map(()=>[]);e.forEach((n,c)=>{for(let l of n){let n=r.get(l);if(!n)continue;let u=r=>{if(r<0||r>=e.length||s[r].some(e=>IM(l,e)))return!1;let c=o+r*t;return NM(l,c),tN(l,i,a,n)?(l.coordinate=c,s[r].push(l),!0):!1},d=!1;for(let e=0;e<=3&&!d;e++)d=u(c-e)||e>0&&u(c+e);d||NM(l,l.coordinate)}})}function ZM(e,t,n){let r=n.get(e.relationshipId),i=[];for(let e=0;e<t.ids.length;e++){let n=t.ids[e];(n===r?.[0]||n===r?.[1])&&i.push(e)}return{blocked:SM(e.points,t,r?.[0]??``,r?.[1]??``),crossed:nN(e.points),own:i,intruded:eN(e.points,t,i),beforeDelta:QM(e,-1),afterDelta:QM(e,1)}}function QM(e,t){let n=e.points[t<0?e.index:e.index+1],r=e.points[t<0?e.index-1:e.index+2];return e.vertical?r.x-n.x:r.y-n.y}function $M(e,t){return Math.abs(t)>=.5&&e*t<=0}function eN(e,t,n){let r=0;for(let i of n){let n=t.left[i],a=t.top[i],o=t.right[i],s=t.bottom[i];for(let t=1;t<e.length;t++){let i=e[t-1],c=e[t];if(xM(i.x,i.y,c.x,c.y,n,a,o,s)){r++;break}}}return r}function tN(e,t,n,r){let i=e.points[e.index-1],a=e.points[e.index],o=e.points[e.index+1],s=e.points[e.index+2];if((e.vertical?Math.abs(i.x-a.x)<.5||Math.abs(s.x-o.x)<.5:Math.abs(i.y-a.y)<.5||Math.abs(s.y-o.y)<.5)||e.index===1&&$M(QM(e,-1),r.beforeDelta)||e.index+2===e.points.length-1&&$M(QM(e,1),r.afterDelta)||eN(e.points,t,r.own)>r.intruded||!r.crossed&&nN(e.points))return!1;let c=n.get(e.relationshipId);return SM(e.points,t,c?.[0]??``,c?.[1]??``)<=r.blocked}function nN(e){for(let t=0;t+1<e.length;t++)for(let n=t+2;n+1<e.length;n++)if(rN(e[t],e[t+1],e[n],e[n+1]))return!0;return!1}function rN(e,t,n,r){let i=Math.abs(e.x-t.x)<.5;if(i===Math.abs(n.x-r.x)<.5)return!1;let a=i?e:n,o=i?t:r,s=i?n:e,c=i?r:t;return a.x>Math.min(s.x,c.x)&&a.x<Math.max(s.x,c.x)&&s.y>Math.min(a.y,o.y)&&s.y<Math.max(a.y,o.y)}const iN={[V.top]:L.top,[V.bottom]:L.bottom,[V.left]:L.left,[V.right]:L.right},aN=Math.PI*2,oN=.15,sN={[V.top]:-Math.PI,[V.right]:-Math.PI/2,[V.bottom]:0,[V.left]:Math.PI/2},cN={[V.top]:!1,[V.right]:!1,[V.bottom]:!0,[V.left]:!0};function lN(e,t=`document`){Ph(t);let{tableIds:n,relationshipIds:r}=Zg(e,t),{collections:i}=e,a=B(n),o=M(i).collection(`tableEntities`),s=M(i).collection(`relationshipEntities`).selectByIds(r).filter(({start:e,end:t})=>a(e.tableId)&&a(t.tableId)),c=new Map,l=new Map,u=new Map,d=xN(s);for(let n of s){let r=bN(n),{start:i,end:a}=r,s=o.selectById(i.tableId),f=o.selectById(a.tableId);if(!(!s||!f)){if(l.set(n,r),u.set(r.id,[0,0]),i.tableId===a.tableId)gN(hN(e,c,s,t),r);else{let n=hN(e,c,s,t),o=hN(e,c,f,t),[l,u]=TN(n.objectPoint,o.objectPoint,r);n[l].push({id:r.id,isStart:!0,point:i,angle:wN(l,n,o),tie:d.tieAt(r.id,i.tableId,a.tableId)}),o[u].push({id:r.id,isStart:!1,point:a,angle:wN(u,o,n),tie:d.tieAt(r.id,a.tableId,i.tableId)})}}}for(let e of c.values())for(let t of _h)EN(t,e,u);for(let[e,n]of l.entries())Ah(e,u.get(n.id)??[0,0],t),Ih(e,n,t);t===`document`?dN(e,l,u):uN(l,u,t)}function uN(e,t,n){for(let[r,i]of e.entries()){let{id:e,start:a,end:o}=i;if(a.tableId===o.tableId)continue;let{m:s,l:c}=yM(i,t.get(e)??[0,0]);Mh(r,[s,c],n)}}function dN(e,t,n){let r=bM(e),i=rM(e),a=fM(i,r),o=i.entries,s=new Map,c=new Set,l=uM();if(a)for(let e of a)l.markBox(e);let u=new Map,d=new Map,f=new Map;for(let[e,i]of t.entries()){let{id:t,start:p,end:m}=i;if(p.tableId===m.tableId)continue;let{m:h,l:g}=yM(i,n.get(t)??[0,0]),_=o.get(t),v,y;a!==null&&_!==void 0&&mN(_,h,g,p,m)&&!lM(_.bounds,a)?(v=_.pristine,y=fN(v)):(y=EM(h,p.direction,g,m.direction,r,p.tableId,m.tableId),v=fN(y),c.add(t),_&&dM(l,_.nudged),dM(l,v)),u.set(t,y),d.set(t,[p.tableId,m.tableId]),f.set(t,e),s.set(t,{mx:h.x,my:h.y,mDirection:p.direction,lx:g.x,ly:g.y,lDirection:m.direction,startTableId:p.tableId,endTableId:m.tableId,pristine:v,nudged:y,bounds:sM(v)})}if(a)for(let[e,t]of o)s.has(e)||dM(l,t.nudged);PM(u,r,d,a===null?void 0:pN(o,c,l));for(let[e,t]of u){let n=f.get(e);n&&Mh(n,t)}i.entries=s}function fN(e){return e.map(({x:e,y:t})=>({x:e,y:t}))}function pN(e,t,n){return{dirty:t,lanes:n,coordinate(t,n,r){let i=e.get(t)?.nudged[n];if(i)return r?i.x:i.y}}}function mN(e,t,n,r,i){return e.mx===t.x&&e.my===t.y&&e.lx===n.x&&e.ly===n.y&&e.mDirection===r.direction&&e.lDirection===i.direction&&e.startTableId===r.tableId&&e.endTableId===i.tableId}function hN(e,t,n,r){let i=t.get(n.id);if(!i){let a=O_(e,n,r);i={tableId:n.id,centerX:a.top.x,centerY:a.left.y,objectPoint:a,selfCount:0,top:[],bottom:[],left:[],right:[]},t.set(n.id,i)}return i}function gN(e,t){let{rt:n,width:r,height:i}=e.objectPoint,a=e.selfCount++,o=yN(Math.min(r,i)*oN,20,60)+a*14;t.start.direction=L.top,t.start.x=n.x-o,t.start.y=n.y,t.end.direction=L.right,t.end.x=n.x,t.end.y=n.y+o}function _N(e,t){let{width:n,height:r}=e.objectPoint;return yN(Math.min(n,r)*oN,20,60)+t*14}function vN(e){return e.selfCount?_N(e,e.selfCount-1)+8:0}function yN(e,t,n){return Math.min(Math.max(e,t),n)}function bN({id:e,start:t,end:n}){return{id:e,start:yh(t),end:yh(n)}}function xN(e){let t=new Map;for(let{id:n,start:r,end:i}of e){let e=SN(r.tableId,i.tableId),a=t.get(e);a?a.push(n):t.set(e,[n])}let n=new Map,r=new Map,i=!1;for(let e of t.values())e.length<2||(i=!0,e.sort(),e.forEach((t,i)=>{n.set(t,i),r.set(t,e.length)}));return{tieAt(e,t,a){if(!i)return 0;let o=n.get(e)??0;return t<=a?o:(r.get(e)??1)-1-o}}}function SN(e,t){return e<t?`${e}|${t}`:`${t}|${e}`}function CN(e){let t=e%aN;return t<0?t+aN:t}function wN(e,t,n){return CN(Math.atan2(n.centerY-t.centerY,n.centerX-t.centerX)-sN[e])}function TN(e,t,n){let r=[V.bottom,V.bottom],i=k_(e.bottom,t.bottom);n.start.x=e.bottom.x,n.start.y=e.bottom.y,n.end.x=t.bottom.x,n.end.y=t.bottom.y,n.start.direction=L.bottom,n.end.direction=L.bottom;for(let a of _h)for(let o of _h){let s=a,c=o,l=k_(e[s],t[c]);i<=l||(i=l,r[0]=s,r[1]=c,n.start.x=e[s].x,n.start.y=e[s].y,n.start.direction=iN[s],n.end.x=t[c].x,n.end.y=t[c].y,n.end.direction=iN[c])}return r}function EN(e,t,n){let r=t[e];if(!r.length)return;r.sort((e,t)=>e.angle-t.angle||e.tie-t.tie||(e.id<t.id?-1:1));let{objectPoint:i}=t,a=e===V.top||e===V.bottom,o=(a?i.lt.x:i.lt.y)+12,s=(a?i.rb.x:i.rb.y)-12,c=vN(t);if(c&&(e===V.top?s-=c:e===V.right&&(o+=c)),s<o){let e=(o+s)/2;o=e,s=e}let l=s-o,u=(o+s)/2,d=r.length,f=d>1?Math.min(l/(d-1),120):0,p=u-f*(d-1)/2;r.forEach((t,r)=>{let o=cN[e]?d-1-r:r,s=p+o*f;a?(t.point.x=s,t.point.y=e===V.top?i.top.y:i.bottom.y):(t.point.y=s,t.point.x=e===V.left?i.left.x:i.right.x);let c=n.get(t.id);c&&(c[+!t.isStart]=r)})}const DN=(e,t)=>e.pipe(He(10,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let{doc:e,collections:n}=t(),r=M(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds);for(let e of r){let{end:t,identification:r}=e,i=M(n).collection(`tableEntities`).selectById(t.tableId);if(!i)continue;let a=B(i.columnIds),o=M(n).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(e=>a(e.id));if(!o.length)continue;let s=o.every(e=>W(e.options,R.primaryKey));s!==r&&(e.identification=s)}}),ON=(e,t)=>e.pipe(He(10,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let{doc:e,collections:n}=t(),r=M(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds);for(let e of r){let{end:t,startRelationshipType:r}=e,i=M(n).collection(`tableEntities`).selectById(t.tableId);if(!i)continue;let a=B(i.columnIds),o=M(n).collection(`tableColumnEntities`).selectByIds(t.columnIds).filter(e=>a(e.id));if(!o.length)continue;let s=o.every(e=>W(e.options,R.notNull))?ih.dash:ih.ring;s!==r&&(e.startRelationshipType=s)}}),kN=B([IS.type,RS.type,Vx.type]),AN=({tags:e})=>!x(e)&&W(e,Hg.drag)?Ue(5):Ue(0,we),jN=(e,t)=>e.pipe(Be(e=>{kN(e.type)||d_()}),Ve(AN,{leading:!1,trailing:!0})).subscribe(()=>{lN(t())}),MN=B([yv.type,zv.type,Vx.type]),NN=B([Sg.type,wg.type,Eg.type,Og.type]),PN=({id:e})=>[e],FN=({ids:e})=>e,IN=({tableId:e})=>[e],LN=(e,{kind:t})=>t,RN=()=>og.flow,zN=(e,{kind:t})=>t??dg(e)?.kind??null,BN={[vg.type]:LN,[bg.type]:LN,[Mg.type]:LN,[Ig.type]:RN,[Pg.type]:zN,[Ag.type]:zN},VN={[PS.type]:PN,[BS.type]:PN,[RS.type]:PN,[HS.type]:PN,[WS.type]:PN,[mS.type]:PN,[gS.type]:PN,[IS.type]:FN,[Ag.type]:FN,[dC.type]:IN,[pC.type]:IN,[hC.type]:IN,[_C.type]:IN,[yC.type]:IN,[xC.type]:IN,[TC.type]:IN};function HN(e,t){let{tableIds:n,relationshipIds:r}=Zg(e,t);return new Set([...n,...r])}function UN(e,t,n,r){if(MN(t.type)||NN(t.type))return!1;let i=BN[t.type];if(i&&i(e,t.payload)!==r)return!1;let a=VN[t.type];if(!a)return!0;let o=HN(e,r);return a(t.payload).some(e=>o.has(e)||n.has(e))}const WN=[og.flow],GN=(e,t)=>{let n={flow:new Set},r=new Set;return e.pipe(Oe(e=>{let i=t(),a=!1;for(let t of WN)fg(i,t)&&UN(i,e,n[t],t)&&(r.add(t),a=!0);return a}),Ve(AN,{leading:!1,trailing:!0})).subscribe(()=>{let e=t(),i=[...r];r.clear();for(let t of i)fg(e,t)&&(lN(e,t),n[t]=HN(e,t))})},KN=[yv,zv,mS,gS,Vx,PS,BS,IS,RS,HS,WS,dC,pC,hC,_C,yC,xC,XS],qN=[TC],JN=[vg,bg,Sg,wg,Eg,Og,Ag,Mg,Pg,Ig],YN=[[[pC,TC,Vy,Gy],DN],[[pC,kC,Vy,Gy],ON],[KN,jN],[[...KN,...qN,...JN],GN]],XN=[[[Vy,Gy],(e,t,n)=>e.pipe(He(5,void 0,{leading:!1,trailing:!0})).subscribe(()=>{let e=t();C_(e,n),lN(e)})],[[BS],(e,t)=>e.pipe(Pe(we)).subscribe(()=>{let{doc:e,editor:n}=t(),r=n.drawRelationship?.start;!r||e.tableIds.includes(r.tableId)||(n.drawRelationship=null)})]],ZN=e=>e.pipe(Pe(we)),QN=[[[TC],(e,t)=>ZN(e).subscribe(({payload:{id:e}})=>{let{collections:n}=t(),r=M(n).collection(`tableColumnEntities`).selectById(e);r&&W(r.options,R.primaryKey)&&(W(r.options,R.notNull)||(r.options|=R.notNull))})],[[mS],(e,t)=>ZN(e).subscribe(({payload:{id:e,end:n}})=>{let{doc:{relationshipIds:r},collections:i}=t();if(!r.includes(e))return;let a=M(i).collection(`tableColumnEntities`).selectByIds(n.columnIds);for(let e of a)e.ui.keys=e.ui.keys|z.foreignKey})],[[gS],(e,t)=>ZN(e).subscribe(({payload:{id:e}})=>{let{doc:{relationshipIds:n},collections:r}=t();if(n.includes(e))return;let i=M(r).collection(`relationshipEntities`).selectById(e);if(!i)return;let a=M(r).collection(`tableColumnEntities`).selectByIds(i.end.columnIds);for(let e of a)e.ui.keys=e.ui.keys&~z.foreignKey})],[[Vy,Gy],(e,t)=>ZN(e).subscribe(()=>{let{doc:e,collections:n}=t(),r=M(n).collection(`relationshipEntities`).selectByIds(e.relationshipIds),i=M(n).collection(`tableEntities`).selectByIds(e.tableIds),a=new Set,o=M(n).collection(`tableColumnEntities`);for(let{end:e}of r){let t=o.selectByIds(e.columnIds);for(let e of t)e.ui.keys=e.ui.keys|z.foreignKey,a.add(e.id)}for(let e of i){let t=o.selectByIds(e.columnIds);for(let e of t)W(e.ui.keys,z.foreignKey)&&!a.has(e.id)&&(e.ui.keys=e.ui.keys&~z.foreignKey)}})]],$N=[...XN,...QN,...YN];function eP(e){let t=()=>e.state,n=$N.map(([n,r])=>{let i=new Se;return{pattern:B(n.map(String)),action$:i,subscription:r(i,t,e.context)}}),r=e.subscribe(e=>{for(let t of e)for(let e of n)e.pattern(t.type)&&e.action$.next(t)});return{destroy:()=>{n.forEach(({action$:e,subscription:t})=>{t.unsubscribe(),e.complete()}),n.splice(0,n.length),r()}}}function tP(e,{getReadonly:t=()=>!1,getHistory:n}={}){let r=new Set,i=eM(e),a=eP(i),o={notify:e=>i.dispatch(Oy(e)),dispatch:i.dispatchSync,getNextVersion:()=>e.clock.getNextVersion()},s=n?.(o)??Vj(o);s.setLimit(2048);let c=()=>dg(i.state),l=new Se,u=l.pipe(Qj(c)),d=new Se,f=new Se,p=f.pipe(Ie(void 0),Le(()=>d.pipe(Kj(jj,[[`@@move`,Oj],[`@@scroll`,Aj],[`@@color`,kj]])))),m=new xe(e=>i.subscribe(t=>e.next(t))).pipe(Uj(Sj),Jj(t,[Hg.shared]),Ee(200)),h=(...t)=>{let n=e.clock.getNextVersion();return Iu(i.state,i.context,t).map(e=>(x(e.version)&&(e.version=n),e))},g=(...e)=>{let t=h(e);l.next(t)},_=(...e)=>{queueMicrotask(()=>g(e))},v=()=>{Array.from(r).forEach(e=>le(e)?e():e.unsubscribe()),r.clear(),i.destroy(),a.destroy(),s.clear(),l.complete()},y=()=>{f.next(),s.clear()},ee=()=>{t()||c()||s.undo()},te=()=>{t()||c()||s.redo()};return r.add(p.subscribe(QC(i,s))).add(u.pipe(Uj(Mj),qj([Hg.changeOnly,Hg.shared]),Jj(t),$j(c)).subscribe(d)).add(u.pipe(Jj(t,[Hg.shared]),$j(c,[Hg.shared])).subscribe(i.dispatchSync)).add(i.subscribe(t=>{t.forEach(t=>e.clock.merge(t.version))})),Object.freeze({...i,dispatch:_,dispatchSync:g,destroy:v,undo:ee,redo:te,history:s,resetHistory:y,change$:m})}const nP={openColorPicker:`openColorPicker`,closeColorPicker:`closeColorPicker`,openToast:`openToast`,openTableProperties:`openTableProperties`,dragendColumnAll:`dragendColumnAll`,copy:`copy`,paste:`paste`,schemaGC:`schemaGC`,toggleSearch:`toggleSearch`,openThemeBuilder:`openThemeBuilder`,setThemeOptions:`setThemeOptions`,mouseTrackerStart:`mouseTrackerStart`,mouseTrackerEnd:`mouseTrackerEnd`,openDiffViewer:`openDiffViewer`,openAutomaticTablePlacement:`openAutomaticTablePlacement`,duplicateDragStart:`duplicateDragStart`,dragSelectStart:`dragSelectStart`};var rP=new WeakMap,iP=class{constructor(){Pj(this,rP,new Set)}on(e){return Ij(rP,this).has(e)||Ij(rP,this).add(e),()=>{Ij(rP,this).delete(e)}}emit(e){Ij(rP,this).forEach(t=>{qC(Reflect.get(t,e.type),e)})}clear(){Ij(rP,this).clear()}};const aP=O(nP.openColorPicker);O(nP.closeColorPicker),O(nP.openToast),O(nP.openTableProperties);const oP=O(nP.dragendColumnAll);O(nP.copy),O(nP.paste),O(nP.schemaGC),O(nP.toggleSearch),O(nP.openThemeBuilder),O(nP.setThemeOptions),O(nP.mouseTrackerStart),O(nP.mouseTrackerEnd),O(nP.openDiffViewer),O(nP.openAutomaticTablePlacement);const sP=O(nP.duplicateDragStart);O(nP.dragSelectStart);const cP=Qe();let lP=cP.os.name===`mac`,uP=cP.os.name===`ios`;cP.os.name,cP.os.name,cP.browser.name,cP.browser.name,cP.browser.name,$e(e=>{lP=e.os.name===`mac`,uP=e.os.name===`ios`,e.os.name,e.os.name,e.browser.name,e.browser.name,e.browser.name});const dP=()=>lP||uP,fP={edit:`edit`,stop:`stop`,search:`search`,undo:`undo`,redo:`redo`,addTable:`addTable`,addColumn:`addColumn`,addMemo:`addMemo`,removeTable:`removeTable`,removeColumn:`removeColumn`,primaryKey:`primaryKey`,selectAllTable:`selectAllTable`,selectAllColumn:`selectAllColumn`,relationshipZeroOne:`relationshipZeroOne`,relationshipZeroN:`relationshipZeroN`,relationshipOneOnly:`relationshipOneOnly`,relationshipOneN:`relationshipOneN`,tableProperties:`tableProperties`,focusView:`focusView`,zoomIn:`zoomIn`,zoomOut:`zoomOut`,zoomReset:`zoomReset`,handTool:`handTool`,zenMode:`zenMode`};Object.values(fP);const pP=()=>({[fP.edit]:[{shortcut:`Enter`}],[fP.stop]:[{shortcut:`Escape`}],[fP.search]:[{shortcut:`$mod+KeyK`,preventDefault:!0,stopPropagation:!0}],[fP.undo]:[{shortcut:`$mod+KeyZ`,preventDefault:!0,stopPropagation:!0}],[fP.redo]:[{shortcut:`$mod+Shift+KeyZ`,preventDefault:!0,stopPropagation:!0}],[fP.addTable]:[{shortcut:`Alt+KeyN`,preventDefault:!0}],[fP.addColumn]:[{shortcut:`Alt+Enter`,preventDefault:!0}],[fP.addMemo]:[{shortcut:`Alt+KeyM`,preventDefault:!0}],[fP.removeTable]:[{shortcut:`$mod+Backspace`,preventDefault:!0},{shortcut:`$mod+Delete`,preventDefault:!0}],[fP.removeColumn]:[{shortcut:`Alt+Backspace`,preventDefault:!0},{shortcut:`Alt+Delete`,preventDefault:!0}],[fP.primaryKey]:[{shortcut:`Alt+KeyK`,preventDefault:!0}],[fP.selectAllTable]:[{shortcut:`$mod+KeyA`,preventDefault:!0},{shortcut:`$mod+Alt+KeyA`,preventDefault:!0}],[fP.selectAllColumn]:[{shortcut:`Alt+KeyA`,preventDefault:!0}],[fP.relationshipZeroOne]:[{shortcut:`$mod+Alt+Digit1`,preventDefault:!0}],[fP.relationshipZeroN]:[{shortcut:`$mod+Alt+Digit2`,preventDefault:!0}],[fP.relationshipOneOnly]:[{shortcut:`$mod+Alt+Digit3`,preventDefault:!0}],[fP.relationshipOneN]:[{shortcut:`$mod+Alt+Digit4`,preventDefault:!0}],[fP.tableProperties]:[{shortcut:`Alt+Space`,preventDefault:!0}],[fP.focusView]:[{shortcut:`Alt+KeyF`,preventDefault:!0,stopPropagation:!0}],[fP.zoomIn]:[{shortcut:`$mod+Equal`,preventDefault:!0,stopPropagation:!0}],[fP.zoomOut]:[{shortcut:`$mod+Minus`,preventDefault:!0,stopPropagation:!0}],[fP.zoomReset]:[{shortcut:`$mod+Digit0`,preventDefault:!0,stopPropagation:!0}],[fP.handTool]:[{shortcut:`Space`,preventDefault:!0}],[fP.zenMode]:[{shortcut:`Alt+KeyZ`,preventDefault:!0,stopPropagation:!0}]}),mP={Shift:`Shift`,Meta:`Meta`,Alt:`Alt`,Control:`Control`};mP.Shift,mP.Meta,mP.Alt,mP.Control,mP.Shift,mP.Meta,mP.Alt,mP.Control;function hP(e){return dP()?e.metaKey:e.ctrlKey}function gP(e,t){let{devtools:n=!0,...r}=t??{},i=Bj(e),a=tP(i,r),o=Ma(pP(),{shallow:!0}),s=new Se,c=new Se,l=new iP;return Object.freeze({...i,actions:xj,store:a,keyBindingMap:o,shortcut$:s,keydown$:c,emitter:l})}const _P=Si({}),vP=(e,t)=>qa(e,{..._P,value:t??_P.value});function yP(e){e.store.dispatchSync(Uy()),e.store.destroy(),e.keydown$.complete(),e.shortcut$.complete(),e.emitter.clear()}const bP=[`table`,`memo`,`relationship`],xP=e=>typeof e==`string`&&bP.includes(e);function SP(e){let t=e;if(typeof t.clientX==`number`)return{x:t.clientX,y:t.clientY};let n=e.touches?.[0];return n?{x:n.clientX,y:n.clientY}:null}const CP=(e,t)=>!!(e&&t&&e.x===t.x&&e.y===t.y),wP=new WeakMap,TP=`mousedown.sceneHit touchstart.sceneHit contextmenu.sceneHit`;function EP(e){return e.on(TP,t=>{let n=t.evt,r=SP(n),i=wP.get(e),a=t.target===e?null:OP(t.target),o=n.type===`contextmenu`&&CP(i?.point,r)?i?.hit??null:null;wP.set(e,{evt:n,hit:a??o,point:r})}),()=>{e.off(TP),wP.delete(e)}}function DP(e,t){let n=`${t}-`,r=e.id();if(r.startsWith(n))return r.slice(n.length);let[i,a=``]=e.name().split(/\s+/);return i===t?a:``}function OP(e){let t=e;for(;t;){let e=t.getAttr(`kind`);if(xP(e))return{kind:e,id:DP(t,e)};t=t.getParent()}return null}const kP=Si({}),AP=e=>qa(e,kP);function jP({app:e,container:t,scene:n,width:r,height:i,theme:a}){let o=new y({container:t,width:r,height:i}),s={host:o.container(),parentElement:null},c=Ja(s,_P,e),l=a?Ja(s,kP,a):null,u=EP(o);return Jf(o,n),{stage:o,destroy:()=>{u(),Jf(o,null),l?.destroy(),c.destroy(),o.destroy()}}}const MP=e=>new Promise(t=>setTimeout(t,e)),NP=32767;function PP(e,t,n){let r=Math.max(t,n),i=t*n;return r<=0||i<=0?e:Math.min(e,NP/r,16384/Math.sqrt(i))}function FP({x:e,y:t,width:n,height:r},i){return{x:e-i,y:t-i,width:n+i*2,height:r+i*2}}function IP(e){let{settings:{show:t},doc:{relationshipIds:n},collections:r}=e,i=F_(e);if(W(t,P.relationship)){let e=M(r).collection(`relationshipEntities`).selectByIds(n);for(let t of e){let e=Bh(t);i=i?P_(i,e):e}}return FP(i??{x:0,y:0,width:0,height:0},80)}function LP({width:e,height:t},n=1){let r=n>0?n:1,i=Math.max(e,t),a=e*t;return i<=0||a<=0?r:Math.min(r,NP/i,Math.sqrt(268435456/a))}const RP={"arrow-right":et,atom:tt,braces:nt,brackets:rt,"case-sensitive":it,check:at,"chevron-down":ot,"chevron-right":st,code:ct,contrast:lt,copy:ut,database:dt,diff:ft,"external-link":pt,eye:mt,"file-diff":ht,"file-image":gt,"file-input":_t,"file-output":vt,fullscreen:yt,"grip-vertical":bt,hand:xt,"key-round":St,maximize:Ct,minimize:wt,minus:Tt,"moon-star":Et,"mouse-pointer-2":Dt,network:Ot,palette:kt,plus:At,"redo-2":jt,"refresh-cw":Mt,"rotate-ccw-clock":Nt,search:Pt,settings:Ft,"share-2":It,spline:Lt,"sticky-note":Rt,sun:zt,table:Bt,"table-2":Vt,"table-properties":Ht,"undo-2":Ut,"wand-sparkles":Wt,waypoints:Gt,workflow:Kt,x:qt},zP={ZeroOneN:[[`circle`,{cx:`7`,cy:`12`,r:`5`}],[`path`,{d:`M12 12h10`}],[`path`,{d:`M15 6v12`}],[`path`,{d:`M16 12l6-6`}],[`path`,{d:`M16 12l6 6`}]],ZeroOne:[[`path`,{d:`M2 12h3`}],[`circle`,{cx:`10`,cy:`12`,r:`5`}],[`path`,{d:`M15 12h7`}],[`path`,{d:`M20 6v12`}]],ZeroN:[[`path`,{d:`M2 12h3`}],[`circle`,{cx:`10`,cy:`12`,r:`5`}],[`path`,{d:`M15 12h7`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]],OneOnly:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}],[`path`,{d:`M19 6v12`}]],OneN:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]],One:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M14 6v12`}]],N:[[`path`,{d:`M2 12h20`}],[`path`,{d:`M15 12l7-6`}],[`path`,{d:`M15 12l7 6`}]]},BP={};VP();function VP(){for(let e of Object.keys(RP))BP[e]={name:e,node:RP[e]};for(let e of Object.keys(zP))BP[e]={name:e,node:zP[e]}}function HP(e){return BP[e]}const UP=`-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Open Sans', system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'`;Hd.global`
|
|
27
27
|
:host {
|
|
28
|
-
--text-font-family: ${
|
|
28
|
+
--text-font-family: ${UP};
|
|
29
29
|
--code-font-family: ${`'Menlo', 'Consolas', 'Bitstream Vera Sans Mono', monospace, 'Apple Color Emoji', 'Segoe UI Emoji'`};
|
|
30
30
|
}
|
|
31
|
-
`;const wM=CM,TM=`normal normal 12px ${wM}`,EM={ascent:0,descent:0};let DM=null;function OM(){if(DM)return DM;if(typeof document>`u`)return EM;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return EM;e.font=TM;let t=e.measureText(`M`),n=t.fontBoundingBoxAscent??t.actualBoundingBoxAscent,r=t.fontBoundingBoxDescent??t.actualBoundingBoxDescent;return!Number.isFinite(n)||!Number.isFinite(r)?EM:(DM={ascent:n,descent:r},DM)}const kM=[20,24,28,35,60],AM=1.5,jM=Number(`0 0 24 24`.split(` `)[2]),MM=`transparent`,NM=MM,PM=`pointer`;function FM(e,t){let n=e.target?.getStage()?.container();n&&(n.style.cursor=t)}function IM(e){return e instanceof MouseEvent}function LM(e,t,n,r){if(!IM(t)||!t.altKey||t.button!==0)return!1;let{store:i,emitter:a}=e;return i.state.editor.selectedMap[n]||i.dispatchSync(r===s_.memo?bS(n,!1):kS(n,!1)),t.preventDefault(),a.emit(Hj()),!0}const RM=wa({active:{}});function zM(e){RM.active[e.editor.id]=!0,Yh(e)}function BM(e){Reflect.deleteProperty(RM.active,e.editor.id),Xh(e)}function VM(e,t){let n=e??null;for(;n;){let e=n.getAttr(`kind`);if(typeof e==`string`&&t.includes(e))return!0;n=n.getParent()}return!1}const HM={focus:`@dineug/erd-editor/internal-focus`,forceFocus:`@dineug/erd-editor/internal-force-focus`,forwardMoveStart:`@dineug/erd-editor/internal-forward-move-start`};function UM(e,t){function n(n,r){return new CustomEvent(e,{detail:n,...t,...r})}return n.toString=()=>`${e}`,n.type=e,n}UM(HM.focus),UM(HM.forceFocus);const WM=UM(HM.forwardMoveStart,{bubbles:!0,composed:!0});function GM(e){return ke(()=>je(window,e))}GM(`keyup`);const KM=GM(`mousedown`),qM=GM(`mousemove`),JM=GM(`mouseup`),YM=GM(`touchstart`),XM=GM(`touchmove`),ZM=GM(`touchend`),QM=GM(`dragstart`),$M=GM(`pointercancel`),eN=GM(`blur`);Te().pipe(Le());const tN=GM(WM.type).pipe(Ne(e=>e.detail.originEvent)),nN=Pe(KM,YM,tN),rN=Pe(JM,ZM,QM,$M,eN);let iN=0,aN=0;typeof window<`u`&&nN.subscribe(e=>{IM(e)?(iN=e.clientX,aN=e.clientY):(iN=e.touches[0].clientX,aN=e.touches[0].clientY)});const oN=Pe(qM.pipe(Ne(e=>{let t=e.clientX,n=e.clientY,r=t-iN,i=n-aN;return iN=t,aN=n,{event:e,movementX:r,movementY:i,x:t,y:n}})),XM.pipe(Ae(e=>e.touches.length===1),Ne(e=>{let t=e.touches[0].clientX,n=e.touches[0].clientY,r=t-iN,i=n-aN;return iN=t,aN=n,{event:e,movementX:r,movementY:i,x:t,y:n}}))).pipe(Re(rN));function sN(e,t){let n=Qj(e),r=({event:e,movementX:t,movementY:r})=>{e.type===`mousemove`&&e.preventDefault();let{store:i}=n.value;i.dispatch(nk(t,r))};return{onMoveStart:e=>{if(!e?.target)return;let{store:i}=n.value,a=t.entityId(),o=!VM(e.target,t.blockedKinds);if(o&&LM(n.value,e.evt,a,t.selectType))return;let s=Yj(e.evt)||!!i.state.editor.selectedMap[a];i.dispatch(t.selectType===s_.memo?bS(a,s):kS(a,s)),o&&(zM(i.state),oN.subscribe(r).add(()=>BM(i.state)))}}}const cN=[`table-header-color`,`column-row`,`icon`,`input-padding`];function lN(e,t){return sN(e,{entityId:()=>t.table.id,selectType:s_.table,blockedKinds:cN})}function uN(){let e=new Set;return ia(()=>{Array.from(e).forEach(e=>de(e)?e():e.unsubscribe()),e.clear()}),{addUnsubscribe:(...t)=>{t.forEach(t=>e.add(t))}}}function dN(e,t,n,r=null){if(!e||n!==e.tableId)return!1;switch(t){case`tableName`:case`tableComment`:return t===e.focusType}return r===e.columnId&&t===e.focusType}const fN=(e,t,n)=>e?.tableId===t&&e.selectColumnIds.includes(n);function pN(e,t,n,r=null){if(e?.tableId!==n)return!1;switch(t){case W.tableName:case W.tableComment:return t===e.focusType&&e.edit}return r===e.columnId&&t===e.focusType&&e.edit}const mN={grayColor1:`gray-1`,grayColor2:`gray-2`,grayColor3:`gray-3`,grayColor4:`gray-4`,grayColor5:`gray-5`,grayColor6:`gray-6`,grayColor7:`gray-7`,grayColor8:`gray-8`,grayColor9:`gray-9`,grayColor10:`gray-10`,grayColor11:`gray-11`,grayColor12:`gray-12`,accentColor1:`accent-1`,accentColor2:`accent-2`,accentColor3:`accent-3`,accentColor4:`accent-4`,accentColor5:`accent-5`,accentColor6:`accent-6`,accentColor7:`accent-7`,accentColor8:`accent-8`,accentColor9:`accent-9`,accentColor10:`accent-10`,accentColor11:`accent-11`,accentColor12:`accent-12`,canvasBackground:`gray-3`,canvasBoundaryBackground:`gray-1`,tableBackground:`gray-2`,tableSelect:`accent-8`,tableBorder:`gray-6`,memoBackground:`gray-2`,memoSelect:`accent-8`,memoBorder:`gray-6`,columnSelect:`gray-5`,columnHover:`gray-4`,relationshipHover:`accent-8`,toolbarBackground:`gray-1`,contextMenuBackground:`gray-2`,contextMenuSelect:`gray-4`,contextMenuHover:`accent-7`,contextMenuBorder:`gray-6`,minimapBorder:`override-black`,minimapShadow:`override-black`,minimapViewportBorder:`accent-7`,minimapViewportBorderHover:`accent-8`,toastBackground:`gray-2`,toastBorder:`gray-6`,dragSelectBackground:`accent-5`,dragSelectBorder:`accent-8`,scrollbarTrack:`grayA-3`,scrollbarThumb:`gray-9`,scrollbarThumbHover:`gray-10`,foreground:`gray-11`,active:`gray-12`,placeholder:`grayA-10`,focus:`accent-8`,inputActive:`accent-10`,keyPK:`custom-amber--9`,keyFK:`custom-ruby--9`,keyPFK:`custom-cyan--9`,diffInsertBackground:`custom-green--4`,diffDeleteBackground:`custom-red--4`,diffCrossBackground:`custom-blue--4`,diffInsertForeground:`custom-green--11`,diffDeleteForeground:`custom-red--11`,diffCrossForeground:`custom-blue--11`},hN={amber:Vt,amberA:Ht,amberDark:Ut,amberDarkA:Wt,blue:Gt,blueA:Kt,blueDark:qt,blueDarkA:Jt,bronze:Yt,bronzeA:Xt,bronzeDark:Zt,bronzeDarkA:Qt,brown:$t,brownA:en,brownDark:tn,brownDarkA:nn,crimson:rn,crimsonA:an,crimsonDark:on,crimsonDarkA:sn,cyan:cn,cyanA:ln,cyanDark:un,cyanDarkA:dn,gold:fn,goldA:pn,goldDark:mn,goldDarkA:hn,grass:gn,grassA:_n,grassDark:vn,grassDarkA:yn,gray:bn,grayA:xn,grayDark:Sn,grayDarkA:Cn,green:wn,greenA:Tn,greenDark:En,greenDarkA:Dn,indigo:On,indigoA:kn,indigoDark:An,indigoDarkA:jn,iris:Mn,irisA:Nn,irisDark:Pn,irisDarkA:Fn,jade:In,jadeA:Ln,jadeDark:Rn,jadeDarkA:zn,lime:Bn,limeA:Vn,limeDark:Hn,limeDarkA:Un,mauve:Wn,mauveA:Gn,mauveDark:Kn,mauveDarkA:qn,mint:Jn,mintA:Yn,mintDark:Xn,mintDarkA:Zn,olive:Qn,oliveA:$n,oliveDark:er,oliveDarkA:tr,orange:nr,orangeA:rr,orangeDark:ir,orangeDarkA:ar,pink:or,pinkA:sr,pinkDark:cr,pinkDarkA:lr,plum:ur,plumA:dr,plumDark:fr,plumDarkA:pr,purple:mr,purpleA:hr,purpleDark:gr,purpleDarkA:_r,red:vr,redA:yr,redDark:br,redDarkA:xr,ruby:Sr,rubyA:Cr,rubyDark:wr,rubyDarkA:Tr,sage:Er,sageA:Dr,sageDark:Or,sageDarkA:kr,sand:Ar,sandA:jr,sandDark:Mr,sandDarkA:Nr,sky:Pr,skyA:Fr,skyDark:Ir,skyDarkA:Lr,slate:Rr,slateA:zr,slateDark:Br,slateDarkA:Vr,teal:Hr,tealA:Ur,tealDark:Wr,tealDarkA:Gr,tomato:Kr,tomatoA:qr,tomatoDark:Jr,tomatoDarkA:Yr,violet:Xr,violetA:Zr,violetDark:Qr,violetDarkA:$r,yellow:ei,yellowA:ti,yellowDark:ni,yellowDarkA:ri};Object.values({dark:`dark`,light:`light`}),Object.values({gray:`gray`,mauve:`mauve`,slate:`slate`,sage:`sage`,olive:`olive`,sand:`sand`}),Object.values({gray:`gray`,gold:`gold`,bronze:`bronze`,brown:`brown`,yellow:`yellow`,amber:`amber`,orange:`orange`,tomato:`tomato`,red:`red`,ruby:`ruby`,crimson:`crimson`,pink:`pink`,plum:`plum`,purple:`purple`,violet:`violet`,iris:`iris`,indigo:`indigo`,blue:`blue`,cyan:`cyan`,teal:`teal`,jade:`jade`,green:`green`,grass:`grass`,lime:`lime`,mint:`mint`,sky:`sky`}),Object.keys(mN);const gN=[`tomato`,`gold`,`grass`,`teal`,`iris`,`purple`,`plum`,`pink`].map(e=>Ve(hN,`${e}.${e}9`)??``);function _N(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return gN[Math.abs(t)%gN.length]}function vN(e,t){let n=Qj(e),{addUnsubscribe:r}=uN(),i=wa({force:!1}),a=()=>{i.force=!i.force};ra(()=>{let{store:e}=n.value,{editor:{sharedFocusTrackerMap:t}}=e.state;r(Ta(t).subscribe(a))});let o=()=>{let{store:e}=n.value;return i.force,Object.values(e.state.editor.sharedFocusTrackerMap)};return{sharedFocusTableColor:()=>{let e=o().find(e=>e.tableId===t);return e?_N(e.id):null},sharedFocusColor:(e,n)=>{let r=o().find(r=>dN(r,e,t,n));return r?_N(r.id):null}}}function yN(e,t){let n=Qj(e),{addUnsubscribe:r}=uN(),i=wa({force:!1}),a=()=>{i.force=!i.force};return ra(()=>{let{store:e}=n.value,{editor:{sharedSelectionTrackerMap:t}}=e.state;r(Ta(t).subscribe(a))}),{sharedSelectColor:()=>{let{store:e}=n.value;i.force;let r=Object.values(e.state.editor.sharedSelectionTrackerMap).find(e=>e.selectedIds.includes(t));return r?_N(r.id):null}}}const bN=e=>e>.6?kM[0]:e>.5?kM[1]:e>.4?kM[2]:e>.3?kM[3]:kM[4],xN=(e,t)=>{let n=Qj(t),r=uM(t),{sharedFocusTableColor:i}=vN(t,e.table.id),{sharedSelectColor:a}=yN(t,e.table.id),{onMoveStart:o}=lN(t,e),s=t=>{let{emitter:r}=n.value;r.emit(Bj({x:t.evt.clientX,y:t.evt.clientY,color:e.table.ui.color}))};return()=>{let{store:t}=n.value,{editor:c,settings:l}=t.state,{table:u}=e,d=r.value,f=!!c.selectedMap[u.id],p=Rh(t.state,u),m=He(u.name.trim()),h=i(),g=a(),ee=h??g;return O`<k-group id=${e.preview?``:`table-${u.id}`} name="table high-level-table" kind="table" visible=${e.visible??!0} selected=${f} sharedFocus=${h} sharedSelect=${g} x=${p.x} y=${p.y} @mousedown=${o} @touchstart=${o}><k-rect name="table-body" x=${1/2} y=${1/2} width=${p.width-1} height=${p.height-1} cornerRadius=${6} fill=${d.tableBackground} stroke=${f?d.tableSelect:d.tableBorder} strokeWidth=${1} />${ee?O`<k-rect name="table-ring" x=${-1/2} y=${-1/2} width=${p.width+1} height=${p.height+1} cornerRadius=${6} stroke=${ee} strokeWidth=${1} />`:null}<k-rect name="table-header-color" kind="table-header-color" x=${1} y=${0} width=${p.width-2} height=${4} cornerRadius=${[6,6,0,0]} fill=${u.ui.color} @click=${s} @mouseenter=${e=>{FM(e,PM)}} @mouseleave=${e=>{FM(e,``)}} /><k-text name="high-level-table-name" x=${1} y=${9} width=${p.width-2} height=${p.height-18} text=${m?`unnamed`:u.name} fill=${m?d.placeholder:d.active} fontFamily=${wM} fontSize=${bN(l.zoomLevel)} fontStyle="bold" align="center" verticalAlign="middle" wrap="char" /></k-group>`}};Pd`
|
|
31
|
+
`;function WP(e){return e instanceof MouseEvent}function GP(e){return(e.touches?.length??0)>1}const KP=UP,qP=e=>`normal normal 12px ${e}`;qP(KP);const JP={ascent:0,descent:0},YP=new Map;function XP(e=KP){let t=YP.get(e);if(t)return t;if(typeof document>`u`)return JP;let n=document.createElement(`canvas`).getContext(`2d`);if(!n)return JP;n.font=qP(e);let r=n.measureText(`M`),i=r.fontBoundingBoxAscent??r.actualBoundingBoxAscent,a=r.fontBoundingBoxDescent??r.actualBoundingBoxDescent;if(!Number.isFinite(i)||!Number.isFinite(a))return JP;let o={ascent:i,descent:a};return YP.set(e,o),o}const ZP=[20,24,28,35,60],QP=1.5;function $P(e){return{color:e,blur:20,offsetX:0,offsetY:2,opacity:.4}}const eF=Number(`0 0 24 24`.split(` `)[2]),tF=`transparent`,nF=tF,rF=new Set([tF,`none`,``]);function iF(e){let t=(e??``).trim();return rF.has(t)?null:{color:t,blur:10,offsetX:0,offsetY:2,opacity:1}}const aF=`pointer`,oF=new WeakMap,sF=e=>e.target?.getStage()?.container();function cF(e,t){let n=sF(e);if(!n)return;let r=oF.get(n);r?r.requested=t:n.style.cursor=t}function lF(e,t){let n=sF(e);if(!n||!WP(e.evt))return me;let r={requested:oF.get(n)?.requested??n.style.cursor};return oF.set(n,r),n.style.cursor=t,()=>{oF.get(n)===r&&(oF.delete(n),n.style.cursor=r.requested)}}function uF(e){let t=Math.min(6.5,e/2),n=Math.min(4,t),r=t-Math.sqrt(t**2-(t-n)**2);return[`M ${n} ${r}`,`A ${t} ${t} 0 0 0 0 ${t}`,`L 0 ${e-t}`,`A ${t} ${t} 0 0 0 ${n} ${e-r}`,`Z`].join(` `)}function dF(e,t,n,r){if(!WP(t)||!t.altKey||t.button!==0)return!1;let{store:i,emitter:a}=e;return i.state.editor.selectedMap[n]||i.dispatchSync(r===ig.memo?tw(n,!1):uw(n,!1)),t.preventDefault(),a.emit(sP()),!0}const fF=Ma({active:{}});function pF(e,t=`document`){fF.active[$_(e,t)]=!0,tv(e,t)}function mF(e,t=`document`){Reflect.deleteProperty(fF.active,$_(e,t)),nv(e,t)}function hF(e,t){let n=e??null;for(;n;){let e=n.getAttr(`kind`);if(typeof e==`string`&&t.includes(e))return!0;n=n.getParent()}return!1}const gF={focus:`@dineug/erd-editor/internal-focus`,forceFocus:`@dineug/erd-editor/internal-force-focus`,forwardMoveStart:`@dineug/erd-editor/internal-forward-move-start`};function _F(e,t){function n(n,r){return new CustomEvent(e,{detail:n,...t,...r})}return n.toString=()=>`${e}`,n.type=e,n}_F(gF.focus),_F(gF.forceFocus);const vF=_F(gF.forwardMoveStart,{bubbles:!0,composed:!0});function yF(e){return De(()=>ke(window,e))}yF(`keyup`);const bF=yF(`mousedown`),xF=yF(`mousemove`),SF=yF(`mouseup`),CF=yF(`touchstart`),wF=yF(`touchmove`),TF=yF(`touchend`),EF=yF(`dragstart`),DF=yF(`pointercancel`),OF=yF(`blur`);Ce().pipe(Fe());const kF=yF(vF.type).pipe(je(e=>e.detail.originEvent)),AF=Me(bF,CF,kF),jF=Me(SF,TF,EF,DF,OF);let MF=0,NF=0;typeof window<`u`&&AF.subscribe(e=>{WP(e)?(MF=e.clientX,NF=e.clientY):(MF=e.touches[0].clientX,NF=e.touches[0].clientY)});const PF=Me(xF.pipe(je(e=>{let t=e.clientX,n=e.clientY,r=t-MF,i=n-NF;return MF=t,NF=n,{event:e,movementX:r,movementY:i,x:t,y:n}})),wF.pipe(Oe(e=>e.touches.length===1),je(e=>{let t=e.touches[0].clientX,n=e.touches[0].clientY,r=t-MF,i=n-NF;return MF=t,NF=n,{event:e,movementX:r,movementY:i,x:t,y:n}}))).pipe(ze(jF));function FF(e,t){let n=vP(e),r=e=>({event:t,movementX:r,movementY:i})=>{t.type===`mousemove`&&t.preventDefault();let{store:a}=n.value;a.dispatch(GA(r,i,e))};return{onMoveStart:e=>{if(!e?.target||GP(e.evt))return;let{store:i}=n.value,a=t.entityId(),o=t.source.value,s=!hF(e.target,t.blockedKinds(o));if(s&&dF(n.value,e.evt,a,t.selectType))return;let c=hP(e.evt)||!!i.state.editor.selectedMap[a];if(i.dispatch(t.selectType===ig.memo?tw(a,c):uw(a,c)),!s)return;let l=r(o),u=!1,d=0,f=0,p=()=>{u=!0,pF(i.state,o)};hF(e.target,t.clickKinds?.(o)??[])||p(),PF.subscribe(e=>{if(u)return l(e);e.event.type===`mousemove`&&e.event.preventDefault(),d+=e.movementX,f+=e.movementY,!(Math.abs(d)+Math.abs(f)<4)&&(p(),l({...e,movementX:d,movementY:f}))}).add(()=>u&&mF(i.state,o))}}}const IF=[`table-header-color`,`column-row`,`icon`],LF=[`input-padding`],RF=[`icon`];function zF(e,t,n){return FF(e,{entityId:()=>t.table.id,selectType:ig.table,blockedKinds:e=>e===`document`?IF:RF,clickKinds:e=>e===`document`?LF:[],source:n})}function BF(){let e=new Set;return fa(()=>{Array.from(e).forEach(e=>le(e)?e():e.unsubscribe()),e.clear()}),{addUnsubscribe:(...t)=>{t.forEach(t=>e.add(t))}}}function VF(e,t,n,r=null){if(!e||n!==e.tableId)return!1;switch(t){case`tableName`:case`tableComment`:return t===e.focusType}return r===e.columnId&&t===e.focusType}const HF=(e,t,n)=>e?.tableId===t&&e.selectColumnIds.includes(n);function UF(e,t,n,r=null){if(e?.tableId!==n)return!1;switch(t){case U.tableName:case U.tableComment:return t===e.focusType&&e.edit}return r===e.columnId&&t===e.focusType&&e.edit}const WF={grayColor1:`gray-1`,grayColor2:`gray-2`,grayColor3:`gray-3`,grayColor4:`gray-4`,grayColor5:`gray-5`,grayColor6:`gray-6`,grayColor7:`gray-7`,grayColor8:`gray-8`,grayColor9:`gray-9`,grayColor10:`gray-10`,grayColor11:`gray-11`,grayColor12:`gray-12`,accentColor1:`accent-1`,accentColor2:`accent-2`,accentColor3:`accent-3`,accentColor4:`accent-4`,accentColor5:`accent-5`,accentColor6:`accent-6`,accentColor7:`accent-7`,accentColor8:`accent-8`,accentColor9:`accent-9`,accentColor10:`accent-10`,accentColor11:`accent-11`,accentColor12:`accent-12`,canvasBackground:`gray-3`,canvasBoundaryBackground:`gray-1`,tableBackground:`gray-2`,tableHeaderBackground:`gray-5`,tableSelect:`accent-8`,tableBorder:`gray-6`,tableShadow:`override-transparent`,memoBackground:`gray-2`,memoSelect:`accent-8`,memoBorder:`gray-6`,memoShadow:`override-transparent`,columnSelect:`accent-3`,columnSelectHover:`accent-4`,columnHover:`gray-4`,relationshipHover:`accent-8`,visualizationLink:`gray-7`,visualizationColumn:`gray-8`,visualizationRelationship:`gray-8`,toolbarBackground:`gray-1`,contextMenuBackground:`gray-2`,contextMenuSelect:`gray-4`,contextMenuHover:`accent-7`,contextMenuBorder:`gray-6`,minimapBorder:`override-black`,minimapShadow:`override-black`,minimapViewportBorder:`accent-7`,minimapViewportBorderHover:`accent-8`,toastBackground:`gray-2`,toastBorder:`gray-6`,dragSelectBackground:`accent-5`,dragSelectBorder:`accent-8`,scrollbarTrack:`grayA-3`,scrollbarThumb:`gray-9`,scrollbarThumbHover:`gray-10`,foreground:`gray-11`,active:`gray-12`,placeholder:`grayA-10`,focus:`accent-8`,inputActive:`accent-10`,keyPK:`custom-amber--9`,keyFK:`custom-ruby--9`,keyPFK:`custom-cyan--9`,diffInsertBackground:`custom-green--4`,diffDeleteBackground:`custom-red--4`,diffCrossBackground:`custom-blue--4`,diffInsertForeground:`custom-green--11`,diffDeleteForeground:`custom-red--11`,diffCrossForeground:`custom-blue--11`},GF={amber:Jt,amberA:Yt,amberDark:Xt,amberDarkA:Zt,blue:Qt,blueA:$t,blueDark:en,blueDarkA:tn,bronze:nn,bronzeA:rn,bronzeDark:an,bronzeDarkA:on,brown:sn,brownA:cn,brownDark:ln,brownDarkA:un,crimson:dn,crimsonA:fn,crimsonDark:pn,crimsonDarkA:mn,cyan:hn,cyanA:gn,cyanDark:_n,cyanDarkA:vn,gold:yn,goldA:bn,goldDark:xn,goldDarkA:Sn,grass:Cn,grassA:wn,grassDark:Tn,grassDarkA:En,gray:Dn,grayA:On,grayDark:kn,grayDarkA:An,green:jn,greenA:Mn,greenDark:Nn,greenDarkA:Pn,indigo:Fn,indigoA:In,indigoDark:Ln,indigoDarkA:Rn,iris:zn,irisA:Bn,irisDark:Vn,irisDarkA:Hn,jade:Un,jadeA:Wn,jadeDark:Gn,jadeDarkA:Kn,lime:qn,limeA:Jn,limeDark:Yn,limeDarkA:Xn,mauve:Zn,mauveA:Qn,mauveDark:$n,mauveDarkA:er,mint:tr,mintA:nr,mintDark:rr,mintDarkA:ir,olive:ar,oliveA:or,oliveDark:sr,oliveDarkA:cr,orange:lr,orangeA:ur,orangeDark:dr,orangeDarkA:fr,pink:pr,pinkA:mr,pinkDark:hr,pinkDarkA:gr,plum:_r,plumA:vr,plumDark:yr,plumDarkA:br,purple:xr,purpleA:Sr,purpleDark:Cr,purpleDarkA:wr,red:Tr,redA:Er,redDark:Dr,redDarkA:Or,ruby:kr,rubyA:Ar,rubyDark:jr,rubyDarkA:Mr,sage:Nr,sageA:Pr,sageDark:Fr,sageDarkA:Ir,sand:Lr,sandA:Rr,sandDark:zr,sandDarkA:Br,sky:Vr,skyA:Hr,skyDark:Ur,skyDarkA:Wr,slate:Gr,slateA:Kr,slateDark:qr,slateDarkA:Jr,teal:Yr,tealA:Xr,tealDark:Zr,tealDarkA:Qr,tomato:$r,tomatoA:ei,tomatoDark:ti,tomatoDarkA:ni,violet:ri,violetA:ii,violetDark:ai,violetDarkA:oi,yellow:si,yellowA:ci,yellowDark:li,yellowDarkA:ui};Object.values({dark:`dark`,light:`light`}),Object.values({gray:`gray`,mauve:`mauve`,slate:`slate`,sage:`sage`,olive:`olive`,sand:`sand`});const KF={gray:`gray`,gold:`gold`,bronze:`bronze`,brown:`brown`,yellow:`yellow`,amber:`amber`,orange:`orange`,tomato:`tomato`,red:`red`,ruby:`ruby`,crimson:`crimson`,pink:`pink`,plum:`plum`,purple:`purple`,violet:`violet`,iris:`iris`,indigo:`indigo`,blue:`blue`,cyan:`cyan`,teal:`teal`,jade:`jade`,green:`green`,grass:`grass`,lime:`lime`,mint:`mint`,sky:`sky`};Object.values(KF),Object.keys(WF),B([KF.gray,KF.gold,KF.bronze]);const qF=[`tomato`,`gold`,`grass`,`teal`,`iris`,`purple`,`plum`,`pink`].map(e=>We(GF,`${e}.${e}9`)??``);function JF(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return qF[Math.abs(t)%qF.length]}function YF(e,t){let n=vP(e),{addUnsubscribe:r}=BF(),i=Ma({force:!1}),a=()=>{i.force=!i.force};da(()=>{let{store:e}=n.value,{editor:{sharedFocusTrackerMap:t}}=e.state;r(Na(t).subscribe(a))});let o=()=>{let{store:e}=n.value;return i.force,Object.values(e.state.editor.sharedFocusTrackerMap)};return{sharedFocusTableColor:()=>{let e=o().find(e=>e.tableId===t);return e?JF(e.id):null},sharedFocusColor:(e,n)=>{let r=o().find(r=>VF(r,e,t,n));return r?JF(r.id):null}}}function XF(e,t){let n=vP(e),{addUnsubscribe:r}=BF(),i=Ma({force:!1}),a=()=>{i.force=!i.force};return da(()=>{let{store:e}=n.value,{editor:{sharedSelectionTrackerMap:t}}=e.state;r(Na(t).subscribe(a))}),{sharedSelectColor:()=>{let{store:e}=n.value;i.force;let r=Object.values(e.state.editor.sharedSelectionTrackerMap).find(e=>e.selectedIds.includes(t));return r?JF(r.id):null}}}const ZF=Si(`document`),QF=e=>qa(e,ZF),$F=e=>e>.6?ZP[0]:e>.5?ZP[1]:e>.4?ZP[2]:e>.3?ZP[3]:ZP[4],eI=(e,t)=>{let n=vP(t),r=AP(t),i=QF(t),{sharedFocusTableColor:a}=YF(t,e.table.id),{sharedSelectColor:o}=XF(t,e.table.id),{onMoveStart:s}=zF(t,e,i),c=!1,l=e=>{c=!!n.value.store.state.editor.drawRelationship,s(e)},u=t=>{if(c)return;let{emitter:r}=n.value;r.emit(aP({x:t.evt.clientX,y:t.evt.clientY,color:e.table.ui.color}))};return()=>{let{store:t}=n.value,{editor:s}=t.state,{table:c}=e,d=r.value,f=i.value,p=!!s.selectedMap[c.id],m=A_(t.state,c,f),{zoomLevel:h}=B_(t.state,f),g=Ge(c.name.trim()),_=a(),v=o(),y=_??v;return k`<k-group id=${e.preview?``:`table-${c.id}`} name="table high-level-table" kind="table" visible=${e.visible??!0} selected=${p} sharedFocus=${_} sharedSelect=${v} x=${m.x} y=${m.y} @mousedown=${l} @touchstart=${l}><k-rect name="table-body" x=${1/2} y=${1/2} width=${m.width-1} height=${m.height-1} cornerRadius=${6} fill=${d.tableBackground} stroke=${p?d.tableSelect:d.tableBorder} strokeWidth=${1} />${y?k`<k-rect name="table-ring" x=${-1/2} y=${-1/2} width=${m.width+1} height=${m.height+1} cornerRadius=${6} stroke=${y} strokeWidth=${1} />`:null}<k-text name="high-level-table-name" x=${1} y=${9} width=${m.width-2} height=${m.height-18} text=${g?`unnamed`:c.name} fill=${g?d.placeholder:d.active} fontFamily=${KP} fontSize=${$F(h)} fontStyle="bold" align="center" verticalAlign="middle" wrap="char" /><k-path name="table-header-color" kind="table-header-color" data=${uF(m.height)} fill=${c.ui.color} @click=${u} @mouseenter=${e=>{cF(e,aF)}} @mouseleave=${e=>{cF(e,``)}} /></k-group>`}};Hd`
|
|
32
32
|
position: absolute;
|
|
33
33
|
|
|
34
34
|
&.vertical {
|
|
@@ -47,8 +47,8 @@ import*as e from"comlink";import{CHARSET as t,DECLARATION as n,IMPORT as r,LAYER
|
|
|
47
47
|
width: ${5}px;
|
|
48
48
|
height: ${5}px;
|
|
49
49
|
}
|
|
50
|
-
`;const
|
|
51
|
-
`),document.body.append(e);let t=e.getBoundingClientRect().height;return e.remove(),
|
|
52
|
-
`)}function
|
|
53
|
-
`&&(r+=1),n.push({text:i,start:t})}return n}function
|
|
54
|
-
`),oe=e.preview?0:qN(ee,_),{width:se,height:ce}=Vh(_),le=1/2;return O`<k-group id=${e.preview?``:`memo-${_.id}`} name="memo" kind="memo" selected=${ne} sharedSelect=${re} x=${_.ui.x} y=${_.ui.y} @mousedown=${a} @touchstart=${a} @mouseenter=${s} @mouseleave=${c}><k-rect name="memo-shared-select" kind="memo-shared-select" x=${-.5} y=${-.5} width=${se+1} height=${ce+1} cornerRadius=${7} stroke=${re??``} strokeWidth=${1} listening=${!1} /><k-rect name="memo-body" kind="memo-body" x=${le} y=${le} width=${se-1} height=${ce-1} cornerRadius=${6} fill=${te.memoBackground} stroke=${ne?te.memoSelect:te.memoBorder} strokeWidth=${1} /><k-group name="memo-container" kind="memo-container" x=${1} y=${1}><k-rect name="memo-header-color" kind="memo-header-color" x=${0} y=${-1} width=${se-2} height=${4} cornerRadius=${[6,6,0,0]} fill=${_.ui.color} @click=${f} @mouseenter=${e=>{FM(e,PM)}} @mouseleave=${e=>{FM(e,``)}} />${cP({icon:`x`,name:`memo-remove`,kind:`icon`,size:12,color:o.hover?o.removeHover?te.active:te.foreground:MM,x:8+_.ui.width-12,y:8,click:d,mouseenter:l,mouseleave:u})}<k-group name="memo-text-clip" kind="memo-textarea" x=${8} y=${24} clipX=${0} clipY=${0} clipWidth=${_.ui.width} clipHeight=${_.ui.height} @click=${p} @mouseenter=${m} @mouseleave=${h} @wheel=${g}><k-rect name="memo-textarea-hit" kind="memo-textarea" x=${0} y=${0} width=${_.ui.width} height=${_.ui.height} fill=${NM} /><k-text name="memo-textarea" kind="memo-textarea" offsetY=${oe} text=${ae} visible=${!ie} fill=${te.active} fontFamily=${wM} fontSize=${12} fontStyle=${`400`} lineHeight=${PN()} wrap="none" /></k-group><${kN} .memo=${_} .top=${ce} .left=${se} /></k-group></k-group>`}};function uP(e,t,n){return Math.abs(e.x-t.x)<.5?{x:e.x,y:e.y+Math.sign(t.y-e.y)*n}:{x:e.x+Math.sign(t.x-e.x)*n,y:e.y}}function dP(e,t){if(e.length<3||t<=0)return e;let n=[e[0]],r=e=>{let t=n[n.length-1];Math.abs(t.x-e.x)<.5&&Math.abs(t.y-e.y)<.5||n.push(e)};for(let n=1;n<e.length-1;n++){let i=e[n-1],a=e[n],o=e[n+1];if(Math.abs(a.x-i.x)<.5==Math.abs(o.x-a.x)<.5){r(a);continue}let s=Math.abs(a.x-i.x)+Math.abs(a.y-i.y),c=Math.abs(o.x-a.x)+Math.abs(o.y-a.y),l=Math.min(t,s/2,c/2);if(l<2){r(a);continue}r(uP(a,i,l)),r(uP(a,o,l))}return r(e[e.length-1]),n}function fP(e){let{start:t,end:n}=e,[r,i]=Ug(e),a=hA(t,n);return{path:pP(t,n,gA(mA(r),a),gA(mA(i),a),Kg(e)),line:mP(t,n)}}function pP(e,t,n,r,i){let a={start:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},end:{x1:t.x,y1:t.y,x2:t.x,y2:t.y}},o={M:{x:0,y:0},L:{x:0,y:0},Q:{x:0,y:0},d(){return e.tableId===t.tableId?[[{x:this.M.x,y:this.M.y},{x:this.L.x,y:this.L.y}]]:_P(dP(i&&i.length>1?i:vP(this.M,this.L,e.direction),8))}},s=1;return e.direction===I.left||e.direction===I.right?(e.direction===I.left&&(s*=-1),a.start.x2=e.x+s*n,a.start.x1+=s*25,o.M.x=a.start.x2,o.M.y=e.y):(e.direction===I.top||e.direction===I.bottom)&&(e.direction===I.top&&(s*=-1),a.start.y2=e.y+s*n,a.start.y1+=s*25,o.M.x=e.x,o.M.y=a.start.y2),s=1,t.direction===I.left||t.direction===I.right?(t.direction===I.left&&(s*=-1),a.end.x2=t.x+s*r,a.end.x1+=s*25,o.L.x=a.end.x2,o.L.y=t.y):(t.direction===I.top||t.direction===I.bottom)&&(t.direction===I.top&&(s*=-1),a.end.y2=t.y+s*r,a.end.y1+=s*25,o.L.x=t.x,o.L.y=a.end.y2),{line:a,path:o}}function mP(e,t){let n={start:{base:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},base2:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},center:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},center2:{x1:e.x,y1:e.y,x2:e.x,y2:e.y}},end:{base:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},base2:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},left:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},center:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},center2:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},right:{x1:t.x,y1:t.y,x2:t.x,y2:t.y}}},r={cx:t.x,cy:t.y},i={cx:e.x,cy:e.y},a=1;return e.direction===I.left||e.direction===I.right?(e.direction===I.left&&(a*=-1),n.start.base.x1=n.start.base.x2+=a*11,n.start.base2.x1=n.start.base2.x2+=a*18,n.start.center.x1=n.start.base.x1,n.start.base.y1-=7,n.start.base.y2+=7,n.start.base2.y1-=7,n.start.base2.y2+=7,n.start.center2.x1+=a*25,i.cx+=a*18):(e.direction===I.top||e.direction===I.bottom)&&(e.direction===I.top&&(a*=-1),n.start.base.y1=n.start.base.y2+=a*11,n.start.base2.y1=n.start.base2.y2+=a*18,n.start.center.y1=n.start.base.y1,n.start.base.x1-=7,n.start.base.x2+=7,n.start.base2.x1-=7,n.start.base2.x2+=7,n.start.center2.y1+=a*25,i.cy+=a*18),a=1,t.direction===I.left||t.direction===I.right?(t.direction===I.left&&(a*=-1),n.end.base.x1=n.end.base.x2+=a*11,n.end.base2.x1=n.end.base2.x2+=a*18,n.end.center.x1=n.end.left.x1=n.end.right.x1=n.end.base.x1,n.end.base.y1-=7,n.end.base.y2+=7,n.end.base2.y1-=7,n.end.base2.y2+=7,n.end.left.y2+=7,n.end.right.y2-=7,n.end.center2.x1+=a*25,r.cx+=a*18):(t.direction===I.top||t.direction===I.bottom)&&(t.direction===I.top&&(a*=-1),n.end.base.y1=n.end.base.y2+=a*11,n.end.base2.y1=n.end.base2.y2+=a*18,n.end.center.y1=n.end.left.y1=n.end.right.y1=n.end.base.y1,n.end.base.x1-=7,n.end.base.x2+=7,n.end.base2.x1-=7,n.end.base2.x2+=7,n.end.left.x2+=7,n.end.right.x2-=7,n.end.center2.y1+=a*25,r.cy+=a*18),{line:n,circle:r,startCircle:i}}function hP(e){if(!e.length)return``;let[[t]]=e,n=`M${gP(t.x)} ${gP(t.y)}`;for(let[,t]of e)n+=`L${gP(t.x)} ${gP(t.y)}`;return n}function gP(e){return Math.round(e*100)/100}function _P(e){let t=[];for(let n=1;n<e.length;n++)t.push([e[n-1],e[n]]);return t}function vP(e,t,n){if(_A(n)){if(Math.abs(e.y-t.y)<.5)return[e,t];let n=(e.x+t.x)/2;return[e,{x:n,y:e.y},{x:n,y:t.y},t]}if(Math.abs(e.x-t.x)<.5)return[e,t];let r=(e.y+t.y)/2;return[e,{x:e.x,y:r},{x:t.x,y:r},t]}const yP=`relationship-decoration`,bP=({x1:e,y1:t,x2:n,y2:r})=>[e,t,n,r];function xP(e,t){return O`<k-line name=${yP} kind=${yP} points=${bP(e)} stroke=${t} strokeWidth=${2} listening=${!1} />`}function SP({cx:e,cy:t},n){return O`<k-circle name=${yP} kind=${yP} x=${e} y=${t} radius=${6} stroke=${n} strokeWidth=${2} listening=${!1} />`}const CP={1:{ring:!0,ticks:[`base`,`left`,`center`,`right`]},[Ym.ZeroOne]:{ring:!0,ticks:[`base`,`center`]},[Ym.ZeroN]:{ring:!0,ticks:[`left`,`center`,`right`]},[Ym.OneOnly]:{ring:!1,ticks:[`base`,`base2`,`center2`]},[Ym.OneN]:{ring:!1,ticks:[`base`,`left`,`center2`,`right`]},32:{ring:!1,ticks:[`base`,`center2`]},64:{ring:!1,ticks:[`left`,`center2`,`right`]}};function wP(e,{path:t,line:n},r){let i=CP[e];return i?O`${xP(t.line.end,r)}${i.ring?SP(n.circle,r):null}${i.ticks.map(e=>xP(n.line.end[e],r))}`:null}const TP=[10,10],EP=[];function DP({direction:e}){let t=e===I.left||e===I.top?-1:1;return e===I.left||e===I.right?{along:{x:t,y:0},across:{x:0,y:1}}:{along:{x:0,y:t},across:{x:1,y:0}}}function OP({x:e,y:t},{along:n,across:r},i,a){return{x:e+n.x*i+r.x*a,y:t+n.y*i+r.y*a}}function kP({x:e,y:t},n){return`M${e-n} ${t}A${n} ${n} 0 0 1 ${e+n} ${t}A${n} ${n} 0 0 1 ${e-n} ${t}`}function AP(e){let t=DP(e),n=(n,r)=>OP(e,t,n,r),r=n(11,0);return[hP([[n(11,-7),n(11,7)]]),hP([[n(18,-7),n(18,7)]]),hP([[r,n(0,7)]]),hP([[r,n(0,-7)]]),kP(n(18,0),6)].join(``)}function jP({start:e,end:t},{line:n},r){return`${hP([[{x:e.x,y:e.y},{x:n.start.x2,y:n.start.y2}],...r,[{x:n.end.x2,y:n.end.y2},{x:t.x,y:t.y}]])}${AP(e)}${AP(t)}`}function MP(e){return 8/(e>0?e:1)}const NP=(e,t)=>{let n=Qj(t),r=uM(t),i=wa({hover:!1}),a=()=>{let{relationship:t}=e,{store:r}=n.value;i.hover=!0,r.dispatch(Bv({columnIds:[...t.start.columnIds,...t.end.columnIds]}))},o=()=>{let{store:e}=n.value;i.hover=!1,e.dispatch(Bv({columnIds:[]}))};return()=>{let{store:t}=n.value,{editor:s,settings:c}=t.state,{relationship:l,strokeWidth:u}=e,d=r.value,f=fP(l),{path:p,line:m}=f,h=p.path.d(),g=!!s.hoverRelationshipMap[l.id],ee=i.hover||g?d.relationshipHover:l.identification?d.keyPFK:d.keyFK,_=wP(l.relationshipType,f,ee);return O`<k-group name=${`relationship ${l.id}`} kind="relationship" @mouseenter=${a} @mouseleave=${o}><k-path name="relationship-hit-area" kind="relationship-hit-area" data=${jP(l,p,h)} hitStrokeWidth=${MP(c.zoomLevel)} lineCap="round" /><k-path name="relationship-route" kind="relationship-route" data=${hP(h)} dash=${l.identification?EP:TP} stroke=${ee} strokeWidth=${u} listening=${!1} />${xP(p.line.start,ee)}${xP(m.line.start.base,ee)}${l.startRelationshipType===Xm.ring?O`${SP(m.startCircle,ee)}${xP(m.line.start.center,ee)}`:O`${xP(m.line.start.base2,ee)}${xP(m.line.start.center2,ee)}`}${_}</k-group>`}},PP=e=>()=>{let{relationships:t,viewport:n}=e,r=e.strokeWidth??2,i=n?t.filter(e=>o_(n,e,r)):t;return O`<k-group name="relationship-group" kind="relationship-group">${su(i,e=>e.id,e=>O`<${NP} .relationship=${e} .strokeWidth=${r} />`)}</k-group>`},FP=e=>e.evt?.detail??0;function IP(){let e=null;return{track(t,n){FP(n)<=1&&(e=t)},isDouble(t,n){return FP(n)>=2&&e===t}}}const LP=(e,t)=>{let n=z(e,R.primaryKey),r=z(e,R.foreignKey);return n&&r?t.keyPFK:n?t.keyPK:r?t.keyFK:MM},RP=(e,t,n)=>t?e.columnSelect:n?e.columnHover:MM,zP=(e,t)=>{let n=Qj(t),r=uM(t),i=wa({hover:!1,removeHover:!1}),{addUnsubscribe:a}=uN(),o=IP(),s=null,c=()=>{s?.unsubscribe(),s=null};a(c);let l=t=>{if(e.preview||e.ghost||t.evt.button!==0)return;c();let n=!1,r=oN.subscribe({next:()=>{n||(n=!0,e.onDragstart?.(e.column.id,t))},complete:()=>{s===r&&(s=null),n&&e.onDragend?.()}});s=r},u=()=>{i.hover=!0},d=()=>{i.hover=!1},f=e=>{i.removeHover=!0,FM(e,PM)},p=e=>{i.removeHover=!1,FM(e,``)},m=(e,t)=>t?i.removeHover?e.active:e.foreground:MM,h=(t,r)=>{let{store:i}=n.value,{column:a}=e;i.dispatch(mv({tableId:a.tableId,columnId:a.id,focusType:t,$mod:Yj(r.evt),shiftKey:r.evt.shiftKey}))},g=(t,r)=>{if(!o.isDouble(t,r))return;let{store:i}=n.value,{column:a}=e;i.dispatch(MS(t)?IS(t,a.tableId,a.id):bv())},ee=()=>{let{store:t}=n.value,{column:r}=e;t.dispatch(FS(r.tableId,[r.id]))},_=()=>{let{column:t}=e;if(t.ui.keys===0)return;let{store:r}=n.value;r.dispatch(Sk(t.id))},te=()=>{let{store:e}=n.value;e.dispatch(Ck())},ne=({focusType:t,x:n,width:i,text:a,fill:s,focus:c,edit:l,sharedFocus:u,ellipsis:d})=>O`<k-group name=${`column-col ${t}`} kind="column-col" sharedFocus=${u} x=${n} y=${0} @mousedown=${e=>{h(t,e),o.track(t,e)}} @dblclick=${e=>{g(t,e)}}><k-text name="cell-text" y=${2} width=${i} height=${QN()} text=${a} fill=${s} fontFamily=${wM} fontSize=${12} verticalAlign="middle" wrap="none" ellipsis=${d} visible=${!l} hitFunc=${iP} />${c?O`<k-rect name="cell-focus-border" y=${20.5} width=${i} height=${AM} fill=${XN(r.value,l,e.editorFocused)} listening=${!1} />`:null}${u?O`<k-rect name="cell-shared-focus-border" y=${22.5} width=${i+8} height=${AM} fill=${u} listening=${!1} />`:null}</k-group>`,re=({columnType:t,focusType:n,x:i,width:a})=>{let{column:o}=e,s=r.value;switch(t){case P.columnName:return ne({focusType:n,x:i,width:a,text:o.name.trim()?o.name:`column`,fill:o.name.trim()?s.active:s.placeholder,focus:e.focusName,edit:e.editName,sharedFocus:e.sharedFocusName,ellipsis:!0});case P.columnDefault:return ne({focusType:n,x:i,width:a,text:o.default.trim()?o.default:`default`,fill:o.default.trim()?s.active:s.placeholder,focus:e.focusDefault,edit:e.editDefault,sharedFocus:e.sharedFocusDefault,ellipsis:!0});case P.columnComment:return ne({focusType:n,x:i,width:a,text:o.comment.trim()?o.comment:`comment`,fill:o.comment.trim()?s.active:s.placeholder,focus:e.focusComment,edit:e.editComment,sharedFocus:e.sharedFocusComment,ellipsis:!0});case P.columnDataType:return ne({focusType:n,x:i,width:a,text:o.dataType.trim()?o.dataType:`dataType`,fill:o.dataType.trim()?s.active:s.placeholder,focus:e.focusDataType,edit:e.editDataType,sharedFocus:e.sharedFocusDataType,ellipsis:!0});case P.columnNotNull:return ne({focusType:n,x:i,width:a,text:z(o.options,L.notNull)?`N-N`:`NULL`,fill:s.active,focus:e.focusNotNull,edit:!1,sharedFocus:e.sharedFocusNotNull,ellipsis:!1});case P.columnUnique:return ne({focusType:n,x:i,width:a,text:`UQ`,fill:z(o.options,L.unique)?s.active:s.placeholder,focus:e.focusUnique,edit:!1,sharedFocus:e.sharedFocusUnique,ellipsis:!1});case P.columnAutoIncrement:return ne({focusType:n,x:i,width:a,text:`AI`,fill:z(o.options,L.autoIncrement)?s.active:s.placeholder,focus:e.focusAutoIncrement,edit:!1,sharedFocus:e.sharedFocusAutoIncrement,ellipsis:!1})}return null},ie=()=>{let{store:t}=n.value;return nP(t.state,{name:e.widthName,comment:e.widthComment,dataType:e.widthDataType,default:e.widthDefault}).map(e=>({columnType:e.columnType,template:re(e)})).filter(({template:e})=>!!e)};return()=>{let{store:t}=n.value,{editor:a}=t.state,{column:o,selected:s,width:c}=e,h=r.value,g=!!(e.hovered||i.hover||a.hoverColumnMap[o.id]),ne=!!a.draggingColumnMap[o.id],re=c-18,ae=RP(h,s,g);return O`<k-group id=${e.preview?``:`column-${o.id}`} name="column-row" kind="column-row" tableId=${o.tableId} selected=${s} y=${e.y} opacity=${ne?.5:1} visible=${!e.ghost} @mousedown=${l} @mouseenter=${u} @mouseleave=${d}><k-rect name="column-row-background" x=${1} width=${c-2} height=${24} fill=${ae} />${cP({icon:`key-round`,name:`column-col column-key`,kind:`column-col`,size:12,color:LP(o.ui.keys,h),x:9,y:6,mouseenter:_,mouseleave:te})}${su(ie(),({columnType:e})=>e,({template:e})=>e)}${cP({icon:`x`,name:`column-remove`,kind:`icon`,size:12,color:m(h,g),x:9+re-12,y:6,click:ee,mouseenter:f,mouseleave:p})}</k-group>`}};function BP(e,t){let{collections:n,doc:r}=e,i=r_(e),a=j(n).collection(`tableEntities`).selectByIds(r.tableIds).filter(t=>a_(i,e,t)).sort((e,t)=>t.ui.zIndex-e.ui.zIndex);for(let n of a){let r=Rh(e,n);if(!(t.x>=r.x&&t.x<=r.x+r.width&&t.y>=r.y&&t.y<=r.y+r.height))continue;let i=Bh(e,n,0).y;if(t.y<i)return null;let a=Math.floor((t.y-i)/24),o=n.columnIds[a];return o?{tableId:n.id,columnId:o,index:a}:null}return null}function VP(e,t){let n=e.getAbsolutePosition(),r=e.getAbsoluteScale();return{x:(n.x-t.x)/(r.x||1),y:(n.y-t.y)/(r.y||1)}}function HP(e){let t=new Map,n=null,r=null,i=(e,n,r,i)=>{t.get(e)?.(),e.offsetX(r),e.offsetY(i),Qd(n);let a=!1,o=-1,s=()=>{a||(a=!0,clearTimeout(o),t.delete(e),$d(n))},c=new si({node:e,offsetX:0,offsetY:0,duration:.3,easing:oi.EaseInOut,onFinish:s,onReset:s});t.set(e,()=>{c.destroy(),e.offsetX(0),e.offsetY(0),s()}),o=setTimeout(()=>t.get(e)?.(),500),c.play()},a=()=>{let e=n;return n=null,r?.(),r=null,e},o=()=>{let e=a();if(e)for(let t of e){let{node:e}=t,n=e.getLayer();if(!n||!e.getStage())continue;let{x:r,y:a}=VP(e,t);!r&&!a||i(e,n,r,a)}};return{snapshot(){n=e().map(e=>{let{x:t,y:n}=e.getAbsolutePosition();return{node:e,x:t,y:n}}),r??=Jd(o)},cancel(){a(),[...t.values()].forEach(e=>e())}}}function UP(e,t){let n=Qj(e),r=()=>n.value.store.state.editor.focusTable;return{hasFocus:(e,n)=>dN(r(),e,t,n),hasEdit:(e,n)=>pN(r(),e,t,n),hasSelectColumn:e=>fN(r(),t,e)}}const WP=(e,t)=>{let n=Qj(t),r=uM(t),{hasEdit:i,hasFocus:a,hasSelectColumn:o}=UP(t,e.table.id),{sharedFocusColor:s,sharedFocusTableColor:c}=vN(t,e.table.id),{sharedSelectColor:l}=yN(t,e.table.id),{onMoveStart:u}=lN(t,e),{addUnsubscribe:d}=uN(),f=wa({hover:!1,iconHover:null,dragstartId:null}),p=IP(),m=null,h=null,g=null,ee=()=>{f.hover=!0},_=()=>{f.hover=!1},te=e=>t=>{f.iconHover=e,FM(t,PM)},ne=e=>{f.iconHover=null,FM(e,``)},re=(e,t,n)=>n?f.iconHover===t?e.active:e.foreground:MM,ie=(t,n)=>n?e.editorFocused===!1?t.placeholder:t.tableSelect:t.tableBorder,ae=t=>{let{emitter:r}=n.value;r.emit(Bj({x:t.evt.clientX,y:t.evt.clientY,color:e.table.ui.color}))},oe=()=>{let{store:t}=n.value;t.dispatch(PS(e.table.id))},se=()=>{let{store:t}=n.value;t.dispatch(OS(e.table.id))},ce=t=>{let{store:r}=n.value;r.dispatch(fv({tableId:e.table.id,focusType:t}))},le=(e,t)=>{if(!p.isDouble(e,t))return;let{store:r}=n.value;r.dispatch(bv())},ue=e=>{let t=h,n=t?.findOne(`.scene`);if(!t||!n)return null;t.setPointersPositions(e);let r=t.getPointerPosition();return r?n.getAbsoluteTransform().copy().invert().point(r):null},de=e=>{let{store:t}=n.value,r=ue(e);if(!r)return;let i=BP(t.state,r);if(!i)return;let{editor:{draggableColumn:a}}=t.state;!a||a.columnIds.includes(i.columnId)||(g?.snapshot(),t.dispatch(xk(i.columnId,i.tableId)))},v=()=>{let{store:e,emitter:t}=n.value;!m&&f.dragstartId===null||(m?.unsubscribe(),m=null,h=null,f.dragstartId=null,e.dispatch(Qv()),t.emit(Vj()))},fe=(e,t)=>{let{store:r}=n.value,{editor:{focusTable:i}}=r.state;if(!i||!i.columnId)return;let a=t.target?.getStage()??null;a&&(m?.unsubscribe(),h=a,f.dragstartId=e,g??=HP(()=>a.find(`.column-row`)),r.dispatch(bk(Yj(t.evt))),m=oN.subscribe({next:({event:e})=>{de(e)},complete:v}))};ra(()=>{let{emitter:e}=n.value;d(e.on({dragendColumnAll:()=>{m?.unsubscribe(),m=null}}),()=>{m?.unsubscribe(),m=null,g?.cancel()})});let y=({focusType:t,x:n,width:i,text:a,fill:o,focus:s,edit:c,sharedFocus:l})=>O`<k-group name=${`input-padding ${t}`} kind="input-padding" sharedFocus=${l} x=${n} y=${0} @mousedown=${e=>{ce(t),p.track(t,e)}} @dblclick=${e=>{le(t,e)}}><k-text name="cell-text" y=${2} width=${i} height=${QN()} text=${a} fill=${o} fontFamily=${wM} fontSize=${12} verticalAlign="middle" wrap="none" ellipsis=${!0} visible=${!c} hitFunc=${aP} />${s?O`<k-rect name="cell-focus-border" y=${20.5} width=${i} height=${AM} fill=${XN(r.value,c,e.editorFocused)} listening=${!1} />`:null}${l?O`<k-rect name="cell-shared-focus-border" y=${22.5} width=${i+8} height=${AM} fill=${l} listening=${!1} />`:null}</k-group>`;return()=>{let{store:t}=n.value,{editor:d,collections:p}=t.state,{table:m}=e,h=r.value,g=!!d.selectedMap[m.id],ce=zh(t.state,m),le=Rh(t.state,m),ue=le.width-18,de=!!(e.hovered||f.hover),pe=e.ghostColumnId??f.dragstartId,b=pe!==null&&!m.columnIds.includes(pe)?pe:null,me=c(),he=l(),ge=s(W.tableName),_e=s(W.tableComment),ve=me??he,ye=eP(t.state,m),be=ye.find(e=>e.focusType===W.tableName),xe=ye.find(e=>e.focusType===W.tableComment),Se=j(p).collection(`tableColumnEntities`).selectByIds(b?[...m.columnIds,b]:m.columnIds);return O`<k-group id=${e.preview?``:`table-${m.id}`} name="table" kind="table" visible=${e.visible??!0} selected=${g} sharedFocus=${me} sharedSelect=${he} x=${le.x} y=${le.y} @mousedown=${u} @touchstart=${u} @mouseenter=${ee} @mouseleave=${_}><k-rect name="table-body" x=${1/2} y=${1/2} width=${le.width-1} height=${le.height-1} cornerRadius=${6} fill=${h.tableBackground} stroke=${ie(h,g)} strokeWidth=${1} />${ve?O`<k-rect name="table-ring" x=${-1/2} y=${-1/2} width=${le.width+1} height=${le.height+1} cornerRadius=${6} stroke=${ve} strokeWidth=${1} listening=${!1} />`:null}<k-rect name="table-header-color" kind="table-header-color" x=${1} y=${0} width=${le.width-2} height=${4} cornerRadius=${[6,6,0,0]} fill=${m.ui.color} @click=${ae} @mouseenter=${e=>{FM(e,PM)}} @mouseleave=${e=>{FM(e,``)}} /><k-group name="table-header" x=${9} y=${9}>${cP({icon:`plus`,name:`table-add-column`,kind:`icon`,size:12,color:re(h,`plus`,de),mouseenter:te(`plus`),mouseleave:ne,x:ue-24-4,y:0,click:oe})}${cP({icon:`x`,name:`table-remove`,kind:`icon`,size:12,color:re(h,`x`,de),mouseenter:te(`x`),mouseleave:ne,x:ue-12,y:0,click:se})}<k-group name="table-header-inputs" y=${14}>${be?y({...be,text:m.name.trim()?m.name:`table`,fill:m.name.trim()?h.active:h.placeholder,focus:a(W.tableName),edit:i(W.tableName),sharedFocus:ge}):null}${xe?y({...xe,text:m.comment.trim()?m.comment:`comment`,fill:m.comment.trim()?h.active:h.placeholder,focus:a(W.tableComment),edit:i(W.tableComment),sharedFocus:_e}):null}</k-group></k-group><k-group name="table-columns">${su(Se,e=>e.id,(n,r)=>O`<${zP} .column=${n} .y=${Bh(t.state,m,r).y-le.y} .width=${le.width} .selected=${o(n.id)} .hovered=${n.id===e.hoveredColumnId} .widthName=${ce.name} .widthDataType=${ce.dataType} .widthDefault=${ce.default} .widthComment=${ce.comment} .focusName=${a(W.columnName,n.id)} .focusDataType=${a(W.columnDataType,n.id)} .focusNotNull=${a(W.columnNotNull,n.id)} .focusDefault=${a(W.columnDefault,n.id)} .focusComment=${a(W.columnComment,n.id)} .focusUnique=${a(W.columnUnique,n.id)} .focusAutoIncrement=${a(W.columnAutoIncrement,n.id)} .editName=${i(W.columnName,n.id)} .editDataType=${i(W.columnDataType,n.id)} .editDefault=${i(W.columnDefault,n.id)} .editComment=${i(W.columnComment,n.id)} .sharedFocusName=${s(W.columnName,n.id)} .sharedFocusDataType=${s(W.columnDataType,n.id)} .sharedFocusNotNull=${s(W.columnNotNull,n.id)} .sharedFocusDefault=${s(W.columnDefault,n.id)} .sharedFocusComment=${s(W.columnComment,n.id)} .sharedFocusUnique=${s(W.columnUnique,n.id)} .sharedFocusAutoIncrement=${s(W.columnAutoIncrement,n.id)} .ghost=${n.id===b} .preview=${e.preview} .editorFocused=${e.editorFocused} .onDragstart=${fe} .onDragend=${v} />`)}</k-group></k-group>`}},GP=(e,t)=>e.ui.zIndex-t.ui.zIndex,KP=(e,t)=>{let n=Qj(t),r=uM(t);return()=>{let{store:t}=n.value,{box:i,scale:a}=e,{settings:{show:o,zoomLevel:s},doc:{tableIds:c,memoIds:l,relationshipIds:u},collections:d}=t.state,f=r.value,p=j(d).collection(`tableEntities`).selectByIds(c).sort(GP),m=j(d).collection(`memoEntities`).selectByIds(l).sort(GP),h=j(d).collection(`relationshipEntities`).selectByIds(u),g=wh(s);return O`<k-layer name="export-scene" listening=${!1} x=${-i.x*a} y=${-i.y*a} scaleX=${a} scaleY=${a}><k-rect name="export-background" x=${i.x} y=${i.y} width=${i.width} height=${i.height} fill=${f.canvasBackground} />${z(o,N.relationship)?O`<${PP} .relationships=${h} />`:null}${su(p,e=>e.id,e=>g?O`<${xN} .table=${e} />`:O`<${WP} .table=${e} />`)}${su(m,e=>e.id,e=>O`<${lP} .memo=${e} />`)}</k-layer>`}};async function qP({doc:e,theme:t,toWidth:n,zoomLevel:r}){let i=Xj({toWidth:n},{devtools:!1});i.store.dispatchSync(tk(e)),y(r)&&i.store.dispatchSync(rg({value:r})),await fM(32);let a=i.store.state.settings.zoomLevel,o=gM(i.store.state),s=_M(o,a),c=dM({app:i,container:document.createElement(`div`),scene:O`<${KP} .box=${o} .scale=${s} />`,width:o.width*s,height:o.height*s,theme:t});return await tf(),{stage:c.stage,box:o,scale:s,zoomLevel:a,destroy:()=>{c.destroy(),$j(i)}}}function JP(e){return`convertToBlob`in e?e.convertToBlob({type:`image/png`}):new Promise((t,n)=>{e.toBlob(e=>{e?t(e):n(Error(`[export-png] the canvas encoded no png`))},`image/png`)})}async function YP({doc:e,theme:t,pixelRatio:n,zoomLevel:r,toWidth:i}){let a=await qP({doc:e,theme:t,toWidth:i,zoomLevel:r});try{let e=mM(n,a.stage.width(),a.stage.height()),t=a.stage.toCanvas({pixelRatio:e}),r=await JP(t),{width:i,height:o}=t;return{blob:r,width:i,height:o,reduction:a.scale*e<n*a.zoomLevel?{documentWidth:a.box.width,documentHeight:a.box.height,width:i,height:o}:null}}finally{a.destroy()}}const XP=`400 12px ${CM}`,ZP=[`ERD editor 0123456789`,`가나다 漢字 テスト`,`—…€· iIlL1`];function QP(){if(typeof OffscreenCanvas>`u`)return null;let e=new OffscreenCanvas(1,1).getContext(`2d`);return e?(e.font=XP,t=>Math.round(e.measureText(t).width)+2):null}function $P(e){return ZP.map(t=>e(t))}function eF(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}const tF=new class{async probeFontWidths(){return $P(this.createToWidth())}async render(e){let t=this.createToWidth(),n=$P(t);if(!eF(n,e.fontProbe))throw Error(`[export-png] this realm measures text differently: ${n.join()} against ${e.fontProbe.join()}`);return YP({...e,toWidth:t})}createToWidth(){let e=QP();if(!e)throw Error(`[export-png] this realm has no 2d context to measure by`);return e}};self.onconnect=t=>{let n=t.ports[0];e.expose(tF,n)};
|
|
50
|
+
`;const tI={left:`left`,right:`right`,bottom:`bottom`,lt:`lt`,rt:`rt`,lb:`lb`,rb:`rb`},nI={vertical:`vertical`,horizontal:`horizontal`,edge:`edge`},rI={left:`ew-resize`,right:`ew-resize`,bottom:`ns-resize`,lt:`nwse-resize`,rt:`nesw-resize`,lb:`nesw-resize`,rb:`nwse-resize`},iI=(e,t)=>[{shape:nI.vertical,position:tI.left},{shape:nI.vertical,position:tI.right,left:t},{shape:nI.horizontal,position:tI.bottom,top:e},{shape:nI.edge,position:tI.lt},{shape:nI.edge,position:tI.rt,left:t},{shape:nI.edge,position:tI.lb,top:e},{shape:nI.edge,position:tI.rb,top:e,left:t}],aI=({shape:e,top:t=0})=>t===0&&e===nI.vertical?t:t-5/2,oI=({shape:e,left:t=0})=>t===0&&e===nI.horizontal?t:t-5/2,sI=e=>WP(e.evt)?{x:e.evt.clientX,y:e.evt.clientY}:{x:e.evt.touches[0]?.clientX??0,y:e.evt.touches[0]?.clientY??0},cI=(e,t)=>{let n=vP(t),r=0,i=0,a=({movementX:t,x:i},a)=>{let{zoomLevel:o}=n.value.store.state.settings,s=Object.assign({change:!1},e.memo.ui),c=t/o,l=a===V.left?s.width-c:s.width+c;return 116<l&&(t<0?i<r:i>r)&&(a===V.left&&(s.x+=c),r+=t,s.width=l,s.change=!0),s},o=({movementY:t,y:r},a)=>{let{zoomLevel:o}=n.value.store.state.settings,s=Object.assign({change:!1},e.memo.ui),c=t/o,l=a===V.top?s.height-c:s.height+c;return 100<l&&(t<0?r<i:r>i)&&(a===V.top&&(s.y+=c),i+=t,s.height=l,s.change=!0),s},s=(t,r)=>{t.event.type===`mousemove`&&t.event.preventDefault();let{store:i}=n.value,s=null,c=null;switch(r){case tI.left:case tI.right:s=a(t,r);break;case tI.bottom:c=o(t,V.bottom);break;case tI.lt:s=a(t,V.left),c=o(t,V.top);break;case tI.rt:s=a(t,V.right),c=o(t,V.top);break;case tI.lb:s=a(t,V.left),c=o(t,V.bottom);break;case tI.rb:s=a(t,V.right),c=o(t,V.bottom)}if(!s?.change&&!c?.change)return;let{id:l,ui:u}=e.memo,d=s?.change?s:u,f=c?.change?c:u;i.dispatch(Zx({id:l,x:d.x,y:f.y,width:d.width,height:f.height}))},c=(e,t)=>{if(GP(e.evt))return;let n=sI(e);r=n.x,i=n.y;let a=lF(e,rI[t]);PF.subscribe(e=>s(e,t)).add(a)};return()=>{let t=e.left-2,n=e.top-2;return k`${iI(e.top,e.left).map(e=>k`<k-rect name=${`memo-sash memo-sash-${e.position}`} kind="sash" x=${oI(e)} y=${aI(e)} width=${e.shape===nI.horizontal?t:5} height=${e.shape===nI.vertical?n:5} fill=${nF} @mousedown=${t=>{c(t,e.position)}} @touchstart=${t=>{c(t,e.position)}} @mouseenter=${t=>{cF(t,rI[e.position])}} @mouseleave=${e=>{cF(e,``)}} />`)}`}},lI=`400 12px ${KP}`,uI=12*1.2;let dI=null;function fI(){if(dI!==null)return dI;if(typeof document>`u`||!document.body)return uI;let e=document.createElement(`div`);e.setAttribute(`aria-hidden`,`true`),e.style.cssText=`position:absolute;visibility:hidden;top:-10000px;left:0;margin:0;padding:0;border:0;font:${lI};line-height:normal;white-space:pre`,e.textContent=Array.from({length:10},()=>`M`).join(`
|
|
51
|
+
`),document.body.append(e);let t=e.getBoundingClientRect().height;return e.remove(),dI=t/10||uI,dI}function pI(){return fI()/12}const mI={whiteSpace:`pre-wrap`,wordBreak:`normal`},hI=new Map;function gI(e,t){let n=`${t} ${e}`,r=hI.get(n);if(r)return r;let i=fi(e,lI,mI),{lines:a}=di(i,t,fI()),o=a.map(e=>e.text);return hI.size>=256&&hI.clear(),hI.set(n,o),o}function _I(){let e=typeof document>`u`?null:document.createElement(`canvas`).getContext(`2d`);return e?(e.font=lI,t=>e.measureText(t).width):()=>0}let vI=null;function yI(e){return vI??=_I(),vI(e)}function bI(e){return e.replace(/\r\n?/g,`
|
|
52
|
+
`)}function xI(e,t){let n=[],r=0;for(let i of gI(e,t)){let t=r;r+=i.length,e[r]===`
|
|
53
|
+
`&&(r+=1),n.push({text:i,start:t})}return n}function SI(e,t){let n=0,r=Math.abs(t),i=``;for(let a of Array.from(e.text)){i+=a;let e=Math.abs(t-yI(i));if(e>r)break;n=i.length,r=e}return n}function CI(e,t,n,r){let i=bI(e),a=xI(i,t);if(!a.length)return 0;let o=Math.max(0,Math.floor(r/fI()));if(o>=a.length)return i.length;let s=a[o];return s.start+SI(s,n)}function wI(e){let t=gI(e.value,e.ui.width).length;return Math.max(0,t*fI()-e.ui.height)}function TI(e,t){return Math.min(Math.max(0,t),wI(e))}function EI(e,t){return TI(t,e.memoScrollTopMap[t.id]??0)}const DI=[`memo-header-color`,`memo-textarea`,`icon`,`sash`];function OI(e,t,n){return FF(e,{entityId:()=>t.memo.id,selectType:ig.memo,blockedKinds:()=>DI,source:n})}function kI(e=`document`){return e===`document`?3:9}function AI(e=`document`){return e===`document`?2:0}function jI(e=`document`){return e===`document`?LI():16}function MI(e=`document`){return e===`document`?2:8}function NI(e=`document`,t){return e===`document`?LI(t):16}function PI(){return x_(`document`)-MI(`document`)*2-QP}function FI(e,t,n){return t?e.inputActive:n===!1?e.placeholder:e.focus}function II(e){let{ascent:t,descent:n}=XP(e);return Math.round(18.5/2+(t-n)/2)}function LI(e){let{ascent:t,descent:n}=XP(e);return(II(e)-(t-n)/2)*2}function RI(e=`document`){return e===`document`?29:31}function zI(e,t){let{maxWidthComment:n}=e.settings;return n===-1||n>=t.ui.widthComment?t.ui.widthComment:n}function BI(e,t,n=`document`){let r=n!==`document`,i=[{focusType:U.tableName,x:20,width:r?v_(t.ui.widthName):t.ui.widthName}];return!r&&W(e.settings.show,P.tableComment)&&i.push({focusType:U.tableComment,x:20+t.ui.widthName+8,width:zI(e,t)}),i}const VI=[{columnType:F.columnName,focusType:U.columnName,show:null,width:e=>e.name},{columnType:F.columnDefault,focusType:U.columnDefault,show:P.columnDefault,width:e=>e.default},{columnType:F.columnComment,focusType:U.columnComment,show:P.columnComment,width:e=>e.comment},{columnType:F.columnDataType,focusType:U.columnDataType,show:P.columnDataType,width:e=>e.dataType},{columnType:F.columnNotNull,focusType:U.columnNotNull,show:P.columnNotNull,width:()=>35},{columnType:F.columnUnique,focusType:U.columnUnique,show:P.columnUnique,width:()=>22},{columnType:F.columnAutoIncrement,focusType:U.columnAutoIncrement,show:P.columnAutoIncrement,width:()=>15}],HI=[F.columnName,F.columnDataType];function UI(e,t,n=`document`){let{settings:r}=e,i=[],a=RI(n),o=n===`document`?r.columnOrder:HI;for(let e of o){let o=VI.find(t=>t.columnType===e);if(!o||n===`document`&&o.show!==null&&!W(r.show,o.show))continue;let s=o.width(t);i.push({columnType:e,focusType:o.focusType,x:a,width:s}),a+=s+8}return i}function WI(e,t,n,r,i,a){e.beginPath(),e.rect(n,r,i,a),e.closePath(),e.fillShape(t)}function GI(e){return(t,n)=>{WI(t,n,0,-MI(e),n.width()+8,x_(e))}}const KI={document:GI(`document`),flow:GI(`flow`)};function qI(e){let t=0-AI(e);return(e,n)=>{WI(e,n,0,t,n.width()+8,24)}}const JI={document:qI(`document`),flow:qI(`flow`)},YI=(e,t)=>{WI(e,t,-t.x(),-t.y(),eF,eF)},XI=([e,t],n,r)=>e===`circle`?k`<k-circle x=${Number(t.cx)} y=${Number(t.cy)} radius=${Number(t.r)} fill=${n} stroke=${n} strokeWidth=${2} listening=${r} hitFunc=${r?YI:void 0} />`:k`<k-path data=${String(t.d)} stroke=${n} strokeWidth=${2} lineCap="round" lineJoin="round" listening=${r} hitFunc=${r?YI:void 0} />`;function ZI({icon:e,name:t,kind:n,size:r,color:i,x:a,y:o,click:s,mouseenter:c,mouseleave:l}){let u=HP(e);if(!u)return null;let d=r/eF;return k`<k-group name=${t} kind=${n} x=${a} y=${o} scaleX=${d} scaleY=${d} @click=${s} @mouseenter=${c} @mouseleave=${l}>${u.node.map((e,t)=>XI(e,i,t===0))}</k-group>`}function QI(e){return e.ctrlKey?!hP(e)||Math.abs(e.deltaY)<25:!1}const $I=(e,t)=>{let n=vP(t),r=AP(t),i=QF(t),{sharedSelectColor:a}=XF(t,e.memo.id),{onMoveStart:o}=OI(t,e,i),s=Ma({hover:!1,removeHover:!1}),c=()=>{s.hover=!0},l=()=>{s.hover=!1},u=e=>{s.removeHover=!0,cF(e,aF)},d=e=>{s.removeHover=!1,cF(e,``)},f=()=>{let{store:t}=n.value;t.dispatch(ew(e.memo.id))},p=t=>{let{emitter:r}=n.value;r.emit(aP({x:t.evt.clientX,y:t.evt.clientY,color:e.memo.ui.color}))},m=t=>{if(e.preview)return;let{store:r}=n.value,{memo:i}=e,a=t.currentTarget.getRelativePointerPosition();if(a){let e=EI(r.state.editor,i);i.id,CI(i.value,i.ui.width,a.x,a.y+e)}r.dispatch(ab({id:i.id}))},h=t=>{cF(t,e.preview?``:`text`)},g=e=>{cF(e,``)},_=t=>{if(QI(t.evt)||(t.evt.stopPropagation(),t.evt.preventDefault(),e.preview||hP(t.evt)))return;let{store:r}=n.value,{memo:i}=e,a=EI(r.state.editor,i),o=TI(i,a+t.evt.deltaY);o!==a&&r.dispatch(lb({id:i.id,scrollTop:o}))};return()=>{let{store:t}=n.value,{editor:i}=t.state,{memo:v}=e,y=r.value,ee=!!i.selectedMap[v.id],te=iF(y.memoShadow),ne=a(),re=!e.preview&&i.editMemoId===v.id,ie=gI(v.value,v.ui.width).join(`
|
|
54
|
+
`),ae=e.preview?0:EI(i,v),{width:b,height:oe}=N_(v),se=1/2;return k`<k-group id=${e.preview?``:`memo-${v.id}`} name="memo" kind="memo" selected=${ee} sharedSelect=${ne} x=${v.ui.x} y=${v.ui.y} @mousedown=${o} @touchstart=${o} @mouseenter=${c} @mouseleave=${l}><k-rect name="memo-shared-select" kind="memo-shared-select" x=${-.5} y=${-.5} width=${b+1} height=${oe+1} cornerRadius=${7} stroke=${ne??``} strokeWidth=${1} listening=${!1} /><k-rect name="memo-body" kind="memo-body" x=${se} y=${se} width=${b-1} height=${oe-1} cornerRadius=${6} fill=${y.memoBackground} stroke=${ee?y.memoSelect:y.memoBorder} strokeWidth=${1} shadowColor=${te?.color} shadowBlur=${te?.blur} shadowOffsetX=${te?.offsetX} shadowOffsetY=${te?.offsetY} shadowOpacity=${te?.opacity} shadowForStrokeEnabled=${!te&&void 0} /><k-group name="memo-container" kind="memo-container" x=${1} y=${1}><k-rect name="memo-header-color" kind="memo-header-color" x=${0} y=${-1} width=${b-2} height=${4} cornerRadius=${[6,6,0,0]} fill=${v.ui.color} @click=${p} @mouseenter=${e=>{cF(e,aF)}} @mouseleave=${e=>{cF(e,``)}} />${ZI({icon:`x`,name:`memo-remove`,kind:`icon`,size:12,color:s.hover?s.removeHover?y.active:y.foreground:tF,x:8+v.ui.width-12,y:8,click:f,mouseenter:u,mouseleave:d})}<k-group name="memo-text-clip" kind="memo-textarea" x=${8} y=${24} clipX=${0} clipY=${0} clipWidth=${v.ui.width} clipHeight=${v.ui.height} @click=${m} @mouseenter=${h} @mouseleave=${g} @wheel=${_}><k-rect name="memo-textarea-hit" kind="memo-textarea" x=${0} y=${0} width=${v.ui.width} height=${v.ui.height} fill=${nF} /><k-text name="memo-textarea" kind="memo-textarea" offsetY=${ae} text=${ie} visible=${!re} fill=${y.active} fontFamily=${KP} fontSize=${12} fontStyle=${`400`} lineHeight=${pI()} wrap="none" /></k-group><${cI} .memo=${v} .top=${oe} .left=${b} /></k-group></k-group>`}},eL={now:()=>performance.now(),requestFrame:e=>requestAnimationFrame(e),cancelFrame:e=>cancelAnimationFrame(e)},tL=new Map,nL=new Map,rL=Ma({});let iL=eL,aL=null;function oL(e){let t=1-e;return 1-t*t*t}function sL(){aL===null&&nL.size!==0&&(aL=iL.requestFrame(cL))}function cL(){aL=null;let e=iL.now();for(let[t,n]of[...nL]){let r=e-n.startedAt,{from:i,to:a}=n;if(r>=300){nL.delete(t),rL[t]=a;continue}let o=r>0?r/300:0;rL[t]=i+(a-i)*oL(o)}sL()}function lL(e,t,n){return`${e} ${t}:${n}`}function uL(e){let t=rL[e];if(t!==void 0)return t;let n=nL.get(e);return n?n.from:tL.get(e)??0}function dL(e,t){let n=tL.get(e);if(n===t)return;if(n===void 0){tL.set(e,t);return}let r=uL(e);tL.set(e,t),nL.set(e,{from:r,to:t,startedAt:iL.now()}),sL()}const fL=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i;function pL(e){let t=fL.exec(e.trim());if(!t)return null;let n=t[1],r=n.length===6?n:[...n].map(e=>`${e}${e}`).join(``);return[0,2,4].map(e=>parseInt(r.slice(e,e+2),16))}function mL(e,t,n){if(!(n>0))return e;if(n>=1)return t;let r=pL(e),i=pL(t);return!r||!i?n<.5?e:t:`#${r.map((e,t)=>Math.round(e+(i[t]-e)*n)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function hL(e,t,n){return Math.abs(e.x-t.x)<.5?{x:e.x,y:e.y+Math.sign(t.y-e.y)*n}:{x:e.x+Math.sign(t.x-e.x)*n,y:e.y}}function gL(e,t){if(e.length<3||t<=0)return e;let n=[e[0]],r=e=>{let t=n[n.length-1];Math.abs(t.x-e.x)<.5&&Math.abs(t.y-e.y)<.5||n.push(e)};for(let n=1;n<e.length-1;n++){let i=e[n-1],a=e[n],o=e[n+1];if(Math.abs(a.x-i.x)<.5==Math.abs(o.x-a.x)<.5){r(a);continue}let s=Math.abs(a.x-i.x)+Math.abs(a.y-i.y),c=Math.abs(o.x-a.x)+Math.abs(o.y-a.y),l=Math.min(t,s/2,c/2);if(l<2){r(a);continue}r(hL(a,i,l)),r(hL(a,o,l))}return r(e[e.length-1]),n}function _L(e,t=`document`){let{start:n,end:r}=Fh(e,t),[i,a]=jh(e,t),o=mM(n,r);return{path:vL(n,r,hM(pM(i),o),hM(pM(a),o),Nh(e,t),t),line:yL(n,r)}}function vL(e,t,n,r,i,a){let o={start:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},end:{x1:t.x,y1:t.y,x2:t.x,y2:t.y}},s={M:{x:0,y:0},L:{x:0,y:0},Q:{x:0,y:0},d(){return e.tableId===t.tableId?[[{x:this.M.x,y:this.M.y},{x:this.L.x,y:this.L.y}]]:SL(a===`document`?gL(i&&i.length>1?i:wL(this.M,this.L,e.direction),8):hh(this.M,CL(e.direction),this.L,CL(t.direction)))}},c=1;return e.direction===L.left||e.direction===L.right?(e.direction===L.left&&(c*=-1),o.start.x2=e.x+c*n,o.start.x1+=c*25,s.M.x=o.start.x2,s.M.y=e.y):(e.direction===L.top||e.direction===L.bottom)&&(e.direction===L.top&&(c*=-1),o.start.y2=e.y+c*n,o.start.y1+=c*25,s.M.x=e.x,s.M.y=o.start.y2),c=1,t.direction===L.left||t.direction===L.right?(t.direction===L.left&&(c*=-1),o.end.x2=t.x+c*r,o.end.x1+=c*25,s.L.x=o.end.x2,s.L.y=t.y):(t.direction===L.top||t.direction===L.bottom)&&(t.direction===L.top&&(c*=-1),o.end.y2=t.y+c*r,o.end.y1+=c*25,s.L.x=t.x,s.L.y=o.end.y2),{line:o,path:s}}function yL(e,t){let n={start:{base:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},base2:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},center:{x1:e.x,y1:e.y,x2:e.x,y2:e.y},center2:{x1:e.x,y1:e.y,x2:e.x,y2:e.y}},end:{base:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},base2:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},left:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},center:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},center2:{x1:t.x,y1:t.y,x2:t.x,y2:t.y},right:{x1:t.x,y1:t.y,x2:t.x,y2:t.y}}},r={cx:t.x,cy:t.y},i={cx:e.x,cy:e.y},a=1;return e.direction===L.left||e.direction===L.right?(e.direction===L.left&&(a*=-1),n.start.base.x1=n.start.base.x2+=a*11,n.start.base2.x1=n.start.base2.x2+=a*18,n.start.center.x1=n.start.base.x1,n.start.base.y1-=7,n.start.base.y2+=7,n.start.base2.y1-=7,n.start.base2.y2+=7,n.start.center2.x1+=a*25,i.cx+=a*18):(e.direction===L.top||e.direction===L.bottom)&&(e.direction===L.top&&(a*=-1),n.start.base.y1=n.start.base.y2+=a*11,n.start.base2.y1=n.start.base2.y2+=a*18,n.start.center.y1=n.start.base.y1,n.start.base.x1-=7,n.start.base.x2+=7,n.start.base2.x1-=7,n.start.base2.x2+=7,n.start.center2.y1+=a*25,i.cy+=a*18),a=1,t.direction===L.left||t.direction===L.right?(t.direction===L.left&&(a*=-1),n.end.base.x1=n.end.base.x2+=a*11,n.end.base2.x1=n.end.base2.x2+=a*18,n.end.center.x1=n.end.left.x1=n.end.right.x1=n.end.base.x1,n.end.base.y1-=7,n.end.base.y2+=7,n.end.base2.y1-=7,n.end.base2.y2+=7,n.end.left.y2+=7,n.end.right.y2-=7,n.end.center2.x1+=a*25,r.cx+=a*18):(t.direction===L.top||t.direction===L.bottom)&&(t.direction===L.top&&(a*=-1),n.end.base.y1=n.end.base.y2+=a*11,n.end.base2.y1=n.end.base2.y2+=a*18,n.end.center.y1=n.end.left.y1=n.end.right.y1=n.end.base.y1,n.end.base.x1-=7,n.end.base.x2+=7,n.end.base2.x1-=7,n.end.base2.x2+=7,n.end.left.x2+=7,n.end.right.x2-=7,n.end.center2.y1+=a*25,r.cy+=a*18),{line:n,circle:r,startCircle:i}}function bL(e){if(!e.length)return``;let[[t]]=e,n=`M${xL(t.x)} ${xL(t.y)}`;for(let[,t]of e)n+=`L${xL(t.x)} ${xL(t.y)}`;return n}function xL(e){return Math.round(e*100)/100}function SL(e){let t=[];for(let n=1;n<e.length;n++)t.push([e[n-1],e[n]]);return t}function CL(e){let t=_M(e);return gM(e)?{x:t,y:0}:{x:0,y:t}}function wL(e,t,n){if(gM(n)){if(Math.abs(e.y-t.y)<.5)return[e,t];let n=(e.x+t.x)/2;return[e,{x:n,y:e.y},{x:n,y:t.y},t]}if(Math.abs(e.x-t.x)<.5)return[e,t];let r=(e.y+t.y)/2;return[e,{x:e.x,y:r},{x:t.x,y:r},t]}const TL=`relationship-decoration`,EL=({x1:e,y1:t,x2:n,y2:r})=>[e,t,n,r];function DL(e,t,n){return k`<k-line name=${TL} kind=${TL} points=${EL(e)} stroke=${t} strokeWidth=${n} listening=${!1} />`}function OL({cx:e,cy:t},n,r){return k`<k-circle name=${TL} kind=${TL} x=${e} y=${t} radius=${6} stroke=${n} strokeWidth=${r} listening=${!1} />`}const kL={1:{ring:!0,ticks:[`base`,`left`,`center`,`right`]},[rh.ZeroOne]:{ring:!0,ticks:[`base`,`center`]},[rh.ZeroN]:{ring:!0,ticks:[`left`,`center`,`right`]},[rh.OneOnly]:{ring:!1,ticks:[`base`,`base2`,`center2`]},[rh.OneN]:{ring:!1,ticks:[`base`,`left`,`center2`,`right`]},32:{ring:!1,ticks:[`base`,`center2`]},64:{ring:!1,ticks:[`left`,`center2`,`right`]}};function AL(e,{path:t,line:n},r,i){let a=kL[e];return a?k`${DL(t.line.end,r,i)}${a.ring?OL(n.circle,r,i):null}${a.ticks.map(e=>DL(n.line.end[e],r,i))}`:null}const jL=[10,10],ML=[];function NL({direction:e}){let t=e===L.left||e===L.top?-1:1;return e===L.left||e===L.right?{along:{x:t,y:0},across:{x:0,y:1}}:{along:{x:0,y:t},across:{x:1,y:0}}}function PL({x:e,y:t},{along:n,across:r},i,a){return{x:e+n.x*i+r.x*a,y:t+n.y*i+r.y*a}}function FL({x:e,y:t},n){return`M${e-n} ${t}A${n} ${n} 0 0 1 ${e+n} ${t}A${n} ${n} 0 0 1 ${e-n} ${t}`}function IL(e){let t=NL(e),n=(n,r)=>PL(e,t,n,r),r=n(11,0);return[bL([[n(11,-7),n(11,7)]]),bL([[n(18,-7),n(18,7)]]),bL([[r,n(0,7)]]),bL([[r,n(0,-7)]]),FL(n(18,0),6)].join(``)}function LL({start:e,end:t},{line:n},r){return`${bL([[{x:e.x,y:e.y},{x:n.start.x2,y:n.start.y2}],...r,[{x:n.end.x2,y:n.end.y2},{x:t.x,y:t.y}]])}${IL(e)}${IL(t)}`}function RL(e){return 8/(e>0?e:1)}const zL=(e,t)=>{let n=vP(t),r=AP(t),i=QF(t),a=Ma({hover:!1}),o=()=>{let{relationship:t}=e,{store:r}=n.value;a.hover=!0,r.dispatch(xb({columnIds:[...t.start.columnIds,...t.end.columnIds]}))},s=()=>{let{store:e}=n.value;a.hover=!1,e.dispatch(xb({columnIds:[]}))};return()=>{let{store:t}=n.value,{editor:c}=t.state,{relationship:l,strokeWidth:u}=e,d=r.value,f=i.value,{zoomLevel:p}=B_(t.state,f),m=Fh(l,f),h=_L(l,f),{path:g,line:_}=h,v=g.path.d(),y=!!c.hoverRelationshipMap[l.id],ee=a.hover||y,te=f!==`document`,ne=te?d.visualizationRelationship:l.identification?d.keyPFK:d.keyFK,re=ee?d.relationshipHover:ne,ie=lL(c.id,`relationship`,l.id),ae=0;te&&(dL(ie,+!!e.lit),ae=uL(ie));let b=mL(re,d.accentColor9,ae),oe=AL(l.relationshipType,h,b,u);return k`<k-group name=${`relationship ${l.id}`} kind="relationship" @mouseenter=${o} @mouseleave=${s}><k-path name="relationship-hit-area" kind="relationship-hit-area" data=${LL(m,g,v)} hitStrokeWidth=${RL(p)} lineCap="round" /><k-path name="relationship-route" kind="relationship-route" data=${bL(v)} dash=${te||l.identification?ML:jL} stroke=${b} strokeWidth=${u} listening=${!1} />${DL(g.line.start,b,u)}${DL(_.line.start.base,b,u)}${l.startRelationshipType===ih.ring?k`${OL(_.startCircle,b,u)}${DL(_.line.start.center,b,u)}`:k`${DL(_.line.start.base2,b,u)}${DL(_.line.start.center2,b,u)}`}${oe}</k-group>`}},BL=(e,t)=>{let n=QF(t);return()=>{let{relationships:t,viewport:r,litIds:i}=e,a=n.value,o=e.strokeWidth??zh(a),s=r?t.filter(e=>Z_(r,e,o,a)):t;return k`<k-group name="relationship-group" kind="relationship-group">${hu(s,e=>e.id,e=>k`<${zL} .relationship=${e} .strokeWidth=${o} .lit=${i?.has(e.id)??!1} />`)}</k-group>`}},VL=Ma({pointers:{}});function HL(e,t,n,{columnId:r,columnIds:i}){let a=M_(e,t,t.columnIds.indexOf(r)),o=Math.max(i.indexOf(r),0);VL.pointers[$_(e,`document`)]={...n,grabX:n.x-A_(e,t).x,grabY:n.y-a.y+o*24,over:!0}}function UL(e,{x:t,y:n},r){let i=VL.pointers[$_(e,`document`)];i&&(i.x=t,i.y=n,i.over=r)}function WL(e){Reflect.deleteProperty(VL.pointers,$_(e,`document`))}const GL=e=>e.evt?.detail??0;function KL(){let e=null;return{track(t,n){GL(n)<=1&&(e=t)},isDouble(t,n){return GL(n)>=2&&e===t}}}const qL={insert:1,delete:2};function JL(e,t,n){let r=t?.get(n);return r===qL.insert?e.diffInsertBackground:r===qL.delete?e.diffDeleteBackground:null}const YL=(e,t)=>{let n=W(e,z.primaryKey),r=W(e,z.foreignKey);return n&&r?t.keyPFK:n?t.keyPK:r?t.keyFK:tF},XL=(e,t,n,r,i)=>!t&&n?r?e.columnSelectHover:e.columnSelect:i>0?r?mL(e.columnHover,e.accentColor4,i):mL(e.tableBackground,e.accentColor3,i):r?e.columnHover:tF,ZL=(e,t)=>{let n=vP(t),r=AP(t),i=Ma({hover:!1,removeHover:!1}),{addUnsubscribe:a}=BF(),o=KL(),s=null,c=()=>{s?.unsubscribe(),s=null};a(c);let l=t=>{if(e.preview||e.ghost||t.evt.button!==0||e.source!==`document`)return;c();let n=!1,r=PF.subscribe({next:()=>{n||(n=!0,e.onDragstart?.(e.column.id,t))},complete:()=>{s===r&&(s=null),n&&e.onDragend?.()}});s=r},u=!1,d=e=>{u=!!n.value.store.state.editor.drawRelationship,l(e)},f=()=>{i.hover=!0},p=()=>{i.hover=!1},m=e=>{i.removeHover=!0,cF(e,aF)},h=e=>{i.removeHover=!1,cF(e,``)},g=(e,t)=>t?i.removeHover?e.active:e.foreground:tF,_=(t,r)=>{if(e.source!==`document`)return;let{store:i}=n.value,{column:a}=e;i.dispatch(Yy({tableId:a.tableId,columnId:a.id,focusType:t,$mod:hP(r.evt),shiftKey:r.evt.shiftKey}))},v=(t,r)=>{if(!o.isDouble(t,r)||e.source!==`document`)return;let{store:i}=n.value,{column:a}=e;i.dispatch(pw(t)?_w(t,a.tableId,a.id):tb())},y=()=>{if(u)return;let{store:t}=n.value,{column:r}=e;t.dispatch(gw(r.tableId,[r.id]))},ee=()=>{let{column:t}=e;if(t.ui.keys===0)return;let{store:r}=n.value;r.dispatch(fj(t.id))},te=()=>{let{store:e}=n.value;e.dispatch(pj())},ne=(t,n)=>{let i=JL(r.value,e.diffPaths,t);return i?k`<k-rect name="cell-diff-background" width=${n+8} height=${x_(e.source)} fill=${i} listening=${!1} />`:null},re=({focusType:t,x:n,width:i,text:a,fill:s,focus:c,edit:l,sharedFocus:u,ellipsis:d,opacity:f=1,align:p,fontFamily:m=KP})=>k`<k-group name=${`column-col ${t}`} kind="column-col" sharedFocus=${u} x=${n} y=${0} opacity=${f} listening=${f>0} @mousedown=${e=>{_(t,e),o.track(t,e)}} @dblclick=${e=>{v(t,e)}}>${ne(t,i)}<k-text name="cell-text" y=${MI(e.source)} width=${i} height=${NI(e.source,m)} text=${a} fill=${s} fontFamily=${m} fontSize=${12} align=${p} verticalAlign="middle" wrap="none" ellipsis=${d} visible=${!l} hitFunc=${KI[e.source]} />${c&&e.source===`document`?k`<k-rect name="cell-focus-border" y=${MI(e.source)+PI()} width=${i} height=${QP} fill=${FI(r.value,l,e.editorFocused)} listening=${!1} />`:null}${u?k`<k-rect name="cell-shared-focus-border" y=${x_(e.source)-QP} width=${i+8} height=${QP} fill=${u} listening=${!1} />`:null}</k-group>`,ie=({columnType:t,focusType:n,x:i,width:a})=>{let{column:o}=e,s=r.value,c=e.source!==`document`;switch(t){case F.columnName:return re({focusType:n,x:i,width:a,text:o.name.trim()?o.name:`column`,fill:o.name.trim()?s.active:s.placeholder,focus:e.focusName,edit:e.editName,sharedFocus:e.sharedFocusName,ellipsis:!0});case F.columnDefault:return re({focusType:n,x:i,width:a,text:o.default.trim()?o.default:`default`,fill:o.default.trim()?s.active:s.placeholder,focus:e.focusDefault,edit:e.editDefault,sharedFocus:e.sharedFocusDefault,ellipsis:!0});case F.columnComment:return re({focusType:n,x:i,width:a,text:o.comment.trim()?o.comment:`comment`,fill:o.comment.trim()?s.active:s.placeholder,focus:e.focusComment,edit:e.editComment,sharedFocus:e.sharedFocusComment,ellipsis:!0});case F.columnDataType:return re({focusType:n,x:i,width:a,text:o.dataType.trim()?o.dataType:`dataType`,fill:o.dataType.trim()?s.active:s.placeholder,focus:e.focusDataType,edit:e.editDataType,sharedFocus:e.sharedFocusDataType,ellipsis:!0,opacity:c?e.litAlpha??0:1,align:c?`right`:void 0,fontFamily:c?`'Menlo', 'Consolas', 'Bitstream Vera Sans Mono', monospace, 'Apple Color Emoji', 'Segoe UI Emoji'`:void 0});case F.columnNotNull:return re({focusType:n,x:i,width:a,text:W(o.options,R.notNull)?`N-N`:`NULL`,fill:s.active,focus:e.focusNotNull,edit:!1,sharedFocus:e.sharedFocusNotNull,ellipsis:!1});case F.columnUnique:return re({focusType:n,x:i,width:a,text:`UQ`,fill:W(o.options,R.unique)?s.active:s.placeholder,focus:e.focusUnique,edit:!1,sharedFocus:e.sharedFocusUnique,ellipsis:!1});case F.columnAutoIncrement:return re({focusType:n,x:i,width:a,text:`AI`,fill:W(o.options,R.autoIncrement)?s.active:s.placeholder,focus:e.focusAutoIncrement,edit:!1,sharedFocus:e.sharedFocusAutoIncrement,ellipsis:!1})}return null},ae=()=>{let{store:t}=n.value;return UI(t.state,{name:e.widthName,comment:e.widthComment,dataType:e.widthDataType,default:e.widthDefault},e.source).map(e=>({columnType:e.columnType,template:ie(e)})).filter(({template:e})=>!!e)};return()=>{let{store:t}=n.value,{editor:a}=t.state,{column:o,selected:s,width:c}=e,l=r.value,u=!!(e.hovered||i.hover||a.hoverColumnMap[o.id]),_=!!a.draggingColumnMap[o.id],v=c-18,ne=e.source!==`document`,re=XL(l,ne,s,u,ne&&e.related?e.litAlpha??0:0),ie=x_(e.source),b=ne?16:12;return k`<k-group id=${e.preview?``:`column-${o.id}`} name="column-row" kind="column-row" tableId=${o.tableId} selected=${s} y=${e.y} opacity=${_?.5:1} visible=${!e.ghost} @mousedown=${d} @mouseenter=${f} @mouseleave=${p}><k-rect name="column-row-background" x=${1} width=${c-2} height=${ie} cornerRadius=${e.last?[0,0,6,6]:0} fill=${re} />${ZI({icon:`key-round`,name:`column-col column-key`,kind:`column-col`,size:b,color:YL(o.ui.keys,l),x:9,y:(ie-b)/2,mouseenter:ee,mouseleave:te})}${hu(ae(),({columnType:e})=>e,({template:e})=>e)}${e.divider?k`<k-line name="column-row-divider" points=${[1,ie,c-1,ie]} stroke=${l.tableBorder} strokeWidth=${1} listening=${!1} />`:null}${ne?null:ZI({icon:`x`,name:`column-remove`,kind:`icon`,size:12,color:g(l,u),x:9+v-12,y:6,click:y,mouseenter:m,mouseleave:h})}</k-group>`}};function QL(e,t){let{settings:n}=e,{viewport:r}=e.editor,i=W_(n,t),a=W_(n,{x:t.x+t.width,y:t.y+t.height});return i.x>=0&&i.y>=0&&a.x<=r.width&&a.y<=r.height}const $L=e=>function*(t){let{viewport:n}=t.editor,r=M(t.collections).collection(`tableEntities`).selectById(e);if(!r)return;let i=A_(t,r);if(!QL(t,i)){let e=K_(t.settings.zoomLevel,{x:i.x+i.width/2,y:i.y+i.height/2},{x:n.width/2,y:n.height/2});yield hv({originX:e.x,originY:e.y})}yield uw(e,!1)};function eR(e,t){e.dispatchSync(Cv({value:Ym.ERD})),e.dispatchSync($L(t))}const tR=Si(null),nR=e=>qa(e,tR);function rR(e,t){e.store.dispatchSync(Ig({tableIds:t,kind:og.flow}))}function iR(e,t,n=`document`){let{collections:r}=e,i=J_(e,n),a=M(r).collection(`tableEntities`).selectByIds(Zg(e,n).tableIds).filter(t=>X_(i,e,t,n)).sort((e,t)=>t.ui.zIndex-e.ui.zIndex).map(t=>({table:t,rect:A_(e,t,n)})),o=(e,n)=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height+n,s=a.find(({rect:e})=>o(e,0))??a.find(({rect:e})=>o(e,8));if(!s)return null;let{table:c}=s,l=Xg(e,c,n),u={tableId:c.id,columnId:null,index:l.length};if(!l.length)return u;let d=M_(e,c,0,n);if(t.y<d.y)return null;let f=Math.floor((t.y-d.y)/d.height);return f>=l.length?u:{tableId:c.id,columnId:l[f],index:f}}function aR({collections:e},{tableId:t,columnIds:n},r){if(r.columnId!==null)return n.includes(r.columnId);if(r.tableId!==t)return!1;let i=M(e).collection(`tableEntities`).selectById(t);return ce(i?.columnIds.slice(-n.length),n)}const oR=`flipFade`;function sR(e,t){let n=e.getAbsolutePosition(),r=e.getAbsoluteScale();return{x:(n.x-t.x)/(r.x||1),y:(n.y-t.y)/(r.y||1)}}function cR(e){let t=new Map,n=new Map,r=null,i=null,a=(e,t,n,r,i,a)=>{sf(n);let o=!1,s=-1,c=()=>{o||(o=!0,clearTimeout(s),e.delete(t),i(),cf(n))},l=new mi({node:t,...r,duration:.3,easing:pi.EaseInOut,onFinish:c,onReset:c});l.onUpdate=a,e.set(t,()=>{l.destroy(),c()}),s=setTimeout(()=>e.get(t)?.(),500),l.play()},o=(e,n,r,i)=>{t.get(e)?.(),e.offsetX(r),e.offsetY(i),a(t,e,n,{offsetX:0,offsetY:0},()=>{e.offsetX(0),e.offsetY(0)})},s=(e,t)=>{n.get(e)?.();let r=e.opacity(),i=!1,o=()=>{i=!0,e.opacity(r*(e.getAttr(oR)??1)),i=!1};e.on(`opacityChange.${oR}`,()=>{i||(r=e.opacity())}),e.setAttr(oR,0),o();let s=()=>{e.off(`opacityChange.${oR}`),e.setAttr(oR,void 0),o()};a(n,e,t,{[oR]:1},s,o)},c=()=>{let e=r;return r=null,i?.(),i=null,e},l=()=>{let t=c();if(!t)return;for(let e of t){let{node:t}=e,n=t.getLayer();if(!n||!t.getStage())continue;let{x:r,y:i}=sR(t,e);!r&&!i||o(t,n,r,i)}let n=new Set(t.map(({node:e})=>e));for(let t of e()){let e=t.getLayer();n.has(t)||!e||!t.getStage()||s(t,e)}};return{snapshot(){r=e().map(e=>{let{x:t,y:n}=e.getAbsolutePosition();return{node:e,x:t,y:n}}),i??=nf(l)},cancel(){c(),[...t.values(),...n.values()].forEach(e=>e())}}}function lR(e,t){let n=vP(e),r=()=>n.value.store.state.editor.focusTable;return{hasFocus:(e,n)=>VF(r(),e,t,n),hasEdit:(e,n)=>UF(r(),e,t,n),hasSelectColumn:e=>HF(r(),t,e)}}function uR(e){if(WP(e))return{x:e.clientX,y:e.clientY};let{touches:t,changedTouches:n}=e,r=t?.[0]??n?.[0];return r?{x:r.clientX,y:r.clientY}:null}const dR=e=>e.type===`mouseup`||e.type===`touchend`&&!e.touches?.length;function fR(e,t){return Math.abs(t.x-e.x)<=4&&Math.abs(t.y-e.y)<=4}function pR(e){return!hP(e)&&(!WP(e)||e.button===0)}function mR(e,t){let n=uR(e);!n||GP(e)||jF.pipe(Re(1)).subscribe(e=>{let r=dR(e)?uR(e):null;r&&fR(n,r)&&t()})}function hR(e,t,n){return{onPress:r=>{let{evt:i}=r,a=n.value;if(a===`document`||!pR(i))return;let o=e.value.store.state.editor.views[a];if(!o)return;let{id:s}=t.table;mR(i,()=>{let{store:t}=e.value;t.state.editor.views[a]===o&&o_(t.state,s,a)})}}}const gR=[`icon`],_R=(e,t,n)=>t.trim()?n?e.foreground:e.active:e.placeholder,vR=(e,t)=>{let n=vP(t),r=AP(t),i=QF(t),a=nR(t),{hasEdit:o,hasFocus:s,hasSelectColumn:c}=lR(t,e.table.id),{sharedFocusColor:l,sharedFocusTableColor:u}=YF(t,e.table.id),{sharedSelectColor:d}=XF(t,e.table.id),{onMoveStart:f}=zF(t,e,i),p=hR(n,e,i),{addUnsubscribe:m}=BF(),h=Ma({hover:!1,iconHover:null,dragstartId:null}),g=KL(),_=null,v=null,y=null,ee=()=>{h.hover=!0,i.value!==`document`&&t_(n.value.store.state,e.table.id,i.value)},te=()=>{h.hover=!1,i.value!==`document`&&t_(n.value.store.state,null,i.value)};m(()=>{i.value!==`document`&&n_(n.value.store.state,e.table.id,i.value)});let ne=e=>t=>{h.iconHover=e,cF(t,aF)},re=e=>{h.iconHover=null,cF(e,``)},ie=(e,t,n)=>n?h.iconHover===t?e.active:e.foreground:tF,ae=(t,n)=>n?e.editorFocused===!1?t.placeholder:t.tableSelect:t.tableBorder,b=!1,oe=e=>{b=!!n.value.store.state.editor.drawRelationship,!(i.value!==`document`&&hF(e.target,gR))&&(f(e),p.onPress(e))},se=t=>{if(b)return;let{emitter:r}=n.value;r.emit(aP({x:t.evt.clientX,y:t.evt.clientY,color:e.table.ui.color}))},ce=()=>{if(b)return;let{store:t}=n.value;t.dispatch(hw(e.table.id))},le=()=>{if(b)return;let{store:t}=n.value;t.dispatch(lw(e.table.id))},x=()=>{rR(n.value,[e.table.id])},ue=()=>{eR(n.value.store,e.table.id)},S=t=>{if(i.value!==`document`)return;let{store:r}=n.value;r.dispatch(qy({tableId:e.table.id,focusType:t}))},de=(e,t)=>{if(!g.isDouble(e,t)||i.value!==`document`)return;let{store:r}=n.value;r.dispatch(tb())},C=e=>{let t=v,n=t?.findOne(`.scene`);if(!t||!n)return null;t.setPointersPositions(e);let r=t.getPointerPosition();return r?n.getAbsoluteTransform().copy().invert().point(r):null},fe=e=>{let{store:t}=n.value,r=C(e);if(!r)return;let a=iR(t.state,r,i.value);if(UL(t.state,r,a!==null),!a)return;let{editor:{draggableColumn:o}}=t.state;!o||aR(t.state,o,a)||(y?.snapshot(),t.dispatch(dj(a.columnId,a.tableId)))},pe=()=>{let{store:e,emitter:t}=n.value;!_&&h.dragstartId===null||(_?.unsubscribe(),_=null,v=null,h.dragstartId=null,WL(e.state),e.dispatch(Nb()),t.emit(oP()))},me=(t,r)=>{let{store:a}=n.value;if(i.value!==`document`)return;let{editor:{focusTable:o}}=a.state;if(!o||!o.columnId)return;let s=r.target?.getStage()??null;if(!s)return;_?.unsubscribe(),v=s,h.dragstartId=t,y??=cR(()=>s.find(`.column-row`));let c=hP(r.evt),l=C(r.evt);l&&HL(a.state,e.table,l,{columnId:t,columnIds:c?o.selectColumnIds:[t]}),a.dispatch(lj(c)),_=PF.subscribe({next:({event:e})=>{fe(e)},complete:pe})};da(()=>{let{emitter:e}=n.value;m(e.on({dragendColumnAll:()=>{_?.unsubscribe(),_=null,WL(n.value.store.state)}}),()=>{_&&WL(n.value.store.state),_?.unsubscribe(),_=null,y?.cancel()})});let he=({focusType:t,x:n,width:o,text:s,fill:c,focus:l,edit:u,sharedFocus:d})=>{let f=i.value,p=f!==`document`,m=JL(r.value,a.value?.get(e.table.id)?.[1],t);return k`<k-group name=${`input-padding ${t}`} kind="input-padding" sharedFocus=${d} x=${n} y=${0} @mousedown=${e=>{S(t),g.track(t,e)}} @dblclick=${e=>{de(t,e)}}>${m?k`<k-rect name="cell-diff-background" width=${o+8} height=${24} fill=${m} listening=${!1} />`:null}<k-text name="cell-text" y=${AI(f)} width=${o} height=${jI(f)} text=${s} fill=${c} fontFamily=${KP} fontSize=${p?14:12} fontStyle=${p?`500`:`normal`} verticalAlign="middle" wrap="none" ellipsis=${!0} visible=${!u} hitFunc=${JI[f]} />${l&&!p?k`<k-rect name="cell-focus-border" y=${AI(f)+18.5} width=${o} height=${QP} fill=${FI(r.value,u,e.editorFocused)} listening=${!1} />`:null}${d?k`<k-rect name="cell-shared-focus-border" y=${22.5} width=${o+8} height=${QP} fill=${d} listening=${!1} />`:null}</k-group>`};return()=>{let{store:t}=n.value,{editor:f,collections:p}=t.state,{table:m}=e,g=r.value,_=!!f.selectedMap[m.id],v=i.value,y=j_(t.state,m,v),b=A_(t.state,m,v),S=b.width-18,de=!!(e.hovered||h.hover),C=e.ghostColumnId??h.dragstartId,fe=C!==null&&!m.columnIds.includes(C)?C:null,ge=u(),_e=d(),ve=l(U.tableName),ye=l(U.tableComment),be=ge??_e,xe=v!==`document`,Se=kI(v)-9,Ce=Se+(xe?2:6),we=xe?16:12,Te=xe&&de,Ee=(e,t)=>!xe&&o(e,t),De=BI(t.state,m,v),Oe=De.find(e=>e.focusType===U.tableName),ke=De.find(e=>e.focusType===U.tableComment),Ae=Xg(t.state,m,v),je=Ae.length===0,Me=xe&&!!e.lit,Ne=xe?$P(g.minimapShadow):iF(g.tableShadow),Pe=lL(f.id,`table`,m.id),Fe=0;xe&&(dL(Pe,+!!Me),Fe=uL(Pe));let Ie=M(p).collection(`tableColumnEntities`).selectByIds(fe?[...Ae,fe]:Ae);return k`<k-group id=${e.preview?``:`table-${m.id}`} name="table" kind="table" visible=${e.visible??!0} selected=${_} sharedFocus=${ge} sharedSelect=${_e} x=${b.x} y=${b.y} @mousedown=${oe} @touchstart=${oe} @mouseenter=${ee} @mouseleave=${te}><k-rect name="table-body" x=${1/2} y=${1/2} width=${b.width-1} height=${b.height-1} cornerRadius=${6} fill=${g.tableBackground} stroke=${mL(ae(g,_),g.accentColor9,Fe)} strokeWidth=${1} shadowColor=${Ne?.color} shadowBlur=${Ne?.blur} shadowOffsetX=${Ne?.offsetX} shadowOffsetY=${Ne?.offsetY} shadowOpacity=${Ne?.opacity} shadowForStrokeEnabled=${!Ne&&void 0} @mouseenter=${e=>{xe&&cF(e,`pointer`)}} @mouseleave=${e=>{xe&&cF(e,``)}} /><k-rect name="table-header-band" x=${1} y=${1} width=${b.width-2} height=${je?b.height-2:9+b_(v)-1} cornerRadius=${je?6:[6,6,0,0]} fill=${g.tableHeaderBackground} listening=${!1} />${Fe>0?k`<k-rect name="table-glow" x=${-1/2} y=${-1/2} width=${b.width+1} height=${b.height+1} cornerRadius=${6} opacity=${Fe} stroke=${g.accentColor9} strokeWidth=${1} shadowColor=${g.accentColor9} shadowBlur=${14} shadowOpacity=${.55} shadowForStrokeEnabled=${!0} listening=${!1} />`:null}${be?k`<k-rect name="table-ring" x=${-1/2} y=${-1/2} width=${b.width+1} height=${b.height+1} cornerRadius=${6} stroke=${be} strokeWidth=${1} listening=${!1} />`:null}<k-group name="table-header" x=${9} y=${9}><k-group name="table-header-inputs" y=${Se}>${ZI({icon:`table-2`,name:`table-header-icon`,kind:`table-header-icon`,size:we,color:g.foreground,x:0,y:xe?0:(24-we)/2})}${Oe?he({...Oe,text:m.name.trim()?m.name:`table`,fill:_R(g,m.name,xe),focus:s(U.tableName),edit:Ee(U.tableName),sharedFocus:ve}):null}${ke?he({...ke,text:m.comment.trim()?m.comment:`comment`,fill:m.comment.trim()?g.active:g.placeholder,focus:s(U.tableComment),edit:Ee(U.tableComment),sharedFocus:ye}):null}</k-group>${xe?null:ZI({icon:`plus`,name:`table-add-column`,kind:`icon`,size:12,color:ie(g,`plus`,de),mouseenter:ne(`plus`),mouseleave:re,x:S-24-4,y:Ce,click:ce})}${xe?null:ZI({icon:`x`,name:`table-remove`,kind:`icon`,size:12,color:ie(g,`x`,de),mouseenter:ne(`x`),mouseleave:re,x:S-12,y:Ce,click:le})}${Te?ZI({icon:`waypoints`,name:`table-related`,kind:`icon`,size:12,color:ie(g,`waypoints`,de),mouseenter:ne(`waypoints`),mouseleave:re,x:S-28,y:Ce,click:x}):null}${Te?ZI({icon:`external-link`,name:`table-go-to-erd`,kind:`icon`,size:12,color:ie(g,`external-link`,de),mouseenter:ne(`external-link`),mouseleave:re,x:S-12,y:Ce,click:ue}):null}</k-group><k-group name="table-columns">${hu(Ie,e=>e.id,(n,r)=>k`<${ZL} .column=${n} .source=${v} .related=${e.relatedColumnIds?.has(n.id)??!1} .diffPaths=${a.value?.get(n.id)?.[1]??null} .litAlpha=${Fe} .divider=${xe&&r<Ae.length-1} .last=${r===Ae.length-1} .y=${M_(t.state,m,r,v).y-b.y} .width=${b.width} .selected=${c(n.id)} .hovered=${n.id===e.hoveredColumnId} .widthName=${y.name} .widthDataType=${y.dataType} .widthDefault=${y.default} .widthComment=${y.comment} .focusName=${s(U.columnName,n.id)} .focusDataType=${s(U.columnDataType,n.id)} .focusNotNull=${s(U.columnNotNull,n.id)} .focusDefault=${s(U.columnDefault,n.id)} .focusComment=${s(U.columnComment,n.id)} .focusUnique=${s(U.columnUnique,n.id)} .focusAutoIncrement=${s(U.columnAutoIncrement,n.id)} .editName=${Ee(U.columnName,n.id)} .editDataType=${Ee(U.columnDataType,n.id)} .editDefault=${Ee(U.columnDefault,n.id)} .editComment=${Ee(U.columnComment,n.id)} .sharedFocusName=${l(U.columnName,n.id)} .sharedFocusDataType=${l(U.columnDataType,n.id)} .sharedFocusNotNull=${l(U.columnNotNull,n.id)} .sharedFocusDefault=${l(U.columnDefault,n.id)} .sharedFocusComment=${l(U.columnComment,n.id)} .sharedFocusUnique=${l(U.columnUnique,n.id)} .sharedFocusAutoIncrement=${l(U.columnAutoIncrement,n.id)} .ghost=${n.id===fe} .preview=${e.preview} .editorFocused=${e.editorFocused} .onDragstart=${me} .onDragend=${pe} />`)}</k-group><k-path name="table-header-color" kind="table-header-color" data=${uF(b.height)} fill=${m.ui.color} listening=${!xe} @click=${se} @mouseenter=${e=>{cF(e,aF)}} @mouseleave=${e=>{cF(e,``)}} /></k-group>`}},yR=(e,t)=>e.ui.zIndex-t.ui.zIndex,bR=(e,t)=>{let n=vP(t),r=AP(t);return()=>{let{store:t}=n.value,{box:i,scale:a}=e,{settings:{show:o,zoomLevel:s},doc:{tableIds:c,memoIds:l,relationshipIds:u},collections:d}=t.state,f=r.value,p=M(d).collection(`tableEntities`).selectByIds(c).sort(yR),m=M(d).collection(`memoEntities`).selectByIds(l).sort(yR),h=M(d).collection(`relationshipEntities`).selectByIds(u),g=rg(s);return k`<k-layer name="export-scene" listening=${!1} x=${-i.x*a} y=${-i.y*a} scaleX=${a} scaleY=${a}><k-rect name="export-background" x=${i.x} y=${i.y} width=${i.width} height=${i.height} fill=${f.canvasBackground} />${W(o,P.relationship)?k`<${BL} .relationships=${h} />`:null}${hu(p,e=>e.id,e=>g?k`<${eI} .table=${e} />`:k`<${vR} .table=${e} />`)}${hu(m,e=>e.id,e=>k`<${$I} .memo=${e} />`)}</k-layer>`}};async function xR({doc:e,theme:t,toWidth:n,zoomLevel:r}){let i=gP({toWidth:n},{devtools:!1});i.store.dispatchSync(WA(e)),S(r)&&i.store.dispatchSync(lv({value:r})),await MP(32);let a=i.store.state.settings.zoomLevel,o=IP(i.store.state),s=LP(o,a),c=jP({app:i,container:document.createElement(`div`),scene:k`<${bR} .box=${o} .scale=${s} />`,width:o.width*s,height:o.height*s,theme:t});return await uf(),{stage:c.stage,box:o,scale:s,zoomLevel:a,destroy:()=>{c.destroy(),yP(i)}}}function SR(e){return`convertToBlob`in e?e.convertToBlob({type:`image/png`}):new Promise((t,n)=>{e.toBlob(e=>{e?t(e):n(Error(`[export-png] the canvas encoded no png`))},`image/png`)})}async function CR({doc:e,theme:t,pixelRatio:n,zoomLevel:r,toWidth:i}){let a=await xR({doc:e,theme:t,toWidth:i,zoomLevel:r});try{let e=PP(n,a.stage.width(),a.stage.height()),t=a.stage.toCanvas({pixelRatio:e}),r=await SR(t),{width:i,height:o}=t;return{blob:r,width:i,height:o,reduction:a.scale*e<n*a.zoomLevel?{documentWidth:a.box.width,documentHeight:a.box.height,width:i,height:o}:null}}finally{a.destroy()}}const wR=`400 12px ${UP}`,TR=[`ERD editor 0123456789`,`가나다 漢字 テスト`,`—…€· iIlL1`];function ER(){if(typeof OffscreenCanvas>`u`)return null;let e=new OffscreenCanvas(1,1).getContext(`2d`);return e?(e.font=wR,t=>Math.round(e.measureText(t).width)+2):null}function DR(e){return TR.map(t=>e(t))}function OR(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}const kR=new class{async probeFontWidths(){return DR(this.createToWidth())}async render(e){let t=this.createToWidth(),n=DR(t);if(!OR(n,e.fontProbe))throw Error(`[export-png] this realm measures text differently: ${n.join()} against ${e.fontProbe.join()}`);return CR({...e,toWidth:t})}createToWidth(){let e=ER();if(!e)throw Error(`[export-png] this realm has no 2d context to measure by`);return e}};self.onconnect=t=>{let n=t.ports[0];e.expose(kR,n)};
|