@lvce-editor/editor-worker 19.72.2 → 19.72.4

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.
@@ -5445,7 +5445,7 @@ const mergeConflictsEqual$1 = (oldState, newState) => {
5445
5445
  return conflict.startRowIndex === other.startRowIndex && conflict.endRowIndex === other.endRowIndex;
5446
5446
  });
5447
5447
  };
5448
- const updateDerivedState = async (oldState, newState) => {
5448
+ const updateDerivedState = async (oldState, newState, deferGutterDecorations = false) => {
5449
5449
  const horizontalState = oldState.initial || oldState.lines !== newState.lines || oldState.width !== newState.width || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.tabSize !== newState.tabSize || oldState.lineNumbers !== newState.lineNumbers || oldState.breakPoints !== newState.breakPoints || oldState.gutterDecorations !== newState.gutterDecorations || oldState.lightBulbRowIndex !== newState.lightBulbRowIndex ? await updateHorizontalLayout(newState) : newState;
5450
5450
  const layoutState = oldState.lines !== newState.lines && 'foldingRanges' in newState ? updateLayout(horizontalState, []) : horizontalState;
5451
5451
  const nextState = mergeConflictsEqual$1(oldState, layoutState) ? layoutState : {
@@ -5513,7 +5513,7 @@ const updateDerivedState = async (oldState, newState) => {
5513
5513
  lightBulbRowIndex: await getLightBulbRowIndex(finalState)
5514
5514
  };
5515
5515
  }
5516
- if (oldState.lines !== nextState.lines || oldState.uri !== nextState.uri) {
5516
+ if (!deferGutterDecorations && (oldState.lines !== nextState.lines || oldState.uri !== nextState.uri)) {
5517
5517
  finalState = {
5518
5518
  ...finalState,
5519
5519
  gutterDecorations: await getEditorGutterDecorations(finalState)
@@ -6259,7 +6259,7 @@ const run = async (uid, token, save) => {
6259
6259
  }
6260
6260
  await save(token);
6261
6261
  };
6262
- const schedule = (uid, save) => {
6262
+ const schedule$1 = (uid, save) => {
6263
6263
  dispose$4(uid);
6264
6264
  const token = ++state$7.nextToken;
6265
6265
  const timeout = setTimeout(run, autoSaveDelay, uid, token, save);
@@ -7900,6 +7900,70 @@ const editorDiagnosticEffect = {
7900
7900
  isActive: (oldEditor, newEditor) => !oldEditor.initial && !newEditor.loadError && newEditor.diagnosticsEnabled && (oldEditor.lines !== newEditor.lines || oldEditor.languageId !== newEditor.languageId)
7901
7901
  };
7902
7902
 
7903
+ const refreshes = new WeakMap();
7904
+ const isCurrent = (editor, snapshot) => Boolean(editor && editor.lifecycle === snapshot.lifecycle && !editor.lifecycle?.disposed && editor.lines === snapshot.lines && editor.gutterDecorations === snapshot.gutterDecorations && editor.uri === snapshot.uri && editor.languageId === snapshot.languageId && editor.applicationId === snapshot.applicationId);
7905
+ const refresh = async request => {
7906
+ try {
7907
+ while (request.pending) {
7908
+ const snapshot = request.pending;
7909
+ request.pending = undefined;
7910
+ if (snapshot.lifecycle?.disposed) {
7911
+ continue;
7912
+ }
7913
+ const gutterDecorations = await getEditorGutterDecorations(snapshot);
7914
+ const changed = await enqueue(snapshot.uid, async () => {
7915
+ const current = get$8(snapshot.uid)?.newState;
7916
+ if (!isCurrent(current, snapshot) || current.gutterDecorations.length === gutterDecorations.length && gutterDecorations.every((item, index) => item.rowIndex === current.gutterDecorations[index].rowIndex && item.type === current.gutterDecorations[index].type)) {
7917
+ return false;
7918
+ }
7919
+ const next = await updateDerivedState(current, {
7920
+ ...current,
7921
+ gutterDecorations
7922
+ });
7923
+ // Derived state may await layout RPCs while an asynchronous render consumes the baseline.
7924
+ const latest = get$8(snapshot.uid);
7925
+ if (!isCurrent(latest?.newState, snapshot)) {
7926
+ return false;
7927
+ }
7928
+ set$a(snapshot.uid, latest.oldState, next);
7929
+ return true;
7930
+ });
7931
+ if (changed) {
7932
+ await invoke$d('Editor.renderPending', snapshot.uid);
7933
+ }
7934
+ }
7935
+ } catch (error) {
7936
+ console.warn('Failed to refresh gutter decorations:', error);
7937
+ } finally {
7938
+ request.running = false;
7939
+ if (request.pending) {
7940
+ request.running = true;
7941
+ void refresh(request);
7942
+ }
7943
+ }
7944
+ };
7945
+ const schedule = editor => {
7946
+ const {
7947
+ lifecycle
7948
+ } = editor;
7949
+ if (!lifecycle || lifecycle.disposed) {
7950
+ return;
7951
+ }
7952
+ let request = refreshes.get(lifecycle);
7953
+ if (!request) {
7954
+ request = {
7955
+ pending: undefined,
7956
+ running: false
7957
+ };
7958
+ refreshes.set(lifecycle, request);
7959
+ }
7960
+ request.pending = editor;
7961
+ if (!request.running) {
7962
+ request.running = true;
7963
+ void refresh(request);
7964
+ }
7965
+ };
7966
+
7903
7967
  const cursorUndoLimit = 100;
7904
7968
  const selectionsEqual = (left, right) => {
7905
7969
  if (left === right) {
@@ -7983,7 +8047,8 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
7983
8047
  if (state === newEditor) {
7984
8048
  return returnState ? newEditor : undefined;
7985
8049
  }
7986
- const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
8050
+ const deferGutterDecorations = !initial && uri === newEditor.uri && lines !== newEditor.lines && Boolean(newEditor.lifecycle);
8051
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor, deferGutterDecorations);
7987
8052
  // Another command can commit before the renderer consumes this edit.
7988
8053
  // Keep its last rendered baseline, including renders completed while we awaited derived state.
7989
8054
  const renderedState = get$8(uid)?.oldState ?? oldInstance.oldState;
@@ -7993,6 +8058,9 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
7993
8058
  void editorDiagnosticEffect.apply(newEditorWithDerivedState);
7994
8059
  }
7995
8060
  const finalEditor = newEditorWithDerivedState;
8061
+ if (deferGutterDecorations) {
8062
+ schedule(finalEditor);
8063
+ }
7996
8064
  await notifyEditorStatusChange(state, finalEditor);
7997
8065
  if (!initial && uri === finalEditor.uri && (endOfLine !== finalEditor.endOfLine || insertSpaces !== finalEditor.insertSpaces || lines !== finalEditor.lines || modified !== finalEditor.modified || redoStack !== finalEditor.redoStack || undoStack !== finalEditor.undoStack)) {
7998
8066
  for (const key of getKeys$2()) {
@@ -8015,15 +8083,18 @@ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true
8015
8083
  redoStack: finalEditor.redoStack,
8016
8084
  undoStack: finalEditor.undoStack,
8017
8085
  visualDecorations: finalEditor.visualDecorations
8018
- });
8086
+ }, deferGutterDecorations);
8019
8087
  set$a(otherUid, instance.oldState, synchronizedEditor);
8088
+ if (deferGutterDecorations) {
8089
+ schedule(synchronizedEditor);
8090
+ }
8020
8091
  if (editorDiagnosticEffect.isActive(editor, synchronizedEditor)) {
8021
8092
  void editorDiagnosticEffect.apply(synchronizedEditor);
8022
8093
  }
8023
8094
  }
8024
8095
  }
8025
8096
  if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
8026
- schedule(uid, token => saveAfterDelay(uid, token));
8097
+ schedule$1(uid, token => saveAfterDelay(uid, token));
8027
8098
  } else if (modified && !finalEditor.modified) {
8028
8099
  dispose$4(uid);
8029
8100
  }
@@ -8315,7 +8386,7 @@ const cancelSelection = editor => {
8315
8386
  return scheduleSelections(editor, newSelections);
8316
8387
  };
8317
8388
 
8318
- const colorPattern = /#[\dA-Fa-f]+/g;
8389
+ const colorPattern$2 = /#[\dA-Fa-f]+/g;
8319
8390
  const numberPattern = /(?<![\w.#])[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?(?![\d.])/g;
8320
8391
  const validColorLengths = new Set([4, 5, 7, 9]);
8321
8392
  const isColor = value => {
@@ -8398,7 +8469,7 @@ const findMatchAt = (line, columnIndex, pattern, predicate) => {
8398
8469
  return undefined;
8399
8470
  };
8400
8471
  const findValueAt = (line, columnIndex) => {
8401
- return findMatchAt(line, columnIndex, colorPattern, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
8472
+ return findMatchAt(line, columnIndex, colorPattern$2, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
8402
8473
  };
8403
8474
  const getSelectionTarget = (editor, index) => {
8404
8475
  const selectionStartRow = editor.selections[index];
@@ -8766,7 +8837,7 @@ const openColorPicker = async editor => {
8766
8837
  const bounds = getColorPickerBounds(editor);
8767
8838
  const {
8768
8839
  getColorPickerRange
8769
- } = await import('./GetColorPickerRange-CsGZK202.js');
8840
+ } = await Promise.resolve().then(function () { return GetColorPickerRange; });
8770
8841
  const range = await getColorPickerRange(editor);
8771
8842
  const createWidget = () => create$6(bounds, range, editor.undoStack.length);
8772
8843
  return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$5, fullFocus);
@@ -11409,10 +11480,17 @@ const continueScrollingAndMovingSelection = async editorUid => {
11409
11480
  return;
11410
11481
  }
11411
11482
  set$a(editor.uid, editor, derivedEditor);
11483
+ await invoke$d('Editor.renderPending', editor.uid);
11412
11484
  if (derivedEditor.hasListener) {
11413
11485
  requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
11414
11486
  }
11415
11487
  };
11488
+ const scheduleInitialSelectionAutoScroll = editorUid => {
11489
+ // Let the wrapped pointer-move command commit hasListener before the loop reads state.
11490
+ requestAnimationFrame(() => {
11491
+ requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
11492
+ });
11493
+ };
11416
11494
  const moveSelectionPx = async (editor, x, y) => {
11417
11495
  object(editor);
11418
11496
  number(x);
@@ -11428,7 +11506,7 @@ const moveSelectionPx = async (editor, x, y) => {
11428
11506
  };
11429
11507
  }
11430
11508
  if (!editor.hasListener) {
11431
- requestAnimationFrame(() => continueScrollingAndMovingSelection(editor.uid));
11509
+ scheduleInitialSelectionAutoScroll(editor.uid);
11432
11510
  }
11433
11511
  return {
11434
11512
  ...newEditor,
@@ -15389,6 +15467,20 @@ const getPositionAtCursor = editorUid => {
15389
15467
  const editor = getEditor$1(editorUid);
15390
15468
  return getPositionAtCursor$1(editor);
15391
15469
  };
15470
+ const getCompletionContext = (editorUid, includeLine = false) => {
15471
+ const editor = getEditor$1(editorUid);
15472
+ const position = getPositionAtCursor$1(editor);
15473
+ if (!includeLine) {
15474
+ return {
15475
+ ...position,
15476
+ wordBefore: getWordBefore(editor, position.rowIndex, position.columnIndex)
15477
+ };
15478
+ }
15479
+ return {
15480
+ ...position,
15481
+ line: editor.lines[position.rowIndex] || ''
15482
+ };
15483
+ };
15392
15484
  const getUri = editorUid => {
15393
15485
  const editor = getEditor$1(editorUid);
15394
15486
  return editor.uri;
@@ -18769,6 +18861,7 @@ const commandMap = {
18769
18861
  'Editor.fold': wrapCommand(fold$1),
18770
18862
  'Editor.format': wrapCommand(format),
18771
18863
  'Editor.getCommandIds': getCommandIds,
18864
+ 'Editor.getCompletionContext': getCompletionContext,
18772
18865
  'Editor.getDiagnostics': getDiagnostics,
18773
18866
  'Editor.getKeyBindings': getKeyBindings,
18774
18867
  'Editor.getKeys': getKeys,
@@ -19442,4 +19535,100 @@ const main = async () => {
19442
19535
 
19443
19536
  main();
19444
19537
 
19445
- export { offsetAt as o };
19538
+ const noColorRange = {
19539
+ endOffset: -1,
19540
+ startOffset: -1,
19541
+ value: ''
19542
+ };
19543
+ const colorPattern$1 = /#[\da-f]{3,8}\b|(?<![\w$])0x[\da-f]{6}(?![\w$])|\b(?:hsla?|rgba?)\([^)]*\)/gi;
19544
+ const getColorPickerRange = async editor => {
19545
+ const {
19546
+ lines,
19547
+ selections
19548
+ } = editor;
19549
+ if (!selections || selections.length < 4) {
19550
+ return noColorRange;
19551
+ }
19552
+ const selectionStartRow = selections[0];
19553
+ const selectionEndRow = selections[2];
19554
+ if (selectionStartRow !== selectionEndRow) {
19555
+ return noColorRange;
19556
+ }
19557
+ const selectionStartColumn = selections[1];
19558
+ const selectionEndColumn = selections[3];
19559
+ const rowIndex = selectionEndRow;
19560
+ const line = lines[rowIndex];
19561
+ if (typeof line !== 'string') {
19562
+ return noColorRange;
19563
+ }
19564
+ if (selectionStartColumn !== selectionEndColumn) {
19565
+ const startColumn = Math.min(selectionStartColumn, selectionEndColumn);
19566
+ const endColumn = Math.max(selectionStartColumn, selectionEndColumn);
19567
+ return {
19568
+ endOffset: offsetAt(editor, rowIndex, endColumn),
19569
+ startOffset: offsetAt(editor, rowIndex, startColumn),
19570
+ value: line.slice(startColumn, endColumn)
19571
+ };
19572
+ }
19573
+ const columnIndex = selectionEndColumn;
19574
+ for (const match of line.matchAll(colorPattern$1)) {
19575
+ const startColumn = match.index;
19576
+ const endColumn = startColumn + match[0].length;
19577
+ if (columnIndex >= startColumn && columnIndex <= endColumn) {
19578
+ return {
19579
+ endOffset: offsetAt(editor, rowIndex, endColumn),
19580
+ startOffset: offsetAt(editor, rowIndex, startColumn),
19581
+ value: match[0]
19582
+ };
19583
+ }
19584
+ }
19585
+ const {
19586
+ getNamedColorRange
19587
+ } = await Promise.resolve().then(function () { return GetNamedColorRange; });
19588
+ const namedColorRange = getNamedColorRange(line, columnIndex);
19589
+ if (!namedColorRange) {
19590
+ return noColorRange;
19591
+ }
19592
+ return {
19593
+ endOffset: offsetAt(editor, rowIndex, namedColorRange.end),
19594
+ startOffset: offsetAt(editor, rowIndex, namedColorRange.start),
19595
+ value: namedColorRange.value
19596
+ };
19597
+ };
19598
+
19599
+ const GetColorPickerRange = {
19600
+ __proto__: null,
19601
+ getColorPickerRange
19602
+ };
19603
+
19604
+ const colorPattern = /\b[a-z]+\b/gi;
19605
+ const getNamedColorRange = (line, columnIndex) => {
19606
+ for (const match of line.matchAll(colorPattern)) {
19607
+ const start = match.index;
19608
+ const end = start + match[0].length;
19609
+ if (columnIndex < start || columnIndex > end || line[start - 1] === '-' || line[end] === '-') {
19610
+ continue;
19611
+ }
19612
+ const value = match[0];
19613
+ if (value.toLowerCase() === 'currentcolor') {
19614
+ return undefined;
19615
+ }
19616
+ const context = new OffscreenCanvas(1, 1).getContext('2d');
19617
+ context.fillStyle = '#010203';
19618
+ context.fillStyle = value;
19619
+ if (context.fillStyle === '#010203') {
19620
+ return undefined;
19621
+ }
19622
+ return {
19623
+ end,
19624
+ start,
19625
+ value
19626
+ };
19627
+ }
19628
+ return undefined;
19629
+ };
19630
+
19631
+ const GetNamedColorRange = {
19632
+ __proto__: null,
19633
+ getNamedColorRange
19634
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.72.2",
3
+ "version": "19.72.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"
@@ -1,64 +0,0 @@
1
- import { o as offsetAt } from './editorWorkerMain.js';
2
-
3
- const noColorRange = {
4
- endOffset: -1,
5
- startOffset: -1,
6
- value: ''
7
- };
8
- const colorPattern = /#[\da-f]{3,8}\b|(?<![\w$])0x[\da-f]{6}(?![\w$])|\b(?:hsla?|rgba?)\([^)]*\)/gi;
9
- const getColorPickerRange = async editor => {
10
- const {
11
- lines,
12
- selections
13
- } = editor;
14
- if (!selections || selections.length < 4) {
15
- return noColorRange;
16
- }
17
- const selectionStartRow = selections[0];
18
- const selectionEndRow = selections[2];
19
- if (selectionStartRow !== selectionEndRow) {
20
- return noColorRange;
21
- }
22
- const selectionStartColumn = selections[1];
23
- const selectionEndColumn = selections[3];
24
- const rowIndex = selectionEndRow;
25
- const line = lines[rowIndex];
26
- if (typeof line !== 'string') {
27
- return noColorRange;
28
- }
29
- if (selectionStartColumn !== selectionEndColumn) {
30
- const startColumn = Math.min(selectionStartColumn, selectionEndColumn);
31
- const endColumn = Math.max(selectionStartColumn, selectionEndColumn);
32
- return {
33
- endOffset: offsetAt(editor, rowIndex, endColumn),
34
- startOffset: offsetAt(editor, rowIndex, startColumn),
35
- value: line.slice(startColumn, endColumn)
36
- };
37
- }
38
- const columnIndex = selectionEndColumn;
39
- for (const match of line.matchAll(colorPattern)) {
40
- const startColumn = match.index;
41
- const endColumn = startColumn + match[0].length;
42
- if (columnIndex >= startColumn && columnIndex <= endColumn) {
43
- return {
44
- endOffset: offsetAt(editor, rowIndex, endColumn),
45
- startOffset: offsetAt(editor, rowIndex, startColumn),
46
- value: match[0]
47
- };
48
- }
49
- }
50
- const {
51
- getNamedColorRange
52
- } = await import('./GetNamedColorRange-LJAB8ndU.js');
53
- const namedColorRange = getNamedColorRange(line, columnIndex);
54
- if (!namedColorRange) {
55
- return noColorRange;
56
- }
57
- return {
58
- endOffset: offsetAt(editor, rowIndex, namedColorRange.end),
59
- startOffset: offsetAt(editor, rowIndex, namedColorRange.start),
60
- value: namedColorRange.value
61
- };
62
- };
63
-
64
- export { getColorPickerRange };
@@ -1,28 +0,0 @@
1
- const colorPattern = /\b[a-z]+\b/gi;
2
- const getNamedColorRange = (line, columnIndex) => {
3
- for (const match of line.matchAll(colorPattern)) {
4
- const start = match.index;
5
- const end = start + match[0].length;
6
- if (columnIndex < start || columnIndex > end || line[start - 1] === '-' || line[end] === '-') {
7
- continue;
8
- }
9
- const value = match[0];
10
- if (value.toLowerCase() === 'currentcolor') {
11
- return undefined;
12
- }
13
- const context = new OffscreenCanvas(1, 1).getContext('2d');
14
- context.fillStyle = '#010203';
15
- context.fillStyle = value;
16
- if (context.fillStyle === '#010203') {
17
- return undefined;
18
- }
19
- return {
20
- end,
21
- start,
22
- value
23
- };
24
- }
25
- return undefined;
26
- };
27
-
28
- export { getNamedColorRange };