@softwarity/geojson-editor 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/geojson-editor.js +2 -2
- package/package.json +2 -2
- package/src/constants.ts +74 -0
- package/src/geojson-editor.css +15 -3
- package/src/geojson-editor.d.ts +155 -0
- package/src/geojson-editor.ts +665 -765
- package/src/internal-types.ts +111 -0
- package/src/syntax-highlighter.ts +197 -0
- package/src/types.ts +48 -0
- package/src/utils.ts +59 -0
- package/src/validation.ts +90 -0
- package/types/geojson-editor.d.ts +146 -488
- package/types/types.d.ts +44 -0
- package/types/geojson-editor.template.d.ts +0 -4
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
A feature-rich, framework-agnostic **Web Component** for editing GeoJSON features with syntax highlighting, collapsible nodes, and integrated color picker.
|
|
25
25
|
|
|
26
|
-
**[🚀 Try the Live Demo](https://softwarity.github.io/geojson-editor/)**
|
|
26
|
+
**[🚀 Try the Live Demo](https://softwarity.github.io/geojson-editor/)** | **[📋 Release Notes](RELEASE_NOTES.md)**
|
|
27
27
|
|
|
28
28
|
<p align="center">
|
|
29
29
|
<a href="https://softwarity.github.io/geojson-editor/">
|
|
@@ -62,7 +62,8 @@ A feature-rich, framework-agnostic **Web Component** for editing GeoJSON feature
|
|
|
62
62
|
- **GeoJSON-Aware Highlighting** - Distinct colors for GeoJSON keywords (`type`, `coordinates`, `geometry`, etc.)
|
|
63
63
|
- **GeoJSON Type Validation** - Valid types (`Point`, `LineString`, `Polygon`, etc.) highlighted distinctly; invalid types (`LinearRing`, unknown types) shown with error styling (colors configurable via theme)
|
|
64
64
|
- **Syntax Highlighting** - JSON syntax highlighting with customizable color schemes
|
|
65
|
-
- **Collapsible Nodes** - Collapse/expand JSON objects and arrays with visual indicators (`{...}` / `[...]`); use
|
|
65
|
+
- **Collapsible Nodes** - Collapse/expand JSON objects and arrays with visual indicators (`{...}` / `[...]`); use Enter to expand and Shift+Enter to collapse; `coordinates` auto-collapsed on load
|
|
66
|
+
- **Attribute Navigation** - Tab/Shift+Tab to navigate between JSON attributes (keys and values) for quick editing
|
|
66
67
|
- **Virtualized Rendering** - Monaco-like architecture: only visible lines are rendered to DOM for optimal performance with large GeoJSON files
|
|
67
68
|
- **Feature Visibility Toggle** - Hide/show individual Features via eye icon in gutter; hidden features are grayed out and excluded from `change` events (useful for temporary filtering without deleting data)
|
|
68
69
|
- **Color Picker** - Built-in color swatch for hex color properties (`#rrggbb`) displayed inline next to the value; click to open native color picker
|
|
@@ -191,7 +192,7 @@ editor.addEventListener('error', (e) => {
|
|
|
191
192
|
| `readonly` | `boolean` | `false` | Make editor read-only |
|
|
192
193
|
| `dark-selector` | `string` | `".dark"` | CSS selector for dark color scheme detection |
|
|
193
194
|
|
|
194
|
-
**Note:** `coordinates` nodes are automatically collapsed when content is loaded to improve readability. Use
|
|
195
|
+
**Note:** `coordinates` nodes are automatically collapsed when content is loaded to improve readability. Use Enter to expand and Shift+Enter to collapse nodes, or click the gutter toggle. Use Tab/Shift+Tab to navigate between attributes.
|
|
195
196
|
|
|
196
197
|
### Dark Selector Syntax
|
|
197
198
|
|
|
@@ -415,8 +416,10 @@ const success = await editor.open({ collapsed: ['$root'] });
|
|
|
415
416
|
| `Ctrl+→` / `Cmd+→` | Move cursor to next word |
|
|
416
417
|
| `Ctrl+Shift+←` / `Cmd+Shift+←` | Select to previous word |
|
|
417
418
|
| `Ctrl+Shift+→` / `Cmd+Shift+→` | Select to next word |
|
|
418
|
-
| `
|
|
419
|
-
| `Shift+
|
|
419
|
+
| `Enter` | Expand collapsed node at cursor |
|
|
420
|
+
| `Shift+Enter` | Collapse innermost node containing cursor |
|
|
421
|
+
| `Tab` | Navigate to next attribute (key or value) |
|
|
422
|
+
| `Shift+Tab` | Navigate to previous attribute |
|
|
420
423
|
|
|
421
424
|
## Events
|
|
422
425
|
|
package/dist/geojson-editor.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license MIT
|
|
3
3
|
* @name @softwarity/geojson-editor
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.18
|
|
5
5
|
* @author Softwarity (https://www.softwarity.io/)
|
|
6
6
|
* @copyright 2025 Softwarity
|
|
7
7
|
* @see https://github.com/softwarity/geojson-editor
|
|
8
8
|
*/
|
|
9
|
-
const e=["type","geometry","properties","coordinates","id","features"],t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],s=/"geometry"\s*:/,i=/"properties"\s*:/,n=/"features"\s*:/,o=/^(\s*"[^"]+"\s*:\s*)([{\[])/,r=/^(\s*)([{\[]),?\s*$/,l=/&/g,a=/</g,h=/>/g,c=/([{}[\],:])/g,d=/"([^"]+)"(<span class="json-punctuation">:<\/span>)/g,u=/<span class="geojson-key">"type"<\/span><span class="json-punctuation">:<\/span>(\s*)"([^"]*)"/g,p=/(<span class="json-punctuation">:<\/span>)(\s*)"([^"]*)"/g,g=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,f=/(<span class="json-punctuation">:<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi,m=/(<span class="json-punctuation">[\[,]<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi,C=/^(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gim,y=/(<span class="json-punctuation">:<\/span>)(\s*)(true|false)/g,v=/(<span class="json-punctuation">:<\/span>)(\s*)(null)/g,L=/(<\/span>|^)([^<]+)(<span|$)/g,b=/^\s*$/,_=/(\s+)/;class x extends HTMLElement{constructor(){super(),this.lines=[],this.collapsedNodes=/* @__PURE__ */new Set,this.hiddenFeatures=/* @__PURE__ */new Set,this._nodeIdCounter=0,this._lineToNodeId=/* @__PURE__ */new Map,this._nodeIdToLines=/* @__PURE__ */new Map,this.visibleLines=[],this.lineMetadata=/* @__PURE__ */new Map,this.featureRanges=/* @__PURE__ */new Map,this.viewportHeight=0,this.lineHeight=19.5,this.bufferLines=5,this._lastStartIndex=-1,this._lastEndIndex=-1,this._lastTotalLines=-1,this._scrollRaf=null,this.cursorLine=0,this.cursorColumn=0,this.selectionStart=null,this.selectionEnd=null,this.renderTimer=null,this.inputTimer=null,this.themes={dark:{},light:{}},this._undoStack=[],this._redoStack=[],this._maxHistorySize=100,this._lastActionTime=0,this._lastActionType=null,this._groupingDelay=500,this._isSelecting=!1,this._isComposing=!1,this._blockRender=!1,this._charWidth=null,this._contextMapCache=null,this._contextMapLinesLength=0,this._contextMapFirstLine=void 0,this._contextMapLastLine=void 0,this.attachShadow({mode:"open"})}_invalidateRenderCache(){this._lastStartIndex=-1,this._lastEndIndex=-1,this._lastTotalLines=-1}_createSnapshot(){return{lines:[...this.lines],cursorLine:this.cursorLine,cursorColumn:this.cursorColumn,timestamp:Date.now()}}_restoreSnapshot(e){this.lines=[...e.lines],this.cursorLine=e.cursorLine,this.cursorColumn=e.cursorColumn,this.updateModel(),this._invalidateRenderCache(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange()}_saveToHistory(e="edit"){const t=Date.now();if(!(e===this._lastActionType&&t-this._lastActionTime<this._groupingDelay)){const e=this._createSnapshot();this._undoStack.push(e),this._undoStack.length>this._maxHistorySize&&this._undoStack.shift(),this._redoStack=[]}this._lastActionTime=t,this._lastActionType=e}undo(){if(0===this._undoStack.length)return!1;this._redoStack.push(this._createSnapshot());const e=this._undoStack.pop();return this._restoreSnapshot(e),this._lastActionType=null,this._lastActionTime=0,!0}redo(){if(0===this._redoStack.length)return!1;this._undoStack.push(this._createSnapshot());const e=this._redoStack.pop();return this._restoreSnapshot(e),this._lastActionType=null,this._lastActionTime=0,!0}clearHistory(){this._undoStack=[],this._redoStack=[],this._lastActionType=null,this._lastActionTime=0}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}_generateNodeId(){return"node_"+ ++this._nodeIdCounter}_getCollapsedRangeForLine(e){for(const[t,s]of this._nodeIdToLines)if(this.collapsedNodes.has(t)&&e>s.startLine&&e<s.endLine)return{nodeId:t,...s};return null}_getCollapsedClosingLine(e){for(const[t,s]of this._nodeIdToLines)if(this.collapsedNodes.has(t)&&e===s.endLine)return{nodeId:t,...s};return null}_getClosingBracketPos(e){return Math.max(e.lastIndexOf("]"),e.lastIndexOf("}"))}_getCollapsedNodeAtLine(e){const t=this._lineToNodeId.get(e);return t&&this.collapsedNodes.has(t)?{nodeId:t,...this._nodeIdToLines.get(t)}:null}_getCollapsibleNodeAtLine(e){const t=this._lineToNodeId.get(e);if(t){const e=this._nodeIdToLines.get(t);return{nodeId:t,isCollapsed:this.collapsedNodes.has(t),...e}}return null}_getContainingExpandedNode(e){let t=null;for(const[s,i]of this._nodeIdToLines)this.collapsedNodes.has(s)||e>=i.startLine&&e<=i.endLine&&(!t||i.endLine-i.startLine<t.endLine-t.startLine)&&(t={nodeId:s,...i});return t}_deleteCollapsedNode(e){this._saveToHistory("delete");const t=e.endLine-e.startLine+1;this.lines.splice(e.startLine,t),this.cursorLine=Math.min(e.startLine,this.lines.length-1),this.cursorColumn=0,this.formatAndUpdate()}_rebuildNodeIdMappings(){const e=new Set(this.collapsedNodes),t=/* @__PURE__ */new Map;for(const[n,o]of this._nodeIdToLines)o.nodeKey&&t.set(n,o.nodeKey);const s=[];for(const n of e){const e=t.get(n);e&&s.push(e)}this._nodeIdCounter=0,this._lineToNodeId.clear(),this._nodeIdToLines.clear(),this.collapsedNodes.clear();const i=/* @__PURE__ */new Map;for(let n=0;n<this.lines.length;n++){const e=this.lines[n],t=e.match(/^\s*"([^"]+)"\s*:\s*([{\[])/),o=!t&&e.match(/^\s*([{\[]),?\s*$/);if(!t&&!o)continue;let r,l;t?(r=t[1],l=t[2]):(l=o[1],r=`__root_${l}_${n}`);const a=e.substring(e.indexOf(l)+1),h=this._countBrackets(a,l);if(h.close>h.open)continue;const c=this._findClosingLine(n,l);if(-1===c||c===n)continue;const d=this._generateNodeId();this._lineToNodeId.set(n,d),this._nodeIdToLines.set(d,{startLine:n,endLine:c,nodeKey:r,isRootFeature:!!o});const u=i.get(r)||0;i.set(r,u+1);const p=s.indexOf(r);-1!==p&&(s.splice(p,1),this.collapsedNodes.add(d))}}static get observedAttributes(){return["readonly","value","placeholder","dark-selector"]}connectedCallback(){this.render(),this.setupEventListeners(),this.updatePrefixSuffix(),this.updateThemeCSS(),this.value&&this.setValue(this.value),this.updatePlaceholderVisibility()}disconnectedCallback(){this.renderTimer&&clearTimeout(this.renderTimer),this.inputTimer&&clearTimeout(this.inputTimer);const e=document.querySelector(".geojson-color-picker-input");e&&(e._closeListener&&document.removeEventListener("click",e._closeListener,!0),e.remove())}attributeChangedCallback(e,t,s){if(t!==s)switch(e){case"value":this.setValue(s);break;case"readonly":this.updateReadonly();break;case"placeholder":this.updatePlaceholderContent();break;case"dark-selector":this.updateThemeCSS()}}get readonly(){return this.hasAttribute("readonly")}get value(){return this.getAttribute("value")||""}get placeholder(){return this.getAttribute("placeholder")||""}get prefix(){return'{"type": "FeatureCollection", "features": ['}get suffix(){return"]}"}render(){const e=document.createElement("style");e.textContent=':host *,:host *:before,:host *:after{box-sizing:border-box;font: 13px/1.5 Courier New,Courier,monospace;font-variant:normal;letter-spacing:0;word-spacing:0;text-transform:none;text-decoration:none;text-indent:0}:host{--line-height: 19.5px;--gutter-width: 50px;--editor-padding-y: 8px;--editor-padding-x: 12px;display:flex;flex-direction:column;position:relative;width:100%;height:400px;border-radius:4px;overflow:hidden}:host([readonly]) .editor-wrapper:after{content:"";position:absolute;inset:0;pointer-events:none;background:repeating-linear-gradient(-45deg,rgba(128,128,128,.08),rgba(128,128,128,.08) 3px,transparent 3px,transparent 12px);z-index:1}:host([readonly]) .hidden-textarea{cursor:text}.editor-wrapper{position:relative;width:100%;flex:1;background:var(--bg-color, #fff);display:flex;overflow:hidden}.gutter{width:var(--gutter-width);background:var(--gutter-bg, #f0f0f0);border-right:1px solid var(--gutter-border, #e0e0e0);overflow:hidden;flex-shrink:0;position:relative}.gutter-scroll{position:absolute;inset:0;overflow:hidden;padding:8px 0}.gutter-scroll-content{position:relative;width:100%}.gutter-content{position:absolute;top:0;left:0;right:0;will-change:transform}.gutter-line{height:var(--line-height);display:flex;align-items:center;justify-content:flex-end;padding-right:4px}.line-number{font-size:11px;color:var(--gutter-text, #999);-webkit-user-select:none;user-select:none;min-width:20px;text-align:right}.collapse-column{width:16px;display:flex;align-items:center;justify-content:center;flex-shrink:0}.collapse-button{width:12px;height:12px;border-radius:2px;cursor:pointer;transition:transform .1s;flex-shrink:0;background:transparent;border:none;color:var(--json-punct, #a9b7c6);font-size:10px;display:flex;align-items:center;justify-content:center;-webkit-user-select:none;user-select:none;opacity:0;transition:opacity .15s}.collapse-button.collapsed,.gutter:hover .collapse-button{opacity:1}.collapse-button:hover{transform:scale(1.2)}@media(hover:none),(pointer:coarse){.collapse-button{opacity:1}}.editor-content{position:relative;flex:1;overflow:hidden}.hidden-textarea{position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;padding:0;margin:0;border:none;outline:none;resize:none;overflow:hidden;z-index:-1;pointer-events:none;caret-color:transparent}.viewport{position:absolute;inset:0;overflow:auto;padding:var(--editor-padding-y) var(--editor-padding-x);overscroll-behavior:contain}.scroll-content{position:relative;width:100%}.lines-container{position:absolute;top:0;left:0;right:0;will-change:transform}.line{height:var(--line-height);white-space:pre;display:block;position:relative}.cursor{position:absolute;width:2px;height:1em;background:var(--caret-color, #000);top:.15em;pointer-events:none;animation:cursor-blink 1s step-end infinite}@keyframes cursor-blink{0%,to{opacity:1}50%{opacity:0}}.selection{position:absolute;height:100%;top:0;background:var(--selection-color, rgba(51, 153, 255, .3));pointer-events:none;z-index:0}.line-hidden>span{opacity:.35;filter:grayscale(50%)}.placeholder-layer{position:absolute;top:var(--editor-padding-y);left:var(--editor-padding-x);color:#6a6a6a;pointer-events:none;z-index:0;white-space:pre}.json-key{color:var(--json-key, #660e7a)}.json-string{color:var(--json-string, #008000)}.json-number{color:var(--json-number, #00f)}.json-boolean,.json-null{color:var(--json-boolean, #000080)}.json-punctuation{color:var(--json-punct, #000)}.json-key-invalid{color:var(--json-key-invalid, #f00)}.json-error{color:var(--json-error, #f00)}.geojson-key{color:var(--geojson-key, #660e7a);font-weight:600}.geojson-type{color:var(--geojson-type, #008000);font-weight:600}.geojson-type-invalid{color:var(--geojson-type-invalid, #f00);font-weight:600}.collapsed-bracket-array,.collapsed-bracket-object{color:var(--json-punct, #000)}.collapsed-bracket-array:after,.collapsed-bracket-object:after{content:"…";color:var(--json-punct, #888)}.prefix-wrapper,.suffix-wrapper{display:flex;flex-shrink:0;background:var(--bg-color, #fff)}.prefix-gutter,.suffix-gutter{width:var(--gutter-width);background:var(--gutter-bg, #f0f0f0);border-right:1px solid var(--gutter-border, #e0e0e0);flex-shrink:0}.editor-prefix,.editor-suffix{flex:1;padding:4px 12px;color:var(--text-color, #000);background:var(--bg-color, #fff);-webkit-user-select:none;user-select:none;white-space:pre-wrap;word-wrap:break-word;opacity:.6}.prefix-wrapper{border-bottom:1px solid rgba(255,255,255,.1);position:relative}.suffix-wrapper{border-top:1px solid rgba(255,255,255,.1);position:relative}.info-btn{position:absolute;right:.5rem;top:50%;transform:translateY(-50%);background:transparent;border:none;color:var(--text-color, #000);opacity:.15;cursor:pointer;font-size:.7rem;width:1rem;height:1rem;padding:0;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:opacity .2s;font-family:sans-serif}.info-btn:hover{opacity:.5}.clear-btn{position:absolute;right:.5rem;top:50%;transform:translateY(-50%);background:transparent;border:none;color:var(--text-color, #000);opacity:.3;cursor:pointer;font-size:.65rem;width:1rem;height:1rem;padding:.15rem 0 0;border-radius:3px;display:flex;align-items:center;justify-content:center;transition:opacity .2s,background .2s}.clear-btn:hover{opacity:.7;background:#ffffff1a}.clear-btn[hidden]{display:none}.viewport::-webkit-scrollbar{width:10px;height:10px}.viewport::-webkit-scrollbar-track{background:var(--control-bg, #e8e8e8)}.viewport::-webkit-scrollbar-thumb{background:var(--control-border, #c0c0c0);border-radius:5px}.viewport::-webkit-scrollbar-thumb:hover{background:var(--control-color, #000080)}.viewport{scrollbar-width:thin;scrollbar-color:var(--control-border, #c0c0c0) var(--control-bg, #e8e8e8)}.json-color,.json-boolean{position:relative}.json-color:before,.json-boolean:before{content:"";position:absolute;left:-8px;top:50%;transform:translateY(-50%);margin-top:-1px;width:8px;height:8px;border-radius:2px;cursor:pointer}.json-color:hover:before,.json-boolean:hover:before{transform:translateY(-50%) scale(1.2);border-color:var(--control-color, #000080)}.json-color:before{background-color:var(--swatch-color);border:1px solid var(--json-punct, #a9b7c6)}.json-boolean:before{border:1.5px solid var(--control-border, #c0c0c0);background:transparent}.json-bool-true:before{content:"✔";border-color:var(--control-color, #000080);color:var(--control-color, #000080);font-size:8px;display:flex;align-items:center;justify-content:center;line-height:8px}.line.has-visibility:before{content:"👁";position:absolute;left:0;top:3px;font-size:10px;color:var(--control-color, #000080);opacity:.6;cursor:pointer;z-index:1}.line.has-visibility:hover:before{opacity:1;transform:scale(1.15)}.line.has-visibility.feature-hidden:before{opacity:.5}';const t=document.createElement("div");for(t.innerHTML=function(e="",t=""){return`\n <div class="prefix-wrapper">\n <div class="prefix-gutter"></div>\n <div class="editor-prefix" id="editorPrefix"></div>\n <button class="info-btn" id="infoBtn" title="@softwarity/geojson-editor v${t}" aria-label="About">ⓘ</button>\n </div>\n <div class="editor-wrapper">\n <div class="gutter">\n <div class="gutter-scroll" id="gutterScroll">\n <div class="gutter-scroll-content" id="gutterScrollContent">\n <div class="gutter-content" id="gutterContent"></div>\n </div>\n </div>\n </div>\n <div class="editor-content">\n <div class="placeholder-layer" id="placeholderLayer">${s=e,s?s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):""}</div>\n <textarea\n class="hidden-textarea"\n id="hiddenTextarea"\n spellcheck="false"\n autocomplete="off"\n autocorrect="off"\n autocapitalize="off"\n tabindex="0"\n ></textarea>\n <div class="viewport" id="viewport">\n <div class="scroll-content" id="scrollContent">\n <div class="lines-container" id="linesContainer"></div>\n </div>\n </div>\n </div>\n </div>\n <div class="suffix-wrapper">\n <div class="suffix-gutter"></div>\n <div class="editor-suffix" id="editorSuffix"></div>\n <button class="clear-btn" id="clearBtn" title="Clear editor">✕</button>\n </div>\n `;var s}(this.placeholder,"1.0.17"),this.shadowRoot.innerHTML="",this.shadowRoot.appendChild(e);t.firstChild;)this.shadowRoot.appendChild(t.firstChild)}setupEventListeners(){const e=this.shadowRoot.getElementById("hiddenTextarea"),t=this.shadowRoot.getElementById("viewport"),s=this.shadowRoot.getElementById("gutterContent"),i=this.shadowRoot.querySelector(".gutter"),n=this.shadowRoot.getElementById("clearBtn"),o=this.shadowRoot.querySelector(".editor-wrapper");this._isSelecting=!1,t.addEventListener("click",e=>{this.handleEditorClick(e)},!0),t.addEventListener("mousedown",t=>{const s=t.target,i=s.closest(".line.has-visibility");if(i){const e=i.getBoundingClientRect();if(t.clientX-e.left<14)return void(this._blockRender=!0)}if(s.classList.contains("json-color")||s.classList.contains("json-boolean")){const e=s.getBoundingClientRect(),i=t.clientX-e.left;if(i<0&&i>=-8)return void(this._blockRender=!0)}t.preventDefault();const n=this._getPositionFromClick(t);t.shiftKey&&this.selectionStart?(this.selectionEnd=n,this.cursorLine=n.line,this.cursorColumn=n.column):(this.cursorLine=n.line,this.cursorColumn=n.column,this.selectionStart={line:n.line,column:n.column},this.selectionEnd=null,this._isSelecting=!0),e.focus(),this._invalidateRenderCache(),this.scheduleRender()}),t.addEventListener("mousemove",e=>{if(!this._isSelecting)return;const s=this._getPositionFromClick(e);this.selectionEnd=s,this.cursorLine=s.line,this.cursorColumn=s.column;const i=t.getBoundingClientRect();e.clientY<i.top+30?t.scrollTop-=20:e.clientY>i.bottom-30&&(t.scrollTop+=20),this._invalidateRenderCache(),this.scheduleRender()}),document.addEventListener("mouseup",()=>{this._isSelecting=!1}),e.addEventListener("focus",()=>{o.classList.add("focused"),this._invalidateRenderCache(),this.scheduleRender()}),e.addEventListener("blur",()=>{o.classList.remove("focused"),this._invalidateRenderCache(),this.scheduleRender()});let r=!1;t.addEventListener("scroll",()=>{r||(this.syncGutterScroll(),this._scrollRaf||(this._scrollRaf=requestAnimationFrame(()=>{this._scrollRaf=null,r=!0,this.renderViewport(),r=!1})))}),e.addEventListener("compositionstart",()=>{this._isComposing=!0}),e.addEventListener("compositionend",()=>{this._isComposing=!1,this.handleInput()}),e.addEventListener("input",()=>{this._isComposing||this.handleInput()}),e.addEventListener("keydown",e=>{this.handleKeydown(e)}),e.addEventListener("paste",e=>{this.handlePaste(e)}),e.addEventListener("copy",e=>{this.handleCopy(e)}),e.addEventListener("cut",e=>{this.handleCut(e)}),s.addEventListener("click",e=>{this.handleGutterClick(e)}),i.addEventListener("mousedown",e=>{e.preventDefault()}),i.addEventListener("wheel",e=>{e.preventDefault(),t.scrollTop+=e.deltaY}),n.addEventListener("click",()=>{this.removeAll()}),this.updateReadonly()}setValue(e,t=!0){if(this.lines.length>0&&this._saveToHistory("setValue"),e&&e.trim())try{const t="["+e+"]",s=JSON.parse(t),i=JSON.stringify(s,null,2).split("\n");this.lines=i.slice(1,-1)}catch(s){this.lines=e.split("\n")}else this.lines=[];this.collapsedNodes.clear(),this.hiddenFeatures.clear(),this._lineToNodeId.clear(),this._nodeIdToLines.clear(),this.cursorLine=0,this.cursorColumn=0,this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),t&&this.lines.length>0&&requestAnimationFrame(()=>{this.autoCollapseCoordinates()}),this.emitChange()}getContent(){return this.lines.join("\n")}updateModel(){this._contextMapCache=null,this._rebuildNodeIdMappings(),this.computeFeatureRanges(),this.computeLineMetadata(),this.computeVisibleLines()}updateView(){this.computeLineMetadata(),this.computeVisibleLines()}computeFeatureRanges(){this.featureRanges.clear();try{const e=this.lines.join("\n"),t=this.prefix+e+this.suffix,s=JSON.parse(t);if(!s.features)return;let i=0,n=0,o=!1,r=-1,l=null;for(let a=0;a<this.lines.length;a++){const e=this.lines[a];if(!o&&/"type"\s*:\s*"Feature"/.test(e)){let e=a;for(let t=a;t>=0;t--){const s=this.lines[t].trim();if("{"===s||"{,"===s){e=t;break}}r=e,o=!0,n=1;for(let t=e;t<=a;t++){const s=this._countBrackets(this.lines[t],"{");n+=t===e?s.open-1-s.close:s.open-s.close}i<s.features.length&&(l=this._getFeatureKey(s.features[i]))}else if(o){const t=this._countBrackets(e,"{");n+=t.open-t.close,n<=0&&(l&&this.featureRanges.set(l,{startLine:r,endLine:a,featureIndex:i}),i++,o=!1,l=null)}}}catch(e){}}computeLineMetadata(){this.lineMetadata.clear();const e=this._findCollapsibleRanges();for(let t=0;t<this.lines.length;t++){const s=this.lines[t],i={colors:[],booleans:[],collapseButton:null,visibilityButton:null,isHidden:!1,isCollapsed:!1,featureKey:null},n=/"([\w-]+)"\s*:\s*"(#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}))"/g;let o;for(;null!==(o=n.exec(s));)i.colors.push({attributeName:o[1],color:o[2]});const r=/"([\w-]+)"\s*:\s*(true|false)/g;let l;for(;null!==(l=r.exec(s));)i.booleans.push({attributeName:l[1],value:"true"===l[2]});const a=e.find(e=>e.startLine===t);a&&(i.collapseButton={nodeKey:a.nodeKey,nodeId:a.nodeId,isCollapsed:this.collapsedNodes.has(a.nodeId)}),e.find(e=>this.collapsedNodes.has(e.nodeId)&&t>e.startLine&&t<e.endLine)&&(i.isCollapsed=!0);for(const[e,h]of this.featureRanges)if(t>=h.startLine&&t<=h.endLine){i.featureKey=e,this.hiddenFeatures.has(e)&&(i.isHidden=!0),t===h.startLine&&(i.visibilityButton={featureKey:e,isHidden:this.hiddenFeatures.has(e)});break}this.lineMetadata.set(t,i)}}computeVisibleLines(){this.visibleLines=[];for(let e=0;e<this.lines.length;e++){const t=this.lineMetadata.get(e);t&&t.isCollapsed||this.visibleLines.push({index:e,content:this.lines[e],meta:t})}this._invalidateRenderCache(),this._lastEndIndex=-1,this._lastTotalLines=-1}scheduleRender(){this.renderTimer||(this.renderTimer=requestAnimationFrame(()=>{this.renderTimer=null,this.renderViewport()}))}renderViewport(){if(this._blockRender)return;const e=this.shadowRoot.getElementById("viewport"),t=this.shadowRoot.getElementById("linesContainer"),s=this.shadowRoot.getElementById("scrollContent");if(this.shadowRoot.getElementById("gutterContent"),!e||!t)return;this.viewportHeight=e.clientHeight;const i=this.visibleLines.length,n=i*this.lineHeight;s&&(s.style.height=`${n}px`);const o=e.scrollTop,r=Math.floor(o/this.lineHeight),l=Math.ceil(this.viewportHeight/this.lineHeight),a=Math.max(0,r-this.bufferLines),h=Math.min(i,r+l+this.bufferLines);if(i>0&&this._lastStartIndex===a&&this._lastEndIndex===h&&this._lastTotalLines===i)return;this._lastStartIndex=a,this._lastEndIndex=h,this._lastTotalLines=i;const c=a*this.lineHeight;t.style.transform=`translateY(${c}px)`;const d=this._buildContextMap(),u=this.shadowRoot.querySelector(".editor-wrapper"),p=u?.classList.contains("focused"),g=document.createDocumentFragment();if(0===i){const e=document.createElement("div");return e.className="line empty-line",e.dataset.lineIndex="0",p&&(e.innerHTML=this._insertCursor(0)),g.appendChild(e),t.innerHTML="",t.appendChild(g),void this.renderGutter(0,0)}for(let f=a;f<h;f++){const e=this.visibleLines[f];if(!e)continue;const t=document.createElement("div");t.className="line",t.dataset.lineIndex=String(e.index),e.meta?.visibilityButton&&(t.classList.add("has-visibility"),t.dataset.featureKey=e.meta.visibilityButton.featureKey,e.meta.visibilityButton.isHidden&&t.classList.add("feature-hidden")),e.meta?.isHidden&&t.classList.add("line-hidden");const s=d.get(e.index);let i=this._highlightSyntax(e.content,s,e.meta);p&&this._hasSelection()&&(i=this._addSelectionHighlight(i,e.index,e.content)),p&&e.index===this.cursorLine&&(i+=this._insertCursor(this.cursorColumn)),t.innerHTML=i,g.appendChild(t)}t.innerHTML="",t.appendChild(g),this.renderGutter(a,h)}_insertCursor(e){return`<span class="cursor" style="left: ${e*this._getCharWidth()}px"></span>`}_addSelectionHighlight(e,t,s){const{start:i,end:n}=this._normalizeSelection();if(!i||!n)return e;if(t<i.line||t>n.line)return e;const o=this._getCharWidth();let r,l;return t===i.line&&t===n.line?(r=i.column,l=n.column):t===i.line?(r=i.column,l=s.length):t===n.line?(r=0,l=n.column):(r=0,l=s.length),`<span class="selection" style="left: ${r*o}px; width: ${(l-r)*o}px"></span>`+e}_getCharWidth(){if(!this._charWidth){const e=document.createElement("canvas").getContext("2d");e.font="13px 'Courier New', Courier, monospace",this._charWidth=e.measureText("M").width}return this._charWidth}renderGutter(e,t){const s=this.shadowRoot.getElementById("gutterContent"),i=this.shadowRoot.getElementById("gutterScrollContent");if(!s)return;const n=this.visibleLines.length*this.lineHeight;i&&(i.style.height=`${n}px`);const o=e*this.lineHeight;s.style.transform=`translateY(${o}px)`;const r=document.createDocumentFragment();for(let l=e;l<t;l++){const e=this.visibleLines[l];if(!e)continue;const t=document.createElement("div");t.className="gutter-line";const s=e.meta,i=document.createElement("span");i.className="line-number",i.textContent=String(e.index+1),t.appendChild(i);const n=document.createElement("div");if(n.className="collapse-column",s?.collapseButton){const t=document.createElement("div");t.className="collapse-button"+(s.collapseButton.isCollapsed?" collapsed":""),t.textContent=s.collapseButton.isCollapsed?"›":"⌄",t.dataset.line=String(e.index),t.dataset.nodeId=s.collapseButton.nodeId,t.title=s.collapseButton.isCollapsed?"Expand":"Collapse",n.appendChild(t)}t.appendChild(n),r.appendChild(t)}s.innerHTML="",s.appendChild(r)}syncGutterScroll(){const e=this.shadowRoot.getElementById("gutterScroll"),t=this.shadowRoot.getElementById("viewport");e&&t&&(e.scrollTop=t.scrollTop)}handleInput(){const e=this.shadowRoot.getElementById("hiddenTextarea"),t=e.value;if(t)if(this._getCollapsedRangeForLine(this.cursorLine))e.value="";else{if(this._getCollapsedClosingLine(this.cursorLine)){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);if(this.cursorColumn<=s)return void(e.value="")}if(this._getCollapsedNodeAtLine(this.cursorLine)){const t=this.lines[this.cursorLine].search(/[{\[]/);if(this.cursorColumn>t)return void(e.value="")}if(this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine],s=e.substring(0,this.cursorColumn),i=e.substring(this.cursorColumn),n=t.split("\n");if(1===n.length)this.lines[this.cursorLine]=s+t+i,this.cursorColumn+=t.length;else{this.lines[this.cursorLine]=s+n[0];for(let t=1;t<n.length-1;t++)this.lines.splice(this.cursorLine+t,0,n[t]);const e=n[n.length-1]+i;this.lines.splice(this.cursorLine+n.length-1,0,e),this.cursorLine+=n.length-1,this.cursorColumn=n[n.length-1].length}}else{const e=t.split("\n");this.lines.push(...e),this.cursorLine=this.lines.length-1,this.cursorColumn=this.lines[this.cursorLine].length}e.value="",clearTimeout(this.inputTimer),this.inputTimer=setTimeout(()=>{this.formatAndUpdate()},150)}}handleKeydown(e){const t={inCollapsedZone:this._getCollapsedRangeForLine(this.cursorLine),onCollapsedNode:this._getCollapsedNodeAtLine(this.cursorLine),onClosingLine:this._getCollapsedClosingLine(this.cursorLine)},s={Enter:()=>this._handleEnter(t),Backspace:()=>this._handleBackspace(t),Delete:()=>this._handleDelete(t),ArrowUp:()=>this._handleArrowKey(-1,0,e.shiftKey,e.ctrlKey||e.metaKey),ArrowDown:()=>this._handleArrowKey(1,0,e.shiftKey,e.ctrlKey||e.metaKey),ArrowLeft:()=>this._handleArrowKey(0,-1,e.shiftKey,e.ctrlKey||e.metaKey),ArrowRight:()=>this._handleArrowKey(0,1,e.shiftKey,e.ctrlKey||e.metaKey),Home:()=>this._handleHomeEnd("home",e.shiftKey,t.onClosingLine),End:()=>this._handleHomeEnd("end",e.shiftKey,t.onClosingLine),Tab:()=>this._handleTab(e.shiftKey,t)},i={a:()=>this._selectAll(),z:()=>e.shiftKey?this.redo():this.undo(),y:()=>this.redo(),s:()=>this.save(),o:()=>!this.hasAttribute("readonly")&&this.open()};if(s[e.key])return e.preventDefault(),void s[e.key]();(e.ctrlKey||e.metaKey)&&i[e.key]&&(e.preventDefault(),i[e.key]())}_handleEnter(e){if(!e.onCollapsedNode&&!e.inCollapsedZone){if(e.onClosingLine){const e=this.lines[this.cursorLine],t=this._getClosingBracketPos(e);if(t>=0&&this.cursorColumn<=t)return}this.insertNewline()}}_handleBackspace(e){if(this._hasSelection())return this._deleteSelection(),void this.formatAndUpdate();if(e.onClosingLine){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);return s>=0&&this.cursorColumn>s+1?void this.deleteBackward():void this._deleteCollapsedNode(e.onClosingLine)}if(e.onCollapsedNode&&0===this.cursorColumn)this._deleteCollapsedNode(e.onCollapsedNode);else if(!e.inCollapsedZone){if(e.onCollapsedNode){const t=this.lines[this.cursorLine].search(/[{\[]/);if(this.cursorColumn>t+1)return void this._deleteCollapsedNode(e.onCollapsedNode)}this.deleteBackward()}}_handleDelete(e){if(this._hasSelection())return this._deleteSelection(),void this.formatAndUpdate();if(e.onClosingLine){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);return s>=0&&this.cursorColumn>s?void this.deleteForward():void this._deleteCollapsedNode(e.onClosingLine)}if(e.onCollapsedNode){const t=this.lines[this.cursorLine].search(/[{\[]/);if(this.cursorColumn>t)return void this._deleteCollapsedNode(e.onCollapsedNode)}e.inCollapsedZone||this.deleteForward()}_handleTab(e,t){if(e){const e=this._getContainingExpandedNode(this.cursorLine);if(e){const t=this.lines[e.startLine],s=t.search(/[{\[]/);this.toggleCollapse(e.nodeId),this.cursorLine=e.startLine,this.cursorColumn=s>=0?s+1:t.length,this._clearSelection(),this._scrollToCursor()}return}t.onCollapsedNode?this.toggleCollapse(t.onCollapsedNode.nodeId):t.onClosingLine&&this.toggleCollapse(t.onClosingLine.nodeId)}insertNewline(){if(this._saveToHistory("newline"),this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine],t=e.substring(0,this.cursorColumn),s=e.substring(this.cursorColumn);this.lines[this.cursorLine]=t,this.lines.splice(this.cursorLine+1,0,s),this.cursorLine++,this.cursorColumn=0}else this.lines.push(""),this.cursorLine=this.lines.length-1,this.cursorColumn=0;this.formatAndUpdate()}deleteBackward(){if(this._saveToHistory("delete"),this.cursorColumn>0){const e=this.lines[this.cursorLine];this.lines[this.cursorLine]=e.substring(0,this.cursorColumn-1)+e.substring(this.cursorColumn),this.cursorColumn--}else if(this.cursorLine>0){const e=this.lines[this.cursorLine],t=this.lines[this.cursorLine-1];this.cursorColumn=t.length,this.lines[this.cursorLine-1]=t+e,this.lines.splice(this.cursorLine,1),this.cursorLine--}this.formatAndUpdate()}deleteForward(){if(this._saveToHistory("delete"),this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine];this.cursorColumn<e.length?this.lines[this.cursorLine]=e.substring(0,this.cursorColumn)+e.substring(this.cursorColumn+1):this.cursorLine<this.lines.length-1&&(this.lines[this.cursorLine]=e+this.lines[this.cursorLine+1],this.lines.splice(this.cursorLine+1,1))}this.formatAndUpdate()}moveCursorSkipCollapsed(e){let t=this.cursorLine+e;for(;t>=0&&t<this.lines.length;){const s=this._getCollapsedRangeForLine(t);s&&(t=e>0?s.endLine:s.startLine);break}this.cursorLine=Math.max(0,Math.min(this.lines.length-1,t));const s=this.lines[this.cursorLine]?.length||0;this.cursorColumn=Math.min(this.cursorColumn,s),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}moveCursorHorizontal(e){e>0?this._moveCursorRight():this._moveCursorLeft(),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_moveCursorRight(){const e=this.lines[this.cursorLine],t=this._getCollapsedNodeAtLine(this.cursorLine);if(this._getCollapsedClosingLine(this.cursorLine)){const t=this._getClosingBracketPos(e);this.cursorColumn<t?this.cursorColumn=t:this.cursorColumn>=e.length?this.cursorLine<this.lines.length-1&&(this.cursorLine++,this.cursorColumn=0):this.cursorColumn++}else if(t){const s=e.search(/[{\[]/);this.cursorColumn<s?this.cursorColumn++:this.cursorColumn===s?this.cursorColumn=s+1:(this.cursorLine=t.endLine,this.cursorColumn=this._getClosingBracketPos(this.lines[this.cursorLine]))}else if(this.cursorColumn>=e.length){if(this.cursorLine<this.lines.length-1){this.cursorLine++,this.cursorColumn=0;const e=this._getCollapsedRangeForLine(this.cursorLine);e&&(this.cursorLine=e.endLine,this.cursorColumn=0)}}else this.cursorColumn++}_moveCursorLeft(){const e=this.lines[this.cursorLine],t=this._getCollapsedNodeAtLine(this.cursorLine),s=this._getCollapsedClosingLine(this.cursorLine);if(s){const t=this._getClosingBracketPos(e);if(this.cursorColumn>t+1)this.cursorColumn--;else{this.cursorLine=s.startLine;const e=this.lines[this.cursorLine];this.cursorColumn=e.search(/[{\[]/)+1}}else if(t){const t=e.search(/[{\[]/);this.cursorColumn>t+1?this.cursorColumn=t+1:this.cursorColumn===t+1?this.cursorColumn=t:this.cursorColumn>0?this.cursorColumn--:this.cursorLine>0&&(this.cursorLine--,this.cursorColumn=this.lines[this.cursorLine]?.length||0)}else if(this.cursorColumn>0)this.cursorColumn--;else if(this.cursorLine>0)if(this.cursorLine--,this._getCollapsedClosingLine(this.cursorLine))this.cursorColumn=this.lines[this.cursorLine]?.length||0;else{const e=this._getCollapsedRangeForLine(this.cursorLine);if(e){this.cursorLine=e.startLine;const t=this.lines[this.cursorLine];this.cursorColumn=t.search(/[{\[]/)+1}else this.cursorColumn=this.lines[this.cursorLine]?.length||0}}_scrollToCursor(){const e=this.shadowRoot.getElementById("viewport");if(!e)return;const t=this.visibleLines.findIndex(e=>e.index===this.cursorLine);if(-1===t)return;const s=t*this.lineHeight,i=e.scrollTop,n=i+e.clientHeight;s<i?e.scrollTop=s:s+this.lineHeight>n&&(e.scrollTop=s+this.lineHeight-e.clientHeight)}_handleArrowKey(e,t,s,i=!1){s&&!this.selectionStart&&(this.selectionStart={line:this.cursorLine,column:this.cursorColumn}),0!==e?this.moveCursorSkipCollapsed(e):0!==t&&(i?this._moveCursorByWord(t):this.moveCursorHorizontal(t)),s?this.selectionEnd={line:this.cursorLine,column:this.cursorColumn}:(this.selectionStart=null,this.selectionEnd=null)}_moveCursorByWord(e){const t=this.lines[this.cursorLine]||"",s=e=>/[\w-]/.test(e),i=this._getCollapsedNodeAtLine(this.cursorLine);if(e>0){let e=this.cursorColumn;if(i){const s=t.search(/[{\[]/);if(s>=0&&e>=s)return this.cursorLine=i.endLine,this.cursorColumn=(this.lines[this.cursorLine]||"").length,this._invalidateRenderCache(),this._scrollToCursor(),void this.scheduleRender()}if(e>=t.length){if(this.cursorLine<this.lines.length-1){let e=this.cursorLine+1;const t=this._getCollapsedRangeForLine(e);t&&(e=t.endLine),this.cursorLine=Math.min(e,this.lines.length-1),this.cursorColumn=0}}else if(s(t[e])){for(;e<t.length&&s(t[e]);)e++;this.cursorColumn=e}else{for(;e<t.length&&!s(t[e]);)e++;this.cursorColumn=e}}else{let e=this.cursorColumn;const i=this._getCollapsedClosingLine(this.cursorLine);if(i){const s=this._getClosingBracketPos(t);if(s>=0&&e<=s+1){this.cursorLine=i.startLine;const e=(this.lines[this.cursorLine]||"").search(/[{\[]/);return this.cursorColumn=e>=0?e:0,this._invalidateRenderCache(),this._scrollToCursor(),void this.scheduleRender()}}if(0===e){if(this.cursorLine>0){let e=this.cursorLine-1;const t=this._getCollapsedRangeForLine(e);t&&(e=t.startLine),this.cursorLine=Math.max(e,0),this.cursorColumn=this.lines[this.cursorLine].length}}else if(e>0&&s(t[e-1])){for(;e>0&&s(t[e-1]);)e--;this.cursorColumn=e}else{for(;e>0&&!s(t[e-1]);)e--;for(;e>0&&s(t[e-1]);)e--;this.cursorColumn=e}}this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_handleHomeEnd(e,t,s){t&&!this.selectionStart&&(this.selectionStart={line:this.cursorLine,column:this.cursorColumn}),"home"===e?(s&&(this.cursorLine=s.startLine),this.cursorColumn=0):this.cursorLine<this.lines.length&&(this.cursorColumn=this.lines[this.cursorLine].length),t?this.selectionEnd={line:this.cursorLine,column:this.cursorColumn}:(this.selectionStart=null,this.selectionEnd=null),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_selectAll(){this.selectionStart={line:0,column:0};const e=this.lines.length-1;this.selectionEnd={line:e,column:this.lines[e]?.length||0},this.cursorLine=e,this.cursorColumn=this.lines[e]?.length||0,this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_getSelectedText(){if(!this.selectionStart||!this.selectionEnd)return"";const{start:e,end:t}=this._normalizeSelection();if(!e||!t)return"";if(e.line===t.line)return this.lines[e.line].substring(e.column,t.column);let s=this.lines[e.line].substring(e.column)+"\n";for(let i=e.line+1;i<t.line;i++)s+=this.lines[i]+"\n";return s+=this.lines[t.line].substring(0,t.column),s}_normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return{start:null,end:null};const e=this.selectionStart,t=this.selectionEnd;return e.line<t.line||e.line===t.line&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}_hasSelection(){return!(!this.selectionStart||!this.selectionEnd||this.selectionStart.line===this.selectionEnd.line&&this.selectionStart.column===this.selectionEnd.column)}_clearSelection(){this.selectionStart=null,this.selectionEnd=null}_deleteSelection(){if(!this._hasSelection())return!1;this._saveToHistory("delete");const{start:e,end:t}=this._normalizeSelection();if(e.line===t.line){const s=this.lines[e.line];this.lines[e.line]=s.substring(0,e.column)+s.substring(t.column)}else{const s=this.lines[e.line].substring(0,e.column),i=this.lines[t.line].substring(t.column);this.lines[e.line]=s+i,this.lines.splice(e.line+1,t.line-e.line)}return this.cursorLine=e.line,this.cursorColumn=e.column,this.selectionStart=null,this.selectionEnd=null,!0}insertText(e){if(this._hasSelection()&&this._deleteSelection(),!this._getCollapsedRangeForLine(this.cursorLine)){if(this._getCollapsedClosingLine(this.cursorLine)){const e=this.lines[this.cursorLine],t=this._getClosingBracketPos(e);if(this.cursorColumn<=t)return}if(this._getCollapsedNodeAtLine(this.cursorLine)){const e=this.lines[this.cursorLine].search(/[{\[]/);if(this.cursorColumn>e)return}if(this._saveToHistory("insert"),0===this.lines.length){const t=e.split("\n");this.lines=t,this.cursorLine=t.length-1,this.cursorColumn=t[t.length-1].length}else if(this.cursorLine<this.lines.length){const t=this.lines[this.cursorLine];this.lines[this.cursorLine]=t.substring(0,this.cursorColumn)+e+t.substring(this.cursorColumn),this.cursorColumn+=e.length}this.formatAndUpdate()}}handlePaste(e){e.preventDefault();const t=e.clipboardData.getData("text/plain");if(!t)return;const s=0===this.lines.length;try{const e=JSON.parse(t),s=this._normalizeToFeatures(e).map(e=>JSON.stringify(e,null,2)).join(",\n");this.insertText(s)}catch{this.insertText(t)}s&&this.lines.length>0&&(this.renderTimer&&(cancelAnimationFrame(this.renderTimer),this.renderTimer=null),this.autoCollapseCoordinates())}handleCopy(e){e.preventDefault(),this._hasSelection()?e.clipboardData.setData("text/plain",this._getSelectedText()):e.clipboardData.setData("text/plain",this.getContent())}handleCut(e){e.preventDefault(),this._hasSelection()?(e.clipboardData.setData("text/plain",this._getSelectedText()),this._saveToHistory("cut"),this._deleteSelection(),this.formatAndUpdate()):(e.clipboardData.setData("text/plain",this.getContent()),this._saveToHistory("cut"),this.lines=[],this.cursorLine=0,this.cursorColumn=0,this.formatAndUpdate())}_getPositionFromClick(e){const t=this.shadowRoot.getElementById("viewport"),s=this.shadowRoot.getElementById("linesContainer"),i=t.getBoundingClientRect(),n=e.clientY-i.top+t.scrollTop-8,o=Math.floor(n/this.lineHeight);let r=0,l=0;if(o>=0&&o<this.visibleLines.length){const n=this.visibleLines[o];r=n.index;const a=s?.querySelector(`.line[data-line-index="${n.index}"]`),h=this._getCharWidth();if(a){const t=a.getBoundingClientRect(),s=e.clientX-t.left,i=Math.round(s/h),o=n.content?.length||0;l=Math.max(0,Math.min(i,o))}else{const s=12,o=e.clientX-i.left+t.scrollLeft-s,r=Math.round(o/h),a=n.content?.length||0;l=Math.max(0,Math.min(r,a))}}return{line:r,column:l}}handleGutterClick(e){const t=e.target.closest(".visibility-button");if(t)this.toggleFeatureVisibility(t.dataset.featureKey);else if(e.target.classList.contains("collapse-button")){const t=e.target.dataset.nodeId;return void this.toggleCollapse(t)}}handleEditorClick(e){this._blockRender=!1;const t=e.target.closest(".line.has-visibility");if(t){const s=t.getBoundingClientRect();if(e.clientX-s.left<14){e.preventDefault(),e.stopPropagation();const s=t.dataset.featureKey;return void(s&&this.toggleFeatureVisibility(s))}}if(e.target.classList.contains("json-color")){const t=e.target.getBoundingClientRect(),s=e.clientX-t.left;if(s<0&&s>=-8){e.preventDefault(),e.stopPropagation();const t=e.target.dataset.color,s=e.target.closest(".line");if(s){const i=parseInt(s.dataset.lineIndex),n=this.lines[i].match(/"([\w-]+)"\s*:\s*"#/);n&&this.showColorPicker(e.target,i,t,n[1])}return}}if(e.target.classList.contains("json-boolean")){const t=e.target.getBoundingClientRect(),s=e.clientX-t.left;if(s<0&&s>=-8){e.preventDefault(),e.stopPropagation();const t=e.target.closest(".line");if(t){const e=parseInt(t.dataset.lineIndex),s=this.lines[e].match(/"([\w-]+)"\s*:\s*(true|false)/);if(s){const t="true"===s[2];this.updateBooleanValue(e,!t,s[1])}}return}}}toggleCollapse(e){this.collapsedNodes.has(e)?this.collapsedNodes.delete(e):this.collapsedNodes.add(e),this.updateView(),this._invalidateRenderCache(),this.scheduleRender()}autoCollapseCoordinates(){this._applyCollapsedOption(["coordinates"])}_applyCollapsedFromOptions(e,t){const s=void 0!==e.collapsed?e.collapsed:["coordinates"];s&&(!Array.isArray(s)||s.length>0)&&this._applyCollapsedOption(s,t)}_applyCollapsedOption(e,t=null){const s=this._findCollapsibleRanges(),i=s.filter(e=>e.isRootFeature);for(const n of s){let s=!1;if("function"==typeof e){const o=i.findIndex(e=>n.startLine>=e.startLine&&n.endLine<=e.endLine),r=e(t?.[o]||null,o);s=n.isRootFeature?r.includes("$root"):r.includes(n.nodeKey)}else Array.isArray(e)&&(s=n.isRootFeature?e.includes("$root"):e.includes(n.nodeKey));s&&this.collapsedNodes.add(n.nodeId)}this.updateModel(),this.scheduleRender()}toggleFeatureVisibility(e){this.hiddenFeatures.has(e)?this.hiddenFeatures.delete(e):this.hiddenFeatures.add(e),this.updateView(),this.scheduleRender(),this.emitChange()}showColorPicker(e,t,s,i){const n=document.querySelector(".geojson-color-picker-anchor");n&&n.remove();const o=document.createElement("div");o.className="geojson-color-picker-anchor";const r=e.getBoundingClientRect();o.style.cssText=`\n position: fixed;\n left: ${r.left-8}px;\n top: ${r.top+r.height}px;\n width: 10px;\n height: 10px;\n z-index: 9998;\n `,document.body.appendChild(o);const l=document.createElement("input");l.type="color",l.value=s,l.className="geojson-color-picker-input",l.style.cssText="\n position: absolute;\n left: 0;\n top: 0;\n width: 10px;\n height: 10px;\n opacity: 0;\n border: none;\n padding: 0;\n cursor: pointer;\n ",o.appendChild(l),l.addEventListener("input",e=>{this.updateColorValue(t,e.target.value,i)});const a=e=>{e.target!==l&&(document.removeEventListener("click",a,!0),o.remove())};l._closeListener=a,setTimeout(()=>{document.addEventListener("click",a,!0)},100),l.focus(),l.click()}updateColorValue(e,t,s){const i=new RegExp(`"${s}"\\s*:\\s*"#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})"`);this.lines[e]=this.lines[e].replace(i,`"${s}": "${t}"`),this.updateView(),this.scheduleRender(),this.emitChange()}updateBooleanValue(e,t,s){const i=new RegExp(`"${s}"\\s*:\\s*(true|false)`);this.lines[e]=this.lines[e].replace(i,`"${s}": ${t}`),this.updateView(),this.scheduleRender(),this.emitChange()}formatAndUpdate(){try{const e="["+this.lines.join("\n")+"]",t=JSON.parse(e),s=JSON.stringify(t,null,2).split("\n");this.lines=s.slice(1,-1)}catch(e){}this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange()}emitChange(){const e=this.getContent(),t=this.prefix+e+this.suffix;try{let s=JSON.parse(t);this.hiddenFeatures.size>0&&(s.features=s.features.filter(e=>{const t=this._getFeatureKey(e);return!this.hiddenFeatures.has(t)}));const i=this._validateGeoJSON(s);i.length>0?this.dispatchEvent(new CustomEvent("error",{detail:{error:i.join("; "),errors:i,content:e},bubbles:!0,composed:!0})):this.dispatchEvent(new CustomEvent("change",{detail:s,bubbles:!0,composed:!0}))}catch(s){this.dispatchEvent(new CustomEvent("error",{detail:{error:s.message,content:e},bubbles:!0,composed:!0}))}}updateReadonly(){const e=this.shadowRoot.getElementById("hiddenTextarea"),t=this.shadowRoot.getElementById("clearBtn");e&&(e.readOnly=this.readonly),t&&(t.hidden=this.readonly)}updatePlaceholderVisibility(){const e=this.shadowRoot.getElementById("placeholderLayer");e&&(e.style.display=this.lines.length>0?"none":"block")}updatePlaceholderContent(){const e=this.shadowRoot.getElementById("placeholderLayer");e&&(e.textContent=this.placeholder),this.updatePlaceholderVisibility()}updatePrefixSuffix(){const e=this.shadowRoot.getElementById("editorPrefix"),t=this.shadowRoot.getElementById("editorSuffix");e&&(e.textContent=this.prefix),t&&(t.textContent=this.suffix)}updateThemeCSS(){const e=this.getAttribute("dark-selector")||".dark",t=this._parseSelectorToHostRule(e);let s=this.shadowRoot.getElementById("theme-styles");s||(s=document.createElement("style"),s.id="theme-styles",this.shadowRoot.insertBefore(s,this.shadowRoot.firstChild));const i=e=>Object.entries(e).map(([e,t])=>{return`--${s=e,s.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${t};`;var s}).join("\n "),n=i(this.themes.light||{});let o=n?`:host {\n ${n}\n }\n`:"";o+=`${t} {\n ${i({bgColor:"#2b2b2b",textColor:"#a9b7c6",caretColor:"#bbbbbb",gutterBg:"#313335",gutterBorder:"#3c3f41",gutterText:"#606366",jsonKey:"#9876aa",jsonString:"#6a8759",jsonNumber:"#6897bb",jsonBoolean:"#cc7832",jsonNull:"#cc7832",jsonPunct:"#a9b7c6",jsonError:"#ff6b68",controlColor:"#cc7832",controlBg:"#3c3f41",controlBorder:"#5a5a5a",geojsonKey:"#9876aa",geojsonType:"#6a8759",geojsonTypeInvalid:"#ff6b68",jsonKeyInvalid:"#ff6b68",...this.themes.dark})}\n }`,s.textContent=o}_parseSelectorToHostRule(e){return e?e.startsWith(".")&&!e.includes(" ")?`:host(${e})`:`:host-context(${e})`:':host([data-color-scheme="dark"])'}setTheme(e){e.dark&&(this.themes.dark={...this.themes.dark,...e.dark}),e.light&&(this.themes.light={...this.themes.light,...e.light}),this.updateThemeCSS()}resetTheme(){this.themes={dark:{},light:{}},this.updateThemeCSS()}_getFeatureKey(e){if(!e)return null;if(void 0!==e.id)return`id:${e.id}`;if(void 0!==e.properties?.id)return`prop:${e.properties.id}`;const t=e.geometry?.type||"null",s=JSON.stringify(e.geometry?.coordinates||[]);let i=0;for(let n=0;n<s.length;n++)i=(i<<5)-i+s.charCodeAt(n),i&=i;return`hash:${t}:${i.toString(36)}`}_countBrackets(e,t){const s="{"===t?"}":"]";let i=0,n=0,o=!1,r=!1;for(const l of e)r?r=!1:"\\"===l&&o?r=!0:'"'!==l?o||(l===t&&i++,l===s&&n++):o=!o;return{open:i,close:n}}_findCollapsibleRanges(){const e=[];for(const[t,s]of this._lineToNodeId){const i=this._nodeIdToLines.get(s);if(!i)continue;const n=this.lines[t];if(!n)continue;const o=n.match(/^\s*"([^"]+)"\s*:\s*([{\[])/),r=!o&&n.match(/^\s*([{\[]),?\s*$/);if(!o&&!r)continue;const l=o?o[2]:r[1];e.push({startLine:i.startLine,endLine:i.endLine,nodeKey:i.nodeKey||(o?o[1]:`__root_${t}`),nodeId:s,openBracket:l,isRootFeature:!!r})}return e.sort((e,t)=>e.startLine-t.startLine),e}_findClosingLine(e,t){let s=1;const i=this.lines[e],n=i.indexOf(t);if(-1!==n){const o=i.substring(n+1),r=this._countBrackets(o,t);if(s+=r.open-r.close,0===s)return e}for(let o=e+1;o<this.lines.length;o++){const e=this._countBrackets(this.lines[o],t);if(s+=e.open-e.close,0===s)return o}return-1}_buildContextMap(){const e=this.lines.length;if(this._contextMapCache&&this._contextMapLinesLength===e&&this._contextMapFirstLine===this.lines[0]&&this._contextMapLastLine===this.lines[e-1])return this._contextMapCache;const t=/* @__PURE__ */new Map,o=[];let r=null;for(let l=0;l<e;l++){const e=this.lines[l],a=o[o.length-1]?.context||"Feature";t.set(l,a),s.test(e)?r="geometry":i.test(e)?r="properties":n.test(e)&&(r="Feature");const h=(e.match(/\{/g)||[]).length,c=(e.match(/\}/g)||[]).length,d=(e.match(/\[/g)||[]).length,u=(e.match(/\]/g)||[]).length;for(let t=0;t<h+d;t++)o.push({context:r||a,isArray:t>=h}),r=null;for(let t=0;t<c+u&&o.length>0;t++)o.pop()}return this._contextMapCache=t,this._contextMapLinesLength=e,this._contextMapFirstLine=this.lines[0],this._contextMapLastLine=this.lines[e-1],t}_highlightSyntax(s,i,n){if(!s)return"";let x=s,w=null;if(n?.collapseButton?.isCollapsed){const e=s.match(o),t=!e&&s.match(r);e?(x=e[1]+e[2],w=e[2]):t&&(x=t[1]+t[2],w=t[2])}let k=x.replace(l,"&").replace(a,"<").replace(h,">");if(k=k.replace(c,'<span class="json-punctuation">$1</span>'),d.lastIndex=0,k=k.replace(d,(t,s,n)=>"properties"!==i&&e.includes(s)?`<span class="geojson-key">"${s}"</span>${n}`:`<span class="json-key">"${s}"</span>${n}`),"properties"!==i&&(u.lastIndex=0,k=k.replace(u,(e,s,i)=>`<span class="geojson-key">"type"</span><span class="json-punctuation">:</span>${s}<span class="${"Feature"===i||"FeatureCollection"===i||t.includes(i)?"geojson-type":"geojson-type-invalid"}">"${i}"</span>`)),p.lastIndex=0,k=k.replace(p,(e,t,s,i)=>e.includes("geojson-type")||e.includes("json-string")?e:g.test(i)?`${t}${s}<span class="json-string json-color" data-color="${i}" style="--swatch-color: ${i}">"${i}"</span>`:`${t}${s}<span class="json-string">"${i}"</span>`),f.lastIndex=0,k=k.replace(f,'$1$2<span class="json-number">$3</span>'),m.lastIndex=0,k=k.replace(m,'$1$2<span class="json-number">$3</span>'),C.lastIndex=0,k=k.replace(C,'$1<span class="json-number">$2</span>'),y.lastIndex=0,k=k.replace(y,(e,t,s,i)=>`${t}${s}<span class="json-boolean${"true"===i?" json-bool-true":" json-bool-false"}">${i}</span>`),v.lastIndex=0,k=k.replace(v,'$1$2<span class="json-null">$3</span>'),w){const e="["===w?"collapsed-bracket-array":"collapsed-bracket-object";k=k.replace(new RegExp(`<span class="json-punctuation">\\${w}<\\/span>$`),`<span class="${e}">${w}</span>`)}return L.lastIndex=0,k=k.replace(L,(e,t,s,i)=>{if(!s||b.test(s))return e;const n=s.split(_);let o=!1;const r=n.map(e=>b.test(e)?e:(o=!0,`<span class="json-error">${e}</span>`)).join("");return o?t+r+i:e}),k}_validateGeoJSON(e){const s=[];return e.features?(e.features.forEach((e,i)=>{"Feature"!==e.type&&s.push(`features[${i}]: type must be "Feature"`),e.geometry&&e.geometry.type&&(t.includes(e.geometry.type)||s.push(`features[${i}].geometry: invalid type "${e.geometry.type}"`))}),s):s}_validateFeature(e){if(!e||"object"!=typeof e)throw new Error("Feature must be an object");if("Feature"!==e.type)throw new Error('Feature type must be "Feature"');if(!("geometry"in e))throw new Error("Feature must have a geometry property");if(!("properties"in e))throw new Error("Feature must have a properties property");if(null!==e.geometry){if(!e.geometry||"object"!=typeof e.geometry)throw new Error("Feature geometry must be an object or null");if(!e.geometry.type)throw new Error("Feature geometry must have a type");if(!t.includes(e.geometry.type))throw new Error(`Invalid geometry type: "${e.geometry.type}"`);if(!("coordinates"in e.geometry))throw new Error("Feature geometry must have coordinates")}if(null!==e.properties&&"object"!=typeof e.properties)throw new Error("Feature properties must be an object or null")}_normalizeToFeatures(e){let t=[];if(Array.isArray(e))t=e;else{if(!e||"object"!=typeof e)throw new Error("Input must be a Feature, array of Features, or FeatureCollection");if("FeatureCollection"===e.type&&Array.isArray(e.features))t=e.features;else{if("Feature"!==e.type)throw new Error("Input must be a Feature, array of Features, or FeatureCollection");t=[e]}}for(const s of t)this._validateFeature(s);return t}set(e,t={}){const s=this._normalizeToFeatures(e),i=s.map(e=>JSON.stringify(e,null,2)).join(",\n");this.setValue(i,!1),this._applyCollapsedFromOptions(t,s)}add(e,t={}){const s=this._normalizeToFeatures(e),i=[...this._parseFeatures(),...s],n=i.map(e=>JSON.stringify(e,null,2)).join(",\n");this.setValue(n,!1),this._applyCollapsedFromOptions(t,i)}insertAt(e,t,s={}){const i=this._normalizeToFeatures(e),n=this._parseFeatures(),o=t<0?n.length+t:t;n.splice(Math.max(0,Math.min(o,n.length)),0,...i);const r=n.map(e=>JSON.stringify(e,null,2)).join(",\n");this.setValue(r,!1),this._applyCollapsedFromOptions(s,n)}removeAt(e){const t=this._parseFeatures(),s=e<0?t.length+e:e;if(s>=0&&s<t.length){const e=t.splice(s,1)[0];return this.set(t),e}}removeAll(){this.lines.length>0&&this._saveToHistory("removeAll");const e=this._parseFeatures();return this.lines=[],this.collapsedNodes.clear(),this.hiddenFeatures.clear(),this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange(),e}get(e){const t=this._parseFeatures();return t[e<0?t.length+e:e]}getAll(){return this._parseFeatures()}emit(){this.emitChange()}save(e="features.geojson"){try{const t={type:"FeatureCollection",features:this._parseFeatures()},s=JSON.stringify(t,null,2),i=new Blob([s],{type:"application/geo+json"}),n=URL.createObjectURL(i),o=document.createElement("a");return o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n),!0}catch(t){return!1}}open(e={}){return new Promise(t=>{const s=document.createElement("input");s.type="file",s.accept=".geojson,.json,application/geo+json,application/json",s.style.display="none",s.addEventListener("change",i=>{const n=i.target.files?.[0];if(!n)return document.body.removeChild(s),void t(!1);const o=new FileReader;o.onload=i=>{try{const n=i.target?.result,o=JSON.parse(n),r=this._normalizeToFeatures(o);this._saveToHistory("open"),this.set(r,e),this.clearHistory(),document.body.removeChild(s),t(!0)}catch(n){document.body.removeChild(s),t(!1)}},o.onerror=()=>{document.body.removeChild(s),t(!1)},o.readAsText(n)}),s.addEventListener("cancel",()=>{document.body.removeChild(s),t(!1)}),document.body.appendChild(s),s.click()})}_parseFeatures(){try{const e=this.lines.join("\n");return e.trim()?JSON.parse("["+e+"]"):[]}catch(e){return[]}}}customElements.get("geojson-editor")||customElements.define("geojson-editor",x);export{x as default};
|
|
9
|
+
const e=["type","geometry","properties","coordinates","id","features"],t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],s=/"geometry"\s*:/,i=/"properties"\s*:/,n=/"features"\s*:/,o=/^(\s*"[^"]+"\s*:\s*)([{\[])/,r=/^(\s*)([{\[]),?\s*$/,l=/&/g,a=/</g,h=/>/g,c=/([{}[\],:])/g,d=/"([^"]+)"(<span class="json-punctuation">:<\/span>)/g,u=/<span class="geojson-key">"type"<\/span><span class="json-punctuation">:<\/span>(\s*)"([^"]*)"/g,p=/(<span class="json-punctuation">:<\/span>)(\s*)"([^"]*)"/g,g=/(<span class="json-punctuation">:<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi,f=/(<span class="json-punctuation">[\[,]<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi,m=/^(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gim,C=/(<span class="json-punctuation">:<\/span>)(\s*)(true|false)/g,b=/(<span class="json-punctuation">:<\/span>)(\s*)(null)/g,_=/(<\/span>|^)([^<]+)(<span|$)/g,v=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,y=/^#?([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/,L=/^\s*$/,x=/(\s+)/,w=/"([\w-]+)"\s*:\s*(?:"([^"]*)"|(\btrue\b|\bfalse\b))/g,k=/"([\w-]+)"\s*:\s*(?:"([^"]*)"|(\btrue\b|\bfalse\b))/,S=/"([\w-]+)"\s*:\s*(true|false)/,T=/"type"\s*:\s*"Feature"/,j=/^\s*"([^"]+)"\s*:\s*([{\[])/,R=/^\s*([{\[]),?\s*$/,I=/[{\[]/,E=/[\w-]/,F=/([A-Z])/g,$=/\{/g,A=/\}/g,N=/\[/g,M=/\]/g;function B(e){if(!e)return null;if(void 0!==e.id)return`id:${e.id}`;if(void 0!==e.properties?.id)return`prop:${e.properties.id}`;const t=e.geometry?.type||"null",s=e.geometry,i=JSON.stringify(s?.coordinates||[]);let n=0;for(let o=0;o<i.length;o++)n=(n<<5)-n+i.charCodeAt(o),n&=n;return`hash:${t}:${n.toString(36)}`}function H(e,t){const s="{"===t?"}":"]";let i=0,n=0,o=!1,r=!1;for(const l of e)r?r=!1:"\\"===l&&o?r=!0:'"'!==l?o||(l===t&&i++,l===s&&n++):o=!o;return{open:i,close:n}}function P(e){if(!e||"object"!=typeof e)throw new Error("Feature must be an object");if("Feature"!==e.type)throw new Error('Feature type must be "Feature"');if(!("geometry"in e))throw new Error("Feature must have a geometry property");if(!("properties"in e))throw new Error("Feature must have a properties property");if(null!==e.geometry){if("object"!=typeof e.geometry)throw new Error("Feature geometry must be an object or null");if(!e.geometry.type)throw new Error("Feature geometry must have a type");if(!t.includes(e.geometry.type))throw new Error(`Invalid geometry type: "${e.geometry.type}"`);if(!("coordinates"in e.geometry))throw new Error("Feature geometry must have coordinates")}if(null!==e.properties&&"object"!=typeof e.properties)throw new Error("Feature properties must be an object or null")}function K(e){let t=[];if(Array.isArray(e))t=e;else{if(!e||"object"!=typeof e)throw new Error("Input must be a Feature, array of Features, or FeatureCollection");if("FeatureCollection"===e.type&&"features"in e&&Array.isArray(e.features))t=e.features;else{if("Feature"!==e.type)throw new Error("Input must be a Feature, array of Features, or FeatureCollection");t=[e]}}for(const s of t)P(s);return t}let D=null;function O(e){return",aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow,yellowgreen,".includes(","+e.toLowerCase()+",")}function V(s,i,n){if(!s)return"";let y=s,w=null;if(n?.collapseButton?.isCollapsed){const e=s.match(o),t=!e&&s.match(r);e?(y=e[1]+e[2],w=e[2]):t&&(y=t[1]+t[2],w=t[2])}let k=y.replace(l,"&").replace(a,"<").replace(h,">");if(k=k.replace(c,'<span class="json-punctuation">$1</span>'),d.lastIndex=0,k=k.replace(d,(t,s,n)=>"properties"!==i&&e.includes(s)?`<span class="geojson-key">"${s}"</span>${n}`:`<span class="json-key">"${s}"</span>${n}`),"properties"!==i&&(u.lastIndex=0,k=k.replace(u,(e,s,i)=>`<span class="geojson-key">"type"</span><span class="json-punctuation">:</span>${s}<span class="${"Feature"===i||"FeatureCollection"===i||t.includes(i)?"geojson-type":"geojson-type-invalid"}">"${i}"</span>`)),p.lastIndex=0,k=k.replace(p,(e,t,s,i)=>e.includes("geojson-type")||e.includes("json-string")?e:v.test(i)||O(i)?`${t}${s}<span class="json-string json-color" data-color="${i}" style="--swatch-color: ${i}">"${i}"</span>`:`${t}${s}<span class="json-string">"${i}"</span>`),g.lastIndex=0,k=k.replace(g,'$1$2<span class="json-number">$3</span>'),f.lastIndex=0,k=k.replace(f,'$1$2<span class="json-number">$3</span>'),m.lastIndex=0,k=k.replace(m,'$1<span class="json-number">$2</span>'),C.lastIndex=0,k=k.replace(C,(e,t,s,i)=>`${t}${s}<span class="json-boolean${"true"===i?" json-bool-true":" json-bool-false"}">${i}</span>`),b.lastIndex=0,k=k.replace(b,'$1$2<span class="json-null">$3</span>'),w){const e="["===w?"collapsed-bracket-array":"collapsed-bracket-object";k=k.replace(new RegExp(`<span class="json-punctuation">\\${w}<\\/span>$`),`<span class="${e}">${w}</span>`)}return _.lastIndex=0,k=k.replace(_,(e,t,s,i)=>{if(!s||L.test(s))return e;const n=s.split(x);let o=!1;const r=n.map(e=>L.test(e)?e:(o=!0,`<span class="json-error">${e}</span>`)).join("");return o?t+r+i:e}),k}const z=e=>document.createElement(e);class U extends HTMLElement{constructor(){super(),this.lines=[],this.collapsedNodes=/* @__PURE__ */new Set,this.hiddenFeatures=/* @__PURE__ */new Set,this._nodeIdCounter=0,this._lineToNodeId=/* @__PURE__ */new Map,this._nodeIdToLines=/* @__PURE__ */new Map,this.visibleLines=[],this.lineMetadata=/* @__PURE__ */new Map,this.featureRanges=/* @__PURE__ */new Map,this.viewportHeight=0,this.lineHeight=19.5,this.bufferLines=5,this._lastStartIndex=-1,this._lastEndIndex=-1,this._lastTotalLines=-1,this._scrollRaf=null,this.cursorLine=0,this.cursorColumn=0,this.selectionStart=null,this.selectionEnd=null,this.renderTimer=void 0,this.inputTimer=void 0,this.themes={dark:{},light:{}},this._undoStack=[],this._redoStack=[],this._maxHistorySize=100,this._lastActionTime=0,this._lastActionType=null,this._groupingDelay=500,this._isSelecting=!1,this._isComposing=!1,this._blockRender=!1,this._insertMode=!0,this._charWidth=null,this._contextMapCache=null,this._contextMapLinesLength=0,this._contextMapFirstLine=void 0,this._contextMapLastLine=void 0,this._viewport=null,this._linesContainer=null,this._scrollContent=null,this._hiddenTextarea=null,this._gutterContent=null,this._gutterScrollContent=null,this._gutterScroll=null,this._gutter=null,this._clearBtn=null,this._editorWrapper=null,this._placeholderLayer=null,this._editorPrefix=null,this._editorSuffix=null,this.attachShadow({mode:"open"})}_id(e){return this.shadowRoot.getElementById(e)}_invalidateRenderCache(){this._lastStartIndex=-1,this._lastEndIndex=-1,this._lastTotalLines=-1}_createSnapshot(){return{lines:[...this.lines],cursorLine:this.cursorLine,cursorColumn:this.cursorColumn,timestamp:Date.now()}}_restoreSnapshot(e){this.lines=[...e.lines],this.cursorLine=e.cursorLine,this.cursorColumn=e.cursorColumn,this.updateModel(),this._invalidateRenderCache(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange()}_saveToHistory(e="edit"){const t=Date.now();if(!(e===this._lastActionType&&t-this._lastActionTime<this._groupingDelay)){const e=this._createSnapshot();this._undoStack.push(e),this._undoStack.length>this._maxHistorySize&&this._undoStack.shift(),this._redoStack=[]}this._lastActionTime=t,this._lastActionType=e}undo(){if(0===this._undoStack.length)return!1;this._redoStack.push(this._createSnapshot());const e=this._undoStack.pop();return e&&this._restoreSnapshot(e),this._lastActionType=null,this._lastActionTime=0,!0}redo(){if(0===this._redoStack.length)return!1;this._undoStack.push(this._createSnapshot());const e=this._redoStack.pop();return e&&this._restoreSnapshot(e),this._lastActionType=null,this._lastActionTime=0,!0}clearHistory(){this._undoStack=[],this._redoStack=[],this._lastActionType=null,this._lastActionTime=0}canUndo(){return this._undoStack.length>0}canRedo(){return this._redoStack.length>0}_generateNodeId(){return"node_"+ ++this._nodeIdCounter}_getCollapsedRangeForLine(e){for(const[t,s]of this._nodeIdToLines)if(this.collapsedNodes.has(t)&&e>s.startLine&&e<s.endLine)return{nodeId:t,...s};return null}_getCollapsedClosingLine(e){for(const[t,s]of this._nodeIdToLines)if(this.collapsedNodes.has(t)&&e===s.endLine)return{nodeId:t,...s};return null}_getClosingBracketPos(e){return Math.max(e.lastIndexOf("]"),e.lastIndexOf("}"))}_getCollapsedNodeAtLine(e){const t=this._lineToNodeId.get(e);if(t&&this.collapsedNodes.has(t)){const e=this._nodeIdToLines.get(t);if(e)return{nodeId:t,...e}}return null}_getContainingExpandedNode(e){let t=null;for(const[s,i]of this._nodeIdToLines)this.collapsedNodes.has(s)||e>=i.startLine&&e<=i.endLine&&(!t||i.endLine-i.startLine<t.endLine-t.startLine)&&(t={nodeId:s,...i});return t}_deleteCollapsedNode(e){this._saveToHistory("delete");const t=e.endLine-e.startLine+1;this.lines.splice(e.startLine,t),this.cursorLine=Math.min(e.startLine,this.lines.length-1),this.cursorColumn=0,this.formatAndUpdate()}_rebuildNodeIdMappings(){const e=new Set(this.collapsedNodes),t=/* @__PURE__ */new Map;for(const[n,o]of this._nodeIdToLines)o.nodeKey&&t.set(n,o.nodeKey);const s=[];for(const n of e){const e=t.get(n);e&&s.push(e)}this._nodeIdCounter=0,this._lineToNodeId.clear(),this._nodeIdToLines.clear(),this.collapsedNodes.clear();const i=/* @__PURE__ */new Map;for(let n=0;n<this.lines.length;n++){const e=this.lines[n],t=e.match(j),o=!t&&e.match(R);if(!t&&!o)continue;let r,l;if(t)r=t[1],l=t[2];else{if(!o)continue;l=o[1],r=`__root_${l}_${n}`}const a=H(e.substring(e.indexOf(l)+1),l);if(a.close>a.open)continue;const h=this._findClosingLine(n,l);if(-1===h||h===n)continue;const c=this._generateNodeId();this._lineToNodeId.set(n,c),this._nodeIdToLines.set(c,{startLine:n,endLine:h,nodeKey:r,isRootFeature:!!o});const d=i.get(r)||0;i.set(r,d+1);const u=s.indexOf(r);-1!==u&&(s.splice(u,1),this.collapsedNodes.add(c))}}static get observedAttributes(){return["readonly","value","placeholder","dark-selector"]}connectedCallback(){this.render(),this._cacheElements(),this.setupEventListeners(),this.updatePrefixSuffix(),this.updateThemeCSS(),this.value&&this.setValue(this.value),this.updatePlaceholderVisibility()}disconnectedCallback(){this.renderTimer&&clearTimeout(this.renderTimer),this.inputTimer&&clearTimeout(this.inputTimer);const e=document.querySelector(".geojson-color-picker-input");e&&(e._closeListener&&document.removeEventListener("click",e._closeListener,!0),e.remove())}attributeChangedCallback(e,t,s){if(t!==s)switch(e){case"value":this.setValue(s);break;case"readonly":this.updateReadonly();break;case"placeholder":this.updatePlaceholderContent();break;case"dark-selector":this.updateThemeCSS()}}get readonly(){return this.hasAttribute("readonly")}get value(){return this.getAttribute("value")||""}get placeholder(){return this.getAttribute("placeholder")||""}get prefix(){return'{"type": "FeatureCollection", "features": ['}get suffix(){return"]}"}render(){const e=this.shadowRoot,t=z("style");t.textContent=':host *,:host *:before,:host *:after{box-sizing:border-box;font: 13px/1.5 Courier New,Courier,monospace;font-variant:normal;letter-spacing:0;word-spacing:0;text-transform:none;text-decoration:none;text-indent:0}:host{--line-height: 19.5px;--gutter-width: 50px;--editor-padding-y: 8px;--editor-padding-x: 12px;display:flex;flex-direction:column;position:relative;width:100%;height:400px;border-radius:4px;overflow:hidden}:host([readonly]) .editor-wrapper:after{content:"";position:absolute;inset:0;pointer-events:none;background:repeating-linear-gradient(-45deg,rgba(128,128,128,.08),rgba(128,128,128,.08) 3px,transparent 3px,transparent 12px);z-index:1}:host([readonly]) .hidden-textarea{cursor:text}.editor-wrapper{position:relative;width:100%;flex:1;background:var(--bg-color, #fff);display:flex;overflow:hidden}.gutter{width:var(--gutter-width);background:var(--gutter-bg, #f0f0f0);border-right:1px solid var(--gutter-border, #e0e0e0);overflow:hidden;flex-shrink:0;position:relative}.gutter-scroll{position:absolute;inset:0;overflow:hidden;padding:8px 0}.gutter-scroll-content{position:relative;width:100%}.gutter-content{position:absolute;top:0;left:0;right:0;will-change:transform}.gutter-line{height:var(--line-height);display:flex;align-items:center;justify-content:flex-end;padding-right:4px}.line-number{font-size:11px;color:var(--gutter-text, #999);-webkit-user-select:none;user-select:none;min-width:20px;text-align:right}.collapse-column{width:16px;display:flex;align-items:center;justify-content:center;flex-shrink:0}.collapse-button{width:12px;height:12px;border-radius:2px;cursor:pointer;flex-shrink:0;background:transparent;border:none;color:var(--json-punct, #a9b7c6);font-size:10px;display:flex;align-items:center;justify-content:center;-webkit-user-select:none;user-select:none;opacity:0;transition:transform .1s,opacity .15s}.collapse-button.collapsed,.gutter:hover .collapse-button{opacity:1}.collapse-button:hover{transform:scale(1.2)}@media(hover:none),(pointer:coarse){.collapse-button{opacity:1}}.editor-content{position:relative;flex:1;overflow:hidden}.hidden-textarea{position:absolute;top:0;left:0;width:100%;height:100%;opacity:0;padding:0;margin:0;border:none;outline:none;resize:none;overflow:hidden;z-index:-1;pointer-events:none;caret-color:transparent}.viewport{position:absolute;inset:0;overflow:auto;padding:var(--editor-padding-y) var(--editor-padding-x);overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:var(--control-border, #c0c0c0) var(--control-bg, #e8e8e8)}.scroll-content{position:relative;width:100%}.lines-container{position:absolute;top:0;left:0;right:0;will-change:transform}.line{height:var(--line-height);white-space:pre;display:block;position:relative}.cursor{position:absolute;width:2px;height:1em;background:var(--caret-color, #000);top:.15em;pointer-events:none;animation:cursor-blink 1s step-end infinite}.cursor.cursor-block{width:.6em;opacity:.5;animation:cursor-blink-block 1s step-end infinite}@keyframes cursor-blink-block{0%,to{opacity:.5}50%{opacity:.2}}@keyframes cursor-blink{0%,to{opacity:1}50%{opacity:0}}.selection{position:absolute;height:100%;top:0;background:var(--selection-color, rgba(51, 153, 255, .3));pointer-events:none;z-index:0}.line-hidden>span{opacity:.35;filter:grayscale(50%)}.placeholder-layer{position:absolute;top:var(--editor-padding-y);left:var(--editor-padding-x);color:#6a6a6a;pointer-events:none;z-index:0;white-space:pre}.json-key{color:var(--json-key, #660e7a)}.json-string{color:var(--json-string, #008000)}.json-number{color:var(--json-number, #00f)}.json-boolean,.json-null{color:var(--json-boolean, #000080)}.json-punctuation{color:var(--json-punct, #000)}.json-key-invalid{color:var(--json-key-invalid, #f00)}.json-error{color:var(--json-error, #f00)}.geojson-key{color:var(--geojson-key, #660e7a);font-weight:600}.geojson-type{color:var(--geojson-type, #008000);font-weight:600}.geojson-type-invalid{color:var(--geojson-type-invalid, #f00);font-weight:600}.collapsed-bracket-array,.collapsed-bracket-object{color:var(--json-punct, #000)}.collapsed-bracket-array:after,.collapsed-bracket-object:after{content:"…";color:var(--json-punct, #888)}.prefix-wrapper,.suffix-wrapper{display:flex;flex-shrink:0;background:var(--bg-color, #fff)}.prefix-gutter,.suffix-gutter{width:var(--gutter-width);background:var(--gutter-bg, #f0f0f0);border-right:1px solid var(--gutter-border, #e0e0e0);flex-shrink:0}.editor-prefix,.editor-suffix{flex:1;padding:4px 12px;color:var(--text-color, #000);background:var(--bg-color, #fff);-webkit-user-select:none;user-select:none;white-space:pre-wrap;word-wrap:break-word;opacity:.6}.prefix-wrapper{border-bottom:1px solid rgba(255,255,255,.1);position:relative}.suffix-wrapper{border-top:1px solid rgba(255,255,255,.1);position:relative}.info-btn{position:absolute;right:.5rem;top:50%;transform:translateY(-50%);background:transparent;border:none;color:var(--text-color, #000);opacity:.15;cursor:pointer;font-size:.7rem;width:1rem;height:1rem;padding:0;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:opacity .2s;font-family:sans-serif}.info-btn:hover{opacity:.5}.clear-btn{position:absolute;right:.5rem;top:50%;transform:translateY(-50%);background:transparent;border:none;color:var(--text-color, #000);opacity:.3;cursor:pointer;font-size:.65rem;width:1rem;height:1rem;padding:.15rem 0 0;border-radius:3px;display:flex;align-items:center;justify-content:center;transition:opacity .2s,background .2s}.clear-btn:hover{opacity:.7;background:#ffffff1a}.clear-btn[hidden]{display:none}.viewport::-webkit-scrollbar{width:10px;height:10px}.viewport::-webkit-scrollbar-track{background:var(--control-bg, #e8e8e8)}.viewport::-webkit-scrollbar-thumb{background:var(--control-border, #c0c0c0);border-radius:5px}.viewport::-webkit-scrollbar-thumb:hover{background:var(--control-color, #000080)}.json-color,.json-boolean{position:relative}.json-color:before,.json-boolean:before{content:"";position:absolute;left:-8px;top:50%;transform:translateY(-50%);margin-top:-1px;width:8px;height:8px;border-radius:2px;cursor:pointer}.json-color:hover:before,.json-boolean:hover:before{transform:translateY(-50%) scale(1.2);border-color:var(--control-color, #000080)}.json-color:before{background-color:var(--swatch-color);border:1px solid var(--json-punct, #a9b7c6)}.json-boolean:before{border:1.5px solid var(--control-border, #c0c0c0);background:transparent}.json-bool-true:before{content:"✔";border-color:var(--control-color, #000080);color:var(--control-color, #000080);font-size:8px;display:flex;align-items:center;justify-content:center;line-height:8px}.line.has-visibility:before{content:"👁";position:absolute;left:0;top:3px;font-size:10px;color:var(--control-color, #000080);opacity:.6;cursor:pointer;z-index:1}.line.has-visibility:hover:before{opacity:1;transform:scale(1.15)}.line.has-visibility.feature-hidden:before{opacity:.5}';const s=z("div");for(s.innerHTML=function(e="",t=""){return`\n <div class="prefix-wrapper">\n <div class="prefix-gutter"></div>\n <div class="editor-prefix" id="editorPrefix"></div>\n <button class="info-btn" id="infoBtn" title="@softwarity/geojson-editor v${t}" aria-label="About">ⓘ</button>\n </div>\n <div class="editor-wrapper">\n <div class="gutter">\n <div class="gutter-scroll" id="gutterScroll">\n <div class="gutter-scroll-content" id="gutterScrollContent">\n <div class="gutter-content" id="gutterContent"></div>\n </div>\n </div>\n </div>\n <div class="editor-content">\n <div class="placeholder-layer" id="placeholderLayer">${s=e,s?s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):""}</div>\n <textarea\n class="hidden-textarea"\n id="hiddenTextarea"\n spellcheck="false"\n autocomplete="off"\n autocorrect="off"\n autocapitalize="off"\n tabindex="0"\n ></textarea>\n <div class="viewport" id="viewport">\n <div class="scroll-content" id="scrollContent">\n <div class="lines-container" id="linesContainer"></div>\n </div>\n </div>\n </div>\n </div>\n <div class="suffix-wrapper">\n <div class="suffix-gutter"></div>\n <div class="editor-suffix" id="editorSuffix"></div>\n <button class="clear-btn" id="clearBtn" title="Clear editor">✕</button>\n </div>\n `;var s}(this.placeholder,"1.0.18"),e.innerHTML="",e.appendChild(t);s.firstChild;)e.appendChild(s.firstChild)}_cacheElements(){this._viewport=this._id("viewport"),this._linesContainer=this._id("linesContainer"),this._scrollContent=this._id("scrollContent"),this._hiddenTextarea=this._id("hiddenTextarea"),this._gutterContent=this._id("gutterContent"),this._gutterScrollContent=this._id("gutterScrollContent"),this._gutterScroll=this._id("gutterScroll"),this._gutter=this.shadowRoot.querySelector(".gutter"),this._clearBtn=this._id("clearBtn"),this._editorWrapper=this.shadowRoot.querySelector(".editor-wrapper"),this._placeholderLayer=this._id("placeholderLayer"),this._editorPrefix=this._id("editorPrefix"),this._editorSuffix=this._id("editorSuffix")}setupEventListeners(){const e=this._hiddenTextarea,t=this._viewport,s=this._gutterContent,i=this._gutter,n=this._clearBtn,o=this._editorWrapper;if(!(e&&t&&s&&i&&n&&o))return;this._isSelecting=!1,t.addEventListener("click",e=>{this.handleEditorClick(e)},!0),t.addEventListener("mousedown",t=>{const s=t.target,i=s.closest(".line.has-visibility");if(i){const e=i.getBoundingClientRect();if(t.clientX-e.left<14)return void(this._blockRender=!0)}if(s.classList.contains("json-color")||s.classList.contains("json-boolean")){const e=s.getBoundingClientRect(),i=t.clientX-e.left;if(i<0&&i>=-8)return void(this._blockRender=!0)}t.preventDefault();const n=this._getPositionFromClick(t);t.shiftKey&&this.selectionStart?(this.selectionEnd=n,this.cursorLine=n.line,this.cursorColumn=n.column):(this.cursorLine=n.line,this.cursorColumn=n.column,this.selectionStart={line:n.line,column:n.column},this.selectionEnd=null,this._isSelecting=!0),e.focus(),this._invalidateRenderCache(),this.scheduleRender()}),t.addEventListener("mousemove",e=>{if(!this._isSelecting)return;const s=this._getPositionFromClick(e);this.selectionEnd=s,this.cursorLine=s.line,this.cursorColumn=s.column;const i=t.getBoundingClientRect();e.clientY<i.top+30?t.scrollTop-=20:e.clientY>i.bottom-30&&(t.scrollTop+=20),this._invalidateRenderCache(),this.scheduleRender()}),document.addEventListener("mouseup",()=>{this._isSelecting=!1}),e.addEventListener("focus",()=>{o.classList.add("focused"),this._invalidateRenderCache(),this.scheduleRender()}),e.addEventListener("blur",()=>{o.classList.remove("focused"),this._invalidateRenderCache(),this.scheduleRender()});let r=!1;t.addEventListener("scroll",()=>{r||(this.syncGutterScroll(),this._scrollRaf||(this._scrollRaf=requestAnimationFrame(()=>{this._scrollRaf=null,r=!0,this.renderViewport(),r=!1})))}),e.addEventListener("compositionstart",()=>{this._isComposing=!0}),e.addEventListener("compositionend",()=>{this._isComposing=!1,this.handleInput()}),e.addEventListener("input",()=>{this._isComposing||this.handleInput()}),e.addEventListener("keydown",e=>{this.handleKeydown(e)}),e.addEventListener("paste",e=>{this.handlePaste(e)}),e.addEventListener("copy",e=>{this.handleCopy(e)}),e.addEventListener("cut",e=>{this.handleCut(e)}),s.addEventListener("click",e=>{this.handleGutterClick(e)}),i.addEventListener("mousedown",e=>{e.preventDefault()}),i.addEventListener("wheel",e=>{e.preventDefault(),t.scrollTop+=e.deltaY}),n.addEventListener("click",()=>{this.removeAll()}),this.updateReadonly()}setValue(e,t=!0){if(this.lines.length>0&&this._saveToHistory("setValue"),e&&e.trim())try{const t="["+e+"]",s=JSON.parse(t),i=JSON.stringify(s,null,2).split("\n");this.lines=i.slice(1,-1)}catch(s){this.lines=e.split("\n")}else this.lines=[];this.collapsedNodes.clear(),this.hiddenFeatures.clear(),this._lineToNodeId.clear(),this._nodeIdToLines.clear(),this.cursorLine=0,this.cursorColumn=0,this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),t&&this.lines.length>0&&requestAnimationFrame(()=>{this.autoCollapseCoordinates()}),this.emitChange()}getContent(){return this.lines.join("\n")}updateModel(){this._contextMapCache=null,this._rebuildNodeIdMappings(),this.computeFeatureRanges(),this.computeLineMetadata(),this.computeVisibleLines()}updateView(){this.computeLineMetadata(),this.computeVisibleLines()}computeFeatureRanges(){this.featureRanges.clear();try{const e=this.lines.join("\n"),t=this.prefix+e+this.suffix,s=JSON.parse(t);if(!s.features)return;let i=0,n=0,o=!1,r=-1,l=null;for(let a=0;a<this.lines.length;a++){const e=this.lines[a];if(!o&&T.test(e)){let e=a;for(let t=a;t>=0;t--){const s=this.lines[t].trim();if("{"===s||"{,"===s){e=t;break}}r=e,o=!0,n=1;for(let t=e;t<=a;t++){const s=H(this.lines[t],"{");n+=t===e?s.open-1-s.close:s.open-s.close}i<s.features.length&&(l=B(s.features[i]))}else if(o){const t=H(e,"{");n+=t.open-t.close,n<=0&&(l&&this.featureRanges.set(l,{startLine:r,endLine:a,featureIndex:i}),i++,o=!1,l=null)}}}catch(e){}}computeLineMetadata(){this.lineMetadata.clear();const e=this._findCollapsibleRanges();for(let t=0;t<this.lines.length;t++){const s=this.lines[t],i={colors:[],booleans:[],collapseButton:null,visibilityButton:null,isHidden:!1,isCollapsed:!1,featureKey:null};let n;for(w.lastIndex=0;null!==(n=w.exec(s));){const[,e,t,s]=n;s?i.booleans.push({attributeName:e,value:"true"===s}):t&&(v.test(t)||O(t))&&i.colors.push({attributeName:e,color:t})}const o=e.find(e=>e.startLine===t);o&&(i.collapseButton={nodeKey:o.nodeKey,nodeId:o.nodeId,isCollapsed:this.collapsedNodes.has(o.nodeId)}),e.find(e=>this.collapsedNodes.has(e.nodeId)&&t>e.startLine&&t<e.endLine)&&(i.isCollapsed=!0);for(const[e,r]of this.featureRanges)if(t>=r.startLine&&t<=r.endLine){i.featureKey=e,this.hiddenFeatures.has(e)&&(i.isHidden=!0),t===r.startLine&&(i.visibilityButton={featureKey:e,isHidden:this.hiddenFeatures.has(e)});break}this.lineMetadata.set(t,i)}}computeVisibleLines(){this.visibleLines=[];for(let e=0;e<this.lines.length;e++){const t=this.lineMetadata.get(e);t&&t.isCollapsed||this.visibleLines.push({index:e,content:this.lines[e],meta:t})}this._invalidateRenderCache()}scheduleRender(){this.renderTimer||(this.renderTimer=requestAnimationFrame(()=>{this.renderTimer=void 0,this.renderViewport()}))}renderViewport(){if(this._blockRender)return;const e=this._viewport,t=this._linesContainer,s=this._scrollContent;if(!e||!t)return;this.viewportHeight=e.clientHeight;const i=this.visibleLines.length,n=i*this.lineHeight;s&&(s.style.height=`${n}px`);const o=e.scrollTop,r=Math.floor(o/this.lineHeight),l=Math.ceil(this.viewportHeight/this.lineHeight),a=Math.max(0,r-this.bufferLines),h=Math.min(i,r+l+this.bufferLines);if(i>0&&this._lastStartIndex===a&&this._lastEndIndex===h&&this._lastTotalLines===i)return;this._lastStartIndex=a,this._lastEndIndex=h,this._lastTotalLines=i;const c=a*this.lineHeight;t.style.transform=`translateY(${c}px)`;const d=this._buildContextMap(),u=this._editorWrapper?.classList.contains("focused"),p=document.createDocumentFragment();if(0===i){const e=z("div");return e.className="line empty-line",e.dataset.lineIndex="0",u&&(e.innerHTML=this._insertCursor(0)),p.appendChild(e),t.innerHTML="",t.appendChild(p),void this.renderGutter(0,0)}for(let g=a;g<h;g++){const e=this.visibleLines[g];if(!e)continue;const t=z("div");t.className="line",t.dataset.lineIndex=String(e.index),e.meta?.visibilityButton&&(t.classList.add("has-visibility"),t.dataset.featureKey=e.meta.visibilityButton.featureKey,e.meta.visibilityButton.isHidden&&t.classList.add("feature-hidden")),e.meta?.isHidden&&t.classList.add("line-hidden");const s=d.get(e.index)||"Feature";let i=V(e.content,s,e.meta);u&&this._hasSelection()&&(i=this._addSelectionHighlight(i,e.index,e.content)),u&&e.index===this.cursorLine&&(i+=this._insertCursor(this.cursorColumn)),t.innerHTML=i,p.appendChild(t)}t.innerHTML="",t.appendChild(p),this.renderGutter(a,h)}_insertCursor(e){const t=this._getCharWidth(),s=e*t;return this._insertMode?`<span class="cursor" style="left: ${s}px"></span>`:`<span class="cursor cursor-block" style="left: ${s}px; width: ${t}px"></span>`}_addSelectionHighlight(e,t,s){const i=this._normalizeSelection();if(!i)return e;const{start:n,end:o}=i;if(t<n.line||t>o.line)return e;const r=this._getCharWidth();let l,a;return t===n.line&&t===o.line?(l=n.column,a=o.column):t===n.line?(l=n.column,a=s.length):t===o.line?(l=0,a=o.column):(l=0,a=s.length),`<span class="selection" style="left: ${l*r}px; width: ${(a-l)*r}px"></span>`+e}_getCharWidth(){if(!this._charWidth){const e=z("canvas").getContext("2d");e?(e.font="13px 'Courier New', Courier, monospace",this._charWidth=e.measureText("M").width):this._charWidth=7.8}return this._charWidth}renderGutter(e,t){const s=this._gutterContent,i=this._gutterScrollContent;if(!s)return;const n=this.visibleLines.length*this.lineHeight;i&&(i.style.height=`${n}px`);const o=e*this.lineHeight;s.style.transform=`translateY(${o}px)`;const r=document.createDocumentFragment();for(let l=e;l<t;l++){const e=this.visibleLines[l];if(!e)continue;const t=z("div");t.className="gutter-line";const s=e.meta,i=z("span");i.className="line-number",i.textContent=String(e.index+1),t.appendChild(i);const n=z("div");if(n.className="collapse-column",s?.collapseButton){const t=z("div");t.className="collapse-button"+(s.collapseButton.isCollapsed?" collapsed":""),t.textContent=s.collapseButton.isCollapsed?"›":"⌄",t.dataset.line=String(e.index),t.dataset.nodeId=s.collapseButton.nodeId,t.title=s.collapseButton.isCollapsed?"Expand":"Collapse",n.appendChild(t)}t.appendChild(n),r.appendChild(t)}s.innerHTML="",s.appendChild(r)}syncGutterScroll(){this._gutterScroll&&this._viewport&&(this._gutterScroll.scrollTop=this._viewport.scrollTop)}handleInput(){const e=this._hiddenTextarea,t=e?.value;if(t)if(this._hasSelection()&&this._deleteSelection(),this._getCollapsedRangeForLine(this.cursorLine))e.value="";else{if(this._getCollapsedClosingLine(this.cursorLine)){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);if(this.cursorColumn<=s)return void(e.value="")}if(this._getCollapsedNodeAtLine(this.cursorLine)){const t=this.lines[this.cursorLine].search(I);if(this.cursorColumn>t)return void(e.value="")}if(this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine],s=e.substring(0,this.cursorColumn),i=t.split("\n");if(1===i.length){if(this._insertMode){const i=e.substring(this.cursorColumn);this.lines[this.cursorLine]=s+t+i}else{const i=e.substring(this.cursorColumn+t.length);this.lines[this.cursorLine]=s+t+i}this.cursorColumn+=t.length}else{const t=e.substring(this.cursorColumn);this.lines[this.cursorLine]=s+i[0];for(let e=1;e<i.length-1;e++)this.lines.splice(this.cursorLine+e,0,i[e]);const n=i[i.length-1]+t;this.lines.splice(this.cursorLine+i.length-1,0,n),this.cursorLine+=i.length-1,this.cursorColumn=i[i.length-1].length}}else{const e=t.split("\n");this.lines.push(...e),this.cursorLine=this.lines.length-1,this.cursorColumn=this.lines[this.cursorLine].length}e.value="",clearTimeout(this.inputTimer),this.inputTimer=setTimeout(()=>{this.formatAndUpdate()},150)}}handleKeydown(e){const t={inCollapsedZone:this._getCollapsedRangeForLine(this.cursorLine),onCollapsedNode:this._getCollapsedNodeAtLine(this.cursorLine),onClosingLine:this._getCollapsedClosingLine(this.cursorLine)},s={Enter:()=>this._handleEnter(e.shiftKey,t),Backspace:()=>this._handleBackspace(t),Delete:()=>this._handleDelete(t),ArrowUp:()=>this._handleArrowKey(-1,0,e.shiftKey,e.ctrlKey||e.metaKey),ArrowDown:()=>this._handleArrowKey(1,0,e.shiftKey,e.ctrlKey||e.metaKey),ArrowLeft:()=>this._handleArrowKey(0,-1,e.shiftKey,e.ctrlKey||e.metaKey),ArrowRight:()=>this._handleArrowKey(0,1,e.shiftKey,e.ctrlKey||e.metaKey),Home:()=>this._handleHomeEnd("home",e.shiftKey,t.onClosingLine),End:()=>this._handleHomeEnd("end",e.shiftKey,t.onClosingLine),Tab:()=>this._handleTab(e.shiftKey,t),Insert:()=>{this._insertMode=!this._insertMode,this.scheduleRender()}},i={a:()=>this._selectAll(),z:()=>e.shiftKey?this.redo():this.undo(),y:()=>this.redo(),s:()=>this.save(),o:()=>!this.hasAttribute("readonly")&&this.open()};if(s[e.key])return e.preventDefault(),void s[e.key]();(e.ctrlKey||e.metaKey)&&i[e.key]&&(e.preventDefault(),i[e.key]())}_handleEnter(e,t){if(e){const e=this._getContainingExpandedNode(this.cursorLine);if(e){const t=this.lines[e.startLine],s=t.search(I);this.toggleCollapse(e.nodeId),this.cursorLine=e.startLine,this.cursorColumn=s>=0?s+1:t.length,this._clearSelection(),this._scrollToCursor()}return}if(t.onCollapsedNode)this.toggleCollapse(t.onCollapsedNode.nodeId);else{if(t.onClosingLine){const e=this.lines[this.cursorLine],s=this._getClosingBracketPos(e);if(s>=0&&this.cursorColumn<=s)return void this.toggleCollapse(t.onClosingLine.nodeId)}t.inCollapsedZone||this.insertNewline()}}_handleBackspace(e){if(this._hasSelection())return this._deleteSelection(),void this.formatAndUpdate();if(e.onClosingLine){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);return s>=0&&this.cursorColumn>s+1?void this.deleteBackward():void this._deleteCollapsedNode(e.onClosingLine)}if(e.onCollapsedNode&&0===this.cursorColumn)this._deleteCollapsedNode(e.onCollapsedNode);else if(!e.inCollapsedZone){if(e.onCollapsedNode){const t=this.lines[this.cursorLine].search(I);if(this.cursorColumn>t+1)return void this._deleteCollapsedNode(e.onCollapsedNode)}this.deleteBackward()}}_handleDelete(e){if(this._hasSelection())return this._deleteSelection(),void this.formatAndUpdate();if(e.onClosingLine){const t=this.lines[this.cursorLine],s=this._getClosingBracketPos(t);return s>=0&&this.cursorColumn>s?void this.deleteForward():void this._deleteCollapsedNode(e.onClosingLine)}if(e.onCollapsedNode){const t=this.lines[this.cursorLine].search(I);if(this.cursorColumn>t)return void this._deleteCollapsedNode(e.onCollapsedNode)}e.inCollapsedZone||this.deleteForward()}_handleTab(e,t){e?this._navigateToPrevAttribute():this._navigateToNextAttribute()}_navigateToNextAttribute(){const e=this.visibleLines.length;let t=this.visibleLines.findIndex(e=>e.index===this.cursorLine);t<0&&(t=0);for(let s=t;s<e;s++){const e=this.visibleLines[s],i=this.lines[e.index],n=s===t?this.cursorColumn:0,o=this._findNextAttributeInLine(i,n);if(null!==o)return this.cursorLine=e.index,this.cursorColumn=o.start,this.selectionStart={line:e.index,column:o.start},this.selectionEnd={line:e.index,column:o.end},this._scrollToCursor(),this._invalidateRenderCache(),void this.scheduleRender()}for(let s=0;s<t;s++){const e=this.visibleLines[s],t=this.lines[e.index],i=this._findNextAttributeInLine(t,0);if(null!==i)return this.cursorLine=e.index,this.cursorColumn=i.start,this.selectionStart={line:e.index,column:i.start},this.selectionEnd={line:e.index,column:i.end},this._scrollToCursor(),this._invalidateRenderCache(),void this.scheduleRender()}}_navigateToPrevAttribute(){const e=this.visibleLines.length;let t=this.visibleLines.findIndex(e=>e.index===this.cursorLine);t<0&&(t=e-1);for(let s=t;s>=0;s--){const e=this.visibleLines[s],i=this.lines[e.index],n=s===t?this.cursorColumn:i.length,o=this._findPrevAttributeInLine(i,n);if(null!==o)return this.cursorLine=e.index,this.cursorColumn=o.start,this.selectionStart={line:e.index,column:o.start},this.selectionEnd={line:e.index,column:o.end},this._scrollToCursor(),this._invalidateRenderCache(),void this.scheduleRender()}for(let s=e-1;s>t;s--){const e=this.visibleLines[s],t=this.lines[e.index],i=this._findPrevAttributeInLine(t,t.length);if(null!==i)return this.cursorLine=e.index,this.cursorColumn=i.start,this.selectionStart={line:e.index,column:i.start},this.selectionEnd={line:e.index,column:i.end},this._scrollToCursor(),this._invalidateRenderCache(),void this.scheduleRender()}}_findNextAttributeInLine(e,t){const s=/"([^"]+)"(?:\s*:\s*(?:"([^"]*)"|(-?\d+\.?\d*(?:e[+-]?\d+)?)|true|false|null))?/gi;let i;for(;null!==(i=s.exec(e));){const s=i.index+1,n=s+i[1].length;if(s>t)return{start:s,end:n};if(void 0!==i[2]){const s=e.substring(i.index).match(/:\s*"([^"]*)"/);if(s){const e=i.index+(s.index||0)+s[0].indexOf('"')+1,n=e+i[2].length;if(e>t)return{start:e,end:n}}}else if(void 0!==i[3]){const s=e.substring(i.index).match(/:\s*(-?\d+\.?\d*(?:e[+-]?\d+)?)/i);if(s){const e=i.index+(s.index||0)+s[0].indexOf(s[1]),n=e+s[1].length;if(e>t)return{start:e,end:n}}}else{const s=e.substring(i.index).match(/:\s*(true|false|null)/);if(s){const e=i.index+(s.index||0)+s[0].indexOf(s[1]),n=e+s[1].length;if(e>t)return{start:e,end:n}}}}return null}_findPrevAttributeInLine(e,t){const s=[],i=/"([^"]+)"(?:\s*:\s*(?:"([^"]*)"|(-?\d+\.?\d*(?:e[+-]?\d+)?)|true|false|null))?/gi;let n;for(;null!==(n=i.exec(e));){const t=n.index+1,i=t+n[1].length;if(s.push({start:t,end:i}),void 0!==n[2]){const t=e.substring(n.index).match(/:\s*"([^"]*)"/);if(t){const e=n.index+(t.index||0)+t[0].indexOf('"')+1,i=e+n[2].length;s.push({start:e,end:i})}}else if(void 0!==n[3]){const t=e.substring(n.index).match(/:\s*(-?\d+\.?\d*(?:e[+-]?\d+)?)/i);if(t){const e=n.index+(t.index||0)+t[0].indexOf(t[1]),i=e+t[1].length;s.push({start:e,end:i})}}else{const t=e.substring(n.index).match(/:\s*(true|false|null)/);if(t){const e=n.index+(t.index||0)+t[0].indexOf(t[1]),i=e+t[1].length;s.push({start:e,end:i})}}}for(let o=s.length-1;o>=0;o--)if(s[o].end<t)return s[o];return null}insertNewline(){if(this._saveToHistory("newline"),this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine],t=e.substring(0,this.cursorColumn),s=e.substring(this.cursorColumn);this.lines[this.cursorLine]=t,this.lines.splice(this.cursorLine+1,0,s),this.cursorLine++,this.cursorColumn=0}else this.lines.push(""),this.cursorLine=this.lines.length-1,this.cursorColumn=0;this.formatAndUpdate()}deleteBackward(){if(this._saveToHistory("delete"),this.cursorColumn>0){const e=this.lines[this.cursorLine];this.lines[this.cursorLine]=e.substring(0,this.cursorColumn-1)+e.substring(this.cursorColumn),this.cursorColumn--}else if(this.cursorLine>0){const e=this.lines[this.cursorLine],t=this.lines[this.cursorLine-1];this.cursorColumn=t.length,this.lines[this.cursorLine-1]=t+e,this.lines.splice(this.cursorLine,1),this.cursorLine--}this.formatAndUpdate()}deleteForward(){if(this._saveToHistory("delete"),this.cursorLine<this.lines.length){const e=this.lines[this.cursorLine];this.cursorColumn<e.length?this.lines[this.cursorLine]=e.substring(0,this.cursorColumn)+e.substring(this.cursorColumn+1):this.cursorLine<this.lines.length-1&&(this.lines[this.cursorLine]=e+this.lines[this.cursorLine+1],this.lines.splice(this.cursorLine+1,1))}this.formatAndUpdate()}moveCursorSkipCollapsed(e){let t=this.cursorLine+e;for(;t>=0&&t<this.lines.length;){const s=this._getCollapsedRangeForLine(t);if(!s)break;t=e>0?s.endLine:s.startLine}this.cursorLine=Math.max(0,Math.min(this.lines.length-1,t));const s=this.lines[this.cursorLine]?.length||0;this.cursorColumn=Math.min(this.cursorColumn,s),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}moveCursorHorizontal(e){e>0?this._moveCursorRight():this._moveCursorLeft(),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_moveCursorRight(){const e=this.lines[this.cursorLine],t=this._getCollapsedNodeAtLine(this.cursorLine);if(this._getCollapsedClosingLine(this.cursorLine)){const t=this._getClosingBracketPos(e);this.cursorColumn<t?this.cursorColumn=t:this.cursorColumn>=e.length?this.cursorLine<this.lines.length-1&&(this.cursorLine++,this.cursorColumn=0):this.cursorColumn++}else if(t){const s=e.search(I);this.cursorColumn<s?this.cursorColumn++:this.cursorColumn===s?this.cursorColumn=s+1:(this.cursorLine=t.endLine,this.cursorColumn=this._getClosingBracketPos(this.lines[this.cursorLine]))}else if(this.cursorColumn>=e.length){if(this.cursorLine<this.lines.length-1){this.cursorLine++,this.cursorColumn=0;const e=this._getCollapsedRangeForLine(this.cursorLine);e&&(this.cursorLine=e.endLine,this.cursorColumn=0)}}else this.cursorColumn++}_moveCursorLeft(){const e=this.lines[this.cursorLine],t=this._getCollapsedNodeAtLine(this.cursorLine),s=this._getCollapsedClosingLine(this.cursorLine);if(s){const t=this._getClosingBracketPos(e);if(this.cursorColumn>t+1)this.cursorColumn--;else{this.cursorLine=s.startLine;const e=this.lines[this.cursorLine];this.cursorColumn=e.search(I)+1}}else if(t){const t=e.search(I);this.cursorColumn>t+1?this.cursorColumn=t+1:this.cursorColumn===t+1?this.cursorColumn=t:this.cursorColumn>0?this.cursorColumn--:this.cursorLine>0&&(this.cursorLine--,this.cursorColumn=this.lines[this.cursorLine]?.length||0)}else if(this.cursorColumn>0)this.cursorColumn--;else if(this.cursorLine>0)if(this.cursorLine--,this._getCollapsedClosingLine(this.cursorLine))this.cursorColumn=this.lines[this.cursorLine]?.length||0;else{const e=this._getCollapsedRangeForLine(this.cursorLine);if(e){this.cursorLine=e.startLine;const t=this.lines[this.cursorLine];this.cursorColumn=t.search(I)+1}else this.cursorColumn=this.lines[this.cursorLine]?.length||0}}_scrollToCursor(){const e=this._viewport;if(!e)return;const t=this.visibleLines.findIndex(e=>e.index===this.cursorLine);if(-1===t)return;const s=t*this.lineHeight,i=e.scrollTop,n=i+e.clientHeight;s<i?e.scrollTop=s:s+this.lineHeight>n&&(e.scrollTop=s+this.lineHeight-e.clientHeight)}_handleArrowKey(e,t,s,i=!1){s&&!this.selectionStart&&(this.selectionStart={line:this.cursorLine,column:this.cursorColumn}),0!==e?this.moveCursorSkipCollapsed(e):0!==t&&(i?this._moveCursorByWord(t):this.moveCursorHorizontal(t)),s?this.selectionEnd={line:this.cursorLine,column:this.cursorColumn}:(this.selectionStart=null,this.selectionEnd=null)}_moveCursorByWord(e){const t=this.lines[this.cursorLine]||"",s=e=>E.test(e),i=this._getCollapsedNodeAtLine(this.cursorLine);if(e>0){let e=this.cursorColumn;if(i){const s=t.search(I);if(s>=0&&e>=s)return this.cursorLine=i.endLine,this.cursorColumn=(this.lines[this.cursorLine]||"").length,this._invalidateRenderCache(),this._scrollToCursor(),void this.scheduleRender()}if(e>=t.length){if(this.cursorLine<this.lines.length-1){let e=this.cursorLine+1;const t=this._getCollapsedRangeForLine(e);t&&(e=t.endLine),this.cursorLine=Math.min(e,this.lines.length-1),this.cursorColumn=0}}else if(s(t[e])){for(;e<t.length&&s(t[e]);)e++;this.cursorColumn=e}else{for(;e<t.length&&!s(t[e]);)e++;this.cursorColumn=e}}else{let e=this.cursorColumn;const i=this._getCollapsedClosingLine(this.cursorLine);if(i){const s=this._getClosingBracketPos(t);if(s>=0&&e<=s+1){this.cursorLine=i.startLine;const e=(this.lines[this.cursorLine]||"").search(I);return this.cursorColumn=e>=0?e:0,this._invalidateRenderCache(),this._scrollToCursor(),void this.scheduleRender()}}if(0===e){if(this.cursorLine>0){let e=this.cursorLine-1;const t=this._getCollapsedRangeForLine(e);t&&(e=t.startLine),this.cursorLine=Math.max(e,0),this.cursorColumn=this.lines[this.cursorLine].length}}else if(e>0&&s(t[e-1])){for(;e>0&&s(t[e-1]);)e--;this.cursorColumn=e}else{for(;e>0&&!s(t[e-1]);)e--;for(;e>0&&s(t[e-1]);)e--;this.cursorColumn=e}}this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_handleHomeEnd(e,t,s){t&&!this.selectionStart&&(this.selectionStart={line:this.cursorLine,column:this.cursorColumn}),"home"===e?(s&&(this.cursorLine=s.startLine),this.cursorColumn=0):this.cursorLine<this.lines.length&&(this.cursorColumn=this.lines[this.cursorLine].length),t?this.selectionEnd={line:this.cursorLine,column:this.cursorColumn}:(this.selectionStart=null,this.selectionEnd=null),this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_selectAll(){this.selectionStart={line:0,column:0};const e=this.lines.length-1;this.selectionEnd={line:e,column:this.lines[e]?.length||0},this.cursorLine=e,this.cursorColumn=this.lines[e]?.length||0,this._invalidateRenderCache(),this._scrollToCursor(),this.scheduleRender()}_getSelectedText(){const e=this._normalizeSelection();if(!e)return"";const{start:t,end:s}=e;if(t.line===s.line)return this.lines[t.line].substring(t.column,s.column);let i=this.lines[t.line].substring(t.column)+"\n";for(let n=t.line+1;n<s.line;n++)i+=this.lines[n]+"\n";return i+=this.lines[s.line].substring(0,s.column),i}_normalizeSelection(){if(!this.selectionStart||!this.selectionEnd)return null;const e=this.selectionStart,t=this.selectionEnd;return e.line<t.line||e.line===t.line&&e.column<=t.column?{start:e,end:t}:{start:t,end:e}}_hasSelection(){return!(!this.selectionStart||!this.selectionEnd||this.selectionStart.line===this.selectionEnd.line&&this.selectionStart.column===this.selectionEnd.column)}_clearSelection(){this.selectionStart=null,this.selectionEnd=null}_deleteSelection(){const e=this._normalizeSelection();if(!e)return!1;const{start:t,end:s}=e;if(this._saveToHistory("delete"),t.line===s.line){const e=this.lines[t.line];this.lines[t.line]=e.substring(0,t.column)+e.substring(s.column)}else{const e=this.lines[t.line].substring(0,t.column),i=this.lines[s.line].substring(s.column);this.lines[t.line]=e+i,this.lines.splice(t.line+1,s.line-t.line)}return this.cursorLine=t.line,this.cursorColumn=t.column,this.selectionStart=null,this.selectionEnd=null,!0}insertText(e){if(this._hasSelection()&&this._deleteSelection(),!this._getCollapsedRangeForLine(this.cursorLine)){if(this._getCollapsedClosingLine(this.cursorLine)){const e=this.lines[this.cursorLine],t=this._getClosingBracketPos(e);if(this.cursorColumn<=t)return}if(this._getCollapsedNodeAtLine(this.cursorLine)){const e=this.lines[this.cursorLine].search(I);if(this.cursorColumn>e)return}if(this._saveToHistory("insert"),0===this.lines.length){const t=e.split("\n");this.lines=t,this.cursorLine=t.length-1,this.cursorColumn=t[t.length-1].length}else if(this.cursorLine<this.lines.length){const t=this.lines[this.cursorLine];this.lines[this.cursorLine]=t.substring(0,this.cursorColumn)+e+t.substring(this.cursorColumn),this.cursorColumn+=e.length}this.formatAndUpdate()}}handlePaste(e){e.preventDefault();const t=e.clipboardData?.getData("text/plain");if(!t)return;const s=0===this.lines.length;try{const e=K(JSON.parse(t)).map(e=>JSON.stringify(e,null,2)).join(",\n");this.insertText(e)}catch{this.insertText(t)}s&&this.lines.length>0&&(this.renderTimer&&(cancelAnimationFrame(this.renderTimer),this.renderTimer=void 0),this.autoCollapseCoordinates())}handleCopy(e){e.preventDefault(),e.clipboardData&&(this._hasSelection()?e.clipboardData.setData("text/plain",this._getSelectedText()):e.clipboardData.setData("text/plain",this.getContent()))}handleCut(e){e.preventDefault(),e.clipboardData&&(this._hasSelection()?(e.clipboardData.setData("text/plain",this._getSelectedText()),this._saveToHistory("cut"),this._deleteSelection(),this.formatAndUpdate()):(e.clipboardData.setData("text/plain",this.getContent()),this._saveToHistory("cut"),this.lines=[],this.cursorLine=0,this.cursorColumn=0,this.formatAndUpdate()))}_getPositionFromClick(e){const t=this._viewport,s=this._linesContainer;if(!t)return{line:0,column:0};const i=t.getBoundingClientRect(),n=e.clientY-i.top+t.scrollTop-8,o=Math.floor(n/this.lineHeight);let r=0,l=0;if(o>=0&&o<this.visibleLines.length){const n=this.visibleLines[o];r=n.index;const a=s?.querySelector(`.line[data-line-index="${n.index}"]`),h=this._getCharWidth();if(a){const t=a.getBoundingClientRect(),s=e.clientX-t.left,i=Math.round(s/h),o=n.content?.length||0;l=Math.max(0,Math.min(i,o))}else{const s=12,o=e.clientX-i.left+t.scrollLeft-s,r=Math.round(o/h),a=n.content?.length||0;l=Math.max(0,Math.min(r,a))}}return{line:r,column:l}}handleGutterClick(e){const t=e.target;if(!t)return;const s=t.closest(".visibility-button");if(s)this.toggleFeatureVisibility(s.dataset.featureKey);else if(t.classList.contains("collapse-button")){const e=t.dataset.nodeId;return void(e&&this.toggleCollapse(e))}}handleEditorClick(e){const t=e.target;if(!t)return;this._blockRender=!1;const s=t.closest(".line.has-visibility");if(s){const t=s.getBoundingClientRect();if(e.clientX-t.left<14){e.preventDefault(),e.stopPropagation();const t=s.dataset.featureKey;return void(t&&this.toggleFeatureVisibility(t))}}if(t.classList.contains("json-color")){const s=t.getBoundingClientRect(),i=e.clientX-s.left;if(i<0&&i>=-8){e.preventDefault(),e.stopPropagation();const s=t.dataset.color,i=t.closest(".line");if(i){const e=parseInt(i.dataset.lineIndex||"0"),n=this.lines[e].match(k);n&&n[1]&&s&&this.showColorPicker(t,e,s,n[1])}return}}if(t.classList.contains("json-boolean")){const s=t.getBoundingClientRect(),i=e.clientX-s.left;if(i<0&&i>=-8){e.preventDefault(),e.stopPropagation();const s=t.closest(".line");if(s){const e=parseInt(s.dataset.lineIndex||"0"),t=this.lines[e].match(S);if(t){const s="true"===t[2];this.updateBooleanValue(e,!s,t[1])}}return}}}toggleCollapse(e){this.collapsedNodes.has(e)?this.collapsedNodes.delete(e):this.collapsedNodes.add(e),this.updateView(),this._invalidateRenderCache(),this.scheduleRender()}autoCollapseCoordinates(){this._applyCollapsedOption(["coordinates"])}_applyCollapsedFromOptions(e,t){const s=void 0!==e.collapsed?e.collapsed:["coordinates"];s&&(!Array.isArray(s)||s.length>0)&&this._applyCollapsedOption(s,t)}_applyCollapsedOption(e,t=null){const s=this._findCollapsibleRanges(),i=s.filter(e=>e.isRootFeature);for(const n of s){let s=!1;if("function"==typeof e){const o=i.findIndex(e=>n.startLine>=e.startLine&&n.endLine<=e.endLine),r=e(t?.[o]||null,o);s=n.isRootFeature?r.includes("$root"):r.includes(n.nodeKey)}else Array.isArray(e)&&(s=n.isRootFeature?e.includes("$root"):e.includes(n.nodeKey));s&&this.collapsedNodes.add(n.nodeId)}this.updateModel(),this.scheduleRender()}toggleFeatureVisibility(e){e&&(this.hiddenFeatures.has(e)?this.hiddenFeatures.delete(e):this.hiddenFeatures.add(e),this.updateView(),this.scheduleRender(),this.emitChange())}showColorPicker(e,t,s,i){const n=document.querySelector(".geojson-color-picker-anchor");n&&n.remove();const o=z("div");o.className="geojson-color-picker-anchor";const r=e.getBoundingClientRect();o.style.cssText=`\n position: fixed;\n left: ${r.left-8}px;\n top: ${r.top+r.height}px;\n width: 10px;\n height: 10px;\n z-index: 9998;\n `,document.body.appendChild(o);const l=z("input");l.type="color";let a=s;a=s.startsWith("#")?s.replace(y,"#$1$1$2$2$3$3"):function(e){const t=(D||(D=document.createElement("div"),D.style.display="none",document.body.appendChild(D)),D);t.style.color=e;const s=getComputedStyle(t).color;if(!s)return null;const i=s.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(!i)return null;const[,n,o,r]=i;return"#"+parseInt(n,10).toString(16).padStart(2,"0")+parseInt(o,10).toString(16).padStart(2,"0")+parseInt(r,10).toString(16).padStart(2,"0")}(s)||"#000000",l.value=a,l.className="geojson-color-picker-input",l.style.cssText="\n position: absolute;\n left: 0;\n top: 0;\n width: 10px;\n height: 10px;\n opacity: 0;\n border: none;\n padding: 0;\n cursor: pointer;\n ",o.appendChild(l),l.addEventListener("input",e=>{this.updateColorValue(t,e.target.value,i)});const h=e=>{e.target!==l&&(document.removeEventListener("click",h,!0),o.remove())};l._closeListener=h,setTimeout(()=>{document.addEventListener("click",h,!0)},100),l.focus(),l.click()}updateColorValue(e,t,s){const i=new RegExp(`"${s}"\\s*:\\s*"(?:#[0-9a-fA-F]{3,6}|[a-zA-Z]+)"`);this.lines[e]=this.lines[e].replace(i,`"${s}": "${t}"`),this.updateView(),this.scheduleRender(),this.emitChange()}updateBooleanValue(e,t,s){const i=new RegExp(`"${s}"\\s*:\\s*(true|false)`);this.lines[e]=this.lines[e].replace(i,`"${s}": ${t}`),this.updateView(),this.scheduleRender(),this.emitChange()}formatAndUpdate(){try{const e="["+this.lines.join("\n")+"]",t=JSON.parse(e),s=JSON.stringify(t,null,2).split("\n");this.lines=s.slice(1,-1)}catch(e){}this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange()}emitChange(){const e=this.getContent(),s=this.prefix+e+this.suffix;try{let i=JSON.parse(s);this.hiddenFeatures.size>0&&(i.features=i.features.filter(e=>{const t=B(e);return!t||!this.hiddenFeatures.has(t)}));const n=function(e){const s=[];return e.features?(e.features.forEach((e,i)=>{"Feature"!==e.type&&s.push(`features[${i}]: type must be "Feature"`),e.geometry&&e.geometry.type&&(t.includes(e.geometry.type)||s.push(`features[${i}].geometry: invalid type "${e.geometry.type}"`))}),s):s}(i);n.length>0?this.dispatchEvent(new CustomEvent("error",{detail:{error:n.join("; "),errors:n,content:e},bubbles:!0,composed:!0})):this.dispatchEvent(new CustomEvent("change",{detail:i,bubbles:!0,composed:!0}))}catch(i){this.dispatchEvent(new CustomEvent("error",{detail:{error:i instanceof Error?i.message:"Unknown error",content:e},bubbles:!0,composed:!0}))}}updateReadonly(){this._hiddenTextarea&&(this._hiddenTextarea.readOnly=this.readonly),this._clearBtn&&(this._clearBtn.hidden=this.readonly)}updatePlaceholderVisibility(){this._placeholderLayer&&(this._placeholderLayer.style.display=this.lines.length>0?"none":"block")}updatePlaceholderContent(){this._placeholderLayer&&(this._placeholderLayer.textContent=this.placeholder),this.updatePlaceholderVisibility()}updatePrefixSuffix(){this._editorPrefix&&(this._editorPrefix.textContent=this.prefix),this._editorSuffix&&(this._editorSuffix.textContent=this.suffix)}updateThemeCSS(){const e=(t=this.getAttribute("dark-selector")||".dark").startsWith(".")&&!t.includes(" ")?`:host(${t})`:`:host-context(${t})`;var t;let s=this._id("theme-styles");s||(s=z("style"),s.id="theme-styles",this.shadowRoot.insertBefore(s,this.shadowRoot.firstChild)),F.lastIndex=0;const i=e=>Object.entries(e).filter(e=>void 0!==e[1]).map(([e,t])=>{return`--${s=e,s.replace(F,"-$1").toLowerCase()}: ${t};`;var s}).join("\n "),n=i(this.themes.light||{});let o=n?`:host {\n ${n}\n }\n`:"";o+=`${e} {\n ${i({bgColor:"#2b2b2b",textColor:"#a9b7c6",caretColor:"#bbb",gutterBg:"#313335",gutterBorder:"#3c3f41",gutterText:"#606366",jsonKey:"#9876aa",jsonString:"#6a8759",jsonNumber:"#6897bb",jsonBoolean:"#cc7832",jsonNull:"#cc7832",jsonPunct:"#a9b7c6",jsonError:"#ff6b68",controlColor:"#cc7832",controlBg:"#3c3f41",controlBorder:"#5a5a5a",geojsonKey:"#9876aa",geojsonType:"#6a8759",geojsonTypeInvalid:"#ff6b68",jsonKeyInvalid:"#ff6b68",...this.themes.dark})}\n }`,s.textContent=o}setTheme(e){e.dark&&(this.themes.dark={...this.themes.dark,...e.dark}),e.light&&(this.themes.light={...this.themes.light,...e.light}),this.updateThemeCSS()}resetTheme(){this.themes={dark:{},light:{}},this.updateThemeCSS()}getTheme(){return{...this.themes}}_findCollapsibleRanges(){const e=[];for(const[t,s]of this._lineToNodeId){const i=this._nodeIdToLines.get(s);if(!i)continue;const n=this.lines[t];if(!n)continue;const o=n.match(j),r=!o&&n.match(R);if(!o&&!r)continue;const l=o?o[2]:r?r[1]:"{";e.push({startLine:i.startLine,endLine:i.endLine,nodeKey:i.nodeKey||(o?o[1]:`__root_${t}`),nodeId:s,openBracket:l,isRootFeature:!!r})}return e.sort((e,t)=>e.startLine-t.startLine),e}_findClosingLine(e,t){let s=1;const i=this.lines[e],n=i.indexOf(t);if(-1!==n){const o=H(i.substring(n+1),t);if(s+=o.open-o.close,0===s)return e}for(let o=e+1;o<this.lines.length;o++){const e=H(this.lines[o],t);if(s+=e.open-e.close,0===s)return o}return-1}_buildContextMap(){const e=this.lines.length;if(this._contextMapCache&&this._contextMapLinesLength===e&&this._contextMapFirstLine===this.lines[0]&&this._contextMapLastLine===this.lines[e-1])return this._contextMapCache;const t=/* @__PURE__ */new Map,o=[];let r=null;for(let l=0;l<e;l++){const e=this.lines[l],a=o[o.length-1]?.context||"Feature";t.set(l,a),s.test(e)?r="geometry":i.test(e)?r="properties":n.test(e)&&(r="Feature"),$.lastIndex=0,A.lastIndex=0,N.lastIndex=0,M.lastIndex=0;const h=(e.match($)||[]).length,c=(e.match(A)||[]).length,d=(e.match(N)||[]).length,u=(e.match(M)||[]).length;for(let t=0;t<h+d;t++)o.push({context:r||a,isArray:t>=h}),r=null;for(let t=0;t<c+u&&o.length>0;t++)o.pop()}return this._contextMapCache=t,this._contextMapLinesLength=e,this._contextMapFirstLine=this.lines[0],this._contextMapLastLine=this.lines[e-1],t}set(e,t={}){const s=K(e);this._setFeaturesInternal(s,t)}add(e,t={}){const s=K(e),i=[...this._parseFeatures(),...s];this._setFeaturesInternal(i,t)}insertAt(e,t,s={}){const i=K(e),n=this._parseFeatures(),o=t<0?n.length+t:t;n.splice(Math.max(0,Math.min(o,n.length)),0,...i),this._setFeaturesInternal(n,s)}_setFeaturesInternal(e,t){const s=e.map(e=>JSON.stringify(e,null,2)).join(",\n");this.setValue(s,!1),this._applyCollapsedFromOptions(t,e)}removeAt(e){const t=this._parseFeatures(),s=e<0?t.length+e:e;if(s>=0&&s<t.length){const e=t.splice(s,1)[0];return this.set(t),e}}removeAll(){this.lines.length>0&&this._saveToHistory("removeAll");const e=this._parseFeatures();return this.lines=[],this.collapsedNodes.clear(),this.hiddenFeatures.clear(),this.updateModel(),this.scheduleRender(),this.updatePlaceholderVisibility(),this.emitChange(),e}get(e){const t=this._parseFeatures();return t[e<0?t.length+e:e]}getAll(){return this._parseFeatures()}emit(){this.emitChange()}save(e="features.geojson"){try{const t={type:"FeatureCollection",features:this._parseFeatures()},s=JSON.stringify(t,null,2),i=new Blob([s],{type:"application/geo+json"}),n=URL.createObjectURL(i),o=z("a");return o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n),!0}catch(t){return!1}}open(e={}){return new Promise(t=>{const s=z("input");s.type="file",s.accept=".geojson,.json,application/geo+json,application/json",s.style.display="none",s.addEventListener("change",i=>{const n=i.target.files?.[0];if(!n)return document.body.removeChild(s),void t(!1);const o=new FileReader;o.onload=i=>{try{const n=i.target?.result,o=K(JSON.parse(n));this._saveToHistory("open"),this.set(o,e),this.clearHistory(),document.body.removeChild(s),t(!0)}catch(n){document.body.removeChild(s),t(!1)}},o.onerror=()=>{document.body.removeChild(s),t(!1)},o.readAsText(n)}),s.addEventListener("cancel",()=>{document.body.removeChild(s),t(!1)}),document.body.appendChild(s),s.click()})}_parseFeatures(){try{const e=this.lines.join("\n");return e.trim()?JSON.parse("["+e+"]"):[]}catch(e){return[]}}}customElements.get("geojson-editor")||customElements.define("geojson-editor",U);export{U as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softwarity/geojson-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "A feature-rich GeoJSON editor Web Component with syntax highlighting, collapsible nodes, and color picker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/geojson-editor.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "vite",
|
|
22
22
|
"build": "vite build && npm run build:types",
|
|
23
|
-
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir types",
|
|
23
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir types && cp src/geojson-editor.d.ts types/ && rm -f types/constants.d.ts types/utils.d.ts types/validation.d.ts types/syntax-highlighter.d.ts types/geojson-editor.template.d.ts types/internal-types.d.ts",
|
|
24
24
|
"preview": "vite preview",
|
|
25
25
|
"test": "web-test-runner",
|
|
26
26
|
"test:watch": "web-test-runner --watch",
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { GeoJsonGeometryTypes } from 'geojson';
|
|
2
|
+
|
|
3
|
+
// Version injected by Vite build from package.json
|
|
4
|
+
declare const __VERSION__: string;
|
|
5
|
+
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'dev';
|
|
6
|
+
|
|
7
|
+
// GeoJSON constants - exclude GeometryCollection which is not supported
|
|
8
|
+
export type GeometryType = Exclude<GeoJsonGeometryTypes, 'GeometryCollection'>;
|
|
9
|
+
export const GEOJSON_KEYS: string[] = ['type', 'geometry', 'properties', 'coordinates', 'id', 'features'];
|
|
10
|
+
export const GEOMETRY_TYPES: GeometryType[] = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
|
|
11
|
+
|
|
12
|
+
// ========== Pre-compiled regex patterns for performance ==========
|
|
13
|
+
|
|
14
|
+
// Context detection
|
|
15
|
+
export const RE_CONTEXT_GEOMETRY = /"geometry"\s*:/;
|
|
16
|
+
export const RE_CONTEXT_PROPERTIES = /"properties"\s*:/;
|
|
17
|
+
export const RE_CONTEXT_FEATURES = /"features"\s*:/;
|
|
18
|
+
|
|
19
|
+
// Collapsed node detection
|
|
20
|
+
export const RE_COLLAPSED_BRACKET = /^(\s*"[^"]+"\s*:\s*)([{\[])/;
|
|
21
|
+
export const RE_COLLAPSED_ROOT = /^(\s*)([{\[]),?\s*$/;
|
|
22
|
+
|
|
23
|
+
// HTML escaping
|
|
24
|
+
export const RE_ESCAPE_AMP = /&/g;
|
|
25
|
+
export const RE_ESCAPE_LT = /</g;
|
|
26
|
+
export const RE_ESCAPE_GT = />/g;
|
|
27
|
+
|
|
28
|
+
// Syntax highlighting
|
|
29
|
+
export const RE_PUNCTUATION = /([{}[\],:])/g;
|
|
30
|
+
export const RE_JSON_KEYS = /"([^"]+)"(<span class="json-punctuation">:<\/span>)/g;
|
|
31
|
+
export const RE_TYPE_VALUES = /<span class="geojson-key">"type"<\/span><span class="json-punctuation">:<\/span>(\s*)"([^"]*)"/g;
|
|
32
|
+
export const RE_STRING_VALUES = /(<span class="json-punctuation">:<\/span>)(\s*)"([^"]*)"/g;
|
|
33
|
+
export const RE_NUMBERS_COLON = /(<span class="json-punctuation">:<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi;
|
|
34
|
+
export const RE_NUMBERS_ARRAY = /(<span class="json-punctuation">[\[,]<\/span>)(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gi;
|
|
35
|
+
export const RE_NUMBERS_START = /^(\s*)(-?\d+\.?\d*(?:e[+-]?\d+)?)/gim;
|
|
36
|
+
export const RE_BOOLEANS = /(<span class="json-punctuation">:<\/span>)(\s*)(true|false)/g;
|
|
37
|
+
export const RE_NULL = /(<span class="json-punctuation">:<\/span>)(\s*)(null)/g;
|
|
38
|
+
export const RE_UNRECOGNIZED = /(<\/span>|^)([^<]+)(<span|$)/g;
|
|
39
|
+
|
|
40
|
+
// Color validation and normalization
|
|
41
|
+
export const RE_COLOR_HEX = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
42
|
+
export const RE_NORMALIZE_COLOR = /^#?([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/;
|
|
43
|
+
|
|
44
|
+
// Whitespace
|
|
45
|
+
export const RE_WHITESPACE_ONLY = /^\s*$/;
|
|
46
|
+
export const RE_WHITESPACE_SPLIT = /(\s+)/;
|
|
47
|
+
|
|
48
|
+
// Attribute extraction - unified regex for string values and booleans
|
|
49
|
+
// Captures: [1] attributeName, [2] stringValue (if string), [3] boolValue (if boolean)
|
|
50
|
+
export const RE_ATTR_VALUE = /"([\w-]+)"\s*:\s*(?:"([^"]*)"|(\btrue\b|\bfalse\b))/g;
|
|
51
|
+
// Non-global version for single match with capture groups
|
|
52
|
+
export const RE_ATTR_VALUE_SINGLE = /"([\w-]+)"\s*:\s*(?:"([^"]*)"|(\btrue\b|\bfalse\b))/;
|
|
53
|
+
// Boolean attribute matching (non-global for single match)
|
|
54
|
+
export const RE_ATTR_AND_BOOL_VALUE = /"([\w-]+)"\s*:\s*(true|false)/;
|
|
55
|
+
|
|
56
|
+
// Feature detection
|
|
57
|
+
export const RE_IS_FEATURE = /"type"\s*:\s*"Feature"/;
|
|
58
|
+
|
|
59
|
+
// Collapsible node matching
|
|
60
|
+
export const RE_KV_MATCH = /^\s*"([^"]+)"\s*:\s*([{\[])/;
|
|
61
|
+
export const RE_ROOT_MATCH = /^\s*([{\[]),?\s*$/;
|
|
62
|
+
export const RE_BRACKET_POS = /[{\[]/;
|
|
63
|
+
|
|
64
|
+
// Word navigation
|
|
65
|
+
export const RE_IS_WORD_CHAR = /[\w-]/;
|
|
66
|
+
|
|
67
|
+
// Theme CSS generation
|
|
68
|
+
export const RE_TO_KEBAB = /([A-Z])/g;
|
|
69
|
+
|
|
70
|
+
// Bracket counting
|
|
71
|
+
export const RE_OPEN_BRACES = /\{/g;
|
|
72
|
+
export const RE_CLOSE_BRACES = /\}/g;
|
|
73
|
+
export const RE_OPEN_BRACKETS = /\[/g;
|
|
74
|
+
export const RE_CLOSE_BRACKET = /\]/g;
|
package/src/geojson-editor.css
CHANGED
|
@@ -104,7 +104,6 @@
|
|
|
104
104
|
height: 12px;
|
|
105
105
|
border-radius: 2px;
|
|
106
106
|
cursor: pointer;
|
|
107
|
-
transition: transform 0.1s;
|
|
108
107
|
flex-shrink: 0;
|
|
109
108
|
background: transparent;
|
|
110
109
|
border: none;
|
|
@@ -115,7 +114,7 @@
|
|
|
115
114
|
justify-content: center;
|
|
116
115
|
user-select: none;
|
|
117
116
|
opacity: 0;
|
|
118
|
-
transition: opacity 0.15s;
|
|
117
|
+
transition: transform 0.1s, opacity 0.15s;
|
|
119
118
|
}
|
|
120
119
|
.collapse-button.collapsed {
|
|
121
120
|
opacity: 1;
|
|
@@ -167,6 +166,8 @@
|
|
|
167
166
|
overflow: auto;
|
|
168
167
|
padding: var(--editor-padding-y) var(--editor-padding-x);
|
|
169
168
|
overscroll-behavior: contain; /* Prevent scroll chaining to parent */
|
|
169
|
+
scrollbar-width: thin;
|
|
170
|
+
scrollbar-color: var(--control-border, #c0c0c0) var(--control-bg, #e8e8e8);
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
/* Scroll content - defines total scrollable height */
|
|
@@ -203,6 +204,18 @@
|
|
|
203
204
|
animation: cursor-blink 1s step-end infinite;
|
|
204
205
|
}
|
|
205
206
|
|
|
207
|
+
/* Block cursor for overwrite mode */
|
|
208
|
+
.cursor.cursor-block {
|
|
209
|
+
width: 0.6em; /* Will be overridden inline with charWidth */
|
|
210
|
+
opacity: 0.5;
|
|
211
|
+
animation: cursor-blink-block 1s step-end infinite;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@keyframes cursor-blink-block {
|
|
215
|
+
0%, 100% { opacity: 0.5; }
|
|
216
|
+
50% { opacity: 0.2; }
|
|
217
|
+
}
|
|
218
|
+
|
|
206
219
|
@keyframes cursor-blink {
|
|
207
220
|
0%, 100% { opacity: 1; }
|
|
208
221
|
50% { opacity: 0; }
|
|
@@ -337,7 +350,6 @@
|
|
|
337
350
|
.viewport::-webkit-scrollbar-track { background: var(--control-bg, #e8e8e8); }
|
|
338
351
|
.viewport::-webkit-scrollbar-thumb { background: var(--control-border, #c0c0c0); border-radius: 5px; }
|
|
339
352
|
.viewport::-webkit-scrollbar-thumb:hover { background: var(--control-color, #000080); }
|
|
340
|
-
.viewport { scrollbar-width: thin; scrollbar-color: var(--control-border, #c0c0c0) var(--control-bg, #e8e8e8); }
|
|
341
353
|
|
|
342
354
|
/* ========== Inline Controls (using ::before pseudo-elements) ========== */
|
|
343
355
|
|