@pixifact/platform-wechat 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-wechat
2
+
3
+ Pixifact 微信小游戏 PixiJS 平台适配器。
4
+
5
+ ```bash
6
+ bun add @pixifact/platform-wechat
7
+ ```
8
+
9
+ 在 Vite 配置启用 `pixifact()`,并在 mode env 中声明:
10
+
11
+ ```ini
12
+ VITE_PLATFORM=wechat
13
+ VITE_APP_ID=wx123456
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 不读取 `wx` 或执行平台初始化;Canvas、输入、生命周期和资源 adapter 在 `createApplication()` 时安装。资源继续使用 PixiJS `Assets`,分包在首次读取前自动加载。
25
+
26
+ 完整配置见 [微信小游戏构建](https://github.com/hxg2050/pixifact/blob/main/docs/zh/wechat-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,12 @@
1
+ import { createMiniGameApplication } from 'pixifact/internal/minigame';
2
+ import { fetchWechatResource } from './fetch.js';
3
+ import { wechatApi } from './types.js';
4
+ function wechatTouchCoordinates(touch) {
5
+ return {
6
+ x: touch.clientX ?? touch.x ?? touch.pageX ?? touch.screenX ?? 0,
7
+ y: touch.clientY ?? touch.y ?? touch.pageY ?? touch.screenY ?? 0,
8
+ };
9
+ }
10
+ export function createApplication(options = {}) {
11
+ return createMiniGameApplication(wechatApi(), 'WeChatMiniGame', fetchWechatResource, wechatTouchCoordinates, options);
12
+ }
@@ -0,0 +1 @@
1
+ export declare function fetchWechatResource(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 { loadWechatSubpackage } from './subpackage.js';
3
+ import { wechatApi } from './types.js';
4
+ export async function fetchWechatResource(input, init = {}) {
5
+ const subpackage = miniGameResourceSubpackage(input);
6
+ if (subpackage)
7
+ await loadWechatSubpackage(subpackage);
8
+ return fetchMiniGameResource(wechatApi(), input, init, 'WeChat');
9
+ }
@@ -0,0 +1,2 @@
1
+ export { createApplication } from './application.js';
2
+ export type { WechatCanvas, WechatMiniGameApi } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createApplication } from './application.js';
@@ -0,0 +1,6 @@
1
+ import { bindMiniGameLifecycle, type MiniGameLifecycleBinding } from 'pixifact/internal/minigame';
2
+ export type WechatLifecycleBinding = MiniGameLifecycleBinding;
3
+ export declare function bindWechatLifecycle(target: Parameters<typeof bindMiniGameLifecycle>[1], options?: {
4
+ onHide?(): void;
5
+ onShow?(): void;
6
+ }): WechatLifecycleBinding;
@@ -0,0 +1,5 @@
1
+ import { bindMiniGameLifecycle } from 'pixifact/internal/minigame';
2
+ import { wechatApi } from './types.js';
3
+ export function bindWechatLifecycle(target, options = {}) {
4
+ return bindMiniGameLifecycle(wechatApi(), target, options);
5
+ }
@@ -0,0 +1 @@
1
+ export declare const loadWechatSubpackage: (name: string) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { createMiniGameSubpackageLoader } from 'pixifact/internal/minigame';
2
+ import { wechatApi } from './types.js';
3
+ export const loadWechatSubpackage = createMiniGameSubpackageLoader(wechatApi, 'WeChat');
@@ -0,0 +1,7 @@
1
+ import type { MiniGameApi, MiniGameCanvas, MiniGameImage, MiniGameTouch, MiniGameTouchEvent } from 'pixifact/internal/minigame';
2
+ export type WechatCanvas = MiniGameCanvas;
3
+ export type WechatImage = MiniGameImage;
4
+ export type WechatTouch = MiniGameTouch;
5
+ export type WechatTouchEvent = MiniGameTouchEvent;
6
+ export type WechatMiniGameApi = MiniGameApi;
7
+ export declare function wechatApi(): MiniGameApi;
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export function wechatApi() {
2
+ return globalThis.wx;
3
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@pixifact/platform-wechat",
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-wechat"
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
+ }