@al8b/image 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +30 -0
  2. package/dist/blending.d.mts +3 -0
  3. package/dist/blending.d.ts +3 -0
  4. package/dist/blending.js +65 -0
  5. package/dist/blending.js.map +1 -0
  6. package/dist/blending.mjs +40 -0
  7. package/dist/blending.mjs.map +1 -0
  8. package/dist/color-DJyRSbpZ.d.mts +16 -0
  9. package/dist/color-DJyRSbpZ.d.ts +16 -0
  10. package/dist/core/color.d.mts +1 -0
  11. package/dist/core/color.d.ts +1 -0
  12. package/dist/core/color.js +61 -0
  13. package/dist/core/color.js.map +1 -0
  14. package/dist/core/color.mjs +36 -0
  15. package/dist/core/color.mjs.map +1 -0
  16. package/dist/core/context.d.mts +25 -0
  17. package/dist/core/context.d.ts +25 -0
  18. package/dist/core/context.js +77 -0
  19. package/dist/core/context.js.map +1 -0
  20. package/dist/core/context.mjs +53 -0
  21. package/dist/core/context.mjs.map +1 -0
  22. package/dist/core/drawing.d.mts +2 -0
  23. package/dist/core/drawing.d.ts +2 -0
  24. package/dist/core/drawing.js +165 -0
  25. package/dist/core/drawing.js.map +1 -0
  26. package/dist/core/drawing.mjs +134 -0
  27. package/dist/core/drawing.mjs.map +1 -0
  28. package/dist/core/font.d.mts +19 -0
  29. package/dist/core/font.d.ts +19 -0
  30. package/dist/core/font.js +80 -0
  31. package/dist/core/font.js.map +1 -0
  32. package/dist/core/font.mjs +55 -0
  33. package/dist/core/font.mjs.map +1 -0
  34. package/dist/core/image.d.mts +84 -0
  35. package/dist/core/image.d.ts +84 -0
  36. package/dist/core/image.js +1018 -0
  37. package/dist/core/image.js.map +1 -0
  38. package/dist/core/image.mjs +993 -0
  39. package/dist/core/image.mjs.map +1 -0
  40. package/dist/core/map-rendering.d.mts +2 -0
  41. package/dist/core/map-rendering.d.ts +2 -0
  42. package/dist/core/map-rendering.js +95 -0
  43. package/dist/core/map-rendering.js.map +1 -0
  44. package/dist/core/map-rendering.mjs +70 -0
  45. package/dist/core/map-rendering.mjs.map +1 -0
  46. package/dist/core/pixel.d.mts +18 -0
  47. package/dist/core/pixel.d.ts +18 -0
  48. package/dist/core/pixel.js +99 -0
  49. package/dist/core/pixel.js.map +1 -0
  50. package/dist/core/pixel.mjs +73 -0
  51. package/dist/core/pixel.mjs.map +1 -0
  52. package/dist/core/shapes.d.mts +2 -0
  53. package/dist/core/shapes.d.ts +2 -0
  54. package/dist/core/shapes.js +218 -0
  55. package/dist/core/shapes.js.map +1 -0
  56. package/dist/core/shapes.mjs +187 -0
  57. package/dist/core/shapes.mjs.map +1 -0
  58. package/dist/core/sprite-rendering.d.mts +2 -0
  59. package/dist/core/sprite-rendering.d.ts +2 -0
  60. package/dist/core/sprite-rendering.js +135 -0
  61. package/dist/core/sprite-rendering.js.map +1 -0
  62. package/dist/core/sprite-rendering.mjs +108 -0
  63. package/dist/core/sprite-rendering.mjs.map +1 -0
  64. package/dist/core/text.d.mts +2 -0
  65. package/dist/core/text.d.ts +2 -0
  66. package/dist/core/text.js +105 -0
  67. package/dist/core/text.js.map +1 -0
  68. package/dist/core/text.mjs +78 -0
  69. package/dist/core/text.mjs.map +1 -0
  70. package/dist/core/transform.d.mts +2 -0
  71. package/dist/core/transform.d.ts +2 -0
  72. package/dist/core/transform.js +101 -0
  73. package/dist/core/transform.js.map +1 -0
  74. package/dist/core/transform.mjs +71 -0
  75. package/dist/core/transform.mjs.map +1 -0
  76. package/dist/drawing-Bo2U4IUE.d.mts +31 -0
  77. package/dist/drawing-e7iVDl14.d.ts +31 -0
  78. package/dist/index.d.mts +12 -0
  79. package/dist/index.d.ts +12 -0
  80. package/dist/index.js +1098 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/index.mjs +1066 -0
  83. package/dist/index.mjs.map +1 -0
  84. package/dist/map-rendering-CzeC061I.d.mts +20 -0
  85. package/dist/map-rendering-DcldCBtY.d.ts +20 -0
  86. package/dist/shapes-BY37IuhJ.d.ts +27 -0
  87. package/dist/shapes-CpCwX9Rp.d.mts +27 -0
  88. package/dist/sprite-rendering-Dac9FQ2x.d.ts +30 -0
  89. package/dist/sprite-rendering-DfQuLVXT.d.mts +30 -0
  90. package/dist/text-CIoUSRc-.d.mts +19 -0
  91. package/dist/text-HW25Qq3e.d.ts +19 -0
  92. package/dist/transform-Dqo6bY4r.d.mts +25 -0
  93. package/dist/transform-iwq8WdqR.d.ts +25 -0
  94. package/package.json +43 -0
@@ -0,0 +1,108 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core/drawing.ts
5
+ function initDrawOp(context, state, x, y, object_transform = true) {
6
+ let res = false;
7
+ if (state.image_transform) {
8
+ context.save();
9
+ res = true;
10
+ context.translate(state.translation_x, state.translation_y);
11
+ context.scale(state.scale_x, state.scale_y);
12
+ context.rotate(state.rotation / 180 * Math.PI);
13
+ context.translate(x, y);
14
+ }
15
+ if (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {
16
+ if (!res) {
17
+ context.save();
18
+ res = true;
19
+ context.translate(x, y);
20
+ }
21
+ if (state.object_rotation !== 0) {
22
+ context.rotate(state.object_rotation / 180 * Math.PI);
23
+ }
24
+ if (state.object_scale_x !== 1 || state.object_scale_y !== 1) {
25
+ context.scale(state.object_scale_x, state.object_scale_y);
26
+ }
27
+ }
28
+ return res;
29
+ }
30
+ __name(initDrawOp, "initDrawOp");
31
+ function closeDrawOp(context) {
32
+ context.restore();
33
+ }
34
+ __name(closeDrawOp, "closeDrawOp");
35
+
36
+ // src/core/sprite-rendering.ts
37
+ function getSpriteFrame(sprite) {
38
+ if (typeof sprite === "object" && "canvas" in sprite && !("frames" in sprite)) {
39
+ return sprite.canvas || sprite.image || null;
40
+ }
41
+ if (typeof sprite === "object" && sprite.frames && sprite.frames.length > 0) {
42
+ if (!sprite.ready) {
43
+ return null;
44
+ }
45
+ if (sprite.frames.length > 1) {
46
+ if (!sprite.animation_start || sprite.animation_start === 0) {
47
+ sprite.animation_start = Date.now();
48
+ }
49
+ const dt = 1e3 / (sprite.fps || 5);
50
+ const frame = Math.floor((Date.now() - sprite.animation_start) / dt) % sprite.frames.length;
51
+ if (frame >= 0 && frame < sprite.frames.length) {
52
+ return sprite.frames[frame].canvas;
53
+ }
54
+ return sprite.frames[0].canvas;
55
+ }
56
+ return sprite.frames[0].canvas;
57
+ }
58
+ return null;
59
+ }
60
+ __name(getSpriteFrame, "getSpriteFrame");
61
+ function drawSprite(context, state, sprite, x, y, w, h) {
62
+ const canvas = getSpriteFrame(sprite);
63
+ if (canvas == null) {
64
+ return;
65
+ }
66
+ if (w == null) {
67
+ w = canvas.width;
68
+ }
69
+ if (!h) {
70
+ h = w / canvas.width * canvas.height;
71
+ }
72
+ context.globalAlpha = state.alpha;
73
+ context.imageSmoothingEnabled = !state.pixelated;
74
+ if (initDrawOp(context, state, x, y)) {
75
+ context.drawImage(canvas, -w / 2 - state.anchor_x * w / 2, -h / 2 + state.anchor_y * h / 2, w, h);
76
+ closeDrawOp(context);
77
+ } else {
78
+ context.drawImage(canvas, x - w / 2 - state.anchor_x * w / 2, y - h / 2 + state.anchor_y * h / 2, w, h);
79
+ }
80
+ }
81
+ __name(drawSprite, "drawSprite");
82
+ function drawSpritePart(context, state, sprite, sx, sy, sw, sh, x, y, w, h) {
83
+ const canvas = getSpriteFrame(sprite);
84
+ if (canvas == null) {
85
+ return;
86
+ }
87
+ if (w == null) {
88
+ w = canvas.width;
89
+ }
90
+ if (!h) {
91
+ h = w / sw * sh;
92
+ }
93
+ context.globalAlpha = state.alpha;
94
+ context.imageSmoothingEnabled = !state.pixelated;
95
+ if (initDrawOp(context, state, x, y)) {
96
+ context.drawImage(canvas, sx, sy, sw, sh, -w / 2 - state.anchor_x * w / 2, -h / 2 + state.anchor_y * h / 2, w, h);
97
+ closeDrawOp(context);
98
+ } else {
99
+ context.drawImage(canvas, sx, sy, sw, sh, x - w / 2 - state.anchor_x * w / 2, y - h / 2 + state.anchor_y * h / 2, w, h);
100
+ }
101
+ }
102
+ __name(drawSpritePart, "drawSpritePart");
103
+ export {
104
+ drawSprite,
105
+ drawSpritePart,
106
+ getSpriteFrame
107
+ };
108
+ //# sourceMappingURL=sprite-rendering.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/drawing.ts","../../src/core/sprite-rendering.ts"],"sourcesContent":["/**\n * Drawing operations for Image class\n * Handles all drawing primitives (rectangles, circles, lines, etc.)\n */\n\nimport type { ImageContextState } from \"./context\";\n\nexport function initDrawOp(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tobject_transform = true,\n): boolean {\n\tlet res = false;\n\n\tif (state.image_transform) {\n\t\tcontext.save();\n\t\tres = true;\n\t\tcontext.translate(state.translation_x, state.translation_y);\n\t\tcontext.scale(state.scale_x, state.scale_y);\n\t\tcontext.rotate((state.rotation / 180) * Math.PI);\n\t\tcontext.translate(x, y);\n\t}\n\n\tif (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {\n\t\tif (!res) {\n\t\t\tcontext.save();\n\t\t\tres = true;\n\t\t\tcontext.translate(x, y);\n\t\t}\n\t\tif (state.object_rotation !== 0) {\n\t\t\tcontext.rotate((state.object_rotation / 180) * Math.PI);\n\t\t}\n\t\tif (state.object_scale_x !== 1 || state.object_scale_y !== 1) {\n\t\t\tcontext.scale(state.object_scale_x, state.object_scale_y);\n\t\t}\n\t}\n\n\treturn res;\n}\n\nexport function closeDrawOp(context: CanvasRenderingContext2D): void {\n\tcontext.restore();\n}\n\nexport function fillRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.fillRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.fillRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function fillRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).fillRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).fillRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function fillRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse((-state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t}\n}\n\nexport function drawRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.strokeRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.strokeRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function drawRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).strokeRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).strokeRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function drawRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t}\n}\n\nexport function drawLine(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx1: number,\n\ty1: number,\n\tx2: number,\n\ty2: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tconst transform = initDrawOp(context, state, 0, 0, false);\n\tcontext.beginPath();\n\tcontext.moveTo(x1, y1);\n\tcontext.lineTo(x2, y2);\n\tcontext.stroke();\n\tif (transform) {\n\t\tcloseDrawOp(context);\n\t}\n}\n","/**\n * Sprite and image rendering for Image class\n * Handles drawing sprites and images onto the canvas\n */\n\nimport type { ImageContextState } from \"./context\";\nimport { closeDrawOp, initDrawOp } from \"./drawing\";\n\nexport interface SpriteSource {\n\tframes?: Array<{\n\t\tcanvas: HTMLCanvasElement;\n\t}>;\n\tcanvas?: HTMLCanvasElement;\n\timage?: HTMLImageElement;\n\tready?: boolean | number;\n\tfps?: number;\n\tanimation_start?: number;\n}\n\nexport function getSpriteFrame(sprite: SpriteSource | string): HTMLCanvasElement | null {\n\t// Handle Image instances\n\tif (typeof sprite === \"object\" && \"canvas\" in sprite && !(\"frames\" in sprite)) {\n\t\treturn sprite.canvas || (sprite.image as any) || null;\n\t}\n\n\t// Handle Sprite instances\n\tif (typeof sprite === \"object\" && sprite.frames && sprite.frames.length > 0) {\n\t\tif (!sprite.ready) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (sprite.frames.length > 1) {\n\t\t\t// Initialize animation_start lazily on first use to ensure animation starts from frame 0\n\t\t\t// This ensures smooth sequential animation: 0->1->2->...->N->0->1->...\n\t\t\tif (!sprite.animation_start || sprite.animation_start === 0) {\n\t\t\t\tsprite.animation_start = Date.now();\n\t\t\t}\n\t\t\tconst dt = 1000 / (sprite.fps || 5);\n\t\t\tconst frame = Math.floor((Date.now() - sprite.animation_start) / dt) % sprite.frames.length;\n\t\t\tif (frame >= 0 && frame < sprite.frames.length) {\n\t\t\t\treturn sprite.frames[frame].canvas;\n\t\t\t}\n\t\t\treturn sprite.frames[0].canvas;\n\t\t}\n\t\treturn sprite.frames[0].canvas;\n\t}\n\n\treturn null;\n}\n\nexport function drawSprite(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tsprite: SpriteSource | string,\n\tx: number,\n\ty: number,\n\tw?: number,\n\th?: number,\n): void {\n\tconst canvas = getSpriteFrame(sprite);\n\tif (canvas == null) {\n\t\treturn;\n\t}\n\n\tif (w == null) {\n\t\tw = canvas.width;\n\t}\n\tif (!h) {\n\t\th = (w / canvas.width) * canvas.height;\n\t}\n\n\tcontext.globalAlpha = state.alpha;\n\tcontext.imageSmoothingEnabled = !state.pixelated;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.drawImage(canvas, -w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.drawImage(canvas, x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function drawSpritePart(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tsprite: SpriteSource | string,\n\tsx: number,\n\tsy: number,\n\tsw: number,\n\tsh: number,\n\tx: number,\n\ty: number,\n\tw?: number,\n\th?: number,\n): void {\n\tconst canvas = getSpriteFrame(sprite);\n\tif (canvas == null) {\n\t\treturn;\n\t}\n\n\t// Image class uses w = canvas.width (Screen uses w = sw)\n\tif (w == null) {\n\t\tw = canvas.width;\n\t}\n\tif (!h) {\n\t\th = (w / sw) * sh;\n\t}\n\n\tcontext.globalAlpha = state.alpha;\n\tcontext.imageSmoothingEnabled = !state.pixelated;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.drawImage(canvas, sx, sy, sw, sh, -w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.drawImage(\n\t\t\tcanvas,\n\t\t\tsx,\n\t\t\tsy,\n\t\t\tsw,\n\t\t\tsh,\n\t\t\tx - w / 2 - (state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;AA9BgBN;AAgCT,SAASkB,eACfjB,SACAC,OACAhB,QACAiC,IACAC,IACAC,IACAC,IACAnB,GACAC,GACAC,GACAC,GAAU;AAEV,QAAMnB,SAASF,eAAeC,MAAAA;AAC9B,MAAIC,UAAU,MAAM;AACnB;EACD;AAGA,MAAIkB,KAAK,MAAM;AACdA,QAAIlB,OAAOoB;EACZ;AACA,MAAI,CAACD,GAAG;AACPA,QAAKD,IAAIgB,KAAMC;EAChB;AAEArB,UAAQQ,cAAcP,MAAMQ;AAC5BT,UAAQU,wBAAwB,CAACT,MAAMU;AAEvC,MAAIC,WAAWZ,SAASC,OAAOC,GAAGC,CAAAA,GAAI;AACrCH,YAAQa,UAAU3B,QAAQgC,IAAIC,IAAIC,IAAIC,IAAI,CAACjB,IAAI,IAAKH,MAAMa,WAAWV,IAAK,GAAG,CAACC,IAAI,IAAKJ,MAAMc,WAAWV,IAAK,GAAGD,GAAGC,CAAAA;AACnHW,gBAAYhB,OAAAA;EACb,OAAO;AACNA,YAAQa,UACP3B,QACAgC,IACAC,IACAC,IACAC,IACAnB,IAAIE,IAAI,IAAKH,MAAMa,WAAWV,IAAK,GACnCD,IAAIE,IAAI,IAAKJ,MAAMc,WAAWV,IAAK,GACnCD,GACAC,CAAAA;EAEF;AACD;AA7CgBY;","names":["initDrawOp","context","state","x","y","object_transform","res","image_transform","save","translate","translation_x","translation_y","scale","scale_x","scale_y","rotate","rotation","Math","PI","object_rotation","object_scale_x","object_scale_y","closeDrawOp","restore","getSpriteFrame","sprite","canvas","image","frames","length","ready","animation_start","Date","now","dt","fps","frame","Math","floor","drawSprite","context","state","x","y","w","h","width","height","globalAlpha","alpha","imageSmoothingEnabled","pixelated","initDrawOp","drawImage","anchor_x","anchor_y","closeDrawOp","drawSpritePart","sx","sy","sw","sh"]}
@@ -0,0 +1,2 @@
1
+ import './context.mjs';
2
+ export { d as drawText, a as drawTextOutline, b as textWidth } from '../text-CIoUSRc-.mjs';
@@ -0,0 +1,2 @@
1
+ import './context.js';
2
+ export { d as drawText, a as drawTextOutline, b as textWidth } from '../text-HW25Qq3e.js';
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/core/text.ts
22
+ var text_exports = {};
23
+ __export(text_exports, {
24
+ drawText: () => drawText,
25
+ drawTextOutline: () => drawTextOutline,
26
+ textWidth: () => textWidth
27
+ });
28
+ module.exports = __toCommonJS(text_exports);
29
+
30
+ // src/core/drawing.ts
31
+ function initDrawOp(context, state, x, y, object_transform = true) {
32
+ let res = false;
33
+ if (state.image_transform) {
34
+ context.save();
35
+ res = true;
36
+ context.translate(state.translation_x, state.translation_y);
37
+ context.scale(state.scale_x, state.scale_y);
38
+ context.rotate(state.rotation / 180 * Math.PI);
39
+ context.translate(x, y);
40
+ }
41
+ if (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {
42
+ if (!res) {
43
+ context.save();
44
+ res = true;
45
+ context.translate(x, y);
46
+ }
47
+ if (state.object_rotation !== 0) {
48
+ context.rotate(state.object_rotation / 180 * Math.PI);
49
+ }
50
+ if (state.object_scale_x !== 1 || state.object_scale_y !== 1) {
51
+ context.scale(state.object_scale_x, state.object_scale_y);
52
+ }
53
+ }
54
+ return res;
55
+ }
56
+ __name(initDrawOp, "initDrawOp");
57
+ function closeDrawOp(context) {
58
+ context.restore();
59
+ }
60
+ __name(closeDrawOp, "closeDrawOp");
61
+
62
+ // src/core/text.ts
63
+ function textWidth(context, state, text, size) {
64
+ context.font = `${size}pt ${state.font}`;
65
+ return context.measureText(text).width;
66
+ }
67
+ __name(textWidth, "textWidth");
68
+ function drawText(context, state, text, x, y, size) {
69
+ context.globalAlpha = state.alpha;
70
+ context.font = `${size}pt ${state.font}`;
71
+ context.textAlign = "center";
72
+ context.textBaseline = "middle";
73
+ const w = context.measureText(text).width;
74
+ const h = size;
75
+ if (initDrawOp(context, state, x, y)) {
76
+ context.fillText(text, 0 - state.anchor_x * w / 2, 0 + state.anchor_y * h / 2);
77
+ closeDrawOp(context);
78
+ } else {
79
+ context.fillText(text, x - state.anchor_x * w / 2, y + state.anchor_y * h / 2);
80
+ }
81
+ }
82
+ __name(drawText, "drawText");
83
+ function drawTextOutline(context, state, text, x, y, size) {
84
+ context.globalAlpha = state.alpha;
85
+ context.font = `${size}pt ${state.font}`;
86
+ context.lineWidth = state.line_width;
87
+ context.textAlign = "center";
88
+ context.textBaseline = "middle";
89
+ const w = context.measureText(text).width;
90
+ const h = size;
91
+ if (initDrawOp(context, state, x, y)) {
92
+ context.strokeText(text, 0 - state.anchor_x * w / 2, 0 + state.anchor_y * h / 2);
93
+ closeDrawOp(context);
94
+ } else {
95
+ context.strokeText(text, x - state.anchor_x * w / 2, y + state.anchor_y * h / 2);
96
+ }
97
+ }
98
+ __name(drawTextOutline, "drawTextOutline");
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ drawText,
102
+ drawTextOutline,
103
+ textWidth
104
+ });
105
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/text.ts","../../src/core/drawing.ts"],"sourcesContent":["/**\n * Text rendering operations for Image class\n * Handles text drawing, measurement, and font management\n */\n\nimport type { ImageContextState } from \"./context\";\nimport { closeDrawOp, initDrawOp } from \"./drawing\";\n\nexport function textWidth(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tsize: number,\n): number {\n\tcontext.font = `${size}pt ${state.font}`;\n\treturn context.measureText(text).width;\n}\n\nexport function drawText(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tx: number,\n\ty: number,\n\tsize: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.font = `${size}pt ${state.font}`;\n\tcontext.textAlign = \"center\";\n\tcontext.textBaseline = \"middle\";\n\n\tconst w = context.measureText(text).width;\n\tconst h = size;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.fillText(text, 0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.fillText(text, x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2);\n\t}\n}\n\nexport function drawTextOutline(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tx: number,\n\ty: number,\n\tsize: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.font = `${size}pt ${state.font}`;\n\tcontext.lineWidth = state.line_width;\n\tcontext.textAlign = \"center\";\n\tcontext.textBaseline = \"middle\";\n\n\tconst w = context.measureText(text).width;\n\tconst h = size;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.strokeText(text, 0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.strokeText(text, x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2);\n\t}\n}\n","/**\n * Drawing operations for Image class\n * Handles all drawing primitives (rectangles, circles, lines, etc.)\n */\n\nimport type { ImageContextState } from \"./context\";\n\nexport function initDrawOp(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tobject_transform = true,\n): boolean {\n\tlet res = false;\n\n\tif (state.image_transform) {\n\t\tcontext.save();\n\t\tres = true;\n\t\tcontext.translate(state.translation_x, state.translation_y);\n\t\tcontext.scale(state.scale_x, state.scale_y);\n\t\tcontext.rotate((state.rotation / 180) * Math.PI);\n\t\tcontext.translate(x, y);\n\t}\n\n\tif (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {\n\t\tif (!res) {\n\t\t\tcontext.save();\n\t\t\tres = true;\n\t\t\tcontext.translate(x, y);\n\t\t}\n\t\tif (state.object_rotation !== 0) {\n\t\t\tcontext.rotate((state.object_rotation / 180) * Math.PI);\n\t\t}\n\t\tif (state.object_scale_x !== 1 || state.object_scale_y !== 1) {\n\t\t\tcontext.scale(state.object_scale_x, state.object_scale_y);\n\t\t}\n\t}\n\n\treturn res;\n}\n\nexport function closeDrawOp(context: CanvasRenderingContext2D): void {\n\tcontext.restore();\n}\n\nexport function fillRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.fillRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.fillRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function fillRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).fillRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).fillRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function fillRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse((-state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t}\n}\n\nexport function drawRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.strokeRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.strokeRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function drawRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).strokeRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).strokeRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function drawRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t}\n}\n\nexport function drawLine(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx1: number,\n\ty1: number,\n\tx2: number,\n\ty2: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tconst transform = initDrawOp(context, state, 0, 0, false);\n\tcontext.beginPath();\n\tcontext.moveTo(x1, y1);\n\tcontext.lineTo(x2, y2);\n\tcontext.stroke();\n\tif (transform) {\n\t\tcloseDrawOp(context);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACOO,SAASA,WACfC,SACAC,OACAC,GACAC,GACAC,mBAAmB,MAAI;AAEvB,MAAIC,MAAM;AAEV,MAAIJ,MAAMK,iB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rCT,YAAQiB,SAASf,MAAM,IAAKD,MAAMiB,WAAWJ,IAAK,GAAG,IAAKb,MAAMkB,WAAWJ,IAAK,CAAA;AAChFK,gBAAYpB,OAAAA;EACb,OAAO;AACNA,YAAQiB,SAASf,MAAMM,IAAKP,MAAMiB,WAAWJ,IAAK,GAAGL,IAAKR,MAAMkB,WAAWJ,IAAK,CAAA;EACjF;AACD;AAtBgBR;AAwBT,SAASc,gBACfrB,SACAC,OACAC,MACAM,GACAC,GACAN,MAAY;AAEZH,UAAQU,cAAcT,MAAMU;AAC5BX,UAAQI,OAAO,GAAGD,IAAAA,MAAUF,MAAMG,IAAI;AACtCJ,UAAQsB,YAAYrB,MAAMsB;AAC1BvB,UAAQY,YAAY;AACpBZ,UAAQa,eAAe;AAEvB,QAAMC,IAAId,QAAQK,YAAYH,IAAAA,EAAMI;AACpC,QAAMS,IAAIZ;AAEV,MAAIa,WAAWhB,SAASC,OAAOO,GAAGC,CAAAA,GAAI;AACrCT,YAAQwB,WAAWtB,MAAM,IAAKD,MAAMiB,WAAWJ,IAAK,GAAG,IAAKb,MAAMkB,WAAWJ,IAAK,CAAA;AAClFK,gBAAYpB,OAAAA;EACb,OAAO;AACNA,YAAQwB,WAAWtB,MAAMM,IAAKP,MAAMiB,WAAWJ,IAAK,GAAGL,IAAKR,MAAMkB,WAAWJ,IAAK,CAAA;EACnF;AACD;AAvBgBM;","names":["initDrawOp","context","state","x","y","object_transform","res","image_transform","save","translate","translation_x","translation_y","scale","scale_x","scale_y","rotate","rotation","Math","PI","object_rotation","object_scale_x","object_scale_y","closeDrawOp","restore","textWidth","context","state","text","size","font","measureText","width","drawText","x","y","globalAlpha","alpha","textAlign","textBaseline","w","h","initDrawOp","fillText","anchor_x","anchor_y","closeDrawOp","drawTextOutline","lineWidth","line_width","strokeText"]}
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core/drawing.ts
5
+ function initDrawOp(context, state, x, y, object_transform = true) {
6
+ let res = false;
7
+ if (state.image_transform) {
8
+ context.save();
9
+ res = true;
10
+ context.translate(state.translation_x, state.translation_y);
11
+ context.scale(state.scale_x, state.scale_y);
12
+ context.rotate(state.rotation / 180 * Math.PI);
13
+ context.translate(x, y);
14
+ }
15
+ if (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {
16
+ if (!res) {
17
+ context.save();
18
+ res = true;
19
+ context.translate(x, y);
20
+ }
21
+ if (state.object_rotation !== 0) {
22
+ context.rotate(state.object_rotation / 180 * Math.PI);
23
+ }
24
+ if (state.object_scale_x !== 1 || state.object_scale_y !== 1) {
25
+ context.scale(state.object_scale_x, state.object_scale_y);
26
+ }
27
+ }
28
+ return res;
29
+ }
30
+ __name(initDrawOp, "initDrawOp");
31
+ function closeDrawOp(context) {
32
+ context.restore();
33
+ }
34
+ __name(closeDrawOp, "closeDrawOp");
35
+
36
+ // src/core/text.ts
37
+ function textWidth(context, state, text, size) {
38
+ context.font = `${size}pt ${state.font}`;
39
+ return context.measureText(text).width;
40
+ }
41
+ __name(textWidth, "textWidth");
42
+ function drawText(context, state, text, x, y, size) {
43
+ context.globalAlpha = state.alpha;
44
+ context.font = `${size}pt ${state.font}`;
45
+ context.textAlign = "center";
46
+ context.textBaseline = "middle";
47
+ const w = context.measureText(text).width;
48
+ const h = size;
49
+ if (initDrawOp(context, state, x, y)) {
50
+ context.fillText(text, 0 - state.anchor_x * w / 2, 0 + state.anchor_y * h / 2);
51
+ closeDrawOp(context);
52
+ } else {
53
+ context.fillText(text, x - state.anchor_x * w / 2, y + state.anchor_y * h / 2);
54
+ }
55
+ }
56
+ __name(drawText, "drawText");
57
+ function drawTextOutline(context, state, text, x, y, size) {
58
+ context.globalAlpha = state.alpha;
59
+ context.font = `${size}pt ${state.font}`;
60
+ context.lineWidth = state.line_width;
61
+ context.textAlign = "center";
62
+ context.textBaseline = "middle";
63
+ const w = context.measureText(text).width;
64
+ const h = size;
65
+ if (initDrawOp(context, state, x, y)) {
66
+ context.strokeText(text, 0 - state.anchor_x * w / 2, 0 + state.anchor_y * h / 2);
67
+ closeDrawOp(context);
68
+ } else {
69
+ context.strokeText(text, x - state.anchor_x * w / 2, y + state.anchor_y * h / 2);
70
+ }
71
+ }
72
+ __name(drawTextOutline, "drawTextOutline");
73
+ export {
74
+ drawText,
75
+ drawTextOutline,
76
+ textWidth
77
+ };
78
+ //# sourceMappingURL=text.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/drawing.ts","../../src/core/text.ts"],"sourcesContent":["/**\n * Drawing operations for Image class\n * Handles all drawing primitives (rectangles, circles, lines, etc.)\n */\n\nimport type { ImageContextState } from \"./context\";\n\nexport function initDrawOp(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tobject_transform = true,\n): boolean {\n\tlet res = false;\n\n\tif (state.image_transform) {\n\t\tcontext.save();\n\t\tres = true;\n\t\tcontext.translate(state.translation_x, state.translation_y);\n\t\tcontext.scale(state.scale_x, state.scale_y);\n\t\tcontext.rotate((state.rotation / 180) * Math.PI);\n\t\tcontext.translate(x, y);\n\t}\n\n\tif (object_transform && (state.object_rotation !== 0 || state.object_scale_x !== 1 || state.object_scale_y !== 1)) {\n\t\tif (!res) {\n\t\t\tcontext.save();\n\t\t\tres = true;\n\t\t\tcontext.translate(x, y);\n\t\t}\n\t\tif (state.object_rotation !== 0) {\n\t\t\tcontext.rotate((state.object_rotation / 180) * Math.PI);\n\t\t}\n\t\tif (state.object_scale_x !== 1 || state.object_scale_y !== 1) {\n\t\t\tcontext.scale(state.object_scale_x, state.object_scale_y);\n\t\t}\n\t}\n\n\treturn res;\n}\n\nexport function closeDrawOp(context: CanvasRenderingContext2D): void {\n\tcontext.restore();\n}\n\nexport function fillRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.fillRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.fillRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function fillRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).fillRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).fillRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function fillRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse((-state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.fill();\n\t}\n}\n\nexport function drawRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.strokeRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.strokeRect(x - w / 2 - (state.anchor_x * w) / 2, y - h / 2 + (state.anchor_y * h) / 2, w, h);\n\t}\n}\n\nexport function drawRoundRect(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tround: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tif (initDrawOp(context, state, x, y)) {\n\t\t(context as any).strokeRoundRect(-w / 2 - (state.anchor_x * w) / 2, -h / 2 + (state.anchor_y * h) / 2, w, h, round);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\t(context as any).strokeRoundRect(\n\t\t\tx - w / 2 - (state.anchor_x * w) / 2,\n\t\t\ty - h / 2 + (state.anchor_y * h) / 2,\n\t\t\tw,\n\t\t\th,\n\t\t\tround,\n\t\t);\n\t}\n}\n\nexport function drawRound(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tw = Math.abs(w);\n\th = Math.abs(h);\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.beginPath();\n\t\tcontext.ellipse(x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\tcontext.stroke();\n\t}\n}\n\nexport function drawLine(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\tx1: number,\n\ty1: number,\n\tx2: number,\n\ty2: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.lineWidth = state.line_width;\n\tconst transform = initDrawOp(context, state, 0, 0, false);\n\tcontext.beginPath();\n\tcontext.moveTo(x1, y1);\n\tcontext.lineTo(x2, y2);\n\tcontext.stroke();\n\tif (transform) {\n\t\tcloseDrawOp(context);\n\t}\n}\n","/**\n * Text rendering operations for Image class\n * Handles text drawing, measurement, and font management\n */\n\nimport type { ImageContextState } from \"./context\";\nimport { closeDrawOp, initDrawOp } from \"./drawing\";\n\nexport function textWidth(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tsize: number,\n): number {\n\tcontext.font = `${size}pt ${state.font}`;\n\treturn context.measureText(text).width;\n}\n\nexport function drawText(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tx: number,\n\ty: number,\n\tsize: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.font = `${size}pt ${state.font}`;\n\tcontext.textAlign = \"center\";\n\tcontext.textBaseline = \"middle\";\n\n\tconst w = context.measureText(text).width;\n\tconst h = size;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.fillText(text, 0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.fillText(text, x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2);\n\t}\n}\n\nexport function drawTextOutline(\n\tcontext: CanvasRenderingContext2D,\n\tstate: ImageContextState,\n\ttext: string,\n\tx: number,\n\ty: number,\n\tsize: number,\n): void {\n\tcontext.globalAlpha = state.alpha;\n\tcontext.font = `${size}pt ${state.font}`;\n\tcontext.lineWidth = state.line_width;\n\tcontext.textAlign = \"center\";\n\tcontext.textBaseline = \"middle\";\n\n\tconst w = context.measureText(text).width;\n\tconst h = size;\n\n\tif (initDrawOp(context, state, x, y)) {\n\t\tcontext.strokeText(text, 0 - (state.anchor_x * w) / 2, 0 + (state.anchor_y * h) / 2);\n\t\tcloseDrawOp(context);\n\t} else {\n\t\tcontext.strokeText(text, x - (state.anchor_x * w) / 2, y + (state.anchor_y * h) / 2);\n\t}\n}\n"],"mappings":";;;;AAOO,SAASA,WACfC,SACAC,OACAC,GACAC,GACAC,mBAAmB,MAAI;AAEvB,MAAIC,MAAM;AAEV,MAAIJ,MAAMK,iBAAiB;AAC1BN,YAAQO,KAAI;AACZF,UAAM;AACNL,YAAQQ,UAAUP,MAAMQ,eAAeR,MAAMS,aAAa;AAC1DV,YAAQW,MAAMV,MAAMW,SAASX,MAAMY,OAAO;AAC1Cb,YAAQc,OAAQb,MAAMc,WAAW,MAAOC,KAAKC,EAAE;AAC/CjB,YAAQQ,UAAUN,GAAGC,CAAAA;EACtB;AAEA,MAAIC,qBAAqBH,MAAMiB,oBAAoB,KAAKjB,MAAMkB,mBAAmB,KAAKlB,MAAMmB,mBAAmB,IAAI;AAClH,QAAI,CAACf,KAAK;AACTL,cAAQO,KAAI;AACZF,YAAM;AACNL,cAAQQ,UAAUN,GAAGC,CAAAA;IACtB;AACA,QAAIF,MAAMiB,oBAAoB,GAAG;AAChClB,cAAQc,OAAQb,MAAMiB,kBAAkB,MAAOF,KAAKC,EAAE;IACvD;AACA,QAAIhB,MAAMkB,mBAAmB,KAAKlB,MAAMmB,mBAAmB,GAAG;AAC7DpB,cAAQW,MAAMV,MAAMkB,gBAAgBlB,MAAMmB,cAAc;IACzD;EACD;AAEA,SAAOf;AACR;AAjCgBN;AAmCT,SAASsB,YAAYrB,SAAiC;AAC5DA,UAAQsB,QAAO;AAChB;AAFgBD;;;AClCT,SAASE,UACfC,SACAC,OACAC,MACAC,MAAY;AAEZH,UAAQI,OAAO,GAAGD,IAAAA,MAAUF,MAAMG,IAAI;AACtC,SAAOJ,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","state","x","y","object_transform","res","image_transform","save","translate","translation_x","translation_y","scale","scale_x","scale_y","rotate","rotation","Math","PI","object_rotation","object_scale_x","object_scale_y","closeDrawOp","restore","textWidth","context","state","text","size","font","measureText","width","drawText","x","y","globalAlpha","alpha","textAlign","textBaseline","w","h","initDrawOp","fillText","anchor_x","anchor_y","closeDrawOp","drawTextOutline","lineWidth","line_width","strokeText"]}
@@ -0,0 +1,2 @@
1
+ import './context.mjs';
2
+ export { s as setDrawAnchor, a as setDrawRotation, b as setDrawScale, c as setRotation, d as setScale, e as setTranslation } from '../transform-Dqo6bY4r.mjs';
@@ -0,0 +1,2 @@
1
+ import './context.js';
2
+ export { s as setDrawAnchor, a as setDrawRotation, b as setDrawScale, c as setRotation, d as setScale, e as setTranslation } from '../transform-iwq8WdqR.js';
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/core/transform.ts
22
+ var transform_exports = {};
23
+ __export(transform_exports, {
24
+ setDrawAnchor: () => setDrawAnchor,
25
+ setDrawRotation: () => setDrawRotation,
26
+ setDrawScale: () => setDrawScale,
27
+ setRotation: () => setRotation,
28
+ setScale: () => setScale,
29
+ setTranslation: () => setTranslation
30
+ });
31
+ module.exports = __toCommonJS(transform_exports);
32
+
33
+ // src/core/context.ts
34
+ function updateImageTransform(state) {
35
+ state.image_transform = state.translation_x !== 0 || state.translation_y !== 0 || state.scale_x !== 1 || state.scale_y !== 1 || state.rotation !== 0;
36
+ }
37
+ __name(updateImageTransform, "updateImageTransform");
38
+
39
+ // src/core/transform.ts
40
+ function setTranslation(state, translation_x, translation_y) {
41
+ state.translation_x = translation_x;
42
+ state.translation_y = translation_y;
43
+ if (!isFinite(state.translation_x)) {
44
+ state.translation_x = 0;
45
+ }
46
+ if (!isFinite(state.translation_y)) {
47
+ state.translation_y = 0;
48
+ }
49
+ updateImageTransform(state);
50
+ }
51
+ __name(setTranslation, "setTranslation");
52
+ function setScale(state, scale_x, scale_y) {
53
+ state.scale_x = scale_x;
54
+ state.scale_y = scale_y;
55
+ if (!isFinite(state.scale_x) || state.scale_x === 0) {
56
+ state.scale_x = 1;
57
+ }
58
+ if (!isFinite(state.scale_y) || state.scale_y === 0) {
59
+ state.scale_y = 1;
60
+ }
61
+ updateImageTransform(state);
62
+ }
63
+ __name(setScale, "setScale");
64
+ function setRotation(state, rotation) {
65
+ state.rotation = rotation;
66
+ if (!isFinite(state.rotation)) {
67
+ state.rotation = 0;
68
+ }
69
+ updateImageTransform(state);
70
+ }
71
+ __name(setRotation, "setRotation");
72
+ function setDrawAnchor(state, anchor_x, anchor_y) {
73
+ state.anchor_x = anchor_x;
74
+ state.anchor_y = anchor_y;
75
+ if (typeof state.anchor_x !== "number") {
76
+ state.anchor_x = 0;
77
+ }
78
+ if (typeof state.anchor_y !== "number") {
79
+ state.anchor_y = 0;
80
+ }
81
+ }
82
+ __name(setDrawAnchor, "setDrawAnchor");
83
+ function setDrawRotation(state, object_rotation) {
84
+ state.object_rotation = object_rotation;
85
+ }
86
+ __name(setDrawRotation, "setDrawRotation");
87
+ function setDrawScale(state, object_scale_x, object_scale_y) {
88
+ state.object_scale_x = object_scale_x;
89
+ state.object_scale_y = object_scale_y;
90
+ }
91
+ __name(setDrawScale, "setDrawScale");
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ setDrawAnchor,
95
+ setDrawRotation,
96
+ setDrawScale,
97
+ setRotation,
98
+ setScale,
99
+ setTranslation
100
+ });
101
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/transform.ts","../../src/core/context.ts"],"sourcesContent":["/**\n * Transform operations for Image class\n * Handles translation, rotation, scaling, and anchoring\n */\n\nimport type { ImageContextState } from \"./context\";\nimport { updateImageTransform } from \"./context\";\n\nexport function setTranslation(state: ImageContextState, translation_x: number, translation_y: number): void {\n\tstate.translation_x = translation_x;\n\tstate.translation_y = translation_y;\n\n\tif (!isFinite(state.translation_x)) {\n\t\tstate.translation_x = 0;\n\t}\n\tif (!isFinite(state.translation_y)) {\n\t\tstate.translation_y = 0;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setScale(state: ImageContextState, scale_x: number, scale_y: number): void {\n\tstate.scale_x = scale_x;\n\tstate.scale_y = scale_y;\n\n\tif (!isFinite(state.scale_x) || state.scale_x === 0) {\n\t\tstate.scale_x = 1;\n\t}\n\tif (!isFinite(state.scale_y) || state.scale_y === 0) {\n\t\tstate.scale_y = 1;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setRotation(state: ImageContextState, rotation: number): void {\n\tstate.rotation = rotation;\n\n\tif (!isFinite(state.rotation)) {\n\t\tstate.rotation = 0;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setDrawAnchor(state: ImageContextState, anchor_x: number, anchor_y: number): void {\n\tstate.anchor_x = anchor_x;\n\tstate.anchor_y = anchor_y;\n\n\tif (typeof state.anchor_x !== \"number\") {\n\t\tstate.anchor_x = 0;\n\t}\n\tif (typeof state.anchor_y !== \"number\") {\n\t\tstate.anchor_y = 0;\n\t}\n}\n\nexport function setDrawRotation(state: ImageContextState, object_rotation: number): void {\n\tstate.object_rotation = object_rotation;\n}\n\nexport function setDrawScale(state: ImageContextState, object_scale_x: number, object_scale_y: number): void {\n\tstate.object_scale_x = object_scale_x;\n\tstate.object_scale_y = object_scale_y;\n}\n","/**\n * Context management for Image class\n * Handles canvas context initialization and state management\n */\n\nexport interface ImageContextState {\n\talpha: number;\n\tpixelated: number;\n\tline_width: number;\n\ttranslation_x: number;\n\ttranslation_y: number;\n\trotation: number;\n\tscale_x: number;\n\tscale_y: number;\n\timage_transform: boolean;\n\tanchor_x: number;\n\tanchor_y: number;\n\tobject_rotation: number;\n\tobject_scale_x: number;\n\tobject_scale_y: number;\n\tfont: string;\n}\n\nexport function createDefaultContextState(centered: boolean): ImageContextState {\n\tif (centered) {\n\t\treturn {\n\t\t\talpha: 1,\n\t\t\tpixelated: 1,\n\t\t\tline_width: 1,\n\t\t\ttranslation_x: 0, // Will be set to width/2\n\t\t\ttranslation_y: 0, // Will be set to height/2\n\t\t\trotation: 0,\n\t\t\tscale_x: 1,\n\t\t\tscale_y: -1,\n\t\t\timage_transform: true,\n\t\t\tanchor_x: 0,\n\t\t\tanchor_y: 0,\n\t\t\tobject_rotation: 0,\n\t\t\tobject_scale_x: 1,\n\t\t\tobject_scale_y: -1,\n\t\t\tfont: \"BitCell\",\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\talpha: 1,\n\t\t\tpixelated: 1,\n\t\t\tline_width: 1,\n\t\t\ttranslation_x: 0,\n\t\t\ttranslation_y: 0,\n\t\t\trotation: 0,\n\t\t\tscale_x: 1,\n\t\t\tscale_y: 1,\n\t\t\timage_transform: false,\n\t\t\tanchor_x: -1,\n\t\t\tanchor_y: 1,\n\t\t\tobject_rotation: 0,\n\t\t\tobject_scale_x: 1,\n\t\t\tobject_scale_y: 1,\n\t\t\tfont: \"BitCell\",\n\t\t};\n\t}\n}\n\nexport function updateImageTransform(state: ImageContextState): void {\n\tstate.image_transform =\n\t\tstate.translation_x !== 0 ||\n\t\tstate.translation_y !== 0 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,UAAU;AACvCZ,UAAMY,WAAW;EAClB;AACD;AAVgBF;AAYT,SAASG,gBAAgBb,OAA0Bc,iBAAuB;AAChFd,QAAMc,kBAAkBA;AACzB;AAFgBD;AAIT,SAASE,aAAaf,OAA0BgB,gBAAwBC,gBAAsB;AACpGjB,QAAMgB,iBAAiBA;AACvBhB,QAAMiB,iBAAiBA;AACxB;AAHgBF;","names":["updateImageTransform","state","image_transform","translation_x","translation_y","scale_x","scale_y","rotation","setTranslation","state","translation_x","translation_y","isFinite","updateImageTransform","setScale","scale_x","scale_y","setRotation","rotation","setDrawAnchor","anchor_x","anchor_y","setDrawRotation","object_rotation","setDrawScale","object_scale_x","object_scale_y"]}
@@ -0,0 +1,71 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core/context.ts
5
+ function updateImageTransform(state) {
6
+ state.image_transform = state.translation_x !== 0 || state.translation_y !== 0 || state.scale_x !== 1 || state.scale_y !== 1 || state.rotation !== 0;
7
+ }
8
+ __name(updateImageTransform, "updateImageTransform");
9
+
10
+ // src/core/transform.ts
11
+ function setTranslation(state, translation_x, translation_y) {
12
+ state.translation_x = translation_x;
13
+ state.translation_y = translation_y;
14
+ if (!isFinite(state.translation_x)) {
15
+ state.translation_x = 0;
16
+ }
17
+ if (!isFinite(state.translation_y)) {
18
+ state.translation_y = 0;
19
+ }
20
+ updateImageTransform(state);
21
+ }
22
+ __name(setTranslation, "setTranslation");
23
+ function setScale(state, scale_x, scale_y) {
24
+ state.scale_x = scale_x;
25
+ state.scale_y = scale_y;
26
+ if (!isFinite(state.scale_x) || state.scale_x === 0) {
27
+ state.scale_x = 1;
28
+ }
29
+ if (!isFinite(state.scale_y) || state.scale_y === 0) {
30
+ state.scale_y = 1;
31
+ }
32
+ updateImageTransform(state);
33
+ }
34
+ __name(setScale, "setScale");
35
+ function setRotation(state, rotation) {
36
+ state.rotation = rotation;
37
+ if (!isFinite(state.rotation)) {
38
+ state.rotation = 0;
39
+ }
40
+ updateImageTransform(state);
41
+ }
42
+ __name(setRotation, "setRotation");
43
+ function setDrawAnchor(state, anchor_x, anchor_y) {
44
+ state.anchor_x = anchor_x;
45
+ state.anchor_y = anchor_y;
46
+ if (typeof state.anchor_x !== "number") {
47
+ state.anchor_x = 0;
48
+ }
49
+ if (typeof state.anchor_y !== "number") {
50
+ state.anchor_y = 0;
51
+ }
52
+ }
53
+ __name(setDrawAnchor, "setDrawAnchor");
54
+ function setDrawRotation(state, object_rotation) {
55
+ state.object_rotation = object_rotation;
56
+ }
57
+ __name(setDrawRotation, "setDrawRotation");
58
+ function setDrawScale(state, object_scale_x, object_scale_y) {
59
+ state.object_scale_x = object_scale_x;
60
+ state.object_scale_y = object_scale_y;
61
+ }
62
+ __name(setDrawScale, "setDrawScale");
63
+ export {
64
+ setDrawAnchor,
65
+ setDrawRotation,
66
+ setDrawScale,
67
+ setRotation,
68
+ setScale,
69
+ setTranslation
70
+ };
71
+ //# sourceMappingURL=transform.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/context.ts","../../src/core/transform.ts"],"sourcesContent":["/**\n * Context management for Image class\n * Handles canvas context initialization and state management\n */\n\nexport interface ImageContextState {\n\talpha: number;\n\tpixelated: number;\n\tline_width: number;\n\ttranslation_x: number;\n\ttranslation_y: number;\n\trotation: number;\n\tscale_x: number;\n\tscale_y: number;\n\timage_transform: boolean;\n\tanchor_x: number;\n\tanchor_y: number;\n\tobject_rotation: number;\n\tobject_scale_x: number;\n\tobject_scale_y: number;\n\tfont: string;\n}\n\nexport function createDefaultContextState(centered: boolean): ImageContextState {\n\tif (centered) {\n\t\treturn {\n\t\t\talpha: 1,\n\t\t\tpixelated: 1,\n\t\t\tline_width: 1,\n\t\t\ttranslation_x: 0, // Will be set to width/2\n\t\t\ttranslation_y: 0, // Will be set to height/2\n\t\t\trotation: 0,\n\t\t\tscale_x: 1,\n\t\t\tscale_y: -1,\n\t\t\timage_transform: true,\n\t\t\tanchor_x: 0,\n\t\t\tanchor_y: 0,\n\t\t\tobject_rotation: 0,\n\t\t\tobject_scale_x: 1,\n\t\t\tobject_scale_y: -1,\n\t\t\tfont: \"BitCell\",\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\talpha: 1,\n\t\t\tpixelated: 1,\n\t\t\tline_width: 1,\n\t\t\ttranslation_x: 0,\n\t\t\ttranslation_y: 0,\n\t\t\trotation: 0,\n\t\t\tscale_x: 1,\n\t\t\tscale_y: 1,\n\t\t\timage_transform: false,\n\t\t\tanchor_x: -1,\n\t\t\tanchor_y: 1,\n\t\t\tobject_rotation: 0,\n\t\t\tobject_scale_x: 1,\n\t\t\tobject_scale_y: 1,\n\t\t\tfont: \"BitCell\",\n\t\t};\n\t}\n}\n\nexport function updateImageTransform(state: ImageContextState): void {\n\tstate.image_transform =\n\t\tstate.translation_x !== 0 ||\n\t\tstate.translation_y !== 0 ||\n\t\tstate.scale_x !== 1 ||\n\t\tstate.scale_y !== 1 ||\n\t\tstate.rotation !== 0;\n}\n","/**\n * Transform operations for Image class\n * Handles translation, rotation, scaling, and anchoring\n */\n\nimport type { ImageContextState } from \"./context\";\nimport { updateImageTransform } from \"./context\";\n\nexport function setTranslation(state: ImageContextState, translation_x: number, translation_y: number): void {\n\tstate.translation_x = translation_x;\n\tstate.translation_y = translation_y;\n\n\tif (!isFinite(state.translation_x)) {\n\t\tstate.translation_x = 0;\n\t}\n\tif (!isFinite(state.translation_y)) {\n\t\tstate.translation_y = 0;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setScale(state: ImageContextState, scale_x: number, scale_y: number): void {\n\tstate.scale_x = scale_x;\n\tstate.scale_y = scale_y;\n\n\tif (!isFinite(state.scale_x) || state.scale_x === 0) {\n\t\tstate.scale_x = 1;\n\t}\n\tif (!isFinite(state.scale_y) || state.scale_y === 0) {\n\t\tstate.scale_y = 1;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setRotation(state: ImageContextState, rotation: number): void {\n\tstate.rotation = rotation;\n\n\tif (!isFinite(state.rotation)) {\n\t\tstate.rotation = 0;\n\t}\n\n\tupdateImageTransform(state);\n}\n\nexport function setDrawAnchor(state: ImageContextState, anchor_x: number, anchor_y: number): void {\n\tstate.anchor_x = anchor_x;\n\tstate.anchor_y = anchor_y;\n\n\tif (typeof state.anchor_x !== \"number\") {\n\t\tstate.anchor_x = 0;\n\t}\n\tif (typeof state.anchor_y !== \"number\") {\n\t\tstate.anchor_y = 0;\n\t}\n}\n\nexport function setDrawRotation(state: ImageContextState, object_rotation: number): void {\n\tstate.object_rotation = object_rotation;\n}\n\nexport function setDrawScale(state: ImageContextState, object_scale_x: number, object_scale_y: number): void {\n\tstate.object_scale_x = object_scale_x;\n\tstate.object_scale_y = object_scale_y;\n}\n"],"mappings":";;;;AA+DO,SAASA,qBAAqBC,OAAwB;AAC5DA,QAAMC,kBACLD,MAAME,kBAAkB,KACxBF,MAAMG,kBAAkB,KACxBH,MAAMI,YAAY,KAClBJ,MAAMK,YAAY,KAClBL,MAAMM,aAAa;AACrB;AAPgBP;;;ACvDT,SAASQ,eAAeC,OAA0BC,eAAuBC,eAAqB;AACpGF,QAAMC,gBAAgBA;AACtBD,QAAME,gBAAgBA;AAEtB,MAAI,CAACC,SAASH,MAAMC,aAAa,GAAG;AACnCD,UAAMC,gBAAgB;EACvB;AACA,MAAI,CAACE,SAASH,MAAME,aAAa,GAAG;AACnCF,UAAME,gBAAgB;EACvB;AAEAE,uBAAqBJ,KAAAA;AACtB;AAZgBD;AAcT,SAASM,SAASL,OAA0BM,SAAiBC,SAAe;AAClFP,QAAMM,UAAUA;AAChBN,QAAMO,UAAUA;AAEhB,MAAI,CAACJ,SAASH,MAAMM,OAAO,KAAKN,MAAMM,YAAY,GAAG;AACpDN,UAAMM,UAAU;EACjB;AACA,MAAI,CAACH,SAASH,MAAMO,OAAO,KAAKP,MAAMO,YAAY,GAAG;AACpDP,UAAMO,UAAU;EACjB;AAEAH,uBAAqBJ,KAAAA;AACtB;AAZgBK;AAcT,SAASG,YAAYR,OAA0BS,UAAgB;AACrET,QAAMS,WAAWA;AAEjB,MAAI,CAACN,SAASH,MAAMS,QAAQ,GAAG;AAC9BT,UAAMS,WAAW;EAClB;AAEAL,uBAAqBJ,KAAAA;AACtB;AARgBQ;AAUT,SAASE,cAAcV,OAA0BW,UAAkBC,UAAgB;AACzFZ,QAAMW,WAAWA;AACjBX,QAAMY,WAAWA;AAEjB,MAAI,OAAOZ,MAAMW,aAAa,UAAU;AACvCX,UAAMW,WAAW;EAClB;AACA,MAAI,OAAOX,MAAMY,aAAa,UAAU;AACvCZ,UAAMY,WAAW;EAClB;AACD;AAVgBF;AAYT,SAASG,gBAAgBb,OAA0Bc,iBAAuB;AAChFd,QAAMc,kBAAkBA;AACzB;AAFgBD;AAIT,SAASE,aAAaf,OAA0BgB,gBAAwBC,gBAAsB;AACpGjB,QAAMgB,iBAAiBA;AACvBhB,QAAMiB,iBAAiBA;AACxB;AAHgBF;","names":["updateImageTransform","state","image_transform","translation_x","translation_y","scale_x","scale_y","rotation","setTranslation","state","translation_x","translation_y","isFinite","updateImageTransform","setScale","scale_x","scale_y","setRotation","rotation","setDrawAnchor","anchor_x","anchor_y","setDrawRotation","object_rotation","setDrawScale","object_scale_x","object_scale_y"]}
@@ -0,0 +1,31 @@
1
+ import { ImageContextState } from './core/context.mjs';
2
+
3
+ /**
4
+ * Drawing operations for Image class
5
+ * Handles all drawing primitives (rectangles, circles, lines, etc.)
6
+ */
7
+
8
+ declare function initDrawOp(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, object_transform?: boolean): boolean;
9
+ declare function closeDrawOp(context: CanvasRenderingContext2D): void;
10
+ declare function fillRect(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number): void;
11
+ declare function fillRoundRect(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number, round: number): void;
12
+ declare function fillRound(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number): void;
13
+ declare function drawRect(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number): void;
14
+ declare function drawRoundRect(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number, round: number): void;
15
+ declare function drawRound(context: CanvasRenderingContext2D, state: ImageContextState, x: number, y: number, w: number, h: number): void;
16
+ declare function drawLine(context: CanvasRenderingContext2D, state: ImageContextState, x1: number, y1: number, x2: number, y2: number): void;
17
+
18
+ declare const drawing_closeDrawOp: typeof closeDrawOp;
19
+ declare const drawing_drawLine: typeof drawLine;
20
+ declare const drawing_drawRect: typeof drawRect;
21
+ declare const drawing_drawRound: typeof drawRound;
22
+ declare const drawing_drawRoundRect: typeof drawRoundRect;
23
+ declare const drawing_fillRect: typeof fillRect;
24
+ declare const drawing_fillRound: typeof fillRound;
25
+ declare const drawing_fillRoundRect: typeof fillRoundRect;
26
+ declare const drawing_initDrawOp: typeof initDrawOp;
27
+ declare namespace drawing {
28
+ export { drawing_closeDrawOp as closeDrawOp, drawing_drawLine as drawLine, drawing_drawRect as drawRect, drawing_drawRound as drawRound, drawing_drawRoundRect as drawRoundRect, drawing_fillRect as fillRect, drawing_fillRound as fillRound, drawing_fillRoundRect as fillRoundRect, drawing_initDrawOp as initDrawOp };
29
+ }
30
+
31
+ export { drawLine as a, drawRect as b, closeDrawOp as c, drawing as d, drawRound as e, drawRoundRect as f, fillRect as g, fillRound as h, fillRoundRect as i, initDrawOp as j };