@gjsify/gtksource-core 0.56.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/buffer-vectors.js +3 -0
- package/lib/esm/buffer.js +5 -0
- package/lib/esm/coerce.js +1 -0
- package/lib/esm/color.js +1 -0
- package/lib/esm/conformance.js +1 -0
- package/lib/esm/editor-driver.js +0 -0
- package/lib/esm/editor-session.js +2 -0
- package/lib/esm/fallback-schemes.js +2 -0
- package/lib/esm/gutter.js +1 -0
- package/lib/esm/highlight-controller.js +1 -0
- package/lib/esm/highlighter.js +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/init-vectors.js +1 -0
- package/lib/esm/init.js +1 -0
- package/lib/esm/language-manager.js +1 -0
- package/lib/esm/line-store.js +1 -0
- package/lib/esm/managers-vectors.js +1 -0
- package/lib/esm/signals.js +1 -0
- package/lib/esm/style-scheme.js +1 -0
- package/lib/esm/text-iter.js +1 -0
- package/lib/esm/token-styler.js +1 -0
- package/lib/esm/view-vectors.js +1 -0
- package/lib/types/buffer-vectors.d.ts +42 -0
- package/lib/types/buffer-vectors.gjs.spec.d.ts +2 -0
- package/lib/types/buffer-vectors.spec.d.ts +2 -0
- package/lib/types/buffer.d.ts +110 -0
- package/lib/types/buffer.spec.d.ts +2 -0
- package/lib/types/coerce.d.ts +2 -0
- package/lib/types/color.d.ts +6 -0
- package/lib/types/conformance.d.ts +4 -0
- package/lib/types/editor-driver.d.ts +40 -0
- package/lib/types/editor-session.d.ts +54 -0
- package/lib/types/editor-session.spec.d.ts +2 -0
- package/lib/types/fallback-schemes.d.ts +4 -0
- package/lib/types/gutter.d.ts +20 -0
- package/lib/types/gutter.spec.d.ts +2 -0
- package/lib/types/highlight-controller.d.ts +24 -0
- package/lib/types/highlighter.d.ts +33 -0
- package/lib/types/highlighter.spec.d.ts +2 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/init-vectors.d.ts +10 -0
- package/lib/types/init.d.ts +1 -0
- package/lib/types/init.gjs.spec.d.ts +2 -0
- package/lib/types/init.spec.d.ts +2 -0
- package/lib/types/language-manager.d.ts +35 -0
- package/lib/types/line-store.d.ts +9 -0
- package/lib/types/managers-vectors.d.ts +25 -0
- package/lib/types/managers-vectors.gjs.spec.d.ts +2 -0
- package/lib/types/managers-vectors.spec.d.ts +2 -0
- package/lib/types/managers.spec.d.ts +2 -0
- package/lib/types/signals.d.ts +12 -0
- package/lib/types/style-scheme.d.ts +55 -0
- package/lib/types/text-iter.d.ts +21 -0
- package/lib/types/token-styler.d.ts +27 -0
- package/lib/types/view-vectors.d.ts +56 -0
- package/lib/types/view-vectors.gjs.spec.d.ts +2 -0
- package/package.json +7 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=`héllo
|
|
2
|
+
😀 wörld`,iterAt=(e,t)=>{let n=e.get_start_iter();return n.set_offset(t),n},bounds=e=>{let[t,n,r]=e.get_selection_bounds();return[t,n.get_offset(),r.get_offset()]},logging=(e,t)=>{let n=[];for(let r of t)e.connect(r,((e,...t)=>{let[i,a]=t;n.push(r===`mark-set`?`${r}:${i.get_offset()}:${a.name}`:r)}));return n},typed=(e,t)=>{e.begin_user_action(),e.insert_at_cursor(t,-1),e.end_user_action()},t=[{rule:`setting text puts the cursor after it, counted in characters`,observe:t=>{let n=new t.Buffer;return n.text=e,[n.cursor_position,bounds(n)]},shows:[13,[!1,13,13]]},{rule:`the two marks are named insert and selection_bound`,observe:e=>{let t=new e.Buffer;return[t.get_insert().name,t.get_selection_bound().name]},shows:[`insert`,`selection_bound`]},{rule:`TextIter.set_offset counts characters; a negative or too large offset is the end`,observe:t=>{let n=new t.Buffer;return n.text=e,[iterAt(n,8).get_offset(),iterAt(n,999).get_offset(),iterAt(n,-1).get_offset()]},shows:[8,13,13]},{rule:`get_text between two iterators`,observe:t=>{let n=new t.Buffer;return n.text=e,n.get_text(n.get_start_iter(),iterAt(n,8),!1)},shows:`héllo
|
|
3
|
+
😀 `},{rule:`move_mark on insert reports mark-set, then cursor-moved, even for the same place`,observe:t=>{let n=new t.Buffer;n.text=e;let r=logging(n,[`mark-set`,`cursor-moved`]);return n.move_mark(n.get_insert(),iterAt(n,3)),n.move_mark(n.get_insert(),iterAt(n,3)),r},shows:[`mark-set:3:insert`,`cursor-moved`,`mark-set:3:insert`,`cursor-moved`]},{rule:`move_mark on selection_bound reports mark-set only and makes a selection`,observe:t=>{let n=new t.Buffer;n.text=e,n.move_mark(n.get_insert(),iterAt(n,3));let r=logging(n,[`mark-set`,`cursor-moved`]);n.move_mark(n.get_selection_bound(),iterAt(n,5));let[,i,a]=n.get_selection_bounds();return[r,bounds(n),n.get_text(i,a,!1)]},shows:[[`mark-set:5:selection_bound`],[!0,3,5],`lo`]},{rule:`get_selection_bounds is ordered whichever mark is first`,observe:t=>{let n=new t.Buffer;return n.text=e,n.move_mark(n.get_insert(),iterAt(n,5)),n.move_mark(n.get_selection_bound(),iterAt(n,3)),[bounds(n),n.cursor_position]},shows:[[!0,3,5],5]},{rule:`moving a mark to 0 through a handler-built iterator`,observe:t=>{let n=new t.Buffer;n.text=e;let r=[];n.connect(`mark-set`,((e,t,n)=>{r.push([t.get_offset(),n.name])}));let i=n.get_start_iter();return i.set_offset(0),n.move_mark(n.get_insert(),i),[r,n.cursor_position]},shows:[[[0,`insert`]],0]},{rule:`a user action brackets its edits with begin and end, the outermost only`,observe:e=>{let t=new e.Buffer,n=logging(t,[`begin-user-action`,`end-user-action`]);t.begin_user_action(),t.begin_user_action(),t.insert_at_cursor(`a`,-1),t.end_user_action();let r=[...n];return t.end_user_action(),[r,n]},shows:[[`begin-user-action`],[`begin-user-action`,`end-user-action`]]},{rule:`undo and redo of a user action restore the text and report in order`,observe:e=>{let t=new e.Buffer,n=logging(t,[`undo`,`redo`]);typed(t,`abc`);let r=[t.can_undo,t.can_redo];t.undo();let i=[t.text,t.can_undo,t.can_redo,t.cursor_position];return t.redo(),[r,i,t.text,t.cursor_position,n]},shows:[[!0,!1],[``,!1,!0,0],`abc`,3,[`undo`,`redo`]]},{rule:`several edits in one user action are one undo step`,observe:e=>{let t=new e.Buffer;t.begin_user_action(),t.insert_at_cursor(`x`,-1),t.insert_at_cursor(`yz`,-1),t.end_user_action(),t.undo();let n=[t.text,t.can_undo];return t.redo(),[n,t.text]},shows:[[``,!1],`xyz`]},{rule:`an edit outside a user action is undoable too`,observe:e=>{let t=new e.Buffer;t.insert_at_cursor(`abc`,-1);let n=t.can_undo;return t.undo(),[n,t.text]},shows:[!0,``]},{rule:`undoing a delete brings the text and the cursor back, redo deletes again`,observe:e=>{let t=new e.Buffer;t.text=`abcd`,t.begin_user_action(),t.delete(iterAt(t,1),iterAt(t,3)),t.end_user_action();let n=[t.text,t.cursor_position];t.undo();let r=[t.text,t.cursor_position];return t.redo(),[n,r,[t.text,t.cursor_position]]},shows:[[`ad`,2],[`abcd`,4],[`ad`,1]]},{rule:`setting text is not undoable and drops the history`,observe:e=>{let t=new e.Buffer;typed(t,`x`),t.text=`unrec`;let n=[t.can_undo,t.can_redo];return t.undo(),[n,t.text]},shows:[[!1,!1],`unrec`]},{rule:`connect_after runs after the plain handlers, whichever was connected first`,observe:e=>{let t=new e.Buffer,n=[];return t.connect_after(`cursor-moved`,(()=>n.push(`after`))),t.connect(`cursor-moved`,(()=>n.push(`plain`))),t.move_mark(t.get_insert(),t.get_start_iter()),n},shows:[`plain`,`after`]},{rule:`connecting a signal the buffer does not have throws`,observe:e=>{try{return new e.Buffer().connect(`no-such-signal`,(()=>{})),!1}catch{return!0}},shows:!0},{rule:`set_language(null) leaves no language`,observe:e=>{let t=new e.Buffer;return t.set_language(null),t.language},shows:null}];export{t as GTKSOURCE_BUFFER_VECTORS};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{SignalEmitter as e}from"./signals.js";import{TextIter as t,TextMark as n}from"./text-iter.js";const r=new Set([`changed`,`mark-set`,`begin-user-action`,`end-user-action`,`undo`,`redo`,`cursor-moved`,`notify::language`,`notify::style-scheme`,`notify::highlight-syntax`,`notify::cursor-position`,`notify::can-undo`,`notify::can-redo`]);var GtkSourceBuffer=class extends e{constructor(e=``){super(),this.lines=[``],this.lineStarts=[0],this.startsValidTo=1,this.cursor=0,this.bound=0,this.insertMark=new n(`insert`),this.boundMark=new n(`selection_bound`),this.undoStack=[],this.redoStack=[],this.open=null,this.depth=0,this.recording=!0,this.reportedUndo=!1,this.reportedRedo=!1,this.lang=null,this.scheme=null,this.highlight=!0;let{text:t=``,highlightSyntax:r=!0}=typeof e==`string`?{text:e}:e;t!==``&&(this.lines=t.split(`
|
|
2
|
+
`)),this.highlight=r!==!1&&String(r)!==`false`}get text(){return this.lines.join(`
|
|
3
|
+
`)}set text(e){this.recording=!1;try{this.replace(0,this.length,e??``),this.placeCursor(this.length)}finally{this.recording=!0}this.undoStack=[],this.redoStack=[],this.open&&(this.open.edits.length=0),this.syncUndoState()}get length(){return this.offsetOfLine(this.lines.length-1)+this.lines[this.lines.length-1].length}get lineCount(){return this.lines.length}getLine(e){let t=this.lines[e];if(t===void 0)throw RangeError(`Buffer: line ${e} is outside 0..${this.lines.length-1}`);return t}getLines(){return[...this.lines]}offsetOfLine(e){if(e<0||e>=this.lines.length)throw RangeError(`Buffer: line ${e} is outside 0..${this.lines.length-1}`);for(;this.startsValidTo<=e;){let e=this.startsValidTo-1;this.lineStarts[this.startsValidTo]=this.lineStarts[e]+this.lines[e].length+1,this.startsValidTo++}return this.lineStarts[e]}lineOfOffset(e){this.checkOffset(e);let t=0,n=this.lines.length-1;for(;t<n;){let r=t+n+1>>1;this.offsetOfLine(r)<=e?t=r:n=r-1}return t}getText(e=0,t=this.length){if(this.checkOffset(e),this.checkOffset(t),e>t)throw RangeError(`Buffer: range ${e}..${t} is reversed`);return this.text.slice(e,t)}insert(e,t){this.replace(e,e,t)}delete(e,t){if(typeof e==`number`&&typeof t==`number`){this.replace(e,t,``);return}let n=typeof e==`number`?e:this.ownIter(e,`delete`),r=typeof t==`number`?t:this.ownIter(t,`delete`);this.replace(Math.min(n,r),Math.max(n,r),``)}replace(e,t,n){if(this.checkOffset(e),this.checkOffset(t),e>t)throw RangeError(`Buffer: range ${e}..${t} is reversed`);let r=this.lineOfOffset(e),i=this.lineOfOffset(t),a=this.offsetOfLine(r),o=this.offsetOfLine(i),s=this.lines.slice(r,i+1).join(`
|
|
4
|
+
`).slice(e-a,t-a);if(s===``&&n===``)return;let c=(this.lines[r].slice(0,e-a)+n+this.lines[i].slice(t-o)).split(`
|
|
5
|
+
`);this.lines.splice(r,i-r+1,...c),this.startsValidTo=Math.min(this.startsValidTo,r+1);let l=this.cursor,shift=r=>r>=t?r-s.length+n.length:r>e?e+n.length:r;this.cursor=shift(this.cursor),this.bound=shift(this.bound);let u={start:e,removedText:s,insertedText:n,firstLine:r,removedLines:i-r+1,insertedLines:c.length};this.record(u,l),this.emit(`changed`,u),this.cursor!==l&&this.emit(`notify::cursor-position`),this.emit(`cursor-moved`)}get cursorPosition(){return this.cursor}get cursor_position(){return new t(this,this.cursor).get_offset()}get selectionBoundPosition(){return this.bound}selectRange(e,t){this.checkOffset(e),this.checkOffset(t),e!==this.cursor&&this.moveInsert(e),t!==this.bound&&this.moveBound(t)}placeCursor(e){this.selectRange(e,e)}moveInsert(e){this.cursor=e,this.emit(`mark-set`,new t(this,e),this.insertMark),this.emit(`cursor-moved`),this.emit(`notify::cursor-position`)}moveBound(e){this.bound=e,this.emit(`mark-set`,new t(this,e),this.boundMark)}get_insert(){return this.insertMark}get_selection_bound(){return this.boundMark}get_start_iter(){return new t(this,0)}get_end_iter(){return new t(this,this.length)}get_selection_bounds(){let e=Math.min(this.cursor,this.bound),n=Math.max(this.cursor,this.bound);return[e!==n,new t(this,e),new t(this,n)]}get_text(e,t,n){let r=this.ownIter(e,`get_text`),i=this.ownIter(t,`get_text`);return this.getText(Math.min(r,i),Math.max(r,i))}move_mark(e,t){let n=this.ownIter(t,`move_mark`);if(e===this.insertMark)this.moveInsert(n);else if(e===this.boundMark)this.moveBound(n);else throw Error(`GtkSource.Buffer.move_mark: only the 'insert' and 'selection_bound' marks exist`)}insert_at_cursor(e,t){if(t!==-1)throw Error(`GtkSource.Buffer.insert_at_cursor: only len -1 is implemented`);this.insert(this.cursor,e)}set_language(e){this.language=e}set_style_scheme(e){this.styleScheme=e}begin_user_action(){this.depth++>0||(this.open={edits:[],before:this.cursor},this.emit(`begin-user-action`))}end_user_action(){if(this.depth===0||--this.depth>0)return;let e=this.open;this.open=null,e&&e.edits.length>0&&this.push(e),this.emit(`end-user-action`)}get can_undo(){return this.undoStack.length>0}get can_redo(){return this.redoStack.length>0}undo(){let e=this.depth===0?this.undoStack.pop():void 0;e&&(this.emit(`undo`),this.applyHistory(()=>{for(let t of[...e.edits].reverse())this.replace(t.start,t.start+t.insertedText.length,t.removedText)}),this.moveInsert(e.before),this.moveBound(e.before),this.redoStack.push(e),this.syncUndoState())}redo(){let e=this.depth===0?this.redoStack.pop():void 0;if(!e)return;this.emit(`redo`),this.applyHistory(()=>{for(let t of e.edits)this.replace(t.start,t.start+t.removedText.length,t.insertedText)});let t=e.edits[e.edits.length-1],n=t.start+t.insertedText.length;this.moveInsert(n),this.moveBound(n),this.undoStack.push(e),this.syncUndoState()}applyHistory(e){this.recording=!1;try{e()}finally{this.recording=!0}}record(e,t){this.recording&&(this.redoStack=[],this.open?this.open.edits.push(e):this.push({edits:[e],before:t}))}push(e){this.undoStack.push(e),this.syncUndoState()}syncUndoState(){let e=this.can_undo,t=this.can_redo,n=e!==this.reportedUndo,r=t!==this.reportedRedo;this.reportedUndo=e,this.reportedRedo=t,n&&this.emit(`notify::can-undo`),r&&this.emit(`notify::can-redo`)}checkSignal(e){if(!r.has(e))throw Error(`GtkSource.Buffer: signal '${e}' is not implemented`)}ownIter(e,n){if(!(e instanceof t)||e.source!==this)throw TypeError(`GtkSource.Buffer.${n}: the iterator belongs to another buffer`);return e.utf16Offset}get language(){return this.lang}set language(e){e!==this.lang&&(this.lang=e,this.emit(`notify::language`))}get styleScheme(){return this.scheme}set styleScheme(e){e!==this.scheme&&(this.scheme=e,this.emit(`notify::style-scheme`))}get highlightSyntax(){return this.highlight}set highlightSyntax(e){e!==this.highlight&&(this.highlight=e,this.emit(`notify::highlight-syntax`))}checkOffset(e){if(!Number.isInteger(e)||e<0||e>this.length)throw RangeError(`Buffer: offset ${e} is outside 0..${this.length}`)}};export{GtkSourceBuffer as Buffer,GtkSourceBuffer,t as TextIter,n as TextMark};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function toBoolean(e,t){if(typeof e==`boolean`)return e;if(e===`true`)return!0;if(e===`false`)return!1;throw TypeError(`${t}: ${JSON.stringify(e)} is not a boolean`)}function toNumber(e,t){let n=typeof e==`string`&&e.trim()!==``?Number(e):e;if(typeof n!=`number`||!Number.isFinite(n))throw TypeError(`${t}: ${JSON.stringify(e)} is not a number`);return n}export{toBoolean,toNumber};
|
package/lib/esm/color.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function parseColor(e){let t=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.exec(e.trim());if(!t)return;let n=t[1];n.length===3&&(n=[...n].map(e=>e+e).join(``)),n.length===6&&(n+=`ff`);let r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return parseInt(n.slice(6,8),16)<<24|r<<16|i<<8|a|0}export{parseColor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{GTKSOURCE_BUFFER_VECTORS as e}from"./buffer-vectors.js";import{GTKSOURCE_INIT_VECTORS as t}from"./init-vectors.js";import{GTKSOURCE_MANAGER_VECTORS as n}from"./managers-vectors.js";import{GTKSOURCE_VIEW_DEFAULT_VECTORS as r,GTKSOURCE_VIEW_SURFACE_VECTORS as i}from"./view-vectors.js";export{e as GTKSOURCE_BUFFER_VECTORS,t as GTKSOURCE_INIT_VECTORS,n as GTKSOURCE_MANAGER_VECTORS,r as GTKSOURCE_VIEW_DEFAULT_VECTORS,i as GTKSOURCE_VIEW_SURFACE_VECTORS};
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{SignalEmitter as e}from"./signals.js";import{Buffer as t}from"./buffer.js";import{StyleSchemeManager as n}from"./style-scheme.js";import{HighlightController as r}from"./highlight-controller.js";function leadingWhitespace(e){return/^[ \t]*/.exec(e)[0]}var EditorSession=class extends e{constructor(e,r=n.getDefault(),i=`light`){super(),this.driver=e,this.schemes=r,this.bufferHandlers=[],this.mirroring=!1,this.fromNative=!1,this.props={autoIndent:!1,indentWidth:-1,showLineNumbers:!1,monospace:!1,editable:!0,highlightCurrentLine:!1,cursorVisible:!0,leftMargin:0,rightMargin:0,topMargin:0,bottomMargin:0},this.variant=i,e.bind(this),this.attach(new t)}get buffer(){return this.current}set buffer(e){e!==this.current&&(this.attach(e),this.emit(`notify::buffer`))}attach(e){if(this.current){for(let e of this.bufferHandlers.splice(0))this.current.disconnect(e);this.controller.dispose()}this.current=e,this.bufferHandlers.push(e.connect(`changed`,(e,t)=>this.onBufferChanged(t)),e.connect(`mark-set`,()=>this.onBufferCursor())),this.mirroring=!0;try{this.driver.setText(e.text)}finally{this.mirroring=!1}this.controller=new r(e,this.driver,this.schemes,this.variant),this.driver.setLineCount(e.lineCount),this.driver.setSelection(e.cursorPosition,e.cursorPosition),this.pushLayout()}onBufferChanged(e){if(!this.fromNative){this.mirroring=!0;try{this.driver.replaceRange(e.start,e.start+e.removedText.length,e.insertedText)}finally{this.mirroring=!1}}e.insertedLines!==e.removedLines&&this.driver.setLineCount(this.current.lineCount)}onBufferCursor(){this.fromNative||this.mirroring||this.driver.setSelection(this.current.selectionBoundPosition,this.current.cursorPosition)}onNativeEdit(e,t,n){if(!this.mirroring){this.fromNative=!0,this.current.begin_user_action();try{this.current.replace(e,e+t,n)}finally{this.fromNative=!1,this.current.end_user_action()}if(this.props.autoIndent&&n===`
|
|
2
|
+
`){let t=leadingWhitespace(this.current.getLine(this.current.lineOfOffset(e)));t!==``&&(this.current.insert(e+1,t),this.driver.setSelection(this.current.cursorPosition,this.current.cursorPosition))}}}onNativeSelection(e,t){if(this.mirroring)return;let clamp=e=>Math.min(Math.max(0,e),this.current.length);this.fromNative=!0;try{this.current.selectRange(clamp(t),clamp(e))}finally{this.fromNative=!1}}setProp(e,t,n){this.props[e]!==t&&(this.props[e]=t,this.emit(`notify::${n}`),this.pushLayout())}pushLayout(){let{props:e}=this;this.driver.setLayout({showLineNumbers:e.showLineNumbers,monospace:e.monospace,editable:e.editable,highlightCurrentLine:e.highlightCurrentLine,cursorVisible:e.cursorVisible,leftMargin:e.leftMargin,rightMargin:e.rightMargin,topMargin:e.topMargin,bottomMargin:e.bottomMargin})}get autoIndent(){return this.props.autoIndent}set autoIndent(e){this.setProp(`autoIndent`,e,`auto-indent`)}get indentWidth(){return this.props.indentWidth}set indentWidth(e){this.setProp(`indentWidth`,e,`indent-width`)}get showLineNumbers(){return this.props.showLineNumbers}set showLineNumbers(e){this.setProp(`showLineNumbers`,e,`show-line-numbers`)}get monospace(){return this.props.monospace}set monospace(e){this.setProp(`monospace`,e,`monospace`)}get editable(){return this.props.editable}set editable(e){this.setProp(`editable`,e,`editable`)}get highlightCurrentLine(){return this.props.highlightCurrentLine}set highlightCurrentLine(e){this.setProp(`highlightCurrentLine`,e,`highlight-current-line`)}get cursorVisible(){return this.props.cursorVisible}set cursorVisible(e){this.setProp(`cursorVisible`,e,`cursor-visible`)}get leftMargin(){return this.props.leftMargin}set leftMargin(e){this.setProp(`leftMargin`,e,`left-margin`)}get rightMargin(){return this.props.rightMargin}set rightMargin(e){this.setProp(`rightMargin`,e,`right-margin`)}get topMargin(){return this.props.topMargin}set topMargin(e){this.setProp(`topMargin`,e,`top-margin`)}get bottomMargin(){return this.props.bottomMargin}set bottomMargin(e){this.setProp(`bottomMargin`,e,`bottom-margin`)}setColorScheme(e){this.variant=e,this.controller.setColorScheme(e)}dispose(){for(let e of this.bufferHandlers.splice(0))this.current.disconnect(e);this.controller.dispose()}};export{EditorSession,leadingWhitespace};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const scheme=(e,t,n)=>`<?xml version="1.0" encoding="UTF-8"?>\n<style-scheme id="${e}" name="${t}" version="1.0">\n${Object.entries(n).map(([e,t])=>` <style name="${e}" ${t}/>`).join(`
|
|
2
|
+
`)}\n</style-scheme>\n`,e=`Adwaita`,t=`Adwaita-dark`,n=scheme(e,`Adwaita (gjsify fallback)`,{text:`foreground="#2e3436" background="#ffffff"`,selection:`background="#a8c8f0"`,cursor:`foreground="#2e3436"`,"current-line":`background="#f0f0f0"`,"line-numbers":`foreground="#8a8f92" background="#f6f5f4"`,"current-line-number":`foreground="#2e3436" background="#f0f0f0"`,"def:comment":`foreground="#77767b" italic="true"`,"def:shebang":`foreground="#77767b" italic="true"`,"def:doc-comment-element":`foreground="#77767b" italic="true"`,"def:keyword":`foreground="#a51d2d" bold="true"`,"def:statement":`foreground="#a51d2d" bold="true"`,"def:preprocessor":`foreground="#813d9c"`,"def:type":`foreground="#1a5fb4"`,"def:builtin":`foreground="#1a5fb4"`,"def:function":`foreground="#1a5fb4"`,"def:identifier":`foreground="#1a5fb4"`,"def:constant":`foreground="#26a269"`,"def:number":`foreground="#26a269"`,"def:decimal":`foreground="#26a269"`,"def:base-n-integer":`foreground="#26a269"`,"def:floating-point":`foreground="#26a269"`,"def:boolean":`foreground="#26a269"`,"def:string":`foreground="#c64600"`,"def:character":`foreground="#c64600"`,"def:special-char":`foreground="#c64600" bold="true"`,"def:special-constant":`foreground="#c64600"`,"def:operator":`foreground="#5e5c64"`,"def:error":`foreground="#c01c28" underline="error"`,"def:note":`foreground="#813d9c" bold="true"`}),r=scheme(t,`Adwaita Dark (gjsify fallback)`,{text:`foreground="#ebebeb" background="#1e1e1e"`,selection:`background="#35516e"`,cursor:`foreground="#ebebeb"`,"current-line":`background="#2a2a2a"`,"line-numbers":`foreground="#8a8a8a" background="#242424"`,"current-line-number":`foreground="#ebebeb" background="#2a2a2a"`,"def:comment":`foreground="#9a9996" italic="true"`,"def:shebang":`foreground="#9a9996" italic="true"`,"def:doc-comment-element":`foreground="#9a9996" italic="true"`,"def:keyword":`foreground="#ff7b63" bold="true"`,"def:statement":`foreground="#ff7b63" bold="true"`,"def:preprocessor":`foreground="#dc8add"`,"def:type":`foreground="#78aeed"`,"def:builtin":`foreground="#78aeed"`,"def:function":`foreground="#78aeed"`,"def:identifier":`foreground="#78aeed"`,"def:constant":`foreground="#8ff0a4"`,"def:number":`foreground="#8ff0a4"`,"def:decimal":`foreground="#8ff0a4"`,"def:base-n-integer":`foreground="#8ff0a4"`,"def:floating-point":`foreground="#8ff0a4"`,"def:boolean":`foreground="#8ff0a4"`,"def:string":`foreground="#ffbe6f"`,"def:character":`foreground="#ffbe6f"`,"def:special-char":`foreground="#ffbe6f" bold="true"`,"def:special-constant":`foreground="#ffbe6f"`,"def:operator":`foreground="#c0bfbc"`,"def:error":`foreground="#ff7b63" underline="error"`,"def:note":`foreground="#dc8add" bold="true"`});export{t as FALLBACK_DARK_ID,e as FALLBACK_LIGHT_ID,r as fallbackDarkScheme,n as fallbackLightScheme};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function digitCount(e,t=2){return Math.max(t,String(Math.max(1,e)).length)}function gutterWidth(e,t,n,r=2){return Math.ceil(digitCount(e,r)*t+2*n)}function visibleLines(e,t,n,r,i){if(e<=0)return null;let a=0,o=e-1;for(;a<o;){let e=a+o>>1;n(e)<=r?a=e+1:o=e}let s=a;if(t(s)>=i||n(s)<=r)return null;for(a=s,o=e-1;a<o;){let e=a+o+1>>1;t(e)<i?a=e:o=e-1}return{first:s,last:a}}function emphasisedLine(e,t){return e?t:-1}export{digitCount,emphasisedLine,gutterWidth,visibleLines};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{IncrementalHighlighter as e}from"./highlighter.js";import{StyleSchemeManager as t,paletteOf as n}from"./style-scheme.js";import{TokenStyler as r}from"./token-styler.js";var HighlightController=class{constructor(e,n,r=t.getDefault(),i=`light`){this.buffer=e,this.sink=n,this.schemes=r,this.highlighter=null,this.styler=null,this.handlers=[],this.variant=i,this.handlers.push(e.connect(`changed`,(e,t)=>this.onChanged(t)),e.connect(`notify::language`,()=>this.rebuild()),e.connect(`notify::style-scheme`,()=>this.rebuild()),e.connect(`notify::highlight-syntax`,()=>this.rebuild())),this.rebuild()}get scheme(){let e=this.buffer.styleScheme;return e?this.schemes.variantOf(e,this.variant):this.schemes.getDefaultFor(this.variant)}setColorScheme(e){e!==this.variant&&(this.variant=e,this.rebuild(!1))}dispose(){for(let e of this.handlers.splice(0))this.buffer.disconnect(e)}rebuild(t=!0){let i=this.scheme,a=this.buffer.language;if(i&&this.sink.setPalette(n(i,this.variant)),!a||!i||!this.buffer.highlightSyntax){this.highlighter=null,this.styler=null,this.sink.clearAll();return}(t||!this.highlighter||this.highlighter.tokenizer!==a.tokenizer)&&(this.highlighter=new e(a.tokenizer),this.highlighter.reset(this.buffer.getLines())),this.styler=new r(a.definition,i),this.paint(0,this.buffer.lineCount-1)}onChanged(e){if(this.sink.spliceLines(e.firstLine,e.removedLines,e.insertedLines),!this.highlighter)return;let t=this.highlighter.update(this.buffer.getLines(),{first:e.firstLine,removed:e.removedLines,inserted:e.insertedLines});this.paint(t.first,t.last)}paint(e,t){let{highlighter:n,styler:r}=this;if(!(!n||!r))for(let i=e;i<=t;i++)this.sink.paintLine(i,this.buffer.offsetOfLine(i),r.runsOf(n.tokensOf(i)))}};export{HighlightController};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{INITIAL_STATE as e}from"./tokenizer.js";function sameState(e,t){return e.stack.length===t.stack.length?e.stack.every((e,n)=>e===t.stack[n]):!1}var IncrementalHighlighter=class{constructor(e){this.tokenizer=e,this.results=[]}get lineCount(){return this.results.length}tokensOf(e){let t=this.results[e];if(!t)throw RangeError(`IncrementalHighlighter: line ${e} is outside 0..${this.results.length-1}`);return t.tokens}reset(t){this.results=[];let n=e;for(let e of t){let t=this.tokenizer.tokenize(e,n);this.results.push(t),n=t.state}return t.length===0?null:{first:0,last:t.length-1}}update(t,n){let{first:r,removed:i,inserted:a}=n;if(r<0||i<1||a<1||r+i>this.results.length)throw RangeError(`IncrementalHighlighter: edit ${JSON.stringify(n)} does not fit ${this.results.length} lines`);if(t.length!==this.results.length-i+a)throw RangeError(`IncrementalHighlighter: ${t.length} lines do not match the edit`);let o=this.results[r+i-1].state,s=Array.from({length:a},()=>void 0);this.results.splice(r,i,...s);let c=r,l=r===0?e:this.results[r-1].state;for(;c<r+a;c++){let e=this.tokenizer.tokenize(t[c],l);this.results[c]=e,l=e.state}let u=r+a-1;for(;!sameState(l,o)&&c<t.length;){o=this.results[c].state;let e=this.tokenizer.tokenize(t[c],l);this.results[c]=e,l=e.state,u=c,c++}return{first:r,last:u}}};export{IncrementalHighlighter,sameState};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./
|
|
1
|
+
import{SignalEmitter as e}from"./signals.js";import{TextIter as t,TextMark as n}from"./text-iter.js";import{Buffer as r}from"./buffer.js";import{toBoolean as i,toNumber as a}from"./coerce.js";import{parseColor as o}from"./color.js";import"./editor-driver.js";import{UnsupportedRegexError as s,translateRegex as c}from"./regex.js";import{XmlParseError as l,childElements as u,decodeEntities as d,parseXml as f,textContent as p}from"./xml.js";import{keywordPattern as m,parseLanguage as h}from"./lang.js";import{INITIAL_STATE as g,Tokenizer as _,schemeStyleName as v}from"./tokenizer.js";import{IncrementalHighlighter as y,sameState as b}from"./highlighter.js";import{parseStyleScheme as x,resolveStyle as S}from"./style.js";import{FALLBACK_DARK_ID as C,FALLBACK_LIGHT_ID as w,fallbackDarkScheme as T,fallbackLightScheme as E}from"./fallback-schemes.js";import{StyleScheme as D,StyleSchemeManager as O,paletteOf as k}from"./style-scheme.js";import{TokenStyler as A}from"./token-styler.js";import{HighlightController as j}from"./highlight-controller.js";import{EditorSession as M,leadingWhitespace as N}from"./editor-session.js";import{digitCount as P,emphasisedLine as F,gutterWidth as I,visibleLines as L}from"./gutter.js";import"./types.js";import{Language as R,LanguageManager as z}from"./language-manager.js";import{LineStore as B}from"./line-store.js";import{init as V}from"./init.js";export{r as Buffer,r as GtkSourceBuffer,M as EditorSession,C as FALLBACK_DARK_ID,w as FALLBACK_LIGHT_ID,j as HighlightController,g as INITIAL_STATE,y as IncrementalHighlighter,R as Language,z as LanguageManager,B as LineStore,e as SignalEmitter,D as StyleScheme,O as StyleSchemeManager,t as TextIter,n as TextMark,A as TokenStyler,_ as Tokenizer,s as UnsupportedRegexError,l as XmlParseError,u as childElements,d as decodeEntities,P as digitCount,F as emphasisedLine,T as fallbackDarkScheme,E as fallbackLightScheme,I as gutterWidth,V as init,m as keywordPattern,N as leadingWhitespace,k as paletteOf,o as parseColor,h as parseLanguage,x as parseStyleScheme,f as parseXml,S as resolveStyle,b as sameState,v as schemeStyleName,p as textContent,i as toBoolean,a as toNumber,c as translateRegex,L as visibleLines};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[{rule:`init is a function on the namespace`,observe:e=>typeof e.init,shows:`function`},{rule:`init() returns undefined`,observe:e=>e.init(),shows:void 0},{rule:`a second init() is harmless and also returns undefined`,observe:e=>(e.init(),e.init()),shows:void 0}];export{e as GTKSOURCE_INIT_VECTORS};
|
package/lib/esm/init.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function init(){}export{init};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parseLanguage as e}from"./lang.js";import{Tokenizer as t}from"./tokenizer.js";const splitList=e=>(e??``).split(`;`).map(e=>e.trim()).filter(e=>e!==``);function globMatches(e,t){let n=e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`).replace(/\?/g,`.`);return RegExp(`^${n}$`).test(t)}var Language=class{constructor(e){this.definition=e}get id(){return this.definition.id}get name(){return this.definition.name??this.definition.id}get section(){return this.definition.section??`Others`}get globs(){return splitList(this.definition.metadata.globs)}get mimeTypes(){return splitList(this.definition.metadata.mimetypes)}get tokenizer(){return this.cached??=new t(this.definition)}},n=class LanguageManager{constructor(){this.languages=new Map}static getDefault(){return LanguageManager.instance??=new LanguageManager}static get_default(){return LanguageManager.getDefault()}get languageIds(){return[...this.languages.keys()].sort()}addLanguageFromXml(t,n={}){let r=new Language(e(t,n));return this.languages.set(r.id,r),r}getLanguage(e){return this.languages.get(e)??null}get_language(e){return this.getLanguage(e)}guessLanguage(e,t){let n=[...this.languages.values()].sort((e,t)=>e.id.localeCompare(t.id));if(e!==null){let t=e.slice(Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))+1),r=n.find(e=>e.globs.some(e=>globMatches(e,t)));if(r)return r}return t===null?null:n.find(e=>e.mimeTypes.includes(t))??null}};export{Language,n as LanguageManager};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";var LineStore=class{constructor(){this.slots=[]}get(e){return this.slots[e]}set(e,t){for(;this.slots.length<=e;)this.slots.push(void 0);this.slots[e]=t}splice(e,t,n){for(;this.slots.length<e+t;)this.slots.push(void 0);return this.slots.splice(e,t,...Array.from({length:n},()=>void 0)).filter(e=>e!==void 0)}clear(){let e=this.slots.filter(e=>e!==void 0);return this.slots=[],e}};export{LineStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[{rule:`LanguageManager.get_default() is one instance`,observe:e=>e.LanguageManager.get_default()===e.LanguageManager.get_default(),shows:!0},{rule:`get_language of an id nothing registered is null`,observe:e=>e.LanguageManager.get_default().get_language(`no-such-language`),shows:null},{rule:`StyleSchemeManager.get_default() is one instance`,observe:e=>e.StyleSchemeManager.get_default()===e.StyleSchemeManager.get_default(),shows:!0},{rule:`get_scheme of an id nothing registered is null`,observe:e=>e.StyleSchemeManager.get_default().get_scheme(`no-such-scheme`),shows:null},{rule:`the stock Adwaita scheme is there and answers to its id`,observe:e=>e.StyleSchemeManager.get_default().get_scheme(`Adwaita`)?.id,shows:`Adwaita`},{rule:`a new Buffer holds the empty text`,observe:e=>new e.Buffer().text,shows:``},{rule:`a new Buffer has no language`,observe:e=>new e.Buffer().language,shows:null},{rule:`a Buffer built with a text property reads it back`,observe:e=>new e.Buffer({text:`LDA #$01`}).text,shows:`LDA #$01`}];export{e as GTKSOURCE_MANAGER_VECTORS};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";let e=1;var SignalEmitter=class{constructor(){this.handlers=new Map}connect(e,t){return this.add(e,t,!1)}connect_after(e,t){return this.add(e,t,!0)}checkSignal(e){}add(t,n,r){this.checkSignal(t);let i=e++;return this.handlers.set(i,{name:t,callback:n,after:r}),i}disconnect(e){if(!this.handlers.delete(e))throw Error(`No signal handler with id ${e} on this object`)}emit(e,...t){let n=Array.from(this.handlers.values()).filter(t=>t.name===e);for(let e of[!1,!0])for(let r of n)r.after===e&&r.callback(this,...t)}};export{SignalEmitter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parseColor as e}from"./color.js";import{parseStyleScheme as t,resolveStyle as n}from"./style.js";import{FALLBACK_DARK_ID as r,FALLBACK_LIGHT_ID as i,fallbackDarkScheme as a,fallbackLightScheme as o}from"./fallback-schemes.js";var StyleScheme=class{constructor(e,t){this.definition=e,this.lookup=t}get id(){return this.definition.id}get name(){return this.definition.name??this.definition.id}get parentId(){return this.definition.parentScheme}getStyle(e){return n(this.definition,e,this.lookup)}};const s={foreground:-13749194,background:-1,selection:-5715728,lineNumber:-7696494},c={foreground:-1315861,background:-14803426,selection:-13282962,lineNumber:-7697782};function paletteOf(t,n){let r=n===`dark`?c:s,color=t=>t===void 0?void 0:e(t),i=t.getStyle(`text`),a=t.getStyle(`selection`),o=t.getStyle(`current-line`),l=t.getStyle(`line-numbers`),u=t.getStyle(`current-line-number`),d=color(i?.foreground)??r.foreground,f=color(i?.background)??r.background,p=color(l?.foreground)??r.lineNumber,m=color(l?.background)??f,h=color(o?.background)??0;return{dark:n===`dark`,foreground:d,background:f,selectionBackground:color(a?.background)??r.selection,currentLineBackground:h,lineNumberForeground:p,lineNumberBackground:m,currentLineNumberForeground:color(u?.foreground)??d,currentLineNumberBackground:color(u?.background)??h}}var l=class StyleSchemeManager{static getDefault(){return StyleSchemeManager.instance??=new StyleSchemeManager}static get_default(){return StyleSchemeManager.getDefault()}constructor(e=!0){if(this.definitions=new Map,this.fallbacks=new Set,e)for(let e of[o,a]){let n=t(e);this.definitions.set(n.id,n),this.fallbacks.add(n.id)}}get schemeIds(){return[...this.definitions.keys()].sort()}isFallback(e){return this.fallbacks.has(e)}addScheme(e){return this.definitions.set(e.id,e),this.fallbacks.delete(e.id),this.wrap(e)}addSchemeFromXml(e){return this.addScheme(t(e))}getScheme(e){let t=this.definitions.get(e);return t?this.wrap(t):null}get_scheme(e){return this.getScheme(e)}getDefaultFor(e){return this.getScheme(e===`dark`?r:i)}variantOf(e,t){let n=e.id.endsWith(`-dark`);if(n===(t===`dark`))return e;let r=n?e.id.slice(0,-5):`${e.id}-dark`;return this.getScheme(r)??e}wrap(e){return new StyleScheme(e,e=>this.definitions.get(e))}};export{StyleScheme,l as StyleSchemeManager,paletteOf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";var TextIter=class{constructor(e,t){this.source=e,this.offset=t}get utf16Offset(){return this.offset}get_offset(){let e=0,t=this.source.getText(0,this.offset);for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<t.length){let e=t.charCodeAt(n+1);e>=56320&&e<=57343&&n++}e++}return e}set_offset(e){if(!Number.isInteger(e))throw TypeError(`TextIter.set_offset: ${e} is not an integer`);let t=this.source.getText(),n=0;for(let r=0;e>=0&&r<e&&n<t.length;r++)n+=t.codePointAt(n)>65535?2:1;this.offset=e<0||n>=t.length?this.source.length:n}},TextMark=class{constructor(e){this.name=e}};export{TextIter,TextMark};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{parseColor as e}from"./color.js";import{schemeStyleName as t}from"./tokenizer.js";var TokenStyler=class{constructor(e,t){this.language=e,this.scheme=t,this.cache=new Map}styleFor(n){if(this.cache.has(n))return this.cache.get(n);let r=this.scheme.getStyle(t(this.language,n)),i;if(r){let t=r.foreground===void 0?void 0:e(r.foreground),n=r.background===void 0?void 0:e(r.background),a=r.underline!==void 0&&r.underline!==`none`,o=r.bold===!0,s=r.italic===!0,c=r.strikethrough===!0;(t!==void 0||n!==void 0||o||s||a||c)&&(i={foreground:t,background:n,bold:o,italic:s,underline:a,strikethrough:c})}return this.cache.set(n,i),i}runsOf(e){let t=[];for(let n of e){let e=this.styleFor(n.style);e&&n.end>n.start&&t.push({start:n.start,end:n.end,style:e})}return t}};export{TokenStyler};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e=[{property:`auto-indent`,member:`autoIndent`,shows:!1},{property:`indent-width`,member:`indentWidth`,shows:-1},{property:`show-line-numbers`,member:`showLineNumbers`,shows:!1},{property:`highlight-current-line`,member:`highlightCurrentLine`,shows:!1},{property:`monospace`,member:`monospace`,shows:!1},{property:`editable`,member:`editable`,shows:!0},{property:`cursor-visible`,member:`cursorVisible`,shows:!0},{property:`left-margin`,member:`leftMargin`,shows:0},{property:`right-margin`,member:`rightMargin`,shows:0},{property:`top-margin`,member:`topMargin`,shows:0},{property:`bottom-margin`,member:`bottomMargin`,shows:0}],pick=(e,t)=>Object.fromEntries(t.map(t=>[t,e[t]])),t=[{rule:`Gtk.TextWindowType carries the typelib numbers`,instance:!1,observe:({Gtk:e})=>pick(e.TextWindowType,[`WIDGET`,`TEXT`,`LEFT`,`RIGHT`,`TOP`]),shows:{WIDGET:1,TEXT:2,LEFT:3,RIGHT:4,TOP:5}},{rule:`Gtk.PolicyType carries the typelib numbers`,instance:!1,observe:({Gtk:e})=>pick(e.PolicyType,[`ALWAYS`,`AUTOMATIC`,`NEVER`,`EXTERNAL`]),shows:{ALWAYS:0,AUTOMATIC:1,NEVER:2,EXTERNAL:3}},{rule:`Gtk.TextDirection carries the typelib numbers`,instance:!1,observe:({Gtk:e})=>pick(e.TextDirection,[`NONE`,`LTR`,`RTL`]),shows:{NONE:0,LTR:1,RTL:2}},{rule:`cursor_visible is true by default and the property and accessors agree`,instance:!0,observe:({GtkSource:e})=>{let t=new e.View,n=[t.cursor_visible,t.get_cursor_visible()];t.cursor_visible=!1;let r=[t.cursor_visible,t.get_cursor_visible()];return t.set_cursor_visible(!0),[n,r,[t.cursor_visible,t.get_cursor_visible()]]},shows:[[!0,!0],[!1,!1],[!0,!0]]},{rule:`set_editable and the editable property agree`,instance:!0,observe:({GtkSource:e})=>{let t=new e.View;t.set_editable(!1);let n=[t.editable,t.get_editable()];return t.editable=!0,[n,[t.editable,t.get_editable()]]},shows:[[!1,!1],[!0,!0]]},{rule:`highlight_current_line and show_line_numbers are plain boolean properties`,instance:!0,observe:({GtkSource:e})=>{let t=new e.View,n=[t.highlight_current_line,t.show_line_numbers];return t.highlight_current_line=!0,t.show_line_numbers=!0,[n,[t.highlight_current_line,t.show_line_numbers]]},shows:[[!1,!1],[!0,!0]]},{rule:`vadjustment and hadjustment are two stable, distinct adjustments`,instance:!0,observe:({GtkSource:e})=>{let t=new e.View;return[t.vadjustment===t.get_vadjustment(),t.vadjustment===t.hadjustment,t.vadjustment.get_value()]},shows:[!0,!1,0]},{rule:`direction is LTR by default and set_direction is read back`,instance:!0,observe:({Gtk:e,GtkSource:t})=>{let n=new t.View,r=n.get_direction();return n.set_direction(e.TextDirection.RTL),[r,n.get_direction()]},shows:[1,2]},{rule:`a fresh view has no sibling and no parent`,instance:!0,observe:({GtkSource:e})=>{let t=new e.View;return[t.get_next_sibling(),t.get_parent()]},shows:[null,null]},{rule:`a scrolled window starts AUTOMATIC on both axes and set_policy is read back`,instance:!1,observe:({Gtk:e})=>{let t=new e.ScrolledWindow,n=t.get_policy();return t.set_policy(e.PolicyType.NEVER,e.PolicyType.ALWAYS),[n,t.get_policy()]},shows:[[1,1],[2,0]]},{rule:`set_policy refuses a value that is not a Gtk.PolicyType`,instance:!1,observe:({Gtk:e})=>{let t=new e.ScrolledWindow;try{return t.set_policy(7,1),`accepted`}catch{return`threw`}},shows:`threw`},{rule:`a scrolled window adopts the view adjustment it is given`,instance:!0,observe:({Gtk:e,GtkSource:t})=>{let n=new t.View,r=new e.ScrolledWindow;return r.set_vadjustment(n.vadjustment),[r.get_vadjustment()===n.vadjustment,r.vadjustment===n.vadjustment]},shows:[!0,!0]}];export{e as GTKSOURCE_VIEW_DEFAULT_VECTORS,t as GTKSOURCE_VIEW_SURFACE_VECTORS};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface IterLike {
|
|
2
|
+
get_offset(): number;
|
|
3
|
+
set_offset(offset: number): void;
|
|
4
|
+
}
|
|
5
|
+
interface MarkLike {
|
|
6
|
+
readonly name: string | null;
|
|
7
|
+
}
|
|
8
|
+
/** The part of a `GtkSource.Buffer` the vectors read. */
|
|
9
|
+
export interface BufferLike {
|
|
10
|
+
text: string;
|
|
11
|
+
readonly language: unknown;
|
|
12
|
+
readonly cursor_position: number;
|
|
13
|
+
readonly can_undo: boolean;
|
|
14
|
+
readonly can_redo: boolean;
|
|
15
|
+
get_start_iter(): IterLike;
|
|
16
|
+
get_end_iter(): IterLike;
|
|
17
|
+
get_insert(): MarkLike;
|
|
18
|
+
get_selection_bound(): MarkLike;
|
|
19
|
+
get_selection_bounds(): [boolean, IterLike, IterLike];
|
|
20
|
+
get_text(start: IterLike, end: IterLike, includeHidden: boolean): string;
|
|
21
|
+
move_mark(mark: MarkLike, where: IterLike): void;
|
|
22
|
+
insert_at_cursor(text: string, len: number): void;
|
|
23
|
+
delete(start: IterLike, end: IterLike): void;
|
|
24
|
+
begin_user_action(): void;
|
|
25
|
+
end_user_action(): void;
|
|
26
|
+
undo(): void;
|
|
27
|
+
redo(): void;
|
|
28
|
+
set_language(language: null): void;
|
|
29
|
+
connect(name: string, callback: (...args: never[]) => void): number;
|
|
30
|
+
connect_after(name: string, callback: (...args: never[]) => void): number;
|
|
31
|
+
}
|
|
32
|
+
/** The part of `GtkSource` the vectors read. */
|
|
33
|
+
export interface GtkSourceBufferLike {
|
|
34
|
+
Buffer: new (properties?: any) => BufferLike;
|
|
35
|
+
}
|
|
36
|
+
export interface GtkSourceBufferVector {
|
|
37
|
+
readonly rule: string;
|
|
38
|
+
readonly observe: (GtkSource: GtkSourceBufferLike) => unknown;
|
|
39
|
+
readonly shows: unknown;
|
|
40
|
+
}
|
|
41
|
+
export declare const GTKSOURCE_BUFFER_VECTORS: readonly GtkSourceBufferVector[];
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Language } from './language-manager.js';
|
|
2
|
+
import { SignalEmitter } from './signals.js';
|
|
3
|
+
import type { StyleScheme } from './style-scheme.js';
|
|
4
|
+
import { TextIter, TextMark } from './text-iter.js';
|
|
5
|
+
/** What `changed` carries: one contiguous replacement. */
|
|
6
|
+
export interface TextEdit {
|
|
7
|
+
readonly start: number;
|
|
8
|
+
readonly removedText: string;
|
|
9
|
+
readonly insertedText: string;
|
|
10
|
+
/** The lines `[firstLine, firstLine + removedLines)` of the old text became `insertedLines` lines. */
|
|
11
|
+
readonly firstLine: number;
|
|
12
|
+
readonly removedLines: number;
|
|
13
|
+
readonly insertedLines: number;
|
|
14
|
+
}
|
|
15
|
+
/** What a `.blp` may construct a buffer with: `buffer: GtkSource.Buffer { text: "…"; }`. */
|
|
16
|
+
export interface BufferProps {
|
|
17
|
+
text?: string;
|
|
18
|
+
highlightSyntax?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class GtkSourceBuffer extends SignalEmitter {
|
|
21
|
+
private lines;
|
|
22
|
+
/** `lineStarts[i]` is the offset of line `i`; valid for `i < startsValidTo`. */
|
|
23
|
+
private lineStarts;
|
|
24
|
+
private startsValidTo;
|
|
25
|
+
private cursor;
|
|
26
|
+
private bound;
|
|
27
|
+
private readonly insertMark;
|
|
28
|
+
private readonly boundMark;
|
|
29
|
+
private undoStack;
|
|
30
|
+
private redoStack;
|
|
31
|
+
private open;
|
|
32
|
+
private depth;
|
|
33
|
+
private recording;
|
|
34
|
+
private reportedUndo;
|
|
35
|
+
private reportedRedo;
|
|
36
|
+
private lang;
|
|
37
|
+
private scheme;
|
|
38
|
+
private highlight;
|
|
39
|
+
constructor(init?: string | BufferProps);
|
|
40
|
+
get text(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Replaces everything. Like `gtk_text_buffer_set_text` — a delete and an insert — the
|
|
43
|
+
* insert mark ends after the new text, so the cursor lands at the end.
|
|
44
|
+
*/
|
|
45
|
+
set text(value: string);
|
|
46
|
+
get length(): number;
|
|
47
|
+
get lineCount(): number;
|
|
48
|
+
/** Line `index` without its terminator. */
|
|
49
|
+
getLine(index: number): string;
|
|
50
|
+
/** A copy of every line. */
|
|
51
|
+
getLines(): string[];
|
|
52
|
+
offsetOfLine(index: number): number;
|
|
53
|
+
lineOfOffset(offset: number): number;
|
|
54
|
+
getText(start?: number, end?: number): string;
|
|
55
|
+
insert(offset: number, text: string): void;
|
|
56
|
+
/** Offsets in UTF-16 units, or the two `TextIter`s of `gtk_text_buffer_delete` (any order). */
|
|
57
|
+
delete(start: number | TextIter, end: number | TextIter): void;
|
|
58
|
+
/** The one mutation every other one goes through. An edit that changes nothing emits nothing. */
|
|
59
|
+
replace(start: number, end: number, text: string): void;
|
|
60
|
+
/** `GtkTextBuffer:cursor-position`. */
|
|
61
|
+
get cursorPosition(): number;
|
|
62
|
+
/** The GJS spelling of `GtkTextBuffer:cursor-position`, in characters like `TextIter.get_offset`. */
|
|
63
|
+
get cursor_position(): number;
|
|
64
|
+
/** Where `selection_bound` is; equal to `cursorPosition` when nothing is selected. */
|
|
65
|
+
get selectionBoundPosition(): number;
|
|
66
|
+
/** Moves both marks like `gtk_text_buffer_select_range`; a mark already there is left alone. */
|
|
67
|
+
selectRange(cursor: number, bound: number): void;
|
|
68
|
+
/** Collapses the selection onto `offset`. */
|
|
69
|
+
placeCursor(offset: number): void;
|
|
70
|
+
private moveInsert;
|
|
71
|
+
private moveBound;
|
|
72
|
+
get_insert(): TextMark;
|
|
73
|
+
get_selection_bound(): TextMark;
|
|
74
|
+
get_start_iter(): TextIter;
|
|
75
|
+
get_end_iter(): TextIter;
|
|
76
|
+
/** `[has_selection, start, end]`, start before end whichever mark is which. */
|
|
77
|
+
get_selection_bounds(): [boolean, TextIter, TextIter];
|
|
78
|
+
/** The buffer has no tags, so no text is hidden and `include_hidden` changes nothing. */
|
|
79
|
+
get_text(start: TextIter, end: TextIter, _includeHidden: boolean): string;
|
|
80
|
+
move_mark(mark: TextMark, where: TextIter): void;
|
|
81
|
+
/** Only `len` -1 (the whole string): GTK counts bytes there, and nothing here needs a prefix. */
|
|
82
|
+
insert_at_cursor(text: string, len: number): void;
|
|
83
|
+
set_language(language: Language | null): void;
|
|
84
|
+
set_style_scheme(scheme: StyleScheme | null): void;
|
|
85
|
+
/** Edits between the outermost begin and its end are one undo step. */
|
|
86
|
+
begin_user_action(): void;
|
|
87
|
+
end_user_action(): void;
|
|
88
|
+
get can_undo(): boolean;
|
|
89
|
+
get can_redo(): boolean;
|
|
90
|
+
undo(): void;
|
|
91
|
+
redo(): void;
|
|
92
|
+
private applyHistory;
|
|
93
|
+
private record;
|
|
94
|
+
private push;
|
|
95
|
+
private syncUndoState;
|
|
96
|
+
protected checkSignal(name: string): void;
|
|
97
|
+
private ownIter;
|
|
98
|
+
/** `GtkSource.Buffer:language` — what to highlight with; `null` highlights nothing. */
|
|
99
|
+
get language(): Language | null;
|
|
100
|
+
set language(value: Language | null);
|
|
101
|
+
/** `GtkSource.Buffer:style-scheme`; `null` lets the view pick one for the light/dark mode. */
|
|
102
|
+
get styleScheme(): StyleScheme | null;
|
|
103
|
+
set styleScheme(value: StyleScheme | null);
|
|
104
|
+
/** `GtkSource.Buffer:highlight-syntax`, on by default. */
|
|
105
|
+
get highlightSyntax(): boolean;
|
|
106
|
+
set highlightSyntax(value: boolean);
|
|
107
|
+
private checkOffset;
|
|
108
|
+
}
|
|
109
|
+
export { GtkSourceBuffer as Buffer };
|
|
110
|
+
export { TextIter, TextMark } from './text-iter.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `#rgb`, `#rrggbb` and `#rrggbbaa` (CSS puts the alpha LAST: Learn6502's `#00000018` is a
|
|
3
|
+
* barely-there black). Anything else — named colours, `rgb()` — is `undefined`; a scheme
|
|
4
|
+
* that uses them loses that colour rather than crashing the editor.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseColor(value: string): number | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { EditorPalette } from './style-scheme.js';
|
|
2
|
+
import type { StyledRun } from './token-styler.js';
|
|
3
|
+
/** What the driver reports back. Offsets are UTF-16 code units, valid AFTER the edit. */
|
|
4
|
+
export interface EditorHost {
|
|
5
|
+
/** The user replaced `removedLength` characters at `start` with `inserted`. */
|
|
6
|
+
onNativeEdit(start: number, removedLength: number, inserted: string): void;
|
|
7
|
+
onNativeSelection(start: number, end: number): void;
|
|
8
|
+
}
|
|
9
|
+
export interface EditorLayout {
|
|
10
|
+
readonly showLineNumbers: boolean;
|
|
11
|
+
readonly monospace: boolean;
|
|
12
|
+
readonly editable: boolean;
|
|
13
|
+
readonly highlightCurrentLine: boolean;
|
|
14
|
+
/** `GtkTextView:cursor-visible`: whether the insertion cursor is drawn. */
|
|
15
|
+
readonly cursorVisible: boolean;
|
|
16
|
+
/** The `left-margin` … `bottom-margin` of `Gtk.TextView`, in device-independent pixels. */
|
|
17
|
+
readonly leftMargin: number;
|
|
18
|
+
readonly rightMargin: number;
|
|
19
|
+
readonly topMargin: number;
|
|
20
|
+
readonly bottomMargin: number;
|
|
21
|
+
}
|
|
22
|
+
/** Where highlighted runs go. Spans live on the text, so they follow lines through edits. */
|
|
23
|
+
export interface HighlightSink {
|
|
24
|
+
/** Lines `[first, first + removed)` were replaced by `inserted` lines; drop what they carried. */
|
|
25
|
+
spliceLines(first: number, removed: number, inserted: number): void;
|
|
26
|
+
/** Replace everything painted on `line` (which starts at `lineStart`) with `runs`. */
|
|
27
|
+
paintLine(line: number, lineStart: number, runs: readonly StyledRun[]): void;
|
|
28
|
+
clearAll(): void;
|
|
29
|
+
setPalette(palette: EditorPalette): void;
|
|
30
|
+
}
|
|
31
|
+
export interface EditorDriver extends HighlightSink {
|
|
32
|
+
bind(host: EditorHost): void;
|
|
33
|
+
/** Replaces the whole text and forgets every span: the buffer was swapped. */
|
|
34
|
+
setText(text: string): void;
|
|
35
|
+
/** Mirrors a programmatic edit into the widget's text. */
|
|
36
|
+
replaceRange(start: number, end: number, text: string): void;
|
|
37
|
+
setSelection(start: number, end: number): void;
|
|
38
|
+
setLineCount(count: number): void;
|
|
39
|
+
setLayout(layout: EditorLayout): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Buffer } from './buffer.js';
|
|
2
|
+
import type { EditorDriver, EditorHost } from './editor-driver.js';
|
|
3
|
+
import { StyleSchemeManager } from './style-scheme.js';
|
|
4
|
+
import type { ColorSchemeVariant } from './style-scheme.js';
|
|
5
|
+
import { SignalEmitter } from './signals.js';
|
|
6
|
+
/** The leading blanks of `line`: what `auto-indent` carries onto the next line. */
|
|
7
|
+
export declare function leadingWhitespace(line: string): string;
|
|
8
|
+
export declare class EditorSession extends SignalEmitter implements EditorHost {
|
|
9
|
+
private readonly driver;
|
|
10
|
+
private readonly schemes;
|
|
11
|
+
private current;
|
|
12
|
+
private controller;
|
|
13
|
+
private readonly bufferHandlers;
|
|
14
|
+
private mirroring;
|
|
15
|
+
private fromNative;
|
|
16
|
+
private variant;
|
|
17
|
+
private props;
|
|
18
|
+
constructor(driver: EditorDriver, schemes?: StyleSchemeManager, variant?: ColorSchemeVariant);
|
|
19
|
+
get buffer(): Buffer;
|
|
20
|
+
set buffer(value: Buffer);
|
|
21
|
+
private attach;
|
|
22
|
+
private onBufferChanged;
|
|
23
|
+
private onBufferCursor;
|
|
24
|
+
onNativeEdit(start: number, removedLength: number, inserted: string): void;
|
|
25
|
+
onNativeSelection(start: number, end: number): void;
|
|
26
|
+
private setProp;
|
|
27
|
+
private pushLayout;
|
|
28
|
+
get autoIndent(): boolean;
|
|
29
|
+
set autoIndent(value: boolean);
|
|
30
|
+
/** Held and read back; Android has no Tab key to apply it to (see the package README). */
|
|
31
|
+
get indentWidth(): number;
|
|
32
|
+
set indentWidth(value: number);
|
|
33
|
+
get showLineNumbers(): boolean;
|
|
34
|
+
set showLineNumbers(value: boolean);
|
|
35
|
+
get monospace(): boolean;
|
|
36
|
+
set monospace(value: boolean);
|
|
37
|
+
get editable(): boolean;
|
|
38
|
+
set editable(value: boolean);
|
|
39
|
+
get highlightCurrentLine(): boolean;
|
|
40
|
+
set highlightCurrentLine(value: boolean);
|
|
41
|
+
get cursorVisible(): boolean;
|
|
42
|
+
set cursorVisible(value: boolean);
|
|
43
|
+
get leftMargin(): number;
|
|
44
|
+
set leftMargin(value: number);
|
|
45
|
+
get rightMargin(): number;
|
|
46
|
+
set rightMargin(value: number);
|
|
47
|
+
get topMargin(): number;
|
|
48
|
+
set topMargin(value: number);
|
|
49
|
+
get bottomMargin(): number;
|
|
50
|
+
set bottomMargin(value: number);
|
|
51
|
+
/** Re-tints for the light/dark change; the tokens are kept. */
|
|
52
|
+
setColorScheme(variant: ColorSchemeVariant): void;
|
|
53
|
+
dispose(): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Digits needed to write `lineCount`; never fewer than `minDigits`, so a 9-line file does not jitter at line 10. */
|
|
2
|
+
export declare function digitCount(lineCount: number, minDigits?: number): number;
|
|
3
|
+
/** Total gutter width in pixels: the widest label plus padding on both sides. */
|
|
4
|
+
export declare function gutterWidth(lineCount: number, digitWidth: number, padding: number, minDigits?: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* The lines whose vertical extent meets `[viewTop, viewBottom)`, found by binary search over
|
|
7
|
+
* the layout's line tops so a 10 000-line file draws the ~40 labels it shows, not 10 000.
|
|
8
|
+
* `lineBottom(i)` is the bottom edge of line `i`; both edges are in the same pixel space as
|
|
9
|
+
* the view range. `null` when nothing is visible.
|
|
10
|
+
*/
|
|
11
|
+
export declare function visibleLines(lineCount: number, lineTop: (line: number) => number, lineBottom: (line: number) => number, viewTop: number, viewBottom: number): {
|
|
12
|
+
first: number;
|
|
13
|
+
last: number;
|
|
14
|
+
} | null;
|
|
15
|
+
/**
|
|
16
|
+
* The line whose number carries the `current-line-number` style, or `-1`. The style rides on
|
|
17
|
+
* `highlight-current-line`: that property defaults to false, so a read-only snippet's first
|
|
18
|
+
* line (where the caret rests at offset 0) must not look picked out.
|
|
19
|
+
*/
|
|
20
|
+
export declare function emphasisedLine(highlightCurrentLine: boolean, caretLine: number): number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Buffer } from './buffer.js';
|
|
2
|
+
import type { HighlightSink } from './editor-driver.js';
|
|
3
|
+
import { StyleSchemeManager } from './style-scheme.js';
|
|
4
|
+
import type { ColorSchemeVariant, StyleScheme } from './style-scheme.js';
|
|
5
|
+
export declare class HighlightController {
|
|
6
|
+
private readonly buffer;
|
|
7
|
+
private readonly sink;
|
|
8
|
+
private readonly schemes;
|
|
9
|
+
private highlighter;
|
|
10
|
+
private styler;
|
|
11
|
+
private variant;
|
|
12
|
+
private readonly handlers;
|
|
13
|
+
constructor(buffer: Buffer, sink: HighlightSink, schemes?: StyleSchemeManager, variant?: ColorSchemeVariant);
|
|
14
|
+
/** The scheme actually in force: the buffer's (its other-mode sibling when one exists), else the default. */
|
|
15
|
+
get scheme(): StyleScheme | null;
|
|
16
|
+
setColorScheme(variant: ColorSchemeVariant): void;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Full repaint. `retokenize` is false for a pure re-tint: the tokens did not change, only what they look like.
|
|
20
|
+
*/
|
|
21
|
+
private rebuild;
|
|
22
|
+
private onChanged;
|
|
23
|
+
private paint;
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LineState, Token, Tokenizer } from './tokenizer.js';
|
|
2
|
+
/** Lines `first..last`, both inclusive. */
|
|
3
|
+
export interface LineRange {
|
|
4
|
+
readonly first: number;
|
|
5
|
+
readonly last: number;
|
|
6
|
+
}
|
|
7
|
+
/** `lines[first .. first + removed)` of the old text are now `lines[first .. first + inserted)`. */
|
|
8
|
+
export interface LineEdit {
|
|
9
|
+
readonly first: number;
|
|
10
|
+
readonly removed: number;
|
|
11
|
+
readonly inserted: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Two line states are the same when the same span contexts are open. The tokenizer hands out
|
|
15
|
+
* the same node object for the same context every time (its candidate lists are cached), so
|
|
16
|
+
* identity is the right comparison; if it ever returned fresh nodes this would only cost
|
|
17
|
+
* speed — the propagation would run to the end of the document — never correctness.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sameState(a: LineState, b: LineState): boolean;
|
|
20
|
+
export declare class IncrementalHighlighter {
|
|
21
|
+
readonly tokenizer: Tokenizer;
|
|
22
|
+
private results;
|
|
23
|
+
constructor(tokenizer: Tokenizer);
|
|
24
|
+
get lineCount(): number;
|
|
25
|
+
tokensOf(line: number): readonly Token[];
|
|
26
|
+
/** Tokenizes the whole text; returns the range now valid, `null` for no lines. */
|
|
27
|
+
reset(lines: readonly string[]): LineRange | null;
|
|
28
|
+
/**
|
|
29
|
+
* Applies one line edit. `lines` is the NEW full text, already edited. Returns the lines
|
|
30
|
+
* whose tokens were recomputed — the ones a renderer must repaint.
|
|
31
|
+
*/
|
|
32
|
+
update(lines: readonly string[], edit: LineEdit): LineRange;
|
|
33
|
+
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,3 +4,18 @@ export * from './style.js';
|
|
|
4
4
|
export * from './regex.js';
|
|
5
5
|
export * from './xml.js';
|
|
6
6
|
export * from './tokenizer.js';
|
|
7
|
+
export * from './signals.js';
|
|
8
|
+
export * from './color.js';
|
|
9
|
+
export * from './buffer.js';
|
|
10
|
+
export * from './language-manager.js';
|
|
11
|
+
export * from './style-scheme.js';
|
|
12
|
+
export * from './fallback-schemes.js';
|
|
13
|
+
export * from './token-styler.js';
|
|
14
|
+
export * from './highlighter.js';
|
|
15
|
+
export * from './highlight-controller.js';
|
|
16
|
+
export * from './editor-driver.js';
|
|
17
|
+
export * from './editor-session.js';
|
|
18
|
+
export * from './line-store.js';
|
|
19
|
+
export * from './gutter.js';
|
|
20
|
+
export * from './coerce.js';
|
|
21
|
+
export * from './init.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The part of `GtkSource` the vectors read. */
|
|
2
|
+
export interface GtkSourceInitLike {
|
|
3
|
+
init(): unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface GtkSourceInitVector {
|
|
6
|
+
readonly rule: string;
|
|
7
|
+
readonly observe: (GtkSource: GtkSourceInitLike) => unknown;
|
|
8
|
+
readonly shows: unknown;
|
|
9
|
+
}
|
|
10
|
+
export declare const GTKSOURCE_INIT_VECTORS: readonly GtkSourceInitVector[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Tokenizer } from './tokenizer.js';
|
|
2
|
+
import type { LanguageDefinition } from './types.js';
|
|
3
|
+
export declare class Language {
|
|
4
|
+
readonly definition: LanguageDefinition;
|
|
5
|
+
private cached;
|
|
6
|
+
constructor(definition: LanguageDefinition);
|
|
7
|
+
get id(): string;
|
|
8
|
+
get name(): string;
|
|
9
|
+
get section(): string;
|
|
10
|
+
get globs(): string[];
|
|
11
|
+
get mimeTypes(): string[];
|
|
12
|
+
/** Built on first use: compiling every pattern is the expensive part of loading a language. */
|
|
13
|
+
get tokenizer(): Tokenizer;
|
|
14
|
+
}
|
|
15
|
+
export declare class LanguageManager {
|
|
16
|
+
private static instance;
|
|
17
|
+
/** `GtkSource.LanguageManager.get_default()`. */
|
|
18
|
+
static getDefault(): LanguageManager;
|
|
19
|
+
/** GJS spelling of {@link getDefault}. */
|
|
20
|
+
static get_default(): LanguageManager;
|
|
21
|
+
private readonly languages;
|
|
22
|
+
get languageIds(): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Parses and registers a `.lang` file. Constructs the core does not model land in
|
|
25
|
+
* `language.definition.unsupported`; pass `strict` to throw on them instead.
|
|
26
|
+
*/
|
|
27
|
+
addLanguageFromXml(xml: string, options?: {
|
|
28
|
+
strict?: boolean;
|
|
29
|
+
}): Language;
|
|
30
|
+
getLanguage(id: string): Language | null;
|
|
31
|
+
/** GJS spelling of {@link getLanguage}. */
|
|
32
|
+
get_language(id: string): Language | null;
|
|
33
|
+
/** `gtk_source_language_manager_guess_language()`: by file name first, then by content type. */
|
|
34
|
+
guessLanguage(filename: string | null, contentType: string | null): Language | null;
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class LineStore<T> {
|
|
2
|
+
private slots;
|
|
3
|
+
get(line: number): T | undefined;
|
|
4
|
+
set(line: number, value: T | undefined): void;
|
|
5
|
+
/** Returns the values that were dropped, so the caller can release what they hold. */
|
|
6
|
+
splice(first: number, removed: number, inserted: number): T[];
|
|
7
|
+
/** Empties every slot and returns the values that were held. */
|
|
8
|
+
clear(): T[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The part of `GtkSource` the vectors read. */
|
|
2
|
+
export interface GtkSourceManagersLike {
|
|
3
|
+
LanguageManager: {
|
|
4
|
+
get_default(): {
|
|
5
|
+
get_language(id: string): unknown;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
StyleSchemeManager: {
|
|
9
|
+
get_default(): {
|
|
10
|
+
get_scheme(id: string): {
|
|
11
|
+
id: string;
|
|
12
|
+
} | null;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
Buffer: new (properties?: any) => {
|
|
16
|
+
text: string;
|
|
17
|
+
language: unknown;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface GtkSourceManagersVector {
|
|
21
|
+
readonly rule: string;
|
|
22
|
+
readonly observe: (GtkSource: GtkSourceManagersLike) => unknown;
|
|
23
|
+
readonly shows: unknown;
|
|
24
|
+
}
|
|
25
|
+
export declare const GTKSOURCE_MANAGER_VECTORS: readonly GtkSourceManagersVector[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class SignalEmitter {
|
|
2
|
+
private readonly handlers;
|
|
3
|
+
connect(name: string, callback: (self: this, ...args: never[]) => void): number;
|
|
4
|
+
/** `g_signal_connect_after`: runs once every plain handler of the emission has run. */
|
|
5
|
+
connect_after(name: string, callback: (self: this, ...args: never[]) => void): number;
|
|
6
|
+
/** An emitter that knows its signals overrides this and throws for a name it does not have. */
|
|
7
|
+
protected checkSignal(_name: string): void;
|
|
8
|
+
private add;
|
|
9
|
+
/** Removes exactly the handler `connect` returned this id for; an id nothing holds throws. */
|
|
10
|
+
disconnect(id: number): void;
|
|
11
|
+
protected emit(name: string, ...args: unknown[]): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ResolvedStyle, StyleSchemeDefinition } from './types.js';
|
|
2
|
+
export type ColorSchemeVariant = 'light' | 'dark';
|
|
3
|
+
export declare class StyleScheme {
|
|
4
|
+
readonly definition: StyleSchemeDefinition;
|
|
5
|
+
private readonly lookup;
|
|
6
|
+
constructor(definition: StyleSchemeDefinition, lookup: (id: string) => StyleSchemeDefinition | undefined);
|
|
7
|
+
get id(): string;
|
|
8
|
+
get name(): string;
|
|
9
|
+
get parentId(): string | undefined;
|
|
10
|
+
/** `text`, `line-numbers`, `def:keyword`, …; throws on a parent-scheme loop or a missing parent. */
|
|
11
|
+
getStyle(name: string): ResolvedStyle | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** The colours the view itself paints — everything that is not a syntax token. ARGB ints. */
|
|
14
|
+
export interface EditorPalette {
|
|
15
|
+
readonly dark: boolean;
|
|
16
|
+
readonly foreground: number;
|
|
17
|
+
readonly background: number;
|
|
18
|
+
readonly selectionBackground: number;
|
|
19
|
+
readonly currentLineBackground: number;
|
|
20
|
+
readonly lineNumberForeground: number;
|
|
21
|
+
readonly lineNumberBackground: number;
|
|
22
|
+
readonly currentLineNumberForeground: number;
|
|
23
|
+
readonly currentLineNumberBackground: number;
|
|
24
|
+
}
|
|
25
|
+
/** Reads the palette off a scheme; a style the scheme (and its parents) lack takes a neutral default. */
|
|
26
|
+
export declare function paletteOf(scheme: StyleScheme, variant: ColorSchemeVariant): EditorPalette;
|
|
27
|
+
export declare class StyleSchemeManager {
|
|
28
|
+
private static instance;
|
|
29
|
+
/** `GtkSource.StyleSchemeManager.get_default()`. */
|
|
30
|
+
static getDefault(): StyleSchemeManager;
|
|
31
|
+
/** GJS spelling of {@link getDefault}. */
|
|
32
|
+
static get_default(): StyleSchemeManager;
|
|
33
|
+
private readonly definitions;
|
|
34
|
+
private readonly fallbacks;
|
|
35
|
+
/** @param withFallbacks register this package's own `Adwaita`/`Adwaita-dark` stand-ins. */
|
|
36
|
+
constructor(withFallbacks?: boolean);
|
|
37
|
+
get schemeIds(): string[];
|
|
38
|
+
/** Whether `id` is still this package's stand-in rather than a scheme the consumer supplied. */
|
|
39
|
+
isFallback(id: string): boolean;
|
|
40
|
+
/** Adds a scheme, replacing one with the same id (that is how the real Adwaita replaces the stand-in). */
|
|
41
|
+
addScheme(definition: StyleSchemeDefinition): StyleScheme;
|
|
42
|
+
addSchemeFromXml(xml: string): StyleScheme;
|
|
43
|
+
getScheme(id: string): StyleScheme | null;
|
|
44
|
+
/** GJS spelling of {@link getScheme}. */
|
|
45
|
+
get_scheme(id: string): StyleScheme | null;
|
|
46
|
+
/** The scheme to use when nothing was chosen: the stand-in or real `Adwaita` / `Adwaita-dark`. */
|
|
47
|
+
getDefaultFor(variant: ColorSchemeVariant): StyleScheme | null;
|
|
48
|
+
/**
|
|
49
|
+
* The same scheme for the other mode, found by the `<id>-dark` naming convention
|
|
50
|
+
* (`Learn6502` / `Learn6502-dark`). `scheme` itself when it already is the asked variant
|
|
51
|
+
* or has no sibling — never a guess across unrelated schemes.
|
|
52
|
+
*/
|
|
53
|
+
variantOf(scheme: StyleScheme, variant: ColorSchemeVariant): StyleScheme;
|
|
54
|
+
private wrap;
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What an iterator needs of its buffer. */
|
|
2
|
+
export interface TextIterSource {
|
|
3
|
+
readonly length: number;
|
|
4
|
+
getText(start?: number, end?: number): string;
|
|
5
|
+
}
|
|
6
|
+
export declare class TextIter {
|
|
7
|
+
readonly source: TextIterSource;
|
|
8
|
+
private offset;
|
|
9
|
+
/** Made by a buffer, never by a caller: GTK hands iterators out, it does not take them in. `source` is the owning buffer. */
|
|
10
|
+
constructor(source: TextIterSource, utf16Offset: number);
|
|
11
|
+
/** The offset in UTF-16 units, the buffer's own measure; not part of the `Gtk.TextIter` surface. */
|
|
12
|
+
get utf16Offset(): number;
|
|
13
|
+
get_offset(): number;
|
|
14
|
+
/** Like `gtk_text_iter_set_offset`: a negative offset, or one past the end, is the end. */
|
|
15
|
+
set_offset(charOffset: number): void;
|
|
16
|
+
}
|
|
17
|
+
/** One of the two marks every buffer has, `insert` and `selection_bound`. */
|
|
18
|
+
export declare class TextMark {
|
|
19
|
+
readonly name: string | null;
|
|
20
|
+
constructor(name: string | null);
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Token } from './tokenizer.js';
|
|
2
|
+
import type { LanguageDefinition } from './types.js';
|
|
3
|
+
import type { StyleScheme } from './style-scheme.js';
|
|
4
|
+
/** What one run of text looks like. Colours are signed ARGB ints. */
|
|
5
|
+
export interface RunStyle {
|
|
6
|
+
readonly foreground?: number;
|
|
7
|
+
readonly background?: number;
|
|
8
|
+
readonly bold: boolean;
|
|
9
|
+
readonly italic: boolean;
|
|
10
|
+
readonly underline: boolean;
|
|
11
|
+
readonly strikethrough: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** `[start, end)` within one line. */
|
|
14
|
+
export interface StyledRun {
|
|
15
|
+
readonly start: number;
|
|
16
|
+
readonly end: number;
|
|
17
|
+
readonly style: RunStyle;
|
|
18
|
+
}
|
|
19
|
+
export declare class TokenStyler {
|
|
20
|
+
private readonly language;
|
|
21
|
+
private readonly scheme;
|
|
22
|
+
private readonly cache;
|
|
23
|
+
constructor(language: LanguageDefinition, scheme: StyleScheme);
|
|
24
|
+
/** `undefined` when the scheme gives the style nothing to paint: the run keeps the text colour. */
|
|
25
|
+
styleFor(tokenStyle: string): RunStyle | undefined;
|
|
26
|
+
runsOf(tokens: readonly Token[]): StyledRun[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface GtkSourceViewDefaultsVector {
|
|
2
|
+
readonly property: string;
|
|
3
|
+
/** The member a port spells it as. */
|
|
4
|
+
readonly member: string;
|
|
5
|
+
readonly shows: boolean | number;
|
|
6
|
+
}
|
|
7
|
+
export declare const GTKSOURCE_VIEW_DEFAULT_VECTORS: readonly GtkSourceViewDefaultsVector[];
|
|
8
|
+
interface AdjustmentLike {
|
|
9
|
+
get_value(): number;
|
|
10
|
+
}
|
|
11
|
+
export interface ViewLike {
|
|
12
|
+
cursor_visible: boolean;
|
|
13
|
+
editable: boolean;
|
|
14
|
+
highlight_current_line: boolean;
|
|
15
|
+
show_line_numbers: boolean;
|
|
16
|
+
readonly vadjustment: AdjustmentLike;
|
|
17
|
+
readonly hadjustment: AdjustmentLike;
|
|
18
|
+
get_cursor_visible(): boolean;
|
|
19
|
+
set_cursor_visible(value: boolean): void;
|
|
20
|
+
get_editable(): boolean;
|
|
21
|
+
set_editable(value: boolean): void;
|
|
22
|
+
get_vadjustment(): AdjustmentLike;
|
|
23
|
+
get_direction(): number;
|
|
24
|
+
set_direction(direction: number): void;
|
|
25
|
+
get_first_child(): unknown;
|
|
26
|
+
get_next_sibling(): unknown;
|
|
27
|
+
get_parent(): unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ScrolledWindowLike {
|
|
30
|
+
readonly vadjustment: AdjustmentLike;
|
|
31
|
+
get_policy(): [number, number];
|
|
32
|
+
set_policy(h: number, v: number): void;
|
|
33
|
+
set_vadjustment(adjustment: AdjustmentLike): void;
|
|
34
|
+
get_vadjustment(): AdjustmentLike;
|
|
35
|
+
}
|
|
36
|
+
/** The parts of `Gtk` and `GtkSource` the slice-4 vectors read. */
|
|
37
|
+
export interface GtkSourceViewSurfaceLike {
|
|
38
|
+
Gtk: {
|
|
39
|
+
TextWindowType: Record<string, number>;
|
|
40
|
+
PolicyType: Record<string, number>;
|
|
41
|
+
TextDirection: Record<string, number>;
|
|
42
|
+
ScrolledWindow: new (properties?: any) => ScrolledWindowLike;
|
|
43
|
+
};
|
|
44
|
+
GtkSource: {
|
|
45
|
+
View: new (properties?: any) => ViewLike;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface GtkSourceViewSurfaceVector {
|
|
49
|
+
readonly rule: string;
|
|
50
|
+
/** Whether a `GtkSource.View` instance is built, which needs a display on GJS. */
|
|
51
|
+
readonly instance: boolean;
|
|
52
|
+
readonly observe: (ns: GtkSourceViewSurfaceLike) => unknown;
|
|
53
|
+
readonly shows: unknown;
|
|
54
|
+
}
|
|
55
|
+
export declare const GTKSOURCE_VIEW_SURFACE_VECTORS: readonly GtkSourceViewSurfaceVector[];
|
|
56
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/gtksource-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Headless GtkSourceView language/style parsing (renderer-free) — parse .lang and style scheme XML into typed data with JS regex translation, strict unsupported reporting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./lib/types/index.d.ts",
|
|
11
11
|
"default": "./lib/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./conformance": {
|
|
14
|
+
"types": "./lib/types/conformance.d.ts",
|
|
15
|
+
"default": "./lib/esm/conformance.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
@@ -42,8 +46,8 @@
|
|
|
42
46
|
"headless"
|
|
43
47
|
],
|
|
44
48
|
"devDependencies": {
|
|
45
|
-
"@gjsify/cli": "^0.
|
|
46
|
-
"@gjsify/unit": "^0.
|
|
49
|
+
"@gjsify/cli": "^0.57.0",
|
|
50
|
+
"@gjsify/unit": "^0.57.0",
|
|
47
51
|
"@types/node": "^25.9.2",
|
|
48
52
|
"typescript": "^6.0.3"
|
|
49
53
|
},
|