structile 6.0.0__py3-none-any.whl

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.
@@ -0,0 +1,188 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Structile</title>
7
+ <style>:root,:root[data-theme=light]{--bg:#f3f5f8;--bg2:#ffffff;--chrome:#eceef2;--chrome-diff:#e6eaf2;--line:#d7dce3;--ink:#1b2330;--ink-dim:#4c5765;--ink-faint:#7c8695;--accent:#1670a0;--accent-soft:#d6e9f4;--hl:#a17a17;--hl-bg:#fbe6a8;--hl-cur:#f2c14e;--t-str:#1c7a41;--t-num:#8236c2;--t-bool:#a2610a;--t-null:#7c8695;--t-na:#b5562b;--diff-add-bg:#e5f0e6;--diff-add-ink:#1c7a41;--diff-del-bg:#fbe4e2;--diff-del-ink:#b42318;--diff-chg-bg:#fdf3d9;--diff-chg-ink:#8a6d1a;--tbl:#ffffff;--tbl-line:#e0e5eb;--tbl-head:#eceef2;--tint-0:rgba(15,23,35,.028);--tint-1:rgba(15,23,35,.045);--tint-2:rgba(15,23,35,.065);--tint-3:rgba(15,23,35,.09);--tint-4:rgba(15,23,35,.11);--dot:#e2e7ed;--pop-bg:#ffffff;--shadow:rgba(30,40,55,.18);--hover-ink:#000;--mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Roboto Mono",monospace;--sans:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}:root[data-theme=dark]{--bg:#0e1116;--bg2:#11151c;--chrome:#0b0e13;--chrome-diff:#111a24;--line:#222a36;--ink:#e7ecf3;--ink-dim:#9aa6b6;--ink-faint:#6b7686;--accent:#4aa3c7;--accent-soft:#1d3a47;--hl:#caa64a;--hl-bg:#4a3c14;--hl-cur:#bd9737;--t-str:#9ecb8f;--t-num:#e0b0ff;--t-bool:#f0a868;--t-null:#6b7686;--t-na:#e8935f;--diff-add-bg:#1b2925;--diff-add-ink:#9ecb8f;--diff-del-bg:#3a1c1a;--diff-del-ink:#f2a49b;--diff-chg-bg:#3a2f12;--diff-chg-ink:#e0c076;--tbl:#0c0f15;--tbl-line:#1c2530;--tbl-head:#141a23;--tint-0:rgba(255,255,255,.018);--tint-1:rgba(255,255,255,.035);--tint-2:rgba(255,255,255,.05);--tint-3:rgba(255,255,255,.07);--tint-4:rgba(255,255,255,.08);--dot:#161b23;--pop-bg:#0c0f15;--shadow:rgba(0,0,0,.55);--hover-ink:#fff}*{box-sizing:border-box}body,html{height:100%;margin:0}body{background:var(--bg);color:var(--ink);font-family:var(--sans);font-size:13px;display:flex;flex-direction:column;overflow:hidden}#bar{display:flex;align-items:center;gap:10px;padding:8px 12px;background:var(--chrome);border-bottom:1px solid var(--line);flex:0 0 auto;flex-wrap:wrap}#bar.drag{box-shadow:inset 0 0 0 2px var(--accent);background:var(--accent-soft)}.filename-label{background:0 0;border:none;border-bottom:1px dashed var(--ink-faint);margin:0;padding:2px 0;font:inherit;text-align:left;cursor:pointer;color:var(--ink-dim);font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:220px;flex:0 1 auto}.filename-label:hover{color:var(--accent);border-bottom-color:var(--accent)}body.embedded #fileNameLabel{cursor:default;border-bottom-color:transparent}body.embedded #fileNameLabel:hover{color:var(--ink-dim);border-bottom-color:transparent}body.embedded [data-embed-hide]{display:none!important}body.embedded:not(.structile-settings-panel-enabled) [data-settings-panel-hide]{display:none!important}body.host-manages-save [data-host-save-hide]{display:none!important}[data-host-save-show]{display:none!important}body.host-manages-save [data-host-save-show]{display:inline-block!important}[data-embed-only]{display:none}body.embedded [data-embed-only]{display:inline-block}body.structile-source-view-disabled [data-source-view-hide]{display:none!important}body.structile-diff-mode [data-diff-hide]{display:none!important}#diffHeader{display:flex;flex-wrap:wrap;align-items:center;gap:14px;padding:8px 14px;background:var(--chrome-diff);border-bottom:1px solid var(--line);font-size:12px}#diffHeader[hidden]{display:none}#diffHeader .dh-title{font-weight:700;font-size:13px}#diffHeader .diff-info-btn{width:22px;height:22px;padding:0;border-radius:50%;font-weight:700;display:inline-flex;align-items:center;justify-content:center}#diffHeader .dh-side{color:var(--ink-dim);display:inline-flex;align-items:baseline;gap:4px;min-width:0}#diffHeader .dh-side b{color:var(--ink)}#diffHeader .dh-name-btn{background:0 0;border:none;padding:0;margin:0;font:inherit;color:inherit;cursor:pointer;border-bottom:1px dashed var(--ink-faint);display:inline-block;max-width:200px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:bottom}#diffHeader .dh-name-btn:hover{color:var(--accent);border-bottom-color:var(--accent)}#diffHeader .dh-name-btn:disabled{cursor:default;opacity:1;color:inherit;border-bottom-color:transparent}#diffHeader .diff-swap-btn{width:22px;height:22px;padding:0;border-radius:50%;font-size:13px;display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto}#diffHeader .dh-layout,#diffHeader .dh-scope{display:inline-flex}#diffHeader .dh-layout .btn,#diffHeader .dh-scope .btn{border-radius:0}#diffHeader .dh-layout .btn:first-child,#diffHeader .dh-scope .btn:first-child{border-radius:6px 0 0 6px}#diffHeader .dh-layout .btn:not(:first-child),#diffHeader .dh-scope .btn:not(:first-child){border-left:none}#diffHeader .dh-layout .btn:last-child,#diffHeader .dh-scope .btn:last-child{border-radius:0 6px 6px 0}#diffHeader .diff-layout-btn.active,#diffHeader .diff-scope-btn.active{color:var(--accent);border-color:var(--accent-soft);background:var(--accent-soft)}#diffHeader .dh-summary{margin-left:auto;color:var(--ink-faint);cursor:help}#diffHeader .dh-count{border-bottom:1px dotted var(--ink-faint);cursor:help}#diffHeader .diff-exit-btn{flex:0 0 auto}#diffHeader .diff-exit-btn:hover{color:var(--diff-del-ink);border-color:var(--diff-del-ink)}.diff-help-pop{position:fixed;z-index:310;width:min(760px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow:auto;background:var(--pop-bg);border:1px solid var(--accent);border-radius:8px;padding:12px;color:var(--ink);box-shadow:0 8px 24px var(--shadow)}.diff-help-pop h4{margin:0 0 7px;font-size:14px}.diff-help-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}.diff-help-col{border:1px solid var(--line);border-radius:7px;padding:9px;min-width:0}.diff-help-col.active{border-color:var(--accent)}.diff-help-col h5{margin:0 0 7px;font-size:13px}.diff-help-tag{font-size:9px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:var(--accent);border:1px solid var(--accent);border-radius:3px;padding:1px 4px;margin-left:6px;vertical-align:2px}.diff-help-scope{color:var(--ink-dim);line-height:1.42;padding:4px 6px;border-radius:5px}.diff-help-scope+.diff-help-scope{margin-top:5px}.diff-help-scope b{color:var(--ink)}.diff-help-scope.active{background:var(--accent-soft);box-shadow:inset 2px 0 0 var(--accent)}.diff-help-scope.active b{color:var(--accent)}.diff-help-note{margin:8px 0 0;padding-top:7px;border-top:1px dashed var(--line);font-size:11px;color:var(--ink-faint);line-height:1.4;font-style:italic}.diff-help-note b{font-style:normal;color:var(--ink-dim)}.box.diff-added,.dname.diff-added,.pcell.diff-added,.tname.diff-added{background:var(--diff-add-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-add-ink)}.box.diff-removed,.dname.diff-removed,.pcell.diff-removed,.tname.diff-removed{background:var(--diff-del-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-del-ink)}.box.diff-changed,.dname.diff-changed,.pcell.diff-changed,.tname.diff-changed{background:var(--diff-chg-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-chg-ink)}.box.diff-struck .dname,.box.diff-struck .pcell .pk,.box.diff-struck .pcell .pv,.box.diff-struck .tname,.box.diff-struck td,.box.diff-struck th,.pcell.diff-struck .pk,.pcell.diff-struck .pv,td.diff-struck,th.diff-struck{text-decoration:line-through}.box.diff-order,.dname.diff-order,.tname.diff-order{box-shadow:inset 0 0 0 1px var(--accent)}td.diff-added,th.diff-added{background:var(--diff-add-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-add-ink)}td.diff-removed,th.diff-removed{background:var(--diff-del-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-del-ink)}td.diff-changed,th.diff-changed{background:var(--diff-chg-bg)!important;box-shadow:inset 0 0 0 1px var(--diff-chg-ink)}th.diff-order{box-shadow:inset 0 2px 0 var(--accent)}tr.diff-row-order td:first-child{border-left:3px solid var(--accent)}.sep{width:1px;height:22px;background:var(--line);margin:0 2px}.ctl{display:flex;align-items:center;gap:6px;color:var(--ink-dim);font-size:12px}#searchInput,input[type=number],input[type=text],select,textarea{background:var(--bg2);color:var(--ink);border:1px solid var(--line);border-radius:6px;padding:5px 8px;font-family:var(--sans);font-size:12px;outline:0}input:focus,select:focus,textarea:focus{border-color:var(--accent)}.btn{background:var(--bg2);color:var(--ink);border:1px solid var(--line);border-radius:6px;padding:6px 10px;font-size:12px;cursor:pointer;font-family:var(--sans)}.btn:hover{border-color:var(--accent);color:var(--hover-ink)}.btn:disabled{opacity:.4;cursor:not-allowed}.btn:disabled:hover{border-color:var(--line);color:var(--ink)}.btn.sm{padding:4px 9px;font-size:14px;line-height:1}.btn.ghost{background:0 0}.btn-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;margin-right:5px;border-radius:50%;color:#fff;font-size:11px;font-weight:700;line-height:1}.btn-icon.export{background:#1c7a41}.btn-icon.load{background:#1670a0}.btn-icon.reset{background:#a2610a}.split-btn{display:inline-flex}.split-btn .btn{border-radius:0}.split-btn .btn:first-child{border-radius:6px 0 0 6px}.split-btn .btn:not(:first-child){border-left:none}.split-btn .btn:last-child{border-radius:0 6px 6px 0}.split-btn .split-caret{padding:4px 6px}.history-menu{position:fixed;z-index:300;min-width:220px;max-width:400px;max-height:340px;overflow:auto;background:var(--pop-bg);border:1px solid var(--accent);border-radius:8px;box-shadow:0 10px 30px var(--shadow);padding:4px}.history-row{padding:5px 9px;font-size:12px;font-family:var(--mono);color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;border-radius:5px;cursor:pointer}.history-row:hover{background:var(--accent-soft)}.history-row-pending{background:var(--accent-soft)}.history-empty{padding:6px 9px;font-size:12px;color:var(--ink-faint);font-style:italic}.hist-hl{background:var(--hl-bg)!important;box-shadow:inset 0 0 0 1px var(--hl);border-radius:3px}.dname.hist-hl,.pcell.hist-hl,.tname.hist-hl{outline:1px solid var(--hl)}.btn.sm.toggle{padding:4px 7px;font-size:11px;font-weight:700;font-family:var(--mono)}.btn.toggle.active{color:var(--accent);border-color:var(--accent-soft);background:var(--accent-soft)}.search{display:flex;align-items:center;gap:6px;margin-left:auto}.search .btn{height:28px;display:inline-flex;align-items:center;justify-content:center}#searchInput{width:230px;height:28px}#searchInput.invalid{border-color:#e0786b}.count{color:var(--ink-faint);font-size:11px;min-width:54px;font-variant-numeric:tabular-nums}.count.has{color:var(--hl)}.count.err-count{color:#e0786b;min-width:0}.panel{background:var(--chrome);border-bottom:1px solid var(--line);padding:10px 12px;display:flex;flex-direction:column;gap:8px;flex:0 0 auto;max-width:1400px;width:100%}.panel[hidden]{display:none}.drop-zone{border:1px dashed var(--line);border-radius:7px;padding:10px 12px;background:var(--bg2);color:var(--ink-dim);font-size:12px;text-align:center}.drop-zone.drag{border-color:var(--accent);background:var(--accent-soft);color:var(--ink)}.settings-tabs{display:flex;flex-wrap:wrap;gap:6px}#settingsPanel .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:8px 16px}#settingsPanel label{display:flex;flex-direction:column;gap:3px;font-size:11px;color:var(--ink-dim);white-space:nowrap}#settingsPanel input{width:100%}#settingsPanel input#rmEmpty,#settingsPanel input#rmNull{width:90px}#settingsPanel input.rm-match{width:160px}#settingsPanel input.rm-repl{width:120px}#settingsPanel input#linkClose,#settingsPanel input#linkOpen{width:130px}#settingsPanel input.tc-pattern{width:180px}#settingsPanel input.tc-width{width:70px}#settingsPanel input#tcLowOccThreshold,#settingsPanel input#tcLowOccWidth{width:70px}#settingsPanel label.ctl-row{flex-direction:row;align-items:center}#settingsPanel input[type=checkbox]{width:auto;flex:none}.panel-row{display:flex;align-items:center;gap:10px}.panel-title{font-weight:600;font-size:12px;color:var(--ink)}.hint{color:var(--ink-faint);font-size:11px}#mainRow{display:flex;flex:1 1 auto;min-height:0;overflow:hidden}.source-pane{display:flex;flex-direction:column;min-width:160px;min-height:0;flex:0 0 40%;max-width:640px;background:var(--bg2);border-right:1px solid var(--line)}.source-pane[hidden]{display:none}#sourcePanelRight{border-right:none;border-left:1px solid var(--line)}.source-pane.source-pane-diff{flex-basis:24%;max-width:440px}.pane-resizer{flex:0 0 7px;min-width:7px;cursor:col-resize;background:0 0;position:relative;align-self:stretch}.pane-resizer::after{content:"";position:absolute;left:3px;top:0;bottom:0;width:1px;background:var(--line)}.pane-resizer.dragging::after,.pane-resizer:focus-visible::after,.pane-resizer:hover::after{left:2px;width:3px;background:var(--accent)}.pane-resizer:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}.pane-resizer[hidden]{display:none}.source-pane-title{flex:0 0 auto;padding:6px 10px;font-family:var(--mono);font-size:11px;font-weight:600;color:var(--ink-dim);background:var(--chrome);border-bottom:1px solid var(--line);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;align-items:center;gap:6px}.btn.xs{padding:1px 7px;font-size:10px;line-height:1.6;font-weight:600}.diff-side-save{margin-left:auto;flex:0 0 auto}.diff-side-save[hidden]{display:none}.source-pane-close{margin-left:auto;flex:0 0 auto;padding:0 6px;font-size:13px;line-height:1.7;border-color:transparent}.source-pane-close:hover{border-color:var(--accent)}.source-pane-title-actions{margin-left:auto;flex:0 0 auto;display:flex;align-items:center;gap:6px}@property --structile-render-pct{syntax:'<number>';inherits:false;initial-value:100}.source-render-btn{flex:0 0 auto;padding:0;width:16px;height:16px;border-radius:50%;border-color:transparent;display:flex;align-items:center;justify-content:center}.source-render-btn:hover{border-color:var(--accent)}.source-render-btn[hidden]{display:none}.source-render-btn:disabled{cursor:not-allowed;opacity:.6}.source-render-ring{display:block;width:11px;height:11px;border-radius:50%;--structile-render-pct:100;background:conic-gradient(var(--accent) calc(var(--structile-render-pct) * 1%),var(--line) 0);transition-property:--structile-render-pct;transition-timing-function:linear}.source-render-btn.source-render-btn-error .source-render-ring{background:var(--t-na);transition:none}.source-pre{flex:1 1 auto;margin:0;overflow:auto;padding:8px 10px;box-sizing:border-box;font-family:var(--mono);font-size:12px;line-height:1.5;color:var(--ink);white-space:pre;tab-size:2;background:var(--bg2)}.source-input,.source-pre{scrollbar-width:thin;scrollbar-color:var(--line) var(--bg2)}.source-input::-webkit-scrollbar,.source-pre::-webkit-scrollbar{width:10px;height:10px}.source-input::-webkit-scrollbar-track,.source-pre::-webkit-scrollbar-track{background:var(--bg2)}.source-input::-webkit-scrollbar-thumb,.source-pre::-webkit-scrollbar-thumb{background:var(--line);border-radius:6px;border:2px solid var(--bg2)}.source-input::-webkit-scrollbar-thumb:hover,.source-pre::-webkit-scrollbar-thumb:hover{background:var(--ink-faint)}.source-edit-wrap{position:relative;flex:1 1 auto;min-height:0}.source-edit-wrap .source-pre{position:absolute;inset:0;overflow:hidden;pointer-events:none}.source-input{position:absolute;inset:0;margin:0;border:0;resize:none;outline:0;padding:8px 10px;box-sizing:border-box;font-family:var(--mono);font-size:12px;line-height:1.5;white-space:pre;tab-size:2;overflow:auto;background:0 0;color:transparent;caret-color:var(--ink)}.source-input::selection{background:var(--accent-soft);color:var(--ink)}.source-edit-wrap.composing .source-input{color:var(--ink)}.source-edit-wrap.composing .source-pre{opacity:.35}.source-pane-status{margin-left:8px;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.03em;color:var(--t-na)}.source-pane-status[hidden]{display:none}.source-pane-editmode-label{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.03em;color:var(--t-na)}.source-pane-editmode-label[hidden]{display:none}.tok-key{color:var(--ink-dim);font-weight:600}.tok-string{color:var(--t-str)}.tok-number{color:var(--t-num)}.tok-bool{color:var(--t-bool)}.tok-null{color:var(--t-null);font-style:italic}.tok-punct{color:var(--ink-faint)}.tok-tag{color:var(--accent);font-weight:600}.tok-attr{color:var(--t-num)}.tok-comment{color:var(--ink-faint);font-style:italic}.graph-sel{outline:2px solid var(--hover-ink);outline-offset:1px;border-radius:2px;background:var(--hl-cur)!important;color:#1a1205!important}.graph-sel.diff-added,.graph-sel.diff-changed,.graph-sel.diff-removed{background:var(--hl-cur)!important}.graph-sel .pk,.graph-sel .pk::after,.graph-sel .pv,.hl.cur .pk,.hl.cur .pk::after,.hl.cur .pv{color:#1a1205!important}mark.src-sel{background:var(--accent-soft);outline:1px solid var(--accent);border-radius:2px;color:inherit}.tok-fold-bracket{color:var(--accent);font-weight:700}.src-fold{display:inline;background:var(--accent-soft);border-radius:2px;padding:0 2px;color:var(--accent)}.src-fold-caret{font-size:9px;vertical-align:1px}.source-input:read-only{caret-color:transparent}mark.src-search-hit{background:var(--hl-bg)!important;box-shadow:inset 0 0 0 1px var(--hl);border-radius:2px;color:inherit}mark.src-search-cur{background:var(--hl-cur)!important;color:#1a1205!important;border-radius:2px}.source-find-bar{flex:0 0 auto;display:flex;align-items:center;gap:6px;padding:6px 8px;background:var(--chrome);border-bottom:1px solid var(--line)}.source-find-bar[hidden]{display:none}.source-find-input{flex:1 1 auto;min-width:0;height:24px;font-size:12px;font-family:var(--mono)}.source-find-input.invalid{border-color:#e0786b}.source-find-bar .count{min-width:40px;font-size:10px}.source-find-toggle{flex:0 0 auto;padding:0 6px;font-size:13px;line-height:1.7;border-color:transparent}.source-find-toggle:hover{border-color:var(--accent)}.source-find-toggle.active{color:var(--accent);border-color:var(--accent)}#canvasWrap{flex:1 1 auto;overflow:auto;position:relative;background:radial-gradient(circle at 1px 1px,var(--dot) 1px,transparent 0) 0 0/22px 22px,var(--bg)}#canvas{position:relative;transform-origin:0 0}#splitWrap{display:none;flex:1 1 auto;overflow:hidden;min-height:0}body.structile-diff-split #canvasWrap{display:none}body.structile-diff-split #splitWrap{display:flex}.split-pane{flex:1 1 50%;min-width:0;display:flex;flex-direction:column;min-height:0}.split-pane+.split-pane{border-left:1px solid var(--line)}.split-canvas-wrap{flex:1 1 auto;overflow:auto;position:relative;min-width:0;background:radial-gradient(circle at 1px 1px,var(--dot) 1px,transparent 0) 0 0/22px 22px,var(--bg)}.split-canvas{position:relative;transform-origin:0 0}@media (max-width:760px){#splitWrap{flex-direction:column}.split-pane+.split-pane{border-left:none;border-top:1px solid var(--line)}}.box{position:absolute}.dict{border:1px solid var(--line);border-left-width:3px;border-radius:7px;overflow:hidden}.dict-header{display:flex;align-items:center;gap:6px;padding:0 9px;cursor:pointer;user-select:none;background:var(--tint-1);border-bottom:1px solid var(--tint-2)}.dict-header:hover{background:var(--tint-3)}.caret{color:var(--ink-faint);font-size:10px;width:10px;flex:0 0 auto}.dname{font-family:var(--mono);font-weight:600;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;position:relative}.dict-left{display:flex;align-items:baseline;gap:4px;flex:1 1 auto;min-width:0;overflow:hidden}.dict-left .dname{flex:0 1 auto;min-width:0;max-width:calc(100% - var(--badge-space,0px))}.badge{font-family:var(--mono);color:var(--ink-faint);font-size:11px;flex:0 0 auto;min-width:max-content;position:relative}.prim{border:1px solid var(--line);border-radius:7px;background:var(--tint-0);overflow:hidden}.pcell{display:flex;align-items:center;gap:0;padding:0 8px;overflow:hidden;white-space:nowrap;border-right:1px solid var(--tint-1);border-bottom:1px solid var(--tint-1);font-family:var(--mono);font-size:12px;position:relative}.pcell .pk{color:var(--ink-dim)}.pcell .pk::after{content:":\00a0";color:var(--ink-faint)}.pcell .pv{overflow:hidden;text-overflow:ellipsis}.pcell.marker{color:var(--ink-faint);font-style:italic;justify-content:center;cursor:pointer}.t-str{color:var(--t-str)}.t-num{color:var(--t-num)}.t-bool{color:var(--t-bool)}.t-null{color:var(--t-null);font-style:italic}.t-na{color:var(--t-na);font-weight:600}.structile-link{color:var(--accent)!important;text-decoration:underline;text-decoration-style:dashed;cursor:pointer}.structile-link:hover{text-decoration-style:solid}table.dtable td.t-container{color:var(--accent);cursor:pointer;text-align:center;font-weight:600}table.dtable td.t-container:hover{background:var(--tint-3)}table.dtable td.t-container.active{background:var(--accent-soft)}.overlay.detached-panel,.overlay.large-prim,.overlay.large-table,.overlay.peek,.table-box{position:absolute;border:1px solid var(--line);border-radius:7px;background:var(--tbl);overflow:hidden}.table-box{border-left-width:3px}.overlay{box-shadow:0 10px 34px var(--shadow)}.overlay.large-prim,.overlay.large-table,.overlay.peek{border-color:var(--accent-soft)}.overlay.detached-panel{border:1px dashed var(--accent)}.ttool{display:flex;align-items:center;gap:8px;padding:0 6px 0 9px;cursor:pointer;user-select:none;background:var(--tbl-head);border-bottom:1px solid var(--tbl-line)}.ttool:hover{background:var(--tint-3)}.ttool-left{display:flex;align-items:baseline;gap:8px;flex:1 1 auto;min-width:0;overflow:hidden}.tname{font-family:var(--mono);font-weight:600;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:0 0 auto;position:relative}.tdim{font-family:var(--mono);font-size:11px;color:var(--ink-faint);flex:0 0 auto;position:relative}.ttool-btns{display:flex;gap:3px;flex:0 0 auto}.tbtn{background:0 0;border:1px solid transparent;color:var(--ink-dim);width:22px;height:20px;border-radius:5px;cursor:pointer;font-size:12px;line-height:1;display:flex;align-items:center;justify-content:center;padding:0}.tbtn:hover{background:var(--tint-4);color:var(--hover-ink);border-color:var(--line)}.tbtn.active{color:var(--accent);border-color:var(--accent-soft);background:var(--accent-soft)}.tscroll{overflow:auto}table.dtable{border-collapse:collapse;font-family:var(--mono);font-size:12px;table-layout:fixed}table.dtable td,table.dtable th{border-right:1px solid var(--tbl-line);border-bottom:1px solid var(--tbl-line);padding:0 8px;height:22px;line-height:22px;white-space:nowrap;overflow:hidden;text-align:left;max-width:0}table.dtable th{background:var(--tbl-head);color:var(--ink-dim);font-weight:600;position:sticky;top:0;z-index:1}table.dtable td{color:var(--ink);position:relative}table.dtable td.marker,table.dtable th.marker{color:var(--ink-faint);text-align:center;background:var(--tint-0)}table.dtable td.rowmarker{color:var(--ink-faint);text-align:center;font-style:italic;background:var(--tint-0)}table.dtable td.empty{color:var(--ink-faint);font-style:italic;text-align:center}.zone{position:absolute;z-index:3}.zone.right{right:0;top:0;width:24px;height:100%;cursor:e-resize}.zone.bottom{left:0;bottom:0;height:20px;width:100%;cursor:s-resize}.zone.corner{right:0;bottom:0;width:28px;height:24px;cursor:se-resize}table.dtable td.marker,table.dtable td.rowmarker,table.dtable th.marker{cursor:e-resize}table.dtable td.rowmarker{cursor:s-resize}.connector{position:absolute;height:0;border-top:1px dashed var(--accent);transform-origin:0 0;pointer-events:none;z-index:55;opacity:.7}.hl{background:var(--hl-bg)!important;box-shadow:inset 0 0 0 1px var(--hl);border-radius:3px}.hl.cur{background:var(--hl-cur)!important;color:#1a1205!important;box-shadow:inset 0 0 0 1px var(--hover-ink)}.dname.hl,.pcell.hl,.tname.hl{outline:1px solid var(--hl)}.note{position:fixed;bottom:14px;left:50%;transform:translateX(-50%);background:var(--pop-bg);border:1px solid var(--accent-soft);color:var(--ink);padding:8px 14px;border-radius:8px;font-size:12px;z-index:200;box-shadow:0 8px 24px var(--shadow)}.note.warning{background:var(--diff-chg-bg);border-color:var(--diff-chg-ink)}.note .note-action{margin-left:10px;border-color:var(--diff-chg-ink)}.dname,.tname{-webkit-user-select:text;user-select:text;cursor:text}table.dtable.full td,table.dtable.full th{max-width:none;overflow:visible;text-overflow:clip}table.dtable.full td.colfixed,table.dtable.full th.colfixed{max-width:0;overflow:hidden;text-overflow:ellipsis}.editpop{position:absolute;z-index:80;min-width:80px;max-width:60vw;background:var(--pop-bg);border:1px solid var(--accent);border-radius:6px;padding:6px 9px;box-shadow:0 8px 24px var(--shadow)}.editpop-input{font-family:var(--mono);font-size:12px;color:var(--ink);background:var(--bg);border:1px solid var(--accent-soft);border-radius:4px;padding:3px 6px;width:220px;max-width:56vw;box-sizing:border-box}.editpop-input:focus{outline:0;border-color:var(--accent)}.editpop-err{margin-top:4px;font-size:11px;color:#e0786b;max-width:40vw}.about-pop{position:fixed;z-index:300;width:250px;background:var(--pop-bg);border:1px solid var(--accent);border-radius:8px;padding:10px 12px;font-size:12px;color:var(--ink);box-shadow:0 8px 24px var(--shadow)}.about-pop h4{margin:0 0 6px;font-size:13px;color:var(--ink);font-weight:600}.about-pop .tagline{color:var(--ink-dim);font-size:11px;font-style:italic;margin:-2px 0 6px}.about-pop .desc{color:var(--ink-dim);margin-bottom:8px;line-height:1.4}.about-pop .row{display:flex;justify-content:space-between;gap:10px;padding:2px 0;color:var(--ink-faint)}.about-pop .row b{color:var(--ink);font-weight:600;font-family:var(--mono);-webkit-user-select:text;user-select:text}</style>
8
+ </head>
9
+ <body>
10
+ <header id="bar">
11
+ <button type="button" id="fileNameLabel" class="filename-label">Load data…</button>
12
+ <input id="fileInput" type="file" accept=".json,.py,.xml,.html,.htm,.ini,.toml,.yaml,.yml,.csv,.js,application/json" multiple hidden>
13
+ <button id="diffBtn" class="btn" title="Compare the current data with another file" data-embed-hide data-diff-hide hidden>Diff…</button>
14
+ <input id="diffIntakeInput" type="file" accept=".json,.py,.xml,.html,.htm,.ini,.toml,.yaml,.yml,.csv,.js" multiple hidden>
15
+ <span class="split-btn">
16
+ <button id="undoBtn" class="btn sm" title="Undo (Ctrl+Z)" disabled>↶ Undo</button>
17
+ <button id="undoMenuBtn" class="btn sm split-caret" title="Undo history" disabled>▾</button>
18
+ </span>
19
+ <span class="split-btn">
20
+ <button id="redoBtn" class="btn sm" title="Redo (Ctrl+Y)" disabled>↷ Redo</button>
21
+ <button id="redoMenuBtn" class="btn sm split-caret" title="Redo history" disabled>▾</button>
22
+ </span>
23
+ <button id="saveBtn" class="btn sm" title="Save the edited data (Ctrl+S)" disabled data-host-save-hide data-diff-hide>Save</button>
24
+ <button id="saveAsBtn" class="btn sm" title="Save a copy under a new name" data-embed-only data-host-save-hide data-diff-hide>Save As…</button>
25
+ <button id="hostSaveBtn" class="btn sm" title="Save the edited data" disabled data-host-save-show data-diff-hide>Save</button>
26
+ <button id="pasteBtn" class="btn" data-embed-hide>Paste…</button>
27
+ <span class="sep"></span>
28
+ <button id="saveViewBtn" class="btn" data-embed-hide>Save view</button>
29
+ <button id="loadViewBtn" class="btn" data-embed-hide>Load view</button>
30
+ <input id="viewInput" type="file" accept=".json,application/json" hidden>
31
+ <button id="settingsBtn" class="btn toggle" aria-pressed="false" data-settings-panel-hide>Settings</button>
32
+ <!-- data-embed-hide: without it, this sep sits right next to the one
33
+ above once every embed-hidden button between them (Save view/Load
34
+ view/Settings) vanishes, showing two separators in a row with
35
+ nothing between them — one is enough. -->
36
+ <span class="sep" data-embed-hide></span>
37
+ <div class="search">
38
+ <input id="searchInput" type="text" placeholder="Search keys, values, cells…" title="Searches the DATA (graph keys/values/cells) — for the raw source TEXT, use the 🔍 button inside the source pane" spellcheck="false">
39
+ <span class="split-btn">
40
+ <button id="caseBtn" class="btn sm toggle" title="Match case">Aa</button>
41
+ <button id="regexBtn" class="btn sm toggle" title="Use regular expression">.*</button>
42
+ </span>
43
+ <span id="searchCount" class="count"></span>
44
+ <span class="split-btn">
45
+ <button id="prevMatch" class="btn sm" title="Previous match">‹</button>
46
+ <button id="nextMatch" class="btn sm" title="Next match (Enter)">›</button>
47
+ </span>
48
+ </div>
49
+ <span class="sep"></span>
50
+ <button id="sourceToggleBtn" class="btn sm toggle" title="Show/hide raw source text" aria-pressed="false" data-source-view-hide>{ } Source</button>
51
+ <button id="themeBtn" class="btn sm" title="Toggle theme">☀</button>
52
+ <button id="aboutBtn" class="btn sm" title="About / version info" data-embed-hide>?</button>
53
+ </header>
54
+
55
+ <!-- source_code_view_claude.md Phase 4: Paste… now goes straight through
56
+ #sourcePanelInput (see the pasteBtn click handler) instead of a
57
+ separate paste textarea — this panel's only remaining job is the
58
+ XML/HTML <-> interpreter pairing hint (showPendingPairHint), needed
59
+ whenever pasted/dropped structured data arrives without its matching
60
+ interpreter (or vice versa) already loaded. -->
61
+ <div id="pastePanel" class="panel" hidden data-embed-hide>
62
+ <div id="pendingPairHint" class="panel-row" hidden>
63
+ <span id="pendingPairMsg" class="hint"></span>
64
+ <button type="button" id="pendingPairBtn" class="btn sm">Choose file…</button>
65
+ <input id="pendingPairFile" type="file" hidden>
66
+ <button type="button" id="pendingPairCancel" class="btn sm ghost" title="Cancel pairing">Cancel</button>
67
+ </div>
68
+ </div>
69
+
70
+ <div id="diffIntakePanel" class="panel" hidden data-embed-hide>
71
+ <div class="panel-title">Assembling a diff</div>
72
+ <div id="diffIntakeStatus" class="hint"></div>
73
+ <div id="diffIntakeDrop" class="drop-zone">Drop the remaining data file and/or interpreter(s) here</div>
74
+ <div class="panel-row">
75
+ <button type="button" id="diffIntakeAddBtn" class="btn sm">Choose file(s)…</button>
76
+ <button type="button" id="diffIntakeCancelBtn" class="btn sm ghost" title="Cancel this diff">Cancel</button>
77
+ </div>
78
+ </div>
79
+
80
+ <div id="settingsPanel" class="panel" hidden data-settings-panel-hide>
81
+ <div class="panel-row">
82
+ <button id="exportSettings" class="btn ghost" title="Export current values to a settings JSON file"><span class="btn-icon export">&#8682;</span>Export settings</button>
83
+ <button id="loadSettings" class="btn ghost" title="Load current values from a settings JSON file"><span class="btn-icon load">&#8681;</span>Load settings</button>
84
+ <button id="resetSettings" class="btn ghost" title="Reset current values to built-in defaults"><span class="btn-icon reset">&#8634;</span>Reset defaults</button>
85
+ <button id="setDefaultSettingsBtn" class="btn ghost" data-embed-only title="Save these values as the default for new views this host creates from now on">Set as default</button>
86
+ <input id="settingsInput" type="file" accept=".json,application/json" hidden>
87
+ <span class="hint">Structural changes re-pack the layout; the rest just re-render.</span>
88
+ </div>
89
+ <div class="hint">Current values shown below are applied immediately. Load settings replaces these values; reset restores the built-in defaults.</div>
90
+ <div class="settings-tabs" id="settingsTabs"><!-- generated by buildSettingsPanel() from SETTINGS_SCHEMA --></div>
91
+ <div class="grid" id="settingsGrid"><!-- generated by buildSettingsPanel(): the active tab's inputs --></div>
92
+ <div id="settingsSpecialPanel" hidden>
93
+ <div class="hint">A dict value or table cell wrapped between this prefix and suffix, matched verbatim (delimiters included), becomes a clickable link that jumps to whichever dict/table elsewhere in this document has that exact same name. Blank prefix = off. Saved automatically, and round-trips through Export/Load settings.</div>
94
+ <div id="linkSettingsPanel"><!-- generated by buildLinkSettingsPanel() --></div>
95
+ <div class="hint">Override how specific values are displayed — cosmetic only, doesn't change the underlying data. Blank = no override. Saved automatically, and round-trips through Export/Load settings.</div>
96
+ <div id="renderMapPanel"><!-- generated by buildRenderMapPanel() --></div>
97
+ </div>
98
+ <div id="settingsTableColPanel" hidden>
99
+ <div class="hint">Detached-view-only column width overrides (the &#10688; button in a table's toolbar). A rule forces every column whose header name matches its regex to a fixed width, in characters — first matching rule wins. Saved automatically, and round-trips through Export/Load settings.</div>
100
+ <div id="tableColRulesPanel"><!-- generated by buildTableColRulesPanel() --></div>
101
+ <div class="panel-row">
102
+ <label class="ctl">Low-occupancy threshold (0–1) &#8594; <input type="number" id="tcLowOccThreshold" min="0" max="1" step="0.01"></label>
103
+ <label class="ctl">Low-occupancy width (chars) &#8594; <input type="number" id="tcLowOccWidth" min="1" step="1"></label>
104
+ </div>
105
+ <div class="hint">A column with no rule match whose distinct-value count is under this fraction of its row count (e.g. a status/category/flag column) gets the width above instead of its natural full width. 0 disables.</div>
106
+ </div>
107
+ </div>
108
+
109
+ <div id="diffHeader" class="diff-header" hidden></div>
110
+ <div id="mainRow">
111
+ <div id="sourcePanelLeft" class="source-pane source-pane-diff" hidden>
112
+ <div class="source-pane-title" id="sourcePanelLeftTitle"><span id="sourcePanelLeftEditLabel" class="source-pane-editmode-label" hidden>Original</span><button type="button" id="diffSaveLeftBtn" class="btn xs diff-side-save" title="Save left side (Ctrl+S while focused)" hidden>Save</button><span id="sourcePanelLeftStatus" class="source-pane-status" role="status" aria-live="polite" hidden></span><span class="source-pane-title-actions"><button type="button" id="sourceFindToggleBtnLeft" class="btn xs ghost source-find-toggle" title="Find in this source (Ctrl+F while focused)">&#128269;</button><button type="button" id="sourcePanelLeftCloseBtn" class="btn xs ghost source-pane-close" title="Close source pane">&times;</button></span></div>
113
+ <div class="source-find-bar" id="sourceFindBarLeft" hidden>
114
+ <input type="text" id="sourceFindInputLeft" class="source-find-input" placeholder="Find in source…" spellcheck="false">
115
+ <span class="split-btn">
116
+ <button type="button" id="sourceFindCaseLeft" class="btn sm toggle" title="Match case">Aa</button>
117
+ <button type="button" id="sourceFindRegexLeft" class="btn sm toggle" title="Use regular expression">.*</button>
118
+ </span>
119
+ <span id="sourceFindCountLeft" class="count"></span>
120
+ <span class="split-btn">
121
+ <button type="button" id="sourceFindPrevLeft" class="btn sm" title="Previous match (Shift+Enter)">&#8249;</button>
122
+ <button type="button" id="sourceFindNextLeft" class="btn sm" title="Next match (Enter)">&#8250;</button>
123
+ </span>
124
+ <button type="button" id="sourceFindCloseLeft" class="btn xs ghost" title="Close find bar (Esc)">&times;</button>
125
+ </div>
126
+ <div class="source-edit-wrap">
127
+ <pre class="source-pre" aria-hidden="true"><code id="sourcePanelLeftCode"></code></pre>
128
+ <textarea id="sourcePanelLeftInput" class="source-input" spellcheck="false" autocomplete="off" autocapitalize="off" autocorrect="off" aria-label="Left source text"></textarea>
129
+ </div>
130
+ </div>
131
+ <div id="sourcePanel" class="source-pane" hidden>
132
+ <div class="source-pane-title"><button type="button" id="sourceEditBtn" class="btn xs" title="Edit — opens a diff view: original on the left, your edits on the right">Edit</button><span id="sourcePanelStatus" class="source-pane-status" role="status" aria-live="polite" hidden></span><span class="source-pane-title-actions"><button type="button" id="sourceFindToggleBtnSingle" class="btn xs ghost source-find-toggle" title="Find in source (Ctrl+F while focused)">&#128269;</button><button type="button" id="sourceRenderBtn" class="btn ghost source-render-btn" title="Render pending changes now" hidden><span id="sourceRenderRing" class="source-render-ring" aria-hidden="true"></span></button><button type="button" id="sourcePanelCloseBtn" class="btn xs ghost source-pane-close" title="Close source pane">&times;</button></span></div>
133
+ <div class="source-find-bar" id="sourceFindBarSingle" hidden>
134
+ <input type="text" id="sourceFindInputSingle" class="source-find-input" placeholder="Find in source…" spellcheck="false">
135
+ <span class="split-btn">
136
+ <button type="button" id="sourceFindCaseSingle" class="btn sm toggle" title="Match case">Aa</button>
137
+ <button type="button" id="sourceFindRegexSingle" class="btn sm toggle" title="Use regular expression">.*</button>
138
+ </span>
139
+ <span id="sourceFindCountSingle" class="count"></span>
140
+ <span class="split-btn">
141
+ <button type="button" id="sourceFindPrevSingle" class="btn sm" title="Previous match (Shift+Enter)">&#8249;</button>
142
+ <button type="button" id="sourceFindNextSingle" class="btn sm" title="Next match (Enter)">&#8250;</button>
143
+ </span>
144
+ <button type="button" id="sourceFindCloseSingle" class="btn xs ghost" title="Close find bar (Esc)">&times;</button>
145
+ </div>
146
+ <div class="source-edit-wrap">
147
+ <pre class="source-pre" aria-hidden="true"><code id="sourcePanelCode"></code></pre>
148
+ <textarea id="sourcePanelInput" class="source-input" spellcheck="false" autocomplete="off" autocapitalize="off" autocorrect="off" aria-label="Source text" readonly></textarea>
149
+ </div>
150
+ </div>
151
+ <div id="paneResizerLeft" class="pane-resizer" role="separator" aria-orientation="vertical" aria-label="Resize source pane" tabindex="0" hidden></div>
152
+ <div id="canvasWrap"><div id="canvas"></div></div>
153
+ <div id="splitWrap">
154
+ <div class="split-pane" id="splitPaneLeft">
155
+ <div class="split-canvas-wrap" id="canvasWrapLeft"><div id="canvasLeft" class="split-canvas"></div></div>
156
+ </div>
157
+ <div class="split-pane" id="splitPaneRight">
158
+ <div class="split-canvas-wrap" id="canvasWrapRight"><div id="canvasRight" class="split-canvas"></div></div>
159
+ </div>
160
+ </div>
161
+ <div id="paneResizerRight" class="pane-resizer" role="separator" aria-orientation="vertical" aria-label="Resize right source pane" tabindex="0" hidden></div>
162
+ <div id="sourcePanelRight" class="source-pane source-pane-diff" hidden>
163
+ <div class="source-pane-title" id="sourcePanelRightTitle"><span id="sourcePanelRightEditLabel" class="source-pane-editmode-label" hidden>Editing</span><button type="button" id="diffSaveRightBtn" class="btn xs diff-side-save" title="Save right side (Ctrl+S while focused)" hidden>Save</button><span id="sourcePanelRightStatus" class="source-pane-status" role="status" aria-live="polite" hidden></span><span class="source-pane-title-actions"><button type="button" id="sourceFindToggleBtnRight" class="btn xs ghost source-find-toggle" title="Find in this source (Ctrl+F while focused)">&#128269;</button><button type="button" id="sourceRenderBtnRight" class="btn ghost source-render-btn" title="Render pending changes now" hidden><span id="sourceRenderRingRight" class="source-render-ring" aria-hidden="true"></span></button><button type="button" id="sourcePanelRightCloseBtn" class="btn xs ghost source-pane-close" title="Close source pane">&times;</button></span></div>
164
+ <div class="source-find-bar" id="sourceFindBarRight" hidden>
165
+ <input type="text" id="sourceFindInputRight" class="source-find-input" placeholder="Find in source…" spellcheck="false">
166
+ <span class="split-btn">
167
+ <button type="button" id="sourceFindCaseRight" class="btn sm toggle" title="Match case">Aa</button>
168
+ <button type="button" id="sourceFindRegexRight" class="btn sm toggle" title="Use regular expression">.*</button>
169
+ </span>
170
+ <span id="sourceFindCountRight" class="count"></span>
171
+ <span class="split-btn">
172
+ <button type="button" id="sourceFindPrevRight" class="btn sm" title="Previous match (Shift+Enter)">&#8249;</button>
173
+ <button type="button" id="sourceFindNextRight" class="btn sm" title="Next match (Enter)">&#8250;</button>
174
+ </span>
175
+ <button type="button" id="sourceFindCloseRight" class="btn xs ghost" title="Close find bar (Esc)">&times;</button>
176
+ </div>
177
+ <div class="source-edit-wrap">
178
+ <pre class="source-pre" aria-hidden="true"><code id="sourcePanelRightCode"></code></pre>
179
+ <textarea id="sourcePanelRightInput" class="source-input" spellcheck="false" autocomplete="off" autocapitalize="off" autocorrect="off" aria-label="Right source text"></textarea>
180
+ </div>
181
+ </div>
182
+ </div>
183
+ <div id="statusNote" class="note" role="status" aria-live="polite" hidden></div>
184
+
185
+ <script>
186
+ "use strict";const e=document.currentScript&&document.currentScript.textContent||"",t="6.0.0",n="Daniel Tuzes",o="2026-08-05",r={ROW_H:23,CELL_H:22,TITLE_H:26,PAD:8,CELL_PAD_X:8,TCELL_PAD_X:8,BORDER:1,MINCOL:34,MAXCOL:230,BTN:22},l=[{section:"Text limits"},{key:"nameMax",label:"nameMax (key chars)",default:14,min:1,step:1,structural:!0},{key:"valMax",label:"valMax (value chars)",default:14,min:1,step:1,structural:!0},{key:"headerLabelMax",label:"headerLabelMax — outer title chars",default:32,min:3,step:1,structural:!0},{section:"Table windows"},{key:"n",label:"n — compact columns",default:4,min:1,step:1,structural:!0},{key:"m",label:"m — compact rows",default:6,min:1,step:1,structural:!0},{key:"N",label:"N — peek/expand columns",default:12,min:1,step:1,structural:!1},{key:"M",label:"M — peek/expand rows",default:12,min:1,step:1,structural:!1},{key:"detCols",label:"detCols — detached max columns",default:12,min:1,step:1,structural:!1},{key:"detRows",label:"detRows — detached max rows",default:25,min:1,step:1,structural:!1},{key:"cellContainerBadges",label:"Show dict/table values in table cells as clickable badges",type:"checkbox",default:!0,structural:!0},{section:"Interaction"},{key:"dwellMs",label:"dwellMs — peek delay",default:150,min:0,step:50,structural:!1},{key:"sourceAutoRenderMs",label:"sourceAutoRenderMs — auto-render delay after source edits",default:1e3,min:0,step:100,structural:!1},{section:"Layout"},{key:"gap",label:"gap — box spacing (px)",default:10,min:0,step:1,structural:!0},{key:"kvRows",label:"kvRows (N) — values per column before wrapping",default:7,min:1,step:1,structural:!0},{key:"kvCols",label:"kvCols (M) — max columns before expand/detach",default:5,min:1,step:1,structural:!0},{key:"maxWidthFrac",label:"maxWidthFrac — box width cap, × screen width (0 = off)",default:.6667,min:0,step:.05,round:!1,structural:!0}],i=new Map,s={},a=[],c=new Set;for(const e of l)e.section||(i.set(e.key,e),s[e.key]=e.default,a.push(e.key),e.structural&&c.add(e.key));let d=Object.assign({},s),u=Object.assign({},d),f={forNull:null,forEmpty:null,values:{}},h={open:"",close:""},p={rules:[],lowOccupancyThreshold:.1,lowOccupancyWidth:8},m="canvas",g="canvasWrap";function y(){return document.getElementById(m)}function v(){return document.getElementById(g)}let w=null,b=new Map,x=null,k="data",E=!0,S=!1;function L(){const e=document.getElementById("diffBtn");e&&(e.hidden=!S)}let C=null,I=null;const M={collapsed:new Set,minimized:new Set,large:new Set,detached:new Set};let T=1;function O(){return T++}let B=new Map,_=new Map,R=new Map,P=new Map,N=[],A=[],j=!1,W=null,H=null,D=-1,z=new Map;const F=document.createElement("canvas").getContext("2d"),K='12px ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace';F.font=K;const q=document.createElement("canvas").getContext("2d"),X='600 12px ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace';function U(e){return F.measureText(String(e)).width}function V(e){return q.measureText(String(e)).width}function Y(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"bigint"==typeof e}function J(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof Set)}function $(e){return Y(e)?"primitive":Array.isArray(e)?"table":J(e)||e instanceof Set?"dict":"primitive"}function G(e){return null===e?f.forNull:""===e?f.forEmpty:"string"==typeof e&&Object.prototype.hasOwnProperty.call(f.values,e)?f.values[e]:null}function Z(e){const t=G(e);if(null!=t)return t;if(null===e)return"null";if("string"==typeof e)return e;if("boolean"==typeof e)return e?"true":"false";if("number"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch(t){return String(e)}}function Q(e,t,n,o){const r=e._cellDims||(e._cellDims=new Map),l=t+":"+n,i=r.get(l);if(i&&i.rawValue===o)return i;const s=nt(o),a={rawValue:o,totalRows:s.totalRows,totalCols:s.totalCols};return r.set(l,a),a}function ee(e,t,n,o){if(o instanceof Set)return"("+o.size+")";if(J(o))return"{"+Object.keys(o).length+"}";const r=Q(e,t,n,o);return"["+r.totalRows+"×"+r.totalCols+"]"}function te(e){if(null!=G(e))return"t-na";if(null===e)return"t-null";const t=typeof e;return"number"===t||"bigint"===t?"t-num":"boolean"===t?"t-bool":"t-str"}function ne(){return!!h.open}function oe(e){if(!ne()||"string"!=typeof e)return!1;const t=h.open,n=h.close;return!(e.length<t.length+n.length)&&(!!e.startsWith(t)&&!(n&&!e.endsWith(n)))}function re(e){for(const t of B.values())if(!t.isRoot&&("dict"===t.kind||"table"===t.kind)&&t.displayLabel===e)return t;return null}function le(e){if(!oe(e))return null;const t=re(e);return t?t.id:null}function ie(e){return e.map(e=>String(e).replace(/~/g,"~0").replace(/\//g,"~1")).join("/")}function se(e,t){if(e.length>=t.length)return!1;for(let n=0;n<e.length;n++)if(String(e[n])!==String(t[n]))return!1;return!0}function ae(e,t,n){const o={};for(const r of Object.keys(e))o[String(r)===String(t)?n:r]=e[r];for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function ce(e){return(e=String(e)).length<=u.nameMax?e:e.slice(0,Math.max(1,u.nameMax-1))+"…"}function de(e){return!/\s/.test(e)&&/[:/._\-@]/.test(e)}function ue(e){const t=/^(-)?(\d)(?:\.(\d+))?e([+-]\d+)$/i.exec(e.toExponential());if(!t)return String(e).slice(0,u.valMax);const n=t[1]||"",o=("E"+parseInt(t[4],10)).length;let r=Math.min(100,Math.max(0,u.valMax-n.length-o-2));for(;r>=0;r--){const t=/^(-)?(\d)(?:\.(\d+))?e([+-]\d+)$/i.exec(e.toExponential(r));if(!t)continue;const n=t[1]||"",o=t[2],l=t[3]||"",i=n+o+(l?"."+l:"")+("E"+parseInt(t[4],10));if(i.length<=u.valMax)return i}const l=/^(-)?(\d)e([+-]\d+)$/i.exec(e.toExponential(0));return(l?(l[1]||"")+l[2]+"E"+parseInt(l[3],10):String(e)).slice(0,Math.max(1,u.valMax))}function fe(e){const t=String(e);return t.length<=u.valMax?t:Number.isFinite(e)?ue(e):t.slice(0,u.valMax)}function he(e){const t=e.toString();if(t.length<=u.valMax)return t;const n=e<0n,o=n?t.slice(1):t,r=o.length-1;let l=Math.min(o.length,Math.max(1,u.valMax-(n?1:0)-("E"+r).length-1));for(;l>=1;l--){let e=o.slice(0,l),t=r;if(l<o.length&&o.charCodeAt(l)-48>=5){let n=(BigInt(e)+1n).toString();n.length>e.length&&(n=n.slice(0,l),t+=1),e=n}const i=(n?"-":"")+(e.length>1?e[0]+"."+e.slice(1):e)+"E"+t;if(i.length<=u.valMax)return i}return(n?"-":"")+o[0]+"E"+r}function pe(e){if("number"==typeof e)return fe(e);if("bigint"==typeof e)return he(e);let t=Z(e);if(t.length<=u.valMax)return t;if(de(t)){const e=Math.max(2,u.valMax-1),n=Math.ceil(e/2),o=Math.floor(e/2);return t.slice(0,n)+"…"+t.slice(t.length-o)}return t.slice(0,Math.max(1,u.valMax-1))+"…"}function me(e){e=String(e);const t=Math.max(1,Math.round(u.headerLabelMax||d.headerLabelMax||32));return e.length<=t?e:e.slice(0,Math.max(1,t-1))+"…"}function ge(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ye(e){return String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}q.font=X;const ve="structile-theme";function we(){const e=document.documentElement.getAttribute("data-theme");return"light"===e||"dark"===e?e:window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function be(){const e=document.getElementById("themeBtn");if(!e)return;const t=we();e.textContent="dark"===t?"☾":"☀",e.title="Switch to "+("dark"===t?"light":"dark")+" theme"}function xe(e){document.documentElement.setAttribute("data-theme",e);try{localStorage.setItem(ve,e)}catch(e){}be(),w&&Ri()}function ke(){try{const e=localStorage.getItem(ve);return"light"===e||"dark"===e?e:null}catch(e){return null}}const Ee="structile-sourcePanel";function Se(){try{return"1"===localStorage.getItem(Ee)}catch(e){return!1}}function Le(e){try{localStorage.setItem(Ee,e?"1":"0")}catch(e){}}const Ce="structile-renderMap";function Ie(){try{localStorage.setItem(Ce,JSON.stringify(f))}catch(e){}}function Me(){try{const e=JSON.parse(localStorage.getItem(Ce));if(!e||"object"!=typeof e)return;"string"==typeof e.forNull&&(f.forNull=e.forNull),"string"==typeof e.forEmpty&&(f.forEmpty=e.forEmpty),e.values&&"object"==typeof e.values&&(f.values=Object.assign({},e.values))}catch(e){}}const Te="structile-linkSettings";function Oe(){try{localStorage.setItem(Te,JSON.stringify(h))}catch(e){}}function Be(){try{const e=JSON.parse(localStorage.getItem(Te));if(!e||"object"!=typeof e)return;"string"==typeof e.open&&(h.open=e.open),"string"==typeof e.close&&(h.close=e.close)}catch(e){}}const _e="structile-tableColSettings";function Re(){try{localStorage.setItem(_e,JSON.stringify(p))}catch(e){}}function Pe(){try{const e=JSON.parse(localStorage.getItem(_e));if(!e||"object"!=typeof e)return;Array.isArray(e.rules)&&(p.rules=e.rules.filter(e=>e&&"string"==typeof e.pattern&&"number"==typeof e.width&&isFinite(e.width)).map(e=>({pattern:e.pattern,width:e.width}))),"number"==typeof e.lowOccupancyThreshold&&isFinite(e.lowOccupancyThreshold)&&(p.lowOccupancyThreshold=e.lowOccupancyThreshold),"number"==typeof e.lowOccupancyWidth&&isFinite(e.lowOccupancyWidth)&&(p.lowOccupancyWidth=e.lowOccupancyWidth)}catch(e){}}function Ne(){if(document.documentElement.setAttribute("data-theme",ke()||we()),be(),window.matchMedia){const e=window.matchMedia("(prefers-color-scheme: dark)"),t=()=>{ke()||(document.documentElement.setAttribute("data-theme",e.matches?"dark":"light"),be(),w&&Ri())};e.addEventListener?e.addEventListener("change",t):e.addListener&&e.addListener(t)}const e=document.getElementById("themeBtn");e&&e.addEventListener("click",()=>xe("dark"===we()?"light":"dark"))}function Ae(){ua=Se(),fa();const e=document.getElementById("sourceToggleBtn");e&&e.addEventListener("click",()=>je(!ua)),["sourcePanelCloseBtn","sourcePanelLeftCloseBtn","sourcePanelRightCloseBtn"].forEach(e=>{const t=document.getElementById(e);t&&t.addEventListener("click",()=>je(!1))});const t=document.getElementById("sourceEditBtn");t&&t.addEventListener("click",Sl)}function je(e){ua=e,Le(ua),fa(),e||nc(),ha(),Ri()}const We="structile-paneWidths",He={sourcePanel:"single",sourcePanelLeft:"diffLeft",sourcePanelRight:"diffRight"},De=160;function ze(){try{const e=JSON.parse(localStorage.getItem(We));return e&&"object"==typeof e?e:{}}catch(e){return{}}}function Fe(e,t){if("number"==typeof t&&isFinite(t))try{const n=ze();n[e]=t,localStorage.setItem(We,JSON.stringify(n))}catch(e){}}function Ke(e){for(const t of e){const e=document.getElementById(t);if(e&&!e.hidden)return e}return null}function qe(e,t,n){const o=document.getElementById(e);if(!o)return;let r=!1,l=0,i=0,s=null;const a=e=>{if(!s)return null;const t=parseFloat(getComputedStyle(s).maxWidth)||1/0,n=Math.max(De,Math.min(e,t));return s.style.flexBasis=n+"px",n},c=e=>{if(null==e||!s)return;const t=He[s.id];t&&Fe(t,e)},d=e=>{r&&a(i+(e.clientX-l)*n)},u=()=>{r&&(r=!1,o.classList.remove("dragging"),document.removeEventListener("pointermove",d),document.removeEventListener("pointerup",u),c(s&&parseFloat(s.style.flexBasis)),Ri())};o.addEventListener("pointerdown",e=>{s=Ke(t),s&&(r=!0,l=e.clientX,i=s.getBoundingClientRect().width,o.classList.add("dragging"),e.preventDefault(),document.addEventListener("pointermove",d),document.addEventListener("pointerup",u))}),o.addEventListener("keydown",e=>{if(s=Ke(t),!s)return;let o=0;if("ArrowLeft"===e.key)o=-20*n;else{if("ArrowRight"!==e.key)return;o=20*n}e.preventDefault(),c(a(s.getBoundingClientRect().width+o)),Ri()})}function Xe(){const e=ze(),t=(t,n)=>{const o=document.getElementById(t);o&&"number"==typeof e[n]&&(o.style.flexBasis=e[n]+"px")};t("sourcePanel","single"),t("sourcePanelLeft","diffLeft"),t("sourcePanelRight","diffRight")}function Ue(){Xe(),qe("paneResizerLeft",["sourcePanel","sourcePanelLeft"],1),qe("paneResizerRight",["sourcePanelRight"],-1)}const Ve=["#1a2230","#1b2925","#262132","#2b291d","#1e2530","#29212f","#1d2a2d","#2a2421"],Ye=["#e6ebf5","#e5f0e6","#efe7f6","#f6f0dd","#e6ecf4","#f6e8f2","#e2f0ef","#f5ebe4"];function Je(e){const t="light"===we()?Ye:Ve,n=t.length;return t[(e%n+n)%n]}function $e(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function Ge(e){return $e(e&&e.length?e.join("/"):"(root)")%360}function Ze(e){return"hsl("+Ge(e)+"deg 52% 58%)"}function Qe(e){const t=e&&e.table?e.table.mode:"empty";return"records"===t?"hsl(195deg 58% 58%)":"grid"===t?"hsl(265deg 50% 62%)":"list"===t?"hsl(145deg 45% 55%)":"hsl(40deg 50% 58%)"}function et(e){const t=e&&e.table?e.table.mode:"empty";return"records"===t?"hsl(195deg 45% 28%)":"grid"===t?"hsl(265deg 38% 30%)":"list"===t?"hsl(145deg 34% 27%)":"hsl(40deg 34% 28%)"}function tt(e,t,n){(n=n||{}).softBorder&&(e.style.borderColor=et(t)),e.style.borderLeftWidth="3px",e.style.borderLeftColor=Qe(t)}function nt(e){if(Array.isArray(e)||(e=[]),0===e.length)return{headers:null,colKeys:[],rows:[],totalRows:0,totalCols:0,mode:"empty"};const t=e.every(J),n=e.every(e=>Array.isArray(e));if(t){const t=[],n=new Set;for(const o of e)for(const e of Object.keys(o))n.has(e)||(n.add(e),t.push(e));const o=e.map(e=>t.map(t=>t in e?e[t]:null));return{headers:t,colKeys:t,rows:o,totalRows:o.length,totalCols:t.length,mode:"records"}}if(n){const t=Math.max(1,...e.map(e=>e.length));let n=null,o=0;const r=e[0],l=r.length>0&&r.every(e=>"string"==typeof e);let i=!1;for(let t=1;t<e.length&&!i;t++)for(const n of e[t])if("string"!=typeof n){i=!0;break}if(l&&i)for(n=r.slice(),o=1;n.length<t;)n.push("");const s=[];for(let n=o;n<e.length;n++){const o=e[n].slice();for(;o.length<t;)o.push(null);s.push(o)}return{headers:n,colKeys:n||Array.from({length:t},(e,t)=>String(t)),rows:s,totalRows:s.length,totalCols:t,mode:"grid",dataStart:o}}const o=e.map(e=>[e]);return{headers:null,colKeys:[""],rows:o,totalRows:o.length,totalCols:1,mode:"list"}}function ot(e,t){const n=e.table;n.sourceArr=t,"grid"===n.mode&&n.dataStart&&(n.headerRowRef=t[n.dataStart-1]),n.headers&&(n.colIds=n.colKeys.map(()=>O()),n.colIds.forEach((t,n)=>R.set(t,{node:e,col:n}))),n.cellIds=[];for(let o=0;o<n.rows.length;o++){n.cellIds.push([]);for(let r=0;r<n.totalCols;r++){const l=O();let i;n.cellIds[o].push(l),i="list"===n.mode?{parent:t,key:o}:"grid"===n.mode?{parent:t[o+(n.dataStart||0)],key:r}:{parent:t[o],key:n.colKeys[r]},P.set(l,Object.assign({node:e,r:o,c:r},i))}}}function rt(e){return null===e?"null":typeof e}function lt(e,t){return rt(e)!==rt(t)?{equal:!1,typeChanged:!0}:{equal:gi(e,t),typeChanged:!1}}function it(e,t){if(null===e)return"z";if("boolean"==typeof e)return"b:"+e;if("number"==typeof e)return"n:"+(Number.isNaN(e)?"NaN":String(e));if("bigint"==typeof e)return"i:"+e.toString();if("string"==typeof e)return"s:"+JSON.stringify(e);if(e instanceof Set){return"<<"+[...e].map(e=>it(e,t)).sort().join(",")+">>"}if(Array.isArray(e))return"["+e.map(e=>it(e,t)).join(",")+"]";if(J(e)){return"{"+Object.keys(e).sort().map(n=>JSON.stringify(n)+":"+it(e[n],t)).join(",")+"}"}return"u:"+String(e)}function st(e){if(Y(e))return"primitive";if(e instanceof Set)return"set";if(J(e))return"object";if(Array.isArray(e)){const t=nt(e);return"records"===t.mode||"grid"===t.mode?"table":"array"}return"primitive"}function at(e){const t=st(e);return"table"===t?"array":t}function ct(e,t){return e.concat([t])}function dt(e){return e.map(e=>"key"===e.t?"."+e.k:"member"===e.t?"{"+e.k+"}":"row"===e.t?"[row "+JSON.stringify(e.k)+"]":"col"===e.t?"."+e.k:"item"===e.t?"["+(null!=e.i?e.i:"+"+e.ri)+"]":"?").join("")||"(root)"}function ut(e){const t=new Map;return e.forEach((e,n)=>{t.has(e)||t.set(e,[]),t.get(e).push(n)}),t}function ft(e,t){const n=ut(t),o=new Set,r=[];for(let t=0;t<e.length;t++){const l=n.get(e[t]);let i=null;l&&l.length&&(i=l.shift(),o.add(i)),r.push({li:t,ri:i})}for(let e=0;e<t.length;e++)o.has(e)||r.push({li:null,ri:e});return r}function ht(e,t){return e||t?t&&e?"mixed":t?"orderChanged":"changed":"equal"}function pt(e){const t=e.length,n=e.map((e,t)=>t).sort((t,n)=>e[t].ri-e[n].ri),o=new Array(t);return n.forEach((e,t)=>{o[e]=t}),e.map((e,t)=>o[t]!==t)}function mt(e,t,n,o){const r="added"===e?"right":"left",l=st(t),i={status:e,path:n,kind:l};if(i[r]=t,"object"===l)i.children=Object.keys(t).sort().map(r=>mt(e,t[r],ct(n,{t:"key",k:r}),o));else if("set"===l)i.children=[...t].map(t=>mt(e,t,ct(n,{t:"member",k:it(t)}),o));else if("table"===l){const l=nt(t);i.children=l.rows.map((t,i)=>{const s=ct(n,{t:"row",k:{index:i}}),a=l.colKeys.map((n,r)=>mt(e,t[r],ct(s,{t:"col",k:n}),o)),c={status:e,path:s,kind:"row",children:a};return c[r]=Ct(l,i),c})}else"array"===l&&(i.children=t.map((t,r)=>mt(e,t,ct(n,"added"===e?{t:"item",ri:r}:{t:"item",i:r}),o)));return i}function gt(e,t,n){return mt("added",e,t,n)}function yt(e,t,n){return mt("removed",e,t,n)}function vt(e,t){return Array.from(new Set([...Object.keys(e),...Object.keys(t)])).sort()}function wt(e){return null==e?1:e instanceof Set?[...e].reduce((e,t)=>e+wt(t),0)||1:Array.isArray(e)?e.reduce((e,t)=>e+wt(t),0)||1:J(e)&&Object.keys(e).reduce((t,n)=>t+wt(e[n]),0)||1}function bt(e){if(!e)return 0;if("equal"===e.status)return 0;if(!e.children)return 1;return e.children.reduce((e,t)=>e+bt(t),0)||1}const xt=1;function kt(e,t,n,o,r){if(!n.length||!o.length)return[];const l=[];for(const i of n)for(const n of o){const o=e[i],s=t[n];if(at(o)!==at(s))continue;const a=wt(o)+wt(s)-(bt(zt(o,s,r))+1);a>0&&l.push({oldKey:i,newKey:n,savings:a})}l.sort((e,t)=>t.savings-e.savings);const i=new Set,s=new Set,a=[];for(const e of l)i.has(e.oldKey)||s.has(e.newKey)||(i.add(e.oldKey),s.add(e.newKey),a.push(e));return a}function Et(e,t,n){const o=n.path||[],r=Object.keys(e).filter(e=>!Object.prototype.hasOwnProperty.call(t,e)),l=Object.keys(t).filter(t=>!Object.prototype.hasOwnProperty.call(e,t)),i=kt(e,t,r,l,n),s=new Set(i.map(e=>e.oldKey)),a=new Map(i.map(e=>[e.newKey,e.oldKey])),c=vt(e,t).filter(e=>!s.has(e)),d=[];let u=!1;for(const r of c){const l=Object.prototype.hasOwnProperty.call(e,r),i=Object.prototype.hasOwnProperty.call(t,r),s=ct(o,{t:"key",k:r});let c;if(a.has(r)){const o=a.get(r);c=zt(e[o],t[r],Object.assign({},n,{path:s})),"equal"===c.status&&(c.status="changed"),c.renamedFrom=o,u=!0}else l&&i?(c=zt(e[r],t[r],Object.assign({},n,{path:s})),"equal"!==c.status&&(u=!0)):i?(c=gt(t[r],s,n),u=!0):(c=yt(e[r],s,n),u=!0);d.push(c)}return{status:u?"changed":"equal",path:o,left:e,right:t,kind:"object",children:d}}function St(e,t,n){const o=n.path||[],r=[...e],l=[...t],i=r.map(e=>it(e)),s=l.map(e=>it(e)),a=ft(i,s),c=[];let d=!1;for(const e of a)null!=e.li&&null!=e.ri?c.push({status:"equal",path:ct(o,{t:"member",k:i[e.li]}),left:r[e.li],right:l[e.ri],kind:st(r[e.li])}):null!=e.ri?(d=!0,c.push(gt(l[e.ri],ct(o,{t:"member",k:s[e.ri]}),n))):(d=!0,c.push(yt(r[e.li],ct(o,{t:"member",k:i[e.li]}),n)));return{status:d?"changed":"equal",path:o,left:e,right:t,kind:"set",children:c}}function Lt(e,t,n){const o=n.path||[],r=ft(e.map(e=>it(e)),t.map(e=>it(e))),l=r.filter(e=>null!=e.li&&null!=e.ri),i=pt(l),s=new Map;l.forEach((e,t)=>s.set(e.li,i[t]));const a=[];let c=!1,d=!1;for(const l of r)if(null!=l.li&&null!=l.ri){const r=s.get(l.li);r&&(d=!0);const i=ct(o,{t:"item",i:l.li,ri:l.ri}),c=zt(e[l.li],t[l.ri],Object.assign({},n,{path:i}));r&&(c.status="orderChanged",c.order={changed:!0,fromIndex:l.li,toIndex:l.ri}),a.push(c)}else null!=l.ri?(c=!0,a.push(gt(t[l.ri],ct(o,{t:"item",ri:l.ri}),n))):(c=!0,a.push(yt(e[l.li],ct(o,{t:"item",i:l.li}),n)));return{status:ht(c,d),path:o,left:e,right:t,kind:"array",children:a,order:d?{changed:!0}:void 0}}function Ct(e,t){const n={};for(let o=0;o<e.colKeys.length;o++)n[e.colKeys[o]]=e.rows[t][o];return n}function It(e,t,n){const o={};for(const r of n){const n=e.colKeys.indexOf(r);o[r]=-1===n?void 0:e.rows[t][n]}return o}function Mt(e,t){const n=new Set(e.colKeys);return e.colKeys.concat(t.colKeys.filter(e=>!n.has(e)))}function Tt(e,t){const n=e.colKeys.indexOf(t);if(-1===n)return null;const o=e.rows.map(e=>it(e[n])).sort();return it(o)}function Ot(e,t,n,o){const r=new Map,l=new Map,i=(e,t,n)=>{e.has(t)||e.set(t,[]),e.get(t).push(n)};for(const t of n)i(r,Tt(e,t),t);for(const e of o)i(l,Tt(t,e),e);const s=[];for(const t of n){const n=Tt(e,t),o=r.get(n),i=l.get(n);o&&i&&1===o.length&&1===i.length&&s.push({left:t,right:i[0]})}return s}function Bt(e,t){const n=new Map(e.colKeys.map((e,t)=>[e,t])),o=new Map(t.colKeys.map((e,t)=>[e,t])),r=e.colKeys.filter(e=>o.has(e)).map(e=>({c:e,li:n.get(e),ri:o.get(e)})).sort((e,t)=>e.li-t.li),l=pt(r),i=new Set;return r.forEach((e,t)=>{l[t]&&i.add(e.c)}),i}function _t(e,t){return Bt(e,t).size>0}function Rt(e,t,n){const o=e.colKeys.indexOf(n),r=t.colKeys.indexOf(n);if(-1===o||-1===r)return!1;const l=new Set;for(let t=0;t<e.rows.length;t++){const n=it(e.rows[t][o]);if(l.has(n))return!1;l.add(n)}const i=new Set;for(let e=0;e<t.rows.length;e++){const n=it(t.rows[e][r]);if(i.has(n))return!1;i.add(n)}return!0}function Pt(e,t,n){const o=["id","key","name"],r=o.concat(n.filter(e=>!o.includes(e)));for(const n of r)if(Rt(e,t,n))return n;return null}function Nt(e,t,n){const o=new Map,r=new Map;let l=!1;for(let t=0;t<e.rows.length;t++){const r=it(It(e,t,n));o.has(r)||o.set(r,[]),o.get(r).push(t),o.get(r).length>1&&(l=!0)}for(let e=0;e<t.rows.length;e++){const o=it(It(t,e,n));r.has(o)||r.set(o,[]),r.get(o).push(e),r.get(o).length>1&&(l=!0)}if(l)return{duplicateKeys:!0};const i=[],s=new Set;for(const[e,t]of o){const n=t[0],o=r.get(e);o&&o.length?(i.push({li:n,ri:o[0]}),s.add(o[0])):i.push({li:n,ri:null})}for(const[e,t]of r)s.has(t[0])||i.push({li:null,ri:t[0]});return i.sort((e,t)=>(null!=e.li?e.li:1e9+e.ri)-(null!=t.li?t.li:1e9+t.ri)),i}function At(e,t,n,o,r,l){const i=o.filter(e=>!n.includes(e)),s=(e,t)=>it(i.map(n=>{const o=e.colKeys.indexOf(n);return-1===o?void 0:e.rows[t][o]})),a=new Map,c=new Map;for(const t of r){const n=s(e,t);a.has(n)||a.set(n,[]),a.get(n).push(t)}for(const e of l){const n=s(t,e);c.has(n)||c.set(n,[]),c.get(n).push(e)}const d=[];for(const[e,t]of a){const n=c.get(e);1===t.length&&n&&1===n.length&&d.push({li:t[0],ri:n[0]})}return d}function jt(e,t,n,o,r){const l=At(e,t,n,o,r.filter(e=>null!=e.li&&null==e.ri).map(e=>e.li),r.filter(e=>null==e.li&&null!=e.ri).map(e=>e.ri));if(!l.length)return r;const i=new Set(l.map(e=>e.li)),s=new Set(l.map(e=>e.ri)),a=r.filter(e=>!(null!=e.li&&null==e.ri&&i.has(e.li)||null==e.li&&null!=e.ri&&s.has(e.ri)));for(const e of l)a.push({li:e.li,ri:e.ri,keyRenamed:!0});return a.sort((e,t)=>(null!=e.li?e.li:1e9+e.ri)-(null!=t.li?t.li:1e9+t.ri)),a}function Wt(e,t){if(e.rows.length!==t.rows.length)return null;const n=ft(e.rows.map((t,n)=>it(Ct(e,n))),t.rows.map((e,n)=>it(Ct(t,n))));return n.length===e.rows.length&&n.every(e=>null!=e.li&&null!=e.ri)?n:null}function Ht(e,t,n){const o=(n=n||{}).path||[],r=nt(e),l=nt(t),i=l.colKeys.filter(e=>!r.colKeys.includes(e)),s=r.colKeys.filter(e=>!l.colKeys.includes(e)),a=Ot(r,l,s,i),c=new Map(a.map(e=>[e.left,e.right])),d=Object.assign({},r,{colKeys:r.colKeys.map(e=>c.get(e)||e)}),u=Mt(d,l),f=Bt(d,l),h=f.size>0,p=l.colKeys.filter(e=>!d.colKeys.includes(e)),m=d.colKeys.filter(e=>!l.colKeys.includes(e));let g=null,y=null,v=!1,w=null;const b=(n.keyColumns||[]).map(e=>c.get(e)||e);if(b.length&&b.every(e=>d.colKeys.includes(e)&&l.colKeys.includes(e))){const e=Nt(d,l,b);e.duplicateKeys||(g=b,y="explicit-key",w=e)}if(!w){const e=Pt(d,l,u);if(e){const t=Nt(d,l,[e]);t.duplicateKeys||(g=[e],y="auto-key",w=t)}}if(!w){const e=Wt(d,l);e&&(w=e,y="canonical-reorder")}if(!w){w=ft(d.rows.map((e,t)=>it(Ct(d,t))),l.rows.map((e,t)=>it(Ct(l,t)))),y="sequence-fallback",v=!0}g&&(w=jt(d,l,g,u,w));const x=w.filter(e=>null!=e.li&&null!=e.ri),k=pt(x),E=new Map;x.forEach((e,t)=>E.set(e.li,k[t]));const S=[];let L=!1,C=!1,I=!1;for(const e of w)if(null!=e.li&&null!=e.ri){const t=g?It(d,e.li,g):{index:e.li},i=ct(o,{t:"row",k:t}),s=E.get(e.li);s&&(L=!0);const a=[];let c=!1;for(const t of u){const o=d.colKeys.indexOf(t),s=l.colKeys.indexOf(t),u=-1===o?void 0:r.rows[e.li][o],f=-1===s?void 0:l.rows[e.ri][s],h=ct(i,{t:"col",k:t}),p=zt(u,f,Object.assign({},n,{path:h}));"equal"!==p.status&&(c=!0,C=!0),a.push(p)}S.push({status:ht(c,s),path:i,left:Ct(r,e.li),right:Ct(l,e.ri),kind:"row",children:a,order:{changed:s,fromIndex:e.li,toIndex:e.ri},match:{key:t,by:y,keyRenamed:!!e.keyRenamed}})}else if(null!=e.ri){I=!0;const t=ct(o,{t:"row",k:{index:e.ri}}),r=l.colKeys.map((o,r)=>gt(l.rows[e.ri][r],ct(t,{t:"col",k:o}),n));S.push({status:"added",path:t,right:Ct(l,e.ri),kind:"row",children:r})}else{I=!0;const t=ct(o,{t:"row",k:{index:e.li}}),l=d.colKeys.map((o,l)=>yt(r.rows[e.li][l],ct(t,{t:"col",k:o}),n));S.push({status:"removed",path:t,left:Ct(r,e.li),kind:"row",children:l})}const M=x.filter(e=>e.keyRenamed).map(e=>({li:e.li,ri:e.ri,from:It(d,e.li,g),to:It(l,e.ri,g)})),T=h||L;return{status:ht(C||I||a.length>0,T),path:o,left:e,right:t,kind:"table",children:S,order:{columnsChanged:h,rowsChanged:L,canonicalColumns:u,movedColumns:f},match:{rowStrategy:y,keyColumns:g,ambiguous:v,addedColumns:p,removedColumns:m,renamedColumns:a,rowKeyRenames:M}}}function Dt(e,t,n){const o=lt(e,t);return{status:o.typeChanged?"typeChanged":o.equal?"equal":"changed",path:n,left:e,right:t,kind:"primitive"}}function zt(e,t,n){const o=(n=n||{}).path||[];if(void 0===e&&void 0===t)return{status:"equal",path:o,kind:"primitive"};if(void 0===e)return gt(t,o,n);if(void 0===t)return yt(e,o,n);const r=at(e),l=at(t);if(r!==l)return{status:"typeChanged",path:o,left:e,right:t,kind:"mixed",leftKind:r,rightKind:l};if("primitive"===r)return Dt(e,t,o);if("object"===r)return Et(e,t,n);if("set"===r)return St(e,t,n);return"table"===st(e)||"table"===st(t)?Ht(e,t,n):Lt(e,t,n)}const Ft=[{id:"D01",description:"Identical scalars and nested structures -> no differences",run(){const e=zt({a:1,b:[1,2,{c:"x"}],d:{e:!0},s:new Set(["p","q"])},{a:1,b:[1,2,{c:"x"}],d:{e:!0},s:new Set(["q","p"])});if("equal"!==e.status)throw new Error("expected equal, got "+e.status);return{pass:!0}}},{id:"D02",description:'1 vs "1", true vs 1 -> type changes, no display-text collapse',run(){const e=zt({a:1,b:!0},{a:"1",b:1});if("changed"!==e.status)throw new Error("expected changed, got "+e.status);const t=t=>e.children.find(e=>e.path[e.path.length-1].k===t);if("typeChanged"!==t("a").status)throw new Error("'a' (1 vs \"1\") should be typeChanged");if("typeChanged"!==t("b").status)throw new Error("'b' (true vs 1) should be typeChanged");return{pass:!0}}},{id:"D03",description:"Same keys, different insertion order -> no diff, no order event",run(){const e={a:1,b:2,c:3},t={c:3,a:1,b:2},n=zt(e,t);if("equal"!==n.status)throw new Error("expected equal, got "+n.status);if(n.order)throw new Error("objects must never report an order event");return{pass:!0}}},{id:"D04",description:"One key added, one removed, one changed",run(){const e=zt({keep:1,removeMe:2,changeMe:3,nested:{stay:!0}},{keep:1,changeMe:4,addMe:5,nested:{stay:!0}});if("changed"!==e.status)throw new Error("expected changed, got "+e.status);const t=e.children.filter(e=>"equal"!==e.status);if(3!==t.length)throw new Error("expected exactly 3 non-equal children, got "+t.length);const n=t=>e.children.find(e=>e.path[e.path.length-1].k===t);if("added"!==n("addMe").status)throw new Error("addMe should be added");if("removed"!==n("removeMe").status)throw new Error("removeMe should be removed");if("changed"!==n("changeMe").status)throw new Error("changeMe should be changed");if("equal"!==n("keep").status)throw new Error("keep should be equal");if("equal"!==n("nested").status)throw new Error("nested should be equal");return{pass:!0}}},{id:"D05",description:"Set order ignored; add/remove produces exactly one member event",run(){const e=zt({tags:new Set(["x","y"])},{tags:new Set(["y","x"])});if("equal"!==e.status)throw new Error("expected equal for reordered set, got "+e.status);const t=zt({tags:new Set(["x","y"])},{tags:new Set(["x","y","z"])}).children.find(e=>"tags"===e.path[e.path.length-1].k);if("changed"!==t.status)throw new Error("expected tags changed, got "+t.status);const n=t.children.filter(e=>"equal"!==e.status);if(1!==n.length)throw new Error("expected exactly one set-member event, got "+n.length);if("added"!==n[0].status)throw new Error("expected the one event to be 'added'");return{pass:!0}}},{id:"D06",description:"Same ordinary list, different order -> order difference",run(){const e=zt({items:[1,2,3]},{items:[3,2,1]}).children.find(e=>"items"===e.path[e.path.length-1].k);if("orderChanged"!==e.status)throw new Error("expected orderChanged, got "+e.status);return{pass:!0}}},{id:"D07",description:"Same table columns, different order -> column-order event, no cell changes",run(){const e=zt([{id:1,a:10,b:20}],[{b:20,id:1,a:10}]);if("table"!==e.kind)throw new Error("expected table kind, got "+e.kind);if("orderChanged"!==e.status)throw new Error("expected orderChanged, got "+e.status);if(!e.order.columnsChanged)throw new Error("expected order.columnsChanged=true");if(e.order.rowsChanged)throw new Error("rows should not be flagged as changed");if(e.children.some(e=>e.children.some(e=>"equal"!==e.status)))throw new Error("no cell should be marked changed");return{pass:!0}}},{id:"D08",description:"Same keyed rows, different order -> row-order event, no cell changes",run(){const e=zt([{id:1,value:"a"},{id:2,value:"b"}],[{id:2,value:"b"},{id:1,value:"a"}]);if("orderChanged"!==e.status)throw new Error("expected orderChanged, got "+e.status);if(!e.order.rowsChanged)throw new Error("expected order.rowsChanged=true");if(e.order.columnsChanged)throw new Error("columns should not be flagged as changed");if(e.children.some(e=>e.children.some(e=>"equal"!==e.status)))throw new Error("no cell should be marked changed");if("auto-key"!==e.match.rowStrategy)throw new Error("expected auto-detected 'id' key, got strategy "+e.match.rowStrategy);return{pass:!0}}},{id:"D09",description:"Keyed row moves and one cell changes -> order event + exactly one changed cell",run(){const e=zt([{id:1,value:"a"},{id:2,value:"b"}],[{id:2,value:"B"},{id:1,value:"a"}]);if(!e.order.rowsChanged)throw new Error("expected rowsChanged=true");if("mixed"!==e.status)throw new Error("expected mixed status, got "+e.status);let t=0;for(const n of e.children)for(const e of n.children)"equal"!==e.status&&t++;if(1!==t)throw new Error("expected exactly 1 changed cell, got "+t);return{pass:!0}}},{id:"D10",description:"Added/removed rows and columns don't mark unrelated cells changed",run(){const e=zt([{id:1,a:1},{id:2,a:2}],[{id:1,a:1,b:9},{id:3,a:3}]);if(!e.match.addedColumns.includes("b"))throw new Error("expected column 'b' detected as added");if(1!==e.children.filter(e=>"removed"===e.status).length)throw new Error("expected exactly one removed row (id=2)");if(1!==e.children.filter(e=>"added"===e.status).length)throw new Error("expected exactly one added row (id=3)");if("equal"!==e.children.find(e=>e.left&&1===e.left.id).children.find(e=>"a"===e.path[e.path.length-1].k).status)throw new Error("unrelated cell 'a' on row id=1 must stay equal despite column 'b' being added");return{pass:!0}}},{id:"D11",description:"Duplicate/unkeyed rows fall back deterministically with an ambiguous marker",run(){const e=zt([{x:1,y:1},{x:1,y:1},{x:2,y:2}],[{x:1,y:1},{x:9,y:9},{x:2,y:2}]);if("sequence-fallback"!==e.match.rowStrategy)throw new Error("expected sequence-fallback strategy, got "+e.match.rowStrategy);if(!e.match.ambiguous)throw new Error("expected match.ambiguous=true");return{pass:!0}}},{id:"D12",description:"Large integers/BigInts compare by full value, not display text",run(){const e=12345678901234567890n;if("equal"!==zt({v:e},{v:12345678901234567890n}).children[0].status)throw new Error("equal bigints should compare equal");const t=zt({v:e},{v:e+1n}).children[0];if("changed"!==t.status)throw new Error("differing bigints should compare changed, got "+t.status);const n=zt({v:e},{v:Number(e)}).children[0];if("typeChanged"!==n.status)throw new Error("bigint vs number must be typeChanged, got "+n.status);return{pass:!0}}},{id:"D13",description:"Swapping left/right inverts added/removed and old/new, keeps matches stable",run(){const e=[{id:1,value:"a"},{id:2,value:"b"}],t=[{id:2,value:"B"},{id:1,value:"a"}],n=zt(e,t),o=zt(t,e);if(n.order.rowsChanged!==o.order.rowsChanged)throw new Error("row-order flag should be symmetric");const r=[].concat(...n.children.map(e=>e.children)).find(e=>"equal"!==e.status),l=[].concat(...o.children.map(e=>e.children)).find(e=>"equal"!==e.status);if(!r||!l)throw new Error("both directions should report the changed cell");if(r.left!==l.right||r.right!==l.left)throw new Error("old/new should invert when swapped");return{pass:!0}}},{id:"D14",description:"Repeated runs produce identical diff metadata",run(){const e=[{id:2,value:"b"},{id:1,value:"a"}],t=[{id:1,value:"a"},{id:2,value:"B"}],n=e=>JSON.stringify(e,(e,t)=>"bigint"==typeof t?t.toString()+"n":t);if(n(zt(e,t))!=n(zt(e,t)))throw new Error("two runs over identical input produced different diff metadata");return{pass:!0}}},{id:"T01",description:"An unambiguous table column rename is one amber header change",run(){const e=zt([{id:1,old_name:"x"},{id:2,old_name:"y"}],[{id:1,new_name:"x"},{id:2,new_name:"y"}]);if("changed"!==e.status)throw new Error("column rename should mark the table changed");if(e.match.addedColumns.length||e.match.removedColumns.length)throw new Error("renamed column must not remain add/remove noise");if(1!==e.match.renamedColumns.length||"old_name"!==e.match.renamedColumns[0].left||"new_name"!==e.match.renamedColumns[0].right)throw new Error("expected old_name -> new_name rename metadata");if(e.children.some(e=>e.children.some(e=>"equal"!==e.status)))throw new Error("a header-only rename must not mark its unchanged cells");const t=[],n=[],o=Kl(e,[],t,"left"),r=Kl(e,[],n,"right");if(!("old_name"in o[0])||!("new_name"in r[0]))throw new Error("split panes must retain their source header names");if(!t.some(e=>"colHeader"===e.t&&1===e.col&&"diff-changed"===e.cls)||!n.some(e=>"colHeader"===e.t&&1===e.col&&"diff-changed"===e.cls))throw new Error("renamed header should be amber in both panes");return{pass:!0}}},{id:"S01",description:"Split dict placeholders repeat values, strike only the missing side, and keep changes amber",run(){const e=zt({removed:1,changed:2},{added:3,changed:4}),t=[],n=[],o=Kl(e,[],t,"left"),r=Kl(e,[],n,"right");if(3!==o.added||1!==r.removed)throw new Error("missing dict values must repeat the real counterpart, not null");const l=(e,t)=>e.find(e=>"item"===e.t&&1===e.path.length&&e.path[0]===t),i=l(t,"added"),s=l(n,"added"),a=l(t,"removed"),c=l(n,"removed");if(!i||"diff-removed"!==i.cls||!i.strike||!s||"diff-added"!==s.cls||s.strike)throw new Error("right-only dict entry colors/strike are wrong");if(!a||"diff-removed"!==a.cls||a.strike||!c||"diff-added"!==c.cls||!c.strike)throw new Error("left-only dict entry colors/strike are wrong");if("diff-changed"!==l(t,"changed").cls||"diff-changed"!==l(n,"changed").cls)throw new Error("two-sided changed dict values must be amber in both panes");return{pass:!0}}},{id:"S02",description:"Split table rows/columns repeat and strike missing counterparts while changed cells stay amber",run(){const e=zt([{id:1,a:"old",left_only:10},{id:2,a:"remove",left_only:20}],[{id:1,a:"new",right_only:90},{id:3,a:"add",right_only:30}]),t=[],n=[],o=Kl(e,[],t,"left"),r=Kl(e,[],n,"right");if(90!==o[0].right_only||10!==r[0].left_only)throw new Error("missing columns must repeat counterpart cell values");if(2!==o[1].id||2!==r[1].id||3!==o[2].id||3!==r[2].id)throw new Error("missing rows must repeat the full identifiable counterpart");const l=(e,t,n,o)=>e.find(e=>e.t===t&&(null==n||e.row===n)&&e.col===o);if("diff-changed"!==l(t,"cell",0,1).cls||"diff-changed"!==l(n,"cell",0,1).cls)throw new Error("changed cell must be amber in both panes");if(l(t,"cell",1,0).strike||!l(n,"cell",1,0).strike||!l(t,"cell",2,0).strike||l(n,"cell",2,0).strike)throw new Error("one-sided row strike must appear only in the missing pane");if(l(t,"colHeader",null,2).strike||!l(n,"colHeader",null,2).strike||!l(t,"colHeader",null,3).strike||l(n,"colHeader",null,3).strike)throw new Error("one-sided column header strike must appear only in the missing pane");return{pass:!0}}},{id:"T02",description:"Editing a table row's own key value reads as one modified row, not delete+add",run(){const e=zt([{tradeId:"TRD-1",side:"buy",notional:100},{tradeId:"TRD-2",side:"sell",notional:200}],[{tradeId:"TRD-1",side:"buy",notional:100},{tradeId:"TRD-9",side:"sell",notional:200}]);if("auto-key"!==e.match.rowStrategy)throw new Error("expected auto-detected 'tradeId' key, got "+e.match.rowStrategy);if(e.children.some(e=>"added"===e.status||"removed"===e.status))throw new Error("a pure key-value edit must not leave an add/remove row behind");if(2!==e.children.length)throw new Error("expected exactly 2 rows, got "+e.children.length);const t=e.children.find(e=>e.right&&"TRD-9"===e.right.tradeId);if(!t)throw new Error("expected the edited row to still be found by its new key");if("changed"!==t.status)throw new Error("expected the renamed-key row to read as 'changed', got "+t.status);if(!t.match.keyRenamed)throw new Error("expected row.match.keyRenamed=true");const n=t.children.find(e=>"tradeId"===e.path[e.path.length-1].k);if("changed"!==n.status||"TRD-2"!==n.left||"TRD-9"!==n.right)throw new Error("expected tradeId cell itself to show the old->new change");if("equal"!==t.children.find(e=>"side"===e.path[e.path.length-1].k).status)throw new Error("unrelated cell 'side' must stay equal");if(1!==e.match.rowKeyRenames.length)throw new Error("expected exactly one row key rename recorded");return{pass:!0}}},{id:"T03",description:"Unrelated add+remove rows that merely resemble each other are NOT merged into a rename",run(){const e=zt([{id:1,a:1},{id:2,a:2}],[{id:1,a:1,b:9},{id:3,a:3}]);if(1!==e.children.filter(e=>"removed"===e.status).length)throw new Error("expected exactly one removed row (id=2)");if(1!==e.children.filter(e=>"added"===e.status).length)throw new Error("expected exactly one added row (id=3)");if(0!==e.match.rowKeyRenames.length)throw new Error("dissimilar leftover rows must not be treated as a key rename");return{pass:!0}}},{id:"K01 (bonus)",description:"Explicit key_columns overrides auto-detection",run(){const e=[{a:1,b:10},{a:2,b:20}],t=[{a:1,b:99},{a:2,b:10}];if("auto-key"!==zt(e,t).match.rowStrategy)throw new Error("expected auto-key by default");const n=zt(e,t,{keyColumns:["b"]});if("explicit-key"!==n.match.rowStrategy)throw new Error("expected explicit-key when key_columns is given");const o=n.children.find(e=>e.left&&10===e.left.b&&e.right&&10===e.right.b);if(!o)throw new Error("expected a row matched by b=10 across sides");if("changed"!==o.children.find(e=>"a"===e.path[e.path.length-1].k).status)throw new Error("row matched by b=10 should show 'a' as changed (1 vs 2)");return{pass:!0}}},{id:"R01",description:"A key rename onto an otherwise-identical nested object surfaces as its own Compact unit and is highlighted in Unified",run(){const e=zt({a:{old_key:{x:1,y:2}}},{a:{new_key:{x:1,y:2}}});if("changed"!==e.status)throw new Error("expected changed, got "+e.status);const t=[];if(Xl(e,t),1!==t.length)throw new Error("expected exactly one Compact unit, got "+t.length);if(!t[0].children.find(e=>"old_key"===e.renamedFrom))throw new Error("expected the Compact unit to be the object directly holding the renamed key, not an ancestor or a deeper drill-through");const n=[];if(Hl(e,[],n),!n.some(e=>"container"===e.t&&"diff-changed"===e.cls&&"old_key → new_key"===e.path[e.path.length-1]))throw new Error("expected the renamed nested object's box to be tinted diff-changed in Unified");return{pass:!0}}},{id:"R02",description:"Split shows each pane's own real key for a renamed scalar field, and tints a renamed container's box in both panes",run(){const e=zt({old_name:"same",wrapper:{old_key:{x:1}}},{new_name:"same",wrapper:{new_key:{x:1}}}),t=[],n=[],o=Kl(e,[],t,"left"),r=Kl(e,[],n,"right");if(!("old_name"in o)||"new_name"in o)throw new Error("left pane must show the scalar's own real key (old_name), not the compound or the new name");if(!("new_name"in r)||"old_name"in r)throw new Error("right pane must show the scalar's own real key (new_name), not the compound or the old name");const l="old_key → new_key";if(!(l in o.wrapper)||!(l in r.wrapper))throw new Error("a renamed CONTAINER value must keep the shared compound key in both panes so both boxes stay path-aligned");if(!t.some(e=>"container"===e.t&&"diff-changed"===e.cls&&e.path[e.path.length-1]===l)||!n.some(e=>"container"===e.t&&"diff-changed"===e.cls&&e.path[e.path.length-1]===l))throw new Error("expected the renamed nested object's box to be tinted diff-changed in both split panes");return{pass:!0}}}];function Kt(){const e=Ft.map(e=>{try{const t=e.run();return{id:e.id,description:e.description,pass:!(!t||!1===t.pass),message:t&&t.message||"ok"}}catch(t){return{id:e.id,description:e.description,pass:!1,message:"threw: "+(t&&t.message||t)}}});return{results:e,summary:{total:e.length,passed:e.filter(e=>e.pass).length,failedIds:e.filter(e=>!e.pass).map(e=>e.id)}}}function qt(e,t,n){const o=$(e);if("primitive"===o)return{kind:"primitive",path:t,depth:n,value:e};if("table"===o){const o={kind:"table",path:t,depth:n,table:nt(e),key:t.length?t[t.length-1]:"(root)",displayLabel:t.length?String(t[t.length-1]):"(root)",id:O()};return ot(o,e),B.set(o.id,o),o}let r=[t.length?String(t[t.length-1]):"(root)"],l=[],i=e,s=t.slice();if(t.length>0)for(;J(i);){const e=Object.keys(i);if(1!==e.length||!J(i[e[0]]))break;l.push(i),r.push(e[0]),s=s.concat([e[0]]),i=i[e[0]]}const a={kind:"dict",path:t,depth:n,labels:r,chainHolders:l,displayLabel:r.join("/"),fullPath:s,dict:i,id:O()};return B.set(a.id,a),Xt(a,i,s,n+1),a}function Xt(e,t,n,o){const r=t instanceof Set,l=r?[...t].map((e,t)=>[t,e]):Object.entries(t),i=[],s=[];for(const[e,a]of l){const l=n.concat([e]);if("primitive"===$(a))i.push({key:r?null:e,refKey:e,value:a,path:l,id:O(),parent:t});else{const n=qt(a,l,o);n.ownerParent=t,n.ownerKey=e,r&&(n.noOwnLabel=!0),s.push(n)}}let a=null;if(i.length&&(a={kind:"prim",path:n.concat(["$prims"]),depth:o,items:i,parentPath:n,isSet:r}),a)for(const e of i)_.set(e.id,{node:a,item:e});e.children=[];let c=0;a&&(a.siblingIndex=c++,e.children.push(a));for(const t of s)t.siblingIndex=c++,e.children.push(t);e.keyCount=l.length,e.isSet=r}function Ut(e){const t=$(e);if("dict"===t){const t={kind:"dict",isRoot:!0,path:[],depth:-1,labels:[],displayLabel:"(root)",fullPath:[],dict:e,id:O()};return B.set(t.id,t),Xt(t,e,[],0),t}if("table"===t){const t={kind:"table",isRoot:!0,path:[],depth:0,table:nt(e),displayLabel:"(root array)",key:"(root)",siblingIndex:0,id:O()};return ot(t,e),B.set(t.id,t),t}{const t={key:"(value)",refKey:null,value:e,path:[],id:O(),parent:null},n={kind:"prim",isRoot:!0,path:[],depth:0,items:[t],parentPath:[],siblingIndex:0};return _.set(t.id,{node:n,item:t}),n}}function Vt(e,t){if(e.parent=t,e.children)for(const t of e.children)Vt(t,e)}function Yt(e){if(b.set(ie(e.path),e),e.children)for(const t of e.children)Yt(t)}function Jt(e,t,n){if(e.parent=t,e.cellHost=n,e.children)for(const t of e.children)Jt(t,e,n)}function $t(e,t,n,o){const r=e.table,l=r._cellNodes||(r._cellNodes=new Map),i=t+":"+n,s=l.get(i);if(s&&s.rawValue===o)return s.node;if(s){const e=ie(s.node.path);M.detached.delete(e),b.get(e)===s.node&&b.delete(e)}const a=qt(o,rc({node:e,r:t,c:n}),e.depth+1);a.isRoot=!0,a.cellOrigin={hostTable:e,r:t,c:n},"list"!==e.table.mode&&(a.displayLabel=(a.displayLabel||String(a.key))+"["+t+"]");return Jt(a,e,e.cellHost||e),Yt(a),"dict"===a.kind&&(bn(a,!0,!1),On(a,0,0)),l.set(i,{rawValue:o,node:a}),a}function Gt(e){j&&ss();const t=ie(e.path);M.detached.has(t)?M.detached.delete(t):M.detached.add(t),Ri()}function Zt(e){T=1,B=new Map,_=new Map,R=new Map,P=new Map,N=[],A=[],w=Ut(e),b=new Map,Vt(w,null),Yt(w),tl&&"split"===ol&&en(w),Do()}function Qt(e){const t=String(e),n=t.indexOf(" → ");return-1===n?t:"canvasLeft"===m?t.slice(0,n):t.slice(n+3)}function en(e){if(e&&("dict"===e.kind&&e.labels&&e.labels.length?(e.labels=e.labels.map(Qt),e.displayLabel=e.labels.join("/")):"table"!==e.kind||e.isRoot||(e.displayLabel=Qt(e.displayLabel)),e.children))for(const t of e.children)en(t)}function tn(){if(!(u.maxWidthFrac>0))return null;const e=v(),t=e&&e.clientWidth||window.innerWidth||1200;return Math.round(u.maxWidthFrac*t)}function nn(){const e=v(),t=tn()||e&&e.clientWidth||window.innerWidth||1200,n=e&&e.clientHeight||window.innerHeight||800;return n>0?t/n:1}function on(e,t){return{cols:Math.max(1,Math.ceil(e/t)),rows:Math.min(Math.max(e,1),t)}}function rn(e){const t=e.items,n=t.length;e.cells=t.map(e=>{const t=null==e.key;return{disp:t?pe(e.value):ce(e.key)+": "+pe(e.value),full:t?Z(e.value):String(e.key)+": "+Z(e.value),value:e.value,key:e.key,path:e.path,id:e.id}});let o=0;for(const t of e.cells)o=Math.max(o,U(t.disp));o=Math.ceil(o)+2*r.CELL_PAD_X+6,o=Math.max(o,40);const l=r.CELL_H,i=u.kvRows,s=u.kvCols,a=n>i*s;let c,d;e.kvOverflow=a,e.kvN=i,a?(c={cols:s,rows:i},d=s*i-1):(c=on(n,i),d=n),e.cols=c.cols,e.rowsCount=c.rows,e.visibleK=d,e.hiddenCount=n-d,e.cellW=o,e.cellH=l,e.kvOwnHeader=a&&!(!e.parent||!e.parent.isRoot),e.w=c.cols*o+2*r.BORDER,e.h=c.rows*l+(e.kvOwnHeader?r.TITLE_H:0)+2*r.BORDER}function ln(e){return u.cellContainerBadges&&"primitive"!==$(e)}function sn(e,t){const n=[],o=e.rows.slice(0,t||e.rows.length);for(let t=0;t<e.totalCols;t++){let l=e.headers?U(ce(null==e.headers[t]?"":e.headers[t])):0;for(let n=0;n<o.length;n++){const r=o[n][t],i=ln(r)?ee(e,n,t,r):pe(r);l=Math.max(l,U(i))}l=Math.ceil(l)+2*r.TCELL_PAD_X+4,n.push(Math.max(r.MINCOL,l))}return n}function an(e){if(e._fullColWidths)return e._fullColWidths;const t=e.table,n=[];for(let o=0;o<t.totalCols;o++){let l=t.headers?U(String(null==t.headers[o]?"":t.headers[o])):0;for(let e=0;e<t.rows.length;e++){const n=t.rows[e][o],r=ln(n)?ee(t,e,o,n):Z(n);l=Math.max(l,U(r))}let i=Math.max(r.MINCOL,Math.ceil(l)+2*r.TCELL_PAD_X);e.colWidths&&e.colWidths[o]>i&&(i=e.colWidths[o]),n.push(i)}return e._fullColWidths=n,n}function cn(e){const t=Math.max(1,Math.round(e)||1),n=Math.ceil(U("0".repeat(t)))+2*r.TCELL_PAD_X+4;return Math.max(r.MINCOL,n)}function dn(e){for(const t of p.rules)if(t.pattern)try{if(new RegExp(t.pattern).test(e))return t.width}catch(e){}return null}function un(e,t){if(0===e.totalRows)return 1;const n=new Set;for(const o of e.rows)n.add(Z(o[t]));return n.size/e.totalRows}function fn(e){const t=e.table,n=an(e),o=p.rules.length>0,r=p.lowOccupancyThreshold>0;if(!o&&!r)return{widths:n,narrow:null};const l=n.slice(),i=new Array(t.totalCols).fill(!1);for(let e=0;e<t.totalCols;e++){const n=t.headers?String(null==t.headers[e]?"":t.headers[e]):"";let o=t.headers?dn(n):null;null==o&&r&&un(t,e)<p.lowOccupancyThreshold&&(o=p.lowOccupancyWidth),null!=o&&(l[e]=cn(o),i[e]=!0)}return{widths:l,narrow:i}}function hn(e){return Math.max(r.MINCOL,Math.ceil(U("+"+e))+2*r.TCELL_PAD_X)}function pn(e){const t=e.noOwnLabel?"":e.displayLabel||e.key||"array",n="["+e.table.totalRows+"×"+e.table.totalCols+"]";return Math.ceil(V(me(t))+10+U(n))+12+3*(r.BTN+3)+18}function mn(e){const t=e.table;e.colWidths=sn(t,200),e._fullColWidths=null;const n=Math.min(u.n,t.totalCols),o=t.totalCols-n,l=Math.min(u.m,t.totalRows),i=t.totalRows-l;e.hiddenCols=o,e.hiddenRows=i;let s=r.BORDER;for(let t=0;t<n;t++)s+=e.colWidths[t]+r.BORDER;o>0&&(s+=hn(o)+r.BORDER);let a=r.TITLE_H;t.headers&&(a+=r.ROW_H),a+=l*r.ROW_H,i>0&&(a+=r.ROW_H),0===t.totalRows&&(a+=r.ROW_H),a+=3,e.compactW=Math.max(pn(e),Math.ceil(s)),e.compactH=Math.ceil(a),e.minW=Math.ceil(pn(e)),e.minH=r.TITLE_H;const c=M.minimized.has(ie(e.path));e.w=c?e.minW:e.compactW,e.h=c?e.minH:e.compactH}function gn(e){const t=e.children&&e.children.find(e=>"prim"===e.kind);return t&&t.kvOverflow&&!t.kvOwnHeader?t:null}function yn(e){return e.isSet?"("+e.keyCount+")":"{ "+e.keyCount+" }"}function vn(e){const t=e.noOwnLabel?"":e.displayLabel,n=yn(e),o=gn(e)?3:1;return Math.ceil(16+V(me(t))+10+U(n))+28+o*(r.BTN+4)}function wn(e,t,n){const o=n&&1===e.children.length&&"dict"===e.children[0].kind;for(const t of e.children)bn(t,!1,o);const l=n?nn():1;if(0===e.children.length)e._hsucc=[],e._vsucc=[],e._htopo=[],e._vtopo=[],e.contentW=0,e.contentH=0;else{const t=Tn(e.children.map(e=>({w:e.w+u.gap,h:e.h+u.gap,ref:e})),l,tn());for(const e of t.placements)e.box.ref.relX=e.x,e.box.ref.relY=e.y;_n(e),Rn(e.children,e._hsucc,e._htopo,"w","relX"),Rn(e.children,e._vsucc,e._vtopo,"h","relY");let n=0,o=0;for(const t of e.children)n=Math.max(n,t.relX+t.w+u.gap),o=Math.max(o,t.relY+t.h+u.gap);e.contentW=n,e.contentH=o}if(t)e.contentOrigin={x:r.PAD,y:r.PAD},e.w=r.PAD+e.contentW,e.h=r.PAD+e.contentH;else{const t=vn(e);e.contentOrigin={x:r.PAD,y:r.TITLE_H+r.PAD},e.expandedW=Math.max(r.PAD+e.contentW,t),e.expandedH=0===e.children.length?r.TITLE_H:r.TITLE_H+r.PAD+e.contentH,e.collapsedW=t,e.collapsedH=r.TITLE_H;const n=M.collapsed.has(ie(e.path));e.w=n?e.collapsedW:e.expandedW,e.h=n?e.collapsedH:e.expandedH}}function bn(e,t,n){"dict"===e.kind?wn(e,t,n):"prim"===e.kind?rn(e):"table"===e.kind&&mn(e)}function xn(e){const t=vn(e);e.expandedW=Math.max(r.PAD+e.contentW,t),e.collapsedW=t,e.collapsedH=r.TITLE_H;const n=M.collapsed.has(ie(e.path));e.w=n?e.collapsedW:e.expandedW,e.h=n?e.collapsedH:e.expandedH}function kn(){bn(w,!0,!0),On(w,0,0)}function En(e){return e.children.map(e=>ie(e.path)).join(String.fromCharCode(0))}function Sn(){const e=new Map;return function t(n){if("dict"===n.kind&&n.children&&n.children.length&&e.set(ie(n.path),{sig:En(n),hsucc:n._hsucc,vsucc:n._vsucc,htopo:n._htopo,vtopo:n._vtopo}),n.children)for(const e of n.children)t(e)}(w),e}function Ln(e){!function t(n){if(n.children)for(const e of n.children)t(e);if("dict"!==n.kind||!n.children||!n.children.length)return;const o=e.get(ie(n.path));o&&o.sig===En(n)&&(n._hsucc=o.hsucc,n._vsucc=o.vsucc,n._htopo=o.htopo,n._vtopo=o.vtopo,Nn(n))}(w),On(w,0,0)}function Cn(e,t,n){const o=t+n;let r=0;for(const n of e){if(!(n.x+n.w<=t+1e-6)){if(n.x>=o-1e-6)break;n.y>r&&(r=n.y)}}return r}function In(e,t,n,o){const r=t+n,l=[];for(const n of e){const e=n.x+n.w;if(n.x<t){const o=Math.min(e,t)-n.x;o>1e-6&&l.push({x:n.x,w:o,y:n.y})}const i=Math.max(n.x,t),s=Math.min(e,r);if(s-i>1e-6&&l.push({x:i,w:s-i,y:o}),e>r){const t=Math.max(n.x,r),o=e-t;o>1e-6&&l.push({x:t,w:o,y:n.y})}}l.sort((e,t)=>e.x-t.x);const i=[];for(const e of l){const t=i[i.length-1];t&&Math.abs(t.y-e.y)<1e-6&&Math.abs(t.x+t.w-e.x)<1e-6?t.w+=e.w:i.push({x:e.x,w:e.w,y:e.y})}return i}function Mn(e,t){let n=[{x:0,w:t,y:0}];const o=[];for(const r of e){let e=null;for(let o=0;o<n.length;o++){const l=n[o].x;if(l+r.w>t+.5)continue;const i=Cn(n,l,r.w);(null===e||i<e.y-1e-6||Math.abs(i-e.y)<1e-6&&l<e.x)&&(e={x:l,y:i})}if(null===e){e={x:0,y:Cn(n,0,r.w)}}o.push({box:r,x:e.x,y:e.y}),n=In(n,e.x,r.w,e.y+r.h)}return o}function Tn(e,t,n){if(0===e.length)return{placements:[],w:0,h:0,order:[],width:0};const o=e.slice().sort((e,t)=>t.h-e.h||t.w-e.w),r=o.map(e=>e.w),l=Math.max.apply(null,r),i=r.reduce((e,t)=>e+t,0),s=o.reduce((e,t)=>e+t.w*t.h,0),a=Math.sqrt(s*t),c=l;let d=Math.max(i,l);n&&(d=Math.max(l,Math.min(d,n)));const u=[];for(let e=0;e<25;e++)u.push(c+e/24*(d-c));let f=Math.max(a,l);n&&(f=Math.min(f,Math.max(l,n))),u.push(f);const h=[];for(let e of u){e=Math.max(e,l);const n=Mn(o,e);let r=0,i=0;for(const e of n)r=Math.max(r,e.x+e.box.w),i=Math.max(i,e.y+e.box.h);const a=Math.abs(Math.log(r/i/t)),c=(r*i-s)/s;h.push({placements:n,w:r,h:i,width:e,aspectScore:a,wasteFrac:c})}const p=Math.min.apply(null,h.map(e=>e.aspectScore)),m=h.filter(e=>e.aspectScore<=1.6*p+1e-6||e.aspectScore<=p+.05);let g=m[0];for(const e of m)e.wasteFrac<g.wasteFrac&&(g=e);return g.score=g.aspectScore+.3*g.wasteFrac,g.order=o,g}function On(e,t,n){if(e.absX=t,e.absY=n,"dict"===e.kind){if(!(!e.isRoot&&M.collapsed.has(ie(e.path)))&&e.children){const o=t+e.contentOrigin.x,r=n+e.contentOrigin.y;for(const t of e.children)On(t,o+(t.relX||0),r+(t.relY||0))}}}function Bn(e,t){const n=new Array(e).fill(0);for(let o=0;o<e;o++)for(const e of t[o])n[e]++;const o=[];for(let t=0;t<e;t++)0===n[t]&&o.push(t);const r=[];for(;o.length;){const e=o.shift();r.push(e);for(const r of t[e])0===--n[r]&&o.push(r)}if(r.length<e){const t=new Set(r);for(let n=0;n<e;n++)t.has(n)||r.push(n)}return r}function _n(e){const t=e.children,n=t.length,o=Array.from({length:n},()=>[]),r=Array.from({length:n},()=>[]);for(let e=0;e<n;e++)for(let l=e+1;l<n;l++){const n=t[e],i=t[l],s=n.relX+n.w,a=i.relX+i.w;n.relX<a-1e-6&&i.relX<s-1e-6?n.relY<=i.relY?r[e].push(l):r[l].push(e):n.relX<=i.relX?o[e].push(l):o[l].push(e)}e._hsucc=o,e._vsucc=r,e._htopo=Bn(n,o),e._vtopo=Bn(n,r)}function Rn(e,t,n,o,r){const l=e.length,i=new Array(l).fill(0);for(const r of n){const n=i[r]+e[r][o]+u.gap;for(const e of t[r])n>i[e]&&(i[e]=n)}for(let t=0;t<l;t++)e[t][r]=i[t]}function Pn(e){let t=0,n=0;for(const o of e.children)t=Math.max(t,o.relX+o.w+u.gap),n=Math.max(n,o.relY+o.h+u.gap);if(e.contentW=t,e.contentH=n,e.isRoot)e.w=r.PAD+t,e.h=r.PAD+n;else{const o=M.collapsed.has(ie(e.path));e.expandedW=Math.max(r.PAD+t,vn(e)),e.expandedH=0===e.children.length?r.TITLE_H:r.TITLE_H+r.PAD+n,e.w=o?e.collapsedW:e.expandedW,e.h=o?e.collapsedH:e.expandedH}}function Nn(e){e.children&&e.children.length&&e._hsucc&&(Rn(e.children,e._hsucc,e._htopo,"w","relX"),Rn(e.children,e._vsucc,e._vtopo,"h","relY")),Pn(e)}function An(e){let t=e,n=t.parent;for(;n;)Nn(n),t=n,n=t.parent;On(w,0,0)}function jn(e){j&&ss();const t=ie(e.path);M.collapsed.has(t)?M.collapsed.delete(t):M.collapsed.add(t);const n=M.collapsed.has(t);e.w=n?e.collapsedW:e.expandedW,e.h=n?e.collapsedH:e.expandedH,An(e),Ri(),Ec(e,n)}function Wn(e){if("table"!==e.kind)return;const t=ie(e.path),n=M.minimized.has(t),o=n?e.minW:e.compactW,r=n?e.minH:e.compactH;o===e.w&&r===e.h||(e.w=o,e.h=r,An(e))}function Hn(e){j&&ss();const t=ie(e.path);M.minimized.has(t)?M.minimized.delete(t):(M.minimized.add(t),M.large.delete(t)),Wn(e),Ri(),Ec(e,M.minimized.has(t))}function Dn(e){j&&ss();const t=ie(e.path);M.large.has(t)?M.large.delete(t):(M.large.add(t),M.minimized.delete(t),M.detached.delete(t)),Wn(e),Ri()}function zn(e){if(e.cellHost)return void Gt(e);j&&ss();const t=ie(e.path);M.detached.has(t)?M.detached.delete(t):(M.detached.add(t),M.large.delete(t)),Wn(e),Ri()}function Fn(e,t){if("detached"===t)return void zn(e);const n=ie(e.path);M.large.has(n)?Dn(e):"table"===e.kind&&Hn(e)}function Kn(){const e=window.getSelection&&window.getSelection();return!!(e&&String(e).length>0)}function qn(e,t,n,o){const r=document.createElement("button");return r.className="tbtn"+(o?" active":""),"restore"!==t&&"default size"!==t||(e="▭"),r.type="button",r.title=t,r.textContent=e,r.onclick=e=>{e.stopPropagation(),n()},r}function Xn(e){if("table"===e.kind)return{label:e.noOwnLabel?"":e.displayLabel||e.key||"array",dim:"["+e.table.totalRows+"×"+e.table.totalCols+"]",dataId:e.cellHost?null:"dict:"+ie(e.path),showMinimize:!0};if("dict"===e.kind)return{label:e.displayLabel||e.key||"object",dim:yn(e),dataId:null,showMinimize:!1};return{label:e.parent&&e.parent.noOwnLabel?"":e.parent&&e.parent.displayLabel||"values",dim:e.isSet?"("+e.items.length+")":"{"+e.items.length+"}",dataId:null,showMinimize:!1}}function Un(e,t){const n=ie(e.path),o=Xn(e),l=document.createElement("div");l.className="ttool",l.style.height=r.TITLE_H+"px";const i=document.createElement("div");i.className="ttool-left";const s=me(o.label);i.innerHTML='<span class="tname"'+(o.dataId?' data-id="'+ye(o.dataId)+'"':"")+' title="'+ye(o.label)+'">'+ge(s)+'</span><span class="tdim">'+o.dim+"</span>",!o.dataId||e.isRoot||e.noOwnLabel||(i.querySelector(".tname").__nodeId=e.id),l.appendChild(i);const a=document.createElement("div");if(a.className="ttool-btns","detached"===t)a.appendChild(qn("✕","close (re-attach)",()=>zn(e)));else{if(o.showMinimize){const t=M.minimized.has(n);a.appendChild(qn(t?"▭":"▁",t?"default size":"minimize",()=>Hn(e)))}const t=M.large.has(n);a.appendChild(qn(t?"⤡":"⤢",t?"restore":"expand",()=>Dn(e))),a.appendChild(qn("⧉","detach",()=>zn(e),M.detached.has(n)))}return l.appendChild(a),l.onclick=n=>{n.target.closest(".ttool-btns")||n.target.closest(".tname")||Kn()||Fn(e,t)},l}function Vn(e,t){const n=e.table,o=ie(e.path),l=!!t.full,i=t.widths||(l?an(e):e.colWidths),s=t.narrowCols||null,a=document.createElement("table");a.className="dtable"+(l?" full":"");const c=t.colsAll?n.totalCols:Math.min(u.n,n.totalCols),d=!!t.markers&&n.totalCols>c,f=t.rowsAll?n.totalRows:Math.min(u.m,n.totalRows),h=!!t.markers&&n.totalRows>f,p=e=>l?String(e):ce(e),m=e=>l?Z(e):pe(e),g=document.createElement("colgroup");let y=r.BORDER;for(let e=0;e<c;e++){const t=document.createElement("col");t.style.width=i[e]+"px",g.appendChild(t),y+=i[e]+r.BORDER}if(d){const e=hn(n.totalCols-c),t=document.createElement("col");t.style.width=e+"px",g.appendChild(t),y+=e+r.BORDER}if(a.appendChild(g),a.style.width=y+"px",n.headers){const e=document.createElement("thead"),t=document.createElement("tr");for(let e=0;e<c;e++){const r=document.createElement("th"),l=String(null==n.headers[e]?"":n.headers[e]);r.title=l,r.textContent=p(l),s&&s[e]&&r.classList.add("colfixed"),r.setAttribute("data-id","th:"+o+":"+e),r.__colId=n.colIds[e],t.appendChild(r)}if(d){const e=document.createElement("th");e.className="marker",e.textContent="+"+(n.totalCols-c),t.appendChild(e)}e.appendChild(t),a.appendChild(e)}const v=document.createElement("tbody");if(0===n.totalRows){const e=document.createElement("tr"),t=document.createElement("td");t.colSpan=c+(d?1:0),t.className="empty",t.textContent="(empty)",e.appendChild(t),v.appendChild(e)}for(let t=0;t<f;t++){const r=n.rows[t],l=document.createElement("tr");for(let i=0;i<c;i++){const a=document.createElement("td"),c=r[i],d=$(c);if(ln(c)){a.className="t-container",a.textContent=ee(n,t,i,c);const o=M.detached.has(ie(rc({node:e,r:t,c:i})));a.title=("dict"===d?"object":"array")+(o?" — already open, click to close":" — click to open, hover to peek");const r=o?$t(e,t,i,c):null;o&&a.classList.add("active"),a.addEventListener("click",n=>{n.stopPropagation(),Gt(r||$t(e,t,i,c))}),o||ro(a,e,t,i,c)}else{const e=Z(c);a.title=e,a.textContent=m(c),a.className=te(c);const t=le(c);null!=t&&(a.classList.add("structile-link"),a.setAttribute("data-link-id",String(t)))}s&&s[i]&&a.classList.add("colfixed"),a.setAttribute("data-id","td:"+o+":"+t+":"+i),a.__cellId=n.cellIds[t][i],l.appendChild(a)}if(d){const e=document.createElement("td");e.className="marker",e.textContent="…",l.appendChild(e)}v.appendChild(l)}if(h){const e=document.createElement("tr"),t=document.createElement("td");t.colSpan=c+(d?1:0),t.className="rowmarker",t.textContent=n.totalRows-f+" more rows",e.appendChild(t),v.appendChild(e)}return a.appendChild(v),a}function Yn(e,t){const n=document.createElement("div");n.className="pcell",n.title=e.full,n.setAttribute("data-id","val:"+ie(e.path)),n.__id=e.id;const o=le(e.value),r=null!=o?" structile-link":"",l=null!=o?' data-link-id="'+o+'"':"";if(null==e.key)n.innerHTML='<span class="pv'+r+" "+te(e.value)+'"'+l+">"+ge(t)+"</span>";else{const o=t.indexOf(": "),i=o>=0?t.slice(0,o):t,s=o>=0?t.slice(o+2):"";n.innerHTML='<span class="pk">'+ge(i)+'</span><span class="pv'+r+" "+te(e.value)+'"'+l+">"+ge(s)+"</span>"}return n}function Jn(e,t){const n=document.createElement("div");n.className="box prim",n.style.left=e.absX+"px",n.style.top=e.absY+"px",n.style.width=e.w+"px",n.style.height=e.h+"px",e.kvOwnHeader&&n.appendChild(Un(e,"compact"));const o=document.createElement("div");o.style.display="grid",o.style.gridTemplateColumns="repeat("+e.cols+", "+e.cellW+"px)",o.style.gridAutoRows=e.cellH+"px";for(const t of e.cells.slice(0,e.visibleK))o.appendChild(Yn(t,t.disp));if(e.hiddenCount>0){const t=document.createElement("div");t.className="pcell marker",t.textContent="+"+e.hiddenCount+" more",Qn(t,e,"right"),o.appendChild(t)}n.appendChild(o),t.appendChild(n)}function $n(e){if(e._fullCellW)return e._fullCellW;let t=0;for(const n of e.cells)t=Math.max(t,U(n.full));return e._fullCellW=Math.max(Math.ceil(t)+2*r.CELL_PAD_X+6,40),e._fullCellW}function Gn(e,t){const n=$n(e),o=e.cellH,r=document.createElement("div");r.className="tscroll",r.style.overflow="auto";const l=document.createElement("div");l.style.display="grid",l.style.gridTemplateColumns="repeat("+t.cols+", "+n+"px)",l.style.gridAutoRows=o+"px";for(const t of e.cells)l.appendChild(Yn(t,t.full));return r.appendChild(l),r}function Zn(e){const t=document.createElement("div");return t.className="zone "+e,t}function Qn(e,t,n){if(!e)return;let o=null;e.addEventListener("mouseenter",()=>{clearTimeout(o),o=setTimeout(()=>_i(t,n),u.dwellMs)}),e.addEventListener("mouseleave",()=>clearTimeout(o))}window.STRUCTILE_TESTING={canonicalKey:it,compareScalars:lt,classifySemanticContainer:st,topKind:at,diffValues:zt,diffObjects:Et,diffSets:St,diffArrays:Lt,diffTables:Ht,diffPathToString:dt,buildDiffSideValue:Kl,buildDiffSupersetValue:Hl,collectCompactUnits:Xl,runFixtures:Kt,fixtures:Ft};const eo=14,to=250;let no=null,oo=null;function ro(e,t,n,o,r){let l=0,i=0;e.addEventListener("mouseenter",e=>{l=e.clientX,i=e.clientY,clearTimeout(oo),clearTimeout(no),no=setTimeout(()=>io($t(t,n,o,r),l,i),u.dwellMs)}),e.addEventListener("mousemove",e=>{l=e.clientX,i=e.clientY}),e.addEventListener("mouseleave",()=>{clearTimeout(no),Io&&lo()})}function lo(){clearTimeout(oo),oo=setTimeout(Mo,to)}function io(e,t,n){Mo();const o=document.createElement("div");o.className="overlay peek cell-peek",o.style.position="fixed",o.style.zIndex="70",o.appendChild(Un(e,"compact"));const r=Math.round(.5*window.innerWidth),l=Math.round(.5*window.innerHeight);"table"===e.kind?(tt(o,e,{softBorder:!0}),o.appendChild(po(e,{full:!0,capW:r,capH:l}))):(o.style.borderLeftWidth="3px",o.style.borderLeftColor=Ze(e.path),o.appendChild(ko(e,r))),o.addEventListener("mouseenter",()=>clearTimeout(oo)),o.addEventListener("mouseleave",lo),o.addEventListener("click",t=>{t.target.closest(".ttool")||(Mo(),Gt(e))}),document.body.appendChild(o);let i=t+eo,s=n+eo;i=Math.min(i,Math.max(0,window.innerWidth-o.offsetWidth-4)),s=Math.min(s,Math.max(0,window.innerHeight-o.offsetHeight-4)),o.style.left=i+"px",o.style.top=s+"px",Io=o}function so(e,t){const n=t.hiddenCols>0,o=t.hiddenRows>0;if(n){const n=Zn("right");n.style.top=r.TITLE_H+"px",n.style.height=Math.max(0,t.h-r.TITLE_H)+"px",e.appendChild(n),Qn(n,t,"right")}if(o){const n=Zn("bottom");e.appendChild(n),Qn(n,t,"bottom")}if(n&&o){const n=Zn("corner");e.appendChild(n),Qn(n,t,"corner")}e.querySelectorAll("th.marker, td.marker").forEach(e=>Qn(e,t,"right")),Qn(e.querySelector("td.rowmarker"),t,"bottom")}function ao(e,t){const n=M.minimized.has(ie(e.path)),o=document.createElement("div");if(o.className="box table-box",o.style.left=e.absX+"px",o.style.top=e.absY+"px",o.style.width=e.w+"px",o.style.height=e.h+"px",tt(o,e),o.appendChild(Un(e,"compact")),!n){const t=document.createElement("div");t.className="tscroll",t.style.overflow="hidden",t.appendChild(Vn(e,{colsAll:!1,rowsAll:!1,markers:!0})),o.appendChild(t),so(o,e)}t.appendChild(o)}function co(e,t){if("dict"===e.kind){const n=!e.isRoot&&M.collapsed.has(ie(e.path));if(!e.isRoot){const o=document.createElement("div");o.className="box dict",o.style.left=e.absX+"px",o.style.top=e.absY+"px",o.style.width=e.w+"px",o.style.height=e.h+"px",o.style.background=Je(e.depth),o.style.borderLeftColor=Ze(e.path);const l=document.createElement("div");l.className="dict-header",l.style.height=r.TITLE_H+"px";const i=n?"▸":"▾",s=yn(e),a=e.noOwnLabel?"":e.displayLabel,c=me(a);l.innerHTML='<span class="caret">'+i+'</span><span class="dict-left" style="--badge-space:'+Math.ceil(U(s)+4)+'px"><span class="dname" data-id="'+ye("dict:"+ie(e.path))+'" title="'+ye(a)+'">'+ge(c)+'</span><span class="badge">'+s+"</span></span>",e.noOwnLabel||(l.querySelector(".dname").__nodeId=e.id);const d=document.createElement("div");d.className="ttool-btns",d.appendChild(qn(n?"▭":"▁",n?"restore":"collapse",()=>jn(e)));const u=gn(e);if(u){const e=ie(u.path),t=M.large.has(e);d.appendChild(qn(t?"⤡":"⤢",t?"restore":"expand",()=>Dn(u))),d.appendChild(qn("⧉","detach",()=>zn(u),M.detached.has(e)))}l.appendChild(d),l.onclick=t=>{t.target.closest(".dname")||(t.stopPropagation(),t.target.closest(".ttool-btns")||Kn()||(u&&M.large.has(ie(u.path))?Dn(u):jn(e)))},o.appendChild(l),t.appendChild(o)}if(!n&&e.children)for(const n of e.children)co(n,t)}else"prim"===e.kind?Jn(e,t):"table"===e.kind&&ao(e,t)}function uo(e,t){const n=Math.max(1,t||1),o=Math.max(1,Math.round(Number(e)||n));return Math.min(o,n)}function fo(e,t,n){const o=e.table,l=n||e.colWidths||[],i=uo(t,o.totalCols);let s=r.BORDER;for(let e=0;e<i;e++)s+=(l[e]||r.MINCOL)+r.BORDER;return Math.ceil(s+16)}function ho(e,t){const n=e.table,o=uo(t,n.totalRows||1);let l=r.TITLE_H;return n.headers&&(l+=r.ROW_H),l+=o*r.ROW_H+2,Math.ceil(l+16)}function po(e,t){const n=null!=(t=t||{}).capW||null!=t.capH,o=document.createElement("div");return o.className="tscroll",null!=t.capH&&(o.style.maxHeight=Math.max(60,t.capH-r.TITLE_H)+"px"),null!=t.capW&&(o.style.maxWidth=t.capW+"px"),o.style.overflow=n?"auto":"visible",o.appendChild(Vn(e,{colsAll:!0,rowsAll:!0,markers:!1,full:!!t.full,widths:t.widths,narrowCols:t.narrowCols})),o}function mo(e){let t=e.parent;for(;t;){if(!t.isRoot&&M.collapsed.has(ie(t.path)))return!0;t=t.parent}return!1}function go(e){return e.cellHost?e.cellHost:"prim"!==e.kind||e.kvOwnHeader||!e.parent||e.parent.isRoot?e:e.parent}function yo(e){return!!e.cellHost||("table"===e.kind||"prim"===e.kind&&e.kvOverflow)}function vo(e,t,n,o,r){const l=o-t,i=r-n,s=Math.sqrt(l*l+i*i),a=180*Math.atan2(i,l)/Math.PI,c=document.createElement("div");c.className="connector",c.style.left=t+"px",c.style.top=n+"px",c.style.width=s+"px",c.style.transform="rotate("+a+"deg)",e.appendChild(c)}function wo(e,t,n){const o=document.createElement("div");let r,l;if(o.appendChild(Un(e,"large")),"table"===e.kind){o.className="overlay large-table",tt(o,e,{softBorder:!0});const i=an(e);r=Math.min(Math.round(.9*t),fo(e,u.N,i)),l=Math.min(Math.round(.85*n),ho(e,u.M)),o.style.maxWidth=Math.max(pn(e),r)+"px",o.style.maxHeight=l+"px",o.appendChild(po(e,{full:!0,capW:r,capH:l}))}else{o.className="overlay large-prim";const n=on(e.items.length,e.kvN);r=Math.min(Math.round(.9*t),n.cols*$n(e)+16),l=e.h,o.style.maxWidth=r+"px",o.appendChild(Gn(e,n))}return{wrap:o,capW:r,capH:l}}const bo=220,xo=4;function ko(e,t){On(e,0,0);const n=document.createElement("div");n.style.position="relative",n.style.width=e.w+"px",n.style.height=e.h+"px",co(e,n);const o=document.createElement("div");return o.className="tscroll",o.style.maxWidth=Math.max(bo,t)+"px",o.style.maxHeight="70vh",o.appendChild(n),o}function Eo(e,t,n){const o="td:"+ie(e.path)+":"+t+":"+n,r=y();for(const e of r.querySelectorAll('td[data-id^="td:"]')){if(e.getAttribute("data-id")!==o)continue;const t=e.getBoundingClientRect(),n=r.getBoundingClientRect();return{right:t.right-n.left,top:t.top-n.top,bot:t.bottom-n.top}}return null}function So(e,t){if(e.cellOrigin){const t=Eo(e.cellOrigin.hostTable,e.cellOrigin.r,e.cellOrigin.c);if(t)return t}return{right:t.absX+t.compactW,top:t.absY,bot:t.absY+t.compactH}}function Lo(e,t,n){const o=document.createElement("div");let l;if(o.className="overlay detached-panel",o.style.overflow="visible",o.style.zIndex="52",o.appendChild(Un(e,"detached")),"table"===e.kind){const i=e.table,{widths:s,narrow:a}=fn(e);let c=null,d=null;const f=Math.min(u.detCols,i.totalCols);let h=r.BORDER;for(let e=0;e<f;e++)h+=s[e]+r.BORDER;h+=16;const p=n-4;(i.totalCols>u.detCols||h>p)&&(c=Math.max(bo,Math.min(h,p))),i.totalRows>u.detRows&&(d=r.TITLE_H+(i.headers?r.ROW_H:0)+u.detRows*r.ROW_H+2+16),tt(o,e),o.style.borderColor=Qe(e),o.appendChild(po(e,{full:!0,capW:c,capH:d,widths:s,narrowCols:a})),l=So(e,t)}else if("dict"===e.kind)o.style.borderLeftWidth="3px",o.style.borderLeftColor=Ze(e.path),o.appendChild(ko(e,n)),l=So(e,t);else{const r=on(e.items.length,e.kvN);r.cols*$n(e)+16>n&&(o.style.maxWidth=Math.max(bo,n)+"px"),o.appendChild(Gn(e,r)),l={right:t.absX+t.w,top:t.absY,bot:t.absY+t.h}}return{wrap:o,src:l}}function Co(e){const t=v(),n=t&&t.clientWidth||window.innerWidth,o=t&&t.clientHeight||window.innerHeight;let l=w.w+r.PAD,i=w.h+r.PAD;for(const t of M.large){const s=b.get(t);if(!s||!yo(s))continue;const a=go(s);if(mo(a))continue;const{wrap:c,capW:d,capH:u}=wo(s,n,o);c.style.left=a.absX+"px",c.style.top=a.absY+"px",c.style.zIndex="45",e.appendChild(c),l=Math.max(l,a.absX+(c.offsetWidth||d)+r.PAD),i=Math.max(i,a.absY+(c.offsetHeight||u)+r.PAD)}const s=w.w+2*u.gap,a=Math.max(bo,n-s-r.PAD),c=[];for(const e of M.detached){const t=b.get(e);if(!t||!yo(t))continue;const n=go(t);mo(n)||c.push({node:t,host:n})}c.sort((e,t)=>e.host.absY-t.host.absY);let d=0;for(const{node:t,host:n}of c){const o=Math.max(n.absY,d),{wrap:c,src:f}=Lo(t,n,a);c.style.left=s+"px",c.style.top=o+"px",e.appendChild(c);const h=c.offsetHeight||200,p=c.offsetWidth||200;vo(e,f.right,f.top,s,o),vo(e,f.right,f.bot,s,o+h),l=Math.max(l,s+p+r.PAD),i=Math.max(i,o+h+r.PAD),d=o+h+u.gap}e.style.width=Math.ceil(l)+"px",e.style.height=Math.ceil(i)+"px"}let Io=null;function Mo(){clearTimeout(no),clearTimeout(oo),Io&&(Io.remove(),Io=null)}function To(e,t){const n=n=>{e.contains(n.target)||n.target===t.ignore||t.dismiss()},o=e=>{"Escape"===e.key&&t.dismiss()},r=(t=t||{}).scrollEl?()=>t.dismiss():null;return setTimeout(()=>document.addEventListener("mousedown",n),0),document.addEventListener("keydown",o),r&&t.scrollEl.addEventListener("scroll",r,{passive:!0}),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",o),r&&t.scrollEl.removeEventListener("scroll",r)}}let Oo=null,Bo=null;function _o(){Oo&&(Oo.remove(),Oo=null),Bo&&(Bo(),Bo=null)}function Ro(e,t,n){_o();const o=y(),r=document.createElement("div");r.className="editpop";const l=document.createElement("input");l.type="text",l.className="editpop-input",l.value=t;const i=document.createElement("div");i.className="editpop-err",i.style.display="none",r.appendChild(l),r.appendChild(i);const s=e.getBoundingClientRect(),a=o.getBoundingClientRect();r.style.left=Math.max(0,s.left-a.left)+"px",r.style.top=s.bottom-a.top+4+"px",o.appendChild(r),Oo=r,l.focus(),l.select();l.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),(()=>{const e=n(l.value);if(e)return i.textContent=e,i.style.display="block",void l.focus();_o()})())}),Bo=To(r,{dismiss:_o,scrollEl:document.getElementById(g)})}function Po(e){const t=e.trim();if(t.length>=2&&'"'===t[0]&&'"'===t[t.length-1])try{const e=JSON.parse(t);return"string"!=typeof e?{error:"Invalid string literal"}:{value:e}}catch(e){return{error:"Invalid string literal"}}if(/^-?(0|[1-9]\d*)$/.test(t)&&!Number.isSafeInteger(Number(t)))try{return{value:BigInt(t)}}catch(e){return{error:"Invalid integer literal"}}try{const e=JSON.parse(t);return null===e||"number"==typeof e||"boolean"==typeof e?{value:e}:{error:"Unquoted value must be a number, true, false, or null"}}catch(e){return{error:"Unquoted value must be a number, true, false, or null"}}}function No(e){const t=_.get(e);if(t)return t.item.value;const n=P.get(e);return n?n.node.table.rows[n.r][n.c]:void 0}function Ao(e,t){"SourceEdit"===e.type?Wo(e,t):"SelfEdit"===e.type?jo(e,t):"DiffEdit"===e.type&&zd(e,t)}function jo(e,t){ll.value="do"===t?e.newValue:e.oldValue,Wl(),"split"===ol?hi():fi(!0)}function Wo(e,t){const n=w?Sn():null;x="do"===t?e.newValue:e.oldValue,j&&ss(),pa=null,ma=null,S=!0,L(),Zt(x),kn(),n&&Ln(n)}function Ho(){return tl&&!nl&&"split"===ol?{undo:hl[Ac],redo:pl[Ac]}:{undo:N,redo:A}}function Do(){const e=document.getElementById("undoBtn"),t=document.getElementById("redoBtn"),n=document.getElementById("undoMenuBtn"),o=document.getElementById("redoMenuBtn"),{undo:r,redo:l}=Ho();e&&(e.disabled=0===r.length),t&&(t.disabled=0===l.length),n&&(n.disabled=0===r.length),o&&(o.disabled=0===l.length)}function zo(e,t){return"python"===e?ds(String(t)):JSON.stringify(String(t))}function Fo(e,t){return"python"===e?us(t):gs(t)}function Ko(e,t,n,o){return e.slice(0,t)+o+e.slice(n)}function qo(e,t,n){if("SetValue"===e.type){const t=_.get(e.nodeId);if(t)return{oldPath:t.item.path,role:"value",newText:Fo(n,t.item.value)};const o=P.get(e.nodeId);return o?{oldPath:rc(o),role:"value",newText:Fo(n,o.node.table.rows[o.r][o.c])}:null}if("Rename"===e.type){const o="do"===t?e.oldKey:e.newKey,r=_.get(e.nodeId);if(r)return{oldPath:r.item.path.slice(0,-1).concat([o]),role:"key",newText:zo(n,r.item.key)};const l=B.get(e.nodeId);return l?{oldPath:l.path.slice(0,-1).concat([o]),role:"key",newText:zo(n,l.ownerKey)}:{unspliceable:!0}}return{unspliceable:!0}}function Xo(e){I.text=e,I.value=x,I.valid=!0,I.diagnostic=null,I.revision++,I.locations=wa(e,I.format),I.renderedText=e,pa=null}function Uo(e){Hs&&(clearTimeout(Hs),Hs=null),Ds&&(clearTimeout(Ds),Ds=null),Xo(e);const t=document.getElementById("sourcePanelInput");ta(Ta(t,e,Ws(document.getElementById("sourcePanelCode"),e,I.format,null,"single",I.locations,Fa("single")),"single")),Ma.single=t.value,Zs(),Vs()}function Vo(){if(!I||!C||"function"!=typeof C.serialize)return;let e;try{e=C.serialize(x)}catch(e){return}Uo(e)}function Yo(e,t){if(!I)return;if(qr){let n=null;if(e&&"SourceEdit"===e.type)n="do"===t?e.newText:e.oldText;else if(C&&"function"==typeof C.serialize)try{n=C.serialize(x)}catch(e){n=null}return void(null!=n&&Xo(n))}if(e&&"SourceEdit"===e.type)return void Uo("do"===t?e.newText:e.oldText);const n=I.format;if(e&&("json"===n||"python"===n)&&I.locations){const o=qo(e,t,n),r=o&&!o.unspliceable&&I.locations.lastByKey.get(ga(o.oldPath,o.role));if(r)return void Uo(Ko(I.text,r.from,r.to,o.newText))}Vo()}function Jo(e){return!(!e||e.text===e.baselineText)}function $o(){return Jo(I)}function Go(e){if(!nl)return e();const t=N,n=A,o=e();return N=t,A=n,Do(),o}function Zo(e){if(!tl||nl){if(j&&ss(),nl)return Ao(e,"do"),N.push(e),A.length=0,Do(),gd(e.newText),void dd();Ao(e,"do"),N.push(e),A.length=0,Do(),Yo(e,"do"),Qr(),"SourceEdit"!==e.type&&Sc(),wr(),Ri()}}function Qo(e,t){const n=hl[e];if(!n.length)return;if(Ad(e))return void Lu("Render the pending source edit before undoing");pr();const o=Math.min(t,n.length),r=[];for(let t=0;t<o;t++){const t=n.pop();Ao(t,"undo"),pl[e].push(t),r.push(t)}Do(),Dd(e,r[r.length-1].oldText),dd()}function er(e,t){const n=pl[e];if(!n.length)return;if(Ad(e))return void Lu("Render the pending source edit before redoing");pr();const o=Math.min(t,n.length),r=[];for(let t=0;t<o;t++){const t=n.pop();Ao(t,"do"),hl[e].push(t),r.push(t)}Do(),Dd(e,r[r.length-1].newText),dd()}function tr(e){if(tl&&!nl)return"split"===ol?Qo(Ac,e):void 0;if(!N.length)return;if(nl?Ld():qs())return void Lu("Render the pending edit before undoing");pr();const t=Math.min(e,N.length),n=[];if(nl){for(let e=0;e<t;e++){const e=N.pop();Ao(e,"undo"),A.push(e),n.push(e)}return Do(),gd(n[n.length-1].oldText),void dd()}for(let e=0;e<t;e++){const e=N.pop();Ao(e,"undo"),A.push(e),n.push(e)}Do(),Yo(1===n.length?n[0]:null,"undo"),Qr(),Sc(),wr(),Ri()}function nr(e){if(tl&&!nl)return"split"===ol?er(Ac,e):void 0;if(!A.length)return;if(nl?Ld():qs())return void Lu("Render the pending edit before redoing");pr();const t=Math.min(e,A.length),n=[];if(nl){for(let e=0;e<t;e++){const e=A.pop();Ao(e,"do"),N.push(e),n.push(e)}return Do(),gd(n[n.length-1].newText),void dd()}for(let e=0;e<t;e++){const e=A.pop();Ao(e,"do"),N.push(e),n.push(e)}Do(),Yo(1===n.length?n[0]:null,"do"),Qr(),Sc(),wr(),Ri()}function or(){tr(1)}function rr(){nr(1)}function lr(e){return Z(e)}function ir(e){return"SourceEdit"===e.type?{text:"edited source: "+xi(e.changes),ownerNode:null,selfKind:null,selfId:null}:"SelfEdit"===e.type?{text:"edited: "+xi(e.changes),ownerNode:null,selfKind:null,selfId:null}:"DiffEdit"===e.type?{text:"edited "+e.side+": "+xi(e.changes),ownerNode:null,selfKind:null,selfId:null}:{text:"",ownerNode:null,selfKind:null,selfId:null}}function sr(e){const t=[];let n=e;for(;n;)n.isRoot||null==n.id||t.push(n.id),n=n.parent;return t}let ar=[];function cr(){for(const e of ar)e.classList.remove("hist-hl");ar=[]}function dr(e){cr();const t=new Set,n=[];for(const o of e){const e=ir(o);e.selfKind&&n.push({kind:e.selfKind,id:e.selfId});for(const n of sr(e.ownerNode))t.add(n)}const o=document.getElementById("canvas");if(o){o.querySelectorAll(".dname, .tname").forEach(e=>{null!=e.__nodeId&&t.has(e.__nodeId)&&(e.classList.add("hist-hl"),ar.push(e))});for(const e of n)"pcell"===e.kind||"pk"===e.kind?o.querySelectorAll(".pcell").forEach(t=>{t.__id===e.id&&(t.classList.add("hist-hl"),ar.push(t))}):"td"===e.kind?o.querySelectorAll("td[title]").forEach(t=>{t.__cellId===e.id&&(t.classList.add("hist-hl"),ar.push(t))}):"th"===e.kind?o.querySelectorAll("th[title]").forEach(t=>{t.__colId===e.id&&(t.classList.add("hist-hl"),ar.push(t))}):"name"===e.kind&&o.querySelectorAll(".dname, .tname").forEach(t=>{t.__nodeId===e.id&&(t.classList.add("hist-hl"),ar.push(t))})}}let ur=null,fr=null,hr=null;function pr(){cr(),ur&&(ur.remove(),ur=null),fr&&(fr(),fr=null),hr=null}function mr(e){const t=Ho(),n="undo"===e?t.undo:t.redo,o=document.createElement("div");if(o.className="history-menu",!n.length){const t=document.createElement("div");return t.className="history-empty",t.textContent="Nothing to "+e,o.appendChild(t),o}const r=[],l=()=>{for(const e of r)e.classList.remove("history-row-pending")};for(let t=n.length-1,i=1;t>=0;t--,i++){const s=ir(n[t]),a=document.createElement("div");a.className="history-row",a.textContent=s.text,a.title=s.text;const c=i;a.addEventListener("mouseenter",()=>{l();for(let e=0;e<c;e++)r[e].classList.add("history-row-pending");dr(n.slice(n.length-c))}),a.addEventListener("mouseleave",()=>{l(),cr()}),a.addEventListener("click",()=>{pr(),"undo"===e?tr(c):nr(c)}),r.push(a),o.appendChild(a)}return o}function gr(e,t){const n=ur&&hr===e;if(pr(),n)return;_o();const o=mr(e);document.body.appendChild(o);const r=t.getBoundingClientRect(),l=o.offsetWidth;o.style.left=Math.max(8,Math.min(r.left,window.innerWidth-l-8))+"px",o.style.top=r.bottom+6+"px",hr=e,ur=o,fr=To(o,{dismiss:pr,ignore:t})}function yr(e){if(e instanceof Set)return new Set([...e].map(yr));if(Array.isArray(e))return e.map(yr);if(e&&"object"==typeof e){const t={};for(const n of Object.keys(e))t[n]=yr(e[n]);return t}return e}function vr(){wr(),Qr()}function wr(){const e=$o(),t=!(!C||"function"!=typeof C.serialize),n=e&&!(!I||I.valid)&&!qr,o=t?n?"Save source (graph is stale — current source text hasn't reparsed successfully)":"Save the edited data (Ctrl+S)":"This source format has no serializer — can't save back",r=document.getElementById("saveBtn");r&&(r.disabled=!e||!t,r.title=o,r.setAttribute("aria-label",n?"Save source (graph is stale)":"Save"));const l=document.getElementById("hostSaveBtn");l&&(l.disabled=!e||!t,l.title=o)}function br(){return C&&"function"==typeof C.serialize?C.serialize(x):null}function xr(){return tl&&nl?ll?ll.text:null:I&&!qr?I.text:br()}function kr(e){const t=e||"json";return[{description:t.toUpperCase()+" file",accept:{[{json:"application/json",py:"text/x-python",xml:"application/xml",html:"text/html"}[t]||"text/plain"]:["."+t]}}]}async function Er(){if(tl)return void Lu("Diff mode is read-only — nothing to save.");if(!C||"function"!=typeof C.serialize)return void Lu("This format has no serializer — can't save back");if(!$o())return void Lu("Nothing to save");const e=xr();if(null==e)return void Lu("This format has no serializer — can't save back");if(Fr)return Vr({type:"structile-save-requested",format:C.kind,ext:C.ext||"json",fileName:k,isSaveAs:!1,content:e}),I&&(I.baselineText=I.text),vr(),Ri(),void Lu("Save requested");if("function"==typeof window.showSaveFilePicker){const t=C.ext||"json";let n;try{n=await window.showSaveFilePicker({suggestedName:k+"."+t,types:kr(t)})}catch(e){if(e&&"AbortError"===e.name)return;return void Lu("Could not open save dialog: "+(e&&e.message||e))}try{const t=await n.createWritable();await t.write(e),await t.close()}catch(e){return void Lu("Could not write the file: "+(e&&e.message||e))}return n.name&&(k=n.name.replace(/\.[^./\\]+$/,"")),Ou(),Lu("Saved "+(n.name||k)),void jr(e)}const t=prompt("Save as (file name, without extension):",k);if(null==t||!t.trim())return;k=t.trim(),Ou();const n=k+"."+(C.ext||"json");ru(n,e),Lu("Saved "+n),jr(e)}function Sr(){Er()}function Lr(){Kr&&Vr({type:"structile-graph-save-requested"})}function Cr(e){if(tl&&nl){if(!e)return void Rd()}else if(tl)return void Vr({type:"structile-save-requested",error:"Diff mode is read-only — nothing to save."});if(!C||"function"!=typeof C.serialize)return void Vr({type:"structile-save-requested",error:"This format has no serializer — can't save back"});const t=xr();null!=t?(Vr({type:"structile-save-requested",format:C.kind,ext:C.ext||"json",fileName:k,isSaveAs:!1,content:t}),e||(I&&(I.baselineText=I.text),vr(),Ri())):Vr({type:"structile-save-requested",error:"This format has no serializer — can't save back"})}function Ir(e){const t=(e||"").trim();return t?/[\\/:*?"<>|\x00-\x1f]/.test(t)?{error:'Name can’t contain \\ / : * ? " < > |'}:"."===t||".."===t?{error:"Invalid name"}:{value:t}:{error:"Enter a file name"}}function Mr(e){if(tl)return void Lu("Diff mode is read-only — nothing to save.");if(!C||"function"!=typeof C.serialize)return void Lu("This format has no serializer — can't save back");const t=xr();null!=t?(Vr({type:"structile-save-requested",format:C.kind,ext:C.ext||"json",fileName:e,isSaveAs:!0,content:t}),k=e,E=!0,Ou(),I&&(I.baselineText=I.text),vr(),Ri(),Lu("Saved as "+e+"."+(C.ext||"json"))):Lu("This format has no serializer — can't save back")}let Tr=null;function Or(){Tr&&(Tr.el.remove(),Tr.teardown(),Tr=null)}function Br(e){if(Tr)return void Or();const t=C&&C.ext||"json",n=document.createElement("div");n.className="about-pop";const o=document.createElement("h4");o.textContent="Save As";const r=document.createElement("div");r.className="desc",r.textContent="Writes a new "+t.toUpperCase()+" file under this name. The current file is left untouched; further saves go to the new one.";const l=document.createElement("div");l.className="panel-row";const i=document.createElement("input");i.type="text",i.id="saveAsNameInput",i.className="editpop-input",i.spellcheck=!1,i.style.width="160px",i.value=k;const s=document.createElement("span");s.textContent="."+t,s.className="desc",s.style.marginBottom="0",l.appendChild(i),l.appendChild(s);const a=document.createElement("div");a.className="editpop-err",a.style.display="none";const c=document.createElement("div");c.className="panel-row",c.style.marginTop="8px";const d=document.createElement("button");d.type="button",d.id="saveAsConfirmBtn",d.className="btn sm",d.textContent="Save";const u=document.createElement("button");u.type="button",u.id="saveAsCancelBtn",u.className="btn sm ghost",u.textContent="Cancel",c.appendChild(d),c.appendChild(u),n.appendChild(o),n.appendChild(r),n.appendChild(l),n.appendChild(a),n.appendChild(c),document.body.appendChild(n);const f=e.getBoundingClientRect(),h=n.offsetWidth;n.style.left=Math.max(8,Math.min(f.right-h,window.innerWidth-h-8))+"px",n.style.top=f.bottom+6+"px",i.focus(),i.select();const p=()=>{const e=Ir(i.value);if(e.error)return a.textContent=e.error,a.style.display="block",void i.focus();Or(),Mr(e.value)};d.addEventListener("click",p),u.addEventListener("click",Or),i.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),p())});const m=To(n,{dismiss:Or,ignore:e});Tr={el:n,teardown:m}}const _r="structile-handoff-";let Rr="";function Pr(){return Date.now().toString(36)+Math.random().toString(36).slice(2,10)}function Nr(e,t){const n={fileName:t,kind:C.kind,text:e};return"xml"===C.kind&&(n.xmlMode=C.mode,n.xmlExt=C.ext,n.format=C.format,n.interpreterSource=C.interpreterSource||""),n}function Ar(){const e=document.documentElement.cloneNode(!0);return e.querySelectorAll("script").forEach(e=>{/^\s*window\.__STRUCTILE_SNAPSHOT__\s*=/.test(e.textContent||"")&&e.remove()}),"<!DOCTYPE html>\n"+e.outerHTML}function jr(e){if("undefined"==typeof BroadcastChannel)return void Lu("Saved "+k+" — this browser can't auto-open a clean copy in a new tab; reload manually to start one.");const t=Pr(),n=window.open("","_blank");if(!n)return void Lu("Saved "+k+" — allow popups to open the saved copy in a new tab.");const o=Nr(e,k),r=new BroadcastChannel("structile-handoff-"+t),l=e=>{e.data&&"structile-handoff-hello"===e.data.type&&(r.postMessage({type:"structile-handoff-payload",payload:o}),r.removeEventListener("message",l),setTimeout(()=>r.close(),1e3))};r.addEventListener("message",l);try{n.name=_r+t,n.document.open(),n.document.write(Rr||Ar()),n.document.close()}catch(e){r.removeEventListener("message",l),r.close();try{n.close()}catch(e){}return void Lu("Saved "+k+" — could not open the clean viewer tab: "+(e&&e.message||e))}setTimeout(()=>{r.removeEventListener("message",l),r.close()},15e3)}function Wr(){try{const e=new URL(location.href).searchParams.get("handoff");if(e)return e}catch(e){}try{return window.name&&window.name.startsWith(_r)?window.name.slice(_r.length):null}catch(e){return null}}function Hr(){try{const e=new URL(location.href);e.searchParams.delete("handoff"),history.replaceState(null,"",e.href)}catch(e){}try{window.name.startsWith(_r)&&(window.name="")}catch(e){}}function Dr(e){try{let t;if("python"===e.kind)t=vs;else if("xml"===e.kind){const n=Du(e.interpreterSource||"");if("function"!=typeof(e.xmlMode?n.interpretFn:n.interpretTextFn))throw new Error("handed-off interpreter script is missing "+(e.xmlMode?"interpretXML":"interpretText"));t=ws(n,e.xmlMode||null,e.format||e.xmlExt),t.interpreterSource=e.interpreterSource||""}else t=ys;Bu(t.parse(e.text),e.fileName||"data",t,{rawText:e.text}),Lu("Opened the saved copy of "+(e.fileName||"data"))}catch(e){Lu("Could not open the saved copy: "+(e&&e.message||e)),bf()}}function zr(e){const t=Wr();if(!t||"undefined"==typeof BroadcastChannel)return void e(!1);Hr();let n=!1;const o=new BroadcastChannel("structile-handoff-"+t),r=t=>{n||(n=!0,e(t))};o.addEventListener("message",e=>{e.data&&"structile-handoff-payload"===e.data.type&&(Dr(e.data.payload),r(!0),setTimeout(()=>o.close(),500))}),o.postMessage({type:"structile-handoff-hello"}),setTimeout(()=>{n||(o.close(),r(!1))},4e3)}let Fr=!1,Kr=!1,qr=!1;function Xr(e){e.disableSourceView&&(qr=!0,document.body.classList.add("structile-source-view-disabled"))}function Ur(){Fr||(Fr=!0,document.body.classList.add("embedded"))}function Vr(e){const t=window.parent&&window.parent!==window?window.parent:window.opener;t&&t.postMessage(e,"*")}function Yr(e){e.config&&yu(e.config,"host config");const t="string"==typeof e.name&&!!e.name,n=t?e.name:"data";if(void 0!==e.value)return void Bu(e.value,n,ys,{hasRealName:t});if("string"!=typeof e.text)return;if(!e.format&&e.interpreterCandidatesByFormat&&Object.keys(e.interpreterCandidatesByFormat).length)return void Uu(e.text,e.interpreterCandidatesByFormat,n);const o=e.format||"json";if("json"===o)try{Bu(ms(e.text),n,ys,{hasRealName:t,rawText:e.text})}catch(e){Lu("Could not parse embedded JSON: "+e.message)}else if("python"===o)try{Bu(cs(e.text),n,vs,{rawText:e.text})}catch(e){Lu("Could not parse embedded Python data: "+e.message)}else{const t=Ju(o);("string"==typeof e.interpreterSource?!!e.interpreterSource:Array.isArray(e.interpreterSource)&&e.interpreterSource.length>0)?Xu(e.text,e.interpreterSource,t,n,o,e.interpreterCandidateNames):Vu(e.text,t,n,o)}}function Jr(e){Ur(),e.hostManagesSave&&(Kr=!0,document.body.classList.add("host-manages-save")),Xr(e),e.enableSettingsPanel&&document.body.classList.add("structile-settings-panel-enabled")}function $r(e){Jr(e),Yr(e)}function Gr(e){const t=e.data;t&&"object"==typeof t&&("structile-embed-init"===t.type?$r(t):"structile-embed-diff-init"===t.type?(Jr(t),Ll(t)):"structile-embed-interpreter"===t.type&&"string"==typeof t.source?(Ur(),Yu(t.source,"string"==typeof t.name?t.name:void 0)):"structile-embed-request-save"===t.type?Cr(!!t.forBackup):"structile-embed-select-range"===t.type?uc(t):"structile-embed-fold-range"===t.type?Lc(t):"structile-embed-text-changed"===t.type?ra(t.text):"structile-embed-source-saved"===t.type&&la(t.text))}function Zr(){try{("1"===new URL(location.href).searchParams.get("embed")||"about:srcdoc"===location.href)&&Ur()}catch(e){}window.addEventListener("message",Gr)}function Qr(){if(!Fr)return;const e=$o();Vr({type:"structile-dirty-state-changed",dirty:e,totalCount:e?1:0})}function el(){if(!Fr||!cl)return;const e=Il(cl),t=Object.values(e).reduce((e,t)=>e+t,0);Vr({type:"structile-dirty-state-changed",dirty:t>0,totalCount:t})}let tl=!1,nl=!1,ol="unified",rl=null,ll=null,il="",sl="",al=null,cl=null,dl=new Map,ul=new Map,fl=new Map,hl={left:[],right:[]},pl={left:[],right:[]};function ml(){tl&&(nc(),tl=!1,nl=!1,rl=null,ll=null,il="",sl="",al=null,cl=null,Vl=[],Yl=[],Jl=[],$l=null,Gl=null,Zl=null,Ql=null,dl=new Map,ul=new Map,fl=new Map,Nl=new Map,Al=new Map,Wc(),m="canvas",g="canvasWrap",document.body.classList.remove("structile-diff-mode"),document.body.classList.remove("structile-diff-split"),di())}function gl(){ml(),S?(M.collapsed=new Set,M.minimized=new Set,M.large=new Set,M.detached=new Set,Zt(x),kn(),Ri(),document.getElementById("canvasWrap").scrollTo(0,0)):bf()}function yl(){return!nl||(gl(),wr(),Qr(),!0)}function vl(e,t,n){return wl(e,t,n).value}function wl(e,t,n){if("json"===e)return{value:ms(t),serialize:ys.serialize};if("python"===e)return{value:cs(t),serialize:vs.serialize};if(!(Array.isArray(n)?n.length>0:!!n))throw new Error(e+" diff needs an interpreterSource");const o=Ju(e),r=zu(t,o,n);if(!r.ok){const e=r.attempts[r.attempts.length-1];throw new Error(r.attempts.length>1?"none of "+r.attempts.length+" interpreters worked — "+(e?e.error:""):e?e.error:"interpreter failed")}return{value:r.value,serialize:(o?r.serializeFn:r.serializeTextFn)||null}}function bl(e,t,n){const o=e.format||"json",r="string"==typeof e.name&&e.name?e.name:n;try{const{value:n,serialize:l}=wl(o,e.text,t);return{name:r,format:o,text:e.text,value:n,serialize:l}}catch(e){throw new Error(("left"===n?"Left":"Right")+" side: "+(e&&e.message||e))}}function xl(e){const t=e.format||"json";return{name:e.name,value:e.value,...Ls(e.text,t),serialize:e.serialize||null}}function kl(e,t,n,o,r,l,i){j&&ss(),nc(),tl=!0,rl=xl(e),ll=xl(t),il=n||"",sl=o||"",al=l&&l.length?l:null,ol="split"===r?"split":"unified",hl={left:[],right:[]},pl={left:[],right:[]},Wl(),Ul="full",document.body.classList.add("structile-diff-mode"),document.body.classList.toggle("structile-diff-split","split"===ol),Wc(),fi(i),Do(),wr(),dd()}function El(){if(nl)return;const e=Ul;kl(ll,rl,sl,il,ol,al),e!==Ul&&(Ul=e,fi())}function Sl(e){if(tl||!I||!S)return!1;if(!C||"function"!=typeof C.parse)return!1;const t="string"==typeof e?e:I.text;let n;try{n=C.parse(t)}catch(e){return Lu("Can't edit — the current source doesn't parse: "+(e&&e.message||e)),!1}const o={name:k,format:I.format,text:t,value:x},r={name:k,format:I.format,text:t,value:n},l=C.interpreterSource||"";return nl=!0,N=[],A=[],kl(o,r,l,l,"unified",null,!0),!0}function Ll(e){if(e.config&&yu(e.config,"host config"),!e.left||!e.right||"string"!=typeof e.left.text||"string"!=typeof e.right.text)return Lu("Diff init is missing left/right data"),!1;const t=e.leftInterpreterSource||e.interpreterSource,n=e.rightInterpreterSource||e.interpreterSource;let o,r;try{o=bl(e.left,t,"left"),r=bl(e.right,n,"right")}catch(e){return Lu("Could not load diff: "+(e&&e.message||e)),!1}return kl(o,r,t||"",n||"",e.diff&&e.diff.view||"unified",e.keyColumns||null),!0}function Cl(e,t){for(const n in t)e[n]=(e[n]||0)+t[n];return e}function Il(e){if(!e||"equal"===e.status)return{};if("mixed"===e.status){const t={mixed:1};for(const n of e.children||[])Cl(t,Il(n));return t}if("added"===e.status||"removed"===e.status){const t={};return t[e.status]=1,t}if(!e.children||!e.children.length){const t={};return t[e.status]=1,t}const t={};for(const n of e.children)Cl(t,Il(n));return 0===Object.values(t).reduce((e,t)=>e+t,0)&&(t[e.status]=1),t}const Ml={added:"Added: present only on the right side.",removed:"Removed: present only on the left side.",changed:"Changed: same location and type, different value.",typeChanged:"Type changed: same location, but a different JSON type entirely (e.g. number vs string, or an object vs an array) — never treated as a value change.",orderChanged:"Order changed: the same values on both sides, just in a different position (arrays/tables only — object keys and set members have no order to change).",mixed:"Mixed: both reordered AND value-changed within the same container."},Tl="Counts each distinct difference once — a changed value, a whole added/removed subtree, or a moved item/row — never the container that holds it. A container (object/array/table) only adds to a count directly when it holds a difference no single child can represent on its own (for example: a table whose only difference is column order or a renamed column, with every cell and row otherwise identical).";function Ol(e){return void 0===e?"":Z(e)}function Bl(e){return void 0===e?"":e instanceof Set?"{"+[...e].map(Bl).join(", ")+"}":Array.isArray(e)?"["+e.map(Bl).join(", ")+"]":J(e)?"{"+Object.keys(e).map(t=>JSON.stringify(t)+": "+Bl(e[t])).join(", ")+"}":Z(e)}function _l(e){return"added"===e?"diff-added":"removed"===e?"diff-removed":"changed"===e||"typeChanged"===e?"diff-changed":null}function Rl(e){return new Map((e.match&&e.match.renamedColumns||[]).map(e=>[e.right,e.left]))}function Pl(e,t,n){if(!e)return;if(e.leftPath=t,e.rightPath=n,!e.children||!e.children.length)return;const o=e.kind;if("object"===o)for(const o of e.children){const e=o.path[o.path.length-1].k,r="added"===o.status?null:null!=o.renamedFrom?o.renamedFrom:e,l="removed"===o.status?null:e;Pl(o,null==r||null==t?null:t.concat([r]),null==l||null==n?null:n.concat([l]))}else if("set"===o)for(const o of e.children){const r=o.path[o.path.length-1].k;let l=null,i=null;if("added"!==o.status&&null!=t&&e.left){const t=[...e.left].findIndex(e=>it(e)===r);-1!==t&&(l=t)}if("removed"!==o.status&&null!=n&&e.right){const t=[...e.right].findIndex(e=>it(e)===r);-1!==t&&(i=t)}Pl(o,null==l?null:t.concat([l]),null==i?null:n.concat([i]))}else if("array"===o)for(const o of e.children){const e=o.path[o.path.length-1],r=e.i,l=e.ri;Pl(o,null==r||null==t?null:t.concat([r]),null==l||null==n?null:n.concat([l]))}else if("table"===o){const o=Rl(e),r=nt(e.left),l=nt(e.right),i="grid"===r.mode&&r.dataStart||0,s="grid"===l.mode&&l.dataStart||0,a=e=>"grid"===r.mode?r.colKeys.indexOf(e):e,c=e=>"grid"===l.mode?l.colKeys.indexOf(e):e;for(const r of e.children){const e=r.path[r.path.length-1];let l=null,d=null;r.order&&null!=r.order.fromIndex&&null!=r.order.toIndex?(l=r.order.fromIndex,d=r.order.toIndex):e.k&&"number"==typeof e.k.index&&("removed"===r.status?l=e.k.index:d=e.k.index);const u=null==l||null==t?null:t.concat([l+i]),f=null==d||null==n?null:n.concat([d+s]);r.leftPath=u,r.rightPath=f;for(const e of r.children){const t=e.path[e.path.length-1].k,n=a(o.has(t)?o.get(t):t),r=c(t);Pl(e,"added"===e.status||null==u||-1===n?null:u.concat([n]),"removed"===e.status||null==f||-1===r?null:f.concat([r]))}}}}let Nl=new Map,Al=new Map;function jl(e,t,n){if(e&&(null!=e.leftPath&&t.set(ie(e.leftPath),e),null!=e.rightPath&&n.set(ie(e.rightPath),e),e.children))for(const o of e.children)jl(o,t,n)}function Wl(){cl=zt(rl.value,ll.value,al&&al.length?{keyColumns:al}:{}),Pl(cl,[],[]),Nl=new Map,Al=new Map,jl(cl,Nl,Al)}function Hl(e,t,n,o,r,l){if(!e)return null;l&&l.set(ie(t),e),e.supersetPath=t;const i=e.kind;if("primitive"===i)return o||"equal"===e.status||n.push({t:"item",path:t,cls:_l(e.status)}),"removed"===e.status?e.left:"added"===e.status?e.right:"equal"===e.status?e.left:Ol(e.left)+" → "+Ol(e.right);if("mixed"===i)return o||n.push({t:"item",path:t,cls:"diff-changed"}),Bl(e.left)+" → "+Bl(e.right);if("object"===i){let i=o;o||"added"!==e.status&&"removed"!==e.status||(n.push({t:"container",path:t,cls:_l(e.status)}),i=!0);const s={};for(const o of e.children){if(r&&"equal"===o.status)continue;const e=o.path[o.path.length-1].k,a=o.renamedFrom?o.renamedFrom+" → "+e:e,c=t.concat([a]);o.renamedFrom&&!i&&"primitive"!==o.kind&&"mixed"!==o.kind&&n.push({t:"container",path:c,cls:"diff-changed",nameOnly:!0}),s[a]=Hl(o,c,n,i,r,l)}return s}if("set"===i){let i=o;o||"added"!==e.status&&"removed"!==e.status||(n.push({t:"container",path:t,cls:_l(e.status)}),i=!0);const s=e.children.slice().sort((e,t)=>{const n=e.path[e.path.length-1].k,o=t.path[t.path.length-1].k;return n<o?-1:n>o?1:0}),a=r?s.filter(e=>"equal"!==e.status):s,c=new Set;return a.forEach((e,o)=>{i||"equal"===e.status||n.push({t:"item",path:t.concat([o]),cls:_l(e.status)}),c.add(Hl(e,t.concat([o]),n,i,r,l))}),c}if("array"===i){let i=o;o||"added"!==e.status&&"removed"!==e.status||(n.push({t:"container",path:t,cls:_l(e.status)}),i=!0);const s=r?e.children.filter(e=>"equal"!==e.status):e.children,a=[];return s.forEach((e,o)=>{i||("orderChanged"===e.status?n.push({t:"rowOrder",tablePath:t,row:o}):"equal"!==e.status&&n.push({t:"cell",tablePath:t,row:o,col:0,cls:_l(e.status)||"diff-changed"})),a.push(Hl(e,t.concat([o]),n,i,r,l))}),a}if("table"===i){let i=o;o||"added"!==e.status&&"removed"!==e.status||(n.push({t:"container",path:t,cls:_l(e.status)}),i=!0);const s=e.order?e.order.canonicalColumns:e.children[0]?e.children[0].children.map(e=>e.path[e.path.length-1].k):[],a=r?e.children.filter(e=>"equal"!==e.status):e.children,c=new Set(e.match&&e.match.keyColumns||[]),d=new Map((e.match&&e.match.renamedColumns||[]).map(e=>[e.right,e.left]));let u=r?s.filter(t=>c.has(t)||e.match&&e.match.addedColumns.includes(t)||e.match&&e.match.removedColumns.includes(t)||d.has(t)||e.order&&e.order.movedColumns&&e.order.movedColumns.has(t)||e.children.some(e=>{const n=e.children.find(e=>e.path[e.path.length-1].k===t);return n&&"equal"!==n.status})):s;return r&&!u.length&&(u=s),i||u.forEach((o,r)=>{d.has(o)?n.push({t:"colHeader",tablePath:t,col:r,cls:"diff-changed"}):e.match.addedColumns.includes(o)?n.push({t:"colHeader",tablePath:t,col:r,cls:"diff-added"}):e.match.removedColumns.includes(o)?n.push({t:"colHeader",tablePath:t,col:r,cls:"diff-removed"}):e.order.movedColumns&&e.order.movedColumns.has(o)&&n.push({t:"colHeader",tablePath:t,col:r,cls:"diff-order"})}),a.map((e,o)=>{!i&&e.order&&e.order.changed&&n.push({t:"rowOrder",tablePath:t,row:o});const s=new Map(e.children.map(e=>[e.path[e.path.length-1].k,e])),a={};return l&&l.set(ie(t.concat([o])),e),e.supersetPath=t.concat([o]),u.forEach((e,u)=>{const f=d.has(e)?d.get(e)+" → "+e:e,h=s.get(e);h?(i||"equal"===h.status||n.push({t:"cell",tablePath:t,row:o,col:u,cls:_l(h.status)}),!r||"equal"!==h.status||c.has(e)?a[f]=Hl(h,t.concat([o,f]),n,i,r,l):a[f]=null):a[f]=null}),a})}return null}function Dl(e,t){return"left"===t?"added"===e.status:"removed"===e.status}function zl(e,t){const n="left"===t?e.left:e.right;return Dl(e,t)?"left"===t?e.right:e.left:n}function Fl(e,t){return"added"===e.status||"removed"===e.status?{cls:"left"===t?"diff-removed":"diff-added",strike:Dl(e,t)}:"changed"===e.status||"typeChanged"===e.status?{cls:"diff-changed",strike:!1}:null}function Kl(e,t,n,o,r,l,i){if(!e)return null;i&&i.set(ie(t),e),"left"===o?e.sidePathLeft=t:e.sidePathRight=t;const s=zl(e,o),a=Fl(e,o),c=e.kind;if("primitive"===c)return"equal"===e.status||"orderChanged"===e.status||!r&&a&&n.push({t:"item",path:t,cls:a.cls,strike:a.strike}),s;if("mixed"===c)return!r&&a&&n.push({t:"item",path:t,cls:a.cls,strike:a.strike}),Bl(s);if("object"===c){const s=r;r||"added"!==e.status&&"removed"!==e.status||n.push({t:"container",path:t,cls:a.cls,strike:a.strike});const c={};for(const r of e.children){if(l&&"equal"===r.status)continue;const e=r.path[r.path.length-1].k,a="primitive"===r.kind||"mixed"===r.kind,d=r.renamedFrom?a?"left"===o?r.renamedFrom:e:r.renamedFrom+" → "+e:e,u=t.concat([d]);!r.renamedFrom||s||a||n.push({t:"container",path:u,cls:"diff-changed",nameOnly:!0}),c[d]=Kl(r,u,n,o,s,l,i)}return c}if("set"===c){const s=r;r||"added"!==e.status&&"removed"!==e.status||n.push({t:"container",path:t,cls:a.cls,strike:a.strike});const c=e.children.slice().sort((e,t)=>{const n=e.path[e.path.length-1].k,o=t.path[t.path.length-1].k;return n<o?-1:n>o?1:0}),d=l?c.filter(e=>"equal"!==e.status):c,u=new Set;return d.forEach((e,r)=>{u.add(Kl(e,t.concat([r]),n,o,s,l,i))}),u}if("array"===c){const s=r;r||"added"!==e.status&&"removed"!==e.status||n.push({t:"container",path:t,cls:a.cls,strike:a.strike});const c=l?e.children.filter(e=>"equal"!==e.status):e.children,d=[];return c.forEach((e,r)=>{if(!s)if("orderChanged"===e.status)n.push({t:"rowOrder",tablePath:t,row:r});else if("equal"!==e.status){const l=Fl(e,o);l&&n.push({t:"cell",tablePath:t,row:r,col:0,cls:l.cls,strike:l.strike})}d.push(Kl(e,t.concat([r]),n,o,!0,l,i))}),d}if("table"===c){const s=r;r||"added"!==e.status&&"removed"!==e.status||n.push({t:"container",path:t,cls:a.cls,strike:a.strike});const c=e.order?e.order.canonicalColumns:e.children[0]?e.children[0].children.map(e=>e.path[e.path.length-1].k):[],d=l?e.children.filter(e=>"equal"!==e.status):e.children,u=new Set(e.match&&e.match.keyColumns||[]),f=new Map((e.match&&e.match.renamedColumns||[]).map(e=>[e.right,e.left]));let h=l?c.filter(t=>u.has(t)||e.match&&e.match.addedColumns.includes(t)||e.match&&e.match.removedColumns.includes(t)||f.has(t)||e.order&&e.order.movedColumns&&e.order.movedColumns.has(t)||e.children.some(e=>{const n=e.children.find(e=>e.path[e.path.length-1].k===t);return n&&"equal"!==n.status})):c;return l&&!h.length&&(h=c),s||h.forEach((r,l)=>{if(f.has(r))n.push({t:"colHeader",tablePath:t,col:l,cls:"diff-changed"});else if(e.match&&e.match.addedColumns.includes(r)){const e=Fl({status:"added"},o);n.push({t:"colHeader",tablePath:t,col:l,cls:e.cls,strike:e.strike})}else if(e.match&&e.match.removedColumns.includes(r)){const e=Fl({status:"removed"},o);n.push({t:"colHeader",tablePath:t,col:l,cls:e.cls,strike:e.strike})}else e.order&&e.order.movedColumns&&e.order.movedColumns.has(r)&&n.push({t:"colHeader",tablePath:t,col:l,cls:"diff-order"})}),d.map((e,r)=>{const a=!s&&("added"===e.status||"removed"===e.status),c=a?Fl(e,o):null;!s&&!a&&e.order&&e.order.changed&&n.push({t:"rowOrder",tablePath:t,row:r});const d=new Map(e.children.map(e=>[e.path[e.path.length-1].k,e])),p={};return i&&i.set(ie(t.concat([r])),e),"left"===o?e.sidePathLeft=t.concat([r]):e.sidePathRight=t.concat([r]),h.forEach((e,h)=>{const m="left"===o&&f.has(e)?f.get(e):e,g=d.get(e);if(!g)return p[m]=null,void(a&&n.push({t:"cell",tablePath:t,row:r,col:h,cls:c.cls,strike:c.strike}));if(a)return n.push({t:"cell",tablePath:t,row:r,col:h,cls:c.cls,strike:c.strike}),void(p[m]=Kl(g,t.concat([r,m]),n,o,!0,l,i));if(!s&&"equal"!==g.status){const e=Fl(g,o);e&&n.push({t:"cell",tablePath:t,row:r,col:h,cls:e.cls,strike:e.strike})}!l||"equal"!==g.status||u.has(e)?p[m]=Kl(g,t.concat([r,m]),n,o,!0,l,i):p[m]=null}),p})}return null}function ql(e){const t=[],n=e=>{t.length?t[t.length-1]+=e:t.push(e)};for(const o of e.path||[])"key"===o.t||"col"===o.t?t.push(o.k):"member"===o.t?t.push("{"+o.k+"}"):"row"===o.t?n("["+(o.k&&"object"==typeof o.k?Object.entries(o.k).map(([e,t])=>e+"="+Ol(t)).join(","):o.k)+"]"):"item"===o.t&&n("["+(null!=o.i?o.i:"+"+o.ri)+"]");return t.length?t.join("/"):"(root)"}function Xl(e,t){if(e&&"equal"!==e.status&&"primitive"!==e.kind&&"mixed"!==e.kind)if("added"!==e.status&&"removed"!==e.status&&"table"!==e.kind){if("object"===e.kind||"set"===e.kind||"array"===e.kind){if(e.children.some(e=>"equal"!==e.status&&("primitive"===e.kind||"mixed"===e.kind||"added"===e.status||"removed"===e.status||e.renamedFrom))||"object"!==e.kind)return void t.push(e);for(const n of e.children)Xl(n,t)}}else t.push(e)}let Ul="full",Vl=[],Yl=[],Jl=[],$l=null,Gl=null,Zl=null,Ql=null,ei=!1;function ti(){return tl?"split"!==ol?Vl:"canvasLeft"===m?Yl:Jl:[]}function ni(e){e&&(w=e.ROOT,b=e.NODES,B=e.NODE_BY_ID,_=e.ITEM_BY_ID,R=e.COLUMN_BY_ID,P=e.CELL_BY_ID)}function oi(e){let t=e;for(;t&&t.parent;)t=t.parent;return t&&Zl&&t===Zl.ROOT?{canvas:"canvasLeft",wrap:"canvasWrapLeft",regs:Zl}:t&&Ql&&t===Ql.ROOT?{canvas:"canvasRight",wrap:"canvasWrapRight",regs:Ql}:null}function ri(e,t){j&&ss();const n=t&&w?Sn():null;t||(M.collapsed=new Set,M.minimized=new Set,M.large=new Set,M.detached=new Set),Go(()=>{Zt(e)}),kn(),n&&Ln(n),Ri()}function li(e,t){const n=t||y();if(!n||!e||!e.length)return;const o=new Map;for(const[e,t]of _)o.set(ie(t.item.path),e);const r=(e,t,n)=>{e.has(t)?e.get(t).push(n):e.set(t,[n])},l=new Map,i=new Map,s=new Map,a=new Map;n.querySelectorAll(".pcell").forEach(e=>r(l,e.__id,e)),n.querySelectorAll(".dname, .tname").forEach(e=>r(i,e.__nodeId,e)),n.querySelectorAll("td[title]").forEach(e=>r(s,e.__cellId,e)),n.querySelectorAll("th[title]").forEach(e=>r(a,e.__colId,e));const c=(e,t,n)=>{t&&e.classList.add(t),n&&e.classList.add("diff-struck")},d=(e,t,n)=>{if(e)for(const o of e)c(o,t,n)},u=(e,t,n)=>{if(e)for(const o of e)c(o.closest(".box")||o,t,n)};for(const t of e)if("item"===t.t)d(l.get(o.get(ie(t.path))),t.cls,t.strike);else if("container"===t.t){const e=b.get(ie(t.path));if(e){const n=i.get(e.id);t.nameOnly?d(n,t.cls,t.strike):u(n,t.cls,t.strike)}}else if("cell"===t.t){const e=b.get(ie(t.tablePath)),n=e&&e.table&&e.table.cellIds[t.row]&&e.table.cellIds[t.row][t.col];if(null!=n){const e=s.get(n);if(e)for(const n of e)c(n,t.cls,t.strike)}}else if("colHeader"===t.t){const e=b.get(ie(t.tablePath)),n=e&&e.table&&e.table.colIds&&e.table.colIds[t.col];if(null!=n){const e=a.get(n);if(e)for(const n of e)c(n,t.cls,t.strike)}}else if("rowOrder"===t.t){const e=b.get(ie(t.tablePath)),n=e&&e.table&&e.table.cellIds[t.row]&&e.table.cellIds[t.row][0],o=null!=n?s.get(n):null;if(o)for(const e of o){const t=e.closest("tr");t&&t.classList.add("diff-row-order")}}}let ii=null;function si(){ii&&(ii.btn&&ii.btn.setAttribute("aria-expanded","false"),ii.el.remove(),ii.teardown(),ii=null)}function ai(e,t,n,o){const r=ol===e&&Ul===t;return'<div class="diff-help-scope'+(r?" active":"")+'"><b>'+n+"</b>"+(r?' <span class="diff-help-tag">current</span>':"")+" — "+o+"</div>"}function ci(e){if(ii)return void si();const t=document.createElement("div");t.className="diff-help-pop",t.setAttribute("role","dialog"),t.setAttribute("aria-label","Diff view guide");const n="split"===ol,o="unified"===ol;t.innerHTML='<h4>What the diff views show</h4><div class="diff-help-grid"><section class="diff-help-col'+(n?" active":"")+'"><h5>Split</h5>'+ai("split","full","Full","Complete left and right data in aligned panes. One-sided data is red on the left and green on the right, with the missing-side copy struck through; changed values are amber on both sides.")+ai("split","compact","Compact","The innermost changed containers in two aligned panes, with breadcrumbs and all nearby unchanged fields, rows, and cells retained as context.")+ai("split","ultracompact","Ultracompact","The same containers and breadcrumbs as Compact, pruned to changed data plus identifiers and order markers needed to interpret it.")+'<p class="diff-help-note"><b>Table alignment</b> (applies to every Split scope above): matched rows and columns follow the <b>Left file</b> order; right-only rows/columns are appended in Right-file order, so both panes line up exactly — order badges still identify source-order changes.</p></section><section class="diff-help-col'+(o?" active":"")+'"><h5>Unified</h5>'+ai("unified","full","Full","One complete superset view. Added data is green, removed data red, and old → new changes amber at one logical location.")+ai("unified","compact","Compact","One superset containing the innermost changed containers, with breadcrumbs and complete local context.")+ai("unified","ultracompact","Ultracompact","The same containers and breadcrumbs as Compact, showing only changes plus identifiers and order markers.")+"</section></div>",document.body.appendChild(t);const r=e.getBoundingClientRect(),l=t.offsetWidth,i=t.offsetHeight;t.style.left=Math.max(8,Math.min(r.left,window.innerWidth-l-8))+"px",t.style.top=Math.max(8,Math.min(r.bottom+6,window.innerHeight-i-8))+"px",e.setAttribute("aria-expanded","true");const s=To(t,{dismiss:si,ignore:e});ii={el:t,teardown:s,btn:e}}function di(){ha(),Ou();const e=document.getElementById("diffHeader");if(!e)return;if(si(),!tl||!cl)return e.hidden=!0,void(e.innerHTML="");e.hidden=!1;const t=Il(cl),n=["added","removed","changed","typeChanged","orderChanged","mixed"].filter(e=>t[e]).map(e=>'<span class="dh-count" title="'+ye(Ml[e])+'">'+t[e]+" "+ge(e)+"</span>"),o=n.length?n.join(", "):"no differences",r=(e,t)=>'<button type="button" class="btn sm diff-scope-btn'+(Ul===e?" active":"")+'" data-scope="'+e+'">'+t+"</button>",l=(e,t)=>'<button type="button" class="btn sm diff-layout-btn'+(ol===e?" active":"")+'" data-layout="'+e+'">'+t+"</button>",i=document.body.classList.contains("embedded"),s=(e,t,n)=>{const o=i?n.name:"Click to replace this side — "+n.name;return'<span class="dh-side"><b>'+e+':</b> <span class="dh-namewrap"><button type="button" class="dh-name-btn" data-side="'+t+'"'+(i?" disabled":"")+' title="'+ye(o)+'"><span class="dh-name">'+ge(n.name)+"</span></button> ("+ge(n.format)+")</span></span>"},a=!nl&&document.body.classList.contains("embedded")&&!S;e.innerHTML=nl?'<span class="dh-title">Edit</span><button id="diffInfoBtn" type="button" class="btn sm diff-info-btn" title="Explain diff views" aria-label="Explain diff views" aria-expanded="false">i</button><span class="dh-layout">'+l("split","Split")+l("unified","Unified")+'</span><span class="dh-scope">'+r("full","Full")+r("compact","Compact")+r("ultracompact","Ultracompact")+'</span><span class="dh-summary" title="'+ye(Tl)+'">'+o+'</span><button id="selfEditSaveBtn" type="button" class="btn sm" title="Save (Ctrl+S)">Save</button><button id="diffExitBtn" type="button" class="btn sm diff-exit-btn" title="Discard these edits and go back">Cancel</button>':'<span class="dh-title">Diff</span><button id="diffInfoBtn" type="button" class="btn sm diff-info-btn" title="Explain diff views" aria-label="Explain diff views" aria-expanded="false">i</button>'+s("Left","left",rl)+'<button id="diffSwapBtn" type="button" class="btn sm diff-swap-btn" title="Swap left and right" aria-label="Swap left and right">&#8644;</button>'+s("Right","right",ll)+'<span class="dh-layout">'+l("split","Split")+l("unified","Unified")+'</span><span class="dh-scope">'+r("full","Full")+r("compact","Compact")+r("ultracompact","Ultracompact")+'</span><span class="dh-summary" title="'+ye(Tl)+'">'+o+"</span>"+(a?"":'<button id="diffExitBtn" type="button" class="btn sm diff-exit-btn" title="Leave diff mode">&#10005; Exit diff</button>');const c=e.querySelectorAll(".dh-namewrap");if(2===c.length){const e=Math.max(c[0].getBoundingClientRect().width,c[1].getBoundingClientRect().width);c[0].style.minWidth=c[1].style.minWidth=e+"px"}const d=document.getElementById("diffSwapBtn");d&&d.addEventListener("click",El);const u=document.getElementById("diffExitBtn");u&&u.addEventListener("click",nl?yl:gl),e.querySelectorAll(".dh-name-btn:not([disabled])").forEach(e=>{e.addEventListener("click",()=>yf(e.getAttribute("data-side")))}),e.querySelectorAll(".diff-scope-btn").forEach(e=>{e.addEventListener("click",()=>{j&&ss(),Ul=e.getAttribute("data-scope"),fi()})}),e.querySelectorAll(".diff-layout-btn").forEach(e=>{e.addEventListener("click",()=>ui(e.getAttribute("data-layout")))});const f=document.getElementById("diffInfoBtn");f&&f.addEventListener("click",e=>{e.stopPropagation(),ci(e.currentTarget)});const h=document.getElementById("selfEditSaveBtn");h&&h.addEventListener("click",()=>{Kr?Lr():Rd()})}function ui(e){const t="split"===e?"split":"unified";t!==ol&&(j&&ss(),ol=t,document.body.classList.toggle("structile-diff-split","split"===ol),"unified"===ol&&(m="canvas",g="canvasWrap"),fi())}function fi(e){if(!tl||!cl)return;if("split"===ol)return hi(),void di();let t;m="canvas",g="canvasWrap";const n=[],o=new Map;if("full"===Ul)t=Hl(cl,[],n,!1,!1,o);else{const e="ultracompact"===Ul,r=[];if(Xl(cl,r),1===r.length&&r[0]===cl)t=Hl(cl,[],n,!1,e,o);else{const l={};r.length||(l["(no differences)"]="left and right are identical");for(const t of r){const r=ql(t);l[r]=Hl(t,[r],n,!1,e,o)}t=l}}Vl=n,dl=o,ri(t,e),li(n),di()}function hi(){const e=[],t=[];let n,o;const r=new Map,l=new Map;if("full"===Ul)n=Kl(cl,[],e,"left",!1,!1,r),o=Kl(cl,[],t,"right",!1,!1,l);else{const i="ultracompact"===Ul,s=[];if(Xl(cl,s),1===s.length&&s[0]===cl)n=Kl(cl,[],e,"left",!1,i,r),o=Kl(cl,[],t,"right",!1,i,l);else{const a={},c={};s.length||(a["(no differences)"]="left and right are identical",c["(no differences)"]="left and right are identical");for(const n of s){const o=ql(n);a[o]=Kl(n,[o],e,"left",!1,i,r),c[o]=Kl(n,[o],t,"right",!1,i,l)}n=a,o=c}}$l=n,Gl=o,Yl=e,Jl=t,ul=r,fl=l,pi()}function pi(){tl&&"split"===ol&&Go(()=>{m="canvasLeft",g="canvasWrapLeft",Zt($l),kn(),Mo(),_o();let e=y();e.innerHTML="",co(w,e),Co(e),li(Yl,e),Zl={ROOT:w,NODES:b,NODE_BY_ID:B,ITEM_BY_ID:_,COLUMN_BY_ID:R,CELL_BY_ID:P},m="canvasRight",g="canvasWrapRight",Zt(Gl),kn(),e=y(),e.innerHTML="",co(w,e),Co(e),li(Jl,e),Ql={ROOT:w,NODES:b,NODE_BY_ID:B,ITEM_BY_ID:_,COLUMN_BY_ID:R,CELL_BY_ID:P},j&&Ni&&es()})}function mi(){const e=document.getElementById("canvasWrapLeft"),t=document.getElementById("canvasWrapRight");if(!e||!t)return;const n=(e,t)=>{ei||(ei=!0,t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft,ei=!1)};e.addEventListener("scroll",()=>n(e,t)),t.addEventListener("scroll",()=>n(t,e))}function gi(e,t){if(e===t)return!0;if(e instanceof Set||t instanceof Set){if(!(e instanceof Set&&t instanceof Set&&e.size===t.size))return!1;const n=[...t],o=new Array(n.length).fill(!1);for(const t of e){let e=!1;for(let r=0;r<n.length;r++)if(!o[r]&&gi(t,n[r])){o[r]=!0,e=!0;break}if(!e)return!1}return!0}if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!gi(e[n],t[n]))return!1;return!0}if(e&&t&&"object"==typeof e&&"object"==typeof t){const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!gi(e[o],t[o]))return!1;return!0}return!1}function yi(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof Set)}function vi(e,t,n,o){if(yi(e)&&yi(t)){const r=Object.keys(e),l=Object.keys(t);for(const l of r)Object.prototype.hasOwnProperty.call(t,l)||o.push({op:"remove",path:n.concat([l]),oldValue:e[l]});for(const r of l)Object.prototype.hasOwnProperty.call(e,r)||o.push({op:"add",path:n.concat([r]),newValue:t[r]});for(const l of r)Object.prototype.hasOwnProperty.call(t,l)&&vi(e[l],t[l],n.concat([l]),o);return}if(Array.isArray(e)&&Array.isArray(t)){const r=Math.min(e.length,t.length);for(let l=0;l<r;l++)vi(e[l],t[l],n.concat([l]),o);for(let t=r;t<e.length;t++)o.push({op:"remove",path:n.concat([t]),oldValue:e[t]});for(let e=r;e<t.length;e++)o.push({op:"add",path:n.concat([e]),newValue:t[e]});return}gi(e,t)||o.push({op:"set",path:n,oldValue:e,newValue:t})}function wi(e){if(!e.length)return"(root)";let t="";for(const n of e)t+="number"==typeof n?"["+n+"]":(t?".":"")+n;return t}function bi(e){const t=wi(e.path);return"add"===e.op?"added "+t+": "+lr(e.newValue):"remove"===e.op?"removed "+t+" (was "+lr(e.oldValue)+")":t+": "+lr(e.oldValue)+" → "+lr(e.newValue)}function xi(e){let t=e.slice(0,4).map(bi).join("; ");return e.length>4&&(t+="; +"+(e.length-4)+" more"),t}function ki(){if(!C||"function"!=typeof C.serialize)return console.warn("[roundtrip] No serializer for the active format"+(C?" ("+C.kind+")":"")+"."),!1;if("function"!=typeof C.parse)return console.warn("[roundtrip] No parser available to verify the round trip."),!1;let e,t;try{e=C.serialize(x)}catch(e){return console.error("[roundtrip] serialize() threw:",e),!1}try{t=C.parse(e)}catch(t){return console.error("[roundtrip] re-parse threw:",t,"\nserialized text:\n"+e),!1}const n=gi(x,t);return n?console.log("[roundtrip] OK — "+C.kind+" round-trips the current (possibly edited/renamed) value exactly."):console.error("[roundtrip] MISMATCH — serialized text did not re-parse to an equal value.",{original:x,reparsed:t,text:e}),n}function Ei(e,t){let n,o=null,r=null;if(tl&&nl){if(o=pd(t),!o)return void Lu("Nothing to edit here — removed on the right");const e=fd(ll.value,o);n=void 0===e?null:e}else{if(!tl){const e=_.get(t),n=e?null:P.get(t);if(r=e?e.item.path:n?rc(n):null,!r)return}const e=No(t);n=void 0===e?null:e}Ro(e,"string"==typeof n?JSON.stringify(n):String(n),e=>{const n=Po(e);return n.error?n.error:tl&&nl?(wd(o,n.value),null):r?Sl()?(wd(r,n.value),null):"Can't edit right now":(Zo({type:"SetValue",nodeId:t,oldValue:No(t),newValue:n.value}),null)})}function Si(e,t){if(tl&&nl){const n=pd(t);if(!n||!n.length)return void Lu("Nothing to edit here — removed on the right");const o=String(n[n.length-1]),r=n.slice(0,-1);return void Ro(e,o,e=>{if(e===o)return null;if(""===e)return"Key cannot be empty";const t=fd(ll.value,r);return t&&Object.prototype.hasOwnProperty.call(t,e)?"Key already exists":(bd(r,o,e),null)})}const n=_.get(t);if(!n||null===n.item.parent)return;const o=String(n.item.refKey),r=n.item.path.slice(0,-1);Ro(e,o,e=>e===o?null:""===e?"Key cannot be empty":Object.prototype.hasOwnProperty.call(n.item.parent,e)?"Key already exists":Sl()?(bd(r,o,e),null):"Can't edit right now")}function Li(e){return"dict"===e.kind&&e.labels.length>1&&!e.labels.some(e=>-1!==e.indexOf("/"))}function Ci(e,t){if(tl&&nl){const n=B.get(t);if(!n||n.isRoot)return;const o=md(n.path);if(!o)return void Lu("Nothing to edit here — removed on the right");if(Li(n))return Mi(e,n,o);const r=String(o[o.length-1]),l=o.slice(0,-1);return void Ro(e,r,e=>{if(e===r)return null;if(""===e)return"Key cannot be empty";const t=fd(ll.value,l);return t&&Object.prototype.hasOwnProperty.call(t,e)?"Key already exists":(bd(l,r,e),null)})}const n=B.get(t);if(!n||n.isRoot)return;if(Li(n))return Ii(e,n);const o=String(n.ownerKey),r=n.path.slice(0,-1);Ro(e,o,e=>e===o?null:""===e?"Key cannot be empty":Object.prototype.hasOwnProperty.call(n.ownerParent,e)?"Key already exists":Sl()?(bd(r,o,e),null):"Can't edit right now")}function Ii(e,t){const n=t.labels.slice(),o=n.join("/"),r=t.path;Ro(e,o,e=>{if(e===o)return null;const l=e.split("/");if(l.length!==n.length)return"Must have "+n.length+' parts separated by / (matching "'+o+'")';if(l.some(e=>""===e))return"Key cannot be empty";if(l[0]!==n[0]&&Object.prototype.hasOwnProperty.call(t.ownerParent,l[0]))return"Key already exists";const i=[];for(let e=0;e<l.length;e++)l[e]!==n[e]&&i.push({index:e,oldKey:n[e],newKey:l[e]});return i.length?Sl()?(xd(r,i),null):"Can't edit right now":null})}function Mi(e,t,n){const o=t.labels.slice(),r=o.join("/");Ro(e,r,e=>{if(e===r)return null;const t=e.split("/");if(t.length!==o.length)return"Must have "+o.length+' parts separated by / (matching "'+r+'")';if(t.some(e=>""===e))return"Key cannot be empty";const l=[];for(let e=0;e<t.length;e++)t[e]!==o[e]&&l.push({index:e,oldKey:o[e],newKey:t[e]});return l.length?(xd(n,l),null):null})}function Ti(e,t){const n=R.get(t);if(!n)return;const o=n.node.table;if("records"!==o.mode)return;const r=String(null==o.headers[n.col]?"":o.headers[n.col]);if(tl&&nl){const t=md(n.node.path);return t?void Ro(e,r,e=>e===r?null:""===e?"Column name cannot be empty":o.headers.some((t,o)=>o!==n.col&&String(t)===e)?"Column name already exists":(kd(t,r,e),null)):void Lu("Nothing to edit here — removed on the right")}const l=n.node.path;Ro(e,r,e=>e===r?null:""===e?"Column name cannot be empty":o.headers.some((t,o)=>o!==n.col&&String(t)===e)?"Column name already exists":Sl()?(kd(l,r,e),null):"Can't edit right now")}function Oi(e,t){if(t){const t=e.target.closest(".pk");if(t){const e=t.closest(".pcell");return e&&null!=e.__id?{kind:"key",anchor:t,id:e.__id}:null}}const n=e.target.closest(".pv, .pcell");if(n){const e=n.closest(".pcell");return e&&null!=e.__id?{kind:"value",anchor:n,id:e.__id}:null}const o=e.target.closest("td[title]");if(o&&null!=o.__cellId)return{kind:"value",anchor:o,id:o.__cellId};if(!t)return null;const r=e.target.closest("th[title]");if(r&&null!=r.__colId)return{kind:"header",anchor:r,id:r.__colId};const l=e.target.closest(".dname");if(l&&null!=l.__nodeId)return{kind:"name",anchor:l,id:l.__nodeId};const i=e.target.closest(".tname");return i&&null!=i.__nodeId?{kind:"name",anchor:i,id:i.__nodeId}:null}function Bi(e){if(tl&&(!nl||"unified"!==ol)){if(!nl&&"unified"===ol&&Oi(e,!0)){e.preventDefault();Lu("Graph editing is unavailable in Unified view because a cell may represent both files. Switch to Split view"+(qr?"":", or edit either file in the Source panes")+".",{warning:!0,duration:7e3,actionLabel:"Switch to Split view",action:()=>ui("split")})}return}if(tl?Ld():qs())return void Lu("Render the pending source edit before editing the graph");const t=Oi(e,!0);t&&(e.preventDefault(),"key"===t.kind?Si(t.anchor,t.id):"value"===t.kind?Ei(t.anchor,t.id):"header"===t.kind?Ti(t.anchor,t.id):Ci(t.anchor,t.id))}function _i(e,t){if(tl&&"split"===ol){const t=oi(e);t&&(m=t.canvas,g=t.wrap,ni(t.regs))}Mo();const n=y(),o=v(),l=o&&o.clientWidth||window.innerWidth,i=o&&o.clientHeight||window.innerHeight,s=go(e),a=document.createElement("div");if(a.className="overlay peek",a.style.left=s.absX+"px",a.style.top=s.absY+"px",a.style.zIndex="60",a.appendChild(Un(e,"compact")),"table"===e.kind){const n="right"===t?{colsAll:!0,rowsAll:!1}:"bottom"===t?{colsAll:!1,rowsAll:!0}:{colsAll:!0,rowsAll:!0},o=an(e),s=n.colsAll?u.N:u.n,c=n.rowsAll?u.M:u.m,d=Math.min(Math.round(.9*l),fo(e,s,o)),f=Math.min(Math.round(.85*i),ho(e,c));tt(a,e,{softBorder:!0});const h=document.createElement("div");h.className="tscroll",h.style.maxHeight=Math.max(60,f-r.TITLE_H)+"px",h.style.maxWidth=d+"px",h.style.overflow="auto",h.appendChild(Vn(e,{colsAll:n.colsAll,rowsAll:n.rowsAll,markers:!1,full:!0})),a.appendChild(h)}else{const t=on(e.items.length,e.kvN),n=Math.min(Math.round(.9*l),t.cols*$n(e)+16),o=Math.min(Math.round(.85*i),r.TITLE_H+t.rows*e.cellH+16);a.style.maxWidth=n+"px",a.style.maxHeight=o+"px",a.appendChild(Gn(e,t))}a.addEventListener("mouseleave",Mo),a.addEventListener("click",t=>{t.target.closest(".ttool")||(Mo(),Dn(e))}),n.appendChild(a),Io=a,tl&&li(ti())}function Ri(){if(ha(),tl&&"split"===ol)return void pi();Mo(),_o();const e=y();e.innerHTML="",co(w,e),Co(e),Pi(),gc(),j&&Ni&&es(),tl&&li(Vl)}function Pi(){z=new Map;const e=document.querySelectorAll("[data-id]");for(const t of e)z.set(t.getAttribute("data-id"),t)}let Ni="",Ai=null,ji=!1,Wi=!1;function Hi(e,t,n){if(n)try{const n=new RegExp(e,t?"":"i");return{test:e=>n.test(String(e)),error:null}}catch(e){return{test:()=>!1,error:"invalid regex"}}const o=t?e:e.toLowerCase();return{test:e=>-1!==(t?String(e):String(e).toLowerCase()).indexOf(o),error:null}}function Di(e,t,n){if("dict"===e.kind){const o=e.labels&&e.labels.length?e.labels:[e.displayLabel];if(!e.isRoot)for(const r of o)if(t.test(r)){n.push({type:"dictkey",node:e});break}if(e.children)for(const o of e.children)Di(o,t,n)}else if("prim"===e.kind)e.items.forEach((o,r)=>{(null!=o.key&&t.test(o.key)||t.test(Z(o.value)))&&n.push({type:"val",node:e,item:o,path:o.path,idx:r})});else if("table"===e.kind){const o=e.table;!e.isRoot&&t.test(e.displayLabel||e.key||"")&&n.push({type:"dictkey",node:e}),o.headers&&o.headers.forEach((o,r)=>{t.test(o)&&n.push({type:"th",node:e,c:r})}),o.rows.forEach((o,r)=>o.forEach((o,l)=>{t.test(Z(o))&&n.push({type:"td",node:e,r:r,c:l})}))}}function zi(e,t,n){for(const[o,r]of n||b)"dict"!==r.kind||r.isRoot||M.collapsed.has(o)&&se(r.path,e)&&t.add(o)}function Fi(){const e=new Map;return b.forEach((t,n)=>{e.set(n,{relX:t.relX,relY:t.relY,w:t.w,h:t.h,contentW:t.contentW,contentH:t.contentH,hsucc:t._hsucc,vsucc:t._vsucc,htopo:t._htopo,vtopo:t._vtopo})}),e}function Ki(e){b.forEach((t,n)=>{const o=e.get(n);o&&(t.relX=o.relX,t.relY=o.relY,t.w=o.w,t.h=o.h,t.contentW=o.contentW,t.contentH=o.contentH,t._hsucc=o.hsucc,t._vsucc=o.vsucc,t._htopo=o.htopo,t._vtopo=o.vtopo)}),On(w,0,0)}function qi(e){return"dictkey"===e.type?"dict:"+ie(e.node.path):"val"===e.type?"val:"+ie(e.item.path):"th"===e.type?"th:"+ie(e.node.path)+":"+e.c:"td"===e.type?"td:"+ie(e.node.path)+":"+e.r+":"+e.c:""}let Xi=[];function Ui(){return{collapsed:new Set(M.collapsed),minimized:new Set(M.minimized),large:new Set(M.large),detached:new Set(M.detached)}}function Vi(){H&&(M.collapsed=new Set(H.collapsed),M.minimized=new Set(H.minimized),M.large=new Set(H.large),M.detached=new Set(H.detached))}function Yi(e){let t;t="dictkey"===e.type?e.node.path:"val"===e.type?e.path:e.node.path.concat(["th"===e.type?"#h"+e.c:"#"+e.r+"_"+e.c]);const n=new Set;zi(t,n,e._splitNodes||b);for(const e of n)M.collapsed.delete(e);if("td"===e.type||"th"===e.type){const t=e.node,n=ie(t.path);M.minimized.delete(n);const o=void 0!==e.c&&e.c>=Math.min(u.n,t.table.totalCols),r=void 0!==e.r&&e.r>=Math.min(u.m,t.table.totalRows);(o||r)&&M.large.add(n)}else"val"===e.type&&e.node.kvOverflow&&e.idx>=e.node.visibleK&&M.large.add(ie(e.node.path))}function Ji(e){const t=[],n=(n,o)=>{if(!n||!n.ROOT)return;const r=[];Di(n.ROOT,e,r);for(const e of r)e._splitSide=o,e._splitNodes=n.NODES,t.push(e)};return n(Zl,"left"),n(Ql,"right"),t}function $i(e){Zl&&Ql||pi(),j||(H=Ui(),W=null,j=!0);const t=Hi(e,ji,Wi);Ai=t.error;const n=document.getElementById("searchInput");n&&n.classList.toggle("invalid",!!t.error);const o=t.error?[]:Ji(t);Xi=o,D=o.length?0:-1,Zi()}function Gi(e){const t=(e||"").trim();if(Ni=t,!t)return void ss();if(nc(),tl&&"split"===ol)return void $i(t);j||(W=Fi(),H=Ui(),j=!0);const n=Hi(t,ji,Wi);Ai=n.error;const o=document.getElementById("searchInput");o&&o.classList.toggle("invalid",!!n.error);const r=[];n.error||Di(w,n,r),Xi=r,D=r.length?0:-1,Zi()}function Zi(){tl&&"split"===ol?(Vi(),D>=0&&Yi(Xi[D]),pi()):(W&&Ki(W),Vi(),D>=0&&Yi(Xi[D]),kn(),Ri());const e=document.querySelector(".hl.cur");e&&e.scrollIntoView(Object.assign({behavior:"smooth"},ns(Xi[D].type)))}function Qi(e,t,n){ts();const o=new Set;let r=null;if(tl&&"split"===ol){const e=e=>{const t=new Map,n=document.getElementById(e);return n&&n.querySelectorAll("[data-id]").forEach(e=>t.set(e.getAttribute("data-id"),e)),t};r={left:e("canvasLeft"),right:e("canvasRight")}}t.forEach((e,t)=>{const n=qi(e),l=r&&r[e._splitSide],i=r?e._splitSide+"|"+n:n;if(o.has(i))return;o.add(i);const s=r?l?l.get(n):null:z.get(n);s&&(s.classList.add("hl"),t===D&&s.classList.add("cur"))}),is(t.length,n)}function es(){Qi(Ni,Xi,Ai)}function ts(){document.querySelectorAll(".hl").forEach(e=>e.classList.remove("hl","cur"))}function ns(e){return"td"===e||"th"===e?{block:"center",inline:"center"}:"val"===e?{block:"nearest",inline:"center"}:{block:"nearest",inline:"nearest"}}function os(e){Xi.length&&(D=(e%Xi.length+Xi.length)%Xi.length,Zi())}function rs(){Xi.length&&os(D+1)}function ls(){Xi.length&&os(D-1)}function is(e,t){const n=document.getElementById("searchCount");return n.classList.toggle("err-count",!!t),t?(n.textContent=t,void n.classList.toggle("has",!1)):e?(n.textContent=(D>=0?D+1+"/":"")+e,void n.classList.toggle("has",!0)):(n.textContent=Ni?"0 matches":"",void n.classList.toggle("has",!1))}function ss(){j&&(W&&Ki(W),Vi(),j=!1,W=null,H=null),Ni="",Ai=null,Xi=[],D=-1;const e=document.getElementById("searchInput");e&&(e.value="",e.classList.remove("invalid")),is(0),Ri()}function as(e){const t=[],n=e.length;let o=0;const r=e=>e>="0"&&e<="9",l=e=>/[A-Za-z_]/.test(e),i=e=>/[A-Za-z0-9_]/.test(e),s={n:"\n",t:"\t",r:"\r","\\":"\\","'":"'",'"':'"',0:"\0"};for(;o<n;){const a=e[o];if(" "!==a&&"\t"!==a&&"\n"!==a&&"\r"!==a){if(!("{}[]():,".indexOf(a)>=0)){if("'"===a||'"'===a){const r=a;let l=o+1,i="";for(;l<n&&e[l]!==r;)"\\"===e[l]&&l+1<n?(i+=null!=s[e[l+1]]?s[e[l+1]]:e[l+1],l+=2):(i+=e[l],l++);if(l>=n)throw new Error("Unterminated string starting at position "+o);t.push({t:"STRING",v:i,pos:o}),o=l+1;continue}if(r(a)||"-"===a&&r(e[o+1]||"")){let l=o+("-"===a?1:0),i=!0;for(;l<n&&r(e[l]);)l++;if("."===e[l])for(i=!1,l++;l<n&&r(e[l]);)l++;if("e"===e[l]||"E"===e[l])for(i=!1,l++,"+"!==e[l]&&"-"!==e[l]||l++;l<n&&r(e[l]);)l++;const s=e.slice(o,l),c=i&&!Number.isSafeInteger(Number(s))?BigInt(s):Number(s);t.push({t:"NUMBER",v:c,pos:o}),o=l;continue}if(l(a)){let r=o+1;for(;r<n&&i(e[r]);)r++;t.push({t:"IDENT",v:e.slice(o,r),pos:o}),o=r;continue}throw new Error("Unexpected character '"+a+"' at position "+o)}t.push({t:a,pos:o}),o++}else o++}return t.push({t:"EOF",pos:n}),t}function cs(e){const t=as(e);let n=0;const o=()=>t[n],r=()=>t[n++],l=e=>{const t=r();if(t.t!==e)throw new Error("Expected '"+e+"' but found '"+(null!=t.v?t.v:t.t)+"' at position "+t.pos);return t};function i(){const e=o();if("{"===e.t)return function(){if(l("{"),"}"===o().t)return r(),{};const e=i();if(":"===o().t){r();const t={};for(t[String(e)]=i();","===o().t&&(r(),"}"!==o().t);){const e=i();l(":"),t[String(e)]=i()}return l("}"),t}const t=new Set([e]);for(;","===o().t&&(r(),"}"!==o().t);)t.add(i());return l("}"),t}();if("["===e.t)return function(){l("[");const e=[];if("]"===o().t)return r(),e;e.push(i());for(;","===o().t&&(r(),"]"!==o().t);)e.push(i());return l("]"),e}();if("("===e.t)return function(){if(l("("),")"===o().t)return r(),[];const e=[i()];let t=!1;for(;","===o().t&&(r(),t=!0,")"!==o().t);)e.push(i()),t=!1;return l(")"),1!==e.length||t?e:e[0]}();if("STRING"===e.t)return r(),e.v;if("NUMBER"===e.t)return r(),e.v;if("IDENT"===e.t){if(r(),"None"===e.v)return null;if("True"===e.v)return!0;if("False"===e.v)return!1;if("set"===e.v||"frozenset"===e.v)return function(){if(l("("),")"===o().t)return r(),new Set;const e=i();if(l(")"),e instanceof Set)return e;if(Array.isArray(e))return new Set(e);throw new Error("set()/frozenset() expects a list, tuple, or set argument")}();throw new Error("Unexpected identifier '"+e.v+"' at position "+e.pos+" — only None/True/False/set/frozenset are valid bare identifiers here")}throw new Error("Unexpected token '"+(null!=e.v?e.v:e.t)+"' at position "+e.pos)}const s=i();if("EOF"!==o().t)throw new Error("Unexpected trailing content at position "+o().pos);return s}function ds(e){const t=-1!==e.indexOf("'"),n=-1!==e.indexOf('"'),o=t&&!n?'"':"'";let r=o;for(const t of e)r+="\\"===t?"\\\\":t===o?"\\"+o:"\n"===t?"\\n":"\t"===t?"\\t":"\r"===t?"\\r":t;return r+o}function us(e){if(null==e)return"None";if("boolean"==typeof e)return e?"True":"False";if("number"==typeof e||"bigint"==typeof e)return String(e);if("string"==typeof e)return ds(e);if(e instanceof Set)return 0===e.size?"set()":"{"+[...e].map(us).join(", ")+"}";if(Array.isArray(e))return"["+e.map(us).join(", ")+"]";const t=Object.keys(e);return t.length?"{"+t.map(t=>ds(String(t))+": "+us(e[t])).join(", ")+"}":"{}"}const fs="BIGINT",hs=/"(?:[^"\\]|\\.)*"|(?<=[,:[\s]|^)(-?\d+)(?=[,\]}\s]|$)/g;function ps(e){return e.replace(hs,(e,t)=>void 0===t||Number.isSafeInteger(Number(t))?e:'"'+fs+t+'"')}function ms(e){return JSON.parse(ps(e),(e,t)=>"string"==typeof t&&0===t.indexOf(fs)?BigInt(t.slice(fs.length)):t)}function gs(e,t){return JSON.stringify(e,(e,t)=>"bigint"==typeof t?fs+t.toString():t instanceof Set?[...t]:t,t).replace(new RegExp('"'+fs+'(-?\\d+)"',"g"),"$1")}const ys={kind:"json",ext:"json",serialize:e=>gs(e,2),parse:e=>ms(e)},vs={kind:"python",ext:"py",serialize:us,parse:cs};function ws(e,t,n){const o=n||("text/html"===t?"html":"xml");return{kind:"xml",ext:o,mode:t||null,format:o,serialize:(t?e.serializeFn:e.serializeTextFn)||null,parse:n=>t?e.interpretFn((new DOMParser).parseFromString(n,t)):e.interpretTextFn(n)}}function bs(e){try{return{value:JSON.parse(e),format:ys}}catch(t){try{return{value:cs(e),format:vs}}catch(e){throw new Error("Not valid JSON ("+t.message+") or Python literal syntax ("+e.message+")")}}}function xs(e){return/^\s*</.test(e)}function ks(e){return/^\s*(<!doctype\s+html|<html[\s>])/i.test(e)}function Es(e){return e?"json"===e.kind?"json":"python"===e.kind?"python":e.format||e.ext||"text":"json"}function Ss(e){return e.replace(/\r\n?/g,"\n")}function Ls(e,t){return{text:e=Ss(e),renderedText:e,baselineText:e,format:t,valid:!0,diagnostic:null,locations:wa(e,t),revision:0}}function Cs(e,t,n){let o=e;if("string"!=typeof o&&(o="",t&&"function"==typeof t.serialize))try{o=t.serialize(n)}catch(e){o=""}const r=Es(t);I={...Ls(o,r),value:n},pa=null,ma=null,Hs&&(clearTimeout(Hs),Hs=null),Ds&&(clearTimeout(Ds),Ds=null),Vs()}function Is(e){const t=[],n=e.length,o=e=>e>="0"&&e<="9";let r=0;for(;r<n;){const l=e[r];if(" "!==l&&"\t"!==l&&"\n"!==l&&"\r"!==l){if('"'===l){const o=r;let l=r+1;for(;l<n&&'"'!==e[l];)l+="\\"===e[l]&&l+1<n?2:1;l=Math.min(l+1,n);let i=l;for(;i<n&&/\s/.test(e[i]);)i++;t.push({start:o,end:l,class:":"===e[i]?"tok-key":"tok-string"}),r=l;continue}if("-"===l||o(l)){const i=r;let s=r+("-"===l?1:0);for(;s<n&&o(e[s]);)s++;if("."===e[s])for(s++;s<n&&o(e[s]);)s++;if("e"===e[s]||"E"===e[s])for(s++,"+"!==e[s]&&"-"!==e[s]||s++;s<n&&o(e[s]);)s++;t.push({start:i,end:s,class:"tok-number"}),r=s;continue}if(e.startsWith("true",r)||e.startsWith("false",r)){const n="t"===e[r]?"true":"false";t.push({start:r,end:r+n.length,class:"tok-bool"}),r+=n.length;continue}e.startsWith("null",r)?(t.push({start:r,end:r+4,class:"tok-null"}),r+=4):"{}[]:,".indexOf(l)>=0?(t.push({start:r,end:r+1,class:"tok-punct"}),r++):r++}else r++}return t}function Ms(e){const t=[],n=e.length,o=e=>e>="0"&&e<="9",r=e=>/[A-Za-z_]/.test(e),l=e=>/[A-Za-z0-9_]/.test(e);let i=0;for(;i<n;){const s=e[i];if(" "!==s&&"\t"!==s&&"\n"!==s&&"\r"!==s)if("{}[]():,".indexOf(s)>=0)t.push({start:i,end:i+1,class:"tok-punct"}),i++;else{if("'"===s||'"'===s){const o=s,r=i;let l=i+1;for(;l<n&&e[l]!==o;)l+="\\"===e[l]&&l+1<n?2:1;l=Math.min(l+1,n);let a=l;for(;a<n&&/\s/.test(e[a]);)a++;t.push({start:r,end:l,class:":"===e[a]?"tok-key":"tok-string"}),i=l;continue}if(o(s)||"-"===s&&o(e[i+1]||"")){const r=i;let l=i+("-"===s?1:0);for(;l<n&&o(e[l]);)l++;if("."===e[l])for(l++;l<n&&o(e[l]);)l++;if("e"===e[l]||"E"===e[l])for(l++,"+"!==e[l]&&"-"!==e[l]||l++;l<n&&o(e[l]);)l++;t.push({start:r,end:l,class:"tok-number"}),i=l;continue}if(r(s)){const o=i;let r=i+1;for(;r<n&&l(e[r]);)r++;const s=e.slice(o,r);t.push({start:o,end:r,class:"True"===s||"False"===s?"tok-bool":"None"===s?"tok-null":"tok-key"}),i=r;continue}i++}else i++}return t}function Ts(e){const t=[],n=e.length,o=e=>" "===e||"\t"===e||"\n"===e||"\r"===e;let r=0;for(;r<n;){if("<"!==e[r]){r++;continue}if(e.startsWith("\x3c!--",r)){let o=e.indexOf("--\x3e",r+4);o=-1===o?n:o+3,t.push({start:r,end:o,class:"tok-comment"}),r=o;continue}if(e.startsWith("<!",r)||e.startsWith("<?",r)){let o=e.indexOf(">",r);o=-1===o?n:o+1,t.push({start:r,end:o,class:"tok-comment"}),r=o;continue}let l=r+1;"/"===e[l]&&l++;const i=l;for(;l<n&&!o(e[l])&&">"!==e[l]&&"/"!==e[l];)l++;if(l!==i){for(t.push({start:r,end:l,class:"tok-tag"}),r=l;r<n&&">"!==e[r];){if(o(e[r])||"/"===e[r]){r++;continue}const l=r;for(;r<n&&!o(e[r])&&"="!==e[r]&&">"!==e[r]&&"/"!==e[r];)r++;for(r>l&&t.push({start:l,end:r,class:"tok-attr"});r<n&&o(e[r]);)r++;if("="===e[r]){for(r++;r<n&&o(e[r]);)r++;if('"'===e[r]||"'"===e[r]){const o=e[r],l=r;for(r++;r<n&&e[r]!==o;)r++;r=Math.min(r+1,n),t.push({start:l,end:r,class:"tok-string"})}else{const l=r;for(;r<n&&!o(e[r])&&">"!==e[r]&&"/"!==e[r];)r++;r>l&&t.push({start:l,end:r,class:"tok-string"})}}}">"===e[r]&&r++}else r++}return t}function Os(e){const t=[],n=e.length,o=e=>e>="0"&&e<="9";let r=0;for(;r<n;){const l=e[r];if('"'===l||"'"===l){const o=l,i=r;let s=r+1;for(;s<n&&e[s]!==o;)s+="\\"===e[s]&&s+1<n?2:1;s=Math.min(s+1,n),t.push({start:i,end:s,class:"tok-string"}),r=s;continue}if("#"===l||e.startsWith("//",r)){let o=e.indexOf("\n",r);o=-1===o?n:o,t.push({start:r,end:o,class:"tok-comment"}),r=o;continue}if(o(l)||"-"===l&&o(e[r+1]||"")){const l=r;let i=r+1;for(;i<n&&o(e[i]);)i++;if("."===e[i])for(i++;i<n&&o(e[i]);)i++;t.push({start:l,end:i,class:"tok-number"}),r=i;continue}r++}return t}function Bs(e){return"json"===e?Is:"python"===e?Ms:"xml"===e||"html"===e?Ts:Os}function _s(e,t){const n=e.length,o=t.slice().sort((e,t)=>e.start-t.start),r=[];let l=0;for(const e of o)e.start<l||e.end<=e.start||(e.start>l&&r.push({start:l,end:e.start,cls:""}),r.push({start:e.start,end:e.end,cls:e.class}),l=e.end);return l<n&&r.push({start:l,end:n,cls:""}),r}function Rs(e,t){if(null==t)return e;const n=[];for(const o of e)t>o.start&&t<o.end?(n.push({start:o.start,end:t,cls:o.cls}),n.push({start:t,end:o.end,cls:o.cls})):n.push(o);return n}function Ps(e,t,n){const o=[];for(const r of e)r.end<=t||r.start>=n||o.push({start:Math.max(r.start,t),end:Math.min(r.end,n),cls:r.cls});return o}function Ns(e,t,n,o){let r=t;for(const e of n)r=Rs(r,e.from),r=Rs(r,e.to);for(const e of o)r=Rs(r,e.from),r=Rs(r,e.to);const l=new Set(o.map(e=>e.from)),i=t=>{const n=l.has(t.start)?[t.cls,"tok-fold-bracket"].filter(Boolean).join(" "):t.cls,o=ge(e.slice(t.start,t.end));return n?'<span class="'+n+'">'+o+"</span>":o};let s="",a=0;for(;a<r.length;){const e=r[a],t=n.find(t=>e.start>=t.from&&e.start<t.to);if(t){for(s+='<mark class="'+t.cls+'">';a<r.length&&r[a].start<t.to;)s+=i(r[a]),a++;s+="</mark>"}else s+=i(e),a++}return s}function As(e,t){const n=ge(e[t.from]),o=ge(e[t.to-1]);return'<span class="src-fold" data-fold-from="'+t.from+'" data-fold-to="'+t.to+'" title="Click to expand">'+n+'<span class="src-fold-caret">▸</span>…'+o+"</span>"}function js(e,t,n,o){const r=_s(e,t),l=o&&o.folded||[],i=o&&o.hints||[];if(!l.length)return Ns(e,r,n,i);const s=l.slice().sort((e,t)=>e.from-t.from);let a="",c=0;for(const t of s){if(t.from>c){const o=n.filter(e=>e.from<t.from&&e.to>c).map(e=>({from:Math.max(e.from,c),to:Math.min(e.to,t.from),cls:e.cls})),l=i.filter(e=>e.from>=c&&e.from<t.from);a+=Ns(e,Ps(r,c,t.from),o,l)}a+=As(e,t),c=t.to}if(c<e.length){const t=n.filter(t=>t.from<e.length&&t.to>c).map(e=>({from:Math.max(e.from,c),to:e.to,cls:e.cls})),o=i.filter(e=>e.from>=c);a+=Ns(e,Ps(r,c,e.length),t,o)}return a}function Ws(e,t,n,o,r,l,i,s){if(!e)return{folded:[],hints:[]};let a;try{a=Bs(n)(t)}catch(e){a=[]}const c=[];if(i&&i.length)for(const e of i)c.push(e);else o&&c.push({from:o.from,to:o.to,cls:"src-sel"});const d=s||(r&&l?Sa(t,l,r):{folded:[],hints:[]});return e.innerHTML=js(t,a,c,d),d}let Hs=null,Ds=null,zs=!1;const Fs=150;function Ks(){const e=u.sourceAutoRenderMs;return"number"==typeof e&&isFinite(e)&&e>=0?e:1e3}function qs(){return!(!I||qr||I.text===I.renderedText)}function Xs(e,t,n,o){const r=document.getElementById(e);r&&(r.hidden=!t,t&&(r.classList.toggle("source-render-btn-error",n),r.disabled=n,r.title=n?"Can't render yet — "+o+" doesn't parse":"Render now (auto-renders "+Ks()+"ms after you stop typing)"))}function Us(e){const t=document.getElementById(e);t&&(t.style.transitionDuration="0ms",t.style.setProperty("--structile-render-pct","100"),t.offsetWidth,t.style.transitionDuration=Ks()+"ms",t.style.setProperty("--structile-render-pct","0"))}function Vs(){const e=qs();Xs("sourceRenderBtn",e,e&&!1===I.valid,"the source text")}function Ys(){Us("sourceRenderRing")}let Js=!1;function $s(e,t){let n=1,o=1;for(let r=0;r<t&&r<e.length;r++)"\n"===e[r]?(n++,o=1):o++;return{line:n,column:o}}function Gs(e,t){const n=e&&e.message||String(e),o=/position (\d+)/.exec(n),r=o?Math.min(parseInt(o[1],10),t.length):null,l=null!=r?$s(t,r):{};return{message:n,offset:r,line:null!=l.line?l.line:null,column:null!=l.column?l.column:null}}function Zs(){const e=document.getElementById("sourcePanelStatus");if(!e)return;if(!I||I.valid)return e.hidden=!0,e.textContent="",void(e.title="");const t=I.diagnostic,n=t&&null!=t.line?" (line "+t.line+", col "+t.column+")":"";e.hidden=!1,e.textContent="unparsed"+n,e.title=t?t.message:""}function Qs(){const e=document.getElementById("sourcePanelInput"),t=document.getElementById("sourcePanel"),n=t&&t.querySelector(".source-pre");e&&n&&(n.scrollTop=e.scrollTop,n.scrollLeft=e.scrollLeft)}function ea(e,t,n,o){if(!e||e.value===t)return;const r=e.scrollTop,l=e.scrollLeft,i=e.selectionStart,s=e.selectionEnd;n(!0),e.value=t;try{e.selectionStart=Math.min(i,t.length),e.selectionEnd=Math.min(s,t.length)}catch(e){}e.scrollTop=r,e.scrollLeft=l,n(!1),o()}function ta(e){ea(document.getElementById("sourcePanelInput"),e,e=>{Js=e},Qs)}function na(e){if(!I||I.revision!==e)return;if(tl)return;const t=I.text;try{C.parse(t),I.valid=!0,I.diagnostic=null}catch(e){I.valid=!1,I.diagnostic=Gs(e,t)}Zs(),Vs()}function oa(e){if(!I||I.revision!==e)return;if(tl)return;const t=I.text;if((C===ys||C===vs)&&xs(t)){const e=ks(t);return I.format=e?"html":"xml",I.valid=!1,I.diagnostic={message:"Waiting for a matching interpreter",offset:null,line:null,column:null},Ws(document.getElementById("sourcePanelCode"),t,I.format,null),Zs(),Vs(),void Vu(t,e?"text/html":"application/xml","pasted",e?"html":"xml")}let n;try{n=C.parse(t)}catch(e){return I.valid=!1,I.diagnostic=Gs(e,t),Zs(),void Vs()}I.valid=!0,I.diagnostic=null,I.format=Es(C);const o=[];return vi(x,n,[],o),o.length?S?void(Sl(I.baselineText)?Td(t,(e,t)=>{ll.valid=!1,ll.diagnostic=Gs(e,t),od("right")}):Lu("Can't edit right now")):(Zo({type:"SourceEdit",oldValue:x,newValue:n,oldText:I.renderedText,newText:t,changes:o}),void Vs()):(Uo(t),void Vs())}function ra(e,t){if(tl&&!nl)return;if("string"!=typeof e)return;if(!C||"function"!=typeof C.parse)return;if(Oo)return;if(tl&&nl){if(Ld())return;return void Td(e,null)}let n;try{n=C.parse(e)}catch(e){return}const o=[];if(vi(x,n,[],o),o.length){if(!S||t||qr){let t="";try{t=C.serialize(x)}catch(e){}return void Zo({type:"SourceEdit",oldValue:x,newValue:n,oldText:t,newText:e,changes:o})}Sl()&&Td(e,null)}}function la(e){tl||("string"==typeof e&&ra(e,!0),Oo||(vr(),Ri()))}function ia(e,t,n,o,r){const l=e();l&&(clearTimeout(l),t(null)),n()||t(setTimeout(()=>{t(null),r()},o))}function sa(e){ia(()=>Hs,e=>{Hs=e},()=>zs,Fs,()=>na(e))}function aa(e){ia(()=>Ds,e=>{Ds=e},()=>zs,Ks(),()=>oa(e))}function ca(e){if(Js)return;if(!I)return;const t=e.target;let n=null;if(Ia.single.length){const e=Na("single",t,I.text);if(!e.ok)return void Lu("Can't edit inside a collapsed section — expand it first");I.text=e.realText,n=e.foldInfo}else I.text=t.value;I.revision++,(pa||ma)&&(pa=null,ma=null,pc());const o=Ws(document.getElementById("sourcePanelCode"),I.text,I.format,null,"single",I.locations,null,n);ta(Ta(t,I.text,o,"single")),Ma.single=t.value,Qs(),sa(I.revision),aa(I.revision),Vs(),Ys()}function da(){I&&""!==I.text&&(I.text="",I.revision++,(pa||ma)&&(pa=null,ma=null,pc()),sa(I.revision),aa(I.revision),Vs(),Ys())}let ua=!1;function fa(){const e=document.getElementById("sourceToggleBtn");e&&(e.classList.toggle("active",ua),e.setAttribute("aria-pressed",ua?"true":"false"))}function ha(){const e=document.getElementById("sourcePanel"),t=document.getElementById("sourcePanelLeft"),n=document.getElementById("sourcePanelRight"),o=ua&&!qr,r=o&&!tl,l=o&&tl,i=document.getElementById("paneResizerLeft"),s=document.getElementById("paneResizerRight");if(i&&(i.hidden=!(r||l)),s&&(s.hidden=!l),e){if(e.hidden=!r,r&&I){const e=Ws(document.getElementById("sourcePanelCode"),I.text,I.format,pa,"single",I.locations,Fa("single")),t=document.getElementById("sourcePanelInput");ta(Ta(t,I.text,e,"single")),Ma.single=t.value,t.readOnly=!0,Zs(),Qs(),Vs()}const t=document.getElementById("sourceEditBtn");t&&(t.hidden=!r)}if(t){t.hidden=!l;const e=document.getElementById("sourcePanelLeftEditLabel");if(e&&(e.hidden=!nl),l&&rl){const e=Ws(document.getElementById("sourcePanelLeftCode"),rl.text,rl.format||"json",Pc,"left",rl.locations,Fa("left")),t=document.getElementById("sourcePanelLeftInput");ld(t,Ta(t,rl.text,e,"left")),Ma.left=t.value,nl&&(t.readOnly=!0),od("left"),rd("left")}}if(n){n.hidden=!l;const e=document.getElementById("sourcePanelRightEditLabel");if(e&&(e.hidden=!nl),l&&ll){const e=Ws(document.getElementById("sourcePanelRightCode"),ll.text,ll.format||"json",Nc,"right",ll.locations,Fa("right")),t=document.getElementById("sourcePanelRightInput");ld(t,Ta(t,ll.text,e,"right")),Ma.right=t.value,od("right"),rd("right"),nl&&Cd()}}dd()}let pa=null,ma=null;function ga(e,t){return t+":"+ie(e)}function ya(e){const t=[],n=e.length;let o=0;const r=e=>e>="0"&&e<="9";function l(){for(;o<n&&(" "===e[o]||"\t"===e[o]||"\n"===e[o]||"\r"===e[o]);)o++}function i(e){throw new Error(e+" at position "+o)}function s(){const t=o;o++;let r="";for(;o<n&&'"'!==e[o];)if("\\"===e[o]&&o+1<n){const t=e[o+1];if("u"===t)r+=String.fromCharCode(parseInt(e.substr(o+2,4),16)),o+=6;else{const e={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};r+=null!=e[t]?e[t]:t,o+=2}}else r+=e[o],o++;return o>=n&&i("Unterminated string"),o++,{value:r,from:t,to:o}}function a(c){l();const d=e[o];if("{"===d)return function(n){const r=o;if(o++,l(),"}"===e[o])return o++,{from:r,to:o};for(;;){l(),'"'!==e[o]&&i("Expected a string key");const r=s(),c=n.concat([r.value]);t.push({path:c,role:"key",from:r.from,to:r.to}),l(),":"!==e[o]&&i("Expected ':'"),o++,l();const d=a(c);if(t.push({path:c,role:"value",from:d.from,to:d.to}),l(),","!==e[o])break;o++}"}"!==e[o]&&i("Expected '}'");return o++,{from:r,to:o}}(c);if("["===d)return function(n){const r=o;if(o++,l(),"]"===e[o])return o++,{from:r,to:o};let s=0;for(;;){l();const r=n.concat([s]),i=a(r);if(t.push({path:r,role:"value",from:i.from,to:i.to}),s++,l(),","!==e[o])break;o++}"]"!==e[o]&&i("Expected ']'");return o++,{from:r,to:o}}(c);if('"'===d){const e=s();return{from:e.from,to:e.to}}if("-"===d||r(d))return function(){const t=o;for("-"===e[o]&&o++;o<n&&r(e[o]);)o++;if("."===e[o])for(o++;o<n&&r(e[o]);)o++;if("e"===e[o]||"E"===e[o])for(o++,"+"!==e[o]&&"-"!==e[o]||o++;o<n&&r(e[o]);)o++;return{from:t,to:o}}();if(e.startsWith("true",o)){const e=o;return o+=4,{from:e,to:o}}if(e.startsWith("false",o)){const e=o;return o+=5,{from:e,to:o}}if(e.startsWith("null",o)){const e=o;return o+=4,{from:e,to:o}}i("Unexpected token")}l();const c=a([]);return t.push({path:[],role:"value",from:c.from,to:c.to}),t}function va(e){const t=[],n=e.length;let o=0;const r=e=>e>="0"&&e<="9",l=e=>/[A-Za-z0-9_]/.test(e);function i(){for(;o<n&&/\s/.test(e[o]);)o++}function s(e){throw new Error(e+" at position "+o)}function a(c){i();const d=e[o];if("{"===d)return function(n){const r=o;if(o++,i(),"}"===e[o])return o++,{from:r,to:o,value:{}};const l=a(n);if(i(),":"===e[o]){const c={};let d=l;for(;;){const r=n.concat([String(d.value)]);t.push({path:r,role:"key",from:d.from,to:d.to}),":"!==e[o]&&s("Expected ':'"),o++,i();const l=a(r);if(t.push({path:r,role:"value",from:l.from,to:l.to}),c[String(d.value)]=l.value,i(),","!==e[o])break;if(o++,i(),"}"===e[o])break;d=a(n),i()}return"}"!==e[o]&&s("Expected '}'"),o++,{from:r,to:o,value:c}}const c=new Map,d=[];function u(e){const o=null===e.value||"object"!=typeof e.value;if(o&&c.has(e.value))return void t.push({path:n.concat([c.get(e.value)]),role:"value",from:e.from,to:e.to});const r=d.length;d.push(e.value),o&&c.set(e.value,r),t.push({path:n.concat([r]),role:"value",from:e.from,to:e.to})}u(l),i();for(;","===e[o]&&(o++,i(),"}"!==e[o]);)u(a(n)),i();"}"!==e[o]&&s("Expected '}'");return o++,{from:r,to:o,value:new Set(d)}}(c);if("["===d)return function(n,r,l){const c=o;if(o++,i(),e[o]===l)return o++,{from:c,to:o,value:[]};let d=0;const u=[];for(;;){i();const r=n.concat([d]),s=a(r);if(t.push({path:r,role:"value",from:s.from,to:s.to}),u.push(s.value),d++,i(),","!==e[o])break;if(o++,i(),e[o]===l)break}e[o]!==l&&s("Expected '"+l+"'");return o++,{from:c,to:o,value:u}}(c,0,"]");if("("===d)return function(n){const r=o;if(o++,i(),")"===e[o])return o++,{from:r,to:o,value:[]};const l=[];let c=0,d=n.concat([c]),u=a(d);t.push({path:d,role:"value",from:u.from,to:u.to}),l.push(u),c++;let f=!1;i();for(;","===e[o]&&(o++,f=!0,i(),")"!==e[o]);)d=n.concat([c]),u=a(d),t.push({path:d,role:"value",from:u.from,to:u.to}),l.push(u),c++,f=!1,i();")"!==e[o]&&s("Expected ')'");o++;const h=o;return 1!==l.length||f?{from:r,to:h,value:l.map(e=>e.value)}:{from:r,to:h,value:l[0].value}}(c);if("'"===d||'"'===d){const t=function(){const t=e[o],r=o;o++;let l="";for(;o<n&&e[o]!==t;)if("\\"===e[o]&&o+1<n){const t=e[o+1],n={n:"\n",t:"\t",r:"\r","\\":"\\","'":"'",'"':'"',0:"\0"};l+=null!=n[t]?n[t]:t,o+=2}else l+=e[o],o++;return o>=n&&s("Unterminated string"),o++,{value:l,from:r,to:o}}();return{from:t.from,to:t.to,value:t.value}}if(r(d)||"-"===d&&r(e[o+1]||""))return function(){const t=o;"-"===e[o]&&o++;let l=!0;for(;o<n&&r(e[o]);)o++;if("."===e[o])for(l=!1,o++;o<n&&r(e[o]);)o++;if("e"===e[o]||"E"===e[o])for(l=!1,o++,"+"!==e[o]&&"-"!==e[o]||o++;o<n&&r(e[o]);)o++;const i=e.slice(t,o),s=l&&!Number.isSafeInteger(Number(i))?BigInt(i):Number(i);return{from:t,to:o,value:s}}();if((e=>/[A-Za-z_]/.test(e))(d)){const t=o;let r=o+1;for(;r<n&&l(e[r]);)r++;const d=e.slice(t,r);if("None"===d)return o=r,{from:t,to:r,value:null};if("True"===d)return o=r,{from:t,to:r,value:!0};if("False"===d)return o=r,{from:t,to:r,value:!1};if("set"===d||"frozenset"===d)return o=r,function(t,n){i(),"("!==e[o]&&s("Expected '(' after set/frozenset");if(o++,i(),")"===e[o])return o++,{from:n,to:o,value:new Set};const r=a(t);i(),")"!==e[o]&&s("Expected ')'");o++;const l=Array.isArray(r.value)?r.value:r.value instanceof Set?[...r.value]:null;null===l&&s("set()/frozenset() expects a list, tuple, or set argument");return{from:n,to:o,value:new Set(l)}}(c,t);s("Unexpected identifier '"+d+"'")}s("Unexpected token")}i();const c=a([]);return t.push({path:[],role:"value",from:c.from,to:c.to}),t}function wa(e,t){let n;try{if("json"===t)n=ya(e);else{if("python"!==t)return null;n=va(e)}}catch(e){return null}const o=new Map;for(const e of n){const t=ga(e.path,e.role);e.occurrence=o.has(t)?o.get(t).occurrence+1:0,o.set(t,e)}return{list:n,lastByKey:o}}function ba(e,t){if("single"===e)return fd(x,t);const n="left"===e?rl:ll;return n?fd(n.value,t):void 0}function xa(e,t){if("single"===e)return ie(t);const n=("left"===e?Nl:Al).get(ie(t));if(!n)return null;const o=tl&&"split"===ol?"left"===e?n.sidePathLeft:n.sidePathRight:n.supersetPath;return null!=o?ie(o):null}function ka(e,t){const n=xa(e,t);return null!=n&&(M.collapsed.has(n)||M.minimized.has(n))}function Ea(e,t){const n=xa(e,t);if(null==n)return;if(tl&&"split"===ol){const o="table"===$(ba(e,t)),r=o?M.minimized:M.collapsed;return r.has(n)?r.delete(n):r.add(n),o&&M.large.delete(n),void Ri()}const o=lc(n);if(o)return void("table"===o.kind?Hn(o):jn(o));const r="table"===$(ba(e,t)),l=r?M.minimized:M.collapsed;l.has(n)?l.delete(n):l.add(n),r&&M.large.delete(n),Ri()}function Sa(e,t,n){const o={folded:[],hints:[]};if(!t)return o;const r=[];for(const n of t.list){if("value"!==n.role||!n.path.length)continue;if(n.to-n.from<=2)continue;const t=e[n.from];"{"!==t&&"["!==t&&"("!==t||r.push(n)}r.sort((e,t)=>e.from-t.from);let l=-1;for(const e of r)e.from<l||(ka(n,e.path)?(o.folded.push(e),l=e.to):o.hints.push({from:e.from,to:e.from+1}));return o}function La(e,t){if(!e)return null;for(const n of e.list)if("value"===n.role&&n.path.length&&!(n.to-n.from<=2||t!==n.from&&t!==n.from+1))return n;return null}function Ca(e,t){const n=t&&t.folded||[];if(!n.length)return{text:e,placeholders:[]};const o=n.slice().sort((e,t)=>e.from-t.from);let r="",l=0;const i=[];for(const t of o){r+=e.slice(l,t.from);const n=r.length;r+=e[t.from]+"…"+e[t.to-1],i.push({dispFrom:n,dispTo:r.length,loc:t}),l=t.to}return r+=e.slice(l),{text:r,placeholders:i}}let Ia={single:[],left:[],right:[]},Ma={single:null,left:null,right:null};function Ta(e,t,n,o){if(!e)return t;e.readOnly=!1;if(!(n&&n.folded||[]).length)return Ia[o]=[],t;const r=Ca(t,n);return Ia[o]=r.placeholders,r.text}function Oa(e,t){let n=e;for(const o of t){if(o.dispTo>e)break;n+=o.loc.to-o.loc.from-(o.dispTo-o.dispFrom)}return n}function Ba(e,t,n){let o=e;for(const r of t){if(e<=r.dispFrom)break;if(!(e>=r.dispTo))return o-e+(n?r.loc.to:r.loc.from);o+=r.loc.to-r.loc.from-(r.dispTo-r.dispFrom)}return o}function _a(e,t,n){const o=Ia[e];if(!o||!o.length)return;const r=n.target,l=r.selectionStart,i=r.selectionEnd;if(l===i)return;const s=Ba(l,o,!1),a=Ba(i,o,!0);n.clipboardData.setData("text/plain",t.slice(s,a)),n.preventDefault()}function Ra(e,t){const n=Math.min(e.length,t.length);let o=0;for(;o<n&&e[o]===t[o];)o++;let r=e.length,l=t.length;for(;r>o&&l>o&&e[r-1]===t[l-1];)r--,l--;return{start:o,oldEnd:r,inserted:t.slice(o,l)}}function Pa(e,t,n){return n.some(n=>e<n.dispTo&&t>n.dispFrom)}function Na(e,t,n){const o=Ia[e],r=Ma[e],l=t.value;if(null==r)return{ok:!0,realText:l,foldInfo:null};const i=Ra(r,l);if(Pa(i.start,i.oldEnd,o)){t.value=r;try{t.selectionStart=t.selectionEnd=i.start}catch(e){}return{ok:!1}}const s=Oa(i.start,o),a=Oa(i.oldEnd,o),c=i.inserted.length-(a-s),d=o.map(e=>e.dispFrom<i.oldEnd?e:{dispFrom:e.dispFrom+c,dispTo:e.dispTo+c,loc:Object.assign({},e.loc,{from:e.loc.from+c,to:e.loc.to+c})});Ia[e]=d;return{ok:!0,realText:n.slice(0,s)+i.inserted+n.slice(a),foldInfo:{folded:d.map(e=>e.loc),hints:[]}}}function Aa(){return{query:"",caseSensitive:!1,useRegex:!1,matches:[],index:-1,error:null,active:!1,savedFolds:[]}}let ja={single:Aa(),left:Aa(),right:Aa()};function Wa(e){return"single"===e?"Single":"left"===e?"Left":"Right"}function Ha(e,t){return document.getElementById(t+Wa(e))}function Da(e){return"single"===e?I:"left"===e?rl:ll}function za(e){return"single"===e?"sourcePanelCode":"left"===e?"sourcePanelLeftCode":"sourcePanelRightCode"}function Fa(e){const t=ja[e];return t&&t.query&&!t.error?t.matches.map((e,n)=>({from:e.from,to:e.to,cls:n===t.index?"src-search-cur":"src-search-hit"})):[]}function Ka(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qa(e,t,n,o){if(!t)return{matches:[],error:null};let r;try{r=new RegExp(o?t:Ka(t),"g"+(n?"":"i"))}catch(e){return{matches:[],error:"invalid regex"}}const l=[];let i,s=0;for(;(i=r.exec(e))&&s<2e4;){const e=Math.max(i[0].length,1);l.push({from:i.index,to:i.index+e}),r.lastIndex=i.index+e,s++}return{matches:l,error:null}}function Xa(e){if(tl&&"split"===ol)return void Ri();let t=!1;for(const n of e){const e=lc(n);if(e){if("table"===e.kind){const t=M.minimized.has(n);e.w=t?e.minW:e.compactW,e.h=t?e.minH:e.compactH}else{const t=M.collapsed.has(n);e.w=t?e.collapsedW:e.expandedW,e.h=t?e.collapsedH:e.expandedH}An(e)}else t=!0}t&&kn(),Ri()}function Ua(e){const t=ja[e];if(t.active)return;t.active=!0;const n=Da(e);if(!n)return;const o=Sa(n.text,n.locations,e),r=[];for(const t of o.folded){const n=xa(e,t.path);null!=n&&(M.collapsed.has(n)?(M.collapsed.delete(n),r.push({pk:n,set:"collapsed"})):M.minimized.has(n)&&(M.minimized.delete(n),r.push({pk:n,set:"minimized"})))}t.savedFolds=r,r.length&&Xa(r.map(e=>e.pk))}function Va(e){const t=ja[e];if(!t.active)return;t.active=!1;const n=t.savedFolds;if(t.savedFolds=[],n.length){for(const e of n)M[e.set].add(e.pk);Xa(n.map(e=>e.pk))}else Ri()}function Ya(e){const t=ja[e],n=Ha(e,"sourceFindInput");n&&n.classList.toggle("invalid",!!t.error);const o=Ha(e,"sourceFindCount");o&&(o.classList.toggle("err-count",!!t.error),o.textContent=t.error?t.error:t.query?t.matches.length?t.index+1+"/"+t.matches.length:"0 matches":"")}function Ja(e,t){const n=ja[e];if(!n.matches.length)return;n.index=(t%n.matches.length+n.matches.length)%n.matches.length,Ya(e),ha();const o=document.getElementById(za(e)),r=o&&o.querySelector(".src-search-cur");r&&wc(r)}function $a(e){const t=ja[e];t.matches.length&&Ja(e,t.index+1)}function Ga(e){const t=ja[e];t.matches.length&&Ja(e,t.index-1)}function Za(e){const t=ja[e],n=Da(e),o=Ha(e,"sourceFindInput"),r=o?o.value:"",l=t.active;if(t.query=r,!r)return t.matches=[],t.index=-1,t.error=null,l?Va(e):ha(),void Ya(e);l||Ua(e);const i=n?qa(n.text,r,t.caseSensitive,t.useRegex):{matches:[],error:null};t.error=i.error,t.matches=i.error?[]:i.matches,t.index=t.matches.length?0:-1,Ya(e),t.index>=0?Ja(e,t.index):ha()}function Qa(e){const t=Ha(e,"sourceFindBar");if(!t)return;j&&ss(),t.hidden=!1;const n=Ha(e,"sourceFindInput");n&&(n.focus(),n.select())}function ec(e){const t=Ha(e,"sourceFindBar");t&&(t.hidden=!0);const n=ja[e],o=Ha(e,"sourceFindInput");o&&(o.value=""),n.query="",n.matches=[],n.index=-1,n.error=null,n.active&&Va(e),Ya(e),ha()}function tc(e){const t=Ha(e,"sourceFindBar");t&&(t.hidden?Qa(e):ec(e))}function nc(){["single","left","right"].forEach(ec)}function oc(){const e=document.activeElement&&document.activeElement.id;if("sourcePanelInput"===e)return"single";if("sourcePanelLeftInput"===e)return"left";if("sourcePanelRightInput"===e)return"right";const t={Single:"single",Left:"left",Right:"right"};for(const n in t)if(e==="sourceFindInput"+n)return t[n];return null}function rc(e){const t=e.node.table;return"list"===t.mode?e.node.path.concat([e.r]):"grid"===t.mode?e.node.path.concat([e.r+(t.dataStart||0),e.c]):e.node.path.concat([e.r,t.colKeys[e.c]])}function lc(e){const t=b.get(e);return t&&!t.cellHost?t:null}function ic(e){const t=ie(e);if(lc(t))return"dict:"+t;if(z.has("val:"+t))return"val:"+t;if(e.length>=1){const t=b.get(ie(e.slice(0,-1)));if(t&&"table"===t.kind&&"list"===t.table.mode){const n=e[e.length-1];if("number"==typeof n)return"td:"+ie(t.path)+":"+n+":0"}}if(e.length>=2){const t=e.slice(0,-2),n=b.get(ie(t));if(n&&"table"===n.kind){const t=n.table,o=e[e.length-2],r=e[e.length-1];if("grid"===t.mode&&t.headers&&t.dataStart&&o===t.dataStart-1)return"th:"+ie(n.path)+":"+r;let l,i;if("records"===t.mode?(l=o,i=t.colKeys.indexOf(r)):"grid"===t.mode&&(l=o-(t.dataStart||0),i=r),"number"==typeof l&&l>=0&&"number"==typeof i&&i>=0)return"td:"+ie(n.path)+":"+l+":"+i}}return null}function sc(e){const t=ie(e);if(lc(t))return"dict:"+t;if(z.has("val:"+t))return"val:"+t;if(e.length>=2){const t=b.get(ie(e.slice(0,-2)));if(t&&"table"===t.kind&&"records"===t.table.mode){const n=t.table.colKeys.indexOf(e[e.length-1]);if(-1!==n)return"th:"+ie(t.path)+":"+n}}return null}function ac(e){return"key"===e.role?sc(e.path):ic(e.path)}function cc(e,t){if(!I||!I.locations)return null;const n=e.table;if("records"===n.mode){const o=n.colKeys[t];for(let t=0;t<n.rows.length;t++){const n=I.locations.lastByKey.get(ga(e.path.concat([t,o]),"key"));if(n)return n}return null}return"grid"===n.mode&&n.dataStart?I.locations.lastByKey.get(ga(e.path.concat([n.dataStart-1,t]),"value")):null}function dc(e,t){if(!t||!t.length)return null;const n=t.filter(t=>t.from<=e&&e<=t.to);n.sort((e,t)=>e.to-e.from-(t.to-t.from));for(const e of n){const t=ac(e);if(t&&z.has(t))return{id:t,loc:e}}return null}function uc(e){if(tl)return;const t="number"==typeof e.from?e.from:null;if(null==t||!I||!I.locations||!I.valid)return void yc();const n=I.locations.list.filter(e=>e.from<=t&&t<=e.to);n.sort((e,t)=>e.to-e.from-(t.to-t.from));const o=n[0];if(!o)return void yc();const r=new Set;zi(o.path,r,b);for(const e of r)M.collapsed.delete(e);kn(),Ri();const l=ac(o);l&&mc(l,{scroll:!0})}function fc(e,t,n){if(!t||!e.contains(t))return null;let o=0;const r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let l;for(;l=r.nextNode();){if(l===t)return o+n;o+=l.textContent.length}return o}function hc(e,t){let n=null;if(document.caretRangeFromPoint)n=document.caretRangeFromPoint(t.clientX,t.clientY);else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(t.clientX,t.clientY);e&&(n={startContainer:e.offsetNode,startOffset:e.offset})}return n?fc(e,n.startContainer,n.startOffset):null}function pc(){document.querySelectorAll(".graph-sel").forEach(e=>e.classList.remove("graph-sel"))}function mc(e,t){pc(),ma=e;const n=z.get(e);return n&&(n.classList.add("graph-sel"),t&&t.scroll&&n.scrollIntoView({block:"nearest",inline:"nearest"})),n}function gc(){ma&&mc(ma,{scroll:!1})}function yc(){return(null!=ma||null!=pa||null!=Pc||null!=Nc)&&(ma=null,pa=null,Pc=null,Nc=null,pc(),ha(),!0)}const vc=32;function wc(e){const t=e.closest(".source-pre");if(!t)return;const n=t.parentElement&&t.parentElement.querySelector(".source-input"),o=Math.min(vc,t.clientHeight/2),r=e.offsetTop,l=r+e.offsetHeight,i=t.scrollTop,s=i+t.clientHeight;let a=null;r-o<i?a=Math.max(0,r-o):l+o>s&&(a=Math.max(0,l+o-t.clientHeight)),null!=a&&(t.scrollTop=a,n&&(n.scrollTop=a));const c=e.offsetLeft,d=c+e.offsetWidth,u=t.scrollLeft,f=u+t.clientWidth;let h=null;c<u?h=c:d>f&&(h=d-t.clientWidth),null!=h&&(t.scrollLeft=h,n&&(n.scrollLeft=h))}function bc(e,t){if(pa=e,!I)return;const n=document.getElementById("sourcePanelCode");if(Ws(n,I.text,I.format,e,"single",I.locations,Fa("single")),t&&t.scroll&&n){const e=n.querySelector(".src-sel");e&&wc(e)}}function xc(e){qr&&Vr({type:"structile-graph-selection-changed",from:e?e.from:null,to:e?e.to:null})}let kc=!1;function Ec(e,t){if(!qr||kc||!I||!I.locations)return;const n=I.locations.lastByKey.get(ga(e.path,"value"));n&&Vr({type:"structile-graph-fold-changed",from:n.from,to:n.to,collapsed:t})}function Sc(){if(!qr||tl)return;const e=br();null!=e&&Vr({type:"structile-graph-text-changed",text:e})}function Lc(e){if(tl||!I||!I.locations||!I.valid)return;const t="number"==typeof e.from?e.from:null,n="number"==typeof e.to?e.to:null;if(null==t||null==n)return;const o=I.locations.list.find(e=>"value"===e.role&&e.from===t&&e.to===n);if(o&&ka("single",o.path)!==!!e.collapsed){kc=!0;try{Ea("single",o.path)}finally{kc=!1}}}function Cc(e){const t=e.target.closest(".pk");if(t){const e=t.closest(".pcell"),n=e&&null!=e.__id&&_.get(e.__id);if(n)return{path:n.item.path,role:"key"}}const n=e.target.closest(".pv, .pcell");if(n){const e=n.closest(".pcell"),t=e&&null!=e.__id&&_.get(e.__id);if(t)return{path:t.item.path,role:"value"}}const o=e.target.closest("td[title]");if(o&&null!=o.__cellId){const e=P.get(o.__cellId);if(e)return{path:rc(e),role:"value"}}const r=e.target.closest("th[title]");if(r&&null!=r.__colId){const e=R.get(r.__colId);if(e)return{thEntry:e}}const l=e.target.closest(".dname");if(l&&null!=l.__nodeId){const e=B.get(l.__nodeId);if(e)return{path:e.path,role:"key"}}const i=e.target.closest(".tname");if(i&&null!=i.__nodeId){const e=B.get(i.__nodeId);if(e)return{path:e.path,role:"key"}}return null}function Ic(e){const t=new Set;zi(e.path,t,b);for(const e of t)M.collapsed.delete(e);kn(),Ri(),mc("dict:"+ie(e.path),{scroll:!0})}function Mc(e){const t=e.target.closest(".structile-link");if(!t)return!1;const n=Number(t.getAttribute("data-link-id")),o=isFinite(n)?B.get(n):null;return o&&Ic(o),!0}function Tc(e,t){const n=t.target.closest(".structile-link");if(!n)return!1;const o="left"===e?Zl:Ql;if(!o)return!0;const r=Number(n.getAttribute("data-link-id")),l=isFinite(r)?o.NODE_BY_ID.get(r):null;if(l){const t=new Set;zi(l.path,t,o.NODES);for(const e of t)M.collapsed.delete(e);pi();const n=Hc("left"===e?"canvasLeft":"canvasRight").get("dict:"+ie(l.path));n&&(pc(),n.classList.add("graph-sel"),n.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}))}return!0}function Oc(e){if(tl)return;if(Mc(e))return;const t=e.target.closest("[data-id]");if(!t)return void(yc()&&xc(null));if(!qr&&!ua)return;if(!I||!I.locations)return;if(!I.valid)return;const n=Cc(e);if(!n)return;const o=n.thEntry?cc(n.thEntry.node,n.thEntry.col):I.locations.lastByKey.get(ga(n.path,n.role));o&&(mc(t.getAttribute("data-id"),{scroll:!1}),qr?xc(o):bc(o,{scroll:!0}))}function Bc(e){if(tl)return;if(!ua||qr)return;if(!I||!I.locations)return;const t=hc(e.currentTarget,e);if(null==t)return;const n=dc(t,I.locations.list);n&&(mc(n.id,{scroll:!0}),bc(n.loc,{scroll:!1}))}function _c(e){if(tl)return;if(!ua||qr)return;const t=e.currentTarget.selectionStart;if(null==t)return;const n=Ia.single.find(e=>t>=e.dispFrom&&t<=e.dispTo);if(n)return void Ea("single",n.loc.path);if(!I||!I.locations||!I.valid)return;const o=dc(Oa(t,Ia.single),I.locations.list);o?(mc(o.id,{scroll:!0}),bc(o.loc,{scroll:!1})):yc()}function Rc(e){if(tl)return;if(!ua||qr)return;if(!I||!I.locations||!I.valid)return;const t=e.currentTarget.selectionStart;if(null==t)return;const n=Ia.single;if(n.some(e=>t>=e.dispFrom&&t<=e.dispTo))return;const o=Oa(t,n),r=La(I.locations,o);r&&(e.preventDefault(),Ea("single",r.path))}Object.assign(window.STRUCTILE_TESTING,{buildJSONLocations:ya,buildPythonLocations:va,buildSourceLocations:wa,getSourceSession:()=>I,getGraphSelId:()=>ma,getSourceSelection:()=>pa,hasPendingSourceEdit:qs,getCollapsedPaths:()=>[...M.collapsed],getMinimizedPaths:()=>[...M.minimized],getSourceFoldPlaceholders:e=>Ia[e],getSourceFindState:e=>ja[e]});let Pc=null,Nc=null,Ac="left";function jc(e){Ac=e,Do()}function Wc(){ma=null,pc(),Pc=null,Nc=null}function Hc(e){const t=new Map,n=document.getElementById(e);return n&&n.querySelectorAll("[data-id]").forEach(e=>t.set(e.getAttribute("data-id"),e)),t}function Dc(e,t){const n="left"===e?Zl:Ql;if(!n)return null;const o={ROOT:w,NODES:b,NODE_BY_ID:B,ITEM_BY_ID:_,COLUMN_BY_ID:R,CELL_BY_ID:P},r=z;ni(n),z=Hc("left"===e?"canvasLeft":"canvasRight");try{return t()}finally{ni(o),z=r}}function zc(e,t){const n=("unified"===e?dl:"left"===e?ul:fl).get(ie(t.node.path)),o={leftLoc:null,rightLoc:null};if(!n||"table"!==n.kind||!n.children.length)return o;const r=t.node.table&&t.node.table.headers?t.node.table.headers[t.col]:null;if(null==r)return o;let l=r,i=r;if("unified"===e&&-1!==r.indexOf(" → ")){const e=r.split(" → ");l=e[0],i=e[e.length-1]}let s=null,a=null;if("right"!==e&&rl.locations)for(const e of n.children){if(null==e.leftPath)continue;const t=rl.locations.lastByKey.get(ga(e.leftPath.concat([l]),"key"));if(t){s=t;break}}if("left"!==e&&ll.locations)for(const e of n.children){if(null==e.rightPath)continue;const t=ll.locations.lastByKey.get(ga(e.rightPath.concat([i]),"key"));if(t){a=t;break}}return{leftLoc:s,rightLoc:a}}function Fc(e,t){"left"===e?Pc=t:Nc=t;const n="left"===e?rl:ll,o=document.getElementById("left"===e?"sourcePanelLeftCode":"sourcePanelRightCode");return n&&o&&Ws(o,n.text,n.format,t,e,n.locations,Fa(e)),o}function Kc(e,t,n){let o=null,r=null;if(n.thEntry){const t=zc(e,n.thEntry);o=t.leftLoc,r=t.rightLoc}else{const t=("unified"===e?dl:"left"===e?ul:fl).get(ie(n.path));t&&(null!=t.leftPath&&rl.locations&&(o=rl.locations.lastByKey.get(ga(t.leftPath,n.role))),null!=t.rightPath&&ll.locations&&(r=ll.locations.lastByKey.get(ga(t.rightPath,n.role))))}if("left"===e&&(r=null),"right"===e&&(o=null),!o&&!r)return;pc(),t.classList.add("graph-sel"),"unified"===e&&(ma=t.getAttribute("data-id")),t.scrollIntoView({block:"nearest",inline:"nearest"});const l=Fc("left",o),i=Fc("right",r);if(l){const e=l.querySelector(".src-sel");e&&wc(e)}if(i){const e=i.querySelector(".src-sel");e&&wc(e)}const s=o&&r?Ac:o?"left":"right",a=document.getElementById("left"===s?"sourcePanelLeftInput":"sourcePanelRightInput");a&&a.focus({preventScroll:!0})}function qc(e){if(!tl||"unified"!==ol)return;if(Mc(e))return;const t=e.target.closest("[data-id]");if(!t)return void yc();if(!ua||qr)return;if(!rl||!ll)return;const n=Cc(e);n&&Kc("unified",t,n)}function Xc(e,t){if(!tl||"split"!==ol)return;if(Tc(e,t))return;const n=t.target.closest("[data-id]");if(!n)return void yc();if(!ua||qr)return;if(!rl||!ll)return;const o=Dc(e,()=>Cc(t));o&&Kc(e,n,o)}function Uc(e){if(!tl||!nl||"split"!==ol)return;if(Ld())return void Lu("Render the pending source edit before editing the graph");if(!Ql)return;m="canvasRight",g="canvasWrapRight",ni(Ql);const t=Oi(e,!0);t&&(e.preventDefault(),"key"===t.kind?Si(t.anchor,t.id):"value"===t.kind?Ei(t.anchor,t.id):"header"===t.kind?Ti(t.anchor,t.id):Ci(t.anchor,t.id))}function Vc(e,t){const n="left"===e?rl:ll;if(!n||!n.locations)return null;const o="left"===e?Nl:Al,r=n.locations.list.filter(e=>e.from<=t&&t<=e.to).sort((e,t)=>e.to-e.from-(t.to-t.from));for(const t of r){const n=o.get(ie(t.path));if(n){if("unified"===ol){if(null==n.supersetPath)continue;const e=ac({path:n.supersetPath,role:t.role});if(e&&z.has(e))return{viewKind:"unified",dataId:e,loc:t}}else{const o="left"===e?n.sidePathLeft:n.sidePathRight;if(null==o)continue;const r=Dc(e,()=>{const e=ac({path:o,role:t.role});return e&&z.has(e)?e:null});if(r)return{viewKind:e,dataId:r,loc:t}}continue}if(t.path.length<2)continue;const r=o.get(ie(t.path.slice(0,-2)));if(!r||"table"!==r.kind)continue;const l="left"===e?r.left:r.right;if(!l)continue;const i=nt(l),s=t.path[t.path.length-2],a=t.path[t.path.length-1];if("grid"===i.mode&&i.headers&&i.dataStart&&s===i.dataStart-1)if("unified"===ol){if(null==r.supersetPath)continue;const e="th:"+ie(r.supersetPath)+":"+a;if(z.has(e))return{viewKind:"unified",dataId:e,loc:t}}else{const n="left"===e?r.sidePathLeft:r.sidePathRight;if(null==n)continue;const o=Dc(e,()=>{const e="th:"+ie(n)+":"+a;return z.has(e)?e:null});if(o)return{viewKind:e,dataId:o,loc:t}}}return null}function Yc(e){if(pc(),"unified"===e.viewKind){ma=e.dataId;const t=z.get(e.dataId);t&&(t.classList.add("graph-sel"),t.scrollIntoView({block:"nearest",inline:"nearest"}))}else Dc(e.viewKind,()=>{const t=z.get(e.dataId);t&&(t.classList.add("graph-sel"),t.scrollIntoView({block:"nearest",inline:"nearest"}))})}function Jc(e,t){if(!tl||!ua||qr)return;jc(e);const n=t.currentTarget.selectionStart;if(null==n)return;const o=Ia[e].find(e=>n>=e.dispFrom&&n<=e.dispTo);if(o)return void Ea(e,o.loc.path);const r="left"===e?rl:ll;if(!r||!r.valid)return;const l=Vc(e,Oa(n,Ia[e]));l?(Yc(l),Fc(e,l.loc),Fc("left"===e?"right":"left",null)):yc()}function $c(e,t){if(!tl||!ua||qr)return;const n="left"===e?rl:ll;if(!n||!n.locations||!n.valid)return;const o=t.currentTarget.selectionStart;if(null==o)return;const r=Ia[e];if(r.some(e=>o>=e.dispFrom&&o<=e.dispTo))return;const l=Oa(o,r),i=La(n.locations,l);i&&(t.preventDefault(),Ea(e,i.path))}Object.assign(window.STRUCTILE_TESTING,{getDiffSourceSelection:()=>({left:Pc,right:Nc}),getDiffRoot:()=>cl,getSelfEditMode:()=>nl,hasPendingSelfEdit:()=>Ld()});let Gc=null,Zc=null,Qc=!1,ed=!1;const td={left:!1,right:!1};function nd(e){return"left"===e?{code:"sourcePanelLeftCode",input:"sourcePanelLeftInput",wrap:"sourcePanelLeft",status:"sourcePanelLeftStatus",save:"diffSaveLeftBtn"}:{code:"sourcePanelRightCode",input:"sourcePanelRightInput",wrap:"sourcePanelRight",status:"sourcePanelRightStatus",save:"diffSaveRightBtn"}}function od(e){const t=nd(e),n=document.getElementById(t.status),o="left"===e?rl:ll;if(!n)return;if(!o||o.valid)return n.hidden=!0,n.textContent="",void(n.title="");const r=o.diagnostic,l=r&&null!=r.line?" (line "+r.line+", col "+r.column+")":"";n.hidden=!1,n.textContent="unparsed"+l,n.title=r?r.message:""}function rd(e){const t=nd(e),n=document.getElementById(t.input),o=document.getElementById(t.wrap),r=o&&o.querySelector(".source-pre");n&&r&&(r.scrollTop=n.scrollTop,r.scrollLeft=n.scrollLeft)}function ld(e,t){const n=e&&"sourcePanelLeftInput"===e.id?"left":"right";ea(e,t,e=>{td[n]=e},()=>rd(n))}function id(e,t){const n="left"===e?rl:ll;if(!tl||!n||n.revision!==t)return;const o=n.text,r="left"===e?il:sl;let l,i;try{({value:l,serialize:i}=wl(n.format,o,r))}catch(t){return n.valid=!1,n.diagnostic=Gs(t,o),od(e),void dd()}n.valid=!0,n.diagnostic=null,n.value=l,n.serialize=i,n.renderedText=o,n.locations=wa(o,n.format),(hl[e].length||pl[e].length)&&(hl[e]=[],pl[e]=[],Do()),Wl(),"split"===ol?hi():fi(!0),od(e),dd()}function sd(e,t){if("left"===e){if(Gc&&(clearTimeout(Gc),Gc=null),Qc)return;Gc=setTimeout(()=>{Gc=null,id("left",t)},Fs)}else{if(Zc&&(clearTimeout(Zc),Zc=null),ed)return;Zc=setTimeout(()=>{Zc=null,id("right",t)},Fs)}}function ad(e,t){if(td[e])return;const n="left"===e?rl:ll;if(!n)return;const o=t.target;let r=null;if(Ia[e].length){const t=Na(e,o,n.text);if(!t.ok)return void Lu("Can't edit inside a collapsed section — expand it first");n.text=t.realText,r=t.foldInfo}else n.text=o.value;n.revision++,Fc(e,null);const l=nd(e),i=Ws(document.getElementById(l.code),n.text,n.format,null,e,n.locations,null,r);if(ld(o,Ta(o,n.text,i,e)),Ma[e]=o.value,rd(e),nl&&"right"===e)return Bd(n.revision),_d(n.revision),Cd(),void Id();sd(e,n.revision)}function cd(e){return Jo("left"===e?rl:ll)}function dd(){["left","right"].forEach(e=>{const t=nd(e),n=document.getElementById(t.save);if(!n)return;const o=tl&&!nl&&ua&&!qr;if(n.hidden=!o,!o)return;const r="left"===e?rl:ll;n.disabled=!cd(e),n.title=r&&!r.valid?"Save "+e+" (graph is stale — hasn't reparsed successfully)":"Save "+e+" side (Ctrl+S while this pane is focused)"})}async function ud(e){if(!tl)return null;const t="left"===e?rl:ll;if(!t)return null;if(t.text===t.baselineText)return Lu("Nothing to save on the "+e+" side"),null;const n=t.text,o="python"===t.format?"py":"json"!==t.format&&t.format?t.format:"json",r=(t.name||e).replace(/\.[^./\\]+$/,"");if(Fr)return Vr({type:"structile-save-requested",format:t.format,ext:o,fileName:r,isSaveAs:!1,content:n,side:e}),t.baselineText=t.text,ha(),dd(),Lu("Save requested ("+e+")"),{ok:!0};if("function"==typeof window.showSaveFilePicker){let e;try{e=await window.showSaveFilePicker({suggestedName:r+"."+o,types:kr(o)})}catch(e){return e&&"AbortError"===e.name||Lu("Could not open save dialog: "+(e&&e.message||e)),null}try{const t=await e.createWritable();await t.write(n),await t.close()}catch(e){return Lu("Could not write the file: "+(e&&e.message||e)),null}return t.baselineText=t.text,ha(),dd(),Lu("Saved "+(e.name||r+"."+o)),{ok:!0,savedName:e.name||r+"."+o}}const l=prompt("Save "+e+" as (file name, without extension):",r);if(null==l||!l.trim())return null;const i=l.trim()+"."+o;return ru(i,n),t.baselineText=t.text,ha(),dd(),Lu("Saved "+i),{ok:!0,savedName:i}}function fd(e,t){let n=e;for(const e of t){if(null==n)return;n=n[e]}return n}function hd(e,t,n){if(!t.length)return n;let o=e;for(let e=0;e<t.length-1;e++)o=o[t[e]];return o[t[t.length-1]]=n,e}function pd(e){const t=_.get(e),n=t?null:P.get(e),o=t?t.item.path:n?rc(n):null;if(!o)return null;const r=("unified"===ol?dl:fl).get(ie(o));return r?r.rightPath:null}function md(e){const t=("unified"===ol?dl:fl).get(ie(e));return t?t.rightPath:null}function gd(e){Zc&&(clearTimeout(Zc),Zc=null),ll.text=e,ll.renderedText=e,ll.valid=!0,ll.diagnostic=null,ll.revision++,ll.locations=wa(e,ll.format),Fc("right",null);const t=document.getElementById("sourcePanelRightInput");ld(t,Ta(t,e,Ws(document.getElementById("sourcePanelRightCode"),e,ll.format,null,"right",ll.locations,Fa("right")),"right")),Ma.right=t.value,od("right"),el()}function yd(e,t,n,o){const r=ll.format;if(e&&("json"===r||"python"===r)&&ll.locations){const o=ll.locations.lastByKey.get(ga(e,t));if(o)return Ko(ll.text,o.from,o.to,n)}if(C&&"function"==typeof C.serialize)try{return C.serialize(o)}catch(e){}return ll.text}function vd(e,t){const n=ll.value,o=[];vi(n,e,[],o),o.length&&Zo({type:"SelfEdit",oldValue:n,newValue:e,oldText:ll.text,newText:t,changes:o})}function wd(e,t){const n=hd(yr(ll.value),e,t);vd(n,yd(e,"value",Fo(ll.format,t),n))}function bd(e,t,n){const o=yr(ll.value);qd(o,e,t,n);vd(o,yd(e.concat([t]),"key",zo(ll.format,n),o))}function xd(e,t){const n=yr(ll.value);for(const o of t){const t=e.length-1+o.index;qd(n,e.slice(0,t),o.oldKey,o.newKey)}vd(n,yd(null,null,null,n))}function kd(e,t,n){const o=yr(ll.value),r=fd(o,e);if(Array.isArray(r))for(const e of r)e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)&&ae(e,t,n);vd(o,yd(null,null,null,o))}let Ed=null,Sd=null;function Ld(){return!(!nl||!ll||ll.text===ll.renderedText)}function Cd(){const e=Ld();Xs("sourceRenderBtnRight",e,e&&!1===ll.valid,"the current text")}function Id(){Us("sourceRenderRingRight")}function Md(e){if(!nl||!ll||ll.revision!==e)return;const t=ll.text;try{vl(ll.format,t,sl),ll.valid=!0,ll.diagnostic=null}catch(e){ll.valid=!1,ll.diagnostic=Gs(e,t)}od("right"),Cd()}function Td(e,t){let n;try{n=vl(ll.format,e,sl)}catch(n){return t&&t(n,e),void Cd()}ll.valid=!0,ll.diagnostic=null;const o=ll.value,r=[];if(vi(o,n,[],r),!r.length)return ll.value=n,gd(e),Wl(),"split"===ol?hi():fi(!0),void Cd();Zo({type:"SelfEdit",oldValue:o,newValue:n,oldText:ll.renderedText,newText:e,changes:r}),Cd()}function Od(e){nl&&ll&&ll.revision===e&&Td(ll.text,(e,t)=>{ll.valid=!1,ll.diagnostic=Gs(e,t),od("right")})}function Bd(e){ia(()=>Ed,e=>{Ed=e},()=>ed,Fs,()=>Md(e))}function _d(e){ia(()=>Sd,e=>{Sd=e},()=>ed,Ks(),()=>Od(e))}async function Rd(){if(!tl||!nl)return;if(Ld()&&(Ed&&(clearTimeout(Ed),Ed=null),Sd&&(clearTimeout(Sd),Sd=null),Od(ll.revision)),ll&&!ll.valid)return void Lu("Fix the source error before saving");const e=await ud("right");if(!e)return;const t=ll.value,n=ll.text,o=C;x=t,e.savedName&&(k=e.savedName.replace(/\.[^./\\]+$/,"")),Cs(n,o,t),gl(),vr()}function Pd(e){return"left"===e?rl:ll}function Nd(e){const t=Pd(e);return!(!t||"function"!=typeof t.serialize)}function Ad(e){const t=Pd(e);return!(!t||t.text===t.renderedText)}function jd(e,t){const n=("left"===e?ul:fl).get(ie(t));return n?"left"===e?n.leftPath:n.rightPath:null}function Wd(e,t){return Pd(e).serialize(t)}function Hd(e,t,n,o,r){const l=Pd(e);if(n&&l.locations){const e=l.locations.lastByKey.get(ga(n,o));if(e)return Ko(l.text,e.from,e.to,r)}return Wd(e,t)}function Dd(e,t){"left"===e?Gc&&(clearTimeout(Gc),Gc=null):Zc&&(clearTimeout(Zc),Zc=null);const n=Pd(e);n.text=t,n.renderedText=t,n.valid=!0,n.diagnostic=null,n.revision++,n.locations=wa(t,n.format),Fc(e,null);const o=nd(e),r=document.getElementById(o.input);ld(r,Ta(r,t,Ws(document.getElementById(o.code),t,n.format,null,e,n.locations,Fa(e)),e)),Ma[e]=r.value,od(e)}function zd(e,t){Pd(e.side).value="do"===t?e.newValue:e.oldValue,Wl(),"split"===ol?hi():fi(!0)}function Fd(e,t,n,o){const r=[];if(vi(t,n,[],r),!r.length)return;const l={type:"DiffEdit",side:e,oldValue:t,newValue:n,oldText:Pd(e).text,newText:o,changes:r};zd(l,"do"),hl[e].push(l),pl[e].length=0,Do(),Dd(e,o),dd()}function Kd(e,t,n){const o=Pd(e),r=o.value,l=hd(yr(r),t,n);Fd(e,r,l,Hd(e,l,t,"value",Fo(o.format,n)))}function qd(e,t,n,o){ae(fd(e,t),n,o)}function Xd(e,t,n,o){const r=Pd(e),l=r.value,i=yr(l);qd(i,t,n,o);Fd(e,l,i,Hd(e,i,t.concat([n]),"key",zo(r.format,o)))}function Ud(e,t,n){const o=Pd(e).value,r=yr(o);for(const e of n){const n=t.length-1+e.index;qd(r,t.slice(0,n),e.oldKey,e.newKey)}Fd(e,o,r,Hd(e,r,null,null,null))}function Vd(e,t,n,o){const r=Pd(e).value,l=yr(r),i=fd(l,t);if(Array.isArray(i))for(const e of i)e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,n)&&ae(e,n,o);Fd(e,r,l,Hd(e,l,null,null,null))}function Yd(e,t,n){const o=_.get(n),r=o?null:P.get(n),l=o?o.item.path:r?rc(r):null;if(!l)return;const i=jd(e,l);if(!i)return void Lu("Nothing to edit here — no counterpart on this side");const s=fd(Pd(e).value,i),a=void 0===s?null:s;Ro(t,"string"==typeof a?JSON.stringify(a):String(a),t=>{const n=Po(t);return n.error?n.error:(Kd(e,i,n.value),null)})}function Jd(e,t,n){const o=_.get(n);if(!o||null===o.item.parent)return;const r=jd(e,o.item.path);if(!r)return void Lu("Nothing to edit here — no counterpart on this side");const l=String(o.item.refKey),i=r.slice(0,-1);Ro(t,l,t=>{if(t===l)return null;if(""===t)return"Key cannot be empty";const n=fd(Pd(e).value,i);return n&&Object.prototype.hasOwnProperty.call(n,t)?"Key already exists":(Xd(e,i,l,t),null)})}function $d(e,t,n){const o=R.get(n);if(!o)return;const r=o.node.table;if("records"!==r.mode)return;const l=String(null==r.headers[o.col]?"":r.headers[o.col]),i=jd(e,o.node.path);i?Ro(t,l,t=>t===l?null:""===t?"Column name cannot be empty":r.headers.some((e,n)=>n!==o.col&&String(e)===t)?"Column name already exists":(Vd(e,i,l,t),null)):Lu("Nothing to edit here — no counterpart on this side")}function Gd(e,t,n,o){const r=n.labels.slice(),l=r.join("/");Ro(t,l,t=>{if(t===l)return null;const n=t.split("/");if(n.length!==r.length)return"Must have "+r.length+' parts separated by / (matching "'+l+'")';if(n.some(e=>""===e))return"Key cannot be empty";const i=[];for(let e=0;e<n.length;e++)n[e]!==r[e]&&i.push({index:e,oldKey:r[e],newKey:n[e]});return i.length?(Ud(e,o,i),null):null})}function Zd(e,t,n){const o=B.get(n);if(!o||o.isRoot)return;const r=jd(e,o.path);if(!r)return void Lu("Nothing to edit here — no counterpart on this side");if(Li(o))return Gd(e,t,o,r);const l=String(o.ownerKey),i=r.slice(0,-1);Ro(t,l,t=>{if(t===l)return null;if(""===t)return"Key cannot be empty";const n=fd(Pd(e).value,i);return n&&Object.prototype.hasOwnProperty.call(n,t)?"Key already exists":(Xd(e,i,l,t),null)})}function Qd(e,t){if(!tl||nl||"split"!==ol)return;if(!Nd(e))return;if(Ad(e))return void Lu("Render the pending source edit before editing the graph");const n="left"===e?Zl:Ql;if(!n)return;m="left"===e?"canvasLeft":"canvasRight",g="left"===e?"canvasWrapLeft":"canvasWrapRight",ni(n),jc(e);const o=Oi(t,!0);o&&(t.preventDefault(),"key"===o.kind?Jd(e,o.anchor,o.id):"value"===o.kind?Yd(e,o.anchor,o.id):"header"===o.kind?$d(e,o.anchor,o.id):Zd(e,o.anchor,o.id))}function eu(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return(t>>>0).toString(16)}function tu(){try{return eu(JSON.stringify(x,(e,t)=>"bigint"==typeof t?t.toString():t))}catch(e){return"0"}}function nu(e){const t=[];for(const n of e){const e=b.get(n);e&&t.push(e.path)}return t}function ou(){return{version:1,file:k,savedAt:(new Date).toISOString(),contentHash:tu(),settings:Object.assign({},u),collapsed:nu(M.collapsed),minimized:nu(M.minimized),large:nu(M.large),detached:nu(M.detached)}}function ru(e,t,n){const o=new Blob([t],{type:n||"application/json"}),r=URL.createObjectURL(o),l=document.createElement("a");l.href=r,l.download=e,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(r),1500)}function lu(e,t,n){const o=new FileReader;o.onload=()=>{try{n(JSON.parse(o.result))}catch(e){Lu(t+": "+e.message)}},o.readAsText(e)}function iu(){j&&ss();const e=ou();ru(k+".view.json",JSON.stringify(e,null,2)),Lu("Saved "+k+".view.json")}function su(){try{const e=decodeURIComponent(window.location.pathname||"");return(e.split(/[\\/]/).filter(Boolean).pop()||"structile.html").replace(/\.(html?|xhtml)$/i,"")||"structile"}catch(e){return"structile"}}function au(){return su()+".settings.json"}function cu(){for(const e of a)Of(e);return{version:1,app:"Structile",exportedAt:(new Date).toISOString(),settings:Object.assign({},u),renderMap:JSON.parse(JSON.stringify(f)),links:JSON.parse(JSON.stringify(h)),tableCols:JSON.parse(JSON.stringify(p))}}function du(e){const t=e&&"object"==typeof e&&e.renderMap;return!(!t||"object"!=typeof t)&&(f.forNull="string"==typeof t.forNull?t.forNull:null,f.forEmpty="string"==typeof t.forEmpty?t.forEmpty:null,f.values=t.values&&"object"==typeof t.values?Object.assign({},t.values):{},!0)}function uu(e){const t=e&&"object"==typeof e&&e.links;return!(!t||"object"!=typeof t)&&(h.open="string"==typeof t.open?t.open:"",h.close="string"==typeof t.close?t.close:"",!0)}function fu(e){const t=e&&"object"==typeof e&&e.tableCols;return!(!t||"object"!=typeof t)&&(p.rules=Array.isArray(t.rules)?t.rules.filter(e=>e&&"string"==typeof e.pattern&&"number"==typeof e.width&&isFinite(e.width)).map(e=>({pattern:e.pattern,width:e.width})):[],p.lowOccupancyThreshold="number"==typeof t.lowOccupancyThreshold&&isFinite(t.lowOccupancyThreshold)?t.lowOccupancyThreshold:.1,p.lowOccupancyWidth="number"==typeof t.lowOccupancyWidth&&isFinite(t.lowOccupancyWidth)?t.lowOccupancyWidth:8,!0)}function hu(){const e=au(),t=cu();ru(e,JSON.stringify(t,null,2)),Lu("Exported "+e)}function pu(){const e=cu();Vr({type:"structile-settings-changed",settings:e.settings,renderMap:e.renderMap,links:e.links,tableCols:e.tableCols,theme:we()}),Lu("Saved as default for new views")}function mu(e){return e&&"object"==typeof e&&e.settings&&"object"==typeof e.settings?e.settings:e}function gu(e){const t=mu(e),n=Object.assign({},s);let o=0;if(t&&"object"==typeof t){"number"!=typeof t.headerLabelMaxW||"headerLabelMax"in t||(n.headerLabelMax=Math.max(3,Math.round(t.headerLabelMaxW/7)),o++);for(const e of Object.keys(s)){const r=t[e];("checkbox"===i.get(e).type?"boolean"==typeof r:"number"==typeof r&&isFinite(r))&&(n[e]=r,o++)}}return{settings:n,used:o}}function yu(e,t){const n=gu(e);u=Object.assign({},d),Object.assign(u,n.settings),Tf(),du(e)&&(Ie(),Df()),uu(e)&&(Oe(),_f()),fu(e)&&(Re(),Jf());const o=e&&"object"==typeof e?e.theme:null;"light"!==o&&"dark"!==o||xe(o),w&&(j&&ss(),kn(),Ri());return Lu("Loaded "+t+(n.used?"":" (no recognized settings found; using built-in defaults)")),n}function vu(e){lu(e,"Could not read settings file",t=>yu(t,e.name||"settings"))}function wu(e){return Array.isArray(e)?ie(e):"string"==typeof e?e:null}function bu(){!function e(t){if(t.children)for(const n of t.children)e(n);if("table"===t.kind){const e=ie(t.path),n=M.minimized.has(e);t.w=n?t.minW:t.compactW,t.h=n?t.minH:t.compactH}else"dict"===t.kind&&Nn(t)}(w),On(w,0,0)}function xu(e){let t=0;if(e.settings){const t=gu(e);u=Object.assign({},d,t.settings),Tf()}M.collapsed=new Set,M.minimized=new Set,M.large=new Set,M.detached=new Set,kn();const n=(e,n)=>{if(Array.isArray(e))for(const o of e){const e=wu(o);null!=e?b.has(e)||Array.isArray(o)&&"primitive"!==$(fd(x,o))?n.add(e):t++:t++}};n(e.collapsed,M.collapsed),n(e.minimized,M.minimized),n(e.large,M.large),n(e.detached,M.detached);for(const e of M.detached)M.large.delete(e),M.minimized.delete(e);for(const e of M.large)M.minimized.delete(e);bu(),Ri();let o="Loaded view for "+(e.file||"file");e.contentHash&&e.contentHash!==tu()&&(o+=" — note: saved for a different version, applied best-effort"),t&&(o+=" ("+t+" stale path"+(t>1?"s":"")+" dropped)"),Lu(o)}function ku(e){lu(e,"Could not read view file",xu)}Object.assign(window.STRUCTILE_TESTING,{getDiffSideSession:e=>"left"===e?rl:ll}),Object.assign(window.STRUCTILE_TESTING,{getDiffUndoStack:e=>hl[e],getDiffRedoStack:e=>pl[e]});let Eu=null;function Su(){const e=document.getElementById("statusNote");clearTimeout(Eu),Eu=null,e.hidden=!0}function Lu(e,t){const n=t||{},o=document.getElementById("statusNote");if(o.className="note"+(n.warning?" warning":""),o.replaceChildren(document.createTextNode(e)),n.actionLabel&&"function"==typeof n.action){const e=document.createElement("button");e.type="button",e.className="btn sm note-action",e.textContent=n.actionLabel,e.addEventListener("click",()=>{Su(),n.action()}),o.appendChild(e)}o.hidden=!1,clearTimeout(Eu),Eu=setTimeout(Su,n.duration||4200)}function Cu(){try{return eu(e||document.documentElement.outerHTML)}catch(e){return"n/a"}}let Iu=null;function Mu(){Iu&&(Iu.el.remove(),Iu.teardown(),Iu=null)}function Tu(e){if(Iu)return void Mu();const r=document.createElement("div");r.className="about-pop",r.innerHTML='<h4>Structile</h4><div class="tagline">A spatial editor and diff tool for structured data.</div><div class="desc">Zero-dependency, single-file viewer that packs nested JSON into a readable spatial layout.</div><div class="row"><span>Version</span><b>'+ge(t)+'</b></div><div class="row"><span>Author</span><b>'+ge(n)+'</b></div><div class="row"><span>Modified</span><b>'+ge(o)+'</b></div><div class="row"><span>Code hash</span><b>'+ge(Cu())+"</b></div>",document.body.appendChild(r);const l=e.getBoundingClientRect(),i=r.offsetWidth;r.style.left=Math.max(8,Math.min(l.right-i,window.innerWidth-i-8))+"px",r.style.top=l.bottom+6+"px";const s=To(r,{dismiss:Mu,ignore:e});Iu={el:r,teardown:s}}function Ou(){const e=document.getElementById("fileNameLabel");if(!e)return;if(e.hidden=tl&&!nl,e.hidden)return;if(!S)return e.textContent=Fr?"":"Load data…",void(e.title="");const t=E?k+"."+(C&&C.ext||"json"):k;e.textContent=t,e.title=Fr?t:"Click to load different data — "+t}function Bu(e,t,n,o){tl&&ml(),j&&ss(),x=e,k=t||"data",C=n||ys,E=!(o&&!1===o.hasRealName),S=!0,L(),Ou(),Cs(o&&o.rawText,C,e),M.collapsed=new Set,M.minimized=new Set,M.large=new Set,M.detached=new Set,Ni="",Xi=[];const r=document.getElementById("searchInput");r&&(r.value=""),is(0),Zt(e),vr(),kn(),Ri(),document.getElementById("canvasWrap").scrollTo(0,0)}function _u(e,t){const n=new FileReader;n.onload=()=>t(n.result),n.onerror=()=>Lu("Could not read "+e.name),n.readAsText(e)}function Ru(e){return/\.view\.json$/i.test(e)?"view":/\.settings\.json$/i.test(e)?"settings":/\.py$/i.test(e)?"python":Qu(e)?"structureddata":/\.js$/i.test(e)?"interpreter":"json"}let Pu=null;function Nu(){document.getElementById("pastePanel").hidden=!1;const e=document.getElementById("pendingPairMsg"),t=document.getElementById("pendingPairFile");if("data"===Pu.kind){const n=Pu.format||("text/html"===Pu.mode?"html":"xml");e.textContent="Loaded "+(Pu.name||"data")+" ("+n+") — choose its matching interpreter (.js) to render it:"+(Pu.cacheMissed?" (this session's saved "+n+" interpreter didn't match)":""),t.accept=".js"}else e.textContent="Loaded interpreter "+(Pu.name||"")+" — choose its matching data file, or paste XML data into the source pane:",t.accept=Gu.join(",");document.getElementById("pendingPairHint").hidden=!1}function Au(){Pu=null;const e=document.getElementById("pendingPairHint");e&&(e.hidden=!0);const t=document.getElementById("pastePanel");t&&(t.hidden=!0);const n=document.getElementById("pendingPairFile");n&&(n.value="")}let ju=Object.create(null);function Wu(e,t){if(!e||!t)return;let n=ju[e];n||(n=ju[e]=[]);const o=n.indexOf(t);-1!==o&&n.splice(o,1),n.unshift(t),n.length>5&&(n.length=5)}function Hu(e,t,n,o){const r=o&&ju[o];if(!r||!r.length)return!1;const l=zu(e,t,r);return!!l.ok&&(Ku(l,t,o,n," (reused this session's "+o+" interpreter)",e),!0)}function Du(e){const t=new Function('"use strict";\n'+e+'\n;return { interpretXML: (typeof interpretXML==="function") ? interpretXML : null, serializeXML: (typeof serializeXML==="function") ? serializeXML : null, interpretText: (typeof interpretText==="function") ? interpretText : null, serializeText: (typeof serializeText==="function") ? serializeText : null };')();return{interpretFn:t.interpretXML,serializeFn:t.serializeXML,interpretTextFn:t.interpretText,serializeTextFn:t.serializeText}}function zu(e,t,n){const o=Array.isArray(n)?n:[n];let r=null;if(t)try{r=(new DOMParser).parseFromString(e,t);const n=r.querySelector&&r.querySelector("parsererror");if(n)throw new Error(n.textContent.split("\n")[0])}catch(e){return{ok:!1,attempts:[{ok:!1,error:"Could not parse "+("text/html"===t?"HTML":"XML")+": "+e.message}]}}const l=[];for(let n=0;n<o.length;n++){let i,s,a,c;try{({interpretFn:i,serializeFn:s,interpretTextFn:a,serializeTextFn:c}=Du(o[n]));if("function"!=typeof(t?i:a))throw new Error("interpreter script must define function "+(t?"interpretXML(xmlDocument)":"interpretText(text)"))}catch(e){l.push({ok:!1,error:"Interpreter script error: "+e.message});continue}try{const d=t?i(r):a(e);return l.push({ok:!0,error:null}),{ok:!0,value:d,interpretFn:i,serializeFn:s,interpretTextFn:a,serializeTextFn:c,workingSource:o[n],workingIndex:n,attempts:l}}catch(e){l.push({ok:!1,error:"threw: "+(e&&e.message||e)})}}return{ok:!1,attempts:l}}function Fu(e,t){const n=[];for(const o of Object.keys(t)){const r=zu(e,Ju(o),t[o]);if(n.push({format:o,attempts:r.attempts}),r.ok)return Object.assign({format:o},r)}return{ok:!1,attempts:n}}function Ku(e,t,n,o,r,l){const i=ws(e,t,n);i.interpreterSource=e.workingSource,Wu(n,e.workingSource),Bu(e.value,o||"data",i,{rawText:l});Lu("Loaded "+(o||"data")+" via interpreter"+(e.attempts.length>1?" (interpreter "+(e.workingIndex+1)+" of "+e.attempts.length+" worked)":"")+(r||"")+((t?!!e.serializeFn:!!e.serializeTextFn)?"":" (read-only — no "+(t?"serializeXML":"serializeText")+" defined)"))}function qu(e,t,n){if(!Fr)return;Vr({type:"structile-embed-interpreter-resolved",candidates:(Array.isArray(e)?e:[e]).map((e,o)=>{const r=n&&n[o]||"candidate "+(o+1),l=t.attempts[o];return l?l.ok?{name:r,outcome:"used"}:{name:r,outcome:"raised",error:l.error}:{name:r,outcome:"not_tried"}})})}function Xu(e,t,n,o,r,l){const i=zu(e,n,t);qu(t,i,l);const s=r||("text/html"===n?"html":"xml");if(!i.ok){const e=i.attempts[i.attempts.length-1];return Lu((i.attempts.length>1?"None of "+i.attempts.length+" interpreters worked — ":"")+(e?e.error:"interpreter failed")),!1}return Ku(i,n,s,o,"",e),!0}function Uu(e,t,n){const o=Fu(e,t);if(!o.ok){return Lu("Could not determine a format for this data — none of the interpreters for "+Object.keys(t).join("/")+" accepted it"),!1}return Ku(o,Ju(o.format),o.format,n," (format: "+o.format+")",e),!0}function Vu(e,t,n,o){if(Pu&&"interpreter"===Pu.kind){return void(Xu(e,Pu.text,t,n,o)&&Au())}const r=!!(o&&ju[o]&&ju[o].length);Hu(e,t,n,o)||(Pu={kind:"data",text:e,mode:t,name:n,format:o,cacheMissed:r},Nu())}function Yu(e,t){if(Pu&&"data"===Pu.kind){return void(Xu(Pu.text,e,Pu.mode,Pu.name,Pu.format)&&Au())}Pu={kind:"interpreter",text:e,name:t},Nu()}function Ju(e){return"html"===e?"text/html":"xml"===e?"application/xml":null}const $u={".xml":"xml",".html":"html",".htm":"html",".ini":"ini",".toml":"toml",".yaml":"yaml",".yml":"yaml",".csv":"csv"},Gu=Object.keys($u),Zu=".json, .py, .xml, .html, .ini, .toml, .yaml, .csv";function Qu(e){const t=/\.[^./\\]+$/.exec(e);return t&&$u[t[0].toLowerCase()]||null}function ef(e){return Ju(Qu(e))}function tf(e){return e.replace(/\.[^./\\]+$/,"")}function nf(e,t){_u(e,n=>{_u(t,t=>{Xu(n,t,ef(e.name),tf(e.name),Qu(e.name))})})}function of(e){_u(e,t=>{try{const{value:n,format:o}=bs(t);Bu(n,e.name.replace(/\.(json|py)$/i,""),o,{rawText:t}),Lu("Loaded "+e.name)}catch(t){Lu("Could not load "+e.name+" — "+t.message)}})}function rf(e){if(!e)return;const t=Ru(e.name);"view"!==t?"settings"!==t?"python"!==t?"structureddata"!==t?"interpreter"!==t?of(e):_u(e,t=>Yu(t,tf(e.name))):_u(e,t=>Vu(t,ef(e.name),tf(e.name),Qu(e.name))):_u(e,t=>{try{Bu(cs(t),tf(e.name),vs,{rawText:t}),Lu("Loaded "+e.name)}catch(t){Lu("Invalid Python data in "+e.name+" — "+t.message)}}):vu(e):ku(e)}function lf(e,t){return"python"===t?"python":"structureddata"===t?Qu(e):"json"===t?"json":null}let sf=null;function af(){return sf?"left"===sf.lockedSide?sf.right?null:"right":"right"===sf.lockedSide?sf.left?null:"left":sf.left?sf.right?null:"right":"left":null}function cf(e){if(!e||void 0!==e.value)return;if("json"===e.format){try{e.value=ms(e.text),delete e.error}catch(t){e.error="invalid JSON — "+t.message}return}if("python"===e.format){try{e.value=cs(e.text),delete e.error}catch(t){e.error="invalid Python literal — "+t.message}return}if(!sf.interpreterPool.length)return;const t=Ju(e.format),n=sf.interpreterPool.map(e=>e.source),o=zu(e.text,t,n);o.ok?(e.value=o.value,e.workingSource=o.workingSource,delete e.lastAttempts):e.lastAttempts=o.attempts}function df(){if(!sf)return;cf(sf.left),cf(sf.right);const e=sf.left,t=sf.right;if(e&&void 0!==e.value&&t&&void 0!==t.value){const n={name:e.name,format:e.format,text:e.text,value:e.value},o={name:t.name,format:t.format,text:t.text,value:t.value};return sf=null,hf(),kl(n,o,e.workingSource||"",t.workingSource||"","unified",null),void Lu("Comparing "+n.name+" and "+o.name)}ff()}function uf(e,t){if(!e)return t+": not yet — drop or choose a data file";if(void 0!==e.value)return t+": "+e.name+" ("+e.format+") ✓";if(e.error)return t+": "+e.name+" — "+e.error;if("json"!==e.format&&"python"!==e.format){const n=sf.interpreterPool.length;return t+": "+e.name+" ("+e.format+") — needs an interpreter (.js)"+(n?" — tried "+n+", none worked yet":"")}return t+": "+e.name+" ("+e.format+")"}function ff(){const e=document.getElementById("diffIntakePanel");e&&(sf?(e.hidden=!1,document.getElementById("diffIntakeStatus").innerHTML=ge(uf(sf.left,"Left"))+"<br>"+ge(uf(sf.right,"Right"))):e.hidden=!0)}function hf(){const e=document.getElementById("diffIntakePanel");e&&(e.hidden=!0)}function pf(){sf=null,hf()}function mf(e){if(!sf||!e||!e.length)return;const t=Array.from(e),n=[],o=[],r=[];for(const e of t){const t=Ru(e.name);"interpreter"===t?o.push(e):"view"===t||"settings"===t?r.push(e):n.push({file:e,kind:t})}if(r.length&&Lu("Ignoring "+r.length+" unrelated file(s) — a diff needs data file(s) and/or interpreter(s) only."),n.length>1)Lu("Already assembling a diff — pick exactly one data file (plus any interpreters it needs), not "+n.length+".");else if(1===n.length){const e=af();if(e){const t=n[0].file,o=lf(t.name,n[0].kind);o?_u(t,n=>{sf&&(sf[e]={name:t.name.replace(/\.[^./\\]+$/,""),format:o,text:n,value:void 0},df())}):Lu("Choose a data file ("+Zu+") for the diff.")}else Lu("Both sides are already set — Cancel to start over, or click a side's name (once compared) to replace it.")}for(const e of o)_u(e,t=>{sf&&(sf.interpreterPool.some(e=>e.source===t)||sf.interpreterPool.push({source:t,name:e.name}),df())});n.length||o.length||ff()}function gf(){if(tl||!S)return;const e=C&&"xml"===C.kind?C.ext:C&&C.kind;let t="";if("function"==typeof C.serialize)try{t=C.serialize(x)}catch(e){t=""}const n=C&&"xml"===C.kind&&C.interpreterSource||"";sf={left:{name:k,format:e,text:t,value:x,workingSource:n||void 0},right:null,lockedSide:"left",interpreterPool:[]},n&&sf.interpreterPool.push({source:n,name:"("+k+"'s interpreter)"}),ff(),document.getElementById("diffIntakeInput").click()}function yf(e){if(!tl||nl)return;const t="left"===e?"right":"left",n="left"===t?rl:ll,o="left"===t?il:sl;sf={left:null,right:null,lockedSide:t,interpreterPool:[]},sf[t]={name:n.name,format:n.format,text:n.text,value:n.value,workingSource:o||void 0};for(const e of[il,sl])e&&!sf.interpreterPool.some(t=>t.source===e)&&sf.interpreterPool.push({source:e,name:"(current interpreter)"});ff(),document.getElementById("diffIntakeInput").click()}function vf(e){if(!e||!e.length)return;const t=Array.from(e);if(1===t.length)return void rf(t[0]);if(sf)return void mf(t);const n=[],o=[],r=[];for(const e of t){const t=Ru(e.name);"interpreter"===t?o.push(e):"view"===t||"settings"===t?r.push(e):n.push({file:e,kind:t})}if(1!==n.length||1!==o.length||0!==r.length||"structureddata"!==n[0].kind){if(2===n.length&&o.length<=1&&0===r.length){const[e,t]=n,r=lf(e.file.name,e.kind),l=lf(t.file.name,t.kind);return r&&l?(sf={left:null,right:null,lockedSide:null,interpreterPool:[]},_u(e.file,t=>{sf&&(sf.left={name:e.file.name.replace(/\.[^./\\]+$/,""),format:r,text:t,value:void 0},df())}),_u(t.file,e=>{sf&&(sf.right={name:t.file.name.replace(/\.[^./\\]+$/,""),format:l,text:e,value:void 0},df())}),1===o.length&&_u(o[0],e=>{sf&&(sf.interpreterPool.push({source:e,name:o[0].name}),df())}),void ff()):void Lu("Choose two data files ("+Zu+") to compare.")}Lu("Could not tell what to do with these "+t.length+" files — drop one data file, a markup file with its interpreter, or two data files (plus any interpreters) to compare.")}else nf(n[0].file,o[0])}function wf(e,t){if(!e)return;const n=t||vf,o=t=>{t.preventDefault(),t.stopPropagation(),e.classList.add("drag")},r=t=>{t.preventDefault(),t.stopPropagation(),e.classList.remove("drag")};e.addEventListener("dragenter",o),e.addEventListener("dragover",o),e.addEventListener("dragleave",r),e.addEventListener("drop",e=>{r(e),n(e.dataTransfer&&e.dataTransfer.files)})}function bf(){Bu({},"data",ys,{hasRealName:!1}),S=!1,L(),Ou(),Lu("No data loaded — use Load data… or Paste… to get started.")}const xf="Special values",kf="Table columns";function Ef(){const e=[];for(const t of l)t.section&&e.push(t.section);return e.push(xf),e.push(kf),e}let Sf=null;function Lf(){const e=document.getElementById("settingsTabs");if(!e)return;const t=Ef();Sf&&t.includes(Sf)||(Sf=t[0]),e.innerHTML="";for(const n of t){const t=document.createElement("button");t.type="button",t.className="btn sm toggle settings-tab"+(n===Sf?" active":""),t.textContent=n,t.dataset.tab=n,e.appendChild(t)}}function Cf(){const e=document.getElementById("settingsGrid"),t=document.getElementById("settingsSpecialPanel"),n=document.getElementById("settingsTableColPanel");if(!e||!t||!n)return;const o=Sf===xf,r=Sf===kf;if(t.hidden=!o,n.hidden=!r,e.hidden=o||r,e.innerHTML="",!o&&!r){let t=!1;for(const n of l){if(n.section){t=n.section===Sf;continue}if(!t)continue;const o=document.createElement("label"),r="checkbox"===n.type;r&&(o.className="ctl-row"),o.appendChild(document.createTextNode(n.label));const l=document.createElement("input");l.id="s_"+n.key,r?l.type="checkbox":(l.type="number",l.min=String(n.min),l.step=String(n.step)),l.addEventListener("change",()=>Bf(n.key)),o.appendChild(l),e.appendChild(o)}}Tf()}function If(e){e!==Sf&&(Sf=e,Lf(),Cf())}function Mf(){Lf(),Cf()}function Tf(){for(const e of a){const t=document.getElementById("s_"+e);t&&("checkbox"===i.get(e).type?t.checked=!!u[e]:t.value=u[e])}}function Of(e){const t=document.getElementById("s_"+e);if(!t)return;const n=i.get(e);if("checkbox"===n.type)return void(u[e]=t.checked);let o=parseFloat(t.value);isFinite(o)||(o=d[e]),!1!==n.round&&(o=Math.round(o)),o=Math.max(n.min,o),u[e]=o,t.value=o}function Bf(e){j&&ss(),Of(e),c.has(e)?(kn(),Ri()):Ri()}function _f(){const e=document.getElementById("linkSettingsPanel");e&&(e.innerHTML='<div class="panel-row"><label class="ctl">Link prefix &#8594; <input type="text" id="linkOpen" placeholder="(off)"></label><label class="ctl">Link suffix &#8594; <input type="text" id="linkClose" placeholder="(off)"></label></div>',document.getElementById("linkOpen").value=h.open,document.getElementById("linkClose").value=h.close,Rf())}function Rf(){const e=document.getElementById("linkSettingsPanel");e._wired||(e._wired=!0,e.addEventListener("change",e=>{const t=e.target;return"linkOpen"===t.id?(h.open=t.value,Oe(),void jf()):"linkClose"===t.id?(h.close=t.value,Oe(),void jf()):void 0}))}let Pf=[];function Nf(){Pf=Object.keys(f.values).map(e=>({match:e,repl:f.values[e]}))}function Af(){const e={};for(const t of Pf)""!==t.match&&(e[t.match]=t.repl);f.values=e}function jf(){j&&ss(),w&&(kn(),Ri())}function Wf(){Af(),Ie(),jf()}function Hf(){return Pf.map((e,t)=>'<div class="panel-row rm-row" data-idx="'+t+'"><input type="text" class="rm-match" data-idx="'+t+'" value="'+ye(e.match)+'" placeholder="value to match"><span class="hint">shown as</span><input type="text" class="rm-repl" data-idx="'+t+'" value="'+ye(e.repl)+'" placeholder="replacement text"><button type="button" class="btn sm ghost rm-remove" data-idx="'+t+'" title="Remove">&times;</button></div>').join("")}function Df(){const e=document.getElementById("renderMapPanel");e&&(Nf(),e.innerHTML='<div class="panel-row"><label class="ctl">Null / None &#8594; <input type="text" id="rmNull" placeholder="(default)"></label><label class="ctl">Empty string &#8594; <input type="text" id="rmEmpty" placeholder="(default)"></label></div><div id="rmRows">'+Hf()+'</div><div class="panel-row"><button type="button" id="rmAdd" class="btn ghost sm">+ Add special value</button></div>',document.getElementById("rmNull").value=f.forNull||"",document.getElementById("rmEmpty").value=f.forEmpty||"",Ff())}function zf(){document.getElementById("rmRows").innerHTML=Hf()}function Ff(){const e=document.getElementById("renderMapPanel");e._wired||(e._wired=!0,e.addEventListener("change",e=>{const t=e.target;if("rmNull"===t.id)return f.forNull=""===t.value?null:t.value,Ie(),void jf();if("rmEmpty"===t.id)return f.forEmpty=""===t.value?null:t.value,Ie(),void jf();if(t.classList.contains("rm-match")||t.classList.contains("rm-repl")){const e=Number(t.getAttribute("data-idx")),n=Pf[e];if(!n)return;t.classList.contains("rm-match")?n.match=t.value:n.repl=t.value,Wf()}}),e.addEventListener("click",e=>{if("rmAdd"===e.target.id){Pf.push({match:"",repl:""}),zf();const e=document.querySelectorAll("#rmRows .rm-match");return void(e.length&&e[e.length-1].focus())}if(e.target.classList.contains("rm-remove")){const t=Number(e.target.getAttribute("data-idx"));Pf.splice(t,1),zf(),Wf()}}))}let Kf=[];function qf(){Kf=p.rules.map(e=>({pattern:e.pattern,width:e.width}))}function Xf(){p.rules=Kf.filter(e=>""!==e.pattern).map(e=>({pattern:e.pattern,width:Math.max(1,Math.round(Number(e.width))||1)}))}function Uf(){j&&ss(),w&&Ri()}function Vf(){Xf(),Re(),Uf()}function Yf(){return Kf.map((e,t)=>'<div class="panel-row tc-row" data-idx="'+t+'"><input type="text" class="tc-pattern" data-idx="'+t+'" value="'+ye(e.pattern)+'" placeholder="column name regex"><span class="hint">width (chars)</span><input type="number" class="tc-width" data-idx="'+t+'" min="1" step="1" value="'+ye(String(e.width))+'"><button type="button" class="btn sm ghost tc-remove" data-idx="'+t+'" title="Remove">&times;</button></div>').join("")}function Jf(){const e=document.getElementById("tableColRulesPanel");if(!e)return;qf(),e.innerHTML='<div id="tcRows">'+Yf()+'</div><div class="panel-row"><button type="button" id="tcAdd" class="btn ghost sm">+ Add column width rule</button></div>';const t=document.getElementById("tcLowOccThreshold"),n=document.getElementById("tcLowOccWidth");t&&(t.value=p.lowOccupancyThreshold),n&&(n.value=p.lowOccupancyWidth),Gf()}function $f(){document.getElementById("tcRows").innerHTML=Yf()}function Gf(){const e=document.getElementById("settingsTableColPanel");e&&!e._wired&&(e._wired=!0,e.addEventListener("change",e=>{const t=e.target;if("tcLowOccThreshold"===t.id){let e=parseFloat(t.value);return isFinite(e)||(e=0),e=Math.min(1,Math.max(0,e)),p.lowOccupancyThreshold=e,t.value=e,Re(),void Uf()}if("tcLowOccWidth"===t.id){let e=Math.round(parseFloat(t.value));return(!isFinite(e)||e<1)&&(e=1),p.lowOccupancyWidth=e,t.value=e,Re(),void Uf()}if(t.classList.contains("tc-pattern")||t.classList.contains("tc-width")){const e=Number(t.getAttribute("data-idx")),n=Kf[e];if(!n)return;t.classList.contains("tc-pattern")?n.pattern=t.value:n.width=t.value,Vf()}}),e.addEventListener("click",e=>{if("tcAdd"===e.target.id){Kf.push({pattern:"",width:p.lowOccupancyWidth||8}),$f();const e=document.querySelectorAll("#tcRows .tc-pattern");return void(e.length&&e[e.length-1].focus())}if(e.target.classList.contains("tc-remove")){const t=Number(e.target.getAttribute("data-idx"));Kf.splice(t,1),$f(),Vf()}}))}function Zf(e,t){let n=null;return function(){const o=arguments;clearTimeout(n),n=setTimeout(()=>e.apply(null,o),t)}}async function Qf(){Ne(),Ae(),Ue(),Rr=Ar(),Me(),Be(),Pe(),Zr();const e=document.getElementById("fileInput");document.getElementById("fileNameLabel").addEventListener("click",()=>{Fr||e.click()}),e.addEventListener("change",()=>{vf(e.files),e.value=""});const t=document.getElementById("diffIntakeInput"),n=document.getElementById("diffBtn");n.addEventListener("click",gf),wf(n,e=>{sf?mf(e):!tl&&S&&(gf(),mf(e))}),t.addEventListener("change",()=>{mf(t.files),t.value=""}),document.getElementById("diffIntakeAddBtn").addEventListener("click",()=>t.click()),document.getElementById("diffIntakeCancelBtn").addEventListener("click",pf),wf(document.getElementById("diffIntakeDrop"),mf),document.getElementById("undoBtn").addEventListener("click",or),document.getElementById("redoBtn").addEventListener("click",rr),document.getElementById("undoMenuBtn").addEventListener("click",e=>{e.stopPropagation(),gr("undo",e.currentTarget)}),document.getElementById("redoMenuBtn").addEventListener("click",e=>{e.stopPropagation(),gr("redo",e.currentTarget)}),document.getElementById("saveBtn").addEventListener("click",Sr),document.getElementById("saveAsBtn").addEventListener("click",e=>{e.stopPropagation(),Br(e.currentTarget)}),document.getElementById("hostSaveBtn").addEventListener("click",Lr),document.getElementById("pasteBtn").addEventListener("click",()=>{tl&&ml(),ua||(ua=!0,Le(!0),fa()),S||da(),Ri();const e=document.getElementById("sourcePanelInput");e&&(Ia.single=[],e.readOnly=!1,e.focus())}),wf(document.getElementById("bar"));const o=document.getElementById("pendingPairFile");document.getElementById("pendingPairBtn").addEventListener("click",()=>o.click()),document.getElementById("pendingPairCancel").addEventListener("click",Au),o.addEventListener("change",()=>{const e=o.files&&o.files[0];e&&Pu&&("data"===Pu.kind?_u(e,t=>Yu(t,tf(e.name))):_u(e,t=>Vu(t,ef(e.name),tf(e.name),Qu(e.name)))),o.value=""}),document.getElementById("aboutBtn").addEventListener("click",e=>{e.stopPropagation(),Tu(e.currentTarget)}),document.getElementById("saveViewBtn").addEventListener("click",iu);const r=document.getElementById("viewInput");document.getElementById("loadViewBtn").addEventListener("click",()=>r.click()),r.addEventListener("change",()=>{const e=r.files&&r.files[0];e&&ku(e),r.value=""});const l=document.getElementById("settingsPanel"),i=document.getElementById("settingsBtn");i.addEventListener("click",()=>{l.hidden=!l.hidden,i.classList.toggle("active",!l.hidden),i.setAttribute("aria-pressed",l.hidden?"false":"true")}),document.getElementById("resetSettings").addEventListener("click",()=>{u=Object.assign({},d),Tf(),j&&ss(),kn(),Ri(),Lu("Reset settings to built-in defaults")});const s=document.getElementById("settingsInput");document.getElementById("loadSettings").addEventListener("click",()=>s.click()),document.getElementById("exportSettings").addEventListener("click",hu),document.getElementById("setDefaultSettingsBtn").addEventListener("click",pu),s.addEventListener("change",()=>{const e=s.files&&s.files[0];e&&vu(e),s.value=""}),document.getElementById("settingsTabs").addEventListener("click",e=>{const t=e.target.closest(".settings-tab");t&&If(t.dataset.tab)}),Mf(),_f(),Df(),Jf();const a=document.getElementById("searchInput");a.addEventListener("input",Zf(()=>Gi(a.value),180)),a.addEventListener("keydown",e=>{"Enter"===e.key?(e.preventDefault(),e.shiftKey?ls():rs()):"Escape"===e.key&&(ss(),a.blur())}),document.getElementById("nextMatch").addEventListener("click",rs),document.getElementById("prevMatch").addEventListener("click",ls);const c=document.getElementById("caseBtn"),f=document.getElementById("regexBtn");c.addEventListener("click",()=>{ji=!ji,c.classList.toggle("active",ji),Gi(a.value)}),f.addEventListener("click",()=>{Wi=!Wi,f.classList.toggle("active",Wi),Gi(a.value)}),["single","left","right"].forEach(e=>{const t=Ha(e,"sourceFindInput");if(!t)return;t.addEventListener("input",Zf(()=>Za(e),180)),t.addEventListener("keydown",t=>{"Enter"===t.key?(t.preventDefault(),t.shiftKey?Ga(e):$a(e)):"Escape"===t.key&&(t.preventDefault(),ec(e))});const n=Ha(e,"sourceFindCase"),o=Ha(e,"sourceFindRegex");n&&n.addEventListener("click",()=>{const t=ja[e];t.caseSensitive=!t.caseSensitive,n.classList.toggle("active",t.caseSensitive),Za(e)}),o&&o.addEventListener("click",()=>{const t=ja[e];t.useRegex=!t.useRegex,o.classList.toggle("active",t.useRegex),Za(e)});const r=Ha(e,"sourceFindPrev"),l=Ha(e,"sourceFindNext");r&&r.addEventListener("click",()=>Ga(e)),l&&l.addEventListener("click",()=>$a(e));const i=Ha(e,"sourceFindClose");i&&i.addEventListener("click",()=>ec(e));const s=document.getElementById("sourceFindToggleBtn"+Wa(e));s&&s.addEventListener("click",()=>tc(e))}),window.addEventListener("resize",Zf(()=>{j||kn(),Ri()},160)),document.addEventListener("keydown",t=>{const n=t.ctrlKey||t.metaKey;if(n&&"f"===t.key.toLowerCase()){t.preventDefault();const e=oc();return e?void Qa(e):(a.focus(),void a.select())}if(n&&"o"===t.key.toLowerCase())return t.preventDefault(),void e.click();if(n&&"s"===t.key.toLowerCase()){if(Kr)return;if(t.preventDefault(),tl&&nl)return void Rd();if(tl){const e=document.activeElement&&document.activeElement.id;return void("sourcePanelLeftInput"===e?ud("left"):"sourcePanelRightInput"===e?ud("right"):Lu("Focus a source pane to save that side (Ctrl+S)"))}Sr()}else{if(n&&"z"===t.key.toLowerCase()&&document.activeElement!==a&&!/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName))return t.preventDefault(),void or();if(n&&"y"===t.key.toLowerCase()&&document.activeElement!==a&&!/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName))return t.preventDefault(),void rr();if("Escape"===t.key){const e=t.target===a,n=t.target&&"string"==typeof t.target.id&&0===t.target.id.indexOf("sourceFindInput");return void(e||n||!yc()||(xc(null),t.preventDefault()))}"/"!==t.key||document.activeElement===a||/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName)||(t.preventDefault(),a.focus())}}),document.getElementById("canvas").addEventListener("dblclick",Bi),document.getElementById("canvasWrap").addEventListener("click",Oc);const h=document.getElementById("sourcePanelInput");h&&(h.addEventListener("input",ca),h.addEventListener("scroll",Qs),h.addEventListener("click",_c),h.addEventListener("dblclick",Rc),h.addEventListener("copy",e=>{I&&_a("single",I.text,e)}),h.addEventListener("compositionstart",()=>{zs=!0;const e=document.getElementById("sourcePanel");e&&e.querySelector(".source-edit-wrap").classList.add("composing")}),h.addEventListener("compositionend",()=>{zs=!1;const e=document.getElementById("sourcePanel");e&&e.querySelector(".source-edit-wrap").classList.remove("composing"),I&&(sa(I.revision),aa(I.revision),Ys())}));const p=document.getElementById("sourceRenderBtn");p&&p.addEventListener("click",()=>{I&&(Hs&&(clearTimeout(Hs),Hs=null),Ds&&(clearTimeout(Ds),Ds=null),oa(I.revision))});const m=document.getElementById("sourceRenderBtnRight");m&&m.addEventListener("click",()=>{ll&&(Ed&&(clearTimeout(Ed),Ed=null),Sd&&(clearTimeout(Sd),Sd=null),Od(ll.revision))}),document.getElementById("canvasWrap").addEventListener("click",qc);const g=document.getElementById("canvasLeft"),y=document.getElementById("canvasRight"),v=document.getElementById("canvasWrapLeft"),w=document.getElementById("canvasWrapRight");v&&v.addEventListener("click",e=>Xc("left",e)),w&&w.addEventListener("click",e=>Xc("right",e)),y&&y.addEventListener("dblclick",Uc),g&&g.addEventListener("dblclick",e=>Qd("left",e)),y&&y.addEventListener("dblclick",e=>Qd("right",e)),["left","right"].forEach(e=>{const t=nd(e),n=document.getElementById(t.input);if(!n)return;n.addEventListener("input",t=>ad(e,t)),n.addEventListener("scroll",()=>rd(e)),n.addEventListener("click",t=>Jc(e,t)),n.addEventListener("dblclick",t=>$c(e,t)),n.addEventListener("copy",t=>{const n="left"===e?rl:ll;n&&_a(e,n.text,t)}),n.addEventListener("focus",()=>jc(e)),n.addEventListener("compositionstart",()=>{"left"===e?Qc=!0:ed=!0;const n=document.getElementById(t.wrap);n&&n.querySelector(".source-edit-wrap").classList.add("composing")}),n.addEventListener("compositionend",()=>{"left"===e?Qc=!1:ed=!1;const n=document.getElementById(t.wrap);n&&n.querySelector(".source-edit-wrap").classList.remove("composing");const o="left"===e?rl:ll;if(o)return nl&&"right"===e?(Bd(o.revision),_d(o.revision),void Id()):void sd(e,o.revision)});const o=document.getElementById(t.save);o&&o.addEventListener("click",()=>ud(e))}),mi();const b=()=>{if(window.__STRUCTILE_SNAPSHOT__){const e=window.__STRUCTILE_SNAPSHOT__;e&&"diff"===e.mode?Ll(e):Yr(e)}else Fr||bf()};Wr()?zr(e=>{e||b()}):b()}"undefined"!=typeof window&&window.__NO_AUTORUN||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",Qf):Qf()),"undefined"!=typeof module&&module.exports&&(module.exports={buildTree:Zt,fullLayout:kn,collectMatchesTree:Di,stableRelayout:An,packBest:Tn,buildTable:nt,classify:$,pkey:ie,fullColWidths:an,relayoutFromState:bu,buildView:ou,applyView:xu,_state:()=>({ROOT:w,NODES:b,STATE:M,settings:u})});</script>
187
+ </body>
188
+ </html>