@series-inc/venus-sdk 3.1.2-beta.1 → 3.1.2

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.
Files changed (38) hide show
  1. package/dist/{AdsApi-DFutZ7_q.d.mts → AdsApi-CNGRf6j0.d.mts} +293 -501
  2. package/dist/{AdsApi-DFutZ7_q.d.ts → AdsApi-CNGRf6j0.d.ts} +293 -501
  3. package/dist/{chunk-U6NFOU3E.mjs → chunk-PXWCNWJ6.mjs} +1525 -1380
  4. package/dist/chunk-PXWCNWJ6.mjs.map +1 -0
  5. package/dist/{chunk-QABXMFND.mjs → chunk-W7IPHM67.mjs} +26 -3
  6. package/dist/chunk-W7IPHM67.mjs.map +1 -0
  7. package/dist/core-R3FHW62G.mjs +3 -0
  8. package/dist/{core-62LWDHN7.mjs.map → core-R3FHW62G.mjs.map} +1 -1
  9. package/dist/index.cjs +1531 -1406
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.mts +92 -280
  12. package/dist/index.d.ts +92 -280
  13. package/dist/index.mjs +6 -4
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/venus-api/index.cjs +2012 -1548
  16. package/dist/venus-api/index.cjs.map +1 -1
  17. package/dist/venus-api/index.d.mts +2 -2
  18. package/dist/venus-api/index.d.ts +2 -2
  19. package/dist/venus-api/index.mjs +391 -92
  20. package/dist/venus-api/index.mjs.map +1 -1
  21. package/package.json +1 -1
  22. package/dist/chunk-NSSMTXJJ.mjs +0 -7
  23. package/dist/chunk-NSSMTXJJ.mjs.map +0 -1
  24. package/dist/chunk-QABXMFND.mjs.map +0 -1
  25. package/dist/chunk-U6NFOU3E.mjs.map +0 -1
  26. package/dist/chunk-UXY5CKKG.mjs +0 -12
  27. package/dist/chunk-UXY5CKKG.mjs.map +0 -1
  28. package/dist/core-62LWDHN7.mjs +0 -4
  29. package/dist/vite/index.cjs +0 -534
  30. package/dist/vite/index.cjs.map +0 -1
  31. package/dist/vite/index.mjs +0 -527
  32. package/dist/vite/index.mjs.map +0 -1
  33. package/dist/webview/index.cjs +0 -15
  34. package/dist/webview/index.cjs.map +0 -1
  35. package/dist/webview/index.d.mts +0 -15
  36. package/dist/webview/index.d.ts +0 -15
  37. package/dist/webview/index.mjs +0 -4
  38. package/dist/webview/index.mjs.map +0 -1
@@ -1,12 +0,0 @@
1
- // raw-loader:/Users/pchan/Development/series/venus/venus-sdk/packages/api/src/webview/webviewLibraryShim.js
2
- var webviewLibraryShim_default = "/**\r\n * Venus Embedded Libraries WebView Shim\r\n *\r\n * This code is injected into H5 game WebViews BEFORE the game's main script runs.\r\n * It bootstraps the embedded libraries system by:\r\n * 1. Reading window.__venusLibrariesConfig (set by the Vite plugin)\r\n * 2. Loading libraries via RPC (mobile) or CDN (web)\r\n * 3. Registering libraries in window.__venusLibraryExports\r\n * 4. Allowing the game's virtual modules to access them\r\n *\r\n * This shim is NOT imported by H5 games - it's injected by the Venus host via\r\n * injectedJavaScriptBeforeContentLoaded in H5AppPoolRenderer.\r\n */\r\n\r\n;(function () {\r\n if (typeof window === 'undefined') {\r\n return\r\n }\r\n\r\n if (window.__venusLibraryShim && window.__venusLibraryShim.__initialized) {\r\n return\r\n }\r\n\r\n var RESPONSE_TYPE = 'H5_RESPONSE'\r\n var REQUEST_TYPE = 'H5_LOAD_EMBEDDED_ASSET'\r\n var REQUEST_TIMEOUT_MS = 12000\r\n var pendingRequests = new Map()\r\n\r\n function ensureConfig() {\r\n if (!window.__venusLibrariesConfig) {\r\n window.__venusLibrariesConfig = {\r\n enabled: false,\r\n required: [],\r\n manifest: {},\r\n cdnBase: '',\r\n }\r\n }\r\n if (!window.__venusLibrariesConfig.manifest) {\r\n window.__venusLibrariesConfig.manifest = {}\r\n }\r\n if (!Array.isArray(window.__venusLibrariesConfig.required)) {\r\n window.__venusLibrariesConfig.required = []\r\n }\r\n return window.__venusLibrariesConfig\r\n }\r\n\r\n function ensureExportsRegistry() {\r\n if (!window.__venusLibraryExports) {\r\n window.__venusLibraryExports = {}\r\n }\r\n return window.__venusLibraryExports\r\n }\r\n\r\n function hasHostBridge() {\r\n return !!(\r\n window.ReactNativeWebView &&\r\n typeof window.ReactNativeWebView.postMessage === 'function'\r\n )\r\n }\r\n\r\n function registerResponseListeners() {\r\n if (\r\n window.__venusLibraryShim &&\r\n window.__venusLibraryShim.__listenerRegistered\r\n ) {\r\n return\r\n }\r\n\r\n function handleMessage(event) {\r\n var payload = parsePayload(event && event.data)\r\n if (!payload || payload.type !== RESPONSE_TYPE || !payload.data) {\r\n return\r\n }\r\n var requestId = payload.data.requestId\r\n if (!requestId || !pendingRequests.has(requestId)) {\r\n return\r\n }\r\n var pending = pendingRequests.get(requestId)\r\n pendingRequests.delete(requestId)\r\n clearTimeout(pending.timeout)\r\n\r\n if (payload.data.success === false) {\r\n pending.reject(\r\n new Error(payload.data.error || 'Embedded library load failed'),\r\n )\r\n return\r\n }\r\n\r\n var value = payload.data.value || payload.data\r\n if (!value || !value.base64Data) {\r\n pending.reject(\r\n new Error('Embedded library response was missing base64Data'),\r\n )\r\n return\r\n }\r\n\r\n pending.resolve(value.base64Data)\r\n }\r\n\r\n if (\r\n typeof document !== 'undefined' &&\r\n typeof document.addEventListener === 'function'\r\n ) {\r\n document.addEventListener('message', handleMessage, false)\r\n }\r\n if (\r\n typeof window !== 'undefined' &&\r\n typeof window.addEventListener === 'function'\r\n ) {\r\n window.addEventListener('message', handleMessage, false)\r\n }\r\n\r\n if (!window.__venusLibraryShim) {\r\n window.__venusLibraryShim = {}\r\n }\r\n window.__venusLibraryShim.__listenerRegistered = true\r\n }\r\n\r\n function parsePayload(raw) {\r\n if (!raw || typeof raw !== 'string') {\r\n return null\r\n }\r\n try {\r\n return JSON.parse(raw)\r\n } catch (error) {\r\n return null\r\n }\r\n }\r\n\r\n function createRequestId(libraryKey) {\r\n var sanitized = ''\r\n for (var i = 0; i < libraryKey.length; i++) {\r\n var c = libraryKey.charAt(i)\r\n if (\r\n (c >= 'a' && c <= 'z') ||\r\n (c >= 'A' && c <= 'Z') ||\r\n (c >= '0' && c <= '9') ||\r\n c === '-' ||\r\n c === '_'\r\n ) {\r\n sanitized += c\r\n } else {\r\n sanitized += '_'\r\n }\r\n }\r\n return (\r\n 'embedded-lib-' +\r\n sanitized +\r\n '-' +\r\n Date.now() +\r\n '-' +\r\n Math.random().toString(36).slice(2)\r\n )\r\n }\r\n\r\n function postHostRequest(assetKey, requestId) {\r\n if (!hasHostBridge()) {\r\n throw new Error('Host bridge is unavailable')\r\n }\r\n var bridge = window.ReactNativeWebView\r\n var message = {\r\n type: REQUEST_TYPE,\r\n direction: 'H5_TO_APP',\r\n data: {\r\n requestId: requestId,\r\n assetKey: assetKey,\r\n },\r\n instanceId:\r\n (window._venusInitState && window._venusInitState.poolId) || 'unknown',\r\n timestamp: Date.now(),\r\n }\r\n bridge.postMessage(JSON.stringify(message))\r\n }\r\n\r\n function loadLibraryViaHost(assetKey, libraryKey) {\r\n return new Promise(function (resolve, reject) {\r\n var requestId = createRequestId(libraryKey)\r\n var timeout = setTimeout(function () {\r\n pendingRequests.delete(requestId)\r\n reject(new Error('Timed out loading embedded library: ' + libraryKey))\r\n }, REQUEST_TIMEOUT_MS)\r\n\r\n pendingRequests.set(requestId, {\r\n resolve: resolve,\r\n reject: reject,\r\n timeout: timeout,\r\n })\r\n\r\n try {\r\n postHostRequest(assetKey, requestId)\r\n } catch (error) {\r\n pendingRequests.delete(requestId)\r\n clearTimeout(timeout)\r\n reject(error)\r\n }\r\n })\r\n }\r\n\r\n function buildCdnUrl(config, entry) {\r\n var base = config.cdnBase || ''\r\n if (!base.endsWith('/')) {\r\n base += '/'\r\n }\r\n var path = entry.cdnPath\r\n if (path.charAt(0) === '/') {\r\n path = path.substring(1)\r\n }\r\n return base + path\r\n }\r\n\r\n async function loadLibraryViaCdn(config, entry, libraryKey) {\r\n if (!config.cdnBase) {\r\n throw new Error('CDN base URL is not configured')\r\n }\r\n var url = buildCdnUrl(config, entry)\r\n var response = await fetch(url, { credentials: 'omit' })\r\n if (!response.ok) {\r\n throw new Error(\r\n 'Failed to fetch embedded library from CDN: ' + libraryKey,\r\n )\r\n }\r\n return await response.text()\r\n }\r\n\r\n function decodeBase64ToUtf8(base64) {\r\n if (typeof base64 !== 'string') {\r\n throw new Error('Invalid base64 payload')\r\n }\r\n\r\n if (typeof atob === 'function') {\r\n var binary = atob(base64)\r\n if (typeof TextDecoder !== 'undefined') {\r\n var len = binary.length\r\n var bytes = new Uint8Array(len)\r\n for (var i = 0; i < len; i++) {\r\n bytes[i] = binary.charCodeAt(i)\r\n }\r\n return new TextDecoder('utf-8').decode(bytes)\r\n }\r\n return decodeURIComponent(escape(binary))\r\n }\r\n\r\n var bufferCtor =\r\n (typeof globalThis !== 'undefined' && globalThis.Buffer) ||\r\n (typeof window !== 'undefined' && window.Buffer)\r\n if (bufferCtor) {\r\n return bufferCtor.from(base64, 'base64').toString('utf-8')\r\n }\r\n\r\n throw new Error('No base64 decoder available')\r\n }\r\n\r\n function evaluateLibrarySource(libraryKey, globalVar, source) {\r\n var registry = ensureExportsRegistry()\r\n if (!source) {\r\n throw new Error('Embedded library source was empty for ' + libraryKey)\r\n }\r\n\r\n var previousValue = window[globalVar]\r\n try {\r\n var executor = new Function(\r\n source + '\\n//# sourceURL=venus-library-' + libraryKey + '.js',\r\n )\r\n executor.call(window)\r\n } catch (error) {\r\n throw new Error(\r\n 'Failed to evaluate embedded library ' +\r\n libraryKey +\r\n ': ' +\r\n (error && error.message ? error.message : error),\r\n )\r\n }\r\n\r\n var exported = window[globalVar] || previousValue\r\n if (!exported) {\r\n throw new Error(\r\n 'Embedded library ' + libraryKey + ' did not register ' + globalVar,\r\n )\r\n }\r\n\r\n registry[libraryKey] = exported\r\n return exported\r\n }\r\n\r\n async function ensureLibraryLoaded(config, libraryKey) {\r\n var registry = ensureExportsRegistry()\r\n if (registry[libraryKey]) {\r\n return registry[libraryKey]\r\n }\r\n\r\n var entry = config.manifest && config.manifest[libraryKey]\r\n if (!entry) {\r\n throw new Error('No manifest entry for embedded library ' + libraryKey)\r\n }\r\n\r\n var source = null\r\n if (config.useHost !== false && hasHostBridge()) {\r\n try {\r\n var base64 = await loadLibraryViaHost(entry.assetKey, libraryKey)\r\n source = decodeBase64ToUtf8(base64)\r\n } catch (error) {\r\n // Log the RPC error loudly before fallback\r\n console.error(\r\n '[Venus Libraries] Failed to load ' +\r\n libraryKey +\r\n ' from host via RPC:',\r\n error,\r\n )\r\n console.warn(\r\n '[Venus Libraries] Falling back to CDN for ' +\r\n libraryKey +\r\n '. This may indicate an asset packaging issue.',\r\n )\r\n }\r\n }\r\n\r\n if (!source) {\r\n source = await loadLibraryViaCdn(config, entry, libraryKey)\r\n }\r\n\r\n return evaluateLibrarySource(libraryKey, entry.globalVar, source)\r\n }\r\n\r\n async function bootstrap() {\r\n try {\r\n registerResponseListeners()\r\n getBootstrapPromise()\r\n\r\n var config = ensureConfig()\r\n\r\n if (!config.enabled) {\r\n if (bootstrapResolve) bootstrapResolve()\r\n return\r\n }\r\n\r\n if (!Array.isArray(config.required) || config.required.length === 0) {\r\n if (bootstrapResolve) bootstrapResolve()\r\n return\r\n }\r\n\r\n // Group libraries by load stage for parallel loading within stages\r\n var librariesByStage = {}\r\n for (var i = 0; i < config.required.length; i++) {\r\n var libraryKey = config.required[i]\r\n var entry = config.manifest[libraryKey]\r\n var stage = entry.loadStage || 0\r\n if (!librariesByStage[stage]) librariesByStage[stage] = []\r\n librariesByStage[stage].push(libraryKey)\r\n }\r\n\r\n // Load stages sequentially, libraries within each stage in parallel\r\n var stages = Object.keys(librariesByStage).sort(function (a, b) {\r\n return parseInt(a, 10) - parseInt(b, 10)\r\n })\r\n\r\n for (var s = 0; s < stages.length; s++) {\r\n var stage = stages[s]\r\n var libs = librariesByStage[stage]\r\n\r\n // Load all libraries in this stage in parallel\r\n var stagePromises = libs.map(function (libraryKey) {\r\n return ensureLibraryLoaded(config, libraryKey).catch(\r\n function (error) {\r\n console.error(\r\n '[Venus Libraries] Failed to load library ' + libraryKey,\r\n error,\r\n )\r\n throw error\r\n },\r\n )\r\n })\r\n\r\n await Promise.all(stagePromises)\r\n }\r\n\r\n if (bootstrapResolve) bootstrapResolve()\r\n } catch (error) {\r\n console.error('[Venus Libraries] Bootstrap error', error)\r\n if (bootstrapReject) bootstrapReject(error)\r\n throw error\r\n }\r\n }\r\n\r\n // Create a promise that resolves when bootstrap completes\r\n var bootstrapPromise = null\r\n var bootstrapResolve = null\r\n var bootstrapReject = null\r\n\r\n function getBootstrapPromise() {\r\n if (!bootstrapPromise) {\r\n bootstrapPromise = new Promise(function (resolve, reject) {\r\n bootstrapResolve = resolve\r\n bootstrapReject = reject\r\n })\r\n }\r\n return bootstrapPromise\r\n }\r\n\r\n window.__venusLibraryShim = {\r\n bootstrap: bootstrap,\r\n ready: getBootstrapPromise,\r\n getExports: function (libraryKey) {\r\n var registry = ensureExportsRegistry()\r\n return registry[libraryKey]\r\n },\r\n __initialized: true,\r\n }\r\n})()\r\n";
3
-
4
- // src/webview/webviewLibraryShimSource.ts
5
- var WEBVIEW_LIBRARY_SHIM_SOURCE = webviewLibraryShim_default;
6
- function getWebviewLibraryShimSource() {
7
- return WEBVIEW_LIBRARY_SHIM_SOURCE;
8
- }
9
-
10
- export { WEBVIEW_LIBRARY_SHIM_SOURCE, getWebviewLibraryShimSource };
11
- //# sourceMappingURL=chunk-UXY5CKKG.mjs.map
12
- //# sourceMappingURL=chunk-UXY5CKKG.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["raw-loader:/Users/pchan/Development/series/venus/venus-sdk/packages/api/src/webview/webviewLibraryShim.js","../src/webview/webviewLibraryShimSource.ts"],"names":[],"mappings":";AAAA,IAAO,0BAAA,GAAQ,omYAAA;;;ACcR,IAAM,2BAAA,GAA8B;AAEpC,SAAS,2BAAA,GAAsC;AACpD,EAAA,OAAO,2BAAA;AACT","file":"chunk-UXY5CKKG.mjs","sourcesContent":["export default \"/**\\r\\n * Venus Embedded Libraries WebView Shim\\r\\n *\\r\\n * This code is injected into H5 game WebViews BEFORE the game's main script runs.\\r\\n * It bootstraps the embedded libraries system by:\\r\\n * 1. Reading window.__venusLibrariesConfig (set by the Vite plugin)\\r\\n * 2. Loading libraries via RPC (mobile) or CDN (web)\\r\\n * 3. Registering libraries in window.__venusLibraryExports\\r\\n * 4. Allowing the game's virtual modules to access them\\r\\n *\\r\\n * This shim is NOT imported by H5 games - it's injected by the Venus host via\\r\\n * injectedJavaScriptBeforeContentLoaded in H5AppPoolRenderer.\\r\\n */\\r\\n\\r\\n;(function () {\\r\\n if (typeof window === 'undefined') {\\r\\n return\\r\\n }\\r\\n\\r\\n if (window.__venusLibraryShim && window.__venusLibraryShim.__initialized) {\\r\\n return\\r\\n }\\r\\n\\r\\n var RESPONSE_TYPE = 'H5_RESPONSE'\\r\\n var REQUEST_TYPE = 'H5_LOAD_EMBEDDED_ASSET'\\r\\n var REQUEST_TIMEOUT_MS = 12000\\r\\n var pendingRequests = new Map()\\r\\n\\r\\n function ensureConfig() {\\r\\n if (!window.__venusLibrariesConfig) {\\r\\n window.__venusLibrariesConfig = {\\r\\n enabled: false,\\r\\n required: [],\\r\\n manifest: {},\\r\\n cdnBase: '',\\r\\n }\\r\\n }\\r\\n if (!window.__venusLibrariesConfig.manifest) {\\r\\n window.__venusLibrariesConfig.manifest = {}\\r\\n }\\r\\n if (!Array.isArray(window.__venusLibrariesConfig.required)) {\\r\\n window.__venusLibrariesConfig.required = []\\r\\n }\\r\\n return window.__venusLibrariesConfig\\r\\n }\\r\\n\\r\\n function ensureExportsRegistry() {\\r\\n if (!window.__venusLibraryExports) {\\r\\n window.__venusLibraryExports = {}\\r\\n }\\r\\n return window.__venusLibraryExports\\r\\n }\\r\\n\\r\\n function hasHostBridge() {\\r\\n return !!(\\r\\n window.ReactNativeWebView &&\\r\\n typeof window.ReactNativeWebView.postMessage === 'function'\\r\\n )\\r\\n }\\r\\n\\r\\n function registerResponseListeners() {\\r\\n if (\\r\\n window.__venusLibraryShim &&\\r\\n window.__venusLibraryShim.__listenerRegistered\\r\\n ) {\\r\\n return\\r\\n }\\r\\n\\r\\n function handleMessage(event) {\\r\\n var payload = parsePayload(event && event.data)\\r\\n if (!payload || payload.type !== RESPONSE_TYPE || !payload.data) {\\r\\n return\\r\\n }\\r\\n var requestId = payload.data.requestId\\r\\n if (!requestId || !pendingRequests.has(requestId)) {\\r\\n return\\r\\n }\\r\\n var pending = pendingRequests.get(requestId)\\r\\n pendingRequests.delete(requestId)\\r\\n clearTimeout(pending.timeout)\\r\\n\\r\\n if (payload.data.success === false) {\\r\\n pending.reject(\\r\\n new Error(payload.data.error || 'Embedded library load failed'),\\r\\n )\\r\\n return\\r\\n }\\r\\n\\r\\n var value = payload.data.value || payload.data\\r\\n if (!value || !value.base64Data) {\\r\\n pending.reject(\\r\\n new Error('Embedded library response was missing base64Data'),\\r\\n )\\r\\n return\\r\\n }\\r\\n\\r\\n pending.resolve(value.base64Data)\\r\\n }\\r\\n\\r\\n if (\\r\\n typeof document !== 'undefined' &&\\r\\n typeof document.addEventListener === 'function'\\r\\n ) {\\r\\n document.addEventListener('message', handleMessage, false)\\r\\n }\\r\\n if (\\r\\n typeof window !== 'undefined' &&\\r\\n typeof window.addEventListener === 'function'\\r\\n ) {\\r\\n window.addEventListener('message', handleMessage, false)\\r\\n }\\r\\n\\r\\n if (!window.__venusLibraryShim) {\\r\\n window.__venusLibraryShim = {}\\r\\n }\\r\\n window.__venusLibraryShim.__listenerRegistered = true\\r\\n }\\r\\n\\r\\n function parsePayload(raw) {\\r\\n if (!raw || typeof raw !== 'string') {\\r\\n return null\\r\\n }\\r\\n try {\\r\\n return JSON.parse(raw)\\r\\n } catch (error) {\\r\\n return null\\r\\n }\\r\\n }\\r\\n\\r\\n function createRequestId(libraryKey) {\\r\\n var sanitized = ''\\r\\n for (var i = 0; i < libraryKey.length; i++) {\\r\\n var c = libraryKey.charAt(i)\\r\\n if (\\r\\n (c >= 'a' && c <= 'z') ||\\r\\n (c >= 'A' && c <= 'Z') ||\\r\\n (c >= '0' && c <= '9') ||\\r\\n c === '-' ||\\r\\n c === '_'\\r\\n ) {\\r\\n sanitized += c\\r\\n } else {\\r\\n sanitized += '_'\\r\\n }\\r\\n }\\r\\n return (\\r\\n 'embedded-lib-' +\\r\\n sanitized +\\r\\n '-' +\\r\\n Date.now() +\\r\\n '-' +\\r\\n Math.random().toString(36).slice(2)\\r\\n )\\r\\n }\\r\\n\\r\\n function postHostRequest(assetKey, requestId) {\\r\\n if (!hasHostBridge()) {\\r\\n throw new Error('Host bridge is unavailable')\\r\\n }\\r\\n var bridge = window.ReactNativeWebView\\r\\n var message = {\\r\\n type: REQUEST_TYPE,\\r\\n direction: 'H5_TO_APP',\\r\\n data: {\\r\\n requestId: requestId,\\r\\n assetKey: assetKey,\\r\\n },\\r\\n instanceId:\\r\\n (window._venusInitState && window._venusInitState.poolId) || 'unknown',\\r\\n timestamp: Date.now(),\\r\\n }\\r\\n bridge.postMessage(JSON.stringify(message))\\r\\n }\\r\\n\\r\\n function loadLibraryViaHost(assetKey, libraryKey) {\\r\\n return new Promise(function (resolve, reject) {\\r\\n var requestId = createRequestId(libraryKey)\\r\\n var timeout = setTimeout(function () {\\r\\n pendingRequests.delete(requestId)\\r\\n reject(new Error('Timed out loading embedded library: ' + libraryKey))\\r\\n }, REQUEST_TIMEOUT_MS)\\r\\n\\r\\n pendingRequests.set(requestId, {\\r\\n resolve: resolve,\\r\\n reject: reject,\\r\\n timeout: timeout,\\r\\n })\\r\\n\\r\\n try {\\r\\n postHostRequest(assetKey, requestId)\\r\\n } catch (error) {\\r\\n pendingRequests.delete(requestId)\\r\\n clearTimeout(timeout)\\r\\n reject(error)\\r\\n }\\r\\n })\\r\\n }\\r\\n\\r\\n function buildCdnUrl(config, entry) {\\r\\n var base = config.cdnBase || ''\\r\\n if (!base.endsWith('/')) {\\r\\n base += '/'\\r\\n }\\r\\n var path = entry.cdnPath\\r\\n if (path.charAt(0) === '/') {\\r\\n path = path.substring(1)\\r\\n }\\r\\n return base + path\\r\\n }\\r\\n\\r\\n async function loadLibraryViaCdn(config, entry, libraryKey) {\\r\\n if (!config.cdnBase) {\\r\\n throw new Error('CDN base URL is not configured')\\r\\n }\\r\\n var url = buildCdnUrl(config, entry)\\r\\n var response = await fetch(url, { credentials: 'omit' })\\r\\n if (!response.ok) {\\r\\n throw new Error(\\r\\n 'Failed to fetch embedded library from CDN: ' + libraryKey,\\r\\n )\\r\\n }\\r\\n return await response.text()\\r\\n }\\r\\n\\r\\n function decodeBase64ToUtf8(base64) {\\r\\n if (typeof base64 !== 'string') {\\r\\n throw new Error('Invalid base64 payload')\\r\\n }\\r\\n\\r\\n if (typeof atob === 'function') {\\r\\n var binary = atob(base64)\\r\\n if (typeof TextDecoder !== 'undefined') {\\r\\n var len = binary.length\\r\\n var bytes = new Uint8Array(len)\\r\\n for (var i = 0; i < len; i++) {\\r\\n bytes[i] = binary.charCodeAt(i)\\r\\n }\\r\\n return new TextDecoder('utf-8').decode(bytes)\\r\\n }\\r\\n return decodeURIComponent(escape(binary))\\r\\n }\\r\\n\\r\\n var bufferCtor =\\r\\n (typeof globalThis !== 'undefined' && globalThis.Buffer) ||\\r\\n (typeof window !== 'undefined' && window.Buffer)\\r\\n if (bufferCtor) {\\r\\n return bufferCtor.from(base64, 'base64').toString('utf-8')\\r\\n }\\r\\n\\r\\n throw new Error('No base64 decoder available')\\r\\n }\\r\\n\\r\\n function evaluateLibrarySource(libraryKey, globalVar, source) {\\r\\n var registry = ensureExportsRegistry()\\r\\n if (!source) {\\r\\n throw new Error('Embedded library source was empty for ' + libraryKey)\\r\\n }\\r\\n\\r\\n var previousValue = window[globalVar]\\r\\n try {\\r\\n var executor = new Function(\\r\\n source + '\\\\n//# sourceURL=venus-library-' + libraryKey + '.js',\\r\\n )\\r\\n executor.call(window)\\r\\n } catch (error) {\\r\\n throw new Error(\\r\\n 'Failed to evaluate embedded library ' +\\r\\n libraryKey +\\r\\n ': ' +\\r\\n (error && error.message ? error.message : error),\\r\\n )\\r\\n }\\r\\n\\r\\n var exported = window[globalVar] || previousValue\\r\\n if (!exported) {\\r\\n throw new Error(\\r\\n 'Embedded library ' + libraryKey + ' did not register ' + globalVar,\\r\\n )\\r\\n }\\r\\n\\r\\n registry[libraryKey] = exported\\r\\n return exported\\r\\n }\\r\\n\\r\\n async function ensureLibraryLoaded(config, libraryKey) {\\r\\n var registry = ensureExportsRegistry()\\r\\n if (registry[libraryKey]) {\\r\\n return registry[libraryKey]\\r\\n }\\r\\n\\r\\n var entry = config.manifest && config.manifest[libraryKey]\\r\\n if (!entry) {\\r\\n throw new Error('No manifest entry for embedded library ' + libraryKey)\\r\\n }\\r\\n\\r\\n var source = null\\r\\n if (config.useHost !== false && hasHostBridge()) {\\r\\n try {\\r\\n var base64 = await loadLibraryViaHost(entry.assetKey, libraryKey)\\r\\n source = decodeBase64ToUtf8(base64)\\r\\n } catch (error) {\\r\\n // Log the RPC error loudly before fallback\\r\\n console.error(\\r\\n '[Venus Libraries] Failed to load ' +\\r\\n libraryKey +\\r\\n ' from host via RPC:',\\r\\n error,\\r\\n )\\r\\n console.warn(\\r\\n '[Venus Libraries] Falling back to CDN for ' +\\r\\n libraryKey +\\r\\n '. This may indicate an asset packaging issue.',\\r\\n )\\r\\n }\\r\\n }\\r\\n\\r\\n if (!source) {\\r\\n source = await loadLibraryViaCdn(config, entry, libraryKey)\\r\\n }\\r\\n\\r\\n return evaluateLibrarySource(libraryKey, entry.globalVar, source)\\r\\n }\\r\\n\\r\\n async function bootstrap() {\\r\\n try {\\r\\n registerResponseListeners()\\r\\n getBootstrapPromise()\\r\\n\\r\\n var config = ensureConfig()\\r\\n\\r\\n if (!config.enabled) {\\r\\n if (bootstrapResolve) bootstrapResolve()\\r\\n return\\r\\n }\\r\\n\\r\\n if (!Array.isArray(config.required) || config.required.length === 0) {\\r\\n if (bootstrapResolve) bootstrapResolve()\\r\\n return\\r\\n }\\r\\n\\r\\n // Group libraries by load stage for parallel loading within stages\\r\\n var librariesByStage = {}\\r\\n for (var i = 0; i < config.required.length; i++) {\\r\\n var libraryKey = config.required[i]\\r\\n var entry = config.manifest[libraryKey]\\r\\n var stage = entry.loadStage || 0\\r\\n if (!librariesByStage[stage]) librariesByStage[stage] = []\\r\\n librariesByStage[stage].push(libraryKey)\\r\\n }\\r\\n\\r\\n // Load stages sequentially, libraries within each stage in parallel\\r\\n var stages = Object.keys(librariesByStage).sort(function (a, b) {\\r\\n return parseInt(a, 10) - parseInt(b, 10)\\r\\n })\\r\\n\\r\\n for (var s = 0; s < stages.length; s++) {\\r\\n var stage = stages[s]\\r\\n var libs = librariesByStage[stage]\\r\\n\\r\\n // Load all libraries in this stage in parallel\\r\\n var stagePromises = libs.map(function (libraryKey) {\\r\\n return ensureLibraryLoaded(config, libraryKey).catch(\\r\\n function (error) {\\r\\n console.error(\\r\\n '[Venus Libraries] Failed to load library ' + libraryKey,\\r\\n error,\\r\\n )\\r\\n throw error\\r\\n },\\r\\n )\\r\\n })\\r\\n\\r\\n await Promise.all(stagePromises)\\r\\n }\\r\\n\\r\\n if (bootstrapResolve) bootstrapResolve()\\r\\n } catch (error) {\\r\\n console.error('[Venus Libraries] Bootstrap error', error)\\r\\n if (bootstrapReject) bootstrapReject(error)\\r\\n throw error\\r\\n }\\r\\n }\\r\\n\\r\\n // Create a promise that resolves when bootstrap completes\\r\\n var bootstrapPromise = null\\r\\n var bootstrapResolve = null\\r\\n var bootstrapReject = null\\r\\n\\r\\n function getBootstrapPromise() {\\r\\n if (!bootstrapPromise) {\\r\\n bootstrapPromise = new Promise(function (resolve, reject) {\\r\\n bootstrapResolve = resolve\\r\\n bootstrapReject = reject\\r\\n })\\r\\n }\\r\\n return bootstrapPromise\\r\\n }\\r\\n\\r\\n window.__venusLibraryShim = {\\r\\n bootstrap: bootstrap,\\r\\n ready: getBootstrapPromise,\\r\\n getExports: function (libraryKey) {\\r\\n var registry = ensureExportsRegistry()\\r\\n return registry[libraryKey]\\r\\n },\\r\\n __initialized: true,\\r\\n }\\r\\n})()\\r\\n\"","/**\r\n * Webview Library Shim Source\r\n *\r\n * This module exports the shim code that is injected into H5 game WebViews.\r\n * The actual shim code is in webviewLibraryShim.js and imported as a raw string.\r\n *\r\n * Using Vite's ?raw import allows us to:\r\n * - Keep the shim as actual JavaScript (not a string literal)\r\n * - Get proper IDE support (syntax highlighting, linting)\r\n * - Avoid escaping issues\r\n */\r\n\r\nimport shimSource from './webviewLibraryShim.js?raw'\r\n\r\nexport const WEBVIEW_LIBRARY_SHIM_SOURCE = shimSource\r\n\r\nexport function getWebviewLibraryShimSource(): string {\r\n return WEBVIEW_LIBRARY_SHIM_SOURCE\r\n}\r\n"]}
@@ -1,4 +0,0 @@
1
- export { MOCK_DELAYS, createMockDelay, createProxiedMethod, createProxiedObject, isWebPlatform } from './chunk-QABXMFND.mjs';
2
- import './chunk-NSSMTXJJ.mjs';
3
- //# sourceMappingURL=core-62LWDHN7.mjs.map
4
- //# sourceMappingURL=core-62LWDHN7.mjs.map
@@ -1,534 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var fs = require('fs');
5
-
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var path__default = /*#__PURE__*/_interopDefault(path);
9
- var fs__default = /*#__PURE__*/_interopDefault(fs);
10
-
11
- // src/vite/venusLibrariesPlugin.ts
12
-
13
- // src/shared-assets/embeddedLibrariesManifest.ts
14
- var DEFAULT_SHARED_LIB_CDN_BASE = "https://venus-static-01293ak.web.app/libs";
15
- var EMBEDDED_LIBRARIES = [
16
- {
17
- libraryKey: "phaser@3.90.0",
18
- assetKey: "library:phaser@3.90.0",
19
- packageName: "phaser",
20
- version: "3.90.0",
21
- globalVar: "Phaser",
22
- cdnPath: "phaser/3.90.0/phaser.min.js",
23
- moduleSpecifiers: [{ match: "exact", value: "phaser" }],
24
- loadStage: 0,
25
- enabled: true
26
- },
27
- {
28
- libraryKey: "react@18.3.1",
29
- assetKey: "library:react@18.3.1",
30
- packageName: "react",
31
- version: "18.3.1",
32
- globalVar: "React",
33
- cdnPath: "react/18.3.1/react.production.min.js",
34
- moduleSpecifiers: [
35
- { match: "exact", value: "react", behavior: "namespace" },
36
- { match: "exact", value: "react/jsx-runtime", behavior: "react-jsx-runtime" },
37
- {
38
- match: "exact",
39
- value: "react/jsx-dev-runtime",
40
- behavior: "react-jsx-dev-runtime"
41
- }
42
- ],
43
- loadStage: 0,
44
- // Must load before ReactDOM
45
- enabled: true
46
- },
47
- {
48
- libraryKey: "react-dom@18.3.1",
49
- assetKey: "library:react-dom@18.3.1",
50
- packageName: "react-dom",
51
- version: "18.3.1",
52
- globalVar: "ReactDOM",
53
- cdnPath: "react-dom/18.3.1/react-dom.production.min.js",
54
- moduleSpecifiers: [
55
- { match: "exact", value: "react-dom", behavior: "namespace" },
56
- { match: "exact", value: "react-dom/client", behavior: "namespace" }
57
- ],
58
- loadStage: 1,
59
- // Depends on React (stage 0)
60
- enabled: true
61
- },
62
- {
63
- libraryKey: "three@0.170.0",
64
- assetKey: "library:three@0.170.0",
65
- packageName: "three",
66
- version: "0.170.0",
67
- globalVar: "THREE",
68
- cdnPath: "three/r170/three.min.js",
69
- moduleSpecifiers: [
70
- { match: "exact", value: "three", behavior: "namespace" },
71
- { match: "prefix", value: "three/examples/jsm/", behavior: "namespace" }
72
- ],
73
- loadStage: 0,
74
- enabled: true
75
- },
76
- {
77
- libraryKey: "matter-js@0.19.0",
78
- assetKey: "library:matter-js@0.19.0",
79
- packageName: "matter-js",
80
- version: "0.19.0",
81
- globalVar: "Matter",
82
- cdnPath: "matter-js/0.19.0/matter.min.js",
83
- moduleSpecifiers: [{ match: "exact", value: "matter-js" }],
84
- loadStage: 0,
85
- enabled: true
86
- },
87
- {
88
- libraryKey: "inkjs@2.2.0",
89
- assetKey: "library:inkjs@2.2.0",
90
- packageName: "inkjs",
91
- version: "2.2.0",
92
- globalVar: "inkjs",
93
- cdnPath: "inkjs/2.2.0/ink.min.js",
94
- moduleSpecifiers: [{ match: "exact", value: "inkjs" }],
95
- loadStage: 0,
96
- enabled: true
97
- },
98
- {
99
- libraryKey: "zustand@5.0.3",
100
- assetKey: "library:zustand@5.0.3",
101
- packageName: "zustand",
102
- version: "5.0.3",
103
- globalVar: "zustand",
104
- cdnPath: "zustand/5.0.3/zustand.min.js",
105
- moduleSpecifiers: [
106
- { match: "exact", value: "zustand" },
107
- { match: "exact", value: "zustand/middleware" }
108
- ],
109
- loadStage: 0,
110
- enabled: true
111
- },
112
- {
113
- libraryKey: "ammo.js@2024.11",
114
- assetKey: "library:ammo.js@2024.11",
115
- packageName: "ammo.js",
116
- version: "2024.11",
117
- globalVar: "Ammo",
118
- cdnPath: "ammo/2024.11/ammo.js",
119
- moduleSpecifiers: [
120
- { match: "exact", value: "ammo.js" },
121
- { match: "exact", value: "ammo.js/builds/ammo.wasm.js" }
122
- ],
123
- loadStage: 0,
124
- enabled: false
125
- // Not ready yet - WASM loading needs additional work
126
- }
127
- ];
128
- var EMBEDDED_LIBRARY_BY_KEY = EMBEDDED_LIBRARIES.reduce(
129
- (acc, lib) => {
130
- acc[lib.libraryKey] = lib;
131
- return acc;
132
- },
133
- {}
134
- );
135
- var MODULE_TO_LIBRARY_SPECIFIERS = EMBEDDED_LIBRARIES.filter(
136
- (lib) => lib.enabled
137
- ).flatMap(
138
- (lib) => lib.moduleSpecifiers.map((specifier) => ({
139
- ...specifier,
140
- libraryKey: lib.libraryKey
141
- }))
142
- );
143
-
144
- // src/vite/venusLibrariesPlugin.ts
145
- function generateVirtualModule(lib, spec, importPath) {
146
- const errorCheck = `
147
- // Wait for shim to complete loading libraries
148
- if (window.__venusLibraryShim && window.__venusLibraryShim.ready) {
149
- try {
150
- await window.__venusLibraryShim.ready();
151
- } catch (error) {
152
- console.error('[Venus Libraries] Shim bootstrap failed:', error);
153
- throw error;
154
- }
155
- } else {
156
- console.warn('[Venus Libraries] No shim found - running without embedded libraries');
157
- }
158
-
159
- // Verify library was loaded
160
- if (!window.__venusLibraryExports || !window.__venusLibraryExports['${lib.libraryKey}']) {
161
- console.error('[Venus Libraries] ${lib.packageName} library not loaded');
162
- console.error('[Venus Libraries] Config:', window.__venusLibrariesConfig);
163
- console.error('[Venus Libraries] Exports:', window.__venusLibraryExports);
164
- throw new Error(
165
- '${lib.packageName} not loaded (${importPath}). Check console for errors.'
166
- );
167
- }
168
- `;
169
- const libVar = `window.__venusLibraryExports['${lib.libraryKey}']`;
170
- switch (spec.behavior) {
171
- case "react-jsx-runtime":
172
- return `
173
- const React = await (async function() {
174
- ${errorCheck}
175
- return ${libVar};
176
- })();
177
-
178
- export const jsx = React.jsx || function(type, props, key) {
179
- return React.createElement(type, { ...props, key });
180
- };
181
- export const jsxs = React.jsxs || jsx;
182
- export const Fragment = React.Fragment;
183
- `;
184
- case "react-jsx-dev-runtime":
185
- return `
186
- const React = await (async function() {
187
- ${errorCheck}
188
- return ${libVar};
189
- })();
190
-
191
- export const jsxDEV = React.jsxDEV || React.createElement;
192
- export const Fragment = React.Fragment;
193
- `;
194
- case "namespace":
195
- let namedExports = "";
196
- if (lib.packageName === "react") {
197
- namedExports = `
198
- export const {
199
- createElement, createContext, createRef,
200
- Component, PureComponent, Fragment, StrictMode, Suspense, lazy, forwardRef, memo,
201
- useState, useEffect, useContext, useReducer, useCallback, useMemo, useRef,
202
- useLayoutEffect, useImperativeHandle, useDebugValue, useTransition, useDeferredValue,
203
- Children, cloneElement, isValidElement, version
204
- } = lib;`;
205
- } else if (lib.packageName === "react-dom") {
206
- namedExports = `
207
- export const { createRoot, hydrateRoot, render, unmountComponentAtNode, findDOMNode, version } = lib;`;
208
- } else if (lib.packageName === "three") {
209
- namedExports = `
210
- // Three.js exports everything on the global THREE object, accessible via default export
211
- // Individual exports can be accessed as: import THREE from 'three'; const { Scene, Camera } = THREE;`;
212
- } else {
213
- namedExports = "";
214
- }
215
- return `
216
- const lib = await (async function() {
217
- ${errorCheck}
218
- return ${libVar};
219
- })();
220
-
221
- export default lib;
222
- ${namedExports}
223
- `;
224
- case "default":
225
- case void 0:
226
- return `
227
- const lib = await (async function() {
228
- ${errorCheck}
229
- return ${libVar};
230
- })();
231
-
232
- export default lib;
233
- `;
234
- default:
235
- throw new Error(
236
- `Unknown behavior: ${spec.behavior} for ${lib.packageName}. Valid behaviors: default, namespace, react-jsx-runtime, react-jsx-dev-runtime`
237
- );
238
- }
239
- }
240
- function venusLibrariesPlugin(options = {}) {
241
- const cdnDir = path__default.default.resolve(options.cdnDir || "./cdn");
242
- const debug = options.debug || false;
243
- const requiredLibraries = /* @__PURE__ */ new Set();
244
- let isServe = false;
245
- let enabled = false;
246
- let appName = options.appName;
247
- return {
248
- name: "vite-plugin-venus-libraries",
249
- enforce: "pre",
250
- // Run before other plugins to intercept imports
251
- // 0. Configure Vite build options
252
- config(config) {
253
- if (!enabled) return;
254
- if (!config.build) config.build = {};
255
- if (!config.build.rollupOptions) config.build.rollupOptions = {};
256
- if (config.build.rollupOptions.output) {
257
- const output = config.build.rollupOptions.output;
258
- const outputs = Array.isArray(output) ? output : [output];
259
- outputs.forEach((o) => {
260
- if (o.manualChunks && typeof o.manualChunks === "object") {
261
- const chunks = o.manualChunks;
262
- EMBEDDED_LIBRARIES.forEach((lib) => {
263
- if (lib.enabled && chunks[lib.packageName]) {
264
- delete chunks[lib.packageName];
265
- }
266
- });
267
- }
268
- });
269
- }
270
- },
271
- // Log plugin status
272
- configResolved(config) {
273
- isServe = config.command === "serve";
274
- enabled = !isServe && process.env.VENUS_DISABLE_EMBEDDED_LIBS !== "true";
275
- if (!appName && config.root) {
276
- const rootParts = config.root.split(path__default.default.sep);
277
- const h5Index = rootParts.indexOf("H5");
278
- if (h5Index >= 0 && h5Index < rootParts.length - 1) {
279
- appName = rootParts[h5Index + 1];
280
- if (debug) {
281
- console.log(
282
- `[Venus Libraries] Auto-detected app name from folder structure: ${appName}`
283
- );
284
- }
285
- } else if (debug) {
286
- console.log(
287
- "[Venus Libraries] Not in H5 folder structure - CDN asset serving disabled (embedded libraries still work)"
288
- );
289
- }
290
- }
291
- if (isServe) {
292
- return;
293
- }
294
- if (!enabled) {
295
- console.log(
296
- "\n[Venus Libraries] Building with bundled libraries (standalone mode)"
297
- );
298
- }
299
- },
300
- // 1. Intercept library imports
301
- resolveId(id, importer) {
302
- if (!enabled) return null;
303
- const match = MODULE_TO_LIBRARY_SPECIFIERS.find((spec) => {
304
- if (spec.match === "exact") {
305
- return spec.value === id;
306
- } else if (spec.match === "prefix") {
307
- return id.startsWith(spec.value);
308
- }
309
- return false;
310
- });
311
- if (match) {
312
- requiredLibraries.add(match.libraryKey);
313
- const virtualId = `\0virtual:venus-lib:${match.libraryKey}:${id}`;
314
- return virtualId;
315
- }
316
- return null;
317
- },
318
- // 2. Generate virtual module
319
- load(id) {
320
- if (!id.startsWith("\0virtual:venus-lib:")) {
321
- return null;
322
- }
323
- const parts = id.split(":");
324
- const libraryKey = parts[2];
325
- const importPath = parts.slice(3).join(":");
326
- const lib = EMBEDDED_LIBRARY_BY_KEY[libraryKey];
327
- if (!lib) {
328
- const availableKeys = Object.keys(EMBEDDED_LIBRARY_BY_KEY).join(", ");
329
- throw new Error(
330
- `Unknown library: ${libraryKey}. Available libraries: ${availableKeys}`
331
- );
332
- }
333
- const spec = lib.moduleSpecifiers.find((s) => s.value === importPath);
334
- if (!spec) {
335
- const validSpecifiers = lib.moduleSpecifiers.map((s) => s.value).join(", ");
336
- throw new Error(
337
- `Unknown module specifier: ${importPath} for ${libraryKey}. Valid specifiers: ${validSpecifiers}`
338
- );
339
- }
340
- const virtualModule = generateVirtualModule(lib, spec, importPath);
341
- return `// Virtual module: ${importPath}
342
- ${virtualModule}`;
343
- },
344
- // 3. Transform HTML - inject config and shim for web support
345
- transformIndexHtml(html) {
346
- if (!enabled || requiredLibraries.size === 0) {
347
- return html;
348
- }
349
- const manifest = {};
350
- requiredLibraries.forEach((libraryKey) => {
351
- const lib = EMBEDDED_LIBRARY_BY_KEY[libraryKey];
352
- manifest[libraryKey] = {
353
- assetKey: lib.assetKey,
354
- cdnPath: lib.cdnPath,
355
- globalVar: lib.globalVar,
356
- loadStage: lib.loadStage
357
- };
358
- });
359
- const embeddedLibsScript = `
360
- <script>
361
- // Set config (may be overridden by Venus host)
362
- if (!window.__venusLibrariesConfig) {
363
- window.__venusLibrariesConfig = {
364
- enabled: true,
365
- required: ${JSON.stringify(Array.from(requiredLibraries))},
366
- manifest: ${JSON.stringify(manifest, null, 2)},
367
- cdnBase: '${DEFAULT_SHARED_LIB_CDN_BASE}',
368
- useHost: false, // Web uses CDN
369
- debug: ${debug}
370
- };
371
- }
372
-
373
- // Minimal shim for web (CDN loading)
374
- if (!window.__venusLibraryShim) {
375
- var bootstrapResolve, bootstrapReject;
376
- var bootstrapPromise = new Promise(function(resolve, reject) {
377
- bootstrapResolve = resolve;
378
- bootstrapReject = reject;
379
- });
380
-
381
- window.__venusLibraryShim = {
382
- ready: function() { return bootstrapPromise; },
383
- __initialized: true
384
- };
385
-
386
- // Auto-load libraries from CDN by stage (respects dependencies)
387
- var config = window.__venusLibrariesConfig;
388
- if (!config.required || config.required.length === 0) {
389
- bootstrapResolve();
390
- } else {
391
- // Group libraries by load stage
392
- var librariesByStage = {};
393
- for (var i = 0; i < config.required.length; i++) {
394
- var libraryKey = config.required[i];
395
- var entry = config.manifest[libraryKey];
396
- var stage = entry.loadStage || 0;
397
- if (!librariesByStage[stage]) librariesByStage[stage] = [];
398
- librariesByStage[stage].push({ libraryKey: libraryKey, entry: entry });
399
- }
400
-
401
- // Load stages sequentially, libraries within each stage in parallel
402
- var stages = Object.keys(librariesByStage).sort(function(a, b) { return parseInt(a, 10) - parseInt(b, 10); });
403
-
404
- (async function loadByStages() {
405
- for (var s = 0; s < stages.length; s++) {
406
- var stage = stages[s];
407
- var libs = librariesByStage[stage];
408
-
409
- // Load all libraries in this stage in parallel
410
- var stagePromises = libs.map(function(lib) {
411
- var base = config.cdnBase || '';
412
- if (!base.endsWith('/')) base += '/';
413
- var path = lib.entry.cdnPath;
414
- if (path.charAt(0) === '/') path = path.substring(1);
415
- var url = base + path;
416
- return fetch(url)
417
- .then(function(r) { return r.text(); })
418
- .then(function(src) {
419
- (new Function(src)).call(window);
420
- if (!window.__venusLibraryExports) window.__venusLibraryExports = {};
421
- window.__venusLibraryExports[lib.libraryKey] = window[lib.entry.globalVar];
422
- });
423
- });
424
-
425
- await Promise.all(stagePromises);
426
- }
427
- })()
428
- .then(function() {
429
- bootstrapResolve();
430
- })
431
- .catch(function(err) {
432
- console.error('[Venus Libraries] Library loading failed:', err);
433
- bootstrapReject(err);
434
- });
435
- }
436
- }
437
- </script>`;
438
- return html.replace("<head>", "<head>" + embeddedLibsScript);
439
- },
440
- // 4. Serve CDN assets in dev mode (only if in H5 folder structure)
441
- configureServer(server) {
442
- if (!enabled || !appName) {
443
- return;
444
- }
445
- if (debug) {
446
- console.log(
447
- `[Venus Libraries] Dev server will serve /${appName}/* from ${cdnDir}`
448
- );
449
- }
450
- server.middlewares.use(
451
- (req, res, next) => {
452
- if (!req.url) return next();
453
- const urlPath = req.url.split("?")[0];
454
- if (!urlPath.startsWith(`/${appName}/`)) return next();
455
- const relativePath = urlPath.replace(`/${appName}/`, "");
456
- const filePath = path__default.default.join(cdnDir, relativePath);
457
- if (fs__default.default.existsSync(filePath) && fs__default.default.statSync(filePath).isFile()) {
458
- const ext = path__default.default.extname(filePath).toLowerCase();
459
- const contentTypes = {
460
- ".png": "image/png",
461
- ".jpg": "image/jpeg",
462
- ".jpeg": "image/jpeg",
463
- ".gif": "image/gif",
464
- ".webp": "image/webp",
465
- ".mp3": "audio/mpeg",
466
- ".mp4": "video/mp4",
467
- ".ogg": "audio/ogg",
468
- ".wav": "audio/wav",
469
- ".json": "application/json"
470
- };
471
- res.setHeader(
472
- "Content-Type",
473
- contentTypes[ext] || "application/octet-stream"
474
- );
475
- res.setHeader("Cache-Control", "public, max-age=3600");
476
- return res.end(fs__default.default.readFileSync(filePath));
477
- }
478
- next();
479
- }
480
- );
481
- },
482
- // 5. Emit manifest for debugging
483
- generateBundle() {
484
- if (!enabled || requiredLibraries.size === 0) return;
485
- const libraries = {};
486
- const libraryNames = [];
487
- let totalSavingsKB = 0;
488
- requiredLibraries.forEach((libraryKey) => {
489
- const lib = EMBEDDED_LIBRARY_BY_KEY[libraryKey];
490
- libraries[libraryKey] = {
491
- assetKey: lib.assetKey,
492
- cdnPath: lib.cdnPath,
493
- globalVar: lib.globalVar,
494
- packageName: lib.packageName,
495
- version: lib.version,
496
- moduleSpecifiers: lib.moduleSpecifiers.map((s) => s.value)
497
- };
498
- libraryNames.push(lib.packageName);
499
- const sizes = {
500
- phaser: 1100,
501
- react: 138,
502
- "react-dom": 42,
503
- three: 600,
504
- "matter-js": 100,
505
- inkjs: 50
506
- };
507
- totalSavingsKB += sizes[lib.packageName] || 0;
508
- });
509
- const manifest = {
510
- enabled: true,
511
- required: Array.from(requiredLibraries),
512
- libraries,
513
- cdnBase: DEFAULT_SHARED_LIB_CDN_BASE,
514
- buildTime: (/* @__PURE__ */ new Date()).toISOString(),
515
- plugin: "@series-inc/venus-sdk/vite"
516
- };
517
- this.emitFile({
518
- type: "asset",
519
- fileName: "venus-libraries.manifest.json",
520
- source: JSON.stringify(manifest, null, 2)
521
- });
522
- const libList = libraryNames.join(", ");
523
- const savingsMsg = totalSavingsKB > 0 ? ` (~${totalSavingsKB}KB saved)` : "";
524
- console.log(
525
- `
526
- [Venus Libraries] Using embedded libraries to reduce bundle size: ${libList}${savingsMsg}`
527
- );
528
- }
529
- };
530
- }
531
-
532
- exports.venusLibrariesPlugin = venusLibrariesPlugin;
533
- //# sourceMappingURL=index.cjs.map
534
- //# sourceMappingURL=index.cjs.map