@shopify/react-native-skia 0.1.148 → 0.1.150

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,7 +71,7 @@ namespace RNSkia
71
71
 
72
72
  JSI_HOST_FUNCTION(getTextWidth) {
73
73
  auto str = arguments[0].asString(runtime).utf8(runtime);
74
- auto numGlyphIDs = str.length();
74
+ auto numGlyphIDs = getObject()->countText(str.c_str(), str.length(), SkTextEncoding::kUTF8);
75
75
  std::vector<SkGlyphID> glyphs;
76
76
  glyphs.resize(numGlyphIDs);
77
77
  int glyphsSize = static_cast<int>(numGlyphIDs);
@@ -111,9 +111,9 @@ namespace RNSkia
111
111
  JSI_HOST_FUNCTION(getGlyphIDs)
112
112
  {
113
113
  auto str = arguments[0].asString(runtime).utf8(runtime);
114
- auto numGlyphIDs = count > 1 && !arguments[1].isNull() && !arguments[1].isUndefined()
115
- ? arguments[1].asNumber()
116
- : str.length();
114
+ int numGlyphIDs = count > 1 && !arguments[1].isNull() && !arguments[1].isUndefined()
115
+ ? static_cast<int>(arguments[1].asNumber())
116
+ : getObject()->countText(str.c_str(), str.length(), SkTextEncoding::kUTF8);
117
117
  std::vector<SkGlyphID> glyphIDs;
118
118
  glyphIDs.resize(numGlyphIDs);
119
119
  getObject()->textToGlyphs(str.c_str(), str.length(), SkTextEncoding::kUTF8,
@@ -114,9 +114,9 @@ public:
114
114
  }
115
115
 
116
116
  JSI_HOST_FUNCTION(requestRedraw) {
117
- if (count < 2) {
117
+ if (count != 1) {
118
118
  _platformContext->raiseError(
119
- std::string("requestRedraw: Expected 2 arguments, got " + std::to_string(count) + "."));
119
+ std::string("requestRedraw: Expected 1 arguments, got " + std::to_string(count) + "."));
120
120
 
121
121
  return jsi::Value::undefined();
122
122
  }
@@ -73,6 +73,7 @@ const Mock = {
73
73
  useImage: Noop,
74
74
  useSVG: Noop,
75
75
  usePicture: Noop,
76
+ createPicture: Noop,
76
77
  // 3. Point/Rect/Transform utilities
77
78
  vec,
78
79
  rect: (x, y, width, height) => ({
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","useSharedValueEffect","Values","ValuesHooks","Selector","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","ShaderLib","createDrawing","createDeclaration"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAlBA;AAoBA,MAAMA,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEO,MAAMC,IAAa,GAAG,IAAIP,IAAJ,EAAtB;;;AAEA,MAAMQ,GAAG,GAAG,CAACC,CAAD,EAAaC,CAAb;AAAA;;AAAA,SAA6B;AAAED,IAAAA,CAAC,EAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAO,CAAV;AAAaC,IAAAA,CAAC,UAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAOD,CAAP,uCAAY;AAA1B,GAA7B;AAAA,CAAZ;;;AAEA,MAAME,IAOV,GAAG;AACJ;AACA;AACAJ,EAAAA,IAHI;AAIJ,KAAGK,QAJC;AAKJ;AACAC,EAAAA,UAAU,E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AATA,oBA5DI;AA6DJC,EAAAA,aAAa,EAAE7D,IA7DX;AA8DJ8D,EAAAA,iBAAiB,EAAE9D;AA9Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","BaseSkia","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","createPicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","useSharedValueEffect","Values","ValuesHooks","Selector","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","ShaderLib","createDrawing","createDeclaration"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;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N;AAsCJqC,EAAAA,UAAU,EAAErC,IAtCR;AAuCJsC,EAAAA,WAAW,EAAEtC,IAvCT;AAwCJuC,EAAAA,MAAM,EAAEvC,IAxCJ;AAyCJwC,EAAAA,kBAAkB,EAAExC,IAzChB;AA0CJ;AACAyC,EAAAA,oBAAoB,EAApBA,0CA3CI;AA4CJ;AACA,KAAGC,MA7CC;AA8CJ,KAAGC,WA9CC;AA+CJC,EAAAA,QAAQ,EAARA,kBA/CI;AAgDJ;AACA,KAAGC,eAjDC;AAkDJ,KAAGC,eAlDC;AAmDJ,KAAGC,cAnDC;AAoDJ,KAAGC,aApDC;AAqDJ,KAAGC,iBArDC;AAsDJ,KAAGC,mBAtDC;AAuDJC,EAAAA,iBAAiB,EAAE,CACjBC,MADiB,EAEjBC,WAFiB,EAGjBC,YAHiB,KAIdC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3DD;AA4DJC,EAAAA,SAAS,EAAE,CAACC,EAAD,EAAaC,EAAb,EAAwBC,EAAxB,KAAsCL,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CA5D7C;AA6DJK,EAAAA,SAAS,EAATA,oBA7DI;AA8DJC,EAAAA,aAAa,EAAE9D,IA9DX;AA+DJ+D,EAAAA,iBAAiB,EAAE/D;AA/Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n createPicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
@@ -40,9 +40,18 @@ const loadData = (source, factory, onError) => {
40
40
  };
41
41
 
42
42
  const useLoading = (source, loader) => {
43
+ const mounted = (0, _react.useRef)(false);
43
44
  const [data, setData] = (0, _react.useState)(null);
44
45
  (0, _react.useEffect)(() => {
45
- loader().then(setData); // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ mounted.current = true;
47
+ loader().then(value => {
48
+ if (mounted.current) {
49
+ setData(value);
50
+ }
51
+ });
52
+ return () => {
53
+ mounted.current = false;
54
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
46
55
  }, [source]);
47
56
  return data;
48
57
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["Data.ts"],"names":["resolveAsset","source","Image","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","fromURI","then","d","useLoading","loader","data","setData","useRawData","identity","useData"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAGA,MAAMA,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAO,uBAAWA,MAAX,IACHC,mBAAMC,kBAAN,CAAyBF,MAAzB,EAAiCG,GAD9B,GAEHH,MAAM,CAACI,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB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AAU,CAACtB,MAAD,EAAS,MAAMW,QAAQ,CAACX,MAAD,EAASO,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;;;AAMP,MAAMmB,QAAQ,GAAIH,IAAD,IAAkBA,IAAnC;;AAEO,MAAMI,OAAO,GAAG,CACrB5B,MADqB,EAErBQ,OAFqB,KAGlBkB,UAAU,CAAC1B,MAAD,EAAS2B,QAAT,EAAmBnB,OAAnB,CAHR","sourcesContent":["import { useEffect, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n loader().then(setData);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
1
+ {"version":3,"sources":["Data.ts"],"names":["resolveAsset","source","Image","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","fromURI","then","d","useLoading","loader","mounted","data","setData","current","value","useRawData","identity","useData"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAGA,MAAMA,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAO,uBAAWA,MAAX,IACHC,mBAAMC,kBAAN,CAAyBF,MAAzB,EAAiCG,GAD9B,GAEHH,MAAM,CAACI,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB,EAA4B;AAC1BD,IAAAA,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;AACA,WAAO,IAAP;AACD,GAHD,MAGO;AACL,WAAOD,aAAP;AACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfX,MADe,EAEfO,OAFe,EAGfC,OAHe,KAIO;AACtB,MAAIR,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKY,SAAlC,EAA6C;AAC3C,WAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;AACD,GAFD,MAEO,IAAId,MAAM,YAAYe,UAAtB,EAAkC;AACvC,WAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACT,cAAc,CAACW,WAAKC,IAAL,CAAUC,SAAV,CAAoBlB,MAApB,CAAD,EAA8BO,OAA9B,EAAuCC,OAAvC,CAAf,CADF,CAAP;AAGD,GAJM,MAIA;AACL,UAAML,GAAG,GAAG,OAAOH,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCD,YAAY,CAACC,MAAD,CAA9D;AACA,WAAOgB,WAAKC,IAAL,CAAUE,OAAV,CAAkBhB,GAAlB,EAAuBiB,IAAvB,CAA6BC,CAAD,IACjChB,cAAc,CAACgB,CAAD,EAAId,OAAJ,EAAaC,OAAb,CADT,CAAP;AAGD;AACF,CAjBD;;AAkBA,MAAMc,UAAU,GAAG,CACjBtB,MADiB,EAEjBuB,MAFiB,KAGd;AACH,QAAMC,OAAO,GAAG,mBAAO,KAAP,CAAhB;AACA,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkB,qBAAmB,IAAnB,CAAxB;AACA,wBAAU,MAAM;AACdF,IAAAA,OAAO,CAACG,OAAR,GAAkB,IAAlB;AACAJ,IAAAA,MAAM,GAAGH,IAAT,CAAeQ,KAAD,IAAW;AACvB,UAAIJ,OAAO,CAACG,OAAZ,EAAqB;AACnBD,QAAAA,OAAO,CAACE,KAAD,CAAP;AACD;AACF,KAJD;AAKA,WAAO,MAAM;AACXJ,MAAAA,OAAO,CAACG,OAAR,GAAkB,KAAlB;AACD,KAFD,CAPc,CAUd;AACD,GAXD,EAWG,CAAC3B,MAAD,CAXH;AAYA,SAAOyB,IAAP;AACD,CAnBD;;AAqBO,MAAMI,UAAU,GAAG,CACxB7B,MADwB,EAExBO,OAFwB,EAGxBC,OAHwB,KAIrBc,UAAU,CAACtB,MAAD,EAAS,MAAMW,QAAQ,CAACX,MAAD,EAASO,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;;;AAMP,MAAMsB,QAAQ,GAAIL,IAAD,IAAkBA,IAAnC;;AAEO,MAAMM,OAAO,GAAG,CACrB/B,MADqB,EAErBQ,OAFqB,KAGlBqB,UAAU,CAAC7B,MAAD,EAAS8B,QAAT,EAAmBtB,OAAnB,CAHR","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.usePicture = void 0;
6
+ exports.usePicture = exports.createPicture = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
@@ -17,14 +17,32 @@ var _Skia = require("../Skia");
17
17
  */
18
18
  const usePicture = function (rect, cb) {
19
19
  let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
20
+ console.warn("usePicture() is deprecated. Use createPicture() instead.");
20
21
  return (0, _react.useMemo)(() => {
21
22
  const recorder = _Skia.Skia.PictureRecorder();
22
23
 
23
24
  const canvas = recorder.beginRecording(rect);
24
25
  cb(canvas);
25
26
  return recorder.finishRecordingAsPicture(); // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [cb, rect, deps]);
27
+ }, deps);
27
28
  };
29
+ /**
30
+ * Memoizes and returns an SkPicture that can be drawn to another canvas.
31
+ * @param rect Picture bounds
32
+ * @param cb Callback for drawing to the canvas
33
+ * @returns SkPicture
34
+ */
35
+
28
36
 
29
37
  exports.usePicture = usePicture;
38
+
39
+ const createPicture = (rect, cb) => {
40
+ const recorder = _Skia.Skia.PictureRecorder();
41
+
42
+ const canvas = recorder.beginRecording(rect);
43
+ cb(canvas);
44
+ return recorder.finishRecordingAsPicture();
45
+ };
46
+
47
+ exports.createPicture = createPicture;
30
48
  //# sourceMappingURL=Picture.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Picture.ts"],"names":["usePicture","rect","cb","deps","recorder","Skia","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture"],"mappings":";;;;;;;AACA;;AAEA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,UACxBC,IADwB,EAExBC,EAFwB,EAIV;AAAA,MADdC,IACc,uEADS,EACT;AACd,SAAO,oBAAQ,MAAM;AACnB,UAAMC,QAAQ,GAAGC,WAAKC,eAAL,EAAjB;;AACA,UAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAT,CAAwBP,IAAxB,CAAf;AACAC,IAAAA,EAAE,CAACK,MAAD,CAAF;AACA,WAAOH,QAAQ,CAACK,wBAAT,EAAP,CAJmB,CAKnB;AACD,GANM,EAMJ,CAACP,EAAD,EAAKD,IAAL,EAAWE,IAAX,CANI,CAAP;AAOD,CAZM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkCanvas, SkPicture, SkRect } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const usePicture = (\n rect: SkRect,\n cb: (canvas: SkCanvas) => void,\n deps: DependencyList = []\n): SkPicture => {\n return useMemo(() => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [cb, rect, deps]);\n};\n"]}
1
+ {"version":3,"sources":["Picture.ts"],"names":["usePicture","rect","cb","deps","console","warn","recorder","Skia","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture","createPicture"],"mappings":";;;;;;;AACA;;AAEA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,UACxBC,IADwB,EAExBC,EAFwB,EAIrB;AAAA,MADHC,IACG,uEADoB,EACpB;AACHC,EAAAA,OAAO,CAACC,IAAR,CAAa,0DAAb;AACA,SAAO,oBAAQ,MAAM;AACnB,UAAMC,QAAQ,GAAGC,WAAKC,eAAL,EAAjB;;AACA,UAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAT,CAAwBT,IAAxB,CAAf;AACAC,IAAAA,EAAE,CAACO,MAAD,CAAF;AACA,WAAOH,QAAQ,CAACK,wBAAT,EAAP,CAJmB,CAKnB;AACD,GANM,EAMJR,IANI,CAAP;AAOD,CAbM;AAeP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMS,aAAa,GAAG,CAACX,IAAD,EAAeC,EAAf,KAAkD;AAC7E,QAAMI,QAAQ,GAAGC,WAAKC,eAAL,EAAjB;;AACA,QAAMC,MAAM,GAAGH,QAAQ,CAACI,cAAT,CAAwBT,IAAxB,CAAf;AACAC,EAAAA,EAAE,CAACO,MAAD,CAAF;AACA,SAAOH,QAAQ,CAACK,wBAAT,EAAP;AACD,CALM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkCanvas, SkRect } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const usePicture = (\n rect: SkRect,\n cb: (canvas: SkCanvas) => void,\n deps: DependencyList = []\n) => {\n console.warn(\"usePicture() is deprecated. Use createPicture() instead.\");\n return useMemo(() => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const createPicture = (rect: SkRect, cb: (canvas: SkCanvas) => void) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n};\n"]}
@@ -47,6 +47,7 @@ export const Mock = {
47
47
  useImage: Noop,
48
48
  useSVG: Noop,
49
49
  usePicture: Noop,
50
+ createPicture: Noop,
50
51
  // 3. Point/Rect/Transform utilities
51
52
  vec,
52
53
  rect: (x, y, width, height) => ({
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["Values","ValuesHooks","Selector","BaseSkia","useSharedValueEffect","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"mappings":"AAAA;AAGA,OAAO,KAAKA,MAAZ,MAAwB,eAAxB;AACA,OAAO,KAAKC,WAAZ,MAA6B,iBAA7B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,OAAO,KAAKC,QAAZ,MAA0B,eAA1B;AAKA,SAASC,oBAAT,QAAqC,6CAArC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,eAAZ,MAAiC,qBAAjC;AACA,OAAO,KAAKC,cAAZ,MAAgC,oBAAhC;AACA,OAAO,KAAKC,aAAZ,MAA+B,oCAA/B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,yCAAnC;AACA,OAAO,KAAKC,mBAAZ,MAAqC,0CAArC;AACA,SAASC,SAAT,QAA0B,0CAA1B;;AAEA,MAAMC,IAAN,CAAW;AACTC,EAAAA,WAAW,GAAG;AACZ,WAAO,IAAIC,KAAJ,CAAU,MAAM,CAAE,CAAlB,EAAoB;AACzBC,MAAAA,GAAG,EAAE,MAAM,IAAIH,IAAJ,EADc;AAEzBI,MAAAA,KAAK,EAAE,MAAM,IAAIJ,IAAJ,EAFY;AAGzBK,MAAAA,GAAG,EAAE,MAAM;AAHc,KAApB,CAAP;AAKD;;AAPQ;;AAUX,MAAMC,IAAe,GAAG,MAAM,CAAE,CAAhC;;AAEA,OAAO,MAAMC,IAAa,GAAG,IAAIP,IAAJ,EAAtB;AAEP,OAAO,MAAMQ,GAAG,GAAG,CAACC,CAAD,EAAaC,CAAb;AAAA;;AAAA,SAA6B;AAAED,IAAAA,CAAC,EAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAO,CAAV;AAAaC,IAAAA,CAAC,UAAEA,CAAF,aAAEA,CAAF,cAAEA,CAAF,GAAOD,CAAP,uCAAY;AAA1B,GAA7B;AAAA,CAAZ;AAEP,OAAO,MAAME,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AnB,EAAsB,CAAtB,EAAyB,CAAzB,CA3D7C;AA4DJnD,EAAAA,SA5DI;AA6DJwD,EAAAA,aAAa,EAAEjD,IA7DX;AA8DJkD,EAAAA,iBAAiB,EAAElD;AA9Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["Values","ValuesHooks","Selector","BaseSkia","useSharedValueEffect","timingFunctions","springFunctions","decayFunctions","interpolateFn","interpolatePathFn","interpolateVectorFn","ShaderLib","Stub","constructor","Proxy","get","apply","set","Noop","Skia","vec","x","y","Mock","useRawData","useData","useFont","useTypeface","useImage","useSVG","usePicture","createPicture","rect","width","height","rrect","r","rx","ry","point","add","a","b","sub","neg","dist","Math","hypot","translate","translateX","translateY","bounds","topLeft","topRight","bottomLeft","bottomRight","center","processTransform2d","interpolateColors","_value","_inputRange","_outputRange","Float32Array","of","mixColors","_v","_x","_y","createDrawing","createDeclaration"],"mappings":"AAAA;AAGA,OAAO,KAAKA,MAAZ,MA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A9DX;AA+DJmD,EAAAA,iBAAiB,EAAEnD;AA/Df,CAPC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Color, Skia as SkiaApi, SkRect, Vector } from \"../skia/types\";\nimport * as Values from \"../values/web\";\nimport * as ValuesHooks from \"../values/hooks\";\nimport { Selector } from \"../values/selector\";\nimport * as BaseSkia from \"../skia/types\";\nimport type * as SkiaExports from \"../skia\";\nimport type * as ExternalExports from \"../external\";\nimport type * as ValueExports from \"../values\";\nimport type * as AnimationExports from \"../animation\";\nimport { useSharedValueEffect } from \"../external/reanimated/useSharedValueEffect\";\nimport * as timingFunctions from \"../animation/timing\";\nimport * as springFunctions from \"../animation/spring\";\nimport * as decayFunctions from \"../animation/decay\";\nimport * as interpolateFn from \"../animation/functions/interpolate\";\nimport * as interpolatePathFn from \"../animation/functions/interpolatePaths\";\nimport * as interpolateVectorFn from \"../animation/functions/interpolateVector\";\nimport { ShaderLib } from \"../renderer/components/shaders/ShaderLib\";\n\nclass Stub {\n constructor() {\n return new Proxy(() => {}, {\n get: () => new Stub(),\n apply: () => new Stub(),\n set: () => true,\n });\n }\n}\n\nconst Noop: () => any = () => {};\n\nexport const Skia: SkiaApi = new Stub() as any;\n\nexport const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });\n\nexport const Mock: typeof SkiaExports &\n typeof ExternalExports &\n typeof ValueExports &\n typeof AnimationExports & {\n createDrawing: () => any;\n createDeclaration: () => any;\n ShaderLib: typeof ShaderLib;\n } = {\n // SkiaExports\n // 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc\n Skia,\n ...BaseSkia,\n // 2. Hooks\n useRawData: Noop,\n useData: Noop,\n useFont: Noop,\n useTypeface: Noop,\n useImage: Noop,\n useSVG: Noop,\n usePicture: Noop,\n createPicture: Noop,\n // 3. Point/Rect/Transform utilities\n vec,\n rect: (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n }),\n rrect: (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n }),\n point: vec,\n add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),\n sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),\n neg: (a: Vector) => vec(-a.x, -a.y),\n dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),\n translate: ({ x, y }: Vector) =>\n [{ translateX: x }, { translateY: y }] as const,\n\n bounds: Noop,\n topLeft: Noop,\n topRight: Noop,\n bottomLeft: Noop,\n bottomRight: Noop,\n center: Noop,\n processTransform2d: Noop,\n // ExternalExports\n useSharedValueEffect,\n // ValueExports\n ...Values,\n ...ValuesHooks,\n Selector,\n // Animations\n ...timingFunctions,\n ...springFunctions,\n ...decayFunctions,\n ...interpolateFn,\n ...interpolatePathFn,\n ...interpolateVectorFn,\n interpolateColors: (\n _value: number,\n _inputRange: number[],\n _outputRange: Color[]\n ) => Float32Array.of(0, 0, 0, 0),\n mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),\n ShaderLib,\n createDrawing: Noop,\n createDeclaration: Noop,\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
2
  import { Image } from "react-native";
3
3
  import { Skia } from "../Skia";
4
4
  import { isRNModule } from "../types";
@@ -30,9 +30,18 @@ const loadData = (source, factory, onError) => {
30
30
  };
31
31
 
32
32
  const useLoading = (source, loader) => {
33
+ const mounted = useRef(false);
33
34
  const [data, setData] = useState(null);
34
35
  useEffect(() => {
35
- loader().then(setData); // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ mounted.current = true;
37
+ loader().then(value => {
38
+ if (mounted.current) {
39
+ setData(value);
40
+ }
41
+ });
42
+ return () => {
43
+ mounted.current = false;
44
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
36
45
  }, [source]);
37
46
  return data;
38
47
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["Data.ts"],"names":["useEffect","useState","Image","Skia","isRNModule","resolveAsset","source","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","data","setData","useRawData","identity","useData"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC;AACA,SAASC,KAAT,QAAsB,cAAtB;AAEA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,UAAT,QAA2B,UAA3B;;AAGA,MAAMC,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAOF,UAAU,CAACE,MAAD,CAAV,GACHJ,KAAK,CAACK,kBAAN,CAAyBD,MAAzB,EAAiCE,GAD9B,GAEHF,MAAM,CAACG,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB,EAA4B;AAC1BD,IAAAA,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;AACA,WAAO,IAAP;AACD,GAHD,MAGO;AACL,WAAOD,aAAP;AACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfV,MADe,EAEfM,OAFe,EAGfC,OAHe,KAIO;AACtB,MAAIP,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKW,SAAlC,EAA6C;AAC3C,WAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;AACD,GAFD,MAEO,IAAIb,MAAM,YAAYc,UAAtB,EAAkC;AACvC,WAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACT,cAAc,CAACP,IAAI,CAACkB,IAAL,CAAUC,SAAV,CAAoBhB,MAApB,CAAD,EAA8BM,OAA9B,EAAuCC,OAAvC,CAAf,CADF,CAAP;AAGD,GAJM,MAIA;AACL,UAAML,GAAG,GAAG,OAAOF,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCD,YAAY,CAACC,MAAD,CAA9D;AACA,WAAOH,IAAI,CAACkB,IAAL,CAAUE,OAAV,CAAkBf,GAAlB,EAAuBgB,IAAvB,CAA6BC,CAAD,IACjCf,cAAc,CAACe,CAAD,EAAIb,OAAJ,EAAaC,OAAb,CADT,CAAP;AAGD;AACF,CAjBD;;AAkBA,MAAMa,UAAU,GAAG,CACjBpB,MADiB,EAEjBqB,MAFiB,KAGd;AACH,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkB5B,QAAQ,CAAW,IAAX,CAAhC;AACAD,EAAAA,SAAS,CAAC,MAAM;AACd2B,IAAAA,MAAM,GAAGH,IAAT,CAAcK,OAAd,EADc,CAEd;AACD,GAHQ,EAGN,CAACvB,MAAD,CAHM,CAAT;AAIA,SAAOsB,IAAP;AACD,CAVD;;AAYA,OAAO,MAAME,UAAU,GAAG,CACxBxB,MADwB,EAExBM,OAFwB,EAGxBC,OAHwB,KAIrBa,UAAU,CAACpB,MAAD,EAAS,MAAMU,QAAQ,CAACV,MAAD,EAASM,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;AAMP,MAAMkB,QAAQ,GAAIH,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMI,OAAO,GAAG,CACrB1B,MADqB,EAErBO,OAFqB,KAGlBiB,UAAU,CAACxB,MAAD,EAASyB,QAAT,EAAmBlB,OAAnB,CAHR","sourcesContent":["import { useEffect, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n loader().then(setData);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
1
+ {"version":3,"sources":["Data.ts"],"names":["useEffect","useRef","useState","Image","Skia","isRNModule","resolveAsset","source","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","mounted","data","setData","current","value","useRawData","identity","useData"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;AACA,SAASC,KAAT,QAAsB,cAAtB;AAEA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,UAAT,QAA2B,UAA3B;;AAGA,MAAMC,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAOF,UAAU,CAACE,MAAD,CAAV,GACHJ,KAAK,CAAC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AAD,CAAtB;AACA,QAAM,CAAC6B,IAAD,EAAOC,OAAP,IAAkB7B,QAAQ,CAAW,IAAX,CAAhC;AACAF,EAAAA,SAAS,CAAC,MAAM;AACd6B,IAAAA,OAAO,CAACG,OAAR,GAAkB,IAAlB;AACAJ,IAAAA,MAAM,GAAGH,IAAT,CAAeQ,KAAD,IAAW;AACvB,UAAIJ,OAAO,CAACG,OAAZ,EAAqB;AACnBD,QAAAA,OAAO,CAACE,KAAD,CAAP;AACD;AACF,KAJD;AAKA,WAAO,MAAM;AACXJ,MAAAA,OAAO,CAACG,OAAR,GAAkB,KAAlB;AACD,KAFD,CAPc,CAUd;AACD,GAXQ,EAWN,CAACzB,MAAD,CAXM,CAAT;AAYA,SAAOuB,IAAP;AACD,CAnBD;;AAqBA,OAAO,MAAMI,UAAU,GAAG,CACxB3B,MADwB,EAExBM,OAFwB,EAGxBC,OAHwB,KAIrBa,UAAU,CAACpB,MAAD,EAAS,MAAMU,QAAQ,CAACV,MAAD,EAASM,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;AAMP,MAAMqB,QAAQ,GAAIL,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMM,OAAO,GAAG,CACrB7B,MADqB,EAErBO,OAFqB,KAGlBoB,UAAU,CAAC3B,MAAD,EAAS4B,QAAT,EAAmBrB,OAAnB,CAHR","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
@@ -9,11 +9,25 @@ import { Skia } from "../Skia";
9
9
  */
10
10
  export const usePicture = function (rect, cb) {
11
11
  let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
12
+ console.warn("usePicture() is deprecated. Use createPicture() instead.");
12
13
  return useMemo(() => {
13
14
  const recorder = Skia.PictureRecorder();
14
15
  const canvas = recorder.beginRecording(rect);
15
16
  cb(canvas);
16
17
  return recorder.finishRecordingAsPicture(); // eslint-disable-next-line react-hooks/exhaustive-deps
17
- }, [cb, rect, deps]);
18
+ }, deps);
19
+ };
20
+ /**
21
+ * Memoizes and returns an SkPicture that can be drawn to another canvas.
22
+ * @param rect Picture bounds
23
+ * @param cb Callback for drawing to the canvas
24
+ * @returns SkPicture
25
+ */
26
+
27
+ export const createPicture = (rect, cb) => {
28
+ const recorder = Skia.PictureRecorder();
29
+ const canvas = recorder.beginRecording(rect);
30
+ cb(canvas);
31
+ return recorder.finishRecordingAsPicture();
18
32
  };
19
33
  //# sourceMappingURL=Picture.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Picture.ts"],"names":["useMemo","Skia","usePicture","rect","cb","deps","recorder","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture"],"mappings":"AACA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,IAAT,QAAqB,SAArB;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,UACxBC,IADwB,EAExBC,EAFwB,EAIV;AAAA,MADdC,IACc,uEADS,EACT;AACd,SAAOL,OAAO,CAAC,MAAM;AACnB,UAAMM,QAAQ,GAAGL,IAAI,CAACM,eAAL,EAAjB;AACA,UAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAT,CAAwBN,IAAxB,CAAf;AACAC,IAAAA,EAAE,CAACI,MAAD,CAAF;AACA,WAAOF,QAAQ,CAACI,wBAAT,EAAP,CAJmB,CAKnB;AACD,GANa,EAMX,CAACN,EAAD,EAAKD,IAAL,EAAWE,IAAX,CANW,CAAd;AAOD,CAZM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkCanvas, SkPicture, SkRect } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const usePicture = (\n rect: SkRect,\n cb: (canvas: SkCanvas) => void,\n deps: DependencyList = []\n): SkPicture => {\n return useMemo(() => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [cb, rect, deps]);\n};\n"]}
1
+ {"version":3,"sources":["Picture.ts"],"names":["useMemo","Skia","usePicture","rect","cb","deps","console","warn","recorder","PictureRecorder","canvas","beginRecording","finishRecordingAsPicture","createPicture"],"mappings":"AACA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,IAAT,QAAqB,SAArB;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,UACxBC,IADwB,EAExBC,EAFwB,EAIrB;AAAA,MADHC,IACG,uEADoB,EACpB;AACHC,EAAAA,OAAO,CAACC,IAAR,CAAa,0DAAb;AACA,SAAOP,OAAO,CAAC,MAAM;AACnB,UAAMQ,QAAQ,GAAGP,IAAI,CAACQ,eAAL,EAAjB;AACA,UAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAT,CAAwBR,IAAxB,CAAf;AACAC,IAAAA,EAAE,CAACM,MAAD,CAAF;AACA,WAAOF,QAAQ,CAACI,wBAAT,EAAP,CAJmB,CAKnB;AACD,GANa,EAMXP,IANW,CAAd;AAOD,CAbM;AAeP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,aAAa,GAAG,CAACV,IAAD,EAAeC,EAAf,KAAkD;AAC7E,QAAMI,QAAQ,GAAGP,IAAI,CAACQ,eAAL,EAAjB;AACA,QAAMC,MAAM,GAAGF,QAAQ,CAACG,cAAT,CAAwBR,IAAxB,CAAf;AACAC,EAAAA,EAAE,CAACM,MAAD,CAAF;AACA,SAAOF,QAAQ,CAACI,wBAAT,EAAP;AACD,CALM","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkCanvas, SkRect } from \"../types\";\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const usePicture = (\n rect: SkRect,\n cb: (canvas: SkCanvas) => void,\n deps: DependencyList = []\n) => {\n console.warn(\"usePicture() is deprecated. Use createPicture() instead.\");\n return useMemo(() => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Memoizes and returns an SkPicture that can be drawn to another canvas.\n * @param rect Picture bounds\n * @param cb Callback for drawing to the canvas\n * @returns SkPicture\n */\nexport const createPicture = (rect: SkRect, cb: (canvas: SkCanvas) => void) => {\n const recorder = Skia.PictureRecorder();\n const canvas = recorder.beginRecording(rect);\n cb(canvas);\n return recorder.finishRecordingAsPicture();\n};\n"]}
@@ -1,9 +1,16 @@
1
1
  import type { DependencyList } from "react";
2
- import type { SkCanvas, SkPicture, SkRect } from "../types";
2
+ import type { SkCanvas, SkRect } from "../types";
3
3
  /**
4
4
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
5
5
  * @param rect Picture bounds
6
6
  * @param cb Callback for drawing to the canvas
7
7
  * @returns SkPicture
8
8
  */
9
- export declare const usePicture: (rect: SkRect, cb: (canvas: SkCanvas) => void, deps?: DependencyList) => SkPicture;
9
+ export declare const usePicture: (rect: SkRect, cb: (canvas: SkCanvas) => void, deps?: DependencyList) => import("../types").SkPicture;
10
+ /**
11
+ * Memoizes and returns an SkPicture that can be drawn to another canvas.
12
+ * @param rect Picture bounds
13
+ * @param cb Callback for drawing to the canvas
14
+ * @returns SkPicture
15
+ */
16
+ export declare const createPicture: (rect: SkRect, cb: (canvas: SkCanvas) => void) => import("../types").SkPicture;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.148",
10
+ "version": "0.1.150",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
package/src/mock/index.ts CHANGED
@@ -54,6 +54,7 @@ export const Mock: typeof SkiaExports &
54
54
  useImage: Noop,
55
55
  useSVG: Noop,
56
56
  usePicture: Noop,
57
+ createPicture: Noop,
57
58
  // 3. Point/Rect/Transform utilities
58
59
  vec,
59
60
  rect: (x: number, y: number, width: number, height: number) => ({
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
2
  import { Image } from "react-native";
3
3
 
4
4
  import { Skia } from "../Skia";
@@ -47,9 +47,18 @@ const useLoading = <T>(
47
47
  source: DataSourceParam,
48
48
  loader: () => Promise<T | null>
49
49
  ) => {
50
+ const mounted = useRef(false);
50
51
  const [data, setData] = useState<T | null>(null);
51
52
  useEffect(() => {
52
- loader().then(setData);
53
+ mounted.current = true;
54
+ loader().then((value) => {
55
+ if (mounted.current) {
56
+ setData(value);
57
+ }
58
+ });
59
+ return () => {
60
+ mounted.current = false;
61
+ };
53
62
  // eslint-disable-next-line react-hooks/exhaustive-deps
54
63
  }, [source]);
55
64
  return data;
@@ -2,7 +2,7 @@ import type { DependencyList } from "react";
2
2
  import { useMemo } from "react";
3
3
 
4
4
  import { Skia } from "../Skia";
5
- import type { SkCanvas, SkPicture, SkRect } from "../types";
5
+ import type { SkCanvas, SkRect } from "../types";
6
6
 
7
7
  /**
8
8
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
@@ -14,12 +14,26 @@ export const usePicture = (
14
14
  rect: SkRect,
15
15
  cb: (canvas: SkCanvas) => void,
16
16
  deps: DependencyList = []
17
- ): SkPicture => {
17
+ ) => {
18
+ console.warn("usePicture() is deprecated. Use createPicture() instead.");
18
19
  return useMemo(() => {
19
20
  const recorder = Skia.PictureRecorder();
20
21
  const canvas = recorder.beginRecording(rect);
21
22
  cb(canvas);
22
23
  return recorder.finishRecordingAsPicture();
23
24
  // eslint-disable-next-line react-hooks/exhaustive-deps
24
- }, [cb, rect, deps]);
25
+ }, deps);
26
+ };
27
+
28
+ /**
29
+ * Memoizes and returns an SkPicture that can be drawn to another canvas.
30
+ * @param rect Picture bounds
31
+ * @param cb Callback for drawing to the canvas
32
+ * @returns SkPicture
33
+ */
34
+ export const createPicture = (rect: SkRect, cb: (canvas: SkCanvas) => void) => {
35
+ const recorder = Skia.PictureRecorder();
36
+ const canvas = recorder.beginRecording(rect);
37
+ cb(canvas);
38
+ return recorder.finishRecordingAsPicture();
25
39
  };