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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -29
  3. package/dist/client.d.ts +23 -0
  4. package/dist/compiler/compileScenes.js +13 -4
  5. package/dist/compiler/typescriptCompiler.js +2 -2
  6. package/dist/compiler-node/vite.d.ts +16 -6
  7. package/dist/compiler-node/vite.js +417 -32
  8. package/dist/errors.d.ts +1 -1
  9. package/dist/errors.js +6 -0
  10. package/dist/platform/{wechat → minigame}/adapter.d.ts +7 -6
  11. package/dist/platform/{wechat → minigame}/adapter.js +10 -8
  12. package/dist/platform/minigame/application.d.ts +4 -0
  13. package/dist/platform/minigame/application.js +53 -0
  14. package/dist/platform/minigame/fetch.d.ts +2 -0
  15. package/dist/platform/{wechat → minigame}/fetch.js +13 -15
  16. package/dist/platform/minigame/index.d.ts +8 -0
  17. package/dist/platform/minigame/index.js +8 -0
  18. package/dist/platform/minigame/input.d.ts +16 -0
  19. package/dist/platform/{wechat → minigame}/input.js +18 -19
  20. package/dist/platform/minigame/lifecycle.d.ts +15 -0
  21. package/dist/platform/{wechat → minigame}/lifecycle.js +5 -7
  22. package/dist/platform/{wechat → minigame}/runtime.d.ts +5 -5
  23. package/dist/platform/{wechat → minigame}/runtime.js +14 -20
  24. package/dist/platform/minigame/subpackage.d.ts +3 -0
  25. package/dist/platform/minigame/subpackage.js +36 -0
  26. package/dist/platform/{wechat → minigame}/types.d.ts +24 -21
  27. package/dist/platform/minigame/types.js +1 -0
  28. package/dist/platform/web/index.d.ts +2 -0
  29. package/dist/platform/web/index.js +6 -0
  30. package/dist/project/index.d.ts +5 -24
  31. package/dist/project/index.js +45 -59
  32. package/dist/scene/index.d.ts +0 -1
  33. package/dist/scene/index.js +0 -1
  34. package/package.json +16 -7
  35. package/dist/platform/wechat/application.d.ts +0 -32
  36. package/dist/platform/wechat/application.js +0 -79
  37. package/dist/platform/wechat/fetch.d.ts +0 -1
  38. package/dist/platform/wechat/index.d.ts +0 -4
  39. package/dist/platform/wechat/index.js +0 -3
  40. package/dist/platform/wechat/input.d.ts +0 -12
  41. package/dist/platform/wechat/lifecycle.d.ts +0 -14
  42. package/dist/platform/wechat/subpackage.d.ts +0 -1
  43. package/dist/platform/wechat/subpackage.js +0 -27
  44. package/dist/platform/wechat/types.js +0 -3
  45. package/dist/scene/sceneAssetRuntime.d.ts +0 -11
  46. 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 的 Scene / UI / 轻场景语义层,面向 AI 可直接编辑的 `.scene` 工作流。
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
- ```ts
16
- import { parseSceneTemplate } from 'pixifact/compiler';
17
- import { Group } from 'pixifact/runtime';
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
- `pixifact/compiler` 只包含解析、校验和生成 API。游戏运行时使用 `pixifact/runtime`、`pixifact/scene` 和具体平台入口,不要从 compiler 入口导入 Scene decorator 或运行时加载 API。
19
+ ## Vite
23
20
 
24
- Compiler Scene 项目通常还会安装 CLI:
21
+ ```ts
22
+ import { defineConfig } from 'vite';
23
+ import { pixifact } from 'pixifact/compiler-node';
25
24
 
26
- ```bash
27
- bun add -d pixifact-cli
25
+ export default defineConfig({ plugins: [pixifact()] });
28
26
  ```
29
27
 
30
- 然后校验和编译 `.scene` 文件:
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
- 声明 `targets.wechat` 后,可校验和构建微信小游戏:
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
- ```bash
40
- pixifact validate --target wechat
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
- 完整配置见仓库文档 [微信小游戏构建](https://github.com/hxg2050/pixifact/blob/main/docs/zh/wechat-minigame.md)。
40
+ `createApplication()` 返回原生 PixiJS `Application`,不隐式初始化 Assets。Scene 纹理和业务 JSON、音频、字体、资源包都沿用 PixiJS `Assets.load()` / `Assets.loadBundle()`。
46
41
 
47
42
  ## Scene 工作流
48
43
 
49
- Pixifact 把项目相对 `.scene` 文件作为 source of truth。外部 Agent 直接编辑 `.scene` 源文件,然后运行校验和编译。
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 或更高版本
@@ -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 { access, mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
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 writeFile(generatedFile, code);
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 writeFile(path.join(generatedDir, 'scenes.generated.ts'), `${[
135
+ await writeGeneratedFile(path.join(generatedDir, 'scenes.generated.ts'), `${[
135
136
  ...builtinRegistryImports,
136
137
  ...projectRegistryImports,
137
138
  ].join('\n')}\n`);
138
- await writeFile(path.join(generatedDir, generatedSceneAssetsFileName), `${JSON.stringify([...projectAssets].sort(), null, 2)}\n`);
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]) => ` loadSceneTexture(${JSON.stringify(texture)}),`),
197
+ ...entries.map(([texture]) => ` Assets.load<Texture>(${JSON.stringify(texture)}),`),
198
198
  ' ]);',
199
199
  '}',
200
200
  ].join('\n');
@@ -1,9 +1,19 @@
1
- export interface PixifactScenesPluginOptions {
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 declare function pixifactScenesPlugin(options?: PixifactScenesPluginOptions): {
6
- name: string;
7
- resolveId(id: string): "\0pixifact:scenes" | undefined;
8
- load(id: string): Promise<string | undefined>;
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>;