@pixifact/platform-douyin 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 youxia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @pixifact/platform-douyin
2
+
3
+ Pixifact 抖音小游戏 PixiJS 平台适配器。
4
+
5
+ ```bash
6
+ bun add @pixifact/platform-douyin
7
+ ```
8
+
9
+ 在 Vite 配置启用 `pixifact()`,并在 mode env 中声明:
10
+
11
+ ```ini
12
+ VITE_PLATFORM=douyin
13
+ VITE_APP_ID=tt123456
14
+ ```
15
+
16
+ 游戏入口通过 `pixifact:platform` 使用统一 API:
17
+
18
+ ```ts
19
+ import { createApplication } from 'pixifact:platform';
20
+
21
+ const app = await createApplication();
22
+ ```
23
+
24
+ 返回值是原生 PixiJS `Application`。包的顶层 import 不读取 `tt` 或执行初始化;小游戏构建固定输出 ES2018。资源继续使用 PixiJS `Assets`,分包在首次读取前自动加载。
25
+
26
+ 完整配置见 [抖音小游戏构建](https://github.com/hxg2050/pixifact/blob/main/docs/zh/douyin-minigame.md)。
@@ -0,0 +1,2 @@
1
+ import type { Application, ApplicationOptions } from 'pixi.js';
2
+ export declare function createApplication(options?: Partial<ApplicationOptions>): Promise<Application>;
@@ -0,0 +1,14 @@
1
+ import { createMiniGameApplication } from 'pixifact/internal/minigame';
2
+ import { fetchDouyinResource } from './fetch.js';
3
+ import { installDouyinImageAssets } from './imageAssets.js';
4
+ import { douyinApi } from './types.js';
5
+ function douyinTouchCoordinates(touch) {
6
+ return {
7
+ x: touch.screenX ?? touch.clientX ?? touch.x ?? touch.pageX ?? 0,
8
+ y: touch.screenY ?? touch.clientY ?? touch.y ?? touch.pageY ?? 0,
9
+ };
10
+ }
11
+ export function createApplication(options = {}) {
12
+ installDouyinImageAssets();
13
+ return createMiniGameApplication(douyinApi(), 'DouyinMiniGame', fetchDouyinResource, douyinTouchCoordinates, options);
14
+ }
@@ -0,0 +1 @@
1
+ export declare function fetchDouyinResource(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
package/dist/fetch.js ADDED
@@ -0,0 +1,9 @@
1
+ import { fetchMiniGameResource, miniGameResourceSubpackage } from 'pixifact/internal/minigame';
2
+ import { loadDouyinSubpackage } from './subpackage.js';
3
+ import { douyinApi } from './types.js';
4
+ export async function fetchDouyinResource(input, init = {}) {
5
+ const subpackage = miniGameResourceSubpackage(input);
6
+ if (subpackage)
7
+ await loadDouyinSubpackage(subpackage);
8
+ return fetchMiniGameResource(douyinApi(), input, init, 'Douyin');
9
+ }
@@ -0,0 +1 @@
1
+ export declare function installDouyinImageAssets(): void;
@@ -0,0 +1,60 @@
1
+ import { checkDataUrl, checkExtension, createTexture, extensions, ExtensionType, getResolutionOfUrl, ImageSource, LoaderParserPriority, } from 'pixi.js';
2
+ import { douyinApi } from './types.js';
3
+ const validImageExtensions = ['.jpeg', '.jpg', '.png', '.webp', '.avif'];
4
+ const validImageMimes = ['image/jpeg', 'image/png', 'image/webp', 'image/avif'];
5
+ const douyinImageLoaderId = 'pixifact-douyin-image';
6
+ const douyinImageLoader = {
7
+ extension: {
8
+ type: ExtensionType.LoadParser,
9
+ priority: LoaderParserPriority.High + 1,
10
+ name: 'loadDouyinTextures',
11
+ },
12
+ id: douyinImageLoaderId,
13
+ test(url) {
14
+ return checkDataUrl(url, validImageMimes) || checkExtension(url, validImageExtensions);
15
+ },
16
+ async load(url, asset, loader) {
17
+ const image = await loadDouyinImage(url);
18
+ const { width, height } = image;
19
+ if (!isPositiveDimension(width) || !isPositiveDimension(height)) {
20
+ throw new Error(`[pixifact-douyin] Loaded image has no usable size: ${url}`);
21
+ }
22
+ const resolution = asset.data?.resolution || getResolutionOfUrl(url);
23
+ const source = new ImageSource({
24
+ alphaMode: 'premultiply-alpha-on-upload',
25
+ resolution,
26
+ ...asset.data,
27
+ resource: image,
28
+ width: width / resolution,
29
+ height: height / resolution,
30
+ });
31
+ return createTexture(source, loader, url);
32
+ },
33
+ unload(texture) {
34
+ texture.destroy(true);
35
+ },
36
+ };
37
+ export function installDouyinImageAssets() {
38
+ extensions.add(douyinImageLoader);
39
+ }
40
+ function loadDouyinImage(url) {
41
+ const image = douyinApi().createImage();
42
+ return new Promise((resolve, reject) => {
43
+ image.onload = () => {
44
+ clearImageHandlers(image);
45
+ resolve(image);
46
+ };
47
+ image.onerror = () => {
48
+ clearImageHandlers(image);
49
+ reject(new Error(`[pixifact-douyin] Failed to load image: ${url}`));
50
+ };
51
+ image.src = url;
52
+ });
53
+ }
54
+ function clearImageHandlers(image) {
55
+ image.onload = null;
56
+ image.onerror = null;
57
+ }
58
+ function isPositiveDimension(value) {
59
+ return Number.isFinite(value) && value > 0;
60
+ }
@@ -0,0 +1,2 @@
1
+ export { createApplication } from './application.js';
2
+ export type { DouyinCanvas, DouyinMiniGameApi } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createApplication } from './application.js';
@@ -0,0 +1,5 @@
1
+ import { type MiniGamePointerBinding, type MiniGamePointerEventSink } from 'pixifact/internal/minigame';
2
+ import type { DouyinCanvas } from './types.js';
3
+ export type DouyinPointerEventSink = MiniGamePointerEventSink;
4
+ export type DouyinPointerBinding = MiniGamePointerBinding;
5
+ export declare function bindDouyinPointerEvents(canvas: DouyinCanvas, sink: DouyinPointerEventSink): DouyinPointerBinding;
package/dist/input.js ADDED
@@ -0,0 +1,11 @@
1
+ import { bindMiniGamePointerEvents, } from 'pixifact/internal/minigame';
2
+ import { douyinApi } from './types.js';
3
+ function douyinTouchCoordinates(touch) {
4
+ return {
5
+ x: touch.screenX ?? touch.clientX ?? touch.x ?? touch.pageX ?? 0,
6
+ y: touch.screenY ?? touch.clientY ?? touch.y ?? touch.pageY ?? 0,
7
+ };
8
+ }
9
+ export function bindDouyinPointerEvents(canvas, sink) {
10
+ return bindMiniGamePointerEvents(douyinApi(), canvas, sink, douyinTouchCoordinates);
11
+ }
@@ -0,0 +1,6 @@
1
+ import { bindMiniGameLifecycle, type MiniGameLifecycleBinding } from 'pixifact/internal/minigame';
2
+ export type DouyinLifecycleBinding = MiniGameLifecycleBinding;
3
+ export declare function bindDouyinLifecycle(target: Parameters<typeof bindMiniGameLifecycle>[1], options?: {
4
+ onHide?(): void;
5
+ onShow?(): void;
6
+ }): DouyinLifecycleBinding;
@@ -0,0 +1,5 @@
1
+ import { bindMiniGameLifecycle } from 'pixifact/internal/minigame';
2
+ import { douyinApi } from './types.js';
3
+ export function bindDouyinLifecycle(target, options = {}) {
4
+ return bindMiniGameLifecycle(douyinApi(), target, options);
5
+ }
@@ -0,0 +1 @@
1
+ export declare const loadDouyinSubpackage: (name: string) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { createMiniGameSubpackageLoader } from 'pixifact/internal/minigame';
2
+ import { douyinApi } from './types.js';
3
+ export const loadDouyinSubpackage = createMiniGameSubpackageLoader(douyinApi, 'Douyin');
@@ -0,0 +1,7 @@
1
+ import type { MiniGameApi, MiniGameCanvas, MiniGameImage, MiniGameTouch, MiniGameTouchEvent } from 'pixifact/internal/minigame';
2
+ export type DouyinCanvas = MiniGameCanvas;
3
+ export type DouyinImage = MiniGameImage;
4
+ export type DouyinTouch = MiniGameTouch;
5
+ export type DouyinTouchEvent = MiniGameTouchEvent;
6
+ export type DouyinMiniGameApi = MiniGameApi;
7
+ export declare function douyinApi(): MiniGameApi;
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export function douyinApi() {
2
+ return globalThis.tt;
3
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@pixifact/platform-douyin",
3
+ "version": "0.7.0",
4
+ "description": "Pixifact 抖音小游戏 PixiJS 平台适配器。",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist/",
11
+ "README.md"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/hxg2050/pixifact",
16
+ "directory": "packages/platform-douyin"
17
+ },
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.js"
24
+ }
25
+ },
26
+ "scripts": {
27
+ "build": "bun ../pixifact/scripts/clean-dist.mjs dist && bunx --no-install tsc -p tsconfig.build.json && bun ../pixifact/scripts/fix-dist-esm-imports.mjs dist"
28
+ },
29
+ "peerDependencies": {
30
+ "pixifact": ">=0.7.0 <1",
31
+ "pixi.js": ">=8.3.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "license": "MIT"
38
+ }