@rpgjs/client 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (172) hide show
  1. package/dist/Game/AnimationManager.d.ts +8 -0
  2. package/dist/Game/Map.d.ts +7 -1
  3. package/dist/Gui/Gui.d.ts +170 -5
  4. package/dist/Resource.d.ts +97 -0
  5. package/dist/RpgClient.d.ts +259 -59
  6. package/dist/RpgClientEngine.d.ts +379 -6
  7. package/dist/Sound.d.ts +199 -0
  8. package/dist/components/animations/index.d.ts +4 -0
  9. package/dist/components/dynamics/parse-value.d.ts +1 -0
  10. package/dist/components/gui/index.d.ts +3 -3
  11. package/dist/components/index.d.ts +3 -1
  12. package/dist/components/prebuilt/index.d.ts +18 -0
  13. package/dist/index.d.ts +6 -1
  14. package/dist/index.js +11 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/index10.js +149 -4
  17. package/dist/index10.js.map +1 -1
  18. package/dist/index11.js +22 -7
  19. package/dist/index11.js.map +1 -1
  20. package/dist/index12.js +6 -4
  21. package/dist/index12.js.map +1 -1
  22. package/dist/index13.js +11 -14
  23. package/dist/index13.js.map +1 -1
  24. package/dist/index14.js +8 -40
  25. package/dist/index14.js.map +1 -1
  26. package/dist/index15.js +217 -180
  27. package/dist/index15.js.map +1 -1
  28. package/dist/index16.js +104 -7
  29. package/dist/index16.js.map +1 -1
  30. package/dist/index17.js +82 -372
  31. package/dist/index17.js.map +1 -1
  32. package/dist/index18.js +110 -27
  33. package/dist/index18.js.map +1 -1
  34. package/dist/index19.js +360 -18
  35. package/dist/index19.js.map +1 -1
  36. package/dist/index2.js +726 -32
  37. package/dist/index2.js.map +1 -1
  38. package/dist/index20.js +5 -2416
  39. package/dist/index20.js.map +1 -1
  40. package/dist/index21.js +47 -109
  41. package/dist/index21.js.map +1 -1
  42. package/dist/index22.js +7 -107
  43. package/dist/index22.js.map +1 -1
  44. package/dist/index23.js +394 -65
  45. package/dist/index23.js.map +1 -1
  46. package/dist/index24.js +40 -15
  47. package/dist/index24.js.map +1 -1
  48. package/dist/index25.js +20 -36
  49. package/dist/index25.js.map +1 -1
  50. package/dist/index26.js +2629 -1
  51. package/dist/index26.js.map +1 -1
  52. package/dist/index27.js +102 -310
  53. package/dist/index27.js.map +1 -1
  54. package/dist/index28.js +63 -17
  55. package/dist/index28.js.map +1 -1
  56. package/dist/index29.js +18 -8
  57. package/dist/index29.js.map +1 -1
  58. package/dist/index3.js +70 -8
  59. package/dist/index3.js.map +1 -1
  60. package/dist/index30.js +24 -8
  61. package/dist/index30.js.map +1 -1
  62. package/dist/index31.js +88 -167
  63. package/dist/index31.js.map +1 -1
  64. package/dist/index32.js +34 -494
  65. package/dist/index32.js.map +1 -1
  66. package/dist/index33.js +22 -10
  67. package/dist/index33.js.map +1 -1
  68. package/dist/index34.js +3 -4401
  69. package/dist/index34.js.map +1 -1
  70. package/dist/index35.js +20 -1
  71. package/dist/index35.js.map +1 -1
  72. package/dist/index36.js +18 -82
  73. package/dist/index36.js.map +1 -1
  74. package/dist/index37.js +8 -58
  75. package/dist/index37.js.map +1 -1
  76. package/dist/index38.js +4 -13
  77. package/dist/index38.js.map +1 -1
  78. package/dist/index39.js +10 -18
  79. package/dist/index39.js.map +1 -1
  80. package/dist/index4.js +25 -5
  81. package/dist/index4.js.map +1 -1
  82. package/dist/index40.js +7 -0
  83. package/dist/index40.js.map +1 -0
  84. package/dist/index41.js +3690 -0
  85. package/dist/index41.js.map +1 -0
  86. package/dist/index42.js +187 -0
  87. package/dist/index42.js.map +1 -0
  88. package/dist/index43.js +504 -0
  89. package/dist/index43.js.map +1 -0
  90. package/dist/index44.js +77 -0
  91. package/dist/index44.js.map +1 -0
  92. package/dist/index45.js +6 -0
  93. package/dist/index45.js.map +1 -0
  94. package/dist/index46.js +20 -0
  95. package/dist/index46.js.map +1 -0
  96. package/dist/index47.js +146 -0
  97. package/dist/index47.js.map +1 -0
  98. package/dist/index48.js +12 -0
  99. package/dist/index48.js.map +1 -0
  100. package/dist/index49.js +113 -0
  101. package/dist/index49.js.map +1 -0
  102. package/dist/index5.js +2 -1
  103. package/dist/index5.js.map +1 -1
  104. package/dist/index50.js +136 -0
  105. package/dist/index50.js.map +1 -0
  106. package/dist/index51.js +137 -0
  107. package/dist/index51.js.map +1 -0
  108. package/dist/index52.js +112 -0
  109. package/dist/index52.js.map +1 -0
  110. package/dist/index53.js +141 -0
  111. package/dist/index53.js.map +1 -0
  112. package/dist/index54.js +9 -0
  113. package/dist/index54.js.map +1 -0
  114. package/dist/index55.js +54 -0
  115. package/dist/index55.js.map +1 -0
  116. package/dist/index6.js +1 -1
  117. package/dist/index6.js.map +1 -1
  118. package/dist/index7.js +11 -3
  119. package/dist/index7.js.map +1 -1
  120. package/dist/index8.js +68 -7
  121. package/dist/index8.js.map +1 -1
  122. package/dist/index9.js +278 -15
  123. package/dist/index9.js.map +1 -1
  124. package/dist/presets/animation.d.ts +31 -0
  125. package/dist/presets/faceset.d.ts +30 -0
  126. package/dist/presets/index.d.ts +103 -0
  127. package/dist/presets/lpc.d.ts +89 -0
  128. package/dist/services/keyboardControls.d.ts +5 -0
  129. package/dist/services/loadMap.d.ts +123 -2
  130. package/dist/services/mmorpg.d.ts +12 -4
  131. package/dist/services/standalone.d.ts +54 -2
  132. package/package.json +22 -18
  133. package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
  134. package/src/Game/Map.ts +20 -2
  135. package/src/Game/Object.ts +163 -9
  136. package/src/Gui/Gui.ts +362 -17
  137. package/src/Resource.ts +150 -0
  138. package/src/RpgClient.ts +264 -58
  139. package/src/RpgClientEngine.ts +848 -36
  140. package/src/Sound.ts +253 -0
  141. package/src/components/{effects → animations}/animation.ce +3 -6
  142. package/src/components/{effects → animations}/index.ts +1 -1
  143. package/src/components/character.ce +193 -36
  144. package/src/components/dynamics/parse-value.ts +80 -0
  145. package/src/components/dynamics/text.ce +183 -0
  146. package/src/components/gui/box.ce +17 -0
  147. package/src/components/gui/dialogbox/index.ce +73 -35
  148. package/src/components/gui/dialogbox/selection.ce +16 -1
  149. package/src/components/gui/index.ts +3 -4
  150. package/src/components/index.ts +5 -1
  151. package/src/components/prebuilt/hp-bar.ce +255 -0
  152. package/src/components/prebuilt/index.ts +22 -0
  153. package/src/components/scenes/canvas.ce +12 -10
  154. package/src/components/scenes/draw-map.ce +6 -23
  155. package/src/components/scenes/event-layer.ce +9 -3
  156. package/src/core/setup.ts +2 -0
  157. package/src/index.ts +7 -2
  158. package/src/module.ts +72 -6
  159. package/src/presets/animation.ts +46 -0
  160. package/src/presets/faceset.ts +60 -0
  161. package/src/presets/index.ts +7 -1
  162. package/src/presets/lpc.ts +108 -0
  163. package/src/services/keyboardControls.ts +8 -0
  164. package/src/services/loadMap.ts +132 -3
  165. package/src/services/mmorpg.ts +29 -5
  166. package/src/services/standalone.ts +70 -6
  167. package/tsconfig.json +1 -1
  168. package/vite.config.ts +1 -1
  169. package/dist/Game/EffectManager.d.ts +0 -5
  170. package/dist/components/effects/index.d.ts +0 -4
  171. package/src/components/scenes/element-map.ce +0 -23
  172. /package/src/components/{effects → animations}/hit.ce +0 -0
package/dist/index22.js CHANGED
@@ -1,109 +1,9 @@
1
- import { useProps, useDefineProps, signal, animatedSignal, computed, trigger, mount, effect, h, Container, Rect, cond, Text } from 'canvasengine';
2
- import component$1 from './index37.js';
3
- import { inject } from './index6.js';
4
- import { RpgClientEngine } from './index2.js';
1
+ const WebSocketToken = "websocket";
2
+ class AbstractWebsocket {
3
+ constructor(context) {
4
+ this.context = context;
5
+ }
6
+ }
5
7
 
6
- function component($$props) {
7
- useProps($$props);
8
- const defineProps = useDefineProps($$props);
9
- var _a = defineProps(), message = _a.message, _choices = _a.choices, onFinish = _a.onFinish; _a.onInteraction;
10
- var client = inject(RpgClientEngine);
11
- var keyboardControls = client.globalConfig.keyboardControls;
12
- client.stopProcessingInput = true;
13
- var isDestroyed = false;
14
- var texts = [message()];
15
- var height = signal(250);
16
- var isTextCompleted = signal(false);
17
- var border = signal({ width: 5, color: "#595971" });
18
- var shadow = signal({ color: "#000", blur: 10, offsetX: 10, offsetY: 10 });
19
- var contentOpacity = animatedSignal(0, {
20
- duration: 1000,
21
- });
22
- var scaleX = animatedSignal(0, {
23
- duration: 500,
24
- });
25
- scaleX.set(1);
26
- contentOpacity.set(1);
27
- var currentTextIndex = signal(0);
28
- var currentText = computed(function () { var _a; return (_a = texts === null || texts === void 0 ? void 0 : texts[currentTextIndex()]) !== null && _a !== void 0 ? _a : ''; });
29
- var isChoiceDisplayed = signal(false);
30
- var text = computed(function () {
31
- var current = currentText();
32
- return typeof current === "string" ? current : current.text;
33
- });
34
- var choices = computed(function () {
35
- //const current = currentText();
36
- //return typeof current === "string" ? null : current.choices;
37
- return _choices;
38
- });
39
- var visibleSelection = computed(function () { return isChoiceDisplayed() && choices().length != 0; });
40
- var triggerSkip = trigger();
41
- var typewriter = {
42
- speed: 0.3,
43
- skip: triggerSkip,
44
- onComplete: function () {
45
- isTextCompleted.set(true);
46
- }
47
- };
48
- var textStyle = {
49
- wordWrap: true,
50
- wordWrapWidth: 700 - 256 - 80
51
- };
52
- signal({ x: 0, y: 0, width: 256, height: 256 });
53
- mount(function (element) {
54
- var dialogbox = element.props.children[0];
55
- return function () {
56
- dialogbox.directives.controls.onDestroy();
57
- isDestroyed = true;
58
- // Wait destroy is finished before start processing input
59
- setTimeout(function () {
60
- client.stopProcessingInput = false;
61
- }, 500);
62
- };
63
- });
64
- var controls = signal({
65
- next: {
66
- bind: keyboardControls.action,
67
- keyDown: function (e) {
68
- if (isDestroyed)
69
- return;
70
- if (isChoiceDisplayed()) {
71
- // If choices are displayed, do nothing (wait for selection)
72
- return;
73
- }
74
- // If text is still typing, just skip (fast forward) the animation
75
- if (!isTextCompleted()) {
76
- triggerSkip.start();
77
- isTextCompleted.set(true);
78
- }
79
- else {
80
- var isFinished = currentTextIndex() === texts.length - 1;
81
- currentTextIndex.update(function (index) {
82
- if (index < texts.length - 1) {
83
- return index + 1;
84
- }
85
- return index;
86
- });
87
- isChoiceDisplayed.set(false);
88
- isTextCompleted.set(false);
89
- if (isFinished && onFinish) {
90
- onFinish();
91
- }
92
- }
93
- },
94
- },
95
- });
96
- var onSelect = function (index) {
97
- onFinish(index);
98
- };
99
- effect(function () {
100
- if (choices().length != 0) {
101
- isChoiceDisplayed.set(true);
102
- }
103
- });
104
- let $this = h(Container, { justifyContent: 'center', alignItems: 'center', width: '100%', height: '100%' }, h(Container, { ref: 'dialogbox', scale: { x: scaleX }, anchor: [0.5, 0.5], width: 700, height, controls, positionType: 'absolute', bottom: 10 }, [h(Rect, { width: 700, height: 250, color: '#1a1a2e' }), h(Rect, { x: 0, y: 0, width: 700, height, color: '#1a1a2e', alpha: 0.9, borderRadius: 10, border, shadow }), h(Container, { flexDirection: 'row', width: 700, height, alpha: contentOpacity }, h(Container, { flexDirection: 'column' }, [h(Text, { text, color: '#fff', fontSize: 18, margin: 40, typewriter, style: textStyle }), cond(visibleSelection, () => h(component$1, { selectedIndex: 0, items: choices, onSelect }))]))]));
105
- return $this
106
- }
107
-
108
- export { component as default };
8
+ export { AbstractWebsocket, WebSocketToken };
109
9
  //# sourceMappingURL=index22.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index22.js","sources":["../src/components/gui/dialogbox/index.ce"],"sourcesContent":["<Container justifyContent=\"center\" alignItems=\"center\" width=\"100%\" height=\"100%\">\n <Container\n ref=\"dialogbox\"\n scale={{ x: scaleX }}\n anchor={[0.5, 0.5]}\n width={700}\n height\n controls\n positionType=\"absolute\"\n bottom={10}\n >\n <Rect width={700} height={250} color=\"#1a1a2e\" />\n <Rect\n x={0}\n y={0}\n width={700}\n height\n color=\"#1a1a2e\"\n alpha={0.9}\n borderRadius={10}\n border\n shadow\n />\n <Container\n flexDirection=\"row\"\n width={700}\n height\n alpha={contentOpacity}\n >\n <Container flexDirection=\"column\">\n <Text\n text\n color=\"#fff\"\n fontSize={18}\n margin={40}\n typewriter\n style={textStyle}\n />\n @if (visibleSelection) {\n <Selection selectedIndex={0} items={choices} onSelect />\n }\n </Container>\n </Container>\n</Container> \n\n \n</Container>\n<script>\n import Selection from './selection.ce'\n\n import {\n animatedSignal,\n computed,\n effect,\n signal,\n trigger,\n mount\n } from \"canvasengine\";\n\n import { inject } from \"../../../core/inject\";\n import { RpgClientEngine } from \"../../../RpgClientEngine\";\n\n const {\n message,\n choices: _choices,\n onFinish,\n onInteraction\n } = defineProps();\n\n const client = inject(RpgClientEngine);\n const keyboardControls = client.globalConfig.keyboardControls;\n\n client.stopProcessingInput = true;\n let isDestroyed = false;\n\n const texts = [message()]\n const height = signal(250);\n const isTextCompleted = signal(false);\n\n const drawSpeaker = (g) => {\n g.beginFill(0xffa500); // Orange color\n g.lineStyle(2, 0x000000); // Black border\n g.moveTo(0, 0);\n g.lineTo(70, 0);\n g.lineTo(80, 15);\n g.lineTo(70, 30);\n g.lineTo(0, 30);\n g.lineTo(0, 0);\n g.endFill();\n };\n\n const border = signal({ width: 5, color: \"#595971\" });\n const shadow = signal({ color: \"#000\", blur: 10, offsetX: 10, offsetY: 10 });\n\n const contentOpacity = animatedSignal(0, {\n duration: 1000,\n });\n\n const scaleX = animatedSignal(0, {\n duration: 500,\n });\n\n scaleX.set(1);\n contentOpacity.set(1);\n\n const currentTextIndex = signal(0);\n const currentText = computed(() => texts?.[currentTextIndex()] ?? '');\n const isChoiceDisplayed = signal(false);\n\n const text = computed(() => {\n const current = currentText();\n return typeof current === \"string\" ? current : current.text;\n });\n\n const choices = computed(() => {\n //const current = currentText();\n //return typeof current === \"string\" ? null : current.choices;\n return _choices;\n });\n\n const visibleSelection = computed(() => isChoiceDisplayed() && choices().length != 0)\n\n const triggerSkip = trigger();\n\n const typewriter = {\n speed: 0.3,\n skip: triggerSkip,\n onComplete: () => {\n isTextCompleted.set(true);\n }\n }\n\n const textStyle = {\n wordWrap: true,\n wordWrapWidth: 700 - 256 - 80\n }\n\n const face = signal({ x: 0, y: 0, width: 256, height: 256 });\n\n mount((element) => {\n const [dialogbox] = element.props.children\n return () => {\n dialogbox.directives.controls.onDestroy()\n isDestroyed = true;\n // Wait destroy is finished before start processing input\n setTimeout(() => {\n client.stopProcessingInput = false;\n }, 500)\n }\n })\n\n const controls = signal({\n next: {\n bind: keyboardControls.action,\n keyDown(e) {\n if (isDestroyed) return;\n if (isChoiceDisplayed()) {\n // If choices are displayed, do nothing (wait for selection)\n return;\n }\n\n // If text is still typing, just skip (fast forward) the animation\n if (!isTextCompleted()) {\n triggerSkip.start();\n isTextCompleted.set(true);\n }\n else {\n const isFinished = currentTextIndex() === texts.length - 1;\n currentTextIndex.update((index) => {\n if (index < texts.length - 1) {\n return index + 1;\n }\n return index;\n });\n isChoiceDisplayed.set(false);\n isTextCompleted.set(false);\n if (isFinished && onFinish) {\n onFinish();\n } \n }\n },\n },\n });\n\n const onSelect = (index) => {\n onFinish(index);\n }\n \n effect(() => {\n if (choices().length != 0) {\n isChoiceDisplayed.set(true);\n }\n });\n</script>"],"names":["Selection"],"mappings":";;;;;AAWqB,SAAS,SAAS,CAAC,OAAO,EAAE;AACjD,QAAuB,QAAQ,CAAC,OAAO;AACvC,QAAQ,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO;AAClD,QAAW,IAAC,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAiB,EAAE,CAAC;AACxH,IAAI,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;AACpC,IAAI,gBAAgB,GAAG,MAAM,CAAC,YAAY,CAAC,gBAAgB;AAC3D,MAAM,CAAC,mBAAmB,GAAG,IAAI;AACjC,IAAI,WAAW,GAAG,KAAK;AACvB,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;AACvB,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,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AAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAACA,WAAS,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjuB,QAAQ,OAAO;AACf;;;;"}
1
+ {"version":3,"file":"index22.js","sources":["../src/services/AbstractSocket.ts"],"sourcesContent":["import { Context } from \"@signe/di\";\n\nexport const WebSocketToken = \"websocket\";\n\nexport abstract class AbstractWebsocket {\n constructor(protected context: Context) {}\n\n abstract connection(listeners?: (data: any) => void): Promise<void>;\n abstract emit(event: string, data: any): void;\n abstract on(event: string, callback: (data: any) => void): void;\n abstract off(event: string, callback: (data: any) => void): void;\n abstract updateProperties(params: { room: string, host?: string }): void;\n abstract reconnect(listeners?: (data: any) => void): void;\n}\n"],"names":[],"mappings":"AAEO,MAAM,cAAA,GAAiB;AAEvB,MAAe,iBAAA,CAAkB;AAAA,EACtC,YAAsB,OAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EAAmB;AAQ3C;;;;"}
package/dist/index23.js CHANGED
@@ -1,71 +1,400 @@
1
- import { useProps, useDefineProps, animatedSignal, signal, mount, tick, h, Text } from 'canvasengine';
2
- import { Direction } from '@rpgjs/common';
1
+ import { __name } from './index34.js';
2
+ import { isSignal, isComputed, isObjectSubject, isArraySubject } from './index35.js';
3
3
 
4
- function component($$props) {
5
- useProps($$props);
6
- const defineProps = useDefineProps($$props);
7
- var _a = defineProps({
8
- duration: {
9
- default: 1000
10
- },
11
- color: {
12
- default: 'black'
13
- }
14
- }), text = _a.text, direction = _a.direction, onFinish = _a.onFinish, duration = _a.duration, color = _a.color, positionX = _a.x, positionY = _a.y;
15
- var scale = animatedSignal(1, {
16
- duration: duration(),
17
- });
18
- var randomPosition = function () { return Math.floor(Math.random() * 60); };
19
- var initialY = randomPosition();
20
- var x = signal(positionX());
21
- var y = signal(positionY() - initialY);
22
- var velocityX = 0;
23
- var velocityY = 0;
24
- var speed = 200;
25
- switch (direction()) {
26
- case Direction.Left:
27
- velocityX = speed;
28
- break;
29
- case Direction.Right:
30
- velocityX = -200;
31
- break;
32
- case Direction.Up:
33
- velocityY = speed;
34
- break;
35
- case Direction.Down:
36
- velocityY = -200;
37
- break;
38
- }
39
- velocityX += (Math.random() - 0.5) * 100;
40
- velocityY += (Math.random() - 0.5) * 100;
41
- var gravity = 500;
42
- var deceleration = 0.98;
43
- mount(function () {
44
- scale.set(0.1);
45
- });
46
- var elapsedTime = 0;
47
- tick(function (_a) {
48
- var deltaTime = _a.deltaTime;
49
- elapsedTime += deltaTime;
50
- if (elapsedTime < duration()) {
51
- // Update position
52
- x.update(function (x) { return x + (velocityX * deltaTime) / 1000; });
53
- y.update(function (y) { return y + (velocityY * deltaTime) / 1000; });
54
- // Apply gravity
55
- velocityY += (gravity * deltaTime) / 1000;
56
- // Apply deceleration
57
- velocityX *= deceleration;
58
- velocityY *= deceleration;
59
- }
60
- else {
61
- if (onFinish) {
62
- onFinish();
4
+ // src/utils.ts
5
+ function isFunction(val) {
6
+ return {}.toString.call(val) === "[object Function]";
7
+ }
8
+ __name(isFunction, "isFunction");
9
+ function isClass(obj) {
10
+ return typeof obj === "function" && obj.prototype && obj.prototype.constructor === obj;
11
+ }
12
+ __name(isClass, "isClass");
13
+ var isObject = /* @__PURE__ */ __name((item) => item && typeof item === "object" && !Array.isArray(item) && item !== null, "isObject");
14
+ 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;
19
+ }
20
+ __name(isInstanceOfClass, "isInstanceOfClass");
21
+ 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;
29
+ }
30
+ __name(generateShortUUID, "generateShortUUID");
31
+
32
+ // src/core.ts
33
+ var DELETE_TOKEN = "$delete";
34
+ 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);
55
+ }, "syncClass");
56
+ 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;
72
+ }
73
+ __name(createStatesSnapshot, "createStatesSnapshot");
74
+ function setMetadata(target, key, value) {
75
+ const meta = target.constructor._propertyMetadata;
76
+ const propId = meta?.get(key);
77
+ if (propId) {
78
+ if (isSignal(target[propId])) {
79
+ target[propId].set(value);
80
+ } else {
81
+ target[propId] = value;
82
+ }
83
+ }
84
+ }
85
+ __name(setMetadata, "setMetadata");
86
+ var createSyncClass = /* @__PURE__ */ __name((currentClass, parentKey = null, parentClass = null, path = "") => {
87
+ currentClass.$path = path;
88
+ if (parentClass) {
89
+ currentClass.$valuesChanges = parentClass.$valuesChanges;
90
+ }
91
+ if (parentKey) {
92
+ setMetadata(currentClass, "id", parentKey);
93
+ }
94
+ if (currentClass.$snapshot) {
95
+ for (const key of currentClass.$snapshot.keys()) {
96
+ const signal = currentClass.$snapshot.get(key);
97
+ const syncToClient = signal.options?.syncToClient ?? true;
98
+ const persist2 = signal.options?.persist ?? true;
99
+ const transform = signal.options?.transform;
100
+ let signalValue = signal();
101
+ if (transform) {
102
+ signalValue = transform(signalValue);
103
+ }
104
+ if (isObject(signalValue) || Array.isArray(signalValue)) {
105
+ signalValue = {
106
+ ...signalValue
107
+ };
108
+ }
109
+ const transformedValue = signalValue;
110
+ const newPath = (path ? path + "." : "") + key;
111
+ if (syncToClient) {
112
+ currentClass.$valuesChanges.set(newPath, transformedValue);
113
+ }
114
+ if (persist2) {
115
+ if (parentClass) currentClass.$valuesChanges.setPersist(path, transformedValue);
116
+ }
117
+ if (isComputed(signal)) {
118
+ signal.observable.subscribe((newValue) => {
119
+ if (syncToClient) {
120
+ const transformedNewValue = transform ? transform(newValue) : newValue;
121
+ currentClass.$valuesChanges.set(newPath, transformedNewValue);
122
+ }
123
+ });
124
+ }
125
+ }
126
+ }
127
+ }, "createSyncClass");
128
+ var type = /* @__PURE__ */ __name((_signal, path, options = {}, currentInstance) => {
129
+ const { syncToClient = true, persist: persist2 = true, transform } = options;
130
+ let init = true;
131
+ const handleObjectSubject = /* @__PURE__ */ __name((value, propPath) => {
132
+ const newPath = `${propPath}${value.key ? `.${value.key}` : ""}`;
133
+ if ([
134
+ "add",
135
+ "reset",
136
+ "update"
137
+ ].includes(value.type)) {
138
+ if (isInstanceOfClass(value.value)) {
139
+ createSyncClass(value.value, value.key, currentInstance, newPath);
140
+ } else if (value.type === "update" && (isObject(value.value) || Array.isArray(value.value))) {
141
+ createSyncClass(value.value, value.key, currentInstance, newPath);
142
+ } else {
143
+ savePath(newPath, value.value);
144
+ }
145
+ } else if (value.type === "remove") {
146
+ savePath(newPath, DELETE_TOKEN);
147
+ }
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)) {
154
+ createSyncClass(item, value.key, currentInstance, newPath2);
155
+ } else {
156
+ savePath(newPath2, item);
157
+ }
158
+ });
159
+ return;
160
+ }
161
+ const newPath = `${propPath}.${value.index}`;
162
+ const firstItem = value.items?.[0];
163
+ if ([
164
+ "add",
165
+ "update"
166
+ ].includes(value.type) && firstItem !== void 0) {
167
+ if (isInstanceOfClass(firstItem)) {
168
+ createSyncClass(firstItem, value.key, currentInstance, newPath);
169
+ } else if (value.type === "update" && (isObject(firstItem) || Array.isArray(firstItem))) {
170
+ createSyncClass(firstItem, value.key, currentInstance, newPath);
171
+ } else {
172
+ savePath(newPath, firstItem);
173
+ }
174
+ } else if (value.type === "remove") {
175
+ savePath(newPath, DELETE_TOKEN);
176
+ }
177
+ }, "handleArraySubject");
178
+ const savePath = /* @__PURE__ */ __name((propPath, value) => {
179
+ const transformedValue = transform && value !== DELETE_TOKEN ? transform(value) : value;
180
+ if (syncToClient) {
181
+ currentInstance.$valuesChanges.set(propPath, transformedValue);
182
+ }
183
+ if (persist2 && currentInstance.$path !== void 0) {
184
+ currentInstance.$valuesChanges.setPersist(transformedValue == DELETE_TOKEN ? propPath : currentInstance.$path, transformedValue);
185
+ }
186
+ }, "savePath");
187
+ const setupSubscription = /* @__PURE__ */ __name((signal, signalPath) => {
188
+ if (!isSignal(signal)) return;
189
+ if (syncToClient && currentInstance.$valuesChanges) {
190
+ const initialValue = signal();
191
+ const transformedInitialValue = transform ? transform(initialValue) : initialValue;
192
+ currentInstance.$valuesChanges.set(signalPath, transformedInitialValue);
193
+ }
194
+ signal.options = options;
195
+ signal.observable.subscribe((value) => {
196
+ if (init) return;
197
+ if (currentInstance.$path !== void 0) {
198
+ const fullPath = `${currentInstance.$path ? currentInstance.$path + "." : ""}${signalPath}`;
199
+ if (isComputed(signal)) {
200
+ savePath(fullPath, value);
201
+ } else if (isObjectSubject(signal._subject)) {
202
+ handleObjectSubject(value, fullPath);
203
+ } else if (isArraySubject(signal._subject)) {
204
+ handleArraySubject(value, fullPath);
205
+ } else {
206
+ savePath(fullPath, value);
63
207
  }
208
+ }
209
+ });
210
+ if (!currentInstance.$snapshot) {
211
+ currentInstance.$snapshot = /* @__PURE__ */ new Map();
64
212
  }
65
- });
66
- let $this = h(Text, { x, y, zIndex: 10000, color, scale, size: 30, text });
67
- return $this
213
+ currentInstance.$snapshot.set(path, signal);
214
+ }, "setupSubscription");
215
+ if (!isSignal(_signal)) {
216
+ if (_signal && typeof _signal === "object" && !Array.isArray(_signal)) {
217
+ for (const key in _signal) {
218
+ if (Object.prototype.hasOwnProperty.call(_signal, key)) {
219
+ const value = _signal[key];
220
+ const propertyPath = `${path}.${key}`;
221
+ if (isSignal(value)) {
222
+ setupSubscription(value, propertyPath);
223
+ } else if (value && typeof value === "object" && !Array.isArray(value)) {
224
+ type(value, propertyPath, options, currentInstance);
225
+ }
226
+ }
68
227
  }
228
+ init = false;
229
+ }
230
+ return _signal;
231
+ }
232
+ setupSubscription(_signal, path);
233
+ init = false;
234
+ return _signal;
235
+ }, "type");
236
+
237
+ // src/decorators.ts
238
+ function sync(options) {
239
+ let classType;
240
+ let persist2 = true;
241
+ let syncToClient = true;
242
+ let transform;
243
+ if (typeof options === "function") {
244
+ classType = options;
245
+ } else if (typeof options === "object") {
246
+ classType = options.classType;
247
+ if (options.hasOwnProperty("persist")) {
248
+ persist2 = options.persist;
249
+ }
250
+ if (options.hasOwnProperty("syncToClient")) {
251
+ syncToClient = options.syncToClient;
252
+ }
253
+ if (options.hasOwnProperty("transform")) {
254
+ transform = options.transform;
255
+ }
256
+ }
257
+ return function(target, propertyKey) {
258
+ const privatePropertyKey = `__${propertyKey}`;
259
+ const getter = /* @__PURE__ */ __name(function() {
260
+ return this[privatePropertyKey];
261
+ }, "getter");
262
+ const setter = /* @__PURE__ */ __name(function(newVal) {
263
+ this[privatePropertyKey] = type(newVal, propertyKey, {
264
+ classType,
265
+ persist: persist2,
266
+ syncToClient,
267
+ transform
268
+ }, this);
269
+ }, "setter");
270
+ Object.defineProperty(target, propertyKey, {
271
+ get: getter,
272
+ set: setter,
273
+ enumerable: true,
274
+ configurable: true
275
+ });
276
+ };
277
+ }
278
+ __name(sync, "sync");
279
+ function id() {
280
+ return function(target, propertyKey) {
281
+ if (!target.constructor._propertyMetadata) {
282
+ target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
283
+ }
284
+ target.constructor._propertyMetadata.set("id", propertyKey);
285
+ };
286
+ }
287
+ __name(id, "id");
288
+ function users(options) {
289
+ return function(target, propertyKey) {
290
+ if (!target.constructor._propertyMetadata) {
291
+ target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
292
+ }
293
+ target.constructor._propertyMetadata.set("users", propertyKey);
294
+ sync(options)(target, propertyKey);
295
+ };
296
+ }
297
+ __name(users, "users");
298
+ function persist() {
299
+ return sync({
300
+ persist: true,
301
+ syncToClient: false
302
+ });
303
+ }
304
+ __name(persist, "persist");
305
+ function connected() {
306
+ return function(target, propertyKey) {
307
+ if (!target.constructor._propertyMetadata) {
308
+ target.constructor._propertyMetadata = /* @__PURE__ */ new Map();
309
+ }
310
+ target.constructor._propertyMetadata.set("connected", propertyKey);
311
+ sync({
312
+ persist: false
313
+ })(target, propertyKey);
314
+ };
315
+ }
316
+ __name(connected, "connected");
317
+ function load(rootInstance, values, valueIsObject) {
318
+ if (valueIsObject) {
319
+ loadFromObject(rootInstance, values);
320
+ } else {
321
+ loadFromPaths(rootInstance, values);
322
+ }
323
+ }
324
+ __name(load, "load");
325
+ function loadFromPaths(rootInstance, values) {
326
+ for (const [path, value] of Object.entries(values)) {
327
+ const parts = path.split(".");
328
+ loadValue(rootInstance, parts, value);
329
+ }
330
+ }
331
+ __name(loadFromPaths, "loadFromPaths");
332
+ function loadFromObject(rootInstance, values, currentPath = "") {
333
+ for (let key in values) {
334
+ const value = values[key];
335
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
336
+ if (typeof value === "object" && !Array.isArray(value) && value !== null) {
337
+ loadFromObject(rootInstance, value, newPath);
338
+ } else {
339
+ const parts = newPath.split(".");
340
+ loadValue(rootInstance, parts, value);
341
+ }
342
+ }
343
+ }
344
+ __name(loadFromObject, "loadFromObject");
345
+ function loadValue(rootInstance, parts, value) {
346
+ let current = rootInstance;
347
+ for (let i = 0; i < parts.length; i++) {
348
+ const part = parts[i];
349
+ if (i === parts.length - 1) {
350
+ if (value == DELETE_TOKEN) {
351
+ if (isSignal(current)) {
352
+ current = current();
353
+ }
354
+ Reflect.deleteProperty(current, part);
355
+ } else if (current[part]?._subject) {
356
+ current[part].set(value);
357
+ } else if (isSignal(current) && Array.isArray(current()) && !isNaN(Number(part))) {
358
+ current()[Number(part)] = value;
359
+ } else {
360
+ current[part] = value;
361
+ }
362
+ } else {
363
+ if (isSignal(current)) {
364
+ current = current();
365
+ }
366
+ const currentValue = current[part];
367
+ if (currentValue === void 0) {
368
+ const parentInstance = getByPath(rootInstance, parts.slice(0, i).join("."));
369
+ const classType = parentInstance?.options?.classType;
370
+ if (classType) {
371
+ current[part] = !isClass(classType) ? classType(part) : new classType();
372
+ setMetadata(current[part], "id", part);
373
+ } else {
374
+ current[part] = {};
375
+ }
376
+ }
377
+ current = current[part];
378
+ }
379
+ }
380
+ }
381
+ __name(loadValue, "loadValue");
382
+ function getByPath(root, path) {
383
+ const parts = path.split(".");
384
+ let current = root;
385
+ for (const part of parts) {
386
+ if (isSignal(current)) {
387
+ current = current();
388
+ }
389
+ if (current[part]) {
390
+ current = current[part];
391
+ } else {
392
+ return void 0;
393
+ }
394
+ }
395
+ return current;
396
+ }
397
+ __name(getByPath, "getByPath");
69
398
 
70
- export { component as default };
399
+ export { DELETE_TOKEN, connected, createStatesSnapshot, createSyncClass, generateShortUUID, getByPath, id, isClass, isFunction, isInstanceOfClass, isObject, load, persist, setMetadata, sync, syncClass, type, users };
71
400
  //# sourceMappingURL=index23.js.map