@shopify/react-native-skia 2.6.9 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/cpp/jni/include/JniSkiaBaseView.h +6 -4
- package/android/cpp/jni/include/JniSkiaPictureView.h +8 -6
- package/android/cpp/rnskia-android/OpenGLContext.h +10 -1
- package/android/cpp/rnskia-android/RNSkAndroidView.h +8 -8
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +9 -5
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +4 -2
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +48 -12
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +5 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +2 -2
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +11 -7
- package/apple/MetalContext.h +7 -6
- package/apple/MetalLayerColorSpace.mm +39 -0
- package/apple/MetalLayerColorSpaceUtils.h +34 -0
- package/apple/MetalWindowContext.h +3 -1
- package/apple/MetalWindowContext.mm +9 -8
- package/apple/RNSkAppleView.h +6 -0
- package/apple/RNSkMetalCanvasProvider.h +2 -0
- package/apple/RNSkMetalCanvasProvider.mm +15 -2
- package/apple/SkiaPictureView.mm +1 -0
- package/apple/SkiaPictureViewManager.mm +5 -0
- package/apple/SkiaUIView.h +1 -0
- package/apple/SkiaUIView.mm +9 -0
- package/cpp/api/JsiSkParagraph.h +114 -0
- package/cpp/api/JsiSkSurface.h +8 -2
- package/cpp/rnskia/RNDawnContext.h +4 -3
- package/cpp/rnskia/RNDawnUtils.h +25 -6
- package/cpp/rnskia/RNDawnWindowContext.h +44 -10
- package/cpp/rnskia/RNMetalLayerColorSpace.h +16 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +46 -24
- package/cpp/rnwgpu/SurfaceRegistry.h +10 -4
- package/lib/commonjs/Platform/Platform.web.js +2 -90
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.js +11 -2
- package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +10 -1
- package/lib/commonjs/renderer/Canvas.js +2 -0
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.web.js +4 -5
- package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
- package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/web/Host.js +7 -0
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +5 -0
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.js +6 -0
- package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +14 -3
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +2 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +1 -0
- package/lib/commonjs/sksg/Container.native.js +11 -0
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +1 -0
- package/lib/commonjs/sksg/Container.web.js +45 -3
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js +66 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js +26 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/Player.js +1 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +12 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +1 -0
- package/lib/commonjs/sksg/StaticContainer.js +27 -1
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js +32 -7
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +2 -0
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +279 -94
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/formats.d.ts +1 -0
- package/lib/commonjs/views/formats.js +28 -0
- package/lib/commonjs/views/formats.js.map +1 -0
- package/lib/commonjs/views/index.d.ts +1 -0
- package/lib/commonjs/views/index.js +11 -0
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +6 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +3 -91
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/external/reanimated/useVideoLoading.js +12 -2
- package/lib/module/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/module/mock/index.js +1 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +10 -1
- package/lib/module/renderer/Canvas.js +2 -0
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/core/SVG.web.js +4 -5
- package/lib/module/skia/core/SVG.web.js.map +1 -1
- package/lib/module/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/web/Host.js +7 -0
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +5 -0
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/module/skia/web/JsiSkParagraph.js +7 -1
- package/lib/module/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraphStyle.js +14 -3
- package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/module/skia/web/JsiSkSurface.js +2 -1
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +1 -0
- package/lib/module/sksg/Container.native.js +11 -0
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +1 -0
- package/lib/module/sksg/Container.web.js +46 -4
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/module/sksg/Recorder/FrameScope.js +59 -0
- package/lib/module/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/module/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js +19 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/module/sksg/Recorder/Player.js +1 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/module/sksg/Recorder/Recorder.js +10 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +1 -0
- package/lib/module/sksg/StaticContainer.js +28 -2
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/module/specs/NativeSkiaModule.web.js +32 -7
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -0
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +280 -95
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/formats.d.ts +1 -0
- package/lib/module/views/formats.js +22 -0
- package/lib/module/views/formats.js.map +1 -0
- package/lib/module/views/index.d.ts +1 -0
- package/lib/module/views/index.js +1 -0
- package/lib/module/views/index.js.map +1 -1
- package/lib/module/views/types.d.ts +6 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/Platform/Platform.web.d.ts +1 -2
- package/lib/typescript/lib/commonjs/mock/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +3 -3
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.d.ts +17 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +13 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/lib/commonjs/views/formats.d.ts +2 -0
- package/lib/typescript/lib/module/Platform/Platform.web.d.ts +1 -3
- package/lib/typescript/lib/module/mock/index.d.ts +2 -2
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +2 -1
- package/lib/typescript/lib/module/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +3 -3
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.native.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/lib/module/views/formats.d.ts +1 -0
- package/lib/typescript/lib/module/views/index.d.ts +1 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +10 -1
- package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/src/sksg/Container.native.d.ts +1 -0
- package/lib/typescript/src/sksg/Container.web.d.ts +1 -0
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/typescript/src/sksg/StaticContainer.d.ts +1 -0
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/formats.d.ts +1 -0
- package/lib/typescript/src/views/index.d.ts +1 -0
- package/lib/typescript/src/views/types.d.ts +6 -0
- package/package.json +4 -1
- package/react-native-skia.podspec +1 -0
- package/src/Platform/Platform.web.tsx +7 -99
- package/src/external/reanimated/useVideoLoading.ts +12 -2
- package/src/mock/index.ts +1 -0
- package/src/renderer/Canvas.tsx +11 -0
- package/src/skia/core/SVG.web.ts +5 -14
- package/src/skia/types/Paragraph/Paragraph.ts +67 -0
- package/src/skia/types/Surface/Surface.ts +5 -1
- package/src/skia/web/Host.ts +7 -0
- package/src/skia/web/JsiSkPaint.ts +5 -0
- package/src/skia/web/JsiSkParagraph.ts +9 -1
- package/src/skia/web/JsiSkParagraphStyle.ts +16 -2
- package/src/skia/web/JsiSkSurface.ts +2 -1
- package/src/sksg/Container.native.ts +12 -0
- package/src/sksg/Container.web.ts +43 -4
- package/src/sksg/Recorder/DrawingContext.ts +19 -6
- package/src/sksg/Recorder/FrameScope.native.ts +21 -0
- package/src/sksg/Recorder/FrameScope.ts +69 -0
- package/src/sksg/Recorder/Player.ts +1 -2
- package/src/sksg/Recorder/Recorder.ts +15 -1
- package/src/sksg/Recorder/commands/Drawing.ts +3 -3
- package/src/sksg/Recorder/commands/Shaders.ts +22 -16
- package/src/sksg/StaticContainer.ts +29 -2
- package/src/specs/NativeSkiaModule.web.ts +39 -7
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/SkiaPictureView.tsx +2 -0
- package/src/views/SkiaPictureView.web.tsx +318 -106
- package/src/views/formats.ts +21 -0
- package/src/views/index.ts +1 -0
- package/src/views/types.ts +7 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { Skia } from "../Skia";
|
|
3
|
+
import { Platform } from "../../Platform";
|
|
3
4
|
export const useSVG = (source, onError) => {
|
|
4
5
|
const [svg, setSVG] = useState(null);
|
|
5
6
|
if (source === null || source === undefined) {
|
|
@@ -10,12 +11,10 @@ export const useSVG = (source, onError) => {
|
|
|
10
11
|
let src;
|
|
11
12
|
if (typeof source === "string") {
|
|
12
13
|
src = source;
|
|
13
|
-
} else if (
|
|
14
|
-
|
|
15
|
-
} else if (typeof source === "object" && "uri" in source) {
|
|
16
|
-
src = source.uri;
|
|
14
|
+
} else if (source instanceof Uint8Array) {
|
|
15
|
+
throw new Error(`Invalid svg data source. Make sure that the source resolves to a string. Got: ${source}`);
|
|
17
16
|
} else {
|
|
18
|
-
|
|
17
|
+
src = Platform.resolveAsset(source);
|
|
19
18
|
}
|
|
20
19
|
const result = await fetch(src);
|
|
21
20
|
const svgStr = await result.text();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useState","Skia","useSVG","source","onError","svg","setSVG","undefined","Error","src","
|
|
1
|
+
{"version":3,"names":["useEffect","useState","Skia","Platform","useSVG","source","onError","svg","setSVG","undefined","Error","src","Uint8Array","resolveAsset","result","fetch","svgStr","text","newSvg","SVG","MakeFromString"],"sources":["SVG.web.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { DataSourceParam, SkSVG } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nexport const useSVG = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => {\n const [svg, setSVG] = useState<SkSVG | null>(null);\n if (source === null || source === undefined) {\n throw new Error(`Invalid svg data source. Got: ${source}`);\n }\n useEffect(() => {\n (async () => {\n let src: string;\n if (typeof source === \"string\") {\n src = source;\n } else if (source instanceof Uint8Array) {\n throw new Error(\n `Invalid svg data source. Make sure that the source resolves to a string. Got: ${source}`\n );\n } else {\n src = Platform.resolveAsset(source);\n }\n const result = await fetch(src);\n const svgStr = await result.text();\n const newSvg = Skia.SVG.MakeFromString(svgStr);\n setSVG(newSvg);\n if (newSvg === null && onError !== undefined) {\n onError(new Error(\"Failed to create SVG from source.\"));\n }\n })();\n }, [onError, source]);\n return svg;\n};\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAE3C,SAASC,IAAI,QAAQ,SAAS;AAE9B,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC,OAAO,MAAMC,MAAM,GAAGA,CACpBC,MAAuB,EACvBC,OAA8B,KAC3B;EACH,MAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGP,QAAQ,CAAe,IAAI,CAAC;EAClD,IAAII,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKI,SAAS,EAAE;IAC3C,MAAM,IAAIC,KAAK,CAAC,iCAAiCL,MAAM,EAAE,CAAC;EAC5D;EACAL,SAAS,CAAC,MAAM;IACd,CAAC,YAAY;MACX,IAAIW,GAAW;MACf,IAAI,OAAON,MAAM,KAAK,QAAQ,EAAE;QAC9BM,GAAG,GAAGN,MAAM;MACd,CAAC,MAAM,IAAIA,MAAM,YAAYO,UAAU,EAAE;QACvC,MAAM,IAAIF,KAAK,CACb,iFAAiFL,MAAM,EACzF,CAAC;MACH,CAAC,MAAM;QACLM,GAAG,GAAGR,QAAQ,CAACU,YAAY,CAACR,MAAM,CAAC;MACrC;MACA,MAAMS,MAAM,GAAG,MAAMC,KAAK,CAACJ,GAAG,CAAC;MAC/B,MAAMK,MAAM,GAAG,MAAMF,MAAM,CAACG,IAAI,CAAC,CAAC;MAClC,MAAMC,MAAM,GAAGhB,IAAI,CAACiB,GAAG,CAACC,cAAc,CAACJ,MAAM,CAAC;MAC9CR,MAAM,CAACU,MAAM,CAAC;MACd,IAAIA,MAAM,KAAK,IAAI,IAAIZ,OAAO,KAAKG,SAAS,EAAE;QAC5CH,OAAO,CAAC,IAAII,KAAK,CAAC,mCAAmC,CAAC,CAAC;MACzD;IACF,CAAC,EAAE,CAAC;EACN,CAAC,EAAE,CAACJ,OAAO,EAAED,MAAM,CAAC,CAAC;EACrB,OAAOE,GAAG;AACZ,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { SkCanvas } from "../Canvas";
|
|
2
|
+
import type { SkFont } from "../Font";
|
|
2
3
|
import type { SkJSIInstance } from "../JsiInstance";
|
|
4
|
+
import type { SkPath } from "../Path";
|
|
5
|
+
import type { SkPoint } from "../Point";
|
|
3
6
|
import type { SkRect } from "../Rect";
|
|
7
|
+
import type { SkSize } from "../Size";
|
|
4
8
|
import type { TextDirection } from "./ParagraphStyle";
|
|
5
9
|
export interface LineMetrics {
|
|
6
10
|
/** The index in the text buffer the line begins. */
|
|
@@ -36,6 +40,42 @@ export interface SkRectWithDirection {
|
|
|
36
40
|
rect: SkRect;
|
|
37
41
|
direction: TextDirection;
|
|
38
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Information about a run of glyphs passed to the visitor of
|
|
45
|
+
* `SkParagraph.extendedVisit`. All glyphs in a run share the same font: for
|
|
46
|
+
* text shaped through font fallback, each fallback font produces its own
|
|
47
|
+
* run(s).
|
|
48
|
+
*/
|
|
49
|
+
export interface ParagraphVisitorInfo {
|
|
50
|
+
/** The font used to shape this run (the resolved fallback font, if any). */
|
|
51
|
+
font: SkFont;
|
|
52
|
+
/** Origin of the run within the paragraph (baseline corrected). */
|
|
53
|
+
origin: SkPoint;
|
|
54
|
+
/** Advance of the run. */
|
|
55
|
+
advance: SkSize;
|
|
56
|
+
/** The glyph ids of the run. */
|
|
57
|
+
glyphs: number[];
|
|
58
|
+
/**
|
|
59
|
+
* The position of each glyph, relative to the run `origin`. Add `origin`
|
|
60
|
+
* to obtain paragraph coordinates: for a run shaped through font fallback,
|
|
61
|
+
* the run placement is carried by `origin`, not by the positions.
|
|
62
|
+
*/
|
|
63
|
+
positions: SkPoint[];
|
|
64
|
+
/**
|
|
65
|
+
* The tight ink bounds of each glyph, relative to the glyph's origin.
|
|
66
|
+
* Combine with `positions` to compute the exact painted bounds of the run.
|
|
67
|
+
*/
|
|
68
|
+
bounds: SkRect[];
|
|
69
|
+
/** The UTF-8 text index of the cluster each glyph belongs to. */
|
|
70
|
+
utf8Starts: number[];
|
|
71
|
+
/** Reserved flags (currently always 0). */
|
|
72
|
+
flags: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Visitor for `SkParagraph.extendedVisit`. Called once per run of glyphs;
|
|
76
|
+
* `info` is null to signal the end of a line.
|
|
77
|
+
*/
|
|
78
|
+
export type ParagraphExtendedVisitor = (lineNumber: number, info: ParagraphVisitorInfo | null) => void;
|
|
39
79
|
export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
|
|
40
80
|
/**
|
|
41
81
|
* Calculates the position of the the glyphs in the paragraph
|
|
@@ -106,4 +146,26 @@ export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
|
|
|
106
146
|
* to the paragraph.
|
|
107
147
|
*/
|
|
108
148
|
getRectsForPlaceholders(): SkRectWithDirection[];
|
|
149
|
+
/**
|
|
150
|
+
* Converts the glyphs of the given line into an SkPath, with all font
|
|
151
|
+
* fallbacks already applied. Use `computeTightBounds()` on the resulting
|
|
152
|
+
* path to measure the exact ink bounds of the rendered text (as opposed to
|
|
153
|
+
* the font-metrics based bounds returned by `getRectsForRange`).
|
|
154
|
+
* Note that color glyphs (e.g. emojis) cannot be converted to a path and
|
|
155
|
+
* are skipped. Returns null if the line number is out of bounds.
|
|
156
|
+
* This method requires the layout method to have been called first.
|
|
157
|
+
* Not implemented on React Native Web.
|
|
158
|
+
* @param lineNumber The line number (zero indexed, see `getLineMetrics`)
|
|
159
|
+
*/
|
|
160
|
+
getPath(lineNumber: number): SkPath | null;
|
|
161
|
+
/**
|
|
162
|
+
* Visits the laid out paragraph, calling the visitor once for every run of
|
|
163
|
+
* glyphs with the resolved font, glyph ids, positions and per-glyph tight
|
|
164
|
+
* ink bounds. The visitor is called with a null info to signal the end of
|
|
165
|
+
* each line. This exposes the exact layout that would be painted.
|
|
166
|
+
* This method requires the layout method to have been called first.
|
|
167
|
+
* Not implemented on React Native Web.
|
|
168
|
+
* @param visitor Called once per glyph run, and once per line end
|
|
169
|
+
*/
|
|
170
|
+
extendedVisit(visitor: ParagraphExtendedVisitor): void;
|
|
109
171
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["Paragraph.ts"],"sourcesContent":["import type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nimport type { TextDirection } from \"./ParagraphStyle\";\n\nexport interface LineMetrics {\n /** The index in the text buffer the line begins. */\n startIndex: number;\n /** The index in the text buffer the line ends. */\n endIndex: number;\n endExcludingWhitespaces: number;\n endIncludingNewline: number;\n /** True if the line ends in a hard break (e.g. newline) */\n isHardBreak: boolean;\n /**\n * The final computed ascent for the line. This can be impacted by\n * the strut, height, scaling, as well as outlying runs that are very tall.\n */\n ascent: number;\n /**\n * The final computed descent for the line. This can be impacted by\n * the strut, height, scaling, as well as outlying runs that are very tall.\n */\n descent: number;\n /** round(ascent + descent) */\n height: number;\n /** width of the line */\n width: number;\n /** The left edge of the line. The right edge can be obtained with `left + width` */\n left: number;\n /** The y position of the baseline for this line from the top of the paragraph. */\n baseline: number;\n /** Zero indexed line number. */\n lineNumber: number;\n}\n\nexport interface SkRectWithDirection {\n rect: SkRect;\n direction: TextDirection;\n}\n\nexport interface SkParagraph extends SkJSIInstance<\"Paragraph\"> {\n /**\n * Calculates the position of the the glyphs in the paragraph\n * @param width Max width of the paragraph\n */\n layout(width: number): void;\n /**\n * Paints the paragraph to the provded canvas\n * @param canvas Canvas to paint into\n * @param x X coordinate to paint at\n * @param y Y coordinate to paint at\n */\n paint(canvas: SkCanvas, x: number, y: number): void;\n /**\n * Returns the height of the paragraph. This method requires the layout\n * method to have been called first.\n */\n getHeight(): number;\n /**\n * Returns the max width of the paragraph. This method requires the layout\n * method to have been called first.\n */\n getMaxWidth(): number;\n /**\n * Returns the minimum intrinsic width of the paragraph.\n * The minimum intrinsic width is the width beyond which increasing the width of the paragraph\n * does not decrease the height. This is effectively the width at which the paragraph\n * can no longer wrap lines and is forced to overflow.\n * This method requires the layout method to have been called first.\n * @returns {number} The minimum intrinsic width of the paragraph.\n */\n getMinIntrinsicWidth(): number;\n /**\n * Returns the maximum intrinsic width of the paragraph.\n * The maximum intrinsic width is the width at which the paragraph can layout its content without line breaks,\n * meaning it's the width of the widest line or the widest word if the widest line is shorter than that.\n * This width represents the ideal width for the paragraph to display all content in a single line without overflow.\n * This method requires the layout method to have been called first.\n * @returns {number} The maximum intrinsic width of the paragraph.\n */\n getMaxIntrinsicWidth(): number;\n\n /**\n * Returns the width of the longest line in the paragraph.\n * This method requires the layout method to have been called first.\n */\n getLongestLine(): number;\n\n /**\n * Returns the index of the glyph at the given position. This method requires\n * the layout method to have been called first.\n * @param x X coordinate of the position\n * @param y Y coordinate of the position\n */\n getGlyphPositionAtCoordinate(x: number, y: number): number;\n /**\n * Returns the bounding boxes of the glyphs in the given range. This method\n * requires the layout method to have been called first.\n * @param start Start index of the range\n * @param end End index of the range\n */\n getRectsForRange(start: number, end: number): SkRect[];\n /**\n * Returns the bounding boxes for all lines in the paragraph. This method\n * requires the layout method to have been called first.\n */\n getLineMetrics(): LineMetrics[];\n /**\n * Returns a list of rects with direction info for the placeholders added\n * to the paragraph.\n */\n getRectsForPlaceholders(): SkRectWithDirection[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["Paragraph.ts"],"sourcesContent":["import type { SkCanvas } from \"../Canvas\";\nimport type { SkFont } from \"../Font\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkPath } from \"../Path\";\nimport type { SkPoint } from \"../Point\";\nimport type { SkRect } from \"../Rect\";\nimport type { SkSize } from \"../Size\";\n\nimport type { TextDirection } from \"./ParagraphStyle\";\n\nexport interface LineMetrics {\n /** The index in the text buffer the line begins. */\n startIndex: number;\n /** The index in the text buffer the line ends. */\n endIndex: number;\n endExcludingWhitespaces: number;\n endIncludingNewline: number;\n /** True if the line ends in a hard break (e.g. newline) */\n isHardBreak: boolean;\n /**\n * The final computed ascent for the line. This can be impacted by\n * the strut, height, scaling, as well as outlying runs that are very tall.\n */\n ascent: number;\n /**\n * The final computed descent for the line. This can be impacted by\n * the strut, height, scaling, as well as outlying runs that are very tall.\n */\n descent: number;\n /** round(ascent + descent) */\n height: number;\n /** width of the line */\n width: number;\n /** The left edge of the line. The right edge can be obtained with `left + width` */\n left: number;\n /** The y position of the baseline for this line from the top of the paragraph. */\n baseline: number;\n /** Zero indexed line number. */\n lineNumber: number;\n}\n\nexport interface SkRectWithDirection {\n rect: SkRect;\n direction: TextDirection;\n}\n\n/**\n * Information about a run of glyphs passed to the visitor of\n * `SkParagraph.extendedVisit`. All glyphs in a run share the same font: for\n * text shaped through font fallback, each fallback font produces its own\n * run(s).\n */\nexport interface ParagraphVisitorInfo {\n /** The font used to shape this run (the resolved fallback font, if any). */\n font: SkFont;\n /** Origin of the run within the paragraph (baseline corrected). */\n origin: SkPoint;\n /** Advance of the run. */\n advance: SkSize;\n /** The glyph ids of the run. */\n glyphs: number[];\n /**\n * The position of each glyph, relative to the run `origin`. Add `origin`\n * to obtain paragraph coordinates: for a run shaped through font fallback,\n * the run placement is carried by `origin`, not by the positions.\n */\n positions: SkPoint[];\n /**\n * The tight ink bounds of each glyph, relative to the glyph's origin.\n * Combine with `positions` to compute the exact painted bounds of the run.\n */\n bounds: SkRect[];\n /** The UTF-8 text index of the cluster each glyph belongs to. */\n utf8Starts: number[];\n /** Reserved flags (currently always 0). */\n flags: number;\n}\n\n/**\n * Visitor for `SkParagraph.extendedVisit`. Called once per run of glyphs;\n * `info` is null to signal the end of a line.\n */\nexport type ParagraphExtendedVisitor = (\n lineNumber: number,\n info: ParagraphVisitorInfo | null\n) => void;\n\nexport interface SkParagraph extends SkJSIInstance<\"Paragraph\"> {\n /**\n * Calculates the position of the the glyphs in the paragraph\n * @param width Max width of the paragraph\n */\n layout(width: number): void;\n /**\n * Paints the paragraph to the provded canvas\n * @param canvas Canvas to paint into\n * @param x X coordinate to paint at\n * @param y Y coordinate to paint at\n */\n paint(canvas: SkCanvas, x: number, y: number): void;\n /**\n * Returns the height of the paragraph. This method requires the layout\n * method to have been called first.\n */\n getHeight(): number;\n /**\n * Returns the max width of the paragraph. This method requires the layout\n * method to have been called first.\n */\n getMaxWidth(): number;\n /**\n * Returns the minimum intrinsic width of the paragraph.\n * The minimum intrinsic width is the width beyond which increasing the width of the paragraph\n * does not decrease the height. This is effectively the width at which the paragraph\n * can no longer wrap lines and is forced to overflow.\n * This method requires the layout method to have been called first.\n * @returns {number} The minimum intrinsic width of the paragraph.\n */\n getMinIntrinsicWidth(): number;\n /**\n * Returns the maximum intrinsic width of the paragraph.\n * The maximum intrinsic width is the width at which the paragraph can layout its content without line breaks,\n * meaning it's the width of the widest line or the widest word if the widest line is shorter than that.\n * This width represents the ideal width for the paragraph to display all content in a single line without overflow.\n * This method requires the layout method to have been called first.\n * @returns {number} The maximum intrinsic width of the paragraph.\n */\n getMaxIntrinsicWidth(): number;\n\n /**\n * Returns the width of the longest line in the paragraph.\n * This method requires the layout method to have been called first.\n */\n getLongestLine(): number;\n\n /**\n * Returns the index of the glyph at the given position. This method requires\n * the layout method to have been called first.\n * @param x X coordinate of the position\n * @param y Y coordinate of the position\n */\n getGlyphPositionAtCoordinate(x: number, y: number): number;\n /**\n * Returns the bounding boxes of the glyphs in the given range. This method\n * requires the layout method to have been called first.\n * @param start Start index of the range\n * @param end End index of the range\n */\n getRectsForRange(start: number, end: number): SkRect[];\n /**\n * Returns the bounding boxes for all lines in the paragraph. This method\n * requires the layout method to have been called first.\n */\n getLineMetrics(): LineMetrics[];\n /**\n * Returns a list of rects with direction info for the placeholders added\n * to the paragraph.\n */\n getRectsForPlaceholders(): SkRectWithDirection[];\n /**\n * Converts the glyphs of the given line into an SkPath, with all font\n * fallbacks already applied. Use `computeTightBounds()` on the resulting\n * path to measure the exact ink bounds of the rendered text (as opposed to\n * the font-metrics based bounds returned by `getRectsForRange`).\n * Note that color glyphs (e.g. emojis) cannot be converted to a path and\n * are skipped. Returns null if the line number is out of bounds.\n * This method requires the layout method to have been called first.\n * Not implemented on React Native Web.\n * @param lineNumber The line number (zero indexed, see `getLineMetrics`)\n */\n getPath(lineNumber: number): SkPath | null;\n /**\n * Visits the laid out paragraph, calling the visitor once for every run of\n * glyphs with the resolved font, glyph ids, positions and per-glyph tight\n * ink bounds. The visitor is called with a null info to signal the end of\n * each line. This exposes the exact layout that would be painted.\n * This method requires the layout method to have been called first.\n * Not implemented on React Native Web.\n * @param visitor Called once per glyph run, and once per line end\n */\n extendedVisit(visitor: ParagraphExtendedVisitor): void;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -35,8 +35,12 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
35
35
|
makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;
|
|
36
36
|
/**
|
|
37
37
|
* Make sure any queued draws are sent to the screen or the GPU.
|
|
38
|
+
* @param sync - When true, block until the GPU has finished executing the
|
|
39
|
+
* submitted work. Use this before reading the surface's texture from a native
|
|
40
|
+
* consumer on a different command queue (see {@link getNativeTextureUnstable}).
|
|
41
|
+
* Defaults to false.
|
|
38
42
|
*/
|
|
39
|
-
flush(): void;
|
|
43
|
+
flush(sync?: boolean): void;
|
|
40
44
|
/**
|
|
41
45
|
* Returns the possibly scaled width of the surface.
|
|
42
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /**\n * Returns the backend texture of the surface.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the surface is deleted\n * or draw operations are performed on the surface.\n * The returned object may be null if the surface does not have a backend texture.\n *\n * @return backend texture of the surface or null\n */\n getNativeTextureUnstable(): unknown;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n */\n flush(): void;\n\n /**\n * Returns the possibly scaled width of the surface.\n */\n width(): number;\n\n /**\n * Returns the possibly scaled height of the surface.\n */\n height(): number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["Surface.ts"],"sourcesContent":["import type { SkImage } from \"../Image\";\nimport type { SkCanvas } from \"../Canvas\";\nimport type { SkJSIInstance } from \"../JsiInstance\";\nimport type { SkRect } from \"../Rect\";\n\nexport interface SkSurface extends SkJSIInstance<\"Surface\"> {\n /** Returns Canvas that draws into the surface. Subsequent calls return the\n same Canvas. Canvas returned is managed and owned by Surface, and is\n deleted when Surface is deleted.\n\n @return drawing Canvas for Surface\n\n example: https://fiddle.skia.org/c/@Surface_getCanvas\n */\n getCanvas(): SkCanvas;\n\n /**\n * Returns the backend texture of the surface.\n * The returned object can be used to create a Skia Image object.\n * The returned object is backend specific and should be used with caution.\n * It is the caller's responsibility to ensure that the texture is not used after the surface is deleted\n * or draw operations are performed on the surface.\n * The returned object may be null if the surface does not have a backend texture.\n *\n * @return backend texture of the surface or null\n */\n getNativeTextureUnstable(): unknown;\n\n /** Returns Image capturing Surface contents. Subsequent drawing to\n Surface contents are not captured.\n\n @param bounds A rectangle specifying the subset of the surface that\n is of interest.\n @return Image initialized with Surface contents\n\n example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot\n */\n makeImageSnapshot(bounds?: SkRect, outputImage?: SkImage): SkImage;\n\n /**\n * Make sure any queued draws are sent to the screen or the GPU.\n * @param sync - When true, block until the GPU has finished executing the\n * submitted work. Use this before reading the surface's texture from a native\n * consumer on a different command queue (see {@link getNativeTextureUnstable}).\n * Defaults to false.\n */\n flush(sync?: boolean): void;\n\n /**\n * Returns the possibly scaled width of the surface.\n */\n width(): number;\n\n /**\n * Returns the possibly scaled height of the surface.\n */\n height(): number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -26,6 +26,13 @@ export class BaseHostObject extends Host {
|
|
|
26
26
|
}
|
|
27
27
|
[Symbol.dispose]() {
|
|
28
28
|
if (this.ref !== null && typeof this.ref === "object" && "delete" in this.ref && typeof this.ref.delete === "function") {
|
|
29
|
+
// Renderer-owned and user-owned disposal can overlap (and emscripten
|
|
30
|
+
// throws on double delete) — make disposing an already-deleted object
|
|
31
|
+
// a no-op.
|
|
32
|
+
const ref = this.ref;
|
|
33
|
+
if (typeof ref.isDeleted === "function" && ref.isDeleted()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
29
36
|
this.ref.delete();
|
|
30
37
|
}
|
|
31
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["throwNotImplementedOnRNWeb","jest","fn","Error","Host","constructor","CanvasKit","_defineProperty","BaseHostObject","ref","typename","__typename__","dispose","Symbol","delete","HostObject","fromValue","value","getEnum","name","v","e","result","Object","values","find","entry","optEnum","undefined"],"sources":["Host.ts"],"sourcesContent":["import type { CanvasKit, EmbindEnumEntity } from \"canvaskit-wasm\";\n\nimport type { SkJSIInstance } from \"../types\";\n\nexport const throwNotImplementedOnRNWeb = <T>(): T => {\n if (typeof jest !== \"undefined\") {\n return jest.fn() as unknown as T;\n }\n throw new Error(\"Not implemented on React Native Web\");\n};\n\nexport abstract class Host {\n readonly CanvasKit: CanvasKit;\n\n constructor(CanvasKit: CanvasKit) {\n this.CanvasKit = CanvasKit;\n }\n}\n\nexport abstract class BaseHostObject<T, N extends string>\n extends Host\n implements SkJSIInstance<N>\n{\n readonly __typename__: N;\n ref: T;\n\n constructor(CanvasKit: CanvasKit, ref: T, typename: N) {\n super(CanvasKit);\n this.ref = ref;\n this.__typename__ = typename;\n }\n\n dispose() {\n this[Symbol.dispose]();\n }\n\n [Symbol.dispose](): void {\n if (\n this.ref !== null &&\n typeof this.ref === \"object\" &&\n \"delete\" in this.ref &&\n typeof this.ref.delete === \"function\"\n ) {\n this.ref.delete();\n }\n }\n}\n\nexport abstract class HostObject<T, N extends string> extends BaseHostObject<\n T,\n N\n> {\n static fromValue<T>(value: SkJSIInstance<string>) {\n return (value as HostObject<T, string>).ref;\n }\n}\n\nexport const getEnum = (\n CanvasKit: CanvasKit,\n name: keyof CanvasKit,\n v: number\n): EmbindEnumEntity => {\n const e = CanvasKit[name];\n if (typeof e !== \"function\") {\n throw new Error(`${name} is not an number`);\n }\n const result = Object.values(e).find(\n (entry) =>\n entry !== null &&\n typeof entry === \"object\" &&\n \"value\" in entry &&\n entry.value === v\n );\n if (!result) {\n throw new Error(\n `Enum ${name} does not have value ${v} on React Native Web`\n );\n }\n return result;\n};\n\nexport const optEnum = (\n CanvasKit: CanvasKit,\n name: keyof CanvasKit,\n v: number | undefined\n): EmbindEnumEntity | undefined => {\n return v === undefined ? undefined : getEnum(CanvasKit, name, v);\n};\n"],"mappings":";;;AAIA,OAAO,MAAMA,0BAA0B,GAAGA,CAAA,KAAY;EACpD,IAAI,OAAOC,IAAI,KAAK,WAAW,EAAE;IAC/B,OAAOA,IAAI,CAACC,EAAE,CAAC,CAAC;EAClB;EACA,MAAM,IAAIC,KAAK,CAAC,qCAAqC,CAAC;AACxD,CAAC;AAED,OAAO,MAAeC,IAAI,CAAC;EAGzBC,WAAWA,CAACC,SAAoB,EAAE;IAAAC,eAAA;IAChC,IAAI,CAACD,SAAS,GAAGA,SAAS;EAC5B;AACF;AAEA,OAAO,MAAeE,cAAc,SAC1BJ,IAAI,CAEd;EAIEC,WAAWA,CAACC,SAAoB,EAAEG,GAAM,EAAEC,QAAW,EAAE;IACrD,KAAK,CAACJ,SAAS,CAAC;IAACC,eAAA;IAAAA,eAAA;IACjB,IAAI,CAACE,GAAG,GAAGA,GAAG;IACd,IAAI,CAACE,YAAY,GAAGD,QAAQ;EAC9B;EAEAE,OAAOA,CAAA,EAAG;IACR,IAAI,CAACC,MAAM,CAACD,OAAO,CAAC,CAAC,CAAC;EACxB;EAEA,CAACC,MAAM,CAACD,OAAO,IAAU;IACvB,IACE,IAAI,CAACH,GAAG,KAAK,IAAI,IACjB,OAAO,IAAI,CAACA,GAAG,KAAK,QAAQ,IAC5B,QAAQ,IAAI,IAAI,CAACA,GAAG,IACpB,OAAO,IAAI,CAACA,GAAG,CAACK,MAAM,KAAK,UAAU,EACrC;MACA,IAAI,
|
|
1
|
+
{"version":3,"names":["throwNotImplementedOnRNWeb","jest","fn","Error","Host","constructor","CanvasKit","_defineProperty","BaseHostObject","ref","typename","__typename__","dispose","Symbol","delete","isDeleted","HostObject","fromValue","value","getEnum","name","v","e","result","Object","values","find","entry","optEnum","undefined"],"sources":["Host.ts"],"sourcesContent":["import type { CanvasKit, EmbindEnumEntity } from \"canvaskit-wasm\";\n\nimport type { SkJSIInstance } from \"../types\";\n\nexport const throwNotImplementedOnRNWeb = <T>(): T => {\n if (typeof jest !== \"undefined\") {\n return jest.fn() as unknown as T;\n }\n throw new Error(\"Not implemented on React Native Web\");\n};\n\nexport abstract class Host {\n readonly CanvasKit: CanvasKit;\n\n constructor(CanvasKit: CanvasKit) {\n this.CanvasKit = CanvasKit;\n }\n}\n\nexport abstract class BaseHostObject<T, N extends string>\n extends Host\n implements SkJSIInstance<N>\n{\n readonly __typename__: N;\n ref: T;\n\n constructor(CanvasKit: CanvasKit, ref: T, typename: N) {\n super(CanvasKit);\n this.ref = ref;\n this.__typename__ = typename;\n }\n\n dispose() {\n this[Symbol.dispose]();\n }\n\n [Symbol.dispose](): void {\n if (\n this.ref !== null &&\n typeof this.ref === \"object\" &&\n \"delete\" in this.ref &&\n typeof this.ref.delete === \"function\"\n ) {\n // Renderer-owned and user-owned disposal can overlap (and emscripten\n // throws on double delete) — make disposing an already-deleted object\n // a no-op.\n const ref = this.ref as unknown as { isDeleted?: () => boolean };\n if (typeof ref.isDeleted === \"function\" && ref.isDeleted()) {\n return;\n }\n this.ref.delete();\n }\n }\n}\n\nexport abstract class HostObject<T, N extends string> extends BaseHostObject<\n T,\n N\n> {\n static fromValue<T>(value: SkJSIInstance<string>) {\n return (value as HostObject<T, string>).ref;\n }\n}\n\nexport const getEnum = (\n CanvasKit: CanvasKit,\n name: keyof CanvasKit,\n v: number\n): EmbindEnumEntity => {\n const e = CanvasKit[name];\n if (typeof e !== \"function\") {\n throw new Error(`${name} is not an number`);\n }\n const result = Object.values(e).find(\n (entry) =>\n entry !== null &&\n typeof entry === \"object\" &&\n \"value\" in entry &&\n entry.value === v\n );\n if (!result) {\n throw new Error(\n `Enum ${name} does not have value ${v} on React Native Web`\n );\n }\n return result;\n};\n\nexport const optEnum = (\n CanvasKit: CanvasKit,\n name: keyof CanvasKit,\n v: number | undefined\n): EmbindEnumEntity | undefined => {\n return v === undefined ? undefined : getEnum(CanvasKit, name, v);\n};\n"],"mappings":";;;AAIA,OAAO,MAAMA,0BAA0B,GAAGA,CAAA,KAAY;EACpD,IAAI,OAAOC,IAAI,KAAK,WAAW,EAAE;IAC/B,OAAOA,IAAI,CAACC,EAAE,CAAC,CAAC;EAClB;EACA,MAAM,IAAIC,KAAK,CAAC,qCAAqC,CAAC;AACxD,CAAC;AAED,OAAO,MAAeC,IAAI,CAAC;EAGzBC,WAAWA,CAACC,SAAoB,EAAE;IAAAC,eAAA;IAChC,IAAI,CAACD,SAAS,GAAGA,SAAS;EAC5B;AACF;AAEA,OAAO,MAAeE,cAAc,SAC1BJ,IAAI,CAEd;EAIEC,WAAWA,CAACC,SAAoB,EAAEG,GAAM,EAAEC,QAAW,EAAE;IACrD,KAAK,CAACJ,SAAS,CAAC;IAACC,eAAA;IAAAA,eAAA;IACjB,IAAI,CAACE,GAAG,GAAGA,GAAG;IACd,IAAI,CAACE,YAAY,GAAGD,QAAQ;EAC9B;EAEAE,OAAOA,CAAA,EAAG;IACR,IAAI,CAACC,MAAM,CAACD,OAAO,CAAC,CAAC,CAAC;EACxB;EAEA,CAACC,MAAM,CAACD,OAAO,IAAU;IACvB,IACE,IAAI,CAACH,GAAG,KAAK,IAAI,IACjB,OAAO,IAAI,CAACA,GAAG,KAAK,QAAQ,IAC5B,QAAQ,IAAI,IAAI,CAACA,GAAG,IACpB,OAAO,IAAI,C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extends HostObject {
|
|
|
56
56
|
return new JsiSkPaint(this.CanvasKit, this.ref.copy());
|
|
57
57
|
}
|
|
58
58
|
assign(paint) {
|
|
59
|
+
const previous = this.ref;
|
|
59
60
|
this.ref = paint.ref.copy();
|
|
61
|
+
// The replaced ref is a WASM object the GC will not reclaim.
|
|
62
|
+
previous.delete();
|
|
60
63
|
}
|
|
61
64
|
reset() {
|
|
65
|
+
const previous = this.ref;
|
|
62
66
|
this.ref = new this.CanvasKit.Paint();
|
|
67
|
+
previous.delete();
|
|
63
68
|
}
|
|
64
69
|
getAlphaf() {
|
|
65
70
|
return this.getColor()[3];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HostObject","getEnum","JsiSkColorFilter","JsiSkImageFilter","JsiSkMaskFilter","JsiSkPathEffect","JsiSkShader","kBlendModePlusDarker","kBlendModePlusLighter","plusDarkerSkSL","plusLighterSkSL","blenderCache","WeakMap","getBlenderCache","ck","cache","get","plusDarker","plusLighter","set","JsiSkPaint","constructor","CanvasKit","ref","copy","assign","paint","reset","Paint","getAlphaf","getColor","getStrokeCap","value","getStrokeJoin","getStrokeMiter","getStrokeWidth","setAlphaf","alpha","setAntiAlias","aa","setDither","dither","setBlendMode","blendMode","effect","RuntimeEffect","MakeForBlender","makeBlender","setBlender","setColor","color","setColorFilter","filter","fromValue","setImageFilter","setMaskFilter","setPathEffect","setShader","shader","setStrokeCap","cap","setStrokeJoin","join","setStrokeMiter","limit","setStrokeWidth","width","setStyle","style"],"sources":["JsiSkPaint.ts"],"sourcesContent":["import type { Blender, CanvasKit, Paint } from \"canvaskit-wasm\";\n\nimport type {\n StrokeJoin,\n BlendMode,\n SkColor,\n SkColorFilter,\n SkImageFilter,\n SkPaint,\n SkShader,\n StrokeCap,\n PaintStyle,\n SkMaskFilter,\n SkPathEffect,\n} from \"../types\";\n\nimport { HostObject, getEnum } from \"./Host\";\nimport { JsiSkColorFilter } from \"./JsiSkColorFilter\";\nimport { JsiSkImageFilter } from \"./JsiSkImageFilter\";\nimport { JsiSkMaskFilter } from \"./JsiSkMaskFilter\";\nimport { JsiSkPathEffect } from \"./JsiSkPathEffect\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// Custom blend mode values (must match TypeScript BlendMode enum)\nconst kBlendModePlusDarker = 1001;\nconst kBlendModePlusLighter = 1002;\n\n// SkSL for PlusDarker blend mode\n// Formula: rc = max(0, 1 - ((1-dst) + (1-src))) = max(0, src + dst - 1)\nconst plusDarkerSkSL = `\n vec4 main(vec4 src, vec4 dst) {\n float outAlpha = src.a + dst.a - src.a * dst.a;\n vec3 srcUnpremul = src.a > 0.0 ? src.rgb / src.a : vec3(0.0);\n vec3 dstUnpremul = dst.a > 0.0 ? dst.rgb / dst.a : vec3(0.0);\n vec3 blended = max(vec3(0.0), srcUnpremul + dstUnpremul - vec3(1.0));\n return vec4(blended * outAlpha, outAlpha);\n }\n`;\n\n// SkSL for PlusLighter blend mode\n// Formula: rc = min(1, dst + src)\nconst plusLighterSkSL = `\n vec4 main(vec4 src, vec4 dst) {\n float outAlpha = src.a + dst.a - src.a * dst.a;\n vec3 srcUnpremul = src.a > 0.0 ? src.rgb / src.a : vec3(0.0);\n vec3 dstUnpremul = dst.a > 0.0 ? dst.rgb / dst.a : vec3(0.0);\n vec3 blended = min(vec3(1.0), srcUnpremul + dstUnpremul);\n return vec4(blended * outAlpha, outAlpha);\n }\n`;\n\n// Cache for custom blenders per CanvasKit instance\n// Using WeakMap ensures blenders are cleaned up when CanvasKit instance is garbage collected\ninterface BlenderCache {\n plusDarker: Blender | null;\n plusLighter: Blender | null;\n}\nconst blenderCache = new WeakMap<CanvasKit, BlenderCache>();\n\nconst getBlenderCache = (ck: CanvasKit): BlenderCache => {\n let cache = blenderCache.get(ck);\n if (!cache) {\n cache = { plusDarker: null, plusLighter: null };\n blenderCache.set(ck, cache);\n }\n return cache;\n};\n\nexport class JsiSkPaint extends HostObject<Paint, \"Paint\"> implements SkPaint {\n constructor(CanvasKit: CanvasKit, ref: Paint) {\n super(CanvasKit, ref, \"Paint\");\n }\n\n copy() {\n return new JsiSkPaint(this.CanvasKit, this.ref.copy());\n }\n\n assign(paint: JsiSkPaint) {\n this.ref = paint.ref.copy();\n }\n\n reset() {\n this.ref = new this.CanvasKit.Paint();\n }\n\n getAlphaf() {\n return this.getColor()[3];\n }\n\n getColor() {\n return this.ref.getColor();\n }\n\n getStrokeCap() {\n return this.ref.getStrokeCap().value;\n }\n\n getStrokeJoin() {\n return this.ref.getStrokeJoin().value;\n }\n\n getStrokeMiter() {\n return this.ref.getStrokeMiter();\n }\n\n getStrokeWidth() {\n return this.ref.getStrokeWidth();\n }\n\n setAlphaf(alpha: number) {\n this.ref.setAlphaf(alpha);\n }\n\n setAntiAlias(aa: boolean) {\n this.ref.setAntiAlias(aa);\n }\n\n setDither(dither: boolean) {\n this.ref.setDither(dither);\n }\n\n setBlendMode(blendMode: BlendMode) {\n if (blendMode === kBlendModePlusDarker) {\n // Use custom PlusDarker blender via SkRuntimeEffect\n const cache = getBlenderCache(this.CanvasKit);\n if (!cache.plusDarker) {\n const effect =\n this.CanvasKit.RuntimeEffect.MakeForBlender(plusDarkerSkSL);\n if (effect) {\n cache.plusDarker = effect.makeBlender([]);\n }\n }\n if (cache.plusDarker) {\n this.ref.setBlender(cache.plusDarker);\n }\n } else if (blendMode === kBlendModePlusLighter) {\n // Use custom PlusLighter blender via SkRuntimeEffect\n const cache = getBlenderCache(this.CanvasKit);\n if (!cache.plusLighter) {\n const effect =\n this.CanvasKit.RuntimeEffect.MakeForBlender(plusLighterSkSL);\n if (effect) {\n cache.plusLighter = effect.makeBlender([]);\n }\n }\n if (cache.plusLighter) {\n this.ref.setBlender(cache.plusLighter);\n }\n } else {\n this.ref.setBlendMode(getEnum(this.CanvasKit, \"BlendMode\", blendMode));\n }\n }\n\n setColor(color: SkColor) {\n this.ref.setColor(color);\n }\n\n setColorFilter(filter: SkColorFilter | null) {\n this.ref.setColorFilter(filter ? JsiSkColorFilter.fromValue(filter) : null);\n }\n\n setImageFilter(filter: SkImageFilter | null) {\n this.ref.setImageFilter(filter ? JsiSkImageFilter.fromValue(filter) : null);\n }\n\n setMaskFilter(filter: SkMaskFilter | null) {\n this.ref.setMaskFilter(filter ? JsiSkMaskFilter.fromValue(filter) : null);\n }\n\n setPathEffect(effect: SkPathEffect | null) {\n this.ref.setPathEffect(effect ? JsiSkPathEffect.fromValue(effect) : null);\n }\n\n setShader(shader: SkShader | null) {\n this.ref.setShader(shader ? JsiSkShader.fromValue(shader) : null);\n }\n\n setStrokeCap(cap: StrokeCap) {\n this.ref.setStrokeCap(getEnum(this.CanvasKit, \"StrokeCap\", cap));\n }\n\n setStrokeJoin(join: StrokeJoin) {\n this.ref.setStrokeJoin(getEnum(this.CanvasKit, \"StrokeJoin\", join));\n }\n\n setStrokeMiter(limit: number) {\n this.ref.setStrokeMiter(limit);\n }\n\n setStrokeWidth(width: number) {\n this.ref.setStrokeWidth(width);\n }\n\n setStyle(style: PaintStyle) {\n this.ref.setStyle({ value: style });\n }\n}\n"],"mappings":"AAgBA,SAASA,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAC5C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,WAAW,QAAQ,eAAe;;AAE3C;AACA,MAAMC,oBAAoB,GAAG,IAAI;AACjC,MAAMC,qBAAqB,GAAG,IAAI;;AAElC;AACA;AACA,MAAMC,cAAc,GAAG;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA,MAAMC,eAAe,GAAG;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;;AAKA,MAAMC,YAAY,GAAG,IAAIC,OAAO,CAA0B,CAAC;AAE3D,MAAMC,eAAe,GAAIC,EAAa,IAAmB;EACvD,IAAIC,KA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AI,CAACqB,SAAS,EAAE,WAAW,EAAEsC,GAAG,CAAC,CAAC;EAClE;EAEAC,aAAaA,CAACC,IAAgB,EAAE;IAC9B,IAAI,CAACvC,GAAG,CAACsC,aAAa,CAAC5D,OAAO,CAAC,IAAI,CAACqB,SAAS,EAAE,YAAY,EAAEwC,IAAI,CAAC,CAAC;EACrE;EAEAC,cAAcA,CAACC,KAAa,EAAE;IAC5B,IAAI,CAACzC,GAAG,CAACwC,cAAc,CAACC,KAAK,CAAC;EAChC;EAEAC,cAAcA,CAACC,KAAa,EAAE;IAC5B,IAAI,CAAC3C,GAAG,CAAC0C,cAAc,CAACC,KAAK,CAAC;EAChC;EAEAC,QAAQA,CAACC,KAAiB,EAAE;IAC1B,IAAI,CAAC7C,GAAG,CAAC4C,QAAQ,CAAC;MAAEnC,KAAK,EAAEoC;IAAM,CAAC,CAAC;EACrC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["HostObject","getEnum","JsiSkColorFilter","JsiSkImageFilter","JsiSkMaskFilter","JsiSkPathEffect","JsiSkShader","kBlendModePlusDarker","kBlendModePlusLighter","plusDarkerSkSL","plusLighterSkSL","blenderCache","WeakMap","getBlenderCache","ck","cache","get","plusDarker","plusLighter","set","JsiSkPaint","constructor","CanvasKit","ref","copy","assign","paint","previous","delete","reset","Paint","getAlphaf","getColor","getStrokeCap","value","getStrokeJoin","getStrokeMiter","getStrokeWidth","setAlphaf","alpha","setAntiAlias","aa","setDither","dither","setBlendMode","blendMode","effect","RuntimeEffect","MakeForBlender","makeBlender","setBlender","setColor","color","setColorFilter","filter","fromValue","setImageFilter","setMaskFilter","setPathEffect","setShader","shader","setStrokeCap","cap","setStrokeJoin","join","setStrokeMiter","limit","setStrokeWidth","width","setStyle","style"],"sources":["JsiSkPaint.ts"],"sourcesContent":["import type { Blender, CanvasKit, Paint } from \"canvaskit-wasm\";\n\nimport type {\n StrokeJoin,\n BlendMode,\n SkColor,\n SkColorFilter,\n SkImageFilter,\n SkPaint,\n SkShader,\n StrokeCap,\n PaintStyle,\n SkMaskFilter,\n SkPathEffect,\n} from \"../types\";\n\nimport { HostObject, getEnum } from \"./Host\";\nimport { JsiSkColorFilter } from \"./JsiSkColorFilter\";\nimport { JsiSkImageFilter } from \"./JsiSkImageFilter\";\nimport { JsiSkMaskFilter } from \"./JsiSkMaskFilter\";\nimport { JsiSkPathEffect } from \"./JsiSkPathEffect\";\nimport { JsiSkShader } from \"./JsiSkShader\";\n\n// Custom blend mode values (must match TypeScript BlendMode enum)\nconst kBlendModePlusDarker = 1001;\nconst kBlendModePlusLighter = 1002;\n\n// SkSL for PlusDarker blend mode\n// Formula: rc = max(0, 1 - ((1-dst) + (1-src))) = max(0, src + dst - 1)\nconst plusDarkerSkSL = `\n vec4 main(vec4 src, vec4 dst) {\n float outAlpha = src.a + dst.a - src.a * dst.a;\n vec3 srcUnpremul = src.a > 0.0 ? src.rgb / src.a : vec3(0.0);\n vec3 dstUnpremul = dst.a > 0.0 ? dst.rgb / dst.a : vec3(0.0);\n vec3 blended = max(vec3(0.0), srcUnpremul + dstUnpremul - vec3(1.0));\n return vec4(blended * outAlpha, outAlpha);\n }\n`;\n\n// SkSL for PlusLighter blend mode\n// Formula: rc = min(1, dst + src)\nconst plusLighterSkSL = `\n vec4 main(vec4 src, vec4 dst) {\n float outAlpha = src.a + dst.a - src.a * dst.a;\n vec3 srcUnpremul = src.a > 0.0 ? src.rgb / src.a : vec3(0.0);\n vec3 dstUnpremul = dst.a > 0.0 ? dst.rgb / dst.a : vec3(0.0);\n vec3 blended = min(vec3(1.0), srcUnpremul + dstUnpremul);\n return vec4(blended * outAlpha, outAlpha);\n }\n`;\n\n// Cache for custom blenders per CanvasKit instance\n// Using WeakMap ensures blenders are cleaned up when CanvasKit instance is garbage collected\ninterface BlenderCache {\n plusDarker: Blender | null;\n plusLighter: Blender | null;\n}\nconst blenderCache = new WeakMap<CanvasKit, BlenderCache>();\n\nconst getBlenderCache = (ck: CanvasKit): BlenderCache => {\n let cache = blenderCache.get(ck);\n if (!cache) {\n cache = { plusDarker: null, plusLighter: null };\n blenderCache.set(ck, cache);\n }\n return cache;\n};\n\nexport class JsiSkPaint extends HostObject<Paint, \"Paint\"> implements SkPaint {\n constructor(CanvasKit: CanvasKit, ref: Paint) {\n super(CanvasKit, ref, \"Paint\");\n }\n\n copy() {\n return new JsiSkPaint(this.CanvasKit, this.ref.copy());\n }\n\n assign(paint: JsiSkPaint) {\n const previous = this.ref;\n this.ref = paint.ref.copy();\n // The replaced ref is a WASM object the GC will not reclaim.\n previous.delete();\n }\n\n reset() {\n const previous = this.ref;\n this.ref = new this.CanvasKit.Paint();\n previous.delete();\n }\n\n getAlphaf() {\n return this.getColor()[3];\n }\n\n getColor() {\n return this.ref.getColor();\n }\n\n getStrokeCap() {\n return this.ref.getStrokeCap().value;\n }\n\n getStrokeJoin() {\n return this.ref.getStrokeJoin().value;\n }\n\n getStrokeMiter() {\n return this.ref.getStrokeMiter();\n }\n\n getStrokeWidth() {\n return this.ref.getStrokeWidth();\n }\n\n setAlphaf(alpha: number) {\n this.ref.setAlphaf(alpha);\n }\n\n setAntiAlias(aa: boolean) {\n this.ref.setAntiAlias(aa);\n }\n\n setDither(dither: boolean) {\n this.ref.setDither(dither);\n }\n\n setBlendMode(blendMode: BlendMode) {\n if (blendMode === kBlendModePlusDarker) {\n // Use custom PlusDarker blender via SkRuntimeEffect\n const cache = getBlenderCache(this.CanvasKit);\n if (!cache.plusDarker) {\n const effect =\n this.CanvasKit.RuntimeEffect.MakeForBlender(plusDarkerSkSL);\n if (effect) {\n cache.plusDarker = effect.makeBlender([]);\n }\n }\n if (cache.plusDarker) {\n this.ref.setBlender(cache.plusDarker);\n }\n } else if (blendMode === kBlendModePlusLighter) {\n // Use custom PlusLighter blender via SkRuntimeEffect\n const cache = getBlenderCache(this.CanvasKit);\n if (!cache.plusLighter) {\n const effect =\n this.CanvasKit.RuntimeEffect.MakeForBlender(plusLighterSkSL);\n if (effect) {\n cache.plusLighter = effect.makeBlender([]);\n }\n }\n if (cache.plusLighter) {\n this.ref.setBlender(cache.plusLighter);\n }\n } else {\n this.ref.setBlendMode(getEnum(this.CanvasKit, \"BlendMode\", blendMode));\n }\n }\n\n setColor(color: SkColor) {\n this.ref.setColor(color);\n }\n\n setColorFilter(filter: SkColorFilter | null) {\n this.ref.setColorFilter(filter ? JsiSkColorFilter.fromValue(filter) : null);\n }\n\n setImageFilter(filter: SkImageFilter | null) {\n this.ref.setImageFilter(filter ? JsiSkImageFilter.fromValue(filter) : null);\n }\n\n setMaskFilter(filter: SkMaskFilter | null) {\n this.ref.setMaskFilter(filter ? JsiSkMaskFilter.fromValue(filter) : null);\n }\n\n setPathEffect(effect: SkPathEffect | null) {\n this.ref.setPathEffect(effect ? JsiSkPathEffect.fromValue(effect) : null);\n }\n\n setShader(shader: SkShader | null) {\n this.ref.setShader(shader ? JsiSkShader.fromValue(shader) : null);\n }\n\n setStrokeCap(cap: StrokeCap) {\n this.ref.setStrokeCap(getEnum(this.CanvasKit, \"StrokeCap\", cap));\n }\n\n setStrokeJoin(join: StrokeJoin) {\n this.ref.setStrokeJoin(getEnum(this.CanvasKit, \"StrokeJoin\", join));\n }\n\n setStrokeMiter(limit: number) {\n this.ref.setStrokeMiter(limit);\n }\n\n setStrokeWidth(width: number) {\n this.ref.setStrokeWidth(width);\n }\n\n setStyle(style: PaintStyle) {\n this.ref.setStyle({ value: style });\n }\n}\n"],"mappings":"AAgBA,SAASA,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAC5C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,WAAW,QAAQ,eAAe;;AAE3C;AACA,MAAMC,oBAAoB,GAAG,IAAI;AACjC,MAAMC,qBAAqB,GAAG,IAAI;;AAElC;AACA;AACA,MAAMC,cAAc,GAAG;AACvB;AACA;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EAC3E;EAEAI,aAAaA,CAACZ,MAA2B,EAAE;IACzC,IAAI,CAACvB,GAAG,CAACmC,aAAa,CAACZ,MAAM,GAAGzC,eAAe,CAACkD,SAAS,CAACT,MAAM,CAAC,GAAG,IAAI,CAAC;EAC3E;EAEAa,SAASA,CAACC,MAAuB,EAAE;IACjC,IAAI,CAACrC,GAAG,CAACoC,SAAS,CAACC,MAAM,GAAGtD,WAAW,CAACiD,SAAS,CAACK,MAAM,CAAC,GAAG,IAAI,CAAC;EACnE;EAEAC,YAAYA,CAACC,GAAc,EAAE;IAC3B,IAAI,CAACvC,GAAG,CAACsC,YAAY,CAAC5D,OAAO,CAAC,IAAI,CAACqB,SAAS,EAAE,WAAW,EAAEwC,GAAG,CAAC,CAAC;EAClE;EAEAC,aAAaA,CAACC,IAAgB,EAAE;IAC9B,IAAI,CAACzC,GAAG,CAACwC,aAAa,CAAC9D,OAAO,CAAC,IAAI,CAACqB,SAAS,EAAE,YAAY,EAAE0C,IAAI,CAAC,CAAC;EACrE;EAEAC,cAAcA,CAACC,KAAa,EAAE;IAC5B,IAAI,CAAC3C,GAAG,CAAC0C,cAAc,CAACC,KAAK,CAAC;EAChC;EAEAC,cAAcA,CAACC,KAAa,EAAE;IAC5B,IAAI,CAAC7C,GAAG,CAAC4C,cAAc,CAACC,KAAK,CAAC;EAChC;EAEAC,QAAQA,CAACC,KAAiB,EAAE;IAC1B,IAAI,CAAC/C,GAAG,CAAC8C,QAAQ,CAAC;MAAEnC,KAAK,EAAEoC;IAAM,CAAC,CAAC;EACrC;AACF","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CanvasKit, Paragraph } from "canvaskit-wasm";
|
|
2
|
-
import type { SkRect, SkRectWithDirection, SkParagraph, LineMetrics } from "../types";
|
|
2
|
+
import type { SkRect, SkRectWithDirection, SkParagraph, SkPath, LineMetrics, ParagraphExtendedVisitor } from "../types";
|
|
3
3
|
import { HostObject } from "./Host";
|
|
4
4
|
import type { JsiSkCanvas } from "./JsiSkCanvas";
|
|
5
5
|
export declare class JsiSkParagraph extends HostObject<Paragraph, "Paragraph"> implements SkParagraph {
|
|
@@ -15,4 +15,6 @@ export declare class JsiSkParagraph extends HostObject<Paragraph, "Paragraph"> i
|
|
|
15
15
|
getRectsForPlaceholders(): SkRectWithDirection[];
|
|
16
16
|
getRectsForRange(start: number, end: number): SkRect[];
|
|
17
17
|
getLineMetrics(): LineMetrics[];
|
|
18
|
+
getPath(_lineNumber: number): SkPath | null;
|
|
19
|
+
extendedVisit(_visitor: ParagraphExtendedVisitor): void;
|
|
18
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HostObject } from "./Host";
|
|
1
|
+
import { HostObject, throwNotImplementedOnRNWeb } from "./Host";
|
|
2
2
|
import { JsiSkRect } from "./JsiSkRect";
|
|
3
3
|
export class JsiSkParagraph extends HostObject {
|
|
4
4
|
constructor(CanvasKit, ref) {
|
|
@@ -49,5 +49,11 @@ export class JsiSkParagraph extends HostObject {
|
|
|
49
49
|
getLineMetrics() {
|
|
50
50
|
return this.ref.getLineMetrics();
|
|
51
51
|
}
|
|
52
|
+
getPath(_lineNumber) {
|
|
53
|
+
return throwNotImplementedOnRNWeb();
|
|
54
|
+
}
|
|
55
|
+
extendedVisit(_visitor) {
|
|
56
|
+
return throwNotImplementedOnRNWeb();
|
|
57
|
+
}
|
|
52
58
|
}
|
|
53
59
|
//# sourceMappingURL=JsiSkParagraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HostObject","JsiSkRect","JsiSkParagraph","constructor","CanvasKit","ref","getMinIntrinsicWidth","getMaxIntrinsicWidth","getLongestLine","layout","width","paint","canvas","x","y","drawParagraph","getHeight","getMaxWidth","getGlyphPositionAtCoordinate","pos","getRectsForPlaceholders","map","rect","dir","direction","value","getRectsForRange","start","end","getLineMetrics"],"sources":["JsiSkParagraph.ts"],"sourcesContent":["import type { CanvasKit, Paragraph } from \"canvaskit-wasm\";\n\nimport type {\n SkRect,\n SkRectWithDirection,\n SkParagraph,\n LineMetrics,\n} from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport type { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkParagraph\n extends HostObject<Paragraph, \"Paragraph\">\n implements SkParagraph\n{\n constructor(CanvasKit: CanvasKit, ref: Paragraph) {\n super(CanvasKit, ref, \"Paragraph\");\n }\n getMinIntrinsicWidth() {\n return this.ref.getMinIntrinsicWidth();\n }\n\n getMaxIntrinsicWidth() {\n return this.ref.getMaxIntrinsicWidth();\n }\n\n getLongestLine() {\n return this.ref.getLongestLine();\n }\n\n layout(width: number) {\n this.ref.layout(width);\n }\n paint(canvas: JsiSkCanvas, x: number, y: number) {\n canvas.ref.drawParagraph(this.ref, x, y);\n }\n getHeight() {\n return this.ref.getHeight();\n }\n getMaxWidth() {\n return this.ref.getMaxWidth();\n }\n getGlyphPositionAtCoordinate(x: number, y: number) {\n return this.ref.getGlyphPositionAtCoordinate(x, y).pos;\n }\n getRectsForPlaceholders(): SkRectWithDirection[] {\n return this.ref.getRectsForPlaceholders().map(({ rect, dir }) => ({\n rect: new JsiSkRect(this.CanvasKit, rect),\n direction: dir.value,\n }));\n }\n getRectsForRange(start: number, end: number): SkRect[] {\n return this.ref\n .getRectsForRange(\n start,\n end,\n { value: 0 } /** kTight */,\n { value: 0 } /** kTight */\n )\n .map(({ rect }) => new JsiSkRect(this.CanvasKit, rect));\n }\n getLineMetrics(): LineMetrics[] {\n return this.ref.getLineMetrics();\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["HostObject","throwNotImplementedOnRNWeb","JsiSkRect","JsiSkParagraph","constructor","CanvasKit","ref","getMinIntrinsicWidth","getMaxIntrinsicWidth","getLongestLine","layout","width","paint","canvas","x","y","drawParagraph","getHeight","getMaxWidth","getGlyphPositionAtCoordinate","pos","getRectsForPlaceholders","map","rect","dir","direction","value","getRectsForRange","start","end","getLineMetrics","getPath","_lineNumber","extendedVisit","_visitor"],"sources":["JsiSkParagraph.ts"],"sourcesContent":["import type { CanvasKit, Paragraph } from \"canvaskit-wasm\";\n\nimport type {\n SkRect,\n SkRectWithDirection,\n SkParagraph,\n SkPath,\n LineMetrics,\n ParagraphExtendedVisitor,\n} from \"../types\";\n\nimport { HostObject, throwNotImplementedOnRNWeb } from \"./Host\";\nimport type { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkParagraph\n extends HostObject<Paragraph, \"Paragraph\">\n implements SkParagraph\n{\n constructor(CanvasKit: CanvasKit, ref: Paragraph) {\n super(CanvasKit, ref, \"Paragraph\");\n }\n getMinIntrinsicWidth() {\n return this.ref.getMinIntrinsicWidth();\n }\n\n getMaxIntrinsicWidth() {\n return this.ref.getMaxIntrinsicWidth();\n }\n\n getLongestLine() {\n return this.ref.getLongestLine();\n }\n\n layout(width: number) {\n this.ref.layout(width);\n }\n paint(canvas: JsiSkCanvas, x: number, y: number) {\n canvas.ref.drawParagraph(this.ref, x, y);\n }\n getHeight() {\n return this.ref.getHeight();\n }\n getMaxWidth() {\n return this.ref.getMaxWidth();\n }\n getGlyphPositionAtCoordinate(x: number, y: number) {\n return this.ref.getGlyphPositionAtCoordinate(x, y).pos;\n }\n getRectsForPlaceholders(): SkRectWithDirection[] {\n return this.ref.getRectsForPlaceholders().map(({ rect, dir }) => ({\n rect: new JsiSkRect(this.CanvasKit, rect),\n direction: dir.value,\n }));\n }\n getRectsForRange(start: number, end: number): SkRect[] {\n return this.ref\n .getRectsForRange(\n start,\n end,\n { value: 0 } /** kTight */,\n { value: 0 } /** kTight */\n )\n .map(({ rect }) => new JsiSkRect(this.CanvasKit, rect));\n }\n getLineMetrics(): LineMetrics[] {\n return this.ref.getLineMetrics();\n }\n getPath(_lineNumber: number): SkPath | null {\n return throwNotImplementedOnRNWeb<SkPath | null>();\n }\n extendedVisit(_visitor: Parag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AC,CAAC;MAAEC,IAAI;MAAEC;IAAI,CAAC,MAAM;MAChED,IAAI,EAAE,IAAIrB,SAAS,CAAC,IAAI,CAACG,SAAS,EAAEkB,IAAI,CAAC;MACzCE,SAAS,EAAED,GAAG,CAACE;IACjB,CAAC,CAAC,CAAC;EACL;EACAC,gBAAgBA,CAACC,KAAa,EAAEC,GAAW,EAAY;IACrD,OAAO,IAAI,CAACvB,GAAG,CACZqB,gBAAgB,CACfC,KAAK,EACLC,GAAG,EACH;MAAEH,KAAK,EAAE;IAAE,CAAC,CAAC,eACb;MAAEA,KAAK,EAAE;IAAE,CAAC,CAAC,aACf,CAAC,CACAJ,GAAG,CAAC,CAAC;MAAEC;IAAK,CAAC,KAAK,IAAIrB,SAAS,CAAC,IAAI,CAACG,SAAS,EAAEkB,IAAI,CAAC,CAAC;EAC3D;EACAO,cAAcA,CAAA,EAAkB;IAC9B,OAAO,IAAI,CAACxB,GAAG,CAACwB,cAAc,CAAC,CAAC;EAClC;EACAC,OAAOA,CAACC,WAAmB,EAAiB;IAC1C,OAAO/B,0BAA0B,CAAgB,CAAC;EACpD;EACAgC,aAAaA,CAACC,QAAkC,EAAQ;IACtD,OAAOjC,0BAA0B,CAAO,CAAC;EAC3C;AACF","ignoreList":[]}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import { TextDirection } from "../types";
|
|
2
|
+
import { JsiSkTextStyle } from "./JsiSkTextStyle";
|
|
2
3
|
export class JsiSkParagraphStyle {
|
|
3
4
|
static toParagraphStyle(ck, value) {
|
|
4
5
|
var _value$disableHinting, _value$ellipsis, _value$heightMultipli, _value$maxLines, _value$replaceTabChar, _ps$strutStyle, _value$strutStyle$fon, _value$strutStyle, _value$strutStyle$fon2, _value$strutStyle2, _value$strutStyle$hei, _value$strutStyle3, _value$strutStyle$lea, _value$strutStyle4, _value$strutStyle$for, _value$strutStyle5, _ps$strutStyle$fontSt, _value$strutStyle6, _value$strutStyle7, _value$strutStyle8, _value$strutStyle$hal, _value$strutStyle9, _value$strutStyle$str, _value$strutStyle0;
|
|
5
6
|
// Seems like we need to provide the textStyle.color value, otherwise
|
|
6
7
|
// the constructor crashes.
|
|
8
|
+
const textStyle = {
|
|
9
|
+
color: ck.BLACK
|
|
10
|
+
};
|
|
11
|
+
if (value.textStyle) {
|
|
12
|
+
// Only merge the properties that are set; toTextStyle() emits undefined
|
|
13
|
+
// for the others and the ParagraphStyle constructor requires a color.
|
|
14
|
+
Object.entries(JsiSkTextStyle.toTextStyle(value.textStyle)).forEach(([key, v]) => {
|
|
15
|
+
if (v !== undefined) {
|
|
16
|
+
textStyle[key] = v;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
7
20
|
const ps = new ck.ParagraphStyle({
|
|
8
|
-
textStyle
|
|
9
|
-
color: ck.BLACK
|
|
10
|
-
}
|
|
21
|
+
textStyle
|
|
11
22
|
});
|
|
12
23
|
ps.disableHinting = (_value$disableHinting = value.disableHinting) !== null && _value$disableHinting !== void 0 ? _value$disableHinting : ps.disableHinting;
|
|
13
24
|
ps.ellipsis = (_value$ellipsis = value.ellipsis) !== null && _value$ellipsis !== void 0 ? _value$ellipsis : ps.ellipsis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TextDirection","JsiSkParagraphStyle","toParagraphStyle","ck","value","_value$disableHinting","_value$ellipsis","_value$heightMultipli","_value$maxLines","_value$replaceTabChar","_ps$strutStyle","_value$strutStyle$fon","_value$strutStyle","_value$strutStyle$fon2","_value$strutStyle2","_value$strutStyle$hei","_value$strutStyle3","_value$strutStyle$lea","_value$strutStyle4","_value$strutStyle$for","_value$strutStyle5","_ps$strutStyle$fontSt","_value$strutStyle6","_value$strutStyle7","_value$strutStyle8","_value$strutStyle$hal","_value$strutStyle9","_value$strutStyle$str","_value$strutStyle0","
|
|
1
|
+
{"version":3,"names":["TextDirection","JsiSkTextStyle","JsiSkParagraphStyle","toParagraphStyle","ck","value","_value$disableHinting","_value$ellipsis","_value$heightMultipli","_value$maxLines","_value$replaceTabChar","_ps$strutStyle","_value$strutStyle$fon","_value$strutStyle","_value$strutStyle$fon2","_value$strutStyle2","_value$strutStyle$hei","_value$strutStyle3","_value$strutStyle$lea","_value$strutStyle4","_value$strutStyle$for","_value$strutStyle5","_ps$strutStyle$fontSt","_value$strutStyle6","_value$strutStyle7","_value$strutStyle8","_value$strutStyle$hal","_value$strutStyle9","_value$strutStyle$str","_value$strutStyle0","textStyle","color","BLACK","Object","entries","toTextStyle","forEach","key","v","undefined","ps","ParagraphStyle","disableHinting","ellipsis","heightMultiplier","maxLines","replaceTabCharacters","textAlign","textDirection","LTR","textHeightBehavior","strutStyle","fontFamilies","fontSize","leading","forceStrutHeight","fontStyle","slant","width","weight","halfLeading","strutEnabled"],"sources":["JsiSkParagraphStyle.ts"],"sourcesContent":["import type { CanvasKit, ParagraphStyle, TextStyle } from \"canvaskit-wasm\";\n\nimport { TextDirection } from \"../types\";\nimport type { SkParagraphStyle } from \"../types\";\n\nimport { JsiSkTextStyle } from \"./JsiSkTextStyle\";\n\nexport class JsiSkParagraphStyle {\n static toParagraphStyle(\n ck: CanvasKit,\n value: SkParagraphStyle\n ): ParagraphStyle {\n // Seems like we need to provide the textStyle.color value, otherwise\n // the constructor crashes.\n const textStyle: TextStyle = { color: ck.BLACK };\n if (value.textStyle) {\n // Only merge the properties that are set; toTextStyle() emits undefined\n // for the others and the ParagraphStyle constructor requires a color.\n Object.entries(JsiSkTextStyle.toTextStyle(value.textStyle)).forEach(\n ([key, v]) => {\n if (v !== undefined) {\n (textStyle as Record<string, unknown>)[key] = v;\n }\n }\n );\n }\n const ps = new ck.ParagraphStyle({ textStyle });\n\n ps.disableHinting = value.disableHinting ?? ps.disableHinting;\n ps.ellipsis = value.ellipsis ?? ps.ellipsis;\n ps.heightMultiplier = value.heightMultiplier ?? ps.heightMultiplier;\n ps.maxLines = value.maxLines ?? ps.maxLines;\n ps.replaceTabCharacters =\n value.replaceTabCharacters ?? ps.replaceTabCharacters;\n ps.textAlign =\n value.textAlign !== undefined ? { value: value.textAlign } : ps.textAlign;\n ps.textDirection =\n value.textDirection !== undefined\n ? { value: value.textDirection === TextDirection.LTR ? 1 : 0 }\n : ps.textDirection;\n ps.textHeightBehavior =\n value.textHeightBehavior !== undefined\n ? { value: value.textHeightBehavior }\n : ps.textHeightBehavior;\n\n ps.strutStyle = ps.strutStyle ?? {};\n ps.strutStyle.fontFamilies =\n value.strutStyle?.fontFamilies ?? ps.strutStyle.fontFamilies;\n ps.strutStyle.fontSize =\n value.strutStyle?.fontSize ?? ps.strutStyle.fontSize;\n ps.strutStyle.heightMultiplier =\n value.strutStyle?.heightMultiplier ?? ps.strutStyle.heightMultiplier;\n ps.strutStyle.leading = value.strutStyle?.leading ?? ps.strutStyle.leading;\n ps.strutStyle.forceStrutHeight =\n value.strutStyle?.forceStrutHeight ?? ps.strutStyle.forceStrutHeight;\n\n ps.strutStyle.fontStyle = ps.strutStyle.fontStyle ?? {};\n\n ps.strutStyle.fontStyle.slant =\n value.strutStyle?.fontStyle?.slant !== undefined\n ? { value: value.strutStyle.fontStyle.slant }\n : ps.strutStyle.fontStyle.slant;\n ps.strutStyle.fontStyle.width =\n value.strutStyle?.fontStyle?.width !== undefined\n ? { value: value.strutStyle.fontStyle.width }\n : ps.strutStyle.fontStyle.width;\n ps.strutStyle.fontStyle.weight =\n value.strutStyle?.fontStyle?.weight !== undefined\n ? { value: value.strutStyle.fontStyle.weight }\n : ps.strutStyle.fontStyle.weight;\n ps.strutStyle.halfLeading =\n value.strutStyle?.halfLeading ?? ps.strutStyle.halfLeading;\n ps.strutStyle.strutEnabled =\n value.strutStyle?.strutEnabled ?? ps.strutStyle.strutEnabled;\n\n return ps;\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa,QAAQ,UAAU;AAGxC,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,OAAO,MAAMC,mBAAmB,CAAC;EAC/B,OAAOC,gBAAgBA,CACrBC,EAAa,EACbC,KAAuB,EAC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<Surface, "Surface"> implements SkSurface {
|
|
6
6
|
constructor(CanvasKit: CanvasKit, ref: Surface);
|
|
7
7
|
[Symbol.dispose](): void;
|
|
8
|
-
flush(): void;
|
|
8
|
+
flush(_sync?: boolean): void;
|
|
9
9
|
width(): number;
|
|
10
10
|
height(): number;
|
|
11
11
|
getCanvas(): SkCanvas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HostObject","JsiSkCanvas","JsiSkImage","JsiSkRect","JsiSkSurface","constructor","CanvasKit","ref","Symbol","dispose","flush","width","height","getCanvas","makeImageSnapshot","bounds","outputImage","image","Array","from","fromValue","undefined","getNativeTextureUnstable","console","warn"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n [Symbol.dispose]() {\n this.ref.dispose();\n }\n\n flush() {\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n if (outputImage) {\n outputImage.ref = image;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":"AAIA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,MAAMC,YAAY,SACfJ,UAAU,CAEpB;EACEK,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;EAClC;EAEA,CAACC,MAAM,CAACC,OAAO,IAAI;IACjB,IAAI,CAACF,GAAG,CAACE,OAAO,CAAC,CAAC;EACpB;EAEAC,KAAKA,
|
|
1
|
+
{"version":3,"names":["HostObject","JsiSkCanvas","JsiSkImage","JsiSkRect","JsiSkSurface","constructor","CanvasKit","ref","Symbol","dispose","flush","_sync","width","height","getCanvas","makeImageSnapshot","bounds","outputImage","image","Array","from","fromValue","undefined","getNativeTextureUnstable","console","warn"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n [Symbol.dispose]() {\n this.ref.dispose();\n }\n\n flush(_sync?: boolean) {\n // CanvasKit has no separate CPU sync; flush() is sufficient on the web backend.\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n if (outputImage) {\n outputImage.ref = image;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":"AAIA,SAASA,UAAU,QAAQ,QAAQ;AACnC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,SAAS,QAAQ,aAAa;AAEvC,OAAO,MAAMC,YAAY,SACfJ,UAAU,CAEpB;EACEK,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;EAClC;EAEA,CAACC,MAAM,CAACC,OAAO,IAAI;IACjB,IAAI,CAACF,GAAG,CAACE,OAAO,CAAC,CAAC;EACpB;EAEAC,KAAKA,CAACC,KAAe,EAAE;IACrB;IACA,IAAI,CAACJ,GAAG,CAACG,KAAK,CAAC,CAAC;EAClB;EAEAE,KAAKA,CAAA,EAAG;IACN,OAAO,IAAI,CAACL,GAAG,CAACK,KAAK,CAAC,CAAC;EACzB;EAEAC,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACN,GAAG,CAACM,MAAM,CAAC,CAAC;EAC1B;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIb,WAAW,CAAC,IAAI,CAACK,SAAS,EAAE,IAAI,CAACC,GAAG,CAACO,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAC,iBAAiBA,CAACC,MAAe,EAAEC,WAAwB,EAAW;IACpE,MAAMC,KAAK,GAAG,IAAI,CAACX,GAAG,CAACQ,iBAAiB,CACtCC,MAAM,GACFG,KAAK,CAACC,IAAI,CAACjB,SAAS,CAACkB,SAAS,CAAC,IAAI,CAACf,SAAS,EAAEU,MAAM,CAAC,CAAC,GACvDM,SACN,CAAC;IACD,IAAIL,WAAW,EAAE;MACfA,WAAW,CAACV,GAAG,GAAGW,KAAK;IACzB;IACA,OAAO,IAAIhB,UAAU,CAAC,IAAI,CAACI,SAAS,EAAEY,KAAK,CAAC;EAC9C;EAEAK,wBAAwBA,CAAA,EAAY;IAClCC,OAAO,CAACC,IAAI,CAAC,6CAA6C,CAAC;IAC3D,OAAO,IAAI;EACb;AACF","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ declare class NativeReanimatedContainer extends Container {
|
|
|
7
7
|
private mapperId;
|
|
8
8
|
private picture;
|
|
9
9
|
constructor(Skia: Skia, nativeId: number);
|
|
10
|
+
unmount(): void;
|
|
10
11
|
redraw(): void;
|
|
11
12
|
}
|
|
12
13
|
export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | NativeReanimatedContainer;
|
|
@@ -30,9 +30,20 @@ class NativeReanimatedContainer extends Container {
|
|
|
30
30
|
_defineProperty(this, "picture", void 0);
|
|
31
31
|
this.picture = Skia.Picture.MakePicture(null);
|
|
32
32
|
}
|
|
33
|
+
unmount() {
|
|
34
|
+
super.unmount();
|
|
35
|
+
if (this.mapperId !== null) {
|
|
36
|
+
// The mapper closure retains the recorder and its resources (e.g.
|
|
37
|
+
// images) on the UI runtime and keeps updating the picture of an
|
|
38
|
+
// unmounted view — stop it or it leaks for the lifetime of the app.
|
|
39
|
+
Rea.stopMapper(this.mapperId);
|
|
40
|
+
this.mapperId = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
33
43
|
redraw() {
|
|
34
44
|
if (this.mapperId !== null) {
|
|
35
45
|
Rea.stopMapper(this.mapperId);
|
|
46
|
+
this.mapperId = null;
|
|
36
47
|
}
|
|
37
48
|
if (this.unmounted) {
|
|
38
49
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","constructor","Skia","_defineProperty","Picture","MakePicture","
|
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","constructor","Skia","_defineProperty","Picture","MakePicture","unmount","mapperId","stopMapper","redraw","unmounted","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","createContainer"],"sources":["Container.native.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkPicture } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\nimport { visit } from \"./Recorder/Visitor\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n picture: SkPicture\n) => {\n \"worklet\";\n\n //const start = performance.now();\n recorder.play(picture);\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n private picture: SkPicture;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n this.picture = Skia.Picture.MakePicture(null)!;\n }\n\n unmount() {\n super.unmount();\n if (this.mapperId !== null) {\n // The mapper closure retains the recorder and its resources (e.g.\n // images) on the UI runtime and keeps updating the picture of an\n // unmounted view — stop it or it leaks for the lifetime of the app.\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new ReanimatedRecorder(this.Skia);\n const { nativeId, picture } = this;\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n // Draw first frame\n Rea.runOnUI(() => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n })();\n // Animate\n if (sharedValues.length > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new NativeReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAGvE,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,SAAS,EAAEC,eAAe,QAAQ,mBAAmB;AAC9D,SAASC,KAAK,QAAQ,oBAAoB;AAE1C,OAAO,qBAAqB;AAC5B,OAAO,cAAc;;AAErB;AACA,MAAM;EAAEC;AAAY,CAAC,GAAGC,UAAU;AAElC,MAAMC,kBAAkB,GAAGA,CACzBC,QAAgB,EAChBC,QAAqB,EACrBC,OAAkB,KACf;EACH,SAAS;;EAET;EACAD,QAAQ,CAACE,IAAI,CAACD,OAAO,CAAC;EACtB;EACA;EACAL,WAAW,CAACO,cAAc,CAACJ,QAAQ,EAAE,SAAS,EAAEE,OAAO,CAAC;AAC1D,CAAC;AAED,MAAMG,yBAAyB,SAASX,SAAS,CAAC;EAIhDY,WAAWA,CACTC,IAAU,EACFP,QAAgB,EACxB;IACA,KAAK,CAACO,IAAI,CAAC;IAAC,KAFJP,QAAgB,GAAhBA,QAAgB;IAAAQ,eAAA,mBALQ,IAAI;IAAAA,eAAA;IAQpC,IAAI,CAAC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ACvD,CAAC,EAAEe,YAAY,CAAC;IAClB;EACF;AACF;AAEA,OAAO,MAAMQ,eAAe,GAAGA,CAAClB,IAAU,EAAEP,QAAgB,KAAK;EAC/D,IAAIR,gBAAgB,IAAIQ,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIK,yBAAyB,CAACE,IAAI,EAAEP,QAAQ,CAAC;EACtD,CAAC,MAAM;IACL,OAAO,IAAIL,eAAe,CAACY,IAAI,EAAEP,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ declare class ReanimatedContainer extends Container {
|
|
|
6
6
|
private nativeId;
|
|
7
7
|
private mapperId;
|
|
8
8
|
constructor(Skia: Skia, nativeId: number);
|
|
9
|
+
unmount(): void;
|
|
9
10
|
redraw(): void;
|
|
10
11
|
}
|
|
11
12
|
export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | ReanimatedContainer;
|