@rpgjs/client 5.0.0-alpha.43 → 5.0.0-alpha.44

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 (137) hide show
  1. package/dist/Game/AnimationManager.js +25 -24
  2. package/dist/Game/AnimationManager.js.map +1 -1
  3. package/dist/Game/Event.js +11 -10
  4. package/dist/Game/Event.js.map +1 -1
  5. package/dist/Game/Map.js +78 -94
  6. package/dist/Game/Map.js.map +1 -1
  7. package/dist/Game/Object.js +182 -216
  8. package/dist/Game/Object.js.map +1 -1
  9. package/dist/Game/Player.js +11 -10
  10. package/dist/Game/Player.js.map +1 -1
  11. package/dist/Gui/Gui.js +440 -473
  12. package/dist/Gui/Gui.js.map +1 -1
  13. package/dist/Gui/NotificationManager.js +48 -50
  14. package/dist/Gui/NotificationManager.js.map +1 -1
  15. package/dist/Resource.js +132 -113
  16. package/dist/Resource.js.map +1 -1
  17. package/dist/RpgClientEngine.js +1333 -1486
  18. package/dist/RpgClientEngine.js.map +1 -1
  19. package/dist/Sound.js +162 -92
  20. package/dist/Sound.js.map +1 -1
  21. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.js +9 -0
  22. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.js +6 -0
  23. package/dist/components/animations/animation.ce.js +22 -19
  24. package/dist/components/animations/animation.ce.js.map +1 -1
  25. package/dist/components/animations/hit.ce.js +67 -68
  26. package/dist/components/animations/hit.ce.js.map +1 -1
  27. package/dist/components/animations/index.js +9 -8
  28. package/dist/components/animations/index.js.map +1 -1
  29. package/dist/components/character.ce.js +390 -314
  30. package/dist/components/character.ce.js.map +1 -1
  31. package/dist/components/dynamics/parse-value.js +42 -52
  32. package/dist/components/dynamics/parse-value.js.map +1 -1
  33. package/dist/components/dynamics/text.ce.js +71 -139
  34. package/dist/components/dynamics/text.ce.js.map +1 -1
  35. package/dist/components/gui/box.ce.js +26 -25
  36. package/dist/components/gui/box.ce.js.map +1 -1
  37. package/dist/components/gui/dialogbox/index.ce.js +202 -149
  38. package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
  39. package/dist/components/gui/gameover.ce.js +190 -138
  40. package/dist/components/gui/gameover.ce.js.map +1 -1
  41. package/dist/components/gui/hud/hud.ce.js +90 -33
  42. package/dist/components/gui/hud/hud.ce.js.map +1 -1
  43. package/dist/components/gui/index.js +14 -0
  44. package/dist/components/gui/menu/equip-menu.ce.js +478 -346
  45. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
  46. package/dist/components/gui/menu/exit-menu.ce.js +52 -33
  47. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
  48. package/dist/components/gui/menu/items-menu.ce.js +341 -226
  49. package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
  50. package/dist/components/gui/menu/main-menu.ce.js +414 -205
  51. package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
  52. package/dist/components/gui/menu/options-menu.ce.js +46 -26
  53. package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
  54. package/dist/components/gui/menu/skills-menu.ce.js +104 -50
  55. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
  56. package/dist/components/gui/mobile/index.js +18 -21
  57. package/dist/components/gui/mobile/index.js.map +1 -1
  58. package/dist/components/gui/mobile/mobile.ce.js +76 -15
  59. package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
  60. package/dist/components/gui/notification/notification.ce.js +62 -36
  61. package/dist/components/gui/notification/notification.ce.js.map +1 -1
  62. package/dist/components/gui/save-load.ce.js +386 -239
  63. package/dist/components/gui/save-load.ce.js.map +1 -1
  64. package/dist/components/gui/shop/shop.ce.js +649 -319
  65. package/dist/components/gui/shop/shop.ce.js.map +1 -1
  66. package/dist/components/gui/title-screen.ce.js +187 -145
  67. package/dist/components/gui/title-screen.ce.js.map +1 -1
  68. package/dist/components/index.js +4 -0
  69. package/dist/components/prebuilt/hp-bar.ce.js +114 -104
  70. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
  71. package/dist/components/prebuilt/index.js +2 -0
  72. package/dist/components/prebuilt/light-halo.ce.js +92 -74
  73. package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
  74. package/dist/components/scenes/canvas.ce.js +58 -42
  75. package/dist/components/scenes/canvas.ce.js.map +1 -1
  76. package/dist/components/scenes/draw-map.ce.js +87 -64
  77. package/dist/components/scenes/draw-map.ce.js.map +1 -1
  78. package/dist/components/scenes/event-layer.ce.js +26 -16
  79. package/dist/components/scenes/event-layer.ce.js.map +1 -1
  80. package/dist/core/inject.js +11 -10
  81. package/dist/core/inject.js.map +1 -1
  82. package/dist/core/setup.js +13 -13
  83. package/dist/core/setup.js.map +1 -1
  84. package/dist/index.js +44 -41
  85. package/dist/module.js +169 -168
  86. package/dist/module.js.map +1 -1
  87. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js +209 -298
  88. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js.map +1 -1
  89. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +430 -507
  90. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -1
  91. package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js +2062 -2571
  92. package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js.map +1 -1
  93. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +8 -3
  94. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -1
  95. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js +78 -101
  96. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js.map +1 -1
  97. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js +264 -401
  98. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js.map +1 -1
  99. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +9 -7
  100. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -1
  101. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +106 -165
  102. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
  103. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +361 -461
  104. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
  105. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
  106. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3633 -4280
  107. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
  108. package/dist/presets/animation.js +37 -25
  109. package/dist/presets/animation.js.map +1 -1
  110. package/dist/presets/faceset.js +49 -22
  111. package/dist/presets/faceset.js.map +1 -1
  112. package/dist/presets/icon.js +13 -13
  113. package/dist/presets/icon.js.map +1 -1
  114. package/dist/presets/index.js +15 -14
  115. package/dist/presets/index.js.map +1 -1
  116. package/dist/presets/lpc.js +96 -93
  117. package/dist/presets/lpc.js.map +1 -1
  118. package/dist/presets/rmspritesheet.js +40 -39
  119. package/dist/presets/rmspritesheet.js.map +1 -1
  120. package/dist/services/AbstractSocket.js +10 -8
  121. package/dist/services/AbstractSocket.js.map +1 -1
  122. package/dist/services/keyboardControls.js +20 -18
  123. package/dist/services/keyboardControls.js.map +1 -1
  124. package/dist/services/loadMap.js +120 -36
  125. package/dist/services/loadMap.js.map +1 -1
  126. package/dist/services/mmorpg.js +128 -136
  127. package/dist/services/mmorpg.js.map +1 -1
  128. package/dist/services/save.js +74 -66
  129. package/dist/services/save.js.map +1 -1
  130. package/dist/services/standalone.js +165 -167
  131. package/dist/services/standalone.js.map +1 -1
  132. package/dist/utils/getEntityProp.js +49 -51
  133. package/dist/utils/getEntityProp.js.map +1 -1
  134. package/package.json +8 -8
  135. package/src/components/character.ce +1 -1
  136. package/src/components/scenes/draw-map.ce +3 -1
  137. package/dist/index.js.map +0 -1
@@ -1,464 +1,327 @@
1
- import { __name } from './chunk-7QVYU63E.js';
2
- import { isSignal, isComputed, isObjectSubject, isArraySubject } from '../../../../../@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js';
3
-
4
- // src/utils.ts
1
+ import { __name } from "./chunk-7QVYU63E.js";
2
+ import { isArraySubject, isComputed, isObjectSubject, isSignal } from "../../../../../@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js";
3
+ //#region ../../node_modules/.pnpm/@signe+sync@2.8.3/node_modules/@signe/sync/dist/index.js
5
4
  function isFunction(val) {
6
- return {}.toString.call(val) === "[object Function]";
5
+ return {}.toString.call(val) === "[object Function]";
7
6
  }
8
7
  __name(isFunction, "isFunction");
9
8
  function isClass(obj) {
10
- return typeof obj === "function" && obj.prototype && obj.prototype.constructor === obj;
9
+ return typeof obj === "function" && obj.prototype && obj.prototype.constructor === obj;
11
10
  }
12
11
  __name(isClass, "isClass");
13
12
  var isObject = /* @__PURE__ */ __name((item) => item && typeof item === "object" && !Array.isArray(item) && item !== null, "isObject");
14
13
  function isInstanceOfClass(value) {
15
- if (value === null || typeof value !== "object" || value === void 0 || Array.isArray(value)) {
16
- return false;
17
- }
18
- return Object.getPrototypeOf(value) !== Object.prototype;
14
+ if (value === null || typeof value !== "object" || value === void 0 || Array.isArray(value)) return false;
15
+ return Object.getPrototypeOf(value) !== Object.prototype;
19
16
  }
20
17
  __name(isInstanceOfClass, "isInstanceOfClass");
21
18
  function generateShortUUID() {
22
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
23
- let uuid = "";
24
- for (let i = 0; i < 8; i++) {
25
- const randomIndex = Math.floor(Math.random() * chars.length);
26
- uuid += chars[randomIndex];
27
- }
28
- return uuid;
19
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
20
+ let uuid = "";
21
+ for (let i = 0; i < 8; i++) {
22
+ const randomIndex = Math.floor(Math.random() * 62);
23
+ uuid += chars[randomIndex];
24
+ }
25
+ return uuid;
29
26
  }
30
27
  __name(generateShortUUID, "generateShortUUID");
31
-
32
- // src/core.ts
33
28
  var DELETE_TOKEN = "$delete";
34
29
  var syncClass = /* @__PURE__ */ __name((instance, options = {}) => {
35
- const cacheSync = /* @__PURE__ */ new Map();
36
- const cachePersist = /* @__PURE__ */ new Map();
37
- instance.$valuesChanges = {
38
- set: /* @__PURE__ */ __name((path, value) => {
39
- cacheSync.set(path, value);
40
- options.onSync?.(cacheSync);
41
- }, "set"),
42
- setPersist: /* @__PURE__ */ __name((path, value) => {
43
- if (path == "") path = ".";
44
- cachePersist.set(path, value);
45
- options.onPersist?.(cachePersist);
46
- }, "setPersist"),
47
- has: /* @__PURE__ */ __name((path) => {
48
- return cacheSync.has(path);
49
- }, "has"),
50
- get: /* @__PURE__ */ __name((path) => {
51
- return cacheSync.get(path);
52
- }, "get")
53
- };
54
- createSyncClass(instance);
30
+ const cacheSync = /* @__PURE__ */ new Map();
31
+ const cachePersist = /* @__PURE__ */ new Map();
32
+ instance.$valuesChanges = {
33
+ set: /* @__PURE__ */ __name((path, value) => {
34
+ cacheSync.set(path, value);
35
+ options.onSync?.(cacheSync);
36
+ }, "set"),
37
+ setPersist: /* @__PURE__ */ __name((path, value) => {
38
+ if (path == "") path = ".";
39
+ cachePersist.set(path, value);
40
+ options.onPersist?.(cachePersist);
41
+ }, "setPersist"),
42
+ has: /* @__PURE__ */ __name((path) => {
43
+ return cacheSync.has(path);
44
+ }, "has"),
45
+ get: /* @__PURE__ */ __name((path) => {
46
+ return cacheSync.get(path);
47
+ }, "get")
48
+ };
49
+ createSyncClass(instance);
55
50
  }, "syncClass");
56
51
  function createStatesSnapshot(instance) {
57
- let persistObject = {};
58
- if (instance?.$snapshot) {
59
- for (const key of instance.$snapshot.keys()) {
60
- const signal = instance.$snapshot.get(key);
61
- const persist2 = signal.options.persist ?? true;
62
- let value = signal();
63
- if (isObject(value) || Array.isArray(value)) {
64
- continue;
65
- }
66
- if (persist2) {
67
- persistObject[key] = value;
68
- }
69
- }
70
- }
71
- return persistObject;
52
+ let persistObject = {};
53
+ if (instance?.$snapshot) for (const key of instance.$snapshot.keys()) {
54
+ const signal = instance.$snapshot.get(key);
55
+ const persist2 = signal.options.persist ?? true;
56
+ let value = signal();
57
+ if (isObject(value) || Array.isArray(value)) continue;
58
+ if (persist2) persistObject[key] = value;
59
+ }
60
+ return persistObject;
72
61
  }
73
62
  __name(createStatesSnapshot, "createStatesSnapshot");
74
63
  var SNAPSHOT_SKIP = Symbol("snapshot-skip");
75
64
  var serializeSnapshotDeep = /* @__PURE__ */ __name((value, path, options, seen) => {
76
- if (isSignal(value)) {
77
- return serializeSnapshotDeep(value(), path, options, seen);
78
- }
79
- if (value instanceof Map) {
80
- return SNAPSHOT_SKIP;
81
- }
82
- if (options.filter && !options.filter(value, path)) {
83
- return SNAPSHOT_SKIP;
84
- }
85
- if (value instanceof Date) {
86
- return options.dateToString ? options.dateToString(value) : value.toISOString();
87
- }
88
- if (value && typeof value === "object") {
89
- if (seen.has(value)) {
90
- return SNAPSHOT_SKIP;
91
- }
92
- seen.add(value);
93
- if (Array.isArray(value)) {
94
- const result2 = [];
95
- value.forEach((item, index) => {
96
- const itemPath = path ? `${path}.${index}` : String(index);
97
- const serialized = serializeSnapshotDeep(item, itemPath, options, seen);
98
- if (serialized !== SNAPSHOT_SKIP) {
99
- result2.push(serialized);
100
- }
101
- });
102
- return result2;
103
- }
104
- const result = {};
105
- const idKey = isInstanceOfClass(value) ? value.constructor?._propertyMetadata?.get("id") : void 0;
106
- const entries = Object.entries(value).filter(([key]) => isInstanceOfClass(value) ? key.startsWith("__") || (idKey ? key === idKey : false) : true);
107
- for (const [key, childValue] of entries) {
108
- const normalizedKey = key.startsWith("__") ? key.slice(2) : key;
109
- const childPath = path ? `${path}.${normalizedKey}` : normalizedKey;
110
- const serialized = serializeSnapshotDeep(childValue, childPath, options, seen);
111
- if (serialized !== SNAPSHOT_SKIP) {
112
- result[normalizedKey] = serialized;
113
- }
114
- }
115
- return result;
116
- }
117
- return value;
65
+ if (isSignal(value)) return serializeSnapshotDeep(value(), path, options, seen);
66
+ if (value instanceof Map) return SNAPSHOT_SKIP;
67
+ if (options.filter && !options.filter(value, path)) return SNAPSHOT_SKIP;
68
+ if (value instanceof Date) return options.dateToString ? options.dateToString(value) : value.toISOString();
69
+ if (value && typeof value === "object") {
70
+ if (seen.has(value)) return SNAPSHOT_SKIP;
71
+ seen.add(value);
72
+ if (Array.isArray(value)) {
73
+ const result2 = [];
74
+ value.forEach((item, index) => {
75
+ const serialized = serializeSnapshotDeep(item, path ? `${path}.${index}` : String(index), options, seen);
76
+ if (serialized !== SNAPSHOT_SKIP) result2.push(serialized);
77
+ });
78
+ return result2;
79
+ }
80
+ const result = {};
81
+ const idKey = isInstanceOfClass(value) ? value.constructor?._propertyMetadata?.get("id") : void 0;
82
+ const entries = Object.entries(value).filter(([key]) => isInstanceOfClass(value) ? key.startsWith("__") || (idKey ? key === idKey : false) : true);
83
+ for (const [key, childValue] of entries) {
84
+ const normalizedKey = key.startsWith("__") ? key.slice(2) : key;
85
+ const serialized = serializeSnapshotDeep(childValue, path ? `${path}.${normalizedKey}` : normalizedKey, options, seen);
86
+ if (serialized !== SNAPSHOT_SKIP) result[normalizedKey] = serialized;
87
+ }
88
+ return result;
89
+ }
90
+ return value;
118
91
  }, "serializeSnapshotDeep");
119
92
  function createStatesSnapshotDeep(instance, options = {}) {
120
- const persistObject = {};
121
- if (instance?.$snapshot) {
122
- for (const key of instance.$snapshot.keys()) {
123
- const signal = instance.$snapshot.get(key);
124
- const persist2 = signal.options.persist ?? true;
125
- if (!persist2) {
126
- continue;
127
- }
128
- const value = signal();
129
- const serialized = serializeSnapshotDeep(value, key, options, /* @__PURE__ */ new WeakSet());
130
- if (serialized !== SNAPSHOT_SKIP) {
131
- persistObject[key] = serialized;
132
- }
133
- }
134
- }
135
- return persistObject;
93
+ const persistObject = {};
94
+ if (instance?.$snapshot) for (const key of instance.$snapshot.keys()) {
95
+ const signal = instance.$snapshot.get(key);
96
+ if (!(signal.options.persist ?? true)) continue;
97
+ const serialized = serializeSnapshotDeep(signal(), key, options, /* @__PURE__ */ new WeakSet());
98
+ if (serialized !== SNAPSHOT_SKIP) persistObject[key] = serialized;
99
+ }
100
+ return persistObject;
136
101
  }
137
102
  __name(createStatesSnapshotDeep, "createStatesSnapshotDeep");
138
103
  function setMetadata(target, key, value) {
139
- const meta = target.constructor._propertyMetadata;
140
- const propId = meta?.get(key);
141
- if (propId) {
142
- if (isSignal(target[propId])) {
143
- target[propId].set(value);
144
- } else {
145
- target[propId] = value;
146
- }
147
- }
104
+ const propId = target.constructor._propertyMetadata?.get(key);
105
+ if (propId) if (isSignal(target[propId])) target[propId].set(value);
106
+ else target[propId] = value;
148
107
  }
149
108
  __name(setMetadata, "setMetadata");
150
109
  var createSyncClass = /* @__PURE__ */ __name((currentClass, parentKey = null, parentClass = null, path = "") => {
151
- currentClass.$path = path;
152
- if (parentClass) {
153
- currentClass.$valuesChanges = parentClass.$valuesChanges;
154
- }
155
- if (parentKey) {
156
- setMetadata(currentClass, "id", parentKey);
157
- }
158
- if (currentClass.$snapshot) {
159
- for (const key of currentClass.$snapshot.keys()) {
160
- const signal = currentClass.$snapshot.get(key);
161
- const syncToClient = signal.options?.syncToClient ?? true;
162
- const persist2 = signal.options?.persist ?? true;
163
- const transform = signal.options?.transform;
164
- let signalValue = signal();
165
- if (transform) {
166
- signalValue = transform(signalValue);
167
- }
168
- if (isObject(signalValue) || Array.isArray(signalValue)) {
169
- signalValue = {
170
- ...signalValue
171
- };
172
- }
173
- const transformedValue = signalValue;
174
- const newPath = (path ? path + "." : "") + key;
175
- if (syncToClient) {
176
- currentClass.$valuesChanges.set(newPath, transformedValue);
177
- }
178
- if (persist2) {
179
- if (parentClass) currentClass.$valuesChanges.setPersist(path, transformedValue);
180
- }
181
- if (isComputed(signal)) {
182
- signal.observable.subscribe((newValue) => {
183
- if (syncToClient) {
184
- const transformedNewValue = transform ? transform(newValue) : newValue;
185
- currentClass.$valuesChanges.set(newPath, transformedNewValue);
186
- }
187
- });
188
- }
189
- }
190
- }
110
+ currentClass.$path = path;
111
+ if (parentClass) currentClass.$valuesChanges = parentClass.$valuesChanges;
112
+ if (parentKey) setMetadata(currentClass, "id", parentKey);
113
+ if (currentClass.$snapshot) for (const key of currentClass.$snapshot.keys()) {
114
+ const signal = currentClass.$snapshot.get(key);
115
+ const syncToClient = signal.options?.syncToClient ?? true;
116
+ const persist2 = signal.options?.persist ?? true;
117
+ const transform = signal.options?.transform;
118
+ let signalValue = signal();
119
+ if (transform) signalValue = transform(signalValue);
120
+ if (isObject(signalValue) || Array.isArray(signalValue)) signalValue = { ...signalValue };
121
+ const transformedValue = signalValue;
122
+ const newPath = (path ? path + "." : "") + key;
123
+ if (syncToClient) currentClass.$valuesChanges.set(newPath, transformedValue);
124
+ if (persist2) {
125
+ if (parentClass) currentClass.$valuesChanges.setPersist(path, transformedValue);
126
+ }
127
+ if (isComputed(signal)) signal.observable.subscribe((newValue) => {
128
+ if (syncToClient) {
129
+ const transformedNewValue = transform ? transform(newValue) : newValue;
130
+ currentClass.$valuesChanges.set(newPath, transformedNewValue);
131
+ }
132
+ });
133
+ }
191
134
  }, "createSyncClass");
192
135
  var type = /* @__PURE__ */ __name((_signal, path, options = {}, currentInstance) => {
193
- const { syncToClient = true, persist: persist2 = true, transform } = options;
194
- let init = true;
195
- const handleObjectSubject = /* @__PURE__ */ __name((value, propPath) => {
196
- const newPath = `${propPath}${value.key ? `.${value.key}` : ""}`;
197
- if ([
198
- "add",
199
- "reset",
200
- "update"
201
- ].includes(value.type)) {
202
- if (isInstanceOfClass(value.value)) {
203
- createSyncClass(value.value, value.key, currentInstance, newPath);
204
- } else if (value.type === "update" && (isObject(value.value) || Array.isArray(value.value))) {
205
- createSyncClass(value.value, value.key, currentInstance, newPath);
206
- } else {
207
- savePath(newPath, value.value);
208
- }
209
- } else if (value.type === "remove") {
210
- savePath(newPath, DELETE_TOKEN);
211
- }
212
- }, "handleObjectSubject");
213
- const handleArraySubject = /* @__PURE__ */ __name((value, propPath) => {
214
- if (value.type === "reset" && Array.isArray(value.items)) {
215
- value.items.forEach((item, index) => {
216
- const newPath2 = `${propPath}.${index}`;
217
- if (isInstanceOfClass(item)) {
218
- createSyncClass(item, value.key, currentInstance, newPath2);
219
- } else {
220
- savePath(newPath2, item);
221
- }
222
- });
223
- return;
224
- }
225
- const newPath = `${propPath}.${value.index}`;
226
- const firstItem = value.items?.[0];
227
- if ([
228
- "add",
229
- "update"
230
- ].includes(value.type) && firstItem !== void 0) {
231
- if (isInstanceOfClass(firstItem)) {
232
- createSyncClass(firstItem, value.key, currentInstance, newPath);
233
- } else if (value.type === "update" && (isObject(firstItem) || Array.isArray(firstItem))) {
234
- createSyncClass(firstItem, value.key, currentInstance, newPath);
235
- } else {
236
- savePath(newPath, firstItem);
237
- }
238
- } else if (value.type === "remove") {
239
- savePath(newPath, DELETE_TOKEN);
240
- }
241
- }, "handleArraySubject");
242
- const savePath = /* @__PURE__ */ __name((propPath, value) => {
243
- const transformedValue = transform && value !== DELETE_TOKEN ? transform(value) : value;
244
- if (syncToClient) {
245
- currentInstance.$valuesChanges.set(propPath, transformedValue);
246
- }
247
- if (persist2 && currentInstance.$path !== void 0) {
248
- currentInstance.$valuesChanges.setPersist(transformedValue == DELETE_TOKEN ? propPath : currentInstance.$path, transformedValue);
249
- }
250
- }, "savePath");
251
- const setupSubscription = /* @__PURE__ */ __name((signal, signalPath) => {
252
- if (!isSignal(signal)) return;
253
- if (syncToClient && currentInstance.$valuesChanges) {
254
- const initialValue = signal();
255
- const transformedInitialValue = transform ? transform(initialValue) : initialValue;
256
- currentInstance.$valuesChanges.set(signalPath, transformedInitialValue);
257
- }
258
- signal.options = options;
259
- signal.observable.subscribe((value) => {
260
- if (init) return;
261
- if (currentInstance.$path !== void 0) {
262
- const fullPath = `${currentInstance.$path ? currentInstance.$path + "." : ""}${signalPath}`;
263
- if (isComputed(signal)) {
264
- savePath(fullPath, value);
265
- } else if (isObjectSubject(signal._subject)) {
266
- handleObjectSubject(value, fullPath);
267
- } else if (isArraySubject(signal._subject)) {
268
- handleArraySubject(value, fullPath);
269
- } else {
270
- savePath(fullPath, value);
271
- }
272
- }
273
- });
274
- if (!currentInstance.$snapshot) {
275
- currentInstance.$snapshot = /* @__PURE__ */ new Map();
276
- }
277
- currentInstance.$snapshot.set(path, signal);
278
- }, "setupSubscription");
279
- if (!isSignal(_signal)) {
280
- if (_signal && typeof _signal === "object" && !Array.isArray(_signal)) {
281
- for (const key in _signal) {
282
- if (Object.prototype.hasOwnProperty.call(_signal, key)) {
283
- const value = _signal[key];
284
- const propertyPath = `${path}.${key}`;
285
- if (isSignal(value)) {
286
- setupSubscription(value, propertyPath);
287
- } else if (value && typeof value === "object" && !Array.isArray(value)) {
288
- type(value, propertyPath, options, currentInstance);
289
- }
290
- }
291
- }
292
- init = false;
293
- }
294
- return _signal;
295
- }
296
- setupSubscription(_signal, path);
297
- init = false;
298
- return _signal;
136
+ const { syncToClient = true, persist: persist2 = true, transform } = options;
137
+ let init = true;
138
+ const handleObjectSubject = /* @__PURE__ */ __name((value, propPath) => {
139
+ const newPath = `${propPath}${value.key ? `.${value.key}` : ""}`;
140
+ if ([
141
+ "add",
142
+ "reset",
143
+ "update"
144
+ ].includes(value.type)) if (isInstanceOfClass(value.value)) createSyncClass(value.value, value.key, currentInstance, newPath);
145
+ else if (value.type === "update" && (isObject(value.value) || Array.isArray(value.value))) createSyncClass(value.value, value.key, currentInstance, newPath);
146
+ else savePath(newPath, value.value);
147
+ else if (value.type === "remove") savePath(newPath, DELETE_TOKEN);
148
+ }, "handleObjectSubject");
149
+ const handleArraySubject = /* @__PURE__ */ __name((value, propPath) => {
150
+ if (value.type === "reset" && Array.isArray(value.items)) {
151
+ value.items.forEach((item, index) => {
152
+ const newPath2 = `${propPath}.${index}`;
153
+ if (isInstanceOfClass(item)) createSyncClass(item, value.key, currentInstance, newPath2);
154
+ else savePath(newPath2, item);
155
+ });
156
+ return;
157
+ }
158
+ const newPath = `${propPath}.${value.index}`;
159
+ const firstItem = value.items?.[0];
160
+ if (["add", "update"].includes(value.type) && firstItem !== void 0) if (isInstanceOfClass(firstItem)) createSyncClass(firstItem, value.key, currentInstance, newPath);
161
+ else if (value.type === "update" && (isObject(firstItem) || Array.isArray(firstItem))) createSyncClass(firstItem, value.key, currentInstance, newPath);
162
+ else savePath(newPath, firstItem);
163
+ else if (value.type === "remove") savePath(newPath, DELETE_TOKEN);
164
+ }, "handleArraySubject");
165
+ const savePath = /* @__PURE__ */ __name((propPath, value) => {
166
+ const transformedValue = transform && value !== "$delete" ? transform(value) : value;
167
+ if (syncToClient) currentInstance.$valuesChanges.set(propPath, transformedValue);
168
+ if (persist2 && currentInstance.$path !== void 0) currentInstance.$valuesChanges.setPersist(transformedValue == "$delete" ? propPath : currentInstance.$path, transformedValue);
169
+ }, "savePath");
170
+ const setupSubscription = /* @__PURE__ */ __name((signal, signalPath) => {
171
+ if (!isSignal(signal)) return;
172
+ if (syncToClient && currentInstance.$valuesChanges) {
173
+ const initialValue = signal();
174
+ const transformedInitialValue = transform ? transform(initialValue) : initialValue;
175
+ currentInstance.$valuesChanges.set(signalPath, transformedInitialValue);
176
+ }
177
+ signal.options = options;
178
+ signal.observable.subscribe((value) => {
179
+ if (init) return;
180
+ if (currentInstance.$path !== void 0) {
181
+ const fullPath = `${currentInstance.$path ? currentInstance.$path + "." : ""}${signalPath}`;
182
+ if (isComputed(signal)) savePath(fullPath, value);
183
+ else if (isObjectSubject(signal._subject)) handleObjectSubject(value, fullPath);
184
+ else if (isArraySubject(signal._subject)) handleArraySubject(value, fullPath);
185
+ else savePath(fullPath, value);
186
+ }
187
+ });
188
+ if (!currentInstance.$snapshot) currentInstance.$snapshot = /* @__PURE__ */ new Map();
189
+ currentInstance.$snapshot.set(path, signal);
190
+ }, "setupSubscription");
191
+ if (!isSignal(_signal)) {
192
+ if (_signal && typeof _signal === "object" && !Array.isArray(_signal)) {
193
+ for (const key in _signal) if (Object.prototype.hasOwnProperty.call(_signal, key)) {
194
+ const value = _signal[key];
195
+ const propertyPath = `${path}.${key}`;
196
+ if (isSignal(value)) setupSubscription(value, propertyPath);
197
+ else if (value && typeof value === "object" && !Array.isArray(value)) type(value, propertyPath, options, currentInstance);
198
+ }
199
+ init = false;
200
+ }
201
+ return _signal;
202
+ }
203
+ setupSubscription(_signal, path);
204
+ init = false;
205
+ return _signal;
299
206
  }, "type");
300
-
301
- // src/decorators.ts
302
207
  function sync(options) {
303
- let classType;
304
- let persist2 = true;
305
- let syncToClient = true;
306
- let transform;
307
- if (typeof options === "function") {
308
- classType = options;
309
- } else if (typeof options === "object") {
310
- classType = options.classType;
311
- if (options.hasOwnProperty("persist")) {
312
- persist2 = options.persist;
313
- }
314
- if (options.hasOwnProperty("syncToClient")) {
315
- syncToClient = options.syncToClient;
316
- }
317
- if (options.hasOwnProperty("transform")) {
318
- transform = options.transform;
319
- }
320
- }
321
- return function(target, propertyKey) {
322
- const privatePropertyKey = `__${propertyKey}`;
323
- const getter = /* @__PURE__ */ __name(function() {
324
- return this[privatePropertyKey];
325
- }, "getter");
326
- const setter = /* @__PURE__ */ __name(function(newVal) {
327
- this[privatePropertyKey] = type(newVal, propertyKey, {
328
- classType,
329
- persist: persist2,
330
- syncToClient,
331
- transform
332
- }, this);
333
- }, "setter");
334
- Object.defineProperty(target, propertyKey, {
335
- get: getter,
336
- set: setter,
337
- enumerable: true,
338
- configurable: true
339
- });
340
- };
208
+ let classType;
209
+ let persist2 = true;
210
+ let syncToClient = true;
211
+ let transform;
212
+ if (typeof options === "function") classType = options;
213
+ else if (typeof options === "object") {
214
+ classType = options.classType;
215
+ if (options.hasOwnProperty("persist")) persist2 = options.persist;
216
+ if (options.hasOwnProperty("syncToClient")) syncToClient = options.syncToClient;
217
+ if (options.hasOwnProperty("transform")) transform = options.transform;
218
+ }
219
+ return function(target, propertyKey) {
220
+ const privatePropertyKey = `__${propertyKey}`;
221
+ const getter = /* @__PURE__ */ __name(function() {
222
+ return this[privatePropertyKey];
223
+ }, "getter");
224
+ const setter = /* @__PURE__ */ __name(function(newVal) {
225
+ this[privatePropertyKey] = type(newVal, propertyKey, {
226
+ classType,
227
+ persist: persist2,
228
+ syncToClient,
229
+ transform
230
+ }, this);
231
+ }, "setter");
232
+ Object.defineProperty(target, propertyKey, {
233
+ get: getter,
234
+ set: setter,
235
+ enumerable: true,
236
+ configurable: true
237
+ });
238
+ };
341
239
  }
342
240
  __name(sync, "sync");
343
241
  function id() {
344
- return function(target, propertyKey) {
345
- if (!target.constructor._propertyMetadata) {
346
- target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
347
- }
348
- target.constructor._propertyMetadata.set("id", propertyKey);
349
- };
242
+ return function(target, propertyKey) {
243
+ if (!target.constructor._propertyMetadata) target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
244
+ target.constructor._propertyMetadata.set("id", propertyKey);
245
+ };
350
246
  }
351
247
  __name(id, "id");
352
248
  function users(options) {
353
- return function(target, propertyKey) {
354
- if (!target.constructor._propertyMetadata) {
355
- target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
356
- }
357
- target.constructor._propertyMetadata.set("users", propertyKey);
358
- sync(options)(target, propertyKey);
359
- };
249
+ return function(target, propertyKey) {
250
+ if (!target.constructor._propertyMetadata) target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
251
+ target.constructor._propertyMetadata.set("users", propertyKey);
252
+ sync(options)(target, propertyKey);
253
+ };
360
254
  }
361
255
  __name(users, "users");
362
256
  function persist() {
363
- return sync({
364
- persist: true,
365
- syncToClient: false
366
- });
257
+ return sync({
258
+ persist: true,
259
+ syncToClient: false
260
+ });
367
261
  }
368
262
  __name(persist, "persist");
369
263
  function connected() {
370
- return function(target, propertyKey) {
371
- if (!target.constructor._propertyMetadata) {
372
- target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
373
- }
374
- target.constructor._propertyMetadata.set("connected", propertyKey);
375
- sync({
376
- persist: false
377
- })(target, propertyKey);
378
- };
264
+ return function(target, propertyKey) {
265
+ if (!target.constructor._propertyMetadata) target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
266
+ target.constructor._propertyMetadata.set("connected", propertyKey);
267
+ sync({ persist: false })(target, propertyKey);
268
+ };
379
269
  }
380
270
  __name(connected, "connected");
381
271
  function load(rootInstance, values, valueIsObject) {
382
- if (valueIsObject) {
383
- loadFromObject(rootInstance, values);
384
- } else {
385
- loadFromPaths(rootInstance, values);
386
- }
272
+ if (valueIsObject) loadFromObject(rootInstance, values);
273
+ else loadFromPaths(rootInstance, values);
387
274
  }
388
275
  __name(load, "load");
389
276
  function loadFromPaths(rootInstance, values) {
390
- for (const [path, value] of Object.entries(values)) {
391
- const parts = path.split(".");
392
- loadValue(rootInstance, parts, value);
393
- }
277
+ for (const [path, value] of Object.entries(values)) loadValue(rootInstance, path.split("."), value);
394
278
  }
395
279
  __name(loadFromPaths, "loadFromPaths");
396
280
  function loadFromObject(rootInstance, values, currentPath = "") {
397
- for (let key in values) {
398
- const value = values[key];
399
- const newPath = currentPath ? `${currentPath}.${key}` : key;
400
- if (typeof value === "object" && !Array.isArray(value) && value !== null) {
401
- loadFromObject(rootInstance, value, newPath);
402
- } else {
403
- const parts = newPath.split(".");
404
- loadValue(rootInstance, parts, value);
405
- }
406
- }
281
+ for (let key in values) {
282
+ const value = values[key];
283
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
284
+ if (typeof value === "object" && !Array.isArray(value) && value !== null) loadFromObject(rootInstance, value, newPath);
285
+ else loadValue(rootInstance, newPath.split("."), value);
286
+ }
407
287
  }
408
288
  __name(loadFromObject, "loadFromObject");
409
289
  function loadValue(rootInstance, parts, value) {
410
- let current = rootInstance;
411
- for (let i = 0; i < parts.length; i++) {
412
- const part = parts[i];
413
- if (i === parts.length - 1) {
414
- if (value == DELETE_TOKEN) {
415
- if (isSignal(current)) {
416
- current = current();
417
- }
418
- Reflect.deleteProperty(current, part);
419
- } else if (current[part]?._subject) {
420
- current[part].set(value);
421
- } else if (isSignal(current) && Array.isArray(current()) && !isNaN(Number(part))) {
422
- current()[Number(part)] = value;
423
- } else {
424
- current[part] = value;
425
- }
426
- } else {
427
- if (isSignal(current)) {
428
- current = current();
429
- }
430
- const currentValue = current[part];
431
- if (currentValue === void 0) {
432
- const parentInstance = getByPath(rootInstance, parts.slice(0, i).join("."));
433
- const classType = parentInstance?.options?.classType;
434
- if (classType) {
435
- current[part] = !isClass(classType) ? classType(part) : new classType();
436
- setMetadata(current[part], "id", part);
437
- } else {
438
- current[part] = {};
439
- }
440
- }
441
- current = current[part];
442
- }
443
- }
290
+ let current = rootInstance;
291
+ for (let i = 0; i < parts.length; i++) {
292
+ const part = parts[i];
293
+ if (i === parts.length - 1) if (value == "$delete") {
294
+ if (isSignal(current)) current = current();
295
+ Reflect.deleteProperty(current, part);
296
+ } else if (current[part]?._subject) current[part].set(value);
297
+ else if (isSignal(current) && Array.isArray(current()) && !isNaN(Number(part))) current()[Number(part)] = value;
298
+ else current[part] = value;
299
+ else {
300
+ if (isSignal(current)) current = current();
301
+ if (current[part] === void 0) {
302
+ const classType = getByPath(rootInstance, parts.slice(0, i).join("."))?.options?.classType;
303
+ if (classType) {
304
+ current[part] = !isClass(classType) ? classType(part) : new classType();
305
+ setMetadata(current[part], "id", part);
306
+ } else current[part] = {};
307
+ }
308
+ current = current[part];
309
+ }
310
+ }
444
311
  }
445
312
  __name(loadValue, "loadValue");
446
313
  function getByPath(root, path) {
447
- const parts = path.split(".");
448
- let current = root;
449
- for (const part of parts) {
450
- if (isSignal(current)) {
451
- current = current();
452
- }
453
- if (current[part]) {
454
- current = current[part];
455
- } else {
456
- return void 0;
457
- }
458
- }
459
- return current;
314
+ const parts = path.split(".");
315
+ let current = root;
316
+ for (const part of parts) {
317
+ if (isSignal(current)) current = current();
318
+ if (current[part]) current = current[part];
319
+ else return;
320
+ }
321
+ return current;
460
322
  }
461
323
  __name(getByPath, "getByPath");
324
+ //#endregion
325
+ export { DELETE_TOKEN, createStatesSnapshot, createStatesSnapshotDeep, generateShortUUID, getByPath, id, load, persist, sync, syncClass, users };
462
326
 
463
- export { DELETE_TOKEN, connected, createStatesSnapshot, createStatesSnapshotDeep, createSyncClass, generateShortUUID, getByPath, id, isClass, isFunction, isInstanceOfClass, isObject, load, persist, setMetadata, sync, syncClass, type, users };
464
- //# sourceMappingURL=index.js.map
327
+ //# sourceMappingURL=index.js.map