@cyclonium/core 0.0.100

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 (79) hide show
  1. package/lib/2d/transform-2d-component.d.ts +67 -0
  2. package/lib/2d/transform-2d-component.js +206 -0
  3. package/lib/decorator/legacy/apply-legacy-decorators.d.ts +5 -0
  4. package/lib/decorator/legacy/apply-legacy-decorators.js +12 -0
  5. package/lib/decorator/legacy/editable/common.d.ts +3 -0
  6. package/lib/decorator/legacy/editable/common.js +16 -0
  7. package/lib/decorator/legacy/editable/editable.d.ts +23 -0
  8. package/lib/decorator/legacy/editable/editable.js +61 -0
  9. package/lib/decorator/legacy/legacy-component-decorator.d.ts +11 -0
  10. package/lib/decorator/legacy/legacy-component-decorator.js +91 -0
  11. package/lib/decorator/legacy/legacy-decorator.d.ts +3 -0
  12. package/lib/decorator/legacy/legacy-decorator.js +3 -0
  13. package/lib/decorator/legacy/legacy-general-decorator.d.ts +32 -0
  14. package/lib/decorator/legacy/legacy-general-decorator.js +94 -0
  15. package/lib/decorator/legacy/utils.d.ts +6 -0
  16. package/lib/decorator/legacy/utils.js +17 -0
  17. package/lib/export/2d.d.ts +2 -0
  18. package/lib/export/2d.js +2 -0
  19. package/lib/export/framework.d.ts +4 -0
  20. package/lib/export/framework.js +4 -0
  21. package/lib/export/internal.d.ts +2 -0
  22. package/lib/export/internal.js +2 -0
  23. package/lib/export/legacy-decorator.d.ts +4 -0
  24. package/lib/export/legacy-decorator.js +4 -0
  25. package/lib/export/log.d.ts +2 -0
  26. package/lib/export/log.js +2 -0
  27. package/lib/export/math/bounds-2d.d.ts +2 -0
  28. package/lib/export/math/bounds-2d.js +2 -0
  29. package/lib/export/math/geometry.d.ts +2 -0
  30. package/lib/export/math/geometry.js +2 -0
  31. package/lib/export/math/mat3.d.ts +2 -0
  32. package/lib/export/math/mat3.js +2 -0
  33. package/lib/export/math/number.d.ts +2 -0
  34. package/lib/export/math/number.js +2 -0
  35. package/lib/export/math/ray.d.ts +2 -0
  36. package/lib/export/math/ray.js +2 -0
  37. package/lib/export/math/transform-2d.d.ts +2 -0
  38. package/lib/export/math/transform-2d.js +2 -0
  39. package/lib/export/math/trigonometry.d.ts +2 -0
  40. package/lib/export/math/trigonometry.js +2 -0
  41. package/lib/export/math/vec2.d.ts +2 -0
  42. package/lib/export/math/vec2.js +2 -0
  43. package/lib/export/utils.d.ts +5 -0
  44. package/lib/export/utils.js +5 -0
  45. package/lib/framework/component.d.ts +90 -0
  46. package/lib/framework/component.js +322 -0
  47. package/lib/framework/coroutine.d.ts +105 -0
  48. package/lib/framework/coroutine.js +278 -0
  49. package/lib/framework/execution-order.d.ts +12 -0
  50. package/lib/framework/execution-order.js +17 -0
  51. package/lib/framework/tasking.d.ts +17 -0
  52. package/lib/framework/tasking.js +82 -0
  53. package/lib/math/bounds-2d.d.ts +2 -0
  54. package/lib/math/bounds-2d.js +13 -0
  55. package/lib/math/geometry.d.ts +4 -0
  56. package/lib/math/geometry.js +19 -0
  57. package/lib/math/mat3.d.ts +2 -0
  58. package/lib/math/mat3.js +2 -0
  59. package/lib/math/number.d.ts +2 -0
  60. package/lib/math/number.js +2 -0
  61. package/lib/math/ray.d.ts +12 -0
  62. package/lib/math/ray.js +26 -0
  63. package/lib/math/transform-2d.d.ts +2 -0
  64. package/lib/math/transform-2d.js +2 -0
  65. package/lib/math/trigonometry.d.ts +2 -0
  66. package/lib/math/trigonometry.js +2 -0
  67. package/lib/math/vec2.d.ts +5 -0
  68. package/lib/math/vec2.js +17 -0
  69. package/lib/utils/assert.d.ts +5 -0
  70. package/lib/utils/assert.js +14 -0
  71. package/lib/utils/enum.d.ts +3 -0
  72. package/lib/utils/enum.js +15 -0
  73. package/lib/utils/inheritance.d.ts +2 -0
  74. package/lib/utils/inheritance.js +5 -0
  75. package/lib/utils/logger.d.ts +7 -0
  76. package/lib/utils/logger.js +19 -0
  77. package/lib/utils/raw.d.ts +6 -0
  78. package/lib/utils/raw.js +26 -0
  79. package/package.json +44 -0
@@ -0,0 +1,67 @@
1
+ import { CycloComponent } from '../framework/component.ts';
2
+ import { Mat3 } from '../math/mat3.ts';
3
+ import { Vec2 } from '../math/vec2.ts';
4
+ export declare enum TransformFlag {
5
+ position = 1,
6
+ rotation = 2,
7
+ scale = 4
8
+ }
9
+ declare class TransformChangeFlags {
10
+ get token(): boolean;
11
+ frontValue: number;
12
+ get backValue(): number;
13
+ reset(): void;
14
+ private _token;
15
+ private _backValue;
16
+ }
17
+ export declare class TransformChangeFlagsObserver {
18
+ observe(transform: Transform2DComponent): void;
19
+ sync(): number;
20
+ private _token;
21
+ private _flags;
22
+ }
23
+ export declare class Transform2DComponent extends CycloComponent {
24
+ static DEFAULT_FORWARD: Readonly<Vec2>;
25
+ static DEFAULT_UP: Readonly<Vec2>;
26
+ static DEFAULT_RIGHT: Readonly<Vec2>;
27
+ get position(): Vec2;
28
+ set position(value: Vec2);
29
+ get x(): number;
30
+ set x(value: number);
31
+ get y(): number;
32
+ set y(value: number);
33
+ get localPosition(): Vec2;
34
+ set localPosition(value: Vec2);
35
+ get localX(): number;
36
+ set localX(value: number);
37
+ get localY(): number;
38
+ set localY(value: number);
39
+ get rotation(): number;
40
+ set rotation(value: number);
41
+ get localRotation(): number;
42
+ set localRotation(value: number);
43
+ get scale(): Vec2;
44
+ set scale(value: Vec2 | number);
45
+ get localScale(): Vec2;
46
+ set localScale(value: Vec2 | number);
47
+ get forward(): Vec2;
48
+ set forward(value: Vec2);
49
+ get up(): Vec2;
50
+ set up(value: Vec2);
51
+ get right(): Vec2;
52
+ set right(value: Vec2);
53
+ get matrix(): Mat3;
54
+ get changeFlags(): TransformChangeFlags;
55
+ rotateAround(point: Vec2, angle: number): void;
56
+ protected onFrameEnd(): void;
57
+ private _position;
58
+ private _scale;
59
+ private _localPosition;
60
+ private _localScale;
61
+ private _forward;
62
+ private _matrix;
63
+ private _changeFlags;
64
+ private _setChangeFlag;
65
+ }
66
+ export {};
67
+ //# sourceMappingURL=transform-2d-component.d.ts.map
@@ -0,0 +1,206 @@
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
+ var Transform2DComponent_1;
8
+ import { Quat, Vec3 } from 'cc';
9
+ import { editable, cycloBuiltinClass } from "../decorator/legacy/legacy-decorator.js";
10
+ import { CycloComponent } from "../framework/component.js";
11
+ import { Mat3 } from "../math/mat3.js";
12
+ import { mat3FromSRT } from "../math/transform-2d.js";
13
+ import { Vec2 } from "../math/vec2.js";
14
+ import { to0ToPI2 } from "../math/trigonometry.js";
15
+ import { logger } from "../utils/logger.js";
16
+ import { clamp } from "../math/number.js";
17
+ export var TransformFlag;
18
+ (function (TransformFlag) {
19
+ TransformFlag[TransformFlag["position"] = 1] = "position";
20
+ TransformFlag[TransformFlag["rotation"] = 2] = "rotation";
21
+ TransformFlag[TransformFlag["scale"] = 4] = "scale";
22
+ })(TransformFlag || (TransformFlag = {}));
23
+ class TransformChangeFlags {
24
+ get token() {
25
+ return this._token;
26
+ }
27
+ frontValue = 0;
28
+ get backValue() {
29
+ return this._backValue;
30
+ }
31
+ reset() {
32
+ this._token = !this._token;
33
+ this._backValue = this.frontValue;
34
+ this.frontValue = 0;
35
+ }
36
+ _token = false;
37
+ _backValue = 0;
38
+ }
39
+ export class TransformChangeFlagsObserver {
40
+ observe(transform) {
41
+ const flags = transform.changeFlags;
42
+ this._token = flags.token;
43
+ this._flags = flags;
44
+ }
45
+ sync() {
46
+ if (this._token === this._flags.token) {
47
+ return this._flags.frontValue;
48
+ }
49
+ else {
50
+ this._token = this._flags.token;
51
+ return this._flags.backValue | this._flags.frontValue;
52
+ }
53
+ }
54
+ _token = false;
55
+ _flags = new TransformChangeFlags();
56
+ }
57
+ let Transform2DComponent = class Transform2DComponent extends CycloComponent {
58
+ static { Transform2DComponent_1 = this; }
59
+ static DEFAULT_FORWARD = Vec2.UNIT_X;
60
+ static DEFAULT_UP = Vec2.UNIT_Y;
61
+ static DEFAULT_RIGHT = Vec2.UNIT_X;
62
+ get position() {
63
+ return Vec2.set(this._position, this.node.worldPosition.x, this.node.worldPosition.y);
64
+ }
65
+ set position(value) {
66
+ Vec2.assign(this._position, value);
67
+ this.node.worldPosition = new Vec3(value.x, value.y, this.node.worldPosition.z);
68
+ this._setChangeFlag(TransformFlag.position);
69
+ }
70
+ get x() {
71
+ return this.node.worldPosition.x;
72
+ }
73
+ set x(value) {
74
+ this.node.worldPosition = new Vec3(value, this.node.worldPosition.y, this.node.worldPosition.z);
75
+ this._setChangeFlag(TransformFlag.position);
76
+ }
77
+ get y() {
78
+ return this.node.worldPosition.y;
79
+ }
80
+ set y(value) {
81
+ this.node.worldPosition = new Vec3(this.node.worldPosition.x, value, this.node.worldPosition.z);
82
+ this._setChangeFlag(TransformFlag.position);
83
+ }
84
+ get localPosition() {
85
+ return Vec2.set(this._localPosition, this.node.position.x, this.node.position.y);
86
+ }
87
+ set localPosition(value) {
88
+ Vec2.assign(this._localPosition, value);
89
+ this.node.position = new Vec3(value.x, value.y, this.node.position.z);
90
+ this._setChangeFlag(TransformFlag.position);
91
+ }
92
+ get localX() {
93
+ return this.node.position.x;
94
+ }
95
+ set localX(value) {
96
+ this.node.position = new Vec3(value, this.node.position.y, this.node.position.z);
97
+ this._setChangeFlag(TransformFlag.position);
98
+ }
99
+ get localY() {
100
+ return this.node.position.y;
101
+ }
102
+ set localY(value) {
103
+ this.node.position = new Vec3(this.node.position.x, value, this.node.position.z);
104
+ this._setChangeFlag(TransformFlag.position);
105
+ }
106
+ get rotation() {
107
+ return to0ToPI2(getZRotation(this.node.worldRotation));
108
+ }
109
+ set rotation(value) {
110
+ this.node.worldRotation = Quat.fromAxisAngle(new Quat(), Vec3.UNIT_Z, value);
111
+ this._setChangeFlag(TransformFlag.rotation);
112
+ }
113
+ get localRotation() {
114
+ return to0ToPI2(getZRotation(this.node.rotation));
115
+ }
116
+ set localRotation(value) {
117
+ this.node.rotation = Quat.fromAxisAngle(new Quat(), Vec3.UNIT_Z, value);
118
+ this._setChangeFlag(TransformFlag.rotation);
119
+ }
120
+ get scale() {
121
+ return Vec2.set(this._scale, this.node.worldScale.x, this.node.worldScale.y);
122
+ }
123
+ set scale(value) {
124
+ this.node.worldScale = typeof value === 'number' ? new Vec3(value, value, this.node.worldScale.z) : new Vec3(value.x, value.y, this.node.worldScale.z);
125
+ this._setChangeFlag(TransformFlag.scale);
126
+ }
127
+ get localScale() {
128
+ return Vec2.set(this._localScale, this.node.scale.x, this.node.scale.y);
129
+ }
130
+ set localScale(value) {
131
+ this.node.scale = typeof value === 'number' ? new Vec3(value, value, this.node.scale.z) : new Vec3(value.x, value.y, this.node.scale.z);
132
+ this._setChangeFlag(TransformFlag.scale);
133
+ }
134
+ get forward() {
135
+ const f = Vec3.transformQuat(new Vec3(), new Vec3(Transform2DComponent_1.DEFAULT_FORWARD.x, Transform2DComponent_1.DEFAULT_FORWARD.y, 0), this.node.worldRotation);
136
+ return Vec2.set(this._forward, f.x, f.y);
137
+ }
138
+ set forward(value) {
139
+ const angle = Vec2.signedAngle(Transform2DComponent_1.DEFAULT_FORWARD, value);
140
+ this.rotation = angle;
141
+ }
142
+ get up() {
143
+ return Transform2DComponent_1.DEFAULT_UP.rotate(this.rotation);
144
+ }
145
+ set up(value) {
146
+ this.rotation = Vec2.signedAngle(Transform2DComponent_1.DEFAULT_UP, value);
147
+ }
148
+ get right() {
149
+ return Transform2DComponent_1.DEFAULT_RIGHT.rotate(this.rotation);
150
+ }
151
+ set right(value) {
152
+ this.rotation = Vec2.signedAngle(Transform2DComponent_1.DEFAULT_RIGHT, value);
153
+ }
154
+ get matrix() {
155
+ return mat3FromSRT(this.position, this.rotation, this.scale, this._matrix);
156
+ }
157
+ get changeFlags() {
158
+ return this._changeFlags;
159
+ }
160
+ rotateAround(point, angle) {
161
+ const dx = this.position.x - point.x;
162
+ const dy = this.position.y - point.y;
163
+ const rotatedX = dx * Math.cos(angle) - dy * Math.sin(angle);
164
+ const rotatedY = dx * Math.sin(angle) + dy * Math.cos(angle);
165
+ this.position = new Vec2(point.x + rotatedX, point.y + rotatedY);
166
+ this.rotation += angle;
167
+ this._setChangeFlag(TransformFlag.position | TransformFlag.rotation);
168
+ }
169
+ onFrameEnd() {
170
+ this._changeFlags.reset();
171
+ }
172
+ _position = new Vec2();
173
+ _scale = new Vec2(1, 1);
174
+ _localPosition = new Vec2();
175
+ _localScale = new Vec2(1, 1);
176
+ _forward = new Vec2();
177
+ _matrix = new Mat3(Mat3.IDENTITY);
178
+ _changeFlags = new TransformChangeFlags();
179
+ _setChangeFlag(mask) {
180
+ this._changeFlags.frontValue |= mask;
181
+ }
182
+ };
183
+ __decorate([
184
+ editable
185
+ ], Transform2DComponent.prototype, "localPosition", null);
186
+ __decorate([
187
+ editable({ radian: true })
188
+ ], Transform2DComponent.prototype, "localRotation", null);
189
+ __decorate([
190
+ editable
191
+ ], Transform2DComponent.prototype, "localScale", null);
192
+ Transform2DComponent = Transform2DComponent_1 = __decorate([
193
+ cycloBuiltinClass('Transform2DComponent')
194
+ ], Transform2DComponent);
195
+ export { Transform2DComponent };
196
+ function getZRotation(quat) {
197
+ const { z, w } = quat;
198
+ const halfTheta = Math.acos(clamp(w, -1, 1));
199
+ if (halfTheta === 0) {
200
+ return 0;
201
+ }
202
+ const sinSign = Math.sign(halfTheta);
203
+ const axisSign = sinSign * Math.sign(z);
204
+ return axisSign * halfTheta * 2;
205
+ }
206
+ //# sourceMappingURL=transform-2d-component.js.map
@@ -0,0 +1,5 @@
1
+ export declare function applyLegacyDecorators<T extends object>(targetClass: new (...args: never[]) => T, options: {
2
+ classDecorators?: ClassDecorator[];
3
+ propertyDecorators?: Partial<Record<Extract<keyof T, string>, PropertyDecorator[]>>;
4
+ }): void;
5
+ //# sourceMappingURL=apply-legacy-decorators.d.ts.map
@@ -0,0 +1,12 @@
1
+ export function applyLegacyDecorators(targetClass, options) {
2
+ const { classDecorators, propertyDecorators } = options;
3
+ if (propertyDecorators) {
4
+ Object.entries(propertyDecorators).forEach(([propertyName, decorators]) => {
5
+ decorators.forEach((decorator) => decorator(targetClass.prototype, propertyName));
6
+ });
7
+ }
8
+ if (classDecorators) {
9
+ classDecorators.forEach((decorator) => decorator(targetClass));
10
+ }
11
+ }
12
+ //# sourceMappingURL=apply-legacy-decorators.js.map
@@ -0,0 +1,3 @@
1
+ import { _decorator } from 'cc';
2
+ export declare function createDecoratorForSetEditableMetadata(opts: Parameters<typeof _decorator.property>[0]): PropertyDecorator;
3
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { _decorator } from 'cc';
2
+ export function createDecoratorForSetEditableMetadata(opts) {
3
+ return (target, propertyKey, descriptor) => {
4
+ const normalizedOptions = {
5
+ ...opts,
6
+ };
7
+ if (normalizedOptions.visible === undefined) {
8
+ if (typeof propertyKey === 'string' && propertyKey.startsWith('_')) {
9
+ normalizedOptions.visible = true;
10
+ normalizedOptions.displayName = propertyKey.slice(1);
11
+ }
12
+ }
13
+ return _decorator.property(normalizedOptions)(target, propertyKey, descriptor);
14
+ };
15
+ }
16
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1,23 @@
1
+ import { CCInteger, type CCBoolean, type CCFloat, type CCString } from 'cc';
2
+ export interface EditableDecoratorOptions {
3
+ type?: Function | typeof CCInteger;
4
+ min?: number;
5
+ max?: number;
6
+ step?: number;
7
+ slide?: boolean;
8
+ /** @deprecated Use `radians` instead. */
9
+ radian?: boolean;
10
+ radians?: boolean;
11
+ unit?: string;
12
+ visible?: boolean | (() => boolean);
13
+ group?: string;
14
+ override?: boolean;
15
+ readonly?: boolean;
16
+ tooltip?: string;
17
+ }
18
+ declare function editable(options?: EditableDecoratorOptions): PropertyDecorator;
19
+ declare function editable(type?: Function): PropertyDecorator;
20
+ declare function editable(type?: typeof CCInteger | typeof CCBoolean | typeof CCFloat | typeof CCString): PropertyDecorator;
21
+ declare function editable(target: object, propertyKey: string | symbol): void;
22
+ export { editable };
23
+ //# sourceMappingURL=editable.d.ts.map
@@ -0,0 +1,61 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ import { CCInteger } from 'cc';
3
+ import { isSubClassOfInclusive } from "../../../utils/inheritance.js";
4
+ import { logger } from "../../../utils/logger.js";
5
+ import { createDecoratorForSetEditableMetadata } from "./common.js";
6
+ function editable(...args) {
7
+ if (args.length === 0) {
8
+ // `@editable()`
9
+ return editableWithOptions({});
10
+ }
11
+ else if (args.length === 1) {
12
+ const args0 = args[0];
13
+ if (typeof args0 === 'object' && args0) {
14
+ if (args0.constructor === CCInteger.constructor) {
15
+ // `@editable(CCInteger)`
16
+ return editableWithOptions({
17
+ type: args0,
18
+ });
19
+ }
20
+ // `@editable(options)`
21
+ return editableWithOptions(args0);
22
+ }
23
+ else if (typeof args0 === 'function') {
24
+ if (isSubClassOfInclusive(args0, Array)) {
25
+ // https://forum.cocos.org/t/topic/165943
26
+ logger.warn(`@editable(Array) is not supported.`);
27
+ }
28
+ // `@editable(Node)`
29
+ return editableWithOptions({
30
+ type: args0,
31
+ });
32
+ }
33
+ else {
34
+ throw new Error(`Invalid @editable() arguments.`);
35
+ }
36
+ }
37
+ else {
38
+ // `@editable`
39
+ return editableWithOptions({})(...args);
40
+ }
41
+ }
42
+ function editableWithOptions(options) {
43
+ return (...args) => {
44
+ const modifiedOptions = { ...options };
45
+ if (modifiedOptions.radians !== undefined) {
46
+ modifiedOptions.radian = modifiedOptions.radians;
47
+ }
48
+ if (modifiedOptions.radian) {
49
+ if (modifiedOptions.min === undefined && modifiedOptions.max === undefined) {
50
+ modifiedOptions.min = 0;
51
+ modifiedOptions.max = Math.PI * 2;
52
+ }
53
+ if (modifiedOptions.step === undefined) {
54
+ modifiedOptions.step = 1;
55
+ }
56
+ }
57
+ createDecoratorForSetEditableMetadata(modifiedOptions)(...args);
58
+ };
59
+ }
60
+ export { editable };
61
+ //# sourceMappingURL=editable.js.map
@@ -0,0 +1,11 @@
1
+ import { Component } from 'cc';
2
+ import { CycloComponent } from '../../framework/component.ts';
3
+ export declare function executionOrder(order: number): ClassDecorator;
4
+ export declare namespace executionOrder {
5
+ function lateThan(component: CycloComponentClass): ClassDecorator;
6
+ }
7
+ export declare const executeInEditMode: ((value?: boolean) => ClassDecorator) & ClassDecorator;
8
+ export declare function requiresComponent<T extends Component>(componentType: new (...args: never[]) => T): MethodDecorator;
9
+ type CycloComponentClass = new (...args: never[]) => CycloComponent;
10
+ export {};
11
+ //# sourceMappingURL=legacy-component-decorator.d.ts.map
@@ -0,0 +1,91 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ import { _decorator, Component } from 'cc';
3
+ import { CycloComponent } from "../../framework/component.js";
4
+ import { getExecutionOrder, setExecutionOrder } from "../../framework/execution-order.js";
5
+ import { logger } from "../../utils/logger.js";
6
+ export function executionOrder(order) {
7
+ return defineComponentDecorator((target) => {
8
+ setExecutionOrder(target, order);
9
+ });
10
+ }
11
+ // eslint-disable-next-line @typescript-eslint/no-namespace
12
+ (function (executionOrder) {
13
+ function lateThan(component) {
14
+ return defineComponentDecorator((target) => {
15
+ setExecutionOrder(target, getExecutionOrder(component) + 1);
16
+ });
17
+ }
18
+ executionOrder.lateThan = lateThan;
19
+ })(executionOrder || (executionOrder = {}));
20
+ export const executeInEditMode = defineComponentDecoratorWithOptionalBoolean((target, value) => {
21
+ _decorator.executeInEditMode(value)(target);
22
+ });
23
+ function addRequiredComponent(target, componentType) {
24
+ let _requireComponent = Reflect.getOwnPropertyDescriptor(target.constructor, '_requireComponent')?.value;
25
+ if (_requireComponent === undefined) {
26
+ _requireComponent = [];
27
+ Reflect.defineProperty(target.constructor, '_requireComponent', {
28
+ value: _requireComponent,
29
+ writable: true,
30
+ enumerable: true,
31
+ configurable: true,
32
+ });
33
+ }
34
+ _requireComponent.push(componentType);
35
+ }
36
+ export function requiresComponent(componentType) {
37
+ return defineComponentMethodDecorator((target, propertyKey, descriptor) => {
38
+ addRequiredComponent(target, componentType);
39
+ const { get, set, value, ...remain } = descriptor;
40
+ if (set) {
41
+ throw new Error(`Property ${String(propertyKey)} of should not has set`);
42
+ }
43
+ if (value !== undefined) {
44
+ throw new Error(`Property ${String(propertyKey)} of should not has value`);
45
+ }
46
+ return {
47
+ ...remain,
48
+ get() {
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ const component = this.getComponent(componentType);
51
+ if (!component) {
52
+ throw new Error(`Component ${componentType.name} is not found.`);
53
+ }
54
+ return component;
55
+ },
56
+ };
57
+ });
58
+ }
59
+ function defineComponentDecorator(decorate) {
60
+ return (target) => {
61
+ if (!(target.prototype instanceof CycloComponent)) {
62
+ throw new Error(`Class ${target.name} is not a subclass of CycloComponent.`);
63
+ }
64
+ decorate(target);
65
+ };
66
+ }
67
+ function defineComponentDecoratorWithOptionalBoolean(decorate) {
68
+ return ((...args) => {
69
+ const arg0 = args[0];
70
+ if (typeof arg0 === 'boolean' || arg0 === undefined) {
71
+ return defineComponentDecorator((target) => {
72
+ decorate(target, arg0);
73
+ });
74
+ }
75
+ else {
76
+ return defineComponentDecorator((target) => {
77
+ decorate(target);
78
+ })(...args);
79
+ }
80
+ });
81
+ }
82
+ function defineComponentMethodDecorator(decorate) {
83
+ return (target, propertyKey, descriptor) => {
84
+ if (!(target instanceof CycloComponent)) {
85
+ throw new Error(`Class ${target} is not a subclass of CycloComponent.`);
86
+ }
87
+ return decorate(target, propertyKey, descriptor);
88
+ };
89
+ }
90
+ ;
91
+ //# sourceMappingURL=legacy-component-decorator.js.map
@@ -0,0 +1,3 @@
1
+ export * from './legacy-general-decorator.ts';
2
+ export * from './legacy-component-decorator.ts';
3
+ //# sourceMappingURL=legacy-decorator.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from "./legacy-general-decorator.js";
2
+ export * from "./legacy-component-decorator.js";
3
+ //# sourceMappingURL=legacy-decorator.js.map
@@ -0,0 +1,32 @@
1
+ import { _decorator } from 'cc';
2
+ import { editable } from './editable/editable.ts';
3
+ export { editable };
4
+ export interface CycloClassOptions {
5
+ name?: string;
6
+ abstract?: boolean;
7
+ }
8
+ export interface CycloClassDecorator {
9
+ (options?: CycloClassOptions): ClassDecorator;
10
+ (name?: string): ClassDecorator;
11
+ <TFunction extends Function>(target: TFunction): TFunction | void;
12
+ }
13
+ export declare function createScopedCycloClassDecorator(opts: {
14
+ scope: string;
15
+ }): CycloClassDecorator;
16
+ declare const cycloClass: CycloClassDecorator;
17
+ declare const cycloBuiltinClass: CycloClassDecorator;
18
+ export { cycloClass, cycloBuiltinClass };
19
+ export declare const serializable: typeof _decorator.property;
20
+ /**
21
+ * Marks that the property's default value might vary between instances.
22
+ * @description
23
+ * Use this for dynamic initializers such as `_time = Math.random()`.
24
+ * Cocos will avoid treating that initializer result as a reusable default, for
25
+ * example when stripping default values during serialization.
26
+ */
27
+ export declare const dynamicDefault: PropertyDecorator;
28
+ export declare const designType: typeof _decorator.type;
29
+ export declare const editorOnly: (...args: Parameters<PropertyDecorator>) => void;
30
+ export declare const idem: MethodDecorator;
31
+ export declare function idemBy<T>(equals: (a: T, b: T) => boolean): MethodDecorator;
32
+ //# sourceMappingURL=legacy-general-decorator.d.ts.map
@@ -0,0 +1,94 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ import { _decorator, CCClass, Component } from 'cc';
3
+ import { editable } from "./editable/editable.js";
4
+ export { editable };
5
+ const dynamicDefaultProperties = new WeakMap();
6
+ export function createScopedCycloClassDecorator(opts) {
7
+ const { scope } = opts;
8
+ function cycloClass(...args) {
9
+ if (args.length === 0) {
10
+ return cycloClassWithOptions(scope);
11
+ }
12
+ else if (typeof args[0] === 'string') {
13
+ return cycloClassWithOptions(scope, { name: args[0] });
14
+ }
15
+ else if (typeof args[0] === 'object' && args[0]) {
16
+ return cycloClassWithOptions(scope, args[0]);
17
+ }
18
+ else {
19
+ return cycloClassWithOptions(scope)(...args);
20
+ }
21
+ }
22
+ return cycloClass;
23
+ }
24
+ function cycloClassWithOptions(scope, options) {
25
+ return (target) => {
26
+ const name = options?.name ?? target.name;
27
+ if (!(options?.abstract) && target.prototype instanceof Component) {
28
+ _decorator.menu(`${scope}/${name}`)(target);
29
+ }
30
+ _decorator.ccclass(typeof name === 'string' ? `${scope}${name}` : name)(target);
31
+ const propertyNames = dynamicDefaultProperties.get(target.prototype);
32
+ if (propertyNames) {
33
+ for (const propertyName of propertyNames) {
34
+ CCClass.Attr.setClassAttr(target, propertyName, 'default', undefined);
35
+ }
36
+ dynamicDefaultProperties.delete(target.prototype);
37
+ }
38
+ };
39
+ }
40
+ const cycloClass = createScopedCycloClassDecorator({
41
+ scope: '',
42
+ });
43
+ const cycloBuiltinClass = createScopedCycloClassDecorator({
44
+ scope: 'cyclo.',
45
+ });
46
+ export { cycloClass, cycloBuiltinClass };
47
+ export const serializable = _decorator.property;
48
+ /**
49
+ * Marks that the property's default value might vary between instances.
50
+ * @description
51
+ * Use this for dynamic initializers such as `_time = Math.random()`.
52
+ * Cocos will avoid treating that initializer result as a reusable default, for
53
+ * example when stripping default values during serialization.
54
+ */
55
+ export const dynamicDefault = (target, propertyKey) => {
56
+ if (typeof propertyKey !== 'string') {
57
+ return;
58
+ }
59
+ let propertyNames = dynamicDefaultProperties.get(target);
60
+ if (!propertyNames) {
61
+ propertyNames = new Set();
62
+ dynamicDefaultProperties.set(target, propertyNames);
63
+ }
64
+ propertyNames.add(propertyKey);
65
+ };
66
+ export const designType = _decorator.type;
67
+ export const editorOnly = (...args) => {
68
+ _decorator.property({ serializable: true, editorOnly: true })(...args);
69
+ };
70
+ export const idem = (_, propertyKey, descriptor) => {
71
+ const set = descriptor.set;
72
+ descriptor.set = function (value) {
73
+ // @ts-expect-error Dynamic property access by the decorated key.
74
+ if (this[propertyKey] === value) {
75
+ return;
76
+ }
77
+ // @ts-expect-error Setter type is preserved by the original descriptor.
78
+ set.call(this, value);
79
+ };
80
+ };
81
+ export function idemBy(equals) {
82
+ return (_target, propertyKey, descriptor) => {
83
+ const set = descriptor.set;
84
+ descriptor.set = function (value) {
85
+ // @ts-expect-error Dynamic property access by the decorated key.
86
+ if (equals(this[propertyKey], value)) {
87
+ return;
88
+ }
89
+ // @ts-expect-error Setter type is preserved by the original descriptor.
90
+ set.call(this, value);
91
+ };
92
+ };
93
+ }
94
+ //# sourceMappingURL=legacy-general-decorator.js.map
@@ -0,0 +1,6 @@
1
+ export interface ShortenPropertyDecorator<TArgs extends any[]> {
2
+ (...args: TArgs): PropertyDecorator;
3
+ (target: Object, propertyKey: string | symbol): void;
4
+ }
5
+ export declare function defineShortenPropertyDecorator<TArgs extends any[]>(decorator: (...args: TArgs) => PropertyDecorator, ...defaultArgs: TArgs): ShortenPropertyDecorator<TArgs>;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,17 @@
1
+ export function defineShortenPropertyDecorator(decorator, ...defaultArgs) {
2
+ return ((...args) => {
3
+ if (args.length === 0) {
4
+ // @x()
5
+ return decorator(...defaultArgs);
6
+ }
7
+ else if (!(typeof args[0] === 'object' && args[0] && typeof args[1] === 'string' || typeof args[1] === 'symbol')) {
8
+ // @x(opts)
9
+ return decorator(...args);
10
+ }
11
+ else {
12
+ // @x
13
+ return decorator(...defaultArgs)(...args);
14
+ }
15
+ });
16
+ }
17
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,2 @@
1
+ export { Transform2DComponent, TransformChangeFlagsObserver, TransformFlag } from '../2d/transform-2d-component.ts';
2
+ //# sourceMappingURL=2d.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { Transform2DComponent, TransformChangeFlagsObserver, TransformFlag } from "../2d/transform-2d-component.js";
2
+ //# sourceMappingURL=2d.js.map