@blinkorb/rcx 0.0.0 → 0.0.1

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 (201) hide show
  1. package/components/canvas/context.d.ts +11 -0
  2. package/components/canvas/context.js +4 -0
  3. package/components/canvas/context.js.map +1 -0
  4. package/components/canvas/index.d.ts +7 -0
  5. package/components/canvas/index.js +62 -0
  6. package/components/canvas/index.js.map +1 -0
  7. package/components/index.js +6 -0
  8. package/components/index.js.map +1 -0
  9. package/components/paths/arc-to.d.ts +12 -0
  10. package/components/paths/arc-to.js +24 -0
  11. package/components/paths/arc-to.js.map +1 -0
  12. package/components/paths/clip.d.ts +6 -0
  13. package/components/paths/clip.js +19 -0
  14. package/components/paths/clip.js.map +1 -0
  15. package/components/paths/index.js +6 -0
  16. package/components/paths/index.js.map +1 -0
  17. package/components/paths/line.d.ts +11 -0
  18. package/components/paths/line.js +25 -0
  19. package/components/paths/line.js.map +1 -0
  20. package/components/paths/path.d.ts +8 -0
  21. package/components/paths/path.js +33 -0
  22. package/components/paths/path.js.map +1 -0
  23. package/components/paths/point.d.ts +7 -0
  24. package/components/paths/point.js +15 -0
  25. package/components/paths/point.js.map +1 -0
  26. package/components/shapes/circle.d.ts +14 -0
  27. package/components/shapes/circle.js +8 -0
  28. package/components/shapes/circle.js.map +1 -0
  29. package/components/shapes/ellipse.d.ts +15 -0
  30. package/components/shapes/ellipse.js +24 -0
  31. package/components/shapes/ellipse.js.map +1 -0
  32. package/components/shapes/index.js +4 -0
  33. package/components/shapes/index.js.map +1 -0
  34. package/components/shapes/rectangle.d.ts +10 -0
  35. package/components/shapes/rectangle.js +20 -0
  36. package/components/shapes/rectangle.js.map +1 -0
  37. package/components/text/index.js +2 -0
  38. package/components/text/index.js.map +1 -0
  39. package/components/text/text.d.ts +13 -0
  40. package/components/text/text.js +78 -0
  41. package/components/text/text.js.map +1 -0
  42. package/components/transform/index.js +4 -0
  43. package/components/transform/index.js.map +1 -0
  44. package/components/transform/rotate.d.ts +5 -0
  45. package/components/transform/rotate.js +14 -0
  46. package/components/transform/rotate.js.map +1 -0
  47. package/components/transform/scale.d.ts +11 -0
  48. package/components/transform/scale.js +14 -0
  49. package/components/transform/scale.js.map +1 -0
  50. package/components/transform/translate.d.ts +6 -0
  51. package/components/transform/translate.js +14 -0
  52. package/components/transform/translate.js.map +1 -0
  53. package/context/create-context.d.ts +9 -0
  54. package/context/create-context.js +29 -0
  55. package/context/create-context.js.map +1 -0
  56. package/context/index.js +2 -0
  57. package/context/index.js.map +1 -0
  58. package/hooks/index.js +9 -0
  59. package/hooks/index.js.map +1 -0
  60. package/hooks/use-canvas-context.d.ts +1 -0
  61. package/hooks/use-canvas-context.js +9 -0
  62. package/hooks/use-canvas-context.js.map +1 -0
  63. package/hooks/use-linear-gradient.d.ts +9 -0
  64. package/hooks/use-linear-gradient.js +13 -0
  65. package/hooks/use-linear-gradient.js.map +1 -0
  66. package/hooks/use-loop.d.ts +1 -0
  67. package/hooks/use-loop.js +9 -0
  68. package/hooks/use-loop.js.map +1 -0
  69. package/hooks/use-on.d.ts +2 -0
  70. package/hooks/use-on.js +16 -0
  71. package/hooks/use-on.js.map +1 -0
  72. package/hooks/use-radial-gradient.d.ts +11 -0
  73. package/hooks/use-radial-gradient.js +13 -0
  74. package/hooks/use-radial-gradient.js.map +1 -0
  75. package/hooks/use-render.d.ts +3 -0
  76. package/hooks/use-render.js +8 -0
  77. package/hooks/use-render.js.map +1 -0
  78. package/hooks/use-state.d.ts +3 -0
  79. package/hooks/use-state.js +5 -0
  80. package/hooks/use-state.js.map +1 -0
  81. package/hooks/use-window-size.d.ts +4 -0
  82. package/hooks/use-window-size.js +20 -0
  83. package/hooks/use-window-size.js.map +1 -0
  84. package/index.js +7 -0
  85. package/index.js.map +1 -0
  86. package/internal/emitter.d.ts +15 -0
  87. package/internal/emitter.js +19 -0
  88. package/internal/emitter.js.map +1 -0
  89. package/internal/global.d.ts +2 -0
  90. package/internal/global.js +4 -0
  91. package/internal/global.js.map +1 -0
  92. package/internal/hooks.d.ts +2 -0
  93. package/internal/hooks.js +17 -0
  94. package/internal/hooks.js.map +1 -0
  95. package/internal/reactive.d.ts +2 -0
  96. package/internal/reactive.js +16 -0
  97. package/internal/reactive.js.map +1 -0
  98. package/jsx-runtime.d.ts +4 -0
  99. package/jsx-runtime.js +8 -0
  100. package/jsx-runtime.js.map +1 -0
  101. package/package.json +11 -23
  102. package/render.d.ts +4 -0
  103. package/render.js +198 -0
  104. package/render.js.map +1 -0
  105. package/types.d.ts +108 -0
  106. package/types.js +1 -0
  107. package/types.js.map +1 -0
  108. package/utils/apply-fill-and-stroke-style.d.ts +2 -0
  109. package/utils/apply-fill-and-stroke-style.js +24 -0
  110. package/utils/apply-fill-and-stroke-style.js.map +1 -0
  111. package/utils/get-recommended-pixel-ratio.d.ts +1 -0
  112. package/utils/get-recommended-pixel-ratio.js +2 -0
  113. package/utils/get-recommended-pixel-ratio.js.map +1 -0
  114. package/utils/index.js +9 -0
  115. package/utils/index.js.map +1 -0
  116. package/utils/is-own-property-of.d.ts +2 -0
  117. package/utils/is-own-property-of.js +2 -0
  118. package/utils/is-own-property-of.js.map +1 -0
  119. package/utils/is-valid-fill-or-stroke-style.d.ts +1 -0
  120. package/utils/is-valid-fill-or-stroke-style.js +3 -0
  121. package/utils/is-valid-fill-or-stroke-style.js.map +1 -0
  122. package/utils/is-valid-stroke-cap.d.ts +1 -0
  123. package/utils/is-valid-stroke-cap.js +8 -0
  124. package/utils/is-valid-stroke-cap.js.map +1 -0
  125. package/utils/is-valid-stroke-join.d.ts +1 -0
  126. package/utils/is-valid-stroke-join.js +8 -0
  127. package/utils/is-valid-stroke-join.js.map +1 -0
  128. package/utils/resolve-styles.d.ts +2 -0
  129. package/utils/resolve-styles.js +16 -0
  130. package/utils/resolve-styles.js.map +1 -0
  131. package/utils/type-guards.d.ts +2 -0
  132. package/utils/type-guards.js +2 -0
  133. package/utils/type-guards.js.map +1 -0
  134. package/utils/with-px.d.ts +1 -0
  135. package/utils/with-px.js +2 -0
  136. package/utils/with-px.js.map +1 -0
  137. package/.eslintignore +0 -4
  138. package/.eslintrc.json +0 -286
  139. package/.gitattributes +0 -2
  140. package/.github/CODEOWNERS +0 -1
  141. package/.github/workflows/ci.yml +0 -19
  142. package/.nvmrc +0 -1
  143. package/.prettierignore +0 -28
  144. package/.prettierrc.json +0 -4
  145. package/demo/index.html +0 -29
  146. package/demo/index.tsx +0 -316
  147. package/demo/tsconfig.json +0 -12
  148. package/jest.config.ts +0 -21
  149. package/scripts/prep-package.js +0 -29
  150. package/src/components/canvas/context.ts +0 -6
  151. package/src/components/canvas/index.ts +0 -98
  152. package/src/components/paths/arc-to.ts +0 -66
  153. package/src/components/paths/clip.ts +0 -32
  154. package/src/components/paths/line.ts +0 -53
  155. package/src/components/paths/path.ts +0 -59
  156. package/src/components/paths/point.ts +0 -24
  157. package/src/components/shapes/circle.tsx +0 -32
  158. package/src/components/shapes/ellipse.ts +0 -75
  159. package/src/components/shapes/rectangle.ts +0 -45
  160. package/src/components/text/text.ts +0 -137
  161. package/src/components/transform/rotate.ts +0 -26
  162. package/src/components/transform/scale.ts +0 -34
  163. package/src/components/transform/translate.ts +0 -27
  164. package/src/context/create-context.ts +0 -49
  165. package/src/hooks/use-canvas-context.ts +0 -11
  166. package/src/hooks/use-linear-gradient.ts +0 -39
  167. package/src/hooks/use-loop.ts +0 -11
  168. package/src/hooks/use-on.ts +0 -18
  169. package/src/hooks/use-radial-gradient.ts +0 -45
  170. package/src/hooks/use-render.ts +0 -14
  171. package/src/hooks/use-state.ts +0 -9
  172. package/src/hooks/use-window-size.ts +0 -24
  173. package/src/internal/emitter.ts +0 -39
  174. package/src/internal/global.ts +0 -5
  175. package/src/internal/hooks.ts +0 -32
  176. package/src/internal/reactive.test.ts +0 -20
  177. package/src/internal/reactive.ts +0 -20
  178. package/src/jsx-runtime.ts +0 -21
  179. package/src/render.ts +0 -299
  180. package/src/types.ts +0 -151
  181. package/src/utils/apply-fill-and-stroke-style.ts +0 -33
  182. package/src/utils/get-recommended-pixel-ratio.ts +0 -2
  183. package/src/utils/is-own-property-of.ts +0 -6
  184. package/src/utils/is-valid-fill-or-stroke-style.ts +0 -5
  185. package/src/utils/is-valid-stroke-cap.ts +0 -10
  186. package/src/utils/is-valid-stroke-join.ts +0 -10
  187. package/src/utils/resolve-styles.ts +0 -21
  188. package/src/utils/type-guards.ts +0 -4
  189. package/src/utils/with-px.ts +0 -4
  190. package/tsb.config.ts +0 -11
  191. package/tsconfig.dist.json +0 -13
  192. package/tsconfig.json +0 -25
  193. /package/{src/components/index.ts → components/index.d.ts} +0 -0
  194. /package/{src/components/paths/index.ts → components/paths/index.d.ts} +0 -0
  195. /package/{src/components/shapes/index.ts → components/shapes/index.d.ts} +0 -0
  196. /package/{src/components/text/index.ts → components/text/index.d.ts} +0 -0
  197. /package/{src/components/transform/index.ts → components/transform/index.d.ts} +0 -0
  198. /package/{src/context/index.ts → context/index.d.ts} +0 -0
  199. /package/{src/hooks/index.ts → hooks/index.d.ts} +0 -0
  200. /package/{src/index.ts → index.d.ts} +0 -0
  201. /package/{src/utils/index.ts → utils/index.d.ts} +0 -0
@@ -0,0 +1,11 @@
1
+ import type { RCXCanvasContext, RCXRenderingContext } from '../../types.ts';
2
+ export declare const canvasContext: {
3
+ Provider: import("../../types.ts").RCXComponent<import("../../index.ts").ProviderProps<RCXCanvasContext>>;
4
+ useProvide: (value: RCXCanvasContext) => void;
5
+ useInject: () => Readonly<RCXCanvasContext> | undefined;
6
+ };
7
+ export declare const renderingContext: {
8
+ Provider: import("../../types.ts").RCXComponent<import("../../index.ts").ProviderProps<RCXRenderingContext>>;
9
+ useProvide: (value: RCXRenderingContext) => void;
10
+ useInject: () => Readonly<RCXRenderingContext> | undefined;
11
+ };
@@ -0,0 +1,4 @@
1
+ import { createContext } from "../../context/create-context.js";
2
+ export const canvasContext = createContext();
3
+ export const renderingContext = createContext();
4
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/components/canvas/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGhE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,EAAoB,CAAC;AAE/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,EAAuB,CAAC","sourcesContent":["import { createContext } from '../../context/create-context.ts';\nimport type { RCXCanvasContext, RCXRenderingContext } from '../../types.ts';\n\nexport const canvasContext = createContext<RCXCanvasContext>();\n\nexport const renderingContext = createContext<RCXRenderingContext>();\n"]}
@@ -0,0 +1,7 @@
1
+ import type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type CanvasProps = RCXPropsWithChildren<{
3
+ width?: number | 'auto';
4
+ height?: number | 'auto';
5
+ pixelRatio?: number | 'auto';
6
+ }>;
7
+ export declare const Canvas: RCXComponent<CanvasProps>;
@@ -0,0 +1,62 @@
1
+ import { useOnMount } from "../../hooks/use-on.js";
2
+ import { useRenderBeforeChildren } from "../../hooks/use-render.js";
3
+ import { useReactive, useUnreactive } from "../../hooks/use-state.js";
4
+ import { getRecommendedPixelRatio } from "../../utils/get-recommended-pixel-ratio.js";
5
+ import { canvasContext, renderingContext } from "./context.js";
6
+ const getValueOrAuto = (value, autoValue) => {
7
+ if (typeof value === 'number') {
8
+ return value;
9
+ }
10
+ return autoValue;
11
+ };
12
+ export const Canvas = (props) => {
13
+ const renderingContextStateRoot = renderingContext.useInject();
14
+ if (!renderingContextStateRoot) {
15
+ throw new Error('Canvas was rendered outside of an application');
16
+ }
17
+ const initialCanvasSize = renderingContextStateRoot.canvas.getBoundingClientRect();
18
+ const canvasSize = useReactive({
19
+ width: initialCanvasSize.width,
20
+ height: initialCanvasSize.height,
21
+ });
22
+ const resizeObserver = useUnreactive(new ResizeObserver((entries) => {
23
+ const canvasEntry = entries[0];
24
+ if (typeof canvasEntry === 'undefined') {
25
+ return;
26
+ }
27
+ const rect = canvasEntry.target.getBoundingClientRect();
28
+ canvasSize.width = rect.width;
29
+ canvasSize.height = rect.height;
30
+ }));
31
+ useOnMount(() => {
32
+ resizeObserver.observe(renderingContextStateRoot.canvas);
33
+ return () => {
34
+ resizeObserver.disconnect();
35
+ };
36
+ });
37
+ useRenderBeforeChildren((renderingContextState) => {
38
+ const pixelRatio = getValueOrAuto(props.pixelRatio, getRecommendedPixelRatio());
39
+ const rect = renderingContextState.canvas.getBoundingClientRect();
40
+ const width = getValueOrAuto(props.width, rect.width * pixelRatio) / pixelRatio;
41
+ const height = getValueOrAuto(props.height, rect.height * pixelRatio) / pixelRatio;
42
+ renderingContextState.canvas.width = width * pixelRatio;
43
+ renderingContextState.canvas.height = height * pixelRatio;
44
+ renderingContextState.ctx2d.scale(pixelRatio, pixelRatio);
45
+ });
46
+ const pixelRatio = getValueOrAuto(props.pixelRatio, getRecommendedPixelRatio());
47
+ const rect = renderingContextStateRoot.canvas.getBoundingClientRect();
48
+ const width = getValueOrAuto(props.width, rect.width * pixelRatio) / pixelRatio;
49
+ const height = getValueOrAuto(props.height, rect.height * pixelRatio) / pixelRatio;
50
+ canvasContext.useProvide({
51
+ ...renderingContextStateRoot,
52
+ props,
53
+ width,
54
+ height,
55
+ pixelRatio,
56
+ actualWidth: width * pixelRatio,
57
+ actualHeight: height * pixelRatio,
58
+ });
59
+ return props.children;
60
+ };
61
+ Canvas.displayName = 'Canvas';
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/canvas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,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,KAAK,GAAG,UAAU;QAC/B,YAAY,EAAE,MAAM,GAAG,UAAU;KAClC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC","sourcesContent":["import { useOnMount } from '../../hooks/use-on.ts';\nimport { useRenderBeforeChildren } from '../../hooks/use-render.ts';\nimport { useReactive, useUnreactive } from '../../hooks/use-state.ts';\nimport type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\nimport { getRecommendedPixelRatio } from '../../utils/get-recommended-pixel-ratio.ts';\nimport { canvasContext, renderingContext } from './context.ts';\n\nexport type CanvasProps = RCXPropsWithChildren<{\n width?: number | 'auto';\n height?: number | 'auto';\n pixelRatio?: number | 'auto';\n}>;\n\nconst getValueOrAuto = (\n value: undefined | number | 'auto',\n autoValue: number\n) => {\n if (typeof value === 'number') {\n return value;\n }\n\n return autoValue;\n};\n\nexport const Canvas: RCXComponent<CanvasProps> = (props) => {\n const renderingContextStateRoot = renderingContext.useInject();\n\n if (!renderingContextStateRoot) {\n throw new Error('Canvas was rendered outside of an application');\n }\n\n const initialCanvasSize =\n renderingContextStateRoot.canvas.getBoundingClientRect();\n const canvasSize = useReactive({\n width: initialCanvasSize.width,\n height: initialCanvasSize.height,\n });\n const resizeObserver = useUnreactive(\n new ResizeObserver((entries) => {\n const canvasEntry = entries[0];\n if (typeof canvasEntry === 'undefined') {\n return;\n }\n\n const rect = canvasEntry.target.getBoundingClientRect();\n canvasSize.width = rect.width;\n canvasSize.height = rect.height;\n })\n );\n\n useOnMount(() => {\n resizeObserver.observe(renderingContextStateRoot.canvas);\n\n return () => {\n resizeObserver.disconnect();\n };\n });\n\n useRenderBeforeChildren((renderingContextState) => {\n const pixelRatio = getValueOrAuto(\n props.pixelRatio,\n getRecommendedPixelRatio()\n );\n const rect = renderingContextState.canvas.getBoundingClientRect();\n const width =\n getValueOrAuto(props.width, rect.width * pixelRatio) / pixelRatio;\n const height =\n getValueOrAuto(props.height, rect.height * pixelRatio) / pixelRatio;\n\n renderingContextState.canvas.width = width * pixelRatio;\n renderingContextState.canvas.height = height * pixelRatio;\n renderingContextState.ctx2d.scale(pixelRatio, pixelRatio);\n });\n\n const pixelRatio = getValueOrAuto(\n props.pixelRatio,\n getRecommendedPixelRatio()\n );\n const rect = renderingContextStateRoot.canvas.getBoundingClientRect();\n const width =\n getValueOrAuto(props.width, rect.width * pixelRatio) / pixelRatio;\n const height =\n getValueOrAuto(props.height, rect.height * pixelRatio) / pixelRatio;\n\n canvasContext.useProvide({\n ...renderingContextStateRoot,\n props,\n width,\n height,\n pixelRatio,\n actualWidth: width * pixelRatio,\n actualHeight: height * pixelRatio,\n });\n\n return props.children;\n};\n\nCanvas.displayName = 'Canvas';\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./canvas/index.js";
2
+ export * from "./paths/index.js";
3
+ export * from "./shapes/index.js";
4
+ export * from "./text/index.js";
5
+ export * from "./transform/index.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './canvas/index.ts';\nexport * from './paths/index.ts';\nexport * from './shapes/index.ts';\nexport * from './text/index.ts';\nexport * from './transform/index.ts';\n"]}
@@ -0,0 +1,12 @@
1
+ import type { RCXComponent, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export type ArcToProps = RCXPropsWithChildren<{
3
+ startControlX: number;
4
+ startControlY: number;
5
+ endControlX: number;
6
+ endControlY: number;
7
+ radius: number;
8
+ style?: RCXStyleProp<RCXShapeStyle>;
9
+ beginPath?: boolean;
10
+ closePath?: boolean;
11
+ }>;
12
+ export declare const ArcTo: RCXComponent<ArcToProps>;
@@ -0,0 +1,24 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ import { applyFillAndStrokeStyles } from "../../utils/apply-fill-and-stroke-style.js";
3
+ import { resolveStyles } from "../../utils/resolve-styles.js";
4
+ export const ArcTo = (props) => {
5
+ useRenderBeforeChildren((renderingContext) => {
6
+ const { startControlX, startControlY, endControlX, endControlY, radius, beginPath = false, } = props;
7
+ renderingContext.ctx2d.save();
8
+ if (beginPath) {
9
+ renderingContext.ctx2d.beginPath();
10
+ }
11
+ renderingContext.ctx2d.arcTo(startControlX, startControlY, endControlX, endControlY, radius);
12
+ });
13
+ useRenderAfterChildren((renderingContext) => {
14
+ const { closePath = false } = props;
15
+ if (closePath) {
16
+ renderingContext.ctx2d.closePath();
17
+ }
18
+ applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));
19
+ renderingContext.ctx2d.restore();
20
+ });
21
+ return props.children;
22
+ };
23
+ ArcTo.displayName = 'ArcTo';
24
+ //# sourceMappingURL=arc-to.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arc-to.js","sourceRoot":"","sources":["../../../src/components/paths/arc-to.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAa9D,MAAM,CAAC,MAAM,KAAK,GAA6B,CAAC,KAAK,EAAE,EAAE;IACvD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EACJ,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,MAAM,EACN,SAAS,GAAG,KAAK,GAClB,GAAG,KAAK,CAAC;QAEV,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAC1B,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;QAEpC,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,wBAAwB,CAAC,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type {\n RCXComponent,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { applyFillAndStrokeStyles } from '../../utils/apply-fill-and-stroke-style.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\n\nexport type ArcToProps = RCXPropsWithChildren<{\n startControlX: number;\n startControlY: number;\n endControlX: number;\n endControlY: number;\n radius: number;\n style?: RCXStyleProp<RCXShapeStyle>;\n beginPath?: boolean;\n closePath?: boolean;\n}>;\n\nexport const ArcTo: RCXComponent<ArcToProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const {\n startControlX,\n startControlY,\n endControlX,\n endControlY,\n radius,\n beginPath = false,\n } = props;\n\n renderingContext.ctx2d.save();\n\n if (beginPath) {\n renderingContext.ctx2d.beginPath();\n }\n\n renderingContext.ctx2d.arcTo(\n startControlX,\n startControlY,\n endControlX,\n endControlY,\n radius\n );\n });\n\n useRenderAfterChildren((renderingContext) => {\n const { closePath = false } = props;\n\n if (closePath) {\n renderingContext.ctx2d.closePath();\n }\n\n applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));\n\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nArcTo.displayName = 'ArcTo';\n"]}
@@ -0,0 +1,6 @@
1
+ import type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type ClipProps = RCXPropsWithChildren<{
3
+ path?: Path2D;
4
+ fillRule?: CanvasFillRule;
5
+ }>;
6
+ export declare const Clip: RCXComponent<ClipProps>;
@@ -0,0 +1,19 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ export const Clip = (props) => {
3
+ useRenderBeforeChildren((renderingContext) => {
4
+ const { path, fillRule } = props;
5
+ renderingContext.ctx2d.save();
6
+ if (typeof path === 'undefined') {
7
+ renderingContext.ctx2d.clip(fillRule);
8
+ }
9
+ else {
10
+ renderingContext.ctx2d.clip(path, fillRule);
11
+ }
12
+ });
13
+ useRenderAfterChildren((renderingContext) => {
14
+ renderingContext.ctx2d.restore();
15
+ });
16
+ return props.children;
17
+ };
18
+ Clip.displayName = 'Clip';
19
+ //# sourceMappingURL=clip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clip.js","sourceRoot":"","sources":["../../../src/components/paths/clip.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAQnC,MAAM,CAAC,MAAM,IAAI,GAA4B,CAAC,KAAK,EAAE,EAAE;IACrD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAEjC,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\n\nexport type ClipProps = RCXPropsWithChildren<{\n path?: Path2D;\n fillRule?: CanvasFillRule;\n}>;\n\nexport const Clip: RCXComponent<ClipProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { path, fillRule } = props;\n\n renderingContext.ctx2d.save();\n\n if (typeof path === 'undefined') {\n renderingContext.ctx2d.clip(fillRule);\n } else {\n renderingContext.ctx2d.clip(path, fillRule);\n }\n });\n\n useRenderAfterChildren((renderingContext) => {\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nClip.displayName = 'Clip';\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./arc-to.js";
2
+ export * from "./line.js";
3
+ export * from "./path.js";
4
+ export * from "./point.js";
5
+ export * from "./clip.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/paths/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC","sourcesContent":["export * from './arc-to.ts';\nexport * from './line.ts';\nexport * from './path.ts';\nexport * from './point.ts';\nexport * from './clip.ts';\n"]}
@@ -0,0 +1,11 @@
1
+ import type { RCXComponent, RCXLineStyle, RCXPropsWithChildren, RCXStyleProp } from '../../types.ts';
2
+ export type LineProps = RCXPropsWithChildren<{
3
+ startX: number;
4
+ startY: number;
5
+ endX: number;
6
+ endY: number;
7
+ beginPath?: boolean;
8
+ closePath?: boolean;
9
+ style?: RCXStyleProp<RCXLineStyle>;
10
+ }>;
11
+ export declare const Line: RCXComponent<LineProps>;
@@ -0,0 +1,25 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ import { applyFillAndStrokeStyles } from "../../utils/apply-fill-and-stroke-style.js";
3
+ import { resolveStyles } from "../../utils/resolve-styles.js";
4
+ export const Line = (props) => {
5
+ useRenderBeforeChildren((renderingContext) => {
6
+ const { startX, startY, endX, endY, beginPath = true } = props;
7
+ renderingContext.ctx2d.save();
8
+ if (beginPath) {
9
+ renderingContext.ctx2d.beginPath();
10
+ }
11
+ renderingContext.ctx2d.moveTo(startX, startY);
12
+ renderingContext.ctx2d.lineTo(endX, endY);
13
+ });
14
+ useRenderAfterChildren((renderingContext) => {
15
+ const { closePath = false } = props;
16
+ if (closePath) {
17
+ renderingContext.ctx2d.closePath();
18
+ }
19
+ applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));
20
+ renderingContext.ctx2d.restore();
21
+ });
22
+ return props.children;
23
+ };
24
+ Line.displayName = 'Line';
25
+ //# sourceMappingURL=line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line.js","sourceRoot":"","sources":["../../../src/components/paths/line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAY9D,MAAM,CAAC,MAAM,IAAI,GAA4B,CAAC,KAAK,EAAE,EAAE;IACrD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAE/D,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;QAEpC,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,wBAAwB,CAAC,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type {\n RCXComponent,\n RCXLineStyle,\n RCXPropsWithChildren,\n RCXStyleProp,\n} from '../../types.ts';\nimport { applyFillAndStrokeStyles } from '../../utils/apply-fill-and-stroke-style.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\n\nexport type LineProps = RCXPropsWithChildren<{\n startX: number;\n startY: number;\n endX: number;\n endY: number;\n beginPath?: boolean;\n closePath?: boolean;\n style?: RCXStyleProp<RCXLineStyle>;\n}>;\n\nexport const Line: RCXComponent<LineProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { startX, startY, endX, endY, beginPath = true } = props;\n\n renderingContext.ctx2d.save();\n\n if (beginPath) {\n renderingContext.ctx2d.beginPath();\n }\n\n renderingContext.ctx2d.moveTo(startX, startY);\n renderingContext.ctx2d.lineTo(endX, endY);\n });\n\n useRenderAfterChildren((renderingContext) => {\n const { closePath = false } = props;\n\n if (closePath) {\n renderingContext.ctx2d.closePath();\n }\n\n applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));\n\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nLine.displayName = 'Line';\n"]}
@@ -0,0 +1,8 @@
1
+ import type { RCXComponent, RCXPoint, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export type PathProps = RCXPropsWithChildren<{
3
+ points?: readonly RCXPoint[];
4
+ beginPath?: boolean;
5
+ closePath?: boolean;
6
+ style?: RCXStyleProp<RCXShapeStyle>;
7
+ }>;
8
+ export declare const Path: RCXComponent<PathProps>;
@@ -0,0 +1,33 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ import { applyFillAndStrokeStyles } from "../../utils/apply-fill-and-stroke-style.js";
3
+ import { resolveStyles } from "../../utils/resolve-styles.js";
4
+ import { isArray } from "../../utils/type-guards.js";
5
+ export const Path = (props) => {
6
+ useRenderBeforeChildren((renderingContext) => {
7
+ const { points, beginPath = true } = props;
8
+ renderingContext.ctx2d.save();
9
+ if (beginPath) {
10
+ renderingContext.ctx2d.beginPath();
11
+ }
12
+ points?.forEach((point, index) => {
13
+ const [x, y] = isArray(point) ? point : [point.x, point.y];
14
+ if (index === 0) {
15
+ renderingContext.ctx2d.moveTo(x, y);
16
+ }
17
+ else {
18
+ renderingContext.ctx2d.lineTo(x, y);
19
+ }
20
+ });
21
+ });
22
+ useRenderAfterChildren((renderingContext) => {
23
+ const { closePath = false } = props;
24
+ if (closePath) {
25
+ renderingContext.ctx2d.closePath();
26
+ }
27
+ applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));
28
+ renderingContext.ctx2d.restore();
29
+ });
30
+ return props.children;
31
+ };
32
+ Path.displayName = 'Path';
33
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/components/paths/path.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAQnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AASrD,MAAM,CAAC,MAAM,IAAI,GAA4B,CAAC,KAAK,EAAE,EAAE;IACrD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAE3C,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YAE3D,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBAChB,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;QAEpC,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,wBAAwB,CAAC,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type {\n RCXComponent,\n RCXPoint,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { applyFillAndStrokeStyles } from '../../utils/apply-fill-and-stroke-style.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\nimport { isArray } from '../../utils/type-guards.ts';\n\nexport type PathProps = RCXPropsWithChildren<{\n points?: readonly RCXPoint[];\n beginPath?: boolean;\n closePath?: boolean;\n style?: RCXStyleProp<RCXShapeStyle>;\n}>;\n\nexport const Path: RCXComponent<PathProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { points, beginPath = true } = props;\n\n renderingContext.ctx2d.save();\n\n if (beginPath) {\n renderingContext.ctx2d.beginPath();\n }\n\n points?.forEach((point, index) => {\n const [x, y] = isArray(point) ? point : [point.x, point.y];\n\n if (index === 0) {\n renderingContext.ctx2d.moveTo(x, y);\n } else {\n renderingContext.ctx2d.lineTo(x, y);\n }\n });\n });\n\n useRenderAfterChildren((renderingContext) => {\n const { closePath = false } = props;\n\n if (closePath) {\n renderingContext.ctx2d.closePath();\n }\n\n applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));\n\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nPath.displayName = 'Path';\n"]}
@@ -0,0 +1,7 @@
1
+ import type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type PointProps = RCXPropsWithChildren<{
3
+ x: number;
4
+ y: number;
5
+ lineTo?: boolean;
6
+ }>;
7
+ export declare const Point: RCXComponent<PointProps>;
@@ -0,0 +1,15 @@
1
+ import { useRenderBeforeChildren } from "../../hooks/use-render.js";
2
+ export const Point = (props) => {
3
+ useRenderBeforeChildren((renderingContext) => {
4
+ const { x, y, lineTo = true } = props;
5
+ if (lineTo) {
6
+ renderingContext.ctx2d.lineTo(x, y);
7
+ }
8
+ else {
9
+ renderingContext.ctx2d.moveTo(x, y);
10
+ }
11
+ });
12
+ return props.children;
13
+ };
14
+ Point.displayName = 'Point';
15
+ //# sourceMappingURL=point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.js","sourceRoot":"","sources":["../../../src/components/paths/point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AASpE,MAAM,CAAC,MAAM,KAAK,GAA6B,CAAC,KAAK,EAAE,EAAE;IACvD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAEtC,IAAI,MAAM,EAAE,CAAC;YACX,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import { useRenderBeforeChildren } from '../../hooks/use-render.ts';\nimport type { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\n\nexport type PointProps = RCXPropsWithChildren<{\n x: number;\n y: number;\n lineTo?: boolean;\n}>;\n\nexport const Point: RCXComponent<PointProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { x, y, lineTo = true } = props;\n\n if (lineTo) {\n renderingContext.ctx2d.lineTo(x, y);\n } else {\n renderingContext.ctx2d.moveTo(x, y);\n }\n });\n\n return props.children;\n};\n\nPoint.displayName = 'Point';\n"]}
@@ -0,0 +1,14 @@
1
+ import type { RCXComponent, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export type CircleProps = RCXPropsWithChildren<{
3
+ x: number;
4
+ y: number;
5
+ radius: number;
6
+ rotation?: number;
7
+ startAngle?: number;
8
+ endAngle?: number;
9
+ counterClockwise?: boolean;
10
+ beginPath?: boolean;
11
+ closePath?: boolean;
12
+ style?: RCXStyleProp<RCXShapeStyle>;
13
+ }>;
14
+ export declare const Circle: RCXComponent<CircleProps>;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "@blinkorb/rcx/jsx-runtime";
2
+ import { Ellipse } from "./ellipse.js";
3
+ export const Circle = (props) => {
4
+ const { radius, ...rest } = props;
5
+ return (_jsx(Ellipse, { ...rest, radiusX: radius, radiusY: radius, children: props.children }));
6
+ };
7
+ Circle.displayName = 'Circle';
8
+ //# sourceMappingURL=circle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle.js","sourceRoot":"","sources":["../../../src/components/shapes/circle.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,CAAC,MAAM,MAAM,GAA8B,CAAC,KAAK,EAAE,EAAE;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAElC,OAAO,CACL,KAAC,OAAO,OAAK,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAChD,KAAK,CAAC,QAAQ,GACP,CACX,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC","sourcesContent":["import type {\n RCXComponent,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { Ellipse } from './ellipse.ts';\n\nexport type CircleProps = RCXPropsWithChildren<{\n x: number;\n y: number;\n radius: number;\n rotation?: number;\n startAngle?: number;\n endAngle?: number;\n counterClockwise?: boolean;\n beginPath?: boolean;\n closePath?: boolean;\n style?: RCXStyleProp<RCXShapeStyle>;\n}>;\n\nexport const Circle: RCXComponent<CircleProps> = (props) => {\n const { radius, ...rest } = props;\n\n return (\n <Ellipse {...rest} radiusX={radius} radiusY={radius}>\n {props.children}\n </Ellipse>\n );\n};\n\nCircle.displayName = 'Circle';\n"]}
@@ -0,0 +1,15 @@
1
+ import type { RCXComponent, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export type EllipseProps = RCXPropsWithChildren<{
3
+ x: number;
4
+ y: number;
5
+ radiusX: number;
6
+ radiusY: number;
7
+ rotation?: number;
8
+ startAngle?: number;
9
+ endAngle?: number;
10
+ counterClockwise?: boolean;
11
+ beginPath?: boolean;
12
+ closePath?: boolean;
13
+ style?: RCXStyleProp<RCXShapeStyle>;
14
+ }>;
15
+ export declare const Ellipse: RCXComponent<EllipseProps>;
@@ -0,0 +1,24 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ import { applyFillAndStrokeStyles } from "../../utils/apply-fill-and-stroke-style.js";
3
+ import { resolveStyles } from "../../utils/resolve-styles.js";
4
+ export const Ellipse = (props) => {
5
+ useRenderBeforeChildren((renderingContext) => {
6
+ const { x, y, radiusX, radiusY, rotation = 0, startAngle = 0, endAngle = Math.PI * 2, counterClockwise = false, beginPath = true, } = props;
7
+ renderingContext.ctx2d.save();
8
+ if (beginPath) {
9
+ renderingContext.ctx2d.beginPath();
10
+ }
11
+ renderingContext.ctx2d.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterClockwise);
12
+ });
13
+ useRenderAfterChildren((renderingContext) => {
14
+ const { closePath = true } = props;
15
+ if (closePath) {
16
+ renderingContext.ctx2d.closePath();
17
+ }
18
+ applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));
19
+ renderingContext.ctx2d.restore();
20
+ });
21
+ return props.children;
22
+ };
23
+ Ellipse.displayName = 'Ellipse';
24
+ //# sourceMappingURL=ellipse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ellipse.js","sourceRoot":"","sources":["../../../src/components/shapes/ellipse.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAgB9D,MAAM,CAAC,MAAM,OAAO,GAA+B,CAAC,KAAK,EAAE,EAAE;IAC3D,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EACJ,CAAC,EACD,CAAC,EACD,OAAO,EACP,OAAO,EACP,QAAQ,GAAG,CAAC,EACZ,UAAU,GAAG,CAAC,EACd,QAAQ,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,EACtB,gBAAgB,GAAG,KAAK,EACxB,SAAS,GAAG,IAAI,GACjB,GAAG,KAAK,CAAC;QAEV,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAC5B,CAAC,EACD,CAAC,EACD,OAAO,EACP,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,gBAAgB,CACjB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAEnC,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,wBAAwB,CAAC,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type {\n RCXComponent,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { applyFillAndStrokeStyles } from '../../utils/apply-fill-and-stroke-style.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\n\nexport type EllipseProps = RCXPropsWithChildren<{\n x: number;\n y: number;\n radiusX: number;\n radiusY: number;\n rotation?: number;\n startAngle?: number;\n endAngle?: number;\n counterClockwise?: boolean;\n beginPath?: boolean;\n closePath?: boolean;\n style?: RCXStyleProp<RCXShapeStyle>;\n}>;\n\nexport const Ellipse: RCXComponent<EllipseProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const {\n x,\n y,\n radiusX,\n radiusY,\n rotation = 0,\n startAngle = 0,\n endAngle = Math.PI * 2,\n counterClockwise = false,\n beginPath = true,\n } = props;\n\n renderingContext.ctx2d.save();\n\n if (beginPath) {\n renderingContext.ctx2d.beginPath();\n }\n\n renderingContext.ctx2d.ellipse(\n x,\n y,\n radiusX,\n radiusY,\n rotation,\n startAngle,\n endAngle,\n counterClockwise\n );\n });\n\n useRenderAfterChildren((renderingContext) => {\n const { closePath = true } = props;\n\n if (closePath) {\n renderingContext.ctx2d.closePath();\n }\n\n applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));\n\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nEllipse.displayName = 'Ellipse';\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./circle.js";
2
+ export * from "./ellipse.js";
3
+ export * from "./rectangle.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/shapes/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './circle.tsx';\nexport * from './ellipse.ts';\nexport * from './rectangle.ts';\n"]}
@@ -0,0 +1,10 @@
1
+ import type { RCXComponent, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export type RectangleProps = RCXPropsWithChildren<{
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ beginPath?: boolean;
8
+ style?: RCXStyleProp<RCXShapeStyle>;
9
+ }>;
10
+ export declare const Rectangle: RCXComponent<RectangleProps>;
@@ -0,0 +1,20 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ import { applyFillAndStrokeStyles } from "../../utils/apply-fill-and-stroke-style.js";
3
+ import { resolveStyles } from "../../utils/resolve-styles.js";
4
+ export const Rectangle = (props) => {
5
+ useRenderBeforeChildren((renderingContext) => {
6
+ const { x, y, width, height, beginPath = true } = props;
7
+ renderingContext.ctx2d.save();
8
+ if (beginPath) {
9
+ renderingContext.ctx2d.beginPath();
10
+ }
11
+ renderingContext.ctx2d.rect(x, y, width, height);
12
+ });
13
+ useRenderAfterChildren((renderingContext) => {
14
+ applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));
15
+ renderingContext.ctx2d.restore();
16
+ });
17
+ return props.children;
18
+ };
19
+ Rectangle.displayName = 'Rectangle';
20
+ //# sourceMappingURL=rectangle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rectangle.js","sourceRoot":"","sources":["../../../src/components/shapes/rectangle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAW9D,MAAM,CAAC,MAAM,SAAS,GAAiC,CAAC,KAAK,EAAE,EAAE;IAC/D,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QAExD,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,SAAS,EAAE,CAAC;YACd,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACrC,CAAC;QAED,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,sBAAsB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC1C,wBAAwB,CAAC,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvE,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,QAAQ,CAAC;AACxB,CAAC,CAAC;AAEF,SAAS,CAAC,WAAW,GAAG,WAAW,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport type {\n RCXComponent,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { applyFillAndStrokeStyles } from '../../utils/apply-fill-and-stroke-style.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\n\nexport type RectangleProps = RCXPropsWithChildren<{\n x: number;\n y: number;\n width: number;\n height: number;\n beginPath?: boolean;\n style?: RCXStyleProp<RCXShapeStyle>;\n}>;\n\nexport const Rectangle: RCXComponent<RectangleProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { x, y, width, height, beginPath = true } = props;\n\n renderingContext.ctx2d.save();\n\n if (beginPath) {\n renderingContext.ctx2d.beginPath();\n }\n\n renderingContext.ctx2d.rect(x, y, width, height);\n });\n\n useRenderAfterChildren((renderingContext) => {\n applyFillAndStrokeStyles(renderingContext, resolveStyles(props.style));\n\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nRectangle.displayName = 'Rectangle';\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./text.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/text/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC","sourcesContent":["export * from './text.ts';\n"]}
@@ -0,0 +1,13 @@
1
+ import type { RCXChildren, RCXComponent, RCXFontStyle, RCXPropsWithChildren, RCXShapeStyle, RCXStyleProp } from '../../types.ts';
2
+ export interface TextStyle extends RCXShapeStyle, RCXFontStyle {
3
+ align?: CanvasTextAlign;
4
+ baseline?: CanvasTextBaseline;
5
+ }
6
+ export type TextProps = RCXPropsWithChildren<{
7
+ x: number;
8
+ y: number;
9
+ maxWidth?: number;
10
+ children?: RCXChildren;
11
+ style?: RCXStyleProp<TextStyle>;
12
+ }>;
13
+ export declare const Text: RCXComponent<TextProps>;
@@ -0,0 +1,78 @@
1
+ import { useRenderBeforeChildren } from "../../hooks/use-render.js";
2
+ import { isValidFillOrStrokeStyle } from "../../utils/is-valid-fill-or-stroke-style.js";
3
+ import { isValidStrokeCap } from "../../utils/is-valid-stroke-cap.js";
4
+ import { isValidStrokeJoin } from "../../utils/is-valid-stroke-join.js";
5
+ import { resolveStyles } from "../../utils/resolve-styles.js";
6
+ import { isArray } from "../../utils/type-guards.js";
7
+ import { withPx } from "../../utils/with-px.js";
8
+ const DEFAULT_FONT_STYLE = {
9
+ // font string
10
+ fontStyle: 'normal',
11
+ fontWeight: 'normal',
12
+ fontSize: 10,
13
+ fontFamily: 'sans-serif',
14
+ // other ctx2d properties
15
+ fontStretch: 'normal',
16
+ fontVariant: 'normal',
17
+ fontKerning: 'normal',
18
+ };
19
+ const getTextFromChildren = (children) => {
20
+ if (children === null ||
21
+ typeof children === 'boolean' ||
22
+ typeof children === 'undefined') {
23
+ return '';
24
+ }
25
+ if (typeof children === 'object') {
26
+ if (isArray(children)) {
27
+ return children.reduce((acc, child) => acc + getTextFromChildren(child), '');
28
+ }
29
+ return getTextFromChildren(children.props.children);
30
+ }
31
+ return children.toString();
32
+ };
33
+ export const Text = (props) => {
34
+ useRenderBeforeChildren((renderingContext) => {
35
+ const { x, y, maxWidth, children } = props;
36
+ const { fill, stroke, strokeWidth, strokeCap, strokeJoin, align, baseline, fontStyle = DEFAULT_FONT_STYLE.fontStyle, fontWeight = DEFAULT_FONT_STYLE.fontWeight, fontSize = DEFAULT_FONT_STYLE.fontSize, fontFamily = DEFAULT_FONT_STYLE.fontFamily,
37
+ // other ctx2d properties
38
+ fontStretch = DEFAULT_FONT_STYLE.fontStretch, fontVariant = DEFAULT_FONT_STYLE.fontVariant, fontKerning = DEFAULT_FONT_STYLE.fontKerning, } = resolveStyles(props.style);
39
+ const text = getTextFromChildren(children);
40
+ renderingContext.ctx2d.save();
41
+ if (typeof align === 'string') {
42
+ renderingContext.ctx2d.textAlign = align;
43
+ }
44
+ if (typeof baseline === 'string') {
45
+ renderingContext.ctx2d.textBaseline = baseline;
46
+ }
47
+ renderingContext.ctx2d.font = [
48
+ fontStyle,
49
+ fontWeight,
50
+ withPx(fontSize),
51
+ fontFamily,
52
+ ].join(' ');
53
+ renderingContext.ctx2d.fontStretch = fontStretch;
54
+ renderingContext.ctx2d.fontVariantCaps = fontVariant;
55
+ renderingContext.ctx2d.fontKerning = fontKerning;
56
+ if (isValidFillOrStrokeStyle(fill)) {
57
+ renderingContext.ctx2d.fillStyle = fill;
58
+ renderingContext.ctx2d.fillText(text, x, y, maxWidth);
59
+ }
60
+ if (typeof strokeWidth === 'number') {
61
+ renderingContext.ctx2d.lineWidth = strokeWidth;
62
+ }
63
+ if (isValidStrokeCap(strokeCap)) {
64
+ renderingContext.ctx2d.lineCap = strokeCap;
65
+ }
66
+ if (isValidStrokeJoin(strokeJoin)) {
67
+ renderingContext.ctx2d.lineJoin = strokeJoin;
68
+ }
69
+ if (isValidFillOrStrokeStyle(stroke)) {
70
+ renderingContext.ctx2d.strokeStyle = stroke;
71
+ renderingContext.ctx2d.strokeText(text, x, y, maxWidth);
72
+ }
73
+ renderingContext.ctx2d.restore();
74
+ });
75
+ return null;
76
+ };
77
+ Text.displayName = 'Text';
78
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/components/text/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AASpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,E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C,SAAS,GAAG,IAAI,CAAC;YACxC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,gBAAgB,CAAC,KAAK,CAAC,SAAS,GAAG,WAAW,CAAC;QACjD,CAAC;QAED,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,gBAAgB,CAAC,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC;QAC7C,CAAC;QAED,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;YAClC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QAC/C,CAAC;QAED,IAAI,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,gBAAgB,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC;YAC5C,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC1D,CAAC;QAED,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC","sourcesContent":["import { useRenderBeforeChildren } from '../../hooks/use-render.ts';\nimport type {\n RCXChildren,\n RCXComponent,\n RCXFontStyle,\n RCXPropsWithChildren,\n RCXShapeStyle,\n RCXStyleProp,\n} from '../../types.ts';\nimport { isValidFillOrStrokeStyle } from '../../utils/is-valid-fill-or-stroke-style.ts';\nimport { isValidStrokeCap } from '../../utils/is-valid-stroke-cap.ts';\nimport { isValidStrokeJoin } from '../../utils/is-valid-stroke-join.ts';\nimport { resolveStyles } from '../../utils/resolve-styles.ts';\nimport { isArray } from '../../utils/type-guards.ts';\nimport { withPx } from '../../utils/with-px.ts';\n\nexport interface TextStyle extends RCXShapeStyle, RCXFontStyle {\n align?: CanvasTextAlign;\n baseline?: CanvasTextBaseline;\n}\n\nexport type TextProps = RCXPropsWithChildren<{\n x: number;\n y: number;\n maxWidth?: number;\n children?: RCXChildren;\n style?: RCXStyleProp<TextStyle>;\n}>;\n\nconst DEFAULT_FONT_STYLE = {\n // font string\n fontStyle: 'normal',\n fontWeight: 'normal',\n fontSize: 10,\n fontFamily: 'sans-serif',\n // other ctx2d properties\n fontStretch: 'normal',\n fontVariant: 'normal',\n fontKerning: 'normal',\n} satisfies Required<RCXFontStyle>;\n\nconst getTextFromChildren = (children: RCXChildren): string => {\n if (\n children === null ||\n typeof children === 'boolean' ||\n typeof children === 'undefined'\n ) {\n return '';\n }\n\n if (typeof children === 'object') {\n if (isArray(children)) {\n return children.reduce<string>(\n (acc, child) => acc + getTextFromChildren(child),\n ''\n );\n }\n\n return getTextFromChildren(children.props.children);\n }\n\n return children.toString();\n};\n\nexport const Text: RCXComponent<TextProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { x, y, maxWidth, children } = props;\n const {\n fill,\n stroke,\n strokeWidth,\n strokeCap,\n strokeJoin,\n align,\n baseline,\n fontStyle = DEFAULT_FONT_STYLE.fontStyle,\n fontWeight = DEFAULT_FONT_STYLE.fontWeight,\n fontSize = DEFAULT_FONT_STYLE.fontSize,\n fontFamily = DEFAULT_FONT_STYLE.fontFamily,\n // other ctx2d properties\n fontStretch = DEFAULT_FONT_STYLE.fontStretch,\n fontVariant = DEFAULT_FONT_STYLE.fontVariant,\n fontKerning = DEFAULT_FONT_STYLE.fontKerning,\n } = resolveStyles(props.style);\n\n const text = getTextFromChildren(children);\n\n renderingContext.ctx2d.save();\n\n if (typeof align === 'string') {\n renderingContext.ctx2d.textAlign = align;\n }\n\n if (typeof baseline === 'string') {\n renderingContext.ctx2d.textBaseline = baseline;\n }\n\n renderingContext.ctx2d.font = [\n fontStyle,\n fontWeight,\n withPx(fontSize),\n fontFamily,\n ].join(' ');\n\n renderingContext.ctx2d.fontStretch = fontStretch;\n renderingContext.ctx2d.fontVariantCaps = fontVariant;\n renderingContext.ctx2d.fontKerning = fontKerning;\n\n if (isValidFillOrStrokeStyle(fill)) {\n renderingContext.ctx2d.fillStyle = fill;\n renderingContext.ctx2d.fillText(text, x, y, maxWidth);\n }\n\n if (typeof strokeWidth === 'number') {\n renderingContext.ctx2d.lineWidth = strokeWidth;\n }\n\n if (isValidStrokeCap(strokeCap)) {\n renderingContext.ctx2d.lineCap = strokeCap;\n }\n\n if (isValidStrokeJoin(strokeJoin)) {\n renderingContext.ctx2d.lineJoin = strokeJoin;\n }\n\n if (isValidFillOrStrokeStyle(stroke)) {\n renderingContext.ctx2d.strokeStyle = stroke;\n renderingContext.ctx2d.strokeText(text, x, y, maxWidth);\n }\n\n renderingContext.ctx2d.restore();\n });\n\n return null;\n};\n\nText.displayName = 'Text';\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./translate.js";
2
+ export * from "./rotate.js";
3
+ export * from "./scale.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/transform/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC","sourcesContent":["export * from './translate.ts';\nexport * from './rotate.ts';\nexport * from './scale.ts';\n"]}
@@ -0,0 +1,5 @@
1
+ import { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type RotateProps = RCXPropsWithChildren<{
3
+ rotation: number;
4
+ }>;
5
+ export declare const Rotate: RCXComponent<RotateProps>;