three-stdlib 2.35.4 → 2.35.5
Sign up to get free protection for your applications and to get access to all the features.
- package/_polyfill/CapsuleGeometry.cjs +17 -20
- package/_polyfill/CapsuleGeometry.cjs.map +1 -1
- package/_polyfill/CapsuleGeometry.js +17 -20
- package/_polyfill/CapsuleGeometry.js.map +1 -1
- package/_polyfill/constants.cjs +1 -1
- package/_polyfill/constants.cjs.map +1 -1
- package/_polyfill/constants.js +1 -1
- package/_polyfill/constants.js.map +1 -1
- package/animation/AnimationClipCreator.cjs +13 -13
- package/animation/AnimationClipCreator.cjs.map +1 -1
- package/animation/AnimationClipCreator.js +13 -13
- package/animation/AnimationClipCreator.js.map +1 -1
- package/animation/CCDIKSolver.cjs +11 -11
- package/animation/CCDIKSolver.cjs.map +1 -1
- package/animation/CCDIKSolver.js +12 -12
- package/animation/CCDIKSolver.js.map +1 -1
- package/animation/MMDAnimationHelper.cjs +1 -1
- package/animation/MMDAnimationHelper.cjs.map +1 -1
- package/animation/MMDAnimationHelper.js +1 -1
- package/animation/MMDAnimationHelper.js.map +1 -1
- package/animation/MMDPhysics.cjs +4 -4
- package/animation/MMDPhysics.cjs.map +1 -1
- package/animation/MMDPhysics.js +4 -4
- package/animation/MMDPhysics.js.map +1 -1
- package/controls/ArcballControls.cjs +2 -2
- package/controls/ArcballControls.cjs.map +1 -1
- package/controls/ArcballControls.js +3 -3
- package/controls/ArcballControls.js.map +1 -1
- package/controls/FirstPersonControls.cjs +1 -1
- package/controls/FirstPersonControls.cjs.map +1 -1
- package/controls/FirstPersonControls.js +1 -1
- package/controls/FirstPersonControls.js.map +1 -1
- package/controls/OrbitControls.cjs +2 -2
- package/controls/OrbitControls.cjs.map +1 -1
- package/controls/OrbitControls.js +3 -3
- package/controls/OrbitControls.js.map +1 -1
- package/controls/PointerLockControls.cjs +2 -2
- package/controls/PointerLockControls.cjs.map +1 -1
- package/controls/PointerLockControls.js +3 -3
- package/controls/PointerLockControls.js.map +1 -1
- package/csm/CSM.cjs +4 -4
- package/csm/CSM.cjs.map +1 -1
- package/csm/CSM.js +5 -5
- package/csm/CSM.js.map +1 -1
- package/csm/CSMFrustum.cjs +1 -1
- package/csm/CSMFrustum.cjs.map +1 -1
- package/csm/CSMFrustum.js +2 -2
- package/csm/CSMFrustum.js.map +1 -1
- package/deprecated/Geometry.cjs +715 -722
- package/deprecated/Geometry.cjs.map +1 -1
- package/deprecated/Geometry.js +716 -723
- package/deprecated/Geometry.js.map +1 -1
- package/effects/AnaglyphEffect.cjs +1 -2
- package/effects/AnaglyphEffect.cjs.map +1 -1
- package/effects/AnaglyphEffect.js +2 -3
- package/effects/AnaglyphEffect.js.map +1 -1
- package/effects/OutlineEffect.cjs +1 -2
- package/effects/OutlineEffect.cjs.map +1 -1
- package/effects/OutlineEffect.js +2 -3
- package/effects/OutlineEffect.js.map +1 -1
- package/effects/ParallaxBarrierEffect.cjs +1 -2
- package/effects/ParallaxBarrierEffect.cjs.map +1 -1
- package/effects/ParallaxBarrierEffect.js +2 -3
- package/effects/ParallaxBarrierEffect.js.map +1 -1
- package/exporters/DRACOExporter.cjs +122 -133
- package/exporters/DRACOExporter.cjs.map +1 -1
- package/exporters/DRACOExporter.d.ts +21 -23
- package/exporters/DRACOExporter.js +122 -133
- package/exporters/DRACOExporter.js.map +1 -1
- package/exporters/GLTFExporter.cjs +167 -170
- package/exporters/GLTFExporter.cjs.map +1 -1
- package/exporters/GLTFExporter.js +167 -170
- package/exporters/GLTFExporter.js.map +1 -1
- package/geometries/LightningStrike.cjs +515 -524
- package/geometries/LightningStrike.cjs.map +1 -1
- package/geometries/LightningStrike.js +515 -524
- package/geometries/LightningStrike.js.map +1 -1
- package/geometries/RoundedBoxGeometry.cjs +1 -1
- package/geometries/RoundedBoxGeometry.cjs.map +1 -1
- package/geometries/RoundedBoxGeometry.js +2 -2
- package/geometries/RoundedBoxGeometry.js.map +1 -1
- package/helpers/RaycasterHelper.cjs +2 -2
- package/helpers/RaycasterHelper.cjs.map +1 -1
- package/helpers/RaycasterHelper.js +3 -3
- package/helpers/RaycasterHelper.js.map +1 -1
- package/helpers/VertexNormalsHelper.cjs +3 -3
- package/helpers/VertexNormalsHelper.cjs.map +1 -1
- package/helpers/VertexNormalsHelper.js +4 -4
- package/helpers/VertexNormalsHelper.js.map +1 -1
- package/helpers/VertexTangentsHelper.cjs +2 -2
- package/helpers/VertexTangentsHelper.cjs.map +1 -1
- package/helpers/VertexTangentsHelper.js +3 -3
- package/helpers/VertexTangentsHelper.js.map +1 -1
- package/interactive/InteractiveGroup.cjs +1 -1
- package/interactive/InteractiveGroup.cjs.map +1 -1
- package/interactive/InteractiveGroup.js +2 -2
- package/interactive/InteractiveGroup.js.map +1 -1
- package/interactive/SelectionBox.cjs +15 -15
- package/interactive/SelectionBox.cjs.map +1 -1
- package/interactive/SelectionBox.js +16 -16
- package/interactive/SelectionBox.js.map +1 -1
- package/libs/chevrotain.cjs +1 -1
- package/libs/chevrotain.cjs.map +1 -1
- package/libs/chevrotain.js +1 -1
- package/libs/chevrotain.js.map +1 -1
- package/libs/lottie.cjs +1 -1
- package/libs/lottie.cjs.map +1 -1
- package/libs/lottie.js +1 -1
- package/libs/lottie.js.map +1 -1
- package/libs/opentype.cjs +1 -1
- package/libs/opentype.cjs.map +1 -1
- package/libs/opentype.js +1 -1
- package/libs/opentype.js.map +1 -1
- package/lights/LightProbeGenerator.cjs +5 -5
- package/lights/LightProbeGenerator.cjs.map +1 -1
- package/lights/LightProbeGenerator.js +5 -5
- package/lights/LightProbeGenerator.js.map +1 -1
- package/lights/RectAreaLightUniformsLib.cjs +3 -3
- package/lights/RectAreaLightUniformsLib.cjs.map +1 -1
- package/lights/RectAreaLightUniformsLib.js +3 -3
- package/lights/RectAreaLightUniformsLib.js.map +1 -1
- package/lines/LineMaterial.cjs +1 -2
- package/lines/LineMaterial.cjs.map +1 -1
- package/lines/LineMaterial.js +2 -3
- package/lines/LineMaterial.js.map +1 -1
- package/lines/LineSegments2.cjs +13 -13
- package/lines/LineSegments2.cjs.map +1 -1
- package/lines/LineSegments2.js +14 -14
- package/lines/LineSegments2.js.map +1 -1
- package/lines/LineSegmentsGeometry.cjs +2 -2
- package/lines/LineSegmentsGeometry.cjs.map +1 -1
- package/lines/LineSegmentsGeometry.js +3 -3
- package/lines/LineSegmentsGeometry.js.map +1 -1
- package/lines/Wireframe.cjs +3 -3
- package/lines/Wireframe.cjs.map +1 -1
- package/lines/Wireframe.js +4 -4
- package/lines/Wireframe.js.map +1 -1
- package/loaders/BasisTextureLoader.cjs +435 -441
- package/loaders/BasisTextureLoader.cjs.map +1 -1
- package/loaders/BasisTextureLoader.js +435 -441
- package/loaders/BasisTextureLoader.js.map +1 -1
- package/loaders/EXRLoader.cjs +1 -2
- package/loaders/EXRLoader.cjs.map +1 -1
- package/loaders/EXRLoader.js +2 -3
- package/loaders/EXRLoader.js.map +1 -1
- package/loaders/FBXLoader.cjs +2 -2
- package/loaders/FBXLoader.cjs.map +1 -1
- package/loaders/FBXLoader.js +2 -2
- package/loaders/FBXLoader.js.map +1 -1
- package/loaders/FontLoader.cjs +2 -2
- package/loaders/FontLoader.cjs.map +1 -1
- package/loaders/FontLoader.d.ts +2 -2
- package/loaders/FontLoader.js +2 -2
- package/loaders/FontLoader.js.map +1 -1
- package/loaders/GLTFLoader.cjs +2 -2
- package/loaders/GLTFLoader.cjs.map +1 -1
- package/loaders/GLTFLoader.js +2 -2
- package/loaders/GLTFLoader.js.map +1 -1
- package/loaders/KTX2Loader.cjs +374 -377
- package/loaders/KTX2Loader.cjs.map +1 -1
- package/loaders/KTX2Loader.js +374 -377
- package/loaders/KTX2Loader.js.map +1 -1
- package/loaders/LDrawLoader.cjs +4 -5
- package/loaders/LDrawLoader.cjs.map +1 -1
- package/loaders/LDrawLoader.js +5 -6
- package/loaders/LDrawLoader.js.map +1 -1
- package/loaders/OBJLoader.cjs +5 -5
- package/loaders/OBJLoader.cjs.map +1 -1
- package/loaders/OBJLoader.js +6 -6
- package/loaders/OBJLoader.js.map +1 -1
- package/loaders/PRWMLoader.cjs +43 -46
- package/loaders/PRWMLoader.cjs.map +1 -1
- package/loaders/PRWMLoader.js +43 -46
- package/loaders/PRWMLoader.js.map +1 -1
- package/loaders/SVGLoader.cjs +1688 -1694
- package/loaders/SVGLoader.cjs.map +1 -1
- package/loaders/SVGLoader.js +1688 -1694
- package/loaders/SVGLoader.js.map +1 -1
- package/loaders/XLoader.cjs +1 -1
- package/loaders/XLoader.cjs.map +1 -1
- package/loaders/XLoader.js +1 -1
- package/loaders/XLoader.js.map +1 -1
- package/math/Capsule.cjs +3 -3
- package/math/Capsule.cjs.map +1 -1
- package/math/Capsule.js +3 -3
- package/math/Capsule.js.map +1 -1
- package/math/ColorConverter.cjs +9 -9
- package/math/ColorConverter.cjs.map +1 -1
- package/math/ColorConverter.js +9 -9
- package/math/ColorConverter.js.map +1 -1
- package/math/ConvexHull.cjs +50 -53
- package/math/ConvexHull.cjs.map +1 -1
- package/math/ConvexHull.js +50 -53
- package/math/ConvexHull.js.map +1 -1
- package/math/ImprovedNoise.cjs +1 -1
- package/math/ImprovedNoise.cjs.map +1 -1
- package/math/ImprovedNoise.js +1 -1
- package/math/ImprovedNoise.js.map +1 -1
- package/math/MeshSurfaceSampler.cjs +2 -2
- package/math/MeshSurfaceSampler.cjs.map +1 -1
- package/math/MeshSurfaceSampler.js +2 -2
- package/math/MeshSurfaceSampler.js.map +1 -1
- package/math/OBB.cjs +14 -14
- package/math/OBB.cjs.map +1 -1
- package/math/OBB.js +15 -15
- package/math/OBB.js.map +1 -1
- package/math/Octree.cjs +7 -7
- package/math/Octree.cjs.map +1 -1
- package/math/Octree.js +8 -8
- package/math/Octree.js.map +1 -1
- package/misc/ConvexObjectBreaker.cjs +268 -271
- package/misc/ConvexObjectBreaker.cjs.map +1 -1
- package/misc/ConvexObjectBreaker.js +269 -272
- package/misc/ConvexObjectBreaker.js.map +1 -1
- package/misc/Gyroscope.cjs +6 -6
- package/misc/Gyroscope.cjs.map +1 -1
- package/misc/Gyroscope.js +7 -7
- package/misc/Gyroscope.js.map +1 -1
- package/modifiers/CurveModifier.cjs +1 -1
- package/modifiers/CurveModifier.cjs.map +1 -1
- package/modifiers/CurveModifier.js +2 -2
- package/modifiers/CurveModifier.js.map +1 -1
- package/modifiers/SimplifyModifier.cjs +2 -2
- package/modifiers/SimplifyModifier.cjs.map +1 -1
- package/modifiers/SimplifyModifier.js +2 -2
- package/modifiers/SimplifyModifier.js.map +1 -1
- package/objects/BatchedMesh.cjs +2 -2
- package/objects/BatchedMesh.cjs.map +1 -1
- package/objects/BatchedMesh.js +3 -3
- package/objects/BatchedMesh.js.map +1 -1
- package/objects/GroundProjectedEnv.cjs +1 -2
- package/objects/GroundProjectedEnv.cjs.map +1 -1
- package/objects/GroundProjectedEnv.js +2 -3
- package/objects/GroundProjectedEnv.js.map +1 -1
- package/objects/Lensflare.cjs +206 -209
- package/objects/Lensflare.cjs.map +1 -1
- package/objects/Lensflare.js +206 -209
- package/objects/Lensflare.js.map +1 -1
- package/objects/Reflector.cjs +146 -154
- package/objects/Reflector.cjs.map +1 -1
- package/objects/Reflector.js +146 -154
- package/objects/Reflector.js.map +1 -1
- package/objects/ReflectorForSSRPass.cjs +180 -183
- package/objects/ReflectorForSSRPass.cjs.map +1 -1
- package/objects/ReflectorForSSRPass.js +180 -183
- package/objects/ReflectorForSSRPass.js.map +1 -1
- package/objects/Refractor.cjs +161 -164
- package/objects/Refractor.cjs.map +1 -1
- package/objects/Refractor.js +161 -164
- package/objects/Refractor.js.map +1 -1
- package/objects/ShadowMesh.cjs +1 -1
- package/objects/ShadowMesh.cjs.map +1 -1
- package/objects/ShadowMesh.js +2 -2
- package/objects/ShadowMesh.js.map +1 -1
- package/objects/Sky.cjs +32 -35
- package/objects/Sky.cjs.map +1 -1
- package/objects/Sky.d.ts +6 -100
- package/objects/Sky.js +32 -35
- package/objects/Sky.js.map +1 -1
- package/objects/Water.cjs +1 -2
- package/objects/Water.cjs.map +1 -1
- package/objects/Water.js +2 -3
- package/objects/Water.js.map +1 -1
- package/objects/Water2.cjs +140 -143
- package/objects/Water2.cjs.map +1 -1
- package/objects/Water2.js +140 -143
- package/objects/Water2.js.map +1 -1
- package/package.json +1 -1
- package/postprocessing/SAOPass.cjs +264 -267
- package/postprocessing/SAOPass.cjs.map +1 -1
- package/postprocessing/SAOPass.js +264 -267
- package/postprocessing/SAOPass.js.map +1 -1
- package/postprocessing/SSAOPass.cjs +250 -253
- package/postprocessing/SSAOPass.cjs.map +1 -1
- package/postprocessing/SSAOPass.js +250 -253
- package/postprocessing/SSAOPass.js.map +1 -1
- package/postprocessing/SSRPass.cjs +376 -379
- package/postprocessing/SSRPass.cjs.map +1 -1
- package/postprocessing/SSRPass.js +376 -379
- package/postprocessing/SSRPass.js.map +1 -1
- package/postprocessing/UnrealBloomPass.cjs +202 -205
- package/postprocessing/UnrealBloomPass.cjs.map +1 -1
- package/postprocessing/UnrealBloomPass.js +202 -205
- package/postprocessing/UnrealBloomPass.js.map +1 -1
- package/renderers/CSS2DRenderer.cjs +5 -5
- package/renderers/CSS2DRenderer.cjs.map +1 -1
- package/renderers/CSS2DRenderer.js +5 -5
- package/renderers/CSS2DRenderer.js.map +1 -1
- package/renderers/CSS3DRenderer.cjs +5 -5
- package/renderers/CSS3DRenderer.cjs.map +1 -1
- package/renderers/CSS3DRenderer.js +6 -6
- package/renderers/CSS3DRenderer.js.map +1 -1
- package/shaders/ACESFilmicToneMappingShader.cjs +46 -71
- package/shaders/ACESFilmicToneMappingShader.cjs.map +1 -1
- package/shaders/ACESFilmicToneMappingShader.js +46 -71
- package/shaders/ACESFilmicToneMappingShader.js.map +1 -1
- package/shaders/AfterimageShader.cjs +22 -41
- package/shaders/AfterimageShader.cjs.map +1 -1
- package/shaders/AfterimageShader.js +22 -41
- package/shaders/AfterimageShader.js.map +1 -1
- package/shaders/BasicShader.cjs +6 -20
- package/shaders/BasicShader.cjs.map +1 -1
- package/shaders/BasicShader.js +6 -20
- package/shaders/BasicShader.js.map +1 -1
- package/shaders/BleachBypassShader.cjs +26 -46
- package/shaders/BleachBypassShader.cjs.map +1 -1
- package/shaders/BleachBypassShader.js +26 -46
- package/shaders/BleachBypassShader.js.map +1 -1
- package/shaders/BlendShader.cjs +19 -33
- package/shaders/BlendShader.cjs.map +1 -1
- package/shaders/BlendShader.js +19 -33
- package/shaders/BlendShader.js.map +1 -1
- package/shaders/BokehShader.cjs +90 -117
- package/shaders/BokehShader.cjs.map +1 -1
- package/shaders/BokehShader.js +90 -117
- package/shaders/BokehShader.js.map +1 -1
- package/shaders/BokehShader2.cjs +232 -333
- package/shaders/BokehShader2.cjs.map +1 -1
- package/shaders/BokehShader2.js +232 -333
- package/shaders/BokehShader2.js.map +1 -1
- package/shaders/BrightnessContrastShader.cjs +22 -38
- package/shaders/BrightnessContrastShader.cjs.map +1 -1
- package/shaders/BrightnessContrastShader.js +22 -38
- package/shaders/BrightnessContrastShader.js.map +1 -1
- package/shaders/ColorCorrectionShader.cjs +21 -35
- package/shaders/ColorCorrectionShader.cjs.map +1 -1
- package/shaders/ColorCorrectionShader.js +21 -35
- package/shaders/ColorCorrectionShader.js.map +1 -1
- package/shaders/ColorifyShader.cjs +19 -34
- package/shaders/ColorifyShader.cjs.map +1 -1
- package/shaders/ColorifyShader.js +19 -34
- package/shaders/ColorifyShader.js.map +1 -1
- package/shaders/ConvolutionShader.cjs +24 -43
- package/shaders/ConvolutionShader.cjs.map +1 -1
- package/shaders/ConvolutionShader.js +24 -43
- package/shaders/ConvolutionShader.js.map +1 -1
- package/shaders/CopyShader.cjs +16 -30
- package/shaders/CopyShader.cjs.map +1 -1
- package/shaders/CopyShader.js +16 -30
- package/shaders/CopyShader.js.map +1 -1
- package/shaders/DOFMipMapShader.cjs +21 -38
- package/shaders/DOFMipMapShader.cjs.map +1 -1
- package/shaders/DOFMipMapShader.js +21 -38
- package/shaders/DOFMipMapShader.js.map +1 -1
- package/shaders/DepthLimitedBlurShader.cjs +69 -98
- package/shaders/DepthLimitedBlurShader.cjs.map +1 -1
- package/shaders/DepthLimitedBlurShader.js +69 -98
- package/shaders/DepthLimitedBlurShader.js.map +1 -1
- package/shaders/DigitalGlitch.cjs +59 -70
- package/shaders/DigitalGlitch.cjs.map +1 -1
- package/shaders/DigitalGlitch.js +59 -70
- package/shaders/DigitalGlitch.js.map +1 -1
- package/shaders/DotScreenShader.cjs +28 -49
- package/shaders/DotScreenShader.cjs.map +1 -1
- package/shaders/DotScreenShader.js +28 -49
- package/shaders/DotScreenShader.js.map +1 -1
- package/shaders/FXAAShader.cjs +1089 -1098
- package/shaders/FXAAShader.cjs.map +1 -1
- package/shaders/FXAAShader.js +1089 -1098
- package/shaders/FXAAShader.js.map +1 -1
- package/shaders/FilmShader.cjs +29 -57
- package/shaders/FilmShader.cjs.map +1 -1
- package/shaders/FilmShader.js +29 -57
- package/shaders/FilmShader.js.map +1 -1
- package/shaders/FocusShader.cjs +43 -70
- package/shaders/FocusShader.cjs.map +1 -1
- package/shaders/FocusShader.js +43 -70
- package/shaders/FocusShader.js.map +1 -1
- package/shaders/FreiChenShader.cjs +53 -74
- package/shaders/FreiChenShader.cjs.map +1 -1
- package/shaders/FreiChenShader.js +53 -74
- package/shaders/FreiChenShader.js.map +1 -1
- package/shaders/FresnelShader.cjs +35 -55
- package/shaders/FresnelShader.cjs.map +1 -1
- package/shaders/FresnelShader.js +35 -55
- package/shaders/FresnelShader.js.map +1 -1
- package/shaders/GammaCorrectionShader.cjs +19 -33
- package/shaders/GammaCorrectionShader.cjs.map +1 -1
- package/shaders/GammaCorrectionShader.js +19 -33
- package/shaders/GammaCorrectionShader.js.map +1 -1
- package/shaders/GodRaysShader.cjs +116 -193
- package/shaders/GodRaysShader.cjs.map +1 -1
- package/shaders/GodRaysShader.js +116 -193
- package/shaders/GodRaysShader.js.map +1 -1
- package/shaders/HalftoneShader.cjs +192 -270
- package/shaders/HalftoneShader.cjs.map +1 -1
- package/shaders/HalftoneShader.js +192 -270
- package/shaders/HalftoneShader.js.map +1 -1
- package/shaders/HorizontalTiltShiftShader.cjs +27 -43
- package/shaders/HorizontalTiltShiftShader.cjs.map +1 -1
- package/shaders/HorizontalTiltShiftShader.js +27 -43
- package/shaders/HorizontalTiltShiftShader.js.map +1 -1
- package/shaders/HueSaturationShader.cjs +31 -47
- package/shaders/HueSaturationShader.cjs.map +1 -1
- package/shaders/HueSaturationShader.js +31 -47
- package/shaders/HueSaturationShader.js.map +1 -1
- package/shaders/KaleidoShader.cjs +24 -37
- package/shaders/KaleidoShader.cjs.map +1 -1
- package/shaders/KaleidoShader.js +24 -37
- package/shaders/KaleidoShader.js.map +1 -1
- package/shaders/LuminosityHighPassShader.cjs +24 -43
- package/shaders/LuminosityHighPassShader.cjs.map +1 -1
- package/shaders/LuminosityHighPassShader.js +24 -43
- package/shaders/LuminosityHighPassShader.js.map +1 -1
- package/shaders/LuminosityShader.cjs +17 -34
- package/shaders/LuminosityShader.cjs.map +1 -1
- package/shaders/LuminosityShader.js +17 -34
- package/shaders/LuminosityShader.js.map +1 -1
- package/shaders/MirrorShader.cjs +26 -39
- package/shaders/MirrorShader.cjs.map +1 -1
- package/shaders/MirrorShader.js +26 -39
- package/shaders/MirrorShader.js.map +1 -1
- package/shaders/NormalMapShader.cjs +21 -36
- package/shaders/NormalMapShader.cjs.map +1 -1
- package/shaders/NormalMapShader.js +21 -36
- package/shaders/NormalMapShader.js.map +1 -1
- package/shaders/ParallaxShader.cjs +97 -147
- package/shaders/ParallaxShader.cjs.map +1 -1
- package/shaders/ParallaxShader.js +97 -147
- package/shaders/ParallaxShader.js.map +1 -1
- package/shaders/PixelShader.cjs +18 -31
- package/shaders/PixelShader.cjs.map +1 -1
- package/shaders/PixelShader.js +18 -31
- package/shaders/PixelShader.js.map +1 -1
- package/shaders/RGBShiftShader.cjs +20 -33
- package/shaders/RGBShiftShader.cjs.map +1 -1
- package/shaders/RGBShiftShader.js +20 -33
- package/shaders/RGBShiftShader.js.map +1 -1
- package/shaders/SAOShader.cjs +117 -154
- package/shaders/SAOShader.cjs.map +1 -1
- package/shaders/SAOShader.js +117 -154
- package/shaders/SAOShader.js.map +1 -1
- package/shaders/SMAAShader.cjs +270 -358
- package/shaders/SMAAShader.cjs.map +1 -1
- package/shaders/SMAAShader.js +270 -358
- package/shaders/SMAAShader.js.map +1 -1
- package/shaders/SSAOShader.cjs +142 -236
- package/shaders/SSAOShader.cjs.map +1 -1
- package/shaders/SSAOShader.js +142 -236
- package/shaders/SSAOShader.js.map +1 -1
- package/shaders/SSRShader.cjs +4 -4
- package/shaders/SSRShader.cjs.map +1 -1
- package/shaders/SSRShader.js +4 -4
- package/shaders/SSRShader.js.map +1 -1
- package/shaders/SepiaShader.cjs +20 -36
- package/shaders/SepiaShader.cjs.map +1 -1
- package/shaders/SepiaShader.js +20 -36
- package/shaders/SepiaShader.js.map +1 -1
- package/shaders/SobelOperatorShader.cjs +37 -64
- package/shaders/SobelOperatorShader.cjs.map +1 -1
- package/shaders/SobelOperatorShader.js +37 -64
- package/shaders/SobelOperatorShader.js.map +1 -1
- package/shaders/TechnicolorShader.cjs +16 -29
- package/shaders/TechnicolorShader.cjs.map +1 -1
- package/shaders/TechnicolorShader.js +16 -29
- package/shaders/TechnicolorShader.js.map +1 -1
- package/shaders/ToneMapShader.cjs +35 -55
- package/shaders/ToneMapShader.cjs.map +1 -1
- package/shaders/ToneMapShader.js +35 -55
- package/shaders/ToneMapShader.js.map +1 -1
- package/shaders/ToonShader.cjs +165 -275
- package/shaders/ToonShader.cjs.map +1 -1
- package/shaders/ToonShader.js +165 -275
- package/shaders/ToonShader.js.map +1 -1
- package/shaders/TriangleBlurShader.cjs +27 -50
- package/shaders/TriangleBlurShader.cjs.map +1 -1
- package/shaders/TriangleBlurShader.js +27 -50
- package/shaders/TriangleBlurShader.js.map +1 -1
- package/shaders/UnpackDepthRGBAShader.cjs +17 -32
- package/shaders/UnpackDepthRGBAShader.cjs.map +1 -1
- package/shaders/UnpackDepthRGBAShader.js +17 -32
- package/shaders/UnpackDepthRGBAShader.js.map +1 -1
- package/shaders/VerticalTiltShiftShader.cjs +27 -43
- package/shaders/VerticalTiltShiftShader.cjs.map +1 -1
- package/shaders/VerticalTiltShiftShader.js +27 -43
- package/shaders/VerticalTiltShiftShader.js.map +1 -1
- package/shaders/VignetteShader.cjs +27 -43
- package/shaders/VignetteShader.cjs.map +1 -1
- package/shaders/VignetteShader.js +27 -43
- package/shaders/VignetteShader.js.map +1 -1
- package/shaders/VolumeShader.cjs +213 -264
- package/shaders/VolumeShader.cjs.map +1 -1
- package/shaders/VolumeShader.js +213 -264
- package/shaders/VolumeShader.js.map +1 -1
- package/shaders/WaterRefractionShader.cjs +35 -63
- package/shaders/WaterRefractionShader.cjs.map +1 -1
- package/shaders/WaterRefractionShader.js +35 -63
- package/shaders/WaterRefractionShader.js.map +1 -1
- package/utils/GeometryCompressionUtils.cjs +1 -2
- package/utils/GeometryCompressionUtils.cjs.map +1 -1
- package/utils/GeometryCompressionUtils.js +2 -3
- package/utils/GeometryCompressionUtils.js.map +1 -1
- package/utils/RoughnessMipmapper.cjs +3 -3
- package/utils/RoughnessMipmapper.cjs.map +1 -1
- package/utils/RoughnessMipmapper.js +4 -4
- package/utils/RoughnessMipmapper.js.map +1 -1
- package/webxr/ARButton.cjs +106 -109
- package/webxr/ARButton.cjs.map +1 -1
- package/webxr/ARButton.d.ts +3 -4
- package/webxr/ARButton.js +106 -109
- package/webxr/ARButton.js.map +1 -1
- package/webxr/OculusHandPointerModel.cjs +2 -2
- package/webxr/OculusHandPointerModel.cjs.map +1 -1
- package/webxr/OculusHandPointerModel.js +2 -2
- package/webxr/OculusHandPointerModel.js.map +1 -1
- package/webxr/VRButton.cjs +95 -98
- package/webxr/VRButton.cjs.map +1 -1
- package/webxr/VRButton.d.ts +5 -6
- package/webxr/VRButton.js +95 -98
- package/webxr/VRButton.js.map +1 -1
- package/webxr/XRHandPrimitiveModel.cjs +2 -2
- package/webxr/XRHandPrimitiveModel.cjs.map +1 -1
- package/webxr/XRHandPrimitiveModel.js +3 -3
- package/webxr/XRHandPrimitiveModel.js.map +1 -1
package/loaders/SVGLoader.js
CHANGED
@@ -1,1822 +1,1816 @@
|
|
1
1
|
import { Loader, FileLoader, Matrix3, Vector2, Vector3, ShapeUtils, Box2, Shape, Path, BufferGeometry, Float32BufferAttribute, ShapePath } from "three";
|
2
2
|
const COLOR_SPACE_SVG = "srgb";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
3
|
+
class SVGLoader extends Loader {
|
4
|
+
constructor(manager) {
|
5
|
+
super(manager);
|
6
|
+
this.defaultDPI = 90;
|
7
|
+
this.defaultUnit = "px";
|
8
|
+
}
|
9
|
+
load(url, onLoad, onProgress, onError) {
|
10
|
+
const scope = this;
|
11
|
+
const loader = new FileLoader(scope.manager);
|
12
|
+
loader.setPath(scope.path);
|
13
|
+
loader.setRequestHeader(scope.requestHeader);
|
14
|
+
loader.setWithCredentials(scope.withCredentials);
|
15
|
+
loader.load(
|
16
|
+
url,
|
17
|
+
function(text) {
|
18
|
+
try {
|
19
|
+
onLoad(scope.parse(text));
|
20
|
+
} catch (e) {
|
21
|
+
if (onError) {
|
22
|
+
onError(e);
|
23
|
+
} else {
|
24
|
+
console.error(e);
|
25
|
+
}
|
26
|
+
scope.manager.itemError(url);
|
27
|
+
}
|
28
|
+
},
|
29
|
+
onProgress,
|
30
|
+
onError
|
31
|
+
);
|
32
|
+
}
|
33
|
+
parse(text) {
|
34
|
+
const scope = this;
|
35
|
+
function parseNode(node, style) {
|
36
|
+
if (node.nodeType !== 1)
|
37
|
+
return;
|
38
|
+
const transform = getNodeTransform(node);
|
39
|
+
let isDefsNode = false;
|
40
|
+
let path = null;
|
41
|
+
switch (node.nodeName) {
|
42
|
+
case "svg":
|
43
|
+
style = parseStyle(node, style);
|
44
|
+
break;
|
45
|
+
case "style":
|
46
|
+
parseCSSStylesheet(node);
|
47
|
+
break;
|
48
|
+
case "g":
|
49
|
+
style = parseStyle(node, style);
|
50
|
+
break;
|
51
|
+
case "path":
|
52
|
+
style = parseStyle(node, style);
|
53
|
+
if (node.hasAttribute("d"))
|
54
|
+
path = parsePathNode(node);
|
55
|
+
break;
|
56
|
+
case "rect":
|
57
|
+
style = parseStyle(node, style);
|
58
|
+
path = parseRectNode(node);
|
59
|
+
break;
|
60
|
+
case "polygon":
|
61
|
+
style = parseStyle(node, style);
|
62
|
+
path = parsePolygonNode(node);
|
63
|
+
break;
|
64
|
+
case "polyline":
|
65
|
+
style = parseStyle(node, style);
|
66
|
+
path = parsePolylineNode(node);
|
67
|
+
break;
|
68
|
+
case "circle":
|
69
|
+
style = parseStyle(node, style);
|
70
|
+
path = parseCircleNode(node);
|
71
|
+
break;
|
72
|
+
case "ellipse":
|
73
|
+
style = parseStyle(node, style);
|
74
|
+
path = parseEllipseNode(node);
|
75
|
+
break;
|
76
|
+
case "line":
|
77
|
+
style = parseStyle(node, style);
|
78
|
+
path = parseLineNode(node);
|
79
|
+
break;
|
80
|
+
case "defs":
|
81
|
+
isDefsNode = true;
|
82
|
+
break;
|
83
|
+
case "use":
|
84
|
+
style = parseStyle(node, style);
|
85
|
+
const href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "";
|
86
|
+
const usedNodeId = href.substring(1);
|
87
|
+
const usedNode = node.viewportElement.getElementById(usedNodeId);
|
88
|
+
if (usedNode) {
|
89
|
+
parseNode(usedNode, style);
|
90
|
+
} else {
|
91
|
+
console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
|
28
92
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
if (path) {
|
96
|
+
if (style.fill !== void 0 && style.fill !== "none") {
|
97
|
+
path.color.setStyle(style.fill, COLOR_SPACE_SVG);
|
98
|
+
}
|
99
|
+
transformPath(path, currentTransform);
|
100
|
+
paths.push(path);
|
101
|
+
path.userData = { node, style };
|
102
|
+
}
|
103
|
+
const childNodes = node.childNodes;
|
104
|
+
for (let i = 0; i < childNodes.length; i++) {
|
105
|
+
const node2 = childNodes[i];
|
106
|
+
if (isDefsNode && node2.nodeName !== "style" && node2.nodeName !== "defs") {
|
107
|
+
continue;
|
108
|
+
}
|
109
|
+
parseNode(node2, style);
|
110
|
+
}
|
111
|
+
if (transform) {
|
112
|
+
transformStack.pop();
|
113
|
+
if (transformStack.length > 0) {
|
114
|
+
currentTransform.copy(transformStack[transformStack.length - 1]);
|
115
|
+
} else {
|
116
|
+
currentTransform.identity();
|
117
|
+
}
|
118
|
+
}
|
33
119
|
}
|
34
|
-
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
120
|
+
function parsePathNode(node) {
|
121
|
+
const path = new ShapePath();
|
122
|
+
const point = new Vector2();
|
123
|
+
const control = new Vector2();
|
124
|
+
const firstPoint = new Vector2();
|
125
|
+
let isFirstPoint = true;
|
126
|
+
let doSetFirstPoint = false;
|
127
|
+
const d = node.getAttribute("d");
|
128
|
+
if (d === "" || d === "none")
|
129
|
+
return null;
|
130
|
+
const commands = d.match(/[a-df-z][^a-df-z]*/gi);
|
131
|
+
for (let i = 0, l = commands.length; i < l; i++) {
|
132
|
+
const command = commands[i];
|
133
|
+
const type = command.charAt(0);
|
134
|
+
const data2 = command.slice(1).trim();
|
135
|
+
if (isFirstPoint === true) {
|
136
|
+
doSetFirstPoint = true;
|
137
|
+
isFirstPoint = false;
|
138
|
+
}
|
139
|
+
let numbers;
|
140
|
+
switch (type) {
|
141
|
+
case "M":
|
142
|
+
numbers = parseFloats(data2);
|
143
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
144
|
+
point.x = numbers[j + 0];
|
145
|
+
point.y = numbers[j + 1];
|
146
|
+
control.x = point.x;
|
147
|
+
control.y = point.y;
|
148
|
+
if (j === 0) {
|
149
|
+
path.moveTo(point.x, point.y);
|
150
|
+
} else {
|
151
|
+
path.lineTo(point.x, point.y);
|
152
|
+
}
|
153
|
+
if (j === 0)
|
154
|
+
firstPoint.copy(point);
|
155
|
+
}
|
156
|
+
break;
|
157
|
+
case "H":
|
158
|
+
numbers = parseFloats(data2);
|
159
|
+
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
160
|
+
point.x = numbers[j];
|
161
|
+
control.x = point.x;
|
162
|
+
control.y = point.y;
|
163
|
+
path.lineTo(point.x, point.y);
|
164
|
+
if (j === 0 && doSetFirstPoint === true)
|
165
|
+
firstPoint.copy(point);
|
166
|
+
}
|
167
|
+
break;
|
168
|
+
case "V":
|
169
|
+
numbers = parseFloats(data2);
|
170
|
+
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
171
|
+
point.y = numbers[j];
|
172
|
+
control.x = point.x;
|
173
|
+
control.y = point.y;
|
174
|
+
path.lineTo(point.x, point.y);
|
175
|
+
if (j === 0 && doSetFirstPoint === true)
|
176
|
+
firstPoint.copy(point);
|
177
|
+
}
|
45
178
|
break;
|
46
|
-
case "
|
47
|
-
|
179
|
+
case "L":
|
180
|
+
numbers = parseFloats(data2);
|
181
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
182
|
+
point.x = numbers[j + 0];
|
183
|
+
point.y = numbers[j + 1];
|
184
|
+
control.x = point.x;
|
185
|
+
control.y = point.y;
|
186
|
+
path.lineTo(point.x, point.y);
|
187
|
+
if (j === 0 && doSetFirstPoint === true)
|
188
|
+
firstPoint.copy(point);
|
189
|
+
}
|
48
190
|
break;
|
49
|
-
case "
|
50
|
-
|
191
|
+
case "C":
|
192
|
+
numbers = parseFloats(data2);
|
193
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 6) {
|
194
|
+
path.bezierCurveTo(
|
195
|
+
numbers[j + 0],
|
196
|
+
numbers[j + 1],
|
197
|
+
numbers[j + 2],
|
198
|
+
numbers[j + 3],
|
199
|
+
numbers[j + 4],
|
200
|
+
numbers[j + 5]
|
201
|
+
);
|
202
|
+
control.x = numbers[j + 2];
|
203
|
+
control.y = numbers[j + 3];
|
204
|
+
point.x = numbers[j + 4];
|
205
|
+
point.y = numbers[j + 5];
|
206
|
+
if (j === 0 && doSetFirstPoint === true)
|
207
|
+
firstPoint.copy(point);
|
208
|
+
}
|
51
209
|
break;
|
52
|
-
case "
|
53
|
-
|
54
|
-
|
55
|
-
path
|
210
|
+
case "S":
|
211
|
+
numbers = parseFloats(data2);
|
212
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
213
|
+
path.bezierCurveTo(
|
214
|
+
getReflection(point.x, control.x),
|
215
|
+
getReflection(point.y, control.y),
|
216
|
+
numbers[j + 0],
|
217
|
+
numbers[j + 1],
|
218
|
+
numbers[j + 2],
|
219
|
+
numbers[j + 3]
|
220
|
+
);
|
221
|
+
control.x = numbers[j + 0];
|
222
|
+
control.y = numbers[j + 1];
|
223
|
+
point.x = numbers[j + 2];
|
224
|
+
point.y = numbers[j + 3];
|
225
|
+
if (j === 0 && doSetFirstPoint === true)
|
226
|
+
firstPoint.copy(point);
|
227
|
+
}
|
56
228
|
break;
|
57
|
-
case "
|
58
|
-
|
59
|
-
|
229
|
+
case "Q":
|
230
|
+
numbers = parseFloats(data2);
|
231
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
232
|
+
path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
|
233
|
+
control.x = numbers[j + 0];
|
234
|
+
control.y = numbers[j + 1];
|
235
|
+
point.x = numbers[j + 2];
|
236
|
+
point.y = numbers[j + 3];
|
237
|
+
if (j === 0 && doSetFirstPoint === true)
|
238
|
+
firstPoint.copy(point);
|
239
|
+
}
|
60
240
|
break;
|
61
|
-
case "
|
62
|
-
|
63
|
-
|
241
|
+
case "T":
|
242
|
+
numbers = parseFloats(data2);
|
243
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
244
|
+
const rx = getReflection(point.x, control.x);
|
245
|
+
const ry = getReflection(point.y, control.y);
|
246
|
+
path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
|
247
|
+
control.x = rx;
|
248
|
+
control.y = ry;
|
249
|
+
point.x = numbers[j + 0];
|
250
|
+
point.y = numbers[j + 1];
|
251
|
+
if (j === 0 && doSetFirstPoint === true)
|
252
|
+
firstPoint.copy(point);
|
253
|
+
}
|
64
254
|
break;
|
65
|
-
case "
|
66
|
-
|
67
|
-
|
255
|
+
case "A":
|
256
|
+
numbers = parseFloats(data2, [3, 4], 7);
|
257
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 7) {
|
258
|
+
if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
|
259
|
+
continue;
|
260
|
+
const start = point.clone();
|
261
|
+
point.x = numbers[j + 5];
|
262
|
+
point.y = numbers[j + 6];
|
263
|
+
control.x = point.x;
|
264
|
+
control.y = point.y;
|
265
|
+
parseArcCommand(
|
266
|
+
path,
|
267
|
+
numbers[j],
|
268
|
+
numbers[j + 1],
|
269
|
+
numbers[j + 2],
|
270
|
+
numbers[j + 3],
|
271
|
+
numbers[j + 4],
|
272
|
+
start,
|
273
|
+
point
|
274
|
+
);
|
275
|
+
if (j === 0 && doSetFirstPoint === true)
|
276
|
+
firstPoint.copy(point);
|
277
|
+
}
|
68
278
|
break;
|
69
|
-
case "
|
70
|
-
|
71
|
-
|
279
|
+
case "m":
|
280
|
+
numbers = parseFloats(data2);
|
281
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
282
|
+
point.x += numbers[j + 0];
|
283
|
+
point.y += numbers[j + 1];
|
284
|
+
control.x = point.x;
|
285
|
+
control.y = point.y;
|
286
|
+
if (j === 0) {
|
287
|
+
path.moveTo(point.x, point.y);
|
288
|
+
} else {
|
289
|
+
path.lineTo(point.x, point.y);
|
290
|
+
}
|
291
|
+
if (j === 0)
|
292
|
+
firstPoint.copy(point);
|
293
|
+
}
|
72
294
|
break;
|
73
|
-
case "
|
74
|
-
|
75
|
-
|
295
|
+
case "h":
|
296
|
+
numbers = parseFloats(data2);
|
297
|
+
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
298
|
+
point.x += numbers[j];
|
299
|
+
control.x = point.x;
|
300
|
+
control.y = point.y;
|
301
|
+
path.lineTo(point.x, point.y);
|
302
|
+
if (j === 0 && doSetFirstPoint === true)
|
303
|
+
firstPoint.copy(point);
|
304
|
+
}
|
76
305
|
break;
|
77
|
-
case "
|
78
|
-
|
79
|
-
|
306
|
+
case "v":
|
307
|
+
numbers = parseFloats(data2);
|
308
|
+
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
309
|
+
point.y += numbers[j];
|
310
|
+
control.x = point.x;
|
311
|
+
control.y = point.y;
|
312
|
+
path.lineTo(point.x, point.y);
|
313
|
+
if (j === 0 && doSetFirstPoint === true)
|
314
|
+
firstPoint.copy(point);
|
315
|
+
}
|
80
316
|
break;
|
81
|
-
case "
|
82
|
-
|
317
|
+
case "l":
|
318
|
+
numbers = parseFloats(data2);
|
319
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
320
|
+
point.x += numbers[j + 0];
|
321
|
+
point.y += numbers[j + 1];
|
322
|
+
control.x = point.x;
|
323
|
+
control.y = point.y;
|
324
|
+
path.lineTo(point.x, point.y);
|
325
|
+
if (j === 0 && doSetFirstPoint === true)
|
326
|
+
firstPoint.copy(point);
|
327
|
+
}
|
83
328
|
break;
|
84
|
-
case "
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
329
|
+
case "c":
|
330
|
+
numbers = parseFloats(data2);
|
331
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 6) {
|
332
|
+
path.bezierCurveTo(
|
333
|
+
point.x + numbers[j + 0],
|
334
|
+
point.y + numbers[j + 1],
|
335
|
+
point.x + numbers[j + 2],
|
336
|
+
point.y + numbers[j + 3],
|
337
|
+
point.x + numbers[j + 4],
|
338
|
+
point.y + numbers[j + 5]
|
339
|
+
);
|
340
|
+
control.x = point.x + numbers[j + 2];
|
341
|
+
control.y = point.y + numbers[j + 3];
|
342
|
+
point.x += numbers[j + 4];
|
343
|
+
point.y += numbers[j + 5];
|
344
|
+
if (j === 0 && doSetFirstPoint === true)
|
345
|
+
firstPoint.copy(point);
|
346
|
+
}
|
347
|
+
break;
|
348
|
+
case "s":
|
349
|
+
numbers = parseFloats(data2);
|
350
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
351
|
+
path.bezierCurveTo(
|
352
|
+
getReflection(point.x, control.x),
|
353
|
+
getReflection(point.y, control.y),
|
354
|
+
point.x + numbers[j + 0],
|
355
|
+
point.y + numbers[j + 1],
|
356
|
+
point.x + numbers[j + 2],
|
357
|
+
point.y + numbers[j + 3]
|
358
|
+
);
|
359
|
+
control.x = point.x + numbers[j + 0];
|
360
|
+
control.y = point.y + numbers[j + 1];
|
361
|
+
point.x += numbers[j + 2];
|
362
|
+
point.y += numbers[j + 3];
|
363
|
+
if (j === 0 && doSetFirstPoint === true)
|
364
|
+
firstPoint.copy(point);
|
365
|
+
}
|
366
|
+
break;
|
367
|
+
case "q":
|
368
|
+
numbers = parseFloats(data2);
|
369
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
370
|
+
path.quadraticCurveTo(
|
371
|
+
point.x + numbers[j + 0],
|
372
|
+
point.y + numbers[j + 1],
|
373
|
+
point.x + numbers[j + 2],
|
374
|
+
point.y + numbers[j + 3]
|
375
|
+
);
|
376
|
+
control.x = point.x + numbers[j + 0];
|
377
|
+
control.y = point.y + numbers[j + 1];
|
378
|
+
point.x += numbers[j + 2];
|
379
|
+
point.y += numbers[j + 3];
|
380
|
+
if (j === 0 && doSetFirstPoint === true)
|
381
|
+
firstPoint.copy(point);
|
382
|
+
}
|
383
|
+
break;
|
384
|
+
case "t":
|
385
|
+
numbers = parseFloats(data2);
|
386
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
387
|
+
const rx = getReflection(point.x, control.x);
|
388
|
+
const ry = getReflection(point.y, control.y);
|
389
|
+
path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
|
390
|
+
control.x = rx;
|
391
|
+
control.y = ry;
|
392
|
+
point.x = point.x + numbers[j + 0];
|
393
|
+
point.y = point.y + numbers[j + 1];
|
394
|
+
if (j === 0 && doSetFirstPoint === true)
|
395
|
+
firstPoint.copy(point);
|
93
396
|
}
|
94
397
|
break;
|
398
|
+
case "a":
|
399
|
+
numbers = parseFloats(data2, [3, 4], 7);
|
400
|
+
for (let j = 0, jl = numbers.length; j < jl; j += 7) {
|
401
|
+
if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
|
402
|
+
continue;
|
403
|
+
const start = point.clone();
|
404
|
+
point.x += numbers[j + 5];
|
405
|
+
point.y += numbers[j + 6];
|
406
|
+
control.x = point.x;
|
407
|
+
control.y = point.y;
|
408
|
+
parseArcCommand(
|
409
|
+
path,
|
410
|
+
numbers[j],
|
411
|
+
numbers[j + 1],
|
412
|
+
numbers[j + 2],
|
413
|
+
numbers[j + 3],
|
414
|
+
numbers[j + 4],
|
415
|
+
start,
|
416
|
+
point
|
417
|
+
);
|
418
|
+
if (j === 0 && doSetFirstPoint === true)
|
419
|
+
firstPoint.copy(point);
|
420
|
+
}
|
421
|
+
break;
|
422
|
+
case "Z":
|
423
|
+
case "z":
|
424
|
+
path.currentPath.autoClose = true;
|
425
|
+
if (path.currentPath.curves.length > 0) {
|
426
|
+
point.copy(firstPoint);
|
427
|
+
path.currentPath.currentPoint.copy(point);
|
428
|
+
isFirstPoint = true;
|
429
|
+
}
|
430
|
+
break;
|
431
|
+
default:
|
432
|
+
console.warn(command);
|
95
433
|
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
434
|
+
doSetFirstPoint = false;
|
435
|
+
}
|
436
|
+
return path;
|
437
|
+
}
|
438
|
+
function parseCSSStylesheet(node) {
|
439
|
+
if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
|
440
|
+
return;
|
441
|
+
for (let i = 0; i < node.sheet.cssRules.length; i++) {
|
442
|
+
const stylesheet = node.sheet.cssRules[i];
|
443
|
+
if (stylesheet.type !== 1)
|
444
|
+
continue;
|
445
|
+
const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
|
446
|
+
for (let j = 0; j < selectorList.length; j++) {
|
447
|
+
const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
|
448
|
+
stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
|
103
449
|
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
450
|
+
}
|
451
|
+
}
|
452
|
+
function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
|
453
|
+
if (rx == 0 || ry == 0) {
|
454
|
+
path.lineTo(end.x, end.y);
|
455
|
+
return;
|
456
|
+
}
|
457
|
+
x_axis_rotation = x_axis_rotation * Math.PI / 180;
|
458
|
+
rx = Math.abs(rx);
|
459
|
+
ry = Math.abs(ry);
|
460
|
+
const dx2 = (start.x - end.x) / 2;
|
461
|
+
const dy2 = (start.y - end.y) / 2;
|
462
|
+
const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
|
463
|
+
const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
|
464
|
+
let rxs = rx * rx;
|
465
|
+
let rys = ry * ry;
|
466
|
+
const x1ps = x1p * x1p;
|
467
|
+
const y1ps = y1p * y1p;
|
468
|
+
const cr = x1ps / rxs + y1ps / rys;
|
469
|
+
if (cr > 1) {
|
470
|
+
const s = Math.sqrt(cr);
|
471
|
+
rx = s * rx;
|
472
|
+
ry = s * ry;
|
473
|
+
rxs = rx * rx;
|
474
|
+
rys = ry * ry;
|
475
|
+
}
|
476
|
+
const dq = rxs * y1ps + rys * x1ps;
|
477
|
+
const pq = (rxs * rys - dq) / dq;
|
478
|
+
let q = Math.sqrt(Math.max(0, pq));
|
479
|
+
if (large_arc_flag === sweep_flag)
|
480
|
+
q = -q;
|
481
|
+
const cxp = q * rx * y1p / ry;
|
482
|
+
const cyp = -q * ry * x1p / rx;
|
483
|
+
const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
|
484
|
+
const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
|
485
|
+
const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
|
486
|
+
const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
|
487
|
+
path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
|
488
|
+
}
|
489
|
+
function svgAngle(ux, uy, vx, vy) {
|
490
|
+
const dot = ux * vx + uy * vy;
|
491
|
+
const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
|
492
|
+
let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
|
493
|
+
if (ux * vy - uy * vx < 0)
|
494
|
+
ang = -ang;
|
495
|
+
return ang;
|
496
|
+
}
|
497
|
+
function parseRectNode(node) {
|
498
|
+
const x = parseFloatWithUnits(node.getAttribute("x") || 0);
|
499
|
+
const y = parseFloatWithUnits(node.getAttribute("y") || 0);
|
500
|
+
const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
|
501
|
+
const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
|
502
|
+
const w = parseFloatWithUnits(node.getAttribute("width"));
|
503
|
+
const h = parseFloatWithUnits(node.getAttribute("height"));
|
504
|
+
const bci = 1 - 0.551915024494;
|
505
|
+
const path = new ShapePath();
|
506
|
+
path.moveTo(x + rx, y);
|
507
|
+
path.lineTo(x + w - rx, y);
|
508
|
+
if (rx !== 0 || ry !== 0) {
|
509
|
+
path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
|
510
|
+
}
|
511
|
+
path.lineTo(x + w, y + h - ry);
|
512
|
+
if (rx !== 0 || ry !== 0) {
|
513
|
+
path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
|
514
|
+
}
|
515
|
+
path.lineTo(x + rx, y + h);
|
516
|
+
if (rx !== 0 || ry !== 0) {
|
517
|
+
path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
|
518
|
+
}
|
519
|
+
path.lineTo(x, y + ry);
|
520
|
+
if (rx !== 0 || ry !== 0) {
|
521
|
+
path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
|
522
|
+
}
|
523
|
+
return path;
|
524
|
+
}
|
525
|
+
function parsePolygonNode(node) {
|
526
|
+
function iterator(match, a, b) {
|
527
|
+
const x = parseFloatWithUnits(a);
|
528
|
+
const y = parseFloatWithUnits(b);
|
529
|
+
if (index === 0) {
|
530
|
+
path.moveTo(x, y);
|
531
|
+
} else {
|
532
|
+
path.lineTo(x, y);
|
111
533
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
534
|
+
index++;
|
535
|
+
}
|
536
|
+
const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
|
537
|
+
const path = new ShapePath();
|
538
|
+
let index = 0;
|
539
|
+
node.getAttribute("points").replace(regex, iterator);
|
540
|
+
path.currentPath.autoClose = true;
|
541
|
+
return path;
|
542
|
+
}
|
543
|
+
function parsePolylineNode(node) {
|
544
|
+
function iterator(match, a, b) {
|
545
|
+
const x = parseFloatWithUnits(a);
|
546
|
+
const y = parseFloatWithUnits(b);
|
547
|
+
if (index === 0) {
|
548
|
+
path.moveTo(x, y);
|
549
|
+
} else {
|
550
|
+
path.lineTo(x, y);
|
551
|
+
}
|
552
|
+
index++;
|
553
|
+
}
|
554
|
+
const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
|
555
|
+
const path = new ShapePath();
|
556
|
+
let index = 0;
|
557
|
+
node.getAttribute("points").replace(regex, iterator);
|
558
|
+
path.currentPath.autoClose = false;
|
559
|
+
return path;
|
560
|
+
}
|
561
|
+
function parseCircleNode(node) {
|
562
|
+
const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
|
563
|
+
const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
|
564
|
+
const r = parseFloatWithUnits(node.getAttribute("r") || 0);
|
565
|
+
const subpath = new Path();
|
566
|
+
subpath.absarc(x, y, r, 0, Math.PI * 2);
|
567
|
+
const path = new ShapePath();
|
568
|
+
path.subPaths.push(subpath);
|
569
|
+
return path;
|
570
|
+
}
|
571
|
+
function parseEllipseNode(node) {
|
572
|
+
const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
|
573
|
+
const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
|
574
|
+
const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
|
575
|
+
const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
|
576
|
+
const subpath = new Path();
|
577
|
+
subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
|
578
|
+
const path = new ShapePath();
|
579
|
+
path.subPaths.push(subpath);
|
580
|
+
return path;
|
581
|
+
}
|
582
|
+
function parseLineNode(node) {
|
583
|
+
const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
|
584
|
+
const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
|
585
|
+
const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
|
586
|
+
const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
|
587
|
+
const path = new ShapePath();
|
588
|
+
path.moveTo(x1, y1);
|
589
|
+
path.lineTo(x2, y2);
|
590
|
+
path.currentPath.autoClose = false;
|
591
|
+
return path;
|
592
|
+
}
|
593
|
+
function parseStyle(node, style) {
|
594
|
+
style = Object.assign({}, style);
|
595
|
+
let stylesheetStyles = {};
|
596
|
+
if (node.hasAttribute("class")) {
|
597
|
+
const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
|
598
|
+
for (let i = 0; i < classSelectors.length; i++) {
|
599
|
+
stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
|
119
600
|
}
|
120
601
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
602
|
+
if (node.hasAttribute("id")) {
|
603
|
+
stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["#" + node.getAttribute("id")]);
|
604
|
+
}
|
605
|
+
function addStyle(svgName, jsName, adjustFunction) {
|
606
|
+
if (adjustFunction === void 0)
|
607
|
+
adjustFunction = function copy(v) {
|
608
|
+
if (v.startsWith("url"))
|
609
|
+
console.warn("SVGLoader: url access in attributes is not implemented.");
|
610
|
+
return v;
|
611
|
+
};
|
612
|
+
if (node.hasAttribute(svgName))
|
613
|
+
style[jsName] = adjustFunction(node.getAttribute(svgName));
|
614
|
+
if (stylesheetStyles[svgName])
|
615
|
+
style[jsName] = adjustFunction(stylesheetStyles[svgName]);
|
616
|
+
if (node.style && node.style[svgName] !== "")
|
617
|
+
style[jsName] = adjustFunction(node.style[svgName]);
|
618
|
+
}
|
619
|
+
function clamp(v) {
|
620
|
+
return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
|
621
|
+
}
|
622
|
+
function positive(v) {
|
623
|
+
return Math.max(0, parseFloatWithUnits(v));
|
624
|
+
}
|
625
|
+
addStyle("fill", "fill");
|
626
|
+
addStyle("fill-opacity", "fillOpacity", clamp);
|
627
|
+
addStyle("fill-rule", "fillRule");
|
628
|
+
addStyle("opacity", "opacity", clamp);
|
629
|
+
addStyle("stroke", "stroke");
|
630
|
+
addStyle("stroke-opacity", "strokeOpacity", clamp);
|
631
|
+
addStyle("stroke-width", "strokeWidth", positive);
|
632
|
+
addStyle("stroke-linejoin", "strokeLineJoin");
|
633
|
+
addStyle("stroke-linecap", "strokeLineCap");
|
634
|
+
addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
|
635
|
+
addStyle("visibility", "visibility");
|
636
|
+
return style;
|
637
|
+
}
|
638
|
+
function getReflection(a, b) {
|
639
|
+
return a - (b - a);
|
640
|
+
}
|
641
|
+
function parseFloats(input, flags, stride) {
|
642
|
+
if (typeof input !== "string") {
|
643
|
+
throw new TypeError("Invalid input: " + typeof input);
|
644
|
+
}
|
645
|
+
const RE = {
|
646
|
+
SEPARATOR: /[ \t\r\n\,.\-+]/,
|
647
|
+
WHITESPACE: /[ \t\r\n]/,
|
648
|
+
DIGIT: /[\d]/,
|
649
|
+
SIGN: /[-+]/,
|
650
|
+
POINT: /\./,
|
651
|
+
COMMA: /,/,
|
652
|
+
EXP: /e/i,
|
653
|
+
FLAGS: /[01]/
|
654
|
+
};
|
655
|
+
const SEP = 0;
|
656
|
+
const INT = 1;
|
657
|
+
const FLOAT = 2;
|
658
|
+
const EXP = 3;
|
659
|
+
let state = SEP;
|
660
|
+
let seenComma = true;
|
661
|
+
let number = "", exponent = "";
|
662
|
+
const result = [];
|
663
|
+
function throwSyntaxError(current2, i, partial) {
|
664
|
+
const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
|
665
|
+
error.partial = partial;
|
666
|
+
throw error;
|
667
|
+
}
|
668
|
+
function newNumber() {
|
669
|
+
if (number !== "") {
|
670
|
+
if (exponent === "")
|
671
|
+
result.push(Number(number));
|
672
|
+
else
|
673
|
+
result.push(Number(number) * Math.pow(10, Number(exponent)));
|
674
|
+
}
|
675
|
+
number = "";
|
676
|
+
exponent = "";
|
677
|
+
}
|
678
|
+
let current;
|
679
|
+
const length = input.length;
|
680
|
+
for (let i = 0; i < length; i++) {
|
681
|
+
current = input[i];
|
682
|
+
if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
|
683
|
+
state = INT;
|
684
|
+
number = current;
|
685
|
+
newNumber();
|
686
|
+
continue;
|
687
|
+
}
|
688
|
+
if (state === SEP) {
|
689
|
+
if (RE.WHITESPACE.test(current)) {
|
690
|
+
continue;
|
139
691
|
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
145
|
-
point.x = numbers[j + 0];
|
146
|
-
point.y = numbers[j + 1];
|
147
|
-
control.x = point.x;
|
148
|
-
control.y = point.y;
|
149
|
-
if (j === 0) {
|
150
|
-
path.moveTo(point.x, point.y);
|
151
|
-
} else {
|
152
|
-
path.lineTo(point.x, point.y);
|
153
|
-
}
|
154
|
-
if (j === 0)
|
155
|
-
firstPoint.copy(point);
|
156
|
-
}
|
157
|
-
break;
|
158
|
-
case "H":
|
159
|
-
numbers = parseFloats(data2);
|
160
|
-
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
161
|
-
point.x = numbers[j];
|
162
|
-
control.x = point.x;
|
163
|
-
control.y = point.y;
|
164
|
-
path.lineTo(point.x, point.y);
|
165
|
-
if (j === 0 && doSetFirstPoint === true)
|
166
|
-
firstPoint.copy(point);
|
167
|
-
}
|
168
|
-
break;
|
169
|
-
case "V":
|
170
|
-
numbers = parseFloats(data2);
|
171
|
-
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
172
|
-
point.y = numbers[j];
|
173
|
-
control.x = point.x;
|
174
|
-
control.y = point.y;
|
175
|
-
path.lineTo(point.x, point.y);
|
176
|
-
if (j === 0 && doSetFirstPoint === true)
|
177
|
-
firstPoint.copy(point);
|
178
|
-
}
|
179
|
-
break;
|
180
|
-
case "L":
|
181
|
-
numbers = parseFloats(data2);
|
182
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
183
|
-
point.x = numbers[j + 0];
|
184
|
-
point.y = numbers[j + 1];
|
185
|
-
control.x = point.x;
|
186
|
-
control.y = point.y;
|
187
|
-
path.lineTo(point.x, point.y);
|
188
|
-
if (j === 0 && doSetFirstPoint === true)
|
189
|
-
firstPoint.copy(point);
|
190
|
-
}
|
191
|
-
break;
|
192
|
-
case "C":
|
193
|
-
numbers = parseFloats(data2);
|
194
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 6) {
|
195
|
-
path.bezierCurveTo(
|
196
|
-
numbers[j + 0],
|
197
|
-
numbers[j + 1],
|
198
|
-
numbers[j + 2],
|
199
|
-
numbers[j + 3],
|
200
|
-
numbers[j + 4],
|
201
|
-
numbers[j + 5]
|
202
|
-
);
|
203
|
-
control.x = numbers[j + 2];
|
204
|
-
control.y = numbers[j + 3];
|
205
|
-
point.x = numbers[j + 4];
|
206
|
-
point.y = numbers[j + 5];
|
207
|
-
if (j === 0 && doSetFirstPoint === true)
|
208
|
-
firstPoint.copy(point);
|
209
|
-
}
|
210
|
-
break;
|
211
|
-
case "S":
|
212
|
-
numbers = parseFloats(data2);
|
213
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
214
|
-
path.bezierCurveTo(
|
215
|
-
getReflection(point.x, control.x),
|
216
|
-
getReflection(point.y, control.y),
|
217
|
-
numbers[j + 0],
|
218
|
-
numbers[j + 1],
|
219
|
-
numbers[j + 2],
|
220
|
-
numbers[j + 3]
|
221
|
-
);
|
222
|
-
control.x = numbers[j + 0];
|
223
|
-
control.y = numbers[j + 1];
|
224
|
-
point.x = numbers[j + 2];
|
225
|
-
point.y = numbers[j + 3];
|
226
|
-
if (j === 0 && doSetFirstPoint === true)
|
227
|
-
firstPoint.copy(point);
|
228
|
-
}
|
229
|
-
break;
|
230
|
-
case "Q":
|
231
|
-
numbers = parseFloats(data2);
|
232
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
233
|
-
path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
|
234
|
-
control.x = numbers[j + 0];
|
235
|
-
control.y = numbers[j + 1];
|
236
|
-
point.x = numbers[j + 2];
|
237
|
-
point.y = numbers[j + 3];
|
238
|
-
if (j === 0 && doSetFirstPoint === true)
|
239
|
-
firstPoint.copy(point);
|
240
|
-
}
|
241
|
-
break;
|
242
|
-
case "T":
|
243
|
-
numbers = parseFloats(data2);
|
244
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
245
|
-
const rx = getReflection(point.x, control.x);
|
246
|
-
const ry = getReflection(point.y, control.y);
|
247
|
-
path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
|
248
|
-
control.x = rx;
|
249
|
-
control.y = ry;
|
250
|
-
point.x = numbers[j + 0];
|
251
|
-
point.y = numbers[j + 1];
|
252
|
-
if (j === 0 && doSetFirstPoint === true)
|
253
|
-
firstPoint.copy(point);
|
254
|
-
}
|
255
|
-
break;
|
256
|
-
case "A":
|
257
|
-
numbers = parseFloats(data2, [3, 4], 7);
|
258
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 7) {
|
259
|
-
if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
|
260
|
-
continue;
|
261
|
-
const start = point.clone();
|
262
|
-
point.x = numbers[j + 5];
|
263
|
-
point.y = numbers[j + 6];
|
264
|
-
control.x = point.x;
|
265
|
-
control.y = point.y;
|
266
|
-
parseArcCommand(
|
267
|
-
path,
|
268
|
-
numbers[j],
|
269
|
-
numbers[j + 1],
|
270
|
-
numbers[j + 2],
|
271
|
-
numbers[j + 3],
|
272
|
-
numbers[j + 4],
|
273
|
-
start,
|
274
|
-
point
|
275
|
-
);
|
276
|
-
if (j === 0 && doSetFirstPoint === true)
|
277
|
-
firstPoint.copy(point);
|
278
|
-
}
|
279
|
-
break;
|
280
|
-
case "m":
|
281
|
-
numbers = parseFloats(data2);
|
282
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
283
|
-
point.x += numbers[j + 0];
|
284
|
-
point.y += numbers[j + 1];
|
285
|
-
control.x = point.x;
|
286
|
-
control.y = point.y;
|
287
|
-
if (j === 0) {
|
288
|
-
path.moveTo(point.x, point.y);
|
289
|
-
} else {
|
290
|
-
path.lineTo(point.x, point.y);
|
291
|
-
}
|
292
|
-
if (j === 0)
|
293
|
-
firstPoint.copy(point);
|
294
|
-
}
|
295
|
-
break;
|
296
|
-
case "h":
|
297
|
-
numbers = parseFloats(data2);
|
298
|
-
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
299
|
-
point.x += numbers[j];
|
300
|
-
control.x = point.x;
|
301
|
-
control.y = point.y;
|
302
|
-
path.lineTo(point.x, point.y);
|
303
|
-
if (j === 0 && doSetFirstPoint === true)
|
304
|
-
firstPoint.copy(point);
|
305
|
-
}
|
306
|
-
break;
|
307
|
-
case "v":
|
308
|
-
numbers = parseFloats(data2);
|
309
|
-
for (let j = 0, jl = numbers.length; j < jl; j++) {
|
310
|
-
point.y += numbers[j];
|
311
|
-
control.x = point.x;
|
312
|
-
control.y = point.y;
|
313
|
-
path.lineTo(point.x, point.y);
|
314
|
-
if (j === 0 && doSetFirstPoint === true)
|
315
|
-
firstPoint.copy(point);
|
316
|
-
}
|
317
|
-
break;
|
318
|
-
case "l":
|
319
|
-
numbers = parseFloats(data2);
|
320
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
321
|
-
point.x += numbers[j + 0];
|
322
|
-
point.y += numbers[j + 1];
|
323
|
-
control.x = point.x;
|
324
|
-
control.y = point.y;
|
325
|
-
path.lineTo(point.x, point.y);
|
326
|
-
if (j === 0 && doSetFirstPoint === true)
|
327
|
-
firstPoint.copy(point);
|
328
|
-
}
|
329
|
-
break;
|
330
|
-
case "c":
|
331
|
-
numbers = parseFloats(data2);
|
332
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 6) {
|
333
|
-
path.bezierCurveTo(
|
334
|
-
point.x + numbers[j + 0],
|
335
|
-
point.y + numbers[j + 1],
|
336
|
-
point.x + numbers[j + 2],
|
337
|
-
point.y + numbers[j + 3],
|
338
|
-
point.x + numbers[j + 4],
|
339
|
-
point.y + numbers[j + 5]
|
340
|
-
);
|
341
|
-
control.x = point.x + numbers[j + 2];
|
342
|
-
control.y = point.y + numbers[j + 3];
|
343
|
-
point.x += numbers[j + 4];
|
344
|
-
point.y += numbers[j + 5];
|
345
|
-
if (j === 0 && doSetFirstPoint === true)
|
346
|
-
firstPoint.copy(point);
|
347
|
-
}
|
348
|
-
break;
|
349
|
-
case "s":
|
350
|
-
numbers = parseFloats(data2);
|
351
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
352
|
-
path.bezierCurveTo(
|
353
|
-
getReflection(point.x, control.x),
|
354
|
-
getReflection(point.y, control.y),
|
355
|
-
point.x + numbers[j + 0],
|
356
|
-
point.y + numbers[j + 1],
|
357
|
-
point.x + numbers[j + 2],
|
358
|
-
point.y + numbers[j + 3]
|
359
|
-
);
|
360
|
-
control.x = point.x + numbers[j + 0];
|
361
|
-
control.y = point.y + numbers[j + 1];
|
362
|
-
point.x += numbers[j + 2];
|
363
|
-
point.y += numbers[j + 3];
|
364
|
-
if (j === 0 && doSetFirstPoint === true)
|
365
|
-
firstPoint.copy(point);
|
366
|
-
}
|
367
|
-
break;
|
368
|
-
case "q":
|
369
|
-
numbers = parseFloats(data2);
|
370
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 4) {
|
371
|
-
path.quadraticCurveTo(
|
372
|
-
point.x + numbers[j + 0],
|
373
|
-
point.y + numbers[j + 1],
|
374
|
-
point.x + numbers[j + 2],
|
375
|
-
point.y + numbers[j + 3]
|
376
|
-
);
|
377
|
-
control.x = point.x + numbers[j + 0];
|
378
|
-
control.y = point.y + numbers[j + 1];
|
379
|
-
point.x += numbers[j + 2];
|
380
|
-
point.y += numbers[j + 3];
|
381
|
-
if (j === 0 && doSetFirstPoint === true)
|
382
|
-
firstPoint.copy(point);
|
383
|
-
}
|
384
|
-
break;
|
385
|
-
case "t":
|
386
|
-
numbers = parseFloats(data2);
|
387
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 2) {
|
388
|
-
const rx = getReflection(point.x, control.x);
|
389
|
-
const ry = getReflection(point.y, control.y);
|
390
|
-
path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
|
391
|
-
control.x = rx;
|
392
|
-
control.y = ry;
|
393
|
-
point.x = point.x + numbers[j + 0];
|
394
|
-
point.y = point.y + numbers[j + 1];
|
395
|
-
if (j === 0 && doSetFirstPoint === true)
|
396
|
-
firstPoint.copy(point);
|
397
|
-
}
|
398
|
-
break;
|
399
|
-
case "a":
|
400
|
-
numbers = parseFloats(data2, [3, 4], 7);
|
401
|
-
for (let j = 0, jl = numbers.length; j < jl; j += 7) {
|
402
|
-
if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
|
403
|
-
continue;
|
404
|
-
const start = point.clone();
|
405
|
-
point.x += numbers[j + 5];
|
406
|
-
point.y += numbers[j + 6];
|
407
|
-
control.x = point.x;
|
408
|
-
control.y = point.y;
|
409
|
-
parseArcCommand(
|
410
|
-
path,
|
411
|
-
numbers[j],
|
412
|
-
numbers[j + 1],
|
413
|
-
numbers[j + 2],
|
414
|
-
numbers[j + 3],
|
415
|
-
numbers[j + 4],
|
416
|
-
start,
|
417
|
-
point
|
418
|
-
);
|
419
|
-
if (j === 0 && doSetFirstPoint === true)
|
420
|
-
firstPoint.copy(point);
|
421
|
-
}
|
422
|
-
break;
|
423
|
-
case "Z":
|
424
|
-
case "z":
|
425
|
-
path.currentPath.autoClose = true;
|
426
|
-
if (path.currentPath.curves.length > 0) {
|
427
|
-
point.copy(firstPoint);
|
428
|
-
path.currentPath.currentPoint.copy(point);
|
429
|
-
isFirstPoint = true;
|
430
|
-
}
|
431
|
-
break;
|
432
|
-
default:
|
433
|
-
console.warn(command);
|
692
|
+
if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
|
693
|
+
state = INT;
|
694
|
+
number = current;
|
695
|
+
continue;
|
434
696
|
}
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
}
|
439
|
-
function parseCSSStylesheet(node) {
|
440
|
-
if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
|
441
|
-
return;
|
442
|
-
for (let i = 0; i < node.sheet.cssRules.length; i++) {
|
443
|
-
const stylesheet = node.sheet.cssRules[i];
|
444
|
-
if (stylesheet.type !== 1)
|
697
|
+
if (RE.POINT.test(current)) {
|
698
|
+
state = FLOAT;
|
699
|
+
number = current;
|
445
700
|
continue;
|
446
|
-
const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
|
447
|
-
for (let j = 0; j < selectorList.length; j++) {
|
448
|
-
const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
|
449
|
-
stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
|
450
701
|
}
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
return;
|
457
|
-
}
|
458
|
-
x_axis_rotation = x_axis_rotation * Math.PI / 180;
|
459
|
-
rx = Math.abs(rx);
|
460
|
-
ry = Math.abs(ry);
|
461
|
-
const dx2 = (start.x - end.x) / 2;
|
462
|
-
const dy2 = (start.y - end.y) / 2;
|
463
|
-
const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
|
464
|
-
const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
|
465
|
-
let rxs = rx * rx;
|
466
|
-
let rys = ry * ry;
|
467
|
-
const x1ps = x1p * x1p;
|
468
|
-
const y1ps = y1p * y1p;
|
469
|
-
const cr = x1ps / rxs + y1ps / rys;
|
470
|
-
if (cr > 1) {
|
471
|
-
const s = Math.sqrt(cr);
|
472
|
-
rx = s * rx;
|
473
|
-
ry = s * ry;
|
474
|
-
rxs = rx * rx;
|
475
|
-
rys = ry * ry;
|
476
|
-
}
|
477
|
-
const dq = rxs * y1ps + rys * x1ps;
|
478
|
-
const pq = (rxs * rys - dq) / dq;
|
479
|
-
let q = Math.sqrt(Math.max(0, pq));
|
480
|
-
if (large_arc_flag === sweep_flag)
|
481
|
-
q = -q;
|
482
|
-
const cxp = q * rx * y1p / ry;
|
483
|
-
const cyp = -q * ry * x1p / rx;
|
484
|
-
const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
|
485
|
-
const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
|
486
|
-
const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
|
487
|
-
const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
|
488
|
-
path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
|
489
|
-
}
|
490
|
-
function svgAngle(ux, uy, vx, vy) {
|
491
|
-
const dot = ux * vx + uy * vy;
|
492
|
-
const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
|
493
|
-
let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
|
494
|
-
if (ux * vy - uy * vx < 0)
|
495
|
-
ang = -ang;
|
496
|
-
return ang;
|
497
|
-
}
|
498
|
-
function parseRectNode(node) {
|
499
|
-
const x = parseFloatWithUnits(node.getAttribute("x") || 0);
|
500
|
-
const y = parseFloatWithUnits(node.getAttribute("y") || 0);
|
501
|
-
const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
|
502
|
-
const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
|
503
|
-
const w = parseFloatWithUnits(node.getAttribute("width"));
|
504
|
-
const h = parseFloatWithUnits(node.getAttribute("height"));
|
505
|
-
const bci = 1 - 0.551915024494;
|
506
|
-
const path = new ShapePath();
|
507
|
-
path.moveTo(x + rx, y);
|
508
|
-
path.lineTo(x + w - rx, y);
|
509
|
-
if (rx !== 0 || ry !== 0) {
|
510
|
-
path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
|
511
|
-
}
|
512
|
-
path.lineTo(x + w, y + h - ry);
|
513
|
-
if (rx !== 0 || ry !== 0) {
|
514
|
-
path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
|
515
|
-
}
|
516
|
-
path.lineTo(x + rx, y + h);
|
517
|
-
if (rx !== 0 || ry !== 0) {
|
518
|
-
path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
|
519
|
-
}
|
520
|
-
path.lineTo(x, y + ry);
|
521
|
-
if (rx !== 0 || ry !== 0) {
|
522
|
-
path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
|
523
|
-
}
|
524
|
-
return path;
|
525
|
-
}
|
526
|
-
function parsePolygonNode(node) {
|
527
|
-
function iterator(match, a, b) {
|
528
|
-
const x = parseFloatWithUnits(a);
|
529
|
-
const y = parseFloatWithUnits(b);
|
530
|
-
if (index === 0) {
|
531
|
-
path.moveTo(x, y);
|
532
|
-
} else {
|
533
|
-
path.lineTo(x, y);
|
702
|
+
if (RE.COMMA.test(current)) {
|
703
|
+
if (seenComma) {
|
704
|
+
throwSyntaxError(current, i, result);
|
705
|
+
}
|
706
|
+
seenComma = true;
|
534
707
|
}
|
535
|
-
index++;
|
536
708
|
}
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
path.currentPath.autoClose = true;
|
542
|
-
return path;
|
543
|
-
}
|
544
|
-
function parsePolylineNode(node) {
|
545
|
-
function iterator(match, a, b) {
|
546
|
-
const x = parseFloatWithUnits(a);
|
547
|
-
const y = parseFloatWithUnits(b);
|
548
|
-
if (index === 0) {
|
549
|
-
path.moveTo(x, y);
|
550
|
-
} else {
|
551
|
-
path.lineTo(x, y);
|
709
|
+
if (state === INT) {
|
710
|
+
if (RE.DIGIT.test(current)) {
|
711
|
+
number += current;
|
712
|
+
continue;
|
552
713
|
}
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
let index = 0;
|
558
|
-
node.getAttribute("points").replace(regex, iterator);
|
559
|
-
path.currentPath.autoClose = false;
|
560
|
-
return path;
|
561
|
-
}
|
562
|
-
function parseCircleNode(node) {
|
563
|
-
const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
|
564
|
-
const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
|
565
|
-
const r = parseFloatWithUnits(node.getAttribute("r") || 0);
|
566
|
-
const subpath = new Path();
|
567
|
-
subpath.absarc(x, y, r, 0, Math.PI * 2);
|
568
|
-
const path = new ShapePath();
|
569
|
-
path.subPaths.push(subpath);
|
570
|
-
return path;
|
571
|
-
}
|
572
|
-
function parseEllipseNode(node) {
|
573
|
-
const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
|
574
|
-
const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
|
575
|
-
const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
|
576
|
-
const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
|
577
|
-
const subpath = new Path();
|
578
|
-
subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
|
579
|
-
const path = new ShapePath();
|
580
|
-
path.subPaths.push(subpath);
|
581
|
-
return path;
|
582
|
-
}
|
583
|
-
function parseLineNode(node) {
|
584
|
-
const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
|
585
|
-
const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
|
586
|
-
const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
|
587
|
-
const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
|
588
|
-
const path = new ShapePath();
|
589
|
-
path.moveTo(x1, y1);
|
590
|
-
path.lineTo(x2, y2);
|
591
|
-
path.currentPath.autoClose = false;
|
592
|
-
return path;
|
593
|
-
}
|
594
|
-
function parseStyle(node, style) {
|
595
|
-
style = Object.assign({}, style);
|
596
|
-
let stylesheetStyles = {};
|
597
|
-
if (node.hasAttribute("class")) {
|
598
|
-
const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
|
599
|
-
for (let i = 0; i < classSelectors.length; i++) {
|
600
|
-
stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
|
714
|
+
if (RE.POINT.test(current)) {
|
715
|
+
number += current;
|
716
|
+
state = FLOAT;
|
717
|
+
continue;
|
601
718
|
}
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
adjustFunction = function copy(v) {
|
609
|
-
if (v.startsWith("url"))
|
610
|
-
console.warn("SVGLoader: url access in attributes is not implemented.");
|
611
|
-
return v;
|
612
|
-
};
|
613
|
-
if (node.hasAttribute(svgName))
|
614
|
-
style[jsName] = adjustFunction(node.getAttribute(svgName));
|
615
|
-
if (stylesheetStyles[svgName])
|
616
|
-
style[jsName] = adjustFunction(stylesheetStyles[svgName]);
|
617
|
-
if (node.style && node.style[svgName] !== "")
|
618
|
-
style[jsName] = adjustFunction(node.style[svgName]);
|
619
|
-
}
|
620
|
-
function clamp(v) {
|
621
|
-
return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
|
622
|
-
}
|
623
|
-
function positive(v) {
|
624
|
-
return Math.max(0, parseFloatWithUnits(v));
|
625
|
-
}
|
626
|
-
addStyle("fill", "fill");
|
627
|
-
addStyle("fill-opacity", "fillOpacity", clamp);
|
628
|
-
addStyle("fill-rule", "fillRule");
|
629
|
-
addStyle("opacity", "opacity", clamp);
|
630
|
-
addStyle("stroke", "stroke");
|
631
|
-
addStyle("stroke-opacity", "strokeOpacity", clamp);
|
632
|
-
addStyle("stroke-width", "strokeWidth", positive);
|
633
|
-
addStyle("stroke-linejoin", "strokeLineJoin");
|
634
|
-
addStyle("stroke-linecap", "strokeLineCap");
|
635
|
-
addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
|
636
|
-
addStyle("visibility", "visibility");
|
637
|
-
return style;
|
638
|
-
}
|
639
|
-
function getReflection(a, b) {
|
640
|
-
return a - (b - a);
|
641
|
-
}
|
642
|
-
function parseFloats(input, flags, stride) {
|
643
|
-
if (typeof input !== "string") {
|
644
|
-
throw new TypeError("Invalid input: " + typeof input);
|
645
|
-
}
|
646
|
-
const RE = {
|
647
|
-
SEPARATOR: /[ \t\r\n\,.\-+]/,
|
648
|
-
WHITESPACE: /[ \t\r\n]/,
|
649
|
-
DIGIT: /[\d]/,
|
650
|
-
SIGN: /[-+]/,
|
651
|
-
POINT: /\./,
|
652
|
-
COMMA: /,/,
|
653
|
-
EXP: /e/i,
|
654
|
-
FLAGS: /[01]/
|
655
|
-
};
|
656
|
-
const SEP = 0;
|
657
|
-
const INT = 1;
|
658
|
-
const FLOAT = 2;
|
659
|
-
const EXP = 3;
|
660
|
-
let state = SEP;
|
661
|
-
let seenComma = true;
|
662
|
-
let number = "", exponent = "";
|
663
|
-
const result = [];
|
664
|
-
function throwSyntaxError(current2, i, partial) {
|
665
|
-
const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
|
666
|
-
error.partial = partial;
|
667
|
-
throw error;
|
668
|
-
}
|
669
|
-
function newNumber() {
|
670
|
-
if (number !== "") {
|
671
|
-
if (exponent === "")
|
672
|
-
result.push(Number(number));
|
673
|
-
else
|
674
|
-
result.push(Number(number) * Math.pow(10, Number(exponent)));
|
719
|
+
if (RE.EXP.test(current)) {
|
720
|
+
state = EXP;
|
721
|
+
continue;
|
722
|
+
}
|
723
|
+
if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
|
724
|
+
throwSyntaxError(current, i, result);
|
675
725
|
}
|
676
|
-
number = "";
|
677
|
-
exponent = "";
|
678
726
|
}
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
current = input[i];
|
683
|
-
if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
|
684
|
-
state = INT;
|
685
|
-
number = current;
|
686
|
-
newNumber();
|
727
|
+
if (state === FLOAT) {
|
728
|
+
if (RE.DIGIT.test(current)) {
|
729
|
+
number += current;
|
687
730
|
continue;
|
688
731
|
}
|
689
|
-
if (
|
690
|
-
|
691
|
-
|
692
|
-
}
|
693
|
-
if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
|
694
|
-
state = INT;
|
695
|
-
number = current;
|
696
|
-
continue;
|
697
|
-
}
|
698
|
-
if (RE.POINT.test(current)) {
|
699
|
-
state = FLOAT;
|
700
|
-
number = current;
|
701
|
-
continue;
|
702
|
-
}
|
703
|
-
if (RE.COMMA.test(current)) {
|
704
|
-
if (seenComma) {
|
705
|
-
throwSyntaxError(current, i, result);
|
706
|
-
}
|
707
|
-
seenComma = true;
|
708
|
-
}
|
732
|
+
if (RE.EXP.test(current)) {
|
733
|
+
state = EXP;
|
734
|
+
continue;
|
709
735
|
}
|
710
|
-
if (
|
711
|
-
|
712
|
-
number += current;
|
713
|
-
continue;
|
714
|
-
}
|
715
|
-
if (RE.POINT.test(current)) {
|
716
|
-
number += current;
|
717
|
-
state = FLOAT;
|
718
|
-
continue;
|
719
|
-
}
|
720
|
-
if (RE.EXP.test(current)) {
|
721
|
-
state = EXP;
|
722
|
-
continue;
|
723
|
-
}
|
724
|
-
if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
|
725
|
-
throwSyntaxError(current, i, result);
|
726
|
-
}
|
736
|
+
if (RE.POINT.test(current) && number[number.length - 1] === ".") {
|
737
|
+
throwSyntaxError(current, i, result);
|
727
738
|
}
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
if (RE.EXP.test(current)) {
|
734
|
-
state = EXP;
|
735
|
-
continue;
|
736
|
-
}
|
737
|
-
if (RE.POINT.test(current) && number[number.length - 1] === ".") {
|
738
|
-
throwSyntaxError(current, i, result);
|
739
|
-
}
|
739
|
+
}
|
740
|
+
if (state === EXP) {
|
741
|
+
if (RE.DIGIT.test(current)) {
|
742
|
+
exponent += current;
|
743
|
+
continue;
|
740
744
|
}
|
741
|
-
if (
|
742
|
-
if (
|
745
|
+
if (RE.SIGN.test(current)) {
|
746
|
+
if (exponent === "") {
|
743
747
|
exponent += current;
|
744
748
|
continue;
|
745
749
|
}
|
746
|
-
if (RE.SIGN.test(
|
747
|
-
|
748
|
-
exponent += current;
|
749
|
-
continue;
|
750
|
-
}
|
751
|
-
if (exponent.length === 1 && RE.SIGN.test(exponent)) {
|
752
|
-
throwSyntaxError(current, i, result);
|
753
|
-
}
|
754
|
-
}
|
755
|
-
}
|
756
|
-
if (RE.WHITESPACE.test(current)) {
|
757
|
-
newNumber();
|
758
|
-
state = SEP;
|
759
|
-
seenComma = false;
|
760
|
-
} else if (RE.COMMA.test(current)) {
|
761
|
-
newNumber();
|
762
|
-
state = SEP;
|
763
|
-
seenComma = true;
|
764
|
-
} else if (RE.SIGN.test(current)) {
|
765
|
-
newNumber();
|
766
|
-
state = INT;
|
767
|
-
number = current;
|
768
|
-
} else if (RE.POINT.test(current)) {
|
769
|
-
newNumber();
|
770
|
-
state = FLOAT;
|
771
|
-
number = current;
|
772
|
-
} else {
|
773
|
-
throwSyntaxError(current, i, result);
|
774
|
-
}
|
775
|
-
}
|
776
|
-
newNumber();
|
777
|
-
return result;
|
778
|
-
}
|
779
|
-
const units = ["mm", "cm", "in", "pt", "pc", "px"];
|
780
|
-
const unitConversion = {
|
781
|
-
mm: {
|
782
|
-
mm: 1,
|
783
|
-
cm: 0.1,
|
784
|
-
in: 1 / 25.4,
|
785
|
-
pt: 72 / 25.4,
|
786
|
-
pc: 6 / 25.4,
|
787
|
-
px: -1
|
788
|
-
},
|
789
|
-
cm: {
|
790
|
-
mm: 10,
|
791
|
-
cm: 1,
|
792
|
-
in: 1 / 2.54,
|
793
|
-
pt: 72 / 2.54,
|
794
|
-
pc: 6 / 2.54,
|
795
|
-
px: -1
|
796
|
-
},
|
797
|
-
in: {
|
798
|
-
mm: 25.4,
|
799
|
-
cm: 2.54,
|
800
|
-
in: 1,
|
801
|
-
pt: 72,
|
802
|
-
pc: 6,
|
803
|
-
px: -1
|
804
|
-
},
|
805
|
-
pt: {
|
806
|
-
mm: 25.4 / 72,
|
807
|
-
cm: 2.54 / 72,
|
808
|
-
in: 1 / 72,
|
809
|
-
pt: 1,
|
810
|
-
pc: 6 / 72,
|
811
|
-
px: -1
|
812
|
-
},
|
813
|
-
pc: {
|
814
|
-
mm: 25.4 / 6,
|
815
|
-
cm: 2.54 / 6,
|
816
|
-
in: 1 / 6,
|
817
|
-
pt: 72 / 6,
|
818
|
-
pc: 1,
|
819
|
-
px: -1
|
820
|
-
},
|
821
|
-
px: {
|
822
|
-
px: 1
|
823
|
-
}
|
824
|
-
};
|
825
|
-
function parseFloatWithUnits(string) {
|
826
|
-
let theUnit = "px";
|
827
|
-
if (typeof string === "string" || string instanceof String) {
|
828
|
-
for (let i = 0, n = units.length; i < n; i++) {
|
829
|
-
const u = units[i];
|
830
|
-
if (string.endsWith(u)) {
|
831
|
-
theUnit = u;
|
832
|
-
string = string.substring(0, string.length - u.length);
|
833
|
-
break;
|
750
|
+
if (exponent.length === 1 && RE.SIGN.test(exponent)) {
|
751
|
+
throwSyntaxError(current, i, result);
|
834
752
|
}
|
835
753
|
}
|
836
754
|
}
|
837
|
-
|
838
|
-
|
839
|
-
|
755
|
+
if (RE.WHITESPACE.test(current)) {
|
756
|
+
newNumber();
|
757
|
+
state = SEP;
|
758
|
+
seenComma = false;
|
759
|
+
} else if (RE.COMMA.test(current)) {
|
760
|
+
newNumber();
|
761
|
+
state = SEP;
|
762
|
+
seenComma = true;
|
763
|
+
} else if (RE.SIGN.test(current)) {
|
764
|
+
newNumber();
|
765
|
+
state = INT;
|
766
|
+
number = current;
|
767
|
+
} else if (RE.POINT.test(current)) {
|
768
|
+
newNumber();
|
769
|
+
state = FLOAT;
|
770
|
+
number = current;
|
840
771
|
} else {
|
841
|
-
|
842
|
-
if (scale < 0) {
|
843
|
-
scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
|
844
|
-
}
|
772
|
+
throwSyntaxError(current, i, result);
|
845
773
|
}
|
846
|
-
return scale * parseFloat(string);
|
847
774
|
}
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
775
|
+
newNumber();
|
776
|
+
return result;
|
777
|
+
}
|
778
|
+
const units = ["mm", "cm", "in", "pt", "pc", "px"];
|
779
|
+
const unitConversion = {
|
780
|
+
mm: {
|
781
|
+
mm: 1,
|
782
|
+
cm: 0.1,
|
783
|
+
in: 1 / 25.4,
|
784
|
+
pt: 72 / 25.4,
|
785
|
+
pc: 6 / 25.4,
|
786
|
+
px: -1
|
787
|
+
},
|
788
|
+
cm: {
|
789
|
+
mm: 10,
|
790
|
+
cm: 1,
|
791
|
+
in: 1 / 2.54,
|
792
|
+
pt: 72 / 2.54,
|
793
|
+
pc: 6 / 2.54,
|
794
|
+
px: -1
|
795
|
+
},
|
796
|
+
in: {
|
797
|
+
mm: 25.4,
|
798
|
+
cm: 2.54,
|
799
|
+
in: 1,
|
800
|
+
pt: 72,
|
801
|
+
pc: 6,
|
802
|
+
px: -1
|
803
|
+
},
|
804
|
+
pt: {
|
805
|
+
mm: 25.4 / 72,
|
806
|
+
cm: 2.54 / 72,
|
807
|
+
in: 1 / 72,
|
808
|
+
pt: 1,
|
809
|
+
pc: 6 / 72,
|
810
|
+
px: -1
|
811
|
+
},
|
812
|
+
pc: {
|
813
|
+
mm: 25.4 / 6,
|
814
|
+
cm: 2.54 / 6,
|
815
|
+
in: 1 / 6,
|
816
|
+
pt: 72 / 6,
|
817
|
+
pc: 1,
|
818
|
+
px: -1
|
819
|
+
},
|
820
|
+
px: {
|
821
|
+
px: 1
|
822
|
+
}
|
823
|
+
};
|
824
|
+
function parseFloatWithUnits(string) {
|
825
|
+
let theUnit = "px";
|
826
|
+
if (typeof string === "string" || string instanceof String) {
|
827
|
+
for (let i = 0, n = units.length; i < n; i++) {
|
828
|
+
const u = units[i];
|
829
|
+
if (string.endsWith(u)) {
|
830
|
+
theUnit = u;
|
831
|
+
string = string.substring(0, string.length - u.length);
|
832
|
+
break;
|
833
|
+
}
|
855
834
|
}
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
const tx = parseFloatWithUnits(node.getAttribute("x"));
|
865
|
-
const ty = parseFloatWithUnits(node.getAttribute("y"));
|
866
|
-
transform.translate(tx, ty);
|
835
|
+
}
|
836
|
+
let scale = void 0;
|
837
|
+
if (theUnit === "px" && scope.defaultUnit !== "px") {
|
838
|
+
scale = unitConversion["in"][scope.defaultUnit] / scope.defaultDPI;
|
839
|
+
} else {
|
840
|
+
scale = unitConversion[theUnit][scope.defaultUnit];
|
841
|
+
if (scale < 0) {
|
842
|
+
scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
|
867
843
|
}
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
const scaleX = array[0];
|
911
|
-
let scaleY = scaleX;
|
912
|
-
if (array.length >= 2) {
|
913
|
-
scaleY = array[1];
|
914
|
-
}
|
915
|
-
currentTransform2.scale(scaleX, scaleY);
|
916
|
-
}
|
917
|
-
break;
|
918
|
-
case "skewX":
|
919
|
-
if (array.length === 1) {
|
920
|
-
currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
|
844
|
+
}
|
845
|
+
return scale * parseFloat(string);
|
846
|
+
}
|
847
|
+
function getNodeTransform(node) {
|
848
|
+
if (!(node.hasAttribute("transform") || node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y")))) {
|
849
|
+
return null;
|
850
|
+
}
|
851
|
+
const transform = parseNodeTransform(node);
|
852
|
+
if (transformStack.length > 0) {
|
853
|
+
transform.premultiply(transformStack[transformStack.length - 1]);
|
854
|
+
}
|
855
|
+
currentTransform.copy(transform);
|
856
|
+
transformStack.push(transform);
|
857
|
+
return transform;
|
858
|
+
}
|
859
|
+
function parseNodeTransform(node) {
|
860
|
+
const transform = new Matrix3();
|
861
|
+
const currentTransform2 = tempTransform0;
|
862
|
+
if (node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y"))) {
|
863
|
+
const tx = parseFloatWithUnits(node.getAttribute("x"));
|
864
|
+
const ty = parseFloatWithUnits(node.getAttribute("y"));
|
865
|
+
transform.translate(tx, ty);
|
866
|
+
}
|
867
|
+
if (node.hasAttribute("transform")) {
|
868
|
+
const transformsTexts = node.getAttribute("transform").split(")");
|
869
|
+
for (let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
|
870
|
+
const transformText = transformsTexts[tIndex].trim();
|
871
|
+
if (transformText === "")
|
872
|
+
continue;
|
873
|
+
const openParPos = transformText.indexOf("(");
|
874
|
+
const closeParPos = transformText.length;
|
875
|
+
if (openParPos > 0 && openParPos < closeParPos) {
|
876
|
+
const transformType = transformText.slice(0, openParPos);
|
877
|
+
const array = parseFloats(transformText.slice(openParPos + 1));
|
878
|
+
currentTransform2.identity();
|
879
|
+
switch (transformType) {
|
880
|
+
case "translate":
|
881
|
+
if (array.length >= 1) {
|
882
|
+
const tx = array[0];
|
883
|
+
let ty = 0;
|
884
|
+
if (array.length >= 2) {
|
885
|
+
ty = array[1];
|
921
886
|
}
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
887
|
+
currentTransform2.translate(tx, ty);
|
888
|
+
}
|
889
|
+
break;
|
890
|
+
case "rotate":
|
891
|
+
if (array.length >= 1) {
|
892
|
+
let angle = 0;
|
893
|
+
let cx = 0;
|
894
|
+
let cy = 0;
|
895
|
+
angle = array[0] * Math.PI / 180;
|
896
|
+
if (array.length >= 3) {
|
897
|
+
cx = array[1];
|
898
|
+
cy = array[2];
|
926
899
|
}
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
900
|
+
tempTransform1.makeTranslation(-cx, -cy);
|
901
|
+
tempTransform2.makeRotation(angle);
|
902
|
+
tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
|
903
|
+
tempTransform1.makeTranslation(cx, cy);
|
904
|
+
currentTransform2.multiplyMatrices(tempTransform1, tempTransform3);
|
905
|
+
}
|
906
|
+
break;
|
907
|
+
case "scale":
|
908
|
+
if (array.length >= 1) {
|
909
|
+
const scaleX = array[0];
|
910
|
+
let scaleY = scaleX;
|
911
|
+
if (array.length >= 2) {
|
912
|
+
scaleY = array[1];
|
931
913
|
}
|
932
|
-
|
933
|
-
|
914
|
+
currentTransform2.scale(scaleX, scaleY);
|
915
|
+
}
|
916
|
+
break;
|
917
|
+
case "skewX":
|
918
|
+
if (array.length === 1) {
|
919
|
+
currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
|
920
|
+
}
|
921
|
+
break;
|
922
|
+
case "skewY":
|
923
|
+
if (array.length === 1) {
|
924
|
+
currentTransform2.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
|
925
|
+
}
|
926
|
+
break;
|
927
|
+
case "matrix":
|
928
|
+
if (array.length === 6) {
|
929
|
+
currentTransform2.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
|
930
|
+
}
|
931
|
+
break;
|
934
932
|
}
|
935
|
-
transform.premultiply(currentTransform2);
|
936
933
|
}
|
934
|
+
transform.premultiply(currentTransform2);
|
937
935
|
}
|
938
|
-
return transform;
|
939
936
|
}
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
};
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
}
|
979
|
-
}
|
980
|
-
}
|
981
|
-
function transfEllipseNoSkew(curve) {
|
982
|
-
const sx = getTransformScaleX(m);
|
983
|
-
const sy = getTransformScaleY(m);
|
984
|
-
curve.xRadius *= sx;
|
985
|
-
curve.yRadius *= sy;
|
986
|
-
const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
|
987
|
-
curve.aRotation += theta;
|
937
|
+
return transform;
|
938
|
+
}
|
939
|
+
function transformPath(path, m) {
|
940
|
+
function transfVec2(v2) {
|
941
|
+
tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
|
942
|
+
v2.set(tempV3.x, tempV3.y);
|
943
|
+
}
|
944
|
+
function transfEllipseGeneric(curve) {
|
945
|
+
const a = curve.xRadius;
|
946
|
+
const b = curve.yRadius;
|
947
|
+
const cosTheta = Math.cos(curve.aRotation);
|
948
|
+
const sinTheta = Math.sin(curve.aRotation);
|
949
|
+
const v1 = new Vector3(a * cosTheta, a * sinTheta, 0);
|
950
|
+
const v2 = new Vector3(-b * sinTheta, b * cosTheta, 0);
|
951
|
+
const f1 = v1.applyMatrix3(m);
|
952
|
+
const f2 = v2.applyMatrix3(m);
|
953
|
+
const mF = tempTransform0.set(f1.x, f2.x, 0, f1.y, f2.y, 0, 0, 0, 1);
|
954
|
+
const mFInv = tempTransform1.copy(mF).invert();
|
955
|
+
const mFInvT = tempTransform2.copy(mFInv).transpose();
|
956
|
+
const mQ = mFInvT.multiply(mFInv);
|
957
|
+
const mQe = mQ.elements;
|
958
|
+
const ed = eigenDecomposition(mQe[0], mQe[1], mQe[4]);
|
959
|
+
const rt1sqrt = Math.sqrt(ed.rt1);
|
960
|
+
const rt2sqrt = Math.sqrt(ed.rt2);
|
961
|
+
curve.xRadius = 1 / rt1sqrt;
|
962
|
+
curve.yRadius = 1 / rt2sqrt;
|
963
|
+
curve.aRotation = Math.atan2(ed.sn, ed.cs);
|
964
|
+
const isFullEllipse = (curve.aEndAngle - curve.aStartAngle) % (2 * Math.PI) < Number.EPSILON;
|
965
|
+
if (!isFullEllipse) {
|
966
|
+
const mDsqrt = tempTransform1.set(rt1sqrt, 0, 0, 0, rt2sqrt, 0, 0, 0, 1);
|
967
|
+
const mRT = tempTransform2.set(ed.cs, ed.sn, 0, -ed.sn, ed.cs, 0, 0, 0, 1);
|
968
|
+
const mDRF = mDsqrt.multiply(mRT).multiply(mF);
|
969
|
+
const transformAngle = (phi) => {
|
970
|
+
const { x: cosR, y: sinR } = new Vector3(Math.cos(phi), Math.sin(phi), 0).applyMatrix3(mDRF);
|
971
|
+
return Math.atan2(sinR, cosR);
|
972
|
+
};
|
973
|
+
curve.aStartAngle = transformAngle(curve.aStartAngle);
|
974
|
+
curve.aEndAngle = transformAngle(curve.aEndAngle);
|
988
975
|
if (isTransformFlipped(m)) {
|
989
|
-
curve.aStartAngle *= -1;
|
990
|
-
curve.aEndAngle *= -1;
|
991
976
|
curve.aClockwise = !curve.aClockwise;
|
992
977
|
}
|
993
978
|
}
|
994
|
-
const subPaths = path.subPaths;
|
995
|
-
for (let i = 0, n = subPaths.length; i < n; i++) {
|
996
|
-
const subPath = subPaths[i];
|
997
|
-
const curves = subPath.curves;
|
998
|
-
for (let j = 0; j < curves.length; j++) {
|
999
|
-
const curve = curves[j];
|
1000
|
-
if (curve.isLineCurve) {
|
1001
|
-
transfVec2(curve.v1);
|
1002
|
-
transfVec2(curve.v2);
|
1003
|
-
} else if (curve.isCubicBezierCurve) {
|
1004
|
-
transfVec2(curve.v0);
|
1005
|
-
transfVec2(curve.v1);
|
1006
|
-
transfVec2(curve.v2);
|
1007
|
-
transfVec2(curve.v3);
|
1008
|
-
} else if (curve.isQuadraticBezierCurve) {
|
1009
|
-
transfVec2(curve.v0);
|
1010
|
-
transfVec2(curve.v1);
|
1011
|
-
transfVec2(curve.v2);
|
1012
|
-
} else if (curve.isEllipseCurve) {
|
1013
|
-
tempV2.set(curve.aX, curve.aY);
|
1014
|
-
transfVec2(tempV2);
|
1015
|
-
curve.aX = tempV2.x;
|
1016
|
-
curve.aY = tempV2.y;
|
1017
|
-
if (isTransformSkewed(m)) {
|
1018
|
-
transfEllipseGeneric(curve);
|
1019
|
-
} else {
|
1020
|
-
transfEllipseNoSkew(curve);
|
1021
|
-
}
|
1022
|
-
}
|
1023
|
-
}
|
1024
|
-
}
|
1025
|
-
}
|
1026
|
-
function isTransformFlipped(m) {
|
1027
|
-
const te = m.elements;
|
1028
|
-
return te[0] * te[4] - te[1] * te[3] < 0;
|
1029
979
|
}
|
1030
|
-
function
|
1031
|
-
const te = m.elements;
|
1032
|
-
const basisDot = te[0] * te[3] + te[1] * te[4];
|
1033
|
-
if (basisDot === 0)
|
1034
|
-
return false;
|
980
|
+
function transfEllipseNoSkew(curve) {
|
1035
981
|
const sx = getTransformScaleX(m);
|
1036
982
|
const sy = getTransformScaleY(m);
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
|
1046
|
-
}
|
1047
|
-
function eigenDecomposition(A, B, C) {
|
1048
|
-
let rt1, rt2, cs, sn, t;
|
1049
|
-
const sm = A + C;
|
1050
|
-
const df = A - C;
|
1051
|
-
const rt = Math.sqrt(df * df + 4 * B * B);
|
1052
|
-
if (sm > 0) {
|
1053
|
-
rt1 = 0.5 * (sm + rt);
|
1054
|
-
t = 1 / rt1;
|
1055
|
-
rt2 = A * t * C - B * t * B;
|
1056
|
-
} else if (sm < 0) {
|
1057
|
-
rt2 = 0.5 * (sm - rt);
|
1058
|
-
} else {
|
1059
|
-
rt1 = 0.5 * rt;
|
1060
|
-
rt2 = -0.5 * rt;
|
1061
|
-
}
|
1062
|
-
if (df > 0) {
|
1063
|
-
cs = df + rt;
|
1064
|
-
} else {
|
1065
|
-
cs = df - rt;
|
1066
|
-
}
|
1067
|
-
if (Math.abs(cs) > 2 * Math.abs(B)) {
|
1068
|
-
t = -2 * B / cs;
|
1069
|
-
sn = 1 / Math.sqrt(1 + t * t);
|
1070
|
-
cs = t * sn;
|
1071
|
-
} else if (Math.abs(B) === 0) {
|
1072
|
-
cs = 1;
|
1073
|
-
sn = 0;
|
1074
|
-
} else {
|
1075
|
-
t = -0.5 * cs / B;
|
1076
|
-
cs = 1 / Math.sqrt(1 + t * t);
|
1077
|
-
sn = t * cs;
|
1078
|
-
}
|
1079
|
-
if (df > 0) {
|
1080
|
-
t = cs;
|
1081
|
-
cs = -sn;
|
1082
|
-
sn = t;
|
1083
|
-
}
|
1084
|
-
return { rt1, rt2, cs, sn };
|
1085
|
-
}
|
1086
|
-
const paths = [];
|
1087
|
-
const stylesheets = {};
|
1088
|
-
const transformStack = [];
|
1089
|
-
const tempTransform0 = new Matrix3();
|
1090
|
-
const tempTransform1 = new Matrix3();
|
1091
|
-
const tempTransform2 = new Matrix3();
|
1092
|
-
const tempTransform3 = new Matrix3();
|
1093
|
-
const tempV2 = new Vector2();
|
1094
|
-
const tempV3 = new Vector3();
|
1095
|
-
const currentTransform = new Matrix3();
|
1096
|
-
const xml = new DOMParser().parseFromString(text, "image/svg+xml");
|
1097
|
-
parseNode(xml.documentElement, {
|
1098
|
-
fill: "#000",
|
1099
|
-
fillOpacity: 1,
|
1100
|
-
strokeOpacity: 1,
|
1101
|
-
strokeWidth: 1,
|
1102
|
-
strokeLineJoin: "miter",
|
1103
|
-
strokeLineCap: "butt",
|
1104
|
-
strokeMiterLimit: 4
|
1105
|
-
});
|
1106
|
-
const data = { paths, xml: xml.documentElement };
|
1107
|
-
return data;
|
1108
|
-
}
|
1109
|
-
static createShapes(shapePath) {
|
1110
|
-
const BIGNUMBER = 999999999;
|
1111
|
-
const IntersectionLocationType = {
|
1112
|
-
ORIGIN: 0,
|
1113
|
-
DESTINATION: 1,
|
1114
|
-
BETWEEN: 2,
|
1115
|
-
LEFT: 3,
|
1116
|
-
RIGHT: 4,
|
1117
|
-
BEHIND: 5,
|
1118
|
-
BEYOND: 6
|
1119
|
-
};
|
1120
|
-
const classifyResult = {
|
1121
|
-
loc: IntersectionLocationType.ORIGIN,
|
1122
|
-
t: 0
|
1123
|
-
};
|
1124
|
-
function findEdgeIntersection(a0, a1, b0, b1) {
|
1125
|
-
const x1 = a0.x;
|
1126
|
-
const x2 = a1.x;
|
1127
|
-
const x3 = b0.x;
|
1128
|
-
const x4 = b1.x;
|
1129
|
-
const y1 = a0.y;
|
1130
|
-
const y2 = a1.y;
|
1131
|
-
const y3 = b0.y;
|
1132
|
-
const y4 = b1.y;
|
1133
|
-
const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
|
1134
|
-
const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
1135
|
-
const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
1136
|
-
const t1 = nom1 / denom;
|
1137
|
-
const t2 = nom2 / denom;
|
1138
|
-
if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
|
1139
|
-
return null;
|
1140
|
-
} else if (nom1 === 0 && denom === 0) {
|
1141
|
-
for (let i = 0; i < 2; i++) {
|
1142
|
-
classifyPoint(i === 0 ? b0 : b1, a0, a1);
|
1143
|
-
if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
|
1144
|
-
const point = i === 0 ? b0 : b1;
|
1145
|
-
return { x: point.x, y: point.y, t: classifyResult.t };
|
1146
|
-
} else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
|
1147
|
-
const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
|
1148
|
-
const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
|
1149
|
-
return { x, y, t: classifyResult.t };
|
1150
|
-
}
|
1151
|
-
}
|
1152
|
-
return null;
|
1153
|
-
} else {
|
1154
|
-
for (let i = 0; i < 2; i++) {
|
1155
|
-
classifyPoint(i === 0 ? b0 : b1, a0, a1);
|
1156
|
-
if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
|
1157
|
-
const point = i === 0 ? b0 : b1;
|
1158
|
-
return { x: point.x, y: point.y, t: classifyResult.t };
|
1159
|
-
}
|
1160
|
-
}
|
1161
|
-
const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
|
1162
|
-
const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
|
1163
|
-
return { x, y, t: t1 };
|
983
|
+
curve.xRadius *= sx;
|
984
|
+
curve.yRadius *= sy;
|
985
|
+
const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
|
986
|
+
curve.aRotation += theta;
|
987
|
+
if (isTransformFlipped(m)) {
|
988
|
+
curve.aStartAngle *= -1;
|
989
|
+
curve.aEndAngle *= -1;
|
990
|
+
curve.aClockwise = !curve.aClockwise;
|
1164
991
|
}
|
1165
992
|
}
|
1166
|
-
|
1167
|
-
|
1168
|
-
const
|
1169
|
-
const
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
}
|
1194
|
-
if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
|
1195
|
-
classifyResult.loc = IntersectionLocationType.BEYOND;
|
1196
|
-
return;
|
1197
|
-
}
|
1198
|
-
let t;
|
1199
|
-
if (ax !== 0) {
|
1200
|
-
t = bx / ax;
|
1201
|
-
} else {
|
1202
|
-
t = by / ay;
|
1203
|
-
}
|
1204
|
-
classifyResult.loc = IntersectionLocationType.BETWEEN;
|
1205
|
-
classifyResult.t = t;
|
1206
|
-
}
|
1207
|
-
function getIntersections(path1, path2) {
|
1208
|
-
const intersectionsRaw = [];
|
1209
|
-
const intersections = [];
|
1210
|
-
for (let index = 1; index < path1.length; index++) {
|
1211
|
-
const path1EdgeStart = path1[index - 1];
|
1212
|
-
const path1EdgeEnd = path1[index];
|
1213
|
-
for (let index2 = 1; index2 < path2.length; index2++) {
|
1214
|
-
const path2EdgeStart = path2[index2 - 1];
|
1215
|
-
const path2EdgeEnd = path2[index2];
|
1216
|
-
const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
|
1217
|
-
if (intersection !== null && intersectionsRaw.find(
|
1218
|
-
(i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
|
1219
|
-
) === void 0) {
|
1220
|
-
intersectionsRaw.push(intersection);
|
1221
|
-
intersections.push(new Vector2(intersection.x, intersection.y));
|
993
|
+
const subPaths = path.subPaths;
|
994
|
+
for (let i = 0, n = subPaths.length; i < n; i++) {
|
995
|
+
const subPath = subPaths[i];
|
996
|
+
const curves = subPath.curves;
|
997
|
+
for (let j = 0; j < curves.length; j++) {
|
998
|
+
const curve = curves[j];
|
999
|
+
if (curve.isLineCurve) {
|
1000
|
+
transfVec2(curve.v1);
|
1001
|
+
transfVec2(curve.v2);
|
1002
|
+
} else if (curve.isCubicBezierCurve) {
|
1003
|
+
transfVec2(curve.v0);
|
1004
|
+
transfVec2(curve.v1);
|
1005
|
+
transfVec2(curve.v2);
|
1006
|
+
transfVec2(curve.v3);
|
1007
|
+
} else if (curve.isQuadraticBezierCurve) {
|
1008
|
+
transfVec2(curve.v0);
|
1009
|
+
transfVec2(curve.v1);
|
1010
|
+
transfVec2(curve.v2);
|
1011
|
+
} else if (curve.isEllipseCurve) {
|
1012
|
+
tempV2.set(curve.aX, curve.aY);
|
1013
|
+
transfVec2(tempV2);
|
1014
|
+
curve.aX = tempV2.x;
|
1015
|
+
curve.aY = tempV2.y;
|
1016
|
+
if (isTransformSkewed(m)) {
|
1017
|
+
transfEllipseGeneric(curve);
|
1018
|
+
} else {
|
1019
|
+
transfEllipseNoSkew(curve);
|
1222
1020
|
}
|
1223
1021
|
}
|
1224
1022
|
}
|
1225
|
-
return intersections;
|
1226
|
-
}
|
1227
|
-
function getScanlineIntersections(scanline, boundingBox, paths) {
|
1228
|
-
const center = new Vector2();
|
1229
|
-
boundingBox.getCenter(center);
|
1230
|
-
const allIntersections = [];
|
1231
|
-
paths.forEach((path) => {
|
1232
|
-
if (path.boundingBox.containsPoint(center)) {
|
1233
|
-
const intersections = getIntersections(scanline, path.points);
|
1234
|
-
intersections.forEach((p) => {
|
1235
|
-
allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
|
1236
|
-
});
|
1237
|
-
}
|
1238
|
-
});
|
1239
|
-
allIntersections.sort((i1, i2) => {
|
1240
|
-
return i1.point.x - i2.point.x;
|
1241
|
-
});
|
1242
|
-
return allIntersections;
|
1243
1023
|
}
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1024
|
+
}
|
1025
|
+
function isTransformFlipped(m) {
|
1026
|
+
const te = m.elements;
|
1027
|
+
return te[0] * te[4] - te[1] * te[3] < 0;
|
1028
|
+
}
|
1029
|
+
function isTransformSkewed(m) {
|
1030
|
+
const te = m.elements;
|
1031
|
+
const basisDot = te[0] * te[3] + te[1] * te[4];
|
1032
|
+
if (basisDot === 0)
|
1033
|
+
return false;
|
1034
|
+
const sx = getTransformScaleX(m);
|
1035
|
+
const sy = getTransformScaleY(m);
|
1036
|
+
return Math.abs(basisDot / (sx * sy)) > Number.EPSILON;
|
1037
|
+
}
|
1038
|
+
function getTransformScaleX(m) {
|
1039
|
+
const te = m.elements;
|
1040
|
+
return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
|
1041
|
+
}
|
1042
|
+
function getTransformScaleY(m) {
|
1043
|
+
const te = m.elements;
|
1044
|
+
return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
|
1045
|
+
}
|
1046
|
+
function eigenDecomposition(A, B, C) {
|
1047
|
+
let rt1, rt2, cs, sn, t;
|
1048
|
+
const sm = A + C;
|
1049
|
+
const df = A - C;
|
1050
|
+
const rt = Math.sqrt(df * df + 4 * B * B);
|
1051
|
+
if (sm > 0) {
|
1052
|
+
rt1 = 0.5 * (sm + rt);
|
1053
|
+
t = 1 / rt1;
|
1054
|
+
rt2 = A * t * C - B * t * B;
|
1055
|
+
} else if (sm < 0) {
|
1056
|
+
rt2 = 0.5 * (sm - rt);
|
1057
|
+
} else {
|
1058
|
+
rt1 = 0.5 * rt;
|
1059
|
+
rt2 = -0.5 * rt;
|
1060
|
+
}
|
1061
|
+
if (df > 0) {
|
1062
|
+
cs = df + rt;
|
1063
|
+
} else {
|
1064
|
+
cs = df - rt;
|
1065
|
+
}
|
1066
|
+
if (Math.abs(cs) > 2 * Math.abs(B)) {
|
1067
|
+
t = -2 * B / cs;
|
1068
|
+
sn = 1 / Math.sqrt(1 + t * t);
|
1069
|
+
cs = t * sn;
|
1070
|
+
} else if (Math.abs(B) === 0) {
|
1071
|
+
cs = 1;
|
1072
|
+
sn = 0;
|
1073
|
+
} else {
|
1074
|
+
t = -0.5 * cs / B;
|
1075
|
+
cs = 1 / Math.sqrt(1 + t * t);
|
1076
|
+
sn = t * cs;
|
1077
|
+
}
|
1078
|
+
if (df > 0) {
|
1079
|
+
t = cs;
|
1080
|
+
cs = -sn;
|
1081
|
+
sn = t;
|
1082
|
+
}
|
1083
|
+
return { rt1, rt2, cs, sn };
|
1084
|
+
}
|
1085
|
+
const paths = [];
|
1086
|
+
const stylesheets = {};
|
1087
|
+
const transformStack = [];
|
1088
|
+
const tempTransform0 = new Matrix3();
|
1089
|
+
const tempTransform1 = new Matrix3();
|
1090
|
+
const tempTransform2 = new Matrix3();
|
1091
|
+
const tempTransform3 = new Matrix3();
|
1092
|
+
const tempV2 = new Vector2();
|
1093
|
+
const tempV3 = new Vector3();
|
1094
|
+
const currentTransform = new Matrix3();
|
1095
|
+
const xml = new DOMParser().parseFromString(text, "image/svg+xml");
|
1096
|
+
parseNode(xml.documentElement, {
|
1097
|
+
fill: "#000",
|
1098
|
+
fillOpacity: 1,
|
1099
|
+
strokeOpacity: 1,
|
1100
|
+
strokeWidth: 1,
|
1101
|
+
strokeLineJoin: "miter",
|
1102
|
+
strokeLineCap: "butt",
|
1103
|
+
strokeMiterLimit: 4
|
1104
|
+
});
|
1105
|
+
const data = { paths, xml: xml.documentElement };
|
1106
|
+
return data;
|
1107
|
+
}
|
1108
|
+
static createShapes(shapePath) {
|
1109
|
+
const BIGNUMBER = 999999999;
|
1110
|
+
const IntersectionLocationType = {
|
1111
|
+
ORIGIN: 0,
|
1112
|
+
DESTINATION: 1,
|
1113
|
+
BETWEEN: 2,
|
1114
|
+
LEFT: 3,
|
1115
|
+
RIGHT: 4,
|
1116
|
+
BEHIND: 5,
|
1117
|
+
BEYOND: 6
|
1118
|
+
};
|
1119
|
+
const classifyResult = {
|
1120
|
+
loc: IntersectionLocationType.ORIGIN,
|
1121
|
+
t: 0
|
1122
|
+
};
|
1123
|
+
function findEdgeIntersection(a0, a1, b0, b1) {
|
1124
|
+
const x1 = a0.x;
|
1125
|
+
const x2 = a1.x;
|
1126
|
+
const x3 = b0.x;
|
1127
|
+
const x4 = b1.x;
|
1128
|
+
const y1 = a0.y;
|
1129
|
+
const y2 = a1.y;
|
1130
|
+
const y3 = b0.y;
|
1131
|
+
const y4 = b1.y;
|
1132
|
+
const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
|
1133
|
+
const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
|
1134
|
+
const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
1135
|
+
const t1 = nom1 / denom;
|
1136
|
+
const t2 = nom2 / denom;
|
1137
|
+
if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
|
1138
|
+
return null;
|
1139
|
+
} else if (nom1 === 0 && denom === 0) {
|
1140
|
+
for (let i = 0; i < 2; i++) {
|
1141
|
+
classifyPoint(i === 0 ? b0 : b1, a0, a1);
|
1142
|
+
if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
|
1143
|
+
const point = i === 0 ? b0 : b1;
|
1144
|
+
return { x: point.x, y: point.y, t: classifyResult.t };
|
1145
|
+
} else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
|
1146
|
+
const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
|
1147
|
+
const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
|
1148
|
+
return { x, y, t: classifyResult.t };
|
1275
1149
|
}
|
1276
|
-
i++;
|
1277
1150
|
}
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
let isHoleFor = null;
|
1286
|
-
let lastCWValue = null;
|
1287
|
-
for (let i2 = 0; i2 < stack.length; i2++) {
|
1288
|
-
const identifier = stack[i2];
|
1289
|
-
if (isHole) {
|
1290
|
-
lastCWValue = allPaths[identifier].isCW;
|
1291
|
-
isHole = false;
|
1292
|
-
isHoleFor = identifier;
|
1293
|
-
} else if (lastCWValue !== allPaths[identifier].isCW) {
|
1294
|
-
lastCWValue = allPaths[identifier].isCW;
|
1295
|
-
isHole = true;
|
1296
|
-
}
|
1151
|
+
return null;
|
1152
|
+
} else {
|
1153
|
+
for (let i = 0; i < 2; i++) {
|
1154
|
+
classifyPoint(i === 0 ? b0 : b1, a0, a1);
|
1155
|
+
if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
|
1156
|
+
const point = i === 0 ? b0 : b1;
|
1157
|
+
return { x: point.x, y: point.y, t: classifyResult.t };
|
1297
1158
|
}
|
1298
|
-
return { identifier: simplePath.identifier, isHole, for: isHoleFor };
|
1299
|
-
} else {
|
1300
|
-
console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
|
1301
1159
|
}
|
1160
|
+
const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
|
1161
|
+
const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
|
1162
|
+
return { x, y, t: t1 };
|
1302
1163
|
}
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1164
|
+
}
|
1165
|
+
function classifyPoint(p, edgeStart, edgeEnd) {
|
1166
|
+
const ax = edgeEnd.x - edgeStart.x;
|
1167
|
+
const ay = edgeEnd.y - edgeStart.y;
|
1168
|
+
const bx = p.x - edgeStart.x;
|
1169
|
+
const by = p.y - edgeStart.y;
|
1170
|
+
const sa = ax * by - bx * ay;
|
1171
|
+
if (p.x === edgeStart.x && p.y === edgeStart.y) {
|
1172
|
+
classifyResult.loc = IntersectionLocationType.ORIGIN;
|
1173
|
+
classifyResult.t = 0;
|
1174
|
+
return;
|
1175
|
+
}
|
1176
|
+
if (p.x === edgeEnd.x && p.y === edgeEnd.y) {
|
1177
|
+
classifyResult.loc = IntersectionLocationType.DESTINATION;
|
1178
|
+
classifyResult.t = 1;
|
1179
|
+
return;
|
1180
|
+
}
|
1181
|
+
if (sa < -Number.EPSILON) {
|
1182
|
+
classifyResult.loc = IntersectionLocationType.LEFT;
|
1183
|
+
return;
|
1184
|
+
}
|
1185
|
+
if (sa > Number.EPSILON) {
|
1186
|
+
classifyResult.loc = IntersectionLocationType.RIGHT;
|
1187
|
+
return;
|
1188
|
+
}
|
1189
|
+
if (ax * bx < 0 || ay * by < 0) {
|
1190
|
+
classifyResult.loc = IntersectionLocationType.BEHIND;
|
1191
|
+
return;
|
1192
|
+
}
|
1193
|
+
if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
|
1194
|
+
classifyResult.loc = IntersectionLocationType.BEYOND;
|
1195
|
+
return;
|
1196
|
+
}
|
1197
|
+
let t;
|
1198
|
+
if (ax !== 0) {
|
1199
|
+
t = bx / ax;
|
1200
|
+
} else {
|
1201
|
+
t = by / ay;
|
1202
|
+
}
|
1203
|
+
classifyResult.loc = IntersectionLocationType.BETWEEN;
|
1204
|
+
classifyResult.t = t;
|
1205
|
+
}
|
1206
|
+
function getIntersections(path1, path2) {
|
1207
|
+
const intersectionsRaw = [];
|
1208
|
+
const intersections = [];
|
1209
|
+
for (let index = 1; index < path1.length; index++) {
|
1210
|
+
const path1EdgeStart = path1[index - 1];
|
1211
|
+
const path1EdgeEnd = path1[index];
|
1212
|
+
for (let index2 = 1; index2 < path2.length; index2++) {
|
1213
|
+
const path2EdgeStart = path2[index2 - 1];
|
1214
|
+
const path2EdgeEnd = path2[index2];
|
1215
|
+
const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
|
1216
|
+
if (intersection !== null && intersectionsRaw.find(
|
1217
|
+
(i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
|
1218
|
+
) === void 0) {
|
1219
|
+
intersectionsRaw.push(intersection);
|
1220
|
+
intersections.push(new Vector2(intersection.x, intersection.y));
|
1324
1221
|
}
|
1325
1222
|
}
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1223
|
+
}
|
1224
|
+
return intersections;
|
1225
|
+
}
|
1226
|
+
function getScanlineIntersections(scanline, boundingBox, paths) {
|
1227
|
+
const center = new Vector2();
|
1228
|
+
boundingBox.getCenter(center);
|
1229
|
+
const allIntersections = [];
|
1230
|
+
paths.forEach((path) => {
|
1231
|
+
if (path.boundingBox.containsPoint(center)) {
|
1232
|
+
const intersections = getIntersections(scanline, path.points);
|
1233
|
+
intersections.forEach((p) => {
|
1234
|
+
allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
|
1235
|
+
});
|
1331
1236
|
}
|
1332
|
-
return {
|
1333
|
-
curves: p.curves,
|
1334
|
-
points,
|
1335
|
-
isCW: ShapeUtils.isClockWise(points),
|
1336
|
-
identifier: -1,
|
1337
|
-
boundingBox: new Box2(new Vector2(minX, minY), new Vector2(maxX, maxY))
|
1338
|
-
};
|
1339
1237
|
});
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
);
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
path.curves = hole.curves;
|
1364
|
-
shape.holes.push(path);
|
1365
|
-
});
|
1366
|
-
shapesToReturn.push(shape);
|
1238
|
+
allIntersections.sort((i1, i2) => {
|
1239
|
+
return i1.point.x - i2.point.x;
|
1240
|
+
});
|
1241
|
+
return allIntersections;
|
1242
|
+
}
|
1243
|
+
function isHoleTo(simplePath, allPaths, scanlineMinX2, scanlineMaxX2, _fillRule) {
|
1244
|
+
if (_fillRule === null || _fillRule === void 0 || _fillRule === "") {
|
1245
|
+
_fillRule = "nonzero";
|
1246
|
+
}
|
1247
|
+
const centerBoundingBox = new Vector2();
|
1248
|
+
simplePath.boundingBox.getCenter(centerBoundingBox);
|
1249
|
+
const scanline = [new Vector2(scanlineMinX2, centerBoundingBox.y), new Vector2(scanlineMaxX2, centerBoundingBox.y)];
|
1250
|
+
const scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
|
1251
|
+
scanlineIntersections.sort((i1, i2) => {
|
1252
|
+
return i1.point.x - i2.point.x;
|
1253
|
+
});
|
1254
|
+
const baseIntersections = [];
|
1255
|
+
const otherIntersections = [];
|
1256
|
+
scanlineIntersections.forEach((i2) => {
|
1257
|
+
if (i2.identifier === simplePath.identifier) {
|
1258
|
+
baseIntersections.push(i2);
|
1259
|
+
} else {
|
1260
|
+
otherIntersections.push(i2);
|
1367
1261
|
}
|
1368
1262
|
});
|
1369
|
-
|
1263
|
+
const firstXOfPath = baseIntersections[0].point.x;
|
1264
|
+
const stack = [];
|
1265
|
+
let i = 0;
|
1266
|
+
while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
|
1267
|
+
if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
|
1268
|
+
stack.pop();
|
1269
|
+
} else {
|
1270
|
+
stack.push(otherIntersections[i].identifier);
|
1271
|
+
}
|
1272
|
+
i++;
|
1273
|
+
}
|
1274
|
+
stack.push(simplePath.identifier);
|
1275
|
+
if (_fillRule === "evenodd") {
|
1276
|
+
const isHole = stack.length % 2 === 0 ? true : false;
|
1277
|
+
const isHoleFor = stack[stack.length - 2];
|
1278
|
+
return { identifier: simplePath.identifier, isHole, for: isHoleFor };
|
1279
|
+
} else if (_fillRule === "nonzero") {
|
1280
|
+
let isHole = true;
|
1281
|
+
let isHoleFor = null;
|
1282
|
+
let lastCWValue = null;
|
1283
|
+
for (let i2 = 0; i2 < stack.length; i2++) {
|
1284
|
+
const identifier = stack[i2];
|
1285
|
+
if (isHole) {
|
1286
|
+
lastCWValue = allPaths[identifier].isCW;
|
1287
|
+
isHole = false;
|
1288
|
+
isHoleFor = identifier;
|
1289
|
+
} else if (lastCWValue !== allPaths[identifier].isCW) {
|
1290
|
+
lastCWValue = allPaths[identifier].isCW;
|
1291
|
+
isHole = true;
|
1292
|
+
}
|
1293
|
+
}
|
1294
|
+
return { identifier: simplePath.identifier, isHole, for: isHoleFor };
|
1295
|
+
} else {
|
1296
|
+
console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
|
1297
|
+
}
|
1370
1298
|
}
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1299
|
+
let scanlineMinX = BIGNUMBER;
|
1300
|
+
let scanlineMaxX = -BIGNUMBER;
|
1301
|
+
let simplePaths = shapePath.subPaths.map((p) => {
|
1302
|
+
const points = p.getPoints();
|
1303
|
+
let maxY = -BIGNUMBER;
|
1304
|
+
let minY = BIGNUMBER;
|
1305
|
+
let maxX = -BIGNUMBER;
|
1306
|
+
let minX = BIGNUMBER;
|
1307
|
+
for (let i = 0; i < points.length; i++) {
|
1308
|
+
const p2 = points[i];
|
1309
|
+
if (p2.y > maxY) {
|
1310
|
+
maxY = p2.y;
|
1311
|
+
}
|
1312
|
+
if (p2.y < minY) {
|
1313
|
+
minY = p2.y;
|
1314
|
+
}
|
1315
|
+
if (p2.x > maxX) {
|
1316
|
+
maxX = p2.x;
|
1317
|
+
}
|
1318
|
+
if (p2.x < minX) {
|
1319
|
+
minX = p2.x;
|
1320
|
+
}
|
1321
|
+
}
|
1322
|
+
if (scanlineMaxX <= maxX) {
|
1323
|
+
scanlineMaxX = maxX + 1;
|
1324
|
+
}
|
1325
|
+
if (scanlineMinX >= minX) {
|
1326
|
+
scanlineMinX = minX - 1;
|
1327
|
+
}
|
1377
1328
|
return {
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1329
|
+
curves: p.curves,
|
1330
|
+
points,
|
1331
|
+
isCW: ShapeUtils.isClockWise(points),
|
1332
|
+
identifier: -1,
|
1333
|
+
boundingBox: new Box2(new Vector2(minX, minY), new Vector2(maxX, maxY))
|
1383
1334
|
};
|
1335
|
+
});
|
1336
|
+
simplePaths = simplePaths.filter((sp) => sp.points.length > 1);
|
1337
|
+
for (let identifier = 0; identifier < simplePaths.length; identifier++) {
|
1338
|
+
simplePaths[identifier].identifier = identifier;
|
1384
1339
|
}
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1340
|
+
const isAHole = simplePaths.map(
|
1341
|
+
(p) => isHoleTo(
|
1342
|
+
p,
|
1343
|
+
simplePaths,
|
1344
|
+
scanlineMinX,
|
1345
|
+
scanlineMaxX,
|
1346
|
+
shapePath.userData ? shapePath.userData.style.fillRule : void 0
|
1347
|
+
)
|
1348
|
+
);
|
1349
|
+
const shapesToReturn = [];
|
1350
|
+
simplePaths.forEach((p) => {
|
1351
|
+
const amIAHole = isAHole[p.identifier];
|
1352
|
+
if (!amIAHole.isHole) {
|
1353
|
+
const shape = new Shape();
|
1354
|
+
shape.curves = p.curves;
|
1355
|
+
const holes = isAHole.filter((h) => h.isHole && h.for === p.identifier);
|
1356
|
+
holes.forEach((h) => {
|
1357
|
+
const hole = simplePaths[h.identifier];
|
1358
|
+
const path = new Path();
|
1359
|
+
path.curves = hole.curves;
|
1360
|
+
shape.holes.push(path);
|
1361
|
+
});
|
1362
|
+
shapesToReturn.push(shape);
|
1391
1363
|
}
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1364
|
+
});
|
1365
|
+
return shapesToReturn;
|
1366
|
+
}
|
1367
|
+
static getStrokeStyle(width, color, lineJoin, lineCap, miterLimit) {
|
1368
|
+
width = width !== void 0 ? width : 1;
|
1369
|
+
color = color !== void 0 ? color : "#000";
|
1370
|
+
lineJoin = lineJoin !== void 0 ? lineJoin : "miter";
|
1371
|
+
lineCap = lineCap !== void 0 ? lineCap : "butt";
|
1372
|
+
miterLimit = miterLimit !== void 0 ? miterLimit : 4;
|
1373
|
+
return {
|
1374
|
+
strokeColor: color,
|
1375
|
+
strokeWidth: width,
|
1376
|
+
strokeLineJoin: lineJoin,
|
1377
|
+
strokeLineCap: lineCap,
|
1378
|
+
strokeMiterLimit: miterLimit
|
1379
|
+
};
|
1380
|
+
}
|
1381
|
+
static pointsToStroke(points, style, arcDivisions, minDistance) {
|
1382
|
+
const vertices = [];
|
1383
|
+
const normals = [];
|
1384
|
+
const uvs = [];
|
1385
|
+
if (SVGLoader.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
|
1386
|
+
return null;
|
1397
1387
|
}
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1388
|
+
const geometry = new BufferGeometry();
|
1389
|
+
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
|
1390
|
+
geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
|
1391
|
+
geometry.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
|
1392
|
+
return geometry;
|
1393
|
+
}
|
1394
|
+
static pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
|
1395
|
+
const tempV2_1 = new Vector2();
|
1396
|
+
const tempV2_2 = new Vector2();
|
1397
|
+
const tempV2_3 = new Vector2();
|
1398
|
+
const tempV2_4 = new Vector2();
|
1399
|
+
const tempV2_5 = new Vector2();
|
1400
|
+
const tempV2_6 = new Vector2();
|
1401
|
+
const tempV2_7 = new Vector2();
|
1402
|
+
const lastPointL = new Vector2();
|
1403
|
+
const lastPointR = new Vector2();
|
1404
|
+
const point0L = new Vector2();
|
1405
|
+
const point0R = new Vector2();
|
1406
|
+
const currentPointL = new Vector2();
|
1407
|
+
const currentPointR = new Vector2();
|
1408
|
+
const nextPointL = new Vector2();
|
1409
|
+
const nextPointR = new Vector2();
|
1410
|
+
const innerPoint = new Vector2();
|
1411
|
+
const outerPoint = new Vector2();
|
1412
|
+
arcDivisions = arcDivisions !== void 0 ? arcDivisions : 12;
|
1413
|
+
minDistance = minDistance !== void 0 ? minDistance : 1e-3;
|
1414
|
+
vertexOffset = vertexOffset !== void 0 ? vertexOffset : 0;
|
1415
|
+
points = removeDuplicatedPoints(points);
|
1416
|
+
const numPoints = points.length;
|
1417
|
+
if (numPoints < 2)
|
1418
|
+
return 0;
|
1419
|
+
const isClosed = points[0].equals(points[numPoints - 1]);
|
1420
|
+
let currentPoint;
|
1421
|
+
let previousPoint = points[0];
|
1422
|
+
let nextPoint;
|
1423
|
+
const strokeWidth2 = style.strokeWidth / 2;
|
1424
|
+
const deltaU = 1 / (numPoints - 1);
|
1425
|
+
let u0 = 0, u1;
|
1426
|
+
let innerSideModified;
|
1427
|
+
let joinIsOnLeftSide;
|
1428
|
+
let isMiter;
|
1429
|
+
let initialJoinIsOnLeftSide = false;
|
1430
|
+
let numVertices = 0;
|
1431
|
+
let currentCoordinate = vertexOffset * 3;
|
1432
|
+
let currentCoordinateUV = vertexOffset * 2;
|
1433
|
+
getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
|
1434
|
+
lastPointL.copy(points[0]).sub(tempV2_1);
|
1435
|
+
lastPointR.copy(points[0]).add(tempV2_1);
|
1436
|
+
point0L.copy(lastPointL);
|
1437
|
+
point0R.copy(lastPointR);
|
1438
|
+
for (let iPoint = 1; iPoint < numPoints; iPoint++) {
|
1439
|
+
currentPoint = points[iPoint];
|
1440
|
+
if (iPoint === numPoints - 1) {
|
1441
|
+
if (isClosed) {
|
1442
|
+
nextPoint = points[1];
|
1443
|
+
} else
|
1444
|
+
nextPoint = void 0;
|
1445
|
+
} else {
|
1446
|
+
nextPoint = points[iPoint + 1];
|
1447
|
+
}
|
1448
|
+
const normal1 = tempV2_1;
|
1449
|
+
getNormal(previousPoint, currentPoint, normal1);
|
1450
|
+
tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
|
1451
|
+
currentPointL.copy(currentPoint).sub(tempV2_3);
|
1452
|
+
currentPointR.copy(currentPoint).add(tempV2_3);
|
1453
|
+
u1 = u0 + deltaU;
|
1454
|
+
innerSideModified = false;
|
1455
|
+
if (nextPoint !== void 0) {
|
1456
|
+
getNormal(currentPoint, nextPoint, tempV2_2);
|
1457
|
+
tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
|
1458
|
+
nextPointL.copy(currentPoint).sub(tempV2_3);
|
1459
|
+
nextPointR.copy(currentPoint).add(tempV2_3);
|
1460
|
+
joinIsOnLeftSide = true;
|
1461
|
+
tempV2_3.subVectors(nextPoint, previousPoint);
|
1462
|
+
if (normal1.dot(tempV2_3) < 0) {
|
1463
|
+
joinIsOnLeftSide = false;
|
1464
|
+
}
|
1465
|
+
if (iPoint === 1)
|
1466
|
+
initialJoinIsOnLeftSide = joinIsOnLeftSide;
|
1467
|
+
tempV2_3.subVectors(nextPoint, currentPoint);
|
1468
|
+
tempV2_3.normalize();
|
1469
|
+
const dot = Math.abs(normal1.dot(tempV2_3));
|
1470
|
+
if (dot > Number.EPSILON) {
|
1471
|
+
const miterSide = strokeWidth2 / dot;
|
1472
|
+
tempV2_3.multiplyScalar(-miterSide);
|
1473
|
+
tempV2_4.subVectors(currentPoint, previousPoint);
|
1474
|
+
tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
|
1475
|
+
innerPoint.copy(tempV2_5).negate();
|
1476
|
+
const miterLength2 = tempV2_5.length();
|
1477
|
+
const segmentLengthPrev = tempV2_4.length();
|
1478
|
+
tempV2_4.divideScalar(segmentLengthPrev);
|
1479
|
+
tempV2_6.subVectors(nextPoint, currentPoint);
|
1480
|
+
const segmentLengthNext = tempV2_6.length();
|
1481
|
+
tempV2_6.divideScalar(segmentLengthNext);
|
1482
|
+
if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
|
1483
|
+
innerSideModified = true;
|
1468
1484
|
}
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
innerPoint.copy(tempV2_5).negate();
|
1480
|
-
const miterLength2 = tempV2_5.length();
|
1481
|
-
const segmentLengthPrev = tempV2_4.length();
|
1482
|
-
tempV2_4.divideScalar(segmentLengthPrev);
|
1483
|
-
tempV2_6.subVectors(nextPoint, currentPoint);
|
1484
|
-
const segmentLengthNext = tempV2_6.length();
|
1485
|
-
tempV2_6.divideScalar(segmentLengthNext);
|
1486
|
-
if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
|
1487
|
-
innerSideModified = true;
|
1485
|
+
outerPoint.copy(tempV2_5).add(currentPoint);
|
1486
|
+
innerPoint.add(currentPoint);
|
1487
|
+
isMiter = false;
|
1488
|
+
if (innerSideModified) {
|
1489
|
+
if (joinIsOnLeftSide) {
|
1490
|
+
nextPointR.copy(innerPoint);
|
1491
|
+
currentPointR.copy(innerPoint);
|
1492
|
+
} else {
|
1493
|
+
nextPointL.copy(innerPoint);
|
1494
|
+
currentPointL.copy(innerPoint);
|
1488
1495
|
}
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1496
|
+
} else {
|
1497
|
+
makeSegmentTriangles();
|
1498
|
+
}
|
1499
|
+
switch (style.strokeLineJoin) {
|
1500
|
+
case "bevel":
|
1501
|
+
makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
|
1502
|
+
break;
|
1503
|
+
case "round":
|
1504
|
+
createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
|
1493
1505
|
if (joinIsOnLeftSide) {
|
1494
|
-
|
1495
|
-
currentPointR.copy(innerPoint);
|
1506
|
+
makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
|
1496
1507
|
} else {
|
1497
|
-
|
1498
|
-
currentPointL.copy(innerPoint);
|
1508
|
+
makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
|
1499
1509
|
}
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
if (joinIsOnLeftSide) {
|
1510
|
-
makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
|
1510
|
+
break;
|
1511
|
+
case "miter":
|
1512
|
+
case "miter-clip":
|
1513
|
+
default:
|
1514
|
+
const miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
|
1515
|
+
if (miterFraction < 1) {
|
1516
|
+
if (style.strokeLineJoin !== "miter-clip") {
|
1517
|
+
makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
|
1518
|
+
break;
|
1511
1519
|
} else {
|
1512
|
-
|
1520
|
+
createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
|
1521
|
+
if (joinIsOnLeftSide) {
|
1522
|
+
tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
|
1523
|
+
tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
|
1524
|
+
addVertex(currentPointL, u1, 0);
|
1525
|
+
addVertex(tempV2_6, u1, 0);
|
1526
|
+
addVertex(currentPoint, u1, 0.5);
|
1527
|
+
addVertex(currentPoint, u1, 0.5);
|
1528
|
+
addVertex(tempV2_6, u1, 0);
|
1529
|
+
addVertex(tempV2_7, u1, 0);
|
1530
|
+
addVertex(currentPoint, u1, 0.5);
|
1531
|
+
addVertex(tempV2_7, u1, 0);
|
1532
|
+
addVertex(nextPointL, u1, 0);
|
1533
|
+
} else {
|
1534
|
+
tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
|
1535
|
+
tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
|
1536
|
+
addVertex(currentPointR, u1, 1);
|
1537
|
+
addVertex(tempV2_6, u1, 1);
|
1538
|
+
addVertex(currentPoint, u1, 0.5);
|
1539
|
+
addVertex(currentPoint, u1, 0.5);
|
1540
|
+
addVertex(tempV2_6, u1, 1);
|
1541
|
+
addVertex(tempV2_7, u1, 1);
|
1542
|
+
addVertex(currentPoint, u1, 0.5);
|
1543
|
+
addVertex(tempV2_7, u1, 1);
|
1544
|
+
addVertex(nextPointR, u1, 1);
|
1545
|
+
}
|
1513
1546
|
}
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1547
|
+
} else {
|
1548
|
+
if (innerSideModified) {
|
1549
|
+
if (joinIsOnLeftSide) {
|
1550
|
+
addVertex(lastPointR, u0, 1);
|
1551
|
+
addVertex(lastPointL, u0, 0);
|
1552
|
+
addVertex(outerPoint, u1, 0);
|
1553
|
+
addVertex(lastPointR, u0, 1);
|
1554
|
+
addVertex(outerPoint, u1, 0);
|
1555
|
+
addVertex(innerPoint, u1, 1);
|
1523
1556
|
} else {
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
addVertex(tempV2_7, u1, 0);
|
1536
|
-
addVertex(nextPointL, u1, 0);
|
1537
|
-
} else {
|
1538
|
-
tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
|
1539
|
-
tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
|
1540
|
-
addVertex(currentPointR, u1, 1);
|
1541
|
-
addVertex(tempV2_6, u1, 1);
|
1542
|
-
addVertex(currentPoint, u1, 0.5);
|
1543
|
-
addVertex(currentPoint, u1, 0.5);
|
1544
|
-
addVertex(tempV2_6, u1, 1);
|
1545
|
-
addVertex(tempV2_7, u1, 1);
|
1546
|
-
addVertex(currentPoint, u1, 0.5);
|
1547
|
-
addVertex(tempV2_7, u1, 1);
|
1548
|
-
addVertex(nextPointR, u1, 1);
|
1549
|
-
}
|
1557
|
+
addVertex(lastPointR, u0, 1);
|
1558
|
+
addVertex(lastPointL, u0, 0);
|
1559
|
+
addVertex(outerPoint, u1, 1);
|
1560
|
+
addVertex(lastPointL, u0, 0);
|
1561
|
+
addVertex(innerPoint, u1, 0);
|
1562
|
+
addVertex(outerPoint, u1, 1);
|
1563
|
+
}
|
1564
|
+
if (joinIsOnLeftSide) {
|
1565
|
+
nextPointL.copy(outerPoint);
|
1566
|
+
} else {
|
1567
|
+
nextPointR.copy(outerPoint);
|
1550
1568
|
}
|
1551
1569
|
} else {
|
1552
|
-
if (
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
addVertex(innerPoint, u1, 1);
|
1560
|
-
} else {
|
1561
|
-
addVertex(lastPointR, u0, 1);
|
1562
|
-
addVertex(lastPointL, u0, 0);
|
1563
|
-
addVertex(outerPoint, u1, 1);
|
1564
|
-
addVertex(lastPointL, u0, 0);
|
1565
|
-
addVertex(innerPoint, u1, 0);
|
1566
|
-
addVertex(outerPoint, u1, 1);
|
1567
|
-
}
|
1568
|
-
if (joinIsOnLeftSide) {
|
1569
|
-
nextPointL.copy(outerPoint);
|
1570
|
-
} else {
|
1571
|
-
nextPointR.copy(outerPoint);
|
1572
|
-
}
|
1570
|
+
if (joinIsOnLeftSide) {
|
1571
|
+
addVertex(currentPointL, u1, 0);
|
1572
|
+
addVertex(outerPoint, u1, 0);
|
1573
|
+
addVertex(currentPoint, u1, 0.5);
|
1574
|
+
addVertex(currentPoint, u1, 0.5);
|
1575
|
+
addVertex(outerPoint, u1, 0);
|
1576
|
+
addVertex(nextPointL, u1, 0);
|
1573
1577
|
} else {
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
addVertex(nextPointL, u1, 0);
|
1581
|
-
} else {
|
1582
|
-
addVertex(currentPointR, u1, 1);
|
1583
|
-
addVertex(outerPoint, u1, 1);
|
1584
|
-
addVertex(currentPoint, u1, 0.5);
|
1585
|
-
addVertex(currentPoint, u1, 0.5);
|
1586
|
-
addVertex(outerPoint, u1, 1);
|
1587
|
-
addVertex(nextPointR, u1, 1);
|
1588
|
-
}
|
1578
|
+
addVertex(currentPointR, u1, 1);
|
1579
|
+
addVertex(outerPoint, u1, 1);
|
1580
|
+
addVertex(currentPoint, u1, 0.5);
|
1581
|
+
addVertex(currentPoint, u1, 0.5);
|
1582
|
+
addVertex(outerPoint, u1, 1);
|
1583
|
+
addVertex(nextPointR, u1, 1);
|
1589
1584
|
}
|
1590
|
-
isMiter = true;
|
1591
1585
|
}
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
makeSegmentTriangles();
|
1586
|
+
isMiter = true;
|
1587
|
+
}
|
1588
|
+
break;
|
1596
1589
|
}
|
1597
1590
|
} else {
|
1598
1591
|
makeSegmentTriangles();
|
1599
1592
|
}
|
1600
|
-
|
1601
|
-
|
1602
|
-
}
|
1603
|
-
u0 = u1;
|
1604
|
-
previousPoint = currentPoint;
|
1605
|
-
lastPointL.copy(nextPointL);
|
1606
|
-
lastPointR.copy(nextPointR);
|
1607
|
-
}
|
1608
|
-
if (!isClosed) {
|
1609
|
-
addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
|
1610
|
-
} else if (innerSideModified && vertices) {
|
1611
|
-
let lastOuter = outerPoint;
|
1612
|
-
let lastInner = innerPoint;
|
1613
|
-
if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
|
1614
|
-
lastOuter = innerPoint;
|
1615
|
-
lastInner = outerPoint;
|
1616
|
-
}
|
1617
|
-
if (joinIsOnLeftSide) {
|
1618
|
-
if (isMiter || initialJoinIsOnLeftSide) {
|
1619
|
-
lastInner.toArray(vertices, 0 * 3);
|
1620
|
-
lastInner.toArray(vertices, 3 * 3);
|
1621
|
-
if (isMiter) {
|
1622
|
-
lastOuter.toArray(vertices, 1 * 3);
|
1623
|
-
}
|
1624
|
-
}
|
1625
|
-
} else {
|
1626
|
-
if (isMiter || !initialJoinIsOnLeftSide) {
|
1627
|
-
lastInner.toArray(vertices, 1 * 3);
|
1628
|
-
lastInner.toArray(vertices, 3 * 3);
|
1629
|
-
if (isMiter) {
|
1630
|
-
lastOuter.toArray(vertices, 0 * 3);
|
1631
|
-
}
|
1632
|
-
}
|
1633
|
-
}
|
1593
|
+
} else {
|
1594
|
+
makeSegmentTriangles();
|
1634
1595
|
}
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1596
|
+
if (!isClosed && iPoint === numPoints - 1) {
|
1597
|
+
addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
|
1598
|
+
}
|
1599
|
+
u0 = u1;
|
1600
|
+
previousPoint = currentPoint;
|
1601
|
+
lastPointL.copy(nextPointL);
|
1602
|
+
lastPointR.copy(nextPointR);
|
1603
|
+
}
|
1604
|
+
if (!isClosed) {
|
1605
|
+
addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
|
1606
|
+
} else if (innerSideModified && vertices) {
|
1607
|
+
let lastOuter = outerPoint;
|
1608
|
+
let lastInner = innerPoint;
|
1609
|
+
if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
|
1610
|
+
lastOuter = innerPoint;
|
1611
|
+
lastInner = outerPoint;
|
1612
|
+
}
|
1613
|
+
if (joinIsOnLeftSide) {
|
1614
|
+
if (isMiter || initialJoinIsOnLeftSide) {
|
1615
|
+
lastInner.toArray(vertices, 0 * 3);
|
1616
|
+
lastInner.toArray(vertices, 3 * 3);
|
1617
|
+
if (isMiter) {
|
1618
|
+
lastOuter.toArray(vertices, 1 * 3);
|
1649
1619
|
}
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1620
|
+
}
|
1621
|
+
} else {
|
1622
|
+
if (isMiter || !initialJoinIsOnLeftSide) {
|
1623
|
+
lastInner.toArray(vertices, 1 * 3);
|
1624
|
+
lastInner.toArray(vertices, 3 * 3);
|
1625
|
+
if (isMiter) {
|
1626
|
+
lastOuter.toArray(vertices, 0 * 3);
|
1655
1627
|
}
|
1656
1628
|
}
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1629
|
+
}
|
1630
|
+
}
|
1631
|
+
return numVertices;
|
1632
|
+
function getNormal(p1, p2, result) {
|
1633
|
+
result.subVectors(p2, p1);
|
1634
|
+
return result.set(-result.y, result.x).normalize();
|
1635
|
+
}
|
1636
|
+
function addVertex(position, u, v) {
|
1637
|
+
if (vertices) {
|
1638
|
+
vertices[currentCoordinate] = position.x;
|
1639
|
+
vertices[currentCoordinate + 1] = position.y;
|
1640
|
+
vertices[currentCoordinate + 2] = 0;
|
1641
|
+
if (normals) {
|
1642
|
+
normals[currentCoordinate] = 0;
|
1643
|
+
normals[currentCoordinate + 1] = 0;
|
1644
|
+
normals[currentCoordinate + 2] = 1;
|
1645
|
+
}
|
1646
|
+
currentCoordinate += 3;
|
1647
|
+
if (uvs) {
|
1648
|
+
uvs[currentCoordinateUV] = u;
|
1649
|
+
uvs[currentCoordinateUV + 1] = v;
|
1650
|
+
currentCoordinateUV += 2;
|
1674
1651
|
}
|
1652
|
+
}
|
1653
|
+
numVertices += 3;
|
1654
|
+
}
|
1655
|
+
function makeCircularSector(center, p1, p2, u, v) {
|
1656
|
+
tempV2_1.copy(p1).sub(center).normalize();
|
1657
|
+
tempV2_2.copy(p2).sub(center).normalize();
|
1658
|
+
let angle = Math.PI;
|
1659
|
+
const dot = tempV2_1.dot(tempV2_2);
|
1660
|
+
if (Math.abs(dot) < 1)
|
1661
|
+
angle = Math.abs(Math.acos(dot));
|
1662
|
+
angle /= arcDivisions;
|
1663
|
+
tempV2_3.copy(p1);
|
1664
|
+
for (let i = 0, il = arcDivisions - 1; i < il; i++) {
|
1665
|
+
tempV2_4.copy(tempV2_3).rotateAround(center, angle);
|
1666
|
+
addVertex(tempV2_3, u, v);
|
1675
1667
|
addVertex(tempV2_4, u, v);
|
1676
|
-
addVertex(p2, u, v);
|
1677
1668
|
addVertex(center, u, 0.5);
|
1669
|
+
tempV2_3.copy(tempV2_4);
|
1678
1670
|
}
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
addVertex(lastPointL, u0, 0);
|
1704
|
-
addVertex(innerPoint, u1, 0);
|
1705
|
-
addVertex(currentPointR, u1, 1);
|
1706
|
-
addVertex(currentPointR, u, 1);
|
1707
|
-
addVertex(innerPoint, u, 0);
|
1708
|
-
addVertex(nextPointR, u, 1);
|
1709
|
-
}
|
1671
|
+
addVertex(tempV2_4, u, v);
|
1672
|
+
addVertex(p2, u, v);
|
1673
|
+
addVertex(center, u, 0.5);
|
1674
|
+
}
|
1675
|
+
function makeSegmentTriangles() {
|
1676
|
+
addVertex(lastPointR, u0, 1);
|
1677
|
+
addVertex(lastPointL, u0, 0);
|
1678
|
+
addVertex(currentPointL, u1, 0);
|
1679
|
+
addVertex(lastPointR, u0, 1);
|
1680
|
+
addVertex(currentPointL, u1, 0);
|
1681
|
+
addVertex(currentPointR, u1, 1);
|
1682
|
+
}
|
1683
|
+
function makeSegmentWithBevelJoin(joinIsOnLeftSide2, innerSideModified2, u) {
|
1684
|
+
if (innerSideModified2) {
|
1685
|
+
if (joinIsOnLeftSide2) {
|
1686
|
+
addVertex(lastPointR, u0, 1);
|
1687
|
+
addVertex(lastPointL, u0, 0);
|
1688
|
+
addVertex(currentPointL, u1, 0);
|
1689
|
+
addVertex(lastPointR, u0, 1);
|
1690
|
+
addVertex(currentPointL, u1, 0);
|
1691
|
+
addVertex(innerPoint, u1, 1);
|
1692
|
+
addVertex(currentPointL, u, 0);
|
1693
|
+
addVertex(nextPointL, u, 0);
|
1694
|
+
addVertex(innerPoint, u, 0.5);
|
1710
1695
|
} else {
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1696
|
+
addVertex(lastPointR, u0, 1);
|
1697
|
+
addVertex(lastPointL, u0, 0);
|
1698
|
+
addVertex(currentPointR, u1, 1);
|
1699
|
+
addVertex(lastPointL, u0, 0);
|
1700
|
+
addVertex(innerPoint, u1, 0);
|
1701
|
+
addVertex(currentPointR, u1, 1);
|
1702
|
+
addVertex(currentPointR, u, 1);
|
1703
|
+
addVertex(innerPoint, u, 0);
|
1704
|
+
addVertex(nextPointR, u, 1);
|
1705
|
+
}
|
1706
|
+
} else {
|
1707
|
+
if (joinIsOnLeftSide2) {
|
1708
|
+
addVertex(currentPointL, u, 0);
|
1709
|
+
addVertex(nextPointL, u, 0);
|
1710
|
+
addVertex(currentPoint, u, 0.5);
|
1711
|
+
} else {
|
1712
|
+
addVertex(currentPointR, u, 1);
|
1713
|
+
addVertex(nextPointR, u, 0);
|
1714
|
+
addVertex(currentPoint, u, 0.5);
|
1720
1715
|
}
|
1721
1716
|
}
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1717
|
+
}
|
1718
|
+
function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide2, innerSideModified2) {
|
1719
|
+
if (innerSideModified2) {
|
1720
|
+
if (joinIsOnLeftSide2) {
|
1721
|
+
addVertex(lastPointR, u0, 1);
|
1722
|
+
addVertex(lastPointL, u0, 0);
|
1723
|
+
addVertex(currentPointL, u1, 0);
|
1724
|
+
addVertex(lastPointR, u0, 1);
|
1725
|
+
addVertex(currentPointL, u1, 0);
|
1726
|
+
addVertex(innerPoint, u1, 1);
|
1727
|
+
addVertex(currentPointL, u0, 0);
|
1728
|
+
addVertex(currentPoint, u1, 0.5);
|
1729
|
+
addVertex(innerPoint, u1, 1);
|
1730
|
+
addVertex(currentPoint, u1, 0.5);
|
1731
|
+
addVertex(nextPointL, u0, 0);
|
1732
|
+
addVertex(innerPoint, u1, 1);
|
1733
|
+
} else {
|
1734
|
+
addVertex(lastPointR, u0, 1);
|
1735
|
+
addVertex(lastPointL, u0, 0);
|
1736
|
+
addVertex(currentPointR, u1, 1);
|
1737
|
+
addVertex(lastPointL, u0, 0);
|
1738
|
+
addVertex(innerPoint, u1, 0);
|
1739
|
+
addVertex(currentPointR, u1, 1);
|
1740
|
+
addVertex(currentPointR, u0, 1);
|
1741
|
+
addVertex(innerPoint, u1, 0);
|
1742
|
+
addVertex(currentPoint, u1, 0.5);
|
1743
|
+
addVertex(currentPoint, u1, 0.5);
|
1744
|
+
addVertex(innerPoint, u1, 0);
|
1745
|
+
addVertex(nextPointR, u0, 1);
|
1751
1746
|
}
|
1752
1747
|
}
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1748
|
+
}
|
1749
|
+
function addCapGeometry(center, p1, p2, joinIsOnLeftSide2, start, u) {
|
1750
|
+
switch (style.strokeLineCap) {
|
1751
|
+
case "round":
|
1752
|
+
if (start) {
|
1753
|
+
makeCircularSector(center, p2, p1, u, 0.5);
|
1754
|
+
} else {
|
1755
|
+
makeCircularSector(center, p1, p2, u, 0.5);
|
1756
|
+
}
|
1757
|
+
break;
|
1758
|
+
case "square":
|
1759
|
+
if (start) {
|
1760
|
+
tempV2_1.subVectors(p1, center);
|
1761
|
+
tempV2_2.set(tempV2_1.y, -tempV2_1.x);
|
1762
|
+
tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
|
1763
|
+
tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
|
1764
|
+
if (joinIsOnLeftSide2) {
|
1765
|
+
tempV2_3.toArray(vertices, 1 * 3);
|
1766
|
+
tempV2_4.toArray(vertices, 0 * 3);
|
1767
|
+
tempV2_4.toArray(vertices, 3 * 3);
|
1758
1768
|
} else {
|
1759
|
-
|
1769
|
+
tempV2_3.toArray(vertices, 1 * 3);
|
1770
|
+
uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
|
1771
|
+
tempV2_4.toArray(vertices, 0 * 3);
|
1760
1772
|
}
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
tempV2_4.toArray(vertices, 3 * 3);
|
1772
|
-
} else {
|
1773
|
-
tempV2_3.toArray(vertices, 1 * 3);
|
1774
|
-
uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
|
1775
|
-
tempV2_4.toArray(vertices, 0 * 3);
|
1776
|
-
}
|
1773
|
+
} else {
|
1774
|
+
tempV2_1.subVectors(p2, center);
|
1775
|
+
tempV2_2.set(tempV2_1.y, -tempV2_1.x);
|
1776
|
+
tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
|
1777
|
+
tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
|
1778
|
+
const vl = vertices.length;
|
1779
|
+
if (joinIsOnLeftSide2) {
|
1780
|
+
tempV2_3.toArray(vertices, vl - 1 * 3);
|
1781
|
+
tempV2_4.toArray(vertices, vl - 2 * 3);
|
1782
|
+
tempV2_4.toArray(vertices, vl - 4 * 3);
|
1777
1783
|
} else {
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
|
1782
|
-
const vl = vertices.length;
|
1783
|
-
if (joinIsOnLeftSide2) {
|
1784
|
-
tempV2_3.toArray(vertices, vl - 1 * 3);
|
1785
|
-
tempV2_4.toArray(vertices, vl - 2 * 3);
|
1786
|
-
tempV2_4.toArray(vertices, vl - 4 * 3);
|
1787
|
-
} else {
|
1788
|
-
tempV2_4.toArray(vertices, vl - 2 * 3);
|
1789
|
-
tempV2_3.toArray(vertices, vl - 1 * 3);
|
1790
|
-
tempV2_4.toArray(vertices, vl - 4 * 3);
|
1791
|
-
}
|
1784
|
+
tempV2_4.toArray(vertices, vl - 2 * 3);
|
1785
|
+
tempV2_3.toArray(vertices, vl - 1 * 3);
|
1786
|
+
tempV2_4.toArray(vertices, vl - 4 * 3);
|
1792
1787
|
}
|
1793
|
-
break;
|
1794
|
-
}
|
1795
|
-
}
|
1796
|
-
function removeDuplicatedPoints(points2) {
|
1797
|
-
let dupPoints = false;
|
1798
|
-
for (let i = 1, n = points2.length - 1; i < n; i++) {
|
1799
|
-
if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
|
1800
|
-
dupPoints = true;
|
1801
|
-
break;
|
1802
1788
|
}
|
1789
|
+
break;
|
1790
|
+
}
|
1791
|
+
}
|
1792
|
+
function removeDuplicatedPoints(points2) {
|
1793
|
+
let dupPoints = false;
|
1794
|
+
for (let i = 1, n = points2.length - 1; i < n; i++) {
|
1795
|
+
if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
|
1796
|
+
dupPoints = true;
|
1797
|
+
break;
|
1803
1798
|
}
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1799
|
+
}
|
1800
|
+
if (!dupPoints)
|
1801
|
+
return points2;
|
1802
|
+
const newPoints = [];
|
1803
|
+
newPoints.push(points2[0]);
|
1804
|
+
for (let i = 1, n = points2.length - 1; i < n; i++) {
|
1805
|
+
if (points2[i].distanceTo(points2[i + 1]) >= minDistance) {
|
1806
|
+
newPoints.push(points2[i]);
|
1812
1807
|
}
|
1813
|
-
newPoints.push(points2[points2.length - 1]);
|
1814
|
-
return newPoints;
|
1815
1808
|
}
|
1809
|
+
newPoints.push(points2[points2.length - 1]);
|
1810
|
+
return newPoints;
|
1816
1811
|
}
|
1817
1812
|
}
|
1818
|
-
|
1819
|
-
})();
|
1813
|
+
}
|
1820
1814
|
export {
|
1821
1815
|
SVGLoader
|
1822
1816
|
};
|