pixifact 0.2.2 → 0.4.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 (48) hide show
  1. package/README.md +14 -0
  2. package/dist/compiler/compileScenes.d.ts +1 -0
  3. package/dist/compiler/compileScenes.js +8 -9
  4. package/dist/compiler/index.d.ts +0 -4
  5. package/dist/compiler/index.js +0 -4
  6. package/dist/compiler/pixiNodeSchema.d.ts +2 -2
  7. package/dist/compiler/pixiNodeSchema.js +10 -0
  8. package/dist/compiler/sceneValidation.js +1 -1
  9. package/dist/compiler/scriptInterfaceExtractor.js +6 -0
  10. package/dist/compiler/spec.d.ts +2 -2
  11. package/dist/compiler/templateParser.js +1 -0
  12. package/dist/compiler/typescriptCompiler.js +54 -45
  13. package/dist/compiler-node/vite.d.ts +2 -1
  14. package/dist/compiler-node/vite.js +29 -2
  15. package/dist/platform/wechat/adapter.d.ts +316 -0
  16. package/dist/platform/wechat/adapter.js +26 -0
  17. package/dist/platform/wechat/application.d.ts +32 -0
  18. package/dist/platform/wechat/application.js +79 -0
  19. package/dist/platform/wechat/fetch.d.ts +1 -0
  20. package/dist/platform/wechat/fetch.js +145 -0
  21. package/dist/platform/wechat/index.d.ts +4 -0
  22. package/dist/platform/wechat/index.js +3 -0
  23. package/dist/platform/wechat/input.d.ts +12 -0
  24. package/dist/platform/wechat/input.js +93 -0
  25. package/dist/platform/wechat/lifecycle.d.ts +14 -0
  26. package/dist/platform/wechat/lifecycle.js +42 -0
  27. package/dist/platform/wechat/runtime.d.ts +49 -0
  28. package/dist/platform/wechat/runtime.js +189 -0
  29. package/dist/platform/wechat/subpackage.d.ts +1 -0
  30. package/dist/platform/wechat/subpackage.js +27 -0
  31. package/dist/platform/wechat/types.d.ts +105 -0
  32. package/dist/platform/wechat/types.js +3 -0
  33. package/dist/project/index.d.ts +23 -0
  34. package/dist/project/index.js +69 -0
  35. package/dist/{compiler → scene}/decorators.d.ts +1 -1
  36. package/dist/scene/index.d.ts +5 -0
  37. package/dist/scene/index.js +5 -0
  38. package/dist/scene/sceneAssetRuntime.d.ts +11 -0
  39. package/dist/scene/sceneAssetRuntime.js +43 -0
  40. package/dist/{compiler → scene}/sceneRuntime.d.ts +7 -0
  41. package/dist/scene/sceneRuntime.js +85 -0
  42. package/package.json +11 -1
  43. package/dist/compiler/sceneRuntime.js +0 -22
  44. /package/dist/{compiler → scene}/decorators.js +0 -0
  45. /package/dist/{compiler → scene}/eventRuntime.d.ts +0 -0
  46. /package/dist/{compiler → scene}/eventRuntime.js +0 -0
  47. /package/dist/{compiler → scene}/slotRuntime.d.ts +0 -0
  48. /package/dist/{compiler → scene}/slotRuntime.js +0 -0
@@ -0,0 +1,11 @@
1
+ import { type Texture } from 'pixi.js';
2
+ export interface SceneAssetLocation {
3
+ src: string;
4
+ pack?: string;
5
+ }
6
+ export type SceneAssetManifest = Record<string, SceneAssetLocation>;
7
+ export interface SceneAssetRuntimeOptions {
8
+ loadPack?: (name: string) => Promise<void>;
9
+ }
10
+ export declare function configureSceneAssets(manifest: SceneAssetManifest, options?: SceneAssetRuntimeOptions): void;
11
+ export declare function loadSceneTexture(id: string): Promise<Texture>;
@@ -0,0 +1,43 @@
1
+ import { Assets } from 'pixi.js';
2
+ let assetManifest = {};
3
+ let loadPack;
4
+ const loadedPacks = new Set();
5
+ const loadingPacks = new Map();
6
+ export function configureSceneAssets(manifest, options = {}) {
7
+ assetManifest = manifest;
8
+ loadPack = options.loadPack;
9
+ loadedPacks.clear();
10
+ loadingPacks.clear();
11
+ }
12
+ async function preparePack(name) {
13
+ if (loadedPacks.has(name)) {
14
+ return;
15
+ }
16
+ const existing = loadingPacks.get(name);
17
+ if (existing) {
18
+ return existing;
19
+ }
20
+ if (!loadPack) {
21
+ throw new Error(`Scene asset pack "${name}" has no platform loader.`);
22
+ }
23
+ const pending = loadPack(name).then(() => {
24
+ loadedPacks.add(name);
25
+ loadingPacks.delete(name);
26
+ }, (error) => {
27
+ loadingPacks.delete(name);
28
+ throw error;
29
+ });
30
+ loadingPacks.set(name, pending);
31
+ return pending;
32
+ }
33
+ export async function loadSceneTexture(id) {
34
+ const location = assetManifest[id];
35
+ if (!location) {
36
+ throw new Error(`Scene asset "${id}" is missing from the target manifest.`);
37
+ }
38
+ if (location.pack) {
39
+ await preparePack(location.pack);
40
+ }
41
+ Assets.add({ alias: id, src: location.src });
42
+ return Assets.load(id);
43
+ }
@@ -2,13 +2,20 @@ import type { Container } from 'pixi.js';
2
2
  import type { Group } from '../runtime/index.js';
3
3
  export interface SceneMountResult {
4
4
  root: Group;
5
+ nodes: Record<string, Container>;
5
6
  parts: Record<string, Container>;
6
7
  slots: Record<string, Container>;
7
8
  }
8
9
  export interface SceneDefinition {
10
+ assets: string[];
11
+ dependencies: string[];
9
12
  mount(root: Group): SceneMountResult;
13
+ prepare(): Promise<void>;
10
14
  }
11
15
  export declare function registerScene(path: string, definition: SceneDefinition): void;
12
16
  export declare function registerSceneClass(constructor: object, path: string): void;
13
17
  export declare function mountScene(root: Group, path: string): SceneMountResult;
14
18
  export declare function mountSceneClass(root: Group, constructor: object): SceneMountResult;
19
+ export declare function prepareScene(path: string): Promise<void>;
20
+ export declare function prepareSceneClass(constructor: object): Promise<void>;
21
+ export declare function getSceneNode(root: Group, locator: string): Container<import("pixi.js").ContainerChild> | undefined;
@@ -0,0 +1,85 @@
1
+ const sceneDefinitions = new Map();
2
+ const scenePathsByConstructor = new WeakMap();
3
+ const sceneMounts = new WeakMap();
4
+ const preparedScenes = new Set();
5
+ const preparingScenes = new Map();
6
+ export function registerScene(path, definition) {
7
+ sceneDefinitions.set(path, definition);
8
+ preparedScenes.delete(path);
9
+ preparingScenes.delete(path);
10
+ }
11
+ export function registerSceneClass(constructor, path) {
12
+ scenePathsByConstructor.set(constructor, path);
13
+ }
14
+ export function mountScene(root, path) {
15
+ const definition = sceneDefinitions.get(path);
16
+ if (!definition) {
17
+ throw new Error(`Scene "${path}" has not been registered.`);
18
+ }
19
+ if (!preparedScenes.has(path)) {
20
+ throw new Error(`Scene "${path}" must be prepared before it is instantiated.`);
21
+ }
22
+ const result = definition.mount(root);
23
+ sceneMounts.set(root, result);
24
+ return result;
25
+ }
26
+ export function mountSceneClass(root, constructor) {
27
+ const path = scenePathsByConstructor.get(constructor);
28
+ if (!path) {
29
+ throw new Error(`Scene class "${constructor instanceof Function ? constructor.name : 'unknown'}" has not been bound to a .scene file.`);
30
+ }
31
+ return mountScene(root, path);
32
+ }
33
+ export async function prepareScene(path) {
34
+ if (preparedScenes.has(path)) {
35
+ return;
36
+ }
37
+ assertSceneDependencyGraph(path);
38
+ const pending = preparingScenes.get(path);
39
+ if (pending) {
40
+ return pending;
41
+ }
42
+ const definition = sceneDefinitions.get(path);
43
+ if (!definition) {
44
+ throw new Error(`Scene "${path}" has not been registered.`);
45
+ }
46
+ const preparation = (async () => {
47
+ await Promise.all(definition.dependencies.map((dependency) => prepareScene(dependency)));
48
+ await definition.prepare();
49
+ preparedScenes.add(path);
50
+ preparingScenes.delete(path);
51
+ })().catch((error) => {
52
+ preparingScenes.delete(path);
53
+ throw error;
54
+ });
55
+ preparingScenes.set(path, preparation);
56
+ return preparation;
57
+ }
58
+ function assertSceneDependencyGraph(path, visiting = new Set(), visited = new Set()) {
59
+ if (visiting.has(path)) {
60
+ throw new Error(`Scene dependency cycle detected at "${path}".`);
61
+ }
62
+ if (visited.has(path)) {
63
+ return;
64
+ }
65
+ const definition = sceneDefinitions.get(path);
66
+ if (!definition) {
67
+ throw new Error(`Scene "${path}" has not been registered.`);
68
+ }
69
+ visiting.add(path);
70
+ for (const dependency of definition.dependencies) {
71
+ assertSceneDependencyGraph(dependency, visiting, visited);
72
+ }
73
+ visiting.delete(path);
74
+ visited.add(path);
75
+ }
76
+ export async function prepareSceneClass(constructor) {
77
+ const path = scenePathsByConstructor.get(constructor);
78
+ if (!path) {
79
+ throw new Error(`Scene class "${constructor instanceof Function ? constructor.name : 'unknown'}" has not been bound to a .scene file.`);
80
+ }
81
+ return prepareScene(path);
82
+ }
83
+ export function getSceneNode(root, locator) {
84
+ return sceneMounts.get(root)?.nodes[locator];
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixifact",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Pixifact 2D UI 和轻量游戏 Scene 语义框架。",
5
5
  "packageManager": "bun@1.3.13",
6
6
  "main": "./dist/index.js",
@@ -42,6 +42,11 @@
42
42
  "import": "./dist/runtime/index.js",
43
43
  "require": "./dist/runtime/index.js"
44
44
  },
45
+ "./scene": {
46
+ "types": "./dist/scene/index.d.ts",
47
+ "import": "./dist/scene/index.js",
48
+ "require": "./dist/scene/index.js"
49
+ },
45
50
  "./compiler": {
46
51
  "types": "./dist/compiler/index.d.ts",
47
52
  "import": "./dist/compiler/index.js",
@@ -51,6 +56,11 @@
51
56
  "types": "./dist/compiler-node/index.d.ts",
52
57
  "import": "./dist/compiler-node/index.js",
53
58
  "require": "./dist/compiler-node/index.js"
59
+ },
60
+ "./platform/wechat": {
61
+ "types": "./dist/platform/wechat/index.d.ts",
62
+ "import": "./dist/platform/wechat/index.js",
63
+ "require": "./dist/platform/wechat/index.js"
54
64
  }
55
65
  },
56
66
  "peerDependencies": {
@@ -1,22 +0,0 @@
1
- const sceneDefinitions = new Map();
2
- const scenePathsByConstructor = new WeakMap();
3
- export function registerScene(path, definition) {
4
- sceneDefinitions.set(path, definition);
5
- }
6
- export function registerSceneClass(constructor, path) {
7
- scenePathsByConstructor.set(constructor, path);
8
- }
9
- export function mountScene(root, path) {
10
- const definition = sceneDefinitions.get(path);
11
- if (!definition) {
12
- throw new Error(`Scene "${path}" has not been registered.`);
13
- }
14
- return definition.mount(root);
15
- }
16
- export function mountSceneClass(root, constructor) {
17
- const path = scenePathsByConstructor.get(constructor);
18
- if (!path) {
19
- throw new Error(`Scene class "${constructor instanceof Function ? constructor.name : 'unknown'}" has not been bound to a .scene file.`);
20
- }
21
- return mountScene(root, path);
22
- }
File without changes
File without changes
File without changes
File without changes
File without changes