mini-three-adapter 0.0.0-stage → 0.1.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/AGENTS.md +85 -0
- package/LICENSE +21 -0
- package/README.md +158 -2
- package/dist/build/rollup.d.ts +8 -0
- package/dist/build/rollup.js +393 -0
- package/dist/build/rollup.js.map +1 -0
- package/dist/build/vite.d.ts +15 -0
- package/dist/build/vite.js +395 -0
- package/dist/build/vite.js.map +1 -0
- package/dist/chunk-34RWHAW4.js +128 -0
- package/dist/chunk-34RWHAW4.js.map +1 -0
- package/dist/chunk-3UGQWFH3.js +1246 -0
- package/dist/chunk-3UGQWFH3.js.map +1 -0
- package/dist/chunk-4UEBRAK6.js +711 -0
- package/dist/chunk-4UEBRAK6.js.map +1 -0
- package/dist/chunk-LB3WL24R.js +91 -0
- package/dist/chunk-LB3WL24R.js.map +1 -0
- package/dist/chunk-MTBMOFAL.js +132 -0
- package/dist/chunk-MTBMOFAL.js.map +1 -0
- package/dist/chunk-QYQQ5J6E.js +3 -0
- package/dist/chunk-QYQQ5J6E.js.map +1 -0
- package/dist/chunk-V6TY7KAL.js +7 -0
- package/dist/chunk-V6TY7KAL.js.map +1 -0
- package/dist/chunk-WLRQDTSZ.js +145 -0
- package/dist/chunk-WLRQDTSZ.js.map +1 -0
- package/dist/chunk-Z7AMDRN3.js +66 -0
- package/dist/chunk-Z7AMDRN3.js.map +1 -0
- package/dist/core/index.d.ts +101 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/platforms/browser.d.ts +23 -0
- package/dist/platforms/browser.js +7 -0
- package/dist/platforms/browser.js.map +1 -0
- package/dist/platforms/wechat-game.d.ts +31 -0
- package/dist/platforms/wechat-game.js +8 -0
- package/dist/platforms/wechat-game.js.map +1 -0
- package/dist/platforms/wechat-miniprogram.d.ts +26 -0
- package/dist/platforms/wechat-miniprogram.js +8 -0
- package/dist/platforms/wechat-miniprogram.js.map +1 -0
- package/dist/plugin-core-BuqW9C-L.d.ts +127 -0
- package/dist/polyfills/index.d.ts +291 -0
- package/dist/polyfills/index.js +4 -0
- package/dist/polyfills/index.js.map +1 -0
- package/dist/runtime-7uUOoFhC.d.ts +263 -0
- package/dist/scope.d.ts +146 -0
- package/dist/scope.js +4 -0
- package/dist/scope.js.map +1 -0
- package/dist/types-BzK0LQMa.d.ts +153 -0
- package/dist/wx-types-NMNyrsWO.d.ts +150 -0
- package/docs/01-design-principles.md +105 -0
- package/docs/02-architecture.md +126 -0
- package/docs/03-module-map.md +99 -0
- package/docs/04-api-reference.md +291 -0
- package/docs/05-build-plugin.md +146 -0
- package/docs/06-platform-notes.md +108 -0
- package/docs/07-integration-guide.md +211 -0
- package/docs/08-extension-guide.md +101 -0
- package/docs/09-testing-and-release.md +206 -0
- package/docs/10-ai-playbook.md +140 -0
- package/docs/11-compat-matrix.md +94 -0
- package/docs/README.md +41 -0
- package/docs/adr/0001-scoped-globals.md +41 -0
- package/docs/adr/0002-unified-runtime-lifecycle.md +40 -0
- package/docs/adr/0003-ast-rewrite.md +51 -0
- package/docs/adr/0004-in-place-patching.md +42 -0
- package/docs/adr/0005-webgl2-only.md +44 -0
- package/docs/adr/0006-zero-three-dependency.md +43 -0
- package/docs/adr/README.md +28 -0
- package/llms.txt +65 -0
- package/package.json +117 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/build/plugin-core.ts","../../src/build/scope-rewrite.ts","../../src/build/assets.ts","../../src/build/rollup.ts"],"sourcesContent":["/**\n * Rollup/Vite-compatible plugin core (zero hard dependency on either bundler).\n *\n * Responsibilities:\n * 1. Rewrite free browser globals inside third-party modules to scoped access.\n * 2. Handle `three/webgpu` (WebGPU is unavailable in WeChat mini games).\n * 3. Collect worker/wasm assets referenced by addons and emit them + a manifest.\n * 4. Produce a machine-readable build report for CI and AI-assisted iteration.\n */\nimport { promises as fs } from 'node:fs';\nimport {\n DEFAULT_FORCE_UNDEF,\n rewriteGlobals,\n type RewriteOptions,\n} from './scope-rewrite';\nimport {\n collectAssetReferences,\n collectAssets,\n type AssetManifest,\n type AssetOptions,\n} from './assets';\n\nexport interface MiniThreePluginOptions extends AssetOptions {\n /** Extra modules to transform. Receives a normalized (slash-separated) id. */\n include?: (id: string) => boolean;\n /** Modules to skip even when they match. */\n exclude?: (id: string) => boolean;\n /** Also transform application code (off by default). */\n includeUserCode?: boolean;\n /** Rewrite options (advanced). */\n rewrite?: RewriteOptions;\n /** How to handle `three/webgpu` imports. Default 'warn'. */\n webgpu?: 'warn' | 'error' | 'rewrite' | 'ignore';\n /** Print a build report summary. Default true. */\n report?: boolean;\n /** Verbose per-module logs. */\n debug?: boolean;\n}\n\nexport interface BuildReport {\n modulesScanned: number;\n modulesRewritten: number;\n rewrites: number;\n globalsSeen: string[];\n assetReferences: string[];\n missingAssets: string[];\n webgpuWarnings: string[];\n parseFailures: string[];\n}\n\nexport interface PluginContext {\n warn(message: string): void;\n error(message: string): never;\n emitFile(file: { type: 'asset'; fileName: string; source: string | Uint8Array }): string;\n}\n\nexport interface MiniThreePlugin {\n name: string;\n enforce: 'pre';\n transform(this: PluginContext, code: string, id: string): { code: string; map: unknown } | null;\n generateBundle(this: PluginContext, options: { dir?: string; file?: string }): Promise<void>;\n api: {\n report(): BuildReport;\n };\n}\n\nconst DEFAULT_INCLUDE = (id: string): boolean => {\n const normalized = id.replace(/\\\\/g, '/').split('?')[0] ?? id;\n return (\n normalized.includes('/node_modules/three/') ||\n normalized.includes('/node_modules/three-stdlib/') ||\n normalized.includes('/node_modules/@react-three/') ||\n normalized.includes('/node_modules/@tresjs/') ||\n normalized.includes('/node_modules/.vite/deps/three') ||\n normalized.includes('/node_modules/.vite/deps/three-stdlib') ||\n /\\/node_modules\\/three@[^/]+\\//.test(normalized)\n );\n};\n\nexport function miniThreePlugin(options: MiniThreePluginOptions = {}): MiniThreePlugin {\n const include = options.include ?? DEFAULT_INCLUDE;\n const exclude = options.exclude ?? (() => false);\n const webgpuMode = options.webgpu ?? 'warn';\n const report: BuildReport = {\n modulesScanned: 0,\n modulesRewritten: 0,\n rewrites: 0,\n globalsSeen: [],\n assetReferences: [],\n missingAssets: [],\n webgpuWarnings: [],\n parseFailures: [],\n };\n const seenGlobals = new Set<string>();\n const assetRefs = new Set<string>();\n let manifest: AssetManifest | null = null;\n let filesToEmit = new Map<string, string>();\n\n const note = (ctx: PluginContext, message: string): void => {\n if (options.debug) ctx.warn(`[mini-three] ${message}`);\n };\n\n return {\n name: 'mini-three-adapter',\n enforce: 'pre',\n\n transform(this: PluginContext, code: string, id: string) {\n const normalized = id.replace(/\\\\/g, '/');\n const shouldTransform = options.includeUserCode\n ? !normalized.includes('/node_modules/mini-three-adapter/') && !exclude(normalized)\n : include(normalized) && !exclude(normalized);\n if (!shouldTransform) return null;\n\n report.modulesScanned++;\n for (const ref of collectAssetReferences(code)) assetRefs.add(ref);\n\n let currentCode = code;\n if (webgpuMode !== 'ignore' && /from\\s*['\"`]three\\/webgpu['\"`]/.test(code)) {\n const message = `[mini-three] ${normalized} imports 'three/webgpu'; WebGPU is not available in WeChat mini games.`;\n report.webgpuWarnings.push(message);\n if (webgpuMode === 'error') this.error(message);\n if (webgpuMode === 'warn') this.warn(`${message} Use three's WebGLRenderer instead.`);\n if (webgpuMode === 'rewrite') {\n currentCode = currentCode\n .replace(/(['\"`])three\\/webgpu\\1/g, '$1three$1')\n .replace(/\\bWebGPURenderer\\b/g, 'WebGLRenderer');\n note(this, `rewrote three/webgpu -> three in ${normalized}`);\n }\n }\n\n const result = rewriteGlobals(currentCode, normalized, {\n ...options.rewrite,\n ...(options.rewrite?.forceUndef ? {} : { forceUndef: [...DEFAULT_FORCE_UNDEF] }),\n });\n if (result && 'error' in result) {\n report.parseFailures.push(result.error);\n this.warn(`[mini-three] ${result.error}`);\n return null;\n }\n if (!result) return webgpuMode === 'rewrite' ? { code: currentCode, map: null } : null;\n\n report.modulesRewritten++;\n report.rewrites += result.count;\n for (const name of result.seen) seenGlobals.add(name);\n note(this, `${normalized}: ${result.count} global(s) rewritten (${result.seen.join(', ')})`);\n return { code: result.code, map: result.map };\n },\n\n async generateBundle(this: PluginContext, bundleOptions) {\n const refs = Array.from(assetRefs);\n report.assetReferences = refs;\n report.globalsSeen = Array.from(seenGlobals).sort();\n\n if (refs.length > 0) {\n const collected = await collectAssets(refs, {\n cwd: options.cwd,\n roots: options.roots,\n outputDir: options.outputDir,\n brotli: options.brotli,\n manifest: options.manifest,\n });\n manifest = collected.manifest;\n filesToEmit = collected.files;\n report.missingAssets = collected.missing;\n for (const missing of collected.missing) {\n this.warn(`[mini-three] asset not found in known roots: ${missing}`);\n }\n for (const [destination, source] of filesToEmit) {\n try {\n const content = await fs.readFile(source);\n this.emitFile({ type: 'asset', fileName: destination, source: content });\n } catch (error) {\n this.warn(`[mini-three] could not emit ${destination}: ${String(error)}`);\n }\n }\n } else {\n manifest = {\n generatedBy: 'mini-three-adapter',\n outputDir: options.outputDir ?? 'assets/three',\n entries: [],\n gameJsonSuggestion: {},\n decoderPaths: {},\n };\n }\n\n if (options.manifest !== false) {\n this.emitFile({\n type: 'asset',\n fileName: 'mini-three-assets.json',\n source: JSON.stringify({ ...manifest, build: report, output: bundleOptions.dir ?? bundleOptions.file ?? '' }, null, 2),\n });\n }\n if (options.report !== false) {\n this.warn(\n `[mini-three] build report: ${report.modulesScanned} module(s) scanned, ` +\n `${report.modulesRewritten} rewritten, ${report.rewrites} reference(s) -> scope, ` +\n `${filesToEmit.size} asset(s) emitted, ${report.missingAssets.length} missing.`,\n );\n }\n },\n\n api: {\n report: () => ({\n ...report,\n globalsSeen: Array.from(seenGlobals).sort(),\n assetReferences: Array.from(assetRefs),\n webgpuWarnings: [...report.webgpuWarnings],\n parseFailures: [...report.parseFailures],\n }),\n },\n };\n}\n","/**\n * AST-based global-to-scope rewriting.\n *\n * The reference adapter uses a Rollup \"prefix global\" pass that effectively\n * text-replaces identifiers. That breaks on shadowed locals, object keys, and\n * `typeof window` feature detection. Here we parse with @babel/parser and use\n * Babel's scope binding information, so ONLY free (unbound) references to\n * browser globals are rewritten — application code is never touched.\n */\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\nimport MagicString from 'magic-string';\nimport type { NodePath } from '@babel/traverse';\nimport type { Identifier } from '@babel/types';\nimport type { Node } from '@babel/types';\n\n// Babel's CJS/ESM interop differs between bundlers; normalize once.\nconst traverse = (typeof _traverse === 'function'\n ? _traverse\n : (_traverse as unknown as { default: typeof _traverse }).default) as typeof _traverse;\n\nexport const DEFAULT_GLOBAL_NAMES: readonly string[] = [\n 'window', 'self', 'document', 'navigator', 'screen', 'location',\n 'innerWidth', 'innerHeight', 'outerWidth', 'outerHeight',\n 'devicePixelRatio', 'pageXOffset', 'pageYOffset',\n 'performance', 'requestAnimationFrame', 'cancelAnimationFrame',\n 'getComputedStyle', 'matchMedia', 'atob', 'btoa',\n 'Event', 'EventTarget', 'CustomEvent', 'PointerEvent', 'MouseEvent',\n 'TouchEvent', 'MessageEvent', 'ProgressEvent', 'KeyboardEvent', 'DOMException',\n 'HTMLElement', 'HTMLCanvasElement', 'HTMLImageElement', 'HTMLVideoElement',\n 'OffscreenCanvas', 'Image', 'ImageData', 'DOMRect',\n 'WebGLRenderingContext', 'WebGL2RenderingContext', 'AudioContext',\n 'Blob', 'URL', 'URLSearchParams', 'FileReader', 'TextDecoder', 'TextEncoder',\n 'AbortController', 'AbortSignal', 'fetch', 'XMLHttpRequest', 'WebSocket',\n 'createImageBitmap', 'Worker', 'WebAssembly', 'ResizeObserver',\n];\n\n/** Globals that must remain `undefined` in the mini game scope. */\nexport const DEFAULT_FORCE_UNDEF: readonly string[] = ['createImageBitmap'];\n\nexport interface RewriteOptions {\n /** Extra global identifiers to rewrite. */\n extraGlobals?: string[];\n /** Replace the default global list instead of extending it. */\n globals?: string[];\n /** Identifiers that must evaluate to `undefined` (feature-detection off). */\n forceUndef?: string[];\n /** Name of the injected scope accessor. Default `__m3`. */\n accessor?: string;\n /** Module specifier that exports `getActiveScope`. */\n scopeModule?: string;\n}\n\nexport interface RewriteResult {\n code: string;\n map: { toString(): string } | null;\n /** Number of rewritten references. */\n count: number;\n /** Globals actually seen (useful for the build report). */\n seen: string[];\n}\n\nexport interface RewriteFailure {\n code: string;\n error: string;\n}\n\nexport const SCOPE_IMPORT = (accessor: string, module: string): string =>\n `import { getActiveScope as ${accessor} } from '${module}';\\n`;\n\nfunction isNonComputedKey(path: NodePath): boolean {\n const parent = path.parentPath;\n if (!parent) return false;\n const self: unknown = path.node;\n if (parent.isObjectProperty() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isObjectMethod() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isClassProperty() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isClassMethod() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isMemberExpression() && !parent.node.computed && (parent.node.property as unknown) === self) return true;\n return false;\n}\n\n/** Rewrite free browser-global references in one module. Returns null if nothing changed. */\nexport function rewriteGlobals(\n code: string,\n id: string,\n options: RewriteOptions = {},\n): RewriteResult | RewriteFailure | null {\n const names = new Set<string>([\n ...(options.globals ?? DEFAULT_GLOBAL_NAMES),\n ...(options.extraGlobals ?? []),\n ...(options.forceUndef ?? DEFAULT_FORCE_UNDEF),\n ]);\n const accessor = options.accessor ?? '__m3';\n const scopeModule = options.scopeModule ?? 'mini-three-adapter/scope';\n\n let ast;\n try {\n ast = parse(code, {\n sourceType: 'unambiguous',\n errorRecovery: true,\n plugins: ['importAttributes', 'classProperties', 'topLevelAwait', 'typescript', 'jsx'],\n });\n } catch (error) {\n return { code, error: `[mini-three] parse failed for ${id}: ${String(error)}` };\n }\n\n const ms = new MagicString(code);\n const seen = new Set<string>();\n let count = 0;\n\n traverse(ast, {\n ReferencedIdentifier(path: NodePath<Node>) {\n const node = path.node as Identifier;\n const name = node.name;\n if (!name || !names.has(name)) return;\n if (node.start == null || node.end == null) return;\n if (isNonComputedKey(path)) return;\n // Babel scope knows about imports, function params, local declarations,\n // catch bindings and block-scoped shadowing. This is the critical check\n // that a regex-based replacement cannot perform.\n if (path.scope.hasBinding(name, true)) return;\n // `typeof window` stays correct: `typeof __m3().window` === 'object'.\n seen.add(name);\n ms.overwrite(node.start, node.end, `${accessor}().${name}`);\n count++;\n },\n });\n\n if (count === 0) return null;\n ms.prepend(SCOPE_IMPORT(accessor, scopeModule));\n return {\n code: ms.toString(),\n map: ms.generateMap({ source: id, includeContent: true, hires: true }) as unknown as { toString(): string },\n count,\n seen: Array.from(seen).sort(),\n };\n}\n","/**\n * Worker / WASM asset collection for three.js addons.\n *\n * DRACOLoader, KTX2Loader, 3DMLoader, LottieLoader, ... reference decoder\n * `.js` and `.wasm` files by string path. In a mini game those files are not\n * reachable via HTTP; they must be copied into the code package (ideally a\n * subpackage) and `setDecoderPath` must point at the copied location.\n *\n * The plugin scans transformed modules, resolves each referenced basename in a\n * small set of known directories, copies it, and emits a manifest plus a\n * `game.json` suggestion. No global state, no hidden writes.\n */\nimport { promises as fs } from 'node:fs';\nimport path from 'node:path';\n\nexport interface AssetOptions {\n /** Extra directories to search (besides three's jsm/libs). */\n roots?: string[];\n /** Output directory relative to the bundle root. Default 'assets/three'. */\n outputDir?: string;\n /** Copy `.wasm.br` alongside `.wasm` when available. Default true. */\n brotli?: boolean;\n /** Emit `mini-three-assets.json`. Default true. */\n manifest?: boolean;\n /** Working directory used to resolve roots. Default process.cwd(). */\n cwd?: string;\n}\n\nexport interface AssetEntry {\n /** Original string found in the module. */\n reference: string;\n /** Resolved absolute source path. */\n source: string;\n /** Relative destination inside the bundle. */\n destination: string;\n kind: 'worker' | 'wasm' | 'data';\n}\n\nexport interface AssetManifest {\n generatedBy: 'mini-three-adapter';\n outputDir: string;\n entries: AssetEntry[];\n /** Paste into game.json (adjust subpackage names to your project). */\n gameJsonSuggestion: Record<string, unknown>;\n /** Decoder paths to feed to loaders at runtime. */\n decoderPaths: Record<string, string>;\n}\n\nconst ASSET_PATTERN = /(['\"`])([^'\"`\\n]*\\.(?:wasm|wasm\\.br|bin|js))\\1/g;\nconst DECODER_KEYWORDS = [\n 'draco', 'basis', 'ktx2', 'rhino3dm', 'zstd', 'meshopt', 'ammo',\n 'worker', 'decoder', 'transcoder', 'lottie', 'sdf',\n];\n\nexport function collectAssetReferences(code: string): string[] {\n const found = new Set<string>();\n let match: RegExpExecArray | null;\n ASSET_PATTERN.lastIndex = 0;\n while ((match = ASSET_PATTERN.exec(code)) !== null) {\n const value = match[2] ?? '';\n const lower = value.toLowerCase();\n if (DECODER_KEYWORDS.some((keyword) => lower.includes(keyword))) found.add(value);\n }\n return Array.from(found);\n}\n\nasync function indexFiles(root: string, maxDepth = 5): Promise<Map<string, string>> {\n const index = new Map<string, string>();\n const walk = async (dir: string, depth: number): Promise<void> => {\n if (depth > maxDepth) return;\n let entries;\n try { entries = await fs.readdir(dir, { withFileTypes: true }); }\n catch { return; }\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) await walk(full, depth + 1);\n else if (entry.isFile() && !index.has(entry.name)) index.set(entry.name, full);\n }\n };\n await walk(root, 0);\n return index;\n}\n\nfunction classify(name: string): AssetEntry['kind'] {\n if (name.endsWith('.wasm') || name.endsWith('.wasm.br')) return 'wasm';\n if (name.endsWith('.js')) return 'worker';\n return 'data';\n}\n\nexport function defaultRoots(cwd: string): string[] {\n return [\n path.join(cwd, 'node_modules/three/examples/jsm/libs'),\n path.join(cwd, 'node_modules/three/examples/jsm'),\n path.join(cwd, 'node_modules/three-stdlib'),\n path.join(cwd, 'public'),\n path.join(cwd, 'static'),\n ];\n}\n\nexport interface CollectResult {\n manifest: AssetManifest;\n /** Files to write: destination (relative) -> absolute source. */\n files: Map<string, string>;\n missing: string[];\n}\n\n/** Resolve references against known roots without copying anything. */\nexport async function collectAssets(references: string[], options: AssetOptions = {}): Promise<CollectResult> {\n const cwd = options.cwd ?? process.cwd();\n const outputDir = (options.outputDir ?? 'assets/three').replace(/\\\\/g, '/').replace(/\\/$/, '');\n const roots = [...defaultRoots(cwd), ...(options.roots ?? [])];\n const indexes = await Promise.all(roots.map((root) => indexFiles(root)));\n const find = (name: string): string | undefined => {\n for (const index of indexes) {\n const hit = index.get(name);\n if (hit) return hit;\n }\n return undefined;\n };\n\n const entries: AssetEntry[] = [];\n const files = new Map<string, string>();\n const missing: string[] = [];\n\n for (const reference of references) {\n const base = path.posix.basename(reference.split('?')[0] ?? reference);\n const source = find(base);\n if (!source) { missing.push(reference); continue; }\n const entry: AssetEntry = {\n reference,\n source,\n destination: `${outputDir}/${base}`,\n kind: classify(base),\n };\n entries.push(entry);\n files.set(entry.destination, source);\n if (options.brotli !== false && entry.kind === 'wasm') {\n const br = find(`${base}.br`);\n if (br) {\n entries.push({ reference: `${reference}.br`, source: br, destination: `${outputDir}/${base}.br`, kind: 'wasm' });\n files.set(`${outputDir}/${base}.br`, br);\n }\n }\n }\n\n const decoderPaths: Record<string, string> = {};\n for (const entry of entries) {\n const name = path.posix.basename(entry.destination).toLowerCase();\n for (const key of ['draco', 'ktx2', 'basis', 'meshopt', 'rhino3dm', 'zstd', 'ammo']) {\n if (name.includes(key)) decoderPaths[key] = `${outputDir}/`;\n }\n }\n\n const manifest: AssetManifest = {\n generatedBy: 'mini-three-adapter',\n outputDir,\n entries,\n gameJsonSuggestion: {\n workers: { path: `${outputDir}`, isSubpackage: true },\n subpackages: [{ name: 'three-assets', root: `${outputDir}/` }],\n },\n decoderPaths,\n };\n return { manifest, files, missing };\n}\n\n/** Copy resolved files into `outDir`. */\nexport async function copyAssets(files: Map<string, string>, outDir: string): Promise<number> {\n let written = 0;\n for (const [destination, source] of files) {\n const target = path.join(outDir, destination);\n await fs.mkdir(path.dirname(target), { recursive: true });\n await fs.copyFile(source, target);\n written++;\n }\n return written;\n}\n","/** Rollup entry: `import { miniThree } from 'mini-three-adapter/rollup'`. */\nimport { miniThreePlugin, type MiniThreePlugin, type MiniThreePluginOptions } from './plugin-core';\n\nexport function miniThree(options: MiniThreePluginOptions = {}): MiniThreePlugin {\n return miniThreePlugin(options);\n}\n\nexport default miniThree;\nexport { miniThreePlugin } from './plugin-core';\nexport type { MiniThreePluginOptions, BuildReport } from './plugin-core';\nexport { DEFAULT_GLOBAL_NAMES, DEFAULT_FORCE_UNDEF, rewriteGlobals } from './scope-rewrite';\nexport type { RewriteOptions, RewriteResult } from './scope-rewrite';\nexport { collectAssetReferences, collectAssets, copyAssets } from './assets';\nexport type { AssetOptions, AssetManifest, AssetEntry } from './assets';\n"],"mappings":";AASA,SAAS,YAAYA,WAAU;;;ACA/B,SAAS,aAAa;AACtB,OAAO,eAAe;AACtB,OAAO,iBAAiB;AAMxB,IAAM,WAAY,OAAO,cAAc,aACnC,YACC,UAAuD;AAErD,IAAM,uBAA0C;AAAA,EACrD;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAY;AAAA,EAAa;AAAA,EAAU;AAAA,EACrD;AAAA,EAAc;AAAA,EAAe;AAAA,EAAc;AAAA,EAC3C;AAAA,EAAoB;AAAA,EAAe;AAAA,EACnC;AAAA,EAAe;AAAA,EAAyB;AAAA,EACxC;AAAA,EAAoB;AAAA,EAAc;AAAA,EAAQ;AAAA,EAC1C;AAAA,EAAS;AAAA,EAAe;AAAA,EAAe;AAAA,EAAgB;AAAA,EACvD;AAAA,EAAc;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAiB;AAAA,EAChE;AAAA,EAAe;AAAA,EAAqB;AAAA,EAAoB;AAAA,EACxD;AAAA,EAAmB;AAAA,EAAS;AAAA,EAAa;AAAA,EACzC;AAAA,EAAyB;AAAA,EAA0B;AAAA,EACnD;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAmB;AAAA,EAAc;AAAA,EAAe;AAAA,EAC/D;AAAA,EAAmB;AAAA,EAAe;AAAA,EAAS;AAAA,EAAkB;AAAA,EAC7D;AAAA,EA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BuildReport, m as miniThreePlugin } from '../plugin-core-BuqW9C-L.js';
|
|
3
|
+
|
|
4
|
+
/** Vite entry: `import miniThree from 'mini-three-adapter/vite'`. */
|
|
5
|
+
|
|
6
|
+
interface ViteMiniThreePlugin extends MiniThreePlugin {
|
|
7
|
+
config(): Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin. `optimizeDeps.exclude` keeps three's ESM sources intact so the
|
|
11
|
+
* AST rewrite sees the original module graph instead of a pre-bundled blob.
|
|
12
|
+
*/
|
|
13
|
+
declare function miniThree(options?: MiniThreePluginOptions): ViteMiniThreePlugin;
|
|
14
|
+
|
|
15
|
+
export { MiniThreePluginOptions, type ViteMiniThreePlugin, miniThree as default, miniThree };
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
// src/build/plugin-core.ts
|
|
2
|
+
import { promises as fs2 } from "fs";
|
|
3
|
+
|
|
4
|
+
// src/build/scope-rewrite.ts
|
|
5
|
+
import { parse } from "@babel/parser";
|
|
6
|
+
import _traverse from "@babel/traverse";
|
|
7
|
+
import MagicString from "magic-string";
|
|
8
|
+
var traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
|
|
9
|
+
var DEFAULT_GLOBAL_NAMES = [
|
|
10
|
+
"window",
|
|
11
|
+
"self",
|
|
12
|
+
"document",
|
|
13
|
+
"navigator",
|
|
14
|
+
"screen",
|
|
15
|
+
"location",
|
|
16
|
+
"innerWidth",
|
|
17
|
+
"innerHeight",
|
|
18
|
+
"outerWidth",
|
|
19
|
+
"outerHeight",
|
|
20
|
+
"devicePixelRatio",
|
|
21
|
+
"pageXOffset",
|
|
22
|
+
"pageYOffset",
|
|
23
|
+
"performance",
|
|
24
|
+
"requestAnimationFrame",
|
|
25
|
+
"cancelAnimationFrame",
|
|
26
|
+
"getComputedStyle",
|
|
27
|
+
"matchMedia",
|
|
28
|
+
"atob",
|
|
29
|
+
"btoa",
|
|
30
|
+
"Event",
|
|
31
|
+
"EventTarget",
|
|
32
|
+
"CustomEvent",
|
|
33
|
+
"PointerEvent",
|
|
34
|
+
"MouseEvent",
|
|
35
|
+
"TouchEvent",
|
|
36
|
+
"MessageEvent",
|
|
37
|
+
"ProgressEvent",
|
|
38
|
+
"KeyboardEvent",
|
|
39
|
+
"DOMException",
|
|
40
|
+
"HTMLElement",
|
|
41
|
+
"HTMLCanvasElement",
|
|
42
|
+
"HTMLImageElement",
|
|
43
|
+
"HTMLVideoElement",
|
|
44
|
+
"OffscreenCanvas",
|
|
45
|
+
"Image",
|
|
46
|
+
"ImageData",
|
|
47
|
+
"DOMRect",
|
|
48
|
+
"WebGLRenderingContext",
|
|
49
|
+
"WebGL2RenderingContext",
|
|
50
|
+
"AudioContext",
|
|
51
|
+
"Blob",
|
|
52
|
+
"URL",
|
|
53
|
+
"URLSearchParams",
|
|
54
|
+
"FileReader",
|
|
55
|
+
"TextDecoder",
|
|
56
|
+
"TextEncoder",
|
|
57
|
+
"AbortController",
|
|
58
|
+
"AbortSignal",
|
|
59
|
+
"fetch",
|
|
60
|
+
"XMLHttpRequest",
|
|
61
|
+
"WebSocket",
|
|
62
|
+
"createImageBitmap",
|
|
63
|
+
"Worker",
|
|
64
|
+
"WebAssembly",
|
|
65
|
+
"ResizeObserver"
|
|
66
|
+
];
|
|
67
|
+
var DEFAULT_FORCE_UNDEF = ["createImageBitmap"];
|
|
68
|
+
var SCOPE_IMPORT = (accessor, module) => `import { getActiveScope as ${accessor} } from '${module}';
|
|
69
|
+
`;
|
|
70
|
+
function isNonComputedKey(path2) {
|
|
71
|
+
const parent = path2.parentPath;
|
|
72
|
+
if (!parent) return false;
|
|
73
|
+
const self = path2.node;
|
|
74
|
+
if (parent.isObjectProperty() && !parent.node.computed && parent.node.key === self) return true;
|
|
75
|
+
if (parent.isObjectMethod() && !parent.node.computed && parent.node.key === self) return true;
|
|
76
|
+
if (parent.isClassProperty() && !parent.node.computed && parent.node.key === self) return true;
|
|
77
|
+
if (parent.isClassMethod() && !parent.node.computed && parent.node.key === self) return true;
|
|
78
|
+
if (parent.isMemberExpression() && !parent.node.computed && parent.node.property === self) return true;
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
function rewriteGlobals(code, id, options = {}) {
|
|
82
|
+
const names = /* @__PURE__ */ new Set([
|
|
83
|
+
...options.globals ?? DEFAULT_GLOBAL_NAMES,
|
|
84
|
+
...options.extraGlobals ?? [],
|
|
85
|
+
...options.forceUndef ?? DEFAULT_FORCE_UNDEF
|
|
86
|
+
]);
|
|
87
|
+
const accessor = options.accessor ?? "__m3";
|
|
88
|
+
const scopeModule = options.scopeModule ?? "mini-three-adapter/scope";
|
|
89
|
+
let ast;
|
|
90
|
+
try {
|
|
91
|
+
ast = parse(code, {
|
|
92
|
+
sourceType: "unambiguous",
|
|
93
|
+
errorRecovery: true,
|
|
94
|
+
plugins: ["importAttributes", "classProperties", "topLevelAwait", "typescript", "jsx"]
|
|
95
|
+
});
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return { code, error: `[mini-three] parse failed for ${id}: ${String(error)}` };
|
|
98
|
+
}
|
|
99
|
+
const ms = new MagicString(code);
|
|
100
|
+
const seen = /* @__PURE__ */ new Set();
|
|
101
|
+
let count = 0;
|
|
102
|
+
traverse(ast, {
|
|
103
|
+
ReferencedIdentifier(path2) {
|
|
104
|
+
const node = path2.node;
|
|
105
|
+
const name = node.name;
|
|
106
|
+
if (!name || !names.has(name)) return;
|
|
107
|
+
if (node.start == null || node.end == null) return;
|
|
108
|
+
if (isNonComputedKey(path2)) return;
|
|
109
|
+
if (path2.scope.hasBinding(name, true)) return;
|
|
110
|
+
seen.add(name);
|
|
111
|
+
ms.overwrite(node.start, node.end, `${accessor}().${name}`);
|
|
112
|
+
count++;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (count === 0) return null;
|
|
116
|
+
ms.prepend(SCOPE_IMPORT(accessor, scopeModule));
|
|
117
|
+
return {
|
|
118
|
+
code: ms.toString(),
|
|
119
|
+
map: ms.generateMap({ source: id, includeContent: true, hires: true }),
|
|
120
|
+
count,
|
|
121
|
+
seen: Array.from(seen).sort()
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/build/assets.ts
|
|
126
|
+
import { promises as fs } from "fs";
|
|
127
|
+
import path from "path";
|
|
128
|
+
var ASSET_PATTERN = /(['"`])([^'"`\n]*\.(?:wasm|wasm\.br|bin|js))\1/g;
|
|
129
|
+
var DECODER_KEYWORDS = [
|
|
130
|
+
"draco",
|
|
131
|
+
"basis",
|
|
132
|
+
"ktx2",
|
|
133
|
+
"rhino3dm",
|
|
134
|
+
"zstd",
|
|
135
|
+
"meshopt",
|
|
136
|
+
"ammo",
|
|
137
|
+
"worker",
|
|
138
|
+
"decoder",
|
|
139
|
+
"transcoder",
|
|
140
|
+
"lottie",
|
|
141
|
+
"sdf"
|
|
142
|
+
];
|
|
143
|
+
function collectAssetReferences(code) {
|
|
144
|
+
const found = /* @__PURE__ */ new Set();
|
|
145
|
+
let match;
|
|
146
|
+
ASSET_PATTERN.lastIndex = 0;
|
|
147
|
+
while ((match = ASSET_PATTERN.exec(code)) !== null) {
|
|
148
|
+
const value = match[2] ?? "";
|
|
149
|
+
const lower = value.toLowerCase();
|
|
150
|
+
if (DECODER_KEYWORDS.some((keyword) => lower.includes(keyword))) found.add(value);
|
|
151
|
+
}
|
|
152
|
+
return Array.from(found);
|
|
153
|
+
}
|
|
154
|
+
async function indexFiles(root, maxDepth = 5) {
|
|
155
|
+
const index = /* @__PURE__ */ new Map();
|
|
156
|
+
const walk = async (dir, depth) => {
|
|
157
|
+
if (depth > maxDepth) return;
|
|
158
|
+
let entries;
|
|
159
|
+
try {
|
|
160
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
161
|
+
} catch {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
for (const entry of entries) {
|
|
165
|
+
const full = path.join(dir, entry.name);
|
|
166
|
+
if (entry.isDirectory()) await walk(full, depth + 1);
|
|
167
|
+
else if (entry.isFile() && !index.has(entry.name)) index.set(entry.name, full);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
await walk(root, 0);
|
|
171
|
+
return index;
|
|
172
|
+
}
|
|
173
|
+
function classify(name) {
|
|
174
|
+
if (name.endsWith(".wasm") || name.endsWith(".wasm.br")) return "wasm";
|
|
175
|
+
if (name.endsWith(".js")) return "worker";
|
|
176
|
+
return "data";
|
|
177
|
+
}
|
|
178
|
+
function defaultRoots(cwd) {
|
|
179
|
+
return [
|
|
180
|
+
path.join(cwd, "node_modules/three/examples/jsm/libs"),
|
|
181
|
+
path.join(cwd, "node_modules/three/examples/jsm"),
|
|
182
|
+
path.join(cwd, "node_modules/three-stdlib"),
|
|
183
|
+
path.join(cwd, "public"),
|
|
184
|
+
path.join(cwd, "static")
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
async function collectAssets(references, options = {}) {
|
|
188
|
+
const cwd = options.cwd ?? process.cwd();
|
|
189
|
+
const outputDir = (options.outputDir ?? "assets/three").replace(/\\/g, "/").replace(/\/$/, "");
|
|
190
|
+
const roots = [...defaultRoots(cwd), ...options.roots ?? []];
|
|
191
|
+
const indexes = await Promise.all(roots.map((root) => indexFiles(root)));
|
|
192
|
+
const find = (name) => {
|
|
193
|
+
for (const index of indexes) {
|
|
194
|
+
const hit = index.get(name);
|
|
195
|
+
if (hit) return hit;
|
|
196
|
+
}
|
|
197
|
+
return void 0;
|
|
198
|
+
};
|
|
199
|
+
const entries = [];
|
|
200
|
+
const files = /* @__PURE__ */ new Map();
|
|
201
|
+
const missing = [];
|
|
202
|
+
for (const reference of references) {
|
|
203
|
+
const base = path.posix.basename(reference.split("?")[0] ?? reference);
|
|
204
|
+
const source = find(base);
|
|
205
|
+
if (!source) {
|
|
206
|
+
missing.push(reference);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const entry = {
|
|
210
|
+
reference,
|
|
211
|
+
source,
|
|
212
|
+
destination: `${outputDir}/${base}`,
|
|
213
|
+
kind: classify(base)
|
|
214
|
+
};
|
|
215
|
+
entries.push(entry);
|
|
216
|
+
files.set(entry.destination, source);
|
|
217
|
+
if (options.brotli !== false && entry.kind === "wasm") {
|
|
218
|
+
const br = find(`${base}.br`);
|
|
219
|
+
if (br) {
|
|
220
|
+
entries.push({ reference: `${reference}.br`, source: br, destination: `${outputDir}/${base}.br`, kind: "wasm" });
|
|
221
|
+
files.set(`${outputDir}/${base}.br`, br);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const decoderPaths = {};
|
|
226
|
+
for (const entry of entries) {
|
|
227
|
+
const name = path.posix.basename(entry.destination).toLowerCase();
|
|
228
|
+
for (const key of ["draco", "ktx2", "basis", "meshopt", "rhino3dm", "zstd", "ammo"]) {
|
|
229
|
+
if (name.includes(key)) decoderPaths[key] = `${outputDir}/`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const manifest = {
|
|
233
|
+
generatedBy: "mini-three-adapter",
|
|
234
|
+
outputDir,
|
|
235
|
+
entries,
|
|
236
|
+
gameJsonSuggestion: {
|
|
237
|
+
workers: { path: `${outputDir}`, isSubpackage: true },
|
|
238
|
+
subpackages: [{ name: "three-assets", root: `${outputDir}/` }]
|
|
239
|
+
},
|
|
240
|
+
decoderPaths
|
|
241
|
+
};
|
|
242
|
+
return { manifest, files, missing };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/build/plugin-core.ts
|
|
246
|
+
var DEFAULT_INCLUDE = (id) => {
|
|
247
|
+
const normalized = id.replace(/\\/g, "/").split("?")[0] ?? id;
|
|
248
|
+
return normalized.includes("/node_modules/three/") || normalized.includes("/node_modules/three-stdlib/") || normalized.includes("/node_modules/@react-three/") || normalized.includes("/node_modules/@tresjs/") || normalized.includes("/node_modules/.vite/deps/three") || normalized.includes("/node_modules/.vite/deps/three-stdlib") || /\/node_modules\/three@[^/]+\//.test(normalized);
|
|
249
|
+
};
|
|
250
|
+
function miniThreePlugin(options = {}) {
|
|
251
|
+
const include = options.include ?? DEFAULT_INCLUDE;
|
|
252
|
+
const exclude = options.exclude ?? (() => false);
|
|
253
|
+
const webgpuMode = options.webgpu ?? "warn";
|
|
254
|
+
const report = {
|
|
255
|
+
modulesScanned: 0,
|
|
256
|
+
modulesRewritten: 0,
|
|
257
|
+
rewrites: 0,
|
|
258
|
+
globalsSeen: [],
|
|
259
|
+
assetReferences: [],
|
|
260
|
+
missingAssets: [],
|
|
261
|
+
webgpuWarnings: [],
|
|
262
|
+
parseFailures: []
|
|
263
|
+
};
|
|
264
|
+
const seenGlobals = /* @__PURE__ */ new Set();
|
|
265
|
+
const assetRefs = /* @__PURE__ */ new Set();
|
|
266
|
+
let manifest = null;
|
|
267
|
+
let filesToEmit = /* @__PURE__ */ new Map();
|
|
268
|
+
const note = (ctx, message) => {
|
|
269
|
+
if (options.debug) ctx.warn(`[mini-three] ${message}`);
|
|
270
|
+
};
|
|
271
|
+
return {
|
|
272
|
+
name: "mini-three-adapter",
|
|
273
|
+
enforce: "pre",
|
|
274
|
+
transform(code, id) {
|
|
275
|
+
const normalized = id.replace(/\\/g, "/");
|
|
276
|
+
const shouldTransform = options.includeUserCode ? !normalized.includes("/node_modules/mini-three-adapter/") && !exclude(normalized) : include(normalized) && !exclude(normalized);
|
|
277
|
+
if (!shouldTransform) return null;
|
|
278
|
+
report.modulesScanned++;
|
|
279
|
+
for (const ref of collectAssetReferences(code)) assetRefs.add(ref);
|
|
280
|
+
let currentCode = code;
|
|
281
|
+
if (webgpuMode !== "ignore" && /from\s*['"`]three\/webgpu['"`]/.test(code)) {
|
|
282
|
+
const message = `[mini-three] ${normalized} imports 'three/webgpu'; WebGPU is not available in WeChat mini games.`;
|
|
283
|
+
report.webgpuWarnings.push(message);
|
|
284
|
+
if (webgpuMode === "error") this.error(message);
|
|
285
|
+
if (webgpuMode === "warn") this.warn(`${message} Use three's WebGLRenderer instead.`);
|
|
286
|
+
if (webgpuMode === "rewrite") {
|
|
287
|
+
currentCode = currentCode.replace(/(['"`])three\/webgpu\1/g, "$1three$1").replace(/\bWebGPURenderer\b/g, "WebGLRenderer");
|
|
288
|
+
note(this, `rewrote three/webgpu -> three in ${normalized}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const result = rewriteGlobals(currentCode, normalized, {
|
|
292
|
+
...options.rewrite,
|
|
293
|
+
...options.rewrite?.forceUndef ? {} : { forceUndef: [...DEFAULT_FORCE_UNDEF] }
|
|
294
|
+
});
|
|
295
|
+
if (result && "error" in result) {
|
|
296
|
+
report.parseFailures.push(result.error);
|
|
297
|
+
this.warn(`[mini-three] ${result.error}`);
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
if (!result) return webgpuMode === "rewrite" ? { code: currentCode, map: null } : null;
|
|
301
|
+
report.modulesRewritten++;
|
|
302
|
+
report.rewrites += result.count;
|
|
303
|
+
for (const name of result.seen) seenGlobals.add(name);
|
|
304
|
+
note(this, `${normalized}: ${result.count} global(s) rewritten (${result.seen.join(", ")})`);
|
|
305
|
+
return { code: result.code, map: result.map };
|
|
306
|
+
},
|
|
307
|
+
async generateBundle(bundleOptions) {
|
|
308
|
+
const refs = Array.from(assetRefs);
|
|
309
|
+
report.assetReferences = refs;
|
|
310
|
+
report.globalsSeen = Array.from(seenGlobals).sort();
|
|
311
|
+
if (refs.length > 0) {
|
|
312
|
+
const collected = await collectAssets(refs, {
|
|
313
|
+
cwd: options.cwd,
|
|
314
|
+
roots: options.roots,
|
|
315
|
+
outputDir: options.outputDir,
|
|
316
|
+
brotli: options.brotli,
|
|
317
|
+
manifest: options.manifest
|
|
318
|
+
});
|
|
319
|
+
manifest = collected.manifest;
|
|
320
|
+
filesToEmit = collected.files;
|
|
321
|
+
report.missingAssets = collected.missing;
|
|
322
|
+
for (const missing of collected.missing) {
|
|
323
|
+
this.warn(`[mini-three] asset not found in known roots: ${missing}`);
|
|
324
|
+
}
|
|
325
|
+
for (const [destination, source] of filesToEmit) {
|
|
326
|
+
try {
|
|
327
|
+
const content = await fs2.readFile(source);
|
|
328
|
+
this.emitFile({ type: "asset", fileName: destination, source: content });
|
|
329
|
+
} catch (error) {
|
|
330
|
+
this.warn(`[mini-three] could not emit ${destination}: ${String(error)}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
manifest = {
|
|
335
|
+
generatedBy: "mini-three-adapter",
|
|
336
|
+
outputDir: options.outputDir ?? "assets/three",
|
|
337
|
+
entries: [],
|
|
338
|
+
gameJsonSuggestion: {},
|
|
339
|
+
decoderPaths: {}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
if (options.manifest !== false) {
|
|
343
|
+
this.emitFile({
|
|
344
|
+
type: "asset",
|
|
345
|
+
fileName: "mini-three-assets.json",
|
|
346
|
+
source: JSON.stringify({ ...manifest, build: report, output: bundleOptions.dir ?? bundleOptions.file ?? "" }, null, 2)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (options.report !== false) {
|
|
350
|
+
this.warn(
|
|
351
|
+
`[mini-three] build report: ${report.modulesScanned} module(s) scanned, ${report.modulesRewritten} rewritten, ${report.rewrites} reference(s) -> scope, ${filesToEmit.size} asset(s) emitted, ${report.missingAssets.length} missing.`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
api: {
|
|
356
|
+
report: () => ({
|
|
357
|
+
...report,
|
|
358
|
+
globalsSeen: Array.from(seenGlobals).sort(),
|
|
359
|
+
assetReferences: Array.from(assetRefs),
|
|
360
|
+
webgpuWarnings: [...report.webgpuWarnings],
|
|
361
|
+
parseFailures: [...report.parseFailures]
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/build/vite.ts
|
|
368
|
+
function miniThree(options = {}) {
|
|
369
|
+
const core = miniThreePlugin(options);
|
|
370
|
+
return {
|
|
371
|
+
...core,
|
|
372
|
+
config() {
|
|
373
|
+
return {
|
|
374
|
+
optimizeDeps: {
|
|
375
|
+
exclude: ["three", "three-stdlib", "three/examples/jsm"]
|
|
376
|
+
},
|
|
377
|
+
build: {
|
|
378
|
+
commonjsOptions: { transformMixedEsModules: true },
|
|
379
|
+
rollupOptions: {
|
|
380
|
+
output: {
|
|
381
|
+
manualChunks: void 0
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
var vite_default = miniThree;
|
|
390
|
+
export {
|
|
391
|
+
vite_default as default,
|
|
392
|
+
miniThree,
|
|
393
|
+
miniThreePlugin
|
|
394
|
+
};
|
|
395
|
+
//# sourceMappingURL=vite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/build/plugin-core.ts","../../src/build/scope-rewrite.ts","../../src/build/assets.ts","../../src/build/vite.ts"],"sourcesContent":["/**\n * Rollup/Vite-compatible plugin core (zero hard dependency on either bundler).\n *\n * Responsibilities:\n * 1. Rewrite free browser globals inside third-party modules to scoped access.\n * 2. Handle `three/webgpu` (WebGPU is unavailable in WeChat mini games).\n * 3. Collect worker/wasm assets referenced by addons and emit them + a manifest.\n * 4. Produce a machine-readable build report for CI and AI-assisted iteration.\n */\nimport { promises as fs } from 'node:fs';\nimport {\n DEFAULT_FORCE_UNDEF,\n rewriteGlobals,\n type RewriteOptions,\n} from './scope-rewrite';\nimport {\n collectAssetReferences,\n collectAssets,\n type AssetManifest,\n type AssetOptions,\n} from './assets';\n\nexport interface MiniThreePluginOptions extends AssetOptions {\n /** Extra modules to transform. Receives a normalized (slash-separated) id. */\n include?: (id: string) => boolean;\n /** Modules to skip even when they match. */\n exclude?: (id: string) => boolean;\n /** Also transform application code (off by default). */\n includeUserCode?: boolean;\n /** Rewrite options (advanced). */\n rewrite?: RewriteOptions;\n /** How to handle `three/webgpu` imports. Default 'warn'. */\n webgpu?: 'warn' | 'error' | 'rewrite' | 'ignore';\n /** Print a build report summary. Default true. */\n report?: boolean;\n /** Verbose per-module logs. */\n debug?: boolean;\n}\n\nexport interface BuildReport {\n modulesScanned: number;\n modulesRewritten: number;\n rewrites: number;\n globalsSeen: string[];\n assetReferences: string[];\n missingAssets: string[];\n webgpuWarnings: string[];\n parseFailures: string[];\n}\n\nexport interface PluginContext {\n warn(message: string): void;\n error(message: string): never;\n emitFile(file: { type: 'asset'; fileName: string; source: string | Uint8Array }): string;\n}\n\nexport interface MiniThreePlugin {\n name: string;\n enforce: 'pre';\n transform(this: PluginContext, code: string, id: string): { code: string; map: unknown } | null;\n generateBundle(this: PluginContext, options: { dir?: string; file?: string }): Promise<void>;\n api: {\n report(): BuildReport;\n };\n}\n\nconst DEFAULT_INCLUDE = (id: string): boolean => {\n const normalized = id.replace(/\\\\/g, '/').split('?')[0] ?? id;\n return (\n normalized.includes('/node_modules/three/') ||\n normalized.includes('/node_modules/three-stdlib/') ||\n normalized.includes('/node_modules/@react-three/') ||\n normalized.includes('/node_modules/@tresjs/') ||\n normalized.includes('/node_modules/.vite/deps/three') ||\n normalized.includes('/node_modules/.vite/deps/three-stdlib') ||\n /\\/node_modules\\/three@[^/]+\\//.test(normalized)\n );\n};\n\nexport function miniThreePlugin(options: MiniThreePluginOptions = {}): MiniThreePlugin {\n const include = options.include ?? DEFAULT_INCLUDE;\n const exclude = options.exclude ?? (() => false);\n const webgpuMode = options.webgpu ?? 'warn';\n const report: BuildReport = {\n modulesScanned: 0,\n modulesRewritten: 0,\n rewrites: 0,\n globalsSeen: [],\n assetReferences: [],\n missingAssets: [],\n webgpuWarnings: [],\n parseFailures: [],\n };\n const seenGlobals = new Set<string>();\n const assetRefs = new Set<string>();\n let manifest: AssetManifest | null = null;\n let filesToEmit = new Map<string, string>();\n\n const note = (ctx: PluginContext, message: string): void => {\n if (options.debug) ctx.warn(`[mini-three] ${message}`);\n };\n\n return {\n name: 'mini-three-adapter',\n enforce: 'pre',\n\n transform(this: PluginContext, code: string, id: string) {\n const normalized = id.replace(/\\\\/g, '/');\n const shouldTransform = options.includeUserCode\n ? !normalized.includes('/node_modules/mini-three-adapter/') && !exclude(normalized)\n : include(normalized) && !exclude(normalized);\n if (!shouldTransform) return null;\n\n report.modulesScanned++;\n for (const ref of collectAssetReferences(code)) assetRefs.add(ref);\n\n let currentCode = code;\n if (webgpuMode !== 'ignore' && /from\\s*['\"`]three\\/webgpu['\"`]/.test(code)) {\n const message = `[mini-three] ${normalized} imports 'three/webgpu'; WebGPU is not available in WeChat mini games.`;\n report.webgpuWarnings.push(message);\n if (webgpuMode === 'error') this.error(message);\n if (webgpuMode === 'warn') this.warn(`${message} Use three's WebGLRenderer instead.`);\n if (webgpuMode === 'rewrite') {\n currentCode = currentCode\n .replace(/(['\"`])three\\/webgpu\\1/g, '$1three$1')\n .replace(/\\bWebGPURenderer\\b/g, 'WebGLRenderer');\n note(this, `rewrote three/webgpu -> three in ${normalized}`);\n }\n }\n\n const result = rewriteGlobals(currentCode, normalized, {\n ...options.rewrite,\n ...(options.rewrite?.forceUndef ? {} : { forceUndef: [...DEFAULT_FORCE_UNDEF] }),\n });\n if (result && 'error' in result) {\n report.parseFailures.push(result.error);\n this.warn(`[mini-three] ${result.error}`);\n return null;\n }\n if (!result) return webgpuMode === 'rewrite' ? { code: currentCode, map: null } : null;\n\n report.modulesRewritten++;\n report.rewrites += result.count;\n for (const name of result.seen) seenGlobals.add(name);\n note(this, `${normalized}: ${result.count} global(s) rewritten (${result.seen.join(', ')})`);\n return { code: result.code, map: result.map };\n },\n\n async generateBundle(this: PluginContext, bundleOptions) {\n const refs = Array.from(assetRefs);\n report.assetReferences = refs;\n report.globalsSeen = Array.from(seenGlobals).sort();\n\n if (refs.length > 0) {\n const collected = await collectAssets(refs, {\n cwd: options.cwd,\n roots: options.roots,\n outputDir: options.outputDir,\n brotli: options.brotli,\n manifest: options.manifest,\n });\n manifest = collected.manifest;\n filesToEmit = collected.files;\n report.missingAssets = collected.missing;\n for (const missing of collected.missing) {\n this.warn(`[mini-three] asset not found in known roots: ${missing}`);\n }\n for (const [destination, source] of filesToEmit) {\n try {\n const content = await fs.readFile(source);\n this.emitFile({ type: 'asset', fileName: destination, source: content });\n } catch (error) {\n this.warn(`[mini-three] could not emit ${destination}: ${String(error)}`);\n }\n }\n } else {\n manifest = {\n generatedBy: 'mini-three-adapter',\n outputDir: options.outputDir ?? 'assets/three',\n entries: [],\n gameJsonSuggestion: {},\n decoderPaths: {},\n };\n }\n\n if (options.manifest !== false) {\n this.emitFile({\n type: 'asset',\n fileName: 'mini-three-assets.json',\n source: JSON.stringify({ ...manifest, build: report, output: bundleOptions.dir ?? bundleOptions.file ?? '' }, null, 2),\n });\n }\n if (options.report !== false) {\n this.warn(\n `[mini-three] build report: ${report.modulesScanned} module(s) scanned, ` +\n `${report.modulesRewritten} rewritten, ${report.rewrites} reference(s) -> scope, ` +\n `${filesToEmit.size} asset(s) emitted, ${report.missingAssets.length} missing.`,\n );\n }\n },\n\n api: {\n report: () => ({\n ...report,\n globalsSeen: Array.from(seenGlobals).sort(),\n assetReferences: Array.from(assetRefs),\n webgpuWarnings: [...report.webgpuWarnings],\n parseFailures: [...report.parseFailures],\n }),\n },\n };\n}\n","/**\n * AST-based global-to-scope rewriting.\n *\n * The reference adapter uses a Rollup \"prefix global\" pass that effectively\n * text-replaces identifiers. That breaks on shadowed locals, object keys, and\n * `typeof window` feature detection. Here we parse with @babel/parser and use\n * Babel's scope binding information, so ONLY free (unbound) references to\n * browser globals are rewritten — application code is never touched.\n */\nimport { parse } from '@babel/parser';\nimport _traverse from '@babel/traverse';\nimport MagicString from 'magic-string';\nimport type { NodePath } from '@babel/traverse';\nimport type { Identifier } from '@babel/types';\nimport type { Node } from '@babel/types';\n\n// Babel's CJS/ESM interop differs between bundlers; normalize once.\nconst traverse = (typeof _traverse === 'function'\n ? _traverse\n : (_traverse as unknown as { default: typeof _traverse }).default) as typeof _traverse;\n\nexport const DEFAULT_GLOBAL_NAMES: readonly string[] = [\n 'window', 'self', 'document', 'navigator', 'screen', 'location',\n 'innerWidth', 'innerHeight', 'outerWidth', 'outerHeight',\n 'devicePixelRatio', 'pageXOffset', 'pageYOffset',\n 'performance', 'requestAnimationFrame', 'cancelAnimationFrame',\n 'getComputedStyle', 'matchMedia', 'atob', 'btoa',\n 'Event', 'EventTarget', 'CustomEvent', 'PointerEvent', 'MouseEvent',\n 'TouchEvent', 'MessageEvent', 'ProgressEvent', 'KeyboardEvent', 'DOMException',\n 'HTMLElement', 'HTMLCanvasElement', 'HTMLImageElement', 'HTMLVideoElement',\n 'OffscreenCanvas', 'Image', 'ImageData', 'DOMRect',\n 'WebGLRenderingContext', 'WebGL2RenderingContext', 'AudioContext',\n 'Blob', 'URL', 'URLSearchParams', 'FileReader', 'TextDecoder', 'TextEncoder',\n 'AbortController', 'AbortSignal', 'fetch', 'XMLHttpRequest', 'WebSocket',\n 'createImageBitmap', 'Worker', 'WebAssembly', 'ResizeObserver',\n];\n\n/** Globals that must remain `undefined` in the mini game scope. */\nexport const DEFAULT_FORCE_UNDEF: readonly string[] = ['createImageBitmap'];\n\nexport interface RewriteOptions {\n /** Extra global identifiers to rewrite. */\n extraGlobals?: string[];\n /** Replace the default global list instead of extending it. */\n globals?: string[];\n /** Identifiers that must evaluate to `undefined` (feature-detection off). */\n forceUndef?: string[];\n /** Name of the injected scope accessor. Default `__m3`. */\n accessor?: string;\n /** Module specifier that exports `getActiveScope`. */\n scopeModule?: string;\n}\n\nexport interface RewriteResult {\n code: string;\n map: { toString(): string } | null;\n /** Number of rewritten references. */\n count: number;\n /** Globals actually seen (useful for the build report). */\n seen: string[];\n}\n\nexport interface RewriteFailure {\n code: string;\n error: string;\n}\n\nexport const SCOPE_IMPORT = (accessor: string, module: string): string =>\n `import { getActiveScope as ${accessor} } from '${module}';\\n`;\n\nfunction isNonComputedKey(path: NodePath): boolean {\n const parent = path.parentPath;\n if (!parent) return false;\n const self: unknown = path.node;\n if (parent.isObjectProperty() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isObjectMethod() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isClassProperty() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isClassMethod() && !parent.node.computed && (parent.node.key as unknown) === self) return true;\n if (parent.isMemberExpression() && !parent.node.computed && (parent.node.property as unknown) === self) return true;\n return false;\n}\n\n/** Rewrite free browser-global references in one module. Returns null if nothing changed. */\nexport function rewriteGlobals(\n code: string,\n id: string,\n options: RewriteOptions = {},\n): RewriteResult | RewriteFailure | null {\n const names = new Set<string>([\n ...(options.globals ?? DEFAULT_GLOBAL_NAMES),\n ...(options.extraGlobals ?? []),\n ...(options.forceUndef ?? DEFAULT_FORCE_UNDEF),\n ]);\n const accessor = options.accessor ?? '__m3';\n const scopeModule = options.scopeModule ?? 'mini-three-adapter/scope';\n\n let ast;\n try {\n ast = parse(code, {\n sourceType: 'unambiguous',\n errorRecovery: true,\n plugins: ['importAttributes', 'classProperties', 'topLevelAwait', 'typescript', 'jsx'],\n });\n } catch (error) {\n return { code, error: `[mini-three] parse failed for ${id}: ${String(error)}` };\n }\n\n const ms = new MagicString(code);\n const seen = new Set<string>();\n let count = 0;\n\n traverse(ast, {\n ReferencedIdentifier(path: NodePath<Node>) {\n const node = path.node as Identifier;\n const name = node.name;\n if (!name || !names.has(name)) return;\n if (node.start == null || node.end == null) return;\n if (isNonComputedKey(path)) return;\n // Babel scope knows about imports, function params, local declarations,\n // catch bindings and block-scoped shadowing. This is the critical check\n // that a regex-based replacement cannot perform.\n if (path.scope.hasBinding(name, true)) return;\n // `typeof window` stays correct: `typeof __m3().window` === 'object'.\n seen.add(name);\n ms.overwrite(node.start, node.end, `${accessor}().${name}`);\n count++;\n },\n });\n\n if (count === 0) return null;\n ms.prepend(SCOPE_IMPORT(accessor, scopeModule));\n return {\n code: ms.toString(),\n map: ms.generateMap({ source: id, includeContent: true, hires: true }) as unknown as { toString(): string },\n count,\n seen: Array.from(seen).sort(),\n };\n}\n","/**\n * Worker / WASM asset collection for three.js addons.\n *\n * DRACOLoader, KTX2Loader, 3DMLoader, LottieLoader, ... reference decoder\n * `.js` and `.wasm` files by string path. In a mini game those files are not\n * reachable via HTTP; they must be copied into the code package (ideally a\n * subpackage) and `setDecoderPath` must point at the copied location.\n *\n * The plugin scans transformed modules, resolves each referenced basename in a\n * small set of known directories, copies it, and emits a manifest plus a\n * `game.json` suggestion. No global state, no hidden writes.\n */\nimport { promises as fs } from 'node:fs';\nimport path from 'node:path';\n\nexport interface AssetOptions {\n /** Extra directories to search (besides three's jsm/libs). */\n roots?: string[];\n /** Output directory relative to the bundle root. Default 'assets/three'. */\n outputDir?: string;\n /** Copy `.wasm.br` alongside `.wasm` when available. Default true. */\n brotli?: boolean;\n /** Emit `mini-three-assets.json`. Default true. */\n manifest?: boolean;\n /** Working directory used to resolve roots. Default process.cwd(). */\n cwd?: string;\n}\n\nexport interface AssetEntry {\n /** Original string found in the module. */\n reference: string;\n /** Resolved absolute source path. */\n source: string;\n /** Relative destination inside the bundle. */\n destination: string;\n kind: 'worker' | 'wasm' | 'data';\n}\n\nexport interface AssetManifest {\n generatedBy: 'mini-three-adapter';\n outputDir: string;\n entries: AssetEntry[];\n /** Paste into game.json (adjust subpackage names to your project). */\n gameJsonSuggestion: Record<string, unknown>;\n /** Decoder paths to feed to loaders at runtime. */\n decoderPaths: Record<string, string>;\n}\n\nconst ASSET_PATTERN = /(['\"`])([^'\"`\\n]*\\.(?:wasm|wasm\\.br|bin|js))\\1/g;\nconst DECODER_KEYWORDS = [\n 'draco', 'basis', 'ktx2', 'rhino3dm', 'zstd', 'meshopt', 'ammo',\n 'worker', 'decoder', 'transcoder', 'lottie', 'sdf',\n];\n\nexport function collectAssetReferences(code: string): string[] {\n const found = new Set<string>();\n let match: RegExpExecArray | null;\n ASSET_PATTERN.lastIndex = 0;\n while ((match = ASSET_PATTERN.exec(code)) !== null) {\n const value = match[2] ?? '';\n const lower = value.toLowerCase();\n if (DECODER_KEYWORDS.some((keyword) => lower.includes(keyword))) found.add(value);\n }\n return Array.from(found);\n}\n\nasync function indexFiles(root: string, maxDepth = 5): Promise<Map<string, string>> {\n const index = new Map<string, string>();\n const walk = async (dir: string, depth: number): Promise<void> => {\n if (depth > maxDepth) return;\n let entries;\n try { entries = await fs.readdir(dir, { withFileTypes: true }); }\n catch { return; }\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) await walk(full, depth + 1);\n else if (entry.isFile() && !index.has(entry.name)) index.set(entry.name, full);\n }\n };\n await walk(root, 0);\n return index;\n}\n\nfunction classify(name: string): AssetEntry['kind'] {\n if (name.endsWith('.wasm') || name.endsWith('.wasm.br')) return 'wasm';\n if (name.endsWith('.js')) return 'worker';\n return 'data';\n}\n\nexport function defaultRoots(cwd: string): string[] {\n return [\n path.join(cwd, 'node_modules/three/examples/jsm/libs'),\n path.join(cwd, 'node_modules/three/examples/jsm'),\n path.join(cwd, 'node_modules/three-stdlib'),\n path.join(cwd, 'public'),\n path.join(cwd, 'static'),\n ];\n}\n\nexport interface CollectResult {\n manifest: AssetManifest;\n /** Files to write: destination (relative) -> absolute source. */\n files: Map<string, string>;\n missing: string[];\n}\n\n/** Resolve references against known roots without copying anything. */\nexport async function collectAssets(references: string[], options: AssetOptions = {}): Promise<CollectResult> {\n const cwd = options.cwd ?? process.cwd();\n const outputDir = (options.outputDir ?? 'assets/three').replace(/\\\\/g, '/').replace(/\\/$/, '');\n const roots = [...defaultRoots(cwd), ...(options.roots ?? [])];\n const indexes = await Promise.all(roots.map((root) => indexFiles(root)));\n const find = (name: string): string | undefined => {\n for (const index of indexes) {\n const hit = index.get(name);\n if (hit) return hit;\n }\n return undefined;\n };\n\n const entries: AssetEntry[] = [];\n const files = new Map<string, string>();\n const missing: string[] = [];\n\n for (const reference of references) {\n const base = path.posix.basename(reference.split('?')[0] ?? reference);\n const source = find(base);\n if (!source) { missing.push(reference); continue; }\n const entry: AssetEntry = {\n reference,\n source,\n destination: `${outputDir}/${base}`,\n kind: classify(base),\n };\n entries.push(entry);\n files.set(entry.destination, source);\n if (options.brotli !== false && entry.kind === 'wasm') {\n const br = find(`${base}.br`);\n if (br) {\n entries.push({ reference: `${reference}.br`, source: br, destination: `${outputDir}/${base}.br`, kind: 'wasm' });\n files.set(`${outputDir}/${base}.br`, br);\n }\n }\n }\n\n const decoderPaths: Record<string, string> = {};\n for (const entry of entries) {\n const name = path.posix.basename(entry.destination).toLowerCase();\n for (const key of ['draco', 'ktx2', 'basis', 'meshopt', 'rhino3dm', 'zstd', 'ammo']) {\n if (name.includes(key)) decoderPaths[key] = `${outputDir}/`;\n }\n }\n\n const manifest: AssetManifest = {\n generatedBy: 'mini-three-adapter',\n outputDir,\n entries,\n gameJsonSuggestion: {\n workers: { path: `${outputDir}`, isSubpackage: true },\n subpackages: [{ name: 'three-assets', root: `${outputDir}/` }],\n },\n decoderPaths,\n };\n return { manifest, files, missing };\n}\n\n/** Copy resolved files into `outDir`. */\nexport async function copyAssets(files: Map<string, string>, outDir: string): Promise<number> {\n let written = 0;\n for (const [destination, source] of files) {\n const target = path.join(outDir, destination);\n await fs.mkdir(path.dirname(target), { recursive: true });\n await fs.copyFile(source, target);\n written++;\n }\n return written;\n}\n","/** Vite entry: `import miniThree from 'mini-three-adapter/vite'`. */\nimport { miniThreePlugin, type MiniThreePlugin, type MiniThreePluginOptions } from './plugin-core';\n\nexport interface ViteMiniThreePlugin extends MiniThreePlugin {\n config(): Record<string, unknown>;\n}\n\n/**\n * Vite plugin. `optimizeDeps.exclude` keeps three's ESM sources intact so the\n * AST rewrite sees the original module graph instead of a pre-bundled blob.\n */\nexport function miniThree(options: MiniThreePluginOptions = {}): ViteMiniThreePlugin {\n const core = miniThreePlugin(options);\n return {\n ...core,\n config() {\n return {\n optimizeDeps: {\n exclude: ['three', 'three-stdlib', 'three/examples/jsm'],\n },\n build: {\n commonjsOptions: { transformMixedEsModules: true },\n rollupOptions: {\n output: {\n manualChunks: undefined,\n },\n },\n },\n };\n },\n };\n}\n\nexport default miniThree;\nexport { miniThreePlugin } from './plugin-core';\nexport type { MiniThreePluginOptions, BuildReport } from './plugin-core';\n"],"mappings":";AASA,SAAS,YAAYA,WAAU;;;ACA/B,SAAS,aAAa;AACtB,OAAO,eAAe;AACtB,OAAO,iBAAiB;AAMxB,IAAM,WAAY,OAAO,cAAc,aACnC,YACC,UAAuD;AAErD,IAAM,uBAA0C;AAAA,EACrD;AAAA,EAAU;AAAA,EAAQ;AAAA,EAAY;AAAA,EAAa;AAAA,EAAU;AAAA,EACrD;AAAA,EAAc;AAAA,EAAe;AAAA,EAAc;AAAA,EAC3C;AAAA,EAAoB;AAAA,EAAe;AAAA,EACnC;AAAA,EAAe;AAAA,EAAyB;AAAA,EACxC;AAAA,EAAoB;AAAA,EAAc;AAAA,EAAQ;AAAA,EAC1C;AAAA,EAAS;AAAA,EAAe;AAAA,EAAe;AAAA,EAAgB;AAAA,EACvD;AAAA,EAAc;AAAA,EAAgB;AAAA,EAAiB;AAAA,EAAiB;AAAA,EAChE;AAAA,EAAe;AAAA,EAAqB;AAAA,EAAoB;AAAA,EACxD;AAAA,EAAmB;AAAA,EAAS;AAAA,EAAa;AAAA,EACzC;AAAA,EAAyB;AAAA,EAA0B;AAAA,EACnD;AAAA,EAAQ;AAAA,EAAO;AAAA,EAAmB;AAAA,EAAc;AAAA,EAAe;AAAA,EAC/D;AAAA,EAAmB;AAAA,EAAe;AAAA,EAAS;AAAA,EAAkB;AAAA,EAC7D;AAAA,EAAqB;AAAA,EAAU;AAAA,EAAe;AAChD;AAGO,IAAM,sBAAyC,CAAC,mBAAmB;AA6BnE,IAAM,eAAe,CAAC,UAAkB,WAC7C,8BAA8B,QAAQ,YAAY,MAAM;AAAA;AAE1D,SAAS,iBAAiBC,OAAyB;AACjD,QAAM,SAASA,MAAK;AACpB,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,OAAgBA,MAAK;AAC3B,MAAI,OAAO,iBA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