@weasel-js/core 1.9.2 → 1.9.4
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/CHANGELOG.md +393 -0
- package/README.md +2 -2
- package/dist/WeaselProvider.js +5 -5
- package/dist/affordances/composeAffordanceLayer.js +10 -20
- package/dist/affordances/composeAffordanceLayer.js.map +1 -1
- package/dist/affordances/cornerResize.js +25 -17
- package/dist/affordances/cornerResize.js.map +1 -1
- package/dist/affordances/hitAffordanceRegions.js +27 -20
- package/dist/affordances/hitAffordanceRegions.js.map +1 -1
- package/dist/affordances/rotationHandle.js +18 -18
- package/dist/affordances/rotationHandle.js.map +1 -1
- package/dist/animation/behaviors/momentum.js +93 -55
- package/dist/animation/behaviors/momentum.js.map +1 -1
- package/dist/animation/loop.js +10 -12
- package/dist/animation/loop.js.map +1 -1
- package/dist/animation/reflow.js +8 -8
- package/dist/animation/reflow.js.map +1 -1
- package/dist/animation/stagger.js +64 -56
- package/dist/animation/stagger.js.map +1 -1
- package/dist/animation/timeline/booking.js +62 -54
- package/dist/animation/timeline/booking.js.map +1 -1
- package/dist/animation/timeline/createTimeline.js +85 -76
- package/dist/animation/timeline/createTimeline.js.map +1 -1
- package/dist/animation/timeline/sampleTrack.js +13 -5
- package/dist/animation/timeline/sampleTrack.js.map +1 -1
- package/dist/animation/useAnimator.js +45 -35
- package/dist/animation/useAnimator.js.map +1 -1
- package/dist/animation/wrappers/animateLifecycle.js +31 -24
- package/dist/animation/wrappers/animateLifecycle.js.map +1 -1
- package/dist/animation/wrappers/animateOnSetPose.js +28 -26
- package/dist/animation/wrappers/animateOnSetPose.js.map +1 -1
- package/dist/animation/wrappers/instantPose.js +13 -0
- package/dist/animation/wrappers/instantPose.js.map +1 -0
- package/dist/{poseDescriptor-D-OH-tu5.d.ts → autoPoseDescriptor-Ct7yqivU.d.ts} +28 -3
- package/dist/barrel/chrome.js +16 -0
- package/dist/barrel/input.js +19 -0
- package/dist/barrel/interactions.js +42 -0
- package/dist/barrel/paint.js +18 -0
- package/dist/barrel/paths.js +19 -0
- package/dist/barrel/renderer.js +20 -0
- package/dist/barrel/routing.js +51 -0
- package/dist/barrel/text.js +18 -0
- package/dist/barrel/viewport.js +52 -0
- package/dist/builtins-DPcdghtB.d.ts +1223 -0
- package/dist/canvas/Canvas.js +363 -448
- package/dist/canvas/Canvas.js.map +1 -1
- package/dist/canvas/CanvasView.js +164 -165
- package/dist/canvas/CanvasView.js.map +1 -1
- package/dist/canvas/CursorCoordsHud.js +37 -32
- package/dist/canvas/CursorCoordsHud.js.map +1 -1
- package/dist/canvas/DrawCanvas.js +49 -43
- package/dist/canvas/DrawCanvas.js.map +1 -1
- package/dist/canvas/MinimapCanvas.js +26 -25
- package/dist/canvas/MinimapCanvas.js.map +1 -1
- package/dist/canvas/NodeShape.js +59 -377
- package/dist/canvas/NodeShape.js.map +1 -1
- package/dist/canvas/PickHud.js +50 -47
- package/dist/canvas/PickHud.js.map +1 -1
- package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js +167 -0
- package/dist/canvas/SceneCanvas/GestureDispatcherMounter.js.map +1 -0
- package/dist/canvas/SceneCanvas/PointerProviderIfRoot.js +13 -13
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js +67 -0
- package/dist/canvas/SceneCanvas/StandardActionsRegistrar.js.map +1 -0
- package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js +16 -0
- package/dist/canvas/SceneCanvas/ToolKeybindingsMounter.js.map +1 -0
- package/dist/canvas/SceneCanvas/coordTrace.js +10 -0
- package/dist/canvas/SceneCanvas/coordTrace.js.map +1 -0
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js +146 -92
- package/dist/canvas/SceneCanvas/defaultNodeProperties.js.map +1 -1
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js +9 -8
- package/dist/canvas/SceneCanvas/defaultNodeRouting.js.map +1 -1
- package/dist/canvas/SceneCanvas/features.js +1 -0
- package/dist/canvas/SceneCanvas/features.js.map +1 -1
- package/dist/canvas/SceneCanvas/isDev.js +12 -0
- package/dist/canvas/SceneCanvas/isDev.js.map +1 -0
- package/dist/canvas/SceneCanvas/poseGeometry.js +29 -28
- package/dist/canvas/SceneCanvas/poseGeometry.js.map +1 -1
- package/dist/canvas/SceneCanvas/poseRegistrars.js +13 -0
- package/dist/canvas/SceneCanvas/poseRegistrars.js.map +1 -0
- package/dist/canvas/SceneCanvas/props.js +38 -0
- package/dist/canvas/SceneCanvas/props.js.map +1 -0
- package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js +21 -62
- package/dist/canvas/SceneCanvas/useBuiltinShapeTools.js.map +1 -1
- package/dist/canvas/SceneCanvas/useDispatcherOverlayLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js +46 -48
- package/dist/canvas/SceneCanvas/usePreviewGhostLayer.js.map +1 -1
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js +33 -33
- package/dist/canvas/SceneCanvas/useSceneSelectTool.js.map +1 -1
- package/dist/canvas/SceneCanvas.js +534 -788
- package/dist/canvas/SceneCanvas.js.map +1 -1
- package/dist/canvas/SceneViewCanvas.js +45 -43
- package/dist/canvas/SceneViewCanvas.js.map +1 -1
- package/dist/canvas/buildSceneLayer.js +91 -0
- package/dist/canvas/buildSceneLayer.js.map +1 -0
- package/dist/canvas/buildSceneTree.js +16 -19
- package/dist/canvas/buildSceneTree.js.map +1 -1
- package/dist/canvas/canvasRenderer.js +68 -52
- package/dist/canvas/canvasRenderer.js.map +1 -1
- package/dist/canvas/deps/changes.js +13 -0
- package/dist/canvas/deps/changes.js.map +1 -0
- package/dist/canvas/deps/editAnchors.js +28 -28
- package/dist/canvas/deps/insert.js +119 -91
- package/dist/canvas/deps/insert.js.map +1 -1
- package/dist/canvas/deps/slice.js +46 -45
- package/dist/canvas/deps/slice.js.map +1 -1
- package/dist/canvas/deps/textEdit.js +10 -9
- package/dist/canvas/deps/textEdit.js.map +1 -1
- package/dist/canvas/derivedPath.js +46 -23
- package/dist/canvas/derivedPath.js.map +1 -1
- package/dist/canvas/getNodeAtPoint.js +7 -7
- package/dist/canvas/getNodeAtPoint.js.map +1 -1
- package/dist/canvas/hud.module.js +1 -1
- package/dist/canvas/hud.module.js.map +1 -1
- package/dist/canvas/kitRequirements.js +2 -2
- package/dist/canvas/kitRequirements.js.map +1 -1
- package/dist/canvas/layerOrder.js +13 -6
- package/dist/canvas/layerOrder.js.map +1 -1
- package/dist/canvas/minimapMath.js +12 -10
- package/dist/canvas/minimapMath.js.map +1 -1
- package/dist/canvas/nodeShapes/derivedPainter.js +34 -0
- package/dist/canvas/nodeShapes/derivedPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/imagePainter.js +87 -0
- package/dist/canvas/nodeShapes/imagePainter.js.map +1 -0
- package/dist/canvas/nodeShapes/memo.js +9 -0
- package/dist/canvas/nodeShapes/memo.js.map +1 -0
- package/dist/canvas/nodeShapes/nodePaint.js +57 -0
- package/dist/canvas/nodeShapes/nodePaint.js.map +1 -0
- package/dist/canvas/nodeShapes/pathPainter.js +38 -0
- package/dist/canvas/nodeShapes/pathPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/poseBox.js +20 -0
- package/dist/canvas/nodeShapes/poseBox.js.map +1 -0
- package/dist/canvas/nodeShapes/rectFallbackPainter.js +38 -0
- package/dist/canvas/nodeShapes/rectFallbackPainter.js.map +1 -0
- package/dist/canvas/nodeShapes/shapePainter.js +72 -0
- package/dist/canvas/nodeShapes/shapePainter.js.map +1 -0
- package/dist/canvas/nodeShapes/textPainter.js +55 -0
- package/dist/canvas/nodeShapes/textPainter.js.map +1 -0
- package/dist/canvas/overlayRoleStrokes.js.map +1 -1
- package/dist/canvas/paintCull.js +10 -11
- package/dist/canvas/paintCull.js.map +1 -1
- package/dist/canvas/pickWalk.js +52 -63
- package/dist/canvas/pickWalk.js.map +1 -1
- package/dist/canvas/poseRotation.js +11 -23
- package/dist/canvas/poseRotation.js.map +1 -1
- package/dist/canvas/renderDebugSnapshot.js +5 -5
- package/dist/canvas/renderSceneToPixels.js +3 -1
- package/dist/canvas/renderSceneToPixels.js.map +1 -1
- package/dist/canvas/sceneAdapter.js +66 -148
- package/dist/canvas/sceneAdapter.js.map +1 -1
- package/dist/canvas/sceneClipboard.js +112 -0
- package/dist/canvas/sceneClipboard.js.map +1 -0
- package/dist/canvas/sceneSlotWiring.js +4 -4
- package/dist/canvas/sceneSlotWiring.js.map +1 -1
- package/dist/canvas/sceneViewRender.js +39 -40
- package/dist/canvas/sceneViewRender.js.map +1 -1
- package/dist/canvas/useCanvasRenderer.js +14 -6
- package/dist/canvas/useCanvasRenderer.js.map +1 -1
- package/dist/canvas/useCanvasView.js +58 -0
- package/dist/canvas/useCanvasView.js.map +1 -0
- package/dist/canvas/useFrameLoop.js +35 -26
- package/dist/canvas/useFrameLoop.js.map +1 -1
- package/dist/canvas/useSceneLayerList.js +21 -0
- package/dist/canvas/useSceneLayerList.js.map +1 -0
- package/dist/clipboard.d.ts +10 -6
- package/dist/clone.d.ts +4 -3
- package/dist/core/adapters/arrayAdapter.js +48 -39
- package/dist/core/adapters/arrayAdapter.js.map +1 -1
- package/dist/core/device/index.js +5 -4
- package/dist/core/device/useDeviceProfile.js +38 -44
- package/dist/core/device/useDeviceProfile.js.map +1 -1
- package/dist/core/device/watchDevicePixelRatio.js +17 -0
- package/dist/core/device/watchDevicePixelRatio.js.map +1 -0
- package/dist/core/fillInPoseFrame.js.map +1 -1
- package/dist/core/geometry/poseDescriptor.js +21 -19
- package/dist/core/geometry/poseDescriptor.js.map +1 -1
- package/dist/core/geometry/poseFrame.js +44 -0
- package/dist/core/geometry/poseFrame.js.map +1 -0
- package/dist/core/geometry/poseRotation.js.map +1 -1
- package/dist/core/geometry/regionHit.js +9 -10
- package/dist/core/geometry/regionHit.js.map +1 -1
- package/dist/core/geometry/unionBounds.js +31 -29
- package/dist/core/geometry/unionBounds.js.map +1 -1
- package/dist/core/isPlainObject.js +2 -11
- package/dist/core/ops/arrange.js +1 -0
- package/dist/core/ops/arrange.js.map +1 -1
- package/dist/core/ops/create.js +10 -5
- package/dist/core/ops/create.js.map +1 -1
- package/dist/core/ops/delete.js +12 -24
- package/dist/core/ops/delete.js.map +1 -1
- package/dist/core/ops/reorder/index.js +43 -40
- package/dist/core/ops/reorder/index.js.map +1 -1
- package/dist/core/ops/reorder/setChildOrder.js +34 -0
- package/dist/core/ops/reorder/setChildOrder.js.map +1 -0
- package/dist/core/paintKinds.js +5 -5
- package/dist/core/paintKinds.js.map +1 -1
- package/dist/core/scene/NodeProperties.js.map +1 -1
- package/dist/core/scene/appliedLog.js +37 -0
- package/dist/core/scene/appliedLog.js.map +1 -0
- package/dist/core/scene/arrivalWindow.js +101 -0
- package/dist/core/scene/arrivalWindow.js.map +1 -0
- package/dist/core/scene/derivedPath.js.map +1 -1
- package/dist/core/scene/historyFacade.js +84 -0
- package/dist/core/scene/historyFacade.js.map +1 -0
- package/dist/core/scene/kitOps.js +173 -0
- package/dist/core/scene/kitOps.js.map +1 -0
- package/dist/core/scene/layerStack.js +38 -0
- package/dist/core/scene/layerStack.js.map +1 -0
- package/dist/core/scene/lockGuard.js +37 -0
- package/dist/core/scene/lockGuard.js.map +1 -0
- package/dist/core/scene/nodeFnFields.js +5 -6
- package/dist/core/scene/nodeFnFields.js.map +1 -1
- package/dist/core/scene/nodeMemo.js +45 -19
- package/dist/core/scene/nodeMemo.js.map +1 -1
- package/dist/core/scene/nodeStore.js +126 -0
- package/dist/core/scene/nodeStore.js.map +1 -0
- package/dist/core/scene/pickability.js +6 -0
- package/dist/core/scene/pickability.js.map +1 -0
- package/dist/core/scene/poseFeed.js +38 -38
- package/dist/core/scene/poseFeed.js.map +1 -1
- package/dist/core/scene/poseOverrides.js +34 -38
- package/dist/core/scene/poseOverrides.js.map +1 -1
- package/dist/core/scene/renderOrder.js +84 -0
- package/dist/core/scene/renderOrder.js.map +1 -0
- package/dist/core/scene/scene.js +289 -866
- package/dist/core/scene/scene.js.map +1 -1
- package/dist/core/scene/serialization.js +68 -0
- package/dist/core/scene/serialization.js.map +1 -0
- package/dist/core/scene/treeOrder.js +13 -0
- package/dist/core/scene/treeOrder.js.map +1 -0
- package/dist/core/scene/types.js.map +1 -1
- package/dist/core/viewport/meanScale.js +1 -1
- package/dist/core/viewport/meanScale.js.map +1 -1
- package/dist/core/viewport/view.js +12 -12
- package/dist/core/viewport/view.js.map +1 -1
- package/dist/core/viewport/zoomBounds.js +10 -8
- package/dist/core/viewport/zoomBounds.js.map +1 -1
- package/dist/{cornerHandles-BCrDp_mH.d.ts → cornerHandles-CtCb8a3G.d.ts} +1 -1
- package/dist/debug/createDebugOverlayLayer.js +14 -14
- package/dist/debug/createDebugOverlayLayer.js.map +1 -1
- package/dist/debug/flag.js +2 -41
- package/dist/features/chrome-caps/useHoverTracking.js +22 -17
- package/dist/features/chrome-caps/useHoverTracking.js.map +1 -1
- package/dist/features/focus/gateLayer.js +3 -4
- package/dist/features/focus/gateLayer.js.map +1 -1
- package/dist/features/images/imageCache.js +19 -9
- package/dist/features/images/imageCache.js.map +1 -1
- package/dist/features/ingestion/contentHandlers.js +14 -11
- package/dist/features/ingestion/contentHandlers.js.map +1 -1
- package/dist/features/ingestion/index.js +1 -1
- package/dist/features/ingestion/registerKitHandlers.js +7 -7
- package/dist/features/ingestion/weaselJsonHandler.js +17 -14
- package/dist/features/ingestion/weaselJsonHandler.js.map +1 -1
- package/dist/features/meshPaint/lazyKind.js +201 -35
- package/dist/features/meshPaint/lazyKind.js.map +1 -1
- package/dist/features/meshPaint/meshPaint.js +82 -79
- package/dist/features/meshPaint/meshPaint.js.map +1 -1
- package/dist/features/minimap/createMinimapContribution.js +42 -42
- package/dist/features/minimap/layers.js +44 -62
- package/dist/features/minimap/layers.js.map +1 -1
- package/dist/features/parallax/createParallaxPlane.js +10 -14
- package/dist/features/parallax/createParallaxPlane.js.map +1 -1
- package/dist/features/paths/anchorEdits.js +19 -8
- package/dist/features/paths/anchorEdits.js.map +1 -1
- package/dist/features/paths/anchors.js +31 -26
- package/dist/features/paths/anchors.js.map +1 -1
- package/dist/features/paths/booleans.js +2 -2
- package/dist/features/paths/index.js +13 -11
- package/dist/features/paths/markerCommands.js +37 -36
- package/dist/features/paths/markerCommands.js.map +1 -1
- package/dist/features/paths/pathInWorld.js +19 -19
- package/dist/features/paths/pathInWorld.js.map +1 -1
- package/dist/features/paths/pathLayer.js.map +1 -1
- package/dist/features/paths/strokeToPath.js +40 -0
- package/dist/features/paths/strokeToPath.js.map +1 -0
- package/dist/features/paths/tessellate/stroke.js.map +1 -1
- package/dist/features/patterns/commandPaint.js +18 -0
- package/dist/features/patterns/commandPaint.js.map +1 -0
- package/dist/features/patterns/index.js +5 -17
- package/dist/features/patterns/index.js.map +1 -1
- package/dist/features/patterns/rasterizeTile.js +17 -0
- package/dist/features/patterns/rasterizeTile.js.map +1 -0
- package/dist/features/patterns/resolveSpec.js +52 -44
- package/dist/features/patterns/resolveSpec.js.map +1 -1
- package/dist/features/poseRun/usePoseRun.js +8 -3
- package/dist/features/poseRun/usePoseRun.js.map +1 -1
- package/dist/features/selection/SelectionContext.js +5 -0
- package/dist/features/selection/SelectionContext.js.map +1 -1
- package/dist/features/selection/overlay.js +18 -18
- package/dist/features/selection/overlay.js.map +1 -1
- package/dist/features/text/domOffsets.js +82 -0
- package/dist/features/text/domOffsets.js.map +1 -0
- package/dist/features/text/domRuns.js +103 -131
- package/dist/features/text/domRuns.js.map +1 -1
- package/dist/features/text/hitTest.js +5 -2
- package/dist/features/text/hitTest.js.map +1 -1
- package/dist/features/text/isTextData.js +8 -0
- package/dist/features/text/isTextData.js.map +1 -0
- package/dist/features/text/overlayDirection.js +15 -0
- package/dist/features/text/overlayDirection.js.map +1 -0
- package/dist/features/text/runs/rangeStyle.js +32 -34
- package/dist/features/text/runs/rangeStyle.js.map +1 -1
- package/dist/features/text/textCommand.js +34 -33
- package/dist/features/text/textCommand.js.map +1 -1
- package/dist/features/text/textToPath.js +40 -40
- package/dist/features/text/textToPath.js.map +1 -1
- package/dist/features/text/useSceneTextEdit.js +76 -82
- package/dist/features/text/useSceneTextEdit.js.map +1 -1
- package/dist/features/text/useTextEdit.js +184 -160
- package/dist/features/text/useTextEdit.js.map +1 -1
- package/dist/features/tiling/createTiledLayer.js +24 -22
- package/dist/features/tiling/createTiledLayer.js.map +1 -1
- package/dist/index.d.ts +11010 -7700
- package/dist/index.js +316 -309
- package/dist/input/keyState.js +42 -43
- package/dist/input/keyState.js.map +1 -1
- package/dist/input/useKeyModifiers.js +11 -0
- package/dist/input/useKeyModifiers.js.map +1 -0
- package/dist/interactions/actions/align/align.js +8 -8
- package/dist/interactions/actions/clipboard/clipboardOps.js +34 -32
- package/dist/interactions/actions/clipboard/clipboardOps.js.map +1 -1
- package/dist/interactions/actions/clipboard/materializePaste.js +10 -7
- package/dist/interactions/actions/clipboard/materializePaste.js.map +1 -1
- package/dist/interactions/actions/clipboard/wireFormat.js.map +1 -1
- package/dist/interactions/actions/clone/behaviors/cloneByAltDrag.js.map +1 -1
- package/dist/interactions/actions/defaultCommitAdapter.js +20 -18
- package/dist/interactions/actions/defaultCommitAdapter.js.map +1 -1
- package/dist/interactions/actions/defaults/align.js +9 -10
- package/dist/interactions/actions/defaults/align.js.map +1 -1
- package/dist/interactions/actions/defaults/anchorEditing.js +59 -81
- package/dist/interactions/actions/defaults/anchorEditing.js.map +1 -1
- package/dist/interactions/actions/defaults/areaSelect.js +35 -38
- package/dist/interactions/actions/defaults/areaSelect.js.map +1 -1
- package/dist/interactions/actions/defaults/clipboard.js +26 -10
- package/dist/interactions/actions/defaults/clipboard.js.map +1 -1
- package/dist/interactions/actions/defaults/clone.js +44 -60
- package/dist/interactions/actions/defaults/clone.js.map +1 -1
- package/dist/interactions/actions/defaults/copySubtree.js +40 -0
- package/dist/interactions/actions/defaults/copySubtree.js.map +1 -0
- package/dist/interactions/actions/defaults/distribute.js +14 -13
- package/dist/interactions/actions/defaults/distribute.js.map +1 -1
- package/dist/interactions/actions/defaults/duplicate.js +17 -57
- package/dist/interactions/actions/defaults/duplicate.js.map +1 -1
- package/dist/interactions/actions/defaults/editAnchors.js +18 -18
- package/dist/interactions/actions/defaults/enterTextEdit.js.map +1 -1
- package/dist/interactions/actions/defaults/flip.js +52 -46
- package/dist/interactions/actions/defaults/flip.js.map +1 -1
- package/dist/interactions/actions/defaults/group.js +43 -48
- package/dist/interactions/actions/defaults/group.js.map +1 -1
- package/dist/interactions/actions/defaults/ingest.js +35 -33
- package/dist/interactions/actions/defaults/ingest.js.map +1 -1
- package/dist/interactions/actions/defaults/insert.js +50 -51
- package/dist/interactions/actions/defaults/insert.js.map +1 -1
- package/dist/interactions/actions/defaults/insertPathAnchor.js +7 -7
- package/dist/interactions/actions/defaults/lassoSelect.js +67 -70
- package/dist/interactions/actions/defaults/lassoSelect.js.map +1 -1
- package/dist/interactions/actions/defaults/move.js +267 -249
- package/dist/interactions/actions/defaults/move.js.map +1 -1
- package/dist/interactions/actions/defaults/nudge.js +40 -68
- package/dist/interactions/actions/defaults/nudge.js.map +1 -1
- package/dist/interactions/actions/defaults/nudgeSteps.js +37 -0
- package/dist/interactions/actions/defaults/nudgeSteps.js.map +1 -0
- package/dist/interactions/actions/defaults/reorder.js +2 -0
- package/dist/interactions/actions/defaults/reorder.js.map +1 -1
- package/dist/interactions/actions/defaults/resize.js +104 -98
- package/dist/interactions/actions/defaults/resize.js.map +1 -1
- package/dist/interactions/actions/defaults/rotate.js +111 -110
- package/dist/interactions/actions/defaults/rotate.js.map +1 -1
- package/dist/interactions/actions/defaults/setFill.js +7 -7
- package/dist/interactions/actions/defaults/setFillOpacity.js +4 -4
- package/dist/interactions/actions/defaults/setStroke.js +12 -12
- package/dist/interactions/actions/defaults/setStrokeOpacity.js +6 -6
- package/dist/interactions/actions/defaults/sliceOps.js +19 -19
- package/dist/interactions/actions/defaults/viewportDragPan.js +37 -26
- package/dist/interactions/actions/defaults/viewportDragPan.js.map +1 -1
- package/dist/interactions/actions/edit-anchors/geometry.js +28 -23
- package/dist/interactions/actions/edit-anchors/geometry.js.map +1 -1
- package/dist/interactions/actions/flip/helpers.js +30 -17
- package/dist/interactions/actions/flip/helpers.js.map +1 -1
- package/dist/interactions/actions/hitSelection.js +8 -0
- package/dist/interactions/actions/hitSelection.js.map +1 -0
- package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js +14 -18
- package/dist/interactions/actions/lasso-select/behaviors/selectFromLasso.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js +5 -5
- package/dist/interactions/actions/move/behaviors/snapBackOrDelete.js.map +1 -1
- package/dist/interactions/actions/move/behaviors/snapToContainer.js +32 -21
- package/dist/interactions/actions/move/behaviors/snapToContainer.js.map +1 -1
- package/dist/interactions/actions/move/gestureAdapter.js +32 -15
- package/dist/interactions/actions/move/gestureAdapter.js.map +1 -1
- package/dist/interactions/actions/move/landedDescendants.js +33 -0
- package/dist/interactions/actions/move/landedDescendants.js.map +1 -0
- package/dist/interactions/actions/outlines/createOutlines.js +18 -18
- package/dist/interactions/actions/poseDescriptorDep.js +16 -4
- package/dist/interactions/actions/poseDescriptorDep.js.map +1 -1
- package/dist/interactions/actions/poseFrame.js +11 -6
- package/dist/interactions/actions/poseFrame.js.map +1 -1
- package/dist/interactions/actions/previewOverrides.js +5 -5
- package/dist/interactions/actions/previewOverrides.js.map +1 -1
- package/dist/interactions/actions/selectionSubtree.js +69 -0
- package/dist/interactions/actions/selectionSubtree.js.map +1 -0
- package/dist/interactions/actions/useStandardActions.js +66 -62
- package/dist/interactions/actions/useStandardActions.js.map +1 -1
- package/dist/interactions/gestures/dragGesture/dragGesture.js +4 -7
- package/dist/interactions/gestures/dragGesture/dragGesture.js.map +1 -1
- package/dist/interactions/gestures/dragGesture/dragPointOf.js +23 -0
- package/dist/interactions/gestures/dragGesture/dragPointOf.js.map +1 -0
- package/dist/interactions/gestures/handleDrag/handleDrag.js +21 -26
- package/dist/interactions/gestures/handleDrag/handleDrag.js.map +1 -1
- package/dist/interactions/gestures/pointerDrag/pointerDrag.js +8 -6
- package/dist/interactions/gestures/pointerDrag/pointerDrag.js.map +1 -1
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js +8 -4
- package/dist/interactions/gestures/thresholdDrag/thresholdDrag.js.map +1 -1
- package/dist/{math-Drrw4ewZ.d.ts → math-J-ACHyEg.d.ts} +1 -2
- package/dist/math.d.ts +2 -3
- package/dist/move.d.ts +12 -11
- package/dist/{originProjection-DEklpDc_.d.ts → originProjection-gHnOup4e.d.ts} +1 -1
- package/dist/{registerProgram-BMZRDgrh.d.ts → registerProgram-T9S_PfAX.d.ts} +18 -7
- package/dist/renderer/DrawCommand.js.map +1 -1
- package/dist/renderer/WeaselRenderer.js +75 -73
- package/dist/renderer/WeaselRenderer.js.map +1 -1
- package/dist/renderer/cache/GLImageCache.js +15 -5
- package/dist/renderer/cache/GLImageCache.js.map +1 -1
- package/dist/renderer/cache/GLMeshCache.js +23 -23
- package/dist/renderer/cache/GLMeshCache.js.map +1 -1
- package/dist/renderer/cache/GLTextureCache.js +18 -1
- package/dist/renderer/cache/GLTextureCache.js.map +1 -1
- package/dist/renderer/cache/cache.js.map +1 -1
- package/dist/renderer/cache/markerCommandCache.js.map +1 -1
- package/dist/renderer/cache/strokeMeshCache.js.map +1 -1
- package/dist/renderer/cullDrawCommands.js +11 -11
- package/dist/renderer/draw/batch.js +133 -0
- package/dist/renderer/draw/batch.js.map +1 -0
- package/dist/renderer/draw/clip.js +89 -0
- package/dist/renderer/draw/clip.js.map +1 -0
- package/dist/renderer/draw/customShader.js +230 -0
- package/dist/renderer/draw/customShader.js.map +1 -0
- package/dist/renderer/draw/drawTriangles.js +8 -0
- package/dist/renderer/draw/drawTriangles.js.map +1 -0
- package/dist/renderer/draw/effects.js +28 -0
- package/dist/renderer/draw/effects.js.map +1 -0
- package/dist/renderer/draw/flushBatch.js +35 -0
- package/dist/renderer/draw/flushBatch.js.map +1 -0
- package/dist/renderer/draw/gradient.js +90 -0
- package/dist/renderer/draw/gradient.js.map +1 -0
- package/dist/renderer/draw/image.js +38 -0
- package/dist/renderer/draw/image.js.map +1 -0
- package/dist/renderer/draw/mesh.js +16 -0
- package/dist/renderer/draw/mesh.js.map +1 -0
- package/dist/renderer/draw/paintBind.js +70 -0
- package/dist/renderer/draw/paintBind.js.map +1 -0
- package/dist/renderer/draw/pathPaint.js +142 -0
- package/dist/renderer/draw/pathPaint.js.map +1 -0
- package/dist/renderer/draw/scratchPass.js +83 -0
- package/dist/renderer/draw/scratchPass.js.map +1 -0
- package/dist/renderer/draw/stencil.js +28 -0
- package/dist/renderer/draw/stencil.js.map +1 -0
- package/dist/renderer/draw/text.js +167 -0
- package/dist/renderer/draw/text.js.map +1 -0
- package/dist/renderer/draw/uniforms.js +77 -0
- package/dist/renderer/draw/uniforms.js.map +1 -0
- package/dist/renderer/draw.js +60 -1116
- package/dist/renderer/draw.js.map +1 -1
- package/dist/renderer/effects/EffectTargets.js +3 -0
- package/dist/renderer/effects/EffectTargets.js.map +1 -1
- package/dist/renderer/effects/composite.js +7 -5
- package/dist/renderer/effects/composite.js.map +1 -1
- package/dist/renderer/index.js +18 -17
- package/dist/renderer/math/color.js +63 -83
- package/dist/renderer/math/color.js.map +1 -1
- package/dist/renderer/math/mat3.js +15 -11
- package/dist/renderer/math/mat3.js.map +1 -1
- package/dist/renderer/math/viewToMat3.js +1 -1
- package/dist/renderer/math/viewToMat3.js.map +1 -1
- package/dist/renderer/shaders/ShaderProgram.js +13 -13
- package/dist/renderer/shaders/ShaderProgram.js.map +1 -1
- package/dist/renderer/shaders/glyphPaint.js +3 -3
- package/dist/renderer/shaders/glyphPaint.js.map +1 -1
- package/dist/renderer/shaders/gradFill.js +2 -1
- package/dist/renderer/shaders/gradFill.js.map +1 -1
- package/dist/renderer/shaders/pathFill.js +2 -1
- package/dist/renderer/shaders/pathFill.js.map +1 -1
- package/dist/renderer/shaders/patternFill.js +2 -1
- package/dist/renderer/shaders/patternFill.js.map +1 -1
- package/dist/renderer/shaders/registerProgram.js.map +1 -1
- package/dist/renderer/strokeLengths.js.map +1 -1
- package/dist/renderer/textures/registerTexture.js +25 -5
- package/dist/renderer/textures/registerTexture.js.map +1 -1
- package/dist/renderer.d.ts +16 -15
- package/dist/renderer.js +17 -16
- package/dist/resize.d.ts +5 -6
- package/dist/resize.js +5 -5
- package/dist/style.css +1 -1
- package/dist/test-hook/install.js +12 -6
- package/dist/test-hook/install.js.map +1 -1
- package/dist/{test-seams-CuIxe0xY.d.ts → test-seams-DM2B87-g.d.ts} +4 -4
- package/dist/test-seams.d.ts +2 -2
- package/dist/tools/builtin/ellipse/useEllipseTool.js +1 -0
- package/dist/tools/builtin/ellipse/useEllipseTool.js.map +1 -1
- package/dist/tools/builtin/hand/useHandTool.js +1 -0
- package/dist/tools/builtin/hand/useHandTool.js.map +1 -1
- package/dist/tools/builtin/lasso/useLassoTool.js +11 -11
- package/dist/tools/builtin/lasso/useLassoTool.js.map +1 -1
- package/dist/tools/builtin/line/useLineTool.js +1 -0
- package/dist/tools/builtin/line/useLineTool.js.map +1 -1
- package/dist/tools/builtin/pen/usePenTool.js +153 -103
- package/dist/tools/builtin/pen/usePenTool.js.map +1 -1
- package/dist/tools/builtin/pencil/usePencilTool.js +1 -0
- package/dist/tools/builtin/pencil/usePencilTool.js.map +1 -1
- package/dist/tools/builtin/polygon/usePolygonTool.js +13 -8
- package/dist/tools/builtin/polygon/usePolygonTool.js.map +1 -1
- package/dist/tools/builtin/rect/useRectTool.js +1 -0
- package/dist/tools/builtin/rect/useRectTool.js.map +1 -1
- package/dist/tools/builtin/select/selectionContributions.js +24 -23
- package/dist/tools/builtin/select/selectionContributions.js.map +1 -1
- package/dist/tools/builtin/select/useSelectTool.js +51 -48
- package/dist/tools/builtin/select/useSelectTool.js.map +1 -1
- package/dist/tools/builtin/shared/pointerFollower.js +17 -0
- package/dist/tools/builtin/shared/pointerFollower.js.map +1 -0
- package/dist/tools/builtin/slice/useSliceTool.js +49 -54
- package/dist/tools/builtin/slice/useSliceTool.js.map +1 -1
- package/dist/tools/builtin/star/useStarTool.js +22 -16
- package/dist/tools/builtin/star/useStarTool.js.map +1 -1
- package/dist/tools/builtin/text/useTextTool.js +13 -2
- package/dist/tools/builtin/text/useTextTool.js.map +1 -1
- package/dist/tools/useKeybindings.js +14 -30
- package/dist/tools/useKeybindings.js.map +1 -1
- package/dist/{types-B_9g6hMM.d.ts → types-B4iJRHC3.d.ts} +5 -1
- package/dist/{types-A37hYkeR.d.ts → types-k-5Oqh-U.d.ts} +31 -7
- package/dist/util/color.js +3 -3
- package/dist/util/color.js.map +1 -1
- package/dist/util/paint.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +20 -18
- package/dist/autoPoseDescriptor-vCdt55xm.d.ts +0 -27
- package/dist/builtins-C-VgUlWI.d.ts +0 -4514
- package/dist/core/isPlainObject.js.map +0 -1
- package/dist/debug/flag.js.map +0 -1
- package/dist/interactions/actions/defaults/freshNodeId.js +0 -10
- package/dist/interactions/actions/defaults/freshNodeId.js.map +0 -1
- package/dist/renderer/shaders/imageFill.js +0 -14
- package/dist/renderer/shaders/imageFill.js.map +0 -1
- package/dist/tools/prefs.js +0 -47
- package/dist/tools/prefs.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawTriangles.js","names":["drawTriangles","ctx","count","type"],"sources":["../../../src/renderer/draw/drawTriangles.ts"],"sourcesContent":["import type { DrawContext } from './drawContext';\n\n/** Every GL draw the renderer issues goes through here, so the frame's\n * draw-call count cannot miss one. */\nexport function drawTriangles(ctx: DrawContext, count: number, type: number): void {\n ctx.gl.drawElements(ctx.gl.TRIANGLES, count, type, 0);\n if (ctx.stats) ctx.stats.drawCalls++;\n}\n"],"mappings":";AAIA,SAAgBA,EAAc,GAAkB,GAAe,GAAoB;CAEjF,AADAC,EAAI,GAAG,aAAaA,EAAI,GAAG,WAAWC,GAAOC,GAAM,CAAC,GAChDF,EAAI,SAAO,EAAI,MAAM;AAC3B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { drawTriangles as e } from "./drawTriangles.js";
|
|
2
|
+
import { setUniforms as t } from "./customShader.js";
|
|
3
|
+
import { setColorMatrixUniforms as n } from "./uniforms.js";
|
|
4
|
+
//#region src/renderer/draw/effects.ts
|
|
5
|
+
function r(e, t, n, r) {
|
|
6
|
+
let i = e.gl, a = e.renderTarget ?? null;
|
|
7
|
+
i.bindFramebuffer(i.FRAMEBUFFER, a ? a.fbo : null), a ? i.viewport(0, 0, t, n) : (e.restoreTargetRect?.(), r && i.enable(i.SCISSOR_TEST));
|
|
8
|
+
}
|
|
9
|
+
function i(r, i, a, o, s, c, l, u) {
|
|
10
|
+
let d = r.gl;
|
|
11
|
+
d.useProgram(i.handle);
|
|
12
|
+
let f = i.attribute("a_position"), p = i.attribute("a_uv");
|
|
13
|
+
d.bindBuffer(d.ARRAY_BUFFER, r.quadVbo), d.bindBuffer(d.ELEMENT_ARRAY_BUFFER, r.quadIbo), f !== void 0 && f >= 0 && (d.enableVertexAttribArray(f), d.vertexAttribPointer(f, 2, d.FLOAT, !1, 16, 0)), p !== void 0 && p >= 0 && (d.enableVertexAttribArray(p), d.vertexAttribPointer(p, 2, d.FLOAT, !1, 16, 8)), d.activeTexture(d.TEXTURE0), d.bindTexture(d.TEXTURE_2D, a);
|
|
14
|
+
let m = i.uniform("u_source");
|
|
15
|
+
m !== void 0 && d.uniform1i(m, 0);
|
|
16
|
+
let h = i.uniform("u_resolution");
|
|
17
|
+
h !== void 0 && d.uniform2f(h, o, s);
|
|
18
|
+
let g = i.uniform("u_texel");
|
|
19
|
+
if (g !== void 0 && d.uniform2f(g, 1 / o, 1 / s), l) {
|
|
20
|
+
let e = i.uniform("u_alpha");
|
|
21
|
+
e !== void 0 && d.uniform1f(e, l.alpha), n(r, i, l.colorMatrix);
|
|
22
|
+
}
|
|
23
|
+
c && t(d, i, u ?? "effect", c, r.textureCache, { value: 1 }), e(r, 6, r.gl.UNSIGNED_SHORT), f !== void 0 && f >= 0 && d.disableVertexAttribArray(f), p !== void 0 && p >= 0 && d.disableVertexAttribArray(p), d.bindBuffer(d.ARRAY_BUFFER, null), d.bindBuffer(d.ELEMENT_ARRAY_BUFFER, null);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { i as drawFullscreenQuad, r as returnToRenderTarget };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","names":["returnToRenderTarget","gl","ctx","target","width","height","scissorWasOn","drawFullscreenQuad","program","aPos","aUv","texture","source","resolution","texel","composite","alpha","setColorMatrixUniforms","uniforms","setUniforms","programId","drawTriangles"],"sources":["../../../src/renderer/draw/effects.ts"],"sourcesContent":["import type { ShaderUniform } from '../shaders/registerProgram';\nimport type { ShaderProgram } from '../shaders/ShaderProgram';\nimport type { DrawContext } from './drawContext';\nimport { drawTriangles } from './drawTriangles';\nimport { setColorMatrixUniforms } from './uniforms';\nimport { setUniforms } from './customShader';\n\n/** Rebind `ctx.renderTarget` after an offscreen pass: a pooled target takes\n * the whole `width` × `height` buffer, the default framebuffer the renderer's\n * own rect and the scissor it had. */\nexport function returnToRenderTarget(\n ctx: DrawContext, width: number, height: number, scissorWasOn: boolean,\n): void {\n const gl = ctx.gl;\n const target = ctx.renderTarget ?? null;\n gl.bindFramebuffer(gl.FRAMEBUFFER, target ? target.fbo : null);\n if (target) {\n gl.viewport(0, 0, width, height);\n } else {\n ctx.restoreTargetRect?.();\n if (scissorWasOn) gl.enable(gl.SCISSOR_TEST);\n }\n}\n\n/** One pass: the kit quad, `u_source` bound to `texture`, and whatever else\n * the caller supplies. Leaves no attribute arrays or buffers bound. */\nexport function drawFullscreenQuad(\n ctx: DrawContext,\n program: ShaderProgram,\n texture: WebGLTexture,\n width: number,\n height: number,\n uniforms?: Record<string, ShaderUniform>,\n composite?: { alpha: number; colorMatrix: Float32Array },\n programId?: string,\n): void {\n const gl = ctx.gl;\n gl.useProgram(program.handle);\n\n const aPos = program.attribute('a_position');\n const aUv = program.attribute('a_uv');\n gl.bindBuffer(gl.ARRAY_BUFFER, ctx.quadVbo);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ctx.quadIbo);\n if (aPos !== undefined && aPos >= 0) {\n gl.enableVertexAttribArray(aPos);\n gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);\n }\n if (aUv !== undefined && aUv >= 0) {\n gl.enableVertexAttribArray(aUv);\n gl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);\n }\n\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, texture);\n const source = program.uniform('u_source');\n if (source !== undefined) gl.uniform1i(source, 0);\n const resolution = program.uniform('u_resolution');\n if (resolution !== undefined) gl.uniform2f(resolution, width, height);\n const texel = program.uniform('u_texel');\n if (texel !== undefined) gl.uniform2f(texel, 1 / width, 1 / height);\n\n if (composite) {\n const alpha = program.uniform('u_alpha');\n if (alpha !== undefined) gl.uniform1f(alpha, composite.alpha);\n setColorMatrixUniforms(ctx, program, composite.colorMatrix);\n }\n\n // Unit 0 is `u_source`; a consumer texture starts above it.\n if (uniforms) setUniforms(gl, program, programId ?? 'effect', uniforms, ctx.textureCache, { value: 1 });\n\n drawTriangles(ctx, 6, ctx.gl.UNSIGNED_SHORT);\n\n if (aPos !== undefined && aPos >= 0) gl.disableVertexAttribArray(aPos);\n if (aUv !== undefined && aUv >= 0) gl.disableVertexAttribArray(aUv);\n gl.bindBuffer(gl.ARRAY_BUFFER, null);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);\n}\n"],"mappings":";;;;AAUA,SAAgBA,EACd,GAAkB,GAAe,GAAgB,GAC3C;CACN,IAAMC,IAAKC,EAAI,IACTC,IAASD,EAAI,gBAAgB;CAEnC,AADAD,EAAG,gBAAgBA,EAAG,aAAaE,IAASA,EAAO,MAAM,IAAI,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AAU,WAAW;CAC5D;CAUA,AAPIG,KAAUC,EAAYlB,GAAIO,GAASY,KAAa,UAAUF,GAAUhB,EAAI,cAAc,EAAE,OAAO,EAAE,CAAC,GAEtGmB,EAAcnB,GAAK,GAAGA,EAAI,GAAG,cAAc,GAEvCO,MAAS,KAAA,KAAaA,KAAQ,KAAGR,EAAG,yBAAyBQ,CAAI,GACjEC,MAAQ,KAAA,KAAaA,KAAO,KAAGT,EAAG,yBAAyBS,CAAG,GAClET,EAAG,WAAWA,EAAG,cAAc,IAAI,GACnCA,EAAG,WAAWA,EAAG,sBAAsB,IAAI;AAC7C"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BATCH_TEXTURE_SLOTS as e } from "../shaders/batchFill.js";
|
|
2
|
+
import { mat3 as t } from "../math/mat3.js";
|
|
3
|
+
import { drawTriangles as n } from "./drawTriangles.js";
|
|
4
|
+
import { applyClipTest as r } from "./stencil.js";
|
|
5
|
+
import { setAlphaUniform as i, setColorMatrixUniforms as a, setColorUniform as o, setProjAndModel as s } from "./uniforms.js";
|
|
6
|
+
//#region src/renderer/draw/flushBatch.ts
|
|
7
|
+
var c = t.identity(), l = new Int32Array(Array.from({ length: e }, (e, t) => t)), u = new Float32Array(2 * e);
|
|
8
|
+
function d(e) {
|
|
9
|
+
let t = e.drawBatch, d = e.batchState;
|
|
10
|
+
if (t.length === 0 || d === void 0) {
|
|
11
|
+
e.batchState = void 0;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
let f = e.gl, p = e.batchFill;
|
|
15
|
+
f.useProgram(p.handle);
|
|
16
|
+
let m = t.uploadAndBind();
|
|
17
|
+
s(e, p, c), o(e, p, 1, 1, 1, 1), i(e, p, d.alpha), f.uniform1f(p.uniform("u_synthBold"), d.synthBold), a(e, p, d.colorMatrix), f.activeTexture(f.TEXTURE0), f.bindTexture(f.TEXTURE_2D, e.whiteTexture);
|
|
18
|
+
for (let t = 0; t < d.textures.length; t++) {
|
|
19
|
+
let n = d.textures[t];
|
|
20
|
+
if (n.kind === "atlas") {
|
|
21
|
+
e.textureCache.bind(n.id, t + 1), u[2 * (t + 1)] = n.fieldScale[0], u[2 * (t + 1) + 1] = n.fieldScale[1];
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (n.kind === "ramps") {
|
|
25
|
+
e.gradRamps.bind(t + 1);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
e.imageCache.bind(n.image, t + 1), e.imageCache.setMagFilter(n.image, n.sampling === "nearest" ? f.NEAREST : f.LINEAR);
|
|
29
|
+
}
|
|
30
|
+
f.uniform1iv(p.uniform("u_samplers"), l), f.uniform2fv(p.uniform("u_fieldScale"), u), r(e, d.clipDepth), n(e, m, e.gl.UNSIGNED_INT), f.activeTexture(f.TEXTURE0), f.bindVertexArray(null), t.reset(), e.batchState = void 0;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { c as BATCH_MODEL, d as flushBatch };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=flushBatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushBatch.js","names":["BATCH_MODEL","mat3","SAMPLER_UNITS","BATCH_TEXTURE_SLOTS","i","FIELD_SCALES","flushBatch","batch","ctx","staged","gl","prog","indexCount","setProjAndModel","setColorUniform","setAlphaUniform","setColorMatrixUniforms","entry","applyClipTest","drawTriangles"],"sources":["../../../src/renderer/draw/flushBatch.ts"],"sourcesContent":["import { mat3 } from '../math/mat3';\nimport { BATCH_TEXTURE_SLOTS } from '../shaders/batchFill';\nimport type { DrawContext } from './drawContext';\nimport { drawTriangles } from './drawTriangles';\nimport {\n setColorUniform,\n setAlphaUniform,\n setColorMatrixUniforms,\n setProjAndModel,\n} from './uniforms';\nimport { applyClipTest } from './stencil';\n\n/** The rect batch transforms its own corners, so it draws at model identity. */\nexport const BATCH_MODEL = mat3.identity();\n\n/** `u_samplers[i] = i`, uploaded whole per flush. Built once: the mapping from\n * slot to texture unit is the identity and never varies. */\nconst SAMPLER_UNITS = new Int32Array(\n Array.from({ length: BATCH_TEXTURE_SLOTS }, (_, i) => i),\n);\n\n/** `u_fieldScale`, per slot: an atlas slot's `glyphFieldScale`. Slots that are\n * not atlases keep whatever a previous flush wrote, which nothing reads. */\nconst FIELD_SCALES = new Float32Array(2 * BATCH_TEXTURE_SLOTS);\n\n/**\n * Draw the staged run as one `drawElements`, under the state it was staged\n * under. Callers that are about to bind a different program, or paint anything\n * that must land on top of the run, call this first; a group that only changes\n * the color matrix does not, because `pushRect` notices and flushes then, and\n * one that only changes transform or alpha does not break the run at all.\n *\n * Stencil clips are the exception: the stencil is real GL state that the\n * staged values cannot reconstruct, so `pushClip` flushes *before* writing a\n * bit, and `popClip` before clearing one a staged run tests. Rect clips never\n * reach the stencil while only staged geometry is inside them — see\n * `enterClip`.\n *\n * `u_color` stays white: the vertex-color program multiplies it by the\n * per-vertex color, so white makes the result bit-identical to the flat\n * program's `u_color`-only math. `u_model` stays identity for the same reason —\n * the corners arrive already transformed.\n */\nexport function flushBatch(ctx: DrawContext): void {\n const batch = ctx.drawBatch;\n const staged = ctx.batchState;\n if (batch.length === 0 || staged === undefined) {\n // An empty run's state still names a clip depth, and an item refused by\n // the CPU cut is about to be staged again under a different one.\n ctx.batchState = undefined;\n return;\n }\n const gl = ctx.gl;\n const prog = ctx.batchFill;\n gl.useProgram(prog.handle);\n const indexCount = batch.uploadAndBind();\n setProjAndModel(ctx, prog, BATCH_MODEL);\n setColorUniform(ctx, prog, 1, 1, 1, 1);\n setAlphaUniform(ctx, prog, staged.alpha);\n gl.uniform1f(prog.uniform('u_synthBold')!, staged.synthBold);\n setColorMatrixUniforms(ctx, prog, staged.colorMatrix);\n gl.activeTexture(gl.TEXTURE0);\n gl.bindTexture(gl.TEXTURE_2D, ctx.whiteTexture);\n for (let i = 0; i < staged.textures.length; i++) {\n const entry = staged.textures[i];\n if (entry.kind === 'atlas') {\n ctx.textureCache.bind(entry.id, i + 1);\n FIELD_SCALES[2 * (i + 1)] = entry.fieldScale[0];\n FIELD_SCALES[2 * (i + 1) + 1] = entry.fieldScale[1];\n continue;\n }\n if (entry.kind === 'ramps') {\n ctx.gradRamps.bind(i + 1);\n continue;\n }\n ctx.imageCache.bind(entry.image, i + 1);\n // Per flush, not at upload: the same bitmap can be drawn at both filters in\n // one frame. The cache skips the write when the texture already carries the\n // value, which is most flushes.\n ctx.imageCache.setMagFilter(\n entry.image,\n entry.sampling === 'nearest' ? gl.NEAREST : gl.LINEAR,\n );\n }\n gl.uniform1iv(prog.uniform('u_samplers')!, SAMPLER_UNITS);\n gl.uniform2fv(prog.uniform('u_fieldScale')!, FIELD_SCALES);\n applyClipTest(ctx, staged.clipDepth);\n drawTriangles(ctx, indexCount, ctx.gl.UNSIGNED_INT);\n // Everything else in the renderer binds its texture to unit 0 and some of it\n // does so without an `activeTexture` of its own, so leaving unit 6 selected\n // sends the next such bind to a unit nothing samples.\n gl.activeTexture(gl.TEXTURE0);\n // Not redundant: `drawShader` binds no VAO and points attributes at whatever\n // is current, so a slot left bound here comes back corrupted a ring later.\n gl.bindVertexArray(null);\n batch.reset();\n ctx.batchState = undefined;\n}\n"],"mappings":";;;;;;AAaA,IAAaA,IAAcC,EAAK,SAAS,GAInCC,IAAgB,IAAI,WACxB,MAAM,KAAK,EAAE,QAAQC,EAAoB,IAAI,GAAG,MAAMC,CAAC,CACzD,GAIMC,IAAe,IAAI,aAAa,IAAIF,CAAmB;AAoB7D,SAAgBG,EAAW,GAAwB;CACjD,IAAMC,IAAQC,EAAI,WACZC,IAASD,EAAI;CACnB,IAAID,EAAM,WAAW,KAAKE,MAAW,KAAA,GAAW;EAG9C,EAAI,aAAa,KAAA;EACjB;CACF;CACA,IAAMC,IAAKF,EAAI,IACTG,IAAOH,EAAI;CACjB,EAAG,WAAWG,EAAK,MAAM;CACzB,IAAMC,IAAaL,EAAM,cAAc;CAOvC,AANAM,EAAgBL,GAAKG,GAAMX,CAAW,G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
|
2
|
+
import { mat3 as r } from "../math/mat3.js";
|
|
3
|
+
//#region src/renderer/draw/gradient.ts
|
|
4
|
+
function i(r, i, u) {
|
|
5
|
+
if (u) return;
|
|
6
|
+
let d = i.fill ?? "solid";
|
|
7
|
+
if (d === "solid") {
|
|
8
|
+
let e = i;
|
|
9
|
+
return {
|
|
10
|
+
kind: "solid",
|
|
11
|
+
color: e.color,
|
|
12
|
+
opacity: e.opacity
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (d !== "linear-gradient" && d !== "radial-gradient" && d !== "conic-gradient") return;
|
|
16
|
+
let f = i, p = o(r, f.units);
|
|
17
|
+
return p ? f.fill === "linear-gradient" ? a(f, t, s(p, f)) : f.fill === "radial-gradient" ? a(f, n, c(p, f)) : a(f, e, l(p, f)) : null;
|
|
18
|
+
}
|
|
19
|
+
function a(e, t, n) {
|
|
20
|
+
return {
|
|
21
|
+
kind: "ramp",
|
|
22
|
+
stops: e.stops,
|
|
23
|
+
space: e.interpolate ?? "rgb",
|
|
24
|
+
opacity: e.opacity,
|
|
25
|
+
mode: t,
|
|
26
|
+
uv: n
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function o(e, t) {
|
|
30
|
+
let n = d(e, t);
|
|
31
|
+
return n && r.multiply(n, e.state.transform);
|
|
32
|
+
}
|
|
33
|
+
function s(e, t) {
|
|
34
|
+
let n = t.to.x - t.from.x, r = t.to.y - t.from.y, i = Math.hypot(n, r) || 1, a = 1 / (i * i);
|
|
35
|
+
return {
|
|
36
|
+
ux: (e[0] * n + e[1] * r) * a,
|
|
37
|
+
uy: (e[3] * n + e[4] * r) * a,
|
|
38
|
+
u0: ((e[6] - t.from.x) * n + (e[7] - t.from.y) * r) * a,
|
|
39
|
+
vx: 0,
|
|
40
|
+
vy: 0,
|
|
41
|
+
v0: 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function c(e, t) {
|
|
45
|
+
let n = 1 / Math.max(t.radius, 1e-4);
|
|
46
|
+
return {
|
|
47
|
+
ux: e[0] * n,
|
|
48
|
+
uy: e[3] * n,
|
|
49
|
+
u0: (e[6] - t.center.x) * n,
|
|
50
|
+
vx: e[1] * n,
|
|
51
|
+
vy: e[4] * n,
|
|
52
|
+
v0: (e[7] - t.center.y) * n
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function l(e, t) {
|
|
56
|
+
let n = Math.cos(t.angle), r = Math.sin(t.angle), i = e[6] - t.center.x, a = e[7] - t.center.y;
|
|
57
|
+
return {
|
|
58
|
+
ux: n * e[0] + r * e[1],
|
|
59
|
+
uy: n * e[3] + r * e[4],
|
|
60
|
+
u0: n * i + r * a,
|
|
61
|
+
vx: n * e[1] - r * e[0],
|
|
62
|
+
vy: n * e[4] - r * e[3],
|
|
63
|
+
v0: n * a - r * i
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function u(e, n) {
|
|
67
|
+
return e.mode === t ? {
|
|
68
|
+
uv: {
|
|
69
|
+
...e.uv,
|
|
70
|
+
v0: n
|
|
71
|
+
},
|
|
72
|
+
post: 1
|
|
73
|
+
} : {
|
|
74
|
+
uv: e.uv,
|
|
75
|
+
post: n
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function d(e, t) {
|
|
79
|
+
return t === "local" ? r.invert(e.state.transform) : t === "world" && e.viewMatrix ? r.invert(e.viewMatrix) : r.identity();
|
|
80
|
+
}
|
|
81
|
+
function f(e, t) {
|
|
82
|
+
let n = d(e, t), i = n && r.invert(n);
|
|
83
|
+
if (!i) return null;
|
|
84
|
+
let a = e.deviceWidth && e.widthCss > 0 ? e.deviceWidth / e.widthCss : 1;
|
|
85
|
+
return r.multiply(r.scaled(r.identity(), a, a), i);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { i as batchPaint, d as gradientSpaceInverse, u as rampVertices, f as spaceToDevice };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=gradient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradient.js","names":["batchPaint","hasVColors","kind","fill","solid","grad","g","gradientMap","ctx","ramp","PAINT_MODE_PLAIN","linearRampUV","PAINT_MODE_RADIAL","radialRampUV","PAINT_MODE_CONIC","conicRampUV","inverse","gradientSpaceInverse","units","mat3","dx","dy","len","k","cos","sin","dx0","dy0","rampVertices","paint","rowV","spaceToDevice","toScreen","ratio"],"sources":["../../../src/renderer/draw/gradient.ts"],"sourcesContent":["import type { ColorSpace, FillStyle, GradientUnits, GradStop } from '@weasel-js/paint';\nimport { mat3, type GlMat3 } from '../math/mat3';\nimport type { GradientUV } from '../drawBatch';\nimport { PAINT_MODE_PLAIN, PAINT_MODE_RADIAL, PAINT_MODE_CONIC } from '../shaders/batchFill';\nimport type { DrawContext } from './drawContext';\n\n/** A paint a run can express, resolved from a `FillStyle` by `batchPaint`. */\nexport type BatchPaint =\n | { kind: 'solid'; color: string; opacity?: number }\n | {\n kind: 'ramp'; stops: GradStop[]; space: ColorSpace; opacity?: number;\n /** `PAINT_MODE_PLAIN` for a linear gradient, whose ramp position a vertex\n * carries outright; `PAINT_MODE_RADIAL` / `PAINT_MODE_CONIC` otherwise. */\n mode: number;\n uv: GradientUV;\n };\n\n/**\n * `fill` as something a run can carry, or `undefined` for a paint no run can\n * express — a pattern, a shader, per-vertex colors — and `null` for a gradient\n * whose space has no inverse under this transform, which draws nothing.\n *\n * **All three gradients qualify, and for the same reason,** which is not that\n * their ramp position is affine in position — only a linear gradient's is. It\n * is that the *coordinate* the ramp position is computed from is affine in all\n * three, so a vertex can carry that and the rasterizer's interpolation across a\n * triangle is exact. A linear gradient's coordinate is the ramp position\n * itself, which is why it needs no paint mode; the other two carry a\n * gradient-space point and the shader takes a `length` or an `atan` of it.\n */\nexport function batchPaint(\n ctx: DrawContext, fill: FillStyle, hasVColors: boolean,\n): BatchPaint | undefined | null {\n if (hasVColors) return undefined;\n const kind = fill.fill ?? 'solid';\n if (kind === 'solid') {\n const solid = fill as { color: string; opacity?: number };\n return { kind: 'solid', color: solid.color, opacity: solid.opacity };\n }\n if (kind !== 'linear-gradient' && kind !== 'radial-gradient' && kind !== 'conic-gradient') {\n return undefined;\n }\n const grad = fill as Extract<FillStyle, { fill: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }>;\n const g = gradientMap(ctx, grad.units);\n if (!g) return null;\n if (grad.fill === 'linear-gradient') return ramp(grad, PAINT_MODE_PLAIN, linearRampUV(g, grad));\n if (grad.fill === 'radial-gradient') return ramp(grad, PAINT_MODE_RADIAL, radialRampUV(g, grad));\n return ramp(grad, PAINT_MODE_CONIC, conicRampUV(g, grad));\n}\n\nfunction ramp(\n fill: { stops: GradStop[]; interpolate?: ColorSpace; opacity?: number },\n mode: number, uv: GradientUV,\n): BatchPaint {\n return {\n kind: 'ramp', stops: fill.stops, space: fill.interpolate ?? 'rgb',\n opacity: fill.opacity, mode, uv,\n };\n}\n\n/**\n * Geometry-space → gradient-space, as the one matrix a vertex is measured\n * through.\n *\n * `gradientSpaceInverse` maps a screen position back into the gradient's space\n * and the batch's vertices arrive before the model transform, so the two\n * compose. This is the composition `gradFill`'s vertex shader does in two\n * steps, and the pair have to agree: a radial gradient goes through that one\n * and a linear one through this.\n */\nfunction gradientMap(ctx: DrawContext, units: GradientUnits | undefined): GlMat3 | null {\n const inverse = gradientSpaceInverse(ctx, units);\n return inverse && mat3.multiply(inverse, ctx.state.transform);\n}\n\n/**\n * The gradient shader's `dot(p - from, dir) / len` folded into `u`, with `v`\n * left for the atlas row `stageRamps` fills in.\n */\nfunction linearRampUV(\n g: GlMat3, fill: Extract<FillStyle, { fill: 'linear-gradient' }>,\n): GradientUV {\n const dx = fill.to.x - fill.from.x;\n const dy = fill.to.y - fill.from.y;\n const len = Math.hypot(dx, dy) || 1;\n // dir is (dx, dy)/len and the divisor is len, so the pair is 1/len².\n const k = 1 / (len * len);\n return {\n ux: (g[0] * dx + g[1] * dy) * k,\n uy: (g[3] * dx + g[4] * dy) * k,\n u0: ((g[6] - fill.from.x) * dx + (g[7] - fill.from.y) * dy) * k,\n vx: 0, vy: 0, v0: 0,\n };\n}\n\n/** The gradient-space point scaled so its distance from the center *is* the\n * ramp position, which is what makes the shader's half a `length`. */\nfunction radialRampUV(\n g: GlMat3, fill: Extract<FillStyle, { fill: 'radial-gradient' }>,\n): GradientUV {\n // The floor is `gradFill`'s own `max(u_gradRadius, 0.0001)`.\n const k = 1 / Math.max(fill.radius, 1e-4);\n return {\n ux: g[0] * k, uy: g[3] * k, u0: (g[6] - fill.center.x) * k,\n vx: g[1] * k, vy: g[4] * k, v0: (g[7] - fill.center.y) * k,\n };\n}\n\n/**\n * The gradient-space point about the center, turned by `-angle` so the shader's\n * half is an `atan` of it and nothing else.\n *\n * `gradFill` subtracts the angle from the arctangent instead. The two agree\n * because rotating a point turns its arctangent by the same amount, and the\n * `fract` that follows takes care of the wrap either way.\n */\nfunction conicRampUV(\n g: GlMat3, fill: Extract<FillStyle, { fill: 'conic-gradient' }>,\n): GradientUV {\n const cos = Math.cos(fill.angle);\n const sin = Math.sin(fill.angle);\n const dx0 = g[6] - fill.center.x;\n const dy0 = g[7] - fill.center.y;\n return {\n ux: cos * g[0] + sin * g[1],\n uy: cos * g[3] + sin * g[4],\n u0: cos * dx0 + sin * dy0,\n vx: cos * g[1] - sin * g[0],\n vy: cos * g[4] - sin * g[3],\n v0: cos * dy0 - sin * dx0,\n };\n}\n\n/**\n * What a gradient's vertices carry once its row is known.\n *\n * A linear gradient's `a_uv` is (ramp position, row) and its `a_post` is the\n * plain 1, because that is what the plain paint mode already samples. A radial\n * or conic one needs both `a_uv` channels for its coordinate, so its row goes\n * in `a_post` — which no gradient uses for alpha, its opacity riding the vertex\n * color instead.\n */\nexport function rampVertices(\n paint: Extract<BatchPaint, { kind: 'ramp' }>, rowV: number,\n): { uv: GradientUV; post: number } {\n return paint.mode === PAINT_MODE_PLAIN\n ? { uv: { ...paint.uv, v0: rowV }, post: 1 }\n : { uv: paint.uv, post: rowV };\n}\n\n/**\n * Screen→gradient-space matrix for `u_worldInv`, which the vertex shader\n * applies to each fragment's screen position to recover the coordinates the\n * gradient's geometry is expressed in.\n *\n * `'world'` silently degrades to screen space when no view matrix reached\n * the renderer — `render(commands)` without a view is a supported call, and\n * a missing view is not worth a thrown frame. `null` when the space has no\n * inverse; a paint measured in it draws nothing.\n */\nexport function gradientSpaceInverse(ctx: DrawContext, units: GradientUnits | undefined): GlMat3 | null {\n if (units === 'local') return mat3.invert(ctx.state.transform);\n if (units === 'world' && ctx.viewMatrix) return mat3.invert(ctx.viewMatrix);\n return mat3.identity();\n}\n\n/** The paint space `units` names → device pixels: the forward transform\n * `gradientSpaceInverse` undoes, scaled by the target's pixel ratio. */\nexport function spaceToDevice(ctx: DrawContext, units: GradientUnits | undefined): GlMat3 | null {\n const inverse = gradientSpaceInverse(ctx, units);\n const toScreen = inverse && mat3.invert(inverse);\n if (!toScreen) return null;\n const ratio = ctx.deviceWidth && ctx.widthCss > 0 ? ctx.deviceWidth / ctx.widthCss : 1;\n return mat3.multiply(mat3.scaled(mat3.identity(), ratio, ratio), toScreen);\n}\n"],"mappings":";;;AA8BA,SAAgBA,EACd,GAAkB,GAAiB,GACJ;CAC/B,IAAIC,GAAY;CAChB,IAAMC,IAAOC,EAAK,QAAQ;CAC1B,IAAID,MAAS,SAAS;EACpB,IAAME,IAAQD;EACd,OAAO;GAAE,MAAM;GAAS,OAAOC,EAAM;GAAO,SAASA,EAAM;EAAQ;CACrE;CACA,IAAIF,MAAS,qBAAqBA,MAAS,qBAAqBA,MAAS,kBACvE;CAEF,IAAMG,IAAOF,GACPG,IAAIC,EAAYC,GAAKH,EAAK,KAAK;CAIrC,OAHKC,IACDD,EAAK,SAAS,oBAA0BI,EAAKJ,GAAMK,GAAkBC,EAAaL,GAAGD,CAAI,CAAC,IAC1FA,EAAK,SAAS,oBAA0BI,EAAKJ,GAAMO,GAAmBC,EAAaP,GAAGD,CAAI,CAAC,IACxFI,EAAKJ,GAAMS,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KAAK,GACzBuB,IAAMpB,EAAE,KAAKH,EAAK,OAAO,GACzBwB,IAAMrB,EAAE,KAAKH,EAAK,OAAO;CAC/B,OAAO;EACL,IAAIqB,IAAMlB,EAAE,KAAKmB,IAAMnB,EAAE;EACzB,IAAIkB,IAAMlB,EAAE,KAAKmB,IAAMnB,EAAE;EACzB,IAAIkB,IAAME,IAAMD,IAAME;EACtB,IAAIH,IAAMlB,EAAE,KAAKmB,IAAMnB,EAAE;EACzB,IAAIkB,IAAMlB,EAAE,KAAKmB,IAAMnB,EAAE;EACzB,IAAIkB,IAAMG,IAAMF,IAAMC;CACxB;AACF;AAWA,SAAgBE,EACd,GAA8C,GACZ;CAClC,OAAOC,EAAM,SAASnB,IAClB;EAAE,IAAI;GAAE,GAAGmB,EAAM;GAAI,IAAIC;EAAK;EAAG,MAAM;CAAE,IACzC;EAAE,IAAID,EAAM;EAAI,MAAMC;CAAK;AACjC;AAYA,SAAgBb,EAAqB,GAAkB,GAAiD;CAGtG,OAFIC,MAAU,UAAgBC,EAAK,OAAOX,EAAI,MAAM,SAAS,IACzDU,MAAU,WAAWV,EAAI,aAAmBW,EAAK,OAAOX,EAAI,UAAU,IACnEW,EAAK,SAAS;AACvB;AAIA,SAAgBY,EAAc,GAAkB,GAAiD;CAC/F,IAAMf,IAAUC,EAAqBT,GAAKU,CAAK,GACzCc,IAAWhB,KAAWG,EAAK,OAAOH,CAAO;CAC/C,IAAI,CAACgB,GAAU,OAAO;CACtB,IAAMC,IAAQzB,EAAI,eAAeA,EAAI,WAAW,IAAIA,EAAI,cAAcA,EAAI,WAAW;CACrF,OAAOW,EAAK,SAASA,EAAK,OAAOA,EAAK,SAAS,GAAGc,GAAOA,CAAK,GAAGD,CAAQ;AAC3E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { flushBatch as e } from "./flushBatch.js";
|
|
2
|
+
import { enterUncut as t, leaveUncut as n, retryUncut as r } from "./clip.js";
|
|
3
|
+
import { stageImage as i } from "./batch.js";
|
|
4
|
+
import { SPRITE_STRIDE as a } from "../DrawCommand.js";
|
|
5
|
+
//#region src/renderer/draw/image.ts
|
|
6
|
+
function o(e, t) {
|
|
7
|
+
e.imageCache.upload(t.image, t.image);
|
|
8
|
+
let { staged: n, slot: a } = i(e, t.image, t.sampling ?? "linear"), s = t.source, c = 0, l = 0, u = 1, d = 1;
|
|
9
|
+
if (s) {
|
|
10
|
+
let e = t.image.width, n = t.image.height;
|
|
11
|
+
c = s.x / e, u = (s.x + s.w) / e, l = s.y / n, d = (s.y + s.h) / n;
|
|
12
|
+
}
|
|
13
|
+
if (t.flipX) {
|
|
14
|
+
let e = c;
|
|
15
|
+
c = u, u = e;
|
|
16
|
+
}
|
|
17
|
+
if (t.flipY) {
|
|
18
|
+
let e = l;
|
|
19
|
+
l = d, d = e;
|
|
20
|
+
}
|
|
21
|
+
e.drawBatch.pushQuad(t.x, t.y, t.w, t.h, e.state.transform, c, l, u, d, (t.opacity ?? 1) * (n.foldsAlpha ? e.state.alpha : 1), a) || r(e, t, void 0, o);
|
|
22
|
+
}
|
|
23
|
+
function s(r, o) {
|
|
24
|
+
let s = o.sprites, c = Math.floor(s.length / a);
|
|
25
|
+
if (c === 0) return;
|
|
26
|
+
r.imageCache.upload(o.image, o.image);
|
|
27
|
+
let l = o.sampling ?? "linear", { staged: u, slot: d } = i(r, o.image, l), f = r.drawBatch, p = r.state.transform, m = u.foldsAlpha ? r.state.alpha : 1, h = o.image.width, g = o.image.height;
|
|
28
|
+
for (let _ = 0, v = 0; _ < c; _++, v += a) {
|
|
29
|
+
f.wouldOverflow(4) && (e(r), {staged: u, slot: d} = i(r, o.image, l), m = u.foldsAlpha ? r.state.alpha : 1);
|
|
30
|
+
let a = s[v + 4], c = s[v + 5], _ = s[v + 6], y = s[v + 7], b;
|
|
31
|
+
for (; !f.pushQuad(s[v], s[v + 1], s[v + 2], s[v + 3], p, a / h, c / g, (a + _) / h, (c + y) / g, s[v + 8] * m, d);) b = t(r), {staged: u, slot: d} = i(r, o.image, l), m = u.foldsAlpha ? r.state.alpha : 1;
|
|
32
|
+
b !== void 0 && (n(r, b), {staged: u, slot: d} = i(r, o.image, l), m = u.foldsAlpha ? r.state.alpha : 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { o as drawImage, s as drawSprites };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","names":["drawImage","cmd","stageImage","ctx","src","u0","v0","u1","v1","tw","th","t","staged","slot","retryUncut","drawSprites","data","count","SPRITE_STRIDE","sampling","batch","m","groupAlpha","s","i","flushBatch","sx","sy","sw","sh","cut","enterUncut","leaveUncut"],"sources":["../../../src/renderer/draw/image.ts"],"sourcesContent":["import { type ImageDrawCommand, type SpritesDrawCommand, SPRITE_STRIDE } from '../DrawCommand';\nimport type { ClipRect } from '../batchClip';\nimport type { DrawContext } from './drawContext';\nimport { enterUncut, leaveUncut, retryUncut } from './clip';\nimport { flushBatch } from './flushBatch';\nimport { stageImage } from './batch';\n\n/**\n * Stage one image quad. Nothing reaches the GPU here — `flushBatch` draws the\n * run this joins.\n *\n * The upload has to happen now rather than at flush: a run is keyed on bitmap\n * identity, and `flushBatch` binds a texture it assumes already exists.\n */\nexport function drawImage(ctx: DrawContext, cmd: ImageDrawCommand): void {\n ctx.imageCache.upload(cmd.image, cmd.image);\n const { staged, slot } = stageImage(ctx, cmd.image, cmd.sampling ?? 'linear');\n\n // Sampling window: the whole bitmap unless `source` narrows it, with the\n // flips applied by swapping the ends rather than moving the quad.\n const src = cmd.source;\n let u0 = 0, v0 = 0, u1 = 1, v1 = 1;\n if (src) {\n const tw = cmd.image.width, th = cmd.image.height;\n u0 = src.x / tw; u1 = (src.x + src.w) / tw;\n v0 = src.y / th; v1 = (src.y + src.h) / th;\n }\n if (cmd.flipX) { const t = u0; u0 = u1; u1 = t; }\n if (cmd.flipY) { const t = v0; v0 = v1; v1 = t; }\n\n if (!ctx.drawBatch.pushQuad(\n cmd.x, cmd.y, cmd.w, cmd.h, ctx.state.transform,\n u0, v0, u1, v1,\n // Group alpha rides the vertices only where it rode the solid colors too:\n // with a real color matrix in the run it is `u_alpha`, and folding it here\n // as well would apply it twice.\n (cmd.opacity ?? 1) * (staged.foldsAlpha ? ctx.state.alpha : 1),\n slot,\n )) retryUncut(ctx, cmd, undefined, drawImage);\n}\n\n/**\n * Stage a packed run of sprites. The same staging `drawImage` does, minus a\n * command object per quad — see `SpritesDrawCommand`.\n *\n * The run is opened once and reopened only when the per-flush cap forces a\n * chunk, so the state check that costs a command its own run happens twice in\n * a frame rather than twenty thousand times.\n */\nexport function drawSprites(ctx: DrawContext, cmd: SpritesDrawCommand): void {\n const data = cmd.sprites;\n const count = Math.floor(data.length / SPRITE_STRIDE);\n if (count === 0) return;\n\n ctx.imageCache.upload(cmd.image, cmd.image);\n const sampling = cmd.sampling ?? 'linear';\n let { staged, slot } = stageImage(ctx, cmd.image, sampling);\n\n const batch = ctx.drawBatch;\n const m = ctx.state.transform;\n let groupAlpha = staged.foldsAlpha ? ctx.state.alpha : 1;\n const tw = cmd.image.width;\n const th = cmd.image.height;\n\n for (let s = 0, i = 0; s < count; s++, i += SPRITE_STRIDE) {\n if (batch.wouldOverflow(4)) {\n flushBatch(ctx);\n ({ staged, slot } = stageImage(ctx, cmd.image, sampling));\n groupAlpha = staged.foldsAlpha ? ctx.state.alpha : 1;\n }\n const sx = data[i + 4], sy = data[i + 5], sw = data[i + 6], sh = data[i + 7];\n let cut: ClipRect | null | undefined;\n while (!batch.pushQuad(\n data[i], data[i + 1], data[i + 2], data[i + 3], m,\n sx / tw, sy / th, (sx + sw) / tw, (sy + sh) / th,\n data[i + 8] * groupAlpha, slot,\n )) {\n cut = enterUncut(ctx);\n ({ staged, slot } = stageImage(ctx, cmd.image, sampling));\n groupAlpha = staged.foldsAlpha ? ctx.state.alpha : 1;\n }\n if (cut !== undefined) {\n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derer/draw/mesh.ts
|
|
4
|
+
function n(n, r) {
|
|
5
|
+
return n.flattenTolerance === void 0 ? e(r) : t(r, { flattenTolerance: n.flattenTolerance });
|
|
6
|
+
}
|
|
7
|
+
function r(e, t) {
|
|
8
|
+
return e.flattenTolerance === void 0 ? e.meshCache.handleFor(t) : e.meshCache.uploadTransient(t);
|
|
9
|
+
}
|
|
10
|
+
function i(e, t) {
|
|
11
|
+
return r(e, n(e, t));
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { n as fillMesh, i as fillMeshHandle, r as meshHandle };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=mesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.js","names":["fillMesh","ctx","getMesh","path","tessellate","meshHandle","mesh","fillMeshHandle"],"sources":["../../../src/renderer/draw/mesh.ts"],"sourcesContent":["import type { Path } from '@weasel-js/geom';\nimport type { GLMeshHandle } from '../cache/GLMeshCache';\nimport { getMesh } from '../cache/cache';\nimport { tessellate, type Mesh } from '@weasel-js/geom/tessellate';\nimport type { DrawContext } from './drawContext';\n\n/**\n * Tessellate a fill honoring ctx.flattenTolerance: default route is the\n * persistent Path-identity cache; a custom tolerance tessellates fresh, because\n * the persistent cache's key does not include tolerance.\n */\nexport function fillMesh(ctx: DrawContext, path: Path): Mesh {\n if (ctx.flattenTolerance !== undefined) {\n return tessellate(path, { flattenTolerance: ctx.flattenTolerance });\n }\n return getMesh(path);\n}\n\n/** Upload a mesh for its own draw. A freshly tessellated one rides the\n * transient pool, freed at end of frame. */\nexport function meshHandle(ctx: DrawContext, mesh: Mesh): GLMeshHandle {\n if (ctx.flattenTolerance !== undefined) return ctx.meshCache.uploadTransient(mesh);\n return ctx.meshCache.handleFor(mesh);\n}\n\nexport function fillMeshHandle(ctx: DrawContext, path: Path): GLMeshHandle {\n return meshHandle(ctx, fillMesh(ctx, path));\n}\n"],"mappings":";;;AAWA,SAAgBA,EAAS,GAAkB,GAAkB;CAI3D,OAHIC,EAAI,qBAAqB,KAAA,IAGtBC,EAAQC,CAAI,IAFVC,EAAWD,GAAM,EAAE,kBAAkBF,EAAI,iBAAiB,CAAC;AAGtE;AAIA,SAAgBI,EAAW,GAAkB,GAA0B;CAErE,OADIJ,EAAI,qBAAqB,KAAA,IACtBA,EAAI,UAAU,UAAUK,CAAI,IADYL,EAAI,UAAU,gBAAgBK,CAAI;AAEnF;AAEA,SAAgBC,EAAe,GAAkB,GAA0B;CACzE,OAAOF,EAAWJ,GAAKD,EAASC,GAAKE,CAAI,CAAC;AAC5C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createPaintResources as e } from "../paintResources.js";
|
|
2
|
+
import { getTexture as t } from "../textures/registerTexture.js";
|
|
3
|
+
import { mat3 as n } from "../math/mat3.js";
|
|
4
|
+
import { setAlphaUniform as r, setColorMatrixUniforms as i, setProjAndModel as a } from "./uniforms.js";
|
|
5
|
+
import { gradientSpaceInverse as o, spaceToDevice as s } from "./gradient.js";
|
|
6
|
+
import { patternTileSpace as c } from "../math/patternSpace.js";
|
|
7
|
+
//#region src/renderer/draw/paintBind.ts
|
|
8
|
+
function l(e) {
|
|
9
|
+
let t = u.get(e);
|
|
10
|
+
if (t) return t;
|
|
11
|
+
let n = {
|
|
12
|
+
gl: e.gl,
|
|
13
|
+
get alpha() {
|
|
14
|
+
return e.state.alpha;
|
|
15
|
+
},
|
|
16
|
+
program: (t) => e.ensureProgram?.(t) ?? e.programRegistry.get(t) ?? null,
|
|
17
|
+
setProjAndModel: (t) => a(e, t),
|
|
18
|
+
spaceInverse: (t) => o(e, t),
|
|
19
|
+
spaceToDevice: (t) => s(e, t),
|
|
20
|
+
get maxTextureSize() {
|
|
21
|
+
return e.imageCache.maxTextureSide;
|
|
22
|
+
},
|
|
23
|
+
resources: e.paintResources ?? f(e.gl),
|
|
24
|
+
bindRamp: (t, n, r) => {
|
|
25
|
+
let i = e.gradRamps.upload(t, r);
|
|
26
|
+
return e.gradRamps.bind(n), e.gradRamps.rowV(i);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return u.set(e, n), n;
|
|
30
|
+
}
|
|
31
|
+
var u = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
function f(t) {
|
|
33
|
+
let n = d.get(t);
|
|
34
|
+
return n || (n = e(), d.set(t, n)), n;
|
|
35
|
+
}
|
|
36
|
+
function p(e, s, l, u) {
|
|
37
|
+
let d = l.pattern, f = t(d.id);
|
|
38
|
+
if (!f) return (typeof process > "u" || process.env.NODE_ENV !== "production") && console.warn(`weasel: pattern TextureHandle "${d.id}" not registered`), null;
|
|
39
|
+
let p = o(e, l.units);
|
|
40
|
+
if (!p) return null;
|
|
41
|
+
let h = c(p, l.origin ?? {
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0
|
|
44
|
+
}, l.transform);
|
|
45
|
+
if (!h) return null;
|
|
46
|
+
e.textureCache.uploadRegistered(d.id, f.source, "repeat");
|
|
47
|
+
let g = e.gl;
|
|
48
|
+
g.useProgram(s.handle), a(e, s, u), i(e, s), g.uniformMatrix3fv(s.uniform("u_worldInv"), !1, n.toUniform(h));
|
|
49
|
+
let [_, v] = m(f.source);
|
|
50
|
+
return g.uniform2f(s.uniform("u_tileSize"), _, v), e.textureCache.bind(d.id, 0), g.uniform1i(s.uniform("u_sampler"), 0), g.uniform1f(s.uniform("u_opacity"), l.opacity ?? 1), r(e, s, e.state.alpha), s;
|
|
51
|
+
}
|
|
52
|
+
function m(e) {
|
|
53
|
+
let t = "naturalWidth" in e ? e.naturalWidth : e.width, n = "naturalHeight" in e ? e.naturalHeight : e.height;
|
|
54
|
+
return [t || 1, n || 1];
|
|
55
|
+
}
|
|
56
|
+
function h(e, t, s, c) {
|
|
57
|
+
let l = o(e, s.units);
|
|
58
|
+
if (!l) return null;
|
|
59
|
+
let u = e.gl, d = e.gradRamps.upload(s.stops, s.interpolate ?? "rgb");
|
|
60
|
+
if (u.useProgram(t.handle), a(e, t, c), u.uniformMatrix3fv(t.uniform("u_worldInv"), !1, n.toUniform(l)), i(e, t), e.gradRamps.bind(0), u.uniform1i(t.uniform("u_ramp"), 0), u.uniform1f(t.uniform("u_rampV"), e.gradRamps.rowV(d)), r(e, t, e.state.alpha), u.uniform1f(t.uniform("u_opacity"), s.opacity ?? 1), s.fill === "linear-gradient") {
|
|
61
|
+
u.uniform1i(t.uniform("u_gradKind"), 0);
|
|
62
|
+
let e = s.to.x - s.from.x, n = s.to.y - s.from.y, r = Math.hypot(e, n) || 1;
|
|
63
|
+
u.uniform2f(t.uniform("u_gradP0"), s.from.x, s.from.y), u.uniform2f(t.uniform("u_gradDir"), e / r, n / r), u.uniform1f(t.uniform("u_gradLen"), r), u.uniform1f(t.uniform("u_gradRadius"), 0), u.uniform1f(t.uniform("u_gradAngle"), 0);
|
|
64
|
+
} else s.fill === "radial-gradient" ? (u.uniform1i(t.uniform("u_gradKind"), 1), u.uniform2f(t.uniform("u_gradP0"), s.center.x, s.center.y), u.uniform2f(t.uniform("u_gradDir"), 0, 0), u.uniform1f(t.uniform("u_gradLen"), 0), u.uniform1f(t.uniform("u_gradRadius"), s.radius), u.uniform1f(t.uniform("u_gradAngle"), 0)) : (u.uniform1i(t.uniform("u_gradKind"), 2), u.uniform2f(t.uniform("u_gradP0"), s.center.x, s.center.y), u.uniform2f(t.uniform("u_gradDir"), 0, 0), u.uniform1f(t.uniform("u_gradLen"), 0), u.uniform1f(t.uniform("u_gradRadius"), 0), u.uniform1f(t.uniform("u_gradAngle"), s.angle));
|
|
65
|
+
return t;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { h as bindGradient, p as bindPattern, l as paintBindContext };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=paintBind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paintBind.js","names":["paintBindContext","cached","BIND_CONTEXTS","ctx","made","id","setProjAndModel","prog","gradientSpaceInverse","units","spaceToDevice","unownedPaintResources","row","stops","space","unit","UNOWNED_RESOURCES","gl","createPaintResources","bindPattern","tex","fill","entry","getTexture","inverse","tileSpace","patternTileSpace","model","setColorMatrixUniforms","mat3","tw","th","textureSize","setAlphaUniform","w","source","h","bindGradient","dx","dy","len"],"sources":["../../../src/renderer/draw/paintBind.ts"],"sourcesContent":["import type { FillStyle } from '@weasel-js/paint';\nimport type { PaintBindContext, PaintResources } from 'core/paintKinds';\nimport { createPaintResources } from '../paintResources';\nimport { getTexture, type TextureHandle } from '../textures/registerTexture';\nimport type { ShaderProgram } from '../shaders/ShaderProgram';\nimport { mat3, type GlMat3 } from '../math/mat3';\nimport { patternTileSpace } from '../math/patternSpace';\nimport type { DrawContext } from './drawContext';\nimport { setAlphaUniform, setColorMatrixUniforms, setProjAndModel } from './uniforms';\nimport { gradientSpaceInverse, spaceToDevice } from './gradient';\n\n/** The narrow renderer surface a registered paint kind binds against, built\n * once per frame context. `DrawContext` is not consumer surface. */\nexport function paintBindContext(ctx: DrawContext): PaintBindContext {\n const cached = BIND_CONTEXTS.get(ctx);\n if (cached) return cached;\n const made: PaintBindContext = {\n gl: ctx.gl,\n get alpha() { return ctx.state.alpha; },\n program: (id) => ctx.ensureProgram?.(id) ?? ctx.programRegistry.get(id) ?? null,\n setProjAndModel: (prog) => setProjAndModel(ctx, prog),\n spaceInverse: (units) => gradientSpaceInverse(ctx, units),\n spaceToDevice: (units) => spaceToDevice(ctx, units),\n get maxTextureSize() { return ctx.imageCache.maxTextureSide; },\n resources: ctx.paintResources ?? unownedPaintResources(ctx.gl),\n bindRamp: (stops, unit, space) => {\n const row = ctx.gradRamps.upload(stops, space);\n ctx.gradRamps.bind(unit);\n return ctx.gradRamps.rowV(row);\n },\n };\n BIND_CONTEXTS.set(ctx, made);\n return made;\n}\n\nconst BIND_CONTEXTS = new WeakMap<DrawContext, PaintBindContext>();\n\nconst UNOWNED_RESOURCES = new WeakMap<WebGL2RenderingContext, PaintResources>();\n\nfunction unownedPaintResources(gl: WebGL2RenderingContext): PaintResources {\n let made = UNOWNED_RESOURCES.get(gl);\n if (!made) {\n made = createPaintResources();\n UNOWNED_RESOURCES.set(gl, made);\n }\n return made;\n}\n\n/** Bind `prog` — the path program or the glyph one, which share every paint\n * uniform — to draw `fill` under `model`. */\nexport function bindPattern(\n ctx: DrawContext,\n prog: ShaderProgram,\n fill: Extract<FillStyle, { fill: 'pattern' }>,\n model: GlMat3,\n): ShaderProgram | null {\n const tex = fill.pattern as TextureHandle;\n const entry = getTexture(tex.id);\n if (!entry) {\n const isDev = typeof process !== 'undefined' ? process.env.NODE_ENV !== 'production' : true;\n if (isDev) console.warn(`weasel: pattern TextureHandle \"${tex.id}\" not registered`);\n return null;\n }\n const inverse = gradientSpaceInverse(ctx, fill.units);\n if (!inverse) return null;\n const tileSpace = patternTileSpace(inverse, fill.origin ?? { x: 0, y: 0 }, fill.transform);\n if (!tileSpace) return null;\n ctx.textureCache.uploadRegistered(tex.id, entry.source, 'repeat');\n\n // A path fill mesh carries a_position only, so the tile coordinate is\n // recovered per fragment from the screen position — the same route\n // gradients take through `u_worldInv`, and the reason this can't reuse\n // the image-fill shader, whose a_uv such a mesh leaves unbound.\n const gl = ctx.gl;\n gl.useProgram(prog.handle);\n setProjAndModel(ctx, prog, model);\n setColorMatrixUniforms(ctx, prog);\n gl.uniformMatrix3fv(prog.uniform('u_worldInv')!, false, mat3.toUniform(tileSpace));\n const [tw, th] = textureSize(entry.source);\n gl.uniform2f(prog.uniform('u_tileSize')!, tw, th);\n ctx.textureCache.bind(tex.id, 0);\n gl.uniform1i(prog.uniform('u_sampler')!, 0);\n gl.uniform1f(prog.uniform('u_opacity')!, fill.opacity ?? 1);\n setAlphaUniform(ctx, prog, ctx.state.alpha);\n return prog;\n}\n\n/** Tile extent in paint-space units — one tile spans this many units of\n * whatever space `units` names. */\nfunction textureSize(source: HTMLImageElement | ImageBitmap): [number, number] {\n const w = 'naturalWidth' in source ? source.naturalWidth : source.width;\n const h = 'naturalHeight' in source ? source.naturalHeight : source.height;\n return [w || 1, h || 1];\n}\n\n/** The gradient counterpart of `bindPattern`. */\nexport function bindGradient(\n ctx: DrawContext,\n prog: ShaderProgram,\n fill: Extract<FillStyle, { fill: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }>,\n model: GlMat3,\n): ShaderProgram | null {\n const inverse = gradientSpaceInverse(ctx, fill.units);\n if (!inverse) return null;\n const gl = ctx.gl;\n const row = ctx.gradRamps.upload(fill.stops, fill.interpolate ?? 'rgb');\n\n gl.useProgram(prog.handle);\n setProjAndModel(ctx, prog, model);\n\n gl.uniformMatrix3fv(prog.uniform('u_worldInv')!, false, mat3.toUniform(inverse));\n setColorMatrixUniforms(ctx, prog);\n\n ctx.gradRamps.bind(0);\n gl.uniform1i(prog.uniform('u_ramp')!, 0);\n gl.uniform1f(prog.uniform('u_rampV')!, ctx.gradRamps.rowV(row));\n setAlphaUniform(ctx, prog, ctx.state.alpha);\n gl.uniform1f(prog.uniform('u_opacity')!, fill.opacity ?? 1);\n\n if (fill.fill === 'linear-gradient') {\n gl.uniform1i(prog.uniform('u_gradKind')!, 0);\n const dx = fill.to.x - fill.from.x;\n const dy = fill.to.y - fill.from.y;\n const len = Math.hypot(dx, dy) || 1;\n gl.uniform2f(prog.uniform('u_gradP0')!, fill.from.x, fill.from.y);\n gl.uniform2f(prog.uniform('u_gradDir')!, dx / len, dy / len);\n gl.uniform1f(prog.uniform('u_gradLen')!, len);\n gl.uniform1f(prog.uniform('u_gradRadius')!, 0);\n gl.uniform1f(prog.uniform('u_gradAngle')!, 0);\n } else if (fill.fill === 'radial-gradient') {\n gl.uniform1i(prog.uniform('u_gradKind')!, 1);\n gl.uniform2f(prog.uniform('u_gradP0')!, fill.center.x, fill.center.y);\n gl.uniform2f(prog.uniform('u_gradDir')!, 0, 0);\n gl.uniform1f(prog.uniform('u_gradLen')!, 0);\n gl.uniform1f(prog.uniform('u_gradRadius')!, fill.radius);\n gl.uniform1f(prog.uniform('u_gradAngle')!, 0);\n } else {\n // conic\n gl.uniform1i(prog.uniform('u_gradKind')!, 2);\n gl.uniform2f(prog.uniform('u_gradP0')!, fill.center.x, fill.center.y);\n gl.uniform2f(prog.uniform('u_gradDir')!, 0, 0);\n gl.uniform1f(prog.uniform('u_gradLen')!, 0);\n gl.uniform1f(prog.uniform('u_gradRadius')!, 0);\n gl.uniform1f(prog.uniform('u_gradAngle')!, fill.angle);\n }\n\n return prog;\n}\n"],"mappings":";;;;;;;AAaA,SAAgBA,EAAiB,GAAoC;CACnE,IAAMC,IAASC,EAAc,IAAIC,CAAG;CACpC,IAAIF,GAAQ,OAAOA;CACnB,IAAMG,IAAyB;EAC7B,IAAID,EAAI;EACR,IAAI,QAAQ;GAAE,OAAOA,EAAI,MAAM;EAAO;EACtC,UAAU,MAAOA,EAAI,gBAAgBE,CAAE,KAAKF,EAAI,gBAAgB,IAAIE,CAAE,KAAK;EAC3E,kBAAkB,MAASC,EAAgBH,GAAKI,CAAI;EACpD,eAAe,MAAUC,EAAqBL,GAAKM,CAAK;EACxD,gBAAgB,MAAUC,EAAcP,GAAKM,CAAK;EAClD,IAAI,iBAAiB;GAAE,OAAON,EAAI,WAAW;EAAgB;EAC7D,WAAWA,EAAI,kBAAkBQ,EAAsBR,EAAI,EAAE;EAC7D,WAAW,GAAO,GAAM,MAAU;GAChC,IAAMS,IAAMT,EAAI,UAAU,OAAOU,GAAOC,CAAK;GAE7C,OADAX,EAAI,UAAU,KAAKY,CAAI,GAChBZ,EAAI,UAAU,KAAKS,CAAG;EAC/B;CACF;CAEA,OADAV,EAAc,IAAIC,GAAKC,CAAI,GACpBA;AACT;AAEA,IAAMF,oBAAgB,IAAI,QAAuC,GAE3Dc,oBAAoB,IAAI,QAAgD;AAE9E,SAASL,EAAsB,GAA4C;CACzE,IAAIP,IAAOY,EAAkB,IAAIC,CAAE;CAKnC,OAJKb,MACH,IAAOc,EAAqB,GAC5BF,EAAkB,IAAIC,GAAIb,CAAI,IAE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UAAUV,EAAK,QAAQ,aAAa,GAAI,CAAC;CAC9C,OAAO,AAAIc,EAAK,SAAS,qBACvBJ,EAAG,UAAUV,EAAK,QAAQ,YAAY,GAAI,CAAC,GAC3CU,EAAG,UAAUV,EAAK,QAAQ,UAAU,GAAIc,EAAK,OAAO,GAAGA,EAAK,OAAO,CAAC,GACpEJ,EAAG,UAAUV,EAAK,QAAQ,WAAW,GAAI,GAAG,CAAC,GAC7CU,EAAG,UAAUV,EAAK,QAAQ,WAAW,GAAI,CAAC,GAC1CU,EAAG,UAAUV,EAAK,QAAQ,cAAc,GAAIc,EAAK,MAAM,GACvDJ,EAAG,UAAUV,EAAK,QAAQ,aAAa,GAAI,CAAC,MAG5CU,EAAG,UAAUV,EAAK,QAAQ,YAAY,GAAI,CAAC,GAC3CU,EAAG,UAAUV,EAAK,QAAQ,UAAU,GAAIc,EAAK,OAAO,GAAGA,EAAK,OAAO,CAAC,GACpEJ,EAAG,UAAUV,EAAK,QAAQ,WAAW,GAAI,GAAG,CAAC,GAC7CU,EAAG,UAAUV,EAAK,QAAQ,WAAW,GAAI,CAAC,GAC1CU,EAAG,UAAUV,EAAK,QAAQ,cAAc,GAAI,CAAC,GAC7CU,EAAG,UAAUV,EAAK,QAAQ,aAAa,GAAIc,EAAK,KAAK;CAGvD,OAAOd;AACT"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { drawTriangles as e } from "./drawTriangles.js";
|
|
2
|
+
import { ancestorMask as t, applyClipTest as n, beginParityMask as r, endParityMask as i } from "./stencil.js";
|
|
3
|
+
import { setColorMatrixUniforms as a, setProjAndModel as o, setSolidPaintUniforms as s } from "./uniforms.js";
|
|
4
|
+
import { fillMesh as c, fillMeshHandle as l, meshHandle as u } from "./mesh.js";
|
|
5
|
+
import { flushForOwnDraw as d } from "./clip.js";
|
|
6
|
+
import { getPaintKind as f } from "../../core/paintKinds.js";
|
|
7
|
+
import { metricKeepsRects as p } from "../../features/paths/tessellate/metric.js";
|
|
8
|
+
import { resolveStrokeWidth as m } from "../../features/paths/tessellate/stroke.js";
|
|
9
|
+
import { strokeMesh as h } from "../cache/strokeMeshCache.js";
|
|
10
|
+
import { resolveStrokeLengths as g } from "../strokeLengths.js";
|
|
11
|
+
import { cachedMarkerCommands as _ } from "../cache/markerCommandCache.js";
|
|
12
|
+
import { batchPaint as v } from "./gradient.js";
|
|
13
|
+
import { pushRampRect as y, pushRect as b, tryStageFill as x } from "./batch.js";
|
|
14
|
+
import { bindGradient as S, bindPattern as C, paintBindContext as w } from "./paintBind.js";
|
|
15
|
+
//#region src/renderer/draw/pathPaint.ts
|
|
16
|
+
function T(e, t) {
|
|
17
|
+
t.fill && E(e, t), t.stroke?.paint && L(e, t);
|
|
18
|
+
}
|
|
19
|
+
function E(e, t) {
|
|
20
|
+
let n = t.fill, r = n.fill === void 0 || n.fill === "solid", i = !!(t.vertexColors && t.vertexColors.length > 0), a = n, o = v(e, n, i);
|
|
21
|
+
if (o === null) return;
|
|
22
|
+
if (o !== void 0 && t.path.kind === "rect") {
|
|
23
|
+
o.kind === "ramp" ? y(e, t.path, o) : b(e, t.path, o);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let s = c(e, t.path);
|
|
27
|
+
if (x(e, s, o)) return;
|
|
28
|
+
let l = u(e, s);
|
|
29
|
+
r && i ? A(e, t, a, l) : l.requiresStencil ? I(e, n, l) : M(e, n, l);
|
|
30
|
+
}
|
|
31
|
+
function D(e, t, n, r) {
|
|
32
|
+
let i = e.createBuffer();
|
|
33
|
+
if (!i) throw Error("attachVertexColors: createBuffer returned null");
|
|
34
|
+
e.bindBuffer(e.ARRAY_BUFFER, i), e.bufferData(e.ARRAY_BUFFER, k(n, r), e.DYNAMIC_DRAW);
|
|
35
|
+
let a = t.attribute("a_vertexColor");
|
|
36
|
+
return a !== void 0 && (e.enableVertexAttribArray(a), e.vertexAttribPointer(a, 4, e.FLOAT, !1, 0, 0)), {
|
|
37
|
+
vbo: i,
|
|
38
|
+
location: a
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function O(e, { vbo: t, location: n }) {
|
|
42
|
+
n !== void 0 && e.disableVertexAttribArray(n), e.deleteBuffer(t);
|
|
43
|
+
}
|
|
44
|
+
function k(e, t) {
|
|
45
|
+
let n = t.anchorA, r = t.anchorB, i = t.anchorT;
|
|
46
|
+
if (!n || !r || !i) return new Float32Array(e);
|
|
47
|
+
let a = n.length, o = new Float32Array(a * 4);
|
|
48
|
+
for (let t = 0; t < a; t++) {
|
|
49
|
+
let a = n[t] * 4, s = r[t] * 4, c = i[t];
|
|
50
|
+
o[t * 4 + 0] = e[a + 0] + (e[s + 0] - e[a + 0]) * c, o[t * 4 + 1] = e[a + 1] + (e[s + 1] - e[a + 1]) * c, o[t * 4 + 2] = e[a + 2] + (e[s + 2] - e[a + 2]) * c, o[t * 4 + 3] = e[a + 3] + (e[s + 3] - e[a + 3]) * c;
|
|
51
|
+
}
|
|
52
|
+
return o;
|
|
53
|
+
}
|
|
54
|
+
function A(t, c, l, u) {
|
|
55
|
+
let d = t.gl, f = t.pathFillVColor;
|
|
56
|
+
d.useProgram(f.handle), d.bindVertexArray(u.vao), o(t, f), s(t, f, l.color, l.opacity), a(t, f);
|
|
57
|
+
let p = D(d, f, c.vertexColors, u);
|
|
58
|
+
u.requiresStencil ? (r(t, u.indexCount), e(t, u.indexCount, t.gl.UNSIGNED_INT), i(t)) : (n(t), e(t, u.indexCount, t.gl.UNSIGNED_INT)), O(d, p), d.bindVertexArray(null);
|
|
59
|
+
}
|
|
60
|
+
function j(e, t) {
|
|
61
|
+
let n = t.fill ?? "solid";
|
|
62
|
+
if (n === "solid") return N(e, t);
|
|
63
|
+
if (n === "pattern") return P(e, t);
|
|
64
|
+
if (n === "linear-gradient" || n === "radial-gradient" || n === "conic-gradient") return F(e, t);
|
|
65
|
+
let r = f(n)?.bind;
|
|
66
|
+
return r ? r(w(e), t) : null;
|
|
67
|
+
}
|
|
68
|
+
function M(t, r, i) {
|
|
69
|
+
if (!j(t, r)) return;
|
|
70
|
+
let a = t.gl;
|
|
71
|
+
a.bindVertexArray(i.vao), n(t), e(t, i.indexCount, t.gl.UNSIGNED_INT), a.bindVertexArray(null);
|
|
72
|
+
}
|
|
73
|
+
function N(e, t) {
|
|
74
|
+
let n = e.pathFill;
|
|
75
|
+
return e.gl.useProgram(n.handle), o(e, n), s(e, n, t.color, t.opacity), a(e, n), n;
|
|
76
|
+
}
|
|
77
|
+
function P(e, t) {
|
|
78
|
+
return C(e, e.patternFill, t, e.state.transform);
|
|
79
|
+
}
|
|
80
|
+
function F(e, t) {
|
|
81
|
+
return S(e, e.gradFill, t, e.state.transform);
|
|
82
|
+
}
|
|
83
|
+
function I(t, n, a) {
|
|
84
|
+
let s = t.gl;
|
|
85
|
+
s.useProgram(t.pathFill.handle), s.bindVertexArray(a.vao), o(t, t.pathFill), r(t, a.indexCount), j(t, n) && e(t, a.indexCount, t.gl.UNSIGNED_INT), i(t), s.bindVertexArray(null);
|
|
86
|
+
}
|
|
87
|
+
function L(e, t) {
|
|
88
|
+
let { cmd: n, spaces: r } = g(e.state.transform, t), i = n.stroke, a = i.align ?? "center", o = r.ribbon?.metric;
|
|
89
|
+
(n.path.kind === "polygon" || o !== void 0 && !p(o)) && a !== "center" ? (d(e), V(e, n, a, r)) : R(e, n, r);
|
|
90
|
+
let s = m(i.width ?? 1, 1), c = _(n.path, t.stroke, i, s, e.flattenTolerance, r);
|
|
91
|
+
for (let t of c) T(e, t);
|
|
92
|
+
}
|
|
93
|
+
function R(t, r, i) {
|
|
94
|
+
let c = r.stroke, l = c.paint, u = l.fill === void 0 || l.fill === "solid", d = l, f = h(r.path, c, t.flattenTolerance, i);
|
|
95
|
+
if (f.indices.length === 0) return;
|
|
96
|
+
let p = !!(c.vertexColors && c.vertexColors.length > 0), m = v(t, l, p);
|
|
97
|
+
if (m === null || x(t, f, m)) return;
|
|
98
|
+
let g = p ? t.meshCache.uploadTransient(f) : t.meshCache.uploadRecurring(f);
|
|
99
|
+
if (!u && !p) {
|
|
100
|
+
M(t, l, g);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let _ = t.gl;
|
|
104
|
+
if (p) {
|
|
105
|
+
let r = t.pathFillVColor;
|
|
106
|
+
_.useProgram(r.handle), _.bindVertexArray(g.vao), o(t, r), s(t, r, u ? d.color : "#ffffff", l.opacity), a(t, r);
|
|
107
|
+
let i = D(_, r, c.vertexColors, g);
|
|
108
|
+
n(t), e(t, g.indexCount, t.gl.UNSIGNED_INT), O(_, i), _.bindVertexArray(null);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
_.useProgram(t.pathFill.handle), _.bindVertexArray(g.vao), o(t, t.pathFill), s(t, t.pathFill, d.color, d.opacity), a(t, t.pathFill), n(t), e(t, g.indexCount, t.gl.UNSIGNED_INT), _.bindVertexArray(null);
|
|
112
|
+
}
|
|
113
|
+
var z = /* @__PURE__ */ new WeakMap();
|
|
114
|
+
function B(e) {
|
|
115
|
+
let t = z.get(e);
|
|
116
|
+
return t === void 0 && (t = e.map((e) => e * 2), z.set(e, t)), t;
|
|
117
|
+
}
|
|
118
|
+
function V(n, r, i, c) {
|
|
119
|
+
let u = r.stroke, d = u.paint, f = d.fill === void 0 || d.fill === "solid", p = d, g = {
|
|
120
|
+
...u,
|
|
121
|
+
width: m(u.width ?? 1, 1) * 2,
|
|
122
|
+
...u.vertexWidths ? { vertexWidths: B(u.vertexWidths) } : {},
|
|
123
|
+
align: "center"
|
|
124
|
+
}, _ = !!(u.vertexColors && u.vertexColors.length > 0), v = l(n, r.path), y = h(r.path, g, n.flattenTolerance, c);
|
|
125
|
+
if (y.indices.length === 0) return;
|
|
126
|
+
let b = _ ? n.meshCache.uploadTransient(y) : n.meshCache.uploadRecurring(y), x = n.gl, S = _ ? n.pathFillVColor : n.pathFill;
|
|
127
|
+
x.useProgram(S.handle), o(n, S), x.enable(x.STENCIL_TEST), x.colorMask(!1, !1, !1, !1), x.stencilMask(1), x.stencilFunc(x.ALWAYS, 1, 1), x.stencilOp(x.KEEP, x.KEEP, v.requiresStencil ? x.INVERT : x.REPLACE), x.bindVertexArray(v.vao), e(n, v.indexCount, n.gl.UNSIGNED_INT);
|
|
128
|
+
let C = t(n.clipDepth);
|
|
129
|
+
x.colorMask(!0, !0, !0, !0), i === "inner" ? x.stencilFunc(x.EQUAL, C | 1, C | 1) : x.stencilFunc(x.EQUAL, C, C | 1), x.stencilOp(x.KEEP, x.KEEP, x.KEEP);
|
|
130
|
+
let w = S;
|
|
131
|
+
if (_ ? (s(n, S, f ? p.color : "#ffffff", d.opacity), a(n, S)) : w = j(n, d), !w) {
|
|
132
|
+
x.stencilMask(1), x.clear(x.STENCIL_BUFFER_BIT), x.disable(x.STENCIL_TEST), x.bindVertexArray(null);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
x.bindVertexArray(b.vao);
|
|
136
|
+
let T = _ ? D(x, w, u.vertexColors, b) : null;
|
|
137
|
+
e(n, b.indexCount, n.gl.UNSIGNED_INT), x.stencilMask(1), x.clear(x.STENCIL_BUFFER_BIT), x.disable(x.STENCIL_TEST), T && O(x, T), x.bindVertexArray(null);
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { T as drawPath, M as drawPathFillByKind };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=pathPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathPaint.js","names":["drawPath","cmd","drawPathFill","ctx","drawPathStroke","fill","isSolid","hasVColors","solid","paint","batchPaint","pushRampRect","pushRect","mesh","fillMesh","tryStageFill","handle","meshHandle","drawPathFillVColor","drawPathFillStencil","drawPathFillByKind","attachVertexColors","vbo","gl","expandAnchorColors","perAnchor","location","prog","detachVertexColors","aA","aB","aT","n","out","i","a4","b4","t","setProjAndModel","setSolidPaintUniforms","setColorMatrixUniforms","colors","beginParityMask","drawTriangles","endParityMask","applyClipTest","bindPathFillByKind","kind","bindPathFillSolid","bindPathFillPattern","bindPathFillGradient","bind","getPaintKind","paintBindContext","bindPattern","bindGradient","resolveStrokeLengths","rawCmd","stroke","align","metric","spaces","metricKeepsRects","flushForOwnDraw","drawPathStrokeStenciled","drawPathStrokeUnclipped","width","resolveStrokeWidth","heads","cachedMarkerCommands","marker","strokeMesh","batched","DOUBLED_VERTEX_WIDTHS","doubledVertexWidths","doubled","widths","w","widerStroke","useVColor","fillHandle","fillMeshHandle","ribbonMesh","ribbonHandle","clipMask","ancestorMask","ribbonProg"],"sources":["../../../src/renderer/draw/pathPaint.ts"],"sourcesContent":["import type { Stroke, FillStyle } from '@weasel-js/paint';\nimport { getPaintKind } from 'core/paintKinds';\nimport type { PathDrawCommand } from '../DrawCommand';\nimport type { GLMeshHandle } from '../cache/GLMeshCache';\nimport type { ShaderProgram } from '../shaders/ShaderProgram';\nimport { resolveStrokeWidth } from 'features/paths/tessellate/stroke';\nimport { strokeMesh } from '../cache/strokeMeshCache';\nimport { resolveStrokeLengths, type StrokedPathCommand } from '../strokeLengths';\nimport { metricKeepsRects, type StrokeSpaces } from 'features/paths/tessellate/metric';\nimport { cachedMarkerCommands } from '../cache/markerCommandCache';\nimport type { DrawContext } from './drawContext';\nimport { drawTriangles } from './drawTriangles';\nimport { fillMesh, meshHandle, fillMeshHandle } from './mesh';\nimport { setColorMatrixUniforms, setProjAndModel, setSolidPaintUniforms } from './uniforms';\nimport { applyClipTest, ancestorMask, beginParityMask, endParityMask } from './stencil';\nimport { flushForOwnDraw } from './clip';\nimport { pushRect, pushRampRect, tryStageFill } from './batch';\nimport { batchPaint } from './gradient';\nimport { paintBindContext, bindPattern, bindGradient } from './paintBind';\n\nexport function drawPath(ctx: DrawContext, cmd: PathDrawCommand): void {\n if (cmd.fill) drawPathFill(ctx, cmd);\n // A stroke with no `paint` paints nothing, the way a node's `fill: null`\n // does. Commands arriving from a consumer painter or overlay can carry one.\n if (cmd.stroke?.paint) drawPathStroke(ctx, cmd as StrokedPathCommand);\n}\n\nfunction drawPathFill(ctx: DrawContext, cmd: PathDrawCommand): void {\n const fill = cmd.fill!;\n // Batchable: see `batchPaint`. A rect skips tessellation entirely; anything\n // else stages its mesh. Both also keep animated demos that mint a fresh Path\n // every frame from allocating a GL buffer per frame.\n const isSolid = fill.fill === undefined || fill.fill === 'solid';\n const hasVColors = !!(cmd.vertexColors && cmd.vertexColors.length > 0);\n const solid = fill as { color: string; opacity?: number };\n const paint = batchPaint(ctx, fill, hasVColors);\n if (paint === null) return;\n\n if (paint !== undefined && cmd.path.kind === 'rect') {\n if (paint.kind === 'ramp') pushRampRect(ctx, cmd.path, paint);\n else pushRect(ctx, cmd.path, paint);\n return;\n }\n\n const mesh = fillMesh(ctx, cmd.path);\n if (tryStageFill(ctx, mesh, paint)) return;\n\n const handle = meshHandle(ctx, mesh);\n if (isSolid && hasVColors) {\n drawPathFillVColor(ctx, cmd, solid, handle);\n } else if (handle.requiresStencil) {\n drawPathFillStencil(ctx, fill, handle);\n } else {\n drawPathFillByKind(ctx, fill, handle);\n }\n}\n\ninterface VertexColorBinding { vbo: WebGLBuffer; location: number | undefined }\n\n/** Point the bound mesh VAO's a_vertexColor at a fresh buffer of per-vertex\n * colors. Pair with `detachVertexColors` before the VAO is unbound. */\nfunction attachVertexColors(\n gl: WebGL2RenderingContext, prog: ShaderProgram, perAnchor: number[], handle: GLMeshHandle,\n): VertexColorBinding {\n const vbo = gl.createBuffer();\n if (!vbo) throw new Error('attachVertexColors: createBuffer returned null');\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n gl.bufferData(gl.ARRAY_BUFFER, expandAnchorColors(perAnchor, handle), gl.DYNAMIC_DRAW);\n const location = prog.attribute('a_vertexColor');\n if (location !== undefined) {\n gl.enableVertexAttribArray(location);\n gl.vertexAttribPointer(location, 4, gl.FLOAT, false, 0, 0);\n }\n return { vbo, location };\n}\n\n// Order matters: a buffer deleted after its VAO is unbound stays attached to\n// that VAO and is not freed until the mesh is, and one deleted while its\n// attribute is still enabled leaves the VAO unable to draw.\nfunction detachVertexColors(gl: WebGL2RenderingContext, { vbo, location }: VertexColorBinding): void {\n if (location !== undefined) gl.disableVertexAttribArray(location);\n gl.deleteBuffer(vbo);\n}\n\nfunction expandAnchorColors(perAnchor: number[], handle: GLMeshHandle): Float32Array {\n const aA = handle.anchorA;\n const aB = handle.anchorB;\n const aT = handle.anchorT;\n if (!aA || !aB || !aT) {\n // Legacy fallback: mesh lacks anchor params (e.g. non-path mesh). Treat\n // the caller-provided array as already per-vertex.\n return new Float32Array(perAnchor);\n }\n const n = aA.length;\n const out = new Float32Array(n * 4);\n for (let i = 0; i < n; i++) {\n const a4 = aA[i] * 4;\n const b4 = aB[i] * 4;\n const t = aT[i];\n out[i * 4 + 0] = perAnchor[a4 + 0] + (perAnchor[b4 + 0] - perAnchor[a4 + 0]) * t;\n out[i * 4 + 1] = perAnchor[a4 + 1] + (perAnchor[b4 + 1] - perAnchor[a4 + 1]) * t;\n out[i * 4 + 2] = perAnchor[a4 + 2] + (perAnchor[b4 + 2] - perAnchor[a4 + 2]) * t;\n out[i * 4 + 3] = perAnchor[a4 + 3] + (perAnchor[b4 + 3] - perAnchor[a4 + 3]) * t;\n }\n return out;\n}\n\nfunction drawPathFillVColor(\n ctx: DrawContext,\n cmd: PathDrawCommand,\n fill: { color: string; opacity?: number },\n handle: GLMeshHandle,\n): void {\n const gl = ctx.gl;\n const prog = ctx.pathFillVColor;\n gl.useProgram(prog.handle);\n gl.bindVertexArray(handle.vao);\n setProjAndModel(ctx, prog);\n setSolidPaintUniforms(ctx, prog, fill.color, fill.opacity);\n setColorMatrixUniforms(ctx, prog);\n\n const colors = attachVertexColors(gl, prog, cmd.vertexColors!, handle);\n\n if (handle.requiresStencil) {\n beginParityMask(ctx, handle.indexCount);\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n endParityMask(ctx);\n } else {\n applyClipTest(ctx);\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n }\n detachVertexColors(gl, colors);\n gl.bindVertexArray(null);\n}\n\n/**\n * Bind the program, uniforms and textures for `fill`, and return the program.\n *\n * Split from the draw so a caller owning its own stencil state can paint\n * without `applyClipTest` clobbering it — `drawPathStrokeStenciled` clips a\n * doubled ribbon to one side of the silhouette, and `applyClipTest` at depth 0\n * disables the stencil test outright.\n */\nfunction bindPathFillByKind(ctx: DrawContext, fill: FillStyle): ShaderProgram | null {\n const kind = fill.fill ?? 'solid';\n if (kind === 'solid') return bindPathFillSolid(ctx, fill as { color: string; opacity?: number });\n if (kind === 'pattern') return bindPathFillPattern(ctx, fill as Extract<FillStyle, { fill: 'pattern' }>);\n if (kind === 'linear-gradient' || kind === 'radial-gradient' || kind === 'conic-gradient') {\n return bindPathFillGradient(ctx, fill as Extract<FillStyle, { fill: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }>);\n }\n const bind = getPaintKind(kind)?.bind;\n return bind ? bind(paintBindContext(ctx), fill) : null;\n}\n\nexport function drawPathFillByKind(ctx: DrawContext, fill: FillStyle, handle: GLMeshHandle): void {\n const prog = bindPathFillByKind(ctx, fill);\n if (!prog) return;\n const gl = ctx.gl;\n gl.bindVertexArray(handle.vao);\n applyClipTest(ctx);\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n gl.bindVertexArray(null);\n}\n\nfunction bindPathFillSolid(\n ctx: DrawContext,\n fill: { color: string; opacity?: number },\n): ShaderProgram {\n const prog = ctx.pathFill;\n ctx.gl.useProgram(prog.handle);\n setProjAndModel(ctx, prog);\n setSolidPaintUniforms(ctx, prog, fill.color, fill.opacity);\n setColorMatrixUniforms(ctx, prog);\n return prog;\n}\n\nfunction bindPathFillPattern(\n ctx: DrawContext,\n fill: Extract<FillStyle, { fill: 'pattern' }>,\n): ShaderProgram | null {\n return bindPattern(ctx, ctx.patternFill, fill, ctx.state.transform);\n}\n\nfunction bindPathFillGradient(\n ctx: DrawContext,\n fill: Extract<FillStyle, { fill: 'linear-gradient' | 'radial-gradient' | 'conic-gradient' }>,\n): ShaderProgram | null {\n return bindGradient(ctx, ctx.gradFill, fill, ctx.state.transform);\n}\n\nfunction drawPathFillStencil(ctx: DrawContext, fill: FillStyle, handle: GLMeshHandle): void {\n const gl = ctx.gl;\n gl.useProgram(ctx.pathFill.handle);\n gl.bindVertexArray(handle.vao);\n setProjAndModel(ctx, ctx.pathFill);\n\n beginParityMask(ctx, handle.indexCount);\n // The paint binds here, not above: pass 1 runs under a false colorMask, so a\n // uniform missed here renders black while the GL-recorder tests still pass.\n // Not `drawPathFillByKind` — its `applyClipTest` would disable this stencil.\n if (bindPathFillByKind(ctx, fill)) {\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n }\n\n endParityMask(ctx);\n gl.bindVertexArray(null);\n}\n\nfunction drawPathStroke(ctx: DrawContext, rawCmd: StrokedPathCommand): void {\n const { cmd, spaces } = resolveStrokeLengths(ctx.state.transform, rawCmd);\n const stroke = cmd.stroke;\n const align = stroke.align ?? 'center';\n const metric = spaces.ribbon?.metric;\n // A rect the metric turns is no longer a rect in the space its ribbon is\n // built in, so it aligns through the stencil like any polygon.\n const stenciled = cmd.path.kind === 'polygon' || (metric !== undefined && !metricKeepsRects(metric));\n if (stenciled && align !== 'center') {\n flushForOwnDraw(ctx);\n drawPathStrokeStenciled(ctx, cmd, align, spaces);\n } else {\n drawPathStrokeUnclipped(ctx, cmd, spaces);\n }\n // After the ribbon, so a head sits on top of the line it caps.\n const width = resolveStrokeWidth(stroke.width ?? 1, 1);\n const heads = cachedMarkerCommands(cmd.path, rawCmd.stroke, stroke, width, ctx.flattenTolerance, spaces);\n for (const marker of heads) drawPath(ctx, marker);\n}\n\nfunction drawPathStrokeUnclipped(ctx: DrawContext, cmd: StrokedPathCommand, spaces: StrokeSpaces): void {\n const stroke = cmd.stroke;\n const paint = stroke.paint;\n const isSolid = paint.fill === undefined || paint.fill === 'solid';\n const solid = paint as { color: string; opacity?: number };\n const mesh = strokeMesh(cmd.path, stroke, ctx.flattenTolerance, spaces);\n if (mesh.indices.length === 0) return;\n\n // Staged, a ribbon allocates nothing and joins the fill it sits on.\n const hasVColors = !!(stroke.vertexColors && stroke.vertexColors.length > 0);\n const batched = batchPaint(ctx, paint, hasVColors);\n if (batched === null) return;\n if (tryStageFill(ctx, mesh, batched)) return;\n\n // The VAO records the per-draw color attribute, so a vertex-colored draw\n // cannot share a persistent one with a draw that has no vertex colors.\n const handle = hasVColors\n ? ctx.meshCache.uploadTransient(mesh)\n : ctx.meshCache.uploadRecurring(mesh);\n\n if (!isSolid && !hasVColors) {\n drawPathFillByKind(ctx, paint, handle);\n return;\n }\n\n const gl = ctx.gl;\n if (hasVColors) {\n const prog = ctx.pathFillVColor;\n gl.useProgram(prog.handle);\n gl.bindVertexArray(handle.vao);\n setProjAndModel(ctx, prog);\n // Per-vertex colors are the paint here; a non-solid base has no single\n // color to multiply by, so white leaves the vertex colors unmodified.\n setSolidPaintUniforms(ctx, prog, isSolid ? solid.color : '#ffffff', paint.opacity);\n setColorMatrixUniforms(ctx, prog);\n\n const colors = attachVertexColors(gl, prog, stroke.vertexColors!, handle);\n applyClipTest(ctx);\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n detachVertexColors(gl, colors);\n gl.bindVertexArray(null);\n return;\n }\n\n gl.useProgram(ctx.pathFill.handle);\n gl.bindVertexArray(handle.vao);\n setProjAndModel(ctx, ctx.pathFill);\n setSolidPaintUniforms(ctx, ctx.pathFill, solid.color, solid.opacity);\n setColorMatrixUniforms(ctx, ctx.pathFill);\n applyClipTest(ctx);\n drawTriangles(ctx, handle.indexCount, ctx.gl.UNSIGNED_INT);\n gl.bindVertexArray(null);\n}\n\n/** The ribbon cache compares `vertexWidths` by reference, so the doubled copy\n * has to be the same array on every frame the source array is. */\nconst DOUBLED_VERTEX_WIDTHS = new WeakMap<number[], number[]>();\n\nfunction doubledVertexWidths(widths: number[]): number[] {\n let doubled = DOUBLED_VERTEX_WIDTHS.get(widths);\n if (doubled === undefined) {\n doubled = widths.map((w) => w * 2);\n DOUBLED_VERTEX_WIDTHS.set(widths, doubled);\n }\n return doubled;\n}\n\nfunction drawPathStrokeStenciled(\n ctx: DrawContext,\n cmd: StrokedPathCommand,\n align: 'inner' | 'outer',\n spaces: StrokeSpaces,\n): void {\n const stroke = cmd.stroke;\n const paint = stroke.paint;\n const isSolid = paint.fill === undefined || paint.fill === 'solid';\n const solid = paint as { color: string; opacity?: number };\n const widerStroke: Stroke = {\n ...stroke,\n width: resolveStrokeWidth(stroke.width ?? 1, 1) * 2,\n ...(stroke.vertexWidths ? { vertexWidths: doubledVertexWidths(stroke.vertexWidths) } : {}),\n align: 'center',\n };\n\n const useVColor = !!(stroke.vertexColors && stroke.vertexColors.length > 0);\n\n const fillHandle = fillMeshHandle(ctx, cmd.path);\n const ribbonMesh = strokeMesh(cmd.path, widerStroke, ctx.flattenTolerance, spaces);\n if (ribbonMesh.indices.length === 0) return;\n // The VAO records the per-draw color attribute, so a vertex-colored draw\n // cannot share a persistent one with a draw that has no vertex colors.\n const ribbonHandle = useVColor\n ? ctx.meshCache.uploadTransient(ribbonMesh)\n : ctx.meshCache.uploadRecurring(ribbonMesh);\n\n const gl = ctx.gl;\n const prog = useVColor ? ctx.pathFillVColor : ctx.pathFill;\n gl.useProgram(prog.handle);\n setProjAndModel(ctx, prog);\n\n gl.enable(gl.STENCIL_TEST);\n gl.colorMask(false, false, false, false);\n gl.stencilMask(0x01);\n gl.stencilFunc(gl.ALWAYS, 1, 0x01);\n // An even-odd fill is one fan per contour, and only parity cuts its holes.\n gl.stencilOp(gl.KEEP, gl.KEEP, fillHandle.requiresStencil ? gl.INVERT : gl.REPLACE);\n gl.bindVertexArray(fillHandle.vao);\n drawTriangles(ctx, fillHandle.indexCount, ctx.gl.UNSIGNED_INT);\n\n const clipMask = ancestorMask(ctx.clipDepth);\n gl.colorMask(true, true, true, true);\n if (align === 'inner') {\n gl.stencilFunc(gl.EQUAL, clipMask | 0x01, clipMask | 0x01);\n } else {\n gl.stencilFunc(gl.EQUAL, clipMask, clipMask | 0x01);\n }\n gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);\n // Bind the paint here rather than through `drawPathFillByKind`: that calls\n // `applyClipTest`, which at clip depth 0 disables the stencil test this\n // function just set up to clip the ribbon to one side.\n let ribbonProg: ShaderProgram | null = prog;\n if (useVColor) {\n // Per-vertex colors are the paint here; a non-solid base has no single\n // color to multiply by, so white leaves the vertex colors unmodified.\n setSolidPaintUniforms(ctx, prog, isSolid ? solid.color : '#ffffff', paint.opacity);\n setColorMatrixUniforms(ctx, prog);\n } else {\n ribbonProg = bindPathFillByKind(ctx, paint);\n }\n if (!ribbonProg) {\n gl.stencilMask(0x01);\n gl.clear(gl.STENCIL_BUFFER_BIT);\n gl.disable(gl.STENCIL_TEST);\n gl.bindVertexArray(null);\n return;\n }\n gl.bindVertexArray(ribbonHandle.vao);\n\n const colors = useVColor\n ? attachVertexColors(gl, ribbonProg, stroke.vertexColors!, ribbonHandle)\n : null;\n\n drawTriangles(ctx, ribbonHandle.indexCount, ctx.gl.UNSIGNED_INT);\n\n // Narrow to bit 0 first: clear only zeroes bits the mask enables, and\n // pushClip owns bits 1-7.\n gl.stencilMask(0x01);\n gl.clear(gl.STENCIL_BUFFER_BIT);\n gl.disable(gl.STENCIL_TEST);\n if (colors) detachVertexColors(gl, colors);\n gl.bindVertexArray(null);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgBA,EAAS,GAAkB,GAA4B;CAIrE,AAHIC,EAAI,QAAMC,EAAaC,GAAKF,CAAG,GAG/BA,EAAI,QAAQ,SAAOG,EAAeD,GAAKF,CAAyB;AACtE;AAEA,SAASC,EAAa,GAAkB,GAA4B;CAClE,IAAMG,IAAOJ,EAAI,MAIXK,IAAUD,EAAK,SAAS,KAAA,KAAaA,EAAK,SAAS,SACnDE,IAAa,CAAC,EAAEN,EAAI,gBAAgBA,EAAI,aAAa,SAAS,IAC9DO,IAAQH,GACRI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