@lvce-editor/status-bar-worker 3.31.5 → 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$7,
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$7(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
 
@@ -655,16 +662,16 @@ const isRight = name => {
655
662
  return name === Notifications$1 || isEditorStatus(name);
656
663
  };
657
664
 
658
- const state$1 = {
665
+ const state$2 = {
659
666
  rpc: undefined
660
667
  };
661
- const set$6 = rpc => {
662
- state$1.rpc = rpc;
668
+ const set$8 = rpc => {
669
+ state$2.rpc = rpc;
663
670
  };
664
- const invoke$4 = (method, ...args) => {
671
+ const invoke$6 = (method, ...args) => {
665
672
  const {
666
673
  rpc
667
- } = state$1;
674
+ } = state$2;
668
675
  return rpc.invoke(method, ...args);
669
676
  };
670
677
 
@@ -674,16 +681,16 @@ const handleClickEditorStatus = async (name, status) => {
674
681
  }
675
682
  switch (name) {
676
683
  case EditorEndOfLine$1:
677
- await invoke$4('QuickPick.openStatusBarPicker', 'end-of-line');
684
+ await invoke$6('QuickPick.openStatusBarPicker', 'end-of-line');
678
685
  return;
679
686
  case EditorIndentation:
680
- await invoke$4('QuickPick.openStatusBarPicker', 'indentation');
687
+ await invoke$6('QuickPick.openStatusBarPicker', 'indentation');
681
688
  return;
682
689
  case EditorLanguage$1:
683
- await invoke$4('QuickPick.openStatusBarPicker', 'language-mode');
690
+ await invoke$6('QuickPick.openStatusBarPicker', 'language-mode');
684
691
  return;
685
692
  case EditorPosition$1:
686
- await invoke$4('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
  };
@@ -744,49 +751,6 @@ class VError extends Error {
744
751
  }
745
752
  }
746
753
 
747
- class AssertionError extends Error {
748
- constructor(message) {
749
- super(message);
750
- this.name = 'AssertionError';
751
- }
752
- }
753
- const Object$1 = 1;
754
- const Number$1 = 2;
755
- const Array$1 = 3;
756
- const String$1 = 4;
757
- const Boolean$1 = 5;
758
- const Function = 6;
759
- const Null = 7;
760
- const Unknown = 8;
761
- const getType = value => {
762
- switch (typeof value) {
763
- case 'number':
764
- return Number$1;
765
- case 'function':
766
- return Function;
767
- case 'string':
768
- return String$1;
769
- case 'object':
770
- if (value === null) {
771
- return Null;
772
- }
773
- if (Array.isArray(value)) {
774
- return Array$1;
775
- }
776
- return Object$1;
777
- case 'boolean':
778
- return Boolean$1;
779
- default:
780
- return Unknown;
781
- }
782
- };
783
- const number = value => {
784
- const type = getType(value);
785
- if (type !== Number$1) {
786
- throw new AssertionError('expected value to be of type number');
787
- }
788
- };
789
-
790
754
  const isMessagePort = value => {
791
755
  return value && value instanceof MessagePort;
792
756
  };
@@ -1843,7 +1807,7 @@ const createMockRpc = ({
1843
1807
  };
1844
1808
 
1845
1809
  const rpcs = Object.create(null);
1846
- const set$5 = (id, rpc) => {
1810
+ const set$7 = (id, rpc) => {
1847
1811
  rpcs[id] = rpc;
1848
1812
  };
1849
1813
  const get$3 = id => {
@@ -1876,7 +1840,7 @@ const create = rpcId => {
1876
1840
  const mockRpc = createMockRpc({
1877
1841
  commandMap
1878
1842
  });
1879
- set$5(rpcId, mockRpc);
1843
+ set$7(rpcId, mockRpc);
1880
1844
  // @ts-ignore
1881
1845
  mockRpc[Symbol.dispose] = () => {
1882
1846
  remove(rpcId);
@@ -1885,52 +1849,57 @@ const create = rpcId => {
1885
1849
  return mockRpc;
1886
1850
  },
1887
1851
  set(rpc) {
1888
- set$5(rpcId, rpc);
1852
+ set$7(rpcId, rpc);
1889
1853
  }
1890
1854
  };
1891
1855
  };
1892
1856
 
1893
1857
  const {
1894
- invoke: invoke$3,
1895
- set: set$4
1858
+ invoke: invoke$5,
1859
+ set: set$6
1896
1860
  } = create(ExtensionManagementWorker);
1897
1861
 
1898
1862
  const {
1899
- invoke: invoke$2,
1900
- set: set$3
1863
+ invoke: invoke$4,
1864
+ set: set$5
1901
1865
  } = create(RendererProcess);
1902
1866
 
1903
1867
  const {
1904
- invoke: invoke$1,
1868
+ invoke: invoke$3,
1869
+ set: set$4
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
+ };
1874
+
1875
+ const {
1876
+ invoke: invoke$2,
1905
1877
  invokeAndTransfer,
1906
- set: set$2
1878
+ set: set$3
1907
1879
  } = create(RendererWorker);
1908
- const showContextMenu2 = async (uid, menuId, x, y, args) => {
1909
- number(uid);
1910
- number(menuId);
1911
- number(x);
1912
- number(y);
1913
- await invoke$1('ContextMenu.show2', uid, menuId, x, y, args);
1880
+ const sendMessagePortToTextMeasurementWorker = async port => {
1881
+ const command = 'TextMeasurement.handleMessagePort';
1882
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
1914
1883
  };
1915
1884
  const getPreference = async key => {
1916
- return await invoke$1('Preferences.get', key);
1885
+ return await invoke$2('Preferences.get', key);
1917
1886
  };
1918
1887
 
1919
1888
  const handleClickExtensionStatusBarItem = async name => {
1920
1889
  try {
1921
- await invoke$3('Extensions.executeCommand', name);
1890
+ await invoke$5('Extensions.executeCommand', name);
1922
1891
  } catch (error) {
1923
1892
  console.error(new VError(error, `Failed to execute status bar command: ${name}`));
1924
1893
  }
1925
1894
  };
1926
1895
 
1927
1896
  const handleClickNotification = async () => {
1928
- await invoke$1('Viewlet.openWidget', 'NotificationCenter');
1897
+ await invoke$2('Viewlet.openWidget', 'NotificationCenter');
1929
1898
  };
1930
1899
 
1931
1900
  const handleClickProblems = async () => {
1932
1901
  // @ts-ignore
1933
- await invoke$1('Layout.showPanel', 'Problems');
1902
+ await invoke$2('Layout.showPanel', 'Problems');
1934
1903
  };
1935
1904
 
1936
1905
  const handleClick = async (state, name) => {
@@ -1960,13 +1929,26 @@ const handleClick = async (state, name) => {
1960
1929
  return state;
1961
1930
  };
1962
1931
 
1932
+ const state$1 = {
1933
+ rpc: undefined
1934
+ };
1935
+ const set$2 = rpc => {
1936
+ state$1.rpc = rpc;
1937
+ };
1938
+ const invoke$1 = (method, ...args) => {
1939
+ const {
1940
+ rpc
1941
+ } = state$1;
1942
+ return rpc.invoke(method, ...args);
1943
+ };
1944
+
1963
1945
  const show2 = async (uid, menuId, x, y, args) => {
1964
- await showContextMenu2(uid, menuId, x, y, args);
1946
+ await invoke$1('Menu.show2', uid, menuId, x, y, args);
1965
1947
  };
1966
1948
 
1967
1949
  const getStatusBarItemContextMenuItems = async (extensionId, providerId) => {
1968
1950
  try {
1969
- return await invoke$3('Extensions.getStatusBarItemContextMenuItems', extensionId, providerId);
1951
+ return await invoke$5('Extensions.getStatusBarItemContextMenuItems', extensionId, providerId);
1970
1952
  } catch {
1971
1953
  return [];
1972
1954
  }
@@ -2234,6 +2216,81 @@ const applyRender = (oldState, newState, diffResult) => {
2234
2216
  return commands;
2235
2217
  };
2236
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
+
2237
2294
  const state = {
2238
2295
  connected: false
2239
2296
  };
@@ -2244,10 +2301,10 @@ const isConnected = () => {
2244
2301
  return connected;
2245
2302
  };
2246
2303
  const invoke = (method, ...params) => {
2247
- return invoke$2(method, ...params);
2304
+ return invoke$4(method, ...params);
2248
2305
  };
2249
2306
  const set$1 = rpc => {
2250
- set$3(rpc);
2307
+ set$5(rpc);
2251
2308
  state.connected = true;
2252
2309
  };
2253
2310
 
@@ -2257,12 +2314,29 @@ const renderDirect = async (uid, commands) => {
2257
2314
  const transactionId = await invoke('Viewlet.queueCommands', uid, rendererProcessCommands);
2258
2315
  return [...rendererWorkerCommands, ['Viewlet.commitPending', uid, transactionId]];
2259
2316
  };
2260
- 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)])];
2261
2337
  const {
2262
- newState,
2263
2338
  oldState
2264
- } = get$5(uid);
2265
- set$7(uid, newState, newState);
2339
+ } = current;
2266
2340
  const commands = applyRender(oldState, newState, diffResult);
2267
2341
  if (!isConnected()) {
2268
2342
  return commands;
@@ -2309,7 +2383,7 @@ const handleEditorStatusChangedAll = async update => {
2309
2383
  if (newState === newerState || oldState === newerState) {
2310
2384
  continue;
2311
2385
  }
2312
- set$7(uid, oldState, newerState);
2386
+ set$9(uid, oldState, newerState);
2313
2387
  changedUids.push(uid);
2314
2388
  }
2315
2389
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2350,7 +2424,7 @@ const handleEditorStatusVisibilityChangedAll = async visible => {
2350
2424
  if (newState === newerState || oldState === newerState) {
2351
2425
  continue;
2352
2426
  }
2353
- set$7(uid, oldState, newerState);
2427
+ set$9(uid, oldState, newerState);
2354
2428
  changedUids.push(uid);
2355
2429
  }
2356
2430
  await Promise.all(changedUids.map(renderOutOfBand));
@@ -2437,8 +2511,8 @@ const getBuiltinStatusBarItems = async (errorCount, warningCount, {
2437
2511
  };
2438
2512
 
2439
2513
  const getExtensionStatusBarItems = async (assetDir, platform) => {
2440
- await invoke$3('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2441
- return invoke$3('Extensions.getStatusBarItems');
2514
+ await invoke$5('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2515
+ return invoke$5('Extensions.getStatusBarItems');
2442
2516
  };
2443
2517
 
2444
2518
  const toStatusBarItem = uiStatusBarItem => {
@@ -2516,7 +2590,7 @@ const toUiStatusBarItems = statusBarItems => {
2516
2590
 
2517
2591
  const getNotificationCount = async () => {
2518
2592
  try {
2519
- return await invoke$3('Extensions.getNotificationCount');
2593
+ return await invoke$5('Extensions.getNotificationCount');
2520
2594
  } catch {
2521
2595
  return 0;
2522
2596
  }
@@ -2595,7 +2669,7 @@ const handleExtensionManagementChange = async () => {
2595
2669
  // Loading and other updates can finish while the provider query is pending.
2596
2670
  // Only replace the extension items; retain the current lifecycle and render baseline.
2597
2671
  const current = get$5(uid);
2598
- set$7(uid, current.oldState, {
2672
+ set$9(uid, current.oldState, {
2599
2673
  ...current.newState,
2600
2674
  statusBarItemsLeft: newerState.statusBarItemsLeft
2601
2675
  });
@@ -2640,7 +2714,7 @@ const handleNotificationCountChangedAll = async count => {
2640
2714
  if (newState === newerState || oldState === newerState) {
2641
2715
  continue;
2642
2716
  }
2643
- set$7(uid, oldState, newerState);
2717
+ set$9(uid, oldState, newerState);
2644
2718
  await renderOutOfBand(uid);
2645
2719
  }
2646
2720
  };
@@ -2655,7 +2729,7 @@ const handleExtensionManagementMessagePort = async port => {
2655
2729
  commandMap: commandMap$1,
2656
2730
  messagePort: port
2657
2731
  });
2658
- set$4(rpc);
2732
+ set$6(rpc);
2659
2733
  };
2660
2734
 
2661
2735
  const supportsEditorStatusDeltas = () => true;
@@ -2667,7 +2741,7 @@ const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess =
2667
2741
  throw new TypeError(`Viewlet command not found: ${command}`);
2668
2742
  }
2669
2743
  await fn(uid, ...args);
2670
- await invoke$1('Viewlet.requestRender', uid);
2744
+ await invoke$2('Viewlet.requestRender', uid);
2671
2745
  };
2672
2746
  const rpc = await create$4({
2673
2747
  commandMap: {
@@ -2709,7 +2783,7 @@ const handleWorkspaceChange = async state => {
2709
2783
  assetDir,
2710
2784
  platform
2711
2785
  } = state;
2712
- await invoke$3('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2786
+ await invoke$5('Extensions.activateByEvent', 'onStatusBarItem', assetDir, platform);
2713
2787
  return state;
2714
2788
  };
2715
2789
 
@@ -2930,6 +3004,16 @@ const commandMap = {
2930
3004
  'StatusBar.terminate': terminate
2931
3005
  };
2932
3006
 
3007
+ const initializeMenuWorker = async () => {
3008
+ const rpc = await create$2({
3009
+ commandMap: {},
3010
+ async send(port) {
3011
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMenuWorker', port);
3012
+ }
3013
+ });
3014
+ set$2(rpc);
3015
+ };
3016
+
2933
3017
  const initializeQuickPickWorker = async () => {
2934
3018
  const rpc = await create$2({
2935
3019
  commandMap: {},
@@ -2937,19 +3021,31 @@ const initializeQuickPickWorker = async () => {
2937
3021
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToQuickPickWorker', port, 'QuickPick.handleStatusBarMessagePort', 0);
2938
3022
  }
2939
3023
  });
2940
- set$6(rpc);
3024
+ set$8(rpc);
2941
3025
  };
2942
3026
 
2943
3027
  const initializeRenderWorker = async () => {
2944
3028
  const rpc = await create$1({
2945
3029
  commandMap: commandMap
2946
3030
  });
2947
- set$2(rpc);
3031
+ set$3(rpc);
3032
+ };
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);
2948
3044
  };
2949
3045
 
2950
3046
  const listen = async () => {
2951
3047
  registerCommands(commandMap);
2952
- await Promise.all([initializeRenderWorker(), initializeQuickPickWorker()]);
3048
+ await Promise.all([initializeRenderWorker(), initializeQuickPickWorker(), initializeMenuWorker(), initializeTextMeasurementWorkerRpc()]);
2953
3049
  };
2954
3050
 
2955
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.31.5",
3
+ "version": "3.32.1",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",