pixifact 0.1.3 → 0.1.4

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 (185) hide show
  1. package/README.md +3 -3
  2. package/dist/builtin-scenes/CenterContainer.d.ts +13 -0
  3. package/dist/builtin-scenes/CenterContainer.js +71 -0
  4. package/dist/builtin-scenes/CenterContainer.scene +3 -0
  5. package/dist/builtin-scenes/CenterContainer.ts +77 -0
  6. package/dist/builtin-scenes/Control.d.ts +44 -0
  7. package/dist/builtin-scenes/Control.js +206 -0
  8. package/dist/builtin-scenes/Control.scene +3 -0
  9. package/dist/builtin-scenes/Control.ts +233 -0
  10. package/dist/builtin-scenes/FlexItem.d.ts +45 -0
  11. package/dist/builtin-scenes/FlexItem.js +164 -0
  12. package/dist/builtin-scenes/FlexItem.scene +3 -0
  13. package/dist/builtin-scenes/FlexItem.ts +180 -0
  14. package/dist/builtin-scenes/FlexLayout.d.ts +29 -0
  15. package/dist/builtin-scenes/FlexLayout.js +358 -0
  16. package/dist/builtin-scenes/FlexLayout.scene +3 -0
  17. package/dist/builtin-scenes/FlexLayout.ts +409 -0
  18. package/dist/builtin-scenes/HBoxContainer.d.ts +15 -0
  19. package/dist/builtin-scenes/HBoxContainer.js +70 -0
  20. package/dist/builtin-scenes/HBoxContainer.scene +3 -0
  21. package/dist/builtin-scenes/HBoxContainer.ts +75 -0
  22. package/dist/builtin-scenes/MarginContainer.d.ts +23 -0
  23. package/dist/builtin-scenes/MarginContainer.js +131 -0
  24. package/dist/builtin-scenes/MarginContainer.scene +3 -0
  25. package/dist/builtin-scenes/MarginContainer.ts +139 -0
  26. package/dist/builtin-scenes/VBoxContainer.d.ts +15 -0
  27. package/dist/builtin-scenes/VBoxContainer.js +70 -0
  28. package/dist/builtin-scenes/VBoxContainer.scene +3 -0
  29. package/dist/builtin-scenes/VBoxContainer.ts +75 -0
  30. package/dist/builtin-scenes/controlLayout.d.ts +57 -0
  31. package/dist/builtin-scenes/controlLayout.js +202 -0
  32. package/dist/builtin-scenes/controlLayout.ts +270 -0
  33. package/dist/compiler/builtinScenes.d.ts +14 -0
  34. package/dist/compiler/builtinScenes.js +62 -0
  35. package/dist/compiler/compileScenes.js +126 -19
  36. package/dist/compiler/decorators.js +3 -0
  37. package/dist/compiler/index.d.ts +1 -0
  38. package/dist/compiler/index.js +1 -0
  39. package/dist/compiler/sceneAssetPair.js +19 -0
  40. package/dist/compiler/sceneRuntime.d.ts +5 -4
  41. package/dist/compiler/scriptInterfaceExtractor.d.ts +5 -0
  42. package/dist/compiler/scriptInterfaceExtractor.js +214 -8
  43. package/dist/compiler/spec.d.ts +2 -0
  44. package/dist/compiler/templateParser.js +4 -3
  45. package/dist/compiler/templateSerializer.js +2 -1
  46. package/dist/compiler/typescriptCompiler.js +87 -13
  47. package/dist/compiler-node/builtinSceneAssets.d.ts +8 -0
  48. package/dist/compiler-node/builtinSceneAssets.js +57 -0
  49. package/dist/compiler-node/index.d.ts +1 -0
  50. package/dist/compiler-node/index.js +1 -0
  51. package/dist/errors.d.ts +1 -0
  52. package/dist/errors.js +24 -0
  53. package/dist/index.d.ts +2 -5
  54. package/dist/index.js +2 -5
  55. package/dist/{authoring/ProjectConfig.d.ts → project/index.d.ts} +7 -0
  56. package/dist/{authoring/ProjectConfig.js → project/index.js} +22 -0
  57. package/dist/runtime/Group.d.ts +18 -0
  58. package/dist/runtime/Group.js +45 -0
  59. package/dist/runtime/index.d.ts +1 -9
  60. package/dist/runtime/index.js +1 -9
  61. package/package.json +4 -26
  62. package/dist/authoring/ActionRegistry.d.ts +0 -10
  63. package/dist/authoring/ActionRegistry.js +0 -26
  64. package/dist/authoring/ComponentPalette.d.ts +0 -16
  65. package/dist/authoring/ComponentPalette.js +0 -50
  66. package/dist/authoring/DesignToken.d.ts +0 -16
  67. package/dist/authoring/DesignToken.js +0 -33
  68. package/dist/authoring/DiffModel.d.ts +0 -10
  69. package/dist/authoring/DiffModel.js +0 -104
  70. package/dist/authoring/InspectorModel.d.ts +0 -27
  71. package/dist/authoring/InspectorModel.js +0 -139
  72. package/dist/authoring/LogicGraph.d.ts +0 -66
  73. package/dist/authoring/LogicGraph.js +0 -184
  74. package/dist/authoring/OverrideJournal.d.ts +0 -18
  75. package/dist/authoring/OverrideJournal.js +0 -23
  76. package/dist/authoring/PreferenceMemory.d.ts +0 -21
  77. package/dist/authoring/PreferenceMemory.js +0 -39
  78. package/dist/authoring/RuntimePreview.d.ts +0 -11
  79. package/dist/authoring/RuntimePreview.js +0 -25
  80. package/dist/authoring/SceneDocument.d.ts +0 -74
  81. package/dist/authoring/SceneDocument.js +0 -332
  82. package/dist/authoring/SceneProjectState.d.ts +0 -20
  83. package/dist/authoring/SceneProjectState.js +0 -8
  84. package/dist/authoring/SceneSelection.d.ts +0 -11
  85. package/dist/authoring/SceneSelection.js +0 -1
  86. package/dist/authoring/index.d.ts +0 -13
  87. package/dist/authoring/index.js +0 -13
  88. package/dist/commands/Command.d.ts +0 -63
  89. package/dist/commands/Command.js +0 -1
  90. package/dist/commands/CommandStack.d.ts +0 -14
  91. package/dist/commands/CommandStack.js +0 -45
  92. package/dist/commands/applyCommand.d.ts +0 -23
  93. package/dist/commands/applyCommand.js +0 -316
  94. package/dist/commands/index.d.ts +0 -4
  95. package/dist/commands/index.js +0 -4
  96. package/dist/commands/utils.d.ts +0 -17
  97. package/dist/commands/utils.js +0 -77
  98. package/dist/commands/validateCommand.d.ts +0 -12
  99. package/dist/commands/validateCommand.js +0 -285
  100. package/dist/nodes/Input.d.ts +0 -91
  101. package/dist/nodes/Input.js +0 -352
  102. package/dist/nodes/Textarea.d.ts +0 -10
  103. package/dist/nodes/Textarea.js +0 -38
  104. package/dist/nodes/components/Button.d.ts +0 -8
  105. package/dist/nodes/components/Button.js +0 -45
  106. package/dist/nodes/components/InputField.d.ts +0 -12
  107. package/dist/nodes/components/InputField.js +0 -53
  108. package/dist/nodes/components/ProgressBar.d.ts +0 -14
  109. package/dist/nodes/components/ProgressBar.js +0 -66
  110. package/dist/nodes/components/ScrollRect.d.ts +0 -23
  111. package/dist/nodes/components/ScrollRect.js +0 -108
  112. package/dist/nodes/components/Selectable.d.ts +0 -32
  113. package/dist/nodes/components/Selectable.js +0 -153
  114. package/dist/nodes/components/index.d.ts +0 -5
  115. package/dist/nodes/components/index.js +0 -5
  116. package/dist/nodes/graphics/Graphic.d.ts +0 -14
  117. package/dist/nodes/graphics/Graphic.js +0 -47
  118. package/dist/nodes/graphics/ImageGraphic.d.ts +0 -9
  119. package/dist/nodes/graphics/ImageGraphic.js +0 -42
  120. package/dist/nodes/graphics/RoundedRectGraphic.d.ts +0 -13
  121. package/dist/nodes/graphics/RoundedRectGraphic.js +0 -65
  122. package/dist/nodes/graphics/TextGraphic.d.ts +0 -13
  123. package/dist/nodes/graphics/TextGraphic.js +0 -70
  124. package/dist/nodes/graphics/index.d.ts +0 -4
  125. package/dist/nodes/graphics/index.js +0 -4
  126. package/dist/nodes/index.d.ts +0 -3
  127. package/dist/nodes/index.js +0 -3
  128. package/dist/runtime/Application.d.ts +0 -15
  129. package/dist/runtime/Application.js +0 -67
  130. package/dist/runtime/GameObject.d.ts +0 -100
  131. package/dist/runtime/GameObject.js +0 -297
  132. package/dist/runtime/GameObjectEvent.d.ts +0 -52
  133. package/dist/runtime/GameObjectEvent.js +0 -38
  134. package/dist/runtime/Transform.d.ts +0 -32
  135. package/dist/runtime/Transform.js +0 -157
  136. package/dist/runtime/component/Component.d.ts +0 -13
  137. package/dist/runtime/component/Component.js +0 -13
  138. package/dist/runtime/component/ComponentRegistry.d.ts +0 -49
  139. package/dist/runtime/component/ComponentRegistry.js +0 -25
  140. package/dist/runtime/component/Flex.d.ts +0 -6
  141. package/dist/runtime/component/Flex.js +0 -15
  142. package/dist/runtime/component/FlexGroup.d.ts +0 -26
  143. package/dist/runtime/component/FlexGroup.js +0 -136
  144. package/dist/runtime/component/GridLayout.d.ts +0 -47
  145. package/dist/runtime/component/GridLayout.js +0 -129
  146. package/dist/runtime/component/Layout.d.ts +0 -104
  147. package/dist/runtime/component/Layout.js +0 -248
  148. package/dist/runtime/component/decorators.d.ts +0 -4
  149. package/dist/runtime/component/decorators.js +0 -52
  150. package/dist/runtime/component/index.d.ts +0 -7
  151. package/dist/runtime/component/index.js +0 -7
  152. package/dist/runtime/graphics/index.d.ts +0 -11
  153. package/dist/runtime/graphics/index.js +0 -29
  154. package/dist/runtime/group/index.d.ts +0 -39
  155. package/dist/runtime/group/index.js +0 -102
  156. package/dist/runtime/image/Image.d.ts +0 -19
  157. package/dist/runtime/image/Image.js +0 -60
  158. package/dist/runtime/image/NineSliceImage.d.ts +0 -23
  159. package/dist/runtime/image/NineSliceImage.js +0 -64
  160. package/dist/runtime/image/index.d.ts +0 -2
  161. package/dist/runtime/image/index.js +0 -2
  162. package/dist/runtime/label/Label.d.ts +0 -11
  163. package/dist/runtime/label/Label.js +0 -26
  164. package/dist/runtime/label/LabelStyle.d.ts +0 -3
  165. package/dist/runtime/label/LabelStyle.js +0 -3
  166. package/dist/runtime/label/index.d.ts +0 -2
  167. package/dist/runtime/label/index.js +0 -2
  168. package/dist/runtime/utils/index.d.ts +0 -1
  169. package/dist/runtime/utils/index.js +0 -1
  170. package/dist/runtime/utils/onlyOnceQueueMicrotask.d.ts +0 -1
  171. package/dist/runtime/utils/onlyOnceQueueMicrotask.js +0 -12
  172. package/dist/runtime/utils/setProps.d.ts +0 -10
  173. package/dist/runtime/utils/setProps.js +0 -17
  174. package/dist/scene/dsl.d.ts +0 -25
  175. package/dist/scene/dsl.js +0 -112
  176. package/dist/scene/index.d.ts +0 -5
  177. package/dist/scene/index.js +0 -5
  178. package/dist/scene/instantiate.d.ts +0 -8
  179. package/dist/scene/instantiate.js +0 -208
  180. package/dist/scene/nodesDsl.d.ts +0 -42
  181. package/dist/scene/nodesDsl.js +0 -169
  182. package/dist/scene/spec.d.ts +0 -100
  183. package/dist/scene/spec.js +0 -1
  184. package/dist/scene/templates.d.ts +0 -21
  185. package/dist/scene/templates.js +0 -239
@@ -1,23 +0,0 @@
1
- import { NineSliceSprite, Texture } from "pixi.js";
2
- import { GameObject } from "../GameObject.js";
3
- export declare class NineSliceImage extends GameObject<NineSliceSprite> {
4
- private _texture;
5
- display: NineSliceSprite;
6
- protected _width: number;
7
- protected _height: number;
8
- /**
9
- * 这两个参数主要用于解决从来没有执行过resize或没有宽高进行赋值的情况下,使用默认纹理的宽高进行配置
10
- */
11
- private _isSetWidth;
12
- private _isSetHeight;
13
- get width(): number;
14
- set width(val: number);
15
- get height(): number;
16
- set height(val: number);
17
- /**
18
- * 背景纹理
19
- */
20
- get texture(): Texture;
21
- set texture(value: Texture);
22
- resize(): void;
23
- }
@@ -1,64 +0,0 @@
1
- import { NineSliceSprite, Texture } from "pixi.js";
2
- import { GameObject } from "../GameObject.js";
3
- export class NineSliceImage extends GameObject {
4
- _texture = new Texture();
5
- display = new NineSliceSprite(this._texture);
6
- _width = 0;
7
- _height = 0;
8
- /**
9
- * 这两个参数主要用于解决从来没有执行过resize或没有宽高进行赋值的情况下,使用默认纹理的宽高进行配置
10
- */
11
- _isSetWidth = false;
12
- _isSetHeight = false;
13
- // get width() {
14
- // return this.display.texture.orig.width;
15
- // }
16
- get width() {
17
- return this._width;
18
- }
19
- set width(val) {
20
- this._width = val;
21
- this._isSetWidth = true;
22
- this.display.width = val;
23
- this.refreshPivot();
24
- this.emitter.emit(GameObject.Event.RESIZE);
25
- }
26
- // get height() {
27
- // return this.display.texture.orig.height;
28
- // }
29
- get height() {
30
- return this._height;
31
- }
32
- set height(val) {
33
- this._height = val;
34
- this._isSetHeight = true;
35
- this.display.height = val;
36
- this.refreshPivot();
37
- this.emitter.emit(GameObject.Event.RESIZE);
38
- }
39
- /**
40
- * 背景纹理
41
- */
42
- get texture() {
43
- return this.display.texture;
44
- }
45
- set texture(value) {
46
- this.display.texture = value;
47
- if (this._isSetWidth) {
48
- this.display.width = this.width;
49
- }
50
- else {
51
- this._width = this.display.width;
52
- }
53
- if (this._isSetHeight) {
54
- this.display.height = this.height;
55
- }
56
- else {
57
- this._height = this.display.height;
58
- }
59
- }
60
- resize() {
61
- this.width = this.display.texture.width;
62
- this.height = this.display.texture.height;
63
- }
64
- }
@@ -1,2 +0,0 @@
1
- export * from './Image.js';
2
- export * from './NineSliceImage.js';
@@ -1,2 +0,0 @@
1
- export * from './Image.js';
2
- export * from './NineSliceImage.js';
@@ -1,11 +0,0 @@
1
- import { Text } from "pixi.js";
2
- import { LabelStyle } from "./LabelStyle.js";
3
- import { GameObject } from "../GameObject.js";
4
- export declare class Label extends GameObject {
5
- display: Text;
6
- get value(): string;
7
- set value(val: string);
8
- get style(): LabelStyle;
9
- set style(val: LabelStyle);
10
- resize(): void;
11
- }
@@ -1,26 +0,0 @@
1
- import { Text } from "pixi.js";
2
- import { GameObject } from "../GameObject.js";
3
- export class Label extends GameObject {
4
- display = new Text();
5
- // get width() {
6
- // return this._width;
7
- // }
8
- // set width() {
9
- // }
10
- get value() {
11
- return this.display.text;
12
- }
13
- set value(val) {
14
- this.display.text = val;
15
- }
16
- get style() {
17
- return this.display.style;
18
- }
19
- set style(val) {
20
- this.display.style = val;
21
- }
22
- resize() {
23
- this.width = this.display.width;
24
- this.height = this.display.height;
25
- }
26
- }
@@ -1,3 +0,0 @@
1
- import { TextStyle } from "pixi.js";
2
- export declare class LabelStyle extends TextStyle {
3
- }
@@ -1,3 +0,0 @@
1
- import { TextStyle } from "pixi.js";
2
- export class LabelStyle extends TextStyle {
3
- }
@@ -1,2 +0,0 @@
1
- export * from './Label.js';
2
- export * from './LabelStyle.js';
@@ -1,2 +0,0 @@
1
- export * from './Label.js';
2
- export * from './LabelStyle.js';
@@ -1 +0,0 @@
1
- export * from './setProps.js';
@@ -1 +0,0 @@
1
- export * from './setProps.js';
@@ -1 +0,0 @@
1
- export declare const onlyOnceQueueMicrotask: <TArgs extends unknown[]>(fn: (...args: TArgs) => void) => ((...args: TArgs) => void);
@@ -1,12 +0,0 @@
1
- export const onlyOnceQueueMicrotask = (fn) => {
2
- let run = false;
3
- return ((...args) => {
4
- if (!run) {
5
- run = true;
6
- queueMicrotask(() => {
7
- fn(...args);
8
- run = false;
9
- });
10
- }
11
- });
12
- };
@@ -1,10 +0,0 @@
1
- export type Props<T> = {
2
- [P in keyof T]?: Props<T[P]>;
3
- };
4
- /**
5
- * 快速设置
6
- * @param obj
7
- * @param props
8
- */
9
- export declare function setProps<T extends object>(obj: T, props: Partial<T>): T;
10
- export declare const sp: typeof setProps;
@@ -1,17 +0,0 @@
1
- /**
2
- * 快速设置
3
- * @param obj
4
- * @param props
5
- */
6
- export function setProps(obj, props) {
7
- for (let key in props) {
8
- const value = props[key];
9
- // if (typeof value === 'object') {
10
- // setProps(obj[key], value!);
11
- // continue;
12
- // }
13
- obj[key] = value;
14
- }
15
- return obj;
16
- }
17
- export const sp = setProps;
@@ -1,25 +0,0 @@
1
- import type { ComponentSpec, ContainerNodeSpec, ImageNodeSpec, InputNodeSpec, NodeSpec, RectTransformSpec, SceneSpec, ShapeNodeSpec, TextNodeSpec } from "./spec.js";
2
- export type NodeDslOptions = RectTransformSpec & {
3
- id?: string;
4
- key?: string;
5
- role?: string;
6
- components?: ComponentSpec[];
7
- };
8
- export type ContainerDslOptions = NodeDslOptions & {
9
- children?: NodeSpec[];
10
- };
11
- export type ImageDslOptions = NodeDslOptions & NonNullable<ImageNodeSpec['image']>;
12
- export type TextDslOptions = NodeDslOptions & NonNullable<TextNodeSpec['text']>;
13
- export type InputDslOptions = NodeDslOptions & NonNullable<InputNodeSpec['input']>;
14
- export type ShapeDslOptions = NodeDslOptions & NonNullable<ShapeNodeSpec['shape']>;
15
- export declare function scene(name: string, root: ContainerNodeSpec): SceneSpec;
16
- export declare function container(name: string, options?: ContainerDslOptions): ContainerNodeSpec;
17
- export declare function image(name: string, options?: ImageDslOptions): ImageNodeSpec;
18
- export declare function text(name: string, options?: TextDslOptions): TextNodeSpec;
19
- export declare function input(name: string, options?: InputDslOptions): InputNodeSpec;
20
- export declare function shape(name: string, options?: ShapeDslOptions): ShapeNodeSpec;
21
- export declare function component(type: string, props?: Record<string, unknown>, id?: string): ComponentSpec;
22
- export declare function ref(componentId: string, nodeId?: string): string | {
23
- node: string;
24
- component: string;
25
- };
package/dist/scene/dsl.js DELETED
@@ -1,112 +0,0 @@
1
- const transformKeys = new Set([
2
- 'x',
3
- 'y',
4
- 'width',
5
- 'height',
6
- 'anchorX',
7
- 'anchorY',
8
- 'scaleX',
9
- 'scaleY',
10
- 'rotation',
11
- ]);
12
- function splitNodeOptions(options) {
13
- const { id, key, role, components, ...rest } = options;
14
- const transform = {};
15
- const props = {};
16
- for (const [prop, value] of Object.entries(rest)) {
17
- if (transformKeys.has(prop)) {
18
- transform[prop] = value;
19
- }
20
- else {
21
- props[prop] = value;
22
- }
23
- }
24
- return { id, key, role, components, transform, props };
25
- }
26
- export function scene(name, root) {
27
- return {
28
- version: 1,
29
- type: 'scene',
30
- name,
31
- root,
32
- };
33
- }
34
- export function container(name, options = {}) {
35
- const { children, } = options;
36
- const { id, key, role, components, transform } = splitNodeOptions(options);
37
- return {
38
- id,
39
- key,
40
- role,
41
- name,
42
- kind: 'container',
43
- transform,
44
- components,
45
- children,
46
- };
47
- }
48
- export function image(name, options = {}) {
49
- const { id, key, role, components, transform, props } = splitNodeOptions(options);
50
- return {
51
- id,
52
- key,
53
- role,
54
- name,
55
- kind: 'image',
56
- transform,
57
- components,
58
- image: props,
59
- };
60
- }
61
- export function text(name, options = {}) {
62
- const { id, key, role, components, transform, props } = splitNodeOptions(options);
63
- return {
64
- id,
65
- key,
66
- role,
67
- name,
68
- kind: 'text',
69
- transform,
70
- components,
71
- text: props,
72
- };
73
- }
74
- export function input(name, options = {}) {
75
- const { id, key, role, components, transform, props } = splitNodeOptions(options);
76
- return {
77
- id,
78
- key,
79
- role,
80
- name,
81
- kind: 'input',
82
- transform,
83
- components,
84
- input: props,
85
- };
86
- }
87
- export function shape(name, options = {}) {
88
- const { id, key, role, components, transform, props } = splitNodeOptions(options);
89
- return {
90
- id,
91
- key,
92
- role,
93
- name,
94
- kind: 'shape',
95
- transform,
96
- components,
97
- shape: props,
98
- };
99
- }
100
- export function component(type, props, id) {
101
- return {
102
- id,
103
- type,
104
- props,
105
- };
106
- }
107
- export function ref(componentId, nodeId) {
108
- if (!nodeId) {
109
- return componentId;
110
- }
111
- return { node: nodeId, component: componentId };
112
- }
@@ -1,5 +0,0 @@
1
- export * from './spec.js';
2
- export * from './instantiate.js';
3
- export * from './dsl.js';
4
- export * from './nodesDsl.js';
5
- export * from './templates.js';
@@ -1,5 +0,0 @@
1
- export * from './spec.js';
2
- export * from './instantiate.js';
3
- export * from './dsl.js';
4
- export * from './nodesDsl.js';
5
- export * from './templates.js';
@@ -1,8 +0,0 @@
1
- import { Group } from "../runtime/index.js";
2
- import { Input } from "../nodes/Input.js";
3
- import type { InstantiateContext, InstantiateResult, NodeSpec, SceneSpec } from "./spec.js";
4
- import "../nodes/graphics/index.js";
5
- type SceneRuntimeNode = Group | Input;
6
- export declare function instantiateScene(scene: SceneSpec | NodeSpec, parent?: Group, context?: InstantiateContext): InstantiateResult<SceneRuntimeNode>;
7
- export declare const instantiate: typeof instantiateScene;
8
- export {};
@@ -1,208 +0,0 @@
1
- import { GameObject, Group } from "../runtime/index.js";
2
- import { ComponentRegistry } from "../runtime/component/ComponentRegistry.js";
3
- import { Input } from "../nodes/Input.js";
4
- import "../nodes/graphics/index.js";
5
- function indexNode(map, node, spec) {
6
- if (spec.key) {
7
- map.set(spec.key, node);
8
- }
9
- if (spec.id) {
10
- map.set(spec.id, node);
11
- }
12
- if (spec.name) {
13
- map.set(spec.name, node);
14
- }
15
- }
16
- function applyTransform(node, spec) {
17
- const transform = spec.transform;
18
- if (!transform) {
19
- return;
20
- }
21
- if (transform.width !== undefined)
22
- node.width = transform.width;
23
- if (transform.height !== undefined)
24
- node.height = transform.height;
25
- if (transform.x !== undefined)
26
- node.x = transform.x;
27
- if (transform.y !== undefined)
28
- node.y = transform.y;
29
- if (transform.anchorX !== undefined)
30
- node.anchorX = transform.anchorX;
31
- if (transform.anchorY !== undefined)
32
- node.anchorY = transform.anchorY;
33
- if (transform.scaleX !== undefined)
34
- node.scaleX = transform.scaleX;
35
- if (transform.scaleY !== undefined)
36
- node.scaleY = transform.scaleY;
37
- if (transform.rotation !== undefined)
38
- node.rotation = transform.rotation;
39
- }
40
- function resolveComponentRef(value, nodes, components) {
41
- if (typeof value === 'string') {
42
- return components.get(value) ?? nodes.get(value) ?? value;
43
- }
44
- if (!value || typeof value !== 'object') {
45
- return value;
46
- }
47
- const ref = value;
48
- if (!ref.component) {
49
- return value;
50
- }
51
- if (ref.node) {
52
- return components.get(`${ref.node}:${ref.component}`) ?? components.get(ref.component) ?? value;
53
- }
54
- return components.get(ref.component) ?? value;
55
- }
56
- function resolveEvent(value, context) {
57
- if (typeof value !== 'string') {
58
- return value;
59
- }
60
- return context?.actions?.[value] ?? value;
61
- }
62
- function addComponentFromSpec(node, spec, components, pendingProps, nodeIds) {
63
- const schema = ComponentRegistry.get(spec.type);
64
- if (!schema) {
65
- throw new Error(`Unknown component type "${spec.type}".`);
66
- }
67
- const initialProps = {};
68
- for (const prop of schema.props) {
69
- if (prop.default !== undefined) {
70
- initialProps[prop.key] = prop.default;
71
- }
72
- }
73
- for (const [key, value] of Object.entries(spec.props ?? {})) {
74
- const prop = schema.props.find((candidate) => candidate.key === key);
75
- if (prop?.type === 'componentRef' || prop?.type === 'nodeRef' || prop?.type === 'event') {
76
- continue;
77
- }
78
- initialProps[key] = value;
79
- }
80
- const component = node.addComponent(schema.ctor, initialProps);
81
- if (spec.id) {
82
- components.set(spec.id, component);
83
- for (const nodeId of nodeIds) {
84
- components.set(`${nodeId}:${spec.id}`, component);
85
- }
86
- }
87
- for (const [key, value] of Object.entries(spec.props ?? {})) {
88
- const prop = schema.props.find((candidate) => candidate.key === key);
89
- if (prop?.type === 'componentRef' || prop?.type === 'nodeRef' || prop?.type === 'event') {
90
- pendingProps.push({ component, key, value });
91
- }
92
- }
93
- return component;
94
- }
95
- function rendererId(spec, fallback) {
96
- return spec.id ?? spec.key ?? spec.name ?? fallback;
97
- }
98
- function applyTextNode(node, spec, components, pendingProps, nodeIds) {
99
- addComponentFromSpec(node, {
100
- id: rendererId(spec, 'text'),
101
- type: 'ui.TextGraphic',
102
- props: {
103
- text: spec.text?.value ?? '',
104
- color: spec.text?.color ?? 0x000000,
105
- fontSize: spec.text?.fontSize ?? 14,
106
- fontFamily: spec.text?.fontFamily ?? 'Arial',
107
- fontWeight: spec.text?.fontWeight ?? 'normal',
108
- center: spec.text?.center ?? false,
109
- },
110
- }, components, pendingProps, nodeIds);
111
- }
112
- function applyImageNode(node, spec, components, pendingProps, nodeIds) {
113
- addComponentFromSpec(node, {
114
- id: rendererId(spec, 'image'),
115
- type: 'ui.ImageGraphic',
116
- props: {
117
- src: spec.image?.src ?? '',
118
- tint: spec.image?.tint ?? 0xffffff,
119
- },
120
- }, components, pendingProps, nodeIds);
121
- }
122
- function applyShapeNode(node, spec, components, pendingProps, nodeIds) {
123
- addComponentFromSpec(node, {
124
- id: rendererId(spec, 'shape'),
125
- type: 'ui.RoundedRectGraphic',
126
- props: {
127
- color: spec.shape?.color ?? 0xffffff,
128
- fillAlpha: spec.shape?.fillAlpha ?? 1,
129
- radius: spec.shape?.type === 'rect' ? 0 : spec.shape?.radius ?? 0,
130
- strokeColor: spec.shape?.strokeColor ?? 0x000000,
131
- strokeWidth: spec.shape?.strokeWidth ?? 0,
132
- strokeAlpha: spec.shape?.strokeAlpha ?? 1,
133
- },
134
- }, components, pendingProps, nodeIds);
135
- }
136
- function applyInputNode(node, spec) {
137
- if (!spec.input) {
138
- return;
139
- }
140
- if (spec.input.value !== undefined)
141
- node.value = spec.input.value;
142
- if (spec.input.backgroundColor !== undefined)
143
- node.backgroundColor = spec.input.backgroundColor;
144
- if (spec.input.borderColor !== undefined)
145
- node.borderColor = spec.input.borderColor;
146
- if (spec.input.borderSize !== undefined)
147
- node.borderSize = spec.input.borderSize;
148
- if (spec.input.fontSize !== undefined)
149
- node.fontSize = spec.input.fontSize;
150
- if (spec.input.fontFamily !== undefined)
151
- node.fontFamily = spec.input.fontFamily;
152
- if (spec.input.paddingLeft !== undefined)
153
- node.paddingLeft = spec.input.paddingLeft;
154
- if (spec.input.paddingRight !== undefined)
155
- node.paddingRight = spec.input.paddingRight;
156
- if (spec.input.paddingTop !== undefined)
157
- node.paddingTop = spec.input.paddingTop;
158
- if (spec.input.paddingBottom !== undefined)
159
- node.paddingBottom = spec.input.paddingBottom;
160
- }
161
- function instantiateNode(spec, parent, nodes, components, pendingProps) {
162
- const node = GameObject.instantiate(spec.kind === 'input' ? Input : Group, parent);
163
- const nodeIds = [spec.id, spec.key, spec.name].filter((value) => !!value);
164
- indexNode(nodes, node, spec);
165
- applyTransform(node, spec);
166
- switch (spec.kind) {
167
- case 'image':
168
- applyImageNode(node, spec, components, pendingProps, nodeIds);
169
- break;
170
- case 'text':
171
- applyTextNode(node, spec, components, pendingProps, nodeIds);
172
- break;
173
- case 'shape':
174
- applyShapeNode(node, spec, components, pendingProps, nodeIds);
175
- break;
176
- case 'input':
177
- applyInputNode(node, spec);
178
- break;
179
- }
180
- for (const componentSpec of spec.components ?? []) {
181
- addComponentFromSpec(node, componentSpec, components, pendingProps, nodeIds);
182
- }
183
- if (spec.kind === 'container') {
184
- for (const childSpec of spec.children ?? []) {
185
- instantiateNode(childSpec, node, nodes, components, pendingProps);
186
- }
187
- }
188
- return node;
189
- }
190
- export function instantiateScene(scene, parent, context) {
191
- const rootSpec = 'root' in scene ? scene.root : scene;
192
- const nodes = new Map();
193
- const components = new Map();
194
- const pendingProps = [];
195
- const root = instantiateNode(rootSpec, parent, nodes, components, pendingProps);
196
- for (const item of pendingProps) {
197
- const schema = ComponentRegistry.getByCtor(item.component.constructor);
198
- const prop = schema?.props.find((candidate) => candidate.key === item.key);
199
- const value = prop?.type === 'componentRef' || prop?.type === 'nodeRef'
200
- ? resolveComponentRef(item.value, nodes, components)
201
- : prop?.type === 'event'
202
- ? resolveEvent(item.value, context)
203
- : item.value;
204
- item.component[item.key] = value;
205
- }
206
- return { root, nodes, components };
207
- }
208
- export const instantiate = instantiateScene;
@@ -1,42 +0,0 @@
1
- import type { ContainerNodeSpec } from "./spec.js";
2
- export declare function buttonScene(name: string, options?: {
3
- id?: string;
4
- key?: string;
5
- role?: string;
6
- x?: number;
7
- y?: number;
8
- width?: number;
9
- height?: number;
10
- label?: string;
11
- color?: number;
12
- textColor?: number;
13
- radius?: number;
14
- onClick?: string;
15
- }): ContainerNodeSpec;
16
- export declare function progressBarScene(name: string, options?: {
17
- id?: string;
18
- key?: string;
19
- role?: string;
20
- x?: number;
21
- y?: number;
22
- width?: number;
23
- height?: number;
24
- value?: number;
25
- min?: number;
26
- max?: number;
27
- backgroundColor?: number;
28
- fillColor?: number;
29
- radius?: number;
30
- }): ContainerNodeSpec;
31
- export declare function scrollViewScene(name: string, options?: {
32
- id?: string;
33
- key?: string;
34
- role?: string;
35
- x?: number;
36
- y?: number;
37
- width?: number;
38
- height?: number;
39
- contentHeight?: number;
40
- wheelSensitivity?: number;
41
- dragEnabled?: boolean;
42
- }): ContainerNodeSpec;