@shopify/react-native-skia 2.8.0 → 2.9.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.
Files changed (48) hide show
  1. package/android/build.gradle +10 -4
  2. package/android/cpp/rnskia-android/OpenGLContext.h +29 -3
  3. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +9 -2
  4. package/android/cpp/rnskia-android/gl/Context.h +3 -0
  5. package/android/cpp/rnskia-android/gl/Surface.h +1 -1
  6. package/cpp/api/JsiSkiaContext.h +4 -0
  7. package/cpp/rnskia/RNSkView.h +6 -0
  8. package/lib/commonjs/Platform/Platform.js +5 -2
  9. package/lib/commonjs/Platform/Platform.js.map +1 -1
  10. package/lib/commonjs/Platform/Platform.web.js +8 -7
  11. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  12. package/lib/commonjs/skia/core/Font.d.ts +21 -6
  13. package/lib/commonjs/skia/core/Font.js +24 -4
  14. package/lib/commonjs/skia/core/Font.js.map +1 -1
  15. package/lib/commonjs/skia/types/Data/Data.d.ts +5 -4
  16. package/lib/commonjs/skia/types/Data/Data.js +7 -1
  17. package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
  18. package/lib/commonjs/skia/web/JsiSkFont.d.ts +1 -1
  19. package/lib/commonjs/skia/web/JsiSkFont.js +43 -2
  20. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  21. package/lib/module/Platform/Platform.js +6 -3
  22. package/lib/module/Platform/Platform.js.map +1 -1
  23. package/lib/module/Platform/Platform.web.js +9 -8
  24. package/lib/module/Platform/Platform.web.js.map +1 -1
  25. package/lib/module/skia/core/Font.d.ts +21 -6
  26. package/lib/module/skia/core/Font.js +26 -5
  27. package/lib/module/skia/core/Font.js.map +1 -1
  28. package/lib/module/skia/types/Data/Data.d.ts +5 -4
  29. package/lib/module/skia/types/Data/Data.js +5 -0
  30. package/lib/module/skia/types/Data/Data.js.map +1 -1
  31. package/lib/module/skia/web/JsiSkFont.d.ts +1 -1
  32. package/lib/module/skia/web/JsiSkFont.js +44 -3
  33. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  34. package/lib/typescript/lib/commonjs/skia/types/Data/Data.d.ts +1 -0
  35. package/lib/typescript/lib/commonjs/skia/web/JsiSkFont.d.ts +1 -1
  36. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  37. package/lib/typescript/lib/module/skia/types/Data/Data.d.ts +1 -0
  38. package/lib/typescript/lib/module/skia/web/JsiSkFont.d.ts +1 -1
  39. package/lib/typescript/src/skia/core/Font.d.ts +21 -6
  40. package/lib/typescript/src/skia/types/Data/Data.d.ts +5 -4
  41. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -1
  42. package/package.json +8 -2
  43. package/react-native-skia.podspec +18 -10
  44. package/src/Platform/Platform.ts +6 -7
  45. package/src/Platform/Platform.web.tsx +9 -8
  46. package/src/skia/core/Font.ts +34 -13
  47. package/src/skia/types/Data/Data.ts +14 -4
  48. package/src/skia/web/JsiSkFont.ts +48 -4
@@ -74,12 +74,18 @@ static def resolveNodePackage(packageName, baseDir) {
74
74
  return proc.text.trim()
75
75
  }
76
76
 
77
- // Graphite is detected via a marker file created by install-skia-graphite, which
78
- // downloads its binaries directly into libs/. For the default (Ganesh) build the
79
- // binaries live in the react-native-skia-android npm package and are read in place.
77
+ // Graphite is detected via a marker file (created by install-skia-graphite for
78
+ // in-repo development, or shipped in the npm tarball for next-channel releases).
79
+ // The prebuilt binaries live in the react-native-skia-android npm package for the
80
+ // default (Ganesh) build and in react-native-skia-graphite-android for Graphite.
81
+ // In-repo Graphite development downloads them directly into libs/android instead,
82
+ // which takes precedence over the npm package when present.
80
83
  def useGraphite = file("${projectDir}/../libs/.graphite").exists()
84
+ def localGraphiteLibs = file("${projectDir}/../libs/android")
81
85
  def skiaLibsPath = useGraphite
82
- ? "${projectDir}/../libs/android"
86
+ ? (localGraphiteLibs.exists()
87
+ ? "${projectDir}/../libs/android"
88
+ : "${resolveNodePackage('react-native-skia-graphite-android', projectDir)}/libs")
83
89
  : "${resolveNodePackage('react-native-skia-android', projectDir)}/libs"
84
90
 
85
91
  logger.warn("react-native-skia: SK_GRAPHITE: ${useGraphite}")
@@ -42,6 +42,11 @@ private:
42
42
  _glConfig = _glDisplay->chooseConfig();
43
43
  _glContext = _glDisplay->makeContext(_glConfig, nullptr);
44
44
  _glSurface = _glDisplay->makePixelBufferSurface(_glConfig, 1, 1);
45
+ if (_glContext == nullptr || _glSurface == nullptr) {
46
+ RNSkLogger::logToConsole(
47
+ "Couldn't create the shared OpenGL context or surface");
48
+ return;
49
+ }
45
50
  _glContext->makeCurrent(_glSurface.get());
46
51
  }
47
52
  };
@@ -60,6 +65,10 @@ public:
60
65
 
61
66
  sk_sp<SkSurface> MakeOffscreen(int width, int height,
62
67
  bool useP3ColorSpace = false) {
68
+ if (_directContext == nullptr) {
69
+ return nullptr;
70
+ }
71
+
63
72
  auto colorType = kRGBA_8888_SkColorType;
64
73
 
65
74
  SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
@@ -110,6 +119,9 @@ public:
110
119
  sk_sp<SkImage> MakeImageFromBuffer(void *buffer,
111
120
  bool requireKnownFormat = false) {
112
121
  #if __ANDROID_API__ >= 26
122
+ if (_directContext == nullptr) {
123
+ return nullptr;
124
+ }
113
125
  const AHardwareBuffer *hardwareBuffer =
114
126
  static_cast<AHardwareBuffer *>(buffer);
115
127
  DeleteImageProc deleteImageProc = nullptr;
@@ -181,6 +193,11 @@ public:
181
193
  // TODO: remove width, height
182
194
  std::unique_ptr<WindowContext> MakeWindow(ANativeWindow *window,
183
195
  bool highBitDepth = false) {
196
+ if (_directContext == nullptr) {
197
+ RNSkLogger::logToConsole(
198
+ "The OpenGL context is invalid, the surface will not be rendered");
199
+ return nullptr;
200
+ }
184
201
  auto display = OpenGLSharedContext::getInstance().getDisplay();
185
202
  if (highBitDepth) {
186
203
  // A 10-bit window surface would require the shared EGL context to be
@@ -196,7 +213,11 @@ public:
196
213
  }
197
214
 
198
215
  GrDirectContext *getDirectContext() { return _directContext.get(); }
199
- void makeCurrent() { _glContext->makeCurrent(_glSurface.get()); }
216
+ void makeCurrent() {
217
+ if (_glContext != nullptr) {
218
+ _glContext->makeCurrent(_glSurface.get());
219
+ }
220
+ }
200
221
 
201
222
  private:
202
223
  std::unique_ptr<gl::Context> _glContext;
@@ -209,12 +230,17 @@ private:
209
230
  auto glConfig = OpenGLSharedContext::getInstance().getConfig();
210
231
  _glContext = display->makeContext(glConfig, sharedContext);
211
232
  _glSurface = display->makePixelBufferSurface(glConfig, 1, 1);
212
- _glContext->makeCurrent(_glSurface.get());
233
+ if (_glContext == nullptr || _glSurface == nullptr ||
234
+ !_glContext->makeCurrent(_glSurface.get())) {
235
+ RNSkLogger::logToConsole(
236
+ "Couldn't create the OpenGL context, Skia rendering is disabled");
237
+ return;
238
+ }
213
239
  auto backendInterface = GrGLMakeNativeInterface();
214
240
  _directContext = GrDirectContexts::MakeGL(backendInterface);
215
241
 
216
242
  if (_directContext == nullptr) {
217
- throw std::runtime_error("GrDirectContexts::MakeGL failed");
243
+ RNSkLogger::logToConsole("GrDirectContexts::MakeGL failed");
218
244
  }
219
245
  }
220
246
  };
@@ -16,7 +16,12 @@ namespace RNSkia {
16
16
 
17
17
  sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
18
18
  if (_skSurface == nullptr) {
19
- _glContext->makeCurrent(_glSurface.get());
19
+ if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
20
+ RNSkLogger::logToConsole(
21
+ "Couldn't create the EGL window surface, the surface will not be "
22
+ "rendered");
23
+ return nullptr;
24
+ }
20
25
  GLint stencil;
21
26
  glGetIntegerv(GL_STENCIL_BITS, &stencil);
22
27
 
@@ -52,7 +57,9 @@ sk_sp<SkSurface> OpenGLWindowContext::getSurface() {
52
57
  }
53
58
 
54
59
  void OpenGLWindowContext::present() {
55
- _glContext->makeCurrent(_glSurface.get());
60
+ if (_glSurface == nullptr || !_glContext->makeCurrent(_glSurface.get())) {
61
+ return;
62
+ }
56
63
  _directContext->flushAndSubmit();
57
64
  _glSurface->present();
58
65
  }
@@ -26,6 +26,9 @@ public:
26
26
  if (_context == EGL_NO_CONTEXT) {
27
27
  return false;
28
28
  }
29
+ if (surface == nullptr || !surface->isValid()) {
30
+ return false;
31
+ }
29
32
  const auto result =
30
33
  eglMakeCurrentIfNecessary(_display, surface->getHandle(),
31
34
  surface->getHandle(), _context) == EGL_TRUE;
@@ -17,7 +17,7 @@ public:
17
17
  }
18
18
  }
19
19
 
20
- bool isValid() { return _surface != EGL_NO_SURFACE; }
20
+ bool isValid() const { return _surface != EGL_NO_SURFACE; }
21
21
 
22
22
  const EGLSurface &getHandle() const { return _surface; }
23
23
 
@@ -79,6 +79,10 @@ public:
79
79
  }
80
80
  auto result =
81
81
  context->makeContextFromNativeSurface(surface, width, height);
82
+ if (result == nullptr) {
83
+ throw std::runtime_error(
84
+ "Couldn't create a Skia context from the native surface");
85
+ }
82
86
  // Return the newly constructed object
83
87
  auto hostObjectInstance =
84
88
  std::make_shared<JsiSkiaContext>(context, std::move(result));
@@ -84,6 +84,9 @@ public:
84
84
  Returns a snapshot of the current surface/canvas
85
85
  */
86
86
  sk_sp<SkImage> makeSnapshot(SkRect *bounds) {
87
+ if (_surface == nullptr) {
88
+ return nullptr;
89
+ }
87
90
  sk_sp<SkImage> image;
88
91
  if (bounds != nullptr) {
89
92
  SkIRect b =
@@ -120,6 +123,9 @@ public:
120
123
  Render to a canvas
121
124
  */
122
125
  bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override {
126
+ if (_surface == nullptr) {
127
+ return false;
128
+ }
123
129
  cb(_surface->getCanvas());
124
130
  return true;
125
131
  };
@@ -10,8 +10,11 @@ const Platform = exports.Platform = {
10
10
  OS: _reactNative.Platform.OS,
11
11
  PixelRatio: _reactNative.PixelRatio.get(),
12
12
  resolveAsset: source => {
13
- // eslint-disable-next-line no-nested-ternary
14
- return (0, _types.isRNModule)(source) ? _reactNative.Image.resolveAssetSource(source).uri : "uri" in source ? source.uri : source.default;
13
+ const asset = (0, _types.unwrapModule)(source);
14
+ if (typeof asset === "string") {
15
+ return asset;
16
+ }
17
+ return (0, _types.isRNModule)(asset) ? _reactNative.Image.resolveAssetSource(asset).uri : asset.uri;
15
18
  },
16
19
  findNodeHandle: _reactNative.findNodeHandle,
17
20
  View: _reactNative.View
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_types","Platform","exports","OS","RNPlatform","PixelRatio","get","resolveAsset","source","isRNModule","Image","resolveAssetSource","uri","default","findNodeHandle","View"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n Platform as RNPlatform,\n findNodeHandle,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n resolveAsset: (source: DataModule) => {\n // eslint-disable-next-line no-nested-ternary\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : \"uri\" in source\n ? source.uri\n : source.default;\n },\n findNodeHandle,\n View,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAIO,MAAME,QAAmB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACjCE,EAAE,EAAEC,qBAAU,CAACD,EAAE;EACjBE,UAAU,EAAEA,uBAAU,CAACC,GAAG,CAAC,CAAC;EAC5BC,YAAY,EAAGC,MAAkB,IAAK;IACpC;IACA,OAAO,IAAAC,iBAAU,EAACD,MAAM,CAAC,GACrBE,kBAAK,CAACC,kBAAkB,CAACH,MAAM,CAAC,CAACI,GAAG,GACpC,KAAK,IAAIJ,MAAM,GACbA,MAAM,CAACI,GAAG,GACVJ,MAAM,CAACK,OAAO;EACtB,CAAC;EACDC,cAAc,EAAdA,2BAAc;EACdC,IAAI,EAAJA;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_types","Platform","exports","OS","RNPlatform","PixelRatio","get","resolveAsset","source","asset","unwrapModule","isRNModule","Image","resolveAssetSource","uri","findNodeHandle","View"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n Platform as RNPlatform,\n findNodeHandle,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule, unwrapModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n resolveAsset: (source: DataModule) => {\n const asset = unwrapModule(source);\n if (typeof asset === \"string\") {\n return asset;\n }\n return isRNModule(asset) ? Image.resolveAssetSource(asset).uri : asset.uri;\n },\n findNodeHandle,\n View,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAIO,MAAME,QAAmB,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACjCE,EAAE,EAAEC,qBAAU,CAACD,EAAE;EACjBE,UAAU,EAAEA,uBAAU,CAACC,GAAG,CAAC,CAAC;EAC5BC,YAAY,EAAGC,MAAkB,IAAK;IACpC,MAAMC,KAAK,GAAG,IAAAC,mBAAY,EAACF,MAAM,CAAC;IAClC,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAOA,KAAK;IACd;IACA,OAAO,IAAAE,iBAAU,EAACF,KAAK,CAAC,GAAGG,kBAAK,CAACC,kBAAkB,CAACJ,KAAK,CAAC,CAACK,GAAG,GAAGL,KAAK,CAACK,GAAG;EAC5E,CAAC;EACDC,cAAc,EAAdA,2BAAc;EACdC,IAAI,EAAJA;AACF,CAAC","ignoreList":[]}
@@ -44,8 +44,12 @@ const Platform = exports.Platform = {
44
44
  PixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
45
45
  // window is not defined on node
46
46
  resolveAsset: source => {
47
- if ((0, _types.isRNModule)(source)) {
48
- if (typeof source === "number" && typeof require === "function") {
47
+ const asset = (0, _types.unwrapModule)(source);
48
+ if (typeof asset === "string") {
49
+ return asset;
50
+ }
51
+ if ((0, _types.isRNModule)(asset)) {
52
+ if (typeof require === "function") {
49
53
  const {
50
54
  getAssetByID
51
55
  } = require("react-native/Libraries/Image/AssetRegistry");
@@ -53,16 +57,13 @@ const Platform = exports.Platform = {
53
57
  httpServerLocation,
54
58
  name,
55
59
  type
56
- } = getAssetByID(source);
60
+ } = getAssetByID(asset);
57
61
  const uri = `${httpServerLocation}/${name}.${type}`;
58
62
  return uri;
59
63
  }
60
64
  throw new Error("Asset source is a number - this is not supported on the web");
61
65
  }
62
- if ("uri" in source) {
63
- return source.uri;
64
- }
65
- return source.default;
66
+ return asset.uri;
66
67
  },
67
68
  findNodeHandle: () => {
68
69
  throw new Error("findNodeHandle is not supported on the web");
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_types","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","View","children","style","rawStyle","useMemo","cssStyles","alignItems","backgroundColor","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","textDecoration","zIndex","createElement","Platform","exports","OS","PixelRatio","window","devicePixelRatio","resolveAsset","source","isRNModule","getAssetByID","httpServerLocation","name","type","uri","Error","findNodeHandle"],"sources":["Platform.web.tsx"],"sourcesContent":["import type { CSSProperties } from \"react\";\nimport React, { useMemo } from \"react\";\nimport type { ViewComponent, ViewProps } from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\n// Layout is observed by the views themselves (see SkiaPictureView.web.tsx):\n// this shim only reproduces react-native-web's default View styling.\nconst View = (({ children, style: rawStyle }: ViewProps) => {\n const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);\n const cssStyles = useMemo(() => {\n return {\n alignItems: \"stretch\" as const,\n backgroundColor: \"transparent\" as const,\n border: \"0 solid black\" as const,\n boxSizing: \"border-box\" as const,\n display: \"flex\" as const,\n flexBasis: \"auto\" as const,\n flexDirection: \"column\" as const,\n flexShrink: 0,\n listStyle: \"none\" as const,\n margin: 0,\n minHeight: 0,\n minWidth: 0,\n padding: 0,\n position: \"relative\" as const,\n textDecoration: \"none\" as const,\n zIndex: 0,\n ...style,\n };\n }, [style]);\n\n return <div style={cssStyles}>{children}</div>;\n}) as unknown as typeof ViewComponent;\n\nexport const Platform: IPlatform = {\n OS: \"web\",\n PixelRatio: typeof window !== \"undefined\" ? window.devicePixelRatio : 1, // window is not defined on node\n resolveAsset: (source: DataModule) => {\n if (isRNModule(source)) {\n if (typeof source === \"number\" && typeof require === \"function\") {\n const {\n getAssetByID,\n } = require(\"react-native/Libraries/Image/AssetRegistry\");\n const { httpServerLocation, name, type } = getAssetByID(source);\n const uri = `${httpServerLocation}/${name}.${type}`;\n return uri;\n }\n throw new Error(\n \"Asset source is a number - this is not supported on the web\"\n );\n }\n if (\"uri\" in source) {\n return source.uri;\n }\n return source.default;\n },\n findNodeHandle: () => {\n throw new Error(\"findNodeHandle is not supported on the web\");\n },\n View,\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAA2C,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAA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Map","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","View","children","style","rawStyle","useMemo","cssStyles","alignItems","backgroundColor","border","boxSizing","display","flexBasis","flexDirection","flexShrink","listStyle","margin","minHeight","minWidth","padding","position","textDecoration","zIndex","createElement","Platform","exports","OS","PixelRatio","window","devicePixelRatio","resolveAsset","source","asset","unwrapModule","isRNModule","getAssetByID","httpServerLocation","name","type","uri","Error","findNodeHandle"],"sources":["Platform.web.tsx"],"sourcesContent":["import type { CSSProperties } from \"react\";\nimport React, { useMemo } from \"react\";\nimport type { ViewComponent, ViewProps } from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule, unwrapModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\n// Layout is observed by the views themselves (see SkiaPictureView.web.tsx):\n// this shim only reproduces react-native-web's default View styling.\nconst View = (({ children, style: rawStyle }: ViewProps) => {\n const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);\n const cssStyles = useMemo(() => {\n return {\n alignItems: \"stretch\" as const,\n backgroundColor: \"transparent\" as const,\n border: \"0 solid black\" as const,\n boxSizing: \"border-box\" as const,\n display: \"flex\" as const,\n flexBasis: \"auto\" as const,\n flexDirection: \"column\" as const,\n flexShrink: 0,\n listStyle: \"none\" as const,\n margin: 0,\n minHeight: 0,\n minWidth: 0,\n padding: 0,\n position: \"relative\" as const,\n textDecoration: \"none\" as const,\n zIndex: 0,\n ...style,\n };\n }, [style]);\n\n return <div style={cssStyles}>{children}</div>;\n}) as unknown as typeof ViewComponent;\n\nexport const Platform: IPlatform = {\n OS: \"web\",\n PixelRatio: typeof window !== \"undefined\" ? window.devicePixelRatio : 1, // window is not defined on node\n resolveAsset: (source: DataModule) => {\n const asset = unwrapModule(source);\n if (typeof asset === \"string\") {\n return asset;\n }\n if (isRNModule(asset)) {\n if (typeof require === \"function\") {\n const {\n getAssetByID,\n } = require(\"react-native/Libraries/Image/AssetRegistry\");\n const { httpServerLocation, name, type } = getAssetByID(asset);\n const uri = `${httpServerLocation}/${name}.${type}`;\n return uri;\n }\n throw new Error(\n \"Asset source is a number - this is not supported on the web\"\n );\n }\n return asset.uri;\n },\n findNodeHandle: () => {\n throw new Error(\"findNodeHandle is not supported on the web\");\n },\n View,\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAAyD,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,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A,KAAK;IACd;IACA,IAAI,IAAAE,iBAAU,EAACF,KAAK,CAAC,EAAE;MACrB,IAAI,OAAOpD,OAAO,KAAK,UAAU,EAAE;QACjC,MAAM;UACJuD;QACF,CAAC,GAAGvD,OAAO,CAAC,4CAA4C,CAAC;QACzD,MAAM;UAAEwD,kBAAkB;UAAEC,IAAI;UAAEC;QAAK,CAAC,GAAGH,YAAY,CAACH,KAAK,CAAC;QAC9D,MAAMO,GAAG,GAAG,GAAGH,kBAAkB,IAAIC,IAAI,IAAIC,IAAI,EAAE;QACnD,OAAOC,GAAG;MACZ;MACA,MAAM,IAAIC,KAAK,CACb,6DACF,CAAC;IACH;IACA,OAAOR,KAAK,CAACO,GAAG;EAClB,CAAC;EACDE,cAAc,EAAEA,CAAA,KAAM;IACpB,MAAM,IAAID,KAAK,CAAC,4CAA4C,CAAC;EAC/D,CAAC;EACDvC;AACF,CAAC","ignoreList":[]}
@@ -1,18 +1,33 @@
1
+ import { FontSlant, FontWeight } from "../types";
1
2
  import type { DataModule, DataSourceParam, SkFontMgr } from "../types";
2
3
  import type { SkTypefaceFontProvider } from "../types/Paragraph/TypefaceFontProvider";
3
4
  /**
4
5
  * Returns a Skia Font object
5
6
  * */
6
7
  export declare const useFont: (font: DataSourceParam, size?: number, onError?: (err: Error) => void) => import("../types").SkFont | null;
7
- type Slant = "normal" | "italic" | "oblique";
8
- type Weight = "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900";
9
- interface RNFontStyle {
8
+ /**
9
+ * React Native style font slant, as found in the `fontStyle` property of
10
+ * `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.
11
+ */
12
+ export type RNFontSlant = "normal" | "italic" | "oblique" | FontSlant;
13
+ /**
14
+ * React Native style font weight, as found in the `fontWeight` property of
15
+ * `TextStyle`. Numeric weights such as the {@link FontWeight} enum values
16
+ * used by the Paragraph API are accepted as well.
17
+ */
18
+ export type RNFontWeight = "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | FontWeight;
19
+ /**
20
+ * Font style accepted by {@link matchFont}.
21
+ * `fontStyle` and `fontWeight` accept both the React Native string values
22
+ * and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same
23
+ * values can be shared with the Paragraph API.
24
+ */
25
+ export interface RNFontStyle {
10
26
  fontFamily: string;
11
27
  fontSize: number;
12
- fontStyle: Slant;
13
- fontWeight: Weight;
28
+ fontStyle: RNFontSlant;
29
+ fontWeight: RNFontWeight;
14
30
  }
15
31
  export declare const matchFont: (inputStyle?: Partial<RNFontStyle>, fontMgr?: SkFontMgr) => import("../types").SkFont;
16
32
  export declare const listFontFamilies: (fontMgr?: SkFontMgr) => string[];
17
33
  export declare const useFonts: (sources: Record<string, DataModule[]>) => SkTypefaceFontProvider | null;
18
- export {};
@@ -26,6 +26,24 @@ const useFont = (font, size = defaultFontSize, onError) => {
26
26
  }
27
27
  }, [size, typeface]);
28
28
  };
29
+
30
+ /**
31
+ * React Native style font slant, as found in the `fontStyle` property of
32
+ * `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.
33
+ */
34
+
35
+ /**
36
+ * React Native style font weight, as found in the `fontWeight` property of
37
+ * `TextStyle`. Numeric weights such as the {@link FontWeight} enum values
38
+ * used by the Paragraph API are accepted as well.
39
+ */
40
+
41
+ /**
42
+ * Font style accepted by {@link matchFont}.
43
+ * `fontStyle` and `fontWeight` accept both the React Native string values
44
+ * and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same
45
+ * values can be shared with the Paragraph API.
46
+ */
29
47
  exports.useFont = useFont;
30
48
  const defaultFontStyle = {
31
49
  fontFamily: "System",
@@ -34,7 +52,9 @@ const defaultFontStyle = {
34
52
  fontWeight: "normal"
35
53
  };
36
54
  const slant = s => {
37
- if (s === "italic") {
55
+ if (typeof s === "number") {
56
+ return s;
57
+ } else if (s === "italic") {
38
58
  return _types.FontSlant.Italic;
39
59
  } else if (s === "oblique") {
40
60
  return _types.FontSlant.Oblique;
@@ -45,11 +65,11 @@ const slant = s => {
45
65
  const weight = fontWeight => {
46
66
  switch (fontWeight) {
47
67
  case "normal":
48
- return 400;
68
+ return _types.FontWeight.Normal;
49
69
  case "bold":
50
- return 700;
70
+ return _types.FontWeight.Bold;
51
71
  default:
52
- return parseInt(fontWeight, 10);
72
+ return typeof fontWeight === "number" ? fontWeight : parseInt(fontWeight, 10);
53
73
  }
54
74
  };
55
75
  const matchFont = (inputStyle = {}, fontMgr = _Skia.Skia.FontMgr.System()) => {
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Skia","_types","_Platform","_Typeface","defaultFontSize","useFont","font","size","onError","typeface","useTypeface","useMemo","Skia","Font","exports","defaultFontStyle","fontFamily","fontSize","fontStyle","fontWeight","slant","s","FontSlant","Italic","Oblique","Upright","weight","parseInt","matchFont","inputStyle","fontMgr","FontMgr","System","style","width","matchFamilyStyle","listFontFamilies","families","Set","i","countFamilies","add","getFamilyName","Array","from","loadTypefaces","typefacesToLoad","promises","Object","keys","flatMap","familyName","map","typefaceToLoad","Data","fromURI","Platform","resolveAsset","then","data","tf","Typeface","MakeFreeTypeFaceFromData","Error","Promise","all","useFonts","sources","setFontMgr","useState","useEffect","result","fMgr","TypefaceFontProvider","Make","forEach","registerFont"],"sources":["Font.ts"],"sourcesContent":["/*global SkiaApi*/\nimport { useEffect, useMemo, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport { FontSlant } from \"../types\";\nimport type { DataModule, DataSourceParam, SkFontMgr } from \"../types\";\nimport { Platform } from \"../../Platform\";\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\n\nimport { useTypeface } from \"./Typeface\";\n\nconst defaultFontSize = 14;\n\n/**\n * Returns a Skia Font object\n * */\nexport const useFont = (\n font: DataSourceParam,\n size = defaultFontSize,\n onError?: (err: Error) => void\n) => {\n const typeface = useTypeface(font, onError);\n return useMemo(() => {\n if (typeface) {\n return Skia.Font(typeface, size);\n } else {\n return null;\n }\n }, [size, typeface]);\n};\n\ntype Slant = \"normal\" | \"italic\" | \"oblique\";\ntype Weight =\n | \"normal\"\n | \"bold\"\n | \"100\"\n | \"200\"\n | \"300\"\n | \"400\"\n | \"500\"\n | \"600\"\n | \"700\"\n | \"800\"\n | \"900\";\n\ninterface RNFontStyle {\n fontFamily: string;\n fontSize: number;\n fontStyle: Slant;\n fontWeight: Weight;\n}\n\nconst defaultFontStyle: RNFontStyle = {\n fontFamily: \"System\",\n fontSize: defaultFontSize,\n fontStyle: \"normal\",\n fontWeight: \"normal\",\n};\n\nconst slant = (s: Slant) => {\n if (s === \"italic\") {\n return FontSlant.Italic;\n } else if (s === \"oblique\") {\n return FontSlant.Oblique;\n } else {\n return FontSlant.Upright;\n }\n};\n\nconst weight = (fontWeight: Weight) => {\n switch (fontWeight) {\n case \"normal\":\n return 400;\n case \"bold\":\n return 700;\n default:\n return parseInt(fontWeight, 10);\n }\n};\n\nexport const matchFont = (\n inputStyle: Partial<RNFontStyle> = {},\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const fontStyle = {\n ...defaultFontStyle,\n ...inputStyle,\n };\n const style = {\n weight: weight(fontStyle.fontWeight),\n width: 5,\n slant: slant(fontStyle.fontStyle),\n };\n const typeface = fontMgr.matchFamilyStyle(fontStyle.fontFamily, style);\n return Skia.Font(typeface, fontStyle.fontSize);\n};\n\nexport const listFontFamilies = (\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const families = new Set<string>();\n for (let i = 0; i < fontMgr.countFamilies(); i++) {\n families.add(fontMgr.getFamilyName(i));\n }\n return Array.from(families);\n};\n\nconst loadTypefaces = (typefacesToLoad: Record<string, DataModule[]>) => {\n const promises = Object.keys(typefacesToLoad).flatMap((familyName) => {\n return typefacesToLoad[familyName].map((typefaceToLoad) => {\n return Skia.Data.fromURI(Platform.resolveAsset(typefaceToLoad)).then(\n (data) => {\n const tf = Skia.Typeface.MakeFreeTypeFaceFromData(data);\n if (tf === null) {\n throw new Error(`Couldn't create typeface for ${familyName}`);\n }\n return [familyName, tf] as const;\n }\n );\n });\n });\n return Promise.all(promises);\n};\n\nexport const useFonts = (sources: Record<string, DataModule[]>) => {\n const [fontMgr, setFontMgr] = useState<null | SkTypefaceFontProvider>(null);\n\n useEffect(() => {\n loadTypefaces(sources).then((result) => {\n const fMgr = Skia.TypefaceFontProvider.Make();\n result.forEach(([familyName, typeface]) => {\n fMgr.registerFont(typeface, familyName);\n });\n setFontMgr(fMgr);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return fontMgr;\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AAGA,IAAAI,SAAA,GAAAJ,OAAA;AATA;;AAWA,MAAMK,eAAe,GAAG,EAAE;;AAE1B;AACA;AACA;AACO,MAAMC,OAAO,GAAGA,CACrBC,IAAqB,EACrBC,IAAI,GAAGH,eAAe,EACtBI,OAA8B,KAC3B;EACH,MAAMC,QAAQ,GAAG,IAAAC,qBAAW,EAACJ,IAAI,EAAEE,OAAO,CAAC;EAC3C,OAAO,IAAAG,cAAO,EAAC,MAAM;IACnB,IAAIF,QAAQ,EAAE;MACZ,OAAOG,UAAI,CAACC,IAAI,CAACJ,QAAQ,EAAEF,IAAI,CAAC;IAClC,CAAC,MAAM;MACL,OAAO,IAAI;IACb;EACF,CAAC,EAAE,CAACA,IAAI,EAAEE,QAAQ,CAAC,CAAC;AACtB,CAAC;AAACK,OAAA,CAAAT,OAAA,GAAAA,OAAA;AAuBF,MAAMU,gBAA6B,GAAG;EACpCC,UAAU,EAAE,QAAQ;EACpBC,QAAQ,EAAEb,eAAe;EACzBc,SAAS,EAAE,QAAQ;EACnBC,UAAU,EAAE;AACd,CAAC;AAED,MAAMC,KAAK,GAAIC,CAAQ,IAAK;EAC1B,IAAIA,CAAC,KAAK,QAA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AE1C,QAAQ,CAAC,KAAK;QACzC+D,IAAI,CAACI,YAAY,CAACnE,QAAQ,EAAE0C,UAAU,CAAC;MACzC,CAAC,CAAC;MACFiB,UAAU,CAACI,IAAI,CAAC;IAClB,CAAC,CAAC;IACF;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO1C,OAAO;AAChB,CAAC;AAAChB,OAAA,CAAAoD,QAAA,GAAAA,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_Skia","_types","_Platform","_Typeface","defaultFontSize","useFont","font","size","onError","typeface","useTypeface","useMemo","Skia","Font","exports","defaultFontStyle","fontFamily","fontSize","fontStyle","fontWeight","slant","s","FontSlant","Italic","Oblique","Upright","weight","FontWeight","Normal","Bold","parseInt","matchFont","inputStyle","fontMgr","FontMgr","System","style","width","matchFamilyStyle","listFontFamilies","families","Set","i","countFamilies","add","getFamilyName","Array","from","loadTypefaces","typefacesToLoad","promises","Object","keys","flatMap","familyName","map","typefaceToLoad","Data","fromURI","Platform","resolveAsset","then","data","tf","Typeface","MakeFreeTypeFaceFromData","Error","Promise","all","useFonts","sources","setFontMgr","useState","useEffect","result","fMgr","TypefaceFontProvider","Make","forEach","registerFont"],"sources":["Font.ts"],"sourcesContent":["/*global SkiaApi*/\nimport { useEffect, useMemo, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport { FontSlant, FontWeight } from \"../types\";\nimport type { DataModule, DataSourceParam, SkFontMgr } from \"../types\";\nimport { Platform } from \"../../Platform\";\nimport type { SkTypefaceFontProvider } from \"../types/Paragraph/TypefaceFontProvider\";\n\nimport { useTypeface } from \"./Typeface\";\n\nconst defaultFontSize = 14;\n\n/**\n * Returns a Skia Font object\n * */\nexport const useFont = (\n font: DataSourceParam,\n size = defaultFontSize,\n onError?: (err: Error) => void\n) => {\n const typeface = useTypeface(font, onError);\n return useMemo(() => {\n if (typeface) {\n return Skia.Font(typeface, size);\n } else {\n return null;\n }\n }, [size, typeface]);\n};\n\n/**\n * React Native style font slant, as found in the `fontStyle` property of\n * `TextStyle`. The Skia {@link FontSlant} enum is accepted as well.\n */\nexport type RNFontSlant = \"normal\" | \"italic\" | \"oblique\" | FontSlant;\n\n/**\n * React Native style font weight, as found in the `fontWeight` property of\n * `TextStyle`. Numeric weights such as the {@link FontWeight} enum values\n * used by the Paragraph API are accepted as well.\n */\nexport type RNFontWeight =\n | \"normal\"\n | \"bold\"\n | \"100\"\n | \"200\"\n | \"300\"\n | \"400\"\n | \"500\"\n | \"600\"\n | \"700\"\n | \"800\"\n | \"900\"\n | FontWeight;\n\n/**\n * Font style accepted by {@link matchFont}.\n * `fontStyle` and `fontWeight` accept both the React Native string values\n * and the Skia enums ({@link FontSlant} and {@link FontWeight}), so the same\n * values can be shared with the Paragraph API.\n */\nexport interface RNFontStyle {\n fontFamily: string;\n fontSize: number;\n fontStyle: RNFontSlant;\n fontWeight: RNFontWeight;\n}\n\nconst defaultFontStyle: RNFontStyle = {\n fontFamily: \"System\",\n fontSize: defaultFontSize,\n fontStyle: \"normal\",\n fontWeight: \"normal\",\n};\n\nconst slant = (s: RNFontSlant): FontSlant => {\n if (typeof s === \"number\") {\n return s;\n } else if (s === \"italic\") {\n return FontSlant.Italic;\n } else if (s === \"oblique\") {\n return FontSlant.Oblique;\n } else {\n return FontSlant.Upright;\n }\n};\n\nconst weight = (fontWeight: RNFontWeight): FontWeight => {\n switch (fontWeight) {\n case \"normal\":\n return FontWeight.Normal;\n case \"bold\":\n return FontWeight.Bold;\n default:\n return typeof fontWeight === \"number\"\n ? fontWeight\n : (parseInt(fontWeight, 10) as FontWeight);\n }\n};\n\nexport const matchFont = (\n inputStyle: Partial<RNFontStyle> = {},\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const fontStyle = {\n ...defaultFontStyle,\n ...inputStyle,\n };\n const style = {\n weight: weight(fontStyle.fontWeight),\n width: 5,\n slant: slant(fontStyle.fontStyle),\n };\n const typeface = fontMgr.matchFamilyStyle(fontStyle.fontFamily, style);\n return Skia.Font(typeface, fontStyle.fontSize);\n};\n\nexport const listFontFamilies = (\n fontMgr: SkFontMgr = Skia.FontMgr.System()\n) => {\n const families = new Set<string>();\n for (let i = 0; i < fontMgr.countFamilies(); i++) {\n families.add(fontMgr.getFamilyName(i));\n }\n return Array.from(families);\n};\n\nconst loadTypefaces = (typefacesToLoad: Record<string, DataModule[]>) => {\n const promises = Object.keys(typefacesToLoad).flatMap((familyName) => {\n return typefacesToLoad[familyName].map((typefaceToLoad) => {\n return Skia.Data.fromURI(Platform.resolveAsset(typefaceToLoad)).then(\n (data) => {\n const tf = Skia.Typeface.MakeFreeTypeFaceFromData(data);\n if (tf === null) {\n throw new Error(`Couldn't create typeface for ${familyName}`);\n }\n return [familyName, tf] as const;\n }\n );\n });\n });\n return Promise.all(promises);\n};\n\nexport const useFonts = (sources: Record<string, DataModule[]>) => {\n const [fontMgr, setFontMgr] = useState<null | SkTypefaceFontProvider>(null);\n\n useEffect(() => {\n loadTypefaces(sources).then((result) => {\n const fMgr = Skia.TypefaceFontProvider.Make();\n result.forEach(([familyName, typeface]) => {\n fMgr.registerFont(typeface, familyName);\n });\n setFontMgr(fMgr);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return fontMgr;\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AAGA,IAAAI,SAAA,GAAAJ,OAAA;AATA;;AAWA,MAAMK,eAAe,GAAG,EAAE;;AAE1B;AACA;AACA;AACO,MAAMC,OAAO,GAAGA,CACrBC,IAAqB,EACrBC,IAAI,GAAGH,eAAe,EACtBI,OAA8B,KAC3B;EACH,MAAMC,QAAQ,GAAG,IAAAC,qBAAW,EAACJ,IAAI,EAAEE,OAAO,CAAC;EAC3C,OAAO,IAAAG,cAAO,EAAC,MAAM;IACnB,IAAIF,QAAQ,EAAE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D,QAAQ,CAACC,wBAAwB,CAACH,IAAI,CAAC;QACvD,IAAIC,EAAE,KAAK,IAAI,EAAE;UACf,MAAM,IAAIG,KAAK,CAAC,gCAAgCZ,UAAU,EAAE,CAAC;QAC/D;QACA,OAAO,CAACA,UAAU,EAAES,EAAE,CAAC;MACzB,CACF,CAAC;IACH,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOI,OAAO,CAACC,GAAG,CAAClB,QAAQ,CAAC;AAC9B,CAAC;AAEM,MAAMmB,QAAQ,GAAIC,OAAqC,IAAK;EACjE,MAAM,CAACrC,OAAO,EAAEsC,UAAU,CAAC,GAAG,IAAAC,eAAQ,EAAgC,IAAI,CAAC;EAE3E,IAAAC,gBAAS,EAAC,MAAM;IACdzB,aAAa,CAACsB,OAAO,CAAC,CAACT,IAAI,CAAEa,MAAM,IAAK;MACtC,MAAMC,IAAI,GAAG/D,UAAI,CAACgE,oBAAoB,CAACC,IAAI,CAAC,CAAC;MAC7CH,MAAM,CAACI,OAAO,CAAC,CAAC,CAACxB,UAAU,EAAE7C,QAAQ,CAAC,KAAK;QACzCkE,IAAI,CAACI,YAAY,CAACtE,QAAQ,EAAE6C,UAAU,CAAC;MACzC,CAAC,CAAC;MACFiB,UAAU,CAACI,IAAI,CAAC;IAClB,CAAC,CAAC;IACF;EACF,CAAC,EAAE,EAAE,CAAC;EACN,OAAO1C,OAAO;AAChB,CAAC;AAACnB,OAAA,CAAAuD,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1,17 +1,18 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
2
  export type SkData = SkJSIInstance<"Data">;
3
3
  type RNModule = number;
4
- type ESModule = {
5
- __esModule: true;
6
- default: string;
7
- };
8
4
  type MetroAsset = {
9
5
  uri: string;
10
6
  width: number;
11
7
  height: number;
12
8
  };
9
+ type ESModule = {
10
+ __esModule: true;
11
+ default: RNModule | MetroAsset | string;
12
+ };
13
13
  export type DataModule = RNModule | ESModule | MetroAsset;
14
14
  export type DataSource = DataModule | string | Uint8Array;
15
15
  export type DataSourceParam = DataSource | null | undefined;
16
16
  export declare const isRNModule: (mod: DataModule) => mod is RNModule;
17
+ export declare const unwrapModule: (mod: DataModule) => RNModule | MetroAsset | string;
17
18
  export {};
@@ -3,7 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isRNModule = void 0;
6
+ exports.unwrapModule = exports.isRNModule = void 0;
7
7
  const isRNModule = mod => typeof mod === "number";
8
+
9
+ // Since Expo SDK 52, on web, require() may return an ES module interop
10
+ // object ({ default: <asset> }) instead of the asset itself.
11
+ // See https://github.com/Shopify/react-native-skia/issues/2784
8
12
  exports.isRNModule = isRNModule;
13
+ const unwrapModule = mod => typeof mod === "object" && mod !== null && "default" in mod ? mod.default : mod;
14
+ exports.unwrapModule = unwrapModule;
9
15
  //# sourceMappingURL=Data.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["isRNModule","mod","exports"],"sources":["Data.ts"],"sourcesContent":["import type { SkJSIInstance } from \"../JsiInstance\";\n\nexport type SkData = SkJSIInstance<\"Data\">;\n\ntype RNModule = number;\ntype ESModule = {\n __esModule: true;\n default: string;\n};\ntype MetroAsset = {\n uri: string;\n width: number;\n height: number;\n};\n\nexport type DataModule = RNModule | ESModule | MetroAsset;\nexport type DataSource = DataModule | string | Uint8Array;\nexport type DataSourceParam = DataSource | null | undefined;\n\nexport const isRNModule = (mod: DataModule): mod is RNModule =>\n typeof mod === \"number\";\n"],"mappings":";;;;;;AAmBO,MAAMA,UAAU,GAAIC,GAAe,IACxC,OAAOA,GAAG,KAAK,QAAQ;AAACC,OAAA,CAAAF,UAAA,GAAAA,UAAA","ignoreList":[]}
1
+ {"version":3,"names":["isRNModule","mod","exports","unwrapModule","default"],"sources":["Data.ts"],"sourcesContent":["import type { SkJSIInstance } from \"../JsiInstance\";\n\nexport type SkData = SkJSIInstance<\"Data\">;\n\ntype RNModule = number;\ntype MetroAsset = {\n uri: string;\n width: number;\n height: number;\n};\ntype ESModule = {\n __esModule: true;\n default: RNModule | MetroAsset | string;\n};\n\nexport type DataModule = RNModule | ESModule | MetroAsset;\nexport type DataSource = DataModule | string | Uint8Array;\nexport type DataSourceParam = DataSource | null | undefined;\n\nexport const isRNModule = (mod: DataModule): mod is RNModule =>\n typeof mod === \"number\";\n\n// Since Expo SDK 52, on web, require() may return an ES module interop\n// object ({ default: <asset> }) instead of the asset itself.\n// See https://github.com/Shopify/react-native-skia/issues/2784\nexport const unwrapModule = (\n mod: DataModule\n): RNModule | MetroAsset | string =>\n typeof mod === \"object\" && mod !== null && \"default\" in mod\n ? mod.default\n : mod;\n"],"mappings":";;;;;;AAmBO,MAAMA,UAAU,GAAIC,GAAe,IACxC,OAAOA,GAAG,KAAK,QAAQ;;AAEzB;AACA;AACA;AAAAC,OAAA,CAAAF,UAAA,GAAAA,UAAA;AACO,MAAMG,YAAY,GACvBF,GAAe,IAEf,OAAOA,GAAG,KAAK,QAAQ,IAAIA,GAAG,KAAK,IAAI,IAAI,SAAS,IAAIA,GAAG,GACvDA,GAAG,CAACG,OAAO,GACXH,GAAG;AAACC,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -5,7 +5,7 @@ import { JsiSkRect } from "./JsiSkRect";
5
5
  import { JsiSkTypeface } from "./JsiSkTypeface";
6
6
  export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
7
7
  constructor(CanvasKit: CanvasKit, ref: Font);
8
- measureText(_text: string, _paint?: SkPaint | undefined): SkRect;
8
+ measureText(text: string, paint?: SkPaint | undefined): SkRect;
9
9
  getTextWidth(text: string, paint?: SkPaint | undefined): number;
10
10
  getMetrics(): {
11
11
  ascent: number;
@@ -13,8 +13,49 @@ class JsiSkFont extends _Host.HostObject {
13
13
  constructor(CanvasKit, ref) {
14
14
  super(CanvasKit, ref, "Font");
15
15
  }
16
- measureText(_text, _paint) {
17
- return (0, _Host.throwNotImplementedOnRNWeb)();
16
+ measureText(text, paint) {
17
+ // CanvasKit doesn't expose SkFont::measureText directly, so we polyfill
18
+ // it: for each glyph we take its ink bounds (relative to its own origin),
19
+ // offset it by the accumulated advance, and union the results. This
20
+ // matches the bounds computed natively by SkFont::measureText.
21
+ const glyphs = this.ref.getGlyphIDs(text);
22
+ if (glyphs.length === 0) {
23
+ return new _JsiSkRect.JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
24
+ }
25
+ const skPaint = paint ? _JsiSkPaint.JsiSkPaint.fromValue(paint) : null;
26
+ // Flattened rectangles: 4 floats (left, top, right, bottom) per glyph.
27
+ const bounds = this.ref.getGlyphBounds(glyphs, skPaint);
28
+ const advances = this.ref.getGlyphWidths(glyphs, skPaint);
29
+ let left = 0;
30
+ let top = 0;
31
+ let right = 0;
32
+ let bottom = 0;
33
+ let isEmpty = true;
34
+ let xPos = 0;
35
+ for (let i = 0; i < glyphs.length; i++) {
36
+ const l = bounds[i * 4] + xPos;
37
+ const t = bounds[i * 4 + 1];
38
+ const r = bounds[i * 4 + 2] + xPos;
39
+ const b = bounds[i * 4 + 3];
40
+ xPos += advances[i];
41
+ // Skip empty glyph bounds (e.g. whitespace), like SkRect::join does.
42
+ if (l >= r || t >= b) {
43
+ continue;
44
+ }
45
+ if (isEmpty) {
46
+ left = l;
47
+ top = t;
48
+ right = r;
49
+ bottom = b;
50
+ isEmpty = false;
51
+ } else {
52
+ left = Math.min(left, l);
53
+ top = Math.min(top, t);
54
+ right = Math.max(right, r);
55
+ bottom = Math.max(bottom, b);
56
+ }
57
+ }
58
+ return new _JsiSkRect.JsiSkRect(this.CanvasKit, this.CanvasKit.LTRBRect(left, top, right, bottom));
18
59
  }
19
60
  getTextWidth(text, paint) {
20
61
  const ids = this.getGlyphIDs(text);
@@ -1 +1 @@
1
- {"version":3,"names":["_Host","require","_JsiSkPaint","_JsiSkPoint","_JsiSkRect","_JsiSkTypeface","JsiSkFont","HostObject","constructor","CanvasKit","ref","measureText","_text","_paint","throwNotImplementedOnRNWeb","getTextWidth","text","paint","ids","getGlyphIDs","widths","getGlyphWidths","reduce","a","b","getMetrics","result","ascent","descent","leading","bounds","JsiSkRect","undefined","str","numCodePoints","glyphs","JsiSkPaint","fromValue","getGlyphIntercepts","positions","top","bottom","map","p","Array","from","JsiSkPoint","flat","getScaleX","getSize","getSkewX","isEmbolden","getTypeface","tf","JsiSkTypeface","setEdging","edging","getEnum","setEmbeddedBitmaps","embeddedBitmaps","setHinting","hinting","setLinearMetrics","linearMetrics","setScaleX","sx","setSize","points","setSkewX","setEmbolden","embolden","setSubpixel","subpixel","setTypeface","face","exports"],"sources":["JsiSkFont.ts"],"sourcesContent":["import type { CanvasKit, Font } from \"canvaskit-wasm\";\n\nimport type {\n FontEdging,\n FontHinting,\n SkFont,\n SkPaint,\n SkPoint,\n SkRect,\n SkTypeface,\n} from \"../types\";\n\nimport { HostObject, getEnum, throwNotImplementedOnRNWeb } from \"./Host\";\nimport { JsiSkPaint } from \"./JsiSkPaint\";\nimport { JsiSkPoint } from \"./JsiSkPoint\";\nimport { JsiSkRect } from \"./JsiSkRect\";\nimport { JsiSkTypeface } from \"./JsiSkTypeface\";\n\nexport class JsiSkFont extends HostObject<Font, \"Font\"> implements SkFont {\n constructor(CanvasKit: CanvasKit, ref: Font) {\n super(CanvasKit, ref, \"Font\");\n }\n\n measureText(_text: string, _paint?: SkPaint | undefined) {\n return throwNotImplementedOnRNWeb<SkRect>();\n }\n\n getTextWidth(text: string, paint?: SkPaint | undefined) {\n const ids = this.getGlyphIDs(text);\n const widths = this.getGlyphWidths(ids, paint);\n return widths.reduce((a, b) => a + b, 0);\n }\n\n getMetrics() {\n const result = this.ref.getMetrics();\n return {\n ascent: result.ascent,\n descent: result.descent,\n leading: result.leading,\n bounds: result.bounds\n ? new JsiSkRect(this.CanvasKit, result.bounds)\n : undefined,\n };\n }\n\n getGlyphIDs(str: string, numCodePoints?: number) {\n // TODO: Fix return value in the C++ implementation\n return [...this.ref.getGlyphIDs(str, numCodePoints)];\n }\n\n // TODO: Fix return value in the C++ implementation, it return float32\n getGlyphWidths(glyphs: number[], paint?: SkPaint | null) {\n return [\n ...this.ref.getGlyphWidths(\n glyphs,\n paint ? JsiSkPaint.fromValue(paint) : null\n ),\n ];\n }\n\n getGlyphIntercepts(\n glyphs: number[],\n positions: SkPoint[],\n top: number,\n bottom: number\n ) {\n return [\n ...this.ref.getGlyphIntercepts(\n glyphs,\n positions.map((p) => Array.from(JsiSkPoint.fromValue(p))).flat(),\n top,\n bottom\n ),\n ];\n }\n\n getScaleX() {\n return this.ref.getScaleX();\n }\n\n getSize() {\n return this.ref.getSize();\n }\n\n getSkewX() {\n return this.ref.getSkewX();\n }\n\n isEmbolden() {\n return this.ref.isEmbolden();\n }\n\n getTypeface() {\n const tf = this.ref.getTypeface();\n return tf ? new JsiSkTypeface(this.CanvasKit, tf) : null;\n }\n\n setEdging(edging: FontEdging) {\n this.ref.setEdging(getEnum(this.CanvasKit, \"FontEdging\", edging));\n }\n\n setEmbeddedBitmaps(embeddedBitmaps: boolean) {\n this.ref.setEmbeddedBitmaps(embeddedBitmaps);\n }\n\n setHinting(hinting: FontHinting) {\n this.ref.setHinting(getEnum(this.CanvasKit, \"FontHinting\", hinting));\n }\n\n setLinearMetrics(linearMetrics: boolean) {\n this.ref.setLinearMetrics(linearMetrics);\n }\n\n setScaleX(sx: number) {\n this.ref.setScaleX(sx);\n }\n\n setSize(points: number) {\n this.ref.setSize(points);\n }\n\n setSkewX(sx: number) {\n this.ref.setSkewX(sx);\n }\n\n setEmbolden(embolden: boolean) {\n this.ref.setEmbolden(embolden);\n }\n\n setSubpixel(subpixel: boolean) {\n this.ref.setSubpixel(subpixel);\n }\n\n setTypeface(face: SkTypeface | null) {\n this.ref.setTypeface(face ? JsiSkTypeface.fromValue(face) : null);\n }\n}\n"],"mappings":";;;;;;AAYA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,G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kBAAkB,CAACC,eAAe,CAAC;EAC9C;EAEAC,UAAUA,CAACC,OAAoB,EAAE;IAC/B,IAAI,CAACnD,GAAG,CAACkD,UAAU,CAAC,IAAAH,aAAO,EAAC,IAAI,CAAChD,SAAS,EAAE,aAAa,EAAEoD,OAAO,CAAC,CAAC;EACtE;EAEAC,gBAAgBA,CAACC,aAAsB,EAAE;IACvC,IAAI,CAACrD,GAAG,CAACoD,gBAAgB,CAACC,aAAa,CAAC;EAC1C;EAEAC,SAASA,CAACC,EAAU,EAAE;IACpB,IAAI,CAACvD,GAAG,CAACsD,SAAS,CAACC,EAAE,CAAC;EACxB;EAEAC,OAAOA,CAACC,MAAc,EAAE;IACtB,IAAI,CAACzD,GAAG,CAACwD,OAAO,CAACC,MAAM,CAAC;EAC1B;EAEAC,QAAQA,CAACH,EAAU,EAAE;IACnB,IAAI,CAACvD,GAAG,CAAC0D,QAAQ,CAACH,EAAE,CAAC;EACvB;EAEAI,WAAWA,CAACC,QAAiB,EAAE;IAC7B,IAAI,CAAC5D,GAAG,CAAC2D,WAAW,CAACC,QAAQ,CAAC;EAChC;EAEAC,WAAWA,CAACC,QAAiB,EAAE;IAC7B,IAAI,CAAC9D,GAAG,CAAC6D,WAAW,CAACC,QAAQ,CAAC;EAChC;EAEAC,WAAWA,CAACC,IAAuB,EAAE;IACnC,IAAI,CAAChE,GAAG,CAAC+D,WAAW,CAACC,IAAI,GAAGpB,4BAAa,CAACjB,SAAS,CAACqC,IAAI,CAAC,GAAG,IAAI,CAAC;EACnE;AACF;AAACC,OAAA,CAAArE,SAAA,GAAAA,SAAA","ignoreList":[]}
1
+ {"version":3,"names":["_Host","require","_JsiSkPaint","_JsiSkPoint","_JsiSkRect","_JsiSkTypeface","JsiSkFont","HostObject","constructor","CanvasKit","ref","measureText","text","paint","glyphs","getGlyphIDs","length","JsiSkRect","XYWHRect","skPaint","JsiSkPaint","fromValue","bounds","getGlyphBounds","advances","getGlyphWidths","left","top","right","bottom","isEmpty","xPos","i","l","t","r","b","Math","min","max","LTRBRect","getTextWidth","ids","widths","reduce","a","getMetrics","result","ascent","descent","leading","undefined","str","numCodePoints","getGlyphIntercepts","positions","map","p","Array","from","JsiSkPoint","flat","getScaleX","getSize","getSkewX","isEmbolden","getTypeface","tf","JsiSkTypeface","setEdging","edging","getEnum","setEmbeddedBitmaps","embeddedBitmaps","setHinting","hinting","setLinearMetrics","linearMetrics","setScaleX","sx","setSize","points","setSkewX","setEmbolden","embolden","setSubpixel","subpixel","setTypeface","face","exports"],"sources":["JsiSkFont.ts"],"sourcesContent":["import type { CanvasKit, Font, Paint } from \"canvaskit-wasm\";\n\nimport type {\n FontEdging,\n FontHinting,\n SkFont,\n SkPaint,\n SkPoint,\n SkRect,\n SkTypeface,\n} from \"../types\";\n\nimport { HostObject, getEnum } from \"./Host\";\nimport { JsiSkPaint } from \"./JsiSkPaint\";\nimport { JsiSkPoint } from \"./JsiSkPoint\";\nimport { JsiSkRect } from \"./JsiSkRect\";\nimport { JsiSkTypeface } from \"./JsiSkTypeface\";\n\nexport class JsiSkFont extends HostObject<Font, \"Font\"> implements SkFont {\n constructor(CanvasKit: CanvasKit, ref: Font) {\n super(CanvasKit, ref, \"Font\");\n }\n\n measureText(text: string, paint?: SkPaint | undefined): SkRect {\n // CanvasKit doesn't expose SkFont::measureText directly, so we polyfill\n // it: for each glyph we take its ink bounds (relative to its own origin),\n // offset it by the accumulated advance, and union the results. This\n // matches the bounds computed natively by SkFont::measureText.\n const glyphs = this.ref.getGlyphIDs(text);\n if (glyphs.length === 0) {\n return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));\n }\n const skPaint = paint ? JsiSkPaint.fromValue<Paint>(paint) : null;\n // Flattened rectangles: 4 floats (left, top, right, bottom) per glyph.\n const bounds = this.ref.getGlyphBounds(glyphs, skPaint);\n const advances = this.ref.getGlyphWidths(glyphs, skPaint);\n let left = 0;\n let top = 0;\n let right = 0;\n let bottom = 0;\n let isEmpty = true;\n let xPos = 0;\n for (let i = 0; i < glyphs.length; i++) {\n const l = bounds[i * 4] + xPos;\n const t = bounds[i * 4 + 1];\n const r = bounds[i * 4 + 2] + xPos;\n const b = bounds[i * 4 + 3];\n xPos += advances[i];\n // Skip empty glyph bounds (e.g. whitespace), like SkRect::join does.\n if (l >= r || t >= b) {\n continue;\n }\n if (isEmpty) {\n left = l;\n top = t;\n right = r;\n bottom = b;\n isEmpty = false;\n } else {\n left = Math.min(left, l);\n top = Math.min(top, t);\n right = Math.max(right, r);\n bottom = Math.max(bottom, b);\n }\n }\n return new JsiSkRect(\n this.CanvasKit,\n this.CanvasKit.LTRBRect(left, top, right, bottom)\n );\n }\n\n getTextWidth(text: string, paint?: SkPaint | undefined) {\n const ids = this.getGlyphIDs(text);\n const widths = this.getGlyphWidths(ids, paint);\n return widths.reduce((a, b) => a + b, 0);\n }\n\n getMetrics() {\n const result = this.ref.getMetrics();\n return {\n ascent: result.ascent,\n descent: result.descent,\n leading: result.leading,\n bounds: result.bounds\n ? new JsiSkRect(this.CanvasKit, result.bounds)\n : undefined,\n };\n }\n\n getGlyphIDs(str: string, numCodePoints?: number) {\n // TODO: Fix return value in the C++ implementation\n return [...this.ref.getGlyphIDs(str, numCodePoints)];\n }\n\n // TODO: Fix return value in the C++ implementation, it return float32\n getGlyphWidths(glyphs: number[], paint?: SkPaint | null) {\n return [\n ...this.ref.getGlyphWidths(\n glyphs,\n paint ? JsiSkPaint.fromValue(paint) : null\n ),\n ];\n }\n\n getGlyphIntercepts(\n glyphs: number[],\n positions: SkPoint[],\n top: number,\n bottom: number\n ) {\n return [\n ...this.ref.getGlyphIntercepts(\n glyphs,\n positions.map((p) => Array.from(JsiSkPoint.fromValue(p))).flat(),\n top,\n bottom\n ),\n ];\n }\n\n getScaleX() {\n return this.ref.getScaleX();\n }\n\n getSize() {\n return this.ref.getSize();\n }\n\n getSkewX() {\n return this.ref.getSkewX();\n }\n\n isEmbolden() {\n return this.ref.isEmbolden();\n }\n\n getTypeface() {\n const tf = this.ref.getTypeface();\n return tf ? new JsiSkTypeface(this.CanvasKit, tf) : null;\n }\n\n setEdging(edging: FontEdging) {\n this.ref.setEdging(getEnum(this.CanvasKit, \"FontEdging\", edging));\n }\n\n setEmbeddedBitmaps(embeddedBitmaps: boolean) {\n this.ref.setEmbeddedBitmaps(embeddedBitmaps);\n }\n\n setHinting(hinting: FontHinting) {\n this.ref.setHinting(getEnum(this.CanvasKit, \"FontHinting\", hinting));\n }\n\n setLinearMetrics(linearMetrics: boolean) {\n this.ref.setLinearMetrics(linearMetrics);\n }\n\n setScaleX(sx: number) {\n this.ref.setScaleX(sx);\n }\n\n setSize(points: number) {\n this.ref.setSize(points);\n }\n\n setSkewX(sx: number) {\n this.ref.setSkewX(sx);\n }\n\n setEmbolden(embolden: boolean) {\n this.ref.setEmbolden(embolden);\n }\n\n setSubpixel(subpixel: boolean) {\n this.ref.setSubpixel(subpixel);\n }\n\n setTypeface(face: SkTypeface | null) {\n this.ref.setTypeface(face ? JsiSkTypeface.fromValue(face) : null);\n }\n}\n"],"mappings":";;;;;;AAYA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAEO,MAAMK,SAAS,SAASC,gBAAU,CAAiC;EACxEC,WAAWA,CAACC,SAAoB,EAAEC,GAAS,EAAE;IAC3C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,MAAM,CAAC;EAC/B;EAEAC,WAAWA,CAACC,IAAY,EAAEC,KAA2B,EAAU;IAC7D;IACA;IACA;IACA;IACA,MAAMC,MAAM,GAAG,IAAI,CAACJ,GAAG,CAACK,WAAW,CAACH,IAAI,CAAC;IACzC,IAAIE,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;MACvB,OAAO,IAAIC,oBAAS,CAAC,IAAI,CAACR,SAAS,EAAE,IAAI,C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RNPlatform, findNodeHandle, View } from "react-native";
2
- import { isRNModule } from "../skia/types";
2
+ import { isRNModule, unwrapModule } from "../skia/types";
3
3
  export const Platform = {
4
4
  OS: RNPlatform.OS,
5
5
  PixelRatio: PixelRatio.get(),
6
6
  resolveAsset: source => {
7
- // eslint-disable-next-line no-nested-ternary
8
- return isRNModule(source) ? Image.resolveAssetSource(source).uri : "uri" in source ? source.uri : source.default;
7
+ const asset = unwrapModule(source);
8
+ if (typeof asset === "string") {
9
+ return asset;
10
+ }
11
+ return isRNModule(asset) ? Image.resolveAssetSource(asset).uri : asset.uri;
9
12
  },
10
13
  findNodeHandle,
11
14
  View
@@ -1 +1 @@
1
- {"version":3,"names":["Image","PixelRatio","Platform","RNPlatform","findNodeHandle","View","isRNModule","OS","get","resolveAsset","source","resolveAssetSource","uri","default"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n Platform as RNPlatform,\n findNodeHandle,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n resolveAsset: (source: DataModule) => {\n // eslint-disable-next-line no-nested-ternary\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : \"uri\" in source\n ? source.uri\n : source.default;\n },\n findNodeHandle,\n View,\n};\n"],"mappings":"AAAA,SACEA,KAAK,EACLC,UAAU,EACVC,QAAQ,IAAIC,UAAU,EACtBC,cAAc,EACdC,IAAI,QACC,cAAc;AAGrB,SAASC,UAAU,QAAQ,eAAe;AAI1C,OAAO,MAAMJ,QAAmB,GAAG;EACjCK,EAAE,EAAEJ,UAAU,CAACI,EAAE;EACjBN,UAAU,EAAEA,UAAU,CAACO,GAAG,CAAC,CAAC;EAC5BC,YAAY,EAAGC,MAAkB,IAAK;IACpC;IACA,OAAOJ,UAAU,CAACI,MAAM,CAAC,GACrBV,KAAK,CAACW,kBAAkB,CAACD,MAAM,CAAC,CAACE,GAAG,GACpC,KAAK,IAAIF,MAAM,GACbA,MAAM,CAACE,GAAG,GACVF,MAAM,CAACG,OAAO;EACtB,CAAC;EACDT,cAAc;EACdC;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Image","PixelRatio","Platform","RNPlatform","findNodeHandle","View","isRNModule","unwrapModule","OS","get","resolveAsset","source","asset","resolveAssetSource","uri"],"sources":["Platform.ts"],"sourcesContent":["import {\n Image,\n PixelRatio,\n Platform as RNPlatform,\n findNodeHandle,\n View,\n} from \"react-native\";\n\nimport type { DataModule } from \"../skia/types\";\nimport { isRNModule, unwrapModule } from \"../skia/types\";\n\nimport type { IPlatform } from \"./IPlatform\";\n\nexport const Platform: IPlatform = {\n OS: RNPlatform.OS,\n PixelRatio: PixelRatio.get(),\n resolveAsset: (source: DataModule) => {\n const asset = unwrapModule(source);\n if (typeof asset === \"string\") {\n return asset;\n }\n return isRNModule(asset) ? Image.resolveAssetSource(asset).uri : asset.uri;\n },\n findNodeHandle,\n View,\n};\n"],"mappings":"AAAA,SACEA,KAAK,EACLC,UAAU,EACVC,QAAQ,IAAIC,UAAU,EACtBC,cAAc,EACdC,IAAI,QACC,cAAc;AAGrB,SAASC,UAAU,EAAEC,YAAY,QAAQ,eAAe;AAIxD,OAAO,MAAML,QAAmB,GAAG;EACjCM,EAAE,EAAEL,UAAU,CAACK,EAAE;EACjBP,UAAU,EAAEA,UAAU,CAACQ,GAAG,CAAC,CAAC;EAC5BC,YAAY,EAAGC,MAAkB,IAAK;IACpC,MAAMC,KAAK,GAAGL,YAAY,CAACI,MAAM,CAAC;IAClC,IAAI,OAAOC,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAOA,KAAK;IACd;IACA,OAAON,UAAU,CAACM,KAAK,CAAC,GAAGZ,KAAK,CAACa,kBAAkB,CAACD,KAAK,CAAC,CAACE,GAAG,GAAGF,KAAK,CAACE,GAAG;EAC5E,CAAC;EACDV,cAAc;EACdC;AACF,CAAC","ignoreList":[]}