@shopify/react-native-skia 2.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +20 -1
- package/cpp/api/JsiSkApi.h +3 -0
- package/cpp/api/JsiSkImageFilterFactory.h +478 -39
- package/cpp/api/JsiSkSkottie.h +590 -0
- package/cpp/api/JsiSkottieFactory.h +65 -0
- package/cpp/api/recorder/Command.h +1 -0
- package/cpp/api/recorder/Convertor.h +16 -0
- package/cpp/api/recorder/Drawings.h +23 -0
- package/cpp/api/recorder/JsiRecorder.h +6 -0
- package/cpp/api/recorder/RNRecorder.h +9 -0
- package/cpp/api/third_party/SkottieUtils.cpp +333 -0
- package/cpp/api/third_party/SkottieUtils.h +172 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +980 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.h +389 -0
- package/cpp/skia/modules/skottie/include/ExternalLayer.h +56 -0
- package/cpp/skia/modules/skottie/include/Skottie.h +313 -0
- package/cpp/skia/modules/skottie/include/SkottieProperty.h +190 -0
- package/cpp/skia/modules/skottie/include/SlotManager.h +113 -0
- package/cpp/skia/modules/skottie/include/TextShaper.h +200 -0
- package/cpp/skia/modules/skottie/src/SkottieValue.h +56 -0
- package/cpp/skia/modules/skottie/src/animator/Animator.h +89 -0
- package/cpp/skia/modules/skottie/src/text/Font.h +82 -0
- package/cpp/skia/modules/skottie/src/text/TextAdapter.h +155 -0
- package/cpp/skia/modules/skottie/src/text/TextAnimator.h +121 -0
- package/cpp/skia/modules/skottie/src/text/TextValue.h +28 -0
- package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +61 -0
- package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +135 -0
- package/cpp/skia/modules/sksg/include/SkSGDraw.h +57 -0
- package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +50 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +181 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGGradient.h +108 -0
- package/cpp/skia/modules/sksg/include/SkSGGroup.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGImage.h +59 -0
- package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +46 -0
- package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGMerge.h +74 -0
- package/cpp/skia/modules/sksg/include/SkSGNode.h +128 -0
- package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGPaint.h +112 -0
- package/cpp/skia/modules/sksg/include/SkSGPath.h +68 -0
- package/cpp/skia/modules/sksg/include/SkSGPlane.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGRect.h +122 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +283 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +157 -0
- package/cpp/skia/modules/sksg/include/SkSGScene.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGText.h +82 -0
- package/cpp/skia/modules/sksg/include/SkSGTransform.h +127 -0
- package/cpp/skia/src/base/SkArenaAlloc.h +371 -0
- package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/commonjs/dom/types/Drawings.d.ts +5 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
- package/lib/commonjs/dom/types/NodeType.js +2 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/commonjs/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/setup.d.ts +5 -0
- package/lib/commonjs/renderer/components/Skottie.d.ts +4 -0
- package/lib/commonjs/renderer/components/Skottie.js +13 -0
- package/lib/commonjs/renderer/components/Skottie.js.map +1 -0
- package/lib/commonjs/renderer/components/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/index.js +11 -0
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +11 -2
- package/lib/commonjs/skia/types/Matrix4.js +42 -1
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Recorder.d.ts +2 -1
- package/lib/commonjs/skia/types/Recorder.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Skottie.d.ts +223 -0
- package/lib/commonjs/skia/types/Skottie.js +73 -0
- package/lib/commonjs/skia/types/Skottie.js.map +1 -0
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +2 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js +243 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js +26 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/commonjs/sksg/Elements.d.ts +2 -1
- package/lib/commonjs/sksg/Elements.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Core.d.ts +4 -2
- package/lib/commonjs/sksg/Recorder/Core.js +1 -0
- package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +2 -0
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +6 -0
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js +3 -0
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +11 -4
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/module/dom/types/Drawings.d.ts +5 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/NodeType.d.ts +2 -1
- package/lib/module/dom/types/NodeType.js +2 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/module/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/setup.d.ts +5 -0
- package/lib/module/renderer/components/Skottie.d.ts +4 -0
- package/lib/module/renderer/components/Skottie.js +5 -0
- package/lib/module/renderer/components/Skottie.js.map +1 -0
- package/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/module/renderer/components/index.js +1 -0
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +11 -2
- package/lib/module/skia/types/Matrix4.js +40 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Recorder.d.ts +2 -1
- package/lib/module/skia/types/Recorder.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Skottie.d.ts +223 -0
- package/lib/module/skia/types/Skottie.js +74 -0
- package/lib/module/skia/types/Skottie.js.map +1 -0
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/module/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +2 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js +236 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/module/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/module/skia/web/JsiSkottieFactory.js +19 -0
- package/lib/module/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/module/sksg/Elements.d.ts +2 -1
- package/lib/module/sksg/Elements.js.map +1 -1
- package/lib/module/sksg/Recorder/Core.d.ts +4 -2
- package/lib/module/sksg/Recorder/Core.js +1 -0
- package/lib/module/sksg/Recorder/Core.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +3 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/Recorder.js +6 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.js +3 -0
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js +9 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/types/Skottie.d.ts +6 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +48 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +6 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +7 -0
- package/lib/typescript/lib/module/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Skottie.d.ts +5 -0
- package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieAnimation.d.ts +47 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieFactory.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/typescript/src/dom/types/Drawings.d.ts +5 -1
- package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
- package/lib/typescript/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/typescript/src/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/setup.d.ts +5 -0
- package/lib/typescript/src/renderer/components/Skottie.d.ts +4 -0
- package/lib/typescript/src/renderer/components/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/typescript/src/skia/types/Matrix4.d.ts +11 -2
- package/lib/typescript/src/skia/types/Recorder.d.ts +2 -1
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/Skottie.d.ts +223 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/typescript/src/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/typescript/src/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/typescript/src/sksg/Elements.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Core.d.ts +4 -2
- package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/libs/android/arm64-v8a/libjsonreader.a +0 -0
- package/libs/android/armeabi-v7a/libjsonreader.a +0 -0
- package/libs/android/x86/libjsonreader.a +0 -0
- package/libs/android/x86_64/libjsonreader.a +0 -0
- package/libs/apple/libpathops.xcframework/Info.plist +8 -8
- package/libs/apple/libskia.xcframework/Info.plist +14 -14
- package/libs/apple/libskottie.xcframework/Info.plist +14 -14
- package/libs/apple/libskparagraph.xcframework/Info.plist +16 -16
- package/libs/apple/libsksg.xcframework/Info.plist +5 -5
- package/libs/apple/libskshaper.xcframework/Info.plist +14 -14
- package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
- package/libs/apple/libsvg.xcframework/Info.plist +14 -14
- package/package.json +1 -1
- package/react-native-skia.podspec +4 -2
- package/src/__tests__/snapshots/matrix4/camera-corner.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-offset.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-top-left-center.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-zoom-out.png +0 -0
- package/src/__tests__/snapshots/matrix4/full-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/scaled-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective2.png +0 -0
- package/src/dom/types/Drawings.ts +6 -0
- package/src/dom/types/NodeType.ts +2 -0
- package/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.tsx +492 -0
- package/src/renderer/__tests__/e2e/Camera.spec.tsx +475 -0
- package/src/renderer/__tests__/e2e/LightingImageFilters.spec.tsx +1478 -0
- package/src/renderer/__tests__/e2e/Skottie.spec.tsx +440 -0
- package/src/renderer/__tests__/e2e/setup/skottie/basic_slots.json +1118 -0
- package/src/renderer/__tests__/e2e/setup/skottie/color-props.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/confetti.json +5899 -0
- package/src/renderer/__tests__/e2e/setup/skottie/drinks.json +43857 -0
- package/src/renderer/__tests__/e2e/setup/skottie/fingerprint.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/lego_loader.json +29540 -0
- package/src/renderer/__tests__/e2e/setup/skottie/new-drop.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/onboarding.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/text-layer.json +1 -0
- package/src/renderer/__tests__/setup.tsx +23 -0
- package/src/renderer/components/Skottie.tsx +8 -0
- package/src/renderer/components/index.ts +1 -0
- package/src/skia/__tests__/assets/Avenir-Heavy.ttf +0 -0
- package/src/skia/types/ImageFilter/ImageFilterFactory.ts +391 -21
- package/src/skia/types/Matrix4.ts +108 -2
- package/src/skia/types/Recorder.ts +2 -0
- package/src/skia/types/Skia.ts +2 -0
- package/src/skia/types/Skottie.ts +266 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkImageFilterFactory.ts +266 -31
- package/src/skia/web/JsiSkia.ts +2 -0
- package/src/skia/web/JsiSkottieAnimation.ts +259 -0
- package/src/skia/web/JsiSkottieFactory.ts +25 -0
- package/src/sksg/Elements.tsx +2 -0
- package/src/sksg/Recorder/Core.ts +3 -0
- package/src/sksg/Recorder/Player.ts +3 -0
- package/src/sksg/Recorder/ReanimatedRecorder.ts +6 -0
- package/src/sksg/Recorder/Recorder.ts +5 -0
- package/src/sksg/Recorder/Visitor.ts +3 -0
- package/src/sksg/Recorder/commands/Drawing.ts +7 -3
- package/src/sksg/Recorder/commands/ImageFilters.ts +1 -1
@@ -0,0 +1,440 @@
|
|
1
|
+
/* eslint-disable camelcase */
|
2
|
+
import React from "react";
|
3
|
+
|
4
|
+
import { checkImage, docPath } from "../../../__tests__/setup";
|
5
|
+
import { dataAssets, importSkia, surface } from "../setup";
|
6
|
+
import { Group, Skottie } from "../../components";
|
7
|
+
|
8
|
+
const legoLoaderJSON = require("./setup/skottie/lego_loader.json");
|
9
|
+
const drinksJSON = require("./setup/skottie/drinks.json");
|
10
|
+
const confettiJSON = require("./setup/skottie/confetti.json");
|
11
|
+
const onboardingJSON = require("./setup/skottie/onboarding.json");
|
12
|
+
const basicSlotsJSON = require("./setup/skottie/basic_slots.json");
|
13
|
+
const fingerprintJSON = require("./setup/skottie/fingerprint.json");
|
14
|
+
const textLayerJSON = require("./setup/skottie/text-layer.json");
|
15
|
+
|
16
|
+
describe("Skottie", () => {
|
17
|
+
it("Should render Skottie component with lego animation", async () => {
|
18
|
+
const { Skia } = importSkia();
|
19
|
+
const source = JSON.stringify(legoLoaderJSON);
|
20
|
+
const legoAnimation = Skia.Skottie.Make(source);
|
21
|
+
// THIS IS FOR INTERNAL TESTING ONLY
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
23
|
+
// @ts-expect-error
|
24
|
+
legoAnimation.source = source;
|
25
|
+
// END OF INTERNAL TESTING ONLY
|
26
|
+
const img = await surface.draw(
|
27
|
+
<Group transform={[{ scale: 0.5 }]}>
|
28
|
+
<Skottie animation={legoAnimation} frame={41} />
|
29
|
+
</Group>
|
30
|
+
);
|
31
|
+
checkImage(img, docPath("skottie/skottie-component-lego.png"));
|
32
|
+
});
|
33
|
+
it("Should render Skottie component with drinks animation", async () => {
|
34
|
+
const { Skia } = importSkia();
|
35
|
+
const source = JSON.stringify(drinksJSON);
|
36
|
+
const drinksAnimation = Skia.Skottie.Make(source);
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
38
|
+
// @ts-expect-error
|
39
|
+
drinksAnimation.source = source;
|
40
|
+
const img = await surface.draw(
|
41
|
+
<Group transform={[{ scale: 0.3 }]}>
|
42
|
+
<Skottie animation={drinksAnimation} frame={200} />
|
43
|
+
</Group>
|
44
|
+
);
|
45
|
+
checkImage(img, docPath("skottie/skottie-component-drinks.png"));
|
46
|
+
});
|
47
|
+
it("Should render Skottie component with confetti animation", async () => {
|
48
|
+
const { Skia } = importSkia();
|
49
|
+
const source = JSON.stringify(confettiJSON);
|
50
|
+
const confettiAnimation = Skia.Skottie.Make(source);
|
51
|
+
// THIS IS FOR INTERNAL TESTING ONLY
|
52
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
53
|
+
// @ts-expect-error
|
54
|
+
confettiAnimation.source = source;
|
55
|
+
// END OF INTERNAL TESTING ONLY
|
56
|
+
const img = await surface.draw(
|
57
|
+
<Group transform={[{ scale: 0.8 }]}>
|
58
|
+
<Skottie animation={confettiAnimation} frame={30} />
|
59
|
+
</Group>
|
60
|
+
);
|
61
|
+
checkImage(img, docPath("skottie/skottie-component-confetti.png"));
|
62
|
+
});
|
63
|
+
it("Should render Skottie component with basic slots animation", async () => {
|
64
|
+
const { Skia } = importSkia();
|
65
|
+
const assets = {
|
66
|
+
NotoSerif: Skia.Data.fromBytes(
|
67
|
+
new Uint8Array(Array.from(dataAssets.NotoSansSCRegular))
|
68
|
+
),
|
69
|
+
"img_0.png": Skia.Data.fromBytes(
|
70
|
+
new Uint8Array(Array.from(dataAssets.img_0))
|
71
|
+
),
|
72
|
+
};
|
73
|
+
const source = JSON.stringify(basicSlotsJSON);
|
74
|
+
const animation = Skia.Skottie.Make(source, assets);
|
75
|
+
// THIS IS FOR INTERNAL TESTING ONLY
|
76
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
77
|
+
// @ts-expect-error
|
78
|
+
animation.source = source;
|
79
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
80
|
+
// @ts-expect-error
|
81
|
+
animation.assets = {
|
82
|
+
NotoSerif: Array.from(dataAssets.NotoSansSCRegular),
|
83
|
+
"img_0.png": Array.from(dataAssets.img_0),
|
84
|
+
};
|
85
|
+
// END OF INTERNAL TESTING ONLY
|
86
|
+
const img = await surface.draw(
|
87
|
+
<Group transform={[{ scale: 0.6 }]}>
|
88
|
+
<Skottie animation={animation} frame={0} />
|
89
|
+
</Group>
|
90
|
+
);
|
91
|
+
checkImage(img, docPath("skottie/skottie-component-basic-slots.png"));
|
92
|
+
});
|
93
|
+
it("Get durations", async () => {
|
94
|
+
const { lego, drinks, confetti, onboarding } = await surface.eval(
|
95
|
+
(Skia, ctx) => {
|
96
|
+
const legoAnimation = Skia.Skottie.Make(ctx.legoLoader);
|
97
|
+
const drinksAnimation = Skia.Skottie.Make(ctx.drinks);
|
98
|
+
const confettiAnimation = Skia.Skottie.Make(ctx.confetti);
|
99
|
+
const onboardingAnimation = Skia.Skottie.Make(ctx.onboarding);
|
100
|
+
return {
|
101
|
+
lego: {
|
102
|
+
duration: Math.round(legoAnimation.duration() * 1000),
|
103
|
+
fps: Math.round(legoAnimation.fps()),
|
104
|
+
version: legoAnimation.version(),
|
105
|
+
size: legoAnimation.size(),
|
106
|
+
},
|
107
|
+
drinks: {
|
108
|
+
duration: Math.round(drinksAnimation.duration() * 1000),
|
109
|
+
fps: Math.round(drinksAnimation.fps()),
|
110
|
+
version: drinksAnimation.version(),
|
111
|
+
size: drinksAnimation.size(),
|
112
|
+
},
|
113
|
+
confetti: {
|
114
|
+
duration: Math.round(confettiAnimation.duration() * 1000),
|
115
|
+
fps: Math.round(confettiAnimation.fps()),
|
116
|
+
version: confettiAnimation.version(),
|
117
|
+
size: confettiAnimation.size(),
|
118
|
+
},
|
119
|
+
onboarding: {
|
120
|
+
duration: Math.round(onboardingAnimation.duration() * 1000),
|
121
|
+
fps: Math.round(onboardingAnimation.fps()),
|
122
|
+
version: onboardingAnimation.version(),
|
123
|
+
size: onboardingAnimation.size(),
|
124
|
+
},
|
125
|
+
};
|
126
|
+
},
|
127
|
+
{
|
128
|
+
legoLoader: JSON.stringify(legoLoaderJSON),
|
129
|
+
drinks: JSON.stringify(drinksJSON),
|
130
|
+
confetti: JSON.stringify(confettiJSON),
|
131
|
+
onboarding: JSON.stringify(onboardingJSON),
|
132
|
+
}
|
133
|
+
);
|
134
|
+
expect(lego.version).toEqual("4.7.0");
|
135
|
+
expect(lego.duration).toEqual(5033);
|
136
|
+
expect(lego.fps).toEqual(30);
|
137
|
+
expect(lego.size).toEqual({ width: 800, height: 600 });
|
138
|
+
expect(drinks.duration).toEqual(9160);
|
139
|
+
expect(drinks.fps).toEqual(25);
|
140
|
+
expect(drinks.version).toEqual("4.5.9");
|
141
|
+
expect(lego.size).toEqual({ width: 800, height: 600 });
|
142
|
+
expect(confetti.duration).toEqual(1969);
|
143
|
+
expect(confetti.fps).toEqual(30);
|
144
|
+
expect(confetti.version).toEqual("4.12.0");
|
145
|
+
expect(lego.size).toEqual({ width: 800, height: 600 });
|
146
|
+
expect(onboarding.duration).toEqual(2636);
|
147
|
+
expect(onboarding.fps).toEqual(30);
|
148
|
+
expect(onboarding.version).toEqual("5.0.3");
|
149
|
+
expect(lego.size).toEqual({ width: 800, height: 600 });
|
150
|
+
});
|
151
|
+
it("Get first frame", async () => {
|
152
|
+
const raw = await surface.eval(
|
153
|
+
(Skia, ctx) => {
|
154
|
+
const legoAnimation = Skia.Skottie.Make(ctx.legoLoader);
|
155
|
+
const sur = Skia.Surface.MakeOffscreen(800, 600);
|
156
|
+
if (!sur) {
|
157
|
+
throw new Error("Failed to create surface");
|
158
|
+
}
|
159
|
+
const canvas = sur.getCanvas();
|
160
|
+
legoAnimation.seekFrame(41);
|
161
|
+
legoAnimation.render(canvas);
|
162
|
+
sur.flush();
|
163
|
+
return sur.makeImageSnapshot().encodeToBase64();
|
164
|
+
},
|
165
|
+
{
|
166
|
+
legoLoader: JSON.stringify(legoLoaderJSON),
|
167
|
+
}
|
168
|
+
);
|
169
|
+
const { Skia } = importSkia();
|
170
|
+
const rData = Skia.Data.fromBase64(raw);
|
171
|
+
const image = Skia.Image.MakeImageFromEncoded(rData)!;
|
172
|
+
expect(rData).toBeDefined();
|
173
|
+
checkImage(image, docPath("skottie/lego.png"));
|
174
|
+
});
|
175
|
+
it("Get slot information", async () => {
|
176
|
+
const slots = await surface.eval(
|
177
|
+
(Skia, ctx) => {
|
178
|
+
const assets = {
|
179
|
+
NotoSerif: Skia.Data.fromBytes(new Uint8Array(ctx.NotoSerif)),
|
180
|
+
"img_0.png": Skia.Data.fromBytes(new Uint8Array(ctx.img_0)),
|
181
|
+
};
|
182
|
+
const animation = Skia.Skottie.Make(ctx.basicSlotsJSON, assets);
|
183
|
+
return animation.getSlotInfo();
|
184
|
+
},
|
185
|
+
{
|
186
|
+
basicSlotsJSON: JSON.stringify(basicSlotsJSON),
|
187
|
+
NotoSerif: Array.from(dataAssets.NotoSansSCRegular),
|
188
|
+
img_0: Array.from(dataAssets.img_0),
|
189
|
+
}
|
190
|
+
);
|
191
|
+
expect(slots).toEqual({
|
192
|
+
colorSlotIDs: ["FillsGroup", "StrokeGroup"],
|
193
|
+
imageSlotIDs: ["ImageSource"],
|
194
|
+
scalarSlotIDs: ["Opacity"],
|
195
|
+
textSlotIDs: ["TextSource"],
|
196
|
+
vec2SlotIDs: ["ScaleGroup"],
|
197
|
+
});
|
198
|
+
});
|
199
|
+
it("Get props information", async () => {
|
200
|
+
const props = await surface.eval(
|
201
|
+
(Skia, ctx) => {
|
202
|
+
const assets = {
|
203
|
+
NotoSerif: Skia.Data.fromBytes(new Uint8Array(ctx.NotoSerif)),
|
204
|
+
"img_0.png": Skia.Data.fromBytes(new Uint8Array(ctx.img_0)),
|
205
|
+
};
|
206
|
+
const animation = Skia.Skottie.Make(ctx.basicSlotsJSON, assets);
|
207
|
+
return {
|
208
|
+
opacityProps: animation
|
209
|
+
.getOpacityProps()
|
210
|
+
.sort((a, b) => a.key.localeCompare(b.key)),
|
211
|
+
transformProps: [
|
212
|
+
animation
|
213
|
+
.getTransformProps()
|
214
|
+
.find(({ key }) => key === "Transform"),
|
215
|
+
],
|
216
|
+
colorProps: animation
|
217
|
+
.getColorProps()
|
218
|
+
.sort((a, b) => a.key.localeCompare(b.key))
|
219
|
+
.map(({ key, value }) => ({ key, value: Array.from(value) })),
|
220
|
+
textProps: animation
|
221
|
+
.getTextProps()
|
222
|
+
.sort((a, b) => a.key.localeCompare(b.key)),
|
223
|
+
};
|
224
|
+
},
|
225
|
+
{
|
226
|
+
basicSlotsJSON: JSON.stringify(basicSlotsJSON),
|
227
|
+
NotoSerif: Array.from(dataAssets.NotoSansSCRegular),
|
228
|
+
img_0: Array.from(dataAssets.img_0),
|
229
|
+
}
|
230
|
+
);
|
231
|
+
expect(props).toEqual({
|
232
|
+
opacityProps: [
|
233
|
+
{ key: "Black Solid 1", value: 70 },
|
234
|
+
{ key: "Turquoise Solid 1", value: 100 },
|
235
|
+
{ key: "text_comp", value: 100 },
|
236
|
+
{ key: "image_comp", value: 100 },
|
237
|
+
{ key: "shapes_comp", value: 100 },
|
238
|
+
{ key: "comp", value: 100 },
|
239
|
+
{ key: "img1.png", value: 100 },
|
240
|
+
{ key: "text slots", value: 100 },
|
241
|
+
{ key: "Shape Layer 2", value: 100 },
|
242
|
+
{ key: "Shape Layer 1", value: 100 },
|
243
|
+
{ key: "Transform", value: 100 },
|
244
|
+
].sort((a, b) => a.key.localeCompare(b.key)),
|
245
|
+
transformProps: [
|
246
|
+
{
|
247
|
+
key: "Transform",
|
248
|
+
value: {
|
249
|
+
anchor: { x: 0, y: 0 },
|
250
|
+
position: { x: 97, y: 0 },
|
251
|
+
scale: { x: 100, y: 100 },
|
252
|
+
rotation: 0,
|
253
|
+
skew: 0,
|
254
|
+
skewAxis: 0,
|
255
|
+
},
|
256
|
+
},
|
257
|
+
],
|
258
|
+
colorProps: [
|
259
|
+
{ key: "Black Solid 1", value: [0, 0, 0, 1] },
|
260
|
+
{ key: "Turquoise Solid 1", value: [0, 1, 0.7450980544090271, 1] },
|
261
|
+
{ key: "Fill 1", value: [0, 0, 0, 1] },
|
262
|
+
{ key: "Stroke 1", value: [0, 0, 0, 1] },
|
263
|
+
].sort((a, b) => a.key.localeCompare(b.key)),
|
264
|
+
textProps: [
|
265
|
+
{
|
266
|
+
key: "text slots",
|
267
|
+
value: {
|
268
|
+
size: 39,
|
269
|
+
text: "text slots",
|
270
|
+
},
|
271
|
+
},
|
272
|
+
],
|
273
|
+
});
|
274
|
+
});
|
275
|
+
it("load skottie with assets", async () => {
|
276
|
+
const raw = await surface.eval(
|
277
|
+
(Skia, ctx) => {
|
278
|
+
const assets = {
|
279
|
+
NotoSerif: Skia.Data.fromBytes(new Uint8Array(ctx.NotoSerif)),
|
280
|
+
"img_0.png": Skia.Data.fromBytes(new Uint8Array(ctx.img_0)),
|
281
|
+
};
|
282
|
+
const animation = Skia.Skottie.Make(ctx.basicSlotsJSON, assets);
|
283
|
+
const size = animation.size();
|
284
|
+
const sur = Skia.Surface.MakeOffscreen(size.width, size.height);
|
285
|
+
if (!sur) {
|
286
|
+
throw new Error("Failed to create surface");
|
287
|
+
}
|
288
|
+
const canvas = sur.getCanvas();
|
289
|
+
animation.seekFrame(0);
|
290
|
+
animation.render(canvas);
|
291
|
+
sur.flush();
|
292
|
+
return sur.makeImageSnapshot().encodeToBase64();
|
293
|
+
},
|
294
|
+
{
|
295
|
+
basicSlotsJSON: JSON.stringify(basicSlotsJSON),
|
296
|
+
NotoSerif: Array.from(dataAssets.NotoSansSCRegular),
|
297
|
+
img_0: Array.from(dataAssets.img_0),
|
298
|
+
}
|
299
|
+
);
|
300
|
+
const { Skia } = importSkia();
|
301
|
+
const rData = Skia.Data.fromBase64(raw);
|
302
|
+
const image = Skia.Image.MakeImageFromEncoded(rData)!;
|
303
|
+
expect(rData).toBeDefined();
|
304
|
+
checkImage(image, docPath("skottie/basic_slots.png"));
|
305
|
+
});
|
306
|
+
it("load skottie with assets and set color slots", async () => {
|
307
|
+
const raw = await surface.eval(
|
308
|
+
(Skia, ctx) => {
|
309
|
+
const assets = {
|
310
|
+
NotoSerif: Skia.Data.fromBytes(new Uint8Array(ctx.NotoSerif)),
|
311
|
+
"img_0.png": Skia.Data.fromBytes(new Uint8Array(ctx.img_0)),
|
312
|
+
};
|
313
|
+
const animation = Skia.Skottie.Make(ctx.basicSlotsJSON, assets);
|
314
|
+
const size = animation.size();
|
315
|
+
const sur = Skia.Surface.MakeOffscreen(size.width, size.height);
|
316
|
+
if (!sur) {
|
317
|
+
throw new Error("Failed to create surface");
|
318
|
+
}
|
319
|
+
const canvas = sur.getCanvas();
|
320
|
+
animation.setColorSlot("FillsGroup", Skia.Color("cyan"));
|
321
|
+
animation.setColorSlot("StrokeGroup", Skia.Color("magenta"));
|
322
|
+
animation.seekFrame(0);
|
323
|
+
animation.render(canvas);
|
324
|
+
sur.flush();
|
325
|
+
return sur.makeImageSnapshot().encodeToBase64();
|
326
|
+
},
|
327
|
+
{
|
328
|
+
basicSlotsJSON: JSON.stringify(basicSlotsJSON),
|
329
|
+
NotoSerif: Array.from(dataAssets.NotoSansSCRegular),
|
330
|
+
img_0: Array.from(dataAssets.img_0),
|
331
|
+
}
|
332
|
+
);
|
333
|
+
const { Skia } = importSkia();
|
334
|
+
const rData = Skia.Data.fromBase64(raw);
|
335
|
+
const image = Skia.Image.MakeImageFromEncoded(rData)!;
|
336
|
+
expect(rData).toBeDefined();
|
337
|
+
checkImage(image, docPath("skottie/basic_slots-with-colors.png"));
|
338
|
+
});
|
339
|
+
it("has color props", async () => {
|
340
|
+
const colorProps = await surface.eval(
|
341
|
+
(Skia, ctx) => {
|
342
|
+
const animation = Skia.Skottie.Make(ctx.fingerprint);
|
343
|
+
const props = animation.getColorProps();
|
344
|
+
return props.map(({ key, value }) => ({
|
345
|
+
key,
|
346
|
+
value: Array.from(value),
|
347
|
+
}));
|
348
|
+
},
|
349
|
+
{
|
350
|
+
fingerprint: JSON.stringify(fingerprintJSON),
|
351
|
+
}
|
352
|
+
);
|
353
|
+
expect(colorProps.length).toBe(1);
|
354
|
+
});
|
355
|
+
it("fingerprint example (1)", async () => {
|
356
|
+
const raw = await surface.eval(
|
357
|
+
(Skia, ctx) => {
|
358
|
+
const animation = Skia.Skottie.Make(ctx.fingerprint);
|
359
|
+
const size = animation.size();
|
360
|
+
const sur = Skia.Surface.MakeOffscreen(size.width, size.height);
|
361
|
+
if (!sur) {
|
362
|
+
throw new Error("Failed to create surface");
|
363
|
+
}
|
364
|
+
const canvas = sur.getCanvas();
|
365
|
+
const colorProp = animation.getColorProps()[0];
|
366
|
+
animation.setColor(colorProp.key, Skia.Color("rgb(60, 120, 255)"));
|
367
|
+
animation.seekFrame(120);
|
368
|
+
animation.render(canvas);
|
369
|
+
sur.flush();
|
370
|
+
return sur.makeImageSnapshot().encodeToBase64();
|
371
|
+
},
|
372
|
+
{
|
373
|
+
fingerprint: JSON.stringify(fingerprintJSON),
|
374
|
+
}
|
375
|
+
);
|
376
|
+
const { Skia } = importSkia();
|
377
|
+
const rData = Skia.Data.fromBase64(raw);
|
378
|
+
const image = Skia.Image.MakeImageFromEncoded(rData)!;
|
379
|
+
expect(rData).toBeDefined();
|
380
|
+
checkImage(image, docPath("skottie/fingerprint-color1.png"));
|
381
|
+
});
|
382
|
+
it("has text props", async () => {
|
383
|
+
const colorProps = await surface.eval(
|
384
|
+
(Skia, ctx) => {
|
385
|
+
const assets = {
|
386
|
+
"Avenir-Heavy": Skia.Data.fromBytes(new Uint8Array(ctx.AvenirHeavy)),
|
387
|
+
};
|
388
|
+
const animation = Skia.Skottie.Make(ctx.textLayerJSON, assets);
|
389
|
+
const props = animation.getTextProps();
|
390
|
+
return props.map(({ key, value }) => ({
|
391
|
+
key,
|
392
|
+
value,
|
393
|
+
}));
|
394
|
+
},
|
395
|
+
{
|
396
|
+
textLayerJSON: JSON.stringify(textLayerJSON),
|
397
|
+
AvenirHeavy: Array.from(dataAssets.AvenirHeavy),
|
398
|
+
}
|
399
|
+
);
|
400
|
+
expect(colorProps[0]).toEqual({
|
401
|
+
key: "hello!",
|
402
|
+
value: { text: "hello!", size: 164 },
|
403
|
+
});
|
404
|
+
expect(colorProps[1]).toEqual({
|
405
|
+
key: "hello! 2",
|
406
|
+
value: { text: "hello!", size: 164 },
|
407
|
+
});
|
408
|
+
});
|
409
|
+
it("text prop", async () => {
|
410
|
+
const raw = await surface.eval(
|
411
|
+
(Skia, ctx) => {
|
412
|
+
const assets = {
|
413
|
+
"Avenir-Heavy": Skia.Data.fromBytes(new Uint8Array(ctx.AvenirHeavy)),
|
414
|
+
};
|
415
|
+
const animation = Skia.Skottie.Make(ctx.textLayer, assets);
|
416
|
+
const size = animation.size();
|
417
|
+
const sur = Skia.Surface.MakeOffscreen(size.width, size.height);
|
418
|
+
if (!sur) {
|
419
|
+
throw new Error("Failed to create surface");
|
420
|
+
}
|
421
|
+
const canvas = sur.getCanvas();
|
422
|
+
animation.setText("hello!", "World", 164);
|
423
|
+
animation.setText("hello! 2", "World", 164);
|
424
|
+
animation.seekFrame(animation.duration() * 0.5);
|
425
|
+
animation.render(canvas);
|
426
|
+
sur.flush();
|
427
|
+
return sur.makeImageSnapshot().encodeToBase64();
|
428
|
+
},
|
429
|
+
{
|
430
|
+
textLayer: JSON.stringify(textLayerJSON),
|
431
|
+
AvenirHeavy: Array.from(dataAssets.AvenirHeavy),
|
432
|
+
}
|
433
|
+
);
|
434
|
+
const { Skia } = importSkia();
|
435
|
+
const rData = Skia.Data.fromBase64(raw);
|
436
|
+
const image = Skia.Image.MakeImageFromEncoded(rData)!;
|
437
|
+
expect(rData).toBeDefined();
|
438
|
+
checkImage(image, docPath("skottie/text-prop.png"));
|
439
|
+
});
|
440
|
+
});
|