@hanzogui/vite-plugin 2.0.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.
- package/LICENSE +21 -0
- package/dist/cjs/extensions.cjs +26 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/loadGui.cjs +82 -0
- package/dist/cjs/plugin.cjs +301 -0
- package/dist/esm/extensions.mjs +3 -0
- package/dist/esm/extensions.mjs.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/loadGui.mjs +44 -0
- package/dist/esm/loadGui.mjs.map +1 -0
- package/dist/esm/plugin.mjs +265 -0
- package/dist/esm/plugin.mjs.map +1 -0
- package/package.json +56 -0
- package/src/extensions.ts +12 -0
- package/src/index.ts +1 -0
- package/src/loadGui.ts +94 -0
- package/src/plugin.ts +560 -0
- package/types/extensions.d.ts +2 -0
- package/types/extensions.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
- package/types/loadGui.d.ts +15 -0
- package/types/loadGui.d.ts.map +1 -0
- package/types/plugin.d.ts +22 -0
- package/types/plugin.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var extensions_exports = {};
|
|
22
|
+
__export(extensions_exports, {
|
|
23
|
+
extensions: () => extensions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(extensions_exports);
|
|
26
|
+
const extensions = [".ios.js", ".native.js", ".native.ts", ".native.tsx", ".js", ".jsx", ".json", ".ts", ".tsx", ".mjs"];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./plugin.cjs"), module.exports);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
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);
|
|
32
|
+
var loadGui_exports = {};
|
|
33
|
+
__export(loadGui_exports, {
|
|
34
|
+
cleanup: () => cleanup,
|
|
35
|
+
ensureFullConfigLoaded: () => ensureFullConfigLoaded,
|
|
36
|
+
getGuiOptions: () => getGuiOptions,
|
|
37
|
+
getLoadPromise: () => getLoadPromise,
|
|
38
|
+
loadGuiBuildConfig: () => loadGuiBuildConfig
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(loadGui_exports);
|
|
41
|
+
var StaticWorker = __toESM(require("@hanzogui/static-worker"), 1);
|
|
42
|
+
const LOAD_STATE_KEY = "__gui_load_state__";
|
|
43
|
+
function getLoadState() {
|
|
44
|
+
return globalThis[LOAD_STATE_KEY] || (globalThis[LOAD_STATE_KEY] = {
|
|
45
|
+
loadPromise: null,
|
|
46
|
+
loadedOptions: null,
|
|
47
|
+
fullConfigLoaded: !1,
|
|
48
|
+
fullConfigLoadPromise: null
|
|
49
|
+
}), globalThis[LOAD_STATE_KEY];
|
|
50
|
+
}
|
|
51
|
+
function getGuiOptions() {
|
|
52
|
+
return getLoadState().loadedOptions;
|
|
53
|
+
}
|
|
54
|
+
function getLoadPromise() {
|
|
55
|
+
return getLoadState().loadPromise;
|
|
56
|
+
}
|
|
57
|
+
async function loadGuiBuildConfig(optionsIn) {
|
|
58
|
+
const state = getLoadState();
|
|
59
|
+
return state.loadedOptions ? state.loadedOptions : (state.loadPromise || (state.loadPromise = (async () => {
|
|
60
|
+
const options = await StaticWorker.loadGuiBuildConfig({
|
|
61
|
+
...optionsIn,
|
|
62
|
+
platform: "web"
|
|
63
|
+
});
|
|
64
|
+
return state.loadedOptions = options, options;
|
|
65
|
+
})()), state.loadPromise);
|
|
66
|
+
}
|
|
67
|
+
async function ensureFullConfigLoaded() {
|
|
68
|
+
const state = getLoadState();
|
|
69
|
+
if (!state.fullConfigLoaded) return state.fullConfigLoadPromise || (state.fullConfigLoadPromise = (async () => {
|
|
70
|
+
const options = await loadGuiBuildConfig();
|
|
71
|
+
!options.disableWatchGuiConfig && !options.disable && (await StaticWorker.loadGui({
|
|
72
|
+
components: ["@hanzo/gui"],
|
|
73
|
+
platform: "web",
|
|
74
|
+
...options
|
|
75
|
+
})), state.fullConfigLoaded = !0;
|
|
76
|
+
})()), state.fullConfigLoadPromise;
|
|
77
|
+
}
|
|
78
|
+
async function cleanup() {
|
|
79
|
+
await StaticWorker.destroyPool();
|
|
80
|
+
const state = getLoadState();
|
|
81
|
+
state.loadPromise = null, state.loadedOptions = null, state.fullConfigLoaded = !1, state.fullConfigLoadPromise = null;
|
|
82
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
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);
|
|
32
|
+
var plugin_exports = {};
|
|
33
|
+
__export(plugin_exports, {
|
|
34
|
+
guiAliases: () => guiAliases,
|
|
35
|
+
guiPlugin: () => guiPlugin
|
|
36
|
+
});
|
|
37
|
+
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__";
|
|
50
|
+
function getSharedCache() {
|
|
51
|
+
return globalThis[CACHE_KEY] || (globalThis[CACHE_KEY] = {}), globalThis[CACHE_KEY];
|
|
52
|
+
}
|
|
53
|
+
function getSharedCacheSize() {
|
|
54
|
+
return globalThis[CACHE_SIZE_KEY] || 0;
|
|
55
|
+
}
|
|
56
|
+
function setSharedCacheSize(size) {
|
|
57
|
+
globalThis[CACHE_SIZE_KEY] = size;
|
|
58
|
+
}
|
|
59
|
+
function clearSharedCache() {
|
|
60
|
+
globalThis[CACHE_KEY] = {}, globalThis[CACHE_SIZE_KEY] = 0;
|
|
61
|
+
}
|
|
62
|
+
function getPendingExtractions() {
|
|
63
|
+
return globalThis[PENDING_KEY] || (globalThis[PENDING_KEY] = /* @__PURE__ */new Map()), globalThis[PENDING_KEY];
|
|
64
|
+
}
|
|
65
|
+
function guiAliases(options = {}) {
|
|
66
|
+
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"));
|
|
73
|
+
aliases.push({
|
|
74
|
+
// map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
|
|
75
|
+
// extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
|
|
76
|
+
find: /^react-native(?:-web)?\/dist\/(?:exports|modules)\/.*\/([^/]+)$/,
|
|
77
|
+
replacement: `${rnwlBase}/dist/esm/$1.mjs`
|
|
78
|
+
}, {
|
|
79
|
+
find: /^react-native$/,
|
|
80
|
+
replacement: rnwl
|
|
81
|
+
}, {
|
|
82
|
+
find: /^react-native\/(Libraries\/Utilities\/codegenNativeComponent|Libraries\/Utilities\/codegenNativeCommand)$/,
|
|
83
|
+
replacement: `${rnwlBase}/$1`
|
|
84
|
+
}, {
|
|
85
|
+
find: "react-native/package.json",
|
|
86
|
+
replacement: resolve("@hanzogui/react-native-web-lite/package.json")
|
|
87
|
+
}, {
|
|
88
|
+
find: /^react-native-web$/,
|
|
89
|
+
replacement: rnwl
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return aliases;
|
|
93
|
+
}
|
|
94
|
+
function guiPlugin({
|
|
95
|
+
disableResolveConfig,
|
|
96
|
+
...guiOptionsIn
|
|
97
|
+
} = {}) {
|
|
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"];
|
|
102
|
+
(0, import_loadGui.loadGuiBuildConfig)(guiOptionsIn);
|
|
103
|
+
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));
|
|
115
|
+
function isNotClient(environment) {
|
|
116
|
+
return environment?.name && environment.name !== "client";
|
|
117
|
+
}
|
|
118
|
+
function isNative(environment) {
|
|
119
|
+
return environment?.name && (environment.name === "ios" || environment.name === "android");
|
|
120
|
+
}
|
|
121
|
+
function invalidateModule(absoluteId) {
|
|
122
|
+
if (!server) return;
|
|
123
|
+
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();
|
|
128
|
+
}
|
|
129
|
+
return [{
|
|
130
|
+
name: "hanzo-gui",
|
|
131
|
+
enforce: "pre",
|
|
132
|
+
configureServer(_server) {
|
|
133
|
+
server = _server;
|
|
134
|
+
},
|
|
135
|
+
async buildEnd() {
|
|
136
|
+
await watcher?.then(res => {
|
|
137
|
+
res?.dispose();
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
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
|
+
});
|
|
145
|
+
},
|
|
146
|
+
async config(_, env) {
|
|
147
|
+
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_"],
|
|
157
|
+
environments: {
|
|
158
|
+
client: {
|
|
159
|
+
define: {
|
|
160
|
+
"process.env.HANZO_GUI_IS_CLIENT": JSON.stringify(!0),
|
|
161
|
+
"process.env.HANZO_GUI_ENVIRONMENT": '"client"'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
define: {
|
|
166
|
+
// reanimated support
|
|
167
|
+
_frameTimestamp: void 0,
|
|
168
|
+
_WORKLET: !1,
|
|
169
|
+
__DEV__: `${env.mode === "development"}`,
|
|
170
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
171
|
+
"process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
|
|
172
|
+
"process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
|
|
173
|
+
"process.env.IS_STATIC": JSON.stringify(!1),
|
|
174
|
+
...(env.mode === "production" && {
|
|
175
|
+
"process.env.HANZO_GUI_OPTIMIZE_THEMES": JSON.stringify(!0)
|
|
176
|
+
})
|
|
177
|
+
},
|
|
178
|
+
resolve: disableResolveConfig || enableNativeEnv ? {} : {
|
|
179
|
+
extensions,
|
|
180
|
+
alias: {
|
|
181
|
+
...(options.platform !== "native" && {
|
|
182
|
+
"react-native/Libraries/Renderer/shims/ReactFabric": resolve("@hanzogui/proxy-worm"),
|
|
183
|
+
"react-native/Libraries/Utilities/codegenNativeComponent": resolve("@hanzogui/proxy-worm"),
|
|
184
|
+
"react-native-svg": resolve("@hanzogui/react-native-svg"),
|
|
185
|
+
...(!options?.useReactNativeWebLite && {
|
|
186
|
+
"react-native": resolve("react-native-web")
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
name: "gui-rnw-lite",
|
|
195
|
+
config() {
|
|
196
|
+
if (enableNativeEnv) return {};
|
|
197
|
+
const options = (0, import_loadGui.getGuiOptions)();
|
|
198
|
+
return options?.useReactNativeWebLite ? {
|
|
199
|
+
resolve: {
|
|
200
|
+
alias: guiAliases({
|
|
201
|
+
rnwLite: options.useReactNativeWebLite
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
} : {};
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
name: "gui-extract",
|
|
208
|
+
enforce: "pre",
|
|
209
|
+
async config(userConf) {
|
|
210
|
+
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");
|
|
212
|
+
},
|
|
213
|
+
async configResolved(resolvedConfig) {
|
|
214
|
+
config = resolvedConfig;
|
|
215
|
+
},
|
|
216
|
+
async resolveId(source) {
|
|
217
|
+
if (!shouldExtract || isNative(this.environment) || isNotClient(this.environment)) return;
|
|
218
|
+
const [validId, query] = source.split("?");
|
|
219
|
+
if (!validId.endsWith(virtualExt)) return;
|
|
220
|
+
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
|
|
221
|
+
if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
|
|
222
|
+
},
|
|
223
|
+
async load(id) {
|
|
224
|
+
if (!shouldExtract || (0, import_loadGui.getGuiOptions)()?.disable || isNative(this.environment) || isNotClient(this.environment)) return;
|
|
225
|
+
const [validId] = id.split("?");
|
|
226
|
+
return cssMap.get(validId);
|
|
227
|
+
},
|
|
228
|
+
transform: {
|
|
229
|
+
order: "pre",
|
|
230
|
+
async handler(code, id) {
|
|
231
|
+
const options = await ensureLoaded();
|
|
232
|
+
if (await (0, import_loadGui.ensureFullConfigLoaded)(), options?.disable || isNative(this.environment)) return;
|
|
233
|
+
const [validId] = id.split("?");
|
|
234
|
+
if (!validId.endsWith(".tsx")) return;
|
|
235
|
+
const {
|
|
236
|
+
shouldDisable,
|
|
237
|
+
shouldPrintDebug
|
|
238
|
+
} = await (0, import_static_worker.getPragmaOptions)({
|
|
239
|
+
source: code,
|
|
240
|
+
path: validId
|
|
241
|
+
});
|
|
242
|
+
if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
|
|
243
|
+
|
|
244
|
+
Original source:
|
|
245
|
+
${code}
|
|
246
|
+
|
|
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,
|
|
254
|
+
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);
|
|
258
|
+
const pendingExtraction = pending.get(cacheKey);
|
|
259
|
+
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)}`);
|
|
261
|
+
const result = await pendingExtraction;
|
|
262
|
+
return result ? formatResult(result) : void 0;
|
|
263
|
+
}
|
|
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
|
+
const extractionPromise = (async () => {
|
|
266
|
+
let extracted;
|
|
267
|
+
try {
|
|
268
|
+
extracted = await Static.extractToClassNames({
|
|
269
|
+
source: code,
|
|
270
|
+
sourcePath: validId,
|
|
271
|
+
options,
|
|
272
|
+
shouldPrintDebug
|
|
273
|
+
});
|
|
274
|
+
} 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;
|
|
276
|
+
}
|
|
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);
|
|
280
|
+
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;
|
|
290
|
+
})();
|
|
291
|
+
pending.set(cacheKey, extractionPromise);
|
|
292
|
+
try {
|
|
293
|
+
const result = await extractionPromise;
|
|
294
|
+
return result ? formatResult(result) : void 0;
|
|
295
|
+
} finally {
|
|
296
|
+
pending.delete(cacheKey);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}];
|
|
301
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["extensions"],"sources":["../../src/extensions.ts"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,UAAA,GAAa,CACxB,WACA,cACA,cACA,eACA,OACA,QACA,SACA,OACA,QACA,OACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as StaticWorker from "@hanzogui/static-worker";
|
|
2
|
+
const LOAD_STATE_KEY = "__gui_load_state__";
|
|
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];
|
|
10
|
+
}
|
|
11
|
+
function getGuiOptions() {
|
|
12
|
+
return getLoadState().loadedOptions;
|
|
13
|
+
}
|
|
14
|
+
function getLoadPromise() {
|
|
15
|
+
return getLoadState().loadPromise;
|
|
16
|
+
}
|
|
17
|
+
async function loadGuiBuildConfig(optionsIn) {
|
|
18
|
+
const state = getLoadState();
|
|
19
|
+
return state.loadedOptions ? state.loadedOptions : (state.loadPromise || (state.loadPromise = (async () => {
|
|
20
|
+
const options = await StaticWorker.loadGuiBuildConfig({
|
|
21
|
+
...optionsIn,
|
|
22
|
+
platform: "web"
|
|
23
|
+
});
|
|
24
|
+
return state.loadedOptions = options, options;
|
|
25
|
+
})()), state.loadPromise);
|
|
26
|
+
}
|
|
27
|
+
async function ensureFullConfigLoaded() {
|
|
28
|
+
const state = getLoadState();
|
|
29
|
+
if (!state.fullConfigLoaded) return state.fullConfigLoadPromise || (state.fullConfigLoadPromise = (async () => {
|
|
30
|
+
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;
|
|
37
|
+
}
|
|
38
|
+
async function cleanup() {
|
|
39
|
+
await StaticWorker.destroyPool();
|
|
40
|
+
const state = getLoadState();
|
|
41
|
+
state.loadPromise = null, state.loadedOptions = null, state.fullConfigLoaded = !1, state.fullConfigLoadPromise = null;
|
|
42
|
+
}
|
|
43
|
+
export { cleanup, ensureFullConfigLoaded, getGuiOptions, getLoadPromise, loadGuiBuildConfig };
|
|
44
|
+
//# sourceMappingURL=loadGui.mjs.map
|
|
@@ -0,0 +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":"AAAA,YAAYA,YAAA,MAAkB;AAI9B,MAAMC,cAAA,GAAiB;AASvB,SAASC,aAAA,EAA0B;EACjC,OAAMC,UAAA,CAAmBF,cAAc,MACnCE,UAAA,CAAmBF,cAAc,IAAI;IACrCG,WAAA,EAAa;IACbC,aAAA,EAAe;IACfC,gBAAA,EAAkB;IAClBC,qBAAA,EAAuB;EACzB,IAEMJ,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,OAAIU,KAAA,CAAMP,aAAA,GAAsBO,KAAA,CAAMP,aAAA,IAClCO,KAAA,CAAMR,WAAA,KAEVQ,KAAA,CAAMR,WAAA,IAAe,YAAY;IAC/B,MAAMS,OAAA,GAAU,MAAMb,YAAA,CAAaU,kBAAA,CAAmB;MACpD,GAAGC,SAAA;MACHG,QAAA,EAAU;IACZ,CAAC;IAED,OAAAF,KAAA,CAAMP,aAAA,GAAgBQ,OAAA,EACfA,OAAA;EACT,GAAG,IAEID,KAAA,CAAMR,WAAA;AACf;AAMA,eAAsBW,uBAAA,EAAwC;EAC5D,MAAMH,KAAA,GAAQV,YAAA,CAAa;EAE3B,IAAI,CAAAU,KAAA,CAAMN,gBAAA,EACV,OAAIM,KAAA,CAAML,qBAAA,KAIVK,KAAA,CAAML,qBAAA,IAAyB,YAAY;IACzC,MAAMM,OAAA,GAAU,MAAMH,kBAAA,CAAmB;IAGrC,CAACG,OAAA,CAAQG,qBAAA,IAAyB,CAACH,OAAA,CAAQI,OAAA,KAC7C,MAAMjB,YAAA,CAAakB,OAAA,CAAQ;MACzBC,UAAA,EAAY,CAAC,YAAY;MACzBL,QAAA,EAAU;MACV,GAAGD;IACL,CAAC,IAEHD,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":[]}
|