Initial commit xmarticaims
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
// Silence is golden.
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php get_header(); ?>
|
||||
|
||||
<main role="main" aria-label="Content">
|
||||
<section>
|
||||
<div class="enter-up enter-d1 mb-6 px-[5.2vw] pt-10 xl:px-12 md:px-6">
|
||||
<?php if ( function_exists( 'rank_math_the_breadcrumbs' ) ) { rank_math_the_breadcrumbs(); } ?>
|
||||
</div>
|
||||
|
||||
<article id="post-404">
|
||||
|
||||
<h1><?php esc_html_e( 'Page not found', 'html5blank' ); ?></h1>
|
||||
<h2>
|
||||
<a href="<?php echo esc_url( home_url() ); ?>"><?php esc_html_e( 'Return home?', 'html5blank' ); ?></a>
|
||||
</h2>
|
||||
|
||||
</article>
|
||||
<!-- /article -->
|
||||
|
||||
</section>
|
||||
<!-- /section -->
|
||||
</main>
|
||||
|
||||
<?php get_sidebar(); ?>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php get_header(); ?>
|
||||
|
||||
<main role="main" aria-label="Content">
|
||||
<!-- section -->
|
||||
<section>
|
||||
|
||||
<h1><?php esc_html_e( 'Archives', 'html5blank' ); ?></h1>
|
||||
|
||||
<?php get_template_part( 'loop' ); ?>
|
||||
|
||||
<?php get_template_part( 'pagination' ); ?>
|
||||
|
||||
</section>
|
||||
<!-- /section -->
|
||||
</main>
|
||||
|
||||
<?php get_sidebar(); ?>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="arrow-forward-sharp" clip-path="url(#clip0_0_4)">
|
||||
<path id="Vector" d="M8.672 3.28125L12.89 7.5L8.672 11.7188M12.304 7.5H3.75" stroke="black" stroke-width="2" stroke-miterlimit="10" stroke-linecap="square"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_0_4">
|
||||
<rect width="15" height="15" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 490 B |
@@ -0,0 +1,7 @@
|
||||
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="50.246" height="21.42" viewBox="0 0 50.246 21.42" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="IMS">
|
||||
<path id="Vector" d="M42.3362 21.42C40.5656 21.42 39.0452 21.1217 37.775 20.5251C36.5048 19.9285 35.5137 19.0913 34.8016 18.0136C34.0896 16.9358 33.6854 15.6657 33.5892 14.203L38.006 14.0009C38.1214 14.8092 38.3524 15.5021 38.6988 16.0794C39.0645 16.6375 39.5456 17.0609 40.1422 17.3496C40.7581 17.6383 41.5086 17.7826 42.3939 17.7826C43.1252 17.7826 43.7411 17.696 44.2414 17.5228C44.7611 17.3496 45.1556 17.0898 45.425 16.7434C45.6945 16.3777 45.8292 15.9351 45.8292 15.4155C45.8292 14.9343 45.7137 14.5206 45.4828 14.1742C45.2518 13.8085 44.8092 13.4813 44.1548 13.1926C43.5005 12.8847 42.5382 12.5864 41.2681 12.2977C39.5167 11.8936 38.1022 11.4413 37.0245 10.9409C35.966 10.4406 35.1962 9.81509 34.715 9.06453C34.2339 8.29472 33.9933 7.33245 33.9933 6.17774C33.9933 4.94604 34.2916 3.8683 34.8882 2.94453C35.5041 2.02075 36.3894 1.29906 37.5441 0.779433C38.6988 0.259811 40.0748 0 41.6722 0C43.3658 0 44.7996 0.298302 45.9735 0.894905C47.1475 1.49151 48.0616 2.30943 48.716 3.34868C49.3896 4.38792 49.7937 5.58113 49.9284 6.9283L45.5405 7.15925C45.4828 6.44717 45.2903 5.83132 44.9631 5.3117C44.636 4.77283 44.1933 4.35906 43.6352 4.07038C43.0771 3.7817 42.4035 3.63736 41.6145 3.63736C40.6137 3.63736 39.8247 3.85868 39.2473 4.30132C38.6892 4.74396 38.4101 5.32132 38.4101 6.0334C38.4101 6.53377 38.5352 6.95717 38.7854 7.30359C39.0548 7.63076 39.4879 7.91943 40.0845 8.16962C40.7003 8.41981 41.5664 8.66038 42.6826 8.89132C44.5879 9.27623 46.089 9.76698 47.186 10.3636C48.3022 10.9409 49.0913 11.6338 49.5531 12.4421C50.015 13.2504 50.246 14.1742 50.246 15.2134C50.246 16.4836 49.9188 17.5902 49.2645 18.5332C48.6294 19.457 47.7152 20.1691 46.522 20.6694C45.3481 21.1698 43.9528 21.42 42.3362 21.42Z" fill="black"/>
|
||||
<path id="Vector_2" d="M8.26007 20.9582V0.461985H14.1203L19.3453 15.3867L24.5416 0.461985H30.4018V20.9582H26.0138V7.67897L21.1929 20.9005H17.4401L12.648 7.67897V20.9582H8.26007Z" fill="black"/>
|
||||
<path id="Vector_3" d="M4.91738e-06 20.9582V0.461985H4.38793V20.9582H4.91738e-06Z" fill="black"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,9 @@
|
||||
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="83.4433" height="21.0823" viewBox="0 0 83.4433 21.0823" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="Xmart">
|
||||
<path id="Vector" d="M80.1145 20.732C78.5572 20.732 77.4087 20.3718 76.6689 19.6516C75.9487 18.9313 75.5885 17.8022 75.5885 16.2644V1.48922H79.3261V15.914C79.3261 16.6342 79.4819 17.1404 79.7933 17.4324C80.1048 17.7049 80.5915 17.8412 81.2533 17.8412H83.4433V20.732H80.1145ZM73.1357 8.03001V5.13921H83.4433V8.03001H73.1357Z" fill="white"/>
|
||||
<path id="Vector_2" d="M63.0298 20.732V5.13921H66.5338L66.6798 9.4608L66.3586 9.4024C66.5922 7.90347 67.0302 6.82308 67.6726 6.16121C68.3345 5.47988 69.23 5.13921 70.359 5.13921H71.7898V8.35121H70.3298C69.5317 8.35121 68.8698 8.46801 68.3442 8.7016C67.8186 8.9352 67.4196 9.30507 67.147 9.8112C66.894 10.2979 66.7674 10.9403 66.7674 11.7384V20.732H63.0298Z" fill="white"/>
|
||||
<path id="Vector_3" d="M50.6746 21.0823C49.0395 21.0823 47.7255 20.7125 46.7327 19.9727C45.7399 19.2135 45.2435 18.1623 45.2435 16.8192C45.2435 15.476 45.662 14.4248 46.4991 13.6656C47.3361 12.9064 48.6112 12.3613 50.3243 12.0304L55.4926 11.0084C55.4926 9.89877 55.2396 9.07144 54.7334 8.52637C54.2273 7.96184 53.4778 7.67958 52.485 7.67958C51.5896 7.67958 50.879 7.89371 50.3534 8.32198C49.8473 8.73077 49.4969 9.32451 49.3023 10.1032L45.5063 9.92797C45.8177 8.27331 46.5769 7.00798 47.7839 6.13198C48.9908 5.23652 50.5579 4.78879 52.485 4.78879C54.7042 4.78879 56.3784 5.35332 57.5074 6.48238C58.656 7.59198 59.2302 9.18824 59.2302 11.2712V16.936C59.2302 17.3448 59.2984 17.627 59.4346 17.7827C59.5904 17.9385 59.8142 18.0163 60.1062 18.0163H60.6026V20.7319C60.4858 20.7709 60.2912 20.8001 60.0186 20.8195C59.7656 20.839 59.5028 20.8487 59.2302 20.8487C58.5878 20.8487 58.0136 20.7514 57.5074 20.5567C57.0013 20.3426 56.612 19.9825 56.3394 19.4763C56.0669 18.9507 55.9306 18.2402 55.9306 17.3448L56.2518 17.5784C56.0961 18.2597 55.7554 18.8729 55.2298 19.4179C54.7237 19.9435 54.0813 20.3523 53.3026 20.6443C52.524 20.9363 51.648 21.0823 50.6746 21.0823ZM51.4338 18.3667C52.2709 18.3667 52.9912 18.2013 53.5946 17.8703C54.1981 17.5394 54.6653 17.082 54.9962 16.498C55.3272 15.914 55.4926 15.2229 55.4926 14.4248V13.5488L51.463 14.3664C50.626 14.5416 50.0225 14.8044 49.6527 15.1548C49.3023 15.4857 49.1271 15.9237 49.1271 16.4688C49.1271 17.0722 49.3217 17.5394 49.7111 17.8703C50.1199 18.2013 50.6941 18.3667 51.4338 18.3667Z" fill="white"/>
|
||||
<path id="Vector_4" d="M20.4561 20.7319V5.13918H23.8433L23.9601 8.96437L23.6097 8.78917C23.7849 7.95211 24.0867 7.24158 24.5149 6.65758C24.9627 6.05412 25.498 5.59665 26.1209 5.28518C26.7633 4.95425 27.4641 4.78879 28.2233 4.78879C29.547 4.78879 30.6177 5.16838 31.4353 5.92758C32.2529 6.66731 32.7688 7.68931 32.9829 8.99357H32.4865C32.6617 8.07864 32.9634 7.31944 33.3917 6.71598C33.82 6.09305 34.3553 5.61612 34.9977 5.28518C35.6596 4.95425 36.3993 4.78879 37.2169 4.78879C38.2875 4.78879 39.2122 5.02238 39.9909 5.48958C40.7695 5.93732 41.3633 6.59918 41.7721 7.47518C42.2003 8.35117 42.4145 9.43157 42.4145 10.7164V20.7319H38.6769V11.68C38.6769 10.3952 38.453 9.43157 38.0053 8.78917C37.577 8.14678 36.9152 7.82558 36.0197 7.82558C35.4162 7.82558 34.9004 7.98131 34.4721 8.29278C34.0438 8.60424 33.7129 9.06171 33.4793 9.66517C33.2652 10.2492 33.1581 10.9597 33.1581 11.7968V20.7319H29.6833V11.7968C29.6833 10.512 29.4886 9.52891 29.0993 8.84757C28.71 8.16624 28.0384 7.82558 27.0845 7.82558C26.481 7.82558 25.9652 7.98131 25.5369 8.29278C25.1281 8.60424 24.7972 9.06171 24.5441 9.66517C24.3105 10.2492 24.1937 10.9597 24.1937 11.7968V20.7319H20.4561Z" fill="white"/>
|
||||
<path id="Vector_5" d="M0 20.7319L6.97878 10.3368L0.0583999 0H4.49679L9.31477 7.44598L14.016 0H18.4251L11.534 10.2784L18.5127 20.7319H14.1036L9.25637 13.1692L4.40919 20.7319H0Z" fill="white"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="112"
|
||||
height="20"
|
||||
id="svg2">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<g
|
||||
transform="translate(-254.26343,-163.48068)"
|
||||
id="layer1">
|
||||
<g
|
||||
transform="translate(256.02387,164.53694)"
|
||||
id="g2418" style="fill:#fff">
|
||||
<path
|
||||
d="M 45.365,7.256 L 44.379,7.279 L 44.379,3.336 L 45.509,3.336 C 46.365,3.336 46.646,3.964 46.646,5.336 C 46.646,6.708 46.33,7.256 45.365,7.256 M 50.34,16.246 L 50.34,12.02 C 50.34,10.016 49.625,8.851 48.097,8.577 C 49.873,8.106 50.359,6.616 50.359,4.708 C 50.359,2.018 49.392,0.346 46.255,0.346 L 40.637,0.346 L 40.64,17.763 L 44.38,17.763 L 44.38,10.19 L 45.302,10.19 C 46.202,10.19 46.629,10.811 46.629,11.64 L 46.629,16.273 C 46.629,17.043 46.784,17.611 46.89,17.762 L 50.673,17.762 C 50.541,17.618 50.34,17.017 50.34,16.246"
|
||||
id="path2384" />
|
||||
<path
|
||||
d="M 8.387,14.801 C 9.056,14.243 9.171,13.552 9.171,12.932 L 9.171,10.328 L 5.535,10.328 L 5.535,13.861 C 5.535,14.367 5.126,14.777 4.621,14.777 C 4.116,14.777 3.74,14.367 3.74,13.861 L 3.74,3.852 C 3.74,3.347 4.116,2.937 4.621,2.937 C 5.126,2.937 5.535,3.347 5.535,3.852 L 5.535,7.408 L 9.166,7.408 L 9.166,3.719 C 9.166,1.681 7.834,0.004 4.59,0 C 1.259,0 0,1.685 0,3.723 L 0,14.174 C 0,16.194 1.604,17.722 3.655,17.722 L 4.781,17.722 L 8.387,14.801 z"
|
||||
id="path2386" />
|
||||
<path
|
||||
d="M 103.314,7.247 L 102.321,7.247 L 102.321,3.327 L 103.457,3.327 C 104.311,3.327 104.594,3.955 104.594,5.326 C 104.594,6.699 104.28,7.247 103.314,7.247 M 108.285,16.237 L 108.285,12.01 C 108.285,10.007 107.573,8.842 106.045,8.567 C 107.821,8.097 108.307,6.608 108.307,4.701 C 108.307,2.009 107.337,0.337 104.203,0.337 L 98.584,0.337 L 98.584,17.754 L 102.333,17.754 L 102.333,10.182 L 103.248,10.182 C 104.15,10.182 104.572,10.802 104.572,11.632 L 104.572,16.265 C 104.572,17.036 104.731,17.603 104.836,17.754 L 108.616,17.754 C 108.486,17.609 108.285,17.007 108.285,16.237"
|
||||
id="path2388" />
|
||||
<path
|
||||
d="M 90.796,11.487 L 91.77,3.36 L 92.742,11.487 L 90.796,11.487 z M 94.275,0.303 L 89.246,0.303 L 86.258,17.753 L 90.044,17.753 L 90.415,14.674 L 93.12,14.672 L 93.489,17.753 L 97.278,17.753 L 94.275,0.303 z"
|
||||
id="path2390" />
|
||||
<polygon
|
||||
points="69.198,17.751 69.198,0.341 73.034,0.341 73.034,14.446 77.031,14.446 77.031,17.751 69.198,17.751 "
|
||||
id="polygon2392" />
|
||||
<rect
|
||||
width="3.8329999"
|
||||
height="17.41"
|
||||
x="63.333"
|
||||
y="0.34200001"
|
||||
id="rect2394" />
|
||||
<polygon
|
||||
points="69.198,17.751 69.198,0.341 73.034,0.341 73.034,14.446 77.031,14.446 77.031,17.751 69.198,17.751 "
|
||||
id="polygon2396" />
|
||||
<polygon
|
||||
points="77.954,17.751 77.954,0.341 81.787,0.341 81.787,14.446 85.786,14.446 85.786,17.751 77.954,17.751 "
|
||||
id="polygon2398" />
|
||||
<path
|
||||
d="M 57.057,7.764 L 55.913,7.75 L 55.913,3.334 L 57.051,3.334 C 58.023,3.334 58.186,4 58.186,5.594 C 58.186,7.241 58.022,7.764 57.057,7.764 M 58.022,0.342 L 52.177,0.342 L 52.177,17.759 L 55.925,17.759 L 55.925,10.847 L 58.022,10.847 C 61.465,10.847 62.046,8.653 62.046,5.594 C 62.047,2.536 61.466,0.342 58.022,0.342"
|
||||
id="path2400" />
|
||||
<polygon
|
||||
points="34.161,3.66 34.161,7.11 38.13,7.11 38.13,10.521 34.161,10.521 34.161,14.387 38.877,14.385 38.877,17.746 30.322,17.75 30.322,0.338 30.318,0.338 38.722,0.338 38.722,3.66 34.161,3.66 "
|
||||
id="polygon2402" />
|
||||
<polygon
|
||||
points="22.721,15.211 22.721,3.726 20.211,3.726 20.211,0.343 29.293,0.343 29.293,3.726 26.771,3.726 26.771,17.701 25.695,17.701 22.721,15.211 "
|
||||
id="polygon2404" />
|
||||
<polygon
|
||||
points="24.348,17.727 15.504,10.316 6.34,17.727 24.348,17.727 "
|
||||
id="polygon2406"
|
||||
style="fill:#ffc400" />
|
||||
<path
|
||||
d="M 14.526,8.319 L 15.505,3.315 L 16.479,8.319 L 14.526,8.319 z M 18.027,0.361 L 12.961,0.361 L 10.01,13.604 L 15.506,9.167 L 21.236,13.969 L 18.027,0.361 z"
|
||||
id="path2408" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="5.87 4.02 434.12 117.32">
|
||||
<path d="M261.43 15.85a10.12 10.12 0 1 1-10 10.11 10.16 10.16 0 0 1 10-10.11m138.78 55.69c0 9 6 14 13.19 14a11.63 11.63 0 0 0 11.24-7.1 1.52 1.52 0 0 1 1.85-.88l12.4 3.79a1.54 1.54 0 0 1 1 2c-3 9.35-12.16 18.15-26.5 18.15-16.83 0-30.35-12.39-30.35-29.9s13.18-30 29.78-30c14.79 0 23.74 8.62 26.74 18.15a1.54 1.54 0 0 1-1 2l-12.62 3.81a1.53 1.53 0 0 1-1.86-.91c-1.53-3.79-4.9-7.08-10.91-7.08-7.17-.12-12.96 4.88-12.96 13.97m-52.09-30.01c-16.82 0-30 12.39-30 29.9s13.18 30 30 30 30-12.51 30-30-13.06-29.9-30-29.9m0 44c-6.47 0-12.72-4.66-12.72-14.09s6.25-14 12.72-14 12.74 4.43 12.74 14-6.14 14.08-12.74 14.08ZM315.6 58.6a1.54 1.54 0 0 1-1.74 1.29 23 23 0 0 0-3.28-.2c-6.93 0-13.18 4.12-13.18 15.38V98.2a1.53 1.53 0 0 1-1.53 1.53h-14.22a1.53 1.53 0 0 1-1.53-1.53V44.77a1.53 1.53 0 0 1 1.53-1.53h13.65a1.53 1.53 0 0 1 1.53 1.53v6.09c3-6.37 10.12-8.19 14.66-8.19a28 28 0 0 1 5 .56 1.52 1.52 0 0 1 1.16 1.77Z" class="cls" style="fill:#fff;fill-opacity:1"/>
|
||||
<rect width="17.28" height="56.49" x="252.9" y="43.24" class="cls" rx="1.53" style="fill:#fff;fill-opacity:1"/>
|
||||
<path d="M220 41.87c-8.07 0-14.21 3.53-16.59 7.17v-4.27a1.53 1.53 0 0 0-1.53-1.53h-13.61a1.52 1.52 0 0 0-1.53 1.53v75a1.53 1.53 0 0 0 1.53 1.53h14.21a1.53 1.53 0 0 0 1.52-1.5V95.3c2.62 3.18 8.07 5.68 15.35 5.68 15.8 0 26.94-12.39 26.94-29.67.01-16.93-9.88-29.44-26.29-29.44m-3.52 43.65c-6.71 0-12.73-4.77-12.73-14.09s6-14 12.73-14 12.84 4.54 12.84 14-5.98 14.09-12.8 14.09ZM128.09 98.2V20.67a1.54 1.54 0 0 1 1.53-1.53h48a1.54 1.54 0 0 1 1.53 1.53v13.88a1.54 1.54 0 0 1-1.53 1.53h-30a1.53 1.53 0 0 0-1.53 1.53v12.28a1.53 1.53 0 0 0 1.53 1.53h26.95a1.54 1.54 0 0 1 1.49 1.58v12.69a1.53 1.53 0 0 1-1.53 1.53h-26.95a1.54 1.54 0 0 0-1.53 1.53v12.4a1.53 1.53 0 0 0 1.53 1.53h30.13a1.53 1.53 0 0 1 1.53 1.53v14a1.52 1.52 0 0 1-1.53 1.53h-48.09a1.53 1.53 0 0 1-1.53-1.54M101.2 49.05V35a8.13 8.13 0 0 0-4.07-7L57.61 5.12a8.16 8.16 0 0 0-8.14 0L10 27.94A8.13 8.13 0 0 0 5.88 35v45.62a8.13 8.13 0 0 0 4.07 7l39.52 22.82a8.16 8.16 0 0 0 8.14 0l39.52-22.77a8.13 8.13 0 0 0 4.07-7V59.9L53.54 88.39 27.05 73.1V42.51l23.78-13.73a5.41 5.41 0 0 1 5.42 0L80 42.63 55.51 56.75a5.6 5.6 0 0 1-5.6 0L32.32 46.61v23.75L53.13 81.5l44-25.4a8.13 8.13 0 0 0 4.07-7.05" class="cls" style="fill:#fff;fill-opacity:1"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg fill="#fff" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="850" height="135.664" viewBox="0 0 224.896 35.894">
|
||||
<path d="M148.51 0c-9.33-.062-20.703 3.807-20.763 17.858-.06 13.91 11.553 18.3 20.763 18.024 8.561-.255 18.013-2.634 18.445-13.105l-9.463.021c-.267 6.58-5.517 7.885-8.982 7.896-3.555.013-10.79-.735-10.904-12.695-.108-11.289 6.533-12.885 10.904-12.837 4.371.048 8.707 2.087 8.756 7.227l9.401-.008C166.571 6.088 161.131.085 148.51 0ZM0 .638V35.2h9.15V19.947h18.518V35.2h9.193V.637h-9.193V14.47H9.15V.637Zm44.452 0v34.56h9.213V.638Zm12.623 0v5.717h13.419v28.838h9.114V6.354H93.03V.637Zm114.367 0V35.2h9.15V19.947h18.518V35.2h9.15V.637h-9.15V14.47h-18.517V.637Zm44.231 0v34.56h9.223V.638ZM101.541.689l-16.385 34.51h10.281l3.195-7.754 17.313-.006 3.187 7.76h10.306L113.128.689Zm5.763 5.836 6.332 15.42-12.717.008z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 907 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 170 34"><path d="M159 33.2c-2.9.1-5.7-.7-7.9-2.5-2.1-1.9-3.2-4.6-3-7.4v-15h9.7v15c0 .7.6 1.3 1.3 1.3.7 0 1.2-.6 1.3-1.3v-15h9.7v15c0 3.2-1 5.7-3 7.4-2.4 1.8-5.3 2.7-8.1 2.5zm-121.3 0c-7-.1-12.7-5.8-12.6-12.9-.2-7 5.4-12.8 12.4-12.9 7-.2 12.8 5.4 12.9 12.4v.6c0 3.4-1.3 6.7-3.7 9.1-2.4 2.4-5.6 3.7-9 3.7zm0-16.5c-2 0-3.7 1.6-3.7 3.6s1.6 3.7 3.6 3.7 3.7-1.6 3.7-3.6v-.1c0-2-1.6-3.6-3.6-3.6zm97.6 16.5c-4.1 0-6.9-1.2-10.4-3.2l2.7-6.4s4 2.6 6.7 2.6c.3 0 .6 0 .9-.1.5-.1.8-.5.8-1s-.2-.9-.7-1.1c-.5-.2-1.1-.4-1.6-.5-1.9-.5-4.9-1.2-6.4-4.1-1.7-3.2-1-7.1 1.7-9.4 2.1-1.7 4.7-2.6 7.4-2.6h.5c3 .1 5.9 1 8.5 2.7l-2.7 6.4c-1.8-1-4.2-2.1-5.7-2.1-.8 0-1.2.3-1.3.9-.1.9.8 1.2 2.3 1.6 1.3.3 2.5.7 3.7 1.3 2.9 1.7 4.4 5.1 3.5 8.4-.4 1.9-1.5 3.5-3.1 4.6-1.9 1.4-4.3 2.1-6.8 2zM9.8 32.3H0V8.4h9.8V20L15 8.4h11.1l-5.6 11.7 5.9 12.2H15.3L9.8 20.1v12.2zm50 0H51l3.6-23.9h8.9l3 9.6 3-9.6h8.9l3.3 22.5 7.6-22.5H99l8.2 23.9H97L94.1 21l-2.9 11.3H73l-1.3-9.1-2.5 9.1h-5.7L61 23.2l-1.2 9.1zm60 0H110v-15h-5.7V8.4h15.4V.8h9.1v9.5h-9.1l.1 22z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="#fff" enable-background="new 0 0 1000 124" viewBox="0 0 1000 124" xmlns="http://www.w3.org/2000/svg"><path d="m238.9 95.2h31.4v28.8h-89.9v-124h89v28.8h-30.6v19.8h27.9v26.1h-27.9v20.5zm-137.6 28.8h59.3v-124h-59.3zm-42.9-124h-58.4v124h85.4v-33.2h-27zm595.7 74.6h27.9v-26.1h-27.9v-19.7h30.6v-28.8h-89v124h89.9v-28.8h-31.5zm-230.7 16.1c0 16.2-9.5 26.8-25.7 30.7-7.1 1.7-18.6 2.6-29 2.6h-80.5v-124h80c10.2 0 21.4.9 28.4 2.6 15.8 3.9 25.1 14.5 25.1 30.7 0 14.9-8.8 25.1-20 28.4 12 2.7 21.7 13.3 21.7 29m-78.7-40.4h8.1c10.8 0 14.4-5.4 14.4-13s-3.6-13-14.4-13h-8.1zm24.3 36c0-8.1-3.7-13.5-15.3-13.5h-9v27h9c11.7-.1 15.3-5.5 15.3-13.5m148-40.5h-19.8v-45.8h-58.4v124h58.4v-47.6h19.8v47.6h58.4v-124h-58.4zm450.9 26.5c15.3-7 22.1-18.6 22.1-34.4 0-18.4-11-30.4-29.4-34.9-8.1-1.9-21.2-3-33-3h-71.9v124h55.7v-39.5h5l21.1 39.5h62.5zm-48.4-13.9h-8.1v-29.6h8.1c10.8 0 14.4 5.4 14.4 14.8s-3.6 14.8-14.4 14.8zm-104.1 13.9c15.3-7 22.1-18.6 22.1-34.4 0-18.4-11-30.4-29.4-34.9-8.1-1.9-21.2-3-33-3h-71.9v124h55.7v-39.5h5l21.1 39.5h62.5zm-48.5-13.9h-8.1v-29.6h8.1c10.8 0 14.4 5.4 14.4 14.8s-3.6 14.8-14.4 14.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg fill="#fff"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="800"
|
||||
height="110.066"
|
||||
viewBox="0 0 800 110.066"
|
||||
id="svg2"
|
||||
xml:space="preserve"><defs
|
||||
id="defs23" />
|
||||
<g
|
||||
style="display:none"
|
||||
id="Grade">
|
||||
</g>
|
||||
<g
|
||||
id="Camada_1">
|
||||
</g>
|
||||
<g
|
||||
id="Área_de_trabalho">
|
||||
</g>
|
||||
<g
|
||||
id="Linhas-guia">
|
||||
</g>
|
||||
<g
|
||||
id="Page_1">
|
||||
<g
|
||||
id="Camada_1_1_">
|
||||
<g
|
||||
id="g10">
|
||||
<polygon
|
||||
points="0,4.723 0,19.33 23.959,19.33 70.846,107.261 128.543,107.261 175.43,19.184 199.385,19.033 199.437,4.723 127.761,4.723 127.761,19.083 146.849,19.083 113.74,81.595 77.933,19.301 104.05,19.184 104.004,4.723 0,4.723 "
|
||||
style="fill:#fff;fill-rule:evenodd"
|
||||
id="polygon12" />
|
||||
<polygon
|
||||
points="462.405,4.723 462.405,19.33 486.357,19.33 533.245,107.261 590.944,107.261 637.831,19.184 661.789,19.033 661.832,4.723 590.169,4.723 590.169,19.083 609.249,19.083 576.141,81.595 540.33,19.301 566.455,19.184 566.406,4.723 462.405,4.723 "
|
||||
style="fill:#fff;fill-rule:evenodd"
|
||||
id="polygon14" />
|
||||
<path
|
||||
d="M 344.515,4.723 L 344.515,19.33 L 368.47,19.33 L 368.51,91.118 L 343.255,91.118 L 343.255,107.119 L 368.527,107.262 L 488.139,107.262 L 488.139,59.532 L 472.558,59.532 C 471.704,84.803 449.782,91.152 440.548,91.152 C 432.087,91.152 415.693,91.119 415.693,91.119 L 415.693,19.301 L 439.288,19.183 L 439.256,4.722 L 344.515,4.722 L 344.515,4.723 z "
|
||||
style="fill:#fff;fill-rule:evenodd"
|
||||
id="path16" />
|
||||
<path
|
||||
d="M 262.808,94.13 C 248.453,94.13 236.822,76.935 236.822,55.713 C 236.822,34.486 248.453,17.278 262.808,17.278 C 277.159,17.278 288.794,34.486 288.794,55.713 C 288.794,76.935 277.159,94.13 262.808,94.13 L 262.808,94.13 z M 263.864,1.777 C 223.144,1.777 190.135,26.024 190.135,55.922 C 190.135,85.822 223.143,110.066 263.864,110.066 C 304.581,110.066 337.595,85.822 337.595,55.922 C 337.595,26.024 304.581,1.777 263.864,1.777 L 263.864,1.777 z "
|
||||
style="fill:#fff;fill-rule:evenodd"
|
||||
id="path18" />
|
||||
<path
|
||||
d="M 725.215,93.857 C 710.865,93.857 699.235,76.377 699.235,54.804 C 699.235,33.239 710.866,15.755 725.215,15.755 C 739.567,15.755 751.195,33.239 751.195,54.804 C 751.196,76.376 739.567,93.857 725.215,93.857 L 725.215,93.857 z M 726.276,0 C 685.547,0 652.548,24.642 652.548,55.028 C 652.548,85.413 685.546,110.05 726.276,110.05 C 766.99,110.05 800,85.413 800,55.028 C 800,24.642 766.99,0 726.276,0 L 726.276,0 z "
|
||||
style="fill:#fff;fill-rule:evenodd"
|
||||
id="path20" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 736 KiB |
|
After Width: | Height: | Size: 819 KiB |
|
After Width: | Height: | Size: 800 KiB |
|
After Width: | Height: | Size: 779 KiB |
|
After Width: | Height: | Size: 754 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
|
||||
<path d="M10 4V16M4 10H16" stroke="#4FACD9" stroke-width="2" stroke-linecap="square"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 191 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="24" cy="23" r="8"/><path d="M29.7 28.7 36 35M19 18l-4-3M17 23h-6M19 28l-4 4M24 15v-5"/>
|
||||
<path d="M21 20h6v6h-6zM31 18l4-2M31 23h6"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 404 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="23" cy="23" r="10"/><circle cx="23" cy="23" r="6"/><circle cx="23" cy="23" r="2"/>
|
||||
<path d="M30 30l7 7M34 15h4v4M38 15l-7 7"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 398 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="14" y="13" width="22" height="26" rx="2"/><path d="M20 13v-2h10v2M19 27h12M19 31h9"/>
|
||||
<circle cx="25" cy="20" r="3"/><path d="M20 25c1-2 3-3 5-3s4 1 5 3"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 424 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="12" y="11" width="24" height="28" rx="2"/><path d="M17 17h14M17 22h14M17 27h9M17 32h7"/>
|
||||
<circle cx="33" cy="33" r="5"/><path d="M36.5 36.5 40 40"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 417 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="13" y="11" width="20" height="28" rx="2"/>
|
||||
<path d="M17 16h12M17 20h12M17 25h3v3h-3zM23 25h3v3h-3zM17 31h3v3h-3zM23 31h3v3h-3zM36 16h3v18h-3z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 413 B |
@@ -0,0 +1,8 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="11" y="12" width="28" height="18" rx="2"/>
|
||||
<path d="M17 17h16M17 21h10M25 30v4M19 37h12"/>
|
||||
<circle cx="16" cy="34" r="2"/><circle cx="25" cy="37" r="2"/><circle cx="34" cy="34" r="2"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 457 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M12 37h27M16 34v-8h5v8M24 34V20h5v14M32 34V15h5v19M14 20l7-5 6 3 10-7"/>
|
||||
<path d="M33 11h4v4"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 364 B |
@@ -0,0 +1,8 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="11" y="12" width="28" height="20" rx="2"/>
|
||||
<rect x="15" y="16" width="20" height="12" rx="1"/>
|
||||
<path d="M19 37h12M25 32v5M18 20h14M18 24h10"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 415 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="25" cy="16" r="4"/><circle cx="16" cy="29" r="4"/><circle cx="34" cy="29" r="4"/>
|
||||
<path d="M20 39v-2a5 5 0 0 0-5-5h-1a5 5 0 0 0-5 5v2M41 39v-2a5 5 0 0 0-5-5h-1a5 5 0 0 0-5 5v2M31 25v-2a5 5 0 0 0-5-5h-2a5 5 0 0 0-5 5v2"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 492 B |
@@ -0,0 +1,7 @@
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="50" height="50" rx="8" fill="#4FACD9"/>
|
||||
<g stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M16 11h15l5 5v23H16zM31 11v6h5M20 22h12M20 26h12M20 30h8"/>
|
||||
<path d="M12 16h4M12 20h4M12 24h4"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 365 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45" viewBox="0 0 45 45" fill="none">
|
||||
<rect x="0.5" y="0.5" width="44" height="44" rx="22" stroke="#4FACD9"/>
|
||||
<path d="M14.5 16.5H30.5V28.5H14.5V16.5Z" stroke="#4FACD9" stroke-width="1.5" stroke-linejoin="round"/>
|
||||
<path d="M15.5 17.5L22.5 23L29.5 17.5" stroke="#4FACD9" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 406 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45" viewBox="0 0 45 45" fill="none">
|
||||
<rect x="0.5" y="0.5" width="44" height="44" rx="22" stroke="#4FACD9"/>
|
||||
<path d="M29.5 20.5C29.5 25.75 22.5 31.5 22.5 31.5C22.5 31.5 15.5 25.75 15.5 20.5C15.5 16.63 18.63 13.5 22.5 13.5C26.37 13.5 29.5 16.63 29.5 20.5Z" stroke="#4FACD9" stroke-width="1.5" stroke-linejoin="round"/>
|
||||
<circle cx="22.5" cy="20.5" r="2.5" stroke="#4FACD9" stroke-width="1.5"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 462 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="45" height="45" viewBox="0 0 45 45" fill="none">
|
||||
<rect x="0.5" y="0.5" width="44" height="44" rx="22" stroke="#4FACD9"/>
|
||||
<path d="M17.25 14.5H14.75C14.06 14.5 13.5 15.06 13.5 15.75C13.5 24.45 20.55 31.5 29.25 31.5C29.94 31.5 30.5 30.94 30.5 30.25V27.75L25.75 26.5L24.5 29C20.92 27.47 17.53 24.08 16 20.5L18.5 19.25L17.25 14.5Z" stroke="#4FACD9" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 469 B |
@@ -0,0 +1,9 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2025 Julian Garnier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var registry = require('./registry.cjs');
|
||||
|
||||
|
||||
|
||||
exports.registerAdapter = registry.registerAdapter;
|
||||
@@ -0,0 +1 @@
|
||||
export { registerAdapter } from "./registry.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { registerAdapter } from './registry.js';
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Anime.js adapter API. Each library or class group that wants to extend `animate()` and `utils.set()` calls `registerAdapter()` to create its own `Adapter`. The returned `Adapter` exposes `registerTargetAdapter(detect)` for per-class detection and `registerPropertyResolver(fn)` for global Color / Vector / pattern-based fallbacks.
|
||||
*
|
||||
* import { registerAdapter } from 'animejs/adapters';
|
||||
*
|
||||
* const myAdapter = registerAdapter();
|
||||
* const widget = myAdapter.registerTargetAdapter((t) => t instanceof MyWidget);
|
||||
* widget.registerProperty('value',
|
||||
* (t) => t.getValue(),
|
||||
* (target, value) => target.setValue(value),
|
||||
* );
|
||||
*
|
||||
* For scalar tweens, `value` is the interpolated number. For color and complex tweens it is `undefined`; read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* Resolution order: every Adapter's target adapters in registration order (first match wins) then every Adapter's property resolvers (first non-null wins) then engine direct property path.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef TargetAdapterEntry
|
||||
* @property {(t: any) => any} get
|
||||
* @property {(target: any, value: number, tween: any) => void} set
|
||||
* @property {(t: any) => boolean} [gate]
|
||||
*/
|
||||
|
||||
const alwaysTrue = () => true;
|
||||
|
||||
class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect) {
|
||||
this.detect = detect;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
this.props = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name, getter, setter, gate) {
|
||||
this.props[name] = {
|
||||
get: getter,
|
||||
set: setter,
|
||||
gate: gate || alwaysTrue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect) {
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
this.detect = detect || null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
this.targetAdapters = [];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
this.propertyResolvers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect) {
|
||||
const ta = new TargetAdapter(detect);
|
||||
this.targetAdapters.push(ta);
|
||||
return ta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver) {
|
||||
if (this.propertyResolvers.indexOf(resolver) === -1) this.propertyResolvers.push(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
const adapters = /** @type {Adapter[]} */([]);
|
||||
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
function registerAdapter(detect) {
|
||||
const a = new Adapter(detect);
|
||||
adapters.push(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
function resolveAdapterEntry(target, name) {
|
||||
if (!target) return null;
|
||||
const al = adapters.length;
|
||||
outer: for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const tas = a.targetAdapters;
|
||||
for (let j = 0, m = tas.length; j < m; j++) {
|
||||
const ta = tas[j];
|
||||
if (ta.detect(target)) {
|
||||
const entry = ta.props[name];
|
||||
if (entry && (!entry.gate || entry.gate(target))) return entry;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const rs = a.propertyResolvers;
|
||||
for (let j = 0, m = rs.length; j < m; j++) {
|
||||
const entry = rs[j](target, name);
|
||||
if (entry) return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
exports.registerAdapter = registerAdapter;
|
||||
exports.resolveAdapterEntry = resolveAdapterEntry;
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
export function registerAdapter(detect?: (t: any) => boolean): Adapter;
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
export function resolveAdapterEntry(target: any, name: string): TargetAdapterEntry | null;
|
||||
export type TargetAdapterEntry = {
|
||||
get: (t: any) => any;
|
||||
set: (target: any, value: number, tween: any) => void;
|
||||
gate?: (t: any) => boolean;
|
||||
};
|
||||
declare class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect?: ((t: any) => boolean) | null);
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
detect: ((t: any) => boolean) | null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
targetAdapters: TargetAdapter[];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
propertyResolvers: ((target: any, name: string) => TargetAdapterEntry | null)[];
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect: (t: any) => boolean): TargetAdapter;
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver: (target: any, name: string) => TargetAdapterEntry | null): void;
|
||||
}
|
||||
declare class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect: (t: any) => boolean);
|
||||
detect: (t: any) => boolean;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
props: Record<string, TargetAdapterEntry>;
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
}
|
||||
export {};
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Anime.js adapter API. Each library or class group that wants to extend `animate()` and `utils.set()` calls `registerAdapter()` to create its own `Adapter`. The returned `Adapter` exposes `registerTargetAdapter(detect)` for per-class detection and `registerPropertyResolver(fn)` for global Color / Vector / pattern-based fallbacks.
|
||||
*
|
||||
* import { registerAdapter } from 'animejs/adapters';
|
||||
*
|
||||
* const myAdapter = registerAdapter();
|
||||
* const widget = myAdapter.registerTargetAdapter((t) => t instanceof MyWidget);
|
||||
* widget.registerProperty('value',
|
||||
* (t) => t.getValue(),
|
||||
* (target, value) => target.setValue(value),
|
||||
* );
|
||||
*
|
||||
* For scalar tweens, `value` is the interpolated number. For color and complex tweens it is `undefined`; read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* Resolution order: every Adapter's target adapters in registration order (first match wins) then every Adapter's property resolvers (first non-null wins) then engine direct property path.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef TargetAdapterEntry
|
||||
* @property {(t: any) => any} get
|
||||
* @property {(target: any, value: number, tween: any) => void} set
|
||||
* @property {(t: any) => boolean} [gate]
|
||||
*/
|
||||
|
||||
const alwaysTrue = () => true;
|
||||
|
||||
class TargetAdapter {
|
||||
/**
|
||||
* @param {(t: any) => boolean} detect
|
||||
*/
|
||||
constructor(detect) {
|
||||
this.detect = detect;
|
||||
/** @type {Record<string, TargetAdapterEntry>} */
|
||||
this.props = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property the adapter handles. `setter` receives `(target, value, tween)`. For color and complex tweens `value` is `undefined`, read `tween._numbers` instead. `gate(target)` scopes the prop to a subset of matching targets.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {(t: any) => any} getter
|
||||
* @param {(target: any, value: number, tween: any) => void} setter
|
||||
* @param {(t: any) => boolean} [gate]
|
||||
*/
|
||||
registerProperty(name, getter, setter, gate) {
|
||||
this.props[name] = {
|
||||
get: getter,
|
||||
set: setter,
|
||||
gate: gate || alwaysTrue,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Adapter {
|
||||
/**
|
||||
* @param {((t: any) => boolean) | null} [detect]
|
||||
* Optional gate. When provided, every lookup against this Adapter's target adapters and resolvers is skipped if `detect(target)` returns falsy. Lets the Adapter as a whole short-circuit on unrelated targets.
|
||||
*/
|
||||
constructor(detect) {
|
||||
/** @type {((t: any) => boolean) | null} */
|
||||
this.detect = detect || null;
|
||||
/** @type {TargetAdapter[]} */
|
||||
this.targetAdapters = [];
|
||||
/** @type {((target: any, name: string) => TargetAdapterEntry | null)[]} */
|
||||
this.propertyResolvers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a `TargetAdapter` scoped to this Adapter.
|
||||
*
|
||||
* @param {(t: any) => boolean} detect
|
||||
* @return {TargetAdapter}
|
||||
*/
|
||||
registerTargetAdapter(detect) {
|
||||
const ta = new TargetAdapter(detect);
|
||||
this.targetAdapters.push(ta);
|
||||
return ta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a property resolver scoped to this Adapter. Resolvers are functions invoked at tween creation when no target adapter has claimed the name; the function returns an entry for names it handles or `null` to defer. Use for runtime-matched patterns (Color / Vector axis detection, name-prefix conventions, etc.).
|
||||
*
|
||||
* @param {(target: any, name: string) => TargetAdapterEntry | null} resolver
|
||||
*/
|
||||
registerPropertyResolver(resolver) {
|
||||
if (this.propertyResolvers.indexOf(resolver) === -1) this.propertyResolvers.push(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
const adapters = /** @type {Adapter[]} */([]);
|
||||
|
||||
/**
|
||||
* Creates and registers an Adapter. Each library extending `animate()` calls this once and uses the returned Adapter to wire up its target adapters and property resolvers. The optional `detect` short-circuits all lookups against the Adapter when the target is unrelated.
|
||||
*
|
||||
* @param {(t: any) => boolean} [detect]
|
||||
* @return {Adapter}
|
||||
*/
|
||||
function registerAdapter(detect) {
|
||||
const a = new Adapter(detect);
|
||||
adapters.push(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal resolution. Tries every Adapter's target adapters first (in registration order, first match wins), then every Adapter's property resolvers.
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {TargetAdapterEntry | null}
|
||||
*/
|
||||
function resolveAdapterEntry(target, name) {
|
||||
if (!target) return null;
|
||||
const al = adapters.length;
|
||||
outer: for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const tas = a.targetAdapters;
|
||||
for (let j = 0, m = tas.length; j < m; j++) {
|
||||
const ta = tas[j];
|
||||
if (ta.detect(target)) {
|
||||
const entry = ta.props[name];
|
||||
if (entry && (!entry.gate || entry.gate(target))) return entry;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < al; i++) {
|
||||
const a = adapters[i];
|
||||
if (a.detect && !a.detect(target)) continue;
|
||||
const rs = a.propertyResolvers;
|
||||
for (let j = 0, m = rs.length; j < m; j++) {
|
||||
const entry = rs[j](target, name);
|
||||
if (entry) return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export { registerAdapter, resolveAdapterEntry };
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var registry = require('../registry.cjs');
|
||||
|
||||
// Duck-typed gate for three.js targets, used as threeAdapter's Adapter-level detect.
|
||||
// Early-rejects DOM nodes via nodeType so the OR chain only runs on non-DOM objects.
|
||||
// Includes the isAnimejsInstanceProxy marker set in instance.js for per-instance wrappers.
|
||||
const isThreeTarget = (t) => !!(
|
||||
t && !t.nodeType && (
|
||||
t.isObject3D || t.isMaterial || t.isTexture ||
|
||||
t.isFog || t.isFogExp2 || t.isUniformNode ||
|
||||
t.isColor || t.isVector2 || t.isVector3 || t.isVector4 ||
|
||||
t.isAnimejsInstanceProxy
|
||||
)
|
||||
);
|
||||
|
||||
const threeAdapter = registry.registerAdapter(isThreeTarget);
|
||||
|
||||
exports.threeAdapter = threeAdapter;
|
||||
@@ -0,0 +1,15 @@
|
||||
export const threeAdapter: {
|
||||
detect: (t: any) => boolean;
|
||||
targetAdapters: {
|
||||
detect: (t: any) => boolean;
|
||||
props: Record<string, import("../registry.js").TargetAdapterEntry>;
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
}[];
|
||||
propertyResolvers: ((target: any, name: string) => import("../registry.js").TargetAdapterEntry | null)[];
|
||||
registerTargetAdapter(detect: (t: any) => boolean): {
|
||||
detect: (t: any) => boolean;
|
||||
props: Record<string, import("../registry.js").TargetAdapterEntry>;
|
||||
registerProperty(name: string, getter: (t: any) => any, setter: (target: any, value: number, tween: any) => void, gate?: (t: any) => boolean): void;
|
||||
};
|
||||
registerPropertyResolver(resolver: (target: any, name: string) => TargetAdapterEntry | null): void;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { registerAdapter } from '../registry.js';
|
||||
|
||||
// Duck-typed gate for three.js targets, used as threeAdapter's Adapter-level detect.
|
||||
// Early-rejects DOM nodes via nodeType so the OR chain only runs on non-DOM objects.
|
||||
// Includes the isAnimejsInstanceProxy marker set in instance.js for per-instance wrappers.
|
||||
const isThreeTarget = (t) => !!(
|
||||
t && !t.nodeType && (
|
||||
t.isObject3D || t.isMaterial || t.isTexture ||
|
||||
t.isFog || t.isFogExp2 || t.isUniformNode ||
|
||||
t.isColor || t.isVector2 || t.isVector3 || t.isVector4 ||
|
||||
t.isAnimejsInstanceProxy
|
||||
)
|
||||
);
|
||||
|
||||
const threeAdapter = registerAdapter(isThreeTarget);
|
||||
|
||||
export { threeAdapter };
|
||||
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
|
||||
/**
|
||||
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
||||
*/
|
||||
|
||||
|
||||
const COLOR_NORM = 1 / 255;
|
||||
|
||||
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
||||
|
||||
const PATH_DIRECT = 0;
|
||||
const PATH_UNIFORM = 1;
|
||||
const PATH_NODE = 2;
|
||||
|
||||
const KIND_COLOR = 0;
|
||||
const KIND_SCALAR = 1;
|
||||
const KIND_VECTOR = 2;
|
||||
|
||||
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
||||
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
||||
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
||||
if (skewX !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewX));
|
||||
e[4] += e[0] * t;
|
||||
e[5] += e[1] * t;
|
||||
e[6] += e[2] * t;
|
||||
}
|
||||
if (skewY !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewY));
|
||||
e[0] += e[4] * t;
|
||||
e[1] += e[5] * t;
|
||||
e[2] += e[6] * t;
|
||||
}
|
||||
if (skewZ !== 0) {
|
||||
const t = Math.tan(number.degToRad(skewZ));
|
||||
e[0] += e[8] * t;
|
||||
e[1] += e[9] * t;
|
||||
e[2] += e[10] * t;
|
||||
}
|
||||
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
||||
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
||||
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
||||
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorHex(c) {
|
||||
return c ? `#${c.getHexString(three.SRGBColorSpace)}` : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isVectorWith(v, axis) {
|
||||
if (!v) return false;
|
||||
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
||||
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
||||
return !!v.isVector4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
function classifyTargetProp(target, name) {
|
||||
const value = target[name];
|
||||
if (value !== undefined) {
|
||||
if (value && value.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
if (value && value.isUniformNode) {
|
||||
// Route TSL slot writes through node value, booleans share the scalar entry.
|
||||
const v = value.value;
|
||||
if (v && v.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
if (typeof v === 'number' || typeof v === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (typeof value === 'number' || typeof value === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const uniforms = target.uniforms;
|
||||
const u = uniforms && uniforms[name];
|
||||
if (u) {
|
||||
const uv = u.value;
|
||||
if (uv && uv.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
if (typeof uv === 'number') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (axis) {
|
||||
const base = name.slice(0, -1);
|
||||
if (isVectorWith(target[base], axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const baseSlot = target[base];
|
||||
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const ub = uniforms && uniforms[base];
|
||||
if (ub && isVectorWith(ub.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function leafAt(target, name, path) {
|
||||
if (path === PATH_DIRECT) return target[name];
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
return e ? e.value : null;
|
||||
}
|
||||
const n = target[name];
|
||||
return n ? n.value : null;
|
||||
}
|
||||
|
||||
function writeLeafScalar(target, name, v, path) {
|
||||
if (path === PATH_DIRECT) { target[name] = v; return; }
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
if (e) e.value = v;
|
||||
return;
|
||||
}
|
||||
const n = target[name];
|
||||
if (n) n.value = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
function readScalar(target, name, path, defaultValue) {
|
||||
if (defaultValue === undefined) defaultValue = 0;
|
||||
if (!target) return defaultValue;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
if (!first) return defaultValue;
|
||||
const v = leafAt(first, name, path);
|
||||
return v === undefined || v === null ? defaultValue : v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeScalar(target, name, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
||||
} else {
|
||||
writeLeafScalar(target, name, v, path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorAt(target, name, path) {
|
||||
if (!target) return null;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
return readColorHex(first ? leafAt(first, name, path) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeColorAt(target, name, ns, path) {
|
||||
if (!target) return;
|
||||
const r = ns[0] * COLOR_NORM;
|
||||
const g = ns[1] * COLOR_NORM;
|
||||
const b = ns[2] * COLOR_NORM;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const c = leafAt(target[i], name, path);
|
||||
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
||||
}
|
||||
} else {
|
||||
const c = leafAt(target, name, path);
|
||||
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
function readVectorAt(target, base, axis, path) {
|
||||
if (!target) return 0;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
const vec = first ? leafAt(first, base, path) : null;
|
||||
return vec ? vec[axis] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeVectorAt(target, base, axis, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const vec = leafAt(target[i], base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
} else {
|
||||
const vec = leafAt(target, base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
}
|
||||
|
||||
exports.AXIS_MAP = AXIS_MAP;
|
||||
exports.COLOR_NORM = COLOR_NORM;
|
||||
exports.KIND_COLOR = KIND_COLOR;
|
||||
exports.KIND_SCALAR = KIND_SCALAR;
|
||||
exports.KIND_VECTOR = KIND_VECTOR;
|
||||
exports.PATH_DIRECT = PATH_DIRECT;
|
||||
exports.applySkewOrigin = applySkewOrigin;
|
||||
exports.classifyTargetProp = classifyTargetProp;
|
||||
exports.isVectorWith = isVectorWith;
|
||||
exports.readColorAt = readColorAt;
|
||||
exports.readColorHex = readColorHex;
|
||||
exports.readScalar = readScalar;
|
||||
exports.readVectorAt = readVectorAt;
|
||||
exports.writeColorAt = writeColorAt;
|
||||
exports.writeScalar = writeScalar;
|
||||
exports.writeVectorAt = writeVectorAt;
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
export function applySkewOrigin(e: number[], skewX: number, skewY: number, skewZ: number, ox: number, oy: number, oz: number): void;
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
export function readColorHex(c: any): string | null;
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function isVectorWith(v: any, axis: "x" | "y" | "z" | "w"): boolean;
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
export function classifyTargetProp(target: any, name: string): {
|
||||
kind: number;
|
||||
path: number;
|
||||
base: string;
|
||||
axis: "x" | "y" | "z" | "w";
|
||||
} | null;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
export function readScalar(target: any, name: string, path: number, defaultValue?: number): number;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeScalar(target: any, name: string, v: number, path: number): void;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
export function readColorAt(target: any, name: string, path: number): string | null;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeColorAt(target: any, name: string, ns: Array<number>, path: number): void;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
export function readVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", path: number): number;
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
export function writeVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", v: number, path: number): void;
|
||||
export const COLOR_NORM: number;
|
||||
export const AXIS_MAP: Record<string, "x" | "y" | "z" | "w">;
|
||||
export const PATH_DIRECT: 0;
|
||||
export const KIND_COLOR: 0;
|
||||
export const KIND_SCALAR: 1;
|
||||
export const KIND_VECTOR: 2;
|
||||
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace } from 'three';
|
||||
import { degToRad } from '../../utils/number.js';
|
||||
|
||||
/**
|
||||
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
||||
*/
|
||||
|
||||
|
||||
const COLOR_NORM = 1 / 255;
|
||||
|
||||
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
||||
|
||||
const PATH_DIRECT = 0;
|
||||
const PATH_UNIFORM = 1;
|
||||
const PATH_NODE = 2;
|
||||
|
||||
const KIND_COLOR = 0;
|
||||
const KIND_SCALAR = 1;
|
||||
const KIND_VECTOR = 2;
|
||||
|
||||
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
||||
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
||||
|
||||
/**
|
||||
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
||||
*
|
||||
* @param {number[]} e
|
||||
* @param {number} skewX
|
||||
* @param {number} skewY
|
||||
* @param {number} skewZ
|
||||
* @param {number} ox
|
||||
* @param {number} oy
|
||||
* @param {number} oz
|
||||
*/
|
||||
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
||||
if (skewX !== 0) {
|
||||
const t = Math.tan(degToRad(skewX));
|
||||
e[4] += e[0] * t;
|
||||
e[5] += e[1] * t;
|
||||
e[6] += e[2] * t;
|
||||
}
|
||||
if (skewY !== 0) {
|
||||
const t = Math.tan(degToRad(skewY));
|
||||
e[0] += e[4] * t;
|
||||
e[1] += e[5] * t;
|
||||
e[2] += e[6] * t;
|
||||
}
|
||||
if (skewZ !== 0) {
|
||||
const t = Math.tan(degToRad(skewZ));
|
||||
e[0] += e[8] * t;
|
||||
e[1] += e[9] * t;
|
||||
e[2] += e[10] * t;
|
||||
}
|
||||
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
||||
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
||||
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
||||
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} c
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorHex(c) {
|
||||
return c ? `#${c.getHexString(SRGBColorSpace)}` : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
||||
*
|
||||
* @param {any} v
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isVectorWith(v, axis) {
|
||||
if (!v) return false;
|
||||
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
||||
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
||||
return !!v.isVector4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
||||
*
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
||||
*/
|
||||
function classifyTargetProp(target, name) {
|
||||
const value = target[name];
|
||||
if (value !== undefined) {
|
||||
if (value && value.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
if (value && value.isUniformNode) {
|
||||
// Route TSL slot writes through node value, booleans share the scalar entry.
|
||||
const v = value.value;
|
||||
if (v && v.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
if (typeof v === 'number' || typeof v === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (typeof value === 'number' || typeof value === 'boolean') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
||||
return desc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const uniforms = target.uniforms;
|
||||
const u = uniforms && uniforms[name];
|
||||
if (u) {
|
||||
const uv = u.value;
|
||||
if (uv && uv.isColor) {
|
||||
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
if (typeof uv === 'number') {
|
||||
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (axis) {
|
||||
const base = name.slice(0, -1);
|
||||
if (isVectorWith(target[base], axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const baseSlot = target[base];
|
||||
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
const ub = uniforms && uniforms[base];
|
||||
if (ub && isVectorWith(ub.value, axis)) {
|
||||
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function leafAt(target, name, path) {
|
||||
if (path === PATH_DIRECT) return target[name];
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
return e ? e.value : null;
|
||||
}
|
||||
const n = target[name];
|
||||
return n ? n.value : null;
|
||||
}
|
||||
|
||||
function writeLeafScalar(target, name, v, path) {
|
||||
if (path === PATH_DIRECT) { target[name] = v; return; }
|
||||
if (path === PATH_UNIFORM) {
|
||||
const u = target.uniforms;
|
||||
const e = u && u[name];
|
||||
if (e) e.value = v;
|
||||
return;
|
||||
}
|
||||
const n = target[name];
|
||||
if (n) n.value = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @param {number} [defaultValue]
|
||||
* @return {number}
|
||||
*/
|
||||
function readScalar(target, name, path, defaultValue) {
|
||||
if (defaultValue === undefined) defaultValue = 0;
|
||||
if (!target) return defaultValue;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
if (!first) return defaultValue;
|
||||
const v = leafAt(first, name, path);
|
||||
return v === undefined || v === null ? defaultValue : v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeScalar(target, name, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
||||
} else {
|
||||
writeLeafScalar(target, name, v, path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {number} path
|
||||
* @return {String | null}
|
||||
*/
|
||||
function readColorAt(target, name, path) {
|
||||
if (!target) return null;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
return readColorHex(first ? leafAt(first, name, path) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} name
|
||||
* @param {Array.<Number>} ns
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeColorAt(target, name, ns, path) {
|
||||
if (!target) return;
|
||||
const r = ns[0] * COLOR_NORM;
|
||||
const g = ns[1] * COLOR_NORM;
|
||||
const b = ns[2] * COLOR_NORM;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const c = leafAt(target[i], name, path);
|
||||
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
||||
}
|
||||
} else {
|
||||
const c = leafAt(target, name, path);
|
||||
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} path
|
||||
* @return {number}
|
||||
*/
|
||||
function readVectorAt(target, base, axis, path) {
|
||||
if (!target) return 0;
|
||||
const first = Array.isArray(target) ? target[0] : target;
|
||||
const vec = first ? leafAt(first, base, path) : null;
|
||||
return vec ? vec[axis] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} target
|
||||
* @param {string} base
|
||||
* @param {'x' | 'y' | 'z' | 'w'} axis
|
||||
* @param {number} v
|
||||
* @param {number} path
|
||||
*/
|
||||
function writeVectorAt(target, base, axis, v, path) {
|
||||
if (!target) return;
|
||||
if (Array.isArray(target)) {
|
||||
for (let i = 0, l = target.length; i < l; i++) {
|
||||
const vec = leafAt(target[i], base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
} else {
|
||||
const vec = leafAt(target, base, path);
|
||||
if (vec) vec[axis] = v;
|
||||
}
|
||||
}
|
||||
|
||||
export { AXIS_MAP, COLOR_NORM, KIND_COLOR, KIND_SCALAR, KIND_VECTOR, PATH_DIRECT, applySkewOrigin, classifyTargetProp, isVectorWith, readColorAt, readColorHex, readScalar, readVectorAt, writeColorAt, writeScalar, writeVectorAt };
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var adapter = require('./adapter.cjs');
|
||||
require('./resolvers.cjs');
|
||||
require('./uniform.cjs');
|
||||
require('./object3d.cjs');
|
||||
var instance = require('./instance.cjs');
|
||||
|
||||
|
||||
|
||||
exports.threeAdapter = adapter.threeAdapter;
|
||||
exports.commitChanges = instance.commitChanges;
|
||||
exports.getInstances = instance.getInstances;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { threeAdapter } from "./adapter.js";
|
||||
export { getInstances, commitChanges } from "./instance.js";
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { threeAdapter } from './adapter.js';
|
||||
import './resolvers.js';
|
||||
import './uniform.js';
|
||||
import './object3d.js';
|
||||
export { commitChanges, getInstances } from './instance.js';
|
||||
@@ -0,0 +1,368 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
const hasSkewOrigin = (t) => !!(t._skewX || t._skewY || t._skewZ || t._originX || t._originY || t._originZ);
|
||||
|
||||
/**
|
||||
* @import { Object3D, InstancedMesh } from 'three'
|
||||
*
|
||||
* @typedef {InstancedMesh | BatchedMesh} InstanceParent
|
||||
*/
|
||||
|
||||
const DIRTY_POS = 1;
|
||||
const DIRTY_ROT = 2;
|
||||
const DIRTY_SCALE = 4;
|
||||
const DIRTY_SKEW = 8;
|
||||
|
||||
/** @type {WeakMap<InstanceParent, InstanceBinding>} */
|
||||
const bindings = new WeakMap();
|
||||
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
class InstanceBinding {
|
||||
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh) {
|
||||
this.mesh = mesh;
|
||||
this.hasInstanceMatrix = 'instanceMatrix' in mesh;
|
||||
/** @type {(Instance | null)[]} */
|
||||
this.instances = [];
|
||||
/** @type {Instance[]} */
|
||||
this.dirtyList = [];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
this.userOnBeforeRender = mesh.onBeforeRender || null;
|
||||
this.chainedHandler = makeChainedHandler(this);
|
||||
Object.defineProperty(mesh, 'onBeforeRender', {
|
||||
configurable: true,
|
||||
get: () => this.chainedHandler,
|
||||
set: (fn) => { this.userOnBeforeRender = fn; },
|
||||
});
|
||||
}
|
||||
|
||||
flush() {
|
||||
const list = this.dirtyList;
|
||||
if (list.length === 0) return;
|
||||
for (let i = 0, l = list.length; i < l; i++) list[i]._flush();
|
||||
if (this.hasInstanceMatrix) /** @type {InstancedMesh} */(this.mesh).instanceMatrix.needsUpdate = true;
|
||||
list.length = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {Object3D['onBeforeRender']}
|
||||
*/
|
||||
function makeChainedHandler(binding) {
|
||||
return function (renderer, scene, camera, geometry, material, group) {
|
||||
binding.flush();
|
||||
const u = binding.userOnBeforeRender;
|
||||
if (u) u.call(binding.mesh, renderer, scene, camera, geometry, material, group);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
class Instance {
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding, id) {
|
||||
this.isAnimejsInstanceProxy = true;
|
||||
this.parent = binding.mesh;
|
||||
this.id = id;
|
||||
this._position = new three.Vector3();
|
||||
this._rotation = new three.Euler(0, 0, 0, 'XYZ');
|
||||
this._scale = new three.Vector3(1, 1, 1);
|
||||
this._matrix = new three.Matrix4();
|
||||
this._quat = new three.Quaternion();
|
||||
// Pre-allocate _color so the hidden class stays stable, set color mutates it in place rather than re-binding the field.
|
||||
this._color = new three.Color();
|
||||
this._dirty = 0;
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// applySkewOrigin computes Math.tan inline per non-zero axis, so we only carry the user-facing angle here.
|
||||
this._skewX = 0;
|
||||
this._skewY = 0;
|
||||
this._skewZ = 0;
|
||||
this._originX = 0;
|
||||
this._originY = 0;
|
||||
this._originZ = 0;
|
||||
// Skip the position-only fast path in _flush whenever any skew or origin is non-zero, since both modify the matrix beyond pure translation.
|
||||
this._hasSkewOrigin = false;
|
||||
// Cache the binding dirty queue once so per-frame setters skip a property hop.
|
||||
/** @type {Instance[]} */
|
||||
this._dirtyList = binding.dirtyList;
|
||||
// Cache parent capability flags once so per-frame setters skip prototype-chain in checks.
|
||||
const parent = binding.mesh;
|
||||
this._hasSetColor = 'setColorAt' in parent;
|
||||
this._hasSetVisible = 'setVisibleAt' in parent;
|
||||
this._hasGetVisible = 'getVisibleAt' in parent;
|
||||
|
||||
parent.getMatrixAt(id, this._matrix);
|
||||
if (this._matrix.elements[15] === 0) this._matrix.identity();
|
||||
this._matrix.decompose(this._position, this._quat, this._scale);
|
||||
this._rotation.setFromQuaternion(this._quat, 'XYZ');
|
||||
|
||||
if ('getColorAt' in parent && 'instanceColor' in parent && parent.instanceColor) {
|
||||
parent.getColorAt(id, this._color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag) {
|
||||
// Enqueue once per frame, later flags only OR into _dirty without re-pushing to the queue.
|
||||
if (this._dirty === 0) this._dirtyList.push(this);
|
||||
this._dirty |= flag;
|
||||
}
|
||||
|
||||
_flush() {
|
||||
const d = this._dirty;
|
||||
if (!d) return;
|
||||
const m = this._matrix;
|
||||
const p = this._position;
|
||||
if (d === DIRTY_POS && !this._hasSkewOrigin) {
|
||||
const e = m.elements;
|
||||
e[12] = p.x; e[13] = p.y; e[14] = p.z;
|
||||
} else {
|
||||
const q = this._quat;
|
||||
if (d & DIRTY_ROT) q.setFromEuler(this._rotation);
|
||||
m.compose(p, q, this._scale);
|
||||
if (this._hasSkewOrigin) {
|
||||
helpers.applySkewOrigin(m.elements, this._skewX, this._skewY, this._skewZ, this._originX, this._originY, this._originZ);
|
||||
}
|
||||
}
|
||||
this.parent.setMatrixAt(this.id, m);
|
||||
this._dirty = 0;
|
||||
}
|
||||
|
||||
get x() { return this._position.x; }
|
||||
set x(v) { this._position.x = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get y() { return this._position.y; }
|
||||
set y(v) { this._position.y = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get z() { return this._position.z; }
|
||||
set z(v) { this._position.z = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get rotateX() { return number.radToDeg(this._rotation.x); }
|
||||
set rotateX(v) { this._rotation.x = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateY() { return number.radToDeg(this._rotation.y); }
|
||||
set rotateY(v) { this._rotation.y = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateZ() { return number.radToDeg(this._rotation.z); }
|
||||
set rotateZ(v) { this._rotation.z = number.degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get scaleX() { return this._scale.x; }
|
||||
set scaleX(v) { this._scale.x = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleY() { return this._scale.y; }
|
||||
set scaleY(v) { this._scale.y = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleZ() { return this._scale.z; }
|
||||
set scaleZ(v) { this._scale.z = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scale() { return this._scale.x; }
|
||||
set scale(v) {
|
||||
const s = this._scale;
|
||||
s.x = v; s.y = v; s.z = v;
|
||||
this._markDirty(DIRTY_SCALE);
|
||||
}
|
||||
|
||||
get skewX() { return this._skewX; }
|
||||
set skewX(v) {
|
||||
this._skewX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewY() { return this._skewY; }
|
||||
set skewY(v) {
|
||||
this._skewY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewZ() { return this._skewZ; }
|
||||
set skewZ(v) {
|
||||
this._skewZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginX() { return this._originX; }
|
||||
set transformOriginX(v) {
|
||||
this._originX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginY() { return this._originY; }
|
||||
set transformOriginY(v) {
|
||||
this._originY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginZ() { return this._originZ; }
|
||||
set transformOriginZ(v) {
|
||||
this._originZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get opacity() {
|
||||
return helpers.readScalar(/** @type {any} */(this.parent).material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
}
|
||||
/** @param {number} v */
|
||||
set opacity(v) {
|
||||
helpers.writeScalar(/** @type {any} */(this.parent).material, 'opacity', v, helpers.PATH_DIRECT);
|
||||
}
|
||||
|
||||
get visible() {
|
||||
return this._hasGetVisible ? /** @type {any} */(this.parent).getVisibleAt(this.id) : true;
|
||||
}
|
||||
/** @param {boolean} v */
|
||||
set visible(v) {
|
||||
if (this._hasSetVisible) /** @type {any} */(this.parent).setVisibleAt(this.id, v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
function commitChanges(mesh) {
|
||||
const binding = bindings.get(mesh);
|
||||
if (binding) binding.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function getInstances(mesh) {
|
||||
let binding = bindings.get(mesh);
|
||||
if (!binding) {
|
||||
binding = new InstanceBinding(mesh);
|
||||
bindings.set(mesh, binding);
|
||||
}
|
||||
if (mesh instanceof three.BatchedMesh) {
|
||||
return refreshBatched(binding);
|
||||
}
|
||||
return refreshInstanced(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshInstanced(binding) {
|
||||
const mesh = /** @type {InstancedMesh} */(binding.mesh);
|
||||
const count = mesh.count;
|
||||
const arr = binding.instances;
|
||||
if (arr.length === 0 && count > 0) {
|
||||
arr.length = count;
|
||||
for (let i = 0; i < count; i++) arr[i] = new Instance(binding, i);
|
||||
return arr;
|
||||
}
|
||||
if (arr.length < count) {
|
||||
for (let i = arr.length; i < count; i++) arr.push(new Instance(binding, i));
|
||||
} else if (arr.length > count) {
|
||||
arr.length = count;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshBatched(binding) {
|
||||
const mesh = /** @type {BatchedMesh} */(binding.mesh);
|
||||
const arr = binding.instances;
|
||||
// Read three internal _instanceInfo to skip slots marked inactive by deleteInstance.
|
||||
// Iterate the full slot count, not instanceCount, since deleted slots leave gaps but live ids past them must still be visited.
|
||||
const instanceInfo = /** @type {{ _instanceInfo?: { active: boolean }[] }} */(mesh)._instanceInfo ?? [];
|
||||
const len = instanceInfo.length;
|
||||
if (arr.length < len) arr.length = len;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const info = instanceInfo[i];
|
||||
const inactive = info && info.active === false;
|
||||
if (inactive) {
|
||||
arr[i] = null;
|
||||
} else if (!arr[i]) {
|
||||
arr[i] = new Instance(binding, i);
|
||||
}
|
||||
}
|
||||
if (arr.length > len) arr.length = len;
|
||||
return arr;
|
||||
}
|
||||
|
||||
const instanceAdapter = adapter.threeAdapter.registerTargetAdapter((t) => t instanceof Instance);
|
||||
instanceAdapter.registerProperty('color',
|
||||
(t) => helpers.readColorHex(t._color),
|
||||
(t, _, tw) => {
|
||||
if (!t._hasSetColor) return;
|
||||
const ns = tw._numbers;
|
||||
t._color.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
const p = /** @type {any} */(t.parent);
|
||||
p.setColorAt(t.id, t._color);
|
||||
if (p.instanceColor) p.instanceColor.needsUpdate = true;
|
||||
},
|
||||
);
|
||||
// Shorthand 3-token string x y z routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
instanceAdapter.registerProperty('transformOrigin',
|
||||
(t) => `${t._originX} ${t._originY} ${t._originZ}`,
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t._originX = ns[0];
|
||||
t._originY = ns[1];
|
||||
t._originZ = ns[2];
|
||||
t._hasSkewOrigin = hasSkewOrigin(t);
|
||||
t._markDirty(DIRTY_SKEW);
|
||||
},
|
||||
);
|
||||
|
||||
exports.commitChanges = commitChanges;
|
||||
exports.getInstances = getInstances;
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
export function commitChanges(mesh: InstanceParent): void;
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
export function getInstances(mesh: InstanceParent): (Instance | null)[];
|
||||
export type InstanceParent = InstancedMesh | BatchedMesh;
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
declare class Instance {
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding: InstanceBinding, id: number);
|
||||
isAnimejsInstanceProxy: boolean;
|
||||
parent: InstanceParent;
|
||||
id: number;
|
||||
_position: Vector3;
|
||||
_rotation: Euler;
|
||||
_scale: Vector3;
|
||||
_matrix: Matrix4;
|
||||
_quat: Quaternion;
|
||||
_color: Color;
|
||||
_dirty: number;
|
||||
_skewX: number;
|
||||
_skewY: number;
|
||||
_skewZ: number;
|
||||
_originX: number;
|
||||
_originY: number;
|
||||
_originZ: number;
|
||||
_hasSkewOrigin: boolean;
|
||||
/** @type {Instance[]} */
|
||||
_dirtyList: Instance[];
|
||||
_hasSetColor: boolean;
|
||||
_hasSetVisible: boolean;
|
||||
_hasGetVisible: boolean;
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag: number): void;
|
||||
_flush(): void;
|
||||
set x(v: number);
|
||||
get x(): number;
|
||||
set y(v: number);
|
||||
get y(): number;
|
||||
set z(v: number);
|
||||
get z(): number;
|
||||
set rotateX(v: number);
|
||||
get rotateX(): number;
|
||||
set rotateY(v: number);
|
||||
get rotateY(): number;
|
||||
set rotateZ(v: number);
|
||||
get rotateZ(): number;
|
||||
set scaleX(v: number);
|
||||
get scaleX(): number;
|
||||
set scaleY(v: number);
|
||||
get scaleY(): number;
|
||||
set scaleZ(v: number);
|
||||
get scaleZ(): number;
|
||||
set scale(v: number);
|
||||
get scale(): number;
|
||||
set skewX(v: number);
|
||||
get skewX(): number;
|
||||
set skewY(v: number);
|
||||
get skewY(): number;
|
||||
set skewZ(v: number);
|
||||
get skewZ(): number;
|
||||
set transformOriginX(v: number);
|
||||
get transformOriginX(): number;
|
||||
set transformOriginY(v: number);
|
||||
get transformOriginY(): number;
|
||||
set transformOriginZ(v: number);
|
||||
get transformOriginZ(): number;
|
||||
/** @param {number} v */
|
||||
set opacity(v: number);
|
||||
get opacity(): number;
|
||||
/** @param {boolean} v */
|
||||
set visible(v: boolean);
|
||||
get visible(): boolean;
|
||||
}
|
||||
import type { InstancedMesh } from 'three';
|
||||
import { BatchedMesh } from 'three';
|
||||
import { Vector3 } from 'three';
|
||||
import { Euler } from 'three';
|
||||
import { Matrix4 } from 'three';
|
||||
import { Quaternion } from 'three';
|
||||
import { Color } from 'three';
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
declare class InstanceBinding {
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh: InstanceParent);
|
||||
mesh: InstanceParent;
|
||||
hasInstanceMatrix: boolean;
|
||||
/** @type {(Instance | null)[]} */
|
||||
instances: (Instance | null)[];
|
||||
/** @type {Instance[]} */
|
||||
dirtyList: Instance[];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
userOnBeforeRender: Object3D["onBeforeRender"] | null;
|
||||
chainedHandler: (renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry, material: import("three").Material, group: import("three").Group) => void;
|
||||
flush(): void;
|
||||
}
|
||||
import type { Object3D } from 'three';
|
||||
export {};
|
||||
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace, Vector3, Euler, Matrix4, Quaternion, Color, BatchedMesh } from 'three';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readColorHex, COLOR_NORM, applySkewOrigin, readScalar, PATH_DIRECT, writeScalar } from './helpers.js';
|
||||
|
||||
const hasSkewOrigin = (t) => !!(t._skewX || t._skewY || t._skewZ || t._originX || t._originY || t._originZ);
|
||||
|
||||
/**
|
||||
* @import { Object3D, InstancedMesh } from 'three'
|
||||
*
|
||||
* @typedef {InstancedMesh | BatchedMesh} InstanceParent
|
||||
*/
|
||||
|
||||
const DIRTY_POS = 1;
|
||||
const DIRTY_ROT = 2;
|
||||
const DIRTY_SCALE = 4;
|
||||
const DIRTY_SKEW = 8;
|
||||
|
||||
/** @type {WeakMap<InstanceParent, InstanceBinding>} */
|
||||
const bindings = new WeakMap();
|
||||
|
||||
/**
|
||||
* Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
|
||||
*/
|
||||
class InstanceBinding {
|
||||
|
||||
/** @param {InstanceParent} mesh */
|
||||
constructor(mesh) {
|
||||
this.mesh = mesh;
|
||||
this.hasInstanceMatrix = 'instanceMatrix' in mesh;
|
||||
/** @type {(Instance | null)[]} */
|
||||
this.instances = [];
|
||||
/** @type {Instance[]} */
|
||||
this.dirtyList = [];
|
||||
/** @type {Object3D['onBeforeRender'] | null} */
|
||||
this.userOnBeforeRender = mesh.onBeforeRender || null;
|
||||
this.chainedHandler = makeChainedHandler(this);
|
||||
Object.defineProperty(mesh, 'onBeforeRender', {
|
||||
configurable: true,
|
||||
get: () => this.chainedHandler,
|
||||
set: (fn) => { this.userOnBeforeRender = fn; },
|
||||
});
|
||||
}
|
||||
|
||||
flush() {
|
||||
const list = this.dirtyList;
|
||||
if (list.length === 0) return;
|
||||
for (let i = 0, l = list.length; i < l; i++) list[i]._flush();
|
||||
if (this.hasInstanceMatrix) /** @type {InstancedMesh} */(this.mesh).instanceMatrix.needsUpdate = true;
|
||||
list.length = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {Object3D['onBeforeRender']}
|
||||
*/
|
||||
function makeChainedHandler(binding) {
|
||||
return function (renderer, scene, camera, geometry, material, group) {
|
||||
binding.flush();
|
||||
const u = binding.userOnBeforeRender;
|
||||
if (u) u.call(binding.mesh, renderer, scene, camera, geometry, material, group);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
|
||||
*
|
||||
* Caveats:
|
||||
* - `opacity` writes the parent's shared material, every instance is affected.
|
||||
* - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
|
||||
*/
|
||||
class Instance {
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @param {number} id
|
||||
*/
|
||||
constructor(binding, id) {
|
||||
this.isAnimejsInstanceProxy = true;
|
||||
this.parent = binding.mesh;
|
||||
this.id = id;
|
||||
this._position = new Vector3();
|
||||
this._rotation = new Euler(0, 0, 0, 'XYZ');
|
||||
this._scale = new Vector3(1, 1, 1);
|
||||
this._matrix = new Matrix4();
|
||||
this._quat = new Quaternion();
|
||||
// Pre-allocate _color so the hidden class stays stable, set color mutates it in place rather than re-binding the field.
|
||||
this._color = new Color();
|
||||
this._dirty = 0;
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// applySkewOrigin computes Math.tan inline per non-zero axis, so we only carry the user-facing angle here.
|
||||
this._skewX = 0;
|
||||
this._skewY = 0;
|
||||
this._skewZ = 0;
|
||||
this._originX = 0;
|
||||
this._originY = 0;
|
||||
this._originZ = 0;
|
||||
// Skip the position-only fast path in _flush whenever any skew or origin is non-zero, since both modify the matrix beyond pure translation.
|
||||
this._hasSkewOrigin = false;
|
||||
// Cache the binding dirty queue once so per-frame setters skip a property hop.
|
||||
/** @type {Instance[]} */
|
||||
this._dirtyList = binding.dirtyList;
|
||||
// Cache parent capability flags once so per-frame setters skip prototype-chain in checks.
|
||||
const parent = binding.mesh;
|
||||
this._hasSetColor = 'setColorAt' in parent;
|
||||
this._hasSetVisible = 'setVisibleAt' in parent;
|
||||
this._hasGetVisible = 'getVisibleAt' in parent;
|
||||
|
||||
parent.getMatrixAt(id, this._matrix);
|
||||
if (this._matrix.elements[15] === 0) this._matrix.identity();
|
||||
this._matrix.decompose(this._position, this._quat, this._scale);
|
||||
this._rotation.setFromQuaternion(this._quat, 'XYZ');
|
||||
|
||||
if ('getColorAt' in parent && 'instanceColor' in parent && parent.instanceColor) {
|
||||
parent.getColorAt(id, this._color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} flag
|
||||
*/
|
||||
_markDirty(flag) {
|
||||
// Enqueue once per frame, later flags only OR into _dirty without re-pushing to the queue.
|
||||
if (this._dirty === 0) this._dirtyList.push(this);
|
||||
this._dirty |= flag;
|
||||
}
|
||||
|
||||
_flush() {
|
||||
const d = this._dirty;
|
||||
if (!d) return;
|
||||
const m = this._matrix;
|
||||
const p = this._position;
|
||||
if (d === DIRTY_POS && !this._hasSkewOrigin) {
|
||||
const e = m.elements;
|
||||
e[12] = p.x; e[13] = p.y; e[14] = p.z;
|
||||
} else {
|
||||
const q = this._quat;
|
||||
if (d & DIRTY_ROT) q.setFromEuler(this._rotation);
|
||||
m.compose(p, q, this._scale);
|
||||
if (this._hasSkewOrigin) {
|
||||
applySkewOrigin(m.elements, this._skewX, this._skewY, this._skewZ, this._originX, this._originY, this._originZ);
|
||||
}
|
||||
}
|
||||
this.parent.setMatrixAt(this.id, m);
|
||||
this._dirty = 0;
|
||||
}
|
||||
|
||||
get x() { return this._position.x; }
|
||||
set x(v) { this._position.x = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get y() { return this._position.y; }
|
||||
set y(v) { this._position.y = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get z() { return this._position.z; }
|
||||
set z(v) { this._position.z = v; this._markDirty(DIRTY_POS); }
|
||||
|
||||
get rotateX() { return radToDeg(this._rotation.x); }
|
||||
set rotateX(v) { this._rotation.x = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateY() { return radToDeg(this._rotation.y); }
|
||||
set rotateY(v) { this._rotation.y = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get rotateZ() { return radToDeg(this._rotation.z); }
|
||||
set rotateZ(v) { this._rotation.z = degToRad(v); this._markDirty(DIRTY_ROT); }
|
||||
|
||||
get scaleX() { return this._scale.x; }
|
||||
set scaleX(v) { this._scale.x = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleY() { return this._scale.y; }
|
||||
set scaleY(v) { this._scale.y = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scaleZ() { return this._scale.z; }
|
||||
set scaleZ(v) { this._scale.z = v; this._markDirty(DIRTY_SCALE); }
|
||||
|
||||
get scale() { return this._scale.x; }
|
||||
set scale(v) {
|
||||
const s = this._scale;
|
||||
s.x = v; s.y = v; s.z = v;
|
||||
this._markDirty(DIRTY_SCALE);
|
||||
}
|
||||
|
||||
get skewX() { return this._skewX; }
|
||||
set skewX(v) {
|
||||
this._skewX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewY() { return this._skewY; }
|
||||
set skewY(v) {
|
||||
this._skewY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get skewZ() { return this._skewZ; }
|
||||
set skewZ(v) {
|
||||
this._skewZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginX() { return this._originX; }
|
||||
set transformOriginX(v) {
|
||||
this._originX = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginY() { return this._originY; }
|
||||
set transformOriginY(v) {
|
||||
this._originY = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get transformOriginZ() { return this._originZ; }
|
||||
set transformOriginZ(v) {
|
||||
this._originZ = v;
|
||||
this._hasSkewOrigin = hasSkewOrigin(this);
|
||||
this._markDirty(DIRTY_SKEW);
|
||||
}
|
||||
|
||||
get opacity() {
|
||||
return readScalar(/** @type {any} */(this.parent).material, 'opacity', PATH_DIRECT, 1);
|
||||
}
|
||||
/** @param {number} v */
|
||||
set opacity(v) {
|
||||
writeScalar(/** @type {any} */(this.parent).material, 'opacity', v, PATH_DIRECT);
|
||||
}
|
||||
|
||||
get visible() {
|
||||
return this._hasGetVisible ? /** @type {any} */(this.parent).getVisibleAt(this.id) : true;
|
||||
}
|
||||
/** @param {boolean} v */
|
||||
set visible(v) {
|
||||
if (this._hasSetVisible) /** @type {any} */(this.parent).setVisibleAt(this.id, v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes pending matrix writes for every dirty instance of `mesh`.
|
||||
* Called automatically before each render. Call it yourself if you read
|
||||
* `mesh.instanceMatrix` between an animation tick and the next render.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
*/
|
||||
function commitChanges(mesh) {
|
||||
const binding = bindings.get(mesh);
|
||||
if (binding) binding.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
|
||||
*
|
||||
* animate(getInstances(mesh), { x: 100, delay: stagger(5) });
|
||||
* animate(getInstances(mesh)[42], { scale: 2 });
|
||||
*
|
||||
* The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
|
||||
*
|
||||
* `mesh.onBeforeRender` is replaced with an accessor that flushes
|
||||
* pending instance writes before each render and forwards to your
|
||||
* handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
|
||||
* auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
|
||||
* chained dispatcher rather than `fn` itself, so identity checks
|
||||
* (`mesh.onBeforeRender === fn`) will not match.
|
||||
*
|
||||
* @param {InstanceParent} mesh
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function getInstances(mesh) {
|
||||
let binding = bindings.get(mesh);
|
||||
if (!binding) {
|
||||
binding = new InstanceBinding(mesh);
|
||||
bindings.set(mesh, binding);
|
||||
}
|
||||
if (mesh instanceof BatchedMesh) {
|
||||
return refreshBatched(binding);
|
||||
}
|
||||
return refreshInstanced(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshInstanced(binding) {
|
||||
const mesh = /** @type {InstancedMesh} */(binding.mesh);
|
||||
const count = mesh.count;
|
||||
const arr = binding.instances;
|
||||
if (arr.length === 0 && count > 0) {
|
||||
arr.length = count;
|
||||
for (let i = 0; i < count; i++) arr[i] = new Instance(binding, i);
|
||||
return arr;
|
||||
}
|
||||
if (arr.length < count) {
|
||||
for (let i = arr.length; i < count; i++) arr.push(new Instance(binding, i));
|
||||
} else if (arr.length > count) {
|
||||
arr.length = count;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InstanceBinding} binding
|
||||
* @return {(Instance | null)[]}
|
||||
*/
|
||||
function refreshBatched(binding) {
|
||||
const mesh = /** @type {BatchedMesh} */(binding.mesh);
|
||||
const arr = binding.instances;
|
||||
// Read three internal _instanceInfo to skip slots marked inactive by deleteInstance.
|
||||
// Iterate the full slot count, not instanceCount, since deleted slots leave gaps but live ids past them must still be visited.
|
||||
const instanceInfo = /** @type {{ _instanceInfo?: { active: boolean }[] }} */(mesh)._instanceInfo ?? [];
|
||||
const len = instanceInfo.length;
|
||||
if (arr.length < len) arr.length = len;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const info = instanceInfo[i];
|
||||
const inactive = info && info.active === false;
|
||||
if (inactive) {
|
||||
arr[i] = null;
|
||||
} else if (!arr[i]) {
|
||||
arr[i] = new Instance(binding, i);
|
||||
}
|
||||
}
|
||||
if (arr.length > len) arr.length = len;
|
||||
return arr;
|
||||
}
|
||||
|
||||
const instanceAdapter = threeAdapter.registerTargetAdapter((t) => t instanceof Instance);
|
||||
instanceAdapter.registerProperty('color',
|
||||
(t) => readColorHex(t._color),
|
||||
(t, _, tw) => {
|
||||
if (!t._hasSetColor) return;
|
||||
const ns = tw._numbers;
|
||||
t._color.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
const p = /** @type {any} */(t.parent);
|
||||
p.setColorAt(t.id, t._color);
|
||||
if (p.instanceColor) p.instanceColor.needsUpdate = true;
|
||||
},
|
||||
);
|
||||
// Shorthand 3-token string x y z routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
instanceAdapter.registerProperty('transformOrigin',
|
||||
(t) => `${t._originX} ${t._originY} ${t._originZ}`,
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t._originX = ns[0];
|
||||
t._originY = ns[1];
|
||||
t._originZ = ns[2];
|
||||
t._hasSkewOrigin = hasSkewOrigin(t);
|
||||
t._markDirty(DIRTY_SKEW);
|
||||
},
|
||||
);
|
||||
|
||||
export { commitChanges, getInstances };
|
||||
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* `Object3D` adapter. Maps flat properties (position, rotation, scale, opacity, color, visible, light / audio / camera specifics) onto the matching three.js fields, and auto-detects material props (direct / uniform / TSL `UniformNode`) on the target's `material` at tween creation.
|
||||
*/
|
||||
|
||||
|
||||
const colorTarget = (t) => t.isLight ? t : t.material;
|
||||
|
||||
// Per-mesh skew and transformOrigin state, stored under a private symbol so we add one hidden property instead of polluting the Object3D surface with seven underscored fields.
|
||||
const skewSymbol = Symbol('animejs.skewOrigin');
|
||||
|
||||
// Fallback opacity storage for Object3D targets without a material such as Groups or CSS2DObjects.
|
||||
// Without it reads always return the default 1, so reverse-direction tweens between two non-default values collapse to a no-op delta and the visibility flip never fires on the way back.
|
||||
const opacitySymbol = Symbol('animejs.opacity');
|
||||
|
||||
/**
|
||||
* Sets `o.visible` based on opacity and current scale. If `opacity` is omitted, reads it from `o.material` (defaults to `1` when no material is present).
|
||||
*
|
||||
* @param {Object3D & { material?: import('three').Material | import('three').Material[] }} o
|
||||
* @param {number} [opacity]
|
||||
*/
|
||||
function setVisibility(o, opacity) {
|
||||
if (opacity === undefined) {
|
||||
if (o.material) {
|
||||
opacity = helpers.readScalar(o.material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
} else {
|
||||
const v = o[opacitySymbol];
|
||||
opacity = v === undefined ? 1 : v;
|
||||
}
|
||||
}
|
||||
const s = o.scale;
|
||||
o.visible = !!(opacity && s.x && s.y && s.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a per-mesh `updateMatrix` override on first skew / transformOrigin write. The override calls the original three.js compose, then patches the result with `applySkewOrigin` whenever any axis is non-zero. Idempotent.
|
||||
*
|
||||
* @param {any} mesh
|
||||
* @return {{ skewX: number, skewY: number, skewZ: number, originX: number, originY: number, originZ: number }}
|
||||
*/
|
||||
function installSkewMatrix(mesh) {
|
||||
let s = mesh[skewSymbol];
|
||||
if (s) return s;
|
||||
s = mesh[skewSymbol] = { skewX: 0, skewY: 0, skewZ: 0, originX: 0, originY: 0, originZ: 0 };
|
||||
const original = mesh.updateMatrix;
|
||||
mesh.updateMatrix = function () {
|
||||
original.call(this);
|
||||
const st = this[skewSymbol];
|
||||
if (st.skewX !== 0 || st.skewY !== 0 || st.skewZ !== 0 || st.originX !== 0 || st.originY !== 0 || st.originZ !== 0) {
|
||||
helpers.applySkewOrigin(this.matrix.elements, st.skewX, st.skewY, st.skewZ, st.originX, st.originY, st.originZ);
|
||||
}
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
const threeObject3D = adapter.threeAdapter.registerTargetAdapter((t) => t instanceof three.Object3D);
|
||||
|
||||
// Position
|
||||
threeObject3D.registerProperty('x', (t) => t.position.x, (t, v) => { t.position.x = v; });
|
||||
threeObject3D.registerProperty('y', (t) => t.position.y, (t, v) => { t.position.y = v; });
|
||||
threeObject3D.registerProperty('z', (t) => t.position.z, (t, v) => { t.position.z = v; });
|
||||
|
||||
// Rotation in degrees
|
||||
threeObject3D.registerProperty('rotateX', (t) => number.radToDeg(t.rotation.x), (t, v) => { t.rotation.x = number.degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateY', (t) => number.radToDeg(t.rotation.y), (t, v) => { t.rotation.y = number.degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateZ', (t) => number.radToDeg(t.rotation.z), (t, v) => { t.rotation.z = number.degToRad(v); });
|
||||
|
||||
// Scale per-axis and uniform
|
||||
threeObject3D.registerProperty('scaleX', (t) => t.scale.x, (t, v) => { t.scale.x = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleY', (t) => t.scale.y, (t, v) => { t.scale.y = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleZ', (t) => t.scale.z, (t, v) => { t.scale.z = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scale',
|
||||
(t) => t.scale.x,
|
||||
(t, v) => {
|
||||
t.scale.x = v; t.scale.y = v; t.scale.z = v;
|
||||
setVisibility(t);
|
||||
},
|
||||
);
|
||||
|
||||
// Material
|
||||
threeObject3D.registerProperty('visible', (t) => t.visible, (t, v) => { t.visible = !!v; });
|
||||
threeObject3D.registerProperty('opacity',
|
||||
(t) => {
|
||||
if (t.material) return helpers.readScalar(t.material, 'opacity', helpers.PATH_DIRECT, 1);
|
||||
const v = t[opacitySymbol];
|
||||
return v === undefined ? 1 : v;
|
||||
},
|
||||
(t, v) => {
|
||||
if (t.material) helpers.writeScalar(t.material, 'opacity', v, helpers.PATH_DIRECT);
|
||||
else t[opacitySymbol] = v;
|
||||
setVisibility(t, v);
|
||||
},
|
||||
(t) => !t.isLight,
|
||||
);
|
||||
threeObject3D.registerProperty('color',
|
||||
(t) => helpers.readColorAt(colorTarget(t), 'color', helpers.PATH_DIRECT),
|
||||
(t, _, tw) => helpers.writeColorAt(colorTarget(t), 'color', tw._numbers, helpers.PATH_DIRECT),
|
||||
);
|
||||
|
||||
// HemisphereLight
|
||||
threeObject3D.registerProperty('groundColor',
|
||||
(t) => helpers.readColorAt(t, 'groundColor', helpers.PATH_DIRECT),
|
||||
(t, _, tw) => helpers.writeColorAt(t, 'groundColor', tw._numbers, helpers.PATH_DIRECT),
|
||||
(t) => !!t.groundColor,
|
||||
);
|
||||
|
||||
// Scene background, lazily initializes scene background to a Color on first write so the user does not have to set one upfront.
|
||||
threeObject3D.registerProperty('background',
|
||||
(t) => {
|
||||
const bg = /** @type {any} */(t).background;
|
||||
return bg && bg.isColor ? helpers.readColorHex(bg) : '#000000';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const scene = /** @type {any} */(t);
|
||||
let bg = scene.background;
|
||||
if (!bg || !bg.isColor) {
|
||||
bg = new three.Color();
|
||||
scene.background = bg;
|
||||
}
|
||||
const ns = tw._numbers;
|
||||
bg.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
},
|
||||
(t) => !!t.isScene,
|
||||
);
|
||||
|
||||
// Method-bridged props for Audio and PerspectiveCamera focalLength, read via getXxx and write via setXxx.
|
||||
const registerMethodProp = (apiName, getter, setter, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[getter](),
|
||||
(t, v) => { t[setter](v); },
|
||||
(t) => !!t[gate],
|
||||
);
|
||||
};
|
||||
registerMethodProp('volume', 'getVolume', 'setVolume', 'setVolume');
|
||||
// PositionalAudio
|
||||
registerMethodProp('refDistance', 'getRefDistance', 'setRefDistance', 'setRefDistance');
|
||||
registerMethodProp('rolloffFactor', 'getRolloffFactor', 'setRolloffFactor', 'setRefDistance');
|
||||
registerMethodProp('maxDistance', 'getMaxDistance', 'setMaxDistance', 'setRefDistance');
|
||||
// PerspectiveCamera
|
||||
registerMethodProp('focalLength', 'getFocalLength', 'setFocalLength', 'setFocalLength');
|
||||
|
||||
// Camera projection-update props, setter writes the value then calls updateProjectionMatrix.
|
||||
const registerCameraProp = (apiName, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[apiName],
|
||||
(t, v) => { t[apiName] = v; t.updateProjectionMatrix(); },
|
||||
gate,
|
||||
);
|
||||
};
|
||||
const isPersp = (t) => !!t.isPerspectiveCamera;
|
||||
const isOrtho = (t) => !!t.isOrthographicCamera;
|
||||
registerCameraProp('fov', isPersp);
|
||||
registerCameraProp('aspect', isPersp);
|
||||
registerCameraProp('left', isOrtho);
|
||||
registerCameraProp('right', isOrtho);
|
||||
registerCameraProp('top', isOrtho);
|
||||
registerCameraProp('bottom', isOrtho);
|
||||
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// Patches mesh updateMatrix on first write so the standard PRS compose is followed by an in-place skew and origin shift.
|
||||
// Reads default to 0 for meshes that have never been written.
|
||||
/**
|
||||
* @param {String} apiName
|
||||
* @param {String} key
|
||||
*/
|
||||
const registerSkewProp = (apiName, key) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => { const s = /** @type {any} */(t)[skewSymbol]; return s ? s[key] : 0; },
|
||||
(t, v) => { installSkewMatrix(t)[key] = v; },
|
||||
);
|
||||
};
|
||||
registerSkewProp('skewX', 'skewX');
|
||||
registerSkewProp('skewY', 'skewY');
|
||||
registerSkewProp('skewZ', 'skewZ');
|
||||
registerSkewProp('transformOriginX', 'originX');
|
||||
registerSkewProp('transformOriginY', 'originY');
|
||||
registerSkewProp('transformOriginZ', 'originZ');
|
||||
|
||||
// Shorthand 3-token string x y z or 2-string from-to array routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
threeObject3D.registerProperty('transformOrigin',
|
||||
(t) => {
|
||||
const s = /** @type {any} */(t)[skewSymbol];
|
||||
return s ? `${s.originX} ${s.originY} ${s.originZ}` : '0 0 0';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const s = installSkewMatrix(t);
|
||||
const ns = tw._numbers;
|
||||
s.originX = ns[0];
|
||||
s.originY = ns[1];
|
||||
s.originZ = ns[2];
|
||||
},
|
||||
);
|
||||
|
||||
// Shared by both camera types.
|
||||
const isCamera = (t) => !!t.isPerspectiveCamera || !!t.isOrthographicCamera;
|
||||
registerCameraProp('near', isCamera);
|
||||
registerCameraProp('far', isCamera);
|
||||
registerCameraProp('zoom', isCamera);
|
||||
|
||||
// Auto-detection for material props on meshes and direct Vector / Color fields on the target is provided by the shared resolvers in resolvers.js.
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { Object3D, Color, SRGBColorSpace } from 'three';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readScalar, PATH_DIRECT, writeScalar, readColorAt, writeColorAt, readColorHex, COLOR_NORM, applySkewOrigin } from './helpers.js';
|
||||
|
||||
/**
|
||||
* `Object3D` adapter. Maps flat properties (position, rotation, scale, opacity, color, visible, light / audio / camera specifics) onto the matching three.js fields, and auto-detects material props (direct / uniform / TSL `UniformNode`) on the target's `material` at tween creation.
|
||||
*/
|
||||
|
||||
|
||||
const colorTarget = (t) => t.isLight ? t : t.material;
|
||||
|
||||
// Per-mesh skew and transformOrigin state, stored under a private symbol so we add one hidden property instead of polluting the Object3D surface with seven underscored fields.
|
||||
const skewSymbol = Symbol('animejs.skewOrigin');
|
||||
|
||||
// Fallback opacity storage for Object3D targets without a material such as Groups or CSS2DObjects.
|
||||
// Without it reads always return the default 1, so reverse-direction tweens between two non-default values collapse to a no-op delta and the visibility flip never fires on the way back.
|
||||
const opacitySymbol = Symbol('animejs.opacity');
|
||||
|
||||
/**
|
||||
* Sets `o.visible` based on opacity and current scale. If `opacity` is omitted, reads it from `o.material` (defaults to `1` when no material is present).
|
||||
*
|
||||
* @param {Object3D & { material?: import('three').Material | import('three').Material[] }} o
|
||||
* @param {number} [opacity]
|
||||
*/
|
||||
function setVisibility(o, opacity) {
|
||||
if (opacity === undefined) {
|
||||
if (o.material) {
|
||||
opacity = readScalar(o.material, 'opacity', PATH_DIRECT, 1);
|
||||
} else {
|
||||
const v = o[opacitySymbol];
|
||||
opacity = v === undefined ? 1 : v;
|
||||
}
|
||||
}
|
||||
const s = o.scale;
|
||||
o.visible = !!(opacity && s.x && s.y && s.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a per-mesh `updateMatrix` override on first skew / transformOrigin write. The override calls the original three.js compose, then patches the result with `applySkewOrigin` whenever any axis is non-zero. Idempotent.
|
||||
*
|
||||
* @param {any} mesh
|
||||
* @return {{ skewX: number, skewY: number, skewZ: number, originX: number, originY: number, originZ: number }}
|
||||
*/
|
||||
function installSkewMatrix(mesh) {
|
||||
let s = mesh[skewSymbol];
|
||||
if (s) return s;
|
||||
s = mesh[skewSymbol] = { skewX: 0, skewY: 0, skewZ: 0, originX: 0, originY: 0, originZ: 0 };
|
||||
const original = mesh.updateMatrix;
|
||||
mesh.updateMatrix = function () {
|
||||
original.call(this);
|
||||
const st = this[skewSymbol];
|
||||
if (st.skewX !== 0 || st.skewY !== 0 || st.skewZ !== 0 || st.originX !== 0 || st.originY !== 0 || st.originZ !== 0) {
|
||||
applySkewOrigin(this.matrix.elements, st.skewX, st.skewY, st.skewZ, st.originX, st.originY, st.originZ);
|
||||
}
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
const threeObject3D = threeAdapter.registerTargetAdapter((t) => t instanceof Object3D);
|
||||
|
||||
// Position
|
||||
threeObject3D.registerProperty('x', (t) => t.position.x, (t, v) => { t.position.x = v; });
|
||||
threeObject3D.registerProperty('y', (t) => t.position.y, (t, v) => { t.position.y = v; });
|
||||
threeObject3D.registerProperty('z', (t) => t.position.z, (t, v) => { t.position.z = v; });
|
||||
|
||||
// Rotation in degrees
|
||||
threeObject3D.registerProperty('rotateX', (t) => radToDeg(t.rotation.x), (t, v) => { t.rotation.x = degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateY', (t) => radToDeg(t.rotation.y), (t, v) => { t.rotation.y = degToRad(v); });
|
||||
threeObject3D.registerProperty('rotateZ', (t) => radToDeg(t.rotation.z), (t, v) => { t.rotation.z = degToRad(v); });
|
||||
|
||||
// Scale per-axis and uniform
|
||||
threeObject3D.registerProperty('scaleX', (t) => t.scale.x, (t, v) => { t.scale.x = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleY', (t) => t.scale.y, (t, v) => { t.scale.y = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scaleZ', (t) => t.scale.z, (t, v) => { t.scale.z = v; setVisibility(t); });
|
||||
threeObject3D.registerProperty('scale',
|
||||
(t) => t.scale.x,
|
||||
(t, v) => {
|
||||
t.scale.x = v; t.scale.y = v; t.scale.z = v;
|
||||
setVisibility(t);
|
||||
},
|
||||
);
|
||||
|
||||
// Material
|
||||
threeObject3D.registerProperty('visible', (t) => t.visible, (t, v) => { t.visible = !!v; });
|
||||
threeObject3D.registerProperty('opacity',
|
||||
(t) => {
|
||||
if (t.material) return readScalar(t.material, 'opacity', PATH_DIRECT, 1);
|
||||
const v = t[opacitySymbol];
|
||||
return v === undefined ? 1 : v;
|
||||
},
|
||||
(t, v) => {
|
||||
if (t.material) writeScalar(t.material, 'opacity', v, PATH_DIRECT);
|
||||
else t[opacitySymbol] = v;
|
||||
setVisibility(t, v);
|
||||
},
|
||||
(t) => !t.isLight,
|
||||
);
|
||||
threeObject3D.registerProperty('color',
|
||||
(t) => readColorAt(colorTarget(t), 'color', PATH_DIRECT),
|
||||
(t, _, tw) => writeColorAt(colorTarget(t), 'color', tw._numbers, PATH_DIRECT),
|
||||
);
|
||||
|
||||
// HemisphereLight
|
||||
threeObject3D.registerProperty('groundColor',
|
||||
(t) => readColorAt(t, 'groundColor', PATH_DIRECT),
|
||||
(t, _, tw) => writeColorAt(t, 'groundColor', tw._numbers, PATH_DIRECT),
|
||||
(t) => !!t.groundColor,
|
||||
);
|
||||
|
||||
// Scene background, lazily initializes scene background to a Color on first write so the user does not have to set one upfront.
|
||||
threeObject3D.registerProperty('background',
|
||||
(t) => {
|
||||
const bg = /** @type {any} */(t).background;
|
||||
return bg && bg.isColor ? readColorHex(bg) : '#000000';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const scene = /** @type {any} */(t);
|
||||
let bg = scene.background;
|
||||
if (!bg || !bg.isColor) {
|
||||
bg = new Color();
|
||||
scene.background = bg;
|
||||
}
|
||||
const ns = tw._numbers;
|
||||
bg.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
},
|
||||
(t) => !!t.isScene,
|
||||
);
|
||||
|
||||
// Method-bridged props for Audio and PerspectiveCamera focalLength, read via getXxx and write via setXxx.
|
||||
const registerMethodProp = (apiName, getter, setter, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[getter](),
|
||||
(t, v) => { t[setter](v); },
|
||||
(t) => !!t[gate],
|
||||
);
|
||||
};
|
||||
registerMethodProp('volume', 'getVolume', 'setVolume', 'setVolume');
|
||||
// PositionalAudio
|
||||
registerMethodProp('refDistance', 'getRefDistance', 'setRefDistance', 'setRefDistance');
|
||||
registerMethodProp('rolloffFactor', 'getRolloffFactor', 'setRolloffFactor', 'setRefDistance');
|
||||
registerMethodProp('maxDistance', 'getMaxDistance', 'setMaxDistance', 'setRefDistance');
|
||||
// PerspectiveCamera
|
||||
registerMethodProp('focalLength', 'getFocalLength', 'setFocalLength', 'setFocalLength');
|
||||
|
||||
// Camera projection-update props, setter writes the value then calls updateProjectionMatrix.
|
||||
const registerCameraProp = (apiName, gate) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => t[apiName],
|
||||
(t, v) => { t[apiName] = v; t.updateProjectionMatrix(); },
|
||||
gate,
|
||||
);
|
||||
};
|
||||
const isPersp = (t) => !!t.isPerspectiveCamera;
|
||||
const isOrtho = (t) => !!t.isOrthographicCamera;
|
||||
registerCameraProp('fov', isPersp);
|
||||
registerCameraProp('aspect', isPersp);
|
||||
registerCameraProp('left', isOrtho);
|
||||
registerCameraProp('right', isOrtho);
|
||||
registerCameraProp('top', isOrtho);
|
||||
registerCameraProp('bottom', isOrtho);
|
||||
|
||||
// Skew in degrees and transform-origin in object-space.
|
||||
// Patches mesh updateMatrix on first write so the standard PRS compose is followed by an in-place skew and origin shift.
|
||||
// Reads default to 0 for meshes that have never been written.
|
||||
/**
|
||||
* @param {String} apiName
|
||||
* @param {String} key
|
||||
*/
|
||||
const registerSkewProp = (apiName, key) => {
|
||||
threeObject3D.registerProperty(apiName,
|
||||
(t) => { const s = /** @type {any} */(t)[skewSymbol]; return s ? s[key] : 0; },
|
||||
(t, v) => { installSkewMatrix(t)[key] = v; },
|
||||
);
|
||||
};
|
||||
registerSkewProp('skewX', 'skewX');
|
||||
registerSkewProp('skewY', 'skewY');
|
||||
registerSkewProp('skewZ', 'skewZ');
|
||||
registerSkewProp('transformOriginX', 'originX');
|
||||
registerSkewProp('transformOriginY', 'originY');
|
||||
registerSkewProp('transformOriginZ', 'originZ');
|
||||
|
||||
// Shorthand 3-token string x y z or 2-string from-to array routed via the engine COMPLEX path.
|
||||
// The setter reads tween _numbers for the per-frame lerped triplet.
|
||||
threeObject3D.registerProperty('transformOrigin',
|
||||
(t) => {
|
||||
const s = /** @type {any} */(t)[skewSymbol];
|
||||
return s ? `${s.originX} ${s.originY} ${s.originZ}` : '0 0 0';
|
||||
},
|
||||
(t, _, tw) => {
|
||||
const s = installSkewMatrix(t);
|
||||
const ns = tw._numbers;
|
||||
s.originX = ns[0];
|
||||
s.originY = ns[1];
|
||||
s.originZ = ns[2];
|
||||
},
|
||||
);
|
||||
|
||||
// Shared by both camera types.
|
||||
const isCamera = (t) => !!t.isPerspectiveCamera || !!t.isOrthographicCamera;
|
||||
registerCameraProp('near', isCamera);
|
||||
registerCameraProp('far', isCamera);
|
||||
registerCameraProp('zoom', isCamera);
|
||||
|
||||
// Auto-detection for material props on meshes and direct Vector / Color fields on the target is provided by the shared resolvers in resolvers.js.
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var adapter = require('./adapter.cjs');
|
||||
var number = require('../../utils/number.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* Global property resolvers for three.js targets. Auto-detect `Color`-typed properties, `Vector2/3/4` axis components, shader uniforms, and TSL `UniformNode` slots on any three.js object. For mesh-like targets, a second resolver walks to `target.material` and runs the same detection there.
|
||||
*/
|
||||
|
||||
|
||||
const identity = (t) => t;
|
||||
const getMaterial = (t) => t.material;
|
||||
|
||||
const directColorCache = [{}, {}, {}];
|
||||
const directScalarCache = [{}, {}, {}];
|
||||
const directVectorCache = [{}, {}, {}];
|
||||
|
||||
const materialColorCache = [{}, {}, {}];
|
||||
const materialScalarCache = [{}, {}, {}];
|
||||
const materialVectorCache = [{}, {}, {}];
|
||||
|
||||
const buildEntry = (name, d, getHost, colorCaches, scalarCaches, vectorCaches) => {
|
||||
const path = d.path;
|
||||
if (d.kind === helpers.KIND_COLOR) {
|
||||
const cache = colorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readColorAt(getHost(t), name, path),
|
||||
set: (t, _, tw) => helpers.writeColorAt(getHost(t), name, tw._numbers, path),
|
||||
});
|
||||
}
|
||||
if (d.kind === helpers.KIND_SCALAR) {
|
||||
const cache = scalarCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readScalar(getHost(t), name, path),
|
||||
set: (t, v) => helpers.writeScalar(getHost(t), name, v, path),
|
||||
});
|
||||
}
|
||||
// KIND_VECTOR
|
||||
const base = d.base;
|
||||
const axis = d.axis;
|
||||
const cache = vectorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => helpers.readVectorAt(getHost(t), base, axis, path),
|
||||
set: (t, v) => helpers.writeVectorAt(getHost(t), base, axis, v, path),
|
||||
});
|
||||
};
|
||||
|
||||
// Detect direct Color, Vector axis, uniforms, and UniformNode slots on the target.
|
||||
// Numeric or boolean direct fields fall through to the engine OBJECT path.
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const d = helpers.classifyTargetProp(target, name);
|
||||
if (!d) return null;
|
||||
if (d.kind === helpers.KIND_SCALAR && d.path === helpers.PATH_DIRECT) return null;
|
||||
return buildEntry(name, d, identity, directColorCache, directScalarCache, directVectorCache);
|
||||
});
|
||||
|
||||
// Walk to target.material for meshes and other Object3D subclasses with a material field.
|
||||
// Skip when the target already exposes the name directly so a mesh-level mapping wins.
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (target[name] !== undefined) return null;
|
||||
const m = target.material;
|
||||
if (!m) return null;
|
||||
const first = Array.isArray(m) ? m[0] : m;
|
||||
if (!first) return null;
|
||||
const d = helpers.classifyTargetProp(first, name);
|
||||
if (!d) return null;
|
||||
return buildEntry(name, d, getMaterial, materialColorCache, materialScalarCache, materialVectorCache);
|
||||
});
|
||||
|
||||
// Convert angle-named scalar fields between degrees and radians so users animate in degrees on any three.js target.
|
||||
// Object3D Euler rotation is excluded because Euler is not a number, the rotateX/Y/Z mappings handle it.
|
||||
const ANGLE_NAMES = { rotation: 1, angle: 1 };
|
||||
const angleEntries = {};
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (!ANGLE_NAMES[name]) return null;
|
||||
if (typeof target[name] !== 'number') return null;
|
||||
return angleEntries[name] || (angleEntries[name] = {
|
||||
get: (t) => number.radToDeg(t[name]),
|
||||
set: (t, v) => { t[name] = number.degToRad(v); },
|
||||
});
|
||||
});
|
||||
|
||||
// Decompose Euler-typed angle fields to axis components in degrees, like rotationX, rotationY, rotationZ when rotation is an Euler.
|
||||
// Object3D mappings win because static adapter props beat resolvers, so this only catches non-Object3D targets with an Euler rotation field.
|
||||
const eulerAxisEntries = {};
|
||||
adapter.threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const axis = helpers.AXIS_MAP[name[name.length - 1]];
|
||||
if (!axis) return null;
|
||||
const base = name.slice(0, -1);
|
||||
if (!ANGLE_NAMES[base]) return null;
|
||||
const v = target[base];
|
||||
if (!v || !v.isEuler) return null;
|
||||
return eulerAxisEntries[name] || (eulerAxisEntries[name] = {
|
||||
get: (t) => number.radToDeg(t[base][axis]),
|
||||
set: (t, v) => { t[base][axis] = number.degToRad(v); },
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { radToDeg, degToRad } from '../../utils/number.js';
|
||||
import { classifyTargetProp, KIND_SCALAR, PATH_DIRECT, AXIS_MAP, KIND_COLOR, writeColorAt, readColorAt, writeScalar, readScalar, writeVectorAt, readVectorAt } from './helpers.js';
|
||||
|
||||
/**
|
||||
* Global property resolvers for three.js targets. Auto-detect `Color`-typed properties, `Vector2/3/4` axis components, shader uniforms, and TSL `UniformNode` slots on any three.js object. For mesh-like targets, a second resolver walks to `target.material` and runs the same detection there.
|
||||
*/
|
||||
|
||||
|
||||
const identity = (t) => t;
|
||||
const getMaterial = (t) => t.material;
|
||||
|
||||
const directColorCache = [{}, {}, {}];
|
||||
const directScalarCache = [{}, {}, {}];
|
||||
const directVectorCache = [{}, {}, {}];
|
||||
|
||||
const materialColorCache = [{}, {}, {}];
|
||||
const materialScalarCache = [{}, {}, {}];
|
||||
const materialVectorCache = [{}, {}, {}];
|
||||
|
||||
const buildEntry = (name, d, getHost, colorCaches, scalarCaches, vectorCaches) => {
|
||||
const path = d.path;
|
||||
if (d.kind === KIND_COLOR) {
|
||||
const cache = colorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readColorAt(getHost(t), name, path),
|
||||
set: (t, _, tw) => writeColorAt(getHost(t), name, tw._numbers, path),
|
||||
});
|
||||
}
|
||||
if (d.kind === KIND_SCALAR) {
|
||||
const cache = scalarCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readScalar(getHost(t), name, path),
|
||||
set: (t, v) => writeScalar(getHost(t), name, v, path),
|
||||
});
|
||||
}
|
||||
// KIND_VECTOR
|
||||
const base = d.base;
|
||||
const axis = d.axis;
|
||||
const cache = vectorCaches[path];
|
||||
return cache[name] || (cache[name] = {
|
||||
get: (t) => readVectorAt(getHost(t), base, axis, path),
|
||||
set: (t, v) => writeVectorAt(getHost(t), base, axis, v, path),
|
||||
});
|
||||
};
|
||||
|
||||
// Detect direct Color, Vector axis, uniforms, and UniformNode slots on the target.
|
||||
// Numeric or boolean direct fields fall through to the engine OBJECT path.
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const d = classifyTargetProp(target, name);
|
||||
if (!d) return null;
|
||||
if (d.kind === KIND_SCALAR && d.path === PATH_DIRECT) return null;
|
||||
return buildEntry(name, d, identity, directColorCache, directScalarCache, directVectorCache);
|
||||
});
|
||||
|
||||
// Walk to target.material for meshes and other Object3D subclasses with a material field.
|
||||
// Skip when the target already exposes the name directly so a mesh-level mapping wins.
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (target[name] !== undefined) return null;
|
||||
const m = target.material;
|
||||
if (!m) return null;
|
||||
const first = Array.isArray(m) ? m[0] : m;
|
||||
if (!first) return null;
|
||||
const d = classifyTargetProp(first, name);
|
||||
if (!d) return null;
|
||||
return buildEntry(name, d, getMaterial, materialColorCache, materialScalarCache, materialVectorCache);
|
||||
});
|
||||
|
||||
// Convert angle-named scalar fields between degrees and radians so users animate in degrees on any three.js target.
|
||||
// Object3D Euler rotation is excluded because Euler is not a number, the rotateX/Y/Z mappings handle it.
|
||||
const ANGLE_NAMES = { rotation: 1, angle: 1 };
|
||||
const angleEntries = {};
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
if (!ANGLE_NAMES[name]) return null;
|
||||
if (typeof target[name] !== 'number') return null;
|
||||
return angleEntries[name] || (angleEntries[name] = {
|
||||
get: (t) => radToDeg(t[name]),
|
||||
set: (t, v) => { t[name] = degToRad(v); },
|
||||
});
|
||||
});
|
||||
|
||||
// Decompose Euler-typed angle fields to axis components in degrees, like rotationX, rotationY, rotationZ when rotation is an Euler.
|
||||
// Object3D mappings win because static adapter props beat resolvers, so this only catches non-Object3D targets with an Euler rotation field.
|
||||
const eulerAxisEntries = {};
|
||||
threeAdapter.registerPropertyResolver((target, name) => {
|
||||
const axis = AXIS_MAP[name[name.length - 1]];
|
||||
if (!axis) return null;
|
||||
const base = name.slice(0, -1);
|
||||
if (!ANGLE_NAMES[base]) return null;
|
||||
const v = target[base];
|
||||
if (!v || !v.isEuler) return null;
|
||||
return eulerAxisEntries[name] || (eulerAxisEntries[name] = {
|
||||
get: (t) => radToDeg(t[base][axis]),
|
||||
set: (t, v) => { t[base][axis] = degToRad(v); },
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Anime.js - adapters - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var three = require('three');
|
||||
var adapter = require('./adapter.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* Bare `UniformNode` adapter. Auto-detects `UniformNode` instances and exposes their `.value` for animation. Scalars and booleans animate via `value`, `Color` uniforms via `color`, and `Vector2/3/4` uniforms via `x` / `y` / `z` / `w` axes.
|
||||
*
|
||||
* import 'animejs/bindings/three';
|
||||
* import { uniform } from 'three/tsl';
|
||||
* animate(uniform(0), { value: 1 });
|
||||
* animate(uniform(new Color()), { color: '#0f0' });
|
||||
* animate(uniform(new Vector3()), { x: 1, y: 0.5 });
|
||||
*
|
||||
* `UniformNode` slots assigned to `NodeMaterial` (`material.colorNode`, `material.offsetNode`, ...) are auto-detected by the shared resolvers in `resolvers.js`. Non-uniform nodes (`mix`, `add`, computed expressions), `Matrix3/4` and `Texture` valued uniforms, and `UniformArrayNode` / `BufferNode` are out of scope and fall through to the engine's direct property path.
|
||||
*/
|
||||
|
||||
|
||||
const uniformNode = adapter.threeAdapter.registerTargetAdapter((t) => !!(t && t.isUniformNode));
|
||||
|
||||
// Scalar and bool uniforms animate via the engine OBJECT fallthrough on value, no adapter prop needed since the engine writes uniform value natively.
|
||||
uniformNode.registerProperty('color',
|
||||
(t) => helpers.readColorHex(t.value),
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t.value.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
|
||||
},
|
||||
(t) => !!(t.value && t.value.isColor),
|
||||
);
|
||||
uniformNode.registerProperty('x', (t) => t.value.x, (t, v) => { t.value.x = v; }, (t) => helpers.isVectorWith(t.value, 'x'));
|
||||
uniformNode.registerProperty('y', (t) => t.value.y, (t, v) => { t.value.y = v; }, (t) => helpers.isVectorWith(t.value, 'y'));
|
||||
uniformNode.registerProperty('z', (t) => t.value.z, (t, v) => { t.value.z = v; }, (t) => helpers.isVectorWith(t.value, 'z'));
|
||||
uniformNode.registerProperty('w', (t) => t.value.w, (t, v) => { t.value.w = v; }, (t) => helpers.isVectorWith(t.value, 'w'));
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Anime.js - adapters - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { SRGBColorSpace } from 'three';
|
||||
import { threeAdapter } from './adapter.js';
|
||||
import { readColorHex, COLOR_NORM, isVectorWith } from './helpers.js';
|
||||
|
||||
/**
|
||||
* Bare `UniformNode` adapter. Auto-detects `UniformNode` instances and exposes their `.value` for animation. Scalars and booleans animate via `value`, `Color` uniforms via `color`, and `Vector2/3/4` uniforms via `x` / `y` / `z` / `w` axes.
|
||||
*
|
||||
* import 'animejs/bindings/three';
|
||||
* import { uniform } from 'three/tsl';
|
||||
* animate(uniform(0), { value: 1 });
|
||||
* animate(uniform(new Color()), { color: '#0f0' });
|
||||
* animate(uniform(new Vector3()), { x: 1, y: 0.5 });
|
||||
*
|
||||
* `UniformNode` slots assigned to `NodeMaterial` (`material.colorNode`, `material.offsetNode`, ...) are auto-detected by the shared resolvers in `resolvers.js`. Non-uniform nodes (`mix`, `add`, computed expressions), `Matrix3/4` and `Texture` valued uniforms, and `UniformArrayNode` / `BufferNode` are out of scope and fall through to the engine's direct property path.
|
||||
*/
|
||||
|
||||
|
||||
const uniformNode = threeAdapter.registerTargetAdapter((t) => !!(t && t.isUniformNode));
|
||||
|
||||
// Scalar and bool uniforms animate via the engine OBJECT fallthrough on value, no adapter prop needed since the engine writes uniform value natively.
|
||||
uniformNode.registerProperty('color',
|
||||
(t) => readColorHex(t.value),
|
||||
(t, _, tw) => {
|
||||
const ns = tw._numbers;
|
||||
t.value.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
|
||||
},
|
||||
(t) => !!(t.value && t.value.isColor),
|
||||
);
|
||||
uniformNode.registerProperty('x', (t) => t.value.x, (t, v) => { t.value.x = v; }, (t) => isVectorWith(t.value, 'x'));
|
||||
uniformNode.registerProperty('y', (t) => t.value.y, (t, v) => { t.value.y = v; }, (t) => isVectorWith(t.value, 'y'));
|
||||
uniformNode.registerProperty('z', (t) => t.value.z, (t, v) => { t.value.z = v; }, (t) => isVectorWith(t.value, 'z'));
|
||||
uniformNode.registerProperty('w', (t) => t.value.w, (t, v) => { t.value.w = v; }, (t) => isVectorWith(t.value, 'w'));
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Anime.js - animatable - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('../core/consts.cjs');
|
||||
var globals = require('../core/globals.cjs');
|
||||
var helpers = require('../core/helpers.cjs');
|
||||
var animation = require('../animation/animation.cjs');
|
||||
var parser = require('../easings/eases/parser.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* TargetsParam,
|
||||
* AnimatableParams,
|
||||
* AnimationParams,
|
||||
* TweenParamsOptions,
|
||||
* Tween,
|
||||
* AnimatableProperty,
|
||||
* AnimatableObject,
|
||||
* } from '../types/index.js';
|
||||
*/
|
||||
|
||||
class Animatable {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimatableParams} parameters
|
||||
*/
|
||||
constructor(targets, parameters) {
|
||||
if (globals.scope.current) globals.scope.current.register(this);
|
||||
const beginHandler = () => {
|
||||
if (this.callbacks.completed) this.callbacks.reset();
|
||||
this.callbacks.play();
|
||||
};
|
||||
const pauseHandler = () => {
|
||||
if (this.callbacks.completed) return;
|
||||
let paused = true;
|
||||
for (let name in this.animations) {
|
||||
const anim = this.animations[name];
|
||||
if (!anim.paused && paused) {
|
||||
paused = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (paused) {
|
||||
this.callbacks.complete();
|
||||
}
|
||||
};
|
||||
/** @type {AnimationParams} */
|
||||
const globalParams = {
|
||||
onBegin: beginHandler,
|
||||
onComplete: pauseHandler,
|
||||
onPause: pauseHandler,
|
||||
};
|
||||
/** @type {AnimationParams} */
|
||||
const callbacksAnimationParams = { v: 1, autoplay: false };
|
||||
const properties = {};
|
||||
this.targets = [];
|
||||
/** @type {Record<String, JSAnimation>} */
|
||||
this.animations = {};
|
||||
/** @type {JSAnimation|null} */
|
||||
this.callbacks = null;
|
||||
if (helpers.isUnd(targets) || helpers.isUnd(parameters)) return;
|
||||
for (let propName in parameters) {
|
||||
const paramValue = parameters[propName];
|
||||
if (helpers.isKey(propName)) {
|
||||
properties[propName] = paramValue;
|
||||
} else if (helpers.stringStartsWith(propName, 'on')) {
|
||||
callbacksAnimationParams[propName] = paramValue;
|
||||
} else {
|
||||
globalParams[propName] = paramValue;
|
||||
}
|
||||
}
|
||||
this.callbacks = new animation.JSAnimation({ v: 0 }, callbacksAnimationParams);
|
||||
for (let propName in properties) {
|
||||
const propValue = properties[propName];
|
||||
const isObjValue = helpers.isObj(propValue);
|
||||
/** @type {TweenParamsOptions} */
|
||||
let propParams = {};
|
||||
let to = '+=0';
|
||||
if (isObjValue) {
|
||||
const unit = propValue.unit;
|
||||
if (helpers.isStr(unit)) to += unit;
|
||||
} else {
|
||||
propParams.duration = propValue;
|
||||
}
|
||||
propParams[propName] = isObjValue ? helpers.mergeObjects({ to }, propValue) : to;
|
||||
const animParams = helpers.mergeObjects(globalParams, propParams);
|
||||
animParams.composition = consts.compositionTypes.replace;
|
||||
animParams.autoplay = false;
|
||||
const animation$1 = this.animations[propName] = new animation.JSAnimation(targets, animParams, null, 0, false).init();
|
||||
if (!this.targets.length) this.targets.push(...animation$1.targets);
|
||||
/** @type {AnimatableProperty} */
|
||||
this[propName] = (to, duration, ease) => {
|
||||
const tween = /** @type {Tween} */(animation$1._head);
|
||||
if (helpers.isUnd(to) && tween) {
|
||||
const numbers = tween._numbers;
|
||||
if (numbers && numbers.length) {
|
||||
return numbers;
|
||||
} else {
|
||||
return tween._modifier(tween._number);
|
||||
}
|
||||
} else {
|
||||
helpers.forEachChildren(animation$1, (/** @type {Tween} */tween) => {
|
||||
if (helpers.isArr(to)) {
|
||||
for (let i = 0, l = /** @type {Array} */(to).length; i < l; i++) {
|
||||
if (!helpers.isUnd(tween._numbers[i])) {
|
||||
tween._fromNumbers[i] = /** @type {Number} */(tween._modifier(tween._numbers[i]));
|
||||
tween._toNumbers[i] = to[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tween._fromNumber = /** @type {Number} */(tween._modifier(tween._number));
|
||||
tween._toNumber = /** @type {Number} */(to);
|
||||
}
|
||||
if (!helpers.isUnd(ease)) tween._ease = parser.parseEase(ease);
|
||||
tween._currentTime = 0;
|
||||
});
|
||||
if (!helpers.isUnd(duration)) animation$1.stretch(duration);
|
||||
animation$1.reset(true).resume();
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
revert() {
|
||||
for (let propName in this.animations) {
|
||||
this[propName] = consts.noop;
|
||||
this.animations[propName].revert();
|
||||
}
|
||||
this.animations = {};
|
||||
this.targets.length = 0;
|
||||
if (this.callbacks) this.callbacks.revert();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimatableParams} parameters
|
||||
* @return {AnimatableObject}
|
||||
*/
|
||||
const createAnimatable = (targets, parameters) => /** @type {AnimatableObject} */ (new Animatable(targets, parameters));
|
||||
|
||||
exports.Animatable = Animatable;
|
||||
exports.createAnimatable = createAnimatable;
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @import {
|
||||
* TargetsParam,
|
||||
* AnimatableParams,
|
||||
* AnimationParams,
|
||||
* TweenParamsOptions,
|
||||
* Tween,
|
||||
* AnimatableProperty,
|
||||
* AnimatableObject,
|
||||
* } from '../types/index.js';
|
||||
*/
|
||||
export class Animatable {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimatableParams} parameters
|
||||
*/
|
||||
constructor(targets: TargetsParam, parameters: AnimatableParams);
|
||||
targets: (HTMLElement | SVGElement | import("../types/index.js").JSTarget)[];
|
||||
/** @type {Record<String, JSAnimation>} */
|
||||
animations: Record<string, JSAnimation>;
|
||||
/** @type {JSAnimation|null} */
|
||||
callbacks: JSAnimation | null;
|
||||
revert(): this;
|
||||
}
|
||||
export function createAnimatable(targets: TargetsParam, parameters: AnimatableParams): AnimatableObject;
|
||||
import { JSAnimation } from '../animation/animation.js';
|
||||
import type { TargetsParam } from '../types/index.js';
|
||||
import type { AnimatableParams } from '../types/index.js';
|
||||
import type { AnimatableObject } from '../types/index.js';
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Anime.js - animatable - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { compositionTypes, noop } from '../core/consts.js';
|
||||
import { scope } from '../core/globals.js';
|
||||
import { isUnd, isKey, stringStartsWith, isObj, mergeObjects, forEachChildren, isArr, isStr } from '../core/helpers.js';
|
||||
import { JSAnimation } from '../animation/animation.js';
|
||||
import { parseEase } from '../easings/eases/parser.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* TargetsParam,
|
||||
* AnimatableParams,
|
||||
* AnimationParams,
|
||||
* TweenParamsOptions,
|
||||
* Tween,
|
||||
* AnimatableProperty,
|
||||
* AnimatableObject,
|
||||
* } from '../types/index.js';
|
||||
*/
|
||||
|
||||
class Animatable {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimatableParams} parameters
|
||||
*/
|
||||
constructor(targets, parameters) {
|
||||
if (scope.current) scope.current.register(this);
|
||||
const beginHandler = () => {
|
||||
if (this.callbacks.completed) this.callbacks.reset();
|
||||
this.callbacks.play();
|
||||
};
|
||||
const pauseHandler = () => {
|
||||
if (this.callbacks.completed) return;
|
||||
let paused = true;
|
||||
for (let name in this.animations) {
|
||||
const anim = this.animations[name];
|
||||
if (!anim.paused && paused) {
|
||||
paused = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (paused) {
|
||||
this.callbacks.complete();
|
||||
}
|
||||
};
|
||||
/** @type {AnimationParams} */
|
||||
const globalParams = {
|
||||
onBegin: beginHandler,
|
||||
onComplete: pauseHandler,
|
||||
onPause: pauseHandler,
|
||||
};
|
||||
/** @type {AnimationParams} */
|
||||
const callbacksAnimationParams = { v: 1, autoplay: false };
|
||||
const properties = {};
|
||||
this.targets = [];
|
||||
/** @type {Record<String, JSAnimation>} */
|
||||
this.animations = {};
|
||||
/** @type {JSAnimation|null} */
|
||||
this.callbacks = null;
|
||||
if (isUnd(targets) || isUnd(parameters)) return;
|
||||
for (let propName in parameters) {
|
||||
const paramValue = parameters[propName];
|
||||
if (isKey(propName)) {
|
||||
properties[propName] = paramValue;
|
||||
} else if (stringStartsWith(propName, 'on')) {
|
||||
callbacksAnimationParams[propName] = paramValue;
|
||||
} else {
|
||||
globalParams[propName] = paramValue;
|
||||
}
|
||||
}
|
||||
this.callbacks = new JSAnimation({ v: 0 }, callbacksAnimationParams);
|
||||
for (let propName in properties) {
|
||||
const propValue = properties[propName];
|
||||
const isObjValue = isObj(propValue);
|
||||
/** @type {TweenParamsOptions} */
|
||||
let propParams = {};
|
||||
let to = '+=0';
|
||||
if (isObjValue) {
|
||||
const unit = propValue.unit;
|
||||
if (isStr(unit)) to += unit;
|
||||
} else {
|
||||
propParams.duration = propValue;
|
||||
}
|
||||
propParams[propName] = isObjValue ? mergeObjects({ to }, propValue) : to;
|
||||
const animParams = mergeObjects(globalParams, propParams);
|
||||
animParams.composition = compositionTypes.replace;
|
||||
animParams.autoplay = false;
|
||||
const animation = this.animations[propName] = new JSAnimation(targets, animParams, null, 0, false).init();
|
||||
if (!this.targets.length) this.targets.push(...animation.targets);
|
||||
/** @type {AnimatableProperty} */
|
||||
this[propName] = (to, duration, ease) => {
|
||||
const tween = /** @type {Tween} */(animation._head);
|
||||
if (isUnd(to) && tween) {
|
||||
const numbers = tween._numbers;
|
||||
if (numbers && numbers.length) {
|
||||
return numbers;
|
||||
} else {
|
||||
return tween._modifier(tween._number);
|
||||
}
|
||||
} else {
|
||||
forEachChildren(animation, (/** @type {Tween} */tween) => {
|
||||
if (isArr(to)) {
|
||||
for (let i = 0, l = /** @type {Array} */(to).length; i < l; i++) {
|
||||
if (!isUnd(tween._numbers[i])) {
|
||||
tween._fromNumbers[i] = /** @type {Number} */(tween._modifier(tween._numbers[i]));
|
||||
tween._toNumbers[i] = to[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tween._fromNumber = /** @type {Number} */(tween._modifier(tween._number));
|
||||
tween._toNumber = /** @type {Number} */(to);
|
||||
}
|
||||
if (!isUnd(ease)) tween._ease = parseEase(ease);
|
||||
tween._currentTime = 0;
|
||||
});
|
||||
if (!isUnd(duration)) animation.stretch(duration);
|
||||
animation.reset(true).resume();
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
revert() {
|
||||
for (let propName in this.animations) {
|
||||
this[propName] = noop;
|
||||
this.animations[propName].revert();
|
||||
}
|
||||
this.animations = {};
|
||||
this.targets.length = 0;
|
||||
if (this.callbacks) this.callbacks.revert();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimatableParams} parameters
|
||||
* @return {AnimatableObject}
|
||||
*/
|
||||
const createAnimatable = (targets, parameters) => /** @type {AnimatableObject} */ (new Animatable(targets, parameters));
|
||||
|
||||
export { Animatable, createAnimatable };
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Anime.js - animatable - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var animatable = require('./animatable.cjs');
|
||||
|
||||
|
||||
|
||||
exports.Animatable = animatable.Animatable;
|
||||
exports.createAnimatable = animatable.createAnimatable;
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./animatable.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Anime.js - animatable - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { Animatable, createAnimatable } from './animatable.js';
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Anime.js - animation - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('../core/consts.cjs');
|
||||
var helpers = require('../core/helpers.cjs');
|
||||
var render = require('../core/render.cjs');
|
||||
|
||||
const additive = {
|
||||
animation: null,
|
||||
update: consts.noop,
|
||||
};
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tween,
|
||||
* TweenAdditiveLookups,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef AdditiveAnimation
|
||||
* @property {Number} duration
|
||||
* @property {Number} _offset
|
||||
* @property {Number} _delay
|
||||
* @property {Tween} _head
|
||||
* @property {Tween} _tail
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {TweenAdditiveLookups} lookups
|
||||
* @return {AdditiveAnimation}
|
||||
*/
|
||||
const addAdditiveAnimation = lookups => {
|
||||
let animation = additive.animation;
|
||||
if (!animation) {
|
||||
animation = {
|
||||
duration: consts.minValue,
|
||||
computeDeltaTime: consts.noop,
|
||||
_offset: 0,
|
||||
_delay: 0,
|
||||
_head: null,
|
||||
_tail: null,
|
||||
};
|
||||
additive.animation = animation;
|
||||
additive.update = () => {
|
||||
lookups.forEach(propertyAnimation => {
|
||||
for (let propertyName in propertyAnimation) {
|
||||
const tweens = propertyAnimation[propertyName];
|
||||
const lookupTween = tweens._head;
|
||||
if (lookupTween) {
|
||||
const valueType = lookupTween._valueType;
|
||||
const additiveValues = valueType === consts.valueTypes.COMPLEX || valueType === consts.valueTypes.COLOR ? helpers.cloneArray(lookupTween._fromNumbers) : null;
|
||||
let additiveValue = lookupTween._fromNumber;
|
||||
let tween = tweens._tail;
|
||||
while (tween && tween !== lookupTween) {
|
||||
if (additiveValues) {
|
||||
for (let i = 0, l = tween._numbers.length; i < l; i++) additiveValues[i] += tween._numbers[i];
|
||||
} else {
|
||||
additiveValue += tween._number;
|
||||
}
|
||||
tween = tween._prevAdd;
|
||||
}
|
||||
lookupTween._toNumber = additiveValue;
|
||||
lookupTween._toNumbers = additiveValues;
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO: Avoid polymorphism here, idealy the additive animation should be a regular animation with a higher priority in the render loop
|
||||
render.render(animation, 1, 1, 0, consts.tickModes.FORCE);
|
||||
};
|
||||
}
|
||||
return animation;
|
||||
};
|
||||
|
||||
exports.addAdditiveAnimation = addAdditiveAnimation;
|
||||
exports.additive = additive;
|
||||
@@ -0,0 +1,15 @@
|
||||
export namespace additive {
|
||||
export let animation: any;
|
||||
export { noop as update };
|
||||
}
|
||||
export function addAdditiveAnimation(lookups: TweenAdditiveLookups): AdditiveAnimation;
|
||||
export type AdditiveAnimation = {
|
||||
duration: number;
|
||||
_offset: number;
|
||||
_delay: number;
|
||||
_head: Tween;
|
||||
_tail: Tween;
|
||||
};
|
||||
import { noop } from '../core/consts.js';
|
||||
import type { TweenAdditiveLookups } from '../types/index.js';
|
||||
import type { Tween } from '../types/index.js';
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Anime.js - animation - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { noop, minValue, valueTypes, tickModes } from '../core/consts.js';
|
||||
import { cloneArray } from '../core/helpers.js';
|
||||
import { render } from '../core/render.js';
|
||||
|
||||
const additive = {
|
||||
animation: null,
|
||||
update: noop,
|
||||
};
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tween,
|
||||
* TweenAdditiveLookups,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef AdditiveAnimation
|
||||
* @property {Number} duration
|
||||
* @property {Number} _offset
|
||||
* @property {Number} _delay
|
||||
* @property {Tween} _head
|
||||
* @property {Tween} _tail
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {TweenAdditiveLookups} lookups
|
||||
* @return {AdditiveAnimation}
|
||||
*/
|
||||
const addAdditiveAnimation = lookups => {
|
||||
let animation = additive.animation;
|
||||
if (!animation) {
|
||||
animation = {
|
||||
duration: minValue,
|
||||
computeDeltaTime: noop,
|
||||
_offset: 0,
|
||||
_delay: 0,
|
||||
_head: null,
|
||||
_tail: null,
|
||||
};
|
||||
additive.animation = animation;
|
||||
additive.update = () => {
|
||||
lookups.forEach(propertyAnimation => {
|
||||
for (let propertyName in propertyAnimation) {
|
||||
const tweens = propertyAnimation[propertyName];
|
||||
const lookupTween = tweens._head;
|
||||
if (lookupTween) {
|
||||
const valueType = lookupTween._valueType;
|
||||
const additiveValues = valueType === valueTypes.COMPLEX || valueType === valueTypes.COLOR ? cloneArray(lookupTween._fromNumbers) : null;
|
||||
let additiveValue = lookupTween._fromNumber;
|
||||
let tween = tweens._tail;
|
||||
while (tween && tween !== lookupTween) {
|
||||
if (additiveValues) {
|
||||
for (let i = 0, l = tween._numbers.length; i < l; i++) additiveValues[i] += tween._numbers[i];
|
||||
} else {
|
||||
additiveValue += tween._number;
|
||||
}
|
||||
tween = tween._prevAdd;
|
||||
}
|
||||
lookupTween._toNumber = additiveValue;
|
||||
lookupTween._toNumbers = additiveValues;
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO: Avoid polymorphism here, idealy the additive animation should be a regular animation with a higher priority in the render loop
|
||||
render(animation, 1, 1, 0, tickModes.FORCE);
|
||||
};
|
||||
}
|
||||
return animation;
|
||||
};
|
||||
|
||||
export { addAdditiveAnimation, additive };
|
||||
@@ -0,0 +1,746 @@
|
||||
/**
|
||||
* Anime.js - animation - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('../core/consts.cjs');
|
||||
var helpers = require('../core/helpers.cjs');
|
||||
var globals = require('../core/globals.cjs');
|
||||
var targets = require('../core/targets.cjs');
|
||||
var registry = require('../adapters/registry.cjs');
|
||||
var values = require('../core/values.cjs');
|
||||
var styles = require('../core/styles.cjs');
|
||||
var units = require('../core/units.cjs');
|
||||
var parser = require('../easings/eases/parser.cjs');
|
||||
var timer = require('../timer/timer.cjs');
|
||||
var composition = require('./composition.cjs');
|
||||
var additive = require('./additive.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tween,
|
||||
* TweenKeyValue,
|
||||
* TweenParamsOptions,
|
||||
* TweenValues,
|
||||
* DurationKeyframes,
|
||||
* PercentageKeyframes,
|
||||
* AnimationParams,
|
||||
* TweenPropValue,
|
||||
* ArraySyntaxValue,
|
||||
* TargetsParam,
|
||||
* TimerParams,
|
||||
* TweenParamValue,
|
||||
* DOMTarget,
|
||||
* TargetsArray,
|
||||
* Callback,
|
||||
* EasingFunction,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* Timeline,
|
||||
* } from '../timeline/timeline.js'
|
||||
*
|
||||
* @import {
|
||||
* Spring,
|
||||
* } from '../easings/spring/index.js'
|
||||
*/
|
||||
|
||||
// Defines decomposed values target objects only once and mutate their properties later to avoid GC
|
||||
// TODO: Maybe move the objects creation to values.js and use the decompose function to create the base object
|
||||
const fromTargetObject = values.createDecomposedValueTargetObject();
|
||||
const toTargetObject = values.createDecomposedValueTargetObject();
|
||||
const inlineStylesStore = {};
|
||||
const toFunctionStore = { func: null };
|
||||
const fromFunctionStore = { func: null };
|
||||
const keyframesTargetArray = [null];
|
||||
const fastSetValuesArray = [null, null];
|
||||
/** @type {TweenKeyValue} */
|
||||
const keyObjectTarget = { to: null };
|
||||
|
||||
let tweenId = 0;
|
||||
let JSAnimationId = 0;
|
||||
let keyframes;
|
||||
/** @type {TweenParamsOptions & TweenValues} */
|
||||
let key;
|
||||
|
||||
/**
|
||||
* @param {DurationKeyframes | PercentageKeyframes} keyframes
|
||||
* @param {AnimationParams} parameters
|
||||
* @return {AnimationParams}
|
||||
*/
|
||||
const generateKeyframes = (keyframes, parameters) => {
|
||||
/** @type {AnimationParams} */
|
||||
const properties = {};
|
||||
if (helpers.isArr(keyframes)) {
|
||||
const propertyNames = [].concat(.../** @type {DurationKeyframes} */(keyframes).map(key => Object.keys(key))).filter(helpers.isKey);
|
||||
for (let i = 0, l = propertyNames.length; i < l; i++) {
|
||||
const propName = propertyNames[i];
|
||||
const propArray = /** @type {DurationKeyframes} */(keyframes).map(key => {
|
||||
/** @type {TweenKeyValue} */
|
||||
const newKey = {};
|
||||
for (let p in key) {
|
||||
const keyValue = /** @type {TweenPropValue} */(key[p]);
|
||||
if (helpers.isKey(p)) {
|
||||
if (p === propName) {
|
||||
newKey.to = keyValue;
|
||||
}
|
||||
} else {
|
||||
newKey[p] = keyValue;
|
||||
}
|
||||
}
|
||||
return newKey;
|
||||
});
|
||||
properties[propName] = /** @type {ArraySyntaxValue} */(propArray);
|
||||
}
|
||||
|
||||
} else {
|
||||
const totalDuration = /** @type {Number} */(values.setValue(parameters.duration, globals.globals.defaults.duration));
|
||||
const keys = Object.keys(keyframes)
|
||||
.map(key => { return {o: parseFloat(key) / 100, p: keyframes[key]} })
|
||||
.sort((a, b) => a.o - b.o);
|
||||
keys.forEach(key => {
|
||||
const offset = key.o;
|
||||
const prop = key.p;
|
||||
for (let name in prop) {
|
||||
if (helpers.isKey(name)) {
|
||||
let propArray = /** @type {Array} */(properties[name]);
|
||||
if (!propArray) propArray = properties[name] = [];
|
||||
const duration = offset * totalDuration;
|
||||
let length = propArray.length;
|
||||
let prevKey = propArray[length - 1];
|
||||
const keyObj = { to: prop[name] };
|
||||
let durProgress = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
durProgress += propArray[i].duration;
|
||||
}
|
||||
if (length === 1) {
|
||||
keyObj.from = prevKey.to;
|
||||
}
|
||||
if (prop.ease) {
|
||||
keyObj.ease = prop.ease;
|
||||
}
|
||||
keyObj.duration = duration - (length ? durProgress : 0);
|
||||
propArray.push(keyObj);
|
||||
}
|
||||
}
|
||||
return key;
|
||||
});
|
||||
|
||||
for (let name in properties) {
|
||||
const propArray = /** @type {Array} */(properties[name]);
|
||||
let prevEase;
|
||||
// let durProgress = 0
|
||||
for (let i = 0, l = propArray.length; i < l; i++) {
|
||||
const prop = propArray[i];
|
||||
// Emulate WAPPI easing parameter position
|
||||
const currentEase = prop.ease;
|
||||
prop.ease = prevEase ? prevEase : undefined;
|
||||
prevEase = currentEase;
|
||||
// durProgress += prop.duration;
|
||||
// if (i === l - 1 && durProgress !== totalDuration) {
|
||||
// propArray.push({ from: prop.to, ease: prop.ease, duration: totalDuration - durProgress })
|
||||
// }
|
||||
}
|
||||
if (!propArray[0].duration) {
|
||||
propArray.shift();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return properties;
|
||||
};
|
||||
|
||||
class JSAnimation extends timer.Timer {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimationParams} parameters
|
||||
* @param {Timeline} [parent]
|
||||
* @param {Number} [parentPosition]
|
||||
* @param {Boolean} [fastSet=false]
|
||||
* @param {Number} [index=0]
|
||||
* @param {TargetsArray} [allTargets]
|
||||
*/
|
||||
constructor(
|
||||
targets$1,
|
||||
parameters,
|
||||
parent,
|
||||
parentPosition,
|
||||
fastSet = false,
|
||||
index = 0,
|
||||
allTargets
|
||||
) {
|
||||
|
||||
super(/** @type {TimerParams & AnimationParams} */(parameters), parent, parentPosition);
|
||||
|
||||
/** @type {Tween} */
|
||||
this._head;
|
||||
/** @type {Tween} */
|
||||
this._tail;
|
||||
|
||||
++JSAnimationId;
|
||||
|
||||
const parsedTargets = targets.registerTargets(targets$1);
|
||||
const targetsLength = parsedTargets.length;
|
||||
|
||||
// If the parameters object contains a "keyframes" property, convert all the keyframes values to regular properties
|
||||
|
||||
const kfParams = /** @type {AnimationParams} */(parameters).keyframes;
|
||||
const params = /** @type {AnimationParams} */(kfParams ? helpers.mergeObjects(generateKeyframes(/** @type {DurationKeyframes} */(kfParams), parameters), parameters) : parameters);
|
||||
|
||||
const {
|
||||
id,
|
||||
delay,
|
||||
duration,
|
||||
ease,
|
||||
playbackEase,
|
||||
modifier,
|
||||
composition: composition$1,
|
||||
onRender,
|
||||
} = params;
|
||||
|
||||
const animDefaults = parent ? parent.defaults : globals.globals.defaults;
|
||||
const animEase = values.setValue(ease, animDefaults.ease);
|
||||
const animPlaybackEase = values.setValue(playbackEase, animDefaults.playbackEase);
|
||||
const parsedAnimPlaybackEase = animPlaybackEase ? parser.parseEase(animPlaybackEase) : null;
|
||||
const hasSpring = !helpers.isUnd(/** @type {Spring} */(animEase).ease);
|
||||
const tEasing = hasSpring ? /** @type {Spring} */(animEase).ease : values.setValue(ease, parsedAnimPlaybackEase ? 'linear' : animDefaults.ease);
|
||||
const tDuration = hasSpring ? /** @type {Spring} */(animEase).settlingDuration : values.setValue(duration, animDefaults.duration);
|
||||
const tDelay = values.setValue(delay, animDefaults.delay);
|
||||
const tModifier = modifier || animDefaults.modifier;
|
||||
// If no composition is defined and the targets length is high (>= 1000) set the composition to 'none' (0) for faster tween creation
|
||||
const tComposition = helpers.isUnd(composition$1) && targetsLength >= consts.K ? consts.compositionTypes.none : !helpers.isUnd(composition$1) ? composition$1 : animDefaults.composition;
|
||||
// const absoluteOffsetTime = this._offset;
|
||||
const absoluteOffsetTime = this._offset + (parent ? parent._offset : 0);
|
||||
// This allows targeting the current animation in the spring onComplete callback
|
||||
if (hasSpring) /** @type {Spring} */(animEase).parent = this;
|
||||
|
||||
let iterationDuration = NaN;
|
||||
let iterationDelay = NaN;
|
||||
let animationAnimationLength = 0;
|
||||
let shouldTriggerRender = 0;
|
||||
|
||||
for (let targetIndex = 0; targetIndex < targetsLength; targetIndex++) {
|
||||
|
||||
const target = parsedTargets[targetIndex];
|
||||
const ti = index || targetIndex;
|
||||
const tl = allTargets || parsedTargets;
|
||||
|
||||
let lastTransformGroupIndex = NaN;
|
||||
let lastTransformGroupLength = NaN;
|
||||
|
||||
for (let p in params) {
|
||||
|
||||
if (helpers.isKey(p)) {
|
||||
|
||||
const tweenType = values.getTweenType(target, p);
|
||||
const adapterProp = registry.resolveAdapterEntry(target, p);
|
||||
|
||||
const propName = styles.sanitizePropertyName(p, target, tweenType);
|
||||
|
||||
let propValue = params[p];
|
||||
|
||||
const isPropValueArray = helpers.isArr(propValue);
|
||||
|
||||
if (fastSet && !isPropValueArray) {
|
||||
fastSetValuesArray[0] = propValue;
|
||||
fastSetValuesArray[1] = propValue;
|
||||
propValue = fastSetValuesArray;
|
||||
}
|
||||
|
||||
// TODO: Allow nested keyframes inside ObjectValue value (prop: { to: [.5, 1, .75, 2, 3] })
|
||||
// Normalize property values to valid keyframe syntax:
|
||||
// [x, y] to [{to: [x, y]}] or {to: x} to [{to: x}] or keep keys syntax [{}, {}, {}...]
|
||||
// const keyframes = isArr(propValue) ? propValue.length === 2 && !isObj(propValue[0]) ? [{ to: propValue }] : propValue : [propValue];
|
||||
if (isPropValueArray) {
|
||||
const arrayLength = /** @type {Array} */(propValue).length;
|
||||
const isNotObjectValue = !helpers.isObj(propValue[0]);
|
||||
// Convert [x, y] to [{to: [x, y]}]
|
||||
if (arrayLength === 2 && isNotObjectValue) {
|
||||
keyObjectTarget.to = /** @type {TweenParamValue} */(/** @type {unknown} */(propValue));
|
||||
keyframesTargetArray[0] = keyObjectTarget;
|
||||
keyframes = keyframesTargetArray;
|
||||
// Convert [x, y, z] to [[x, y], z]
|
||||
} else if (arrayLength > 2 && isNotObjectValue) {
|
||||
keyframes = [];
|
||||
/** @type {Array.<Number>} */(propValue).forEach((v, i) => {
|
||||
if (!i) {
|
||||
fastSetValuesArray[0] = v;
|
||||
} else if (i === 1) {
|
||||
fastSetValuesArray[1] = v;
|
||||
keyframes.push(fastSetValuesArray);
|
||||
} else {
|
||||
keyframes.push(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
keyframes = /** @type {Array.<TweenKeyValue>} */(propValue);
|
||||
}
|
||||
} else {
|
||||
keyframesTargetArray[0] = propValue;
|
||||
keyframes = keyframesTargetArray;
|
||||
}
|
||||
|
||||
let siblings = null;
|
||||
let prevTween = null;
|
||||
let firstTweenChangeStartTime = NaN;
|
||||
let lastTweenChangeEndTime = 0;
|
||||
let tweenIndex = 0;
|
||||
|
||||
for (let l = keyframes.length; tweenIndex < l; tweenIndex++) {
|
||||
|
||||
const keyframe = keyframes[tweenIndex];
|
||||
|
||||
if (helpers.isObj(keyframe)) {
|
||||
key = keyframe;
|
||||
} else {
|
||||
keyObjectTarget.to = /** @type {TweenParamValue} */(keyframe);
|
||||
key = keyObjectTarget;
|
||||
}
|
||||
|
||||
toFunctionStore.func = null;
|
||||
fromFunctionStore.func = null;
|
||||
|
||||
const computedComposition = values.getFunctionValue(values.setValue(key.composition, tComposition), target, ti, tl, null, null);
|
||||
const tweenComposition = helpers.isNum(computedComposition) ? computedComposition : consts.compositionTypes[computedComposition];
|
||||
if (!siblings && tweenComposition !== consts.compositionTypes.none) siblings = composition.getTweenSiblings(target, propName);
|
||||
// Timelines pass the last sibling tween if it belongs to the same timeline
|
||||
// Standalone animations only pass prevTween when the property has multiple keyframes
|
||||
const tailTween = siblings ? siblings._tail : null;
|
||||
const prevSiblingTween = parent && tailTween && tailTween.parent.parent === parent ? tailTween : prevTween;
|
||||
const computedToValue = values.getFunctionValue(key.to, target, ti, tl, toFunctionStore, prevSiblingTween);
|
||||
|
||||
let tweenToValue;
|
||||
// Allows function based values to return an object syntax value ({to: v})
|
||||
if (helpers.isObj(computedToValue) && !helpers.isUnd(computedToValue.to)) {
|
||||
key = computedToValue;
|
||||
tweenToValue = computedToValue.to;
|
||||
} else {
|
||||
tweenToValue = computedToValue;
|
||||
}
|
||||
const tweenFromValue = values.getFunctionValue(key.from, target, ti, tl, fromFunctionStore, prevSiblingTween);
|
||||
const easeToParse = key.ease || tEasing;
|
||||
|
||||
const easeFunctionResult = values.getFunctionValue(easeToParse, target, ti, tl, null, prevSiblingTween);
|
||||
const keyEasing = helpers.isFnc(easeFunctionResult) || helpers.isStr(easeFunctionResult) ? easeFunctionResult : easeToParse;
|
||||
|
||||
const hasSpring = !helpers.isUnd(keyEasing) && !helpers.isUnd(/** @type {Spring} */(keyEasing).ease);
|
||||
const tweenEasing = hasSpring ? /** @type {Spring} */(keyEasing).ease : keyEasing;
|
||||
// Calculate default individual keyframe duration by dividing the tl of keyframes
|
||||
const tweenDuration = hasSpring ? /** @type {Spring} */(keyEasing).settlingDuration : values.getFunctionValue(values.setValue(key.duration, (l > 1 ? values.getFunctionValue(tDuration, target, ti, tl, null, prevSiblingTween) / l : tDuration)), target, ti, tl, null, prevSiblingTween);
|
||||
// Default delay value should only be applied to the first tween
|
||||
const tweenDelay = values.getFunctionValue(values.setValue(key.delay, (!tweenIndex ? tDelay : 0)), target, ti, tl, null, prevSiblingTween);
|
||||
// Modifiers are treated differently and don't accept function based value to prevent having to pass a function wrapper
|
||||
const tweenModifier = key.modifier || tModifier;
|
||||
const hasFromvalue = !helpers.isUnd(tweenFromValue);
|
||||
const hasToValue = !helpers.isUnd(tweenToValue);
|
||||
const isFromToArray = helpers.isArr(tweenToValue);
|
||||
const isFromToValue = isFromToArray || (hasFromvalue && hasToValue);
|
||||
// Capture the update-start in local time, the previous sibling's end for keyframes after the first, zero for the first keyframe. Used to derive a precision-matched _absoluteUpdateStartTime below.
|
||||
const tweenUpdateStartLocal = prevTween ? lastTweenChangeEndTime : 0;
|
||||
const tweenStartTime = prevTween ? lastTweenChangeEndTime + tweenDelay : tweenDelay;
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const absoluteStartTime = helpers.round(absoluteOffsetTime + tweenStartTime, 12);
|
||||
// Match the rounding pattern of prevSibling._absoluteEndTime so the composition overlap check compares cleanly when keyframes touch at a boundary.
|
||||
const absoluteUpdateStartTime = helpers.round(absoluteOffsetTime + tweenUpdateStartLocal, 12);
|
||||
|
||||
// Force a onRender callback if the animation contains at least one from value and autoplay is set to false
|
||||
if (!shouldTriggerRender && (hasFromvalue || isFromToArray)) shouldTriggerRender = 1;
|
||||
|
||||
let prevSibling = prevTween;
|
||||
|
||||
if (tweenComposition !== consts.compositionTypes.none) {
|
||||
let nextSibling = siblings._head;
|
||||
// Walk prior siblings up to the new tween, skipping overridden ones so the chain resolves to the latest live value instead of stopping at the first override.
|
||||
while (nextSibling && nextSibling._absoluteStartTime <= absoluteStartTime) {
|
||||
if (!nextSibling._isOverridden) prevSibling = nextSibling;
|
||||
nextSibling = nextSibling._nextRep;
|
||||
// Overrides all the next siblings if the next sibling starts at the same time of after as the new tween start time
|
||||
if (nextSibling && nextSibling._absoluteStartTime >= absoluteStartTime) {
|
||||
while (nextSibling) {
|
||||
composition.overrideTween(nextSibling);
|
||||
// This will ends both the current while loop and the upper one once all the next sibllings have been overriden
|
||||
nextSibling = nextSibling._nextRep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decompose values
|
||||
if (isFromToValue) {
|
||||
values.decomposeRawValue(isFromToArray ? values.getFunctionValue(tweenToValue[0], target, ti, tl, fromFunctionStore, prevSiblingTween) : tweenFromValue, fromTargetObject);
|
||||
values.decomposeRawValue(isFromToArray ? values.getFunctionValue(tweenToValue[1], target, ti, tl, toFunctionStore, prevSiblingTween) : tweenToValue, toTargetObject);
|
||||
// Needed to force an inline style registration
|
||||
const originalValue = values.getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore);
|
||||
if (fromTargetObject.t === consts.valueTypes.NUMBER) {
|
||||
if (prevSibling) {
|
||||
if (prevSibling._valueType === consts.valueTypes.UNIT) {
|
||||
fromTargetObject.t = consts.valueTypes.UNIT;
|
||||
fromTargetObject.u = prevSibling._unit;
|
||||
}
|
||||
} else {
|
||||
values.decomposeRawValue(
|
||||
originalValue,
|
||||
values.decomposedOriginalValue
|
||||
);
|
||||
if (values.decomposedOriginalValue.t === consts.valueTypes.UNIT) {
|
||||
fromTargetObject.t = consts.valueTypes.UNIT;
|
||||
fromTargetObject.u = values.decomposedOriginalValue.u;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasToValue) {
|
||||
values.decomposeRawValue(tweenToValue, toTargetObject);
|
||||
} else {
|
||||
if (prevTween) {
|
||||
values.decomposeTweenValue(prevTween, toTargetObject);
|
||||
} else {
|
||||
// No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
|
||||
values.decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
|
||||
values.getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore), toTargetObject);
|
||||
}
|
||||
}
|
||||
if (hasFromvalue) {
|
||||
values.decomposeRawValue(tweenFromValue, fromTargetObject);
|
||||
} else {
|
||||
if (prevTween) {
|
||||
values.decomposeTweenValue(prevTween, fromTargetObject);
|
||||
} else {
|
||||
// No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
|
||||
values.decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
|
||||
values.getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore), fromTargetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply operators
|
||||
if (fromTargetObject.o) {
|
||||
fromTargetObject.n = values.getRelativeValue(
|
||||
!prevSibling ? values.decomposeRawValue(
|
||||
values.getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore),
|
||||
values.decomposedOriginalValue
|
||||
).n : prevSibling._toNumber,
|
||||
fromTargetObject.n,
|
||||
fromTargetObject.o
|
||||
);
|
||||
}
|
||||
|
||||
if (toTargetObject.o) {
|
||||
toTargetObject.n = values.getRelativeValue(fromTargetObject.n, toTargetObject.n, toTargetObject.o);
|
||||
}
|
||||
|
||||
// Values omogenisation in cases of type difference between "from" and "to"
|
||||
if (fromTargetObject.t !== toTargetObject.t) {
|
||||
if (fromTargetObject.t === consts.valueTypes.COMPLEX || toTargetObject.t === consts.valueTypes.COMPLEX) {
|
||||
const complexValue = fromTargetObject.t === consts.valueTypes.COMPLEX ? fromTargetObject : toTargetObject;
|
||||
const notComplexValue = fromTargetObject.t === consts.valueTypes.COMPLEX ? toTargetObject : fromTargetObject;
|
||||
notComplexValue.t = consts.valueTypes.COMPLEX;
|
||||
notComplexValue.s = helpers.cloneArray(complexValue.s);
|
||||
notComplexValue.d = complexValue.d.map(() => notComplexValue.n);
|
||||
} else if (fromTargetObject.t === consts.valueTypes.UNIT || toTargetObject.t === consts.valueTypes.UNIT) {
|
||||
const unitValue = fromTargetObject.t === consts.valueTypes.UNIT ? fromTargetObject : toTargetObject;
|
||||
const notUnitValue = fromTargetObject.t === consts.valueTypes.UNIT ? toTargetObject : fromTargetObject;
|
||||
notUnitValue.t = consts.valueTypes.UNIT;
|
||||
notUnitValue.u = unitValue.u;
|
||||
} else if (fromTargetObject.t === consts.valueTypes.COLOR || toTargetObject.t === consts.valueTypes.COLOR) {
|
||||
const colorValue = fromTargetObject.t === consts.valueTypes.COLOR ? fromTargetObject : toTargetObject;
|
||||
const notColorValue = fromTargetObject.t === consts.valueTypes.COLOR ? toTargetObject : fromTargetObject;
|
||||
notColorValue.t = consts.valueTypes.COLOR;
|
||||
notColorValue.d = colorValue.d.map(() => 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Unit conversion
|
||||
if (fromTargetObject.u !== toTargetObject.u) {
|
||||
let valueToConvert = toTargetObject.u ? fromTargetObject : toTargetObject;
|
||||
valueToConvert = units.convertValueUnit(/** @type {DOMTarget} */(target), valueToConvert, toTargetObject.u ? toTargetObject.u : fromTargetObject.u, false);
|
||||
// TODO:
|
||||
// convertValueUnit(target, to.u ? from : to, to.u ? to.u : from.u);
|
||||
}
|
||||
|
||||
// Fill in non existing complex values
|
||||
if (toTargetObject.d && fromTargetObject.d && (toTargetObject.d.length !== fromTargetObject.d.length)) {
|
||||
const longestValue = fromTargetObject.d.length > toTargetObject.d.length ? fromTargetObject : toTargetObject;
|
||||
const shortestValue = longestValue === fromTargetObject ? toTargetObject : fromTargetObject;
|
||||
// TODO: Check if n should be used instead of 0 for default complex values
|
||||
shortestValue.d = longestValue.d.map((/** @type {Number} */_, /** @type {Number} */i) => helpers.isUnd(shortestValue.d[i]) ? 0 : shortestValue.d[i]);
|
||||
shortestValue.s = helpers.cloneArray(longestValue.s);
|
||||
}
|
||||
|
||||
// Tween factory
|
||||
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const tweenUpdateDuration = helpers.round(+tweenDuration || consts.minValue, 12);
|
||||
|
||||
// Copy the value of the iniline style if it exist and imediatly nullify it to prevents false positive on other targets
|
||||
let inlineValue = inlineStylesStore[propName];
|
||||
if (!helpers.isNil(inlineValue)) inlineStylesStore[propName] = null;
|
||||
|
||||
// Resolve the adapter setter once so render skips the lookup per frame.
|
||||
const tweenSetter = adapterProp ? adapterProp.set : null;
|
||||
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
lastTweenChangeEndTime = helpers.round(tweenStartTime + tweenUpdateDuration, 12);
|
||||
|
||||
const fromD = fromTargetObject.d;
|
||||
const toD = toTargetObject.d;
|
||||
const toS = toTargetObject.s;
|
||||
|
||||
/** @type {Tween} */
|
||||
const tween = {
|
||||
parent: this,
|
||||
id: tweenId++,
|
||||
property: propName,
|
||||
target: target,
|
||||
_value: null,
|
||||
_toFunc: toFunctionStore.func,
|
||||
_fromFunc: fromFunctionStore.func,
|
||||
_ease: parser.parseEase(tweenEasing),
|
||||
_fromNumbers: fromD ? helpers.cloneArray(fromD) : consts.emptyArray,
|
||||
_toNumbers: toD ? helpers.cloneArray(toD) : consts.emptyArray,
|
||||
_strings: toS ? helpers.cloneArray(toS) : consts.emptyArray,
|
||||
_fromNumber: fromTargetObject.n,
|
||||
_toNumber: toTargetObject.n,
|
||||
_numbers: fromD ? helpers.cloneArray(fromD) : consts.emptyArray, // For additive tween and animatables
|
||||
_number: fromTargetObject.n, // For additive tween and animatables
|
||||
_unit: toTargetObject.u,
|
||||
_modifier: tweenModifier,
|
||||
_currentTime: 0,
|
||||
_startTime: tweenStartTime,
|
||||
_delay: +tweenDelay,
|
||||
_updateDuration: tweenUpdateDuration,
|
||||
_changeDuration: tweenUpdateDuration,
|
||||
_absoluteStartTime: absoluteStartTime,
|
||||
_absoluteUpdateStartTime: absoluteUpdateStartTime,
|
||||
_absoluteEndTime: helpers.round(absoluteOffsetTime + lastTweenChangeEndTime, 12),
|
||||
_hasFromValue: hasFromvalue || isFromToArray ? 1 : 0,
|
||||
// NOTE: Investigate bit packing to stores ENUM / BOOL
|
||||
_tweenType: tweenType,
|
||||
_setter: tweenSetter,
|
||||
_valueType: toTargetObject.t,
|
||||
_composition: tweenComposition,
|
||||
_isOverlapped: 0,
|
||||
_isOverridden: 0,
|
||||
_renderTransforms: 0,
|
||||
_inlineValue: inlineValue,
|
||||
_prevRep: null, // For replaced tween
|
||||
_nextRep: null, // For replaced tween
|
||||
_prevAdd: null, // For additive tween
|
||||
_nextAdd: null, // For additive tween
|
||||
_prev: null,
|
||||
_next: null,
|
||||
};
|
||||
|
||||
if (tweenComposition !== consts.compositionTypes.none) {
|
||||
composition.composeTween(tween, siblings);
|
||||
}
|
||||
|
||||
// Pre-compute the tween end value for function-based value chaining (ie morphTo / scrambleText in keyframe arrays and timelines)
|
||||
const vt = tween._valueType;
|
||||
if (vt === consts.valueTypes.COMPLEX) {
|
||||
tween._value = values.composeComplexValue(tween, 1, -1);
|
||||
} else if (vt === consts.valueTypes.UNIT) {
|
||||
tween._value = `${tweenModifier(tween._toNumber)}${tween._unit}`;
|
||||
} else if (vt === consts.valueTypes.COLOR) {
|
||||
const d = toTargetObject.d;
|
||||
tween._value = `rgba(${helpers.round(d[0], 0)},${helpers.round(d[1], 0)},${helpers.round(d[2], 0)},${d[3]})`;
|
||||
} else {
|
||||
tween._value = tweenModifier(tween._toNumber);
|
||||
}
|
||||
|
||||
if (isNaN(firstTweenChangeStartTime)) {
|
||||
firstTweenChangeStartTime = tween._startTime;
|
||||
}
|
||||
|
||||
prevTween = tween;
|
||||
animationAnimationLength++;
|
||||
|
||||
helpers.addChild(this, tween);
|
||||
|
||||
}
|
||||
|
||||
// Update animation timings with the added tweens properties
|
||||
|
||||
if (isNaN(iterationDelay) || firstTweenChangeStartTime < iterationDelay) {
|
||||
iterationDelay = firstTweenChangeStartTime;
|
||||
}
|
||||
|
||||
if (isNaN(iterationDuration) || lastTweenChangeEndTime > iterationDuration) {
|
||||
iterationDuration = lastTweenChangeEndTime;
|
||||
}
|
||||
|
||||
// TODO: Find a way to inline tween._renderTransforms = 1 here
|
||||
if (tweenType === consts.tweenTypes.TRANSFORM) {
|
||||
lastTransformGroupIndex = animationAnimationLength - tweenIndex;
|
||||
lastTransformGroupLength = animationAnimationLength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Set _renderTransforms to last transform property to correctly render the transforms list
|
||||
if (!isNaN(lastTransformGroupIndex)) {
|
||||
let i = 0;
|
||||
helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
if (i >= lastTransformGroupIndex && i < lastTransformGroupLength) {
|
||||
tween._renderTransforms = 1;
|
||||
if (tween._composition === consts.compositionTypes.blend) {
|
||||
helpers.forEachChildren(additive.additive.animation, (/** @type {Tween} */additiveTween) => {
|
||||
if (additiveTween.id === tween.id) {
|
||||
additiveTween._renderTransforms = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
i++;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!targetsLength) {
|
||||
console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
|
||||
}
|
||||
|
||||
if (iterationDelay) {
|
||||
helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
// If (startTime - delay) equals 0, this means the tween is at the begining of the animation so we need to trim the delay too
|
||||
if (!(tween._startTime - tween._delay)) {
|
||||
tween._delay -= iterationDelay;
|
||||
}
|
||||
tween._startTime -= iterationDelay;
|
||||
});
|
||||
iterationDuration -= iterationDelay;
|
||||
} else {
|
||||
iterationDelay = 0;
|
||||
}
|
||||
|
||||
// Prevents iterationDuration to be NaN if no valid animatable props have been provided
|
||||
// Prevents _iterationCount to be NaN if no valid animatable props have been provided
|
||||
if (!iterationDuration) {
|
||||
iterationDuration = consts.minValue;
|
||||
this.iterationCount = 0;
|
||||
}
|
||||
/** @type {TargetsArray} */
|
||||
this.targets = parsedTargets;
|
||||
/** @type {String|Number} */
|
||||
this.id = !helpers.isUnd(id) ? id : JSAnimationId;
|
||||
/** @type {Number} */
|
||||
this.duration = iterationDuration === consts.minValue ? consts.minValue : helpers.clampInfinity(((iterationDuration + this._loopDelay) * this.iterationCount) - this._loopDelay) || consts.minValue;
|
||||
/** @type {Callback<this>} */
|
||||
this.onRender = onRender || animDefaults.onRender;
|
||||
/** @type {EasingFunction} */
|
||||
this._ease = parsedAnimPlaybackEase;
|
||||
/** @type {Number} */
|
||||
this._delay = iterationDelay;
|
||||
// NOTE: I'm keeping delay values separated from offsets in timelines because delays can override previous tweens and it could be confusing to debug a timeline with overridden tweens and no associated visible delays.
|
||||
// this._delay = parent ? 0 : iterationDelay;
|
||||
// this._offset += parent ? iterationDelay : 0;
|
||||
/** @type {Number} */
|
||||
this.iterationDuration = iterationDuration;
|
||||
|
||||
if (!this._autoplay && shouldTriggerRender) this.onRender(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} newDuration
|
||||
* @return {this}
|
||||
*/
|
||||
stretch(newDuration) {
|
||||
const currentDuration = this.duration;
|
||||
if (currentDuration === helpers.normalizeTime(newDuration)) return this;
|
||||
const timeScale = newDuration / currentDuration;
|
||||
// NOTE: Find a better way to handle the stretch of an animation after stretch = 0
|
||||
helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
// Rounding is necessary here to minimize floating point errors
|
||||
tween._updateDuration = helpers.normalizeTime(tween._updateDuration * timeScale);
|
||||
tween._changeDuration = helpers.normalizeTime(tween._changeDuration * timeScale);
|
||||
tween._currentTime *= timeScale;
|
||||
tween._delay *= timeScale;
|
||||
tween._startTime *= timeScale;
|
||||
tween._absoluteStartTime *= timeScale;
|
||||
tween._absoluteUpdateStartTime *= timeScale;
|
||||
tween._absoluteEndTime *= timeScale;
|
||||
});
|
||||
return super.stretch(newDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {this}
|
||||
*/
|
||||
refresh() {
|
||||
helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
const toFunc = tween._toFunc;
|
||||
const fromFunc = tween._fromFunc;
|
||||
if (toFunc || fromFunc) {
|
||||
if (fromFunc) {
|
||||
values.decomposeRawValue(fromFunc(), fromTargetObject);
|
||||
if (fromTargetObject.u !== tween._unit && tween.target[consts.isDomSymbol]) {
|
||||
units.convertValueUnit(/** @type {DOMTarget} */(tween.target), fromTargetObject, tween._unit, true);
|
||||
}
|
||||
tween._fromNumbers = helpers.cloneArray(fromTargetObject.d);
|
||||
tween._fromNumber = fromTargetObject.n;
|
||||
} else if (toFunc) {
|
||||
// When only toFunc exists, get from value from target
|
||||
values.decomposeRawValue(values.getOriginalAnimatableValue(tween.target, tween.property, tween._tweenType), values.decomposedOriginalValue);
|
||||
tween._fromNumbers = helpers.cloneArray(values.decomposedOriginalValue.d);
|
||||
tween._fromNumber = values.decomposedOriginalValue.n;
|
||||
}
|
||||
if (toFunc) {
|
||||
values.decomposeRawValue(toFunc(), toTargetObject);
|
||||
tween._toNumbers = helpers.cloneArray(toTargetObject.d);
|
||||
tween._strings = helpers.cloneArray(toTargetObject.s);
|
||||
// Make sure to apply relative operators https://github.com/juliangarnier/anime/issues/1025
|
||||
tween._toNumber = toTargetObject.o ? values.getRelativeValue(tween._fromNumber, toTargetObject.n, toTargetObject.o) : toTargetObject.n;
|
||||
}
|
||||
}
|
||||
});
|
||||
// This forces setter animations to render once
|
||||
if (this.duration === consts.minValue) this.restart();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the animation and revert all the values affected by this animation to their original state
|
||||
* @return {this}
|
||||
*/
|
||||
revert() {
|
||||
super.revert();
|
||||
return styles.revertValues(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {this & {then: null}} ResolvedJSAnimation
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Callback<ResolvedJSAnimation>} [callback]
|
||||
* @return Promise<this>
|
||||
*/
|
||||
then(callback) {
|
||||
return super.then(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimationParams} parameters
|
||||
* @return {JSAnimation}
|
||||
*/
|
||||
const animate = (targets, parameters) => {
|
||||
if (globals.globals.editor) {
|
||||
return globals.globals.editor.addAnimation(targets, parameters);
|
||||
} else {
|
||||
return new JSAnimation(targets, parameters, null, 0, false).init();
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSAnimation = JSAnimation;
|
||||
exports.animate = animate;
|
||||
@@ -0,0 +1,55 @@
|
||||
export class JSAnimation extends Timer {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimationParams} parameters
|
||||
* @param {Timeline} [parent]
|
||||
* @param {Number} [parentPosition]
|
||||
* @param {Boolean} [fastSet=false]
|
||||
* @param {Number} [index=0]
|
||||
* @param {TargetsArray} [allTargets]
|
||||
*/
|
||||
constructor(targets: TargetsParam, parameters: AnimationParams, parent?: Timeline, parentPosition?: number, fastSet?: boolean, index?: number, allTargets?: TargetsArray);
|
||||
/** @type {Tween} */
|
||||
_head: Tween;
|
||||
/** @type {Tween} */
|
||||
_tail: Tween;
|
||||
/** @type {TargetsArray} */
|
||||
targets: TargetsArray;
|
||||
/** @type {Callback<this>} */
|
||||
onRender: Callback<this>;
|
||||
/** @type {EasingFunction} */
|
||||
_ease: EasingFunction;
|
||||
/**
|
||||
* @param {Number} newDuration
|
||||
* @return {this}
|
||||
*/
|
||||
stretch(newDuration: number): this;
|
||||
/**
|
||||
* @return {this}
|
||||
*/
|
||||
refresh(): this;
|
||||
/**
|
||||
* Cancel the animation and revert all the values affected by this animation to their original state
|
||||
* @return {this}
|
||||
*/
|
||||
revert(): this;
|
||||
/**
|
||||
* @typedef {this & {then: null}} ResolvedJSAnimation
|
||||
*/
|
||||
/**
|
||||
* @param {Callback<ResolvedJSAnimation>} [callback]
|
||||
* @return Promise<this>
|
||||
*/
|
||||
then(callback?: Callback<this & {
|
||||
then: null;
|
||||
}>): Promise<any>;
|
||||
}
|
||||
export function animate(targets: TargetsParam, parameters: AnimationParams): JSAnimation;
|
||||
import { Timer } from '../timer/timer.js';
|
||||
import type { Tween } from '../types/index.js';
|
||||
import type { TargetsArray } from '../types/index.js';
|
||||
import type { Callback } from '../types/index.js';
|
||||
import type { EasingFunction } from '../types/index.js';
|
||||
import type { TargetsParam } from '../types/index.js';
|
||||
import type { AnimationParams } from '../types/index.js';
|
||||
import type { Timeline } from '../timeline/timeline.js';
|
||||
@@ -0,0 +1,743 @@
|
||||
/**
|
||||
* Anime.js - animation - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { K, compositionTypes, valueTypes, emptyArray, minValue, isDomSymbol, tweenTypes } from '../core/consts.js';
|
||||
import { mergeObjects, isUnd, isKey, isObj, cloneArray, isNil, round, addChild, forEachChildren, clampInfinity, normalizeTime, isArr, isNum, isFnc, isStr } from '../core/helpers.js';
|
||||
import { globals } from '../core/globals.js';
|
||||
import { registerTargets } from '../core/targets.js';
|
||||
import { resolveAdapterEntry } from '../adapters/registry.js';
|
||||
import { setValue, getTweenType, getFunctionValue, decomposeRawValue, getOriginalAnimatableValue, createDecomposedValueTargetObject, decomposedOriginalValue, getRelativeValue, composeComplexValue, decomposeTweenValue } from '../core/values.js';
|
||||
import { sanitizePropertyName, revertValues } from '../core/styles.js';
|
||||
import { convertValueUnit } from '../core/units.js';
|
||||
import { parseEase } from '../easings/eases/parser.js';
|
||||
import { Timer } from '../timer/timer.js';
|
||||
import { getTweenSiblings, overrideTween, composeTween } from './composition.js';
|
||||
import { additive } from './additive.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tween,
|
||||
* TweenKeyValue,
|
||||
* TweenParamsOptions,
|
||||
* TweenValues,
|
||||
* DurationKeyframes,
|
||||
* PercentageKeyframes,
|
||||
* AnimationParams,
|
||||
* TweenPropValue,
|
||||
* ArraySyntaxValue,
|
||||
* TargetsParam,
|
||||
* TimerParams,
|
||||
* TweenParamValue,
|
||||
* DOMTarget,
|
||||
* TargetsArray,
|
||||
* Callback,
|
||||
* EasingFunction,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* Timeline,
|
||||
* } from '../timeline/timeline.js'
|
||||
*
|
||||
* @import {
|
||||
* Spring,
|
||||
* } from '../easings/spring/index.js'
|
||||
*/
|
||||
|
||||
// Defines decomposed values target objects only once and mutate their properties later to avoid GC
|
||||
// TODO: Maybe move the objects creation to values.js and use the decompose function to create the base object
|
||||
const fromTargetObject = createDecomposedValueTargetObject();
|
||||
const toTargetObject = createDecomposedValueTargetObject();
|
||||
const inlineStylesStore = {};
|
||||
const toFunctionStore = { func: null };
|
||||
const fromFunctionStore = { func: null };
|
||||
const keyframesTargetArray = [null];
|
||||
const fastSetValuesArray = [null, null];
|
||||
/** @type {TweenKeyValue} */
|
||||
const keyObjectTarget = { to: null };
|
||||
|
||||
let tweenId = 0;
|
||||
let JSAnimationId = 0;
|
||||
let keyframes;
|
||||
/** @type {TweenParamsOptions & TweenValues} */
|
||||
let key;
|
||||
|
||||
/**
|
||||
* @param {DurationKeyframes | PercentageKeyframes} keyframes
|
||||
* @param {AnimationParams} parameters
|
||||
* @return {AnimationParams}
|
||||
*/
|
||||
const generateKeyframes = (keyframes, parameters) => {
|
||||
/** @type {AnimationParams} */
|
||||
const properties = {};
|
||||
if (isArr(keyframes)) {
|
||||
const propertyNames = [].concat(.../** @type {DurationKeyframes} */(keyframes).map(key => Object.keys(key))).filter(isKey);
|
||||
for (let i = 0, l = propertyNames.length; i < l; i++) {
|
||||
const propName = propertyNames[i];
|
||||
const propArray = /** @type {DurationKeyframes} */(keyframes).map(key => {
|
||||
/** @type {TweenKeyValue} */
|
||||
const newKey = {};
|
||||
for (let p in key) {
|
||||
const keyValue = /** @type {TweenPropValue} */(key[p]);
|
||||
if (isKey(p)) {
|
||||
if (p === propName) {
|
||||
newKey.to = keyValue;
|
||||
}
|
||||
} else {
|
||||
newKey[p] = keyValue;
|
||||
}
|
||||
}
|
||||
return newKey;
|
||||
});
|
||||
properties[propName] = /** @type {ArraySyntaxValue} */(propArray);
|
||||
}
|
||||
|
||||
} else {
|
||||
const totalDuration = /** @type {Number} */(setValue(parameters.duration, globals.defaults.duration));
|
||||
const keys = Object.keys(keyframes)
|
||||
.map(key => { return {o: parseFloat(key) / 100, p: keyframes[key]} })
|
||||
.sort((a, b) => a.o - b.o);
|
||||
keys.forEach(key => {
|
||||
const offset = key.o;
|
||||
const prop = key.p;
|
||||
for (let name in prop) {
|
||||
if (isKey(name)) {
|
||||
let propArray = /** @type {Array} */(properties[name]);
|
||||
if (!propArray) propArray = properties[name] = [];
|
||||
const duration = offset * totalDuration;
|
||||
let length = propArray.length;
|
||||
let prevKey = propArray[length - 1];
|
||||
const keyObj = { to: prop[name] };
|
||||
let durProgress = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
durProgress += propArray[i].duration;
|
||||
}
|
||||
if (length === 1) {
|
||||
keyObj.from = prevKey.to;
|
||||
}
|
||||
if (prop.ease) {
|
||||
keyObj.ease = prop.ease;
|
||||
}
|
||||
keyObj.duration = duration - (length ? durProgress : 0);
|
||||
propArray.push(keyObj);
|
||||
}
|
||||
}
|
||||
return key;
|
||||
});
|
||||
|
||||
for (let name in properties) {
|
||||
const propArray = /** @type {Array} */(properties[name]);
|
||||
let prevEase;
|
||||
// let durProgress = 0
|
||||
for (let i = 0, l = propArray.length; i < l; i++) {
|
||||
const prop = propArray[i];
|
||||
// Emulate WAPPI easing parameter position
|
||||
const currentEase = prop.ease;
|
||||
prop.ease = prevEase ? prevEase : undefined;
|
||||
prevEase = currentEase;
|
||||
// durProgress += prop.duration;
|
||||
// if (i === l - 1 && durProgress !== totalDuration) {
|
||||
// propArray.push({ from: prop.to, ease: prop.ease, duration: totalDuration - durProgress })
|
||||
// }
|
||||
}
|
||||
if (!propArray[0].duration) {
|
||||
propArray.shift();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return properties;
|
||||
};
|
||||
|
||||
class JSAnimation extends Timer {
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimationParams} parameters
|
||||
* @param {Timeline} [parent]
|
||||
* @param {Number} [parentPosition]
|
||||
* @param {Boolean} [fastSet=false]
|
||||
* @param {Number} [index=0]
|
||||
* @param {TargetsArray} [allTargets]
|
||||
*/
|
||||
constructor(
|
||||
targets,
|
||||
parameters,
|
||||
parent,
|
||||
parentPosition,
|
||||
fastSet = false,
|
||||
index = 0,
|
||||
allTargets
|
||||
) {
|
||||
|
||||
super(/** @type {TimerParams & AnimationParams} */(parameters), parent, parentPosition);
|
||||
|
||||
/** @type {Tween} */
|
||||
this._head;
|
||||
/** @type {Tween} */
|
||||
this._tail;
|
||||
|
||||
++JSAnimationId;
|
||||
|
||||
const parsedTargets = registerTargets(targets);
|
||||
const targetsLength = parsedTargets.length;
|
||||
|
||||
// If the parameters object contains a "keyframes" property, convert all the keyframes values to regular properties
|
||||
|
||||
const kfParams = /** @type {AnimationParams} */(parameters).keyframes;
|
||||
const params = /** @type {AnimationParams} */(kfParams ? mergeObjects(generateKeyframes(/** @type {DurationKeyframes} */(kfParams), parameters), parameters) : parameters);
|
||||
|
||||
const {
|
||||
id,
|
||||
delay,
|
||||
duration,
|
||||
ease,
|
||||
playbackEase,
|
||||
modifier,
|
||||
composition,
|
||||
onRender,
|
||||
} = params;
|
||||
|
||||
const animDefaults = parent ? parent.defaults : globals.defaults;
|
||||
const animEase = setValue(ease, animDefaults.ease);
|
||||
const animPlaybackEase = setValue(playbackEase, animDefaults.playbackEase);
|
||||
const parsedAnimPlaybackEase = animPlaybackEase ? parseEase(animPlaybackEase) : null;
|
||||
const hasSpring = !isUnd(/** @type {Spring} */(animEase).ease);
|
||||
const tEasing = hasSpring ? /** @type {Spring} */(animEase).ease : setValue(ease, parsedAnimPlaybackEase ? 'linear' : animDefaults.ease);
|
||||
const tDuration = hasSpring ? /** @type {Spring} */(animEase).settlingDuration : setValue(duration, animDefaults.duration);
|
||||
const tDelay = setValue(delay, animDefaults.delay);
|
||||
const tModifier = modifier || animDefaults.modifier;
|
||||
// If no composition is defined and the targets length is high (>= 1000) set the composition to 'none' (0) for faster tween creation
|
||||
const tComposition = isUnd(composition) && targetsLength >= K ? compositionTypes.none : !isUnd(composition) ? composition : animDefaults.composition;
|
||||
// const absoluteOffsetTime = this._offset;
|
||||
const absoluteOffsetTime = this._offset + (parent ? parent._offset : 0);
|
||||
// This allows targeting the current animation in the spring onComplete callback
|
||||
if (hasSpring) /** @type {Spring} */(animEase).parent = this;
|
||||
|
||||
let iterationDuration = NaN;
|
||||
let iterationDelay = NaN;
|
||||
let animationAnimationLength = 0;
|
||||
let shouldTriggerRender = 0;
|
||||
|
||||
for (let targetIndex = 0; targetIndex < targetsLength; targetIndex++) {
|
||||
|
||||
const target = parsedTargets[targetIndex];
|
||||
const ti = index || targetIndex;
|
||||
const tl = allTargets || parsedTargets;
|
||||
|
||||
let lastTransformGroupIndex = NaN;
|
||||
let lastTransformGroupLength = NaN;
|
||||
|
||||
for (let p in params) {
|
||||
|
||||
if (isKey(p)) {
|
||||
|
||||
const tweenType = getTweenType(target, p);
|
||||
const adapterProp = resolveAdapterEntry(target, p);
|
||||
|
||||
const propName = sanitizePropertyName(p, target, tweenType);
|
||||
|
||||
let propValue = params[p];
|
||||
|
||||
const isPropValueArray = isArr(propValue);
|
||||
|
||||
if (fastSet && !isPropValueArray) {
|
||||
fastSetValuesArray[0] = propValue;
|
||||
fastSetValuesArray[1] = propValue;
|
||||
propValue = fastSetValuesArray;
|
||||
}
|
||||
|
||||
// TODO: Allow nested keyframes inside ObjectValue value (prop: { to: [.5, 1, .75, 2, 3] })
|
||||
// Normalize property values to valid keyframe syntax:
|
||||
// [x, y] to [{to: [x, y]}] or {to: x} to [{to: x}] or keep keys syntax [{}, {}, {}...]
|
||||
// const keyframes = isArr(propValue) ? propValue.length === 2 && !isObj(propValue[0]) ? [{ to: propValue }] : propValue : [propValue];
|
||||
if (isPropValueArray) {
|
||||
const arrayLength = /** @type {Array} */(propValue).length;
|
||||
const isNotObjectValue = !isObj(propValue[0]);
|
||||
// Convert [x, y] to [{to: [x, y]}]
|
||||
if (arrayLength === 2 && isNotObjectValue) {
|
||||
keyObjectTarget.to = /** @type {TweenParamValue} */(/** @type {unknown} */(propValue));
|
||||
keyframesTargetArray[0] = keyObjectTarget;
|
||||
keyframes = keyframesTargetArray;
|
||||
// Convert [x, y, z] to [[x, y], z]
|
||||
} else if (arrayLength > 2 && isNotObjectValue) {
|
||||
keyframes = [];
|
||||
/** @type {Array.<Number>} */(propValue).forEach((v, i) => {
|
||||
if (!i) {
|
||||
fastSetValuesArray[0] = v;
|
||||
} else if (i === 1) {
|
||||
fastSetValuesArray[1] = v;
|
||||
keyframes.push(fastSetValuesArray);
|
||||
} else {
|
||||
keyframes.push(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
keyframes = /** @type {Array.<TweenKeyValue>} */(propValue);
|
||||
}
|
||||
} else {
|
||||
keyframesTargetArray[0] = propValue;
|
||||
keyframes = keyframesTargetArray;
|
||||
}
|
||||
|
||||
let siblings = null;
|
||||
let prevTween = null;
|
||||
let firstTweenChangeStartTime = NaN;
|
||||
let lastTweenChangeEndTime = 0;
|
||||
let tweenIndex = 0;
|
||||
|
||||
for (let l = keyframes.length; tweenIndex < l; tweenIndex++) {
|
||||
|
||||
const keyframe = keyframes[tweenIndex];
|
||||
|
||||
if (isObj(keyframe)) {
|
||||
key = keyframe;
|
||||
} else {
|
||||
keyObjectTarget.to = /** @type {TweenParamValue} */(keyframe);
|
||||
key = keyObjectTarget;
|
||||
}
|
||||
|
||||
toFunctionStore.func = null;
|
||||
fromFunctionStore.func = null;
|
||||
|
||||
const computedComposition = getFunctionValue(setValue(key.composition, tComposition), target, ti, tl, null, null);
|
||||
const tweenComposition = isNum(computedComposition) ? computedComposition : compositionTypes[computedComposition];
|
||||
if (!siblings && tweenComposition !== compositionTypes.none) siblings = getTweenSiblings(target, propName);
|
||||
// Timelines pass the last sibling tween if it belongs to the same timeline
|
||||
// Standalone animations only pass prevTween when the property has multiple keyframes
|
||||
const tailTween = siblings ? siblings._tail : null;
|
||||
const prevSiblingTween = parent && tailTween && tailTween.parent.parent === parent ? tailTween : prevTween;
|
||||
const computedToValue = getFunctionValue(key.to, target, ti, tl, toFunctionStore, prevSiblingTween);
|
||||
|
||||
let tweenToValue;
|
||||
// Allows function based values to return an object syntax value ({to: v})
|
||||
if (isObj(computedToValue) && !isUnd(computedToValue.to)) {
|
||||
key = computedToValue;
|
||||
tweenToValue = computedToValue.to;
|
||||
} else {
|
||||
tweenToValue = computedToValue;
|
||||
}
|
||||
const tweenFromValue = getFunctionValue(key.from, target, ti, tl, fromFunctionStore, prevSiblingTween);
|
||||
const easeToParse = key.ease || tEasing;
|
||||
|
||||
const easeFunctionResult = getFunctionValue(easeToParse, target, ti, tl, null, prevSiblingTween);
|
||||
const keyEasing = isFnc(easeFunctionResult) || isStr(easeFunctionResult) ? easeFunctionResult : easeToParse;
|
||||
|
||||
const hasSpring = !isUnd(keyEasing) && !isUnd(/** @type {Spring} */(keyEasing).ease);
|
||||
const tweenEasing = hasSpring ? /** @type {Spring} */(keyEasing).ease : keyEasing;
|
||||
// Calculate default individual keyframe duration by dividing the tl of keyframes
|
||||
const tweenDuration = hasSpring ? /** @type {Spring} */(keyEasing).settlingDuration : getFunctionValue(setValue(key.duration, (l > 1 ? getFunctionValue(tDuration, target, ti, tl, null, prevSiblingTween) / l : tDuration)), target, ti, tl, null, prevSiblingTween);
|
||||
// Default delay value should only be applied to the first tween
|
||||
const tweenDelay = getFunctionValue(setValue(key.delay, (!tweenIndex ? tDelay : 0)), target, ti, tl, null, prevSiblingTween);
|
||||
// Modifiers are treated differently and don't accept function based value to prevent having to pass a function wrapper
|
||||
const tweenModifier = key.modifier || tModifier;
|
||||
const hasFromvalue = !isUnd(tweenFromValue);
|
||||
const hasToValue = !isUnd(tweenToValue);
|
||||
const isFromToArray = isArr(tweenToValue);
|
||||
const isFromToValue = isFromToArray || (hasFromvalue && hasToValue);
|
||||
// Capture the update-start in local time, the previous sibling's end for keyframes after the first, zero for the first keyframe. Used to derive a precision-matched _absoluteUpdateStartTime below.
|
||||
const tweenUpdateStartLocal = prevTween ? lastTweenChangeEndTime : 0;
|
||||
const tweenStartTime = prevTween ? lastTweenChangeEndTime + tweenDelay : tweenDelay;
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const absoluteStartTime = round(absoluteOffsetTime + tweenStartTime, 12);
|
||||
// Match the rounding pattern of prevSibling._absoluteEndTime so the composition overlap check compares cleanly when keyframes touch at a boundary.
|
||||
const absoluteUpdateStartTime = round(absoluteOffsetTime + tweenUpdateStartLocal, 12);
|
||||
|
||||
// Force a onRender callback if the animation contains at least one from value and autoplay is set to false
|
||||
if (!shouldTriggerRender && (hasFromvalue || isFromToArray)) shouldTriggerRender = 1;
|
||||
|
||||
let prevSibling = prevTween;
|
||||
|
||||
if (tweenComposition !== compositionTypes.none) {
|
||||
let nextSibling = siblings._head;
|
||||
// Walk prior siblings up to the new tween, skipping overridden ones so the chain resolves to the latest live value instead of stopping at the first override.
|
||||
while (nextSibling && nextSibling._absoluteStartTime <= absoluteStartTime) {
|
||||
if (!nextSibling._isOverridden) prevSibling = nextSibling;
|
||||
nextSibling = nextSibling._nextRep;
|
||||
// Overrides all the next siblings if the next sibling starts at the same time of after as the new tween start time
|
||||
if (nextSibling && nextSibling._absoluteStartTime >= absoluteStartTime) {
|
||||
while (nextSibling) {
|
||||
overrideTween(nextSibling);
|
||||
// This will ends both the current while loop and the upper one once all the next sibllings have been overriden
|
||||
nextSibling = nextSibling._nextRep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decompose values
|
||||
if (isFromToValue) {
|
||||
decomposeRawValue(isFromToArray ? getFunctionValue(tweenToValue[0], target, ti, tl, fromFunctionStore, prevSiblingTween) : tweenFromValue, fromTargetObject);
|
||||
decomposeRawValue(isFromToArray ? getFunctionValue(tweenToValue[1], target, ti, tl, toFunctionStore, prevSiblingTween) : tweenToValue, toTargetObject);
|
||||
// Needed to force an inline style registration
|
||||
const originalValue = getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore);
|
||||
if (fromTargetObject.t === valueTypes.NUMBER) {
|
||||
if (prevSibling) {
|
||||
if (prevSibling._valueType === valueTypes.UNIT) {
|
||||
fromTargetObject.t = valueTypes.UNIT;
|
||||
fromTargetObject.u = prevSibling._unit;
|
||||
}
|
||||
} else {
|
||||
decomposeRawValue(
|
||||
originalValue,
|
||||
decomposedOriginalValue
|
||||
);
|
||||
if (decomposedOriginalValue.t === valueTypes.UNIT) {
|
||||
fromTargetObject.t = valueTypes.UNIT;
|
||||
fromTargetObject.u = decomposedOriginalValue.u;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasToValue) {
|
||||
decomposeRawValue(tweenToValue, toTargetObject);
|
||||
} else {
|
||||
if (prevTween) {
|
||||
decomposeTweenValue(prevTween, toTargetObject);
|
||||
} else {
|
||||
// No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
|
||||
decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
|
||||
getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore), toTargetObject);
|
||||
}
|
||||
}
|
||||
if (hasFromvalue) {
|
||||
decomposeRawValue(tweenFromValue, fromTargetObject);
|
||||
} else {
|
||||
if (prevTween) {
|
||||
decomposeTweenValue(prevTween, fromTargetObject);
|
||||
} else {
|
||||
// No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
|
||||
decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
|
||||
getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore), fromTargetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply operators
|
||||
if (fromTargetObject.o) {
|
||||
fromTargetObject.n = getRelativeValue(
|
||||
!prevSibling ? decomposeRawValue(
|
||||
getOriginalAnimatableValue(target, propName, tweenType, inlineStylesStore),
|
||||
decomposedOriginalValue
|
||||
).n : prevSibling._toNumber,
|
||||
fromTargetObject.n,
|
||||
fromTargetObject.o
|
||||
);
|
||||
}
|
||||
|
||||
if (toTargetObject.o) {
|
||||
toTargetObject.n = getRelativeValue(fromTargetObject.n, toTargetObject.n, toTargetObject.o);
|
||||
}
|
||||
|
||||
// Values omogenisation in cases of type difference between "from" and "to"
|
||||
if (fromTargetObject.t !== toTargetObject.t) {
|
||||
if (fromTargetObject.t === valueTypes.COMPLEX || toTargetObject.t === valueTypes.COMPLEX) {
|
||||
const complexValue = fromTargetObject.t === valueTypes.COMPLEX ? fromTargetObject : toTargetObject;
|
||||
const notComplexValue = fromTargetObject.t === valueTypes.COMPLEX ? toTargetObject : fromTargetObject;
|
||||
notComplexValue.t = valueTypes.COMPLEX;
|
||||
notComplexValue.s = cloneArray(complexValue.s);
|
||||
notComplexValue.d = complexValue.d.map(() => notComplexValue.n);
|
||||
} else if (fromTargetObject.t === valueTypes.UNIT || toTargetObject.t === valueTypes.UNIT) {
|
||||
const unitValue = fromTargetObject.t === valueTypes.UNIT ? fromTargetObject : toTargetObject;
|
||||
const notUnitValue = fromTargetObject.t === valueTypes.UNIT ? toTargetObject : fromTargetObject;
|
||||
notUnitValue.t = valueTypes.UNIT;
|
||||
notUnitValue.u = unitValue.u;
|
||||
} else if (fromTargetObject.t === valueTypes.COLOR || toTargetObject.t === valueTypes.COLOR) {
|
||||
const colorValue = fromTargetObject.t === valueTypes.COLOR ? fromTargetObject : toTargetObject;
|
||||
const notColorValue = fromTargetObject.t === valueTypes.COLOR ? toTargetObject : fromTargetObject;
|
||||
notColorValue.t = valueTypes.COLOR;
|
||||
notColorValue.d = colorValue.d.map(() => 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Unit conversion
|
||||
if (fromTargetObject.u !== toTargetObject.u) {
|
||||
let valueToConvert = toTargetObject.u ? fromTargetObject : toTargetObject;
|
||||
valueToConvert = convertValueUnit(/** @type {DOMTarget} */(target), valueToConvert, toTargetObject.u ? toTargetObject.u : fromTargetObject.u, false);
|
||||
// TODO:
|
||||
// convertValueUnit(target, to.u ? from : to, to.u ? to.u : from.u);
|
||||
}
|
||||
|
||||
// Fill in non existing complex values
|
||||
if (toTargetObject.d && fromTargetObject.d && (toTargetObject.d.length !== fromTargetObject.d.length)) {
|
||||
const longestValue = fromTargetObject.d.length > toTargetObject.d.length ? fromTargetObject : toTargetObject;
|
||||
const shortestValue = longestValue === fromTargetObject ? toTargetObject : fromTargetObject;
|
||||
// TODO: Check if n should be used instead of 0 for default complex values
|
||||
shortestValue.d = longestValue.d.map((/** @type {Number} */_, /** @type {Number} */i) => isUnd(shortestValue.d[i]) ? 0 : shortestValue.d[i]);
|
||||
shortestValue.s = cloneArray(longestValue.s);
|
||||
}
|
||||
|
||||
// Tween factory
|
||||
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const tweenUpdateDuration = round(+tweenDuration || minValue, 12);
|
||||
|
||||
// Copy the value of the iniline style if it exist and imediatly nullify it to prevents false positive on other targets
|
||||
let inlineValue = inlineStylesStore[propName];
|
||||
if (!isNil(inlineValue)) inlineStylesStore[propName] = null;
|
||||
|
||||
// Resolve the adapter setter once so render skips the lookup per frame.
|
||||
const tweenSetter = adapterProp ? adapterProp.set : null;
|
||||
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
lastTweenChangeEndTime = round(tweenStartTime + tweenUpdateDuration, 12);
|
||||
|
||||
const fromD = fromTargetObject.d;
|
||||
const toD = toTargetObject.d;
|
||||
const toS = toTargetObject.s;
|
||||
|
||||
/** @type {Tween} */
|
||||
const tween = {
|
||||
parent: this,
|
||||
id: tweenId++,
|
||||
property: propName,
|
||||
target: target,
|
||||
_value: null,
|
||||
_toFunc: toFunctionStore.func,
|
||||
_fromFunc: fromFunctionStore.func,
|
||||
_ease: parseEase(tweenEasing),
|
||||
_fromNumbers: fromD ? cloneArray(fromD) : emptyArray,
|
||||
_toNumbers: toD ? cloneArray(toD) : emptyArray,
|
||||
_strings: toS ? cloneArray(toS) : emptyArray,
|
||||
_fromNumber: fromTargetObject.n,
|
||||
_toNumber: toTargetObject.n,
|
||||
_numbers: fromD ? cloneArray(fromD) : emptyArray, // For additive tween and animatables
|
||||
_number: fromTargetObject.n, // For additive tween and animatables
|
||||
_unit: toTargetObject.u,
|
||||
_modifier: tweenModifier,
|
||||
_currentTime: 0,
|
||||
_startTime: tweenStartTime,
|
||||
_delay: +tweenDelay,
|
||||
_updateDuration: tweenUpdateDuration,
|
||||
_changeDuration: tweenUpdateDuration,
|
||||
_absoluteStartTime: absoluteStartTime,
|
||||
_absoluteUpdateStartTime: absoluteUpdateStartTime,
|
||||
_absoluteEndTime: round(absoluteOffsetTime + lastTweenChangeEndTime, 12),
|
||||
_hasFromValue: hasFromvalue || isFromToArray ? 1 : 0,
|
||||
// NOTE: Investigate bit packing to stores ENUM / BOOL
|
||||
_tweenType: tweenType,
|
||||
_setter: tweenSetter,
|
||||
_valueType: toTargetObject.t,
|
||||
_composition: tweenComposition,
|
||||
_isOverlapped: 0,
|
||||
_isOverridden: 0,
|
||||
_renderTransforms: 0,
|
||||
_inlineValue: inlineValue,
|
||||
_prevRep: null, // For replaced tween
|
||||
_nextRep: null, // For replaced tween
|
||||
_prevAdd: null, // For additive tween
|
||||
_nextAdd: null, // For additive tween
|
||||
_prev: null,
|
||||
_next: null,
|
||||
};
|
||||
|
||||
if (tweenComposition !== compositionTypes.none) {
|
||||
composeTween(tween, siblings);
|
||||
}
|
||||
|
||||
// Pre-compute the tween end value for function-based value chaining (ie morphTo / scrambleText in keyframe arrays and timelines)
|
||||
const vt = tween._valueType;
|
||||
if (vt === valueTypes.COMPLEX) {
|
||||
tween._value = composeComplexValue(tween, 1, -1);
|
||||
} else if (vt === valueTypes.UNIT) {
|
||||
tween._value = `${tweenModifier(tween._toNumber)}${tween._unit}`;
|
||||
} else if (vt === valueTypes.COLOR) {
|
||||
const d = toTargetObject.d;
|
||||
tween._value = `rgba(${round(d[0], 0)},${round(d[1], 0)},${round(d[2], 0)},${d[3]})`;
|
||||
} else {
|
||||
tween._value = tweenModifier(tween._toNumber);
|
||||
}
|
||||
|
||||
if (isNaN(firstTweenChangeStartTime)) {
|
||||
firstTweenChangeStartTime = tween._startTime;
|
||||
}
|
||||
|
||||
prevTween = tween;
|
||||
animationAnimationLength++;
|
||||
|
||||
addChild(this, tween);
|
||||
|
||||
}
|
||||
|
||||
// Update animation timings with the added tweens properties
|
||||
|
||||
if (isNaN(iterationDelay) || firstTweenChangeStartTime < iterationDelay) {
|
||||
iterationDelay = firstTweenChangeStartTime;
|
||||
}
|
||||
|
||||
if (isNaN(iterationDuration) || lastTweenChangeEndTime > iterationDuration) {
|
||||
iterationDuration = lastTweenChangeEndTime;
|
||||
}
|
||||
|
||||
// TODO: Find a way to inline tween._renderTransforms = 1 here
|
||||
if (tweenType === tweenTypes.TRANSFORM) {
|
||||
lastTransformGroupIndex = animationAnimationLength - tweenIndex;
|
||||
lastTransformGroupLength = animationAnimationLength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Set _renderTransforms to last transform property to correctly render the transforms list
|
||||
if (!isNaN(lastTransformGroupIndex)) {
|
||||
let i = 0;
|
||||
forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
if (i >= lastTransformGroupIndex && i < lastTransformGroupLength) {
|
||||
tween._renderTransforms = 1;
|
||||
if (tween._composition === compositionTypes.blend) {
|
||||
forEachChildren(additive.animation, (/** @type {Tween} */additiveTween) => {
|
||||
if (additiveTween.id === tween.id) {
|
||||
additiveTween._renderTransforms = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
i++;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!targetsLength) {
|
||||
console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
|
||||
}
|
||||
|
||||
if (iterationDelay) {
|
||||
forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
// If (startTime - delay) equals 0, this means the tween is at the begining of the animation so we need to trim the delay too
|
||||
if (!(tween._startTime - tween._delay)) {
|
||||
tween._delay -= iterationDelay;
|
||||
}
|
||||
tween._startTime -= iterationDelay;
|
||||
});
|
||||
iterationDuration -= iterationDelay;
|
||||
} else {
|
||||
iterationDelay = 0;
|
||||
}
|
||||
|
||||
// Prevents iterationDuration to be NaN if no valid animatable props have been provided
|
||||
// Prevents _iterationCount to be NaN if no valid animatable props have been provided
|
||||
if (!iterationDuration) {
|
||||
iterationDuration = minValue;
|
||||
this.iterationCount = 0;
|
||||
}
|
||||
/** @type {TargetsArray} */
|
||||
this.targets = parsedTargets;
|
||||
/** @type {String|Number} */
|
||||
this.id = !isUnd(id) ? id : JSAnimationId;
|
||||
/** @type {Number} */
|
||||
this.duration = iterationDuration === minValue ? minValue : clampInfinity(((iterationDuration + this._loopDelay) * this.iterationCount) - this._loopDelay) || minValue;
|
||||
/** @type {Callback<this>} */
|
||||
this.onRender = onRender || animDefaults.onRender;
|
||||
/** @type {EasingFunction} */
|
||||
this._ease = parsedAnimPlaybackEase;
|
||||
/** @type {Number} */
|
||||
this._delay = iterationDelay;
|
||||
// NOTE: I'm keeping delay values separated from offsets in timelines because delays can override previous tweens and it could be confusing to debug a timeline with overridden tweens and no associated visible delays.
|
||||
// this._delay = parent ? 0 : iterationDelay;
|
||||
// this._offset += parent ? iterationDelay : 0;
|
||||
/** @type {Number} */
|
||||
this.iterationDuration = iterationDuration;
|
||||
|
||||
if (!this._autoplay && shouldTriggerRender) this.onRender(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} newDuration
|
||||
* @return {this}
|
||||
*/
|
||||
stretch(newDuration) {
|
||||
const currentDuration = this.duration;
|
||||
if (currentDuration === normalizeTime(newDuration)) return this;
|
||||
const timeScale = newDuration / currentDuration;
|
||||
// NOTE: Find a better way to handle the stretch of an animation after stretch = 0
|
||||
forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
// Rounding is necessary here to minimize floating point errors
|
||||
tween._updateDuration = normalizeTime(tween._updateDuration * timeScale);
|
||||
tween._changeDuration = normalizeTime(tween._changeDuration * timeScale);
|
||||
tween._currentTime *= timeScale;
|
||||
tween._delay *= timeScale;
|
||||
tween._startTime *= timeScale;
|
||||
tween._absoluteStartTime *= timeScale;
|
||||
tween._absoluteUpdateStartTime *= timeScale;
|
||||
tween._absoluteEndTime *= timeScale;
|
||||
});
|
||||
return super.stretch(newDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {this}
|
||||
*/
|
||||
refresh() {
|
||||
forEachChildren(this, (/** @type {Tween} */tween) => {
|
||||
const toFunc = tween._toFunc;
|
||||
const fromFunc = tween._fromFunc;
|
||||
if (toFunc || fromFunc) {
|
||||
if (fromFunc) {
|
||||
decomposeRawValue(fromFunc(), fromTargetObject);
|
||||
if (fromTargetObject.u !== tween._unit && tween.target[isDomSymbol]) {
|
||||
convertValueUnit(/** @type {DOMTarget} */(tween.target), fromTargetObject, tween._unit, true);
|
||||
}
|
||||
tween._fromNumbers = cloneArray(fromTargetObject.d);
|
||||
tween._fromNumber = fromTargetObject.n;
|
||||
} else if (toFunc) {
|
||||
// When only toFunc exists, get from value from target
|
||||
decomposeRawValue(getOriginalAnimatableValue(tween.target, tween.property, tween._tweenType), decomposedOriginalValue);
|
||||
tween._fromNumbers = cloneArray(decomposedOriginalValue.d);
|
||||
tween._fromNumber = decomposedOriginalValue.n;
|
||||
}
|
||||
if (toFunc) {
|
||||
decomposeRawValue(toFunc(), toTargetObject);
|
||||
tween._toNumbers = cloneArray(toTargetObject.d);
|
||||
tween._strings = cloneArray(toTargetObject.s);
|
||||
// Make sure to apply relative operators https://github.com/juliangarnier/anime/issues/1025
|
||||
tween._toNumber = toTargetObject.o ? getRelativeValue(tween._fromNumber, toTargetObject.n, toTargetObject.o) : toTargetObject.n;
|
||||
}
|
||||
}
|
||||
});
|
||||
// This forces setter animations to render once
|
||||
if (this.duration === minValue) this.restart();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the animation and revert all the values affected by this animation to their original state
|
||||
* @return {this}
|
||||
*/
|
||||
revert() {
|
||||
super.revert();
|
||||
return revertValues(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {this & {then: null}} ResolvedJSAnimation
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Callback<ResolvedJSAnimation>} [callback]
|
||||
* @return Promise<this>
|
||||
*/
|
||||
then(callback) {
|
||||
return super.then(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TargetsParam} targets
|
||||
* @param {AnimationParams} parameters
|
||||
* @return {JSAnimation}
|
||||
*/
|
||||
const animate = (targets, parameters) => {
|
||||
if (globals.editor) {
|
||||
return globals.editor.addAnimation(targets, parameters);
|
||||
} else {
|
||||
return new JSAnimation(targets, parameters, null, 0, false).init();
|
||||
}
|
||||
};
|
||||
|
||||
export { JSAnimation, animate };
|
||||
@@ -0,0 +1,386 @@
|
||||
/**
|
||||
* Anime.js - animation - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('../core/consts.cjs');
|
||||
var helpers = require('../core/helpers.cjs');
|
||||
var styles = require('../core/styles.cjs');
|
||||
var engine = require('../engine/engine.cjs');
|
||||
var additive = require('./additive.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* TweenReplaceLookups,
|
||||
* TweenAdditiveLookups,
|
||||
* TweenPropertySiblings,
|
||||
* Tween,
|
||||
* Target,
|
||||
* TargetsArray,
|
||||
* Renderable,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
const lookups = {
|
||||
/** @type {TweenReplaceLookups} */
|
||||
_rep: new WeakMap(),
|
||||
/** @type {TweenAdditiveLookups} */
|
||||
_add: new Map(),
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Target} target
|
||||
* @param {String} property
|
||||
* @param {String} lookup
|
||||
* @return {TweenPropertySiblings}
|
||||
*/
|
||||
const getTweenSiblings = (target, property, lookup = '_rep') => {
|
||||
const lookupMap = lookups[lookup];
|
||||
let targetLookup = lookupMap.get(target);
|
||||
if (!targetLookup) {
|
||||
targetLookup = {};
|
||||
lookupMap.set(target, targetLookup);
|
||||
}
|
||||
return targetLookup[property] ? targetLookup[property] : targetLookup[property] = {
|
||||
_head: null,
|
||||
_tail: null,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} p
|
||||
* @param {Tween} c
|
||||
* @return {Number|Boolean}
|
||||
*/
|
||||
const addTweenSortMethod = (p, c) => {
|
||||
return p._isOverridden || p._absoluteStartTime > c._absoluteStartTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
*/
|
||||
const overrideTween = tween => {
|
||||
tween._isOverlapped = 1;
|
||||
tween._isOverridden = 1;
|
||||
tween._changeDuration = consts.minValue;
|
||||
tween._currentTime = consts.minValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
* @param {TweenPropertySiblings} siblings
|
||||
* @return {Tween}
|
||||
*/
|
||||
const composeTween = (tween, siblings) => {
|
||||
|
||||
const tweenCompositionType = tween._composition;
|
||||
|
||||
// Handle replaced tweens
|
||||
|
||||
if (tweenCompositionType === consts.compositionTypes.replace) {
|
||||
|
||||
const tweenAbsStartTime = tween._absoluteStartTime;
|
||||
|
||||
helpers.addChild(siblings, tween, addTweenSortMethod, '_prevRep', '_nextRep');
|
||||
|
||||
const prevSibling = tween._prevRep;
|
||||
|
||||
// Update the previous siblings for composition replace tweens
|
||||
|
||||
if (prevSibling) {
|
||||
|
||||
const prevParent = prevSibling.parent;
|
||||
const prevAbsEndTime = prevSibling._absoluteEndTime;
|
||||
|
||||
// Handle looped animations tween
|
||||
|
||||
if (
|
||||
// Check if the previous tween is from a different animation
|
||||
tween.parent.id !== prevParent.id &&
|
||||
// Check if the animation has loops
|
||||
prevParent.iterationCount> 1 &&
|
||||
// Check if _absoluteChangeEndTime of last loop overlaps the current tween
|
||||
prevAbsEndTime + (prevParent.duration - prevParent.iterationDuration) > tweenAbsStartTime
|
||||
) {
|
||||
|
||||
// TODO: Find a way to only override the iterations overlapping with the tween
|
||||
overrideTween(prevSibling);
|
||||
|
||||
let prevPrevSibling = prevSibling._prevRep;
|
||||
|
||||
// If the tween was part of a set of keyframes, override its siblings
|
||||
while (prevPrevSibling && prevPrevSibling.parent.id === prevParent.id) {
|
||||
overrideTween(prevPrevSibling);
|
||||
prevPrevSibling = prevPrevSibling._prevRep;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Read the precision-matched update-start instead of subtracting tween._delay live so sequential keyframes touching at a boundary don't trigger a phantom overlap from float drift.
|
||||
const absoluteUpdateStartTime = tween._absoluteUpdateStartTime;
|
||||
|
||||
if (prevAbsEndTime > absoluteUpdateStartTime) {
|
||||
|
||||
const prevChangeStartTime = prevSibling._startTime;
|
||||
const prevTLOffset = prevAbsEndTime - (prevChangeStartTime + prevSibling._updateDuration);
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const updatedPrevChangeDuration = helpers.round(absoluteUpdateStartTime - prevTLOffset - prevChangeStartTime, 12);
|
||||
|
||||
prevSibling._changeDuration = updatedPrevChangeDuration;
|
||||
prevSibling._currentTime = updatedPrevChangeDuration;
|
||||
prevSibling._isOverlapped = 1;
|
||||
|
||||
// Override the previous tween if its new _changeDuration is lower than minValue
|
||||
// TODO: See if it's even neceseeary to test against minValue, checking for 0 might be enough
|
||||
if (updatedPrevChangeDuration < consts.minValue) {
|
||||
overrideTween(prevSibling);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip the cancel cascade when both tweens share the same parent timeline, a timeline cannot replace itself.
|
||||
const tweenParentTL = tween.parent.parent;
|
||||
if (!tweenParentTL || tweenParentTL !== prevParent.parent) {
|
||||
|
||||
let pausePrevParentAnimation = true;
|
||||
|
||||
helpers.forEachChildren(prevParent, (/** @type Tween */t) => {
|
||||
if (!t._isOverlapped) pausePrevParentAnimation = false;
|
||||
});
|
||||
|
||||
if (pausePrevParentAnimation) {
|
||||
const prevParentTL = prevParent.parent;
|
||||
if (prevParentTL) {
|
||||
let pausePrevParentTL = true;
|
||||
helpers.forEachChildren(prevParentTL, (/** @type JSAnimation */a) => {
|
||||
if (a !== prevParent) {
|
||||
helpers.forEachChildren(a, (/** @type Tween */t) => {
|
||||
if (!t._isOverlapped) pausePrevParentTL = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
if (pausePrevParentTL) {
|
||||
prevParentTL.cancel();
|
||||
}
|
||||
} else {
|
||||
prevParent.cancel();
|
||||
// Previously, calling .cancel() on a timeline child would affect the render order of other children
|
||||
// Worked around this by marking it as .completed and using .pause() for safe removal in the engine loop
|
||||
// This is no longer needed since timeline tween composition is now handled separately
|
||||
// Keeping this here for reference
|
||||
// prevParent.completed = true;
|
||||
// prevParent.pause();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// let nextSibling = tween._nextRep;
|
||||
|
||||
// // All the next siblings are automatically overridden
|
||||
|
||||
// if (nextSibling && nextSibling._absoluteStartTime >= tweenAbsStartTime) {
|
||||
// while (nextSibling) {
|
||||
// overrideTween(nextSibling);
|
||||
// nextSibling = nextSibling._nextRep;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (nextSibling && nextSibling._absoluteStartTime < tweenAbsStartTime) {
|
||||
// while (nextSibling) {
|
||||
// overrideTween(nextSibling);
|
||||
// console.log(tween.id, nextSibling.id);
|
||||
// nextSibling = nextSibling._nextRep;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Handle additive tweens composition
|
||||
|
||||
} else if (tweenCompositionType === consts.compositionTypes.blend) {
|
||||
|
||||
const additiveTweenSiblings = getTweenSiblings(tween.target, tween.property, '_add');
|
||||
const additiveAnimation = additive.addAdditiveAnimation(lookups._add);
|
||||
|
||||
let lookupTween = additiveTweenSiblings._head;
|
||||
|
||||
if (!lookupTween) {
|
||||
lookupTween = { ...tween };
|
||||
lookupTween._composition = consts.compositionTypes.replace;
|
||||
lookupTween._updateDuration = consts.minValue;
|
||||
lookupTween._startTime = 0;
|
||||
lookupTween._numbers = helpers.cloneArray(tween._fromNumbers);
|
||||
lookupTween._number = 0;
|
||||
lookupTween._next = null;
|
||||
lookupTween._prev = null;
|
||||
helpers.addChild(additiveTweenSiblings, lookupTween);
|
||||
helpers.addChild(additiveAnimation, lookupTween);
|
||||
}
|
||||
|
||||
// Convert the values of TO to FROM and set TO to 0
|
||||
|
||||
const toNumber = tween._toNumber;
|
||||
tween._fromNumber = lookupTween._fromNumber - toNumber;
|
||||
tween._toNumber = 0;
|
||||
tween._numbers = helpers.cloneArray(tween._fromNumbers);
|
||||
tween._number = 0;
|
||||
lookupTween._fromNumber = toNumber;
|
||||
|
||||
if (tween._toNumbers.length) {
|
||||
const toNumbers = helpers.cloneArray(tween._toNumbers);
|
||||
toNumbers.forEach((value, i) => {
|
||||
tween._fromNumbers[i] = lookupTween._fromNumbers[i] - value;
|
||||
tween._toNumbers[i] = 0;
|
||||
});
|
||||
lookupTween._fromNumbers = toNumbers;
|
||||
}
|
||||
|
||||
helpers.addChild(additiveTweenSiblings, tween, null, '_prevAdd', '_nextAdd');
|
||||
|
||||
}
|
||||
|
||||
return tween;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
* @return {Tween}
|
||||
*/
|
||||
const removeTweenSliblings = tween => {
|
||||
const tweenComposition = tween._composition;
|
||||
if (tweenComposition !== consts.compositionTypes.none) {
|
||||
const tweenTarget = tween.target;
|
||||
const tweenProperty = tween.property;
|
||||
const replaceTweensLookup = lookups._rep;
|
||||
const replaceTargetProps = replaceTweensLookup.get(tweenTarget);
|
||||
const tweenReplaceSiblings = replaceTargetProps[tweenProperty];
|
||||
helpers.removeChild(tweenReplaceSiblings, tween, '_prevRep', '_nextRep');
|
||||
if (tweenComposition === consts.compositionTypes.blend) {
|
||||
const addTweensLookup = lookups._add;
|
||||
const addTargetProps = addTweensLookup.get(tweenTarget);
|
||||
if (!addTargetProps) return;
|
||||
const additiveTweenSiblings = addTargetProps[tweenProperty];
|
||||
const additiveAnimation = additive.additive.animation;
|
||||
helpers.removeChild(additiveTweenSiblings, tween, '_prevAdd', '_nextAdd');
|
||||
// If only one tween is left in the additive lookup, it's the tween lookup
|
||||
const lookupTween = additiveTweenSiblings._head;
|
||||
if (lookupTween && lookupTween === additiveTweenSiblings._tail) {
|
||||
helpers.removeChild(additiveTweenSiblings, lookupTween, '_prevAdd', '_nextAdd');
|
||||
helpers.removeChild(additiveAnimation, lookupTween);
|
||||
let shouldClean = true;
|
||||
for (let prop in addTargetProps) {
|
||||
if (addTargetProps[prop]._head) {
|
||||
shouldClean = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldClean) {
|
||||
addTweensLookup.delete(tweenTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tween;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {TargetsArray} targetsArray
|
||||
* @param {JSAnimation} animation
|
||||
* @param {String} [propertyName]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const removeTargetsFromJSAnimation = (targetsArray, animation, propertyName) => {
|
||||
let tweensMatchesTargets = false;
|
||||
helpers.forEachChildren(animation, (/**@type {Tween} */tween) => {
|
||||
const tweenTarget = tween.target;
|
||||
if (targetsArray.includes(tweenTarget)) {
|
||||
const tweenName = tween.property;
|
||||
const tweenType = tween._tweenType;
|
||||
const normalizePropName = styles.sanitizePropertyName(propertyName, tweenTarget, tweenType);
|
||||
if (!normalizePropName || normalizePropName && normalizePropName === tweenName) {
|
||||
// Make sure to flag the previous CSS transform tween to renderTransform
|
||||
if (tween.parent._tail === tween &&
|
||||
tween._tweenType === consts.tweenTypes.TRANSFORM &&
|
||||
tween._prev &&
|
||||
tween._prev._tweenType === consts.tweenTypes.TRANSFORM
|
||||
) {
|
||||
tween._prev._renderTransforms = 1;
|
||||
}
|
||||
// Removes the tween from the selected animation
|
||||
helpers.removeChild(animation, tween);
|
||||
// Detach the tween from its siblings to make sure blended tweens are correctlly removed
|
||||
removeTweenSliblings(tween);
|
||||
tweensMatchesTargets = true;
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
return tweensMatchesTargets;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {TargetsArray} targetsArray
|
||||
* @param {Renderable} [renderable]
|
||||
* @param {String} [propertyName]
|
||||
*/
|
||||
const removeTargetsFromRenderable = (targetsArray, renderable, propertyName) => {
|
||||
const parent = /** @type {Renderable|typeof engine} **/(renderable ? renderable : engine.engine);
|
||||
let removeMatches;
|
||||
if (parent._hasChildren) {
|
||||
let iterationDuration = 0;
|
||||
helpers.forEachChildren(parent, (/** @type {Renderable} */child) => {
|
||||
if (!child._hasChildren) {
|
||||
removeMatches = removeTargetsFromJSAnimation(targetsArray, /** @type {JSAnimation} */(child), propertyName);
|
||||
// Remove the child from its parent if no tweens and no children left after the removal
|
||||
if (removeMatches && !child._head) {
|
||||
child.cancel();
|
||||
helpers.removeChild(parent, child);
|
||||
} else {
|
||||
// Calculate the new iterationDuration value to handle onComplete with last child in render()
|
||||
const childTLOffset = child._offset + child._delay;
|
||||
const childDur = childTLOffset + child.duration;
|
||||
if (childDur > iterationDuration) {
|
||||
iterationDuration = childDur;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make sure to also remove engine's children targets
|
||||
// NOTE: Avoid recursion?
|
||||
if (child._head) {
|
||||
removeTargetsFromRenderable(targetsArray, child, propertyName);
|
||||
} else {
|
||||
child._hasChildren = false;
|
||||
}
|
||||
}, true);
|
||||
// Update iterationDuration value to handle onComplete with last child in render()
|
||||
if (!helpers.isUnd(/** @type {Renderable} */(parent).iterationDuration)) {
|
||||
/** @type {Renderable} */(parent).iterationDuration = iterationDuration;
|
||||
}
|
||||
} else {
|
||||
removeMatches = removeTargetsFromJSAnimation(
|
||||
targetsArray,
|
||||
/** @type {JSAnimation} */(parent),
|
||||
propertyName
|
||||
);
|
||||
}
|
||||
if (removeMatches && !parent._head) {
|
||||
parent._hasChildren = false;
|
||||
// Cancel the parent if there are no tweens and no children left after the removal
|
||||
// We have to check if the .cancel() method exist to handle cases where the parent is the engine itself
|
||||
if (/** @type {Renderable} */(parent).cancel) /** @type {Renderable} */(parent).cancel();
|
||||
}
|
||||
};
|
||||
|
||||
exports.composeTween = composeTween;
|
||||
exports.getTweenSiblings = getTweenSiblings;
|
||||
exports.overrideTween = overrideTween;
|
||||
exports.removeTargetsFromRenderable = removeTargetsFromRenderable;
|
||||
exports.removeTweenSliblings = removeTweenSliblings;
|
||||
@@ -0,0 +1,10 @@
|
||||
export function getTweenSiblings(target: Target, property: string, lookup?: string): TweenPropertySiblings;
|
||||
export function overrideTween(tween: Tween): void;
|
||||
export function composeTween(tween: Tween, siblings: TweenPropertySiblings): Tween;
|
||||
export function removeTweenSliblings(tween: Tween): Tween;
|
||||
export function removeTargetsFromRenderable(targetsArray: TargetsArray, renderable?: Renderable, propertyName?: string): void;
|
||||
import type { Target } from '../types/index.js';
|
||||
import type { TweenPropertySiblings } from '../types/index.js';
|
||||
import type { Tween } from '../types/index.js';
|
||||
import type { TargetsArray } from '../types/index.js';
|
||||
import type { Renderable } from '../types/index.js';
|
||||
@@ -0,0 +1,380 @@
|
||||
/**
|
||||
* Anime.js - animation - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { compositionTypes, minValue, tweenTypes } from '../core/consts.js';
|
||||
import { forEachChildren, removeChild, isUnd, addChild, round, cloneArray } from '../core/helpers.js';
|
||||
import { sanitizePropertyName } from '../core/styles.js';
|
||||
import { engine } from '../engine/engine.js';
|
||||
import { additive, addAdditiveAnimation } from './additive.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* TweenReplaceLookups,
|
||||
* TweenAdditiveLookups,
|
||||
* TweenPropertySiblings,
|
||||
* Tween,
|
||||
* Target,
|
||||
* TargetsArray,
|
||||
* Renderable,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
const lookups = {
|
||||
/** @type {TweenReplaceLookups} */
|
||||
_rep: new WeakMap(),
|
||||
/** @type {TweenAdditiveLookups} */
|
||||
_add: new Map(),
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Target} target
|
||||
* @param {String} property
|
||||
* @param {String} lookup
|
||||
* @return {TweenPropertySiblings}
|
||||
*/
|
||||
const getTweenSiblings = (target, property, lookup = '_rep') => {
|
||||
const lookupMap = lookups[lookup];
|
||||
let targetLookup = lookupMap.get(target);
|
||||
if (!targetLookup) {
|
||||
targetLookup = {};
|
||||
lookupMap.set(target, targetLookup);
|
||||
}
|
||||
return targetLookup[property] ? targetLookup[property] : targetLookup[property] = {
|
||||
_head: null,
|
||||
_tail: null,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} p
|
||||
* @param {Tween} c
|
||||
* @return {Number|Boolean}
|
||||
*/
|
||||
const addTweenSortMethod = (p, c) => {
|
||||
return p._isOverridden || p._absoluteStartTime > c._absoluteStartTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
*/
|
||||
const overrideTween = tween => {
|
||||
tween._isOverlapped = 1;
|
||||
tween._isOverridden = 1;
|
||||
tween._changeDuration = minValue;
|
||||
tween._currentTime = minValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
* @param {TweenPropertySiblings} siblings
|
||||
* @return {Tween}
|
||||
*/
|
||||
const composeTween = (tween, siblings) => {
|
||||
|
||||
const tweenCompositionType = tween._composition;
|
||||
|
||||
// Handle replaced tweens
|
||||
|
||||
if (tweenCompositionType === compositionTypes.replace) {
|
||||
|
||||
const tweenAbsStartTime = tween._absoluteStartTime;
|
||||
|
||||
addChild(siblings, tween, addTweenSortMethod, '_prevRep', '_nextRep');
|
||||
|
||||
const prevSibling = tween._prevRep;
|
||||
|
||||
// Update the previous siblings for composition replace tweens
|
||||
|
||||
if (prevSibling) {
|
||||
|
||||
const prevParent = prevSibling.parent;
|
||||
const prevAbsEndTime = prevSibling._absoluteEndTime;
|
||||
|
||||
// Handle looped animations tween
|
||||
|
||||
if (
|
||||
// Check if the previous tween is from a different animation
|
||||
tween.parent.id !== prevParent.id &&
|
||||
// Check if the animation has loops
|
||||
prevParent.iterationCount> 1 &&
|
||||
// Check if _absoluteChangeEndTime of last loop overlaps the current tween
|
||||
prevAbsEndTime + (prevParent.duration - prevParent.iterationDuration) > tweenAbsStartTime
|
||||
) {
|
||||
|
||||
// TODO: Find a way to only override the iterations overlapping with the tween
|
||||
overrideTween(prevSibling);
|
||||
|
||||
let prevPrevSibling = prevSibling._prevRep;
|
||||
|
||||
// If the tween was part of a set of keyframes, override its siblings
|
||||
while (prevPrevSibling && prevPrevSibling.parent.id === prevParent.id) {
|
||||
overrideTween(prevPrevSibling);
|
||||
prevPrevSibling = prevPrevSibling._prevRep;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Read the precision-matched update-start instead of subtracting tween._delay live so sequential keyframes touching at a boundary don't trigger a phantom overlap from float drift.
|
||||
const absoluteUpdateStartTime = tween._absoluteUpdateStartTime;
|
||||
|
||||
if (prevAbsEndTime > absoluteUpdateStartTime) {
|
||||
|
||||
const prevChangeStartTime = prevSibling._startTime;
|
||||
const prevTLOffset = prevAbsEndTime - (prevChangeStartTime + prevSibling._updateDuration);
|
||||
// Rounding is necessary here to minimize floating point errors when working in seconds
|
||||
const updatedPrevChangeDuration = round(absoluteUpdateStartTime - prevTLOffset - prevChangeStartTime, 12);
|
||||
|
||||
prevSibling._changeDuration = updatedPrevChangeDuration;
|
||||
prevSibling._currentTime = updatedPrevChangeDuration;
|
||||
prevSibling._isOverlapped = 1;
|
||||
|
||||
// Override the previous tween if its new _changeDuration is lower than minValue
|
||||
// TODO: See if it's even neceseeary to test against minValue, checking for 0 might be enough
|
||||
if (updatedPrevChangeDuration < minValue) {
|
||||
overrideTween(prevSibling);
|
||||
}
|
||||
}
|
||||
|
||||
// Skip the cancel cascade when both tweens share the same parent timeline, a timeline cannot replace itself.
|
||||
const tweenParentTL = tween.parent.parent;
|
||||
if (!tweenParentTL || tweenParentTL !== prevParent.parent) {
|
||||
|
||||
let pausePrevParentAnimation = true;
|
||||
|
||||
forEachChildren(prevParent, (/** @type Tween */t) => {
|
||||
if (!t._isOverlapped) pausePrevParentAnimation = false;
|
||||
});
|
||||
|
||||
if (pausePrevParentAnimation) {
|
||||
const prevParentTL = prevParent.parent;
|
||||
if (prevParentTL) {
|
||||
let pausePrevParentTL = true;
|
||||
forEachChildren(prevParentTL, (/** @type JSAnimation */a) => {
|
||||
if (a !== prevParent) {
|
||||
forEachChildren(a, (/** @type Tween */t) => {
|
||||
if (!t._isOverlapped) pausePrevParentTL = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
if (pausePrevParentTL) {
|
||||
prevParentTL.cancel();
|
||||
}
|
||||
} else {
|
||||
prevParent.cancel();
|
||||
// Previously, calling .cancel() on a timeline child would affect the render order of other children
|
||||
// Worked around this by marking it as .completed and using .pause() for safe removal in the engine loop
|
||||
// This is no longer needed since timeline tween composition is now handled separately
|
||||
// Keeping this here for reference
|
||||
// prevParent.completed = true;
|
||||
// prevParent.pause();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// let nextSibling = tween._nextRep;
|
||||
|
||||
// // All the next siblings are automatically overridden
|
||||
|
||||
// if (nextSibling && nextSibling._absoluteStartTime >= tweenAbsStartTime) {
|
||||
// while (nextSibling) {
|
||||
// overrideTween(nextSibling);
|
||||
// nextSibling = nextSibling._nextRep;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (nextSibling && nextSibling._absoluteStartTime < tweenAbsStartTime) {
|
||||
// while (nextSibling) {
|
||||
// overrideTween(nextSibling);
|
||||
// console.log(tween.id, nextSibling.id);
|
||||
// nextSibling = nextSibling._nextRep;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Handle additive tweens composition
|
||||
|
||||
} else if (tweenCompositionType === compositionTypes.blend) {
|
||||
|
||||
const additiveTweenSiblings = getTweenSiblings(tween.target, tween.property, '_add');
|
||||
const additiveAnimation = addAdditiveAnimation(lookups._add);
|
||||
|
||||
let lookupTween = additiveTweenSiblings._head;
|
||||
|
||||
if (!lookupTween) {
|
||||
lookupTween = { ...tween };
|
||||
lookupTween._composition = compositionTypes.replace;
|
||||
lookupTween._updateDuration = minValue;
|
||||
lookupTween._startTime = 0;
|
||||
lookupTween._numbers = cloneArray(tween._fromNumbers);
|
||||
lookupTween._number = 0;
|
||||
lookupTween._next = null;
|
||||
lookupTween._prev = null;
|
||||
addChild(additiveTweenSiblings, lookupTween);
|
||||
addChild(additiveAnimation, lookupTween);
|
||||
}
|
||||
|
||||
// Convert the values of TO to FROM and set TO to 0
|
||||
|
||||
const toNumber = tween._toNumber;
|
||||
tween._fromNumber = lookupTween._fromNumber - toNumber;
|
||||
tween._toNumber = 0;
|
||||
tween._numbers = cloneArray(tween._fromNumbers);
|
||||
tween._number = 0;
|
||||
lookupTween._fromNumber = toNumber;
|
||||
|
||||
if (tween._toNumbers.length) {
|
||||
const toNumbers = cloneArray(tween._toNumbers);
|
||||
toNumbers.forEach((value, i) => {
|
||||
tween._fromNumbers[i] = lookupTween._fromNumbers[i] - value;
|
||||
tween._toNumbers[i] = 0;
|
||||
});
|
||||
lookupTween._fromNumbers = toNumbers;
|
||||
}
|
||||
|
||||
addChild(additiveTweenSiblings, tween, null, '_prevAdd', '_nextAdd');
|
||||
|
||||
}
|
||||
|
||||
return tween;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tween} tween
|
||||
* @return {Tween}
|
||||
*/
|
||||
const removeTweenSliblings = tween => {
|
||||
const tweenComposition = tween._composition;
|
||||
if (tweenComposition !== compositionTypes.none) {
|
||||
const tweenTarget = tween.target;
|
||||
const tweenProperty = tween.property;
|
||||
const replaceTweensLookup = lookups._rep;
|
||||
const replaceTargetProps = replaceTweensLookup.get(tweenTarget);
|
||||
const tweenReplaceSiblings = replaceTargetProps[tweenProperty];
|
||||
removeChild(tweenReplaceSiblings, tween, '_prevRep', '_nextRep');
|
||||
if (tweenComposition === compositionTypes.blend) {
|
||||
const addTweensLookup = lookups._add;
|
||||
const addTargetProps = addTweensLookup.get(tweenTarget);
|
||||
if (!addTargetProps) return;
|
||||
const additiveTweenSiblings = addTargetProps[tweenProperty];
|
||||
const additiveAnimation = additive.animation;
|
||||
removeChild(additiveTweenSiblings, tween, '_prevAdd', '_nextAdd');
|
||||
// If only one tween is left in the additive lookup, it's the tween lookup
|
||||
const lookupTween = additiveTweenSiblings._head;
|
||||
if (lookupTween && lookupTween === additiveTweenSiblings._tail) {
|
||||
removeChild(additiveTweenSiblings, lookupTween, '_prevAdd', '_nextAdd');
|
||||
removeChild(additiveAnimation, lookupTween);
|
||||
let shouldClean = true;
|
||||
for (let prop in addTargetProps) {
|
||||
if (addTargetProps[prop]._head) {
|
||||
shouldClean = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldClean) {
|
||||
addTweensLookup.delete(tweenTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tween;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {TargetsArray} targetsArray
|
||||
* @param {JSAnimation} animation
|
||||
* @param {String} [propertyName]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const removeTargetsFromJSAnimation = (targetsArray, animation, propertyName) => {
|
||||
let tweensMatchesTargets = false;
|
||||
forEachChildren(animation, (/**@type {Tween} */tween) => {
|
||||
const tweenTarget = tween.target;
|
||||
if (targetsArray.includes(tweenTarget)) {
|
||||
const tweenName = tween.property;
|
||||
const tweenType = tween._tweenType;
|
||||
const normalizePropName = sanitizePropertyName(propertyName, tweenTarget, tweenType);
|
||||
if (!normalizePropName || normalizePropName && normalizePropName === tweenName) {
|
||||
// Make sure to flag the previous CSS transform tween to renderTransform
|
||||
if (tween.parent._tail === tween &&
|
||||
tween._tweenType === tweenTypes.TRANSFORM &&
|
||||
tween._prev &&
|
||||
tween._prev._tweenType === tweenTypes.TRANSFORM
|
||||
) {
|
||||
tween._prev._renderTransforms = 1;
|
||||
}
|
||||
// Removes the tween from the selected animation
|
||||
removeChild(animation, tween);
|
||||
// Detach the tween from its siblings to make sure blended tweens are correctlly removed
|
||||
removeTweenSliblings(tween);
|
||||
tweensMatchesTargets = true;
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
return tweensMatchesTargets;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {TargetsArray} targetsArray
|
||||
* @param {Renderable} [renderable]
|
||||
* @param {String} [propertyName]
|
||||
*/
|
||||
const removeTargetsFromRenderable = (targetsArray, renderable, propertyName) => {
|
||||
const parent = /** @type {Renderable|typeof engine} **/(renderable ? renderable : engine);
|
||||
let removeMatches;
|
||||
if (parent._hasChildren) {
|
||||
let iterationDuration = 0;
|
||||
forEachChildren(parent, (/** @type {Renderable} */child) => {
|
||||
if (!child._hasChildren) {
|
||||
removeMatches = removeTargetsFromJSAnimation(targetsArray, /** @type {JSAnimation} */(child), propertyName);
|
||||
// Remove the child from its parent if no tweens and no children left after the removal
|
||||
if (removeMatches && !child._head) {
|
||||
child.cancel();
|
||||
removeChild(parent, child);
|
||||
} else {
|
||||
// Calculate the new iterationDuration value to handle onComplete with last child in render()
|
||||
const childTLOffset = child._offset + child._delay;
|
||||
const childDur = childTLOffset + child.duration;
|
||||
if (childDur > iterationDuration) {
|
||||
iterationDuration = childDur;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make sure to also remove engine's children targets
|
||||
// NOTE: Avoid recursion?
|
||||
if (child._head) {
|
||||
removeTargetsFromRenderable(targetsArray, child, propertyName);
|
||||
} else {
|
||||
child._hasChildren = false;
|
||||
}
|
||||
}, true);
|
||||
// Update iterationDuration value to handle onComplete with last child in render()
|
||||
if (!isUnd(/** @type {Renderable} */(parent).iterationDuration)) {
|
||||
/** @type {Renderable} */(parent).iterationDuration = iterationDuration;
|
||||
}
|
||||
} else {
|
||||
removeMatches = removeTargetsFromJSAnimation(
|
||||
targetsArray,
|
||||
/** @type {JSAnimation} */(parent),
|
||||
propertyName
|
||||
);
|
||||
}
|
||||
if (removeMatches && !parent._head) {
|
||||
parent._hasChildren = false;
|
||||
// Cancel the parent if there are no tweens and no children left after the removal
|
||||
// We have to check if the .cancel() method exist to handle cases where the parent is the engine itself
|
||||
if (/** @type {Renderable} */(parent).cancel) /** @type {Renderable} */(parent).cancel();
|
||||
}
|
||||
};
|
||||
|
||||
export { composeTween, getTweenSiblings, overrideTween, removeTargetsFromRenderable, removeTweenSliblings };
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Anime.js - animation - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var animation = require('./animation.cjs');
|
||||
|
||||
|
||||
|
||||
exports.JSAnimation = animation.JSAnimation;
|
||||
exports.animate = animation.animate;
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./animation.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Anime.js - animation - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
export { JSAnimation, animate } from './animation.js';
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('./consts.cjs');
|
||||
var globals = require('./globals.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tickable,
|
||||
* Tween,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/*
|
||||
* Base class to control framerate and playback rate.
|
||||
* Inherited by Engine, Timer, Animation and Timeline.
|
||||
*/
|
||||
class Clock {
|
||||
|
||||
/** @param {Number} [initTime] */
|
||||
constructor(initTime = 0) {
|
||||
/** @type {Number} */
|
||||
this.deltaTime = 0;
|
||||
/** @type {Number} */
|
||||
this._currentTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._lastTickTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._startTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._lastTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._frameDuration = consts.K / consts.maxFps;
|
||||
/** @type {Number} */
|
||||
this._fps = consts.maxFps;
|
||||
/** @type {Number} */
|
||||
this._speed = 1;
|
||||
/** @type {Boolean} */
|
||||
this._hasChildren = false;
|
||||
/** @type {Tickable|Tween} */
|
||||
this._head = null;
|
||||
/** @type {Tickable|Tween} */
|
||||
this._tail = null;
|
||||
}
|
||||
|
||||
get fps() {
|
||||
return this._fps;
|
||||
}
|
||||
|
||||
set fps(frameRate) {
|
||||
const fr = +frameRate;
|
||||
const fps = fr < consts.minValue ? consts.minValue : fr;
|
||||
const frameDuration = consts.K / fps;
|
||||
if (fps > globals.defaults.frameRate) globals.defaults.frameRate = fps;
|
||||
this._fps = fps;
|
||||
this._frameDuration = frameDuration;
|
||||
}
|
||||
|
||||
get speed() {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
set speed(playbackRate) {
|
||||
const pbr = +playbackRate;
|
||||
this._speed = pbr < consts.minValue ? consts.minValue : pbr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {tickModes}
|
||||
*/
|
||||
requestTick(time) {
|
||||
const frameDuration = this._frameDuration;
|
||||
const elapsed = time - this._lastTickTime;
|
||||
const scaled = frameDuration * .25;
|
||||
const tolerance = scaled < 4 ? scaled : 4;
|
||||
// Tolerance prevents dropping frames that arrive a bit early due to RAF jitter
|
||||
// typically <= ~25% of frame duration and capped at 4ms so it doesn't dominate at high fps.
|
||||
// e.g. at 60fps (frameDuration=16.667ms) a frame arriving after 15ms:
|
||||
// - without tolerance: 15 < 16.667 -> skip
|
||||
// - with tolerance: 15 + 4 >= 16.667 -> tick
|
||||
if (elapsed + tolerance < frameDuration) return consts.tickModes.NONE;
|
||||
this._lastTickTime = elapsed >= frameDuration ? time - (elapsed % frameDuration) : time;
|
||||
return consts.tickModes.AUTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {Number}
|
||||
*/
|
||||
computeDeltaTime(time) {
|
||||
const delta = time - this._lastTime;
|
||||
this.deltaTime = delta;
|
||||
this._lastTime = time;
|
||||
return delta;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.Clock = Clock;
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @import {
|
||||
* Tickable,
|
||||
* Tween,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
export class Clock {
|
||||
/** @param {Number} [initTime] */
|
||||
constructor(initTime?: number);
|
||||
/** @type {Number} */
|
||||
deltaTime: number;
|
||||
/** @type {Number} */
|
||||
_currentTime: number;
|
||||
/** @type {Number} */
|
||||
_lastTickTime: number;
|
||||
/** @type {Number} */
|
||||
_startTime: number;
|
||||
/** @type {Number} */
|
||||
_lastTime: number;
|
||||
/** @type {Number} */
|
||||
_frameDuration: number;
|
||||
/** @type {Number} */
|
||||
_fps: number;
|
||||
/** @type {Number} */
|
||||
_speed: number;
|
||||
/** @type {Boolean} */
|
||||
_hasChildren: boolean;
|
||||
/** @type {Tickable|Tween} */
|
||||
_head: Tickable | Tween;
|
||||
/** @type {Tickable|Tween} */
|
||||
_tail: Tickable | Tween;
|
||||
set fps(frameRate: number);
|
||||
get fps(): number;
|
||||
set speed(playbackRate: number);
|
||||
get speed(): number;
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {tickModes}
|
||||
*/
|
||||
requestTick(time: number): tickModes;
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {Number}
|
||||
*/
|
||||
computeDeltaTime(time: number): number;
|
||||
}
|
||||
import type { Tickable } from '../types/index.js';
|
||||
import type { Tween } from '../types/index.js';
|
||||
import { tickModes } from './consts.js';
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { K, maxFps, minValue, tickModes } from './consts.js';
|
||||
import { defaults } from './globals.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tickable,
|
||||
* Tween,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/*
|
||||
* Base class to control framerate and playback rate.
|
||||
* Inherited by Engine, Timer, Animation and Timeline.
|
||||
*/
|
||||
class Clock {
|
||||
|
||||
/** @param {Number} [initTime] */
|
||||
constructor(initTime = 0) {
|
||||
/** @type {Number} */
|
||||
this.deltaTime = 0;
|
||||
/** @type {Number} */
|
||||
this._currentTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._lastTickTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._startTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._lastTime = initTime;
|
||||
/** @type {Number} */
|
||||
this._frameDuration = K / maxFps;
|
||||
/** @type {Number} */
|
||||
this._fps = maxFps;
|
||||
/** @type {Number} */
|
||||
this._speed = 1;
|
||||
/** @type {Boolean} */
|
||||
this._hasChildren = false;
|
||||
/** @type {Tickable|Tween} */
|
||||
this._head = null;
|
||||
/** @type {Tickable|Tween} */
|
||||
this._tail = null;
|
||||
}
|
||||
|
||||
get fps() {
|
||||
return this._fps;
|
||||
}
|
||||
|
||||
set fps(frameRate) {
|
||||
const fr = +frameRate;
|
||||
const fps = fr < minValue ? minValue : fr;
|
||||
const frameDuration = K / fps;
|
||||
if (fps > defaults.frameRate) defaults.frameRate = fps;
|
||||
this._fps = fps;
|
||||
this._frameDuration = frameDuration;
|
||||
}
|
||||
|
||||
get speed() {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
set speed(playbackRate) {
|
||||
const pbr = +playbackRate;
|
||||
this._speed = pbr < minValue ? minValue : pbr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {tickModes}
|
||||
*/
|
||||
requestTick(time) {
|
||||
const frameDuration = this._frameDuration;
|
||||
const elapsed = time - this._lastTickTime;
|
||||
const scaled = frameDuration * .25;
|
||||
const tolerance = scaled < 4 ? scaled : 4;
|
||||
// Tolerance prevents dropping frames that arrive a bit early due to RAF jitter
|
||||
// typically <= ~25% of frame duration and capped at 4ms so it doesn't dominate at high fps.
|
||||
// e.g. at 60fps (frameDuration=16.667ms) a frame arriving after 15ms:
|
||||
// - without tolerance: 15 < 16.667 -> skip
|
||||
// - with tolerance: 15 + 4 >= 16.667 -> tick
|
||||
if (elapsed + tolerance < frameDuration) return tickModes.NONE;
|
||||
this._lastTickTime = elapsed >= frameDuration ? time - (elapsed % frameDuration) : time;
|
||||
return tickModes.AUTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} time
|
||||
* @return {Number}
|
||||
*/
|
||||
computeDeltaTime(time) {
|
||||
const delta = time - this._lastTime;
|
||||
this.deltaTime = delta;
|
||||
this._lastTime = time;
|
||||
return delta;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Clock };
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('./consts.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* ColorArray,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* RGB / RGBA Color value string -> RGBA values array
|
||||
* @param {String} rgbValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const rgbToRgba = rgbValue => {
|
||||
const rgba = consts.rgbExecRgx.exec(rgbValue) || consts.rgbaExecRgx.exec(rgbValue);
|
||||
const a = !helpers.isUnd(rgba[4]) ? +rgba[4] : 1;
|
||||
return [
|
||||
+rgba[1],
|
||||
+rgba[2],
|
||||
+rgba[3],
|
||||
a
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* HEX3 / HEX3A / HEX6 / HEX6A Color value string -> RGBA values array
|
||||
* @param {String} hexValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const hexToRgba = hexValue => {
|
||||
const hexLength = hexValue.length;
|
||||
const isShort = hexLength === 4 || hexLength === 5;
|
||||
return [
|
||||
+('0x' + hexValue[1] + hexValue[isShort ? 1 : 2]),
|
||||
+('0x' + hexValue[isShort ? 2 : 3] + hexValue[isShort ? 2 : 4]),
|
||||
+('0x' + hexValue[isShort ? 3 : 5] + hexValue[isShort ? 3 : 6]),
|
||||
((hexLength === 5 || hexLength === 9) ? +(+('0x' + hexValue[isShort ? 4 : 7] + hexValue[isShort ? 4 : 8]) / 255).toFixed(3) : 1)
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} p
|
||||
* @param {Number} q
|
||||
* @param {Number} t
|
||||
* @return {Number}
|
||||
*/
|
||||
const hue2rgb = (p, q, t) => {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
return t < 1 / 6 ? p + (q - p) * 6 * t :
|
||||
t < 1 / 2 ? q :
|
||||
t < 2 / 3 ? p + (q - p) * (2 / 3 - t) * 6 :
|
||||
p;
|
||||
};
|
||||
|
||||
/**
|
||||
* HSL / HSLA Color value string -> RGBA values array
|
||||
* @param {String} hslValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const hslToRgba = hslValue => {
|
||||
const hsla = consts.hslExecRgx.exec(hslValue) || consts.hslaExecRgx.exec(hslValue);
|
||||
const h = +hsla[1] / 360;
|
||||
const s = +hsla[2] / 100;
|
||||
const l = +hsla[3] / 100;
|
||||
const a = !helpers.isUnd(hsla[4]) ? +hsla[4] : 1;
|
||||
let r, g, b;
|
||||
if (s === 0) {
|
||||
r = g = b = l;
|
||||
} else {
|
||||
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
||||
const p = 2 * l - q;
|
||||
r = helpers.round(hue2rgb(p, q, h + 1 / 3) * 255, 0);
|
||||
g = helpers.round(hue2rgb(p, q, h) * 255, 0);
|
||||
b = helpers.round(hue2rgb(p, q, h - 1 / 3) * 255, 0);
|
||||
}
|
||||
return [r, g, b, a];
|
||||
};
|
||||
|
||||
/**
|
||||
* All in one color converter that converts a color string value into an array of RGBA values
|
||||
* @param {String} colorString
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const convertColorStringValuesToRgbaArray = colorString => {
|
||||
return helpers.isRgb(colorString) ? rgbToRgba(colorString) :
|
||||
helpers.isHex(colorString) ? hexToRgba(colorString) :
|
||||
helpers.isHsl(colorString) ? hslToRgba(colorString) :
|
||||
[0, 0, 0, 1];
|
||||
};
|
||||
|
||||
exports.convertColorStringValuesToRgbaArray = convertColorStringValuesToRgbaArray;
|
||||
@@ -0,0 +1,2 @@
|
||||
export function convertColorStringValuesToRgbaArray(colorString: string): ColorArray;
|
||||
import type { ColorArray } from '../types/index.js';
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { rgbExecRgx, rgbaExecRgx, hslExecRgx, hslaExecRgx } from './consts.js';
|
||||
import { isRgb, isHex, isHsl, isUnd, round } from './helpers.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* ColorArray,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* RGB / RGBA Color value string -> RGBA values array
|
||||
* @param {String} rgbValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const rgbToRgba = rgbValue => {
|
||||
const rgba = rgbExecRgx.exec(rgbValue) || rgbaExecRgx.exec(rgbValue);
|
||||
const a = !isUnd(rgba[4]) ? +rgba[4] : 1;
|
||||
return [
|
||||
+rgba[1],
|
||||
+rgba[2],
|
||||
+rgba[3],
|
||||
a
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* HEX3 / HEX3A / HEX6 / HEX6A Color value string -> RGBA values array
|
||||
* @param {String} hexValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const hexToRgba = hexValue => {
|
||||
const hexLength = hexValue.length;
|
||||
const isShort = hexLength === 4 || hexLength === 5;
|
||||
return [
|
||||
+('0x' + hexValue[1] + hexValue[isShort ? 1 : 2]),
|
||||
+('0x' + hexValue[isShort ? 2 : 3] + hexValue[isShort ? 2 : 4]),
|
||||
+('0x' + hexValue[isShort ? 3 : 5] + hexValue[isShort ? 3 : 6]),
|
||||
((hexLength === 5 || hexLength === 9) ? +(+('0x' + hexValue[isShort ? 4 : 7] + hexValue[isShort ? 4 : 8]) / 255).toFixed(3) : 1)
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} p
|
||||
* @param {Number} q
|
||||
* @param {Number} t
|
||||
* @return {Number}
|
||||
*/
|
||||
const hue2rgb = (p, q, t) => {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
return t < 1 / 6 ? p + (q - p) * 6 * t :
|
||||
t < 1 / 2 ? q :
|
||||
t < 2 / 3 ? p + (q - p) * (2 / 3 - t) * 6 :
|
||||
p;
|
||||
};
|
||||
|
||||
/**
|
||||
* HSL / HSLA Color value string -> RGBA values array
|
||||
* @param {String} hslValue
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const hslToRgba = hslValue => {
|
||||
const hsla = hslExecRgx.exec(hslValue) || hslaExecRgx.exec(hslValue);
|
||||
const h = +hsla[1] / 360;
|
||||
const s = +hsla[2] / 100;
|
||||
const l = +hsla[3] / 100;
|
||||
const a = !isUnd(hsla[4]) ? +hsla[4] : 1;
|
||||
let r, g, b;
|
||||
if (s === 0) {
|
||||
r = g = b = l;
|
||||
} else {
|
||||
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
||||
const p = 2 * l - q;
|
||||
r = round(hue2rgb(p, q, h + 1 / 3) * 255, 0);
|
||||
g = round(hue2rgb(p, q, h) * 255, 0);
|
||||
b = round(hue2rgb(p, q, h - 1 / 3) * 255, 0);
|
||||
}
|
||||
return [r, g, b, a];
|
||||
};
|
||||
|
||||
/**
|
||||
* All in one color converter that converts a color string value into an array of RGBA values
|
||||
* @param {String} colorString
|
||||
* @return {ColorArray}
|
||||
*/
|
||||
const convertColorStringValuesToRgbaArray = colorString => {
|
||||
return isRgb(colorString) ? rgbToRgba(colorString) :
|
||||
isHex(colorString) ? hexToRgba(colorString) :
|
||||
isHsl(colorString) ? hslToRgba(colorString) :
|
||||
[0, 0, 0, 1];
|
||||
};
|
||||
|
||||
export { convertColorStringValuesToRgbaArray };
|
||||
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Environments
|
||||
|
||||
// TODO: Do we need to check if we're running inside a worker ?
|
||||
const isBrowser = typeof window !== 'undefined';
|
||||
|
||||
/** @typedef {Window & {AnimeJS: Array}|null} AnimeJSWindow
|
||||
|
||||
/** @type {AnimeJSWindow} */
|
||||
const win = isBrowser ? /** @type {AnimeJSWindow} */(/** @type {unknown} */(window)) : null;
|
||||
|
||||
/** @type {Document|null} */
|
||||
const doc = isBrowser ? document : null;
|
||||
|
||||
// Enums
|
||||
|
||||
/** @enum {Number} */
|
||||
const tweenTypes = {
|
||||
OBJECT: 0,
|
||||
ATTRIBUTE: 1,
|
||||
CSS: 2,
|
||||
TRANSFORM: 3,
|
||||
CSS_VAR: 4,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const valueTypes = {
|
||||
NUMBER: 0,
|
||||
UNIT: 1,
|
||||
COLOR: 2,
|
||||
COMPLEX: 3,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const tickModes = {
|
||||
NONE: 0,
|
||||
AUTO: 1,
|
||||
FORCE: 2,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const compositionTypes = {
|
||||
replace: 0,
|
||||
none: 1,
|
||||
blend: 2,
|
||||
};
|
||||
|
||||
// Cache symbols
|
||||
|
||||
const isRegisteredTargetSymbol = Symbol();
|
||||
const isDomSymbol = Symbol();
|
||||
const isSvgSymbol = Symbol();
|
||||
const transformsSymbol = Symbol();
|
||||
const proxyTargetSymbol = Symbol();
|
||||
|
||||
// Numbers
|
||||
|
||||
const minValue = 1e-11;
|
||||
const maxValue = 1e12;
|
||||
const K = 1e3;
|
||||
const maxFps = 240;
|
||||
|
||||
// Strings
|
||||
|
||||
const emptyString = '';
|
||||
const cssVarPrefix = 'var(';
|
||||
|
||||
// Arrays
|
||||
|
||||
// Shared sentinel for tween slots that don't hold array data. Never mutated, only read; COMPLEX and COLOR tweens always replace the slot before writing.
|
||||
const emptyArray = [];
|
||||
|
||||
const shortTransforms = /*#__PURE__*/ (() => {
|
||||
const map = new Map();
|
||||
map.set('x', 'translateX');
|
||||
map.set('y', 'translateY');
|
||||
map.set('z', 'translateZ');
|
||||
return map;
|
||||
})();
|
||||
|
||||
const validTransforms = [
|
||||
'perspective',
|
||||
'translateX',
|
||||
'translateY',
|
||||
'translateZ',
|
||||
'rotate',
|
||||
'rotateX',
|
||||
'rotateY',
|
||||
'rotateZ',
|
||||
'scale',
|
||||
'scaleX',
|
||||
'scaleY',
|
||||
'scaleZ',
|
||||
'skew',
|
||||
'skewX',
|
||||
'skewY',
|
||||
];
|
||||
|
||||
const transformsFragmentStrings = /*#__PURE__*/ validTransforms.reduce((a, v) => ({...a, [v]: v + '('}), {});
|
||||
|
||||
// Functions
|
||||
|
||||
/** @return {void} */
|
||||
const noop = () => {};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} v
|
||||
* @return {T}
|
||||
*/
|
||||
const noopModifier = v => v;
|
||||
|
||||
// Regex
|
||||
|
||||
const validRgbHslRgx = /\)\s*[-.\d]/;
|
||||
const hexTestRgx = /(^#([\da-f]{3}){1,2}$)|(^#([\da-f]{4}){1,2}$)/i;
|
||||
const rgbExecRgx = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i;
|
||||
const rgbaExecRgx = /rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(-?\d+|-?\d*.\d+)\s*\)/i;
|
||||
const hslExecRgx = /hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)/i;
|
||||
const hslaExecRgx = /hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)/i;
|
||||
// export const digitWithExponentRgx = /[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g;
|
||||
const digitWithExponentRgx = /[-+]?\d*\.?\d+(?:e[-+]?\d)?/gi;
|
||||
// export const unitsExecRgx = /^([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)+([a-z]+|%)$/i;
|
||||
const unitsExecRgx = /^([-+]?\d*\.?\d+(?:e[-+]?\d+)?)([a-z]+|%)$/i;
|
||||
const lowerCaseRgx = /([a-z])([A-Z])/g;
|
||||
const relativeValuesExecRgx = /(\*=|\+=|-=)/;
|
||||
const cssVariableMatchRgx = /var\(\s*(--[\w-]+)(?:\s*,\s*([^)]+))?\s*\)/;
|
||||
|
||||
exports.K = K;
|
||||
exports.compositionTypes = compositionTypes;
|
||||
exports.cssVarPrefix = cssVarPrefix;
|
||||
exports.cssVariableMatchRgx = cssVariableMatchRgx;
|
||||
exports.digitWithExponentRgx = digitWithExponentRgx;
|
||||
exports.doc = doc;
|
||||
exports.emptyArray = emptyArray;
|
||||
exports.emptyString = emptyString;
|
||||
exports.hexTestRgx = hexTestRgx;
|
||||
exports.hslExecRgx = hslExecRgx;
|
||||
exports.hslaExecRgx = hslaExecRgx;
|
||||
exports.isBrowser = isBrowser;
|
||||
exports.isDomSymbol = isDomSymbol;
|
||||
exports.isRegisteredTargetSymbol = isRegisteredTargetSymbol;
|
||||
exports.isSvgSymbol = isSvgSymbol;
|
||||
exports.lowerCaseRgx = lowerCaseRgx;
|
||||
exports.maxFps = maxFps;
|
||||
exports.maxValue = maxValue;
|
||||
exports.minValue = minValue;
|
||||
exports.noop = noop;
|
||||
exports.noopModifier = noopModifier;
|
||||
exports.proxyTargetSymbol = proxyTargetSymbol;
|
||||
exports.relativeValuesExecRgx = relativeValuesExecRgx;
|
||||
exports.rgbExecRgx = rgbExecRgx;
|
||||
exports.rgbaExecRgx = rgbaExecRgx;
|
||||
exports.shortTransforms = shortTransforms;
|
||||
exports.tickModes = tickModes;
|
||||
exports.transformsFragmentStrings = transformsFragmentStrings;
|
||||
exports.transformsSymbol = transformsSymbol;
|
||||
exports.tweenTypes = tweenTypes;
|
||||
exports.unitsExecRgx = unitsExecRgx;
|
||||
exports.validRgbHslRgx = validRgbHslRgx;
|
||||
exports.validTransforms = validTransforms;
|
||||
exports.valueTypes = valueTypes;
|
||||
exports.win = win;
|
||||
@@ -0,0 +1,68 @@
|
||||
export const isBrowser: boolean;
|
||||
/** @typedef {Window & {AnimeJS: Array}|null} AnimeJSWindow
|
||||
|
||||
/** @type {AnimeJSWindow} */
|
||||
export const win: AnimeJSWindow;
|
||||
/** @type {Document|null} */
|
||||
export const doc: Document | null;
|
||||
export type tweenTypes = number;
|
||||
export namespace tweenTypes {
|
||||
let OBJECT: number;
|
||||
let ATTRIBUTE: number;
|
||||
let CSS: number;
|
||||
let TRANSFORM: number;
|
||||
let CSS_VAR: number;
|
||||
}
|
||||
export type valueTypes = number;
|
||||
export namespace valueTypes {
|
||||
let NUMBER: number;
|
||||
let UNIT: number;
|
||||
let COLOR: number;
|
||||
let COMPLEX: number;
|
||||
}
|
||||
export type tickModes = number;
|
||||
export namespace tickModes {
|
||||
let NONE: number;
|
||||
let AUTO: number;
|
||||
let FORCE: number;
|
||||
}
|
||||
export type compositionTypes = number;
|
||||
export namespace compositionTypes {
|
||||
let replace: number;
|
||||
let none: number;
|
||||
let blend: number;
|
||||
}
|
||||
export const isRegisteredTargetSymbol: unique symbol;
|
||||
export const isDomSymbol: unique symbol;
|
||||
export const isSvgSymbol: unique symbol;
|
||||
export const transformsSymbol: unique symbol;
|
||||
export const proxyTargetSymbol: unique symbol;
|
||||
export const minValue: 1e-11;
|
||||
export const maxValue: 1000000000000;
|
||||
export const K: 1000;
|
||||
export const maxFps: 240;
|
||||
export const emptyString: "";
|
||||
export const cssVarPrefix: "var(";
|
||||
export const emptyArray: any[];
|
||||
export const shortTransforms: Map<any, any>;
|
||||
export const validTransforms: string[];
|
||||
export const transformsFragmentStrings: {};
|
||||
export function noop(): void;
|
||||
export function noopModifier<T>(v: T): T;
|
||||
export const validRgbHslRgx: RegExp;
|
||||
export const hexTestRgx: RegExp;
|
||||
export const rgbExecRgx: RegExp;
|
||||
export const rgbaExecRgx: RegExp;
|
||||
export const hslExecRgx: RegExp;
|
||||
export const hslaExecRgx: RegExp;
|
||||
export const digitWithExponentRgx: RegExp;
|
||||
export const unitsExecRgx: RegExp;
|
||||
export const lowerCaseRgx: RegExp;
|
||||
export const relativeValuesExecRgx: RegExp;
|
||||
export const cssVariableMatchRgx: RegExp;
|
||||
/**
|
||||
* /**
|
||||
*/
|
||||
export type AnimeJSWindow = (Window & {
|
||||
AnimeJS: any[];
|
||||
}) | null;
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
// Environments
|
||||
|
||||
// TODO: Do we need to check if we're running inside a worker ?
|
||||
const isBrowser = typeof window !== 'undefined';
|
||||
|
||||
/** @typedef {Window & {AnimeJS: Array}|null} AnimeJSWindow
|
||||
|
||||
/** @type {AnimeJSWindow} */
|
||||
const win = isBrowser ? /** @type {AnimeJSWindow} */(/** @type {unknown} */(window)) : null;
|
||||
|
||||
/** @type {Document|null} */
|
||||
const doc = isBrowser ? document : null;
|
||||
|
||||
// Enums
|
||||
|
||||
/** @enum {Number} */
|
||||
const tweenTypes = {
|
||||
OBJECT: 0,
|
||||
ATTRIBUTE: 1,
|
||||
CSS: 2,
|
||||
TRANSFORM: 3,
|
||||
CSS_VAR: 4,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const valueTypes = {
|
||||
NUMBER: 0,
|
||||
UNIT: 1,
|
||||
COLOR: 2,
|
||||
COMPLEX: 3,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const tickModes = {
|
||||
NONE: 0,
|
||||
AUTO: 1,
|
||||
FORCE: 2,
|
||||
};
|
||||
|
||||
/** @enum {Number} */
|
||||
const compositionTypes = {
|
||||
replace: 0,
|
||||
none: 1,
|
||||
blend: 2,
|
||||
};
|
||||
|
||||
// Cache symbols
|
||||
|
||||
const isRegisteredTargetSymbol = Symbol();
|
||||
const isDomSymbol = Symbol();
|
||||
const isSvgSymbol = Symbol();
|
||||
const transformsSymbol = Symbol();
|
||||
const proxyTargetSymbol = Symbol();
|
||||
|
||||
// Numbers
|
||||
|
||||
const minValue = 1e-11;
|
||||
const maxValue = 1e12;
|
||||
const K = 1e3;
|
||||
const maxFps = 240;
|
||||
|
||||
// Strings
|
||||
|
||||
const emptyString = '';
|
||||
const cssVarPrefix = 'var(';
|
||||
|
||||
// Arrays
|
||||
|
||||
// Shared sentinel for tween slots that don't hold array data. Never mutated, only read; COMPLEX and COLOR tweens always replace the slot before writing.
|
||||
const emptyArray = [];
|
||||
|
||||
const shortTransforms = /*#__PURE__*/ (() => {
|
||||
const map = new Map();
|
||||
map.set('x', 'translateX');
|
||||
map.set('y', 'translateY');
|
||||
map.set('z', 'translateZ');
|
||||
return map;
|
||||
})();
|
||||
|
||||
const validTransforms = [
|
||||
'perspective',
|
||||
'translateX',
|
||||
'translateY',
|
||||
'translateZ',
|
||||
'rotate',
|
||||
'rotateX',
|
||||
'rotateY',
|
||||
'rotateZ',
|
||||
'scale',
|
||||
'scaleX',
|
||||
'scaleY',
|
||||
'scaleZ',
|
||||
'skew',
|
||||
'skewX',
|
||||
'skewY',
|
||||
];
|
||||
|
||||
const transformsFragmentStrings = /*#__PURE__*/ validTransforms.reduce((a, v) => ({...a, [v]: v + '('}), {});
|
||||
|
||||
// Functions
|
||||
|
||||
/** @return {void} */
|
||||
const noop = () => {};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} v
|
||||
* @return {T}
|
||||
*/
|
||||
const noopModifier = v => v;
|
||||
|
||||
// Regex
|
||||
|
||||
const validRgbHslRgx = /\)\s*[-.\d]/;
|
||||
const hexTestRgx = /(^#([\da-f]{3}){1,2}$)|(^#([\da-f]{4}){1,2}$)/i;
|
||||
const rgbExecRgx = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i;
|
||||
const rgbaExecRgx = /rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(-?\d+|-?\d*.\d+)\s*\)/i;
|
||||
const hslExecRgx = /hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)/i;
|
||||
const hslaExecRgx = /hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)/i;
|
||||
// export const digitWithExponentRgx = /[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g;
|
||||
const digitWithExponentRgx = /[-+]?\d*\.?\d+(?:e[-+]?\d)?/gi;
|
||||
// export const unitsExecRgx = /^([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)+([a-z]+|%)$/i;
|
||||
const unitsExecRgx = /^([-+]?\d*\.?\d+(?:e[-+]?\d+)?)([a-z]+|%)$/i;
|
||||
const lowerCaseRgx = /([a-z])([A-Z])/g;
|
||||
const relativeValuesExecRgx = /(\*=|\+=|-=)/;
|
||||
const cssVariableMatchRgx = /var\(\s*(--[\w-]+)(?:\s*,\s*([^)]+))?\s*\)/;
|
||||
|
||||
export { K, compositionTypes, cssVarPrefix, cssVariableMatchRgx, digitWithExponentRgx, doc, emptyArray, emptyString, hexTestRgx, hslExecRgx, hslaExecRgx, isBrowser, isDomSymbol, isRegisteredTargetSymbol, isSvgSymbol, lowerCaseRgx, maxFps, maxValue, minValue, noop, noopModifier, proxyTargetSymbol, relativeValuesExecRgx, rgbExecRgx, rgbaExecRgx, shortTransforms, tickModes, transformsFragmentStrings, transformsSymbol, tweenTypes, unitsExecRgx, validRgbHslRgx, validTransforms, valueTypes, win };
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('./consts.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* DefaultsParams,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* Scope,
|
||||
* } from '../scope/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EditorGlobals
|
||||
* @property {boolean} showPanel
|
||||
* @property {Function} addAnimation
|
||||
* @property {Function} addSet
|
||||
* @property {Function} addTimeline
|
||||
* @property {Function} addTimelineChild
|
||||
* @property {Function} addTimelineLabel
|
||||
* @property {Function} addTimelineCall
|
||||
* @property {Function} addTimelineSync
|
||||
* @property {Function} resolveStagger
|
||||
* @property {Object|null} _head
|
||||
* @property {Object|null} _tail
|
||||
*/
|
||||
|
||||
/** @type {DefaultsParams} */
|
||||
const defaults = {
|
||||
id: null,
|
||||
keyframes: null,
|
||||
playbackEase: null,
|
||||
playbackRate: 1,
|
||||
frameRate: consts.maxFps,
|
||||
loop: 0,
|
||||
reversed: false,
|
||||
alternate: false,
|
||||
autoplay: true,
|
||||
persist: false,
|
||||
duration: consts.K,
|
||||
delay: 0,
|
||||
loopDelay: 0,
|
||||
ease: 'out(2)',
|
||||
composition: consts.compositionTypes.replace,
|
||||
modifier: consts.noopModifier,
|
||||
onBegin: consts.noop,
|
||||
onBeforeUpdate: consts.noop,
|
||||
onUpdate: consts.noop,
|
||||
onLoop: consts.noop,
|
||||
onPause: consts.noop,
|
||||
onComplete: consts.noop,
|
||||
onRender: consts.noop,
|
||||
};
|
||||
|
||||
const scope = {
|
||||
/** @type {Scope} */
|
||||
current: null,
|
||||
/** @type {Document|DOMTarget} */
|
||||
root: consts.doc,
|
||||
};
|
||||
|
||||
const globals = {
|
||||
/** @type {DefaultsParams} */
|
||||
defaults,
|
||||
/** @type {Number} */
|
||||
precision: 4,
|
||||
/** @type {Number} equals 1 in ms mode, 0.001 in s mode */
|
||||
timeScale: 1,
|
||||
/** @type {Number} */
|
||||
tickThreshold: 200,
|
||||
/** @type {EditorGlobals|null} */
|
||||
editor: null,
|
||||
};
|
||||
|
||||
const globalVersions = { version: '4.5.0', engine: null };
|
||||
|
||||
if (consts.isBrowser) {
|
||||
if (!consts.win.AnimeJS) consts.win.AnimeJS = [];
|
||||
consts.win.AnimeJS.push(globalVersions);
|
||||
}
|
||||
|
||||
exports.defaults = defaults;
|
||||
exports.globalVersions = globalVersions;
|
||||
exports.globals = globals;
|
||||
exports.scope = scope;
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @import {
|
||||
* DefaultsParams,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* Scope,
|
||||
* } from '../scope/index.js'
|
||||
*/
|
||||
/**
|
||||
* @typedef {Object} EditorGlobals
|
||||
* @property {boolean} showPanel
|
||||
* @property {Function} addAnimation
|
||||
* @property {Function} addSet
|
||||
* @property {Function} addTimeline
|
||||
* @property {Function} addTimelineChild
|
||||
* @property {Function} addTimelineLabel
|
||||
* @property {Function} addTimelineCall
|
||||
* @property {Function} addTimelineSync
|
||||
* @property {Function} resolveStagger
|
||||
* @property {Object|null} _head
|
||||
* @property {Object|null} _tail
|
||||
*/
|
||||
/** @type {DefaultsParams} */
|
||||
export const defaults: DefaultsParams;
|
||||
export namespace scope {
|
||||
export let current: Scope;
|
||||
export { doc as root };
|
||||
}
|
||||
export namespace globals {
|
||||
export { defaults };
|
||||
export let precision: number;
|
||||
export let timeScale: number;
|
||||
export let tickThreshold: number;
|
||||
export let editor: EditorGlobals | null;
|
||||
}
|
||||
export namespace globalVersions {
|
||||
let version: string;
|
||||
let engine: any;
|
||||
}
|
||||
export type EditorGlobals = {
|
||||
showPanel: boolean;
|
||||
addAnimation: Function;
|
||||
addSet: Function;
|
||||
addTimeline: Function;
|
||||
addTimelineChild: Function;
|
||||
addTimelineLabel: Function;
|
||||
addTimelineCall: Function;
|
||||
addTimelineSync: Function;
|
||||
resolveStagger: Function;
|
||||
_head: any | null;
|
||||
_tail: any | null;
|
||||
};
|
||||
import type { DefaultsParams } from '../types/index.js';
|
||||
import type { Scope } from '../scope/index.js';
|
||||
import { doc } from './consts.js';
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { isBrowser, win, noop, noopModifier, compositionTypes, K, maxFps, doc } from './consts.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* DefaultsParams,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*
|
||||
* @import {
|
||||
* Scope,
|
||||
* } from '../scope/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EditorGlobals
|
||||
* @property {boolean} showPanel
|
||||
* @property {Function} addAnimation
|
||||
* @property {Function} addSet
|
||||
* @property {Function} addTimeline
|
||||
* @property {Function} addTimelineChild
|
||||
* @property {Function} addTimelineLabel
|
||||
* @property {Function} addTimelineCall
|
||||
* @property {Function} addTimelineSync
|
||||
* @property {Function} resolveStagger
|
||||
* @property {Object|null} _head
|
||||
* @property {Object|null} _tail
|
||||
*/
|
||||
|
||||
/** @type {DefaultsParams} */
|
||||
const defaults = {
|
||||
id: null,
|
||||
keyframes: null,
|
||||
playbackEase: null,
|
||||
playbackRate: 1,
|
||||
frameRate: maxFps,
|
||||
loop: 0,
|
||||
reversed: false,
|
||||
alternate: false,
|
||||
autoplay: true,
|
||||
persist: false,
|
||||
duration: K,
|
||||
delay: 0,
|
||||
loopDelay: 0,
|
||||
ease: 'out(2)',
|
||||
composition: compositionTypes.replace,
|
||||
modifier: noopModifier,
|
||||
onBegin: noop,
|
||||
onBeforeUpdate: noop,
|
||||
onUpdate: noop,
|
||||
onLoop: noop,
|
||||
onPause: noop,
|
||||
onComplete: noop,
|
||||
onRender: noop,
|
||||
};
|
||||
|
||||
const scope = {
|
||||
/** @type {Scope} */
|
||||
current: null,
|
||||
/** @type {Document|DOMTarget} */
|
||||
root: doc,
|
||||
};
|
||||
|
||||
const globals = {
|
||||
/** @type {DefaultsParams} */
|
||||
defaults,
|
||||
/** @type {Number} */
|
||||
precision: 4,
|
||||
/** @type {Number} equals 1 in ms mode, 0.001 in s mode */
|
||||
timeScale: 1,
|
||||
/** @type {Number} */
|
||||
tickThreshold: 200,
|
||||
/** @type {EditorGlobals|null} */
|
||||
editor: null,
|
||||
};
|
||||
|
||||
const globalVersions = { version: '4.5.0', engine: null };
|
||||
|
||||
if (isBrowser) {
|
||||
if (!win.AnimeJS) win.AnimeJS = [];
|
||||
win.AnimeJS.push(globalVersions);
|
||||
}
|
||||
|
||||
export { defaults, globalVersions, globals, scope };
|
||||
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('./consts.cjs');
|
||||
var globals = require('./globals.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Target,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
// Strings
|
||||
|
||||
/**
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
const toLowerCase = str => str.replace(consts.lowerCaseRgx, '$1-$2').toLowerCase();
|
||||
|
||||
/**
|
||||
* Prioritize this method instead of regex when possible
|
||||
* @param {String} str
|
||||
* @param {String} sub
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const stringStartsWith = (str, sub) => str.indexOf(sub) === 0;
|
||||
|
||||
// Note: Date.now is used instead of performance.now since it is precise enough for timings calculations, performs slightly faster and works in Node.js environement.
|
||||
const now = Date.now;
|
||||
|
||||
// Types checkers
|
||||
|
||||
const isArr = Array.isArray;
|
||||
/**@param {any} a @return {a is Record<String, any>} */
|
||||
const isObj = a => a && a.constructor === Object;
|
||||
/**@param {any} a @return {a is Number} */
|
||||
const isNum = a => typeof a === 'number' && !isNaN(a);
|
||||
/**@param {any} a @return {a is String} */
|
||||
const isStr = a => typeof a === 'string';
|
||||
/**@param {any} a @return {a is Function} */
|
||||
const isFnc = a => typeof a === 'function';
|
||||
/**@param {any} a @return {a is undefined} */
|
||||
const isUnd = a => typeof a === 'undefined';
|
||||
/**@param {any} a @return {a is null | undefined} */
|
||||
const isNil = a => isUnd(a) || a === null;
|
||||
/**@param {any} a @return {a is SVGElement} */
|
||||
const isSvg = a => consts.isBrowser && a instanceof SVGElement;
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isHex = a => consts.hexTestRgx.test(a);
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isRgb = a => stringStartsWith(a, 'rgb');
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isHsl = a => stringStartsWith(a, 'hsl');
|
||||
/**@param {any} a @return {Boolean} */ // Make sure boxShadow syntax like 'rgb(255, 0, 0) 0px 0px 6px 0px' is not a valid color type
|
||||
const isCol = a => isHex(a) || ((isRgb(a) || isHsl(a)) && (a[a.length - 1] === ')' || !consts.validRgbHslRgx.test(a)));
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isKey = a => !globals.globals.defaults.hasOwnProperty(a);
|
||||
|
||||
// SVG
|
||||
|
||||
// Consider the following as CSS animation
|
||||
// CSS opacity animation has better default values (opacity: 1 instead of 0))
|
||||
// rotate is more commonly intended to be used as a transform
|
||||
const svgCssReservedProperties = ['opacity', 'rotate', 'overflow', 'color'];
|
||||
|
||||
/**
|
||||
* @param {Target} el
|
||||
* @param {String} propertyName
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const isValidSVGAttribute = (el, propertyName) => {
|
||||
if (svgCssReservedProperties.includes(propertyName)) return false;
|
||||
if (el.getAttribute(propertyName) || propertyName in el) {
|
||||
if (propertyName === 'scale') { // Scale
|
||||
const elParentNode = /** @type {SVGGeometryElement} */(/** @type {DOMTarget} */(el).parentNode);
|
||||
// Only consider scale as a valid SVG attribute on filter element
|
||||
return elParentNode && elParentNode.tagName === 'filter';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Number
|
||||
|
||||
/**
|
||||
* @param {Number|String} str
|
||||
* @return {Number}
|
||||
*/
|
||||
const parseNumber = str => isStr(str) ?
|
||||
parseFloat(/** @type {String} */(str)) :
|
||||
/** @type {Number} */(str);
|
||||
|
||||
// Math
|
||||
|
||||
const pow = Math.pow;
|
||||
const sqrt = Math.sqrt;
|
||||
const sin = Math.sin;
|
||||
const cos = Math.cos;
|
||||
const abs = Math.abs;
|
||||
const exp = Math.exp;
|
||||
const ceil = Math.ceil;
|
||||
const floor = Math.floor;
|
||||
const asin = Math.asin;
|
||||
const max = Math.max;
|
||||
const atan2 = Math.atan2;
|
||||
const PI = Math.PI;
|
||||
const _round = Math.round;
|
||||
|
||||
/**
|
||||
* Clamps a value between min and max bounds
|
||||
*
|
||||
* @param {Number} v - Value to clamp
|
||||
* @param {Number} min - Minimum boundary
|
||||
* @param {Number} max - Maximum boundary
|
||||
* @return {Number}
|
||||
*/
|
||||
const clamp = (v, min, max) => v < min ? min : v > max ? max : v;
|
||||
|
||||
/**
|
||||
* Rounds a number to specified decimal places
|
||||
*
|
||||
* @param {Number} v - Value to round
|
||||
* @param {Number} decimalLength - Number of decimal places
|
||||
* @return {Number}
|
||||
*/
|
||||
const round = (v, decimalLength) => {
|
||||
if (decimalLength < 0) return v;
|
||||
if (!decimalLength) return _round(v);
|
||||
const p = 10 ** decimalLength;
|
||||
return _round(v * p) / p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Snaps a value to nearest increment or array value
|
||||
*
|
||||
* @param {Number} v - Value to snap
|
||||
* @param {Number|Array<Number>} increment - Step size or array of snap points
|
||||
* @return {Number}
|
||||
*/
|
||||
const snap = (v, increment) => isArr(increment) ? increment.reduce((closest, cv) => (abs(cv - v) < abs(closest - v) ? cv : closest)) : increment ? _round(v / increment) * increment : v;
|
||||
|
||||
/**
|
||||
* Linear interpolation between two values
|
||||
*
|
||||
* @param {Number} start - Starting value
|
||||
* @param {Number} end - Ending value
|
||||
* @param {Number} factor - Interpolation factor in the range [0, 1]
|
||||
* @return {Number} The interpolated value
|
||||
*/
|
||||
const lerp = (start, end, factor) => factor === 1 ? end : factor === 0 ? start : start + (end - start) * factor;
|
||||
|
||||
/**
|
||||
* Replaces infinity with maximum safe value
|
||||
*
|
||||
* @param {Number} v - Value to check
|
||||
* @return {Number}
|
||||
*/
|
||||
const clampInfinity = v => v === Infinity ? consts.maxValue : v === -Infinity ? -consts.maxValue : v;
|
||||
|
||||
/**
|
||||
* Normalizes time value with minimum threshold
|
||||
*
|
||||
* @param {Number} v - Time value to normalize
|
||||
* @return {Number}
|
||||
*/
|
||||
const normalizeTime = v => v <= consts.minValue ? consts.minValue : clampInfinity(round(v, 11));
|
||||
|
||||
// Arrays
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T[]} a
|
||||
* @return {T[]}
|
||||
*/
|
||||
const cloneArray = a => isArr(a) ? [ ...a ] : a;
|
||||
|
||||
// Objects
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U
|
||||
* @param {T} o1
|
||||
* @param {U} o2
|
||||
* @return {T & U}
|
||||
*/
|
||||
const mergeObjects = (o1, o2) => {
|
||||
const merged = /** @type {T & U} */({ ...o1 });
|
||||
for (let p in o2) {
|
||||
const o1p = /** @type {T & U} */(o1)[p];
|
||||
merged[p] = isUnd(o1p) ? /** @type {T & U} */(o2)[p] : o1p;
|
||||
} return merged;
|
||||
};
|
||||
|
||||
// Linked lists
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Function} callback
|
||||
* @param {Boolean} [reverse]
|
||||
* @param {String} [prevProp]
|
||||
* @param {String} [nextProp]
|
||||
* @return {void}
|
||||
*/
|
||||
const forEachChildren = (parent, callback, reverse, prevProp = '_prev', nextProp = '_next') => {
|
||||
let next = parent._head;
|
||||
let adjustedNextProp = nextProp;
|
||||
if (reverse) {
|
||||
next = parent._tail;
|
||||
adjustedNextProp = prevProp;
|
||||
}
|
||||
while (next) {
|
||||
const currentNext = next[adjustedNextProp];
|
||||
callback(next);
|
||||
next = currentNext;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Object} child
|
||||
* @param {String} [prevProp]
|
||||
* @param {String} [nextProp]
|
||||
* @return {void}
|
||||
*/
|
||||
const removeChild = (parent, child, prevProp = '_prev', nextProp = '_next') => {
|
||||
const prev = child[prevProp];
|
||||
const next = child[nextProp];
|
||||
prev ? prev[nextProp] = next : parent._head = next;
|
||||
next ? next[prevProp] = prev : parent._tail = prev;
|
||||
child[prevProp] = null;
|
||||
child[nextProp] = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Object} child
|
||||
* @param {Function} [sortMethod]
|
||||
* @param {String} prevProp
|
||||
* @param {String} nextProp
|
||||
* @return {void}
|
||||
*/
|
||||
const addChild = (parent, child, sortMethod, prevProp = '_prev', nextProp = '_next') => {
|
||||
let prev = parent._tail;
|
||||
while (prev && sortMethod && sortMethod(prev, child)) prev = prev[prevProp];
|
||||
const next = prev ? prev[nextProp] : parent._head;
|
||||
prev ? prev[nextProp] = child : parent._head = child;
|
||||
next ? next[prevProp] = child : parent._tail = child;
|
||||
child[prevProp] = prev;
|
||||
child[nextProp] = next;
|
||||
};
|
||||
|
||||
exports.PI = PI;
|
||||
exports._round = _round;
|
||||
exports.abs = abs;
|
||||
exports.addChild = addChild;
|
||||
exports.asin = asin;
|
||||
exports.atan2 = atan2;
|
||||
exports.ceil = ceil;
|
||||
exports.clamp = clamp;
|
||||
exports.clampInfinity = clampInfinity;
|
||||
exports.cloneArray = cloneArray;
|
||||
exports.cos = cos;
|
||||
exports.exp = exp;
|
||||
exports.floor = floor;
|
||||
exports.forEachChildren = forEachChildren;
|
||||
exports.isArr = isArr;
|
||||
exports.isCol = isCol;
|
||||
exports.isFnc = isFnc;
|
||||
exports.isHex = isHex;
|
||||
exports.isHsl = isHsl;
|
||||
exports.isKey = isKey;
|
||||
exports.isNil = isNil;
|
||||
exports.isNum = isNum;
|
||||
exports.isObj = isObj;
|
||||
exports.isRgb = isRgb;
|
||||
exports.isStr = isStr;
|
||||
exports.isSvg = isSvg;
|
||||
exports.isUnd = isUnd;
|
||||
exports.isValidSVGAttribute = isValidSVGAttribute;
|
||||
exports.lerp = lerp;
|
||||
exports.max = max;
|
||||
exports.mergeObjects = mergeObjects;
|
||||
exports.normalizeTime = normalizeTime;
|
||||
exports.now = now;
|
||||
exports.parseNumber = parseNumber;
|
||||
exports.pow = pow;
|
||||
exports.removeChild = removeChild;
|
||||
exports.round = round;
|
||||
exports.sin = sin;
|
||||
exports.snap = snap;
|
||||
exports.sqrt = sqrt;
|
||||
exports.stringStartsWith = stringStartsWith;
|
||||
exports.toLowerCase = toLowerCase;
|
||||
@@ -0,0 +1,43 @@
|
||||
export function toLowerCase(str: string): string;
|
||||
export function stringStartsWith(str: string, sub: string): boolean;
|
||||
export const now: () => number;
|
||||
export const isArr: (arg: any) => arg is any[];
|
||||
export function isObj(a: any): a is Record<string, any>;
|
||||
export function isNum(a: any): a is number;
|
||||
export function isStr(a: any): a is string;
|
||||
export function isFnc(a: any): a is Function;
|
||||
export function isUnd(a: any): a is undefined;
|
||||
export function isNil(a: any): a is null | undefined;
|
||||
export function isSvg(a: any): a is SVGElement;
|
||||
export function isHex(a: any): boolean;
|
||||
export function isRgb(a: any): boolean;
|
||||
export function isHsl(a: any): boolean;
|
||||
export function isCol(a: any): boolean;
|
||||
export function isKey(a: any): boolean;
|
||||
export function isValidSVGAttribute(el: Target, propertyName: string): boolean;
|
||||
export function parseNumber(str: number | string): number;
|
||||
export const pow: (x: number, y: number) => number;
|
||||
export const sqrt: (x: number) => number;
|
||||
export const sin: (x: number) => number;
|
||||
export const cos: (x: number) => number;
|
||||
export const abs: (x: number) => number;
|
||||
export const exp: (x: number) => number;
|
||||
export const ceil: (x: number) => number;
|
||||
export const floor: (x: number) => number;
|
||||
export const asin: (x: number) => number;
|
||||
export const max: (...values: number[]) => number;
|
||||
export const atan2: (y: number, x: number) => number;
|
||||
export const PI: number;
|
||||
export const _round: (x: number) => number;
|
||||
export function clamp(v: number, min: number, max: number): number;
|
||||
export function round(v: number, decimalLength: number): number;
|
||||
export function snap(v: number, increment: number | Array<number>): number;
|
||||
export function lerp(start: number, end: number, factor: number): number;
|
||||
export function clampInfinity(v: number): number;
|
||||
export function normalizeTime(v: number): number;
|
||||
export function cloneArray<T>(a: T[]): T[];
|
||||
export function mergeObjects<T, U>(o1: T, o2: U): T & U;
|
||||
export function forEachChildren(parent: any, callback: Function, reverse?: boolean, prevProp?: string, nextProp?: string): void;
|
||||
export function removeChild(parent: any, child: any, prevProp?: string, nextProp?: string): void;
|
||||
export function addChild(parent: any, child: any, sortMethod?: Function, prevProp?: string, nextProp?: string): void;
|
||||
import type { Target } from '../types/index.js';
|
||||
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { isBrowser, maxValue, minValue, hexTestRgx, lowerCaseRgx, validRgbHslRgx } from './consts.js';
|
||||
import { globals } from './globals.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Target,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
// Strings
|
||||
|
||||
/**
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
const toLowerCase = str => str.replace(lowerCaseRgx, '$1-$2').toLowerCase();
|
||||
|
||||
/**
|
||||
* Prioritize this method instead of regex when possible
|
||||
* @param {String} str
|
||||
* @param {String} sub
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const stringStartsWith = (str, sub) => str.indexOf(sub) === 0;
|
||||
|
||||
// Note: Date.now is used instead of performance.now since it is precise enough for timings calculations, performs slightly faster and works in Node.js environement.
|
||||
const now = Date.now;
|
||||
|
||||
// Types checkers
|
||||
|
||||
const isArr = Array.isArray;
|
||||
/**@param {any} a @return {a is Record<String, any>} */
|
||||
const isObj = a => a && a.constructor === Object;
|
||||
/**@param {any} a @return {a is Number} */
|
||||
const isNum = a => typeof a === 'number' && !isNaN(a);
|
||||
/**@param {any} a @return {a is String} */
|
||||
const isStr = a => typeof a === 'string';
|
||||
/**@param {any} a @return {a is Function} */
|
||||
const isFnc = a => typeof a === 'function';
|
||||
/**@param {any} a @return {a is undefined} */
|
||||
const isUnd = a => typeof a === 'undefined';
|
||||
/**@param {any} a @return {a is null | undefined} */
|
||||
const isNil = a => isUnd(a) || a === null;
|
||||
/**@param {any} a @return {a is SVGElement} */
|
||||
const isSvg = a => isBrowser && a instanceof SVGElement;
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isHex = a => hexTestRgx.test(a);
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isRgb = a => stringStartsWith(a, 'rgb');
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isHsl = a => stringStartsWith(a, 'hsl');
|
||||
/**@param {any} a @return {Boolean} */ // Make sure boxShadow syntax like 'rgb(255, 0, 0) 0px 0px 6px 0px' is not a valid color type
|
||||
const isCol = a => isHex(a) || ((isRgb(a) || isHsl(a)) && (a[a.length - 1] === ')' || !validRgbHslRgx.test(a)));
|
||||
/**@param {any} a @return {Boolean} */
|
||||
const isKey = a => !globals.defaults.hasOwnProperty(a);
|
||||
|
||||
// SVG
|
||||
|
||||
// Consider the following as CSS animation
|
||||
// CSS opacity animation has better default values (opacity: 1 instead of 0))
|
||||
// rotate is more commonly intended to be used as a transform
|
||||
const svgCssReservedProperties = ['opacity', 'rotate', 'overflow', 'color'];
|
||||
|
||||
/**
|
||||
* @param {Target} el
|
||||
* @param {String} propertyName
|
||||
* @return {Boolean}
|
||||
*/
|
||||
const isValidSVGAttribute = (el, propertyName) => {
|
||||
if (svgCssReservedProperties.includes(propertyName)) return false;
|
||||
if (el.getAttribute(propertyName) || propertyName in el) {
|
||||
if (propertyName === 'scale') { // Scale
|
||||
const elParentNode = /** @type {SVGGeometryElement} */(/** @type {DOMTarget} */(el).parentNode);
|
||||
// Only consider scale as a valid SVG attribute on filter element
|
||||
return elParentNode && elParentNode.tagName === 'filter';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Number
|
||||
|
||||
/**
|
||||
* @param {Number|String} str
|
||||
* @return {Number}
|
||||
*/
|
||||
const parseNumber = str => isStr(str) ?
|
||||
parseFloat(/** @type {String} */(str)) :
|
||||
/** @type {Number} */(str);
|
||||
|
||||
// Math
|
||||
|
||||
const pow = Math.pow;
|
||||
const sqrt = Math.sqrt;
|
||||
const sin = Math.sin;
|
||||
const cos = Math.cos;
|
||||
const abs = Math.abs;
|
||||
const exp = Math.exp;
|
||||
const ceil = Math.ceil;
|
||||
const floor = Math.floor;
|
||||
const asin = Math.asin;
|
||||
const max = Math.max;
|
||||
const atan2 = Math.atan2;
|
||||
const PI = Math.PI;
|
||||
const _round = Math.round;
|
||||
|
||||
/**
|
||||
* Clamps a value between min and max bounds
|
||||
*
|
||||
* @param {Number} v - Value to clamp
|
||||
* @param {Number} min - Minimum boundary
|
||||
* @param {Number} max - Maximum boundary
|
||||
* @return {Number}
|
||||
*/
|
||||
const clamp = (v, min, max) => v < min ? min : v > max ? max : v;
|
||||
|
||||
/**
|
||||
* Rounds a number to specified decimal places
|
||||
*
|
||||
* @param {Number} v - Value to round
|
||||
* @param {Number} decimalLength - Number of decimal places
|
||||
* @return {Number}
|
||||
*/
|
||||
const round = (v, decimalLength) => {
|
||||
if (decimalLength < 0) return v;
|
||||
if (!decimalLength) return _round(v);
|
||||
const p = 10 ** decimalLength;
|
||||
return _round(v * p) / p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Snaps a value to nearest increment or array value
|
||||
*
|
||||
* @param {Number} v - Value to snap
|
||||
* @param {Number|Array<Number>} increment - Step size or array of snap points
|
||||
* @return {Number}
|
||||
*/
|
||||
const snap = (v, increment) => isArr(increment) ? increment.reduce((closest, cv) => (abs(cv - v) < abs(closest - v) ? cv : closest)) : increment ? _round(v / increment) * increment : v;
|
||||
|
||||
/**
|
||||
* Linear interpolation between two values
|
||||
*
|
||||
* @param {Number} start - Starting value
|
||||
* @param {Number} end - Ending value
|
||||
* @param {Number} factor - Interpolation factor in the range [0, 1]
|
||||
* @return {Number} The interpolated value
|
||||
*/
|
||||
const lerp = (start, end, factor) => factor === 1 ? end : factor === 0 ? start : start + (end - start) * factor;
|
||||
|
||||
/**
|
||||
* Replaces infinity with maximum safe value
|
||||
*
|
||||
* @param {Number} v - Value to check
|
||||
* @return {Number}
|
||||
*/
|
||||
const clampInfinity = v => v === Infinity ? maxValue : v === -Infinity ? -maxValue : v;
|
||||
|
||||
/**
|
||||
* Normalizes time value with minimum threshold
|
||||
*
|
||||
* @param {Number} v - Time value to normalize
|
||||
* @return {Number}
|
||||
*/
|
||||
const normalizeTime = v => v <= minValue ? minValue : clampInfinity(round(v, 11));
|
||||
|
||||
// Arrays
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T[]} a
|
||||
* @return {T[]}
|
||||
*/
|
||||
const cloneArray = a => isArr(a) ? [ ...a ] : a;
|
||||
|
||||
// Objects
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U
|
||||
* @param {T} o1
|
||||
* @param {U} o2
|
||||
* @return {T & U}
|
||||
*/
|
||||
const mergeObjects = (o1, o2) => {
|
||||
const merged = /** @type {T & U} */({ ...o1 });
|
||||
for (let p in o2) {
|
||||
const o1p = /** @type {T & U} */(o1)[p];
|
||||
merged[p] = isUnd(o1p) ? /** @type {T & U} */(o2)[p] : o1p;
|
||||
} return merged;
|
||||
};
|
||||
|
||||
// Linked lists
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Function} callback
|
||||
* @param {Boolean} [reverse]
|
||||
* @param {String} [prevProp]
|
||||
* @param {String} [nextProp]
|
||||
* @return {void}
|
||||
*/
|
||||
const forEachChildren = (parent, callback, reverse, prevProp = '_prev', nextProp = '_next') => {
|
||||
let next = parent._head;
|
||||
let adjustedNextProp = nextProp;
|
||||
if (reverse) {
|
||||
next = parent._tail;
|
||||
adjustedNextProp = prevProp;
|
||||
}
|
||||
while (next) {
|
||||
const currentNext = next[adjustedNextProp];
|
||||
callback(next);
|
||||
next = currentNext;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Object} child
|
||||
* @param {String} [prevProp]
|
||||
* @param {String} [nextProp]
|
||||
* @return {void}
|
||||
*/
|
||||
const removeChild = (parent, child, prevProp = '_prev', nextProp = '_next') => {
|
||||
const prev = child[prevProp];
|
||||
const next = child[nextProp];
|
||||
prev ? prev[nextProp] = next : parent._head = next;
|
||||
next ? next[prevProp] = prev : parent._tail = prev;
|
||||
child[prevProp] = null;
|
||||
child[nextProp] = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} parent
|
||||
* @param {Object} child
|
||||
* @param {Function} [sortMethod]
|
||||
* @param {String} prevProp
|
||||
* @param {String} nextProp
|
||||
* @return {void}
|
||||
*/
|
||||
const addChild = (parent, child, sortMethod, prevProp = '_prev', nextProp = '_next') => {
|
||||
let prev = parent._tail;
|
||||
while (prev && sortMethod && sortMethod(prev, child)) prev = prev[prevProp];
|
||||
const next = prev ? prev[nextProp] : parent._head;
|
||||
prev ? prev[nextProp] = child : parent._head = child;
|
||||
next ? next[prevProp] = child : parent._tail = child;
|
||||
child[prevProp] = prev;
|
||||
child[nextProp] = next;
|
||||
};
|
||||
|
||||
export { PI, _round, abs, addChild, asin, atan2, ceil, clamp, clampInfinity, cloneArray, cos, exp, floor, forEachChildren, isArr, isCol, isFnc, isHex, isHsl, isKey, isNil, isNum, isObj, isRgb, isStr, isSvg, isUnd, isValidSVGAttribute, lerp, max, mergeObjects, normalizeTime, now, parseNumber, pow, removeChild, round, sin, snap, sqrt, stringStartsWith, toLowerCase };
|
||||
@@ -0,0 +1,414 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var globals = require('./globals.cjs');
|
||||
var consts = require('./consts.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
var transforms = require('./transforms.cjs');
|
||||
var values = require('./values.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tickable,
|
||||
* Renderable,
|
||||
* CallbackArgument,
|
||||
* Tween,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Timeline,
|
||||
* } from '../timeline/timeline.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Tickable} tickable
|
||||
* @param {Number} time
|
||||
* @param {Number} muteCallbacks
|
||||
* @param {Number} internalRender
|
||||
* @param {tickModes} tickMode
|
||||
* @return {Number}
|
||||
*/
|
||||
const render = (tickable, time, muteCallbacks, internalRender, tickMode) => {
|
||||
|
||||
const parent = tickable.parent;
|
||||
const duration = tickable.duration;
|
||||
const completed = tickable.completed;
|
||||
const iterationDuration = tickable.iterationDuration;
|
||||
const iterationCount = tickable.iterationCount;
|
||||
const _currentIteration = tickable._currentIteration;
|
||||
const _loopDelay = tickable._loopDelay;
|
||||
const _reversed = tickable._reversed;
|
||||
const _alternate = tickable._alternate;
|
||||
const _hasChildren = tickable._hasChildren;
|
||||
const tickableDelay = tickable._delay;
|
||||
const tickablePrevAbsoluteTime = tickable._currentTime; // TODO: rename ._currentTime to ._absoluteCurrentTime
|
||||
const tickableEndTime = tickableDelay + iterationDuration;
|
||||
const tickableAbsoluteTime = time - tickableDelay;
|
||||
const tickablePrevTime = helpers.clamp(tickablePrevAbsoluteTime, -tickableDelay, duration);
|
||||
const tickableCurrentTime = helpers.clamp(tickableAbsoluteTime, -tickableDelay, duration);
|
||||
const deltaTime = tickableAbsoluteTime - tickablePrevAbsoluteTime;
|
||||
const isCurrentTimeAboveZero = tickableCurrentTime > 0;
|
||||
const isCurrentTimeEqualOrAboveDuration = tickableCurrentTime >= duration;
|
||||
const isSetter = duration <= consts.minValue;
|
||||
const forcedTick = tickMode === consts.tickModes.FORCE;
|
||||
|
||||
let isOdd = 0;
|
||||
let iterationElapsedTime = tickableAbsoluteTime;
|
||||
// Render checks
|
||||
// Used to also check if the children have rendered in order to trigger the onRender callback on the parent timer
|
||||
let hasRendered = 0;
|
||||
|
||||
// Execute the "expensive" iterations calculations only when necessary
|
||||
if (iterationCount > 1) {
|
||||
// bitwise NOT operator seems to be generally faster than Math.floor() across browsers
|
||||
const period = iterationDuration + (isCurrentTimeEqualOrAboveDuration ? 0 : _loopDelay);
|
||||
const currentIteration = ~~(tickableCurrentTime / period);
|
||||
tickable._currentIteration = helpers.clamp(currentIteration, 0, iterationCount);
|
||||
// Prevent the iteration count to go above the max iterations when reaching the end of the animation
|
||||
if (isCurrentTimeEqualOrAboveDuration) tickable._currentIteration--;
|
||||
isOdd = tickable._currentIteration % 2;
|
||||
// Derive elapsed from the same `~~` truncation that gave currentIteration. Using `% period` here can disagree with `~~(/period)` under float drift at iteration boundaries and write the wrong end of the tween for one frame.
|
||||
iterationElapsedTime = tickableCurrentTime - currentIteration * period || 0;
|
||||
}
|
||||
|
||||
// Checks if exactly one of _reversed and (_alternate && isOdd) is true
|
||||
const isReversed = _reversed ^ (_alternate && isOdd);
|
||||
const _ease = /** @type {Renderable} */(tickable)._ease;
|
||||
let iterationTime = isCurrentTimeEqualOrAboveDuration ? isReversed ? 0 : duration : isReversed ? iterationDuration - iterationElapsedTime : iterationElapsedTime;
|
||||
if (_ease) iterationTime = iterationDuration * _ease(iterationTime / iterationDuration) || 0;
|
||||
const isRunningBackwards = (parent ? parent.backwards : tickableAbsoluteTime < tickablePrevAbsoluteTime) ? !isReversed : !!isReversed;
|
||||
|
||||
tickable._currentTime = tickableAbsoluteTime;
|
||||
tickable._iterationTime = iterationTime;
|
||||
tickable.backwards = isRunningBackwards;
|
||||
|
||||
if (isCurrentTimeAboveZero && !tickable.began) {
|
||||
tickable.began = true;
|
||||
if (!muteCallbacks && !(parent && (isRunningBackwards || !parent.began))) {
|
||||
tickable.onBegin(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
} else if (tickableAbsoluteTime <= 0) {
|
||||
tickable.began = false;
|
||||
}
|
||||
|
||||
// Only triggers onLoop for tickable without children, otherwise call the the onLoop callback in the tick function
|
||||
// Make sure to trigger the onLoop before rendering to allow .refresh() to pickup the current values
|
||||
if (!muteCallbacks && !_hasChildren && isCurrentTimeAboveZero && tickable._currentIteration !== _currentIteration) {
|
||||
tickable.onLoop(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
if (
|
||||
forcedTick ||
|
||||
tickMode === consts.tickModes.AUTO && (
|
||||
// Timeline children render from their offset instead of their delay so the gap left by a truncated sibling is covered on seek.
|
||||
time >= (parent && tickableDelay > 0 ? 0 : tickableDelay) && time <= tickableEndTime || // Normal render
|
||||
time <= tickableDelay && tickablePrevTime > tickableDelay || // Playhead is before the animation start time so make sure the animation is at its initial state
|
||||
time >= tickableEndTime && tickablePrevTime !== duration // Playhead is after the animation end time so make sure the animation is at its end state
|
||||
) ||
|
||||
iterationTime >= tickableEndTime && tickablePrevTime !== duration ||
|
||||
// iterationTime is per-iteration, compared to the delay to catch a backward seek into a looped iteration's delay region. Exclude the final settled end, where iterationTime clamps to duration and would falsely match the delay region when the delay exceeds the duration.
|
||||
iterationTime <= tickableDelay && tickablePrevTime > 0 && !isCurrentTimeEqualOrAboveDuration ||
|
||||
time <= tickablePrevTime && tickablePrevTime === duration && completed || // Force a render if a seek occurs on an completed animation
|
||||
isCurrentTimeEqualOrAboveDuration && !completed && isSetter // This prevents 0 duration tickables to be skipped
|
||||
) {
|
||||
|
||||
if (isCurrentTimeAboveZero) {
|
||||
// Trigger onUpdate callback before rendering
|
||||
tickable.computeDeltaTime(tickablePrevTime);
|
||||
if (!muteCallbacks) tickable.onBeforeUpdate(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
// Start tweens rendering
|
||||
if (!_hasChildren) {
|
||||
|
||||
// Time has jumped more than globals.tickThreshold so consider this tick manual
|
||||
const forcedRender = forcedTick || (isRunningBackwards ? deltaTime * -1 : deltaTime) >= globals.globals.tickThreshold;
|
||||
// Round to match the precision of tween._absoluteStartTime so equal-time boundary checks compare cleanly without floating point drift from the unrounded _offset.
|
||||
const absoluteTime = helpers.round(tickable._offset + (parent ? parent._offset : 0) + tickableDelay + iterationTime, 12);
|
||||
|
||||
// Only Animation can have tweens, Timer returns undefined
|
||||
let tween = /** @type {Tween} */(/** @type {JSAnimation} */(tickable)._head);
|
||||
let tweenTarget;
|
||||
let tweenStyle;
|
||||
let tweenTargetTransforms;
|
||||
let tweenTargetTransformsProperties;
|
||||
let tweenTransformsNeedUpdate = 0;
|
||||
|
||||
while (tween) {
|
||||
|
||||
const tweenComposition = tween._composition;
|
||||
const tweenCurrentTime = tween._currentTime;
|
||||
const tweenChangeDuration = tween._changeDuration;
|
||||
const tweenAbsEndTime = tween._absoluteStartTime + tween._changeDuration;
|
||||
const tweenNextRep = tween._nextRep;
|
||||
const tweenPrevRep = tween._prevRep;
|
||||
const tweenHasComposition = tweenComposition !== consts.compositionTypes.none;
|
||||
// The previous sibling stops writing at its truncated end, so this tween takes over the hold from that point.
|
||||
const tweenPrevRepEndTime = tweenPrevRep ? tweenPrevRep._absoluteStartTime + tweenPrevRep._changeDuration : 0;
|
||||
const tweenPrevRepIsCrossParent = tweenPrevRep && tweenPrevRep.parent !== tween.parent;
|
||||
// Same parent keyframes take over at their own start, end plus delay equals the next start by construction.
|
||||
// Cross parent siblings take over at their update start.
|
||||
// Negative delay siblings take over at their own start instead.
|
||||
const tweenNextRepTakeover = !tweenNextRep || tweenNextRep._isOverridden ? tweenAbsEndTime :
|
||||
tweenNextRep.parent === tween.parent ? tweenAbsEndTime + tweenNextRep._delay :
|
||||
tweenNextRep._absoluteStartTime < tweenNextRep._absoluteUpdateStartTime ? tweenNextRep._absoluteStartTime : tweenNextRep._absoluteUpdateStartTime;
|
||||
|
||||
if ((forcedRender || (
|
||||
// Tail keyframes always re-evaluate the gate so an earlier keyframe cannot leave the target stale by writing past its own range after a backward seek.
|
||||
(tweenCurrentTime !== tweenChangeDuration || absoluteTime <= tweenNextRepTakeover ||
|
||||
(tweenPrevRep && !tweenPrevRepIsCrossParent && (!tweenNextRep || tweenNextRep.parent !== tween.parent))) &&
|
||||
// A cross parent tween re-renders its from value from the previous sibling truncated end so the handoff gap holds.
|
||||
// A keyframe re-renders its from revert while the next keyframe time is stale so a backward jump over its range cannot leave the next value in place.
|
||||
(tweenCurrentTime !== 0 || absoluteTime >= tween._absoluteStartTime ||
|
||||
(tweenPrevRepIsCrossParent && !tween._hasFromValue && !tweenPrevRep._isOverridden && absoluteTime >= tweenPrevRepEndTime) ||
|
||||
(tweenNextRep && !tweenNextRep._isOverridden && tweenNextRep.parent === tween.parent && tweenNextRep._currentTime !== 0 && iterationTime < tweenNextRep._startTime))
|
||||
)) &&
|
||||
// Non-first keyframes wait until the iteration reaches their own start before rendering, so the previous keyframe can handle the from-revert when scrubbed backward past this tween's range.
|
||||
(!tweenPrevRep || tweenPrevRepIsCrossParent || iterationTime >= tween._startTime) &&
|
||||
(!tweenHasComposition || (
|
||||
!tween._isOverridden &&
|
||||
(!tween._isOverlapped || absoluteTime <= tweenAbsEndTime) &&
|
||||
// The next sibling owns the value past its takeover point, so yielding there keeps writes single owner in both directions.
|
||||
(!tweenNextRep || tweenNextRep._isOverridden || absoluteTime <= tweenNextRepTakeover) &&
|
||||
// The previous sibling owns the value up to its truncated end.
|
||||
// Cross parent tweens take over the hold from that point, explicit from values wait for their own start.
|
||||
(!tweenPrevRep || (tweenPrevRep._isOverridden || (!tweenPrevRepIsCrossParent ?
|
||||
absoluteTime >= tweenPrevRepEndTime + tween._delay :
|
||||
absoluteTime >= tween._absoluteStartTime || (!tween._hasFromValue && absoluteTime >= tweenPrevRepEndTime))))
|
||||
))
|
||||
) {
|
||||
|
||||
const tweenNewTime = tween._currentTime = helpers.clamp(iterationTime - tween._startTime, 0, tweenChangeDuration);
|
||||
const tweenProgress = tween._ease(tweenNewTime / tween._updateDuration);
|
||||
const tweenModifier = tween._modifier;
|
||||
const tweenValueType = tween._valueType;
|
||||
const tweenType = tween._tweenType;
|
||||
const tweenIsObject = tweenType === consts.tweenTypes.OBJECT;
|
||||
const tweenIsNumber = tweenValueType === consts.valueTypes.NUMBER;
|
||||
// Only round the in-between frames values if the final value is a string. Object targets consume raw numbers, so rounding is dead work there.
|
||||
const tweenPrecision = (tweenIsNumber && tweenIsObject) || tweenProgress === 0 || tweenProgress === 1 ? -1 : globals.globals.precision;
|
||||
|
||||
// Recompose tween value
|
||||
/** @type {String|Number} */
|
||||
let value;
|
||||
/** @type {Number} */
|
||||
let number;
|
||||
|
||||
if (tweenIsNumber) {
|
||||
value = number = /** @type {Number} */(tweenModifier(helpers.round(helpers.lerp(tween._fromNumber, tween._toNumber, tweenProgress), tweenPrecision )));
|
||||
} else if (tweenValueType === consts.valueTypes.UNIT) {
|
||||
// Rounding the values speed up string composition
|
||||
number = /** @type {Number} */(tweenModifier(helpers.round(helpers.lerp(tween._fromNumber, tween._toNumber, tweenProgress), tweenPrecision)));
|
||||
value = `${number}${tween._unit}`;
|
||||
} else if (tweenValueType === consts.valueTypes.COLOR) {
|
||||
const ns = tween._numbers;
|
||||
const fn = tween._fromNumbers;
|
||||
const tn = tween._toNumbers;
|
||||
const omt = 1 - tweenProgress;
|
||||
const fr = fn[0], fg = fn[1], fb = fn[2];
|
||||
const tr = tn[0], tg = tn[1], tb = tn[2];
|
||||
// RGB channels lerp in pseudo-linear space (square inputs, sqrt result) to approximate gamma-correct blending.
|
||||
// See https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear.
|
||||
ns[0] = /** @type {Number} */(tweenModifier(Math.sqrt(fr * fr * omt + tr * tr * tweenProgress)));
|
||||
ns[1] = /** @type {Number} */(tweenModifier(Math.sqrt(fg * fg * omt + tg * tg * tweenProgress)));
|
||||
ns[2] = /** @type {Number} */(tweenModifier(Math.sqrt(fb * fb * omt + tb * tb * tweenProgress)));
|
||||
ns[3] = /** @type {Number} */(tweenModifier(helpers.lerp(fn[3], tn[3], tweenProgress)));
|
||||
// The rgba string is built only for the dispatch path or the internalRender composition tick (setters handles the color comp)
|
||||
if (!tween._setter || internalRender) {
|
||||
value = `rgba(${helpers.round(ns[0], 0)},${helpers.round(ns[1], 0)},${helpers.round(ns[2], 0)},${ns[3]})`;
|
||||
}
|
||||
} else if (tweenValueType === consts.valueTypes.COMPLEX) {
|
||||
value = values.composeComplexValue(tween, tweenProgress, tweenPrecision);
|
||||
}
|
||||
|
||||
// For additive tweens and Animatables
|
||||
if (tweenHasComposition) {
|
||||
tween._number = number;
|
||||
}
|
||||
|
||||
if (!internalRender && tweenComposition !== consts.compositionTypes.blend) {
|
||||
|
||||
const tweenProperty = tween.property;
|
||||
tweenTarget = tween.target;
|
||||
|
||||
if (tween._setter) {
|
||||
tween._setter(tweenTarget, number, tween);
|
||||
} else if (tweenIsObject) {
|
||||
tweenTarget[tweenProperty] = value;
|
||||
} else if (tweenType === consts.tweenTypes.ATTRIBUTE) {
|
||||
/** @type {DOMTarget} */(tweenTarget).setAttribute(tweenProperty, /** @type {String} */(value));
|
||||
} else {
|
||||
tweenStyle = /** @type {DOMTarget} */(tweenTarget).style;
|
||||
if (tweenType === consts.tweenTypes.TRANSFORM) {
|
||||
if (tweenTarget !== tweenTargetTransforms) {
|
||||
tweenTargetTransforms = tweenTarget;
|
||||
// NOTE: Referencing the cachedTransforms in the tween property directly can be a little bit faster but appears to increase memory usage.
|
||||
tweenTargetTransformsProperties = tweenTarget[consts.transformsSymbol];
|
||||
}
|
||||
tweenTargetTransformsProperties[tweenProperty] = value;
|
||||
tweenTransformsNeedUpdate = 1;
|
||||
} else if (tweenType === consts.tweenTypes.CSS) {
|
||||
tweenStyle[tweenProperty] = value;
|
||||
} else if (tweenType === consts.tweenTypes.CSS_VAR) {
|
||||
tweenStyle.setProperty(tweenProperty,/** @type {String} */(value));
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurrentTimeAboveZero) hasRendered = 1;
|
||||
|
||||
} else {
|
||||
// Used for composing timeline tweens without having to do a real render
|
||||
tween._value = value;
|
||||
}
|
||||
|
||||
} else if (tweenCurrentTime && tweenPrevRep && !tweenPrevRepIsCrossParent && iterationTime < tween._startTime) {
|
||||
// Mark the keyframe as reverted when the playhead moves before its start, the previous keyframe owns the from revert and writes it once.
|
||||
tween._currentTime = 0;
|
||||
}
|
||||
|
||||
if (tweenTransformsNeedUpdate && tween._renderTransforms) {
|
||||
tweenStyle.transform = transforms.buildTransformString(tweenTargetTransformsProperties);
|
||||
tweenTransformsNeedUpdate = 0;
|
||||
}
|
||||
|
||||
tween = tween._next;
|
||||
}
|
||||
|
||||
if (!muteCallbacks && hasRendered) {
|
||||
/** @type {JSAnimation} */(tickable).onRender(/** @type {JSAnimation} */(tickable));
|
||||
}
|
||||
}
|
||||
|
||||
if (!muteCallbacks && isCurrentTimeAboveZero) {
|
||||
tickable.onUpdate(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// End tweens rendering
|
||||
|
||||
// Handle setters on timeline differently and allow re-trigering the onComplete callback when seeking backwards
|
||||
if (parent && isSetter) {
|
||||
if (!muteCallbacks && (
|
||||
// (tickableAbsoluteTime > 0 instead) of (tickableAbsoluteTime >= duration) to prevent floating point precision issues
|
||||
// see: https://github.com/juliangarnier/anime/issues/1088
|
||||
(parent.began && !isRunningBackwards && tickableAbsoluteTime > 0 && !completed) ||
|
||||
(isRunningBackwards && tickableAbsoluteTime <= consts.minValue && completed)
|
||||
)) {
|
||||
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
|
||||
tickable.completed = !isRunningBackwards;
|
||||
}
|
||||
// If currentTime is both above 0 and at least equals to duration, handles normal onComplete or infinite loops
|
||||
} else if (isCurrentTimeAboveZero && isCurrentTimeEqualOrAboveDuration) {
|
||||
if (iterationCount === Infinity) {
|
||||
// Offset the tickable _startTime with its duration to reset _currentTime to 0 and continue the infinite timer
|
||||
tickable._startTime += tickable.duration;
|
||||
} else if (tickable._currentIteration >= iterationCount - 1) {
|
||||
// By setting paused to true, we tell the engine loop to not render this tickable and removes it from the list on the next tick
|
||||
tickable.paused = true;
|
||||
if (!completed && !_hasChildren) {
|
||||
// If the tickable has children, triggers onComplete() only when all children have completed in the tick function
|
||||
tickable.completed = true;
|
||||
if (!muteCallbacks && !(parent && (isRunningBackwards || !parent.began))) {
|
||||
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
|
||||
tickable._resolve(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise set the completed flag to false
|
||||
} else {
|
||||
tickable.completed = false;
|
||||
}
|
||||
|
||||
// NOTE: hasRendered * direction (negative for backwards) this way we can remove the tickable.backwards property completly ?
|
||||
return hasRendered;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tickable} tickable
|
||||
* @param {Number} time
|
||||
* @param {Number} muteCallbacks
|
||||
* @param {Number} internalRender
|
||||
* @param {Number} tickMode
|
||||
* @return {void}
|
||||
*/
|
||||
const tick = (tickable, time, muteCallbacks, internalRender, tickMode) => {
|
||||
const _currentIteration = tickable._currentIteration;
|
||||
render(tickable, time, muteCallbacks, internalRender, tickMode);
|
||||
if (tickable._hasChildren) {
|
||||
const tl = /** @type {Timeline} */(tickable);
|
||||
const tlIsRunningBackwards = tl.backwards;
|
||||
const tlChildrenTime = internalRender ? time : tl._iterationTime;
|
||||
const tlCildrenTickTime = helpers.now();
|
||||
|
||||
let tlChildrenHasRendered = 0;
|
||||
let tlChildrenHaveCompleted = true;
|
||||
|
||||
// If the timeline has looped forward, we need to manually triggers children skipped callbacks
|
||||
if (!internalRender && tl._currentIteration !== _currentIteration) {
|
||||
const tlIterationDuration = tl.iterationDuration;
|
||||
helpers.forEachChildren(tl, (/** @type {JSAnimation} */child) => {
|
||||
if (!tlIsRunningBackwards) {
|
||||
// Force an internal render to trigger the callbacks if the child has not completed on loop
|
||||
if (!child.completed && !child.backwards && child._currentTime < child.iterationDuration) {
|
||||
render(child, tlIterationDuration, muteCallbacks, 1, consts.tickModes.FORCE);
|
||||
}
|
||||
// Reset their began and completed flags to allow retrigering callbacks on the next iteration
|
||||
child.began = false;
|
||||
child.completed = false;
|
||||
} else {
|
||||
const childDuration = child.duration;
|
||||
const childStartTime = child._offset + child._delay;
|
||||
const childEndTime = childStartTime + childDuration;
|
||||
// Triggers the onComplete callback on reverse for children on the edges of the timeline
|
||||
if (!muteCallbacks && childDuration <= consts.minValue && (!childStartTime || childEndTime === tlIterationDuration)) {
|
||||
child.onComplete(child);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!muteCallbacks) tl.onLoop(/** @type {CallbackArgument} */(tl));
|
||||
}
|
||||
|
||||
helpers.forEachChildren(tl, (/** @type {JSAnimation} */child) => {
|
||||
const childTime = helpers.round((tlChildrenTime - child._offset) * child._speed, 12); // Rounding is needed when using seconds
|
||||
// Skip past-end siblings on backward iteration so their progress=1 to-values don't render last and overwrite the active sibling's write. Compare against _delay + duration so children with a normalized delay are not skipped while still inside their active range.
|
||||
if (tlIsRunningBackwards && childTime > child._delay + child.duration) return;
|
||||
const childTickMode = child._fps < tl._fps ? child.requestTick(tlCildrenTickTime) : tickMode;
|
||||
tlChildrenHasRendered += render(child, childTime, muteCallbacks, internalRender, childTickMode);
|
||||
if (!child.completed && tlChildrenHaveCompleted) tlChildrenHaveCompleted = false;
|
||||
}, tlIsRunningBackwards);
|
||||
|
||||
// Renders on timeline are triggered by its children so it needs to be set after rendering the children
|
||||
if (!muteCallbacks && tlChildrenHasRendered) tl.onRender(/** @type {CallbackArgument} */(tl));
|
||||
// Triggers the timeline onComplete() once all chindren all completed and the current time has reached the end
|
||||
if ((tlChildrenHaveCompleted || tlIsRunningBackwards) && tl._currentTime >= tl.duration) {
|
||||
// Make sure the paused flag is false in case it has been skipped in the render function
|
||||
tl.paused = true;
|
||||
if (!tl.completed) {
|
||||
tl.completed = true;
|
||||
if (!muteCallbacks) {
|
||||
tl.onComplete(/** @type {CallbackArgument} */(tl));
|
||||
tl._resolve(/** @type {CallbackArgument} */(tl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.render = render;
|
||||
exports.tick = tick;
|
||||
@@ -0,0 +1,4 @@
|
||||
export function render(tickable: Tickable, time: number, muteCallbacks: number, internalRender: number, tickMode: tickModes): number;
|
||||
export function tick(tickable: Tickable, time: number, muteCallbacks: number, internalRender: number, tickMode: number): void;
|
||||
import type { Tickable } from '../types/index.js';
|
||||
import { tickModes } from './consts.js';
|
||||
@@ -0,0 +1,411 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { globals } from './globals.js';
|
||||
import { minValue, tickModes, valueTypes, compositionTypes, tweenTypes, transformsSymbol } from './consts.js';
|
||||
import { forEachChildren, round, now, clamp, lerp } from './helpers.js';
|
||||
import { buildTransformString } from './transforms.js';
|
||||
import { composeComplexValue } from './values.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Tickable,
|
||||
* Renderable,
|
||||
* CallbackArgument,
|
||||
* Tween,
|
||||
* DOMTarget,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Timeline,
|
||||
* } from '../timeline/timeline.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Tickable} tickable
|
||||
* @param {Number} time
|
||||
* @param {Number} muteCallbacks
|
||||
* @param {Number} internalRender
|
||||
* @param {tickModes} tickMode
|
||||
* @return {Number}
|
||||
*/
|
||||
const render = (tickable, time, muteCallbacks, internalRender, tickMode) => {
|
||||
|
||||
const parent = tickable.parent;
|
||||
const duration = tickable.duration;
|
||||
const completed = tickable.completed;
|
||||
const iterationDuration = tickable.iterationDuration;
|
||||
const iterationCount = tickable.iterationCount;
|
||||
const _currentIteration = tickable._currentIteration;
|
||||
const _loopDelay = tickable._loopDelay;
|
||||
const _reversed = tickable._reversed;
|
||||
const _alternate = tickable._alternate;
|
||||
const _hasChildren = tickable._hasChildren;
|
||||
const tickableDelay = tickable._delay;
|
||||
const tickablePrevAbsoluteTime = tickable._currentTime; // TODO: rename ._currentTime to ._absoluteCurrentTime
|
||||
const tickableEndTime = tickableDelay + iterationDuration;
|
||||
const tickableAbsoluteTime = time - tickableDelay;
|
||||
const tickablePrevTime = clamp(tickablePrevAbsoluteTime, -tickableDelay, duration);
|
||||
const tickableCurrentTime = clamp(tickableAbsoluteTime, -tickableDelay, duration);
|
||||
const deltaTime = tickableAbsoluteTime - tickablePrevAbsoluteTime;
|
||||
const isCurrentTimeAboveZero = tickableCurrentTime > 0;
|
||||
const isCurrentTimeEqualOrAboveDuration = tickableCurrentTime >= duration;
|
||||
const isSetter = duration <= minValue;
|
||||
const forcedTick = tickMode === tickModes.FORCE;
|
||||
|
||||
let isOdd = 0;
|
||||
let iterationElapsedTime = tickableAbsoluteTime;
|
||||
// Render checks
|
||||
// Used to also check if the children have rendered in order to trigger the onRender callback on the parent timer
|
||||
let hasRendered = 0;
|
||||
|
||||
// Execute the "expensive" iterations calculations only when necessary
|
||||
if (iterationCount > 1) {
|
||||
// bitwise NOT operator seems to be generally faster than Math.floor() across browsers
|
||||
const period = iterationDuration + (isCurrentTimeEqualOrAboveDuration ? 0 : _loopDelay);
|
||||
const currentIteration = ~~(tickableCurrentTime / period);
|
||||
tickable._currentIteration = clamp(currentIteration, 0, iterationCount);
|
||||
// Prevent the iteration count to go above the max iterations when reaching the end of the animation
|
||||
if (isCurrentTimeEqualOrAboveDuration) tickable._currentIteration--;
|
||||
isOdd = tickable._currentIteration % 2;
|
||||
// Derive elapsed from the same `~~` truncation that gave currentIteration. Using `% period` here can disagree with `~~(/period)` under float drift at iteration boundaries and write the wrong end of the tween for one frame.
|
||||
iterationElapsedTime = tickableCurrentTime - currentIteration * period || 0;
|
||||
}
|
||||
|
||||
// Checks if exactly one of _reversed and (_alternate && isOdd) is true
|
||||
const isReversed = _reversed ^ (_alternate && isOdd);
|
||||
const _ease = /** @type {Renderable} */(tickable)._ease;
|
||||
let iterationTime = isCurrentTimeEqualOrAboveDuration ? isReversed ? 0 : duration : isReversed ? iterationDuration - iterationElapsedTime : iterationElapsedTime;
|
||||
if (_ease) iterationTime = iterationDuration * _ease(iterationTime / iterationDuration) || 0;
|
||||
const isRunningBackwards = (parent ? parent.backwards : tickableAbsoluteTime < tickablePrevAbsoluteTime) ? !isReversed : !!isReversed;
|
||||
|
||||
tickable._currentTime = tickableAbsoluteTime;
|
||||
tickable._iterationTime = iterationTime;
|
||||
tickable.backwards = isRunningBackwards;
|
||||
|
||||
if (isCurrentTimeAboveZero && !tickable.began) {
|
||||
tickable.began = true;
|
||||
if (!muteCallbacks && !(parent && (isRunningBackwards || !parent.began))) {
|
||||
tickable.onBegin(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
} else if (tickableAbsoluteTime <= 0) {
|
||||
tickable.began = false;
|
||||
}
|
||||
|
||||
// Only triggers onLoop for tickable without children, otherwise call the the onLoop callback in the tick function
|
||||
// Make sure to trigger the onLoop before rendering to allow .refresh() to pickup the current values
|
||||
if (!muteCallbacks && !_hasChildren && isCurrentTimeAboveZero && tickable._currentIteration !== _currentIteration) {
|
||||
tickable.onLoop(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
if (
|
||||
forcedTick ||
|
||||
tickMode === tickModes.AUTO && (
|
||||
// Timeline children render from their offset instead of their delay so the gap left by a truncated sibling is covered on seek.
|
||||
time >= (parent && tickableDelay > 0 ? 0 : tickableDelay) && time <= tickableEndTime || // Normal render
|
||||
time <= tickableDelay && tickablePrevTime > tickableDelay || // Playhead is before the animation start time so make sure the animation is at its initial state
|
||||
time >= tickableEndTime && tickablePrevTime !== duration // Playhead is after the animation end time so make sure the animation is at its end state
|
||||
) ||
|
||||
iterationTime >= tickableEndTime && tickablePrevTime !== duration ||
|
||||
// iterationTime is per-iteration, compared to the delay to catch a backward seek into a looped iteration's delay region. Exclude the final settled end, where iterationTime clamps to duration and would falsely match the delay region when the delay exceeds the duration.
|
||||
iterationTime <= tickableDelay && tickablePrevTime > 0 && !isCurrentTimeEqualOrAboveDuration ||
|
||||
time <= tickablePrevTime && tickablePrevTime === duration && completed || // Force a render if a seek occurs on an completed animation
|
||||
isCurrentTimeEqualOrAboveDuration && !completed && isSetter // This prevents 0 duration tickables to be skipped
|
||||
) {
|
||||
|
||||
if (isCurrentTimeAboveZero) {
|
||||
// Trigger onUpdate callback before rendering
|
||||
tickable.computeDeltaTime(tickablePrevTime);
|
||||
if (!muteCallbacks) tickable.onBeforeUpdate(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
// Start tweens rendering
|
||||
if (!_hasChildren) {
|
||||
|
||||
// Time has jumped more than globals.tickThreshold so consider this tick manual
|
||||
const forcedRender = forcedTick || (isRunningBackwards ? deltaTime * -1 : deltaTime) >= globals.tickThreshold;
|
||||
// Round to match the precision of tween._absoluteStartTime so equal-time boundary checks compare cleanly without floating point drift from the unrounded _offset.
|
||||
const absoluteTime = round(tickable._offset + (parent ? parent._offset : 0) + tickableDelay + iterationTime, 12);
|
||||
|
||||
// Only Animation can have tweens, Timer returns undefined
|
||||
let tween = /** @type {Tween} */(/** @type {JSAnimation} */(tickable)._head);
|
||||
let tweenTarget;
|
||||
let tweenStyle;
|
||||
let tweenTargetTransforms;
|
||||
let tweenTargetTransformsProperties;
|
||||
let tweenTransformsNeedUpdate = 0;
|
||||
|
||||
while (tween) {
|
||||
|
||||
const tweenComposition = tween._composition;
|
||||
const tweenCurrentTime = tween._currentTime;
|
||||
const tweenChangeDuration = tween._changeDuration;
|
||||
const tweenAbsEndTime = tween._absoluteStartTime + tween._changeDuration;
|
||||
const tweenNextRep = tween._nextRep;
|
||||
const tweenPrevRep = tween._prevRep;
|
||||
const tweenHasComposition = tweenComposition !== compositionTypes.none;
|
||||
// The previous sibling stops writing at its truncated end, so this tween takes over the hold from that point.
|
||||
const tweenPrevRepEndTime = tweenPrevRep ? tweenPrevRep._absoluteStartTime + tweenPrevRep._changeDuration : 0;
|
||||
const tweenPrevRepIsCrossParent = tweenPrevRep && tweenPrevRep.parent !== tween.parent;
|
||||
// Same parent keyframes take over at their own start, end plus delay equals the next start by construction.
|
||||
// Cross parent siblings take over at their update start.
|
||||
// Negative delay siblings take over at their own start instead.
|
||||
const tweenNextRepTakeover = !tweenNextRep || tweenNextRep._isOverridden ? tweenAbsEndTime :
|
||||
tweenNextRep.parent === tween.parent ? tweenAbsEndTime + tweenNextRep._delay :
|
||||
tweenNextRep._absoluteStartTime < tweenNextRep._absoluteUpdateStartTime ? tweenNextRep._absoluteStartTime : tweenNextRep._absoluteUpdateStartTime;
|
||||
|
||||
if ((forcedRender || (
|
||||
// Tail keyframes always re-evaluate the gate so an earlier keyframe cannot leave the target stale by writing past its own range after a backward seek.
|
||||
(tweenCurrentTime !== tweenChangeDuration || absoluteTime <= tweenNextRepTakeover ||
|
||||
(tweenPrevRep && !tweenPrevRepIsCrossParent && (!tweenNextRep || tweenNextRep.parent !== tween.parent))) &&
|
||||
// A cross parent tween re-renders its from value from the previous sibling truncated end so the handoff gap holds.
|
||||
// A keyframe re-renders its from revert while the next keyframe time is stale so a backward jump over its range cannot leave the next value in place.
|
||||
(tweenCurrentTime !== 0 || absoluteTime >= tween._absoluteStartTime ||
|
||||
(tweenPrevRepIsCrossParent && !tween._hasFromValue && !tweenPrevRep._isOverridden && absoluteTime >= tweenPrevRepEndTime) ||
|
||||
(tweenNextRep && !tweenNextRep._isOverridden && tweenNextRep.parent === tween.parent && tweenNextRep._currentTime !== 0 && iterationTime < tweenNextRep._startTime))
|
||||
)) &&
|
||||
// Non-first keyframes wait until the iteration reaches their own start before rendering, so the previous keyframe can handle the from-revert when scrubbed backward past this tween's range.
|
||||
(!tweenPrevRep || tweenPrevRepIsCrossParent || iterationTime >= tween._startTime) &&
|
||||
(!tweenHasComposition || (
|
||||
!tween._isOverridden &&
|
||||
(!tween._isOverlapped || absoluteTime <= tweenAbsEndTime) &&
|
||||
// The next sibling owns the value past its takeover point, so yielding there keeps writes single owner in both directions.
|
||||
(!tweenNextRep || tweenNextRep._isOverridden || absoluteTime <= tweenNextRepTakeover) &&
|
||||
// The previous sibling owns the value up to its truncated end.
|
||||
// Cross parent tweens take over the hold from that point, explicit from values wait for their own start.
|
||||
(!tweenPrevRep || (tweenPrevRep._isOverridden || (!tweenPrevRepIsCrossParent ?
|
||||
absoluteTime >= tweenPrevRepEndTime + tween._delay :
|
||||
absoluteTime >= tween._absoluteStartTime || (!tween._hasFromValue && absoluteTime >= tweenPrevRepEndTime))))
|
||||
))
|
||||
) {
|
||||
|
||||
const tweenNewTime = tween._currentTime = clamp(iterationTime - tween._startTime, 0, tweenChangeDuration);
|
||||
const tweenProgress = tween._ease(tweenNewTime / tween._updateDuration);
|
||||
const tweenModifier = tween._modifier;
|
||||
const tweenValueType = tween._valueType;
|
||||
const tweenType = tween._tweenType;
|
||||
const tweenIsObject = tweenType === tweenTypes.OBJECT;
|
||||
const tweenIsNumber = tweenValueType === valueTypes.NUMBER;
|
||||
// Only round the in-between frames values if the final value is a string. Object targets consume raw numbers, so rounding is dead work there.
|
||||
const tweenPrecision = (tweenIsNumber && tweenIsObject) || tweenProgress === 0 || tweenProgress === 1 ? -1 : globals.precision;
|
||||
|
||||
// Recompose tween value
|
||||
/** @type {String|Number} */
|
||||
let value;
|
||||
/** @type {Number} */
|
||||
let number;
|
||||
|
||||
if (tweenIsNumber) {
|
||||
value = number = /** @type {Number} */(tweenModifier(round(lerp(tween._fromNumber, tween._toNumber, tweenProgress), tweenPrecision )));
|
||||
} else if (tweenValueType === valueTypes.UNIT) {
|
||||
// Rounding the values speed up string composition
|
||||
number = /** @type {Number} */(tweenModifier(round(lerp(tween._fromNumber, tween._toNumber, tweenProgress), tweenPrecision)));
|
||||
value = `${number}${tween._unit}`;
|
||||
} else if (tweenValueType === valueTypes.COLOR) {
|
||||
const ns = tween._numbers;
|
||||
const fn = tween._fromNumbers;
|
||||
const tn = tween._toNumbers;
|
||||
const omt = 1 - tweenProgress;
|
||||
const fr = fn[0], fg = fn[1], fb = fn[2];
|
||||
const tr = tn[0], tg = tn[1], tb = tn[2];
|
||||
// RGB channels lerp in pseudo-linear space (square inputs, sqrt result) to approximate gamma-correct blending.
|
||||
// See https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear.
|
||||
ns[0] = /** @type {Number} */(tweenModifier(Math.sqrt(fr * fr * omt + tr * tr * tweenProgress)));
|
||||
ns[1] = /** @type {Number} */(tweenModifier(Math.sqrt(fg * fg * omt + tg * tg * tweenProgress)));
|
||||
ns[2] = /** @type {Number} */(tweenModifier(Math.sqrt(fb * fb * omt + tb * tb * tweenProgress)));
|
||||
ns[3] = /** @type {Number} */(tweenModifier(lerp(fn[3], tn[3], tweenProgress)));
|
||||
// The rgba string is built only for the dispatch path or the internalRender composition tick (setters handles the color comp)
|
||||
if (!tween._setter || internalRender) {
|
||||
value = `rgba(${round(ns[0], 0)},${round(ns[1], 0)},${round(ns[2], 0)},${ns[3]})`;
|
||||
}
|
||||
} else if (tweenValueType === valueTypes.COMPLEX) {
|
||||
value = composeComplexValue(tween, tweenProgress, tweenPrecision);
|
||||
}
|
||||
|
||||
// For additive tweens and Animatables
|
||||
if (tweenHasComposition) {
|
||||
tween._number = number;
|
||||
}
|
||||
|
||||
if (!internalRender && tweenComposition !== compositionTypes.blend) {
|
||||
|
||||
const tweenProperty = tween.property;
|
||||
tweenTarget = tween.target;
|
||||
|
||||
if (tween._setter) {
|
||||
tween._setter(tweenTarget, number, tween);
|
||||
} else if (tweenIsObject) {
|
||||
tweenTarget[tweenProperty] = value;
|
||||
} else if (tweenType === tweenTypes.ATTRIBUTE) {
|
||||
/** @type {DOMTarget} */(tweenTarget).setAttribute(tweenProperty, /** @type {String} */(value));
|
||||
} else {
|
||||
tweenStyle = /** @type {DOMTarget} */(tweenTarget).style;
|
||||
if (tweenType === tweenTypes.TRANSFORM) {
|
||||
if (tweenTarget !== tweenTargetTransforms) {
|
||||
tweenTargetTransforms = tweenTarget;
|
||||
// NOTE: Referencing the cachedTransforms in the tween property directly can be a little bit faster but appears to increase memory usage.
|
||||
tweenTargetTransformsProperties = tweenTarget[transformsSymbol];
|
||||
}
|
||||
tweenTargetTransformsProperties[tweenProperty] = value;
|
||||
tweenTransformsNeedUpdate = 1;
|
||||
} else if (tweenType === tweenTypes.CSS) {
|
||||
tweenStyle[tweenProperty] = value;
|
||||
} else if (tweenType === tweenTypes.CSS_VAR) {
|
||||
tweenStyle.setProperty(tweenProperty,/** @type {String} */(value));
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurrentTimeAboveZero) hasRendered = 1;
|
||||
|
||||
} else {
|
||||
// Used for composing timeline tweens without having to do a real render
|
||||
tween._value = value;
|
||||
}
|
||||
|
||||
} else if (tweenCurrentTime && tweenPrevRep && !tweenPrevRepIsCrossParent && iterationTime < tween._startTime) {
|
||||
// Mark the keyframe as reverted when the playhead moves before its start, the previous keyframe owns the from revert and writes it once.
|
||||
tween._currentTime = 0;
|
||||
}
|
||||
|
||||
if (tweenTransformsNeedUpdate && tween._renderTransforms) {
|
||||
tweenStyle.transform = buildTransformString(tweenTargetTransformsProperties);
|
||||
tweenTransformsNeedUpdate = 0;
|
||||
}
|
||||
|
||||
tween = tween._next;
|
||||
}
|
||||
|
||||
if (!muteCallbacks && hasRendered) {
|
||||
/** @type {JSAnimation} */(tickable).onRender(/** @type {JSAnimation} */(tickable));
|
||||
}
|
||||
}
|
||||
|
||||
if (!muteCallbacks && isCurrentTimeAboveZero) {
|
||||
tickable.onUpdate(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// End tweens rendering
|
||||
|
||||
// Handle setters on timeline differently and allow re-trigering the onComplete callback when seeking backwards
|
||||
if (parent && isSetter) {
|
||||
if (!muteCallbacks && (
|
||||
// (tickableAbsoluteTime > 0 instead) of (tickableAbsoluteTime >= duration) to prevent floating point precision issues
|
||||
// see: https://github.com/juliangarnier/anime/issues/1088
|
||||
(parent.began && !isRunningBackwards && tickableAbsoluteTime > 0 && !completed) ||
|
||||
(isRunningBackwards && tickableAbsoluteTime <= minValue && completed)
|
||||
)) {
|
||||
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
|
||||
tickable.completed = !isRunningBackwards;
|
||||
}
|
||||
// If currentTime is both above 0 and at least equals to duration, handles normal onComplete or infinite loops
|
||||
} else if (isCurrentTimeAboveZero && isCurrentTimeEqualOrAboveDuration) {
|
||||
if (iterationCount === Infinity) {
|
||||
// Offset the tickable _startTime with its duration to reset _currentTime to 0 and continue the infinite timer
|
||||
tickable._startTime += tickable.duration;
|
||||
} else if (tickable._currentIteration >= iterationCount - 1) {
|
||||
// By setting paused to true, we tell the engine loop to not render this tickable and removes it from the list on the next tick
|
||||
tickable.paused = true;
|
||||
if (!completed && !_hasChildren) {
|
||||
// If the tickable has children, triggers onComplete() only when all children have completed in the tick function
|
||||
tickable.completed = true;
|
||||
if (!muteCallbacks && !(parent && (isRunningBackwards || !parent.began))) {
|
||||
tickable.onComplete(/** @type {CallbackArgument} */(tickable));
|
||||
tickable._resolve(/** @type {CallbackArgument} */(tickable));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise set the completed flag to false
|
||||
} else {
|
||||
tickable.completed = false;
|
||||
}
|
||||
|
||||
// NOTE: hasRendered * direction (negative for backwards) this way we can remove the tickable.backwards property completly ?
|
||||
return hasRendered;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Tickable} tickable
|
||||
* @param {Number} time
|
||||
* @param {Number} muteCallbacks
|
||||
* @param {Number} internalRender
|
||||
* @param {Number} tickMode
|
||||
* @return {void}
|
||||
*/
|
||||
const tick = (tickable, time, muteCallbacks, internalRender, tickMode) => {
|
||||
const _currentIteration = tickable._currentIteration;
|
||||
render(tickable, time, muteCallbacks, internalRender, tickMode);
|
||||
if (tickable._hasChildren) {
|
||||
const tl = /** @type {Timeline} */(tickable);
|
||||
const tlIsRunningBackwards = tl.backwards;
|
||||
const tlChildrenTime = internalRender ? time : tl._iterationTime;
|
||||
const tlCildrenTickTime = now();
|
||||
|
||||
let tlChildrenHasRendered = 0;
|
||||
let tlChildrenHaveCompleted = true;
|
||||
|
||||
// If the timeline has looped forward, we need to manually triggers children skipped callbacks
|
||||
if (!internalRender && tl._currentIteration !== _currentIteration) {
|
||||
const tlIterationDuration = tl.iterationDuration;
|
||||
forEachChildren(tl, (/** @type {JSAnimation} */child) => {
|
||||
if (!tlIsRunningBackwards) {
|
||||
// Force an internal render to trigger the callbacks if the child has not completed on loop
|
||||
if (!child.completed && !child.backwards && child._currentTime < child.iterationDuration) {
|
||||
render(child, tlIterationDuration, muteCallbacks, 1, tickModes.FORCE);
|
||||
}
|
||||
// Reset their began and completed flags to allow retrigering callbacks on the next iteration
|
||||
child.began = false;
|
||||
child.completed = false;
|
||||
} else {
|
||||
const childDuration = child.duration;
|
||||
const childStartTime = child._offset + child._delay;
|
||||
const childEndTime = childStartTime + childDuration;
|
||||
// Triggers the onComplete callback on reverse for children on the edges of the timeline
|
||||
if (!muteCallbacks && childDuration <= minValue && (!childStartTime || childEndTime === tlIterationDuration)) {
|
||||
child.onComplete(child);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!muteCallbacks) tl.onLoop(/** @type {CallbackArgument} */(tl));
|
||||
}
|
||||
|
||||
forEachChildren(tl, (/** @type {JSAnimation} */child) => {
|
||||
const childTime = round((tlChildrenTime - child._offset) * child._speed, 12); // Rounding is needed when using seconds
|
||||
// Skip past-end siblings on backward iteration so their progress=1 to-values don't render last and overwrite the active sibling's write. Compare against _delay + duration so children with a normalized delay are not skipped while still inside their active range.
|
||||
if (tlIsRunningBackwards && childTime > child._delay + child.duration) return;
|
||||
const childTickMode = child._fps < tl._fps ? child.requestTick(tlCildrenTickTime) : tickMode;
|
||||
tlChildrenHasRendered += render(child, childTime, muteCallbacks, internalRender, childTickMode);
|
||||
if (!child.completed && tlChildrenHaveCompleted) tlChildrenHaveCompleted = false;
|
||||
}, tlIsRunningBackwards);
|
||||
|
||||
// Renders on timeline are triggered by its children so it needs to be set after rendering the children
|
||||
if (!muteCallbacks && tlChildrenHasRendered) tl.onRender(/** @type {CallbackArgument} */(tl));
|
||||
// Triggers the timeline onComplete() once all chindren all completed and the current time has reached the end
|
||||
if ((tlChildrenHaveCompleted || tlIsRunningBackwards) && tl._currentTime >= tl.duration) {
|
||||
// Make sure the paused flag is false in case it has been skipped in the render function
|
||||
tl.paused = true;
|
||||
if (!tl.completed) {
|
||||
tl.completed = true;
|
||||
if (!muteCallbacks) {
|
||||
tl.onComplete(/** @type {CallbackArgument} */(tl));
|
||||
tl._resolve(/** @type {CallbackArgument} */(tl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { render, tick };
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var consts = require('./consts.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
var transforms = require('./transforms.cjs');
|
||||
var values = require('./values.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Target,
|
||||
* DOMTarget,
|
||||
* Renderable,
|
||||
* Tween,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
const propertyNamesCache = {};
|
||||
|
||||
/**
|
||||
* @param {String} propertyName
|
||||
* @param {Target} target
|
||||
* @param {tweenTypes} tweenType
|
||||
* @return {String}
|
||||
*/
|
||||
const sanitizePropertyName = (propertyName, target, tweenType) => {
|
||||
if (tweenType === consts.tweenTypes.TRANSFORM) {
|
||||
const t = consts.shortTransforms.get(propertyName);
|
||||
return t ? t : propertyName;
|
||||
} else if (
|
||||
tweenType === consts.tweenTypes.CSS ||
|
||||
// Handle special cases where properties like "strokeDashoffset" needs to be set as "stroke-dashoffset"
|
||||
// but properties like "baseFrequency" should stay in lowerCamelCase
|
||||
(tweenType === consts.tweenTypes.ATTRIBUTE && (helpers.isSvg(target) && propertyName in /** @type {DOMTarget} */(target).style))
|
||||
) {
|
||||
const cachedPropertyName = propertyNamesCache[propertyName];
|
||||
if (cachedPropertyName) {
|
||||
return cachedPropertyName;
|
||||
} else {
|
||||
const lowerCaseName = propertyName ? helpers.toLowerCase(propertyName) : propertyName;
|
||||
propertyNamesCache[propertyName] = lowerCaseName;
|
||||
return lowerCaseName;
|
||||
}
|
||||
} else {
|
||||
return propertyName;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @template {Renderable} T
|
||||
* @param {T} renderable
|
||||
* @param {Boolean} [inlineStylesOnly]
|
||||
* @return {T}
|
||||
*/
|
||||
const revertValues = (renderable, inlineStylesOnly = false) => {
|
||||
// Allow revertValues() to be called on timelines
|
||||
if (renderable._hasChildren) {
|
||||
helpers.forEachChildren(renderable, (/** @type {Renderable} */child) => revertValues(child, inlineStylesOnly), true);
|
||||
} else {
|
||||
const animation = /** @type {JSAnimation} */(renderable);
|
||||
animation.pause();
|
||||
helpers.forEachChildren(animation, (/** @type {Tween} */tween) => {
|
||||
const tweenProperty = tween.property;
|
||||
const tweenTarget = tween.target;
|
||||
const tweenType = tween._tweenType;
|
||||
const originalInlinedValue = tween._inlineValue;
|
||||
const tweenHadNoInlineValue = helpers.isNil(originalInlinedValue) || originalInlinedValue === consts.emptyString;
|
||||
if (tween._setter) {
|
||||
if (!inlineStylesOnly && !tweenHadNoInlineValue) {
|
||||
// Re-seed the original value to the _number / _numbers props so the setter can write the original state instead of re-applying the current frame.
|
||||
values.decomposeRawValue(originalInlinedValue, values.decomposedOriginalValue);
|
||||
if (values.decomposedOriginalValue.d) {
|
||||
const src = values.decomposedOriginalValue.d;
|
||||
const dst = tween._numbers;
|
||||
for (let i = 0, l = src.length; i < l; i++) dst[i] = src[i];
|
||||
} else {
|
||||
tween._number = values.decomposedOriginalValue.n;
|
||||
}
|
||||
tween._setter(tween.target, tween._number, tween);
|
||||
}
|
||||
} else if (tweenType === consts.tweenTypes.OBJECT) {
|
||||
if (!inlineStylesOnly && !tweenHadNoInlineValue) {
|
||||
tweenTarget[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
} else if (tweenTarget[consts.isDomSymbol]) {
|
||||
if (tweenType === consts.tweenTypes.ATTRIBUTE) {
|
||||
if (!inlineStylesOnly) {
|
||||
if (tweenHadNoInlineValue) {
|
||||
/** @type {DOMTarget} */(tweenTarget).removeAttribute(tweenProperty);
|
||||
} else {
|
||||
/** @type {DOMTarget} */(tweenTarget).setAttribute(tweenProperty, /** @type {String} */(originalInlinedValue));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const targetStyle = /** @type {DOMTarget} */(tweenTarget).style;
|
||||
if (tweenType === consts.tweenTypes.TRANSFORM) {
|
||||
const cachedTransforms = tweenTarget[consts.transformsSymbol];
|
||||
if (tweenHadNoInlineValue) {
|
||||
delete cachedTransforms[tweenProperty];
|
||||
} else {
|
||||
cachedTransforms[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
if (tween._renderTransforms) {
|
||||
if (!Object.keys(cachedTransforms).length) {
|
||||
targetStyle.removeProperty('transform');
|
||||
} else {
|
||||
targetStyle.transform = transforms.buildTransformString(cachedTransforms);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tweenHadNoInlineValue) {
|
||||
targetStyle.removeProperty(helpers.toLowerCase(tweenProperty));
|
||||
} else {
|
||||
targetStyle[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tweenTarget[consts.isDomSymbol] && animation._tail === tween) {
|
||||
animation.targets.forEach(t => {
|
||||
if (t.getAttribute && t.getAttribute('style') === consts.emptyString) {
|
||||
t.removeAttribute('style');
|
||||
} });
|
||||
}
|
||||
});
|
||||
}
|
||||
return renderable;
|
||||
};
|
||||
|
||||
/**
|
||||
* @template {Renderable} T
|
||||
* @param {T} renderable
|
||||
* @return {T}
|
||||
*/
|
||||
const cleanInlineStyles = renderable => revertValues(renderable, true);
|
||||
|
||||
exports.cleanInlineStyles = cleanInlineStyles;
|
||||
exports.revertValues = revertValues;
|
||||
exports.sanitizePropertyName = sanitizePropertyName;
|
||||
@@ -0,0 +1,6 @@
|
||||
export function sanitizePropertyName(propertyName: string, target: Target, tweenType: tweenTypes): string;
|
||||
export function revertValues<T extends Renderable>(renderable: T, inlineStylesOnly?: boolean): T;
|
||||
export function cleanInlineStyles<T extends Renderable>(renderable: T): T;
|
||||
import type { Target } from '../types/index.js';
|
||||
import { tweenTypes } from './consts.js';
|
||||
import type { Renderable } from '../types/index.js';
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Anime.js - core - ESM
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
import { tweenTypes, isDomSymbol, transformsSymbol, emptyString, shortTransforms } from './consts.js';
|
||||
import { forEachChildren, toLowerCase, isNil, isSvg } from './helpers.js';
|
||||
import { buildTransformString } from './transforms.js';
|
||||
import { decomposeRawValue, decomposedOriginalValue } from './values.js';
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* JSAnimation,
|
||||
* } from '../animation/animation.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* Target,
|
||||
* DOMTarget,
|
||||
* Renderable,
|
||||
* Tween,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
const propertyNamesCache = {};
|
||||
|
||||
/**
|
||||
* @param {String} propertyName
|
||||
* @param {Target} target
|
||||
* @param {tweenTypes} tweenType
|
||||
* @return {String}
|
||||
*/
|
||||
const sanitizePropertyName = (propertyName, target, tweenType) => {
|
||||
if (tweenType === tweenTypes.TRANSFORM) {
|
||||
const t = shortTransforms.get(propertyName);
|
||||
return t ? t : propertyName;
|
||||
} else if (
|
||||
tweenType === tweenTypes.CSS ||
|
||||
// Handle special cases where properties like "strokeDashoffset" needs to be set as "stroke-dashoffset"
|
||||
// but properties like "baseFrequency" should stay in lowerCamelCase
|
||||
(tweenType === tweenTypes.ATTRIBUTE && (isSvg(target) && propertyName in /** @type {DOMTarget} */(target).style))
|
||||
) {
|
||||
const cachedPropertyName = propertyNamesCache[propertyName];
|
||||
if (cachedPropertyName) {
|
||||
return cachedPropertyName;
|
||||
} else {
|
||||
const lowerCaseName = propertyName ? toLowerCase(propertyName) : propertyName;
|
||||
propertyNamesCache[propertyName] = lowerCaseName;
|
||||
return lowerCaseName;
|
||||
}
|
||||
} else {
|
||||
return propertyName;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @template {Renderable} T
|
||||
* @param {T} renderable
|
||||
* @param {Boolean} [inlineStylesOnly]
|
||||
* @return {T}
|
||||
*/
|
||||
const revertValues = (renderable, inlineStylesOnly = false) => {
|
||||
// Allow revertValues() to be called on timelines
|
||||
if (renderable._hasChildren) {
|
||||
forEachChildren(renderable, (/** @type {Renderable} */child) => revertValues(child, inlineStylesOnly), true);
|
||||
} else {
|
||||
const animation = /** @type {JSAnimation} */(renderable);
|
||||
animation.pause();
|
||||
forEachChildren(animation, (/** @type {Tween} */tween) => {
|
||||
const tweenProperty = tween.property;
|
||||
const tweenTarget = tween.target;
|
||||
const tweenType = tween._tweenType;
|
||||
const originalInlinedValue = tween._inlineValue;
|
||||
const tweenHadNoInlineValue = isNil(originalInlinedValue) || originalInlinedValue === emptyString;
|
||||
if (tween._setter) {
|
||||
if (!inlineStylesOnly && !tweenHadNoInlineValue) {
|
||||
// Re-seed the original value to the _number / _numbers props so the setter can write the original state instead of re-applying the current frame.
|
||||
decomposeRawValue(originalInlinedValue, decomposedOriginalValue);
|
||||
if (decomposedOriginalValue.d) {
|
||||
const src = decomposedOriginalValue.d;
|
||||
const dst = tween._numbers;
|
||||
for (let i = 0, l = src.length; i < l; i++) dst[i] = src[i];
|
||||
} else {
|
||||
tween._number = decomposedOriginalValue.n;
|
||||
}
|
||||
tween._setter(tween.target, tween._number, tween);
|
||||
}
|
||||
} else if (tweenType === tweenTypes.OBJECT) {
|
||||
if (!inlineStylesOnly && !tweenHadNoInlineValue) {
|
||||
tweenTarget[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
} else if (tweenTarget[isDomSymbol]) {
|
||||
if (tweenType === tweenTypes.ATTRIBUTE) {
|
||||
if (!inlineStylesOnly) {
|
||||
if (tweenHadNoInlineValue) {
|
||||
/** @type {DOMTarget} */(tweenTarget).removeAttribute(tweenProperty);
|
||||
} else {
|
||||
/** @type {DOMTarget} */(tweenTarget).setAttribute(tweenProperty, /** @type {String} */(originalInlinedValue));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const targetStyle = /** @type {DOMTarget} */(tweenTarget).style;
|
||||
if (tweenType === tweenTypes.TRANSFORM) {
|
||||
const cachedTransforms = tweenTarget[transformsSymbol];
|
||||
if (tweenHadNoInlineValue) {
|
||||
delete cachedTransforms[tweenProperty];
|
||||
} else {
|
||||
cachedTransforms[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
if (tween._renderTransforms) {
|
||||
if (!Object.keys(cachedTransforms).length) {
|
||||
targetStyle.removeProperty('transform');
|
||||
} else {
|
||||
targetStyle.transform = buildTransformString(cachedTransforms);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tweenHadNoInlineValue) {
|
||||
targetStyle.removeProperty(toLowerCase(tweenProperty));
|
||||
} else {
|
||||
targetStyle[tweenProperty] = originalInlinedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tweenTarget[isDomSymbol] && animation._tail === tween) {
|
||||
animation.targets.forEach(t => {
|
||||
if (t.getAttribute && t.getAttribute('style') === emptyString) {
|
||||
t.removeAttribute('style');
|
||||
} });
|
||||
}
|
||||
});
|
||||
}
|
||||
return renderable;
|
||||
};
|
||||
|
||||
/**
|
||||
* @template {Renderable} T
|
||||
* @param {T} renderable
|
||||
* @return {T}
|
||||
*/
|
||||
const cleanInlineStyles = renderable => revertValues(renderable, true);
|
||||
|
||||
export { cleanInlineStyles, revertValues, sanitizePropertyName };
|
||||
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Anime.js - core - CJS
|
||||
* @version v4.5.0
|
||||
* @license MIT
|
||||
* @copyright 2026 - Julian Garnier
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var globals = require('./globals.cjs');
|
||||
var consts = require('./consts.cjs');
|
||||
var helpers = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* @import {
|
||||
* DOMTarget,
|
||||
* DOMTargetsParam,
|
||||
* JSTargetsArray,
|
||||
* TargetsParam,
|
||||
* JSTargetsParam,
|
||||
* TargetsArray,
|
||||
* DOMTargetsArray,
|
||||
* } from '../types/index.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {DOMTargetsParam|TargetsParam} v
|
||||
* @return {NodeList|HTMLCollection}
|
||||
*/
|
||||
function getNodeList(v) {
|
||||
const n = helpers.isStr(v) ? globals.scope.root.querySelectorAll(v) : v;
|
||||
if (n instanceof NodeList || n instanceof HTMLCollection) return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @param {DOMTargetsParam} targets
|
||||
* @return {DOMTargetsArray}
|
||||
*
|
||||
* @overload
|
||||
* @param {JSTargetsParam} targets
|
||||
* @return {JSTargetsArray}
|
||||
*
|
||||
* @overload
|
||||
* @param {TargetsParam} targets
|
||||
* @return {TargetsArray}
|
||||
*
|
||||
* @param {DOMTargetsParam|JSTargetsParam|TargetsParam} targets
|
||||
*/
|
||||
function parseTargets(targets) {
|
||||
if (helpers.isNil(targets)) return /** @type {TargetsArray} */([]);
|
||||
if (!consts.isBrowser) return /** @type {JSTargetsArray} */(helpers.isArr(targets) && targets.flat(Infinity) || [targets]);
|
||||
if (helpers.isArr(targets)) {
|
||||
const flattened = targets.flat(Infinity);
|
||||
/** @type {TargetsArray} */
|
||||
const parsed = [];
|
||||
for (let i = 0, l = flattened.length; i < l; i++) {
|
||||
const item = flattened[i];
|
||||
if (!helpers.isNil(item)) {
|
||||
const nodeList = getNodeList(item);
|
||||
if (nodeList) {
|
||||
for (let j = 0, jl = nodeList.length; j < jl; j++) {
|
||||
const subItem = nodeList[j];
|
||||
if (!helpers.isNil(subItem)) {
|
||||
let isDuplicate = false;
|
||||
for (let k = 0, kl = parsed.length; k < kl; k++) {
|
||||
if (parsed[k] === subItem) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isDuplicate) {
|
||||
parsed.push(subItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let isDuplicate = false;
|
||||
for (let j = 0, jl = parsed.length; j < jl; j++) {
|
||||
if (parsed[j] === item) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isDuplicate) {
|
||||
parsed.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
const nodeList = getNodeList(targets);
|
||||
if (nodeList) return /** @type {DOMTargetsArray} */(Array.from(nodeList));
|
||||
return /** @type {TargetsArray} */([targets]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @overload
|
||||
* @param {DOMTargetsParam} targets
|
||||
* @return {DOMTargetsArray}
|
||||
*
|
||||
* @overload
|
||||
* @param {JSTargetsParam} targets
|
||||
* @return {JSTargetsArray}
|
||||
*
|
||||
* @overload
|
||||
* @param {TargetsParam} targets
|
||||
* @return {TargetsArray}
|
||||
*
|
||||
* @param {DOMTargetsParam|JSTargetsParam|TargetsParam} targets
|
||||
*/
|
||||
function registerTargets(targets) {
|
||||
const parsedTargetsArray = parseTargets(targets);
|
||||
const parsedTargetsLength = parsedTargetsArray.length;
|
||||
for (let i = 0; i < parsedTargetsLength; i++) {
|
||||
const target = parsedTargetsArray[i];
|
||||
if (!target[consts.isRegisteredTargetSymbol]) {
|
||||
target[consts.isRegisteredTargetSymbol] = true;
|
||||
const isSvgType = helpers.isSvg(target);
|
||||
const isDom = /** @type {DOMTarget} */(target).nodeType || isSvgType;
|
||||
if (isDom) {
|
||||
target[consts.isDomSymbol] = true;
|
||||
target[consts.isSvgSymbol] = isSvgType;
|
||||
target[consts.transformsSymbol] = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
return parsedTargetsArray;
|
||||
}
|
||||
|
||||
exports.getNodeList = getNodeList;
|
||||
exports.parseTargets = parseTargets;
|
||||
exports.registerTargets = registerTargets;
|
||||