@twick/2d 0.11.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/LICENSE +21 -0
- package/editor/editor/NodeInspectorConfig.d.ts +3 -0
- package/editor/editor/NodeInspectorConfig.d.ts.map +1 -0
- package/editor/editor/PreviewOverlayConfig.d.ts +3 -0
- package/editor/editor/PreviewOverlayConfig.d.ts.map +1 -0
- package/editor/editor/Provider.d.ts +17 -0
- package/editor/editor/Provider.d.ts.map +1 -0
- package/editor/editor/SceneGraphTabConfig.d.ts +3 -0
- package/editor/editor/SceneGraphTabConfig.d.ts.map +1 -0
- package/editor/editor/icons/CircleIcon.d.ts +2 -0
- package/editor/editor/icons/CircleIcon.d.ts.map +1 -0
- package/editor/editor/icons/CodeBlockIcon.d.ts +2 -0
- package/editor/editor/icons/CodeBlockIcon.d.ts.map +1 -0
- package/editor/editor/icons/CurveIcon.d.ts +2 -0
- package/editor/editor/icons/CurveIcon.d.ts.map +1 -0
- package/editor/editor/icons/GridIcon.d.ts +2 -0
- package/editor/editor/icons/GridIcon.d.ts.map +1 -0
- package/editor/editor/icons/IconMap.d.ts +3 -0
- package/editor/editor/icons/IconMap.d.ts.map +1 -0
- package/editor/editor/icons/ImgIcon.d.ts +2 -0
- package/editor/editor/icons/ImgIcon.d.ts.map +1 -0
- package/editor/editor/icons/LayoutIcon.d.ts +2 -0
- package/editor/editor/icons/LayoutIcon.d.ts.map +1 -0
- package/editor/editor/icons/LineIcon.d.ts +2 -0
- package/editor/editor/icons/LineIcon.d.ts.map +1 -0
- package/editor/editor/icons/NodeIcon.d.ts +2 -0
- package/editor/editor/icons/NodeIcon.d.ts.map +1 -0
- package/editor/editor/icons/RayIcon.d.ts +2 -0
- package/editor/editor/icons/RayIcon.d.ts.map +1 -0
- package/editor/editor/icons/RectIcon.d.ts +2 -0
- package/editor/editor/icons/RectIcon.d.ts.map +1 -0
- package/editor/editor/icons/ShapeIcon.d.ts +2 -0
- package/editor/editor/icons/ShapeIcon.d.ts.map +1 -0
- package/editor/editor/icons/TxtIcon.d.ts +2 -0
- package/editor/editor/icons/TxtIcon.d.ts.map +1 -0
- package/editor/editor/icons/VideoIcon.d.ts +2 -0
- package/editor/editor/icons/VideoIcon.d.ts.map +1 -0
- package/editor/editor/icons/View2DIcon.d.ts +2 -0
- package/editor/editor/icons/View2DIcon.d.ts.map +1 -0
- package/editor/editor/index.d.ts +4 -0
- package/editor/editor/index.d.ts.map +1 -0
- package/editor/editor/tree/DetachedRoot.d.ts +2 -0
- package/editor/editor/tree/DetachedRoot.d.ts.map +1 -0
- package/editor/editor/tree/NodeElement.d.ts +8 -0
- package/editor/editor/tree/NodeElement.d.ts.map +1 -0
- package/editor/editor/tree/TreeElement.d.ts +15 -0
- package/editor/editor/tree/TreeElement.d.ts.map +1 -0
- package/editor/editor/tree/TreeRoot.d.ts +3 -0
- package/editor/editor/tree/TreeRoot.d.ts.map +1 -0
- package/editor/editor/tree/ViewRoot.d.ts +2 -0
- package/editor/editor/tree/ViewRoot.d.ts.map +1 -0
- package/editor/editor/tree/index.d.ts +4 -0
- package/editor/editor/tree/index.d.ts.map +1 -0
- package/editor/editor/tsconfig.build.tsbuildinfo +1 -0
- package/editor/index.css +33 -0
- package/editor/index.js +341 -0
- package/editor/index.js.map +1 -0
- package/lib/code/CodeCursor.d.ts +83 -0
- package/lib/code/CodeCursor.d.ts.map +1 -0
- package/lib/code/CodeCursor.js +306 -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 +71 -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 +41 -0
- package/lib/code/CodeRange.d.ts.map +1 -0
- package/lib/code/CodeRange.js +179 -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 +60 -0
- package/lib/code/CodeSignal.d.ts.map +1 -0
- package/lib/code/CodeSignal.js +194 -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 +89 -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/Audio.d.ts +14 -0
- package/lib/components/Audio.d.ts.map +1 -0
- package/lib/components/Audio.js +118 -0
- package/lib/components/Bezier.d.ts +23 -0
- package/lib/components/Bezier.d.ts.map +1 -0
- package/lib/components/Bezier.js +81 -0
- package/lib/components/Circle.d.ts +193 -0
- package/lib/components/Circle.d.ts.map +1 -0
- package/lib/components/Circle.js +178 -0
- package/lib/components/Code.d.ts +231 -0
- package/lib/components/Code.d.ts.map +1 -0
- package/lib/components/Code.js +325 -0
- package/lib/components/CodeBlock.d.ts +133 -0
- package/lib/components/CodeBlock.d.ts.map +1 -0
- package/lib/components/CodeBlock.js +461 -0
- package/lib/components/CubicBezier.d.ts +70 -0
- package/lib/components/CubicBezier.d.ts.map +1 -0
- package/lib/components/CubicBezier.js +81 -0
- package/lib/components/Curve.d.ts +204 -0
- package/lib/components/Curve.d.ts.map +1 -0
- package/lib/components/Curve.js +284 -0
- package/lib/components/Grid.d.ts +76 -0
- package/lib/components/Grid.d.ts.map +1 -0
- package/lib/components/Grid.js +91 -0
- package/lib/components/Icon.d.ts +59 -0
- package/lib/components/Icon.d.ts.map +1 -0
- package/lib/components/Icon.js +58 -0
- package/lib/components/Img.d.ts +118 -0
- package/lib/components/Img.d.ts.map +1 -0
- package/lib/components/Img.js +245 -0
- package/lib/components/Knot.d.ts +90 -0
- package/lib/components/Knot.d.ts.map +1 -0
- package/lib/components/Knot.js +68 -0
- package/lib/components/Latex.d.ts +39 -0
- package/lib/components/Latex.d.ts.map +1 -0
- package/lib/components/Latex.js +101 -0
- package/lib/components/Layout.d.ts +419 -0
- package/lib/components/Layout.d.ts.map +1 -0
- package/lib/components/Layout.js +706 -0
- package/lib/components/Line.d.ts +160 -0
- package/lib/components/Line.d.ts.map +1 -0
- package/lib/components/Line.js +346 -0
- package/lib/components/Media.d.ts +65 -0
- package/lib/components/Media.d.ts.map +1 -0
- package/lib/components/Media.js +303 -0
- package/lib/components/Node.d.ts +836 -0
- package/lib/components/Node.d.ts.map +1 -0
- package/lib/components/Node.js +1317 -0
- package/lib/components/Path.d.ts +20 -0
- package/lib/components/Path.d.ts.map +1 -0
- package/lib/components/Path.js +97 -0
- package/lib/components/Polygon.d.ts +113 -0
- package/lib/components/Polygon.d.ts.map +1 -0
- package/lib/components/Polygon.js +123 -0
- package/lib/components/QuadBezier.d.ts +62 -0
- package/lib/components/QuadBezier.d.ts.map +1 -0
- package/lib/components/QuadBezier.js +76 -0
- package/lib/components/Ray.d.ts +62 -0
- package/lib/components/Ray.d.ts.map +1 -0
- package/lib/components/Ray.js +96 -0
- package/lib/components/Rect.d.ts +114 -0
- package/lib/components/Rect.d.ts.map +1 -0
- package/lib/components/Rect.js +76 -0
- package/lib/components/Rive.d.ts +22 -0
- package/lib/components/Rive.d.ts.map +1 -0
- package/lib/components/Rive.js +117 -0
- package/lib/components/SVG.d.ts +178 -0
- package/lib/components/SVG.d.ts.map +1 -0
- package/lib/components/SVG.js +577 -0
- package/lib/components/Shape.d.ts +40 -0
- package/lib/components/Shape.d.ts.map +1 -0
- package/lib/components/Shape.js +134 -0
- package/lib/components/Spline.d.ts +89 -0
- package/lib/components/Spline.d.ts.map +1 -0
- package/lib/components/Spline.js +256 -0
- package/lib/components/Txt.d.ts +53 -0
- package/lib/components/Txt.d.ts.map +1 -0
- package/lib/components/Txt.js +173 -0
- package/lib/components/TxtLeaf.d.ts +21 -0
- package/lib/components/TxtLeaf.d.ts.map +1 -0
- package/lib/components/TxtLeaf.js +181 -0
- package/lib/components/Video.d.ts +69 -0
- package/lib/components/Video.d.ts.map +1 -0
- package/lib/components/Video.js +283 -0
- package/lib/components/View2D.d.ts +28 -0
- package/lib/components/View2D.d.ts.map +1 -0
- package/lib/components/View2D.js +93 -0
- package/lib/components/index.d.ts +29 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +29 -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 +97 -0
- package/lib/curves/CircleSegment.d.ts +18 -0
- package/lib/curves/CircleSegment.d.ts.map +1 -0
- package/lib/curves/CircleSegment.js +52 -0
- package/lib/curves/CubicBezierSegment.d.ts +18 -0
- package/lib/curves/CubicBezierSegment.d.ts.map +1 -0
- package/lib/curves/CubicBezierSegment.js +55 -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 +45 -0
- package/lib/curves/Polynomial.d.ts +118 -0
- package/lib/curves/Polynomial.d.ts.map +1 -0
- package/lib/curves/Polynomial.js +259 -0
- package/lib/curves/Polynomial2D.d.ts +22 -0
- package/lib/curves/Polynomial2D.d.ts.map +1 -0
- package/lib/curves/Polynomial2D.js +45 -0
- package/lib/curves/PolynomialSegment.d.ts +39 -0
- package/lib/curves/PolynomialSegment.d.ts.map +1 -0
- package/lib/curves/PolynomialSegment.js +86 -0
- package/lib/curves/QuadBezierSegment.d.ts +17 -0
- package/lib/curves/QuadBezierSegment.d.ts.map +1 -0
- package/lib/curves/QuadBezierSegment.js +49 -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 +73 -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 +137 -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 +26 -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 +14 -0
- package/lib/decorators/filtersSignal.d.ts +13 -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 +9 -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 +135 -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 +29 -0
- package/lib/scenes/Scene2D.d.ts.map +1 -0
- package/lib/scenes/Scene2D.js +180 -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 +11 -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/utils/CanvasUtils.d.ts +23 -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 +3 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +3 -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/video/ffmpeg-client.d.ts +5 -0
- package/lib/utils/video/ffmpeg-client.d.ts.map +1 -0
- package/lib/utils/video/ffmpeg-client.js +32 -0
- package/lib/utils/video/mp4-parser-manager.d.ts +3 -0
- package/lib/utils/video/mp4-parser-manager.d.ts.map +1 -0
- package/lib/utils/video/mp4-parser-manager.js +55 -0
- package/lib/utils/video/parser/index.d.ts +2 -0
- package/lib/utils/video/parser/index.d.ts.map +1 -0
- package/lib/utils/video/parser/index.js +2 -0
- package/lib/utils/video/parser/parser.d.ts +21 -0
- package/lib/utils/video/parser/parser.d.ts.map +1 -0
- package/lib/utils/video/parser/parser.js +168 -0
- package/lib/utils/video/parser/sampler.d.ts +16 -0
- package/lib/utils/video/parser/sampler.d.ts.map +1 -0
- package/lib/utils/video/parser/sampler.js +56 -0
- package/lib/utils/video/parser/segment.d.ts +48 -0
- package/lib/utils/video/parser/segment.d.ts.map +1 -0
- package/lib/utils/video/parser/segment.js +239 -0
- package/lib/utils/video/parser/sink.d.ts +9 -0
- package/lib/utils/video/parser/sink.d.ts.map +1 -0
- package/lib/utils/video/parser/sink.js +22 -0
- package/lib/utils/video/parser/utils.d.ts +10 -0
- package/lib/utils/video/parser/utils.d.ts.map +1 -0
- package/lib/utils/video/parser/utils.js +22 -0
- package/package.json +53 -0
- package/src/editor/NodeInspectorConfig.tsx +76 -0
- package/src/editor/PreviewOverlayConfig.tsx +67 -0
- package/src/editor/Provider.tsx +93 -0
- package/src/editor/SceneGraphTabConfig.tsx +81 -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 +17 -0
- package/src/editor/tree/DetachedRoot.tsx +23 -0
- package/src/editor/tree/NodeElement.tsx +74 -0
- package/src/editor/tree/TreeElement.tsx +72 -0
- package/src/editor/tree/TreeRoot.tsx +10 -0
- package/src/editor/tree/ViewRoot.tsx +20 -0
- package/src/editor/tree/index.module.scss +38 -0
- package/src/editor/tree/index.ts +3 -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/vite-env.d.ts +1 -0
- package/src/lib/code/CodeCursor.ts +445 -0
- package/src/lib/code/CodeDiffer.ts +78 -0
- package/src/lib/code/CodeFragment.ts +97 -0
- package/src/lib/code/CodeHighlighter.ts +75 -0
- package/src/lib/code/CodeMetrics.ts +47 -0
- package/src/lib/code/CodeRange.test.ts +74 -0
- package/src/lib/code/CodeRange.ts +216 -0
- package/src/lib/code/CodeScope.ts +101 -0
- package/src/lib/code/CodeSelection.ts +24 -0
- package/src/lib/code/CodeSignal.ts +327 -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 +126 -0
- package/src/lib/code/index.ts +13 -0
- package/src/lib/components/Audio.ts +131 -0
- package/src/lib/components/Bezier.ts +105 -0
- package/src/lib/components/Circle.ts +266 -0
- package/src/lib/components/Code.ts +526 -0
- package/src/lib/components/CodeBlock.ts +576 -0
- package/src/lib/components/CubicBezier.ts +112 -0
- package/src/lib/components/Curve.ts +455 -0
- package/src/lib/components/Grid.ts +135 -0
- package/src/lib/components/Icon.ts +96 -0
- package/src/lib/components/Img.ts +319 -0
- package/src/lib/components/Knot.ts +157 -0
- package/src/lib/components/Latex.ts +122 -0
- package/src/lib/components/Layout.ts +1092 -0
- package/src/lib/components/Line.ts +429 -0
- package/src/lib/components/Media.ts +379 -0
- package/src/lib/components/Node.ts +1940 -0
- package/src/lib/components/Path.ts +137 -0
- package/src/lib/components/Polygon.ts +171 -0
- package/src/lib/components/QuadBezier.ts +100 -0
- package/src/lib/components/Ray.ts +125 -0
- package/src/lib/components/Rect.ts +187 -0
- package/src/lib/components/Rive.ts +156 -0
- package/src/lib/components/SVG.ts +797 -0
- package/src/lib/components/Shape.ts +143 -0
- package/src/lib/components/Spline.ts +344 -0
- package/src/lib/components/Txt.test.tsx +81 -0
- package/src/lib/components/Txt.ts +203 -0
- package/src/lib/components/TxtLeaf.ts +205 -0
- package/src/lib/components/Video.ts +397 -0
- package/src/lib/components/View2D.ts +98 -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 +28 -0
- package/src/lib/components/__tests__/mockScene2D.ts +45 -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 +28 -0
- package/src/lib/components/types.ts +35 -0
- package/src/lib/curves/ArcSegment.ts +159 -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 +94 -0
- package/src/lib/curves/createCurveProfileLerp.ts +471 -0
- package/src/lib/curves/getBezierSplineProfile.ts +223 -0
- package/src/lib/curves/getCircleProfile.ts +86 -0
- package/src/lib/curves/getPathProfile.ts +178 -0
- package/src/lib/curves/getPointAtDistance.ts +21 -0
- package/src/lib/curves/getPolylineProfile.test.ts +21 -0
- package/src/lib/curves/getPolylineProfile.ts +89 -0
- package/src/lib/curves/getRectProfile.ts +139 -0
- package/src/lib/curves/index.ts +16 -0
- package/src/lib/decorators/canvasStyleSignal.ts +16 -0
- package/src/lib/decorators/colorSignal.ts +9 -0
- package/src/lib/decorators/compound.ts +72 -0
- package/src/lib/decorators/computed.ts +18 -0
- package/src/lib/decorators/defaultStyle.ts +18 -0
- package/src/lib/decorators/filtersSignal.ts +136 -0
- package/src/lib/decorators/index.ts +10 -0
- package/src/lib/decorators/initializers.ts +32 -0
- package/src/lib/decorators/nodeName.ts +13 -0
- package/src/lib/decorators/signal.test.ts +90 -0
- package/src/lib/decorators/signal.ts +345 -0
- package/src/lib/decorators/spacingSignal.ts +15 -0
- package/src/lib/decorators/vector2Signal.ts +30 -0
- package/src/lib/globals.d.ts +2 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/jsx-dev-runtime.ts +2 -0
- package/src/lib/jsx-runtime.ts +46 -0
- package/src/lib/parse-svg-path.d.ts +14 -0
- package/src/lib/partials/Filter.ts +180 -0
- package/src/lib/partials/Gradient.ts +102 -0
- package/src/lib/partials/Pattern.ts +34 -0
- package/src/lib/partials/ShaderConfig.ts +117 -0
- package/src/lib/partials/index.ts +4 -0
- package/src/lib/partials/types.ts +58 -0
- package/src/lib/scenes/Scene2D.ts +242 -0
- package/src/lib/scenes/index.ts +3 -0
- package/src/lib/scenes/makeScene2D.ts +16 -0
- package/src/lib/scenes/useScene2D.ts +6 -0
- package/src/lib/tsconfig.build.json +5 -0
- package/src/lib/tsconfig.json +10 -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 +2 -0
- package/src/lib/utils/is.ts +11 -0
- package/src/lib/utils/makeSignalExtensions.ts +30 -0
- package/src/lib/utils/video/declarations.d.ts +1 -0
- package/src/lib/utils/video/ffmpeg-client.ts +50 -0
- package/src/lib/utils/video/mp4-parser-manager.ts +72 -0
- package/src/lib/utils/video/parser/index.ts +1 -0
- package/src/lib/utils/video/parser/parser.ts +257 -0
- package/src/lib/utils/video/parser/sampler.ts +72 -0
- package/src/lib/utils/video/parser/segment.ts +302 -0
- package/src/lib/utils/video/parser/sink.ts +29 -0
- package/src/lib/utils/video/parser/utils.ts +31 -0
- package/src/tsconfig.base.json +19 -0
- package/src/tsconfig.build.json +8 -0
- package/src/tsconfig.json +5 -0
- package/tsconfig.project.json +7 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BBox, transformVectorAsPoint } from '@twick/core';
|
|
8
|
+
import { computed } from '../decorators';
|
|
9
|
+
import { arc, drawLine, drawPivot, moveTo } from '../utils';
|
|
10
|
+
import { Curve } from './Curve';
|
|
11
|
+
export class Bezier extends Curve {
|
|
12
|
+
profile() {
|
|
13
|
+
const segment = this.segment();
|
|
14
|
+
return {
|
|
15
|
+
segments: [segment],
|
|
16
|
+
arcLength: segment.arcLength,
|
|
17
|
+
minSin: 0,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
childrenBBox() {
|
|
21
|
+
return BBox.fromPoints(...this.segment().points);
|
|
22
|
+
}
|
|
23
|
+
desiredSize() {
|
|
24
|
+
return this.segment().getBBox().size;
|
|
25
|
+
}
|
|
26
|
+
offsetComputedLayout(box) {
|
|
27
|
+
box.position = box.position.sub(this.segment().getBBox().center);
|
|
28
|
+
return box;
|
|
29
|
+
}
|
|
30
|
+
drawOverlay(context, matrix) {
|
|
31
|
+
const size = this.computedSize();
|
|
32
|
+
const box = this.childrenBBox().transformCorners(matrix);
|
|
33
|
+
const offsetBeforeTransform = size.mul(this.offset()).scale(0.5);
|
|
34
|
+
const offset = transformVectorAsPoint(offsetBeforeTransform, matrix);
|
|
35
|
+
const overlayInfo = this.overlayInfo(matrix);
|
|
36
|
+
context.lineWidth = 1;
|
|
37
|
+
context.strokeStyle = 'white';
|
|
38
|
+
context.fillStyle = 'white';
|
|
39
|
+
// Draw the curve itself first so everything else gets drawn on top of it
|
|
40
|
+
context.stroke(overlayInfo.curve);
|
|
41
|
+
context.fillStyle = 'white';
|
|
42
|
+
context.globalAlpha = 0.5;
|
|
43
|
+
context.beginPath();
|
|
44
|
+
context.stroke(overlayInfo.handleLines);
|
|
45
|
+
context.globalAlpha = 1;
|
|
46
|
+
context.lineWidth = 2;
|
|
47
|
+
// Draw start and end points
|
|
48
|
+
for (const point of [overlayInfo.startPoint, overlayInfo.endPoint]) {
|
|
49
|
+
moveTo(context, point);
|
|
50
|
+
context.beginPath();
|
|
51
|
+
arc(context, point, 4);
|
|
52
|
+
context.closePath();
|
|
53
|
+
context.stroke();
|
|
54
|
+
context.fill();
|
|
55
|
+
}
|
|
56
|
+
// Draw the control points
|
|
57
|
+
context.fillStyle = 'black';
|
|
58
|
+
for (const point of overlayInfo.controlPoints) {
|
|
59
|
+
moveTo(context, point);
|
|
60
|
+
context.beginPath();
|
|
61
|
+
arc(context, point, 4);
|
|
62
|
+
context.closePath();
|
|
63
|
+
context.fill();
|
|
64
|
+
context.stroke();
|
|
65
|
+
}
|
|
66
|
+
// Draw the offset marker
|
|
67
|
+
context.lineWidth = 1;
|
|
68
|
+
context.beginPath();
|
|
69
|
+
drawPivot(context, offset);
|
|
70
|
+
context.stroke();
|
|
71
|
+
// Draw the bounding box
|
|
72
|
+
context.beginPath();
|
|
73
|
+
drawLine(context, box);
|
|
74
|
+
context.closePath();
|
|
75
|
+
context.stroke();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
__decorate([
|
|
79
|
+
computed()
|
|
80
|
+
], Bezier.prototype, "childrenBBox", null);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DLFNBQVMsR0FBRyxDQUFDLENBQUM7UUFDdEIsT0FBTyxDQUFDLFNBQVMsRUFBRSxDQUFDO1FBQ3BCLFNBQVMsQ0FBQyxPQUFPLEVBQUUsTUFBTSxDQUFDLENBQUM7UUFDM0IsT0FBTyxDQUFDLE1BQU0sRUFBRSxDQUFDO1FBRWpCLHdCQUF3QjtRQUN4QixPQUFPLENBQUMsU0FBUyxFQUFFLENBQUM7UUFDcEIsUUFBUSxDQUFDLE9BQU8sRUFBRSxHQUFHLENBQUMsQ0FBQztRQUN2QixPQUFPLENBQUMsU0FBUyxFQUFFLENBQUM7UUFDcEIsT0FBTyxDQUFDLE1BQU0sRUFBRSxDQUFDO0lBQ25CLENBQUM7Q0FDRjtBQXhFVztJQURULFFBQVEsRUFBRTswQ0FHViJ9
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { SerializedVector2, SignalValue, SimpleSignal } from '@twick/core';
|
|
2
|
+
import { BBox } from '@twick/core';
|
|
3
|
+
import type { CurveProfile } from '../curves';
|
|
4
|
+
import type { DesiredLength } from '../partials';
|
|
5
|
+
import type { CurveProps } from './Curve';
|
|
6
|
+
import { Curve } from './Curve';
|
|
7
|
+
export interface CircleProps extends CurveProps {
|
|
8
|
+
/**
|
|
9
|
+
* {@inheritDoc Circle.startAngle}
|
|
10
|
+
*/
|
|
11
|
+
startAngle?: SignalValue<number>;
|
|
12
|
+
/**
|
|
13
|
+
* {@inheritDoc Circle.endAngle}
|
|
14
|
+
*/
|
|
15
|
+
endAngle?: SignalValue<number>;
|
|
16
|
+
/**
|
|
17
|
+
* {@inheritDoc Circle.counterclockwise}
|
|
18
|
+
*/
|
|
19
|
+
counterclockwise?: SignalValue<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* {@inheritDoc Circle.closed}
|
|
22
|
+
*/
|
|
23
|
+
closed?: SignalValue<boolean>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A node for drawing circular shapes.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This node can be used to render shapes such as: circle, ellipse, arc, and
|
|
30
|
+
* sector (pie chart).
|
|
31
|
+
*
|
|
32
|
+
* @preview
|
|
33
|
+
* ```tsx editor
|
|
34
|
+
* // snippet Simple circle
|
|
35
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
36
|
+
*
|
|
37
|
+
* export default makeScene2D(function* (view) {
|
|
38
|
+
* view.add(
|
|
39
|
+
* <Circle
|
|
40
|
+
* size={160}
|
|
41
|
+
* fill={'lightseagreen'}
|
|
42
|
+
* />
|
|
43
|
+
* );
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // snippet Ellipse
|
|
47
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
48
|
+
*
|
|
49
|
+
* export default makeScene2D(function* (view) {
|
|
50
|
+
* view.add(
|
|
51
|
+
* <Circle
|
|
52
|
+
* width={160}
|
|
53
|
+
* height={80}
|
|
54
|
+
* fill={'lightseagreen'}
|
|
55
|
+
* />
|
|
56
|
+
* );
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // snippet Sector (pie chart):
|
|
60
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
61
|
+
* import {createRef} from '@twick/core';
|
|
62
|
+
*
|
|
63
|
+
* export default makeScene2D(function* (view) {
|
|
64
|
+
* const ref = createRef<Circle>();
|
|
65
|
+
* view.add(
|
|
66
|
+
* <Circle
|
|
67
|
+
* ref={ref}
|
|
68
|
+
* size={160}
|
|
69
|
+
* fill={'lightseagreen'}
|
|
70
|
+
* startAngle={30}
|
|
71
|
+
* endAngle={270}
|
|
72
|
+
* closed={true}
|
|
73
|
+
* />
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* yield* ref().startAngle(270, 2).to(30, 2);
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // snippet Arc:
|
|
80
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
81
|
+
* import {createRef} from '@twick/core';
|
|
82
|
+
*
|
|
83
|
+
* export default makeScene2D(function* (view) {
|
|
84
|
+
* const ref = createRef<Circle>();
|
|
85
|
+
* view.add(
|
|
86
|
+
* <Circle
|
|
87
|
+
* ref={ref}
|
|
88
|
+
* size={160}
|
|
89
|
+
* stroke={'lightseagreen'}
|
|
90
|
+
* lineWidth={8}
|
|
91
|
+
* startAngle={-90}
|
|
92
|
+
* endAngle={90}
|
|
93
|
+
* />
|
|
94
|
+
* );
|
|
95
|
+
*
|
|
96
|
+
* yield* ref().startAngle(-270, 2).to(-90, 2);
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // snippet Curve properties:
|
|
100
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
101
|
+
* import {all, createRef, easeInCubic, easeOutCubic} from '@twick/core';
|
|
102
|
+
*
|
|
103
|
+
* export default makeScene2D(function* (view) {
|
|
104
|
+
* const ref = createRef<Circle>();
|
|
105
|
+
* view.add(
|
|
106
|
+
* <Circle
|
|
107
|
+
* ref={ref}
|
|
108
|
+
* size={160}
|
|
109
|
+
* stroke={'lightseagreen'}
|
|
110
|
+
* lineWidth={8}
|
|
111
|
+
* endAngle={270}
|
|
112
|
+
* endArrow
|
|
113
|
+
* />,
|
|
114
|
+
* );
|
|
115
|
+
*
|
|
116
|
+
* yield* all(ref().start(1, 1), ref().rotation(180, 1, easeInCubic));
|
|
117
|
+
* ref().start(0).end(0);
|
|
118
|
+
* yield* all(ref().end(1, 1), ref().rotation(360, 1, easeOutCubic));
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare class Circle extends Curve {
|
|
123
|
+
/**
|
|
124
|
+
* The starting angle in degrees for the circle sector.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* This property can be used together with {@link startAngle} to turn this
|
|
128
|
+
* circle into a sector (when using fill) or an arc (when using stroke).
|
|
129
|
+
*
|
|
130
|
+
* @defaultValue 0
|
|
131
|
+
*/
|
|
132
|
+
readonly startAngle: SimpleSignal<number, this>;
|
|
133
|
+
/**
|
|
134
|
+
* The ending angle in degrees for the circle sector.
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* This property can be used together with {@link endAngle} to turn this
|
|
138
|
+
* circle into a sector (when using fill) or an arc (when using stroke).
|
|
139
|
+
*
|
|
140
|
+
* @defaultValue 360
|
|
141
|
+
*/
|
|
142
|
+
readonly endAngle: SimpleSignal<number, this>;
|
|
143
|
+
/**
|
|
144
|
+
* Whether the circle sector should be drawn counterclockwise.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* By default, the circle begins at {@link startAngle} and is drawn clockwise
|
|
148
|
+
* until reaching {@link endAngle}. Setting this property to true will reverse
|
|
149
|
+
* this direction.
|
|
150
|
+
*/
|
|
151
|
+
readonly counterclockwise: SimpleSignal<boolean, this>;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the path of this circle should be closed.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* When set to true, the path of this circle will start and end at the center.
|
|
157
|
+
* This can be used to fine-tune how sectors are rendered.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* A closed circle will look like a pie chart:
|
|
161
|
+
* ```tsx
|
|
162
|
+
* <Circle
|
|
163
|
+
* size={300}
|
|
164
|
+
* fill={'lightseagreen'}
|
|
165
|
+
* endAngle={230}
|
|
166
|
+
* closed={true}
|
|
167
|
+
* />
|
|
168
|
+
* ```
|
|
169
|
+
* An open one will look like an arc:
|
|
170
|
+
* ```tsx
|
|
171
|
+
* <Circle
|
|
172
|
+
* size={300}
|
|
173
|
+
* stroke={'lightseagreen'}
|
|
174
|
+
* lineWidth={8}
|
|
175
|
+
* endAngle={230}
|
|
176
|
+
* closed={false}
|
|
177
|
+
* />
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @defaultValue false
|
|
181
|
+
*/
|
|
182
|
+
readonly closed: SimpleSignal<boolean, this>;
|
|
183
|
+
constructor(props: CircleProps);
|
|
184
|
+
profile(): CurveProfile;
|
|
185
|
+
protected desiredSize(): SerializedVector2<DesiredLength>;
|
|
186
|
+
protected offsetComputedLayout(box: BBox): BBox;
|
|
187
|
+
protected childrenBBox(): BBox;
|
|
188
|
+
protected getPath(): Path2D;
|
|
189
|
+
protected getRipplePath(): Path2D;
|
|
190
|
+
protected getCacheBBox(): BBox;
|
|
191
|
+
protected createPath(expand?: number): Path2D;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=Circle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Circle.d.ts","sourceRoot":"","sources":["../../src/lib/components/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAC,IAAI,EAAU,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAG5C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACxC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC7C;;OAEG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC;;OAEG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B;;OAEG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACxC;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AACH,qBACa,MAAO,SAAQ,KAAK;IAC/B;;;;;;;;OAQG;IACH,SAEwB,UAAU,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/D;;;;;;;;OAQG;IACH,SAEwB,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE7D;;;;;;;OAOG;IACH,SAEwB,gBAAgB,EAAE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,SAAwB,MAAM,EAAE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;gBAEzC,KAAK,EAAE,WAAW;IAK9B,OAAO,IAAI,YAAY;cAUX,WAAW,IAAI,iBAAiB,CAAC,aAAa,CAAC;cAO/C,oBAAoB,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI;cAIrC,YAAY,IAAI,IAAI;cAIpB,OAAO,IAAI,MAAM;cAQjB,aAAa,IAAI,MAAM;cAIvB,YAAY,IAAI,IAAI;IAIvC,SAAS,CAAC,UAAU,CAAC,MAAM,SAAI;CAsBhC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BBox, DEG2RAD } from '@twick/core';
|
|
8
|
+
import { getCircleProfile } from '../curves';
|
|
9
|
+
import { computed, initial, nodeName, signal } from '../decorators';
|
|
10
|
+
import { Curve } from './Curve';
|
|
11
|
+
/**
|
|
12
|
+
* A node for drawing circular shapes.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This node can be used to render shapes such as: circle, ellipse, arc, and
|
|
16
|
+
* sector (pie chart).
|
|
17
|
+
*
|
|
18
|
+
* @preview
|
|
19
|
+
* ```tsx editor
|
|
20
|
+
* // snippet Simple circle
|
|
21
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
22
|
+
*
|
|
23
|
+
* export default makeScene2D(function* (view) {
|
|
24
|
+
* view.add(
|
|
25
|
+
* <Circle
|
|
26
|
+
* size={160}
|
|
27
|
+
* fill={'lightseagreen'}
|
|
28
|
+
* />
|
|
29
|
+
* );
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // snippet Ellipse
|
|
33
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
34
|
+
*
|
|
35
|
+
* export default makeScene2D(function* (view) {
|
|
36
|
+
* view.add(
|
|
37
|
+
* <Circle
|
|
38
|
+
* width={160}
|
|
39
|
+
* height={80}
|
|
40
|
+
* fill={'lightseagreen'}
|
|
41
|
+
* />
|
|
42
|
+
* );
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // snippet Sector (pie chart):
|
|
46
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
47
|
+
* import {createRef} from '@twick/core';
|
|
48
|
+
*
|
|
49
|
+
* export default makeScene2D(function* (view) {
|
|
50
|
+
* const ref = createRef<Circle>();
|
|
51
|
+
* view.add(
|
|
52
|
+
* <Circle
|
|
53
|
+
* ref={ref}
|
|
54
|
+
* size={160}
|
|
55
|
+
* fill={'lightseagreen'}
|
|
56
|
+
* startAngle={30}
|
|
57
|
+
* endAngle={270}
|
|
58
|
+
* closed={true}
|
|
59
|
+
* />
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* yield* ref().startAngle(270, 2).to(30, 2);
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // snippet Arc:
|
|
66
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
67
|
+
* import {createRef} from '@twick/core';
|
|
68
|
+
*
|
|
69
|
+
* export default makeScene2D(function* (view) {
|
|
70
|
+
* const ref = createRef<Circle>();
|
|
71
|
+
* view.add(
|
|
72
|
+
* <Circle
|
|
73
|
+
* ref={ref}
|
|
74
|
+
* size={160}
|
|
75
|
+
* stroke={'lightseagreen'}
|
|
76
|
+
* lineWidth={8}
|
|
77
|
+
* startAngle={-90}
|
|
78
|
+
* endAngle={90}
|
|
79
|
+
* />
|
|
80
|
+
* );
|
|
81
|
+
*
|
|
82
|
+
* yield* ref().startAngle(-270, 2).to(-90, 2);
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // snippet Curve properties:
|
|
86
|
+
* import {makeScene2D, Circle} from '@twick/2d';
|
|
87
|
+
* import {all, createRef, easeInCubic, easeOutCubic} from '@twick/core';
|
|
88
|
+
*
|
|
89
|
+
* export default makeScene2D(function* (view) {
|
|
90
|
+
* const ref = createRef<Circle>();
|
|
91
|
+
* view.add(
|
|
92
|
+
* <Circle
|
|
93
|
+
* ref={ref}
|
|
94
|
+
* size={160}
|
|
95
|
+
* stroke={'lightseagreen'}
|
|
96
|
+
* lineWidth={8}
|
|
97
|
+
* endAngle={270}
|
|
98
|
+
* endArrow
|
|
99
|
+
* />,
|
|
100
|
+
* );
|
|
101
|
+
*
|
|
102
|
+
* yield* all(ref().start(1, 1), ref().rotation(180, 1, easeInCubic));
|
|
103
|
+
* ref().start(0).end(0);
|
|
104
|
+
* yield* all(ref().end(1, 1), ref().rotation(360, 1, easeOutCubic));
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
let Circle = class Circle extends Curve {
|
|
109
|
+
constructor(props) {
|
|
110
|
+
super(props);
|
|
111
|
+
}
|
|
112
|
+
profile() {
|
|
113
|
+
return getCircleProfile(this.size().scale(0.5), this.startAngle() * DEG2RAD, this.endAngle() * DEG2RAD, this.closed(), this.counterclockwise());
|
|
114
|
+
}
|
|
115
|
+
desiredSize() {
|
|
116
|
+
return {
|
|
117
|
+
x: this.width.context.getter(),
|
|
118
|
+
y: this.height.context.getter(),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
offsetComputedLayout(box) {
|
|
122
|
+
return box;
|
|
123
|
+
}
|
|
124
|
+
childrenBBox() {
|
|
125
|
+
return BBox.fromSizeCentered(this.computedSize());
|
|
126
|
+
}
|
|
127
|
+
getPath() {
|
|
128
|
+
if (this.requiresProfile()) {
|
|
129
|
+
return this.curveDrawingInfo().path;
|
|
130
|
+
}
|
|
131
|
+
return this.createPath();
|
|
132
|
+
}
|
|
133
|
+
getRipplePath() {
|
|
134
|
+
return this.createPath(this.rippleSize());
|
|
135
|
+
}
|
|
136
|
+
getCacheBBox() {
|
|
137
|
+
return super.getCacheBBox().expand(this.rippleSize());
|
|
138
|
+
}
|
|
139
|
+
createPath(expand = 0) {
|
|
140
|
+
const path = new Path2D();
|
|
141
|
+
const start = this.startAngle() * DEG2RAD;
|
|
142
|
+
let end = this.endAngle() * DEG2RAD;
|
|
143
|
+
const size = this.size().scale(0.5).add(expand);
|
|
144
|
+
const closed = this.closed();
|
|
145
|
+
if (end > start + Math.PI * 2) {
|
|
146
|
+
const loops = Math.floor((end - start) / (Math.PI * 2));
|
|
147
|
+
end -= Math.PI * 2 * loops;
|
|
148
|
+
}
|
|
149
|
+
if (closed) {
|
|
150
|
+
path.moveTo(0, 0);
|
|
151
|
+
}
|
|
152
|
+
path.ellipse(0, 0, size.x, size.y, 0, start, end, this.counterclockwise());
|
|
153
|
+
if (closed) {
|
|
154
|
+
path.closePath();
|
|
155
|
+
}
|
|
156
|
+
return path;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
__decorate([
|
|
160
|
+
initial(0),
|
|
161
|
+
signal()
|
|
162
|
+
], Circle.prototype, "startAngle", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
initial(360),
|
|
165
|
+
signal()
|
|
166
|
+
], Circle.prototype, "endAngle", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
initial(false),
|
|
169
|
+
signal()
|
|
170
|
+
], Circle.prototype, "counterclockwise", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
computed()
|
|
173
|
+
], Circle.prototype, "profile", null);
|
|
174
|
+
Circle = __decorate([
|
|
175
|
+
nodeName('Circle')
|
|
176
|
+
], Circle);
|
|
177
|
+
export { Circle };
|
|
178
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2lyY2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2xpYi9jb21wb25lbnRzL0NpcmNsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFDQSxPQUFPLEVBQUMsSUFBSSxFQUFFLE9BQU8sRUFBQyxNQUFNLGFBQWEsQ0FBQztBQUUxQyxPQUFPLEVBQUMsZ0JBQWdCLEVBQUMsTUFBTSxXQUFXLENBQUM7QUFDM0MsT0FBTyxFQUFDLFFBQVEsRUFBRSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUdsRSxPQUFPLEVBQUMsS0FBSyxFQUFDLE1BQU0sU0FBUyxDQUFDO0FBcUI5Qjs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBZ0dHO0FBRUksSUFBTSxNQUFNLEdBQVosTUFBTSxNQUFPLFNBQVEsS0FBSztJQXVFL0IsWUFBbUIsS0FBa0I7UUFDbkMsS0FBSyx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sQ0FBQyxFQUFFLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQyxFQUFFLElBQUksQ0FBQyxDQUFDLEVBQUUsQ0FBQyxFQUFFLEtBQUssRUFBRSxHQUFHLEVBQUUsSUFBSSxDQUFDLGdCQUFnQixFQUFFLENBQUMsQ0FBQztRQUMzRSxJQUFJLE1BQU0sRUFBRSxDQUFDO1lBQ1gsSUFBSSxDQUFDLFNBQVMsRUFBRSxDQUFDO1FBQ25CLENBQUM7UUFFRCxPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7Q0FDRixDQUFBO0FBL0h5QjtJQUZ2QixPQUFPLENBQUMsQ0FBQyxDQUFDO0lBQ1YsTUFBTSxFQUFFOzBDQUNzRDtBQWF2QztJQUZ2QixPQUFPLENBQUMsR0FBRyxDQUFDO0lBQ1osTUFBTSxFQUFFO3dDQUNvRDtBQVlyQztJQUZ2QixPQUFPLENBQUMsS0FBSyxDQUFDO0lBQ2QsTUFBTSxFQUFFO2dEQUM2RDtBQXVDL0Q7SUFETixRQUFRLEVBQUU7cUNBU1Y7QUFwRlUsTUFBTTtJQURsQixRQUFRLENBQUMsUUFBUSxDQUFDO0dBQ04sTUFBTSxDQTJJbEIifQ==
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { SerializedVector2, Signal, SignalValue, SimpleSignal, ThreadGenerator, TimingFunction, Vector2 } from '@twick/core';
|
|
2
|
+
import { BBox } from '@twick/core';
|
|
3
|
+
import type { CodeFragmentDrawingInfo, CodeHighlighter, CodePoint, CodeRange, CodeSelection, CodeSignal, PossibleCodeScope, PossibleCodeSelection } from '../code';
|
|
4
|
+
import type { DesiredLength } from '../partials';
|
|
5
|
+
import type { ShapeProps } from './Shape';
|
|
6
|
+
import { Shape } from './Shape';
|
|
7
|
+
export interface DrawTokenHook {
|
|
8
|
+
(ctx: CanvasRenderingContext2D, text: string, position: Vector2, color: string, selection: number): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Describes custom drawing logic used by the Code node.
|
|
12
|
+
*/
|
|
13
|
+
export interface DrawHooks {
|
|
14
|
+
/**
|
|
15
|
+
* Custom drawing logic for individual code tokens.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* token(ctx, text, position, color, selection) {
|
|
20
|
+
* const blur = map(3, 0, selection);
|
|
21
|
+
* const alpha = map(0.5, 1, selection);
|
|
22
|
+
* ctx.globalAlpha *= alpha;
|
|
23
|
+
* ctx.filter = `blur(${blur}px)`;
|
|
24
|
+
* ctx.fillStyle = color;
|
|
25
|
+
* ctx.fillText(text, position.x, position.y);
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
token: DrawTokenHook;
|
|
30
|
+
}
|
|
31
|
+
export interface CodeProps extends ShapeProps {
|
|
32
|
+
/**
|
|
33
|
+
* {@inheritDoc Code.highlighter}
|
|
34
|
+
*/
|
|
35
|
+
highlighter?: SignalValue<CodeHighlighter | null>;
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc Code.code}
|
|
38
|
+
*/
|
|
39
|
+
code?: SignalValue<PossibleCodeScope>;
|
|
40
|
+
/**
|
|
41
|
+
* {@inheritDoc Code.selection}
|
|
42
|
+
*/
|
|
43
|
+
selection?: SignalValue<PossibleCodeSelection>;
|
|
44
|
+
/**
|
|
45
|
+
* {@inheritDoc Code.drawHooks}
|
|
46
|
+
*/
|
|
47
|
+
drawHooks?: SignalValue<DrawHooks>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A node for displaying and animating code.
|
|
51
|
+
*
|
|
52
|
+
* @experimental
|
|
53
|
+
*
|
|
54
|
+
* @preview
|
|
55
|
+
* ```tsx editor
|
|
56
|
+
* import {parser} from '@lezer/javascript';
|
|
57
|
+
* import {Code, LezerHighlighter, makeScene2D} from '@twick/2d';
|
|
58
|
+
* import {createRef} from '@twick/core';
|
|
59
|
+
*
|
|
60
|
+
* export default makeScene2D(function* (view) {
|
|
61
|
+
* LezerHighlighter.registerParser(parser);
|
|
62
|
+
* const code = createRef<Code>();
|
|
63
|
+
*
|
|
64
|
+
* view.add(
|
|
65
|
+
* <Code
|
|
66
|
+
* ref={code}
|
|
67
|
+
* offset={-1}
|
|
68
|
+
* position={view.size().scale(-0.5).add(60)}
|
|
69
|
+
* fontFamily={'JetBrains Mono, monospace'}
|
|
70
|
+
* fontSize={36}
|
|
71
|
+
* code={`\
|
|
72
|
+
* function hello() {
|
|
73
|
+
* console.log('Hello');
|
|
74
|
+
* }`}
|
|
75
|
+
* />,
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* yield* code()
|
|
79
|
+
* .code(
|
|
80
|
+
* `\
|
|
81
|
+
* function hello() {
|
|
82
|
+
* console.warn('Hello World');
|
|
83
|
+
* }`,
|
|
84
|
+
* 1,
|
|
85
|
+
* )
|
|
86
|
+
* .wait(0.5)
|
|
87
|
+
* .back(1)
|
|
88
|
+
* .wait(0.5);
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare class Code extends Shape {
|
|
93
|
+
/**
|
|
94
|
+
* Create a standalone code signal.
|
|
95
|
+
*
|
|
96
|
+
* @param initial - The initial code.
|
|
97
|
+
* @param highlighter - Custom highlighter to use.
|
|
98
|
+
*/
|
|
99
|
+
static createSignal(initial: PossibleCodeScope, highlighter?: SignalValue<CodeHighlighter>): CodeSignal<void>;
|
|
100
|
+
static defaultHighlighter: CodeHighlighter | null;
|
|
101
|
+
/**
|
|
102
|
+
* The code highlighter to use for this code node.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* Defaults to a shared {@link code.LezerHighlighter}.
|
|
106
|
+
*/
|
|
107
|
+
readonly highlighter: SimpleSignal<CodeHighlighter | null, this>;
|
|
108
|
+
/**
|
|
109
|
+
* The code to display.
|
|
110
|
+
*/
|
|
111
|
+
readonly code: CodeSignal<this>;
|
|
112
|
+
/**
|
|
113
|
+
* Custom drawing logic for the code.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* Check out {@link DrawHooks} for available render hooks.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* Make the unselected code blurry and transparent:
|
|
120
|
+
* ```tsx
|
|
121
|
+
* <Code
|
|
122
|
+
* drawHooks={{
|
|
123
|
+
* token(ctx, text, position, color, selection) {
|
|
124
|
+
* const blur = map(3, 0, selection);
|
|
125
|
+
* const alpha = map(0.5, 1, selection);
|
|
126
|
+
* ctx.globalAlpha *= alpha;
|
|
127
|
+
* ctx.filter = `blur(${blur}px)`;
|
|
128
|
+
* ctx.fillStyle = color;
|
|
129
|
+
* ctx.fillText(text, position.x, position.y);
|
|
130
|
+
* },
|
|
131
|
+
* }}
|
|
132
|
+
* // ...
|
|
133
|
+
* />
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
readonly drawHooks: SimpleSignal<DrawHooks, this>;
|
|
137
|
+
protected setDrawHooks(value: DrawHooks): void;
|
|
138
|
+
/**
|
|
139
|
+
* The currently selected code range.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* Either a single {@link code.CodeRange} or an array of them
|
|
143
|
+
* describing which parts of the code should be visually emphasized.
|
|
144
|
+
*
|
|
145
|
+
* You can use {@link code.word} and
|
|
146
|
+
* {@link code.lines} to quickly create ranges.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* The following will select the word "console" in the code.
|
|
150
|
+
* Both lines and columns are 0-based. So it will select a 7-character-long
|
|
151
|
+
* (`7`) word in the second line (`1`) starting at the third character (`2`).
|
|
152
|
+
* ```tsx
|
|
153
|
+
* <Code
|
|
154
|
+
* selection={word(1, 2, 7)}
|
|
155
|
+
* code={`\
|
|
156
|
+
* function hello() => {
|
|
157
|
+
* console.log('Hello');
|
|
158
|
+
* }`}
|
|
159
|
+
* // ...
|
|
160
|
+
* />
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
readonly selection: Signal<PossibleCodeSelection, CodeSelection, this>;
|
|
164
|
+
oldSelection: CodeSelection | null;
|
|
165
|
+
selectionProgress: SimpleSignal<number | null, void>;
|
|
166
|
+
protected tweenSelection(value: CodeRange[], duration: number, timingFunction: TimingFunction): ThreadGenerator;
|
|
167
|
+
/**
|
|
168
|
+
* Get the currently displayed code as a string.
|
|
169
|
+
*/
|
|
170
|
+
parsed(): string;
|
|
171
|
+
highlighterCache(): {
|
|
172
|
+
before: unknown;
|
|
173
|
+
after: unknown;
|
|
174
|
+
} | null;
|
|
175
|
+
private cursorCache;
|
|
176
|
+
private get cursor();
|
|
177
|
+
constructor(props: CodeProps);
|
|
178
|
+
/**
|
|
179
|
+
* Create a child code signal.
|
|
180
|
+
*
|
|
181
|
+
* @param initial - The initial code.
|
|
182
|
+
*/
|
|
183
|
+
createSignal(initial: PossibleCodeScope): CodeSignal<this>;
|
|
184
|
+
/**
|
|
185
|
+
* Find all code ranges that match the given pattern.
|
|
186
|
+
*
|
|
187
|
+
* @param pattern - Either a string or a regular expression to match.
|
|
188
|
+
*/
|
|
189
|
+
findAllRanges(pattern: string | RegExp): CodeRange[];
|
|
190
|
+
/**
|
|
191
|
+
* Find the first code range that matches the given pattern.
|
|
192
|
+
*
|
|
193
|
+
* @param pattern - Either a string or a regular expression to match.
|
|
194
|
+
*/
|
|
195
|
+
findFirstRange(pattern: string | RegExp): CodeRange;
|
|
196
|
+
/**
|
|
197
|
+
* Find the last code range that matches the given pattern.
|
|
198
|
+
*
|
|
199
|
+
* @param pattern - Either a string or a regular expression to match.
|
|
200
|
+
*/
|
|
201
|
+
findLastRange(pattern: string | RegExp): CodeRange;
|
|
202
|
+
/**
|
|
203
|
+
* Return the bounding box of the given point (character) in the code.
|
|
204
|
+
*
|
|
205
|
+
* @remarks
|
|
206
|
+
* The returned bound box is in local space of the `Code` node.
|
|
207
|
+
*
|
|
208
|
+
* @param point - The point to get the bounding box for.
|
|
209
|
+
*/
|
|
210
|
+
getPointBbox(point: CodePoint): BBox;
|
|
211
|
+
/**
|
|
212
|
+
* Return bounding boxes of all characters in the selection.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* The returned bound boxes are in local space of the `Code` node.
|
|
216
|
+
* Each line of code has a separate bounding box.
|
|
217
|
+
*
|
|
218
|
+
* @param selection - The selection to get the bounding boxes for.
|
|
219
|
+
*/
|
|
220
|
+
getSelectionBbox(selection: PossibleCodeSelection): BBox[];
|
|
221
|
+
protected drawingInfo(): {
|
|
222
|
+
fragments: CodeFragmentDrawingInfo[];
|
|
223
|
+
verticalOffset: number;
|
|
224
|
+
fontHeight: number;
|
|
225
|
+
};
|
|
226
|
+
protected desiredSize(): SerializedVector2<DesiredLength>;
|
|
227
|
+
protected draw(context: CanvasRenderingContext2D): Promise<void>;
|
|
228
|
+
protected applyText(context: CanvasRenderingContext2D): void;
|
|
229
|
+
protected collectAsyncResources(): void;
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=Code.d.ts.map
|