@shopify/react-native-skia 0.1.115 → 0.1.119

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. package/README.md +39 -2
  2. package/cpp/api/JsiSkApi.h +13 -9
  3. package/cpp/api/JsiSkCanvas.h +9 -1
  4. package/cpp/api/JsiSkPicture.h +71 -0
  5. package/cpp/api/JsiSkPictureFactory.h +50 -0
  6. package/cpp/api/JsiSkPictureRecorder.h +53 -0
  7. package/lib/commonjs/renderer/Canvas.js +22 -36
  8. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  9. package/lib/commonjs/renderer/HostConfig.js +3 -25
  10. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  11. package/lib/commonjs/renderer/components/{Defs.js → Drawing.js} +13 -12
  12. package/lib/commonjs/renderer/components/Drawing.js.map +1 -0
  13. package/lib/commonjs/renderer/components/Group.js +31 -20
  14. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  15. package/lib/commonjs/renderer/components/Paint.js +1 -21
  16. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  17. package/lib/commonjs/renderer/components/Picture.js +35 -0
  18. package/lib/commonjs/renderer/components/Picture.js.map +1 -0
  19. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +5 -34
  20. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  21. package/lib/commonjs/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +19 -8
  22. package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -0
  23. package/lib/commonjs/renderer/components/imageFilters/index.js +4 -17
  24. package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
  25. package/lib/commonjs/renderer/components/index.js +17 -4
  26. package/lib/commonjs/renderer/components/index.js.map +1 -1
  27. package/lib/commonjs/renderer/components/maskFilters/Blur.js +1 -1
  28. package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
  29. package/lib/commonjs/renderer/components/shapes/Box.js +126 -0
  30. package/lib/commonjs/renderer/components/shapes/Box.js.map +1 -0
  31. package/lib/commonjs/renderer/components/shapes/FitBox.js +9 -5
  32. package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
  33. package/lib/commonjs/renderer/components/shapes/index.js +13 -0
  34. package/lib/commonjs/renderer/components/shapes/index.js.map +1 -1
  35. package/lib/commonjs/renderer/index.js +13 -0
  36. package/lib/commonjs/renderer/index.js.map +1 -1
  37. package/lib/commonjs/renderer/nodes/Declaration.js +12 -1
  38. package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
  39. package/lib/commonjs/renderer/nodes/Drawing.js +9 -24
  40. package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
  41. package/lib/commonjs/renderer/nodes/Node.js +9 -16
  42. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  43. package/lib/commonjs/renderer/processors/Paint.js +24 -26
  44. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  45. package/lib/commonjs/renderer/processors/math/Math.js +19 -1
  46. package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
  47. package/lib/commonjs/renderer/processors/math/Matrix3.js +11 -5
  48. package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
  49. package/lib/commonjs/renderer/typeddash.js +26 -2
  50. package/lib/commonjs/renderer/typeddash.js.map +1 -1
  51. package/lib/commonjs/renderer/useContextBridge.js +35 -0
  52. package/lib/commonjs/renderer/useContextBridge.js.map +1 -0
  53. package/lib/commonjs/skia/Canvas.js.map +1 -1
  54. package/lib/commonjs/skia/Picture/Picture.js +6 -0
  55. package/lib/commonjs/skia/Picture/Picture.js.map +1 -0
  56. package/lib/commonjs/skia/Picture/PictureFactory.js +6 -0
  57. package/lib/commonjs/skia/Picture/PictureFactory.js.map +1 -0
  58. package/lib/commonjs/skia/Picture/PictureRecorder.js +6 -0
  59. package/lib/commonjs/skia/Picture/PictureRecorder.js.map +1 -0
  60. package/lib/commonjs/skia/Picture/index.js +58 -0
  61. package/lib/commonjs/skia/Picture/index.js.map +1 -0
  62. package/lib/commonjs/skia/Picture/usePicture.js +30 -0
  63. package/lib/commonjs/skia/Picture/usePicture.js.map +1 -0
  64. package/lib/commonjs/skia/Skia.js +2 -0
  65. package/lib/commonjs/skia/Skia.js.map +1 -1
  66. package/lib/commonjs/skia/index.js +28 -0
  67. package/lib/commonjs/skia/index.js.map +1 -1
  68. package/lib/commonjs/values/hooks/useDerivedValue.js +2 -2
  69. package/lib/commonjs/values/hooks/useDerivedValue.js.map +1 -1
  70. package/lib/commonjs/views/SkiaView.js +6 -44
  71. package/lib/commonjs/views/SkiaView.js.map +1 -1
  72. package/lib/commonjs/views/types.js.map +1 -1
  73. package/lib/module/renderer/Canvas.js +20 -32
  74. package/lib/module/renderer/Canvas.js.map +1 -1
  75. package/lib/module/renderer/HostConfig.js +2 -24
  76. package/lib/module/renderer/HostConfig.js.map +1 -1
  77. package/lib/module/renderer/components/Drawing.js +17 -0
  78. package/lib/module/renderer/components/Drawing.js.map +1 -0
  79. package/lib/module/renderer/components/Group.js +32 -22
  80. package/lib/module/renderer/components/Group.js.map +1 -1
  81. package/lib/module/renderer/components/Paint.js +2 -22
  82. package/lib/module/renderer/components/Paint.js.map +1 -1
  83. package/lib/module/renderer/components/Picture.js +21 -0
  84. package/lib/module/renderer/components/Picture.js.map +1 -0
  85. package/lib/module/renderer/components/imageFilters/InnerShadow.js +4 -26
  86. package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  87. package/lib/module/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +16 -6
  88. package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -0
  89. package/lib/module/renderer/components/imageFilters/index.js +1 -2
  90. package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
  91. package/lib/module/renderer/components/index.js +2 -1
  92. package/lib/module/renderer/components/index.js.map +1 -1
  93. package/lib/module/renderer/components/maskFilters/Blur.js +1 -1
  94. package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
  95. package/lib/module/renderer/components/shapes/Box.js +102 -0
  96. package/lib/module/renderer/components/shapes/Box.js.map +1 -0
  97. package/lib/module/renderer/components/shapes/FitBox.js +5 -4
  98. package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
  99. package/lib/module/renderer/components/shapes/index.js +1 -0
  100. package/lib/module/renderer/components/shapes/index.js.map +1 -1
  101. package/lib/module/renderer/index.js +1 -0
  102. package/lib/module/renderer/index.js.map +1 -1
  103. package/lib/module/renderer/nodes/Declaration.js +4 -0
  104. package/lib/module/renderer/nodes/Declaration.js.map +1 -1
  105. package/lib/module/renderer/nodes/Drawing.js +8 -21
  106. package/lib/module/renderer/nodes/Drawing.js.map +1 -1
  107. package/lib/module/renderer/nodes/Node.js +9 -15
  108. package/lib/module/renderer/nodes/Node.js.map +1 -1
  109. package/lib/module/renderer/processors/Paint.js +22 -21
  110. package/lib/module/renderer/processors/Paint.js.map +1 -1
  111. package/lib/module/renderer/processors/math/Math.js +15 -0
  112. package/lib/module/renderer/processors/math/Math.js.map +1 -1
  113. package/lib/module/renderer/processors/math/Matrix3.js +6 -2
  114. package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
  115. package/lib/module/renderer/typeddash.js +21 -0
  116. package/lib/module/renderer/typeddash.js.map +1 -1
  117. package/lib/module/renderer/useContextBridge.js +21 -0
  118. package/lib/module/renderer/useContextBridge.js.map +1 -0
  119. package/lib/module/skia/Canvas.js.map +1 -1
  120. package/lib/module/skia/Picture/Picture.js +2 -0
  121. package/lib/module/skia/Picture/Picture.js.map +1 -0
  122. package/lib/module/skia/Picture/PictureFactory.js +2 -0
  123. package/lib/module/skia/Picture/PictureFactory.js.map +1 -0
  124. package/lib/module/skia/Picture/PictureRecorder.js +2 -0
  125. package/lib/module/skia/Picture/PictureRecorder.js.map +1 -0
  126. package/lib/module/skia/Picture/index.js +5 -0
  127. package/lib/module/skia/Picture/index.js.map +1 -0
  128. package/lib/module/skia/Picture/usePicture.js +19 -0
  129. package/lib/module/skia/Picture/usePicture.js.map +1 -0
  130. package/lib/module/skia/Skia.js +2 -0
  131. package/lib/module/skia/Skia.js.map +1 -1
  132. package/lib/module/skia/index.js +2 -0
  133. package/lib/module/skia/index.js.map +1 -1
  134. package/lib/module/values/hooks/useDerivedValue.js +1 -1
  135. package/lib/module/values/hooks/useDerivedValue.js.map +1 -1
  136. package/lib/module/views/SkiaView.js +6 -44
  137. package/lib/module/views/SkiaView.js.map +1 -1
  138. package/lib/module/views/types.js.map +1 -1
  139. package/lib/typescript/src/renderer/Canvas.d.ts +5 -10
  140. package/lib/typescript/src/renderer/components/Drawing.d.ts +7 -0
  141. package/lib/typescript/src/renderer/components/Picture.d.ts +6 -0
  142. package/lib/typescript/src/renderer/components/imageFilters/InnerShadow.d.ts +3 -12
  143. package/lib/typescript/src/renderer/components/imageFilters/{DropShadow.d.ts → Shadow.d.ts} +3 -2
  144. package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -2
  145. package/lib/typescript/src/renderer/components/index.d.ts +2 -1
  146. package/lib/typescript/src/renderer/components/shapes/Box.d.ts +23 -0
  147. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +9 -0
  148. package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
  149. package/lib/typescript/src/renderer/index.d.ts +1 -0
  150. package/lib/typescript/src/renderer/nodes/Declaration.d.ts +3 -0
  151. package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
  152. package/lib/typescript/src/renderer/nodes/Node.d.ts +2 -2
  153. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -2
  154. package/lib/typescript/src/renderer/processors/math/Math.d.ts +14 -0
  155. package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -0
  156. package/lib/typescript/src/renderer/typeddash.d.ts +1 -0
  157. package/lib/typescript/src/renderer/useContextBridge.d.ts +5 -0
  158. package/lib/typescript/src/skia/Canvas.d.ts +6 -0
  159. package/lib/typescript/src/skia/Picture/Picture.d.ts +26 -0
  160. package/lib/typescript/src/skia/Picture/PictureFactory.d.ts +8 -0
  161. package/lib/typescript/src/skia/Picture/PictureRecorder.d.ts +15 -0
  162. package/lib/typescript/src/skia/Picture/index.d.ts +4 -0
  163. package/lib/typescript/src/skia/Picture/usePicture.d.ts +11 -0
  164. package/lib/typescript/src/skia/Skia.d.ts +5 -0
  165. package/lib/typescript/src/skia/index.d.ts +2 -0
  166. package/lib/typescript/src/views/SkiaView.d.ts +28 -13
  167. package/lib/typescript/src/views/types.d.ts +0 -23
  168. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  169. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  170. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  171. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  172. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  173. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  174. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  175. package/package.json +7 -7
  176. package/src/renderer/Canvas.tsx +14 -30
  177. package/src/renderer/HostConfig.ts +2 -20
  178. package/src/renderer/components/Drawing.tsx +16 -0
  179. package/src/renderer/components/Group.tsx +44 -27
  180. package/src/renderer/components/Paint.tsx +5 -35
  181. package/src/renderer/components/Picture.tsx +17 -0
  182. package/src/renderer/components/imageFilters/InnerShadow.tsx +33 -47
  183. package/src/renderer/components/imageFilters/Shadow.tsx +39 -0
  184. package/src/renderer/components/imageFilters/index.ts +1 -2
  185. package/src/renderer/components/index.ts +2 -1
  186. package/src/renderer/components/maskFilters/Blur.tsx +1 -1
  187. package/src/renderer/components/shapes/Box.tsx +98 -0
  188. package/src/renderer/components/shapes/FitBox.tsx +6 -4
  189. package/src/renderer/components/shapes/index.ts +1 -0
  190. package/src/renderer/index.ts +1 -0
  191. package/src/renderer/nodes/Declaration.tsx +14 -0
  192. package/src/renderer/nodes/Drawing.tsx +16 -26
  193. package/src/renderer/nodes/Node.ts +9 -12
  194. package/src/renderer/processors/Paint.ts +34 -31
  195. package/src/renderer/processors/math/Math.ts +16 -0
  196. package/src/renderer/processors/math/Matrix3.ts +35 -31
  197. package/src/renderer/typeddash.ts +18 -0
  198. package/src/renderer/useContextBridge.tsx +21 -0
  199. package/src/skia/Canvas.ts +7 -0
  200. package/src/skia/Picture/Picture.ts +34 -0
  201. package/src/skia/Picture/PictureFactory.ts +9 -0
  202. package/src/skia/Picture/PictureRecorder.ts +18 -0
  203. package/src/skia/Picture/index.ts +4 -0
  204. package/src/skia/Picture/usePicture.ts +28 -0
  205. package/src/skia/Skia.ts +5 -0
  206. package/src/skia/index.ts +2 -0
  207. package/src/values/hooks/useDerivedValue.ts +1 -1
  208. package/src/views/SkiaView.tsx +31 -41
  209. package/src/views/types.ts +0 -24
  210. package/lib/commonjs/renderer/components/Defs.js.map +0 -1
  211. package/lib/commonjs/renderer/components/imageFilters/DropShadow.js.map +0 -1
  212. package/lib/module/renderer/components/Defs.js +0 -16
  213. package/lib/module/renderer/components/Defs.js.map +0 -1
  214. package/lib/module/renderer/components/imageFilters/DropShadow.js.map +0 -1
  215. package/lib/typescript/src/renderer/components/Defs.d.ts +0 -5
  216. package/src/renderer/components/Defs.tsx +0 -19
  217. package/src/renderer/components/imageFilters/DropShadow.tsx +0 -31
@@ -0,0 +1,102 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from "react";
4
+ import { ClipOp, BlurStyle, Skia, processColor } from "../../../skia";
5
+ import { createDrawing } from "../../nodes";
6
+ import { add, vec, rrect } from "../../processors";
7
+ import { rect, isRRect } from "../../processors/Rects";
8
+ import { createDeclaration } from "../../nodes/Declaration";
9
+
10
+ const inflate = function (box, dx, dy) {
11
+ let tx = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
12
+ let ty = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
13
+ return rrect(rect(box.rect.x - dx + tx, box.rect.y - dy + ty, box.rect.width + 2 * dx, box.rect.height + 2 * dy), box.rx + dx, box.ry + dy);
14
+ };
15
+
16
+ const deflate = function (box, dx, dy) {
17
+ let tx = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
18
+ let ty = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
19
+ return inflate(box, -dx, -dy, tx, ty);
20
+ };
21
+
22
+ const onDeclare = createDeclaration(_ref => {
23
+ let {
24
+ dx,
25
+ dy,
26
+ spread,
27
+ blur,
28
+ color,
29
+ inner
30
+ } = _ref;
31
+ return {
32
+ dx,
33
+ dy,
34
+ spread,
35
+ blur,
36
+ color,
37
+ inner,
38
+ __typename__: "BoxShadow"
39
+ };
40
+ });
41
+ export const BoxShadow = props => {
42
+ return /*#__PURE__*/React.createElement("skDeclaration", _extends({
43
+ onDeclare: onDeclare
44
+ }, props));
45
+ };
46
+
47
+ const isBoxShadow = s => s.__typename__ === "BoxShadow";
48
+
49
+ const onDraw = createDrawing((ctx, _ref2, node) => {
50
+ let {
51
+ box: defaultBox
52
+ } = _ref2;
53
+ const box = isRRect(defaultBox) ? defaultBox : rrect(defaultBox, 0, 0);
54
+ const {
55
+ canvas,
56
+ paint,
57
+ opacity
58
+ } = ctx;
59
+ const shadows = node.visit(ctx).filter(isBoxShadow);
60
+ shadows.filter(shadow => !shadow.inner).map(shadow => {
61
+ const {
62
+ color = "black",
63
+ blur,
64
+ spread = 0,
65
+ dx = 0,
66
+ dy = 0
67
+ } = shadow;
68
+ const lPaint = Skia.Paint();
69
+ lPaint.setColor(processColor(color, opacity));
70
+ lPaint.setMaskFilter(Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true));
71
+ canvas.drawRRect(inflate(box, spread, spread, dx, dy), lPaint);
72
+ });
73
+ canvas.drawRRect(box, paint);
74
+ shadows.filter(shadow => shadow.inner).map(shadow => {
75
+ const {
76
+ color = "black",
77
+ blur,
78
+ spread = 0,
79
+ dx = 0,
80
+ dy = 0
81
+ } = shadow;
82
+ const delta = add(vec(10, 10), vec(Math.abs(dx), Math.abs(dy)));
83
+ canvas.save();
84
+ canvas.clipRRect(box, ClipOp.Intersect, false);
85
+ const lPaint = Skia.Paint();
86
+ lPaint.setColor(processColor(color, opacity));
87
+ lPaint.setMaskFilter(Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true));
88
+ const inner = deflate(box, spread, spread, dx, dy);
89
+ const outer = inflate(box, delta.x, delta.y);
90
+ canvas.drawDRRect(outer, inner, lPaint);
91
+ canvas.restore();
92
+ });
93
+ });
94
+ export const Box = props => {
95
+ return /*#__PURE__*/React.createElement("skDrawing", _extends({
96
+ onDraw: onDraw
97
+ }, props));
98
+ };
99
+ Box.defaultProps = {
100
+ shadows: []
101
+ };
102
+ //# sourceMappingURL=Box.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Box.tsx"],"names":["React","ClipOp","BlurStyle","Skia","processColor","createDrawing","add","vec","rrect","rect","isRRect","createDeclaration","inflate","box","dx","dy","tx","ty","x","y","width","height","rx","ry","deflate","onDeclare","spread","blur","color","inner","__typename__","BoxShadow","props","isBoxShadow","s","onDraw","ctx","node","defaultBox","canvas","paint","opacity","shadows","visit","filter","shadow","map","lPaint","Paint","setColor","setMaskFilter","MaskFilter","MakeBlur","Normal","drawRRect","delta","Math","abs","save","clipRRect","Intersect","outer","drawDRRect","restore","Box","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,MAAT,EAAiBC,SAAjB,EAA4BC,IAA5B,EAAkCC,YAAlC,QAAsD,eAAtD;AACA,SAASC,aAAT,QAA8B,aAA9B;AAEA,SAASC,GAAT,EAAcC,GAAd,EAAmBC,KAAnB,QAAgC,kBAAhC;AACA,SAASC,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AArB;AACA,UAAM8C,KAAK,GAAGjD,OAAO,CAACC,GAAD,EAAM0C,KAAK,CAACrC,CAAZ,EAAeqC,KAAK,CAACpC,CAArB,CAArB;AACAoB,IAAAA,MAAM,CAACuB,UAAP,CAAkBD,KAAlB,EAAyBhC,KAAzB,EAAgCkB,MAAhC;AACAR,IAAAA,MAAM,CAACwB,OAAP;AACD,GAhBH;AAiBD,CAlC2B,CAA5B;AAoCA,OAAO,MAAMC,GAAG,GAAIhC,KAAD,IAAoC;AACrD,sBAAO;AAAW,IAAA,MAAM,EAAEG;AAAnB,KAA+BH,KAA/B,EAAP;AACD,CAFM;AAIPgC,GAAG,CAACC,YAAJ,GAAmB;AACjBvB,EAAAA,OAAO,EAAE;AADQ,CAAnB","sourcesContent":["import React from \"react\";\n\nimport type { Color, SkRRect } from \"../../../skia\";\nimport { ClipOp, BlurStyle, Skia, processColor } from \"../../../skia\";\nimport { createDrawing } from \"../../nodes\";\nimport type { AnimatedProps, CustomPaintProps } from \"../../processors\";\nimport { add, vec, rrect } from \"../../processors\";\nimport { rect, isRRect } from \"../../processors/Rects\";\nimport { createDeclaration } from \"../../nodes/Declaration\";\nimport type { SkJSIInstance } from \"../../../skia/JsiInstance\";\nimport type { SkRect } from \"../../../skia/Rect\";\n\nconst inflate = (box: SkRRect, dx: number, dy: number, tx = 0, ty = 0) =>\n rrect(\n rect(\n box.rect.x - dx + tx,\n box.rect.y - dy + ty,\n box.rect.width + 2 * dx,\n box.rect.height + 2 * dy\n ),\n box.rx + dx,\n box.ry + dy\n );\n\nconst deflate = (box: SkRRect, dx: number, dy: number, tx = 0, ty = 0) =>\n inflate(box, -dx, -dy, tx, ty);\n\ninterface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n\ninterface BoxShadowDecl extends BoxShadowProps, SkJSIInstance<\"BoxShadow\"> {}\n\nconst onDeclare = createDeclaration<BoxShadowProps>(\n ({ dx, dy, spread, blur, color, inner }) => {\n return { dx, dy, spread, blur, color, inner, __typename__: \"BoxShadow\" };\n }\n);\n\nexport const BoxShadow = (props: AnimatedProps<BoxShadowProps>) => {\n return <skDeclaration onDeclare={onDeclare} {...props} />;\n};\n\nconst isBoxShadow = (s: SkJSIInstance<string>): s is BoxShadowDecl =>\n s.__typename__ === \"BoxShadow\";\n\ninterface BoxProps extends CustomPaintProps {\n box: SkRRect | SkRect;\n}\n\nconst onDraw = createDrawing<BoxProps>((ctx, { box: defaultBox }, node) => {\n const box = isRRect(defaultBox) ? defaultBox : rrect(defaultBox, 0, 0);\n const { canvas, paint, opacity } = ctx;\n const shadows = node.visit(ctx).filter<BoxShadowDecl>(isBoxShadow);\n shadows\n .filter((shadow) => !shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const lPaint = Skia.Paint();\n lPaint.setColor(processColor(color, opacity));\n lPaint.setMaskFilter(\n Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n canvas.drawRRect(inflate(box, spread, spread, dx, dy), lPaint);\n });\n canvas.drawRRect(box, paint);\n\n shadows\n .filter((shadow) => shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const delta = add(vec(10, 10), vec(Math.abs(dx), Math.abs(dy)));\n canvas.save();\n canvas.clipRRect(box, ClipOp.Intersect, false);\n const lPaint = Skia.Paint();\n lPaint.setColor(processColor(color, opacity));\n lPaint.setMaskFilter(\n Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n const inner = deflate(box, spread, spread, dx, dy);\n const outer = inflate(box, delta.x, delta.y);\n canvas.drawDRRect(outer, inner, lPaint);\n canvas.restore();\n });\n});\n\nexport const Box = (props: AnimatedProps<BoxProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nBox.defaultProps = {\n shadows: [],\n};\n"]}
@@ -1,6 +1,10 @@
1
1
  import React, { useMemo } from "react";
2
2
  import { rect2rect, fitRects } from "../image";
3
3
  import { Group } from "../Group";
4
+ export const fitbox = (fit, src, dst) => {
5
+ const rects = fitRects(fit, src, dst);
6
+ return rect2rect(rects.src, rects.dst);
7
+ };
4
8
  export const FitBox = _ref => {
5
9
  let {
6
10
  fit,
@@ -8,10 +12,7 @@ export const FitBox = _ref => {
8
12
  dst,
9
13
  children
10
14
  } = _ref;
11
- const transform = useMemo(() => {
12
- const rects = fitRects(fit, src, dst);
13
- return rect2rect(rects.src, rects.dst);
14
- }, [dst, fit, src]);
15
+ const transform = useMemo(() => fitbox(fit, src, dst), [dst, fit, src]);
15
16
  return /*#__PURE__*/React.createElement(Group, {
16
17
  transform: transform
17
18
  }, children);
@@ -1 +1 @@
1
- {"version":3,"sources":["FitBox.tsx"],"names":["React","useMemo","rect2rect","fitRects","Group","FitBox","fit","src","dst","children","transform","rects","defaultProps"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,OAAhB,QAA+B,OAA/B;AAGA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,UAApC;AAEA,SAASC,KAAT,QAAsB,UAAtB;AASA,OAAO,MAAMC,MAAM,GAAG,QAA2C;AAAA,MAA1C;AAAEC,IAAAA,GAAF;AAAOC,IAAAA,GAAP;AAAYC,IAAAA,GAAZ;AAAiBC,IAAAA;AAAjB,GAA0C;AAC/D,QAAMC,SAAS,GAAGT,OAAO,CAAC,MAAM;AAC9B,UAAMU,KAAK,GAAGR,QAAQ,CAACG,GAAD,EAAMC,GAAN,EAAWC,GAAX,CAAtB;AACA,WAAON,SAAS,CAACS,KAAK,CAACJ,GAAP,EAAYI,KAAK,CAACH,GAAlB,CAAhB;AACD,GAHwB,EAGtB,CAACA,GAAD,EAAMF,GAAN,EAAWC,GAAX,CAHsB,CAAzB;AAIA,sBAAO,oBAAC,KAAD;AAAO,IAAA,SAAS,EAAEG;AAAlB,KAA8BD,QAA9B,CAAP;AACD,CANM;AAQPJ,MAAM,CAACO,YAAP,GAAsB;AACpBN,EAAAA,GAAG,EAAE;AADe,CAAtB","sourcesContent":["import type { ReactNode } from \"react\";\nimport React, { useMemo } from \"react\";\n\nimport type { Fit } from \"../image\";\nimport { rect2rect, fitRects } from \"../image\";\nimport type { SkRect } from \"../../../skia\";\nimport { Group } from \"../Group\";\n\ninterface FitProps {\n fit: Fit;\n src: SkRect;\n dst: SkRect;\n children: ReactNode | ReactNode[];\n}\n\nexport const FitBox = ({ fit, src, dst, children }: FitProps) => {\n const transform = useMemo(() => {\n const rects = fitRects(fit, src, dst);\n return rect2rect(rects.src, rects.dst);\n }, [dst, fit, src]);\n return <Group transform={transform}>{children}</Group>;\n};\n\nFitBox.defaultProps = {\n fit: \"contain\",\n};\n"]}
1
+ {"version":3,"sources":["FitBox.tsx"],"names":["React","useMemo","rect2rect","fitRects","Group","fitbox","fit","src","dst","rects","FitBox","children","transform","defaultProps"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,OAAhB,QAA+B,OAA/B;AAGA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,UAApC;AAEA,SAASC,KAAT,QAAsB,UAAtB;AASA,OAAO,MAAMC,MAAM,GAAG,CAACC,GAAD,EAAWC,GAAX,EAAwBC,GAAxB,KAAwC;AAC5D,QAAMC,KAAK,GAAGN,QAAQ,CAACG,GAAD,EAAMC,GAAN,EAAWC,GAAX,CAAtB;AACA,SAAON,SAAS,CAACO,KAAK,CAACF,GAAP,EAAYE,KAAK,CAACD,GAAlB,CAAhB;AACD,CAHM;AAKP,OAAO,MAAME,MAAM,GAAG,QAA2C;AAAA,MAA1C;AAAEJ,IAAAA,GAAF;AAAOC,IAAAA,GAAP;AAAYC,IAAAA,GAAZ;AAAiBG,IAAAA;AAAjB,GAA0C;AAC/D,QAAMC,SAAS,GAAGX,OAAO,CAAC,MAAMI,MAAM,CAACC,GAAD,EAAMC,GAAN,EAAWC,GAAX,CAAb,EAA8B,CAACA,GAAD,EAAMF,GAAN,EAAWC,GAAX,CAA9B,CAAzB;AACA,sBAAO,oBAAC,KAAD;AAAO,IAAA,SAAS,EAAEK;AAAlB,KAA8BD,QAA9B,CAAP;AACD,CAHM;AAKPD,MAAM,CAACG,YAAP,GAAsB;AACpBP,EAAAA,GAAG,EAAE;AADe,CAAtB","sourcesContent":["import type { ReactNode } from \"react\";\nimport React, { useMemo } from \"react\";\n\nimport type { Fit } from \"../image\";\nimport { rect2rect, fitRects } from \"../image\";\nimport type { SkRect } from \"../../../skia\";\nimport { Group } from \"../Group\";\n\ninterface FitProps {\n fit: Fit;\n src: SkRect;\n dst: SkRect;\n children: ReactNode | ReactNode[];\n}\n\nexport const fitbox = (fit: Fit, src: SkRect, dst: SkRect) => {\n const rects = fitRects(fit, src, dst);\n return rect2rect(rects.src, rects.dst);\n};\n\nexport const FitBox = ({ fit, src, dst, children }: FitProps) => {\n const transform = useMemo(() => fitbox(fit, src, dst), [dst, fit, src]);\n return <Group transform={transform}>{children}</Group>;\n};\n\nFitBox.defaultProps = {\n fit: \"contain\",\n};\n"]}
@@ -10,4 +10,5 @@ export * from "./Patch";
10
10
  export * from "./Vertices";
11
11
  export * from "./Fill";
12
12
  export * from "./FitBox";
13
+ export * from "./Box";
13
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAd;AACA,cAAc,QAAd;AACA,cAAc,eAAd;AACA,cAAc,YAAd;AACA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,UAAd;AACA,cAAc,SAAd;AACA,cAAc,YAAd;AACA,cAAc,QAAd;AACA,cAAc,UAAd","sourcesContent":["export * from \"./Circle\";\nexport * from \"./Rect\";\nexport * from \"./RoundedRect\";\nexport * from \"./DiffRect\";\nexport * from \"./Line\";\nexport * from \"./Path\";\nexport * from \"./Oval\";\nexport * from \"./Points\";\nexport * from \"./Patch\";\nexport * from \"./Vertices\";\nexport * from \"./Fill\";\nexport * from \"./FitBox\";\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAd;AACA,cAAc,QAAd;AACA,cAAc,eAAd;AACA,cAAc,YAAd;AACA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,UAAd;AACA,cAAc,SAAd;AACA,cAAc,YAAd;AACA,cAAc,QAAd;AACA,cAAc,UAAd;AACA,cAAc,OAAd","sourcesContent":["export * from \"./Circle\";\nexport * from \"./Rect\";\nexport * from \"./RoundedRect\";\nexport * from \"./DiffRect\";\nexport * from \"./Line\";\nexport * from \"./Path\";\nexport * from \"./Oval\";\nexport * from \"./Points\";\nexport * from \"./Patch\";\nexport * from \"./Vertices\";\nexport * from \"./Fill\";\nexport * from \"./FitBox\";\nexport * from \"./Box\";\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from "./Canvas";
2
2
  export * from "./components";
3
3
  export * from "./nodes";
4
+ export * from "./useContextBridge";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAd;AACA,cAAc,cAAd;AACA,cAAc,SAAd","sourcesContent":["export * from \"./Canvas\";\nexport * from \"./components\";\nexport * from \"./nodes\";\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAd;AACA,cAAc,cAAd;AACA,cAAc,SAAd;AACA,cAAc,oBAAd","sourcesContent":["export * from \"./Canvas\";\nexport * from \"./components\";\nexport * from \"./nodes\";\nexport * from \"./useContextBridge\";\n"]}
@@ -1,8 +1,12 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
+ import { useCallback } from "react";
3
4
  import { isAnimated, materialize } from "../processors";
4
5
  import { Node } from "./Node";
5
6
  export const createDeclaration = cb => cb;
7
+ export const useDeclaration = (cb, deps) => // eslint-disable-next-line react-hooks/exhaustive-deps
8
+ useCallback(cb, deps !== null && deps !== void 0 ? deps : []);
9
+ export const isDeclarationNode = node => node instanceof DeclarationNode;
6
10
  export class DeclarationNode extends Node {
7
11
  constructor(depMgr, onDeclare, props) {
8
12
  super(depMgr, props);
@@ -1 +1 @@
1
- {"version":3,"sources":["Declaration.tsx"],"names":["isAnimated","materialize","Node","createDeclaration","cb","DeclarationNode","constructor","depMgr","onDeclare","props","memoizable","_props","draw","ctx","children","visit","obj"],"mappings":";;AAGA,SAASA,UAAT,EAAqBC,WAArB,QAAwC,eAAxC;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,iBAAiB,GAC5BC,EAD+B,IAEJA,EAFtB;AAQP,OAAO,MAAMC,eAAN,SAAiCH,IAAjC,CAAyC;AAG9CI,EAAAA,WAAW,CACTC,MADS,EAETC,SAFS,EAGTC,KAHS,EAIT;AACA,UAAMF,MAAN,EAAcE,KAAd;;AADA;;AAEA,UAAMC,UAAN,GAAmB,CAACV,UAAU,CAACS,KAAD,CAA9B;AACA,SAAKD,SAAL,GAAiBA,SAAjB;AACD;;AAEQ,MAALC,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKC,UAAL,GAAkB,CAACV,UAAU,CAACS,KAAD,CAA7B;AACA,UAAMA,KAAN,GAAcA,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKE,MAAZ;AACD;;AAEDC,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,QAAQ,GAAG,KAAKC,KAAL,CAAWF,GAAX,CAAjB;AACA,UAAMJ,KAAK,GAAGR,WAAW,CAAC,KAAKQ,KAAN,CAAzB;AACA,UAAMO,GAAG,GAAG,KAAKR,SAAL,CAAeC,KAAf,EAAsBK,QAAtB,EAAgCD,GAAhC,CAAZ;AACA,WAAOG,GAAP;AACD;;AA3B6C","sourcesContent":["import type { DrawingContext } from \"../DrawingContext\";\nimport type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { AnimatedProps } from \"../processors\";\nimport { isAnimated, materialize } from \"../processors\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\nexport type DeclarationResult = SkJSIInstance<string> | null;\n\ntype DeclarationCallback<T> = (\n props: T,\n children: DeclarationResult[],\n ctx: DrawingContext\n) => DeclarationResult;\n\nexport const createDeclaration = <T,>(\n cb: DeclarationCallback<T>\n): DeclarationCallback<T> => cb;\n\nexport interface DeclarationProps<P> {\n onDeclare: DeclarationCallback<P>;\n}\n\nexport class DeclarationNode<P> extends Node<P> {\n private onDeclare: DeclarationCallback<P>;\n\n constructor(\n depMgr: DependencyManager,\n onDeclare: DeclarationCallback<P>,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n super.memoizable = !isAnimated(props);\n this.onDeclare = onDeclare;\n }\n\n set props(props: AnimatedProps<P>) {\n this.memoizable = !isAnimated(props);\n super.props = props;\n }\n\n get props() {\n return this._props;\n }\n\n draw(ctx: DrawingContext) {\n const children = this.visit(ctx);\n const props = materialize(this.props);\n const obj = this.onDeclare(props, children, ctx);\n return obj;\n }\n}\n"]}
1
+ {"version":3,"sources":["Declaration.tsx"],"names":["useCallback","isAnimated","materialize","Node","createDeclaration","cb","useDeclaration","deps","isDeclarationNode","node","DeclarationNode","constructor","depMgr","onDeclare","props","memoizable","_props","draw","ctx","children","visit","obj"],"mappings":";;AACA,SAASA,WAAT,QAA4B,OAA5B;AAKA,SAASC,UAAT,EAAqBC,WAArB,QAAwC,eAAxC;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,iBAAiB,GAC5BC,EAD+B,IAEJA,EAFtB;AAIP,OAAO,MAAMC,cAAc,GAAG,CAC5BD,EAD4B,EAE5BE,IAF4B,KAI5B;AACAP,WAAW,CAACK,EAAD,EAAKE,IAAL,aAAKA,IAAL,cAAKA,IAAL,GAAa,EAAb,CALN;AAOP,OAAO,MAAMC,iBAAiB,GAC5BC,IAD+B,IAEMA,IAAI,YAAYC,eAFhD;AAQP,OAAO,MAAMA,eAAN,SAAiCP,IAAjC,CAAyC;AAG9CQ,EAAAA,WAAW,CACTC,MADS,EAETC,SAFS,EAGTC,KAHS,EAIT;AACA,UAAMF,MAAN,EAAcE,KAAd;;AADA;;AAEA,UAAMC,UAAN,GAAmB,CAACd,UAAU,CAACa,KAAD,CAA9B;AACA,SAAKD,SAAL,GAAiBA,SAAjB;AACD;;AAEQ,MAALC,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKC,UAAL,GAAkB,CAACd,UAAU,CAACa,KAAD,CAA7B;AACA,UAAMA,KAAN,GAAcA,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKE,MAAZ;AACD;;AAEDC,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,QAAQ,GAAG,KAAKC,KAAL,CAAWF,GAAX,CAAjB;AACA,UAAMJ,KAAK,GAAGZ,WAAW,CAAC,KAAKY,KAAN,CAAzB;AACA,UAAMO,GAAG,GAAG,KAAKR,SAAL,CAAeC,KAAf,EAAsBK,QAAtB,EAAgCD,GAAhC,CAAZ;AACA,WAAOG,GAAP;AACD;;AA3B6C","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback } from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { AnimatedProps } from \"../processors\";\nimport { isAnimated, materialize } from \"../processors\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\nexport type DeclarationResult = SkJSIInstance<string> | null;\n\ntype DeclarationCallback<T> = (\n props: T,\n children: DeclarationResult[],\n ctx: DrawingContext\n) => DeclarationResult;\n\nexport const createDeclaration = <T,>(\n cb: DeclarationCallback<T>\n): DeclarationCallback<T> => cb;\n\nexport const useDeclaration = <P,>(\n cb: DeclarationCallback<P>,\n deps?: DependencyList\n) =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useCallback(cb, deps ?? []);\n\nexport const isDeclarationNode = (\n node: Node\n): node is DeclarationNode<unknown> => node instanceof DeclarationNode;\n\nexport interface DeclarationProps<P> {\n onDeclare: DeclarationCallback<P>;\n}\n\nexport class DeclarationNode<P> extends Node<P> {\n private onDeclare: DeclarationCallback<P>;\n\n constructor(\n depMgr: DependencyManager,\n onDeclare: DeclarationCallback<P>,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n super.memoizable = !isAnimated(props);\n this.onDeclare = onDeclare;\n }\n\n set props(props: AnimatedProps<P>) {\n this.memoizable = !isAnimated(props);\n super.props = props;\n }\n\n get props() {\n return this._props;\n }\n\n draw(ctx: DrawingContext) {\n const children = this.visit(ctx);\n const props = materialize(this.props);\n const obj = this.onDeclare(props, children, ctx);\n return obj;\n }\n}\n"]}
@@ -1,14 +1,13 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
- import React from "react";
4
- import { processPaint, selectPaint } from "../processors";
3
+ import { useCallback } from "react";
4
+ import { processPaint } from "../processors";
5
5
  import { materialize } from "../processors/Animations/Animations";
6
6
  import { isPaint } from "../../skia";
7
7
  import { Node } from "./Node";
8
8
  export const createDrawing = cb => cb;
9
- export const Drawing = props => {
10
- return /*#__PURE__*/React.createElement("skDrawing", props);
11
- };
9
+ export const useDrawing = (cb, deps) => // eslint-disable-next-line react-hooks/exhaustive-deps
10
+ useCallback(cb, deps !== null && deps !== void 0 ? deps : []);
12
11
  export class DrawingNode extends Node {
13
12
  constructor(depMgr, onDraw, skipProcessing, props) {
14
13
  super(depMgr, props);
@@ -27,23 +26,11 @@ export class DrawingNode extends Node {
27
26
  if (this.skipProcessing) {
28
27
  this.onDraw(ctx, drawingProps, this);
29
28
  } else {
30
- const selectedPaint = selectPaint(ctx.paint, drawingProps);
31
- processPaint(selectedPaint, ctx.opacity, drawingProps); // to draw only once:
32
- // onDraw({ ...ctx, paint: selectedPaint }, children);
33
-
34
- [selectedPaint, ...this.children.map(child => {
35
- //if (child.type === NodeType.Declaration) {
36
- const ret = child.draw(ctx);
37
-
38
- if (ret) {
39
- return ret;
40
- } //}
41
-
42
-
43
- return null;
44
- }).filter(isPaint)].forEach(paint => {
29
+ const declarations = this.visit(ctx);
30
+ const paint = processPaint(ctx.paint.copy(), ctx.opacity, drawingProps, declarations);
31
+ [paint, ...declarations.filter(isPaint)].forEach(currentPaint => {
45
32
  this.onDraw({ ...ctx,
46
- paint
33
+ paint: currentPaint
47
34
  }, drawingProps, this);
48
35
  });
49
36
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["Drawing.tsx"],"names":["React","processPaint","selectPaint","materialize","isPaint","Node","createDrawing","cb","Drawing","props","DrawingNode","constructor","depMgr","onDraw","skipProcessing","draw","ctx","drawingProps","selectedPaint","paint","opacity","children","map","child","ret","filter","forEach"],"mappings":";;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,YAAT,EAAuBC,WAAvB,QAA0C,eAA1C;AAEA,SAASC,WAAT,QAA4B,qCAA5B;AACA,SAASC,OAAT,QAAwB,YAAxB;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,aAAa,GAAQC,EAAL,IAC3BA,EADK;AASP,OAAO,MAAMC,OAAO,GAAQC,KAAL,IAAgC;AACrD,sBAAO,iCAAeA,KAAf,CAAP;AACD,CAFM;AAIP,OAAO,MAAMC,WAAN,SAA6BL,IAA7B,CAAqC;AAI1CM,EAAAA,WAAW,CACTC,MADS,EAETC,MAFS,EAGTC,cAHS,EAITL,KAJS,EAKT;AACA,UAAMG,MAAN,EAAcH,KAAd;;AADA;;AAAA;;AAEA,SAAKI,MAAL,GAAcA,MAAd;AACA,SAAKC,cAAL,GAAsBA,cAAtB;AACD;;AAEDC,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,YAAY,GAAGd,WAAW,CAAC,KAAKM,KAAN,CAAhC;;AACA,QAAI,KAAKK,cAAT,EAAyB;AACvB,WAAKD,MAAL,CAAYG,GAAZ,EAAiBC,YAAjB,EAA+B,IAA/B;AACD,KAFD,MAEO;AACL,YAAMC,aAAa,GAAGhB,WAAW,CAACc,GAAG,CAACG,KAAL,EAAYF,YAAZ,CAAjC;AACAhB,MAAAA,YAAY,CAACiB,aAAD,EAAgBF,GAAG,CAACI,OAApB,EAA6BH,YAA7B,CAAZ,CAFK,CAGL;AACA;;AACA,OACEC,aADF,EAEE,GAAG,KAAKG,QAAL,CACAC,GADA,CACKC,KAAD,IAAW;AACd;AACA,cAAMC,GAAG,GAAGD,KAAK,CAACR,IAAN,CAAWC,GAAX,CAAZ;;AACA,YAAIQ,GAAJ,EAAS;AACP,iBAAOA,GAAP;AACD,SALa,CAMd;;;AACA,eAAO,IAAP;AACD,OATA,EAUAC,MAVA,CAUOrB,OAVP,CAFL,EAaEsB,OAbF,CAaWP,KAAD,IAAW;AACnB,aAAKN,MAAL,CAAY,EAAE,GAAGG,GAAL;AAAUG,UAAAA;AAAV,SAAZ,EAA+BF,YAA/B,EAA6C,IAA7C;AACD,OAfD;AAgBD;AACF;;AAzCyC","sourcesContent":["import type { ReactNode } from \"react\";\nimport React from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport { processPaint, selectPaint } from \"../processors\";\nimport type { AnimatedProps } from \"../processors/Animations/Animations\";\nimport { materialize } from \"../processors/Animations/Animations\";\nimport { isPaint } from \"../../skia\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\ntype DrawingCallback<P> = (\n ctx: DrawingContext,\n props: P,\n node: Node<P>\n) => void;\n\ntype OnDrawCallback<P> = (ctx: DrawingContext, props: P, node: Node<P>) => void;\n\nexport const createDrawing = <P,>(cb: OnDrawCallback<P>): DrawingCallback<P> =>\n cb;\n\nexport type DrawingProps<T> = {\n onDraw: DrawingCallback<T>;\n skipProcessing?: boolean;\n children?: ReactNode | ReactNode[];\n};\n\nexport const Drawing = <P,>(props: DrawingProps<P>) => {\n return <skDrawing {...props} />;\n};\n\nexport class DrawingNode<P> extends Node<P> {\n onDraw: DrawingCallback<P>;\n skipProcessing: boolean;\n\n constructor(\n depMgr: DependencyManager,\n onDraw: DrawingCallback<P>,\n skipProcessing: boolean,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n this.onDraw = onDraw;\n this.skipProcessing = skipProcessing;\n }\n\n draw(ctx: DrawingContext) {\n const drawingProps = materialize(this.props);\n if (this.skipProcessing) {\n this.onDraw(ctx, drawingProps, this);\n } else {\n const selectedPaint = selectPaint(ctx.paint, drawingProps);\n processPaint(selectedPaint, ctx.opacity, drawingProps);\n // to draw only once:\n // onDraw({ ...ctx, paint: selectedPaint }, children);\n [\n selectedPaint,\n ...this.children\n .map((child) => {\n //if (child.type === NodeType.Declaration) {\n const ret = child.draw(ctx);\n if (ret) {\n return ret;\n }\n //}\n return null;\n })\n .filter(isPaint),\n ].forEach((paint) => {\n this.onDraw({ ...ctx, paint }, drawingProps, this);\n });\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["Drawing.tsx"],"names":["useCallback","processPaint","materialize","isPaint","Node","createDrawing","cb","useDrawing","deps","DrawingNode","constructor","depMgr","onDraw","skipProcessing","props","draw","ctx","drawingProps","declarations","visit","paint","copy","opacity","filter","forEach","currentPaint"],"mappings":";;AACA,SAASA,WAAT,QAA4B,OAA5B;AAGA,SAASC,YAAT,QAA6B,eAA7B;AAEA,SAASC,WAAT,QAA4B,qCAA5B;AACA,SAASC,OAAT,QAAwB,YAAxB;AAGA,SAASC,IAAT,QAAqB,QAArB;AAUA,OAAO,MAAMC,aAAa,GAAQC,EAAL,IAC3BA,EADK;AAGP,OAAO,MAAMC,UAAU,GAAG,CAAKD,EAAL,EAA4BE,IAA5B,KACxB;AACAR,WAAW,CAACM,EAAD,EAAKE,IAAL,aAAKA,IAAL,cAAKA,IAAL,GAAa,EAAb,CAFN;AAUP,OAAO,MAAMC,WAAN,SAA6BL,IAA7B,CAAqC;AAI1CM,EAAAA,WAAW,CACTC,MADS,EAETC,MAFS,EAGTC,cAHS,EAITC,KAJS,EAKT;AACA,UAAMH,MAAN,EAAcG,KAAd;;AADA;;AAAA;;AAEA,SAAKF,MAAL,GAAcA,MAAd;AACA,SAAKC,cAAL,GAAsBA,cAAtB;AACD;;AAEDE,EAAAA,IAAI,CAACC,GAAD,EAAsB;AACxB,UAAMC,YAAY,GAAGf,WAAW,CAAC,KAAKY,KAAN,CAAhC;;AACA,QAAI,KAAKD,cAAT,EAAyB;AACvB,WAAKD,MAAL,CAAYI,GAAZ,EAAiBC,YAAjB,EAA+B,IAA/B;AACD,KAFD,MAEO;AACL,YAAMC,YAAY,GAAG,KAAKC,KAAL,CAAWH,GAAX,CAArB;AACA,YAAMI,KAAK,GAAGnB,YAAY,CACxBe,GAAG,CAACI,KAAJ,CAAUC,IAAV,EADwB,EAExBL,GAAG,CAACM,OAFoB,EAGxBL,YAHwB,EAIxBC,YAJwB,CAA1B;AAMA,OAACE,KAAD,EAAQ,GAAGF,YAAY,CAACK,MAAb,CAAoBpB,OAApB,CAAX,EAAyCqB,OAAzC,CAAkDC,YAAD,IAAkB;AACjE,aAAKb,MAAL,CAAY,EAAE,GAAGI,GAAL;AAAUI,UAAAA,KAAK,EAAEK;AAAjB,SAAZ,EAA6CR,YAA7C,EAA2D,IAA3D;AACD,OAFD;AAGD;AACF;;AA/ByC","sourcesContent":["import type { DependencyList, ReactNode } from \"react\";\nimport { useCallback } from \"react\";\n\nimport type { DrawingContext } from \"../DrawingContext\";\nimport { processPaint } from \"../processors\";\nimport type { AnimatedProps } from \"../processors/Animations/Animations\";\nimport { materialize } from \"../processors/Animations/Animations\";\nimport { isPaint } from \"../../skia\";\nimport type { DependencyManager } from \"../DependencyManager\";\n\nimport { Node } from \"./Node\";\n\ntype DrawingCallback<P> = (\n ctx: DrawingContext,\n props: P,\n node: Node<P>\n) => void;\n\ntype OnDrawCallback<P> = (ctx: DrawingContext, props: P, node: Node<P>) => void;\n\nexport const createDrawing = <P,>(cb: OnDrawCallback<P>): DrawingCallback<P> =>\n cb;\n\nexport const useDrawing = <P,>(cb: OnDrawCallback<P>, deps?: DependencyList) =>\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useCallback(cb, deps ?? []);\n\nexport type DrawingProps<T> = {\n onDraw: DrawingCallback<T>;\n skipProcessing?: boolean;\n children?: ReactNode | ReactNode[];\n};\n\nexport class DrawingNode<P> extends Node<P> {\n onDraw: DrawingCallback<P>;\n skipProcessing: boolean;\n\n constructor(\n depMgr: DependencyManager,\n onDraw: DrawingCallback<P>,\n skipProcessing: boolean,\n props: AnimatedProps<P>\n ) {\n super(depMgr, props);\n this.onDraw = onDraw;\n this.skipProcessing = skipProcessing;\n }\n\n draw(ctx: DrawingContext) {\n const drawingProps = materialize(this.props);\n if (this.skipProcessing) {\n this.onDraw(ctx, drawingProps, this);\n } else {\n const declarations = this.visit(ctx);\n const paint = processPaint(\n ctx.paint.copy(),\n ctx.opacity,\n drawingProps,\n declarations\n );\n [paint, ...declarations.filter(isPaint)].forEach((currentPaint) => {\n this.onDraw({ ...ctx, paint: currentPaint }, drawingProps, this);\n });\n }\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
- import { isPaint } from "../../skia";
4
3
  export let NodeType;
5
4
 
6
5
  (function (NodeType) {
@@ -16,7 +15,7 @@ export class Node {
16
15
 
17
16
  _defineProperty(this, "memoizable", false);
18
17
 
19
- _defineProperty(this, "memoized", false);
18
+ _defineProperty(this, "memoized", null);
20
19
 
21
20
  _defineProperty(this, "parent", void 0);
22
21
 
@@ -38,26 +37,21 @@ export class Node {
38
37
  return this._props;
39
38
  }
40
39
 
41
- visit(ctx) {
40
+ visit(ctx, children) {
42
41
  const returnedValues = [];
43
- let currentCtx = ctx;
44
- this.children.forEach(child => {
42
+ (children !== null && children !== void 0 ? children : this.children).forEach(child => {
45
43
  if (!child.memoized) {
46
- const ret = child.draw(currentCtx);
44
+ const ret = child.draw(ctx);
47
45
 
48
46
  if (ret) {
49
- if (isPaint(ret)) {
50
- currentCtx = { ...currentCtx,
51
- paint: ret
52
- };
53
- }
54
-
55
47
  returnedValues.push(ret);
56
- }
57
48
 
58
- if (child.memoizable) {
59
- child.memoized = true;
49
+ if (child.memoizable) {
50
+ child.memoized = ret;
51
+ }
60
52
  }
53
+ } else {
54
+ returnedValues.push(child.memoized);
61
55
  }
62
56
  });
63
57
  return returnedValues;
@@ -1 +1 @@
1
- {"version":3,"sources":["Node.ts"],"names":["isPaint","NodeType","Node","constructor","depMgr","props","_props","unSubscribeNode","subscribeNode","visit","ctx","returnedValues","currentCtx","children","forEach","child","memoized","ret","draw","paint","push","memoizable"],"mappings":";;AAAA,SAASA,OAAT,QAAwB,YAAxB;AAMA,WAAYC,QAAZ;;WAAYA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,KAAAA,Q;;AAOZ,OAAO,MAAeC,IAAf,CAAiC;AAQtCC,EAAAA,WAAW,CAACC,MAAD,EAA4BC,KAA5B,EAAqD;AAAA,sCAPpC,EAOoC;;AAAA;;AAAA,wCALnD,KAKmD;;AAAA,sCAJrD,KAIqD;;AAAA;;AAAA;;AAC9D,SAAKC,MAAL,GAAcD,KAAd;AACA,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKA,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACD;;AAIQ,MAALA,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKD,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACA,SAAKC,MAAL,GAAcD,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKC,MAAZ;AACD;;AAEDG,EAAAA,KAAK,CAACC,GAAD,EAAsB;AACzB,UAAMC,cAAkD,GAAG,EAA3D;AACA,QAAIC,UAAU,GAAGF,GAAjB;AACA,SAAKG,QAAL,CAAcC,OAAd,CAAuBC,KAAD,IAAW;AAC/B,UAAI,CAACA,KAAK,CAACC,QAAX,EAAqB;AACnB,cAAMC,GAAG,GAAGF,KAAK,CAACG,IAAN,CAAWN,UAAX,CAAZ;;AACA,YAAIK,GAAJ,EAAS;AACP,cAAIjB,OAAO,CAACiB,GAAD,CAAX,EAAkB;AAChBL,YAAAA,UAAU,GAAG,EAAE,GAAGA,UAAL;AAAiBO,cAAAA,KAAK,EAAEF;AAAxB,aAAb;AACD;;AACDN,UAAAA,cAAc,CAACS,IAAf,CAAoBH,GAApB;AACD;;AACD,YAAIF,KAAK,CAACM,UAAV,EAAsB;AACpBN,UAAAA,KAAK,CAACC,QAAN,GAAiB,IAAjB;AACD;AACF;AACF,KAbD;AAcA,WAAOL,cAAP;AACD;;AA7CqC","sourcesContent":["import { isPaint } from \"../../skia\";\nimport type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { DependencyManager } from \"../DependencyManager\";\nimport type { DrawingContext } from \"../DrawingContext\";\nimport type { AnimatedProps } from \"../processors\";\n\nexport enum NodeType {\n Declaration = \"skDeclaration\",\n Drawing = \"skDrawing\",\n}\n\ntype DeclarationResult = SkJSIInstance<string> | null;\n\nexport abstract class Node<P = unknown> {\n readonly children: Node[] = [];\n _props: AnimatedProps<P>;\n memoizable = false;\n memoized = false;\n parent?: Node;\n depMgr: DependencyManager;\n\n constructor(depMgr: DependencyManager, props: AnimatedProps<P>) {\n this._props = props;\n this.depMgr = depMgr;\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n }\n\n abstract draw(ctx: DrawingContext): void | DeclarationResult;\n\n set props(props: AnimatedProps<P>) {\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n this._props = props;\n }\n\n get props() {\n return this._props;\n }\n\n visit(ctx: DrawingContext) {\n const returnedValues: Exclude<DeclarationResult, null>[] = [];\n let currentCtx = ctx;\n this.children.forEach((child) => {\n if (!child.memoized) {\n const ret = child.draw(currentCtx);\n if (ret) {\n if (isPaint(ret)) {\n currentCtx = { ...currentCtx, paint: ret };\n }\n returnedValues.push(ret);\n }\n if (child.memoizable) {\n child.memoized = true;\n }\n }\n });\n return returnedValues;\n }\n}\n"]}
1
+ {"version":3,"sources":["Node.ts"],"names":["NodeType","Node","constructor","depMgr","props","_props","unSubscribeNode","subscribeNode","visit","ctx","children","returnedValues","forEach","child","memoized","ret","draw","push","memoizable"],"mappings":";;AAKA,WAAYA,QAAZ;;WAAYA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,KAAAA,Q;;AAOZ,OAAO,MAAeC,IAAf,CAAiC;AAQtCC,EAAAA,WAAW,CAACC,MAAD,EAA4BC,KAA5B,EAAqD;AAAA,sCAPpC,EAOoC;;AAAA;;AAAA,wCALnD,KAKmD;;AAAA,sCAJ3B,IAI2B;;AAAA;;AAAA;;AAC9D,SAAKC,MAAL,GAAcD,KAAd;AACA,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKA,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACD;;AAIQ,MAALA,KAAK,CAACA,KAAD,EAA0B;AACjC,SAAKD,MAAL,CAAYG,eAAZ,CAA4B,IAA5B;AACA,SAAKH,MAAL,CAAYI,aAAZ,CAA0B,IAA1B,EAAgCH,KAAhC;AACA,SAAKC,MAAL,GAAcD,KAAd;AACD;;AAEQ,MAALA,KAAK,GAAG;AACV,WAAO,KAAKC,MAAZ;AACD;;AAEDG,EAAAA,KAAK,CAACC,GAAD,EAAsBC,QAAtB,EAAyC;AAC5C,UAAMC,cAAkD,GAAG,EAA3D;AACA,KAACD,QAAD,aAACA,QAAD,cAACA,QAAD,GAAa,KAAKA,QAAlB,EAA4BE,OAA5B,CAAqCC,KAAD,IAAW;AAC7C,UAAI,CAACA,KAAK,CAACC,QAAX,EAAqB;AACnB,cAAMC,GAAG,GAAGF,KAAK,CAACG,IAAN,CAAWP,GAAX,CAAZ;;AACA,YAAIM,GAAJ,EAAS;AACPJ,UAAAA,cAAc,CAACM,IAAf,CAAoBF,GAApB;;AACA,cAAIF,KAAK,CAACK,UAAV,EAAsB;AACpBL,YAAAA,KAAK,CAACC,QAAN,GAAiBC,GAAjB;AACD;AACF;AACF,OARD,MAQO;AACLJ,QAAAA,cAAc,CAACM,IAAf,CAAoBJ,KAAK,CAACC,QAA1B;AACD;AACF,KAZD;AAaA,WAAOH,cAAP;AACD;;AA3CqC","sourcesContent":["import type { SkJSIInstance } from \"../../skia/JsiInstance\";\nimport type { DependencyManager } from \"../DependencyManager\";\nimport type { DrawingContext } from \"../DrawingContext\";\nimport type { AnimatedProps } from \"../processors\";\n\nexport enum NodeType {\n Declaration = \"skDeclaration\",\n Drawing = \"skDrawing\",\n}\n\ntype DeclarationResult = SkJSIInstance<string> | null;\n\nexport abstract class Node<P = unknown> {\n readonly children: Node[] = [];\n _props: AnimatedProps<P>;\n memoizable = false;\n memoized: DeclarationResult | null = null;\n parent?: Node;\n depMgr: DependencyManager;\n\n constructor(depMgr: DependencyManager, props: AnimatedProps<P>) {\n this._props = props;\n this.depMgr = depMgr;\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n }\n\n abstract draw(ctx: DrawingContext): void | DeclarationResult;\n\n set props(props: AnimatedProps<P>) {\n this.depMgr.unSubscribeNode(this);\n this.depMgr.subscribeNode(this, props);\n this._props = props;\n }\n\n get props() {\n return this._props;\n }\n\n visit(ctx: DrawingContext, children?: Node[]) {\n const returnedValues: Exclude<DeclarationResult, null>[] = [];\n (children ?? this.children).forEach((child) => {\n if (!child.memoized) {\n const ret = child.draw(ctx);\n if (ret) {\n returnedValues.push(ret);\n if (child.memoizable) {\n child.memoized = ret;\n }\n }\n } else {\n returnedValues.push(child.memoized);\n }\n });\n return returnedValues;\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
- import { BlendMode, PaintStyle, StrokeJoin, StrokeCap, processColor } from "../../skia";
1
+ import { BlendMode, PaintStyle, StrokeJoin, StrokeCap, processColor, isShader, isMaskFilter, isColorFilter, isPathEffect, isImageFilter, Skia } from "../../skia";
2
2
  export const enumKey = k => k.charAt(0).toUpperCase() + k.slice(1);
3
- export const processPaint = (paint, currentOpacity, _ref) => {
3
+ export const processPaint = (paint, currentOpacity, _ref, children) => {
4
4
  let {
5
+ paint: paintRef,
5
6
  color,
6
7
  blendMode,
7
8
  style,
@@ -12,6 +13,10 @@ export const processPaint = (paint, currentOpacity, _ref) => {
12
13
  opacity
13
14
  } = _ref;
14
15
 
16
+ if (paintRef && paintRef.current) {
17
+ return paintRef.current;
18
+ }
19
+
15
20
  if (color !== undefined) {
16
21
  const c = processColor(color, currentOpacity);
17
22
  paint.setShader(null);
@@ -48,28 +53,24 @@ export const processPaint = (paint, currentOpacity, _ref) => {
48
53
  if (opacity !== undefined) {
49
54
  paint.setAlphaf(opacity);
50
55
  }
51
- };
52
- export const selectPaint = (currentPaint, _ref2) => {
53
- var _paint$current;
54
56
 
55
- let {
56
- paint,
57
- color: cl,
58
- blendMode,
59
- style: paintStyle,
60
- strokeWidth,
61
- strokeJoin,
62
- strokeCap,
63
- strokeMiter,
64
- opacity
65
- } = _ref2;
66
- const hasCustomPaint = cl !== undefined || blendMode !== undefined || paintStyle !== undefined || strokeWidth !== undefined || strokeJoin !== undefined || opacity !== undefined || strokeCap !== undefined || strokeMiter !== undefined;
67
- const parentPaint = (_paint$current = paint === null || paint === void 0 ? void 0 : paint.current) !== null && _paint$current !== void 0 ? _paint$current : currentPaint;
57
+ children.forEach(child => {
58
+ if (isShader(child)) {
59
+ paint.setShader(child);
60
+ } else if (isMaskFilter(child)) {
61
+ paint.setMaskFilter(child);
62
+ } else if (isColorFilter(child)) {
63
+ paint.setColorFilter(child);
64
+ } else if (isPathEffect(child)) {
65
+ paint.setPathEffect(child);
66
+ }
67
+ });
68
+ const filters = children.filter(isImageFilter);
68
69
 
69
- if (hasCustomPaint) {
70
- return parentPaint.copy();
70
+ if (filters.length > 0) {
71
+ paint.setImageFilter(filters.reverse().reduce(Skia.ImageFilter.MakeCompose, null));
71
72
  }
72
73
 
73
- return parentPaint;
74
+ return paint;
74
75
  };
75
76
  //# sourceMappingURL=Paint.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Paint.ts"],"names":["BlendMode","PaintStyle","StrokeJoin","StrokeCap","processColor","enumKey","k","charAt","toUpperCase","slice","processPaint","paint","currentOpacity","color","blendMode","style","strokeWidth","strokeJoin","strokeCap","strokeMiter","opacity","undefined","c","setShader","setColor","getColor","setBlendMode","setStyle","setStrokeJoin","setStrokeCap","setStrokeMiter","setStrokeWidth","setAlphaf","selectPaint","currentPaint","cl","paintStyle","hasCustomPaint","parentPaint","current","copy"],"mappings":"AAEA,SACEA,SADF,EAEEC,UAFF,EAGEC,UAHF,EAIEC,SAJF,EAKEC,YALF,QAMO,YANP;AA0BA,OAAO,MAAMC,OAAO,GAAsBC,CAAnB,IACpBA,CAAC,CAACC,MAAF,CAAS,CAAT,EAAYC,WAAZ,KAA4BF,CAAC,CAACG,KAAF,CAAQ,CAAR,CADxB;AAGP,OAAO,MAAMC,YAAY,GAAG,CAC1BC,KAD0B,EAE1BC,cAF0B,WAavB;AAAA,MAVH;AACEC,IAAAA,KADF;AAEEC,IAAAA,SAFF;AAGEC,IAAAA,KAHF;AAIEC,IAAAA,WAJF;AAKEC,IAAAA,UALF;AAMEC,IAAAA,SANF;AAOEC,IAAAA,WAPF;AAQEC,IAAAA;AARF,GAUG;;AACH,MAAIP,KAAK,KAAKQ,SAAd,EAAyB;AACvB,UAAMC,CAAC,GAAGlB,YAAY,CAACS,KAAD,EA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AIEC,IAAAA,KAAK,EAAEqB,UAJT;AAKEpB,IAAAA,WALF;AAMEC,IAAAA,UANF;AAOEC,IAAAA,SAPF;AAQEC,IAAAA,WARF;AASEC,IAAAA;AATF,GAWG;AACH,QAAMiB,cAAc,GAClBF,EAAE,KAAKd,SAAP,IACAP,SAAS,KAAKO,SADd,IAEAe,UAAU,KAAKf,SAFf,IAGAL,WAAW,KAAKK,SAHhB,IAIAJ,UAAU,KAAKI,SAJf,IAKAD,OAAO,KAAKC,SALZ,IAMAH,SAAS,KAAKG,SANd,IAOAF,WAAW,KAAKE,SARlB;AASA,QAAMiB,WAAW,qBAAG3B,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAE4B,OAAV,2DAAqBL,YAAtC;;AACA,MAAIG,cAAJ,EAAoB;AAClB,WAAOC,WAAW,CAACE,IAAZ,EAAP;AACD;;AACD,SAAOF,WAAP;AACD,CA5BM","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\n\nimport {\n BlendMode,\n PaintStyle,\n StrokeJoin,\n StrokeCap,\n processColor,\n} from \"../../skia\";\nimport type { SkPaint, Color } from \"../../skia\";\nexport type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;\n\nexport interface ChildrenProps {\n children?: ReactNode | ReactNode[];\n}\n\nexport interface CustomPaintProps extends ChildrenProps {\n paint?: RefObject<SkPaint>;\n color?: Color;\n strokeWidth?: number;\n blendMode?: SkEnum<typeof BlendMode>;\n style?: SkEnum<typeof PaintStyle>;\n strokeJoin?: SkEnum<typeof StrokeJoin>;\n strokeCap?: SkEnum<typeof StrokeCap>;\n strokeMiter?: number;\n opacity?: number;\n}\n\nexport const enumKey = <K extends string>(k: K) =>\n (k.charAt(0).toUpperCase() + k.slice(1)) as Capitalize<K>;\n\nexport const processPaint = (\n paint: SkPaint,\n currentOpacity: number,\n {\n color,\n blendMode,\n style,\n strokeWidth,\n strokeJoin,\n strokeCap,\n strokeMiter,\n opacity,\n }: CustomPaintProps\n) => {\n if (color !== undefined) {\n const c = processColor(color, currentOpacity);\n paint.setShader(null);\n paint.setColor(c);\n } else {\n const c = processColor(paint.getColor(), currentOpacity);\n paint.setColor(c);\n }\n if (blendMode !== undefined) {\n paint.setBlendMode(BlendMode[enumKey(blendMode)]);\n }\n if (style !== undefined) {\n paint.setStyle(PaintStyle[enumKey(style)]);\n }\n if (strokeJoin !== undefined) {\n paint.setStrokeJoin(StrokeJoin[enumKey(strokeJoin)]);\n }\n if (strokeCap !== undefined) {\n paint.setStrokeCap(StrokeCap[enumKey(strokeCap)]);\n }\n if (strokeMiter !== undefined) {\n paint.setStrokeMiter(strokeMiter);\n }\n if (strokeWidth !== undefined) {\n paint.setStrokeWidth(strokeWidth);\n }\n if (opacity !== undefined) {\n paint.setAlphaf(opacity);\n }\n};\n\nexport const selectPaint = (\n currentPaint: SkPaint,\n {\n paint,\n color: cl,\n blendMode,\n style: paintStyle,\n strokeWidth,\n strokeJoin,\n strokeCap,\n strokeMiter,\n opacity,\n }: CustomPaintProps\n) => {\n const hasCustomPaint =\n cl !== undefined ||\n blendMode !== undefined ||\n paintStyle !== undefined ||\n strokeWidth !== undefined ||\n strokeJoin !== undefined ||\n opacity !== undefined ||\n strokeCap !== undefined ||\n strokeMiter !== undefined;\n const parentPaint = paint?.current ?? currentPaint;\n if (hasCustomPaint) {\n return parentPaint.copy();\n }\n return parentPaint;\n};\n"]}
1
+ {"version":3,"sources":["Paint.ts"],"names":["BlendMode","PaintStyle","StrokeJoin","StrokeCap","processColor","isShader","isMaskFilter","isColorFilter","isPathEffect","isImageFilter","Skia","enumKey","k","charAt","toUpperCase","slice","processPaint","paint","currentOpacity","children","paintRef","color","blendMode","style","strokeWidth","strokeJoin","strokeCap","strokeMiter","opacity","current","undefined","c","setShader","setColor","getColor","setBlendMode","setStyle","setStrokeJoin","setStrokeCap","setStrokeMiter","setStrokeWidth","setAlphaf","forEach","child","setMaskFilter","setColorFilter","setPathEffect","filters","filter","length","setImageFilter","reverse","reduce","ImageFilter","M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,CAACE,MAAR,GAAiB,CAArB,EAAwB;AACtBhC,IAAAA,KAAK,CAACiC,cAAN,CACEH,OAAO,CACJI,OADH,GAEGC,MAFH,CAEgC1C,IAAI,CAAC2C,WAAL,CAAiBC,WAFjD,EAE8D,IAF9D,CADF;AAKD;;AACD,SAAOrC,KAAP;AACD,CApEM","sourcesContent":["import type { ReactNode, RefObject } from \"react\";\n\nimport {\n BlendMode,\n PaintStyle,\n StrokeJoin,\n StrokeCap,\n processColor,\n isShader,\n isMaskFilter,\n isColorFilter,\n isPathEffect,\n isImageFilter,\n Skia,\n} from \"../../skia\";\nimport type { SkPaint, Color, SkImageFilter } from \"../../skia\";\nimport type { DeclarationResult } from \"../nodes\";\nexport type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;\n\nexport interface ChildrenProps {\n children?: ReactNode | ReactNode[];\n}\n\n// TODO: rename to paint props?\nexport interface CustomPaintProps extends ChildrenProps {\n paint?: RefObject<SkPaint>;\n color?: Color;\n strokeWidth?: number;\n blendMode?: SkEnum<typeof BlendMode>;\n style?: SkEnum<typeof PaintStyle>;\n strokeJoin?: SkEnum<typeof StrokeJoin>;\n strokeCap?: SkEnum<typeof StrokeCap>;\n strokeMiter?: number;\n opacity?: number;\n}\n\nexport const enumKey = <K extends string>(k: K) =>\n (k.charAt(0).toUpperCase() + k.slice(1)) as Capitalize<K>;\n\nexport const processPaint = (\n paint: SkPaint,\n currentOpacity: number,\n {\n paint: paintRef,\n color,\n blendMode,\n style,\n strokeWidth,\n strokeJoin,\n strokeCap,\n strokeMiter,\n opacity,\n }: CustomPaintProps,\n children: DeclarationResult[]\n) => {\n if (paintRef && paintRef.current) {\n return paintRef.current;\n }\n if (color !== undefined) {\n const c = processColor(color, currentOpacity);\n paint.setShader(null);\n paint.setColor(c);\n } else {\n const c = processColor(paint.getColor(), currentOpacity);\n paint.setColor(c);\n }\n if (blendMode !== undefined) {\n paint.setBlendMode(BlendMode[enumKey(blendMode)]);\n }\n if (style !== undefined) {\n paint.setStyle(PaintStyle[enumKey(style)]);\n }\n if (strokeJoin !== undefined) {\n paint.setStrokeJoin(StrokeJoin[enumKey(strokeJoin)]);\n }\n if (strokeCap !== undefined) {\n paint.setStrokeCap(StrokeCap[enumKey(strokeCap)]);\n }\n if (strokeMiter !== undefined) {\n paint.setStrokeMiter(strokeMiter);\n }\n if (strokeWidth !== undefined) {\n paint.setStrokeWidth(strokeWidth);\n }\n if (opacity !== undefined) {\n paint.setAlphaf(opacity);\n }\n children.forEach((child) => {\n if (isShader(child)) {\n paint.setShader(child);\n } else if (isMaskFilter(child)) {\n paint.setMaskFilter(child);\n } else if (isColorFilter(child)) {\n paint.setColorFilter(child);\n } else if (isPathEffect(child)) {\n paint.setPathEffect(child);\n }\n });\n const filters = children.filter(isImageFilter);\n if (filters.length > 0) {\n paint.setImageFilter(\n filters\n .reverse()\n .reduce<SkImageFilter | null>(Skia.ImageFilter.MakeCompose, null)\n );\n }\n return paint;\n};\n"]}
@@ -1,2 +1,17 @@
1
+ /**
2
+ * Linear interpolation
3
+ * @param value
4
+ * @param x
5
+ * @param y
6
+ */
1
7
  export const mix = (value, x, y) => x * (1 - value) + y * value;
8
+ /**
9
+ * @summary Clamps a node with a lower and upper bound.
10
+ * @example
11
+ clamp(-1, 0, 100); // 0
12
+ clamp(1, 0, 100); // 1
13
+ clamp(101, 0, 100); // 100
14
+ */
15
+
16
+ export const clamp = (value, lowerBound, upperBound) => Math.min(Math.max(lowerBound, value), upperBound);
2
17
  //# sourceMappingURL=Math.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Math.ts"],"names":["mix","value","x","y"],"mappings":"AAAA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KACjBD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KADjB","sourcesContent":["export const mix = (value: number, x: number, y: number) =>\n x * (1 - value) + y * value;\n"]}
1
+ {"version":3,"sources":["Math.ts"],"names":["mix","value","x","y","clamp","lowerBound","upperBound","Math","min","max"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,GAAG,GAAG,CAACC,KAAD,EAAgBC,CAAhB,EAA2BC,CAA3B,KACjBD,CAAC,IAAI,IAAID,KAAR,CAAD,GAAkBE,CAAC,GAAGF,KADjB;AAGP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,KAAK,GAAG,CAACH,KAAD,EAAgBI,UAAhB,EAAoCC,UAApC,KACnBC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACE,GAAL,CAASJ,UAAT,EAAqBJ,KAArB,CAAT,EAAsCK,UAAtC,CADK","sourcesContent":["/**\n * Linear interpolation\n * @param value\n * @param x\n * @param y\n */\nexport const mix = (value: number, x: number, y: number) =>\n x * (1 - value) + y * value;\n\n/**\n * @summary Clamps a node with a lower and upper bound.\n * @example\n clamp(-1, 0, 100); // 0\n clamp(1, 0, 100); // 1\n clamp(101, 0, 100); // 100\n */\nexport const clamp = (value: number, lowerBound: number, upperBound: number) =>\n Math.min(Math.max(lowerBound, value), upperBound);\n"]}
@@ -26,11 +26,15 @@ const multiply3 = (m1, m2) => {
26
26
  return [[dot3(m1[0], col0), dot3(m1[0], col1), dot3(m1[0], col2)], [dot3(m1[1], col0), dot3(m1[1], col1), dot3(m1[1], col2)], [dot3(m1[2], col0), dot3(m1[2], col1), dot3(m1[2], col2)]];
27
27
  };
28
28
 
29
+ export const matrixVecMul3 = (m, v) => [dot3(m[0], v), dot3(m[1], v), dot3(m[2], v)];
30
+
29
31
  const skiaMatrix3 = m => {
30
32
  return [m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]];
31
33
  };
32
34
 
33
- export const processTransform2d = transforms => skiaMatrix3(transforms.reduce((acc, transform) => {
35
+ export const processTransform2d = transforms => skiaMatrix3(processTransform(transforms));
36
+
37
+ const processTransform = transforms => transforms.reduce((acc, transform) => {
34
38
  const key = Object.keys(transform)[0];
35
39
  const value = transform[key];
36
40
 
@@ -67,5 +71,5 @@ export const processTransform2d = transforms => skiaMatrix3(transforms.reduce((a
67
71
  }
68
72
 
69
73
  return exhaustiveCheck(key);
70
- }, identityMatrix));
74
+ }, identityMatrix);
71
75
  //# sourceMappingURL=Matrix3.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Matrix3.ts"],"names":["exhaustiveCheck","identityMatrix","translateXMatrix","x","translateYMatrix","y","scaleMatrix","s","scaleXMatrix","scaleYMatrix","skewXMatrix","Math","tan","skewYMatrix","rotateZMatrix","r","cos","sin","dot3","row","col","multiply3","m1","m2","col0","col1","col2","skiaMatrix3","m","processTransform2d","transforms","reduce","acc","transform","key","Object","keys","value"],"mappings":"AAAA,SAASA,eAAT,QAAgC,iBAAhC;AAoCA,MAAMC,cAAuB,GAAG,CAC9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD8B,EAE9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAF8B,EAG9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH8B,CAAhC;;AAMA,MAAMC,gBAAgB,GAAIC,CAAD,IAAwB,CAC/C,CAAC,CAAD,EAAI,CAAJ,EAAOA,CAAP,CAD+C,EAE/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAF+C,EAG/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH+C,CAAjD;;AAMA,MAAMC,gBAAgB,GAAIC,CAAD,IAAwB,CAC/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD+C,EAE/C,CAAC,CAAD,EAAI,CAAJ,EAAOA,CAAP,CAF+C,EAG/C,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAH+C,CAAjD;;AAMA,MAAMC,WAAW,GAAIC,CAAD,IAAwB,CAC1C,CAACA,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD0C,EAE1C,CAAC,CAAD,EAA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Z,EAA0B;AACxB,WAAOb,SAAS,CAACW,GAAD,EAAM5B,gBAAgB,CAACiC,KAAD,CAAtB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnB,WAAOb,SAAS,CAACW,GAAD,EAAM1B,WAAW,CAAC+B,KAAD,CAAjB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,QAAZ,EAAsB;AACpB,WAAOb,SAAS,CAACW,GAAD,EAAMxB,YAAY,CAAC6B,KAAD,CAAlB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,QAAZ,EAAsB;AACpB,WAAOb,SAAS,CAACW,GAAD,EAAMvB,YAAY,CAAC4B,KAAD,CAAlB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnB,WAAOb,SAAS,CAACW,GAAD,EAAMtB,WAAW,CAAC2B,KAAD,CAAjB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnB,WAAOb,SAAS,CAACW,GAAD,EAAMnB,WAAW,CAACwB,KAAD,CAAjB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,SAAhC,EAA2C;AACzC,WAAOb,SAAS,CAACW,GAAD,EAAMlB,aAAa,CAACuB,KAAD,CAAnB,CAAhB;AACD;;AACD,SAAOrC,eAAe,CAACkC,GAAD,CAAtB;AACD,CA5BD,EA4BGjC,cA5BH,CADS,CADN","sourcesContent":["import { exhaustiveCheck } from \"../../typeddash\";\nimport type { SkMatrix } from \"../../../skia/Matrix\";\n\nexport type Vec3 = readonly [number, number, number];\n\nexport type Matrix3 = readonly [Vec3, Vec3, Vec3];\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\nexport type Transforms2d = readonly (\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"rotate\">\n)[];\n\nconst identityMatrix: Matrix3 = [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateXMatrix = (x: number): Matrix3 => [\n [1, 0, x],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateYMatrix = (y: number): Matrix3 => [\n [1, 0, 0],\n [0, 1, y],\n [0, 0, 1],\n];\n\nconst scaleMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst scaleXMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst scaleYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst skewXMatrix = (s: number): Matrix3 => [\n [1, Math.tan(s), 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst skewYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [Math.tan(s), 1, 0],\n [0, 0, 1],\n];\n\nconst rotateZMatrix = (r: number): Matrix3 => [\n [Math.cos(r), -1 * Math.sin(r), 0],\n [Math.sin(r), Math.cos(r), 0],\n [0, 0, 1],\n];\n\nconst dot3 = (row: Vec3, col: Vec3) =>\n row[0] * col[0] + row[1] * col[1] + row[2] * col[2];\n\nconst multiply3 = (m1: Matrix3, m2: Matrix3) => {\n const col0 = [m2[0][0], m2[1][0], m2[2][0]] as const;\n const col1 = [m2[0][1], m2[1][1], m2[2][1]] as const;\n const col2 = [m2[0][2], m2[1][2], m2[2][2]] as const;\n return [\n [dot3(m1[0], col0), dot3(m1[0], col1), dot3(m1[0], col2)],\n [dot3(m1[1], col0), dot3(m1[1], col1), dot3(m1[1], col2)],\n [dot3(m1[2], col0), dot3(m1[2], col1), dot3(m1[2], col2)],\n ] as const;\n};\n\nconst skiaMatrix3 = (m: Matrix3): SkMatrix => {\n return [\n m[0][0],\n m[0][1],\n m[0][2],\n m[1][0],\n m[1][1],\n m[1][2],\n m[2][0],\n m[2][1],\n m[2][2],\n ];\n};\n\nexport const processTransform2d = (transforms: Transforms2d) =>\n skiaMatrix3(\n transforms.reduce((acc, transform) => {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n return multiply3(acc, translateXMatrix(value));\n }\n if (key === \"translateY\") {\n return multiply3(acc, translateYMatrix(value));\n }\n if (key === \"scale\") {\n return multiply3(acc, scaleMatrix(value));\n }\n if (key === \"scaleX\") {\n return multiply3(acc, scaleXMatrix(value));\n }\n if (key === \"scaleY\") {\n return multiply3(acc, scaleYMatrix(value));\n }\n if (key === \"skewX\") {\n return multiply3(acc, skewXMatrix(value));\n }\n if (key === \"skewY\") {\n return multiply3(acc, skewYMatrix(value));\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n return multiply3(acc, rotateZMatrix(value));\n }\n return exhaustiveCheck(key);\n }, identityMatrix)\n );\n"]}
1
+ {"version":3,"sources":["Matrix3.ts"],"names":["exhaustiveCheck","identityMatrix","translateXMatrix","x","translateYMatrix","y","scaleMatrix","s","scaleXMatrix","scaleYMatrix","skewXMatrix","Math","tan","skewYMatrix","rotateZMatrix","r","cos","sin","dot3","row","col","multiply3","m1","m2","col0","col1","col2","matrixVecMul3","m","v","skiaMatrix3","processTransform2d","transforms","processTransform","reduce","acc","transform","key","Object","keys","value"],"mappings":"AAAA,SAASA,eAAT,QAAgC,iBAAhC;AAoCA,MAAMC,cAAuB,GAAG,CAC9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAD8B,EAE9B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAA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CAACgC,KAAD,CAAlB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,QAAZ,EAAsB;AACpB,WAAOhB,SAAS,CAACc,GAAD,EAAM1B,YAAY,CAAC+B,KAAD,CAAlB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnB,WAAOhB,SAAS,CAACc,GAAD,EAAMzB,WAAW,CAAC8B,KAAD,CAAjB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,OAAZ,EAAqB;AACnB,WAAOhB,SAAS,CAACc,GAAD,EAAMtB,WAAW,CAAC2B,KAAD,CAAjB,CAAhB;AACD;;AACD,MAAIH,GAAG,KAAK,QAAR,IAAoBA,GAAG,KAAK,SAAhC,EAA2C;AACzC,WAAOhB,SAAS,CAACc,GAAD,EAAMrB,aAAa,CAAC0B,KAAD,CAAnB,CAAhB;AACD;;AACD,SAAOxC,eAAe,CAACqC,GAAD,CAAtB;AACD,CA5BD,EA4BGpC,cA5BH,CADF","sourcesContent":["import { exhaustiveCheck } from \"../../typeddash\";\nimport type { SkMatrix } from \"../../../skia/Matrix\";\n\nexport type Vec3 = readonly [number, number, number];\n\nexport type Matrix3 = readonly [Vec3, Vec3, Vec3];\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\nexport type Transforms2d = readonly (\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"rotate\">\n)[];\n\nconst identityMatrix: Matrix3 = [\n [1, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateXMatrix = (x: number): Matrix3 => [\n [1, 0, x],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst translateYMatrix = (y: number): Matrix3 => [\n [1, 0, 0],\n [0, 1, y],\n [0, 0, 1],\n];\n\nconst scaleMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst scaleXMatrix = (s: number): Matrix3 => [\n [s, 0, 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst scaleYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [0, s, 0],\n [0, 0, 1],\n];\n\nconst skewXMatrix = (s: number): Matrix3 => [\n [1, Math.tan(s), 0],\n [0, 1, 0],\n [0, 0, 1],\n];\n\nconst skewYMatrix = (s: number): Matrix3 => [\n [1, 0, 0],\n [Math.tan(s), 1, 0],\n [0, 0, 1],\n];\n\nconst rotateZMatrix = (r: number): Matrix3 => [\n [Math.cos(r), -1 * Math.sin(r), 0],\n [Math.sin(r), Math.cos(r), 0],\n [0, 0, 1],\n];\n\nconst dot3 = (row: Vec3, col: Vec3) =>\n row[0] * col[0] + row[1] * col[1] + row[2] * col[2];\n\nconst multiply3 = (m1: Matrix3, m2: Matrix3) => {\n const col0 = [m2[0][0], m2[1][0], m2[2][0]] as const;\n const col1 = [m2[0][1], m2[1][1], m2[2][1]] as const;\n const col2 = [m2[0][2], m2[1][2], m2[2][2]] as const;\n return [\n [dot3(m1[0], col0), dot3(m1[0], col1), dot3(m1[0], col2)],\n [dot3(m1[1], col0), dot3(m1[1], col1), dot3(m1[1], col2)],\n [dot3(m1[2], col0), dot3(m1[2], col1), dot3(m1[2], col2)],\n ] as const;\n};\n\nexport const matrixVecMul3 = (m: Matrix3, v: Vec3) =>\n [dot3(m[0], v), dot3(m[1], v), dot3(m[2], v)] as const;\n\nconst skiaMatrix3 = (m: Matrix3): SkMatrix => {\n return [\n m[0][0],\n m[0][1],\n m[0][2],\n m[1][0],\n m[1][1],\n m[1][2],\n m[2][0],\n m[2][1],\n m[2][2],\n ];\n};\n\nexport const processTransform2d = (transforms: Transforms2d) =>\n skiaMatrix3(processTransform(transforms));\n\nconst processTransform = (transforms: Transforms2d) =>\n transforms.reduce((acc, transform) => {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n return multiply3(acc, translateXMatrix(value));\n }\n if (key === \"translateY\") {\n return multiply3(acc, translateYMatrix(value));\n }\n if (key === \"scale\") {\n return multiply3(acc, scaleMatrix(value));\n }\n if (key === \"scaleX\") {\n return multiply3(acc, scaleXMatrix(value));\n }\n if (key === \"scaleY\") {\n return multiply3(acc, scaleYMatrix(value));\n }\n if (key === \"skewX\") {\n return multiply3(acc, skewXMatrix(value));\n }\n if (key === \"skewY\") {\n return multiply3(acc, skewYMatrix(value));\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n return multiply3(acc, rotateZMatrix(value));\n }\n return exhaustiveCheck(key);\n }, identityMatrix);\n"]}
@@ -1,5 +1,26 @@
1
1
  export const mapKeys = obj => Object.keys(obj);
2
2
  export const exhaustiveCheck = a => {
3
3
  throw new Error(`Unexhaustive handling for ${a}`);
4
+ }; // Shallow eq on props (without children)
5
+
6
+ export const shallowEq = (p1, p2) => {
7
+ const keys1 = mapKeys(p1);
8
+ const keys2 = mapKeys(p2);
9
+
10
+ if (keys1.length !== keys2.length) {
11
+ return false;
12
+ }
13
+
14
+ for (const key of keys1) {
15
+ if (key === "children") {
16
+ continue;
17
+ }
18
+
19
+ if (p1[key] !== p2[key]) {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ return true;
4
25
  };
5
26
  //# sourceMappingURL=typeddash.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["typeddash.ts"],"names":["mapKeys","obj","Object","keys","exhaustiveCheck","a","Error"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAOC,GAAJ,IAAeC,MAAM,CAACC,IAAP,CAAYF,GAAZ,CAA/B;AAEP,OAAO,MAAMG,eAAe,GAAIC,CAAD,IAAqB;AAClD,QAAM,IAAIC,KAAJ,CAAW,6BAA4BD,CAAE,EAAzC,CAAN;AACD,CAFM","sourcesContent":["export const mapKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];\n\nexport const exhaustiveCheck = (a: never): never => {\n throw new Error(`Unexhaustive handling for ${a}`);\n};\n"]}
1
+ {"version":3,"sources":["typeddash.ts"],"names":["mapKeys","obj","Object","keys","exhaustiveCheck","a","Error","shallowEq","p1","p2","keys1","keys2","length","key"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAOC,GAAJ,IAAeC,MAAM,CAACC,IAAP,CAAYF,GAAZ,CAA/B;AAEP,OAAO,MAAMG,eAAe,GAAIC,CAAD,IAAqB;AAClD,QAAM,IAAIC,KAAJ,CAAW,6BAA4BD,CAAE,EAAzC,CAAN;AACD,CAFM,C,CAIP;;AACA,OAAO,MAAME,SAAS,GAAG,CAAIC,EAAJ,EAAWC,EAAX,KAA8B;AACrD,QAAMC,KAAK,GAAGV,OAAO,CAACQ,EAAD,CAArB;AACA,QAAMG,KAAK,GAAGX,OAAO,CAACS,EAAD,CAArB;;AACA,MAAIC,KAAK,CAACE,MAAN,KAAiBD,KAAK,CAACC,MAA3B,EAAmC;AACjC,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,GAAX,IAAkBH,KAAlB,EAAyB;AACvB,QAAIG,GAAG,KAAK,UAAZ,EAAwB;AACtB;AACD;;AACD,QAAIL,EAAE,CAACK,GAAD,CAAF,KAAYJ,EAAE,CAACI,GAAD,CAAlB,EAAyB;AACvB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAfM","sourcesContent":["export const mapKeys = <T>(obj: T) => Object.keys(obj) as (keyof T)[];\n\nexport const exhaustiveCheck = (a: never): never => {\n throw new Error(`Unexhaustive handling for ${a}`);\n};\n\n// Shallow eq on props (without children)\nexport const shallowEq = <P>(p1: P, p2: P): boolean => {\n const keys1 = mapKeys(p1);\n const keys2 = mapKeys(p2);\n if (keys1.length !== keys2.length) {\n return false;\n }\n for (const key of keys1) {\n if (key === \"children\") {\n continue;\n }\n if (p1[key] !== p2[key]) {\n return false;\n }\n }\n return true;\n};\n"]}