@hanzogui/vite-plugin 3.0.5 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,74 +2,90 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var plugin_exports = {};
33
35
  __export(plugin_exports, {
34
36
  guiAliases: () => guiAliases,
35
37
  guiPlugin: () => guiPlugin
36
38
  });
37
39
  module.exports = __toCommonJS(plugin_exports);
38
- var Static = __toESM(require("@hanzogui/static-worker"), 1),
39
- import_static_worker = require("@hanzogui/static-worker"),
40
- import_node_crypto = require("node:crypto"),
41
- import_node_path = __toESM(require("node:path"), 1),
42
- import_node_url = require("node:url"),
43
- import_vite = require("vite"),
44
- import_loadGui = require("./loadGui.cjs");
45
- const import_meta = {},
46
- resolve = name => (0, import_node_url.fileURLToPath)(import_meta.resolve(name)),
47
- CACHE_KEY = "__gui_vite_cache__",
48
- CACHE_SIZE_KEY = "__gui_vite_cache_size__",
49
- PENDING_KEY = "__gui_vite_pending__";
40
+ var Static = __toESM(require("@hanzogui/static-worker"), 1);
41
+ var import_static_worker = require("@hanzogui/static-worker");
42
+ var import_node_crypto = require("node:crypto");
43
+ var import_node_path = __toESM(require("node:path"), 1);
44
+ var import_node_url = require("node:url");
45
+ var import_vite = require("vite");
46
+ var import_loadGui = require("./loadGui.cjs");
47
+ const import_meta = {};
48
+ const resolve = name => (0, import_node_url.fileURLToPath)(import_meta.resolve(name));
49
+ const CACHE_KEY = "__gui_vite_cache__";
50
+ const CACHE_SIZE_KEY = "__gui_vite_cache_size__";
51
+ const PENDING_KEY = "__gui_vite_pending__";
50
52
  function getSharedCache() {
51
- return globalThis[CACHE_KEY] || (globalThis[CACHE_KEY] = {}), globalThis[CACHE_KEY];
53
+ if (!globalThis[CACHE_KEY]) {
54
+ ;
55
+ globalThis[CACHE_KEY] = {};
56
+ }
57
+ return globalThis[CACHE_KEY];
52
58
  }
53
59
  function getSharedCacheSize() {
54
60
  return globalThis[CACHE_SIZE_KEY] || 0;
55
61
  }
56
62
  function setSharedCacheSize(size) {
63
+ ;
57
64
  globalThis[CACHE_SIZE_KEY] = size;
58
65
  }
59
66
  function clearSharedCache() {
60
- globalThis[CACHE_KEY] = {}, globalThis[CACHE_SIZE_KEY] = 0;
67
+ ;
68
+ globalThis[CACHE_KEY] = {};
69
+ globalThis[CACHE_SIZE_KEY] = 0;
61
70
  }
62
71
  function getPendingExtractions() {
63
- return globalThis[PENDING_KEY] || (globalThis[PENDING_KEY] = /* @__PURE__ */new Map()), globalThis[PENDING_KEY];
72
+ if (!globalThis[PENDING_KEY]) {
73
+ ;
74
+ globalThis[PENDING_KEY] = /* @__PURE__ */new Map();
75
+ }
76
+ return globalThis[PENDING_KEY];
64
77
  }
65
78
  function guiAliases(options = {}) {
66
79
  const aliases = [];
67
- if (options.svg && aliases.push({
68
- find: "react-native-svg",
69
- replacement: resolve("@hanzogui/react-native-svg")
70
- }), options.rnwLite) {
71
- const rnwl = resolve(options.rnwLite === "without-animated" ? "@hanzogui/react-native-web-lite/without-animated" : "@hanzogui/react-native-web-lite"),
72
- rnwlBase = import_node_path.default.dirname(resolve("@hanzogui/react-native-web-lite/package.json"));
80
+ if (options.svg) {
81
+ aliases.push({
82
+ find: "react-native-svg",
83
+ replacement: resolve("@hanzogui/react-native-svg")
84
+ });
85
+ }
86
+ if (options.rnwLite) {
87
+ const rnwl = resolve(options.rnwLite === "without-animated" ? "@hanzogui/react-native-web-lite/without-animated" : "@hanzogui/react-native-web-lite");
88
+ const rnwlBase = import_node_path.default.dirname(resolve("@hanzogui/react-native-web-lite/package.json"));
73
89
  aliases.push({
74
90
  // map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
75
91
  // extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
@@ -95,23 +111,32 @@ function guiPlugin({
95
111
  disableResolveConfig,
96
112
  ...guiOptionsIn
97
113
  } = {}) {
98
- let shouldExtract = !guiOptionsIn.disableExtraction,
99
- watcher;
100
- const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv,
101
- extensions = [".web.mjs", ".web.js", ".web.jsx", ".web.ts", ".web.tsx", ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
114
+ let shouldExtract = !guiOptionsIn.disableExtraction;
115
+ let watcher;
116
+ const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv;
117
+ const extensions = [`.web.mjs`, `.web.js`, `.web.jsx`, `.web.ts`, `.web.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
102
118
  (0, import_loadGui.loadGuiBuildConfig)(guiOptionsIn);
103
119
  const ensureLoaded = async () => {
104
- const promise = (0, import_loadGui.getLoadPromise)();
105
- promise && (await promise);
106
- const options = (0, import_loadGui.getGuiOptions)();
107
- return options && (shouldExtract = !options.disableExtraction), options;
108
- },
109
- getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64"),
110
- memoryCache = getSharedCache(),
111
- cssMap = /* @__PURE__ */new Map();
112
- let config, server;
113
- const virtualExt = ".gui.css",
114
- getAbsoluteVirtualFileId = filePath => filePath.startsWith(config.root) ? filePath : (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
120
+ const promise = (0, import_loadGui.getLoadPromise)();
121
+ if (promise) await promise;
122
+ const options = (0, import_loadGui.getGuiOptions)();
123
+ if (options) {
124
+ shouldExtract = !options.disableExtraction;
125
+ }
126
+ return options;
127
+ };
128
+ const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64");
129
+ const memoryCache = getSharedCache();
130
+ const cssMap = /* @__PURE__ */new Map();
131
+ let config;
132
+ let server;
133
+ const virtualExt = `.gui.css`;
134
+ const getAbsoluteVirtualFileId = filePath => {
135
+ if (filePath.startsWith(config.root)) {
136
+ return filePath;
137
+ }
138
+ return (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
139
+ };
115
140
  function isNotClient(environment) {
116
141
  return environment?.name && environment.name !== "client";
117
142
  }
@@ -121,12 +146,17 @@ function guiPlugin({
121
146
  function invalidateModule(absoluteId) {
122
147
  if (!server) return;
123
148
  const {
124
- moduleGraph
125
- } = server,
126
- modules = moduleGraph.getModulesByFile(absoluteId);
127
- if (modules) for (const module2 of modules) moduleGraph.invalidateModule(module2), module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
149
+ moduleGraph
150
+ } = server;
151
+ const modules = moduleGraph.getModulesByFile(absoluteId);
152
+ if (modules) {
153
+ for (const module2 of modules) {
154
+ moduleGraph.invalidateModule(module2);
155
+ module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
156
+ }
157
+ }
128
158
  }
129
- return [{
159
+ const basePlugin = {
130
160
  name: "hanzo-gui",
131
161
  enforce: "pre",
132
162
  configureServer(_server) {
@@ -138,41 +168,48 @@ function guiPlugin({
138
168
  });
139
169
  },
140
170
  async transform(code, id) {
141
- if (id.includes("expo-linear-gradient")) return (0, import_vite.transformWithEsbuild)(code, id, {
142
- loader: "jsx",
143
- jsx: "automatic"
144
- });
171
+ if (id.includes("expo-linear-gradient")) {
172
+ return (0, import_vite.transformWithEsbuild)(code, id, {
173
+ loader: "jsx",
174
+ jsx: "automatic"
175
+ });
176
+ }
145
177
  },
146
178
  async config(_, env) {
147
179
  const options = await ensureLoaded();
148
- if (!options) throw new Error("No hanzo-gui options loaded");
149
- return options.disableWatchGuiConfig || (watcher = Static.watchGuiConfig({
150
- components: ["@hanzo/gui"],
151
- config: "./src/gui.config.ts",
152
- ...options
153
- }).catch(err => {
154
- console.error(` [Hanzo GUI] Error watching config: ${err}`);
155
- })), {
156
- envPrefix: ["HANZO_GUI_"],
180
+ if (!options) {
181
+ throw new Error(`No hanzo-gui options loaded`);
182
+ }
183
+ if (!options.disableWatchGuiConfig) {
184
+ watcher = Static.watchGuiConfig({
185
+ components: ["@hanzo/gui"],
186
+ config: "./src/gui.config.ts",
187
+ ...options
188
+ }).catch(err => {
189
+ console.error(` [GUI] Error watching config: ${err}`);
190
+ });
191
+ }
192
+ return {
193
+ envPrefix: ["GUI_"],
157
194
  environments: {
158
195
  client: {
159
196
  define: {
160
- "process.env.HANZO_GUI_IS_CLIENT": JSON.stringify(!0),
161
- "process.env.HANZO_GUI_ENVIRONMENT": '"client"'
197
+ "process.env.GUI_IS_CLIENT": JSON.stringify(true),
198
+ "process.env.GUI_ENVIRONMENT": '"client"'
162
199
  }
163
200
  }
164
201
  },
165
202
  define: {
166
203
  // reanimated support
167
204
  _frameTimestamp: void 0,
168
- _WORKLET: !1,
205
+ _WORKLET: false,
169
206
  __DEV__: `${env.mode === "development"}`,
170
207
  "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
171
208
  "process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
172
209
  "process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
173
- "process.env.IS_STATIC": JSON.stringify(!1),
210
+ "process.env.IS_STATIC": JSON.stringify(false),
174
211
  ...(env.mode === "production" && {
175
- "process.env.HANZO_GUI_OPTIMIZE_THEMES": JSON.stringify(!0)
212
+ "process.env.GUI_OPTIMIZE_THEMES": JSON.stringify(true)
176
213
  })
177
214
  },
178
215
  resolve: disableResolveConfig || enableNativeEnv ? {} : {
@@ -190,38 +227,73 @@ function guiPlugin({
190
227
  }
191
228
  };
192
229
  }
193
- }, {
230
+ };
231
+ const rnwLitePlugin = {
194
232
  name: "gui-rnw-lite",
195
233
  config() {
196
- if (enableNativeEnv) return {};
234
+ if (enableNativeEnv) {
235
+ return {};
236
+ }
197
237
  const options = (0, import_loadGui.getGuiOptions)();
198
- return options?.useReactNativeWebLite ? {
238
+ if (!options?.useReactNativeWebLite) {
239
+ return {};
240
+ }
241
+ return {
199
242
  resolve: {
200
243
  alias: guiAliases({
201
244
  rnwLite: options.useReactNativeWebLite
202
245
  })
246
+ },
247
+ optimizeDeps: {
248
+ // upstream react-native-web must not be pre-bundled when aliased to lite
249
+ exclude: ["react-native-web"]
203
250
  }
204
- } : {};
251
+ };
205
252
  }
206
- }, {
253
+ };
254
+ const extractPlugin = {
207
255
  name: "gui-extract",
208
256
  enforce: "pre",
209
257
  async config(userConf) {
210
258
  const options = await ensureLoaded();
211
- userConf.optimizeDeps ||= {}, userConf.optimizeDeps.include ||= [], userConf.optimizeDeps.include.push("inline-style-prefixer"), shouldExtract && userConf.optimizeDeps.include.push("@hanzogui/core/inject-styles");
259
+ userConf.optimizeDeps ||= {};
260
+ userConf.optimizeDeps.include ||= [];
261
+ userConf.optimizeDeps.include.push("inline-style-prefixer");
262
+ if (!shouldExtract) return;
263
+ userConf.optimizeDeps.include.push("@hanzogui/core/inject-styles");
212
264
  },
213
265
  async configResolved(resolvedConfig) {
214
266
  config = resolvedConfig;
215
267
  },
216
268
  async resolveId(source) {
217
- if (!shouldExtract || isNative(this.environment) || isNotClient(this.environment)) return;
269
+ if (!shouldExtract) return;
270
+ if (isNative(this.environment)) {
271
+ return;
272
+ }
273
+ if (isNotClient(this.environment)) {
274
+ return;
275
+ }
218
276
  const [validId, query] = source.split("?");
219
- if (!validId.endsWith(virtualExt)) return;
277
+ if (!validId.endsWith(virtualExt)) {
278
+ return;
279
+ }
220
280
  const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
221
- if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
281
+ if (cssMap.has(absoluteId)) {
282
+ return absoluteId + (query ? `?${query}` : "");
283
+ }
222
284
  },
223
285
  async load(id) {
224
- if (!shouldExtract || (0, import_loadGui.getGuiOptions)()?.disable || isNative(this.environment) || isNotClient(this.environment)) return;
286
+ if (!shouldExtract) return;
287
+ const options = (0, import_loadGui.getGuiOptions)();
288
+ if (options?.disable) {
289
+ return;
290
+ }
291
+ if (isNative(this.environment)) {
292
+ return;
293
+ }
294
+ if (isNotClient(this.environment)) {
295
+ return;
296
+ }
225
297
  const [validId] = id.split("?");
226
298
  return cssMap.get(validId);
227
299
  },
@@ -229,9 +301,17 @@ function guiPlugin({
229
301
  order: "pre",
230
302
  async handler(code, id) {
231
303
  const options = await ensureLoaded();
232
- if (await (0, import_loadGui.ensureFullConfigLoaded)(), options?.disable || isNative(this.environment)) return;
304
+ await (0, import_loadGui.ensureFullConfigLoaded)();
305
+ if (options?.disable) {
306
+ return;
307
+ }
308
+ if (isNative(this.environment)) {
309
+ return;
310
+ }
233
311
  const [validId] = id.split("?");
234
- if (!validId.endsWith(".tsx")) return;
312
+ if (!validId.endsWith(".tsx")) {
313
+ return;
314
+ }
235
315
  const {
236
316
  shouldDisable,
237
317
  shouldPrintDebug
@@ -239,29 +319,50 @@ function guiPlugin({
239
319
  source: code,
240
320
  path: validId
241
321
  });
242
- if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
322
+ if (shouldPrintDebug) {
323
+ console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`);
324
+ console.info(`
243
325
 
244
326
  Original source:
245
327
  ${code}
246
328
 
247
- `)), shouldDisable) return;
248
- const isSSR = isNotClient(this.environment),
249
- cacheKey = getHash(`${code}${id}`),
250
- pending = getPendingExtractions(),
251
- formatResult = entry => ({
252
- code: !isSSR && entry.cssImport ? `${entry.js}
253
- ${entry.cssImport}` : entry.js,
329
+ `);
330
+ }
331
+ if (shouldDisable) {
332
+ return;
333
+ }
334
+ const isSSR = isNotClient(this.environment);
335
+ const cacheKey = getHash(`${code}${id}`);
336
+ const pending = getPendingExtractions();
337
+ const formatResult = entry => {
338
+ const finalCode = !isSSR && entry.cssImport ? `${entry.js}
339
+ ${entry.cssImport}` : entry.js;
340
+ return {
341
+ code: finalCode,
254
342
  map: entry.map
255
- }),
256
- cached = memoryCache[cacheKey];
257
- if (cached) return process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`), formatResult(cached);
343
+ };
344
+ };
345
+ const cached = memoryCache[cacheKey];
346
+ if (cached) {
347
+ if (process.env.DEBUG_GUI_CACHE) {
348
+ console.info(`[gui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
349
+ }
350
+ return formatResult(cached);
351
+ }
258
352
  const pendingExtraction = pending.get(cacheKey);
259
353
  if (pendingExtraction) {
260
- process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
354
+ if (process.env.DEBUG_GUI_CACHE) {
355
+ console.info(`[gui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
356
+ }
261
357
  const result = await pendingExtraction;
262
- return result ? formatResult(result) : void 0;
358
+ if (result) {
359
+ return formatResult(result);
360
+ }
361
+ return;
362
+ }
363
+ if (process.env.DEBUG_GUI_CACHE) {
364
+ console.info(`[gui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
263
365
  }
264
- process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
265
366
  const extractionPromise = (async () => {
266
367
  let extracted;
267
368
  try {
@@ -272,30 +373,59 @@ ${entry.cssImport}` : entry.js,
272
373
  shouldPrintDebug
273
374
  });
274
375
  } catch (err) {
275
- return process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] ERROR extracting ${id.split("/").pop()}:`, err), console.error(err instanceof Error ? err.message : String(err)), null;
376
+ if (process.env.DEBUG_GUI_CACHE) {
377
+ console.info(`[gui-cache] ERROR extracting ${id.split("/").pop()}:`, err);
378
+ }
379
+ console.error(err instanceof Error ? err.message : String(err));
380
+ return null;
381
+ }
382
+ if (!extracted) {
383
+ if (process.env.DEBUG_GUI_CACHE) {
384
+ console.info(`[gui-cache] no extraction result for ${id.split("/").pop()}`);
385
+ }
386
+ return null;
276
387
  }
277
- if (!extracted) return process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] no extraction result for ${id.split("/").pop()}`), null;
278
- const rootRelativeId = `${validId}${virtualExt}`,
279
- absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
388
+ const rootRelativeId = `${validId}${virtualExt}`;
389
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
280
390
  let cssImport = null;
281
- extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), cssImport = `import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
282
- const jsCode = extracted.js.toString(),
283
- cacheEntry = {
284
- js: jsCode,
285
- map: extracted.map,
286
- cssImport
287
- },
288
- newSize = getSharedCacheSize() + jsCode.length;
289
- return newSize > 67108864 ? clearSharedCache() : setSharedCacheSize(newSize), memoryCache[cacheKey] = cacheEntry, process.env.DEBUG_HANZO_GUI_CACHE && console.info(`[gui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`), cacheEntry;
391
+ if (extracted.styles) {
392
+ this.addWatchFile(rootRelativeId);
393
+ if (server && cssMap.has(absoluteId)) {
394
+ invalidateModule(rootRelativeId);
395
+ }
396
+ cssImport = `import "${rootRelativeId}";`;
397
+ cssMap.set(absoluteId, extracted.styles);
398
+ }
399
+ const jsCode = extracted.js.toString();
400
+ const cacheEntry = {
401
+ js: jsCode,
402
+ map: extracted.map,
403
+ cssImport
404
+ };
405
+ const newSize = getSharedCacheSize() + jsCode.length;
406
+ if (newSize > 67108864) {
407
+ clearSharedCache();
408
+ } else {
409
+ setSharedCacheSize(newSize);
410
+ }
411
+ memoryCache[cacheKey] = cacheEntry;
412
+ if (process.env.DEBUG_GUI_CACHE) {
413
+ console.info(`[gui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`);
414
+ }
415
+ return cacheEntry;
290
416
  })();
291
417
  pending.set(cacheKey, extractionPromise);
292
418
  try {
293
419
  const result = await extractionPromise;
294
- return result ? formatResult(result) : void 0;
420
+ if (result) {
421
+ return formatResult(result);
422
+ }
423
+ return;
295
424
  } finally {
296
425
  pending.delete(cacheKey);
297
426
  }
298
427
  }
299
428
  }
300
- }];
429
+ };
430
+ return [basePlugin, rnwLitePlugin, extractPlugin];
301
431
  }
@@ -1,12 +1,16 @@
1
1
  import * as StaticWorker from "@hanzogui/static-worker";
2
2
  const LOAD_STATE_KEY = "__gui_load_state__";
3
3
  function getLoadState() {
4
- return globalThis[LOAD_STATE_KEY] || (globalThis[LOAD_STATE_KEY] = {
5
- loadPromise: null,
6
- loadedOptions: null,
7
- fullConfigLoaded: !1,
8
- fullConfigLoadPromise: null
9
- }), globalThis[LOAD_STATE_KEY];
4
+ if (!globalThis[LOAD_STATE_KEY]) {
5
+ ;
6
+ globalThis[LOAD_STATE_KEY] = {
7
+ loadPromise: null,
8
+ loadedOptions: null,
9
+ fullConfigLoaded: false,
10
+ fullConfigLoadPromise: null
11
+ };
12
+ }
13
+ return globalThis[LOAD_STATE_KEY];
10
14
  }
11
15
  function getGuiOptions() {
12
16
  return getLoadState().loadedOptions;
@@ -16,29 +20,42 @@ function getLoadPromise() {
16
20
  }
17
21
  async function loadGuiBuildConfig(optionsIn) {
18
22
  const state = getLoadState();
19
- return state.loadedOptions ? state.loadedOptions : (state.loadPromise || (state.loadPromise = (async () => {
23
+ if (state.loadedOptions) return state.loadedOptions;
24
+ if (state.loadPromise) return state.loadPromise;
25
+ state.loadPromise = (async () => {
20
26
  const options = await StaticWorker.loadGuiBuildConfig({
21
27
  ...optionsIn,
22
28
  platform: "web"
23
29
  });
24
- return state.loadedOptions = options, options;
25
- })()), state.loadPromise);
30
+ state.loadedOptions = options;
31
+ return options;
32
+ })();
33
+ return state.loadPromise;
26
34
  }
27
35
  async function ensureFullConfigLoaded() {
28
36
  const state = getLoadState();
29
- if (!state.fullConfigLoaded) return state.fullConfigLoadPromise || (state.fullConfigLoadPromise = (async () => {
37
+ if (state.fullConfigLoaded) return;
38
+ if (state.fullConfigLoadPromise) return state.fullConfigLoadPromise;
39
+ state.fullConfigLoadPromise = (async () => {
30
40
  const options = await loadGuiBuildConfig();
31
- !options.disableWatchGuiConfig && !options.disable && (await StaticWorker.loadGui({
32
- components: ["@hanzo/gui"],
33
- platform: "web",
34
- ...options
35
- })), state.fullConfigLoaded = !0;
36
- })()), state.fullConfigLoadPromise;
41
+ if (!options.disableWatchGuiConfig && !options.disable) {
42
+ await StaticWorker.loadGui({
43
+ components: ["@hanzo/gui"],
44
+ platform: "web",
45
+ ...options
46
+ });
47
+ }
48
+ state.fullConfigLoaded = true;
49
+ })();
50
+ return state.fullConfigLoadPromise;
37
51
  }
38
52
  async function cleanup() {
39
53
  await StaticWorker.destroyPool();
40
54
  const state = getLoadState();
41
- state.loadPromise = null, state.loadedOptions = null, state.fullConfigLoaded = !1, state.fullConfigLoadPromise = null;
55
+ state.loadPromise = null;
56
+ state.loadedOptions = null;
57
+ state.fullConfigLoaded = false;
58
+ state.fullConfigLoadPromise = null;
42
59
  }
43
60
  export { cleanup, ensureFullConfigLoaded, getGuiOptions, getLoadPromise, loadGuiBuildConfig };
44
61
  //# sourceMappingURL=loadGui.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["StaticWorker","LOAD_STATE_KEY","getLoadState","globalThis","loadPromise","loadedOptions","fullConfigLoaded","fullConfigLoadPromise","getGuiOptions","getLoadPromise","loadGuiBuildConfig","optionsIn","state","options","platform","ensureFullConfigLoaded","disableWatchGuiConfig","disable","loadGui","components","cleanup","destroyPool"],"sources":["../../src/loadGui.ts"],"sourcesContent":[null],"mappings":"AA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,KAAA,CAAMN,gBAAA,GAAmB;EAC3B,GAAG,IAEIM,KAAA,CAAML,qBAAA;AACf;AAEA,eAAsBa,QAAA,EAAU;EAC9B,MAAMpB,YAAA,CAAaqB,WAAA,CAAY;EAC/B,MAAMT,KAAA,GAAQV,YAAA,CAAa;EAC3BU,KAAA,CAAMR,WAAA,GAAc,MACpBQ,KAAA,CAAMP,aAAA,GAAgB,MACtBO,KAAA,CAAMN,gBAAA,GAAmB,IACzBM,KAAA,CAAML,qBAAA,GAAwB;AAChC","ignoreList":[]}
1
+ {"version":3,"names":["StaticWorker","LOAD_STATE_KEY","getLoadState","globalThis","loadPromise","loadedOptions","fullConfigLoaded","fullConfigLoadPromise","getGuiOptions","getLoadPromise","loadGuiBuildConfig","optionsIn","state","options","platform","ensureFullConfigLoaded","disableWatchGuiConfig","disable","loadGui","components","cleanup","destroyPool"],"sources":["../../src/loadGui.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,YAAA,MAAkB;AAI9B,MAAMC,cAAA,GAAiB;AASvB,SAASC,aAAA,EAA0B;EACjC,IAAI,CAAEC,UAAA,CAAmBF,cAAc,GAAG;IACxC;IAAEE,UAAA,CAAmBF,cAAc,IAAI;MACrCG,WAAA,EAAa;MACbC,aAAA,EAAe;MACfC,gBAAA,EAAkB;MAClBC,qBAAA,EAAuB;IACzB;EACF;EACA,OAAQJ,UAAA,CAAmBF,cAAc;AAC3C;AAEO,SAASO,cAAA,EAAmC;EACjD,OAAON,YAAA,CAAa,EAAEG,aAAA;AACxB;AAEO,SAASI,eAAA,EAA6C;EAC3D,OAAOP,YAAA,CAAa,EAAEE,WAAA;AACxB;AAMA,eAAsBM,mBACpBC,SAAA,EACqB;EACrB,MAAMC,KAAA,GAAQV,YAAA,CAAa;EAC3B,IAAIU,KAAA,CAAMP,aAAA,EAAe,OAAOO,KAAA,CAAMP,aAAA;EACtC,IAAIO,KAAA,CAAMR,WAAA,EAAa,OAAOQ,KAAA,CAAMR,WAAA;EAEpCQ,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