@efxlab/motion-canvas-2d 4.0.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/editor/index.css +40 -0
- package/editor/index.js +525 -0
- package/editor/index.js.map +1 -0
- package/lib/code/CodeCursor.d.ts +84 -0
- package/lib/code/CodeCursor.d.ts.map +1 -0
- package/lib/code/CodeCursor.js +315 -0
- package/lib/code/CodeDiffer.d.ts +28 -0
- package/lib/code/CodeDiffer.d.ts.map +1 -0
- package/lib/code/CodeDiffer.js +51 -0
- package/lib/code/CodeFragment.d.ts +42 -0
- package/lib/code/CodeFragment.d.ts.map +1 -0
- package/lib/code/CodeFragment.js +72 -0
- package/lib/code/CodeHighlighter.d.ts +69 -0
- package/lib/code/CodeHighlighter.d.ts.map +1 -0
- package/lib/code/CodeHighlighter.js +2 -0
- package/lib/code/CodeMetrics.d.ts +11 -0
- package/lib/code/CodeMetrics.d.ts.map +1 -0
- package/lib/code/CodeMetrics.js +29 -0
- package/lib/code/CodeRange.d.ts +43 -0
- package/lib/code/CodeRange.d.ts.map +1 -0
- package/lib/code/CodeRange.js +185 -0
- package/lib/code/CodeScope.d.ts +16 -0
- package/lib/code/CodeScope.d.ts.map +1 -0
- package/lib/code/CodeScope.js +72 -0
- package/lib/code/CodeSelection.d.ts +6 -0
- package/lib/code/CodeSelection.d.ts.map +1 -0
- package/lib/code/CodeSelection.js +13 -0
- package/lib/code/CodeSignal.d.ts +63 -0
- package/lib/code/CodeSignal.d.ts.map +1 -0
- package/lib/code/CodeSignal.js +206 -0
- package/lib/code/CodeTokenizer.d.ts +8 -0
- package/lib/code/CodeTokenizer.d.ts.map +1 -0
- package/lib/code/CodeTokenizer.js +50 -0
- package/lib/code/DefaultHighlightStyle.d.ts +3 -0
- package/lib/code/DefaultHighlightStyle.d.ts.map +1 -0
- package/lib/code/DefaultHighlightStyle.js +98 -0
- package/lib/code/LezerHighlighter.d.ts +22 -0
- package/lib/code/LezerHighlighter.d.ts.map +1 -0
- package/lib/code/LezerHighlighter.js +91 -0
- package/lib/code/diff.d.ts +31 -0
- package/lib/code/diff.d.ts.map +1 -0
- package/lib/code/diff.js +236 -0
- package/lib/code/extractRange.d.ts +17 -0
- package/lib/code/extractRange.d.ts.map +1 -0
- package/lib/code/extractRange.js +102 -0
- package/lib/code/index.d.ts +14 -0
- package/lib/code/index.d.ts.map +1 -0
- package/lib/code/index.js +14 -0
- package/lib/components/Bezier.d.ts +22 -0
- package/lib/components/Bezier.d.ts.map +1 -0
- package/lib/components/Bezier.js +80 -0
- package/lib/components/Camera.d.ts +172 -0
- package/lib/components/Camera.d.ts.map +1 -0
- package/lib/components/Camera.js +239 -0
- package/lib/components/Circle.d.ts +191 -0
- package/lib/components/Circle.d.ts.map +1 -0
- package/lib/components/Circle.js +178 -0
- package/lib/components/Code.d.ts +238 -0
- package/lib/components/Code.d.ts.map +1 -0
- package/lib/components/Code.js +331 -0
- package/lib/components/CodeBlock.d.ts +131 -0
- package/lib/components/CodeBlock.d.ts.map +1 -0
- package/lib/components/CodeBlock.js +462 -0
- package/lib/components/CubicBezier.d.ts +69 -0
- package/lib/components/CubicBezier.d.ts.map +1 -0
- package/lib/components/CubicBezier.js +81 -0
- package/lib/components/Curve.d.ts +202 -0
- package/lib/components/Curve.d.ts.map +1 -0
- package/lib/components/Curve.js +284 -0
- package/lib/components/Grid.d.ts +75 -0
- package/lib/components/Grid.d.ts.map +1 -0
- package/lib/components/Grid.js +91 -0
- package/lib/components/Icon.d.ts +58 -0
- package/lib/components/Icon.d.ts.map +1 -0
- package/lib/components/Icon.js +58 -0
- package/lib/components/Img.d.ts +116 -0
- package/lib/components/Img.d.ts.map +1 -0
- package/lib/components/Img.js +233 -0
- package/lib/components/Knot.d.ts +89 -0
- package/lib/components/Knot.d.ts.map +1 -0
- package/lib/components/Knot.js +68 -0
- package/lib/components/Latex.d.ts +49 -0
- package/lib/components/Latex.d.ts.map +1 -0
- package/lib/components/Latex.js +206 -0
- package/lib/components/Layout.d.ts +423 -0
- package/lib/components/Layout.d.ts.map +1 -0
- package/lib/components/Layout.js +699 -0
- package/lib/components/Line.d.ts +158 -0
- package/lib/components/Line.d.ts.map +1 -0
- package/lib/components/Line.js +315 -0
- package/lib/components/Node.d.ts +843 -0
- package/lib/components/Node.d.ts.map +1 -0
- package/lib/components/Node.js +1335 -0
- package/lib/components/Path.d.ts +18 -0
- package/lib/components/Path.d.ts.map +1 -0
- package/lib/components/Path.js +96 -0
- package/lib/components/Polygon.d.ts +157 -0
- package/lib/components/Polygon.d.ts.map +1 -0
- package/lib/components/Polygon.js +183 -0
- package/lib/components/QuadBezier.d.ts +61 -0
- package/lib/components/QuadBezier.d.ts.map +1 -0
- package/lib/components/QuadBezier.js +76 -0
- package/lib/components/Ray.d.ts +60 -0
- package/lib/components/Ray.d.ts.map +1 -0
- package/lib/components/Ray.js +95 -0
- package/lib/components/Rect.d.ts +112 -0
- package/lib/components/Rect.d.ts.map +1 -0
- package/lib/components/Rect.js +76 -0
- package/lib/components/SVG.d.ts +175 -0
- package/lib/components/SVG.d.ts.map +1 -0
- package/lib/components/SVG.js +582 -0
- package/lib/components/Shape.d.ts +39 -0
- package/lib/components/Shape.d.ts.map +1 -0
- package/lib/components/Shape.js +134 -0
- package/lib/components/Spline.d.ts +87 -0
- package/lib/components/Spline.d.ts.map +1 -0
- package/lib/components/Spline.js +230 -0
- package/lib/components/Txt.d.ts +51 -0
- package/lib/components/Txt.d.ts.map +1 -0
- package/lib/components/Txt.js +172 -0
- package/lib/components/TxtLeaf.d.ts +20 -0
- package/lib/components/TxtLeaf.d.ts.map +1 -0
- package/lib/components/TxtLeaf.js +185 -0
- package/lib/components/Video.d.ts +110 -0
- package/lib/components/Video.d.ts.map +1 -0
- package/lib/components/Video.js +267 -0
- package/lib/components/View2D.d.ts +25 -0
- package/lib/components/View2D.d.ts.map +1 -0
- package/lib/components/View2D.js +85 -0
- package/lib/components/index.d.ts +27 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +27 -0
- package/lib/components/types.d.ts +17 -0
- package/lib/components/types.d.ts.map +1 -0
- package/lib/components/types.js +2 -0
- package/lib/curves/ArcSegment.d.ts +26 -0
- package/lib/curves/ArcSegment.d.ts.map +1 -0
- package/lib/curves/ArcSegment.js +116 -0
- package/lib/curves/CircleSegment.d.ts +18 -0
- package/lib/curves/CircleSegment.d.ts.map +1 -0
- package/lib/curves/CircleSegment.js +60 -0
- package/lib/curves/CubicBezierSegment.d.ts +18 -0
- package/lib/curves/CubicBezierSegment.d.ts.map +1 -0
- package/lib/curves/CubicBezierSegment.js +60 -0
- package/lib/curves/CurveDrawingInfo.d.ts +11 -0
- package/lib/curves/CurveDrawingInfo.d.ts.map +1 -0
- package/lib/curves/CurveDrawingInfo.js +2 -0
- package/lib/curves/CurvePoint.d.ts +15 -0
- package/lib/curves/CurvePoint.d.ts.map +1 -0
- package/lib/curves/CurvePoint.js +2 -0
- package/lib/curves/CurveProfile.d.ts +7 -0
- package/lib/curves/CurveProfile.d.ts.map +1 -0
- package/lib/curves/CurveProfile.js +2 -0
- package/lib/curves/KnotInfo.d.ts +12 -0
- package/lib/curves/KnotInfo.d.ts.map +1 -0
- package/lib/curves/KnotInfo.js +2 -0
- package/lib/curves/LineSegment.d.ts +16 -0
- package/lib/curves/LineSegment.d.ts.map +1 -0
- package/lib/curves/LineSegment.js +51 -0
- package/lib/curves/Polynomial.d.ts +118 -0
- package/lib/curves/Polynomial.d.ts.map +1 -0
- package/lib/curves/Polynomial.js +263 -0
- package/lib/curves/Polynomial2D.d.ts +22 -0
- package/lib/curves/Polynomial2D.d.ts.map +1 -0
- package/lib/curves/Polynomial2D.js +51 -0
- package/lib/curves/PolynomialSegment.d.ts +39 -0
- package/lib/curves/PolynomialSegment.d.ts.map +1 -0
- package/lib/curves/PolynomialSegment.js +88 -0
- package/lib/curves/QuadBezierSegment.d.ts +17 -0
- package/lib/curves/QuadBezierSegment.d.ts.map +1 -0
- package/lib/curves/QuadBezierSegment.js +53 -0
- package/lib/curves/Segment.d.ts +9 -0
- package/lib/curves/Segment.d.ts.map +1 -0
- package/lib/curves/Segment.js +3 -0
- package/lib/curves/UniformPolynomialCurveSampler.d.ts +43 -0
- package/lib/curves/UniformPolynomialCurveSampler.d.ts.map +1 -0
- package/lib/curves/UniformPolynomialCurveSampler.js +74 -0
- package/lib/curves/createCurveProfileLerp.d.ts +32 -0
- package/lib/curves/createCurveProfileLerp.d.ts.map +1 -0
- package/lib/curves/createCurveProfileLerp.js +351 -0
- package/lib/curves/getBezierSplineProfile.d.ts +12 -0
- package/lib/curves/getBezierSplineProfile.d.ts.map +1 -0
- package/lib/curves/getBezierSplineProfile.js +140 -0
- package/lib/curves/getCircleProfile.d.ts +4 -0
- package/lib/curves/getCircleProfile.d.ts.map +1 -0
- package/lib/curves/getCircleProfile.js +44 -0
- package/lib/curves/getPathProfile.d.ts +3 -0
- package/lib/curves/getPathProfile.d.ts.map +1 -0
- package/lib/curves/getPathProfile.js +128 -0
- package/lib/curves/getPointAtDistance.d.ts +4 -0
- package/lib/curves/getPointAtDistance.d.ts.map +1 -0
- package/lib/curves/getPointAtDistance.js +15 -0
- package/lib/curves/getPolylineProfile.d.ts +4 -0
- package/lib/curves/getPolylineProfile.d.ts.map +1 -0
- package/lib/curves/getPolylineProfile.js +58 -0
- package/lib/curves/getRectProfile.d.ts +4 -0
- package/lib/curves/getRectProfile.d.ts.map +1 -0
- package/lib/curves/getRectProfile.js +57 -0
- package/lib/curves/index.d.ts +17 -0
- package/lib/curves/index.d.ts.map +1 -0
- package/lib/curves/index.js +17 -0
- package/lib/decorators/canvasStyleSignal.d.ts +5 -0
- package/lib/decorators/canvasStyleSignal.d.ts.map +1 -0
- package/lib/decorators/canvasStyleSignal.js +12 -0
- package/lib/decorators/colorSignal.d.ts +2 -0
- package/lib/decorators/colorSignal.d.ts.map +1 -0
- package/lib/decorators/colorSignal.js +9 -0
- package/lib/decorators/compound.d.ts +27 -0
- package/lib/decorators/compound.d.ts.map +1 -0
- package/lib/decorators/compound.js +49 -0
- package/lib/decorators/computed.d.ts +9 -0
- package/lib/decorators/computed.d.ts.map +1 -0
- package/lib/decorators/computed.js +18 -0
- package/lib/decorators/defaultStyle.d.ts +2 -0
- package/lib/decorators/defaultStyle.d.ts.map +1 -0
- package/lib/decorators/defaultStyle.js +13 -0
- package/lib/decorators/filtersSignal.d.ts +11 -0
- package/lib/decorators/filtersSignal.d.ts.map +1 -0
- package/lib/decorators/filtersSignal.js +73 -0
- package/lib/decorators/index.d.ts +11 -0
- package/lib/decorators/index.d.ts.map +1 -0
- package/lib/decorators/index.js +11 -0
- package/lib/decorators/initializers.d.ts +4 -0
- package/lib/decorators/initializers.d.ts.map +1 -0
- package/lib/decorators/initializers.js +27 -0
- package/lib/decorators/nodeName.d.ts +9 -0
- package/lib/decorators/nodeName.d.ts.map +1 -0
- package/lib/decorators/nodeName.js +13 -0
- package/lib/decorators/signal.d.ts +183 -0
- package/lib/decorators/signal.d.ts.map +1 -0
- package/lib/decorators/signal.js +285 -0
- package/lib/decorators/spacingSignal.d.ts +2 -0
- package/lib/decorators/spacingSignal.d.ts.map +1 -0
- package/lib/decorators/spacingSignal.js +15 -0
- package/lib/decorators/vector2Signal.d.ts +8 -0
- package/lib/decorators/vector2Signal.d.ts.map +1 -0
- package/lib/decorators/vector2Signal.js +15 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx-dev-runtime.d.ts.map +1 -0
- package/lib/jsx-dev-runtime.js +3 -0
- package/lib/jsx-runtime.d.ts +12 -0
- package/lib/jsx-runtime.d.ts.map +1 -0
- package/lib/jsx-runtime.js +23 -0
- package/lib/partials/Filter.d.ts +82 -0
- package/lib/partials/Filter.d.ts.map +1 -0
- package/lib/partials/Filter.js +137 -0
- package/lib/partials/Gradient.d.ts +31 -0
- package/lib/partials/Gradient.d.ts.map +1 -0
- package/lib/partials/Gradient.js +63 -0
- package/lib/partials/Pattern.d.ts +13 -0
- package/lib/partials/Pattern.d.ts.map +1 -0
- package/lib/partials/Pattern.js +27 -0
- package/lib/partials/ShaderConfig.d.ts +81 -0
- package/lib/partials/ShaderConfig.d.ts.map +1 -0
- package/lib/partials/ShaderConfig.js +25 -0
- package/lib/partials/index.d.ts +5 -0
- package/lib/partials/index.d.ts.map +1 -0
- package/lib/partials/index.js +5 -0
- package/lib/partials/types.d.ts +35 -0
- package/lib/partials/types.d.ts.map +1 -0
- package/lib/partials/types.js +2 -0
- package/lib/scenes/Scene2D.d.ts +23 -0
- package/lib/scenes/Scene2D.d.ts.map +1 -0
- package/lib/scenes/Scene2D.js +152 -0
- package/lib/scenes/index.d.ts +4 -0
- package/lib/scenes/index.d.ts.map +1 -0
- package/lib/scenes/index.js +4 -0
- package/lib/scenes/makeScene2D.d.ts +5 -0
- package/lib/scenes/makeScene2D.d.ts.map +1 -0
- package/lib/scenes/makeScene2D.js +12 -0
- package/lib/scenes/useScene2D.d.ts +3 -0
- package/lib/scenes/useScene2D.d.ts.map +1 -0
- package/lib/scenes/useScene2D.js +5 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils/CanvasUtils.d.ts +21 -0
- package/lib/utils/CanvasUtils.d.ts.map +1 -0
- package/lib/utils/CanvasUtils.js +138 -0
- package/lib/utils/diff.d.ts +31 -0
- package/lib/utils/diff.d.ts.map +1 -0
- package/lib/utils/diff.js +97 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/is.d.ts +8 -0
- package/lib/utils/is.d.ts.map +1 -0
- package/lib/utils/is.js +10 -0
- package/lib/utils/makeSignalExtensions.d.ts +4 -0
- package/lib/utils/makeSignalExtensions.d.ts.map +1 -0
- package/lib/utils/makeSignalExtensions.js +20 -0
- package/lib/utils/withDefaults.d.ts +20 -0
- package/lib/utils/withDefaults.d.ts.map +1 -0
- package/lib/utils/withDefaults.js +23 -0
- package/package.json +54 -0
- package/src/editor/NodeInspectorConfig.tsx +76 -0
- package/src/editor/PreviewOverlayConfig.tsx +65 -0
- package/src/editor/Provider.tsx +109 -0
- package/src/editor/SceneGraphTabConfig.tsx +87 -0
- package/src/editor/icons/CircleIcon.tsx +7 -0
- package/src/editor/icons/CodeBlockIcon.tsx +8 -0
- package/src/editor/icons/CurveIcon.tsx +7 -0
- package/src/editor/icons/GridIcon.tsx +7 -0
- package/src/editor/icons/IconMap.ts +35 -0
- package/src/editor/icons/ImgIcon.tsx +8 -0
- package/src/editor/icons/LayoutIcon.tsx +9 -0
- package/src/editor/icons/LineIcon.tsx +7 -0
- package/src/editor/icons/NodeIcon.tsx +7 -0
- package/src/editor/icons/RayIcon.tsx +7 -0
- package/src/editor/icons/RectIcon.tsx +7 -0
- package/src/editor/icons/ShapeIcon.tsx +7 -0
- package/src/editor/icons/TxtIcon.tsx +8 -0
- package/src/editor/icons/VideoIcon.tsx +7 -0
- package/src/editor/icons/View2DIcon.tsx +10 -0
- package/src/editor/index.css +0 -0
- package/src/editor/index.ts +19 -0
- package/src/editor/shortcuts.ts +27 -0
- package/src/editor/tree/DetachedRoot.tsx +27 -0
- package/src/editor/tree/NodeElement.tsx +72 -0
- package/src/editor/tree/TreeElement.tsx +70 -0
- package/src/editor/tree/TreeRoot.tsx +10 -0
- package/src/editor/tree/ViewRoot.tsx +20 -0
- package/src/editor/tree/index.module.scss +45 -0
- package/src/editor/tree/index.ts +4 -0
- package/src/editor/tree/navigation.ts +145 -0
- package/src/editor/tsconfig.build.json +5 -0
- package/src/editor/tsconfig.json +12 -0
- package/src/editor/tsdoc.json +4 -0
- package/src/editor/utils/SignalSet.ts +37 -0
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/vite-env.d.ts +1 -0
- package/src/lib/code/CodeCursor.ts +468 -0
- package/src/lib/code/CodeDiffer.ts +77 -0
- package/src/lib/code/CodeFragment.ts +96 -0
- package/src/lib/code/CodeHighlighter.ts +73 -0
- package/src/lib/code/CodeMetrics.ts +47 -0
- package/src/lib/code/CodeRange.test.ts +113 -0
- package/src/lib/code/CodeRange.ts +222 -0
- package/src/lib/code/CodeScope.ts +100 -0
- package/src/lib/code/CodeSelection.ts +28 -0
- package/src/lib/code/CodeSignal.ts +348 -0
- package/src/lib/code/CodeTokenizer.ts +54 -0
- package/src/lib/code/DefaultHighlightStyle.ts +98 -0
- package/src/lib/code/LezerHighlighter.ts +113 -0
- package/src/lib/code/diff.test.ts +311 -0
- package/src/lib/code/diff.ts +319 -0
- package/src/lib/code/extractRange.ts +125 -0
- package/src/lib/code/index.ts +13 -0
- package/src/lib/components/Bezier.ts +103 -0
- package/src/lib/components/Camera.ts +359 -0
- package/src/lib/components/Circle.ts +269 -0
- package/src/lib/components/Code.ts +532 -0
- package/src/lib/components/CodeBlock.ts +581 -0
- package/src/lib/components/CubicBezier.ts +115 -0
- package/src/lib/components/Curve.ts +455 -0
- package/src/lib/components/Grid.ts +134 -0
- package/src/lib/components/Icon.ts +95 -0
- package/src/lib/components/Img.ts +305 -0
- package/src/lib/components/Knot.ts +156 -0
- package/src/lib/components/Latex.ts +249 -0
- package/src/lib/components/Layout.ts +1071 -0
- package/src/lib/components/Line.ts +394 -0
- package/src/lib/components/Node.ts +1949 -0
- package/src/lib/components/Path.ts +132 -0
- package/src/lib/components/Polygon.ts +238 -0
- package/src/lib/components/QuadBezier.ts +103 -0
- package/src/lib/components/Ray.ts +126 -0
- package/src/lib/components/Rect.ts +186 -0
- package/src/lib/components/SVG.ts +788 -0
- package/src/lib/components/Shape.ts +146 -0
- package/src/lib/components/Spline.ts +318 -0
- package/src/lib/components/Txt.test.tsx +81 -0
- package/src/lib/components/Txt.ts +204 -0
- package/src/lib/components/TxtLeaf.ts +210 -0
- package/src/lib/components/Video.ts +368 -0
- package/src/lib/components/View2D.ts +85 -0
- package/src/lib/components/__logs__/image-without-source.md +17 -0
- package/src/lib/components/__logs__/line-without-points.md +30 -0
- package/src/lib/components/__logs__/reactive-playback-rate.md +21 -0
- package/src/lib/components/__logs__/spline-with-insufficient-knots.md +24 -0
- package/src/lib/components/__tests__/children.test.tsx +142 -0
- package/src/lib/components/__tests__/clone.test.tsx +126 -0
- package/src/lib/components/__tests__/generatorTest.ts +27 -0
- package/src/lib/components/__tests__/mockScene2D.ts +50 -0
- package/src/lib/components/__tests__/query.test.tsx +122 -0
- package/src/lib/components/__tests__/state.test.tsx +60 -0
- package/src/lib/components/index.ts +26 -0
- package/src/lib/components/types.ts +35 -0
- package/src/lib/curves/ArcSegment.ts +155 -0
- package/src/lib/curves/CircleSegment.ts +77 -0
- package/src/lib/curves/CubicBezierSegment.ts +78 -0
- package/src/lib/curves/CurveDrawingInfo.ts +11 -0
- package/src/lib/curves/CurvePoint.ts +15 -0
- package/src/lib/curves/CurveProfile.ts +7 -0
- package/src/lib/curves/KnotInfo.ts +10 -0
- package/src/lib/curves/LineSegment.ts +62 -0
- package/src/lib/curves/Polynomial.ts +355 -0
- package/src/lib/curves/Polynomial2D.ts +62 -0
- package/src/lib/curves/PolynomialSegment.ts +124 -0
- package/src/lib/curves/QuadBezierSegment.ts +64 -0
- package/src/lib/curves/Segment.ts +17 -0
- package/src/lib/curves/UniformPolynomialCurveSampler.ts +93 -0
- package/src/lib/curves/createCurveProfileLerp.ts +471 -0
- package/src/lib/curves/getBezierSplineProfile.ts +227 -0
- package/src/lib/curves/getCircleProfile.ts +86 -0
- package/src/lib/curves/getPathProfile.ts +177 -0
- package/src/lib/curves/getPointAtDistance.ts +21 -0
- package/src/lib/curves/getPolylineProfile.test.ts +21 -0
- package/src/lib/curves/getPolylineProfile.ts +88 -0
- package/src/lib/curves/getRectProfile.ts +138 -0
- package/src/lib/curves/index.ts +16 -0
- package/src/lib/decorators/canvasStyleSignal.ts +15 -0
- package/src/lib/decorators/colorSignal.ts +9 -0
- package/src/lib/decorators/compound.ts +85 -0
- package/src/lib/decorators/computed.ts +18 -0
- package/src/lib/decorators/defaultStyle.ts +15 -0
- package/src/lib/decorators/filtersSignal.ts +133 -0
- package/src/lib/decorators/index.ts +10 -0
- package/src/lib/decorators/initializers.ts +34 -0
- package/src/lib/decorators/nodeName.ts +13 -0
- package/src/lib/decorators/signal.test.ts +89 -0
- package/src/lib/decorators/signal.ts +348 -0
- package/src/lib/decorators/spacingSignal.ts +15 -0
- package/src/lib/decorators/vector2Signal.ts +35 -0
- package/src/lib/globals.d.ts +3 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/jsx-dev-runtime.ts +2 -0
- package/src/lib/jsx-runtime.ts +45 -0
- package/src/lib/parse-svg-path.d.ts +14 -0
- package/src/lib/partials/Filter.ts +185 -0
- package/src/lib/partials/Gradient.ts +103 -0
- package/src/lib/partials/Pattern.ts +35 -0
- package/src/lib/partials/ShaderConfig.ts +122 -0
- package/src/lib/partials/index.ts +4 -0
- package/src/lib/partials/types.ts +58 -0
- package/src/lib/scenes/Scene2D.ts +195 -0
- package/src/lib/scenes/index.ts +3 -0
- package/src/lib/scenes/makeScene2D.ts +19 -0
- package/src/lib/scenes/useScene2D.ts +6 -0
- package/src/lib/tsconfig.build.json +12 -0
- package/src/lib/tsconfig.json +14 -0
- package/src/lib/tsdoc.json +4 -0
- package/src/lib/utils/CanvasUtils.ts +306 -0
- package/src/lib/utils/diff.test.ts +453 -0
- package/src/lib/utils/diff.ts +148 -0
- package/src/lib/utils/index.ts +3 -0
- package/src/lib/utils/is.ts +11 -0
- package/src/lib/utils/makeSignalExtensions.ts +29 -0
- package/src/lib/utils/withDefaults.tsx +26 -0
- package/src/tsconfig.base.json +18 -0
- package/src/tsconfig.build.json +8 -0
- package/src/tsconfig.json +5 -0
- package/tsconfig.project.json +7 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BBox,
|
|
3
|
+
createSignal,
|
|
4
|
+
PossibleVector2,
|
|
5
|
+
SignalValue,
|
|
6
|
+
SimpleSignal,
|
|
7
|
+
threadable,
|
|
8
|
+
ThreadGenerator,
|
|
9
|
+
TimingFunction,
|
|
10
|
+
tween,
|
|
11
|
+
unwrap,
|
|
12
|
+
useLogger,
|
|
13
|
+
Vector2,
|
|
14
|
+
} from '@efxlab/motion-canvas-core';
|
|
15
|
+
import {CurveProfile, getPolylineProfile} from '../curves';
|
|
16
|
+
import {
|
|
17
|
+
calculateLerpDistance,
|
|
18
|
+
polygonLength,
|
|
19
|
+
polygonPointsLerp,
|
|
20
|
+
} from '../curves/createCurveProfileLerp';
|
|
21
|
+
import {computed, initial, nodeName, signal} from '../decorators';
|
|
22
|
+
import {arc, drawLine, drawPivot, lineTo, moveTo} from '../utils';
|
|
23
|
+
import lineWithoutPoints from './__logs__/line-without-points.md';
|
|
24
|
+
import {Curve, CurveProps} from './Curve';
|
|
25
|
+
import {Layout} from './Layout';
|
|
26
|
+
|
|
27
|
+
export interface LineProps extends CurveProps {
|
|
28
|
+
/**
|
|
29
|
+
* {@inheritDoc Line.radius}
|
|
30
|
+
*/
|
|
31
|
+
radius?: SignalValue<number>;
|
|
32
|
+
/**
|
|
33
|
+
* {@inheritDoc Line.points}
|
|
34
|
+
*/
|
|
35
|
+
points?: SignalValue<SignalValue<PossibleVector2>[]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A node for drawing lines and polygons.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* This node can be used to render any polygonal shape defined by a set of
|
|
43
|
+
* points.
|
|
44
|
+
*
|
|
45
|
+
* @preview
|
|
46
|
+
* ```tsx editor
|
|
47
|
+
* // snippet Simple line
|
|
48
|
+
* import {makeScene2D, Line} from '@efxlab/motion-canvas-2d';
|
|
49
|
+
*
|
|
50
|
+
* export default makeScene2D(function* (view) {
|
|
51
|
+
* view.add(
|
|
52
|
+
* <Line
|
|
53
|
+
* points={[
|
|
54
|
+
* [150, 50],
|
|
55
|
+
* [0, -50],
|
|
56
|
+
* [-150, 50],
|
|
57
|
+
* ]}
|
|
58
|
+
* stroke={'lightseagreen'}
|
|
59
|
+
* lineWidth={8}
|
|
60
|
+
* radius={40}
|
|
61
|
+
* startArrow
|
|
62
|
+
* />,
|
|
63
|
+
* );
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // snippet Polygon
|
|
67
|
+
* import {makeScene2D, Line} from '@efxlab/motion-canvas-2d';
|
|
68
|
+
*
|
|
69
|
+
* export default makeScene2D(function* (view) {
|
|
70
|
+
* view.add(
|
|
71
|
+
* <Line
|
|
72
|
+
* points={[
|
|
73
|
+
* [-200, 70],
|
|
74
|
+
* [150, 70],
|
|
75
|
+
* [100, -70],
|
|
76
|
+
* [-100, -70],
|
|
77
|
+
* ]}
|
|
78
|
+
* fill={'lightseagreen'}
|
|
79
|
+
* closed
|
|
80
|
+
* />,
|
|
81
|
+
* );
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // snippet Using signals
|
|
85
|
+
* import {makeScene2D, Line} from '@efxlab/motion-canvas-2d';
|
|
86
|
+
* import {createSignal} from '@efxlab/motion-canvas-core';
|
|
87
|
+
*
|
|
88
|
+
* export default makeScene2D(function* (view) {
|
|
89
|
+
* const tip = createSignal(-150);
|
|
90
|
+
* view.add(
|
|
91
|
+
* <Line
|
|
92
|
+
* points={[
|
|
93
|
+
* [-150, 70],
|
|
94
|
+
* [150, 70],
|
|
95
|
+
* // this point is dynamically calculated based on the signal:
|
|
96
|
+
* () => [tip(), -70],
|
|
97
|
+
* ]}
|
|
98
|
+
* stroke={'lightseagreen'}
|
|
99
|
+
* lineWidth={8}
|
|
100
|
+
* closed
|
|
101
|
+
* />,
|
|
102
|
+
* );
|
|
103
|
+
*
|
|
104
|
+
* yield* tip(150, 1).back(1);
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // snippet Tweening points
|
|
108
|
+
* import {makeScene2D, Line} from '@efxlab/motion-canvas-2d';
|
|
109
|
+
* import {createRef} from '@efxlab/motion-canvas-core';
|
|
110
|
+
*
|
|
111
|
+
* export default makeScene2D(function* (view) {
|
|
112
|
+
* const line = createRef<Line>();
|
|
113
|
+
* view.add(
|
|
114
|
+
* <Line
|
|
115
|
+
* ref={line}
|
|
116
|
+
* points={[
|
|
117
|
+
* [-150, 70],
|
|
118
|
+
* [150, 70],
|
|
119
|
+
* [0, -70],
|
|
120
|
+
* ]}
|
|
121
|
+
* stroke={'lightseagreen'}
|
|
122
|
+
* lineWidth={8}
|
|
123
|
+
* radius={20}
|
|
124
|
+
* closed
|
|
125
|
+
* />,
|
|
126
|
+
* );
|
|
127
|
+
*
|
|
128
|
+
* yield* line()
|
|
129
|
+
* .points(
|
|
130
|
+
* [
|
|
131
|
+
* [-150, 0],
|
|
132
|
+
* [0, 100],
|
|
133
|
+
* [150, 0],
|
|
134
|
+
* [150, -70],
|
|
135
|
+
* [-150, -70],
|
|
136
|
+
* ],
|
|
137
|
+
* 2,
|
|
138
|
+
* )
|
|
139
|
+
* .back(2);
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
@nodeName('Line')
|
|
144
|
+
export class Line extends Curve {
|
|
145
|
+
/**
|
|
146
|
+
* Rotate the points to minimize the overall distance traveled when tweening.
|
|
147
|
+
*
|
|
148
|
+
* @param points - The points to rotate.
|
|
149
|
+
* @param reference - The reference points to which the distance is measured.
|
|
150
|
+
* @param closed - Whether the points form a closed polygon.
|
|
151
|
+
*/
|
|
152
|
+
private static rotatePoints(
|
|
153
|
+
points: Vector2[],
|
|
154
|
+
reference: Vector2[],
|
|
155
|
+
closed: boolean,
|
|
156
|
+
) {
|
|
157
|
+
if (closed) {
|
|
158
|
+
let minDistance = Infinity;
|
|
159
|
+
let bestOffset = 0;
|
|
160
|
+
for (let offset = 0; offset < points.length; offset += 1) {
|
|
161
|
+
const distance = calculateLerpDistance(points, reference, offset);
|
|
162
|
+
if (distance < minDistance) {
|
|
163
|
+
minDistance = distance;
|
|
164
|
+
bestOffset = offset;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (bestOffset) {
|
|
169
|
+
const spliced = points.splice(0, bestOffset);
|
|
170
|
+
points.splice(points.length, 0, ...spliced);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
const originalDistance = calculateLerpDistance(points, reference, 0);
|
|
174
|
+
const reversedPoints = [...points].reverse();
|
|
175
|
+
const reversedDistance = calculateLerpDistance(
|
|
176
|
+
reversedPoints,
|
|
177
|
+
reference,
|
|
178
|
+
0,
|
|
179
|
+
);
|
|
180
|
+
if (reversedDistance < originalDistance) {
|
|
181
|
+
points.reverse();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Distribute additional points along the polyline.
|
|
188
|
+
*
|
|
189
|
+
* @param points - The points of a polyline along which new points should be
|
|
190
|
+
* distributed.
|
|
191
|
+
* @param count - The number of points to add.
|
|
192
|
+
*/
|
|
193
|
+
private static distributePoints(points: Vector2[], count: number) {
|
|
194
|
+
if (points.length === 0) {
|
|
195
|
+
for (let j = 0; j < count; j++) {
|
|
196
|
+
points.push(Vector2.zero);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (points.length === 1) {
|
|
202
|
+
const point = points[0];
|
|
203
|
+
for (let j = 0; j < count; j++) {
|
|
204
|
+
points.push(point);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const desiredLength = points.length + count;
|
|
210
|
+
const arcLength = polygonLength(points);
|
|
211
|
+
let density = arcLength === 0 ? 0 : count / arcLength;
|
|
212
|
+
|
|
213
|
+
let i = 0;
|
|
214
|
+
while (points.length < desiredLength) {
|
|
215
|
+
const pointsLeft = desiredLength - points.length;
|
|
216
|
+
|
|
217
|
+
if (i + 1 >= points.length) {
|
|
218
|
+
density = arcLength === 0 ? 0 : pointsLeft / arcLength;
|
|
219
|
+
i = 0;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const a = points[i];
|
|
224
|
+
const b = points[i + 1];
|
|
225
|
+
const length = a.sub(b).magnitude;
|
|
226
|
+
let pointCount = Math.min(Math.round(length * density), pointsLeft) + 1;
|
|
227
|
+
|
|
228
|
+
if (arcLength === 0) {
|
|
229
|
+
pointCount = 2;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (let j = 1; j < pointCount; j++) {
|
|
233
|
+
points.splice(++i, 0, Vector2.lerp(a, b, j / pointCount));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
i++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The radius of the line's corners.
|
|
242
|
+
*/
|
|
243
|
+
@initial(0)
|
|
244
|
+
@signal()
|
|
245
|
+
declare public readonly radius: SimpleSignal<number, this>;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The points of the line.
|
|
249
|
+
*
|
|
250
|
+
* @remarks
|
|
251
|
+
* When set to `null`, the Line will use the positions of its children as
|
|
252
|
+
* points.
|
|
253
|
+
*/
|
|
254
|
+
@initial(null)
|
|
255
|
+
@signal()
|
|
256
|
+
declare public readonly points: SimpleSignal<
|
|
257
|
+
SignalValue<PossibleVector2>[] | null,
|
|
258
|
+
this
|
|
259
|
+
>;
|
|
260
|
+
|
|
261
|
+
@threadable()
|
|
262
|
+
protected *tweenPoints(
|
|
263
|
+
value: SignalValue<SignalValue<PossibleVector2>[] | null>,
|
|
264
|
+
time: number,
|
|
265
|
+
timingFunction: TimingFunction,
|
|
266
|
+
): ThreadGenerator {
|
|
267
|
+
const fromPoints = [...this.parsedPoints()];
|
|
268
|
+
const toPoints = this.parsePoints(unwrap(value));
|
|
269
|
+
const closed = this.closed();
|
|
270
|
+
|
|
271
|
+
const diff = fromPoints.length - toPoints.length;
|
|
272
|
+
Line.distributePoints(diff < 0 ? fromPoints : toPoints, Math.abs(diff));
|
|
273
|
+
Line.rotatePoints(toPoints, fromPoints, closed);
|
|
274
|
+
|
|
275
|
+
this.tweenedPoints(fromPoints);
|
|
276
|
+
yield* tween(
|
|
277
|
+
time,
|
|
278
|
+
value => {
|
|
279
|
+
const progress = timingFunction(value);
|
|
280
|
+
this.tweenedPoints(polygonPointsLerp(fromPoints, toPoints, progress));
|
|
281
|
+
},
|
|
282
|
+
() => {
|
|
283
|
+
this.tweenedPoints(null);
|
|
284
|
+
this.points(value);
|
|
285
|
+
},
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private tweenedPoints = createSignal<Vector2[] | null>(null);
|
|
290
|
+
|
|
291
|
+
public constructor(props: LineProps) {
|
|
292
|
+
super(props);
|
|
293
|
+
|
|
294
|
+
if (props.children === undefined && props.points === undefined) {
|
|
295
|
+
useLogger().warn({
|
|
296
|
+
message: 'No points specified for the line',
|
|
297
|
+
remarks: lineWithoutPoints,
|
|
298
|
+
inspect: this.key,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
@computed()
|
|
304
|
+
protected childrenBBox() {
|
|
305
|
+
let points = this.tweenedPoints();
|
|
306
|
+
if (!points) {
|
|
307
|
+
const custom = this.points();
|
|
308
|
+
points = custom
|
|
309
|
+
? custom.map(signal => new Vector2(unwrap(signal)))
|
|
310
|
+
: this.children()
|
|
311
|
+
.filter(child => !(child instanceof Layout) || child.isLayoutRoot())
|
|
312
|
+
.map(child => child.position());
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return BBox.fromPoints(...points);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
@computed()
|
|
319
|
+
public parsedPoints(): Vector2[] {
|
|
320
|
+
return this.parsePoints(this.points());
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@computed()
|
|
324
|
+
public override profile(): CurveProfile {
|
|
325
|
+
return getPolylineProfile(
|
|
326
|
+
this.tweenedPoints() ?? this.parsedPoints(),
|
|
327
|
+
this.radius(),
|
|
328
|
+
this.closed(),
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
protected override lineWidthCoefficient(): number {
|
|
333
|
+
const radius = this.radius();
|
|
334
|
+
const join = this.lineJoin();
|
|
335
|
+
|
|
336
|
+
let coefficient = super.lineWidthCoefficient();
|
|
337
|
+
|
|
338
|
+
if (radius === 0 && join === 'miter') {
|
|
339
|
+
const {minSin} = this.profile();
|
|
340
|
+
if (minSin > 0) {
|
|
341
|
+
coefficient = Math.max(coefficient, 0.5 / minSin);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return coefficient;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public override drawOverlay(
|
|
349
|
+
context: CanvasRenderingContext2D,
|
|
350
|
+
matrix: DOMMatrix,
|
|
351
|
+
) {
|
|
352
|
+
const box = this.childrenBBox().transformCorners(matrix);
|
|
353
|
+
const size = this.computedSize();
|
|
354
|
+
const offset = size.mul(this.offset()).scale(0.5).transformAsPoint(matrix);
|
|
355
|
+
|
|
356
|
+
context.fillStyle = 'white';
|
|
357
|
+
context.strokeStyle = 'black';
|
|
358
|
+
context.lineWidth = 1;
|
|
359
|
+
|
|
360
|
+
const path = new Path2D();
|
|
361
|
+
const points = (this.tweenedPoints() ?? this.parsedPoints()).map(point =>
|
|
362
|
+
point.transformAsPoint(matrix),
|
|
363
|
+
);
|
|
364
|
+
if (points.length > 0) {
|
|
365
|
+
moveTo(path, points[0]);
|
|
366
|
+
for (const point of points) {
|
|
367
|
+
lineTo(path, point);
|
|
368
|
+
context.beginPath();
|
|
369
|
+
arc(context, point, 4);
|
|
370
|
+
context.closePath();
|
|
371
|
+
context.fill();
|
|
372
|
+
context.stroke();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
context.strokeStyle = 'white';
|
|
377
|
+
context.stroke(path);
|
|
378
|
+
|
|
379
|
+
context.beginPath();
|
|
380
|
+
drawPivot(context, offset);
|
|
381
|
+
context.stroke();
|
|
382
|
+
|
|
383
|
+
context.beginPath();
|
|
384
|
+
drawLine(context, box);
|
|
385
|
+
context.closePath();
|
|
386
|
+
context.stroke();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private parsePoints(points: SignalValue<PossibleVector2>[] | null) {
|
|
390
|
+
return points
|
|
391
|
+
? points.map(signal => new Vector2(unwrap(signal)))
|
|
392
|
+
: this.children().map(child => child.position());
|
|
393
|
+
}
|
|
394
|
+
}
|