@lvce-editor/editor-worker 13.1.0 → 13.2.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.
@@ -2435,7 +2435,7 @@ const getTabCount = string => {
2435
2435
  return count;
2436
2436
  };
2437
2437
 
2438
- const measureTextWidthFast = (text, charWidth) => {
2438
+ const measureTextWidthFast = async (text, charWidth) => {
2439
2439
  return text.length * charWidth;
2440
2440
  };
2441
2441
 
@@ -2474,7 +2474,7 @@ const getContext = () => {
2474
2474
 
2475
2475
  // TODO for text editor, could dispose measuring canvas after editor has been initialized to free up offscreencanvas space
2476
2476
 
2477
- const measureTextWidthSlow = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
2477
+ const measureTextWidthSlow = async (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
2478
2478
  string(text);
2479
2479
  number(fontWeight);
2480
2480
  number(fontSize);
@@ -2496,14 +2496,14 @@ const measureTextWidthSlow = (text, fontWeight, fontSize, fontFamily, letterSpac
2496
2496
  return width;
2497
2497
  };
2498
2498
 
2499
- const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
2499
+ const measureTextWidth = async (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
2500
2500
  if (isMonoSpaceFont) {
2501
- return measureTextWidthFast(text, charWidth);
2501
+ return await measureTextWidthFast(text, charWidth);
2502
2502
  }
2503
- return measureTextWidthSlow(text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth);
2503
+ return await measureTextWidthSlow(text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth);
2504
2504
  };
2505
2505
 
2506
- const getX = (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0) => {
2506
+ const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0) => {
2507
2507
  if (!line) {
2508
2508
  return 0;
2509
2509
  }
@@ -2525,7 +2525,8 @@ const getX = (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, l
2525
2525
  const normalizedLine = normalizeText(line, normalize, tabSize);
2526
2526
  const tabCount = getTabCount(line.slice(0, column));
2527
2527
  const partialText = normalizedLine.slice(0, column + tabCount);
2528
- return measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth) - halfCursorWidth + difference;
2528
+ const textWidth = await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
2529
+ return textWidth - halfCursorWidth + difference;
2529
2530
  };
2530
2531
 
2531
2532
  const getY = (row, minLineY, rowHeight) => {
@@ -2642,7 +2643,7 @@ const getSelectionArray = visibleSelections => {
2642
2643
  }
2643
2644
  return selectionsArray;
2644
2645
  };
2645
- const getVisible = editor => {
2646
+ const getVisible = async editor => {
2646
2647
  const visibleCursors = [];
2647
2648
  const visibleSelections = [];
2648
2649
  // // TODO binary search
@@ -2675,7 +2676,7 @@ const getVisible = editor => {
2675
2676
  const relativeEndLineRow = selectionEndRow - minLineY;
2676
2677
  const endLineDifference = differences[relativeEndLineRow];
2677
2678
  const endLine = lines[selectionEndRow];
2678
- const endLineEndX = getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference);
2679
+ const endLineEndX = await getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference);
2679
2680
  const endLineY = getY(selectionEndRow, minLineY, rowHeight);
2680
2681
  if (isEmpty(selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) && endLineEndX > 0) {
2681
2682
  visibleCursors.push(endLineEndX, endLineY);
@@ -2685,7 +2686,7 @@ const getVisible = editor => {
2685
2686
  const startLineYRelative = selectionStartRow - minLineY;
2686
2687
  const startLineDifference = differences[startLineYRelative];
2687
2688
  if (selectionStartRow === selectionEndRow) {
2688
- const startX = getX(endLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2689
+ const startX = await getX(endLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2689
2690
  if (reversed) {
2690
2691
  visibleCursors.push(startX, endLineY);
2691
2692
  } else if (endLineEndX >= 0) {
@@ -2696,8 +2697,8 @@ const getVisible = editor => {
2696
2697
  } else {
2697
2698
  if (selectionStartRow >= minLineY) {
2698
2699
  const startLine = lines[selectionStartRow];
2699
- const startLineStartX = getX(startLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2700
- const startLineEndX = getX(startLine, startLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2700
+ const startLineStartX = await getX(startLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2701
+ const startLineEndX = await getX(startLine, startLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
2701
2702
  const startLineStartY = getY(selectionStartRow, minLineY, rowHeight);
2702
2703
  const selectionWidth = startLineEndX - startLineStartX;
2703
2704
  if (reversed) {
@@ -2712,7 +2713,7 @@ const getVisible = editor => {
2712
2713
  const currentLineY = getY(i, minLineY, rowHeight);
2713
2714
  const relativeLine = i - minLineY;
2714
2715
  const difference = differences[relativeLine];
2715
- const selectionWidth = getX(currentLine, currentLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference);
2716
+ const selectionWidth = await getX(currentLine, currentLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference);
2716
2717
  visibleSelections.push(0, currentLineY, selectionWidth, rowHeight);
2717
2718
  }
2718
2719
  if (selectionEndRow <= maxLineY) {
@@ -3131,8 +3132,8 @@ const getLanguages = async () => {
3131
3132
  return languages;
3132
3133
  };
3133
3134
 
3134
- const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing) => {
3135
- return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
3135
+ const measureCharacterWidth = async (fontWeight, fontSize, fontFamily, letterSpacing) => {
3136
+ return await measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
3136
3137
  };
3137
3138
 
3138
3139
  const get$1 = async key => {
@@ -3171,7 +3172,7 @@ const getDiagnosticType = diagnostic => {
3171
3172
  return diagnostic.type;
3172
3173
  };
3173
3174
 
3174
- const getVisibleDiagnostics = (editor, diagnostics) => {
3175
+ const getVisibleDiagnostics = async (editor, diagnostics) => {
3175
3176
  const visibleDiagnostics = [];
3176
3177
  const {
3177
3178
  width,
@@ -3196,7 +3197,7 @@ const getVisibleDiagnostics = (editor, diagnostics) => {
3196
3197
  const diagnosticWidth = columnDelta * charWidth;
3197
3198
  const endLineDifference = 0;
3198
3199
  const halfCursorWidth = 0;
3199
- const x = getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
3200
+ const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
3200
3201
  const y = getY(rowIndex, minLineY, rowHeight) - rowHeight;
3201
3202
  visibleDiagnostics.push({
3202
3203
  x,
@@ -3228,7 +3229,7 @@ const updateDiagnostics = async newState => {
3228
3229
  if (!latest) {
3229
3230
  return newState;
3230
3231
  }
3231
- const decorations = getVisibleDiagnostics(latest.newState, diagnostics);
3232
+ const decorations = await getVisibleDiagnostics(latest.newState, diagnostics);
3232
3233
  const newEditor = {
3233
3234
  ...latest.newState,
3234
3235
  diagnostics,
@@ -3282,7 +3283,7 @@ const createEditor = async ({
3282
3283
  number(id);
3283
3284
  string(content);
3284
3285
  // TODO support overwriting language id by setting it explicitly or via settings
3285
- const charWidth = measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing);
3286
+ const charWidth = await measureCharacterWidth(fontWeight, fontSize, fontFamily, letterSpacing);
3286
3287
  const languages = await getLanguages();
3287
3288
  const computedlanguageId = getLanguageId$1(uri, languages);
3288
3289
  const editor = {
@@ -3582,9 +3583,9 @@ const editorReplaceSelections = (editor, replacement, origin) => {
3582
3583
  return replaceRange(editor, selections, replacement, origin);
3583
3584
  };
3584
3585
 
3585
- const getAccurateColumnIndexAscii = (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) => {
3586
+ const getAccurateColumnIndexAscii = async (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) => {
3586
3587
  for (let i = guess; i < line.length; i++) {
3587
- const width = measureTextWidth(line.slice(0, i), fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3588
+ const width = await measureTextWidth(line.slice(0, i), fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3588
3589
  if (eventX - width < averageCharWidth / 2) {
3589
3590
  return i;
3590
3591
  }
@@ -3631,14 +3632,13 @@ const create$8 = () => {
3631
3632
  };
3632
3633
  };
3633
3634
 
3634
- // @ts-ignore
3635
- const getAccurateColumnIndexUnicode = (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing) => {
3635
+ const getAccurateColumnIndexUnicode = async (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing) => {
3636
3636
  const segmenter = create$8();
3637
3637
  const segments = segmenter.getSegments(line);
3638
3638
  const isMonospaceFont = false;
3639
3639
  const charWidth = 0;
3640
3640
  for (const segment of segments) {
3641
- const width = measureTextWidth(line.slice(0, segment.index), fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3641
+ const width = await measureTextWidth(line.slice(0, segment.index), fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3642
3642
  if (eventX - width < averageCharWidth) {
3643
3643
  return segment.index;
3644
3644
  }
@@ -3651,13 +3651,10 @@ const isAscii = line => {
3651
3651
  return RE_ASCII.test(line);
3652
3652
  };
3653
3653
 
3654
- // @ts-ignore
3655
3654
  const guessOffset = (eventX, averageCharWidth) => {
3656
3655
  const guess = Math.round(eventX / averageCharWidth);
3657
3656
  return guess;
3658
3657
  };
3659
-
3660
- // @ts-ignore
3661
3658
  const normalizeGuess = (line, guess, tabSize) => {
3662
3659
  let normalizedGuess = guess;
3663
3660
  for (let i = 0; i < guess; i++) {
@@ -3667,9 +3664,7 @@ const normalizeGuess = (line, guess, tabSize) => {
3667
3664
  }
3668
3665
  return normalizedGuess;
3669
3666
  };
3670
-
3671
- // @ts-ignore
3672
- const getAccurateColumnIndex = (line, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth, tabSize, eventX) => {
3667
+ const getAccurateColumnIndex = async (line, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth, tabSize, eventX) => {
3673
3668
  string(line);
3674
3669
  number(fontWeight);
3675
3670
  number(fontSize);
@@ -3685,18 +3680,18 @@ const getAccurateColumnIndex = (line, fontWeight, fontSize, fontFamily, letterSp
3685
3680
  const normalizedGuess = normalizeGuess(line, guess, tabSize);
3686
3681
  const text = line.slice(0, normalizedGuess);
3687
3682
  const normalizedText = normalizeText(text, normalize, tabSize);
3688
- const actual = measureTextWidth(normalizedText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3683
+ const actual = await measureTextWidth(normalizedText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3689
3684
  const isAscii$1 = isAscii(line);
3690
3685
  if (isAscii$1) {
3691
3686
  if (Math.abs(eventX - actual) < charWidth / 2) {
3692
3687
  return normalizedGuess;
3693
3688
  }
3694
- return getAccurateColumnIndexAscii(line, normalizedGuess, charWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3689
+ return await getAccurateColumnIndexAscii(line, normalizedGuess, charWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
3695
3690
  }
3696
- return getAccurateColumnIndexUnicode(line, normalizedGuess, charWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing);
3691
+ return await getAccurateColumnIndexUnicode(line, normalizedGuess, charWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing);
3697
3692
  };
3698
3693
 
3699
- const at = (editor, eventX, eventY) => {
3694
+ const at = async (editor, eventX, eventY) => {
3700
3695
  object(editor);
3701
3696
  number(eventX);
3702
3697
  number(eventY);
@@ -3722,7 +3717,7 @@ const at = (editor, eventX, eventY) => {
3722
3717
  }
3723
3718
  const clampedRowIndex = clamp(rowIndex, 0, lines.length - 1);
3724
3719
  const line = lines[clampedRowIndex];
3725
- const columnIndex = getAccurateColumnIndex(line, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth, tabSize, eventX);
3720
+ const columnIndex = await getAccurateColumnIndex(line, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth, tabSize, eventX);
3726
3721
  return {
3727
3722
  rowIndex: clampedRowIndex,
3728
3723
  columnIndex
@@ -5269,8 +5264,8 @@ const selectWord = (editor, rowIndex, columnIndex) => {
5269
5264
  return scheduleSelections(editor, newSelections);
5270
5265
  };
5271
5266
 
5272
- const handleDoubleClick = (editor, modifier, x, y) => {
5273
- const position = at(editor, x, y);
5267
+ const handleDoubleClick = async (editor, modifier, x, y) => {
5268
+ const position = await at(editor, x, y);
5274
5269
  return selectWord(editor, position.rowIndex, position.columnIndex);
5275
5270
  };
5276
5271
 
@@ -5295,7 +5290,7 @@ const handleSingleClick = async (editor, modifier, x, y) => {
5295
5290
  number(modifier);
5296
5291
  number(x);
5297
5292
  number(y);
5298
- const position = at(editor, x, y);
5293
+ const position = await at(editor, x, y);
5299
5294
  return handleClickAtPosition(editor, modifier, position.rowIndex, position.columnIndex);
5300
5295
  };
5301
5296
 
@@ -5379,7 +5374,7 @@ const onHoverIdle = async () => {
5379
5374
  y,
5380
5375
  editor
5381
5376
  } = get();
5382
- at(editor, x, y);
5377
+ await at(editor, x, y);
5383
5378
  await showHover$1();
5384
5379
  };
5385
5380
  const hoverDelay = 300;
@@ -5416,7 +5411,7 @@ const handleMouseMoveWithAltKey = async (editor, x, y) => {
5416
5411
  object(editor);
5417
5412
  number(x);
5418
5413
  number(y);
5419
- const position = at(editor, x, y);
5414
+ const position = await at(editor, x, y);
5420
5415
  const documentOffset = offsetAt(editor, position.rowIndex, position.columnIndex);
5421
5416
  try {
5422
5417
  const definition = await getDefinition(editor, documentOffset);
@@ -5971,8 +5966,8 @@ const moveRectangleSelection = (editor, position) => {
5971
5966
  };
5972
5967
 
5973
5968
  // @ts-ignore
5974
- const moveRectangleSelectionPx = (editor, x, y) => {
5975
- at(editor, x, y);
5969
+ const moveRectangleSelectionPx = async (editor, x, y) => {
5970
+ await at(editor, x, y);
5976
5971
  };
5977
5972
 
5978
5973
  const LessThan = -1;
@@ -6107,11 +6102,11 @@ const continueScrollingAndMovingSelection = async () => {
6107
6102
  };
6108
6103
 
6109
6104
  // @ts-ignore
6110
- const moveSelectionPx = (editor, x, y) => {
6105
+ const moveSelectionPx = async (editor, x, y) => {
6111
6106
  object(editor);
6112
6107
  number(x);
6113
6108
  number(y);
6114
- const position = at(editor, x, y);
6109
+ const position = await at(editor, x, y);
6115
6110
  if (!hasListener() && (position.rowIndex < editor.minLineY || position.rowIndex > editor.maxLineY)) {
6116
6111
  requestAnimationFrame(continueScrollingAndMovingSelection);
6117
6112
  setEditor(editor);
@@ -10074,11 +10069,11 @@ const renderSelections = {
10074
10069
  isEqual(oldState, newState) {
10075
10070
  return oldState.selections === newState.selections && oldState.focused === newState.focused && oldState.minLineY === newState.minLineY && oldState.deltaX === newState.deltaX;
10076
10071
  },
10077
- apply(oldState, newState) {
10072
+ apply: async (oldState, newState) => {
10078
10073
  const {
10079
10074
  cursorInfos,
10080
10075
  selectionInfos
10081
- } = getVisible(newState);
10076
+ } = await getVisible(newState);
10082
10077
  const cursorsDom = getCursorsVirtualDom(cursorInfos);
10083
10078
  const selectionsDom = getSelectionsVirtualDom(selectionInfos);
10084
10079
  return [/* method */'setSelections', cursorsDom, selectionsDom];
@@ -10219,7 +10214,7 @@ const renderWidgets = {
10219
10214
  multiple: true
10220
10215
  };
10221
10216
  const render$6 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$1, renderDecorations, renderGutterInfo, renderWidgets, renderFocusContext, renderAdditionalFocusContext];
10222
- const renderEditor = id => {
10217
+ const renderEditor = async id => {
10223
10218
  const instance = get$5(id);
10224
10219
  if (!instance) {
10225
10220
  return [];
@@ -10232,7 +10227,7 @@ const renderEditor = id => {
10232
10227
  set$6(id, newState, newState);
10233
10228
  for (const item of render$6) {
10234
10229
  if (!item.isEqual(oldState, newState)) {
10235
- const result = item.apply(oldState, newState);
10230
+ const result = await item.apply(oldState, newState);
10236
10231
  // @ts-ignore
10237
10232
  if (item.multiple) {
10238
10233
  commands.push(...result);
@@ -10361,7 +10356,7 @@ const wrapCommand = fn => async (editorUid, ...args) => {
10361
10356
  // TODO combine neweditor with latest editor?
10362
10357
 
10363
10358
  set$6(editorUid, state, newEditor);
10364
- const commands = renderEditor(editorUid);
10359
+ const commands = await renderEditor(editorUid);
10365
10360
  return {
10366
10361
  ...newEditor,
10367
10362
  commands
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "13.1.0",
3
+ "version": "13.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"