@motionscript/core 0.1.0-alpha.6 → 0.1.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/NOTICE +15 -14
- package/README.md +5 -7
- package/dist/assets/errors.js +4 -5
- package/dist/assets/errors.js.map +1 -1
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/assets/manager.js +7 -5
- package/dist/assets/manager.js.map +1 -1
- package/dist/assets/scope.d.ts +1 -1
- package/dist/assets/scope.d.ts.map +1 -1
- package/dist/assets/scope.js +1 -1
- package/dist/assets/scope.js.map +1 -1
- package/dist/attributes/audio/effects/chain.d.ts +73 -0
- package/dist/attributes/audio/effects/chain.d.ts.map +1 -0
- package/dist/attributes/audio/effects/chain.js +67 -0
- package/dist/attributes/audio/effects/chain.js.map +1 -0
- package/dist/attributes/audio/effects/implementations/echo.d.ts +14 -0
- package/dist/attributes/audio/effects/implementations/echo.d.ts.map +1 -0
- package/dist/attributes/audio/effects/implementations/echo.js +11 -0
- package/dist/attributes/audio/effects/implementations/echo.js.map +1 -0
- package/dist/attributes/audio/effects/implementations/gain.d.ts +10 -0
- package/dist/attributes/audio/effects/implementations/gain.d.ts.map +1 -0
- package/dist/attributes/audio/effects/implementations/gain.js +6 -0
- package/dist/attributes/audio/effects/implementations/gain.js.map +1 -0
- package/dist/attributes/audio/effects/implementations/highpass.d.ts +12 -0
- package/dist/attributes/audio/effects/implementations/highpass.d.ts.map +1 -0
- package/dist/attributes/audio/effects/implementations/highpass.js +10 -0
- package/dist/attributes/audio/effects/implementations/highpass.js.map +1 -0
- package/dist/attributes/audio/effects/implementations/lowpass.d.ts +12 -0
- package/dist/attributes/audio/effects/implementations/lowpass.d.ts.map +1 -0
- package/dist/attributes/audio/effects/implementations/lowpass.js +10 -0
- package/dist/attributes/audio/effects/implementations/lowpass.js.map +1 -0
- package/dist/attributes/audio/effects/implementations/tremolo.d.ts +12 -0
- package/dist/attributes/audio/effects/implementations/tremolo.d.ts.map +1 -0
- package/dist/attributes/audio/effects/implementations/tremolo.js +10 -0
- package/dist/attributes/audio/effects/implementations/tremolo.js.map +1 -0
- package/dist/attributes/audio/effects/index.d.ts +12 -0
- package/dist/attributes/audio/effects/index.d.ts.map +1 -0
- package/dist/attributes/audio/effects/index.js +4 -0
- package/dist/attributes/audio/effects/index.js.map +1 -0
- package/dist/attributes/audio/effects/registry.d.ts +36 -0
- package/dist/attributes/audio/effects/registry.d.ts.map +1 -0
- package/dist/attributes/audio/effects/registry.js +80 -0
- package/dist/attributes/audio/effects/registry.js.map +1 -0
- package/dist/attributes/audio/effects/union.d.ts +14 -0
- package/dist/attributes/audio/effects/union.d.ts.map +1 -0
- package/dist/attributes/audio/effects/union.js +24 -0
- package/dist/attributes/audio/effects/union.js.map +1 -0
- package/dist/attributes/audio/ramp.d.ts +103 -0
- package/dist/attributes/audio/ramp.d.ts.map +1 -0
- package/dist/attributes/audio/ramp.js +246 -0
- package/dist/attributes/audio/ramp.js.map +1 -0
- package/dist/attributes/audio/request.d.ts +24 -13
- package/dist/attributes/audio/request.d.ts.map +1 -1
- package/dist/attributes/audio/request.js +4 -3
- package/dist/attributes/audio/request.js.map +1 -1
- package/dist/attributes/audio/schedule.d.ts +24 -31
- package/dist/attributes/audio/schedule.d.ts.map +1 -1
- package/dist/attributes/audio/schedule.js +42 -28
- package/dist/attributes/audio/schedule.js.map +1 -1
- package/dist/attributes/audio/sound.d.ts +15 -12
- package/dist/attributes/audio/sound.d.ts.map +1 -1
- package/dist/attributes/audio/sound.js +8 -10
- package/dist/attributes/audio/sound.js.map +1 -1
- package/dist/attributes/audio/transition.d.ts +33 -0
- package/dist/attributes/audio/transition.d.ts.map +1 -0
- package/dist/attributes/audio/transition.js +48 -0
- package/dist/attributes/audio/transition.js.map +1 -0
- package/dist/attributes/index.d.ts +7 -8
- package/dist/attributes/index.d.ts.map +1 -1
- package/dist/attributes/index.js +6 -9
- package/dist/attributes/index.js.map +1 -1
- package/dist/attributes/layout/insets.d.ts +1 -1
- package/dist/attributes/layout/insets.js.map +1 -1
- package/dist/attributes/layout/matrix2d.d.ts +2 -2
- package/dist/attributes/layout/matrix2d.js.map +1 -1
- package/dist/attributes/layout/size.d.ts +1 -1
- package/dist/attributes/layout/size.js +1 -1
- package/dist/attributes/layout/size.js.map +1 -1
- package/dist/attributes/layout/space3d.js +1 -1
- package/dist/attributes/layout/space3d.js.map +1 -1
- package/dist/attributes/properties/decorator.d.ts +44 -11
- package/dist/attributes/properties/decorator.d.ts.map +1 -1
- package/dist/attributes/properties/decorator.js +37 -9
- package/dist/attributes/properties/decorator.js.map +1 -1
- package/dist/attributes/properties/inputs.d.ts +1 -1
- package/dist/attributes/properties/inputs.js +1 -1
- package/dist/attributes/properties/inputs.js.map +1 -1
- package/dist/attributes/properties/typed.d.ts +24 -145
- package/dist/attributes/properties/typed.d.ts.map +1 -1
- package/dist/attributes/properties/typed.js +16 -112
- package/dist/attributes/properties/typed.js.map +1 -1
- package/dist/attributes/shape/corners/corner-radius.d.ts +2 -3
- package/dist/attributes/shape/corners/corner-radius.d.ts.map +1 -1
- package/dist/attributes/shape/corners/corner-radius.js +2 -3
- package/dist/attributes/shape/corners/corner-radius.js.map +1 -1
- package/dist/attributes/shape/effects/chain.d.ts +96 -409
- package/dist/attributes/shape/effects/chain.d.ts.map +1 -1
- package/dist/attributes/shape/effects/chain.js +93 -283
- package/dist/attributes/shape/effects/chain.js.map +1 -1
- package/dist/attributes/shape/effects/effect-data.d.ts +1 -1
- package/dist/attributes/shape/effects/effect-data.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/ascii.d.ts +45 -13
- package/dist/attributes/shape/effects/implementations/ascii.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/ascii.js +29 -23
- package/dist/attributes/shape/effects/implementations/ascii.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/bit-crush.d.ts +32 -7
- package/dist/attributes/shape/effects/implementations/bit-crush.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/bit-crush.js +17 -15
- package/dist/attributes/shape/effects/implementations/bit-crush.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/block-displace.d.ts +46 -10
- package/dist/attributes/shape/effects/implementations/block-displace.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/block-displace.js +21 -19
- package/dist/attributes/shape/effects/implementations/block-displace.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/bloom.d.ts +32 -7
- package/dist/attributes/shape/effects/implementations/bloom.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/bloom.js +17 -11
- package/dist/attributes/shape/effects/implementations/bloom.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/blur.d.ts +16 -3
- package/dist/attributes/shape/effects/implementations/blur.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/blur.js +13 -5
- package/dist/attributes/shape/effects/implementations/blur.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/bulge.d.ts +28 -9
- package/dist/attributes/shape/effects/implementations/bulge.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/bulge.js +15 -14
- package/dist/attributes/shape/effects/implementations/bulge.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/chromatic-aberration.d.ts +21 -5
- package/dist/attributes/shape/effects/implementations/chromatic-aberration.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/chromatic-aberration.js +15 -10
- package/dist/attributes/shape/effects/implementations/chromatic-aberration.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/color-adjustment.d.ts +96 -26
- package/dist/attributes/shape/effects/implementations/color-adjustment.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/color-adjustment.js +29 -26
- package/dist/attributes/shape/effects/implementations/color-adjustment.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/curves.d.ts +20 -6
- package/dist/attributes/shape/effects/implementations/curves.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/curves.js +26 -23
- package/dist/attributes/shape/effects/implementations/curves.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/directional-blur.d.ts +26 -5
- package/dist/attributes/shape/effects/implementations/directional-blur.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/directional-blur.js +15 -10
- package/dist/attributes/shape/effects/implementations/directional-blur.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/dither.d.ts +58 -11
- package/dist/attributes/shape/effects/implementations/dither.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/dither.js +26 -20
- package/dist/attributes/shape/effects/implementations/dither.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/drop-shadow.d.ts +47 -15
- package/dist/attributes/shape/effects/implementations/drop-shadow.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/drop-shadow.js +24 -29
- package/dist/attributes/shape/effects/implementations/drop-shadow.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/duotone.d.ts +26 -7
- package/dist/attributes/shape/effects/implementations/duotone.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/duotone.js +17 -16
- package/dist/attributes/shape/effects/implementations/duotone.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/edges.d.ts +29 -7
- package/dist/attributes/shape/effects/implementations/edges.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/edges.js +17 -14
- package/dist/attributes/shape/effects/implementations/edges.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/glass.d.ts +76 -19
- package/dist/attributes/shape/effects/implementations/glass.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/glass.js +28 -22
- package/dist/attributes/shape/effects/implementations/glass.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/glow.d.ts +149 -42
- package/dist/attributes/shape/effects/implementations/glow.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/glow.js +74 -72
- package/dist/attributes/shape/effects/implementations/glow.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/grain.d.ts +43 -11
- package/dist/attributes/shape/effects/implementations/grain.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/grain.js +21 -18
- package/dist/attributes/shape/effects/implementations/grain.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/grayscale.d.ts +17 -3
- package/dist/attributes/shape/effects/implementations/grayscale.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/grayscale.js +13 -5
- package/dist/attributes/shape/effects/implementations/grayscale.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/halftone.d.ts +40 -9
- package/dist/attributes/shape/effects/implementations/halftone.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/halftone.js +20 -16
- package/dist/attributes/shape/effects/implementations/halftone.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/invert.d.ts +23 -5
- package/dist/attributes/shape/effects/implementations/invert.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/invert.js +15 -10
- package/dist/attributes/shape/effects/implementations/invert.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/kaleidoscope.d.ts +57 -18
- package/dist/attributes/shape/effects/implementations/kaleidoscope.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/kaleidoscope.js +25 -22
- package/dist/attributes/shape/effects/implementations/kaleidoscope.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/lut.d.ts +34 -7
- package/dist/attributes/shape/effects/implementations/lut.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/lut.js +20 -16
- package/dist/attributes/shape/effects/implementations/lut.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/magnify.d.ts +27 -9
- package/dist/attributes/shape/effects/implementations/magnify.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/magnify.js +17 -14
- package/dist/attributes/shape/effects/implementations/magnify.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/motion-blur.d.ts +54 -19
- package/dist/attributes/shape/effects/implementations/motion-blur.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/motion-blur.js +42 -20
- package/dist/attributes/shape/effects/implementations/motion-blur.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/oil-paint.d.ts +17 -3
- package/dist/attributes/shape/effects/implementations/oil-paint.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/oil-paint.js +13 -9
- package/dist/attributes/shape/effects/implementations/oil-paint.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/outline.d.ts +28 -8
- package/dist/attributes/shape/effects/implementations/outline.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/outline.js +18 -17
- package/dist/attributes/shape/effects/implementations/outline.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/pixelate.d.ts +25 -6
- package/dist/attributes/shape/effects/implementations/pixelate.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/pixelate.js +16 -14
- package/dist/attributes/shape/effects/implementations/pixelate.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/posterize.d.ts +14 -3
- package/dist/attributes/shape/effects/implementations/posterize.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/posterize.js +13 -9
- package/dist/attributes/shape/effects/implementations/posterize.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/progressive-blur.d.ts +91 -26
- package/dist/attributes/shape/effects/implementations/progressive-blur.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/progressive-blur.js +27 -28
- package/dist/attributes/shape/effects/implementations/progressive-blur.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/radial-blur.d.ts +49 -10
- package/dist/attributes/shape/effects/implementations/radial-blur.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/radial-blur.js +19 -20
- package/dist/attributes/shape/effects/implementations/radial-blur.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/rgb-shift.d.ts +36 -6
- package/dist/attributes/shape/effects/implementations/rgb-shift.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/rgb-shift.js +16 -15
- package/dist/attributes/shape/effects/implementations/rgb-shift.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/scanlines.d.ts +52 -11
- package/dist/attributes/shape/effects/implementations/scanlines.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/scanlines.js +21 -18
- package/dist/attributes/shape/effects/implementations/scanlines.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/scatter.d.ts +23 -9
- package/dist/attributes/shape/effects/implementations/scatter.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/scatter.js +15 -12
- package/dist/attributes/shape/effects/implementations/scatter.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/shader.d.ts +90 -34
- package/dist/attributes/shape/effects/implementations/shader.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/shader.js +42 -26
- package/dist/attributes/shape/effects/implementations/shader.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/sharpen.d.ts +23 -5
- package/dist/attributes/shape/effects/implementations/sharpen.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/sharpen.js +16 -11
- package/dist/attributes/shape/effects/implementations/sharpen.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/streak.d.ts +40 -9
- package/dist/attributes/shape/effects/implementations/streak.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/streak.js +19 -16
- package/dist/attributes/shape/effects/implementations/streak.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/threshold.d.ts +24 -5
- package/dist/attributes/shape/effects/implementations/threshold.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/threshold.js +17 -11
- package/dist/attributes/shape/effects/implementations/threshold.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/twirl.d.ts +35 -8
- package/dist/attributes/shape/effects/implementations/twirl.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/twirl.js +17 -16
- package/dist/attributes/shape/effects/implementations/twirl.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/vignette.d.ts +37 -7
- package/dist/attributes/shape/effects/implementations/vignette.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/vignette.js +19 -18
- package/dist/attributes/shape/effects/implementations/vignette.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/vintage.d.ts +24 -5
- package/dist/attributes/shape/effects/implementations/vintage.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/vintage.js +15 -10
- package/dist/attributes/shape/effects/implementations/vintage.js.map +1 -1
- package/dist/attributes/shape/effects/implementations/wave.d.ts +61 -14
- package/dist/attributes/shape/effects/implementations/wave.d.ts.map +1 -1
- package/dist/attributes/shape/effects/implementations/wave.js +26 -23
- package/dist/attributes/shape/effects/implementations/wave.js.map +1 -1
- package/dist/attributes/shape/effects/index.d.ts +4 -2
- package/dist/attributes/shape/effects/index.d.ts.map +1 -1
- package/dist/attributes/shape/effects/index.js +1 -1
- package/dist/attributes/shape/effects/index.js.map +1 -1
- package/dist/attributes/shape/effects/registry.d.ts +11 -0
- package/dist/attributes/shape/effects/registry.d.ts.map +1 -1
- package/dist/attributes/shape/effects/registry.js +113 -102
- package/dist/attributes/shape/effects/registry.js.map +1 -1
- package/dist/attributes/shape/effects/spec.d.ts +229 -0
- package/dist/attributes/shape/effects/spec.d.ts.map +1 -0
- package/dist/attributes/shape/effects/spec.js +178 -0
- package/dist/attributes/shape/effects/spec.js.map +1 -0
- package/dist/attributes/shape/fill/chain.d.ts +7 -9
- package/dist/attributes/shape/fill/chain.d.ts.map +1 -1
- package/dist/attributes/shape/fill/chain.js +9 -11
- package/dist/attributes/shape/fill/chain.js.map +1 -1
- package/dist/attributes/shape/fill/color/parser.d.ts +1 -1
- package/dist/attributes/shape/fill/color/parser.js +1 -1
- package/dist/attributes/shape/fill/color/parser.js.map +1 -1
- package/dist/attributes/shape/fill/implementations/canvas3d.d.ts +2 -2
- package/dist/attributes/shape/fill/implementations/canvas3d.js.map +1 -1
- package/dist/attributes/shape/fill/implementations/shader.d.ts +28 -27
- package/dist/attributes/shape/fill/implementations/shader.d.ts.map +1 -1
- package/dist/attributes/shape/fill/implementations/shader.js +20 -14
- package/dist/attributes/shape/fill/implementations/shader.js.map +1 -1
- package/dist/attributes/shape/fill/implementations/video.d.ts +1 -1
- package/dist/attributes/shape/fill/implementations/video.js +1 -1
- package/dist/attributes/shape/fill/implementations/video.js.map +1 -1
- package/dist/attributes/shape/fill/index.d.ts +1 -1
- package/dist/attributes/shape/fill/index.d.ts.map +1 -1
- package/dist/attributes/shape/fill/index.js.map +1 -1
- package/dist/attributes/shape/fill/lerp.d.ts +1 -1
- package/dist/attributes/shape/fill/lerp.js.map +1 -1
- package/dist/attributes/shape/fill/registry.d.ts +1 -2
- package/dist/attributes/shape/fill/registry.d.ts.map +1 -1
- package/dist/attributes/shape/fill/registry.js +1 -2
- package/dist/attributes/shape/fill/registry.js.map +1 -1
- package/dist/attributes/shape/filters/chain.d.ts +3 -7
- package/dist/attributes/shape/filters/chain.d.ts.map +1 -1
- package/dist/attributes/shape/filters/chain.js +2 -6
- package/dist/attributes/shape/filters/chain.js.map +1 -1
- package/dist/attributes/shape/filters/implementations/color-matrix.d.ts +2 -2
- package/dist/attributes/shape/filters/implementations/color-matrix.d.ts.map +1 -1
- package/dist/attributes/shape/filters/implementations/color-matrix.js.map +1 -1
- package/dist/attributes/shape/filters/registry.d.ts +1 -1
- package/dist/attributes/shape/filters/registry.d.ts.map +1 -1
- package/dist/attributes/shape/filters/registry.js +3 -3
- package/dist/attributes/shape/filters/registry.js.map +1 -1
- package/dist/attributes/shape/filters/union.d.ts +6 -6
- package/dist/attributes/shape/filters/union.d.ts.map +1 -1
- package/dist/attributes/shape/filters/union.js.map +1 -1
- package/dist/attributes/shape/path/ops.d.ts +1 -2
- package/dist/attributes/shape/path/ops.d.ts.map +1 -1
- package/dist/attributes/shape/path/ops.js.map +1 -1
- package/dist/attributes/shape/shaders/index.d.ts +2 -0
- package/dist/attributes/shape/shaders/index.d.ts.map +1 -1
- package/dist/attributes/shape/shaders/index.js +2 -0
- package/dist/attributes/shape/shaders/index.js.map +1 -1
- package/dist/attributes/shape/shaders/language.d.ts +26 -0
- package/dist/attributes/shape/shaders/language.d.ts.map +1 -0
- package/dist/attributes/shape/shaders/language.js +20 -0
- package/dist/attributes/shape/shaders/language.js.map +1 -0
- package/dist/attributes/shape/shaders/pack.d.ts +25 -11
- package/dist/attributes/shape/shaders/pack.d.ts.map +1 -1
- package/dist/attributes/shape/shaders/pack.js +9 -4
- package/dist/attributes/shape/shaders/pack.js.map +1 -1
- package/dist/attributes/shape/shaders/resolve.d.ts +4 -5
- package/dist/attributes/shape/shaders/resolve.d.ts.map +1 -1
- package/dist/attributes/shape/shaders/resolve.js +3 -6
- package/dist/attributes/shape/shaders/resolve.js.map +1 -1
- package/dist/attributes/shape/shaders/uniforms.d.ts +41 -0
- package/dist/attributes/shape/shaders/uniforms.d.ts.map +1 -0
- package/dist/attributes/shape/shaders/uniforms.js +0 -0
- package/dist/attributes/shape/shaders/uniforms.js.map +1 -0
- package/dist/attributes/shared/operators.d.ts +2 -2
- package/dist/attributes/shared/operators.js.map +1 -1
- package/dist/attributes/text/types.d.ts +2 -3
- package/dist/attributes/text/types.d.ts.map +1 -1
- package/dist/attributes/text/types.js.map +1 -1
- package/dist/browser/chunks/chunk-AOT33LMS.js +13 -0
- package/dist/browser/chunks/chunk-AOT33LMS.js.map +7 -0
- package/dist/browser/chunks/chunk-GKM6UZJR.js +6 -0
- package/dist/browser/chunks/chunk-GKM6UZJR.js.map +7 -0
- package/dist/browser/chunks/chunk-LKUYVFU3.js +2 -0
- package/dist/browser/chunks/{chunk-DHB4COFY.js.map → chunk-LKUYVFU3.js.map} +4 -4
- package/dist/browser/chunks/chunk-ZRPZPWZU.js +3 -0
- package/dist/browser/chunks/chunk-ZRPZPWZU.js.map +7 -0
- package/dist/browser/component.js +1 -1
- package/dist/browser/component.js.map +4 -4
- package/dist/browser/experimental.js +1 -1
- package/dist/browser/experimental.js.map +4 -4
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/manifest.json +2 -4
- package/dist/browser/sdk.js +1 -1
- package/dist/component.d.ts +10 -18
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +10 -17
- package/dist/component.js.map +1 -1
- package/dist/components/builtins/audio/audio.d.ts +62 -0
- package/dist/components/builtins/audio/audio.d.ts.map +1 -0
- package/dist/components/builtins/audio/audio.js +38 -0
- package/dist/components/builtins/audio/audio.js.map +1 -0
- package/dist/components/builtins/geometry/composite.d.ts +93 -0
- package/dist/components/builtins/geometry/composite.d.ts.map +1 -0
- package/dist/components/builtins/geometry/composite.js +25 -0
- package/dist/components/builtins/geometry/composite.js.map +1 -0
- package/dist/components/builtins/geometry/geometry.d.ts +921 -0
- package/dist/components/builtins/geometry/geometry.d.ts.map +1 -0
- package/dist/components/builtins/geometry/geometry.js +107 -0
- package/dist/components/builtins/geometry/geometry.js.map +1 -0
- package/dist/components/builtins/geometry/shape-outline.d.ts +93 -0
- package/dist/components/builtins/geometry/shape-outline.d.ts.map +1 -0
- package/dist/components/builtins/geometry/shape-outline.js +470 -0
- package/dist/components/builtins/geometry/shape-outline.js.map +1 -0
- package/dist/components/builtins/layout/layout.d.ts +186 -0
- package/dist/components/builtins/layout/layout.d.ts.map +1 -0
- package/dist/components/builtins/layout/layout.js +84 -0
- package/dist/components/builtins/layout/layout.js.map +1 -0
- package/dist/components/builtins/media/media.d.ts +240 -0
- package/dist/components/builtins/media/media.d.ts.map +1 -0
- package/dist/components/builtins/media/media.js +143 -0
- package/dist/components/builtins/media/media.js.map +1 -0
- package/dist/components/builtins/providers/providers.d.ts +47 -0
- package/dist/components/builtins/providers/providers.d.ts.map +1 -0
- package/dist/components/builtins/providers/providers.js +30 -0
- package/dist/components/builtins/providers/providers.js.map +1 -0
- package/dist/components/builtins/text/number-format.d.ts +66 -0
- package/dist/components/builtins/text/number-format.d.ts.map +1 -0
- package/dist/components/builtins/text/number-format.js +227 -0
- package/dist/components/builtins/text/number-format.js.map +1 -0
- package/dist/components/builtins/text/number-pattern.d.ts +51 -0
- package/dist/components/builtins/text/number-pattern.d.ts.map +1 -0
- package/dist/components/builtins/text/number-pattern.js +77 -0
- package/dist/components/builtins/text/number-pattern.js.map +1 -0
- package/dist/components/builtins/text/text-defaults.d.ts +32 -0
- package/dist/components/builtins/text/text-defaults.d.ts.map +1 -0
- package/dist/components/builtins/text/text-defaults.js +37 -0
- package/dist/components/builtins/text/text-defaults.js.map +1 -0
- package/dist/components/builtins/text/text-layout.d.ts +82 -0
- package/dist/components/builtins/text/text-layout.d.ts.map +1 -0
- package/dist/components/builtins/text/text-layout.js +331 -0
- package/dist/components/builtins/text/text-layout.js.map +1 -0
- package/dist/components/builtins/text/text.d.ts +409 -0
- package/dist/components/builtins/text/text.d.ts.map +1 -0
- package/dist/components/builtins/text/text.js +116 -0
- package/dist/components/builtins/text/text.js.map +1 -0
- package/dist/components/builtins/three/canvas3d.d.ts +245 -0
- package/dist/components/builtins/three/canvas3d.d.ts.map +1 -0
- package/dist/components/builtins/three/canvas3d.js +21 -0
- package/dist/components/builtins/three/canvas3d.js.map +1 -0
- package/dist/components/builtins/three/grid-geometry3d.d.ts +62 -0
- package/dist/components/builtins/three/grid-geometry3d.d.ts.map +1 -0
- package/dist/components/builtins/three/grid-geometry3d.js +114 -0
- package/dist/components/builtins/three/grid-geometry3d.js.map +1 -0
- package/dist/components/builtins/three/three.d.ts +1889 -0
- package/dist/components/builtins/three/three.d.ts.map +1 -0
- package/dist/components/builtins/three/three.js +305 -0
- package/dist/components/builtins/three/three.js.map +1 -0
- package/dist/components/factory/api.d.ts +543 -0
- package/dist/components/factory/api.d.ts.map +1 -0
- package/dist/components/factory/api.js +4 -0
- package/dist/components/factory/api.js.map +1 -0
- package/dist/components/factory/clip-of.d.ts +5 -0
- package/dist/components/factory/clip-of.d.ts.map +1 -0
- package/dist/components/factory/clip-of.js +33 -0
- package/dist/components/factory/clip-of.js.map +1 -0
- package/dist/components/factory/commands-for.d.ts +19 -0
- package/dist/components/factory/commands-for.d.ts.map +1 -0
- package/dist/components/factory/commands-for.js +5 -0
- package/dist/components/factory/commands-for.js.map +1 -0
- package/dist/components/factory/component-audio.d.ts +9 -0
- package/dist/components/factory/component-audio.d.ts.map +1 -0
- package/dist/components/factory/component-audio.js +18 -0
- package/dist/components/factory/component-audio.js.map +1 -0
- package/dist/components/factory/component2d.d.ts +8 -0
- package/dist/components/factory/component2d.d.ts.map +1 -0
- package/dist/components/factory/component2d.js +240 -0
- package/dist/components/factory/component2d.js.map +1 -0
- package/dist/components/factory/component3d.d.ts +9 -0
- package/dist/components/factory/component3d.d.ts.map +1 -0
- package/dist/components/factory/component3d.js +107 -0
- package/dist/components/factory/component3d.js.map +1 -0
- package/dist/components/factory/factory.d.ts +66 -0
- package/dist/components/factory/factory.d.ts.map +1 -0
- package/dist/components/factory/factory.js +347 -0
- package/dist/components/factory/factory.js.map +1 -0
- package/dist/components/factory/timeline.d.ts +22 -0
- package/dist/components/factory/timeline.d.ts.map +1 -0
- package/dist/components/factory/timeline.js +128 -0
- package/dist/components/factory/timeline.js.map +1 -0
- package/dist/components/factory/type-def.d.ts +26 -0
- package/dist/components/factory/type-def.d.ts.map +1 -0
- package/dist/components/factory/type-def.js +16 -0
- package/dist/components/factory/type-def.js.map +1 -0
- package/dist/components/factory/types.d.ts +91 -0
- package/dist/components/factory/types.d.ts.map +1 -0
- package/dist/components/factory/types.js +88 -0
- package/dist/components/factory/types.js.map +1 -0
- package/dist/components/factory/views.d.ts +121 -0
- package/dist/components/factory/views.d.ts.map +1 -0
- package/dist/components/factory/views.js +413 -0
- package/dist/components/factory/views.js.map +1 -0
- package/dist/components/modules/aim.d.ts +30 -0
- package/dist/components/modules/aim.d.ts.map +1 -0
- package/dist/components/modules/aim.js +39 -0
- package/dist/components/modules/aim.js.map +1 -0
- package/dist/components/modules/corners.d.ts +13 -0
- package/dist/components/modules/corners.d.ts.map +1 -0
- package/dist/components/modules/corners.js +12 -0
- package/dist/components/modules/corners.js.map +1 -0
- package/dist/components/modules/flow.d.ts +26 -0
- package/dist/components/modules/flow.d.ts.map +1 -0
- package/dist/components/modules/flow.js +57 -0
- package/dist/components/modules/flow.js.map +1 -0
- package/dist/components/modules/material.d.ts +40 -0
- package/dist/components/modules/material.d.ts.map +1 -0
- package/dist/components/modules/material.js +75 -0
- package/dist/components/modules/material.js.map +1 -0
- package/dist/components/modules/paint.d.ts +71 -0
- package/dist/components/modules/paint.d.ts.map +1 -0
- package/dist/components/modules/paint.js +106 -0
- package/dist/components/modules/paint.js.map +1 -0
- package/dist/components/modules/shapes.d.ts +31 -0
- package/dist/components/modules/shapes.d.ts.map +1 -0
- package/dist/components/modules/shapes.js +43 -0
- package/dist/components/modules/shapes.js.map +1 -0
- package/dist/components/modules/text-layout.d.ts +26 -0
- package/dist/components/modules/text-layout.d.ts.map +1 -0
- package/dist/components/modules/text-layout.js +57 -0
- package/dist/components/modules/text-layout.js.map +1 -0
- package/dist/components/modules/text-style.d.ts +48 -0
- package/dist/components/modules/text-style.d.ts.map +1 -0
- package/dist/components/modules/text-style.js +63 -0
- package/dist/components/modules/text-style.js.map +1 -0
- package/dist/components/modules/three-entries.d.ts +23 -0
- package/dist/components/modules/three-entries.d.ts.map +1 -0
- package/dist/components/modules/three-entries.js +41 -0
- package/dist/components/modules/three-entries.js.map +1 -0
- package/dist/components/modules/view3d.d.ts +59 -0
- package/dist/components/modules/view3d.d.ts.map +1 -0
- package/dist/components/modules/view3d.js +171 -0
- package/dist/components/modules/view3d.js.map +1 -0
- package/dist/components/trees/2d/group-bounds.d.ts +56 -0
- package/dist/components/trees/2d/group-bounds.d.ts.map +1 -0
- package/dist/components/trees/2d/group-bounds.js +87 -0
- package/dist/components/trees/2d/group-bounds.js.map +1 -0
- package/dist/components/trees/2d/node-lifecycle.d.ts +46 -0
- package/dist/components/trees/2d/node-lifecycle.d.ts.map +1 -0
- package/dist/components/trees/2d/node-lifecycle.js +264 -0
- package/dist/components/trees/2d/node-lifecycle.js.map +1 -0
- package/dist/components/trees/2d/node-motion.d.ts +56 -0
- package/dist/components/trees/2d/node-motion.d.ts.map +1 -0
- package/dist/components/trees/2d/node-motion.js +86 -0
- package/dist/components/trees/2d/node-motion.js.map +1 -0
- package/dist/components/trees/2d/node-render.d.ts +36 -0
- package/dist/components/trees/2d/node-render.d.ts.map +1 -0
- package/dist/components/trees/2d/node-render.js +67 -0
- package/dist/components/trees/2d/node-render.js.map +1 -0
- package/dist/components/trees/2d/node-space.d.ts +63 -0
- package/dist/components/trees/2d/node-space.d.ts.map +1 -0
- package/dist/components/trees/2d/node-space.js +131 -0
- package/dist/components/trees/2d/node-space.js.map +1 -0
- package/dist/components/trees/2d/node-transform.d.ts +55 -0
- package/dist/components/trees/2d/node-transform.d.ts.map +1 -0
- package/dist/components/trees/2d/node-transform.js +73 -0
- package/dist/components/trees/2d/node-transform.js.map +1 -0
- package/dist/components/trees/2d/node2d.d.ts +1020 -0
- package/dist/components/trees/2d/node2d.d.ts.map +1 -0
- package/dist/components/trees/2d/node2d.js +1481 -0
- package/dist/components/trees/2d/node2d.js.map +1 -0
- package/dist/components/trees/audio/index.d.ts +2 -0
- package/dist/components/trees/audio/index.d.ts.map +1 -0
- package/dist/components/trees/audio/index.js +2 -0
- package/dist/components/trees/audio/index.js.map +1 -0
- package/dist/components/trees/audio/node-audio.d.ts +116 -0
- package/dist/components/trees/audio/node-audio.d.ts.map +1 -0
- package/dist/components/trees/audio/node-audio.js +171 -0
- package/dist/components/trees/audio/node-audio.js.map +1 -0
- package/dist/components/trees/index.d.ts +10 -0
- package/dist/components/trees/index.d.ts.map +1 -0
- package/dist/components/trees/index.js +14 -0
- package/dist/components/trees/index.js.map +1 -0
- package/dist/components/trees/node/node-editor-state.d.ts +53 -0
- package/dist/components/trees/node/node-editor-state.d.ts.map +1 -0
- package/dist/components/trees/node/node-editor-state.js +23 -0
- package/dist/components/trees/node/node-editor-state.js.map +1 -0
- package/dist/components/trees/node/node-reactive.d.ts +89 -0
- package/dist/components/trees/node/node-reactive.d.ts.map +1 -0
- package/dist/components/trees/node/node-reactive.js +135 -0
- package/dist/components/trees/node/node-reactive.js.map +1 -0
- package/dist/components/trees/node/node-time.d.ts +39 -0
- package/dist/components/trees/node/node-time.d.ts.map +1 -0
- package/dist/components/trees/node/node-time.js +14 -0
- package/dist/components/trees/node/node-time.js.map +1 -0
- package/dist/components/trees/node/node-walk.d.ts +46 -0
- package/dist/components/trees/node/node-walk.d.ts.map +1 -0
- package/dist/components/trees/node/node-walk.js +74 -0
- package/dist/components/trees/node/node-walk.js.map +1 -0
- package/dist/components/trees/node/node.d.ts +401 -0
- package/dist/components/trees/node/node.d.ts.map +1 -0
- package/dist/components/trees/node/node.js +680 -0
- package/dist/components/trees/node/node.js.map +1 -0
- package/dist/components/trees/root/canvas2d-node.d.ts +163 -0
- package/dist/components/trees/root/canvas2d-node.d.ts.map +1 -0
- package/dist/components/trees/root/canvas2d-node.js +216 -0
- package/dist/components/trees/root/canvas2d-node.js.map +1 -0
- package/dist/components/trees/three/node3d.d.ts +222 -0
- package/dist/components/trees/three/node3d.d.ts.map +1 -0
- package/dist/components/trees/three/node3d.js +289 -0
- package/dist/components/trees/three/node3d.js.map +1 -0
- package/dist/document/builtins.js +13 -13
- package/dist/document/builtins.js.map +1 -1
- package/dist/document/command-traits.d.ts +14 -4
- package/dist/document/command-traits.d.ts.map +1 -1
- package/dist/document/command-traits.js +35 -7
- package/dist/document/command-traits.js.map +1 -1
- package/dist/document/deny-globals.d.ts +2 -2
- package/dist/document/deny-globals.js +2 -2
- package/dist/document/deny-globals.js.map +1 -1
- package/dist/document/expression/index.d.ts +1 -1
- package/dist/document/expression/index.js +1 -1
- package/dist/document/expression/index.js.map +1 -1
- package/dist/document/expression/ops.js +1 -1
- package/dist/document/expression/ops.js.map +1 -1
- package/dist/document/index.d.ts +9 -2
- package/dist/document/index.d.ts.map +1 -1
- package/dist/document/index.js +5 -2
- package/dist/document/index.js.map +1 -1
- package/dist/document/migrate.d.ts +70 -0
- package/dist/document/migrate.d.ts.map +1 -0
- package/dist/document/migrate.js +202 -0
- package/dist/document/migrate.js.map +1 -0
- package/dist/document/missing-node.d.ts +27 -0
- package/dist/document/missing-node.d.ts.map +1 -0
- package/dist/document/missing-node.js +48 -0
- package/dist/document/missing-node.js.map +1 -0
- package/dist/document/node-decorator.d.ts +14 -10
- package/dist/document/node-decorator.d.ts.map +1 -1
- package/dist/document/node-decorator.js +14 -10
- package/dist/document/node-decorator.js.map +1 -1
- package/dist/document/node-descriptor.d.ts +7 -3
- package/dist/document/node-descriptor.d.ts.map +1 -1
- package/dist/document/node-descriptor.js.map +1 -1
- package/dist/document/placement.d.ts +2 -1
- package/dist/document/placement.d.ts.map +1 -1
- package/dist/document/placement.js.map +1 -1
- package/dist/document/project.d.ts +2 -0
- package/dist/document/project.d.ts.map +1 -1
- package/dist/document/project.js +1 -0
- package/dist/document/project.js.map +1 -1
- package/dist/document/prop-evolution.d.ts +51 -0
- package/dist/document/prop-evolution.d.ts.map +1 -0
- package/dist/document/prop-evolution.js +83 -0
- package/dist/document/prop-evolution.js.map +1 -0
- package/dist/document/registry.d.ts +39 -25
- package/dist/document/registry.d.ts.map +1 -1
- package/dist/document/registry.js +41 -21
- package/dist/document/registry.js.map +1 -1
- package/dist/document/settled-index.d.ts +2 -0
- package/dist/document/settled-index.d.ts.map +1 -1
- package/dist/document/settled-index.js +5 -5
- package/dist/document/settled-index.js.map +1 -1
- package/dist/document/timeline-patch.d.ts +4 -0
- package/dist/document/timeline-patch.d.ts.map +1 -1
- package/dist/document/timeline-patch.js +28 -3
- package/dist/document/timeline-patch.js.map +1 -1
- package/dist/document/timeline.d.ts +48 -4
- package/dist/document/timeline.d.ts.map +1 -1
- package/dist/document/timeline.js +174 -44
- package/dist/document/timeline.js.map +1 -1
- package/dist/document/types.d.ts +18 -32
- package/dist/document/types.d.ts.map +1 -1
- package/dist/document/types.js.map +1 -1
- package/dist/document/validate.d.ts +18 -6
- package/dist/document/validate.d.ts.map +1 -1
- package/dist/document/validate.js +158 -21
- package/dist/document/validate.js.map +1 -1
- package/dist/document/vocabulary.d.ts +28 -0
- package/dist/document/vocabulary.d.ts.map +1 -0
- package/dist/document/vocabulary.js +42 -0
- package/dist/document/vocabulary.js.map +1 -0
- package/dist/experimental.d.ts +79 -19
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +31 -17
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +10 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -11
- package/dist/index.js.map +1 -1
- package/dist/layout/types.d.ts +1 -1
- package/dist/layout/types.js.map +1 -1
- package/dist/platform/exporter.d.ts +13 -0
- package/dist/platform/exporter.d.ts.map +1 -1
- package/dist/platform/exporter.js.map +1 -1
- package/dist/props/host.d.ts +1 -1
- package/dist/props/host.js.map +1 -1
- package/dist/props/slot.d.ts +1 -1
- package/dist/props/slot.js +1 -1
- package/dist/props/slot.js.map +1 -1
- package/dist/renamed-scene-names.d.ts +1 -1
- package/dist/renamed-scene-names.d.ts.map +1 -1
- package/dist/renamed-scene-names.js +1 -1
- package/dist/renamed-scene-names.js.map +1 -1
- package/dist/render/canvas-render-context2d.d.ts +9 -0
- package/dist/render/canvas-render-context2d.d.ts.map +1 -1
- package/dist/render/canvas-render-context2d.js +10 -0
- package/dist/render/canvas-render-context2d.js.map +1 -1
- package/dist/render/clip-contains.js +1 -1
- package/dist/render/clip-contains.js.map +1 -1
- package/dist/render/clip.d.ts +1 -1
- package/dist/render/clip.js +1 -1
- package/dist/render/clip.js.map +1 -1
- package/dist/render/descriptors/rect.js.map +1 -1
- package/dist/render/descriptors/text.d.ts +13 -7
- package/dist/render/descriptors/text.d.ts.map +1 -1
- package/dist/render/descriptors/text.js +9 -3
- package/dist/render/descriptors/text.js.map +1 -1
- package/dist/render/index.d.ts +2 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +1 -0
- package/dist/render/index.js.map +1 -1
- package/dist/render/render-context2d.d.ts +3 -3
- package/dist/render/render-context2d.js.map +1 -1
- package/dist/render/render-issue.d.ts +39 -0
- package/dist/render/render-issue.d.ts.map +1 -0
- package/dist/render/render-issue.js +29 -0
- package/dist/render/render-issue.js.map +1 -0
- package/dist/render/surface.d.ts +2 -2
- package/dist/render/surface.js.map +1 -1
- package/dist/render3d/builders.d.ts +1 -1
- package/dist/render3d/builders.js +1 -1
- package/dist/render3d/builders.js.map +1 -1
- package/dist/render3d/graphics3d.d.ts +13 -19
- package/dist/render3d/graphics3d.d.ts.map +1 -1
- package/dist/render3d/graphics3d.js +67 -24
- package/dist/render3d/graphics3d.js.map +1 -1
- package/dist/render3d/scene3d.d.ts +1 -1
- package/dist/render3d/scene3d.js +1 -1
- package/dist/render3d/scene3d.js.map +1 -1
- package/dist/render3d/texture.d.ts +2 -2
- package/dist/render3d/texture.d.ts.map +1 -1
- package/dist/render3d/texture.js.map +1 -1
- package/dist/render3d/vector3.d.ts +2 -2
- package/dist/render3d/vector3.js +2 -2
- package/dist/render3d/vector3.js.map +1 -1
- package/dist/runtime/asset-refine.d.ts +1 -1
- package/dist/runtime/asset-refine.d.ts.map +1 -1
- package/dist/runtime/asset-refine.js +3 -2
- package/dist/runtime/asset-refine.js.map +1 -1
- package/dist/runtime/asset-timeline.d.ts +10 -0
- package/dist/runtime/asset-timeline.d.ts.map +1 -1
- package/dist/runtime/asset-timeline.js.map +1 -1
- package/dist/runtime/asset-update.d.ts.map +1 -1
- package/dist/runtime/asset-update.js +8 -1
- package/dist/runtime/asset-update.js.map +1 -1
- package/dist/runtime/audio-index.d.ts +0 -11
- package/dist/runtime/audio-index.d.ts.map +1 -1
- package/dist/runtime/audio-index.js +0 -25
- package/dist/runtime/audio-index.js.map +1 -1
- package/dist/runtime/clip-instance.d.ts +6 -4
- package/dist/runtime/clip-instance.d.ts.map +1 -1
- package/dist/runtime/clip-instance.js +8 -4
- package/dist/runtime/clip-instance.js.map +1 -1
- package/dist/runtime/clip-store.d.ts +2 -3
- package/dist/runtime/clip-store.d.ts.map +1 -1
- package/dist/runtime/clip-store.js +34 -37
- package/dist/runtime/clip-store.js.map +1 -1
- package/dist/runtime/engine.d.ts +8 -6
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +4 -3
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/node-picking.d.ts +2 -2
- package/dist/runtime/node-picking.d.ts.map +1 -1
- package/dist/runtime/node-picking.js +3 -3
- package/dist/runtime/node-picking.js.map +1 -1
- package/dist/runtime/node-picking3d.d.ts +2 -2
- package/dist/runtime/node-picking3d.d.ts.map +1 -1
- package/dist/runtime/node-picking3d.js +1 -1
- package/dist/runtime/node-picking3d.js.map +1 -1
- package/dist/runtime/playback-controller.d.ts +2 -2
- package/dist/runtime/playback-controller.d.ts.map +1 -1
- package/dist/runtime/playback-controller.js +15 -5
- package/dist/runtime/playback-controller.js.map +1 -1
- package/dist/runtime/session.d.ts +7 -3
- package/dist/runtime/session.d.ts.map +1 -1
- package/dist/runtime/session.js +11 -4
- package/dist/runtime/session.js.map +1 -1
- package/dist/runtime/state-evaluator.d.ts +2 -2
- package/dist/runtime/state-evaluator.d.ts.map +1 -1
- package/dist/runtime/state-evaluator.js.map +1 -1
- package/dist/runtime/text-geometry.d.ts +2 -2
- package/dist/runtime/text-geometry.d.ts.map +1 -1
- package/dist/runtime/text-geometry.js +4 -5
- package/dist/runtime/text-geometry.js.map +1 -1
- package/dist/sdk/index.d.ts +50 -44
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +35 -29
- package/dist/sdk/index.js.map +1 -1
- package/dist/tween/command-decorator.d.ts +14 -9
- package/dist/tween/command-decorator.d.ts.map +1 -1
- package/dist/tween/command-decorator.js +3 -2
- package/dist/tween/command-decorator.js.map +1 -1
- package/dist/tween/command.d.ts +1 -1
- package/dist/tween/command.js.map +1 -1
- package/dist/tween/ease/describe.d.ts +2 -0
- package/dist/tween/ease/describe.d.ts.map +1 -1
- package/dist/tween/ease/describe.js +4 -0
- package/dist/tween/ease/describe.js.map +1 -1
- package/dist/tween/ease/spec.d.ts +31 -0
- package/dist/tween/ease/spec.d.ts.map +1 -0
- package/dist/tween/ease/spec.js +51 -0
- package/dist/tween/ease/spec.js.map +1 -0
- package/dist/tween/index.d.ts +3 -1
- package/dist/tween/index.d.ts.map +1 -1
- package/dist/tween/index.js +2 -1
- package/dist/tween/index.js.map +1 -1
- package/dist/tween/loop.d.ts +1 -1
- package/dist/tween/loop.js +1 -1
- package/dist/tween/loop.js.map +1 -1
- package/dist/util/reference.d.ts +6 -6
- package/dist/util/reference.js.map +1 -1
- package/package.json +3 -11
- package/dist/browser/chunks/chunk-2RIYH36X.js +0 -3
- package/dist/browser/chunks/chunk-2RIYH36X.js.map +0 -7
- package/dist/browser/chunks/chunk-DDJN3QII.js +0 -15
- package/dist/browser/chunks/chunk-DDJN3QII.js.map +0 -7
- package/dist/browser/chunks/chunk-DHB4COFY.js +0 -2
- package/dist/browser/chunks/chunk-EJDPYDQI.js +0 -5
- package/dist/browser/chunks/chunk-EJDPYDQI.js.map +0 -7
- package/dist/browser/chunks/chunk-SFNJRPBV.js +0 -2
- package/dist/browser/chunks/chunk-SFNJRPBV.js.map +0 -7
- package/dist/browser/chunks/chunk-XAWE4EAK.js +0 -2
- package/dist/browser/chunks/chunk-XAWE4EAK.js.map +0 -7
- package/dist/browser/jsx-jsx-dev-runtime.js +0 -2
- package/dist/browser/jsx-jsx-dev-runtime.js.map +0 -7
- package/dist/browser/jsx-jsx-runtime.js +0 -2
- package/dist/browser/jsx-jsx-runtime.js.map +0 -7
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { resolveAudioEffects } from "../../../attributes/audio/effects/chain.js";
|
|
2
|
+
import { sourceTimeFor } from "../../../attributes/shape/fill/implementations/video.js";
|
|
3
|
+
import { resolveFill, UNSET_MEDIA_FILL } from "../../../attributes/shape/fill/registry.js";
|
|
4
|
+
import { resolveChainAdjustments } from "../../../attributes/shape/filters/chain.js";
|
|
5
|
+
import { lerpFilterArray } from "../../../attributes/shape/filters/registry.js";
|
|
6
|
+
import { Graphics2D } from "../../../render/graphics2d.js";
|
|
7
|
+
import { component2d } from "../../../components/factory/component2d.js";
|
|
8
|
+
import { Types } from "../../../components/factory/types.js";
|
|
9
|
+
import * as Corners from "../../../components/modules/corners.js";
|
|
10
|
+
import * as Flow from "../../../components/modules/flow.js";
|
|
11
|
+
import * as Paint from "../../../components/modules/paint.js";
|
|
12
|
+
import { internalsOf } from "../../../components/factory/views.js";
|
|
13
|
+
/**
|
|
14
|
+
* Video: a rect painted with a playing picture under its fill, and the
|
|
15
|
+
* picture's sound. Its sound plays from `play`; a `video` row with no `play`
|
|
16
|
+
* of its own gets one per segment, or one over its span while it plays.
|
|
17
|
+
*/
|
|
18
|
+
const video = {
|
|
19
|
+
src: Types.custom(undefined),
|
|
20
|
+
fit: Types.custom(undefined),
|
|
21
|
+
crop: Types.insets,
|
|
22
|
+
zoom: 1,
|
|
23
|
+
anchor: Types.alignment,
|
|
24
|
+
matrix: Types.custom(undefined),
|
|
25
|
+
filters: Types.custom([], {
|
|
26
|
+
resolve: (v) => resolveChainAdjustments(v),
|
|
27
|
+
lerp: lerpFilterArray,
|
|
28
|
+
}),
|
|
29
|
+
playing: true,
|
|
30
|
+
timestamp: Types.custom(undefined),
|
|
31
|
+
trimStart: Types.custom(undefined),
|
|
32
|
+
trimEnd: Types.custom(undefined),
|
|
33
|
+
speed: Types.custom(undefined),
|
|
34
|
+
loop: Types.custom(undefined),
|
|
35
|
+
duration: Types.custom(undefined),
|
|
36
|
+
volume: 1,
|
|
37
|
+
muted: false,
|
|
38
|
+
audioEffects: Types.custom([], { resolve: (v) => resolveAudioEffects(v) }),
|
|
39
|
+
bus: Types.custom(undefined),
|
|
40
|
+
segments: Types.custom([]),
|
|
41
|
+
};
|
|
42
|
+
/** Source seconds played by `elapsed` clip seconds into the segments, or `null` without any. */
|
|
43
|
+
function playedAt(s, elapsed) {
|
|
44
|
+
if (s.segments.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
let played = 0;
|
|
47
|
+
for (const segment of s.segments) {
|
|
48
|
+
if (elapsed <= segment.at)
|
|
49
|
+
break;
|
|
50
|
+
played += Math.min(elapsed - segment.at, segment.duration) * (segment.speed ?? s.speed ?? 1);
|
|
51
|
+
}
|
|
52
|
+
return played;
|
|
53
|
+
}
|
|
54
|
+
function scheduledTimestamp(s, elapsed) {
|
|
55
|
+
const played = playedAt(s, elapsed);
|
|
56
|
+
if (played === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
const start = s.trimStart ?? 0;
|
|
59
|
+
const first = s.segments[0];
|
|
60
|
+
return sourceTimeFor(played + (first ? first.from - start : 0), start, s.trimEnd ?? Infinity, s.loop, s.duration);
|
|
61
|
+
}
|
|
62
|
+
const pictures = new WeakMap();
|
|
63
|
+
/** The frame to paint, resolved once per change of what it depends on. */
|
|
64
|
+
function pictureOf(host, s, elapsed) {
|
|
65
|
+
if (!s.src) {
|
|
66
|
+
pictures.delete(host);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const scheduled = scheduledTimestamp(s, elapsed);
|
|
70
|
+
const crop = s.crop;
|
|
71
|
+
const anchor = s.anchor;
|
|
72
|
+
const key = [
|
|
73
|
+
s.src, s.fit ?? "", s.zoom, s.playing ? 1 : 0, crop.left, crop.right, crop.top, crop.bottom, anchor.x, anchor.y,
|
|
74
|
+
s.timestamp ?? "", s.trimStart ?? "", s.trimEnd ?? "", s.speed ?? "", s.loop ?? "", s.duration ?? "", scheduled ?? "",
|
|
75
|
+
].join("|");
|
|
76
|
+
const kept = pictures.get(host);
|
|
77
|
+
if (kept && kept.key === key)
|
|
78
|
+
return kept.fill;
|
|
79
|
+
const prop = {
|
|
80
|
+
type: "video", src: s.src, fit: s.fit, crop: s.crop, zoom: s.zoom, anchor: s.anchor, matrix: s.matrix,
|
|
81
|
+
filters: s.filters, playing: s.playing, timestamp: s.timestamp ?? scheduled,
|
|
82
|
+
trimStart: s.trimStart, trimEnd: s.trimEnd, speed: s.speed, loop: s.loop, duration: s.duration,
|
|
83
|
+
};
|
|
84
|
+
const fill = resolveFill(prop);
|
|
85
|
+
pictures.set(host, { key, fill });
|
|
86
|
+
return fill;
|
|
87
|
+
}
|
|
88
|
+
export const Video = component2d({
|
|
89
|
+
key: "video",
|
|
90
|
+
state: { ...Paint.state, ...Flow.state, ...Corners.state, ...video },
|
|
91
|
+
commands: {
|
|
92
|
+
...Paint.commands,
|
|
93
|
+
/** Its sound: from `from` in the source for a segment, or as it plays. Cut when the command ends. */
|
|
94
|
+
play: {
|
|
95
|
+
args: {
|
|
96
|
+
from: Types.custom(undefined),
|
|
97
|
+
volume: Types.custom(undefined),
|
|
98
|
+
speed: Types.custom(undefined),
|
|
99
|
+
},
|
|
100
|
+
run: (timeline, state) => {
|
|
101
|
+
const s = state;
|
|
102
|
+
const segment = timeline.args.from !== undefined;
|
|
103
|
+
if (!s.src || s.muted || (!segment && !s.playing))
|
|
104
|
+
return timeline.together([]);
|
|
105
|
+
const speed = timeline.args.speed ?? s.speed ?? 1;
|
|
106
|
+
const loop = !segment && (s.loop ?? "none") !== "none";
|
|
107
|
+
return timeline.sound(s.src, {
|
|
108
|
+
volume: timeline.args.volume ?? s.volume,
|
|
109
|
+
loop,
|
|
110
|
+
trimStart: segment ? timeline.args.from : s.trimStart,
|
|
111
|
+
trimEnd: s.trimEnd,
|
|
112
|
+
speed,
|
|
113
|
+
effects: s.audioEffects,
|
|
114
|
+
bus: s.bus,
|
|
115
|
+
optional: true,
|
|
116
|
+
closed: !loop,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
load: (loader, state) => {
|
|
122
|
+
if (!state.src)
|
|
123
|
+
return;
|
|
124
|
+
loader.fill(resolveFill({
|
|
125
|
+
type: "video", src: state.src, filters: state.filters, trimStart: state.trimStart, trimEnd: state.trimEnd,
|
|
126
|
+
}));
|
|
127
|
+
},
|
|
128
|
+
measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
|
|
129
|
+
layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
|
|
130
|
+
render: (ctx, state) => {
|
|
131
|
+
const s = state;
|
|
132
|
+
const picture = pictureOf(internalsOf(ctx).host, s, ctx.time.elapsed);
|
|
133
|
+
const outline = { width: ctx.size.width, height: ctx.size.height, cornerRadius: s.cornerRadius, cornerStyle: s.cornerStyle, start: s.start, end: s.end };
|
|
134
|
+
Paint.draw(ctx, state, Corners.rect(ctx.size, state), {
|
|
135
|
+
fill: [(picture ?? UNSET_MEDIA_FILL), ...state.fill],
|
|
136
|
+
// The overlay lies on the picture only, masked by it.
|
|
137
|
+
overlay: () => (picture
|
|
138
|
+
? new Graphics2D().mask().rect(outline).fill([picture]).applyMask().rect(outline).fill(state.overlay).endMask()
|
|
139
|
+
: null),
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../../../src/components/builtins/media/media.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,kCAAkC,CAAC;AAG/F,OAAO,EAAE,aAAa,EAA8C,MAAM,+CAA+C,CAAC;AAC1H,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEjF,OAAO,EAAE,uBAAuB,EAAwB,MAAM,kCAAkC,CAAC;AACjG,OAAO,EAAE,eAAe,EAAkB,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,8BAA8B,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,2BAA2B,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AA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AAI,CAAC;SACd,CAAC,CAAC;IACP,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import type { Alignment } from \"@/attributes/layout/alignment\";\r\nimport type { InsetsResolved } from \"@/attributes/layout/insets\";\r\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\r\nimport { resolveAudioEffects, type AudioEffectsInput } from \"@/attributes/audio/effects/chain\";\r\nimport type { AudioEffect } from \"@/attributes/audio/effects/union\";\r\nimport type { ImageFit, ImageMatrix, ImageCrop } from \"@/attributes/shape/fill/implementations/image\";\r\nimport { sourceTimeFor, type VideoFillProp, type VideoFillResolved } from \"@/attributes/shape/fill/implementations/video\";\r\nimport { resolveFill, UNSET_MEDIA_FILL } from \"@/attributes/shape/fill/registry\";\r\nimport type { FillProp } from \"@/attributes/shape/fill/union\";\r\nimport { resolveChainAdjustments, type VideoAdjustment } from \"@/attributes/shape/filters/chain\";\r\nimport { lerpFilterArray, type AnyFilter } from \"@/attributes/shape/filters/registry\";\r\nimport { Graphics2D } from \"@/render/graphics2d\";\r\nimport type { NodeOf, Values } from \"@/components/factory/api\";\r\nimport { component2d } from \"@/components/factory/component2d\";\r\nimport { Types } from \"@/components/factory/types\";\r\nimport * as Corners from \"@/components/modules/corners\";\r\nimport * as Flow from \"@/components/modules/flow\";\r\nimport * as Paint from \"@/components/modules/paint\";\r\nimport { internalsOf } from \"@/components/factory/views\";\r\nimport type { RectProps } from \"@/components/builtins/geometry/geometry\";\r\n\r\n/**\r\n * Video: a rect painted with a playing picture under its fill, and the\r\n * picture's sound. Its sound plays from `play`; a `video` row with no `play`\r\n * of its own gets one per segment, or one over its span while it plays.\r\n */\r\n\r\nconst video = {\r\n src: Types.custom<string | undefined>(undefined),\r\n fit: Types.custom<ImageFit | undefined>(undefined),\r\n crop: Types.insets,\r\n zoom: 1,\r\n anchor: Types.alignment,\r\n matrix: Types.custom<ImageMatrix | undefined>(undefined),\r\n filters: Types.custom<VideoAdjustment, AnyFilter[]>([] as never, {\r\n resolve: (v) => resolveChainAdjustments(v),\r\n lerp: lerpFilterArray,\r\n }),\r\n playing: true,\r\n timestamp: Types.custom<number | null | undefined>(undefined),\r\n trimStart: Types.custom<number | undefined>(undefined),\r\n trimEnd: Types.custom<number | undefined>(undefined),\r\n speed: Types.custom<number | undefined>(undefined),\r\n loop: Types.custom<\"forward\" | \"reverse\" | \"none\" | undefined>(undefined),\r\n duration: Types.custom<number | undefined>(undefined),\r\n volume: 1,\r\n muted: false,\r\n audioEffects: Types.custom<AudioEffectsInput, AudioEffect[]>([] as never, { resolve: (v) => resolveAudioEffects(v) }),\r\n bus: Types.custom<string | undefined>(undefined),\r\n segments: Types.custom<readonly VideoSegment[]>([]),\r\n};\r\n\r\ntype VideoState = Values<typeof video> & { readonly crop: InsetsResolved; readonly anchor: Alignment };\r\n\r\n/** Source seconds played by `elapsed` clip seconds into the segments, or `null` without any. */\r\nfunction playedAt(s: VideoState, elapsed: number): number | null {\r\n if (s.segments.length === 0) return null;\r\n let played = 0;\r\n for (const segment of s.segments) {\r\n if (elapsed <= segment.at) break;\r\n played += Math.min(elapsed - segment.at, segment.duration) * (segment.speed ?? s.speed ?? 1);\r\n }\r\n return played;\r\n}\r\n\r\nfunction scheduledTimestamp(s: VideoState, elapsed: number): number | undefined {\r\n const played = playedAt(s, elapsed);\r\n if (played === null) return undefined;\r\n const start = s.trimStart ?? 0;\r\n const first = s.segments[0];\r\n return sourceTimeFor(played + (first ? first.from - start : 0), start, s.trimEnd ?? Infinity, s.loop, s.duration);\r\n}\r\n\r\nconst pictures = new WeakMap<object, { readonly key: string; readonly fill: VideoFillResolved }>();\r\n\r\n/** The frame to paint, resolved once per change of what it depends on. */\r\nfunction pictureOf(host: object, s: VideoState, elapsed: number): VideoFillResolved | null {\r\n if (!s.src) {\r\n pictures.delete(host);\r\n return null;\r\n }\r\n const scheduled = scheduledTimestamp(s, elapsed);\r\n const crop = s.crop;\r\n const anchor = s.anchor as unknown as Vector2;\r\n const key = [\r\n s.src, s.fit ?? \"\", s.zoom, s.playing ? 1 : 0, crop.left, crop.right, crop.top, crop.bottom, anchor.x, anchor.y,\r\n s.timestamp ?? \"\", s.trimStart ?? \"\", s.trimEnd ?? \"\", s.speed ?? \"\", s.loop ?? \"\", s.duration ?? \"\", scheduled ?? \"\",\r\n ].join(\"|\");\r\n const kept = pictures.get(host);\r\n if (kept && kept.key === key) return kept.fill;\r\n const prop: VideoFillProp = {\r\n type: \"video\", src: s.src, fit: s.fit, crop: s.crop, zoom: s.zoom, anchor: s.anchor, matrix: s.matrix,\r\n filters: s.filters as never, playing: s.playing, timestamp: s.timestamp ?? scheduled,\r\n trimStart: s.trimStart, trimEnd: s.trimEnd, speed: s.speed, loop: s.loop, duration: s.duration,\r\n };\r\n const fill = resolveFill(prop as FillProp) as VideoFillResolved;\r\n pictures.set(host, { key, fill });\r\n return fill;\r\n}\r\n\r\nexport const Video = component2d({\r\n key: \"video\",\r\n state: { ...Paint.state, ...Flow.state, ...Corners.state, ...video },\r\n commands: {\r\n ...Paint.commands,\r\n /** Its sound: from `from` in the source for a segment, or as it plays. Cut when the command ends. */\r\n play: {\r\n args: {\r\n from: Types.custom<number | undefined>(undefined),\r\n volume: Types.custom<number | undefined>(undefined),\r\n speed: Types.custom<number | undefined>(undefined),\r\n },\r\n run: (timeline, state) => {\r\n const s = state as unknown as VideoState;\r\n const segment = timeline.args.from !== undefined;\r\n if (!s.src || s.muted || (!segment && !s.playing)) return timeline.together([]);\r\n const speed = timeline.args.speed ?? s.speed ?? 1;\r\n const loop = !segment && (s.loop ?? \"none\") !== \"none\";\r\n return timeline.sound(s.src, {\r\n volume: timeline.args.volume ?? s.volume,\r\n loop,\r\n trimStart: segment ? timeline.args.from : s.trimStart,\r\n trimEnd: s.trimEnd,\r\n speed,\r\n effects: s.audioEffects,\r\n bus: s.bus,\r\n optional: true,\r\n closed: !loop,\r\n });\r\n },\r\n },\r\n },\r\n load: (loader, state) => {\r\n if (!state.src) return;\r\n loader.fill(resolveFill({\r\n type: \"video\", src: state.src, filters: state.filters, trimStart: state.trimStart, trimEnd: state.trimEnd,\r\n } as unknown as FillProp));\r\n },\r\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\r\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\r\n render: (ctx, state) => {\r\n const s = state as unknown as VideoState & Values<typeof Paint.state> & Values<typeof Corners.state>;\r\n const picture = pictureOf(internalsOf(ctx).host, s, ctx.time.elapsed);\r\n const outline = { width: ctx.size.width, height: ctx.size.height, cornerRadius: s.cornerRadius, cornerStyle: s.cornerStyle, start: s.start, end: s.end };\r\n Paint.draw(ctx, state, Corners.rect(ctx.size, state), {\r\n fill: [(picture ?? UNSET_MEDIA_FILL), ...state.fill] as never,\r\n // The overlay lies on the picture only, masked by it.\r\n overlay: () => (picture\r\n ? new Graphics2D().mask().rect(outline).fill([picture] as never).applyMask().rect(outline).fill(state.overlay).endMask()\r\n : null),\r\n });\r\n },\r\n});\r\n\r\nexport type Video = NodeOf<typeof Video>;\r\n\r\n// What code building a video names its props as, and the segments it plays.\r\n\r\nexport interface VideoProps extends RectProps {\r\n src?: string;\r\n /** How the (cropped) frame is scaled into the node's bounds. Default 'fill'. */\r\n fit?: ImageFit;\r\n /** Window onto the source frame, in fractions of its own size, applied before `fit`. */\r\n crop?: ImageCrop;\r\n /** Magnification on top of the fitted scale. `1` (default) is the fitted size. */\r\n zoom?: number;\r\n /** The point held fixed as `zoom` scales; also the alignment when it doesn't cover. */\r\n anchor?: Alignment;\r\n /** Raw frame→shape matrix; bypasses `crop`/`fit`/`zoom`/`anchor` and the bounds. */\r\n matrix?: ImageMatrix;\r\n /** Visual filters applied to the rendered frame (blur, color, posterizeTime, echo, …). */\r\n filters?: VideoAdjustment;\r\n /** Whether playback advances with the node's clock (drives both picture and sound). Default true. */\r\n playing?: boolean;\r\n /**\r\n * Explicit source time to show, in seconds. Omit it (the default) and the\r\n * picture is timed from the moment this node appeared; set it to drive the\r\n * playhead yourself, and set it to `null` to hand the playhead back to the\r\n * clock (`set()` merges a partial, so `undefined` won't clear it).\r\n */\r\n timestamp?: number | null;\r\n trimStart?: number;\r\n trimEnd?: number;\r\n /** Playback-rate multiplier for both picture and audio. Default 1. */\r\n speed?: number;\r\n loop?: 'forward' | 'reverse' | 'none';\r\n /** Length of one loop cycle, in seconds. Defaults to the trimmed clip length. */\r\n duration?: number;\r\n /** Audio volume in [0, 1]. Default 1. */\r\n volume?: number;\r\n /** Silence the video's audio track without affecting the picture. Default false. */\r\n muted?: boolean;\r\n /** Audio effects applied to the video's sound track (gain, eq, echo, …). */\r\n audioEffects?: AudioEffectsInput;\r\n /**\r\n * The node id of an `AudioBus` in this clip to route the video's sound into.\r\n *\r\n * A `Video` is a `Node2D`, so it cannot be parented under a bus the way a\r\n * `SoundNode` is — its audio is welded to its picture, which has to stay in\r\n * the visual tree. Naming one instead is what lets a video's dialogue sit on\r\n * the same bus as everything else, so ducking the whole group is still one\r\n * edit — and it is the *same* id a `SoundNode` under that bus writes as its\r\n * `parentId`, rather than a second vocabulary for \"which bus\". An id matching\r\n * no bus routes straight to the master, the same as no bus at all.\r\n */\r\n bus?: string;\r\n /**\r\n * An explicit **playback schedule**: the stretches of this node's own clock\r\n * during which the clip advances, and where in the source each one starts.\r\n *\r\n * Omit it (the default) and playback is what it has always been — the clip\r\n * runs from the moment the node appears, at `speed`, until it or the node\r\n * runs out. Give it, and `playing`/`timestamp` are both superseded: the\r\n * picture takes its source time from whichever segment covers the current\r\n * `elapsed`, and the sound is scheduled one clip per segment.\r\n *\r\n * It exists because a **pause** cannot be expressed any other way. `playing:\r\n * false` holds the clip's *first* frame, because with playback derived\r\n * linearly from the clock there is nothing else it could hold; and the sound\r\n * runs on the node's own clock regardless, so a picture frozen by any means\r\n * would drift away from it. A schedule states the one thing both halves need\r\n * and neither could infer — that a paused stretch consumes no source — so\r\n * they cannot come apart.\r\n *\r\n * Still a pure function of the clock, which is the property everything else\r\n * here is built on: frame *N* is identical however the playhead reached it,\r\n * so a scrub, a playthrough and an export agree.\r\n */\r\n segments?: readonly VideoSegment[];\r\n\r\n}\r\n\r\n/**\r\n * One stretch of a {@link Video}'s own clock during which its source advances —\r\n * see {@link VideoProps.segments}.\r\n *\r\n * Trim and loop are applied *on top* of this, by the same code that applies them\r\n * to unscheduled playback, so a schedule says when the clip is running and the\r\n * clip's own props go on saying which part of the file it is running through.\r\n */\r\nexport interface VideoSegment {\r\n /** Second on the node's own clock (`NodeTime.elapsed`) this segment begins. */\r\n at: number;\r\n /** Source in-point for it, in seconds. */\r\n from: number;\r\n /**\r\n * How long it runs, in seconds of the node's clock.\r\n *\r\n * `Infinity` for a clip left running — the same open sentinel\r\n * `AudioRequest.endAt` uses — which resolves against the clip's length.\r\n */\r\n duration: number;\r\n /** Playback rate through it. Defaults to the node's own `speed`. */\r\n speed?: number;\r\n /** Linear gain for its sound. Defaults to the node's own `volume`. */\r\n volume?: number;\r\n}\r\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Context } from "../../../util/context.js";
|
|
2
|
+
import { type NodeOf } from "../../../components/factory/api.js";
|
|
3
|
+
import type { Node2DProps } from "../../../components/trees/2d/node2d.js";
|
|
4
|
+
/** Hands its subtree `value` under `context`, or the context's default when it has no value. */
|
|
5
|
+
export declare const Provider: import("../../../components/factory/api.js").Component<"provider", import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
6
|
+
readonly context: import("../../../components/factory/api.js").Type<Context<unknown> | undefined, Context<unknown> | undefined, false>;
|
|
7
|
+
readonly value: import("../../../components/factory/api.js").Type<unknown, unknown, false>;
|
|
8
|
+
}>, {}, null, import("../../../components/trees/2d/node2d.js").Node2D<Node2DProps>, import("../../../components/factory/api.js").CallProps<import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
9
|
+
readonly context: import("../../../components/factory/api.js").Type<Context<unknown> | undefined, Context<unknown> | undefined, false>;
|
|
10
|
+
readonly value: import("../../../components/factory/api.js").Type<unknown, unknown, false>;
|
|
11
|
+
}>, null, import("../../../components/factory/api.js").BuiltNode<import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
12
|
+
readonly context: import("../../../components/factory/api.js").Type<Context<unknown> | undefined, Context<unknown> | undefined, false>;
|
|
13
|
+
readonly value: import("../../../components/factory/api.js").Type<unknown, unknown, false>;
|
|
14
|
+
}>, {}, import("../../../components/trees/2d/node2d.js").Node2D<Node2DProps>>>>;
|
|
15
|
+
/** Lays its theme and data over what it inherits, and seeds the randomness below it. */
|
|
16
|
+
export declare const ThemeProvider: import("../../../components/factory/api.js").Component<"theme-provider", import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
17
|
+
readonly theme: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
18
|
+
readonly data: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
19
|
+
readonly seed: import("../../../components/factory/api.js").Type<string | number | undefined, string | number | undefined, false>;
|
|
20
|
+
}>, {}, null, import("../../../components/trees/2d/node2d.js").Node2D<Node2DProps>, import("../../../components/factory/api.js").CallProps<import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
21
|
+
readonly theme: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
22
|
+
readonly data: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
23
|
+
readonly seed: import("../../../components/factory/api.js").Type<string | number | undefined, string | number | undefined, false>;
|
|
24
|
+
}>, null, import("../../../components/factory/api.js").BuiltNode<import("../../../components/factory/api.js").Merge<import("../../../components/factory/api.js").Box2DState, {
|
|
25
|
+
readonly theme: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
26
|
+
readonly data: import("../../../components/factory/api.js").Type<Record<string, unknown> | undefined, Record<string, unknown> | undefined, false>;
|
|
27
|
+
readonly seed: import("../../../components/factory/api.js").Type<string | number | undefined, string | number | undefined, false>;
|
|
28
|
+
}>, {}, import("../../../components/trees/2d/node2d.js").Node2D<Node2DProps>>>>;
|
|
29
|
+
export type Provider = NodeOf<typeof Provider>;
|
|
30
|
+
export type ThemeProvider = NodeOf<typeof ThemeProvider>;
|
|
31
|
+
export interface ProviderProps<T> extends Node2DProps {
|
|
32
|
+
/** The context token this provider supplies to its descendants. */
|
|
33
|
+
context: Context<T>;
|
|
34
|
+
/** The value to provide. Omitted → the token's default value. */
|
|
35
|
+
value: T;
|
|
36
|
+
}
|
|
37
|
+
export interface ThemeProviderProps extends Node2DProps {
|
|
38
|
+
/** Named values (e.g. colors) merged onto any ancestor theme, read via
|
|
39
|
+
* `node.useContext(ThemeToken)`. */
|
|
40
|
+
theme: Record<string, unknown>;
|
|
41
|
+
/** Arbitrary data merged onto any ancestor data bag, read via
|
|
42
|
+
* `node.useContext(DataToken)`. */
|
|
43
|
+
data: Record<string, unknown>;
|
|
44
|
+
/** A default seed passed down the tree, read via `node.useContext(SeedToken)`. */
|
|
45
|
+
seed: string | number;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../../src/components/builtins/providers/providers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAY,KAAK,MAAM,EAAiB,MAAM,0BAA0B,CAAC;AAGhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,gGAAgG;AAChG,eAAO,MAAM,QAAQ;;;;;;;;;qEAInB,CAAC;AAEH,wFAAwF;AACxF,eAAO,MAAM,aAAa;;;;;;;;;;;;qEAcxB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAIzD,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,WAAW;IACjD,mEAAmE;IACnE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,iEAAiE;IACjE,KAAK,EAAE,CAAC,CAAC;CACZ;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACnD;wCACoC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B;uCACmC;IACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,kFAAkF;IAClF,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DataToken, SeedToken, ThemeToken } from "../../../runtime/builtin-context.js";
|
|
2
|
+
import { provides } from "../../../components/factory/api.js";
|
|
3
|
+
import { component2d } from "../../../components/factory/component2d.js";
|
|
4
|
+
import { Types } from "../../../components/factory/types.js";
|
|
5
|
+
/** Hands its subtree `value` under `context`, or the context's default when it has no value. */
|
|
6
|
+
export const Provider = component2d({
|
|
7
|
+
key: "provider",
|
|
8
|
+
state: { context: Types.custom(undefined), value: Types.custom(undefined) },
|
|
9
|
+
provide: (state) => (state.context ? [provides(state.context, state.value !== undefined ? state.value : state.context.defaultValue)] : []),
|
|
10
|
+
});
|
|
11
|
+
/** Lays its theme and data over what it inherits, and seeds the randomness below it. */
|
|
12
|
+
export const ThemeProvider = component2d({
|
|
13
|
+
key: "theme-provider",
|
|
14
|
+
state: {
|
|
15
|
+
theme: Types.custom(undefined),
|
|
16
|
+
data: Types.custom(undefined),
|
|
17
|
+
seed: Types.custom(undefined),
|
|
18
|
+
},
|
|
19
|
+
provide: (state, inherited) => {
|
|
20
|
+
const out = [];
|
|
21
|
+
if (state.theme)
|
|
22
|
+
out.push(provides(ThemeToken, { ...inherited(ThemeToken), ...state.theme }));
|
|
23
|
+
if (state.data)
|
|
24
|
+
out.push(provides(DataToken, { ...inherited(DataToken), ...state.data }));
|
|
25
|
+
if (state.seed !== undefined)
|
|
26
|
+
out.push(provides(SeedToken, state.seed));
|
|
27
|
+
return out;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../../src/components/builtins/providers/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAA8B,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,gGAAgG;AAChG,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;IAChC,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAA+B,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAU,SAAS,CAAC,EAAE;IAClH,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;CAC7I,CAAC,CAAC;AAEH,wFAAwF;AACxF,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;IACrC,GAAG,EAAE,gBAAgB;IACrB,KAAK,EAAE;QACH,KAAK,EAAE,KAAK,CAAC,MAAM,CAAsC,SAAS,CAAC;QACnE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAsC,SAAS,CAAC;QAClE,IAAI,EAAE,KAAK,CAAC,MAAM,CAA8B,SAAS,CAAC;KAC7D;IACD,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QAC1B,MAAM,GAAG,GAAe,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,KAAK;YAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9F,IAAI,KAAK,CAAC,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC1F,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACxE,OAAO,GAAG,CAAC;IACf,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import { DataToken, SeedToken, ThemeToken } from \"@/runtime/builtin-context\";\r\nimport type { Context } from \"@/util/context\";\r\nimport { provides, type NodeOf, type Provided } from \"@/components/factory/api\";\r\nimport { component2d } from \"@/components/factory/component2d\";\r\nimport { Types } from \"@/components/factory/types\";\r\nimport type { Node2DProps } from \"@/components/trees/2d/node2d\";\r\n\r\n/** Hands its subtree `value` under `context`, or the context's default when it has no value. */\r\nexport const Provider = component2d({\r\n key: \"provider\",\r\n state: { context: Types.custom<Context<unknown> | undefined>(undefined), value: Types.custom<unknown>(undefined) },\r\n provide: (state) => (state.context ? [provides(state.context, state.value !== undefined ? state.value : state.context.defaultValue)] : []),\r\n});\r\n\r\n/** Lays its theme and data over what it inherits, and seeds the randomness below it. */\r\nexport const ThemeProvider = component2d({\r\n key: \"theme-provider\",\r\n state: {\r\n theme: Types.custom<Record<string, unknown> | undefined>(undefined),\r\n data: Types.custom<Record<string, unknown> | undefined>(undefined),\r\n seed: Types.custom<string | number | undefined>(undefined),\r\n },\r\n provide: (state, inherited) => {\r\n const out: Provided[] = [];\r\n if (state.theme) out.push(provides(ThemeToken, { ...inherited(ThemeToken), ...state.theme }));\r\n if (state.data) out.push(provides(DataToken, { ...inherited(DataToken), ...state.data }));\r\n if (state.seed !== undefined) out.push(provides(SeedToken, state.seed));\r\n return out;\r\n },\r\n});\r\n\r\nexport type Provider = NodeOf<typeof Provider>;\r\nexport type ThemeProvider = NodeOf<typeof ThemeProvider>;\r\n\r\n// What code building a provider names its props as.\r\n\r\nexport interface ProviderProps<T> extends Node2DProps {\r\n /** The context token this provider supplies to its descendants. */\r\n context: Context<T>;\r\n /** The value to provide. Omitted → the token's default value. */\r\n value: T;\r\n}\r\n\r\nexport interface ThemeProviderProps extends Node2DProps {\r\n /** Named values (e.g. colors) merged onto any ancestor theme, read via\r\n * `node.useContext(ThemeToken)`. */\r\n theme: Record<string, unknown>;\r\n /** Arbitrary data merged onto any ancestor data bag, read via\r\n * `node.useContext(DataToken)`. */\r\n data: Record<string, unknown>;\r\n /** A default seed passed down the tree, read via `node.useContext(SeedToken)`. */\r\n seed: string | number;\r\n}\r\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a chart writes a number down.
|
|
3
|
+
*
|
|
4
|
+
* One formatter, driven by a **pattern**, and the named formats are patterns
|
|
5
|
+
* too — `currency` is `$#,##0.00` and nothing more. That is the whole design:
|
|
6
|
+
* a dropdown of four presets and a free-text pattern are otherwise two features
|
|
7
|
+
* that drift, one of them gaining a thousands separator or a negative sign the
|
|
8
|
+
* other never hears about. Here the preset *is* the custom case with the
|
|
9
|
+
* pattern filled in, so there is one set of rules to get right.
|
|
10
|
+
*
|
|
11
|
+
* The grammar is the spreadsheet one, because that is where the numbers come
|
|
12
|
+
* from and what an author already knows:
|
|
13
|
+
*
|
|
14
|
+
* | Pattern | 1234.5 | 0.07 |
|
|
15
|
+
* | ------------ | --------- | ------ |
|
|
16
|
+
* | `#,##0.##` | `1,234.5` | `0.07` |
|
|
17
|
+
* | `0` | `1235` | `0` |
|
|
18
|
+
* | `$#,##0.00` | `$1,234.50` | `$0.07` |
|
|
19
|
+
* | `0.#%` | `123450%` | `7%` |
|
|
20
|
+
* | `#,##0 kg` | `1,235 kg` | `0 kg` |
|
|
21
|
+
*
|
|
22
|
+
* - `0` is a digit that is always written, `#` one that is written only when
|
|
23
|
+
* the number needs it. So `0.00` pads to two decimals and `0.##` trims.
|
|
24
|
+
* - A `,` anywhere in the integer run turns grouping on; where it sits doesn't
|
|
25
|
+
* matter, since `#,##0` and `#,###,##0` mean the same thing to everyone who
|
|
26
|
+
* writes them.
|
|
27
|
+
* - `%` scales by 100 as well as printing — that is what makes it a percent
|
|
28
|
+
* rather than a suffix, and it is why `0.07` under `0.#%` is `7%`. A column
|
|
29
|
+
* that is *already* in percent points wants `#,##0'%'`: quoted, so the sign
|
|
30
|
+
* is printed and nothing is scaled.
|
|
31
|
+
* - Anything else is literal, before the digits or after them. Quote it to be
|
|
32
|
+
* sure — `'#'#,##0` prints a leading hash.
|
|
33
|
+
*
|
|
34
|
+
* Deliberately **not** `Intl.NumberFormat`. Its output is locale-dependent, and
|
|
35
|
+
* a chart is a picture with a fixed layout: the same project rendering
|
|
36
|
+
* `1,234.50` on the author's machine and `1.234,50` on the export box is a
|
|
37
|
+
* silently different image, and the wider string can reflow an axis. What an
|
|
38
|
+
* author wants here is the format they *typed*.
|
|
39
|
+
*/
|
|
40
|
+
/** The named formats the inspector offers, plus the escape hatch. */
|
|
41
|
+
export type NumberFormatName = "plain" | "number" | "currency" | "percent" | "custom";
|
|
42
|
+
/**
|
|
43
|
+
* The pattern behind each named format.
|
|
44
|
+
*
|
|
45
|
+
* `plain` is the historic behaviour — integers bare, everything else to one
|
|
46
|
+
* decimal — kept as the default so no existing chart re-labels itself. The rest
|
|
47
|
+
* are the three formats a chart of money, counts or shares actually needs.
|
|
48
|
+
*/
|
|
49
|
+
export declare const NUMBER_PATTERNS: Record<Exclude<NumberFormatName, "custom">, string>;
|
|
50
|
+
/**
|
|
51
|
+
* `value` written the way `pattern` says.
|
|
52
|
+
*
|
|
53
|
+
* A non-finite value prints empty rather than `NaN`: a tick with no number
|
|
54
|
+
* behind it is a tick that shouldn't caption itself, and `NaN` on an axis reads
|
|
55
|
+
* as a broken chart rather than as missing data.
|
|
56
|
+
*/
|
|
57
|
+
export declare function formatNumber(value: number, pattern: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* The pattern a `(format, custom)` pair names.
|
|
60
|
+
*
|
|
61
|
+
* A blank custom pattern falls back to the plain one rather than to the empty
|
|
62
|
+
* string, so an axis switched to Custom is readable while it is being typed
|
|
63
|
+
* into rather than a column of nothing.
|
|
64
|
+
*/
|
|
65
|
+
export declare function patternFor(format: NumberFormatName | undefined, custom: string | undefined): string;
|
|
66
|
+
//# sourceMappingURL=number-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-format.d.ts","sourceRoot":"","sources":["../../../../src/components/builtins/text/number-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAA;AAErF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,CAQ/E,CAAA;AA6JD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAqBnE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,gBAAgB,GAAG,SAAS,EACpC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,CAMR"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a chart writes a number down.
|
|
3
|
+
*
|
|
4
|
+
* One formatter, driven by a **pattern**, and the named formats are patterns
|
|
5
|
+
* too — `currency` is `$#,##0.00` and nothing more. That is the whole design:
|
|
6
|
+
* a dropdown of four presets and a free-text pattern are otherwise two features
|
|
7
|
+
* that drift, one of them gaining a thousands separator or a negative sign the
|
|
8
|
+
* other never hears about. Here the preset *is* the custom case with the
|
|
9
|
+
* pattern filled in, so there is one set of rules to get right.
|
|
10
|
+
*
|
|
11
|
+
* The grammar is the spreadsheet one, because that is where the numbers come
|
|
12
|
+
* from and what an author already knows:
|
|
13
|
+
*
|
|
14
|
+
* | Pattern | 1234.5 | 0.07 |
|
|
15
|
+
* | ------------ | --------- | ------ |
|
|
16
|
+
* | `#,##0.##` | `1,234.5` | `0.07` |
|
|
17
|
+
* | `0` | `1235` | `0` |
|
|
18
|
+
* | `$#,##0.00` | `$1,234.50` | `$0.07` |
|
|
19
|
+
* | `0.#%` | `123450%` | `7%` |
|
|
20
|
+
* | `#,##0 kg` | `1,235 kg` | `0 kg` |
|
|
21
|
+
*
|
|
22
|
+
* - `0` is a digit that is always written, `#` one that is written only when
|
|
23
|
+
* the number needs it. So `0.00` pads to two decimals and `0.##` trims.
|
|
24
|
+
* - A `,` anywhere in the integer run turns grouping on; where it sits doesn't
|
|
25
|
+
* matter, since `#,##0` and `#,###,##0` mean the same thing to everyone who
|
|
26
|
+
* writes them.
|
|
27
|
+
* - `%` scales by 100 as well as printing — that is what makes it a percent
|
|
28
|
+
* rather than a suffix, and it is why `0.07` under `0.#%` is `7%`. A column
|
|
29
|
+
* that is *already* in percent points wants `#,##0'%'`: quoted, so the sign
|
|
30
|
+
* is printed and nothing is scaled.
|
|
31
|
+
* - Anything else is literal, before the digits or after them. Quote it to be
|
|
32
|
+
* sure — `'#'#,##0` prints a leading hash.
|
|
33
|
+
*
|
|
34
|
+
* Deliberately **not** `Intl.NumberFormat`. Its output is locale-dependent, and
|
|
35
|
+
* a chart is a picture with a fixed layout: the same project rendering
|
|
36
|
+
* `1,234.50` on the author's machine and `1.234,50` on the export box is a
|
|
37
|
+
* silently different image, and the wider string can reflow an axis. What an
|
|
38
|
+
* author wants here is the format they *typed*.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* The pattern behind each named format.
|
|
42
|
+
*
|
|
43
|
+
* `plain` is the historic behaviour — integers bare, everything else to one
|
|
44
|
+
* decimal — kept as the default so no existing chart re-labels itself. The rest
|
|
45
|
+
* are the three formats a chart of money, counts or shares actually needs.
|
|
46
|
+
*/
|
|
47
|
+
export const NUMBER_PATTERNS = {
|
|
48
|
+
// Ungrouped on purpose: this is what `formatMarker` did before there were
|
|
49
|
+
// formats at all, and it is the default, so every chart already drawn keeps
|
|
50
|
+
// the labels it has. Grouping is what the reader picks `number` for.
|
|
51
|
+
plain: "#.#",
|
|
52
|
+
number: "#,##0.##",
|
|
53
|
+
currency: "$#,##0.00",
|
|
54
|
+
percent: "#,##0.#%",
|
|
55
|
+
};
|
|
56
|
+
/** What a pattern with no digits in it falls back to: the `plain` reading. */
|
|
57
|
+
const DEFAULT_PARSED = {
|
|
58
|
+
prefix: "",
|
|
59
|
+
suffix: "",
|
|
60
|
+
grouped: false,
|
|
61
|
+
minInt: 1,
|
|
62
|
+
minFrac: 0,
|
|
63
|
+
maxFrac: 1,
|
|
64
|
+
percent: false,
|
|
65
|
+
};
|
|
66
|
+
/** Walk `text`, calling `visit` with each character and whether it is quoted. */
|
|
67
|
+
function scan(text, visit) {
|
|
68
|
+
let quoted = false;
|
|
69
|
+
for (const ch of text) {
|
|
70
|
+
if (ch === "'") {
|
|
71
|
+
quoted = !quoted;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
visit(ch, quoted);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Does `text` hold `ch` outside quotes? */
|
|
78
|
+
function hasBare(text, ch) {
|
|
79
|
+
let found = false;
|
|
80
|
+
scan(text, (c, quoted) => {
|
|
81
|
+
if (c === ch && !quoted)
|
|
82
|
+
found = true;
|
|
83
|
+
});
|
|
84
|
+
return found;
|
|
85
|
+
}
|
|
86
|
+
/** `text` with every unquoted `ch` dropped, quoting preserved. */
|
|
87
|
+
function removeBare(text, ch) {
|
|
88
|
+
let out = "";
|
|
89
|
+
let quoted = false;
|
|
90
|
+
for (const c of text) {
|
|
91
|
+
if (c === "'") {
|
|
92
|
+
quoted = !quoted;
|
|
93
|
+
out += c;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (c === ch && !quoted)
|
|
97
|
+
continue;
|
|
98
|
+
out += c;
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** `text` with its quotes taken off — what actually gets printed. */
|
|
103
|
+
function literal(text) {
|
|
104
|
+
let out = "";
|
|
105
|
+
scan(text, (ch) => {
|
|
106
|
+
out += ch;
|
|
107
|
+
});
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The `[start, end)` of the pattern's digit run — the first stretch of `#0,.`
|
|
112
|
+
* outside quotes.
|
|
113
|
+
*
|
|
114
|
+
* Quote-aware, so `'#'#,##0` reads its leading hash as text and its run as the
|
|
115
|
+
* three characters after it. Without that, a quoted `#` would be taken for the
|
|
116
|
+
* number and the real digits for a suffix.
|
|
117
|
+
*/
|
|
118
|
+
function digitRun(pattern) {
|
|
119
|
+
let quoted = false;
|
|
120
|
+
let start = -1;
|
|
121
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
122
|
+
const ch = pattern[i];
|
|
123
|
+
if (ch === "'") {
|
|
124
|
+
quoted = !quoted;
|
|
125
|
+
if (start >= 0)
|
|
126
|
+
return [start, i];
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const isDigit = !quoted && "#0,.".includes(ch);
|
|
130
|
+
if (isDigit && start < 0)
|
|
131
|
+
start = i;
|
|
132
|
+
else if (!isDigit && start >= 0)
|
|
133
|
+
return [start, i];
|
|
134
|
+
}
|
|
135
|
+
return start < 0 ? null : [start, pattern.length];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Split `pattern` into its literal edges and its digit run.
|
|
139
|
+
*
|
|
140
|
+
* Everything before the run is a prefix and everything after it a suffix, which
|
|
141
|
+
* is what lets `$#,##0.00`, `#,##0 kg` and `€ #,##0` all work without the
|
|
142
|
+
* language needing a quoting rule for the parts that are only ever text.
|
|
143
|
+
*/
|
|
144
|
+
function parsePattern(pattern) {
|
|
145
|
+
const run = digitRun(pattern);
|
|
146
|
+
if (!run) {
|
|
147
|
+
// No digits at all is not a number format. Fall back rather than print the
|
|
148
|
+
// literal for every tick, which would read as an axis of identical labels.
|
|
149
|
+
return DEFAULT_PARSED;
|
|
150
|
+
}
|
|
151
|
+
const digits = pattern.slice(run[0], run[1]);
|
|
152
|
+
const rawPrefix = pattern.slice(0, run[0]);
|
|
153
|
+
const rawSuffix = pattern.slice(run[1]);
|
|
154
|
+
// An **unquoted** `%` is the percent operator; a quoted one is a sign the
|
|
155
|
+
// author wants printed over data that is already in percent points.
|
|
156
|
+
const percent = hasBare(rawPrefix, "%") || hasBare(rawSuffix, "%");
|
|
157
|
+
const prefix = literal(percent ? removeBare(rawPrefix, "%") : rawPrefix);
|
|
158
|
+
const suffix = literal(percent ? removeBare(rawSuffix, "%") : rawSuffix);
|
|
159
|
+
const point = digits.indexOf(".");
|
|
160
|
+
const intPart = point < 0 ? digits : digits.slice(0, point);
|
|
161
|
+
const fracPart = point < 0 ? "" : digits.slice(point + 1);
|
|
162
|
+
const count = (s, ch) => s.split(ch).length - 1;
|
|
163
|
+
return {
|
|
164
|
+
prefix,
|
|
165
|
+
suffix: percent ? `${suffix}%` : suffix,
|
|
166
|
+
grouped: intPart.includes(","),
|
|
167
|
+
minInt: Math.max(1, count(intPart, "0")),
|
|
168
|
+
minFrac: count(fracPart, "0"),
|
|
169
|
+
maxFrac: fracPart.length,
|
|
170
|
+
percent,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** Parsed patterns are reused across every tick of every frame. */
|
|
174
|
+
const cache = new Map();
|
|
175
|
+
function parsed(pattern) {
|
|
176
|
+
const held = cache.get(pattern);
|
|
177
|
+
if (held)
|
|
178
|
+
return held;
|
|
179
|
+
const next = parsePattern(pattern);
|
|
180
|
+
cache.set(pattern, next);
|
|
181
|
+
return next;
|
|
182
|
+
}
|
|
183
|
+
/** `1234567` → `1,234,567`. Only the integer run is grouped. */
|
|
184
|
+
function group(digits) {
|
|
185
|
+
return digits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* `value` written the way `pattern` says.
|
|
189
|
+
*
|
|
190
|
+
* A non-finite value prints empty rather than `NaN`: a tick with no number
|
|
191
|
+
* behind it is a tick that shouldn't caption itself, and `NaN` on an axis reads
|
|
192
|
+
* as a broken chart rather than as missing data.
|
|
193
|
+
*/
|
|
194
|
+
export function formatNumber(value, pattern) {
|
|
195
|
+
if (!Number.isFinite(value))
|
|
196
|
+
return "";
|
|
197
|
+
const p = parsed(pattern);
|
|
198
|
+
const scaled = p.percent ? value * 100 : value;
|
|
199
|
+
const rounded = scaled.toFixed(p.maxFrac);
|
|
200
|
+
// Rounding is what decides the sign, not the input: -0.001 at two decimals is
|
|
201
|
+
// "0.00", and printing it as "-0.00" puts a minus sign on an axis's zero.
|
|
202
|
+
const negative = rounded.startsWith("-");
|
|
203
|
+
const [rawInt = "0", rawFrac = ""] = (negative ? rounded.slice(1) : rounded).split(".");
|
|
204
|
+
const intDigits = rawInt.padStart(p.minInt, "0");
|
|
205
|
+
// `#` trims, `0` pads: drop trailing zeros down to the required minimum.
|
|
206
|
+
let frac = rawFrac;
|
|
207
|
+
while (frac.length > p.minFrac && frac.endsWith("0"))
|
|
208
|
+
frac = frac.slice(0, -1);
|
|
209
|
+
const body = (p.grouped ? group(intDigits) : intDigits) + (frac ? `.${frac}` : "");
|
|
210
|
+
const sign = negative && Number(rounded) !== 0 ? "-" : "";
|
|
211
|
+
return `${sign}${p.prefix}${body}${p.suffix}`;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The pattern a `(format, custom)` pair names.
|
|
215
|
+
*
|
|
216
|
+
* A blank custom pattern falls back to the plain one rather than to the empty
|
|
217
|
+
* string, so an axis switched to Custom is readable while it is being typed
|
|
218
|
+
* into rather than a column of nothing.
|
|
219
|
+
*/
|
|
220
|
+
export function patternFor(format, custom) {
|
|
221
|
+
if (format === "custom") {
|
|
222
|
+
const trimmed = custom?.trim() ?? "";
|
|
223
|
+
return trimmed === "" ? NUMBER_PATTERNS.plain : trimmed;
|
|
224
|
+
}
|
|
225
|
+
return NUMBER_PATTERNS[format ?? "plain"] ?? NUMBER_PATTERNS.plain;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=number-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-format.js","sourceRoot":"","sources":["../../../../src/components/builtins/text/number-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAKH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwD;IAClF,0EAA0E;IAC1E,4EAA4E;IAC5E,qEAAqE;IACrE,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,UAAU;IAClB,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,UAAU;CACpB,CAAA;AAiBD,8EAA8E;AAC9E,MAAM,cAAc,GAAkB;IACpC,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;IACV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AK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAA;IACzD,CAAC;IACD,OAAO,eAAe,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,eAAe,CAAC,KAAK,CAAA;AACpE,CAAC","sourcesContent":["/**\r\n * How a chart writes a number down.\r\n *\r\n * One formatter, driven by a **pattern**, and the named formats are patterns\r\n * too — `currency` is `$#,##0.00` and nothing more. That is the whole design:\r\n * a dropdown of four presets and a free-text pattern are otherwise two features\r\n * that drift, one of them gaining a thousands separator or a negative sign the\r\n * other never hears about. Here the preset *is* the custom case with the\r\n * pattern filled in, so there is one set of rules to get right.\r\n *\r\n * The grammar is the spreadsheet one, because that is where the numbers come\r\n * from and what an author already knows:\r\n *\r\n * | Pattern | 1234.5 | 0.07 |\r\n * | ------------ | --------- | ------ |\r\n * | `#,##0.##` | `1,234.5` | `0.07` |\r\n * | `0` | `1235` | `0` |\r\n * | `$#,##0.00` | `$1,234.50` | `$0.07` |\r\n * | `0.#%` | `123450%` | `7%` |\r\n * | `#,##0 kg` | `1,235 kg` | `0 kg` |\r\n *\r\n * - `0` is a digit that is always written, `#` one that is written only when\r\n * the number needs it. So `0.00` pads to two decimals and `0.##` trims.\r\n * - A `,` anywhere in the integer run turns grouping on; where it sits doesn't\r\n * matter, since `#,##0` and `#,###,##0` mean the same thing to everyone who\r\n * writes them.\r\n * - `%` scales by 100 as well as printing — that is what makes it a percent\r\n * rather than a suffix, and it is why `0.07` under `0.#%` is `7%`. A column\r\n * that is *already* in percent points wants `#,##0'%'`: quoted, so the sign\r\n * is printed and nothing is scaled.\r\n * - Anything else is literal, before the digits or after them. Quote it to be\r\n * sure — `'#'#,##0` prints a leading hash.\r\n *\r\n * Deliberately **not** `Intl.NumberFormat`. Its output is locale-dependent, and\r\n * a chart is a picture with a fixed layout: the same project rendering\r\n * `1,234.50` on the author's machine and `1.234,50` on the export box is a\r\n * silently different image, and the wider string can reflow an axis. What an\r\n * author wants here is the format they *typed*.\r\n */\r\n\r\n/** The named formats the inspector offers, plus the escape hatch. */\r\nexport type NumberFormatName = \"plain\" | \"number\" | \"currency\" | \"percent\" | \"custom\"\r\n\r\n/**\r\n * The pattern behind each named format.\r\n *\r\n * `plain` is the historic behaviour — integers bare, everything else to one\r\n * decimal — kept as the default so no existing chart re-labels itself. The rest\r\n * are the three formats a chart of money, counts or shares actually needs.\r\n */\r\nexport const NUMBER_PATTERNS: Record<Exclude<NumberFormatName, \"custom\">, string> = {\r\n // Ungrouped on purpose: this is what `formatMarker` did before there were\r\n // formats at all, and it is the default, so every chart already drawn keeps\r\n // the labels it has. Grouping is what the reader picks `number` for.\r\n plain: \"#.#\",\r\n number: \"#,##0.##\",\r\n currency: \"$#,##0.00\",\r\n percent: \"#,##0.#%\",\r\n}\r\n\r\n/** A pattern taken apart once, so formatting a tick is not a parse. */\r\ninterface ParsedPattern {\r\n prefix: string\r\n suffix: string\r\n grouped: boolean\r\n /** Digits always written left of the point — the count of `0`s there. */\r\n minInt: number\r\n /** Digits always written right of it. */\r\n minFrac: number\r\n /** The most that may be written right of it. */\r\n maxFrac: number\r\n /** Scale by 100 and print a `%`. */\r\n percent: boolean\r\n}\r\n\r\n/** What a pattern with no digits in it falls back to: the `plain` reading. */\r\nconst DEFAULT_PARSED: ParsedPattern = {\r\n prefix: \"\",\r\n suffix: \"\",\r\n grouped: false,\r\n minInt: 1,\r\n minFrac: 0,\r\n maxFrac: 1,\r\n percent: false,\r\n}\r\n\r\n/** Walk `text`, calling `visit` with each character and whether it is quoted. */\r\nfunction scan(text: string, visit: (ch: string, quoted: boolean) => void): void {\r\n let quoted = false\r\n for (const ch of text) {\r\n if (ch === \"'\") {\r\n quoted = !quoted\r\n continue\r\n }\r\n visit(ch, quoted)\r\n }\r\n}\r\n\r\n/** Does `text` hold `ch` outside quotes? */\r\nfunction hasBare(text: string, ch: string): boolean {\r\n let found = false\r\n scan(text, (c, quoted) => {\r\n if (c === ch && !quoted) found = true\r\n })\r\n return found\r\n}\r\n\r\n/** `text` with every unquoted `ch` dropped, quoting preserved. */\r\nfunction removeBare(text: string, ch: string): string {\r\n let out = \"\"\r\n let quoted = false\r\n for (const c of text) {\r\n if (c === \"'\") {\r\n quoted = !quoted\r\n out += c\r\n continue\r\n }\r\n if (c === ch && !quoted) continue\r\n out += c\r\n }\r\n return out\r\n}\r\n\r\n/** `text` with its quotes taken off — what actually gets printed. */\r\nfunction literal(text: string): string {\r\n let out = \"\"\r\n scan(text, (ch) => {\r\n out += ch\r\n })\r\n return out\r\n}\r\n\r\n/**\r\n * The `[start, end)` of the pattern's digit run — the first stretch of `#0,.`\r\n * outside quotes.\r\n *\r\n * Quote-aware, so `'#'#,##0` reads its leading hash as text and its run as the\r\n * three characters after it. Without that, a quoted `#` would be taken for the\r\n * number and the real digits for a suffix.\r\n */\r\nfunction digitRun(pattern: string): [number, number] | null {\r\n let quoted = false\r\n let start = -1\r\n for (let i = 0; i < pattern.length; i++) {\r\n const ch = pattern[i]\r\n if (ch === \"'\") {\r\n quoted = !quoted\r\n if (start >= 0) return [start, i]\r\n continue\r\n }\r\n const isDigit = !quoted && \"#0,.\".includes(ch)\r\n if (isDigit && start < 0) start = i\r\n else if (!isDigit && start >= 0) return [start, i]\r\n }\r\n return start < 0 ? null : [start, pattern.length]\r\n}\r\n\r\n/**\r\n * Split `pattern` into its literal edges and its digit run.\r\n *\r\n * Everything before the run is a prefix and everything after it a suffix, which\r\n * is what lets `$#,##0.00`, `#,##0 kg` and `€ #,##0` all work without the\r\n * language needing a quoting rule for the parts that are only ever text.\r\n */\r\nfunction parsePattern(pattern: string): ParsedPattern {\r\n const run = digitRun(pattern)\r\n if (!run) {\r\n // No digits at all is not a number format. Fall back rather than print the\r\n // literal for every tick, which would read as an axis of identical labels.\r\n return DEFAULT_PARSED\r\n }\r\n\r\n const digits = pattern.slice(run[0], run[1])\r\n const rawPrefix = pattern.slice(0, run[0])\r\n const rawSuffix = pattern.slice(run[1])\r\n\r\n // An **unquoted** `%` is the percent operator; a quoted one is a sign the\r\n // author wants printed over data that is already in percent points.\r\n const percent = hasBare(rawPrefix, \"%\") || hasBare(rawSuffix, \"%\")\r\n const prefix = literal(percent ? removeBare(rawPrefix, \"%\") : rawPrefix)\r\n const suffix = literal(percent ? removeBare(rawSuffix, \"%\") : rawSuffix)\r\n\r\n const point = digits.indexOf(\".\")\r\n const intPart = point < 0 ? digits : digits.slice(0, point)\r\n const fracPart = point < 0 ? \"\" : digits.slice(point + 1)\r\n\r\n const count = (s: string, ch: string) => s.split(ch).length - 1\r\n\r\n return {\r\n prefix,\r\n suffix: percent ? `${suffix}%` : suffix,\r\n grouped: intPart.includes(\",\"),\r\n minInt: Math.max(1, count(intPart, \"0\")),\r\n minFrac: count(fracPart, \"0\"),\r\n maxFrac: fracPart.length,\r\n percent,\r\n }\r\n}\r\n\r\n/** Parsed patterns are reused across every tick of every frame. */\r\nconst cache = new Map<string, ParsedPattern>()\r\n\r\nfunction parsed(pattern: string): ParsedPattern {\r\n const held = cache.get(pattern)\r\n if (held) return held\r\n const next = parsePattern(pattern)\r\n cache.set(pattern, next)\r\n return next\r\n}\r\n\r\n/** `1234567` → `1,234,567`. Only the integer run is grouped. */\r\nfunction group(digits: string): string {\r\n return digits.replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")\r\n}\r\n\r\n/**\r\n * `value` written the way `pattern` says.\r\n *\r\n * A non-finite value prints empty rather than `NaN`: a tick with no number\r\n * behind it is a tick that shouldn't caption itself, and `NaN` on an axis reads\r\n * as a broken chart rather than as missing data.\r\n */\r\nexport function formatNumber(value: number, pattern: string): string {\r\n if (!Number.isFinite(value)) return \"\"\r\n const p = parsed(pattern)\r\n\r\n const scaled = p.percent ? value * 100 : value\r\n const rounded = scaled.toFixed(p.maxFrac)\r\n // Rounding is what decides the sign, not the input: -0.001 at two decimals is\r\n // \"0.00\", and printing it as \"-0.00\" puts a minus sign on an axis's zero.\r\n const negative = rounded.startsWith(\"-\")\r\n const [rawInt = \"0\", rawFrac = \"\"] = (\r\n negative ? rounded.slice(1) : rounded\r\n ).split(\".\")\r\n\r\n const intDigits = rawInt.padStart(p.minInt, \"0\")\r\n // `#` trims, `0` pads: drop trailing zeros down to the required minimum.\r\n let frac = rawFrac\r\n while (frac.length > p.minFrac && frac.endsWith(\"0\")) frac = frac.slice(0, -1)\r\n\r\n const body = (p.grouped ? group(intDigits) : intDigits) + (frac ? `.${frac}` : \"\")\r\n const sign = negative && Number(rounded) !== 0 ? \"-\" : \"\"\r\n return `${sign}${p.prefix}${body}${p.suffix}`\r\n}\r\n\r\n/**\r\n * The pattern a `(format, custom)` pair names.\r\n *\r\n * A blank custom pattern falls back to the plain one rather than to the empty\r\n * string, so an axis switched to Custom is readable while it is being typed\r\n * into rather than a column of nothing.\r\n */\r\nexport function patternFor(\r\n format: NumberFormatName | undefined,\r\n custom: string | undefined\r\n): string {\r\n if (format === \"custom\") {\r\n const trimmed = custom?.trim() ?? \"\"\r\n return trimmed === \"\" ? NUMBER_PATTERNS.plain : trimmed\r\n }\r\n return NUMBER_PATTERNS[format ?? \"plain\"] ?? NUMBER_PATTERNS.plain\r\n}\r\n"]}
|