pixifact 0.1.4 → 0.2.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 (74) hide show
  1. package/dist/compiler/builtinScenes.d.ts +2 -2
  2. package/dist/compiler/builtinScenes.js +1 -9
  3. package/dist/compiler/compileScenes.js +16 -0
  4. package/dist/compiler/pixiNodeSchema.d.ts +17 -7
  5. package/dist/compiler/pixiNodeSchema.js +219 -0
  6. package/dist/compiler/sceneValidation.js +13 -2
  7. package/dist/compiler/spec.d.ts +5 -1
  8. package/dist/compiler/templateParser.js +18 -10
  9. package/dist/compiler/templateSerializer.js +1 -0
  10. package/dist/compiler/typescriptCompiler.js +53 -8
  11. package/dist/project/index.d.ts +5 -0
  12. package/dist/project/index.js +22 -0
  13. package/dist/runtime/Control.d.ts +18 -0
  14. package/dist/runtime/Control.js +49 -0
  15. package/dist/runtime/GridContainer.d.ts +25 -0
  16. package/dist/runtime/GridContainer.js +115 -0
  17. package/dist/runtime/Group.d.ts +2 -0
  18. package/dist/runtime/Group.js +30 -10
  19. package/dist/runtime/HBoxContainer.d.ts +21 -0
  20. package/dist/runtime/HBoxContainer.js +74 -0
  21. package/dist/runtime/Image.d.ts +47 -0
  22. package/dist/runtime/Image.js +220 -0
  23. package/dist/runtime/NineImage.d.ts +22 -0
  24. package/dist/runtime/NineImage.js +54 -0
  25. package/dist/runtime/Rect.d.ts +48 -0
  26. package/dist/runtime/Rect.js +162 -0
  27. package/dist/runtime/ScrollContainer.d.ts +28 -0
  28. package/dist/runtime/ScrollContainer.js +370 -0
  29. package/dist/runtime/TileImage.d.ts +27 -0
  30. package/dist/runtime/TileImage.js +57 -0
  31. package/dist/runtime/VBoxContainer.d.ts +21 -0
  32. package/dist/runtime/VBoxContainer.js +74 -0
  33. package/dist/runtime/frameLayout.d.ts +11 -0
  34. package/dist/runtime/frameLayout.js +116 -0
  35. package/dist/runtime/frameLayoutAccessors.d.ts +4 -0
  36. package/dist/runtime/frameLayoutAccessors.js +7 -0
  37. package/dist/runtime/index.d.ts +12 -0
  38. package/dist/runtime/index.js +12 -0
  39. package/dist/runtime/stackLayout.d.ts +16 -0
  40. package/dist/runtime/stackLayout.js +59 -0
  41. package/dist/viewport.d.ts +43 -0
  42. package/dist/viewport.js +93 -0
  43. package/package.json +2 -2
  44. package/dist/builtin-scenes/CenterContainer.d.ts +0 -13
  45. package/dist/builtin-scenes/CenterContainer.js +0 -71
  46. package/dist/builtin-scenes/CenterContainer.scene +0 -3
  47. package/dist/builtin-scenes/CenterContainer.ts +0 -77
  48. package/dist/builtin-scenes/Control.d.ts +0 -44
  49. package/dist/builtin-scenes/Control.js +0 -206
  50. package/dist/builtin-scenes/Control.scene +0 -3
  51. package/dist/builtin-scenes/Control.ts +0 -233
  52. package/dist/builtin-scenes/FlexItem.d.ts +0 -45
  53. package/dist/builtin-scenes/FlexItem.js +0 -164
  54. package/dist/builtin-scenes/FlexItem.scene +0 -3
  55. package/dist/builtin-scenes/FlexItem.ts +0 -180
  56. package/dist/builtin-scenes/FlexLayout.d.ts +0 -29
  57. package/dist/builtin-scenes/FlexLayout.js +0 -358
  58. package/dist/builtin-scenes/FlexLayout.scene +0 -3
  59. package/dist/builtin-scenes/FlexLayout.ts +0 -409
  60. package/dist/builtin-scenes/HBoxContainer.d.ts +0 -15
  61. package/dist/builtin-scenes/HBoxContainer.js +0 -70
  62. package/dist/builtin-scenes/HBoxContainer.scene +0 -3
  63. package/dist/builtin-scenes/HBoxContainer.ts +0 -75
  64. package/dist/builtin-scenes/MarginContainer.d.ts +0 -23
  65. package/dist/builtin-scenes/MarginContainer.js +0 -131
  66. package/dist/builtin-scenes/MarginContainer.scene +0 -3
  67. package/dist/builtin-scenes/MarginContainer.ts +0 -139
  68. package/dist/builtin-scenes/VBoxContainer.d.ts +0 -15
  69. package/dist/builtin-scenes/VBoxContainer.js +0 -70
  70. package/dist/builtin-scenes/VBoxContainer.scene +0 -3
  71. package/dist/builtin-scenes/VBoxContainer.ts +0 -75
  72. package/dist/builtin-scenes/controlLayout.d.ts +0 -57
  73. package/dist/builtin-scenes/controlLayout.js +0 -202
  74. package/dist/builtin-scenes/controlLayout.ts +0 -270
@@ -1 +1,13 @@
1
1
  export * from './Group.js';
2
+ export * from './Control.js';
3
+ export * from './Rect.js';
4
+ export * from './Image.js';
5
+ export * from './NineImage.js';
6
+ export * from './TileImage.js';
7
+ export * from './frameLayout.js';
8
+ export * from './GridContainer.js';
9
+ export * from './HBoxContainer.js';
10
+ export * from './ScrollContainer.js';
11
+ export * from './VBoxContainer.js';
12
+ export * from './stackLayout.js';
13
+ export * from '../viewport.js';
@@ -1 +1,13 @@
1
1
  export * from './Group.js';
2
+ export * from './Control.js';
3
+ export * from './Rect.js';
4
+ export * from './Image.js';
5
+ export * from './NineImage.js';
6
+ export * from './TileImage.js';
7
+ export * from './frameLayout.js';
8
+ export * from './GridContainer.js';
9
+ export * from './HBoxContainer.js';
10
+ export * from './ScrollContainer.js';
11
+ export * from './VBoxContainer.js';
12
+ export * from './stackLayout.js';
13
+ export * from '../viewport.js';
@@ -0,0 +1,16 @@
1
+ import type { ContainerChild } from 'pixi.js';
2
+ export type StackAlign = 'start' | 'center' | 'end';
3
+ export type StackJustify = 'start' | 'center' | 'end' | 'space-between';
4
+ export type StackAxis = 'horizontal' | 'vertical';
5
+ export interface StackSize {
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export declare function finiteNumber(value: number, fallback: number): number;
10
+ export declare function parseStackAlign(value: string): StackAlign;
11
+ export declare function parseStackJustify(value: string): StackJustify;
12
+ export declare function stackAlignOffset(align: StackAlign, available: number): number;
13
+ export declare function stackJustifyOffset(justify: StackJustify, available: number): number;
14
+ export declare function stackChildSize(child: ContainerChild): StackSize;
15
+ export declare function measureStackNaturalSize(axis: StackAxis, children: readonly ContainerChild[], gap: number): StackSize;
16
+ export declare function layoutChild(child: ContainerChild): void;
@@ -0,0 +1,59 @@
1
+ export function finiteNumber(value, fallback) {
2
+ return Number.isFinite(value) ? value : fallback;
3
+ }
4
+ export function parseStackAlign(value) {
5
+ if (value === 'center' || value === 'end') {
6
+ return value;
7
+ }
8
+ return 'start';
9
+ }
10
+ export function parseStackJustify(value) {
11
+ if (value === 'center' || value === 'end' || value === 'space-between') {
12
+ return value;
13
+ }
14
+ return 'start';
15
+ }
16
+ export function stackAlignOffset(align, available) {
17
+ if (align === 'center') {
18
+ return available / 2;
19
+ }
20
+ if (align === 'end') {
21
+ return available;
22
+ }
23
+ return 0;
24
+ }
25
+ export function stackJustifyOffset(justify, available) {
26
+ if (justify === 'center') {
27
+ return available / 2;
28
+ }
29
+ if (justify === 'end') {
30
+ return available;
31
+ }
32
+ return 0;
33
+ }
34
+ export function stackChildSize(child) {
35
+ return {
36
+ width: child.width,
37
+ height: child.height,
38
+ };
39
+ }
40
+ export function measureStackNaturalSize(axis, children, gap) {
41
+ if (children.length === 0) {
42
+ return { width: 0, height: 0 };
43
+ }
44
+ const gapTotal = gap * Math.max(0, children.length - 1);
45
+ const sizes = children.map(stackChildSize);
46
+ if (axis === 'horizontal') {
47
+ return {
48
+ width: sizes.reduce((sum, size) => sum + size.width, 0) + gapTotal,
49
+ height: sizes.reduce((max, size) => Math.max(max, size.height), 0),
50
+ };
51
+ }
52
+ return {
53
+ width: sizes.reduce((max, size) => Math.max(max, size.width), 0),
54
+ height: sizes.reduce((sum, size) => sum + size.height, 0) + gapTotal,
55
+ };
56
+ }
57
+ export function layoutChild(child) {
58
+ child.layout?.();
59
+ }
@@ -0,0 +1,43 @@
1
+ export declare const pixifactViewportModes: readonly ["showAll", "cover", "fixedWidth", "fixedHeight"];
2
+ export type PixifactViewportMode = typeof pixifactViewportModes[number];
3
+ export interface PixifactViewportConfig {
4
+ mode: PixifactViewportMode;
5
+ }
6
+ export interface PixifactViewportSize {
7
+ width: number;
8
+ height: number;
9
+ }
10
+ export interface PixifactViewportPoint {
11
+ x: number;
12
+ y: number;
13
+ }
14
+ export interface PixifactViewportRect extends PixifactViewportPoint, PixifactViewportSize {
15
+ }
16
+ export interface PixifactViewportLayout {
17
+ mode: PixifactViewportMode;
18
+ resolution: PixifactViewportSize;
19
+ screen: PixifactViewportSize;
20
+ scene: PixifactViewportSize;
21
+ visibleRect: PixifactViewportRect;
22
+ scale: number;
23
+ offset: PixifactViewportPoint;
24
+ }
25
+ export interface PixifactViewportLayoutTarget {
26
+ root: {
27
+ setSize(width: number, height: number): void;
28
+ };
29
+ stage: {
30
+ position: {
31
+ set(x: number, y: number): void;
32
+ };
33
+ scale: {
34
+ set(x: number, y?: number): void;
35
+ };
36
+ };
37
+ }
38
+ export declare function calculatePixifactViewportLayout(options: {
39
+ mode: PixifactViewportMode;
40
+ resolution: PixifactViewportSize;
41
+ screen: PixifactViewportSize;
42
+ }): PixifactViewportLayout;
43
+ export declare function applyPixifactViewportLayout(target: PixifactViewportLayoutTarget, layout: PixifactViewportLayout): void;
@@ -0,0 +1,93 @@
1
+ export const pixifactViewportModes = [
2
+ 'showAll',
3
+ 'cover',
4
+ 'fixedWidth',
5
+ 'fixedHeight',
6
+ ];
7
+ export function calculatePixifactViewportLayout(options) {
8
+ const { mode, resolution, screen } = options;
9
+ if (mode === 'showAll') {
10
+ const scale = Math.min(screen.width / resolution.width, screen.height / resolution.height);
11
+ return {
12
+ mode,
13
+ resolution,
14
+ screen,
15
+ scene: { ...resolution },
16
+ visibleRect: { x: 0, y: 0, ...resolution },
17
+ scale,
18
+ offset: centeredOffset(resolution, screen, scale),
19
+ };
20
+ }
21
+ if (mode === 'cover') {
22
+ const scale = Math.max(screen.width / resolution.width, screen.height / resolution.height);
23
+ const visibleRect = centeredVisibleRect(resolution, screen, scale);
24
+ return {
25
+ mode,
26
+ resolution,
27
+ screen,
28
+ scene: { ...resolution },
29
+ visibleRect,
30
+ scale,
31
+ offset: {
32
+ x: cleanZero(-visibleRect.x * scale),
33
+ y: cleanZero(-visibleRect.y * scale),
34
+ },
35
+ };
36
+ }
37
+ if (mode === 'fixedWidth') {
38
+ const scale = screen.width / resolution.width;
39
+ const scene = {
40
+ width: resolution.width,
41
+ height: screen.height / scale,
42
+ };
43
+ return fixedViewportLayout(mode, resolution, screen, scene, scale);
44
+ }
45
+ const scale = screen.height / resolution.height;
46
+ const scene = {
47
+ width: screen.width / scale,
48
+ height: resolution.height,
49
+ };
50
+ return fixedViewportLayout(mode, resolution, screen, scene, scale);
51
+ }
52
+ export function applyPixifactViewportLayout(target, layout) {
53
+ target.root.setSize(layout.scene.width, layout.scene.height);
54
+ target.stage.position.set(layout.offset.x, layout.offset.y);
55
+ target.stage.scale.set(layout.scale, layout.scale);
56
+ }
57
+ function fixedViewportLayout(mode, resolution, screen, scene, scale) {
58
+ return {
59
+ mode,
60
+ resolution,
61
+ screen,
62
+ scene,
63
+ visibleRect: {
64
+ x: 0,
65
+ y: 0,
66
+ ...scene,
67
+ },
68
+ scale,
69
+ offset: {
70
+ x: 0,
71
+ y: 0,
72
+ },
73
+ };
74
+ }
75
+ function centeredOffset(scene, screen, scale) {
76
+ return {
77
+ x: cleanZero((screen.width - scene.width * scale) / 2),
78
+ y: cleanZero((screen.height - scene.height * scale) / 2),
79
+ };
80
+ }
81
+ function centeredVisibleRect(resolution, screen, scale) {
82
+ const width = screen.width / scale;
83
+ const height = screen.height / scale;
84
+ return {
85
+ x: cleanZero((resolution.width - width) / 2),
86
+ y: cleanZero((resolution.height - height) / 2),
87
+ width,
88
+ height,
89
+ };
90
+ }
91
+ function cleanZero(value) {
92
+ return Object.is(value, -0) ? 0 : value;
93
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixifact",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Pixifact 2D UI 和轻量游戏 Scene 语义框架。",
5
5
  "packageManager": "bun@1.3.13",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "author": "youxia <243802688@qq.com>",
27
27
  "license": "MIT",
28
28
  "scripts": {
29
- "build": "bun scripts/clean-dist.mjs && bunx --no-install tsc -p tsconfig.build.json && bun scripts/fix-dist-esm-imports.mjs && bun scripts/copy-scene-assets.mjs"
29
+ "build": "bun scripts/clean-dist.mjs && bunx --no-install tsc -p tsconfig.build.json && bun scripts/fix-dist-esm-imports.mjs"
30
30
  },
31
31
  "publishConfig": {
32
32
  "registry": "https://registry.npmjs.org/"
@@ -1,13 +0,0 @@
1
- import { Container } from 'pixi.js';
2
- import { Control } from './Control.js';
3
- import { type Size } from './controlLayout.js';
4
- export declare class CenterContainer extends Control {
5
- #private;
6
- readonly default: Container;
7
- get alignX(): string;
8
- set alignX(value: string);
9
- get alignY(): string;
10
- set alignY(value: string);
11
- layout(): void;
12
- measureControlNaturalSize(): Size;
13
- }
@@ -1,71 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { prop, scene, slot } from 'pixifact/compiler';
8
- import { Control } from './Control.js';
9
- import { alignOffset, controlChildProps, controlMinSize, fillOrExpand, parseAlign, setControlChildBox, } from './controlLayout.js';
10
- let CenterContainer = class CenterContainer extends Control {
11
- #alignX = 'center';
12
- #alignY = 'center';
13
- #baseSizes = new WeakMap();
14
- get alignX() {
15
- return this.#alignX;
16
- }
17
- set alignX(value) {
18
- this.#alignX = parseAlign(value);
19
- this.layout();
20
- }
21
- get alignY() {
22
- return this.#alignY;
23
- }
24
- set alignY(value) {
25
- this.#alignY = parseAlign(value);
26
- this.layout();
27
- }
28
- layout() {
29
- const size = this.syncControlBoxSize();
30
- const children = this.default?.children;
31
- if (!children || children.length === 0) {
32
- return;
33
- }
34
- for (const child of children) {
35
- const props = controlChildProps(child);
36
- const childSize = controlMinSize(child, this.#baseSizes);
37
- const childWidth = fillOrExpand(props.hSize) ? size.width : childSize.width;
38
- const childHeight = fillOrExpand(props.vSize) ? size.height : childSize.height;
39
- setControlChildBox(child, {
40
- x: alignOffset(this.#alignX, Math.max(0, size.width - childWidth)),
41
- y: alignOffset(this.#alignY, Math.max(0, size.height - childHeight)),
42
- width: childWidth,
43
- height: childHeight,
44
- });
45
- }
46
- }
47
- measureControlNaturalSize() {
48
- const children = this.default?.children;
49
- if (!children || children.length === 0) {
50
- return { width: 0, height: 0 };
51
- }
52
- const sizes = children.map((child) => controlMinSize(child, this.#baseSizes));
53
- return {
54
- width: sizes.reduce((max, size) => Math.max(max, size.width), 0),
55
- height: sizes.reduce((max, size) => Math.max(max, size.height), 0),
56
- };
57
- }
58
- };
59
- __decorate([
60
- slot()
61
- ], CenterContainer.prototype, "default", void 0);
62
- __decorate([
63
- prop({ type: String, default: 'center' })
64
- ], CenterContainer.prototype, "alignX", null);
65
- __decorate([
66
- prop({ type: String, default: 'center' })
67
- ], CenterContainer.prototype, "alignY", null);
68
- CenterContainer = __decorate([
69
- scene()
70
- ], CenterContainer);
71
- export { CenterContainer };
@@ -1,3 +0,0 @@
1
- <Scene name="CenterContainer">
2
- <slot name="default" />
3
- </Scene>
@@ -1,77 +0,0 @@
1
- import { Container } from 'pixi.js';
2
- import { prop, scene, slot } from 'pixifact/compiler';
3
- import { Control } from './Control';
4
- import {
5
- alignOffset,
6
- controlChildProps,
7
- controlMinSize,
8
- fillOrExpand,
9
- parseAlign,
10
- setControlChildBox,
11
- type ControlAlign,
12
- type ControlLayoutChild,
13
- type Size,
14
- } from './controlLayout';
15
-
16
- @scene()
17
- export class CenterContainer extends Control {
18
- @slot()
19
- declare readonly default: Container;
20
-
21
- #alignX: ControlAlign = 'center';
22
- #alignY: ControlAlign = 'center';
23
- #baseSizes = new WeakMap<object, Size>();
24
-
25
- get alignX() {
26
- return this.#alignX;
27
- }
28
-
29
- @prop({ type: String, default: 'center' })
30
- set alignX(value: string) {
31
- this.#alignX = parseAlign(value);
32
- this.layout();
33
- }
34
-
35
- get alignY() {
36
- return this.#alignY;
37
- }
38
-
39
- @prop({ type: String, default: 'center' })
40
- set alignY(value: string) {
41
- this.#alignY = parseAlign(value);
42
- this.layout();
43
- }
44
-
45
- override layout() {
46
- const size = this.syncControlBoxSize();
47
- const children = this.default?.children as ControlLayoutChild[] | undefined;
48
- if (!children || children.length === 0) {
49
- return;
50
- }
51
-
52
- for (const child of children) {
53
- const props = controlChildProps(child);
54
- const childSize = controlMinSize(child, this.#baseSizes);
55
- const childWidth = fillOrExpand(props.hSize) ? size.width : childSize.width;
56
- const childHeight = fillOrExpand(props.vSize) ? size.height : childSize.height;
57
- setControlChildBox(child, {
58
- x: alignOffset(this.#alignX, Math.max(0, size.width - childWidth)),
59
- y: alignOffset(this.#alignY, Math.max(0, size.height - childHeight)),
60
- width: childWidth,
61
- height: childHeight,
62
- });
63
- }
64
- }
65
-
66
- override measureControlNaturalSize(): Size {
67
- const children = this.default?.children as ControlLayoutChild[] | undefined;
68
- if (!children || children.length === 0) {
69
- return { width: 0, height: 0 };
70
- }
71
- const sizes = children.map((child) => controlMinSize(child, this.#baseSizes));
72
- return {
73
- width: sizes.reduce((max, size) => Math.max(max, size.width), 0),
74
- height: sizes.reduce((max, size) => Math.max(max, size.height), 0),
75
- };
76
- }
77
- }
@@ -1,44 +0,0 @@
1
- import { Container } from 'pixi.js';
2
- import { Group } from 'pixifact/runtime';
3
- import { type ControlLayoutProps, type Size } from './controlLayout.js';
4
- export declare class Control extends Group {
5
- #private;
6
- readonly default: Container;
7
- get width(): number;
8
- set width(value: number);
9
- get height(): number;
10
- set height(value: number);
11
- getSize(out?: Size): Size;
12
- setSize(value: number | {
13
- width: number;
14
- height?: number;
15
- }, height?: number): void;
16
- get minWidth(): number;
17
- set minWidth(value: number);
18
- get minHeight(): number;
19
- set minHeight(value: number);
20
- get hSize(): string;
21
- set hSize(value: string);
22
- get vSize(): string;
23
- set vSize(value: string);
24
- get stretch(): number;
25
- set stretch(value: number);
26
- get alignX(): string;
27
- set alignX(value: string);
28
- get alignY(): string;
29
- set alignY(value: string);
30
- onMounted(): void;
31
- getControlLayoutProps(): ControlLayoutProps;
32
- measureControlNaturalSize(): Size;
33
- setControlLayoutBox(x: number, y: number, width: number, height: number): void;
34
- layout(): void;
35
- protected layoutDefaultSlot(size?: Size): void;
36
- protected syncControlBoxSize(): Size;
37
- protected getControlBoxSize(): Size;
38
- protected getAssignedControlBoxSize(): {
39
- width: number | undefined;
40
- height: number | undefined;
41
- };
42
- protected refreshControlLayout(): void;
43
- protected requestParentLayout(): void;
44
- }
@@ -1,206 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { prop, scene, slot } from 'pixifact/compiler';
8
- import { Group } from 'pixifact/runtime';
9
- import { alignOffset, boxSize, defaultControlLayoutProps, finiteNumber, measureChildren, measureChildrenBounds, parseAlign, parseSizeMode, } from './controlLayout.js';
10
- let Control = class Control extends Group {
11
- default;
12
- #explicitWidth;
13
- #explicitHeight;
14
- #layoutWidth;
15
- #layoutHeight;
16
- #minWidth = 0;
17
- #minHeight = 0;
18
- #hSize = 'content';
19
- #vSize = 'content';
20
- #stretch = 1;
21
- #alignX = 'start';
22
- #alignY = 'start';
23
- get width() {
24
- return this.getControlBoxSize().width;
25
- }
26
- set width(value) {
27
- this.#explicitWidth = Math.max(0, finiteNumber(value, 0));
28
- this.refreshControlLayout();
29
- }
30
- get height() {
31
- return this.getControlBoxSize().height;
32
- }
33
- set height(value) {
34
- this.#explicitHeight = Math.max(0, finiteNumber(value, 0));
35
- this.refreshControlLayout();
36
- }
37
- getSize(out = { width: 0, height: 0 }) {
38
- out.width = this.width;
39
- out.height = this.height;
40
- return out;
41
- }
42
- setSize(value, height) {
43
- const size = boxSize(value, height);
44
- this.#explicitWidth = size.width;
45
- this.#explicitHeight = size.height;
46
- this.refreshControlLayout();
47
- }
48
- get minWidth() {
49
- return this.#minWidth;
50
- }
51
- set minWidth(value) {
52
- this.#minWidth = Math.max(0, finiteNumber(value, 0));
53
- this.refreshControlLayout();
54
- }
55
- get minHeight() {
56
- return this.#minHeight;
57
- }
58
- set minHeight(value) {
59
- this.#minHeight = Math.max(0, finiteNumber(value, 0));
60
- this.refreshControlLayout();
61
- }
62
- get hSize() {
63
- return this.#hSize;
64
- }
65
- set hSize(value) {
66
- this.#hSize = parseSizeMode(value);
67
- this.requestParentLayout();
68
- }
69
- get vSize() {
70
- return this.#vSize;
71
- }
72
- set vSize(value) {
73
- this.#vSize = parseSizeMode(value);
74
- this.requestParentLayout();
75
- }
76
- get stretch() {
77
- return this.#stretch;
78
- }
79
- set stretch(value) {
80
- this.#stretch = Math.max(0, finiteNumber(value, 1));
81
- this.requestParentLayout();
82
- }
83
- get alignX() {
84
- return this.#alignX;
85
- }
86
- set alignX(value) {
87
- this.#alignX = parseAlign(value);
88
- this.layout();
89
- }
90
- get alignY() {
91
- return this.#alignY;
92
- }
93
- set alignY(value) {
94
- this.#alignY = parseAlign(value);
95
- this.layout();
96
- }
97
- onMounted() {
98
- this.default.on('childAdded', this.#refreshFromChildren, this);
99
- this.default.on('childRemoved', this.#refreshFromChildren, this);
100
- this.once('destroyed', this.#unmountLayout, this);
101
- this.layout();
102
- }
103
- #unmountLayout() {
104
- this.default.off('childAdded', this.#refreshFromChildren, this);
105
- this.default.off('childRemoved', this.#refreshFromChildren, this);
106
- }
107
- #refreshFromChildren() {
108
- this.refreshControlLayout();
109
- }
110
- getControlLayoutProps() {
111
- return {
112
- ...defaultControlLayoutProps,
113
- minWidth: this.#minWidth,
114
- minHeight: this.#minHeight,
115
- hSize: this.#hSize,
116
- vSize: this.#vSize,
117
- stretch: this.#stretch,
118
- };
119
- }
120
- measureControlNaturalSize() {
121
- const contentSize = this.default ? measureChildren(this.default) : { width: 0, height: 0 };
122
- return {
123
- width: Math.max(this.#minWidth, contentSize.width),
124
- height: Math.max(this.#minHeight, contentSize.height),
125
- };
126
- }
127
- setControlLayoutBox(x, y, width, height) {
128
- this.position.set(x, y);
129
- this.#layoutWidth = Math.max(0, finiteNumber(width, 0));
130
- this.#layoutHeight = Math.max(0, finiteNumber(height, 0));
131
- this.layout();
132
- }
133
- layout() {
134
- const size = this.syncControlBoxSize();
135
- this.layoutDefaultSlot(size);
136
- }
137
- layoutDefaultSlot(size = this.getControlBoxSize()) {
138
- if (!this.default) {
139
- return;
140
- }
141
- const bounds = measureChildrenBounds(this.default);
142
- const offsetX = alignOffset(this.#alignX, Math.max(0, size.width - bounds.width)) - bounds.x;
143
- const offsetY = alignOffset(this.#alignY, Math.max(0, size.height - bounds.height)) - bounds.y;
144
- this.default.position.set(offsetX, offsetY);
145
- }
146
- syncControlBoxSize() {
147
- const size = this.getControlBoxSize();
148
- super.setSize(Math.max(0, finiteNumber(size.width, 0)), Math.max(0, finiteNumber(size.height, 0)));
149
- return size;
150
- }
151
- getControlBoxSize() {
152
- const natural = this.measureControlNaturalSize();
153
- return {
154
- width: this.#layoutWidth ?? this.#explicitWidth ?? natural.width,
155
- height: this.#layoutHeight ?? this.#explicitHeight ?? natural.height,
156
- };
157
- }
158
- getAssignedControlBoxSize() {
159
- return {
160
- width: this.#layoutWidth ?? this.#explicitWidth,
161
- height: this.#layoutHeight ?? this.#explicitHeight,
162
- };
163
- }
164
- refreshControlLayout() {
165
- this.layout();
166
- this.requestParentLayout();
167
- }
168
- requestParentLayout() {
169
- let parent = this.parent;
170
- while (parent) {
171
- if (typeof parent.layout === 'function') {
172
- parent.layout();
173
- return;
174
- }
175
- parent = parent.parent;
176
- }
177
- }
178
- };
179
- __decorate([
180
- slot()
181
- ], Control.prototype, "default", void 0);
182
- __decorate([
183
- prop({ type: Number, default: 0 })
184
- ], Control.prototype, "minWidth", null);
185
- __decorate([
186
- prop({ type: Number, default: 0 })
187
- ], Control.prototype, "minHeight", null);
188
- __decorate([
189
- prop({ type: String, default: 'content' })
190
- ], Control.prototype, "hSize", null);
191
- __decorate([
192
- prop({ type: String, default: 'content' })
193
- ], Control.prototype, "vSize", null);
194
- __decorate([
195
- prop({ type: Number, default: 1 })
196
- ], Control.prototype, "stretch", null);
197
- __decorate([
198
- prop({ type: String, default: 'start' })
199
- ], Control.prototype, "alignX", null);
200
- __decorate([
201
- prop({ type: String, default: 'start' })
202
- ], Control.prototype, "alignY", null);
203
- Control = __decorate([
204
- scene()
205
- ], Control);
206
- export { Control };
@@ -1,3 +0,0 @@
1
- <Scene name="Control">
2
- <slot name="default" />
3
- </Scene>