pixifact 0.6.0 → 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 +21 -0
- package/README.md +30 -29
- package/dist/client.d.ts +23 -0
- package/dist/compiler/compileScenes.js +13 -4
- package/dist/compiler/typescriptCompiler.js +2 -2
- package/dist/compiler-node/vite.d.ts +16 -6
- package/dist/compiler-node/vite.js +417 -32
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +6 -0
- package/dist/platform/{wechat → minigame}/adapter.d.ts +7 -6
- package/dist/platform/{wechat → minigame}/adapter.js +10 -8
- package/dist/platform/minigame/application.d.ts +4 -0
- package/dist/platform/minigame/application.js +53 -0
- package/dist/platform/minigame/fetch.d.ts +2 -0
- package/dist/platform/{wechat → minigame}/fetch.js +13 -15
- package/dist/platform/minigame/index.d.ts +8 -0
- package/dist/platform/minigame/index.js +8 -0
- package/dist/platform/minigame/input.d.ts +16 -0
- package/dist/platform/{wechat → minigame}/input.js +18 -19
- package/dist/platform/minigame/lifecycle.d.ts +15 -0
- package/dist/platform/{wechat → minigame}/lifecycle.js +5 -7
- package/dist/platform/{wechat → minigame}/runtime.d.ts +5 -5
- package/dist/platform/{wechat → minigame}/runtime.js +14 -20
- package/dist/platform/minigame/subpackage.d.ts +3 -0
- package/dist/platform/minigame/subpackage.js +36 -0
- package/dist/platform/{wechat → minigame}/types.d.ts +24 -21
- package/dist/platform/minigame/types.js +1 -0
- package/dist/platform/web/index.d.ts +2 -0
- package/dist/platform/web/index.js +6 -0
- package/dist/project/index.d.ts +5 -24
- package/dist/project/index.js +45 -59
- package/dist/scene/index.d.ts +0 -1
- package/dist/scene/index.js +0 -1
- package/package.json +16 -7
- package/dist/platform/wechat/application.d.ts +0 -32
- package/dist/platform/wechat/application.js +0 -79
- package/dist/platform/wechat/fetch.d.ts +0 -1
- package/dist/platform/wechat/index.d.ts +0 -4
- package/dist/platform/wechat/index.js +0 -3
- package/dist/platform/wechat/input.d.ts +0 -12
- package/dist/platform/wechat/lifecycle.d.ts +0 -14
- package/dist/platform/wechat/subpackage.d.ts +0 -1
- package/dist/platform/wechat/subpackage.js +0 -27
- package/dist/platform/wechat/types.js +0 -3
- package/dist/scene/sceneAssetRuntime.d.ts +0 -11
- package/dist/scene/sceneAssetRuntime.js +0 -43
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
CHANGED
|
@@ -1,58 +1,59 @@
|
|
|
1
1
|
# Pixifact
|
|
2
2
|
|
|
3
|
-
Pixifact 是基于 PixiJS v8
|
|
4
|
-
|
|
5
|
-
`pixifact` 包提供项目配置解析、runtime 节点、compiler API 和生成 Scene 的运行时支持。CLI 和项目脚手架分别由 `pixifact-cli`、`create-pixifact` 提供。
|
|
3
|
+
Pixifact 是基于 PixiJS v8、面向 AI 可编辑 `.scene` 工作流的 Scene / UI / 轻场景语义层。
|
|
6
4
|
|
|
7
5
|
## 安装
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
bun add pixifact pixi.js
|
|
9
|
+
bun add -d pixifact-cli vite
|
|
11
10
|
```
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
只在需要时安装小游戏平台包:
|
|
14
13
|
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import { prepareSceneClass, scene } from 'pixifact/scene';
|
|
19
|
-
import { createWechatPixiApplication } from 'pixifact/platform/wechat';
|
|
14
|
+
```bash
|
|
15
|
+
bun add @pixifact/platform-wechat
|
|
16
|
+
bun add @pixifact/platform-douyin
|
|
20
17
|
```
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
## Vite
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
```ts
|
|
22
|
+
import { defineConfig } from 'vite';
|
|
23
|
+
import { pixifact } from 'pixifact/compiler-node';
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
bun add -d pixifact-cli
|
|
25
|
+
export default defineConfig({ plugins: [pixifact()] });
|
|
28
26
|
```
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pixifact scene validate --all
|
|
34
|
-
pixifact compile-scenes
|
|
35
|
-
```
|
|
28
|
+
Web、微信和抖音共享 `src/main.ts`。平台由当前 Vite mode env 中的 `VITE_PLATFORM=web|wechat|douyin` 选择;小游戏还需要 `VITE_APP_ID`。
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
```ts
|
|
31
|
+
import 'pixifact:scenes';
|
|
32
|
+
import { Assets } from 'pixi.js';
|
|
33
|
+
import { createApplication } from 'pixifact:platform';
|
|
34
|
+
import manifest from 'pixifact:assets';
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
pixifact build --target wechat
|
|
42
|
-
pixifact dev --target wechat
|
|
36
|
+
const app = await createApplication();
|
|
37
|
+
await Assets.init({ manifest });
|
|
43
38
|
```
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
`createApplication()` 返回原生 PixiJS `Application`,不隐式初始化 Assets。Scene 纹理和业务 JSON、音频、字体、资源包都沿用 PixiJS `Assets.load()` / `Assets.loadBundle()`。
|
|
46
41
|
|
|
47
42
|
## Scene 工作流
|
|
48
43
|
|
|
49
|
-
|
|
44
|
+
```bash
|
|
45
|
+
pixifact scene validate --all
|
|
46
|
+
pixifact compile-scenes
|
|
47
|
+
pixifact validate --mode production
|
|
48
|
+
pixifact build --mode production
|
|
49
|
+
```
|
|
50
50
|
|
|
51
|
-
`.pixifact/generated
|
|
51
|
+
项目相对 `.scene` 是 source of truth;不要编辑 `.pixifact/generated/**`。解析、校验和生成 API 位于 `pixifact/compiler`,Node/Vite 插件位于 `pixifact/compiler-node`,runtime 与 Scene API 分别位于 `pixifact/runtime` 和 `pixifact/scene`。
|
|
52
|
+
|
|
53
|
+
微信和抖音构建配置见仓库文档:[微信小游戏](https://github.com/hxg2050/pixifact/blob/main/docs/zh/wechat-minigame.md)、[抖音小游戏](https://github.com/hxg2050/pixifact/blob/main/docs/zh/douyin-minigame.md)。
|
|
52
54
|
|
|
53
55
|
## 环境要求
|
|
54
56
|
|
|
55
57
|
- Bun
|
|
56
58
|
- PixiJS v8
|
|
57
|
-
|
|
58
|
-
桌面编辑器不包含在 npm runtime 包中。
|
|
59
|
+
- Vite 6 或更高版本
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare module 'pixifact:platform' {
|
|
2
|
+
import type { Application, ApplicationOptions } from 'pixi.js';
|
|
3
|
+
|
|
4
|
+
export function createApplication(
|
|
5
|
+
options?: Partial<ApplicationOptions>,
|
|
6
|
+
): Promise<Application>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module 'pixifact:assets' {
|
|
10
|
+
import type { AssetsManifest } from 'pixi.js';
|
|
11
|
+
|
|
12
|
+
const manifest: AssetsManifest;
|
|
13
|
+
export default manifest;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ImportMetaEnv {
|
|
17
|
+
readonly VITE_APP_ID?: string;
|
|
18
|
+
readonly VITE_PLATFORM: 'web' | 'wechat' | 'douyin';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ImportMeta {
|
|
22
|
+
readonly env: ImportMetaEnv;
|
|
23
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { access, mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { builtinSceneAssetIds, builtinSceneNameFromAssetId, isBuiltinSceneAssetId, } from './builtinScenes.js';
|
|
@@ -123,7 +124,7 @@ export async function compileScenes(options) {
|
|
|
123
124
|
collectTemplateTextures(template, projectAssets);
|
|
124
125
|
}
|
|
125
126
|
await mkdir(path.dirname(generatedFile), { recursive: true });
|
|
126
|
-
await
|
|
127
|
+
await writeGeneratedFile(generatedFile, code);
|
|
127
128
|
if (record.kind === 'project') {
|
|
128
129
|
projectRegistryImports.push(`import ${JSON.stringify(generatedSceneModuleImport(scenePath))};`);
|
|
129
130
|
}
|
|
@@ -131,11 +132,19 @@ export async function compileScenes(options) {
|
|
|
131
132
|
builtinRegistryImports.push(`import ${JSON.stringify(generatedSceneModuleImport(scenePath))};`);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
await
|
|
135
|
+
await writeGeneratedFile(path.join(generatedDir, 'scenes.generated.ts'), `${[
|
|
135
136
|
...builtinRegistryImports,
|
|
136
137
|
...projectRegistryImports,
|
|
137
138
|
].join('\n')}\n`);
|
|
138
|
-
await
|
|
139
|
+
await writeGeneratedFile(path.join(generatedDir, generatedSceneAssetsFileName), `${JSON.stringify([...projectAssets].sort(), null, 2)}\n`);
|
|
140
|
+
}
|
|
141
|
+
async function writeGeneratedFile(filePath, content) {
|
|
142
|
+
if (await exists(filePath) && await readFile(filePath, 'utf8') === content) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const temporaryPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;
|
|
146
|
+
await writeFile(temporaryPath, content);
|
|
147
|
+
await rename(temporaryPath, filePath);
|
|
139
148
|
}
|
|
140
149
|
async function readProjectConfig(projectRoot) {
|
|
141
150
|
const configPath = path.join(projectRoot, pixifactProjectConfigFileName);
|
|
@@ -186,15 +186,15 @@ class CompileContext {
|
|
|
186
186
|
if (this.#textures.size === 0) {
|
|
187
187
|
return `export async function ${this.#prepareFunctionName()}() {}`;
|
|
188
188
|
}
|
|
189
|
+
this.#pixiImports.add('Assets');
|
|
189
190
|
this.#pixiImports.add('Texture');
|
|
190
|
-
this.#runtimeImports.add('loadSceneTexture');
|
|
191
191
|
const entries = [...this.#textures.entries()];
|
|
192
192
|
return [
|
|
193
193
|
...entries.map(([, variable]) => `let ${variable}: Texture;`),
|
|
194
194
|
'',
|
|
195
195
|
`export async function ${this.#prepareFunctionName()}() {`,
|
|
196
196
|
` [${entries.map(([, variable]) => variable).join(', ')}] = await Promise.all([`,
|
|
197
|
-
...entries.map(([texture]) => `
|
|
197
|
+
...entries.map(([texture]) => ` Assets.load<Texture>(${JSON.stringify(texture)}),`),
|
|
198
198
|
' ]);',
|
|
199
199
|
'}',
|
|
200
200
|
].join('\n');
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
|
+
export type PixifactPlatform = 'web' | 'wechat' | 'douyin';
|
|
3
|
+
export interface PixifactPluginOptions {
|
|
2
4
|
projectRoot?: string | URL;
|
|
3
|
-
generatedDir?: string;
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export interface PixifactBuildReport {
|
|
7
|
+
mainPackageBytes: number;
|
|
8
|
+
outputDirectory: string;
|
|
9
|
+
platform: PixifactPlatform;
|
|
10
|
+
subpackages: Record<string, number>;
|
|
11
|
+
totalPackageBytes: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function pixifact(options?: PixifactPluginOptions): Plugin[];
|
|
14
|
+
export declare function pixifactBuildReporter(platform: PixifactPlatform, onReport: (report: PixifactBuildReport) => void): Plugin;
|
|
15
|
+
export declare function loadPixifactEnv(projectRoot: string, mode: string): {
|
|
16
|
+
env: Record<string, string>;
|
|
17
|
+
platform: PixifactPlatform;
|
|
9
18
|
};
|
|
19
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|