A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(export): a project can be packaged for Douyin
esengined2400a3b6cff
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ac981b096..d12516bfe 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -41,6 +41,16 @@ published separately; it ships inside the editor.### Added+- **A project can be exported as a Douyin (抖音) mini-game.** Pick *Douyin* in Package+ Project and the same content that makes a WeChat package makes a Douyin one, judged+ against Douyin's own caps — 4MB for the main package and **20MB in total**, ten less+ than WeChat allows, which is the number that catches a package out. Three things are+ deliberately not claimed yet, because this release cannot cite them: the suffix list+ its packer accepts, `.wasm.br` for the engine binary, and a wasm loader of the host's+ own. Each is something only a real device settles, and a package that claimed one+ early would build clean and fail at upload or at boot. Douyin needs no separate engine+ build — the web artifact is what a `tt` host runs.+- **A sprite can be drawn whole even when its texture carries a 9-slice border.** Thetexture decided, not the entity using it: import a panel image with slice borders andevery Sprite showing it was 9-sliced, with nothing on the entity able to say otherwise.diff --git a/pipeline/src/bundle/esengineResolve.ts b/pipeline/src/bundle/esengineResolve.tsindex 997d254d1..5a37aab4a 100644--- a/pipeline/src/bundle/esengineResolve.ts+++ b/pipeline/src/bundle/esengineResolve.ts@@ -29,6 +29,7 @@ export function esengineAlias(sdkDir: string, mainEntry = 'index.js'): Record<st'esengine/dragonbones': path.join(sdkDir, 'dragonbones', 'index.js'),'esengine/physics': path.join(sdkDir, 'physics', 'index.js'),'esengine/physics3d': path.join(sdkDir, 'physics3d', 'index.js'),+ 'esengine/douyin': path.join(sdkDir, 'douyin', 'index.js'),'esengine/wasm': path.join(sdkDir, 'wasm.js'),'esengine/factory': path.join(sdkDir, 'webAppFactory.js'),};diff --git a/pipeline/src/bundle/runtimeHosts.ts b/pipeline/src/bundle/runtimeHosts.tsindex f1954d470..c0323aeac 100644--- a/pipeline/src/bundle/runtimeHosts.ts+++ b/pipeline/src/bundle/runtimeHosts.ts@@ -12,7 +12,12 @@import path from 'node:path';import { ESENGINE_EXTERNAL } from './esengineResolve';-export const RUNTIME_HOSTS = ['gameHost', 'playableHost', 'playableLoader'] as const;+// `douyinPlatformProfile` is not a host but travels the same way: a built-in+// vendor's runtime profile is a module the generated entry imports, so the+// editor has to ship it for the same reason it ships the hosts.+export const RUNTIME_HOSTS = [+ 'gameHost', 'playableHost', 'playableLoader', 'douyinPlatformProfile',+] as const;export type RuntimeHost = (typeof RUNTIME_HOSTS)[number];diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex b44eaaa48..4a680c8ec 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -34,9 +34,15 @@ import {DEFAULT_RUNTIME_CONFIG, packagedRuntimeFields, type RuntimeProjectConfig,} from '../project/runtimeConfig';import { IMPORT_MAP_JSON, IMPORT_MAP_CSP_HASH } from '../bundle/importMap';-import { exportWeChat } from './exportWeChat';import { exportMiniGame } from './exportMiniGame';+import { wechatExportProfile, douyinExportProfile } from './miniGameExportProfile';import type { MiniGameExportProfile } from './miniGameExportProfile';++/** The mini-game vendors the editor ships, by platform id. */+const BUILTIN_MINIGAME_PROFILES: Readonly<Record<string, MiniGameExportProfile>> = {+ wechat: wechatExportProfile,+ douyin: douyinExportProfile,+};import { exportPlayable } from './exportPlayable';import { genericPlayableProfile, type PlayableAdProfile } from './playableAdProfile';import type { OnExportProgress } from './exportProgress';@@ -588,6 +594,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>sdkDir: opts.sdkDistDir,wasmDir: opts.wasmDir,outDir: opts.outDir,+ hostsDir: opts.hostsDir,title,appid: opts.wechatAppid,orientation,@@ -606,9 +613,12 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>}// WeChat has no import maps + a different module/asset model → its own pipeline.- if (platform === 'wechat') {- if (streamed.length > 0) refuseStreamedWorld('the WeChat package');- return await exportWeChat({+ // A table, not a branch per vendor: adding one is a profile object, which is+ // the promise miniGameExportProfile makes and a `platform === …` chain drops.+ const builtinMiniGame = BUILTIN_MINIGAME_PROFILES[platform];+ if (builtinMiniGame) {+ if (streamed.length > 0) refuseStreamedWorld(`the ${builtinMiniGame.id} package`);+ return await exportMiniGame(builtinMiniGame, {root: opts.root,entryScene: opts.entryScene,scenes,@@ -616,6 +626,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>sdkDir: opts.sdkDistDir,wasmDir: opts.wasmDir,outDir: opts.outDir,+ hostsDir: opts.hostsDir,title,appid: opts.wechatAppid,orientation,diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.tsindex 847269258..0cef0aa23 100644--- a/pipeline/src/export/exportMiniGame.ts+++ b/pipeline/src/export/exportMiniGame.ts@@ -41,6 +41,7 @@ import { cookAssets, type Inclusion } from '../assets/cookAssets';import { buildAddressableManifest } from '../assets/addressableManifest';import type { ExportScene } from './exportGame';import type { OnExportProgress } from './exportProgress';+import { runtimeHostEntry } from '../bundle/runtimeHosts';import { breakdownOf, type ModuleBytes } from './bundleBreakdown';import { esengineAlias } from '../bundle/esengineResolve';import { explainBundleErrors, type BundleMessage } from '../bundle/bundleDiagnostics';@@ -230,6 +231,9 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {sdkDir: string;wasmDir: string;outDir: string;+ /** Where the runtime hosts live — sources in dev, a prebuilt tree in a packaged+ * editor. A built-in vendor's platform profile is resolved against it. */+ hostsDir: string;title?: string;/** MiniGame appid (Project Settings) → project config. */appid?: string;@@ -405,12 +409,13 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {? `, uiThemeOverrides: parseThemeOverrides(${JSON.stringify(v)})`: `, ${k}: ${JSON.stringify(v)}`)).join('');- // A vendor whose SDK entry does not install a platform on import (the- // family entry, esengine/minigame — it waits until the game names a host)- // gets its runtime profile installed here, at the top of boot(). Without- // this the package would build fine and then throw on the device, which is- // the worst place to learn that the two halves of a vendor were never joined.- const installsPlatform = !!profile.runtimeProfileModule;+ // esengine/minigame installs no platform until a host is named, so boot() names+ // one: a built-in points at a shipped module, a project vendor at a file beside+ // its own platform. Unjoined, the package builds and throws on the device.+ const platformProfileModule = profile.runtimeProfileHost+ ? runtimeHostEntry(opts.hostsDir, profile.runtimeProfileHost)+ : profile.runtimeProfileModule;+ const installsPlatform = !!platformProfileModule;// A mini-game does not read game.config.json — its configuration IS this// generated call — so the project modules' artifact names ride it here. The// factories arrive separately (game.js require()s the glue); this is what tells@@ -434,9 +439,9 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {await cp(built.modulePath, path.join(absOut, 'aot', 'systems.wasm'));aotArg = `, aot: ${JSON.stringify({ module: 'aot/systems.wasm', manifest: built.manifest })}`;}- // The same answer the scan already gives for wasm side modules, asked of their- // JS: the lean SDK entry plus the subpaths that install what this project uses.- // Video has no subpath, so a project with video takes the whole entry.+ // The scan's answer for wasm side modules, asked of their JS: the lean entry+ // plus the subpaths that install what this project uses. Video has no subpath,+ // so a project with video takes the whole entry.const OPTIONAL_SUBPATH: Record<string, string> = {physics: 'esengine/physics',physics3d: 'esengine/physics3d',@@ -460,7 +465,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {const entrySrc =installs.map((m) => `import ${JSON.stringify(m)};\n`).join('') +`import { ${profile.runtimeInit}${installsPlatform ? ', installMiniGamePlatform' : ''}${themeColors ? ', parseThemeOverrides' : ''} } from 'esengine';\n` +- (installsPlatform ? `import __platformProfile from ${JSON.stringify(profile.runtimeProfileModule)};\n` : '') ++ (installsPlatform ? `import __platformProfile from ${JSON.stringify(platformProfileModule)};\n` : '') +(scriptsAbs && existsSync(scriptsAbs) ? `import ${JSON.stringify(scriptsAbs)};\n` : '') +`export function boot(engineFactory, sideModuleFactories) {\n` +(installsPlatform ? ` installMiniGamePlatform(__platformProfile);\n` : '') +diff --git a/pipeline/src/export/exportWeChat.ts b/pipeline/src/export/exportWeChat.tsdeleted file mode 100644index d1317060e..000000000--- a/pipeline/src/export/exportWeChat.ts+++ /dev/null@@ -1,34 +0,0 @@-// SPDX-License-Identifier: Apache-2.0-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-/**- * @file WeChat MiniGame export — a thin binding of the shared mini-game export- * pipeline (exportMiniGame.ts) to the WeChat profile. All of the assembly- * logic lives in exportMiniGame; this file only fixes the vendor and- * preserves the WeChat-typed public surface exportGame consumes.- */-import { exportMiniGame } from './exportMiniGame';-import { wechatExportProfile } from './miniGameExportProfile';--export interface ExportWeChatResult {- ok: boolean;- platform: 'wechat';- outDir: string;- included: number;- warnings: string[];- errors: string[];-}--/** Parameters accepted by {@link exportWeChat} — the shared pipeline options. */-export type ExportWeChatOptions = Parameters<typeof exportMiniGame>[1];--/**- * Export the open project as a WeChat MiniGame into `outDir`. See- * {@link exportMiniGame} for the full contract; WeChat-specific behavior- * (config files, WXWebAssembly glue names, es2017 floor, suffix whitelist) is- * carried by {@link wechatExportProfile}.- */-export async function exportWeChat(opts: ExportWeChatOptions): Promise<ExportWeChatResult> {- const res = await exportMiniGame(wechatExportProfile, opts);- // The wechat profile's id is 'wechat', so the result platform is 'wechat'.- return res as ExportWeChatResult;-}diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.tsindex 664540bf0..cb50decb0 100644--- a/pipeline/src/export/miniGameExportProfile.ts+++ b/pipeline/src/export/miniGameExportProfile.ts@@ -12,6 +12,7 @@* Adding a vendor = one profile object, not a fork of the pipeline.*/import { WECHAT_MODULE_BUILD_TARGET } from '../bundle/sideModuleScan';+import type { RuntimeHost } from '../bundle/runtimeHosts';import type { SizeBudget } from '../project/sizeBudget';/**@@ -193,6 +194,14 @@ export interface MiniGameExportProfile {*/readonly runtimeProfileModule?: string;+ /**+ * The same thing for a BUILT-IN vendor, whose profile module ships with the+ * pipeline rather than living in a project: a name out of RUNTIME_HOSTS,+ * resolved against the export's hostsDir. Declaring the path directly would+ * be wrong in a packaged editor, which bundles those sources elsewhere.+ */+ readonly runtimeProfileHost?: RuntimeHost;+/** Emit the vendor config files (game.json + project.config.json / project.tt.json). */emitConfigFiles(ctx: MiniGameConfigContext): Array<{ file: string; content: string }>;/** Emit the MiniGame entry the host runs (game.js). */@@ -272,3 +281,61 @@ export const wechatExportProfile: MiniGameExportProfile = {emitEntry: defaultMiniGameEntry,};++// =============================================================================+// Douyin profile+// =============================================================================++/**+ * Douyin (抖音) as a packaging profile. No SDK entry of its own — it goes through+ * the door a project vendor uses, `runtimeProfileHost`. A packer whitelist,+ * `.wasm.br` and a host wasm loader stay off until a device settles them:+ * claiming one early builds clean and fails at upload or at boot.+ */+export const douyinExportProfile: MiniGameExportProfile = {+ id: 'douyin',+ sdkEntryFile: 'index.minigame.js',+ runtimeInit: 'initMiniGameRuntime',+ runtimeProfileHost: 'douyinPlatformProfile',+ // No Douyin-specific engine build: the web artifact is what a `tt` host runs.+ engineGlueCandidates: ['esengine.js'],+ // Same floor as WeChat until a device says otherwise — down-levelling costs+ // nothing and a syntax error on a phone costs a release.+ esTarget: 'es2017',+ wasmBuildHint: 'web',+ hostGlobal: 'tt',+ sideModuleBuildTargets: {},+ nativeSuffixes: new Set(['.js', '.json']),+ // No published list this checkout can cite, so nothing is restaged: staging a+ // file under a name the packer does not take is the failure that only shows at+ // upload, and inventing the list would be that failure with extra steps.+ packerSuffixes: null,+ // Not claimed until a device says it: `.wasm.br` is WeChat's documented path,+ // and shipping only the compressed file to a host that cannot read it is a+ // package that builds clean and never boots.+ wasmBrotli: false,+ subpackageDir: 'subpackages',+ subpackageEntry: 'game.js',++ emitConfigFiles(ctx) {+ const gameCfg: Record<string, unknown> = {+ deviceOrientation: ctx.orientation,+ showStatusBar: false,+ };+ if (ctx.subPackages.length > 0) {+ gameCfg.subPackages = ctx.subPackages.map((s) => ({ name: s.name, root: s.root }));+ }+ const projectCfg: Record<string, unknown> = {+ miniprogramRoot: './',+ projectname: ctx.title,+ appid: ctx.appid,+ compileType: 'game',+ };+ return [+ { file: 'game.json', content: JSON.stringify(gameCfg, null, 2) + '\n' },+ { file: 'project.tt.json', content: JSON.stringify(projectCfg, null, 2) + '\n' },+ ];+ },++ emitEntry: defaultMiniGameEntry,+};diff --git a/pipeline/src/project/platforms.ts b/pipeline/src/project/platforms.tsindex 1ed152567..243dec341 100644--- a/pipeline/src/project/platforms.ts+++ b/pipeline/src/project/platforms.ts@@ -21,11 +21,11 @@* Xcode), so a single row could not tell you what to run, whether this machine* can run it, or where the package comes out.*/-export type BuiltinPlatform = 'web' | 'desktop' | 'wechat' | 'playable' | 'android' | 'ios';+export type BuiltinPlatform = 'web' | 'desktop' | 'wechat' | 'douyin' | 'playable' | 'android' | 'ios';/** Built-ins, in the order they are offered. */export const BUILTIN_PLATFORMS: readonly BuiltinPlatform[] = [- 'web', 'desktop', 'wechat', 'playable', 'android', 'ios',+ 'web', 'desktop', 'wechat', 'douyin', 'playable', 'android', 'ios',];/**@@ -162,7 +162,7 @@ export type ToolchainPiece = 'xcode' | 'macos' | 'emsdk' | 'hostcc';* playable has nowhere to put a module; iOS and Android need a cross-compiler.*/export function compileTargetFor(platform: ExportPlatform): 'wasm' | 'native' | null {- if (platform === 'web' || platform === 'wechat') return 'wasm';+ if (platform === 'web' || platform === 'wechat' || platform === 'douyin') return 'wasm';if (platform === 'desktop') return 'native';if (platform === 'playable' || platform === 'android' || platform === 'ios') return null;// A project platform is a mini-game platform: the playable ones are chosendiff --git a/pipeline/src/project/sizeBudget.ts b/pipeline/src/project/sizeBudget.tsindex 9b2394fb7..1ef3942f2 100644--- a/pipeline/src/project/sizeBudget.ts+++ b/pipeline/src/project/sizeBudget.ts@@ -74,9 +74,17 @@ const MB = 1024 * 1024;*/export function builtinSizeBudgets(platform: ExportPlatform): readonly SizeBudget[] {if (platform === 'wechat') return WECHAT_BUDGETS;+ if (platform === 'douyin') return DOUYIN_BUDGETS;return NO_BUDGETS;}+/** Douyin's caps are lower than WeChat's on the total, which is the one that+ * surprises: a package that fits WeChat can still be 10MB over here. */+const DOUYIN_BUDGETS: readonly SizeBudget[] = [+ { scope: 'initial', maxBytes: 4 * MB, note: "Douyin caps a mini-game's main package at 4MB" },+ { scope: 'total', maxBytes: 20 * MB, note: 'Douyin caps a mini-game at 20MB across the main package and all subpackages' },+];+const NO_BUDGETS: readonly SizeBudget[] = [];/**diff --git a/pipeline/src/runtime/douyinPlatformProfile.ts b/pipeline/src/runtime/douyinPlatformProfile.tsnew file mode 100644index 000000000..82ccf0a4c--- /dev/null+++ b/pipeline/src/runtime/douyinPlatformProfile.ts@@ -0,0 +1,14 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file douyinPlatformProfile.ts — the module a Douyin package installs its+ * platform from, as the export profile's `runtimeProfileModule`.+ *+ * A built-in vendor goes through the same door a project-authored one does:+ * `esengine/minigame` installs nothing until a host is named, and the generated+ * entry names this. That is why Douyin needs no SDK entry of its own — one per+ * vendor is the shape this family exists to avoid.+ */+import { douyinProfile } from 'esengine/douyin';++export default douyinProfile;diff --git a/pipeline/tests/export-douyin.test.ts b/pipeline/tests/export-douyin.test.tsnew file mode 100644index 000000000..8323dea5b--- /dev/null+++ b/pipeline/tests/export-douyin.test.ts@@ -0,0 +1,100 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Douyin MiniGame export — that a second vendor needed no second pipeline.+ * Asserts the four things that are Douyin's and not WeChat's: the config+ * file it writes, the host it names, the entry that installs a platform+ * rather than assuming one, and the caps it is judged against.+ * (Boot correctness is a device's to answer — see RM-032.)+ */+import { describe, it, expect, beforeAll, afterAll } from 'vitest';+import { runtimeConfigOf } from '../src/project/runtimeConfig';+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';+import { exportGame } from '../src/export/exportGame';+import { builtinSizeBudgets } from '../src/project/sizeBudget';++let root: string;+let out: string;+const TEX = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';+const SCN = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';+const meta = (uuid: string, type: string) => JSON.stringify({ uuid, version: '2.0', type, importer: {} });++beforeAll(() => {+ root = mkdtempSync(path.join(tmpdir(), 'estella-export-douyin-'));+ mkdirSync(path.join(root, 'assets'), { recursive: true });+ writeFileSync(path.join(root, 'assets', 'hero.png'), 'PNGDATA');+ writeFileSync(path.join(root, 'assets', 'hero.png.meta'), meta(TEX, 'texture'));+ mkdirSync(path.join(root, 'scenes'), { recursive: true });+ writeFileSync(+ path.join(root, 'scenes', 'main.esscene'),+ JSON.stringify({ version: '1.0', name: 'Main', entities: [{ id: 0, components: [{ type: 'Sprite', data: { texture: `@uuid:${TEX}` } }] }] }),+ );+ writeFileSync(path.join(root, 'scenes', 'main.esscene.meta'), meta(SCN, 'scene'));+ // Douyin bundles the vendor-neutral entry, so the stub is that one — a stub of+ // index.wechat.js would still satisfy a test that only counted files.+ mkdirSync(path.join(root, '_sdk'), { recursive: true });+ writeFileSync(path.join(root, '_sdk', 'index.minigame.js'),+ 'export function initMiniGameRuntime(){return Promise.resolve();}\n'+ + 'export function installMiniGamePlatform(){}\n');+ mkdirSync(path.join(root, '_sdk', 'douyin'), { recursive: true });+ writeFileSync(path.join(root, '_sdk', 'douyin', 'index.js'),+ 'export const douyinProfile = { id: "douyin", hostLabel: "\\u6296\\u97f3" };\n');+ // The web engine artifact: Douyin has no build of its own.+ mkdirSync(path.join(root, '_wasm'), { recursive: true });+ writeFileSync(path.join(root, '_wasm', 'esengine.js'), 'module.exports = () => Promise.resolve({});');+ writeFileSync(path.join(root, '_wasm', 'esengine.wasm'), 'wasmbytes');++ out = path.join(root, 'dist-douyin');+}, 60_000);++afterAll(() => rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }));++describe('exportGame (douyin)', () => {+ it('writes the vendor config Douyin reads, not the one WeChat reads', async () => {+ const res = await exportGame({+ root,+ entryScene: 'scenes/main.esscene',+ hostsDir: path.resolve(__dirname, '../src/runtime'),+ sdkDistDir: path.join(root, '_sdk'),+ wasmDir: path.join(root, '_wasm'),+ outDir: out,+ title: 'My Game',+ platform: 'douyin',+ orientation: 'landscape',+ runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),+ });++ expect(res.ok, res.errors.join('\n')).toBe(true);+ expect(res.platform).toBe('douyin');++ expect(existsSync(path.join(out, 'project.tt.json'))).toBe(true);+ expect(existsSync(path.join(out, 'project.config.json'))).toBe(false);+ const cfg = JSON.parse(readFileSync(path.join(out, 'project.tt.json'), 'utf8'));+ expect(cfg.compileType).toBe('game');+ expect(cfg.miniprogramRoot).toBe('./');+ expect(JSON.parse(readFileSync(path.join(out, 'game.json'), 'utf8')).deviceOrientation).toBe('landscape');+ }, 180_000);++ it('boots through the vendor-neutral entry and names its host', () => {+ // The whole point of the family: Douyin ships no SDK entry of its own, so the+ // bundle must carry index.minigame AND the profile that names `tt` — either+ // one alone is a package that boots into no host at all.+ const bundle = readFileSync(path.join(out, 'game-bundle.js'), 'utf8');+ expect(bundle).toContain('index.minigame.js');+ expect(bundle).toContain('installMiniGamePlatform');+ expect(bundle).toContain('douyin');+ });++ it('is judged against Douyin\'s caps, which are not WeChat\'s', () => {+ const budgets = builtinSizeBudgets('douyin');+ const total = budgets.find((b) => b.scope === 'total');+ const initial = budgets.find((b) => b.scope === 'initial');+ expect(initial?.maxBytes).toBe(4 * 1024 * 1024);+ // 20MB, not WeChat's 30: a package that fits WeChat can still be over here,+ // which is the failure this number exists to catch.+ expect(total?.maxBytes).toBe(20 * 1024 * 1024);+ expect(total?.note).toContain('Douyin');+ });+});diff --git a/sdk/package.json b/sdk/package.jsonindex 1ee703f9c..046b44fbb 100644--- a/sdk/package.json+++ b/sdk/package.json@@ -52,6 +52,10 @@"./physics3d": {"import": "./dist/physics3d/index.js","types": "./dist/physics3d/index.d.ts"+ },+ "./douyin": {+ "import": "./dist/douyin/index.js",+ "types": "./dist/douyin/index.d.ts"}},"files": [diff --git a/sdk/rolldown.config.js b/sdk/rolldown.config.jsindex fe8d0170c..3958ea80d 100644--- a/sdk/rolldown.config.js+++ b/sdk/rolldown.config.js@@ -60,6 +60,7 @@ export default defineConfig(['physics3d/index': 'src/physics3d/index.ts','spine/index': 'src/spine/index.ts','dragonbones/index': 'src/dragonbones/index.ts',+ 'douyin/index': 'src/platform/douyin/index.ts','wasm': 'src/wasm.ts',},output: {diff --git a/sdk/rollup.config.js b/sdk/rollup.config.jsindex 563a60b59..51232603c 100644--- a/sdk/rollup.config.js+++ b/sdk/rollup.config.js@@ -16,6 +16,7 @@ export default ['index.native': 'src/index.native.ts','physics/index': 'src/physics/index.ts','physics3d/index': 'src/physics3d/index.ts',+ 'douyin/index': 'src/platform/douyin/index.ts','spine/index': 'src/spine/index.ts','dragonbones/index': 'src/dragonbones/index.ts','wasm': 'src/wasm.ts',diff --git a/sdk/src/platform/douyin/index.ts b/sdk/src/platform/douyin/index.tsnew file mode 100644index 000000000..e0d216e6a--- /dev/null+++ b/sdk/src/platform/douyin/index.ts@@ -0,0 +1,24 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file index.ts+ * @brief Douyin MiniGame platform (a profile of the mini-game family).+ *+ * Adapter, polyfills and install are the family's; Douyin adds nothing, which is+ * the point of the family existing.+ */+import { MiniGamePlatformAdapter, installMiniGamePlatform } from '../minigame';+import { douyinProfile } from './profile';++export const douyinAdapter = new MiniGamePlatformAdapter(douyinProfile);++let initialized = false;++/** Initialize the Douyin platform. Call it at the entry point (see index.douyin.ts). */+export function initDouyinPlatform(): void {+ if (initialized) return;+ initialized = true;+ installMiniGamePlatform(douyinProfile, douyinAdapter);+}++export { douyinProfile };diff --git a/sdk/src/platform/douyin/profile.ts b/sdk/src/platform/douyin/profile.tsnew file mode 100644index 000000000..f91a0781b--- /dev/null+++ b/sdk/src/platform/douyin/profile.ts@@ -0,0 +1,31 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file profile.ts+ * @brief Douyin as a profile of the mini-game platform family.+ *+ * Three facts and no override: fs, fetch, canvas, image, input, storage,+ * subpackages, audio, video and sockets are the family's, written once in+ * ../minigame/ against the normalized host global, and `tt` answers the same+ * shape `wx` does.+ *+ * UNVERIFIED on a device: that Douyin instantiates wasm through the standard+ * `WebAssembly.instantiate` the family falls back to, rather than a host call of+ * its own the way WeChat's WXWebAssembly does. If it does not, this profile+ * gains an `instantiateWasm` exactly as WeChat's has one. RM-032's acceptance is+ * a real device for that reason.+ */+import type { MiniGameGlobal, MiniGameProfile } from '../minigame';++/** Douyin's host global. Ambient at runtime and absent while bundling, so it is+ * read lazily — importing this module outside Douyin must not touch it. */+declare const tt: unknown;++export const douyinProfile: MiniGameProfile = {+ id: 'douyin',+ hostLabel: '抖音',++ get global(): MiniGameGlobal {+ return tt as MiniGameGlobal;+ },+};diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 7f3564994..8e55789f4 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'feat(export): a project can be packaged for Douyin':+ { note: 'A project can be exported as a Douyin (抖音) mini-game.' },+'feat(render): a sprite says how it fills its box, instead of its texture saying':{ note: 'A sprite can be drawn whole even when its texture carries a 9-slice border.' },