@shopify/react-native-skia 0.1.138 → 0.1.141
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +5 -1
- package/android/build.gradle +3 -1
- package/cpp/api/JsiSkApi.h +0 -4
- package/cpp/api/JsiSkFont.h +0 -19
- package/lib/commonjs/mock/index.js +0 -4
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +5 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
- package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Text.js +4 -6
- package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
- package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
- package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -27
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/skia/core/Data.js +4 -5
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Image.js +4 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.js +3 -1
- package/lib/commonjs/skia/core/SVG.js.map +1 -1
- package/lib/commonjs/skia/core/Typeface.js +4 -1
- package/lib/commonjs/skia/core/Typeface.js.map +1 -1
- package/lib/commonjs/skia/core/index.js +0 -26
- package/lib/commonjs/skia/core/index.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.js +0 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/types/index.js +0 -13
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +53 -33
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/views/useTouchHandler.js +13 -15
- package/lib/commonjs/views/useTouchHandler.js.map +1 -1
- package/lib/module/mock/index.js +0 -4
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +5 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/text/Glyphs.js +4 -5
- package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/module/renderer/components/text/Text.js +4 -5
- package/lib/module/renderer/components/text/Text.js.map +1 -1
- package/lib/module/renderer/components/text/TextPath.js +3 -3
- package/lib/module/renderer/components/text/TextPath.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +0 -23
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/skia/core/Data.js +4 -5
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Image.js +2 -1
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/core/SVG.js +2 -1
- package/lib/module/skia/core/SVG.js.map +1 -1
- package/lib/module/skia/core/Typeface.js +2 -1
- package/lib/module/skia/core/Typeface.js.map +1 -1
- package/lib/module/skia/core/index.js +0 -2
- package/lib/module/skia/core/index.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.js +0 -1
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +0 -6
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -2
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +0 -4
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +53 -34
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/views/useTouchHandler.js +12 -14
- package/lib/module/views/useTouchHandler.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
- package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
- package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
- package/lib/typescript/src/skia/core/index.d.ts +0 -2
- package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
- package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +5 -5
- package/package.json +12 -7
- package/src/mock/index.ts +0 -4
- package/src/renderer/Canvas.tsx +5 -8
- package/src/renderer/DrawingContext.ts +1 -2
- package/src/renderer/components/text/Glyphs.tsx +2 -6
- package/src/renderer/components/text/Text.tsx +2 -3
- package/src/renderer/components/text/TextPath.tsx +2 -3
- package/src/renderer/processors/Font.ts +2 -25
- package/src/skia/core/Data.ts +8 -5
- package/src/skia/core/Image.ts +3 -1
- package/src/skia/core/SVG.ts +3 -1
- package/src/skia/core/Typeface.ts +4 -6
- package/src/skia/core/index.ts +0 -2
- package/src/skia/types/Font/Font.ts +0 -13
- package/src/skia/types/Image/ImageFactory.ts +0 -1
- package/src/skia/types/Path/Path.ts +0 -1
- package/src/skia/types/Skia.ts +0 -2
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkFont.ts +0 -9
- package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
- package/src/skia/web/JsiSkia.ts +0 -2
- package/src/values/hooks/useComputedValue.ts +0 -5
- package/src/views/SkiaView.web.tsx +41 -46
- package/src/views/useTouchHandler.ts +15 -19
- package/android/README.md +0 -14
- package/cpp/api/JsiSkFontMgr.h +0 -84
- package/cpp/api/JsiSkFontMgrFactory.h +0 -48
- package/cpp/skia/include/third_party/skcms/LICENSE +0 -29
- package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
- package/cpp/skia/readme.txt +0 -1
- package/lib/commonjs/skia/core/Paint.js +0 -28
- package/lib/commonjs/skia/core/Paint.js.map +0 -1
- package/lib/commonjs/skia/core/Path.js +0 -72
- package/lib/commonjs/skia/core/Path.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
- package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/module/skia/core/Paint.js +0 -17
- package/lib/module/skia/core/Paint.js.map +0 -1
- package/lib/module/skia/core/Path.js +0 -53
- package/lib/module/skia/core/Path.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/module/skia/types/FontMgr/index.js +0 -3
- package/lib/module/skia/types/FontMgr/index.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
- package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
- package/lib/typescript/src/skia/core/Path.d.ts +0 -21
- package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
- package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
- package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
- package/src/skia/core/Paint.ts +0 -22
- package/src/skia/core/Path.ts +0 -60
- package/src/skia/types/FontMgr/FontMgr.ts +0 -24
- package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
- package/src/skia/types/FontMgr/index.ts +0 -2
- package/src/skia/web/JsiSkFontMgr.ts +0 -38
- package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
@@ -21,30 +21,29 @@ 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,
|
24
|
+
var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouch$x, _prevTouch$y, _prevVelocityRef$curr, _prevVelocityRef$curr2, _prevVelocityRef$curr3, _prevVelocityRef$curr4;
|
25
25
|
|
26
26
|
if (!multiTouch && i > 0) {
|
27
27
|
break;
|
28
28
|
}
|
29
29
|
|
30
|
-
const touch = touches[i];
|
30
|
+
const touch = touches[i];
|
31
|
+
const prevTouch = prevTouchInfoRef.current[touch.id]; // Calculate the velocity from the previous touch.
|
31
32
|
|
32
33
|
const timeDiffseconds = touch.timestamp - ((_prevTouchInfoRef$cur = (_prevTouchInfoRef$cur2 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur2 === void 0 ? void 0 : _prevTouchInfoRef$cur2.timestamp) !== null && _prevTouchInfoRef$cur !== void 0 ? _prevTouchInfoRef$cur : touch.timestamp);
|
33
|
-
const distX = touch.x - ((
|
34
|
-
const distY = touch.y - ((
|
35
|
-
|
36
|
-
if (touch.type !== _types.TouchType.Start && touch.type !== _types.TouchType.End && touch.type !== _types.TouchType.Cancelled) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
};
|
42
|
-
}
|
34
|
+
const distX = touch.x - ((_prevTouch$x = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.x) !== null && _prevTouch$x !== void 0 ? _prevTouch$x : touch.x);
|
35
|
+
const distY = touch.y - ((_prevTouch$y = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.y) !== null && _prevTouch$y !== void 0 ? _prevTouch$y : touch.y);
|
36
|
+
|
37
|
+
if (touch.type !== _types.TouchType.Start && touch.type !== _types.TouchType.End && touch.type !== _types.TouchType.Cancelled && timeDiffseconds > 0) {
|
38
|
+
prevVelocityRef.current[touch.id] = {
|
39
|
+
x: distX / timeDiffseconds / _reactNative.PixelRatio.get(),
|
40
|
+
y: distY / timeDiffseconds / _reactNative.PixelRatio.get()
|
41
|
+
};
|
43
42
|
}
|
44
43
|
|
45
44
|
const extendedTouchInfo = { ...touch,
|
46
|
-
velocityX: (_prevVelocityRef$curr = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$
|
47
|
-
velocityY: (_prevVelocityRef$
|
45
|
+
velocityX: (_prevVelocityRef$curr = (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.x) !== null && _prevVelocityRef$curr !== void 0 ? _prevVelocityRef$curr : 0,
|
46
|
+
velocityY: (_prevVelocityRef$curr3 = (_prevVelocityRef$curr4 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr4 === void 0 ? void 0 : _prevVelocityRef$curr4.y) !== null && _prevVelocityRef$curr3 !== void 0 ? _prevVelocityRef$curr3 : 0
|
48
47
|
}; // Save previous touch
|
49
48
|
|
50
49
|
prevTouchInfoRef.current[touch.id] = touch;
|
@@ -55,7 +54,6 @@ const useInternalTouchHandler = function (handlers) {
|
|
55
54
|
} else if (touch.type === _types.TouchType.Active) {
|
56
55
|
handlers.onActive && handlers.onActive(extendedTouchInfo);
|
57
56
|
} else {
|
58
|
-
handlers.onActive && handlers.onActive(extendedTouchInfo);
|
59
57
|
handlers.onEnd && handlers.onEnd(extendedTouchInfo);
|
60
58
|
}
|
61
59
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTouchHandler.ts"],"names":["useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","
|
1
|
+
{"version":3,"sources":["useTouchHandler.ts"],"names":["useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","TouchType","Start","End","Cancelled","PixelRatio","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":";;;;;;;AACA;;AACA;;AAUA;;AAEA,MAAMA,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;AAAA,MAFjBC,IAEiB,uEAFM,EAEN;AAAA,MADjBC,UACiB,uEADJ,KACI;AACjB,QAAMC,gBAAgB,GAAG,mBAAiD,EAAjD,CAAzB;AACA,QAAMC,eAAe,GAAG,mBAA8C,EAA9C,CAAxB;AAEA,SAAO,wBAAaC,OAAD,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;;;AACO,MAAMkC,oBAAoB,GAAG,UAClCnC,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 { Vector } from \"../skia/types\";\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 | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\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 const prevTouch = prevTouchInfoRef.current[touch.id];\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 = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\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.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"]}
|
package/lib/module/mock/index.js
CHANGED
@@ -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","
|
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,MAA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cAlDC;AAmDJ,KAAGC,aAnDC;AAoDJ,KAAGC,iBApDC;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
|
-
|
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","
|
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,CAAkC;AAChCC,EAAAA,UAAU,EAAE,CADoB;AAEhCC,EAAAA,OAAO,EAAE,OAFuB;AAGhCC,EAAAA,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;AAC7ER,EAAAA,cAAc,CAACS,eAAf,CAA+BH,OAA/B,EAAwCC,IAAxC,EAA8C,IAA9C,EAAoD,MAAM;AACxDZ,IAAAA,SAAS,CAAC,iBAAD,CAAT;AAEAa,IAAAA,SAAS,CAACE,MAAV,CAAiBC,SAAjB;AACD,GAJD;AAKD,CAND;;AAQA,OAAO,MAAMC,YAAY,GAAG,MAAMxB,MAAM,CAAW,IAAX,CAAjC;AAQP,OAAO,MAAMyB,MAAM,gBAAG1B,UAAU,CAC9B,OAA4C2B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AAA,SAAS,CAACE,MAAV,CAAiBkC,WAAjB;AACD,OAFD;AAGD,KAJD;AAKD,GANQ,EAMN,CAACpC,SAAD,EAAYD,IAAZ,CANM,CAAT;AAQA,sBACE,oBAAC,QAAD;AACE,IAAA,GAAG,EAAEiB,GADP;AAEE,IAAA,KAAK,EAAER,KAFT;AAGE,IAAA,MAAM,EAAEe,MAHV;AAIE,IAAA,IAAI,EAAEd,IAJR;AAKE,IAAA,KAAK,EAAEvB;AALT,IADF;AASD,CA3E6B,CAAzB;AA8EP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAM+B,eAAe,GAAG,YAEnB;AAAA,oCADAoB,IACA;AADAA,IAAAA,IACA;AAAA;;AACH,QAAMC,SAAS,GAAGhE,KAAK,CAACM,MAAN,CAAgB,IAAhB,CAAlB;AACAN,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB8D,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 { 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
|
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","
|
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
|
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","
|
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
|
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 = [];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["TextPath.tsx"],"names":["React","createDrawing","
|
1
|
+
{"version":3,"sources":["TextPath.tsx"],"names":["React","createDrawing","onDraw","canvas","paint","Skia","text","initialOffset","path","pathDef","fontDef","Path","MakeFromSVGString","Error","font","ids","getGlyphIDs","widths","getGlyphWidths","rsx","meas","ContourMeasureIter","cont","next","dist","i","length","width","substring","px","py","tx","ty","getPosTan","adjustedX","adjustedY","push","RSXform","blob","TextBlob","MakeFromRSXform","drawTextBlob","TextPath","props","defaultProps"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,aAAT,QAA8B,aAA9B;AAWA,MAAMC,MAAM,GAAGD,aAAa,CAC1B,iBAGK;AAAA,MAFH;AAAEE,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA;AAAjB,GAEG;AAAA,MADH;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,aAAR;AAAuBC,IAAAA,IAAI,EA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,EAAF;AAAMC,MAAAA,EAAN;AAAUC,MAAAA,EAAV;AAAcC,MAAAA;AAAd,QAAqBV,IAAI,CAACW,SAAL,CAAeT,IAAf,CAA3B;AACA,UAAMU,SAAS,GAAGL,EAAE,GAAIF,KAAK,GAAG,CAAT,GAAcI,EAArC;AACA,UAAMI,SAAS,GAAGL,EAAE,GAAIH,KAAK,GAAG,CAAT,GAAcK,EAArC;AACAb,IAAAA,GAAG,CAACiB,IAAJ,CAAS/B,IAAI,CAACgC,OAAL,CAAaN,EAAb,EAAiBC,EAAjB,EAAqBE,SAArB,EAAgCC,SAAhC,CAAT;AACAX,IAAAA,IAAI,IAAIG,KAAK,GAAG,CAAhB;AACD;;AACD,QAAMW,IAAI,GAAGjC,IAAI,CAACkC,QAAL,CAAcC,eAAd,CAA8BlC,IAA9B,EAAoCa,GAApC,EAAyCL,IAAzC,CAAb;AACAX,EAAAA,MAAM,CAACsC,YAAP,CAAoBH,IAApB,EAA0B,CAA1B,EAA6B,CAA7B,EAAgClC,KAAhC;AACD,CA3CyB,CAA5B;AA8CA,OAAO,MAAMsC,QAAQ,GAAIC,KAAD,IAAyC;AAC/D,sBAAO;AAAW,IAAA,MAAM,EAAEzC;AAAnB,KAA+ByC,KAA/B,EAAP;AACD,CAFM;AAIPD,QAAQ,CAACE,YAAT,GAAwB;AACtBrC,EAAAA,aAAa,EAAE;AADO,CAAxB","sourcesContent":["import React from \"react\";\n\nimport type { CustomPaintProps, AnimatedProps } from \"../../processors\";\nimport { createDrawing } from \"../../nodes\";\nimport type { SkPath, SkRSXform } from \"../../../skia/types\";\nimport type { FontDef } from \"../../processors/Font\";\n\nexport type TextPathProps = CustomPaintProps &\n FontDef & {\n text: string;\n path: SkPath | string;\n initialOffset: number;\n };\n\nconst onDraw = createDrawing<TextPathProps>(\n (\n { canvas, paint, Skia },\n { text, initialOffset, path: pathDef, ...fontDef }\n ) => {\n const path =\n typeof pathDef === \"string\"\n ? Skia.Path.MakeFromSVGString(pathDef)\n : pathDef;\n if (path === null) {\n throw new Error(\"Invalid path: \" + pathDef);\n }\n const { font } = fontDef;\n const ids = font.getGlyphIDs(text);\n const widths = font.getGlyphWidths(ids, paint);\n const rsx: SkRSXform[] = [];\n const meas = Skia.ContourMeasureIter(path, false, 1);\n let cont = meas.next();\n let dist = initialOffset;\n for (let i = 0; i < text.length && cont; i++) {\n const width = widths[i];\n dist += width / 2;\n if (dist > cont.length()) {\n // jump to next contour\n cont = meas.next();\n if (!cont) {\n // We have come to the end of the path - terminate the string\n // right here.\n text = text.substring(0, i);\n break;\n }\n dist = width / 2;\n }\n // Gives us the (x, y) coordinates as well as the cos/sin of the tangent\n // line at that position.\n const { px, py, tx, ty } = cont.getPosTan(dist);\n const adjustedX = px - (width / 2) * tx;\n const adjustedY = py - (width / 2) * ty;\n rsx.push(Skia.RSXform(tx, ty, adjustedX, adjustedY));\n dist += width / 2;\n }\n const blob = Skia.TextBlob.MakeFromRSXform(text, rsx, font);\n canvas.drawTextBlob(blob, 0, 0, paint);\n }\n);\n\nexport const TextPath = (props: AnimatedProps<TextPathProps>) => {\n return <skDrawing onDraw={onDraw} {...props} />;\n};\n\nTextPath.defaultProps = {\n initialOffset: 0,\n};\n"]}
|
@@ -1,27 +1,4 @@
|
|
1
1
|
export const isFont = fontDef => // We have an issue to check property existence on JSI backed instances
|
2
2
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3
3
|
fontDef.font !== undefined;
|
4
|
-
export const processFont = (Skia, fontMgr, fontDef) => {
|
5
|
-
let selectedFont;
|
6
|
-
|
7
|
-
if (isFont(fontDef)) {
|
8
|
-
selectedFont = fontDef.font;
|
9
|
-
} else {
|
10
|
-
console.warn( // eslint-disable-next-line max-len
|
11
|
-
"Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts");
|
12
|
-
const {
|
13
|
-
familyName,
|
14
|
-
size
|
15
|
-
} = fontDef;
|
16
|
-
const typeface = fontMgr.matchFamilyStyle(familyName);
|
17
|
-
|
18
|
-
if (typeface === null) {
|
19
|
-
throw new Error(`No typeface found for ${familyName}`);
|
20
|
-
}
|
21
|
-
|
22
|
-
selectedFont = Skia.Font(typeface, size);
|
23
|
-
}
|
24
|
-
|
25
|
-
return selectedFont;
|
26
|
-
};
|
27
4
|
//# sourceMappingURL=Font.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Font.ts"],"names":["isFont","fontDef","font","undefined"
|
1
|
+
{"version":3,"sources":["Font.ts"],"names":["isFont","fontDef","font","undefined"],"mappings":"AAIA,OAAO,MAAMA,MAAM,GAAIC,OAAD,IACpB;AACA;AACCA,OAAD,CAAiBC,IAAjB,KAA0BC,SAHrB","sourcesContent":["import type { SkFont } from \"../../skia/types\";\n\nexport type FontDef = { font: SkFont };\n\nexport const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (fontDef as any).font !== undefined;\n"]}
|
@@ -19,15 +19,14 @@ const factoryWrapper = (data2, factory, onError) => {
|
|
19
19
|
|
20
20
|
const loadDataCollection = (sources, factory, onError) => Promise.all(sources.map(source => loadData(source, factory, onError)));
|
21
21
|
|
22
|
-
const loadData =
|
22
|
+
const loadData = (source, factory, onError) => {
|
23
23
|
if (source === null) {
|
24
|
-
return null;
|
24
|
+
return new Promise(resolve => resolve(null));
|
25
25
|
} else if (source instanceof Uint8Array) {
|
26
|
-
return factoryWrapper(Skia.Data.fromBytes(source), factory, onError);
|
26
|
+
return new Promise(resolve => resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError)));
|
27
27
|
} else {
|
28
28
|
const uri = typeof source === "string" ? source : resolveAsset(source);
|
29
|
-
|
30
|
-
return factoryWrapper(d, factory, onError);
|
29
|
+
return Skia.Data.fromURI(uri).then(d => factoryWrapper(d, factory, onError));
|
31
30
|
}
|
32
31
|
};
|
33
32
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Data.ts"],"names":["useRef","useEffect","useState","Image","Platform","Skia","resolveAsset","source","OS","default","resolveAssetSource","uri","factoryWrapper","data2","factory","onError","factoryResult","Error","loadDataCollection","sources","Promise","all","map","loadData","Uint8Array","Data","fromBytes","
|
1
|
+
{"version":3,"sources":["Data.ts"],"names":["useRef","useEffect","useState","Image","Platform","Skia","resolveAsset","source","OS","default","resolveAssetSource","uri","factoryWrapper","data2","factory","onError","factoryResult","Error","loadDataCollection","sources","Promise","all","map","loadData","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","deps","data","setData","prevSourceRef","current","useDataCollection","useRawData","identity","useData"],"mappings":"AACA,SAASA,MAAT,EAAiBC,SAAjB,EAA4BC,QAA5B,QAA4C,OAA5C;AACA,SAASC,KAAT,EAAgBC,QAAhB,QAAgC,cAAhC;AAEA,SAASC,IAAT,QAAqB,SAArB;;AAGA,MAAMC,YAAY,GAAIC,MAAD,IAAwC;AAC3D,SAAOH,QAAQ,CAACI,EAAT,KAAgB,KAAhB,GACHD,MAAM,CAACE,OADJ,GAEHN,KAAK,CAACO,kBAAN,CAAyBH,MAAzB,EAAiCI,GAFrC;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB,EAA4B;AAC1BD,IAAAA,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;AACA,WAAO,IAAP;AACD,GAHD,MAGO;AACL,WAAOD,aAAP;AACD;AACF,CAZD;;AAcA,MAAME,kBAAkB,GAAG,CACzBC,OADyB,EAEzBL,OAFyB,EAGzBC,OAHyB,KAKzBK,OAAO,CAACC,GAAR,CAAYF,OAAO,CAACG,GAAR,CAAaf,MAAD,IAAYgB,QAAQ,CAAChB,MAAD,EAASO,OAAT,EAAkBC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T;AASA,SAAOC,IAAP;AACD,CAjBD;;AAmBA,OAAO,MAAMI,iBAAiB,GAAG,CAC/BnB,OAD+B,EAE/BL,OAF+B,EAG/BC,OAH+B,EAI/BkB,IAJ+B,KAM/BF,UAAU,CACRZ,OADQ,EAER,MAAMD,kBAAkB,CAACC,OAAD,EAAUL,OAAV,EAAmBC,OAAnB,CAFhB,EAGRkB,IAHQ,CANL;AAYP,OAAO,MAAMM,UAAU,GAAG,CACxBhC,MADwB,EAExBO,OAFwB,EAGxBC,OAHwB,EAIxBkB,IAJwB,KAKrBF,UAAU,CAACxB,MAAD,EAAS,MAAMgB,QAAQ,CAAChB,MAAD,EAASO,OAAT,EAAkBC,OAAlB,CAAvB,EAAmDkB,IAAnD,CALR;;AAOP,MAAMO,QAAQ,GAAIN,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMO,OAAO,GAAG,CACrBlC,MADqB,EAErBQ,OAFqB,EAGrBkB,IAHqB,KAIlBM,UAAU,CAAChC,MAAD,EAASiC,QAAT,EAAmBzB,OAAnB,EAA4BkB,IAA5B,CAJR","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useRef, useEffect, useState } from \"react\";\nimport { Image, Platform } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSource } from \"../types\";\n\nconst resolveAsset = (source: ReturnType<typeof require>) => {\n return Platform.OS === \"web\"\n ? source.default\n : Image.resolveAssetSource(source).uri;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadDataCollection = <T>(\n sources: DataSource[],\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<(T | null)[]> =>\n Promise.all(sources.map((source) => loadData(source, factory, onError)));\n\nconst loadData = <T>(\n source: DataSource,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\n\ntype Source = DataSource | null | undefined;\n\nconst useLoading = <T>(\n source: Source,\n loader: () => Promise<T | null>,\n deps: DependencyList = []\n) => {\n const [data, setData] = useState<T | null>(null);\n const prevSourceRef = useRef<Source>();\n useEffect(() => {\n if (prevSourceRef.current !== source) {\n prevSourceRef.current = source;\n loader().then(setData);\n } else {\n setData(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n return data;\n};\n\nexport const useDataCollection = <T>(\n sources: DataSource[],\n factory: (data: SkData) => T,\n onError?: (err: Error) => void,\n deps?: DependencyList\n) =>\n useLoading(\n sources,\n () => loadDataCollection(sources, factory, onError),\n deps\n );\n\nexport const useRawData = <T>(\n source: DataSource | null | undefined,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void,\n deps?: DependencyList\n) => useLoading(source, () => loadData(source, factory, onError), deps);\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSource | null | undefined,\n onError?: (err: Error) => void,\n deps?: DependencyList\n) => useRawData(source, identity, onError, deps);\n"]}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
2
|
import { useRawData } from "./Data";
|
3
|
+
const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
|
3
4
|
/**
|
4
5
|
* Returns a Skia Image object
|
5
6
|
* */
|
6
7
|
|
7
|
-
export const useImage = (source, onError) => useRawData(source,
|
8
|
+
export const useImage = (source, onError) => useRawData(source, imgFactory, onError);
|
8
9
|
//# sourceMappingURL=Image.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Image.ts"],"names":["Skia","useRawData","
|
1
|
+
{"version":3,"sources":["Image.ts"],"names":["Skia","useRawData","imgFactory","Image","MakeImageFromEncoded","bind","useImage","source","onError"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,UAAU,GAAGF,IAAI,CAACG,KAAL,CAAWC,oBAAX,CAAgCC,IAAhC,CAAqCL,IAAI,CAACG,KAA1C,CAAnB;AAEA;AACA;AACA;;AACA,OAAO,MAAMG,QAAQ,GAAG,CACtBC,MADsB,EAEtBC,OAFsB,KAGnBP,UAAU,CAACM,MAAD,EAASL,UAAT,EAAqBM,OAArB,CAHR","sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSource } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);\n\n/**\n * Returns a Skia Image object\n * */\nexport const useImage = (\n source: DataSource | null | undefined,\n onError?: (err: Error) => void\n) => useRawData(source, imgFactory, onError);\n"]}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
2
|
import { useRawData } from "./Data";
|
3
|
-
|
3
|
+
const svgFactory = Skia.SVG.MakeFromData.bind(Skia.SVG);
|
4
|
+
export const useSVG = (source, onError) => useRawData(source, svgFactory, onError);
|
4
5
|
//# sourceMappingURL=SVG.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["SVG.ts"],"names":["Skia","useRawData","
|
1
|
+
{"version":3,"sources":["SVG.ts"],"names":["Skia","useRawData","svgFactory","SVG","MakeFromData","bind","useSVG","source","onError"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,UAAU,GAAGF,IAAI,CAACG,GAAL,CAASC,YAAT,CAAsBC,IAAtB,CAA2BL,IAAI,CAACG,GAAhC,CAAnB;AAEA,OAAO,MAAMG,MAAM,GAAG,CACpBC,MADoB,EAEpBC,OAFoB,KAGjBP,UAAU,CAACM,MAAD,EAASL,UAAT,EAAqBM,OAArB,CAHR","sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSource } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst svgFactory = Skia.SVG.MakeFromData.bind(Skia.SVG);\n\nexport const useSVG = (\n source: DataSource | null | undefined,\n onError?: (err: Error) => void\n) => useRawData(source, svgFactory, onError);\n"]}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
2
|
import { useRawData } from "./Data";
|
3
|
+
const tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);
|
3
4
|
/**
|
4
5
|
* Returns a Skia Typeface object
|
5
6
|
* */
|
6
7
|
|
7
|
-
export const useTypeface = (source, onError) => useRawData(source,
|
8
|
+
export const useTypeface = (source, onError) => useRawData(source, tfFactory, onError);
|
8
9
|
//# sourceMappingURL=Typeface.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Typeface.ts"],"names":["Skia","useRawData","
|
1
|
+
{"version":3,"sources":["Typeface.ts"],"names":["Skia","useRawData","tfFactory","Typeface","MakeFreeTypeFaceFromData","bind","useTypeface","source","onError"],"mappings":"AAAA,SAASA,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,SAAS,GAAGF,IAAI,CAACG,QAAL,CAAcC,wBAAd,CAAuCC,IAAvC,CAA4CL,IAAI,CAACG,QAAjD,CAAlB;AAEA;AACA;AACA;;AACA,OAAO,MAAMG,WAAW,GAAG,CACzBC,MADyB,EAEzBC,OAFyB,KAGtBP,UAAU,CAACM,MAAD,EAASL,SAAT,EAAoBM,OAApB,CAHR","sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSource } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);\n\n/**\n * Returns a Skia Typeface object\n * */\nexport const useTypeface = (\n source: DataSource | null | undefined,\n onError?: (err: Error) => void\n) => useRawData(source, tfFactory, onError);\n"]}
|
@@ -4,10 +4,8 @@ export * from "./Typeface";
|
|
4
4
|
export * from "./Image";
|
5
5
|
export * from "./Picture";
|
6
6
|
export * from "./SVG";
|
7
|
-
export * from "./Path";
|
8
7
|
export * from "./Vector";
|
9
8
|
export * from "./Rect";
|
10
9
|
export * from "./RRect";
|
11
10
|
export * from "./Matrix";
|
12
|
-
export * from "./Paint";
|
13
11
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,YAAd;AACA,cAAc,SAAd;AACA,cAAc,WAAd;AACA,cAAc,OAAd;AACA,cAAc,
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,YAAd;AACA,cAAc,SAAd;AACA,cAAc,WAAd;AACA,cAAc,OAAd;AACA,cAAc,UAAd;AACA,cAAc,QAAd;AACA,cAAc,SAAd;AACA,cAAc,UAAd","sourcesContent":["export * from \"./Data\";\nexport * from \"./Font\";\nexport * from \"./Typeface\";\nexport * from \"./Image\";\nexport * from \"./Picture\";\nexport * from \"./SVG\";\nexport * from \"./Vector\";\nexport * from \"./Rect\";\nexport * from \"./RRect\";\nexport * from \"./Matrix\";\n"]}
|