@lvce-editor/extension-host-worker 3.15.0 → 3.17.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.
@@ -89,7 +89,7 @@ const fn = value => {
89
89
  }
90
90
  };
91
91
 
92
- const state$c = {
92
+ const state$f = {
93
93
  /** @type{any[]} */
94
94
  onDidOpenEditorListeners: [],
95
95
  /** @type{any[]} */
@@ -101,19 +101,19 @@ const state$c = {
101
101
  textDocuments: Object.create(null)
102
102
  };
103
103
  const setDocument = (textDocumentId, textDocument) => {
104
- state$c.textDocuments[textDocumentId] = textDocument;
104
+ state$f.textDocuments[textDocumentId] = textDocument;
105
105
  };
106
106
  const getDidOpenListeners = () => {
107
- return state$c.onDidSaveTextDocumentListeners;
107
+ return state$f.onDidSaveTextDocumentListeners;
108
108
  };
109
109
  const getWillChangeListeners = () => {
110
- return state$c.onWillChangeEditorListeners;
110
+ return state$f.onWillChangeEditorListeners;
111
111
  };
112
112
  const getDidChangeListeners = () => {
113
- return state$c.onDidChangeTextDocumentListeners;
113
+ return state$f.onDidChangeTextDocumentListeners;
114
114
  };
115
115
  const getDocument = textDocumentId => {
116
- return state$c.textDocuments[textDocumentId];
116
+ return state$f.textDocuments[textDocumentId];
117
117
  };
118
118
 
119
119
  const getOffset$1 = (textDocument, position) => {
@@ -303,11 +303,11 @@ const syncIncremental = (textDocumentId, changes) => {
303
303
  textDocument.text = before + syntheticChange.inserted + after;
304
304
  runListenersSafe(getDidChangeListeners(), textDocument, syntheticChanges);
305
305
  };
306
- const get$6 = textDocumentId => {
306
+ const get$a = textDocumentId => {
307
307
  const textDocument = getDocument(textDocumentId);
308
308
  return textDocument;
309
309
  };
310
- const getText$1 = textDocument => {
310
+ const getText$2 = textDocument => {
311
311
  return textDocument.text;
312
312
  };
313
313
  const setLanguageId = (textDocumentId, languageId) => {
@@ -319,8 +319,8 @@ const setLanguageId = (textDocumentId, languageId) => {
319
319
  runListenersSafe(getDidOpenListeners(), newTextDocument);
320
320
  };
321
321
 
322
- const BABEL_PARSER_SYNTAX_ERROR = 'BABEL_PARSER_SYNTAX_ERROR';
323
322
  const E_NO_PROVIDER_FOUND = 'E_NO_PROVIDER_FOUND';
323
+ const BABEL_PARSER_SYNTAX_ERROR = 'BABEL_PARSER_SYNTAX_ERROR';
324
324
 
325
325
  class NoProviderFoundError extends Error {
326
326
  constructor(message) {
@@ -439,9 +439,9 @@ const getCombinedMessage = (error, message) => {
439
439
  }
440
440
  return stringifiedError;
441
441
  };
442
- const NewLine$2 = '\n';
442
+ const NewLine$3 = '\n';
443
443
  const getNewLineIndex$1 = (string, startIndex = undefined) => {
444
- return string.indexOf(NewLine$2, startIndex);
444
+ return string.indexOf(NewLine$3, startIndex);
445
445
  };
446
446
  const mergeStacks = (parent, child) => {
447
447
  if (!child) {
@@ -535,7 +535,7 @@ const registerMethod = ({
535
535
  }) => {
536
536
  context[`execute${name}Provider`] = async function (textDocumentId, ...params) {
537
537
  try {
538
- const textDocument = get$6(textDocumentId);
538
+ const textDocument = get$a(textDocumentId);
539
539
  if (!textDocument) {
540
540
  throw new Error(`textDocument with id ${textDocumentId} not found`);
541
541
  }
@@ -670,12 +670,12 @@ const executeOrganizeImports = async uid => {
670
670
  if (!organizeImportsAction) {
671
671
  return [];
672
672
  }
673
- const textDocument = get$6(uid);
673
+ const textDocument = get$a(uid);
674
674
  const edits = await organizeImportsAction.execute(textDocument);
675
675
  return edits;
676
676
  };
677
677
 
678
- const state$b = {
678
+ const state$e = {
679
679
  commands: Object.create(null)
680
680
  };
681
681
  const getCommandDisplay = command => {
@@ -698,10 +698,10 @@ const registerCommand = command => {
698
698
  if (!command.execute) {
699
699
  throw new Error('command is missing execute function');
700
700
  }
701
- if (command.id in state$b.commands) {
701
+ if (command.id in state$e.commands) {
702
702
  throw new Error(`command cannot be registered multiple times`);
703
703
  }
704
- state$b.commands[command.id] = command;
704
+ state$e.commands[command.id] = command;
705
705
  } catch (error) {
706
706
  const commandDisplayId = getCommandDisplay(command);
707
707
  throw new VError(error, `Failed to register command${commandDisplayId}`);
@@ -709,7 +709,7 @@ const registerCommand = command => {
709
709
  };
710
710
  const executeCommand = async (id, ...args) => {
711
711
  try {
712
- const command = state$b.commands[id];
712
+ const command = state$e.commands[id];
713
713
  if (!command) {
714
714
  throw new Error(`command ${id} not found`);
715
715
  }
@@ -748,40 +748,40 @@ const {
748
748
  }]
749
749
  });
750
750
 
751
- const state$a = {
751
+ const state$d = {
752
752
  configuration: Object.create(null)
753
753
  };
754
754
  const getConfiguration = key => {
755
- return state$a.configuration[key] ?? '';
755
+ return state$d.configuration[key] ?? '';
756
756
  };
757
757
  const setConfigurations = preferences => {
758
- state$a.configuration = preferences;
758
+ state$d.configuration = preferences;
759
759
  };
760
760
 
761
- const state$9 = {
761
+ const state$c = {
762
762
  rpc: undefined
763
763
  };
764
764
  const invoke$2 = (method, ...params) => {
765
- const rpc = state$9.rpc;
765
+ const rpc = state$c.rpc;
766
766
  return rpc.invoke(method, ...params);
767
767
  };
768
768
  const send$1 = (method, ...params) => {
769
- const rpc = state$9.rpc;
769
+ const rpc = state$c.rpc;
770
770
  return rpc.send(method, ...params);
771
771
  };
772
772
  const invokeAndTransfer$1 = (method, ...params) => {
773
- const rpc = state$9.rpc;
773
+ const rpc = state$c.rpc;
774
774
  return rpc.invokeAndTransfer(method, ...params);
775
775
  };
776
776
  const setRpc = rpc => {
777
- state$9.rpc = rpc;
777
+ state$c.rpc = rpc;
778
778
  };
779
779
 
780
- const state$8 = {
780
+ const state$b = {
781
781
  debugProviderMap: Object.create(null)
782
782
  };
783
783
  const getDebugProvider = id => {
784
- const provider = state$8.debugProviderMap[id];
784
+ const provider = state$b.debugProviderMap[id];
785
785
  if (!provider) {
786
786
  // @ts-ignore
787
787
  throw new VError(`no debug provider "${id}" found`);
@@ -792,7 +792,7 @@ const registerDebugProvider = debugProvider => {
792
792
  if (!debugProvider.id) {
793
793
  throw new Error('Failed to register debug system provider: missing id');
794
794
  }
795
- state$8.debugProviderMap[debugProvider.id] = debugProvider;
795
+ state$b.debugProviderMap[debugProvider.id] = debugProvider;
796
796
  };
797
797
  const start = async (protocol, path) => {
798
798
  try {
@@ -948,7 +948,7 @@ const exec = async (command, args, options) => {
948
948
  };
949
949
 
950
950
  const fileSystemProviderMap = Object.create(null);
951
- const get$5 = protocol => {
951
+ const get$9 = protocol => {
952
952
  const provider = fileSystemProviderMap[protocol];
953
953
  if (!provider) {
954
954
  // @ts-ignore
@@ -956,7 +956,7 @@ const get$5 = protocol => {
956
956
  }
957
957
  return provider;
958
958
  };
959
- const set$4 = (id, provider) => {
959
+ const set$8 = (id, provider) => {
960
960
  if (!id) {
961
961
  throw new Error('Failed to register file system provider: missing id');
962
962
  }
@@ -967,11 +967,11 @@ const registerFileSystemProvider = fileSystemProvider => {
967
967
  if (!fileSystemProvider.id) {
968
968
  throw new Error('Failed to register file system provider: missing id');
969
969
  }
970
- set$4(fileSystemProvider.id, fileSystemProvider);
970
+ set$8(fileSystemProvider.id, fileSystemProvider);
971
971
  };
972
972
  const readDirWithFileTypes$2 = async (protocol, path) => {
973
973
  try {
974
- const provider = get$5(protocol);
974
+ const provider = get$9(protocol);
975
975
  return await provider.readDirWithFileTypes(path);
976
976
  } catch (error) {
977
977
  throw new VError(error, 'Failed to execute file system provider');
@@ -979,7 +979,7 @@ const readDirWithFileTypes$2 = async (protocol, path) => {
979
979
  };
980
980
  const readFile$2 = async (protocol, path) => {
981
981
  try {
982
- const provider = get$5(protocol);
982
+ const provider = get$9(protocol);
983
983
  return await provider.readFile(path);
984
984
  } catch (error) {
985
985
  throw new VError(error, 'Failed to execute file system provider');
@@ -1007,7 +1007,7 @@ const readDirWithFileTypesExternal = async path => {
1007
1007
  };
1008
1008
  const writeFile$2 = async (protocol, uri, content) => {
1009
1009
  try {
1010
- const provider = get$5(protocol);
1010
+ const provider = get$9(protocol);
1011
1011
  return await provider.writeFile(uri, content);
1012
1012
  } catch (error) {
1013
1013
  throw new VError(error, 'Failed to execute file system provider');
@@ -1015,7 +1015,7 @@ const writeFile$2 = async (protocol, uri, content) => {
1015
1015
  };
1016
1016
  const getPathSeparator = protocol => {
1017
1017
  try {
1018
- const provider = get$5(protocol);
1018
+ const provider = get$9(protocol);
1019
1019
  return provider.pathSeparator;
1020
1020
  } catch (error) {
1021
1021
  throw new VError(error, 'Failed to execute file system provider');
@@ -1188,9 +1188,9 @@ class Ipc extends EventTarget {
1188
1188
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
1189
1189
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
1190
1190
  const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
1191
- const NewLine$1 = '\n';
1191
+ const NewLine$2 = '\n';
1192
1192
  const joinLines$1 = lines => {
1193
- return lines.join(NewLine$1);
1193
+ return lines.join(NewLine$2);
1194
1194
  };
1195
1195
  const RE_AT = /^\s+at/;
1196
1196
  const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
@@ -1217,7 +1217,7 @@ const getDetails = lines => {
1217
1217
  };
1218
1218
  };
1219
1219
  const splitLines$2 = lines => {
1220
- return lines.split(NewLine$1);
1220
+ return lines.split(NewLine$2);
1221
1221
  };
1222
1222
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
1223
1223
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
@@ -1645,18 +1645,18 @@ const create$4$1 = (method, params) => {
1645
1645
  };
1646
1646
  };
1647
1647
  const callbacks = Object.create(null);
1648
- const set$3 = (id, fn) => {
1648
+ const set$7 = (id, fn) => {
1649
1649
  callbacks[id] = fn;
1650
1650
  };
1651
- const get$4 = id => {
1651
+ const get$8 = id => {
1652
1652
  return callbacks[id];
1653
1653
  };
1654
1654
  const remove$2 = id => {
1655
1655
  delete callbacks[id];
1656
1656
  };
1657
- let id = 0;
1657
+ let id$1 = 0;
1658
1658
  const create$3$1 = () => {
1659
- return ++id;
1659
+ return ++id$1;
1660
1660
  };
1661
1661
  const registerPromise = () => {
1662
1662
  const id = create$3$1();
@@ -1664,7 +1664,7 @@ const registerPromise = () => {
1664
1664
  resolve,
1665
1665
  promise
1666
1666
  } = Promise.withResolvers();
1667
- set$3(id, resolve);
1667
+ set$7(id, resolve);
1668
1668
  return {
1669
1669
  id,
1670
1670
  promise
@@ -1692,7 +1692,7 @@ class JsonRpcError extends Error {
1692
1692
  this.name = 'JsonRpcError';
1693
1693
  }
1694
1694
  }
1695
- const NewLine = '\n';
1695
+ const NewLine$1 = '\n';
1696
1696
  const DomException = 'DOMException';
1697
1697
  const ReferenceError$1 = 'ReferenceError';
1698
1698
  const SyntaxError$1 = 'SyntaxError';
@@ -1738,22 +1738,22 @@ const constructError = (message, type, name) => {
1738
1738
  return new ErrorConstructor(message);
1739
1739
  };
1740
1740
  const getNewLineIndex = (string, startIndex = undefined) => {
1741
- return string.indexOf(NewLine, startIndex);
1741
+ return string.indexOf(NewLine$1, startIndex);
1742
1742
  };
1743
1743
  const getParentStack = error => {
1744
1744
  let parentStack = error.stack || error.data || error.message || '';
1745
1745
  if (parentStack.startsWith(' at')) {
1746
- parentStack = error.message + NewLine + parentStack;
1746
+ parentStack = error.message + NewLine$1 + parentStack;
1747
1747
  }
1748
1748
  return parentStack;
1749
1749
  };
1750
1750
  const joinLines = lines => {
1751
- return lines.join(NewLine);
1751
+ return lines.join(NewLine$1);
1752
1752
  };
1753
1753
  const MethodNotFound = -32601;
1754
1754
  const Custom = -32001;
1755
1755
  const splitLines$1 = lines => {
1756
- return lines.split(NewLine);
1756
+ return lines.split(NewLine$1);
1757
1757
  };
1758
1758
  const restoreJsonRpcError = error => {
1759
1759
  if (error && error instanceof Error) {
@@ -1763,14 +1763,14 @@ const restoreJsonRpcError = error => {
1763
1763
  if (error && error.code && error.code === MethodNotFound) {
1764
1764
  const restoredError = new JsonRpcError(error.message);
1765
1765
  const parentStack = getParentStack(error);
1766
- restoredError.stack = parentStack + NewLine + currentStack;
1766
+ restoredError.stack = parentStack + NewLine$1 + currentStack;
1767
1767
  return restoredError;
1768
1768
  }
1769
1769
  if (error && error.message) {
1770
1770
  const restoredError = constructError(error.message, error.type, error.name);
1771
1771
  if (error.data) {
1772
1772
  if (error.data.stack && error.data.type && error.message) {
1773
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
1773
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
1774
1774
  } else if (error.data.stack) {
1775
1775
  restoredError.stack = error.data.stack;
1776
1776
  }
@@ -1817,14 +1817,14 @@ const unwrapJsonRpcResult = responseMessage => {
1817
1817
  }
1818
1818
  throw new JsonRpcError('unexpected response message');
1819
1819
  };
1820
- const warn = (...args) => {
1820
+ const warn$1 = (...args) => {
1821
1821
  console.warn(...args);
1822
1822
  };
1823
1823
  const resolve = (id, response) => {
1824
- const fn = get$4(id);
1824
+ const fn = get$8(id);
1825
1825
  if (!fn) {
1826
1826
  console.log(response);
1827
- warn(`callback ${id} may already be disposed`);
1827
+ warn$1(`callback ${id} may already be disposed`);
1828
1828
  return;
1829
1829
  }
1830
1830
  fn(response);
@@ -2402,7 +2402,7 @@ const getExtensionHostSubWorkerUrl = () => {
2402
2402
  };
2403
2403
  const extensionHostSubWorkerUrl = getExtensionHostSubWorkerUrl();
2404
2404
 
2405
- const set$2 = async (url, contentSecurityPolicy) => {
2405
+ const set$6 = async (url, contentSecurityPolicy) => {
2406
2406
  const pathName = new URL(url).pathname;
2407
2407
  await invoke$2('ExtensionHostWorkerContentSecurityPolicy.set', pathName, contentSecurityPolicy);
2408
2408
  };
@@ -2422,7 +2422,7 @@ const createLegacyRpc = async ({
2422
2422
  string(name);
2423
2423
  object(commandMap);
2424
2424
  if (contentSecurityPolicy) {
2425
- await set$2(url, contentSecurityPolicy);
2425
+ await set$6(url, contentSecurityPolicy);
2426
2426
  }
2427
2427
  const rpc = await create$2({
2428
2428
  method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
@@ -2443,7 +2443,7 @@ const rpcs$1 = Object.create(null);
2443
2443
  const add$1 = (id, rpc) => {
2444
2444
  rpcs$1[id] = rpc;
2445
2445
  };
2446
- const get$3 = id => {
2446
+ const get$7 = id => {
2447
2447
  return rpcs$1[id];
2448
2448
  };
2449
2449
 
@@ -2452,15 +2452,15 @@ const rpcs = Object.create(null);
2452
2452
  const register = (id, execute) => {
2453
2453
  registry[id] = execute;
2454
2454
  };
2455
- const get$2 = id => {
2455
+ const get$6 = id => {
2456
2456
  return rpcs[id];
2457
2457
  };
2458
- const set$1 = (id, rpc) => {
2458
+ const set$5 = (id, rpc) => {
2459
2459
  rpcs[id] = rpc;
2460
2460
  };
2461
2461
 
2462
2462
  const createRpcWithId$1 = async (id, commandMap, execute) => {
2463
- const info = get$3(id);
2463
+ const info = get$7(id);
2464
2464
  if (!info) {
2465
2465
  throw new Error(`rpc with id ${id} not found`);
2466
2466
  }
@@ -2476,16 +2476,16 @@ const createRpcWithId$1 = async (id, commandMap, execute) => {
2476
2476
  rpc.ipc.execute = execute;
2477
2477
  }
2478
2478
  await rpc.invoke('LoadFile.loadFile', info.url);
2479
- set$1(id, rpc);
2479
+ set$5(id, rpc);
2480
2480
  return rpc;
2481
2481
  };
2482
2482
 
2483
2483
  const getOrCreateRpc = async (id, commandMap, execute) => {
2484
- const rpc = get$2(id);
2484
+ const rpc = get$6(id);
2485
2485
  if (!rpc) {
2486
- set$1(id, createRpcWithId$1(id, commandMap, execute));
2486
+ set$5(id, createRpcWithId$1(id, commandMap, execute));
2487
2487
  }
2488
- return get$2(id);
2488
+ return get$6(id);
2489
2489
  };
2490
2490
  const createRpcWithId = ({
2491
2491
  id,
@@ -2551,17 +2551,17 @@ const {
2551
2551
  }
2552
2552
  });
2553
2553
 
2554
- const state$7 = {
2554
+ const state$a = {
2555
2555
  providers: Object.create(null)
2556
2556
  };
2557
2557
  const registerSourceControlProvider = provider => {
2558
- state$7.providers[provider.id] = provider;
2558
+ state$a.providers[provider.id] = provider;
2559
2559
  };
2560
2560
  const getFilesFromProvider = provider => {
2561
2561
  return provider.getChangedFiles();
2562
2562
  };
2563
2563
  const getChangedFiles = async providerId => {
2564
- const provider = state$7.providers[providerId];
2564
+ const provider = state$a.providers[providerId];
2565
2565
  if (!provider) {
2566
2566
  throw new Error('no source control provider found');
2567
2567
  }
@@ -2572,7 +2572,7 @@ const getChangedFiles = async providerId => {
2572
2572
  const getFileBefore = async (providerId, uri) => {
2573
2573
  string(providerId);
2574
2574
  string(uri);
2575
- const provider = state$7.providers[providerId];
2575
+ const provider = state$a.providers[providerId];
2576
2576
  if (!provider) {
2577
2577
  throw new Error('no source control provider found');
2578
2578
  }
@@ -2594,7 +2594,7 @@ const getGroupsFromProvider = async (provider, cwd) => {
2594
2594
  throw new Error('source control provider is missing required function getGroups');
2595
2595
  };
2596
2596
  const getGroups = async (providerId, cwd) => {
2597
- const provider = state$7.providers[providerId];
2597
+ const provider = state$a.providers[providerId];
2598
2598
  if (!provider) {
2599
2599
  throw new Error('no source control provider found');
2600
2600
  }
@@ -2602,14 +2602,14 @@ const getGroups = async (providerId, cwd) => {
2602
2602
  return groups;
2603
2603
  };
2604
2604
  const acceptInput = async (providerId, value) => {
2605
- const provider = state$7.providers[providerId];
2605
+ const provider = state$a.providers[providerId];
2606
2606
  if (!provider) {
2607
2607
  throw new Error('no source control provider found');
2608
2608
  }
2609
2609
  await provider.acceptInput(value);
2610
2610
  };
2611
2611
  const add = async path => {
2612
- const provider = Object.values(state$7.providers)[0];
2612
+ const provider = Object.values(state$a.providers)[0];
2613
2613
  if (!provider) {
2614
2614
  return;
2615
2615
  }
@@ -2617,7 +2617,7 @@ const add = async path => {
2617
2617
  await provider.add(path);
2618
2618
  };
2619
2619
  const discard = async path => {
2620
- const provider = Object.values(state$7.providers)[0];
2620
+ const provider = Object.values(state$a.providers)[0];
2621
2621
  if (!provider) {
2622
2622
  return;
2623
2623
  }
@@ -2627,7 +2627,7 @@ const discard = async path => {
2627
2627
  const getEnabledProviderIds = async (scheme, root) => {
2628
2628
  string(scheme);
2629
2629
  string(root);
2630
- const providers = Object.values(state$7.providers);
2630
+ const providers = Object.values(state$a.providers);
2631
2631
  const enabledIds = [];
2632
2632
  for (const provider of providers) {
2633
2633
  // @ts-ignore
@@ -2656,7 +2656,7 @@ const {
2656
2656
  }
2657
2657
  });
2658
2658
 
2659
- const state$6 = {
2659
+ const state$9 = {
2660
2660
  textSearchProviders: Object.create(null)
2661
2661
  };
2662
2662
  const registerTextSearchProvider = textSearchProvider => {
@@ -2667,14 +2667,14 @@ const registerTextSearchProvider = textSearchProvider => {
2667
2667
  if (!textSearchProvider.scheme) {
2668
2668
  throw new Error('textSearchProvider is missing scheme');
2669
2669
  }
2670
- state$6.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
2670
+ state$9.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
2671
2671
  } catch (error) {
2672
2672
  throw new VError(error, 'Failed to register text search provider');
2673
2673
  }
2674
2674
  };
2675
2675
  const executeTextSearchProvider = async (scheme, query) => {
2676
2676
  try {
2677
- const textSearchProvider = state$6.textSearchProviders[scheme];
2677
+ const textSearchProvider = state$9.textSearchProviders[scheme];
2678
2678
  if (!textSearchProvider) {
2679
2679
  throw new Error(`No text search provider for ${scheme} found`);
2680
2680
  }
@@ -2864,14 +2864,14 @@ const createWorker = async ({
2864
2864
  return rpc;
2865
2865
  };
2866
2866
 
2867
- const state$5 = {
2867
+ const state$8 = {
2868
2868
  workspacePath: ''
2869
2869
  };
2870
2870
  const setWorkspacePath = path => {
2871
- state$5.workspacePath = path;
2871
+ state$8.workspacePath = path;
2872
2872
  };
2873
2873
  const getWorkspaceFolder = path => {
2874
- return state$5.workspacePath;
2874
+ return state$8.workspacePath;
2875
2875
  };
2876
2876
 
2877
2877
  class FormattingError extends Error {
@@ -2969,7 +2969,7 @@ const api = {
2969
2969
  registerTabCompletionProvider: registerTabCompletionProvider,
2970
2970
  executeTabCompletionProvider: executeTabCompletionProvider,
2971
2971
  // Text Document
2972
- getTextFromTextDocument: getText$1,
2972
+ getTextFromTextDocument: getText$2,
2973
2973
  // Text Search
2974
2974
  registerTextSearchProvider: registerTextSearchProvider,
2975
2975
  executeTextSearchProvider: executeTextSearchProvider,
@@ -3024,7 +3024,7 @@ const handleUnhandledRejection = event => {
3024
3024
  console.error(output);
3025
3025
  };
3026
3026
 
3027
- const state$4 = {
3027
+ const state$7 = {
3028
3028
  /**
3029
3029
  * @type {any[]}
3030
3030
  */
@@ -3032,10 +3032,10 @@ const state$4 = {
3032
3032
  };
3033
3033
  const addError = error => {
3034
3034
  // @ts-ignore
3035
- state$4.errors.push(error);
3035
+ state$7.errors.push(error);
3036
3036
  };
3037
3037
  const hasRecentErrors = () => {
3038
- return state$4.errors.length > 0;
3038
+ return state$7.errors.length > 0;
3039
3039
  };
3040
3040
  const getRecentError = () => {
3041
3041
  };
@@ -3084,238 +3084,835 @@ const applyBulkReplacement = async (files, ranges, replacement) => {
3084
3084
  throw new Error('not implemented');
3085
3085
  };
3086
3086
 
3087
- const getAssetDir = () => {
3088
- // @ts-ignore
3089
- if (typeof ASSET_DIR !== 'undefined') {
3090
- // @ts-ignore
3091
- return ASSET_DIR;
3092
- }
3093
- if (platform === Electron) {
3094
- return '../../../../..';
3095
- }
3096
- return '';
3097
- };
3098
- const assetDir = getAssetDir();
3099
-
3100
- const iframeWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/iframe-worker/dist/iframeWorkerMain.js`;
3101
-
3102
- const get$1 = key => {
3103
- return invoke$2('Preferences.get', key);
3104
- };
3105
-
3106
- const getConfiguredIframeWorkerUrl = async () => {
3107
- let configuredWorkerUrl = (await get$1('develop.iframeWorkerPath')) || '';
3108
- if (configuredWorkerUrl) {
3109
- configuredWorkerUrl = '/remote' + configuredWorkerUrl;
3110
- }
3111
- configuredWorkerUrl = configuredWorkerUrl || iframeWorkerUrl;
3112
- return configuredWorkerUrl;
3087
+ const addCssStyleSheet = (id, css) => {
3088
+ return invoke$2('Css.addCssStyleSheet', id, css);
3113
3089
  };
3114
3090
 
3115
- const state$3 = {
3116
- id: 0
3117
- };
3118
- const create$1 = () => {
3119
- return ++state$3.id;
3120
- };
3091
+ const NewLine = '\n';
3121
3092
 
3122
- const commandMap$1 = {
3123
- 'WebView.compatExtensionHostWorkerInvoke': (...args) => invoke$2('WebView.compatExtensionHostWorkerInvoke', ...args),
3124
- 'WebView.compatExtensionHostWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatExtensionHostWorkerInvokeAndTransfer', ...args),
3125
- 'WebView.compatRendererProcessInvoke': (...args) => invoke$2('WebView.compatRendererProcessInvoke', ...args),
3126
- 'WebView.compatRendererProcessInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatRendererProcessInvokeAndTransfer', ...args),
3127
- // @ts-ignore
3128
- 'WebView.compatRendererWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1(...args),
3129
- // @ts-ignore
3130
- 'WebView.compatRendererWorkerInvoke': (...args) => invoke$2(...args),
3131
- 'WebView.compatSharedProcessInvoke': (...args) => invoke$2('WebView.compatSharedProcessInvoke', ...args),
3132
- 'WebView.getSavedState': (...args) => invoke$2('WebView.getSavedState', ...args),
3133
- 'WebView.getWebViewInfo': (...args) => invoke$2('WebView.getWebViewInfo', ...args),
3134
- 'WebView.getWebViews': (...args) => invoke$2('WebView.getWebViews', ...args),
3135
- 'WebView.setPort': (...args) => invoke$2('WebView.setPort', ...args),
3136
- 'ExtensionHostManagement.activateByEvent': (...args) => invoke$2('ExtensionHostManagement.activateByEvent', ...args),
3137
- 'WebView.getRemoteUrl': options => getRemoteUrlForWebView(options.uri, options)
3138
- };
3139
- const launchIframeWorker = async () => {
3140
- const configuredWorkerUrl = await getConfiguredIframeWorkerUrl();
3141
- const name = 'Iframe Worker';
3142
- const id = create$1();
3143
- const rpc = await create$2({
3144
- method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
3145
- name,
3146
- url: configuredWorkerUrl,
3147
- id,
3148
- commandMap: commandMap$1
3149
- });
3150
- return rpc;
3093
+ const warn = (...args) => {
3094
+ console.warn(...args);
3151
3095
  };
3152
3096
 
3153
- let workerPromise;
3154
- const ensureWorker = () => {
3155
- if (!workerPromise) {
3156
- workerPromise = launchIframeWorker();
3157
- }
3158
- return workerPromise;
3097
+ const transparent = (color, factor) => {
3098
+ return color;
3159
3099
  };
3160
- const invoke = async (method, ...params) => {
3161
- const rpc = await ensureWorker();
3162
- return rpc.invoke(method, ...params);
3163
- };
3164
-
3165
- const createWebView3 = async ({
3166
- id,
3167
- uri,
3168
- isGitpod,
3169
- platform,
3170
- assetDir,
3171
- webViewScheme,
3172
- useNewWebViewHandler
3173
- }) => {
3174
- await invoke('WebView.create3', {
3175
- id,
3176
- uri,
3177
- isGitpod,
3178
- platform,
3179
- assetDir,
3180
- webViewScheme,
3181
- useNewWebViewHandler
3182
- });
3100
+ const toColorRule = ([key, value]) => {
3101
+ return ` --${key}: ${value};`;
3183
3102
  };
3184
-
3185
- const createWebViewWorkerRpc = async (rpcInfo, port) => {
3186
- // TODO this function is called from the iframe worker to create a direct
3187
- // connection between a webview/iframe and it's webworker. For this to work
3188
- // the iframe worker creates a messagechannel and sends one messageport to the webview
3189
- // and the other messageport to the webworker. This enables direct communication via
3190
- // the two message ports
3191
-
3192
- // TODO have a way so that the worker already includes the webview api and the extension
3193
- // host subworker doesn't need to import the other file
3194
- await invokeAndTransfer$1('IpcParent.create', {
3195
- method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
3196
- url: extensionHostSubWorkerUrl,
3197
- name: rpcInfo.name,
3198
- raw: true,
3199
- port
3200
- });
3103
+ const toTokenColorRule = tokenColor => {
3104
+ return `.${tokenColor.name} { color: ${tokenColor.foreground} }`;
3201
3105
  };
3202
-
3203
- const BraceCompletionExecuteBraceCompletionProvider = 'ExtensionHostBraceCompletion.executeBraceCompletionProvider';
3204
- const ClosingTagExecuteClosingTagProvider = 'ExtensionHostClosingTag.executeClosingTagProvider';
3205
- const CommandExecute = 'ExtensionHostCommand.executeCommand';
3206
- const CompletionExecute = 'ExtensionHostCompletion.execute';
3207
- const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
3208
- const DefinitionExecuteDefinitionProvider = 'ExtensionHostDefinition.executeDefinitionProvider';
3209
- const DiagnosticExecuteDiagnosticProvider = 'ExtensionHost.executeDiagnosticProvider';
3210
- const ExtensionActivate = 'ExtensionHostExtension.activate';
3211
- const FileSystemGetPathSeparator = 'ExtensionHostFileSystem.getPathSeparator';
3212
- const FileSystemReadDirWithFileTypes = 'ExtensionHostFileSystem.readDirWithFileTypes';
3213
- const FileSystemReadFile = 'ExtensionHostFileSystem.readFile';
3214
- const FileSystemWriteFile = 'ExtensionHostFileSystem.writeFile';
3215
- const FormattingExecuteFormmattingProvider = 'ExtensionHostFormatting.executeFormattingProvider';
3216
- const HoverExecute = 'ExtensionHostHover.execute';
3217
- const ImplementationExecuteImplementationProvider = 'ExtensionHostImplementation.executeImplementationProvider';
3218
- const MockExec = 'ExtensionHostMockExec.mockExec';
3219
- const MockRpc = 'ExtensionHostMockRpc.mockRpc';
3220
- const OrganizeImportsExecute = 'ExtensionHostOrganizeImports.execute';
3221
- const ReferenceExecuteFileReferenceProvider = 'ExtensionHostReference.executeFileReferenceProvider';
3222
- const ReferenceExecuteReferenceProvider = 'ExtensionHostReference.executeReferenceProvider';
3223
- const SourceControlAcceptInput = 'ExtensionHostSourceControl.acceptInput';
3224
- const SourceControlAdd = 'ExtensionHostSourceControl.add';
3225
- const SourceControlDiscard = 'ExtensionHostSourceControl.discard';
3226
- const SourceControlGetChangedFiles = 'ExtensionHost.sourceControlGetChangedFiles';
3227
- const SourceControlGetEnabledProviderIds = 'ExtensionHostSourceControl.getEnabledProviderIds';
3228
- const SourceControlGetFileBefore = 'ExtensionHostSourceControl.GetFileBefore';
3229
- const SourceControlGetGroups = 'ExtensionHostSourceControl.getGroups';
3230
- const StatusBarGetStatusBarItems = 'ExtensionHost.getStatusBarItems';
3231
- const StatusBarRegisterChangeListener = 'ExtensionHostStatusBar.registerChangeListener';
3232
- const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
3233
- const TextDocumentSetLanguageId = 'ExtensionHostTextDocument.setLanguageId';
3234
- const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
3235
- const TextDocumentSyncIncremental = 'ExtensionHostTextDocument.syncIncremental';
3236
- const TextSearchExecuteTextSearchProvider = 'ExtensionHostTextSearch.executeTextSearchProvider';
3237
- const TypeDefinitionExecuteTypeDefinitionProvider = 'ExtensionHostTypeDefinition.executeTypeDefinitionProvider';
3238
- const WorkspaceSetPath = 'Workspace.setWorkspacePath';
3239
- const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
3240
- const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
3241
-
3242
- const create = () => {
3243
- return {
3244
- finished: false
3106
+ const addFallbackColors = colors => {
3107
+ const newColors = {
3108
+ ...colors
3245
3109
  };
3246
- };
3247
- const cancel = token => {
3248
- token.finished = true;
3249
- };
3250
- const isCanceled = token => {
3251
- return token.finished;
3252
- };
3253
-
3254
- const baseName = path => {
3255
- const slashIndex = path.lastIndexOf('/');
3256
- return path.slice(slashIndex + 1);
3257
- };
3258
- const getExtensionId = extension => {
3259
- if (extension && extension.id) {
3260
- return extension.id;
3261
- }
3262
- if (extension && extension.path) {
3263
- return baseName(extension.path);
3110
+ if (!newColors.ActivityBarInactiveForeground) {
3111
+ // TODO don't assign, avoid mutation
3112
+ newColors.ActivityBarInactiveForeground = transparent(newColors.ActivityBarForeground);
3264
3113
  }
3265
- return '<unknown>';
3114
+ newColors.CssVariableName ||= colors.VariableName;
3115
+ return newColors;
3266
3116
  };
3267
-
3268
- const getUrlPrefix = (platform, extensionPath) => {
3269
- if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
3270
- return extensionPath;
3117
+ const createColorThemeFromJson = (colorThemeId, colorThemeJson) => {
3118
+ if (!colorThemeJson) {
3119
+ warn(`color theme json for "${colorThemeId}" is empty: "${colorThemeJson}"`);
3120
+ return '';
3271
3121
  }
3272
- if (platform === Web) {
3273
- return extensionPath;
3122
+ if (typeof colorThemeJson !== 'object') {
3123
+ warn(`color theme json for "${colorThemeId}" cannot be converted to css: "${colorThemeJson}"`);
3124
+ return '';
3274
3125
  }
3275
- if (extensionPath.startsWith('/')) {
3276
- return `/remote${extensionPath}`;
3126
+ if (Array.isArray(colorThemeJson)) {
3127
+ warn(`color theme json for "${colorThemeId}" cannot be converted to css, it must be of type object but was of type array`);
3128
+ return '';
3277
3129
  }
3278
- return `/remote/${extensionPath}`;
3279
- };
3280
-
3281
- const handleRpcInfos = extension => {
3282
- try {
3283
- if (!extension) {
3284
- return;
3285
- }
3286
- const rpcs = extension.rpc;
3287
- const urlPrefix = getUrlPrefix(platform, extension.path);
3288
- if (!rpcs) {
3289
- return;
3290
- }
3291
- if (!Array.isArray(rpcs)) {
3292
- return;
3293
- }
3294
- for (const rpc of rpcs) {
3295
- rpc.url = `${urlPrefix}/${rpc.url}`;
3296
- add$1(rpc.id, rpc);
3297
- }
3298
- } catch (error) {
3299
- console.warn(`Failed to handle extension rpcs: ${error}`);
3130
+ const colors = colorThemeJson.colors;
3131
+ if (!colors) {
3132
+ return '';
3300
3133
  }
3301
- };
3134
+ const newColors = addFallbackColors(colors);
3135
+ const colorRules = Object.entries(newColors).map(toColorRule);
3136
+ const tokenColors = colorThemeJson.tokenColors || [];
3137
+ const tokenColorRules = tokenColors.map(toTokenColorRule);
3138
+ const extraRules = [];
3139
+ if (colors.ContrastBorder) {
3140
+ extraRules.push(`#ActivityBar, #SideBar {
3141
+ border-left: 1px solid var(--ContrastBorder);
3142
+ }`, `#Panel {
3143
+ border-top: 1px solid var(--ContrastBorder);
3144
+ }`, `#StatusBar {
3145
+ border-top: 1px solid var(--ContrastBorder);
3146
+ }`, `.ActivityBarItemBadge {
3147
+ border: 1px solid var(--ContrastBorder);
3148
+ }`, `#QuickPick {
3149
+ border: 1px solid var(--ContrastBorder);
3150
+ }`);
3151
+ }
3152
+ const colorThemeCss = `:root {\n${colorRules.join(NewLine)}\n}\n\n${tokenColorRules.join(NewLine)}\n\n${extraRules.join(NewLine)}`;
3153
+ return colorThemeCss;
3154
+ };
3155
+
3156
+ // for (let i = 0; i < 10000; i++) {
3157
+ // createColorThemeFromJson({
3158
+ // type: 'dark',
3159
+ // colors: {
3160
+ // ActivityBarBackground: 'rgb(40, 46, 47)',
3161
+ // ActivityBarForeground: '#878f8c',
3162
+ // ActivityBarActiveBackground: '#1f2727',
3163
+
3164
+ // EditorBackGround: '#1e2324',
3165
+ // EditorScrollBarBackground: 'rgba(57, 71, 71, 0.6)',
3166
+ // EditorCursorBackground: '#a8df5a',
3167
+
3168
+ // ListActiveSelectionBackground: '#515f59',
3169
+ // ListActiveSelectionForeground: '#ffffff',
3170
+ // ListHoverBackground: '#405c5033',
3171
+ // ListHoverForeground: '#e0e0e0',
3172
+ // ListInactiveSelectionBackground: '#3b474280',
3173
+
3174
+ // MainBackground: '#1e2324',
3175
+
3176
+ // PanelBackground: '#1b2020',
3177
+ // PanelBorderTopColor: 'rgba(128, 128, 128, 0.35)',
3178
+
3179
+ // SideBarBackground: '#1b2020',
3180
+
3181
+ // StatusBarBackground: 'rgb(40, 46, 47)',
3182
+ // StatusBarBorderTopColor: '#222222',
3183
+
3184
+ // TabActiveBackground: '#24292a',
3185
+ // TabInactiveBackground: '#282e2f',
3186
+
3187
+ // TitleBarBackground: 'rgb(40, 46, 47)',
3188
+ // TitleBarBorderBottomColor: '#222',
3189
+ // TitleBarColor: '#cccccc',
3190
+ // TitleBarColorInactive: 'rgba(204, 204, 204, 0.6)',
3191
+ // },
3192
+ // }) //?.
3193
+ // }
3302
3194
 
3303
- class ContentSecurityPolicyError extends Error {
3304
- constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
3305
- super(`Content Security Policy Violation: ${violatedDirective}`);
3306
- this.name = 'ContentSecurityPolicyError';
3307
- if (sourceFile) {
3308
- this.stack = `Content Security Policy Violation
3309
- at ${sourceFile}:${lineNumber}:${columnNumber}`;
3310
- } else {
3311
- this.stack = `Content Security Policy Violation
3312
- at <unknown>`;
3313
- }
3314
- }
3195
+ const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
3196
+ let idbProxyableTypes;
3197
+ let cursorAdvanceMethods;
3198
+ // This is a function to prevent it throwing up in node environments.
3199
+ function getIdbProxyableTypes() {
3200
+ return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
3315
3201
  }
3316
-
3317
- const isImportErrorChrome = error => {
3318
- return error && error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module');
3202
+ // This is a function to prevent it throwing up in node environments.
3203
+ function getCursorAdvanceMethods() {
3204
+ return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
3205
+ }
3206
+ const transactionDoneMap = new WeakMap();
3207
+ const transformCache = new WeakMap();
3208
+ const reverseTransformCache = new WeakMap();
3209
+ function promisifyRequest(request) {
3210
+ const promise = new Promise((resolve, reject) => {
3211
+ const unlisten = () => {
3212
+ request.removeEventListener('success', success);
3213
+ request.removeEventListener('error', error);
3214
+ };
3215
+ const success = () => {
3216
+ resolve(wrap(request.result));
3217
+ unlisten();
3218
+ };
3219
+ const error = () => {
3220
+ reject(request.error);
3221
+ unlisten();
3222
+ };
3223
+ request.addEventListener('success', success);
3224
+ request.addEventListener('error', error);
3225
+ });
3226
+ // This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
3227
+ // is because we create many promises from a single IDBRequest.
3228
+ reverseTransformCache.set(promise, request);
3229
+ return promise;
3230
+ }
3231
+ function cacheDonePromiseForTransaction(tx) {
3232
+ // Early bail if we've already created a done promise for this transaction.
3233
+ if (transactionDoneMap.has(tx)) return;
3234
+ const done = new Promise((resolve, reject) => {
3235
+ const unlisten = () => {
3236
+ tx.removeEventListener('complete', complete);
3237
+ tx.removeEventListener('error', error);
3238
+ tx.removeEventListener('abort', error);
3239
+ };
3240
+ const complete = () => {
3241
+ resolve();
3242
+ unlisten();
3243
+ };
3244
+ const error = () => {
3245
+ reject(tx.error || new DOMException('AbortError', 'AbortError'));
3246
+ unlisten();
3247
+ };
3248
+ tx.addEventListener('complete', complete);
3249
+ tx.addEventListener('error', error);
3250
+ tx.addEventListener('abort', error);
3251
+ });
3252
+ // Cache it for later retrieval.
3253
+ transactionDoneMap.set(tx, done);
3254
+ }
3255
+ let idbProxyTraps = {
3256
+ get(target, prop, receiver) {
3257
+ if (target instanceof IDBTransaction) {
3258
+ // Special handling for transaction.done.
3259
+ if (prop === 'done') return transactionDoneMap.get(target);
3260
+ // Make tx.store return the only store in the transaction, or undefined if there are many.
3261
+ if (prop === 'store') {
3262
+ return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
3263
+ }
3264
+ }
3265
+ // Else transform whatever we get back.
3266
+ return wrap(target[prop]);
3267
+ },
3268
+ set(target, prop, value) {
3269
+ target[prop] = value;
3270
+ return true;
3271
+ },
3272
+ has(target, prop) {
3273
+ if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
3274
+ return true;
3275
+ }
3276
+ return prop in target;
3277
+ }
3278
+ };
3279
+ function replaceTraps(callback) {
3280
+ idbProxyTraps = callback(idbProxyTraps);
3281
+ }
3282
+ function wrapFunction(func) {
3283
+ // Due to expected object equality (which is enforced by the caching in `wrap`), we
3284
+ // only create one new func per func.
3285
+ // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
3286
+ // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
3287
+ // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
3288
+ // with real promises, so each advance methods returns a new promise for the cursor object, or
3289
+ // undefined if the end of the cursor has been reached.
3290
+ if (getCursorAdvanceMethods().includes(func)) {
3291
+ return function (...args) {
3292
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3293
+ // the original object.
3294
+ func.apply(unwrap(this), args);
3295
+ return wrap(this.request);
3296
+ };
3297
+ }
3298
+ return function (...args) {
3299
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3300
+ // the original object.
3301
+ return wrap(func.apply(unwrap(this), args));
3302
+ };
3303
+ }
3304
+ function transformCachableValue(value) {
3305
+ if (typeof value === 'function') return wrapFunction(value);
3306
+ // This doesn't return, it just creates a 'done' promise for the transaction,
3307
+ // which is later returned for transaction.done (see idbObjectHandler).
3308
+ if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
3309
+ if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
3310
+ // Return the same value back if we're not going to transform it.
3311
+ return value;
3312
+ }
3313
+ function wrap(value) {
3314
+ // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
3315
+ // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
3316
+ if (value instanceof IDBRequest) return promisifyRequest(value);
3317
+ // If we've already transformed this value before, reuse the transformed value.
3318
+ // This is faster, but it also provides object equality.
3319
+ if (transformCache.has(value)) return transformCache.get(value);
3320
+ const newValue = transformCachableValue(value);
3321
+ // Not all types are transformed.
3322
+ // These may be primitive types, so they can't be WeakMap keys.
3323
+ if (newValue !== value) {
3324
+ transformCache.set(value, newValue);
3325
+ reverseTransformCache.set(newValue, value);
3326
+ }
3327
+ return newValue;
3328
+ }
3329
+ const unwrap = value => reverseTransformCache.get(value);
3330
+
3331
+ /**
3332
+ * Open a database.
3333
+ *
3334
+ * @param name Name of the database.
3335
+ * @param version Schema version.
3336
+ * @param callbacks Additional callbacks.
3337
+ */
3338
+ function openDB(name, version, {
3339
+ blocked,
3340
+ upgrade,
3341
+ blocking,
3342
+ terminated
3343
+ } = {}) {
3344
+ const request = indexedDB.open(name, version);
3345
+ const openPromise = wrap(request);
3346
+ if (upgrade) {
3347
+ request.addEventListener('upgradeneeded', event => {
3348
+ upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
3349
+ });
3350
+ }
3351
+ if (blocked) {
3352
+ request.addEventListener('blocked', event => blocked(
3353
+ // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
3354
+ event.oldVersion, event.newVersion, event));
3355
+ }
3356
+ openPromise.then(db => {
3357
+ if (terminated) db.addEventListener('close', () => terminated());
3358
+ if (blocking) {
3359
+ db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
3360
+ }
3361
+ }).catch(() => {});
3362
+ return openPromise;
3363
+ }
3364
+ const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
3365
+ const writeMethods = ['put', 'add', 'delete', 'clear'];
3366
+ const cachedMethods = new Map();
3367
+ function getMethod(target, prop) {
3368
+ if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
3369
+ return;
3370
+ }
3371
+ if (cachedMethods.get(prop)) return cachedMethods.get(prop);
3372
+ const targetFuncName = prop.replace(/FromIndex$/, '');
3373
+ const useIndex = prop !== targetFuncName;
3374
+ const isWrite = writeMethods.includes(targetFuncName);
3375
+ if (
3376
+ // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
3377
+ !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
3378
+ return;
3379
+ }
3380
+ const method = async function (storeName, ...args) {
3381
+ // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
3382
+ const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
3383
+ let target = tx.store;
3384
+ if (useIndex) target = target.index(args.shift());
3385
+ // Must reject if op rejects.
3386
+ // If it's a write operation, must reject if tx.done rejects.
3387
+ // Must reject with op rejection first.
3388
+ // Must resolve with op value.
3389
+ // Must handle both promises (no unhandled rejections)
3390
+ return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
3391
+ };
3392
+ cachedMethods.set(prop, method);
3393
+ return method;
3394
+ }
3395
+ replaceTraps(oldTraps => ({
3396
+ ...oldTraps,
3397
+ get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
3398
+ has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
3399
+ }));
3400
+ const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
3401
+ const methodMap = {};
3402
+ const advanceResults = new WeakMap();
3403
+ const ittrProxiedCursorToOriginalProxy = new WeakMap();
3404
+ const cursorIteratorTraps = {
3405
+ get(target, prop) {
3406
+ if (!advanceMethodProps.includes(prop)) return target[prop];
3407
+ let cachedFunc = methodMap[prop];
3408
+ if (!cachedFunc) {
3409
+ cachedFunc = methodMap[prop] = function (...args) {
3410
+ advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
3411
+ };
3412
+ }
3413
+ return cachedFunc;
3414
+ }
3415
+ };
3416
+ async function* iterate(...args) {
3417
+ // tslint:disable-next-line:no-this-assignment
3418
+ let cursor = this;
3419
+ if (!(cursor instanceof IDBCursor)) {
3420
+ cursor = await cursor.openCursor(...args);
3421
+ }
3422
+ if (!cursor) return;
3423
+ cursor = cursor;
3424
+ const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
3425
+ ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
3426
+ // Map this double-proxy back to the original, so other cursor methods work.
3427
+ reverseTransformCache.set(proxiedCursor, unwrap(cursor));
3428
+ while (cursor) {
3429
+ yield proxiedCursor;
3430
+ // If one of the advancing methods was not called, call continue().
3431
+ cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
3432
+ advanceResults.delete(proxiedCursor);
3433
+ }
3434
+ }
3435
+ function isIteratorProp(target, prop) {
3436
+ return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
3437
+ }
3438
+ replaceTraps(oldTraps => ({
3439
+ ...oldTraps,
3440
+ get(target, prop, receiver) {
3441
+ if (isIteratorProp(target, prop)) return iterate;
3442
+ return oldTraps.get(target, prop, receiver);
3443
+ },
3444
+ has(target, prop) {
3445
+ return isIteratorProp(target, prop) || oldTraps.has(target, prop);
3446
+ }
3447
+ }));
3448
+
3449
+ const storeId = 'lvce-keyvalue';
3450
+
3451
+ // TODO high memory usage in idb because of transactionDoneMap
3452
+
3453
+ const state$6 = {
3454
+ databases: Object.create(null),
3455
+ dbVersion: 2,
3456
+ cachedDb: undefined
3457
+ };
3458
+ const getDb$1 = async () => {
3459
+ const db = await openDB(storeId, state$6.dbVersion, {
3460
+ async upgrade(db, oldVersion) {
3461
+ if (!db.objectStoreNames.contains(storeId)) {
3462
+ await db.createObjectStore(storeId, {
3463
+ autoIncrement: true
3464
+ });
3465
+ }
3466
+ }
3467
+ });
3468
+ return db;
3469
+ };
3470
+ const getDbMemoized$1 = async () => {
3471
+ state$6.cachedDb ||= await getDb$1();
3472
+ return state$6.cachedDb;
3473
+ };
3474
+
3475
+ // TODO high memory usage in idb because of transactionDoneMap
3476
+
3477
+ const set$4 = async (key, value) => {
3478
+ try {
3479
+ const db = await getDbMemoized$1();
3480
+ await db.put(storeId, value, key);
3481
+ } catch (error) {
3482
+ throw new VError(error, 'Failed to save value to indexed db');
3483
+ }
3484
+ };
3485
+ const get$5 = async key => {
3486
+ try {
3487
+ const db = await getDbMemoized$1();
3488
+ const value = await db.get(storeId, key);
3489
+ return value;
3490
+ } catch (error) {
3491
+ throw new VError(error, 'Failed to get value from indexed db');
3492
+ }
3493
+ };
3494
+
3495
+ const getCacheKey$1 = colorThemeId => {
3496
+ return 'color-theme-' + colorThemeId;
3497
+ };
3498
+ const get$4 = colorThemeId => {
3499
+ const cacheKey = getCacheKey$1(colorThemeId);
3500
+ return get$5(cacheKey);
3501
+ };
3502
+ const set$3 = (colorThemeId, data) => {
3503
+ const cacheKey = getCacheKey$1(colorThemeId);
3504
+ return set$4(cacheKey, data);
3505
+ };
3506
+
3507
+ const GetColorThemeCssCachedIndexedDb = {
3508
+ __proto__: null,
3509
+ get: get$4,
3510
+ set: set$3
3511
+ };
3512
+
3513
+ const getText$1 = key => {
3514
+ return invoke$2('LocalStorage.getText', key);
3515
+ };
3516
+ const setText = (key, value) => {
3517
+ return invoke$2('LocalStorage.setText', key, value);
3518
+ };
3519
+
3520
+ const getCacheKey = colorThemeId => {
3521
+ return 'lvce-color-theme-' + colorThemeId;
3522
+ };
3523
+ const get$3 = colorThemeId => {
3524
+ const cacheKey = getCacheKey(colorThemeId);
3525
+ return getText$1(cacheKey);
3526
+ };
3527
+ const set$2 = (colorThemeId, data) => {
3528
+ const cacheKey = getCacheKey(colorThemeId);
3529
+ return setText(cacheKey, data);
3530
+ };
3531
+
3532
+ const GetColorThemeCssCachedLocalStorage = {
3533
+ __proto__: null,
3534
+ get: get$3,
3535
+ set: set$2
3536
+ };
3537
+
3538
+ const get$2 = colorThemeId => {
3539
+ return '';
3540
+ };
3541
+ const set$1 = (colorThemeId, data) => {
3542
+ // noop
3543
+ };
3544
+
3545
+ const GetColorThemeCssCachedNoop = {
3546
+ __proto__: null,
3547
+ get: get$2,
3548
+ set: set$1
3549
+ };
3550
+
3551
+ const get$1 = key => {
3552
+ return invoke$2('Preferences.get', key);
3553
+ };
3554
+
3555
+ const getCacheFn = config => {
3556
+ switch (config) {
3557
+ case 'localStorage':
3558
+ return GetColorThemeCssCachedLocalStorage;
3559
+ case 'indexedDb':
3560
+ return GetColorThemeCssCachedIndexedDb;
3561
+ default:
3562
+ return GetColorThemeCssCachedNoop;
3563
+ }
3564
+ };
3565
+ const getColorThemeCssCached = async (colorThemeId, getData) => {
3566
+ const config = await get$1('colorTheme.cache');
3567
+ const module = await getCacheFn(config);
3568
+ const cachedData = await module.get(colorThemeId);
3569
+ if (cachedData) {
3570
+ return cachedData;
3571
+ }
3572
+ const newData = await getData(colorThemeId);
3573
+ await module.set(colorThemeId, newData);
3574
+ return newData;
3575
+ };
3576
+
3577
+ const getColorThemeJson$2 = colorThemeId => {
3578
+ return invoke$2(/* ExtensionHost.getColorThemeJson */'ExtensionHost.getColorThemeJson', /* colorThemeId */colorThemeId);
3579
+ };
3580
+
3581
+ const getAssetDir = () => {
3582
+ // @ts-ignore
3583
+ if (typeof ASSET_DIR !== 'undefined') {
3584
+ // @ts-ignore
3585
+ return ASSET_DIR;
3586
+ }
3587
+ if (platform === Electron) {
3588
+ return '../../../../..';
3589
+ }
3590
+ return '';
3591
+ };
3592
+ const assetDir = getAssetDir();
3593
+
3594
+ const getJson = async url => {
3595
+ try {
3596
+ const response = await fetch(url);
3597
+ if (!response.ok) {
3598
+ throw new Error(response.statusText);
3599
+ }
3600
+ const json = await response.json();
3601
+ return json;
3602
+ } catch (error) {
3603
+ throw new VError(error, `Failed to get json`);
3604
+ }
3605
+ };
3606
+
3607
+ const getColorThemeUrlWeb = colorThemeId => {
3608
+ return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
3609
+ };
3610
+ const getColorThemeJson$1 = colorThemeId => {
3611
+ const url = getColorThemeUrlWeb(colorThemeId);
3612
+ // TODO handle error ?
3613
+ return getJson(url);
3614
+ };
3615
+
3616
+ const getColorThemeJson = colorThemeId => {
3617
+ if (platform === Web) {
3618
+ return getColorThemeJson$1(colorThemeId);
3619
+ }
3620
+ return getColorThemeJson$2(colorThemeId);
3621
+ };
3622
+
3623
+ const getColorThemeCssFromJson = async (colorThemeId, colorThemeJson) => {
3624
+ const colorThemeCss = createColorThemeFromJson(/* colorThemeId */colorThemeId, /* colorThemeJson */colorThemeJson);
3625
+ return colorThemeCss;
3626
+ // TODO generate color theme from jsonc
3627
+ };
3628
+ const getColorThemeCssNew = async colorThemeId => {
3629
+ const colorThemeJson = await getColorThemeJson(colorThemeId);
3630
+ const colorThemeCss = await getColorThemeCssFromJson(colorThemeId, colorThemeJson);
3631
+ return colorThemeCss;
3632
+ };
3633
+ const getColorThemeCss = colorThemeId => {
3634
+ return getColorThemeCssCached(colorThemeId, getColorThemeCssNew);
3635
+ };
3636
+
3637
+ const getMetaThemeColor = colorThemeJson => {
3638
+ return colorThemeJson && colorThemeJson.colors && colorThemeJson.colors.TitleBarBackground;
3639
+ };
3640
+
3641
+ const setThemeColor = async themeColor => {
3642
+ await invoke$2(/* Meta.setThemeColor */'Meta.setThemeColor', /* color */themeColor);
3643
+ };
3644
+
3645
+ // TODO by default color theme should come from local storage, session storage, cache storage, indexeddb or blob url -> fast initial load
3646
+ // actual color theme can be computed after workbench has loaded (most times will be the same and doesn't need to be computed)
3647
+
3648
+ const state$5 = {
3649
+ watchedTheme: ''
3650
+ };
3651
+ const FALLBACK_COLOR_THEME_ID = 'slime';
3652
+
3653
+ // TODO json parsing should also happen in renderer worker
3654
+ // so that all validation is here (json parsing errors, invalid shape, ...)
3655
+
3656
+ const applyColorTheme = async colorThemeId => {
3657
+ try {
3658
+ string(colorThemeId);
3659
+ state$5.colorTheme = colorThemeId;
3660
+ const colorThemeCss = await getColorThemeCss(colorThemeId);
3661
+ await addCssStyleSheet('ContributedColorTheme', colorThemeCss);
3662
+ if (platform === Web) {
3663
+ const themeColor = getMetaThemeColor(colorThemeId) || '';
3664
+ await setThemeColor(themeColor);
3665
+ }
3666
+ if (platform !== Web && (await get$1('development.watchColorTheme'))) {
3667
+ watch(colorThemeId);
3668
+ }
3669
+ } catch (error) {
3670
+ throw new VError(error, `Failed to apply color theme "${colorThemeId}"`);
3671
+ }
3672
+ };
3673
+ const watch = async id => {
3674
+ if (state$5.watchedTheme === id) {
3675
+ return;
3676
+ }
3677
+ state$5.watchedTheme = id;
3678
+ await invoke$2('ExtensionHost.watchColorTheme', id);
3679
+ };
3680
+ const getPreferredColorTheme = () => {
3681
+ const preferredColorTheme = get$1('workbench.colorTheme');
3682
+ return preferredColorTheme;
3683
+ };
3684
+
3685
+ // TODO test this, and also the error case
3686
+ // TODO have icon theme, color theme together (maybe)
3687
+ const hydrate$1 = async () => {
3688
+ const preferredColorTheme = await getPreferredColorTheme();
3689
+ const colorThemeId = preferredColorTheme || FALLBACK_COLOR_THEME_ID;
3690
+ try {
3691
+ await applyColorTheme(colorThemeId);
3692
+ } catch (error) {
3693
+ if (colorThemeId === FALLBACK_COLOR_THEME_ID) {
3694
+ throw error;
3695
+ }
3696
+ console.error(error);
3697
+ await applyColorTheme(FALLBACK_COLOR_THEME_ID);
3698
+ }
3699
+ };
3700
+
3701
+ const iframeWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/iframe-worker/dist/iframeWorkerMain.js`;
3702
+
3703
+ const getConfiguredIframeWorkerUrl = async () => {
3704
+ let configuredWorkerUrl = (await get$1('develop.iframeWorkerPath')) || '';
3705
+ if (configuredWorkerUrl) {
3706
+ configuredWorkerUrl = '/remote' + configuredWorkerUrl;
3707
+ }
3708
+ configuredWorkerUrl = configuredWorkerUrl || iframeWorkerUrl;
3709
+ return configuredWorkerUrl;
3710
+ };
3711
+
3712
+ const state$4 = {
3713
+ id: 0
3714
+ };
3715
+ const create$1 = () => {
3716
+ return ++state$4.id;
3717
+ };
3718
+
3719
+ const commandMap$1 = {
3720
+ 'WebView.compatExtensionHostWorkerInvoke': (...args) => invoke$2('WebView.compatExtensionHostWorkerInvoke', ...args),
3721
+ 'WebView.compatExtensionHostWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatExtensionHostWorkerInvokeAndTransfer', ...args),
3722
+ 'WebView.compatRendererProcessInvoke': (...args) => invoke$2('WebView.compatRendererProcessInvoke', ...args),
3723
+ 'WebView.compatRendererProcessInvokeAndTransfer': (...args) => invokeAndTransfer$1('WebView.compatRendererProcessInvokeAndTransfer', ...args),
3724
+ // @ts-ignore
3725
+ 'WebView.compatRendererWorkerInvokeAndTransfer': (...args) => invokeAndTransfer$1(...args),
3726
+ // @ts-ignore
3727
+ 'WebView.compatRendererWorkerInvoke': (...args) => invoke$2(...args),
3728
+ 'WebView.compatSharedProcessInvoke': (...args) => invoke$2('WebView.compatSharedProcessInvoke', ...args),
3729
+ 'WebView.getSavedState': (...args) => invoke$2('WebView.getSavedState', ...args),
3730
+ 'WebView.getWebViewInfo': (...args) => invoke$2('WebView.getWebViewInfo', ...args),
3731
+ 'WebView.getWebViews': (...args) => invoke$2('WebView.getWebViews', ...args),
3732
+ 'WebView.setPort': (...args) => invoke$2('WebView.setPort', ...args),
3733
+ 'ExtensionHostManagement.activateByEvent': (...args) => invoke$2('ExtensionHostManagement.activateByEvent', ...args),
3734
+ 'WebView.getRemoteUrl': options => getRemoteUrlForWebView(options.uri, options)
3735
+ };
3736
+ const launchIframeWorker = async () => {
3737
+ const configuredWorkerUrl = await getConfiguredIframeWorkerUrl();
3738
+ const name = 'Iframe Worker';
3739
+ const id = create$1();
3740
+ const rpc = await create$2({
3741
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
3742
+ name,
3743
+ url: configuredWorkerUrl,
3744
+ id,
3745
+ commandMap: commandMap$1
3746
+ });
3747
+ return rpc;
3748
+ };
3749
+
3750
+ let workerPromise;
3751
+ const ensureWorker = () => {
3752
+ if (!workerPromise) {
3753
+ workerPromise = launchIframeWorker();
3754
+ }
3755
+ return workerPromise;
3756
+ };
3757
+ const invoke = async (method, ...params) => {
3758
+ const rpc = await ensureWorker();
3759
+ return rpc.invoke(method, ...params);
3760
+ };
3761
+
3762
+ const createWebView3 = async ({
3763
+ id,
3764
+ uri,
3765
+ isGitpod,
3766
+ platform,
3767
+ assetDir,
3768
+ webViewScheme,
3769
+ useNewWebViewHandler
3770
+ }) => {
3771
+ await invoke('WebView.create3', {
3772
+ id,
3773
+ uri,
3774
+ isGitpod,
3775
+ platform,
3776
+ assetDir,
3777
+ webViewScheme,
3778
+ useNewWebViewHandler
3779
+ });
3780
+ };
3781
+
3782
+ const createWebViewWorkerRpc = async (rpcInfo, port) => {
3783
+ // TODO this function is called from the iframe worker to create a direct
3784
+ // connection between a webview/iframe and it's webworker. For this to work
3785
+ // the iframe worker creates a messagechannel and sends one messageport to the webview
3786
+ // and the other messageport to the webworker. This enables direct communication via
3787
+ // the two message ports
3788
+
3789
+ // TODO have a way so that the worker already includes the webview api and the extension
3790
+ // host subworker doesn't need to import the other file
3791
+ await invokeAndTransfer$1('IpcParent.create', {
3792
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
3793
+ url: extensionHostSubWorkerUrl,
3794
+ name: rpcInfo.name,
3795
+ raw: true,
3796
+ port
3797
+ });
3798
+ };
3799
+
3800
+ const BraceCompletionExecuteBraceCompletionProvider = 'ExtensionHostBraceCompletion.executeBraceCompletionProvider';
3801
+ const ClosingTagExecuteClosingTagProvider = 'ExtensionHostClosingTag.executeClosingTagProvider';
3802
+ const CommandExecute = 'ExtensionHostCommand.executeCommand';
3803
+ const CompletionExecute = 'ExtensionHostCompletion.execute';
3804
+ const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
3805
+ const DefinitionExecuteDefinitionProvider = 'ExtensionHostDefinition.executeDefinitionProvider';
3806
+ const DiagnosticExecuteDiagnosticProvider = 'ExtensionHost.executeDiagnosticProvider';
3807
+ const ExtensionActivate = 'ExtensionHostExtension.activate';
3808
+ const FileSystemGetPathSeparator = 'ExtensionHostFileSystem.getPathSeparator';
3809
+ const FileSystemReadDirWithFileTypes = 'ExtensionHostFileSystem.readDirWithFileTypes';
3810
+ const FileSystemReadFile = 'ExtensionHostFileSystem.readFile';
3811
+ const FileSystemWriteFile = 'ExtensionHostFileSystem.writeFile';
3812
+ const FormattingExecuteFormmattingProvider = 'ExtensionHostFormatting.executeFormattingProvider';
3813
+ const HoverExecute = 'ExtensionHostHover.execute';
3814
+ const ImplementationExecuteImplementationProvider = 'ExtensionHostImplementation.executeImplementationProvider';
3815
+ const MockExec = 'ExtensionHostMockExec.mockExec';
3816
+ const MockRpc = 'ExtensionHostMockRpc.mockRpc';
3817
+ const OrganizeImportsExecute = 'ExtensionHostOrganizeImports.execute';
3818
+ const ReferenceExecuteFileReferenceProvider = 'ExtensionHostReference.executeFileReferenceProvider';
3819
+ const ReferenceExecuteReferenceProvider = 'ExtensionHostReference.executeReferenceProvider';
3820
+ const SourceControlAcceptInput = 'ExtensionHostSourceControl.acceptInput';
3821
+ const SourceControlAdd = 'ExtensionHostSourceControl.add';
3822
+ const SourceControlDiscard = 'ExtensionHostSourceControl.discard';
3823
+ const SourceControlGetChangedFiles = 'ExtensionHost.sourceControlGetChangedFiles';
3824
+ const SourceControlGetEnabledProviderIds = 'ExtensionHostSourceControl.getEnabledProviderIds';
3825
+ const SourceControlGetFileBefore = 'ExtensionHostSourceControl.GetFileBefore';
3826
+ const SourceControlGetGroups = 'ExtensionHostSourceControl.getGroups';
3827
+ const StatusBarGetStatusBarItems = 'ExtensionHost.getStatusBarItems';
3828
+ const StatusBarRegisterChangeListener = 'ExtensionHostStatusBar.registerChangeListener';
3829
+ const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
3830
+ const TextDocumentSetLanguageId = 'ExtensionHostTextDocument.setLanguageId';
3831
+ const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
3832
+ const TextDocumentSyncIncremental = 'ExtensionHostTextDocument.syncIncremental';
3833
+ const TextSearchExecuteTextSearchProvider = 'ExtensionHostTextSearch.executeTextSearchProvider';
3834
+ const TypeDefinitionExecuteTypeDefinitionProvider = 'ExtensionHostTypeDefinition.executeTypeDefinitionProvider';
3835
+ const WorkspaceSetPath = 'Workspace.setWorkspacePath';
3836
+ const SelectionExecuteSelectionProvider = 'ExtensionHostSelection.executeSelectionProvider';
3837
+ const ConfigurationSetConfiguration = 'ExtensionHostConfiguration.setConfiguration';
3838
+
3839
+ const create = () => {
3840
+ return {
3841
+ finished: false
3842
+ };
3843
+ };
3844
+ const cancel = token => {
3845
+ token.finished = true;
3846
+ };
3847
+ const isCanceled = token => {
3848
+ return token.finished;
3849
+ };
3850
+
3851
+ const baseName = path => {
3852
+ const slashIndex = path.lastIndexOf('/');
3853
+ return path.slice(slashIndex + 1);
3854
+ };
3855
+ const getExtensionId = extension => {
3856
+ if (extension && extension.id) {
3857
+ return extension.id;
3858
+ }
3859
+ if (extension && extension.path) {
3860
+ return baseName(extension.path);
3861
+ }
3862
+ return '<unknown>';
3863
+ };
3864
+
3865
+ const getUrlPrefix = (platform, extensionPath) => {
3866
+ if (extensionPath.startsWith('http://') || extensionPath.startsWith('https://')) {
3867
+ return extensionPath;
3868
+ }
3869
+ if (platform === Web) {
3870
+ return extensionPath;
3871
+ }
3872
+ if (extensionPath.startsWith('/')) {
3873
+ return `/remote${extensionPath}`;
3874
+ }
3875
+ return `/remote/${extensionPath}`;
3876
+ };
3877
+
3878
+ const handleRpcInfos = extension => {
3879
+ try {
3880
+ if (!extension) {
3881
+ return;
3882
+ }
3883
+ const rpcs = extension.rpc;
3884
+ const urlPrefix = getUrlPrefix(platform, extension.path);
3885
+ if (!rpcs) {
3886
+ return;
3887
+ }
3888
+ if (!Array.isArray(rpcs)) {
3889
+ return;
3890
+ }
3891
+ for (const rpc of rpcs) {
3892
+ rpc.url = `${urlPrefix}/${rpc.url}`;
3893
+ add$1(rpc.id, rpc);
3894
+ }
3895
+ } catch (error) {
3896
+ console.warn(`Failed to handle extension rpcs: ${error}`);
3897
+ }
3898
+ };
3899
+
3900
+ class ContentSecurityPolicyError extends Error {
3901
+ constructor(violatedDirective, sourceFile, lineNumber, columnNumber) {
3902
+ super(`Content Security Policy Violation: ${violatedDirective}`);
3903
+ this.name = 'ContentSecurityPolicyError';
3904
+ if (sourceFile) {
3905
+ this.stack = `Content Security Policy Violation
3906
+ at ${sourceFile}:${lineNumber}:${columnNumber}`;
3907
+ } else {
3908
+ this.stack = `Content Security Policy Violation
3909
+ at <unknown>`;
3910
+ }
3911
+ }
3912
+ }
3913
+
3914
+ const isImportErrorChrome = error => {
3915
+ return error && error instanceof Error && error.message.startsWith('Failed to fetch dynamically imported module');
3319
3916
  };
3320
3917
 
3321
3918
  const isImportErrorFirefox = error => {
@@ -3724,7 +4321,7 @@ const mockRpc = () => {
3724
4321
  };
3725
4322
 
3726
4323
  const getStatusBarItems = async () => {
3727
- const providers = Object.values(state$7.providers);
4324
+ const providers = Object.values(state$a.providers);
3728
4325
  const statusBarItems = [];
3729
4326
  for (const provider of providers) {
3730
4327
  // @ts-ignore
@@ -3757,19 +4354,6 @@ const getBlob$2 = async url => {
3757
4354
  }
3758
4355
  };
3759
4356
 
3760
- const getJson = async url => {
3761
- try {
3762
- const response = await fetch(url);
3763
- if (!response.ok) {
3764
- throw new Error(response.statusText);
3765
- }
3766
- const json = await response.json();
3767
- return json;
3768
- } catch (error) {
3769
- throw new VError(error, `Failed to get json`);
3770
- }
3771
- };
3772
-
3773
4357
  const getText = async url => {
3774
4358
  try {
3775
4359
  const response = await fetch(url);
@@ -3906,11 +4490,11 @@ const getContentType = uri => {
3906
4490
 
3907
4491
  // TODO move this to an extension?
3908
4492
 
3909
- const state$2 = {
4493
+ const state$3 = {
3910
4494
  files: Object.create(null)
3911
4495
  };
3912
4496
  const getDirent = uri => {
3913
- return state$2.files[uri];
4497
+ return state$3.files[uri];
3914
4498
  };
3915
4499
  const readFile = uri => {
3916
4500
  const dirent = getDirent(uri);
@@ -3927,7 +4511,7 @@ const ensureParentDir = uri => {
3927
4511
  let endIndex = uri.indexOf(Slash);
3928
4512
  while (endIndex >= 0) {
3929
4513
  const part = uri.slice(startIndex, endIndex + 1);
3930
- state$2.files[part] = {
4514
+ state$3.files[part] = {
3931
4515
  type: Directory$1,
3932
4516
  content: ''
3933
4517
  };
@@ -3942,7 +4526,7 @@ const writeFile = (uri, content) => {
3942
4526
  dirent.content = content;
3943
4527
  } else {
3944
4528
  ensureParentDir(uri);
3945
- state$2.files[uri] = {
4529
+ state$3.files[uri] = {
3946
4530
  type: File$1,
3947
4531
  content
3948
4532
  };
@@ -3953,20 +4537,20 @@ const mkdir = uri => {
3953
4537
  uri += Slash;
3954
4538
  }
3955
4539
  ensureParentDir(uri);
3956
- state$2.files[uri] = {
4540
+ state$3.files[uri] = {
3957
4541
  type: Directory$1,
3958
4542
  content: ''
3959
4543
  };
3960
4544
  };
3961
4545
  const remove = uri => {
3962
4546
  const toDelete = [];
3963
- for (const key of Object.keys(state$2.files)) {
4547
+ for (const key of Object.keys(state$3.files)) {
3964
4548
  if (key.startsWith(uri)) {
3965
4549
  toDelete.push(key);
3966
4550
  }
3967
4551
  }
3968
4552
  for (const key of toDelete) {
3969
- delete state$2.files[key];
4553
+ delete state$3.files[key];
3970
4554
  }
3971
4555
  };
3972
4556
  const readDirWithFileTypes = uri => {
@@ -3974,7 +4558,7 @@ const readDirWithFileTypes = uri => {
3974
4558
  uri += Slash;
3975
4559
  }
3976
4560
  const dirents = [];
3977
- for (const [key, value] of Object.entries(state$2.files)) {
4561
+ for (const [key, value] of Object.entries(state$3.files)) {
3978
4562
  if (key.startsWith(uri)) {
3979
4563
  // @ts-ignore
3980
4564
  switch (value.type) {
@@ -4018,285 +4602,205 @@ const chmod = () => {
4018
4602
  throw new Error('[memfs] chmod not implemented');
4019
4603
  };
4020
4604
  const getFiles = () => {
4021
- return state$2.files;
4022
- };
4023
-
4024
- const getRpcInfo = rpcId => {
4025
- const info = get$3(rpcId);
4026
- if (!info) {
4027
- throw new Error(`Rpc not found ${rpcId}`);
4028
- }
4029
- return info;
4605
+ return state$3.files;
4030
4606
  };
4031
4607
 
4032
- const handleBeforeUnload = () => {
4033
- // TODO save all webviews in localstorage
4034
- // cannot use indexeddb during unload
4035
- console.log('before unload');
4608
+ const state$2 = {
4609
+ webExtensions: []
4036
4610
  };
4037
4611
 
4038
- const handleMessagePort = async port => {
4039
- await MessagePortRpcClient.create({
4040
- messagePort: port,
4041
- commandMap: {}
4042
- });
4612
+ const readJson = url => {
4613
+ return invoke$2('FileSystem.readJson', url);
4043
4614
  };
4044
4615
 
4045
- const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
4046
- let idbProxyableTypes;
4047
- let cursorAdvanceMethods;
4048
- // This is a function to prevent it throwing up in node environments.
4049
- function getIdbProxyableTypes() {
4050
- return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
4051
- }
4052
- // This is a function to prevent it throwing up in node environments.
4053
- function getCursorAdvanceMethods() {
4054
- return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
4055
- }
4056
- const transactionDoneMap = new WeakMap();
4057
- const transformCache = new WeakMap();
4058
- const reverseTransformCache = new WeakMap();
4059
- function promisifyRequest(request) {
4060
- const promise = new Promise((resolve, reject) => {
4061
- const unlisten = () => {
4062
- request.removeEventListener('success', success);
4063
- request.removeEventListener('error', error);
4064
- };
4065
- const success = () => {
4066
- resolve(wrap(request.result));
4067
- unlisten();
4068
- };
4069
- const error = () => {
4070
- reject(request.error);
4071
- unlisten();
4072
- };
4073
- request.addEventListener('success', success);
4074
- request.addEventListener('error', error);
4075
- });
4076
- // This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
4077
- // is because we create many promises from a single IDBRequest.
4078
- reverseTransformCache.set(promise, request);
4079
- return promise;
4080
- }
4081
- function cacheDonePromiseForTransaction(tx) {
4082
- // Early bail if we've already created a done promise for this transaction.
4083
- if (transactionDoneMap.has(tx)) return;
4084
- const done = new Promise((resolve, reject) => {
4085
- const unlisten = () => {
4086
- tx.removeEventListener('complete', complete);
4087
- tx.removeEventListener('error', error);
4088
- tx.removeEventListener('abort', error);
4089
- };
4090
- const complete = () => {
4091
- resolve();
4092
- unlisten();
4093
- };
4094
- const error = () => {
4095
- reject(tx.error || new DOMException('AbortError', 'AbortError'));
4096
- unlisten();
4097
- };
4098
- tx.addEventListener('complete', complete);
4099
- tx.addEventListener('error', error);
4100
- tx.addEventListener('abort', error);
4101
- });
4102
- // Cache it for later retrieval.
4103
- transactionDoneMap.set(tx, done);
4104
- }
4105
- let idbProxyTraps = {
4106
- get(target, prop, receiver) {
4107
- if (target instanceof IDBTransaction) {
4108
- // Special handling for transaction.done.
4109
- if (prop === 'done') return transactionDoneMap.get(target);
4110
- // Make tx.store return the only store in the transaction, or undefined if there are many.
4111
- if (prop === 'store') {
4112
- return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
4616
+ const findMatchingIconThemeExtension = (extensions, iconThemeId) => {
4617
+ for (const extension of extensions) {
4618
+ if (extension && extension.iconThemes) {
4619
+ for (const iconTheme of extension.iconThemes) {
4620
+ if (iconTheme.id === iconThemeId) {
4621
+ return {
4622
+ ...iconTheme,
4623
+ extensionPath: extension.path
4624
+ };
4625
+ }
4113
4626
  }
4114
4627
  }
4115
- // Else transform whatever we get back.
4116
- return wrap(target[prop]);
4117
- },
4118
- set(target, prop, value) {
4119
- target[prop] = value;
4120
- return true;
4121
- },
4122
- has(target, prop) {
4123
- if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
4124
- return true;
4125
- }
4126
- return prop in target;
4127
4628
  }
4629
+ return undefined;
4128
4630
  };
4129
- function replaceTraps(callback) {
4130
- idbProxyTraps = callback(idbProxyTraps);
4131
- }
4132
- function wrapFunction(func) {
4133
- // Due to expected object equality (which is enforced by the caching in `wrap`), we
4134
- // only create one new func per func.
4135
- // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
4136
- // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
4137
- // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
4138
- // with real promises, so each advance methods returns a new promise for the cursor object, or
4139
- // undefined if the end of the cursor has been reached.
4140
- if (getCursorAdvanceMethods().includes(func)) {
4141
- return function (...args) {
4142
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
4143
- // the original object.
4144
- func.apply(unwrap(this), args);
4145
- return wrap(this.request);
4146
- };
4631
+
4632
+ const webExtensionsUrl = `${assetDir}/config/webExtensions.json`;
4633
+
4634
+ const getSharedProcessExtensions$1 = () => {
4635
+ return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
4636
+ };
4637
+ const getStaticWebExtensions = () => {
4638
+ return getJson(webExtensionsUrl);
4639
+ };
4640
+ const getWebExtensionsWeb = async () => {
4641
+ const staticWebExtensions = await getStaticWebExtensions();
4642
+ return [...staticWebExtensions, ...state$2.webExtensions];
4643
+ };
4644
+ const isWebExtension = extension => {
4645
+ return extension && typeof extension.browser === 'string';
4646
+ };
4647
+ const getWebExtensionsDefault = async () => {
4648
+ const staticWebExtensions = await getStaticWebExtensions();
4649
+ const sharedProcessExtensions = await getSharedProcessExtensions$1();
4650
+ const sharedProcessWebExtensions = sharedProcessExtensions.filter(isWebExtension);
4651
+ return [...staticWebExtensions, sharedProcessWebExtensions, ...state$2.webExtensions];
4652
+ };
4653
+ const getWebExtensions = async () => {
4654
+ try {
4655
+ switch (platform) {
4656
+ case Web:
4657
+ return await getWebExtensionsWeb();
4658
+ default:
4659
+ return await getWebExtensionsDefault();
4660
+ }
4661
+ } catch {
4662
+ return state$2.webExtensions;
4147
4663
  }
4148
- return function (...args) {
4149
- // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
4150
- // the original object.
4151
- return wrap(func.apply(unwrap(this), args));
4152
- };
4153
- }
4154
- function transformCachableValue(value) {
4155
- if (typeof value === 'function') return wrapFunction(value);
4156
- // This doesn't return, it just creates a 'done' promise for the transaction,
4157
- // which is later returned for transaction.done (see idbObjectHandler).
4158
- if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
4159
- if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
4160
- // Return the same value back if we're not going to transform it.
4161
- return value;
4162
- }
4163
- function wrap(value) {
4164
- // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
4165
- // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
4166
- if (value instanceof IDBRequest) return promisifyRequest(value);
4167
- // If we've already transformed this value before, reuse the transformed value.
4168
- // This is faster, but it also provides object equality.
4169
- if (transformCache.has(value)) return transformCache.get(value);
4170
- const newValue = transformCachableValue(value);
4171
- // Not all types are transformed.
4172
- // These may be primitive types, so they can't be WeakMap keys.
4173
- if (newValue !== value) {
4174
- transformCache.set(value, newValue);
4175
- reverseTransformCache.set(newValue, value);
4664
+ };
4665
+
4666
+ const getSharedProcessExtensions = () => {
4667
+ return invoke$2(/* ExtensionManagement.getExtensions */'ExtensionManagement.getExtensions');
4668
+ };
4669
+ const getExtensions$1 = async () => {
4670
+ if (platform === Web) {
4671
+ const webExtensions = await getWebExtensions();
4672
+ return webExtensions;
4176
4673
  }
4177
- return newValue;
4178
- }
4179
- const unwrap = value => reverseTransformCache.get(value);
4674
+ if (platform === Remote) {
4675
+ const webExtensions = await getWebExtensions();
4676
+ const sharedProcessExtensions = await getSharedProcessExtensions();
4677
+ return [...sharedProcessExtensions, ...webExtensions];
4678
+ }
4679
+ const extensions = await getSharedProcessExtensions();
4680
+ return extensions;
4681
+ };
4180
4682
 
4181
- /**
4182
- * Open a database.
4183
- *
4184
- * @param name Name of the database.
4185
- * @param version Schema version.
4186
- * @param callbacks Additional callbacks.
4187
- */
4188
- function openDB(name, version, {
4189
- blocked,
4190
- upgrade,
4191
- blocking,
4192
- terminated
4193
- } = {}) {
4194
- const request = indexedDB.open(name, version);
4195
- const openPromise = wrap(request);
4196
- if (upgrade) {
4197
- request.addEventListener('upgradeneeded', event => {
4198
- upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
4199
- });
4683
+ const cache = Object.create(null);
4684
+ const id = 1;
4685
+ const get = () => {
4686
+ return cache[id];
4687
+ };
4688
+ const has = () => {
4689
+ return id in cache;
4690
+ };
4691
+ const set = value => {
4692
+ cache[id] = value;
4693
+ };
4694
+
4695
+ const getExtensions = () => {
4696
+ if (!has()) {
4697
+ set(getExtensions$1());
4200
4698
  }
4201
- if (blocked) {
4202
- request.addEventListener('blocked', event => blocked(
4203
- // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
4204
- event.oldVersion, event.newVersion, event));
4699
+ return get();
4700
+ };
4701
+
4702
+ const getIconThemeUrl = iconThemeId => {
4703
+ return `${assetDir}/extensions/builtin.${iconThemeId}/icon-theme.json`;
4704
+ };
4705
+
4706
+ const getIconThemeJson = async iconThemeId => {
4707
+ if (platform === Web) {
4708
+ const url = getIconThemeUrl(iconThemeId);
4709
+ const json = await getJson(url);
4710
+ return {
4711
+ json,
4712
+ extensionPath: `${assetDir}/extensions/builtin.${iconThemeId}`
4713
+ };
4205
4714
  }
4206
- openPromise.then(db => {
4207
- if (terminated) db.addEventListener('close', () => terminated());
4208
- if (blocking) {
4209
- db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
4715
+ for (const webExtension of state$2.webExtensions) {
4716
+ if (webExtension.iconThemes) {
4717
+ for (const iconTheme of webExtension.iconThemes) {
4718
+ // TODO handle error when icon theme path is not of type string
4719
+ const iconThemeUrl = `${webExtension.path}/${iconTheme.path}`;
4720
+ const json = await getJson(iconThemeUrl);
4721
+ return {
4722
+ json,
4723
+ extensionPath: webExtension.path
4724
+ };
4725
+ }
4210
4726
  }
4211
- }).catch(() => {});
4212
- return openPromise;
4213
- }
4214
- const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
4215
- const writeMethods = ['put', 'add', 'delete', 'clear'];
4216
- const cachedMethods = new Map();
4217
- function getMethod(target, prop) {
4218
- if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
4219
- return;
4220
4727
  }
4221
- if (cachedMethods.get(prop)) return cachedMethods.get(prop);
4222
- const targetFuncName = prop.replace(/FromIndex$/, '');
4223
- const useIndex = prop !== targetFuncName;
4224
- const isWrite = writeMethods.includes(targetFuncName);
4225
- if (
4226
- // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
4227
- !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
4228
- return;
4728
+ const extensions = await getExtensions();
4729
+ const iconTheme = findMatchingIconThemeExtension(extensions, iconThemeId);
4730
+ if (!iconTheme) {
4731
+ return undefined;
4229
4732
  }
4230
- const method = async function (storeName, ...args) {
4231
- // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
4232
- const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
4233
- let target = tx.store;
4234
- if (useIndex) target = target.index(args.shift());
4235
- // Must reject if op rejects.
4236
- // If it's a write operation, must reject if tx.done rejects.
4237
- // Must reject with op rejection first.
4238
- // Must resolve with op value.
4239
- // Must handle both promises (no unhandled rejections)
4240
- return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
4733
+ const iconThemePath = `${iconTheme.extensionPath}/${iconTheme.path}`;
4734
+ const iconThemeJson = await readJson(iconThemePath);
4735
+ return {
4736
+ extensionPath: iconTheme.extensionPath,
4737
+ json: iconThemeJson
4241
4738
  };
4242
- cachedMethods.set(prop, method);
4243
- return method;
4244
- }
4245
- replaceTraps(oldTraps => ({
4246
- ...oldTraps,
4247
- get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
4248
- has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
4249
- }));
4250
- const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
4251
- const methodMap = {};
4252
- const advanceResults = new WeakMap();
4253
- const ittrProxiedCursorToOriginalProxy = new WeakMap();
4254
- const cursorIteratorTraps = {
4255
- get(target, prop) {
4256
- if (!advanceMethodProps.includes(prop)) return target[prop];
4257
- let cachedFunc = methodMap[prop];
4258
- if (!cachedFunc) {
4259
- cachedFunc = methodMap[prop] = function (...args) {
4260
- advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
4261
- };
4262
- }
4263
- return cachedFunc;
4264
- }
4265
4739
  };
4266
- async function* iterate(...args) {
4267
- // tslint:disable-next-line:no-this-assignment
4268
- let cursor = this;
4269
- if (!(cursor instanceof IDBCursor)) {
4270
- cursor = await cursor.openCursor(...args);
4271
- }
4272
- if (!cursor) return;
4273
- cursor = cursor;
4274
- const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
4275
- ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
4276
- // Map this double-proxy back to the original, so other cursor methods work.
4277
- reverseTransformCache.set(proxiedCursor, unwrap(cursor));
4278
- while (cursor) {
4279
- yield proxiedCursor;
4280
- // If one of the advancing methods was not called, call continue().
4281
- cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
4282
- advanceResults.delete(proxiedCursor);
4283
- }
4284
- }
4285
- function isIteratorProp(target, prop) {
4286
- return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
4287
- }
4288
- replaceTraps(oldTraps => ({
4289
- ...oldTraps,
4290
- get(target, prop, receiver) {
4291
- if (isIteratorProp(target, prop)) return iterate;
4292
- return oldTraps.get(target, prop, receiver);
4293
- },
4294
- has(target, prop) {
4295
- return isIteratorProp(target, prop) || oldTraps.has(target, prop);
4740
+
4741
+ const getRpcInfo = rpcId => {
4742
+ const info = get$7(rpcId);
4743
+ if (!info) {
4744
+ throw new Error(`Rpc not found ${rpcId}`);
4296
4745
  }
4297
- }));
4746
+ return info;
4747
+ };
4748
+
4749
+ const handleBeforeUnload = () => {
4750
+ // TODO save all webviews in localstorage
4751
+ // cannot use indexeddb during unload
4752
+ console.log('before unload');
4753
+ };
4754
+
4755
+ const handleMessagePort = async port => {
4756
+ await MessagePortRpcClient.create({
4757
+ messagePort: port,
4758
+ commandMap: {}
4759
+ });
4760
+ };
4761
+
4762
+ const handleIconThemeChange = async () => {
4763
+ await invoke$2('IconTheme.handleIconThemeChange');
4764
+ };
4765
+
4766
+ const initialIconTheme = undefined;
4298
4767
 
4299
4768
  const state$1 = {
4769
+ seenFiles: [],
4770
+ seenFolders: [],
4771
+ hasWarned: [],
4772
+ /**
4773
+ * @type{any}
4774
+ */
4775
+ iconTheme: initialIconTheme,
4776
+ extensionPath: ''
4777
+ };
4778
+ const setTheme = iconTheme => {
4779
+ state$1.iconTheme = iconTheme.json;
4780
+ state$1.extensionPath = iconTheme.extensionPath;
4781
+ };
4782
+ const getState = () => {
4783
+ return state$1;
4784
+ };
4785
+
4786
+ const setIconTheme = async iconThemeId => {
4787
+ try {
4788
+ const iconTheme = await getIconThemeJson(iconThemeId);
4789
+ if (!iconTheme) {
4790
+ return;
4791
+ }
4792
+ setTheme(iconTheme);
4793
+ await handleIconThemeChange();
4794
+ } catch (error) {
4795
+ console.error(new VError(error, 'Failed to load icon theme'));
4796
+ }
4797
+ };
4798
+ const hydrate = async () => {
4799
+ const iconThemeId = (await get$1('icon-theme')) || 'vscode-icons';
4800
+ await setIconTheme(iconThemeId);
4801
+ };
4802
+
4803
+ const state = {
4300
4804
  databases: Object.create(null),
4301
4805
  eventId: 0,
4302
4806
  dbVersion: 1,
@@ -4312,9 +4816,9 @@ const isDataCloneError = error => {
4312
4816
 
4313
4817
  // TODO high memory usage in idb because of transactionDoneMap
4314
4818
 
4315
- const getDb$1 = async () => {
4819
+ const getDb = async () => {
4316
4820
  // @ts-ignore
4317
- const db = await openDB('session', state$1.dbVersion, {
4821
+ const db = await openDB('session', state.dbVersion, {
4318
4822
  async upgrade(db, oldVersion) {
4319
4823
  if (!db.objectStoreNames.contains('session')) {
4320
4824
  const objectStore = await db.createObjectStore('session', {
@@ -4328,13 +4832,13 @@ const getDb$1 = async () => {
4328
4832
  });
4329
4833
  return db;
4330
4834
  };
4331
- const getDbMemoized$1 = async () => {
4332
- state$1.cachedDb ||= await getDb$1();
4333
- return state$1.cachedDb;
4835
+ const getDbMemoized = async () => {
4836
+ state.cachedDb ||= await getDb();
4837
+ return state.cachedDb;
4334
4838
  };
4335
4839
  const saveValue = async (storeId, value) => {
4336
4840
  try {
4337
- const db = await getDbMemoized$1();
4841
+ const db = await getDbMemoized();
4338
4842
  await db.add('session', value);
4339
4843
  } catch (error) {
4340
4844
  if (isDataCloneError(error)) {
@@ -4346,7 +4850,7 @@ const saveValue = async (storeId, value) => {
4346
4850
  };
4347
4851
  const getValues = async storeId => {
4348
4852
  try {
4349
- const db = await getDbMemoized$1();
4853
+ const db = await getDbMemoized();
4350
4854
  const tx = db.transaction(storeId, 'readwrite');
4351
4855
  const [objects] = await Promise.all([tx.store.getAll(), tx.done]);
4352
4856
  console.log({
@@ -4358,7 +4862,7 @@ const getValues = async storeId => {
4358
4862
  }
4359
4863
  };
4360
4864
  const getValuesByIndexName = async (storeId, indexName, only) => {
4361
- const db = await getDbMemoized$1();
4865
+ const db = await getDbMemoized();
4362
4866
  const transaction = db.transaction(storeId);
4363
4867
  const index = transaction.store.index(indexName);
4364
4868
  const iterator = index.iterate(only);
@@ -4369,7 +4873,7 @@ const getValuesByIndexName = async (storeId, indexName, only) => {
4369
4873
  return objects;
4370
4874
  };
4371
4875
  const getHandleDb = async () => {
4372
- const db = await openDB('handle', state$1.dbVersion, {
4876
+ const db = await openDB('handle', state.dbVersion, {
4373
4877
  async upgrade(db, oldVersion) {
4374
4878
  if (!db.objectStoreNames.contains('file-handles-store')) {
4375
4879
  // @ts-ignore
@@ -4389,52 +4893,6 @@ const getHandle$1 = async uri => {
4389
4893
  return handle;
4390
4894
  };
4391
4895
 
4392
- const storeId = 'lvce-keyvalue';
4393
-
4394
- // TODO high memory usage in idb because of transactionDoneMap
4395
-
4396
- const state = {
4397
- databases: Object.create(null),
4398
- dbVersion: 2,
4399
- cachedDb: undefined
4400
- };
4401
- const getDb = async () => {
4402
- const db = await openDB(storeId, state.dbVersion, {
4403
- async upgrade(db, oldVersion) {
4404
- if (!db.objectStoreNames.contains(storeId)) {
4405
- await db.createObjectStore(storeId, {
4406
- autoIncrement: true
4407
- });
4408
- }
4409
- }
4410
- });
4411
- return db;
4412
- };
4413
- const getDbMemoized = async () => {
4414
- state.cachedDb ||= await getDb();
4415
- return state.cachedDb;
4416
- };
4417
-
4418
- // TODO high memory usage in idb because of transactionDoneMap
4419
-
4420
- const set = async (key, value) => {
4421
- try {
4422
- const db = await getDbMemoized();
4423
- await db.put(storeId, value, key);
4424
- } catch (error) {
4425
- throw new VError(error, 'Failed to save value to indexed db');
4426
- }
4427
- };
4428
- const get = async key => {
4429
- try {
4430
- const db = await getDbMemoized();
4431
- const value = await db.get(storeId, key);
4432
- return value;
4433
- } catch (error) {
4434
- throw new VError(error, 'Failed to get value from indexed db');
4435
- }
4436
- };
4437
-
4438
4896
  const loadWebView = async (providerId, savedState) => {
4439
4897
  const rpc = getWebView(providerId);
4440
4898
  await rpc.provider.create(rpc, rpc.uri, savedState);
@@ -4795,6 +5253,7 @@ const textSearch = async (scheme, root, query, options, assetDir) => {
4795
5253
 
4796
5254
  const commandMap = {
4797
5255
  'BulkReplacement.applyBulkReplacement': applyBulkReplacement,
5256
+ 'ColorTheme.hydrate': hydrate$1,
4798
5257
  'ExtensionHost.launchIframeWorker': launchIframeWorker,
4799
5258
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
4800
5259
  'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
@@ -4814,13 +5273,17 @@ const commandMap = {
4814
5273
  'FileSystemMemory.readFile': readFile,
4815
5274
  'FileSystemMemory.remove': remove,
4816
5275
  'FileSystemMemory.writeFile': writeFile,
5276
+ 'IconTheme.getState': getState,
5277
+ 'IconTheme.getJson': getIconThemeJson,
5278
+ 'IconTheme.hydrate': hydrate,
5279
+ 'IconTheme.setIconTheme': setIconTheme,
4817
5280
  'IndexedDb.addHandle': addHandle,
4818
- 'IndexedDb.get': get,
5281
+ 'IndexedDb.get': get$5,
4819
5282
  'IndexedDb.getHandle': getHandle$1,
4820
5283
  'IndexedDb.getValues': getValues,
4821
5284
  'IndexedDb.getValuesByIndexName': getValuesByIndexName,
4822
5285
  'IndexedDb.saveValue': saveValue,
4823
- 'IndexedDb.set': set,
5286
+ 'IndexedDb.set': set$4,
4824
5287
  'SearchFileWithFetch.searchFileWithFetch': searchFile$1,
4825
5288
  'SearchFileWithHtml.searchFileWithHtml': searchFile,
4826
5289
  'TextSearchFetch.textSearch': textSearch$2,