@lvce-editor/status-bar-worker 3.32.0 → 3.32.1

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.
@@ -265,7 +265,7 @@ const {
265
265
  getCommandIds,
266
266
  getKeys,
267
267
  registerCommands,
268
- set: set$8,
268
+ set: set$9,
269
269
  wrapCommand,
270
270
  wrapGetter,
271
271
  wrapSerialAsyncCommand} = create$a();
@@ -279,13 +279,19 @@ const create$9 = (uid, uri, x, y, width, height, platform, assetDir) => {
279
279
  statusBarItemsLeft: [],
280
280
  statusBarItemsRight: [],
281
281
  uid,
282
- warningCount: 0
282
+ visibleStatusBarItemsLeft: [],
283
+ visibleStatusBarItemsRight: [],
284
+ warningCount: 0,
285
+ width
283
286
  };
284
- set$8(uid, state, state);
287
+ set$9(uid, state, state);
285
288
  };
286
289
 
290
+ const areItemsEqual = (left, right) => {
291
+ return left.length === right.length && left.every((item, index) => item === right[index]);
292
+ };
287
293
  const isEqual = (oldState, newState) => {
288
- return oldState.statusBarItemsLeft === newState.statusBarItemsLeft && oldState.statusBarItemsRight === newState.statusBarItemsRight;
294
+ return oldState.statusBarItemsLeft === newState.statusBarItemsLeft && oldState.statusBarItemsRight === newState.statusBarItemsRight && oldState.width === newState.width && areItemsEqual(oldState.visibleStatusBarItemsLeft, newState.visibleStatusBarItemsLeft) && areItemsEqual(oldState.visibleStatusBarItemsRight, newState.visibleStatusBarItemsRight);
289
295
  };
290
296
 
291
297
  const RenderItems = 4;
@@ -499,6 +505,7 @@ const TargetName = 'event.target.name';
499
505
  const ExtensionManagementWorker = 9006;
500
506
  const RendererProcess = 1670;
501
507
  const RendererWorker = 1;
508
+ const TextMeasurementWorker = 7011;
502
509
 
503
510
  const SetDom2 = 'Viewlet.setDom2';
504
511
  const SetFocusContext = 'Viewlet.setFocusContext';
@@ -616,11 +623,11 @@ const getStatusBarVirtualDom = (statusBarItemsLeft, statusBarItemsRight) => {
616
623
 
617
624
  const renderItems = (oldState, newState) => {
618
625
  const {
619
- statusBarItemsLeft,
620
- statusBarItemsRight,
621
- uid
626
+ uid,
627
+ visibleStatusBarItemsLeft,
628
+ visibleStatusBarItemsRight
622
629
  } = newState;
623
- const dom = getStatusBarVirtualDom(statusBarItemsLeft, statusBarItemsRight);
630
+ const dom = getStatusBarVirtualDom(visibleStatusBarItemsLeft, visibleStatusBarItemsRight);
624
631
  return [SetDom2, uid, dom];
625
632
  };
626
633
 
@@ -658,10 +665,10 @@ const isRight = name => {
658
665
  const state$2 = {
659
666
  rpc: undefined
660
667
  };
661
- const set$7 = rpc => {
668
+ const set$8 = rpc => {
662
669
  state$2.rpc = rpc;
663
670
  };
664
- const invoke$5 = (method, ...args) => {
671
+ const invoke$6 = (method, ...args) => {
665
672
  const {
666
673
  rpc
667
674
  } = state$2;
@@ -674,16 +681,16 @@ const handleClickEditorStatus = async (name, status) => {
674
681
  }
675
682
  switch (name) {
676
683
  case EditorEndOfLine$1:
677
- await invoke$5('QuickPick.openStatusBarPicker', 'end-of-line');
684
+ await invoke$6('QuickPick.openStatusBarPicker', 'end-of-line');
678
685
  return;
679
686
  case EditorIndentation:
680
- await invoke$5('QuickPick.openStatusBarPicker', 'indentation');
687
+ await invoke$6('QuickPick.openStatusBarPicker', 'indentation');
681
688
  return;
682
689
  case EditorLanguage$1:
683
- await invoke$5('QuickPick.openStatusBarPicker', 'language-mode');
690
+ await invoke$6('QuickPick.openStatusBarPicker', 'language-mode');
684
691
  return;
685
692
  case EditorPosition$1:
686
- await invoke$5('QuickPick.openStatusBarPicker', 'go-to-line', status.line, status.column);
693
+ await invoke$6('QuickPick.openStatusBarPicker', 'go-to-line', status.line, status.column);
687
694
  return;
688
695
  }
689
696
  };
@@ -1800,7 +1807,7 @@ const createMockRpc = ({
1800
1807
  };
1801
1808
 
1802
1809
  const rpcs = Object.create(null);
1803
- const set$6 = (id, rpc) => {
1810
+ const set$7 = (id, rpc) => {
1804
1811
  rpcs[id] = rpc;
1805
1812
  };
1806
1813
  const get$3 = id => {
@@ -1833,7 +1840,7 @@ const create = rpcId => {
1833
1840
  const mockRpc = createMockRpc({
1834
1841
  commandMap
1835
1842
  });
1836
- set$6(rpcId, mockRpc);
1843
+ set$7(rpcId, mockRpc);
1837
1844
  // @ts-ignore
1838
1845
  mockRpc[Symbol.dispose] = () => {
1839
1846
  remove(rpcId);
@@ -1842,33 +1849,45 @@ const create = rpcId => {
1842
1849
  return mockRpc;
1843
1850
  },
1844
1851
  set(rpc) {
1845
- set$6(rpcId, rpc);
1852
+ set$7(rpcId, rpc);
1846
1853
  }
1847
1854
  };
1848
1855
  };
1849
1856
 
1857
+ const {
1858
+ invoke: invoke$5,
1859
+ set: set$6
1860
+ } = create(ExtensionManagementWorker);
1861
+
1850
1862
  const {
1851
1863
  invoke: invoke$4,
1852
1864
  set: set$5
1853
- } = create(ExtensionManagementWorker);
1865
+ } = create(RendererProcess);
1854
1866
 
1855
1867
  const {
1856
1868
  invoke: invoke$3,
1857
1869
  set: set$4
1858
- } = create(RendererProcess);
1870
+ } = create(TextMeasurementWorker);
1871
+ const measureTextWidths$1 = async (texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
1872
+ return invoke$3('TextMeasurement.measureTextWidths', texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth);
1873
+ };
1859
1874
 
1860
1875
  const {
1861
1876
  invoke: invoke$2,
1862
1877
  invokeAndTransfer,
1863
1878
  set: set$3
1864
1879
  } = create(RendererWorker);
1880
+ const sendMessagePortToTextMeasurementWorker = async port => {
1881
+ const command = 'TextMeasurement.handleMessagePort';
1882
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
1883
+ };
1865
1884
  const getPreference = async key => {
1866
1885
  return await invoke$2('Preferences.get', key);
1867
1886
  };
1868
1887
 
1869
1888
  const handleClickExtensionStatusBarItem = async name => {
1870
1889
  try {
1871
- await invoke$4('Extensions.executeCommand', name);
1890
+ await invoke$5('Extensions.executeCommand', name);
1872
1891
  } catch (error) {
1873
1892
  console.error(new VError(error, `Failed to execute status bar command: ${name}`));
1874
1893
  }
@@ -1929,7 +1948,7 @@ const show2 = async (uid, menuId, x, y, args) => {
1929
1948
 
1930
1949
  const getStatusBarItemContextMenuItems = async (extensionId, providerId) => {
1931
1950
  try {
1932
- return await invoke$4('Extensions.getStatusBarItemContextMenuItems', extensionId, providerId);
1951
+ return await invoke$5('Extensions.getStatusBarItemContextMenuItems', extensionId, providerId);
1933
1952
  } catch {
1934
1953
  return [];
1935
1954
  }
@@ -2197,6 +2216,81 @@ const applyRender = (oldState, newState, diffResult) => {
2197
2216
  return commands;
2198
2217
  };
2199
2218
 
2219
+ const fontSize = 12;
2220
+ const fontFamily = 'system-ui, Ubuntu, Droid Sans, sans-serif';
2221
+ const itemPaddingAndMargin = 16;
2222
+ const iconWidth = 20;
2223
+ const horizontalGroupPadding = 14;
2224
+ const measuredWidths = new WeakMap();
2225
+ const fallbackTextWidth = 150;
2226
+ const measureTextWidths = async values => {
2227
+ if (values.length === 0) {
2228
+ return [];
2229
+ }
2230
+ try {
2231
+ return await measureTextWidths$1(values, 400, fontSize, fontFamily, 0, false, 0);
2232
+ } catch {
2233
+ return values.map(() => fallbackTextWidth);
2234
+ }
2235
+ };
2236
+ const getItemWidths = async items => {
2237
+ const unmeasuredItems = [...new Set(items.filter(item => !measuredWidths.has(item)))];
2238
+ const textElements = unmeasuredItems.flatMap(item => item.elements.filter(element => element.type === 'text'));
2239
+ const textWidths = await measureTextWidths(textElements.map(element => element.value));
2240
+ let textIndex = 0;
2241
+ for (const item of unmeasuredItems) {
2242
+ let itemWidth = itemPaddingAndMargin;
2243
+ for (const element of item.elements) {
2244
+ if (element.type === 'icon') {
2245
+ itemWidth += iconWidth;
2246
+ } else {
2247
+ itemWidth += textWidths[textIndex];
2248
+ textIndex++;
2249
+ }
2250
+ }
2251
+ measuredWidths.set(item, Promise.resolve(itemWidth));
2252
+ }
2253
+ return Promise.all(items.map(item => measuredWidths.get(item)));
2254
+ };
2255
+ const fitItems = (items, widths, availableWidth) => {
2256
+ const visible = [];
2257
+ let usedWidth = 0;
2258
+ for (let i = 0; i < items.length; i++) {
2259
+ const itemWidth = widths[i];
2260
+ if (itemWidth <= availableWidth - usedWidth) {
2261
+ visible.push(items[i]);
2262
+ usedWidth += itemWidth;
2263
+ }
2264
+ }
2265
+ return {
2266
+ items: visible,
2267
+ usedWidth
2268
+ };
2269
+ };
2270
+ const equalItems = (left, right) => {
2271
+ return left.length === right.length && left.every((item, index) => item === right[index]);
2272
+ };
2273
+ const getVisibleStatusBarItems = async state => {
2274
+ const {
2275
+ statusBarItemsLeft,
2276
+ statusBarItemsRight,
2277
+ visibleStatusBarItemsLeft,
2278
+ visibleStatusBarItemsRight,
2279
+ width
2280
+ } = state;
2281
+ const innerWidth = Math.max(0, width - horizontalGroupPadding);
2282
+ const itemWidths = await getItemWidths([...statusBarItemsLeft, ...statusBarItemsRight]);
2283
+ const leftWidths = itemWidths.slice(0, statusBarItemsLeft.length);
2284
+ const rightWidths = itemWidths.slice(statusBarItemsLeft.length);
2285
+ const right = fitItems(statusBarItemsRight, rightWidths, innerWidth);
2286
+ const left = fitItems(statusBarItemsLeft, leftWidths, innerWidth - right.usedWidth);
2287
+ return {
2288
+ ...state,
2289
+ visibleStatusBarItemsLeft: equalItems(visibleStatusBarItemsLeft, left.items) ? visibleStatusBarItemsLeft : left.items,
2290
+ visibleStatusBarItemsRight: equalItems(visibleStatusBarItemsRight, right.items) ? visibleStatusBarItemsRight : right.items
2291
+ };
2292
+ };
2293
+
2200
2294
  const state = {
2201
2295
  connected: false
2202
2296
  };
@@ -2207,10 +2301,10 @@ const isConnected = () => {
2207
2301
  return connected;
2208
2302
  };
2209
2303
  const invoke = (method, ...params) => {
2210
- return invoke$3(method, ...params);
2304
+ return invoke$4(method, ...params);
2211
2305
  };
2212
2306
  const set$1 = rpc => {
2213
- set$4(rpc);
2307
+ set$5(rpc);
2214
2308
  state.connected = true;
2215
2309
  };
2216
2310
 
@@ -2220,12 +2314,29 @@ const renderDirect = async (uid, commands) => {
2220
2314
  const transactionId = await invoke('Viewlet.queueCommands', uid, rendererProcessCommands);
2221
2315
  return [...rendererWorkerCommands, ['Viewlet.commitPending', uid, transactionId]];
2222
2316
  };
2223
- const render2 = (uid, diffResult) => {
2317
+ const render2 = async (uid, _diffResult) => {
2318
+ let current = get$5(uid);
2319
+ let {
2320
+ newState
2321
+ } = current;
2322
+ while (true) {
2323
+ const measuredState = await getVisibleStatusBarItems(newState);
2324
+ const latest = get$5(uid);
2325
+ const {
2326
+ newState: latestState
2327
+ } = latest;
2328
+ if (latestState === newState) {
2329
+ current = latest;
2330
+ newState = measuredState;
2331
+ set$9(uid, current.oldState, newState);
2332
+ break;
2333
+ }
2334
+ newState = latestState;
2335
+ }
2336
+ const diffResult = [...new Set([..._diffResult, ...diff(current.oldState, newState)])];
2224
2337
  const {
2225
- newState,
2226
2338
  oldState
2227
- } = get$5(uid);
2228
- set$8(uid, newState, newState);
2339
+ } = current;
2229
2340
  const commands = applyRender(oldState, newState, diffResult);
2230
2341
  if (!isConnected()) {
2231
2342
  return commands;
@@ -2272,7 +2383,7 @@ const handleEditorStatusChangedAll = async update => {
2272
2383
  if (newState === newerState || oldState === newerState) {
2273
2384
  continue;
2274
2385
  }
2275
- set$8(uid, oldState, newerState);
2386
+ set$9(uid, oldState, newerState);
2276
2387
  changedUids.push(uid);
2277
2388
  }
2278
2389
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2313,7 +2424,7 @@ const handleEditorStatusVisibilityChangedAll = async visible => {
2313
2424
  if (newState === newerState || oldState === newerState) {
2314
2425
  continue;
2315
2426
  }
2316
- set$8(uid, oldState, newerState);
2427
+ set$9(uid, oldState, newerState);
2317
2428
  changedUids.push(uid);
2318
2429
  }
2319
2430
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2400,8 +2511,8 @@ const getBuiltinStatusBarItems = async (errorCount, warningCount, {
2400
2511
  };
2401
2512
 
2402
2513
  const getExtensionStatusBarItems = async (assetDir, platform) => {
2403
- await invoke$4('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2404
- return invoke$4('Extensions.getStatusBarItems');
2514
+ await invoke$5('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2515
+ return invoke$5('Extensions.getStatusBarItems');
2405
2516
  };
2406
2517
 
2407
2518
  const toStatusBarItem = uiStatusBarItem => {
@@ -2479,7 +2590,7 @@ const toUiStatusBarItems = statusBarItems => {
2479
2590
 
2480
2591
  const getNotificationCount = async () => {
2481
2592
  try {
2482
- return await invoke$4('Extensions.getNotificationCount');
2593
+ return await invoke$5('Extensions.getNotificationCount');
2483
2594
  } catch {
2484
2595
  return 0;
2485
2596
  }
@@ -2558,7 +2669,7 @@ const handleExtensionManagementChange = async () => {
2558
2669
  // Loading and other updates can finish while the provider query is pending.
2559
2670
  // Only replace the extension items; retain the current lifecycle and render baseline.
2560
2671
  const current = get$5(uid);
2561
- set$8(uid, current.oldState, {
2672
+ set$9(uid, current.oldState, {
2562
2673
  ...current.newState,
2563
2674
  statusBarItemsLeft: newerState.statusBarItemsLeft
2564
2675
  });
@@ -2603,7 +2714,7 @@ const handleNotificationCountChangedAll = async count => {
2603
2714
  if (newState === newerState || oldState === newerState) {
2604
2715
  continue;
2605
2716
  }
2606
- set$8(uid, oldState, newerState);
2717
+ set$9(uid, oldState, newerState);
2607
2718
  await renderOutOfBand(uid);
2608
2719
  }
2609
2720
  };
@@ -2618,7 +2729,7 @@ const handleExtensionManagementMessagePort = async port => {
2618
2729
  commandMap: commandMap$1,
2619
2730
  messagePort: port
2620
2731
  });
2621
- set$5(rpc);
2732
+ set$6(rpc);
2622
2733
  };
2623
2734
 
2624
2735
  const supportsEditorStatusDeltas = () => true;
@@ -2672,7 +2783,7 @@ const handleWorkspaceChange = async state => {
2672
2783
  assetDir,
2673
2784
  platform
2674
2785
  } = state;
2675
- await invoke$4('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2786
+ await invoke$5('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2676
2787
  return state;
2677
2788
  };
2678
2789
 
@@ -2910,7 +3021,7 @@ const initializeQuickPickWorker = async () => {
2910
3021
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToQuickPickWorker', port, 'QuickPick.handleStatusBarMessagePort', 0);
2911
3022
  }
2912
3023
  });
2913
- set$7(rpc);
3024
+ set$8(rpc);
2914
3025
  };
2915
3026
 
2916
3027
  const initializeRenderWorker = async () => {
@@ -2920,9 +3031,21 @@ const initializeRenderWorker = async () => {
2920
3031
  set$3(rpc);
2921
3032
  };
2922
3033
 
3034
+ const send = port => {
3035
+ // @ts-ignore
3036
+ return sendMessagePortToTextMeasurementWorker(port);
3037
+ };
3038
+ const initializeTextMeasurementWorkerRpc = async () => {
3039
+ const rpc = await create$2({
3040
+ commandMap: {},
3041
+ send
3042
+ });
3043
+ set$4(rpc);
3044
+ };
3045
+
2923
3046
  const listen = async () => {
2924
3047
  registerCommands(commandMap);
2925
- await Promise.all([initializeRenderWorker(), initializeQuickPickWorker(), initializeMenuWorker()]);
3048
+ await Promise.all([initializeRenderWorker(), initializeQuickPickWorker(), initializeMenuWorker(), initializeTextMeasurementWorkerRpc()]);
2926
3049
  };
2927
3050
 
2928
3051
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "3.32.0",
3
+ "version": "3.32.1",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",