@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,14 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ export const Rotate = (props) => {
3
+ useRenderBeforeChildren((renderingContext) => {
4
+ const { rotation } = props;
5
+ renderingContext.ctx2d.save();
6
+ renderingContext.ctx2d.rotate(rotation);
7
+ });
8
+ useRenderAfterChildren((renderingContext) => {
9
+ renderingContext.ctx2d.restore();
10
+ });
11
+ return props.children;
12
+ };
13
+ Rotate.displayName = 'Rotate';
14
+ //# sourceMappingURL=rotate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotate.js","sourceRoot":"","sources":["../../../src/components/transform/rotate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAOnC,MAAM,CAAC,MAAM,MAAM,GAA8B,CAAC,KAAK,EAAE,EAAE;IACzD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAE3B,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9B,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,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,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\n\nexport type RotateProps = RCXPropsWithChildren<{\n rotation: number;\n}>;\n\nexport const Rotate: RCXComponent<RotateProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { rotation } = props;\n\n renderingContext.ctx2d.save();\n renderingContext.ctx2d.rotate(rotation);\n });\n\n useRenderAfterChildren((renderingContext) => {\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nRotate.displayName = 'Rotate';\n"]}
@@ -0,0 +1,11 @@
1
+ import { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type ScaleProps = RCXPropsWithChildren<{
3
+ scale: number;
4
+ scaleX?: never;
5
+ scaleY?: never;
6
+ }> | RCXPropsWithChildren<{
7
+ scale: never;
8
+ scaleX: number;
9
+ scaleY: number;
10
+ }>;
11
+ export declare const Scale: RCXComponent<ScaleProps>;
@@ -0,0 +1,14 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ export const Scale = (props) => {
3
+ useRenderBeforeChildren((renderingContext) => {
4
+ const { scale, scaleX, scaleY } = props;
5
+ renderingContext.ctx2d.save();
6
+ renderingContext.ctx2d.scale(scaleX ?? scale, scaleY ?? scale);
7
+ });
8
+ useRenderAfterChildren((renderingContext) => {
9
+ renderingContext.ctx2d.restore();
10
+ });
11
+ return props.children;
12
+ };
13
+ Scale.displayName = 'Scale';
14
+ //# sourceMappingURL=scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.js","sourceRoot":"","sources":["../../../src/components/transform/scale.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAenC,MAAM,CAAC,MAAM,KAAK,GAA6B,CAAC,KAAK,EAAE,EAAE;IACvD,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAExC,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9B,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC;IACjE,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,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\n\nexport type ScaleProps =\n | RCXPropsWithChildren<{\n scale: number;\n scaleX?: never;\n scaleY?: never;\n }>\n | RCXPropsWithChildren<{\n scale: never;\n scaleX: number;\n scaleY: number;\n }>;\n\nexport const Scale: RCXComponent<ScaleProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { scale, scaleX, scaleY } = props;\n\n renderingContext.ctx2d.save();\n renderingContext.ctx2d.scale(scaleX ?? scale, scaleY ?? scale);\n });\n\n useRenderAfterChildren((renderingContext) => {\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nScale.displayName = 'Scale';\n"]}
@@ -0,0 +1,6 @@
1
+ import { RCXComponent, RCXPropsWithChildren } from '../../types.ts';
2
+ export type TranslateProps = RCXPropsWithChildren<{
3
+ x?: number;
4
+ y?: number;
5
+ }>;
6
+ export declare const Translate: RCXComponent<TranslateProps>;
@@ -0,0 +1,14 @@
1
+ import { useRenderAfterChildren, useRenderBeforeChildren, } from "../../hooks/use-render.js";
2
+ export const Translate = (props) => {
3
+ useRenderBeforeChildren((renderingContext) => {
4
+ const { x = 0, y = 0 } = props;
5
+ renderingContext.ctx2d.save();
6
+ renderingContext.ctx2d.translate(x, y);
7
+ });
8
+ useRenderAfterChildren((renderingContext) => {
9
+ renderingContext.ctx2d.restore();
10
+ });
11
+ return props.children;
12
+ };
13
+ Translate.displayName = 'Translate';
14
+ //# sourceMappingURL=translate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.js","sourceRoot":"","sources":["../../../src/components/transform/translate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAQnC,MAAM,CAAC,MAAM,SAAS,GAAiC,CAAC,KAAK,EAAE,EAAE;IAC/D,uBAAuB,CAAC,CAAC,gBAAgB,EAAE,EAAE;QAC3C,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC;QAE/B,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9B,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,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,SAAS,CAAC,WAAW,GAAG,WAAW,CAAC","sourcesContent":["import {\n useRenderAfterChildren,\n useRenderBeforeChildren,\n} from '../../hooks/use-render.ts';\nimport { RCXComponent, RCXPropsWithChildren } from '../../types.ts';\n\nexport type TranslateProps = RCXPropsWithChildren<{\n x?: number;\n y?: number;\n}>;\n\nexport const Translate: RCXComponent<TranslateProps> = (props) => {\n useRenderBeforeChildren((renderingContext) => {\n const { x = 0, y = 0 } = props;\n\n renderingContext.ctx2d.save();\n renderingContext.ctx2d.translate(x, y);\n });\n\n useRenderAfterChildren((renderingContext) => {\n renderingContext.ctx2d.restore();\n });\n\n return props.children;\n};\n\nTranslate.displayName = 'Translate';\n"]}
@@ -0,0 +1,9 @@
1
+ import type { AnyObject, RCXComponent, RCXPropsWithChildren } from '../types.ts';
2
+ export type ProviderProps<T> = RCXPropsWithChildren<{
3
+ value: T;
4
+ }>;
5
+ export declare const createContext: <T extends AnyObject>(name?: string) => {
6
+ Provider: RCXComponent<ProviderProps<T>>;
7
+ useProvide: (value: T) => void;
8
+ useInject: () => Readonly<T> | undefined;
9
+ };
@@ -0,0 +1,29 @@
1
+ import { cxGlobal } from "../internal/global.js";
2
+ export const createContext = (name) => {
3
+ const symbol = Symbol(name);
4
+ const useProvide = (value) => {
5
+ const { currentNode } = cxGlobal;
6
+ if (!currentNode) {
7
+ throw new Error('useProvide must be called inside the body of a component');
8
+ }
9
+ currentNode.context[symbol] = value;
10
+ };
11
+ const useInject = () => {
12
+ const { currentNode } = cxGlobal;
13
+ if (!currentNode) {
14
+ throw new Error('useInject must be called inside the body of a component');
15
+ }
16
+ return currentNode.context[symbol];
17
+ };
18
+ const Provider = ({ children, value }) => {
19
+ useProvide(value);
20
+ return children;
21
+ };
22
+ Provider.displayName = 'Provider';
23
+ return {
24
+ Provider,
25
+ useProvide,
26
+ useInject,
27
+ };
28
+ };
29
+ //# sourceMappingURL=create-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-context.js","sourceRoot":"","sources":["../../src/context/create-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAWjD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAsB,IAAa,EAAE,EAAE;IAClE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE5B,MAAM,UAAU,GAAG,CAAC,KAAQ,EAAE,EAAE;QAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QAED,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IACtC,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,CAAC;QAED,OAAO,WAAW,CAAC,OAAO,CAAC,MAAM,CAA4B,CAAC;IAChE,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAmC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;QACvE,UAAU,CAAC,KAAK,CAAC,CAAC;QAClB,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC;IAElC,OAAO;QACL,QAAQ;QACR,UAAU;QACV,SAAS;KACV,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { cxGlobal } from '../internal/global.ts';\nimport type {\n AnyObject,\n RCXComponent,\n RCXPropsWithChildren,\n} from '../types.ts';\n\nexport type ProviderProps<T> = RCXPropsWithChildren<{\n value: T;\n}>;\n\nexport const createContext = <T extends AnyObject>(name?: string) => {\n const symbol = Symbol(name);\n\n const useProvide = (value: T) => {\n const { currentNode } = cxGlobal;\n if (!currentNode) {\n throw new Error(\n 'useProvide must be called inside the body of a component'\n );\n }\n\n currentNode.context[symbol] = value;\n };\n\n const useInject = () => {\n const { currentNode } = cxGlobal;\n if (!currentNode) {\n throw new Error(\n 'useInject must be called inside the body of a component'\n );\n }\n\n return currentNode.context[symbol] as Readonly<T> | undefined;\n };\n\n const Provider: RCXComponent<ProviderProps<T>> = ({ children, value }) => {\n useProvide(value);\n return children;\n };\n\n Provider.displayName = 'Provider';\n\n return {\n Provider,\n useProvide,\n useInject,\n };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./create-context.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './create-context.ts';\n"]}
package/hooks/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./use-canvas-context.js";
2
+ export * from "./use-loop.js";
3
+ export * from "./use-on.js";
4
+ export * from "./use-render.js";
5
+ export * from "./use-state.js";
6
+ export * from "./use-window-size.js";
7
+ export * from "./use-linear-gradient.js";
8
+ export * from "./use-radial-gradient.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC","sourcesContent":["export * from './use-canvas-context.ts';\nexport * from './use-loop.ts';\nexport * from './use-on.ts';\nexport * from './use-render.ts';\nexport * from './use-state.ts';\nexport * from './use-window-size.ts';\nexport * from './use-linear-gradient.ts';\nexport * from './use-radial-gradient.ts';\n"]}
@@ -0,0 +1 @@
1
+ export declare const useCanvasContext: () => Readonly<import("../types.ts").RCXCanvasContext>;
@@ -0,0 +1,9 @@
1
+ import { canvasContext } from "../components/canvas/context.js";
2
+ export const useCanvasContext = () => {
3
+ const context = canvasContext.useInject();
4
+ if (!context) {
5
+ throw new Error('useCanvasContext must be used below a Canvas component');
6
+ }
7
+ return context;
8
+ };
9
+ //# sourceMappingURL=use-canvas-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-canvas-context.js","sourceRoot":"","sources":["../../src/hooks/use-canvas-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,EAAE,CAAC;IAE1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import { canvasContext } from '../components/canvas/context.ts';\n\nexport const useCanvasContext = () => {\n const context = canvasContext.useInject();\n\n if (!context) {\n throw new Error('useCanvasContext must be used below a Canvas component');\n }\n\n return context;\n};\n"]}
@@ -0,0 +1,9 @@
1
+ import type { RCXColorStop } from '../types.ts';
2
+ export interface LinearGradientConfig {
3
+ startX: number;
4
+ startY: number;
5
+ endX: number;
6
+ endY: number;
7
+ stops: readonly RCXColorStop[];
8
+ }
9
+ export declare const useLinearGradient: ({ startX, startY, endX, endY, stops, }: LinearGradientConfig) => CanvasGradient;
@@ -0,0 +1,13 @@
1
+ import { renderingContext } from "../components/canvas/context.js";
2
+ export const useLinearGradient = ({ startX, startY, endX, endY, stops, }) => {
3
+ const renderingContextState = renderingContext.useInject();
4
+ if (!renderingContextState) {
5
+ throw new Error('useLinearGradient must be called inside the body of a component');
6
+ }
7
+ const gradient = renderingContextState.ctx2d.createLinearGradient(startX, startY, endX, endY);
8
+ stops.forEach(({ offset, color }) => {
9
+ gradient.addColorStop(offset, color);
10
+ });
11
+ return gradient;
12
+ };
13
+ //# sourceMappingURL=use-linear-gradient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-linear-gradient.js","sourceRoot":"","sources":["../../src/hooks/use-linear-gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAWnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,GACgB,EAAE,EAAE;IACzB,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,SAAS,EAAE,CAAC;IAE3D,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,qBAAqB,CAAC,KAAK,CAAC,oBAAoB,CAC/D,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,CACL,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;QAClC,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { renderingContext } from '../components/canvas/context.ts';\nimport type { RCXColorStop } from '../types.ts';\n\nexport interface LinearGradientConfig {\n startX: number;\n startY: number;\n endX: number;\n endY: number;\n stops: readonly RCXColorStop[];\n}\n\nexport const useLinearGradient = ({\n startX,\n startY,\n endX,\n endY,\n stops,\n}: LinearGradientConfig) => {\n const renderingContextState = renderingContext.useInject();\n\n if (!renderingContextState) {\n throw new Error(\n 'useLinearGradient must be called inside the body of a component'\n );\n }\n\n const gradient = renderingContextState.ctx2d.createLinearGradient(\n startX,\n startY,\n endX,\n endY\n );\n\n stops.forEach(({ offset, color }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n};\n"]}
@@ -0,0 +1 @@
1
+ export declare const useLoop: (callback: () => void) => void;
@@ -0,0 +1,9 @@
1
+ import { useUnreactive } from "./use-state.js";
2
+ export const useLoop = (callback) => {
3
+ const unreactive = useUnreactive({ raf: null });
4
+ if (typeof unreactive.raf === 'number') {
5
+ window.cancelAnimationFrame(unreactive.raf);
6
+ }
7
+ unreactive.raf = window.requestAnimationFrame(callback);
8
+ };
9
+ //# sourceMappingURL=use-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-loop.js","sourceRoot":"","sources":["../../src/hooks/use-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,QAAoB,EAAE,EAAE;IAC9C,MAAM,UAAU,GAAG,aAAa,CAAyB,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IAExE,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,CAAC,oBAAoB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,UAAU,CAAC,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { useUnreactive } from './use-state.ts';\n\nexport const useLoop = (callback: () => void) => {\n const unreactive = useUnreactive<{ raf: number | null }>({ raf: null });\n\n if (typeof unreactive.raf === 'number') {\n window.cancelAnimationFrame(unreactive.raf);\n }\n\n unreactive.raf = window.requestAnimationFrame(callback);\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const useOnMount: (callback: () => void | (() => void)) => void;
2
+ export declare const useOnUnmount: (callback: () => void) => void;
@@ -0,0 +1,16 @@
1
+ import { registerHook } from "../internal/hooks.js";
2
+ export const useOnMount = (callback) => {
3
+ const hook = {
4
+ onMount: () => {
5
+ const onUnmount = callback();
6
+ if (onUnmount) {
7
+ hook.onUnmount = onUnmount;
8
+ }
9
+ },
10
+ };
11
+ registerHook('useOnMount', hook);
12
+ };
13
+ export const useOnUnmount = (callback) => {
14
+ registerHook('useOnUnmount', callback);
15
+ };
16
+ //# sourceMappingURL=use-on.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-on.js","sourceRoot":"","sources":["../../src/hooks/use-on.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAmC,EAAE,EAAE;IAChE,MAAM,IAAI,GAAmB;QAC3B,OAAO,EAAE,GAAG,EAAE;YACZ,MAAM,SAAS,GAAG,QAAQ,EAAE,CAAC;YAC7B,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC7B,CAAC;QACH,CAAC;KACF,CAAC;IACF,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAoB,EAAE,EAAE;IACnD,YAAY,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC,CAAC","sourcesContent":["import { registerHook } from '../internal/hooks.ts';\nimport type { RCXOnMountHook } from '../types.ts';\n\nexport const useOnMount = (callback: () => void | (() => void)) => {\n const hook: RCXOnMountHook = {\n onMount: () => {\n const onUnmount = callback();\n if (onUnmount) {\n hook.onUnmount = onUnmount;\n }\n },\n };\n registerHook('useOnMount', hook);\n};\n\nexport const useOnUnmount = (callback: () => void) => {\n registerHook('useOnUnmount', callback);\n};\n"]}
@@ -0,0 +1,11 @@
1
+ import type { RCXColorStop } from '../types.ts';
2
+ export interface RadialGradientConfig {
3
+ startX: number;
4
+ startY: number;
5
+ startRadius: number;
6
+ endX: number;
7
+ endY: number;
8
+ endRadius: number;
9
+ stops: readonly RCXColorStop[];
10
+ }
11
+ export declare const useRadialGradient: ({ startX, startY, startRadius, endX, endY, endRadius, stops, }: RadialGradientConfig) => CanvasGradient;
@@ -0,0 +1,13 @@
1
+ import { renderingContext } from "../components/canvas/context.js";
2
+ export const useRadialGradient = ({ startX, startY, startRadius, endX, endY, endRadius, stops, }) => {
3
+ const renderingContextState = renderingContext.useInject();
4
+ if (!renderingContextState) {
5
+ throw new Error('useRadialGradient must be called inside the body of a component');
6
+ }
7
+ const gradient = renderingContextState.ctx2d.createRadialGradient(startX, startY, startRadius, endX, endY, endRadius);
8
+ stops.forEach(({ offset, color }) => {
9
+ gradient.addColorStop(offset, color);
10
+ });
11
+ return gradient;
12
+ };
13
+ //# sourceMappingURL=use-radial-gradient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-radial-gradient.js","sourceRoot":"","sources":["../../src/hooks/use-radial-gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAanE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,MAAM,EACN,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,GACgB,EAAE,EAAE;IACzB,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,SAAS,EAAE,CAAC;IAE3D,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,qBAAqB,CAAC,KAAK,CAAC,oBAAoB,CAC/D,MAAM,EACN,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,CACV,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;QAClC,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { renderingContext } from '../components/canvas/context.ts';\nimport type { RCXColorStop } from '../types.ts';\n\nexport interface RadialGradientConfig {\n startX: number;\n startY: number;\n startRadius: number;\n endX: number;\n endY: number;\n endRadius: number;\n stops: readonly RCXColorStop[];\n}\n\nexport const useRadialGradient = ({\n startX,\n startY,\n startRadius,\n endX,\n endY,\n endRadius,\n stops,\n}: RadialGradientConfig) => {\n const renderingContextState = renderingContext.useInject();\n\n if (!renderingContextState) {\n throw new Error(\n 'useRadialGradient must be called inside the body of a component'\n );\n }\n\n const gradient = renderingContextState.ctx2d.createRadialGradient(\n startX,\n startY,\n startRadius,\n endX,\n endY,\n endRadius\n );\n\n stops.forEach(({ offset, color }) => {\n gradient.addColorStop(offset, color);\n });\n\n return gradient;\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import { RCXRenderingContext } from '../types.ts';
2
+ export declare const useRenderBeforeChildren: (callback: (renderingContext: RCXRenderingContext) => void) => void;
3
+ export declare const useRenderAfterChildren: (callback: (renderingContext: RCXRenderingContext) => void) => void;
@@ -0,0 +1,8 @@
1
+ import { registerHook } from "../internal/hooks.js";
2
+ export const useRenderBeforeChildren = (callback) => {
3
+ registerHook('useRenderBeforeChildren', callback);
4
+ };
5
+ export const useRenderAfterChildren = (callback) => {
6
+ registerHook('useRenderAfterChildren', callback);
7
+ };
8
+ //# sourceMappingURL=use-render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-render.js","sourceRoot":"","sources":["../../src/hooks/use-render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,QAAyD,EACzD,EAAE;IACF,YAAY,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,QAAyD,EACzD,EAAE;IACF,YAAY,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC,CAAC","sourcesContent":["import { registerHook } from '../internal/hooks.ts';\nimport { RCXRenderingContext } from '../types.ts';\n\nexport const useRenderBeforeChildren = (\n callback: (renderingContext: RCXRenderingContext) => void\n) => {\n registerHook('useRenderBeforeChildren', callback);\n};\n\nexport const useRenderAfterChildren = (\n callback: (renderingContext: RCXRenderingContext) => void\n) => {\n registerHook('useRenderAfterChildren', callback);\n};\n"]}
@@ -0,0 +1,3 @@
1
+ import type { AnyObject } from '../types.ts';
2
+ export declare const useReactive: <T extends AnyObject>(initialState: T) => T;
3
+ export declare const useUnreactive: <T extends AnyObject>(initialState: T) => T;
@@ -0,0 +1,5 @@
1
+ import { registerHook } from "../internal/hooks.js";
2
+ import { reactive } from "../internal/reactive.js";
3
+ export const useReactive = (initialState) => registerHook('useReactive', reactive(initialState));
4
+ export const useUnreactive = (initialState) => registerHook('useUnreactive', initialState);
5
+ //# sourceMappingURL=use-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-state.js","sourceRoot":"","sources":["../../src/hooks/use-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGnD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAsB,YAAe,EAAE,EAAE,CAClE,YAAY,CAAC,aAAa,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAsB,YAAe,EAAE,EAAE,CACpE,YAAY,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import { registerHook } from '../internal/hooks.ts';\nimport { reactive } from '../internal/reactive.ts';\nimport type { AnyObject } from '../types.ts';\n\nexport const useReactive = <T extends AnyObject>(initialState: T) =>\n registerHook('useReactive', reactive(initialState));\n\nexport const useUnreactive = <T extends AnyObject>(initialState: T) =>\n registerHook('useUnreactive', initialState);\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const useWindowSize: () => {
2
+ width: number;
3
+ height: number;
4
+ };
@@ -0,0 +1,20 @@
1
+ import { useOnMount } from "./use-on.js";
2
+ import { useReactive } from "./use-state.js";
3
+ export const useWindowSize = () => {
4
+ const size = useReactive({
5
+ width: window.innerWidth,
6
+ height: window.innerHeight,
7
+ });
8
+ useOnMount(() => {
9
+ const onResize = () => {
10
+ size.width = window.innerWidth;
11
+ size.height = window.innerHeight;
12
+ };
13
+ window.addEventListener('resize', onResize);
14
+ return () => {
15
+ window.removeEventListener('resize', onResize);
16
+ };
17
+ });
18
+ return size;
19
+ };
20
+ //# sourceMappingURL=use-window-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-window-size.js","sourceRoot":"","sources":["../../src/hooks/use-window-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,IAAI,GAAG,WAAW,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC,UAAU;QACxB,MAAM,EAAE,MAAM,CAAC,WAAW;KAC3B,CAAC,CAAC;IAEH,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;YAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC;QACnC,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAE5C,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import { useOnMount } from './use-on.ts';\nimport { useReactive } from './use-state.ts';\n\nexport const useWindowSize = () => {\n const size = useReactive({\n width: window.innerWidth,\n height: window.innerHeight,\n });\n\n useOnMount(() => {\n const onResize = () => {\n size.width = window.innerWidth;\n size.height = window.innerHeight;\n };\n\n window.addEventListener('resize', onResize);\n\n return () => {\n window.removeEventListener('resize', onResize);\n };\n });\n\n return size;\n};\n"]}
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./types.js";
2
+ export * from "./render.js";
3
+ export * from "./hooks/index.js";
4
+ export * from "./components/index.js";
5
+ export * from "./context/index.js";
6
+ export * from "./utils/index.js";
7
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './types.ts';\nexport * from './render.ts';\nexport * from './hooks/index.ts';\nexport * from './components/index.ts';\nexport * from './context/index.ts';\nexport * from './utils/index.ts';\n"]}
@@ -0,0 +1,15 @@
1
+ import type { AnyFunction, AnyObject } from '../types.ts';
2
+ type Handler<T extends AnyObject, K extends keyof T> = (data: T[K], event: K) => void;
3
+ declare class Emitter<T extends AnyObject> {
4
+ private handlers;
5
+ on: <K extends keyof T>(event: K, handler: Handler<T, K>) => () => void;
6
+ off: <K extends keyof T>(event: K, handler: Handler<T, K>) => void;
7
+ emit: <K extends keyof T>(event: K, data: T[K]) => void;
8
+ }
9
+ export declare const emitter: Emitter<{
10
+ render: null;
11
+ registerState: any;
12
+ registerBeforeChildren: AnyFunction;
13
+ registerAfterChildren: AnyFunction;
14
+ }>;
15
+ export {};
@@ -0,0 +1,19 @@
1
+ class Emitter {
2
+ handlers = {};
3
+ on = (event, handler) => {
4
+ this.handlers[event] = this.handlers[event] || [];
5
+ this.handlers[event]?.push(handler);
6
+ return () => this.off(event, handler);
7
+ };
8
+ off = (event, handler) => {
9
+ const index = this.handlers[event]?.indexOf(handler);
10
+ if (typeof index === 'number' && index >= 0) {
11
+ this.handlers[event]?.splice(index, 1);
12
+ }
13
+ };
14
+ emit = (event, data) => {
15
+ this.handlers[event]?.forEach((handler) => handler(data, event));
16
+ };
17
+ }
18
+ export const emitter = new Emitter();
19
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/internal/emitter.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO;IACH,QAAQ,GAEZ,EAAE,CAAC;IAEA,EAAE,GAAG,CAAoB,KAAQ,EAAE,OAAsB,EAAE,EAAE;QAClE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEpC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC;IAEK,GAAG,GAAG,CAAoB,KAAQ,EAAE,OAAsB,EAAE,EAAE;QACnE,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAErD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC;IAEK,IAAI,GAAG,CAAoB,KAAQ,EAAE,IAAU,EAAE,EAAE;QACxD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACnE,CAAC,CAAC;CACH;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,EAM9B,CAAC","sourcesContent":["import type { AnyFunction, AnyObject } from '../types.ts';\n\ntype Handler<T extends AnyObject, K extends keyof T> = (\n data: T[K],\n event: K\n) => void;\n\nclass Emitter<T extends AnyObject> {\n private handlers: {\n [K in keyof T]?: Handler<T, K>[];\n } = {};\n\n public on = <K extends keyof T>(event: K, handler: Handler<T, K>) => {\n this.handlers[event] = this.handlers[event] || [];\n this.handlers[event]?.push(handler);\n\n return () => this.off(event, handler);\n };\n\n public off = <K extends keyof T>(event: K, handler: Handler<T, K>) => {\n const index = this.handlers[event]?.indexOf(handler);\n\n if (typeof index === 'number' && index >= 0) {\n this.handlers[event]?.splice(index, 1);\n }\n };\n\n public emit = <K extends keyof T>(event: K, data: T[K]) => {\n this.handlers[event]?.forEach((handler) => handler(data, event));\n };\n}\n\nexport const emitter = new Emitter<{\n render: null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n registerState: any;\n registerBeforeChildren: AnyFunction;\n registerAfterChildren: AnyFunction;\n}>();\n"]}
@@ -0,0 +1,2 @@
1
+ import type { RCXGlobal } from '../types.ts';
2
+ export declare const cxGlobal: RCXGlobal;
@@ -0,0 +1,4 @@
1
+ export const cxGlobal = {
2
+ hookIndex: 0,
3
+ };
4
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/internal/global.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAc;IACjC,SAAS,EAAE,CAAC;CACb,CAAC","sourcesContent":["import type { RCXGlobal } from '../types.ts';\n\nexport const cxGlobal: RCXGlobal = {\n hookIndex: 0,\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import type { RCXHookMap } from '../types.ts';
2
+ export declare const registerHook: <H extends keyof RCXHookMap, T extends RCXHookMap[H]>(hookType: H, value: T) => T;
@@ -0,0 +1,17 @@
1
+ import { cxGlobal } from "./global.js";
2
+ export const registerHook = (hookType, value) => {
3
+ const { currentNode, hookIndex } = cxGlobal;
4
+ if (!currentNode) {
5
+ throw new Error(`${hookType} must be called inside the body of a component`);
6
+ }
7
+ const prev = currentNode.hooks[hookIndex];
8
+ if (!!prev && prev.type !== hookType) {
9
+ throw new Error(`${hookType} was called at a different time (conditionally, or in a loop)`);
10
+ }
11
+ const originalValue = prev ? prev.value : value;
12
+ const hook = { type: hookType, value: originalValue };
13
+ currentNode.hooks[hookIndex] = hook;
14
+ cxGlobal.hookIndex += 1;
15
+ return hook.value;
16
+ };
17
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/internal/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,MAAM,YAAY,GAAG,CAI1B,QAAW,EACX,KAAQ,EACR,EAAE;IACF,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IAE5C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,GAAG,QAAQ,gDAAgD,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE1C,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,GAAG,QAAQ,+DAA+D,CAC3E,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAChD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAa,CAAC;IACjE,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC,KAAU,CAAC;AACzB,CAAC,CAAC","sourcesContent":["import type { RCXHook, RCXHookMap } from '../types.ts';\nimport { cxGlobal } from './global.ts';\n\nexport const registerHook = <\n H extends keyof RCXHookMap,\n T extends RCXHookMap[H],\n>(\n hookType: H,\n value: T\n) => {\n const { currentNode, hookIndex } = cxGlobal;\n\n if (!currentNode) {\n throw new Error(\n `${hookType} must be called inside the body of a component`\n );\n }\n\n const prev = currentNode.hooks[hookIndex];\n\n if (!!prev && prev.type !== hookType) {\n throw new Error(\n `${hookType} was called at a different time (conditionally, or in a loop)`\n );\n }\n\n const originalValue = prev ? prev.value : value;\n const hook = { type: hookType, value: originalValue } as RCXHook;\n currentNode.hooks[hookIndex] = hook;\n cxGlobal.hookIndex += 1;\n return hook.value as T;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import type { AnyObject } from '../types.ts';
2
+ export declare const reactive: <T extends AnyObject>(initialState: T) => T;
@@ -0,0 +1,16 @@
1
+ import { emitter } from "./emitter.js";
2
+ export const reactive = (initialState) => new Proxy(initialState, {
3
+ set(target, key, value) {
4
+ Reflect.set(target, key, value);
5
+ emitter.emit('render', null);
6
+ return true;
7
+ },
8
+ get(target, key) {
9
+ const value = Reflect.get(target, key);
10
+ if (typeof value === 'object' && !!value) {
11
+ return reactive(value);
12
+ }
13
+ return value;
14
+ },
15
+ });
16
+ //# sourceMappingURL=reactive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../src/internal/reactive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAsB,YAAe,EAAE,EAAE,CAC/D,IAAI,KAAK,CAAC,YAAY,EAAE;IACtB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK;QACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,MAAM,EAAE,GAAG;QACb,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { AnyObject } from '../types.ts';\nimport { emitter } from './emitter.ts';\n\nexport const reactive = <T extends AnyObject>(initialState: T) =>\n new Proxy(initialState, {\n set(target, key, value) {\n Reflect.set(target, key, value);\n emitter.emit('render', null);\n return true;\n },\n get(target, key) {\n const value = Reflect.get(target, key);\n\n if (typeof value === 'object' && !!value) {\n return reactive(value);\n }\n\n return value;\n },\n });\n"]}
@@ -0,0 +1,4 @@
1
+ import type { AnyObject, RCXComponent, RCXElement, RCXFragmentProps } from './types.ts';
2
+ export declare const jsx: <C extends RCXComponent<P>, P extends AnyObject>(type: C, props: P) => RCXElement<C, P>;
3
+ export declare const jsxs: <C extends RCXComponent<P>, P extends AnyObject>(type: C, props: P) => RCXElement<C, P>;
4
+ export declare const Fragment: RCXComponent<RCXFragmentProps>;
package/jsx-runtime.js ADDED
@@ -0,0 +1,8 @@
1
+ export const jsx = (type, props) => ({
2
+ type,
3
+ props,
4
+ });
5
+ export const jsxs = jsx;
6
+ export const Fragment = ({ children }) => children;
7
+ Fragment.displayName = 'Fragment';
8
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.js","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,IAAO,EACP,KAAQ,EACU,EAAE,CAAC,CAAC;IACtB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAmC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CACvE,QAAQ,CAAC;AAEX,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC","sourcesContent":["import type {\n AnyObject,\n RCXComponent,\n RCXElement,\n RCXFragmentProps,\n} from './types.ts';\n\nexport const jsx = <C extends RCXComponent<P>, P extends AnyObject>(\n type: C,\n props: P\n): RCXElement<C, P> => ({\n type,\n props,\n});\n\nexport const jsxs = jsx;\n\nexport const Fragment: RCXComponent<RCXFragmentProps> = ({ children }) =>\n children;\n\nFragment.displayName = 'Fragment';\n"]}
package/package.json CHANGED
@@ -1,48 +1,36 @@
1
1
  {
2
2
  "name": "@blinkorb/rcx",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Reactive JSX-based library for creating HTML5 canvas applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "type": "module",
9
- "main": "./src/index.ts",
9
+ "main": "./index.js",
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./src/index.ts"
12
+ "import": "./index.js"
13
13
  },
14
14
  "./canvas": {
15
- "import": "./src/components/canvas/index.ts"
15
+ "import": "./components/canvas/index.js"
16
16
  },
17
17
  "./components": {
18
- "import": "./src/components/index.ts"
18
+ "import": "./components/index.js"
19
19
  },
20
20
  "./context": {
21
- "import": "./src/context/index.ts"
21
+ "import": "./context/index.js"
22
22
  },
23
23
  "./hooks": {
24
- "import": "./src/hooks/index.ts"
24
+ "import": "./hooks/index.js"
25
25
  },
26
26
  "./utils": {
27
- "import": "./src/utils/index.ts"
27
+ "import": "./utils/index.js"
28
28
  },
29
29
  "./jsx-runtime": {
30
- "import": "./src/jsx-runtime.ts"
30
+ "import": "./jsx-runtime.js"
31
31
  }
32
32
  },
33
- "scripts": {
34
- "start": "npm run dev",
35
- "dev": "tsb serve",
36
- "dist": "npm run build",
37
- "build": "rm -rf dist && tsc -p tsconfig.dist.json --rewriteRelativeImportExtensions && node scripts/prep-package.js",
38
- "typecheck": "tsc --noEmit",
39
- "format-check": "prettier --check *",
40
- "format": "prettier --write *",
41
- "lint": "eslint '**/*.{ts,tsx,js,jsx}'",
42
- "tests": "jest --coverage --runInBand",
43
- "test": "npm run format-check && npm run typecheck && npm run lint && npm run tests",
44
- "prepublishOnly": "npm run test && npm run dist"
45
- },
33
+ "scripts": {},
46
34
  "repository": {
47
35
  "type": "git",
48
36
  "url": "git+https://github.com/blinkorb/rcx.git"
@@ -77,4 +65,4 @@
77
65
  "ts-node": "^10.9.2",
78
66
  "typescript": "^5.7.3"
79
67
  }
80
- }
68
+ }
package/render.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { RCXElementAny } from './types.ts';
2
+ export declare const render: (element: RCXElementAny, container: HTMLElement) => (() => void) | {
3
+ error: string;
4
+ };