@shopify/react-native-skia 0.1.165 → 0.1.166
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +16 -5
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +34 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +2 -47
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawViewManager.java +2 -44
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +2 -47
- package/cpp/rnskia/dom/base/DerivedNodeProp.h +4 -4
- package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -4
- package/cpp/rnskia/dom/nodes/JsiPathNode.h +12 -5
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +17 -7
- package/cpp/rnskia/dom/props/ClipProp.h +6 -6
- package/cpp/rnskia/dom/props/ImageProps.h +3 -1
- package/cpp/rnskia/dom/props/PaintProps.h +0 -16
- package/cpp/rnskia/dom/props/VerticesProps.h +2 -2
- package/lib/commonjs/dom/nodes/drawings/Box.js +1 -1
- package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -2
- package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/commonjs/skia/types/Shader/Shader.js +26 -27
- package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
- package/lib/module/dom/nodes/drawings/Box.js +1 -1
- package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
- package/lib/module/dom/nodes/paint/ImageFilters.js +1 -1
- package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +5 -4
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/skia/types/Shader/Shader.js +26 -27
- package/lib/module/skia/types/Shader/Shader.js.map +1 -1
- package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -2
- package/package.json +1 -1
- package/src/dom/nodes/drawings/Box.ts +1 -1
- package/src/dom/nodes/paint/ImageFilters.ts +1 -1
- package/src/dom/nodes/paint/Shaders.ts +5 -5
- package/src/skia/types/Shader/Shader.ts +30 -38
@@ -58,6 +58,7 @@ class ImageShaderNode extends ShaderDeclaration {
|
|
58
58
|
...imageShaderProps
|
59
59
|
} = this.props;
|
60
60
|
const rct = (0, _datatypes.getRect)(this.Skia, imageShaderProps);
|
61
|
+
const m3 = this.Skia.Matrix();
|
61
62
|
|
62
63
|
if (rct) {
|
63
64
|
const rects = (0, _datatypes.fitRects)(fit, {
|
@@ -66,12 +67,14 @@ class ImageShaderNode extends ShaderDeclaration {
|
|
66
67
|
width: image.width(),
|
67
68
|
height: image.height()
|
68
69
|
}, rct);
|
69
|
-
const
|
70
|
-
|
70
|
+
const [x, y, sx, sy] = (0, _datatypes.rect2rect)(rects.src, rects.dst);
|
71
|
+
m3.translate(x.translateX, y.translateY);
|
72
|
+
m3.scale(sx.scaleX, sy.scaleY);
|
71
73
|
}
|
72
74
|
|
73
75
|
const lm = this.Skia.Matrix();
|
74
76
|
(0, _datatypes.processTransformProps)(lm, imageShaderProps);
|
77
|
+
lm.concat(m3);
|
75
78
|
return image.makeShaderOptions(_types.TileMode[(0, _datatypes.enumKey)(tx)], _types.TileMode[(0, _datatypes.enumKey)(ty)], _types.FilterMode[(0, _datatypes.enumKey)(fm)], _types.MipmapMode[(0, _datatypes.enumKey)(mm)], lm);
|
76
79
|
}
|
77
80
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ShaderDeclaration","JsiDeclarationNode","constructor","ctx","type","props","DeclarationType","Shader","ShaderNode","NodeType","materialize","source","uniforms","transform","m3","Skia","Matrix","processTransformProps","makeShaderWithChildren","processUniforms","children","filter","child","isShader","map","ImageShaderNode","ImageShader","fit","image","tx","ty","fm","mm","imageShaderProps","rct","getRect","rects","fitRects","x","y","width","height","rect2rect","src","dst","lm","makeShaderOptions","TileMode","enumKey","FilterMode","MipmapMode","ColorNode","ColorShader","color","MakeColor","Color","TurbulenceNode","Turbulence","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeTurbulence","FractalNoiseNode","FractalNoise","MakeFractalNoise","LinearGradientNode","LinearGradient","start","end","colors","positions","mode","localMatrix","flags","processGradientProps","MakeLinearGradient","RadialGradientNode","RadialGradient","c","r","MakeRadialGradient","SweepGradientNode","SweepGradient","MakeSweepGradient","TwoPointConicalGradientNode","TwoPointConicalGradient","startR","endR","MakeTwoPointConicalGradient"],"sources":["Shaders.ts"],"sourcesContent":["import {\n processUniforms,\n FilterMode,\n MipmapMode,\n TileMode,\n} from \"../../../skia/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport type {\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport {\n enumKey,\n fitRects,\n getRect,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../datatypes\";\n\nexport abstract class ShaderDeclaration<P> extends JsiDeclarationNode<\n P,\n SkShader\n> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.Shader, type, props);\n }\n}\n\nexport class ShaderNode extends ShaderDeclaration<ShaderProps> {\n constructor(ctx: NodeContext, props: ShaderProps) {\n super(ctx, NodeType.Shader, props);\n }\n\n materialize() {\n const { source, uniforms, ...transform } = this.props;\n const m3 = this.Skia.Matrix();\n processTransformProps(m3, transform);\n return source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n this.children()\n .filter(\n (child): child is JsiDeclarationNode<unknown, SkShader> =>\n child instanceof JsiDeclarationNode && child.isShader()\n )\n .map((child) => child.materialize()),\n m3\n );\n }\n}\n\nexport class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {\n constructor(ctx: NodeContext, props: ImageShaderProps) {\n super(ctx, NodeType.ImageShader, props);\n }\n\n materialize() {\n const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;\n const rct = getRect(this.Skia, imageShaderProps);\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const m3 = rect2rect(rects.src, rects.dst);\n imageShaderProps.transform = [\n ...(imageShaderProps.transform ?? []),\n ...m3,\n ];\n }\n const lm = this.Skia.Matrix();\n processTransformProps(lm, imageShaderProps);\n return image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n FilterMode[enumKey(fm)],\n MipmapMode[enumKey(mm)],\n lm\n );\n }\n}\n\nexport class ColorNode extends ShaderDeclaration<ColorProps> {\n constructor(ctx: NodeContext, props: ColorProps) {\n super(ctx, NodeType.ColorShader, props);\n }\n\n materialize() {\n const { color } = this.props;\n return this.Skia.Shader.MakeColor(this.Skia.Color(color));\n }\n}\n\nexport class TurbulenceNode extends ShaderDeclaration<TurbulenceProps> {\n constructor(ctx: NodeContext, props: TurbulenceProps) {\n super(ctx, NodeType.Turbulence, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class FractalNoiseNode extends ShaderDeclaration<FractalNoiseProps> {\n constructor(ctx: NodeContext, props: FractalNoiseProps) {\n super(ctx, NodeType.FractalNoise, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class LinearGradientNode extends ShaderDeclaration<LinearGradientProps> {\n constructor(ctx: NodeContext, props: LinearGradientProps) {\n super(ctx, NodeType.LinearGradient, props);\n }\n\n materialize() {\n const { start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class RadialGradientNode extends ShaderDeclaration<RadialGradientProps> {\n constructor(ctx: NodeContext, props: RadialGradientProps) {\n super(ctx, NodeType.RadialGradient, props);\n }\n\n materialize() {\n const { c, r } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class SweepGradientNode extends ShaderDeclaration<SweepGradientProps> {\n constructor(ctx: NodeContext, props: SweepGradientProps) {\n super(ctx, NodeType.SweepGradient, props);\n }\n\n materialize() {\n const { c, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n }\n}\n\nexport class TwoPointConicalGradientNode extends ShaderDeclaration<TwoPointConicalGradientProps> {\n constructor(ctx: NodeContext, props: TwoPointConicalGradientProps) {\n super(ctx, NodeType.TwoPointConicalGradient, props);\n }\n\n materialize() {\n const { startR, endR, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAQA;;AAYA;;AACA;;AASO,MAAeA,iBAAf,SAA4CC,wBAA5C,CAGL;EACAC,WAAW,CAACC,GAAD,EAAmBC,IAAnB,EAAmCC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AAKV,KAArC,CADF;IAEA,OAAO,KAAKU,IAAL,CAAUR,MAAV,CAAiB+E,iBAAjB,CACLL,CAAC,CAAC3C,CADG,EAEL2C,CAAC,CAAC1C,CAFG,EAGLiC,MAHK,EAILC,SAJK,EAKLC,IALK,EAMLC,WANK,EAOLC,KAPK,EAQLN,KARK,EASLC,GATK,CAAP;EAWD;;AApB0E;;;;AAuBtE,MAAMgB,2BAAN,SAA0CvF,iBAA1C,CAA0F;EAC/FE,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAwD;IACjE,MAAMF,GAAN,EAAWM,gBAAA,CAAS+E,uBAApB,EAA6CnF,KAA7C;EACD;;EAEDK,WAAW,GAAG;IACZ,MAAM;MAAE+E,MAAF;MAAUC,IAAV;MAAgBpB,KAAhB;MAAuBC;IAAvB,IAA+B,KAAKlE,KAA1C;IACA,MAAM;MAAEmE,MAAF;MAAUC,SAAV;MAAqBC,IAArB;MAA2BC,WAA3B;MAAwCC;IAAxC,IACJ,IAAAC,+BAAA,EAAqB,KAAK9D,IAA1B,EAAgC,KAAKV,KAArC,CADF;IAEA,OAAO,KAAKU,IAAL,CAAUR,MAAV,CAAiBoF,2BAAjB,CACLrB,KADK,EAELmB,MAFK,EAGLlB,GAHK,EAILmB,IAJK,EAKLlB,MALK,EAMLC,SANK,EAOLC,IAPK,EAQLC,WARK,EASLC,KATK,CAAP;EAWD;;AApB8F"}
|
1
|
+
{"version":3,"names":["ShaderDeclaration","JsiDeclarationNode","constructor","ctx","type","props","DeclarationType","Shader","ShaderNode","NodeType","materialize","source","uniforms","transform","m3","Skia","Matrix","processTransformProps","makeShaderWithChildren","processUniforms","children","filter","child","isShader","map","ImageShaderNode","ImageShader","fit","image","tx","ty","fm","mm","imageShaderProps","rct","getRect","rects","fitRects","x","y","width","height","sx","sy","rect2rect","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderOptions","TileMode","enumKey","FilterMode","MipmapMode","ColorNode","ColorShader","color","MakeColor","Color","TurbulenceNode","Turbulence","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeTurbulence","FractalNoiseNode","FractalNoise","MakeFractalNoise","LinearGradientNode","LinearGradient","start","end","colors","positions","mode","localMatrix","flags","processGradientProps","MakeLinearGradient","RadialGradientNode","RadialGradient","c","r","MakeRadialGradient","SweepGradientNode","SweepGradient","MakeSweepGradient","TwoPointConicalGradientNode","TwoPointConicalGradient","startR","endR","MakeTwoPointConicalGradient"],"sources":["Shaders.ts"],"sourcesContent":["import {\n processUniforms,\n FilterMode,\n MipmapMode,\n TileMode,\n} from \"../../../skia/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport type {\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport {\n enumKey,\n fitRects,\n getRect,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../datatypes\";\n\nexport abstract class ShaderDeclaration<P> extends JsiDeclarationNode<\n P,\n SkShader\n> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.Shader, type, props);\n }\n}\n\nexport class ShaderNode extends ShaderDeclaration<ShaderProps> {\n constructor(ctx: NodeContext, props: ShaderProps) {\n super(ctx, NodeType.Shader, props);\n }\n\n materialize() {\n const { source, uniforms, ...transform } = this.props;\n const m3 = this.Skia.Matrix();\n processTransformProps(m3, transform);\n return source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n this.children()\n .filter(\n (child): child is JsiDeclarationNode<unknown, SkShader> =>\n child instanceof JsiDeclarationNode && child.isShader()\n )\n .map((child) => child.materialize()),\n m3\n );\n }\n}\n\nexport class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {\n constructor(ctx: NodeContext, props: ImageShaderProps) {\n super(ctx, NodeType.ImageShader, props);\n }\n\n materialize() {\n const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;\n const rct = getRect(this.Skia, imageShaderProps);\n const m3 = this.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = this.Skia.Matrix();\n processTransformProps(lm, imageShaderProps);\n lm.concat(m3);\n return image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n FilterMode[enumKey(fm)],\n MipmapMode[enumKey(mm)],\n lm\n );\n }\n}\n\nexport class ColorNode extends ShaderDeclaration<ColorProps> {\n constructor(ctx: NodeContext, props: ColorProps) {\n super(ctx, NodeType.ColorShader, props);\n }\n\n materialize() {\n const { color } = this.props;\n return this.Skia.Shader.MakeColor(this.Skia.Color(color));\n }\n}\n\nexport class TurbulenceNode extends ShaderDeclaration<TurbulenceProps> {\n constructor(ctx: NodeContext, props: TurbulenceProps) {\n super(ctx, NodeType.Turbulence, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class FractalNoiseNode extends ShaderDeclaration<FractalNoiseProps> {\n constructor(ctx: NodeContext, props: FractalNoiseProps) {\n super(ctx, NodeType.FractalNoise, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class LinearGradientNode extends ShaderDeclaration<LinearGradientProps> {\n constructor(ctx: NodeContext, props: LinearGradientProps) {\n super(ctx, NodeType.LinearGradient, props);\n }\n\n materialize() {\n const { start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class RadialGradientNode extends ShaderDeclaration<RadialGradientProps> {\n constructor(ctx: NodeContext, props: RadialGradientProps) {\n super(ctx, NodeType.RadialGradient, props);\n }\n\n materialize() {\n const { c, r } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class SweepGradientNode extends ShaderDeclaration<SweepGradientProps> {\n constructor(ctx: NodeContext, props: SweepGradientProps) {\n super(ctx, NodeType.SweepGradient, props);\n }\n\n materialize() {\n const { c, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n }\n}\n\nexport class TwoPointConicalGradientNode extends ShaderDeclaration<TwoPointConicalGradientProps> {\n constructor(ctx: NodeContext, props: TwoPointConicalGradientProps) {\n super(ctx, NodeType.TwoPointConicalGradient, props);\n }\n\n materialize() {\n const { startR, endR, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAQA;;AAYA;;AACA;;AASO,MAAeA,iBAAf,SAA4CC,wBAA5C,CAGL;EACAC,WAAW,CAACC,GAAD,EAAmBC,IAAnB,EAAmCC,KAAnC,EAA6C;IACtD,MAAMF,GAAN,EAAWG,uBAAA,CAAgBC,MAA3B,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E,MAAF;MAAUC,SAAV;MAAqBC,IAArB;MAA2BC,WAA3B;MAAwCC;IAAxC,IACJ,IAAAC,+BAAA,EAAqB,KAAKvE,IAA1B,EAAgC,KAAKV,KAArC,CADF;IAEA,OAAO,KAAKU,IAAL,CAAUR,MAAV,CAAiBwF,iBAAjB,CACLL,CAAC,CAACpD,CADG,EAELoD,CAAC,CAACnD,CAFG,EAGL0C,MAHK,EAILC,SAJK,EAKLC,IALK,EAMLC,WANK,EAOLC,KAPK,EAQLN,KARK,EASLC,GATK,CAAP;EAWD;;AApB0E;;;;AAuBtE,MAAMgB,2BAAN,SAA0ChG,iBAA1C,CAA0F;EAC/FE,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAwD;IACjE,MAAMF,GAAN,EAAWM,gBAAA,CAASwF,uBAApB,EAA6C5F,KAA7C;EACD;;EAEDK,WAAW,GAAG;IACZ,MAAM;MAAEwF,MAAF;MAAUC,IAAV;MAAgBpB,KAAhB;MAAuBC;IAAvB,IAA+B,KAAK3E,KAA1C;IACA,MAAM;MAAE4E,MAAF;MAAUC,SAAV;MAAqBC,IAArB;MAA2BC,WAA3B;MAAwCC;IAAxC,IACJ,IAAAC,+BAAA,EAAqB,KAAKvE,IAA1B,EAAgC,KAAKV,KAArC,CADF;IAEA,OAAO,KAAKU,IAAL,CAAUR,MAAV,CAAiB6F,2BAAjB,CACLrB,KADK,EAELmB,MAFK,EAGLlB,GAHK,EAILmB,IAJK,EAKLlB,MALK,EAMLC,SANK,EAOLC,IAPK,EAQLC,WARK,EASLC,KATK,CAAP;EAWD;;AApB8F"}
|
@@ -13,43 +13,42 @@ const isVector = obj => // We have an issue to check property existence on JSI b
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
14
|
obj.x !== undefined && obj.y !== undefined;
|
15
15
|
|
16
|
-
const processValue = value => {
|
17
|
-
if (
|
18
|
-
|
16
|
+
const processValue = (values, value) => {
|
17
|
+
if (typeof value === "number") {
|
18
|
+
values.push(value);
|
19
|
+
} else if (Array.isArray(value)) {
|
20
|
+
value.forEach(v => processValue(values, v));
|
21
|
+
} else if (isVector(value)) {
|
22
|
+
values.push(value.x, value.y);
|
23
|
+
} else if (value instanceof Float32Array) {
|
24
|
+
values.push(...value);
|
19
25
|
}
|
20
|
-
|
21
|
-
return value;
|
22
26
|
};
|
23
27
|
|
24
28
|
const processUniforms = (source, uniforms, builder) => {
|
25
|
-
const
|
29
|
+
const result = [];
|
30
|
+
const uniformsCount = source.getUniformCount();
|
31
|
+
|
32
|
+
for (let i = 0; i < uniformsCount; i++) {
|
26
33
|
const name = source.getUniformName(i);
|
27
|
-
const
|
34
|
+
const value = uniforms[name];
|
28
35
|
|
29
|
-
if (
|
30
|
-
throw new Error(
|
36
|
+
if (!value === undefined) {
|
37
|
+
throw new Error( // eslint-disable-next-line max-len
|
38
|
+
`The runtime effect has the uniform value "${name}" declared, but it is missing from the uniforms property of the Runtime effect.`);
|
31
39
|
}
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
const usedUniforms = new Array(source.getUniformCount()).fill(0).map((_, i) => source.getUniformName(i));
|
42
|
-
const unusedUniform = names.map(name => {
|
43
|
-
if (usedUniforms.indexOf(name) === -1) {
|
44
|
-
return name;
|
45
|
-
}
|
46
|
-
|
47
|
-
return null;
|
48
|
-
}).filter(n => n !== null);
|
49
|
-
console.warn("Unused uniforms were provided: " + unusedUniform.join(", "));
|
41
|
+
if (builder === undefined) {
|
42
|
+
processValue(result, value);
|
43
|
+
} else {
|
44
|
+
const uniformValue = [];
|
45
|
+
processValue(uniformValue, value);
|
46
|
+
builder.setUniform(name, uniformValue);
|
47
|
+
result.push(...uniformValue);
|
48
|
+
}
|
50
49
|
}
|
51
50
|
|
52
|
-
return
|
51
|
+
return result;
|
53
52
|
};
|
54
53
|
|
55
54
|
exports.processUniforms = processUniforms;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isShader","obj","__typename__","isVector","x","undefined","y","processValue","
|
1
|
+
{"version":3,"names":["isShader","obj","__typename__","isVector","x","undefined","y","processValue","values","value","push","Array","isArray","forEach","v","Float32Array","processUniforms","source","uniforms","builder","result","uniformsCount","getUniformCount","i","name","getUniformName","Error","uniformValue","setUniform"],"sources":["Shader.ts"],"sourcesContent":["import type { SkJSIInstance } from \"../JsiInstance\";\nimport type { Vector } from \"../Point\";\nimport type { SkRuntimeEffect, SkRuntimeShaderBuilder } from \"../RuntimeEffect\";\n\nexport const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>\n obj !== null && obj.__typename__ === \"Shader\";\n\nexport type SkShader = SkJSIInstance<\"Shader\">;\n\nexport type Uniform = number | Vector | Float32Array | Uniform[];\n\nexport interface Uniforms {\n [name: string]: Uniform;\n}\n\nconst isVector = (obj: unknown): obj is Vector =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (obj as any).x !== undefined && (obj as any).y !== undefined;\n\nconst processValue = (values: number[], value: Uniform) => {\n if (typeof value === \"number\") {\n values.push(value);\n } else if (Array.isArray(value)) {\n value.forEach((v) => processValue(values, v));\n } else if (isVector(value)) {\n values.push(value.x, value.y);\n } else if (value instanceof Float32Array) {\n values.push(...value);\n }\n};\n\nexport const processUniforms = (\n source: SkRuntimeEffect,\n uniforms: Uniforms,\n builder?: SkRuntimeShaderBuilder\n) => {\n const result: number[] = [];\n const uniformsCount = source.getUniformCount();\n for (let i = 0; i < uniformsCount; i++) {\n const name = source.getUniformName(i);\n const value = uniforms[name];\n if (!value === undefined) {\n throw new Error(\n // eslint-disable-next-line max-len\n `The runtime effect has the uniform value \"${name}\" declared, but it is missing from the uniforms property of the Runtime effect.`\n );\n }\n if (builder === undefined) {\n processValue(result, value);\n } else {\n const uniformValue: number[] = [];\n processValue(uniformValue, value);\n builder.setUniform(name, uniformValue);\n result.push(...uniformValue);\n }\n }\n return result;\n};\n"],"mappings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B,KAAJ,EACJ;MACC,6CAA4CF,IAAK,iFAF9C,CAAN;IAID;;IACD,IAAIL,OAAO,KAAKd,SAAhB,EAA2B;MACzBE,YAAY,CAACa,MAAD,EAASX,KAAT,CAAZ;IACD,CAFD,MAEO;MACL,MAAMkB,YAAsB,GAAG,EAA/B;MACApB,YAAY,CAACoB,YAAD,EAAelB,KAAf,CAAZ;MACAU,OAAO,CAACS,UAAR,CAAmBJ,IAAnB,EAAyBG,YAAzB;MACAP,MAAM,CAACV,IAAP,CAAY,GAAGiB,YAAf;IACD;EACF;;EACD,OAAOP,MAAP;AACD,CA1BM"}
|
@@ -17,7 +17,7 @@ const deflate = function (Skia, box, dx, dy) {
|
|
17
17
|
|
18
18
|
export class BoxShadowNode extends JsiDeclarationNode {
|
19
19
|
constructor(ctx, props) {
|
20
|
-
super(ctx, DeclarationType.Unknown, NodeType.
|
20
|
+
super(ctx, DeclarationType.Unknown, NodeType.BoxShadow, props);
|
21
21
|
}
|
22
22
|
|
23
23
|
materialize() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["BlurStyle","ClipOp","isRRect","DeclarationType","NodeType","JsiDeclarationNode","JsiRenderNode","inflate","Skia","box","dx","dy","tx","ty","RRectXY","XYWHRect","rect","x","y","width","height","rx","ry","deflate","BoxShadowNode","constructor","ctx","props","Unknown","
|
1
|
+
{"version":3,"names":["BlurStyle","ClipOp","isRRect","DeclarationType","NodeType","JsiDeclarationNode","JsiRenderNode","inflate","Skia","box","dx","dy","tx","ty","RRectXY","XYWHRect","rect","x","y","width","height","rx","ry","deflate","BoxShadowNode","constructor","ctx","props","Unknown","BoxShadow","materialize","BoxNode","Box","renderNode","canvas","paint","defaultBox","opacity","getAlphaf","shadows","_children","map","node","filter","n","shadow","inner","color","blur","spread","lPaint","Paint","setColor","Color","setAlphaf","setMaskFilter","MaskFilter","MakeBlur","Normal","drawRRect","delta","Point","Math","abs","save","clipRRect","Intersect","outer","drawDRRect","restore"],"sources":["Box.ts"],"sourcesContent":["import type { SkRRect, Skia } from \"../../../skia/types\";\nimport { BlurStyle, ClipOp, isRRect } from \"../../../skia/types\";\nimport type { DrawingContext } from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport type { BoxShadowProps, BoxProps } from \"../../types/Drawings\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport { JsiRenderNode } from \"../RenderNode\";\n\nconst inflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) =>\n Skia.RRectXY(\n Skia.XYWHRect(\n box.rect.x - dx + tx,\n box.rect.y - dy + ty,\n box.rect.width + 2 * dx,\n box.rect.height + 2 * dy\n ),\n box.rx + dx,\n box.ry + dy\n );\n\nconst deflate = (\n Skia: Skia,\n box: SkRRect,\n dx: number,\n dy: number,\n tx = 0,\n ty = 0\n) => inflate(Skia, box, -dx, -dy, tx, ty);\n\nexport class BoxShadowNode extends JsiDeclarationNode<\n BoxShadowProps,\n BoxShadowProps\n> {\n constructor(ctx: NodeContext, props: BoxShadowProps) {\n super(ctx, DeclarationType.Unknown, NodeType.BoxShadow, props);\n }\n\n materialize() {\n return this.props;\n }\n}\n\nexport class BoxNode extends JsiRenderNode<BoxProps> {\n constructor(ctx: NodeContext, props: BoxProps) {\n super(ctx, NodeType.Box, props);\n }\n\n renderNode({ canvas, paint }: DrawingContext) {\n const { box: defaultBox } = this.props;\n const opacity = paint.getAlphaf();\n const box = isRRect(defaultBox)\n ? defaultBox\n : this.Skia.RRectXY(defaultBox, 0, 0);\n const shadows = this._children\n .map((node) => {\n if (node instanceof BoxShadowNode) {\n return node.materialize();\n }\n return null;\n })\n .filter((n): n is BoxShadowProps => n !== null);\n shadows\n .filter((shadow) => !shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n canvas.drawRRect(\n inflate(this.Skia, box, spread, spread, dx, dy),\n lPaint\n );\n });\n\n canvas.drawRRect(box, paint);\n\n shadows\n .filter((shadow) => shadow.inner)\n .map((shadow) => {\n const { color = \"black\", blur, spread = 0, dx = 0, dy = 0 } = shadow;\n const delta = this.Skia.Point(10 + Math.abs(dx), 10 + Math.abs(dy));\n canvas.save();\n canvas.clipRRect(box, ClipOp.Intersect, false);\n const lPaint = this.Skia.Paint();\n lPaint.setColor(this.Skia.Color(color));\n lPaint.setAlphaf(paint.getAlphaf() * opacity);\n\n lPaint.setMaskFilter(\n this.Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)\n );\n const inner = deflate(this.Skia, box, spread, spread, dx, dy);\n const outer = inflate(this.Skia, box, delta.x, delta.y);\n canvas.drawDRRect(outer, inner, lPaint);\n canvas.restore();\n });\n }\n}\n"],"mappings":"AACA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,OAA5B,QAA2C,qBAA3C;AAEA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AAGA,SAASC,kBAAT,QAAmC,SAAnC;AACA,SAASC,aAAT,QAA8B,eAA9B;;AAEA,MAAMC,OAAO,GAAG,UACdC,IADc,EAEdC,GAFc,EAGdC,EAHc,EAIdC,EAJc;EAAA,IAKdC,EALc,uEAKT,CALS;EAAA,IAMdC,EANc,uEAMT,CANS;EAAA,OAQdL,IAAI,CAACM,OAAL,CACEN,IAAI,CAACO,QAAL,CACEN,GAAG,CAACO,IAAJ,CAASC,CAAT,GAAaP,EAAb,GAAkBE,EADpB,EAEEH,GAAG,CAACO,IAAJ,CAASE,CAAT,GAAaP,EAAb,GAAkBE,EAFpB,EAGEJ,GAAG,CAACO,IAAJ,CAASG,KAAT,GAAiB,IAAIT,EAHvB,EAIED,GAAG,CAACO,IAAJ,CAASI,MAAT,GAAkB,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,MAAMe,KAAK,GAAG,KAAKpD,IAAL,CAAUqD,KAAV,CAAgB,KAAKC,IAAI,CAACC,GAAL,CAASrD,EAAT,CAArB,EAAmC,KAAKoD,IAAI,CAACC,GAAL,CAASpD,EAAT,CAAxC,CAAd;MACAuB,MAAM,CAAC8B,IAAP;MACA9B,MAAM,CAAC+B,SAAP,CAAiBxD,GAAjB,EAAsBR,MAAM,CAACiE,SAA7B,EAAwC,KAAxC;MACA,MAAMhB,MAAM,GAAG,KAAK1C,IAAL,CAAU2C,KAAV,EAAf;MACAD,MAAM,CAACE,QAAP,CAAgB,KAAK5C,IAAL,CAAU6C,KAAV,CAAgBN,KAAhB,CAAhB;MACAG,MAAM,CAACI,SAAP,CAAiBnB,KAAK,CAACG,SAAN,KAAoBD,OAArC;MAEAa,MAAM,CAACK,aAAP,CACE,KAAK/C,IAAL,CAAUgD,UAAV,CAAqBC,QAArB,CAA8BzD,SAAS,CAAC0D,MAAxC,EAAgDV,IAAhD,EAAsD,IAAtD,CADF;MAGA,MAAMF,KAAK,GAAGvB,OAAO,CAAC,KAAKf,IAAN,EAAYC,GAAZ,EAAiBwC,MAAjB,EAAyBA,MAAzB,EAAiCvC,EAAjC,EAAqCC,EAArC,CAArB;MACA,MAAMwD,KAAK,GAAG5D,OAAO,CAAC,KAAKC,IAAN,EAAYC,GAAZ,EAAiBmD,KAAK,CAAC3C,CAAvB,EAA0B2C,KAAK,CAAC1C,CAAhC,CAArB;MACAgB,MAAM,CAACkC,UAAP,CAAkBD,KAAlB,EAAyBrB,KAAzB,EAAgCI,MAAhC;MACAhB,MAAM,CAACmC,OAAP;IACD,CAlBH;EAmBD;;AAxDkD"}
|
@@ -99,7 +99,7 @@ export class BlurImageFilterNode extends ImageFilterDeclaration {
|
|
99
99
|
}
|
100
100
|
export class DropShadowImageFilterNode extends ImageFilterDeclaration {
|
101
101
|
constructor(ctx, props) {
|
102
|
-
super(ctx, NodeType.
|
102
|
+
super(ctx, NodeType.DropShadowImageFilter, props);
|
103
103
|
}
|
104
104
|
|
105
105
|
materialize() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["BlendMode","ColorChannel","processUniforms","TileMode","DeclarationType","NodeType","processRadius","enumKey","JsiDeclarationNode","Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","constructor","ctx","type","props","getOptionalChildInstance","index","child","_children","getMandatoryChildInstance","isImageFilter","materialize","isShader","MakeShader","declarationType","Error","OffsetImageFilterNode","OffsetImageFilter","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","MakeDisplacementMap","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","DropShadowImageFilterNode","cl","inner","Color","factory","bind","MakeDropShadowOnly","MakeDropShadow","MorphologyOperator","MorphologyImageFilterNode","MorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","BlendImageFilterNode","BlendImageFilter","a","b","RuntimeShaderImageFilterNode","RuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","MakeRuntimeShader"],"sources":["ImageFilters.ts"],"sourcesContent":["import type { SkImageFilter, SkColor, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport { processRadius, enumKey } from \"../datatypes\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n null\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nexport abstract class ImageFilterDeclaration<\n P,\n Nullable extends null | never = never\n> extends JsiDeclarationNode<P, SkImageFilter, Nullable> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n getOptionalChildInstance(index: number) {\n const child = this._children[index];\n if (!child) {\n return null;\n }\n return this.getMandatoryChildInstance(index);\n }\n\n getMandatoryChildInstance(index: number) {\n const child = this._children[index];\n if (child instanceof JsiDeclarationNode) {\n if (child.isImageFilter()) {\n return child.materialize();\n } else if (child.isShader()) {\n return this.Skia.ImageFilter.MakeShader(child.materialize(), null);\n } else if (child.declarationType === DeclarationType.ColorFilter) {\n return this.Skia.ImageFilter.MakeColorFilter(child.materialize(), null);\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n materialize() {\n const { x, y } = this.props;\n return this.Skia.ImageFilter.MakeOffset(\n x,\n y,\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n materialize() {\n const { channelX, channelY, scale } = this.props;\n return this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n this.getMandatoryChildInstance(0),\n this.getOptionalChildInstance(1)\n );\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n return this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n const input = this.getOptionalChildInstance(0);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, this.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? this.Skia.ImageFilter.MakeDropShadowOnly.bind(this.Skia.ImageFilter)\n : this.Skia.ImageFilter.MakeDropShadow.bind(this.Skia.ImageFilter);\n }\n return factory(dx, dy, blur, blur, color, input);\n }\n}\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nexport class MorphologyImageFilterNode extends ImageFilterDeclaration<MorphologyImageFilterProps> {\n constructor(ctx: NodeContext, props: MorphologyImageFilterProps) {\n super(ctx, NodeType.MorphologyImageFilter, props);\n }\n\n materialize() {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n const input = this.getOptionalChildInstance(0);\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n return this.Skia.ImageFilter.MakeErode(r.x, r.y, input);\n }\n return this.Skia.ImageFilter.MakeDilate(r.x, r.y, input);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n materialize() {\n const { mode } = this.props;\n const a = this.getMandatoryChildInstance(0);\n const b = this.getMandatoryChildInstance(1);\n return this.Skia.ImageFilter.MakeBlend(mode, a, b);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n materialize() {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const input = this.getOptionalChildInstance(0);\n return this.Skia.ImageFilter.MakeRuntimeShader(rtb, null, input);\n }\n}\n"],"mappings":"AACA,SACEA,SADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,QAJF,QAKO,qBALP;AAeA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AACA,SAASC,aAAT,EAAwBC,OAAxB,QAAuC,cAAvC;AAEA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,KAAK,GAAGC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,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IACA,MAAM8C,CAAC,GAAG,KAAKzC,yBAAL,CAA+B,CAA/B,CAAV;IACA,MAAM0C,CAAC,GAAG,KAAK1C,yBAAL,CAA+B,CAA/B,CAAV;IACA,OAAO,KAAKnC,IAAL,CAAUS,WAAV,CAAsBG,SAAtB,CAAgC0C,IAAhC,EAAsCsB,CAAtC,EAAyCC,CAAzC,CAAP;EACD;;AAVqF;AAaxF,OAAO,MAAMC,4BAAN,SAA2CpD,sBAA3C,CAAiG;EACtGC,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAyD;IAClE,MAAMF,GAAN,EAAWpC,QAAQ,CAACuF,wBAApB,EAA8CjD,KAA9C;EACD;;EAEDO,WAAW,GAAG;IACZ,MAAM;MAAE2C,MAAF;MAAUC;IAAV,IAAuB,KAAKnD,KAAlC;IACA,MAAMoD,GAAG,GAAG,KAAKlF,IAAL,CAAUmF,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZ5F,eAAe,CAAC2F,MAAD,EAASC,QAAT,EAAmBC,GAAnB,CAAf;IACD;;IACD,MAAM3E,KAAK,GAAG,KAAKwB,wBAAL,CAA8B,CAA9B,CAAd;IACA,OAAO,KAAK/B,IAAL,CAAUS,WAAV,CAAsB2E,iBAAtB,CAAwCF,GAAxC,EAA6C,IAA7C,EAAmD3E,KAAnD,CAAP;EACD;;AAbqG"}
|
1
|
+
{"version":3,"names":["BlendMode","ColorChannel","processUniforms","TileMode","DeclarationType","NodeType","processRadius","enumKey","JsiDeclarationNode","Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","ImageFilterDeclaration","constructor","ctx","type","props","getOptionalChildInstance","index","child","_children","getMandatoryChildInstance","isImageFilter","materialize","isShader","MakeShader","declarationType","Error","OffsetImageFilterNode","OffsetImageFilter","x","y","DisplacementMapImageFilterNode","DisplacementMapImageFilter","channelX","channelY","scale","MakeDisplacementMap","BlurImageFilterNode","BlurImageFilter","mode","blur","sigma","DropShadowImageFilterNode","DropShadowImageFilter","cl","inner","Color","factory","bind","MakeDropShadowOnly","MakeDropShadow","MorphologyOperator","MorphologyImageFilterNode","MorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","BlendImageFilterNode","BlendImageFilter","a","b","RuntimeShaderImageFilterNode","RuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","MakeRuntimeShader"],"sources":["ImageFilters.ts"],"sourcesContent":["import type { SkImageFilter, SkColor, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport { processRadius, enumKey } from \"../datatypes\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n null\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nexport abstract class ImageFilterDeclaration<\n P,\n Nullable extends null | never = never\n> extends JsiDeclarationNode<P, SkImageFilter, Nullable> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.ImageFilter, type, props);\n }\n\n getOptionalChildInstance(index: number) {\n const child = this._children[index];\n if (!child) {\n return null;\n }\n return this.getMandatoryChildInstance(index);\n }\n\n getMandatoryChildInstance(index: number) {\n const child = this._children[index];\n if (child instanceof JsiDeclarationNode) {\n if (child.isImageFilter()) {\n return child.materialize();\n } else if (child.isShader()) {\n return this.Skia.ImageFilter.MakeShader(child.materialize(), null);\n } else if (child.declarationType === DeclarationType.ColorFilter) {\n return this.Skia.ImageFilter.MakeColorFilter(child.materialize(), null);\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n } else {\n throw new Error(`Found invalid child ${child.type} in ${this.type}`);\n }\n }\n}\n\nexport class OffsetImageFilterNode extends ImageFilterDeclaration<OffsetImageFilterProps> {\n constructor(ctx: NodeContext, props: OffsetImageFilterProps) {\n super(ctx, NodeType.OffsetImageFilter, props);\n }\n\n materialize() {\n const { x, y } = this.props;\n return this.Skia.ImageFilter.MakeOffset(\n x,\n y,\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DisplacementMapImageFilterNode extends ImageFilterDeclaration<DisplacementMapImageFilterProps> {\n constructor(ctx: NodeContext, props: DisplacementMapImageFilterProps) {\n super(ctx, NodeType.DisplacementMapImageFilter, props);\n }\n\n materialize() {\n const { channelX, channelY, scale } = this.props;\n return this.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n this.getMandatoryChildInstance(0),\n this.getOptionalChildInstance(1)\n );\n }\n}\n\nexport class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterProps> {\n constructor(ctx: NodeContext, props: BlurImageFilterProps) {\n super(ctx, NodeType.BlurImageFilter, props);\n }\n\n materialize() {\n const { mode, blur } = this.props;\n const sigma = processRadius(this.Skia, blur);\n return this.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n this.getOptionalChildInstance(0)\n );\n }\n}\n\nexport class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {\n constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {\n super(ctx, NodeType.DropShadowImageFilter, props);\n }\n\n materialize() {\n const { dx, dy, blur, shadowOnly, color: cl, inner } = this.props;\n const color = this.Skia.Color(cl);\n const input = this.getOptionalChildInstance(0);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, this.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? this.Skia.ImageFilter.MakeDropShadowOnly.bind(this.Skia.ImageFilter)\n : this.Skia.ImageFilter.MakeDropShadow.bind(this.Skia.ImageFilter);\n }\n return factory(dx, dy, blur, blur, color, input);\n }\n}\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nexport class MorphologyImageFilterNode extends ImageFilterDeclaration<MorphologyImageFilterProps> {\n constructor(ctx: NodeContext, props: MorphologyImageFilterProps) {\n super(ctx, NodeType.MorphologyImageFilter, props);\n }\n\n materialize() {\n const { operator } = this.props;\n const r = processRadius(this.Skia, this.props.radius);\n const input = this.getOptionalChildInstance(0);\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n return this.Skia.ImageFilter.MakeErode(r.x, r.y, input);\n }\n return this.Skia.ImageFilter.MakeDilate(r.x, r.y, input);\n }\n}\n\nexport class BlendImageFilterNode extends ImageFilterDeclaration<BlendImageFilterProps> {\n constructor(ctx: NodeContext, props: BlendImageFilterProps) {\n super(ctx, NodeType.BlendImageFilter, props);\n }\n\n materialize() {\n const { mode } = this.props;\n const a = this.getMandatoryChildInstance(0);\n const b = this.getMandatoryChildInstance(1);\n return this.Skia.ImageFilter.MakeBlend(mode, a, b);\n }\n}\n\nexport class RuntimeShaderImageFilterNode extends ImageFilterDeclaration<RuntimeShaderImageFilterProps> {\n constructor(ctx: NodeContext, props: RuntimeShaderImageFilterProps) {\n super(ctx, NodeType.RuntimeShaderImageFilter, props);\n }\n\n materialize() {\n const { source, uniforms } = this.props;\n const rtb = this.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const input = this.getOptionalChildInstance(0);\n return this.Skia.ImageFilter.MakeRuntimeShader(rtb, null, input);\n }\n}\n"],"mappings":"AACA,SACEA,SADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,QAJF,QAKO,qBALP;AAeA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AACA,SAASC,aAAT,EAAwBC,OAAxB,QAAuC,cAAvC;AAEA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,KAAK,GAAGC,YAAY,CAACC,EAAb,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAd;;AAEA,MAAMC,eAAe,GAAG,CACtBC,IADsB,EAEtBC,UAFsB,EAGtBC,EAHsB,EAItBC,EAJsB,EAKtBC,MALsB,EAMtBC,MANsB,EAOtBC,KAPsB,EAQtBC,KARsB,KASnB;EACH,MAAMC,aAAa,GAAGR,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CACpBV,IAAI,CAACW,WAAL,CAAiBC,SAAjB,CAA2BhB,KAA3B,EAAkCT,SAAS,CAAC0B,GAA5C,CADoB,EAEpB,IAFoB,CAAtB;EAIA,MAAMC,WAAW,GAAGd,IAAI,CAACS,WAAL,CAAiBC,eAAjB,CAClBV,IAAI,CAACW,WAA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;EACD;;EAEDO,WAAW,GAAG;IACZ,MAAM;MAAE4C,MAAF;MAAUC;IAAV,IAAuB,KAAKpD,KAAlC;IACA,MAAMqD,GAAG,GAAG,KAAKnF,IAAL,CAAUoF,oBAAV,CAA+BH,MAA/B,CAAZ;;IACA,IAAIC,QAAJ,EAAc;MACZ7F,eAAe,CAAC4F,MAAD,EAASC,QAAT,EAAmBC,GAAnB,CAAf;IACD;;IACD,MAAM5E,KAAK,GAAG,KAAKwB,wBAAL,CAA8B,CAA9B,CAAd;IACA,OAAO,KAAK/B,IAAL,CAAUS,WAAV,CAAsB4E,iBAAtB,CAAwCF,GAAxC,EAA6C,IAA7C,EAAmD5E,KAAnD,CAAP;EACD;;AAbqG"}
|
@@ -41,22 +41,23 @@ export class ImageShaderNode extends ShaderDeclaration {
|
|
41
41
|
...imageShaderProps
|
42
42
|
} = this.props;
|
43
43
|
const rct = getRect(this.Skia, imageShaderProps);
|
44
|
+
const m3 = this.Skia.Matrix();
|
44
45
|
|
45
46
|
if (rct) {
|
46
|
-
var _imageShaderProps$tra;
|
47
|
-
|
48
47
|
const rects = fitRects(fit, {
|
49
48
|
x: 0,
|
50
49
|
y: 0,
|
51
50
|
width: image.width(),
|
52
51
|
height: image.height()
|
53
52
|
}, rct);
|
54
|
-
const
|
55
|
-
|
53
|
+
const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);
|
54
|
+
m3.translate(x.translateX, y.translateY);
|
55
|
+
m3.scale(sx.scaleX, sy.scaleY);
|
56
56
|
}
|
57
57
|
|
58
58
|
const lm = this.Skia.Matrix();
|
59
59
|
processTransformProps(lm, imageShaderProps);
|
60
|
+
lm.concat(m3);
|
60
61
|
return image.makeShaderOptions(TileMode[enumKey(tx)], TileMode[enumKey(ty)], FilterMode[enumKey(fm)], MipmapMode[enumKey(mm)], lm);
|
61
62
|
}
|
62
63
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["processUniforms","FilterMode","MipmapMode","TileMode","JsiDeclarationNode","DeclarationType","NodeType","enumKey","fitRects","getRect","processGradientProps","processTransformProps","rect2rect","ShaderDeclaration","constructor","ctx","type","props","Shader","ShaderNode","materialize","source","uniforms","transform","m3","Skia","Matrix","makeShaderWithChildren","children","filter","child","isShader","map","ImageShaderNode","ImageShader","fit","image","tx","ty","fm","mm","imageShaderProps","rct","rects","x","y","width","height","src","dst","lm","makeShaderOptions","ColorNode","ColorShader","color","MakeColor","Color","TurbulenceNode","Turbulence","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeTurbulence","FractalNoiseNode","FractalNoise","MakeFractalNoise","LinearGradientNode","LinearGradient","start","end","colors","positions","mode","localMatrix","flags","MakeLinearGradient","RadialGradientNode","RadialGradient","c","r","MakeRadialGradient","SweepGradientNode","SweepGradient","MakeSweepGradient","TwoPointConicalGradientNode","TwoPointConicalGradient","startR","endR","MakeTwoPointConicalGradient"],"sources":["Shaders.ts"],"sourcesContent":["import {\n processUniforms,\n FilterMode,\n MipmapMode,\n TileMode,\n} from \"../../../skia/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport type {\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport {\n enumKey,\n fitRects,\n getRect,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../datatypes\";\n\nexport abstract class ShaderDeclaration<P> extends JsiDeclarationNode<\n P,\n SkShader\n> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.Shader, type, props);\n }\n}\n\nexport class ShaderNode extends ShaderDeclaration<ShaderProps> {\n constructor(ctx: NodeContext, props: ShaderProps) {\n super(ctx, NodeType.Shader, props);\n }\n\n materialize() {\n const { source, uniforms, ...transform } = this.props;\n const m3 = this.Skia.Matrix();\n processTransformProps(m3, transform);\n return source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n this.children()\n .filter(\n (child): child is JsiDeclarationNode<unknown, SkShader> =>\n child instanceof JsiDeclarationNode && child.isShader()\n )\n .map((child) => child.materialize()),\n m3\n );\n }\n}\n\nexport class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {\n constructor(ctx: NodeContext, props: ImageShaderProps) {\n super(ctx, NodeType.ImageShader, props);\n }\n\n materialize() {\n const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;\n const rct = getRect(this.Skia, imageShaderProps);\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const m3 = rect2rect(rects.src, rects.dst);\n imageShaderProps.transform = [\n ...(imageShaderProps.transform ?? []),\n ...m3,\n ];\n }\n const lm = this.Skia.Matrix();\n processTransformProps(lm, imageShaderProps);\n return image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n FilterMode[enumKey(fm)],\n MipmapMode[enumKey(mm)],\n lm\n );\n }\n}\n\nexport class ColorNode extends ShaderDeclaration<ColorProps> {\n constructor(ctx: NodeContext, props: ColorProps) {\n super(ctx, NodeType.ColorShader, props);\n }\n\n materialize() {\n const { color } = this.props;\n return this.Skia.Shader.MakeColor(this.Skia.Color(color));\n }\n}\n\nexport class TurbulenceNode extends ShaderDeclaration<TurbulenceProps> {\n constructor(ctx: NodeContext, props: TurbulenceProps) {\n super(ctx, NodeType.Turbulence, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class FractalNoiseNode extends ShaderDeclaration<FractalNoiseProps> {\n constructor(ctx: NodeContext, props: FractalNoiseProps) {\n super(ctx, NodeType.FractalNoise, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class LinearGradientNode extends ShaderDeclaration<LinearGradientProps> {\n constructor(ctx: NodeContext, props: LinearGradientProps) {\n super(ctx, NodeType.LinearGradient, props);\n }\n\n materialize() {\n const { start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class RadialGradientNode extends ShaderDeclaration<RadialGradientProps> {\n constructor(ctx: NodeContext, props: RadialGradientProps) {\n super(ctx, NodeType.RadialGradient, props);\n }\n\n materialize() {\n const { c, r } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class SweepGradientNode extends ShaderDeclaration<SweepGradientProps> {\n constructor(ctx: NodeContext, props: SweepGradientProps) {\n super(ctx, NodeType.SweepGradient, props);\n }\n\n materialize() {\n const { c, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n }\n}\n\nexport class TwoPointConicalGradientNode extends ShaderDeclaration<TwoPointConicalGradientProps> {\n constructor(ctx: NodeContext, props: TwoPointConicalGradientProps) {\n super(ctx, NodeType.TwoPointConicalGradient, props);\n }\n\n materialize() {\n const { startR, endR, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\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JsiDeclarationNode","DeclarationType","NodeType","enumKey","fitRects","getRect","processGradientProps","processTransformProps","rect2rect","ShaderDeclaration","constructor","ctx","type","props","Shader","ShaderNode","materialize","source","uniforms","transform","m3","Skia","Matrix","makeShaderWithChildren","children","filter","child","isShader","map","ImageShaderNode","ImageShader","fit","image","tx","ty","fm","mm","imageShaderProps","rct","rects","x","y","width","height","sx","sy","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderOptions","ColorNode","ColorShader","color","MakeColor","Color","TurbulenceNode","Turbulence","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeTurbulence","FractalNoiseNode","FractalNoise","MakeFractalNoise","LinearGradientNode","LinearGradient","start","end","colors","positions","mode","localMatrix","flags","MakeLinearGradient","RadialGradientNode","RadialGradient","c","r","MakeRadialGradient","SweepGradientNode","SweepGradient","MakeSweepGradient","TwoPointConicalGradientNode","TwoPointConicalGradient","startR","endR","MakeTwoPointConicalGradient"],"sources":["Shaders.ts"],"sourcesContent":["import {\n processUniforms,\n FilterMode,\n MipmapMode,\n TileMode,\n} from \"../../../skia/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport type { NodeContext } from \"../Node\";\nimport { JsiDeclarationNode } from \"../Node\";\nimport type {\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../types\";\nimport { DeclarationType, NodeType } from \"../../types\";\nimport {\n enumKey,\n fitRects,\n getRect,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../datatypes\";\n\nexport abstract class ShaderDeclaration<P> extends JsiDeclarationNode<\n P,\n SkShader\n> {\n constructor(ctx: NodeContext, type: NodeType, props: P) {\n super(ctx, DeclarationType.Shader, type, props);\n }\n}\n\nexport class ShaderNode extends ShaderDeclaration<ShaderProps> {\n constructor(ctx: NodeContext, props: ShaderProps) {\n super(ctx, NodeType.Shader, props);\n }\n\n materialize() {\n const { source, uniforms, ...transform } = this.props;\n const m3 = this.Skia.Matrix();\n processTransformProps(m3, transform);\n return source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n this.children()\n .filter(\n (child): child is JsiDeclarationNode<unknown, SkShader> =>\n child instanceof JsiDeclarationNode && child.isShader()\n )\n .map((child) => child.materialize()),\n m3\n );\n }\n}\n\nexport class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {\n constructor(ctx: NodeContext, props: ImageShaderProps) {\n super(ctx, NodeType.ImageShader, props);\n }\n\n materialize() {\n const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;\n const rct = getRect(this.Skia, imageShaderProps);\n const m3 = this.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = this.Skia.Matrix();\n processTransformProps(lm, imageShaderProps);\n lm.concat(m3);\n return image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n FilterMode[enumKey(fm)],\n MipmapMode[enumKey(mm)],\n lm\n );\n }\n}\n\nexport class ColorNode extends ShaderDeclaration<ColorProps> {\n constructor(ctx: NodeContext, props: ColorProps) {\n super(ctx, NodeType.ColorShader, props);\n }\n\n materialize() {\n const { color } = this.props;\n return this.Skia.Shader.MakeColor(this.Skia.Color(color));\n }\n}\n\nexport class TurbulenceNode extends ShaderDeclaration<TurbulenceProps> {\n constructor(ctx: NodeContext, props: TurbulenceProps) {\n super(ctx, NodeType.Turbulence, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class FractalNoiseNode extends ShaderDeclaration<FractalNoiseProps> {\n constructor(ctx: NodeContext, props: FractalNoiseProps) {\n super(ctx, NodeType.FractalNoise, props);\n }\n\n materialize() {\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = this.props;\n return this.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n }\n}\n\nexport class LinearGradientNode extends ShaderDeclaration<LinearGradientProps> {\n constructor(ctx: NodeContext, props: LinearGradientProps) {\n super(ctx, NodeType.LinearGradient, props);\n }\n\n materialize() {\n const { start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class RadialGradientNode extends ShaderDeclaration<RadialGradientProps> {\n constructor(ctx: NodeContext, props: RadialGradientProps) {\n super(ctx, NodeType.RadialGradient, props);\n }\n\n materialize() {\n const { c, r } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n\nexport class SweepGradientNode extends ShaderDeclaration<SweepGradientProps> {\n constructor(ctx: NodeContext, props: SweepGradientProps) {\n super(ctx, NodeType.SweepGradient, props);\n }\n\n materialize() {\n const { c, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n }\n}\n\nexport class TwoPointConicalGradientNode extends ShaderDeclaration<TwoPointConicalGradientProps> {\n constructor(ctx: NodeContext, props: TwoPointConicalGradientProps) {\n super(ctx, NodeType.TwoPointConicalGradient, props);\n }\n\n materialize() {\n const { startR, endR, start, end } = this.props;\n const { colors, positions, mode, localMatrix, flags } =\n processGradientProps(this.Skia, this.props);\n return this.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n }\n}\n"],"mappings":"AAAA,SACEA,eADF,EAEEC,UAFF,EAGEC,UAHF,EAIEC,QAJF,QAKO,qBALP;AAQA,SAASC,kBAAT,QAAmC,SAAnC;AAYA,SAASC,eAAT,EAA0BC,QAA1B,QAA0C,aAA1C;AACA,SACEC,OADF,EAEEC,QAFF,EAGEC,OAHF,EAIEC,oBAJF,EAKEC,qBALF,EAMEC,SANF,QAOO,cAPP;AASA,OAAO,MAAeC,iBAAf,SAA4CT,kBAA5C,CAGL;EACAU,WAAW,CAACC,GAAD,EAAmBC,IAAnB,EAAmCC,KAAnC,EAA6C;IACtD,MAAMF,GAAN,EAAWV,eAAe,CAACa,MAA3B,EAAmCF,IAAnC,EAAyCC,KAAzC;EACD;;AAHD;AAMF,OAAO,MAAME,UAAN,SAAyBN,iBAAzB,CAAwD;EAC7DC,WAAW,CAACC,GAAD,EAAmBE,KAAnB,EAAuC;IAChD,MAAMF,GAAN,EAAWT,QAAQ,CAACY,MAApB,EAA4BD,KAA5B;EACD;;EAEDG,WAAW,GAAG;IACZ,MAAM;MAAEC,MAAF;MAAUC,QAAV;MAAoB,GAAGC;IAAvB,IAAqC,KAAKN,KAAhD;IACA,MAAMO,EAAE,GAAG,KAAKC,IAAL,CAAUC,MAAV,EAAX;IACAf,qBAAqB,CAACa,EAAD,EAAKD,SAAL,CAArB;IACA,OAAOF,MAAM,CAACM,sBAAP,CACL3B,eAAe,CAACqB,MAAD,EAASC,QAAT,CADV,EAEL,KAAKM,QAAL,GACGC,MADH,CAEKC,KAAD,IACEA,KAAK,YAAY1B,kBAAjB,IAAuC0B,KAAK,CAACC,QAAN,EAH7C,EAKGC,GALH,CAKQF,KAAD,IAAWA,KAAK,CAACV,WAAN,EALlB,CAFK,EAQLI,EARK,CAAP;EAUD;;AAnB4D;AAsB/D,OAAO,MAAM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KAAKe,IAAN,EAAY,KAAKR,KAAjB,CADtB;IAEA,OAAO,KAAKQ,IAAL,CAAUP,MAAV,CAAiBkF,2BAAjB,CACLpB,KADK,EAELkB,MAFK,EAGLjB,GAHK,EAILkB,IAJK,EAKLjB,MALK,EAMLC,SANK,EAOLC,IAPK,EAQLC,WARK,EASLC,KATK,CAAP;EAWD;;AApB8F"}
|
@@ -4,42 +4,41 @@ const isVector = obj => // We have an issue to check property existence on JSI b
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
5
5
|
obj.x !== undefined && obj.y !== undefined;
|
6
6
|
|
7
|
-
const processValue = value => {
|
8
|
-
if (
|
9
|
-
|
7
|
+
const processValue = (values, value) => {
|
8
|
+
if (typeof value === "number") {
|
9
|
+
values.push(value);
|
10
|
+
} else if (Array.isArray(value)) {
|
11
|
+
value.forEach(v => processValue(values, v));
|
12
|
+
} else if (isVector(value)) {
|
13
|
+
values.push(value.x, value.y);
|
14
|
+
} else if (value instanceof Float32Array) {
|
15
|
+
values.push(...value);
|
10
16
|
}
|
11
|
-
|
12
|
-
return value;
|
13
17
|
};
|
14
18
|
|
15
19
|
export const processUniforms = (source, uniforms, builder) => {
|
16
|
-
const
|
20
|
+
const result = [];
|
21
|
+
const uniformsCount = source.getUniformCount();
|
22
|
+
|
23
|
+
for (let i = 0; i < uniformsCount; i++) {
|
17
24
|
const name = source.getUniformName(i);
|
18
|
-
const
|
25
|
+
const value = uniforms[name];
|
19
26
|
|
20
|
-
if (
|
21
|
-
throw new Error(
|
27
|
+
if (!value === undefined) {
|
28
|
+
throw new Error( // eslint-disable-next-line max-len
|
29
|
+
`The runtime effect has the uniform value "${name}" declared, but it is missing from the uniforms property of the Runtime effect.`);
|
22
30
|
}
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
const usedUniforms = new Array(source.getUniformCount()).fill(0).map((_, i) => source.getUniformName(i));
|
33
|
-
const unusedUniform = names.map(name => {
|
34
|
-
if (usedUniforms.indexOf(name) === -1) {
|
35
|
-
return name;
|
36
|
-
}
|
37
|
-
|
38
|
-
return null;
|
39
|
-
}).filter(n => n !== null);
|
40
|
-
console.warn("Unused uniforms were provided: " + unusedUniform.join(", "));
|
32
|
+
if (builder === undefined) {
|
33
|
+
processValue(result, value);
|
34
|
+
} else {
|
35
|
+
const uniformValue = [];
|
36
|
+
processValue(uniformValue, value);
|
37
|
+
builder.setUniform(name, uniformValue);
|
38
|
+
result.push(...uniformValue);
|
39
|
+
}
|
41
40
|
}
|
42
41
|
|
43
|
-
return
|
42
|
+
return result;
|
44
43
|
};
|
45
44
|
//# sourceMappingURL=Shader.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isShader","obj","__typename__","isVector","x","undefined","y","processValue","
|
1
|
+
{"version":3,"names":["isShader","obj","__typename__","isVector","x","undefined","y","processValue","values","value","push","Array","isArray","forEach","v","Float32Array","processUniforms","source","uniforms","builder","result","uniformsCount","getUniformCount","i","name","getUniformName","Error","uniformValue","setUniform"],"sources":["Shader.ts"],"sourcesContent":["import type { SkJSIInstance } from \"../JsiInstance\";\nimport type { Vector } from \"../Point\";\nimport type { SkRuntimeEffect, SkRuntimeShaderBuilder } from \"../RuntimeEffect\";\n\nexport const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>\n obj !== null && obj.__typename__ === \"Shader\";\n\nexport type SkShader = SkJSIInstance<\"Shader\">;\n\nexport type Uniform = number | Vector | Float32Array | Uniform[];\n\nexport interface Uniforms {\n [name: string]: Uniform;\n}\n\nconst isVector = (obj: unknown): obj is Vector =>\n // We have an issue to check property existence on JSI backed instances\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (obj as any).x !== undefined && (obj as any).y !== undefined;\n\nconst processValue = (values: number[], value: Uniform) => {\n if (typeof value === \"number\") {\n values.push(value);\n } else if (Array.isArray(value)) {\n value.forEach((v) => processValue(values, v));\n } else if (isVector(value)) {\n values.push(value.x, value.y);\n } else if (value instanceof Float32Array) {\n values.push(...value);\n }\n};\n\nexport const processUniforms = (\n source: SkRuntimeEffect,\n uniforms: Uniforms,\n builder?: SkRuntimeShaderBuilder\n) => {\n const result: number[] = [];\n const uniformsCount = source.getUniformCount();\n for (let i = 0; i < uniformsCount; i++) {\n const name = source.getUniformName(i);\n const value = uniforms[name];\n if (!value === undefined) {\n throw new Error(\n // eslint-disable-next-line max-len\n `The runtime effect has the uniform value \"${name}\" declared, but it is missing from the uniforms property of the Runtime effect.`\n );\n }\n if (builder === undefined) {\n processValue(result, value);\n } else {\n const uniformValue: number[] = [];\n processValue(uniformValue, value);\n builder.setUniform(name, uniformValue);\n result.push(...uniformValue);\n }\n }\n return result;\n};\n"],"mappings":"AAIA,OAAO,MAAMA,QAAQ,GAAIC,GAAD,IACtBA,GAAG,KAAK,IAAR,IAAgBA,GAAG,CAACC,YAAJ,KAAqB,QADhC;;AAWP,MAAMC,QAAQ,GAAIF,GAAD,IACf;AACA;AACCA,GAAD,CAAaG,CAAb,KAAmBC,SAAnB,IAAiCJ,GAAD,CAAaK,CAAb,KAAmBD,SAHrD;;AAKA,MAAME,YAAY,GAAG,CAACC,MAAD,EAAmBC,KAAnB,KAAsC;EACzD,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7BD,MAAM,CAACE,IAAP,CAAYD,KAAZ;EACD,CAFD,MAEO,IAAIE,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,EAA0B;IAC/BA,KAAK,CAACI,OAAN,CAAeC,CAAD,IAAOP,YAAY,CAACC,MAAD,EAASM,CAAT,CAAjC;EACD,CAFM,MAEA,IAAIX,QAAQ,CAACM,KAAD,CAAZ,EAAqB;IAC1BD,MAAM,CAACE,IAAP,CAAYD,KAAK,CAACL,CAAlB,EAAqBK,KAAK,CAACH,CAA3B;EACD,CAFM,MAEA,IAAIG,KAAK,YAAYM,YAArB,EAAmC;IACxCP,MAAM,CAACE,IAAP,CAAY,GAAGD,KAAf;EACD;AACF,CAVD;;AAYA,OAAO,MAAMO,eAAe,GAAG,CAC7BC,MAD6B,EAE7BC,QAF6B,EAG7BC,OAH6B,KAI1B;EACH,MAAMC,MAAgB,GAAG,EAAzB;EACA,MAAMC,aAAa,GAAGJ,MAAM,CAACK,eAAP,EAAtB;;EACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,aAApB,EAAmCE,CAAC,EAApC,EAAwC;IACtC,MAAMC,IAAI,GAAGP,MAAM,CAACQ,cAAP,CAAsBF,CAAtB,CAAb;IACA,MAAMd,KAAK,GAAGS,QAAQ,CAACM,IAAD,CAAtB;;IACA,IAAI,CAACf,KAAD,KAAWJ,SAAf,EAA0B;MACxB,MAAM,IAAIqB,KAAJ,EACJ;MACC,6CAA4CF,IAAK,iFAF9C,CAAN;IAID;;IACD,IAAIL,OAAO,KAAKd,SAAhB,EAA2B;MACzBE,YAAY,CAACa,MAAD,EAASX,KAAT,CAAZ;IACD,CAFD,MAEO;MACL,MAAMkB,YAAsB,GAAG,EAA/B;MACApB,YAAY,CAACoB,YAAD,EAAelB,KAAf,CAAZ;MACAU,OAAO,CAACS,UAAR,CAAmBJ,IAAnB,EAAyBG,YAAzB;MACAP,MAAM,CAACV,IAAP,CAAY,GAAGiB,YAAf;IACD;EACF;;EACD,OAAOP,MAAP;AACD,CA1BM"}
|
@@ -3,8 +3,7 @@ import type { Vector } from "../Point";
|
|
3
3
|
import type { SkRuntimeEffect, SkRuntimeShaderBuilder } from "../RuntimeEffect";
|
4
4
|
export declare const isShader: (obj: SkJSIInstance<string> | null) => obj is SkShader;
|
5
5
|
export declare type SkShader = SkJSIInstance<"Shader">;
|
6
|
-
export declare type
|
7
|
-
export declare type Uniform = UniformValue | readonly UniformValue[] | Float32Array;
|
6
|
+
export declare type Uniform = number | Vector | Float32Array | Uniform[];
|
8
7
|
export interface Uniforms {
|
9
8
|
[name: string]: Uniform;
|
10
9
|
}
|
package/package.json
CHANGED
@@ -40,7 +40,7 @@ export class BoxShadowNode extends JsiDeclarationNode<
|
|
40
40
|
BoxShadowProps
|
41
41
|
> {
|
42
42
|
constructor(ctx: NodeContext, props: BoxShadowProps) {
|
43
|
-
super(ctx, DeclarationType.Unknown, NodeType.
|
43
|
+
super(ctx, DeclarationType.Unknown, NodeType.BoxShadow, props);
|
44
44
|
}
|
45
45
|
|
46
46
|
materialize() {
|
@@ -140,7 +140,7 @@ export class BlurImageFilterNode extends ImageFilterDeclaration<BlurImageFilterP
|
|
140
140
|
|
141
141
|
export class DropShadowImageFilterNode extends ImageFilterDeclaration<DropShadowImageFilterProps> {
|
142
142
|
constructor(ctx: NodeContext, props: DropShadowImageFilterProps) {
|
143
|
-
super(ctx, NodeType.
|
143
|
+
super(ctx, NodeType.DropShadowImageFilter, props);
|
144
144
|
}
|
145
145
|
|
146
146
|
materialize() {
|
@@ -67,20 +67,20 @@ export class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {
|
|
67
67
|
materialize() {
|
68
68
|
const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;
|
69
69
|
const rct = getRect(this.Skia, imageShaderProps);
|
70
|
+
const m3 = this.Skia.Matrix();
|
70
71
|
if (rct) {
|
71
72
|
const rects = fitRects(
|
72
73
|
fit,
|
73
74
|
{ x: 0, y: 0, width: image.width(), height: image.height() },
|
74
75
|
rct
|
75
76
|
);
|
76
|
-
const
|
77
|
-
|
78
|
-
|
79
|
-
...m3,
|
80
|
-
];
|
77
|
+
const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);
|
78
|
+
m3.translate(x.translateX, y.translateY);
|
79
|
+
m3.scale(sx.scaleX, sy.scaleY);
|
81
80
|
}
|
82
81
|
const lm = this.Skia.Matrix();
|
83
82
|
processTransformProps(lm, imageShaderProps);
|
83
|
+
lm.concat(m3);
|
84
84
|
return image.makeShaderOptions(
|
85
85
|
TileMode[enumKey(tx)],
|
86
86
|
TileMode[enumKey(ty)],
|