@rpgjs/client 5.0.0-beta.7 → 5.0.0-beta.8

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 (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/Game/Map.js +2 -1
  3. package/dist/Game/Map.js.map +1 -1
  4. package/dist/Game/Object.d.ts +17 -9
  5. package/dist/Game/Object.js +1 -12
  6. package/dist/Game/Object.js.map +1 -1
  7. package/dist/Gui/Gui.d.ts +17 -4
  8. package/dist/Gui/Gui.js +63 -33
  9. package/dist/Gui/Gui.js.map +1 -1
  10. package/dist/Gui/Gui.spec.d.ts +1 -0
  11. package/dist/Resource.js +1 -1
  12. package/dist/Resource.js.map +1 -1
  13. package/dist/RpgClient.d.ts +35 -2
  14. package/dist/RpgClientEngine.d.ts +41 -5
  15. package/dist/RpgClientEngine.js +43 -3
  16. package/dist/RpgClientEngine.js.map +1 -1
  17. package/dist/components/character.ce.js +225 -2
  18. package/dist/components/character.ce.js.map +1 -1
  19. package/dist/components/dynamics/bar.ce.js +96 -0
  20. package/dist/components/dynamics/bar.ce.js.map +1 -0
  21. package/dist/components/dynamics/image.ce.js +23 -0
  22. package/dist/components/dynamics/image.ce.js.map +1 -0
  23. package/dist/components/dynamics/parse-value.d.ts +3 -0
  24. package/dist/components/dynamics/parse-value.js +51 -35
  25. package/dist/components/dynamics/parse-value.js.map +1 -1
  26. package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
  27. package/dist/components/dynamics/shape-utils.d.ts +16 -0
  28. package/dist/components/dynamics/shape-utils.js +73 -0
  29. package/dist/components/dynamics/shape-utils.js.map +1 -0
  30. package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
  31. package/dist/components/dynamics/shape.ce.js +83 -0
  32. package/dist/components/dynamics/shape.ce.js.map +1 -0
  33. package/dist/components/dynamics/text.ce.js +28 -41
  34. package/dist/components/dynamics/text.ce.js.map +1 -1
  35. package/dist/components/player-components-utils.d.ts +67 -0
  36. package/dist/components/player-components-utils.js +162 -0
  37. package/dist/components/player-components-utils.js.map +1 -0
  38. package/dist/components/player-components-utils.spec.d.ts +1 -0
  39. package/dist/components/player-components.ce.js +188 -0
  40. package/dist/components/player-components.ce.js.map +1 -0
  41. package/dist/core/setup.js.map +1 -1
  42. package/dist/module.js +3 -0
  43. package/dist/module.js.map +1 -1
  44. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js +197 -3
  45. package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js.map +1 -1
  46. package/dist/node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js +1 -1
  47. package/dist/services/loadMap.d.ts +6 -0
  48. package/dist/services/loadMap.js.map +1 -1
  49. package/package.json +4 -4
  50. package/src/Game/Map.ts +12 -2
  51. package/src/Game/Object.ts +22 -35
  52. package/src/Gui/Gui.spec.ts +273 -0
  53. package/src/Gui/Gui.ts +105 -50
  54. package/src/Resource.ts +1 -2
  55. package/src/RpgClient.ts +36 -2
  56. package/src/RpgClientEngine.ts +64 -10
  57. package/src/components/character.ce +281 -1
  58. package/src/components/dynamics/bar.ce +87 -0
  59. package/src/components/dynamics/image.ce +20 -0
  60. package/src/components/dynamics/parse-value.spec.ts +41 -0
  61. package/src/components/dynamics/parse-value.ts +102 -37
  62. package/src/components/dynamics/shape-utils.spec.ts +46 -0
  63. package/src/components/dynamics/shape-utils.ts +61 -0
  64. package/src/components/dynamics/shape.ce +89 -0
  65. package/src/components/dynamics/text.ce +34 -149
  66. package/src/components/player-components-utils.spec.ts +109 -0
  67. package/src/components/player-components-utils.ts +205 -0
  68. package/src/components/player-components.ce +221 -0
  69. package/src/core/setup.ts +2 -2
  70. package/src/module.ts +5 -1
  71. package/src/services/loadMap.ts +2 -0
  72. package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js +0 -227
  73. package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js.map +0 -1
@@ -1,44 +1,60 @@
1
1
  import { computed } from "canvasengine";
2
2
  //#region src/components/dynamics/parse-value.ts
3
- var parseDynamicValue = (value, object) => {
4
- if (typeof value !== "string") return computed(() => String(value ?? ""));
5
- const pattern = /\{([^}]+)\}/g;
6
- const matches = [];
7
- let match;
8
- while ((match = pattern.exec(value)) !== null) matches.push({
9
- property: match[1],
10
- fullMatch: match[0],
11
- index: match.index
12
- });
13
- if (matches.length === 0) return computed(() => value);
14
- return computed(() => {
15
- let result = value;
16
- for (let i = matches.length - 1; i >= 0; i--) {
17
- const { property, fullMatch } = matches[i];
18
- let propertyValue = "";
19
- try {
20
- const propertyPath = property.split(".");
21
- let currentValue = object;
22
- for (let j = 0; j < propertyPath.length; j++) {
23
- const prop = propertyPath[j];
24
- if (typeof currentValue === "function") currentValue = currentValue();
25
- if (currentValue && typeof currentValue === "object" && prop in currentValue) currentValue = currentValue[prop];
26
- else {
27
- currentValue = void 0;
28
- break;
29
- }
30
- }
31
- if (typeof currentValue === "function") currentValue = currentValue();
32
- propertyValue = currentValue != null ? String(currentValue) : "";
33
- } catch (error) {
34
- propertyValue = "";
3
+ var readSignal = (value) => typeof value === "function" ? value() : value;
4
+ var DYNAMIC_VALUE_PATTERN = /\{([^}]+)\}/g;
5
+ var hasDynamicValue = (value) => {
6
+ value = readSignal(value);
7
+ if (typeof value !== "string") return false;
8
+ DYNAMIC_VALUE_PATTERN.lastIndex = 0;
9
+ return DYNAMIC_VALUE_PATTERN.test(value);
10
+ };
11
+ var resolveDynamicSnapshot = (value, object) => {
12
+ value = readSignal(value);
13
+ if (Array.isArray(value)) return value.map((entry) => resolveDynamicSnapshot(entry, object));
14
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, resolveDynamicSnapshot(entry, object)]));
15
+ return resolveDynamicValue(value, object);
16
+ };
17
+ var getDynamicValue = (property, object) => {
18
+ try {
19
+ const propertyPath = property.split(".");
20
+ let currentValue = object;
21
+ for (let j = 0; j < propertyPath.length; j++) {
22
+ let prop = propertyPath[j];
23
+ currentValue = readSignal(currentValue);
24
+ if (j === 0) {
25
+ if (prop === "hp") prop = "hpSignal";
26
+ if (prop === "sp") prop = "spSignal";
27
+ if (prop === "param") prop = "_param";
35
28
  }
36
- result = result.replace(fullMatch, propertyValue);
29
+ if (currentValue && typeof currentValue === "object" && prop in currentValue) currentValue = currentValue[prop];
30
+ else return;
37
31
  }
38
- return result;
32
+ return readSignal(currentValue);
33
+ } catch (error) {
34
+ return;
35
+ }
36
+ };
37
+ var resolveDynamicValue = (value, object) => {
38
+ value = readSignal(value);
39
+ if (typeof value !== "string") return value;
40
+ return value.replace(DYNAMIC_VALUE_PATTERN, (fullMatch, property) => {
41
+ const propertyValue = getDynamicValue(property, object);
42
+ if (propertyValue == null && property.startsWith("$")) return fullMatch;
43
+ return propertyValue != null ? String(propertyValue) : "";
39
44
  });
40
45
  };
46
+ var resolveDynamicProp = (value, object) => {
47
+ if (Array.isArray(value) || value && typeof value === "object" && typeof value !== "function") return computed(() => resolveDynamicSnapshot(value, object));
48
+ if (typeof value === "function" || hasDynamicValue(value)) return computed(() => resolveDynamicValue(value, object));
49
+ return value;
50
+ };
51
+ var resolveDynamicProps = (props, object) => {
52
+ props = readSignal(props);
53
+ if (Array.isArray(props)) return computed(() => resolveDynamicSnapshot(props, object));
54
+ if (props && typeof props === "object") return Object.fromEntries(Object.entries(props).map(([key, value]) => [key, resolveDynamicProp(value, object)]));
55
+ return resolveDynamicProp(props, object);
56
+ };
41
57
  //#endregion
42
- export { parseDynamicValue };
58
+ export { resolveDynamicProps, resolveDynamicValue };
43
59
 
44
60
  //# sourceMappingURL=parse-value.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-value.js","names":[],"sources":["../../../src/components/dynamics/parse-value.ts"],"sourcesContent":["import { computed } from \"canvasengine\";\n\ninterface MatchResult {\n property: string;\n fullMatch: string;\n index: number;\n}\n\nexport const parseDynamicValue = (value: any, object?: any) => {\n if (typeof value !== 'string') {\n return computed(() => String(value ?? ''));\n }\n\n // Find all dynamic references like {propertyName}\n const pattern = /\\{([^}]+)\\}/g;\n const matches: MatchResult[] = [];\n let match;\n \n while ((match = pattern.exec(value)) !== null) {\n matches.push({\n property: match[1],\n fullMatch: match[0],\n index: match.index!\n });\n }\n\n // If no dynamic references found, return simple computed\n if (matches.length === 0) {\n return computed(() => value);\n }\n\n // Create computed that tracks all referenced signals\n return computed(() => {\n let result = value;\n \n // Replace from end to start to preserve indices\n for (let i = matches.length - 1; i >= 0; i--) {\n const { property, fullMatch } = matches[i];\n \n // Try to access the property from the object\n // Support nested properties like {param.maxHp}\n let propertyValue = '';\n try {\n const propertyPath = property.split('.');\n let currentValue = object;\n \n for (let j = 0; j < propertyPath.length; j++) {\n const prop = propertyPath[j];\n \n // Check if currentValue is a signal (function) and call it\n if (typeof currentValue === 'function') {\n currentValue = currentValue();\n }\n \n // Access the property\n if (currentValue && typeof currentValue === 'object' && prop in currentValue) {\n currentValue = currentValue[prop];\n } else {\n currentValue = undefined;\n break;\n }\n }\n \n // If the final value is a signal, call it\n if (typeof currentValue === 'function') {\n currentValue = currentValue();\n }\n \n propertyValue = currentValue != null ? String(currentValue) : '';\n } catch (error) {\n // If property doesn't exist or can't be accessed, use empty string\n propertyValue = '';\n }\n \n result = result.replace(fullMatch, propertyValue);\n }\n \n return result;\n });\n};\n"],"mappings":";;AAQA,IAAa,qBAAqB,OAAY,WAAiB;CAC3D,IAAI,OAAO,UAAU,UACjB,OAAO,eAAe,OAAO,SAAS,GAAG,CAAC;CAI9C,MAAM,UAAU;CAChB,MAAM,UAAyB,EAAE;CACjC,IAAI;CAEJ,QAAQ,QAAQ,QAAQ,KAAK,MAAM,MAAM,MACrC,QAAQ,KAAK;EACT,UAAU,MAAM;EAChB,WAAW,MAAM;EACjB,OAAO,MAAM;EAChB,CAAC;CAIN,IAAI,QAAQ,WAAW,GACnB,OAAO,eAAe,MAAM;CAIhC,OAAO,eAAe;EAClB,IAAI,SAAS;EAGb,KAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;GAC1C,MAAM,EAAE,UAAU,cAAc,QAAQ;GAIxC,IAAI,gBAAgB;GACpB,IAAI;IACA,MAAM,eAAe,SAAS,MAAM,IAAI;IACxC,IAAI,eAAe;IAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;KAC1C,MAAM,OAAO,aAAa;KAG1B,IAAI,OAAO,iBAAiB,YACxB,eAAe,cAAc;KAIjC,IAAI,gBAAgB,OAAO,iBAAiB,YAAY,QAAQ,cAC5D,eAAe,aAAa;UACzB;MACH,eAAe,KAAA;MACf;;;IAKR,IAAI,OAAO,iBAAiB,YACxB,eAAe,cAAc;IAGjC,gBAAgB,gBAAgB,OAAO,OAAO,aAAa,GAAG;YACzD,OAAO;IAEZ,gBAAgB;;GAGpB,SAAS,OAAO,QAAQ,WAAW,cAAc;;EAGrD,OAAO;GACT"}
1
+ {"version":3,"file":"parse-value.js","names":[],"sources":["../../../src/components/dynamics/parse-value.ts"],"sourcesContent":["import { computed } from \"canvasengine\";\n\ninterface MatchResult {\n property: string;\n fullMatch: string;\n index: number;\n}\n\nconst readSignal = (value: any) => typeof value === 'function' ? value() : value;\nconst DYNAMIC_VALUE_PATTERN = /\\{([^}]+)\\}/g;\n\nconst hasDynamicValue = (value: any) => {\n value = readSignal(value);\n if (typeof value !== 'string') return false;\n DYNAMIC_VALUE_PATTERN.lastIndex = 0;\n return DYNAMIC_VALUE_PATTERN.test(value);\n};\n\nconst resolveDynamicSnapshot = (value: any, object?: any): any => {\n value = readSignal(value);\n\n if (Array.isArray(value)) {\n return value.map((entry) => resolveDynamicSnapshot(entry, object));\n }\n\n if (value && typeof value === 'object') {\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, resolveDynamicSnapshot(entry, object)])\n );\n }\n\n return resolveDynamicValue(value, object);\n};\n\nexport const getDynamicValue = (property: string, object?: any) => {\n try {\n const propertyPath = property.split('.');\n let currentValue = object;\n\n for (let j = 0; j < propertyPath.length; j++) {\n let prop = propertyPath[j];\n\n currentValue = readSignal(currentValue);\n\n if (j === 0) {\n if (prop === 'hp') prop = 'hpSignal';\n if (prop === 'sp') prop = 'spSignal';\n if (prop === 'param') prop = '_param';\n }\n\n if (currentValue && typeof currentValue === 'object' && prop in currentValue) {\n currentValue = currentValue[prop];\n } else {\n return undefined;\n }\n }\n\n return readSignal(currentValue);\n } catch (error) {\n return undefined;\n }\n};\n\nexport const resolveDynamicValue = (value: any, object?: any): any => {\n value = readSignal(value);\n\n if (typeof value !== 'string') {\n return value;\n }\n\n return value.replace(DYNAMIC_VALUE_PATTERN, (fullMatch, property) => {\n const propertyValue = getDynamicValue(property, object);\n if (propertyValue == null && property.startsWith('$')) return fullMatch;\n return propertyValue != null ? String(propertyValue) : '';\n });\n};\n\nconst resolveDynamicProp = (value: any, object?: any): any => {\n if (Array.isArray(value) || (value && typeof value === 'object' && typeof value !== 'function')) {\n return computed(() => resolveDynamicSnapshot(value, object));\n }\n\n if (typeof value === 'function' || hasDynamicValue(value)) {\n return computed(() => resolveDynamicValue(value, object));\n }\n\n return value;\n};\n\nexport const resolveDynamicProps = (props: any, object?: any): any => {\n props = readSignal(props);\n\n if (Array.isArray(props)) {\n return computed(() => resolveDynamicSnapshot(props, object));\n }\n\n if (props && typeof props === 'object') {\n return Object.fromEntries(\n Object.entries(props).map(([key, value]) => [key, resolveDynamicProp(value, object)])\n );\n }\n\n return resolveDynamicProp(props, object);\n};\n\nexport const parseDynamicValue = (value: any, object?: any) => {\n if (typeof value !== 'string') {\n return computed(() => String(value ?? ''));\n }\n\n // Find all dynamic references like {propertyName}\n const matches: MatchResult[] = [];\n let match;\n\n DYNAMIC_VALUE_PATTERN.lastIndex = 0;\n while ((match = DYNAMIC_VALUE_PATTERN.exec(value)) !== null) {\n matches.push({\n property: match[1],\n fullMatch: match[0],\n index: match.index!\n });\n }\n\n // If no dynamic references found, return simple computed\n if (matches.length === 0) {\n return computed(() => value);\n }\n\n // Create computed that tracks all referenced signals\n return computed(() => {\n let result = value;\n \n // Replace from end to start to preserve indices\n for (let i = matches.length - 1; i >= 0; i--) {\n const { property, fullMatch } = matches[i];\n \n const currentValue = getDynamicValue(property, object);\n const propertyValue = currentValue != null ? String(currentValue) : property.startsWith('$') ? fullMatch : '';\n \n result = result.replace(fullMatch, propertyValue);\n }\n \n return result;\n });\n};\n"],"mappings":";;AAQA,IAAM,cAAc,UAAe,OAAO,UAAU,aAAa,OAAO,GAAG;AAC3E,IAAM,wBAAwB;AAE9B,IAAM,mBAAmB,UAAe;CACpC,QAAQ,WAAW,MAAM;CACzB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,sBAAsB,YAAY;CAClC,OAAO,sBAAsB,KAAK,MAAM;;AAG5C,IAAM,0BAA0B,OAAY,WAAsB;CAC9D,QAAQ,WAAW,MAAM;CAEzB,IAAI,MAAM,QAAQ,MAAM,EACpB,OAAO,MAAM,KAAK,UAAU,uBAAuB,OAAO,OAAO,CAAC;CAGtE,IAAI,SAAS,OAAO,UAAU,UAC1B,OAAO,OAAO,YACV,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,uBAAuB,OAAO,OAAO,CAAC,CAAC,CAC5F;CAGL,OAAO,oBAAoB,OAAO,OAAO;;AAG7C,IAAa,mBAAmB,UAAkB,WAAiB;CAC/D,IAAI;EACA,MAAM,eAAe,SAAS,MAAM,IAAI;EACxC,IAAI,eAAe;EAEnB,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;GAC1C,IAAI,OAAO,aAAa;GAExB,eAAe,WAAW,aAAa;GAEvC,IAAI,MAAM,GAAG;IACT,IAAI,SAAS,MAAM,OAAO;IAC1B,IAAI,SAAS,MAAM,OAAO;IAC1B,IAAI,SAAS,SAAS,OAAO;;GAGjC,IAAI,gBAAgB,OAAO,iBAAiB,YAAY,QAAQ,cAC5D,eAAe,aAAa;QAE5B;;EAIR,OAAO,WAAW,aAAa;UAC1B,OAAO;EACZ;;;AAIR,IAAa,uBAAuB,OAAY,WAAsB;CAClE,QAAQ,WAAW,MAAM;CAEzB,IAAI,OAAO,UAAU,UACjB,OAAO;CAGX,OAAO,MAAM,QAAQ,wBAAwB,WAAW,aAAa;EACjE,MAAM,gBAAgB,gBAAgB,UAAU,OAAO;EACvD,IAAI,iBAAiB,QAAQ,SAAS,WAAW,IAAI,EAAE,OAAO;EAC9D,OAAO,iBAAiB,OAAO,OAAO,cAAc,GAAG;GACzD;;AAGN,IAAM,sBAAsB,OAAY,WAAsB;CAC1D,IAAI,MAAM,QAAQ,MAAM,IAAK,SAAS,OAAO,UAAU,YAAY,OAAO,UAAU,YAChF,OAAO,eAAe,uBAAuB,OAAO,OAAO,CAAC;CAGhE,IAAI,OAAO,UAAU,cAAc,gBAAgB,MAAM,EACrD,OAAO,eAAe,oBAAoB,OAAO,OAAO,CAAC;CAG7D,OAAO;;AAGX,IAAa,uBAAuB,OAAY,WAAsB;CAClE,QAAQ,WAAW,MAAM;CAEzB,IAAI,MAAM,QAAQ,MAAM,EACpB,OAAO,eAAe,uBAAuB,OAAO,OAAO,CAAC;CAGhE,IAAI,SAAS,OAAO,UAAU,UAC1B,OAAO,OAAO,YACV,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,mBAAmB,OAAO,OAAO,CAAC,CAAC,CACxF;CAGL,OAAO,mBAAmB,OAAO,OAAO"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export declare function getShapePointBounds(points?: any[], toNumber?: (value: any, fallback?: number) => number): {
2
+ minX: number;
3
+ minY: number;
4
+ maxX: number;
5
+ maxY: number;
6
+ };
7
+ export declare function getShapeBox(cfg: any, toNumber?: (value: any, fallback?: number) => number): {
8
+ width: any;
9
+ height: any;
10
+ offsetX: number;
11
+ offsetY: number;
12
+ };
13
+ export declare function translatePolygonPoints(points: any[] | undefined, box: {
14
+ offsetX: number;
15
+ offsetY: number;
16
+ }, toNumber?: (value: any, fallback?: number) => number): number[];
@@ -0,0 +1,73 @@
1
+ //#region src/components/dynamics/shape-utils.ts
2
+ var defaultToNumber = (value, fallback = 0) => {
3
+ const num = typeof value === "number" ? value : parseFloat(value);
4
+ return Number.isFinite(num) ? num : fallback;
5
+ };
6
+ function getShapePointBounds(points = [], toNumber = defaultToNumber) {
7
+ if (!Array.isArray(points) || points.length < 2) return {
8
+ minX: 0,
9
+ minY: 0,
10
+ maxX: 1,
11
+ maxY: 1
12
+ };
13
+ let minX = Infinity;
14
+ let minY = Infinity;
15
+ let maxX = -Infinity;
16
+ let maxY = -Infinity;
17
+ for (let i = 0; i < points.length; i += 2) {
18
+ const x = toNumber(points[i], 0);
19
+ const y = toNumber(points[i + 1], 0);
20
+ minX = Math.min(minX, x);
21
+ minY = Math.min(minY, y);
22
+ maxX = Math.max(maxX, x);
23
+ maxY = Math.max(maxY, y);
24
+ }
25
+ return {
26
+ minX,
27
+ minY,
28
+ maxX,
29
+ maxY
30
+ };
31
+ }
32
+ function getShapeBox(cfg, toNumber = defaultToNumber) {
33
+ if (cfg.type === "circle") return {
34
+ width: cfg.radius * 2,
35
+ height: cfg.radius * 2,
36
+ offsetX: 0,
37
+ offsetY: 0
38
+ };
39
+ if (cfg.type === "line") {
40
+ const minX = Math.min(cfg.x1, cfg.x2);
41
+ const minY = Math.min(cfg.y1, cfg.y2);
42
+ const maxX = Math.max(cfg.x1, cfg.x2);
43
+ const maxY = Math.max(cfg.y1, cfg.y2);
44
+ return {
45
+ width: Math.max(1, maxX - minX),
46
+ height: Math.max(1, maxY - minY),
47
+ offsetX: -minX,
48
+ offsetY: -minY
49
+ };
50
+ }
51
+ if (cfg.type === "polygon") {
52
+ const bounds = getShapePointBounds(cfg.points, toNumber);
53
+ return {
54
+ width: Math.max(1, bounds.maxX - bounds.minX),
55
+ height: Math.max(1, bounds.maxY - bounds.minY),
56
+ offsetX: -bounds.minX,
57
+ offsetY: -bounds.minY
58
+ };
59
+ }
60
+ return {
61
+ width: cfg.width,
62
+ height: cfg.height,
63
+ offsetX: 0,
64
+ offsetY: 0
65
+ };
66
+ }
67
+ function translatePolygonPoints(points = [], box, toNumber = defaultToNumber) {
68
+ return points.map((point, index) => toNumber(point, 0) + (index % 2 === 0 ? box.offsetX : box.offsetY));
69
+ }
70
+ //#endregion
71
+ export { getShapeBox, translatePolygonPoints };
72
+
73
+ //# sourceMappingURL=shape-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-utils.js","names":[],"sources":["../../../src/components/dynamics/shape-utils.ts"],"sourcesContent":["const defaultToNumber = (value: any, fallback = 0) => {\n const num = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(num) ? num : fallback;\n};\n\nexport function getShapePointBounds(points: any[] = [], toNumber = defaultToNumber) {\n if (!Array.isArray(points) || points.length < 2) {\n return { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < points.length; i += 2) {\n const x = toNumber(points[i], 0);\n const y = toNumber(points[i + 1], 0);\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n\n return { minX, minY, maxX, maxY };\n}\n\nexport function getShapeBox(cfg: any, toNumber = defaultToNumber) {\n if (cfg.type === 'circle') {\n return { width: cfg.radius * 2, height: cfg.radius * 2, offsetX: 0, offsetY: 0 };\n }\n\n if (cfg.type === 'line') {\n const minX = Math.min(cfg.x1, cfg.x2);\n const minY = Math.min(cfg.y1, cfg.y2);\n const maxX = Math.max(cfg.x1, cfg.x2);\n const maxY = Math.max(cfg.y1, cfg.y2);\n return {\n width: Math.max(1, maxX - minX),\n height: Math.max(1, maxY - minY),\n offsetX: -minX,\n offsetY: -minY\n };\n }\n\n if (cfg.type === 'polygon') {\n const bounds = getShapePointBounds(cfg.points, toNumber);\n return {\n width: Math.max(1, bounds.maxX - bounds.minX),\n height: Math.max(1, bounds.maxY - bounds.minY),\n offsetX: -bounds.minX,\n offsetY: -bounds.minY\n };\n }\n\n return { width: cfg.width, height: cfg.height, offsetX: 0, offsetY: 0 };\n}\n\nexport function translatePolygonPoints(points: any[] = [], box: { offsetX: number; offsetY: number }, toNumber = defaultToNumber) {\n return points.map((point, index) => toNumber(point, 0) + (index % 2 === 0 ? box.offsetX : box.offsetY));\n}\n"],"mappings":";AAAA,IAAM,mBAAmB,OAAY,WAAW,MAAM;CACpD,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM;CACjE,OAAO,OAAO,SAAS,IAAI,GAAG,MAAM;;AAGtC,SAAgB,oBAAoB,SAAgB,EAAE,EAAE,WAAW,iBAAiB;CAClF,IAAI,CAAC,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,GAC5C,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG;CAG/C,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;EACzC,MAAM,IAAI,SAAS,OAAO,IAAI,EAAE;EAChC,MAAM,IAAI,SAAS,OAAO,IAAI,IAAI,EAAE;EACpC,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;;CAG1B,OAAO;EAAE;EAAM;EAAM;EAAM;EAAM;;AAGnC,SAAgB,YAAY,KAAU,WAAW,iBAAiB;CAChE,IAAI,IAAI,SAAS,UACf,OAAO;EAAE,OAAO,IAAI,SAAS;EAAG,QAAQ,IAAI,SAAS;EAAG,SAAS;EAAG,SAAS;EAAG;CAGlF,IAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,OAAO;GACL,OAAO,KAAK,IAAI,GAAG,OAAO,KAAK;GAC/B,QAAQ,KAAK,IAAI,GAAG,OAAO,KAAK;GAChC,SAAS,CAAC;GACV,SAAS,CAAC;GACX;;CAGH,IAAI,IAAI,SAAS,WAAW;EAC1B,MAAM,SAAS,oBAAoB,IAAI,QAAQ,SAAS;EACxD,OAAO;GACL,OAAO,KAAK,IAAI,GAAG,OAAO,OAAO,OAAO,KAAK;GAC7C,QAAQ,KAAK,IAAI,GAAG,OAAO,OAAO,OAAO,KAAK;GAC9C,SAAS,CAAC,OAAO;GACjB,SAAS,CAAC,OAAO;GAClB;;CAGH,OAAO;EAAE,OAAO,IAAI;EAAO,QAAQ,IAAI;EAAQ,SAAS;EAAG,SAAS;EAAG;;AAGzE,SAAgB,uBAAuB,SAAgB,EAAE,EAAE,KAA2C,WAAW,iBAAiB;CAChI,OAAO,OAAO,KAAK,OAAO,UAAU,SAAS,OAAO,EAAE,IAAI,QAAQ,MAAM,IAAI,IAAI,UAAU,IAAI,SAAS"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,83 @@
1
+ import { resolveDynamicValue } from "./parse-value.js";
2
+ import { getShapeBox, translatePolygonPoints } from "./shape-utils.js";
3
+ import { Container, Graphics, computed, h, useDefineProps, useProps } from "canvasengine";
4
+ //#region src/components/dynamics/shape.ce
5
+ function component($$props) {
6
+ useProps($$props);
7
+ const props = useDefineProps($$props)();
8
+ const { object } = props;
9
+ const read = (prop, fallback) => prop ? prop() : fallback;
10
+ const toNumber = (value, fallback = 0) => {
11
+ const resolved = resolveDynamicValue(value, object);
12
+ const num = typeof resolved === "number" ? resolved : parseFloat(resolved);
13
+ return Number.isFinite(num) ? num : fallback;
14
+ };
15
+ const toColor = (value, fallback) => {
16
+ const resolved = resolveDynamicValue(value, object);
17
+ if (typeof resolved === "number") return resolved;
18
+ if (typeof resolved === "string" && resolved.startsWith("#")) return parseInt(resolved.slice(1), 16);
19
+ return resolved ?? fallback;
20
+ };
21
+ const config = computed(() => ({
22
+ type: read(props.type, "rectangle"),
23
+ fill: toColor(read(props.fill, "#ffffff"), 16777215),
24
+ radius: toNumber(read(props.radius, 8), 8),
25
+ width: toNumber(read(props.width, 16), 16),
26
+ height: toNumber(read(props.height, 16), 16),
27
+ x1: toNumber(read(props.x1, 0), 0),
28
+ y1: toNumber(read(props.y1, 0), 0),
29
+ x2: toNumber(read(props.x2, 16), 16),
30
+ y2: toNumber(read(props.y2, 0), 0),
31
+ opacity: Math.max(0, Math.min(1, toNumber(read(props.opacity, 1), 1))),
32
+ points: read(props.points, []),
33
+ line: read(props.line, null)
34
+ }));
35
+ const shapeBox = computed(() => getShapeBox(config(), toNumber));
36
+ const shapeWidth = computed(() => shapeBox().width);
37
+ const shapeHeight = computed(() => shapeBox().height);
38
+ const drawShape = (g) => {
39
+ const cfg = config();
40
+ const box = shapeBox();
41
+ if (cfg.type === "circle") g.circle(cfg.radius, cfg.radius, cfg.radius);
42
+ else if (cfg.type === "ellipse") g.ellipse(box.width / 2, box.height / 2, box.width / 2, box.height / 2);
43
+ else if (cfg.type === "line") {
44
+ g.moveTo(cfg.x1 + box.offsetX, cfg.y1 + box.offsetY);
45
+ g.lineTo(cfg.x2 + box.offsetX, cfg.y2 + box.offsetY);
46
+ } else if (cfg.type === "polygon" && Array.isArray(cfg.points)) g.poly(translatePolygonPoints(cfg.points, box, toNumber));
47
+ else if (cfg.type === "rounded-rectangle") g.roundRect(0, 0, box.width, box.height, toNumber(read(props.radius, 4), 4));
48
+ else g.rect(0, 0, box.width, box.height);
49
+ if (cfg.type === "line") {
50
+ const line = cfg.line ?? {};
51
+ g.stroke({
52
+ color: toColor(line.color, cfg.fill),
53
+ width: toNumber(line.width, 1),
54
+ alpha: toNumber(line.alpha, cfg.opacity)
55
+ });
56
+ return;
57
+ }
58
+ g.fill({
59
+ color: cfg.fill,
60
+ alpha: cfg.opacity
61
+ });
62
+ if (cfg.line) g.stroke({
63
+ color: toColor(cfg.line.color, cfg.fill),
64
+ width: toNumber(cfg.line.width, 1),
65
+ alpha: toNumber(cfg.line.alpha, cfg.opacity)
66
+ });
67
+ };
68
+ return h(Container, {
69
+ width: shapeWidth,
70
+ height: shapeHeight,
71
+ minWidth: shapeWidth,
72
+ minHeight: shapeHeight
73
+ }, h(Graphics, {
74
+ width: shapeWidth,
75
+ height: shapeHeight,
76
+ draw: drawShape
77
+ }));
78
+ }
79
+ var __ce_component = component;
80
+ //#endregion
81
+ export { __ce_component as default };
82
+
83
+ //# sourceMappingURL=shape.ce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.ce.js","names":[],"sources":["../../../src/components/dynamics/shape.ce"],"sourcesContent":["<Container width={shapeWidth} height={shapeHeight} minWidth={shapeWidth} minHeight={shapeHeight}>\n <Graphics width={shapeWidth} height={shapeHeight} draw={drawShape} />\n</Container>\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { resolveDynamicValue } from \"./parse-value\";\nimport { getShapeBox, translatePolygonPoints } from \"./shape-utils\";\n\nconst props = defineProps();\nconst { object } = props;\n\nconst read = (prop, fallback) => prop ? prop() : fallback;\n\nconst toNumber = (value, fallback = 0) => {\n const resolved = resolveDynamicValue(value, object);\n const num = typeof resolved === 'number' ? resolved : parseFloat(resolved);\n return Number.isFinite(num) ? num : fallback;\n};\n\nconst toColor = (value, fallback) => {\n const resolved = resolveDynamicValue(value, object);\n if (typeof resolved === 'number') return resolved;\n if (typeof resolved === 'string' && resolved.startsWith('#')) {\n return parseInt(resolved.slice(1), 16);\n }\n return resolved ?? fallback;\n};\n\nconst config = computed(() => ({\n type: read(props.type, 'rectangle'),\n fill: toColor(read(props.fill, '#ffffff'), 0xffffff),\n radius: toNumber(read(props.radius, 8), 8),\n width: toNumber(read(props.width, 16), 16),\n height: toNumber(read(props.height, 16), 16),\n x1: toNumber(read(props.x1, 0), 0),\n y1: toNumber(read(props.y1, 0), 0),\n x2: toNumber(read(props.x2, 16), 16),\n y2: toNumber(read(props.y2, 0), 0),\n opacity: Math.max(0, Math.min(1, toNumber(read(props.opacity, 1), 1))),\n points: read(props.points, []),\n line: read(props.line, null)\n}));\n\nconst shapeBox = computed(() => getShapeBox(config(), toNumber));\n\nconst shapeWidth = computed(() => shapeBox().width);\nconst shapeHeight = computed(() => shapeBox().height);\n\nconst drawShape = (g) => {\n const cfg = config();\n const box = shapeBox();\n\n if (cfg.type === 'circle') {\n g.circle(cfg.radius, cfg.radius, cfg.radius);\n } else if (cfg.type === 'ellipse') {\n g.ellipse(box.width / 2, box.height / 2, box.width / 2, box.height / 2);\n } else if (cfg.type === 'line') {\n g.moveTo(cfg.x1 + box.offsetX, cfg.y1 + box.offsetY);\n g.lineTo(cfg.x2 + box.offsetX, cfg.y2 + box.offsetY);\n } else if (cfg.type === 'polygon' && Array.isArray(cfg.points)) {\n g.poly(translatePolygonPoints(cfg.points, box, toNumber));\n } else if (cfg.type === 'rounded-rectangle') {\n g.roundRect(0, 0, box.width, box.height, toNumber(read(props.radius, 4), 4));\n } else {\n g.rect(0, 0, box.width, box.height);\n }\n\n if (cfg.type === 'line') {\n const line = cfg.line ?? {};\n g.stroke({\n color: toColor(line.color, cfg.fill),\n width: toNumber(line.width, 1),\n alpha: toNumber(line.alpha, cfg.opacity)\n });\n return;\n }\n\n g.fill({ color: cfg.fill, alpha: cfg.opacity });\n\n if (cfg.line) {\n g.stroke({\n color: toColor(cfg.line.color, cfg.fill),\n width: toNumber(cfg.line.width, 1),\n alpha: toNumber(cfg.line.alpha, cfg.opacity)\n });\n }\n};\n</script>\n"],"mappings":";;;;AASM,SAAQ,U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A,OAAA;EAAA,QAAA;EAAA,MAAA;EAAA,CAAA,CACD"}
@@ -1,59 +1,46 @@
1
- import { parseDynamicValue } from "./parse-value.js";
1
+ import { resolveDynamicValue } from "./parse-value.js";
2
2
  import { Text, computed, h, useDefineProps, useProps } from "canvasengine";
3
3
  //#region src/components/dynamics/text.ce
4
4
  function component($$props) {
5
5
  useProps($$props);
6
- const { object } = useDefineProps($$props)();
7
- const component = object._component;
6
+ const { object, value, style } = useDefineProps($$props)();
7
+ const read = (prop, fallback) => prop ? prop() : fallback;
8
8
  const parseNumericStyleValue = (value, object) => {
9
- if (value === void 0 || value === null) return;
9
+ value = resolveDynamicValue(value, object);
10
+ if (value === void 0 || value === null) return void 0;
10
11
  if (typeof value === "number") return value;
11
- if (typeof value === "string") if (value.includes("{")) {
12
- const parsed = parseDynamicValue(value, object);
13
- return computed(() => {
14
- const str = parsed();
15
- const num = parseFloat(str);
16
- return isNaN(num) ? 0 : num;
17
- });
18
- } else {
19
- const num = parseFloat(value);
20
- return isNaN(num) ? void 0 : num;
21
- }
22
- return value;
12
+ const num = parseFloat(value);
13
+ return isNaN(num) ? void 0 : num;
23
14
  };
24
- const getComponentStyle = (component) => {
25
- if (!component.style) return {};
26
- const style = component.style;
27
- const result = {};
28
- if (style.fill !== void 0) if (typeof style.fill === "string" && style.fill.includes("{")) result.color = parseDynamicValue(style.fill, object);
29
- else result.color = style.fill;
30
- if (style.fontSize !== void 0) {
31
- const fontSizeValue = parseNumericStyleValue(style.fontSize, object);
32
- if (fontSizeValue !== void 0) result.size = fontSizeValue;
33
- }
34
- if (style.fontFamily !== void 0) if (typeof style.fontFamily === "string" && style.fontFamily.includes("{")) result.fontFamily = parseDynamicValue(style.fontFamily, object);
35
- else result.fontFamily = style.fontFamily;
15
+ const getTextStyle = (style) => {
16
+ if (!style) return {};
36
17
  const textStyle = {};
37
- if (style.fontStyle !== void 0) if (typeof style.fontStyle === "string" && style.fontStyle.includes("{")) textStyle.fontStyle = parseDynamicValue(style.fontStyle, object);
38
- else textStyle.fontStyle = style.fontStyle;
39
- if (style.fontWeight !== void 0) if (typeof style.fontWeight === "string" && style.fontWeight.includes("{")) textStyle.fontWeight = parseDynamicValue(style.fontWeight, object);
40
- else if (typeof style.fontWeight === "number") textStyle.fontWeight = style.fontWeight;
41
- else textStyle.fontWeight = style.fontWeight;
42
- if (style.stroke !== void 0) if (typeof style.stroke === "string" && style.stroke.includes("{")) textStyle.stroke = parseDynamicValue(style.stroke, object);
43
- else textStyle.stroke = style.stroke;
18
+ if (style.fontStyle !== void 0) textStyle.fontStyle = resolveDynamicValue(style.fontStyle, object);
19
+ if (style.fontWeight !== void 0) textStyle.fontWeight = resolveDynamicValue(style.fontWeight, object);
20
+ if (style.stroke !== void 0) textStyle.stroke = resolveDynamicValue(style.stroke, object);
44
21
  if (style.opacity !== void 0) {
45
22
  const opacityValue = parseNumericStyleValue(style.opacity, object);
46
23
  if (opacityValue !== void 0) textStyle.opacity = opacityValue;
47
24
  }
48
25
  if (style.wordWrap !== void 0) textStyle.wordWrap = style.wordWrap;
49
- if (style.align !== void 0) if (typeof style.align === "string" && style.align.includes("{")) textStyle.align = parseDynamicValue(style.align, object);
50
- else textStyle.align = style.align;
51
- if (Object.keys(textStyle).length > 0) result.style = textStyle;
52
- return result;
26
+ if (style.align !== void 0) textStyle.align = resolveDynamicValue(style.align, object);
27
+ return textStyle;
53
28
  };
54
29
  return h(Text, {
55
- text: computed(() => parseDynamicValue(component.value, object)),
56
- ...getComponentStyle(component)
30
+ text: computed(() => String(resolveDynamicValue(read(value, ""), object) ?? "")),
31
+ color: computed(() => {
32
+ const currentStyle = read(style, {});
33
+ return currentStyle.fill !== void 0 ? resolveDynamicValue(currentStyle.fill, object) : void 0;
34
+ }),
35
+ size: computed(() => {
36
+ const currentStyle = read(style, {});
37
+ return currentStyle.fontSize !== void 0 ? parseNumericStyleValue(currentStyle.fontSize, object) : void 0;
38
+ }),
39
+ fontFamily: computed(() => {
40
+ const currentStyle = read(style, {});
41
+ return currentStyle.fontFamily !== void 0 ? resolveDynamicValue(currentStyle.fontFamily, object) : void 0;
42
+ }),
43
+ style: computed(() => getTextStyle(read(style, {})))
57
44
  });
58
45
  }
59
46
  var __ce_component = component;
@@ -1 +1 @@
1
- {"version":3,"file":"text.ce.js","names":[],"sources":["../../../src/components/dynamics/text.ce"],"sourcesContent":["<Text text={parseDynamicValue(component.value, object)} ...getComponentStyle(component) />\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { parseDynamicValue } from \"./parse-value\";\n\nconst { object } = defineProps();\nconst component = object._component;\n\n/**\n * Parses a numeric style value that can be a number or a string\n * \n * If the value is a string, it may contain dynamic references like {hp}\n * which need to be parsed using parseDynamicValue. If it's a number,\n * it's returned as-is wrapped in a computed.\n * \n * @param value - Numeric value (number or string)\n * @param object - Object to resolve dynamic references from\n * @returns Computed signal with the numeric value\n */\nconst parseNumericStyleValue = (value, object) => {\n if (value === undefined || value === null) {\n return undefined;\n }\n \n if (typeof value === 'number') {\n return value;\n }\n \n if (typeof value === 'string') {\n // Check if it contains dynamic references\n if (value.includes('{')) {\n // Parse dynamic value and convert to number\n const parsed = parseDynamicValue(value, object);\n return computed(() => {\n const str = parsed();\n const num = parseFloat(str);\n return isNaN(num) ? 0 : num;\n });\n } else {\n // Simple string number, convert directly\n const num = parseFloat(value);\n return isNaN(num) ? undefined : num;\n }\n }\n \n return value;\n};\n\n/**\n * Maps component style properties to Canvas Engine Text component props\n * \n * Converts TextComponentOptions from the server to the format expected\n * by the Canvas Engine Text component. Supports all text styling properties\n * including fill, fontSize, fontFamily, fontStyle, fontWeight, stroke,\n * opacity, wordWrap, and align. Also supports dynamic values (number | string)\n * for numeric properties like fontSize and opacity.\n * \n * @param component - Component definition with style property\n * @returns Object with Text component props\n * \n * @example\n * ```ts\n * // Component with style\n * const component = {\n * style: {\n * fill: '#000000',\n * fontSize: 20,\n * fontFamily: 'Arial',\n * fontWeight: 'bold'\n * }\n * };\n * \n * const props = getComponentStyle(component);\n * // Returns: { color: '#000000', size: 20, fontFamily: 'Arial', style: { fontWeight: 'bold' } }\n * \n * // Component with dynamic fontSize\n * const component2 = {\n * style: {\n * fill: '#000000',\n * fontSize: '{hp}', // Will be resolved from object.hp\n * opacity: '0.8'\n * }\n * };\n * ```\n */\nconst getComponentStyle = (component) => {\n if (!component.style) {\n return {};\n }\n\n const style = component.style;\n const result = {};\n\n // Map fill to color (shortcut property)\n // fill can be a string (hex color) or a dynamic string\n if (style.fill !== undefined) {\n if (typeof style.fill === 'string' && style.fill.includes('{')) {\n result.color = parseDynamicValue(style.fill, object);\n } else {\n result.color = style.fill;\n }\n }\n\n // Map fontSize to size (shortcut property)\n // fontSize can be number or string (with dynamic references)\n if (style.fontSize !== undefined) {\n const fontSizeValue = parseNumericStyleValue(style.fontSize, object);\n if (fontSizeValue !== undefined) {\n result.size = fontSizeValue;\n }\n }\n\n // Map fontFamily (shortcut property)\n if (style.fontFamily !== undefined) {\n if (typeof style.fontFamily === 'string' && style.fontFamily.includes('{')) {\n result.fontFamily = parseDynamicValue(style.fontFamily, object);\n } else {\n result.fontFamily = style.fontFamily;\n }\n }\n\n // Build style object for PixiJS Text properties\n const textStyle = {};\n\n // Font style properties\n if (style.fontStyle !== undefined) {\n if (typeof style.fontStyle === 'string' && style.fontStyle.includes('{')) {\n textStyle.fontStyle = parseDynamicValue(style.fontStyle, object);\n } else {\n textStyle.fontStyle = style.fontStyle;\n }\n }\n\n if (style.fontWeight !== undefined) {\n if (typeof style.fontWeight === 'string' && style.fontWeight.includes('{')) {\n textStyle.fontWeight = parseDynamicValue(style.fontWeight, object);\n } else if (typeof style.fontWeight === 'number') {\n textStyle.fontWeight = style.fontWeight;\n } else {\n textStyle.fontWeight = style.fontWeight;\n }\n }\n\n // Stroke properties\n if (style.stroke !== undefined) {\n if (typeof style.stroke === 'string' && style.stroke.includes('{')) {\n textStyle.stroke = parseDynamicValue(style.stroke, object);\n } else {\n textStyle.stroke = style.stroke;\n }\n }\n\n // Opacity (can be number or string)\n if (style.opacity !== undefined) {\n const opacityValue = parseNumericStyleValue(style.opacity, object);\n if (opacityValue !== undefined) {\n textStyle.opacity = opacityValue;\n }\n }\n\n // Word wrap\n if (style.wordWrap !== undefined) {\n textStyle.wordWrap = style.wordWrap;\n }\n\n // Text alignment\n if (style.align !== undefined) {\n if (typeof style.align === 'string' && style.align.includes('{')) {\n textStyle.align = parseDynamicValue(style.align, object);\n } else {\n textStyle.align = style.align;\n }\n }\n\n // Only add style prop if there are style properties\n if (Object.keys(textStyle).length > 0) {\n result.style = textStyle;\n }\n\n return result;\n}\n</script>"],"mappings":";;;AAOM,SAAS,UAAU,SAAA;;CAGtB,MAAS,EAAA,WADV,eAAA,QACmC,EAAG;CACxC,MAAE,YAAA,OAAA;CACF,MAAM,0BAA0B,OAAI,WAAQ;EACzC,IAAK,UAAS,KAAA,KAAU,UAAM,MACzB;EAEJ,IAAA,OAAW,UAAU,UACrB,OAAM;EAER,IAAA,OAAA,UAAA,UAEM,IAAA,MAAU,SAAS,IAAI,EAAA;GAE3B,MAAA,SAAA,kBAAA,OAAA,OAAA;GACD,OAAA,eAAA;IACY,MAAO,MAAI,QAAS;IACpB,MAAK,MAAA,WAAA,IAAA;IAChB,OAAA,MAAA,IAAA,GAAA,IAAA;KACD;SAEQ;GAEC,MAAG,MAAM,WAAc,MAAI;GAC3B,OAAM,MAAO,IAAE,GAAA,KAAA,IAAiB;;EAGxC,OAAO;;CAEX,MAAM,qBAAQ,cAAA;EACV,IAAI,CAAC,UAAM,OACP,OAAO,EAAA;EAEX,MAAM,QAAQ,UAAU;EACxB,MAAI,SAAA,EAAA;EAGJ,IAAA,MAAO,SAAK,KAAA,GACf,IAAA,OAAA,MAAA,SAAA,YAAA,MAAA,KAAA,SAAA,IAAA,EAAA,OAAA,QAAA,kBAAA,MAAA,MAAA,OAAA;OAIC,OAAA,QAAA,MAAA;EAKC,IAAI,MAAO,aAAY,KAAA,GAAK;GAC7B,MAAA,gBAAA,uBAAA,MAAA,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AAA,CAC7D;;AAGX,IAAA,iBAEI"}
1
+ {"version":3,"file":"text.ce.js","names":[],"sources":["../../../src/components/dynamics/text.ce"],"sourcesContent":["<Text text={textValue} color={textColor} size={textSize} fontFamily={textFontFamily} style={textStyle} />\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { resolveDynamicValue } from \"./parse-value\";\n\nconst { object, value, style } = defineProps();\n\nconst read = (prop, fallback) => prop ? prop() : fallback;\n\nconst parseNumericStyleValue = (value, object) => {\n value = resolveDynamicValue(value, object);\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'number') return value;\n\n const num = parseFloat(value);\n return isNaN(num) ? undefined : num;\n};\n\nconst getTextStyle = (style) => {\n if (!style) return {};\n const textStyle = {};\n\n if (style.fontStyle !== undefined) {\n textStyle.fontStyle = resolveDynamicValue(style.fontStyle, object);\n }\n\n if (style.fontWeight !== undefined) {\n textStyle.fontWeight = resolveDynamicValue(style.fontWeight, object);\n }\n\n if (style.stroke !== undefined) {\n textStyle.stroke = resolveDynamicValue(style.stroke, object);\n }\n\n if (style.opacity !== undefined) {\n const opacityValue = parseNumericStyleValue(style.opacity, object);\n if (opacityValue !== undefined) {\n textStyle.opacity = opacityValue;\n }\n }\n\n if (style.wordWrap !== undefined) {\n textStyle.wordWrap = style.wordWrap;\n }\n\n if (style.align !== undefined) {\n textStyle.align = resolveDynamicValue(style.align, object);\n }\n\n return textStyle;\n};\n\nconst textValue = computed(() => String(resolveDynamicValue(read(value, ''), object) ?? ''));\nconst textColor = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fill !== undefined ? resolveDynamicValue(currentStyle.fill, object) : undefined;\n});\nconst textSize = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fontSize !== undefined ? parseNumericStyleValue(currentStyle.fontSize, object) : undefined;\n});\nconst textFontFamily = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fontFamily !== undefined ? resolveDynamicValue(currentStyle.fontFamily, object) : undefined;\n});\nconst textStyle = computed(() => get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GAAA,KAAA;IAOF;EAAA,YALpC,eAAA;GACF,MAAM,eAAmB,KAAK,OAAE,EAAA,CAAA;GAC5B,OAAM,aAAc,eAAe,KAAA,IAAC,oBAAA,aAAA,YAAA,OAAA,GAAA,KAAA;IAGF;EAAA,OADpC,eAAA,aAAA,KAAA,OAAA,EAAA,CAAA,CAAA,CACoC;EAAA,CAC5B;;AAGJ,IAAA,iBAAA"}
@@ -0,0 +1,67 @@
1
+ export declare const DEFAULT_HP_BAR_STYLE: {
2
+ fillColor: string;
3
+ };
4
+ export declare const DEFAULT_SP_BAR_STYLE: {
5
+ fillColor: string;
6
+ };
7
+ type NumberResolver = (value: any, fallback?: number) => number;
8
+ export declare function getPointBounds(points?: any[], toNumber?: NumberResolver): {
9
+ width: number;
10
+ height: number;
11
+ };
12
+ export declare function getComponentId(definition: any): any;
13
+ export declare function getComponentProps(definition: any): any;
14
+ export declare function estimateComponentSize(definition: any, { toNumber, estimateTextWidth }?: {
15
+ toNumber?: NumberResolver;
16
+ estimateTextWidth?: (value: any, style?: any) => number;
17
+ }): {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ export declare function computeBlockSize({ position, layout, rowMetrics, gap, graphic, hitbox }: {
22
+ position: string;
23
+ layout?: any;
24
+ rowMetrics: Array<{
25
+ width: number;
26
+ height: number;
27
+ cells: any[];
28
+ }>;
29
+ gap?: {
30
+ row: number;
31
+ column: number;
32
+ };
33
+ graphic: {
34
+ width: number;
35
+ height: number;
36
+ };
37
+ hitbox: {
38
+ w: number;
39
+ h: number;
40
+ };
41
+ }): {
42
+ width: any;
43
+ height: any;
44
+ };
45
+ export declare function computeBlockPosition({ position, size, layout, graphic, hitbox }: {
46
+ position: string;
47
+ size: {
48
+ width: number;
49
+ height: number;
50
+ };
51
+ layout?: any;
52
+ graphic: {
53
+ left: number;
54
+ top: number;
55
+ right: number;
56
+ centerX: number;
57
+ centerY: number;
58
+ };
59
+ hitbox: {
60
+ w: number;
61
+ h: number;
62
+ };
63
+ }): {
64
+ x: number;
65
+ y: number;
66
+ };
67
+ export {};