@shopify/react-native-skia 0.1.137 → 0.1.140

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. package/android/CMakeLists.txt +5 -1
  2. package/android/build.gradle +4 -3
  3. package/cpp/api/JsiSkApi.h +0 -4
  4. package/cpp/api/JsiSkFont.h +0 -19
  5. package/cpp/api/JsiSkTypeface.h +1 -29
  6. package/lib/commonjs/mock/index.js +0 -4
  7. package/lib/commonjs/mock/index.js.map +1 -1
  8. package/lib/commonjs/renderer/Canvas.js +5 -8
  9. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  10. package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
  11. package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
  12. package/lib/commonjs/renderer/components/text/Text.js +4 -6
  13. package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
  14. package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
  15. package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
  16. package/lib/commonjs/renderer/processors/Font.js +1 -27
  17. package/lib/commonjs/renderer/processors/Font.js.map +1 -1
  18. package/lib/commonjs/skia/core/Data.js +3 -1
  19. package/lib/commonjs/skia/core/Data.js.map +1 -1
  20. package/lib/commonjs/skia/core/Image.js +4 -1
  21. package/lib/commonjs/skia/core/Image.js.map +1 -1
  22. package/lib/commonjs/skia/core/SVG.js +3 -1
  23. package/lib/commonjs/skia/core/SVG.js.map +1 -1
  24. package/lib/commonjs/skia/core/Typeface.js +4 -1
  25. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  26. package/lib/commonjs/skia/core/index.js +0 -26
  27. package/lib/commonjs/skia/core/index.js.map +1 -1
  28. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  29. package/lib/commonjs/skia/types/Image/ImageFactory.js +0 -2
  30. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  31. package/lib/commonjs/skia/types/Matrix.js +1 -1
  32. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  33. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  34. package/lib/commonjs/skia/types/index.js +0 -13
  35. package/lib/commonjs/skia/types/index.js.map +1 -1
  36. package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
  37. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  38. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
  39. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  40. package/lib/commonjs/skia/web/JsiSkia.js +0 -3
  41. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  42. package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
  43. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  44. package/lib/commonjs/views/SkiaView.web.js +62 -52
  45. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  46. package/lib/commonjs/views/useTouchHandler.js +8 -3
  47. package/lib/commonjs/views/useTouchHandler.js.map +1 -1
  48. package/lib/commonjs/web/LoadSkiaWeb.js +6 -2
  49. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -1
  50. package/lib/commonjs/web/WithSkiaWeb.js +5 -4
  51. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
  52. package/lib/module/mock/index.js +0 -4
  53. package/lib/module/mock/index.js.map +1 -1
  54. package/lib/module/renderer/Canvas.js +5 -6
  55. package/lib/module/renderer/Canvas.js.map +1 -1
  56. package/lib/module/renderer/components/text/Glyphs.js +4 -5
  57. package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
  58. package/lib/module/renderer/components/text/Text.js +4 -5
  59. package/lib/module/renderer/components/text/Text.js.map +1 -1
  60. package/lib/module/renderer/components/text/TextPath.js +3 -3
  61. package/lib/module/renderer/components/text/TextPath.js.map +1 -1
  62. package/lib/module/renderer/processors/Font.js +0 -23
  63. package/lib/module/renderer/processors/Font.js.map +1 -1
  64. package/lib/module/skia/core/Data.js +3 -1
  65. package/lib/module/skia/core/Data.js.map +1 -1
  66. package/lib/module/skia/core/Image.js +2 -1
  67. package/lib/module/skia/core/Image.js.map +1 -1
  68. package/lib/module/skia/core/SVG.js +2 -1
  69. package/lib/module/skia/core/SVG.js.map +1 -1
  70. package/lib/module/skia/core/Typeface.js +2 -1
  71. package/lib/module/skia/core/Typeface.js.map +1 -1
  72. package/lib/module/skia/core/index.js +0 -2
  73. package/lib/module/skia/core/index.js.map +1 -1
  74. package/lib/module/skia/types/Font/Font.js.map +1 -1
  75. package/lib/module/skia/types/Image/ImageFactory.js +0 -1
  76. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  77. package/lib/module/skia/types/Matrix.js +1 -1
  78. package/lib/module/skia/types/Matrix.js.map +1 -1
  79. package/lib/module/skia/types/Path/Path.js.map +1 -1
  80. package/lib/module/skia/types/index.js +0 -1
  81. package/lib/module/skia/types/index.js.map +1 -1
  82. package/lib/module/skia/web/JsiSkFont.js +0 -6
  83. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  84. package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
  85. package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkia.js +0 -2
  87. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  88. package/lib/module/values/hooks/useComputedValue.js +0 -4
  89. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  90. package/lib/module/views/SkiaView.web.js +62 -53
  91. package/lib/module/views/SkiaView.web.js.map +1 -1
  92. package/lib/module/views/useTouchHandler.js +8 -3
  93. package/lib/module/views/useTouchHandler.js.map +1 -1
  94. package/lib/module/web/LoadSkiaWeb.js +6 -2
  95. package/lib/module/web/LoadSkiaWeb.js.map +1 -1
  96. package/lib/module/web/WithSkiaWeb.js +5 -4
  97. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  98. package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
  99. package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
  100. package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
  101. package/lib/typescript/src/skia/core/index.d.ts +0 -2
  102. package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
  103. package/lib/typescript/src/skia/types/Matrix.d.ts +1 -1
  104. package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
  105. package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +1 -4
  106. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  107. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
  108. package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
  109. package/lib/typescript/src/views/SkiaView.web.d.ts +7 -9
  110. package/lib/typescript/src/web/LoadSkiaWeb.d.ts +3 -3
  111. package/lib/typescript/src/web/WithSkiaWeb.d.ts +4 -2
  112. package/package.json +9 -4
  113. package/src/mock/index.ts +0 -4
  114. package/src/renderer/Canvas.tsx +5 -8
  115. package/src/renderer/DrawingContext.ts +1 -2
  116. package/src/renderer/components/text/Glyphs.tsx +2 -6
  117. package/src/renderer/components/text/Text.tsx +2 -3
  118. package/src/renderer/components/text/TextPath.tsx +2 -3
  119. package/src/renderer/processors/Font.ts +2 -25
  120. package/src/skia/core/Data.ts +3 -1
  121. package/src/skia/core/Image.ts +3 -1
  122. package/src/skia/core/SVG.ts +3 -1
  123. package/src/skia/core/Typeface.ts +4 -6
  124. package/src/skia/core/index.ts +0 -2
  125. package/src/skia/types/Font/Font.ts +0 -13
  126. package/src/skia/types/Image/ImageFactory.ts +0 -1
  127. package/src/skia/types/Matrix.ts +1 -1
  128. package/src/skia/types/Path/Path.ts +0 -1
  129. package/src/skia/types/Skia.ts +0 -2
  130. package/src/skia/types/Typeface/Typeface.ts +1 -4
  131. package/src/skia/types/index.ts +0 -1
  132. package/src/skia/web/JsiSkFont.ts +0 -9
  133. package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
  134. package/src/skia/web/JsiSkia.ts +0 -2
  135. package/src/values/hooks/useComputedValue.ts +0 -5
  136. package/src/views/SkiaView.web.tsx +50 -65
  137. package/src/views/useTouchHandler.ts +4 -2
  138. package/src/web/LoadSkiaWeb.tsx +9 -3
  139. package/src/web/WithSkiaWeb.tsx +10 -5
  140. package/android/README.md +0 -14
  141. package/cpp/api/JsiSkFontMgr.h +0 -84
  142. package/cpp/api/JsiSkFontMgrFactory.h +0 -48
  143. package/cpp/skia/include/third_party/skcms/LICENSE +0 -29
  144. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  145. package/cpp/skia/readme.txt +0 -1
  146. package/lib/commonjs/skia/core/Paint.js +0 -28
  147. package/lib/commonjs/skia/core/Paint.js.map +0 -1
  148. package/lib/commonjs/skia/core/Path.js +0 -72
  149. package/lib/commonjs/skia/core/Path.js.map +0 -1
  150. package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
  151. package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
  152. package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
  153. package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
  154. package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
  155. package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
  156. package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
  157. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
  158. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
  159. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
  160. package/lib/module/skia/core/Paint.js +0 -17
  161. package/lib/module/skia/core/Paint.js.map +0 -1
  162. package/lib/module/skia/core/Path.js +0 -53
  163. package/lib/module/skia/core/Path.js.map +0 -1
  164. package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
  165. package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
  166. package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
  167. package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
  168. package/lib/module/skia/types/FontMgr/index.js +0 -3
  169. package/lib/module/skia/types/FontMgr/index.js.map +0 -1
  170. package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
  171. package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
  172. package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
  173. package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
  174. package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
  175. package/lib/typescript/src/skia/core/Path.d.ts +0 -21
  176. package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
  177. package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
  178. package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
  179. package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
  180. package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
  181. package/src/skia/core/Paint.ts +0 -22
  182. package/src/skia/core/Path.ts +0 -60
  183. package/src/skia/types/FontMgr/FontMgr.ts +0 -24
  184. package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
  185. package/src/skia/types/FontMgr/index.ts +0 -2
  186. package/src/skia/web/JsiSkFontMgr.ts +0 -38
  187. package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
@@ -19,6 +19,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
19
19
 
20
20
  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; }
21
21
 
22
+ const pd = _reactNative.PixelRatio.get();
23
+
22
24
  class SkiaView extends _react.default.Component {
23
25
  constructor(props) {
24
26
  var _props$mode;
@@ -39,12 +41,12 @@ class SkiaView extends _react.default.Component {
39
41
 
40
42
  _defineProperty(this, "_redrawRequests", 0);
41
43
 
42
- _defineProperty(this, "_unmounted", false);
44
+ _defineProperty(this, "width", 0);
45
+
46
+ _defineProperty(this, "height", 0);
47
+
48
+ _defineProperty(this, "requestId", 0);
43
49
 
44
- this.state = {
45
- width: -1,
46
- height: -1
47
- };
48
50
  this._mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : "default";
49
51
  }
50
52
 
@@ -55,21 +57,30 @@ class SkiaView extends _react.default.Component {
55
57
  }
56
58
 
57
59
  onLayout(evt) {
58
- this.setState({
59
- width: evt.nativeEvent.layout.width,
60
- height: evt.nativeEvent.layout.height
61
- }, () => {
62
- // Reset canvas / surface on layout change
63
- if (this._canvasRef.current) {
64
- // Create surface
65
- this._surface = new _JsiSkSurface.JsiSkSurface(global.CanvasKit, global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)); // Get canvas and repaint
66
-
67
- if (this._surface) {
68
- this._canvas = this._surface.getCanvas();
69
- this.redraw();
70
- }
60
+ const {
61
+ CanvasKit
62
+ } = global;
63
+ const {
64
+ width,
65
+ height
66
+ } = evt.nativeEvent.layout;
67
+ this.width = width;
68
+ this.height = height; // Reset canvas / surface on layout change
69
+
70
+ if (this._canvasRef.current) {
71
+ const canvas = this._canvasRef.current;
72
+ canvas.width = canvas.clientWidth * pd;
73
+ canvas.height = canvas.clientHeight * pd;
74
+ const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
75
+
76
+ if (!surface) {
77
+ throw new Error("Could not create surface");
71
78
  }
72
- });
79
+
80
+ this._surface = new _JsiSkSurface.JsiSkSurface(CanvasKit, surface);
81
+ this._canvas = this._surface.getCanvas();
82
+ this.redraw();
83
+ }
73
84
  }
74
85
 
75
86
  componentDidMount() {
@@ -77,11 +88,13 @@ class SkiaView extends _react.default.Component {
77
88
  this.tick();
78
89
  }
79
90
 
91
+ componentDidUpdate() {
92
+ this.redraw();
93
+ }
94
+
80
95
  componentWillUnmount() {
81
96
  this.unsubscribeAll();
82
- this._surface = null;
83
- this._canvas = null;
84
- this._unmounted = true;
97
+ cancelAnimationFrame(this.requestId);
85
98
  }
86
99
  /**
87
100
  * Creates a snapshot from the canvas in the surface
@@ -104,26 +117,31 @@ class SkiaView extends _react.default.Component {
104
117
  if (this._mode === "continuous" || this._redrawRequests > 0) {
105
118
  this._redrawRequests = 0;
106
119
 
107
- if (this._canvas && this.props.onDraw && this.state.height !== -1 && this.state.width !== -1) {
120
+ if (this._canvas && this.props.onDraw) {
108
121
  var _this$_surface2;
109
122
 
110
123
  const touches = [...this._touches];
111
124
  this._touches = [];
112
125
  const info = {
113
- height: this.state.height,
114
- width: this.state.width,
126
+ height: this.height,
127
+ width: this.width,
115
128
  timestamp: Date.now(),
116
- touches: [touches]
129
+ touches: touches.map(t => [t])
117
130
  };
118
- this.props.onDraw && this.props.onDraw(this._canvas, info);
119
- (_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
120
- }
121
- } // Always request a new redraw as long as we're not unmounted
122
131
 
132
+ if (this.props.onDraw) {
133
+ const canvas = this._canvas;
134
+ canvas.save();
135
+ canvas.scale(pd, pd);
136
+ this.props.onDraw(canvas, info);
137
+ canvas.restore();
138
+ }
123
139
 
124
- if (!this._unmounted) {
125
- requestAnimationFrame(this.tick.bind(this));
140
+ (_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
141
+ }
126
142
  }
143
+
144
+ this.requestId = requestAnimationFrame(this.tick.bind(this));
127
145
  }
128
146
 
129
147
  redraw() {
@@ -175,20 +193,8 @@ class SkiaView extends _react.default.Component {
175
193
  this.redraw();
176
194
  }
177
195
 
178
- handleTouchStart(evt) {
179
- this.handleTouchEvent(evt, _types.TouchType.Start);
180
- }
181
-
182
- handleTouchMove(evt) {
183
- this.handleTouchEvent(evt, _types.TouchType.Active);
184
- }
185
-
186
- handleTouchEnd(evt) {
187
- this.handleTouchEvent(evt, _types.TouchType.Cancelled);
188
- }
189
-
190
- handleTouchCancel(evt) {
191
- this.handleTouchEvent(evt, _types.TouchType.End);
196
+ createTouchHandler(touchType) {
197
+ return evt => this.handleTouchEvent(evt, touchType);
192
198
  }
193
199
 
194
200
  render() {
@@ -201,12 +207,16 @@ class SkiaView extends _react.default.Component {
201
207
  onLayout: this.onLayout.bind(this)
202
208
  }), /*#__PURE__*/_react.default.createElement("canvas", {
203
209
  ref: this._canvasRef,
204
- width: this.state.width,
205
- height: this.state.height,
206
- onPointerDown: this.handleTouchStart.bind(this),
207
- onPointerMove: this.handleTouchMove.bind(this),
208
- onPointerUp: this.handleTouchEnd.bind(this),
209
- onPointerCancel: this.handleTouchCancel.bind(this)
210
+ style: {
211
+ display: "flex",
212
+ flex: 1
213
+ },
214
+ onPointerDown: this.createTouchHandler(_types.TouchType.Start),
215
+ onPointerMove: this.createTouchHandler(_types.TouchType.Active),
216
+ onPointerUp: this.createTouchHandler(_types.TouchType.End),
217
+ onPointerCancel: this.createTouchHandler(_types.TouchType.Cancelled),
218
+ onPointerLeave: this.createTouchHandler(_types.TouchType.End),
219
+ onPointerOut: this.createTouchHandler(_types.TouchType.End)
210
220
  }));
211
221
  }
212
222
 
@@ -1 +1 @@
1
- {"version":3,"sources":["SkiaView.web.tsx"],"names":["SkiaView","React","Component","constructor","props","createRef","state","width","height","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","setState","nativeEvent","layout","_canvasRef","current","_surface","JsiSkSurface","global","CanvasKit","MakeWebGLCanvasSurface","_canvas","getCanvas","redraw","componentDidMount","tick","componentWillUnmount","_unmounted","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","handleTouchStart","TouchType","Start","handleTouchMove","Active","handleTouchEnd","Cancelled","handleTouchCancel","End","render","debug","viewProps"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEO,MAAMA,QAAN,SAAuBC,eAAMC,SAA7B,CAGL;AACAC,EAAAA,WA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AL,CAAsBtC,GAAtB,EAA2BsD,iBAAUG,MAArC;AACD;;AAEDC,EAAAA,cAAc,CAAC1D,GAAD,EAAoB;AAChC,SAAKsC,gBAAL,CAAsBtC,GAAtB,EAA2BsD,iBAAUK,SAArC;AACD;;AAEDC,EAAAA,iBAAiB,CAAC5D,GAAD,EAAoB;AACnC,SAAKsC,gBAAL,CAAsBtC,GAAtB,EAA2BsD,iBAAUO,GAArC;AACD;;AAEDC,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEpE,MAAAA,IAAF;AAAQqE,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAK5E,KAAnD;AACA,wBACE,6BAAC,iBAAD,eAAU4E,SAAV;AAAqB,MAAA,QAAQ,EAAE,KAAKjE,QAAL,CAAcgC,IAAd,CAAmB,IAAnB;AAA/B,qBACE;AACE,MAAA,GAAG,EAAE,KAAK3B,UADZ;AAEE,MAAA,KAAK,EAAE,KAAKd,KAAL,CAAWC,KAFpB;AAGE,MAAA,MAAM,EAAE,KAAKD,KAAL,CAAWE,MAHrB;AAIE,MAAA,aAAa,EAAE,KAAK6D,gBAAL,CAAsBtB,IAAtB,CAA2B,IAA3B,CAJjB;AAKE,MAAA,aAAa,EAAE,KAAKyB,eAAL,CAAqBzB,IAArB,CAA0B,IAA1B,CALjB;AAME,MAAA,WAAW,EAAE,KAAK2B,cAAL,CAAoB3B,IAApB,CAAyB,IAAzB,CANf;AAOE,MAAA,eAAe,EAAE,KAAK6B,iBAAL,CAAuB7B,IAAvB,CAA4B,IAA5B;AAPnB,MADF,CADF;AAaD;;AA/KD","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nexport class SkiaView extends React.Component<\n SkiaViewProps,\n { width: number; height: number }\n> {\n constructor(props: SkiaViewProps) {\n super(props);\n this.state = { width: -1, height: -1 };\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef: React.RefObject<HTMLCanvasElement> = React.createRef();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private _unmounted = false;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n this.setState(\n {\n width: evt.nativeEvent.layout.width,\n height: evt.nativeEvent.layout.height,\n },\n () => {\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n // Create surface\n this._surface = new JsiSkSurface(\n global.CanvasKit,\n global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!\n );\n // Get canvas and repaint\n if (this._surface) {\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n }\n }\n );\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n this._surface = null;\n this._canvas = null;\n this._unmounted = true;\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (\n this._canvas &&\n this.props.onDraw &&\n this.state.height !== -1 &&\n this.state.width !== -1\n ) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.state.height,\n width: this.state.width,\n timestamp: Date.now(),\n touches: [touches],\n };\n this.props.onDraw && this.props.onDraw(this._canvas!, info);\n this._surface?.ref.flush();\n }\n }\n // Always request a new redraw as long as we're not unmounted\n if (!this._unmounted) {\n requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n handleTouchStart(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Start);\n }\n\n handleTouchMove(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Active);\n }\n\n handleTouchEnd(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Cancelled);\n }\n\n handleTouchCancel(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.End);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n width={this.state.width}\n height={this.state.height}\n onPointerDown={this.handleTouchStart.bind(this)}\n onPointerMove={this.handleTouchMove.bind(this)}\n onPointerUp={this.handleTouchEnd.bind(this)}\n onPointerCancel={this.handleTouchCancel.bind(this)}\n />\n </View>\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["SkiaView.web.tsx"],"names":["pd","PixelRatio","get","SkiaView","React","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","clientWidth","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","map","t","save","scale","restore","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","createTouchHandler","render","debug","viewProps","display","flex","TouchType","Start","Active","End","Cancelled"],"mappings":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEA,MAAMA,EAAE,GAAGC,wBAAWC,GAAX,EAAX;;AAEO,MAAMC,QAAN,SAAuBC,eAAMC,SAA7B,CAAsD;AAC3DC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAAA;;AAChC,UAAMA,KAAN;;AADgC,sCAKM,IALN;;AAAA,8CAMY,EANZ;;AAAA,sCAOG,EAPH;;AAAA,qCAQC,IARD;;AAAA,qDASbH,eAAMI,SAAN,EATa;;AAAA;;AAAA,6CAWR,CAXQ;;AAAA,mCAYlB,CAZkB;;AAAA,oCAajB,CAbiB;;AAAA,uCAcd,CAdc;;AAEhC,SAAKC,KAAL,kBAAaF,KAAK,CAACG,IAAnB,qDAA2B,SAA3B;AACD;;AAaOC,EAAAA,cAAc,GAAG;AACvB,SAAKC,gBAAL,CAAsBC,OAAtB,CAA+BC,CAAD,IAAOA,CAAC,EAAtC;;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,QAAL,CAAc6C,IAAd,CAAmB,IAAnB;AAA/B,qBACE;AACE,MAAA,GAAG,EAAE,KAAKrC,UADZ;AAEE,MAAA,KAAK,EAAE;AAAE+D,QAAAA,OAAO,EAAE,MAAX;AAAmBC,QAAAA,IAAI,EAAE;AAAzB,OAFT;AAGE,MAAA,aAAa,EAAE,KAAKL,kBAAL,CAAwBM,iBAAUC,KAAlC,CAHjB;AAIE,MAAA,aAAa,EAAE,KAAKP,kBAAL,CAAwBM,iBAAUE,MAAlC,CAJjB;AAKE,MAAA,WAAW,EAAE,KAAKR,kBAAL,CAAwBM,iBAAUG,GAAlC,CALf;AAME,MAAA,eAAe,EAAE,KAAKT,kBAAL,CAAwBM,iBAAUI,SAAlC,CANnB;AAOE,MAAA,cAAc,EAAE,KAAKV,kBAAL,CAAwBM,iBAAUG,GAAlC,CAPlB;AAQE,MAAA,YAAY,EAAE,KAAKT,kBAAL,CAAwBM,iBAAUG,GAAlC;AARhB,MADF,CADF;AAcD;;AAjK0D","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private width = 0;\n private height = 0;\n private requestId = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas && this.props.onDraw) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.height,\n width: this.width,\n timestamp: Date.now(),\n touches: touches.map((t) => [t]),\n };\n if (this.props.onDraw) {\n const canvas = this._canvas!;\n canvas.save();\n canvas.scale(pd, pd);\n this.props.onDraw(canvas, info);\n canvas.restore();\n }\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"]}
@@ -21,7 +21,7 @@ const useInternalTouchHandler = function (handlers) {
21
21
  history.forEach(touches => {
22
22
  // Enumerate touches
23
23
  for (let i = 0; i < touches.length; i++) {
24
- var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouchInfoRef$cur3, _prevTouchInfoRef$cur4, _prevTouchInfoRef$cur5, _prevTouchInfoRef$cur6, _prevVelocityRef$curr, _prevVelocityRef$curr2;
24
+ var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouchInfoRef$cur3, _prevTouchInfoRef$cur4, _prevTouchInfoRef$cur5, _prevTouchInfoRef$cur6;
25
25
 
26
26
  if (!multiTouch && i > 0) {
27
27
  break;
@@ -39,12 +39,17 @@ const useInternalTouchHandler = function (handlers) {
39
39
  x: distX / timeDiffseconds / _reactNative.PixelRatio.get(),
40
40
  y: distY / timeDiffseconds / _reactNative.PixelRatio.get()
41
41
  };
42
+ } else {
43
+ prevVelocityRef.current[touch.id] = {
44
+ x: 0,
45
+ y: 0
46
+ };
42
47
  }
43
48
  }
44
49
 
45
50
  const extendedTouchInfo = { ...touch,
46
- velocityX: (_prevVelocityRef$curr = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr === void 0 ? void 0 : _prevVelocityRef$curr.x,
47
- velocityY: (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.y
51
+ velocityX: prevVelocityRef.current[touch.id].x,
52
+ velocityY: prevVelocityRef.current[touch.id].y
48
53
  }; // Save previous touch
49
54
 
50
55
  prevTouchInfoRef.current[touch.id] = touch;
@@ -1 +1 @@
1
- {"version":3,"sources":["useTouchHandler.ts"],"names":["useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","timeDiffseconds","timestamp","current","id","distX","x","distY","y","type","TouchType","Start","End","Cancelled","PixelRatio","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":";;;;;;;AACA;;AACA;;AAQA;;AAEA,MAAMA,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;AAAA,MAFjBC,IAEiB,uEAFM,EAEN;AAAA,MADjBC,UACiB,uEADJ,KACI;AACjB,QAAMC,gBAAgB,GAAG,mBAAqC,EAArC,CAAzB;AACA,QAAMC,eAAe,GAAG,mBACtB,EADsB,CAAxB;AAIA,SAAO,wBAAaC,OAAD,IAA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CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMiC,oBAAoB,GAAG,UAClClC,QADkC,EAGjB;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo }>({});\n const prevVelocityRef = useRef<{ [key: number]: { x: number; y: number } }>(\n {}\n );\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX =\n touch.x - (prevTouchInfoRef.current[touch.id]?.x ?? touch.x);\n const distY =\n touch.y - (prevTouchInfoRef.current[touch.id]?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled\n ) {\n if (timeDiffseconds > 0) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x,\n velocityY: prevVelocityRef.current[touch.id]?.y,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"]}
1
+ {"version":3,"sources":["useTouchHandler.ts"],"names":["useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","timeDiffseconds","timestamp","current","id","distX","x","distY","y","type","TouchType","Start","End","Cancelled","PixelRatio","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":";;;;;;;AACA;;AACA;;AAQA;;AAEA,MAAMA,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;AAAA,MAFjBC,IAEiB,uEAFM,EAEN;AAAA,MADjBC,UACiB,uEADJ,KACI;AACjB,QAAMC,gBAAgB,GAAG,mBAAqC,EAArC,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ApED;AAsEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMgC,eAAe,GAAG,UAC7BjC,QAD6B,EAGZ;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,KAAjB,CAA9B;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMiC,oBAAoB,GAAG,UAClClC,QADkC,EAGjB;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo }>({});\n const prevVelocityRef = useRef<{ [key: number]: { x: number; y: number } }>(\n {}\n );\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX =\n touch.x - (prevTouchInfoRef.current[touch.id]?.x ?? touch.x);\n const distY =\n touch.y - (prevTouchInfoRef.current[touch.id]?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled\n ) {\n if (timeDiffseconds > 0) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n } else {\n prevVelocityRef.current[touch.id] = { x: 0, y: 0 };\n }\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id].x,\n velocityY: prevVelocityRef.current[touch.id].y,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"]}
@@ -11,8 +11,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
 
12
12
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
13
13
  // @ts-expect-error
14
- const LoadSkiaWeb = async () => {
15
- const CanvasKit = await (0, _canvaskit.default)(); // The CanvasKit API is stored on the global object and used
14
+ const LoadSkiaWeb = async opts => {
15
+ if (global.CanvasKit !== undefined) {
16
+ return;
17
+ }
18
+
19
+ const CanvasKit = await (0, _canvaskit.default)(opts); // The CanvasKit API is stored on the global object and used
16
20
  // to create the JsiSKApi in the Skia.web.ts file.
17
21
 
18
22
  global.CanvasKit = CanvasKit;
@@ -1 +1 @@
1
- {"version":3,"sources":["LoadSkiaWeb.tsx"],"names":["LoadSkiaWeb","CanvasKit","global","LoadSkia"],"mappings":";;;;;;;AAEA;;;;AAFA;AACA;AAQO,MAAMA,WAAW,GAAG,YAAY;AACrC,QAAMC,SAAS,GAAG,MAAM,yBAAxB,CADqC,CAErC;AACA;;AACAC,EAAAA,MAAM,CAACD,SAAP,GAAmBA,SAAnB;AACD,CALM,C,CAOP;;;;AACO,MAAME,QAAQ,GAAGH,WAAjB","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { CanvasKit as CanvasKitType } from \"canvaskit-wasm\";\n\ndeclare global {\n var CanvasKit: CanvasKitType;\n}\n\nexport const LoadSkiaWeb = async () => {\n const CanvasKit = await CanvasKitInit();\n // The CanvasKit API is stored on the global object and used\n // to create the JsiSKApi in the Skia.web.ts file.\n global.CanvasKit = CanvasKit;\n};\n\n// We keep this function for backward compatibility\nexport const LoadSkia = LoadSkiaWeb;\n"]}
1
+ {"version":3,"sources":["LoadSkiaWeb.tsx"],"names":["LoadSkiaWeb","opts","global","CanvasKit","undefined","LoadSkia"],"mappings":";;;;;;;AAEA;;;;AAFA;AACA;AAWO,MAAMA,WAAW,GAAG,MAAOC,IAAP,IAAuC;AAChE,MAAIC,MAAM,CAACC,SAAP,KAAqBC,SAAzB,EAAoC;AAClC;AACD;;AACD,QAAMD,SAAS,GAAG,MAAM,wBAAcF,IAAd,CAAxB,CAJgE,CAKhE;AACA;;AACAC,EAAAA,MAAM,CAACC,SAAP,GAAmBA,SAAnB;AACD,CARM,C,CAUP;;;;AACO,MAAME,QAAQ,GAAGL,WAAjB","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type {\n CanvasKit as CanvasKitType,\n CanvasKitInitOptions,\n} from \"canvaskit-wasm\";\n\ndeclare global {\n var CanvasKit: CanvasKitType;\n}\n\nexport const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {\n if (global.CanvasKit !== undefined) {\n return;\n }\n const CanvasKit = await CanvasKitInit(opts);\n // The CanvasKit API is stored on the global object and used\n // to create the JsiSKApi in the Skia.web.ts file.\n global.CanvasKit = CanvasKit;\n};\n\n// We keep this function for backward compatibility\nexport const LoadSkia = LoadSkiaWeb;\n"]}
@@ -18,19 +18,20 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
18
18
  const WithSkiaWeb = _ref => {
19
19
  let {
20
20
  getComponent,
21
- fallback
21
+ fallback,
22
+ opts
22
23
  } = _ref;
23
24
  const Inner = (0, _react.useMemo)(() => /*#__PURE__*/(0, _react.lazy)(async () => {
24
25
  if (_reactNative.Platform.OS === "web") {
25
- await (0, _LoadSkiaWeb.LoadSkiaWeb)();
26
+ await (0, _LoadSkiaWeb.LoadSkiaWeb)(opts);
26
27
  } else {
27
28
  console.warn("<WithSkiaWeb /> is only necessary on web. Consider not using on native.");
28
29
  }
29
30
 
30
31
  return getComponent();
31
- }), [getComponent]);
32
+ }), [getComponent, opts]);
32
33
  return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
33
- fallback: fallback
34
+ fallback: fallback !== null && fallback !== void 0 ? fallback : null
34
35
  }, /*#__PURE__*/_react.default.createElement(Inner, null));
35
36
  };
36
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["WithSkiaWeb.tsx"],"names":["WithSkiaWeb","getComponent","fallback","Inner","Platform","OS","console","warn"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;;;;;AAOO,MAAMA,WAAW,GAAG,QAA+C;AAAA,MAA9C;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAA8C;AACxE,QAAMC,KAAK,GAAG,oBACZ,mBACE,iBAAK,YAAY;AACf,QAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB,YAAM,+BAAN;AACD,KAFD,MAEO;AACLC,MAAAA,OAAO,CAACC,IAAR,CACE,yEADF;AAGD;;AACD,WAAON,YAAY,EAAnB;AACD,GATD,CAFU,EAYZ,CAACA,YAAD,CAZY,CAAd;AAcA,sBACE,6BAAC,eAAD;AAAU,IAAA,QAAQ,EAAEC;AAApB,kBACE,6BAAC,KAAD,OADF,CADF;AAKD,CApBM","sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"react-native\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n}\n\nexport const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {\n const Inner = useMemo(\n () =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb();\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent]\n );\n return (\n <Suspense fallback={fallback}>\n <Inner />\n </Suspense>\n );\n};\n"]}
1
+ {"version":3,"sources":["WithSkiaWeb.tsx"],"names":["WithSkiaWeb","getComponent","fallback","opts","Inner","Platform","OS","console","warn"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;;;;;AAQO,MAAMA,WAAW,GAAG,QAIN;AAAA,MAJO;AAC1BC,IAAAA,YAD0B;AAE1BC,IAAAA,QAF0B;AAG1BC,IAAAA;AAH0B,GAIP;AACnB,QAAMC,KAAK,GAAG,oBACZ,mBACE,iBAAK,YAAY;AACf,QAAIC,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB,YAAM,8BAAYH,IAAZ,CAAN;AACD,KAFD,MAEO;AACLI,MAAAA,OAAO,CAACC,IAAR,CACE,yEADF;AAGD;;AACD,WAAOP,YAAY,EAAnB;AACD,GATD,CAFU,EAYZ,CAACA,YAAD,EAAeE,IAAf,CAZY,CAAd;AAcA,sBACE,6BAAC,eAAD;AAAU,IAAA,QAAQ,EAAED,QAAF,aAAEA,QAAF,cAAEA,QAAF,GAAc;AAAhC,kBACE,6BAAC,KAAD,OADF,CADF;AAKD,CAxBM","sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"react-native\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback?: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n opts?: Parameters<typeof LoadSkiaWeb>[0];\n}\n\nexport const WithSkiaWeb = ({\n getComponent,\n fallback,\n opts,\n}: WithSkiaProps) => {\n const Inner = useMemo(\n () =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb(opts);\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent, opts]\n );\n return (\n <Suspense fallback={fallback ?? null}>\n <Inner />\n </Suspense>\n );\n};\n"]}
@@ -45,12 +45,8 @@ export const Mock = {
45
45
  useFont: Noop,
46
46
  useTypeface: Noop,
47
47
  useImage: Noop,
48
- usePath: Noop,
49
48
  useSVG: Noop,
50
- useTextPath: Noop,
51
- usePaint: Noop,
52
49
  usePicture: Noop,
53
- useSvgPath: Noop,
54
50
  // 3. Point/Rect/Transform utilities
55
51
  vec,
56
52
  rect: (x, y, width, height) => ({
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["Values","ValuesHooks","BaseSkia","useSharedValueEffect","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useDataCollection","useRawData","useData","useFont","useTypeface","useImage","usePath","useSVG","useTextPath","usePaint","usePicture","useSvgPath","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"mappings":"AAAA;AAGA,OAAO,KAAKA,MAAZ,MAAwB,eAAxB;AACA,OAAO,KAAKC,WAAZ,MAA6B,iBAA7B;AACA,OAAO,KAAKC,QAAZ,MAA0B,eAA1B;AAKA,SAASC,oBAAT,QAAqC,6CAArC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,cAAZ,MAAgC,oBAAhC;AACA,OAAO,KAAKC,aAAZ,MAA+B,oCAA/B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,yCAAnC;AACA,OAAO,KAAKC,mBAAZ,MAAqC,0CAArC;AACA,SAASC,SAAT,QAA0B,0CAA1B;;AAEA,MAAMC,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEA,OAAO,MAAMC,IAAa,GAAG,IAAIP,IAAJ,EAAtB;AAEP,OAAO,MAAMQ,G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DJ;AACA,KAAGG,eApDC;AAqDJ,KAAGC,eArDC;AAsDJ,KAAGC,cAtDC;AAuDJ,KAAGC,aAvDC;AAwDJ,KAAGC,iBAxDC;AAyDJ,KAAGC,mBAzDC;AA0DJoD,EAAAA,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA9DD;AA+DJC,EAAAA,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA/D7C;AAgEJxD,EAAAA,SAhEI;AAiEJ6D,EAAAA,aAAa,EAAEtD,IAjEX;AAkEJuD,EAAAA,iBAAiB,EAAEvD;AAlEf,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useDataCollection: Noop,\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n usePath: Noop,\n useSVG: Noop,\n useTextPath: Noop,\n usePaint: Noop,\n usePicture: Noop,\n useSvgPath: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["Values","ValuesHooks","BaseSkia","useSharedValueEffect","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useDataCollection","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"mappings":"AAAA;AAGA,OAAO,KAAKA,MAAZ,MAAwB,eAAxB;AACA,OAAO,KAAKC,WAAZ,MAA6B,iBAA7B;AACA,OAAO,KAAKC,QAAZ,MAA0B,eAA1B;AAKA,SAASC,oBAAT,QAAqC,6CAArC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,cAAZ,MAAgC,oBAAhC;AACA,OAAO,KAAKC,aAAZ,MAA+B,oCAA/B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,yCAAnC;AACA,OAAO,KAAKC,mBAAZ,MAAqC,0CAArC;AACA,SAASC,SAAT,QAA0B,0CAA1B;;AAEA,MAAMC,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEA,OAAO,MAAMC,IAAa,GAAG,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ApDC;AAqDJ,KAAGC,mBArDC;AAsDJgD,EAAAA,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA1DD;AA2DJC,EAAAA,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;AA4DJpD,EAAAA,SA5DI;AA6DJyD,EAAAA,aAAa,EAAElD,IA7DX;AA8DJmD,EAAAA,iBAAiB,EAAEnD;AA9Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useDataCollection: Noop,\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
@@ -23,15 +23,13 @@ const render = (element, root, container) => {
23
23
  };
24
24
 
25
25
  export const useCanvasRef = () => useRef(null);
26
- const defaultFontMgr = Skia.FontMgr.RefDefault();
27
26
  export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
28
27
  let {
29
28
  children,
30
29
  style,
31
30
  debug,
32
31
  mode,
33
- onTouch,
34
- fontMgr
32
+ onTouch
35
33
  } = _ref;
36
34
  const size = useValue({
37
35
  width: 0,
@@ -83,16 +81,17 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
83
81
  opacity: 1,
84
82
  ref,
85
83
  center: Skia.Point(width / 2, height / 2),
86
- fontMgr: fontMgr !== null && fontMgr !== void 0 ? fontMgr : defaultFontMgr,
87
84
  Skia
88
85
  };
89
86
  container.draw(ctx);
90
87
  }, [tick, onTouch]);
91
88
  useEffect(() => {
92
89
  return () => {
93
- container.depMgr.unsubscribe();
90
+ skiaReconciler.updateContainer(null, root, null, () => {
91
+ container.depMgr.unsubscribe();
92
+ });
94
93
  };
95
- }, [container]);
94
+ }, [container, root]);
96
95
  return /*#__PURE__*/React.createElement(SkiaView, {
97
96
  ref: ref,
98
97
  style: style,
@@ -1 +1 @@
1
- {"version":3,"sources":["Canvas.tsx"],"names":["React","useEffect","useState","useCallback","useMemo","forwardRef","useRef","ReactReconciler","SkiaView","useDrawCallback","useValue","Skia","debug","hostDebug","skHostConfig","Container","DependencyManager","CanvasProvider","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","defaultFontMgr","FontMgr","RefDefault","Canvas","forwardedRef","children","style","mode","onTouch","fontMgr","size","width","height","canvasCtx","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","createContainer","onDraw","canvas","info","timestamp","touches","current","paint","Paint","ctx","opacity","center","Point","draw","unsubscribe","refs","targetRef","forEach"],"mappings":"AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,QAFF,EAGEC,WAHF,EAIEC,OAJF,EAKEC,UALF,EAMEC,MANF,QAOO,OAPP;AAgBA,OAAOC,eAAP,MAA4B,kBAA5B;AAEA,SAASC,QAAT,EAAmBC,eAAnB,QAA0C,UAA1C;AA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;AACA;AACA;;AACA,MAAMmC,eAAe,GAAG,YAEnB;AAAA,oCADAoB,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAGpE,KAAK,CAACM,MAAN,CAAgB,IAAhB,CAAlB;AACAN,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpBkE,IAAAA,IAAI,CAACE,OAAL,CAAcvB,GAAD,IAAS;AACpB,UAAIA,GAAJ,EAAS;AACP,YAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;AAC7BA,UAAAA,GAAG,CAACsB,SAAS,CAACV,OAAX,CAAH;AACD,SAFD,MAEO;AACLZ,UAAAA,GAAG,CAACY,OAAJ,GAAcU,SAAS,CAACV,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACS,IAAD,CAVH;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport { SkiaView, useDrawCallback } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport type { SkFontMgr } from \"../skia/types\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport { Skia } from \"../skia/Skia\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n\n container.depMgr.subscribe();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaView>(null);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaView> {\n ref?: RefObject<SkiaView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n fontMgr?: SkFontMgr;\n}\n\nconst defaultFontMgr = Skia.FontMgr.RefDefault();\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch, fontMgr }, forwardedRef) => {\n const size = useValue({ width: 0, height: 0 });\n const canvasCtx = useMemo(() => ({ Skia, size }), [size]);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [tick, setTick] = useState(0);\n const redraw = useCallback(() => setTick((t) => t + 1), []);\n\n const container = useMemo(\n () => new Container(new DependencyManager(ref), redraw),\n [redraw, ref]\n );\n\n const root = useMemo(\n () => skiaReconciler.createContainer(container, 0, false, null),\n [container]\n );\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={canvasCtx}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container, canvasCtx]);\n\n // Draw callback\n const onDraw = useDrawCallback(\n (canvas, info) => {\n // TODO: if tree is empty (count === 1) maybe we should not render?\n const { width, height, timestamp } = info;\n if (onTouch) {\n onTouch(info.touches);\n }\n if (\n width !== canvasCtx.size.current.width ||\n height !== canvasCtx.size.current.height\n ) {\n canvasCtx.size.current = { width, height };\n }\n const paint = Skia.Paint();\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: Skia.Point(width / 2, height / 2),\n fontMgr: fontMgr ?? defaultFontMgr,\n Skia,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n container.depMgr.unsubscribe();\n };\n }, [container]);\n\n return (\n <SkiaView\n ref={ref}\n style={style}\n onDraw={onDraw}\n mode={mode}\n debug={debug}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"]}
1
+ {"version":3,"sources":["Canvas.tsx"],"names":["React","useEffect","useState","useCallback","useMemo","forwardRef","useRef","ReactReconciler","SkiaView","useDrawCallback","useValue","Skia","debug","hostDebug","skHostConfig","Container","DependencyManager","CanvasProvider","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","subscribe","useCanvasRef","Canvas","forwardedRef","children","style","mode","onTouch","size","width","height","canvasCtx","innerRef","ref","useCombinedRefs","tick","setTick","redraw","t","createContainer","onDraw","canvas","info","timestamp","touches","current","paint","Paint","ctx","opacity","center","Point","draw","unsubscribe","refs","targetRef","forEach"],"mappings":"AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,QAFF,EAGEC,WAHF,EAIEC,OAJF,EAKEC,UALF,EAMEC,MANF,QAOO,OAPP;AAgBA,OAAOC,eAAP,MAA4B,kBAA5B;AAEA,SAASC,QAAT,EAAmBC,eAAnB,QAA0C,UAA1C;AAEA,SAASC,QAAT,QAAyB,0BAAzB;AACA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,KAAK,IAAIC,SAAlB,EAA6BC,YAA7B,QAAiD,cAAjD,C,CACA;;AACA,SAASC,SAAT,QAA0B,SAA1B;AACA,SAASC,iBAAT,QAAkC,qBAAlC;AACA,SAASC,cAAT,QAA+B,aAA/B;AAEA,OAAO,MAAMC,cAAc,GAAGX,eAAe,CAACO,YAAD,CAAtC;AAEPI,cAAc,CAACC,kBAAf,CAAk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AAX,CAAH;AACD,SAFD,MAEO;AACLZ,UAAAA,GAAG,CAACY,OAAJ,GAAcU,SAAS,CAACV,OAAxB;AACD;AACF;AACF,KARD;AASD,GAVD,EAUG,CAACS,IAAD,CAVH;AAWA,SAAOC,SAAP;AACD,CAhBD","sourcesContent":["import React, {\n useEffect,\n useState,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport { SkiaView, useDrawCallback } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { useValue } from \"../values/hooks/useValue\";\nimport { Skia } from \"../skia/Skia\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./nodes\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n\n container.depMgr.subscribe();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaView>(null);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaView> {\n ref?: RefObject<SkiaView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaView, CanvasProps>(\n ({ children, style, debug, mode, onTouch }, forwardedRef) => {\n const size = useValue({ width: 0, height: 0 });\n const canvasCtx = useMemo(() => ({ Skia, size }), [size]);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [tick, setTick] = useState(0);\n const redraw = useCallback(() => setTick((t) => t + 1), []);\n\n const container = useMemo(\n () => new Container(new DependencyManager(ref), redraw),\n [redraw, ref]\n );\n\n const root = useMemo(\n () => skiaReconciler.createContainer(container, 0, false, null),\n [container]\n );\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={canvasCtx}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container, canvasCtx]);\n\n // Draw callback\n const onDraw = useDrawCallback(\n (canvas, info) => {\n // TODO: if tree is empty (count === 1) maybe we should not render?\n const { width, height, timestamp } = info;\n if (onTouch) {\n onTouch(info.touches);\n }\n if (\n width !== canvasCtx.size.current.width ||\n height !== canvasCtx.size.current.height\n ) {\n canvasCtx.size.current = { width, height };\n }\n const paint = Skia.Paint();\n const ctx = {\n width,\n height,\n timestamp,\n canvas,\n paint,\n opacity: 1,\n ref,\n center: Skia.Point(width / 2, height / 2),\n Skia,\n };\n container.draw(ctx);\n },\n [tick, onTouch]\n );\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.unsubscribe();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaView\n ref={ref}\n style={style}\n onDraw={onDraw}\n mode={mode}\n debug={debug}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"]}
@@ -2,13 +2,10 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React from "react";
4
4
  import { createDrawing } from "../../nodes/Drawing";
5
- import { processFont } from "../../processors/Font";
6
5
  const onDraw = createDrawing((_ref, _ref2) => {
7
6
  let {
8
7
  canvas,
9
- paint,
10
- fontMgr,
11
- Skia
8
+ paint
12
9
  } = _ref;
13
10
  let {
14
11
  glyphs: rawGlyphs,
@@ -16,7 +13,9 @@ const onDraw = createDrawing((_ref, _ref2) => {
16
13
  y,
17
14
  ...fontDef
18
15
  } = _ref2;
19
- const font = processFont(Skia, fontMgr, fontDef);
16
+ const {
17
+ font
18
+ } = fontDef;
20
19
  const {
21
20
  glyphs,
22
21
  positions
@@ -1 +1 @@
1
- {"version":3,"sources":["Glyphs.tsx"],"names":["React","createDrawing","processFont","onDraw","canvas","paint","fontMgr","Skia","glyphs","rawGlyphs","x","y","fontDef","font","positions","reduce","acc","glyph","id","pos","push","drawGlyphs","Glyphs","props","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,aAAT,QAA8B,qBAA9B;AAGA,SAASC,WAAT,QAA4B,uBAA5B;AAmBA,MAAMC,MAAM,GAAGF,aAAa,CAC1B,iBAGK;AAAA,MAFH;AAAEG,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA,OAAjB;AAA0BC,IAAAA;AAA1B,GAEG;AAAA,MADH;AAAEC,IAAAA,MAAM,EAAEC,SAAV;AAAqBC,IAAAA,CAArB;AAAwBC,IAAAA,CAAxB;AAA2B,OAAGC;AAA9B,GACG;AACH,QAAMC,IAAI,GAAGX,WAAW,CAACK,IAAD,EAAOD,OAAP,EAAgBM,OAAhB,CAAxB;AACA,QAAM;AAAEJ,IAAAA,MAAF;AAAUM,IAAAA;AAAV,MAAwBL,SAAS,CAACM,MAAV,CAC5B,CAACC,GAAD,EAAMC,KAAN,KAAgB;AACd,UAAM;AAAEC,MAAAA,EAAF;AAAMC,MAAAA;AAAN,QAAcF,KAApB;AACAD,IAAAA,GAAG,CAACR,MAAJ,CAAWY,IAAX,CAAgBF,EAAhB;AACAF,IAAAA,GAAG,CAACF,SAAJ,CAAcM,IAAd,CAAmBD,GAAnB;AACA,WAAOH,GAAP;AACD,GAN2B,EAO5B;AAAER,IAAAA,MAAM,EAAE,EAAV;AAAcM,IAAAA,SAAS,EAAE;AAAzB,GAP4B,CAA9B;AASAV,EAAAA,MAAM,CAACiB,UAAP,CAAkBb,MAAlB,EAA0BM,SAA1B,EAAqCJ,CAArC,EAAwCC,CAAxC,EAA2CE,IAA3C,EAAiDR,KAAjD;AACD,CAhByB,CAA5B;AAmBA,OAAO,MAAMiB,MAAM,GAAIC,KAAD,IAAuC;AAC3D,sBAAO;AAAW,IAAA,MAAM,EAAEpB;AAAnB,KAA+BoB,KAA/B,EAAP;AACD,CAFM;AAIPD,MAAM,CAACE,YAAP,GAAsB;AACpBd,EAAAA,CAAC,EAAE,CADiB;AAEpBC,EAAAA,CAAC,EAAE;AAFiB,CAAtB","sourcesContent":["import React from \"react\";\n\nimport type { CustomPaintProps, AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\nimport type { SkPoint } from \"../../../skia/types\";\nimport type { FontDef } from \"../../processors/Font\";\nimport { processFont } from \"../../processors/Font\";\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport type GlyphsProps = CustomPaintProps &\n FontDef & {\n x: number;\n y: number;\n glyphs: Glyph[];\n };\n\ninterface ProcessedGlyphs {\n glyphs: number[];\n positions: SkPoint[];\n}\n\nconst onDraw = createDrawing<GlyphsProps>(\n (\n { canvas, paint, fontMgr, Skia },\n { glyphs: rawGlyphs, x, y, ...fontDef }\n ) => {\n const font = processFont(Skia, fontMgr, fontDef);\n const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(\n (acc, glyph) => {\n const { id, pos } = glyph;\n acc.glyphs.push(id);\n acc.positions.push(pos);\n return acc;\n },\n { glyphs: [], positions: [] }\n );\n canvas.drawGlyphs(glyphs, positions, x, y, font, paint);\n }\n);\n\nexport const Glyphs = (props: AnimatedProps<GlyphsProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nGlyphs.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
1
+ {"version":3,"sources":["Glyphs.tsx"],"names":["React","createDrawing","onDraw","canvas","paint","glyphs","rawGlyphs","x","y","fontDef","font","positions","reduce","acc","glyph","id","pos","push","drawGlyphs","Glyphs","props","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,aAAT,QAA8B,qBAA9B;AAqBA,MAAMC,MAAM,GAAGD,aAAa,CAC1B,iBAAgE;AAAA,MAA/D;AAAEE,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA+D;AAAA,MAA5C;AAAEC,IAAAA,MAAM,EAAEC,SAAV;AAAqBC,IAAAA,CAArB;AAAwBC,IAAAA,CAAxB;AAA2B,OAAGC;AAA9B,GAA4C;AAC9D,QAAM;AAAEC,IAAAA;AAAF,MAAWD,OAAjB;AACA,QAAM;AAAEJ,IAAAA,MAAF;AAAUM,IAAAA;AAAV,MAAwBL,SAAS,CAACM,MAAV,CAC5B,CAACC,GAAD,EAAMC,KAAN,KAAgB;AACd,UAAM;AAAEC,MAAAA,EAAF;AAAMC,MAAAA;AAAN,QAAcF,KAApB;AACAD,IAAAA,GAAG,CAACR,MAAJ,CAAWY,IAAX,CAAgBF,EAAhB;AACAF,IAAAA,GAAG,CAACF,SAAJ,CAAcM,IAAd,CAAmBD,GAAnB;AACA,WAAOH,GAAP;AACD,GAN2B,EAO5B;AAAER,IAAAA,MAAM,EAAE,EAAV;AAAcM,IAAAA,SAAS,EAAE;AAAzB,GAP4B,CAA9B;AASAR,EAAAA,MAAM,CAACe,UAAP,CAAkBb,MAAlB,EAA0BM,SAA1B,EAAqCJ,CAArC,EAAwCC,CAAxC,EAA2CE,IAA3C,EAAiDN,KAAjD;AACD,CAbyB,CAA5B;AAgBA,OAAO,MAAMe,MAAM,GAAIC,KAAD,IAAuC;AAC3D,sBAAO;AAAW,IAAA,MAAM,EAAElB;AAAnB,KAA+BkB,KAA/B,EAAP;AACD,CAFM;AAIPD,MAAM,CAACE,YAAP,GAAsB;AACpBd,EAAAA,CAAC,EAAE,CADiB;AAEpBC,EAAAA,CAAC,EAAE;AAFiB,CAAtB","sourcesContent":["import React from \"react\";\n\nimport type { CustomPaintProps, AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\nimport type { SkPoint } from \"../../../skia/types\";\nimport type { FontDef } from \"../../processors/Font\";\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport type GlyphsProps = CustomPaintProps &\n FontDef & {\n x: number;\n y: number;\n glyphs: Glyph[];\n };\n\ninterface ProcessedGlyphs {\n glyphs: number[];\n positions: SkPoint[];\n}\n\nconst onDraw = createDrawing<GlyphsProps>(\n ({ canvas, paint }, { glyphs: rawGlyphs, x, y, ...fontDef }) => {\n const { font } = fontDef;\n const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(\n (acc, glyph) => {\n const { id, pos } = glyph;\n acc.glyphs.push(id);\n acc.positions.push(pos);\n return acc;\n },\n { glyphs: [], positions: [] }\n );\n canvas.drawGlyphs(glyphs, positions, x, y, font, paint);\n }\n);\n\nexport const Glyphs = (props: AnimatedProps<GlyphsProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nGlyphs.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
@@ -2,13 +2,10 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React from "react";
4
4
  import { createDrawing } from "../../nodes/Drawing";
5
- import { processFont } from "../../processors";
6
5
  const onDraw = createDrawing((_ref, _ref2) => {
7
6
  let {
8
7
  canvas,
9
- paint,
10
- fontMgr,
11
- Skia
8
+ paint
12
9
  } = _ref;
13
10
  let {
14
11
  text,
@@ -16,7 +13,9 @@ const onDraw = createDrawing((_ref, _ref2) => {
16
13
  y,
17
14
  ...fontDef
18
15
  } = _ref2;
19
- const font = processFont(Skia, fontMgr, fontDef);
16
+ const {
17
+ font
18
+ } = fontDef;
20
19
  canvas.drawText(text, x, y, paint, font);
21
20
  });
22
21
  export const Text = props => {
@@ -1 +1 @@
1
- {"version":3,"sources":["Text.tsx"],"names":["React","createDrawing","processFont","onDraw","canvas","paint","fontMgr","Skia","text","x","y","fontDef","font","drawText","Text","props","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAOA,SAASC,aAAT,QAA8B,qBAA9B;AACA,SAASC,WAAT,QAA4B,kBAA5B;AASA,MAAMC,MAAM,GAAGF,aAAa,CAC1B,iBAAkE;AAAA,MAAjE;AAAEG,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA,OAAjB;AAA0BC,IAAAA;AAA1B,GAAiE;AAAA,MAA/B;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,CAAR;AAAWC,IAAAA,CAAX;AAAc,OAAGC;AAAjB,GAA+B;AAChE,QAAMC,IAAI,GAAGV,WAAW,CAACK,IAAD,EAAOD,OAAP,EAAgBK,OAAhB,CAAxB;AACAP,EAAAA,MAAM,CAACS,QAAP,CAAgBL,IAAhB,EAAsBC,CAAtB,EAAyBC,CAAzB,EAA4BL,KAA5B,EAAmCO,IAAnC;AACD,CAJyB,CAA5B;AAOA,OAAO,MAAME,IAAI,GAAIC,KAAD,IAAqC;AACvD,sBAAO;AAAW,IAAA,MAAM,EAAEZ;AAAnB,KAA+BY,KAA/B,EAAP;AACD,CAFM;AAIPD,IAAI,CAACE,YAAL,GAAoB;AAClBP,EAAAA,CAAC,EAAE,CADe;AAElBC,EAAAA,CAAC,EAAE;AAFe,CAApB","sourcesContent":["import React from \"react\";\n\nimport type {\n CustomPaintProps,\n AnimatedProps,\n FontDef,\n} from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\nimport { processFont } from \"../../processors\";\n\ntype TextProps = CustomPaintProps &\n FontDef & {\n text: string;\n x: number;\n y: number;\n };\n\nconst onDraw = createDrawing<TextProps>(\n ({ canvas, paint, fontMgr, Skia }, { text, x, y, ...fontDef }) => {\n const font = processFont(Skia, fontMgr, fontDef);\n canvas.drawText(text, x, y, paint, font);\n }\n);\n\nexport const Text = (props: AnimatedProps<TextProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nText.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
1
+ {"version":3,"sources":["Text.tsx"],"names":["React","createDrawing","onDraw","canvas","paint","text","x","y","fontDef","font","drawText","Text","props","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAOA,SAASC,aAAT,QAA8B,qBAA9B;AASA,MAAMC,MAAM,GAAGD,aAAa,CAC1B,iBAAmD;AAAA,MAAlD;AAAEE,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAkD;AAAA,MAA/B;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,CAAR;AAAWC,IAAAA,CAAX;AAAc,OAAGC;AAAjB,GAA+B;AACjD,QAAM;AAAEC,IAAAA;AAAF,MAAWD,OAAjB;AACAL,EAAAA,MAAM,CAACO,QAAP,CAAgBL,IAAhB,EAAsBC,CAAtB,EAAyBC,CAAzB,EAA4BH,KAA5B,EAAmCK,IAAnC;AACD,CAJyB,CAA5B;AAOA,OAAO,MAAME,IAAI,GAAIC,KAAD,IAAqC;AACvD,sBAAO;AAAW,IAAA,MAAM,EAAEV;AAAnB,KAA+BU,KAA/B,EAAP;AACD,CAFM;AAIPD,IAAI,CAACE,YAAL,GAAoB;AAClBP,EAAAA,CAAC,EAAE,CADe;AAElBC,EAAAA,CAAC,EAAE;AAFe,CAApB","sourcesContent":["import React from \"react\";\n\nimport type {\n CustomPaintProps,\n AnimatedProps,\n FontDef,\n} from \"../../processors\";\nimport { createDrawing } from \"../../nodes/Drawing\";\n\ntype TextProps = CustomPaintProps &\n FontDef & {\n text: string;\n x: number;\n y: number;\n };\n\nconst onDraw = createDrawing<TextProps>(\n ({ canvas, paint }, { text, x, y, ...fontDef }) => {\n const { font } = fontDef;\n canvas.drawText(text, x, y, paint, font);\n }\n);\n\nexport const Text = (props: AnimatedProps<TextProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nText.defaultProps = {\n x: 0,\n y: 0,\n};\n"]}
@@ -2,12 +2,10 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React from "react";
4
4
  import { createDrawing } from "../../nodes";
5
- import { processFont } from "../../processors/Font";
6
5
  const onDraw = createDrawing((_ref, _ref2) => {
7
6
  let {
8
7
  canvas,
9
8
  paint,
10
- fontMgr,
11
9
  Skia
12
10
  } = _ref;
13
11
  let {
@@ -22,7 +20,9 @@ const onDraw = createDrawing((_ref, _ref2) => {
22
20
  throw new Error("Invalid path: " + pathDef);
23
21
  }
24
22
 
25
- const font = processFont(Skia, fontMgr, fontDef);
23
+ const {
24
+ font
25
+ } = fontDef;
26
26
  const ids = font.getGlyphIDs(text);
27
27
  const widths = font.getGlyphWidths(ids, paint);
28
28
  const rsx = [];